@algorisys/tinyfly 0.114.0 → 0.116.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.
- package/README.md +13 -8
- package/docs/api-reference.md +2 -1
- package/docs/character-appearance.md +27 -2
- package/docs/editor-guide.md +1 -1
- package/docs/examples.md +1 -1
- package/docs/getting-started.md +1 -1
- package/docs/gsap-compat.md +1 -1
- package/docs/llm-guide.md +18 -0
- package/docs/maps.md +2 -2
- package/docs/math.md +280 -0
- package/docs/teaching.md +1 -1
- package/lib/addons/characters.js +2646 -2584
- package/lib/addons/{cricket-play-BZNhfgOK.js → cricket-play-C5CkNOc6.js} +2187 -2005
- package/lib/addons/math.js +2864 -0
- package/lib/addons/sports.js +1 -1
- package/lib/browser/tinyfly-math.iife.js +53 -0
- package/lib/browser/tinyfly.iife.js +12 -12
- package/lib/browser/tinyfly.js +4948 -4699
- package/lib/browser/tinyfly.umd.js +12 -12
- package/lib/embed/tinyfly-embed.iife.js +1 -1
- package/lib/embed/tinyfly-embed.js +8 -0
- package/lib/player/tinyfly-player.es.js +8 -0
- package/lib/player/tinyfly-player.iife.js +1 -1
- package/lib/player/tinyfly-player.umd.js +1 -1
- package/lib/types/characters/capabilities.d.ts +8 -0
- package/lib/types/characters/character.d.ts +4 -0
- package/lib/types/characters/index.d.ts +2 -0
- package/lib/types/characters/look/illustrated-pen.d.ts +36 -0
- package/lib/types/characters/look/illustration-color.d.ts +13 -0
- package/lib/types/characters/look/pen.d.ts +18 -5
- package/lib/types/math/browser-entry.d.ts +3 -0
- package/lib/types/math/embed/auto-mount-math.d.ts +7 -0
- package/lib/types/math/embed/explorable.d.ts +46 -0
- package/lib/types/math/embed/mount-math.d.ts +31 -0
- package/lib/types/math/expr/differentiate.d.ts +7 -0
- package/lib/types/math/expr/evaluate.d.ts +21 -0
- package/lib/types/math/expr/parse-expression.d.ts +50 -0
- package/lib/types/math/figure/derived.d.ts +17 -0
- package/lib/types/math/figure/display-list.d.ts +87 -0
- package/lib/types/math/figure/figure-spec.d.ts +239 -0
- package/lib/types/math/figure/item-context.d.ts +33 -0
- package/lib/types/math/figure/items/calculus.d.ts +7 -0
- package/lib/types/math/figure/items/curves.d.ts +7 -0
- package/lib/types/math/figure/items/grid.d.ts +5 -0
- package/lib/types/math/figure/items/regions.d.ts +5 -0
- package/lib/types/math/figure/items/text.d.ts +5 -0
- package/lib/types/math/figure/items/vectors.d.ts +9 -0
- package/lib/types/math/figure/layout-figure.d.ts +13 -0
- package/lib/types/math/figure/plane.d.ts +20 -0
- package/lib/types/math/figure/validate-spec.d.ts +2 -0
- package/lib/types/math/index.d.ts +43 -0
- package/lib/types/math/linear/mat2.d.ts +41 -0
- package/lib/types/math/linear/vec2.d.ts +18 -0
- package/lib/types/math/presets/calculus.d.ts +59 -0
- package/lib/types/math/presets/linear-algebra.d.ts +42 -0
- package/lib/types/math/render/arrow.d.ts +10 -0
- package/lib/types/math/render/display-list-to-svg.d.ts +10 -0
- package/lib/types/math/render/draw-display-list.d.ts +6 -0
- package/lib/types/math/steps/math-steps.d.ts +34 -0
- package/lib/types/math/targets/math-target.d.ts +43 -0
- package/lib/types/math/tex/equation-morph.d.ts +21 -0
- package/lib/types/math/tex/glyph-metrics.d.ts +24 -0
- package/lib/types/math/tex/tex-layout.d.ts +59 -0
- package/lib/types/math/tex/tex-parser.d.ts +88 -0
- package/lib/types/player/player.d.ts +6 -0
- package/llms-full.txt +388 -12
- package/llms.txt +32 -31
- package/package.json +6 -2
- package/skills/tinyfly/SKILL.md +13 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function($){"use strict";function pe(e){return typeof e=="object"&&e!==null&&e.type==="cubic-bezier"}function me(e){return typeof e=="object"&&e!==null&&e.type!=="cubic-bezier"}const et=2;function ge(e){return e.some(t=>t.interpolation!==void 0)?2:1}function At(e){return e.property==="text"&&"textConfig"in e}function ht(e){return e.kind==="inertia"&&"inertia"in e}function ut(e){return e.kind==="spring"&&"spring"in e}function ye(e){return e.property==="motionPath"&&"motionPathConfig"in e}function be(e,t){if(!(t>0))return e;const n=1e3/t;return Math.floor(e/n+1e-9)*n}function Et(e,t,n="start"){if(t<=1)return 0;if(typeof n=="number"){const i=Math.max(0,Math.min(t-1,n));return Math.abs(e-i)}switch(n){case"end":return t-1-e;case"center":return Math.abs(e-(t-1)/2);case"edges":return(t-1)/2-Math.abs(e-(t-1)/2);default:return e}}function ve(e,t="start"){if(e<=1)return 0;let n=0;for(let i=0;i<e;i++)n=Math.max(n,Et(i,e,t));return n}function Pt(e,t,n){if(n.offsets)return n.offsets[e]??0;const i=n.from??"start",s=Et(e,t,i);if(n.amount!==void 0){const r=ve(t,i);return r===0?0:n.amount*s/r}return n.each!==void 0?n.each*s:0}function ke(e,t){return Array.from({length:e},(n,i)=>Pt(i,e,t))}function dt(e,t){return e<=1?0:Math.max(...ke(e,t))}const H=1,Ct=6e4,nt=Ct/H,B={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1};class we{from;to;stiffness;damping;mass;restDelta;restSpeed;distance;samples;velocity;settledStep=null;constructor(t){this.from=t.from,this.to=t.to,this.stiffness=t.stiffness??B.stiffness,this.damping=t.damping??B.damping,this.mass=t.mass??B.mass,this.restDelta=t.restDelta??B.restDelta,this.restSpeed=t.restSpeed??B.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=t.velocity??B.velocity,this.isAtRest(this.from)&&(this.settledStep=0)}isAtRest(t){return Math.abs(t-this.to)<this.restDelta*this.distance&&Math.abs(this.velocity)<this.restSpeed*this.distance}valueAt(t){if(t<=0)return this.from;const n=Math.floor(t/H);if(this.simulateTo(n+1),this.settledStep!==null&&n>=this.settledStep)return this.to;const i=this.samples[Math.min(n,this.samples.length-1)],s=this.samples[Math.min(n+1,this.samples.length-1)],r=t/H-n;return i+(s-i)*r}settleTime(){return this.simulateTo(nt+1),this.settledStep!==null?this.settledStep*H:Ct}simulateTo(t){if(this.settledStep!==null)return;const n=Math.min(t,nt+1),i=H/1e3;for(;this.samples.length<n;){const s=this.samples[this.samples.length-1],r=s-this.to,a=-this.stiffness*r,o=-this.damping*this.velocity,c=(a+o)/this.mass;this.velocity+=c*i;const l=s+this.velocity*i;if(this.samples.push(l),this.isAtRest(l)){this.settledStep=this.samples.length-1;return}}this.samples.length>nt&&(this.settledStep=nt)}}const It=4,xe=.002,Me=1e-4,Se=6e4;function ft(e){const t=e.friction??It;return t>0?t:It}function Te(e){return e.from+e.velocity/ft(e)}function _e(e,t){if(t===void 0)return e;if(typeof t=="number")return t>0?Math.round(e/t)*t:e;if(t.length===0)return e;let n=t[0];for(const i of t)Math.abs(i-e)<Math.abs(n-e)&&(n=i);return n}function Rt(e){let t=_e(Te(e),e.end);return e.min!==void 0&&(t=Math.max(e.min,t)),e.max!==void 0&&(t=Math.min(e.max,t)),t}function $t(e){const t=Math.abs(Rt(e)-e.from);if(t===0)return 0;const n=e.restDelta??Math.max(Me,t*xe);if(n>=t)return 0;const i=Math.log(t/n)/ft(e);return Math.min(Se,i*1e3)}function Lt(e,t){if(t<=0)return e.from;const n=Rt(e);if(t>=$t(e))return n;const i=ft(e);return e.from+(n-e.from)*(1-Math.exp(-i*t/1e3))}const pt=e=>e,Ae=e=>e*e,Ee=e=>1-(1-e)*(1-e),Pe=e=>e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2,Dt=e=>e*e*e,Ot=e=>1-Math.pow(1-e,3),Nt=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,Ce={linear:pt,"ease-in":Dt,"ease-out":Ot,"ease-in-out":Nt,"ease-in-quad":Ae,"ease-out-quad":Ee,"ease-in-out-quad":Pe,"ease-in-cubic":Dt,"ease-out-cubic":Ot,"ease-in-out-cubic":Nt};function Ie(e){const[t,n,i,s]=e,r=3*t,a=3*(i-t)-r,o=1-r-a,c=3*n,l=3*(s-n)-c,u=1-c-l,h=d=>((o*d+a)*d+r)*d,f=d=>((u*d+l)*d+c)*d,m=d=>(3*o*d+2*a)*d+r,p=d=>{let g=d;for(let k=0;k<8;k++){const M=h(g)-d;if(Math.abs(M)<1e-7)return g;const y=m(g);if(Math.abs(y)<1e-7)break;g-=M/y}let b=0,v=1;for(g=d;b<v;){const k=h(g);if(Math.abs(k-d)<1e-7)return g;d>k?b=g:v=g,g=(b+v)/2}return g};return d=>{if(d<=0)return 0;if(d>=1)return 1;const g=p(d);return f(g)}}function mt(e,t="out"){if(t==="out")return e;const n=i=>1-e(1-i);return t==="in"?n:i=>i<.5?n(i*2)/2:e(i*2-1)/2+.5}function Re(e=1,t=.3){const n=Math.max(1,e),i=t/(2*Math.PI)*Math.asin(1/n);return s=>s<=0?0:s>=1?1:n*Math.pow(2,-10*s)*Math.sin((s-i)*(2*Math.PI)/t)+1}const $e=e=>{if(e<=0)return 0;if(e>=1)return 1;if(e<1/2.75)return 7.5625*e*e;if(e<2/2.75){const s=e-.5454545454545454;return 7.5625*s*s+.75}if(e<2.5/2.75){const s=e-.8181818181818182;return 7.5625*s*s+.9375}const i=e-2.625/2.75;return 7.5625*i*i+.984375};function Le(e=1.70158){return t=>{if(t<=0)return 0;if(t>=1)return 1;const n=t-1;return n*n*((e+1)*n+e)+1}}function De(e,t="end"){const n=Math.max(1,Math.floor(e));return i=>{if(i>=1)return 1;if(i<=0)return t==="start"||t==="both"?t==="start"?1/n:1/(n+1):0;const s=Math.floor(i*n);switch(t){case"start":return Math.min(1,(s+1)/n);case"both":return(s+1)/(n+1);case"none":return n===1?0:Math.min(1,s/(n-1));default:return s/n}}}function Oe(e){switch(e.type){case"steps":return De(e.count,e.position);case"elastic":return mt(Re(e.amplitude,e.period),e.mode);case"bounce":return mt($e,e.mode);case"back":return mt(Le(e.overshoot),e.mode)}}function Ne(e){return e===void 0?pt:pe(e)?Ie(e.points):me(e)?Oe(e):Ce[e]??pt}const Ft=32,Fe=256,z=new Map,Xe=/[MmLlHhVvCcSsQqTtAaZz]/,Ye=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,Ve={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function qe(e){const t=[];let n=0,i=null;const s=()=>{for(;n<e.length&&/[\s,]/.test(e[n]);)n++};for(;n<e.length&&(s(),!(n>=e.length));){const r=e[n];if(Xe.test(r)){i={type:r,args:[]},t.push(i),n++;continue}if(!i)break;const a=i.type==="A"||i.type==="a",o=i.args.length%7;if(a&&(o===3||o===4)){if(r!=="0"&&r!=="1")break;i.args.push(r==="1"?1:0),n++;continue}const c=Ye.exec(e.slice(n));if(!c)break;i.args.push(parseFloat(c[0])),n+=c[0].length}return t}function We(e,t,n,i,s,r,a,o,c){if(e===o&&t===c)return[];let l=Math.abs(n),u=Math.abs(i);if(l===0||u===0)return[[e,t,o,c,o,c]];const h=s*Math.PI/180,f=Math.cos(h),m=Math.sin(h),p=(e-o)/2,d=(t-c)/2,g=f*p+m*d,b=-m*p+f*d,v=g*g/(l*l)+b*b/(u*u);if(v>1){const A=Math.sqrt(v);l*=A,u*=A}const k=r===a?-1:1,M=l*l*u*u-l*l*b*b-u*u*g*g,y=l*l*b*b+u*u*g*g,S=k*Math.sqrt(Math.max(0,M/y)),w=S*l*b/u,P=-S*u*g/l,W=f*w-m*P+(e+o)/2,T=m*w+f*P+(t+c)/2,R=(A,I,D,j)=>{const _t=A*D+I*j,lt=Math.sqrt((A*A+I*I)*(D*D+j*j)),tt=Math.acos(Math.max(-1,Math.min(1,_t/lt)));return A*j-I*D<0?-tt:tt},_=R(1,0,(g-w)/l,(b-P)/u);let C=R((g-w)/l,(b-P)/u,(-g-w)/l,(-b-P)/u);!a&&C>0&&(C-=2*Math.PI),a&&C<0&&(C+=2*Math.PI);const O=Math.max(1,Math.ceil(Math.abs(C)/(Math.PI/2))),x=C/O,E=4/3*Math.tan(x/4),F=A=>{const I=l*Math.cos(A),D=u*Math.sin(A);return[f*I-m*D+W,m*I+f*D+T]},N=A=>{const I=-l*Math.sin(A),D=u*Math.cos(A);return[f*I-m*D,m*I+f*D]},L=[];for(let A=0;A<O;A++){const I=_+A*x,D=I+x,[j,_t]=F(I),[lt,tt]=A===O-1?[o,c]:F(D),[vi,ki]=N(I),[wi,xi]=N(D);L.push([j+E*vi,_t+E*ki,lt-E*wi,tt-E*xi,lt,tt])}return L}function Y(e,t,n,i,s){const r=1-s;return r*r*r*e+3*r*r*s*t+3*r*s*s*n+s*s*s*i}function Xt(e,t,n,i,s){const r=1-s;return 3*r*r*(t-e)+6*r*s*(n-t)+3*s*s*(i-n)}function Q(e,t,n,i){return{subpath:0,type:"L",points:[n,i],startX:e,startY:t,endX:n,endY:i,length:Math.hypot(n-e,i-t)}}function it(e,t,n){const[i,s,r,a,o,c]=n,l=[0];let u=e,h=t,f=0;for(let m=1;m<=Ft;m++){const p=m/Ft,d=Y(e,i,r,o,p),g=Y(t,s,a,c,p);f+=Math.hypot(d-u,g-h),l.push(f),u=d,h=g}return{subpath:0,type:"C",points:[i,s,r,a,o,c],startX:e,startY:t,endX:o,endY:c,length:f,lengths:l}}function st(e){const t=z.get(e);if(t)return t;const n=[];let i=0,s=0,r=0,a=0,o=null,c=null,l=-1;const u=new Set,h=d=>{l<0&&(l=0),d.subpath=l,n.push(d)};for(const{type:d,args:g}of qe(e)){const b=d.toUpperCase(),v=d!==b,k=Ve[b];if(b==="Z"){(i!==r||s!==a)&&h(Q(i,s,r,a)),l>=0&&u.add(l),i=r,s=a,o=c=null;continue}for(let M=0;M+k<=g.length;M+=k){const y=g.slice(M,M+k),S=v?i:0,w=v?s:0;let P=null,W=null;switch(b){case"M":M===0?(i=y[0]+S,s=y[1]+w,r=i,a=s,(l<0||n[n.length-1]?.subpath===l)&&l++):(h(Q(i,s,y[0]+S,y[1]+w)),i=y[0]+S,s=y[1]+w);break;case"L":h(Q(i,s,y[0]+S,y[1]+w)),i=y[0]+S,s=y[1]+w;break;case"H":h(Q(i,s,y[0]+S,s)),i=y[0]+S;break;case"V":h(Q(i,s,i,y[0]+w)),s=y[0]+w;break;case"C":{const T=[y[0]+S,y[1]+w,y[2]+S,y[3]+w,y[4]+S,y[5]+w];h(it(i,s,T)),P=[T[2],T[3]],i=T[4],s=T[5];break}case"S":{const[T,R]=o?[2*i-o[0],2*s-o[1]]:[i,s],_=[T,R,y[0]+S,y[1]+w,y[2]+S,y[3]+w];h(it(i,s,_)),P=[_[2],_[3]],i=_[4],s=_[5];break}case"Q":case"T":{let T=i,R=s;b==="Q"?(T=y[0]+S,R=y[1]+w):c&&(T=2*i-c[0],R=2*s-c[1]);const _=b==="Q"?y[2]+S:y[0]+S,C=b==="Q"?y[3]+w:y[1]+w;h(it(i,s,[i+2/3*(T-i),s+2/3*(R-s),_+2/3*(T-_),C+2/3*(R-C),_,C])),W=[T,R],i=_,s=C;break}case"A":{const T=y[5]+S,R=y[6]+w;let _=i,C=s;for(const O of We(i,s,y[0],y[1],y[2],y[3],y[4],T,R))h(it(_,C,O)),_=O[4],C=O[5];i=T,s=R;break}}o=P,c=W}}const f=n.reduce((d,g)=>d+g.length,0),m=[];for(let d=0;d<n.length;){const g=n[d].subpath;let b=d,v=0;for(;b<n.length&&n[b].subpath===g;)v+=n[b++].length;const k=n[d],M=n[b-1],y=u.has(g)||Math.abs(M.endX-k.startX)<1e-9&&Math.abs(M.endY-k.startY)<1e-9;m.push({start:d,end:b,length:v,closed:y}),d=b}const p={segments:n,totalLength:f,subpaths:m};return z.size>=Fe&&z.delete(z.keys().next().value),z.set(e,p),p}function Be(e,t){const n=e.lengths;if(t<=0)return 0;if(t>=e.length)return 1;let i=0,s=n.length-1;for(;i<s-1;){const o=i+s>>1;n[o]<t?i=o:s=o}const r=n[s]-n[i],a=r>0?(t-n[i])/r:0;return(i+a)/(n.length-1)}function Ue(e,t){if(e.type==="L"){const h=e.length>0?Math.max(0,Math.min(1,t/e.length)):0;return{x:e.startX+(e.endX-e.startX)*h,y:e.startY+(e.endY-e.startY)*h,angle:Math.atan2(e.endY-e.startY,e.endX-e.startX)*180/Math.PI}}const[n,i,s,r,a,o]=e.points,c=Be(e,t);let l=Xt(e.startX,n,s,a,c),u=Xt(e.startY,i,r,o,c);if(Math.hypot(l,u)<1e-9){const h=c<.5?Math.min(1,c+.001):Math.max(0,c-.001),f=Y(e.startX,n,s,a,h),m=Y(e.startY,i,r,o,h),p=Y(e.startX,n,s,a,c),d=Y(e.startY,i,r,o,c);l=c<.5?f-p:p-f,u=c<.5?m-d:d-m}return{x:Y(e.startX,n,s,a,c),y:Y(e.startY,i,r,o,c),angle:Math.atan2(u,l)*180/Math.PI}}function Yt(e,t,n=0,i=e.length){if(i<=n)return{x:0,y:0,angle:0};let s=0;for(let r=n;r<i;r++){const a=e[r];if(s+a.length>=t||r===i-1)return Ue(a,t-s);s+=a.length}return{x:0,y:0,angle:0}}function je(e,t){const{segments:n,totalLength:i}=st(e);return Yt(n,Math.max(0,Math.min(1,t))*i)}const He=24,ze=320,Qe=2.5,G=72,Ge=.2,Ze=128,rt=new Map;let gt=0,V;const Vt=e=>Math.round(e*100)/100;function qt(e,t){const{segments:n,subpaths:i,totalLength:s}=st(e);if(n.length===0)return[];if(t){const r=i.every(a=>a.closed);return[{segments:n,start:0,end:n.length,length:s,closed:r}]}return i.filter(r=>r.length>0).map(r=>({segments:n,start:r.start,end:r.end,length:r.length,closed:r.closed}))}function yt(e,t){const n=e.closed?(t%1+1)%1:Math.max(0,Math.min(1,t)),i=Yt(e.segments,n*e.length,e.start,e.end);return[i.x,i.y]}function Wt(e){const t=[];let n=0;for(let i=e.start;i<e.end;i++)n+=e.segments[i].length,e.length>0&&t.push(n/e.length);return t}function Bt(e,t){const n=[];for(let i=0;i<t;i++)n.push(yt(e,e.closed?i/t:i/(t-1)));return n}function Ut(e){let t=0,n=0;for(const[i,s]of e)t+=i,n+=s;return t/=e.length,n/=e.length,e.map(([i,s])=>[i-t,s-n])}function Ke(e,t,n){const i=e.closed&&t.closed;if(n!==void 0)return{offset:i?Math.abs(n)%G/G:0,reversed:n<0};const s=Ut(Bt(e,G)),r=Ut(Bt(t,G)),a=G;let o={offset:0,reversed:!1},c=1/0;for(const l of[!1,!0]){const u=i?a:1;for(let h=0;h<u;h++){let f=0;for(let m=0;m<a&&f<c;m++){const p=i?l?(h-m+a)%a:(m+h)%a:l?a-1-m:m,d=s[m][0]-r[p][0],g=s[m][1]-r[p][1];f+=d*d+g*g}f<c&&(c=f,o={offset:i?h/a:0,reversed:l})}}return o}function Je(e,t,n){return n?((t.reversed?t.offset-e:e+t.offset)%1+1)%1:t.reversed?1-e:e}function tn(e,t,n){return n?((t.reversed?t.offset-e:e-t.offset)%1+1)%1:t.reversed?1-e:e}function en(e,t,n){const i=e.closed&&t.closed,s=Ke(e,t,n.shapeIndex),r=Math.max(He,Math.min(ze,Math.ceil(Math.max(e.length,t.length)/Qe))),a=new Set,o=h=>a.add(Math.round(h*1e7)/1e7);for(let h=0;h<=r;h++)o(h/r);for(const h of Wt(e))o(h);for(const h of Wt(t))o(tn(h,s,i));let c=[...a].sort((h,f)=>h-f);i&&(c=c.filter(h=>h<1));const l=[],u=[];for(const h of c)l.push(...yt(e,h)),u.push(...yt(t,Je(h,s,i)));return nn({from:l,to:u,closed:i})}function nn(e){const t=e.from.length/2;if(t<=3)return e;const n=new Uint8Array(t);n[0]=1,n[t-1]=1;const i=[[0,t-1]];for(;i.length>0;){const[a,o]=i.pop();let c=-1,l=Ge;for(let u=a+1;u<o;u++){const h=Math.max(jt(e.from,a,o,u),jt(e.to,a,o,u));h>l&&(l=h,c=u)}c!==-1&&(n[c]=1,i.push([a,c],[c,o]))}const s=[],r=[];for(let a=0;a<t;a++)n[a]&&(s.push(e.from[a*2],e.from[a*2+1]),r.push(e.to[a*2],e.to[a*2+1]));return{from:s,to:r,closed:e.closed}}function jt(e,t,n,i){const s=e[t*2],r=e[t*2+1],a=e[n*2]-s,o=e[n*2+1]-r,c=e[i*2]-s,l=e[i*2+1]-r,u=a*a+o*o,h=u===0?0:Math.max(0,Math.min(1,(c*a+l*o)/u));return Math.hypot(c-h*a,l-h*o)}function sn(e,t,n){const i=n.shapeIndex;if(V&&V.from===e&&V.to===t&&V.shapeIndex===i)return V.plan;const r=rt.get(String(i??"auto"))?.get(e)?.get(t);if(r)return V={from:e,to:t,shapeIndex:i,plan:r},r;const a=st(e).subpaths.filter(m=>m.length>0).length===st(t).subpaths.filter(m=>m.length>0).length,o=qt(e,!a),c=qt(t,!a),l={pairs:o.map((m,p)=>en(m,c[p],n))};gt>=Ze&&(rt.clear(),gt=0);const u=String(i??"auto"),h=rt.get(u)??new Map;rt.set(u,h);const f=h.get(e)??new Map;return h.set(e,f),f.set(t,l),gt++,V={from:e,to:t,shapeIndex:i,plan:l},l}function rn(e,t,n,i={}){if(!e)return t;if(!t)return e;const s=Math.max(0,Math.min(1,n));if(s===0)return e;if(s===1)return t;const r=sn(e,t,i);if(r.pairs.length===0)return s<.5?e:t;let a="";for(const o of r.pairs){for(let c=0;c<o.from.length;c+=2){const l=Vt(o.from[c]+(o.to[c]-o.from[c])*s),u=Vt(o.from[c+1]+(o.to[c+1]-o.from[c+1])*s);a+=`${c===0?a?" M":"M":" L"}${l} ${u}`}o.closed&&(a+=" Z")}return a}function an(e){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(e)}const on=.9995;function cn(){return[0,0,0,1]}function ln(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]}function hn(e){return Math.hypot(e[0],e[1],e[2],e[3])}function Z(e){const t=hn(e);return t===0?cn():[e[0]/t,e[1]/t,e[2]/t,e[3]/t]}function un(e,t,n){const i=Z(e);let s=Z(t),r=ln(i,s);if(r<0&&(s=[-s[0],-s[1],-s[2],-s[3]],r=-r),r>on)return Z([i[0]+(s[0]-i[0])*n,i[1]+(s[1]-i[1])*n,i[2]+(s[2]-i[2])*n,i[3]+(s[3]-i[3])*n]);const a=Math.acos(r),o=Math.sin(a),c=Math.sin((1-n)*a)/o,l=Math.sin(n*a)/o;return Z([i[0]*c+s[0]*l,i[1]*c+s[1]*l,i[2]*c+s[2]*l,i[3]*c+s[3]*l])}const X=(e,t,n)=>e+(t-e)*n,Ht=512,bt=new Map,vt=new Map;function zt(e){const t=bt.get(e);if(t)return t;const n=e.replace("#",""),i=[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)];return bt.size<Ht&&bt.set(e,i),i}const Qt=e=>e.charCodeAt(0)===35,Gt=e=>e.startsWith("rgb"),Zt=e=>e.startsWith("rgba"),dn=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,kt=e=>Math.round(e).toString(16).padStart(2,"0");function fn(e,t,n){return`#${kt(e)}${kt(t)}${kt(n)}`}function Kt(e){const t=vt.get(e);if(t)return t;const n=e.match(dn);if(!n)throw new Error(`Invalid rgb color: ${e}`);const i=parseInt(n[1],10),s=parseInt(n[2],10),r=parseInt(n[3],10),a=n[4]!==void 0?[i,s,r,parseFloat(n[4])]:[i,s,r];return vt.size<Ht&&vt.set(e,a),a}const pn=(e,t,n)=>{if(Qt(e)&&Qt(t)){const[i,s,r]=zt(e),[a,o,c]=zt(t),l=X(i,a,n),u=X(s,o,n),h=X(r,c,n);return fn(l,u,h)}if((Gt(e)||Zt(e))&&(Gt(t)||Zt(t))){const i=Kt(e),s=Kt(t),r=Math.round(X(i[0],s[0],n)),a=Math.round(X(i[1],s[1],n)),o=Math.round(X(i[2],s[2],n));if(i.length===4||s.length===4){const c=i[3]??1,l=s[3]??1,u=X(c,l,n);return`rgba(${r}, ${a}, ${o}, ${u})`}return`rgb(${r}, ${a}, ${o})`}return n<1?e:t},mn=(e,t,n)=>{const i=Math.min(e.length,t.length),s=[];for(let r=0;r<i;r++)s.push(X(e[r],t[r],n));return s},gn=(e,t,n)=>un(e,t,n),Jt=(e,t,n)=>n<1?e:t,yn=(e,t,n)=>rn(e,t,n);function bn(e,t){return t==="slerp"?gn:typeof e=="number"?X:Array.isArray(e)?mn:typeof e=="string"?e.startsWith("#")||e.startsWith("rgb")?pn:an(e)?yn:Jt:Jt}function vn(e){const t=[...e.keyframes].sort((n,i)=>n.time-i.time);return{...e,keyframes:t}}function q(e){return e.targets&&e.targets.length>0?e.targets:[e.target]}function U(e,t,n,i){const s=n??0;return!i||t<=1?s:s+Pt(e,t,i)}class wt{track;targets;constructor(t){this.track=t,this.targets=q(t)}getValueAtTime(t){return this.valueForOffset(t-U(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const n=this.targets.length,i=[];for(let s=0;s<n;s++){const r=U(s,n,this.track.delay,this.track.stagger),a=this.valueForOffset(t-r);a!==void 0&&i.push({target:this.targets[s],value:a,start:r+this.track.keyframes[0].time})}return i}getDuration(){const{keyframes:t}=this.track;if(t.length===0)return 0;const n=t[t.length-1].time,i=this.track.stagger?dt(this.targets.length,this.track.stagger):0;return n+(this.track.delay??0)+i+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(t){const{keyframes:n}=this.track;if(n.length===0)return;if(n.length===1||t<=n[0].time)return n[0].value;if(t>=n[n.length-1].time)return n[n.length-1].value;const{from:i,to:s}=this.findSurroundingKeyframes(t);if(!i||!s)return;if(i.time===t)return i.value;const r=s.time-i.time,a=(t-i.time)/r,c=Ne(s.easing)(a);return bn(i.value,this.track.interpolation)(i.value,s.value,c)}findSurroundingKeyframes(t){const{keyframes:n}=this.track;for(let i=0;i<n.length-1;i++)if(t>=n[i].time&&t<=n[i+1].time)return{from:n[i],to:n[i+1]};return{from:null,to:null}}}class kn{track;targets;sampler;constructor(t){this.track=t,this.targets=q(t),this.sampler=new we(t.spring)}getValueAtTime(t){return this.sampler.valueAt(t-U(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const n=this.targets.length,i=[];for(let s=0;s<n;s++){const r=U(s,n,this.track.delay,this.track.stagger);i.push({target:this.targets[s],value:this.sampler.valueAt(t-r),start:r})}return i}getDuration(){const t=this.track.stagger?dt(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+t}getTrack(){return this.track}}class wn{track;targets;duration;constructor(t){this.track=t,this.targets=q(t),this.duration=$t(t.inertia)}getValueAtTime(t){return Lt(this.track.inertia,t-U(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const n=this.targets.length,i=[];for(let s=0;s<n;s++){const r=U(s,n,this.track.delay,this.track.stagger);i.push({target:this.targets[s],value:Lt(this.track.inertia,t-r),start:r})}return i}getDuration(){const t=this.track.stagger?dt(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+t}getTrack(){return this.track}}function xn(e,t){const n={...je(e.pathData,t)};if(e.matrix){const[i,s,r,a,o,c]=e.matrix,{x:l,y:u}=n;n.x=i*l+r*u+o,n.y=s*l+a*u+c;const h=n.angle*Math.PI/180,f=Math.cos(h),m=Math.sin(h);n.angle=Math.atan2(s*f+a*m,i*f+r*m)*180/Math.PI}return e.autoRotate&&e.rotateOffset&&(n.angle+=e.rotateOffset),n}const xt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},Mn=20;function Sn(e){const t=xt[e??"upperCase"]??e??xt.upperCase,n=Array.from(t);return n.length>0?n:Array.from(xt.upperCase)}function Tn(e,t,n){let i=(e|0)^Math.imul(t+1,2654435761)^Math.imul(n+1,2246822507);return i=Math.imul(i^i>>>16,2146121005),i=Math.imul(i^i>>>15,2221713035),(i^i>>>16)>>>0}function _n(e,t,n=0){const i=e.from??"",s=e.to,r=Math.max(0,Math.min(1,t));if(r<=0)return i;if(r>=1)return s;const a=Array.from(i),o=Array.from(s),c=e.rightToLeft??!1;if(e.mode==="type"){const v=Math.round(r*Math.max(a.length,o.length));return c?a.slice(0,Math.max(0,a.length-v)).join("")+o.slice(Math.max(0,o.length-v)).join(""):o.slice(0,v).join("")+a.slice(v).join("")}const l=Math.max(0,Math.min(.999,e.revealDelay??0)),u=Math.max(0,(r-l)/(1-l)),h=Math.floor(u*o.length),f=e.tweenLength===!1?o.length:Math.round(a.length+(o.length-a.length)*r),m=Sn(e.chars),p=e.refreshRate??Mn,d=p>0?Math.floor(n*p/1e3):0,g=e.seed??1;let b="";for(let v=0;v<f;v++){const k=c?v>=f-h:v<h,M=c?o[o.length-(f-v)]:o[v];k&&M!==void 0||M===" "||M===`
|
|
2
|
-
`?b+=M:b+=m[Tn(g,v,d)%m.length]}return b}class An{id;name;_captions;_tracks=[];_trackPlayers=new Map;_motionPathTracks=new Map;_springTracks=new Map;_textTracks=new Map;_config;_currentTime=0;_playbackState="idle";_direction="forward";_loopIteration=0;_explicitDuration;_repeatDelayRemaining=0;_wrapAfterDelay=!1;onUpdate=null;onComplete=null;constructor(t){if(this.id=t.id,this.name=t.name,this._captions=t.captions,this._config=t.config??{},this._explicitDuration=t.config?.duration,t.tracks)for(const n of t.tracks)this.addTrack(n)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(t){if(this._explicitDuration=t,t!==void 0)this._config={...this._config,duration:t};else if(this._config.duration!==void 0){const n={...this._config};delete n.duration,this._config=n}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(t){this._config.speed=t}get drawingRate(){return this._config.drawingRate??0}set drawingRate(t){const n={...this._config};t>0?n.drawingRate=t:delete n.drawingRate,this._config=n}play(){const t=this.duration;this._direction==="forward"&&this._currentTime>=t&&t>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&t>0&&(this._currentTime=t,this._loopIteration=0),this._playbackState="playing"}pause(){this._playbackState="paused"}stop(){this._playbackState="idle",this._repeatDelayRemaining=0,this._wrapAfterDelay=!1,this._currentTime=0,this._loopIteration=0,this._direction="forward"}seek(t){const n=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(t,n)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(t){if(this._playbackState!=="playing")return;const n=this.duration;if(n<=0)return;let s=t*this.speed;if(this._repeatDelayRemaining>0){const o=Math.min(this._repeatDelayRemaining,s);if(this._repeatDelayRemaining-=o,s-=o,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const r=1e3;for(let o=0;o<r&&s>0&&this._playbackState==="playing";o++)if(this._direction==="forward"){const c=n-this._currentTime;if(s>=c){if(s-=c,this._currentTime=n,!this._handleEndReached())break}else this._currentTime+=s,s=0}else{const c=this._currentTime;if(s>=c){if(s-=c,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=s,s=0}const a=this.getStateAtTime(this._currentTime);this.onUpdate?.(a)}getStateAtTime(t){const n=new Map;if(t=be(t,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(t,n);else for(const[i,s]of this._trackPlayers){const r=s.getTrack().property;for(const{target:a,value:o,start:c}of s.getTargetValues(t))this._write(n,i,a,r,o,t-c)}return{values:n,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(t,n){const i=new Map;for(const[s,r]of this._trackPlayers){const a=r.getTrack().property;for(const{target:o,value:c,start:l}of r.getTargetValues(t)){const u=`${o}\0${a}`,h=l<=t,f=i.get(u);(!f||(h!==f.started?h:h?l>=f.start:l<=f.start))&&i.set(u,{trackId:s,target:o,property:a,value:c,start:l,started:h})}}for(const{trackId:s,target:r,property:a,value:o,start:c}of i.values())this._write(n,s,r,a,o,t-c)}_write(t,n,i,s,r,a){if(r===void 0)return;let o=t.get(i);o||(o=new Map,t.set(i,o));const c=this._textTracks.get(n);if(c&&typeof r=="number"){o.set("text",_n(c.textConfig,r,Math.max(0,a)));return}const l=this._motionPathTracks.get(n);if(l&&typeof r=="number"){const u=xn(l.motionPathConfig,r);o.set("motionPathX",u.x),o.set("motionPathY",u.y),l.motionPathConfig.autoRotate&&o.set("motionPathRotate",u.angle)}else o.set(s,r)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const t=new Set;this._sharedWrites=!1;t:for(const n of this._tracks)for(const i of q(n)){const s=`${i}\0${n.property}`;if(t.has(s)){this._sharedWrites=!0;break t}t.add(s)}}return this._sharedWrites}addTrack(t){if(this._tracks.push(t),this._sharedWrites=null,ht(t)){this._trackPlayers.set(t.id,new wn(t));return}if(ut(t)){this._trackPlayers.set(t.id,new kn(t)),this._springTracks.set(t.id,t);return}if(At(t))this._trackPlayers.set(t.id,new wt(t)),this._textTracks.set(t.id,t);else if(ye(t)){const n={id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,delay:t.delay,endDelay:t.endDelay,targets:t.targets,stagger:t.stagger};this._trackPlayers.set(t.id,new wt(n)),this._motionPathTracks.set(t.id,t)}else this._trackPlayers.set(t.id,new wt(t))}replaceTrack(t,n){const i=this._tracks.findIndex(r=>r.id===t);if(i<0)return;const s=this._tracks.slice(i+1);this.removeTrack(t);for(const r of s)this.removeTrack(r.id);this.addTrack(n);for(const r of s)this.addTrack(r)}removeTrack(t){this._tracks=this._tracks.filter(n=>n.id!==t),this._sharedWrites=null,this._trackPlayers.delete(t),this._motionPathTracks.delete(t),this._springTracks.delete(t),this._textTracks.delete(t)}getTracks(t={}){return this._tracks.filter(n=>this._matches(n,t))}removeTracks(t={}){const n=this.getTracks(t).map(i=>i.id);for(const i of n)this.removeTrack(i);return n}getTrackSpan(t){const n=this._trackPlayers.get(t);if(!n)return;const i=n.getTrack(),s=i.delay??0;if(ut(i)||ht(i))return{from:s,to:n.getDuration()};const r=i.keyframes;if(!(!r||r.length===0))return{from:r[0].time+s,to:n.getDuration()}}findConflicts(){const t=[];for(let n=0;n<this._tracks.length;n++){const i=this._tracks[n],s=this.getTrackSpan(i.id);if(s)for(let r=0;r<n;r++){const a=this._tracks[r];if(a.property!==i.property)continue;const o=q(a).filter(h=>q(i).includes(h));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=s.to&&s.from<=c.to))continue;const u=s.from>=c.from;for(const h of o)t.push({target:h,property:i.property,losingTrackId:u?a.id:i.id,winningTrackId:u?i.id:a.id})}}return t}_matches(t,n){if(n.id!==void 0&&t.id!==n.id||n.property!==void 0&&t.property!==n.property||n.target!==void 0&&!q(t).includes(n.target))return!1;if(n.timeRange){const i=this.getTrackSpan(t.id);if(!i||i.to<n.timeRange.from||i.from>n.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:ge(this._tracks),id:this.id,name:this.name,config:{...this._config},tracks:[...this._tracks],...this.captions&&{captions:this.captions}}}get config(){return this._config}get markers(){return[...this._config.markers??[]].sort((t,n)=>t.time-n.time)}setMarkers(t){const n=t&&t.length>0?[...t].sort((s,r)=>s.time-r.time).map(s=>({...s})):void 0,i={...this._config};n?i.markers=n:delete i.markers,this._config=i}get captions(){return this._captions}setCaptions(t){const n={};for(const[i,s]of Object.entries(t??{}))n[i]={...s};this._captions=Object.keys(n).length>0?n:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let t=0;for(const[,n]of this._trackPlayers)t=Math.max(t,n.getDuration());return t}_handleEndReached(){const t=this._config.loop??0;return t===-1||this._loopIteration<t?(this._loopIteration++,this._armRepeatDelay(),this._config.alternate?this._direction="reverse":this._repeatDelayRemaining>0?this._wrapAfterDelay=!0:this._currentTime=0,this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}_handleStartReached(){const t=this._config.loop??0;return this._config.alternate&&(t===-1||this._loopIteration<t)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const En=100;function Pn(e,t,n,i){const s=[],r=[],{duration:a,alternate:o}=i,c=(m,p,d,g)=>{r.push([m,p]);const b=[];e.forEach((v,k)=>{(d==="forward"?(g?v>=m:v>m)&&v<=p:(g?v<=m:v<m)&&v>=p)&&b.push(k)}),b.sort((v,k)=>(d==="forward"?e[v]-e[k]:e[k]-e[v])||v-k);for(const v of b)s.push({kind:"event",index:v,direction:d})};let l=t.time,u=t.direction,h=t.fresh===!0;const f=Math.min(En,Math.max(0,n.iteration-t.iteration));for(let m=0;m<f;m++){const p=u==="forward"?a:0;c(l,p,u,h),s.push({kind:"repeat"}),o?(u=u==="forward"?"reverse":"forward",l=p,h=!1):(l=u==="forward"?0:a,h=!0)}return f>0&&i.holding&&!o?{crossings:s,passes:r}:(c(l,n.time,u,h),{crossings:s,passes:r})}function Cn(e){return{...e,...Array.isArray(e.end)&&{end:[...e.end]}}}function K(e){const t=e.endDelay;return{...e.delay!==void 0&&{delay:e.delay},...t!==void 0&&{endDelay:t},...e.targets!==void 0&&{targets:[...e.targets]},...e.stagger!==void 0&&{stagger:{...e.stagger}}}}function In(e){if(ht(e)){const t=e;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:Cn(t.inertia),...K(t)}}if(ut(e)){const t=e;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...K(t)}}if(At(e)){const t=e;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((n,i)=>n.time-i.time),...K(t)}}if(e.property==="motionPath"&&"motionPathConfig"in e){const t=e,n=[...t.keyframes].sort((i,s)=>i.time-s.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:n,...K(t)}}return vn({id:e.id,target:e.target,property:e.property,keyframes:e.keyframes,...e.interpolation!==void 0&&{interpolation:e.interpolation},...K(e)})}function at(e){const t=e.formatVersion??1;if(t>et)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${et}. Update tinyfly to play it.`);return new An({id:e.id,name:e.name,config:e.config,tracks:e.tracks.map(In),captions:e.captions})}function Rn(e){const[t,n,i,s]=e;return[1-2*(n*n+i*i),2*(t*n+i*s),2*(t*i-n*s),0,2*(t*n-i*s),1-2*(t*t+i*i),2*(n*i+t*s),0,2*(t*i+n*s),2*(n*i-t*s),1-2*(t*t+n*n),0,0,0,0,1]}function $n(e){return!Array.isArray(e)||e.length!==4?null:`matrix3d(${Rn(Z(e)).map(n=>Math.round(n*1e6)/1e6+0).join(", ")})`}const Ln=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),Dn="#ffffff",On="rgba(0, 0, 0, 0.5)";function Nn(e){const t=[];if(e.blur!==void 0&&t.push(`blur(${Math.max(0,e.blur)}px)`),e.brightness!==void 0&&t.push(`brightness(${Math.max(0,e.brightness)})`),e.glow!==void 0&&t.push(`drop-shadow(0 0 ${Math.max(0,e.glow)}px ${e.glowColor??Dn})`),e.shadowX!==void 0||e.shadowY!==void 0||e.shadowBlur!==void 0){const n=e.shadowX??0,i=e.shadowY??0,s=Math.max(0,e.shadowBlur??0);t.push(`drop-shadow(${n}px ${i}px ${s}px ${e.shadowColor??On})`)}return t.length>0?t.join(" "):null}function Fn(e,t){const n=e.childNodes.length===1?e.firstChild:null;if(n&&n.nodeType===3){const i=n;i.data!==t&&(i.data=t);return}e.textContent!==t&&(e.textContent=t)}function Xn(e){if(!("ownerSVGElement"in e))return;const t=e.style;!t||t.transformBox||(t.transformBox="fill-box",t.transformOrigin||(t.transformOrigin="50% 50%"))}const te=new Set(["width","height","top","right","bottom","left","margin","marginTop","marginRight","marginBottom","marginLeft","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","borderRadius","borderWidth","fontSize","lineHeight","letterSpacing","outlineWidth","gap","rowGap","columnGap"]),Yn=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),Vn=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],qn=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),Wn=new Set(["originX","originY"]),Bn=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Un=new Set(["drawOn"]),jn={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},ee={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},Hn="http://www.w3.org/2000/svg";class Mt{targets=new Map;registerTarget(t,n){this.targets.set(t,n)}unregisterTarget(t){this.targets.delete(t)}getTarget(t){return this.targets.get(t)}clearTargets(){this.targets.clear()}applyState(t){for(const[n,i]of t.values){const s=this.targets.get(n);s&&this.applyProperties(s,i)}}applyProperties(t,n){let i=null,s=null,r=null,a=null,o=null;const c=n.has("motionPathX"),l=n.has("motionPathY"),u=n.has("motionPathRotate");for(const[p,d]of n)if(!(p==="x"&&c)&&!(p==="y"&&l)&&!((p==="rotate"||p==="rotateZ")&&u)&&!Un.has(p)){if(Yn.has(p))(i??={})[p]=d;else if(qn.has(p))typeof d=="number"&&((s??={})[p]=d);else if(Wn.has(p))typeof d=="number"&&((r??={})[p]=d);else if(Bn.has(p))typeof d=="number"&&((a??={})[p]=d);else if(Ln.has(p))(o??={})[p]=d;else if(p!=="perspective"){if(p!=="shine")if(p==="text"&&typeof d=="string")Fn(t,d);else if(p==="d"&&typeof d=="string"){const g=t;(g.tagName?.toLowerCase()==="path"?g:g.querySelector?.("path"))?.setAttribute?.("d",d)}else this.applyStyleProperty(t,p,d)}}const h=n.get("shine");typeof h=="number"&&this.applyShine(t,h);const f=[],m=n.get("perspective");if(typeof m=="number"&&m>0&&f.push(`perspective(${m}px)`),i)for(const p of Vn){const d=i[p];if(d===void 0)continue;const g=this.buildTransformPart(p,d);g&&f.push(g)}if(f.length>0&&(t.style.transform=f.join(" "),Xn(t)),s&&(s.childPerspective!==void 0&&(t.style.perspective=`${s.childPerspective}px`),(s.perspectiveOriginX!==void 0||s.perspectiveOriginY!==void 0)&&(t.style.perspectiveOrigin=`${s.perspectiveOriginX??50}% ${s.perspectiveOriginY??50}%`)),r){const p=r.originX??50,d=r.originY??50;t.style.transformOrigin=`${p}% ${d}%`}if(a){const p=a.clipTop??0,d=a.clipRight??0,g=a.clipBottom??0,b=a.clipLeft??0;t.style.clipPath=`inset(${p}% ${d}% ${g}% ${b}%)`}if(o){const p=Nn(o);p&&(t.style.filter=p)}}buildTransformPart(t,n){if(t==="quaternion")return $n(n);if(typeof n!="number")return null;switch(t){case"x":case"motionPathX":return`translateX(${n}px)`;case"y":case"motionPathY":return`translateY(${n}px)`;case"z":return`translateZ(${n}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${n}deg)`;case"rotateX":return`rotateX(${n}deg)`;case"rotateY":return`rotateY(${n}deg)`;case"scale":return`scale(${n})`;case"scaleX":return`scaleX(${n})`;case"scaleY":return`scaleY(${n})`;case"scaleZ":return`scaleZ(${n})`;case"skewX":return`skewX(${n}deg)`;case"skewY":return`skewY(${n}deg)`;default:return null}}applyShine(t,n){t.dataset.shineBase||(t.dataset.shineBase=t.style.color||"currentColor");const i=t.dataset.shineBase,s=-20+n*140,r=t.style;r.color="transparent",r.backgroundImage=`linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${i}, ${i})`,r.backgroundSize="250% 100%, 100% 100%",r.backgroundPosition=`${s}% 0, 0 0`,r.backgroundRepeat="no-repeat",r.webkitBackgroundClip="text",r.backgroundClip="text"}applyStyleProperty(t,n,i){let s;if(t.namespaceURI===Hn&&n in ee){const o=Array.isArray(i)?i.join(", "):String(i);t.style[ee[n]]=o;return}else n==="fill"&&t.dataset?.elementType==="text"?s="color":s=jn[n]??n;let a;typeof i=="number"?te.has(n)||te.has(s)?a=`${i}px`:a=String(i):Array.isArray(i)?a=i.join(", "):a=i,t.style[s]=a}}class ne{media;offset;driftTolerance;constructor(t,n={}){this.media=t,this.offset=n.offset??0,this.driftTolerance=Math.max(0,n.driftTolerance??.15)}targetTime(t){return Math.max(0,t/1e3+this.offset)}update(t,n){const i=this.targetTime(t);n?(this.media.paused&&this.safePlay(),Math.abs(this.media.currentTime-i)>this.driftTolerance&&(this.media.currentTime=i)):(this.media.paused||this.media.pause(),this.media.currentTime!==i&&(this.media.currentTime=i))}seek(t){this.media.currentTime=this.targetTime(t)}setRate(t){this.media.playbackRate=t}dispose(){this.media.paused||this.media.pause()}safePlay(){const t=this.media.play();t&&typeof t.catch=="function"&&t.catch(()=>{})}}function zn(e,t,n,i,s){const r=n-s;if(r<0){t.paused||t.pause(),t.currentTime=0;return}e.update(r,i)}class ot{container;timeline=null;adapter;animationFrameId;lastTime;options;targets={};isDestroyed=!1;mediaSync;mediaTargets=[];symbolInstances=[];scenarioList=[];scenarioId;authored=new Map;markerList=[];listeners=new Set;playhead={time:0,iteration:0,direction:"forward"};stepping=!1;lastMarkerId=null;reducedQuery;onReducedChange=()=>this.applyReducedMotion();visibilityObserver;onScreen=!0;pausedByVisibility=!1;autoplayWhenSeen=!1;onDocumentVisibility=()=>this.updateVisibility();constructor(t,n={}){if(typeof t=="string"){const i=document.querySelector(t);if(!i)throw new Error(`Container not found: ${t}`);this.container=i}else this.container=t;this.options=n,this.adapter=new Mt}async load(t){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(t)}async loadSource(t){let n;if(typeof t=="string"){const i=await fetch(t);if(!i.ok)throw new Error(`Failed to load animation: ${i.statusText}`);n=await i.json()}else n=t;this.useDefinition(n),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(t){const n={...t.config};this.options.speed!==void 0&&(n.speed=this.options.speed),this.options.loop!==void 0&&(n.loop=this.options.loop),this.options.alternate!==void 0&&(n.alternate=this.options.alternate),this.timeline=at({...t,config:n}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(t,n={}){if(t.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const i=new Set;for(const r of t){if(i.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);i.add(r.id)}const s=n.initial===void 0?t[0]:t.find(r=>r.id===n.initial);if(!s)throw new Error(`tinyfly: there is no scenario "${n.initial}"`);this.scenarioList=[...t],this.scenarioId=s.id,await this.loadSource(s.timeline)}get scenarios(){return this.scenarioList.map(t=>({id:t.id,label:t.label??t.id}))}get scenario(){return this.scenarioId}setScenario(t){const n=this.scenarioList.find(o=>o.id===t);if(!n||!this.timeline)return!1;if(t===this.scenarioId)return!0;const i=this.isPlaying,s=this.currentTime>=this.duration-.5,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=t,this.useDefinition(n.timeline),this.lastMarkerId=null;let a=0;return this.reducedMotion||s?a=this.duration:r!==void 0&&(a=this.markers.find(o=>o.id===r)?.time??0),this.seek(a),i&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(t){if(this.authored.has(t))return;const n={style:t.getAttribute("style")};t.children.length===0&&(n.text=t.textContent??"");const i=t.tagName.toLowerCase()==="path"?t:t.querySelector("path");i&&(n.path={element:i,d:i.getAttribute("d")}),this.authored.set(t,n)}restoreAuthored(){for(const[t,n]of this.authored){n.style===null?t.removeAttribute("style"):t.setAttribute("style",n.style),n.text!==void 0&&t.textContent!==n.text&&(t.textContent=n.text),n.path&&(n.path.d===null?n.path.element.removeAttribute("d"):n.path.element.setAttribute("d",n.path.d));const i=t.dataset;i&&delete i.shineBase}}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notify(){for(const t of this.listeners)t()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const t=this.currentTime;let n;for(const i of this.markers)if(i.time<=t+.5)n=i;else break;return n}caption(t,n){const i=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!i)return;const s=n??this.language(),r=a=>a?.[s]?.[i.id]??a?.[s.split("-")[0]]?.[i.id];return r(this.options.captions)??r(this.timeline?.captions)??i.label}next(){if(!this.timeline)return;const t=this.currentTime,n=this.markers.find(i=>i.time>t+.5);if(this.reducedMotion){this.seek(n?n.time:this.duration);return}t>=this.duration-.5||(this.stepping=n!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const t=this.currentTime,n=[...this.markers].reverse().find(i=>i.time<t-.5);this.pause(),this.seek(n?n.time:0)}goToMarker(t){const n=this.markers.find(i=>i.id===t);n&&(this.pause(),this.seek(n.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const t=this.options.initialFrame??"start";if(t==="none")return;const n=t==="end"?this.timeline.duration:t==="start"?0:t;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,n))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(n=>{for(const i of n)this.onScreen=i.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const t=this.container.getBoundingClientRect?.();t&&(t.width>0||t.height>0)&&(this.onScreen=t.bottom>0&&t.top<window.innerHeight&&t.right>0&&t.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const t=this.onScreen&&document.visibilityState!=="hidden";!t&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):t&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const t=this.currentMarker,n=t?.id;n!==this.lastMarkerId&&(this.lastMarkerId=n,this.options.onMarker(t))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(n=>{const i=n,s=Number(i.getAttribute("data-tinyfly-start")??"0")||0,r=i.getAttribute("data-volume");r!==null&&(i.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:i,startTime:s,sync:new ne(i)})})}syncAllMedia(t,n){for(const i of this.mediaTargets)zn(i.sync,i.el,t,n,i.startTime)}loadFromString(t){const n=JSON.parse(t);this.load(n)}registerTarget(t,n){if(typeof n=="string"){const i=this.container.querySelector(n);i&&(this.rememberAuthored(i),this.targets[t]=i,this.adapter.registerTarget(t,i))}else this.rememberAuthored(n),this.targets[t]=n,this.adapter.registerTarget(t,n)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(n=>{const i=n.closest("[data-tinyfly-symbol]");if(i&&i!==n)return;const s=n.getAttribute("data-tinyfly");s&&this.registerTarget(s,n)}),this.timeline&&new Set(this.timeline.tracks.map(i=>i.target)).forEach(i=>{if(!this.targets[i]){const s=this.container.querySelector(`[data-tinyfly="${i}"]`)||this.container.querySelector(`.${i}`)||this.container.querySelector(`#${i}`);s&&this.registerTarget(i,s)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const n=new Map(t.map(i=>[i.id,i]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(i=>{const s=i.getAttribute("data-tinyfly-symbol");if(!s)return;const r=n.get(s);if(!r||!r.timeline.tracks?.length)return;const a=new Mt;i.querySelectorAll("[data-tinyfly]").forEach(o=>{const c=o.getAttribute("data-tinyfly");c&&a.registerTarget(c,o)}),this.symbolInstances.push({adapter:a,timeline:at(r.timeline)})})}attachMedia(t,n){this.mediaSync=new ne(t,n),this.timeline&&(this.mediaSync.setRate(this.timeline.speed),this.mediaSync.update(this.timeline.currentTime,this.isPlaying))}detachMedia(){this.mediaSync?.dispose(),this.mediaSync=void 0}play(){!this.timeline||this.isDestroyed||(this.autoplayWhenSeen=!1,this.stepping=this.options.stepMode===!0,this.startPlaying())}startPlaying(){if(!this.timeline||this.isDestroyed)return;const t=this.timeline.playbackState==="idle";this.timeline.play(),t&&this.timeline.currentTime===0&&this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.update(this.timeline.currentTime,!0),this.syncAllMedia(this.timeline.currentTime,!0),this.startAnimationLoop(),this.notify()}pause(){this.timeline&&(this.stepping=!1,this.timeline.pause(),this.notify(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1),this.stopAnimationLoop())}stop(){this.timeline&&(this.timeline.stop(),this.stopAnimationLoop(),this.applyState(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1))}seek(t){this.timeline&&(this.timeline.seek(t),this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.seek(this.timeline.currentTime),this.syncAllMedia(this.timeline.currentTime,this.isPlaying))}setSpeed(t){this.timeline&&(this.timeline.speed=t,this.mediaSync?.setRate(t))}reverse(){this.timeline&&this.timeline.reverse()}get currentTime(){return this.timeline?.currentTime??0}get duration(){return this.timeline?.duration??0}get isPlaying(){return this.timeline?.playbackState==="playing"}destroy(){this.isDestroyed=!0,this.stopAnimationLoop(),this.reducedQuery?.removeEventListener?.("change",this.onReducedChange),this.visibilityObserver?.disconnect(),typeof document<"u"&&document.removeEventListener("visibilitychange",this.onDocumentVisibility),this.mediaSync?.dispose(),this.mediaSync=void 0;for(const t of this.mediaTargets)t.el.paused||t.el.pause();this.mediaTargets=[],this.adapter.clearTargets();for(const t of this.symbolInstances)t.adapter.clearTargets();this.symbolInstances=[],this.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=n=>{if(this.isDestroyed||!this.timeline)return;const i=n-(this.lastTime??n);this.lastTime=n;const s=this.playhead;this.timeline.tick(i),this.stopAtMarker(s),this.applyState();const r=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,r),this.syncAllMedia(this.timeline.currentTime,r),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(t):(this.animationFrameId=void 0,this.notify())};this.animationFrameId=requestAnimationFrame(t)}stopAtMarker(t){const n=this.timeline,i={time:n.currentTime,iteration:n.loopIteration,direction:n.direction};this.playhead=i;const s=this.markers;if(s.length===0)return;const{crossings:r}=Pn(s.map(a=>a.time),t,i,{duration:n.duration,alternate:n.config.alternate===!0,holding:n.repeatDelayRemaining>0});for(const a of r){if(a.kind!=="event")continue;const o=s[a.index];if(this.stepping||o.pause){this.stepping=!1,n.pause(),n.seek(o.time),this.playhead={time:o.time,iteration:n.loopIteration,direction:n.direction};return}}}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}applyState(){if(!this.timeline)return;const t=this.timeline.currentTime;this.adapter.applyState(this.timeline.getStateAtTime(t)),this.announceMarker(),this.notify();for(const n of this.symbolInstances){const i=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(i>0?t%i:t))}}}async function Qn(e,t,n={}){const i=new ot(e,{...n,autoplay:!0});return await i.load(t),i}function Gn(e,t={}){return new ot(e,t)}const ie={play:"Play",pause:"Pause",prev:"Previous step",next:"Next step",restart:"Restart",scrub:"Position",speed:"Speed",reveal:"Reveal",step:"Step",of:"of",stepFormat:"{index} / {total}",scenario:"Scenario",fullscreen:"Full screen",exitFullscreen:"Exit full screen"},se="tinyfly-controls-style",Zn=`
|
|
2
|
+
`?b+=M:b+=m[Tn(g,v,d)%m.length]}return b}class An{id;name;_captions;_tracks=[];_trackPlayers=new Map;_motionPathTracks=new Map;_springTracks=new Map;_textTracks=new Map;_config;_currentTime=0;_playbackState="idle";_direction="forward";_loopIteration=0;_explicitDuration;_repeatDelayRemaining=0;_wrapAfterDelay=!1;onUpdate=null;onComplete=null;constructor(t){if(this.id=t.id,this.name=t.name,this._captions=t.captions,this._config=t.config??{},this._explicitDuration=t.config?.duration,t.tracks)for(const n of t.tracks)this.addTrack(n)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(t){if(this._explicitDuration=t,t!==void 0)this._config={...this._config,duration:t};else if(this._config.duration!==void 0){const n={...this._config};delete n.duration,this._config=n}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(t){this._config.speed=t}get drawingRate(){return this._config.drawingRate??0}set drawingRate(t){const n={...this._config};t>0?n.drawingRate=t:delete n.drawingRate,this._config=n}play(){const t=this.duration;this._direction==="forward"&&this._currentTime>=t&&t>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&t>0&&(this._currentTime=t,this._loopIteration=0),this._playbackState="playing"}pause(){this._playbackState="paused"}stop(){this._playbackState="idle",this._repeatDelayRemaining=0,this._wrapAfterDelay=!1,this._currentTime=0,this._loopIteration=0,this._direction="forward"}seek(t){const n=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(t,n)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(t){if(this._playbackState!=="playing")return;const n=this.duration;if(n<=0)return;let s=t*this.speed;if(this._repeatDelayRemaining>0){const o=Math.min(this._repeatDelayRemaining,s);if(this._repeatDelayRemaining-=o,s-=o,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const r=1e3;for(let o=0;o<r&&s>0&&this._playbackState==="playing";o++)if(this._direction==="forward"){const c=n-this._currentTime;if(s>=c){if(s-=c,this._currentTime=n,!this._handleEndReached())break}else this._currentTime+=s,s=0}else{const c=this._currentTime;if(s>=c){if(s-=c,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=s,s=0}const a=this.getStateAtTime(this._currentTime);this.onUpdate?.(a)}getStateAtTime(t){const n=new Map;if(t=be(t,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(t,n);else for(const[i,s]of this._trackPlayers){const r=s.getTrack().property;for(const{target:a,value:o,start:c}of s.getTargetValues(t))this._write(n,i,a,r,o,t-c)}return{values:n,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(t,n){const i=new Map;for(const[s,r]of this._trackPlayers){const a=r.getTrack().property;for(const{target:o,value:c,start:l}of r.getTargetValues(t)){const u=`${o}\0${a}`,h=l<=t,f=i.get(u);(!f||(h!==f.started?h:h?l>=f.start:l<=f.start))&&i.set(u,{trackId:s,target:o,property:a,value:c,start:l,started:h})}}for(const{trackId:s,target:r,property:a,value:o,start:c}of i.values())this._write(n,s,r,a,o,t-c)}_write(t,n,i,s,r,a){if(r===void 0)return;let o=t.get(i);o||(o=new Map,t.set(i,o));const c=this._textTracks.get(n);if(c&&typeof r=="number"){o.set("text",_n(c.textConfig,r,Math.max(0,a)));return}const l=this._motionPathTracks.get(n);if(l&&typeof r=="number"){const u=xn(l.motionPathConfig,r);o.set("motionPathX",u.x),o.set("motionPathY",u.y),l.motionPathConfig.autoRotate&&o.set("motionPathRotate",u.angle)}else o.set(s,r)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const t=new Set;this._sharedWrites=!1;t:for(const n of this._tracks)for(const i of q(n)){const s=`${i}\0${n.property}`;if(t.has(s)){this._sharedWrites=!0;break t}t.add(s)}}return this._sharedWrites}addTrack(t){if(this._tracks.push(t),this._sharedWrites=null,ht(t)){this._trackPlayers.set(t.id,new wn(t));return}if(ut(t)){this._trackPlayers.set(t.id,new kn(t)),this._springTracks.set(t.id,t);return}if(At(t))this._trackPlayers.set(t.id,new wt(t)),this._textTracks.set(t.id,t);else if(ye(t)){const n={id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,delay:t.delay,endDelay:t.endDelay,targets:t.targets,stagger:t.stagger};this._trackPlayers.set(t.id,new wt(n)),this._motionPathTracks.set(t.id,t)}else this._trackPlayers.set(t.id,new wt(t))}replaceTrack(t,n){const i=this._tracks.findIndex(r=>r.id===t);if(i<0)return;const s=this._tracks.slice(i+1);this.removeTrack(t);for(const r of s)this.removeTrack(r.id);this.addTrack(n);for(const r of s)this.addTrack(r)}removeTrack(t){this._tracks=this._tracks.filter(n=>n.id!==t),this._sharedWrites=null,this._trackPlayers.delete(t),this._motionPathTracks.delete(t),this._springTracks.delete(t),this._textTracks.delete(t)}getTracks(t={}){return this._tracks.filter(n=>this._matches(n,t))}removeTracks(t={}){const n=this.getTracks(t).map(i=>i.id);for(const i of n)this.removeTrack(i);return n}getTrackSpan(t){const n=this._trackPlayers.get(t);if(!n)return;const i=n.getTrack(),s=i.delay??0;if(ut(i)||ht(i))return{from:s,to:n.getDuration()};const r=i.keyframes;if(!(!r||r.length===0))return{from:r[0].time+s,to:n.getDuration()}}findConflicts(){const t=[];for(let n=0;n<this._tracks.length;n++){const i=this._tracks[n],s=this.getTrackSpan(i.id);if(s)for(let r=0;r<n;r++){const a=this._tracks[r];if(a.property!==i.property)continue;const o=q(a).filter(h=>q(i).includes(h));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=s.to&&s.from<=c.to))continue;const u=s.from>=c.from;for(const h of o)t.push({target:h,property:i.property,losingTrackId:u?a.id:i.id,winningTrackId:u?i.id:a.id})}}return t}_matches(t,n){if(n.id!==void 0&&t.id!==n.id||n.property!==void 0&&t.property!==n.property||n.target!==void 0&&!q(t).includes(n.target))return!1;if(n.timeRange){const i=this.getTrackSpan(t.id);if(!i||i.to<n.timeRange.from||i.from>n.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:ge(this._tracks),id:this.id,name:this.name,config:{...this._config},tracks:[...this._tracks],...this.captions&&{captions:this.captions}}}get config(){return this._config}get markers(){return[...this._config.markers??[]].sort((t,n)=>t.time-n.time)}setMarkers(t){const n=t&&t.length>0?[...t].sort((s,r)=>s.time-r.time).map(s=>({...s})):void 0,i={...this._config};n?i.markers=n:delete i.markers,this._config=i}get captions(){return this._captions}setCaptions(t){const n={};for(const[i,s]of Object.entries(t??{}))n[i]={...s};this._captions=Object.keys(n).length>0?n:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let t=0;for(const[,n]of this._trackPlayers)t=Math.max(t,n.getDuration());return t}_handleEndReached(){const t=this._config.loop??0;return t===-1||this._loopIteration<t?(this._loopIteration++,this._armRepeatDelay(),this._config.alternate?this._direction="reverse":this._repeatDelayRemaining>0?this._wrapAfterDelay=!0:this._currentTime=0,this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}_handleStartReached(){const t=this._config.loop??0;return this._config.alternate&&(t===-1||this._loopIteration<t)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const En=100;function Pn(e,t,n,i){const s=[],r=[],{duration:a,alternate:o}=i,c=(m,p,d,g)=>{r.push([m,p]);const b=[];e.forEach((v,k)=>{(d==="forward"?(g?v>=m:v>m)&&v<=p:(g?v<=m:v<m)&&v>=p)&&b.push(k)}),b.sort((v,k)=>(d==="forward"?e[v]-e[k]:e[k]-e[v])||v-k);for(const v of b)s.push({kind:"event",index:v,direction:d})};let l=t.time,u=t.direction,h=t.fresh===!0;const f=Math.min(En,Math.max(0,n.iteration-t.iteration));for(let m=0;m<f;m++){const p=u==="forward"?a:0;c(l,p,u,h),s.push({kind:"repeat"}),o?(u=u==="forward"?"reverse":"forward",l=p,h=!1):(l=u==="forward"?0:a,h=!0)}return f>0&&i.holding&&!o?{crossings:s,passes:r}:(c(l,n.time,u,h),{crossings:s,passes:r})}function Cn(e){return{...e,...Array.isArray(e.end)&&{end:[...e.end]}}}function K(e){const t=e.endDelay;return{...e.delay!==void 0&&{delay:e.delay},...t!==void 0&&{endDelay:t},...e.targets!==void 0&&{targets:[...e.targets]},...e.stagger!==void 0&&{stagger:{...e.stagger}}}}function In(e){if(ht(e)){const t=e;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:Cn(t.inertia),...K(t)}}if(ut(e)){const t=e;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...K(t)}}if(At(e)){const t=e;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((n,i)=>n.time-i.time),...K(t)}}if(e.property==="motionPath"&&"motionPathConfig"in e){const t=e,n=[...t.keyframes].sort((i,s)=>i.time-s.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:n,...K(t)}}return vn({id:e.id,target:e.target,property:e.property,keyframes:e.keyframes,...e.interpolation!==void 0&&{interpolation:e.interpolation},...K(e)})}function at(e){const t=e.formatVersion??1;if(t>et)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${et}. Update tinyfly to play it.`);return new An({id:e.id,name:e.name,config:e.config,tracks:e.tracks.map(In),captions:e.captions})}function Rn(e){const[t,n,i,s]=e;return[1-2*(n*n+i*i),2*(t*n+i*s),2*(t*i-n*s),0,2*(t*n-i*s),1-2*(t*t+i*i),2*(n*i+t*s),0,2*(t*i+n*s),2*(n*i-t*s),1-2*(t*t+n*n),0,0,0,0,1]}function $n(e){return!Array.isArray(e)||e.length!==4?null:`matrix3d(${Rn(Z(e)).map(n=>Math.round(n*1e6)/1e6+0).join(", ")})`}const Ln=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),Dn="#ffffff",On="rgba(0, 0, 0, 0.5)";function Nn(e){const t=[];if(e.blur!==void 0&&t.push(`blur(${Math.max(0,e.blur)}px)`),e.brightness!==void 0&&t.push(`brightness(${Math.max(0,e.brightness)})`),e.glow!==void 0&&t.push(`drop-shadow(0 0 ${Math.max(0,e.glow)}px ${e.glowColor??Dn})`),e.shadowX!==void 0||e.shadowY!==void 0||e.shadowBlur!==void 0){const n=e.shadowX??0,i=e.shadowY??0,s=Math.max(0,e.shadowBlur??0);t.push(`drop-shadow(${n}px ${i}px ${s}px ${e.shadowColor??On})`)}return t.length>0?t.join(" "):null}function Fn(e,t){const n=e.childNodes.length===1?e.firstChild:null;if(n&&n.nodeType===3){const i=n;i.data!==t&&(i.data=t);return}e.textContent!==t&&(e.textContent=t)}function Xn(e){if(!("ownerSVGElement"in e))return;const t=e.style;!t||t.transformBox||(t.transformBox="fill-box",t.transformOrigin||(t.transformOrigin="50% 50%"))}const te=new Set(["width","height","top","right","bottom","left","margin","marginTop","marginRight","marginBottom","marginLeft","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","borderRadius","borderWidth","fontSize","lineHeight","letterSpacing","outlineWidth","gap","rowGap","columnGap"]),Yn=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),Vn=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],qn=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),Wn=new Set(["originX","originY"]),Bn=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Un=new Set(["drawOn"]),jn={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},ee={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},Hn="http://www.w3.org/2000/svg";class Mt{targets=new Map;registerTarget(t,n){this.targets.set(t,n)}unregisterTarget(t){this.targets.delete(t)}getTarget(t){return this.targets.get(t)}clearTargets(){this.targets.clear()}applyState(t){for(const[n,i]of t.values){const s=this.targets.get(n);s&&this.applyProperties(s,i)}}applyProperties(t,n){let i=null,s=null,r=null,a=null,o=null;const c=n.has("motionPathX"),l=n.has("motionPathY"),u=n.has("motionPathRotate");for(const[p,d]of n)if(!(p==="x"&&c)&&!(p==="y"&&l)&&!((p==="rotate"||p==="rotateZ")&&u)&&!Un.has(p)){if(Yn.has(p))(i??={})[p]=d;else if(qn.has(p))typeof d=="number"&&((s??={})[p]=d);else if(Wn.has(p))typeof d=="number"&&((r??={})[p]=d);else if(Bn.has(p))typeof d=="number"&&((a??={})[p]=d);else if(Ln.has(p))(o??={})[p]=d;else if(p!=="perspective"){if(p!=="shine")if(p==="text"&&typeof d=="string")Fn(t,d);else if(p==="d"&&typeof d=="string"){const g=t;(g.tagName?.toLowerCase()==="path"?g:g.querySelector?.("path"))?.setAttribute?.("d",d)}else this.applyStyleProperty(t,p,d)}}const h=n.get("shine");typeof h=="number"&&this.applyShine(t,h);const f=[],m=n.get("perspective");if(typeof m=="number"&&m>0&&f.push(`perspective(${m}px)`),i)for(const p of Vn){const d=i[p];if(d===void 0)continue;const g=this.buildTransformPart(p,d);g&&f.push(g)}if(f.length>0&&(t.style.transform=f.join(" "),Xn(t)),s&&(s.childPerspective!==void 0&&(t.style.perspective=`${s.childPerspective}px`),(s.perspectiveOriginX!==void 0||s.perspectiveOriginY!==void 0)&&(t.style.perspectiveOrigin=`${s.perspectiveOriginX??50}% ${s.perspectiveOriginY??50}%`)),r){const p=r.originX??50,d=r.originY??50;t.style.transformOrigin=`${p}% ${d}%`}if(a){const p=a.clipTop??0,d=a.clipRight??0,g=a.clipBottom??0,b=a.clipLeft??0;t.style.clipPath=`inset(${p}% ${d}% ${g}% ${b}%)`}if(o){const p=Nn(o);p&&(t.style.filter=p)}}buildTransformPart(t,n){if(t==="quaternion")return $n(n);if(typeof n!="number")return null;switch(t){case"x":case"motionPathX":return`translateX(${n}px)`;case"y":case"motionPathY":return`translateY(${n}px)`;case"z":return`translateZ(${n}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${n}deg)`;case"rotateX":return`rotateX(${n}deg)`;case"rotateY":return`rotateY(${n}deg)`;case"scale":return`scale(${n})`;case"scaleX":return`scaleX(${n})`;case"scaleY":return`scaleY(${n})`;case"scaleZ":return`scaleZ(${n})`;case"skewX":return`skewX(${n}deg)`;case"skewY":return`skewY(${n}deg)`;default:return null}}applyShine(t,n){t.dataset.shineBase||(t.dataset.shineBase=t.style.color||"currentColor");const i=t.dataset.shineBase,s=-20+n*140,r=t.style;r.color="transparent",r.backgroundImage=`linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${i}, ${i})`,r.backgroundSize="250% 100%, 100% 100%",r.backgroundPosition=`${s}% 0, 0 0`,r.backgroundRepeat="no-repeat",r.webkitBackgroundClip="text",r.backgroundClip="text"}applyStyleProperty(t,n,i){let s;if(t.namespaceURI===Hn&&n in ee){const o=Array.isArray(i)?i.join(", "):String(i);t.style[ee[n]]=o;return}else n==="fill"&&t.dataset?.elementType==="text"?s="color":s=jn[n]??n;let a;typeof i=="number"?te.has(n)||te.has(s)?a=`${i}px`:a=String(i):Array.isArray(i)?a=i.join(", "):a=i,t.style[s]=a}}class ne{media;offset;driftTolerance;constructor(t,n={}){this.media=t,this.offset=n.offset??0,this.driftTolerance=Math.max(0,n.driftTolerance??.15)}targetTime(t){return Math.max(0,t/1e3+this.offset)}update(t,n){const i=this.targetTime(t);n?(this.media.paused&&this.safePlay(),Math.abs(this.media.currentTime-i)>this.driftTolerance&&(this.media.currentTime=i)):(this.media.paused||this.media.pause(),this.media.currentTime!==i&&(this.media.currentTime=i))}seek(t){this.media.currentTime=this.targetTime(t)}setRate(t){this.media.playbackRate=t}dispose(){this.media.paused||this.media.pause()}safePlay(){const t=this.media.play();t&&typeof t.catch=="function"&&t.catch(()=>{})}}function zn(e,t,n,i,s){const r=n-s;if(r<0){t.paused||t.pause(),t.currentTime=0;return}e.update(r,i)}class ot{container;timeline=null;adapter;animationFrameId;lastTime;options;targets={};isDestroyed=!1;mediaSync;mediaTargets=[];symbolInstances=[];scenarioList=[];scenarioId;authored=new Map;markerList=[];listeners=new Set;playhead={time:0,iteration:0,direction:"forward"};stepping=!1;lastMarkerId=null;reducedQuery;onReducedChange=()=>this.applyReducedMotion();visibilityObserver;onScreen=!0;pausedByVisibility=!1;autoplayWhenSeen=!1;onDocumentVisibility=()=>this.updateVisibility();constructor(t,n={}){if(typeof t=="string"){const i=document.querySelector(t);if(!i)throw new Error(`Container not found: ${t}`);this.container=i}else this.container=t;this.options=n,this.adapter=new Mt}async load(t){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(t)}async loadSource(t){let n;if(typeof t=="string"){const i=await fetch(t);if(!i.ok)throw new Error(`Failed to load animation: ${i.statusText}`);n=await i.json()}else n=t;this.useDefinition(n),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(t){const n={...t.config};this.options.speed!==void 0&&(n.speed=this.options.speed),this.options.loop!==void 0&&(n.loop=this.options.loop),this.options.alternate!==void 0&&(n.alternate=this.options.alternate),this.timeline=at({...t,config:n}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(t,n={}){if(t.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const i=new Set;for(const r of t){if(i.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);i.add(r.id)}const s=n.initial===void 0?t[0]:t.find(r=>r.id===n.initial);if(!s)throw new Error(`tinyfly: there is no scenario "${n.initial}"`);this.scenarioList=[...t],this.scenarioId=s.id,await this.loadSource(s.timeline)}get scenarios(){return this.scenarioList.map(t=>({id:t.id,label:t.label??t.id}))}get scenario(){return this.scenarioId}setScenario(t){const n=this.scenarioList.find(o=>o.id===t);if(!n||!this.timeline)return!1;if(t===this.scenarioId)return!0;const i=this.isPlaying,s=this.currentTime>=this.duration-.5,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=t,this.useDefinition(n.timeline),this.lastMarkerId=null;let a=0;return this.reducedMotion||s?a=this.duration:r!==void 0&&(a=this.markers.find(o=>o.id===r)?.time??0),this.seek(a),i&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(t){if(this.authored.has(t))return;const n={style:t.getAttribute("style")};t.children.length===0&&(n.text=t.textContent??"");const i=t.tagName.toLowerCase()==="path"?t:t.querySelector("path");i&&(n.path={element:i,d:i.getAttribute("d")}),this.authored.set(t,n)}restoreAuthored(){for(const[t,n]of this.authored){n.style===null?t.removeAttribute("style"):t.setAttribute("style",n.style),n.text!==void 0&&t.textContent!==n.text&&(t.textContent=n.text),n.path&&(n.path.d===null?n.path.element.removeAttribute("d"):n.path.element.setAttribute("d",n.path.d));const i=t.dataset;i&&delete i.shineBase}}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notify(){for(const t of this.listeners)t()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const t=this.currentTime;let n;for(const i of this.markers)if(i.time<=t+.5)n=i;else break;return n}caption(t,n){const i=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!i)return;const s=n??this.language(),r=a=>a?.[s]?.[i.id]??a?.[s.split("-")[0]]?.[i.id];return r(this.options.captions)??r(this.timeline?.captions)??i.label}next(){if(!this.timeline)return;const t=this.currentTime,n=this.markers.find(i=>i.time>t+.5);if(this.reducedMotion){this.seek(n?n.time:this.duration);return}t>=this.duration-.5||(this.stepping=n!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const t=this.currentTime,n=[...this.markers].reverse().find(i=>i.time<t-.5);this.pause(),this.seek(n?n.time:0)}goToMarker(t){const n=this.markers.find(i=>i.id===t);n&&(this.pause(),this.seek(n.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const t=this.options.initialFrame??"start";if(t==="none")return;const n=t==="end"?this.timeline.duration:t==="start"?0:t;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,n))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(n=>{for(const i of n)this.onScreen=i.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const t=this.container.getBoundingClientRect?.();t&&(t.width>0||t.height>0)&&(this.onScreen=t.bottom>0&&t.top<window.innerHeight&&t.right>0&&t.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const t=this.onScreen&&document.visibilityState!=="hidden";!t&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):t&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const t=this.currentMarker,n=t?.id;n!==this.lastMarkerId&&(this.lastMarkerId=n,this.options.onMarker(t))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(n=>{const i=n,s=Number(i.getAttribute("data-tinyfly-start")??"0")||0,r=i.getAttribute("data-volume");r!==null&&(i.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:i,startTime:s,sync:new ne(i)})})}syncAllMedia(t,n){for(const i of this.mediaTargets)zn(i.sync,i.el,t,n,i.startTime)}loadFromString(t){const n=JSON.parse(t);this.load(n)}registerTarget(t,n){if(typeof n=="string"){const i=this.container.querySelector(n);i&&(this.rememberAuthored(i),this.targets[t]=i,this.adapter.registerTarget(t,i))}else this.rememberAuthored(n),this.targets[t]=n,this.adapter.registerTarget(t,n)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(n=>{const i=n.closest("[data-tinyfly-symbol]");if(i&&i!==n)return;const s=n.getAttribute("data-tinyfly");s&&this.registerTarget(s,n)}),this.timeline&&new Set(this.timeline.tracks.map(i=>i.target)).forEach(i=>{if(!this.targets[i]){const s=this.container.querySelector(`[data-tinyfly="${i}"]`)||this.container.querySelector(`.${i}`)||this.container.querySelector(`#${i}`);s&&this.registerTarget(i,s)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const n=new Map(t.map(i=>[i.id,i]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(i=>{const s=i.getAttribute("data-tinyfly-symbol");if(!s)return;const r=n.get(s);if(!r||!r.timeline.tracks?.length)return;const a=new Mt;i.querySelectorAll("[data-tinyfly]").forEach(o=>{const c=o.getAttribute("data-tinyfly");c&&a.registerTarget(c,o)}),this.symbolInstances.push({adapter:a,timeline:at(r.timeline)})})}attachMedia(t,n){this.mediaSync=new ne(t,n),this.timeline&&(this.mediaSync.setRate(this.timeline.speed),this.mediaSync.update(this.timeline.currentTime,this.isPlaying))}detachMedia(){this.mediaSync?.dispose(),this.mediaSync=void 0}play(){!this.timeline||this.isDestroyed||(this.autoplayWhenSeen=!1,this.stepping=this.options.stepMode===!0,this.startPlaying())}startPlaying(){if(!this.timeline||this.isDestroyed)return;const t=this.timeline.playbackState==="idle";this.timeline.play(),t&&this.timeline.currentTime===0&&this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.update(this.timeline.currentTime,!0),this.syncAllMedia(this.timeline.currentTime,!0),this.startAnimationLoop(),this.notify()}pause(){this.timeline&&(this.stepping=!1,this.timeline.pause(),this.notify(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1),this.stopAnimationLoop())}stop(){this.timeline&&(this.timeline.stop(),this.stopAnimationLoop(),this.applyState(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1))}seek(t){this.timeline&&(this.timeline.seek(t),this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.seek(this.timeline.currentTime),this.syncAllMedia(this.timeline.currentTime,this.isPlaying))}setSpeed(t){this.timeline&&(this.timeline.speed=t,this.mediaSync?.setRate(t))}reverse(){this.timeline&&this.timeline.reverse()}get currentTime(){return this.timeline?.currentTime??0}get state(){return this.timeline?.getStateAtTime(this.timeline.currentTime)}get duration(){return this.timeline?.duration??0}get isPlaying(){return this.timeline?.playbackState==="playing"}destroy(){this.isDestroyed=!0,this.stopAnimationLoop(),this.reducedQuery?.removeEventListener?.("change",this.onReducedChange),this.visibilityObserver?.disconnect(),typeof document<"u"&&document.removeEventListener("visibilitychange",this.onDocumentVisibility),this.mediaSync?.dispose(),this.mediaSync=void 0;for(const t of this.mediaTargets)t.el.paused||t.el.pause();this.mediaTargets=[],this.adapter.clearTargets();for(const t of this.symbolInstances)t.adapter.clearTargets();this.symbolInstances=[],this.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=n=>{if(this.isDestroyed||!this.timeline)return;const i=n-(this.lastTime??n);this.lastTime=n;const s=this.playhead;this.timeline.tick(i),this.stopAtMarker(s),this.applyState();const r=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,r),this.syncAllMedia(this.timeline.currentTime,r),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(t):(this.animationFrameId=void 0,this.notify())};this.animationFrameId=requestAnimationFrame(t)}stopAtMarker(t){const n=this.timeline,i={time:n.currentTime,iteration:n.loopIteration,direction:n.direction};this.playhead=i;const s=this.markers;if(s.length===0)return;const{crossings:r}=Pn(s.map(a=>a.time),t,i,{duration:n.duration,alternate:n.config.alternate===!0,holding:n.repeatDelayRemaining>0});for(const a of r){if(a.kind!=="event")continue;const o=s[a.index];if(this.stepping||o.pause){this.stepping=!1,n.pause(),n.seek(o.time),this.playhead={time:o.time,iteration:n.loopIteration,direction:n.direction};return}}}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}applyState(){if(!this.timeline)return;const t=this.timeline.currentTime;this.adapter.applyState(this.timeline.getStateAtTime(t)),this.announceMarker(),this.notify();for(const n of this.symbolInstances){const i=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(i>0?t%i:t))}}}async function Qn(e,t,n={}){const i=new ot(e,{...n,autoplay:!0});return await i.load(t),i}function Gn(e,t={}){return new ot(e,t)}const ie={play:"Play",pause:"Pause",prev:"Previous step",next:"Next step",restart:"Restart",scrub:"Position",speed:"Speed",reveal:"Reveal",step:"Step",of:"of",stepFormat:"{index} / {total}",scenario:"Scenario",fullscreen:"Full screen",exitFullscreen:"Exit full screen"},se="tinyfly-controls-style",Zn=`
|
|
3
3
|
.tf-ctl { --tf-ctl-fg: #1d1d1f; --tf-ctl-bg: #f4f2ee; --tf-ctl-accent: #c2410c; --tf-ctl-radius: 8px;
|
|
4
4
|
font: 14px/1.4 var(--tf-ctl-font, system-ui, sans-serif); color: var(--tf-ctl-fg); margin-top: 8px; }
|
|
5
5
|
.tf-ctl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px; border-radius: var(--tf-ctl-radius); background: var(--tf-ctl-bg); }
|
|
@@ -2126,6 +2126,14 @@ class St {
|
|
|
2126
2126
|
get currentTime() {
|
|
2127
2127
|
return this.timeline?.currentTime ?? 0;
|
|
2128
2128
|
}
|
|
2129
|
+
/**
|
|
2130
|
+
* The animated values at the playhead, for renderers that draw from values
|
|
2131
|
+
* rather than DOM elements (a canvas, or an SVG rebuilt each frame). Read it
|
|
2132
|
+
* from a `subscribe` listener. Undefined before a timeline loads.
|
|
2133
|
+
*/
|
|
2134
|
+
get state() {
|
|
2135
|
+
return this.timeline?.getStateAtTime(this.timeline.currentTime);
|
|
2136
|
+
}
|
|
2129
2137
|
/**
|
|
2130
2138
|
* Get total duration.
|
|
2131
2139
|
*/
|
|
@@ -2126,6 +2126,14 @@ class Zt {
|
|
|
2126
2126
|
get currentTime() {
|
|
2127
2127
|
return this.timeline?.currentTime ?? 0;
|
|
2128
2128
|
}
|
|
2129
|
+
/**
|
|
2130
|
+
* The animated values at the playhead, for renderers that draw from values
|
|
2131
|
+
* rather than DOM elements (a canvas, or an SVG rebuilt each frame). Read it
|
|
2132
|
+
* from a `subscribe` listener. Undefined before a timeline loads.
|
|
2133
|
+
*/
|
|
2134
|
+
get state() {
|
|
2135
|
+
return this.timeline?.getStateAtTime(this.timeline.currentTime);
|
|
2136
|
+
}
|
|
2129
2137
|
/**
|
|
2130
2138
|
* Get total duration.
|
|
2131
2139
|
*/
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
(function(R){"use strict";function ee(i){return typeof i=="object"&&i!==null&&i.type==="cubic-bezier"}function ie(i){return typeof i=="object"&&i!==null&&i.type!=="cubic-bezier"}const At=2;function se(i){return i.some(t=>t.interpolation!==void 0)?2: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 ne(i){return i.property==="motionPath"&&"motionPathConfig"in i}function re(i,t){if(!(t>0))return i;const e=1e3/t;return Math.floor(i/e+1e-9)*e}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 ae(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=ae(t,s);return r===0?0:e.amount*n/r}return e.each!==void 0?e.each*n:0}function oe(i,t){return Array.from({length:i},(e,s)=>_t(s,i,t))}function rt(i,t){return i<=1?0:Math.max(...oe(i,t))}const N=1,kt=6e4,z=kt/N,X={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1};class ce{from;to;stiffness;damping;mass;restDelta;restSpeed;distance;samples;velocity;settledStep=null;constructor(t){this.from=t.from,this.to=t.to,this.stiffness=t.stiffness??X.stiffness,this.damping=t.damping??X.damping,this.mass=t.mass??X.mass,this.restDelta=t.restDelta??X.restDelta,this.restSpeed=t.restSpeed??X.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=t.velocity??X.velocity,this.isAtRest(this.from)&&(this.settledStep=0)}isAtRest(t){return Math.abs(t-this.to)<this.restDelta*this.distance&&Math.abs(this.velocity)<this.restSpeed*this.distance}valueAt(t){if(t<=0)return this.from;const e=Math.floor(t/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,he=.002,le=1e-4,ue=6e4;function at(i){const t=i.friction??wt;return t>0?t:wt}function de(i){return i.from+i.velocity/at(i)}function fe(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=fe(de(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(le,t*he);if(e>=t)return 0;const s=Math.log(t/e)/at(i);return Math.min(ue,s*1e3)}function It(i,t){if(t<=0)return i.from;const e=Pt(i);if(t>=vt(i))return e;const s=at(i);return i.from+(e-i.from)*(1-Math.exp(-s*t/1e3))}const ot=i=>i,pe=i=>i*i,me=i=>1-(1-i)*(1-i),ge=i=>i<.5?2*i*i:1-Math.pow(-2*i+2,2)/2,xt=i=>i*i*i,Ct=i=>1-Math.pow(1-i,3),Rt=i=>i<.5?4*i*i*i:1-Math.pow(-2*i+2,3)/2,ye={linear:ot,"ease-in":xt,"ease-out":Ct,"ease-in-out":Rt,"ease-in-quad":pe,"ease-out-quad":me,"ease-in-out-quad":ge,"ease-in-cubic":xt,"ease-out-cubic":Ct,"ease-in-out-cubic":Rt};function Te(i){const[t,e,s,n]=i,r=3*t,a=3*(s-t)-r,o=1-r-a,c=3*e,h=3*(n-e)-c,u=1-c-h,l=d=>((o*d+a)*d+r)*d,g=d=>((u*d+h)*d+c)*d,p=d=>(3*o*d+2*a)*d+r,f=d=>{let m=d;for(let A=0;A<8;A++){const M=l(m)-d;if(Math.abs(M)<1e-7)return m;const y=p(m);if(Math.abs(y)<1e-7)break;m-=M/y}let T=0,b=1;for(m=d;T<b;){const A=l(m);if(Math.abs(A-d)<1e-7)return m;d>A?T=m:b=m,m=(T+b)/2}return m};return d=>{if(d<=0)return 0;if(d>=1)return 1;const m=f(d);return g(m)}}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 be(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 Ae=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 Se(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 Me(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 _e(i){switch(i.type){case"steps":return Me(i.count,i.position);case"elastic":return ct(be(i.amplitude,i.period),i.mode);case"bounce":return ct(Ae,i.mode);case"back":return ct(Se(i.overshoot),i.mode)}}function ke(i){return i===void 0?ot:ee(i)?Te(i.points):ie(i)?_e(i):ye[i]??ot}const Dt=32,we=256,q=new Map,Pe=/[MmLlHhVvCcSsQqTtAaZz]/,ve=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,Ie={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function xe(i){const t=[];let e=0,s=null;const n=()=>{for(;e<i.length&&/[\s,]/.test(i[e]);)e++};for(;e<i.length&&(n(),!(e>=i.length));){const r=i[e];if(Pe.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=ve.exec(i.slice(e));if(!c)break;s.args.push(parseFloat(c[0])),e+=c[0].length}return t}function Ce(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,g=Math.cos(l),p=Math.sin(l),f=(i-o)/2,d=(t-c)/2,m=g*f+p*d,T=-p*f+g*d,b=m*m/(h*h)+T*T/(u*u);if(b>1){const w=Math.sqrt(b);h*=w,u*=w}const A=r===a?-1:1,M=h*h*u*u-h*h*T*T-u*u*m*m,y=h*h*T*T+u*u*m*m,_=A*Math.sqrt(Math.max(0,M/y)),S=_*h*T/u,E=-_*u*m/h,tt=g*S-p*E+(i+o)/2,k=p*S+g*E+(t+c)/2,x=(w,I,C,Y)=>{const bt=w*C+I*Y,it=Math.sqrt((w*w+I*I)*(C*C+Y*Y)),j=Math.acos(Math.max(-1,Math.min(1,bt/it)));return w*Y-I*C<0?-j:j},P=x(1,0,(m-S)/h,(T-E)/u);let v=x((m-S)/h,(T-E)/u,(-m-S)/h,(-T-E)/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/$,et=4/3*Math.tan(Tt/4),Kt=w=>{const I=h*Math.cos(w),C=u*Math.sin(w);return[g*I-p*C+tt,p*I+g*C+k]},Jt=w=>{const I=-h*Math.sin(w),C=u*Math.cos(w);return[g*I-p*C,p*I+g*C]},te=[];for(let w=0;w<$;w++){const I=P+w*Tt,C=I+Tt,[Y,bt]=Kt(I),[it,j]=w===$-1?[o,c]:Kt(C),[Xi,Fi]=Jt(I),[Yi,Ni]=Jt(C);te.push([Y+et*Xi,bt+et*Fi,it-et*Yi,j-et*Ni,it,j])}return te}function B(i,t,e,s,n){const r=1-n;return r*r*r*i+3*r*r*n*t+3*r*n*n*e+n*n*n*s}function Et(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 G(i,t,e){const[s,n,r,a,o,c]=e,h=[0];let u=i,l=t,g=0;for(let p=1;p<=Dt;p++){const f=p/Dt,d=B(i,s,r,o,f),m=B(t,n,a,c,f);g+=Math.hypot(d-u,m-l),h.push(g),u=d,l=m}return{subpath:0,type:"C",points:[s,n,r,a,o,c],startX:i,startY:t,endX:o,endY:c,length:g,lengths:h}}function Z(i){const t=q.get(i);if(t)return t;const e=[];let s=0,n=0,r=0,a=0,o=null,c=null,h=-1;const u=new Set,l=d=>{h<0&&(h=0),d.subpath=h,e.push(d)};for(const{type:d,args:m}of xe(i)){const T=d.toUpperCase(),b=d!==T,A=Ie[T];if(T==="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+A<=m.length;M+=A){const y=m.slice(M,M+A),_=b?s:0,S=b?n:0;let E=null,tt=null;switch(T){case"M":M===0?(s=y[0]+_,n=y[1]+S,r=s,a=n,(h<0||e[e.length-1]?.subpath===h)&&h++):(l(V(s,n,y[0]+_,y[1]+S)),s=y[0]+_,n=y[1]+S);break;case"L":l(V(s,n,y[0]+_,y[1]+S)),s=y[0]+_,n=y[1]+S;break;case"H":l(V(s,n,y[0]+_,n)),s=y[0]+_;break;case"V":l(V(s,n,s,y[0]+S)),n=y[0]+S;break;case"C":{const k=[y[0]+_,y[1]+S,y[2]+_,y[3]+S,y[4]+_,y[5]+S];l(G(s,n,k)),E=[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,y[0]+_,y[1]+S,y[2]+_,y[3]+S];l(G(s,n,P)),E=[P[2],P[3]],s=P[4],n=P[5];break}case"Q":case"T":{let k=s,x=n;T==="Q"?(k=y[0]+_,x=y[1]+S):c&&(k=2*s-c[0],x=2*n-c[1]);const P=T==="Q"?y[2]+_:y[0]+_,v=T==="Q"?y[3]+S:y[1]+S;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=y[5]+_,x=y[6]+S;let P=s,v=n;for(const $ of Ce(s,n,y[0],y[1],y[2],y[3],y[4],k,x))l(G(P,v,$)),P=$[4],v=$[5];s=k,n=x;break}}o=E,c=tt}}const g=e.reduce((d,m)=>d+m.length,0),p=[];for(let d=0;d<e.length;){const m=e[d].subpath;let T=d,b=0;for(;T<e.length&&e[T].subpath===m;)b+=e[T++].length;const A=e[d],M=e[T-1],y=u.has(m)||Math.abs(M.endX-A.startX)<1e-9&&Math.abs(M.endY-A.startY)<1e-9;p.push({start:d,end:T,length:b,closed:y}),d=T}const f={segments:e,totalLength:g,subpaths:p};return q.size>=we&&q.delete(q.keys().next().value),q.set(i,f),f}function Re(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 De(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=Re(i,t);let h=Et(i.startX,e,n,a,c),u=Et(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),g=B(i.startX,e,n,a,l),p=B(i.startY,s,r,o,l),f=B(i.startX,e,n,a,c),d=B(i.startY,s,r,o,c);h=c<.5?g-f:f-g,u=c<.5?p-d:d-p}return{x:B(i.startX,e,n,a,c),y:B(i.startY,s,r,o,c),angle:Math.atan2(u,h)*180/Math.PI}}function 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 De(a,t-n);n+=a.length}return{x:0,y:0,angle:0}}function Ee(i,t){const{segments:e,totalLength:s}=Z(i);return Bt(e,Math.max(0,Math.min(1,t))*s)}const Be=24,Oe=320,Le=2.5,W=72,$e=.2,Xe=128,K=new Map;let ht=0,O;const Ot=i=>Math.round(i*100)/100;function Lt(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 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 $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 Xt(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 Fe(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(Xt(i,W)),r=Ft(Xt(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 g=0;for(let p=0;p<a&&g<c;p++){const f=s?h?(l-p+a)%a:(p+l)%a:h?a-1-p:p,d=n[p][0]-r[f][0],m=n[p][1]-r[f][1];g+=d*d+m*m}g<c&&(c=g,o={offset:s?l/a:0,reversed:h})}}return o}function Ye(i,t,e){return e?((t.reversed?t.offset-i:i+t.offset)%1+1)%1:t.reversed?1-i:i}function Ne(i,t,e){return e?((t.reversed?t.offset-i:i-t.offset)%1+1)%1:t.reversed?1-i:i}function qe(i,t,e){const s=i.closed&&t.closed,n=Fe(i,t,e.shapeIndex),r=Math.max(Be,Math.min(Oe,Math.ceil(Math.max(i.length,t.length)/Le))),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(Ne(l,n,s));let c=[...a].sort((l,g)=>l-g);s&&(c=c.filter(l=>l<1));const h=[],u=[];for(const l of c)h.push(...lt(i,l)),u.push(...lt(t,Ye(l,n,s)));return Ve({from:h,to:u,closed:s})}function Ve(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=$e;for(let u=a+1;u<o;u++){const l=Math.max(Yt(i.from,a,o,u),Yt(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 Yt(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 We(i,t,e){const s=e.shapeIndex;if(O&&O.from===i&&O.to===t&&O.shapeIndex===s)return O.plan;const r=K.get(String(s??"auto"))?.get(i)?.get(t);if(r)return O={from:i,to:t,shapeIndex:s,plan:r},r;const a=Z(i).subpaths.filter(p=>p.length>0).length===Z(t).subpaths.filter(p=>p.length>0).length,o=Lt(i,!a),c=Lt(t,!a),h={pairs:o.map((p,f)=>qe(p,c[f],e))};ht>=Xe&&(K.clear(),ht=0);const u=String(s??"auto"),l=K.get(u)??new Map;K.set(u,l);const g=l.get(i)??new Map;return l.set(i,g),g.set(t,h),ht++,O={from:i,to:t,shapeIndex:s,plan:h},h}function Ue(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=We(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=Ot(o.from[c]+(o.to[c]-o.from[c])*n),u=Ot(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 He(i){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(i)}const Qe=.9995;function je(){return[0,0,0,1]}function ze(i,t){return i[0]*t[0]+i[1]*t[1]+i[2]*t[2]+i[3]*t[3]}function Ge(i){return Math.hypot(i[0],i[1],i[2],i[3])}function U(i){const t=Ge(i);return t===0?je():[i[0]/t,i[1]/t,i[2]/t,i[3]/t]}function Ze(i,t,e){const s=U(i);let n=U(t),r=ze(s,n);if(r<0&&(n=[-n[0],-n[1],-n[2],-n[3]],r=-r),r>Qe)return U([s[0]+(n[0]-s[0])*e,s[1]+(n[1]-s[1])*e,s[2]+(n[2]-s[2])*e,s[3]+(n[3]-s[3])*e]);const a=Math.acos(r),o=Math.sin(a),c=Math.sin((1-e)*a)/o,h=Math.sin(e*a)/o;return U([s[0]*c+n[0]*h,s[1]*c+n[1]*h,s[2]*c+n[2]*h,s[3]*c+n[3]*h])}const D=(i,t,e)=>i+(t-i)*e,Nt=512,ut=new Map,dt=new Map;function qt(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<Nt&&ut.set(i,s),s}const Vt=i=>i.charCodeAt(0)===35,Wt=i=>i.startsWith("rgb"),Ut=i=>i.startsWith("rgba"),Ke=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,ft=i=>Math.round(i).toString(16).padStart(2,"0");function Je(i,t,e){return`#${ft(i)}${ft(t)}${ft(e)}`}function Ht(i){const t=dt.get(i);if(t)return t;const e=i.match(Ke);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<Nt&&dt.set(i,a),a}const ti=(i,t,e)=>{if(Vt(i)&&Vt(t)){const[s,n,r]=qt(i),[a,o,c]=qt(t),h=D(s,a,e),u=D(n,o,e),l=D(r,c,e);return Je(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},ei=(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},ii=(i,t,e)=>Ze(i,t,e),Qt=(i,t,e)=>e<1?i:t,si=(i,t,e)=>Ue(i,t,e);function ni(i,t){return t==="slerp"?ii:typeof i=="number"?D:Array.isArray(i)?ei:typeof i=="string"?i.startsWith("#")||i.startsWith("rgb")?ti:He(i)?si:Qt:Qt}function ri(i){const t=[...i.keyframes].sort((e,s)=>e.time-s.time);return{...i,keyframes:t}}function L(i){return i.targets&&i.targets.length>0?i.targets:[i.target]}function F(i,t,e,s){const n=e??0;return!s||t<=1?n:n+_t(i,t,s)}class pt{track;targets;constructor(t){this.track=t,this.targets=L(t)}getValueAtTime(t){return this.valueForOffset(t-F(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=F(n,e,this.track.delay,this.track.stagger),a=this.valueForOffset(t-r);a!==void 0&&s.push({target:this.targets[n],value:a,start:r+this.track.keyframes[0].time})}return s}getDuration(){const{keyframes:t}=this.track;if(t.length===0)return 0;const e=t[t.length-1].time,s=this.track.stagger?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=ke(n.easing)(a);return ni(s.value,this.track.interpolation)(s.value,n.value,c)}findSurroundingKeyframes(t){const{keyframes:e}=this.track;for(let s=0;s<e.length-1;s++)if(t>=e[s].time&&t<=e[s+1].time)return{from:e[s],to:e[s+1]};return{from:null,to:null}}}class ai{track;targets;sampler;constructor(t){this.track=t,this.targets=L(t),this.sampler=new ce(t.spring)}getValueAtTime(t){return this.sampler.valueAt(t-F(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=F(n,e,this.track.delay,this.track.stagger);s.push({target:this.targets[n],value:this.sampler.valueAt(t-r),start:r})}return s}getDuration(){const t=this.track.stagger?rt(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+t}getTrack(){return this.track}}class oi{track;targets;duration;constructor(t){this.track=t,this.targets=L(t),this.duration=vt(t.inertia)}getValueAtTime(t){return It(this.track.inertia,t-F(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=F(n,e,this.track.delay,this.track.stagger);s.push({target:this.targets[n],value:It(this.track.inertia,t-r),start:r})}return s}getDuration(){const t=this.track.stagger?rt(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+t}getTrack(){return this.track}}function ci(i,t){const e={...Ee(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,g=Math.cos(l),p=Math.sin(l);e.angle=Math.atan2(n*g+a*p,s*g+r*p)*180/Math.PI}return i.autoRotate&&i.rotateOffset&&(e.angle+=i.rotateOffset),e}const mt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},hi=20;function li(i){const t=mt[i??"upperCase"]??i??mt.upperCase,e=Array.from(t);return e.length>0?e:Array.from(mt.upperCase)}function ui(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 di(i,t,e=0){const s=i.from??"",n=i.to,r=Math.max(0,Math.min(1,t));if(r<=0)return s;if(r>=1)return n;const a=Array.from(s),o=Array.from(n),c=i.rightToLeft??!1;if(i.mode==="type"){const b=Math.round(r*Math.max(a.length,o.length));return c?a.slice(0,Math.max(0,a.length-b)).join("")+o.slice(Math.max(0,o.length-b)).join(""):o.slice(0,b).join("")+a.slice(b).join("")}const h=Math.max(0,Math.min(.999,i.revealDelay??0)),u=Math.max(0,(r-h)/(1-h)),l=Math.floor(u*o.length),g=i.tweenLength===!1?o.length:Math.round(a.length+(o.length-a.length)*r),p=li(i.chars),f=i.refreshRate??hi,d=f>0?Math.floor(e*f/1e3):0,m=i.seed??1;let T="";for(let b=0;b<g;b++){const A=c?b>=g-l:b<l,M=c?o[o.length-(g-b)]:o[b];A&&M!==void 0||M===" "||M===`
|
|
2
|
-
`?T+=M:T+=p[ui(m,b,d)%p.length]}return T}class fi{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}get drawingRate(){return this._config.drawingRate??0}set drawingRate(t){const e={...this._config};t>0?e.drawingRate=t:delete e.drawingRate,this._config=e}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(t=re(t,this._config.drawingRate??0),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,g=s.get(u);(!g||(l!==g.started?l:l?h>=g.start:h<=g.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",di(c.textConfig,r,Math.max(0,a)));return}const h=this._motionPathTracks.get(e);if(h&&typeof r=="number"){const u=ci(h.motionPathConfig,r);o.set("motionPathX",u.x),o.set("motionPathY",u.y),h.motionPathConfig.autoRotate&&o.set("motionPathRotate",u.angle)}else o.set(n,r)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const t=new Set;this._sharedWrites=!1;t:for(const e of this._tracks)for(const s of L(e)){const n=`${s}\0${e.property}`;if(t.has(n)){this._sharedWrites=!0;break t}t.add(n)}}return this._sharedWrites}addTrack(t){if(this._tracks.push(t),this._sharedWrites=null,st(t)){this._trackPlayers.set(t.id,new oi(t));return}if(nt(t)){this._trackPlayers.set(t.id,new ai(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(ne(t)){const e={id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,delay:t.delay,endDelay:t.endDelay,targets:t.targets,stagger:t.stagger};this._trackPlayers.set(t.id,new 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=L(a).filter(l=>L(s).includes(l));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=n.to&&n.from<=c.to))continue;const u=n.from>=c.from;for(const l of o)t.push({target:l,property:s.property,losingTrackId:u?a.id:s.id,winningTrackId:u?s.id:a.id})}}return t}_matches(t,e){if(e.id!==void 0&&t.id!==e.id||e.property!==void 0&&t.property!==e.property||e.target!==void 0&&!L(t).includes(e.target))return!1;if(e.timeRange){const s=this.getTrackSpan(t.id);if(!s||s.to<e.timeRange.from||s.from>e.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:se(this._tracks),id:this.id,name:this.name,config:{...this._config},tracks:[...this._tracks],...this.captions&&{captions:this.captions}}}get config(){return this._config}get markers(){return[...this._config.markers??[]].sort((t,e)=>t.time-e.time)}setMarkers(t){const e=t&&t.length>0?[...t].sort((n,r)=>n.time-r.time).map(n=>({...n})):void 0,s={...this._config};e?s.markers=e:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(t){const e={};for(const[s,n]of Object.entries(t??{}))e[s]={...n};this._captions=Object.keys(e).length>0?e:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let t=0;for(const[,e]of this._trackPlayers)t=Math.max(t,e.getDuration());return t}_handleEndReached(){const t=this._config.loop??0;return t===-1||this._loopIteration<t?(this._loopIteration++,this._armRepeatDelay(),this._config.alternate?this._direction="reverse":this._repeatDelayRemaining>0?this._wrapAfterDelay=!0:this._currentTime=0,this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}_handleStartReached(){const t=this._config.loop??0;return this._config.alternate&&(t===-1||this._loopIteration<t)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const pi=100;function mi(i,t,e,s){const n=[],r=[],{duration:a,alternate:o}=s,c=(p,f,d,m)=>{r.push([p,f]);const T=[];i.forEach((b,A)=>{(d==="forward"?(m?b>=p:b>p)&&b<=f:(m?b<=p:b<p)&&b>=f)&&T.push(A)}),T.sort((b,A)=>(d==="forward"?i[b]-i[A]:i[A]-i[b])||b-A);for(const b of T)n.push({kind:"event",index:b,direction:d})};let h=t.time,u=t.direction,l=t.fresh===!0;const g=Math.min(pi,Math.max(0,e.iteration-t.iteration));for(let p=0;p<g;p++){const f=u==="forward"?a:0;c(h,f,u,l),n.push({kind:"repeat"}),o?(u=u==="forward"?"reverse":"forward",h=f,l=!1):(h=u==="forward"?0:a,l=!0)}return g>0&&s.holding&&!o?{crossings:n,passes:r}:(c(h,e.time,u,l),{crossings:n,passes:r})}function gi(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 yi(i){if(st(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:gi(t.inertia),...H(t)}}if(nt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...H(t)}}if(St(i)){const t=i;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((e,s)=>e.time-s.time),...H(t)}}if(i.property==="motionPath"&&"motionPathConfig"in i){const t=i,e=[...t.keyframes].sort((s,n)=>s.time-n.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:e,...H(t)}}return ri({id:i.id,target:i.target,property:i.property,keyframes:i.keyframes,...i.interpolation!==void 0&&{interpolation:i.interpolation},...H(i)})}function J(i){const t=i.formatVersion??1;if(t>At)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${At}. Update tinyfly to play it.`);return new fi({id:i.id,name:i.name,config:i.config,tracks:i.tracks.map(yi),captions:i.captions})}function Ti(i){const[t,e,s,n]=i;return[1-2*(e*e+s*s),2*(t*e+s*n),2*(t*s-e*n),0,2*(t*e-s*n),1-2*(t*t+s*s),2*(e*s+t*n),0,2*(t*s+e*n),2*(e*s-t*n),1-2*(t*t+e*e),0,0,0,0,1]}function bi(i){return!Array.isArray(i)||i.length!==4?null:`matrix3d(${Ti(U(i)).map(e=>Math.round(e*1e6)/1e6+0).join(", ")})`}const Ai=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),Si="#ffffff",Mi="rgba(0, 0, 0, 0.5)";function _i(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??Si})`),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??Mi})`)}return t.length>0?t.join(" "):null}function ki(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 wi(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"]),Pi=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),vi=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],Ii=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),xi=new Set(["originX","originY"]),Ci=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Ri=new Set(["drawOn"]),Di={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"},Ei="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){let s=null,n=null,r=null,a=null,o=null;const c=e.has("motionPathX"),h=e.has("motionPathY"),u=e.has("motionPathRotate");for(const[f,d]of e)if(!(f==="x"&&c)&&!(f==="y"&&h)&&!((f==="rotate"||f==="rotateZ")&&u)&&!Ri.has(f)){if(Pi.has(f))(s??={})[f]=d;else if(Ii.has(f))typeof d=="number"&&((n??={})[f]=d);else if(xi.has(f))typeof d=="number"&&((r??={})[f]=d);else if(Ci.has(f))typeof d=="number"&&((a??={})[f]=d);else if(Ai.has(f))(o??={})[f]=d;else if(f!=="perspective"){if(f!=="shine")if(f==="text"&&typeof d=="string")ki(t,d);else if(f==="d"&&typeof d=="string"){const m=t;(m.tagName?.toLowerCase()==="path"?m:m.querySelector?.("path"))?.setAttribute?.("d",d)}else this.applyStyleProperty(t,f,d)}}const l=e.get("shine");typeof l=="number"&&this.applyShine(t,l);const g=[],p=e.get("perspective");if(typeof p=="number"&&p>0&&g.push(`perspective(${p}px)`),s)for(const f of vi){const d=s[f];if(d===void 0)continue;const m=this.buildTransformPart(f,d);m&&g.push(m)}if(g.length>0&&(t.style.transform=g.join(" "),wi(t)),n&&(n.childPerspective!==void 0&&(t.style.perspective=`${n.childPerspective}px`),(n.perspectiveOriginX!==void 0||n.perspectiveOriginY!==void 0)&&(t.style.perspectiveOrigin=`${n.perspectiveOriginX??50}% ${n.perspectiveOriginY??50}%`)),r){const f=r.originX??50,d=r.originY??50;t.style.transformOrigin=`${f}% ${d}%`}if(a){const f=a.clipTop??0,d=a.clipRight??0,m=a.clipBottom??0,T=a.clipLeft??0;t.style.clipPath=`inset(${f}% ${d}% ${m}% ${T}%)`}if(o){const f=_i(o);f&&(t.style.filter=f)}}buildTransformPart(t,e){if(t==="quaternion")return bi(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===Ei&&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=Di[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 yt{container;timeline=null;adapter;animationFrameId;lastTime;options;targets={};isDestroyed=!1;mediaSync;mediaTargets=[];symbolInstances=[];scenarioList=[];scenarioId;authored=new Map;markerList=[];listeners=new Set;playhead={time:0,iteration:0,direction:"forward"};stepping=!1;lastMarkerId=null;reducedQuery;onReducedChange=()=>this.applyReducedMotion();visibilityObserver;onScreen=!0;pausedByVisibility=!1;autoplayWhenSeen=!1;onDocumentVisibility=()=>this.updateVisibility();constructor(t,e={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=e,this.adapter=new Q}async load(t){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(t)}async loadSource(t){let e;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load animation: ${s.statusText}`);e=await s.json()}else e=t;this.useDefinition(e),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(t){const e={...t.config};this.options.speed!==void 0&&(e.speed=this.options.speed),this.options.loop!==void 0&&(e.loop=this.options.loop),this.options.alternate!==void 0&&(e.alternate=this.options.alternate),this.timeline=J({...t,config:e}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(t,e={}){if(t.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const s=new Set;for(const r of t){if(s.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);s.add(r.id)}const n=e.initial===void 0?t[0]:t.find(r=>r.id===e.initial);if(!n)throw new Error(`tinyfly: there is no scenario "${e.initial}"`);this.scenarioList=[...t],this.scenarioId=n.id,await this.loadSource(n.timeline)}get scenarios(){return this.scenarioList.map(t=>({id:t.id,label:t.label??t.id}))}get scenario(){return this.scenarioId}setScenario(t){const e=this.scenarioList.find(o=>o.id===t);if(!e||!this.timeline)return!1;if(t===this.scenarioId)return!0;const s=this.isPlaying,n=this.currentTime>=this.duration-.5,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=t,this.useDefinition(e.timeline),this.lastMarkerId=null;let a=0;return this.reducedMotion||n?a=this.duration:r!==void 0&&(a=this.markers.find(o=>o.id===r)?.time??0),this.seek(a),s&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(t){if(this.authored.has(t))return;const e={style:t.getAttribute("style")};t.children.length===0&&(e.text=t.textContent??"");const s=t.tagName.toLowerCase()==="path"?t:t.querySelector("path");s&&(e.path={element:s,d:s.getAttribute("d")}),this.authored.set(t,e)}restoreAuthored(){for(const[t,e]of this.authored){e.style===null?t.removeAttribute("style"):t.setAttribute("style",e.style),e.text!==void 0&&t.textContent!==e.text&&(t.textContent=e.text),e.path&&(e.path.d===null?e.path.element.removeAttribute("d"):e.path.element.setAttribute("d",e.path.d));const s=t.dataset;s&&delete s.shineBase}}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notify(){for(const t of this.listeners)t()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const t=this.currentTime;let e;for(const s of this.markers)if(s.time<=t+.5)e=s;else break;return e}caption(t,e){const s=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!s)return;const n=e??this.language(),r=a=>a?.[n]?.[s.id]??a?.[n.split("-")[0]]?.[s.id];return r(this.options.captions)??r(this.timeline?.captions)??s.label}next(){if(!this.timeline)return;const t=this.currentTime,e=this.markers.find(s=>s.time>t+.5);if(this.reducedMotion){this.seek(e?e.time:this.duration);return}t>=this.duration-.5||(this.stepping=e!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const t=this.currentTime,e=[...this.markers].reverse().find(s=>s.time<t-.5);this.pause(),this.seek(e?e.time:0)}goToMarker(t){const e=this.markers.find(s=>s.id===t);e&&(this.pause(),this.seek(e.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const t=this.options.initialFrame??"start";if(t==="none")return;const e=t==="end"?this.timeline.duration:t==="start"?0:t;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,e))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(e=>{for(const s of e)this.onScreen=s.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const t=this.container.getBoundingClientRect?.();t&&(t.width>0||t.height>0)&&(this.onScreen=t.bottom>0&&t.top<window.innerHeight&&t.right>0&&t.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const t=this.onScreen&&document.visibilityState!=="hidden";!t&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):t&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const t=this.currentMarker,e=t?.id;e!==this.lastMarkerId&&(this.lastMarkerId=e,this.options.onMarker(t))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(e=>{const s=e,n=Number(s.getAttribute("data-tinyfly-start")??"0")||0,r=s.getAttribute("data-volume");r!==null&&(s.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:s,startTime:n,sync:new gt(s)})})}syncAllMedia(t,e){for(const s of this.mediaTargets)Gt(s.sync,s.el,t,e,s.startTime)}loadFromString(t){const e=JSON.parse(t);this.load(e)}registerTarget(t,e){if(typeof e=="string"){const s=this.container.querySelector(e);s&&(this.rememberAuthored(s),this.targets[t]=s,this.adapter.registerTarget(t,s))}else this.rememberAuthored(e),this.targets[t]=e,this.adapter.registerTarget(t,e)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(e=>{const s=e.closest("[data-tinyfly-symbol]");if(s&&s!==e)return;const n=e.getAttribute("data-tinyfly");n&&this.registerTarget(n,e)}),this.timeline&&new Set(this.timeline.tracks.map(s=>s.target)).forEach(s=>{if(!this.targets[s]){const n=this.container.querySelector(`[data-tinyfly="${s}"]`)||this.container.querySelector(`.${s}`)||this.container.querySelector(`#${s}`);n&&this.registerTarget(s,n)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const e=new Map(t.map(s=>[s.id,s]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const n=s.getAttribute("data-tinyfly-symbol");if(!n)return;const r=e.get(n);if(!r||!r.timeline.tracks?.length)return;const a=new 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.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=e=>{if(this.isDestroyed||!this.timeline)return;const s=e-(this.lastTime??e);this.lastTime=e;const n=this.playhead;this.timeline.tick(s),this.stopAtMarker(n),this.applyState();const r=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,r),this.syncAllMedia(this.timeline.currentTime,r),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(t):(this.animationFrameId=void 0,this.notify())};this.animationFrameId=requestAnimationFrame(t)}stopAtMarker(t){const e=this.timeline,s={time:e.currentTime,iteration:e.loopIteration,direction:e.direction};this.playhead=s;const n=this.markers;if(n.length===0)return;const{crossings:r}=mi(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 Bi(i,t,e={}){const s=new yt(i,{...e,autoplay:!0});return await s.load(t),s}function Oi(i,t={}){return new yt(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 Li(i,t,e={}){const s=new Zt(i,{...e,autoplay:!0});return await s.load(t),s}const $i={type:"none",duration:0};R.DEFAULT_TRANSITION=$i,R.MediaSync=gt,R.TinyflyPlayer=yt,R.TinyflySequencer=Zt,R.create=Oi,R.play=Bi,R.playSequence=Li,R.syncMediaElement=Gt,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})})(this.tinyfly=this.tinyfly||{});
|
|
2
|
+
`?T+=M:T+=p[ui(m,b,d)%p.length]}return T}class fi{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}get drawingRate(){return this._config.drawingRate??0}set drawingRate(t){const e={...this._config};t>0?e.drawingRate=t:delete e.drawingRate,this._config=e}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(t=re(t,this._config.drawingRate??0),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,g=s.get(u);(!g||(l!==g.started?l:l?h>=g.start:h<=g.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",di(c.textConfig,r,Math.max(0,a)));return}const h=this._motionPathTracks.get(e);if(h&&typeof r=="number"){const u=ci(h.motionPathConfig,r);o.set("motionPathX",u.x),o.set("motionPathY",u.y),h.motionPathConfig.autoRotate&&o.set("motionPathRotate",u.angle)}else o.set(n,r)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const t=new Set;this._sharedWrites=!1;t:for(const e of this._tracks)for(const s of L(e)){const n=`${s}\0${e.property}`;if(t.has(n)){this._sharedWrites=!0;break t}t.add(n)}}return this._sharedWrites}addTrack(t){if(this._tracks.push(t),this._sharedWrites=null,st(t)){this._trackPlayers.set(t.id,new oi(t));return}if(nt(t)){this._trackPlayers.set(t.id,new ai(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(ne(t)){const e={id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,delay:t.delay,endDelay:t.endDelay,targets:t.targets,stagger:t.stagger};this._trackPlayers.set(t.id,new 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=L(a).filter(l=>L(s).includes(l));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=n.to&&n.from<=c.to))continue;const u=n.from>=c.from;for(const l of o)t.push({target:l,property:s.property,losingTrackId:u?a.id:s.id,winningTrackId:u?s.id:a.id})}}return t}_matches(t,e){if(e.id!==void 0&&t.id!==e.id||e.property!==void 0&&t.property!==e.property||e.target!==void 0&&!L(t).includes(e.target))return!1;if(e.timeRange){const s=this.getTrackSpan(t.id);if(!s||s.to<e.timeRange.from||s.from>e.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:se(this._tracks),id:this.id,name:this.name,config:{...this._config},tracks:[...this._tracks],...this.captions&&{captions:this.captions}}}get config(){return this._config}get markers(){return[...this._config.markers??[]].sort((t,e)=>t.time-e.time)}setMarkers(t){const e=t&&t.length>0?[...t].sort((n,r)=>n.time-r.time).map(n=>({...n})):void 0,s={...this._config};e?s.markers=e:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(t){const e={};for(const[s,n]of Object.entries(t??{}))e[s]={...n};this._captions=Object.keys(e).length>0?e:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let t=0;for(const[,e]of this._trackPlayers)t=Math.max(t,e.getDuration());return t}_handleEndReached(){const t=this._config.loop??0;return t===-1||this._loopIteration<t?(this._loopIteration++,this._armRepeatDelay(),this._config.alternate?this._direction="reverse":this._repeatDelayRemaining>0?this._wrapAfterDelay=!0:this._currentTime=0,this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}_handleStartReached(){const t=this._config.loop??0;return this._config.alternate&&(t===-1||this._loopIteration<t)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const pi=100;function mi(i,t,e,s){const n=[],r=[],{duration:a,alternate:o}=s,c=(p,f,d,m)=>{r.push([p,f]);const T=[];i.forEach((b,A)=>{(d==="forward"?(m?b>=p:b>p)&&b<=f:(m?b<=p:b<p)&&b>=f)&&T.push(A)}),T.sort((b,A)=>(d==="forward"?i[b]-i[A]:i[A]-i[b])||b-A);for(const b of T)n.push({kind:"event",index:b,direction:d})};let h=t.time,u=t.direction,l=t.fresh===!0;const g=Math.min(pi,Math.max(0,e.iteration-t.iteration));for(let p=0;p<g;p++){const f=u==="forward"?a:0;c(h,f,u,l),n.push({kind:"repeat"}),o?(u=u==="forward"?"reverse":"forward",h=f,l=!1):(h=u==="forward"?0:a,l=!0)}return g>0&&s.holding&&!o?{crossings:n,passes:r}:(c(h,e.time,u,l),{crossings:n,passes:r})}function gi(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 yi(i){if(st(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:gi(t.inertia),...H(t)}}if(nt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...H(t)}}if(St(i)){const t=i;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((e,s)=>e.time-s.time),...H(t)}}if(i.property==="motionPath"&&"motionPathConfig"in i){const t=i,e=[...t.keyframes].sort((s,n)=>s.time-n.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:e,...H(t)}}return ri({id:i.id,target:i.target,property:i.property,keyframes:i.keyframes,...i.interpolation!==void 0&&{interpolation:i.interpolation},...H(i)})}function J(i){const t=i.formatVersion??1;if(t>At)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${At}. Update tinyfly to play it.`);return new fi({id:i.id,name:i.name,config:i.config,tracks:i.tracks.map(yi),captions:i.captions})}function Ti(i){const[t,e,s,n]=i;return[1-2*(e*e+s*s),2*(t*e+s*n),2*(t*s-e*n),0,2*(t*e-s*n),1-2*(t*t+s*s),2*(e*s+t*n),0,2*(t*s+e*n),2*(e*s-t*n),1-2*(t*t+e*e),0,0,0,0,1]}function bi(i){return!Array.isArray(i)||i.length!==4?null:`matrix3d(${Ti(U(i)).map(e=>Math.round(e*1e6)/1e6+0).join(", ")})`}const Ai=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),Si="#ffffff",Mi="rgba(0, 0, 0, 0.5)";function _i(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??Si})`),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??Mi})`)}return t.length>0?t.join(" "):null}function ki(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 wi(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"]),Pi=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),vi=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],Ii=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),xi=new Set(["originX","originY"]),Ci=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Ri=new Set(["drawOn"]),Di={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"},Ei="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){let s=null,n=null,r=null,a=null,o=null;const c=e.has("motionPathX"),h=e.has("motionPathY"),u=e.has("motionPathRotate");for(const[f,d]of e)if(!(f==="x"&&c)&&!(f==="y"&&h)&&!((f==="rotate"||f==="rotateZ")&&u)&&!Ri.has(f)){if(Pi.has(f))(s??={})[f]=d;else if(Ii.has(f))typeof d=="number"&&((n??={})[f]=d);else if(xi.has(f))typeof d=="number"&&((r??={})[f]=d);else if(Ci.has(f))typeof d=="number"&&((a??={})[f]=d);else if(Ai.has(f))(o??={})[f]=d;else if(f!=="perspective"){if(f!=="shine")if(f==="text"&&typeof d=="string")ki(t,d);else if(f==="d"&&typeof d=="string"){const m=t;(m.tagName?.toLowerCase()==="path"?m:m.querySelector?.("path"))?.setAttribute?.("d",d)}else this.applyStyleProperty(t,f,d)}}const l=e.get("shine");typeof l=="number"&&this.applyShine(t,l);const g=[],p=e.get("perspective");if(typeof p=="number"&&p>0&&g.push(`perspective(${p}px)`),s)for(const f of vi){const d=s[f];if(d===void 0)continue;const m=this.buildTransformPart(f,d);m&&g.push(m)}if(g.length>0&&(t.style.transform=g.join(" "),wi(t)),n&&(n.childPerspective!==void 0&&(t.style.perspective=`${n.childPerspective}px`),(n.perspectiveOriginX!==void 0||n.perspectiveOriginY!==void 0)&&(t.style.perspectiveOrigin=`${n.perspectiveOriginX??50}% ${n.perspectiveOriginY??50}%`)),r){const f=r.originX??50,d=r.originY??50;t.style.transformOrigin=`${f}% ${d}%`}if(a){const f=a.clipTop??0,d=a.clipRight??0,m=a.clipBottom??0,T=a.clipLeft??0;t.style.clipPath=`inset(${f}% ${d}% ${m}% ${T}%)`}if(o){const f=_i(o);f&&(t.style.filter=f)}}buildTransformPart(t,e){if(t==="quaternion")return bi(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===Ei&&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=Di[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 yt{container;timeline=null;adapter;animationFrameId;lastTime;options;targets={};isDestroyed=!1;mediaSync;mediaTargets=[];symbolInstances=[];scenarioList=[];scenarioId;authored=new Map;markerList=[];listeners=new Set;playhead={time:0,iteration:0,direction:"forward"};stepping=!1;lastMarkerId=null;reducedQuery;onReducedChange=()=>this.applyReducedMotion();visibilityObserver;onScreen=!0;pausedByVisibility=!1;autoplayWhenSeen=!1;onDocumentVisibility=()=>this.updateVisibility();constructor(t,e={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=e,this.adapter=new Q}async load(t){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(t)}async loadSource(t){let e;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load animation: ${s.statusText}`);e=await s.json()}else e=t;this.useDefinition(e),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(t){const e={...t.config};this.options.speed!==void 0&&(e.speed=this.options.speed),this.options.loop!==void 0&&(e.loop=this.options.loop),this.options.alternate!==void 0&&(e.alternate=this.options.alternate),this.timeline=J({...t,config:e}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(t,e={}){if(t.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const s=new Set;for(const r of t){if(s.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);s.add(r.id)}const n=e.initial===void 0?t[0]:t.find(r=>r.id===e.initial);if(!n)throw new Error(`tinyfly: there is no scenario "${e.initial}"`);this.scenarioList=[...t],this.scenarioId=n.id,await this.loadSource(n.timeline)}get scenarios(){return this.scenarioList.map(t=>({id:t.id,label:t.label??t.id}))}get scenario(){return this.scenarioId}setScenario(t){const e=this.scenarioList.find(o=>o.id===t);if(!e||!this.timeline)return!1;if(t===this.scenarioId)return!0;const s=this.isPlaying,n=this.currentTime>=this.duration-.5,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=t,this.useDefinition(e.timeline),this.lastMarkerId=null;let a=0;return this.reducedMotion||n?a=this.duration:r!==void 0&&(a=this.markers.find(o=>o.id===r)?.time??0),this.seek(a),s&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(t){if(this.authored.has(t))return;const e={style:t.getAttribute("style")};t.children.length===0&&(e.text=t.textContent??"");const s=t.tagName.toLowerCase()==="path"?t:t.querySelector("path");s&&(e.path={element:s,d:s.getAttribute("d")}),this.authored.set(t,e)}restoreAuthored(){for(const[t,e]of this.authored){e.style===null?t.removeAttribute("style"):t.setAttribute("style",e.style),e.text!==void 0&&t.textContent!==e.text&&(t.textContent=e.text),e.path&&(e.path.d===null?e.path.element.removeAttribute("d"):e.path.element.setAttribute("d",e.path.d));const s=t.dataset;s&&delete s.shineBase}}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notify(){for(const t of this.listeners)t()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const t=this.currentTime;let e;for(const s of this.markers)if(s.time<=t+.5)e=s;else break;return e}caption(t,e){const s=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!s)return;const n=e??this.language(),r=a=>a?.[n]?.[s.id]??a?.[n.split("-")[0]]?.[s.id];return r(this.options.captions)??r(this.timeline?.captions)??s.label}next(){if(!this.timeline)return;const t=this.currentTime,e=this.markers.find(s=>s.time>t+.5);if(this.reducedMotion){this.seek(e?e.time:this.duration);return}t>=this.duration-.5||(this.stepping=e!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const t=this.currentTime,e=[...this.markers].reverse().find(s=>s.time<t-.5);this.pause(),this.seek(e?e.time:0)}goToMarker(t){const e=this.markers.find(s=>s.id===t);e&&(this.pause(),this.seek(e.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const t=this.options.initialFrame??"start";if(t==="none")return;const e=t==="end"?this.timeline.duration:t==="start"?0:t;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,e))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(e=>{for(const s of e)this.onScreen=s.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const t=this.container.getBoundingClientRect?.();t&&(t.width>0||t.height>0)&&(this.onScreen=t.bottom>0&&t.top<window.innerHeight&&t.right>0&&t.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const t=this.onScreen&&document.visibilityState!=="hidden";!t&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):t&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const t=this.currentMarker,e=t?.id;e!==this.lastMarkerId&&(this.lastMarkerId=e,this.options.onMarker(t))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(e=>{const s=e,n=Number(s.getAttribute("data-tinyfly-start")??"0")||0,r=s.getAttribute("data-volume");r!==null&&(s.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:s,startTime:n,sync:new gt(s)})})}syncAllMedia(t,e){for(const s of this.mediaTargets)Gt(s.sync,s.el,t,e,s.startTime)}loadFromString(t){const e=JSON.parse(t);this.load(e)}registerTarget(t,e){if(typeof e=="string"){const s=this.container.querySelector(e);s&&(this.rememberAuthored(s),this.targets[t]=s,this.adapter.registerTarget(t,s))}else this.rememberAuthored(e),this.targets[t]=e,this.adapter.registerTarget(t,e)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(e=>{const s=e.closest("[data-tinyfly-symbol]");if(s&&s!==e)return;const n=e.getAttribute("data-tinyfly");n&&this.registerTarget(n,e)}),this.timeline&&new Set(this.timeline.tracks.map(s=>s.target)).forEach(s=>{if(!this.targets[s]){const n=this.container.querySelector(`[data-tinyfly="${s}"]`)||this.container.querySelector(`.${s}`)||this.container.querySelector(`#${s}`);n&&this.registerTarget(s,n)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const e=new Map(t.map(s=>[s.id,s]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const n=s.getAttribute("data-tinyfly-symbol");if(!n)return;const r=e.get(n);if(!r||!r.timeline.tracks?.length)return;const a=new 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 state(){return this.timeline?.getStateAtTime(this.timeline.currentTime)}get duration(){return this.timeline?.duration??0}get isPlaying(){return this.timeline?.playbackState==="playing"}destroy(){this.isDestroyed=!0,this.stopAnimationLoop(),this.reducedQuery?.removeEventListener?.("change",this.onReducedChange),this.visibilityObserver?.disconnect(),typeof document<"u"&&document.removeEventListener("visibilitychange",this.onDocumentVisibility),this.mediaSync?.dispose(),this.mediaSync=void 0;for(const t of this.mediaTargets)t.el.paused||t.el.pause();this.mediaTargets=[],this.adapter.clearTargets();for(const t of this.symbolInstances)t.adapter.clearTargets();this.symbolInstances=[],this.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=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}=mi(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 Bi(i,t,e={}){const s=new yt(i,{...e,autoplay:!0});return await s.load(t),s}function Oi(i,t={}){return new yt(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 Li(i,t,e={}){const s=new Zt(i,{...e,autoplay:!0});return await s.load(t),s}const $i={type:"none",duration:0};R.DEFAULT_TRANSITION=$i,R.MediaSync=gt,R.TinyflyPlayer=yt,R.TinyflySequencer=Zt,R.create=Oi,R.play=Bi,R.playSequence=Li,R.syncMediaElement=Gt,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})})(this.tinyfly=this.tinyfly||{});
|