raf-handler
Version:
Use for centralize request animation frame
3 lines (2 loc) • 906 B
JavaScript
window&&window.requestAnimationFrame||(window.requestAnimationFrame=function(){return null},window.cancelAnimationFrame=function(){return null});var n={rAF:[],fps:60,then:Date.now()},e=function e(r){var t=n.rAF;if(n.interval=1e3/n.fps,n.now=Date.now(),n.delta=n.now-n.then,n.delta>n.interval){n.then=n.now-n.delta%n.interval;for(var i=0,a=t.length;i<a;i+=1)t[i](r)}return requestAnimationFrame(e)},r=function(){n.id&&window.cancelAnimationFrame(n.id),n.id=null,n.rAF=null},t=function(e){n.rAF||(n.rAF=[]),n.rAF.push(e)},i=function(e){for(var r=n.rAF,t=0,i=r.length;t<i;t+=1)r[t]===e&&(n.rAF.splice(t,1),t--)},a=function(a){var o;return null!=a&&a.fps&&(n.fps=a.fps),n.id=null==(o=window)?void 0:o.requestAnimationFrame(e),{reset:r,add:t,remove:i,update:e,store:n}};export{a as default,r as resetUpdate,n as store,t as subscribeUpdate,i as unsubscribeUpdate,e as update};
//# sourceMappingURL=index.mjs.map