@algorisys/tinyfly 0.64.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 (140) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +672 -0
  3. package/bin/tinyfly.mjs +59 -0
  4. package/lib/addons/adapters.js +756 -0
  5. package/lib/addons/dom-adapter-ChrbtkLC.js +243 -0
  6. package/lib/addons/drivers.js +72 -0
  7. package/lib/addons/export.js +1169 -0
  8. package/lib/addons/gsap-compat.js +2576 -0
  9. package/lib/addons/interaction.js +225 -0
  10. package/lib/addons/smooth-scroll-DaSacemU.js +671 -0
  11. package/lib/addons/teach.js +215 -0
  12. package/lib/browser/tinyfly.iife.js +2 -0
  13. package/lib/browser/tinyfly.js +6372 -0
  14. package/lib/browser/tinyfly.umd.js +2 -0
  15. package/lib/cli/tools.js +2325 -0
  16. package/lib/embed/tinyfly-embed.iife.js +18 -0
  17. package/lib/embed/tinyfly-embed.js +2316 -0
  18. package/lib/engine/tinyfly-engine.js +1972 -0
  19. package/lib/engine/tinyfly-engine.umd.cjs +2 -0
  20. package/lib/frameworks/react.js +32 -0
  21. package/lib/frameworks/solid.js +27 -0
  22. package/lib/frameworks/svelte.js +15 -0
  23. package/lib/frameworks/vue.js +29 -0
  24. package/lib/player/tinyfly-player.es.js +2306 -0
  25. package/lib/player/tinyfly-player.iife.js +2 -0
  26. package/lib/player/tinyfly-player.umd.js +2 -0
  27. package/lib/types/adapters/canvas/canvas-adapter.d.ts +238 -0
  28. package/lib/types/adapters/canvas/index.d.ts +1 -0
  29. package/lib/types/adapters/dom/dom-adapter.d.ts +50 -0
  30. package/lib/types/adapters/dom/flip.d.ts +60 -0
  31. package/lib/types/adapters/dom/index.d.ts +2 -0
  32. package/lib/types/adapters/filter-utils.d.ts +32 -0
  33. package/lib/types/adapters/index.d.ts +5 -0
  34. package/lib/types/adapters/shine-utils.d.ts +26 -0
  35. package/lib/types/adapters/svg/index.d.ts +1 -0
  36. package/lib/types/adapters/svg/svg-adapter.d.ts +47 -0
  37. package/lib/types/adapters/svg-transform-box.d.ts +13 -0
  38. package/lib/types/adapters/text-content.d.ts +11 -0
  39. package/lib/types/adapters/webgl/index.d.ts +1 -0
  40. package/lib/types/adapters/webgl/webgl-adapter.d.ts +69 -0
  41. package/lib/types/browser/index.d.ts +41 -0
  42. package/lib/types/compat/gsap/custom-eases.d.ts +28 -0
  43. package/lib/types/compat/gsap/defaults.d.ts +19 -0
  44. package/lib/types/compat/gsap/draw-svg-vars.d.ts +36 -0
  45. package/lib/types/compat/gsap/ease-map.d.ts +51 -0
  46. package/lib/types/compat/gsap/image-sequence.d.ts +61 -0
  47. package/lib/types/compat/gsap/index.d.ts +65 -0
  48. package/lib/types/compat/gsap/inertia-vars.d.ts +39 -0
  49. package/lib/types/compat/gsap/keyframes-vars.d.ts +8 -0
  50. package/lib/types/compat/gsap/layout.d.ts +6 -0
  51. package/lib/types/compat/gsap/live-context.d.ts +87 -0
  52. package/lib/types/compat/gsap/live-draggable.d.ts +75 -0
  53. package/lib/types/compat/gsap/live-flip.d.ts +73 -0
  54. package/lib/types/compat/gsap/live-morph.d.ts +18 -0
  55. package/lib/types/compat/gsap/live-motion-path.d.ts +33 -0
  56. package/lib/types/compat/gsap/live-scroll-to.d.ts +52 -0
  57. package/lib/types/compat/gsap/live-scroll.d.ts +108 -0
  58. package/lib/types/compat/gsap/live-transition.d.ts +40 -0
  59. package/lib/types/compat/gsap/live.d.ts +341 -0
  60. package/lib/types/compat/gsap/morph-vars.d.ts +21 -0
  61. package/lib/types/compat/gsap/motion-path-vars.d.ts +38 -0
  62. package/lib/types/compat/gsap/playhead-crossings.d.ts +47 -0
  63. package/lib/types/compat/gsap/position.d.ts +37 -0
  64. package/lib/types/compat/gsap/quick-play.d.ts +38 -0
  65. package/lib/types/compat/gsap/split-text.d.ts +66 -0
  66. package/lib/types/compat/gsap/spring-vars.d.ts +34 -0
  67. package/lib/types/compat/gsap/stage.d.ts +182 -0
  68. package/lib/types/compat/gsap/stagger-grid.d.ts +30 -0
  69. package/lib/types/compat/gsap/text-vars.d.ts +39 -0
  70. package/lib/types/compat/gsap/timeline.d.ts +161 -0
  71. package/lib/types/compat/gsap/utils.d.ts +60 -0
  72. package/lib/types/compat/gsap/vars.d.ts +79 -0
  73. package/lib/types/drivers/index.d.ts +8 -0
  74. package/lib/types/drivers/scroll-driver.d.ts +218 -0
  75. package/lib/types/drivers/scroll-markers.d.ts +41 -0
  76. package/lib/types/drivers/scroll-math.d.ts +87 -0
  77. package/lib/types/drivers/scroll-pin.d.ts +45 -0
  78. package/lib/types/drivers/scroll-snap.d.ts +47 -0
  79. package/lib/types/drivers/smooth-scroll.d.ts +118 -0
  80. package/lib/types/drivers/types.d.ts +23 -0
  81. package/lib/types/drivers/visibility-driver.d.ts +56 -0
  82. package/lib/types/embed/controls.d.ts +46 -0
  83. package/lib/types/embed/index.d.ts +17 -0
  84. package/lib/types/embed/mount.d.ts +41 -0
  85. package/lib/types/embed/tools.d.ts +33 -0
  86. package/lib/types/engine/authoring/custom-ease.d.ts +49 -0
  87. package/lib/types/engine/authoring/index.d.ts +3 -0
  88. package/lib/types/engine/authoring/random.d.ts +38 -0
  89. package/lib/types/engine/authoring/resolve-values.d.ts +57 -0
  90. package/lib/types/engine/core/bake.d.ts +66 -0
  91. package/lib/types/engine/core/clock.d.ts +44 -0
  92. package/lib/types/engine/core/index.d.ts +8 -0
  93. package/lib/types/engine/core/inertia.d.ts +30 -0
  94. package/lib/types/engine/core/playhead-crossings.d.ts +47 -0
  95. package/lib/types/engine/core/spring.d.ts +132 -0
  96. package/lib/types/engine/core/stagger.d.ts +40 -0
  97. package/lib/types/engine/core/timeline.d.ts +203 -0
  98. package/lib/types/engine/core/track.d.ts +90 -0
  99. package/lib/types/engine/export/byte-writer.d.ts +36 -0
  100. package/lib/types/engine/export/css.d.ts +31 -0
  101. package/lib/types/engine/export/gif-decode.test-helper.d.ts +24 -0
  102. package/lib/types/engine/export/gif.d.ts +134 -0
  103. package/lib/types/engine/export/index.d.ts +9 -0
  104. package/lib/types/engine/export/lottie.d.ts +104 -0
  105. package/lib/types/engine/export/mp4.d.ts +64 -0
  106. package/lib/types/engine/export/quantize.d.ts +56 -0
  107. package/lib/types/engine/export/sprite-sheet.d.ts +46 -0
  108. package/lib/types/engine/export/video.d.ts +99 -0
  109. package/lib/types/engine/export/webp.d.ts +82 -0
  110. package/lib/types/engine/index.d.ts +7 -0
  111. package/lib/types/engine/interpolation/easing.d.ts +65 -0
  112. package/lib/types/engine/interpolation/index.d.ts +2 -0
  113. package/lib/types/engine/interpolation/interpolators.d.ts +25 -0
  114. package/lib/types/engine/path/index.d.ts +11 -0
  115. package/lib/types/engine/path/motion-path.d.ts +24 -0
  116. package/lib/types/engine/path/path-builders.d.ts +38 -0
  117. package/lib/types/engine/path/path-morph.d.ts +47 -0
  118. package/lib/types/engine/path/path-utils.d.ts +73 -0
  119. package/lib/types/engine/serialization/index.d.ts +1 -0
  120. package/lib/types/engine/serialization/json.d.ts +30 -0
  121. package/lib/types/engine/text/index.d.ts +2 -0
  122. package/lib/types/engine/text/text-value.d.ts +16 -0
  123. package/lib/types/engine/types.d.ts +401 -0
  124. package/lib/types/frameworks/react.d.ts +35 -0
  125. package/lib/types/frameworks/solid.d.ts +16 -0
  126. package/lib/types/frameworks/svelte.d.ts +19 -0
  127. package/lib/types/frameworks/vue.d.ts +27 -0
  128. package/lib/types/interaction/draggable.d.ts +133 -0
  129. package/lib/types/interaction/index.d.ts +3 -0
  130. package/lib/types/interaction/observer.d.ts +80 -0
  131. package/lib/types/interaction/snap.d.ts +30 -0
  132. package/lib/types/player/index.d.ts +7 -0
  133. package/lib/types/player/media-sync.d.ts +60 -0
  134. package/lib/types/player/player.d.ts +238 -0
  135. package/lib/types/player/sequence-types.d.ts +68 -0
  136. package/lib/types/player/sequencer.d.ts +91 -0
  137. package/lib/types/teach/diagrams.d.ts +137 -0
  138. package/lib/types/teach/index.d.ts +11 -0
  139. package/lib/types/teach/lesson.d.ts +55 -0
  140. package/package.json +170 -0
