const w=16.666666666666668,N=typeof performance<"u"?()=>performance.now():()=>Date.now(),R=typeof window<"u"?e=>window.requestAnimationFrame(e):e=>setTimeout(()=>e(N()),w);function S(e){let t=[],n=[],a=0,o=!1,f=!1;const p=new WeakSet,m={schedule:(s,r=!1,c=!1)=>{const g=c&&o,F=g?t:n;return r&&p.add(s),F.indexOf(s)===-1&&(F.push(s),g&&o&&(a=t.length)),s},cancel:s=>{const r=n.indexOf(s);r!==-1&&n.splice(r,1),p.delete(s)},process:s=>{if(o){f=!0;return}if(o=!0,[t,n]=[n,t],n.length=0,a=t.length,a)for(let r=0;r<a;r++){const c=t[r];c(s),p.has(c)&&(m.schedule(c),e())}o=!1,f&&(f=!1,m.process(s))}};return m}const E=40;let h=!0,l=!1,x=!1;const u={delta:0,timestamp:0},i=["read","update","preRender","render","postRender"],d=i.reduce((e,t)=>(e[t]=S(()=>l=!0),e),{}),C=i.reduce((e,t)=>{const n=d[t];return e[t]=(a,o=!1,f=!1)=>(l||A(),n.schedule(a,o,f)),e},{}),D=i.reduce((e,t)=>(e[t]=d[t].cancel,e),{});i.reduce((e,t)=>(e[t]=()=>d[t].process(u),e),{});const O=e=>d[e].process(u),T=e=>{l=!1,u.delta=h?w:Math.max(Math.min(e-u.timestamp,E),1),u.timestamp=e,x=!0,i.forEach(O),x=!1,l&&(h=!1,R(T))},A=()=>{l=!0,h=!0,x||R(T)},M=()=>u;export{D as c,M as g,C as s};
