@algorisys/tinyfly 0.82.0 → 0.87.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +13 -4
  2. package/bin/tinyfly.mjs +44 -6
  3. package/lib/addons/adapters.js +411 -248
  4. package/lib/addons/characters.js +1652 -1470
  5. package/lib/addons/dom-adapter-Cphr2HZn.js +372 -0
  6. package/lib/addons/gsap-compat.js +197 -187
  7. package/lib/addons/load-scene-vp14_Jj-.js +324 -0
  8. package/lib/addons/maps.js +1 -1
  9. package/lib/addons/scene-3d-webgl.js +240 -0
  10. package/lib/addons/scene-3d.js +306 -0
  11. package/lib/addons/shading-o5T_v9DT.js +89 -0
  12. package/lib/addons/{sketch-CA8ZXhxI.js → sketch-CYPUbk3Q.js} +2 -2
  13. package/lib/browser/tinyfly-scene-3d-webgl.iife.js +116 -0
  14. package/lib/browser/tinyfly-scene-3d.iife.js +3 -0
  15. package/lib/browser/tinyfly.iife.js +4 -4
  16. package/lib/browser/tinyfly.js +4333 -3726
  17. package/lib/browser/tinyfly.umd.js +4 -4
  18. package/lib/cli/tools.js +137 -22
  19. package/lib/embed/tinyfly-embed.iife.js +4 -4
  20. package/lib/embed/tinyfly-embed.js +921 -833
  21. package/lib/engine/tinyfly-engine.js +1022 -776
  22. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  23. package/lib/headless/headless.js +410 -8
  24. package/lib/player/tinyfly-player.es.js +459 -371
  25. package/lib/player/tinyfly-player.iife.js +2 -2
  26. package/lib/player/tinyfly-player.umd.js +2 -2
  27. package/lib/types/adapters/canvas/bloom.d.ts +33 -0
  28. package/lib/types/adapters/canvas/canvas-adapter.d.ts +36 -0
  29. package/lib/types/adapters/canvas/index.d.ts +2 -0
  30. package/lib/types/adapters/canvas/offscreen.d.ts +13 -0
  31. package/lib/types/adapters/transform-3d.d.ts +99 -0
  32. package/lib/types/adapters/webgl/webgl-adapter.d.ts +17 -0
  33. package/lib/types/browser/index.d.ts +2 -0
  34. package/lib/types/characters/character.d.ts +20 -1
  35. package/lib/types/characters/index.d.ts +2 -0
  36. package/lib/types/characters/rig/body-plan.d.ts +3 -1
  37. package/lib/types/characters/rig/skeleton.d.ts +57 -0
  38. package/lib/types/characters/scene-objects.d.ts +2 -0
  39. package/lib/types/compat/gsap/vars.d.ts +8 -0
  40. package/lib/types/engine/core/bake.d.ts +3 -1
  41. package/lib/types/engine/index.d.ts +1 -0
  42. package/lib/types/engine/interpolation/interpolators.d.ts +10 -3
  43. package/lib/types/engine/math/index.d.ts +11 -0
  44. package/lib/types/engine/math/mat4.d.ts +37 -0
  45. package/lib/types/engine/math/quat.d.ts +39 -0
  46. package/lib/types/engine/math/vec3.d.ts +16 -0
  47. package/lib/types/engine/types.d.ts +23 -2
  48. package/lib/types/headless/index.d.ts +1 -0
  49. package/lib/types/headless/loop-check.d.ts +41 -0
  50. package/lib/types/headless/node-video.d.ts +8 -0
  51. package/lib/types/headless/video-scene.d.ts +7 -1
  52. package/lib/types/scene-3d/camera.d.ts +27 -0
  53. package/lib/types/scene-3d/canvas-2d-renderer.d.ts +21 -0
  54. package/lib/types/scene-3d/geometry/extrude.d.ts +17 -0
  55. package/lib/types/scene-3d/geometry/mesh.d.ts +36 -0
  56. package/lib/types/scene-3d/geometry/primitives.d.ts +16 -0
  57. package/lib/types/scene-3d/geometry/triangulate.d.ts +24 -0
  58. package/lib/types/scene-3d/index.d.ts +20 -0
  59. package/lib/types/scene-3d/load-scene.d.ts +31 -0
  60. package/lib/types/scene-3d/object-kind.d.ts +54 -0
  61. package/lib/types/scene-3d/resolve-scene.d.ts +122 -0
  62. package/lib/types/scene-3d/scene-3d-adapter.d.ts +46 -0
  63. package/lib/types/scene-3d/scene-types.d.ts +192 -0
  64. package/lib/types/scene-3d/shading.d.ts +20 -0
  65. package/lib/types/scene-3d/validate-scene.d.ts +11 -0
  66. package/lib/types/scene-3d/webgl/gl-data.d.ts +29 -0
  67. package/lib/types/scene-3d/webgl/index.d.ts +16 -0
  68. package/lib/types/scene-3d/webgl/shaders.d.ts +29 -0
  69. package/lib/types/scene-3d/webgl/webgl2-renderer.d.ts +33 -0
  70. package/package.json +10 -2
  71. package/lib/addons/dom-adapter-CrNwoomd.js +0 -243
