@algorisys/tinyfly 0.81.0 → 0.86.2

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.
Files changed (62) hide show
  1. package/README.md +12 -5
  2. package/lib/addons/adapters.js +363 -248
  3. package/lib/addons/characters.js +1658 -1342
  4. package/lib/addons/dom-adapter-Cphr2HZn.js +372 -0
  5. package/lib/addons/gsap-compat.js +197 -187
  6. package/lib/addons/load-scene-vp14_Jj-.js +324 -0
  7. package/lib/addons/scene-3d-webgl.js +237 -0
  8. package/lib/addons/scene-3d.js +306 -0
  9. package/lib/addons/shading-ByG9UXd0.js +85 -0
  10. package/lib/browser/tinyfly-scene-3d-webgl.iife.js +114 -0
  11. package/lib/browser/tinyfly-scene-3d.iife.js +3 -0
  12. package/lib/browser/tinyfly.iife.js +4 -4
  13. package/lib/browser/tinyfly.js +3295 -2613
  14. package/lib/browser/tinyfly.umd.js +4 -4
  15. package/lib/cli/tools.js +137 -22
  16. package/lib/embed/tinyfly-embed.iife.js +4 -4
  17. package/lib/embed/tinyfly-embed.js +921 -833
  18. package/lib/engine/tinyfly-engine.js +1022 -776
  19. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  20. package/lib/headless/headless.js +264 -7
  21. package/lib/player/tinyfly-player.es.js +459 -371
  22. package/lib/player/tinyfly-player.iife.js +2 -2
  23. package/lib/player/tinyfly-player.umd.js +2 -2
  24. package/lib/types/adapters/canvas/canvas-adapter.d.ts +36 -0
  25. package/lib/types/adapters/transform-3d.d.ts +99 -0
  26. package/lib/types/adapters/webgl/webgl-adapter.d.ts +17 -0
  27. package/lib/types/characters/character.d.ts +20 -1
  28. package/lib/types/characters/dance.d.ts +47 -0
  29. package/lib/types/characters/index.d.ts +3 -1
  30. package/lib/types/characters/rig/body-plan.d.ts +3 -1
  31. package/lib/types/characters/rig/skeleton.d.ts +57 -0
  32. package/lib/types/characters/scene-objects.d.ts +2 -0
  33. package/lib/types/characters/species/human.d.ts +8 -0
  34. package/lib/types/compat/gsap/vars.d.ts +8 -0
  35. package/lib/types/engine/core/bake.d.ts +3 -1
  36. package/lib/types/engine/index.d.ts +1 -0
  37. package/lib/types/engine/interpolation/interpolators.d.ts +10 -3
  38. package/lib/types/engine/math/index.d.ts +11 -0
  39. package/lib/types/engine/math/mat4.d.ts +37 -0
  40. package/lib/types/engine/math/quat.d.ts +39 -0
  41. package/lib/types/engine/math/vec3.d.ts +16 -0
  42. package/lib/types/engine/types.d.ts +23 -2
  43. package/lib/types/scene-3d/camera.d.ts +27 -0
  44. package/lib/types/scene-3d/canvas-2d-renderer.d.ts +21 -0
  45. package/lib/types/scene-3d/geometry/extrude.d.ts +17 -0
  46. package/lib/types/scene-3d/geometry/mesh.d.ts +36 -0
  47. package/lib/types/scene-3d/geometry/primitives.d.ts +16 -0
  48. package/lib/types/scene-3d/geometry/triangulate.d.ts +24 -0
  49. package/lib/types/scene-3d/index.d.ts +20 -0
  50. package/lib/types/scene-3d/load-scene.d.ts +31 -0
  51. package/lib/types/scene-3d/object-kind.d.ts +54 -0
  52. package/lib/types/scene-3d/resolve-scene.d.ts +122 -0
  53. package/lib/types/scene-3d/scene-3d-adapter.d.ts +46 -0
  54. package/lib/types/scene-3d/scene-types.d.ts +191 -0
  55. package/lib/types/scene-3d/shading.d.ts +20 -0
  56. package/lib/types/scene-3d/validate-scene.d.ts +11 -0
  57. package/lib/types/scene-3d/webgl/gl-data.d.ts +28 -0
  58. package/lib/types/scene-3d/webgl/index.d.ts +16 -0
  59. package/lib/types/scene-3d/webgl/shaders.d.ts +29 -0
  60. package/lib/types/scene-3d/webgl/webgl2-renderer.d.ts +33 -0
  61. package/package.json +10 -2
  62. package/lib/addons/dom-adapter-CrNwoomd.js +0 -243