@@ -0,0 +1,2 @@
1
+ var tinyfly=(function(R){"use strict";function te(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 it=1;function St(i){return i.property==="text"&&"textConfig"in i}function st(i){return i.kind==="inertia"&&"inertia"in i}function nt(i){return i.kind==="spring"&&"spring"in i}function ie(i){return i.property==="motionPath"&&"motionPathConfig"in i}function At(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,At(s,i,t));return e}function Mt(i,t,e){if(e.offsets)return e.offsets[i]??0;const s=e.from??"start",n=At(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)=>Mt(s,i,t))}function rt(i,t){return i<=1?0:Math.max(...ne(i,t))}const Y=1,_t=6e4,j=_t/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(j+1),this.settledStep!==null?this.settledStep*Y:_t}simulateTo(t){if(this.settledStep!==null)return;const e=Math.min(t,j+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>j&&(this.settledStep=j)}}const kt=4,ae=.002,oe=1e-4,ce=6e4;function at(i){const t=i.friction??kt;return t>0?t:kt}function he(i){return i.from+i.velocity/at(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 wt(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 Pt(i){const t=Math.abs(wt(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)/at(i);return Math.min(ce,s*1e3)}function vt(i,t){if(t<=0)return i.from;const e=wt(i);if(t>=Pt(i))return e;const s=at(i);return i.from+(e-i.from)*(1-Math.exp(-s*t/1e3))}const ot=i=>i,ue=i=>i*i,fe=i=>1-(1-i)*(1-i),de=i=>i<.5?2*i*i:1-Math.pow(-2*i+2,2)/2,It=i=>i*i*i,Ct=i=>1-Math.pow(1-i,3),xt=i=>i<.5?4*i*i*i:1-Math.pow(-2*i+2,3)/2,pe={linear:ot,"ease-in":It,"ease-out":Ct,"ease-in-out":xt,"ease-in-quad":ue,"ease-out-quad":fe,"ease-in-out-quad":de,"ease-in-cubic":It,"ease-out-cubic":Ct,"ease-in-out-cubic":xt};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,f=p=>((u*p+h)*p+c)*p,d=p=>(3*o*p+2*a)*p+r,b=p=>{let g=p;for(let S=0;S<8;S++){const M=l(g)-p;if(Math.abs(M)<1e-7)return g;const m=d(g);if(Math.abs(m)<1e-7)break;g-=M/m}let y=0,T=1;for(g=p;y<T;){const S=l(g);if(Math.abs(S-p)<1e-7)return g;p>S?y=g:T=g,g=(y+T)/2}return g};return p=>{if(p<=0)return 0;if(p>=1)return 1;const g=b(p);return f(g)}}function ct(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 ge(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 ye=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 Se(i){switch(i.type){case"steps":return be(i.count,i.position);case"elastic":return ct(ge(i.amplitude,i.period),i.mode);case"bounce":return ct(ye,i.mode);case"back":return ct(Te(i.overshoot),i.mode)}}function Ae(i){return i===void 0?ot:te(i)?me(i.points):ee(i)?Se(i):pe[i]??ot}const Rt=32,Me=256,N=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,f=Math.cos(l),d=Math.sin(l),b=(i-o)/2,p=(t-c)/2,g=f*b+d*p,y=-d*b+f*p,T=g*g/(h*h)+y*y/(u*u);if(T>1){const w=Math.sqrt(T);h*=w,u*=w}const S=r===a?-1:1,M=h*h*u*u-h*h*y*y-u*u*g*g,m=h*h*y*y+u*u*g*g,_=S*Math.sqrt(Math.max(0,M/m)),A=_*h*y/u,B=-_*u*g/h,J=f*A-d*B+(i+o)/2,k=d*A+f*B+(t+c)/2,C=(w,I,x,q)=>{const bt=w*x+I*q,et=Math.sqrt((w*w+I*I)*(x*x+q*q)),Q=Math.acos(Math.max(-1,Math.min(1,bt/et)));return w*q-I*x<0?-Q:Q},P=C(1,0,(g-A)/h,(y-B)/u);let v=C((g-A)/h,(y-B)/u,(-g-A)/h,(-y-B)/u);!a&&v>0&&(v-=2*Math.PI),a&&v<0&&(v+=2*Math.PI);const $=Math.max(1,Math.ceil(Math.abs(v)/(Math.PI/2))),Tt=v/$,tt=4/3*Math.tan(Tt/4),Zt=w=>{const I=h*Math.cos(w),x=u*Math.sin(w);return[f*I-d*x+J,d*I+f*x+k]},Kt=w=>{const I=-h*Math.sin(w),x=u*Math.cos(w);return[f*I-d*x,d*I+f*x]},Jt=[];for(let w=0;w<$;w++){const I=P+w*Tt,x=I+Tt,[q,bt]=Zt(I),[et,Q]=w===$-1?[o,c]:Zt(x),[ki,wi]=Kt(I),[Pi,vi]=Kt(x);Jt.push([q+tt*ki,bt+tt*wi,et-tt*Pi,Q-tt*vi,et,Q])}return Jt}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 Dt(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 V(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,f=0;for(let d=1;d<=Rt;d++){const b=d/Rt,p=E(i,s,r,o,b),g=E(t,n,a,c,b);f+=Math.hypot(p-u,g-l),h.push(f),u=p,l=g}return{subpath:0,type:"C",points:[s,n,r,a,o,c],startX:i,startY:t,endX:o,endY:c,length:f,lengths:h}}function G(i){const t=N.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:g}of Pe(i)){const y=p.toUpperCase(),T=p!==y,S=we[y];if(y==="Z"){(s!==r||n!==a)&&l(V(s,n,r,a)),h>=0&&u.add(h),s=r,n=a,o=c=null;continue}for(let M=0;M+S<=g.length;M+=S){const m=g.slice(M,M+S),_=T?s:0,A=T?n:0;let B=null,J=null;switch(y){case"M":M===0?(s=m[0]+_,n=m[1]+A,r=s,a=n,(h<0||e[e.length-1]?.subpath===h)&&h++):(l(V(s,n,m[0]+_,m[1]+A)),s=m[0]+_,n=m[1]+A);break;case"L":l(V(s,n,m[0]+_,m[1]+A)),s=m[0]+_,n=m[1]+A;break;case"H":l(V(s,n,m[0]+_,n)),s=m[0]+_;break;case"V":l(V(s,n,s,m[0]+A)),n=m[0]+A;break;case"C":{const k=[m[0]+_,m[1]+A,m[2]+_,m[3]+A,m[4]+_,m[5]+A];l(z(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]+A,m[2]+_,m[3]+A];l(z(s,n,P)),B=[P[2],P[3]],s=P[4],n=P[5];break}case"Q":case"T":{let k=s,C=n;y==="Q"?(k=m[0]+_,C=m[1]+A):c&&(k=2*s-c[0],C=2*n-c[1]);const P=y==="Q"?m[2]+_:m[0]+_,v=y==="Q"?m[3]+A:m[1]+A;l(z(s,n,[s+.6666666666666666*(k-s),n+.6666666666666666*(C-n),P+.6666666666666666*(k-P),v+.6666666666666666*(C-v),P,v])),J=[k,C],s=P,n=v;break}case"A":{const k=m[5]+_,C=m[6]+A;let P=s,v=n;for(const $ of ve(s,n,m[0],m[1],m[2],m[3],m[4],k,C))l(z(P,v,$)),P=$[4],v=$[5];s=k,n=C;break}}o=B,c=J}}const f=e.reduce((p,g)=>p+g.length,0),d=[];for(let p=0;p<e.length;){const g=e[p].subpath;let y=p,T=0;for(;y<e.length&&e[y].subpath===g;)T+=e[y++].length;const S=e[p],M=e[y-1],m=u.has(g)||Math.abs(M.endX-S.startX)<1e-9&&Math.abs(M.endY-S.startY)<1e-9;d.push({start:p,end:y,length:T,closed:m}),p=y}const b={segments:e,totalLength:f,subpaths:d};return N.size>=Me&&N.delete(N.keys().next().value),N.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 Ce(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=Dt(i.startX,e,n,a,c),u=Dt(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),f=E(i.startX,e,n,a,l),d=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?f-b:b-f,u=c<.5?d-p:p-d}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 Bt(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 Ce(a,t-n);n+=a.length}return{x:0,y:0,angle:0}}function xe(i,t){const{segments:e,totalLength:s}=G(i);return Bt(e,Math.max(0,Math.min(1,t))*s)}const Re=24,De=320,Be=2.5,W=72,Ee=.2,Le=128,Z=new Map;let ht=0,L;const Et=i=>Math.round(i*100)/100;function Lt(i,t){const{segments:e,subpaths:s,totalLength:n}=G(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 lt(i,t){const e=i.closed?(t%1+1)%1:Math.max(0,Math.min(1,t)),s=Bt(i.segments,e*i.length,i.start,i.end);return[s.x,s.y]}function Ot(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 $t(i,t){const e=[];for(let s=0;s<t;s++)e.push(lt(i,i.closed?s/t:s/(t-1)));return e}function Ft(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)%W/W:0,reversed:e<0};const n=Ft($t(i,W)),r=Ft($t(t,W)),a=W;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 f=0;for(let d=0;d<a&&f<c;d++){const b=s?h?(l-d+a)%a:(d+l)%a:h?a-1-d:d,p=n[d][0]-r[b][0],g=n[d][1]-r[b][1];f+=p*p+g*g}f<c&&(c=f,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 Ot(i))o(l);for(const l of Ot(t))o(Fe(l,n,s));let c=[...a].sort((l,f)=>l-f);s&&(c=c.filter(l=>l<1));const h=[],u=[];for(const l of c)h.push(...lt(i,l)),u.push(...lt(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(Xt(i.from,a,o,u),Xt(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 Xt(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 Ye(i,t,e){const s=e.shapeIndex;if(L&&L.from===i&&L.to===t&&L.shapeIndex===s)return L.plan;const r=Z.get(String(s??"auto"))?.get(i)?.get(t);if(r)return L={from:i,to:t,shapeIndex:s,plan:r},r;const a=G(i).subpaths.filter(d=>d.length>0).length===G(t).subpaths.filter(d=>d.length>0).length,o=Lt(i,!a),c=Lt(t,!a),h={pairs:o.map((d,b)=>Xe(d,c[b],e))};ht>=Le&&(Z.clear(),ht=0);const u=String(s??"auto"),l=Z.get(u)??new Map;Z.set(u,l);const f=l.get(i)??new Map;return l.set(i,f),f.set(t,h),ht++,L={from:i,to:t,shapeIndex:s,plan:h},h}function Ne(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=Ye(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=Et(o.from[c]+(o.to[c]-o.from[c])*n),u=Et(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,qt=512,ut=new Map,ft=new Map;function Yt(i){const t=ut.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 ut.size<qt&&ut.set(i,s),s}const Nt=i=>i.charCodeAt(0)===35,Vt=i=>i.startsWith("rgb"),Wt=i=>i.startsWith("rgba"),We=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,dt=i=>Math.round(i).toString(16).padStart(2,"0");function Ue(i,t,e){return`#${dt(i)}${dt(t)}${dt(e)}`}function Ut(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<qt&&ft.set(i,a),a}const He=(i,t,e)=>{if(Nt(i)&&Nt(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((Vt(i)||Wt(i))&&(Vt(t)||Wt(t))){const s=Ut(i),n=Ut(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},Qe=(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},Ht=(i,t,e)=>e<1?i:t,je=(i,t,e)=>Ne(i,t,e);function ze(i){return typeof i=="number"?D:Array.isArray(i)?Qe:typeof i=="string"?i.startsWith("#")||i.startsWith("rgb")?He:Ve(i)?je:Ht:Ht}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+Mt(i,t,s)}class pt{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?rt(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=Ae(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?rt(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=Pt(t.inertia)}getValueAtTime(t){return vt(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:vt(this.track.inertia,t-r),start:r})}return s}getDuration(){const t=this.track.stagger?rt(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={...xe(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,f=Math.cos(l),d=Math.sin(l);e.angle=Math.atan2(n*f+a*d,s*f+r*d)*180/Math.PI}return i.autoRotate&&i.rotateOffset&&(e.angle+=i.rotateOffset),e}const mt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},ti=20;function ei(i){const t=mt[i??"upperCase"]??i??mt.upperCase,e=Array.from(t);return e.length>0?e:Array.from(mt.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),f=i.tweenLength===!1?o.length:Math.round(a.length+(o.length-a.length)*r),d=ei(i.chars),b=i.refreshRate??ti,p=b>0?Math.floor(e*b/1e3):0,g=i.seed??1;let y="";for(let T=0;T<f;T++){const S=c?T>=f-l:T<l,M=c?o[o.length-(f-T)]:o[T];S&&M!==void 0||M===" "||M===`
2
+ `?y+=M:y+=d[ii(g,T,p)%d.length]}return y}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,f=s.get(u);(!f||(l!==f.started?l:l?h>=f.start:h<=f.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,st(t)){this._trackPlayers.set(t.id,new Ke(t));return}if(nt(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 pt(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 pt(e)),this._motionPathTracks.set(t.id,t)}else this._trackPlayers.set(t.id,new pt(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(nt(s)||st(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:it,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)}_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=(d,b,p,g)=>{r.push([d,b]);const y=[];i.forEach((T,S)=>{(p==="forward"?(g?T>=d:T>d)&&T<=b:(g?T<=d:T<d)&&T>=b)&&y.push(S)}),y.sort((T,S)=>(p==="forward"?i[T]-i[S]:i[S]-i[T])||T-S);for(const T of y)n.push({kind:"event",index:T,direction:p})};let h=t.time,u=t.direction,l=t.fresh===!0;const f=Math.min(ri,Math.max(0,e.iteration-t.iteration));for(let d=0;d<f;d++){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 f>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 U(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(st(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:oi(t.inertia),...U(t)}}if(nt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...U(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),...U(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,...U(t)}}return Ge({id:i.id,target:i.target,property:i.property,keyframes:i.keyframes,...U(i)})}function K(i){const t=i.formatVersion??1;if(t>it)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${it}. 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 fi(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 di(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"]),gi=new Set(["originX","originY"]),yi=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Ti={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},jt={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},bi="http://www.w3.org/2000/svg";class H{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[f,d]of e)if(!(f==="x"&&o)&&!(f==="y"&&c)&&!((f==="rotate"||f==="rotateZ")&&h)){if(mi.has(f)){const b=this.buildTransformPart(f,d);b&&s.push(b)}else if(gi.has(f))typeof d=="number"&&((n??={})[f]=d);else if(yi.has(f))typeof d=="number"&&((r??={})[f]=d);else if(hi.has(f))(a??={})[f]=d;else if(f!=="perspective"){if(f!=="shine")if(f==="text"&&typeof d=="string")di(t,d);else if(f==="d"&&typeof d=="string"){const b=t;(b.tagName?.toLowerCase()==="path"?b:b.querySelector?.("path"))?.setAttribute?.("d",d)}else this.applyStyleProperty(t,f,d)}}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 f=n.originX??50,d=n.originY??50;t.style.transformOrigin=`${f}% ${d}%`}if(r){const f=r.clipTop??0,d=r.clipRight??0,b=r.clipBottom??0,p=r.clipLeft??0;t.style.clipPath=`inset(${f}% ${d}% ${b}% ${p}%)`}if(a){const f=fi(a);f&&(t.style.filter=f)}}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===bi&&e in jt){const o=Array.isArray(s)?s.join(", "):String(s);t.style[jt[e]]=o;return}else e==="fill"&&t.dataset?.elementType==="text"?n="color":n=Ti[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 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 yt{container;timeline=null;adapter;animationFrameId;lastTime;options;targets={};isDestroyed=!1;mediaSync;mediaTargets=[];symbolInstances=[];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 H}async load(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.options.speed!==void 0&&(e.config={...e.config,speed:this.options.speed}),this.options.loop!==void 0&&(e.config={...e.config,loop:this.options.loop}),this.options.alternate!==void 0&&(e.config={...e.config,alternate:this.options.alternate}),this.timeline=K(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(),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}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.listeners.clear(),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.targets[t]=s,this.adapter.registerTarget(t,s))}else 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 H;s.querySelectorAll("[data-tinyfly]").forEach(o=>{const c=o.getAttribute("data-tinyfly");c&&a.registerTarget(c,o)}),this.symbolInstances.push({adapter:a,timeline:K(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.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 yt(i,{...e,autoplay:!0});return await s.load(t),s}function Ai(i,t={}){return new yt(i,t)}class Gt{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 H,this.adapterB=new H}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 H;n.querySelectorAll("[data-tinyfly]").forEach(c=>{const h=c.getAttribute("data-tinyfly");h&&o.registerTarget(h,c)}),s.push({adapter:o,timeline:K(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?K(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 Mi(i,t,e={}){const s=new Gt(i,{...e,autoplay:!0});return await s.load(t),s}const _i={type:"none",duration:0};return R.DEFAULT_TRANSITION=_i,R.MediaSync=gt,R.TinyflyPlayer=yt,R.TinyflySequencer=Gt,R.create=Ai,R.play=Si,R.playSequence=Mi,R.syncMediaElement=zt,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"}),R})({});
@@ -0,0 +1,2 @@
1
+ (function(C,Y){typeof exports=="object"&&typeof module<"u"?Y(exports):typeof define=="function"&&define.amd?define(["exports"],Y):(C=typeof globalThis<"u"?globalThis:C||self,Y(C.tinyfly={}))})(this,(function(C){"use strict";function Y(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 At(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 N=1,kt=6e4,z=kt/N,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/N);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/N-e;return s+(n-s)*r}settleTime(){return this.simulateTo(z+1),this.settledStep!==null?this.settledStep*N:kt}simulateTo(t){if(this.settledStep!==null)return;const e=Math.min(t,z+1),s=N/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,fe=i=>1-(1-i)*(1-i),de=i=>i<.5?2*i*i:1-Math.pow(-2*i+2,2)/2,Ct=i=>i*i*i,xt=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":Ct,"ease-out":xt,"ease-in-out":Rt,"ease-in-quad":ue,"ease-out-quad":fe,"ease-in-out-quad":de,"ease-in-cubic":Ct,"ease-out-cubic":xt,"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,f=p=>((u*p+h)*p+c)*p,d=p=>(3*o*p+2*a)*p+r,b=p=>{let y=p;for(let S=0;S<8;S++){const M=l(y)-p;if(Math.abs(M)<1e-7)return y;const m=d(y);if(Math.abs(m)<1e-7)break;y-=M/m}let g=0,T=1;for(y=p;g<T;){const S=l(y);if(Math.abs(S-p)<1e-7)return y;p>S?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 f(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 Se(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 Ae(i){return i===void 0?ct:Y(i)?me(i.points):ee(i)?Se(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,f=Math.cos(l),d=Math.sin(l),b=(i-o)/2,p=(t-c)/2,y=f*b+d*p,g=-d*b+f*p,T=y*y/(h*h)+g*g/(u*u);if(T>1){const w=Math.sqrt(T);h*=w,u*=w}const S=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,_=S*Math.sqrt(Math.max(0,M/m)),A=_*h*g/u,B=-_*u*y/h,tt=f*A-d*B+(i+o)/2,k=d*A+f*B+(t+c)/2,x=(w,I,R,q)=>{const St=w*R+I*q,it=Math.sqrt((w*w+I*I)*(R*R+q*q)),j=Math.acos(Math.max(-1,Math.min(1,St/it)));return w*q-I*R<0?-j:j},P=x(1,0,(y-A)/h,(g-B)/u);let v=x((y-A)/h,(g-B)/u,(-y-A)/h,(-g-B)/u);!a&&v>0&&(v-=2*Math.PI),a&&v<0&&(v+=2*Math.PI);const $=Math.max(1,Math.ceil(Math.abs(v)/(Math.PI/2))),bt=v/$,et=4/3*Math.tan(bt/4),Kt=w=>{const I=h*Math.cos(w),R=u*Math.sin(w);return[f*I-d*R+tt,d*I+f*R+k]},Jt=w=>{const I=-h*Math.sin(w),R=u*Math.cos(w);return[f*I-d*R,d*I+f*R]},te=[];for(let w=0;w<$;w++){const I=P+w*bt,R=I+bt,[q,St]=Kt(I),[it,j]=w===$-1?[o,c]:Kt(R),[ki,wi]=Jt(I),[Pi,vi]=Jt(R);te.push([q+et*ki,St+et*wi,it-et*Pi,j-et*vi,it,j])}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,f=0;for(let d=1;d<=Dt;d++){const b=d/Dt,p=E(i,s,r,o,b),y=E(t,n,a,c,b);f+=Math.hypot(p-u,y-l),h.push(f),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:f,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,S=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+S<=y.length;M+=S){const m=y.slice(M,M+S),_=T?s:0,A=T?n:0;let B=null,tt=null;switch(g){case"M":M===0?(s=m[0]+_,n=m[1]+A,r=s,a=n,(h<0||e[e.length-1]?.subpath===h)&&h++):(l(W(s,n,m[0]+_,m[1]+A)),s=m[0]+_,n=m[1]+A);break;case"L":l(W(s,n,m[0]+_,m[1]+A)),s=m[0]+_,n=m[1]+A;break;case"H":l(W(s,n,m[0]+_,n)),s=m[0]+_;break;case"V":l(W(s,n,s,m[0]+A)),n=m[0]+A;break;case"C":{const k=[m[0]+_,m[1]+A,m[2]+_,m[3]+A,m[4]+_,m[5]+A];l(G(s,n,k)),B=[k[2],k[3]],s=k[4],n=k[5];break}case"S":{const[k,x]=o?[2*s-o[0],2*n-o[1]]:[s,n],P=[k,x,m[0]+_,m[1]+A,m[2]+_,m[3]+A];l(G(s,n,P)),B=[P[2],P[3]],s=P[4],n=P[5];break}case"Q":case"T":{let k=s,x=n;g==="Q"?(k=m[0]+_,x=m[1]+A):c&&(k=2*s-c[0],x=2*n-c[1]);const P=g==="Q"?m[2]+_:m[0]+_,v=g==="Q"?m[3]+A:m[1]+A;l(G(s,n,[s+2/3*(k-s),n+2/3*(x-n),P+2/3*(k-P),v+2/3*(x-v),P,v])),tt=[k,x],s=P,n=v;break}case"A":{const k=m[5]+_,x=m[6]+A;let P=s,v=n;for(const $ of ve(s,n,m[0],m[1],m[2],m[3],m[4],k,x))l(G(P,v,$)),P=$[4],v=$[5];s=k,n=x;break}}o=B,c=tt}}const f=e.reduce((p,y)=>p+y.length,0),d=[];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 S=e[p],M=e[g-1],m=u.has(y)||Math.abs(M.endX-S.startX)<1e-9&&Math.abs(M.endY-S.startY)<1e-9;d.push({start:p,end:g,length:T,closed:m}),p=g}const b={segments:e,totalLength:f,subpaths:d};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 Ce(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),f=E(i.startX,e,n,a,l),d=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?f-b:b-f,u=c<.5?d-p:p-d}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 Ce(a,t-n);n+=a.length}return{x:0,y:0,angle:0}}function xe(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 f=0;for(let d=0;d<a&&f<c;d++){const b=s?h?(l-d+a)%a:(d+l)%a:h?a-1-d:d,p=n[d][0]-r[b][0],y=n[d][1]-r[b][1];f+=p*p+y*y}f<c&&(c=f,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,f)=>l-f);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 Ye(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(d=>d.length>0).length===Z(t).subpaths.filter(d=>d.length>0).length,o=Ot(i,!a),c=Ot(t,!a),h={pairs:o.map((d,b)=>Xe(d,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 f=l.get(i)??new Map;return l.set(i,f),f.set(t,h),lt++,L={from:i,to:t,shapeIndex:s,plan:h},h}function Ne(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=Ye(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,Yt=512,ft=new Map,dt=new Map;function Nt(i){const t=ft.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 ft.size<Yt&&ft.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=dt.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 dt.size<Yt&&dt.set(i,a),a}const He=(i,t,e)=>{if(Vt(i)&&Vt(t)){const[s,n,r]=Nt(i),[a,o,c]=Nt(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},Qe=(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},Qt=(i,t,e)=>e<1?i:t,je=(i,t,e)=>Ne(i,t,e);function ze(i){return typeof i=="number"?D:Array.isArray(i)?Qe:typeof i=="string"?i.startsWith("#")||i.startsWith("rgb")?He:Ve(i)?je:Qt:Qt}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=Ae(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={...xe(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,f=Math.cos(l),d=Math.sin(l);e.angle=Math.atan2(n*f+a*d,s*f+r*d)*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),f=i.tweenLength===!1?o.length:Math.round(a.length+(o.length-a.length)*r),d=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<f;T++){const S=c?T>=f-l:T<l,M=c?o[o.length-(f-T)]:o[T];S&&M!==void 0||M===" "||M===`
2
+ `?g+=M:g+=d[ii(y,T,p)%d.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,f=s.get(u);(!f||(l!==f.started?l:l?h>=f.start:h<=f.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(At(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)}_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=(d,b,p,y)=>{r.push([d,b]);const g=[];i.forEach((T,S)=>{(p==="forward"?(y?T>=d:T>d)&&T<=b:(y?T<=d:T<d)&&T>=b)&&g.push(S)}),g.sort((T,S)=>(p==="forward"?i[T]-i[S]:i[S]-i[T])||T-S);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 f=Math.min(ri,Math.max(0,e.iteration-t.iteration));for(let d=0;d<f;d++){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 f>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(At(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 fi(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 di(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 jt=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={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"},bi="http://www.w3.org/2000/svg";class Q{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[f,d]of e)if(!(f==="x"&&o)&&!(f==="y"&&c)&&!((f==="rotate"||f==="rotateZ")&&h)){if(mi.has(f)){const b=this.buildTransformPart(f,d);b&&s.push(b)}else if(yi.has(f))typeof d=="number"&&((n??={})[f]=d);else if(gi.has(f))typeof d=="number"&&((r??={})[f]=d);else if(hi.has(f))(a??={})[f]=d;else if(f!=="perspective"){if(f!=="shine")if(f==="text"&&typeof d=="string")di(t,d);else if(f==="d"&&typeof d=="string"){const b=t;(b.tagName?.toLowerCase()==="path"?b:b.querySelector?.("path"))?.setAttribute?.("d",d)}else this.applyStyleProperty(t,f,d)}}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 f=n.originX??50,d=n.originY??50;t.style.transformOrigin=`${f}% ${d}%`}if(r){const f=r.clipTop??0,d=r.clipRight??0,b=r.clipBottom??0,p=r.clipLeft??0;t.style.clipPath=`inset(${f}% ${d}% ${b}% ${p}%)`}if(a){const f=fi(a);f&&(t.style.filter=f)}}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===bi&&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=Ti[e]??e;let a;typeof s=="number"?jt.has(e)||jt.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=[];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 Q}async load(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.options.speed!==void 0&&(e.config={...e.config,speed:this.options.speed}),this.options.loop!==void 0&&(e.config={...e.config,loop:this.options.loop}),this.options.alternate!==void 0&&(e.config={...e.config,alternate:this.options.alternate}),this.timeline=J(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(),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}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.listeners.clear(),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.targets[t]=s,this.adapter.registerTarget(t,s))}else 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 Q;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.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 Ai(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 Q,this.adapterB=new Q}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 Q;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 Mi(i,t,e={}){const s=new Zt(i,{...e,autoplay:!0});return await s.load(t),s}const _i={type:"none",duration:0};C.DEFAULT_TRANSITION=_i,C.MediaSync=gt,C.TinyflyPlayer=Tt,C.TinyflySequencer=Zt,C.create=Ai,C.play=Si,C.playSequence=Mi,C.syncMediaElement=Gt,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
@@ -0,0 +1,238 @@
1
+ import type { AnimationState } from '../../engine/types';
2
+ /** Gradient stop definition */
3
+ export interface GradientStop {
4
+ offset: number;
5
+ color: string;
6
+ }
7
+ /** Linear gradient definition */
8
+ export interface LinearGradient {
9
+ type: 'linear';
10
+ angle: number;
11
+ stops: GradientStop[];
12
+ }
13
+ /** Radial gradient definition */
14
+ export interface RadialGradient {
15
+ type: 'radial';
16
+ centerX: number;
17
+ centerY: number;
18
+ radius: number;
19
+ stops: GradientStop[];
20
+ }
21
+ /** Gradient type union */
22
+ export type Gradient = LinearGradient | RadialGradient;
23
+ /** Fill value can be a solid color string or a gradient */
24
+ export type FillValue = string | Gradient;
25
+ /** Check if a fill value is a gradient */
26
+ export declare function isGradient(fill: FillValue | undefined): fill is Gradient;
27
+ /** Base properties for all canvas targets */
28
+ export interface CanvasTargetBase {
29
+ x: number;
30
+ y: number;
31
+ opacity?: number;
32
+ rotate?: number;
33
+ rotateX?: number;
34
+ rotateY?: number;
35
+ scale?: number;
36
+ scaleX?: number;
37
+ scaleY?: number;
38
+ skewX?: number;
39
+ skewY?: number;
40
+ /**
41
+ * Transform pivot, as a percentage of the target's bounding box
42
+ * (0 = left/top, 50 = centre, 100 = right/bottom). Defaults to 50/50, which
43
+ * is the behaviour Canvas had before origins existed.
44
+ */
45
+ originX?: number;
46
+ originY?: number;
47
+ fillStyle?: FillValue;
48
+ strokeStyle?: string;
49
+ lineWidth?: number;
50
+ clipTop?: number;
51
+ clipRight?: number;
52
+ clipBottom?: number;
53
+ clipLeft?: number;
54
+ blur?: number;
55
+ brightness?: number;
56
+ glow?: number;
57
+ glowColor?: string;
58
+ shadowX?: number;
59
+ shadowY?: number;
60
+ shadowBlur?: number;
61
+ shadowColor?: string;
62
+ shine?: number;
63
+ }
64
+ /** Rectangle target */
65
+ export interface RectTarget extends CanvasTargetBase {
66
+ type: 'rect';
67
+ width: number;
68
+ height: number;
69
+ borderRadius?: number;
70
+ }
71
+ /** Circle target */
72
+ export interface CircleTarget extends CanvasTargetBase {
73
+ type: 'circle';
74
+ radius: number;
75
+ }
76
+ /** Text target */
77
+ export interface TextTarget extends CanvasTargetBase {
78
+ type: 'text';
79
+ text: string;
80
+ fontSize?: number;
81
+ fontFamily?: string;
82
+ fontWeight?: number;
83
+ textAlign?: 'left' | 'center' | 'right';
84
+ textBaseline?: CanvasTextBaseline;
85
+ }
86
+ /** Line target */
87
+ export interface LineTarget extends CanvasTargetBase {
88
+ type: 'line';
89
+ x2: number;
90
+ y2: number;
91
+ lineCap?: CanvasLineCap;
92
+ }
93
+ /** Path target (SVG path data) */
94
+ export interface PathTarget extends CanvasTargetBase {
95
+ type: 'path';
96
+ d: string;
97
+ lineCap?: CanvasLineCap;
98
+ lineJoin?: CanvasLineJoin;
99
+ }
100
+ /** Image target */
101
+ export interface ImageTarget extends CanvasTargetBase {
102
+ type: 'image';
103
+ width: number;
104
+ height: number;
105
+ image: CanvasImageSource | null;
106
+ /** How the source fits the box (default 'fill'). */
107
+ objectFit?: 'contain' | 'cover' | 'fill';
108
+ /** Rounded-corner clip radius in px (default 0). */
109
+ borderRadius?: number;
110
+ }
111
+ /** Union of all canvas target types */
112
+ export type CanvasTarget = RectTarget | CircleTarget | TextTarget | LineTarget | PathTarget | ImageTarget;
113
+ /**
114
+ * CanvasAdapter manages canvas drawing objects and applies
115
+ * animation state to them. Call render() in your animation loop
116
+ * to draw all targets.
117
+ */
118
+ export declare class CanvasAdapter {
119
+ private targets;
120
+ private targetOrder;
121
+ private animationOffsets;
122
+ private aliases;
123
+ /**
124
+ * Register a canvas drawing target.
125
+ * @param id - The ID to register the target under
126
+ * @param target - The canvas target to register
127
+ * @param aliasFor - If provided, this ID is an alias for another target (won't render separately)
128
+ */
129
+ registerTarget(id: string, target: CanvasTarget, aliasFor?: string): void;
130
+ /**
131
+ * Unregister a target by its ID.
132
+ */
133
+ unregisterTarget(id: string): void;
134
+ /**
135
+ * Get a registered target.
136
+ */
137
+ getTarget(id: string): CanvasTarget | undefined;
138
+ /**
139
+ * Clear all registered targets.
140
+ */
141
+ clearTargets(): void;
142
+ private static readonly PROPERTY_MAP;
143
+ private static readonly OFFSET_PROPERTIES;
144
+ /**
145
+ * Apply animation state to all registered targets.
146
+ * Position properties (x, y) are treated as offsets applied via ctx.translate().
147
+ * This matches how DOM/CSS transforms work (entire element moves together).
148
+ */
149
+ applyState(state: AnimationState): void;
150
+ /**
151
+ * Get animation offset for a target (for testing).
152
+ */
153
+ getAnimationOffset(id: string): {
154
+ x: number;
155
+ y: number;
156
+ } | undefined;
157
+ /**
158
+ * Render all targets to the provided canvas context.
159
+ * Call this in your animation loop after applyState().
160
+ */
161
+ render(ctx: CanvasRenderingContext2D): void;
162
+ /**
163
+ * Render a single target.
164
+ */
165
+ private renderTarget;
166
+ /**
167
+ * Resolve a fill style to a canvas-compatible value.
168
+ */
169
+ private resolveFillStyle;
170
+ /**
171
+ * Create a canvas linear gradient from a LinearGradient definition.
172
+ */
173
+ private createLinearGradient;
174
+ /**
175
+ * Create a canvas radial gradient from a RadialGradient definition.
176
+ */
177
+ private createRadialGradient;
178
+ /**
179
+ * Get target bounding box for gradient calculations.
180
+ */
181
+ private getTargetBounds;
182
+ /**
183
+ * Render a rectangle.
184
+ */
185
+ private renderRect;
186
+ /**
187
+ * Draw a rounded rectangle path.
188
+ */
189
+ private roundRect;
190
+ /**
191
+ * Render a circle.
192
+ */
193
+ private renderCircle;
194
+ /**
195
+ * Render text.
196
+ */
197
+ private renderText;
198
+ /**
199
+ * Render a line.
200
+ */
201
+ private renderLine;
202
+ /**
203
+ * Render an SVG path.
204
+ */
205
+ private renderPath;
206
+ /**
207
+ * Render an image.
208
+ */
209
+ private renderImage;
210
+ /**
211
+ * Transform pivot X: the target's centre, shifted by `originX` across its
212
+ * own width. `originX: 0` pivots on the left edge, 100 on the right.
213
+ */
214
+ private getPivotX;
215
+ /** Transform pivot Y — see `getPivotX`. */
216
+ private getPivotY;
217
+ /**
218
+ * Bounding-box width used to resolve `originX`. Circles use their diameter;
219
+ * text is approximated from its font size, since measuring it would need the
220
+ * context and the pivot only has to be stable, not typographically exact.
221
+ */
222
+ private getBoundsWidth;
223
+ /** Bounding-box height used to resolve `originY`. See `getBoundsWidth`. */
224
+ private getBoundsHeight;
225
+ /**
226
+ * Get the center X coordinate of a target.
227
+ */
228
+ private getCenterX;
229
+ /**
230
+ * Get the center Y coordinate of a target.
231
+ */
232
+ private getCenterY;
233
+ /**
234
+ * Load an image and return a promise that resolves to the image.
235
+ * Useful for creating ImageTarget objects.
236
+ */
237
+ static loadImage(src: string): Promise<HTMLImageElement>;
238
+ }
@@ -0,0 +1 @@
1
+ export * from './canvas-adapter';
@@ -0,0 +1,50 @@
1
+ import type { AnimationState } from '../../engine/types';
2
+ /**
3
+ * DOMAdapter applies animation state to HTML elements.
4
+ * It maps animation properties to CSS styles and handles
5
+ * transform composition.
6
+ */
7
+ export declare class DOMAdapter {
8
+ private targets;
9
+ /**
10
+ * Register an HTML element as an animation target.
11
+ */
12
+ registerTarget(id: string, element: HTMLElement): void;
13
+ /**
14
+ * Unregister a target by its ID.
15
+ */
16
+ unregisterTarget(id: string): void;
17
+ /**
18
+ * Get a registered target element.
19
+ */
20
+ getTarget(id: string): HTMLElement | undefined;
21
+ /**
22
+ * Clear all registered targets.
23
+ */
24
+ clearTargets(): void;
25
+ /**
26
+ * Apply animation state to all registered targets.
27
+ */
28
+ applyState(state: AnimationState): void;
29
+ /**
30
+ * Apply properties to a single element.
31
+ */
32
+ private applyProperties;
33
+ /**
34
+ * Build a transform function string for a property.
35
+ */
36
+ private buildTransformPart;
37
+ /**
38
+ * Apply a shine sweep to a (text) element.
39
+ *
40
+ * `progress` runs 0..1 as the highlight travels from just off the left edge to
41
+ * just off the right. Two layered, text-clipped gradients are used: a moving
42
+ * white highlight band on top of a solid layer of the element's base colour,
43
+ * so the text stays visible while the sheen passes over the glyphs.
44
+ */
45
+ private applyShine;
46
+ /**
47
+ * Apply a single style property to an element.
48
+ */
49
+ private applyStyleProperty;
50
+ }
@@ -0,0 +1,60 @@
1
+ import type { Track, EasingType } from '../../engine';
2
+ /**
3
+ * FLIP layout transitions, compiled to ordinary keyframes.
4
+ *
5
+ * GSAP's Flip measures the page, applies your layout change, measures again,
6
+ * and animates the difference — re-measuring on every run. The engine cannot do
7
+ * that: reading live layout is exactly the implicit browser state that
8
+ * determinism rule 5 forbids.
9
+ *
10
+ * So measurement happens *here*, in the DOM layer, at authoring time. The
11
+ * output is a set of plain two-keyframe tracks that serialize and replay like
12
+ * anything else. The trade-off, and it is a real one: the resulting JSON is a
13
+ * snapshot of one specific layout change. Re-run it after the page reflows —
14
+ * a different viewport, different text — and it will animate the old geometry.
15
+ * Recompute it when that matters.
16
+ */
17
+ export interface FlipTarget {
18
+ /** Name the engine knows this element by */
19
+ name: string;
20
+ /** The element to measure */
21
+ element: Element;
22
+ }
23
+ export interface FlipOptions {
24
+ /** Duration of the generated tracks, in milliseconds (default: 600) */
25
+ duration?: number;
26
+ /** Easing applied to the end keyframe (default: 'ease-out') */
27
+ easing?: EasingType;
28
+ /** Animate size as well as position (default: true) */
29
+ scale?: boolean;
30
+ /** Prefix for generated track ids (default: 'flip') */
31
+ idPrefix?: string;
32
+ }
33
+ interface Measurement {
34
+ left: number;
35
+ top: number;
36
+ width: number;
37
+ height: number;
38
+ }
39
+ /** Snapshot of a set of elements' geometry, taken before a layout change. */
40
+ export interface FlipState {
41
+ measurements: Map<string, Measurement>;
42
+ }
43
+ /**
44
+ * Measure a set of elements. Call this *before* the layout change.
45
+ */
46
+ export declare function recordFlipState(targets: FlipTarget[]): FlipState;
47
+ /**
48
+ * Measure again and emit tracks animating from the recorded geometry to the
49
+ * current geometry. Call this *after* the layout change.
50
+ *
51
+ * Elements whose geometry did not change produce no tracks, so a Flip over a
52
+ * long list only animates what actually moved.
53
+ */
54
+ export declare function buildFlipTracks(before: FlipState, targets: FlipTarget[], options?: FlipOptions): Track[];
55
+ /**
56
+ * Measure, run a layout change, measure again, and return the tracks — the
57
+ * one-call form of the two functions above.
58
+ */
59
+ export declare function flip(targets: FlipTarget[], applyLayoutChange: () => void, options?: FlipOptions): Track[];
60
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './dom-adapter';
2
+ export * from './flip';