@algorisys/tinyfly 0.115.0 → 0.117.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +11 -6
  2. package/docs/api-reference.md +2 -1
  3. package/docs/editor-guide.md +1 -1
  4. package/docs/examples.md +1 -1
  5. package/docs/getting-started.md +1 -1
  6. package/docs/gsap-compat.md +1 -1
  7. package/docs/llm-guide.md +18 -0
  8. package/docs/maps.md +2 -2
  9. package/docs/math.md +313 -0
  10. package/docs/teaching.md +1 -1
  11. package/lib/addons/characters.js +2614 -2548
  12. package/lib/addons/math.js +3384 -0
  13. package/lib/browser/tinyfly-math.iife.js +53 -0
  14. package/lib/browser/tinyfly.iife.js +12 -12
  15. package/lib/browser/tinyfly.js +993 -905
  16. package/lib/browser/tinyfly.umd.js +12 -12
  17. package/lib/embed/tinyfly-embed.iife.js +1 -1
  18. package/lib/embed/tinyfly-embed.js +8 -0
  19. package/lib/engine/tinyfly-engine.js +112 -98
  20. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  21. package/lib/player/tinyfly-player.es.js +8 -0
  22. package/lib/player/tinyfly-player.iife.js +1 -1
  23. package/lib/player/tinyfly-player.umd.js +1 -1
  24. package/lib/types/characters/capabilities.d.ts +8 -0
  25. package/lib/types/engine/authoring/random.d.ts +7 -0
  26. package/lib/types/math/browser-entry.d.ts +3 -0
  27. package/lib/types/math/embed/auto-mount-math.d.ts +7 -0
  28. package/lib/types/math/embed/explorable.d.ts +46 -0
  29. package/lib/types/math/embed/mount-math.d.ts +31 -0
  30. package/lib/types/math/expr/differentiate.d.ts +7 -0
  31. package/lib/types/math/expr/evaluate.d.ts +21 -0
  32. package/lib/types/math/expr/parse-expression.d.ts +50 -0
  33. package/lib/types/math/figure/derived.d.ts +17 -0
  34. package/lib/types/math/figure/display-list.d.ts +87 -0
  35. package/lib/types/math/figure/figure-spec.d.ts +349 -0
  36. package/lib/types/math/figure/item-context.d.ts +39 -0
  37. package/lib/types/math/figure/items/calculus.d.ts +7 -0
  38. package/lib/types/math/figure/items/curves.d.ts +7 -0
  39. package/lib/types/math/figure/items/grid.d.ts +5 -0
  40. package/lib/types/math/figure/items/probability.d.ts +13 -0
  41. package/lib/types/math/figure/items/regions.d.ts +5 -0
  42. package/lib/types/math/figure/items/text.d.ts +5 -0
  43. package/lib/types/math/figure/items/vectors.d.ts +9 -0
  44. package/lib/types/math/figure/layout-figure.d.ts +13 -0
  45. package/lib/types/math/figure/plane.d.ts +20 -0
  46. package/lib/types/math/figure/validate-spec.d.ts +2 -0
  47. package/lib/types/math/index.d.ts +49 -0
  48. package/lib/types/math/linear/mat2.d.ts +41 -0
  49. package/lib/types/math/linear/vec2.d.ts +18 -0
  50. package/lib/types/math/presets/calculus.d.ts +59 -0
  51. package/lib/types/math/presets/linear-algebra.d.ts +42 -0
  52. package/lib/types/math/presets/probability.d.ts +62 -0
  53. package/lib/types/math/prob/bayes.d.ts +16 -0
  54. package/lib/types/math/prob/distributions.d.ts +58 -0
  55. package/lib/types/math/prob/galton.d.ts +18 -0
  56. package/lib/types/math/prob/histogram.d.ts +20 -0
  57. package/lib/types/math/prob/scatter.d.ts +24 -0
  58. package/lib/types/math/render/arrow.d.ts +10 -0
  59. package/lib/types/math/render/display-list-to-svg.d.ts +10 -0
  60. package/lib/types/math/render/draw-display-list.d.ts +6 -0
  61. package/lib/types/math/steps/math-steps.d.ts +34 -0
  62. package/lib/types/math/targets/math-target.d.ts +43 -0
  63. package/lib/types/math/tex/equation-morph.d.ts +21 -0
  64. package/lib/types/math/tex/glyph-metrics.d.ts +24 -0
  65. package/lib/types/math/tex/tex-layout.d.ts +59 -0
  66. package/lib/types/math/tex/tex-parser.d.ts +88 -0
  67. package/lib/types/player/player.d.ts +6 -0
  68. package/llms-full.txt +400 -10
  69. package/llms.txt +32 -31
  70. package/package.json +6 -2
  71. package/skills/tinyfly/SKILL.md +12 -0