@@ -1,2 +1,2 @@
1
- (function(l,q){typeof exports=="object"&&typeof module<"u"?q(exports):typeof define=="function"&&define.amd?define(["exports"],q):(l=typeof globalThis<"u"?globalThis:l||self,q(l.tinyfly={}))})(this,(function(l){"use strict";function q(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function it(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const Z=1;function ot(t){return t.property==="text"&&"textConfig"in t}function x(t){return t.kind==="inertia"&&"inertia"in t}function U(t){return t.kind==="spring"&&"spring"in t}function Tt(t){return t.property==="motionPath"&&"motionPathConfig"in t}function en(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"angle"in t}function Wt(t){return"keyframes"in t}class nn{_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 rn{_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 bt(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 jt(t,e="start"){if(t<=1)return 0;let n=0;for(let r=0;r<t;r++)n=Math.max(n,bt(r,t,e));return n}function kt(t,e,n){if(n.offsets)return n.offsets[t]??0;const r=n.from??"start",s=bt(t,e,r);if(n.amount!==void 0){const a=jt(e,r);return a===0?0:n.amount*s/a}return n.each!==void 0?n.each*s:0}function Gt(t,e){return Array.from({length:t},(n,r)=>kt(r,t,e))}function ct(t,e){return t<=1?0:Math.max(...Gt(t,e))}const K=1,St=6e4,ut=St/K,O={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1},sn={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 J{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??O.stiffness,this.damping=e.damping??O.damping,this.mass=e.mass??O.mass,this.restDelta=e.restDelta??O.restDelta,this.restSpeed=e.restSpeed??O.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=e.velocity??O.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/K);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/K-n;return r+(s-r)*a}settleTime(){return this.simulateTo(ut+1),this.settledStep!==null?this.settledStep*K:St}simulateTo(e){if(this.settledStep!==null)return;const n=Math.min(e,ut+1),r=K/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 u=s+this.velocity*r;if(this.samples.push(u),this.isAtRest(u)){this.settledStep=this.samples.length-1;return}}this.samples.length>ut&&(this.settledStep=ut)}}function an(t,e){return new J(t).valueAt(e)}function on(t){return new J(t).settleTime()}function cn(t){const e=t.stiffness??O.stiffness,n=t.damping??O.damping,r=t.mass??O.mass;return n<2*Math.sqrt(e*r)}function un(t){const e=t.stiffness??O.stiffness,n=t.mass??O.mass;return 2*Math.sqrt(e*n)}const At=4,ln=.002,hn=1e-4,Qt=6e4;function lt(t){const e=t.friction??At;return e>0?e:At}function Zt(t){return t.from+t.velocity/lt(t)}function fn(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 tt(t){let e=fn(Zt(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 et(t){const e=Math.abs(tt(t)-t.from);if(e===0)return 0;const n=t.restDelta??Math.max(hn,e*ln);if(n>=e)return 0;const r=Math.log(e/n)/lt(t);return Math.min(Qt,r*1e3)}function ht(t,e){if(e<=0)return t.from;const n=tt(t);if(e>=et(t))return n;const r=lt(t);return t.from+(n-t.from)*(1-Math.exp(-r*e/1e3))}function dn(t,e){const n=lt(t),r=tt(t);return e>=et(t)?0:(r-t.from)*n*Math.exp(-n*Math.max(0,e)/1e3)}const ft=t=>t,Jt=t=>t*t,te=t=>1-(1-t)*(1-t),ee=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,Pt=t=>t*t*t,vt=t=>1-Math.pow(1-t,3),wt=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,ne=Pt,re=vt,se=wt,gn={linear:ft,"ease-in":ne,"ease-out":re,"ease-in-out":se,"ease-in-quad":Jt,"ease-out-quad":te,"ease-in-out-quad":ee,"ease-in-cubic":Pt,"ease-out-cubic":vt,"ease-in-out-cubic":wt};function ae(t){const[e,n,r,s]=t,a=3*e,i=3*(r-e)-a,o=1-a-i,c=3*n,u=3*(s-n)-c,h=1-c-u,f=m=>((o*m+i)*m+a)*m,g=m=>((h*m+u)*m+c)*m,d=m=>(3*o*m+2*i)*m+a,M=m=>{let p=m;for(let A=0;A<8;A++){const w=f(p)-m;if(Math.abs(w)<1e-7)return p;const _=d(p);if(Math.abs(_)<1e-7)break;p-=w/_}let T=0,b=1;for(p=m;T<b;){const A=f(p);if(Math.abs(A-m)<1e-7)return p;m>A?T=p:b=p,p=(T+b)/2}return p};return m=>{if(m<=0)return 0;if(m>=1)return 1;const p=M(m);return g(p)}}function Rt(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 oe=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 ce(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 ue(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 le(t){switch(t.type){case"steps":return ue(t.count,t.position);case"elastic":return Rt(ie(t.amplitude,t.period),t.mode);case"bounce":return Rt(oe,t.mode);case"back":return Rt(ce(t.overshoot),t.mode)}}function It(t){return t===void 0?ft:q(t)?ae(t.points):it(t)?le(t):gn[t]??ft}const he=32,mn=256,W=new Map,pn=/[MmLlHhVvCcSsQqTtAaZz]/,yn=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,_n={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function Mn(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(pn.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=yn.exec(t.slice(n));if(!c)break;r.args.push(parseFloat(c[0])),n+=c[0].length}return e}function Tn(t,e,n,r,s,a,i,o,c){if(t===o&&e===c)return[];let u=Math.abs(n),h=Math.abs(r);if(u===0||h===0)return[[t,e,o,c,o,c]];const f=s*Math.PI/180,g=Math.cos(f),d=Math.sin(f),M=(t-o)/2,m=(e-c)/2,p=g*M+d*m,T=-d*M+g*m,b=p*p/(u*u)+T*T/(h*h);if(b>1){const I=Math.sqrt(b);u*=I,h*=I}const A=a===i?-1:1,w=u*u*h*h-u*u*T*T-h*h*p*p,_=u*u*T*T+h*h*p*p,R=A*Math.sqrt(Math.max(0,w/_)),v=R*u*T/h,L=-R*h*p/u,y=g*v-d*L+(t+o)/2,k=d*v+g*L+(e+c)/2,S=(I,E,$,Q)=>{const Kt=I*$+E*Q,Mt=Math.sqrt((I*I+E*E)*($*$+Q*Q)),at=Math.acos(Math.max(-1,Math.min(1,Kt/Mt)));return I*Q-E*$<0?-at:at},P=S(1,0,(p-v)/u,(T-L)/h);let C=S((p-v)/u,(T-L)/h,(-p-v)/u,(-T-L)/h);!i&&C>0&&(C-=2*Math.PI),i&&C<0&&(C+=2*Math.PI);const H=Math.max(1,Math.ceil(Math.abs(C)/(Math.PI/2))),qt=C/H,_t=4/3*Math.tan(qt/4),Ze=I=>{const E=u*Math.cos(I),$=h*Math.sin(I);return[g*E-d*$+y,d*E+g*$+k]},Je=I=>{const E=-u*Math.sin(I),$=h*Math.cos(I);return[g*E-d*$,d*E+g*$]},tn=[];for(let I=0;I<H;I++){const E=P+I*qt,$=E+qt,[Q,Kt]=Ze(E),[Mt,at]=I===H-1?[o,c]:Ze($),[_r,Mr]=Je(E),[Tr,br]=Je($);tn.push([Q+_t*_r,Kt+_t*Mr,Mt-_t*Tr,at-_t*br,Mt,at])}return tn}function V(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 fe(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 nt(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 dt(t,e,n){const[r,s,a,i,o,c]=n,u=[0];let h=t,f=e,g=0;for(let d=1;d<=he;d++){const M=d/he,m=V(t,r,a,o,M),p=V(e,s,i,c,M);g+=Math.hypot(m-h,p-f),u.push(g),h=m,f=p}return{subpath:0,type:"C",points:[r,s,a,i,o,c],startX:t,startY:e,endX:o,endY:c,length:g,lengths:u}}function z(t){const e=W.get(t);if(e)return e;const n=[];let r=0,s=0,a=0,i=0,o=null,c=null,u=-1;const h=new Set,f=m=>{u<0&&(u=0),m.subpath=u,n.push(m)};for(const{type:m,args:p}of Mn(t)){const T=m.toUpperCase(),b=m!==T,A=_n[T];if(T==="Z"){(r!==a||s!==i)&&f(nt(r,s,a,i)),u>=0&&h.add(u),r=a,s=i,o=c=null;continue}for(let w=0;w+A<=p.length;w+=A){const _=p.slice(w,w+A),R=b?r:0,v=b?s:0;let L=null,y=null;switch(T){case"M":w===0?(r=_[0]+R,s=_[1]+v,a=r,i=s,(u<0||n[n.length-1]?.subpath===u)&&u++):(f(nt(r,s,_[0]+R,_[1]+v)),r=_[0]+R,s=_[1]+v);break;case"L":f(nt(r,s,_[0]+R,_[1]+v)),r=_[0]+R,s=_[1]+v;break;case"H":f(nt(r,s,_[0]+R,s)),r=_[0]+R;break;case"V":f(nt(r,s,r,_[0]+v)),s=_[0]+v;break;case"C":{const k=[_[0]+R,_[1]+v,_[2]+R,_[3]+v,_[4]+R,_[5]+v];f(dt(r,s,k)),L=[k[2],k[3]],r=k[4],s=k[5];break}case"S":{const[k,S]=o?[2*r-o[0],2*s-o[1]]:[r,s],P=[k,S,_[0]+R,_[1]+v,_[2]+R,_[3]+v];f(dt(r,s,P)),L=[P[2],P[3]],r=P[4],s=P[5];break}case"Q":case"T":{let k=r,S=s;T==="Q"?(k=_[0]+R,S=_[1]+v):c&&(k=2*r-c[0],S=2*s-c[1]);const P=T==="Q"?_[2]+R:_[0]+R,C=T==="Q"?_[3]+v:_[1]+v;f(dt(r,s,[r+2/3*(k-r),s+2/3*(S-s),P+2/3*(k-P),C+2/3*(S-C),P,C])),y=[k,S],r=P,s=C;break}case"A":{const k=_[5]+R,S=_[6]+v;let P=r,C=s;for(const H of Tn(r,s,_[0],_[1],_[2],_[3],_[4],k,S))f(dt(P,C,H)),P=H[4],C=H[5];r=k,s=S;break}}o=L,c=y}}const g=n.reduce((m,p)=>m+p.length,0),d=[];for(let m=0;m<n.length;){const p=n[m].subpath;let T=m,b=0;for(;T<n.length&&n[T].subpath===p;)b+=n[T++].length;const A=n[m],w=n[T-1],_=h.has(p)||Math.abs(w.endX-A.startX)<1e-9&&Math.abs(w.endY-A.startY)<1e-9;d.push({start:m,end:T,length:b,closed:_}),m=T}const M={segments:n,totalLength:g,subpaths:d};return W.size>=mn&&W.delete(W.keys().next().value),W.set(t,M),M}function bn(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 kn(t,e){if(t.type==="L"){const f=t.length>0?Math.max(0,Math.min(1,e/t.length)):0;return{x:t.startX+(t.endX-t.startX)*f,y:t.startY+(t.endY-t.startY)*f,angle:Math.atan2(t.endY-t.startY,t.endX-t.startX)*180/Math.PI}}const[n,r,s,a,i,o]=t.points,c=bn(t,e);let u=fe(t.startX,n,s,i,c),h=fe(t.startY,r,a,o,c);if(Math.hypot(u,h)<1e-9){const f=c<.5?Math.min(1,c+.001):Math.max(0,c-.001),g=V(t.startX,n,s,i,f),d=V(t.startY,r,a,o,f),M=V(t.startX,n,s,i,c),m=V(t.startY,r,a,o,c);u=c<.5?g-M:M-g,h=c<.5?d-m:m-d}return{x:V(t.startX,n,s,i,c),y:V(t.startY,r,a,o,c),angle:Math.atan2(h,u)*180/Math.PI}}function Dt(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 kn(i,e-s);s+=i.length}return{x:0,y:0,angle:0}}function de(t,e){const{segments:n,totalLength:r}=z(t);return Dt(n,Math.max(0,Math.min(1,e))*r)}function Sn(){W.clear()}function An(t){return z(t).totalLength}const Pn=24,vn=320,wn=2.5,rt=72,Rn=64,In=.2,Dn=128,st=new Map;let gt=0,Y;const ge=t=>Math.round(t*100)/100;function me(t,e){const{segments:n,subpaths:r,totalLength:s}=z(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 Ct(t,e){const n=t.closed?(e%1+1)%1:Math.max(0,Math.min(1,e)),r=Dt(t.segments,n*t.length,t.start,t.end);return[r.x,r.y]}function pe(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(Ct(t,t.closed?r/e:r/(e-1)));return n}function _e(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 Cn(t,e,n){const r=t.closed&&e.closed;if(n!==void 0)return{offset:r?Math.abs(n)%rt/rt:0,reversed:n<0};const s=_e(ye(t,rt)),a=_e(ye(e,rt)),i=rt;let o={offset:0,reversed:!1},c=1/0;for(const u of[!1,!0]){const h=r?i:1;for(let f=0;f<h;f++){let g=0;for(let d=0;d<i&&g<c;d++){const M=r?u?(f-d+i)%i:(d+f)%i:u?i-1-d:d,m=s[d][0]-a[M][0],p=s[d][1]-a[M][1];g+=m*m+p*p}g<c&&(c=g,o={offset:r?f/i:0,reversed:u})}}return o}function En(t,e,n){return n?((e.reversed?e.offset-t:t+e.offset)%1+1)%1:e.reversed?1-t:t}function $n(t,e,n){return n?((e.reversed?e.offset-t:t-e.offset)%1+1)%1:e.reversed?1-t:t}function On(t,e,n){const r=t.closed&&e.closed,s=Cn(t,e,n.shapeIndex),a=Math.max(Pn,Math.min(vn,Math.ceil(Math.max(t.length,e.length)/wn))),i=new Set,o=f=>i.add(Math.round(f*1e7)/1e7);for(let f=0;f<=a;f++)o(f/a);for(const f of pe(t))o(f);for(const f of pe(e))o($n(f,s,r));let c=[...i].sort((f,g)=>f-g);r&&(c=c.filter(f=>f<1));const u=[],h=[];for(const f of c)u.push(...Ct(t,f)),h.push(...Ct(e,En(f,s,r)));return Ln({from:u,to:h,closed:r})}function Ln(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,u=In;for(let h=i+1;h<o;h++){const f=Math.max(Me(t.from,i,o,h),Me(t.to,i,o,h));f>u&&(u=f,c=h)}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 Me(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,u=t[r*2+1]-a,h=i*i+o*o,f=h===0?0:Math.max(0,Math.min(1,(c*i+u*o)/h));return Math.hypot(c-f*i,u-f*o)}function Fn(t,e,n){const r=n.shapeIndex;if(Y&&Y.from===t&&Y.to===e&&Y.shapeIndex===r)return Y.plan;const a=st.get(String(r??"auto"))?.get(t)?.get(e);if(a)return Y={from:t,to:e,shapeIndex:r,plan:a},a;const i=z(t).subpaths.filter(d=>d.length>0).length===z(e).subpaths.filter(d=>d.length>0).length,o=me(t,!i),c=me(e,!i),u={pairs:o.map((d,M)=>On(d,c[M],n))};gt>=Dn&&(st.clear(),gt=0);const h=String(r??"auto"),f=st.get(h)??new Map;st.set(h,f);const g=f.get(t)??new Map;return f.set(t,g),g.set(e,u),gt++,Y={from:t,to:e,shapeIndex:r,plan:u},u}function Te(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=Fn(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 u=ge(o.from[c]+(o.to[c]-o.from[c])*s),h=ge(o.from[c+1]+(o.to[c+1]-o.from[c+1])*s);i+=`${c===0?i?" M":"M":" L"}${u} ${h}`}o.closed&&(i+=" Z")}return i}function Nn(){st.clear(),gt=0,Y=void 0}function be(t){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(t)}const F=(t,e,n)=>t+(e-t)*n,ke=512,Et=new Map,$t=new Map;function Se(t){const e=Et.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 Et.size<ke&&Et.set(t,r),r}const Ae=t=>t.charCodeAt(0)===35,Pe=t=>t.startsWith("rgb"),ve=t=>t.startsWith("rgba"),Xn=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,Ot=t=>Math.round(t).toString(16).padStart(2,"0");function xn(t,e,n){return`#${Ot(t)}${Ot(e)}${Ot(n)}`}function we(t){const e=$t.get(t);if(e)return e;const n=t.match(Xn);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 $t.size<ke&&$t.set(t,i),i}const Re=(t,e,n)=>{if(Ae(t)&&Ae(e)){const[r,s,a]=Se(t),[i,o,c]=Se(e),u=F(r,i,n),h=F(s,o,n),f=F(a,c,n);return xn(u,h,f)}if((Pe(t)||ve(t))&&(Pe(e)||ve(e))){const r=we(t),s=we(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,u=s[3]??1,h=F(c,u,n);return`rgba(${a}, ${i}, ${o}, ${h})`}return`rgb(${a}, ${i}, ${o})`}return n<1?t:e},Ie=(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},Lt=(t,e,n)=>n<1?t:e,De=(t,e,n)=>Te(t,e,n);function Ft(t){return typeof t=="number"?F:Array.isArray(t)?Ie:typeof t=="string"?t.startsWith("#")||t.startsWith("rgb")?Re:be(t)?De:Lt:Lt}const Nt=1e3/60;function Xt(t,e={}){if(!U(t))throw new Error(`bakeSpringTrack: track "${t.id}" is not a spring track`);const n=new J(t.spring);return Ce(t,r=>n.valueAt(r),n.settleTime(),t.spring.from,t.spring.to,e)}function xt(t,e={}){if(!x(t))throw new Error(`bakeInertiaTrack: track "${t.id}" is not an inertia track`);const n=t.inertia;return Ce(t,r=>ht(n,r),et(n),n.from,tt(n),e)}function Ce(t,e,n,r,s,a){const i=a.intervalMs??Nt,o=a.tolerance??.01,c=t.delay??0,u=[];for(let f=0;f<=n;f+=i)u.push({time:f+c,value:e(f),easing:"linear"});const h=u[u.length-1];return!h||h.time<n+c?u.push({time:n+c,value:s,easing:"linear"}):h.value=s,c>0&&u.unshift({time:0,value:r,easing:"linear"}),{id:t.id,target:t.target,property:t.property,keyframes:o>0?Oe(u,o):u,...t.targets&&{targets:[...t.targets]},...t.stagger&&{stagger:{...t.stagger}}}}function Ee(t,e,n,r={}){const s=r.intervalMs??Nt,a=typeof n=="function"?n:It(n),i=Ft(t.value),o=e.time-t.time;if(o<=0)return[e];const c=[];for(let h=s;h<o;h+=s){const f=h/o;c.push({time:t.time+h,value:i(t.value,e.value,a(f)),easing:"linear"})}const u=a(1);return c.push({...e,...u!==1&&{value:i(t.value,e.value,u)},easing:"linear"}),c}function Un(t,e){return U(t)?Xt(t,e):x(t)?xt(t,e):t}function $e(t,e={}){const n=t.keyframes;if(!n.some(s=>it(s.easing)))return t;const r=n.length>0?[n[0]]:[];for(let s=1;s<n.length;s++){const a=n[s];it(a.easing)?r.push(...Ee(n[s-1],a,a.easing,e)):r.push(a)}return{...t,keyframes:r}}function Vn(t,e){return t.filter(Wt).map(n=>$e(n,e)).concat(t.filter(U).map(n=>Xt(n,e)),t.filter(x).map(n=>xt(n,e)))}function Oe(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,u=s.value+(i.value-s.value)*c;Math.abs(a.value-u)>e&&n.push(a)}return n.push(t[t.length-1]),n}function Le(t){const e=[...t.keyframes].sort((n,r)=>n.time-r.time);return{...t,keyframes:e}}function B(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+kt(t,e,r)}class mt{track;targets;constructor(e){this.track=e,this.targets=B(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?ct(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=It(s.easing)(i);return Ft(r.value)(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 Fe{track;targets;sampler;constructor(e){this.track=e,this.targets=B(e),this.sampler=new J(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?ct(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+e}getTrack(){return this.track}}class Ne{track;targets;duration;constructor(e){this.track=e,this.targets=B(e),this.duration=et(e.inertia)}getValueAtTime(e){return ht(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:ht(this.track.inertia,e-a),start:a})}return r}getDuration(){const e=this.track.stagger?ct(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+e}getTrack(){return this.track}}function Ut(t,e){const n={...de(t.pathData,e)};if(t.matrix){const[r,s,a,i,o,c]=t.matrix,{x:u,y:h}=n;n.x=r*u+a*h+o,n.y=s*u+i*h+c;const f=n.angle*Math.PI/180,g=Math.cos(f),d=Math.sin(f);n.angle=Math.atan2(s*g+i*d,r*g+a*d)*180/Math.PI}return t.autoRotate&&t.rotateOffset&&(n.angle+=t.rotateOffset),n}function Yn(t,e,n,r){const s=e+(n-e)*r;return Ut(t,s)}const Vt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},Bn=20;function Xe(t){const e=Vt[t??"upperCase"]??t??Vt.upperCase,n=Array.from(e);return n.length>0?n:Array.from(Vt.upperCase)}function zn(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 xe(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 b=Math.round(a*Math.max(i.length,o.length));return c?i.slice(0,Math.max(0,i.length-b)).join("")+o.slice(Math.max(0,o.length-b)).join(""):o.slice(0,b).join("")+i.slice(b).join("")}const u=Math.max(0,Math.min(.999,t.revealDelay??0)),h=Math.max(0,(a-u)/(1-u)),f=Math.floor(h*o.length),g=t.tweenLength===!1?o.length:Math.round(i.length+(o.length-i.length)*a),d=Xe(t.chars),M=t.refreshRate??Bn,m=M>0?Math.floor(n*M/1e3):0,p=t.seed??1;let T="";for(let b=0;b<g;b++){const A=c?b>=g-f:b<f,w=c?o[o.length-(g-b)]:o[b];A&&w!==void 0||w===" "||w===`
2
- `?T+=w:T+=d[zn(p,b,m)%d.length]}return T}class Ue{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}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(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:u}of a.getTargetValues(e)){const h=`${o}\0${i}`,f=u<=e,g=r.get(h);(!g||(f!==g.started?f:f?u>=g.start:u<=g.start))&&r.set(h,{trackId:s,target:o,property:i,value:c,start:u,started:f})}}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",xe(c.textConfig,a,Math.max(0,i)));return}const u=this._motionPathTracks.get(n);if(u&&typeof a=="number"){const h=Ut(u.motionPathConfig,a);o.set("motionPathX",h.x),o.set("motionPathY",h.y),u.motionPathConfig.autoRotate&&o.set("motionPathRotate",h.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 B(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,x(e)){this._trackPlayers.set(e.id,new Ne(e));return}if(U(e)){this._trackPlayers.set(e.id,new Fe(e)),this._springTracks.set(e.id,e);return}if(ot(e))this._trackPlayers.set(e.id,new mt(e)),this._textTracks.set(e.id,e);else if(Tt(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 mt(n)),this._motionPathTracks.set(e.id,e)}else this._trackPlayers.set(e.id,new mt(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(U(r)||x(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=B(i).filter(f=>B(r).includes(f));if(o.length===0)continue;const c=this.getTrackSpan(i.id);if(!c||!(c.from<=s.to&&s.from<=c.to))continue;const h=s.from>=c.from;for(const f of o)e.push({target:f,property:r.property,losingTrackId:h?i.id:r.id,winningTrackId:h?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&&!B(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:Z,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 Hn=100;function qn(t,e,n,r){const s=[],a=[],{duration:i,alternate:o}=r,c=(d,M,m,p)=>{a.push([d,M]);const T=[];t.forEach((b,A)=>{(m==="forward"?(p?b>=d:b>d)&&b<=M:(p?b<=d:b<d)&&b>=M)&&T.push(A)}),T.sort((b,A)=>(m==="forward"?t[b]-t[A]:t[A]-t[b])||b-A);for(const b of T)s.push({kind:"event",index:b,direction:m})};let u=e.time,h=e.direction,f=e.fresh===!0;const g=Math.min(Hn,Math.max(0,n.iteration-e.iteration));for(let d=0;d<g;d++){const M=h==="forward"?i:0;c(u,M,h,f),s.push({kind:"repeat"}),o?(h=h==="forward"?"reverse":"forward",u=M,f=!1):(u=h==="forward"?0:i,f=!0)}return g>0&&r.holding&&!o?{crossings:s,passes:a}:(c(u,n.time,h,f),{crossings:s,passes:a})}function Ve(t){return x(t)?{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:Ye(t.inertia),...N(t)}:U(t)?{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...N(t)}:ot(t)?{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:t.keyframes.map(Yt),...N(t)}:Tt(t)?{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:t.keyframes.map(Yt),...N(t)}:{id:t.id,target:t.target,property:t.property,keyframes:t.keyframes.map(Yt),...N(t)}}function Ye(t){return{...t,...Array.isArray(t.end)&&{end:[...t.end]}}}function Yt(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 Be(t){if(x(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"inertia",inertia:Ye(e.inertia),...N(e)}}if(U(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"spring",spring:{...e.spring},...N(e)}}if(ot(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 Le({id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,...N(t)})}function ze(t){const e=t._config.markers;return{formatVersion:Z,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,...e&&{markers:e.map(n=>({...n}))}},tracks:t.tracks.map(Ve),...t.captions&&{captions:JSON.parse(JSON.stringify(t.captions))}}}function He(t){const e=t.formatVersion??1;if(e>Z)throw new Error(`tinyfly: this animation uses format version ${e}, but this tinyfly reads up to version ${Z}. Update tinyfly to play it.`);return new Ue({id:t.id,name:t.name,config:t.config,tracks:t.tracks.map(Be),captions:t.captions})}function Kn(t){return JSON.stringify(ze(t))}function Wn(t){const e=JSON.parse(t);return He(e)}function jn(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 qe(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 Bt(t,e,n){return e+t.next()*(n-e)}function Ke(t,e,n,r){if(r<=0)return Bt(t,e,n);const s=Math.floor((n-e)/r),a=Math.round(t.next()*s);return e+a*r}function Gn(t,e){if(e.length!==0)return e[Math.floor(t.next()*e.length)]}const We=/^([+\-*/])=\s*(-?[\d.]+)$/,je=/^random\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*(?:,\s*(-?[\d.]+)\s*)?\)$/i;function Qn(t){return typeof t!="string"?!1:We.test(t.trim())||je.test(t.trim())}function zt(t,e={}){if(typeof t!="string")return t;const n=t.trim(),r=We.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=je.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?Ke(e.random,a,i,o):Bt(e.random,a,i)}return t}function Ge(t,e=0,n){const r=[];let s=e;for(const a of t){const i=zt(a,{base:s,random:n});r.push(i),typeof i=="number"&&(s=i)}return r}class Zn{random;constructor(e){this.random=qe(e)}get seed(){return this.random.seed}resolve(e,n=0){return zt(e,{base:n,random:this.random})}resolveSequence(e,n=0){return Ge(e,n,this.random)}}const Jn=600;function tr(t){if(Array.isArray(t)){const[g,d,M,m]=t;return{fn:Qe(g,d,M,m),bezier:[g,d,M,m]}}const{segments:e}=z(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=g=>(g-n)/a,c=g=>(g-r)/i;if(e.length===1&&s.type==="C"){const[g,d,M,m]=s.points,p=[o(g),c(d),o(M),c(m)];return{fn:Qe(...p),bezier:p}}const u=[],h=[],f=Math.max(8,Math.ceil(Jn/e.length));for(const g of e)for(let d=u.length===0?0:1;d<=f;d++){const[M,m]=rr(g,d/f);u.push(o(M)),h.push(c(m))}return{fn:sr(u,h)}}function er(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,u=c*c,h=i-c;return 1-(u-h*h)}i-=r[o]}return 1}}function nr(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 rr(t,e){if(t.type==="L"){const[u,h]=t.points;return[t.startX+(u-t.startX)*e,t.startY+(h-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 sr(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 Qe(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 h=0;h<8;h++){const f=s(o,t,n)-i,g=a(o,t,n);if(Math.abs(f)<1e-6)return s(o,e,r);if(Math.abs(g)<1e-6)break;o-=f/g}let c=0,u=1;o=i;for(let h=0;h<40;h++)s(o,t,n)<i?c=o:u=o,o=(c+u)/2;return s(o,e,r)}}const ar=350,ir=300,or=550;function cr(t,e={}){const n=e.lead??ar,r=e.gap??ir,s=e.tail??or,a=[];let i=0;return t.forEach((o,c)=>{const u=[];let h=i+n;o.lines.forEach((g,d)=>{if(!(g.duration>=0))throw new Error(`narration: scene ${c} line ${d} has an invalid duration (${g.duration})`);d>0&&(h+=r),u.push({id:g.id??`s${c}-l${d}`,scene:c,line:d,start:h,end:h+g.duration,text:g.text}),h+=g.duration});const f=h+s+(o.tail??0);a.push({id:o.id??`s${c}`,start:i,duration:f-i,cues:u}),i=f}),{duration:i,scenes:a,cues:a.flatMap(o=>o.cues)}}function ur(t){return t.cues.map(e=>({id:e.id,time:e.start,label:e.text}))}function lr(t,e){let n=t.scenes[0];for(const r of t.scenes)if(e>=r.start)n=r;else break;return n}const Ht=t=>6e4/t.bpm;function pt(t,e){return t.offset+e*Ht(t)}function yt(t,e){return(e-t.offset)/Ht(t)}function hr(t,e){return pt(t,Math.round(yt(t,e)))}function fr(t,e){return pt(t,Math.ceil(yt(t,e)-1e-9))}function dr(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(yt(t,e)-1e-9);;a++){const i=pt(t,a);if(i>n+1e-9)break;s.push({time:i,bar:(a%r+r)%r===0,n:a})}return s}const G=100;function gr(t,e,n={}){const r=n.minBpm??70,s=n.maxBpm??180,a=Math.max(1,Math.round(e/G)),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 y=0;y<o;y++){let k=0;for(let S=y*a;S<(y+1)*a;S++)k+=t[S]*t[S];c[y]=Math.log(1e-6+k/a)}const u=new Float64Array(o);for(let y=1;y<o;y++)u[y]=Math.max(0,c[y]-c[y-1]);const h=u.reduce((y,k)=>y+k,0)/o;for(let y=0;y<o;y++)u[y]=Math.max(0,u[y]-h);const f=Math.max(1,Math.floor(60*G/s)),g=Math.min(o-1,Math.ceil(60*G/r)),d=y=>{let k=0;for(let S=y;S<o;S++)k+=u[S]*u[S-y];return k/(o-y)};let M=0;for(let y=0;y<o;y++)M+=u[y]*u[y];M/=o;let m=f,p=-1/0;for(let y=f;y<=g;y++){const k=60*G/y,S=Math.exp(-.5*(Math.log2(k/120)/.9)**2),P=d(y)*S;P>p&&(p=P,m=y)}const T=y=>{const k=Math.floor(y);return k<0||k+1>=o?0:u[k]+(u[k+1]-u[k])*(y-k)},b=(y,k)=>{let S=0;for(let P=k;P<o;P+=y)S+=T(P);return S};let A=m,w=0,_=-1/0;for(let y=m-.6;y<=m+.6+1e-9;y+=.02){if(y<1)continue;const k=Math.max(1,Math.round(y*4));for(let S=0;S<k;S++){const P=S/k*y,C=b(y,P);C>_&&(_=C,w=P,A=y)}}const R=60*G/A,v=M>0?Math.max(0,Math.min(1,d(m)/M)):0,L=(w+.5)*1e3/G;return{bpm:Math.round(R*100)/100,offset:Math.round(L%(6e4/R)),confidence:v}}const X=t=>Math.round(t*1e3)/1e3;function mr(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 u=i(c-1),h=i(c),f=i(c+1),g=i(c+2);if(n===0){a+=` L${X(f.x)} ${X(f.y)}`;continue}const d=n/6,M=h.x+(f.x-u.x)*d,m=h.y+(f.y-u.y)*d,p=f.x-(g.x-h.x)*d,T=f.y-(g.y-h.y)*d;a+=` C${X(M)} ${X(m)} ${X(p)} ${X(T)} ${X(f.x)} ${X(f.y)}`}return r?`${a} Z`:a}const D=(t,e=0)=>{const n=parseFloat(t??"");return Number.isFinite(n)?n:e};function pr(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 yr(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=pr(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}}l.Clock=rn,l.DEFAULT_BAKE_INTERVAL_MS=Nt,l.DEFAULT_INERTIA_FRICTION=At,l.DEFAULT_SPRING=O,l.FORMAT_VERSION=Z,l.INERTIA_MAX_DURATION_MS=Qt,l.InertiaTrackPlayer=Ne,l.MORPH_SAMPLES=Rn,l.ManualClock=nn,l.SPRING_MAX_DURATION_MS=St,l.SPRING_PRESETS=sn,l.SPRING_STEP_MS=K,l.SpringSampler=J,l.SpringTrackPlayer=Fe,l.Timeline=Ue,l.TrackPlayer=mt,l.ValueResolver=Zn,l.backOut=ce,l.bakeEasing=Ee,l.bakeInertiaTrack=xt,l.bakeSpringTrack=Xt,l.beatAtTime=yt,l.beatLength=Ht,l.beatTime=pt,l.beatsBetween=dr,l.bounceOut=oe,l.charactersFor=Xe,l.clearMorphCache=Nn,l.clearPathCache=Sn,l.createCubicBezier=ae,l.createRandom=qe,l.createTrack=Le,l.criticalDamping=un,l.customBounce=er,l.customEase=tr,l.customWiggle=nr,l.deserializeTimeline=He,l.deserializeTrack=Be,l.detectTempo=gr,l.easeIn=ne,l.easeInCubic=Pt,l.easeInOut=se,l.easeInOutCubic=wt,l.easeInOutQuad=ee,l.easeInQuad=Jt,l.easeOut=re,l.easeOutCubic=vt,l.easeOutQuad=te,l.elasticOut=ie,l.expandParametricEasings=$e,l.fromJSON=Wn,l.getEasingFunction=It,l.getInterpolator=Ft,l.getMotionPathPoint=Ut,l.getPathLength=An,l.getPointAtProgress=de,l.hasKeyframes=Wt,l.hashSeed=jn,l.inertiaDuration=et,l.inertiaRest=tt,l.inertiaValueAt=ht,l.inertiaVelocityAt=dn,l.interpolateArray=Ie,l.interpolateColor=Re,l.interpolateMotionPath=Yn,l.interpolateNumber=F,l.interpolatePathString=De,l.interpolateString=Lt,l.isCubicBezierEasing=q,l.isInertiaTrack=x,l.isMotionPathPoint=en,l.isMotionPathTrack=Tt,l.isParametricEasing=it,l.isPathData=be,l.isSpringTrack=U,l.isTextTrack=ot,l.isUnderdamped=cn,l.isUnresolved=Qn,l.linear=ft,l.maxStaggerDistance=jt,l.morphPath=Te,l.narrationMarkers=ur,l.narrationSceneAt=lr,l.naturalRest=Zt,l.nearestBeat=hr,l.nextBeat=fr,l.parametricEasing=le,l.parsePath=z,l.planNarration=cr,l.playheadCrossings=qn,l.pointAtDistance=Dt,l.pointsToPath=mr,l.randomBetween=Bt,l.randomChoice=Gn,l.randomSnapped=Ke,l.resolveSequence=Ge,l.resolveValue=zt,l.serializeTimeline=ze,l.serializeTrack=Ve,l.shapeToPathData=yr,l.simplifyKeyframes=Oe,l.springDuration=on,l.springValueAt=an,l.staggerDistance=bt,l.staggerOffset=kt,l.staggerOffsets=Gt,l.staggerSpan=ct,l.stepsEasing=ue,l.textAt=xe,l.toJSON=Kn,l.toKeyframedTrack=Un,l.toKeyframedTracks=Vn,l.trackTargets=B,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(l,Q){typeof exports=="object"&&typeof module<"u"?Q(exports):typeof define=="function"&&define.amd?define(["exports"],Q):(l=typeof globalThis<"u"?globalThis:l||self,Q(l.tinyfly={}))})(this,(function(l){"use strict";function Q(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function ot(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const kt=2;function At(t){return t.some(e=>e.interpolation!==void 0)?2:1}function ct(t){return t.property==="text"&&"textConfig"in t}function z(t){return t.kind==="inertia"&&"inertia"in t}function V(t){return t.kind==="spring"&&"spring"in t}function Pt(t){return t.property==="motionPath"&&"motionPathConfig"in t}function _n(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"angle"in t}function ie(t){return"keyframes"in t}class Tn{_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 bn{_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 vt(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 ae(t,e="start"){if(t<=1)return 0;let n=0;for(let r=0;r<t;r++)n=Math.max(n,vt(r,t,e));return n}function wt(t,e,n){if(n.offsets)return n.offsets[t]??0;const r=n.from??"start",s=vt(t,e,r);if(n.amount!==void 0){const i=ae(e,r);return i===0?0:n.amount*s/i}return n.each!==void 0?n.each*s:0}function oe(t,e){return Array.from({length:t},(n,r)=>wt(r,t,e))}function ut(t,e){return t<=1?0:Math.max(...oe(t,e))}const G=1,It=6e4,lt=It/G,F={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1},Sn={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 tt{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??F.stiffness,this.damping=e.damping??F.damping,this.mass=e.mass??F.mass,this.restDelta=e.restDelta??F.restDelta,this.restSpeed=e.restSpeed??F.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=e.velocity??F.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)],i=e/G-n;return r+(s-r)*i}settleTime(){return this.simulateTo(lt+1),this.settledStep!==null?this.settledStep*G:It}simulateTo(e){if(this.settledStep!==null)return;const n=Math.min(e,lt+1),r=G/1e3;for(;this.samples.length<n;){const s=this.samples[this.samples.length-1],i=s-this.to,a=-this.stiffness*i,o=-this.damping*this.velocity,c=(a+o)/this.mass;this.velocity+=c*r;const u=s+this.velocity*r;if(this.samples.push(u),this.isAtRest(u)){this.settledStep=this.samples.length-1;return}}this.samples.length>lt&&(this.settledStep=lt)}}function kn(t,e){return new tt(t).valueAt(e)}function An(t){return new tt(t).settleTime()}function Pn(t){const e=t.stiffness??F.stiffness,n=t.damping??F.damping,r=t.mass??F.mass;return n<2*Math.sqrt(e*r)}function vn(t){const e=t.stiffness??F.stiffness,n=t.mass??F.mass;return 2*Math.sqrt(e*n)}const Rt=4,wn=.002,In=1e-4,ce=6e4;function ht(t){const e=t.friction??Rt;return e>0?e:Rt}function ue(t){return t.from+t.velocity/ht(t)}function Rn(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 et(t){let e=Rn(ue(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 nt(t){const e=Math.abs(et(t)-t.from);if(e===0)return 0;const n=t.restDelta??Math.max(In,e*wn);if(n>=e)return 0;const r=Math.log(e/n)/ht(t);return Math.min(ce,r*1e3)}function ft(t,e){if(e<=0)return t.from;const n=et(t);if(e>=nt(t))return n;const r=ht(t);return t.from+(n-t.from)*(1-Math.exp(-r*e/1e3))}function Dn(t,e){const n=ht(t),r=et(t);return e>=nt(t)?0:(r-t.from)*n*Math.exp(-n*Math.max(0,e)/1e3)}const dt=t=>t,le=t=>t*t,he=t=>1-(1-t)*(1-t),fe=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,Dt=t=>t*t*t,Et=t=>1-Math.pow(1-t,3),Ct=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,de=Dt,ge=Et,me=Ct,En={linear:dt,"ease-in":de,"ease-out":ge,"ease-in-out":me,"ease-in-quad":le,"ease-out-quad":he,"ease-in-out-quad":fe,"ease-in-cubic":Dt,"ease-out-cubic":Et,"ease-in-out-cubic":Ct};function pe(t){const[e,n,r,s]=t,i=3*e,a=3*(r-e)-i,o=1-i-a,c=3*n,u=3*(s-n)-c,h=1-c-u,f=m=>((o*m+a)*m+i)*m,d=m=>((h*m+u)*m+c)*m,g=m=>(3*o*m+2*a)*m+i,_=m=>{let p=m;for(let A=0;A<8;A++){const w=f(p)-m;if(Math.abs(w)<1e-7)return p;const M=g(p);if(Math.abs(M)<1e-7)break;p-=w/M}let T=0,b=1;for(p=m;T<b;){const A=f(p);if(Math.abs(A-m)<1e-7)return p;m>A?T=p:b=p,p=(T+b)/2}return p};return m=>{if(m<=0)return 0;if(m>=1)return 1;const p=_(m);return d(p)}}function $t(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 ye(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 Me=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 _e(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 Te(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 be(t){switch(t.type){case"steps":return Te(t.count,t.position);case"elastic":return $t(ye(t.amplitude,t.period),t.mode);case"bounce":return $t(Me,t.mode);case"back":return $t(_e(t.overshoot),t.mode)}}function Ot(t){return t===void 0?dt:Q(t)?pe(t.points):ot(t)?be(t):En[t]??dt}const Se=32,Cn=256,K=new Map,$n=/[MmLlHhVvCcSsQqTtAaZz]/,On=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,Ln={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function Fn(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 i=t[n];if($n.test(i)){r={type:i,args:[]},e.push(r),n++;continue}if(!r)break;const a=r.type==="A"||r.type==="a",o=r.args.length%7;if(a&&(o===3||o===4)){if(i!=="0"&&i!=="1")break;r.args.push(i==="1"?1:0),n++;continue}const c=On.exec(t.slice(n));if(!c)break;r.args.push(parseFloat(c[0])),n+=c[0].length}return e}function Nn(t,e,n,r,s,i,a,o,c){if(t===o&&e===c)return[];let u=Math.abs(n),h=Math.abs(r);if(u===0||h===0)return[[t,e,o,c,o,c]];const f=s*Math.PI/180,d=Math.cos(f),g=Math.sin(f),_=(t-o)/2,m=(e-c)/2,p=d*_+g*m,T=-g*_+d*m,b=p*p/(u*u)+T*T/(h*h);if(b>1){const E=Math.sqrt(b);u*=E,h*=E}const A=i===a?-1:1,w=u*u*h*h-u*u*T*T-h*h*p*p,M=u*u*T*T+h*h*p*p,I=A*Math.sqrt(Math.max(0,w/M)),v=I*u*T/h,$=-I*h*p/u,y=d*v-g*$+(t+o)/2,S=g*v+d*$+(e+c)/2,k=(E,O,L,J)=>{const se=E*L+O*J,St=Math.sqrt((E*E+O*O)*(L*L+J*J)),at=Math.acos(Math.max(-1,Math.min(1,se/St)));return E*J-O*L<0?-at:at},P=k(1,0,(p-v)/u,(T-$)/h);let D=k((p-v)/u,(T-$)/h,(-p-v)/u,(-T-$)/h);!a&&D>0&&(D-=2*Math.PI),a&&D<0&&(D+=2*Math.PI);const R=Math.max(1,Math.ceil(Math.abs(D)/(Math.PI/2))),re=D/R,bt=4/3*Math.tan(re/4),pn=E=>{const O=u*Math.cos(E),L=h*Math.sin(E);return[d*O-g*L+y,g*O+d*L+S]},yn=E=>{const O=-u*Math.sin(E),L=h*Math.cos(E);return[d*O-g*L,g*O+d*L]},Mn=[];for(let E=0;E<R;E++){const O=P+E*re,L=O+re,[J,se]=pn(O),[St,at]=E===R-1?[o,c]:pn(L),[ss,is]=yn(O),[as,os]=yn(L);Mn.push([J+bt*ss,se+bt*is,St-bt*as,at-bt*os,St,at])}return Mn}function U(t,e,n,r,s){const i=1-s;return i*i*i*t+3*i*i*s*e+3*i*s*s*n+s*s*s*r}function ke(t,e,n,r,s){const i=1-s;return 3*i*i*(e-t)+6*i*s*(n-e)+3*s*s*(r-n)}function rt(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 gt(t,e,n){const[r,s,i,a,o,c]=n,u=[0];let h=t,f=e,d=0;for(let g=1;g<=Se;g++){const _=g/Se,m=U(t,r,i,o,_),p=U(e,s,a,c,_);d+=Math.hypot(m-h,p-f),u.push(d),h=m,f=p}return{subpath:0,type:"C",points:[r,s,i,a,o,c],startX:t,startY:e,endX:o,endY:c,length:d,lengths:u}}function j(t){const e=K.get(t);if(e)return e;const n=[];let r=0,s=0,i=0,a=0,o=null,c=null,u=-1;const h=new Set,f=m=>{u<0&&(u=0),m.subpath=u,n.push(m)};for(const{type:m,args:p}of Fn(t)){const T=m.toUpperCase(),b=m!==T,A=Ln[T];if(T==="Z"){(r!==i||s!==a)&&f(rt(r,s,i,a)),u>=0&&h.add(u),r=i,s=a,o=c=null;continue}for(let w=0;w+A<=p.length;w+=A){const M=p.slice(w,w+A),I=b?r:0,v=b?s:0;let $=null,y=null;switch(T){case"M":w===0?(r=M[0]+I,s=M[1]+v,i=r,a=s,(u<0||n[n.length-1]?.subpath===u)&&u++):(f(rt(r,s,M[0]+I,M[1]+v)),r=M[0]+I,s=M[1]+v);break;case"L":f(rt(r,s,M[0]+I,M[1]+v)),r=M[0]+I,s=M[1]+v;break;case"H":f(rt(r,s,M[0]+I,s)),r=M[0]+I;break;case"V":f(rt(r,s,r,M[0]+v)),s=M[0]+v;break;case"C":{const S=[M[0]+I,M[1]+v,M[2]+I,M[3]+v,M[4]+I,M[5]+v];f(gt(r,s,S)),$=[S[2],S[3]],r=S[4],s=S[5];break}case"S":{const[S,k]=o?[2*r-o[0],2*s-o[1]]:[r,s],P=[S,k,M[0]+I,M[1]+v,M[2]+I,M[3]+v];f(gt(r,s,P)),$=[P[2],P[3]],r=P[4],s=P[5];break}case"Q":case"T":{let S=r,k=s;T==="Q"?(S=M[0]+I,k=M[1]+v):c&&(S=2*r-c[0],k=2*s-c[1]);const P=T==="Q"?M[2]+I:M[0]+I,D=T==="Q"?M[3]+v:M[1]+v;f(gt(r,s,[r+2/3*(S-r),s+2/3*(k-s),P+2/3*(S-P),D+2/3*(k-D),P,D])),y=[S,k],r=P,s=D;break}case"A":{const S=M[5]+I,k=M[6]+v;let P=r,D=s;for(const R of Nn(r,s,M[0],M[1],M[2],M[3],M[4],S,k))f(gt(P,D,R)),P=R[4],D=R[5];r=S,s=k;break}}o=$,c=y}}const d=n.reduce((m,p)=>m+p.length,0),g=[];for(let m=0;m<n.length;){const p=n[m].subpath;let T=m,b=0;for(;T<n.length&&n[T].subpath===p;)b+=n[T++].length;const A=n[m],w=n[T-1],M=h.has(p)||Math.abs(w.endX-A.startX)<1e-9&&Math.abs(w.endY-A.startY)<1e-9;g.push({start:m,end:T,length:b,closed:M}),m=T}const _={segments:n,totalLength:d,subpaths:g};return K.size>=Cn&&K.delete(K.keys().next().value),K.set(t,_),_}function Xn(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 i=n[s]-n[r],a=i>0?(e-n[r])/i:0;return(r+a)/(n.length-1)}function xn(t,e){if(t.type==="L"){const f=t.length>0?Math.max(0,Math.min(1,e/t.length)):0;return{x:t.startX+(t.endX-t.startX)*f,y:t.startY+(t.endY-t.startY)*f,angle:Math.atan2(t.endY-t.startY,t.endX-t.startX)*180/Math.PI}}const[n,r,s,i,a,o]=t.points,c=Xn(t,e);let u=ke(t.startX,n,s,a,c),h=ke(t.startY,r,i,o,c);if(Math.hypot(u,h)<1e-9){const f=c<.5?Math.min(1,c+.001):Math.max(0,c-.001),d=U(t.startX,n,s,a,f),g=U(t.startY,r,i,o,f),_=U(t.startX,n,s,a,c),m=U(t.startY,r,i,o,c);u=c<.5?d-_:_-d,h=c<.5?g-m:m-g}return{x:U(t.startX,n,s,a,c),y:U(t.startY,r,i,o,c),angle:Math.atan2(h,u)*180/Math.PI}}function Lt(t,e,n=0,r=t.length){if(r<=n)return{x:0,y:0,angle:0};let s=0;for(let i=n;i<r;i++){const a=t[i];if(s+a.length>=e||i===r-1)return xn(a,e-s);s+=a.length}return{x:0,y:0,angle:0}}function Ae(t,e){const{segments:n,totalLength:r}=j(t);return Lt(n,Math.max(0,Math.min(1,e))*r)}function zn(){K.clear()}function Vn(t){return j(t).totalLength}const Un=24,Yn=320,Bn=2.5,st=72,jn=64,Hn=.2,Qn=128,it=new Map;let mt=0,Y;const Pe=t=>Math.round(t*100)/100;function ve(t,e){const{segments:n,subpaths:r,totalLength:s}=j(t);if(n.length===0)return[];if(e){const i=r.every(a=>a.closed);return[{segments:n,start:0,end:n.length,length:s,closed:i}]}return r.filter(i=>i.length>0).map(i=>({segments:n,start:i.start,end:i.end,length:i.length,closed:i.closed}))}function Ft(t,e){const n=t.closed?(e%1+1)%1:Math.max(0,Math.min(1,e)),r=Lt(t.segments,n*t.length,t.start,t.end);return[r.x,r.y]}function we(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 Ie(t,e){const n=[];for(let r=0;r<e;r++)n.push(Ft(t,t.closed?r/e:r/(e-1)));return n}function Re(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 Gn(t,e,n){const r=t.closed&&e.closed;if(n!==void 0)return{offset:r?Math.abs(n)%st/st:0,reversed:n<0};const s=Re(Ie(t,st)),i=Re(Ie(e,st)),a=st;let o={offset:0,reversed:!1},c=1/0;for(const u of[!1,!0]){const h=r?a:1;for(let f=0;f<h;f++){let d=0;for(let g=0;g<a&&d<c;g++){const _=r?u?(f-g+a)%a:(g+f)%a:u?a-1-g:g,m=s[g][0]-i[_][0],p=s[g][1]-i[_][1];d+=m*m+p*p}d<c&&(c=d,o={offset:r?f/a:0,reversed:u})}}return o}function Kn(t,e,n){return n?((e.reversed?e.offset-t:t+e.offset)%1+1)%1:e.reversed?1-t:t}function Wn(t,e,n){return n?((e.reversed?e.offset-t:t-e.offset)%1+1)%1:e.reversed?1-t:t}function qn(t,e,n){const r=t.closed&&e.closed,s=Gn(t,e,n.shapeIndex),i=Math.max(Un,Math.min(Yn,Math.ceil(Math.max(t.length,e.length)/Bn))),a=new Set,o=f=>a.add(Math.round(f*1e7)/1e7);for(let f=0;f<=i;f++)o(f/i);for(const f of we(t))o(f);for(const f of we(e))o(Wn(f,s,r));let c=[...a].sort((f,d)=>f-d);r&&(c=c.filter(f=>f<1));const u=[],h=[];for(const f of c)u.push(...Ft(t,f)),h.push(...Ft(e,Kn(f,s,r)));return Zn({from:u,to:h,closed:r})}function Zn(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[a,o]=r.pop();let c=-1,u=Hn;for(let h=a+1;h<o;h++){const f=Math.max(De(t.from,a,o,h),De(t.to,a,o,h));f>u&&(u=f,c=h)}c!==-1&&(n[c]=1,r.push([a,c],[c,o]))}const s=[],i=[];for(let a=0;a<e;a++)n[a]&&(s.push(t.from[a*2],t.from[a*2+1]),i.push(t.to[a*2],t.to[a*2+1]));return{from:s,to:i,closed:t.closed}}function De(t,e,n,r){const s=t[e*2],i=t[e*2+1],a=t[n*2]-s,o=t[n*2+1]-i,c=t[r*2]-s,u=t[r*2+1]-i,h=a*a+o*o,f=h===0?0:Math.max(0,Math.min(1,(c*a+u*o)/h));return Math.hypot(c-f*a,u-f*o)}function Jn(t,e,n){const r=n.shapeIndex;if(Y&&Y.from===t&&Y.to===e&&Y.shapeIndex===r)return Y.plan;const i=it.get(String(r??"auto"))?.get(t)?.get(e);if(i)return Y={from:t,to:e,shapeIndex:r,plan:i},i;const a=j(t).subpaths.filter(g=>g.length>0).length===j(e).subpaths.filter(g=>g.length>0).length,o=ve(t,!a),c=ve(e,!a),u={pairs:o.map((g,_)=>qn(g,c[_],n))};mt>=Qn&&(it.clear(),mt=0);const h=String(r??"auto"),f=it.get(h)??new Map;it.set(h,f);const d=f.get(t)??new Map;return f.set(t,d),d.set(e,u),mt++,Y={from:t,to:e,shapeIndex:r,plan:u},u}function Ee(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 i=Jn(t,e,r);if(i.pairs.length===0)return s<.5?t:e;let a="";for(const o of i.pairs){for(let c=0;c<o.from.length;c+=2){const u=Pe(o.from[c]+(o.to[c]-o.from[c])*s),h=Pe(o.from[c+1]+(o.to[c+1]-o.from[c+1])*s);a+=`${c===0?a?" M":"M":" L"}${u} ${h}`}o.closed&&(a+=" Z")}return a}function tr(){it.clear(),mt=0,Y=void 0}function Ce(t){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(t)}const W=Math.PI/180,er=.9995;function Nt(){return[0,0,0,1]}function pt(t,e){const n=Math.hypot(t[0],t[1],t[2]);if(n===0)return Nt();const r=e*W/2,s=Math.sin(r)/n;return[t[0]*s,t[1]*s,t[2]*s,Math.cos(r)]}function nr(t,e,n){return Xt(Xt(pt([0,1,0],e),pt([1,0,0],t)),pt([0,0,1],n))}function rr(t){const[e,n,r,s]=H(t),i=2*(e*r+n*s),a=2*(e*n+r*s),o=1-2*(e*e+r*r),c=2*(n*r-e*s),u=1-2*(n*n+r*r),h=2*(e*r-n*s),f=1-2*(e*e+n*n),d=Math.asin(Math.max(-1,Math.min(1,-c)));return Math.abs(c)<.9999999?[d/W,Math.atan2(i,f)/W,Math.atan2(a,o)/W]:[d/W,Math.atan2(-h,u)/W,0]}function Xt(t,e){const[n,r,s,i]=t,[a,o,c,u]=e;return[i*a+n*u+r*c-s*o,i*o-n*c+r*u+s*a,i*c+n*o-r*a+s*u,i*u-n*a-r*o-s*c]}function $e(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function Oe(t){return Math.hypot(t[0],t[1],t[2],t[3])}function H(t){const e=Oe(t);return e===0?Nt():[t[0]/e,t[1]/e,t[2]/e,t[3]/e]}function sr(t){return[-t[0],-t[1],-t[2],t[3]]}function Le(t,e,n){const r=H(t);let s=H(e),i=$e(r,s);if(i<0&&(s=[-s[0],-s[1],-s[2],-s[3]],i=-i),i>er)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 a=Math.acos(i),o=Math.sin(a),c=Math.sin((1-n)*a)/o,u=Math.sin(n*a)/o;return H([r[0]*c+s[0]*u,r[1]*c+s[1]*u,r[2]*c+s[2]*u,r[3]*c+s[3]*u])}function ir(t,e){const[n,r,s,i]=H(t),a=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]+i*a+(r*c-s*o),e[1]+i*o+(s*a-n*c),e[2]+i*c+(n*o-r*a)]}const ar=Object.freeze(Object.defineProperty({__proto__:null,conjugate:sr,dot:$e,fromAxisAngle:pt,fromEuler:nr,identity:Nt,length:Oe,multiply:Xt,normalize:H,rotateVec3:ir,slerp:Le,toEuler:rr},Symbol.toStringTag,{value:"Module"})),N=(t,e,n)=>t+(e-t)*n,Fe=512,xt=new Map,zt=new Map;function Ne(t){const e=xt.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 xt.size<Fe&&xt.set(t,r),r}const Xe=t=>t.charCodeAt(0)===35,xe=t=>t.startsWith("rgb"),ze=t=>t.startsWith("rgba"),or=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,Vt=t=>Math.round(t).toString(16).padStart(2,"0");function cr(t,e,n){return`#${Vt(t)}${Vt(e)}${Vt(n)}`}function Ve(t){const e=zt.get(t);if(e)return e;const n=t.match(or);if(!n)throw new Error(`Invalid rgb color: ${t}`);const r=parseInt(n[1],10),s=parseInt(n[2],10),i=parseInt(n[3],10),a=n[4]!==void 0?[r,s,i,parseFloat(n[4])]:[r,s,i];return zt.size<Fe&&zt.set(t,a),a}const Ue=(t,e,n)=>{if(Xe(t)&&Xe(e)){const[r,s,i]=Ne(t),[a,o,c]=Ne(e),u=N(r,a,n),h=N(s,o,n),f=N(i,c,n);return cr(u,h,f)}if((xe(t)||ze(t))&&(xe(e)||ze(e))){const r=Ve(t),s=Ve(e),i=Math.round(N(r[0],s[0],n)),a=Math.round(N(r[1],s[1],n)),o=Math.round(N(r[2],s[2],n));if(r.length===4||s.length===4){const c=r[3]??1,u=s[3]??1,h=N(c,u,n);return`rgba(${i}, ${a}, ${o}, ${h})`}return`rgb(${i}, ${a}, ${o})`}return n<1?t:e},Ye=(t,e,n)=>{const r=Math.min(t.length,e.length),s=[];for(let i=0;i<r;i++)s.push(N(t[i],e[i],n));return s},Be=(t,e,n)=>Le(t,e,n),Ut=(t,e,n)=>n<1?t:e,je=(t,e,n)=>Ee(t,e,n);function Yt(t,e){return e==="slerp"?Be:typeof t=="number"?N:Array.isArray(t)?Ye:typeof t=="string"?t.startsWith("#")||t.startsWith("rgb")?Ue:Ce(t)?je:Ut:Ut}const Bt=1e3/60;function jt(t,e={}){if(!V(t))throw new Error(`bakeSpringTrack: track "${t.id}" is not a spring track`);const n=new tt(t.spring);return He(t,r=>n.valueAt(r),n.settleTime(),t.spring.from,t.spring.to,e)}function Ht(t,e={}){if(!z(t))throw new Error(`bakeInertiaTrack: track "${t.id}" is not an inertia track`);const n=t.inertia;return He(t,r=>ft(n,r),nt(n),n.from,et(n),e)}function He(t,e,n,r,s,i){const a=i.intervalMs??Bt,o=i.tolerance??.01,c=t.delay??0,u=[];for(let f=0;f<=n;f+=a)u.push({time:f+c,value:e(f),easing:"linear"});const h=u[u.length-1];return!h||h.time<n+c?u.push({time:n+c,value:s,easing:"linear"}):h.value=s,c>0&&u.unshift({time:0,value:r,easing:"linear"}),{id:t.id,target:t.target,property:t.property,keyframes:o>0?Ke(u,o):u,...t.targets&&{targets:[...t.targets]},...t.stagger&&{stagger:{...t.stagger}}}}function Qe(t,e,n,r={}){const s=r.intervalMs??Bt,i=typeof n=="function"?n:Ot(n),a=Yt(t.value,r.interpolation),o=e.time-t.time;if(o<=0)return[e];const c=[];for(let h=s;h<o;h+=s){const f=h/o;c.push({time:t.time+h,value:a(t.value,e.value,i(f)),easing:"linear"})}const u=i(1);return c.push({...e,...u!==1&&{value:a(t.value,e.value,u)},easing:"linear"}),c}function ur(t,e){return V(t)?jt(t,e):z(t)?Ht(t,e):t}function Ge(t,e={}){const n=t.keyframes;if(!n.some(i=>ot(i.easing)))return t;const r=n.length>0?[n[0]]:[],s={...e,interpolation:t.interpolation??e.interpolation};for(let i=1;i<n.length;i++){const a=n[i];ot(a.easing)?r.push(...Qe(n[i-1],a,a.easing,s)):r.push(a)}return{...t,keyframes:r}}function lr(t,e){return t.filter(ie).map(n=>Ge(n,e)).concat(t.filter(V).map(n=>jt(n,e)),t.filter(z).map(n=>Ht(n,e)))}function Ke(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],i=t[r],a=t[r+1],o=a.time-s.time;if(o<=0)continue;const c=(i.time-s.time)/o,u=s.value+(a.value-s.value)*c;Math.abs(i.value-u)>e&&n.push(i)}return n.push(t[t.length-1]),n}function We(t){const e=[...t.keyframes].sort((n,r)=>n.time-r.time);return{...t,keyframes:e}}function B(t){return t.targets&&t.targets.length>0?t.targets:[t.target]}function q(t,e,n,r){const s=n??0;return!r||e<=1?s:s+wt(t,e,r)}class yt{track;targets;constructor(e){this.track=e,this.targets=B(e)}getValueAtTime(e){return this.valueForOffset(e-q(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 i=q(s,n,this.track.delay,this.track.stagger),a=this.valueForOffset(e-i);a!==void 0&&r.push({target:this.targets[s],value:a,start:i+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?ut(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 i=s.time-r.time,a=(e-r.time)/i,c=Ot(s.easing)(a);return Yt(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 qe{track;targets;sampler;constructor(e){this.track=e,this.targets=B(e),this.sampler=new tt(e.spring)}getValueAtTime(e){return this.sampler.valueAt(e-q(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 i=q(s,n,this.track.delay,this.track.stagger);r.push({target:this.targets[s],value:this.sampler.valueAt(e-i),start:i})}return r}getDuration(){const e=this.track.stagger?ut(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+e}getTrack(){return this.track}}class Ze{track;targets;duration;constructor(e){this.track=e,this.targets=B(e),this.duration=nt(e.inertia)}getValueAtTime(e){return ft(this.track.inertia,e-q(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 i=q(s,n,this.track.delay,this.track.stagger);r.push({target:this.targets[s],value:ft(this.track.inertia,e-i),start:i})}return r}getDuration(){const e=this.track.stagger?ut(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+e}getTrack(){return this.track}}function Qt(t,e){const n={...Ae(t.pathData,e)};if(t.matrix){const[r,s,i,a,o,c]=t.matrix,{x:u,y:h}=n;n.x=r*u+i*h+o,n.y=s*u+a*h+c;const f=n.angle*Math.PI/180,d=Math.cos(f),g=Math.sin(f);n.angle=Math.atan2(s*d+a*g,r*d+i*g)*180/Math.PI}return t.autoRotate&&t.rotateOffset&&(n.angle+=t.rotateOffset),n}function hr(t,e,n,r){const s=e+(n-e)*r;return Qt(t,s)}const Gt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},fr=20;function Je(t){const e=Gt[t??"upperCase"]??t??Gt.upperCase,n=Array.from(e);return n.length>0?n:Array.from(Gt.upperCase)}function dr(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 tn(t,e,n=0){const r=t.from??"",s=t.to,i=Math.max(0,Math.min(1,e));if(i<=0)return r;if(i>=1)return s;const a=Array.from(r),o=Array.from(s),c=t.rightToLeft??!1;if(t.mode==="type"){const b=Math.round(i*Math.max(a.length,o.length));return c?a.slice(0,Math.max(0,a.length-b)).join("")+o.slice(Math.max(0,o.length-b)).join(""):o.slice(0,b).join("")+a.slice(b).join("")}const u=Math.max(0,Math.min(.999,t.revealDelay??0)),h=Math.max(0,(i-u)/(1-u)),f=Math.floor(h*o.length),d=t.tweenLength===!1?o.length:Math.round(a.length+(o.length-a.length)*i),g=Je(t.chars),_=t.refreshRate??fr,m=_>0?Math.floor(n*_/1e3):0,p=t.seed??1;let T="";for(let b=0;b<d;b++){const A=c?b>=d-f:b<f,w=c?o[o.length-(d-b)]:o[b];A&&w!==void 0||w===" "||w===`
2
+ `?T+=w:T+=g[dr(p,b,m)%g.length]}return T}class en{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}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 i=1e3;for(let o=0;o<i&&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 a=this.getStateAtTime(this._currentTime);this.onUpdate?.(a)}getStateAtTime(e){const n=new Map;if(this._hasSharedWrites())this._resolveShared(e,n);else for(const[r,s]of this._trackPlayers){const i=s.getTrack().property;for(const{target:a,value:o,start:c}of s.getTargetValues(e))this._write(n,r,a,i,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,i]of this._trackPlayers){const a=i.getTrack().property;for(const{target:o,value:c,start:u}of i.getTargetValues(e)){const h=`${o}\0${a}`,f=u<=e,d=r.get(h);(!d||(f!==d.started?f:f?u>=d.start:u<=d.start))&&r.set(h,{trackId:s,target:o,property:a,value:c,start:u,started:f})}}for(const{trackId:s,target:i,property:a,value:o,start:c}of r.values())this._write(n,s,i,a,o,e-c)}_write(e,n,r,s,i,a){if(i===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 i=="number"){o.set("text",tn(c.textConfig,i,Math.max(0,a)));return}const u=this._motionPathTracks.get(n);if(u&&typeof i=="number"){const h=Qt(u.motionPathConfig,i);o.set("motionPathX",h.x),o.set("motionPathY",h.y),u.motionPathConfig.autoRotate&&o.set("motionPathRotate",h.angle)}else o.set(s,i)}_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 B(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,z(e)){this._trackPlayers.set(e.id,new Ze(e));return}if(V(e)){this._trackPlayers.set(e.id,new qe(e)),this._springTracks.set(e.id,e);return}if(ct(e))this._trackPlayers.set(e.id,new yt(e)),this._textTracks.set(e.id,e);else if(Pt(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 yt(n)),this._motionPathTracks.set(e.id,e)}else this._trackPlayers.set(e.id,new yt(e))}replaceTrack(e,n){const r=this._tracks.findIndex(i=>i.id===e);if(r<0)return;const s=this._tracks.slice(r+1);this.removeTrack(e);for(const i of s)this.removeTrack(i.id);this.addTrack(n);for(const i of s)this.addTrack(i)}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(V(r)||z(r))return{from:s,to:n.getDuration()};const i=r.keyframes;if(!(!i||i.length===0))return{from:i[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 i=0;i<n;i++){const a=this._tracks[i];if(a.property!==r.property)continue;const o=B(a).filter(f=>B(r).includes(f));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=s.to&&s.from<=c.to))continue;const h=s.from>=c.from;for(const f of o)e.push({target:f,property:r.property,losingTrackId:h?a.id:r.id,winningTrackId:h?r.id:a.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&&!B(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:At(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,i)=>s.time-i.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 gr=100;function mr(t,e,n,r){const s=[],i=[],{duration:a,alternate:o}=r,c=(g,_,m,p)=>{i.push([g,_]);const T=[];t.forEach((b,A)=>{(m==="forward"?(p?b>=g:b>g)&&b<=_:(p?b<=g:b<g)&&b>=_)&&T.push(A)}),T.sort((b,A)=>(m==="forward"?t[b]-t[A]:t[A]-t[b])||b-A);for(const b of T)s.push({kind:"event",index:b,direction:m})};let u=e.time,h=e.direction,f=e.fresh===!0;const d=Math.min(gr,Math.max(0,n.iteration-e.iteration));for(let g=0;g<d;g++){const _=h==="forward"?a:0;c(u,_,h,f),s.push({kind:"repeat"}),o?(h=h==="forward"?"reverse":"forward",u=_,f=!1):(u=h==="forward"?0:a,f=!0)}return d>0&&r.holding&&!o?{crossings:s,passes:i}:(c(u,n.time,h,f),{crossings:s,passes:i})}function nn(t){return z(t)?{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:rn(t.inertia),...X(t)}:V(t)?{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...X(t)}:ct(t)?{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:t.keyframes.map(Kt),...X(t)}:Pt(t)?{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:t.keyframes.map(Kt),...X(t)}:{id:t.id,target:t.target,property:t.property,keyframes:t.keyframes.map(Kt),...t.interpolation!==void 0&&{interpolation:t.interpolation},...X(t)}}function rn(t){return{...t,...Array.isArray(t.end)&&{end:[...t.end]}}}function Kt(t){return{time:t.time,value:t.value,...t.easing&&{easing:t.easing}}}function X(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 sn(t){if(z(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"inertia",inertia:rn(e.inertia),...X(e)}}if(V(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"spring",spring:{...e.spring},...X(e)}}if(ct(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),...X(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,...X(e)}}return We({id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,...t.interpolation!==void 0&&{interpolation:t.interpolation},...X(t)})}function an(t){const e=t._config.markers;return{formatVersion:At(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,...e&&{markers:e.map(n=>({...n}))}},tracks:t.tracks.map(nn),...t.captions&&{captions:JSON.parse(JSON.stringify(t.captions))}}}function on(t){const e=t.formatVersion??1;if(e>kt)throw new Error(`tinyfly: this animation uses format version ${e}, but this tinyfly reads up to version ${kt}. Update tinyfly to play it.`);return new en({id:t.id,name:t.name,config:t.config,tracks:t.tracks.map(sn),captions:t.captions})}function pr(t){return JSON.stringify(an(t))}function yr(t){const e=JSON.parse(t);return on(e)}function Mr(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 cn(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 Wt(t,e,n){return e+t.next()*(n-e)}function un(t,e,n,r){if(r<=0)return Wt(t,e,n);const s=Math.floor((n-e)/r),i=Math.round(t.next()*s);return e+i*r}function _r(t,e){if(e.length!==0)return e[Math.floor(t.next()*e.length)]}const ln=/^([+\-*/])=\s*(-?[\d.]+)$/,hn=/^random\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*(?:,\s*(-?[\d.]+)\s*)?\)$/i;function Tr(t){return typeof t!="string"?!1:ln.test(t.trim())||hn.test(t.trim())}function qt(t,e={}){if(typeof t!="string")return t;const n=t.trim(),r=ln.exec(n);if(r){const[,i,a]=r,o=e.base??0,c=Number.parseFloat(a);switch(i){case"+":return o+c;case"-":return o-c;case"*":return o*c;case"/":return c===0?o:o/c}}const s=hn.exec(n);if(s){if(!e.random)throw new Error(`resolveValue: "${n}" needs a random source — pass one via context.random`);const i=Number.parseFloat(s[1]),a=Number.parseFloat(s[2]),o=s[3]!==void 0?Number.parseFloat(s[3]):void 0;return o!==void 0?un(e.random,i,a,o):Wt(e.random,i,a)}return t}function fn(t,e=0,n){const r=[];let s=e;for(const i of t){const a=qt(i,{base:s,random:n});r.push(a),typeof a=="number"&&(s=a)}return r}class br{random;constructor(e){this.random=cn(e)}get seed(){return this.random.seed}resolve(e,n=0){return qt(e,{base:n,random:this.random})}resolveSequence(e,n=0){return fn(e,n,this.random)}}const Sr=600;function kr(t){if(Array.isArray(t)){const[d,g,_,m]=t;return{fn:dn(d,g,_,m),bezier:[d,g,_,m]}}const{segments:e}=j(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],i=s.endX-n,a=s.endY-r;if(i===0||a===0)throw new Error(`customEase: "${t}" must move along both axes`);const o=d=>(d-n)/i,c=d=>(d-r)/a;if(e.length===1&&s.type==="C"){const[d,g,_,m]=s.points,p=[o(d),c(g),o(_),c(m)];return{fn:dn(...p),bezier:p}}const u=[],h=[],f=Math.max(8,Math.ceil(Sr/e.length));for(const d of e)for(let g=u.length===0?0:1;g<=f;g++){const[_,m]=vr(d,g/f);u.push(o(_)),h.push(c(m))}return{fn:wr(u,h)}}function Ar(t={}){const n=.1+Math.max(0,Math.min(1,t.strength??.7))*.7,r=[1];for(let i=n;i>.002;i*=n)r.push(2*Math.sqrt(i));const s=r.reduce((i,a)=>i+a,0);return i=>{if(i<=0)return 0;if(i>=1)return 1;let a=i*s;for(let o=0;o<r.length;o++){if(a<=r[o]){if(o===0)return(a/r[0])**2;const c=r[o]/2,u=c*c,h=a-c;return 1-(u-h*h)}a-=r[o]}return 1}}function Pr(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 vr(t,e){if(t.type==="L"){const[u,h]=t.points;return[t.startX+(u-t.startX)*e,t.startY+(h-t.startY)*e]}const[n,r,s,i,a,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*a,c*c*c*t.startY+3*c*c*e*r+3*c*e*e*i+e*e*e*o]}function wr(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 a=r+s>>1;t[a]<=n?r=a:s=a}const i=t[s]-t[r];return i===0?e[s]:e[r]+(n-t[r])/i*(e[s]-e[r])}}function dn(t,e,n,r){const s=(a,o,c)=>3*(1-a)*(1-a)*a*o+3*(1-a)*a*a*c+a*a*a,i=(a,o,c)=>3*(1-a)*(1-a)*o+6*(1-a)*a*(c-o)+3*a*a*(1-c);return a=>{if(a<=0)return 0;if(a>=1)return 1;let o=a;for(let h=0;h<8;h++){const f=s(o,t,n)-a,d=i(o,t,n);if(Math.abs(f)<1e-6)return s(o,e,r);if(Math.abs(d)<1e-6)break;o-=f/d}let c=0,u=1;o=a;for(let h=0;h<40;h++)s(o,t,n)<a?c=o:u=o,o=(c+u)/2;return s(o,e,r)}}const Ir=350,Rr=300,Dr=550;function Er(t,e={}){const n=e.lead??Ir,r=e.gap??Rr,s=e.tail??Dr,i=[];let a=0;return t.forEach((o,c)=>{const u=[];let h=a+n;o.lines.forEach((d,g)=>{if(!(d.duration>=0))throw new Error(`narration: scene ${c} line ${g} has an invalid duration (${d.duration})`);g>0&&(h+=r),u.push({id:d.id??`s${c}-l${g}`,scene:c,line:g,start:h,end:h+d.duration,text:d.text}),h+=d.duration});const f=h+s+(o.tail??0);i.push({id:o.id??`s${c}`,start:a,duration:f-a,cues:u}),a=f}),{duration:a,scenes:i,cues:i.flatMap(o=>o.cues)}}function Cr(t){return t.cues.map(e=>({id:e.id,time:e.start,label:e.text}))}function $r(t,e){let n=t.scenes[0];for(const r of t.scenes)if(e>=r.start)n=r;else break;return n}const Zt=t=>6e4/t.bpm;function Mt(t,e){return t.offset+e*Zt(t)}function _t(t,e){return(e-t.offset)/Zt(t)}function Or(t,e){return Mt(t,Math.round(_t(t,e)))}function Lr(t,e){return Mt(t,Math.ceil(_t(t,e)-1e-9))}function Fr(t,e,n){const r=Math.max(1,Math.round(t.beatsPerBar??4)),s=[];if(!(t.bpm>0)||n<e)return s;for(let i=Math.ceil(_t(t,e)-1e-9);;i++){const a=Mt(t,i);if(a>n+1e-9)break;s.push({time:a,bar:(i%r+r)%r===0,n:i})}return s}const Z=100;function Nr(t,e,n={}){const r=n.minBpm??70,s=n.maxBpm??180,i=Math.max(1,Math.round(e/Z)),a=Math.min(t.length,Math.round((n.maxSeconds??60)*e)),o=Math.floor(a/i);if(o<4)return{bpm:120,offset:0,confidence:0};const c=new Float64Array(o);for(let y=0;y<o;y++){let S=0;for(let k=y*i;k<(y+1)*i;k++)S+=t[k]*t[k];c[y]=Math.log(1e-6+S/i)}const u=new Float64Array(o);for(let y=1;y<o;y++)u[y]=Math.max(0,c[y]-c[y-1]);const h=u.reduce((y,S)=>y+S,0)/o;for(let y=0;y<o;y++)u[y]=Math.max(0,u[y]-h);const f=Math.max(1,Math.floor(60*Z/s)),d=Math.min(o-1,Math.ceil(60*Z/r)),g=y=>{let S=0;for(let k=y;k<o;k++)S+=u[k]*u[k-y];return S/(o-y)};let _=0;for(let y=0;y<o;y++)_+=u[y]*u[y];_/=o;let m=f,p=-1/0;for(let y=f;y<=d;y++){const S=60*Z/y,k=Math.exp(-.5*(Math.log2(S/120)/.9)**2),P=g(y)*k;P>p&&(p=P,m=y)}const T=y=>{const S=Math.floor(y);return S<0||S+1>=o?0:u[S]+(u[S+1]-u[S])*(y-S)},b=(y,S)=>{let k=0;for(let P=S;P<o;P+=y)k+=T(P);return k};let A=m,w=0,M=-1/0;for(let y=m-.6;y<=m+.6+1e-9;y+=.02){if(y<1)continue;const S=Math.max(1,Math.round(y*4));for(let k=0;k<S;k++){const P=k/S*y,D=b(y,P);D>M&&(M=D,w=P,A=y)}}const I=60*Z/A,v=_>0?Math.max(0,Math.min(1,g(m)/_)):0,$=(w+.5)*1e3/Z;return{bpm:Math.round(I*100)/100,offset:Math.round($%(6e4/I)),confidence:v}}const x=t=>Math.round(t*1e3)/1e3;function Xr(t,e={}){if(t.length===0)return"";const n=e.curviness??1,r=e.closed??!1,s=t.length;let i=`M${x(t[0].x)} ${x(t[0].y)}`;if(s===1)return i;const a=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 u=a(c-1),h=a(c),f=a(c+1),d=a(c+2);if(n===0){i+=` L${x(f.x)} ${x(f.y)}`;continue}const g=n/6,_=h.x+(f.x-u.x)*g,m=h.y+(f.y-u.y)*g,p=f.x-(d.x-h.x)*g,T=f.y-(d.y-h.y)*g;i+=` C${x(_)} ${x(m)} ${x(p)} ${x(T)} ${x(f.x)} ${x(f.y)}`}return r?`${i} Z`:i}const C=(t,e=0)=>{const n=parseFloat(t??"");return Number.isFinite(n)?n:e};function xr(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 zr(t){const e=t.attributes;switch(t.tag.toLowerCase()){case"path":return e.d??null;case"circle":case"ellipse":{const n=C(e.cx),r=C(e.cy),s=t.tag.toLowerCase()==="circle"?C(e.r):C(e.rx),i=t.tag.toLowerCase()==="circle"?C(e.r):C(e.ry);return`M${n+s} ${r} A${s} ${i} 0 1 1 ${n-s} ${r} A${s} ${i} 0 1 1 ${n+s} ${r} Z`}case"rect":{const n=C(e.x),r=C(e.y),s=C(e.width),i=C(e.height);let a=e.rx!=null?C(e.rx):e.ry!=null?C(e.ry):0,o=e.ry!=null?C(e.ry):a;return a=Math.min(a,s/2),o=Math.min(o,i/2),a===0||o===0?`M${n} ${r} H${n+s} V${r+i} H${n} Z`:`M${n+a} ${r} H${n+s-a} A${a} ${o} 0 0 1 ${n+s} ${r+o} V${r+i-o} A${a} ${o} 0 0 1 ${n+s-a} ${r+i} H${n+a} A${a} ${o} 0 0 1 ${n} ${r+i-o} V${r+o} A${a} ${o} 0 0 1 ${n+a} ${r} Z`}case"line":return`M${C(e.x1)} ${C(e.y1)} L${C(e.x2)} ${C(e.y2)}`;case"polyline":case"polygon":{const n=xr(e.points);if(n.length===0)return null;const r=n.map((s,i)=>`${i===0?"M":"L"}${s.x} ${s.y}`).join(" ");return t.tag.toLowerCase()==="polygon"?`${r} Z`:r}default:return null}}function Vr(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function Jt(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function gn(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function Tt(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function te(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 ee(t){return Math.hypot(t[0],t[1],t[2])}function Ur(t,e){return ee(Jt(t,e))}function ne(t){const e=ee(t);return e===0?[0,0,0]:gn(t,1/e)}function Yr(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 Br=Object.freeze(Object.defineProperty({__proto__:null,add:Vr,cross:te,distance:Ur,dot:Tt,length:ee,lerp:Yr,normalize:ne,scale:gn,subtract:Jt},Symbol.toStringTag,{value:"Module"})),jr=Math.PI/180;function Hr(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function Qr(t,e){const n=new Array(16);for(let r=0;r<4;r++)for(let s=0;s<4;s++){let i=0;for(let a=0;a<4;a++)i+=t[a*4+s]*e[r*4+a];n[r*4+s]=i}return n}function Gr(t){return[1,0,0,0,0,1,0,0,0,0,1,0,t[0],t[1],t[2],1]}function Kr(t){return[t[0],0,0,0,0,t[1],0,0,0,0,t[2],0,0,0,0,1]}function mn(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 Wr(t,e,n){const r=mn(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 qr(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 Zr(t){const[e,n,r,s,i,a,o,c,u,h,f,d,g,_,m,p]=t,T=e*a-n*i,b=e*o-r*i,A=e*c-s*i,w=n*o-r*a,M=n*c-s*a,I=r*c-s*o,v=u*_-h*g,$=u*m-f*g,y=u*p-d*g,S=h*m-f*_,k=h*p-d*_,P=f*p-d*m,D=T*P-b*k+A*S+w*y-M*$+I*v;if(Math.abs(D)<1e-12)return null;const R=1/D;return[(a*P-o*k+c*S)*R,(r*k-n*P-s*S)*R,(_*I-m*M+p*w)*R,(f*M-h*I-d*w)*R,(o*y-i*P-c*$)*R,(e*P-r*y+s*$)*R,(m*A-g*I-p*b)*R,(u*I-f*A+d*b)*R,(i*k-a*y+c*v)*R,(n*y-e*k-s*v)*R,(g*M-_*A+p*T)*R,(h*A-u*M-d*T)*R,(a*$-i*S-o*v)*R,(e*S-n*$+r*v)*R,(_*b-g*w-m*T)*R,(u*w-h*b+f*T)*R]}function Jr(t,e,n,r){const s=1/Math.tan(t*jr/2),i=1/(n-r);return[s/e,0,0,0,0,s,0,0,0,0,(r+n)*i,-1,0,0,2*r*n*i,0]}function ts(t,e,n,r,s,i){const a=1/(e-t),o=1/(r-n),c=1/(i-s);return[2*a,0,0,0,0,2*o,0,0,0,0,-2*c,0,-(e+t)*a,-(r+n)*o,-(i+s)*c,1]}function es(t,e,n=[0,1,0]){const r=ne(Jt(t,e)),s=ne(te(n,r)),i=te(r,s);return[s[0],i[0],r[0],0,s[1],i[1],r[1],0,s[2],i[2],r[2],0,-Tt(s,t),-Tt(i,t),-Tt(r,t),1]}function ns(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],i=t[3]*e[0]+t[7]*e[1]+t[11]*e[2]+t[15];return i===1||i===0?[n,r,s]:[n/i,r/i,s/i]}const rs=Object.freeze(Object.defineProperty({__proto__:null,compose:Wr,fromQuat:mn,identity:Hr,invert:Zr,lookAt:es,multiply:Qr,orthographic:ts,perspective:Jr,scaling:Kr,transformPoint:ns,translation:Gr,transpose:qr},Symbol.toStringTag,{value:"Module"}));l.Clock=bn,l.DEFAULT_BAKE_INTERVAL_MS=Bt,l.DEFAULT_INERTIA_FRICTION=Rt,l.DEFAULT_SPRING=F,l.FORMAT_VERSION=kt,l.INERTIA_MAX_DURATION_MS=ce,l.InertiaTrackPlayer=Ze,l.MORPH_SAMPLES=jn,l.ManualClock=Tn,l.SPRING_MAX_DURATION_MS=It,l.SPRING_PRESETS=Sn,l.SPRING_STEP_MS=G,l.SpringSampler=tt,l.SpringTrackPlayer=qe,l.Timeline=en,l.TrackPlayer=yt,l.ValueResolver=br,l.backOut=_e,l.bakeEasing=Qe,l.bakeInertiaTrack=Ht,l.bakeSpringTrack=jt,l.beatAtTime=_t,l.beatLength=Zt,l.beatTime=Mt,l.beatsBetween=Fr,l.bounceOut=Me,l.charactersFor=Je,l.clearMorphCache=tr,l.clearPathCache=zn,l.createCubicBezier=pe,l.createRandom=cn,l.createTrack=We,l.criticalDamping=vn,l.customBounce=Ar,l.customEase=kr,l.customWiggle=Pr,l.deserializeTimeline=on,l.deserializeTrack=sn,l.detectTempo=Nr,l.easeIn=de,l.easeInCubic=Dt,l.easeInOut=me,l.easeInOutCubic=Ct,l.easeInOutQuad=fe,l.easeInQuad=le,l.easeOut=ge,l.easeOutCubic=Et,l.easeOutQuad=he,l.elasticOut=ye,l.expandParametricEasings=Ge,l.formatVersionFor=At,l.fromJSON=yr,l.getEasingFunction=Ot,l.getInterpolator=Yt,l.getMotionPathPoint=Qt,l.getPathLength=Vn,l.getPointAtProgress=Ae,l.hasKeyframes=ie,l.hashSeed=Mr,l.inertiaDuration=nt,l.inertiaRest=et,l.inertiaValueAt=ft,l.inertiaVelocityAt=Dn,l.interpolateArray=Ye,l.interpolateColor=Ue,l.interpolateMotionPath=hr,l.interpolateNumber=N,l.interpolatePathString=je,l.interpolateQuaternion=Be,l.interpolateString=Ut,l.isCubicBezierEasing=Q,l.isInertiaTrack=z,l.isMotionPathPoint=_n,l.isMotionPathTrack=Pt,l.isParametricEasing=ot,l.isPathData=Ce,l.isSpringTrack=V,l.isTextTrack=ct,l.isUnderdamped=Pn,l.isUnresolved=Tr,l.linear=dt,l.mat4=rs,l.maxStaggerDistance=ae,l.morphPath=Ee,l.narrationMarkers=Cr,l.narrationSceneAt=$r,l.naturalRest=ue,l.nearestBeat=Or,l.nextBeat=Lr,l.parametricEasing=be,l.parsePath=j,l.planNarration=Er,l.playheadCrossings=mr,l.pointAtDistance=Lt,l.pointsToPath=Xr,l.quat=ar,l.randomBetween=Wt,l.randomChoice=_r,l.randomSnapped=un,l.resolveSequence=fn,l.resolveValue=qt,l.serializeTimeline=an,l.serializeTrack=nn,l.shapeToPathData=zr,l.simplifyKeyframes=Ke,l.springDuration=An,l.springValueAt=kn,l.staggerDistance=vt,l.staggerOffset=wt,l.staggerOffsets=oe,l.staggerSpan=ut,l.stepsEasing=Te,l.textAt=tn,l.toJSON=pr,l.toKeyframedTrack=ur,l.toKeyframedTracks=lr,l.trackTargets=B,l.vec3=Br,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
@@ -1,4 +1,4 @@
1
- import { parsePath, createRandom, hashSeed, deserializeTimeline, planNarration } from "@algorisys/tinyfly";
1
+ import { parsePath, createRandom, hashSeed, mat4, quat, deserializeTimeline, planNarration } from "@algorisys/tinyfly";
2
2
  import { spawn } from "node:child_process";
3
3
  import { mkdir, writeFile } from "node:fs/promises";
4
4
  import { resolve, join, dirname } from "node:path";
@@ -268,6 +268,147 @@ function smoothPath(ctx, points) {
268
268
  const last = points[points.length - 1];
269
269
  ctx.lineTo(last.x, last.y);
270
270
  }
271
+ const DEG = Math.PI / 180;
272
+ function has3dTransform(t) {
273
+ return t.z !== void 0 || t.rotateX !== void 0 || t.rotateY !== void 0 || t.perspective !== void 0 || Array.isArray(t.quaternion) && t.quaternion.length === 4;
274
+ }
275
+ function perspectiveMatrix(distance) {
276
+ const m = mat4.identity();
277
+ if (distance > 0) m[11] = -1 / distance;
278
+ return m;
279
+ }
280
+ function skewMatrix(skewX, skewY) {
281
+ const m = mat4.identity();
282
+ m[4] = Math.tan(skewX * DEG);
283
+ m[1] = Math.tan(skewY * DEG);
284
+ return m;
285
+ }
286
+ const turn = (axis, degrees) => degrees ? mat4.fromQuat(quat.fromAxisAngle(axis, degrees)) : null;
287
+ function elementMatrix(t, offset, pivot) {
288
+ const parts = [
289
+ mat4.translation([pivot.x, pivot.y, 0]),
290
+ t.perspective !== void 0 ? perspectiveMatrix(t.perspective) : null,
291
+ mat4.translation([offset.x, offset.y, t.z ?? 0]),
292
+ turn([0, 0, 1], t.rotate),
293
+ turn([1, 0, 0], t.rotateX),
294
+ turn([0, 1, 0], t.rotateY),
295
+ Array.isArray(t.quaternion) && t.quaternion.length === 4 ? mat4.fromQuat(quat.normalize(t.quaternion)) : null,
296
+ t.scale !== void 0 ? mat4.scaling([t.scale, t.scale, 1]) : mat4.scaling([t.scaleX ?? 1, t.scaleY ?? 1, 1]),
297
+ t.skewX !== void 0 || t.skewY !== void 0 ? skewMatrix(t.skewX ?? 0, t.skewY ?? 0) : null,
298
+ mat4.translation([-pivot.x, -pivot.y, 0])
299
+ ];
300
+ return parts.reduce((m, part) => part ? mat4.multiply(m, part) : m, mat4.identity());
301
+ }
302
+ function isAffine(m) {
303
+ return m[3] === 0 && m[7] === 0 && m[11] === 0 && m[15] === 1;
304
+ }
305
+ function affinePart(m) {
306
+ return [m[0], m[1], m[4], m[5], m[12], m[13]];
307
+ }
308
+ function isBackFacing(m) {
309
+ const inverse = mat4.invert(m);
310
+ return inverse !== null && inverse[10] < 0;
311
+ }
312
+ function projectPoint(m, x, y) {
313
+ const w = m[3] * x + m[7] * y + m[15];
314
+ if (w <= 1e-6) return null;
315
+ return { x: (m[0] * x + m[4] * y + m[12]) / w, y: (m[1] * x + m[5] * y + m[13]) / w };
316
+ }
317
+ function triangleTransform(from, to) {
318
+ const [s0, s1, s2] = from;
319
+ const [d0, d1, d2] = to;
320
+ const sx1 = s1.x - s0.x;
321
+ const sy1 = s1.y - s0.y;
322
+ const sx2 = s2.x - s0.x;
323
+ const sy2 = s2.y - s0.y;
324
+ const det = sx1 * sy2 - sx2 * sy1;
325
+ if (Math.abs(det) < 1e-9) return null;
326
+ const dx1 = d1.x - d0.x;
327
+ const dy1 = d1.y - d0.y;
328
+ const dx2 = d2.x - d0.x;
329
+ const dy2 = d2.y - d0.y;
330
+ const a = (dx1 * sy2 - dx2 * sy1) / det;
331
+ const b = (dy1 * sy2 - dy2 * sy1) / det;
332
+ const c = (dx2 * sx1 - dx1 * sx2) / det;
333
+ const d = (dy2 * sx1 - dy1 * sx2) / det;
334
+ return [a, b, c, d, d0.x - a * s0.x - c * s0.y, d0.y - b * s0.x - d * s0.y];
335
+ }
336
+ function meshDivisions(m, bounds) {
337
+ const corners = [
338
+ projectPoint(m, bounds.x, bounds.y),
339
+ projectPoint(m, bounds.x + bounds.width, bounds.y),
340
+ projectPoint(m, bounds.x, bounds.y + bounds.height),
341
+ projectPoint(m, bounds.x + bounds.width, bounds.y + bounds.height)
342
+ ];
343
+ if (corners.some((c2) => c2 === null)) return 16;
344
+ const [a, b, c, d] = corners;
345
+ const size = Math.max(Math.hypot(d.x - a.x, d.y - a.y), Math.hypot(c.x - b.x, c.y - b.y));
346
+ return Math.min(16, Math.max(2, Math.round(size / 40)));
347
+ }
348
+ function perspectiveMesh(m, bounds, divisions = meshDivisions(m, bounds)) {
349
+ const n = Math.max(1, Math.round(divisions));
350
+ const grid = [];
351
+ for (let row = 0; row <= n; row++) {
352
+ const line = [];
353
+ for (let col = 0; col <= n; col++) {
354
+ const source = { x: bounds.x + bounds.width * col / n, y: bounds.y + bounds.height * row / n };
355
+ line.push({ source, target: projectPoint(m, source.x, source.y) });
356
+ }
357
+ grid.push(line);
358
+ }
359
+ const triangles = [];
360
+ const add = (p, q, r) => {
361
+ if (p.target && q.target && r.target) triangles.push({ source: [p.source, q.source, r.source], target: [p.target, q.target, r.target] });
362
+ };
363
+ for (let row = 0; row < n; row++) {
364
+ for (let col = 0; col < n; col++) {
365
+ const tl = grid[row][col];
366
+ const tr = grid[row][col + 1];
367
+ const bl = grid[row + 1][col];
368
+ const br = grid[row + 1][col + 1];
369
+ add(tl, tr, br);
370
+ add(tl, br, bl);
371
+ }
372
+ }
373
+ return triangles;
374
+ }
375
+ function growTriangle(points, amount) {
376
+ const [a, b, c] = points;
377
+ const sign = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x) >= 0 ? 1 : -1;
378
+ const outward = (p, q) => {
379
+ const dx = q.x - p.x;
380
+ const dy = q.y - p.y;
381
+ const len = Math.hypot(dx, dy) || 1;
382
+ return { x: sign * dy / len, y: -sign * dx / len };
383
+ };
384
+ return points.map((p, i) => {
385
+ const prev = points[(i + 2) % 3];
386
+ const next = points[(i + 1) % 3];
387
+ const n1 = outward(prev, p);
388
+ const n2 = outward(p, next);
389
+ const bx = n1.x + n2.x;
390
+ const by = n1.y + n2.y;
391
+ const half = Math.hypot(bx, by) / 2 || 1;
392
+ const reach = Math.min(amount / half, amount * 4);
393
+ const len = Math.hypot(bx, by) || 1;
394
+ return { x: p.x + bx / len * reach, y: p.y + by / len * reach };
395
+ });
396
+ }
397
+ function createLayerCanvas(ctx, width, height) {
398
+ if (typeof OffscreenCanvas !== "undefined") return new OffscreenCanvas(width, height);
399
+ const source = ctx.canvas;
400
+ if (source?.ownerDocument) {
401
+ const canvas = source.ownerDocument.createElement("canvas");
402
+ canvas.width = width;
403
+ canvas.height = height;
404
+ return canvas;
405
+ }
406
+ try {
407
+ return source?.constructor ? new source.constructor(width, height) : null;
408
+ } catch {
409
+ return null;
410
+ }
411
+ }
271
412
  class CanvasAdapter {
272
413
  targets = /* @__PURE__ */ new Map();
273
414
  targetOrder = [];
@@ -278,6 +419,8 @@ class CanvasAdapter {
278
419
  aliases = /* @__PURE__ */ new Map();
279
420
  // Time of the last applied state, passed to custom draw functions
280
421
  time = 0;
422
+ /** Offscreen layer for see-through targets in perspective (see `drawInPerspective`) */
423
+ layer = null;
281
424
  /**
282
425
  * Register a canvas drawing target.
283
426
  * @param id - The ID to register the target under
@@ -325,7 +468,8 @@ class CanvasAdapter {
325
468
  fill: "fillStyle",
326
469
  stroke: "strokeStyle",
327
470
  strokeWidth: "lineWidth",
328
- motionPathRotate: "rotate"
471
+ motionPathRotate: "rotate",
472
+ rotateZ: "rotate"
329
473
  };
330
474
  // Properties that are position offsets (applied via ctx.translate)
331
475
  static OFFSET_PROPERTIES = /* @__PURE__ */ new Set(["x", "y", "motionPathX", "motionPathY"]);
@@ -348,7 +492,7 @@ class CanvasAdapter {
348
492
  } else if (property === "y" || property === "motionPathY") {
349
493
  offsets.y = value;
350
494
  }
351
- } else if (target.type === "custom" && target.props && property in target.props) {
495
+ } else if (target.type === "custom" && target.props && (property in target.props || target.acceptsProp?.(property))) {
352
496
  target.props[property] = value;
353
497
  } else {
354
498
  const targetProperty = CanvasAdapter.PROPERTY_MAP[property] ?? property;
@@ -381,12 +525,27 @@ class CanvasAdapter {
381
525
  */
382
526
  renderTarget(ctx, target, offset) {
383
527
  ctx.save();
384
- if (offset.x !== 0 || offset.y !== 0) {
385
- ctx.translate(offset.x, offset.y);
386
- }
387
528
  if (target.opacity !== void 0) {
388
529
  ctx.globalAlpha = target.opacity;
389
530
  }
531
+ if (has3dTransform(target)) {
532
+ const matrix = elementMatrix(target, offset, { x: this.getPivotX(target), y: this.getPivotY(target) });
533
+ if (target.backfaceVisibility === "hidden" && isBackFacing(matrix)) {
534
+ ctx.restore();
535
+ return;
536
+ }
537
+ if (isAffine(matrix)) {
538
+ ctx.transform(...affinePart(matrix));
539
+ this.drawContent(ctx, target);
540
+ } else {
541
+ this.drawInPerspective(ctx, target, matrix);
542
+ }
543
+ ctx.restore();
544
+ return;
545
+ }
546
+ if (offset.x !== 0 || offset.y !== 0) {
547
+ ctx.translate(offset.x, offset.y);
548
+ }
390
549
  const hasTransform = target.rotate !== void 0 || target.rotateX !== void 0 || target.rotateY !== void 0 || target.scale !== void 0 || target.scaleX !== void 0 || target.scaleY !== void 0 || target.skewX !== void 0 || target.skewY !== void 0;
391
550
  if (hasTransform) {
392
551
  const centerX = this.getPivotX(target);
@@ -415,6 +574,105 @@ class CanvasAdapter {
415
574
  }
416
575
  ctx.translate(-centerX, -centerY);
417
576
  }
577
+ this.drawContent(ctx, target);
578
+ ctx.restore();
579
+ }
580
+ /**
581
+ * Draw a target in perspective: each triangle of a mesh over its bounds is
582
+ * clipped on the canvas and drawn with the 2D transform that carries it
583
+ * there. The triangles overlap by a pixel so no anti-aliased seam shows.
584
+ */
585
+ drawInPerspective(ctx, target, matrix) {
586
+ const alpha = ctx.globalAlpha;
587
+ const layer = alpha < 1 ? this.perspectiveLayer(ctx) : null;
588
+ if (layer) {
589
+ layer.ctx.setTransform(ctx.getTransform());
590
+ this.drawMesh(layer.ctx, target, matrix);
591
+ ctx.save();
592
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
593
+ ctx.drawImage(layer.canvas, 0, 0);
594
+ ctx.restore();
595
+ return;
596
+ }
597
+ this.drawMesh(ctx, target, matrix);
598
+ }
599
+ drawMesh(ctx, target, matrix) {
600
+ const bounds = this.contentBounds(ctx, target);
601
+ for (const triangle of perspectiveMesh(matrix, bounds)) {
602
+ const transform = triangleTransform(triangle.source, triangle.target);
603
+ if (!transform) continue;
604
+ const [p, q, r] = growTriangle(triangle.target, 1);
605
+ ctx.save();
606
+ ctx.beginPath();
607
+ ctx.moveTo(p.x, p.y);
608
+ ctx.lineTo(q.x, q.y);
609
+ ctx.lineTo(r.x, r.y);
610
+ ctx.closePath();
611
+ ctx.clip();
612
+ ctx.transform(...transform);
613
+ this.drawContent(ctx, target);
614
+ ctx.restore();
615
+ }
616
+ }
617
+ /** A cleared offscreen canvas the size of `ctx`'s, reused frame to frame; null where none can be made. */
618
+ perspectiveLayer(ctx) {
619
+ const width = ctx.canvas?.width ?? 0;
620
+ const height = ctx.canvas?.height ?? 0;
621
+ if (!(width > 0 && height > 0)) return null;
622
+ if (!this.layer || this.layer.width !== width || this.layer.height !== height) {
623
+ const canvas = createLayerCanvas(ctx, width, height);
624
+ const layerCtx2 = canvas?.getContext("2d");
625
+ this.layer = canvas && layerCtx2 ? { canvas, ctx: layerCtx2, width, height } : null;
626
+ if (!this.layer) return null;
627
+ }
628
+ const layerCtx = this.layer.ctx;
629
+ layerCtx.setTransform(1, 0, 0, 1, 0, 0);
630
+ layerCtx.globalAlpha = 1;
631
+ layerCtx.clearRect(0, 0, width, height);
632
+ return this.layer;
633
+ }
634
+ /**
635
+ * Everything a target paints, generously: its box, measured text, a path's
636
+ * control points, plus room for its stroke, blur and glow. The perspective
637
+ * mesh covers this, so nothing it draws falls outside.
638
+ */
639
+ contentBounds(ctx, target) {
640
+ let box = this.getTargetBounds(target);
641
+ if (target.type === "text") {
642
+ const fontSize = target.fontSize ?? 16;
643
+ ctx.save();
644
+ ctx.font = `${target.fontWeight ?? 400} ${fontSize}px ${target.fontFamily ?? "sans-serif"}`;
645
+ const width = ctx.measureText(target.text).width;
646
+ ctx.restore();
647
+ const align = target.textAlign ?? "left";
648
+ const left = align === "center" ? target.x - width / 2 : align === "right" ? target.x - width : target.x;
649
+ const top = (target.textBaseline ?? "top") === "top" ? target.y : target.y - fontSize;
650
+ box = { x: left, y: top, width, height: fontSize * 1.4 };
651
+ } else if (target.type === "path") {
652
+ const xs = [];
653
+ const ys = [];
654
+ for (const segment of parsePath(target.d).segments) {
655
+ xs.push(segment.startX, segment.endX);
656
+ ys.push(segment.startY, segment.endY);
657
+ for (let i = 0; i + 1 < segment.points.length; i += 2) {
658
+ xs.push(segment.points[i]);
659
+ ys.push(segment.points[i + 1]);
660
+ }
661
+ }
662
+ if (xs.length > 0) {
663
+ const minX = Math.min(...xs);
664
+ const minY = Math.min(...ys);
665
+ box = { x: target.x + minX, y: target.y + minY, width: Math.max(...xs) - minX, height: Math.max(...ys) - minY };
666
+ }
667
+ }
668
+ const pad = (target.lineWidth ?? 1) + 2 + 3 * Math.max(target.blur ?? 0, target.glow ?? 0, target.shadowBlur ?? 0) + Math.max(Math.abs(target.shadowX ?? 0), Math.abs(target.shadowY ?? 0));
669
+ return { x: box.x - pad, y: box.y - pad, width: box.width + 2 * pad, height: box.height + 2 * pad };
670
+ }
671
+ /**
672
+ * Paint a target in the current transform: its fill and stroke styles,
673
+ * filter and clip, then its shape.
674
+ */
675
+ drawContent(ctx, target) {
418
676
  if (target.fillStyle) {
419
677
  ctx.fillStyle = this.resolveFillStyle(ctx, target);
420
678
  }
@@ -461,7 +719,6 @@ class CanvasAdapter {
461
719
  this.renderCustom(ctx, target);
462
720
  break;
463
721
  }
464
- ctx.restore();
465
722
  }
466
723
  /**
467
724
  * Resolve a fill style to a canvas-compatible value.