@algorisys/tinyfly 0.116.0 → 0.117.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- (function(f,Q){typeof exports=="object"&&typeof module<"u"?Q(exports):typeof define=="function"&&define.amd?define(["exports"],Q):(f=typeof globalThis<"u"?globalThis:f||self,Q(f.tinyfly={}))})(this,(function(f){"use strict";function Q(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function lt(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const vt=2;function It(t){return t.some(e=>e.interpolation!==void 0)?2:1}function ft(t){return t.property==="text"&&"textConfig"in t}function Y(t){return t.kind==="inertia"&&"inertia"in t}function z(t){return t.kind==="spring"&&"spring"in t}function Rt(t){return t.property==="motionPath"&&"motionPathConfig"in t}function Yn(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"angle"in t}function ye(t){return"keyframes"in t}class zn{_currentTime=0;_isRunning=!1;onTick=null;get currentTime(){return this._currentTime}get isRunning(){return this._isRunning}start(){this._isRunning=!0}stop(){this._isRunning=!1}tick(e){this._currentTime+=e,this.onTick?.(e,this._currentTime)}reset(){this._currentTime=0}seek(e){this._currentTime=e}}class Un{_currentTime=0;_isRunning=!1;_lastFrameTime=null;_rafId=null;_speed;onTick=null;constructor(e={}){this._speed=e.speed??1}get currentTime(){return this._currentTime}get isRunning(){return this._isRunning}get speed(){return this._speed}set speed(e){this._speed=e}start(){this._isRunning||(this._isRunning=!0,this._lastFrameTime=null,this._scheduleFrame())}stop(){this._isRunning=!1,this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null)}reset(){this._currentTime=0,this._lastFrameTime=null}seek(e){this._currentTime=e}_scheduleFrame(){this._rafId=requestAnimationFrame(this._onFrame.bind(this))}_onFrame(e){if(this._isRunning){if(this._lastFrameTime!==null){const r=(e-this._lastFrameTime)*this._speed;this._currentTime+=r,this.onTick?.(r,this._currentTime)}this._lastFrameTime=e,this._scheduleFrame()}}}function pe(t,e){if(!(e>0))return t;const n=1e3/e;return Math.floor(t/n+1e-9)*n}function Et(t,e,n="start"){if(e<=1)return 0;if(typeof n=="number"){const r=Math.max(0,Math.min(e-1,n));return Math.abs(t-r)}switch(n){case"end":return e-1-t;case"center":return Math.abs(t-(e-1)/2);case"edges":return(e-1)/2-Math.abs(t-(e-1)/2);default:return t}}function Me(t,e="start"){if(t<=1)return 0;let n=0;for(let r=0;r<t;r++)n=Math.max(n,Et(r,t,e));return n}function Ct(t,e,n){if(n.offsets)return n.offsets[t]??0;const r=n.from??"start",s=Et(t,e,r);if(n.amount!==void 0){const a=Me(e,r);return a===0?0:n.amount*s/a}return n.each!==void 0?n.each*s:0}function _e(t,e){return Array.from({length:t},(n,r)=>Ct(r,t,e))}function dt(t,e){return t<=1?0:Math.max(..._e(t,e))}const G=1,Dt=6e4,mt=Dt/G,L={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1},Vn={gentle:{stiffness:120,damping:18,mass:1},default:{stiffness:180,damping:12,mass:1},snappy:{stiffness:280,damping:20,mass:1},bouncy:{stiffness:220,damping:8,mass:1},wobbly:{stiffness:180,damping:5,mass:1},stiff:{stiffness:400,damping:30,mass:1}};class et{from;to;stiffness;damping;mass;restDelta;restSpeed;distance;samples;velocity;settledStep=null;constructor(e){this.from=e.from,this.to=e.to,this.stiffness=e.stiffness??L.stiffness,this.damping=e.damping??L.damping,this.mass=e.mass??L.mass,this.restDelta=e.restDelta??L.restDelta,this.restSpeed=e.restSpeed??L.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=e.velocity??L.velocity,this.isAtRest(this.from)&&(this.settledStep=0)}isAtRest(e){return Math.abs(e-this.to)<this.restDelta*this.distance&&Math.abs(this.velocity)<this.restSpeed*this.distance}valueAt(e){if(e<=0)return this.from;const n=Math.floor(e/G);if(this.simulateTo(n+1),this.settledStep!==null&&n>=this.settledStep)return this.to;const r=this.samples[Math.min(n,this.samples.length-1)],s=this.samples[Math.min(n+1,this.samples.length-1)],a=e/G-n;return r+(s-r)*a}settleTime(){return this.simulateTo(mt+1),this.settledStep!==null?this.settledStep*G:Dt}simulateTo(e){if(this.settledStep!==null)return;const n=Math.min(e,mt+1),r=G/1e3;for(;this.samples.length<n;){const s=this.samples[this.samples.length-1],a=s-this.to,i=-this.stiffness*a,o=-this.damping*this.velocity,c=(i+o)/this.mass;this.velocity+=c*r;const h=s+this.velocity*r;if(this.samples.push(h),this.isAtRest(h)){this.settledStep=this.samples.length-1;return}}this.samples.length>mt&&(this.settledStep=mt)}}function jn(t,e){return new et(t).valueAt(e)}function Bn(t){return new et(t).settleTime()}function Hn(t){const e=t.stiffness??L.stiffness,n=t.damping??L.damping,r=t.mass??L.mass;return n<2*Math.sqrt(e*r)}function qn(t){const e=t.stiffness??L.stiffness,n=t.mass??L.mass;return 2*Math.sqrt(e*n)}const $t=4,Qn=.002,Gn=1e-4,be=6e4;function gt(t){const e=t.friction??$t;return e>0?e:$t}function Te(t){return t.from+t.velocity/gt(t)}function Kn(t,e){if(e===void 0)return t;if(typeof e=="number")return e>0?Math.round(t/e)*e:t;if(e.length===0)return t;let n=e[0];for(const r of e)Math.abs(r-t)<Math.abs(n-t)&&(n=r);return n}function nt(t){let e=Kn(Te(t),t.end);return t.min!==void 0&&(e=Math.max(t.min,e)),t.max!==void 0&&(e=Math.min(t.max,e)),e}function rt(t){const e=Math.abs(nt(t)-t.from);if(e===0)return 0;const n=t.restDelta??Math.max(Gn,e*Qn);if(n>=e)return 0;const r=Math.log(e/n)/gt(t);return Math.min(be,r*1e3)}function yt(t,e){if(e<=0)return t.from;const n=nt(t);if(e>=rt(t))return n;const r=gt(t);return t.from+(n-t.from)*(1-Math.exp(-r*e/1e3))}function Wn(t,e){const n=gt(t),r=nt(t);return e>=rt(t)?0:(r-t.from)*n*Math.exp(-n*Math.max(0,e)/1e3)}const pt=t=>t,ke=t=>t*t,we=t=>1-(1-t)*(1-t),Se=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,Ot=t=>t*t*t,Lt=t=>1-Math.pow(1-t,3),Ft=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,Pe=Ot,Ae=Lt,xe=Ft,Jn={linear:pt,"ease-in":Pe,"ease-out":Ae,"ease-in-out":xe,"ease-in-quad":ke,"ease-out-quad":we,"ease-in-out-quad":Se,"ease-in-cubic":Ot,"ease-out-cubic":Lt,"ease-in-out-cubic":Ft};function ve(t){const[e,n,r,s]=t,a=3*e,i=3*(r-e)-a,o=1-a-i,c=3*n,h=3*(s-n)-c,l=1-c-h,u=g=>((o*g+i)*g+a)*g,m=g=>((l*g+h)*g+c)*g,d=g=>(3*o*g+2*i)*g+a,y=g=>{let _=g;for(let T=0;T<8;T++){const S=u(_)-g;if(Math.abs(S)<1e-7)return _;const b=d(_);if(Math.abs(b)<1e-7)break;_-=S/b}let M=0,p=1;for(_=g;M<p;){const T=u(_);if(Math.abs(T-g)<1e-7)return _;g>T?M=_:p=_,_=(M+p)/2}return _};return g=>{if(g<=0)return 0;if(g>=1)return 1;const _=y(g);return m(_)}}function Nt(t,e="out"){if(e==="out")return t;const n=r=>1-t(1-r);return e==="in"?n:r=>r<.5?n(r*2)/2:t(r*2-1)/2+.5}function Ie(t=1,e=.3){const n=Math.max(1,t),r=e/(2*Math.PI)*Math.asin(1/n);return s=>s<=0?0:s>=1?1:n*Math.pow(2,-10*s)*Math.sin((s-r)*(2*Math.PI)/e)+1}const Re=t=>{if(t<=0)return 0;if(t>=1)return 1;if(t<1/2.75)return 7.5625*t*t;if(t<2/2.75){const s=t-.5454545454545454;return 7.5625*s*s+.75}if(t<2.5/2.75){const s=t-.8181818181818182;return 7.5625*s*s+.9375}const r=t-2.625/2.75;return 7.5625*r*r+.984375};function Ee(t=1.70158){return e=>{if(e<=0)return 0;if(e>=1)return 1;const n=e-1;return n*n*((t+1)*n+t)+1}}function Ce(t,e="end"){const n=Math.max(1,Math.floor(t));return r=>{if(r>=1)return 1;if(r<=0)return e==="start"||e==="both"?e==="start"?1/n:1/(n+1):0;const s=Math.floor(r*n);switch(e){case"start":return Math.min(1,(s+1)/n);case"both":return(s+1)/(n+1);case"none":return n===1?0:Math.min(1,s/(n-1));default:return s/n}}}function De(t){switch(t.type){case"steps":return Ce(t.count,t.position);case"elastic":return Nt(Ie(t.amplitude,t.period),t.mode);case"bounce":return Nt(Re,t.mode);case"back":return Nt(Ee(t.overshoot),t.mode)}}function Mt(t){return t===void 0?pt:Q(t)?ve(t.points):lt(t)?De(t):Jn[t]??pt}const $e=32,Zn=256,K=new Map,tr=/[MmLlHhVvCcSsQqTtAaZz]/,er=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,nr={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function rr(t){const e=[];let n=0,r=null;const s=()=>{for(;n<t.length&&/[\s,]/.test(t[n]);)n++};for(;n<t.length&&(s(),!(n>=t.length));){const a=t[n];if(tr.test(a)){r={type:a,args:[]},e.push(r),n++;continue}if(!r)break;const i=r.type==="A"||r.type==="a",o=r.args.length%7;if(i&&(o===3||o===4)){if(a!=="0"&&a!=="1")break;r.args.push(a==="1"?1:0),n++;continue}const c=er.exec(t.slice(n));if(!c)break;r.args.push(parseFloat(c[0])),n+=c[0].length}return e}function sr(t,e,n,r,s,a,i,o,c){if(t===o&&e===c)return[];let h=Math.abs(n),l=Math.abs(r);if(h===0||l===0)return[[t,e,o,c,o,c]];const u=s*Math.PI/180,m=Math.cos(u),d=Math.sin(u),y=(t-o)/2,g=(e-c)/2,_=m*y+d*g,M=-d*y+m*g,p=_*_/(h*h)+M*M/(l*l);if(p>1){const C=Math.sqrt(p);h*=C,l*=C}const T=a===i?-1:1,S=h*h*l*l-h*h*M*M-l*l*_*_,b=h*h*M*M+l*l*_*_,x=T*Math.sqrt(Math.max(0,S/b)),P=x*h*M/l,I=-x*l*_/h,k=m*P-d*I+(t+o)/2,w=d*P+m*I+(e+c)/2,A=(C,$,O,tt)=>{const ge=C*O+$*tt,xt=Math.sqrt((C*C+$*$)*(O*O+tt*tt)),ht=Math.acos(Math.max(-1,Math.min(1,ge/xt)));return C*tt-$*O<0?-ht:ht},v=A(1,0,(_-P)/h,(M-I)/l);let E=A((_-P)/h,(M-I)/l,(-_-P)/h,(-M-I)/l);!i&&E>0&&(E-=2*Math.PI),i&&E<0&&(E+=2*Math.PI);const R=Math.max(1,Math.ceil(Math.abs(E)/(Math.PI/2))),me=E/R,At=4/3*Math.tan(me/4),Fn=C=>{const $=h*Math.cos(C),O=l*Math.sin(C);return[m*$-d*O+k,d*$+m*O+w]},Nn=C=>{const $=-h*Math.sin(C),O=l*Math.cos(C);return[m*$-d*O,d*$+m*O]},Xn=[];for(let C=0;C<R;C++){const $=v+C*me,O=$+me,[tt,ge]=Fn($),[xt,ht]=C===R-1?[o,c]:Fn(O),[ua,ha]=Nn($),[la,fa]=Nn(O);Xn.push([tt+At*ua,ge+At*ha,xt-At*la,ht-At*fa,xt,ht])}return Xn}function U(t,e,n,r,s){const a=1-s;return a*a*a*t+3*a*a*s*e+3*a*s*s*n+s*s*s*r}function Oe(t,e,n,r,s){const a=1-s;return 3*a*a*(e-t)+6*a*s*(n-e)+3*s*s*(r-n)}function st(t,e,n,r){return{subpath:0,type:"L",points:[n,r],startX:t,startY:e,endX:n,endY:r,length:Math.hypot(n-t,r-e)}}function _t(t,e,n){const[r,s,a,i,o,c]=n,h=[0];let l=t,u=e,m=0;for(let d=1;d<=$e;d++){const y=d/$e,g=U(t,r,a,o,y),_=U(e,s,i,c,y);m+=Math.hypot(g-l,_-u),h.push(m),l=g,u=_}return{subpath:0,type:"C",points:[r,s,a,i,o,c],startX:t,startY:e,endX:o,endY:c,length:m,lengths:h}}function B(t){const e=K.get(t);if(e)return e;const n=[];let r=0,s=0,a=0,i=0,o=null,c=null,h=-1;const l=new Set,u=g=>{h<0&&(h=0),g.subpath=h,n.push(g)};for(const{type:g,args:_}of rr(t)){const M=g.toUpperCase(),p=g!==M,T=nr[M];if(M==="Z"){(r!==a||s!==i)&&u(st(r,s,a,i)),h>=0&&l.add(h),r=a,s=i,o=c=null;continue}for(let S=0;S+T<=_.length;S+=T){const b=_.slice(S,S+T),x=p?r:0,P=p?s:0;let I=null,k=null;switch(M){case"M":S===0?(r=b[0]+x,s=b[1]+P,a=r,i=s,(h<0||n[n.length-1]?.subpath===h)&&h++):(u(st(r,s,b[0]+x,b[1]+P)),r=b[0]+x,s=b[1]+P);break;case"L":u(st(r,s,b[0]+x,b[1]+P)),r=b[0]+x,s=b[1]+P;break;case"H":u(st(r,s,b[0]+x,s)),r=b[0]+x;break;case"V":u(st(r,s,r,b[0]+P)),s=b[0]+P;break;case"C":{const w=[b[0]+x,b[1]+P,b[2]+x,b[3]+P,b[4]+x,b[5]+P];u(_t(r,s,w)),I=[w[2],w[3]],r=w[4],s=w[5];break}case"S":{const[w,A]=o?[2*r-o[0],2*s-o[1]]:[r,s],v=[w,A,b[0]+x,b[1]+P,b[2]+x,b[3]+P];u(_t(r,s,v)),I=[v[2],v[3]],r=v[4],s=v[5];break}case"Q":case"T":{let w=r,A=s;M==="Q"?(w=b[0]+x,A=b[1]+P):c&&(w=2*r-c[0],A=2*s-c[1]);const v=M==="Q"?b[2]+x:b[0]+x,E=M==="Q"?b[3]+P:b[1]+P;u(_t(r,s,[r+2/3*(w-r),s+2/3*(A-s),v+2/3*(w-v),E+2/3*(A-E),v,E])),k=[w,A],r=v,s=E;break}case"A":{const w=b[5]+x,A=b[6]+P;let v=r,E=s;for(const R of sr(r,s,b[0],b[1],b[2],b[3],b[4],w,A))u(_t(v,E,R)),v=R[4],E=R[5];r=w,s=A;break}}o=I,c=k}}const m=n.reduce((g,_)=>g+_.length,0),d=[];for(let g=0;g<n.length;){const _=n[g].subpath;let M=g,p=0;for(;M<n.length&&n[M].subpath===_;)p+=n[M++].length;const T=n[g],S=n[M-1],b=l.has(_)||Math.abs(S.endX-T.startX)<1e-9&&Math.abs(S.endY-T.startY)<1e-9;d.push({start:g,end:M,length:p,closed:b}),g=M}const y={segments:n,totalLength:m,subpaths:d};return K.size>=Zn&&K.delete(K.keys().next().value),K.set(t,y),y}function ar(t,e){const n=t.lengths;if(e<=0)return 0;if(e>=t.length)return 1;let r=0,s=n.length-1;for(;r<s-1;){const o=r+s>>1;n[o]<e?r=o:s=o}const a=n[s]-n[r],i=a>0?(e-n[r])/a:0;return(r+i)/(n.length-1)}function ir(t,e){if(t.type==="L"){const u=t.length>0?Math.max(0,Math.min(1,e/t.length)):0;return{x:t.startX+(t.endX-t.startX)*u,y:t.startY+(t.endY-t.startY)*u,angle:Math.atan2(t.endY-t.startY,t.endX-t.startX)*180/Math.PI}}const[n,r,s,a,i,o]=t.points,c=ar(t,e);let h=Oe(t.startX,n,s,i,c),l=Oe(t.startY,r,a,o,c);if(Math.hypot(h,l)<1e-9){const u=c<.5?Math.min(1,c+.001):Math.max(0,c-.001),m=U(t.startX,n,s,i,u),d=U(t.startY,r,a,o,u),y=U(t.startX,n,s,i,c),g=U(t.startY,r,a,o,c);h=c<.5?m-y:y-m,l=c<.5?d-g:g-d}return{x:U(t.startX,n,s,i,c),y:U(t.startY,r,a,o,c),angle:Math.atan2(l,h)*180/Math.PI}}function Xt(t,e,n=0,r=t.length){if(r<=n)return{x:0,y:0,angle:0};let s=0;for(let a=n;a<r;a++){const i=t[a];if(s+i.length>=e||a===r-1)return ir(i,e-s);s+=i.length}return{x:0,y:0,angle:0}}function Le(t,e){const{segments:n,totalLength:r}=B(t);return Xt(n,Math.max(0,Math.min(1,e))*r)}function or(){K.clear()}function cr(t){return B(t).totalLength}const ur=24,hr=320,lr=2.5,at=72,fr=64,dr=.2,mr=128,it=new Map;let bt=0,V;const Fe=t=>Math.round(t*100)/100;function Ne(t,e){const{segments:n,subpaths:r,totalLength:s}=B(t);if(n.length===0)return[];if(e){const a=r.every(i=>i.closed);return[{segments:n,start:0,end:n.length,length:s,closed:a}]}return r.filter(a=>a.length>0).map(a=>({segments:n,start:a.start,end:a.end,length:a.length,closed:a.closed}))}function Yt(t,e){const n=t.closed?(e%1+1)%1:Math.max(0,Math.min(1,e)),r=Xt(t.segments,n*t.length,t.start,t.end);return[r.x,r.y]}function Xe(t){const e=[];let n=0;for(let r=t.start;r<t.end;r++)n+=t.segments[r].length,t.length>0&&e.push(n/t.length);return e}function Ye(t,e){const n=[];for(let r=0;r<e;r++)n.push(Yt(t,t.closed?r/e:r/(e-1)));return n}function ze(t){let e=0,n=0;for(const[r,s]of t)e+=r,n+=s;return e/=t.length,n/=t.length,t.map(([r,s])=>[r-e,s-n])}function gr(t,e,n){const r=t.closed&&e.closed;if(n!==void 0)return{offset:r?Math.abs(n)%at/at:0,reversed:n<0};const s=ze(Ye(t,at)),a=ze(Ye(e,at)),i=at;let o={offset:0,reversed:!1},c=1/0;for(const h of[!1,!0]){const l=r?i:1;for(let u=0;u<l;u++){let m=0;for(let d=0;d<i&&m<c;d++){const y=r?h?(u-d+i)%i:(d+u)%i:h?i-1-d:d,g=s[d][0]-a[y][0],_=s[d][1]-a[y][1];m+=g*g+_*_}m<c&&(c=m,o={offset:r?u/i:0,reversed:h})}}return o}function yr(t,e,n){return n?((e.reversed?e.offset-t:t+e.offset)%1+1)%1:e.reversed?1-t:t}function pr(t,e,n){return n?((e.reversed?e.offset-t:t-e.offset)%1+1)%1:e.reversed?1-t:t}function Mr(t,e,n){const r=t.closed&&e.closed,s=gr(t,e,n.shapeIndex),a=Math.max(ur,Math.min(hr,Math.ceil(Math.max(t.length,e.length)/lr))),i=new Set,o=u=>i.add(Math.round(u*1e7)/1e7);for(let u=0;u<=a;u++)o(u/a);for(const u of Xe(t))o(u);for(const u of Xe(e))o(pr(u,s,r));let c=[...i].sort((u,m)=>u-m);r&&(c=c.filter(u=>u<1));const h=[],l=[];for(const u of c)h.push(...Yt(t,u)),l.push(...Yt(e,yr(u,s,r)));return _r({from:h,to:l,closed:r})}function _r(t){const e=t.from.length/2;if(e<=3)return t;const n=new Uint8Array(e);n[0]=1,n[e-1]=1;const r=[[0,e-1]];for(;r.length>0;){const[i,o]=r.pop();let c=-1,h=dr;for(let l=i+1;l<o;l++){const u=Math.max(Ue(t.from,i,o,l),Ue(t.to,i,o,l));u>h&&(h=u,c=l)}c!==-1&&(n[c]=1,r.push([i,c],[c,o]))}const s=[],a=[];for(let i=0;i<e;i++)n[i]&&(s.push(t.from[i*2],t.from[i*2+1]),a.push(t.to[i*2],t.to[i*2+1]));return{from:s,to:a,closed:t.closed}}function Ue(t,e,n,r){const s=t[e*2],a=t[e*2+1],i=t[n*2]-s,o=t[n*2+1]-a,c=t[r*2]-s,h=t[r*2+1]-a,l=i*i+o*o,u=l===0?0:Math.max(0,Math.min(1,(c*i+h*o)/l));return Math.hypot(c-u*i,h-u*o)}function br(t,e,n){const r=n.shapeIndex;if(V&&V.from===t&&V.to===e&&V.shapeIndex===r)return V.plan;const a=it.get(String(r??"auto"))?.get(t)?.get(e);if(a)return V={from:t,to:e,shapeIndex:r,plan:a},a;const i=B(t).subpaths.filter(d=>d.length>0).length===B(e).subpaths.filter(d=>d.length>0).length,o=Ne(t,!i),c=Ne(e,!i),h={pairs:o.map((d,y)=>Mr(d,c[y],n))};bt>=mr&&(it.clear(),bt=0);const l=String(r??"auto"),u=it.get(l)??new Map;it.set(l,u);const m=u.get(t)??new Map;return u.set(t,m),m.set(e,h),bt++,V={from:t,to:e,shapeIndex:r,plan:h},h}function Ve(t,e,n,r={}){if(!t)return e;if(!e)return t;const s=Math.max(0,Math.min(1,n));if(s===0)return t;if(s===1)return e;const a=br(t,e,r);if(a.pairs.length===0)return s<.5?t:e;let i="";for(const o of a.pairs){for(let c=0;c<o.from.length;c+=2){const h=Fe(o.from[c]+(o.to[c]-o.from[c])*s),l=Fe(o.from[c+1]+(o.to[c+1]-o.from[c+1])*s);i+=`${c===0?i?" M":"M":" L"}${h} ${l}`}o.closed&&(i+=" Z")}return i}function Tr(){it.clear(),bt=0,V=void 0}function je(t){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(t)}const W=Math.PI/180,kr=.9995;function zt(){return[0,0,0,1]}function Tt(t,e){const n=Math.hypot(t[0],t[1],t[2]);if(n===0)return zt();const r=e*W/2,s=Math.sin(r)/n;return[t[0]*s,t[1]*s,t[2]*s,Math.cos(r)]}function wr(t,e,n){return Ut(Ut(Tt([0,1,0],e),Tt([1,0,0],t)),Tt([0,0,1],n))}function Sr(t){const[e,n,r,s]=H(t),a=2*(e*r+n*s),i=2*(e*n+r*s),o=1-2*(e*e+r*r),c=2*(n*r-e*s),h=1-2*(n*n+r*r),l=2*(e*r-n*s),u=1-2*(e*e+n*n),m=Math.asin(Math.max(-1,Math.min(1,-c)));return Math.abs(c)<.9999999?[m/W,Math.atan2(a,u)/W,Math.atan2(i,o)/W]:[m/W,Math.atan2(-l,h)/W,0]}function Ut(t,e){const[n,r,s,a]=t,[i,o,c,h]=e;return[a*i+n*h+r*c-s*o,a*o-n*c+r*h+s*i,a*c+n*o-r*i+s*h,a*h-n*i-r*o-s*c]}function Be(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function He(t){return Math.hypot(t[0],t[1],t[2],t[3])}function H(t){const e=He(t);return e===0?zt():[t[0]/e,t[1]/e,t[2]/e,t[3]/e]}function Pr(t){return[-t[0],-t[1],-t[2],t[3]]}function qe(t,e,n){const r=H(t);let s=H(e),a=Be(r,s);if(a<0&&(s=[-s[0],-s[1],-s[2],-s[3]],a=-a),a>kr)return H([r[0]+(s[0]-r[0])*n,r[1]+(s[1]-r[1])*n,r[2]+(s[2]-r[2])*n,r[3]+(s[3]-r[3])*n]);const i=Math.acos(a),o=Math.sin(i),c=Math.sin((1-n)*i)/o,h=Math.sin(n*i)/o;return H([r[0]*c+s[0]*h,r[1]*c+s[1]*h,r[2]*c+s[2]*h,r[3]*c+s[3]*h])}function Ar(t,e){const[n,r,s,a]=H(t),i=2*(r*e[2]-s*e[1]),o=2*(s*e[0]-n*e[2]),c=2*(n*e[1]-r*e[0]);return[e[0]+a*i+(r*c-s*o),e[1]+a*o+(s*i-n*c),e[2]+a*c+(n*o-r*i)]}const xr=Object.freeze(Object.defineProperty({__proto__:null,conjugate:Pr,dot:Be,fromAxisAngle:Tt,fromEuler:wr,identity:zt,length:He,multiply:Ut,normalize:H,rotateVec3:Ar,slerp:qe,toEuler:Sr},Symbol.toStringTag,{value:"Module"})),F=(t,e,n)=>t+(e-t)*n,Qe=512,Vt=new Map,jt=new Map;function Ge(t){const e=Vt.get(t);if(e)return e;const n=t.replace("#",""),r=[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)];return Vt.size<Qe&&Vt.set(t,r),r}const Ke=t=>t.charCodeAt(0)===35,We=t=>t.startsWith("rgb"),Je=t=>t.startsWith("rgba"),vr=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,Bt=t=>Math.round(t).toString(16).padStart(2,"0");function Ir(t,e,n){return`#${Bt(t)}${Bt(e)}${Bt(n)}`}function Ze(t){const e=jt.get(t);if(e)return e;const n=t.match(vr);if(!n)throw new Error(`Invalid rgb color: ${t}`);const r=parseInt(n[1],10),s=parseInt(n[2],10),a=parseInt(n[3],10),i=n[4]!==void 0?[r,s,a,parseFloat(n[4])]:[r,s,a];return jt.size<Qe&&jt.set(t,i),i}const tn=(t,e,n)=>{if(Ke(t)&&Ke(e)){const[r,s,a]=Ge(t),[i,o,c]=Ge(e),h=F(r,i,n),l=F(s,o,n),u=F(a,c,n);return Ir(h,l,u)}if((We(t)||Je(t))&&(We(e)||Je(e))){const r=Ze(t),s=Ze(e),a=Math.round(F(r[0],s[0],n)),i=Math.round(F(r[1],s[1],n)),o=Math.round(F(r[2],s[2],n));if(r.length===4||s.length===4){const c=r[3]??1,h=s[3]??1,l=F(c,h,n);return`rgba(${a}, ${i}, ${o}, ${l})`}return`rgb(${a}, ${i}, ${o})`}return n<1?t:e},en=(t,e,n)=>{const r=Math.min(t.length,e.length),s=[];for(let a=0;a<r;a++)s.push(F(t[a],e[a],n));return s},nn=(t,e,n)=>qe(t,e,n),Ht=(t,e,n)=>n<1?t:e,rn=(t,e,n)=>Ve(t,e,n);function qt(t,e){return e==="slerp"?nn:typeof t=="number"?F:Array.isArray(t)?en:typeof t=="string"?t.startsWith("#")||t.startsWith("rgb")?tn:je(t)?rn:Ht:Ht}const Qt=1e3/60;function Gt(t,e={}){if(!z(t))throw new Error(`bakeSpringTrack: track "${t.id}" is not a spring track`);const n=new et(t.spring);return sn(t,r=>n.valueAt(r),n.settleTime(),t.spring.from,t.spring.to,e)}function Kt(t,e={}){if(!Y(t))throw new Error(`bakeInertiaTrack: track "${t.id}" is not an inertia track`);const n=t.inertia;return sn(t,r=>yt(n,r),rt(n),n.from,nt(n),e)}function sn(t,e,n,r,s,a){const i=a.intervalMs??Qt,o=a.tolerance??.01,c=t.delay??0,h=[];for(let u=0;u<=n;u+=i)h.push({time:u+c,value:e(u),easing:"linear"});const l=h[h.length-1];return!l||l.time<n+c?h.push({time:n+c,value:s,easing:"linear"}):l.value=s,c>0&&h.unshift({time:0,value:r,easing:"linear"}),{id:t.id,target:t.target,property:t.property,keyframes:o>0?cn(h,o):h,...t.targets&&{targets:[...t.targets]},...t.stagger&&{stagger:{...t.stagger}}}}function an(t,e,n,r={}){const s=r.intervalMs??Qt,a=typeof n=="function"?n:Mt(n),i=qt(t.value,r.interpolation),o=e.time-t.time;if(o<=0)return[e];const c=[];for(let l=s;l<o;l+=s){const u=l/o;c.push({time:t.time+l,value:i(t.value,e.value,a(u)),easing:"linear"})}const h=a(1);return c.push({...e,...h!==1&&{value:i(t.value,e.value,h)},easing:"linear"}),c}function Rr(t,e){return z(t)?Gt(t,e):Y(t)?Kt(t,e):t}function on(t,e={}){const n=t.keyframes;if(!n.some(a=>lt(a.easing)))return t;const r=n.length>0?[n[0]]:[],s={...e,interpolation:t.interpolation??e.interpolation};for(let a=1;a<n.length;a++){const i=n[a];lt(i.easing)?r.push(...an(n[a-1],i,i.easing,s)):r.push(i)}return{...t,keyframes:r}}function Er(t,e){return t.filter(ye).map(n=>on(n,e)).concat(t.filter(z).map(n=>Gt(n,e)),t.filter(Y).map(n=>Kt(n,e)))}function cn(t,e){if(t.length<=2)return t;const n=[t[0]];for(let r=1;r<t.length-1;r++){const s=n[n.length-1],a=t[r],i=t[r+1],o=i.time-s.time;if(o<=0)continue;const c=(a.time-s.time)/o,h=s.value+(i.value-s.value)*c;Math.abs(a.value-h)>e&&n.push(a)}return n.push(t[t.length-1]),n}function un(t){const e=[...t.keyframes].sort((n,r)=>n.time-r.time);return{...t,keyframes:e}}function j(t){return t.targets&&t.targets.length>0?t.targets:[t.target]}function J(t,e,n,r){const s=n??0;return!r||e<=1?s:s+Ct(t,e,r)}class ot{track;targets;constructor(e){this.track=e,this.targets=j(e)}getValueAtTime(e){return this.valueForOffset(e-J(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,r=[];for(let s=0;s<n;s++){const a=J(s,n,this.track.delay,this.track.stagger),i=this.valueForOffset(e-a);i!==void 0&&r.push({target:this.targets[s],value:i,start:a+this.track.keyframes[0].time})}return r}getDuration(){const{keyframes:e}=this.track;if(e.length===0)return 0;const n=e[e.length-1].time,r=this.track.stagger?dt(this.targets.length,this.track.stagger):0;return n+(this.track.delay??0)+r+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(e){const{keyframes:n}=this.track;if(n.length===0)return;if(n.length===1||e<=n[0].time)return n[0].value;if(e>=n[n.length-1].time)return n[n.length-1].value;const{from:r,to:s}=this.findSurroundingKeyframes(e);if(!r||!s)return;if(r.time===e)return r.value;const a=s.time-r.time,i=(e-r.time)/a,c=Mt(s.easing)(i);return qt(r.value,this.track.interpolation)(r.value,s.value,c)}findSurroundingKeyframes(e){const{keyframes:n}=this.track;for(let r=0;r<n.length-1;r++)if(e>=n[r].time&&e<=n[r+1].time)return{from:n[r],to:n[r+1]};return{from:null,to:null}}}class hn{track;targets;sampler;constructor(e){this.track=e,this.targets=j(e),this.sampler=new et(e.spring)}getValueAtTime(e){return this.sampler.valueAt(e-J(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,r=[];for(let s=0;s<n;s++){const a=J(s,n,this.track.delay,this.track.stagger);r.push({target:this.targets[s],value:this.sampler.valueAt(e-a),start:a})}return r}getDuration(){const e=this.track.stagger?dt(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+e}getTrack(){return this.track}}class ln{track;targets;duration;constructor(e){this.track=e,this.targets=j(e),this.duration=rt(e.inertia)}getValueAtTime(e){return yt(this.track.inertia,e-J(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,r=[];for(let s=0;s<n;s++){const a=J(s,n,this.track.delay,this.track.stagger);r.push({target:this.targets[s],value:yt(this.track.inertia,e-a),start:a})}return r}getDuration(){const e=this.track.stagger?dt(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+e}getTrack(){return this.track}}function Wt(t,e){const n={...Le(t.pathData,e)};if(t.matrix){const[r,s,a,i,o,c]=t.matrix,{x:h,y:l}=n;n.x=r*h+a*l+o,n.y=s*h+i*l+c;const u=n.angle*Math.PI/180,m=Math.cos(u),d=Math.sin(u);n.angle=Math.atan2(s*m+i*d,r*m+a*d)*180/Math.PI}return t.autoRotate&&t.rotateOffset&&(n.angle+=t.rotateOffset),n}function Cr(t,e,n,r){const s=e+(n-e)*r;return Wt(t,s)}const Jt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},Dr=20;function fn(t){const e=Jt[t??"upperCase"]??t??Jt.upperCase,n=Array.from(e);return n.length>0?n:Array.from(Jt.upperCase)}function $r(t,e,n){let r=(t|0)^Math.imul(e+1,2654435761)^Math.imul(n+1,2246822507);return r=Math.imul(r^r>>>16,2146121005),r=Math.imul(r^r>>>15,2221713035),(r^r>>>16)>>>0}function dn(t,e,n=0){const r=t.from??"",s=t.to,a=Math.max(0,Math.min(1,e));if(a<=0)return r;if(a>=1)return s;const i=Array.from(r),o=Array.from(s),c=t.rightToLeft??!1;if(t.mode==="type"){const p=Math.round(a*Math.max(i.length,o.length));return c?i.slice(0,Math.max(0,i.length-p)).join("")+o.slice(Math.max(0,o.length-p)).join(""):o.slice(0,p).join("")+i.slice(p).join("")}const h=Math.max(0,Math.min(.999,t.revealDelay??0)),l=Math.max(0,(a-h)/(1-h)),u=Math.floor(l*o.length),m=t.tweenLength===!1?o.length:Math.round(i.length+(o.length-i.length)*a),d=fn(t.chars),y=t.refreshRate??Dr,g=y>0?Math.floor(n*y/1e3):0,_=t.seed??1;let M="";for(let p=0;p<m;p++){const T=c?p>=m-u:p<u,S=c?o[o.length-(m-p)]:o[p];T&&S!==void 0||S===" "||S===`
2
- `?M+=S:M+=d[$r(_,p,g)%d.length]}return M}class Zt{id;name;_captions;_tracks=[];_trackPlayers=new Map;_motionPathTracks=new Map;_springTracks=new Map;_textTracks=new Map;_config;_currentTime=0;_playbackState="idle";_direction="forward";_loopIteration=0;_explicitDuration;_repeatDelayRemaining=0;_wrapAfterDelay=!1;onUpdate=null;onComplete=null;constructor(e){if(this.id=e.id,this.name=e.name,this._captions=e.captions,this._config=e.config??{},this._explicitDuration=e.config?.duration,e.tracks)for(const n of e.tracks)this.addTrack(n)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(e){if(this._explicitDuration=e,e!==void 0)this._config={...this._config,duration:e};else if(this._config.duration!==void 0){const n={...this._config};delete n.duration,this._config=n}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(e){this._config.speed=e}get drawingRate(){return this._config.drawingRate??0}set drawingRate(e){const n={...this._config};e>0?n.drawingRate=e:delete n.drawingRate,this._config=n}play(){const e=this.duration;this._direction==="forward"&&this._currentTime>=e&&e>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&e>0&&(this._currentTime=e,this._loopIteration=0),this._playbackState="playing"}pause(){this._playbackState="paused"}stop(){this._playbackState="idle",this._repeatDelayRemaining=0,this._wrapAfterDelay=!1,this._currentTime=0,this._loopIteration=0,this._direction="forward"}seek(e){const n=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(e,n)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(e){if(this._playbackState!=="playing")return;const n=this.duration;if(n<=0)return;let s=e*this.speed;if(this._repeatDelayRemaining>0){const o=Math.min(this._repeatDelayRemaining,s);if(this._repeatDelayRemaining-=o,s-=o,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const a=1e3;for(let o=0;o<a&&s>0&&this._playbackState==="playing";o++)if(this._direction==="forward"){const c=n-this._currentTime;if(s>=c){if(s-=c,this._currentTime=n,!this._handleEndReached())break}else this._currentTime+=s,s=0}else{const c=this._currentTime;if(s>=c){if(s-=c,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=s,s=0}const i=this.getStateAtTime(this._currentTime);this.onUpdate?.(i)}getStateAtTime(e){const n=new Map;if(e=pe(e,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(e,n);else for(const[r,s]of this._trackPlayers){const a=s.getTrack().property;for(const{target:i,value:o,start:c}of s.getTargetValues(e))this._write(n,r,i,a,o,e-c)}return{values:n,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(e,n){const r=new Map;for(const[s,a]of this._trackPlayers){const i=a.getTrack().property;for(const{target:o,value:c,start:h}of a.getTargetValues(e)){const l=`${o}\0${i}`,u=h<=e,m=r.get(l);(!m||(u!==m.started?u:u?h>=m.start:h<=m.start))&&r.set(l,{trackId:s,target:o,property:i,value:c,start:h,started:u})}}for(const{trackId:s,target:a,property:i,value:o,start:c}of r.values())this._write(n,s,a,i,o,e-c)}_write(e,n,r,s,a,i){if(a===void 0)return;let o=e.get(r);o||(o=new Map,e.set(r,o));const c=this._textTracks.get(n);if(c&&typeof a=="number"){o.set("text",dn(c.textConfig,a,Math.max(0,i)));return}const h=this._motionPathTracks.get(n);if(h&&typeof a=="number"){const l=Wt(h.motionPathConfig,a);o.set("motionPathX",l.x),o.set("motionPathY",l.y),h.motionPathConfig.autoRotate&&o.set("motionPathRotate",l.angle)}else o.set(s,a)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const e=new Set;this._sharedWrites=!1;t:for(const n of this._tracks)for(const r of j(n)){const s=`${r}\0${n.property}`;if(e.has(s)){this._sharedWrites=!0;break t}e.add(s)}}return this._sharedWrites}addTrack(e){if(this._tracks.push(e),this._sharedWrites=null,Y(e)){this._trackPlayers.set(e.id,new ln(e));return}if(z(e)){this._trackPlayers.set(e.id,new hn(e)),this._springTracks.set(e.id,e);return}if(ft(e))this._trackPlayers.set(e.id,new ot(e)),this._textTracks.set(e.id,e);else if(Rt(e)){const n={id:e.id,target:e.target,property:e.property,keyframes:e.keyframes,delay:e.delay,endDelay:e.endDelay,targets:e.targets,stagger:e.stagger};this._trackPlayers.set(e.id,new ot(n)),this._motionPathTracks.set(e.id,e)}else this._trackPlayers.set(e.id,new ot(e))}replaceTrack(e,n){const r=this._tracks.findIndex(a=>a.id===e);if(r<0)return;const s=this._tracks.slice(r+1);this.removeTrack(e);for(const a of s)this.removeTrack(a.id);this.addTrack(n);for(const a of s)this.addTrack(a)}removeTrack(e){this._tracks=this._tracks.filter(n=>n.id!==e),this._sharedWrites=null,this._trackPlayers.delete(e),this._motionPathTracks.delete(e),this._springTracks.delete(e),this._textTracks.delete(e)}getTracks(e={}){return this._tracks.filter(n=>this._matches(n,e))}removeTracks(e={}){const n=this.getTracks(e).map(r=>r.id);for(const r of n)this.removeTrack(r);return n}getTrackSpan(e){const n=this._trackPlayers.get(e);if(!n)return;const r=n.getTrack(),s=r.delay??0;if(z(r)||Y(r))return{from:s,to:n.getDuration()};const a=r.keyframes;if(!(!a||a.length===0))return{from:a[0].time+s,to:n.getDuration()}}findConflicts(){const e=[];for(let n=0;n<this._tracks.length;n++){const r=this._tracks[n],s=this.getTrackSpan(r.id);if(s)for(let a=0;a<n;a++){const i=this._tracks[a];if(i.property!==r.property)continue;const o=j(i).filter(u=>j(r).includes(u));if(o.length===0)continue;const c=this.getTrackSpan(i.id);if(!c||!(c.from<=s.to&&s.from<=c.to))continue;const l=s.from>=c.from;for(const u of o)e.push({target:u,property:r.property,losingTrackId:l?i.id:r.id,winningTrackId:l?r.id:i.id})}}return e}_matches(e,n){if(n.id!==void 0&&e.id!==n.id||n.property!==void 0&&e.property!==n.property||n.target!==void 0&&!j(e).includes(n.target))return!1;if(n.timeRange){const r=this.getTrackSpan(e.id);if(!r||r.to<n.timeRange.from||r.from>n.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:It(this._tracks),id:this.id,name:this.name,config:{...this._config},tracks:[...this._tracks],...this.captions&&{captions:this.captions}}}get config(){return this._config}get markers(){return[...this._config.markers??[]].sort((e,n)=>e.time-n.time)}setMarkers(e){const n=e&&e.length>0?[...e].sort((s,a)=>s.time-a.time).map(s=>({...s})):void 0,r={...this._config};n?r.markers=n:delete r.markers,this._config=r}get captions(){return this._captions}setCaptions(e){const n={};for(const[r,s]of Object.entries(e??{}))n[r]={...s};this._captions=Object.keys(n).length>0?n:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let e=0;for(const[,n]of this._trackPlayers)e=Math.max(e,n.getDuration());return e}_handleEndReached(){const e=this._config.loop??0;return e===-1||this._loopIteration<e?(this._loopIteration++,this._armRepeatDelay(),this._config.alternate?this._direction="reverse":this._repeatDelayRemaining>0?this._wrapAfterDelay=!0:this._currentTime=0,this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}_handleStartReached(){const e=this._config.loop??0;return this._config.alternate&&(e===-1||this._loopIteration<e)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const Or=100;function Lr(t,e,n,r){const s=[],a=[],{duration:i,alternate:o}=r,c=(d,y,g,_)=>{a.push([d,y]);const M=[];t.forEach((p,T)=>{(g==="forward"?(_?p>=d:p>d)&&p<=y:(_?p<=d:p<d)&&p>=y)&&M.push(T)}),M.sort((p,T)=>(g==="forward"?t[p]-t[T]:t[T]-t[p])||p-T);for(const p of M)s.push({kind:"event",index:p,direction:g})};let h=e.time,l=e.direction,u=e.fresh===!0;const m=Math.min(Or,Math.max(0,n.iteration-e.iteration));for(let d=0;d<m;d++){const y=l==="forward"?i:0;c(h,y,l,u),s.push({kind:"repeat"}),o?(l=l==="forward"?"reverse":"forward",h=y,u=!1):(h=l==="forward"?0:i,u=!0)}return m>0&&r.holding&&!o?{crossings:s,passes:a}:(c(h,n.time,l,u),{crossings:s,passes:a})}function mn(t){return Y(t)?{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:gn(t.inertia),...N(t)}:z(t)?{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...N(t)}:ft(t)?{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:t.keyframes.map(te),...N(t)}:Rt(t)?{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:t.keyframes.map(te),...N(t)}:{id:t.id,target:t.target,property:t.property,keyframes:t.keyframes.map(te),...t.interpolation!==void 0&&{interpolation:t.interpolation},...N(t)}}function gn(t){return{...t,...Array.isArray(t.end)&&{end:[...t.end]}}}function te(t){return{time:t.time,value:t.value,...t.easing&&{easing:t.easing}}}function N(t){const e=t.endDelay;return{...t.delay!==void 0&&{delay:t.delay},...e!==void 0&&{endDelay:e},...t.targets!==void 0&&{targets:[...t.targets]},...t.stagger!==void 0&&{stagger:{...t.stagger}}}}function yn(t){if(Y(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"inertia",inertia:gn(e.inertia),...N(e)}}if(z(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"spring",spring:{...e.spring},...N(e)}}if(ft(t)){const e=t;return{id:e.id,target:e.target,property:"text",textConfig:{...e.textConfig},keyframes:[...e.keyframes].sort((n,r)=>n.time-r.time),...N(e)}}if(t.property==="motionPath"&&"motionPathConfig"in t){const e=t,n=[...e.keyframes].sort((r,s)=>r.time-s.time);return{id:e.id,target:e.target,property:"motionPath",motionPathConfig:{...e.motionPathConfig},keyframes:n,...N(e)}}return un({id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,...t.interpolation!==void 0&&{interpolation:t.interpolation},...N(t)})}function pn(t){const e=t._config.markers;return{formatVersion:It(t.tracks),id:t.id,name:t.name,config:{duration:t.duration>0?t.duration:void 0,loop:t._config.loop,speed:t._config.speed,alternate:t._config.alternate,repeatDelay:t._config.repeatDelay,...t._config.drawingRate?{drawingRate:t._config.drawingRate}:{},...e&&{markers:e.map(n=>({...n}))}},tracks:t.tracks.map(mn),...t.captions&&{captions:JSON.parse(JSON.stringify(t.captions))}}}function Mn(t){const e=t.formatVersion??1;if(e>vt)throw new Error(`tinyfly: this animation uses format version ${e}, but this tinyfly reads up to version ${vt}. Update tinyfly to play it.`);return new Zt({id:t.id,name:t.name,config:t.config,tracks:t.tracks.map(yn),captions:t.captions})}function Fr(t){return JSON.stringify(pn(t))}function Nr(t){const e=JSON.parse(t);return Mn(e)}function _n(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e>>>0}function ee(t){let e=t>>>0||2654435769;return{seed:t>>>0,next(){return e^=e<<13,e>>>=0,e^=e>>17,e^=e<<5,e>>>=0,e/4294967296}}}function ne(t,e,n){return e+t.next()*(n-e)}function bn(t,e,n,r){if(r<=0)return ne(t,e,n);const s=Math.floor((n-e)/r),a=Math.round(t.next()*s);return e+a*r}function Xr(t,e){if(e.length!==0)return e[Math.floor(t.next()*e.length)]}const Tn=/^([+\-*/])=\s*(-?[\d.]+)$/,kn=/^random\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*(?:,\s*(-?[\d.]+)\s*)?\)$/i;function Yr(t){return typeof t!="string"?!1:Tn.test(t.trim())||kn.test(t.trim())}function re(t,e={}){if(typeof t!="string")return t;const n=t.trim(),r=Tn.exec(n);if(r){const[,a,i]=r,o=e.base??0,c=Number.parseFloat(i);switch(a){case"+":return o+c;case"-":return o-c;case"*":return o*c;case"/":return c===0?o:o/c}}const s=kn.exec(n);if(s){if(!e.random)throw new Error(`resolveValue: "${n}" needs a random source — pass one via context.random`);const a=Number.parseFloat(s[1]),i=Number.parseFloat(s[2]),o=s[3]!==void 0?Number.parseFloat(s[3]):void 0;return o!==void 0?bn(e.random,a,i,o):ne(e.random,a,i)}return t}function wn(t,e=0,n){const r=[];let s=e;for(const a of t){const i=re(a,{base:s,random:n});r.push(i),typeof i=="number"&&(s=i)}return r}class zr{random;constructor(e){this.random=ee(e)}get seed(){return this.random.seed}resolve(e,n=0){return re(e,{base:n,random:this.random})}resolveSequence(e,n=0){return wn(e,n,this.random)}}const Ur=600;function Vr(t){if(Array.isArray(t)){const[m,d,y,g]=t;return{fn:Sn(m,d,y,g),bezier:[m,d,y,g]}}const{segments:e}=B(t);if(e.length===0)throw new Error(`customEase: no curve in "${t}"`);const n=e[0].startX,r=e[0].startY,s=e[e.length-1],a=s.endX-n,i=s.endY-r;if(a===0||i===0)throw new Error(`customEase: "${t}" must move along both axes`);const o=m=>(m-n)/a,c=m=>(m-r)/i;if(e.length===1&&s.type==="C"){const[m,d,y,g]=s.points,_=[o(m),c(d),o(y),c(g)];return{fn:Sn(..._),bezier:_}}const h=[],l=[],u=Math.max(8,Math.ceil(Ur/e.length));for(const m of e)for(let d=h.length===0?0:1;d<=u;d++){const[y,g]=Hr(m,d/u);h.push(o(y)),l.push(c(g))}return{fn:qr(h,l)}}function jr(t={}){const n=.1+Math.max(0,Math.min(1,t.strength??.7))*.7,r=[1];for(let a=n;a>.002;a*=n)r.push(2*Math.sqrt(a));const s=r.reduce((a,i)=>a+i,0);return a=>{if(a<=0)return 0;if(a>=1)return 1;let i=a*s;for(let o=0;o<r.length;o++){if(i<=r[o]){if(o===0)return(i/r[0])**2;const c=r[o]/2,h=c*c,l=i-c;return 1-(h-l*l)}i-=r[o]}return 1}}function Br(t={}){const e=Math.max(1,t.wiggles??10),n=t.type??"easeOut",r=s=>n==="uniform"?1:n==="easeInOut"?Math.sin(Math.PI*s):(1-s)**2;return s=>s<=0||s>=1?0:Math.sin(s*e*Math.PI*2)*r(s)}function Hr(t,e){if(t.type==="L"){const[h,l]=t.points;return[t.startX+(h-t.startX)*e,t.startY+(l-t.startY)*e]}const[n,r,s,a,i,o]=t.points,c=1-e;return[c*c*c*t.startX+3*c*c*e*n+3*c*e*e*s+e*e*e*i,c*c*c*t.startY+3*c*c*e*r+3*c*e*e*a+e*e*e*o]}function qr(t,e){return n=>{if(n<=t[0])return e[0];if(n>=t[t.length-1])return e[e.length-1];let r=0,s=t.length-1;for(;s-r>1;){const i=r+s>>1;t[i]<=n?r=i:s=i}const a=t[s]-t[r];return a===0?e[s]:e[r]+(n-t[r])/a*(e[s]-e[r])}}function Sn(t,e,n,r){const s=(i,o,c)=>3*(1-i)*(1-i)*i*o+3*(1-i)*i*i*c+i*i*i,a=(i,o,c)=>3*(1-i)*(1-i)*o+6*(1-i)*i*(c-o)+3*i*i*(1-c);return i=>{if(i<=0)return 0;if(i>=1)return 1;let o=i;for(let l=0;l<8;l++){const u=s(o,t,n)-i,m=a(o,t,n);if(Math.abs(u)<1e-6)return s(o,e,r);if(Math.abs(m)<1e-6)break;o-=u/m}let c=0,h=1;o=i;for(let l=0;l<40;l++)s(o,t,n)<i?c=o:h=o,o=(c+h)/2;return s(o,e,r)}}const Qr=350,Gr=300,Kr=550;function Wr(t,e={}){const n=e.lead??Qr,r=e.gap??Gr,s=e.tail??Kr,a=[];let i=0;return t.forEach((o,c)=>{const h=[];let l=i+n;o.lines.forEach((m,d)=>{if(!(m.duration>=0))throw new Error(`narration: scene ${c} line ${d} has an invalid duration (${m.duration})`);d>0&&(l+=r),h.push({id:m.id??`s${c}-l${d}`,scene:c,line:d,start:l,end:l+m.duration,text:m.text}),l+=m.duration});const u=l+s+(o.tail??0);a.push({id:o.id??`s${c}`,start:i,duration:u-i,cues:h}),i=u}),{duration:i,scenes:a,cues:a.flatMap(o=>o.cues)}}function Jr(t){return t.cues.map(e=>({id:e.id,time:e.start,label:e.text}))}function Zr(t,e){let n=t.scenes[0];for(const r of t.scenes)if(e>=r.start)n=r;else break;return n}const ct=t=>6e4/t.bpm;function kt(t,e){return t.offset+e*ct(t)}function ut(t,e){return(e-t.offset)/ct(t)}function ts(t,e){return kt(t,Math.round(ut(t,e)))}function es(t,e){return kt(t,Math.ceil(ut(t,e)-1e-9))}function ns(t,e,n){const r=Math.max(1,Math.round(t.beatsPerBar??4)),s=[];if(!(t.bpm>0)||n<e)return s;for(let a=Math.ceil(ut(t,e)-1e-9);;a++){const i=kt(t,a);if(i>n+1e-9)break;s.push({time:i,bar:(a%r+r)%r===0,n:a})}return s}const Z=100;function rs(t,e,n={}){const r=n.minBpm??70,s=n.maxBpm??180,a=Math.max(1,Math.round(e/Z)),i=Math.min(t.length,Math.round((n.maxSeconds??60)*e)),o=Math.floor(i/a);if(o<4)return{bpm:120,offset:0,confidence:0};const c=new Float64Array(o);for(let k=0;k<o;k++){let w=0;for(let A=k*a;A<(k+1)*a;A++)w+=t[A]*t[A];c[k]=Math.log(1e-6+w/a)}const h=new Float64Array(o);for(let k=1;k<o;k++)h[k]=Math.max(0,c[k]-c[k-1]);const l=h.reduce((k,w)=>k+w,0)/o;for(let k=0;k<o;k++)h[k]=Math.max(0,h[k]-l);const u=Math.max(1,Math.floor(60*Z/s)),m=Math.min(o-1,Math.ceil(60*Z/r)),d=k=>{let w=0;for(let A=k;A<o;A++)w+=h[A]*h[A-k];return w/(o-k)};let y=0;for(let k=0;k<o;k++)y+=h[k]*h[k];y/=o;let g=u,_=-1/0;for(let k=u;k<=m;k++){const w=60*Z/k,A=Math.exp(-.5*(Math.log2(w/120)/.9)**2),v=d(k)*A;v>_&&(_=v,g=k)}const M=k=>{const w=Math.floor(k);return w<0||w+1>=o?0:h[w]+(h[w+1]-h[w])*(k-w)},p=(k,w)=>{let A=0;for(let v=w;v<o;v+=k)A+=M(v);return A};let T=g,S=0,b=-1/0;for(let k=g-.6;k<=g+.6+1e-9;k+=.02){if(k<1)continue;const w=Math.max(1,Math.round(k*4));for(let A=0;A<w;A++){const v=A/w*k,E=p(k,v);E>b&&(b=E,S=v,T=k)}}const x=60*Z/T,P=y>0?Math.max(0,Math.min(1,d(g)/y)):0,I=(S+.5)*1e3/Z;return{bpm:Math.round(x*100)/100,offset:Math.round(I%(6e4/x)),confidence:P}}const ss=600,as=250,Pn=1;function is(t,e){const n=e.target??"Camera",r={x:e.stage.width/2,y:e.stage.height/2},s={},a=(u,m,d,y)=>{const g=s[u]??=[];for(;g.length>0&&g[g.length-1].time>=m;)g.pop();g.push({time:m,value:d,...y?{easing:y}:{}})},i=u=>{const m=u.rotate*Math.PI/180,d=(u.focusX-r.x)*u.scale,y=(u.focusY-r.y)*u.scale;return{x:-(d*Math.cos(m)-y*Math.sin(m)),y:-(d*Math.sin(m)+y*Math.cos(m)),scale:u.scale,rotate:u.rotate}},o=(u,m,d)=>{const y=i(m);for(const g of["x","y","scale","rotate"])a(g,u,y[g],d)};let c={focusX:r.x,focusY:r.y,scale:1,rotate:0};const h=[...t].sort((u,m)=>u.at-m.at),l=h.filter(u=>!("shake"in u));l.length>0&&o(0,c);for(const u of l)if("frame"in u){const m=Math.max(Pn,u.duration??ss);o(u.at,c),c={focusX:u.frame.focus?.x??r.x,focusY:u.frame.focus?.y??r.y,scale:u.frame.scale??1,rotate:u.frame.rotate??0},o(u.at+m,c,u.easing??(m>Pn?"ease-in-out":void 0))}else{const{follow:m}=u,d=m.lag??as,y=new Zt({id:"follow",tracks:[{id:"x",target:"s",property:"x",keyframes:m.x}]}),g=p=>y.getStateAtTime(p).values.get("s")?.get("x")??c.focusX,_=[u.at,...m.x.map(p=>p.time).filter(p=>p>u.at&&p<u.until),u.until];o(u.at,c);const M=p=>({focusX:g(p)+(m.lead??0),focusY:m.y??c.focusY,scale:m.scale??c.scale,rotate:c.rotate});for(const p of _){const T=m.x.find(S=>S.time===p)?.easing;o(p+d,M(p),p===u.at?"ease-in-out":T)}c=M(u.until)}for(const u of h.filter(m=>"shake"in m)){const m=u.shake.strength??12,d=u.shake.roll??1.5,y=1e3/(u.shake.frequency??24),g=ee(u.shake.seed??Math.round(u.at)+1),_=()=>g.next()*2-1;for(const M of["shakeX","shakeY","shakeRotate"])a(M,u.at,0);for(let M=u.at+y;M<u.at+u.duration;M+=y){const p=1-(M-u.at)/u.duration;a("shakeX",M,_()*m*p),a("shakeY",M,_()*m*p),a("shakeRotate",M,_()*d*p)}for(const M of["shakeX","shakeY","shakeRotate"])a(M,u.at+u.duration,0,"ease-out")}return Object.entries(s).map(([u,m])=>({id:`${n}-${u}`,target:n,property:u,keyframes:m}))}function An(t,e){const n=t.toLowerCase(),r=e.toLowerCase();let s=Array.from({length:r.length+1},(a,i)=>i);for(let a=1;a<=n.length;a++){const i=[a];for(let o=1;o<=r.length;o++)i[o]=Math.min(s[o]+1,i[o-1]+1,s[o-1]+(n[a-1]===r[o-1]?0:1));s=i}return s[r.length]}function xn(t,e){const n=t.toLowerCase(),r=e.find(i=>i.toLowerCase().includes(n)||n.includes(i.toLowerCase()));if(r&&Math.min(t.length,r.length)>=3)return r;let s,a=1/0;for(const i of e){const o=An(t,i);o<a&&(a=o,s=i)}return s!==void 0&&a<=Math.max(2,Math.floor(t.length/3))?s:void 0}function os(t,e,n,r){const s=typeof e=="string"?r??xn(e,n):void 0;return`Unknown ${t} ${JSON.stringify(e)}${s?`: did you mean "${s}"?`:"."} Known: ${n.join(", ")}`}function cs(t,e){const n=e.step??33,r=e.stiffness??120,s=e.damping??9,a=e.mass??1;let i=t(e.start),o=0;const c=[{time:e.start,value:i}];let h=e.start+n;for(let l=e.start+1;l<=e.end;l++){const m=r*(t(l)-i)-s*o;o+=m/a*.001,i+=o*.001,(l>=h||l===e.end)&&(c.push({time:l,value:i}),h+=n)}return c}function q(t,e,n=1){if(!(e>0))return 0;const r=t*n/e;return r-Math.floor(r)}function se(t){const e=t-Math.floor(t);return 1-Math.abs(e*2-1)}function us(t,e){const n=Math.max(1,Math.round(e.cycles??1)),r=e.amplitude??1,s=q(t,e.period,n)+(e.phase??0),a=s-Math.floor(s);switch(e.shape??"sine"){case"triangle":return r*(se(a+.25)*2-1);case"square":return a<.5?r:-r;default:return r*Math.sin(a*Math.PI*2)}}function hs(t,e){const n=Math.max(1,Math.round(e.cycles??1)),r=typeof e.easing=="function"?e.easing:Mt(e.easing??"ease-in-out"),s=q(t,e.period,n)+(e.phase??0);return r(se(s))}function ls(t,e){const n=vn(e.seed),r=Math.max(1,Math.round(e.cycles??1)),s=(q(t,e.period,1)+(e.phase??0))*Math.PI*2,a=r/Math.PI;return In([Math.cos(s)*a+7.31,Math.sin(s)*a+3.17],n,e.octaves??1)}function fs(t,e,n){const r=vn(n.seed),s=Math.max(1,Math.round(n.cycles??1)),a=Math.max(1,Math.round(n.cyclesAlong??1)),i=q(t,n.period,1)*Math.PI*2,o=q(e,n.periodAlong,1)*Math.PI*2,c=s/Math.PI,h=a/Math.PI;return In([Math.cos(i)*c+5.13,Math.sin(i)*c+9.47,Math.cos(o)*h+2.71,Math.sin(o)*h+6.29],r,n.octaves??1)}const vn=t=>typeof t=="string"?_n(t):(t??0)>>>0;function In(t,e,n){const r=Math.max(1,Math.min(6,Math.round(n)));let s=0,a=1,i=0;for(let o=0;o<r;o++){const c=2**o;s+=a*ds(t.map(h=>h*c),e+o*1013),i+=a,a*=.5}return s/i}function ds(t,e){const n=t.length,r=t.map(Math.floor),a=t.map((o,c)=>o-r[c]).map(o=>o*o*(3-2*o));let i=0;for(let o=0;o<1<<n;o++){let c=1;const h=[];for(let l=0;l<n;l++){const u=o>>l&1;c*=u?a[l]:1-a[l],h.push(r[l]+u)}c!==0&&(i+=c*ms(h,e))}return i}function ms(t,e){let n=(e^2654435769)>>>0;for(const r of t)n=Math.imul(n^(r|0),2246822507)>>>0,n=(n^n>>>13)>>>0,n=Math.imul(n,3266489909)>>>0,n=(n^n>>>16)>>>0;return n/4294967296*2-1}function gs(t,e={}){if(t.length===0)throw new Error("curve: needs at least one key");const r={id:"curve",target:"curve",property:"value",keyframes:t.map(a=>({time:a.at,value:a.value,easing:a.easing})).sort((a,i)=>a.time-i.time),interpolation:e.interpolation},s=new ot(r);return a=>s.getValueAtTime(a)}function ys(t,e){return e*ct({bpm:t.bpm})}function ps(t,e){const n=Math.max(1,Math.round(t/ct(e)));return{beats:n,grid:{...e,bpm:n*6e4/t}}}function Ms(t,e,n={}){const r=Math.max(1e-6,n.attack??.05),s=Math.max(1e-6,n.decay??.4),a=ut(e,t),i=a-Math.floor(a),o=i<r?i/r:Math.max(0,1-(i-r)/s),c=n.barAccent??0;if(c<=0)return o;const h=Math.max(1,Math.round(e.beatsPerBar??4)),u=(Math.floor(a)%h+h)%h===0;return o*(u?1+c:1)/(1+c)}function _s(t,e,n={}){const r=n.fps??30,s=Math.max(1,Math.round(e/r)),a=Math.max(1,Math.ceil(t.length/s)),i=new Float32Array(a),o=Math.min(.99,Math.max(0,n.smoothing??.5));let c=0,h=0;for(let l=0;l<a;l++){let u=0;const m=l*s,d=Math.min(t.length,m+s);for(let g=m;g<d;g++)u+=t[g]*t[g];const y=d>m?Math.sqrt(u/(d-m)):0;c=y>c?y:c*o+y*(1-o),i[l]=c,h=Math.max(h,c)}if(n.normalize!==!1&&h>0)for(let l=0;l<a;l++)i[l]/=h;return i}function bs(t,e,n=30,r){if(t.length===0)return 0;const a=(r?q(e,r)*r:e)*n/1e3,i=Math.floor(a),o=t[Math.min(t.length-1,Math.max(0,i))],c=t[Math.min(t.length-1,Math.max(0,i+1))];return o+(c-o)*(a-i)}const Rn={"16:9":16/9,"2.39:1":2.39,"4:3":4/3,"1:1":1,"9:16":9/16,"4:5":4/5},ae=t=>typeof t=="number"?t:Rn[t];function Ts(t,e){const n=ae(e),r=t.width/t.height;if(n>=r){const a=t.width/n;return{x:0,y:(t.height-a)/2,width:t.width,height:a}}const s=t.height*n;return{x:(t.width-s)/2,y:0,width:s,height:t.height}}function ks(t,e){const n=ae(t),r=s=>Math.max(2,Math.round(s/2)*2);return"width"in e?{width:r(e.width),height:r(e.width/n)}:{width:r(e.height*n),height:r(e.height)}}function ws(t,e={}){const n=r=>({x:t.x+t.width*(1-r)/2,y:t.y+t.height*(1-r)/2,width:t.width*r,height:t.height*r});return{action:n(e.action??.9),title:n(e.title??.8)}}const X=t=>Math.round(t*1e3)/1e3;function Ss(t,e={}){if(t.length===0)return"";const n=e.curviness??1,r=e.closed??!1,s=t.length;let a=`M${X(t[0].x)} ${X(t[0].y)}`;if(s===1)return a;const i=c=>r?t[(c%s+s)%s]:t[Math.max(0,Math.min(s-1,c))],o=r?s:s-1;for(let c=0;c<o;c++){const h=i(c-1),l=i(c),u=i(c+1),m=i(c+2);if(n===0){a+=` L${X(u.x)} ${X(u.y)}`;continue}const d=n/6,y=l.x+(u.x-h.x)*d,g=l.y+(u.y-h.y)*d,_=u.x-(m.x-l.x)*d,M=u.y-(m.y-l.y)*d;a+=` C${X(y)} ${X(g)} ${X(_)} ${X(M)} ${X(u.x)} ${X(u.y)}`}return r?`${a} Z`:a}const D=(t,e=0)=>{const n=parseFloat(t??"");return Number.isFinite(n)?n:e};function Ps(t){const e=(t??"").trim().split(/[\s,]+/).filter(Boolean).map(Number),n=[];for(let r=0;r+1<e.length;r+=2)n.push({x:e[r],y:e[r+1]});return n}function As(t){const e=t.attributes;switch(t.tag.toLowerCase()){case"path":return e.d??null;case"circle":case"ellipse":{const n=D(e.cx),r=D(e.cy),s=t.tag.toLowerCase()==="circle"?D(e.r):D(e.rx),a=t.tag.toLowerCase()==="circle"?D(e.r):D(e.ry);return`M${n+s} ${r} A${s} ${a} 0 1 1 ${n-s} ${r} A${s} ${a} 0 1 1 ${n+s} ${r} Z`}case"rect":{const n=D(e.x),r=D(e.y),s=D(e.width),a=D(e.height);let i=e.rx!=null?D(e.rx):e.ry!=null?D(e.ry):0,o=e.ry!=null?D(e.ry):i;return i=Math.min(i,s/2),o=Math.min(o,a/2),i===0||o===0?`M${n} ${r} H${n+s} V${r+a} H${n} Z`:`M${n+i} ${r} H${n+s-i} A${i} ${o} 0 0 1 ${n+s} ${r+o} V${r+a-o} A${i} ${o} 0 0 1 ${n+s-i} ${r+a} H${n+i} A${i} ${o} 0 0 1 ${n} ${r+a-o} V${r+o} A${i} ${o} 0 0 1 ${n+i} ${r} Z`}case"line":return`M${D(e.x1)} ${D(e.y1)} L${D(e.x2)} ${D(e.y2)}`;case"polyline":case"polygon":{const n=Ps(e.points);if(n.length===0)return null;const r=n.map((s,a)=>`${a===0?"M":"L"}${s.x} ${s.y}`).join(" ");return t.tag.toLowerCase()==="polygon"?`${r} Z`:r}default:return null}}function xs(t,e,n){const r=Math.max(2,Math.round(n.samples??32)),s=Math.max(0,n.length),a=n.since!==void 0?Math.max(e-s,n.since):e-s;if(a>=e)return[];const i=n.period,o=[];for(let c=0;c<r;c++){const h=a+(e-a)*c/(r-1),l=i&&i>0&&c<r-1?(h%i+i)%i:h;o.push({at:t(l),time:h,age:s>0?(e-h)/s:0})}return o}const vs=2.5;function Is(t){const e=[],n=[],r=t.length,s=(a,i)=>{for(let o=a+i;o>=0&&o<r;o+=i){const c=(t[o].x-t[a].x)*i,h=(t[o].y-t[a].y)*i,l=Math.hypot(c,h);if(l>1e-9)return[c/l,h/l]}return null};for(let a=0;a<r;a++){const i=t[a],o=s(a,-1),c=s(a,1),h=o??c??[1,0],l=c??o??[1,0];let u=h[0]+l[0],m=h[1]+l[1];const d=Math.hypot(u,m);d<1e-9?(u=h[0],m=h[1]):(u/=d,m/=d);const y=u*h[0]+m*h[1],g=Math.min(vs,1/Math.max(y,1e-6)),_=i.width/2*g;e.push({x:i.x-m*_,y:i.y+u*_}),n.push({x:i.x+m*_,y:i.y-u*_})}return{left:e,right:n}}function Rs(t){const e=t.length;if(e<2)return null;const n=t[e-1];for(let r=e-2;r>=0;r--){const s=n.x-t[r].x,a=n.y-t[r].y,i=Math.hypot(s,a);if(i>1e-9)return{x:n.x,y:n.y,radius:n.width/2,start:Math.atan2(s/i,-a/i)}}return null}const Es={scale:1,turn:0,x:0,y:0};function Cs(t={}){return{scale:t.scale??1,turn:t.turn??0,x:t.x??0,y:t.y??0}}function En(t,e,n){const{ax:r,ay:s}=wt(t,e);return{scale:t,turn:e,x:n.x-(r*n.x-s*n.y),y:n.y-(s*n.x+r*n.y)}}function ie(t,e){const{ax:n,ay:r}=wt(t.scale,t.turn);return{x:n*e.x-r*e.y+t.x,y:r*e.x+n*e.y+t.y}}function Ds(t,e){const n=ie(e,{x:t.x,y:t.y});return{scale:t.scale*e.scale,turn:t.turn+e.turn,x:n.x,y:n.y}}function $s(t){if(t.scale===0)throw new Error("invertSimilarity: a scale of 0 cannot be undone");const e={scale:1/t.scale,turn:-t.turn,x:0,y:0},n=ie(e,{x:t.x,y:t.y});return{...e,x:-n.x,y:-n.y}}function Cn(t){const{ax:e,ay:n}=wt(t.scale,t.turn),r=1-e,s=-n,a=r*r+s*s;return a<1e-18?null:{x:(t.x*r+t.y*s)/a,y:(t.y*r-t.x*s)/a}}function Os(t,e){if(t.scale<=0)throw new Error("powSimilarity: the scale must be positive");const n=Math.pow(t.scale,e),r=t.turn*e,s=Cn(t);return s?En(n,r,s):{scale:n,turn:r,x:t.x*e,y:t.y*e}}function Ls(t){const{ax:e,ay:n}=wt(t.scale,t.turn);return[e,n,-n,e,t.x,t.y]}const wt=(t,e)=>{const n=e*Math.PI/180;return{ax:t*Math.cos(n),ay:t*Math.sin(n)}};function St([t,e,n],r={}){const s=r.scale??1,a=r.centre??{x:0,y:0},i=Math.sqrt(3)/2;return{x:a.x+(t-e)*i*s,y:a.y+((t+e)*.5-n)*s}}const oe=([t,e,n])=>t+e+n;function ce(t,e={}){const[n,r,s]=t.min,[a,i,o]=t.max,c=m=>St(m,e),h=[(n+a)/2,(r+i)/2,(s+o)/2],l=oe(h),u=[{side:"top",depth:l,tag:t.tag,points:[c([n,r,o]),c([a,r,o]),c([a,i,o]),c([n,i,o])]},{side:"left",depth:l,tag:t.tag,points:[c([n,i,s]),c([a,i,s]),c([a,i,o]),c([n,i,o])]},{side:"right",depth:l,tag:t.tag,points:[c([a,r,s]),c([a,i,s]),c([a,i,o]),c([a,r,o])]}];return t.hide?u.filter(m=>!t.hide.includes(m.side)):u}function ue(t,e={}){return t.map(n=>({box:n,depth:oe([(n.min[0]+n.max[0])/2,(n.min[1]+n.max[1])/2,(n.min[2]+n.max[2])/2])})).sort((n,r)=>n.depth-r.depth).flatMap(({box:n})=>ce(n,e))}function Fs(t={}){const e=t.size??10,r=(t.thickness??2)/2,s=[{tag:0,min:[-r,-r,-r],max:[e-r,r,r]},{tag:1,min:[e-r,-r,-r],max:[e+r,e-r,r]},{tag:2,min:[e-r,e-r,-r],max:[e+r,e+r,e]}],a=t.centre??{x:0,y:0},i=St([2*e/3,e/3,e/3],{scale:t.scale}),o={centre:{x:a.x-i.x,y:a.y-i.y},scale:t.scale};return{boxes:s,faces:[...ue(s,o),...ce({...s[0],hide:["right"]},o)]}}function Ns(t={}){const e=Math.max(2,Math.round(t.steps??8)),n=t.tread??1.5,r=t.rise??.25,s=t.width??3,a=t.base??1.5,i=Math.max(1,Math.round(e*(n-2*r)/(n+2*r))),o=2*(e+i),c=n*(e-i)/o,h=[{dir:[1,0,0],across:[0,1,0],count:e},{dir:[0,1,0],across:[-1,0,0],count:e},{dir:[-1,0,0],across:[0,-1,0],count:i},{dir:[0,-1,0],across:[1,0,0],count:i}],l=[];let u=[0,0,0],m=0;for(const M of h){for(let p=0;p<M.count;p++){const T=m*c,S=[u[0]+M.dir[0]*p*n,u[1]+M.dir[1]*p*n,0],b=[S[0]+M.dir[0]*n+M.across[0]*s,S[1]+M.dir[1]*n+M.across[1]*s,0];l.push({tag:m,min:[Math.min(S[0],b[0]),Math.min(S[1],b[1]),0],max:[Math.max(S[0],b[0]),Math.max(S[1],b[1]),T+a]}),m++}u=[u[0]+M.dir[0]*M.count*n,u[1]+M.dir[1]*M.count*n,0]}const d=o*c,y=t.centre??{x:0,y:0},g=St([e*n/2,e*n/2,d/2+a],{scale:t.scale}),_={centre:{x:y.x-g.x,y:y.y-g.y},scale:t.scale};return{boxes:l,faces:ue(l,_),rise:c}}function Dn(t,e,n){let r=0;for(const s of t){const a=(e-s.x)**2+(n-s.y)**2;r+=a>1e-9?s.r*s.r/a:1e9}return r}function Xs(t,e={}){if(t.length===0)return[];const n=e.threshold??1,r=Math.max(.5,e.cell??4),s=Math.sqrt(1/n)*1.6,a=e.bounds??{x:Math.min(...t.map(d=>d.x-d.r*s)),y:Math.min(...t.map(d=>d.y-d.r*s)),width:Math.max(...t.map(d=>d.x+d.r*s))-Math.min(...t.map(d=>d.x-d.r*s)),height:Math.max(...t.map(d=>d.y+d.r*s))-Math.min(...t.map(d=>d.y-d.r*s))},i=Math.max(2,Math.ceil(a.width/r)+1),o=Math.max(2,Math.ceil(a.height/r)+1),c=new Float64Array(i*o);for(let d=0;d<o;d++)for(let y=0;y<i;y++)c[d*i+y]=Dn(t,a.x+y*r,a.y+d*r)-n;const h=(d,y)=>c[y*i+d],l=(d,y,g,_,M,p)=>{const T=g===p?.5:g/(g-p);return{x:d+(_-d)*T,y:y+(M-y)*T}},u=[];for(let d=0;d+1<o;d++)for(let y=0;y+1<i;y++){const g=a.x+y*r,_=a.y+d*r,M=g+r,p=_+r,T=[h(y,d),h(y+1,d),h(y+1,d+1),h(y,d+1)],S=(T[0]>0?1:0)|(T[1]>0?2:0)|(T[2]>0?4:0)|(T[3]>0?8:0);if(S===0||S===15)continue;const b=()=>l(g,_,T[0],M,_,T[1]),x=()=>l(M,_,T[1],M,p,T[2]),P=()=>l(g,p,T[3],M,p,T[2]),I=()=>l(g,_,T[0],g,p,T[3]),k=(T[0]+T[1]+T[2]+T[3])/4>0;switch(S){case 1:case 14:u.push([I(),b()]);break;case 2:case 13:u.push([b(),x()]);break;case 3:case 12:u.push([I(),x()]);break;case 4:case 11:u.push([x(),P()]);break;case 6:case 9:u.push([b(),P()]);break;case 7:case 8:u.push([I(),P()]);break;case 5:k?u.push([I(),P()],[b(),x()]):u.push([I(),b()],[x(),P()]);break;case 10:k?u.push([I(),b()],[x(),P()]):u.push([I(),P()],[b(),x()]);break}}const m=Ys(u);return e.smooth===!1?m:m.map(d=>$n($n(d)))}function Ys(t){const e=a=>`${Math.round(a.x*1e3)},${Math.round(a.y*1e3)}`,n=new Map;t.forEach(([a,i],o)=>{for(const c of[a,i]){const h=e(c);n.has(h)||n.set(h,[]),n.get(h).push(o)}});const r=new Array(t.length).fill(!1),s=[];for(let a=0;a<t.length;a++){if(r[a])continue;r[a]=!0;const i=[t[a][0],t[a][1]];let o=t[a][1];for(;;){const c=(n.get(e(o))??[]).find(u=>!r[u]);if(c===void 0)break;r[c]=!0;const[h,l]=t[c];if(o=e(h)===e(o)?l:h,e(o)===e(i[0]))break;i.push(o)}i.length>=3&&s.push(i)}return s}function $n(t){const e=[];for(let n=0;n<t.length;n++){const r=t[n],s=t[(n+1)%t.length];e.push({x:r.x*.75+s.x*.25,y:r.y*.75+s.y*.25},{x:r.x*.25+s.x*.75,y:r.y*.25+s.y*.75})}return e}function zs(t){const e=Math.min(1,Math.max(0,t.progress));if(e<=0)return[];const n=t.width/2,r=n*(.55+.75*e),s=Math.max(t.length*e,r*1.2),a=t.x,i=t.y+s-r,o=Math.max(.1,n*(.35-.3*e)),c=i-Math.sqrt(Math.max(0,r*r-o*o)),h=Math.max(0,c-t.y),l=8,u=[],m=[];for(let p=0;p<=l;p++){const T=p/l,S=o+(n-o)*Math.pow(1-T,1.6+1.4*e);u.push({x:a-S,y:t.y+h*T}),m.push({x:a+S,y:t.y+h*T})}const d=Math.max(8,Math.round(t.segments??12)),y=Math.acos(Math.min(1,o/r)),g=-y,_=Math.PI+y,M=[];for(let p=1;p<d;p++){const T=g+(_-g)*p/d;M.push({x:a+Math.cos(T)*r,y:i+Math.sin(T)*r})}return[...m,...M,...u.reverse()]}function Us(t){const e=Math.min(1,Math.max(0,t.grow??1)),n=e>=1?1:1-Math.pow(1-e,3)+.08*Math.sin(e*Math.PI)*e,r=t.r*Math.max(0,n);if(r<=0)return[];const s=Math.max(12,Math.round(t.segments??48)),a=t.wobble??.05,i=t.time??0,o=t.period?i/t.period:i/2500,c=(o-Math.floor(o))*Math.PI*2,h=t.seed??0,l=[];for(let u=0;u<s;u++){const m=u/s*Math.PI*2,d=1+a*(Math.sin(2*m+c+h)*.6+Math.sin(3*m-2*c+h*1.7)*.4);l.push({x:t.x+Math.cos(m)*r*d,y:t.y+Math.sin(m)*r*d})}return l}function Vs(t){const e=t.progress;if(e<=0||e>=1)return[];const n=Math.max(3,Math.round(t.pieces??8)),r=[],s=t.r*(1+1.2*e),a=Math.PI*2/n*.6*(1-e);for(let i=0;i<n;i++){const o=i/n*Math.PI*2+.3,c=[];for(let h=0;h<=4;h++){const l=o-a/2+a*h/4;c.push({x:t.x+Math.cos(l)*s,y:t.y+Math.sin(l)*s})}r.push(c)}return r}function js(t,e={}){const n=Math.max(.05,1+t);return{sx:e.keep==="volume"?1/Math.sqrt(n):1/n,sy:n}}function Bs(t,e,n={x:0,y:0}){return t.map(r=>({x:n.x+(r.x-n.x)*e.sx,y:n.y+(r.y-n.y)*e.sy}))}function Hs(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function he(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function On(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function Pt(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function le(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function fe(t){return Math.hypot(t[0],t[1],t[2])}function qs(t,e){return fe(he(t,e))}function de(t){const e=fe(t);return e===0?[0,0,0]:On(t,1/e)}function Qs(t,e,n){return[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n,t[2]+(e[2]-t[2])*n]}const Gs=Object.freeze(Object.defineProperty({__proto__:null,add:Hs,cross:le,distance:qs,dot:Pt,length:fe,lerp:Qs,normalize:de,scale:On,subtract:he},Symbol.toStringTag,{value:"Module"})),Ks=Math.PI/180;function Ws(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function Js(t,e){const n=new Array(16);for(let r=0;r<4;r++)for(let s=0;s<4;s++){let a=0;for(let i=0;i<4;i++)a+=t[i*4+s]*e[r*4+i];n[r*4+s]=a}return n}function Zs(t){return[1,0,0,0,0,1,0,0,0,0,1,0,t[0],t[1],t[2],1]}function ta(t){return[t[0],0,0,0,0,t[1],0,0,0,0,t[2],0,0,0,0,1]}function Ln(t){const[e,n,r,s]=t;return[1-2*(n*n+r*r),2*(e*n+r*s),2*(e*r-n*s),0,2*(e*n-r*s),1-2*(e*e+r*r),2*(n*r+e*s),0,2*(e*r+n*s),2*(n*r-e*s),1-2*(e*e+n*n),0,0,0,0,1]}function ea(t,e,n){const r=Ln(e);for(let s=0;s<3;s++)r[s]*=n[0],r[4+s]*=n[1],r[8+s]*=n[2];return r[12]=t[0],r[13]=t[1],r[14]=t[2],r}function na(t){const e=new Array(16);for(let n=0;n<4;n++)for(let r=0;r<4;r++)e[r*4+n]=t[n*4+r];return e}function ra(t){const[e,n,r,s,a,i,o,c,h,l,u,m,d,y,g,_]=t,M=e*i-n*a,p=e*o-r*a,T=e*c-s*a,S=n*o-r*i,b=n*c-s*i,x=r*c-s*o,P=h*y-l*d,I=h*g-u*d,k=h*_-m*d,w=l*g-u*y,A=l*_-m*y,v=u*_-m*g,E=M*v-p*A+T*w+S*k-b*I+x*P;if(Math.abs(E)<1e-12)return null;const R=1/E;return[(i*v-o*A+c*w)*R,(r*A-n*v-s*w)*R,(y*x-g*b+_*S)*R,(u*b-l*x-m*S)*R,(o*k-a*v-c*I)*R,(e*v-r*k+s*I)*R,(g*T-d*x-_*p)*R,(h*x-u*T+m*p)*R,(a*A-i*k+c*P)*R,(n*k-e*A-s*P)*R,(d*b-y*T+_*M)*R,(l*T-h*b-m*M)*R,(i*I-a*w-o*P)*R,(e*w-n*I+r*P)*R,(y*p-d*S-g*M)*R,(h*S-l*p+u*M)*R]}function sa(t,e,n,r){const s=1/Math.tan(t*Ks/2),a=1/(n-r);return[s/e,0,0,0,0,s,0,0,0,0,(r+n)*a,-1,0,0,2*r*n*a,0]}function aa(t,e,n,r,s,a){const i=1/(e-t),o=1/(r-n),c=1/(a-s);return[2*i,0,0,0,0,2*o,0,0,0,0,-2*c,0,-(e+t)*i,-(r+n)*o,-(a+s)*c,1]}function ia(t,e,n=[0,1,0]){const r=de(he(t,e)),s=de(le(n,r)),a=le(r,s);return[s[0],a[0],r[0],0,s[1],a[1],r[1],0,s[2],a[2],r[2],0,-Pt(s,t),-Pt(a,t),-Pt(r,t),1]}function oa(t,e){const n=t[0]*e[0]+t[4]*e[1]+t[8]*e[2]+t[12],r=t[1]*e[0]+t[5]*e[1]+t[9]*e[2]+t[13],s=t[2]*e[0]+t[6]*e[1]+t[10]*e[2]+t[14],a=t[3]*e[0]+t[7]*e[1]+t[11]*e[2]+t[15];return a===1||a===0?[n,r,s]:[n/a,r/a,s/a]}const ca=Object.freeze(Object.defineProperty({__proto__:null,compose:ea,fromQuat:Ln,identity:Ws,invert:ra,lookAt:ia,multiply:Js,orthographic:aa,perspective:sa,scaling:ta,transformPoint:oa,translation:Zs,transpose:na},Symbol.toStringTag,{value:"Module"}));f.Clock=Un,f.DEFAULT_BAKE_INTERVAL_MS=Qt,f.DEFAULT_INERTIA_FRICTION=$t,f.DEFAULT_SPRING=L,f.FORMAT_VERSION=vt,f.FRAME_ASPECTS=Rn,f.IDENTITY_SIMILARITY=Es,f.INERTIA_MAX_DURATION_MS=be,f.InertiaTrackPlayer=ln,f.MORPH_SAMPLES=fr,f.ManualClock=zn,f.SPRING_MAX_DURATION_MS=Dt,f.SPRING_PRESETS=Vn,f.SPRING_STEP_MS=G,f.SpringSampler=et,f.SpringTrackPlayer=hn,f.Timeline=Zt,f.TrackPlayer=ot,f.ValueResolver=zr,f.applySimilarity=ie,f.aspectOf=ae,f.audioEnvelope=_s,f.backOut=Ee,f.bakeEasing=an,f.bakeInertiaTrack=Kt,f.bakeSpringTrack=Gt,f.beatAtTime=ut,f.beatLength=ct,f.beatPeriod=ys,f.beatPulse=Ms,f.beatTime=kt,f.beatsBetween=ns,f.bounceOut=Re,f.bubblePath=Us,f.bubblePop=Vs,f.cameraTracks=is,f.charactersFor=fn,f.clearMorphCache=Tr,f.clearPathCache=or,f.closestName=xn,f.composeSimilarity=Ds,f.createCubicBezier=ve,f.createRandom=ee,f.createTrack=un,f.criticalDamping=qn,f.curve=gs,f.customBounce=jr,f.customEase=Vr,f.customWiggle=Br,f.deserializeTimeline=Mn,f.deserializeTrack=yn,f.detectTempo=rs,f.dripPath=zs,f.easeIn=Pe,f.easeInCubic=Ot,f.easeInOut=xe,f.easeInOutCubic=Ft,f.easeInOutQuad=Se,f.easeInQuad=ke,f.easeOut=Ae,f.easeOutCubic=Lt,f.easeOutQuad=we,f.editDistance=An,f.elasticOut=Ie,f.envelopeAt=bs,f.expandParametricEasings=on,f.formatVersionFor=It,f.frameRect=Ts,f.frameSize=ks,f.fromJSON=Nr,f.getEasingFunction=Mt,f.getInterpolator=qt,f.getMotionPathPoint=Wt,f.getPathLength=cr,f.getPointAtProgress=Le,f.hasKeyframes=ye,f.hashSeed=_n,f.heldTime=pe,f.inertiaDuration=rt,f.inertiaRest=nt,f.inertiaValueAt=yt,f.inertiaVelocityAt=Wn,f.interpolateArray=en,f.interpolateColor=tn,f.interpolateMotionPath=Cr,f.interpolateNumber=F,f.interpolatePathString=rn,f.interpolateQuaternion=nn,f.interpolateString=Ht,f.invertSimilarity=$s,f.isCubicBezierEasing=Q,f.isInertiaTrack=Y,f.isMotionPathPoint=Yn,f.isMotionPathTrack=Rt,f.isParametricEasing=lt,f.isPathData=je,f.isSpringTrack=z,f.isTextTrack=ft,f.isUnderdamped=Hn,f.isUnresolved=Yr,f.isoDepth=oe,f.isometricBoxFaces=ce,f.isometricFaces=ue,f.linear=pt,f.loopBeats=ps,f.loopEase=hs,f.loopNoise=ls,f.mat4=ca,f.maxStaggerDistance=Me,f.metaballContours=Xs,f.metaballField=Dn,f.morphPath=Ve,f.narrationMarkers=Jr,f.narrationSceneAt=Zr,f.naturalRest=Te,f.nearestBeat=ts,f.nextBeat=es,f.parametricEasing=De,f.parsePath=B,f.penroseStairs=Ns,f.penroseTriangle=Fs,f.phaseOf=q,f.pingPong=se,f.planNarration=Wr,f.playheadCrossings=Lr,f.pointAtDistance=Xt,f.pointsToPath=Ss,f.powSimilarity=Os,f.projectIsometric=St,f.quat=xr,f.randomBetween=ne,f.randomChoice=Xr,f.randomSnapped=bn,f.resolveSequence=wn,f.resolveValue=re,f.ribbon=Is,f.ribbonHeadCap=Rs,f.safeAreas=ws,f.scalePoints=Bs,f.serializeTimeline=pn,f.serializeTrack=mn,f.shapeToPathData=As,f.similarity=Cs,f.similarityAbout=En,f.similarityFixedPoint=Cn,f.similarityMatrix=Ls,f.simplifyKeyframes=cn,f.springDuration=Bn,f.springFollow=cs,f.springValueAt=jn,f.squashStretch=js,f.staggerDistance=Et,f.staggerOffset=Ct,f.staggerOffsets=_e,f.staggerSpan=dt,f.stepsEasing=Ce,f.textAt=dn,f.toJSON=Fr,f.toKeyframedTrack=Rr,f.toKeyframedTracks=Er,f.torusNoise=fs,f.trackTargets=j,f.trailSamples=xs,f.unknownName=os,f.vec3=Gs,f.wobble=us,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(f,Q){typeof exports=="object"&&typeof module<"u"?Q(exports):typeof define=="function"&&define.amd?define(["exports"],Q):(f=typeof globalThis<"u"?globalThis:f||self,Q(f.tinyfly={}))})(this,(function(f){"use strict";function Q(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function lt(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const vt=2;function It(t){return t.some(e=>e.interpolation!==void 0)?2:1}function ft(t){return t.property==="text"&&"textConfig"in t}function Y(t){return t.kind==="inertia"&&"inertia"in t}function z(t){return t.kind==="spring"&&"spring"in t}function Rt(t){return t.property==="motionPath"&&"motionPathConfig"in t}function Yn(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"angle"in t}function ye(t){return"keyframes"in t}class zn{_currentTime=0;_isRunning=!1;onTick=null;get currentTime(){return this._currentTime}get isRunning(){return this._isRunning}start(){this._isRunning=!0}stop(){this._isRunning=!1}tick(e){this._currentTime+=e,this.onTick?.(e,this._currentTime)}reset(){this._currentTime=0}seek(e){this._currentTime=e}}class jn{_currentTime=0;_isRunning=!1;_lastFrameTime=null;_rafId=null;_speed;onTick=null;constructor(e={}){this._speed=e.speed??1}get currentTime(){return this._currentTime}get isRunning(){return this._isRunning}get speed(){return this._speed}set speed(e){this._speed=e}start(){this._isRunning||(this._isRunning=!0,this._lastFrameTime=null,this._scheduleFrame())}stop(){this._isRunning=!1,this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null)}reset(){this._currentTime=0,this._lastFrameTime=null}seek(e){this._currentTime=e}_scheduleFrame(){this._rafId=requestAnimationFrame(this._onFrame.bind(this))}_onFrame(e){if(this._isRunning){if(this._lastFrameTime!==null){const r=(e-this._lastFrameTime)*this._speed;this._currentTime+=r,this.onTick?.(r,this._currentTime)}this._lastFrameTime=e,this._scheduleFrame()}}}function pe(t,e){if(!(e>0))return t;const n=1e3/e;return Math.floor(t/n+1e-9)*n}function Et(t,e,n="start"){if(e<=1)return 0;if(typeof n=="number"){const r=Math.max(0,Math.min(e-1,n));return Math.abs(t-r)}switch(n){case"end":return e-1-t;case"center":return Math.abs(t-(e-1)/2);case"edges":return(e-1)/2-Math.abs(t-(e-1)/2);default:return t}}function Me(t,e="start"){if(t<=1)return 0;let n=0;for(let r=0;r<t;r++)n=Math.max(n,Et(r,t,e));return n}function Ct(t,e,n){if(n.offsets)return n.offsets[t]??0;const r=n.from??"start",s=Et(t,e,r);if(n.amount!==void 0){const a=Me(e,r);return a===0?0:n.amount*s/a}return n.each!==void 0?n.each*s:0}function _e(t,e){return Array.from({length:t},(n,r)=>Ct(r,t,e))}function dt(t,e){return t<=1?0:Math.max(..._e(t,e))}const G=1,Dt=6e4,mt=Dt/G,L={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1},Un={gentle:{stiffness:120,damping:18,mass:1},default:{stiffness:180,damping:12,mass:1},snappy:{stiffness:280,damping:20,mass:1},bouncy:{stiffness:220,damping:8,mass:1},wobbly:{stiffness:180,damping:5,mass:1},stiff:{stiffness:400,damping:30,mass:1}};class et{from;to;stiffness;damping;mass;restDelta;restSpeed;distance;samples;velocity;settledStep=null;constructor(e){this.from=e.from,this.to=e.to,this.stiffness=e.stiffness??L.stiffness,this.damping=e.damping??L.damping,this.mass=e.mass??L.mass,this.restDelta=e.restDelta??L.restDelta,this.restSpeed=e.restSpeed??L.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=e.velocity??L.velocity,this.isAtRest(this.from)&&(this.settledStep=0)}isAtRest(e){return Math.abs(e-this.to)<this.restDelta*this.distance&&Math.abs(this.velocity)<this.restSpeed*this.distance}valueAt(e){if(e<=0)return this.from;const n=Math.floor(e/G);if(this.simulateTo(n+1),this.settledStep!==null&&n>=this.settledStep)return this.to;const r=this.samples[Math.min(n,this.samples.length-1)],s=this.samples[Math.min(n+1,this.samples.length-1)],a=e/G-n;return r+(s-r)*a}settleTime(){return this.simulateTo(mt+1),this.settledStep!==null?this.settledStep*G:Dt}simulateTo(e){if(this.settledStep!==null)return;const n=Math.min(e,mt+1),r=G/1e3;for(;this.samples.length<n;){const s=this.samples[this.samples.length-1],a=s-this.to,i=-this.stiffness*a,o=-this.damping*this.velocity,c=(i+o)/this.mass;this.velocity+=c*r;const h=s+this.velocity*r;if(this.samples.push(h),this.isAtRest(h)){this.settledStep=this.samples.length-1;return}}this.samples.length>mt&&(this.settledStep=mt)}}function Vn(t,e){return new et(t).valueAt(e)}function Bn(t){return new et(t).settleTime()}function Hn(t){const e=t.stiffness??L.stiffness,n=t.damping??L.damping,r=t.mass??L.mass;return n<2*Math.sqrt(e*r)}function qn(t){const e=t.stiffness??L.stiffness,n=t.mass??L.mass;return 2*Math.sqrt(e*n)}const $t=4,Qn=.002,Gn=1e-4,be=6e4;function gt(t){const e=t.friction??$t;return e>0?e:$t}function Te(t){return t.from+t.velocity/gt(t)}function Kn(t,e){if(e===void 0)return t;if(typeof e=="number")return e>0?Math.round(t/e)*e:t;if(e.length===0)return t;let n=e[0];for(const r of e)Math.abs(r-t)<Math.abs(n-t)&&(n=r);return n}function nt(t){let e=Kn(Te(t),t.end);return t.min!==void 0&&(e=Math.max(t.min,e)),t.max!==void 0&&(e=Math.min(t.max,e)),e}function rt(t){const e=Math.abs(nt(t)-t.from);if(e===0)return 0;const n=t.restDelta??Math.max(Gn,e*Qn);if(n>=e)return 0;const r=Math.log(e/n)/gt(t);return Math.min(be,r*1e3)}function yt(t,e){if(e<=0)return t.from;const n=nt(t);if(e>=rt(t))return n;const r=gt(t);return t.from+(n-t.from)*(1-Math.exp(-r*e/1e3))}function Wn(t,e){const n=gt(t),r=nt(t);return e>=rt(t)?0:(r-t.from)*n*Math.exp(-n*Math.max(0,e)/1e3)}const pt=t=>t,ke=t=>t*t,we=t=>1-(1-t)*(1-t),Se=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,Ot=t=>t*t*t,Lt=t=>1-Math.pow(1-t,3),Ft=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,Pe=Ot,Ae=Lt,xe=Ft,Jn={linear:pt,"ease-in":Pe,"ease-out":Ae,"ease-in-out":xe,"ease-in-quad":ke,"ease-out-quad":we,"ease-in-out-quad":Se,"ease-in-cubic":Ot,"ease-out-cubic":Lt,"ease-in-out-cubic":Ft};function ve(t){const[e,n,r,s]=t,a=3*e,i=3*(r-e)-a,o=1-a-i,c=3*n,h=3*(s-n)-c,l=1-c-h,u=g=>((o*g+i)*g+a)*g,m=g=>((l*g+h)*g+c)*g,d=g=>(3*o*g+2*i)*g+a,y=g=>{let _=g;for(let T=0;T<8;T++){const S=u(_)-g;if(Math.abs(S)<1e-7)return _;const b=d(_);if(Math.abs(b)<1e-7)break;_-=S/b}let M=0,p=1;for(_=g;M<p;){const T=u(_);if(Math.abs(T-g)<1e-7)return _;g>T?M=_:p=_,_=(M+p)/2}return _};return g=>{if(g<=0)return 0;if(g>=1)return 1;const _=y(g);return m(_)}}function Nt(t,e="out"){if(e==="out")return t;const n=r=>1-t(1-r);return e==="in"?n:r=>r<.5?n(r*2)/2:t(r*2-1)/2+.5}function Ie(t=1,e=.3){const n=Math.max(1,t),r=e/(2*Math.PI)*Math.asin(1/n);return s=>s<=0?0:s>=1?1:n*Math.pow(2,-10*s)*Math.sin((s-r)*(2*Math.PI)/e)+1}const Re=t=>{if(t<=0)return 0;if(t>=1)return 1;if(t<1/2.75)return 7.5625*t*t;if(t<2/2.75){const s=t-.5454545454545454;return 7.5625*s*s+.75}if(t<2.5/2.75){const s=t-.8181818181818182;return 7.5625*s*s+.9375}const r=t-2.625/2.75;return 7.5625*r*r+.984375};function Ee(t=1.70158){return e=>{if(e<=0)return 0;if(e>=1)return 1;const n=e-1;return n*n*((t+1)*n+t)+1}}function Ce(t,e="end"){const n=Math.max(1,Math.floor(t));return r=>{if(r>=1)return 1;if(r<=0)return e==="start"||e==="both"?e==="start"?1/n:1/(n+1):0;const s=Math.floor(r*n);switch(e){case"start":return Math.min(1,(s+1)/n);case"both":return(s+1)/(n+1);case"none":return n===1?0:Math.min(1,s/(n-1));default:return s/n}}}function De(t){switch(t.type){case"steps":return Ce(t.count,t.position);case"elastic":return Nt(Ie(t.amplitude,t.period),t.mode);case"bounce":return Nt(Re,t.mode);case"back":return Nt(Ee(t.overshoot),t.mode)}}function Mt(t){return t===void 0?pt:Q(t)?ve(t.points):lt(t)?De(t):Jn[t]??pt}const $e=32,Zn=256,K=new Map,tr=/[MmLlHhVvCcSsQqTtAaZz]/,er=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,nr={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function rr(t){const e=[];let n=0,r=null;const s=()=>{for(;n<t.length&&/[\s,]/.test(t[n]);)n++};for(;n<t.length&&(s(),!(n>=t.length));){const a=t[n];if(tr.test(a)){r={type:a,args:[]},e.push(r),n++;continue}if(!r)break;const i=r.type==="A"||r.type==="a",o=r.args.length%7;if(i&&(o===3||o===4)){if(a!=="0"&&a!=="1")break;r.args.push(a==="1"?1:0),n++;continue}const c=er.exec(t.slice(n));if(!c)break;r.args.push(parseFloat(c[0])),n+=c[0].length}return e}function sr(t,e,n,r,s,a,i,o,c){if(t===o&&e===c)return[];let h=Math.abs(n),l=Math.abs(r);if(h===0||l===0)return[[t,e,o,c,o,c]];const u=s*Math.PI/180,m=Math.cos(u),d=Math.sin(u),y=(t-o)/2,g=(e-c)/2,_=m*y+d*g,M=-d*y+m*g,p=_*_/(h*h)+M*M/(l*l);if(p>1){const C=Math.sqrt(p);h*=C,l*=C}const T=a===i?-1:1,S=h*h*l*l-h*h*M*M-l*l*_*_,b=h*h*M*M+l*l*_*_,x=T*Math.sqrt(Math.max(0,S/b)),P=x*h*M/l,I=-x*l*_/h,k=m*P-d*I+(t+o)/2,w=d*P+m*I+(e+c)/2,A=(C,$,O,tt)=>{const ge=C*O+$*tt,xt=Math.sqrt((C*C+$*$)*(O*O+tt*tt)),ht=Math.acos(Math.max(-1,Math.min(1,ge/xt)));return C*tt-$*O<0?-ht:ht},v=A(1,0,(_-P)/h,(M-I)/l);let E=A((_-P)/h,(M-I)/l,(-_-P)/h,(-M-I)/l);!i&&E>0&&(E-=2*Math.PI),i&&E<0&&(E+=2*Math.PI);const R=Math.max(1,Math.ceil(Math.abs(E)/(Math.PI/2))),me=E/R,At=4/3*Math.tan(me/4),Fn=C=>{const $=h*Math.cos(C),O=l*Math.sin(C);return[m*$-d*O+k,d*$+m*O+w]},Nn=C=>{const $=-h*Math.sin(C),O=l*Math.cos(C);return[m*$-d*O,d*$+m*O]},Xn=[];for(let C=0;C<R;C++){const $=v+C*me,O=$+me,[tt,ge]=Fn($),[xt,ht]=C===R-1?[o,c]:Fn(O),[la,fa]=Nn($),[da,ma]=Nn(O);Xn.push([tt+At*la,ge+At*fa,xt-At*da,ht-At*ma,xt,ht])}return Xn}function j(t,e,n,r,s){const a=1-s;return a*a*a*t+3*a*a*s*e+3*a*s*s*n+s*s*s*r}function Oe(t,e,n,r,s){const a=1-s;return 3*a*a*(e-t)+6*a*s*(n-e)+3*s*s*(r-n)}function st(t,e,n,r){return{subpath:0,type:"L",points:[n,r],startX:t,startY:e,endX:n,endY:r,length:Math.hypot(n-t,r-e)}}function _t(t,e,n){const[r,s,a,i,o,c]=n,h=[0];let l=t,u=e,m=0;for(let d=1;d<=$e;d++){const y=d/$e,g=j(t,r,a,o,y),_=j(e,s,i,c,y);m+=Math.hypot(g-l,_-u),h.push(m),l=g,u=_}return{subpath:0,type:"C",points:[r,s,a,i,o,c],startX:t,startY:e,endX:o,endY:c,length:m,lengths:h}}function B(t){const e=K.get(t);if(e)return e;const n=[];let r=0,s=0,a=0,i=0,o=null,c=null,h=-1;const l=new Set,u=g=>{h<0&&(h=0),g.subpath=h,n.push(g)};for(const{type:g,args:_}of rr(t)){const M=g.toUpperCase(),p=g!==M,T=nr[M];if(M==="Z"){(r!==a||s!==i)&&u(st(r,s,a,i)),h>=0&&l.add(h),r=a,s=i,o=c=null;continue}for(let S=0;S+T<=_.length;S+=T){const b=_.slice(S,S+T),x=p?r:0,P=p?s:0;let I=null,k=null;switch(M){case"M":S===0?(r=b[0]+x,s=b[1]+P,a=r,i=s,(h<0||n[n.length-1]?.subpath===h)&&h++):(u(st(r,s,b[0]+x,b[1]+P)),r=b[0]+x,s=b[1]+P);break;case"L":u(st(r,s,b[0]+x,b[1]+P)),r=b[0]+x,s=b[1]+P;break;case"H":u(st(r,s,b[0]+x,s)),r=b[0]+x;break;case"V":u(st(r,s,r,b[0]+P)),s=b[0]+P;break;case"C":{const w=[b[0]+x,b[1]+P,b[2]+x,b[3]+P,b[4]+x,b[5]+P];u(_t(r,s,w)),I=[w[2],w[3]],r=w[4],s=w[5];break}case"S":{const[w,A]=o?[2*r-o[0],2*s-o[1]]:[r,s],v=[w,A,b[0]+x,b[1]+P,b[2]+x,b[3]+P];u(_t(r,s,v)),I=[v[2],v[3]],r=v[4],s=v[5];break}case"Q":case"T":{let w=r,A=s;M==="Q"?(w=b[0]+x,A=b[1]+P):c&&(w=2*r-c[0],A=2*s-c[1]);const v=M==="Q"?b[2]+x:b[0]+x,E=M==="Q"?b[3]+P:b[1]+P;u(_t(r,s,[r+2/3*(w-r),s+2/3*(A-s),v+2/3*(w-v),E+2/3*(A-E),v,E])),k=[w,A],r=v,s=E;break}case"A":{const w=b[5]+x,A=b[6]+P;let v=r,E=s;for(const R of sr(r,s,b[0],b[1],b[2],b[3],b[4],w,A))u(_t(v,E,R)),v=R[4],E=R[5];r=w,s=A;break}}o=I,c=k}}const m=n.reduce((g,_)=>g+_.length,0),d=[];for(let g=0;g<n.length;){const _=n[g].subpath;let M=g,p=0;for(;M<n.length&&n[M].subpath===_;)p+=n[M++].length;const T=n[g],S=n[M-1],b=l.has(_)||Math.abs(S.endX-T.startX)<1e-9&&Math.abs(S.endY-T.startY)<1e-9;d.push({start:g,end:M,length:p,closed:b}),g=M}const y={segments:n,totalLength:m,subpaths:d};return K.size>=Zn&&K.delete(K.keys().next().value),K.set(t,y),y}function ar(t,e){const n=t.lengths;if(e<=0)return 0;if(e>=t.length)return 1;let r=0,s=n.length-1;for(;r<s-1;){const o=r+s>>1;n[o]<e?r=o:s=o}const a=n[s]-n[r],i=a>0?(e-n[r])/a:0;return(r+i)/(n.length-1)}function ir(t,e){if(t.type==="L"){const u=t.length>0?Math.max(0,Math.min(1,e/t.length)):0;return{x:t.startX+(t.endX-t.startX)*u,y:t.startY+(t.endY-t.startY)*u,angle:Math.atan2(t.endY-t.startY,t.endX-t.startX)*180/Math.PI}}const[n,r,s,a,i,o]=t.points,c=ar(t,e);let h=Oe(t.startX,n,s,i,c),l=Oe(t.startY,r,a,o,c);if(Math.hypot(h,l)<1e-9){const u=c<.5?Math.min(1,c+.001):Math.max(0,c-.001),m=j(t.startX,n,s,i,u),d=j(t.startY,r,a,o,u),y=j(t.startX,n,s,i,c),g=j(t.startY,r,a,o,c);h=c<.5?m-y:y-m,l=c<.5?d-g:g-d}return{x:j(t.startX,n,s,i,c),y:j(t.startY,r,a,o,c),angle:Math.atan2(l,h)*180/Math.PI}}function Xt(t,e,n=0,r=t.length){if(r<=n)return{x:0,y:0,angle:0};let s=0;for(let a=n;a<r;a++){const i=t[a];if(s+i.length>=e||a===r-1)return ir(i,e-s);s+=i.length}return{x:0,y:0,angle:0}}function Le(t,e){const{segments:n,totalLength:r}=B(t);return Xt(n,Math.max(0,Math.min(1,e))*r)}function or(){K.clear()}function cr(t){return B(t).totalLength}const ur=24,hr=320,lr=2.5,at=72,fr=64,dr=.2,mr=128,it=new Map;let bt=0,U;const Fe=t=>Math.round(t*100)/100;function Ne(t,e){const{segments:n,subpaths:r,totalLength:s}=B(t);if(n.length===0)return[];if(e){const a=r.every(i=>i.closed);return[{segments:n,start:0,end:n.length,length:s,closed:a}]}return r.filter(a=>a.length>0).map(a=>({segments:n,start:a.start,end:a.end,length:a.length,closed:a.closed}))}function Yt(t,e){const n=t.closed?(e%1+1)%1:Math.max(0,Math.min(1,e)),r=Xt(t.segments,n*t.length,t.start,t.end);return[r.x,r.y]}function Xe(t){const e=[];let n=0;for(let r=t.start;r<t.end;r++)n+=t.segments[r].length,t.length>0&&e.push(n/t.length);return e}function Ye(t,e){const n=[];for(let r=0;r<e;r++)n.push(Yt(t,t.closed?r/e:r/(e-1)));return n}function ze(t){let e=0,n=0;for(const[r,s]of t)e+=r,n+=s;return e/=t.length,n/=t.length,t.map(([r,s])=>[r-e,s-n])}function gr(t,e,n){const r=t.closed&&e.closed;if(n!==void 0)return{offset:r?Math.abs(n)%at/at:0,reversed:n<0};const s=ze(Ye(t,at)),a=ze(Ye(e,at)),i=at;let o={offset:0,reversed:!1},c=1/0;for(const h of[!1,!0]){const l=r?i:1;for(let u=0;u<l;u++){let m=0;for(let d=0;d<i&&m<c;d++){const y=r?h?(u-d+i)%i:(d+u)%i:h?i-1-d:d,g=s[d][0]-a[y][0],_=s[d][1]-a[y][1];m+=g*g+_*_}m<c&&(c=m,o={offset:r?u/i:0,reversed:h})}}return o}function yr(t,e,n){return n?((e.reversed?e.offset-t:t+e.offset)%1+1)%1:e.reversed?1-t:t}function pr(t,e,n){return n?((e.reversed?e.offset-t:t-e.offset)%1+1)%1:e.reversed?1-t:t}function Mr(t,e,n){const r=t.closed&&e.closed,s=gr(t,e,n.shapeIndex),a=Math.max(ur,Math.min(hr,Math.ceil(Math.max(t.length,e.length)/lr))),i=new Set,o=u=>i.add(Math.round(u*1e7)/1e7);for(let u=0;u<=a;u++)o(u/a);for(const u of Xe(t))o(u);for(const u of Xe(e))o(pr(u,s,r));let c=[...i].sort((u,m)=>u-m);r&&(c=c.filter(u=>u<1));const h=[],l=[];for(const u of c)h.push(...Yt(t,u)),l.push(...Yt(e,yr(u,s,r)));return _r({from:h,to:l,closed:r})}function _r(t){const e=t.from.length/2;if(e<=3)return t;const n=new Uint8Array(e);n[0]=1,n[e-1]=1;const r=[[0,e-1]];for(;r.length>0;){const[i,o]=r.pop();let c=-1,h=dr;for(let l=i+1;l<o;l++){const u=Math.max(je(t.from,i,o,l),je(t.to,i,o,l));u>h&&(h=u,c=l)}c!==-1&&(n[c]=1,r.push([i,c],[c,o]))}const s=[],a=[];for(let i=0;i<e;i++)n[i]&&(s.push(t.from[i*2],t.from[i*2+1]),a.push(t.to[i*2],t.to[i*2+1]));return{from:s,to:a,closed:t.closed}}function je(t,e,n,r){const s=t[e*2],a=t[e*2+1],i=t[n*2]-s,o=t[n*2+1]-a,c=t[r*2]-s,h=t[r*2+1]-a,l=i*i+o*o,u=l===0?0:Math.max(0,Math.min(1,(c*i+h*o)/l));return Math.hypot(c-u*i,h-u*o)}function br(t,e,n){const r=n.shapeIndex;if(U&&U.from===t&&U.to===e&&U.shapeIndex===r)return U.plan;const a=it.get(String(r??"auto"))?.get(t)?.get(e);if(a)return U={from:t,to:e,shapeIndex:r,plan:a},a;const i=B(t).subpaths.filter(d=>d.length>0).length===B(e).subpaths.filter(d=>d.length>0).length,o=Ne(t,!i),c=Ne(e,!i),h={pairs:o.map((d,y)=>Mr(d,c[y],n))};bt>=mr&&(it.clear(),bt=0);const l=String(r??"auto"),u=it.get(l)??new Map;it.set(l,u);const m=u.get(t)??new Map;return u.set(t,m),m.set(e,h),bt++,U={from:t,to:e,shapeIndex:r,plan:h},h}function Ue(t,e,n,r={}){if(!t)return e;if(!e)return t;const s=Math.max(0,Math.min(1,n));if(s===0)return t;if(s===1)return e;const a=br(t,e,r);if(a.pairs.length===0)return s<.5?t:e;let i="";for(const o of a.pairs){for(let c=0;c<o.from.length;c+=2){const h=Fe(o.from[c]+(o.to[c]-o.from[c])*s),l=Fe(o.from[c+1]+(o.to[c+1]-o.from[c+1])*s);i+=`${c===0?i?" M":"M":" L"}${h} ${l}`}o.closed&&(i+=" Z")}return i}function Tr(){it.clear(),bt=0,U=void 0}function Ve(t){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(t)}const W=Math.PI/180,kr=.9995;function zt(){return[0,0,0,1]}function Tt(t,e){const n=Math.hypot(t[0],t[1],t[2]);if(n===0)return zt();const r=e*W/2,s=Math.sin(r)/n;return[t[0]*s,t[1]*s,t[2]*s,Math.cos(r)]}function wr(t,e,n){return jt(jt(Tt([0,1,0],e),Tt([1,0,0],t)),Tt([0,0,1],n))}function Sr(t){const[e,n,r,s]=H(t),a=2*(e*r+n*s),i=2*(e*n+r*s),o=1-2*(e*e+r*r),c=2*(n*r-e*s),h=1-2*(n*n+r*r),l=2*(e*r-n*s),u=1-2*(e*e+n*n),m=Math.asin(Math.max(-1,Math.min(1,-c)));return Math.abs(c)<.9999999?[m/W,Math.atan2(a,u)/W,Math.atan2(i,o)/W]:[m/W,Math.atan2(-l,h)/W,0]}function jt(t,e){const[n,r,s,a]=t,[i,o,c,h]=e;return[a*i+n*h+r*c-s*o,a*o-n*c+r*h+s*i,a*c+n*o-r*i+s*h,a*h-n*i-r*o-s*c]}function Be(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function He(t){return Math.hypot(t[0],t[1],t[2],t[3])}function H(t){const e=He(t);return e===0?zt():[t[0]/e,t[1]/e,t[2]/e,t[3]/e]}function Pr(t){return[-t[0],-t[1],-t[2],t[3]]}function qe(t,e,n){const r=H(t);let s=H(e),a=Be(r,s);if(a<0&&(s=[-s[0],-s[1],-s[2],-s[3]],a=-a),a>kr)return H([r[0]+(s[0]-r[0])*n,r[1]+(s[1]-r[1])*n,r[2]+(s[2]-r[2])*n,r[3]+(s[3]-r[3])*n]);const i=Math.acos(a),o=Math.sin(i),c=Math.sin((1-n)*i)/o,h=Math.sin(n*i)/o;return H([r[0]*c+s[0]*h,r[1]*c+s[1]*h,r[2]*c+s[2]*h,r[3]*c+s[3]*h])}function Ar(t,e){const[n,r,s,a]=H(t),i=2*(r*e[2]-s*e[1]),o=2*(s*e[0]-n*e[2]),c=2*(n*e[1]-r*e[0]);return[e[0]+a*i+(r*c-s*o),e[1]+a*o+(s*i-n*c),e[2]+a*c+(n*o-r*i)]}const xr=Object.freeze(Object.defineProperty({__proto__:null,conjugate:Pr,dot:Be,fromAxisAngle:Tt,fromEuler:wr,identity:zt,length:He,multiply:jt,normalize:H,rotateVec3:Ar,slerp:qe,toEuler:Sr},Symbol.toStringTag,{value:"Module"})),F=(t,e,n)=>t+(e-t)*n,Qe=512,Ut=new Map,Vt=new Map;function Ge(t){const e=Ut.get(t);if(e)return e;const n=t.replace("#",""),r=[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)];return Ut.size<Qe&&Ut.set(t,r),r}const Ke=t=>t.charCodeAt(0)===35,We=t=>t.startsWith("rgb"),Je=t=>t.startsWith("rgba"),vr=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,Bt=t=>Math.round(t).toString(16).padStart(2,"0");function Ir(t,e,n){return`#${Bt(t)}${Bt(e)}${Bt(n)}`}function Ze(t){const e=Vt.get(t);if(e)return e;const n=t.match(vr);if(!n)throw new Error(`Invalid rgb color: ${t}`);const r=parseInt(n[1],10),s=parseInt(n[2],10),a=parseInt(n[3],10),i=n[4]!==void 0?[r,s,a,parseFloat(n[4])]:[r,s,a];return Vt.size<Qe&&Vt.set(t,i),i}const tn=(t,e,n)=>{if(Ke(t)&&Ke(e)){const[r,s,a]=Ge(t),[i,o,c]=Ge(e),h=F(r,i,n),l=F(s,o,n),u=F(a,c,n);return Ir(h,l,u)}if((We(t)||Je(t))&&(We(e)||Je(e))){const r=Ze(t),s=Ze(e),a=Math.round(F(r[0],s[0],n)),i=Math.round(F(r[1],s[1],n)),o=Math.round(F(r[2],s[2],n));if(r.length===4||s.length===4){const c=r[3]??1,h=s[3]??1,l=F(c,h,n);return`rgba(${a}, ${i}, ${o}, ${l})`}return`rgb(${a}, ${i}, ${o})`}return n<1?t:e},en=(t,e,n)=>{const r=Math.min(t.length,e.length),s=[];for(let a=0;a<r;a++)s.push(F(t[a],e[a],n));return s},nn=(t,e,n)=>qe(t,e,n),Ht=(t,e,n)=>n<1?t:e,rn=(t,e,n)=>Ue(t,e,n);function qt(t,e){return e==="slerp"?nn:typeof t=="number"?F:Array.isArray(t)?en:typeof t=="string"?t.startsWith("#")||t.startsWith("rgb")?tn:Ve(t)?rn:Ht:Ht}const Qt=1e3/60;function Gt(t,e={}){if(!z(t))throw new Error(`bakeSpringTrack: track "${t.id}" is not a spring track`);const n=new et(t.spring);return sn(t,r=>n.valueAt(r),n.settleTime(),t.spring.from,t.spring.to,e)}function Kt(t,e={}){if(!Y(t))throw new Error(`bakeInertiaTrack: track "${t.id}" is not an inertia track`);const n=t.inertia;return sn(t,r=>yt(n,r),rt(n),n.from,nt(n),e)}function sn(t,e,n,r,s,a){const i=a.intervalMs??Qt,o=a.tolerance??.01,c=t.delay??0,h=[];for(let u=0;u<=n;u+=i)h.push({time:u+c,value:e(u),easing:"linear"});const l=h[h.length-1];return!l||l.time<n+c?h.push({time:n+c,value:s,easing:"linear"}):l.value=s,c>0&&h.unshift({time:0,value:r,easing:"linear"}),{id:t.id,target:t.target,property:t.property,keyframes:o>0?cn(h,o):h,...t.targets&&{targets:[...t.targets]},...t.stagger&&{stagger:{...t.stagger}}}}function an(t,e,n,r={}){const s=r.intervalMs??Qt,a=typeof n=="function"?n:Mt(n),i=qt(t.value,r.interpolation),o=e.time-t.time;if(o<=0)return[e];const c=[];for(let l=s;l<o;l+=s){const u=l/o;c.push({time:t.time+l,value:i(t.value,e.value,a(u)),easing:"linear"})}const h=a(1);return c.push({...e,...h!==1&&{value:i(t.value,e.value,h)},easing:"linear"}),c}function Rr(t,e){return z(t)?Gt(t,e):Y(t)?Kt(t,e):t}function on(t,e={}){const n=t.keyframes;if(!n.some(a=>lt(a.easing)))return t;const r=n.length>0?[n[0]]:[],s={...e,interpolation:t.interpolation??e.interpolation};for(let a=1;a<n.length;a++){const i=n[a];lt(i.easing)?r.push(...an(n[a-1],i,i.easing,s)):r.push(i)}return{...t,keyframes:r}}function Er(t,e){return t.filter(ye).map(n=>on(n,e)).concat(t.filter(z).map(n=>Gt(n,e)),t.filter(Y).map(n=>Kt(n,e)))}function cn(t,e){if(t.length<=2)return t;const n=[t[0]];for(let r=1;r<t.length-1;r++){const s=n[n.length-1],a=t[r],i=t[r+1],o=i.time-s.time;if(o<=0)continue;const c=(a.time-s.time)/o,h=s.value+(i.value-s.value)*c;Math.abs(a.value-h)>e&&n.push(a)}return n.push(t[t.length-1]),n}function un(t){const e=[...t.keyframes].sort((n,r)=>n.time-r.time);return{...t,keyframes:e}}function V(t){return t.targets&&t.targets.length>0?t.targets:[t.target]}function J(t,e,n,r){const s=n??0;return!r||e<=1?s:s+Ct(t,e,r)}class ot{track;targets;constructor(e){this.track=e,this.targets=V(e)}getValueAtTime(e){return this.valueForOffset(e-J(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,r=[];for(let s=0;s<n;s++){const a=J(s,n,this.track.delay,this.track.stagger),i=this.valueForOffset(e-a);i!==void 0&&r.push({target:this.targets[s],value:i,start:a+this.track.keyframes[0].time})}return r}getDuration(){const{keyframes:e}=this.track;if(e.length===0)return 0;const n=e[e.length-1].time,r=this.track.stagger?dt(this.targets.length,this.track.stagger):0;return n+(this.track.delay??0)+r+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(e){const{keyframes:n}=this.track;if(n.length===0)return;if(n.length===1||e<=n[0].time)return n[0].value;if(e>=n[n.length-1].time)return n[n.length-1].value;const{from:r,to:s}=this.findSurroundingKeyframes(e);if(!r||!s)return;if(r.time===e)return r.value;const a=s.time-r.time,i=(e-r.time)/a,c=Mt(s.easing)(i);return qt(r.value,this.track.interpolation)(r.value,s.value,c)}findSurroundingKeyframes(e){const{keyframes:n}=this.track;for(let r=0;r<n.length-1;r++)if(e>=n[r].time&&e<=n[r+1].time)return{from:n[r],to:n[r+1]};return{from:null,to:null}}}class hn{track;targets;sampler;constructor(e){this.track=e,this.targets=V(e),this.sampler=new et(e.spring)}getValueAtTime(e){return this.sampler.valueAt(e-J(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,r=[];for(let s=0;s<n;s++){const a=J(s,n,this.track.delay,this.track.stagger);r.push({target:this.targets[s],value:this.sampler.valueAt(e-a),start:a})}return r}getDuration(){const e=this.track.stagger?dt(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+e}getTrack(){return this.track}}class ln{track;targets;duration;constructor(e){this.track=e,this.targets=V(e),this.duration=rt(e.inertia)}getValueAtTime(e){return yt(this.track.inertia,e-J(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,r=[];for(let s=0;s<n;s++){const a=J(s,n,this.track.delay,this.track.stagger);r.push({target:this.targets[s],value:yt(this.track.inertia,e-a),start:a})}return r}getDuration(){const e=this.track.stagger?dt(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+e}getTrack(){return this.track}}function Wt(t,e){const n={...Le(t.pathData,e)};if(t.matrix){const[r,s,a,i,o,c]=t.matrix,{x:h,y:l}=n;n.x=r*h+a*l+o,n.y=s*h+i*l+c;const u=n.angle*Math.PI/180,m=Math.cos(u),d=Math.sin(u);n.angle=Math.atan2(s*m+i*d,r*m+a*d)*180/Math.PI}return t.autoRotate&&t.rotateOffset&&(n.angle+=t.rotateOffset),n}function Cr(t,e,n,r){const s=e+(n-e)*r;return Wt(t,s)}const Jt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},Dr=20;function fn(t){const e=Jt[t??"upperCase"]??t??Jt.upperCase,n=Array.from(e);return n.length>0?n:Array.from(Jt.upperCase)}function $r(t,e,n){let r=(t|0)^Math.imul(e+1,2654435761)^Math.imul(n+1,2246822507);return r=Math.imul(r^r>>>16,2146121005),r=Math.imul(r^r>>>15,2221713035),(r^r>>>16)>>>0}function dn(t,e,n=0){const r=t.from??"",s=t.to,a=Math.max(0,Math.min(1,e));if(a<=0)return r;if(a>=1)return s;const i=Array.from(r),o=Array.from(s),c=t.rightToLeft??!1;if(t.mode==="type"){const p=Math.round(a*Math.max(i.length,o.length));return c?i.slice(0,Math.max(0,i.length-p)).join("")+o.slice(Math.max(0,o.length-p)).join(""):o.slice(0,p).join("")+i.slice(p).join("")}const h=Math.max(0,Math.min(.999,t.revealDelay??0)),l=Math.max(0,(a-h)/(1-h)),u=Math.floor(l*o.length),m=t.tweenLength===!1?o.length:Math.round(i.length+(o.length-i.length)*a),d=fn(t.chars),y=t.refreshRate??Dr,g=y>0?Math.floor(n*y/1e3):0,_=t.seed??1;let M="";for(let p=0;p<m;p++){const T=c?p>=m-u:p<u,S=c?o[o.length-(m-p)]:o[p];T&&S!==void 0||S===" "||S===`
2
+ `?M+=S:M+=d[$r(_,p,g)%d.length]}return M}class Zt{id;name;_captions;_tracks=[];_trackPlayers=new Map;_motionPathTracks=new Map;_springTracks=new Map;_textTracks=new Map;_config;_currentTime=0;_playbackState="idle";_direction="forward";_loopIteration=0;_explicitDuration;_repeatDelayRemaining=0;_wrapAfterDelay=!1;onUpdate=null;onComplete=null;constructor(e){if(this.id=e.id,this.name=e.name,this._captions=e.captions,this._config=e.config??{},this._explicitDuration=e.config?.duration,e.tracks)for(const n of e.tracks)this.addTrack(n)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(e){if(this._explicitDuration=e,e!==void 0)this._config={...this._config,duration:e};else if(this._config.duration!==void 0){const n={...this._config};delete n.duration,this._config=n}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(e){this._config.speed=e}get drawingRate(){return this._config.drawingRate??0}set drawingRate(e){const n={...this._config};e>0?n.drawingRate=e:delete n.drawingRate,this._config=n}play(){const e=this.duration;this._direction==="forward"&&this._currentTime>=e&&e>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&e>0&&(this._currentTime=e,this._loopIteration=0),this._playbackState="playing"}pause(){this._playbackState="paused"}stop(){this._playbackState="idle",this._repeatDelayRemaining=0,this._wrapAfterDelay=!1,this._currentTime=0,this._loopIteration=0,this._direction="forward"}seek(e){const n=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(e,n)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(e){if(this._playbackState!=="playing")return;const n=this.duration;if(n<=0)return;let s=e*this.speed;if(this._repeatDelayRemaining>0){const o=Math.min(this._repeatDelayRemaining,s);if(this._repeatDelayRemaining-=o,s-=o,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const a=1e3;for(let o=0;o<a&&s>0&&this._playbackState==="playing";o++)if(this._direction==="forward"){const c=n-this._currentTime;if(s>=c){if(s-=c,this._currentTime=n,!this._handleEndReached())break}else this._currentTime+=s,s=0}else{const c=this._currentTime;if(s>=c){if(s-=c,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=s,s=0}const i=this.getStateAtTime(this._currentTime);this.onUpdate?.(i)}getStateAtTime(e){const n=new Map;if(e=pe(e,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(e,n);else for(const[r,s]of this._trackPlayers){const a=s.getTrack().property;for(const{target:i,value:o,start:c}of s.getTargetValues(e))this._write(n,r,i,a,o,e-c)}return{values:n,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(e,n){const r=new Map;for(const[s,a]of this._trackPlayers){const i=a.getTrack().property;for(const{target:o,value:c,start:h}of a.getTargetValues(e)){const l=`${o}\0${i}`,u=h<=e,m=r.get(l);(!m||(u!==m.started?u:u?h>=m.start:h<=m.start))&&r.set(l,{trackId:s,target:o,property:i,value:c,start:h,started:u})}}for(const{trackId:s,target:a,property:i,value:o,start:c}of r.values())this._write(n,s,a,i,o,e-c)}_write(e,n,r,s,a,i){if(a===void 0)return;let o=e.get(r);o||(o=new Map,e.set(r,o));const c=this._textTracks.get(n);if(c&&typeof a=="number"){o.set("text",dn(c.textConfig,a,Math.max(0,i)));return}const h=this._motionPathTracks.get(n);if(h&&typeof a=="number"){const l=Wt(h.motionPathConfig,a);o.set("motionPathX",l.x),o.set("motionPathY",l.y),h.motionPathConfig.autoRotate&&o.set("motionPathRotate",l.angle)}else o.set(s,a)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const e=new Set;this._sharedWrites=!1;t:for(const n of this._tracks)for(const r of V(n)){const s=`${r}\0${n.property}`;if(e.has(s)){this._sharedWrites=!0;break t}e.add(s)}}return this._sharedWrites}addTrack(e){if(this._tracks.push(e),this._sharedWrites=null,Y(e)){this._trackPlayers.set(e.id,new ln(e));return}if(z(e)){this._trackPlayers.set(e.id,new hn(e)),this._springTracks.set(e.id,e);return}if(ft(e))this._trackPlayers.set(e.id,new ot(e)),this._textTracks.set(e.id,e);else if(Rt(e)){const n={id:e.id,target:e.target,property:e.property,keyframes:e.keyframes,delay:e.delay,endDelay:e.endDelay,targets:e.targets,stagger:e.stagger};this._trackPlayers.set(e.id,new ot(n)),this._motionPathTracks.set(e.id,e)}else this._trackPlayers.set(e.id,new ot(e))}replaceTrack(e,n){const r=this._tracks.findIndex(a=>a.id===e);if(r<0)return;const s=this._tracks.slice(r+1);this.removeTrack(e);for(const a of s)this.removeTrack(a.id);this.addTrack(n);for(const a of s)this.addTrack(a)}removeTrack(e){this._tracks=this._tracks.filter(n=>n.id!==e),this._sharedWrites=null,this._trackPlayers.delete(e),this._motionPathTracks.delete(e),this._springTracks.delete(e),this._textTracks.delete(e)}getTracks(e={}){return this._tracks.filter(n=>this._matches(n,e))}removeTracks(e={}){const n=this.getTracks(e).map(r=>r.id);for(const r of n)this.removeTrack(r);return n}getTrackSpan(e){const n=this._trackPlayers.get(e);if(!n)return;const r=n.getTrack(),s=r.delay??0;if(z(r)||Y(r))return{from:s,to:n.getDuration()};const a=r.keyframes;if(!(!a||a.length===0))return{from:a[0].time+s,to:n.getDuration()}}findConflicts(){const e=[];for(let n=0;n<this._tracks.length;n++){const r=this._tracks[n],s=this.getTrackSpan(r.id);if(s)for(let a=0;a<n;a++){const i=this._tracks[a];if(i.property!==r.property)continue;const o=V(i).filter(u=>V(r).includes(u));if(o.length===0)continue;const c=this.getTrackSpan(i.id);if(!c||!(c.from<=s.to&&s.from<=c.to))continue;const l=s.from>=c.from;for(const u of o)e.push({target:u,property:r.property,losingTrackId:l?i.id:r.id,winningTrackId:l?r.id:i.id})}}return e}_matches(e,n){if(n.id!==void 0&&e.id!==n.id||n.property!==void 0&&e.property!==n.property||n.target!==void 0&&!V(e).includes(n.target))return!1;if(n.timeRange){const r=this.getTrackSpan(e.id);if(!r||r.to<n.timeRange.from||r.from>n.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:It(this._tracks),id:this.id,name:this.name,config:{...this._config},tracks:[...this._tracks],...this.captions&&{captions:this.captions}}}get config(){return this._config}get markers(){return[...this._config.markers??[]].sort((e,n)=>e.time-n.time)}setMarkers(e){const n=e&&e.length>0?[...e].sort((s,a)=>s.time-a.time).map(s=>({...s})):void 0,r={...this._config};n?r.markers=n:delete r.markers,this._config=r}get captions(){return this._captions}setCaptions(e){const n={};for(const[r,s]of Object.entries(e??{}))n[r]={...s};this._captions=Object.keys(n).length>0?n:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let e=0;for(const[,n]of this._trackPlayers)e=Math.max(e,n.getDuration());return e}_handleEndReached(){const e=this._config.loop??0;return e===-1||this._loopIteration<e?(this._loopIteration++,this._armRepeatDelay(),this._config.alternate?this._direction="reverse":this._repeatDelayRemaining>0?this._wrapAfterDelay=!0:this._currentTime=0,this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}_handleStartReached(){const e=this._config.loop??0;return this._config.alternate&&(e===-1||this._loopIteration<e)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const Or=100;function Lr(t,e,n,r){const s=[],a=[],{duration:i,alternate:o}=r,c=(d,y,g,_)=>{a.push([d,y]);const M=[];t.forEach((p,T)=>{(g==="forward"?(_?p>=d:p>d)&&p<=y:(_?p<=d:p<d)&&p>=y)&&M.push(T)}),M.sort((p,T)=>(g==="forward"?t[p]-t[T]:t[T]-t[p])||p-T);for(const p of M)s.push({kind:"event",index:p,direction:g})};let h=e.time,l=e.direction,u=e.fresh===!0;const m=Math.min(Or,Math.max(0,n.iteration-e.iteration));for(let d=0;d<m;d++){const y=l==="forward"?i:0;c(h,y,l,u),s.push({kind:"repeat"}),o?(l=l==="forward"?"reverse":"forward",h=y,u=!1):(h=l==="forward"?0:i,u=!0)}return m>0&&r.holding&&!o?{crossings:s,passes:a}:(c(h,n.time,l,u),{crossings:s,passes:a})}function mn(t){return Y(t)?{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:gn(t.inertia),...N(t)}:z(t)?{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...N(t)}:ft(t)?{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:t.keyframes.map(te),...N(t)}:Rt(t)?{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:t.keyframes.map(te),...N(t)}:{id:t.id,target:t.target,property:t.property,keyframes:t.keyframes.map(te),...t.interpolation!==void 0&&{interpolation:t.interpolation},...N(t)}}function gn(t){return{...t,...Array.isArray(t.end)&&{end:[...t.end]}}}function te(t){return{time:t.time,value:t.value,...t.easing&&{easing:t.easing}}}function N(t){const e=t.endDelay;return{...t.delay!==void 0&&{delay:t.delay},...e!==void 0&&{endDelay:e},...t.targets!==void 0&&{targets:[...t.targets]},...t.stagger!==void 0&&{stagger:{...t.stagger}}}}function yn(t){if(Y(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"inertia",inertia:gn(e.inertia),...N(e)}}if(z(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"spring",spring:{...e.spring},...N(e)}}if(ft(t)){const e=t;return{id:e.id,target:e.target,property:"text",textConfig:{...e.textConfig},keyframes:[...e.keyframes].sort((n,r)=>n.time-r.time),...N(e)}}if(t.property==="motionPath"&&"motionPathConfig"in t){const e=t,n=[...e.keyframes].sort((r,s)=>r.time-s.time);return{id:e.id,target:e.target,property:"motionPath",motionPathConfig:{...e.motionPathConfig},keyframes:n,...N(e)}}return un({id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,...t.interpolation!==void 0&&{interpolation:t.interpolation},...N(t)})}function pn(t){const e=t._config.markers;return{formatVersion:It(t.tracks),id:t.id,name:t.name,config:{duration:t.duration>0?t.duration:void 0,loop:t._config.loop,speed:t._config.speed,alternate:t._config.alternate,repeatDelay:t._config.repeatDelay,...t._config.drawingRate?{drawingRate:t._config.drawingRate}:{},...e&&{markers:e.map(n=>({...n}))}},tracks:t.tracks.map(mn),...t.captions&&{captions:JSON.parse(JSON.stringify(t.captions))}}}function Mn(t){const e=t.formatVersion??1;if(e>vt)throw new Error(`tinyfly: this animation uses format version ${e}, but this tinyfly reads up to version ${vt}. Update tinyfly to play it.`);return new Zt({id:t.id,name:t.name,config:t.config,tracks:t.tracks.map(yn),captions:t.captions})}function Fr(t){return JSON.stringify(pn(t))}function Nr(t){const e=JSON.parse(t);return Mn(e)}function _n(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e>>>0}function ee(t){let e=t>>>0||2654435769;return{seed:t>>>0,next(){return e^=e<<13,e>>>=0,e^=e>>17,e^=e<<5,e>>>=0,e/4294967296}}}function ne(t,e,n){return e+t.next()*(n-e)}function bn(t,e,n,r){if(r<=0)return ne(t,e,n);const s=Math.floor((n-e)/r),a=Math.round(t.next()*s);return e+a*r}function Xr(t,e){if(e.length!==0)return e[Math.floor(t.next()*e.length)]}function Yr(t,e=0,n=1){const r=1-t.next(),s=t.next();return e+n*Math.sqrt(-2*Math.log(r))*Math.cos(2*Math.PI*s)}function zr(t,e){const n=[...e];for(let r=n.length-1;r>0;r--){const s=Math.floor(t.next()*(r+1));[n[r],n[s]]=[n[s],n[r]]}return n}const Tn=/^([+\-*/])=\s*(-?[\d.]+)$/,kn=/^random\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*(?:,\s*(-?[\d.]+)\s*)?\)$/i;function jr(t){return typeof t!="string"?!1:Tn.test(t.trim())||kn.test(t.trim())}function re(t,e={}){if(typeof t!="string")return t;const n=t.trim(),r=Tn.exec(n);if(r){const[,a,i]=r,o=e.base??0,c=Number.parseFloat(i);switch(a){case"+":return o+c;case"-":return o-c;case"*":return o*c;case"/":return c===0?o:o/c}}const s=kn.exec(n);if(s){if(!e.random)throw new Error(`resolveValue: "${n}" needs a random source — pass one via context.random`);const a=Number.parseFloat(s[1]),i=Number.parseFloat(s[2]),o=s[3]!==void 0?Number.parseFloat(s[3]):void 0;return o!==void 0?bn(e.random,a,i,o):ne(e.random,a,i)}return t}function wn(t,e=0,n){const r=[];let s=e;for(const a of t){const i=re(a,{base:s,random:n});r.push(i),typeof i=="number"&&(s=i)}return r}class Ur{random;constructor(e){this.random=ee(e)}get seed(){return this.random.seed}resolve(e,n=0){return re(e,{base:n,random:this.random})}resolveSequence(e,n=0){return wn(e,n,this.random)}}const Vr=600;function Br(t){if(Array.isArray(t)){const[m,d,y,g]=t;return{fn:Sn(m,d,y,g),bezier:[m,d,y,g]}}const{segments:e}=B(t);if(e.length===0)throw new Error(`customEase: no curve in "${t}"`);const n=e[0].startX,r=e[0].startY,s=e[e.length-1],a=s.endX-n,i=s.endY-r;if(a===0||i===0)throw new Error(`customEase: "${t}" must move along both axes`);const o=m=>(m-n)/a,c=m=>(m-r)/i;if(e.length===1&&s.type==="C"){const[m,d,y,g]=s.points,_=[o(m),c(d),o(y),c(g)];return{fn:Sn(..._),bezier:_}}const h=[],l=[],u=Math.max(8,Math.ceil(Vr/e.length));for(const m of e)for(let d=h.length===0?0:1;d<=u;d++){const[y,g]=Qr(m,d/u);h.push(o(y)),l.push(c(g))}return{fn:Gr(h,l)}}function Hr(t={}){const n=.1+Math.max(0,Math.min(1,t.strength??.7))*.7,r=[1];for(let a=n;a>.002;a*=n)r.push(2*Math.sqrt(a));const s=r.reduce((a,i)=>a+i,0);return a=>{if(a<=0)return 0;if(a>=1)return 1;let i=a*s;for(let o=0;o<r.length;o++){if(i<=r[o]){if(o===0)return(i/r[0])**2;const c=r[o]/2,h=c*c,l=i-c;return 1-(h-l*l)}i-=r[o]}return 1}}function qr(t={}){const e=Math.max(1,t.wiggles??10),n=t.type??"easeOut",r=s=>n==="uniform"?1:n==="easeInOut"?Math.sin(Math.PI*s):(1-s)**2;return s=>s<=0||s>=1?0:Math.sin(s*e*Math.PI*2)*r(s)}function Qr(t,e){if(t.type==="L"){const[h,l]=t.points;return[t.startX+(h-t.startX)*e,t.startY+(l-t.startY)*e]}const[n,r,s,a,i,o]=t.points,c=1-e;return[c*c*c*t.startX+3*c*c*e*n+3*c*e*e*s+e*e*e*i,c*c*c*t.startY+3*c*c*e*r+3*c*e*e*a+e*e*e*o]}function Gr(t,e){return n=>{if(n<=t[0])return e[0];if(n>=t[t.length-1])return e[e.length-1];let r=0,s=t.length-1;for(;s-r>1;){const i=r+s>>1;t[i]<=n?r=i:s=i}const a=t[s]-t[r];return a===0?e[s]:e[r]+(n-t[r])/a*(e[s]-e[r])}}function Sn(t,e,n,r){const s=(i,o,c)=>3*(1-i)*(1-i)*i*o+3*(1-i)*i*i*c+i*i*i,a=(i,o,c)=>3*(1-i)*(1-i)*o+6*(1-i)*i*(c-o)+3*i*i*(1-c);return i=>{if(i<=0)return 0;if(i>=1)return 1;let o=i;for(let l=0;l<8;l++){const u=s(o,t,n)-i,m=a(o,t,n);if(Math.abs(u)<1e-6)return s(o,e,r);if(Math.abs(m)<1e-6)break;o-=u/m}let c=0,h=1;o=i;for(let l=0;l<40;l++)s(o,t,n)<i?c=o:h=o,o=(c+h)/2;return s(o,e,r)}}const Kr=350,Wr=300,Jr=550;function Zr(t,e={}){const n=e.lead??Kr,r=e.gap??Wr,s=e.tail??Jr,a=[];let i=0;return t.forEach((o,c)=>{const h=[];let l=i+n;o.lines.forEach((m,d)=>{if(!(m.duration>=0))throw new Error(`narration: scene ${c} line ${d} has an invalid duration (${m.duration})`);d>0&&(l+=r),h.push({id:m.id??`s${c}-l${d}`,scene:c,line:d,start:l,end:l+m.duration,text:m.text}),l+=m.duration});const u=l+s+(o.tail??0);a.push({id:o.id??`s${c}`,start:i,duration:u-i,cues:h}),i=u}),{duration:i,scenes:a,cues:a.flatMap(o=>o.cues)}}function ts(t){return t.cues.map(e=>({id:e.id,time:e.start,label:e.text}))}function es(t,e){let n=t.scenes[0];for(const r of t.scenes)if(e>=r.start)n=r;else break;return n}const ct=t=>6e4/t.bpm;function kt(t,e){return t.offset+e*ct(t)}function ut(t,e){return(e-t.offset)/ct(t)}function ns(t,e){return kt(t,Math.round(ut(t,e)))}function rs(t,e){return kt(t,Math.ceil(ut(t,e)-1e-9))}function ss(t,e,n){const r=Math.max(1,Math.round(t.beatsPerBar??4)),s=[];if(!(t.bpm>0)||n<e)return s;for(let a=Math.ceil(ut(t,e)-1e-9);;a++){const i=kt(t,a);if(i>n+1e-9)break;s.push({time:i,bar:(a%r+r)%r===0,n:a})}return s}const Z=100;function as(t,e,n={}){const r=n.minBpm??70,s=n.maxBpm??180,a=Math.max(1,Math.round(e/Z)),i=Math.min(t.length,Math.round((n.maxSeconds??60)*e)),o=Math.floor(i/a);if(o<4)return{bpm:120,offset:0,confidence:0};const c=new Float64Array(o);for(let k=0;k<o;k++){let w=0;for(let A=k*a;A<(k+1)*a;A++)w+=t[A]*t[A];c[k]=Math.log(1e-6+w/a)}const h=new Float64Array(o);for(let k=1;k<o;k++)h[k]=Math.max(0,c[k]-c[k-1]);const l=h.reduce((k,w)=>k+w,0)/o;for(let k=0;k<o;k++)h[k]=Math.max(0,h[k]-l);const u=Math.max(1,Math.floor(60*Z/s)),m=Math.min(o-1,Math.ceil(60*Z/r)),d=k=>{let w=0;for(let A=k;A<o;A++)w+=h[A]*h[A-k];return w/(o-k)};let y=0;for(let k=0;k<o;k++)y+=h[k]*h[k];y/=o;let g=u,_=-1/0;for(let k=u;k<=m;k++){const w=60*Z/k,A=Math.exp(-.5*(Math.log2(w/120)/.9)**2),v=d(k)*A;v>_&&(_=v,g=k)}const M=k=>{const w=Math.floor(k);return w<0||w+1>=o?0:h[w]+(h[w+1]-h[w])*(k-w)},p=(k,w)=>{let A=0;for(let v=w;v<o;v+=k)A+=M(v);return A};let T=g,S=0,b=-1/0;for(let k=g-.6;k<=g+.6+1e-9;k+=.02){if(k<1)continue;const w=Math.max(1,Math.round(k*4));for(let A=0;A<w;A++){const v=A/w*k,E=p(k,v);E>b&&(b=E,S=v,T=k)}}const x=60*Z/T,P=y>0?Math.max(0,Math.min(1,d(g)/y)):0,I=(S+.5)*1e3/Z;return{bpm:Math.round(x*100)/100,offset:Math.round(I%(6e4/x)),confidence:P}}const is=600,os=250,Pn=1;function cs(t,e){const n=e.target??"Camera",r={x:e.stage.width/2,y:e.stage.height/2},s={},a=(u,m,d,y)=>{const g=s[u]??=[];for(;g.length>0&&g[g.length-1].time>=m;)g.pop();g.push({time:m,value:d,...y?{easing:y}:{}})},i=u=>{const m=u.rotate*Math.PI/180,d=(u.focusX-r.x)*u.scale,y=(u.focusY-r.y)*u.scale;return{x:-(d*Math.cos(m)-y*Math.sin(m)),y:-(d*Math.sin(m)+y*Math.cos(m)),scale:u.scale,rotate:u.rotate}},o=(u,m,d)=>{const y=i(m);for(const g of["x","y","scale","rotate"])a(g,u,y[g],d)};let c={focusX:r.x,focusY:r.y,scale:1,rotate:0};const h=[...t].sort((u,m)=>u.at-m.at),l=h.filter(u=>!("shake"in u));l.length>0&&o(0,c);for(const u of l)if("frame"in u){const m=Math.max(Pn,u.duration??is);o(u.at,c),c={focusX:u.frame.focus?.x??r.x,focusY:u.frame.focus?.y??r.y,scale:u.frame.scale??1,rotate:u.frame.rotate??0},o(u.at+m,c,u.easing??(m>Pn?"ease-in-out":void 0))}else{const{follow:m}=u,d=m.lag??os,y=new Zt({id:"follow",tracks:[{id:"x",target:"s",property:"x",keyframes:m.x}]}),g=p=>y.getStateAtTime(p).values.get("s")?.get("x")??c.focusX,_=[u.at,...m.x.map(p=>p.time).filter(p=>p>u.at&&p<u.until),u.until];o(u.at,c);const M=p=>({focusX:g(p)+(m.lead??0),focusY:m.y??c.focusY,scale:m.scale??c.scale,rotate:c.rotate});for(const p of _){const T=m.x.find(S=>S.time===p)?.easing;o(p+d,M(p),p===u.at?"ease-in-out":T)}c=M(u.until)}for(const u of h.filter(m=>"shake"in m)){const m=u.shake.strength??12,d=u.shake.roll??1.5,y=1e3/(u.shake.frequency??24),g=ee(u.shake.seed??Math.round(u.at)+1),_=()=>g.next()*2-1;for(const M of["shakeX","shakeY","shakeRotate"])a(M,u.at,0);for(let M=u.at+y;M<u.at+u.duration;M+=y){const p=1-(M-u.at)/u.duration;a("shakeX",M,_()*m*p),a("shakeY",M,_()*m*p),a("shakeRotate",M,_()*d*p)}for(const M of["shakeX","shakeY","shakeRotate"])a(M,u.at+u.duration,0,"ease-out")}return Object.entries(s).map(([u,m])=>({id:`${n}-${u}`,target:n,property:u,keyframes:m}))}function An(t,e){const n=t.toLowerCase(),r=e.toLowerCase();let s=Array.from({length:r.length+1},(a,i)=>i);for(let a=1;a<=n.length;a++){const i=[a];for(let o=1;o<=r.length;o++)i[o]=Math.min(s[o]+1,i[o-1]+1,s[o-1]+(n[a-1]===r[o-1]?0:1));s=i}return s[r.length]}function xn(t,e){const n=t.toLowerCase(),r=e.find(i=>i.toLowerCase().includes(n)||n.includes(i.toLowerCase()));if(r&&Math.min(t.length,r.length)>=3)return r;let s,a=1/0;for(const i of e){const o=An(t,i);o<a&&(a=o,s=i)}return s!==void 0&&a<=Math.max(2,Math.floor(t.length/3))?s:void 0}function us(t,e,n,r){const s=typeof e=="string"?r??xn(e,n):void 0;return`Unknown ${t} ${JSON.stringify(e)}${s?`: did you mean "${s}"?`:"."} Known: ${n.join(", ")}`}function hs(t,e){const n=e.step??33,r=e.stiffness??120,s=e.damping??9,a=e.mass??1;let i=t(e.start),o=0;const c=[{time:e.start,value:i}];let h=e.start+n;for(let l=e.start+1;l<=e.end;l++){const m=r*(t(l)-i)-s*o;o+=m/a*.001,i+=o*.001,(l>=h||l===e.end)&&(c.push({time:l,value:i}),h+=n)}return c}function q(t,e,n=1){if(!(e>0))return 0;const r=t*n/e;return r-Math.floor(r)}function se(t){const e=t-Math.floor(t);return 1-Math.abs(e*2-1)}function ls(t,e){const n=Math.max(1,Math.round(e.cycles??1)),r=e.amplitude??1,s=q(t,e.period,n)+(e.phase??0),a=s-Math.floor(s);switch(e.shape??"sine"){case"triangle":return r*(se(a+.25)*2-1);case"square":return a<.5?r:-r;default:return r*Math.sin(a*Math.PI*2)}}function fs(t,e){const n=Math.max(1,Math.round(e.cycles??1)),r=typeof e.easing=="function"?e.easing:Mt(e.easing??"ease-in-out"),s=q(t,e.period,n)+(e.phase??0);return r(se(s))}function ds(t,e){const n=vn(e.seed),r=Math.max(1,Math.round(e.cycles??1)),s=(q(t,e.period,1)+(e.phase??0))*Math.PI*2,a=r/Math.PI;return In([Math.cos(s)*a+7.31,Math.sin(s)*a+3.17],n,e.octaves??1)}function ms(t,e,n){const r=vn(n.seed),s=Math.max(1,Math.round(n.cycles??1)),a=Math.max(1,Math.round(n.cyclesAlong??1)),i=q(t,n.period,1)*Math.PI*2,o=q(e,n.periodAlong,1)*Math.PI*2,c=s/Math.PI,h=a/Math.PI;return In([Math.cos(i)*c+5.13,Math.sin(i)*c+9.47,Math.cos(o)*h+2.71,Math.sin(o)*h+6.29],r,n.octaves??1)}const vn=t=>typeof t=="string"?_n(t):(t??0)>>>0;function In(t,e,n){const r=Math.max(1,Math.min(6,Math.round(n)));let s=0,a=1,i=0;for(let o=0;o<r;o++){const c=2**o;s+=a*gs(t.map(h=>h*c),e+o*1013),i+=a,a*=.5}return s/i}function gs(t,e){const n=t.length,r=t.map(Math.floor),a=t.map((o,c)=>o-r[c]).map(o=>o*o*(3-2*o));let i=0;for(let o=0;o<1<<n;o++){let c=1;const h=[];for(let l=0;l<n;l++){const u=o>>l&1;c*=u?a[l]:1-a[l],h.push(r[l]+u)}c!==0&&(i+=c*ys(h,e))}return i}function ys(t,e){let n=(e^2654435769)>>>0;for(const r of t)n=Math.imul(n^(r|0),2246822507)>>>0,n=(n^n>>>13)>>>0,n=Math.imul(n,3266489909)>>>0,n=(n^n>>>16)>>>0;return n/4294967296*2-1}function ps(t,e={}){if(t.length===0)throw new Error("curve: needs at least one key");const r={id:"curve",target:"curve",property:"value",keyframes:t.map(a=>({time:a.at,value:a.value,easing:a.easing})).sort((a,i)=>a.time-i.time),interpolation:e.interpolation},s=new ot(r);return a=>s.getValueAtTime(a)}function Ms(t,e){return e*ct({bpm:t.bpm})}function _s(t,e){const n=Math.max(1,Math.round(t/ct(e)));return{beats:n,grid:{...e,bpm:n*6e4/t}}}function bs(t,e,n={}){const r=Math.max(1e-6,n.attack??.05),s=Math.max(1e-6,n.decay??.4),a=ut(e,t),i=a-Math.floor(a),o=i<r?i/r:Math.max(0,1-(i-r)/s),c=n.barAccent??0;if(c<=0)return o;const h=Math.max(1,Math.round(e.beatsPerBar??4)),u=(Math.floor(a)%h+h)%h===0;return o*(u?1+c:1)/(1+c)}function Ts(t,e,n={}){const r=n.fps??30,s=Math.max(1,Math.round(e/r)),a=Math.max(1,Math.ceil(t.length/s)),i=new Float32Array(a),o=Math.min(.99,Math.max(0,n.smoothing??.5));let c=0,h=0;for(let l=0;l<a;l++){let u=0;const m=l*s,d=Math.min(t.length,m+s);for(let g=m;g<d;g++)u+=t[g]*t[g];const y=d>m?Math.sqrt(u/(d-m)):0;c=y>c?y:c*o+y*(1-o),i[l]=c,h=Math.max(h,c)}if(n.normalize!==!1&&h>0)for(let l=0;l<a;l++)i[l]/=h;return i}function ks(t,e,n=30,r){if(t.length===0)return 0;const a=(r?q(e,r)*r:e)*n/1e3,i=Math.floor(a),o=t[Math.min(t.length-1,Math.max(0,i))],c=t[Math.min(t.length-1,Math.max(0,i+1))];return o+(c-o)*(a-i)}const Rn={"16:9":16/9,"2.39:1":2.39,"4:3":4/3,"1:1":1,"9:16":9/16,"4:5":4/5},ae=t=>typeof t=="number"?t:Rn[t];function ws(t,e){const n=ae(e),r=t.width/t.height;if(n>=r){const a=t.width/n;return{x:0,y:(t.height-a)/2,width:t.width,height:a}}const s=t.height*n;return{x:(t.width-s)/2,y:0,width:s,height:t.height}}function Ss(t,e){const n=ae(t),r=s=>Math.max(2,Math.round(s/2)*2);return"width"in e?{width:r(e.width),height:r(e.width/n)}:{width:r(e.height*n),height:r(e.height)}}function Ps(t,e={}){const n=r=>({x:t.x+t.width*(1-r)/2,y:t.y+t.height*(1-r)/2,width:t.width*r,height:t.height*r});return{action:n(e.action??.9),title:n(e.title??.8)}}const X=t=>Math.round(t*1e3)/1e3;function As(t,e={}){if(t.length===0)return"";const n=e.curviness??1,r=e.closed??!1,s=t.length;let a=`M${X(t[0].x)} ${X(t[0].y)}`;if(s===1)return a;const i=c=>r?t[(c%s+s)%s]:t[Math.max(0,Math.min(s-1,c))],o=r?s:s-1;for(let c=0;c<o;c++){const h=i(c-1),l=i(c),u=i(c+1),m=i(c+2);if(n===0){a+=` L${X(u.x)} ${X(u.y)}`;continue}const d=n/6,y=l.x+(u.x-h.x)*d,g=l.y+(u.y-h.y)*d,_=u.x-(m.x-l.x)*d,M=u.y-(m.y-l.y)*d;a+=` C${X(y)} ${X(g)} ${X(_)} ${X(M)} ${X(u.x)} ${X(u.y)}`}return r?`${a} Z`:a}const D=(t,e=0)=>{const n=parseFloat(t??"");return Number.isFinite(n)?n:e};function xs(t){const e=(t??"").trim().split(/[\s,]+/).filter(Boolean).map(Number),n=[];for(let r=0;r+1<e.length;r+=2)n.push({x:e[r],y:e[r+1]});return n}function vs(t){const e=t.attributes;switch(t.tag.toLowerCase()){case"path":return e.d??null;case"circle":case"ellipse":{const n=D(e.cx),r=D(e.cy),s=t.tag.toLowerCase()==="circle"?D(e.r):D(e.rx),a=t.tag.toLowerCase()==="circle"?D(e.r):D(e.ry);return`M${n+s} ${r} A${s} ${a} 0 1 1 ${n-s} ${r} A${s} ${a} 0 1 1 ${n+s} ${r} Z`}case"rect":{const n=D(e.x),r=D(e.y),s=D(e.width),a=D(e.height);let i=e.rx!=null?D(e.rx):e.ry!=null?D(e.ry):0,o=e.ry!=null?D(e.ry):i;return i=Math.min(i,s/2),o=Math.min(o,a/2),i===0||o===0?`M${n} ${r} H${n+s} V${r+a} H${n} Z`:`M${n+i} ${r} H${n+s-i} A${i} ${o} 0 0 1 ${n+s} ${r+o} V${r+a-o} A${i} ${o} 0 0 1 ${n+s-i} ${r+a} H${n+i} A${i} ${o} 0 0 1 ${n} ${r+a-o} V${r+o} A${i} ${o} 0 0 1 ${n+i} ${r} Z`}case"line":return`M${D(e.x1)} ${D(e.y1)} L${D(e.x2)} ${D(e.y2)}`;case"polyline":case"polygon":{const n=xs(e.points);if(n.length===0)return null;const r=n.map((s,a)=>`${a===0?"M":"L"}${s.x} ${s.y}`).join(" ");return t.tag.toLowerCase()==="polygon"?`${r} Z`:r}default:return null}}function Is(t,e,n){const r=Math.max(2,Math.round(n.samples??32)),s=Math.max(0,n.length),a=n.since!==void 0?Math.max(e-s,n.since):e-s;if(a>=e)return[];const i=n.period,o=[];for(let c=0;c<r;c++){const h=a+(e-a)*c/(r-1),l=i&&i>0&&c<r-1?(h%i+i)%i:h;o.push({at:t(l),time:h,age:s>0?(e-h)/s:0})}return o}const Rs=2.5;function Es(t){const e=[],n=[],r=t.length,s=(a,i)=>{for(let o=a+i;o>=0&&o<r;o+=i){const c=(t[o].x-t[a].x)*i,h=(t[o].y-t[a].y)*i,l=Math.hypot(c,h);if(l>1e-9)return[c/l,h/l]}return null};for(let a=0;a<r;a++){const i=t[a],o=s(a,-1),c=s(a,1),h=o??c??[1,0],l=c??o??[1,0];let u=h[0]+l[0],m=h[1]+l[1];const d=Math.hypot(u,m);d<1e-9?(u=h[0],m=h[1]):(u/=d,m/=d);const y=u*h[0]+m*h[1],g=Math.min(Rs,1/Math.max(y,1e-6)),_=i.width/2*g;e.push({x:i.x-m*_,y:i.y+u*_}),n.push({x:i.x+m*_,y:i.y-u*_})}return{left:e,right:n}}function Cs(t){const e=t.length;if(e<2)return null;const n=t[e-1];for(let r=e-2;r>=0;r--){const s=n.x-t[r].x,a=n.y-t[r].y,i=Math.hypot(s,a);if(i>1e-9)return{x:n.x,y:n.y,radius:n.width/2,start:Math.atan2(s/i,-a/i)}}return null}const Ds={scale:1,turn:0,x:0,y:0};function $s(t={}){return{scale:t.scale??1,turn:t.turn??0,x:t.x??0,y:t.y??0}}function En(t,e,n){const{ax:r,ay:s}=wt(t,e);return{scale:t,turn:e,x:n.x-(r*n.x-s*n.y),y:n.y-(s*n.x+r*n.y)}}function ie(t,e){const{ax:n,ay:r}=wt(t.scale,t.turn);return{x:n*e.x-r*e.y+t.x,y:r*e.x+n*e.y+t.y}}function Os(t,e){const n=ie(e,{x:t.x,y:t.y});return{scale:t.scale*e.scale,turn:t.turn+e.turn,x:n.x,y:n.y}}function Ls(t){if(t.scale===0)throw new Error("invertSimilarity: a scale of 0 cannot be undone");const e={scale:1/t.scale,turn:-t.turn,x:0,y:0},n=ie(e,{x:t.x,y:t.y});return{...e,x:-n.x,y:-n.y}}function Cn(t){const{ax:e,ay:n}=wt(t.scale,t.turn),r=1-e,s=-n,a=r*r+s*s;return a<1e-18?null:{x:(t.x*r+t.y*s)/a,y:(t.y*r-t.x*s)/a}}function Fs(t,e){if(t.scale<=0)throw new Error("powSimilarity: the scale must be positive");const n=Math.pow(t.scale,e),r=t.turn*e,s=Cn(t);return s?En(n,r,s):{scale:n,turn:r,x:t.x*e,y:t.y*e}}function Ns(t){const{ax:e,ay:n}=wt(t.scale,t.turn);return[e,n,-n,e,t.x,t.y]}const wt=(t,e)=>{const n=e*Math.PI/180;return{ax:t*Math.cos(n),ay:t*Math.sin(n)}};function St([t,e,n],r={}){const s=r.scale??1,a=r.centre??{x:0,y:0},i=Math.sqrt(3)/2;return{x:a.x+(t-e)*i*s,y:a.y+((t+e)*.5-n)*s}}const oe=([t,e,n])=>t+e+n;function ce(t,e={}){const[n,r,s]=t.min,[a,i,o]=t.max,c=m=>St(m,e),h=[(n+a)/2,(r+i)/2,(s+o)/2],l=oe(h),u=[{side:"top",depth:l,tag:t.tag,points:[c([n,r,o]),c([a,r,o]),c([a,i,o]),c([n,i,o])]},{side:"left",depth:l,tag:t.tag,points:[c([n,i,s]),c([a,i,s]),c([a,i,o]),c([n,i,o])]},{side:"right",depth:l,tag:t.tag,points:[c([a,r,s]),c([a,i,s]),c([a,i,o]),c([a,r,o])]}];return t.hide?u.filter(m=>!t.hide.includes(m.side)):u}function ue(t,e={}){return t.map(n=>({box:n,depth:oe([(n.min[0]+n.max[0])/2,(n.min[1]+n.max[1])/2,(n.min[2]+n.max[2])/2])})).sort((n,r)=>n.depth-r.depth).flatMap(({box:n})=>ce(n,e))}function Xs(t={}){const e=t.size??10,r=(t.thickness??2)/2,s=[{tag:0,min:[-r,-r,-r],max:[e-r,r,r]},{tag:1,min:[e-r,-r,-r],max:[e+r,e-r,r]},{tag:2,min:[e-r,e-r,-r],max:[e+r,e+r,e]}],a=t.centre??{x:0,y:0},i=St([2*e/3,e/3,e/3],{scale:t.scale}),o={centre:{x:a.x-i.x,y:a.y-i.y},scale:t.scale};return{boxes:s,faces:[...ue(s,o),...ce({...s[0],hide:["right"]},o)]}}function Ys(t={}){const e=Math.max(2,Math.round(t.steps??8)),n=t.tread??1.5,r=t.rise??.25,s=t.width??3,a=t.base??1.5,i=Math.max(1,Math.round(e*(n-2*r)/(n+2*r))),o=2*(e+i),c=n*(e-i)/o,h=[{dir:[1,0,0],across:[0,1,0],count:e},{dir:[0,1,0],across:[-1,0,0],count:e},{dir:[-1,0,0],across:[0,-1,0],count:i},{dir:[0,-1,0],across:[1,0,0],count:i}],l=[];let u=[0,0,0],m=0;for(const M of h){for(let p=0;p<M.count;p++){const T=m*c,S=[u[0]+M.dir[0]*p*n,u[1]+M.dir[1]*p*n,0],b=[S[0]+M.dir[0]*n+M.across[0]*s,S[1]+M.dir[1]*n+M.across[1]*s,0];l.push({tag:m,min:[Math.min(S[0],b[0]),Math.min(S[1],b[1]),0],max:[Math.max(S[0],b[0]),Math.max(S[1],b[1]),T+a]}),m++}u=[u[0]+M.dir[0]*M.count*n,u[1]+M.dir[1]*M.count*n,0]}const d=o*c,y=t.centre??{x:0,y:0},g=St([e*n/2,e*n/2,d/2+a],{scale:t.scale}),_={centre:{x:y.x-g.x,y:y.y-g.y},scale:t.scale};return{boxes:l,faces:ue(l,_),rise:c}}function Dn(t,e,n){let r=0;for(const s of t){const a=(e-s.x)**2+(n-s.y)**2;r+=a>1e-9?s.r*s.r/a:1e9}return r}function zs(t,e={}){if(t.length===0)return[];const n=e.threshold??1,r=Math.max(.5,e.cell??4),s=Math.sqrt(1/n)*1.6,a=e.bounds??{x:Math.min(...t.map(d=>d.x-d.r*s)),y:Math.min(...t.map(d=>d.y-d.r*s)),width:Math.max(...t.map(d=>d.x+d.r*s))-Math.min(...t.map(d=>d.x-d.r*s)),height:Math.max(...t.map(d=>d.y+d.r*s))-Math.min(...t.map(d=>d.y-d.r*s))},i=Math.max(2,Math.ceil(a.width/r)+1),o=Math.max(2,Math.ceil(a.height/r)+1),c=new Float64Array(i*o);for(let d=0;d<o;d++)for(let y=0;y<i;y++)c[d*i+y]=Dn(t,a.x+y*r,a.y+d*r)-n;const h=(d,y)=>c[y*i+d],l=(d,y,g,_,M,p)=>{const T=g===p?.5:g/(g-p);return{x:d+(_-d)*T,y:y+(M-y)*T}},u=[];for(let d=0;d+1<o;d++)for(let y=0;y+1<i;y++){const g=a.x+y*r,_=a.y+d*r,M=g+r,p=_+r,T=[h(y,d),h(y+1,d),h(y+1,d+1),h(y,d+1)],S=(T[0]>0?1:0)|(T[1]>0?2:0)|(T[2]>0?4:0)|(T[3]>0?8:0);if(S===0||S===15)continue;const b=()=>l(g,_,T[0],M,_,T[1]),x=()=>l(M,_,T[1],M,p,T[2]),P=()=>l(g,p,T[3],M,p,T[2]),I=()=>l(g,_,T[0],g,p,T[3]),k=(T[0]+T[1]+T[2]+T[3])/4>0;switch(S){case 1:case 14:u.push([I(),b()]);break;case 2:case 13:u.push([b(),x()]);break;case 3:case 12:u.push([I(),x()]);break;case 4:case 11:u.push([x(),P()]);break;case 6:case 9:u.push([b(),P()]);break;case 7:case 8:u.push([I(),P()]);break;case 5:k?u.push([I(),P()],[b(),x()]):u.push([I(),b()],[x(),P()]);break;case 10:k?u.push([I(),b()],[x(),P()]):u.push([I(),P()],[b(),x()]);break}}const m=js(u);return e.smooth===!1?m:m.map(d=>$n($n(d)))}function js(t){const e=a=>`${Math.round(a.x*1e3)},${Math.round(a.y*1e3)}`,n=new Map;t.forEach(([a,i],o)=>{for(const c of[a,i]){const h=e(c);n.has(h)||n.set(h,[]),n.get(h).push(o)}});const r=new Array(t.length).fill(!1),s=[];for(let a=0;a<t.length;a++){if(r[a])continue;r[a]=!0;const i=[t[a][0],t[a][1]];let o=t[a][1];for(;;){const c=(n.get(e(o))??[]).find(u=>!r[u]);if(c===void 0)break;r[c]=!0;const[h,l]=t[c];if(o=e(h)===e(o)?l:h,e(o)===e(i[0]))break;i.push(o)}i.length>=3&&s.push(i)}return s}function $n(t){const e=[];for(let n=0;n<t.length;n++){const r=t[n],s=t[(n+1)%t.length];e.push({x:r.x*.75+s.x*.25,y:r.y*.75+s.y*.25},{x:r.x*.25+s.x*.75,y:r.y*.25+s.y*.75})}return e}function Us(t){const e=Math.min(1,Math.max(0,t.progress));if(e<=0)return[];const n=t.width/2,r=n*(.55+.75*e),s=Math.max(t.length*e,r*1.2),a=t.x,i=t.y+s-r,o=Math.max(.1,n*(.35-.3*e)),c=i-Math.sqrt(Math.max(0,r*r-o*o)),h=Math.max(0,c-t.y),l=8,u=[],m=[];for(let p=0;p<=l;p++){const T=p/l,S=o+(n-o)*Math.pow(1-T,1.6+1.4*e);u.push({x:a-S,y:t.y+h*T}),m.push({x:a+S,y:t.y+h*T})}const d=Math.max(8,Math.round(t.segments??12)),y=Math.acos(Math.min(1,o/r)),g=-y,_=Math.PI+y,M=[];for(let p=1;p<d;p++){const T=g+(_-g)*p/d;M.push({x:a+Math.cos(T)*r,y:i+Math.sin(T)*r})}return[...m,...M,...u.reverse()]}function Vs(t){const e=Math.min(1,Math.max(0,t.grow??1)),n=e>=1?1:1-Math.pow(1-e,3)+.08*Math.sin(e*Math.PI)*e,r=t.r*Math.max(0,n);if(r<=0)return[];const s=Math.max(12,Math.round(t.segments??48)),a=t.wobble??.05,i=t.time??0,o=t.period?i/t.period:i/2500,c=(o-Math.floor(o))*Math.PI*2,h=t.seed??0,l=[];for(let u=0;u<s;u++){const m=u/s*Math.PI*2,d=1+a*(Math.sin(2*m+c+h)*.6+Math.sin(3*m-2*c+h*1.7)*.4);l.push({x:t.x+Math.cos(m)*r*d,y:t.y+Math.sin(m)*r*d})}return l}function Bs(t){const e=t.progress;if(e<=0||e>=1)return[];const n=Math.max(3,Math.round(t.pieces??8)),r=[],s=t.r*(1+1.2*e),a=Math.PI*2/n*.6*(1-e);for(let i=0;i<n;i++){const o=i/n*Math.PI*2+.3,c=[];for(let h=0;h<=4;h++){const l=o-a/2+a*h/4;c.push({x:t.x+Math.cos(l)*s,y:t.y+Math.sin(l)*s})}r.push(c)}return r}function Hs(t,e={}){const n=Math.max(.05,1+t);return{sx:e.keep==="volume"?1/Math.sqrt(n):1/n,sy:n}}function qs(t,e,n={x:0,y:0}){return t.map(r=>({x:n.x+(r.x-n.x)*e.sx,y:n.y+(r.y-n.y)*e.sy}))}function Qs(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function he(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function On(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function Pt(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function le(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function fe(t){return Math.hypot(t[0],t[1],t[2])}function Gs(t,e){return fe(he(t,e))}function de(t){const e=fe(t);return e===0?[0,0,0]:On(t,1/e)}function Ks(t,e,n){return[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n,t[2]+(e[2]-t[2])*n]}const Ws=Object.freeze(Object.defineProperty({__proto__:null,add:Qs,cross:le,distance:Gs,dot:Pt,length:fe,lerp:Ks,normalize:de,scale:On,subtract:he},Symbol.toStringTag,{value:"Module"})),Js=Math.PI/180;function Zs(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function ta(t,e){const n=new Array(16);for(let r=0;r<4;r++)for(let s=0;s<4;s++){let a=0;for(let i=0;i<4;i++)a+=t[i*4+s]*e[r*4+i];n[r*4+s]=a}return n}function ea(t){return[1,0,0,0,0,1,0,0,0,0,1,0,t[0],t[1],t[2],1]}function na(t){return[t[0],0,0,0,0,t[1],0,0,0,0,t[2],0,0,0,0,1]}function Ln(t){const[e,n,r,s]=t;return[1-2*(n*n+r*r),2*(e*n+r*s),2*(e*r-n*s),0,2*(e*n-r*s),1-2*(e*e+r*r),2*(n*r+e*s),0,2*(e*r+n*s),2*(n*r-e*s),1-2*(e*e+n*n),0,0,0,0,1]}function ra(t,e,n){const r=Ln(e);for(let s=0;s<3;s++)r[s]*=n[0],r[4+s]*=n[1],r[8+s]*=n[2];return r[12]=t[0],r[13]=t[1],r[14]=t[2],r}function sa(t){const e=new Array(16);for(let n=0;n<4;n++)for(let r=0;r<4;r++)e[r*4+n]=t[n*4+r];return e}function aa(t){const[e,n,r,s,a,i,o,c,h,l,u,m,d,y,g,_]=t,M=e*i-n*a,p=e*o-r*a,T=e*c-s*a,S=n*o-r*i,b=n*c-s*i,x=r*c-s*o,P=h*y-l*d,I=h*g-u*d,k=h*_-m*d,w=l*g-u*y,A=l*_-m*y,v=u*_-m*g,E=M*v-p*A+T*w+S*k-b*I+x*P;if(Math.abs(E)<1e-12)return null;const R=1/E;return[(i*v-o*A+c*w)*R,(r*A-n*v-s*w)*R,(y*x-g*b+_*S)*R,(u*b-l*x-m*S)*R,(o*k-a*v-c*I)*R,(e*v-r*k+s*I)*R,(g*T-d*x-_*p)*R,(h*x-u*T+m*p)*R,(a*A-i*k+c*P)*R,(n*k-e*A-s*P)*R,(d*b-y*T+_*M)*R,(l*T-h*b-m*M)*R,(i*I-a*w-o*P)*R,(e*w-n*I+r*P)*R,(y*p-d*S-g*M)*R,(h*S-l*p+u*M)*R]}function ia(t,e,n,r){const s=1/Math.tan(t*Js/2),a=1/(n-r);return[s/e,0,0,0,0,s,0,0,0,0,(r+n)*a,-1,0,0,2*r*n*a,0]}function oa(t,e,n,r,s,a){const i=1/(e-t),o=1/(r-n),c=1/(a-s);return[2*i,0,0,0,0,2*o,0,0,0,0,-2*c,0,-(e+t)*i,-(r+n)*o,-(a+s)*c,1]}function ca(t,e,n=[0,1,0]){const r=de(he(t,e)),s=de(le(n,r)),a=le(r,s);return[s[0],a[0],r[0],0,s[1],a[1],r[1],0,s[2],a[2],r[2],0,-Pt(s,t),-Pt(a,t),-Pt(r,t),1]}function ua(t,e){const n=t[0]*e[0]+t[4]*e[1]+t[8]*e[2]+t[12],r=t[1]*e[0]+t[5]*e[1]+t[9]*e[2]+t[13],s=t[2]*e[0]+t[6]*e[1]+t[10]*e[2]+t[14],a=t[3]*e[0]+t[7]*e[1]+t[11]*e[2]+t[15];return a===1||a===0?[n,r,s]:[n/a,r/a,s/a]}const ha=Object.freeze(Object.defineProperty({__proto__:null,compose:ra,fromQuat:Ln,identity:Zs,invert:aa,lookAt:ca,multiply:ta,orthographic:oa,perspective:ia,scaling:na,transformPoint:ua,translation:ea,transpose:sa},Symbol.toStringTag,{value:"Module"}));f.Clock=jn,f.DEFAULT_BAKE_INTERVAL_MS=Qt,f.DEFAULT_INERTIA_FRICTION=$t,f.DEFAULT_SPRING=L,f.FORMAT_VERSION=vt,f.FRAME_ASPECTS=Rn,f.IDENTITY_SIMILARITY=Ds,f.INERTIA_MAX_DURATION_MS=be,f.InertiaTrackPlayer=ln,f.MORPH_SAMPLES=fr,f.ManualClock=zn,f.SPRING_MAX_DURATION_MS=Dt,f.SPRING_PRESETS=Un,f.SPRING_STEP_MS=G,f.SpringSampler=et,f.SpringTrackPlayer=hn,f.Timeline=Zt,f.TrackPlayer=ot,f.ValueResolver=Ur,f.applySimilarity=ie,f.aspectOf=ae,f.audioEnvelope=Ts,f.backOut=Ee,f.bakeEasing=an,f.bakeInertiaTrack=Kt,f.bakeSpringTrack=Gt,f.beatAtTime=ut,f.beatLength=ct,f.beatPeriod=Ms,f.beatPulse=bs,f.beatTime=kt,f.beatsBetween=ss,f.bounceOut=Re,f.bubblePath=Vs,f.bubblePop=Bs,f.cameraTracks=cs,f.charactersFor=fn,f.clearMorphCache=Tr,f.clearPathCache=or,f.closestName=xn,f.composeSimilarity=Os,f.createCubicBezier=ve,f.createRandom=ee,f.createTrack=un,f.criticalDamping=qn,f.curve=ps,f.customBounce=Hr,f.customEase=Br,f.customWiggle=qr,f.deserializeTimeline=Mn,f.deserializeTrack=yn,f.detectTempo=as,f.dripPath=Us,f.easeIn=Pe,f.easeInCubic=Ot,f.easeInOut=xe,f.easeInOutCubic=Ft,f.easeInOutQuad=Se,f.easeInQuad=ke,f.easeOut=Ae,f.easeOutCubic=Lt,f.easeOutQuad=we,f.editDistance=An,f.elasticOut=Ie,f.envelopeAt=ks,f.expandParametricEasings=on,f.formatVersionFor=It,f.frameRect=ws,f.frameSize=Ss,f.fromJSON=Nr,f.getEasingFunction=Mt,f.getInterpolator=qt,f.getMotionPathPoint=Wt,f.getPathLength=cr,f.getPointAtProgress=Le,f.hasKeyframes=ye,f.hashSeed=_n,f.heldTime=pe,f.inertiaDuration=rt,f.inertiaRest=nt,f.inertiaValueAt=yt,f.inertiaVelocityAt=Wn,f.interpolateArray=en,f.interpolateColor=tn,f.interpolateMotionPath=Cr,f.interpolateNumber=F,f.interpolatePathString=rn,f.interpolateQuaternion=nn,f.interpolateString=Ht,f.invertSimilarity=Ls,f.isCubicBezierEasing=Q,f.isInertiaTrack=Y,f.isMotionPathPoint=Yn,f.isMotionPathTrack=Rt,f.isParametricEasing=lt,f.isPathData=Ve,f.isSpringTrack=z,f.isTextTrack=ft,f.isUnderdamped=Hn,f.isUnresolved=jr,f.isoDepth=oe,f.isometricBoxFaces=ce,f.isometricFaces=ue,f.linear=pt,f.loopBeats=_s,f.loopEase=fs,f.loopNoise=ds,f.mat4=ha,f.maxStaggerDistance=Me,f.metaballContours=zs,f.metaballField=Dn,f.morphPath=Ue,f.narrationMarkers=ts,f.narrationSceneAt=es,f.naturalRest=Te,f.nearestBeat=ns,f.nextBeat=rs,f.parametricEasing=De,f.parsePath=B,f.penroseStairs=Ys,f.penroseTriangle=Xs,f.phaseOf=q,f.pingPong=se,f.planNarration=Zr,f.playheadCrossings=Lr,f.pointAtDistance=Xt,f.pointsToPath=As,f.powSimilarity=Fs,f.projectIsometric=St,f.quat=xr,f.randomBetween=ne,f.randomChoice=Xr,f.randomNormal=Yr,f.randomSnapped=bn,f.resolveSequence=wn,f.resolveValue=re,f.ribbon=Es,f.ribbonHeadCap=Cs,f.safeAreas=Ps,f.scalePoints=qs,f.serializeTimeline=pn,f.serializeTrack=mn,f.shapeToPathData=vs,f.shuffled=zr,f.similarity=$s,f.similarityAbout=En,f.similarityFixedPoint=Cn,f.similarityMatrix=Ns,f.simplifyKeyframes=cn,f.springDuration=Bn,f.springFollow=hs,f.springValueAt=Vn,f.squashStretch=Hs,f.staggerDistance=Et,f.staggerOffset=Ct,f.staggerOffsets=_e,f.staggerSpan=dt,f.stepsEasing=Ce,f.textAt=dn,f.toJSON=Fr,f.toKeyframedTrack=Rr,f.toKeyframedTracks=Er,f.torusNoise=ms,f.trackTargets=V,f.trailSamples=Is,f.unknownName=us,f.vec3=Ws,f.wobble=ls,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
@@ -36,3 +36,10 @@ export declare function randomBetween(source: RandomSource, min: number, max: nu
36
36
  export declare function randomSnapped(source: RandomSource, min: number, max: number, step: number): number;
37
37
  /** One item from `items`, drawn from `source`. */
38
38
  export declare function randomChoice<T>(source: RandomSource, items: readonly T[]): T | undefined;
39
+ /**
40
+ * A normally distributed value (mean `mean`, standard deviation `sd`), drawn
41
+ * from `source` by the Box–Muller transform. Uses two draws per value.
42
+ */
43
+ export declare function randomNormal(source: RandomSource, mean?: number, sd?: number): number;
44
+ /** A shuffled copy of `items` (Fisher–Yates), drawn from `source`; `items` is unchanged. */
45
+ export declare function shuffled<T>(source: RandomSource, items: readonly T[]): T[];
@@ -218,7 +218,117 @@ export interface EquationItem extends ItemBase {
218
218
  /** A soft panel behind the text (default true for `screen` equations) */
219
219
  backdrop?: boolean;
220
220
  }
221
- export type MathItem = GridItem | AxesItem | VectorItem | BasisItem | PointItem | FunctionItem | ParametricItem | PolygonItem | LineItem | LabelItem | EquationItem | TangentItem | RiemannItem | AreaItem | TaylorItem;
221
+ /**
222
+ * A distribution whose numbers may be value names, so a slider or timeline can
223
+ * move the mean, the spread or n: `{ kind: 'normal', mean: 'mu', sd: 1 }`.
224
+ */
225
+ export type DistributionRef = {
226
+ kind: 'normal';
227
+ mean?: NumRef;
228
+ sd?: NumRef;
229
+ } | {
230
+ kind: 'uniform';
231
+ min?: NumRef;
232
+ max?: NumRef;
233
+ } | {
234
+ kind: 'exponential';
235
+ rate?: NumRef;
236
+ } | {
237
+ kind: 'binomial';
238
+ n: NumRef;
239
+ p: NumRef;
240
+ } | {
241
+ kind: 'poisson';
242
+ rate: NumRef;
243
+ } | {
244
+ kind: 'dice';
245
+ count?: NumRef;
246
+ sides?: NumRef;
247
+ } | {
248
+ kind: 'mean';
249
+ of: DistributionRef;
250
+ count: NumRef;
251
+ };
252
+ /** Samples from a distribution, binned: fills as `count` grows (the same samples every time, from `seed`). */
253
+ export interface HistogramItem extends ItemBase {
254
+ kind: 'histogram';
255
+ distribution: DistributionRef;
256
+ /** How many samples so far (animate it to watch the bars grow) */
257
+ count: NumRef;
258
+ /** [from, to, number of bins]; discrete distributions default to one bin per whole number */
259
+ bins?: [number, number, number];
260
+ /** Bar heights as a density (area 1, matches the curve; default) or as counts */
261
+ scale?: 'density' | 'count';
262
+ /** Draw the distribution's own density over the bars (default false) */
263
+ curve?: boolean;
264
+ /** Seed for the samples (default the item id) */
265
+ seed?: number | string;
266
+ fillOpacity?: number;
267
+ }
268
+ /** A distribution's density curve (or bars, for whole-number ones), with an optional shaded probability. */
269
+ export interface DistributionItem extends ItemBase {
270
+ kind: 'distribution';
271
+ distribution: DistributionRef;
272
+ /** Shade P(from ≤ X ≤ to); `\val{ID.p}` shows it */
273
+ shade?: [NumRef, NumRef];
274
+ domain?: [number, number];
275
+ width?: number;
276
+ fillOpacity?: number;
277
+ }
278
+ /** A Galton board: balls bounce left or right at each row of pegs and pile up into a bell. */
279
+ export interface GaltonItem extends ItemBase {
280
+ kind: 'galton';
281
+ /** Rows of pegs (default 10) */
282
+ rows?: number;
283
+ /** Balls dropped so far; the fractional part is the next ball's way down */
284
+ balls: NumRef;
285
+ seed?: number | string;
286
+ /** World units between pegs (default 0.5) */
287
+ spacing?: number;
288
+ /** World y of the top peg (default near the top of the view) */
289
+ top?: number;
290
+ }
291
+ /** Random points: a uniform scatter (Monte Carlo) or noisy points about a line (regression). */
292
+ export interface ScatterItem extends ItemBase {
293
+ kind: 'scatter';
294
+ points: {
295
+ kind: 'uniform';
296
+ x: [number, number];
297
+ y: [number, number];
298
+ } | {
299
+ kind: 'linear';
300
+ slope: NumRef;
301
+ intercept: NumRef;
302
+ noise: NumRef;
303
+ x: [number, number];
304
+ };
305
+ /** How many points so far */
306
+ count: NumRef;
307
+ seed?: number | string;
308
+ /** An expression in x and y; points where it is true take `insideColor` (e.g. `x^2 + y^2 - 1`, true when ≤ 0) */
309
+ inside?: string;
310
+ insideColor?: string;
311
+ /** Draw the least-squares line (default false) */
312
+ fit?: boolean;
313
+ /** px at a 600 px figure (default 3) */
314
+ radius?: number;
315
+ }
316
+ /** A unit square cut by a prior and a test's two error rates: Bayes' rule as areas. */
317
+ export interface BayesItem extends ItemBase {
318
+ kind: 'bayes';
319
+ /** P(condition) */
320
+ prior: NumRef;
321
+ /** P(positive | condition) */
322
+ truePositive: NumRef;
323
+ /** P(positive | no condition) */
324
+ falsePositive: NumRef;
325
+ /** World bottom-left corner and size (default most of the view) */
326
+ at?: Vec2;
327
+ size?: Vec2;
328
+ /** Label the four regions (default true) */
329
+ labels?: boolean;
330
+ }
331
+ export type MathItem = GridItem | AxesItem | VectorItem | BasisItem | PointItem | FunctionItem | ParametricItem | PolygonItem | LineItem | LabelItem | EquationItem | TangentItem | RiemannItem | AreaItem | TaylorItem | HistogramItem | DistributionItem | GaltonItem | ScatterItem | BayesItem;
222
332
  export type MathItemKind = MathItem['kind'];
223
333
  export declare const ITEM_KINDS: readonly MathItemKind[];
224
334
  export type MathThemeName = 'dark' | 'light' | 'chalk';
@@ -1,6 +1,7 @@
1
1
  import { type Mat2 } from '../linear/mat2';
2
2
  import { type Vec2 } from '../linear/vec2';
3
- import type { MathTheme, NumRef, VecRef } from './figure-spec';
3
+ import type { DistributionRef, MathTheme, NumRef, VecRef } from './figure-spec';
4
+ import type { Distribution } from '../prob/distributions';
4
5
  import type { Plane } from './plane';
5
6
  /** Values by name, as the figure holds them at one moment. */
6
7
  export type Values = Record<string, number | number[]>;
@@ -31,3 +32,8 @@ export declare function vecOf(values: Values, ref: VecRef): Vec2;
31
32
  export declare function matrixOf(values: Values, name: string | undefined): Mat2;
32
33
  /** A number given directly or by the name of a number value. */
33
34
  export declare function numOf(values: Values, ref: NumRef): number;
35
+ /**
36
+ * A distribution with its value names replaced by the values' numbers. Counts
37
+ * (binomial n, dice count and sides, a mean's count) are rounded to whole numbers.
38
+ */
39
+ export declare function distributionOf(values: Values, ref: DistributionRef): Distribution;
@@ -0,0 +1,13 @@
1
+ import { type PointsSpec } from '../../prob/scatter';
2
+ import type { BayesItem, DistributionItem, GaltonItem, HistogramItem, ScatterItem } from '../figure-spec';
3
+ import { type Shape } from '../display-list';
4
+ import { type ItemContext } from '../item-context';
5
+ /** How many samples a histogram or scatter has so far: a whole number, at most 20 000. */
6
+ export declare const sampleCount: (n: number) => number;
7
+ export declare function layoutHistogram(item: HistogramItem, ctx: ItemContext): Shape[];
8
+ export declare function layoutDistribution(item: DistributionItem, ctx: ItemContext): Shape[];
9
+ export declare function layoutGalton(item: GaltonItem, ctx: ItemContext): Shape[];
10
+ export declare function layoutScatter(item: ScatterItem, ctx: ItemContext): Shape[];
11
+ /** A scatter item's points spec with its numbers resolved. */
12
+ export declare function pointsSpec(item: ScatterItem, ctx: Pick<ItemContext, 'values'>): PointsSpec;
13
+ export declare function layoutBayes(item: BayesItem, ctx: ItemContext): Shape[];
@@ -16,6 +16,11 @@ export { parseExpression, expressionNames, ExpressionError, FUNCTIONS, CONSTANTS
16
16
  export { evaluate, compile, compileDerivative, type Scope } from './expr/evaluate';
17
17
  export { differentiate, nthDerivative, expressionToString } from './expr/differentiate';
18
18
  export { integrate } from './figure/derived';
19
+ export { density, meanOf, sdOf, supportOf, sample, samples, isDiscrete, distributionProblem, DISTRIBUTION_KINDS, type Distribution, type DistributionKind } from './prob/distributions';
20
+ export { binSamples, defaultBins, summary, type Bin } from './prob/histogram';
21
+ export { scatterPoints, leastSquares, type PointsSpec } from './prob/scatter';
22
+ export { ballPath, ballAt, binOf } from './prob/galton';
23
+ export { bayesAreas, type BayesAreas } from './prob/bayes';
19
24
  export { parseTex, TexError, TEX_COMMANDS, SYMBOLS, type TexNode, type TexClass } from './tex/tex-parser';
20
25
  export { layoutTex, type TexLayout, type TexPiece, type TexGlyph, type TexRule, type TexStroke, type TexLayoutOptions } from './tex/tex-layout';
21
26
  export { morphEquation, type MorphPiece, type PlacedLayout } from './tex/equation-morph';
@@ -33,6 +38,7 @@ export { mountMath, mountAllMath, type MountedMathFigure } from './embed/mount-m
33
38
  export { mathExplorable, type MathExplorable, type ExplorableOptions, type SliderControl, type DragHandle } from './embed/explorable';
34
39
  export { linearMapFigure, determinantFigure, eigenFigure, vectorSumFigure, spanFigure, MATRIX_TEX, type PresetOptions, } from './presets/linear-algebra';
35
40
  export { tangentFigure, secantFigure, riemannFigure, areaFigure, taylorFigure, limitFigure, type CalculusOptions } from './presets/calculus';
41
+ export { normalFigure, binomialFigure, cltFigure, galtonFigure, monteCarloPiFigure, regressionFigure, bayesFigure, type ProbabilityOptions } from './presets/probability';
36
42
  import type { MathFigureSpec } from './figure/figure-spec';
37
43
  import { type MathProps } from './figure/layout-figure';
38
44
  /** A figure checked up front: returns it unchanged, or throws a message that says how to fix it. */
@@ -0,0 +1,62 @@
1
+ import type { DistributionRef, MathFigureSpec, MathThemeName } from '../figure/figure-spec';
2
+ /**
3
+ * Ready-made probability and statistics figures. Each returns a plain
4
+ * MathFigureSpec whose moving parts are number values:
5
+ *
6
+ * - normalFigure: `mu`, `sigma`, and the shaded range `a`..`b`
7
+ * - binomialFigure: `n` and `p`
8
+ * - cltFigure: `k` (how many draws are averaged) and `samples`
9
+ * - galtonFigure: `balls` (fractional: the next ball is on its way down)
10
+ * - monteCarloPiFigure: `count` points
11
+ * - regressionFigure: `count`, `slope`, `noise`
12
+ * - bayesFigure: `prior`, `sensitivity`, `falsePositive`
13
+ */
14
+ export interface ProbabilityOptions {
15
+ width?: number;
16
+ height?: number;
17
+ theme?: MathThemeName;
18
+ x?: [number, number];
19
+ y?: [number, number];
20
+ }
21
+ /** The normal curve, with P(a ≤ X ≤ b) shaded. */
22
+ export declare function normalFigure(options?: ProbabilityOptions & {
23
+ mean?: number;
24
+ sd?: number;
25
+ shade?: [number, number];
26
+ }): MathFigureSpec;
27
+ /** Binomial(n, p) as bars. */
28
+ export declare function binomialFigure(options?: ProbabilityOptions & {
29
+ n?: number;
30
+ p?: number;
31
+ }): MathFigureSpec;
32
+ /**
33
+ * The central limit theorem: the mean of k draws from a skewed distribution
34
+ * (exponential by default) piles up into a normal curve as k grows.
35
+ */
36
+ export declare function cltFigure(options?: ProbabilityOptions & {
37
+ of?: DistributionRef;
38
+ k?: number;
39
+ samples?: number;
40
+ }): MathFigureSpec;
41
+ /** A Galton board in a tall frame: balls bounce through the pegs into a bell. */
42
+ export declare function galtonFigure(options?: ProbabilityOptions & {
43
+ rows?: number;
44
+ balls?: number;
45
+ }): MathFigureSpec;
46
+ /** Estimate π by throwing points at a square and counting those inside the circle. */
47
+ export declare function monteCarloPiFigure(options?: ProbabilityOptions & {
48
+ count?: number;
49
+ }): MathFigureSpec;
50
+ /** Noisy points about a line, and the least-squares line through them. */
51
+ export declare function regressionFigure(options?: ProbabilityOptions & {
52
+ slope?: number;
53
+ intercept?: number;
54
+ noise?: number;
55
+ count?: number;
56
+ }): MathFigureSpec;
57
+ /** A medical test as areas: how likely is the condition, given a positive result? */
58
+ export declare function bayesFigure(options?: ProbabilityOptions & {
59
+ prior?: number;
60
+ sensitivity?: number;
61
+ falsePositive?: number;
62
+ }): MathFigureSpec;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Bayes' rule as areas of a unit square: the prior splits it into a column
3
+ * with the condition and one without; each column splits into those who test
4
+ * positive and those who do not.
5
+ */
6
+ export interface BayesAreas {
7
+ /** P(condition and positive) */
8
+ truePositive: number;
9
+ /** P(no condition and positive) */
10
+ falsePositive: number;
11
+ /** P(positive) */
12
+ positive: number;
13
+ /** P(condition | positive) */
14
+ posterior: number;
15
+ }
16
+ export declare function bayesAreas(prior: number, sensitivity: number, falsePositiveRate: number): BayesAreas;