UNPKG

sandpit

Version:

A playground for creative coding using JavaScript and the canvas element

44 lines (40 loc) 1.55 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); /** * RequestAnimationFrame shim, as jsdom doesn't * ship with it - primarily for use in the test suites * Credit: https://gist.github.com/paulirish/1579671 * @private */ var requestAnimationFrame = void 0; var cancelAnimationFrame = void 0; var lastTime = 0; var vendors = ['ms', 'moz', 'webkit', 'o']; for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame']; } if (!window.requestAnimationFrame) { exports.requestAnimationFrame = requestAnimationFrame = function requestAnimationFrame(callback, element) { var currTime = new Date().getTime(); var timeToCall = Math.max(0, 16 - (currTime - lastTime)); var id = window.setTimeout(function () { callback(currTime + timeToCall); }, timeToCall); lastTime = currTime + timeToCall; return id; }; } else { exports.requestAnimationFrame = requestAnimationFrame = window.requestAnimationFrame; } if (!window.cancelAnimationFrame) { exports.cancelAnimationFrame = cancelAnimationFrame = function cancelAnimationFrame(id) { clearTimeout(id); }; } else { exports.cancelAnimationFrame = cancelAnimationFrame = window.cancelAnimationFrame; } exports.requestAnimationFrame = requestAnimationFrame; exports.cancelAnimationFrame = cancelAnimationFrame;