@luma.gl/engine
Version:
3D Engine Components for luma.gl
35 lines • 1.32 kB
JavaScript
// luma.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors
/* global window, setTimeout, clearTimeout */
/** Node.js polyfill for requestAnimationFrame */
// / <reference types="@types/node" />
export function requestAnimationFramePolyfill(callback) {
const browserRequestAnimationFrame = typeof window !== 'undefined'
? window.requestAnimationFrame ||
window
.webkitRequestAnimationFrame ||
window
.mozRequestAnimationFrame
: null;
if (browserRequestAnimationFrame) {
return browserRequestAnimationFrame.call(window, callback);
}
return setTimeout(() => callback(typeof performance !== 'undefined' ? performance.now() : Date.now()), 1000 / 60);
}
/** Node.js polyfill for cancelAnimationFrame */
export function cancelAnimationFramePolyfill(timerId) {
const browserCancelAnimationFrame = typeof window !== 'undefined'
? window.cancelAnimationFrame ||
window
.webkitCancelAnimationFrame ||
window
.mozCancelAnimationFrame
: null;
if (browserCancelAnimationFrame) {
browserCancelAnimationFrame.call(window, timerId);
return;
}
clearTimeout(timerId);
}
//# sourceMappingURL=request-animation-frame.js.map