-
Notifications
You must be signed in to change notification settings - Fork 346
/
browser.ts
35 lines (30 loc) 路 1.25 KB
/
browser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Copyright (c) 2017 ~ present NAVER Corp.
* billboard.js project is licensed under the MIT license
*/
/**
* Window object
* @private
*/
/* eslint-disable no-new-func, no-undef */
export {
win as window,
doc as document,
requestAnimationFrame, cancelAnimationFrame,
requestIdleCallback, cancelIdleCallback
};
const win = (() => {
const root = (typeof globalThis === "object" && globalThis !== null && globalThis.Object === Object && globalThis) ||
(typeof global === "object" && global !== null && global.Object === Object && global) ||
(typeof self === "object" && self !== null && self.Object === Object && self);
return root || Function("return this")();
})();
/* eslint-enable no-new-func, no-undef */
// fallback for non-supported environments
const hasRAF = typeof win.requestAnimationFrame === "function";
const hasRIC = typeof win.requestIdleCallback === "function";
const requestAnimationFrame = hasRAF ? win.requestAnimationFrame : (cb => setTimeout(cb, 1));
const cancelAnimationFrame = hasRAF ? win.cancelAnimationFrame : (id => clearTimeout(id));
const requestIdleCallback = hasRIC ? win.requestIdleCallback : requestAnimationFrame;
const cancelIdleCallback = hasRIC ? win.cancelIdleCallback : cancelAnimationFrame;
const doc = win?.document;