@@ -1,5 +1,5 @@
1
1
  (function($){"use strict";function pe(e){return typeof e=="object"&&e!==null&&e.type==="cubic-bezier"}function me(e){return typeof e=="object"&&e!==null&&e.type!=="cubic-bezier"}const et=2;function ge(e){return e.some(t=>t.interpolation!==void 0)?2:1}function At(e){return e.property==="text"&&"textConfig"in e}function ht(e){return e.kind==="inertia"&&"inertia"in e}function ut(e){return e.kind==="spring"&&"spring"in e}function ye(e){return e.property==="motionPath"&&"motionPathConfig"in e}function be(e,t){if(!(t>0))return e;const n=1e3/t;return Math.floor(e/n+1e-9)*n}function Et(e,t,n="start"){if(t<=1)return 0;if(typeof n=="number"){const i=Math.max(0,Math.min(t-1,n));return Math.abs(e-i)}switch(n){case"end":return t-1-e;case"center":return Math.abs(e-(t-1)/2);case"edges":return(t-1)/2-Math.abs(e-(t-1)/2);default:return e}}function ve(e,t="start"){if(e<=1)return 0;let n=0;for(let i=0;i<e;i++)n=Math.max(n,Et(i,e,t));return n}function Pt(e,t,n){if(n.offsets)return n.offsets[e]??0;const i=n.from??"start",s=Et(e,t,i);if(n.amount!==void 0){const r=ve(t,i);return r===0?0:n.amount*s/r}return n.each!==void 0?n.each*s:0}function ke(e,t){return Array.from({length:e},(n,i)=>Pt(i,e,t))}function dt(e,t){return e<=1?0:Math.max(...ke(e,t))}const H=1,Ct=6e4,nt=Ct/H,B={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1};class we{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??B.stiffness,this.damping=t.damping??B.damping,this.mass=t.mass??B.mass,this.restDelta=t.restDelta??B.restDelta,this.restSpeed=t.restSpeed??B.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=t.velocity??B.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 n=Math.floor(t/H);if(this.simulateTo(n+1),this.settledStep!==null&&n>=this.settledStep)return this.to;const i=this.samples[Math.min(n,this.samples.length-1)],s=this.samples[Math.min(n+1,this.samples.length-1)],r=t/H-n;return i+(s-i)*r}settleTime(){return this.simulateTo(nt+1),this.settledStep!==null?this.settledStep*H:Ct}simulateTo(t){if(this.settledStep!==null)return;const n=Math.min(t,nt+1),i=H/1e3;for(;this.samples.length<n;){const s=this.samples[this.samples.length-1],r=s-this.to,a=-this.stiffness*r,o=-this.damping*this.velocity,c=(a+o)/this.mass;this.velocity+=c*i;const l=s+this.velocity*i;if(this.samples.push(l),this.isAtRest(l)){this.settledStep=this.samples.length-1;return}}this.samples.length>nt&&(this.settledStep=nt)}}const It=4,xe=.002,Me=1e-4,Se=6e4;function ft(e){const t=e.friction??It;return t>0?t:It}function Te(e){return e.from+e.velocity/ft(e)}function _e(e,t){if(t===void 0)return e;if(typeof t=="number")return t>0?Math.round(e/t)*t:e;if(t.length===0)return e;let n=t[0];for(const i of t)Math.abs(i-e)<Math.abs(n-e)&&(n=i);return n}function Rt(e){let t=_e(Te(e),e.end);return e.min!==void 0&&(t=Math.max(e.min,t)),e.max!==void 0&&(t=Math.min(e.max,t)),t}function $t(e){const t=Math.abs(Rt(e)-e.from);if(t===0)return 0;const n=e.restDelta??Math.max(Me,t*xe);if(n>=t)return 0;const i=Math.log(t/n)/ft(e);return Math.min(Se,i*1e3)}function Lt(e,t){if(t<=0)return e.from;const n=Rt(e);if(t>=$t(e))return n;const i=ft(e);return e.from+(n-e.from)*(1-Math.exp(-i*t/1e3))}const pt=e=>e,Ae=e=>e*e,Ee=e=>1-(1-e)*(1-e),Pe=e=>e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2,Dt=e=>e*e*e,Ot=e=>1-Math.pow(1-e,3),Nt=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,Ce={linear:pt,"ease-in":Dt,"ease-out":Ot,"ease-in-out":Nt,"ease-in-quad":Ae,"ease-out-quad":Ee,"ease-in-out-quad":Pe,"ease-in-cubic":Dt,"ease-out-cubic":Ot,"ease-in-out-cubic":Nt};function Ie(e){const[t,n,i,s]=e,r=3*t,a=3*(i-t)-r,o=1-r-a,c=3*n,l=3*(s-n)-c,u=1-c-l,h=d=>((o*d+a)*d+r)*d,f=d=>((u*d+l)*d+c)*d,m=d=>(3*o*d+2*a)*d+r,p=d=>{let g=d;for(let k=0;k<8;k++){const M=h(g)-d;if(Math.abs(M)<1e-7)return g;const y=m(g);if(Math.abs(y)<1e-7)break;g-=M/y}let b=0,v=1;for(g=d;b<v;){const k=h(g);if(Math.abs(k-d)<1e-7)return g;d>k?b=g:v=g,g=(b+v)/2}return g};return d=>{if(d<=0)return 0;if(d>=1)return 1;const g=p(d);return f(g)}}function mt(e,t="out"){if(t==="out")return e;const n=i=>1-e(1-i);return t==="in"?n:i=>i<.5?n(i*2)/2:e(i*2-1)/2+.5}function Re(e=1,t=.3){const n=Math.max(1,e),i=t/(2*Math.PI)*Math.asin(1/n);return s=>s<=0?0:s>=1?1:n*Math.pow(2,-10*s)*Math.sin((s-i)*(2*Math.PI)/t)+1}const $e=e=>{if(e<=0)return 0;if(e>=1)return 1;if(e<1/2.75)return 7.5625*e*e;if(e<2/2.75){const s=e-.5454545454545454;return 7.5625*s*s+.75}if(e<2.5/2.75){const s=e-.8181818181818182;return 7.5625*s*s+.9375}const i=e-2.625/2.75;return 7.5625*i*i+.984375};function Le(e=1.70158){return t=>{if(t<=0)return 0;if(t>=1)return 1;const n=t-1;return n*n*((e+1)*n+e)+1}}function De(e,t="end"){const n=Math.max(1,Math.floor(e));return i=>{if(i>=1)return 1;if(i<=0)return t==="start"||t==="both"?t==="start"?1/n:1/(n+1):0;const s=Math.floor(i*n);switch(t){case"start":return Math.min(1,(s+1)/n);case"both":return(s+1)/(n+1);case"none":return n===1?0:Math.min(1,s/(n-1));default:return s/n}}}function Oe(e){switch(e.type){case"steps":return De(e.count,e.position);case"elastic":return mt(Re(e.amplitude,e.period),e.mode);case"bounce":return mt($e,e.mode);case"back":return mt(Le(e.overshoot),e.mode)}}function Ne(e){return e===void 0?pt:pe(e)?Ie(e.points):me(e)?Oe(e):Ce[e]??pt}const Ft=32,Fe=256,z=new Map,Xe=/[MmLlHhVvCcSsQqTtAaZz]/,Ye=/^[-+]?(?:\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 qe(e){const t=[];let n=0,i=null;const s=()=>{for(;n<e.length&&/[\s,]/.test(e[n]);)n++};for(;n<e.length&&(s(),!(n>=e.length));){const r=e[n];if(Xe.test(r)){i={type:r,args:[]},t.push(i),n++;continue}if(!i)break;const a=i.type==="A"||i.type==="a",o=i.args.length%7;if(a&&(o===3||o===4)){if(r!=="0"&&r!=="1")break;i.args.push(r==="1"?1:0),n++;continue}const c=Ye.exec(e.slice(n));if(!c)break;i.args.push(parseFloat(c[0])),n+=c[0].length}return t}function We(e,t,n,i,s,r,a,o,c){if(e===o&&t===c)return[];let l=Math.abs(n),u=Math.abs(i);if(l===0||u===0)return[[e,t,o,c,o,c]];const h=s*Math.PI/180,f=Math.cos(h),m=Math.sin(h),p=(e-o)/2,d=(t-c)/2,g=f*p+m*d,b=-m*p+f*d,v=g*g/(l*l)+b*b/(u*u);if(v>1){const A=Math.sqrt(v);l*=A,u*=A}const k=r===a?-1:1,M=l*l*u*u-l*l*b*b-u*u*g*g,y=l*l*b*b+u*u*g*g,S=k*Math.sqrt(Math.max(0,M/y)),w=S*l*b/u,P=-S*u*g/l,W=f*w-m*P+(e+o)/2,T=m*w+f*P+(t+c)/2,R=(A,I,D,j)=>{const _t=A*D+I*j,lt=Math.sqrt((A*A+I*I)*(D*D+j*j)),tt=Math.acos(Math.max(-1,Math.min(1,_t/lt)));return A*j-I*D<0?-tt:tt},_=R(1,0,(g-w)/l,(b-P)/u);let C=R((g-w)/l,(b-P)/u,(-g-w)/l,(-b-P)/u);!a&&C>0&&(C-=2*Math.PI),a&&C<0&&(C+=2*Math.PI);const O=Math.max(1,Math.ceil(Math.abs(C)/(Math.PI/2))),x=C/O,E=4/3*Math.tan(x/4),F=A=>{const I=l*Math.cos(A),D=u*Math.sin(A);return[f*I-m*D+W,m*I+f*D+T]},N=A=>{const I=-l*Math.sin(A),D=u*Math.cos(A);return[f*I-m*D,m*I+f*D]},L=[];for(let A=0;A<O;A++){const I=_+A*x,D=I+x,[j,_t]=F(I),[lt,tt]=A===O-1?[o,c]:F(D),[vi,ki]=N(I),[wi,xi]=N(D);L.push([j+E*vi,_t+E*ki,lt-E*wi,tt-E*xi,lt,tt])}return L}function Y(e,t,n,i,s){const r=1-s;return r*r*r*e+3*r*r*s*t+3*r*s*s*n+s*s*s*i}function Xt(e,t,n,i,s){const r=1-s;return 3*r*r*(t-e)+6*r*s*(n-t)+3*s*s*(i-n)}function Q(e,t,n,i){return{subpath:0,type:"L",points:[n,i],startX:e,startY:t,endX:n,endY:i,length:Math.hypot(n-e,i-t)}}function it(e,t,n){const[i,s,r,a,o,c]=n,l=[0];let u=e,h=t,f=0;for(let m=1;m<=Ft;m++){const p=m/Ft,d=Y(e,i,r,o,p),g=Y(t,s,a,c,p);f+=Math.hypot(d-u,g-h),l.push(f),u=d,h=g}return{subpath:0,type:"C",points:[i,s,r,a,o,c],startX:e,startY:t,endX:o,endY:c,length:f,lengths:l}}function st(e){const t=z.get(e);if(t)return t;const n=[];let i=0,s=0,r=0,a=0,o=null,c=null,l=-1;const u=new Set,h=d=>{l<0&&(l=0),d.subpath=l,n.push(d)};for(const{type:d,args:g}of qe(e)){const b=d.toUpperCase(),v=d!==b,k=Ve[b];if(b==="Z"){(i!==r||s!==a)&&h(Q(i,s,r,a)),l>=0&&u.add(l),i=r,s=a,o=c=null;continue}for(let M=0;M+k<=g.length;M+=k){const y=g.slice(M,M+k),S=v?i:0,w=v?s:0;let P=null,W=null;switch(b){case"M":M===0?(i=y[0]+S,s=y[1]+w,r=i,a=s,(l<0||n[n.length-1]?.subpath===l)&&l++):(h(Q(i,s,y[0]+S,y[1]+w)),i=y[0]+S,s=y[1]+w);break;case"L":h(Q(i,s,y[0]+S,y[1]+w)),i=y[0]+S,s=y[1]+w;break;case"H":h(Q(i,s,y[0]+S,s)),i=y[0]+S;break;case"V":h(Q(i,s,i,y[0]+w)),s=y[0]+w;break;case"C":{const T=[y[0]+S,y[1]+w,y[2]+S,y[3]+w,y[4]+S,y[5]+w];h(it(i,s,T)),P=[T[2],T[3]],i=T[4],s=T[5];break}case"S":{const[T,R]=o?[2*i-o[0],2*s-o[1]]:[i,s],_=[T,R,y[0]+S,y[1]+w,y[2]+S,y[3]+w];h(it(i,s,_)),P=[_[2],_[3]],i=_[4],s=_[5];break}case"Q":case"T":{let T=i,R=s;b==="Q"?(T=y[0]+S,R=y[1]+w):c&&(T=2*i-c[0],R=2*s-c[1]);const _=b==="Q"?y[2]+S:y[0]+S,C=b==="Q"?y[3]+w:y[1]+w;h(it(i,s,[i+2/3*(T-i),s+2/3*(R-s),_+2/3*(T-_),C+2/3*(R-C),_,C])),W=[T,R],i=_,s=C;break}case"A":{const T=y[5]+S,R=y[6]+w;let _=i,C=s;for(const O of We(i,s,y[0],y[1],y[2],y[3],y[4],T,R))h(it(_,C,O)),_=O[4],C=O[5];i=T,s=R;break}}o=P,c=W}}const f=n.reduce((d,g)=>d+g.length,0),m=[];for(let d=0;d<n.length;){const g=n[d].subpath;let b=d,v=0;for(;b<n.length&&n[b].subpath===g;)v+=n[b++].length;const k=n[d],M=n[b-1],y=u.has(g)||Math.abs(M.endX-k.startX)<1e-9&&Math.abs(M.endY-k.startY)<1e-9;m.push({start:d,end:b,length:v,closed:y}),d=b}const p={segments:n,totalLength:f,subpaths:m};return z.size>=Fe&&z.delete(z.keys().next().value),z.set(e,p),p}function Be(e,t){const n=e.lengths;if(t<=0)return 0;if(t>=e.length)return 1;let i=0,s=n.length-1;for(;i<s-1;){const o=i+s>>1;n[o]<t?i=o:s=o}const r=n[s]-n[i],a=r>0?(t-n[i])/r:0;return(i+a)/(n.length-1)}function Ue(e,t){if(e.type==="L"){const h=e.length>0?Math.max(0,Math.min(1,t/e.length)):0;return{x:e.startX+(e.endX-e.startX)*h,y:e.startY+(e.endY-e.startY)*h,angle:Math.atan2(e.endY-e.startY,e.endX-e.startX)*180/Math.PI}}const[n,i,s,r,a,o]=e.points,c=Be(e,t);let l=Xt(e.startX,n,s,a,c),u=Xt(e.startY,i,r,o,c);if(Math.hypot(l,u)<1e-9){const h=c<.5?Math.min(1,c+.001):Math.max(0,c-.001),f=Y(e.startX,n,s,a,h),m=Y(e.startY,i,r,o,h),p=Y(e.startX,n,s,a,c),d=Y(e.startY,i,r,o,c);l=c<.5?f-p:p-f,u=c<.5?m-d:d-m}return{x:Y(e.startX,n,s,a,c),y:Y(e.startY,i,r,o,c),angle:Math.atan2(u,l)*180/Math.PI}}function Yt(e,t,n=0,i=e.length){if(i<=n)return{x:0,y:0,angle:0};let s=0;for(let r=n;r<i;r++){const a=e[r];if(s+a.length>=t||r===i-1)return Ue(a,t-s);s+=a.length}return{x:0,y:0,angle:0}}function je(e,t){const{segments:n,totalLength:i}=st(e);return Yt(n,Math.max(0,Math.min(1,t))*i)}const He=24,ze=320,Qe=2.5,G=72,Ge=.2,Ze=128,rt=new Map;let gt=0,V;const Vt=e=>Math.round(e*100)/100;function qt(e,t){const{segments:n,subpaths:i,totalLength:s}=st(e);if(n.length===0)return[];if(t){const r=i.every(a=>a.closed);return[{segments:n,start:0,end:n.length,length:s,closed:r}]}return i.filter(r=>r.length>0).map(r=>({segments:n,start:r.start,end:r.end,length:r.length,closed:r.closed}))}function yt(e,t){const n=e.closed?(t%1+1)%1:Math.max(0,Math.min(1,t)),i=Yt(e.segments,n*e.length,e.start,e.end);return[i.x,i.y]}function Wt(e){const t=[];let n=0;for(let i=e.start;i<e.end;i++)n+=e.segments[i].length,e.length>0&&t.push(n/e.length);return t}function Bt(e,t){const n=[];for(let i=0;i<t;i++)n.push(yt(e,e.closed?i/t:i/(t-1)));return n}function Ut(e){let t=0,n=0;for(const[i,s]of e)t+=i,n+=s;return t/=e.length,n/=e.length,e.map(([i,s])=>[i-t,s-n])}function Ke(e,t,n){const i=e.closed&&t.closed;if(n!==void 0)return{offset:i?Math.abs(n)%G/G:0,reversed:n<0};const s=Ut(Bt(e,G)),r=Ut(Bt(t,G)),a=G;let o={offset:0,reversed:!1},c=1/0;for(const l of[!1,!0]){const u=i?a:1;for(let h=0;h<u;h++){let f=0;for(let m=0;m<a&&f<c;m++){const p=i?l?(h-m+a)%a:(m+h)%a:l?a-1-m:m,d=s[m][0]-r[p][0],g=s[m][1]-r[p][1];f+=d*d+g*g}f<c&&(c=f,o={offset:i?h/a:0,reversed:l})}}return o}function Je(e,t,n){return n?((t.reversed?t.offset-e:e+t.offset)%1+1)%1:t.reversed?1-e:e}function tn(e,t,n){return n?((t.reversed?t.offset-e:e-t.offset)%1+1)%1:t.reversed?1-e:e}function en(e,t,n){const i=e.closed&&t.closed,s=Ke(e,t,n.shapeIndex),r=Math.max(He,Math.min(ze,Math.ceil(Math.max(e.length,t.length)/Qe))),a=new Set,o=h=>a.add(Math.round(h*1e7)/1e7);for(let h=0;h<=r;h++)o(h/r);for(const h of Wt(e))o(h);for(const h of Wt(t))o(tn(h,s,i));let c=[...a].sort((h,f)=>h-f);i&&(c=c.filter(h=>h<1));const l=[],u=[];for(const h of c)l.push(...yt(e,h)),u.push(...yt(t,Je(h,s,i)));return nn({from:l,to:u,closed:i})}function nn(e){const t=e.from.length/2;if(t<=3)return e;const n=new Uint8Array(t);n[0]=1,n[t-1]=1;const i=[[0,t-1]];for(;i.length>0;){const[a,o]=i.pop();let c=-1,l=Ge;for(let u=a+1;u<o;u++){const h=Math.max(jt(e.from,a,o,u),jt(e.to,a,o,u));h>l&&(l=h,c=u)}c!==-1&&(n[c]=1,i.push([a,c],[c,o]))}const s=[],r=[];for(let a=0;a<t;a++)n[a]&&(s.push(e.from[a*2],e.from[a*2+1]),r.push(e.to[a*2],e.to[a*2+1]));return{from:s,to:r,closed:e.closed}}function jt(e,t,n,i){const s=e[t*2],r=e[t*2+1],a=e[n*2]-s,o=e[n*2+1]-r,c=e[i*2]-s,l=e[i*2+1]-r,u=a*a+o*o,h=u===0?0:Math.max(0,Math.min(1,(c*a+l*o)/u));return Math.hypot(c-h*a,l-h*o)}function sn(e,t,n){const i=n.shapeIndex;if(V&&V.from===e&&V.to===t&&V.shapeIndex===i)return V.plan;const r=rt.get(String(i??"auto"))?.get(e)?.get(t);if(r)return V={from:e,to:t,shapeIndex:i,plan:r},r;const a=st(e).subpaths.filter(m=>m.length>0).length===st(t).subpaths.filter(m=>m.length>0).length,o=qt(e,!a),c=qt(t,!a),l={pairs:o.map((m,p)=>en(m,c[p],n))};gt>=Ze&&(rt.clear(),gt=0);const u=String(i??"auto"),h=rt.get(u)??new Map;rt.set(u,h);const f=h.get(e)??new Map;return h.set(e,f),f.set(t,l),gt++,V={from:e,to:t,shapeIndex:i,plan:l},l}function rn(e,t,n,i={}){if(!e)return t;if(!t)return e;const s=Math.max(0,Math.min(1,n));if(s===0)return e;if(s===1)return t;const r=sn(e,t,i);if(r.pairs.length===0)return s<.5?e:t;let a="";for(const o of r.pairs){for(let c=0;c<o.from.length;c+=2){const l=Vt(o.from[c]+(o.to[c]-o.from[c])*s),u=Vt(o.from[c+1]+(o.to[c+1]-o.from[c+1])*s);a+=`${c===0?a?" M":"M":" L"}${l} ${u}`}o.closed&&(a+=" Z")}return a}function an(e){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(e)}const on=.9995;function cn(){return[0,0,0,1]}function ln(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]}function hn(e){return Math.hypot(e[0],e[1],e[2],e[3])}function Z(e){const t=hn(e);return t===0?cn():[e[0]/t,e[1]/t,e[2]/t,e[3]/t]}function un(e,t,n){const i=Z(e);let s=Z(t),r=ln(i,s);if(r<0&&(s=[-s[0],-s[1],-s[2],-s[3]],r=-r),r>on)return Z([i[0]+(s[0]-i[0])*n,i[1]+(s[1]-i[1])*n,i[2]+(s[2]-i[2])*n,i[3]+(s[3]-i[3])*n]);const a=Math.acos(r),o=Math.sin(a),c=Math.sin((1-n)*a)/o,l=Math.sin(n*a)/o;return Z([i[0]*c+s[0]*l,i[1]*c+s[1]*l,i[2]*c+s[2]*l,i[3]*c+s[3]*l])}const X=(e,t,n)=>e+(t-e)*n,Ht=512,bt=new Map,vt=new Map;function zt(e){const t=bt.get(e);if(t)return t;const n=e.replace("#",""),i=[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)];return bt.size<Ht&&bt.set(e,i),i}const Qt=e=>e.charCodeAt(0)===35,Gt=e=>e.startsWith("rgb"),Zt=e=>e.startsWith("rgba"),dn=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,kt=e=>Math.round(e).toString(16).padStart(2,"0");function fn(e,t,n){return`#${kt(e)}${kt(t)}${kt(n)}`}function Kt(e){const t=vt.get(e);if(t)return t;const n=e.match(dn);if(!n)throw new Error(`Invalid rgb color: ${e}`);const i=parseInt(n[1],10),s=parseInt(n[2],10),r=parseInt(n[3],10),a=n[4]!==void 0?[i,s,r,parseFloat(n[4])]:[i,s,r];return vt.size<Ht&&vt.set(e,a),a}const pn=(e,t,n)=>{if(Qt(e)&&Qt(t)){const[i,s,r]=zt(e),[a,o,c]=zt(t),l=X(i,a,n),u=X(s,o,n),h=X(r,c,n);return fn(l,u,h)}if((Gt(e)||Zt(e))&&(Gt(t)||Zt(t))){const i=Kt(e),s=Kt(t),r=Math.round(X(i[0],s[0],n)),a=Math.round(X(i[1],s[1],n)),o=Math.round(X(i[2],s[2],n));if(i.length===4||s.length===4){const c=i[3]??1,l=s[3]??1,u=X(c,l,n);return`rgba(${r}, ${a}, ${o}, ${u})`}return`rgb(${r}, ${a}, ${o})`}return n<1?e:t},mn=(e,t,n)=>{const i=Math.min(e.length,t.length),s=[];for(let r=0;r<i;r++)s.push(X(e[r],t[r],n));return s},gn=(e,t,n)=>un(e,t,n),Jt=(e,t,n)=>n<1?e:t,yn=(e,t,n)=>rn(e,t,n);function bn(e,t){return t==="slerp"?gn:typeof e=="number"?X:Array.isArray(e)?mn:typeof e=="string"?e.startsWith("#")||e.startsWith("rgb")?pn:an(e)?yn:Jt:Jt}function vn(e){const t=[...e.keyframes].sort((n,i)=>n.time-i.time);return{...e,keyframes:t}}function q(e){return e.targets&&e.targets.length>0?e.targets:[e.target]}function U(e,t,n,i){const s=n??0;return!i||t<=1?s:s+Pt(e,t,i)}class wt{track;targets;constructor(t){this.track=t,this.targets=q(t)}getValueAtTime(t){return this.valueForOffset(t-U(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const n=this.targets.length,i=[];for(let s=0;s<n;s++){const r=U(s,n,this.track.delay,this.track.stagger),a=this.valueForOffset(t-r);a!==void 0&&i.push({target:this.targets[s],value:a,start:r+this.track.keyframes[0].time})}return i}getDuration(){const{keyframes:t}=this.track;if(t.length===0)return 0;const n=t[t.length-1].time,i=this.track.stagger?dt(this.targets.length,this.track.stagger):0;return n+(this.track.delay??0)+i+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(t){const{keyframes:n}=this.track;if(n.length===0)return;if(n.length===1||t<=n[0].time)return n[0].value;if(t>=n[n.length-1].time)return n[n.length-1].value;const{from:i,to:s}=this.findSurroundingKeyframes(t);if(!i||!s)return;if(i.time===t)return i.value;const r=s.time-i.time,a=(t-i.time)/r,c=Ne(s.easing)(a);return bn(i.value,this.track.interpolation)(i.value,s.value,c)}findSurroundingKeyframes(t){const{keyframes:n}=this.track;for(let i=0;i<n.length-1;i++)if(t>=n[i].time&&t<=n[i+1].time)return{from:n[i],to:n[i+1]};return{from:null,to:null}}}class kn{track;targets;sampler;constructor(t){this.track=t,this.targets=q(t),this.sampler=new we(t.spring)}getValueAtTime(t){return this.sampler.valueAt(t-U(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const n=this.targets.length,i=[];for(let s=0;s<n;s++){const r=U(s,n,this.track.delay,this.track.stagger);i.push({target:this.targets[s],value:this.sampler.valueAt(t-r),start:r})}return i}getDuration(){const t=this.track.stagger?dt(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+t}getTrack(){return this.track}}class wn{track;targets;duration;constructor(t){this.track=t,this.targets=q(t),this.duration=$t(t.inertia)}getValueAtTime(t){return Lt(this.track.inertia,t-U(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const n=this.targets.length,i=[];for(let s=0;s<n;s++){const r=U(s,n,this.track.delay,this.track.stagger);i.push({target:this.targets[s],value:Lt(this.track.inertia,t-r),start:r})}return i}getDuration(){const t=this.track.stagger?dt(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+t}getTrack(){return this.track}}function xn(e,t){const n={...je(e.pathData,t)};if(e.matrix){const[i,s,r,a,o,c]=e.matrix,{x:l,y:u}=n;n.x=i*l+r*u+o,n.y=s*l+a*u+c;const h=n.angle*Math.PI/180,f=Math.cos(h),m=Math.sin(h);n.angle=Math.atan2(s*f+a*m,i*f+r*m)*180/Math.PI}return e.autoRotate&&e.rotateOffset&&(n.angle+=e.rotateOffset),n}const xt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},Mn=20;function Sn(e){const t=xt[e??"upperCase"]??e??xt.upperCase,n=Array.from(t);return n.length>0?n:Array.from(xt.upperCase)}function Tn(e,t,n){let i=(e|0)^Math.imul(t+1,2654435761)^Math.imul(n+1,2246822507);return i=Math.imul(i^i>>>16,2146121005),i=Math.imul(i^i>>>15,2221713035),(i^i>>>16)>>>0}function _n(e,t,n=0){const i=e.from??"",s=e.to,r=Math.max(0,Math.min(1,t));if(r<=0)return i;if(r>=1)return s;const a=Array.from(i),o=Array.from(s),c=e.rightToLeft??!1;if(e.mode==="type"){const v=Math.round(r*Math.max(a.length,o.length));return c?a.slice(0,Math.max(0,a.length-v)).join("")+o.slice(Math.max(0,o.length-v)).join(""):o.slice(0,v).join("")+a.slice(v).join("")}const l=Math.max(0,Math.min(.999,e.revealDelay??0)),u=Math.max(0,(r-l)/(1-l)),h=Math.floor(u*o.length),f=e.tweenLength===!1?o.length:Math.round(a.length+(o.length-a.length)*r),m=Sn(e.chars),p=e.refreshRate??Mn,d=p>0?Math.floor(n*p/1e3):0,g=e.seed??1;let b="";for(let v=0;v<f;v++){const k=c?v>=f-h:v<h,M=c?o[o.length-(f-v)]:o[v];k&&M!==void 0||M===" "||M===`
2
- `?b+=M:b+=m[Tn(g,v,d)%m.length]}return b}class An{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 n of t.tracks)this.addTrack(n)}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 n={...this._config};delete n.duration,this._config=n}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(t){this._config.speed=t}get drawingRate(){return this._config.drawingRate??0}set drawingRate(t){const n={...this._config};t>0?n.drawingRate=t:delete n.drawingRate,this._config=n}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 n=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(t,n)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(t){if(this._playbackState!=="playing")return;const n=this.duration;if(n<=0)return;let s=t*this.speed;if(this._repeatDelayRemaining>0){const o=Math.min(this._repeatDelayRemaining,s);if(this._repeatDelayRemaining-=o,s-=o,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const r=1e3;for(let o=0;o<r&&s>0&&this._playbackState==="playing";o++)if(this._direction==="forward"){const c=n-this._currentTime;if(s>=c){if(s-=c,this._currentTime=n,!this._handleEndReached())break}else this._currentTime+=s,s=0}else{const c=this._currentTime;if(s>=c){if(s-=c,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=s,s=0}const a=this.getStateAtTime(this._currentTime);this.onUpdate?.(a)}getStateAtTime(t){const n=new Map;if(t=be(t,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(t,n);else for(const[i,s]of this._trackPlayers){const r=s.getTrack().property;for(const{target:a,value:o,start:c}of s.getTargetValues(t))this._write(n,i,a,r,o,t-c)}return{values:n,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(t,n){const i=new Map;for(const[s,r]of this._trackPlayers){const a=r.getTrack().property;for(const{target:o,value:c,start:l}of r.getTargetValues(t)){const u=`${o}\0${a}`,h=l<=t,f=i.get(u);(!f||(h!==f.started?h:h?l>=f.start:l<=f.start))&&i.set(u,{trackId:s,target:o,property:a,value:c,start:l,started:h})}}for(const{trackId:s,target:r,property:a,value:o,start:c}of i.values())this._write(n,s,r,a,o,t-c)}_write(t,n,i,s,r,a){if(r===void 0)return;let o=t.get(i);o||(o=new Map,t.set(i,o));const c=this._textTracks.get(n);if(c&&typeof r=="number"){o.set("text",_n(c.textConfig,r,Math.max(0,a)));return}const l=this._motionPathTracks.get(n);if(l&&typeof r=="number"){const u=xn(l.motionPathConfig,r);o.set("motionPathX",u.x),o.set("motionPathY",u.y),l.motionPathConfig.autoRotate&&o.set("motionPathRotate",u.angle)}else o.set(s,r)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const t=new Set;this._sharedWrites=!1;t:for(const n of this._tracks)for(const i of q(n)){const s=`${i}\0${n.property}`;if(t.has(s)){this._sharedWrites=!0;break t}t.add(s)}}return this._sharedWrites}addTrack(t){if(this._tracks.push(t),this._sharedWrites=null,ht(t)){this._trackPlayers.set(t.id,new wn(t));return}if(ut(t)){this._trackPlayers.set(t.id,new kn(t)),this._springTracks.set(t.id,t);return}if(At(t))this._trackPlayers.set(t.id,new wt(t)),this._textTracks.set(t.id,t);else if(ye(t)){const n={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 wt(n)),this._motionPathTracks.set(t.id,t)}else this._trackPlayers.set(t.id,new wt(t))}replaceTrack(t,n){const i=this._tracks.findIndex(r=>r.id===t);if(i<0)return;const s=this._tracks.slice(i+1);this.removeTrack(t);for(const r of s)this.removeTrack(r.id);this.addTrack(n);for(const r of s)this.addTrack(r)}removeTrack(t){this._tracks=this._tracks.filter(n=>n.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(n=>this._matches(n,t))}removeTracks(t={}){const n=this.getTracks(t).map(i=>i.id);for(const i of n)this.removeTrack(i);return n}getTrackSpan(t){const n=this._trackPlayers.get(t);if(!n)return;const i=n.getTrack(),s=i.delay??0;if(ut(i)||ht(i))return{from:s,to:n.getDuration()};const r=i.keyframes;if(!(!r||r.length===0))return{from:r[0].time+s,to:n.getDuration()}}findConflicts(){const t=[];for(let n=0;n<this._tracks.length;n++){const i=this._tracks[n],s=this.getTrackSpan(i.id);if(s)for(let r=0;r<n;r++){const a=this._tracks[r];if(a.property!==i.property)continue;const o=q(a).filter(h=>q(i).includes(h));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=s.to&&s.from<=c.to))continue;const u=s.from>=c.from;for(const h of o)t.push({target:h,property:i.property,losingTrackId:u?a.id:i.id,winningTrackId:u?i.id:a.id})}}return t}_matches(t,n){if(n.id!==void 0&&t.id!==n.id||n.property!==void 0&&t.property!==n.property||n.target!==void 0&&!q(t).includes(n.target))return!1;if(n.timeRange){const i=this.getTrackSpan(t.id);if(!i||i.to<n.timeRange.from||i.from>n.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:ge(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,n)=>t.time-n.time)}setMarkers(t){const n=t&&t.length>0?[...t].sort((s,r)=>s.time-r.time).map(s=>({...s})):void 0,i={...this._config};n?i.markers=n:delete i.markers,this._config=i}get captions(){return this._captions}setCaptions(t){const n={};for(const[i,s]of Object.entries(t??{}))n[i]={...s};this._captions=Object.keys(n).length>0?n:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let t=0;for(const[,n]of this._trackPlayers)t=Math.max(t,n.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 En=100;function Pn(e,t,n,i){const s=[],r=[],{duration:a,alternate:o}=i,c=(m,p,d,g)=>{r.push([m,p]);const b=[];e.forEach((v,k)=>{(d==="forward"?(g?v>=m:v>m)&&v<=p:(g?v<=m:v<m)&&v>=p)&&b.push(k)}),b.sort((v,k)=>(d==="forward"?e[v]-e[k]:e[k]-e[v])||v-k);for(const v of b)s.push({kind:"event",index:v,direction:d})};let l=t.time,u=t.direction,h=t.fresh===!0;const f=Math.min(En,Math.max(0,n.iteration-t.iteration));for(let m=0;m<f;m++){const p=u==="forward"?a:0;c(l,p,u,h),s.push({kind:"repeat"}),o?(u=u==="forward"?"reverse":"forward",l=p,h=!1):(l=u==="forward"?0:a,h=!0)}return f>0&&i.holding&&!o?{crossings:s,passes:r}:(c(l,n.time,u,h),{crossings:s,passes:r})}function Cn(e){return{...e,...Array.isArray(e.end)&&{end:[...e.end]}}}function K(e){const t=e.endDelay;return{...e.delay!==void 0&&{delay:e.delay},...t!==void 0&&{endDelay:t},...e.targets!==void 0&&{targets:[...e.targets]},...e.stagger!==void 0&&{stagger:{...e.stagger}}}}function In(e){if(ht(e)){const t=e;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:Cn(t.inertia),...K(t)}}if(ut(e)){const t=e;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...K(t)}}if(At(e)){const t=e;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((n,i)=>n.time-i.time),...K(t)}}if(e.property==="motionPath"&&"motionPathConfig"in e){const t=e,n=[...t.keyframes].sort((i,s)=>i.time-s.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:n,...K(t)}}return vn({id:e.id,target:e.target,property:e.property,keyframes:e.keyframes,...e.interpolation!==void 0&&{interpolation:e.interpolation},...K(e)})}function at(e){const t=e.formatVersion??1;if(t>et)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${et}. Update tinyfly to play it.`);return new An({id:e.id,name:e.name,config:e.config,tracks:e.tracks.map(In),captions:e.captions})}function Rn(e){const[t,n,i,s]=e;return[1-2*(n*n+i*i),2*(t*n+i*s),2*(t*i-n*s),0,2*(t*n-i*s),1-2*(t*t+i*i),2*(n*i+t*s),0,2*(t*i+n*s),2*(n*i-t*s),1-2*(t*t+n*n),0,0,0,0,1]}function $n(e){return!Array.isArray(e)||e.length!==4?null:`matrix3d(${Rn(Z(e)).map(n=>Math.round(n*1e6)/1e6+0).join(", ")})`}const Ln=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),Dn="#ffffff",On="rgba(0, 0, 0, 0.5)";function Nn(e){const t=[];if(e.blur!==void 0&&t.push(`blur(${Math.max(0,e.blur)}px)`),e.brightness!==void 0&&t.push(`brightness(${Math.max(0,e.brightness)})`),e.glow!==void 0&&t.push(`drop-shadow(0 0 ${Math.max(0,e.glow)}px ${e.glowColor??Dn})`),e.shadowX!==void 0||e.shadowY!==void 0||e.shadowBlur!==void 0){const n=e.shadowX??0,i=e.shadowY??0,s=Math.max(0,e.shadowBlur??0);t.push(`drop-shadow(${n}px ${i}px ${s}px ${e.shadowColor??On})`)}return t.length>0?t.join(" "):null}function Fn(e,t){const n=e.childNodes.length===1?e.firstChild:null;if(n&&n.nodeType===3){const i=n;i.data!==t&&(i.data=t);return}e.textContent!==t&&(e.textContent=t)}function Xn(e){if(!("ownerSVGElement"in e))return;const t=e.style;!t||t.transformBox||(t.transformBox="fill-box",t.transformOrigin||(t.transformOrigin="50% 50%"))}const te=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"]),Yn=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),Vn=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],qn=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),Wn=new Set(["originX","originY"]),Bn=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Un=new Set(["drawOn"]),jn={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},ee={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},Hn="http://www.w3.org/2000/svg";class Mt{targets=new Map;registerTarget(t,n){this.targets.set(t,n)}unregisterTarget(t){this.targets.delete(t)}getTarget(t){return this.targets.get(t)}clearTargets(){this.targets.clear()}applyState(t){for(const[n,i]of t.values){const s=this.targets.get(n);s&&this.applyProperties(s,i)}}applyProperties(t,n){let i=null,s=null,r=null,a=null,o=null;const c=n.has("motionPathX"),l=n.has("motionPathY"),u=n.has("motionPathRotate");for(const[p,d]of n)if(!(p==="x"&&c)&&!(p==="y"&&l)&&!((p==="rotate"||p==="rotateZ")&&u)&&!Un.has(p)){if(Yn.has(p))(i??={})[p]=d;else if(qn.has(p))typeof d=="number"&&((s??={})[p]=d);else if(Wn.has(p))typeof d=="number"&&((r??={})[p]=d);else if(Bn.has(p))typeof d=="number"&&((a??={})[p]=d);else if(Ln.has(p))(o??={})[p]=d;else if(p!=="perspective"){if(p!=="shine")if(p==="text"&&typeof d=="string")Fn(t,d);else if(p==="d"&&typeof d=="string"){const g=t;(g.tagName?.toLowerCase()==="path"?g:g.querySelector?.("path"))?.setAttribute?.("d",d)}else this.applyStyleProperty(t,p,d)}}const h=n.get("shine");typeof h=="number"&&this.applyShine(t,h);const f=[],m=n.get("perspective");if(typeof m=="number"&&m>0&&f.push(`perspective(${m}px)`),i)for(const p of Vn){const d=i[p];if(d===void 0)continue;const g=this.buildTransformPart(p,d);g&&f.push(g)}if(f.length>0&&(t.style.transform=f.join(" "),Xn(t)),s&&(s.childPerspective!==void 0&&(t.style.perspective=`${s.childPerspective}px`),(s.perspectiveOriginX!==void 0||s.perspectiveOriginY!==void 0)&&(t.style.perspectiveOrigin=`${s.perspectiveOriginX??50}% ${s.perspectiveOriginY??50}%`)),r){const p=r.originX??50,d=r.originY??50;t.style.transformOrigin=`${p}% ${d}%`}if(a){const p=a.clipTop??0,d=a.clipRight??0,g=a.clipBottom??0,b=a.clipLeft??0;t.style.clipPath=`inset(${p}% ${d}% ${g}% ${b}%)`}if(o){const p=Nn(o);p&&(t.style.filter=p)}}buildTransformPart(t,n){if(t==="quaternion")return $n(n);if(typeof n!="number")return null;switch(t){case"x":case"motionPathX":return`translateX(${n}px)`;case"y":case"motionPathY":return`translateY(${n}px)`;case"z":return`translateZ(${n}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${n}deg)`;case"rotateX":return`rotateX(${n}deg)`;case"rotateY":return`rotateY(${n}deg)`;case"scale":return`scale(${n})`;case"scaleX":return`scaleX(${n})`;case"scaleY":return`scaleY(${n})`;case"scaleZ":return`scaleZ(${n})`;case"skewX":return`skewX(${n}deg)`;case"skewY":return`skewY(${n}deg)`;default:return null}}applyShine(t,n){t.dataset.shineBase||(t.dataset.shineBase=t.style.color||"currentColor");const i=t.dataset.shineBase,s=-20+n*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(${i}, ${i})`,r.backgroundSize="250% 100%, 100% 100%",r.backgroundPosition=`${s}% 0, 0 0`,r.backgroundRepeat="no-repeat",r.webkitBackgroundClip="text",r.backgroundClip="text"}applyStyleProperty(t,n,i){let s;if(t.namespaceURI===Hn&&n in ee){const o=Array.isArray(i)?i.join(", "):String(i);t.style[ee[n]]=o;return}else n==="fill"&&t.dataset?.elementType==="text"?s="color":s=jn[n]??n;let a;typeof i=="number"?te.has(n)||te.has(s)?a=`${i}px`:a=String(i):Array.isArray(i)?a=i.join(", "):a=i,t.style[s]=a}}class ne{media;offset;driftTolerance;constructor(t,n={}){this.media=t,this.offset=n.offset??0,this.driftTolerance=Math.max(0,n.driftTolerance??.15)}targetTime(t){return Math.max(0,t/1e3+this.offset)}update(t,n){const i=this.targetTime(t);n?(this.media.paused&&this.safePlay(),Math.abs(this.media.currentTime-i)>this.driftTolerance&&(this.media.currentTime=i)):(this.media.paused||this.media.pause(),this.media.currentTime!==i&&(this.media.currentTime=i))}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 zn(e,t,n,i,s){const r=n-s;if(r<0){t.paused||t.pause(),t.currentTime=0;return}e.update(r,i)}class ot{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,n={}){if(typeof t=="string"){const i=document.querySelector(t);if(!i)throw new Error(`Container not found: ${t}`);this.container=i}else this.container=t;this.options=n,this.adapter=new Mt}async load(t){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(t)}async loadSource(t){let n;if(typeof t=="string"){const i=await fetch(t);if(!i.ok)throw new Error(`Failed to load animation: ${i.statusText}`);n=await i.json()}else n=t;this.useDefinition(n),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(t){const n={...t.config};this.options.speed!==void 0&&(n.speed=this.options.speed),this.options.loop!==void 0&&(n.loop=this.options.loop),this.options.alternate!==void 0&&(n.alternate=this.options.alternate),this.timeline=at({...t,config:n}),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,n={}){if(t.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const i=new Set;for(const r of t){if(i.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);i.add(r.id)}const s=n.initial===void 0?t[0]:t.find(r=>r.id===n.initial);if(!s)throw new Error(`tinyfly: there is no scenario "${n.initial}"`);this.scenarioList=[...t],this.scenarioId=s.id,await this.loadSource(s.timeline)}get scenarios(){return this.scenarioList.map(t=>({id:t.id,label:t.label??t.id}))}get scenario(){return this.scenarioId}setScenario(t){const n=this.scenarioList.find(o=>o.id===t);if(!n||!this.timeline)return!1;if(t===this.scenarioId)return!0;const i=this.isPlaying,s=this.currentTime>=this.duration-.5,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=t,this.useDefinition(n.timeline),this.lastMarkerId=null;let a=0;return this.reducedMotion||s?a=this.duration:r!==void 0&&(a=this.markers.find(o=>o.id===r)?.time??0),this.seek(a),i&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(t){if(this.authored.has(t))return;const n={style:t.getAttribute("style")};t.children.length===0&&(n.text=t.textContent??"");const i=t.tagName.toLowerCase()==="path"?t:t.querySelector("path");i&&(n.path={element:i,d:i.getAttribute("d")}),this.authored.set(t,n)}restoreAuthored(){for(const[t,n]of this.authored){n.style===null?t.removeAttribute("style"):t.setAttribute("style",n.style),n.text!==void 0&&t.textContent!==n.text&&(t.textContent=n.text),n.path&&(n.path.d===null?n.path.element.removeAttribute("d"):n.path.element.setAttribute("d",n.path.d));const i=t.dataset;i&&delete i.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 n;for(const i of this.markers)if(i.time<=t+.5)n=i;else break;return n}caption(t,n){const i=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!i)return;const s=n??this.language(),r=a=>a?.[s]?.[i.id]??a?.[s.split("-")[0]]?.[i.id];return r(this.options.captions)??r(this.timeline?.captions)??i.label}next(){if(!this.timeline)return;const t=this.currentTime,n=this.markers.find(i=>i.time>t+.5);if(this.reducedMotion){this.seek(n?n.time:this.duration);return}t>=this.duration-.5||(this.stepping=n!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const t=this.currentTime,n=[...this.markers].reverse().find(i=>i.time<t-.5);this.pause(),this.seek(n?n.time:0)}goToMarker(t){const n=this.markers.find(i=>i.id===t);n&&(this.pause(),this.seek(n.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 n=t==="end"?this.timeline.duration:t==="start"?0:t;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,n))),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(n=>{for(const i of n)this.onScreen=i.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,n=t?.id;n!==this.lastMarkerId&&(this.lastMarkerId=n,this.options.onMarker(t))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(n=>{const i=n,s=Number(i.getAttribute("data-tinyfly-start")??"0")||0,r=i.getAttribute("data-volume");r!==null&&(i.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:i,startTime:s,sync:new ne(i)})})}syncAllMedia(t,n){for(const i of this.mediaTargets)zn(i.sync,i.el,t,n,i.startTime)}loadFromString(t){const n=JSON.parse(t);this.load(n)}registerTarget(t,n){if(typeof n=="string"){const i=this.container.querySelector(n);i&&(this.rememberAuthored(i),this.targets[t]=i,this.adapter.registerTarget(t,i))}else this.rememberAuthored(n),this.targets[t]=n,this.adapter.registerTarget(t,n)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(n=>{const i=n.closest("[data-tinyfly-symbol]");if(i&&i!==n)return;const s=n.getAttribute("data-tinyfly");s&&this.registerTarget(s,n)}),this.timeline&&new Set(this.timeline.tracks.map(i=>i.target)).forEach(i=>{if(!this.targets[i]){const s=this.container.querySelector(`[data-tinyfly="${i}"]`)||this.container.querySelector(`.${i}`)||this.container.querySelector(`#${i}`);s&&this.registerTarget(i,s)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const n=new Map(t.map(i=>[i.id,i]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(i=>{const s=i.getAttribute("data-tinyfly-symbol");if(!s)return;const r=n.get(s);if(!r||!r.timeline.tracks?.length)return;const a=new Mt;i.querySelectorAll("[data-tinyfly]").forEach(o=>{const c=o.getAttribute("data-tinyfly");c&&a.registerTarget(c,o)}),this.symbolInstances.push({adapter:a,timeline:at(r.timeline)})})}attachMedia(t,n){this.mediaSync=new ne(t,n),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=n=>{if(this.isDestroyed||!this.timeline)return;const i=n-(this.lastTime??n);this.lastTime=n;const s=this.playhead;this.timeline.tick(i),this.stopAtMarker(s),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 n=this.timeline,i={time:n.currentTime,iteration:n.loopIteration,direction:n.direction};this.playhead=i;const s=this.markers;if(s.length===0)return;const{crossings:r}=Pn(s.map(a=>a.time),t,i,{duration:n.duration,alternate:n.config.alternate===!0,holding:n.repeatDelayRemaining>0});for(const a of r){if(a.kind!=="event")continue;const o=s[a.index];if(this.stepping||o.pause){this.stepping=!1,n.pause(),n.seek(o.time),this.playhead={time:o.time,iteration:n.loopIteration,direction:n.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 n of this.symbolInstances){const i=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(i>0?t%i:t))}}}async function Qn(e,t,n={}){const i=new ot(e,{...n,autoplay:!0});return await i.load(t),i}function Gn(e,t={}){return new ot(e,t)}const ie={play:"Play",pause:"Pause",prev:"Previous step",next:"Next step",restart:"Restart",scrub:"Position",speed:"Speed",reveal:"Reveal",step:"Step",of:"of",stepFormat:"{index} / {total}",scenario:"Scenario",fullscreen:"Full screen",exitFullscreen:"Exit full screen"},se="tinyfly-controls-style",Zn=`
2
+ `?b+=M:b+=m[Tn(g,v,d)%m.length]}return b}class An{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 n of t.tracks)this.addTrack(n)}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 n={...this._config};delete n.duration,this._config=n}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(t){this._config.speed=t}get drawingRate(){return this._config.drawingRate??0}set drawingRate(t){const n={...this._config};t>0?n.drawingRate=t:delete n.drawingRate,this._config=n}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 n=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(t,n)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(t){if(this._playbackState!=="playing")return;const n=this.duration;if(n<=0)return;let s=t*this.speed;if(this._repeatDelayRemaining>0){const o=Math.min(this._repeatDelayRemaining,s);if(this._repeatDelayRemaining-=o,s-=o,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const r=1e3;for(let o=0;o<r&&s>0&&this._playbackState==="playing";o++)if(this._direction==="forward"){const c=n-this._currentTime;if(s>=c){if(s-=c,this._currentTime=n,!this._handleEndReached())break}else this._currentTime+=s,s=0}else{const c=this._currentTime;if(s>=c){if(s-=c,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=s,s=0}const a=this.getStateAtTime(this._currentTime);this.onUpdate?.(a)}getStateAtTime(t){const n=new Map;if(t=be(t,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(t,n);else for(const[i,s]of this._trackPlayers){const r=s.getTrack().property;for(const{target:a,value:o,start:c}of s.getTargetValues(t))this._write(n,i,a,r,o,t-c)}return{values:n,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(t,n){const i=new Map;for(const[s,r]of this._trackPlayers){const a=r.getTrack().property;for(const{target:o,value:c,start:l}of r.getTargetValues(t)){const u=`${o}\0${a}`,h=l<=t,f=i.get(u);(!f||(h!==f.started?h:h?l>=f.start:l<=f.start))&&i.set(u,{trackId:s,target:o,property:a,value:c,start:l,started:h})}}for(const{trackId:s,target:r,property:a,value:o,start:c}of i.values())this._write(n,s,r,a,o,t-c)}_write(t,n,i,s,r,a){if(r===void 0)return;let o=t.get(i);o||(o=new Map,t.set(i,o));const c=this._textTracks.get(n);if(c&&typeof r=="number"){o.set("text",_n(c.textConfig,r,Math.max(0,a)));return}const l=this._motionPathTracks.get(n);if(l&&typeof r=="number"){const u=xn(l.motionPathConfig,r);o.set("motionPathX",u.x),o.set("motionPathY",u.y),l.motionPathConfig.autoRotate&&o.set("motionPathRotate",u.angle)}else o.set(s,r)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const t=new Set;this._sharedWrites=!1;t:for(const n of this._tracks)for(const i of q(n)){const s=`${i}\0${n.property}`;if(t.has(s)){this._sharedWrites=!0;break t}t.add(s)}}return this._sharedWrites}addTrack(t){if(this._tracks.push(t),this._sharedWrites=null,ht(t)){this._trackPlayers.set(t.id,new wn(t));return}if(ut(t)){this._trackPlayers.set(t.id,new kn(t)),this._springTracks.set(t.id,t);return}if(At(t))this._trackPlayers.set(t.id,new wt(t)),this._textTracks.set(t.id,t);else if(ye(t)){const n={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 wt(n)),this._motionPathTracks.set(t.id,t)}else this._trackPlayers.set(t.id,new wt(t))}replaceTrack(t,n){const i=this._tracks.findIndex(r=>r.id===t);if(i<0)return;const s=this._tracks.slice(i+1);this.removeTrack(t);for(const r of s)this.removeTrack(r.id);this.addTrack(n);for(const r of s)this.addTrack(r)}removeTrack(t){this._tracks=this._tracks.filter(n=>n.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(n=>this._matches(n,t))}removeTracks(t={}){const n=this.getTracks(t).map(i=>i.id);for(const i of n)this.removeTrack(i);return n}getTrackSpan(t){const n=this._trackPlayers.get(t);if(!n)return;const i=n.getTrack(),s=i.delay??0;if(ut(i)||ht(i))return{from:s,to:n.getDuration()};const r=i.keyframes;if(!(!r||r.length===0))return{from:r[0].time+s,to:n.getDuration()}}findConflicts(){const t=[];for(let n=0;n<this._tracks.length;n++){const i=this._tracks[n],s=this.getTrackSpan(i.id);if(s)for(let r=0;r<n;r++){const a=this._tracks[r];if(a.property!==i.property)continue;const o=q(a).filter(h=>q(i).includes(h));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=s.to&&s.from<=c.to))continue;const u=s.from>=c.from;for(const h of o)t.push({target:h,property:i.property,losingTrackId:u?a.id:i.id,winningTrackId:u?i.id:a.id})}}return t}_matches(t,n){if(n.id!==void 0&&t.id!==n.id||n.property!==void 0&&t.property!==n.property||n.target!==void 0&&!q(t).includes(n.target))return!1;if(n.timeRange){const i=this.getTrackSpan(t.id);if(!i||i.to<n.timeRange.from||i.from>n.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:ge(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,n)=>t.time-n.time)}setMarkers(t){const n=t&&t.length>0?[...t].sort((s,r)=>s.time-r.time).map(s=>({...s})):void 0,i={...this._config};n?i.markers=n:delete i.markers,this._config=i}get captions(){return this._captions}setCaptions(t){const n={};for(const[i,s]of Object.entries(t??{}))n[i]={...s};this._captions=Object.keys(n).length>0?n:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let t=0;for(const[,n]of this._trackPlayers)t=Math.max(t,n.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 En=100;function Pn(e,t,n,i){const s=[],r=[],{duration:a,alternate:o}=i,c=(m,p,d,g)=>{r.push([m,p]);const b=[];e.forEach((v,k)=>{(d==="forward"?(g?v>=m:v>m)&&v<=p:(g?v<=m:v<m)&&v>=p)&&b.push(k)}),b.sort((v,k)=>(d==="forward"?e[v]-e[k]:e[k]-e[v])||v-k);for(const v of b)s.push({kind:"event",index:v,direction:d})};let l=t.time,u=t.direction,h=t.fresh===!0;const f=Math.min(En,Math.max(0,n.iteration-t.iteration));for(let m=0;m<f;m++){const p=u==="forward"?a:0;c(l,p,u,h),s.push({kind:"repeat"}),o?(u=u==="forward"?"reverse":"forward",l=p,h=!1):(l=u==="forward"?0:a,h=!0)}return f>0&&i.holding&&!o?{crossings:s,passes:r}:(c(l,n.time,u,h),{crossings:s,passes:r})}function Cn(e){return{...e,...Array.isArray(e.end)&&{end:[...e.end]}}}function K(e){const t=e.endDelay;return{...e.delay!==void 0&&{delay:e.delay},...t!==void 0&&{endDelay:t},...e.targets!==void 0&&{targets:[...e.targets]},...e.stagger!==void 0&&{stagger:{...e.stagger}}}}function In(e){if(ht(e)){const t=e;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:Cn(t.inertia),...K(t)}}if(ut(e)){const t=e;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...K(t)}}if(At(e)){const t=e;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((n,i)=>n.time-i.time),...K(t)}}if(e.property==="motionPath"&&"motionPathConfig"in e){const t=e,n=[...t.keyframes].sort((i,s)=>i.time-s.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:n,...K(t)}}return vn({id:e.id,target:e.target,property:e.property,keyframes:e.keyframes,...e.interpolation!==void 0&&{interpolation:e.interpolation},...K(e)})}function at(e){const t=e.formatVersion??1;if(t>et)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${et}. Update tinyfly to play it.`);return new An({id:e.id,name:e.name,config:e.config,tracks:e.tracks.map(In),captions:e.captions})}function Rn(e){const[t,n,i,s]=e;return[1-2*(n*n+i*i),2*(t*n+i*s),2*(t*i-n*s),0,2*(t*n-i*s),1-2*(t*t+i*i),2*(n*i+t*s),0,2*(t*i+n*s),2*(n*i-t*s),1-2*(t*t+n*n),0,0,0,0,1]}function $n(e){return!Array.isArray(e)||e.length!==4?null:`matrix3d(${Rn(Z(e)).map(n=>Math.round(n*1e6)/1e6+0).join(", ")})`}const Ln=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),Dn="#ffffff",On="rgba(0, 0, 0, 0.5)";function Nn(e){const t=[];if(e.blur!==void 0&&t.push(`blur(${Math.max(0,e.blur)}px)`),e.brightness!==void 0&&t.push(`brightness(${Math.max(0,e.brightness)})`),e.glow!==void 0&&t.push(`drop-shadow(0 0 ${Math.max(0,e.glow)}px ${e.glowColor??Dn})`),e.shadowX!==void 0||e.shadowY!==void 0||e.shadowBlur!==void 0){const n=e.shadowX??0,i=e.shadowY??0,s=Math.max(0,e.shadowBlur??0);t.push(`drop-shadow(${n}px ${i}px ${s}px ${e.shadowColor??On})`)}return t.length>0?t.join(" "):null}function Fn(e,t){const n=e.childNodes.length===1?e.firstChild:null;if(n&&n.nodeType===3){const i=n;i.data!==t&&(i.data=t);return}e.textContent!==t&&(e.textContent=t)}function Xn(e){if(!("ownerSVGElement"in e))return;const t=e.style;!t||t.transformBox||(t.transformBox="fill-box",t.transformOrigin||(t.transformOrigin="50% 50%"))}const te=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"]),Yn=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),Vn=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],qn=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),Wn=new Set(["originX","originY"]),Bn=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Un=new Set(["drawOn"]),jn={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},ee={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},Hn="http://www.w3.org/2000/svg";class Mt{targets=new Map;registerTarget(t,n){this.targets.set(t,n)}unregisterTarget(t){this.targets.delete(t)}getTarget(t){return this.targets.get(t)}clearTargets(){this.targets.clear()}applyState(t){for(const[n,i]of t.values){const s=this.targets.get(n);s&&this.applyProperties(s,i)}}applyProperties(t,n){let i=null,s=null,r=null,a=null,o=null;const c=n.has("motionPathX"),l=n.has("motionPathY"),u=n.has("motionPathRotate");for(const[p,d]of n)if(!(p==="x"&&c)&&!(p==="y"&&l)&&!((p==="rotate"||p==="rotateZ")&&u)&&!Un.has(p)){if(Yn.has(p))(i??={})[p]=d;else if(qn.has(p))typeof d=="number"&&((s??={})[p]=d);else if(Wn.has(p))typeof d=="number"&&((r??={})[p]=d);else if(Bn.has(p))typeof d=="number"&&((a??={})[p]=d);else if(Ln.has(p))(o??={})[p]=d;else if(p!=="perspective"){if(p!=="shine")if(p==="text"&&typeof d=="string")Fn(t,d);else if(p==="d"&&typeof d=="string"){const g=t;(g.tagName?.toLowerCase()==="path"?g:g.querySelector?.("path"))?.setAttribute?.("d",d)}else this.applyStyleProperty(t,p,d)}}const h=n.get("shine");typeof h=="number"&&this.applyShine(t,h);const f=[],m=n.get("perspective");if(typeof m=="number"&&m>0&&f.push(`perspective(${m}px)`),i)for(const p of Vn){const d=i[p];if(d===void 0)continue;const g=this.buildTransformPart(p,d);g&&f.push(g)}if(f.length>0&&(t.style.transform=f.join(" "),Xn(t)),s&&(s.childPerspective!==void 0&&(t.style.perspective=`${s.childPerspective}px`),(s.perspectiveOriginX!==void 0||s.perspectiveOriginY!==void 0)&&(t.style.perspectiveOrigin=`${s.perspectiveOriginX??50}% ${s.perspectiveOriginY??50}%`)),r){const p=r.originX??50,d=r.originY??50;t.style.transformOrigin=`${p}% ${d}%`}if(a){const p=a.clipTop??0,d=a.clipRight??0,g=a.clipBottom??0,b=a.clipLeft??0;t.style.clipPath=`inset(${p}% ${d}% ${g}% ${b}%)`}if(o){const p=Nn(o);p&&(t.style.filter=p)}}buildTransformPart(t,n){if(t==="quaternion")return $n(n);if(typeof n!="number")return null;switch(t){case"x":case"motionPathX":return`translateX(${n}px)`;case"y":case"motionPathY":return`translateY(${n}px)`;case"z":return`translateZ(${n}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${n}deg)`;case"rotateX":return`rotateX(${n}deg)`;case"rotateY":return`rotateY(${n}deg)`;case"scale":return`scale(${n})`;case"scaleX":return`scaleX(${n})`;case"scaleY":return`scaleY(${n})`;case"scaleZ":return`scaleZ(${n})`;case"skewX":return`skewX(${n}deg)`;case"skewY":return`skewY(${n}deg)`;default:return null}}applyShine(t,n){t.dataset.shineBase||(t.dataset.shineBase=t.style.color||"currentColor");const i=t.dataset.shineBase,s=-20+n*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(${i}, ${i})`,r.backgroundSize="250% 100%, 100% 100%",r.backgroundPosition=`${s}% 0, 0 0`,r.backgroundRepeat="no-repeat",r.webkitBackgroundClip="text",r.backgroundClip="text"}applyStyleProperty(t,n,i){let s;if(t.namespaceURI===Hn&&n in ee){const o=Array.isArray(i)?i.join(", "):String(i);t.style[ee[n]]=o;return}else n==="fill"&&t.dataset?.elementType==="text"?s="color":s=jn[n]??n;let a;typeof i=="number"?te.has(n)||te.has(s)?a=`${i}px`:a=String(i):Array.isArray(i)?a=i.join(", "):a=i,t.style[s]=a}}class ne{media;offset;driftTolerance;constructor(t,n={}){this.media=t,this.offset=n.offset??0,this.driftTolerance=Math.max(0,n.driftTolerance??.15)}targetTime(t){return Math.max(0,t/1e3+this.offset)}update(t,n){const i=this.targetTime(t);n?(this.media.paused&&this.safePlay(),Math.abs(this.media.currentTime-i)>this.driftTolerance&&(this.media.currentTime=i)):(this.media.paused||this.media.pause(),this.media.currentTime!==i&&(this.media.currentTime=i))}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 zn(e,t,n,i,s){const r=n-s;if(r<0){t.paused||t.pause(),t.currentTime=0;return}e.update(r,i)}class ot{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,n={}){if(typeof t=="string"){const i=document.querySelector(t);if(!i)throw new Error(`Container not found: ${t}`);this.container=i}else this.container=t;this.options=n,this.adapter=new Mt}async load(t){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(t)}async loadSource(t){let n;if(typeof t=="string"){const i=await fetch(t);if(!i.ok)throw new Error(`Failed to load animation: ${i.statusText}`);n=await i.json()}else n=t;this.useDefinition(n),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(t){const n={...t.config};this.options.speed!==void 0&&(n.speed=this.options.speed),this.options.loop!==void 0&&(n.loop=this.options.loop),this.options.alternate!==void 0&&(n.alternate=this.options.alternate),this.timeline=at({...t,config:n}),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,n={}){if(t.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const i=new Set;for(const r of t){if(i.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);i.add(r.id)}const s=n.initial===void 0?t[0]:t.find(r=>r.id===n.initial);if(!s)throw new Error(`tinyfly: there is no scenario "${n.initial}"`);this.scenarioList=[...t],this.scenarioId=s.id,await this.loadSource(s.timeline)}get scenarios(){return this.scenarioList.map(t=>({id:t.id,label:t.label??t.id}))}get scenario(){return this.scenarioId}setScenario(t){const n=this.scenarioList.find(o=>o.id===t);if(!n||!this.timeline)return!1;if(t===this.scenarioId)return!0;const i=this.isPlaying,s=this.currentTime>=this.duration-.5,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=t,this.useDefinition(n.timeline),this.lastMarkerId=null;let a=0;return this.reducedMotion||s?a=this.duration:r!==void 0&&(a=this.markers.find(o=>o.id===r)?.time??0),this.seek(a),i&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(t){if(this.authored.has(t))return;const n={style:t.getAttribute("style")};t.children.length===0&&(n.text=t.textContent??"");const i=t.tagName.toLowerCase()==="path"?t:t.querySelector("path");i&&(n.path={element:i,d:i.getAttribute("d")}),this.authored.set(t,n)}restoreAuthored(){for(const[t,n]of this.authored){n.style===null?t.removeAttribute("style"):t.setAttribute("style",n.style),n.text!==void 0&&t.textContent!==n.text&&(t.textContent=n.text),n.path&&(n.path.d===null?n.path.element.removeAttribute("d"):n.path.element.setAttribute("d",n.path.d));const i=t.dataset;i&&delete i.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 n;for(const i of this.markers)if(i.time<=t+.5)n=i;else break;return n}caption(t,n){const i=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!i)return;const s=n??this.language(),r=a=>a?.[s]?.[i.id]??a?.[s.split("-")[0]]?.[i.id];return r(this.options.captions)??r(this.timeline?.captions)??i.label}next(){if(!this.timeline)return;const t=this.currentTime,n=this.markers.find(i=>i.time>t+.5);if(this.reducedMotion){this.seek(n?n.time:this.duration);return}t>=this.duration-.5||(this.stepping=n!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const t=this.currentTime,n=[...this.markers].reverse().find(i=>i.time<t-.5);this.pause(),this.seek(n?n.time:0)}goToMarker(t){const n=this.markers.find(i=>i.id===t);n&&(this.pause(),this.seek(n.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 n=t==="end"?this.timeline.duration:t==="start"?0:t;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,n))),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(n=>{for(const i of n)this.onScreen=i.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,n=t?.id;n!==this.lastMarkerId&&(this.lastMarkerId=n,this.options.onMarker(t))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(n=>{const i=n,s=Number(i.getAttribute("data-tinyfly-start")??"0")||0,r=i.getAttribute("data-volume");r!==null&&(i.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:i,startTime:s,sync:new ne(i)})})}syncAllMedia(t,n){for(const i of this.mediaTargets)zn(i.sync,i.el,t,n,i.startTime)}loadFromString(t){const n=JSON.parse(t);this.load(n)}registerTarget(t,n){if(typeof n=="string"){const i=this.container.querySelector(n);i&&(this.rememberAuthored(i),this.targets[t]=i,this.adapter.registerTarget(t,i))}else this.rememberAuthored(n),this.targets[t]=n,this.adapter.registerTarget(t,n)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(n=>{const i=n.closest("[data-tinyfly-symbol]");if(i&&i!==n)return;const s=n.getAttribute("data-tinyfly");s&&this.registerTarget(s,n)}),this.timeline&&new Set(this.timeline.tracks.map(i=>i.target)).forEach(i=>{if(!this.targets[i]){const s=this.container.querySelector(`[data-tinyfly="${i}"]`)||this.container.querySelector(`.${i}`)||this.container.querySelector(`#${i}`);s&&this.registerTarget(i,s)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const n=new Map(t.map(i=>[i.id,i]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(i=>{const s=i.getAttribute("data-tinyfly-symbol");if(!s)return;const r=n.get(s);if(!r||!r.timeline.tracks?.length)return;const a=new Mt;i.querySelectorAll("[data-tinyfly]").forEach(o=>{const c=o.getAttribute("data-tinyfly");c&&a.registerTarget(c,o)}),this.symbolInstances.push({adapter:a,timeline:at(r.timeline)})})}attachMedia(t,n){this.mediaSync=new ne(t,n),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 state(){return this.timeline?.getStateAtTime(this.timeline.currentTime)}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=n=>{if(this.isDestroyed||!this.timeline)return;const i=n-(this.lastTime??n);this.lastTime=n;const s=this.playhead;this.timeline.tick(i),this.stopAtMarker(s),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 n=this.timeline,i={time:n.currentTime,iteration:n.loopIteration,direction:n.direction};this.playhead=i;const s=this.markers;if(s.length===0)return;const{crossings:r}=Pn(s.map(a=>a.time),t,i,{duration:n.duration,alternate:n.config.alternate===!0,holding:n.repeatDelayRemaining>0});for(const a of r){if(a.kind!=="event")continue;const o=s[a.index];if(this.stepping||o.pause){this.stepping=!1,n.pause(),n.seek(o.time),this.playhead={time:o.time,iteration:n.loopIteration,direction:n.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 n of this.symbolInstances){const i=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(i>0?t%i:t))}}}async function Qn(e,t,n={}){const i=new ot(e,{...n,autoplay:!0});return await i.load(t),i}function Gn(e,t={}){return new ot(e,t)}const ie={play:"Play",pause:"Pause",prev:"Previous step",next:"Next step",restart:"Restart",scrub:"Position",speed:"Speed",reveal:"Reveal",step:"Step",of:"of",stepFormat:"{index} / {total}",scenario:"Scenario",fullscreen:"Full screen",exitFullscreen:"Exit full screen"},se="tinyfly-controls-style",Zn=`
3
3
  .tf-ctl { --tf-ctl-fg: #1d1d1f; --tf-ctl-bg: #f4f2ee; --tf-ctl-accent: #c2410c; --tf-ctl-radius: 8px;
4
4
  font: 14px/1.4 var(--tf-ctl-font, system-ui, sans-serif); color: var(--tf-ctl-fg); margin-top: 8px; }
5
5
  .tf-ctl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px; border-radius: var(--tf-ctl-radius); background: var(--tf-ctl-bg); }
@@ -2126,6 +2126,14 @@ class St {
2126
2126
  get currentTime() {
2127
2127
  return this.timeline?.currentTime ?? 0;
2128
2128
  }
2129
+ /**
2130
+ * The animated values at the playhead, for renderers that draw from values
2131
+ * rather than DOM elements (a canvas, or an SVG rebuilt each frame). Read it
2132
+ * from a `subscribe` listener. Undefined before a timeline loads.
2133
+ */
2134
+ get state() {
2135
+ return this.timeline?.getStateAtTime(this.timeline.currentTime);
2136
+ }
2129
2137
  /**
2130
2138
  * Get total duration.
2131
2139
  */