@unito/integration-debugger
Version:
The Unito Integration Debugger
28 lines (27 loc) • 1.04 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.polyfillRequestAnimationFrame = polyfillRequestAnimationFrame;
// Based on https://gist.github.com/paulirish/1579671
function polyfillRequestAnimationFrame() {
if (typeof global.window === 'undefined') {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore happens in environments where 'typescript' is not a runtime dependency.
global.window = {};
}
let lastTime = 0;
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function (callback) {
const now = window.performance.now();
const nextTime = Math.max(lastTime + 16, now);
const id = window.setTimeout(function () {
callback((lastTime = nextTime));
}, nextTime - now);
return id;
};
}
if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function (id) {
clearTimeout(id);
};
}
}
;