@@ -1,2 +1,2 @@
1
- (function(v,N){typeof exports=="object"&&typeof module<"u"?N(exports):typeof define=="function"&&define.amd?define(["exports"],N):(v=typeof globalThis<"u"?globalThis:v||self,N(v.tinyfly=v.tinyfly||{}))})(this,(function(v){"use strict";function N(i){return typeof i=="object"&&i!==null&&i.type==="cubic-bezier"}function ee(i){return typeof i=="object"&&i!==null&&i.type!=="cubic-bezier"}const st=1;function St(i){return i.property==="text"&&"textConfig"in i}function nt(i){return i.kind==="inertia"&&"inertia"in i}function rt(i){return i.kind==="spring"&&"spring"in i}function ie(i){return i.property==="motionPath"&&"motionPathConfig"in i}function Mt(i,t,e="start"){if(t<=1)return 0;if(typeof e=="number"){const s=Math.max(0,Math.min(t-1,e));return Math.abs(i-s)}switch(e){case"end":return t-1-i;case"center":return Math.abs(i-(t-1)/2);case"edges":return(t-1)/2-Math.abs(i-(t-1)/2);default:return i}}function se(i,t="start"){if(i<=1)return 0;let e=0;for(let s=0;s<i;s++)e=Math.max(e,Mt(s,i,t));return e}function _t(i,t,e){if(e.offsets)return e.offsets[i]??0;const s=e.from??"start",n=Mt(i,t,s);if(e.amount!==void 0){const r=se(t,s);return r===0?0:e.amount*n/r}return e.each!==void 0?e.each*n:0}function ne(i,t){return Array.from({length:i},(e,s)=>_t(s,i,t))}function at(i,t){return i<=1?0:Math.max(...ne(i,t))}const Y=1,kt=6e4,z=kt/Y,F={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1};class re{from;to;stiffness;damping;mass;restDelta;restSpeed;distance;samples;velocity;settledStep=null;constructor(t){this.from=t.from,this.to=t.to,this.stiffness=t.stiffness??F.stiffness,this.damping=t.damping??F.damping,this.mass=t.mass??F.mass,this.restDelta=t.restDelta??F.restDelta,this.restSpeed=t.restSpeed??F.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=t.velocity??F.velocity,this.isAtRest(this.from)&&(this.settledStep=0)}isAtRest(t){return Math.abs(t-this.to)<this.restDelta*this.distance&&Math.abs(this.velocity)<this.restSpeed*this.distance}valueAt(t){if(t<=0)return this.from;const e=Math.floor(t/Y);if(this.simulateTo(e+1),this.settledStep!==null&&e>=this.settledStep)return this.to;const s=this.samples[Math.min(e,this.samples.length-1)],n=this.samples[Math.min(e+1,this.samples.length-1)],r=t/Y-e;return s+(n-s)*r}settleTime(){return this.simulateTo(z+1),this.settledStep!==null?this.settledStep*Y:kt}simulateTo(t){if(this.settledStep!==null)return;const e=Math.min(t,z+1),s=Y/1e3;for(;this.samples.length<e;){const n=this.samples[this.samples.length-1],r=n-this.to,a=-this.stiffness*r,o=-this.damping*this.velocity,c=(a+o)/this.mass;this.velocity+=c*s;const h=n+this.velocity*s;if(this.samples.push(h),this.isAtRest(h)){this.settledStep=this.samples.length-1;return}}this.samples.length>z&&(this.settledStep=z)}}const wt=4,ae=.002,oe=1e-4,ce=6e4;function ot(i){const t=i.friction??wt;return t>0?t:wt}function he(i){return i.from+i.velocity/ot(i)}function le(i,t){if(t===void 0)return i;if(typeof t=="number")return t>0?Math.round(i/t)*t:i;if(t.length===0)return i;let e=t[0];for(const s of t)Math.abs(s-i)<Math.abs(e-i)&&(e=s);return e}function Pt(i){let t=le(he(i),i.end);return i.min!==void 0&&(t=Math.max(i.min,t)),i.max!==void 0&&(t=Math.min(i.max,t)),t}function vt(i){const t=Math.abs(Pt(i)-i.from);if(t===0)return 0;const e=i.restDelta??Math.max(oe,t*ae);if(e>=t)return 0;const s=Math.log(t/e)/ot(i);return Math.min(ce,s*1e3)}function It(i,t){if(t<=0)return i.from;const e=Pt(i);if(t>=vt(i))return e;const s=ot(i);return i.from+(e-i.from)*(1-Math.exp(-s*t/1e3))}const ct=i=>i,ue=i=>i*i,de=i=>1-(1-i)*(1-i),fe=i=>i<.5?2*i*i:1-Math.pow(-2*i+2,2)/2,xt=i=>i*i*i,Ct=i=>1-Math.pow(1-i,3),Rt=i=>i<.5?4*i*i*i:1-Math.pow(-2*i+2,3)/2,pe={linear:ct,"ease-in":xt,"ease-out":Ct,"ease-in-out":Rt,"ease-in-quad":ue,"ease-out-quad":de,"ease-in-out-quad":fe,"ease-in-cubic":xt,"ease-out-cubic":Ct,"ease-in-out-cubic":Rt};function me(i){const[t,e,s,n]=i,r=3*t,a=3*(s-t)-r,o=1-r-a,c=3*e,h=3*(n-e)-c,u=1-c-h,l=p=>((o*p+a)*p+r)*p,d=p=>((u*p+h)*p+c)*p,f=p=>(3*o*p+2*a)*p+r,b=p=>{let y=p;for(let A=0;A<8;A++){const M=l(y)-p;if(Math.abs(M)<1e-7)return y;const m=f(y);if(Math.abs(m)<1e-7)break;y-=M/m}let g=0,T=1;for(y=p;g<T;){const A=l(y);if(Math.abs(A-p)<1e-7)return y;p>A?g=y:T=y,y=(g+T)/2}return y};return p=>{if(p<=0)return 0;if(p>=1)return 1;const y=b(p);return d(y)}}function ht(i,t="out"){if(t==="out")return i;const e=s=>1-i(1-s);return t==="in"?e:s=>s<.5?e(s*2)/2:i(s*2-1)/2+.5}function ye(i=1,t=.3){const e=Math.max(1,i),s=t/(2*Math.PI)*Math.asin(1/e);return n=>n<=0?0:n>=1?1:e*Math.pow(2,-10*n)*Math.sin((n-s)*(2*Math.PI)/t)+1}const ge=i=>{if(i<=0)return 0;if(i>=1)return 1;if(i<1/2.75)return 7.5625*i*i;if(i<2/2.75){const n=i-.5454545454545454;return 7.5625*n*n+.75}if(i<2.5/2.75){const n=i-.8181818181818182;return 7.5625*n*n+.9375}const s=i-2.625/2.75;return 7.5625*s*s+.984375};function Te(i=1.70158){return t=>{if(t<=0)return 0;if(t>=1)return 1;const e=t-1;return e*e*((i+1)*e+i)+1}}function be(i,t="end"){const e=Math.max(1,Math.floor(i));return s=>{if(s>=1)return 1;if(s<=0)return t==="start"||t==="both"?t==="start"?1/e:1/(e+1):0;const n=Math.floor(s*e);switch(t){case"start":return Math.min(1,(n+1)/e);case"both":return(n+1)/(e+1);case"none":return e===1?0:Math.min(1,n/(e-1));default:return n/e}}}function Ae(i){switch(i.type){case"steps":return be(i.count,i.position);case"elastic":return ht(ye(i.amplitude,i.period),i.mode);case"bounce":return ht(ge,i.mode);case"back":return ht(Te(i.overshoot),i.mode)}}function Se(i){return i===void 0?ct:N(i)?me(i.points):ee(i)?Ae(i):pe[i]??ct}const Dt=32,Me=256,V=new Map,_e=/[MmLlHhVvCcSsQqTtAaZz]/,ke=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,we={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function Pe(i){const t=[];let e=0,s=null;const n=()=>{for(;e<i.length&&/[\s,]/.test(i[e]);)e++};for(;e<i.length&&(n(),!(e>=i.length));){const r=i[e];if(_e.test(r)){s={type:r,args:[]},t.push(s),e++;continue}if(!s)break;const a=s.type==="A"||s.type==="a",o=s.args.length%7;if(a&&(o===3||o===4)){if(r!=="0"&&r!=="1")break;s.args.push(r==="1"?1:0),e++;continue}const c=ke.exec(i.slice(e));if(!c)break;s.args.push(parseFloat(c[0])),e+=c[0].length}return t}function ve(i,t,e,s,n,r,a,o,c){if(i===o&&t===c)return[];let h=Math.abs(e),u=Math.abs(s);if(h===0||u===0)return[[i,t,o,c,o,c]];const l=n*Math.PI/180,d=Math.cos(l),f=Math.sin(l),b=(i-o)/2,p=(t-c)/2,y=d*b+f*p,g=-f*b+d*p,T=y*y/(h*h)+g*g/(u*u);if(T>1){const w=Math.sqrt(T);h*=w,u*=w}const A=r===a?-1:1,M=h*h*u*u-h*h*g*g-u*u*y*y,m=h*h*g*g+u*u*y*y,_=A*Math.sqrt(Math.max(0,M/m)),S=_*h*g/u,B=-_*u*y/h,tt=d*S-f*B+(i+o)/2,k=f*S+d*B+(t+c)/2,C=(w,x,R,q)=>{const At=w*R+x*q,it=Math.sqrt((w*w+x*x)*(R*R+q*q)),Q=Math.acos(Math.max(-1,Math.min(1,At/it)));return w*q-x*R<0?-Q:Q},P=C(1,0,(y-S)/h,(g-B)/u);let I=C((y-S)/h,(g-B)/u,(-y-S)/h,(-g-B)/u);!a&&I>0&&(I-=2*Math.PI),a&&I<0&&(I+=2*Math.PI);const $=Math.max(1,Math.ceil(Math.abs(I)/(Math.PI/2))),bt=I/$,et=4/3*Math.tan(bt/4),Kt=w=>{const x=h*Math.cos(w),R=u*Math.sin(w);return[d*x-f*R+tt,f*x+d*R+k]},Jt=w=>{const x=-h*Math.sin(w),R=u*Math.cos(w);return[d*x-f*R,f*x+d*R]},te=[];for(let w=0;w<$;w++){const x=P+w*bt,R=x+bt,[q,At]=Kt(x),[it,Q]=w===$-1?[o,c]:Kt(R),[wi,Pi]=Jt(x),[vi,Ii]=Jt(R);te.push([q+et*wi,At+et*Pi,it-et*vi,Q-et*Ii,it,Q])}return te}function E(i,t,e,s,n){const r=1-n;return r*r*r*i+3*r*r*n*t+3*r*n*n*e+n*n*n*s}function Bt(i,t,e,s,n){const r=1-n;return 3*r*r*(t-i)+6*r*n*(e-t)+3*n*n*(s-e)}function W(i,t,e,s){return{subpath:0,type:"L",points:[e,s],startX:i,startY:t,endX:e,endY:s,length:Math.hypot(e-i,s-t)}}function G(i,t,e){const[s,n,r,a,o,c]=e,h=[0];let u=i,l=t,d=0;for(let f=1;f<=Dt;f++){const b=f/Dt,p=E(i,s,r,o,b),y=E(t,n,a,c,b);d+=Math.hypot(p-u,y-l),h.push(d),u=p,l=y}return{subpath:0,type:"C",points:[s,n,r,a,o,c],startX:i,startY:t,endX:o,endY:c,length:d,lengths:h}}function Z(i){const t=V.get(i);if(t)return t;const e=[];let s=0,n=0,r=0,a=0,o=null,c=null,h=-1;const u=new Set,l=p=>{h<0&&(h=0),p.subpath=h,e.push(p)};for(const{type:p,args:y}of Pe(i)){const g=p.toUpperCase(),T=p!==g,A=we[g];if(g==="Z"){(s!==r||n!==a)&&l(W(s,n,r,a)),h>=0&&u.add(h),s=r,n=a,o=c=null;continue}for(let M=0;M+A<=y.length;M+=A){const m=y.slice(M,M+A),_=T?s:0,S=T?n:0;let B=null,tt=null;switch(g){case"M":M===0?(s=m[0]+_,n=m[1]+S,r=s,a=n,(h<0||e[e.length-1]?.subpath===h)&&h++):(l(W(s,n,m[0]+_,m[1]+S)),s=m[0]+_,n=m[1]+S);break;case"L":l(W(s,n,m[0]+_,m[1]+S)),s=m[0]+_,n=m[1]+S;break;case"H":l(W(s,n,m[0]+_,n)),s=m[0]+_;break;case"V":l(W(s,n,s,m[0]+S)),n=m[0]+S;break;case"C":{const k=[m[0]+_,m[1]+S,m[2]+_,m[3]+S,m[4]+_,m[5]+S];l(G(s,n,k)),B=[k[2],k[3]],s=k[4],n=k[5];break}case"S":{const[k,C]=o?[2*s-o[0],2*n-o[1]]:[s,n],P=[k,C,m[0]+_,m[1]+S,m[2]+_,m[3]+S];l(G(s,n,P)),B=[P[2],P[3]],s=P[4],n=P[5];break}case"Q":case"T":{let k=s,C=n;g==="Q"?(k=m[0]+_,C=m[1]+S):c&&(k=2*s-c[0],C=2*n-c[1]);const P=g==="Q"?m[2]+_:m[0]+_,I=g==="Q"?m[3]+S:m[1]+S;l(G(s,n,[s+2/3*(k-s),n+2/3*(C-n),P+2/3*(k-P),I+2/3*(C-I),P,I])),tt=[k,C],s=P,n=I;break}case"A":{const k=m[5]+_,C=m[6]+S;let P=s,I=n;for(const $ of ve(s,n,m[0],m[1],m[2],m[3],m[4],k,C))l(G(P,I,$)),P=$[4],I=$[5];s=k,n=C;break}}o=B,c=tt}}const d=e.reduce((p,y)=>p+y.length,0),f=[];for(let p=0;p<e.length;){const y=e[p].subpath;let g=p,T=0;for(;g<e.length&&e[g].subpath===y;)T+=e[g++].length;const A=e[p],M=e[g-1],m=u.has(y)||Math.abs(M.endX-A.startX)<1e-9&&Math.abs(M.endY-A.startY)<1e-9;f.push({start:p,end:g,length:T,closed:m}),p=g}const b={segments:e,totalLength:d,subpaths:f};return V.size>=Me&&V.delete(V.keys().next().value),V.set(i,b),b}function Ie(i,t){const e=i.lengths;if(t<=0)return 0;if(t>=i.length)return 1;let s=0,n=e.length-1;for(;s<n-1;){const o=s+n>>1;e[o]<t?s=o:n=o}const r=e[n]-e[s],a=r>0?(t-e[s])/r:0;return(s+a)/(e.length-1)}function xe(i,t){if(i.type==="L"){const l=i.length>0?Math.max(0,Math.min(1,t/i.length)):0;return{x:i.startX+(i.endX-i.startX)*l,y:i.startY+(i.endY-i.startY)*l,angle:Math.atan2(i.endY-i.startY,i.endX-i.startX)*180/Math.PI}}const[e,s,n,r,a,o]=i.points,c=Ie(i,t);let h=Bt(i.startX,e,n,a,c),u=Bt(i.startY,s,r,o,c);if(Math.hypot(h,u)<1e-9){const l=c<.5?Math.min(1,c+.001):Math.max(0,c-.001),d=E(i.startX,e,n,a,l),f=E(i.startY,s,r,o,l),b=E(i.startX,e,n,a,c),p=E(i.startY,s,r,o,c);h=c<.5?d-b:b-d,u=c<.5?f-p:p-f}return{x:E(i.startX,e,n,a,c),y:E(i.startY,s,r,o,c),angle:Math.atan2(u,h)*180/Math.PI}}function Et(i,t,e=0,s=i.length){if(s<=e)return{x:0,y:0,angle:0};let n=0;for(let r=e;r<s;r++){const a=i[r];if(n+a.length>=t||r===s-1)return xe(a,t-n);n+=a.length}return{x:0,y:0,angle:0}}function Ce(i,t){const{segments:e,totalLength:s}=Z(i);return Et(e,Math.max(0,Math.min(1,t))*s)}const Re=24,De=320,Be=2.5,U=72,Ee=.2,Le=128,K=new Map;let lt=0,L;const Lt=i=>Math.round(i*100)/100;function Ot(i,t){const{segments:e,subpaths:s,totalLength:n}=Z(i);if(e.length===0)return[];if(t){const r=s.every(a=>a.closed);return[{segments:e,start:0,end:e.length,length:n,closed:r}]}return s.filter(r=>r.length>0).map(r=>({segments:e,start:r.start,end:r.end,length:r.length,closed:r.closed}))}function ut(i,t){const e=i.closed?(t%1+1)%1:Math.max(0,Math.min(1,t)),s=Et(i.segments,e*i.length,i.start,i.end);return[s.x,s.y]}function $t(i){const t=[];let e=0;for(let s=i.start;s<i.end;s++)e+=i.segments[s].length,i.length>0&&t.push(e/i.length);return t}function Ft(i,t){const e=[];for(let s=0;s<t;s++)e.push(ut(i,i.closed?s/t:s/(t-1)));return e}function Xt(i){let t=0,e=0;for(const[s,n]of i)t+=s,e+=n;return t/=i.length,e/=i.length,i.map(([s,n])=>[s-t,n-e])}function Oe(i,t,e){const s=i.closed&&t.closed;if(e!==void 0)return{offset:s?Math.abs(e)%U/U:0,reversed:e<0};const n=Xt(Ft(i,U)),r=Xt(Ft(t,U)),a=U;let o={offset:0,reversed:!1},c=1/0;for(const h of[!1,!0]){const u=s?a:1;for(let l=0;l<u;l++){let d=0;for(let f=0;f<a&&d<c;f++){const b=s?h?(l-f+a)%a:(f+l)%a:h?a-1-f:f,p=n[f][0]-r[b][0],y=n[f][1]-r[b][1];d+=p*p+y*y}d<c&&(c=d,o={offset:s?l/a:0,reversed:h})}}return o}function $e(i,t,e){return e?((t.reversed?t.offset-i:i+t.offset)%1+1)%1:t.reversed?1-i:i}function Fe(i,t,e){return e?((t.reversed?t.offset-i:i-t.offset)%1+1)%1:t.reversed?1-i:i}function Xe(i,t,e){const s=i.closed&&t.closed,n=Oe(i,t,e.shapeIndex),r=Math.max(Re,Math.min(De,Math.ceil(Math.max(i.length,t.length)/Be))),a=new Set,o=l=>a.add(Math.round(l*1e7)/1e7);for(let l=0;l<=r;l++)o(l/r);for(const l of $t(i))o(l);for(const l of $t(t))o(Fe(l,n,s));let c=[...a].sort((l,d)=>l-d);s&&(c=c.filter(l=>l<1));const h=[],u=[];for(const l of c)h.push(...ut(i,l)),u.push(...ut(t,$e(l,n,s)));return qe({from:h,to:u,closed:s})}function qe(i){const t=i.from.length/2;if(t<=3)return i;const e=new Uint8Array(t);e[0]=1,e[t-1]=1;const s=[[0,t-1]];for(;s.length>0;){const[a,o]=s.pop();let c=-1,h=Ee;for(let u=a+1;u<o;u++){const l=Math.max(qt(i.from,a,o,u),qt(i.to,a,o,u));l>h&&(h=l,c=u)}c!==-1&&(e[c]=1,s.push([a,c],[c,o]))}const n=[],r=[];for(let a=0;a<t;a++)e[a]&&(n.push(i.from[a*2],i.from[a*2+1]),r.push(i.to[a*2],i.to[a*2+1]));return{from:n,to:r,closed:i.closed}}function qt(i,t,e,s){const n=i[t*2],r=i[t*2+1],a=i[e*2]-n,o=i[e*2+1]-r,c=i[s*2]-n,h=i[s*2+1]-r,u=a*a+o*o,l=u===0?0:Math.max(0,Math.min(1,(c*a+h*o)/u));return Math.hypot(c-l*a,h-l*o)}function Ne(i,t,e){const s=e.shapeIndex;if(L&&L.from===i&&L.to===t&&L.shapeIndex===s)return L.plan;const r=K.get(String(s??"auto"))?.get(i)?.get(t);if(r)return L={from:i,to:t,shapeIndex:s,plan:r},r;const a=Z(i).subpaths.filter(f=>f.length>0).length===Z(t).subpaths.filter(f=>f.length>0).length,o=Ot(i,!a),c=Ot(t,!a),h={pairs:o.map((f,b)=>Xe(f,c[b],e))};lt>=Le&&(K.clear(),lt=0);const u=String(s??"auto"),l=K.get(u)??new Map;K.set(u,l);const d=l.get(i)??new Map;return l.set(i,d),d.set(t,h),lt++,L={from:i,to:t,shapeIndex:s,plan:h},h}function Ye(i,t,e,s={}){if(!i)return t;if(!t)return i;const n=Math.max(0,Math.min(1,e));if(n===0)return i;if(n===1)return t;const r=Ne(i,t,s);if(r.pairs.length===0)return n<.5?i:t;let a="";for(const o of r.pairs){for(let c=0;c<o.from.length;c+=2){const h=Lt(o.from[c]+(o.to[c]-o.from[c])*n),u=Lt(o.from[c+1]+(o.to[c+1]-o.from[c+1])*n);a+=`${c===0?a?" M":"M":" L"}${h} ${u}`}o.closed&&(a+=" Z")}return a}function Ve(i){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(i)}const D=(i,t,e)=>i+(t-i)*e,Nt=512,dt=new Map,ft=new Map;function Yt(i){const t=dt.get(i);if(t)return t;const e=i.replace("#",""),s=[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)];return dt.size<Nt&&dt.set(i,s),s}const Vt=i=>i.charCodeAt(0)===35,Wt=i=>i.startsWith("rgb"),Ut=i=>i.startsWith("rgba"),We=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,pt=i=>Math.round(i).toString(16).padStart(2,"0");function Ue(i,t,e){return`#${pt(i)}${pt(t)}${pt(e)}`}function Ht(i){const t=ft.get(i);if(t)return t;const e=i.match(We);if(!e)throw new Error(`Invalid rgb color: ${i}`);const s=parseInt(e[1],10),n=parseInt(e[2],10),r=parseInt(e[3],10),a=e[4]!==void 0?[s,n,r,parseFloat(e[4])]:[s,n,r];return ft.size<Nt&&ft.set(i,a),a}const He=(i,t,e)=>{if(Vt(i)&&Vt(t)){const[s,n,r]=Yt(i),[a,o,c]=Yt(t),h=D(s,a,e),u=D(n,o,e),l=D(r,c,e);return Ue(h,u,l)}if((Wt(i)||Ut(i))&&(Wt(t)||Ut(t))){const s=Ht(i),n=Ht(t),r=Math.round(D(s[0],n[0],e)),a=Math.round(D(s[1],n[1],e)),o=Math.round(D(s[2],n[2],e));if(s.length===4||n.length===4){const c=s[3]??1,h=n[3]??1,u=D(c,h,e);return`rgba(${r}, ${a}, ${o}, ${u})`}return`rgb(${r}, ${a}, ${o})`}return e<1?i:t},je=(i,t,e)=>{const s=Math.min(i.length,t.length),n=[];for(let r=0;r<s;r++)n.push(D(i[r],t[r],e));return n},jt=(i,t,e)=>e<1?i:t,Qe=(i,t,e)=>Ye(i,t,e);function ze(i){return typeof i=="number"?D:Array.isArray(i)?je:typeof i=="string"?i.startsWith("#")||i.startsWith("rgb")?He:Ve(i)?Qe:jt:jt}function Ge(i){const t=[...i.keyframes].sort((e,s)=>e.time-s.time);return{...i,keyframes:t}}function O(i){return i.targets&&i.targets.length>0?i.targets:[i.target]}function X(i,t,e,s){const n=e??0;return!s||t<=1?n:n+_t(i,t,s)}class mt{track;targets;constructor(t){this.track=t,this.targets=O(t)}getValueAtTime(t){return this.valueForOffset(t-X(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=X(n,e,this.track.delay,this.track.stagger),a=this.valueForOffset(t-r);a!==void 0&&s.push({target:this.targets[n],value:a,start:r+this.track.keyframes[0].time})}return s}getDuration(){const{keyframes:t}=this.track;if(t.length===0)return 0;const e=t[t.length-1].time,s=this.track.stagger?at(this.targets.length,this.track.stagger):0;return e+(this.track.delay??0)+s+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(t){const{keyframes:e}=this.track;if(e.length===0)return;if(e.length===1||t<=e[0].time)return e[0].value;if(t>=e[e.length-1].time)return e[e.length-1].value;const{from:s,to:n}=this.findSurroundingKeyframes(t);if(!s||!n)return;if(s.time===t)return s.value;const r=n.time-s.time,a=(t-s.time)/r,c=Se(n.easing)(a);return ze(s.value)(s.value,n.value,c)}findSurroundingKeyframes(t){const{keyframes:e}=this.track;for(let s=0;s<e.length-1;s++)if(t>=e[s].time&&t<=e[s+1].time)return{from:e[s],to:e[s+1]};return{from:null,to:null}}}class Ze{track;targets;sampler;constructor(t){this.track=t,this.targets=O(t),this.sampler=new re(t.spring)}getValueAtTime(t){return this.sampler.valueAt(t-X(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=X(n,e,this.track.delay,this.track.stagger);s.push({target:this.targets[n],value:this.sampler.valueAt(t-r),start:r})}return s}getDuration(){const t=this.track.stagger?at(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+t}getTrack(){return this.track}}class Ke{track;targets;duration;constructor(t){this.track=t,this.targets=O(t),this.duration=vt(t.inertia)}getValueAtTime(t){return It(this.track.inertia,t-X(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=X(n,e,this.track.delay,this.track.stagger);s.push({target:this.targets[n],value:It(this.track.inertia,t-r),start:r})}return s}getDuration(){const t=this.track.stagger?at(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+t}getTrack(){return this.track}}function Je(i,t){const e={...Ce(i.pathData,t)};if(i.matrix){const[s,n,r,a,o,c]=i.matrix,{x:h,y:u}=e;e.x=s*h+r*u+o,e.y=n*h+a*u+c;const l=e.angle*Math.PI/180,d=Math.cos(l),f=Math.sin(l);e.angle=Math.atan2(n*d+a*f,s*d+r*f)*180/Math.PI}return i.autoRotate&&i.rotateOffset&&(e.angle+=i.rotateOffset),e}const yt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},ti=20;function ei(i){const t=yt[i??"upperCase"]??i??yt.upperCase,e=Array.from(t);return e.length>0?e:Array.from(yt.upperCase)}function ii(i,t,e){let s=(i|0)^Math.imul(t+1,2654435761)^Math.imul(e+1,2246822507);return s=Math.imul(s^s>>>16,2146121005),s=Math.imul(s^s>>>15,2221713035),(s^s>>>16)>>>0}function si(i,t,e=0){const s=i.from??"",n=i.to,r=Math.max(0,Math.min(1,t));if(r<=0)return s;if(r>=1)return n;const a=Array.from(s),o=Array.from(n),c=i.rightToLeft??!1;if(i.mode==="type"){const T=Math.round(r*Math.max(a.length,o.length));return c?a.slice(0,Math.max(0,a.length-T)).join("")+o.slice(Math.max(0,o.length-T)).join(""):o.slice(0,T).join("")+a.slice(T).join("")}const h=Math.max(0,Math.min(.999,i.revealDelay??0)),u=Math.max(0,(r-h)/(1-h)),l=Math.floor(u*o.length),d=i.tweenLength===!1?o.length:Math.round(a.length+(o.length-a.length)*r),f=ei(i.chars),b=i.refreshRate??ti,p=b>0?Math.floor(e*b/1e3):0,y=i.seed??1;let g="";for(let T=0;T<d;T++){const A=c?T>=d-l:T<l,M=c?o[o.length-(d-T)]:o[T];A&&M!==void 0||M===" "||M===`
2
- `?g+=M:g+=f[ii(y,T,p)%f.length]}return g}class ni{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(t){if(this.id=t.id,this.name=t.name,this._captions=t.captions,this._config=t.config??{},this._explicitDuration=t.config?.duration,t.tracks)for(const e of t.tracks)this.addTrack(e)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(t){if(this._explicitDuration=t,t!==void 0)this._config={...this._config,duration:t};else if(this._config.duration!==void 0){const e={...this._config};delete e.duration,this._config=e}}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(t){this._config.speed=t}play(){const t=this.duration;this._direction==="forward"&&this._currentTime>=t&&t>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&t>0&&(this._currentTime=t,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(t){const e=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(t,e)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(t){if(this._playbackState!=="playing")return;const e=this.duration;if(e<=0)return;let n=t*this.speed;if(this._repeatDelayRemaining>0){const o=Math.min(this._repeatDelayRemaining,n);if(this._repeatDelayRemaining-=o,n-=o,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const r=1e3;for(let o=0;o<r&&n>0&&this._playbackState==="playing";o++)if(this._direction==="forward"){const c=e-this._currentTime;if(n>=c){if(n-=c,this._currentTime=e,!this._handleEndReached())break}else this._currentTime+=n,n=0}else{const c=this._currentTime;if(n>=c){if(n-=c,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=n,n=0}const a=this.getStateAtTime(this._currentTime);this.onUpdate?.(a)}getStateAtTime(t){const e=new Map;if(this._hasSharedWrites())this._resolveShared(t,e);else for(const[s,n]of this._trackPlayers){const r=n.getTrack().property;for(const{target:a,value:o,start:c}of n.getTargetValues(t))this._write(e,s,a,r,o,t-c)}return{values:e,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(t,e){const s=new Map;for(const[n,r]of this._trackPlayers){const a=r.getTrack().property;for(const{target:o,value:c,start:h}of r.getTargetValues(t)){const u=`${o}\0${a}`,l=h<=t,d=s.get(u);(!d||(l!==d.started?l:l?h>=d.start:h<=d.start))&&s.set(u,{trackId:n,target:o,property:a,value:c,start:h,started:l})}}for(const{trackId:n,target:r,property:a,value:o,start:c}of s.values())this._write(e,n,r,a,o,t-c)}_write(t,e,s,n,r,a){if(r===void 0)return;let o=t.get(s);o||(o=new Map,t.set(s,o));const c=this._textTracks.get(e);if(c&&typeof r=="number"){o.set("text",si(c.textConfig,r,Math.max(0,a)));return}const h=this._motionPathTracks.get(e);if(h&&typeof r=="number"){const u=Je(h.motionPathConfig,r);o.set("motionPathX",u.x),o.set("motionPathY",u.y),h.motionPathConfig.autoRotate&&o.set("motionPathRotate",u.angle)}else o.set(n,r)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const t=new Set;this._sharedWrites=!1;t:for(const e of this._tracks)for(const s of O(e)){const n=`${s}\0${e.property}`;if(t.has(n)){this._sharedWrites=!0;break t}t.add(n)}}return this._sharedWrites}addTrack(t){if(this._tracks.push(t),this._sharedWrites=null,nt(t)){this._trackPlayers.set(t.id,new Ke(t));return}if(rt(t)){this._trackPlayers.set(t.id,new Ze(t)),this._springTracks.set(t.id,t);return}if(St(t))this._trackPlayers.set(t.id,new mt(t)),this._textTracks.set(t.id,t);else if(ie(t)){const e={id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,delay:t.delay,endDelay:t.endDelay,targets:t.targets,stagger:t.stagger};this._trackPlayers.set(t.id,new mt(e)),this._motionPathTracks.set(t.id,t)}else this._trackPlayers.set(t.id,new mt(t))}replaceTrack(t,e){const s=this._tracks.findIndex(r=>r.id===t);if(s<0)return;const n=this._tracks.slice(s+1);this.removeTrack(t);for(const r of n)this.removeTrack(r.id);this.addTrack(e);for(const r of n)this.addTrack(r)}removeTrack(t){this._tracks=this._tracks.filter(e=>e.id!==t),this._sharedWrites=null,this._trackPlayers.delete(t),this._motionPathTracks.delete(t),this._springTracks.delete(t),this._textTracks.delete(t)}getTracks(t={}){return this._tracks.filter(e=>this._matches(e,t))}removeTracks(t={}){const e=this.getTracks(t).map(s=>s.id);for(const s of e)this.removeTrack(s);return e}getTrackSpan(t){const e=this._trackPlayers.get(t);if(!e)return;const s=e.getTrack(),n=s.delay??0;if(rt(s)||nt(s))return{from:n,to:e.getDuration()};const r=s.keyframes;if(!(!r||r.length===0))return{from:r[0].time+n,to:e.getDuration()}}findConflicts(){const t=[];for(let e=0;e<this._tracks.length;e++){const s=this._tracks[e],n=this.getTrackSpan(s.id);if(n)for(let r=0;r<e;r++){const a=this._tracks[r];if(a.property!==s.property)continue;const o=O(a).filter(l=>O(s).includes(l));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=n.to&&n.from<=c.to))continue;const u=n.from>=c.from;for(const l of o)t.push({target:l,property:s.property,losingTrackId:u?a.id:s.id,winningTrackId:u?s.id:a.id})}}return t}_matches(t,e){if(e.id!==void 0&&t.id!==e.id||e.property!==void 0&&t.property!==e.property||e.target!==void 0&&!O(t).includes(e.target))return!1;if(e.timeRange){const s=this.getTrackSpan(t.id);if(!s||s.to<e.timeRange.from||s.from>e.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:st,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((t,e)=>t.time-e.time)}setMarkers(t){const e=t&&t.length>0?[...t].sort((n,r)=>n.time-r.time).map(n=>({...n})):void 0,s={...this._config};e?s.markers=e:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(t){const e={};for(const[s,n]of Object.entries(t??{}))e[s]={...n};this._captions=Object.keys(e).length>0?e:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let t=0;for(const[,e]of this._trackPlayers)t=Math.max(t,e.getDuration());return t}_handleEndReached(){const t=this._config.loop??0;return t===-1||this._loopIteration<t?(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 t=this._config.loop??0;return this._config.alternate&&(t===-1||this._loopIteration<t)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const ri=100;function ai(i,t,e,s){const n=[],r=[],{duration:a,alternate:o}=s,c=(f,b,p,y)=>{r.push([f,b]);const g=[];i.forEach((T,A)=>{(p==="forward"?(y?T>=f:T>f)&&T<=b:(y?T<=f:T<f)&&T>=b)&&g.push(A)}),g.sort((T,A)=>(p==="forward"?i[T]-i[A]:i[A]-i[T])||T-A);for(const T of g)n.push({kind:"event",index:T,direction:p})};let h=t.time,u=t.direction,l=t.fresh===!0;const d=Math.min(ri,Math.max(0,e.iteration-t.iteration));for(let f=0;f<d;f++){const b=u==="forward"?a:0;c(h,b,u,l),n.push({kind:"repeat"}),o?(u=u==="forward"?"reverse":"forward",h=b,l=!1):(h=u==="forward"?0:a,l=!0)}return d>0&&s.holding&&!o?{crossings:n,passes:r}:(c(h,e.time,u,l),{crossings:n,passes:r})}function oi(i){return{...i,...Array.isArray(i.end)&&{end:[...i.end]}}}function H(i){const t=i.endDelay;return{...i.delay!==void 0&&{delay:i.delay},...t!==void 0&&{endDelay:t},...i.targets!==void 0&&{targets:[...i.targets]},...i.stagger!==void 0&&{stagger:{...i.stagger}}}}function ci(i){if(nt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:oi(t.inertia),...H(t)}}if(rt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...H(t)}}if(St(i)){const t=i;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((e,s)=>e.time-s.time),...H(t)}}if(i.property==="motionPath"&&"motionPathConfig"in i){const t=i,e=[...t.keyframes].sort((s,n)=>s.time-n.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:e,...H(t)}}return Ge({id:i.id,target:i.target,property:i.property,keyframes:i.keyframes,...H(i)})}function J(i){const t=i.formatVersion??1;if(t>st)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${st}. Update tinyfly to play it.`);return new ni({id:i.id,name:i.name,config:i.config,tracks:i.tracks.map(ci),captions:i.captions})}const hi=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),li="#ffffff",ui="rgba(0, 0, 0, 0.5)";function di(i){const t=[];if(i.blur!==void 0&&t.push(`blur(${Math.max(0,i.blur)}px)`),i.brightness!==void 0&&t.push(`brightness(${Math.max(0,i.brightness)})`),i.glow!==void 0&&t.push(`drop-shadow(0 0 ${Math.max(0,i.glow)}px ${i.glowColor??li})`),i.shadowX!==void 0||i.shadowY!==void 0||i.shadowBlur!==void 0){const e=i.shadowX??0,s=i.shadowY??0,n=Math.max(0,i.shadowBlur??0);t.push(`drop-shadow(${e}px ${s}px ${n}px ${i.shadowColor??ui})`)}return t.length>0?t.join(" "):null}function fi(i,t){const e=i.childNodes.length===1?i.firstChild:null;if(e&&e.nodeType===3){const s=e;s.data!==t&&(s.data=t);return}i.textContent!==t&&(i.textContent=t)}function pi(i){if(!("ownerSVGElement"in i))return;const t=i.style;!t||t.transformBox||(t.transformBox="fill-box",t.transformOrigin||(t.transformOrigin="50% 50%"))}const Qt=new Set(["width","height","top","right","bottom","left","margin","marginTop","marginRight","marginBottom","marginLeft","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","borderRadius","borderWidth","fontSize","lineHeight","letterSpacing","outlineWidth","gap","rowGap","columnGap"]),mi=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","motionPathX","motionPathY","motionPathRotate"]),yi=new Set(["originX","originY"]),gi=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Ti=new Set(["drawOn"]),bi={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},zt={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},Ai="http://www.w3.org/2000/svg";class j{targets=new Map;registerTarget(t,e){this.targets.set(t,e)}unregisterTarget(t){this.targets.delete(t)}getTarget(t){return this.targets.get(t)}clearTargets(){this.targets.clear()}applyState(t){for(const[e,s]of t.values){const n=this.targets.get(e);n&&this.applyProperties(n,s)}}applyProperties(t,e){const s=[];let n=null,r=null,a=null;const o=e.has("motionPathX"),c=e.has("motionPathY"),h=e.has("motionPathRotate");for(const[d,f]of e)if(!(d==="x"&&o)&&!(d==="y"&&c)&&!((d==="rotate"||d==="rotateZ")&&h)&&!Ti.has(d)){if(mi.has(d)){const b=this.buildTransformPart(d,f);b&&s.push(b)}else if(yi.has(d))typeof f=="number"&&((n??={})[d]=f);else if(gi.has(d))typeof f=="number"&&((r??={})[d]=f);else if(hi.has(d))(a??={})[d]=f;else if(d!=="perspective"){if(d!=="shine")if(d==="text"&&typeof f=="string")fi(t,f);else if(d==="d"&&typeof f=="string"){const b=t;(b.tagName?.toLowerCase()==="path"?b:b.querySelector?.("path"))?.setAttribute?.("d",f)}else this.applyStyleProperty(t,d,f)}}const u=e.get("shine");typeof u=="number"&&this.applyShine(t,u);const l=e.get("perspective");if(typeof l=="number"&&s.unshift(`perspective(${l}px)`),s.length>0&&(t.style.transform=s.join(" "),pi(t)),n){const d=n.originX??50,f=n.originY??50;t.style.transformOrigin=`${d}% ${f}%`}if(r){const d=r.clipTop??0,f=r.clipRight??0,b=r.clipBottom??0,p=r.clipLeft??0;t.style.clipPath=`inset(${d}% ${f}% ${b}% ${p}%)`}if(a){const d=di(a);d&&(t.style.filter=d)}}buildTransformPart(t,e){if(typeof e!="number")return null;switch(t){case"x":case"motionPathX":return`translateX(${e}px)`;case"y":case"motionPathY":return`translateY(${e}px)`;case"z":return`translateZ(${e}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${e}deg)`;case"rotateX":return`rotateX(${e}deg)`;case"rotateY":return`rotateY(${e}deg)`;case"scale":return`scale(${e})`;case"scaleX":return`scaleX(${e})`;case"scaleY":return`scaleY(${e})`;case"scaleZ":return`scaleZ(${e})`;case"skewX":return`skewX(${e}deg)`;case"skewY":return`skewY(${e}deg)`;default:return null}}applyShine(t,e){t.dataset.shineBase||(t.dataset.shineBase=t.style.color||"currentColor");const s=t.dataset.shineBase,n=-20+e*140,r=t.style;r.color="transparent",r.backgroundImage=`linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${s}, ${s})`,r.backgroundSize="250% 100%, 100% 100%",r.backgroundPosition=`${n}% 0, 0 0`,r.backgroundRepeat="no-repeat",r.webkitBackgroundClip="text",r.backgroundClip="text"}applyStyleProperty(t,e,s){let n;if(t.namespaceURI===Ai&&e in zt){const o=Array.isArray(s)?s.join(", "):String(s);t.style[zt[e]]=o;return}else e==="fill"&&t.dataset?.elementType==="text"?n="color":n=bi[e]??e;let a;typeof s=="number"?Qt.has(e)||Qt.has(n)?a=`${s}px`:a=String(s):Array.isArray(s)?a=s.join(", "):a=s,t.style[n]=a}}class gt{media;offset;driftTolerance;constructor(t,e={}){this.media=t,this.offset=e.offset??0,this.driftTolerance=Math.max(0,e.driftTolerance??.15)}targetTime(t){return Math.max(0,t/1e3+this.offset)}update(t,e){const s=this.targetTime(t);e?(this.media.paused&&this.safePlay(),Math.abs(this.media.currentTime-s)>this.driftTolerance&&(this.media.currentTime=s)):(this.media.paused||this.media.pause(),this.media.currentTime!==s&&(this.media.currentTime=s))}seek(t){this.media.currentTime=this.targetTime(t)}setRate(t){this.media.playbackRate=t}dispose(){this.media.paused||this.media.pause()}safePlay(){const t=this.media.play();t&&typeof t.catch=="function"&&t.catch(()=>{})}}function Gt(i,t,e,s,n){const r=e-n;if(r<0){t.paused||t.pause(),t.currentTime=0;return}i.update(r,s)}class Tt{container;timeline=null;adapter;animationFrameId;lastTime;options;targets={};isDestroyed=!1;mediaSync;mediaTargets=[];symbolInstances=[];scenarioList=[];scenarioId;authored=new Map;markerList=[];listeners=new Set;playhead={time:0,iteration:0,direction:"forward"};stepping=!1;lastMarkerId=null;reducedQuery;onReducedChange=()=>this.applyReducedMotion();visibilityObserver;onScreen=!0;pausedByVisibility=!1;autoplayWhenSeen=!1;onDocumentVisibility=()=>this.updateVisibility();constructor(t,e={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=e,this.adapter=new j}async load(t){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(t)}async loadSource(t){let e;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load animation: ${s.statusText}`);e=await s.json()}else e=t;this.useDefinition(e),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(t){const e={...t.config};this.options.speed!==void 0&&(e.speed=this.options.speed),this.options.loop!==void 0&&(e.loop=this.options.loop),this.options.alternate!==void 0&&(e.alternate=this.options.alternate),this.timeline=J({...t,config:e}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(t,e={}){if(t.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const s=new Set;for(const r of t){if(s.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);s.add(r.id)}const n=e.initial===void 0?t[0]:t.find(r=>r.id===e.initial);if(!n)throw new Error(`tinyfly: there is no scenario "${e.initial}"`);this.scenarioList=[...t],this.scenarioId=n.id,await this.loadSource(n.timeline)}get scenarios(){return this.scenarioList.map(t=>({id:t.id,label:t.label??t.id}))}get scenario(){return this.scenarioId}setScenario(t){const e=this.scenarioList.find(o=>o.id===t);if(!e||!this.timeline)return!1;if(t===this.scenarioId)return!0;const s=this.isPlaying,n=this.currentTime>=this.duration-.5,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=t,this.useDefinition(e.timeline),this.lastMarkerId=null;let a=0;return this.reducedMotion||n?a=this.duration:r!==void 0&&(a=this.markers.find(o=>o.id===r)?.time??0),this.seek(a),s&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(t){if(this.authored.has(t))return;const e={style:t.getAttribute("style")};t.children.length===0&&(e.text=t.textContent??"");const s=t.tagName.toLowerCase()==="path"?t:t.querySelector("path");s&&(e.path={element:s,d:s.getAttribute("d")}),this.authored.set(t,e)}restoreAuthored(){for(const[t,e]of this.authored){e.style===null?t.removeAttribute("style"):t.setAttribute("style",e.style),e.text!==void 0&&t.textContent!==e.text&&(t.textContent=e.text),e.path&&(e.path.d===null?e.path.element.removeAttribute("d"):e.path.element.setAttribute("d",e.path.d));const s=t.dataset;s&&delete s.shineBase}}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notify(){for(const t of this.listeners)t()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const t=this.currentTime;let e;for(const s of this.markers)if(s.time<=t+.5)e=s;else break;return e}caption(t,e){const s=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!s)return;const n=e??this.language(),r=a=>a?.[n]?.[s.id]??a?.[n.split("-")[0]]?.[s.id];return r(this.options.captions)??r(this.timeline?.captions)??s.label}next(){if(!this.timeline)return;const t=this.currentTime,e=this.markers.find(s=>s.time>t+.5);if(this.reducedMotion){this.seek(e?e.time:this.duration);return}t>=this.duration-.5||(this.stepping=e!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const t=this.currentTime,e=[...this.markers].reverse().find(s=>s.time<t-.5);this.pause(),this.seek(e?e.time:0)}goToMarker(t){const e=this.markers.find(s=>s.id===t);e&&(this.pause(),this.seek(e.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const t=this.options.initialFrame??"start";if(t==="none")return;const e=t==="end"?this.timeline.duration:t==="start"?0:t;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,e))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(e=>{for(const s of e)this.onScreen=s.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const t=this.container.getBoundingClientRect?.();t&&(t.width>0||t.height>0)&&(this.onScreen=t.bottom>0&&t.top<window.innerHeight&&t.right>0&&t.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const t=this.onScreen&&document.visibilityState!=="hidden";!t&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):t&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const t=this.currentMarker,e=t?.id;e!==this.lastMarkerId&&(this.lastMarkerId=e,this.options.onMarker(t))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(e=>{const s=e,n=Number(s.getAttribute("data-tinyfly-start")??"0")||0,r=s.getAttribute("data-volume");r!==null&&(s.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:s,startTime:n,sync:new gt(s)})})}syncAllMedia(t,e){for(const s of this.mediaTargets)Gt(s.sync,s.el,t,e,s.startTime)}loadFromString(t){const e=JSON.parse(t);this.load(e)}registerTarget(t,e){if(typeof e=="string"){const s=this.container.querySelector(e);s&&(this.rememberAuthored(s),this.targets[t]=s,this.adapter.registerTarget(t,s))}else this.rememberAuthored(e),this.targets[t]=e,this.adapter.registerTarget(t,e)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(e=>{const s=e.closest("[data-tinyfly-symbol]");if(s&&s!==e)return;const n=e.getAttribute("data-tinyfly");n&&this.registerTarget(n,e)}),this.timeline&&new Set(this.timeline.tracks.map(s=>s.target)).forEach(s=>{if(!this.targets[s]){const n=this.container.querySelector(`[data-tinyfly="${s}"]`)||this.container.querySelector(`.${s}`)||this.container.querySelector(`#${s}`);n&&this.registerTarget(s,n)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const e=new Map(t.map(s=>[s.id,s]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const n=s.getAttribute("data-tinyfly-symbol");if(!n)return;const r=e.get(n);if(!r||!r.timeline.tracks?.length)return;const a=new j;s.querySelectorAll("[data-tinyfly]").forEach(o=>{const c=o.getAttribute("data-tinyfly");c&&a.registerTarget(c,o)}),this.symbolInstances.push({adapter:a,timeline:J(r.timeline)})})}attachMedia(t,e){this.mediaSync=new gt(t,e),this.timeline&&(this.mediaSync.setRate(this.timeline.speed),this.mediaSync.update(this.timeline.currentTime,this.isPlaying))}detachMedia(){this.mediaSync?.dispose(),this.mediaSync=void 0}play(){!this.timeline||this.isDestroyed||(this.autoplayWhenSeen=!1,this.stepping=this.options.stepMode===!0,this.startPlaying())}startPlaying(){if(!this.timeline||this.isDestroyed)return;const t=this.timeline.playbackState==="idle";this.timeline.play(),t&&this.timeline.currentTime===0&&this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.update(this.timeline.currentTime,!0),this.syncAllMedia(this.timeline.currentTime,!0),this.startAnimationLoop(),this.notify()}pause(){this.timeline&&(this.stepping=!1,this.timeline.pause(),this.notify(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1),this.stopAnimationLoop())}stop(){this.timeline&&(this.timeline.stop(),this.stopAnimationLoop(),this.applyState(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1))}seek(t){this.timeline&&(this.timeline.seek(t),this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.seek(this.timeline.currentTime),this.syncAllMedia(this.timeline.currentTime,this.isPlaying))}setSpeed(t){this.timeline&&(this.timeline.speed=t,this.mediaSync?.setRate(t))}reverse(){this.timeline&&this.timeline.reverse()}get currentTime(){return this.timeline?.currentTime??0}get duration(){return this.timeline?.duration??0}get isPlaying(){return this.timeline?.playbackState==="playing"}destroy(){this.isDestroyed=!0,this.stopAnimationLoop(),this.reducedQuery?.removeEventListener?.("change",this.onReducedChange),this.visibilityObserver?.disconnect(),typeof document<"u"&&document.removeEventListener("visibilitychange",this.onDocumentVisibility),this.mediaSync?.dispose(),this.mediaSync=void 0;for(const t of this.mediaTargets)t.el.paused||t.el.pause();this.mediaTargets=[],this.adapter.clearTargets();for(const t of this.symbolInstances)t.adapter.clearTargets();this.symbolInstances=[],this.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=e=>{if(this.isDestroyed||!this.timeline)return;const s=e-(this.lastTime??e);this.lastTime=e;const n=this.playhead;this.timeline.tick(s),this.stopAtMarker(n),this.applyState();const r=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,r),this.syncAllMedia(this.timeline.currentTime,r),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(t):(this.animationFrameId=void 0,this.notify())};this.animationFrameId=requestAnimationFrame(t)}stopAtMarker(t){const e=this.timeline,s={time:e.currentTime,iteration:e.loopIteration,direction:e.direction};this.playhead=s;const n=this.markers;if(n.length===0)return;const{crossings:r}=ai(n.map(a=>a.time),t,s,{duration:e.duration,alternate:e.config.alternate===!0,holding:e.repeatDelayRemaining>0});for(const a of r){if(a.kind!=="event")continue;const o=n[a.index];if(this.stepping||o.pause){this.stepping=!1,e.pause(),e.seek(o.time),this.playhead={time:o.time,iteration:e.loopIteration,direction:e.direction};return}}}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}applyState(){if(!this.timeline)return;const t=this.timeline.currentTime;this.adapter.applyState(this.timeline.getStateAtTime(t)),this.announceMarker(),this.notify();for(const e of this.symbolInstances){const s=e.timeline.duration;e.adapter.applyState(e.timeline.getStateAtTime(s>0?t%s:t))}}}async function Si(i,t,e={}){const s=new Tt(i,{...e,autoplay:!0});return await s.load(t),s}function Mi(i,t={}){return new Tt(i,t)}class Zt{container;containerA;containerB;adapterA;adapterB;timelineA=null;timelineB=null;symbolDefs=new Map;nestedByAdapter=new Map;sequence=null;options;_currentSceneIndex=0;_state="idle";_isPlaying=!1;_isDestroyed=!1;loopIteration=0;animationFrameId;lastTime;transitionTimer;constructor(t,e={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=e,this.container.style.position="relative",this.container.style.overflow="hidden",this.containerA=this.createSceneContainer(),this.containerB=this.createSceneContainer(),this.container.appendChild(this.containerA),this.container.appendChild(this.containerB),this.containerB.style.visibility="hidden",this.adapterA=new j,this.adapterB=new j}async load(t){let e;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load sequence: ${s.statusText}`);e=await s.json()}else e=t;this.sequence=e,this.symbolDefs.clear();for(const s of e.symbols??[])s.timeline?.tracks?.length&&this.symbolDefs.set(s.id,s.timeline);this.container.style.width=`${e.canvas.width}px`,this.container.style.height=`${e.canvas.height}px`,e.scenes.length>0&&(this.renderScene(e.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(e.scenes[0])),this.options.autoplay&&this.play()}play(){if(!(!this.sequence||this._isDestroyed)&&this.sequence.scenes.length!==0){if(this._isPlaying=!0,this._state==="idle"){if(this._state="playing-scene",this._currentSceneIndex=0,this.timelineA)this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play();else{this.onSceneComplete();return}this.options.onSceneChange?.(0)}else this._state==="playing-scene"&&this.timelineA&&this.timelineA.play();this.startAnimationLoop()}}pause(){this._isPlaying&&(this._isPlaying=!1,this.timelineA&&this.timelineA.pause(),this.timelineB&&this.timelineB.pause(),this.stopAnimationLoop())}stop(){if(this._isPlaying=!1,this._state="idle",this._currentSceneIndex=0,this.loopIteration=0,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.stopAnimationLoop(),this.sequence&&this.sequence.scenes.length>0&&(this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this.renderScene(this.sequence.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(this.sequence.scenes[0]),this.timelineA)){const t=this.timelineA.getStateAtTime(0);this.adapterA.applyState(t),this.applyNested(this.adapterA,0)}}goToScene(t){if(!this.sequence||t<0||t>=this.sequence.scenes.length)return;const e=this._isPlaying;this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this._currentSceneIndex=t,this._state=e?"playing-scene":"idle",this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB);const s=this.sequence.scenes[t];if(this.renderScene(s,this.containerA,this.adapterA),this.timelineA=this.createTimeline(s),this.options.onSceneChange?.(t),e)this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play(),this.startAnimationLoop()):this.onSceneComplete();else if(this.timelineA){const n=this.timelineA.getStateAtTime(0);this.adapterA.applyState(n),this.applyNested(this.adapterA,0)}}destroy(){this._isDestroyed=!0,this._isPlaying=!1,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.adapterA.clearTargets(),this.adapterB.clearTargets();for(const t of this.nestedByAdapter.values())for(const e of t)e.adapter.clearTargets();this.nestedByAdapter.clear(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.timelineA=null,this.timelineB=null,this.containerA.parentNode&&this.containerA.remove(),this.containerB.parentNode&&this.containerB.remove(),this.sequence=null}get currentSceneIndex(){return this._currentSceneIndex}get sceneCount(){return this.sequence?.scenes.length??0}get isPlaying(){return this._isPlaying}get state(){return this._state}createSceneContainer(){const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.width="100%",t.style.height="100%",t}renderScene(t,e,s){e.innerHTML="",s.clearTargets();const n=document.createElement("div");n.style.cssText="position:absolute;inset:0;transform-origin:center center",n.setAttribute("data-tinyfly","Camera"),e.appendChild(n),s.registerTarget("Camera",n);for(const r of t.elements){if(!r.html)continue;const a=document.createElement("div");a.innerHTML=r.html.trim();const o=a.firstElementChild;if(o){n.appendChild(o);const c=o.getAttribute("data-tinyfly");c&&s.registerTarget(c,o)}}this.setupNested(n,s)}setupNested(t,e){const s=[];t.querySelectorAll("[data-tinyfly-symbol]").forEach(n=>{const r=n.getAttribute("data-tinyfly-symbol");if(!r)return;const a=this.symbolDefs.get(r);if(!a)return;const o=new j;n.querySelectorAll("[data-tinyfly]").forEach(c=>{const h=c.getAttribute("data-tinyfly");h&&o.registerTarget(h,c)}),s.push({adapter:o,timeline:J(a)})}),s.length?this.nestedByAdapter.set(e,s):this.nestedByAdapter.delete(e)}applyNested(t,e){const s=this.nestedByAdapter.get(t);if(s)for(const n of s){const r=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(r>0?e%r:e))}}clearContainer(t){t.innerHTML=""}createTimeline(t){return t.timeline?J(t.timeline):null}onSceneComplete(){if(this._isDestroyed||!this.sequence)return;const t=this._currentSceneIndex+1;if(t>=this.sequence.scenes.length){const e=this.options.loop??this.sequence.loop??0;e===-1||e>0&&this.loopIteration<e-1?(this.loopIteration++,this.beginTransitionTo(0)):(this._isPlaying=!1,this._state="idle",this.stopAnimationLoop(),this.options.onComplete?.())}else this.beginTransitionTo(t)}beginTransitionTo(t){if(!this.sequence||this._isDestroyed)return;const e=this.sequence.scenes[t],s=e.transition;if(s.type==="none"||s.duration<=0){this.switchToScene(t);return}this._state="transitioning",this.containerB.style.visibility="visible",this.renderScene(e,this.containerB,this.adapterB),this.timelineB=this.createTimeline(e),this.timelineB&&this.timelineB.play(),this.applyTransition(s.type,s.duration),this.transitionTimer=window.setTimeout(()=>{this.finishTransition(t)},s.duration)}applyTransition(t,e){const s=`${e}ms`,n="ease-in-out";switch(this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),t){case"fade":this.containerB.style.opacity="0";break;case"slide-left":this.containerB.style.transform="translateX(100%)";break;case"slide-right":this.containerB.style.transform="translateX(-100%)";break;case"slide-up":this.containerB.style.transform="translateY(100%)";break;case"slide-down":this.containerB.style.transform="translateY(-100%)";break}switch(this.containerB.offsetHeight,this.containerA.style.transition=`opacity ${s} ${n}, transform ${s} ${n}`,this.containerB.style.transition=`opacity ${s} ${n}, transform ${s} ${n}`,t){case"fade":this.containerA.style.opacity="0",this.containerB.style.opacity="1";break;case"slide-left":this.containerA.style.transform="translateX(-100%)",this.containerB.style.transform="translateX(0)";break;case"slide-right":this.containerA.style.transform="translateX(100%)",this.containerB.style.transform="translateX(0)";break;case"slide-up":this.containerA.style.transform="translateY(-100%)",this.containerB.style.transform="translateY(0)";break;case"slide-down":this.containerA.style.transform="translateY(100%)",this.containerB.style.transform="translateY(0)";break}}resetTransitionStyles(t){t.style.transition="",t.style.opacity="1",t.style.transform=""}finishTransition(t){this.transitionTimer=void 0,this.timelineA&&(this.timelineA.stop(),this.timelineA=null),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.containerA;this.containerA=this.containerB,this.containerB=e;const s=this.adapterA;this.adapterA=this.adapterB,this.adapterB=s,this.timelineA=this.timelineB,this.timelineB=null,this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.playbackState!=="playing"&&this.timelineA.play()):this.onSceneComplete()}switchToScene(t){if(!this.sequence||this._isDestroyed)return;this.timelineA&&this.timelineA.stop(),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.sequence.scenes[t];this.renderScene(e,this.containerA,this.adapterA),this.timelineA=this.createTimeline(e),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play()):this.onSceneComplete()}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=e=>{if(this._isDestroyed||!this._isPlaying)return;const s=e-(this.lastTime??e);if(this.lastTime=e,this.timelineA&&this.timelineA.playbackState==="playing"){this.timelineA.tick(s);const n=this.timelineA.getStateAtTime(this.timelineA.currentTime);this.adapterA.applyState(n),this.applyNested(this.adapterA,this.timelineA.currentTime)}if(this._state==="transitioning"&&this.timelineB&&this.timelineB.playbackState==="playing"){this.timelineB.tick(s);const n=this.timelineB.getStateAtTime(this.timelineB.currentTime);this.adapterB.applyState(n),this.applyNested(this.adapterB,this.timelineB.currentTime)}this._isPlaying?this.animationFrameId=requestAnimationFrame(t):this.animationFrameId=void 0};this.animationFrameId=requestAnimationFrame(t)}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}}async function _i(i,t,e={}){const s=new Zt(i,{...e,autoplay:!0});return await s.load(t),s}const ki={type:"none",duration:0};v.DEFAULT_TRANSITION=ki,v.MediaSync=gt,v.TinyflyPlayer=Tt,v.TinyflySequencer=Zt,v.create=Mi,v.play=Si,v.playSequence=_i,v.syncMediaElement=Gt,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(v,N){typeof exports=="object"&&typeof module<"u"?N(exports):typeof define=="function"&&define.amd?define(["exports"],N):(v=typeof globalThis<"u"?globalThis:v||self,N(v.tinyfly=v.tinyfly||{}))})(this,(function(v){"use strict";function N(i){return typeof i=="object"&&i!==null&&i.type==="cubic-bezier"}function ie(i){return typeof i=="object"&&i!==null&&i.type!=="cubic-bezier"}const St=2;function se(i){return i.some(t=>t.interpolation!==void 0)?2:1}function Mt(i){return i.property==="text"&&"textConfig"in i}function nt(i){return i.kind==="inertia"&&"inertia"in i}function rt(i){return i.kind==="spring"&&"spring"in i}function ne(i){return i.property==="motionPath"&&"motionPathConfig"in i}function _t(i,t,e="start"){if(t<=1)return 0;if(typeof e=="number"){const s=Math.max(0,Math.min(t-1,e));return Math.abs(i-s)}switch(e){case"end":return t-1-i;case"center":return Math.abs(i-(t-1)/2);case"edges":return(t-1)/2-Math.abs(i-(t-1)/2);default:return i}}function re(i,t="start"){if(i<=1)return 0;let e=0;for(let s=0;s<i;s++)e=Math.max(e,_t(s,i,t));return e}function kt(i,t,e){if(e.offsets)return e.offsets[i]??0;const s=e.from??"start",n=_t(i,t,s);if(e.amount!==void 0){const r=re(t,s);return r===0?0:e.amount*n/r}return e.each!==void 0?e.each*n:0}function ae(i,t){return Array.from({length:i},(e,s)=>kt(s,i,t))}function at(i,t){return i<=1?0:Math.max(...ae(i,t))}const q=1,wt=6e4,G=wt/q,X={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1};class oe{from;to;stiffness;damping;mass;restDelta;restSpeed;distance;samples;velocity;settledStep=null;constructor(t){this.from=t.from,this.to=t.to,this.stiffness=t.stiffness??X.stiffness,this.damping=t.damping??X.damping,this.mass=t.mass??X.mass,this.restDelta=t.restDelta??X.restDelta,this.restSpeed=t.restSpeed??X.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=t.velocity??X.velocity,this.isAtRest(this.from)&&(this.settledStep=0)}isAtRest(t){return Math.abs(t-this.to)<this.restDelta*this.distance&&Math.abs(this.velocity)<this.restSpeed*this.distance}valueAt(t){if(t<=0)return this.from;const e=Math.floor(t/q);if(this.simulateTo(e+1),this.settledStep!==null&&e>=this.settledStep)return this.to;const s=this.samples[Math.min(e,this.samples.length-1)],n=this.samples[Math.min(e+1,this.samples.length-1)],r=t/q-e;return s+(n-s)*r}settleTime(){return this.simulateTo(G+1),this.settledStep!==null?this.settledStep*q:wt}simulateTo(t){if(this.settledStep!==null)return;const e=Math.min(t,G+1),s=q/1e3;for(;this.samples.length<e;){const n=this.samples[this.samples.length-1],r=n-this.to,a=-this.stiffness*r,o=-this.damping*this.velocity,c=(a+o)/this.mass;this.velocity+=c*s;const h=n+this.velocity*s;if(this.samples.push(h),this.isAtRest(h)){this.settledStep=this.samples.length-1;return}}this.samples.length>G&&(this.settledStep=G)}}const Pt=4,ce=.002,he=1e-4,le=6e4;function ot(i){const t=i.friction??Pt;return t>0?t:Pt}function ue(i){return i.from+i.velocity/ot(i)}function de(i,t){if(t===void 0)return i;if(typeof t=="number")return t>0?Math.round(i/t)*t:i;if(t.length===0)return i;let e=t[0];for(const s of t)Math.abs(s-i)<Math.abs(e-i)&&(e=s);return e}function vt(i){let t=de(ue(i),i.end);return i.min!==void 0&&(t=Math.max(i.min,t)),i.max!==void 0&&(t=Math.min(i.max,t)),t}function xt(i){const t=Math.abs(vt(i)-i.from);if(t===0)return 0;const e=i.restDelta??Math.max(he,t*ce);if(e>=t)return 0;const s=Math.log(t/e)/ot(i);return Math.min(le,s*1e3)}function It(i,t){if(t<=0)return i.from;const e=vt(i);if(t>=xt(i))return e;const s=ot(i);return i.from+(e-i.from)*(1-Math.exp(-s*t/1e3))}const ct=i=>i,fe=i=>i*i,pe=i=>1-(1-i)*(1-i),me=i=>i<.5?2*i*i:1-Math.pow(-2*i+2,2)/2,Ct=i=>i*i*i,Rt=i=>1-Math.pow(1-i,3),Dt=i=>i<.5?4*i*i*i:1-Math.pow(-2*i+2,3)/2,ye={linear:ct,"ease-in":Ct,"ease-out":Rt,"ease-in-out":Dt,"ease-in-quad":fe,"ease-out-quad":pe,"ease-in-out-quad":me,"ease-in-cubic":Ct,"ease-out-cubic":Rt,"ease-in-out-cubic":Dt};function ge(i){const[t,e,s,n]=i,r=3*t,a=3*(s-t)-r,o=1-r-a,c=3*e,h=3*(n-e)-c,u=1-c-h,l=d=>((o*d+a)*d+r)*d,y=d=>((u*d+h)*d+c)*d,p=d=>(3*o*d+2*a)*d+r,f=d=>{let m=d;for(let A=0;A<8;A++){const M=l(m)-d;if(Math.abs(M)<1e-7)return m;const g=p(m);if(Math.abs(g)<1e-7)break;m-=M/g}let T=0,b=1;for(m=d;T<b;){const A=l(m);if(Math.abs(A-d)<1e-7)return m;d>A?T=m:b=m,m=(T+b)/2}return m};return d=>{if(d<=0)return 0;if(d>=1)return 1;const m=f(d);return y(m)}}function ht(i,t="out"){if(t==="out")return i;const e=s=>1-i(1-s);return t==="in"?e:s=>s<.5?e(s*2)/2:i(s*2-1)/2+.5}function Te(i=1,t=.3){const e=Math.max(1,i),s=t/(2*Math.PI)*Math.asin(1/e);return n=>n<=0?0:n>=1?1:e*Math.pow(2,-10*n)*Math.sin((n-s)*(2*Math.PI)/t)+1}const be=i=>{if(i<=0)return 0;if(i>=1)return 1;if(i<1/2.75)return 7.5625*i*i;if(i<2/2.75){const n=i-.5454545454545454;return 7.5625*n*n+.75}if(i<2.5/2.75){const n=i-.8181818181818182;return 7.5625*n*n+.9375}const s=i-2.625/2.75;return 7.5625*s*s+.984375};function Ae(i=1.70158){return t=>{if(t<=0)return 0;if(t>=1)return 1;const e=t-1;return e*e*((i+1)*e+i)+1}}function Se(i,t="end"){const e=Math.max(1,Math.floor(i));return s=>{if(s>=1)return 1;if(s<=0)return t==="start"||t==="both"?t==="start"?1/e:1/(e+1):0;const n=Math.floor(s*e);switch(t){case"start":return Math.min(1,(n+1)/e);case"both":return(n+1)/(e+1);case"none":return e===1?0:Math.min(1,n/(e-1));default:return n/e}}}function Me(i){switch(i.type){case"steps":return Se(i.count,i.position);case"elastic":return ht(Te(i.amplitude,i.period),i.mode);case"bounce":return ht(be,i.mode);case"back":return ht(Ae(i.overshoot),i.mode)}}function _e(i){return i===void 0?ct:N(i)?ge(i.points):ie(i)?Me(i):ye[i]??ct}const Et=32,ke=256,V=new Map,we=/[MmLlHhVvCcSsQqTtAaZz]/,Pe=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,ve={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function xe(i){const t=[];let e=0,s=null;const n=()=>{for(;e<i.length&&/[\s,]/.test(i[e]);)e++};for(;e<i.length&&(n(),!(e>=i.length));){const r=i[e];if(we.test(r)){s={type:r,args:[]},t.push(s),e++;continue}if(!s)break;const a=s.type==="A"||s.type==="a",o=s.args.length%7;if(a&&(o===3||o===4)){if(r!=="0"&&r!=="1")break;s.args.push(r==="1"?1:0),e++;continue}const c=Pe.exec(i.slice(e));if(!c)break;s.args.push(parseFloat(c[0])),e+=c[0].length}return t}function Ie(i,t,e,s,n,r,a,o,c){if(i===o&&t===c)return[];let h=Math.abs(e),u=Math.abs(s);if(h===0||u===0)return[[i,t,o,c,o,c]];const l=n*Math.PI/180,y=Math.cos(l),p=Math.sin(l),f=(i-o)/2,d=(t-c)/2,m=y*f+p*d,T=-p*f+y*d,b=m*m/(h*h)+T*T/(u*u);if(b>1){const w=Math.sqrt(b);h*=w,u*=w}const A=r===a?-1:1,M=h*h*u*u-h*h*T*T-u*u*m*m,g=h*h*T*T+u*u*m*m,_=A*Math.sqrt(Math.max(0,M/g)),S=_*h*T/u,E=-_*u*m/h,et=y*S-p*E+(i+o)/2,k=p*S+y*E+(t+c)/2,C=(w,I,R,Y)=>{const At=w*R+I*Y,st=Math.sqrt((w*w+I*I)*(R*R+Y*Y)),z=Math.acos(Math.max(-1,Math.min(1,At/st)));return w*Y-I*R<0?-z:z},P=C(1,0,(m-S)/h,(T-E)/u);let x=C((m-S)/h,(T-E)/u,(-m-S)/h,(-T-E)/u);!a&&x>0&&(x-=2*Math.PI),a&&x<0&&(x+=2*Math.PI);const $=Math.max(1,Math.ceil(Math.abs(x)/(Math.PI/2))),bt=x/$,it=4/3*Math.tan(bt/4),Jt=w=>{const I=h*Math.cos(w),R=u*Math.sin(w);return[y*I-p*R+et,p*I+y*R+k]},te=w=>{const I=-h*Math.sin(w),R=u*Math.cos(w);return[y*I-p*R,p*I+y*R]},ee=[];for(let w=0;w<$;w++){const I=P+w*bt,R=I+bt,[Y,At]=Jt(I),[st,z]=w===$-1?[o,c]:Jt(R),[$i,Xi]=te(I),[Fi,Yi]=te(R);ee.push([Y+it*$i,At+it*Xi,st-it*Fi,z-it*Yi,st,z])}return ee}function B(i,t,e,s,n){const r=1-n;return r*r*r*i+3*r*r*n*t+3*r*n*n*e+n*n*n*s}function Bt(i,t,e,s,n){const r=1-n;return 3*r*r*(t-i)+6*r*n*(e-t)+3*n*n*(s-e)}function W(i,t,e,s){return{subpath:0,type:"L",points:[e,s],startX:i,startY:t,endX:e,endY:s,length:Math.hypot(e-i,s-t)}}function Z(i,t,e){const[s,n,r,a,o,c]=e,h=[0];let u=i,l=t,y=0;for(let p=1;p<=Et;p++){const f=p/Et,d=B(i,s,r,o,f),m=B(t,n,a,c,f);y+=Math.hypot(d-u,m-l),h.push(y),u=d,l=m}return{subpath:0,type:"C",points:[s,n,r,a,o,c],startX:i,startY:t,endX:o,endY:c,length:y,lengths:h}}function K(i){const t=V.get(i);if(t)return t;const e=[];let s=0,n=0,r=0,a=0,o=null,c=null,h=-1;const u=new Set,l=d=>{h<0&&(h=0),d.subpath=h,e.push(d)};for(const{type:d,args:m}of xe(i)){const T=d.toUpperCase(),b=d!==T,A=ve[T];if(T==="Z"){(s!==r||n!==a)&&l(W(s,n,r,a)),h>=0&&u.add(h),s=r,n=a,o=c=null;continue}for(let M=0;M+A<=m.length;M+=A){const g=m.slice(M,M+A),_=b?s:0,S=b?n:0;let E=null,et=null;switch(T){case"M":M===0?(s=g[0]+_,n=g[1]+S,r=s,a=n,(h<0||e[e.length-1]?.subpath===h)&&h++):(l(W(s,n,g[0]+_,g[1]+S)),s=g[0]+_,n=g[1]+S);break;case"L":l(W(s,n,g[0]+_,g[1]+S)),s=g[0]+_,n=g[1]+S;break;case"H":l(W(s,n,g[0]+_,n)),s=g[0]+_;break;case"V":l(W(s,n,s,g[0]+S)),n=g[0]+S;break;case"C":{const k=[g[0]+_,g[1]+S,g[2]+_,g[3]+S,g[4]+_,g[5]+S];l(Z(s,n,k)),E=[k[2],k[3]],s=k[4],n=k[5];break}case"S":{const[k,C]=o?[2*s-o[0],2*n-o[1]]:[s,n],P=[k,C,g[0]+_,g[1]+S,g[2]+_,g[3]+S];l(Z(s,n,P)),E=[P[2],P[3]],s=P[4],n=P[5];break}case"Q":case"T":{let k=s,C=n;T==="Q"?(k=g[0]+_,C=g[1]+S):c&&(k=2*s-c[0],C=2*n-c[1]);const P=T==="Q"?g[2]+_:g[0]+_,x=T==="Q"?g[3]+S:g[1]+S;l(Z(s,n,[s+2/3*(k-s),n+2/3*(C-n),P+2/3*(k-P),x+2/3*(C-x),P,x])),et=[k,C],s=P,n=x;break}case"A":{const k=g[5]+_,C=g[6]+S;let P=s,x=n;for(const $ of Ie(s,n,g[0],g[1],g[2],g[3],g[4],k,C))l(Z(P,x,$)),P=$[4],x=$[5];s=k,n=C;break}}o=E,c=et}}const y=e.reduce((d,m)=>d+m.length,0),p=[];for(let d=0;d<e.length;){const m=e[d].subpath;let T=d,b=0;for(;T<e.length&&e[T].subpath===m;)b+=e[T++].length;const A=e[d],M=e[T-1],g=u.has(m)||Math.abs(M.endX-A.startX)<1e-9&&Math.abs(M.endY-A.startY)<1e-9;p.push({start:d,end:T,length:b,closed:g}),d=T}const f={segments:e,totalLength:y,subpaths:p};return V.size>=ke&&V.delete(V.keys().next().value),V.set(i,f),f}function Ce(i,t){const e=i.lengths;if(t<=0)return 0;if(t>=i.length)return 1;let s=0,n=e.length-1;for(;s<n-1;){const o=s+n>>1;e[o]<t?s=o:n=o}const r=e[n]-e[s],a=r>0?(t-e[s])/r:0;return(s+a)/(e.length-1)}function Re(i,t){if(i.type==="L"){const l=i.length>0?Math.max(0,Math.min(1,t/i.length)):0;return{x:i.startX+(i.endX-i.startX)*l,y:i.startY+(i.endY-i.startY)*l,angle:Math.atan2(i.endY-i.startY,i.endX-i.startX)*180/Math.PI}}const[e,s,n,r,a,o]=i.points,c=Ce(i,t);let h=Bt(i.startX,e,n,a,c),u=Bt(i.startY,s,r,o,c);if(Math.hypot(h,u)<1e-9){const l=c<.5?Math.min(1,c+.001):Math.max(0,c-.001),y=B(i.startX,e,n,a,l),p=B(i.startY,s,r,o,l),f=B(i.startX,e,n,a,c),d=B(i.startY,s,r,o,c);h=c<.5?y-f:f-y,u=c<.5?p-d:d-p}return{x:B(i.startX,e,n,a,c),y:B(i.startY,s,r,o,c),angle:Math.atan2(u,h)*180/Math.PI}}function Ot(i,t,e=0,s=i.length){if(s<=e)return{x:0,y:0,angle:0};let n=0;for(let r=e;r<s;r++){const a=i[r];if(n+a.length>=t||r===s-1)return Re(a,t-n);n+=a.length}return{x:0,y:0,angle:0}}function De(i,t){const{segments:e,totalLength:s}=K(i);return Ot(e,Math.max(0,Math.min(1,t))*s)}const Ee=24,Be=320,Oe=2.5,U=72,Le=.2,$e=128,J=new Map;let lt=0,O;const Lt=i=>Math.round(i*100)/100;function $t(i,t){const{segments:e,subpaths:s,totalLength:n}=K(i);if(e.length===0)return[];if(t){const r=s.every(a=>a.closed);return[{segments:e,start:0,end:e.length,length:n,closed:r}]}return s.filter(r=>r.length>0).map(r=>({segments:e,start:r.start,end:r.end,length:r.length,closed:r.closed}))}function ut(i,t){const e=i.closed?(t%1+1)%1:Math.max(0,Math.min(1,t)),s=Ot(i.segments,e*i.length,i.start,i.end);return[s.x,s.y]}function Xt(i){const t=[];let e=0;for(let s=i.start;s<i.end;s++)e+=i.segments[s].length,i.length>0&&t.push(e/i.length);return t}function Ft(i,t){const e=[];for(let s=0;s<t;s++)e.push(ut(i,i.closed?s/t:s/(t-1)));return e}function Yt(i){let t=0,e=0;for(const[s,n]of i)t+=s,e+=n;return t/=i.length,e/=i.length,i.map(([s,n])=>[s-t,n-e])}function Xe(i,t,e){const s=i.closed&&t.closed;if(e!==void 0)return{offset:s?Math.abs(e)%U/U:0,reversed:e<0};const n=Yt(Ft(i,U)),r=Yt(Ft(t,U)),a=U;let o={offset:0,reversed:!1},c=1/0;for(const h of[!1,!0]){const u=s?a:1;for(let l=0;l<u;l++){let y=0;for(let p=0;p<a&&y<c;p++){const f=s?h?(l-p+a)%a:(p+l)%a:h?a-1-p:p,d=n[p][0]-r[f][0],m=n[p][1]-r[f][1];y+=d*d+m*m}y<c&&(c=y,o={offset:s?l/a:0,reversed:h})}}return o}function Fe(i,t,e){return e?((t.reversed?t.offset-i:i+t.offset)%1+1)%1:t.reversed?1-i:i}function Ye(i,t,e){return e?((t.reversed?t.offset-i:i-t.offset)%1+1)%1:t.reversed?1-i:i}function Ne(i,t,e){const s=i.closed&&t.closed,n=Xe(i,t,e.shapeIndex),r=Math.max(Ee,Math.min(Be,Math.ceil(Math.max(i.length,t.length)/Oe))),a=new Set,o=l=>a.add(Math.round(l*1e7)/1e7);for(let l=0;l<=r;l++)o(l/r);for(const l of Xt(i))o(l);for(const l of Xt(t))o(Ye(l,n,s));let c=[...a].sort((l,y)=>l-y);s&&(c=c.filter(l=>l<1));const h=[],u=[];for(const l of c)h.push(...ut(i,l)),u.push(...ut(t,Fe(l,n,s)));return qe({from:h,to:u,closed:s})}function qe(i){const t=i.from.length/2;if(t<=3)return i;const e=new Uint8Array(t);e[0]=1,e[t-1]=1;const s=[[0,t-1]];for(;s.length>0;){const[a,o]=s.pop();let c=-1,h=Le;for(let u=a+1;u<o;u++){const l=Math.max(Nt(i.from,a,o,u),Nt(i.to,a,o,u));l>h&&(h=l,c=u)}c!==-1&&(e[c]=1,s.push([a,c],[c,o]))}const n=[],r=[];for(let a=0;a<t;a++)e[a]&&(n.push(i.from[a*2],i.from[a*2+1]),r.push(i.to[a*2],i.to[a*2+1]));return{from:n,to:r,closed:i.closed}}function Nt(i,t,e,s){const n=i[t*2],r=i[t*2+1],a=i[e*2]-n,o=i[e*2+1]-r,c=i[s*2]-n,h=i[s*2+1]-r,u=a*a+o*o,l=u===0?0:Math.max(0,Math.min(1,(c*a+h*o)/u));return Math.hypot(c-l*a,h-l*o)}function Ve(i,t,e){const s=e.shapeIndex;if(O&&O.from===i&&O.to===t&&O.shapeIndex===s)return O.plan;const r=J.get(String(s??"auto"))?.get(i)?.get(t);if(r)return O={from:i,to:t,shapeIndex:s,plan:r},r;const a=K(i).subpaths.filter(p=>p.length>0).length===K(t).subpaths.filter(p=>p.length>0).length,o=$t(i,!a),c=$t(t,!a),h={pairs:o.map((p,f)=>Ne(p,c[f],e))};lt>=$e&&(J.clear(),lt=0);const u=String(s??"auto"),l=J.get(u)??new Map;J.set(u,l);const y=l.get(i)??new Map;return l.set(i,y),y.set(t,h),lt++,O={from:i,to:t,shapeIndex:s,plan:h},h}function We(i,t,e,s={}){if(!i)return t;if(!t)return i;const n=Math.max(0,Math.min(1,e));if(n===0)return i;if(n===1)return t;const r=Ve(i,t,s);if(r.pairs.length===0)return n<.5?i:t;let a="";for(const o of r.pairs){for(let c=0;c<o.from.length;c+=2){const h=Lt(o.from[c]+(o.to[c]-o.from[c])*n),u=Lt(o.from[c+1]+(o.to[c+1]-o.from[c+1])*n);a+=`${c===0?a?" M":"M":" L"}${h} ${u}`}o.closed&&(a+=" Z")}return a}function Ue(i){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(i)}const He=.9995;function Qe(){return[0,0,0,1]}function je(i,t){return i[0]*t[0]+i[1]*t[1]+i[2]*t[2]+i[3]*t[3]}function ze(i){return Math.hypot(i[0],i[1],i[2],i[3])}function H(i){const t=ze(i);return t===0?Qe():[i[0]/t,i[1]/t,i[2]/t,i[3]/t]}function Ge(i,t,e){const s=H(i);let n=H(t),r=je(s,n);if(r<0&&(n=[-n[0],-n[1],-n[2],-n[3]],r=-r),r>He)return H([s[0]+(n[0]-s[0])*e,s[1]+(n[1]-s[1])*e,s[2]+(n[2]-s[2])*e,s[3]+(n[3]-s[3])*e]);const a=Math.acos(r),o=Math.sin(a),c=Math.sin((1-e)*a)/o,h=Math.sin(e*a)/o;return H([s[0]*c+n[0]*h,s[1]*c+n[1]*h,s[2]*c+n[2]*h,s[3]*c+n[3]*h])}const D=(i,t,e)=>i+(t-i)*e,qt=512,dt=new Map,ft=new Map;function Vt(i){const t=dt.get(i);if(t)return t;const e=i.replace("#",""),s=[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)];return dt.size<qt&&dt.set(i,s),s}const Wt=i=>i.charCodeAt(0)===35,Ut=i=>i.startsWith("rgb"),Ht=i=>i.startsWith("rgba"),Ze=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,pt=i=>Math.round(i).toString(16).padStart(2,"0");function Ke(i,t,e){return`#${pt(i)}${pt(t)}${pt(e)}`}function Qt(i){const t=ft.get(i);if(t)return t;const e=i.match(Ze);if(!e)throw new Error(`Invalid rgb color: ${i}`);const s=parseInt(e[1],10),n=parseInt(e[2],10),r=parseInt(e[3],10),a=e[4]!==void 0?[s,n,r,parseFloat(e[4])]:[s,n,r];return ft.size<qt&&ft.set(i,a),a}const Je=(i,t,e)=>{if(Wt(i)&&Wt(t)){const[s,n,r]=Vt(i),[a,o,c]=Vt(t),h=D(s,a,e),u=D(n,o,e),l=D(r,c,e);return Ke(h,u,l)}if((Ut(i)||Ht(i))&&(Ut(t)||Ht(t))){const s=Qt(i),n=Qt(t),r=Math.round(D(s[0],n[0],e)),a=Math.round(D(s[1],n[1],e)),o=Math.round(D(s[2],n[2],e));if(s.length===4||n.length===4){const c=s[3]??1,h=n[3]??1,u=D(c,h,e);return`rgba(${r}, ${a}, ${o}, ${u})`}return`rgb(${r}, ${a}, ${o})`}return e<1?i:t},ti=(i,t,e)=>{const s=Math.min(i.length,t.length),n=[];for(let r=0;r<s;r++)n.push(D(i[r],t[r],e));return n},ei=(i,t,e)=>Ge(i,t,e),jt=(i,t,e)=>e<1?i:t,ii=(i,t,e)=>We(i,t,e);function si(i,t){return t==="slerp"?ei:typeof i=="number"?D:Array.isArray(i)?ti:typeof i=="string"?i.startsWith("#")||i.startsWith("rgb")?Je:Ue(i)?ii:jt:jt}function ni(i){const t=[...i.keyframes].sort((e,s)=>e.time-s.time);return{...i,keyframes:t}}function L(i){return i.targets&&i.targets.length>0?i.targets:[i.target]}function F(i,t,e,s){const n=e??0;return!s||t<=1?n:n+kt(i,t,s)}class mt{track;targets;constructor(t){this.track=t,this.targets=L(t)}getValueAtTime(t){return this.valueForOffset(t-F(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=F(n,e,this.track.delay,this.track.stagger),a=this.valueForOffset(t-r);a!==void 0&&s.push({target:this.targets[n],value:a,start:r+this.track.keyframes[0].time})}return s}getDuration(){const{keyframes:t}=this.track;if(t.length===0)return 0;const e=t[t.length-1].time,s=this.track.stagger?at(this.targets.length,this.track.stagger):0;return e+(this.track.delay??0)+s+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(t){const{keyframes:e}=this.track;if(e.length===0)return;if(e.length===1||t<=e[0].time)return e[0].value;if(t>=e[e.length-1].time)return e[e.length-1].value;const{from:s,to:n}=this.findSurroundingKeyframes(t);if(!s||!n)return;if(s.time===t)return s.value;const r=n.time-s.time,a=(t-s.time)/r,c=_e(n.easing)(a);return si(s.value,this.track.interpolation)(s.value,n.value,c)}findSurroundingKeyframes(t){const{keyframes:e}=this.track;for(let s=0;s<e.length-1;s++)if(t>=e[s].time&&t<=e[s+1].time)return{from:e[s],to:e[s+1]};return{from:null,to:null}}}class ri{track;targets;sampler;constructor(t){this.track=t,this.targets=L(t),this.sampler=new oe(t.spring)}getValueAtTime(t){return this.sampler.valueAt(t-F(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=F(n,e,this.track.delay,this.track.stagger);s.push({target:this.targets[n],value:this.sampler.valueAt(t-r),start:r})}return s}getDuration(){const t=this.track.stagger?at(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+t}getTrack(){return this.track}}class ai{track;targets;duration;constructor(t){this.track=t,this.targets=L(t),this.duration=xt(t.inertia)}getValueAtTime(t){return It(this.track.inertia,t-F(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=F(n,e,this.track.delay,this.track.stagger);s.push({target:this.targets[n],value:It(this.track.inertia,t-r),start:r})}return s}getDuration(){const t=this.track.stagger?at(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+t}getTrack(){return this.track}}function oi(i,t){const e={...De(i.pathData,t)};if(i.matrix){const[s,n,r,a,o,c]=i.matrix,{x:h,y:u}=e;e.x=s*h+r*u+o,e.y=n*h+a*u+c;const l=e.angle*Math.PI/180,y=Math.cos(l),p=Math.sin(l);e.angle=Math.atan2(n*y+a*p,s*y+r*p)*180/Math.PI}return i.autoRotate&&i.rotateOffset&&(e.angle+=i.rotateOffset),e}const yt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},ci=20;function hi(i){const t=yt[i??"upperCase"]??i??yt.upperCase,e=Array.from(t);return e.length>0?e:Array.from(yt.upperCase)}function li(i,t,e){let s=(i|0)^Math.imul(t+1,2654435761)^Math.imul(e+1,2246822507);return s=Math.imul(s^s>>>16,2146121005),s=Math.imul(s^s>>>15,2221713035),(s^s>>>16)>>>0}function ui(i,t,e=0){const s=i.from??"",n=i.to,r=Math.max(0,Math.min(1,t));if(r<=0)return s;if(r>=1)return n;const a=Array.from(s),o=Array.from(n),c=i.rightToLeft??!1;if(i.mode==="type"){const b=Math.round(r*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 h=Math.max(0,Math.min(.999,i.revealDelay??0)),u=Math.max(0,(r-h)/(1-h)),l=Math.floor(u*o.length),y=i.tweenLength===!1?o.length:Math.round(a.length+(o.length-a.length)*r),p=hi(i.chars),f=i.refreshRate??ci,d=f>0?Math.floor(e*f/1e3):0,m=i.seed??1;let T="";for(let b=0;b<y;b++){const A=c?b>=y-l:b<l,M=c?o[o.length-(y-b)]:o[b];A&&M!==void 0||M===" "||M===`
2
+ `?T+=M:T+=p[li(m,b,d)%p.length]}return T}class di{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(t){if(this.id=t.id,this.name=t.name,this._captions=t.captions,this._config=t.config??{},this._explicitDuration=t.config?.duration,t.tracks)for(const e of t.tracks)this.addTrack(e)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(t){if(this._explicitDuration=t,t!==void 0)this._config={...this._config,duration:t};else if(this._config.duration!==void 0){const e={...this._config};delete e.duration,this._config=e}}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(t){this._config.speed=t}play(){const t=this.duration;this._direction==="forward"&&this._currentTime>=t&&t>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&t>0&&(this._currentTime=t,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(t){const e=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(t,e)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(t){if(this._playbackState!=="playing")return;const e=this.duration;if(e<=0)return;let n=t*this.speed;if(this._repeatDelayRemaining>0){const o=Math.min(this._repeatDelayRemaining,n);if(this._repeatDelayRemaining-=o,n-=o,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const r=1e3;for(let o=0;o<r&&n>0&&this._playbackState==="playing";o++)if(this._direction==="forward"){const c=e-this._currentTime;if(n>=c){if(n-=c,this._currentTime=e,!this._handleEndReached())break}else this._currentTime+=n,n=0}else{const c=this._currentTime;if(n>=c){if(n-=c,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=n,n=0}const a=this.getStateAtTime(this._currentTime);this.onUpdate?.(a)}getStateAtTime(t){const e=new Map;if(this._hasSharedWrites())this._resolveShared(t,e);else for(const[s,n]of this._trackPlayers){const r=n.getTrack().property;for(const{target:a,value:o,start:c}of n.getTargetValues(t))this._write(e,s,a,r,o,t-c)}return{values:e,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(t,e){const s=new Map;for(const[n,r]of this._trackPlayers){const a=r.getTrack().property;for(const{target:o,value:c,start:h}of r.getTargetValues(t)){const u=`${o}\0${a}`,l=h<=t,y=s.get(u);(!y||(l!==y.started?l:l?h>=y.start:h<=y.start))&&s.set(u,{trackId:n,target:o,property:a,value:c,start:h,started:l})}}for(const{trackId:n,target:r,property:a,value:o,start:c}of s.values())this._write(e,n,r,a,o,t-c)}_write(t,e,s,n,r,a){if(r===void 0)return;let o=t.get(s);o||(o=new Map,t.set(s,o));const c=this._textTracks.get(e);if(c&&typeof r=="number"){o.set("text",ui(c.textConfig,r,Math.max(0,a)));return}const h=this._motionPathTracks.get(e);if(h&&typeof r=="number"){const u=oi(h.motionPathConfig,r);o.set("motionPathX",u.x),o.set("motionPathY",u.y),h.motionPathConfig.autoRotate&&o.set("motionPathRotate",u.angle)}else o.set(n,r)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const t=new Set;this._sharedWrites=!1;t:for(const e of this._tracks)for(const s of L(e)){const n=`${s}\0${e.property}`;if(t.has(n)){this._sharedWrites=!0;break t}t.add(n)}}return this._sharedWrites}addTrack(t){if(this._tracks.push(t),this._sharedWrites=null,nt(t)){this._trackPlayers.set(t.id,new ai(t));return}if(rt(t)){this._trackPlayers.set(t.id,new ri(t)),this._springTracks.set(t.id,t);return}if(Mt(t))this._trackPlayers.set(t.id,new mt(t)),this._textTracks.set(t.id,t);else if(ne(t)){const e={id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,delay:t.delay,endDelay:t.endDelay,targets:t.targets,stagger:t.stagger};this._trackPlayers.set(t.id,new mt(e)),this._motionPathTracks.set(t.id,t)}else this._trackPlayers.set(t.id,new mt(t))}replaceTrack(t,e){const s=this._tracks.findIndex(r=>r.id===t);if(s<0)return;const n=this._tracks.slice(s+1);this.removeTrack(t);for(const r of n)this.removeTrack(r.id);this.addTrack(e);for(const r of n)this.addTrack(r)}removeTrack(t){this._tracks=this._tracks.filter(e=>e.id!==t),this._sharedWrites=null,this._trackPlayers.delete(t),this._motionPathTracks.delete(t),this._springTracks.delete(t),this._textTracks.delete(t)}getTracks(t={}){return this._tracks.filter(e=>this._matches(e,t))}removeTracks(t={}){const e=this.getTracks(t).map(s=>s.id);for(const s of e)this.removeTrack(s);return e}getTrackSpan(t){const e=this._trackPlayers.get(t);if(!e)return;const s=e.getTrack(),n=s.delay??0;if(rt(s)||nt(s))return{from:n,to:e.getDuration()};const r=s.keyframes;if(!(!r||r.length===0))return{from:r[0].time+n,to:e.getDuration()}}findConflicts(){const t=[];for(let e=0;e<this._tracks.length;e++){const s=this._tracks[e],n=this.getTrackSpan(s.id);if(n)for(let r=0;r<e;r++){const a=this._tracks[r];if(a.property!==s.property)continue;const o=L(a).filter(l=>L(s).includes(l));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=n.to&&n.from<=c.to))continue;const u=n.from>=c.from;for(const l of o)t.push({target:l,property:s.property,losingTrackId:u?a.id:s.id,winningTrackId:u?s.id:a.id})}}return t}_matches(t,e){if(e.id!==void 0&&t.id!==e.id||e.property!==void 0&&t.property!==e.property||e.target!==void 0&&!L(t).includes(e.target))return!1;if(e.timeRange){const s=this.getTrackSpan(t.id);if(!s||s.to<e.timeRange.from||s.from>e.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:se(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((t,e)=>t.time-e.time)}setMarkers(t){const e=t&&t.length>0?[...t].sort((n,r)=>n.time-r.time).map(n=>({...n})):void 0,s={...this._config};e?s.markers=e:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(t){const e={};for(const[s,n]of Object.entries(t??{}))e[s]={...n};this._captions=Object.keys(e).length>0?e:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let t=0;for(const[,e]of this._trackPlayers)t=Math.max(t,e.getDuration());return t}_handleEndReached(){const t=this._config.loop??0;return t===-1||this._loopIteration<t?(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 t=this._config.loop??0;return this._config.alternate&&(t===-1||this._loopIteration<t)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const fi=100;function pi(i,t,e,s){const n=[],r=[],{duration:a,alternate:o}=s,c=(p,f,d,m)=>{r.push([p,f]);const T=[];i.forEach((b,A)=>{(d==="forward"?(m?b>=p:b>p)&&b<=f:(m?b<=p:b<p)&&b>=f)&&T.push(A)}),T.sort((b,A)=>(d==="forward"?i[b]-i[A]:i[A]-i[b])||b-A);for(const b of T)n.push({kind:"event",index:b,direction:d})};let h=t.time,u=t.direction,l=t.fresh===!0;const y=Math.min(fi,Math.max(0,e.iteration-t.iteration));for(let p=0;p<y;p++){const f=u==="forward"?a:0;c(h,f,u,l),n.push({kind:"repeat"}),o?(u=u==="forward"?"reverse":"forward",h=f,l=!1):(h=u==="forward"?0:a,l=!0)}return y>0&&s.holding&&!o?{crossings:n,passes:r}:(c(h,e.time,u,l),{crossings:n,passes:r})}function mi(i){return{...i,...Array.isArray(i.end)&&{end:[...i.end]}}}function Q(i){const t=i.endDelay;return{...i.delay!==void 0&&{delay:i.delay},...t!==void 0&&{endDelay:t},...i.targets!==void 0&&{targets:[...i.targets]},...i.stagger!==void 0&&{stagger:{...i.stagger}}}}function yi(i){if(nt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:mi(t.inertia),...Q(t)}}if(rt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...Q(t)}}if(Mt(i)){const t=i;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((e,s)=>e.time-s.time),...Q(t)}}if(i.property==="motionPath"&&"motionPathConfig"in i){const t=i,e=[...t.keyframes].sort((s,n)=>s.time-n.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:e,...Q(t)}}return ni({id:i.id,target:i.target,property:i.property,keyframes:i.keyframes,...i.interpolation!==void 0&&{interpolation:i.interpolation},...Q(i)})}function tt(i){const t=i.formatVersion??1;if(t>St)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${St}. Update tinyfly to play it.`);return new di({id:i.id,name:i.name,config:i.config,tracks:i.tracks.map(yi),captions:i.captions})}function gi(i){const[t,e,s,n]=i;return[1-2*(e*e+s*s),2*(t*e+s*n),2*(t*s-e*n),0,2*(t*e-s*n),1-2*(t*t+s*s),2*(e*s+t*n),0,2*(t*s+e*n),2*(e*s-t*n),1-2*(t*t+e*e),0,0,0,0,1]}function Ti(i){return!Array.isArray(i)||i.length!==4?null:`matrix3d(${gi(H(i)).map(e=>Math.round(e*1e6)/1e6+0).join(", ")})`}const bi=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),Ai="#ffffff",Si="rgba(0, 0, 0, 0.5)";function Mi(i){const t=[];if(i.blur!==void 0&&t.push(`blur(${Math.max(0,i.blur)}px)`),i.brightness!==void 0&&t.push(`brightness(${Math.max(0,i.brightness)})`),i.glow!==void 0&&t.push(`drop-shadow(0 0 ${Math.max(0,i.glow)}px ${i.glowColor??Ai})`),i.shadowX!==void 0||i.shadowY!==void 0||i.shadowBlur!==void 0){const e=i.shadowX??0,s=i.shadowY??0,n=Math.max(0,i.shadowBlur??0);t.push(`drop-shadow(${e}px ${s}px ${n}px ${i.shadowColor??Si})`)}return t.length>0?t.join(" "):null}function _i(i,t){const e=i.childNodes.length===1?i.firstChild:null;if(e&&e.nodeType===3){const s=e;s.data!==t&&(s.data=t);return}i.textContent!==t&&(i.textContent=t)}function ki(i){if(!("ownerSVGElement"in i))return;const t=i.style;!t||t.transformBox||(t.transformBox="fill-box",t.transformOrigin||(t.transformOrigin="50% 50%"))}const zt=new Set(["width","height","top","right","bottom","left","margin","marginTop","marginRight","marginBottom","marginLeft","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","borderRadius","borderWidth","fontSize","lineHeight","letterSpacing","outlineWidth","gap","rowGap","columnGap"]),wi=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),Pi=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],vi=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),xi=new Set(["originX","originY"]),Ii=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Ci=new Set(["drawOn"]),Ri={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},Gt={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},Di="http://www.w3.org/2000/svg";class j{targets=new Map;registerTarget(t,e){this.targets.set(t,e)}unregisterTarget(t){this.targets.delete(t)}getTarget(t){return this.targets.get(t)}clearTargets(){this.targets.clear()}applyState(t){for(const[e,s]of t.values){const n=this.targets.get(e);n&&this.applyProperties(n,s)}}applyProperties(t,e){let s=null,n=null,r=null,a=null,o=null;const c=e.has("motionPathX"),h=e.has("motionPathY"),u=e.has("motionPathRotate");for(const[f,d]of e)if(!(f==="x"&&c)&&!(f==="y"&&h)&&!((f==="rotate"||f==="rotateZ")&&u)&&!Ci.has(f)){if(wi.has(f))(s??={})[f]=d;else if(vi.has(f))typeof d=="number"&&((n??={})[f]=d);else if(xi.has(f))typeof d=="number"&&((r??={})[f]=d);else if(Ii.has(f))typeof d=="number"&&((a??={})[f]=d);else if(bi.has(f))(o??={})[f]=d;else if(f!=="perspective"){if(f!=="shine")if(f==="text"&&typeof d=="string")_i(t,d);else if(f==="d"&&typeof d=="string"){const m=t;(m.tagName?.toLowerCase()==="path"?m:m.querySelector?.("path"))?.setAttribute?.("d",d)}else this.applyStyleProperty(t,f,d)}}const l=e.get("shine");typeof l=="number"&&this.applyShine(t,l);const y=[],p=e.get("perspective");if(typeof p=="number"&&p>0&&y.push(`perspective(${p}px)`),s)for(const f of Pi){const d=s[f];if(d===void 0)continue;const m=this.buildTransformPart(f,d);m&&y.push(m)}if(y.length>0&&(t.style.transform=y.join(" "),ki(t)),n&&(n.childPerspective!==void 0&&(t.style.perspective=`${n.childPerspective}px`),(n.perspectiveOriginX!==void 0||n.perspectiveOriginY!==void 0)&&(t.style.perspectiveOrigin=`${n.perspectiveOriginX??50}% ${n.perspectiveOriginY??50}%`)),r){const f=r.originX??50,d=r.originY??50;t.style.transformOrigin=`${f}% ${d}%`}if(a){const f=a.clipTop??0,d=a.clipRight??0,m=a.clipBottom??0,T=a.clipLeft??0;t.style.clipPath=`inset(${f}% ${d}% ${m}% ${T}%)`}if(o){const f=Mi(o);f&&(t.style.filter=f)}}buildTransformPart(t,e){if(t==="quaternion")return Ti(e);if(typeof e!="number")return null;switch(t){case"x":case"motionPathX":return`translateX(${e}px)`;case"y":case"motionPathY":return`translateY(${e}px)`;case"z":return`translateZ(${e}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${e}deg)`;case"rotateX":return`rotateX(${e}deg)`;case"rotateY":return`rotateY(${e}deg)`;case"scale":return`scale(${e})`;case"scaleX":return`scaleX(${e})`;case"scaleY":return`scaleY(${e})`;case"scaleZ":return`scaleZ(${e})`;case"skewX":return`skewX(${e}deg)`;case"skewY":return`skewY(${e}deg)`;default:return null}}applyShine(t,e){t.dataset.shineBase||(t.dataset.shineBase=t.style.color||"currentColor");const s=t.dataset.shineBase,n=-20+e*140,r=t.style;r.color="transparent",r.backgroundImage=`linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${s}, ${s})`,r.backgroundSize="250% 100%, 100% 100%",r.backgroundPosition=`${n}% 0, 0 0`,r.backgroundRepeat="no-repeat",r.webkitBackgroundClip="text",r.backgroundClip="text"}applyStyleProperty(t,e,s){let n;if(t.namespaceURI===Di&&e in Gt){const o=Array.isArray(s)?s.join(", "):String(s);t.style[Gt[e]]=o;return}else e==="fill"&&t.dataset?.elementType==="text"?n="color":n=Ri[e]??e;let a;typeof s=="number"?zt.has(e)||zt.has(n)?a=`${s}px`:a=String(s):Array.isArray(s)?a=s.join(", "):a=s,t.style[n]=a}}class gt{media;offset;driftTolerance;constructor(t,e={}){this.media=t,this.offset=e.offset??0,this.driftTolerance=Math.max(0,e.driftTolerance??.15)}targetTime(t){return Math.max(0,t/1e3+this.offset)}update(t,e){const s=this.targetTime(t);e?(this.media.paused&&this.safePlay(),Math.abs(this.media.currentTime-s)>this.driftTolerance&&(this.media.currentTime=s)):(this.media.paused||this.media.pause(),this.media.currentTime!==s&&(this.media.currentTime=s))}seek(t){this.media.currentTime=this.targetTime(t)}setRate(t){this.media.playbackRate=t}dispose(){this.media.paused||this.media.pause()}safePlay(){const t=this.media.play();t&&typeof t.catch=="function"&&t.catch(()=>{})}}function Zt(i,t,e,s,n){const r=e-n;if(r<0){t.paused||t.pause(),t.currentTime=0;return}i.update(r,s)}class Tt{container;timeline=null;adapter;animationFrameId;lastTime;options;targets={};isDestroyed=!1;mediaSync;mediaTargets=[];symbolInstances=[];scenarioList=[];scenarioId;authored=new Map;markerList=[];listeners=new Set;playhead={time:0,iteration:0,direction:"forward"};stepping=!1;lastMarkerId=null;reducedQuery;onReducedChange=()=>this.applyReducedMotion();visibilityObserver;onScreen=!0;pausedByVisibility=!1;autoplayWhenSeen=!1;onDocumentVisibility=()=>this.updateVisibility();constructor(t,e={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=e,this.adapter=new j}async load(t){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(t)}async loadSource(t){let e;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load animation: ${s.statusText}`);e=await s.json()}else e=t;this.useDefinition(e),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(t){const e={...t.config};this.options.speed!==void 0&&(e.speed=this.options.speed),this.options.loop!==void 0&&(e.loop=this.options.loop),this.options.alternate!==void 0&&(e.alternate=this.options.alternate),this.timeline=tt({...t,config:e}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(t,e={}){if(t.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const s=new Set;for(const r of t){if(s.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);s.add(r.id)}const n=e.initial===void 0?t[0]:t.find(r=>r.id===e.initial);if(!n)throw new Error(`tinyfly: there is no scenario "${e.initial}"`);this.scenarioList=[...t],this.scenarioId=n.id,await this.loadSource(n.timeline)}get scenarios(){return this.scenarioList.map(t=>({id:t.id,label:t.label??t.id}))}get scenario(){return this.scenarioId}setScenario(t){const e=this.scenarioList.find(o=>o.id===t);if(!e||!this.timeline)return!1;if(t===this.scenarioId)return!0;const s=this.isPlaying,n=this.currentTime>=this.duration-.5,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=t,this.useDefinition(e.timeline),this.lastMarkerId=null;let a=0;return this.reducedMotion||n?a=this.duration:r!==void 0&&(a=this.markers.find(o=>o.id===r)?.time??0),this.seek(a),s&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(t){if(this.authored.has(t))return;const e={style:t.getAttribute("style")};t.children.length===0&&(e.text=t.textContent??"");const s=t.tagName.toLowerCase()==="path"?t:t.querySelector("path");s&&(e.path={element:s,d:s.getAttribute("d")}),this.authored.set(t,e)}restoreAuthored(){for(const[t,e]of this.authored){e.style===null?t.removeAttribute("style"):t.setAttribute("style",e.style),e.text!==void 0&&t.textContent!==e.text&&(t.textContent=e.text),e.path&&(e.path.d===null?e.path.element.removeAttribute("d"):e.path.element.setAttribute("d",e.path.d));const s=t.dataset;s&&delete s.shineBase}}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notify(){for(const t of this.listeners)t()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const t=this.currentTime;let e;for(const s of this.markers)if(s.time<=t+.5)e=s;else break;return e}caption(t,e){const s=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!s)return;const n=e??this.language(),r=a=>a?.[n]?.[s.id]??a?.[n.split("-")[0]]?.[s.id];return r(this.options.captions)??r(this.timeline?.captions)??s.label}next(){if(!this.timeline)return;const t=this.currentTime,e=this.markers.find(s=>s.time>t+.5);if(this.reducedMotion){this.seek(e?e.time:this.duration);return}t>=this.duration-.5||(this.stepping=e!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const t=this.currentTime,e=[...this.markers].reverse().find(s=>s.time<t-.5);this.pause(),this.seek(e?e.time:0)}goToMarker(t){const e=this.markers.find(s=>s.id===t);e&&(this.pause(),this.seek(e.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const t=this.options.initialFrame??"start";if(t==="none")return;const e=t==="end"?this.timeline.duration:t==="start"?0:t;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,e))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(e=>{for(const s of e)this.onScreen=s.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const t=this.container.getBoundingClientRect?.();t&&(t.width>0||t.height>0)&&(this.onScreen=t.bottom>0&&t.top<window.innerHeight&&t.right>0&&t.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const t=this.onScreen&&document.visibilityState!=="hidden";!t&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):t&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const t=this.currentMarker,e=t?.id;e!==this.lastMarkerId&&(this.lastMarkerId=e,this.options.onMarker(t))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(e=>{const s=e,n=Number(s.getAttribute("data-tinyfly-start")??"0")||0,r=s.getAttribute("data-volume");r!==null&&(s.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:s,startTime:n,sync:new gt(s)})})}syncAllMedia(t,e){for(const s of this.mediaTargets)Zt(s.sync,s.el,t,e,s.startTime)}loadFromString(t){const e=JSON.parse(t);this.load(e)}registerTarget(t,e){if(typeof e=="string"){const s=this.container.querySelector(e);s&&(this.rememberAuthored(s),this.targets[t]=s,this.adapter.registerTarget(t,s))}else this.rememberAuthored(e),this.targets[t]=e,this.adapter.registerTarget(t,e)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(e=>{const s=e.closest("[data-tinyfly-symbol]");if(s&&s!==e)return;const n=e.getAttribute("data-tinyfly");n&&this.registerTarget(n,e)}),this.timeline&&new Set(this.timeline.tracks.map(s=>s.target)).forEach(s=>{if(!this.targets[s]){const n=this.container.querySelector(`[data-tinyfly="${s}"]`)||this.container.querySelector(`.${s}`)||this.container.querySelector(`#${s}`);n&&this.registerTarget(s,n)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const e=new Map(t.map(s=>[s.id,s]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const n=s.getAttribute("data-tinyfly-symbol");if(!n)return;const r=e.get(n);if(!r||!r.timeline.tracks?.length)return;const a=new j;s.querySelectorAll("[data-tinyfly]").forEach(o=>{const c=o.getAttribute("data-tinyfly");c&&a.registerTarget(c,o)}),this.symbolInstances.push({adapter:a,timeline:tt(r.timeline)})})}attachMedia(t,e){this.mediaSync=new gt(t,e),this.timeline&&(this.mediaSync.setRate(this.timeline.speed),this.mediaSync.update(this.timeline.currentTime,this.isPlaying))}detachMedia(){this.mediaSync?.dispose(),this.mediaSync=void 0}play(){!this.timeline||this.isDestroyed||(this.autoplayWhenSeen=!1,this.stepping=this.options.stepMode===!0,this.startPlaying())}startPlaying(){if(!this.timeline||this.isDestroyed)return;const t=this.timeline.playbackState==="idle";this.timeline.play(),t&&this.timeline.currentTime===0&&this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.update(this.timeline.currentTime,!0),this.syncAllMedia(this.timeline.currentTime,!0),this.startAnimationLoop(),this.notify()}pause(){this.timeline&&(this.stepping=!1,this.timeline.pause(),this.notify(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1),this.stopAnimationLoop())}stop(){this.timeline&&(this.timeline.stop(),this.stopAnimationLoop(),this.applyState(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1))}seek(t){this.timeline&&(this.timeline.seek(t),this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.seek(this.timeline.currentTime),this.syncAllMedia(this.timeline.currentTime,this.isPlaying))}setSpeed(t){this.timeline&&(this.timeline.speed=t,this.mediaSync?.setRate(t))}reverse(){this.timeline&&this.timeline.reverse()}get currentTime(){return this.timeline?.currentTime??0}get duration(){return this.timeline?.duration??0}get isPlaying(){return this.timeline?.playbackState==="playing"}destroy(){this.isDestroyed=!0,this.stopAnimationLoop(),this.reducedQuery?.removeEventListener?.("change",this.onReducedChange),this.visibilityObserver?.disconnect(),typeof document<"u"&&document.removeEventListener("visibilitychange",this.onDocumentVisibility),this.mediaSync?.dispose(),this.mediaSync=void 0;for(const t of this.mediaTargets)t.el.paused||t.el.pause();this.mediaTargets=[],this.adapter.clearTargets();for(const t of this.symbolInstances)t.adapter.clearTargets();this.symbolInstances=[],this.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=e=>{if(this.isDestroyed||!this.timeline)return;const s=e-(this.lastTime??e);this.lastTime=e;const n=this.playhead;this.timeline.tick(s),this.stopAtMarker(n),this.applyState();const r=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,r),this.syncAllMedia(this.timeline.currentTime,r),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(t):(this.animationFrameId=void 0,this.notify())};this.animationFrameId=requestAnimationFrame(t)}stopAtMarker(t){const e=this.timeline,s={time:e.currentTime,iteration:e.loopIteration,direction:e.direction};this.playhead=s;const n=this.markers;if(n.length===0)return;const{crossings:r}=pi(n.map(a=>a.time),t,s,{duration:e.duration,alternate:e.config.alternate===!0,holding:e.repeatDelayRemaining>0});for(const a of r){if(a.kind!=="event")continue;const o=n[a.index];if(this.stepping||o.pause){this.stepping=!1,e.pause(),e.seek(o.time),this.playhead={time:o.time,iteration:e.loopIteration,direction:e.direction};return}}}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}applyState(){if(!this.timeline)return;const t=this.timeline.currentTime;this.adapter.applyState(this.timeline.getStateAtTime(t)),this.announceMarker(),this.notify();for(const e of this.symbolInstances){const s=e.timeline.duration;e.adapter.applyState(e.timeline.getStateAtTime(s>0?t%s:t))}}}async function Ei(i,t,e={}){const s=new Tt(i,{...e,autoplay:!0});return await s.load(t),s}function Bi(i,t={}){return new Tt(i,t)}class Kt{container;containerA;containerB;adapterA;adapterB;timelineA=null;timelineB=null;symbolDefs=new Map;nestedByAdapter=new Map;sequence=null;options;_currentSceneIndex=0;_state="idle";_isPlaying=!1;_isDestroyed=!1;loopIteration=0;animationFrameId;lastTime;transitionTimer;constructor(t,e={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=e,this.container.style.position="relative",this.container.style.overflow="hidden",this.containerA=this.createSceneContainer(),this.containerB=this.createSceneContainer(),this.container.appendChild(this.containerA),this.container.appendChild(this.containerB),this.containerB.style.visibility="hidden",this.adapterA=new j,this.adapterB=new j}async load(t){let e;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load sequence: ${s.statusText}`);e=await s.json()}else e=t;this.sequence=e,this.symbolDefs.clear();for(const s of e.symbols??[])s.timeline?.tracks?.length&&this.symbolDefs.set(s.id,s.timeline);this.container.style.width=`${e.canvas.width}px`,this.container.style.height=`${e.canvas.height}px`,e.scenes.length>0&&(this.renderScene(e.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(e.scenes[0])),this.options.autoplay&&this.play()}play(){if(!(!this.sequence||this._isDestroyed)&&this.sequence.scenes.length!==0){if(this._isPlaying=!0,this._state==="idle"){if(this._state="playing-scene",this._currentSceneIndex=0,this.timelineA)this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play();else{this.onSceneComplete();return}this.options.onSceneChange?.(0)}else this._state==="playing-scene"&&this.timelineA&&this.timelineA.play();this.startAnimationLoop()}}pause(){this._isPlaying&&(this._isPlaying=!1,this.timelineA&&this.timelineA.pause(),this.timelineB&&this.timelineB.pause(),this.stopAnimationLoop())}stop(){if(this._isPlaying=!1,this._state="idle",this._currentSceneIndex=0,this.loopIteration=0,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.stopAnimationLoop(),this.sequence&&this.sequence.scenes.length>0&&(this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this.renderScene(this.sequence.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(this.sequence.scenes[0]),this.timelineA)){const t=this.timelineA.getStateAtTime(0);this.adapterA.applyState(t),this.applyNested(this.adapterA,0)}}goToScene(t){if(!this.sequence||t<0||t>=this.sequence.scenes.length)return;const e=this._isPlaying;this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this._currentSceneIndex=t,this._state=e?"playing-scene":"idle",this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB);const s=this.sequence.scenes[t];if(this.renderScene(s,this.containerA,this.adapterA),this.timelineA=this.createTimeline(s),this.options.onSceneChange?.(t),e)this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play(),this.startAnimationLoop()):this.onSceneComplete();else if(this.timelineA){const n=this.timelineA.getStateAtTime(0);this.adapterA.applyState(n),this.applyNested(this.adapterA,0)}}destroy(){this._isDestroyed=!0,this._isPlaying=!1,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.adapterA.clearTargets(),this.adapterB.clearTargets();for(const t of this.nestedByAdapter.values())for(const e of t)e.adapter.clearTargets();this.nestedByAdapter.clear(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.timelineA=null,this.timelineB=null,this.containerA.parentNode&&this.containerA.remove(),this.containerB.parentNode&&this.containerB.remove(),this.sequence=null}get currentSceneIndex(){return this._currentSceneIndex}get sceneCount(){return this.sequence?.scenes.length??0}get isPlaying(){return this._isPlaying}get state(){return this._state}createSceneContainer(){const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.width="100%",t.style.height="100%",t}renderScene(t,e,s){e.innerHTML="",s.clearTargets();const n=document.createElement("div");n.style.cssText="position:absolute;inset:0;transform-origin:center center",n.setAttribute("data-tinyfly","Camera"),e.appendChild(n),s.registerTarget("Camera",n);for(const r of t.elements){if(!r.html)continue;const a=document.createElement("div");a.innerHTML=r.html.trim();const o=a.firstElementChild;if(o){n.appendChild(o);const c=o.getAttribute("data-tinyfly");c&&s.registerTarget(c,o)}}this.setupNested(n,s)}setupNested(t,e){const s=[];t.querySelectorAll("[data-tinyfly-symbol]").forEach(n=>{const r=n.getAttribute("data-tinyfly-symbol");if(!r)return;const a=this.symbolDefs.get(r);if(!a)return;const o=new j;n.querySelectorAll("[data-tinyfly]").forEach(c=>{const h=c.getAttribute("data-tinyfly");h&&o.registerTarget(h,c)}),s.push({adapter:o,timeline:tt(a)})}),s.length?this.nestedByAdapter.set(e,s):this.nestedByAdapter.delete(e)}applyNested(t,e){const s=this.nestedByAdapter.get(t);if(s)for(const n of s){const r=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(r>0?e%r:e))}}clearContainer(t){t.innerHTML=""}createTimeline(t){return t.timeline?tt(t.timeline):null}onSceneComplete(){if(this._isDestroyed||!this.sequence)return;const t=this._currentSceneIndex+1;if(t>=this.sequence.scenes.length){const e=this.options.loop??this.sequence.loop??0;e===-1||e>0&&this.loopIteration<e-1?(this.loopIteration++,this.beginTransitionTo(0)):(this._isPlaying=!1,this._state="idle",this.stopAnimationLoop(),this.options.onComplete?.())}else this.beginTransitionTo(t)}beginTransitionTo(t){if(!this.sequence||this._isDestroyed)return;const e=this.sequence.scenes[t],s=e.transition;if(s.type==="none"||s.duration<=0){this.switchToScene(t);return}this._state="transitioning",this.containerB.style.visibility="visible",this.renderScene(e,this.containerB,this.adapterB),this.timelineB=this.createTimeline(e),this.timelineB&&this.timelineB.play(),this.applyTransition(s.type,s.duration),this.transitionTimer=window.setTimeout(()=>{this.finishTransition(t)},s.duration)}applyTransition(t,e){const s=`${e}ms`,n="ease-in-out";switch(this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),t){case"fade":this.containerB.style.opacity="0";break;case"slide-left":this.containerB.style.transform="translateX(100%)";break;case"slide-right":this.containerB.style.transform="translateX(-100%)";break;case"slide-up":this.containerB.style.transform="translateY(100%)";break;case"slide-down":this.containerB.style.transform="translateY(-100%)";break}switch(this.containerB.offsetHeight,this.containerA.style.transition=`opacity ${s} ${n}, transform ${s} ${n}`,this.containerB.style.transition=`opacity ${s} ${n}, transform ${s} ${n}`,t){case"fade":this.containerA.style.opacity="0",this.containerB.style.opacity="1";break;case"slide-left":this.containerA.style.transform="translateX(-100%)",this.containerB.style.transform="translateX(0)";break;case"slide-right":this.containerA.style.transform="translateX(100%)",this.containerB.style.transform="translateX(0)";break;case"slide-up":this.containerA.style.transform="translateY(-100%)",this.containerB.style.transform="translateY(0)";break;case"slide-down":this.containerA.style.transform="translateY(100%)",this.containerB.style.transform="translateY(0)";break}}resetTransitionStyles(t){t.style.transition="",t.style.opacity="1",t.style.transform=""}finishTransition(t){this.transitionTimer=void 0,this.timelineA&&(this.timelineA.stop(),this.timelineA=null),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.containerA;this.containerA=this.containerB,this.containerB=e;const s=this.adapterA;this.adapterA=this.adapterB,this.adapterB=s,this.timelineA=this.timelineB,this.timelineB=null,this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.playbackState!=="playing"&&this.timelineA.play()):this.onSceneComplete()}switchToScene(t){if(!this.sequence||this._isDestroyed)return;this.timelineA&&this.timelineA.stop(),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.sequence.scenes[t];this.renderScene(e,this.containerA,this.adapterA),this.timelineA=this.createTimeline(e),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play()):this.onSceneComplete()}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=e=>{if(this._isDestroyed||!this._isPlaying)return;const s=e-(this.lastTime??e);if(this.lastTime=e,this.timelineA&&this.timelineA.playbackState==="playing"){this.timelineA.tick(s);const n=this.timelineA.getStateAtTime(this.timelineA.currentTime);this.adapterA.applyState(n),this.applyNested(this.adapterA,this.timelineA.currentTime)}if(this._state==="transitioning"&&this.timelineB&&this.timelineB.playbackState==="playing"){this.timelineB.tick(s);const n=this.timelineB.getStateAtTime(this.timelineB.currentTime);this.adapterB.applyState(n),this.applyNested(this.adapterB,this.timelineB.currentTime)}this._isPlaying?this.animationFrameId=requestAnimationFrame(t):this.animationFrameId=void 0};this.animationFrameId=requestAnimationFrame(t)}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}}async function Oi(i,t,e={}){const s=new Kt(i,{...e,autoplay:!0});return await s.load(t),s}const Li={type:"none",duration:0};v.DEFAULT_TRANSITION=Li,v.MediaSync=gt,v.TinyflyPlayer=Tt,v.TinyflySequencer=Kt,v.create=Bi,v.play=Ei,v.playSequence=Oi,v.syncMediaElement=Zt,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Bloom: light spilling around what is bright, the glow of neon. Applied to
3
+ * a canvas after drawing: the bright parts are found at a reduced size,
4
+ * blurred twice (a tight glow and a wide halo) and added back over the
5
+ * picture.
6
+ *
7
+ * Deterministic: the blur is plain arithmetic (no `ctx.filter`), so the same
8
+ * frame blooms the same in every browser and in Node.
9
+ */
10
+ export interface BloomOptions {
11
+ /**
12
+ * How bright a pixel must be to glow, 0..1, by its brightest channel (so a
13
+ * saturated neon magenta counts as bright). Default 0.55.
14
+ */
15
+ threshold?: number;
16
+ /** How strongly the glow is added, 0.. (default 0.9) */
17
+ strength?: number;
18
+ /** The glow's reach, px at the canvas's size (default 2% of its larger side); the halo reaches 3× further */
19
+ radius?: number;
20
+ /** Work at 1/n of the size: faster and softer (default 4) */
21
+ downsample?: number;
22
+ /** How much of the wide halo joins the glow, 0..1 (default 0.6) */
23
+ halo?: number;
24
+ }
25
+ /**
26
+ * What glows: each pixel scaled by how far its brightest channel is past the
27
+ * threshold (keeping its hue), as linear RGB floats (3 per pixel).
28
+ */
29
+ export declare function brightPass(data: ArrayLike<number>, threshold: number): Float32Array;
30
+ /** A soft blur close to a Gaussian: three box blurs each way. */
31
+ export declare function boxBlur(source: Float32Array, width: number, height: number, radius: number): Float32Array;
32
+ /** Add a bloom to what is already drawn on `ctx` (its whole canvas, in device pixels). */
33
+ export declare function applyBloom(ctx: CanvasRenderingContext2D, options?: BloomOptions): void;
@@ -33,6 +33,14 @@ export interface CanvasTargetBase {
33
33
  rotate?: number;
34
34
  rotateX?: number;
35
35
  rotateY?: number;
36
+ /** Depth toward the viewer, px (CSS `translateZ`); shows with `perspective` */
37
+ z?: number;
38
+ /** A rotation as an `[x, y, z, w]` quaternion (a track with `interpolation: 'slerp'`) */
39
+ quaternion?: number[];
40
+ /** Distance from the viewer, px (CSS `perspective()`): nearer parts grow, further ones shrink */
41
+ perspective?: number;
42
+ /** `'hidden'`: not drawn while its back faces the viewer (a card's face, past 90°) */
43
+ backfaceVisibility?: 'visible' | 'hidden';
36
44
  scale?: number;
37
45
  scaleX?: number;
38
46
  scaleY?: number;
@@ -143,6 +151,12 @@ export interface CustomTarget extends CanvasTargetBase {
143
151
  draw: CustomDrawFunction;
144
152
  /** Values the draw function reads, with their initial values */
145
153
  props?: Record<string, AnimatableValue>;
154
+ /**
155
+ * Also route properties not declared in `props` when this says yes: for a
156
+ * target whose animated values cannot all be listed up front (a 3D scene,
157
+ * whose tracks name its objects: `cube.rotateY`). They land in `props`.
158
+ */
159
+ acceptsProp?: (property: string) => boolean;
146
160
  }
147
161
  /** Union of all canvas target types */
148
162
  export type CanvasTarget = RectTarget | CircleTarget | TextTarget | LineTarget | PathTarget | ImageTarget | CustomTarget;
@@ -157,6 +171,8 @@ export declare class CanvasAdapter {
157
171
  private animationOffsets;
158
172
  private aliases;
159
173
  private time;
174
+ /** Offscreen layer for see-through targets in perspective (see `drawInPerspective`) */
175
+ private layer;
160
176
  /**
161
177
  * Register a canvas drawing target.
162
178
  * @param id - The ID to register the target under
@@ -200,6 +216,26 @@ export declare class CanvasAdapter {
200
216
  * Render a single target.
201
217
  */
202
218
  private renderTarget;
219
+ /**
220
+ * Draw a target in perspective: each triangle of a mesh over its bounds is
221
+ * clipped on the canvas and drawn with the 2D transform that carries it
222
+ * there. The triangles overlap by a pixel so no anti-aliased seam shows.
223
+ */
224
+ private drawInPerspective;
225
+ private drawMesh;
226
+ /** A cleared offscreen canvas the size of `ctx`'s, reused frame to frame; null where none can be made. */
227
+ private perspectiveLayer;
228
+ /**
229
+ * Everything a target paints, generously: its box, measured text, a path's
230
+ * control points, plus room for its stroke, blur and glow. The perspective
231
+ * mesh covers this, so nothing it draws falls outside.
232
+ */
233
+ private contentBounds;
234
+ /**
235
+ * Paint a target in the current transform: its fill and stroke styles,
236
+ * filter and clip, then its shape.
237
+ */
238
+ private drawContent;
203
239
  /**
204
240
  * Resolve a fill style to a canvas-compatible value.
205
241
  */
@@ -2,3 +2,5 @@ export * from './canvas-adapter';
2
2
  export * from './sketch';
3
3
  export * from './polyline';
4
4
  export * from './outline';
5
+ export * from './bloom';
6
+ export * from './offscreen';
@@ -0,0 +1,13 @@
1
+ /** A canvas that can be drawn on and drawn from: OffscreenCanvas, a DOM canvas, or a Node canvas. */
2
+ export interface CanvasLike {
3
+ width: number;
4
+ height: number;
5
+ getContext(kind: '2d'): unknown;
6
+ }
7
+ /**
8
+ * An offscreen canvas of the same kind as `ctx`'s: an OffscreenCanvas where
9
+ * there is one (browsers, Workers), else a DOM canvas from `ctx`'s document,
10
+ * else the same canvas class (`@napi-rs/canvas` in Node). Null when none can
11
+ * be made.
12
+ */
13
+ export declare function canvasLike(ctx: CanvasRenderingContext2D, width: number, height: number): CanvasLike | null;
@@ -0,0 +1,99 @@
1
+ import { type Mat4 } from '../engine/math';
2
+ /**
3
+ * CSS-style 3D transforms for flat targets (Canvas and WebGL), as pure functions.
4
+ *
5
+ * A target's transform is the same 4×4 matrix CSS builds from its transform
6
+ * list, about the target's pivot (its transform-origin):
7
+ *
8
+ * pivot · perspective · translate(x, y, z) · rotate · rotateX · rotateY ·
9
+ * quaternion · scale · skew · pivot⁻¹
10
+ *
11
+ * the order the DOM and SVG adapters write the functions in, so a target
12
+ * lands on the same pixels in all three. Without perspective the matrix keeps
13
+ * flat things flat, and its x / y part is an ordinary 2D canvas transform
14
+ * (exact). With perspective, the target is drawn through a mesh of small
15
+ * triangles, each a 2D transform of its own (see `perspectiveMesh`).
16
+ */
17
+ export interface Transform3DValues {
18
+ z?: number;
19
+ rotate?: number;
20
+ rotateX?: number;
21
+ rotateY?: number;
22
+ /** `[x, y, z, w]`; a track with `interpolation: 'slerp'` */
23
+ quaternion?: number[];
24
+ scale?: number;
25
+ scaleX?: number;
26
+ scaleY?: number;
27
+ skewX?: number;
28
+ skewY?: number;
29
+ /** Distance from the viewer, px (CSS `perspective()`); none means no foreshortening */
30
+ perspective?: number;
31
+ }
32
+ export interface Point {
33
+ x: number;
34
+ y: number;
35
+ }
36
+ /**
37
+ * A quaternion as a CSS `matrix3d()`: its rotation matrix, column-major as CSS
38
+ * reads it (null for anything that is not 4 numbers). The DOM and SVG adapters
39
+ * write a `quaternion` value with it.
40
+ */
41
+ export declare function quaternionCss(value: unknown): string | null;
42
+ /** Whether a target needs the 3D path: anything with depth, a 3D turn or perspective. */
43
+ export declare function has3dTransform(t: Transform3DValues): boolean;
44
+ /**
45
+ * The target's whole transform: `offset` is its animated x / y, `pivot` its
46
+ * transform-origin, both in canvas coordinates. `scale` wins over
47
+ * `scaleX` / `scaleY`, as in the 2D canvas transform.
48
+ */
49
+ export declare function elementMatrix(t: Transform3DValues, offset: Point, pivot: Point): Mat4;
50
+ /** No perspective: flat stays flat, and the x / y part is an exact 2D transform. */
51
+ export declare function isAffine(m: Mat4): boolean;
52
+ /** The 2D canvas transform `[a, b, c, d, e, f]` of an affine matrix (its x / y part). */
53
+ export declare function affinePart(m: Mat4): [number, number, number, number, number, number];
54
+ /**
55
+ * Whether the target shows its back, as CSS decides it for
56
+ * `backface-visibility: hidden`: its front normal, carried through the
57
+ * transform, points away from the viewer. A mirror (`scaleX: -1`) is not a
58
+ * back.
59
+ */
60
+ export declare function isBackFacing(m: Mat4): boolean;
61
+ /** Where a point of the target's plane lands on the canvas; null behind the viewer. */
62
+ export declare function projectPoint(m: Mat4, x: number, y: number): Point | null;
63
+ /**
64
+ * The 2D transform `[a, b, c, d, e, f]` that carries triangle `from` onto
65
+ * triangle `to` (null when `from` is degenerate).
66
+ */
67
+ export declare function triangleTransform(from: [Point, Point, Point], to: [Point, Point, Point]): [number, number, number, number, number, number] | null;
68
+ export interface MeshTriangle {
69
+ /** In the target's own plane (canvas coordinates before the transform) */
70
+ source: [Point, Point, Point];
71
+ /** On the canvas, after the transform */
72
+ target: [Point, Point, Point];
73
+ }
74
+ /** Cells per side of a perspective mesh: finer for bigger and more slanted targets. */
75
+ export declare function meshDivisions(m: Mat4, bounds: {
76
+ x: number;
77
+ y: number;
78
+ width: number;
79
+ height: number;
80
+ }): number;
81
+ /**
82
+ * The target's bounds cut into a grid of triangles, each with where it lands.
83
+ * Close enough to the true (curved-in-texture) perspective that a 40 px cell
84
+ * is off by well under a pixel. Triangles with a corner behind the viewer are
85
+ * left out.
86
+ */
87
+ export declare function perspectiveMesh(m: Mat4, bounds: {
88
+ x: number;
89
+ y: number;
90
+ width: number;
91
+ height: number;
92
+ }, divisions?: number): MeshTriangle[];
93
+ /**
94
+ * A triangle with each edge pushed outward by `amount` px, so neighbouring
95
+ * clipped triangles overlap a little and no anti-aliased seam shows between
96
+ * them. Each corner moves along its bisector, as far as keeps both of its
97
+ * edges `amount` out (capped, so needle-thin corners do not shoot off).
98
+ */
99
+ export declare function growTriangle(points: [Point, Point, Point], amount: number): [Point, Point, Point];
@@ -24,6 +24,16 @@ export interface WebGLTarget {
24
24
  opacity?: number;
25
25
  /** Degrees, clockwise */
26
26
  rotate?: number;
27
+ /** 3D turns, degrees (CSS `rotateX` / `rotateY`), and depth toward the viewer, px */
28
+ rotateX?: number;
29
+ rotateY?: number;
30
+ z?: number;
31
+ /** A rotation as an `[x, y, z, w]` quaternion (a track with `interpolation: 'slerp'`) */
32
+ quaternion?: number[];
33
+ /** Distance from the viewer, px (CSS `perspective()`) */
34
+ perspective?: number;
35
+ /** `'hidden'`: not drawn while its back faces the viewer */
36
+ backfaceVisibility?: 'visible' | 'hidden';
27
37
  scale?: number;
28
38
  scaleX?: number;
29
39
  scaleY?: number;
@@ -65,5 +75,12 @@ export declare class WebGLAdapter {
65
75
  * in clip space. Column-major, as WebGL expects.
66
76
  */
67
77
  export declare function quadMatrix(target: WebGLTarget, canvasWidth: number, canvasHeight: number): Float32Array;
78
+ /**
79
+ * Build the 4x4 matrix that maps the unit quad to the target's place on the
80
+ * canvas in clip space, with perspective in w. Column-major, as WebGL
81
+ * expects. Depth is flattened (targets draw in order), so nothing is clipped
82
+ * for being near or far.
83
+ */
84
+ export declare function quadMatrix3d(target: WebGLTarget, canvasWidth: number, canvasHeight: number): Float32Array;
68
85
  /** Parse #rgb / #rrggbb into 0..1 components. Unknown input renders white. */
69
86
  export declare function parseColor(color: string): [number, number, number];
@@ -47,6 +47,8 @@ export * from '../drivers';
47
47
  export * from '../interaction';
48
48
  export * from '../characters';
49
49
  export { tf, live, createLive, Stage, LiveTimeline, CompatTimeline, quickPlay, mapEase, CustomEase, CustomBounce, CustomWiggle, } from '../compat/gsap';
50
+ export { applyBloom } from '../adapters/canvas/bloom';
51
+ export type { BloomOptions } from '../adapters/canvas/bloom';
50
52
  export { createControls, DEFAULT_LABELS } from '../embed/controls';
51
53
  export type { Controls, ControlsOptions, ControlLabels, FullscreenControl } from '../embed/controls';
52
54
  export { mount, mountAll, unmount } from '../embed/mount';
@@ -3,7 +3,7 @@ import type { EasingType, Track } from '../engine/types';
3
3
  import type { Point } from '../adapters/canvas/sketch';
4
4
  import type { FrameInfo } from '../headless/video-scene';
5
5
  import type { BodyPlan, Pose, Vec3 } from './rig/body-plan';
6
- import { type SolvedHead } from './rig/skeleton';
6
+ import { type SolvedHead, type ViewProjection } from './rig/skeleton';
7
7
  import { type Look, type Pen, type PencilOptions } from './look/pen';
8
8
  import { type HumanPoseName } from './species/human';
9
9
  import { type HandPose } from './hands/hand-rig';
@@ -134,6 +134,25 @@ export declare function characterHandPose(pose: Pose, side: 'left' | 'right'): H
134
134
  * pencil's boil frame and is passed to layer hooks.
135
135
  */
136
136
  export declare function drawCharacter(ctx: CanvasRenderingContext2D, character: Character, pose: Pose, time?: number): void;
137
+ export interface InViewOptions {
138
+ /** The character's height in the projection's units (metres in a 3D scene) */
139
+ height: number;
140
+ /** ms: the pencil's boil frame, and layer hooks */
141
+ time?: number;
142
+ }
143
+ /**
144
+ * Where every part of a character is when seen through a camera (see
145
+ * {@link skeletonInView}): canvas px, sized by the perspective at its hips.
146
+ */
147
+ export declare function characterJointsInView(character: Character, pose: Pose, projection: ViewProjection, options: InViewOptions): CharacterJoints;
148
+ /**
149
+ * Draw a character seen through a camera: a 3D scene's, or any
150
+ * `projection`. Its turn, roll, lift and ground contact work as front-on;
151
+ * the camera can look from anywhere, so it is drawn in perspective, in its
152
+ * look (clean, pencil, silhouette) and with its face, hands and layers. The
153
+ * canvas is drawn on as it is (no translation to the feet).
154
+ */
155
+ export declare function drawCharacterInView(ctx: CanvasRenderingContext2D, character: Character, pose: Pose, projection: ViewProjection, options: InViewOptions): void;
137
156
  /** A full blend of two poses: `t` 0 is `from`, 1 is `to`. Fields in only one keep its value. */
138
157
  export declare function mixPoses(from: Pose, to: Pose, t: number): Pose;
139
158
  /**
@@ -8,6 +8,8 @@ export * from './stick-figure';
8
8
  export * from './dance';
9
9
  export * from './acrobatics';
10
10
  export { stickToHuman } from './stick-to-human';
11
+ export { skeletonInView, solvePlanSpace, stagePlanSpace, type ViewProjection, type PlanSpace, type StagedSpace } from './rig/skeleton';
12
+ export { characterObjects } from './scene-objects';
11
13
  export * from '../adapters/canvas/sketch';
12
14
  export * from './erase';
13
15
  export * from '../adapters/canvas/polyline';
@@ -9,7 +9,9 @@
9
9
  * Space: +x is the character's left, +y is up, +z is the way it faces. The
10
10
  * hips sit on the y axis; the ground under them is y = 0.
11
11
  */
12
- export type Vec3 = [number, number, number];
12
+ import type { Vec3 } from '../../engine/math';
13
+ /** A point or direction, `[x, y, z]` (the engine's 3D math type). */
14
+ export type { Vec3 };
13
15
  export interface BoneSpec {
14
16
  /** Length, fraction of the height */
15
17
  length: number;