Avoid try/catch, DOM and workers
This commit is contained in:
+4
-16
@@ -37,27 +37,15 @@ export const MAC = ua.indexOf('macintosh') !== -1;
|
||||
* @type {number}
|
||||
* @api
|
||||
*/
|
||||
export const DEVICE_PIXEL_RATIO = (function() {
|
||||
try {
|
||||
return self.devicePixelRatio;
|
||||
} catch (e) {
|
||||
return window.devicePixelRatio || 1;
|
||||
}
|
||||
})();
|
||||
export const DEVICE_PIXEL_RATIO = (typeof self !== 'undefined' ? self.devicePixelRatio : window.devicePixelRatio) || 1;
|
||||
|
||||
/**
|
||||
* The execution context is a window.
|
||||
* The execution context is a worker with OffscreenCanvas available.
|
||||
* @const
|
||||
* @type {boolean}
|
||||
*/
|
||||
export const WINDOW = (function() {
|
||||
try {
|
||||
return 'document' in self;
|
||||
} catch (e) {
|
||||
// ancient browsers don't have `self`
|
||||
return true;
|
||||
}
|
||||
})();
|
||||
export const WORKER_OFFSCREEN_CANVAS = typeof WorkerGlobalScope !== 'undefined' && typeof OffscreenCanvas !== 'undefined' &&
|
||||
self instanceof WorkerGlobalScope; //eslint-disable-line
|
||||
|
||||
/**
|
||||
* Image.prototype.decode() is supported.
|
||||
|
||||
Reference in New Issue
Block a user