"use strict";var R=Object.defineProperty;var A=(i,e,n)=>e in i?R(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n;var h=(i,e,n)=>(A(i,typeof e!="symbol"?e+"":e,n),n);let d=0,q=0;const o=[],v=1e3/60,I=i=>{if(o.length===0){const e=performance.now(),n=Math.max(0,v-(e-d));d=n+e,setTimeout(()=>{const r=o.slice(0);o.length=0;for(let s=0;s{throw c},0)}},Math.round(n))}return q+=1,o.push({handle:q,cancelled:!1,callback:i}),q},w=i=>{for(let e=0;e{const e=()=>i||f,n=new Map,r=(t,a)=>{n.set(t,a)},s=t=>{n.delete(t)},c=t=>e()?window.requestAnimationFrame(t):I(t),u=t=>{window.cancelAnimationFrame(t),w(t)};return document.addEventListener("visibilitychange",()=>{f=!document||!document.hidden,e()||n.forEach((t,a)=>{t(),s(a)})}),{requestAnimationFrame:c,cancelAnimationFrame:u,whenRestarted:r,offRestart:s}};class g{constructor({backgroundThrottling:e}={backgroundThrottling:!0}){h(this,"requestID");h(this,"active",!0);h(this,"runner");this.runner=D(e)}run(e,n=60,r){const s=1e3/n;let c=0,u=0;const t=a=>{if(r&&u>=r)return;this.request(t);const l=a-c;l>s&&(c=a-l%s,u+=1,e(a))};this.cancelRequest(),this.request(t)}async runAsync(e,n=60,r){const s=1e3/n;let c=0,u=0;const t=async a=>{if(r&&u>=r)return;const l=a-c;l>s&&(c=a-l%s,u+=1,await e(a)),this.request(t)};this.cancelRequest(),this.request(t)}request(e){this.requestID&&this.runner.offRestart(this.requestID),this.active&&(this.requestID=this.runner.requestAnimationFrame(e),this.runner.whenRestarted(this.requestID,()=>{this.cancelRequest(),this.requestID=this.runner.requestAnimationFrame(e)}))}cancelRequest(){this.requestID&&(this.runner.cancelAnimationFrame(this.requestID),this.runner.offRestart(this.requestID))}activate(){this.cancelRequest(),this.active=!0}deactivate(){this.cancelRequest(),this.active=!1}}module.exports=g;