@algorisys/tinyfly 0.89.0 → 0.91.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 +5 -5
- package/lib/addons/adapters.js +24 -19
- package/lib/addons/camera-C7bZOWMB.js +33 -0
- package/lib/addons/characters.js +1929 -1622
- package/lib/browser/tinyfly.iife.js +4 -4
- package/lib/browser/tinyfly.js +4882 -4484
- package/lib/browser/tinyfly.umd.js +4 -4
- package/lib/cli/tools.js +16 -0
- package/lib/embed/tinyfly-embed.iife.js +4 -4
- package/lib/embed/tinyfly-embed.js +216 -203
- package/lib/engine/tinyfly-engine.js +849 -783
- package/lib/engine/tinyfly-engine.umd.cjs +2 -2
- package/lib/headless/headless.js +39 -3
- package/lib/player/tinyfly-player.es.js +183 -170
- package/lib/player/tinyfly-player.iife.js +2 -2
- package/lib/player/tinyfly-player.umd.js +2 -2
- package/lib/types/adapters/canvas/camera.d.ts +46 -0
- package/lib/types/adapters/canvas/index.d.ts +1 -0
- package/lib/types/browser/index.d.ts +2 -0
- package/lib/types/characters/acting/index.d.ts +2 -0
- package/lib/types/characters/acting/lip-sync.d.ts +115 -0
- package/lib/types/characters/acting/script.d.ts +94 -0
- package/lib/types/characters/gaits.d.ts +141 -0
- package/lib/types/characters/index.d.ts +2 -0
- package/lib/types/characters/stick-figure.d.ts +15 -0
- package/lib/types/engine/authoring/camera-shots.d.ts +73 -0
- package/lib/types/engine/authoring/index.d.ts +1 -0
- package/lib/types/engine/core/timeline.d.ts +3 -0
- package/lib/types/engine/types.d.ts +6 -0
- package/lib/types/headless/video-scene.d.ts +14 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(v,N){typeof exports=="object"&&typeof module<"u"?N(exports):typeof define=="function"&&define.amd?define(["exports"],N):(v=typeof globalThis<"u"?globalThis:v||self,N(v.tinyfly=v.tinyfly||{}))})(this,(function(v){"use strict";function N(i){return typeof i=="object"&&i!==null&&i.type==="cubic-bezier"}function ie(i){return typeof i=="object"&&i!==null&&i.type!=="cubic-bezier"}const St=2;function se(i){return i.some(t=>t.interpolation!==void 0)?2:1}function Mt(i){return i.property==="text"&&"textConfig"in i}function nt(i){return i.kind==="inertia"&&"inertia"in i}function rt(i){return i.kind==="spring"&&"spring"in i}function ne(i){return i.property==="motionPath"&&"motionPathConfig"in i}function _t(i,t,e="start"){if(t<=1)return 0;if(typeof e=="number"){const s=Math.max(0,Math.min(t-1,e));return Math.abs(i-s)}switch(e){case"end":return t-1-i;case"center":return Math.abs(i-(t-1)/2);case"edges":return(t-1)/2-Math.abs(i-(t-1)/2);default:return i}}function re(i,t="start"){if(i<=1)return 0;let e=0;for(let s=0;s<i;s++)e=Math.max(e,_t(s,i,t));return e}function kt(i,t,e){if(e.offsets)return e.offsets[i]??0;const s=e.from??"start",n=_t(i,t,s);if(e.amount!==void 0){const r=re(t,s);return r===0?0:e.amount*n/r}return e.each!==void 0?e.each*n:0}function ae(i,t){return Array.from({length:i},(e,s)=>kt(s,i,t))}function at(i,t){return i<=1?0:Math.max(...ae(i,t))}const q=1,wt=6e4,G=wt/q,X={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1};class oe{from;to;stiffness;damping;mass;restDelta;restSpeed;distance;samples;velocity;settledStep=null;constructor(t){this.from=t.from,this.to=t.to,this.stiffness=t.stiffness??X.stiffness,this.damping=t.damping??X.damping,this.mass=t.mass??X.mass,this.restDelta=t.restDelta??X.restDelta,this.restSpeed=t.restSpeed??X.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=t.velocity??X.velocity,this.isAtRest(this.from)&&(this.settledStep=0)}isAtRest(t){return Math.abs(t-this.to)<this.restDelta*this.distance&&Math.abs(this.velocity)<this.restSpeed*this.distance}valueAt(t){if(t<=0)return this.from;const e=Math.floor(t/q);if(this.simulateTo(e+1),this.settledStep!==null&&e>=this.settledStep)return this.to;const s=this.samples[Math.min(e,this.samples.length-1)],n=this.samples[Math.min(e+1,this.samples.length-1)],r=t/q-e;return s+(n-s)*r}settleTime(){return this.simulateTo(G+1),this.settledStep!==null?this.settledStep*q:wt}simulateTo(t){if(this.settledStep!==null)return;const e=Math.min(t,G+1),s=q/1e3;for(;this.samples.length<e;){const n=this.samples[this.samples.length-1],r=n-this.to,a=-this.stiffness*r,o=-this.damping*this.velocity,c=(a+o)/this.mass;this.velocity+=c*s;const h=n+this.velocity*s;if(this.samples.push(h),this.isAtRest(h)){this.settledStep=this.samples.length-1;return}}this.samples.length>G&&(this.settledStep=G)}}const Pt=4,ce=.002,he=1e-4,le=6e4;function ot(i){const t=i.friction??Pt;return t>0?t:Pt}function ue(i){return i.from+i.velocity/ot(i)}function de(i,t){if(t===void 0)return i;if(typeof t=="number")return t>0?Math.round(i/t)*t:i;if(t.length===0)return i;let e=t[0];for(const s of t)Math.abs(s-i)<Math.abs(e-i)&&(e=s);return e}function vt(i){let t=de(ue(i),i.end);return i.min!==void 0&&(t=Math.max(i.min,t)),i.max!==void 0&&(t=Math.min(i.max,t)),t}function xt(i){const t=Math.abs(vt(i)-i.from);if(t===0)return 0;const e=i.restDelta??Math.max(he,t*ce);if(e>=t)return 0;const s=Math.log(t/e)/ot(i);return Math.min(le,s*1e3)}function It(i,t){if(t<=0)return i.from;const e=vt(i);if(t>=xt(i))return e;const s=ot(i);return i.from+(e-i.from)*(1-Math.exp(-s*t/1e3))}const ct=i=>i,fe=i=>i*i,pe=i=>1-(1-i)*(1-i),me=i=>i<.5?2*i*i:1-Math.pow(-2*i+2,2)/2,Ct=i=>i*i*i,Rt=i=>1-Math.pow(1-i,3),Dt=i=>i<.5?4*i*i*i:1-Math.pow(-2*i+2,3)/2,ye={linear:ct,"ease-in":Ct,"ease-out":Rt,"ease-in-out":Dt,"ease-in-quad":fe,"ease-out-quad":pe,"ease-in-out-quad":me,"ease-in-cubic":Ct,"ease-out-cubic":Rt,"ease-in-out-cubic":Dt};function ge(i){const[t,e,s,n]=i,r=3*t,a=3*(s-t)-r,o=1-r-a,c=3*e,h=3*(n-e)-c,u=1-c-h,l=d=>((o*d+a)*d+r)*d,y=d=>((u*d+h)*d+c)*d,p=d=>(3*o*d+2*a)*d+r,f=d=>{let m=d;for(let A=0;A<8;A++){const M=l(m)-d;if(Math.abs(M)<1e-7)return m;const g=p(m);if(Math.abs(g)<1e-7)break;m-=M/g}let T=0,b=1;for(m=d;T<b;){const A=l(m);if(Math.abs(A-d)<1e-7)return m;d>A?T=m:b=m,m=(T+b)/2}return m};return d=>{if(d<=0)return 0;if(d>=1)return 1;const m=f(d);return y(m)}}function ht(i,t="out"){if(t==="out")return i;const e=s=>1-i(1-s);return t==="in"?e:s=>s<.5?e(s*2)/2:i(s*2-1)/2+.5}function Te(i=1,t=.3){const e=Math.max(1,i),s=t/(2*Math.PI)*Math.asin(1/e);return n=>n<=0?0:n>=1?1:e*Math.pow(2,-10*n)*Math.sin((n-s)*(2*Math.PI)/t)+1}const be=i=>{if(i<=0)return 0;if(i>=1)return 1;if(i<1/2.75)return 7.5625*i*i;if(i<2/2.75){const n=i-.5454545454545454;return 7.5625*n*n+.75}if(i<2.5/2.75){const n=i-.8181818181818182;return 7.5625*n*n+.9375}const s=i-2.625/2.75;return 7.5625*s*s+.984375};function Ae(i=1.70158){return t=>{if(t<=0)return 0;if(t>=1)return 1;const e=t-1;return e*e*((i+1)*e+i)+1}}function Se(i,t="end"){const e=Math.max(1,Math.floor(i));return s=>{if(s>=1)return 1;if(s<=0)return t==="start"||t==="both"?t==="start"?1/e:1/(e+1):0;const n=Math.floor(s*e);switch(t){case"start":return Math.min(1,(n+1)/e);case"both":return(n+1)/(e+1);case"none":return e===1?0:Math.min(1,n/(e-1));default:return n/e}}}function Me(i){switch(i.type){case"steps":return Se(i.count,i.position);case"elastic":return ht(Te(i.amplitude,i.period),i.mode);case"bounce":return ht(be,i.mode);case"back":return ht(Ae(i.overshoot),i.mode)}}function _e(i){return i===void 0?ct:N(i)?ge(i.points):ie(i)?Me(i):ye[i]??ct}const Et=32,ke=256,V=new Map,we=/[MmLlHhVvCcSsQqTtAaZz]/,Pe=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,ve={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function xe(i){const t=[];let e=0,s=null;const n=()=>{for(;e<i.length&&/[\s,]/.test(i[e]);)e++};for(;e<i.length&&(n(),!(e>=i.length));){const r=i[e];if(we.test(r)){s={type:r,args:[]},t.push(s),e++;continue}if(!s)break;const a=s.type==="A"||s.type==="a",o=s.args.length%7;if(a&&(o===3||o===4)){if(r!=="0"&&r!=="1")break;s.args.push(r==="1"?1:0),e++;continue}const c=Pe.exec(i.slice(e));if(!c)break;s.args.push(parseFloat(c[0])),e+=c[0].length}return t}function Ie(i,t,e,s,n,r,a,o,c){if(i===o&&t===c)return[];let h=Math.abs(e),u=Math.abs(s);if(h===0||u===0)return[[i,t,o,c,o,c]];const l=n*Math.PI/180,y=Math.cos(l),p=Math.sin(l),f=(i-o)/2,d=(t-c)/2,m=y*f+p*d,T=-p*f+y*d,b=m*m/(h*h)+T*T/(u*u);if(b>1){const w=Math.sqrt(b);h*=w,u*=w}const A=r===a?-1:1,M=h*h*u*u-h*h*T*T-u*u*m*m,g=h*h*T*T+u*u*m*m,_=A*Math.sqrt(Math.max(0,M/g)),S=_*h*T/u,E=-_*u*m/h,et=y*S-p*E+(i+o)/2,k=p*S+y*E+(t+c)/2,C=(w,I,R,Y)=>{const At=w*R+I*Y,st=Math.sqrt((w*w+I*I)*(R*R+Y*Y)),z=Math.acos(Math.max(-1,Math.min(1,At/st)));return w*Y-I*R<0?-z:z},P=C(1,0,(m-S)/h,(T-E)/u);let x=C((m-S)/h,(T-E)/u,(-m-S)/h,(-T-E)/u);!a&&x>0&&(x-=2*Math.PI),a&&x<0&&(x+=2*Math.PI);const $=Math.max(1,Math.ceil(Math.abs(x)/(Math.PI/2))),bt=x/$,it=4/3*Math.tan(bt/4),Jt=w=>{const I=h*Math.cos(w),R=u*Math.sin(w);return[y*I-p*R+et,p*I+y*R+k]},te=w=>{const I=-h*Math.sin(w),R=u*Math.cos(w);return[y*I-p*R,p*I+y*R]},ee=[];for(let w=0;w<$;w++){const I=P+w*bt,R=I+bt,[Y,At]=Jt(I),[st,z]=w===$-1?[o,c]:Jt(R),[$i,Xi]=te(I),[Fi,Yi]=te(R);ee.push([Y+it*$i,At+it*Xi,st-it*Fi,z-it*Yi,st,z])}return ee}function B(i,t,e,s,n){const r=1-n;return r*r*r*i+3*r*r*n*t+3*r*n*n*e+n*n*n*s}function Bt(i,t,e,s,n){const r=1-n;return 3*r*r*(t-i)+6*r*n*(e-t)+3*n*n*(s-e)}function W(i,t,e,s){return{subpath:0,type:"L",points:[e,s],startX:i,startY:t,endX:e,endY:s,length:Math.hypot(e-i,s-t)}}function Z(i,t,e){const[s,n,r,a,o,c]=e,h=[0];let u=i,l=t,y=0;for(let p=1;p<=Et;p++){const f=p/Et,d=B(i,s,r,o,f),m=B(t,n,a,c,f);y+=Math.hypot(d-u,m-l),h.push(y),u=d,l=m}return{subpath:0,type:"C",points:[s,n,r,a,o,c],startX:i,startY:t,endX:o,endY:c,length:y,lengths:h}}function K(i){const t=V.get(i);if(t)return t;const e=[];let s=0,n=0,r=0,a=0,o=null,c=null,h=-1;const u=new Set,l=d=>{h<0&&(h=0),d.subpath=h,e.push(d)};for(const{type:d,args:m}of xe(i)){const T=d.toUpperCase(),b=d!==T,A=ve[T];if(T==="Z"){(s!==r||n!==a)&&l(W(s,n,r,a)),h>=0&&u.add(h),s=r,n=a,o=c=null;continue}for(let M=0;M+A<=m.length;M+=A){const g=m.slice(M,M+A),_=b?s:0,S=b?n:0;let E=null,et=null;switch(T){case"M":M===0?(s=g[0]+_,n=g[1]+S,r=s,a=n,(h<0||e[e.length-1]?.subpath===h)&&h++):(l(W(s,n,g[0]+_,g[1]+S)),s=g[0]+_,n=g[1]+S);break;case"L":l(W(s,n,g[0]+_,g[1]+S)),s=g[0]+_,n=g[1]+S;break;case"H":l(W(s,n,g[0]+_,n)),s=g[0]+_;break;case"V":l(W(s,n,s,g[0]+S)),n=g[0]+S;break;case"C":{const k=[g[0]+_,g[1]+S,g[2]+_,g[3]+S,g[4]+_,g[5]+S];l(Z(s,n,k)),E=[k[2],k[3]],s=k[4],n=k[5];break}case"S":{const[k,C]=o?[2*s-o[0],2*n-o[1]]:[s,n],P=[k,C,g[0]+_,g[1]+S,g[2]+_,g[3]+S];l(Z(s,n,P)),E=[P[2],P[3]],s=P[4],n=P[5];break}case"Q":case"T":{let k=s,C=n;T==="Q"?(k=g[0]+_,C=g[1]+S):c&&(k=2*s-c[0],C=2*n-c[1]);const P=T==="Q"?g[2]+_:g[0]+_,x=T==="Q"?g[3]+S:g[1]+S;l(Z(s,n,[s+2/3*(k-s),n+2/3*(C-n),P+2/3*(k-P),x+2/3*(C-x),P,x])),et=[k,C],s=P,n=x;break}case"A":{const k=g[5]+_,C=g[6]+S;let P=s,x=n;for(const $ of Ie(s,n,g[0],g[1],g[2],g[3],g[4],k,C))l(Z(P,x,$)),P=$[4],x=$[5];s=k,n=C;break}}o=E,c=et}}const y=e.reduce((d,m)=>d+m.length,0),p=[];for(let d=0;d<e.length;){const m=e[d].subpath;let T=d,b=0;for(;T<e.length&&e[T].subpath===m;)b+=e[T++].length;const A=e[d],M=e[T-1],g=u.has(m)||Math.abs(M.endX-A.startX)<1e-9&&Math.abs(M.endY-A.startY)<1e-9;p.push({start:d,end:T,length:b,closed:g}),d=T}const f={segments:e,totalLength:y,subpaths:p};return V.size>=ke&&V.delete(V.keys().next().value),V.set(i,f),f}function Ce(i,t){const e=i.lengths;if(t<=0)return 0;if(t>=i.length)return 1;let s=0,n=e.length-1;for(;s<n-1;){const o=s+n>>1;e[o]<t?s=o:n=o}const r=e[n]-e[s],a=r>0?(t-e[s])/r:0;return(s+a)/(e.length-1)}function Re(i,t){if(i.type==="L"){const l=i.length>0?Math.max(0,Math.min(1,t/i.length)):0;return{x:i.startX+(i.endX-i.startX)*l,y:i.startY+(i.endY-i.startY)*l,angle:Math.atan2(i.endY-i.startY,i.endX-i.startX)*180/Math.PI}}const[e,s,n,r,a,o]=i.points,c=Ce(i,t);let h=Bt(i.startX,e,n,a,c),u=Bt(i.startY,s,r,o,c);if(Math.hypot(h,u)<1e-9){const l=c<.5?Math.min(1,c+.001):Math.max(0,c-.001),y=B(i.startX,e,n,a,l),p=B(i.startY,s,r,o,l),f=B(i.startX,e,n,a,c),d=B(i.startY,s,r,o,c);h=c<.5?y-f:f-y,u=c<.5?p-d:d-p}return{x:B(i.startX,e,n,a,c),y:B(i.startY,s,r,o,c),angle:Math.atan2(u,h)*180/Math.PI}}function Ot(i,t,e=0,s=i.length){if(s<=e)return{x:0,y:0,angle:0};let n=0;for(let r=e;r<s;r++){const a=i[r];if(n+a.length>=t||r===s-1)return Re(a,t-n);n+=a.length}return{x:0,y:0,angle:0}}function De(i,t){const{segments:e,totalLength:s}=K(i);return Ot(e,Math.max(0,Math.min(1,t))*s)}const Ee=24,Be=320,Oe=2.5,U=72,Le=.2,$e=128,J=new Map;let lt=0,O;const Lt=i=>Math.round(i*100)/100;function $t(i,t){const{segments:e,subpaths:s,totalLength:n}=K(i);if(e.length===0)return[];if(t){const r=s.every(a=>a.closed);return[{segments:e,start:0,end:e.length,length:n,closed:r}]}return s.filter(r=>r.length>0).map(r=>({segments:e,start:r.start,end:r.end,length:r.length,closed:r.closed}))}function ut(i,t){const e=i.closed?(t%1+1)%1:Math.max(0,Math.min(1,t)),s=Ot(i.segments,e*i.length,i.start,i.end);return[s.x,s.y]}function Xt(i){const t=[];let e=0;for(let s=i.start;s<i.end;s++)e+=i.segments[s].length,i.length>0&&t.push(e/i.length);return t}function Ft(i,t){const e=[];for(let s=0;s<t;s++)e.push(ut(i,i.closed?s/t:s/(t-1)));return e}function Yt(i){let t=0,e=0;for(const[s,n]of i)t+=s,e+=n;return t/=i.length,e/=i.length,i.map(([s,n])=>[s-t,n-e])}function Xe(i,t,e){const s=i.closed&&t.closed;if(e!==void 0)return{offset:s?Math.abs(e)%U/U:0,reversed:e<0};const n=Yt(Ft(i,U)),r=Yt(Ft(t,U)),a=U;let o={offset:0,reversed:!1},c=1/0;for(const h of[!1,!0]){const u=s?a:1;for(let l=0;l<u;l++){let y=0;for(let p=0;p<a&&y<c;p++){const f=s?h?(l-p+a)%a:(p+l)%a:h?a-1-p:p,d=n[p][0]-r[f][0],m=n[p][1]-r[f][1];y+=d*d+m*m}y<c&&(c=y,o={offset:s?l/a:0,reversed:h})}}return o}function Fe(i,t,e){return e?((t.reversed?t.offset-i:i+t.offset)%1+1)%1:t.reversed?1-i:i}function Ye(i,t,e){return e?((t.reversed?t.offset-i:i-t.offset)%1+1)%1:t.reversed?1-i:i}function Ne(i,t,e){const s=i.closed&&t.closed,n=Xe(i,t,e.shapeIndex),r=Math.max(Ee,Math.min(Be,Math.ceil(Math.max(i.length,t.length)/Oe))),a=new Set,o=l=>a.add(Math.round(l*1e7)/1e7);for(let l=0;l<=r;l++)o(l/r);for(const l of Xt(i))o(l);for(const l of Xt(t))o(Ye(l,n,s));let c=[...a].sort((l,y)=>l-y);s&&(c=c.filter(l=>l<1));const h=[],u=[];for(const l of c)h.push(...ut(i,l)),u.push(...ut(t,Fe(l,n,s)));return qe({from:h,to:u,closed:s})}function qe(i){const t=i.from.length/2;if(t<=3)return i;const e=new Uint8Array(t);e[0]=1,e[t-1]=1;const s=[[0,t-1]];for(;s.length>0;){const[a,o]=s.pop();let c=-1,h=Le;for(let u=a+1;u<o;u++){const l=Math.max(Nt(i.from,a,o,u),Nt(i.to,a,o,u));l>h&&(h=l,c=u)}c!==-1&&(e[c]=1,s.push([a,c],[c,o]))}const n=[],r=[];for(let a=0;a<t;a++)e[a]&&(n.push(i.from[a*2],i.from[a*2+1]),r.push(i.to[a*2],i.to[a*2+1]));return{from:n,to:r,closed:i.closed}}function Nt(i,t,e,s){const n=i[t*2],r=i[t*2+1],a=i[e*2]-n,o=i[e*2+1]-r,c=i[s*2]-n,h=i[s*2+1]-r,u=a*a+o*o,l=u===0?0:Math.max(0,Math.min(1,(c*a+h*o)/u));return Math.hypot(c-l*a,h-l*o)}function Ve(i,t,e){const s=e.shapeIndex;if(O&&O.from===i&&O.to===t&&O.shapeIndex===s)return O.plan;const r=J.get(String(s??"auto"))?.get(i)?.get(t);if(r)return O={from:i,to:t,shapeIndex:s,plan:r},r;const a=K(i).subpaths.filter(p=>p.length>0).length===K(t).subpaths.filter(p=>p.length>0).length,o=$t(i,!a),c=$t(t,!a),h={pairs:o.map((p,f)=>Ne(p,c[f],e))};lt>=$e&&(J.clear(),lt=0);const u=String(s??"auto"),l=J.get(u)??new Map;J.set(u,l);const y=l.get(i)??new Map;return l.set(i,y),y.set(t,h),lt++,O={from:i,to:t,shapeIndex:s,plan:h},h}function We(i,t,e,s={}){if(!i)return t;if(!t)return i;const n=Math.max(0,Math.min(1,e));if(n===0)return i;if(n===1)return t;const r=Ve(i,t,s);if(r.pairs.length===0)return n<.5?i:t;let a="";for(const o of r.pairs){for(let c=0;c<o.from.length;c+=2){const h=Lt(o.from[c]+(o.to[c]-o.from[c])*n),u=Lt(o.from[c+1]+(o.to[c+1]-o.from[c+1])*n);a+=`${c===0?a?" M":"M":" L"}${h} ${u}`}o.closed&&(a+=" Z")}return a}function Ue(i){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(i)}const He=.9995;function Qe(){return[0,0,0,1]}function je(i,t){return i[0]*t[0]+i[1]*t[1]+i[2]*t[2]+i[3]*t[3]}function ze(i){return Math.hypot(i[0],i[1],i[2],i[3])}function H(i){const t=ze(i);return t===0?Qe():[i[0]/t,i[1]/t,i[2]/t,i[3]/t]}function Ge(i,t,e){const s=H(i);let n=H(t),r=je(s,n);if(r<0&&(n=[-n[0],-n[1],-n[2],-n[3]],r=-r),r>He)return H([s[0]+(n[0]-s[0])*e,s[1]+(n[1]-s[1])*e,s[2]+(n[2]-s[2])*e,s[3]+(n[3]-s[3])*e]);const a=Math.acos(r),o=Math.sin(a),c=Math.sin((1-e)*a)/o,h=Math.sin(e*a)/o;return H([s[0]*c+n[0]*h,s[1]*c+n[1]*h,s[2]*c+n[2]*h,s[3]*c+n[3]*h])}const D=(i,t,e)=>i+(t-i)*e,qt=512,dt=new Map,ft=new Map;function Vt(i){const t=dt.get(i);if(t)return t;const e=i.replace("#",""),s=[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)];return dt.size<qt&&dt.set(i,s),s}const Wt=i=>i.charCodeAt(0)===35,Ut=i=>i.startsWith("rgb"),Ht=i=>i.startsWith("rgba"),Ze=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,pt=i=>Math.round(i).toString(16).padStart(2,"0");function Ke(i,t,e){return`#${pt(i)}${pt(t)}${pt(e)}`}function Qt(i){const t=ft.get(i);if(t)return t;const e=i.match(Ze);if(!e)throw new Error(`Invalid rgb color: ${i}`);const s=parseInt(e[1],10),n=parseInt(e[2],10),r=parseInt(e[3],10),a=e[4]!==void 0?[s,n,r,parseFloat(e[4])]:[s,n,r];return ft.size<qt&&ft.set(i,a),a}const Je=(i,t,e)=>{if(Wt(i)&&Wt(t)){const[s,n,r]=Vt(i),[a,o,c]=Vt(t),h=D(s,a,e),u=D(n,o,e),l=D(r,c,e);return Ke(h,u,l)}if((Ut(i)||Ht(i))&&(Ut(t)||Ht(t))){const s=Qt(i),n=Qt(t),r=Math.round(D(s[0],n[0],e)),a=Math.round(D(s[1],n[1],e)),o=Math.round(D(s[2],n[2],e));if(s.length===4||n.length===4){const c=s[3]??1,h=n[3]??1,u=D(c,h,e);return`rgba(${r}, ${a}, ${o}, ${u})`}return`rgb(${r}, ${a}, ${o})`}return e<1?i:t},ti=(i,t,e)=>{const s=Math.min(i.length,t.length),n=[];for(let r=0;r<s;r++)n.push(D(i[r],t[r],e));return n},ei=(i,t,e)=>Ge(i,t,e),jt=(i,t,e)=>e<1?i:t,ii=(i,t,e)=>We(i,t,e);function si(i,t){return t==="slerp"?ei:typeof i=="number"?D:Array.isArray(i)?ti:typeof i=="string"?i.startsWith("#")||i.startsWith("rgb")?Je:Ue(i)?ii:jt:jt}function ni(i){const t=[...i.keyframes].sort((e,s)=>e.time-s.time);return{...i,keyframes:t}}function L(i){return i.targets&&i.targets.length>0?i.targets:[i.target]}function F(i,t,e,s){const n=e??0;return!s||t<=1?n:n+kt(i,t,s)}class mt{track;targets;constructor(t){this.track=t,this.targets=L(t)}getValueAtTime(t){return this.valueForOffset(t-F(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=F(n,e,this.track.delay,this.track.stagger),a=this.valueForOffset(t-r);a!==void 0&&s.push({target:this.targets[n],value:a,start:r+this.track.keyframes[0].time})}return s}getDuration(){const{keyframes:t}=this.track;if(t.length===0)return 0;const e=t[t.length-1].time,s=this.track.stagger?at(this.targets.length,this.track.stagger):0;return e+(this.track.delay??0)+s+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(t){const{keyframes:e}=this.track;if(e.length===0)return;if(e.length===1||t<=e[0].time)return e[0].value;if(t>=e[e.length-1].time)return e[e.length-1].value;const{from:s,to:n}=this.findSurroundingKeyframes(t);if(!s||!n)return;if(s.time===t)return s.value;const r=n.time-s.time,a=(t-s.time)/r,c=_e(n.easing)(a);return si(s.value,this.track.interpolation)(s.value,n.value,c)}findSurroundingKeyframes(t){const{keyframes:e}=this.track;for(let s=0;s<e.length-1;s++)if(t>=e[s].time&&t<=e[s+1].time)return{from:e[s],to:e[s+1]};return{from:null,to:null}}}class ri{track;targets;sampler;constructor(t){this.track=t,this.targets=L(t),this.sampler=new oe(t.spring)}getValueAtTime(t){return this.sampler.valueAt(t-F(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=F(n,e,this.track.delay,this.track.stagger);s.push({target:this.targets[n],value:this.sampler.valueAt(t-r),start:r})}return s}getDuration(){const t=this.track.stagger?at(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+t}getTrack(){return this.track}}class ai{track;targets;duration;constructor(t){this.track=t,this.targets=L(t),this.duration=xt(t.inertia)}getValueAtTime(t){return It(this.track.inertia,t-F(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=F(n,e,this.track.delay,this.track.stagger);s.push({target:this.targets[n],value:It(this.track.inertia,t-r),start:r})}return s}getDuration(){const t=this.track.stagger?at(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+t}getTrack(){return this.track}}function oi(i,t){const e={...De(i.pathData,t)};if(i.matrix){const[s,n,r,a,o,c]=i.matrix,{x:h,y:u}=e;e.x=s*h+r*u+o,e.y=n*h+a*u+c;const l=e.angle*Math.PI/180,y=Math.cos(l),p=Math.sin(l);e.angle=Math.atan2(n*y+a*p,s*y+r*p)*180/Math.PI}return i.autoRotate&&i.rotateOffset&&(e.angle+=i.rotateOffset),e}const yt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},ci=20;function hi(i){const t=yt[i??"upperCase"]??i??yt.upperCase,e=Array.from(t);return e.length>0?e:Array.from(yt.upperCase)}function li(i,t,e){let s=(i|0)^Math.imul(t+1,2654435761)^Math.imul(e+1,2246822507);return s=Math.imul(s^s>>>16,2146121005),s=Math.imul(s^s>>>15,2221713035),(s^s>>>16)>>>0}function ui(i,t,e=0){const s=i.from??"",n=i.to,r=Math.max(0,Math.min(1,t));if(r<=0)return s;if(r>=1)return n;const a=Array.from(s),o=Array.from(n),c=i.rightToLeft??!1;if(i.mode==="type"){const b=Math.round(r*Math.max(a.length,o.length));return c?a.slice(0,Math.max(0,a.length-b)).join("")+o.slice(Math.max(0,o.length-b)).join(""):o.slice(0,b).join("")+a.slice(b).join("")}const h=Math.max(0,Math.min(.999,i.revealDelay??0)),u=Math.max(0,(r-h)/(1-h)),l=Math.floor(u*o.length),y=i.tweenLength===!1?o.length:Math.round(a.length+(o.length-a.length)*r),p=hi(i.chars),f=i.refreshRate??ci,d=f>0?Math.floor(e*f/1e3):0,m=i.seed??1;let T="";for(let b=0;b<y;b++){const A=c?b>=y-l:b<l,M=c?o[o.length-(y-b)]:o[b];A&&M!==void 0||M===" "||M===`
|
|
2
|
-
`?T+=M:T+=p[li(m,b,d)%p.length]}return T}class di{id;name;_captions;_tracks=[];_trackPlayers=new Map;_motionPathTracks=new Map;_springTracks=new Map;_textTracks=new Map;_config;_currentTime=0;_playbackState="idle";_direction="forward";_loopIteration=0;_explicitDuration;_repeatDelayRemaining=0;_wrapAfterDelay=!1;onUpdate=null;onComplete=null;constructor(t){if(this.id=t.id,this.name=t.name,this._captions=t.captions,this._config=t.config??{},this._explicitDuration=t.config?.duration,t.tracks)for(const e of t.tracks)this.addTrack(e)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(t){if(this._explicitDuration=t,t!==void 0)this._config={...this._config,duration:t};else if(this._config.duration!==void 0){const e={...this._config};delete e.duration,this._config=e}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(t){this._config.speed=t}play(){const t=this.duration;this._direction==="forward"&&this._currentTime>=t&&t>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&t>0&&(this._currentTime=t,this._loopIteration=0),this._playbackState="playing"}pause(){this._playbackState="paused"}stop(){this._playbackState="idle",this._repeatDelayRemaining=0,this._wrapAfterDelay=!1,this._currentTime=0,this._loopIteration=0,this._direction="forward"}seek(t){const e=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(t,e)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(t){if(this._playbackState!=="playing")return;const e=this.duration;if(e<=0)return;let n=t*this.speed;if(this._repeatDelayRemaining>0){const o=Math.min(this._repeatDelayRemaining,n);if(this._repeatDelayRemaining-=o,n-=o,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const r=1e3;for(let o=0;o<r&&n>0&&this._playbackState==="playing";o++)if(this._direction==="forward"){const c=e-this._currentTime;if(n>=c){if(n-=c,this._currentTime=e,!this._handleEndReached())break}else this._currentTime+=n,n=0}else{const c=this._currentTime;if(n>=c){if(n-=c,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=n,n=0}const a=this.getStateAtTime(this._currentTime);this.onUpdate?.(a)}getStateAtTime(t){const e=new Map;if(this._hasSharedWrites())this._resolveShared(t,e);else for(const[s,n]of this._trackPlayers){const r=n.getTrack().property;for(const{target:a,value:o,start:c}of n.getTargetValues(t))this._write(e,s,a,r,o,t-c)}return{values:e,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(t,e){const s=new Map;for(const[n,r]of this._trackPlayers){const a=r.getTrack().property;for(const{target:o,value:c,start:h}of r.getTargetValues(t)){const u=`${o}\0${a}`,l=h<=t,y=s.get(u);(!y||(l!==y.started?l:l?h>=y.start:h<=y.start))&&s.set(u,{trackId:n,target:o,property:a,value:c,start:h,started:l})}}for(const{trackId:n,target:r,property:a,value:o,start:c}of s.values())this._write(e,n,r,a,o,t-c)}_write(t,e,s,n,r,a){if(r===void 0)return;let o=t.get(s);o||(o=new Map,t.set(s,o));const c=this._textTracks.get(e);if(c&&typeof r=="number"){o.set("text",ui(c.textConfig,r,Math.max(0,a)));return}const h=this._motionPathTracks.get(e);if(h&&typeof r=="number"){const u=oi(h.motionPathConfig,r);o.set("motionPathX",u.x),o.set("motionPathY",u.y),h.motionPathConfig.autoRotate&&o.set("motionPathRotate",u.angle)}else o.set(n,r)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const t=new Set;this._sharedWrites=!1;t:for(const e of this._tracks)for(const s of L(e)){const n=`${s}\0${e.property}`;if(t.has(n)){this._sharedWrites=!0;break t}t.add(n)}}return this._sharedWrites}addTrack(t){if(this._tracks.push(t),this._sharedWrites=null,nt(t)){this._trackPlayers.set(t.id,new ai(t));return}if(rt(t)){this._trackPlayers.set(t.id,new ri(t)),this._springTracks.set(t.id,t);return}if(Mt(t))this._trackPlayers.set(t.id,new mt(t)),this._textTracks.set(t.id,t);else if(ne(t)){const e={id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,delay:t.delay,endDelay:t.endDelay,targets:t.targets,stagger:t.stagger};this._trackPlayers.set(t.id,new mt(e)),this._motionPathTracks.set(t.id,t)}else this._trackPlayers.set(t.id,new mt(t))}replaceTrack(t,e){const s=this._tracks.findIndex(r=>r.id===t);if(s<0)return;const n=this._tracks.slice(s+1);this.removeTrack(t);for(const r of n)this.removeTrack(r.id);this.addTrack(e);for(const r of n)this.addTrack(r)}removeTrack(t){this._tracks=this._tracks.filter(e=>e.id!==t),this._sharedWrites=null,this._trackPlayers.delete(t),this._motionPathTracks.delete(t),this._springTracks.delete(t),this._textTracks.delete(t)}getTracks(t={}){return this._tracks.filter(e=>this._matches(e,t))}removeTracks(t={}){const e=this.getTracks(t).map(s=>s.id);for(const s of e)this.removeTrack(s);return e}getTrackSpan(t){const e=this._trackPlayers.get(t);if(!e)return;const s=e.getTrack(),n=s.delay??0;if(rt(s)||nt(s))return{from:n,to:e.getDuration()};const r=s.keyframes;if(!(!r||r.length===0))return{from:r[0].time+n,to:e.getDuration()}}findConflicts(){const t=[];for(let e=0;e<this._tracks.length;e++){const s=this._tracks[e],n=this.getTrackSpan(s.id);if(n)for(let r=0;r<e;r++){const a=this._tracks[r];if(a.property!==s.property)continue;const o=L(a).filter(l=>L(s).includes(l));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=n.to&&n.from<=c.to))continue;const u=n.from>=c.from;for(const l of o)t.push({target:l,property:s.property,losingTrackId:u?a.id:s.id,winningTrackId:u?s.id:a.id})}}return t}_matches(t,e){if(e.id!==void 0&&t.id!==e.id||e.property!==void 0&&t.property!==e.property||e.target!==void 0&&!L(t).includes(e.target))return!1;if(e.timeRange){const s=this.getTrackSpan(t.id);if(!s||s.to<e.timeRange.from||s.from>e.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:se(this._tracks),id:this.id,name:this.name,config:{...this._config},tracks:[...this._tracks],...this.captions&&{captions:this.captions}}}get config(){return this._config}get markers(){return[...this._config.markers??[]].sort((t,e)=>t.time-e.time)}setMarkers(t){const e=t&&t.length>0?[...t].sort((n,r)=>n.time-r.time).map(n=>({...n})):void 0,s={...this._config};e?s.markers=e:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(t){const e={};for(const[s,n]of Object.entries(t??{}))e[s]={...n};this._captions=Object.keys(e).length>0?e:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let t=0;for(const[,e]of this._trackPlayers)t=Math.max(t,e.getDuration());return t}_handleEndReached(){const t=this._config.loop??0;return t===-1||this._loopIteration<t?(this._loopIteration++,this._armRepeatDelay(),this._config.alternate?this._direction="reverse":this._repeatDelayRemaining>0?this._wrapAfterDelay=!0:this._currentTime=0,this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}_handleStartReached(){const t=this._config.loop??0;return this._config.alternate&&(t===-1||this._loopIteration<t)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const fi=100;function pi(i,t,e,s){const n=[],r=[],{duration:a,alternate:o}=s,c=(p,f,d,m)=>{r.push([p,f]);const T=[];i.forEach((b,A)=>{(d==="forward"?(m?b>=p:b>p)&&b<=f:(m?b<=p:b<p)&&b>=f)&&T.push(A)}),T.sort((b,A)=>(d==="forward"?i[b]-i[A]:i[A]-i[b])||b-A);for(const b of T)n.push({kind:"event",index:b,direction:d})};let h=t.time,u=t.direction,l=t.fresh===!0;const y=Math.min(fi,Math.max(0,e.iteration-t.iteration));for(let p=0;p<y;p++){const f=u==="forward"?a:0;c(h,f,u,l),n.push({kind:"repeat"}),o?(u=u==="forward"?"reverse":"forward",h=f,l=!1):(h=u==="forward"?0:a,l=!0)}return y>0&&s.holding&&!o?{crossings:n,passes:r}:(c(h,e.time,u,l),{crossings:n,passes:r})}function mi(i){return{...i,...Array.isArray(i.end)&&{end:[...i.end]}}}function Q(i){const t=i.endDelay;return{...i.delay!==void 0&&{delay:i.delay},...t!==void 0&&{endDelay:t},...i.targets!==void 0&&{targets:[...i.targets]},...i.stagger!==void 0&&{stagger:{...i.stagger}}}}function yi(i){if(nt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:mi(t.inertia),...Q(t)}}if(rt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...Q(t)}}if(Mt(i)){const t=i;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((e,s)=>e.time-s.time),...Q(t)}}if(i.property==="motionPath"&&"motionPathConfig"in i){const t=i,e=[...t.keyframes].sort((s,n)=>s.time-n.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:e,...Q(t)}}return ni({id:i.id,target:i.target,property:i.property,keyframes:i.keyframes,...i.interpolation!==void 0&&{interpolation:i.interpolation},...Q(i)})}function tt(i){const t=i.formatVersion??1;if(t>St)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${St}. Update tinyfly to play it.`);return new di({id:i.id,name:i.name,config:i.config,tracks:i.tracks.map(yi),captions:i.captions})}function gi(i){const[t,e,s,n]=i;return[1-2*(e*e+s*s),2*(t*e+s*n),2*(t*s-e*n),0,2*(t*e-s*n),1-2*(t*t+s*s),2*(e*s+t*n),0,2*(t*s+e*n),2*(e*s-t*n),1-2*(t*t+e*e),0,0,0,0,1]}function Ti(i){return!Array.isArray(i)||i.length!==4?null:`matrix3d(${gi(H(i)).map(e=>Math.round(e*1e6)/1e6+0).join(", ")})`}const bi=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),Ai="#ffffff",Si="rgba(0, 0, 0, 0.5)";function Mi(i){const t=[];if(i.blur!==void 0&&t.push(`blur(${Math.max(0,i.blur)}px)`),i.brightness!==void 0&&t.push(`brightness(${Math.max(0,i.brightness)})`),i.glow!==void 0&&t.push(`drop-shadow(0 0 ${Math.max(0,i.glow)}px ${i.glowColor??Ai})`),i.shadowX!==void 0||i.shadowY!==void 0||i.shadowBlur!==void 0){const e=i.shadowX??0,s=i.shadowY??0,n=Math.max(0,i.shadowBlur??0);t.push(`drop-shadow(${e}px ${s}px ${n}px ${i.shadowColor??Si})`)}return t.length>0?t.join(" "):null}function _i(i,t){const e=i.childNodes.length===1?i.firstChild:null;if(e&&e.nodeType===3){const s=e;s.data!==t&&(s.data=t);return}i.textContent!==t&&(i.textContent=t)}function ki(i){if(!("ownerSVGElement"in i))return;const t=i.style;!t||t.transformBox||(t.transformBox="fill-box",t.transformOrigin||(t.transformOrigin="50% 50%"))}const zt=new Set(["width","height","top","right","bottom","left","margin","marginTop","marginRight","marginBottom","marginLeft","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","borderRadius","borderWidth","fontSize","lineHeight","letterSpacing","outlineWidth","gap","rowGap","columnGap"]),wi=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),Pi=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],vi=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),xi=new Set(["originX","originY"]),Ii=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Ci=new Set(["drawOn"]),Ri={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},Gt={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},Di="http://www.w3.org/2000/svg";class j{targets=new Map;registerTarget(t,e){this.targets.set(t,e)}unregisterTarget(t){this.targets.delete(t)}getTarget(t){return this.targets.get(t)}clearTargets(){this.targets.clear()}applyState(t){for(const[e,s]of t.values){const n=this.targets.get(e);n&&this.applyProperties(n,s)}}applyProperties(t,e){let s=null,n=null,r=null,a=null,o=null;const c=e.has("motionPathX"),h=e.has("motionPathY"),u=e.has("motionPathRotate");for(const[f,d]of e)if(!(f==="x"&&c)&&!(f==="y"&&h)&&!((f==="rotate"||f==="rotateZ")&&u)&&!Ci.has(f)){if(wi.has(f))(s??={})[f]=d;else if(vi.has(f))typeof d=="number"&&((n??={})[f]=d);else if(xi.has(f))typeof d=="number"&&((r??={})[f]=d);else if(Ii.has(f))typeof d=="number"&&((a??={})[f]=d);else if(bi.has(f))(o??={})[f]=d;else if(f!=="perspective"){if(f!=="shine")if(f==="text"&&typeof d=="string")_i(t,d);else if(f==="d"&&typeof d=="string"){const m=t;(m.tagName?.toLowerCase()==="path"?m:m.querySelector?.("path"))?.setAttribute?.("d",d)}else this.applyStyleProperty(t,f,d)}}const l=e.get("shine");typeof l=="number"&&this.applyShine(t,l);const y=[],p=e.get("perspective");if(typeof p=="number"&&p>0&&y.push(`perspective(${p}px)`),s)for(const f of Pi){const d=s[f];if(d===void 0)continue;const m=this.buildTransformPart(f,d);m&&y.push(m)}if(y.length>0&&(t.style.transform=y.join(" "),ki(t)),n&&(n.childPerspective!==void 0&&(t.style.perspective=`${n.childPerspective}px`),(n.perspectiveOriginX!==void 0||n.perspectiveOriginY!==void 0)&&(t.style.perspectiveOrigin=`${n.perspectiveOriginX??50}% ${n.perspectiveOriginY??50}%`)),r){const f=r.originX??50,d=r.originY??50;t.style.transformOrigin=`${f}% ${d}%`}if(a){const f=a.clipTop??0,d=a.clipRight??0,m=a.clipBottom??0,T=a.clipLeft??0;t.style.clipPath=`inset(${f}% ${d}% ${m}% ${T}%)`}if(o){const f=Mi(o);f&&(t.style.filter=f)}}buildTransformPart(t,e){if(t==="quaternion")return Ti(e);if(typeof e!="number")return null;switch(t){case"x":case"motionPathX":return`translateX(${e}px)`;case"y":case"motionPathY":return`translateY(${e}px)`;case"z":return`translateZ(${e}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${e}deg)`;case"rotateX":return`rotateX(${e}deg)`;case"rotateY":return`rotateY(${e}deg)`;case"scale":return`scale(${e})`;case"scaleX":return`scaleX(${e})`;case"scaleY":return`scaleY(${e})`;case"scaleZ":return`scaleZ(${e})`;case"skewX":return`skewX(${e}deg)`;case"skewY":return`skewY(${e}deg)`;default:return null}}applyShine(t,e){t.dataset.shineBase||(t.dataset.shineBase=t.style.color||"currentColor");const s=t.dataset.shineBase,n=-20+e*140,r=t.style;r.color="transparent",r.backgroundImage=`linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${s}, ${s})`,r.backgroundSize="250% 100%, 100% 100%",r.backgroundPosition=`${n}% 0, 0 0`,r.backgroundRepeat="no-repeat",r.webkitBackgroundClip="text",r.backgroundClip="text"}applyStyleProperty(t,e,s){let n;if(t.namespaceURI===Di&&e in Gt){const o=Array.isArray(s)?s.join(", "):String(s);t.style[Gt[e]]=o;return}else e==="fill"&&t.dataset?.elementType==="text"?n="color":n=Ri[e]??e;let a;typeof s=="number"?zt.has(e)||zt.has(n)?a=`${s}px`:a=String(s):Array.isArray(s)?a=s.join(", "):a=s,t.style[n]=a}}class gt{media;offset;driftTolerance;constructor(t,e={}){this.media=t,this.offset=e.offset??0,this.driftTolerance=Math.max(0,e.driftTolerance??.15)}targetTime(t){return Math.max(0,t/1e3+this.offset)}update(t,e){const s=this.targetTime(t);e?(this.media.paused&&this.safePlay(),Math.abs(this.media.currentTime-s)>this.driftTolerance&&(this.media.currentTime=s)):(this.media.paused||this.media.pause(),this.media.currentTime!==s&&(this.media.currentTime=s))}seek(t){this.media.currentTime=this.targetTime(t)}setRate(t){this.media.playbackRate=t}dispose(){this.media.paused||this.media.pause()}safePlay(){const t=this.media.play();t&&typeof t.catch=="function"&&t.catch(()=>{})}}function Zt(i,t,e,s,n){const r=e-n;if(r<0){t.paused||t.pause(),t.currentTime=0;return}i.update(r,s)}class Tt{container;timeline=null;adapter;animationFrameId;lastTime;options;targets={};isDestroyed=!1;mediaSync;mediaTargets=[];symbolInstances=[];scenarioList=[];scenarioId;authored=new Map;markerList=[];listeners=new Set;playhead={time:0,iteration:0,direction:"forward"};stepping=!1;lastMarkerId=null;reducedQuery;onReducedChange=()=>this.applyReducedMotion();visibilityObserver;onScreen=!0;pausedByVisibility=!1;autoplayWhenSeen=!1;onDocumentVisibility=()=>this.updateVisibility();constructor(t,e={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=e,this.adapter=new j}async load(t){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(t)}async loadSource(t){let e;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load animation: ${s.statusText}`);e=await s.json()}else e=t;this.useDefinition(e),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(t){const e={...t.config};this.options.speed!==void 0&&(e.speed=this.options.speed),this.options.loop!==void 0&&(e.loop=this.options.loop),this.options.alternate!==void 0&&(e.alternate=this.options.alternate),this.timeline=tt({...t,config:e}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(t,e={}){if(t.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const s=new Set;for(const r of t){if(s.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);s.add(r.id)}const n=e.initial===void 0?t[0]:t.find(r=>r.id===e.initial);if(!n)throw new Error(`tinyfly: there is no scenario "${e.initial}"`);this.scenarioList=[...t],this.scenarioId=n.id,await this.loadSource(n.timeline)}get scenarios(){return this.scenarioList.map(t=>({id:t.id,label:t.label??t.id}))}get scenario(){return this.scenarioId}setScenario(t){const e=this.scenarioList.find(o=>o.id===t);if(!e||!this.timeline)return!1;if(t===this.scenarioId)return!0;const s=this.isPlaying,n=this.currentTime>=this.duration-.5,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=t,this.useDefinition(e.timeline),this.lastMarkerId=null;let a=0;return this.reducedMotion||n?a=this.duration:r!==void 0&&(a=this.markers.find(o=>o.id===r)?.time??0),this.seek(a),s&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(t){if(this.authored.has(t))return;const e={style:t.getAttribute("style")};t.children.length===0&&(e.text=t.textContent??"");const s=t.tagName.toLowerCase()==="path"?t:t.querySelector("path");s&&(e.path={element:s,d:s.getAttribute("d")}),this.authored.set(t,e)}restoreAuthored(){for(const[t,e]of this.authored){e.style===null?t.removeAttribute("style"):t.setAttribute("style",e.style),e.text!==void 0&&t.textContent!==e.text&&(t.textContent=e.text),e.path&&(e.path.d===null?e.path.element.removeAttribute("d"):e.path.element.setAttribute("d",e.path.d));const s=t.dataset;s&&delete s.shineBase}}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notify(){for(const t of this.listeners)t()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const t=this.currentTime;let e;for(const s of this.markers)if(s.time<=t+.5)e=s;else break;return e}caption(t,e){const s=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!s)return;const n=e??this.language(),r=a=>a?.[n]?.[s.id]??a?.[n.split("-")[0]]?.[s.id];return r(this.options.captions)??r(this.timeline?.captions)??s.label}next(){if(!this.timeline)return;const t=this.currentTime,e=this.markers.find(s=>s.time>t+.5);if(this.reducedMotion){this.seek(e?e.time:this.duration);return}t>=this.duration-.5||(this.stepping=e!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const t=this.currentTime,e=[...this.markers].reverse().find(s=>s.time<t-.5);this.pause(),this.seek(e?e.time:0)}goToMarker(t){const e=this.markers.find(s=>s.id===t);e&&(this.pause(),this.seek(e.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const t=this.options.initialFrame??"start";if(t==="none")return;const e=t==="end"?this.timeline.duration:t==="start"?0:t;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,e))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(e=>{for(const s of e)this.onScreen=s.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const t=this.container.getBoundingClientRect?.();t&&(t.width>0||t.height>0)&&(this.onScreen=t.bottom>0&&t.top<window.innerHeight&&t.right>0&&t.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const t=this.onScreen&&document.visibilityState!=="hidden";!t&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):t&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const t=this.currentMarker,e=t?.id;e!==this.lastMarkerId&&(this.lastMarkerId=e,this.options.onMarker(t))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(e=>{const s=e,n=Number(s.getAttribute("data-tinyfly-start")??"0")||0,r=s.getAttribute("data-volume");r!==null&&(s.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:s,startTime:n,sync:new gt(s)})})}syncAllMedia(t,e){for(const s of this.mediaTargets)Zt(s.sync,s.el,t,e,s.startTime)}loadFromString(t){const e=JSON.parse(t);this.load(e)}registerTarget(t,e){if(typeof e=="string"){const s=this.container.querySelector(e);s&&(this.rememberAuthored(s),this.targets[t]=s,this.adapter.registerTarget(t,s))}else this.rememberAuthored(e),this.targets[t]=e,this.adapter.registerTarget(t,e)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(e=>{const s=e.closest("[data-tinyfly-symbol]");if(s&&s!==e)return;const n=e.getAttribute("data-tinyfly");n&&this.registerTarget(n,e)}),this.timeline&&new Set(this.timeline.tracks.map(s=>s.target)).forEach(s=>{if(!this.targets[s]){const n=this.container.querySelector(`[data-tinyfly="${s}"]`)||this.container.querySelector(`.${s}`)||this.container.querySelector(`#${s}`);n&&this.registerTarget(s,n)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const e=new Map(t.map(s=>[s.id,s]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const n=s.getAttribute("data-tinyfly-symbol");if(!n)return;const r=e.get(n);if(!r||!r.timeline.tracks?.length)return;const a=new j;s.querySelectorAll("[data-tinyfly]").forEach(o=>{const c=o.getAttribute("data-tinyfly");c&&a.registerTarget(c,o)}),this.symbolInstances.push({adapter:a,timeline:tt(r.timeline)})})}attachMedia(t,e){this.mediaSync=new gt(t,e),this.timeline&&(this.mediaSync.setRate(this.timeline.speed),this.mediaSync.update(this.timeline.currentTime,this.isPlaying))}detachMedia(){this.mediaSync?.dispose(),this.mediaSync=void 0}play(){!this.timeline||this.isDestroyed||(this.autoplayWhenSeen=!1,this.stepping=this.options.stepMode===!0,this.startPlaying())}startPlaying(){if(!this.timeline||this.isDestroyed)return;const t=this.timeline.playbackState==="idle";this.timeline.play(),t&&this.timeline.currentTime===0&&this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.update(this.timeline.currentTime,!0),this.syncAllMedia(this.timeline.currentTime,!0),this.startAnimationLoop(),this.notify()}pause(){this.timeline&&(this.stepping=!1,this.timeline.pause(),this.notify(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1),this.stopAnimationLoop())}stop(){this.timeline&&(this.timeline.stop(),this.stopAnimationLoop(),this.applyState(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1))}seek(t){this.timeline&&(this.timeline.seek(t),this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.seek(this.timeline.currentTime),this.syncAllMedia(this.timeline.currentTime,this.isPlaying))}setSpeed(t){this.timeline&&(this.timeline.speed=t,this.mediaSync?.setRate(t))}reverse(){this.timeline&&this.timeline.reverse()}get currentTime(){return this.timeline?.currentTime??0}get duration(){return this.timeline?.duration??0}get isPlaying(){return this.timeline?.playbackState==="playing"}destroy(){this.isDestroyed=!0,this.stopAnimationLoop(),this.reducedQuery?.removeEventListener?.("change",this.onReducedChange),this.visibilityObserver?.disconnect(),typeof document<"u"&&document.removeEventListener("visibilitychange",this.onDocumentVisibility),this.mediaSync?.dispose(),this.mediaSync=void 0;for(const t of this.mediaTargets)t.el.paused||t.el.pause();this.mediaTargets=[],this.adapter.clearTargets();for(const t of this.symbolInstances)t.adapter.clearTargets();this.symbolInstances=[],this.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=e=>{if(this.isDestroyed||!this.timeline)return;const s=e-(this.lastTime??e);this.lastTime=e;const n=this.playhead;this.timeline.tick(s),this.stopAtMarker(n),this.applyState();const r=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,r),this.syncAllMedia(this.timeline.currentTime,r),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(t):(this.animationFrameId=void 0,this.notify())};this.animationFrameId=requestAnimationFrame(t)}stopAtMarker(t){const e=this.timeline,s={time:e.currentTime,iteration:e.loopIteration,direction:e.direction};this.playhead=s;const n=this.markers;if(n.length===0)return;const{crossings:r}=pi(n.map(a=>a.time),t,s,{duration:e.duration,alternate:e.config.alternate===!0,holding:e.repeatDelayRemaining>0});for(const a of r){if(a.kind!=="event")continue;const o=n[a.index];if(this.stepping||o.pause){this.stepping=!1,e.pause(),e.seek(o.time),this.playhead={time:o.time,iteration:e.loopIteration,direction:e.direction};return}}}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}applyState(){if(!this.timeline)return;const t=this.timeline.currentTime;this.adapter.applyState(this.timeline.getStateAtTime(t)),this.announceMarker(),this.notify();for(const e of this.symbolInstances){const s=e.timeline.duration;e.adapter.applyState(e.timeline.getStateAtTime(s>0?t%s:t))}}}async function Ei(i,t,e={}){const s=new Tt(i,{...e,autoplay:!0});return await s.load(t),s}function Bi(i,t={}){return new Tt(i,t)}class Kt{container;containerA;containerB;adapterA;adapterB;timelineA=null;timelineB=null;symbolDefs=new Map;nestedByAdapter=new Map;sequence=null;options;_currentSceneIndex=0;_state="idle";_isPlaying=!1;_isDestroyed=!1;loopIteration=0;animationFrameId;lastTime;transitionTimer;constructor(t,e={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=e,this.container.style.position="relative",this.container.style.overflow="hidden",this.containerA=this.createSceneContainer(),this.containerB=this.createSceneContainer(),this.container.appendChild(this.containerA),this.container.appendChild(this.containerB),this.containerB.style.visibility="hidden",this.adapterA=new j,this.adapterB=new j}async load(t){let e;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load sequence: ${s.statusText}`);e=await s.json()}else e=t;this.sequence=e,this.symbolDefs.clear();for(const s of e.symbols??[])s.timeline?.tracks?.length&&this.symbolDefs.set(s.id,s.timeline);this.container.style.width=`${e.canvas.width}px`,this.container.style.height=`${e.canvas.height}px`,e.scenes.length>0&&(this.renderScene(e.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(e.scenes[0])),this.options.autoplay&&this.play()}play(){if(!(!this.sequence||this._isDestroyed)&&this.sequence.scenes.length!==0){if(this._isPlaying=!0,this._state==="idle"){if(this._state="playing-scene",this._currentSceneIndex=0,this.timelineA)this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play();else{this.onSceneComplete();return}this.options.onSceneChange?.(0)}else this._state==="playing-scene"&&this.timelineA&&this.timelineA.play();this.startAnimationLoop()}}pause(){this._isPlaying&&(this._isPlaying=!1,this.timelineA&&this.timelineA.pause(),this.timelineB&&this.timelineB.pause(),this.stopAnimationLoop())}stop(){if(this._isPlaying=!1,this._state="idle",this._currentSceneIndex=0,this.loopIteration=0,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.stopAnimationLoop(),this.sequence&&this.sequence.scenes.length>0&&(this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this.renderScene(this.sequence.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(this.sequence.scenes[0]),this.timelineA)){const t=this.timelineA.getStateAtTime(0);this.adapterA.applyState(t),this.applyNested(this.adapterA,0)}}goToScene(t){if(!this.sequence||t<0||t>=this.sequence.scenes.length)return;const e=this._isPlaying;this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this._currentSceneIndex=t,this._state=e?"playing-scene":"idle",this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB);const s=this.sequence.scenes[t];if(this.renderScene(s,this.containerA,this.adapterA),this.timelineA=this.createTimeline(s),this.options.onSceneChange?.(t),e)this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play(),this.startAnimationLoop()):this.onSceneComplete();else if(this.timelineA){const n=this.timelineA.getStateAtTime(0);this.adapterA.applyState(n),this.applyNested(this.adapterA,0)}}destroy(){this._isDestroyed=!0,this._isPlaying=!1,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.adapterA.clearTargets(),this.adapterB.clearTargets();for(const t of this.nestedByAdapter.values())for(const e of t)e.adapter.clearTargets();this.nestedByAdapter.clear(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.timelineA=null,this.timelineB=null,this.containerA.parentNode&&this.containerA.remove(),this.containerB.parentNode&&this.containerB.remove(),this.sequence=null}get currentSceneIndex(){return this._currentSceneIndex}get sceneCount(){return this.sequence?.scenes.length??0}get isPlaying(){return this._isPlaying}get state(){return this._state}createSceneContainer(){const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.width="100%",t.style.height="100%",t}renderScene(t,e,s){e.innerHTML="",s.clearTargets();const n=document.createElement("div");n.style.cssText="position:absolute;inset:0;transform-origin:center center",n.setAttribute("data-tinyfly","Camera"),e.appendChild(n),s.registerTarget("Camera",n);for(const r of t.elements){if(!r.html)continue;const a=document.createElement("div");a.innerHTML=r.html.trim();const o=a.firstElementChild;if(o){n.appendChild(o);const c=o.getAttribute("data-tinyfly");c&&s.registerTarget(c,o)}}this.setupNested(n,s)}setupNested(t,e){const s=[];t.querySelectorAll("[data-tinyfly-symbol]").forEach(n=>{const r=n.getAttribute("data-tinyfly-symbol");if(!r)return;const a=this.symbolDefs.get(r);if(!a)return;const o=new j;n.querySelectorAll("[data-tinyfly]").forEach(c=>{const h=c.getAttribute("data-tinyfly");h&&o.registerTarget(h,c)}),s.push({adapter:o,timeline:tt(a)})}),s.length?this.nestedByAdapter.set(e,s):this.nestedByAdapter.delete(e)}applyNested(t,e){const s=this.nestedByAdapter.get(t);if(s)for(const n of s){const r=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(r>0?e%r:e))}}clearContainer(t){t.innerHTML=""}createTimeline(t){return t.timeline?tt(t.timeline):null}onSceneComplete(){if(this._isDestroyed||!this.sequence)return;const t=this._currentSceneIndex+1;if(t>=this.sequence.scenes.length){const e=this.options.loop??this.sequence.loop??0;e===-1||e>0&&this.loopIteration<e-1?(this.loopIteration++,this.beginTransitionTo(0)):(this._isPlaying=!1,this._state="idle",this.stopAnimationLoop(),this.options.onComplete?.())}else this.beginTransitionTo(t)}beginTransitionTo(t){if(!this.sequence||this._isDestroyed)return;const e=this.sequence.scenes[t],s=e.transition;if(s.type==="none"||s.duration<=0){this.switchToScene(t);return}this._state="transitioning",this.containerB.style.visibility="visible",this.renderScene(e,this.containerB,this.adapterB),this.timelineB=this.createTimeline(e),this.timelineB&&this.timelineB.play(),this.applyTransition(s.type,s.duration),this.transitionTimer=window.setTimeout(()=>{this.finishTransition(t)},s.duration)}applyTransition(t,e){const s=`${e}ms`,n="ease-in-out";switch(this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),t){case"fade":this.containerB.style.opacity="0";break;case"slide-left":this.containerB.style.transform="translateX(100%)";break;case"slide-right":this.containerB.style.transform="translateX(-100%)";break;case"slide-up":this.containerB.style.transform="translateY(100%)";break;case"slide-down":this.containerB.style.transform="translateY(-100%)";break}switch(this.containerB.offsetHeight,this.containerA.style.transition=`opacity ${s} ${n}, transform ${s} ${n}`,this.containerB.style.transition=`opacity ${s} ${n}, transform ${s} ${n}`,t){case"fade":this.containerA.style.opacity="0",this.containerB.style.opacity="1";break;case"slide-left":this.containerA.style.transform="translateX(-100%)",this.containerB.style.transform="translateX(0)";break;case"slide-right":this.containerA.style.transform="translateX(100%)",this.containerB.style.transform="translateX(0)";break;case"slide-up":this.containerA.style.transform="translateY(-100%)",this.containerB.style.transform="translateY(0)";break;case"slide-down":this.containerA.style.transform="translateY(100%)",this.containerB.style.transform="translateY(0)";break}}resetTransitionStyles(t){t.style.transition="",t.style.opacity="1",t.style.transform=""}finishTransition(t){this.transitionTimer=void 0,this.timelineA&&(this.timelineA.stop(),this.timelineA=null),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.containerA;this.containerA=this.containerB,this.containerB=e;const s=this.adapterA;this.adapterA=this.adapterB,this.adapterB=s,this.timelineA=this.timelineB,this.timelineB=null,this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.playbackState!=="playing"&&this.timelineA.play()):this.onSceneComplete()}switchToScene(t){if(!this.sequence||this._isDestroyed)return;this.timelineA&&this.timelineA.stop(),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.sequence.scenes[t];this.renderScene(e,this.containerA,this.adapterA),this.timelineA=this.createTimeline(e),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play()):this.onSceneComplete()}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=e=>{if(this._isDestroyed||!this._isPlaying)return;const s=e-(this.lastTime??e);if(this.lastTime=e,this.timelineA&&this.timelineA.playbackState==="playing"){this.timelineA.tick(s);const n=this.timelineA.getStateAtTime(this.timelineA.currentTime);this.adapterA.applyState(n),this.applyNested(this.adapterA,this.timelineA.currentTime)}if(this._state==="transitioning"&&this.timelineB&&this.timelineB.playbackState==="playing"){this.timelineB.tick(s);const n=this.timelineB.getStateAtTime(this.timelineB.currentTime);this.adapterB.applyState(n),this.applyNested(this.adapterB,this.timelineB.currentTime)}this._isPlaying?this.animationFrameId=requestAnimationFrame(t):this.animationFrameId=void 0};this.animationFrameId=requestAnimationFrame(t)}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}}async function Oi(i,t,e={}){const s=new Kt(i,{...e,autoplay:!0});return await s.load(t),s}const Li={type:"none",duration:0};v.DEFAULT_TRANSITION=Li,v.MediaSync=gt,v.TinyflyPlayer=Tt,v.TinyflySequencer=Kt,v.create=Bi,v.play=Ei,v.playSequence=Oi,v.syncMediaElement=Zt,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(v,N){typeof exports=="object"&&typeof module<"u"?N(exports):typeof define=="function"&&define.amd?define(["exports"],N):(v=typeof globalThis<"u"?globalThis:v||self,N(v.tinyfly=v.tinyfly||{}))})(this,(function(v){"use strict";function N(i){return typeof i=="object"&&i!==null&&i.type==="cubic-bezier"}function ie(i){return typeof i=="object"&&i!==null&&i.type!=="cubic-bezier"}const St=2;function se(i){return i.some(t=>t.interpolation!==void 0)?2:1}function Mt(i){return i.property==="text"&&"textConfig"in i}function nt(i){return i.kind==="inertia"&&"inertia"in i}function rt(i){return i.kind==="spring"&&"spring"in i}function ne(i){return i.property==="motionPath"&&"motionPathConfig"in i}function re(i,t){if(!(t>0))return i;const e=1e3/t;return Math.floor(i/e+1e-9)*e}function _t(i,t,e="start"){if(t<=1)return 0;if(typeof e=="number"){const s=Math.max(0,Math.min(t-1,e));return Math.abs(i-s)}switch(e){case"end":return t-1-i;case"center":return Math.abs(i-(t-1)/2);case"edges":return(t-1)/2-Math.abs(i-(t-1)/2);default:return i}}function ae(i,t="start"){if(i<=1)return 0;let e=0;for(let s=0;s<i;s++)e=Math.max(e,_t(s,i,t));return e}function kt(i,t,e){if(e.offsets)return e.offsets[i]??0;const s=e.from??"start",n=_t(i,t,s);if(e.amount!==void 0){const r=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)=>kt(s,i,t))}function at(i,t){return i<=1?0:Math.max(...oe(i,t))}const q=1,wt=6e4,G=wt/q,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/q);if(this.simulateTo(e+1),this.settledStep!==null&&e>=this.settledStep)return this.to;const s=this.samples[Math.min(e,this.samples.length-1)],n=this.samples[Math.min(e+1,this.samples.length-1)],r=t/q-e;return s+(n-s)*r}settleTime(){return this.simulateTo(G+1),this.settledStep!==null?this.settledStep*q:wt}simulateTo(t){if(this.settledStep!==null)return;const e=Math.min(t,G+1),s=q/1e3;for(;this.samples.length<e;){const n=this.samples[this.samples.length-1],r=n-this.to,a=-this.stiffness*r,o=-this.damping*this.velocity,c=(a+o)/this.mass;this.velocity+=c*s;const h=n+this.velocity*s;if(this.samples.push(h),this.isAtRest(h)){this.settledStep=this.samples.length-1;return}}this.samples.length>G&&(this.settledStep=G)}}const Pt=4,he=.002,le=1e-4,ue=6e4;function ot(i){const t=i.friction??Pt;return t>0?t:Pt}function de(i){return i.from+i.velocity/ot(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 vt(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 xt(i){const t=Math.abs(vt(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)/ot(i);return Math.min(ue,s*1e3)}function It(i,t){if(t<=0)return i.from;const e=vt(i);if(t>=xt(i))return e;const s=ot(i);return i.from+(e-i.from)*(1-Math.exp(-s*t/1e3))}const ct=i=>i,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,Ct=i=>i*i*i,Rt=i=>1-Math.pow(1-i,3),Dt=i=>i<.5?4*i*i*i:1-Math.pow(-2*i+2,3)/2,ye={linear:ct,"ease-in":Ct,"ease-out":Rt,"ease-in-out":Dt,"ease-in-quad":pe,"ease-out-quad":me,"ease-in-out-quad":ge,"ease-in-cubic":Ct,"ease-out-cubic":Rt,"ease-in-out-cubic":Dt};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 ht(i,t="out"){if(t==="out")return i;const e=s=>1-i(1-s);return t==="in"?e:s=>s<.5?e(s*2)/2:i(s*2-1)/2+.5}function 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 ht(be(i.amplitude,i.period),i.mode);case"bounce":return ht(Ae,i.mode);case"back":return ht(Se(i.overshoot),i.mode)}}function ke(i){return i===void 0?ct:N(i)?Te(i.points):ie(i)?_e(i):ye[i]??ct}const Et=32,we=256,V=new Map,Pe=/[MmLlHhVvCcSsQqTtAaZz]/,ve=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,xe={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function Ie(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,et=g*S-p*E+(i+o)/2,k=p*S+g*E+(t+c)/2,C=(w,I,R,Y)=>{const At=w*R+I*Y,st=Math.sqrt((w*w+I*I)*(R*R+Y*Y)),z=Math.acos(Math.max(-1,Math.min(1,At/st)));return w*Y-I*R<0?-z:z},P=C(1,0,(m-S)/h,(T-E)/u);let x=C((m-S)/h,(T-E)/u,(-m-S)/h,(-T-E)/u);!a&&x>0&&(x-=2*Math.PI),a&&x<0&&(x+=2*Math.PI);const $=Math.max(1,Math.ceil(Math.abs(x)/(Math.PI/2))),bt=x/$,it=4/3*Math.tan(bt/4),Jt=w=>{const I=h*Math.cos(w),R=u*Math.sin(w);return[g*I-p*R+et,p*I+g*R+k]},te=w=>{const I=-h*Math.sin(w),R=u*Math.cos(w);return[g*I-p*R,p*I+g*R]},ee=[];for(let w=0;w<$;w++){const I=P+w*bt,R=I+bt,[Y,At]=Jt(I),[st,z]=w===$-1?[o,c]:Jt(R),[Xi,Fi]=te(I),[Yi,Ni]=te(R);ee.push([Y+it*Xi,At+it*Fi,st-it*Yi,z-it*Ni,st,z])}return ee}function B(i,t,e,s,n){const r=1-n;return r*r*r*i+3*r*r*n*t+3*r*n*n*e+n*n*n*s}function Bt(i,t,e,s,n){const r=1-n;return 3*r*r*(t-i)+6*r*n*(e-t)+3*n*n*(s-e)}function W(i,t,e,s){return{subpath:0,type:"L",points:[e,s],startX:i,startY:t,endX:e,endY:s,length:Math.hypot(e-i,s-t)}}function Z(i,t,e){const[s,n,r,a,o,c]=e,h=[0];let u=i,l=t,g=0;for(let p=1;p<=Et;p++){const f=p/Et,d=B(i,s,r,o,f),m=B(t,n,a,c,f);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 K(i){const t=V.get(i);if(t)return t;const e=[];let s=0,n=0,r=0,a=0,o=null,c=null,h=-1;const u=new Set,l=d=>{h<0&&(h=0),d.subpath=h,e.push(d)};for(const{type:d,args:m}of Ie(i)){const T=d.toUpperCase(),b=d!==T,A=xe[T];if(T==="Z"){(s!==r||n!==a)&&l(W(s,n,r,a)),h>=0&&u.add(h),s=r,n=a,o=c=null;continue}for(let M=0;M+A<=m.length;M+=A){const y=m.slice(M,M+A),_=b?s:0,S=b?n:0;let E=null,et=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(W(s,n,y[0]+_,y[1]+S)),s=y[0]+_,n=y[1]+S);break;case"L":l(W(s,n,y[0]+_,y[1]+S)),s=y[0]+_,n=y[1]+S;break;case"H":l(W(s,n,y[0]+_,n)),s=y[0]+_;break;case"V":l(W(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(Z(s,n,k)),E=[k[2],k[3]],s=k[4],n=k[5];break}case"S":{const[k,C]=o?[2*s-o[0],2*n-o[1]]:[s,n],P=[k,C,y[0]+_,y[1]+S,y[2]+_,y[3]+S];l(Z(s,n,P)),E=[P[2],P[3]],s=P[4],n=P[5];break}case"Q":case"T":{let k=s,C=n;T==="Q"?(k=y[0]+_,C=y[1]+S):c&&(k=2*s-c[0],C=2*n-c[1]);const P=T==="Q"?y[2]+_:y[0]+_,x=T==="Q"?y[3]+S:y[1]+S;l(Z(s,n,[s+2/3*(k-s),n+2/3*(C-n),P+2/3*(k-P),x+2/3*(C-x),P,x])),et=[k,C],s=P,n=x;break}case"A":{const k=y[5]+_,C=y[6]+S;let P=s,x=n;for(const $ of Ce(s,n,y[0],y[1],y[2],y[3],y[4],k,C))l(Z(P,x,$)),P=$[4],x=$[5];s=k,n=C;break}}o=E,c=et}}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 V.size>=we&&V.delete(V.keys().next().value),V.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=Bt(i.startX,e,n,a,c),u=Bt(i.startY,s,r,o,c);if(Math.hypot(h,u)<1e-9){const l=c<.5?Math.min(1,c+.001):Math.max(0,c-.001),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 Ot(i,t,e=0,s=i.length){if(s<=e)return{x:0,y:0,angle:0};let n=0;for(let r=e;r<s;r++){const a=i[r];if(n+a.length>=t||r===s-1)return De(a,t-n);n+=a.length}return{x:0,y:0,angle:0}}function Ee(i,t){const{segments:e,totalLength:s}=K(i);return Ot(e,Math.max(0,Math.min(1,t))*s)}const Be=24,Oe=320,Le=2.5,U=72,$e=.2,Xe=128,J=new Map;let lt=0,O;const Lt=i=>Math.round(i*100)/100;function $t(i,t){const{segments:e,subpaths:s,totalLength:n}=K(i);if(e.length===0)return[];if(t){const r=s.every(a=>a.closed);return[{segments:e,start:0,end:e.length,length:n,closed:r}]}return s.filter(r=>r.length>0).map(r=>({segments:e,start:r.start,end:r.end,length:r.length,closed:r.closed}))}function ut(i,t){const e=i.closed?(t%1+1)%1:Math.max(0,Math.min(1,t)),s=Ot(i.segments,e*i.length,i.start,i.end);return[s.x,s.y]}function Xt(i){const t=[];let e=0;for(let s=i.start;s<i.end;s++)e+=i.segments[s].length,i.length>0&&t.push(e/i.length);return t}function Ft(i,t){const e=[];for(let s=0;s<t;s++)e.push(ut(i,i.closed?s/t:s/(t-1)));return e}function Yt(i){let t=0,e=0;for(const[s,n]of i)t+=s,e+=n;return t/=i.length,e/=i.length,i.map(([s,n])=>[s-t,n-e])}function Fe(i,t,e){const s=i.closed&&t.closed;if(e!==void 0)return{offset:s?Math.abs(e)%U/U:0,reversed:e<0};const n=Yt(Ft(i,U)),r=Yt(Ft(t,U)),a=U;let o={offset:0,reversed:!1},c=1/0;for(const h of[!1,!0]){const u=s?a:1;for(let l=0;l<u;l++){let 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 Xt(i))o(l);for(const l of Xt(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(...ut(i,l)),u.push(...ut(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(Nt(i.from,a,o,u),Nt(i.to,a,o,u));l>h&&(h=l,c=u)}c!==-1&&(e[c]=1,s.push([a,c],[c,o]))}const n=[],r=[];for(let a=0;a<t;a++)e[a]&&(n.push(i.from[a*2],i.from[a*2+1]),r.push(i.to[a*2],i.to[a*2+1]));return{from:n,to:r,closed:i.closed}}function Nt(i,t,e,s){const n=i[t*2],r=i[t*2+1],a=i[e*2]-n,o=i[e*2+1]-r,c=i[s*2]-n,h=i[s*2+1]-r,u=a*a+o*o,l=u===0?0:Math.max(0,Math.min(1,(c*a+h*o)/u));return Math.hypot(c-l*a,h-l*o)}function We(i,t,e){const s=e.shapeIndex;if(O&&O.from===i&&O.to===t&&O.shapeIndex===s)return O.plan;const r=J.get(String(s??"auto"))?.get(i)?.get(t);if(r)return O={from:i,to:t,shapeIndex:s,plan:r},r;const a=K(i).subpaths.filter(p=>p.length>0).length===K(t).subpaths.filter(p=>p.length>0).length,o=$t(i,!a),c=$t(t,!a),h={pairs:o.map((p,f)=>qe(p,c[f],e))};lt>=Xe&&(J.clear(),lt=0);const u=String(s??"auto"),l=J.get(u)??new Map;J.set(u,l);const g=l.get(i)??new Map;return l.set(i,g),g.set(t,h),lt++,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=Lt(o.from[c]+(o.to[c]-o.from[c])*n),u=Lt(o.from[c+1]+(o.to[c+1]-o.from[c+1])*n);a+=`${c===0?a?" M":"M":" L"}${h} ${u}`}o.closed&&(a+=" Z")}return a}function 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 H(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=H(i);let n=H(t),r=ze(s,n);if(r<0&&(n=[-n[0],-n[1],-n[2],-n[3]],r=-r),r>Qe)return H([s[0]+(n[0]-s[0])*e,s[1]+(n[1]-s[1])*e,s[2]+(n[2]-s[2])*e,s[3]+(n[3]-s[3])*e]);const a=Math.acos(r),o=Math.sin(a),c=Math.sin((1-e)*a)/o,h=Math.sin(e*a)/o;return H([s[0]*c+n[0]*h,s[1]*c+n[1]*h,s[2]*c+n[2]*h,s[3]*c+n[3]*h])}const D=(i,t,e)=>i+(t-i)*e,qt=512,dt=new Map,ft=new Map;function Vt(i){const t=dt.get(i);if(t)return t;const e=i.replace("#",""),s=[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)];return dt.size<qt&&dt.set(i,s),s}const Wt=i=>i.charCodeAt(0)===35,Ut=i=>i.startsWith("rgb"),Ht=i=>i.startsWith("rgba"),Ke=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,pt=i=>Math.round(i).toString(16).padStart(2,"0");function Je(i,t,e){return`#${pt(i)}${pt(t)}${pt(e)}`}function Qt(i){const t=ft.get(i);if(t)return t;const e=i.match(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 ft.size<qt&&ft.set(i,a),a}const ti=(i,t,e)=>{if(Wt(i)&&Wt(t)){const[s,n,r]=Vt(i),[a,o,c]=Vt(t),h=D(s,a,e),u=D(n,o,e),l=D(r,c,e);return Je(h,u,l)}if((Ut(i)||Ht(i))&&(Ut(t)||Ht(t))){const s=Qt(i),n=Qt(t),r=Math.round(D(s[0],n[0],e)),a=Math.round(D(s[1],n[1],e)),o=Math.round(D(s[2],n[2],e));if(s.length===4||n.length===4){const c=s[3]??1,h=n[3]??1,u=D(c,h,e);return`rgba(${r}, ${a}, ${o}, ${u})`}return`rgb(${r}, ${a}, ${o})`}return e<1?i:t},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),jt=(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:jt:jt}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+kt(i,t,s)}class mt{track;targets;constructor(t){this.track=t,this.targets=L(t)}getValueAtTime(t){return this.valueForOffset(t-F(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=F(n,e,this.track.delay,this.track.stagger),a=this.valueForOffset(t-r);a!==void 0&&s.push({target:this.targets[n],value:a,start:r+this.track.keyframes[0].time})}return s}getDuration(){const{keyframes:t}=this.track;if(t.length===0)return 0;const e=t[t.length-1].time,s=this.track.stagger?at(this.targets.length,this.track.stagger):0;return e+(this.track.delay??0)+s+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(t){const{keyframes:e}=this.track;if(e.length===0)return;if(e.length===1||t<=e[0].time)return e[0].value;if(t>=e[e.length-1].time)return e[e.length-1].value;const{from:s,to:n}=this.findSurroundingKeyframes(t);if(!s||!n)return;if(s.time===t)return s.value;const r=n.time-s.time,a=(t-s.time)/r,c=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?at(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=xt(t.inertia)}getValueAtTime(t){return It(this.track.inertia,t-F(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=F(n,e,this.track.delay,this.track.stagger);s.push({target:this.targets[n],value:It(this.track.inertia,t-r),start:r})}return s}getDuration(){const t=this.track.stagger?at(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+t}getTrack(){return this.track}}function 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 gt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},hi=20;function li(i){const t=gt[i??"upperCase"]??i??gt.upperCase,e=Array.from(t);return e.length>0?e:Array.from(gt.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,nt(t)){this._trackPlayers.set(t.id,new oi(t));return}if(rt(t)){this._trackPlayers.set(t.id,new ai(t)),this._springTracks.set(t.id,t);return}if(Mt(t))this._trackPlayers.set(t.id,new mt(t)),this._textTracks.set(t.id,t);else if(ne(t)){const e={id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,delay:t.delay,endDelay:t.endDelay,targets:t.targets,stagger:t.stagger};this._trackPlayers.set(t.id,new mt(e)),this._motionPathTracks.set(t.id,t)}else this._trackPlayers.set(t.id,new mt(t))}replaceTrack(t,e){const s=this._tracks.findIndex(r=>r.id===t);if(s<0)return;const n=this._tracks.slice(s+1);this.removeTrack(t);for(const r of n)this.removeTrack(r.id);this.addTrack(e);for(const r of n)this.addTrack(r)}removeTrack(t){this._tracks=this._tracks.filter(e=>e.id!==t),this._sharedWrites=null,this._trackPlayers.delete(t),this._motionPathTracks.delete(t),this._springTracks.delete(t),this._textTracks.delete(t)}getTracks(t={}){return this._tracks.filter(e=>this._matches(e,t))}removeTracks(t={}){const e=this.getTracks(t).map(s=>s.id);for(const s of e)this.removeTrack(s);return e}getTrackSpan(t){const e=this._trackPlayers.get(t);if(!e)return;const s=e.getTrack(),n=s.delay??0;if(rt(s)||nt(s))return{from:n,to:e.getDuration()};const r=s.keyframes;if(!(!r||r.length===0))return{from:r[0].time+n,to:e.getDuration()}}findConflicts(){const t=[];for(let e=0;e<this._tracks.length;e++){const s=this._tracks[e],n=this.getTrackSpan(s.id);if(n)for(let r=0;r<e;r++){const a=this._tracks[r];if(a.property!==s.property)continue;const o=L(a).filter(l=>L(s).includes(l));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=n.to&&n.from<=c.to))continue;const u=n.from>=c.from;for(const l of o)t.push({target:l,property:s.property,losingTrackId:u?a.id:s.id,winningTrackId:u?s.id:a.id})}}return t}_matches(t,e){if(e.id!==void 0&&t.id!==e.id||e.property!==void 0&&t.property!==e.property||e.target!==void 0&&!L(t).includes(e.target))return!1;if(e.timeRange){const s=this.getTrackSpan(t.id);if(!s||s.to<e.timeRange.from||s.from>e.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:se(this._tracks),id:this.id,name:this.name,config:{...this._config},tracks:[...this._tracks],...this.captions&&{captions:this.captions}}}get config(){return this._config}get markers(){return[...this._config.markers??[]].sort((t,e)=>t.time-e.time)}setMarkers(t){const e=t&&t.length>0?[...t].sort((n,r)=>n.time-r.time).map(n=>({...n})):void 0,s={...this._config};e?s.markers=e:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(t){const e={};for(const[s,n]of Object.entries(t??{}))e[s]={...n};this._captions=Object.keys(e).length>0?e:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let t=0;for(const[,e]of this._trackPlayers)t=Math.max(t,e.getDuration());return t}_handleEndReached(){const t=this._config.loop??0;return t===-1||this._loopIteration<t?(this._loopIteration++,this._armRepeatDelay(),this._config.alternate?this._direction="reverse":this._repeatDelayRemaining>0?this._wrapAfterDelay=!0:this._currentTime=0,this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}_handleStartReached(){const t=this._config.loop??0;return this._config.alternate&&(t===-1||this._loopIteration<t)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const 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 Q(i){const t=i.endDelay;return{...i.delay!==void 0&&{delay:i.delay},...t!==void 0&&{endDelay:t},...i.targets!==void 0&&{targets:[...i.targets]},...i.stagger!==void 0&&{stagger:{...i.stagger}}}}function yi(i){if(nt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:gi(t.inertia),...Q(t)}}if(rt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...Q(t)}}if(Mt(i)){const t=i;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((e,s)=>e.time-s.time),...Q(t)}}if(i.property==="motionPath"&&"motionPathConfig"in i){const t=i,e=[...t.keyframes].sort((s,n)=>s.time-n.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:e,...Q(t)}}return ri({id:i.id,target:i.target,property:i.property,keyframes:i.keyframes,...i.interpolation!==void 0&&{interpolation:i.interpolation},...Q(i)})}function tt(i){const t=i.formatVersion??1;if(t>St)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${St}. Update tinyfly to play it.`);return new 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(H(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 zt=new Set(["width","height","top","right","bottom","left","margin","marginTop","marginRight","marginBottom","marginLeft","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","borderRadius","borderWidth","fontSize","lineHeight","letterSpacing","outlineWidth","gap","rowGap","columnGap"]),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"],xi=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),Ii=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"},Gt={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},Ei="http://www.w3.org/2000/svg";class j{targets=new Map;registerTarget(t,e){this.targets.set(t,e)}unregisterTarget(t){this.targets.delete(t)}getTarget(t){return this.targets.get(t)}clearTargets(){this.targets.clear()}applyState(t){for(const[e,s]of t.values){const n=this.targets.get(e);n&&this.applyProperties(n,s)}}applyProperties(t,e){let s=null,n=null,r=null,a=null,o=null;const c=e.has("motionPathX"),h=e.has("motionPathY"),u=e.has("motionPathRotate");for(const[f,d]of e)if(!(f==="x"&&c)&&!(f==="y"&&h)&&!((f==="rotate"||f==="rotateZ")&&u)&&!Ri.has(f)){if(Pi.has(f))(s??={})[f]=d;else if(xi.has(f))typeof d=="number"&&((n??={})[f]=d);else if(Ii.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 Gt){const o=Array.isArray(s)?s.join(", "):String(s);t.style[Gt[e]]=o;return}else e==="fill"&&t.dataset?.elementType==="text"?n="color":n=Di[e]??e;let a;typeof s=="number"?zt.has(e)||zt.has(n)?a=`${s}px`:a=String(s):Array.isArray(s)?a=s.join(", "):a=s,t.style[n]=a}}class yt{media;offset;driftTolerance;constructor(t,e={}){this.media=t,this.offset=e.offset??0,this.driftTolerance=Math.max(0,e.driftTolerance??.15)}targetTime(t){return Math.max(0,t/1e3+this.offset)}update(t,e){const s=this.targetTime(t);e?(this.media.paused&&this.safePlay(),Math.abs(this.media.currentTime-s)>this.driftTolerance&&(this.media.currentTime=s)):(this.media.paused||this.media.pause(),this.media.currentTime!==s&&(this.media.currentTime=s))}seek(t){this.media.currentTime=this.targetTime(t)}setRate(t){this.media.playbackRate=t}dispose(){this.media.paused||this.media.pause()}safePlay(){const t=this.media.play();t&&typeof t.catch=="function"&&t.catch(()=>{})}}function Zt(i,t,e,s,n){const r=e-n;if(r<0){t.paused||t.pause(),t.currentTime=0;return}i.update(r,s)}class Tt{container;timeline=null;adapter;animationFrameId;lastTime;options;targets={};isDestroyed=!1;mediaSync;mediaTargets=[];symbolInstances=[];scenarioList=[];scenarioId;authored=new Map;markerList=[];listeners=new Set;playhead={time:0,iteration:0,direction:"forward"};stepping=!1;lastMarkerId=null;reducedQuery;onReducedChange=()=>this.applyReducedMotion();visibilityObserver;onScreen=!0;pausedByVisibility=!1;autoplayWhenSeen=!1;onDocumentVisibility=()=>this.updateVisibility();constructor(t,e={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=e,this.adapter=new j}async load(t){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(t)}async loadSource(t){let e;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load animation: ${s.statusText}`);e=await s.json()}else e=t;this.useDefinition(e),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(t){const e={...t.config};this.options.speed!==void 0&&(e.speed=this.options.speed),this.options.loop!==void 0&&(e.loop=this.options.loop),this.options.alternate!==void 0&&(e.alternate=this.options.alternate),this.timeline=tt({...t,config:e}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(t,e={}){if(t.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const s=new Set;for(const r of t){if(s.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);s.add(r.id)}const n=e.initial===void 0?t[0]:t.find(r=>r.id===e.initial);if(!n)throw new Error(`tinyfly: there is no scenario "${e.initial}"`);this.scenarioList=[...t],this.scenarioId=n.id,await this.loadSource(n.timeline)}get scenarios(){return this.scenarioList.map(t=>({id:t.id,label:t.label??t.id}))}get scenario(){return this.scenarioId}setScenario(t){const e=this.scenarioList.find(o=>o.id===t);if(!e||!this.timeline)return!1;if(t===this.scenarioId)return!0;const s=this.isPlaying,n=this.currentTime>=this.duration-.5,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=t,this.useDefinition(e.timeline),this.lastMarkerId=null;let a=0;return this.reducedMotion||n?a=this.duration:r!==void 0&&(a=this.markers.find(o=>o.id===r)?.time??0),this.seek(a),s&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(t){if(this.authored.has(t))return;const e={style:t.getAttribute("style")};t.children.length===0&&(e.text=t.textContent??"");const s=t.tagName.toLowerCase()==="path"?t:t.querySelector("path");s&&(e.path={element:s,d:s.getAttribute("d")}),this.authored.set(t,e)}restoreAuthored(){for(const[t,e]of this.authored){e.style===null?t.removeAttribute("style"):t.setAttribute("style",e.style),e.text!==void 0&&t.textContent!==e.text&&(t.textContent=e.text),e.path&&(e.path.d===null?e.path.element.removeAttribute("d"):e.path.element.setAttribute("d",e.path.d));const s=t.dataset;s&&delete s.shineBase}}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notify(){for(const t of this.listeners)t()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const t=this.currentTime;let e;for(const s of this.markers)if(s.time<=t+.5)e=s;else break;return e}caption(t,e){const s=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!s)return;const n=e??this.language(),r=a=>a?.[n]?.[s.id]??a?.[n.split("-")[0]]?.[s.id];return r(this.options.captions)??r(this.timeline?.captions)??s.label}next(){if(!this.timeline)return;const t=this.currentTime,e=this.markers.find(s=>s.time>t+.5);if(this.reducedMotion){this.seek(e?e.time:this.duration);return}t>=this.duration-.5||(this.stepping=e!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const t=this.currentTime,e=[...this.markers].reverse().find(s=>s.time<t-.5);this.pause(),this.seek(e?e.time:0)}goToMarker(t){const e=this.markers.find(s=>s.id===t);e&&(this.pause(),this.seek(e.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const t=this.options.initialFrame??"start";if(t==="none")return;const e=t==="end"?this.timeline.duration:t==="start"?0:t;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,e))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(e=>{for(const s of e)this.onScreen=s.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const t=this.container.getBoundingClientRect?.();t&&(t.width>0||t.height>0)&&(this.onScreen=t.bottom>0&&t.top<window.innerHeight&&t.right>0&&t.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const t=this.onScreen&&document.visibilityState!=="hidden";!t&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):t&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const t=this.currentMarker,e=t?.id;e!==this.lastMarkerId&&(this.lastMarkerId=e,this.options.onMarker(t))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(e=>{const s=e,n=Number(s.getAttribute("data-tinyfly-start")??"0")||0,r=s.getAttribute("data-volume");r!==null&&(s.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:s,startTime:n,sync:new yt(s)})})}syncAllMedia(t,e){for(const s of this.mediaTargets)Zt(s.sync,s.el,t,e,s.startTime)}loadFromString(t){const e=JSON.parse(t);this.load(e)}registerTarget(t,e){if(typeof e=="string"){const s=this.container.querySelector(e);s&&(this.rememberAuthored(s),this.targets[t]=s,this.adapter.registerTarget(t,s))}else this.rememberAuthored(e),this.targets[t]=e,this.adapter.registerTarget(t,e)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(e=>{const s=e.closest("[data-tinyfly-symbol]");if(s&&s!==e)return;const n=e.getAttribute("data-tinyfly");n&&this.registerTarget(n,e)}),this.timeline&&new Set(this.timeline.tracks.map(s=>s.target)).forEach(s=>{if(!this.targets[s]){const n=this.container.querySelector(`[data-tinyfly="${s}"]`)||this.container.querySelector(`.${s}`)||this.container.querySelector(`#${s}`);n&&this.registerTarget(s,n)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const e=new Map(t.map(s=>[s.id,s]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const n=s.getAttribute("data-tinyfly-symbol");if(!n)return;const r=e.get(n);if(!r||!r.timeline.tracks?.length)return;const a=new j;s.querySelectorAll("[data-tinyfly]").forEach(o=>{const c=o.getAttribute("data-tinyfly");c&&a.registerTarget(c,o)}),this.symbolInstances.push({adapter:a,timeline:tt(r.timeline)})})}attachMedia(t,e){this.mediaSync=new yt(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 Tt(i,{...e,autoplay:!0});return await s.load(t),s}function Oi(i,t={}){return new Tt(i,t)}class Kt{container;containerA;containerB;adapterA;adapterB;timelineA=null;timelineB=null;symbolDefs=new Map;nestedByAdapter=new Map;sequence=null;options;_currentSceneIndex=0;_state="idle";_isPlaying=!1;_isDestroyed=!1;loopIteration=0;animationFrameId;lastTime;transitionTimer;constructor(t,e={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=e,this.container.style.position="relative",this.container.style.overflow="hidden",this.containerA=this.createSceneContainer(),this.containerB=this.createSceneContainer(),this.container.appendChild(this.containerA),this.container.appendChild(this.containerB),this.containerB.style.visibility="hidden",this.adapterA=new j,this.adapterB=new j}async load(t){let e;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load sequence: ${s.statusText}`);e=await s.json()}else e=t;this.sequence=e,this.symbolDefs.clear();for(const s of e.symbols??[])s.timeline?.tracks?.length&&this.symbolDefs.set(s.id,s.timeline);this.container.style.width=`${e.canvas.width}px`,this.container.style.height=`${e.canvas.height}px`,e.scenes.length>0&&(this.renderScene(e.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(e.scenes[0])),this.options.autoplay&&this.play()}play(){if(!(!this.sequence||this._isDestroyed)&&this.sequence.scenes.length!==0){if(this._isPlaying=!0,this._state==="idle"){if(this._state="playing-scene",this._currentSceneIndex=0,this.timelineA)this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play();else{this.onSceneComplete();return}this.options.onSceneChange?.(0)}else this._state==="playing-scene"&&this.timelineA&&this.timelineA.play();this.startAnimationLoop()}}pause(){this._isPlaying&&(this._isPlaying=!1,this.timelineA&&this.timelineA.pause(),this.timelineB&&this.timelineB.pause(),this.stopAnimationLoop())}stop(){if(this._isPlaying=!1,this._state="idle",this._currentSceneIndex=0,this.loopIteration=0,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.stopAnimationLoop(),this.sequence&&this.sequence.scenes.length>0&&(this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this.renderScene(this.sequence.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(this.sequence.scenes[0]),this.timelineA)){const t=this.timelineA.getStateAtTime(0);this.adapterA.applyState(t),this.applyNested(this.adapterA,0)}}goToScene(t){if(!this.sequence||t<0||t>=this.sequence.scenes.length)return;const e=this._isPlaying;this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this._currentSceneIndex=t,this._state=e?"playing-scene":"idle",this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB);const s=this.sequence.scenes[t];if(this.renderScene(s,this.containerA,this.adapterA),this.timelineA=this.createTimeline(s),this.options.onSceneChange?.(t),e)this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play(),this.startAnimationLoop()):this.onSceneComplete();else if(this.timelineA){const n=this.timelineA.getStateAtTime(0);this.adapterA.applyState(n),this.applyNested(this.adapterA,0)}}destroy(){this._isDestroyed=!0,this._isPlaying=!1,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.adapterA.clearTargets(),this.adapterB.clearTargets();for(const t of this.nestedByAdapter.values())for(const e of t)e.adapter.clearTargets();this.nestedByAdapter.clear(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.timelineA=null,this.timelineB=null,this.containerA.parentNode&&this.containerA.remove(),this.containerB.parentNode&&this.containerB.remove(),this.sequence=null}get currentSceneIndex(){return this._currentSceneIndex}get sceneCount(){return this.sequence?.scenes.length??0}get isPlaying(){return this._isPlaying}get state(){return this._state}createSceneContainer(){const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.width="100%",t.style.height="100%",t}renderScene(t,e,s){e.innerHTML="",s.clearTargets();const n=document.createElement("div");n.style.cssText="position:absolute;inset:0;transform-origin:center center",n.setAttribute("data-tinyfly","Camera"),e.appendChild(n),s.registerTarget("Camera",n);for(const r of t.elements){if(!r.html)continue;const a=document.createElement("div");a.innerHTML=r.html.trim();const o=a.firstElementChild;if(o){n.appendChild(o);const c=o.getAttribute("data-tinyfly");c&&s.registerTarget(c,o)}}this.setupNested(n,s)}setupNested(t,e){const s=[];t.querySelectorAll("[data-tinyfly-symbol]").forEach(n=>{const r=n.getAttribute("data-tinyfly-symbol");if(!r)return;const a=this.symbolDefs.get(r);if(!a)return;const o=new j;n.querySelectorAll("[data-tinyfly]").forEach(c=>{const h=c.getAttribute("data-tinyfly");h&&o.registerTarget(h,c)}),s.push({adapter:o,timeline:tt(a)})}),s.length?this.nestedByAdapter.set(e,s):this.nestedByAdapter.delete(e)}applyNested(t,e){const s=this.nestedByAdapter.get(t);if(s)for(const n of s){const r=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(r>0?e%r:e))}}clearContainer(t){t.innerHTML=""}createTimeline(t){return t.timeline?tt(t.timeline):null}onSceneComplete(){if(this._isDestroyed||!this.sequence)return;const t=this._currentSceneIndex+1;if(t>=this.sequence.scenes.length){const e=this.options.loop??this.sequence.loop??0;e===-1||e>0&&this.loopIteration<e-1?(this.loopIteration++,this.beginTransitionTo(0)):(this._isPlaying=!1,this._state="idle",this.stopAnimationLoop(),this.options.onComplete?.())}else this.beginTransitionTo(t)}beginTransitionTo(t){if(!this.sequence||this._isDestroyed)return;const e=this.sequence.scenes[t],s=e.transition;if(s.type==="none"||s.duration<=0){this.switchToScene(t);return}this._state="transitioning",this.containerB.style.visibility="visible",this.renderScene(e,this.containerB,this.adapterB),this.timelineB=this.createTimeline(e),this.timelineB&&this.timelineB.play(),this.applyTransition(s.type,s.duration),this.transitionTimer=window.setTimeout(()=>{this.finishTransition(t)},s.duration)}applyTransition(t,e){const s=`${e}ms`,n="ease-in-out";switch(this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),t){case"fade":this.containerB.style.opacity="0";break;case"slide-left":this.containerB.style.transform="translateX(100%)";break;case"slide-right":this.containerB.style.transform="translateX(-100%)";break;case"slide-up":this.containerB.style.transform="translateY(100%)";break;case"slide-down":this.containerB.style.transform="translateY(-100%)";break}switch(this.containerB.offsetHeight,this.containerA.style.transition=`opacity ${s} ${n}, transform ${s} ${n}`,this.containerB.style.transition=`opacity ${s} ${n}, transform ${s} ${n}`,t){case"fade":this.containerA.style.opacity="0",this.containerB.style.opacity="1";break;case"slide-left":this.containerA.style.transform="translateX(-100%)",this.containerB.style.transform="translateX(0)";break;case"slide-right":this.containerA.style.transform="translateX(100%)",this.containerB.style.transform="translateX(0)";break;case"slide-up":this.containerA.style.transform="translateY(-100%)",this.containerB.style.transform="translateY(0)";break;case"slide-down":this.containerA.style.transform="translateY(100%)",this.containerB.style.transform="translateY(0)";break}}resetTransitionStyles(t){t.style.transition="",t.style.opacity="1",t.style.transform=""}finishTransition(t){this.transitionTimer=void 0,this.timelineA&&(this.timelineA.stop(),this.timelineA=null),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.containerA;this.containerA=this.containerB,this.containerB=e;const s=this.adapterA;this.adapterA=this.adapterB,this.adapterB=s,this.timelineA=this.timelineB,this.timelineB=null,this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.playbackState!=="playing"&&this.timelineA.play()):this.onSceneComplete()}switchToScene(t){if(!this.sequence||this._isDestroyed)return;this.timelineA&&this.timelineA.stop(),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.sequence.scenes[t];this.renderScene(e,this.containerA,this.adapterA),this.timelineA=this.createTimeline(e),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play()):this.onSceneComplete()}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=e=>{if(this._isDestroyed||!this._isPlaying)return;const s=e-(this.lastTime??e);if(this.lastTime=e,this.timelineA&&this.timelineA.playbackState==="playing"){this.timelineA.tick(s);const n=this.timelineA.getStateAtTime(this.timelineA.currentTime);this.adapterA.applyState(n),this.applyNested(this.adapterA,this.timelineA.currentTime)}if(this._state==="transitioning"&&this.timelineB&&this.timelineB.playbackState==="playing"){this.timelineB.tick(s);const n=this.timelineB.getStateAtTime(this.timelineB.currentTime);this.adapterB.applyState(n),this.applyNested(this.adapterB,this.timelineB.currentTime)}this._isPlaying?this.animationFrameId=requestAnimationFrame(t):this.animationFrameId=void 0};this.animationFrameId=requestAnimationFrame(t)}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}}async function Li(i,t,e={}){const s=new Kt(i,{...e,autoplay:!0});return await s.load(t),s}const $i={type:"none",duration:0};v.DEFAULT_TRANSITION=$i,v.MediaSync=yt,v.TinyflyPlayer=Tt,v.TinyflySequencer=Kt,v.create=Oi,v.play=Bi,v.playSequence=Li,v.syncMediaElement=Zt,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AnimatableValue } from '../../engine/types';
|
|
2
|
+
/**
|
|
3
|
+
* A 2D camera for canvas scenes: pan, zoom and rotate the whole picture.
|
|
4
|
+
*
|
|
5
|
+
* Like the editor's camera, it is just tracks on a reserved target (named
|
|
6
|
+
* `Camera` by convention) with the properties `x`, `y` (pan, px), `scale`
|
|
7
|
+
* (zoom about the stage centre) and `rotate` (degrees about the centre).
|
|
8
|
+
* Three more add on top for shakes, so a shake never disturbs a pan:
|
|
9
|
+
* `shakeX`, `shakeY` (px) and `shakeRotate` (degrees).
|
|
10
|
+
*
|
|
11
|
+
* A point `p` of the scene lands on screen at
|
|
12
|
+
* `centre + (x, y) + shake + R(rotate) · scale · (p − centre)`.
|
|
13
|
+
*/
|
|
14
|
+
export interface CameraView {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
scale: number;
|
|
18
|
+
rotate: number;
|
|
19
|
+
shakeX: number;
|
|
20
|
+
shakeY: number;
|
|
21
|
+
shakeRotate: number;
|
|
22
|
+
}
|
|
23
|
+
/** The camera that changes nothing. */
|
|
24
|
+
export declare const IDENTITY_CAMERA: CameraView;
|
|
25
|
+
/** The camera's view from a target's animated values (missing ones are identity). */
|
|
26
|
+
export declare function cameraFromValues(values: Map<string, AnimatableValue> | undefined): CameraView;
|
|
27
|
+
/**
|
|
28
|
+
* Transform a context so what is drawn next is seen through the camera.
|
|
29
|
+
* `stage` is the scene's size. While shaking, the picture zooms in just
|
|
30
|
+
* enough that the shake never shows past its edges.
|
|
31
|
+
*/
|
|
32
|
+
export declare function applyCamera(ctx: CanvasRenderingContext2D, view: CameraView, stage: {
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
}): void;
|
|
36
|
+
/** Where a scene point appears through the camera (no shake overscan): for placing captions or checking framing. */
|
|
37
|
+
export declare function cameraPoint(view: CameraView, stage: {
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
}, point: {
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
}): {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
};
|
|
@@ -50,6 +50,8 @@ export { tf, live, createLive, Stage, LiveTimeline, CompatTimeline, quickPlay, m
|
|
|
50
50
|
export { applyBloom } from '../adapters/canvas/bloom';
|
|
51
51
|
export type { BloomOptions } from '../adapters/canvas/bloom';
|
|
52
52
|
export { drawTrail } from '../adapters/canvas/trail';
|
|
53
|
+
export { applyCamera, cameraFromValues, cameraPoint, IDENTITY_CAMERA } from '../adapters/canvas/camera';
|
|
54
|
+
export type { CameraView } from '../adapters/canvas/camera';
|
|
53
55
|
export type { TrailStyle } from '../adapters/canvas/trail';
|
|
54
56
|
export { createControls, DEFAULT_LABELS } from '../embed/controls';
|
|
55
57
|
export type { Controls, ControlsOptions, ControlLabels, FullscreenControl } from '../embed/controls';
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { Keyframe, Track } from '../../engine/types';
|
|
2
|
+
/**
|
|
3
|
+
* Lip-sync from text: the mouth shapes a line of dialogue makes, timed over
|
|
4
|
+
* the span it is spoken in.
|
|
5
|
+
*
|
|
6
|
+
* No audio analysis: the text is read as a sequence of sounds (vowels open
|
|
7
|
+
* the mouth in their shape, m/b/p close it, f/v bite the lip, pauses rest
|
|
8
|
+
* it), and the sounds share the line's time by how long each one tends to
|
|
9
|
+
* take. That is how cartoon lip-sync is usually done by hand (a few mouth
|
|
10
|
+
* shapes, timed to the track), and it is close enough for stick figures and
|
|
11
|
+
* cartoon faces. It reads Latin script and Devanagari.
|
|
12
|
+
*
|
|
13
|
+
* Shapes are the face fields `mouth` (0 closed … 1 wide open) and
|
|
14
|
+
* `mouthWidth` (0.5 pursed … 1.5 wide), which the stick figure and the v2
|
|
15
|
+
* characters both have.
|
|
16
|
+
*/
|
|
17
|
+
/** A mouth shape. */
|
|
18
|
+
export interface Viseme {
|
|
19
|
+
mouth: number;
|
|
20
|
+
mouthWidth: number;
|
|
21
|
+
}
|
|
22
|
+
/** The shapes, after the classic cartoon mouth chart. */
|
|
23
|
+
export declare const VISEMES: {
|
|
24
|
+
/** Closed and relaxed */
|
|
25
|
+
rest: {
|
|
26
|
+
mouth: number;
|
|
27
|
+
mouthWidth: number;
|
|
28
|
+
};
|
|
29
|
+
/** "ah": open wide */
|
|
30
|
+
a: {
|
|
31
|
+
mouth: number;
|
|
32
|
+
mouthWidth: number;
|
|
33
|
+
};
|
|
34
|
+
/** "eh": open, wide */
|
|
35
|
+
e: {
|
|
36
|
+
mouth: number;
|
|
37
|
+
mouthWidth: number;
|
|
38
|
+
};
|
|
39
|
+
/** "ee": a little open, stretched wide */
|
|
40
|
+
i: {
|
|
41
|
+
mouth: number;
|
|
42
|
+
mouthWidth: number;
|
|
43
|
+
};
|
|
44
|
+
/** "oh": round */
|
|
45
|
+
o: {
|
|
46
|
+
mouth: number;
|
|
47
|
+
mouthWidth: number;
|
|
48
|
+
};
|
|
49
|
+
/** "oo": small and pursed */
|
|
50
|
+
u: {
|
|
51
|
+
mouth: number;
|
|
52
|
+
mouthWidth: number;
|
|
53
|
+
};
|
|
54
|
+
/** m, b, p: lips pressed */
|
|
55
|
+
m: {
|
|
56
|
+
mouth: number;
|
|
57
|
+
mouthWidth: number;
|
|
58
|
+
};
|
|
59
|
+
/** f, v: lip under the teeth */
|
|
60
|
+
f: {
|
|
61
|
+
mouth: number;
|
|
62
|
+
mouthWidth: number;
|
|
63
|
+
};
|
|
64
|
+
/** l, th, n, d, t: tongue up, a little open */
|
|
65
|
+
l: {
|
|
66
|
+
mouth: number;
|
|
67
|
+
mouthWidth: number;
|
|
68
|
+
};
|
|
69
|
+
/** Other consonants: slightly open */
|
|
70
|
+
c: {
|
|
71
|
+
mouth: number;
|
|
72
|
+
mouthWidth: number;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export type VisemeName = keyof typeof VISEMES;
|
|
76
|
+
/** One sound of a line: its shape, and how long it takes relative to the others. */
|
|
77
|
+
export interface Sound {
|
|
78
|
+
viseme: VisemeName;
|
|
79
|
+
weight: number;
|
|
80
|
+
}
|
|
81
|
+
/** The sounds of a line, in order. */
|
|
82
|
+
export declare function soundsOf(text: string): Sound[];
|
|
83
|
+
export interface LipSyncOptions {
|
|
84
|
+
/** How wide the mouth opens: 1 as charted, less for mumbling, more for shouting (default 1) */
|
|
85
|
+
energy?: number;
|
|
86
|
+
/** Field names, if not `mouth` and `mouthWidth` */
|
|
87
|
+
fields?: {
|
|
88
|
+
mouth?: string;
|
|
89
|
+
mouthWidth?: string;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** A spoken line: what is said, and when (ms). */
|
|
93
|
+
export interface SpokenLine {
|
|
94
|
+
text: string;
|
|
95
|
+
start: number;
|
|
96
|
+
end: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Mouth keyframes for a line spoken from `start` to `end` ms: closed at the
|
|
100
|
+
* start, a shape per sound, closed again at the end. Keys are in time order,
|
|
101
|
+
* for the `mouth` and `mouthWidth` fields.
|
|
102
|
+
*/
|
|
103
|
+
export declare function lipSyncKeyframes(line: SpokenLine, options?: LipSyncOptions): Record<string, Keyframe<number>[]>;
|
|
104
|
+
/** Mouth tracks on `target` for several spoken lines (in time order, not overlapping). */
|
|
105
|
+
export declare function lipSyncTracks(target: string, lines: SpokenLine[], options?: LipSyncOptions): Track[];
|
|
106
|
+
/**
|
|
107
|
+
* Tracks with spoken lines lip-synced over their mouth: during each line the
|
|
108
|
+
* lip-sync shapes replace the `mouth` and `mouthWidth` keys, starting and
|
|
109
|
+
* ending on whatever the face was doing, so a shocked gape or a grin carries
|
|
110
|
+
* on around the speech. Other tracks pass through. Fields missing from
|
|
111
|
+
* `tracks` start from `rest` (default: closed, normal width).
|
|
112
|
+
*/
|
|
113
|
+
export declare function lipSyncOver(target: string, tracks: Track[], lines: SpokenLine[], options?: LipSyncOptions & {
|
|
114
|
+
rest?: Record<string, number>;
|
|
115
|
+
}): Track[];
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Track } from '../../engine/types';
|
|
2
|
+
import { type ExpressionName, type PoseKey, type PoseName, type StickPose } from '../stick-figure';
|
|
3
|
+
import { type GaitName } from '../gaits';
|
|
4
|
+
import { type GagName } from './gags';
|
|
5
|
+
import { type SpokenLine } from './lip-sync';
|
|
6
|
+
import type { ActingOptions } from './acting';
|
|
7
|
+
/**
|
|
8
|
+
* Beat scripts: a story written as what a character does, compiled into
|
|
9
|
+
* acted tracks.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const { tracks, duration, lines } = scriptTracks('crow', [
|
|
13
|
+
* { do: 'walk', to: 600, mood: 'sad' },
|
|
14
|
+
* { do: 'look', toward: 900, mood: 'surprised' },
|
|
15
|
+
* { do: 'take' },
|
|
16
|
+
* { do: 'say', say: 'A pot of water!', mood: 'joyful' },
|
|
17
|
+
* { do: 'run', to: 880 },
|
|
18
|
+
* { do: 'cheer', for: 1200 },
|
|
19
|
+
* ], { from: 200, height: 170, style: 'snappy' })
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Each beat starts when the one before it ends (or at `at`). Walking beats
|
|
23
|
+
* move the figure (its `x` track, as an offset from where it was placed at
|
|
24
|
+
* `from`), turn it to face the way it goes, and pick the gait; pose beats key
|
|
25
|
+
* a named pose; gag beats splice in a gag; `say` lip-syncs a line. The poses
|
|
26
|
+
* then go through the acting pass, so the result winds up, overshoots and
|
|
27
|
+
* overlaps like any `actTracks()` output. Everything is plain keyframes.
|
|
28
|
+
*/
|
|
29
|
+
/** The ways to get somewhere. */
|
|
30
|
+
export type GaitAction = GaitName;
|
|
31
|
+
/** Everything a beat can do. */
|
|
32
|
+
export type Action = GaitAction | PoseName | GagName | 'look' | 'say' | 'hold' | 'stand' | 'face' | 'zip';
|
|
33
|
+
export interface Beat {
|
|
34
|
+
/** What happens */
|
|
35
|
+
do: Action;
|
|
36
|
+
/** When it starts, ms (default: when the beat before ends) */
|
|
37
|
+
at?: number;
|
|
38
|
+
/** How long it takes, ms (default: the action's own length) */
|
|
39
|
+
for?: number;
|
|
40
|
+
/** Walking: where to, scene x */
|
|
41
|
+
to?: number;
|
|
42
|
+
/** `look` and `face`: a scene x, or `viewer` (front-on), `ahead` or `back` */
|
|
43
|
+
toward?: number | 'viewer' | 'ahead' | 'back';
|
|
44
|
+
/** The face for the beat */
|
|
45
|
+
mood?: ExpressionName;
|
|
46
|
+
/** Spoken during the beat, lip-synced (with `do: 'say'`, the beat lasts as long as the line) */
|
|
47
|
+
say?: string;
|
|
48
|
+
/** Joints to change on top of the action's pose */
|
|
49
|
+
pose?: Partial<StickPose>;
|
|
50
|
+
}
|
|
51
|
+
export interface ScriptOptions extends ActingOptions {
|
|
52
|
+
/** Scene x the figure was placed at (its `x` track is an offset from here; default 0) */
|
|
53
|
+
from?: number;
|
|
54
|
+
/** Figure height, px, for stride length (default 300, the stick figure's) */
|
|
55
|
+
height?: number;
|
|
56
|
+
/** Which way it faces at the start (default 1, screen-right) */
|
|
57
|
+
facing?: 1 | -1;
|
|
58
|
+
/** The pose it starts in (default rest) */
|
|
59
|
+
start?: StickPose;
|
|
60
|
+
/** Lip-sync energy (default 1) */
|
|
61
|
+
energy?: number;
|
|
62
|
+
}
|
|
63
|
+
export interface ScriptResult {
|
|
64
|
+
/** Every track the script writes, on the target */
|
|
65
|
+
tracks: Track[];
|
|
66
|
+
/** When the last beat ends, ms */
|
|
67
|
+
duration: number;
|
|
68
|
+
/** The spoken lines with their times, for captions */
|
|
69
|
+
lines: SpokenLine[];
|
|
70
|
+
/** The key poses, before acting */
|
|
71
|
+
keys: PoseKey[];
|
|
72
|
+
/** When each beat starts and ends, ms */
|
|
73
|
+
beats: Array<{
|
|
74
|
+
start: number;
|
|
75
|
+
end: number;
|
|
76
|
+
}>;
|
|
77
|
+
/** Effects to draw, with when and where (scene x on the ground): dust where a zip leaves and where a take lands */
|
|
78
|
+
effects: ScriptEffect[];
|
|
79
|
+
}
|
|
80
|
+
/** A cartoon effect a script asks for: draw it with `drawDustPuff` (progress from `time`, over `length` ms). */
|
|
81
|
+
export interface ScriptEffect {
|
|
82
|
+
kind: 'dust';
|
|
83
|
+
time: number;
|
|
84
|
+
/** Scene x on the ground */
|
|
85
|
+
x: number;
|
|
86
|
+
/** How long it shows, ms */
|
|
87
|
+
length: number;
|
|
88
|
+
}
|
|
89
|
+
/** Time for one gait cycle (two steps), ms. */
|
|
90
|
+
export declare const GAIT_CYCLE_MS: Record<GaitName, number>;
|
|
91
|
+
/** How long a line takes to say, ms. */
|
|
92
|
+
export declare function speechDuration(text: string): number;
|
|
93
|
+
/** Compile beats into tracks on `target` (a `stickFigureTarget`). */
|
|
94
|
+
export declare function scriptTracks(target: string, beats: Beat[], options?: ScriptOptions): ScriptResult;
|