File tree Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change 3
3
* @license MIT
4
4
*/
5
5
6
- import { isNode } from 'common/Platform' ;
7
6
import { IColor , IColorRGB } from 'common/Types' ;
8
7
9
8
let $r = 0 ;
@@ -117,9 +116,10 @@ export namespace color {
117
116
* '#rrggbbaa').
118
117
*/
119
118
export namespace css {
119
+ // Attempt to set get the shared canvas context
120
120
let $ctx : CanvasRenderingContext2D | undefined ;
121
121
let $litmusColor : CanvasGradient | undefined ;
122
- if ( ! isNode ) {
122
+ try {
123
123
// This is guaranteed to run in the first window, so document should be correct
124
124
const canvas = document . createElement ( 'canvas' ) ;
125
125
canvas . width = 1 ;
@@ -133,6 +133,9 @@ export namespace css {
133
133
$litmusColor = $ctx . createLinearGradient ( 0 , 0 , 1 , 1 ) ;
134
134
}
135
135
}
136
+ catch {
137
+ // noop
138
+ }
136
139
137
140
/**
138
141
* Converts a css string to an IColor, this should handle all valid CSS color strings and will
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ interface INavigator {
14
14
declare const navigator : INavigator ;
15
15
declare const process : unknown ;
16
16
17
- export const isNode = ( typeof process !== 'undefined' ) ? true : false ;
17
+ export const isNode = ( typeof process !== 'undefined' && 'title' in ( process as any ) ) ? true : false ;
18
18
const userAgent = ( isNode ) ? 'node' : navigator . userAgent ;
19
19
const platform = ( isNode ) ? 'node' : navigator . platform ;
20
20
You can’t perform that action at this time.
0 commit comments