@algorisys/tinyfly 0.68.1 → 0.70.1

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/lib/cli/tools.js CHANGED
@@ -2247,6 +2247,38 @@ function validateEmbed(definition, options = {}) {
2247
2247
  }
2248
2248
  return problems;
2249
2249
  }
2250
+ function choiceIdsIn(markup) {
2251
+ const ids = /* @__PURE__ */ new Set();
2252
+ for (const match of markup.matchAll(/data-tinyfly-choose\s*=\s*("([^"]*)"|'([^']*)')/g)) ids.add(match[2] ?? match[3]);
2253
+ return [...ids];
2254
+ }
2255
+ function validateScenarios(scenarios, options = {}) {
2256
+ const problems = [];
2257
+ if (scenarios.length === 1) problems.push({ level: "warning", message: "only one scenario, so the reader has nothing to choose" });
2258
+ const ids = /* @__PURE__ */ new Set();
2259
+ const used = /* @__PURE__ */ new Set();
2260
+ for (const scenario of scenarios) {
2261
+ if (ids.has(scenario.id)) {
2262
+ problems.push({ level: "error", message: `scenario id "${scenario.id}" is used more than once` });
2263
+ continue;
2264
+ }
2265
+ ids.add(scenario.id);
2266
+ for (const problem of validateEmbed(scenario.timeline, options)) {
2267
+ if (/is never animated$/.test(problem.message)) continue;
2268
+ problems.push({ level: problem.level, message: `scenario "${scenario.id}": ${problem.message}` });
2269
+ }
2270
+ for (const track of scenario.timeline.tracks) for (const target of [track.target, ...track.targets ?? []]) used.add(target);
2271
+ }
2272
+ if (options.markup !== void 0) {
2273
+ for (const id of choiceIdsIn(options.markup)) {
2274
+ if (!ids.has(id)) problems.push({ level: "error", message: `data-tinyfly-choose="${id}" names no scenario` });
2275
+ }
2276
+ for (const name of targetNamesIn(options.markup)) {
2277
+ if (!used.has(name)) problems.push({ level: "warning", message: `data-tinyfly="${name}" is never animated in any scenario` });
2278
+ }
2279
+ }
2280
+ return problems;
2281
+ }
2250
2282
  function renderFrame(markup, definition, at = "end") {
2251
2283
  const timeline = deserializeTimeline(definition);
2252
2284
  const markers = definition.config?.markers ?? [];
@@ -2338,5 +2370,6 @@ function escapeText(value) {
2338
2370
  export {
2339
2371
  renderFrame,
2340
2372
  targetNamesIn,
2341
- validateEmbed
2373
+ validateEmbed,
2374
+ validateScenarios
2342
2375
  };
@@ -1,5 +1,5 @@
1
- (function(O){"use strict";function ce(e){return typeof e=="object"&&e!==null&&e.type==="cubic-bezier"}function le(e){return typeof e=="object"&&e!==null&&e.type!=="cubic-bezier"}const U=1;function _t(e){return e.property==="text"&&"textConfig"in e}function lt(e){return e.kind==="inertia"&&"inertia"in e}function ht(e){return e.kind==="spring"&&"spring"in e}function he(e){return e.property==="motionPath"&&"motionPathConfig"in e}function xt(e,t,s="start"){if(t<=1)return 0;if(typeof s=="number"){const n=Math.max(0,Math.min(t-1,s));return Math.abs(e-n)}switch(s){case"end":return t-1-e;case"center":return Math.abs(e-(t-1)/2);case"edges":return(t-1)/2-Math.abs(e-(t-1)/2);default:return e}}function ue(e,t="start"){if(e<=1)return 0;let s=0;for(let n=0;n<e;n++)s=Math.max(s,xt(n,e,t));return s}function vt(e,t,s){if(s.offsets)return s.offsets[e]??0;const n=s.from??"start",i=xt(e,t,n);if(s.amount!==void 0){const r=ue(t,n);return r===0?0:s.amount*i/r}return s.each!==void 0?s.each*i:0}function fe(e,t){return Array.from({length:e},(s,n)=>vt(n,e,t))}function ut(e,t){return e<=1?0:Math.max(...fe(e,t))}const j=1,At=6e4,tt=At/j,q={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1};class de{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??q.stiffness,this.damping=t.damping??q.damping,this.mass=t.mass??q.mass,this.restDelta=t.restDelta??q.restDelta,this.restSpeed=t.restSpeed??q.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=t.velocity??q.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 s=Math.floor(t/j);if(this.simulateTo(s+1),this.settledStep!==null&&s>=this.settledStep)return this.to;const n=this.samples[Math.min(s,this.samples.length-1)],i=this.samples[Math.min(s+1,this.samples.length-1)],r=t/j-s;return n+(i-n)*r}settleTime(){return this.simulateTo(tt+1),this.settledStep!==null?this.settledStep*j:At}simulateTo(t){if(this.settledStep!==null)return;const s=Math.min(t,tt+1),n=j/1e3;for(;this.samples.length<s;){const i=this.samples[this.samples.length-1],r=i-this.to,a=-this.stiffness*r,o=-this.damping*this.velocity,c=(a+o)/this.mass;this.velocity+=c*n;const l=i+this.velocity*n;if(this.samples.push(l),this.isAtRest(l)){this.settledStep=this.samples.length-1;return}}this.samples.length>tt&&(this.settledStep=tt)}}const Pt=4,pe=.002,me=1e-4,ge=6e4;function ft(e){const t=e.friction??Pt;return t>0?t:Pt}function ye(e){return e.from+e.velocity/ft(e)}function be(e,t){if(t===void 0)return e;if(typeof t=="number")return t>0?Math.round(e/t)*t:e;if(t.length===0)return e;let s=t[0];for(const n of t)Math.abs(n-e)<Math.abs(s-e)&&(s=n);return s}function It(e){let t=be(ye(e),e.end);return e.min!==void 0&&(t=Math.max(e.min,t)),e.max!==void 0&&(t=Math.min(e.max,t)),t}function Ct(e){const t=Math.abs(It(e)-e.from);if(t===0)return 0;const s=e.restDelta??Math.max(me,t*pe);if(s>=t)return 0;const n=Math.log(t/s)/ft(e);return Math.min(ge,n*1e3)}function Rt(e,t){if(t<=0)return e.from;const s=It(e);if(t>=Ct(e))return s;const n=ft(e);return e.from+(s-e.from)*(1-Math.exp(-n*t/1e3))}const dt=e=>e,ke=e=>e*e,Me=e=>1-(1-e)*(1-e),Te=e=>e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2,Et=e=>e*e*e,Dt=e=>1-Math.pow(1-e,3),$t=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,Se={linear:dt,"ease-in":Et,"ease-out":Dt,"ease-in-out":$t,"ease-in-quad":ke,"ease-out-quad":Me,"ease-in-out-quad":Te,"ease-in-cubic":Et,"ease-out-cubic":Dt,"ease-in-out-cubic":$t};function we(e){const[t,s,n,i]=e,r=3*t,a=3*(n-t)-r,o=1-r-a,c=3*s,l=3*(i-s)-c,u=1-c-l,h=p=>((o*p+a)*p+r)*p,f=p=>((u*p+l)*p+c)*p,d=p=>(3*o*p+2*a)*p+r,b=p=>{let m=p;for(let T=0;T<8;T++){const w=h(m)-p;if(Math.abs(w)<1e-7)return m;const g=d(m);if(Math.abs(g)<1e-7)break;m-=w/g}let k=0,y=1;for(m=p;k<y;){const T=h(m);if(Math.abs(T-p)<1e-7)return m;p>T?k=m:y=m,m=(k+y)/2}return m};return p=>{if(p<=0)return 0;if(p>=1)return 1;const m=b(p);return f(m)}}function pt(e,t="out"){if(t==="out")return e;const s=n=>1-e(1-n);return t==="in"?s:n=>n<.5?s(n*2)/2:e(n*2-1)/2+.5}function _e(e=1,t=.3){const s=Math.max(1,e),n=t/(2*Math.PI)*Math.asin(1/s);return i=>i<=0?0:i>=1?1:s*Math.pow(2,-10*i)*Math.sin((i-n)*(2*Math.PI)/t)+1}const xe=e=>{if(e<=0)return 0;if(e>=1)return 1;if(e<1/2.75)return 7.5625*e*e;if(e<2/2.75){const i=e-.5454545454545454;return 7.5625*i*i+.75}if(e<2.5/2.75){const i=e-.8181818181818182;return 7.5625*i*i+.9375}const n=e-2.625/2.75;return 7.5625*n*n+.984375};function ve(e=1.70158){return t=>{if(t<=0)return 0;if(t>=1)return 1;const s=t-1;return s*s*((e+1)*s+e)+1}}function Ae(e,t="end"){const s=Math.max(1,Math.floor(e));return n=>{if(n>=1)return 1;if(n<=0)return t==="start"||t==="both"?t==="start"?1/s:1/(s+1):0;const i=Math.floor(n*s);switch(t){case"start":return Math.min(1,(i+1)/s);case"both":return(i+1)/(s+1);case"none":return s===1?0:Math.min(1,i/(s-1));default:return i/s}}}function Pe(e){switch(e.type){case"steps":return Ae(e.count,e.position);case"elastic":return pt(_e(e.amplitude,e.period),e.mode);case"bounce":return pt(xe,e.mode);case"back":return pt(ve(e.overshoot),e.mode)}}function Ie(e){return e===void 0?dt:ce(e)?we(e.points):le(e)?Pe(e):Se[e]??dt}const Ot=32,Ce=256,H=new Map,Re=/[MmLlHhVvCcSsQqTtAaZz]/,Ee=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,De={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function $e(e){const t=[];let s=0,n=null;const i=()=>{for(;s<e.length&&/[\s,]/.test(e[s]);)s++};for(;s<e.length&&(i(),!(s>=e.length));){const r=e[s];if(Re.test(r)){n={type:r,args:[]},t.push(n),s++;continue}if(!n)break;const a=n.type==="A"||n.type==="a",o=n.args.length%7;if(a&&(o===3||o===4)){if(r!=="0"&&r!=="1")break;n.args.push(r==="1"?1:0),s++;continue}const c=Ee.exec(e.slice(s));if(!c)break;n.args.push(parseFloat(c[0])),s+=c[0].length}return t}function Oe(e,t,s,n,i,r,a,o,c){if(e===o&&t===c)return[];let l=Math.abs(s),u=Math.abs(n);if(l===0||u===0)return[[e,t,o,c,o,c]];const h=i*Math.PI/180,f=Math.cos(h),d=Math.sin(h),b=(e-o)/2,p=(t-c)/2,m=f*b+d*p,k=-d*b+f*p,y=m*m/(l*l)+k*k/(u*u);if(y>1){const P=Math.sqrt(y);l*=P,u*=P}const T=r===a?-1:1,w=l*l*u*u-l*l*k*k-u*u*m*m,g=l*l*k*k+u*u*m*m,_=T*Math.sqrt(Math.max(0,w/g)),S=_*l*k/u,I=-_*u*m/l,W=f*S-d*I+(e+o)/2,x=d*S+f*I+(t+c)/2,C=(P,R,$,B)=>{const wt=P*$+R*B,ct=Math.sqrt((P*P+R*R)*($*$+B*B)),J=Math.acos(Math.max(-1,Math.min(1,wt/ct)));return P*B-R*$<0?-J:J},A=C(1,0,(m-S)/l,(k-I)/u);let M=C((m-S)/l,(k-I)/u,(-m-S)/l,(-k-I)/u);!a&&M>0&&(M-=2*Math.PI),a&&M<0&&(M+=2*Math.PI);const v=Math.max(1,Math.ceil(Math.abs(M)/(Math.PI/2))),L=M/v,E=4/3*Math.tan(L/4),D=P=>{const R=l*Math.cos(P),$=u*Math.sin(P);return[f*R-d*$+W,d*R+f*$+x]},Z=P=>{const R=-l*Math.sin(P),$=u*Math.cos(P);return[f*R-d*$,d*R+f*$]},K=[];for(let P=0;P<v;P++){const R=A+P*L,$=R+L,[B,wt]=D(R),[ct,J]=P===v-1?[o,c]:D($),[Bs,Us]=Z(R),[js,Hs]=Z($);K.push([B+E*Bs,wt+E*Us,ct-E*js,J-E*Hs,ct,J])}return K}function F(e,t,s,n,i){const r=1-i;return r*r*r*e+3*r*r*i*t+3*r*i*i*s+i*i*i*n}function Lt(e,t,s,n,i){const r=1-i;return 3*r*r*(t-e)+6*r*i*(s-t)+3*i*i*(n-s)}function z(e,t,s,n){return{subpath:0,type:"L",points:[s,n],startX:e,startY:t,endX:s,endY:n,length:Math.hypot(s-e,n-t)}}function et(e,t,s){const[n,i,r,a,o,c]=s,l=[0];let u=e,h=t,f=0;for(let d=1;d<=Ot;d++){const b=d/Ot,p=F(e,n,r,o,b),m=F(t,i,a,c,b);f+=Math.hypot(p-u,m-h),l.push(f),u=p,h=m}return{subpath:0,type:"C",points:[n,i,r,a,o,c],startX:e,startY:t,endX:o,endY:c,length:f,lengths:l}}function st(e){const t=H.get(e);if(t)return t;const s=[];let n=0,i=0,r=0,a=0,o=null,c=null,l=-1;const u=new Set,h=p=>{l<0&&(l=0),p.subpath=l,s.push(p)};for(const{type:p,args:m}of $e(e)){const k=p.toUpperCase(),y=p!==k,T=De[k];if(k==="Z"){(n!==r||i!==a)&&h(z(n,i,r,a)),l>=0&&u.add(l),n=r,i=a,o=c=null;continue}for(let w=0;w+T<=m.length;w+=T){const g=m.slice(w,w+T),_=y?n:0,S=y?i:0;let I=null,W=null;switch(k){case"M":w===0?(n=g[0]+_,i=g[1]+S,r=n,a=i,(l<0||s[s.length-1]?.subpath===l)&&l++):(h(z(n,i,g[0]+_,g[1]+S)),n=g[0]+_,i=g[1]+S);break;case"L":h(z(n,i,g[0]+_,g[1]+S)),n=g[0]+_,i=g[1]+S;break;case"H":h(z(n,i,g[0]+_,i)),n=g[0]+_;break;case"V":h(z(n,i,n,g[0]+S)),i=g[0]+S;break;case"C":{const x=[g[0]+_,g[1]+S,g[2]+_,g[3]+S,g[4]+_,g[5]+S];h(et(n,i,x)),I=[x[2],x[3]],n=x[4],i=x[5];break}case"S":{const[x,C]=o?[2*n-o[0],2*i-o[1]]:[n,i],A=[x,C,g[0]+_,g[1]+S,g[2]+_,g[3]+S];h(et(n,i,A)),I=[A[2],A[3]],n=A[4],i=A[5];break}case"Q":case"T":{let x=n,C=i;k==="Q"?(x=g[0]+_,C=g[1]+S):c&&(x=2*n-c[0],C=2*i-c[1]);const A=k==="Q"?g[2]+_:g[0]+_,M=k==="Q"?g[3]+S:g[1]+S;h(et(n,i,[n+2/3*(x-n),i+2/3*(C-i),A+2/3*(x-A),M+2/3*(C-M),A,M])),W=[x,C],n=A,i=M;break}case"A":{const x=g[5]+_,C=g[6]+S;let A=n,M=i;for(const v of Oe(n,i,g[0],g[1],g[2],g[3],g[4],x,C))h(et(A,M,v)),A=v[4],M=v[5];n=x,i=C;break}}o=I,c=W}}const f=s.reduce((p,m)=>p+m.length,0),d=[];for(let p=0;p<s.length;){const m=s[p].subpath;let k=p,y=0;for(;k<s.length&&s[k].subpath===m;)y+=s[k++].length;const T=s[p],w=s[k-1],g=u.has(m)||Math.abs(w.endX-T.startX)<1e-9&&Math.abs(w.endY-T.startY)<1e-9;d.push({start:p,end:k,length:y,closed:g}),p=k}const b={segments:s,totalLength:f,subpaths:d};return H.size>=Ce&&H.delete(H.keys().next().value),H.set(e,b),b}function Le(e,t){const s=e.lengths;if(t<=0)return 0;if(t>=e.length)return 1;let n=0,i=s.length-1;for(;n<i-1;){const o=n+i>>1;s[o]<t?n=o:i=o}const r=s[i]-s[n],a=r>0?(t-s[n])/r:0;return(n+a)/(s.length-1)}function Ne(e,t){if(e.type==="L"){const h=e.length>0?Math.max(0,Math.min(1,t/e.length)):0;return{x:e.startX+(e.endX-e.startX)*h,y:e.startY+(e.endY-e.startY)*h,angle:Math.atan2(e.endY-e.startY,e.endX-e.startX)*180/Math.PI}}const[s,n,i,r,a,o]=e.points,c=Le(e,t);let l=Lt(e.startX,s,i,a,c),u=Lt(e.startY,n,r,o,c);if(Math.hypot(l,u)<1e-9){const h=c<.5?Math.min(1,c+.001):Math.max(0,c-.001),f=F(e.startX,s,i,a,h),d=F(e.startY,n,r,o,h),b=F(e.startX,s,i,a,c),p=F(e.startY,n,r,o,c);l=c<.5?f-b:b-f,u=c<.5?d-p:p-d}return{x:F(e.startX,s,i,a,c),y:F(e.startY,n,r,o,c),angle:Math.atan2(u,l)*180/Math.PI}}function Nt(e,t,s=0,n=e.length){if(n<=s)return{x:0,y:0,angle:0};let i=0;for(let r=s;r<n;r++){const a=e[r];if(i+a.length>=t||r===n-1)return Ne(a,t-i);i+=a.length}return{x:0,y:0,angle:0}}function Fe(e,t){const{segments:s,totalLength:n}=st(e);return Nt(s,Math.max(0,Math.min(1,t))*n)}const Xe=24,Ye=320,qe=2.5,G=72,Ve=.2,We=128,nt=new Map;let mt=0,X;const Ft=e=>Math.round(e*100)/100;function Xt(e,t){const{segments:s,subpaths:n,totalLength:i}=st(e);if(s.length===0)return[];if(t){const r=n.every(a=>a.closed);return[{segments:s,start:0,end:s.length,length:i,closed:r}]}return n.filter(r=>r.length>0).map(r=>({segments:s,start:r.start,end:r.end,length:r.length,closed:r.closed}))}function gt(e,t){const s=e.closed?(t%1+1)%1:Math.max(0,Math.min(1,t)),n=Nt(e.segments,s*e.length,e.start,e.end);return[n.x,n.y]}function Yt(e){const t=[];let s=0;for(let n=e.start;n<e.end;n++)s+=e.segments[n].length,e.length>0&&t.push(s/e.length);return t}function qt(e,t){const s=[];for(let n=0;n<t;n++)s.push(gt(e,e.closed?n/t:n/(t-1)));return s}function Vt(e){let t=0,s=0;for(const[n,i]of e)t+=n,s+=i;return t/=e.length,s/=e.length,e.map(([n,i])=>[n-t,i-s])}function Be(e,t,s){const n=e.closed&&t.closed;if(s!==void 0)return{offset:n?Math.abs(s)%G/G:0,reversed:s<0};const i=Vt(qt(e,G)),r=Vt(qt(t,G)),a=G;let o={offset:0,reversed:!1},c=1/0;for(const l of[!1,!0]){const u=n?a:1;for(let h=0;h<u;h++){let f=0;for(let d=0;d<a&&f<c;d++){const b=n?l?(h-d+a)%a:(d+h)%a:l?a-1-d:d,p=i[d][0]-r[b][0],m=i[d][1]-r[b][1];f+=p*p+m*m}f<c&&(c=f,o={offset:n?h/a:0,reversed:l})}}return o}function Ue(e,t,s){return s?((t.reversed?t.offset-e:e+t.offset)%1+1)%1:t.reversed?1-e:e}function je(e,t,s){return s?((t.reversed?t.offset-e:e-t.offset)%1+1)%1:t.reversed?1-e:e}function He(e,t,s){const n=e.closed&&t.closed,i=Be(e,t,s.shapeIndex),r=Math.max(Xe,Math.min(Ye,Math.ceil(Math.max(e.length,t.length)/qe))),a=new Set,o=h=>a.add(Math.round(h*1e7)/1e7);for(let h=0;h<=r;h++)o(h/r);for(const h of Yt(e))o(h);for(const h of Yt(t))o(je(h,i,n));let c=[...a].sort((h,f)=>h-f);n&&(c=c.filter(h=>h<1));const l=[],u=[];for(const h of c)l.push(...gt(e,h)),u.push(...gt(t,Ue(h,i,n)));return ze({from:l,to:u,closed:n})}function ze(e){const t=e.from.length/2;if(t<=3)return e;const s=new Uint8Array(t);s[0]=1,s[t-1]=1;const n=[[0,t-1]];for(;n.length>0;){const[a,o]=n.pop();let c=-1,l=Ve;for(let u=a+1;u<o;u++){const h=Math.max(Wt(e.from,a,o,u),Wt(e.to,a,o,u));h>l&&(l=h,c=u)}c!==-1&&(s[c]=1,n.push([a,c],[c,o]))}const i=[],r=[];for(let a=0;a<t;a++)s[a]&&(i.push(e.from[a*2],e.from[a*2+1]),r.push(e.to[a*2],e.to[a*2+1]));return{from:i,to:r,closed:e.closed}}function Wt(e,t,s,n){const i=e[t*2],r=e[t*2+1],a=e[s*2]-i,o=e[s*2+1]-r,c=e[n*2]-i,l=e[n*2+1]-r,u=a*a+o*o,h=u===0?0:Math.max(0,Math.min(1,(c*a+l*o)/u));return Math.hypot(c-h*a,l-h*o)}function Ge(e,t,s){const n=s.shapeIndex;if(X&&X.from===e&&X.to===t&&X.shapeIndex===n)return X.plan;const r=nt.get(String(n??"auto"))?.get(e)?.get(t);if(r)return X={from:e,to:t,shapeIndex:n,plan:r},r;const a=st(e).subpaths.filter(d=>d.length>0).length===st(t).subpaths.filter(d=>d.length>0).length,o=Xt(e,!a),c=Xt(t,!a),l={pairs:o.map((d,b)=>He(d,c[b],s))};mt>=We&&(nt.clear(),mt=0);const u=String(n??"auto"),h=nt.get(u)??new Map;nt.set(u,h);const f=h.get(e)??new Map;return h.set(e,f),f.set(t,l),mt++,X={from:e,to:t,shapeIndex:n,plan:l},l}function Qe(e,t,s,n={}){if(!e)return t;if(!t)return e;const i=Math.max(0,Math.min(1,s));if(i===0)return e;if(i===1)return t;const r=Ge(e,t,n);if(r.pairs.length===0)return i<.5?e:t;let a="";for(const o of r.pairs){for(let c=0;c<o.from.length;c+=2){const l=Ft(o.from[c]+(o.to[c]-o.from[c])*i),u=Ft(o.from[c+1]+(o.to[c+1]-o.from[c+1])*i);a+=`${c===0?a?" M":"M":" L"}${l} ${u}`}o.closed&&(a+=" Z")}return a}function Ze(e){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(e)}const N=(e,t,s)=>e+(t-e)*s,Bt=512,yt=new Map,bt=new Map;function Ut(e){const t=yt.get(e);if(t)return t;const s=e.replace("#",""),n=[parseInt(s.slice(0,2),16),parseInt(s.slice(2,4),16),parseInt(s.slice(4,6),16)];return yt.size<Bt&&yt.set(e,n),n}const jt=e=>e.charCodeAt(0)===35,Ht=e=>e.startsWith("rgb"),zt=e=>e.startsWith("rgba"),Ke=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,kt=e=>Math.round(e).toString(16).padStart(2,"0");function Je(e,t,s){return`#${kt(e)}${kt(t)}${kt(s)}`}function Gt(e){const t=bt.get(e);if(t)return t;const s=e.match(Ke);if(!s)throw new Error(`Invalid rgb color: ${e}`);const n=parseInt(s[1],10),i=parseInt(s[2],10),r=parseInt(s[3],10),a=s[4]!==void 0?[n,i,r,parseFloat(s[4])]:[n,i,r];return bt.size<Bt&&bt.set(e,a),a}const ts=(e,t,s)=>{if(jt(e)&&jt(t)){const[n,i,r]=Ut(e),[a,o,c]=Ut(t),l=N(n,a,s),u=N(i,o,s),h=N(r,c,s);return Je(l,u,h)}if((Ht(e)||zt(e))&&(Ht(t)||zt(t))){const n=Gt(e),i=Gt(t),r=Math.round(N(n[0],i[0],s)),a=Math.round(N(n[1],i[1],s)),o=Math.round(N(n[2],i[2],s));if(n.length===4||i.length===4){const c=n[3]??1,l=i[3]??1,u=N(c,l,s);return`rgba(${r}, ${a}, ${o}, ${u})`}return`rgb(${r}, ${a}, ${o})`}return s<1?e:t},es=(e,t,s)=>{const n=Math.min(e.length,t.length),i=[];for(let r=0;r<n;r++)i.push(N(e[r],t[r],s));return i},Qt=(e,t,s)=>s<1?e:t,ss=(e,t,s)=>Qe(e,t,s);function ns(e){return typeof e=="number"?N:Array.isArray(e)?es:typeof e=="string"?e.startsWith("#")||e.startsWith("rgb")?ts:Ze(e)?ss:Qt:Qt}function is(e){const t=[...e.keyframes].sort((s,n)=>s.time-n.time);return{...e,keyframes:t}}function Y(e){return e.targets&&e.targets.length>0?e.targets:[e.target]}function V(e,t,s,n){const i=s??0;return!n||t<=1?i:i+vt(e,t,n)}class Mt{track;targets;constructor(t){this.track=t,this.targets=Y(t)}getValueAtTime(t){return this.valueForOffset(t-V(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const s=this.targets.length,n=[];for(let i=0;i<s;i++){const r=V(i,s,this.track.delay,this.track.stagger),a=this.valueForOffset(t-r);a!==void 0&&n.push({target:this.targets[i],value:a,start:r+this.track.keyframes[0].time})}return n}getDuration(){const{keyframes:t}=this.track;if(t.length===0)return 0;const s=t[t.length-1].time,n=this.track.stagger?ut(this.targets.length,this.track.stagger):0;return s+(this.track.delay??0)+n+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(t){const{keyframes:s}=this.track;if(s.length===0)return;if(s.length===1||t<=s[0].time)return s[0].value;if(t>=s[s.length-1].time)return s[s.length-1].value;const{from:n,to:i}=this.findSurroundingKeyframes(t);if(!n||!i)return;if(n.time===t)return n.value;const r=i.time-n.time,a=(t-n.time)/r,c=Ie(i.easing)(a);return ns(n.value)(n.value,i.value,c)}findSurroundingKeyframes(t){const{keyframes:s}=this.track;for(let n=0;n<s.length-1;n++)if(t>=s[n].time&&t<=s[n+1].time)return{from:s[n],to:s[n+1]};return{from:null,to:null}}}class rs{track;targets;sampler;constructor(t){this.track=t,this.targets=Y(t),this.sampler=new de(t.spring)}getValueAtTime(t){return this.sampler.valueAt(t-V(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const s=this.targets.length,n=[];for(let i=0;i<s;i++){const r=V(i,s,this.track.delay,this.track.stagger);n.push({target:this.targets[i],value:this.sampler.valueAt(t-r),start:r})}return n}getDuration(){const t=this.track.stagger?ut(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+t}getTrack(){return this.track}}class as{track;targets;duration;constructor(t){this.track=t,this.targets=Y(t),this.duration=Ct(t.inertia)}getValueAtTime(t){return Rt(this.track.inertia,t-V(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const s=this.targets.length,n=[];for(let i=0;i<s;i++){const r=V(i,s,this.track.delay,this.track.stagger);n.push({target:this.targets[i],value:Rt(this.track.inertia,t-r),start:r})}return n}getDuration(){const t=this.track.stagger?ut(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+t}getTrack(){return this.track}}function os(e,t){const s={...Fe(e.pathData,t)};if(e.matrix){const[n,i,r,a,o,c]=e.matrix,{x:l,y:u}=s;s.x=n*l+r*u+o,s.y=i*l+a*u+c;const h=s.angle*Math.PI/180,f=Math.cos(h),d=Math.sin(h);s.angle=Math.atan2(i*f+a*d,n*f+r*d)*180/Math.PI}return e.autoRotate&&e.rotateOffset&&(s.angle+=e.rotateOffset),s}const Tt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},cs=20;function ls(e){const t=Tt[e??"upperCase"]??e??Tt.upperCase,s=Array.from(t);return s.length>0?s:Array.from(Tt.upperCase)}function hs(e,t,s){let n=(e|0)^Math.imul(t+1,2654435761)^Math.imul(s+1,2246822507);return n=Math.imul(n^n>>>16,2146121005),n=Math.imul(n^n>>>15,2221713035),(n^n>>>16)>>>0}function us(e,t,s=0){const n=e.from??"",i=e.to,r=Math.max(0,Math.min(1,t));if(r<=0)return n;if(r>=1)return i;const a=Array.from(n),o=Array.from(i),c=e.rightToLeft??!1;if(e.mode==="type"){const y=Math.round(r*Math.max(a.length,o.length));return c?a.slice(0,Math.max(0,a.length-y)).join("")+o.slice(Math.max(0,o.length-y)).join(""):o.slice(0,y).join("")+a.slice(y).join("")}const l=Math.max(0,Math.min(.999,e.revealDelay??0)),u=Math.max(0,(r-l)/(1-l)),h=Math.floor(u*o.length),f=e.tweenLength===!1?o.length:Math.round(a.length+(o.length-a.length)*r),d=ls(e.chars),b=e.refreshRate??cs,p=b>0?Math.floor(s*b/1e3):0,m=e.seed??1;let k="";for(let y=0;y<f;y++){const T=c?y>=f-h:y<h,w=c?o[o.length-(f-y)]:o[y];T&&w!==void 0||w===" "||w===`
2
- `?k+=w:k+=d[hs(m,y,p)%d.length]}return k}class fs{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 s of t.tracks)this.addTrack(s)}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 s={...this._config};delete s.duration,this._config=s}}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 s=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(t,s)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(t){if(this._playbackState!=="playing")return;const s=this.duration;if(s<=0)return;let i=t*this.speed;if(this._repeatDelayRemaining>0){const o=Math.min(this._repeatDelayRemaining,i);if(this._repeatDelayRemaining-=o,i-=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&&i>0&&this._playbackState==="playing";o++)if(this._direction==="forward"){const c=s-this._currentTime;if(i>=c){if(i-=c,this._currentTime=s,!this._handleEndReached())break}else this._currentTime+=i,i=0}else{const c=this._currentTime;if(i>=c){if(i-=c,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=i,i=0}const a=this.getStateAtTime(this._currentTime);this.onUpdate?.(a)}getStateAtTime(t){const s=new Map;if(this._hasSharedWrites())this._resolveShared(t,s);else for(const[n,i]of this._trackPlayers){const r=i.getTrack().property;for(const{target:a,value:o,start:c}of i.getTargetValues(t))this._write(s,n,a,r,o,t-c)}return{values:s,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(t,s){const n=new Map;for(const[i,r]of this._trackPlayers){const a=r.getTrack().property;for(const{target:o,value:c,start:l}of r.getTargetValues(t)){const u=`${o}\0${a}`,h=l<=t,f=n.get(u);(!f||(h!==f.started?h:h?l>=f.start:l<=f.start))&&n.set(u,{trackId:i,target:o,property:a,value:c,start:l,started:h})}}for(const{trackId:i,target:r,property:a,value:o,start:c}of n.values())this._write(s,i,r,a,o,t-c)}_write(t,s,n,i,r,a){if(r===void 0)return;let o=t.get(n);o||(o=new Map,t.set(n,o));const c=this._textTracks.get(s);if(c&&typeof r=="number"){o.set("text",us(c.textConfig,r,Math.max(0,a)));return}const l=this._motionPathTracks.get(s);if(l&&typeof r=="number"){const u=os(l.motionPathConfig,r);o.set("motionPathX",u.x),o.set("motionPathY",u.y),l.motionPathConfig.autoRotate&&o.set("motionPathRotate",u.angle)}else o.set(i,r)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const t=new Set;this._sharedWrites=!1;t:for(const s of this._tracks)for(const n of Y(s)){const i=`${n}\0${s.property}`;if(t.has(i)){this._sharedWrites=!0;break t}t.add(i)}}return this._sharedWrites}addTrack(t){if(this._tracks.push(t),this._sharedWrites=null,lt(t)){this._trackPlayers.set(t.id,new as(t));return}if(ht(t)){this._trackPlayers.set(t.id,new rs(t)),this._springTracks.set(t.id,t);return}if(_t(t))this._trackPlayers.set(t.id,new Mt(t)),this._textTracks.set(t.id,t);else if(he(t)){const s={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(s)),this._motionPathTracks.set(t.id,t)}else this._trackPlayers.set(t.id,new Mt(t))}replaceTrack(t,s){const n=this._tracks.findIndex(r=>r.id===t);if(n<0)return;const i=this._tracks.slice(n+1);this.removeTrack(t);for(const r of i)this.removeTrack(r.id);this.addTrack(s);for(const r of i)this.addTrack(r)}removeTrack(t){this._tracks=this._tracks.filter(s=>s.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(s=>this._matches(s,t))}removeTracks(t={}){const s=this.getTracks(t).map(n=>n.id);for(const n of s)this.removeTrack(n);return s}getTrackSpan(t){const s=this._trackPlayers.get(t);if(!s)return;const n=s.getTrack(),i=n.delay??0;if(ht(n)||lt(n))return{from:i,to:s.getDuration()};const r=n.keyframes;if(!(!r||r.length===0))return{from:r[0].time+i,to:s.getDuration()}}findConflicts(){const t=[];for(let s=0;s<this._tracks.length;s++){const n=this._tracks[s],i=this.getTrackSpan(n.id);if(i)for(let r=0;r<s;r++){const a=this._tracks[r];if(a.property!==n.property)continue;const o=Y(a).filter(h=>Y(n).includes(h));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=i.to&&i.from<=c.to))continue;const u=i.from>=c.from;for(const h of o)t.push({target:h,property:n.property,losingTrackId:u?a.id:n.id,winningTrackId:u?n.id:a.id})}}return t}_matches(t,s){if(s.id!==void 0&&t.id!==s.id||s.property!==void 0&&t.property!==s.property||s.target!==void 0&&!Y(t).includes(s.target))return!1;if(s.timeRange){const n=this.getTrackSpan(t.id);if(!n||n.to<s.timeRange.from||n.from>s.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:U,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,s)=>t.time-s.time)}setMarkers(t){const s=t&&t.length>0?[...t].sort((i,r)=>i.time-r.time).map(i=>({...i})):void 0,n={...this._config};s?n.markers=s:delete n.markers,this._config=n}get captions(){return this._captions}setCaptions(t){const s={};for(const[n,i]of Object.entries(t??{}))s[n]={...i};this._captions=Object.keys(s).length>0?s:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let t=0;for(const[,s]of this._trackPlayers)t=Math.max(t,s.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 ds=100;function ps(e,t,s,n){const i=[],r=[],{duration:a,alternate:o}=n,c=(d,b,p,m)=>{r.push([d,b]);const k=[];e.forEach((y,T)=>{(p==="forward"?(m?y>=d:y>d)&&y<=b:(m?y<=d:y<d)&&y>=b)&&k.push(T)}),k.sort((y,T)=>(p==="forward"?e[y]-e[T]:e[T]-e[y])||y-T);for(const y of k)i.push({kind:"event",index:y,direction:p})};let l=t.time,u=t.direction,h=t.fresh===!0;const f=Math.min(ds,Math.max(0,s.iteration-t.iteration));for(let d=0;d<f;d++){const b=u==="forward"?a:0;c(l,b,u,h),i.push({kind:"repeat"}),o?(u=u==="forward"?"reverse":"forward",l=b,h=!1):(l=u==="forward"?0:a,h=!0)}return f>0&&n.holding&&!o?{crossings:i,passes:r}:(c(l,s.time,u,h),{crossings:i,passes:r})}function ms(e){return{...e,...Array.isArray(e.end)&&{end:[...e.end]}}}function Q(e){const t=e.endDelay;return{...e.delay!==void 0&&{delay:e.delay},...t!==void 0&&{endDelay:t},...e.targets!==void 0&&{targets:[...e.targets]},...e.stagger!==void 0&&{stagger:{...e.stagger}}}}function gs(e){if(lt(e)){const t=e;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:ms(t.inertia),...Q(t)}}if(ht(e)){const t=e;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...Q(t)}}if(_t(e)){const t=e;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((s,n)=>s.time-n.time),...Q(t)}}if(e.property==="motionPath"&&"motionPathConfig"in e){const t=e,s=[...t.keyframes].sort((n,i)=>n.time-i.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:s,...Q(t)}}return is({id:e.id,target:e.target,property:e.property,keyframes:e.keyframes,...Q(e)})}function it(e){const t=e.formatVersion??1;if(t>U)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${U}. Update tinyfly to play it.`);return new fs({id:e.id,name:e.name,config:e.config,tracks:e.tracks.map(gs),captions:e.captions})}const ys=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),bs="#ffffff",ks="rgba(0, 0, 0, 0.5)";function Ms(e){const t=[];if(e.blur!==void 0&&t.push(`blur(${Math.max(0,e.blur)}px)`),e.brightness!==void 0&&t.push(`brightness(${Math.max(0,e.brightness)})`),e.glow!==void 0&&t.push(`drop-shadow(0 0 ${Math.max(0,e.glow)}px ${e.glowColor??bs})`),e.shadowX!==void 0||e.shadowY!==void 0||e.shadowBlur!==void 0){const s=e.shadowX??0,n=e.shadowY??0,i=Math.max(0,e.shadowBlur??0);t.push(`drop-shadow(${s}px ${n}px ${i}px ${e.shadowColor??ks})`)}return t.length>0?t.join(" "):null}function Ts(e,t){const s=e.childNodes.length===1?e.firstChild:null;if(s&&s.nodeType===3){const n=s;n.data!==t&&(n.data=t);return}e.textContent!==t&&(e.textContent=t)}function Ss(e){if(!("ownerSVGElement"in e))return;const t=e.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"]),ws=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","motionPathX","motionPathY","motionPathRotate"]),_s=new Set(["originX","originY"]),xs=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),vs={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},Kt={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},As="http://www.w3.org/2000/svg";class St{targets=new Map;registerTarget(t,s){this.targets.set(t,s)}unregisterTarget(t){this.targets.delete(t)}getTarget(t){return this.targets.get(t)}clearTargets(){this.targets.clear()}applyState(t){for(const[s,n]of t.values){const i=this.targets.get(s);i&&this.applyProperties(i,n)}}applyProperties(t,s){const n=[];let i=null,r=null,a=null;const o=s.has("motionPathX"),c=s.has("motionPathY"),l=s.has("motionPathRotate");for(const[f,d]of s)if(!(f==="x"&&o)&&!(f==="y"&&c)&&!((f==="rotate"||f==="rotateZ")&&l)){if(ws.has(f)){const b=this.buildTransformPart(f,d);b&&n.push(b)}else if(_s.has(f))typeof d=="number"&&((i??={})[f]=d);else if(xs.has(f))typeof d=="number"&&((r??={})[f]=d);else if(ys.has(f))(a??={})[f]=d;else if(f!=="perspective"){if(f!=="shine")if(f==="text"&&typeof d=="string")Ts(t,d);else if(f==="d"&&typeof d=="string"){const b=t;(b.tagName?.toLowerCase()==="path"?b:b.querySelector?.("path"))?.setAttribute?.("d",d)}else this.applyStyleProperty(t,f,d)}}const u=s.get("shine");typeof u=="number"&&this.applyShine(t,u);const h=s.get("perspective");if(typeof h=="number"&&n.unshift(`perspective(${h}px)`),n.length>0&&(t.style.transform=n.join(" "),Ss(t)),i){const f=i.originX??50,d=i.originY??50;t.style.transformOrigin=`${f}% ${d}%`}if(r){const f=r.clipTop??0,d=r.clipRight??0,b=r.clipBottom??0,p=r.clipLeft??0;t.style.clipPath=`inset(${f}% ${d}% ${b}% ${p}%)`}if(a){const f=Ms(a);f&&(t.style.filter=f)}}buildTransformPart(t,s){if(typeof s!="number")return null;switch(t){case"x":case"motionPathX":return`translateX(${s}px)`;case"y":case"motionPathY":return`translateY(${s}px)`;case"z":return`translateZ(${s}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${s}deg)`;case"rotateX":return`rotateX(${s}deg)`;case"rotateY":return`rotateY(${s}deg)`;case"scale":return`scale(${s})`;case"scaleX":return`scaleX(${s})`;case"scaleY":return`scaleY(${s})`;case"scaleZ":return`scaleZ(${s})`;case"skewX":return`skewX(${s}deg)`;case"skewY":return`skewY(${s}deg)`;default:return null}}applyShine(t,s){t.dataset.shineBase||(t.dataset.shineBase=t.style.color||"currentColor");const n=t.dataset.shineBase,i=-20+s*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(${n}, ${n})`,r.backgroundSize="250% 100%, 100% 100%",r.backgroundPosition=`${i}% 0, 0 0`,r.backgroundRepeat="no-repeat",r.webkitBackgroundClip="text",r.backgroundClip="text"}applyStyleProperty(t,s,n){let i;if(t.namespaceURI===As&&s in Kt){const o=Array.isArray(n)?n.join(", "):String(n);t.style[Kt[s]]=o;return}else s==="fill"&&t.dataset?.elementType==="text"?i="color":i=vs[s]??s;let a;typeof n=="number"?Zt.has(s)||Zt.has(i)?a=`${n}px`:a=String(n):Array.isArray(n)?a=n.join(", "):a=n,t.style[i]=a}}class Jt{media;offset;driftTolerance;constructor(t,s={}){this.media=t,this.offset=s.offset??0,this.driftTolerance=Math.max(0,s.driftTolerance??.15)}targetTime(t){return Math.max(0,t/1e3+this.offset)}update(t,s){const n=this.targetTime(t);s?(this.media.paused&&this.safePlay(),Math.abs(this.media.currentTime-n)>this.driftTolerance&&(this.media.currentTime=n)):(this.media.paused||this.media.pause(),this.media.currentTime!==n&&(this.media.currentTime=n))}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 Ps(e,t,s,n,i){const r=s-i;if(r<0){t.paused||t.pause(),t.currentTime=0;return}e.update(r,n)}class rt{container;timeline=null;adapter;animationFrameId;lastTime;options;targets={};isDestroyed=!1;mediaSync;mediaTargets=[];symbolInstances=[];markerList=[];listeners=new Set;playhead={time:0,iteration:0,direction:"forward"};stepping=!1;lastMarkerId=null;reducedQuery;onReducedChange=()=>this.applyReducedMotion();visibilityObserver;onScreen=!0;pausedByVisibility=!1;autoplayWhenSeen=!1;onDocumentVisibility=()=>this.updateVisibility();constructor(t,s={}){if(typeof t=="string"){const n=document.querySelector(t);if(!n)throw new Error(`Container not found: ${t}`);this.container=n}else this.container=t;this.options=s,this.adapter=new St}async load(t){let s;if(typeof t=="string"){const n=await fetch(t);if(!n.ok)throw new Error(`Failed to load animation: ${n.statusText}`);s=await n.json()}else s=t;this.options.speed!==void 0&&(s.config={...s.config,speed:this.options.speed}),this.options.loop!==void 0&&(s.config={...s.config,loop:this.options.loop}),this.options.alternate!==void 0&&(s.config={...s.config,alternate:this.options.alternate}),this.timeline=it(s),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia(),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notify(){for(const t of this.listeners)t()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const t=this.currentTime;let s;for(const n of this.markers)if(n.time<=t+.5)s=n;else break;return s}caption(t,s){const n=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!n)return;const i=s??this.language(),r=a=>a?.[i]?.[n.id]??a?.[i.split("-")[0]]?.[n.id];return r(this.options.captions)??r(this.timeline?.captions)??n.label}next(){if(!this.timeline)return;const t=this.currentTime,s=this.markers.find(n=>n.time>t+.5);if(this.reducedMotion){this.seek(s?s.time:this.duration);return}t>=this.duration-.5||(this.stepping=s!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const t=this.currentTime,s=[...this.markers].reverse().find(n=>n.time<t-.5);this.pause(),this.seek(s?s.time:0)}goToMarker(t){const s=this.markers.find(n=>n.id===t);s&&(this.pause(),this.seek(s.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 s=t==="end"?this.timeline.duration:t==="start"?0:t;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,s))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.listeners.clear(),this.visibilityObserver=new IntersectionObserver(s=>{for(const n of s)this.onScreen=n.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,s=t?.id;s!==this.lastMarkerId&&(this.lastMarkerId=s,this.options.onMarker(t))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(s=>{const n=s,i=Number(n.getAttribute("data-tinyfly-start")??"0")||0,r=n.getAttribute("data-volume");r!==null&&(n.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:n,startTime:i,sync:new Jt(n)})})}syncAllMedia(t,s){for(const n of this.mediaTargets)Ps(n.sync,n.el,t,s,n.startTime)}loadFromString(t){const s=JSON.parse(t);this.load(s)}registerTarget(t,s){if(typeof s=="string"){const n=this.container.querySelector(s);n&&(this.targets[t]=n,this.adapter.registerTarget(t,n))}else this.targets[t]=s,this.adapter.registerTarget(t,s)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(s=>{const n=s.closest("[data-tinyfly-symbol]");if(n&&n!==s)return;const i=s.getAttribute("data-tinyfly");i&&this.registerTarget(i,s)}),this.timeline&&new Set(this.timeline.tracks.map(n=>n.target)).forEach(n=>{if(!this.targets[n]){const i=this.container.querySelector(`[data-tinyfly="${n}"]`)||this.container.querySelector(`.${n}`)||this.container.querySelector(`#${n}`);i&&this.registerTarget(n,i)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const s=new Map(t.map(n=>[n.id,n]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(n=>{const i=n.getAttribute("data-tinyfly-symbol");if(!i)return;const r=s.get(i);if(!r||!r.timeline.tracks?.length)return;const a=new St;n.querySelectorAll("[data-tinyfly]").forEach(o=>{const c=o.getAttribute("data-tinyfly");c&&a.registerTarget(c,o)}),this.symbolInstances.push({adapter:a,timeline:it(r.timeline)})})}attachMedia(t,s){this.mediaSync=new Jt(t,s),this.timeline&&(this.mediaSync.setRate(this.timeline.speed),this.mediaSync.update(this.timeline.currentTime,this.isPlaying))}detachMedia(){this.mediaSync?.dispose(),this.mediaSync=void 0}play(){!this.timeline||this.isDestroyed||(this.autoplayWhenSeen=!1,this.stepping=this.options.stepMode===!0,this.startPlaying())}startPlaying(){if(!this.timeline||this.isDestroyed)return;const t=this.timeline.playbackState==="idle";this.timeline.play(),t&&this.timeline.currentTime===0&&this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.update(this.timeline.currentTime,!0),this.syncAllMedia(this.timeline.currentTime,!0),this.startAnimationLoop(),this.notify()}pause(){this.timeline&&(this.stepping=!1,this.timeline.pause(),this.notify(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1),this.stopAnimationLoop())}stop(){this.timeline&&(this.timeline.stop(),this.stopAnimationLoop(),this.applyState(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1))}seek(t){this.timeline&&(this.timeline.seek(t),this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.seek(this.timeline.currentTime),this.syncAllMedia(this.timeline.currentTime,this.isPlaying))}setSpeed(t){this.timeline&&(this.timeline.speed=t,this.mediaSync?.setRate(t))}reverse(){this.timeline&&this.timeline.reverse()}get currentTime(){return this.timeline?.currentTime??0}get duration(){return this.timeline?.duration??0}get isPlaying(){return this.timeline?.playbackState==="playing"}destroy(){this.isDestroyed=!0,this.stopAnimationLoop(),this.reducedQuery?.removeEventListener?.("change",this.onReducedChange),this.visibilityObserver?.disconnect(),typeof document<"u"&&document.removeEventListener("visibilitychange",this.onDocumentVisibility),this.mediaSync?.dispose(),this.mediaSync=void 0;for(const t of this.mediaTargets)t.el.paused||t.el.pause();this.mediaTargets=[],this.adapter.clearTargets();for(const t of this.symbolInstances)t.adapter.clearTargets();this.symbolInstances=[],this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=s=>{if(this.isDestroyed||!this.timeline)return;const n=s-(this.lastTime??s);this.lastTime=s;const i=this.playhead;this.timeline.tick(n),this.stopAtMarker(i),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 s=this.timeline,n={time:s.currentTime,iteration:s.loopIteration,direction:s.direction};this.playhead=n;const i=this.markers;if(i.length===0)return;const{crossings:r}=ps(i.map(a=>a.time),t,n,{duration:s.duration,alternate:s.config.alternate===!0,holding:s.repeatDelayRemaining>0});for(const a of r){if(a.kind!=="event")continue;const o=i[a.index];if(this.stepping||o.pause){this.stepping=!1,s.pause(),s.seek(o.time),this.playhead={time:o.time,iteration:s.loopIteration,direction:s.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 s of this.symbolInstances){const n=s.timeline.duration;s.adapter.applyState(s.timeline.getStateAtTime(n>0?t%n:t))}}}async function Is(e,t,s={}){const n=new rt(e,{...s,autoplay:!0});return await n.load(t),n}function Cs(e,t={}){return new rt(e,t)}const te={play:"Play",pause:"Pause",prev:"Previous step",next:"Next step",restart:"Restart",scrub:"Position",speed:"Speed",reveal:"Reveal",step:"Step",of:"of",stepFormat:"{index} / {total}"},ee="tinyfly-controls-style",Rs=`
1
+ (function($){"use strict";function fe(e){return typeof e=="object"&&e!==null&&e.type==="cubic-bezier"}function pe(e){return typeof e=="object"&&e!==null&&e.type!=="cubic-bezier"}const H=1;function _t(e){return e.property==="text"&&"textConfig"in e}function lt(e){return e.kind==="inertia"&&"inertia"in e}function ht(e){return e.kind==="spring"&&"spring"in e}function me(e){return e.property==="motionPath"&&"motionPathConfig"in e}function At(e,t,n="start"){if(t<=1)return 0;if(typeof n=="number"){const s=Math.max(0,Math.min(t-1,n));return Math.abs(e-s)}switch(n){case"end":return t-1-e;case"center":return Math.abs(e-(t-1)/2);case"edges":return(t-1)/2-Math.abs(e-(t-1)/2);default:return e}}function ge(e,t="start"){if(e<=1)return 0;let n=0;for(let s=0;s<e;s++)n=Math.max(n,At(s,e,t));return n}function Et(e,t,n){if(n.offsets)return n.offsets[e]??0;const s=n.from??"start",i=At(e,t,s);if(n.amount!==void 0){const r=ge(t,s);return r===0?0:n.amount*i/r}return n.each!==void 0?n.each*i:0}function ye(e,t){return Array.from({length:e},(n,s)=>Et(s,e,t))}function ut(e,t){return e<=1?0:Math.max(...ye(e,t))}const z=1,Pt=6e4,et=Pt/z,B={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1};class be{from;to;stiffness;damping;mass;restDelta;restSpeed;distance;samples;velocity;settledStep=null;constructor(t){this.from=t.from,this.to=t.to,this.stiffness=t.stiffness??B.stiffness,this.damping=t.damping??B.damping,this.mass=t.mass??B.mass,this.restDelta=t.restDelta??B.restDelta,this.restSpeed=t.restSpeed??B.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=t.velocity??B.velocity,this.isAtRest(this.from)&&(this.settledStep=0)}isAtRest(t){return Math.abs(t-this.to)<this.restDelta*this.distance&&Math.abs(this.velocity)<this.restSpeed*this.distance}valueAt(t){if(t<=0)return this.from;const n=Math.floor(t/z);if(this.simulateTo(n+1),this.settledStep!==null&&n>=this.settledStep)return this.to;const s=this.samples[Math.min(n,this.samples.length-1)],i=this.samples[Math.min(n+1,this.samples.length-1)],r=t/z-n;return s+(i-s)*r}settleTime(){return this.simulateTo(et+1),this.settledStep!==null?this.settledStep*z:Pt}simulateTo(t){if(this.settledStep!==null)return;const n=Math.min(t,et+1),s=z/1e3;for(;this.samples.length<n;){const i=this.samples[this.samples.length-1],r=i-this.to,a=-this.stiffness*r,o=-this.damping*this.velocity,c=(a+o)/this.mass;this.velocity+=c*s;const l=i+this.velocity*s;if(this.samples.push(l),this.isAtRest(l)){this.settledStep=this.samples.length-1;return}}this.samples.length>et&&(this.settledStep=et)}}const Ct=4,ve=.002,ke=1e-4,xe=6e4;function dt(e){const t=e.friction??Ct;return t>0?t:Ct}function we(e){return e.from+e.velocity/dt(e)}function Me(e,t){if(t===void 0)return e;if(typeof t=="number")return t>0?Math.round(e/t)*t:e;if(t.length===0)return e;let n=t[0];for(const s of t)Math.abs(s-e)<Math.abs(n-e)&&(n=s);return n}function It(e){let t=Me(we(e),e.end);return e.min!==void 0&&(t=Math.max(e.min,t)),e.max!==void 0&&(t=Math.min(e.max,t)),t}function Rt(e){const t=Math.abs(It(e)-e.from);if(t===0)return 0;const n=e.restDelta??Math.max(ke,t*ve);if(n>=t)return 0;const s=Math.log(t/n)/dt(e);return Math.min(xe,s*1e3)}function $t(e,t){if(t<=0)return e.from;const n=It(e);if(t>=Rt(e))return n;const s=dt(e);return e.from+(n-e.from)*(1-Math.exp(-s*t/1e3))}const ft=e=>e,Se=e=>e*e,Te=e=>1-(1-e)*(1-e),_e=e=>e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2,Dt=e=>e*e*e,Lt=e=>1-Math.pow(1-e,3),Ot=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,Ae={linear:ft,"ease-in":Dt,"ease-out":Lt,"ease-in-out":Ot,"ease-in-quad":Se,"ease-out-quad":Te,"ease-in-out-quad":_e,"ease-in-cubic":Dt,"ease-out-cubic":Lt,"ease-in-out-cubic":Ot};function Ee(e){const[t,n,s,i]=e,r=3*t,a=3*(s-t)-r,o=1-r-a,c=3*n,l=3*(i-n)-c,u=1-c-l,h=p=>((o*p+a)*p+r)*p,d=p=>((u*p+l)*p+c)*p,f=p=>(3*o*p+2*a)*p+r,g=p=>{let m=p;for(let k=0;k<8;k++){const M=h(m)-p;if(Math.abs(M)<1e-7)return m;const y=f(m);if(Math.abs(y)<1e-7)break;m-=M/y}let b=0,v=1;for(m=p;b<v;){const k=h(m);if(Math.abs(k-p)<1e-7)return m;p>k?b=m:v=m,m=(b+v)/2}return m};return p=>{if(p<=0)return 0;if(p>=1)return 1;const m=g(p);return d(m)}}function pt(e,t="out"){if(t==="out")return e;const n=s=>1-e(1-s);return t==="in"?n:s=>s<.5?n(s*2)/2:e(s*2-1)/2+.5}function Pe(e=1,t=.3){const n=Math.max(1,e),s=t/(2*Math.PI)*Math.asin(1/n);return i=>i<=0?0:i>=1?1:n*Math.pow(2,-10*i)*Math.sin((i-s)*(2*Math.PI)/t)+1}const Ce=e=>{if(e<=0)return 0;if(e>=1)return 1;if(e<1/2.75)return 7.5625*e*e;if(e<2/2.75){const i=e-.5454545454545454;return 7.5625*i*i+.75}if(e<2.5/2.75){const i=e-.8181818181818182;return 7.5625*i*i+.9375}const s=e-2.625/2.75;return 7.5625*s*s+.984375};function Ie(e=1.70158){return t=>{if(t<=0)return 0;if(t>=1)return 1;const n=t-1;return n*n*((e+1)*n+e)+1}}function Re(e,t="end"){const n=Math.max(1,Math.floor(e));return s=>{if(s>=1)return 1;if(s<=0)return t==="start"||t==="both"?t==="start"?1/n:1/(n+1):0;const i=Math.floor(s*n);switch(t){case"start":return Math.min(1,(i+1)/n);case"both":return(i+1)/(n+1);case"none":return n===1?0:Math.min(1,i/(n-1));default:return i/n}}}function $e(e){switch(e.type){case"steps":return Re(e.count,e.position);case"elastic":return pt(Pe(e.amplitude,e.period),e.mode);case"bounce":return pt(Ce,e.mode);case"back":return pt(Ie(e.overshoot),e.mode)}}function De(e){return e===void 0?ft:fe(e)?Ee(e.points):pe(e)?$e(e):Ae[e]??ft}const Nt=32,Le=256,G=new Map,Oe=/[MmLlHhVvCcSsQqTtAaZz]/,Ne=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,Fe={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function Xe(e){const t=[];let n=0,s=null;const i=()=>{for(;n<e.length&&/[\s,]/.test(e[n]);)n++};for(;n<e.length&&(i(),!(n>=e.length));){const r=e[n];if(Oe.test(r)){s={type:r,args:[]},t.push(s),n++;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),n++;continue}const c=Ne.exec(e.slice(n));if(!c)break;s.args.push(parseFloat(c[0])),n+=c[0].length}return t}function Ye(e,t,n,s,i,r,a,o,c){if(e===o&&t===c)return[];let l=Math.abs(n),u=Math.abs(s);if(l===0||u===0)return[[e,t,o,c,o,c]];const h=i*Math.PI/180,d=Math.cos(h),f=Math.sin(h),g=(e-o)/2,p=(t-c)/2,m=d*g+f*p,b=-f*g+d*p,v=m*m/(l*l)+b*b/(u*u);if(v>1){const A=Math.sqrt(v);l*=A,u*=A}const k=r===a?-1:1,M=l*l*u*u-l*l*b*b-u*u*m*m,y=l*l*b*b+u*u*m*m,S=k*Math.sqrt(Math.max(0,M/y)),x=S*l*b/u,P=-S*u*m/l,W=d*x-f*P+(e+o)/2,T=f*x+d*P+(t+c)/2,R=(A,I,L,j)=>{const Tt=A*L+I*j,ct=Math.sqrt((A*A+I*I)*(L*L+j*j)),tt=Math.acos(Math.max(-1,Math.min(1,Tt/ct)));return A*j-I*L<0?-tt:tt},_=R(1,0,(m-x)/l,(b-P)/u);let C=R((m-x)/l,(b-P)/u,(-m-x)/l,(-b-P)/u);!a&&C>0&&(C-=2*Math.PI),a&&C<0&&(C+=2*Math.PI);const O=Math.max(1,Math.ceil(Math.abs(C)/(Math.PI/2))),w=C/O,E=4/3*Math.tan(w/4),F=A=>{const I=l*Math.cos(A),L=u*Math.sin(A);return[d*I-f*L+W,f*I+d*L+T]},N=A=>{const I=-l*Math.sin(A),L=u*Math.cos(A);return[d*I-f*L,f*I+d*L]},D=[];for(let A=0;A<O;A++){const I=_+A*w,L=I+w,[j,Tt]=F(I),[ct,tt]=A===O-1?[o,c]:F(L),[rs,as]=N(I),[os,cs]=N(L);D.push([j+E*rs,Tt+E*as,ct-E*os,tt-E*cs,ct,tt])}return D}function Y(e,t,n,s,i){const r=1-i;return r*r*r*e+3*r*r*i*t+3*r*i*i*n+i*i*i*s}function Ft(e,t,n,s,i){const r=1-i;return 3*r*r*(t-e)+6*r*i*(n-t)+3*i*i*(s-n)}function Q(e,t,n,s){return{subpath:0,type:"L",points:[n,s],startX:e,startY:t,endX:n,endY:s,length:Math.hypot(n-e,s-t)}}function nt(e,t,n){const[s,i,r,a,o,c]=n,l=[0];let u=e,h=t,d=0;for(let f=1;f<=Nt;f++){const g=f/Nt,p=Y(e,s,r,o,g),m=Y(t,i,a,c,g);d+=Math.hypot(p-u,m-h),l.push(d),u=p,h=m}return{subpath:0,type:"C",points:[s,i,r,a,o,c],startX:e,startY:t,endX:o,endY:c,length:d,lengths:l}}function st(e){const t=G.get(e);if(t)return t;const n=[];let s=0,i=0,r=0,a=0,o=null,c=null,l=-1;const u=new Set,h=p=>{l<0&&(l=0),p.subpath=l,n.push(p)};for(const{type:p,args:m}of Xe(e)){const b=p.toUpperCase(),v=p!==b,k=Fe[b];if(b==="Z"){(s!==r||i!==a)&&h(Q(s,i,r,a)),l>=0&&u.add(l),s=r,i=a,o=c=null;continue}for(let M=0;M+k<=m.length;M+=k){const y=m.slice(M,M+k),S=v?s:0,x=v?i:0;let P=null,W=null;switch(b){case"M":M===0?(s=y[0]+S,i=y[1]+x,r=s,a=i,(l<0||n[n.length-1]?.subpath===l)&&l++):(h(Q(s,i,y[0]+S,y[1]+x)),s=y[0]+S,i=y[1]+x);break;case"L":h(Q(s,i,y[0]+S,y[1]+x)),s=y[0]+S,i=y[1]+x;break;case"H":h(Q(s,i,y[0]+S,i)),s=y[0]+S;break;case"V":h(Q(s,i,s,y[0]+x)),i=y[0]+x;break;case"C":{const T=[y[0]+S,y[1]+x,y[2]+S,y[3]+x,y[4]+S,y[5]+x];h(nt(s,i,T)),P=[T[2],T[3]],s=T[4],i=T[5];break}case"S":{const[T,R]=o?[2*s-o[0],2*i-o[1]]:[s,i],_=[T,R,y[0]+S,y[1]+x,y[2]+S,y[3]+x];h(nt(s,i,_)),P=[_[2],_[3]],s=_[4],i=_[5];break}case"Q":case"T":{let T=s,R=i;b==="Q"?(T=y[0]+S,R=y[1]+x):c&&(T=2*s-c[0],R=2*i-c[1]);const _=b==="Q"?y[2]+S:y[0]+S,C=b==="Q"?y[3]+x:y[1]+x;h(nt(s,i,[s+2/3*(T-s),i+2/3*(R-i),_+2/3*(T-_),C+2/3*(R-C),_,C])),W=[T,R],s=_,i=C;break}case"A":{const T=y[5]+S,R=y[6]+x;let _=s,C=i;for(const O of Ye(s,i,y[0],y[1],y[2],y[3],y[4],T,R))h(nt(_,C,O)),_=O[4],C=O[5];s=T,i=R;break}}o=P,c=W}}const d=n.reduce((p,m)=>p+m.length,0),f=[];for(let p=0;p<n.length;){const m=n[p].subpath;let b=p,v=0;for(;b<n.length&&n[b].subpath===m;)v+=n[b++].length;const k=n[p],M=n[b-1],y=u.has(m)||Math.abs(M.endX-k.startX)<1e-9&&Math.abs(M.endY-k.startY)<1e-9;f.push({start:p,end:b,length:v,closed:y}),p=b}const g={segments:n,totalLength:d,subpaths:f};return G.size>=Le&&G.delete(G.keys().next().value),G.set(e,g),g}function qe(e,t){const n=e.lengths;if(t<=0)return 0;if(t>=e.length)return 1;let s=0,i=n.length-1;for(;s<i-1;){const o=s+i>>1;n[o]<t?s=o:i=o}const r=n[i]-n[s],a=r>0?(t-n[s])/r:0;return(s+a)/(n.length-1)}function Ve(e,t){if(e.type==="L"){const h=e.length>0?Math.max(0,Math.min(1,t/e.length)):0;return{x:e.startX+(e.endX-e.startX)*h,y:e.startY+(e.endY-e.startY)*h,angle:Math.atan2(e.endY-e.startY,e.endX-e.startX)*180/Math.PI}}const[n,s,i,r,a,o]=e.points,c=qe(e,t);let l=Ft(e.startX,n,i,a,c),u=Ft(e.startY,s,r,o,c);if(Math.hypot(l,u)<1e-9){const h=c<.5?Math.min(1,c+.001):Math.max(0,c-.001),d=Y(e.startX,n,i,a,h),f=Y(e.startY,s,r,o,h),g=Y(e.startX,n,i,a,c),p=Y(e.startY,s,r,o,c);l=c<.5?d-g:g-d,u=c<.5?f-p:p-f}return{x:Y(e.startX,n,i,a,c),y:Y(e.startY,s,r,o,c),angle:Math.atan2(u,l)*180/Math.PI}}function Xt(e,t,n=0,s=e.length){if(s<=n)return{x:0,y:0,angle:0};let i=0;for(let r=n;r<s;r++){const a=e[r];if(i+a.length>=t||r===s-1)return Ve(a,t-i);i+=a.length}return{x:0,y:0,angle:0}}function We(e,t){const{segments:n,totalLength:s}=st(e);return Xt(n,Math.max(0,Math.min(1,t))*s)}const Be=24,Ue=320,je=2.5,Z=72,He=.2,ze=128,it=new Map;let mt=0,q;const Yt=e=>Math.round(e*100)/100;function qt(e,t){const{segments:n,subpaths:s,totalLength:i}=st(e);if(n.length===0)return[];if(t){const r=s.every(a=>a.closed);return[{segments:n,start:0,end:n.length,length:i,closed:r}]}return s.filter(r=>r.length>0).map(r=>({segments:n,start:r.start,end:r.end,length:r.length,closed:r.closed}))}function gt(e,t){const n=e.closed?(t%1+1)%1:Math.max(0,Math.min(1,t)),s=Xt(e.segments,n*e.length,e.start,e.end);return[s.x,s.y]}function Vt(e){const t=[];let n=0;for(let s=e.start;s<e.end;s++)n+=e.segments[s].length,e.length>0&&t.push(n/e.length);return t}function Wt(e,t){const n=[];for(let s=0;s<t;s++)n.push(gt(e,e.closed?s/t:s/(t-1)));return n}function Bt(e){let t=0,n=0;for(const[s,i]of e)t+=s,n+=i;return t/=e.length,n/=e.length,e.map(([s,i])=>[s-t,i-n])}function Ge(e,t,n){const s=e.closed&&t.closed;if(n!==void 0)return{offset:s?Math.abs(n)%Z/Z:0,reversed:n<0};const i=Bt(Wt(e,Z)),r=Bt(Wt(t,Z)),a=Z;let o={offset:0,reversed:!1},c=1/0;for(const l of[!1,!0]){const u=s?a:1;for(let h=0;h<u;h++){let d=0;for(let f=0;f<a&&d<c;f++){const g=s?l?(h-f+a)%a:(f+h)%a:l?a-1-f:f,p=i[f][0]-r[g][0],m=i[f][1]-r[g][1];d+=p*p+m*m}d<c&&(c=d,o={offset:s?h/a:0,reversed:l})}}return o}function Qe(e,t,n){return n?((t.reversed?t.offset-e:e+t.offset)%1+1)%1:t.reversed?1-e:e}function Ze(e,t,n){return n?((t.reversed?t.offset-e:e-t.offset)%1+1)%1:t.reversed?1-e:e}function Ke(e,t,n){const s=e.closed&&t.closed,i=Ge(e,t,n.shapeIndex),r=Math.max(Be,Math.min(Ue,Math.ceil(Math.max(e.length,t.length)/je))),a=new Set,o=h=>a.add(Math.round(h*1e7)/1e7);for(let h=0;h<=r;h++)o(h/r);for(const h of Vt(e))o(h);for(const h of Vt(t))o(Ze(h,i,s));let c=[...a].sort((h,d)=>h-d);s&&(c=c.filter(h=>h<1));const l=[],u=[];for(const h of c)l.push(...gt(e,h)),u.push(...gt(t,Qe(h,i,s)));return Je({from:l,to:u,closed:s})}function Je(e){const t=e.from.length/2;if(t<=3)return e;const n=new Uint8Array(t);n[0]=1,n[t-1]=1;const s=[[0,t-1]];for(;s.length>0;){const[a,o]=s.pop();let c=-1,l=He;for(let u=a+1;u<o;u++){const h=Math.max(Ut(e.from,a,o,u),Ut(e.to,a,o,u));h>l&&(l=h,c=u)}c!==-1&&(n[c]=1,s.push([a,c],[c,o]))}const i=[],r=[];for(let a=0;a<t;a++)n[a]&&(i.push(e.from[a*2],e.from[a*2+1]),r.push(e.to[a*2],e.to[a*2+1]));return{from:i,to:r,closed:e.closed}}function Ut(e,t,n,s){const i=e[t*2],r=e[t*2+1],a=e[n*2]-i,o=e[n*2+1]-r,c=e[s*2]-i,l=e[s*2+1]-r,u=a*a+o*o,h=u===0?0:Math.max(0,Math.min(1,(c*a+l*o)/u));return Math.hypot(c-h*a,l-h*o)}function tn(e,t,n){const s=n.shapeIndex;if(q&&q.from===e&&q.to===t&&q.shapeIndex===s)return q.plan;const r=it.get(String(s??"auto"))?.get(e)?.get(t);if(r)return q={from:e,to:t,shapeIndex:s,plan:r},r;const a=st(e).subpaths.filter(f=>f.length>0).length===st(t).subpaths.filter(f=>f.length>0).length,o=qt(e,!a),c=qt(t,!a),l={pairs:o.map((f,g)=>Ke(f,c[g],n))};mt>=ze&&(it.clear(),mt=0);const u=String(s??"auto"),h=it.get(u)??new Map;it.set(u,h);const d=h.get(e)??new Map;return h.set(e,d),d.set(t,l),mt++,q={from:e,to:t,shapeIndex:s,plan:l},l}function en(e,t,n,s={}){if(!e)return t;if(!t)return e;const i=Math.max(0,Math.min(1,n));if(i===0)return e;if(i===1)return t;const r=tn(e,t,s);if(r.pairs.length===0)return i<.5?e:t;let a="";for(const o of r.pairs){for(let c=0;c<o.from.length;c+=2){const l=Yt(o.from[c]+(o.to[c]-o.from[c])*i),u=Yt(o.from[c+1]+(o.to[c+1]-o.from[c+1])*i);a+=`${c===0?a?" M":"M":" L"}${l} ${u}`}o.closed&&(a+=" Z")}return a}function nn(e){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(e)}const X=(e,t,n)=>e+(t-e)*n,jt=512,yt=new Map,bt=new Map;function Ht(e){const t=yt.get(e);if(t)return t;const n=e.replace("#",""),s=[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)];return yt.size<jt&&yt.set(e,s),s}const zt=e=>e.charCodeAt(0)===35,Gt=e=>e.startsWith("rgb"),Qt=e=>e.startsWith("rgba"),sn=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,vt=e=>Math.round(e).toString(16).padStart(2,"0");function rn(e,t,n){return`#${vt(e)}${vt(t)}${vt(n)}`}function Zt(e){const t=bt.get(e);if(t)return t;const n=e.match(sn);if(!n)throw new Error(`Invalid rgb color: ${e}`);const s=parseInt(n[1],10),i=parseInt(n[2],10),r=parseInt(n[3],10),a=n[4]!==void 0?[s,i,r,parseFloat(n[4])]:[s,i,r];return bt.size<jt&&bt.set(e,a),a}const an=(e,t,n)=>{if(zt(e)&&zt(t)){const[s,i,r]=Ht(e),[a,o,c]=Ht(t),l=X(s,a,n),u=X(i,o,n),h=X(r,c,n);return rn(l,u,h)}if((Gt(e)||Qt(e))&&(Gt(t)||Qt(t))){const s=Zt(e),i=Zt(t),r=Math.round(X(s[0],i[0],n)),a=Math.round(X(s[1],i[1],n)),o=Math.round(X(s[2],i[2],n));if(s.length===4||i.length===4){const c=s[3]??1,l=i[3]??1,u=X(c,l,n);return`rgba(${r}, ${a}, ${o}, ${u})`}return`rgb(${r}, ${a}, ${o})`}return n<1?e:t},on=(e,t,n)=>{const s=Math.min(e.length,t.length),i=[];for(let r=0;r<s;r++)i.push(X(e[r],t[r],n));return i},Kt=(e,t,n)=>n<1?e:t,cn=(e,t,n)=>en(e,t,n);function ln(e){return typeof e=="number"?X:Array.isArray(e)?on:typeof e=="string"?e.startsWith("#")||e.startsWith("rgb")?an:nn(e)?cn:Kt:Kt}function hn(e){const t=[...e.keyframes].sort((n,s)=>n.time-s.time);return{...e,keyframes:t}}function V(e){return e.targets&&e.targets.length>0?e.targets:[e.target]}function U(e,t,n,s){const i=n??0;return!s||t<=1?i:i+Et(e,t,s)}class kt{track;targets;constructor(t){this.track=t,this.targets=V(t)}getValueAtTime(t){return this.valueForOffset(t-U(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const r=U(i,n,this.track.delay,this.track.stagger),a=this.valueForOffset(t-r);a!==void 0&&s.push({target:this.targets[i],value:a,start:r+this.track.keyframes[0].time})}return s}getDuration(){const{keyframes:t}=this.track;if(t.length===0)return 0;const n=t[t.length-1].time,s=this.track.stagger?ut(this.targets.length,this.track.stagger):0;return n+(this.track.delay??0)+s+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(t){const{keyframes:n}=this.track;if(n.length===0)return;if(n.length===1||t<=n[0].time)return n[0].value;if(t>=n[n.length-1].time)return n[n.length-1].value;const{from:s,to:i}=this.findSurroundingKeyframes(t);if(!s||!i)return;if(s.time===t)return s.value;const r=i.time-s.time,a=(t-s.time)/r,c=De(i.easing)(a);return ln(s.value)(s.value,i.value,c)}findSurroundingKeyframes(t){const{keyframes:n}=this.track;for(let s=0;s<n.length-1;s++)if(t>=n[s].time&&t<=n[s+1].time)return{from:n[s],to:n[s+1]};return{from:null,to:null}}}class un{track;targets;sampler;constructor(t){this.track=t,this.targets=V(t),this.sampler=new be(t.spring)}getValueAtTime(t){return this.sampler.valueAt(t-U(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const r=U(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:this.sampler.valueAt(t-r),start:r})}return s}getDuration(){const t=this.track.stagger?ut(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+t}getTrack(){return this.track}}class dn{track;targets;duration;constructor(t){this.track=t,this.targets=V(t),this.duration=Rt(t.inertia)}getValueAtTime(t){return $t(this.track.inertia,t-U(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const r=U(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:$t(this.track.inertia,t-r),start:r})}return s}getDuration(){const t=this.track.stagger?ut(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+t}getTrack(){return this.track}}function fn(e,t){const n={...We(e.pathData,t)};if(e.matrix){const[s,i,r,a,o,c]=e.matrix,{x:l,y:u}=n;n.x=s*l+r*u+o,n.y=i*l+a*u+c;const h=n.angle*Math.PI/180,d=Math.cos(h),f=Math.sin(h);n.angle=Math.atan2(i*d+a*f,s*d+r*f)*180/Math.PI}return e.autoRotate&&e.rotateOffset&&(n.angle+=e.rotateOffset),n}const xt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},pn=20;function mn(e){const t=xt[e??"upperCase"]??e??xt.upperCase,n=Array.from(t);return n.length>0?n:Array.from(xt.upperCase)}function gn(e,t,n){let s=(e|0)^Math.imul(t+1,2654435761)^Math.imul(n+1,2246822507);return s=Math.imul(s^s>>>16,2146121005),s=Math.imul(s^s>>>15,2221713035),(s^s>>>16)>>>0}function yn(e,t,n=0){const s=e.from??"",i=e.to,r=Math.max(0,Math.min(1,t));if(r<=0)return s;if(r>=1)return i;const a=Array.from(s),o=Array.from(i),c=e.rightToLeft??!1;if(e.mode==="type"){const v=Math.round(r*Math.max(a.length,o.length));return c?a.slice(0,Math.max(0,a.length-v)).join("")+o.slice(Math.max(0,o.length-v)).join(""):o.slice(0,v).join("")+a.slice(v).join("")}const l=Math.max(0,Math.min(.999,e.revealDelay??0)),u=Math.max(0,(r-l)/(1-l)),h=Math.floor(u*o.length),d=e.tweenLength===!1?o.length:Math.round(a.length+(o.length-a.length)*r),f=mn(e.chars),g=e.refreshRate??pn,p=g>0?Math.floor(n*g/1e3):0,m=e.seed??1;let b="";for(let v=0;v<d;v++){const k=c?v>=d-h:v<h,M=c?o[o.length-(d-v)]:o[v];k&&M!==void 0||M===" "||M===`
2
+ `?b+=M:b+=f[gn(m,v,p)%f.length]}return b}class bn{id;name;_captions;_tracks=[];_trackPlayers=new Map;_motionPathTracks=new Map;_springTracks=new Map;_textTracks=new Map;_config;_currentTime=0;_playbackState="idle";_direction="forward";_loopIteration=0;_explicitDuration;_repeatDelayRemaining=0;_wrapAfterDelay=!1;onUpdate=null;onComplete=null;constructor(t){if(this.id=t.id,this.name=t.name,this._captions=t.captions,this._config=t.config??{},this._explicitDuration=t.config?.duration,t.tracks)for(const n of t.tracks)this.addTrack(n)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(t){if(this._explicitDuration=t,t!==void 0)this._config={...this._config,duration:t};else if(this._config.duration!==void 0){const n={...this._config};delete n.duration,this._config=n}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(t){this._config.speed=t}play(){const t=this.duration;this._direction==="forward"&&this._currentTime>=t&&t>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&t>0&&(this._currentTime=t,this._loopIteration=0),this._playbackState="playing"}pause(){this._playbackState="paused"}stop(){this._playbackState="idle",this._repeatDelayRemaining=0,this._wrapAfterDelay=!1,this._currentTime=0,this._loopIteration=0,this._direction="forward"}seek(t){const n=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(t,n)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(t){if(this._playbackState!=="playing")return;const n=this.duration;if(n<=0)return;let i=t*this.speed;if(this._repeatDelayRemaining>0){const o=Math.min(this._repeatDelayRemaining,i);if(this._repeatDelayRemaining-=o,i-=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&&i>0&&this._playbackState==="playing";o++)if(this._direction==="forward"){const c=n-this._currentTime;if(i>=c){if(i-=c,this._currentTime=n,!this._handleEndReached())break}else this._currentTime+=i,i=0}else{const c=this._currentTime;if(i>=c){if(i-=c,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=i,i=0}const a=this.getStateAtTime(this._currentTime);this.onUpdate?.(a)}getStateAtTime(t){const n=new Map;if(this._hasSharedWrites())this._resolveShared(t,n);else for(const[s,i]of this._trackPlayers){const r=i.getTrack().property;for(const{target:a,value:o,start:c}of i.getTargetValues(t))this._write(n,s,a,r,o,t-c)}return{values:n,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(t,n){const s=new Map;for(const[i,r]of this._trackPlayers){const a=r.getTrack().property;for(const{target:o,value:c,start:l}of r.getTargetValues(t)){const u=`${o}\0${a}`,h=l<=t,d=s.get(u);(!d||(h!==d.started?h:h?l>=d.start:l<=d.start))&&s.set(u,{trackId:i,target:o,property:a,value:c,start:l,started:h})}}for(const{trackId:i,target:r,property:a,value:o,start:c}of s.values())this._write(n,i,r,a,o,t-c)}_write(t,n,s,i,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(n);if(c&&typeof r=="number"){o.set("text",yn(c.textConfig,r,Math.max(0,a)));return}const l=this._motionPathTracks.get(n);if(l&&typeof r=="number"){const u=fn(l.motionPathConfig,r);o.set("motionPathX",u.x),o.set("motionPathY",u.y),l.motionPathConfig.autoRotate&&o.set("motionPathRotate",u.angle)}else o.set(i,r)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const t=new Set;this._sharedWrites=!1;t:for(const n of this._tracks)for(const s of V(n)){const i=`${s}\0${n.property}`;if(t.has(i)){this._sharedWrites=!0;break t}t.add(i)}}return this._sharedWrites}addTrack(t){if(this._tracks.push(t),this._sharedWrites=null,lt(t)){this._trackPlayers.set(t.id,new dn(t));return}if(ht(t)){this._trackPlayers.set(t.id,new un(t)),this._springTracks.set(t.id,t);return}if(_t(t))this._trackPlayers.set(t.id,new kt(t)),this._textTracks.set(t.id,t);else if(me(t)){const n={id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,delay:t.delay,endDelay:t.endDelay,targets:t.targets,stagger:t.stagger};this._trackPlayers.set(t.id,new kt(n)),this._motionPathTracks.set(t.id,t)}else this._trackPlayers.set(t.id,new kt(t))}replaceTrack(t,n){const s=this._tracks.findIndex(r=>r.id===t);if(s<0)return;const i=this._tracks.slice(s+1);this.removeTrack(t);for(const r of i)this.removeTrack(r.id);this.addTrack(n);for(const r of i)this.addTrack(r)}removeTrack(t){this._tracks=this._tracks.filter(n=>n.id!==t),this._sharedWrites=null,this._trackPlayers.delete(t),this._motionPathTracks.delete(t),this._springTracks.delete(t),this._textTracks.delete(t)}getTracks(t={}){return this._tracks.filter(n=>this._matches(n,t))}removeTracks(t={}){const n=this.getTracks(t).map(s=>s.id);for(const s of n)this.removeTrack(s);return n}getTrackSpan(t){const n=this._trackPlayers.get(t);if(!n)return;const s=n.getTrack(),i=s.delay??0;if(ht(s)||lt(s))return{from:i,to:n.getDuration()};const r=s.keyframes;if(!(!r||r.length===0))return{from:r[0].time+i,to:n.getDuration()}}findConflicts(){const t=[];for(let n=0;n<this._tracks.length;n++){const s=this._tracks[n],i=this.getTrackSpan(s.id);if(i)for(let r=0;r<n;r++){const a=this._tracks[r];if(a.property!==s.property)continue;const o=V(a).filter(h=>V(s).includes(h));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=i.to&&i.from<=c.to))continue;const u=i.from>=c.from;for(const h of o)t.push({target:h,property:s.property,losingTrackId:u?a.id:s.id,winningTrackId:u?s.id:a.id})}}return t}_matches(t,n){if(n.id!==void 0&&t.id!==n.id||n.property!==void 0&&t.property!==n.property||n.target!==void 0&&!V(t).includes(n.target))return!1;if(n.timeRange){const s=this.getTrackSpan(t.id);if(!s||s.to<n.timeRange.from||s.from>n.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:H,id:this.id,name:this.name,config:{...this._config},tracks:[...this._tracks],...this.captions&&{captions:this.captions}}}get config(){return this._config}get markers(){return[...this._config.markers??[]].sort((t,n)=>t.time-n.time)}setMarkers(t){const n=t&&t.length>0?[...t].sort((i,r)=>i.time-r.time).map(i=>({...i})):void 0,s={...this._config};n?s.markers=n:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(t){const n={};for(const[s,i]of Object.entries(t??{}))n[s]={...i};this._captions=Object.keys(n).length>0?n:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let t=0;for(const[,n]of this._trackPlayers)t=Math.max(t,n.getDuration());return t}_handleEndReached(){const t=this._config.loop??0;return t===-1||this._loopIteration<t?(this._loopIteration++,this._armRepeatDelay(),this._config.alternate?this._direction="reverse":this._repeatDelayRemaining>0?this._wrapAfterDelay=!0:this._currentTime=0,this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}_handleStartReached(){const t=this._config.loop??0;return this._config.alternate&&(t===-1||this._loopIteration<t)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const vn=100;function kn(e,t,n,s){const i=[],r=[],{duration:a,alternate:o}=s,c=(f,g,p,m)=>{r.push([f,g]);const b=[];e.forEach((v,k)=>{(p==="forward"?(m?v>=f:v>f)&&v<=g:(m?v<=f:v<f)&&v>=g)&&b.push(k)}),b.sort((v,k)=>(p==="forward"?e[v]-e[k]:e[k]-e[v])||v-k);for(const v of b)i.push({kind:"event",index:v,direction:p})};let l=t.time,u=t.direction,h=t.fresh===!0;const d=Math.min(vn,Math.max(0,n.iteration-t.iteration));for(let f=0;f<d;f++){const g=u==="forward"?a:0;c(l,g,u,h),i.push({kind:"repeat"}),o?(u=u==="forward"?"reverse":"forward",l=g,h=!1):(l=u==="forward"?0:a,h=!0)}return d>0&&s.holding&&!o?{crossings:i,passes:r}:(c(l,n.time,u,h),{crossings:i,passes:r})}function xn(e){return{...e,...Array.isArray(e.end)&&{end:[...e.end]}}}function K(e){const t=e.endDelay;return{...e.delay!==void 0&&{delay:e.delay},...t!==void 0&&{endDelay:t},...e.targets!==void 0&&{targets:[...e.targets]},...e.stagger!==void 0&&{stagger:{...e.stagger}}}}function wn(e){if(lt(e)){const t=e;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:xn(t.inertia),...K(t)}}if(ht(e)){const t=e;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...K(t)}}if(_t(e)){const t=e;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((n,s)=>n.time-s.time),...K(t)}}if(e.property==="motionPath"&&"motionPathConfig"in e){const t=e,n=[...t.keyframes].sort((s,i)=>s.time-i.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:n,...K(t)}}return hn({id:e.id,target:e.target,property:e.property,keyframes:e.keyframes,...K(e)})}function rt(e){const t=e.formatVersion??1;if(t>H)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${H}. Update tinyfly to play it.`);return new bn({id:e.id,name:e.name,config:e.config,tracks:e.tracks.map(wn),captions:e.captions})}const Mn=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),Sn="#ffffff",Tn="rgba(0, 0, 0, 0.5)";function _n(e){const t=[];if(e.blur!==void 0&&t.push(`blur(${Math.max(0,e.blur)}px)`),e.brightness!==void 0&&t.push(`brightness(${Math.max(0,e.brightness)})`),e.glow!==void 0&&t.push(`drop-shadow(0 0 ${Math.max(0,e.glow)}px ${e.glowColor??Sn})`),e.shadowX!==void 0||e.shadowY!==void 0||e.shadowBlur!==void 0){const n=e.shadowX??0,s=e.shadowY??0,i=Math.max(0,e.shadowBlur??0);t.push(`drop-shadow(${n}px ${s}px ${i}px ${e.shadowColor??Tn})`)}return t.length>0?t.join(" "):null}function An(e,t){const n=e.childNodes.length===1?e.firstChild:null;if(n&&n.nodeType===3){const s=n;s.data!==t&&(s.data=t);return}e.textContent!==t&&(e.textContent=t)}function En(e){if(!("ownerSVGElement"in e))return;const t=e.style;!t||t.transformBox||(t.transformBox="fill-box",t.transformOrigin||(t.transformOrigin="50% 50%"))}const Jt=new Set(["width","height","top","right","bottom","left","margin","marginTop","marginRight","marginBottom","marginLeft","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","borderRadius","borderWidth","fontSize","lineHeight","letterSpacing","outlineWidth","gap","rowGap","columnGap"]),Pn=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","motionPathX","motionPathY","motionPathRotate"]),Cn=new Set(["originX","originY"]),In=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Rn={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},te={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},$n="http://www.w3.org/2000/svg";class wt{targets=new Map;registerTarget(t,n){this.targets.set(t,n)}unregisterTarget(t){this.targets.delete(t)}getTarget(t){return this.targets.get(t)}clearTargets(){this.targets.clear()}applyState(t){for(const[n,s]of t.values){const i=this.targets.get(n);i&&this.applyProperties(i,s)}}applyProperties(t,n){const s=[];let i=null,r=null,a=null;const o=n.has("motionPathX"),c=n.has("motionPathY"),l=n.has("motionPathRotate");for(const[d,f]of n)if(!(d==="x"&&o)&&!(d==="y"&&c)&&!((d==="rotate"||d==="rotateZ")&&l)){if(Pn.has(d)){const g=this.buildTransformPart(d,f);g&&s.push(g)}else if(Cn.has(d))typeof f=="number"&&((i??={})[d]=f);else if(In.has(d))typeof f=="number"&&((r??={})[d]=f);else if(Mn.has(d))(a??={})[d]=f;else if(d!=="perspective"){if(d!=="shine")if(d==="text"&&typeof f=="string")An(t,f);else if(d==="d"&&typeof f=="string"){const g=t;(g.tagName?.toLowerCase()==="path"?g:g.querySelector?.("path"))?.setAttribute?.("d",f)}else this.applyStyleProperty(t,d,f)}}const u=n.get("shine");typeof u=="number"&&this.applyShine(t,u);const h=n.get("perspective");if(typeof h=="number"&&s.unshift(`perspective(${h}px)`),s.length>0&&(t.style.transform=s.join(" "),En(t)),i){const d=i.originX??50,f=i.originY??50;t.style.transformOrigin=`${d}% ${f}%`}if(r){const d=r.clipTop??0,f=r.clipRight??0,g=r.clipBottom??0,p=r.clipLeft??0;t.style.clipPath=`inset(${d}% ${f}% ${g}% ${p}%)`}if(a){const d=_n(a);d&&(t.style.filter=d)}}buildTransformPart(t,n){if(typeof n!="number")return null;switch(t){case"x":case"motionPathX":return`translateX(${n}px)`;case"y":case"motionPathY":return`translateY(${n}px)`;case"z":return`translateZ(${n}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${n}deg)`;case"rotateX":return`rotateX(${n}deg)`;case"rotateY":return`rotateY(${n}deg)`;case"scale":return`scale(${n})`;case"scaleX":return`scaleX(${n})`;case"scaleY":return`scaleY(${n})`;case"scaleZ":return`scaleZ(${n})`;case"skewX":return`skewX(${n}deg)`;case"skewY":return`skewY(${n}deg)`;default:return null}}applyShine(t,n){t.dataset.shineBase||(t.dataset.shineBase=t.style.color||"currentColor");const s=t.dataset.shineBase,i=-20+n*140,r=t.style;r.color="transparent",r.backgroundImage=`linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${s}, ${s})`,r.backgroundSize="250% 100%, 100% 100%",r.backgroundPosition=`${i}% 0, 0 0`,r.backgroundRepeat="no-repeat",r.webkitBackgroundClip="text",r.backgroundClip="text"}applyStyleProperty(t,n,s){let i;if(t.namespaceURI===$n&&n in te){const o=Array.isArray(s)?s.join(", "):String(s);t.style[te[n]]=o;return}else n==="fill"&&t.dataset?.elementType==="text"?i="color":i=Rn[n]??n;let a;typeof s=="number"?Jt.has(n)||Jt.has(i)?a=`${s}px`:a=String(s):Array.isArray(s)?a=s.join(", "):a=s,t.style[i]=a}}class ee{media;offset;driftTolerance;constructor(t,n={}){this.media=t,this.offset=n.offset??0,this.driftTolerance=Math.max(0,n.driftTolerance??.15)}targetTime(t){return Math.max(0,t/1e3+this.offset)}update(t,n){const s=this.targetTime(t);n?(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 Dn(e,t,n,s,i){const r=n-i;if(r<0){t.paused||t.pause(),t.currentTime=0;return}e.update(r,s)}class at{container;timeline=null;adapter;animationFrameId;lastTime;options;targets={};isDestroyed=!1;mediaSync;mediaTargets=[];symbolInstances=[];scenarioList=[];scenarioId;authored=new Map;markerList=[];listeners=new Set;playhead={time:0,iteration:0,direction:"forward"};stepping=!1;lastMarkerId=null;reducedQuery;onReducedChange=()=>this.applyReducedMotion();visibilityObserver;onScreen=!0;pausedByVisibility=!1;autoplayWhenSeen=!1;onDocumentVisibility=()=>this.updateVisibility();constructor(t,n={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=n,this.adapter=new wt}async load(t){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(t)}async loadSource(t){let n;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load animation: ${s.statusText}`);n=await s.json()}else n=t;this.useDefinition(n),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(t){const n={...t.config};this.options.speed!==void 0&&(n.speed=this.options.speed),this.options.loop!==void 0&&(n.loop=this.options.loop),this.options.alternate!==void 0&&(n.alternate=this.options.alternate),this.timeline=rt({...t,config:n}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(t,n={}){if(t.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const 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 i=n.initial===void 0?t[0]:t.find(r=>r.id===n.initial);if(!i)throw new Error(`tinyfly: there is no scenario "${n.initial}"`);this.scenarioList=[...t],this.scenarioId=i.id,await this.loadSource(i.timeline)}get scenarios(){return this.scenarioList.map(t=>({id:t.id,label:t.label??t.id}))}get scenario(){return this.scenarioId}setScenario(t){const n=this.scenarioList.find(o=>o.id===t);if(!n||!this.timeline)return!1;if(t===this.scenarioId)return!0;const s=this.isPlaying,i=this.currentTime>=this.duration-.5,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=t,this.useDefinition(n.timeline),this.lastMarkerId=null;let a=0;return this.reducedMotion||i?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 n={style:t.getAttribute("style")};t.children.length===0&&(n.text=t.textContent??"");const s=t.tagName.toLowerCase()==="path"?t:t.querySelector("path");s&&(n.path={element:s,d:s.getAttribute("d")}),this.authored.set(t,n)}restoreAuthored(){for(const[t,n]of this.authored){n.style===null?t.removeAttribute("style"):t.setAttribute("style",n.style),n.text!==void 0&&t.textContent!==n.text&&(t.textContent=n.text),n.path&&(n.path.d===null?n.path.element.removeAttribute("d"):n.path.element.setAttribute("d",n.path.d));const 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 n;for(const s of this.markers)if(s.time<=t+.5)n=s;else break;return n}caption(t,n){const s=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!s)return;const i=n??this.language(),r=a=>a?.[i]?.[s.id]??a?.[i.split("-")[0]]?.[s.id];return r(this.options.captions)??r(this.timeline?.captions)??s.label}next(){if(!this.timeline)return;const t=this.currentTime,n=this.markers.find(s=>s.time>t+.5);if(this.reducedMotion){this.seek(n?n.time:this.duration);return}t>=this.duration-.5||(this.stepping=n!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const t=this.currentTime,n=[...this.markers].reverse().find(s=>s.time<t-.5);this.pause(),this.seek(n?n.time:0)}goToMarker(t){const n=this.markers.find(s=>s.id===t);n&&(this.pause(),this.seek(n.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const t=this.options.initialFrame??"start";if(t==="none")return;const n=t==="end"?this.timeline.duration:t==="start"?0:t;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,n))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(n=>{for(const s of n)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,n=t?.id;n!==this.lastMarkerId&&(this.lastMarkerId=n,this.options.onMarker(t))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(n=>{const s=n,i=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:i,sync:new ee(s)})})}syncAllMedia(t,n){for(const s of this.mediaTargets)Dn(s.sync,s.el,t,n,s.startTime)}loadFromString(t){const n=JSON.parse(t);this.load(n)}registerTarget(t,n){if(typeof n=="string"){const s=this.container.querySelector(n);s&&(this.rememberAuthored(s),this.targets[t]=s,this.adapter.registerTarget(t,s))}else this.rememberAuthored(n),this.targets[t]=n,this.adapter.registerTarget(t,n)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(n=>{const s=n.closest("[data-tinyfly-symbol]");if(s&&s!==n)return;const i=n.getAttribute("data-tinyfly");i&&this.registerTarget(i,n)}),this.timeline&&new Set(this.timeline.tracks.map(s=>s.target)).forEach(s=>{if(!this.targets[s]){const i=this.container.querySelector(`[data-tinyfly="${s}"]`)||this.container.querySelector(`.${s}`)||this.container.querySelector(`#${s}`);i&&this.registerTarget(s,i)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const n=new Map(t.map(s=>[s.id,s]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const i=s.getAttribute("data-tinyfly-symbol");if(!i)return;const r=n.get(i);if(!r||!r.timeline.tracks?.length)return;const a=new wt;s.querySelectorAll("[data-tinyfly]").forEach(o=>{const c=o.getAttribute("data-tinyfly");c&&a.registerTarget(c,o)}),this.symbolInstances.push({adapter:a,timeline:rt(r.timeline)})})}attachMedia(t,n){this.mediaSync=new ee(t,n),this.timeline&&(this.mediaSync.setRate(this.timeline.speed),this.mediaSync.update(this.timeline.currentTime,this.isPlaying))}detachMedia(){this.mediaSync?.dispose(),this.mediaSync=void 0}play(){!this.timeline||this.isDestroyed||(this.autoplayWhenSeen=!1,this.stepping=this.options.stepMode===!0,this.startPlaying())}startPlaying(){if(!this.timeline||this.isDestroyed)return;const t=this.timeline.playbackState==="idle";this.timeline.play(),t&&this.timeline.currentTime===0&&this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.update(this.timeline.currentTime,!0),this.syncAllMedia(this.timeline.currentTime,!0),this.startAnimationLoop(),this.notify()}pause(){this.timeline&&(this.stepping=!1,this.timeline.pause(),this.notify(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1),this.stopAnimationLoop())}stop(){this.timeline&&(this.timeline.stop(),this.stopAnimationLoop(),this.applyState(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1))}seek(t){this.timeline&&(this.timeline.seek(t),this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.seek(this.timeline.currentTime),this.syncAllMedia(this.timeline.currentTime,this.isPlaying))}setSpeed(t){this.timeline&&(this.timeline.speed=t,this.mediaSync?.setRate(t))}reverse(){this.timeline&&this.timeline.reverse()}get currentTime(){return this.timeline?.currentTime??0}get duration(){return this.timeline?.duration??0}get isPlaying(){return this.timeline?.playbackState==="playing"}destroy(){this.isDestroyed=!0,this.stopAnimationLoop(),this.reducedQuery?.removeEventListener?.("change",this.onReducedChange),this.visibilityObserver?.disconnect(),typeof document<"u"&&document.removeEventListener("visibilitychange",this.onDocumentVisibility),this.mediaSync?.dispose(),this.mediaSync=void 0;for(const t of this.mediaTargets)t.el.paused||t.el.pause();this.mediaTargets=[],this.adapter.clearTargets();for(const t of this.symbolInstances)t.adapter.clearTargets();this.symbolInstances=[],this.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=n=>{if(this.isDestroyed||!this.timeline)return;const s=n-(this.lastTime??n);this.lastTime=n;const i=this.playhead;this.timeline.tick(s),this.stopAtMarker(i),this.applyState();const r=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,r),this.syncAllMedia(this.timeline.currentTime,r),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(t):(this.animationFrameId=void 0,this.notify())};this.animationFrameId=requestAnimationFrame(t)}stopAtMarker(t){const n=this.timeline,s={time:n.currentTime,iteration:n.loopIteration,direction:n.direction};this.playhead=s;const i=this.markers;if(i.length===0)return;const{crossings:r}=kn(i.map(a=>a.time),t,s,{duration:n.duration,alternate:n.config.alternate===!0,holding:n.repeatDelayRemaining>0});for(const a of r){if(a.kind!=="event")continue;const o=i[a.index];if(this.stepping||o.pause){this.stepping=!1,n.pause(),n.seek(o.time),this.playhead={time:o.time,iteration:n.loopIteration,direction:n.direction};return}}}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}applyState(){if(!this.timeline)return;const t=this.timeline.currentTime;this.adapter.applyState(this.timeline.getStateAtTime(t)),this.announceMarker(),this.notify();for(const n of this.symbolInstances){const s=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(s>0?t%s:t))}}}async function Ln(e,t,n={}){const s=new at(e,{...n,autoplay:!0});return await s.load(t),s}function On(e,t={}){return new at(e,t)}const ne={play:"Play",pause:"Pause",prev:"Previous step",next:"Next step",restart:"Restart",scrub:"Position",speed:"Speed",reveal:"Reveal",step:"Step",of:"of",stepFormat:"{index} / {total}",scenario:"Scenario",fullscreen:"Full screen",exitFullscreen:"Exit full screen"},se="tinyfly-controls-style",Nn=`
3
3
  .tf-ctl { --tf-ctl-fg: #1d1d1f; --tf-ctl-bg: #f4f2ee; --tf-ctl-accent: #c2410c; --tf-ctl-radius: 8px;
4
4
  font: 14px/1.4 var(--tf-ctl-font, system-ui, sans-serif); color: var(--tf-ctl-fg); margin-top: 8px; }
5
5
  .tf-ctl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px; border-radius: var(--tf-ctl-radius); background: var(--tf-ctl-bg); }
@@ -18,4 +18,36 @@
18
18
  /* The hidden attribute only hides through the browser's default stylesheet; any rule
19
19
  above that sets display would override it, so enforce it for everything here. */
20
20
  .tf-ctl [hidden] { display: none !important; }
21
- `;function Es(e){if(e.getElementById(ee))return;const t=e.createElement("style");t.id=ee,t.textContent=Rs,e.head.appendChild(t)}function se(e,t,s={}){const n=t.ownerDocument;Es(n);const i={...te,...s.labels},r=s.speeds??[.5,1,2],a=()=>e.markers.length>0,o=()=>e.markers.some(M=>M.label!==void 0||e.caption(M.id)!==void 0),c=n.createElement("div");c.className="tf-ctl";const l=n.createElement("div");l.className="tf-ctl-bar",l.setAttribute("role","group");const u=(M,v,L,E="")=>{const D=n.createElement("button");return D.type="button",D.className=`tf-ctl-btn ${E}`.trim(),D.setAttribute("aria-label",M),D.title=M,D.textContent=v,D.addEventListener("click",L),D},h=u(i.restart,"⟲",()=>{e.pause(),e.seek(0)}),f=u(i.prev,"◀",()=>e.prev()),d=u(i.play,"▶",()=>e.isPlaying?e.pause():p(),"tf-ctl-primary"),b=u(i.next,"▶|",()=>e.next()),p=()=>{e.currentTime>=e.duration-.5&&e.seek(0),e.play()},m=n.createElement("input");m.type="range",m.className="tf-ctl-scrub",m.min="0",m.max="1000",m.step="1",m.setAttribute("aria-label",i.scrub),m.addEventListener("input",()=>{e.pause(),e.seek(Number(m.value)/1e3*e.duration)});const k=n.createElement("span");k.className="tf-ctl-step";const y=n.createElement("select");y.className="tf-ctl-speed",y.setAttribute("aria-label",i.speed);for(const M of r){const v=n.createElement("option");v.value=String(M),v.textContent=`${M}×`,M===1&&(v.selected=!0),y.appendChild(v)}y.addEventListener("change",()=>e.setSpeed(Number(y.value))),l.append(h,f,d,b,m,k),r.length>0&&l.append(y),c.append(l);const T=n.createElement("p");T.className="tf-ctl-caption",T.setAttribute("aria-live","polite"),s.captions!==!1&&c.append(T);const w=n.createElement("div");w.className="tf-ctl-question",w.hidden=!0;const g=n.createElement("span"),_=u(i.reveal,i.reveal,()=>e.play(),"tf-ctl-primary");w.append(g,_),c.append(w);const S=s.mount;S?S.appendChild(c):t.insertAdjacentElement("afterend",c);const I=()=>{const M=e.isPlaying;d.textContent=M?"❚❚":"▶",d.setAttribute("aria-label",M?i.pause:i.play),d.title=M?i.pause:i.play;const v=e.duration;n.activeElement!==m&&(m.value=String(v>0?Math.round(e.currentTime/v*1e3):0));const L=e.markers;if(f.hidden=b.hidden=k.hidden=L.length===0,L.length>0){const E=e.currentMarker,D=E?L.indexOf(E)+1:0;k.textContent=i.stepFormat.replace("{index}",String(D)).replace("{total}",String(L.length)),k.setAttribute("aria-label",`${i.step} ${D} ${i.of} ${L.length}`),f.disabled=e.currentTime<=.5,b.disabled=e.currentTime>=v-.5;const Z=e.caption()??"";T.textContent!==Z&&(T.textContent=Z),T.hidden=!o();const K=!M&&E?.question!==void 0&&Math.abs(e.currentTime-E.time)<1;w.hidden=!K,K&&g.textContent!==E.question&&(g.textContent=E.question)}else w.hidden=!0,T.hidden=!0},W=e.subscribe(I);I();const x=s.keyboardScope??t;!x.hasAttribute("tabindex")&&x.tabIndex<0&&(x.tabIndex=0);const C=new WeakSet,A=M=>{if(C.has(M)||(C.add(M),M.defaultPrevented||M.altKey||M.ctrlKey||M.metaKey))return;const v=M.target;if(!(v.tagName==="INPUT"||v.tagName==="SELECT")&&!(M.key===" "&&v.tagName==="BUTTON"))switch(M.key){case" ":M.preventDefault(),e.isPlaying?e.pause():p();break;case"ArrowRight":if(!a())return;M.preventDefault(),e.next();break;case"ArrowLeft":if(!a())return;M.preventDefault(),e.prev();break;case"Home":M.preventDefault(),e.pause(),e.seek(0);break}};return x.addEventListener("keydown",A),c.addEventListener("keydown",A),{element:c,destroy(){W(),x.removeEventListener("keydown",A),c.removeEventListener("keydown",A),c.remove()}}}const at=new WeakMap;let Ds=0;function ot(e,t,s){if(e)try{return JSON.parse(e)}catch(n){console.warn(`tinyfly: invalid ${t} JSON on`,s,n);return}}async function ne(e,t={}){const s=at.get(e);if(s)return s;const n=e.querySelector("script[data-tinyfly-timeline]"),i=e.getAttribute("data-src");let r=n?ot(n.textContent,"timeline",e):void 0;const a=$s(e.getAttribute("data-markers"));if(!r&&i&&a){const h=await fetch(i);h.ok&&(r=await h.json())}if(r&&a&&!r.config.markers?.length&&(r.config={...r.config,markers:a.map((h,f)=>({id:`step-${f+1}`,time:h}))}),!r&&!i){console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)',e);return}const o=ot(e.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",e),c={playWhenVisible:!0,...t.player,...o&&{captions:o},...ot(e.getAttribute("data-options"),"data-options",e)};Ls(e);const l=new rt(e,c),u={element:e,player:l};if(at.set(e,u),e.setAttribute("data-tinyfly-mounted",""),await l.load(r??i),e.getAttribute("data-controls")!=="false"){const h=ot(e.getAttribute("data-labels"),"data-labels",e),f=e.querySelector("figcaption");u.controls=se(l,e,{...t.controls,labels:{...t.controls?.labels,...h},mount:void 0}),f?e.insertBefore(u.controls.element,f):e.appendChild(u.controls.element)}return u}function $s(e){if(!e)return;const t=e.split(/[\s,]+/).filter(Boolean).map(Number).filter(s=>Number.isFinite(s)&&s>=0).sort((s,n)=>s-n);return t.length>0?t:void 0}async function ie(e=document,t={}){const s=Array.from(e.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(s.map(i=>ne(i,t)))).filter(i=>i!==void 0)}function Os(e){const t=at.get(e);t&&(t.controls?.destroy(),t.player.destroy(),at.delete(e),e.removeAttribute("data-tinyfly-mounted"))}function Ls(e){const t=e.querySelector("svg");if(!t||t.hasAttribute("role")||t.hasAttribute("aria-hidden"))return;const s=e.getAttribute("data-alt"),n=e.querySelector("figcaption");t.setAttribute("role","img"),s?t.setAttribute("aria-label",s):n&&(n.id||=`tinyfly-caption-${++Ds}`,t.setAttribute("aria-labelledby",n.id))}function Ns(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const t=()=>{ie()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}function re(e){const t=new Set;for(const s of e.matchAll(/data-tinyfly\s*=\s*("([^"]*)"|'([^']*)')/g))t.add(s[2]??s[3]);return[...t]}function Fs(e,t={}){const s=[],n=l=>s.push({level:"error",message:l}),i=l=>s.push({level:"warning",message:l});if((e.formatVersion??1)>U)return n(`format version ${e.formatVersion} is newer than this tinyfly reads (${U})`),s;let r=0;try{r=it(e).duration}catch(l){return n(`the timeline does not load: ${l instanceof Error?l.message:String(l)}`),s}const a=e.config?.duration;if(a!==void 0)for(const l of e.tracks){if(!("keyframes"in l))continue;const u=l.keyframes.filter(h=>h.time>a);u.length>0&&n(`track "${l.id}" has a keyframe at ${u[0].time}ms, after the ${a}ms duration`)}const o=e.config?.markers??[],c=new Set;o.forEach((l,u)=>{c.has(l.id)&&n(`marker id "${l.id}" is used more than once`),c.add(l.id),(l.time<0||l.time>r)&&n(`marker "${l.id}" at ${l.time}ms is outside the animation (0–${r}ms)`),u>0&&l.time<o[u-1].time&&n(`marker "${l.id}" comes before "${o[u-1].id}" in time; list markers in order`)});for(const[l,u]of Object.entries(e.captions??{})){for(const h of Object.keys(u))c.has(h)||n(`caption "${h}" (${l}) has no marker with that id`);for(const h of c)h in u||i(`marker "${h}" has no ${l} caption; its label is shown instead`)}if(t.markup!==void 0){const l=new Set(re(t.markup)),u=new Set;for(const h of e.tracks)for(const f of[h.target,...h.targets??[]])u.add(f),l.has(f)||n(`track "${h.id}" targets "${f}", but no element has data-tinyfly="${f}"`);for(const h of l)u.has(h)||i(`data-tinyfly="${h}" is never animated`)}return s}function Xs(e,t,s="end"){const n=it(t),i=t.config?.markers??[],r=s==="start"?0:s==="end"?n.duration:typeof s=="number"?s:i.find(f=>f.id===s)?.time??n.duration,a=n.getStateAtTime(Math.max(0,Math.min(n.duration,r))),o=new St,c=new Map,l=qs(e);for(const f of e.matchAll(ae)){const d=/data-tinyfly\s*=\s*("([^"]*)"|'([^']*)')/.exec(f[2]??"");if(!d)continue;const b=d[2]??d[3];if(c.has(b))continue;const p=Ys(l(f.index??0));c.set(b,p),o.registerTarget(b,p)}o.applyState(a);let u="",h=0;for(const f of e.matchAll(ae)){const[d,b,p="",m]=f,k=f.index??0,y=/data-tinyfly\s*=\s*("([^"]*)"|'([^']*)')/.exec(p),T=y?c.get(y[2]??y[3]):void 0;if(!T||Object.keys(T.style).length===0&&T.text===void 0)continue;u+=e.slice(h,k);const w=Object.entries(T.style).map(([S,I])=>`${Vs(S)}: ${I}`).join("; "),g=/\sstyle\s*=\s*("([^"]*)"|'([^']*)')/.exec(p);let _=p;if(w)if(g){const S=`${(g[2]??g[3]).trim().replace(/;?$/,";")} ${w}`.trim();_=p.replace(g[0],` style="${oe(S)}"`)}else _=`${p} style="${oe(w)}"`;if(u+=`<${b}${_}${m?" /":""}>`,h=k+d.length,T.text!==void 0&&!m){const S=e.indexOf(`</${b}`,h),I=S===-1?"":e.slice(h,S);S!==-1&&!I.includes("<")&&(u+=Ws(T.text),h=S)}}return u+e.slice(h)}const ae=/<([a-zA-Z][\w:-]*)((?:\s+[^\s=>/]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+))?)*)\s*(\/?)>/g;function Ys(e){const t={style:{},dataset:{},namespaceURI:e?"http://www.w3.org/2000/svg":"http://www.w3.org/1999/xhtml",childNodes:[],get textContent(){return t.text??""},set textContent(s){t.text=s}};return e&&(t.ownerSVGElement=null),t}function qs(e){const t=[],s=/<svg[\s>]/gi;let n;for(;n=s.exec(e);){const i=e.toLowerCase().indexOf("</svg>",n.index);t.push([n.index+1,i===-1?e.length:i])}return i=>t.some(([r,a])=>i>r&&i<a)}function Vs(e){const t=e.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`);return/^(webkit|moz|ms)-/.test(t)?`-${t}`:t}function oe(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;")}function Ws(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;")}Ns(),O.DEFAULT_LABELS=te,O.TinyflyPlayer=rt,O.create=Cs,O.createControls=se,O.mount=ne,O.mountAll=ie,O.play=Is,O.renderFrame=Xs,O.targetNamesIn=re,O.unmount=Os,O.validateEmbed=Fs,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})})(this.tinyfly=this.tinyfly||{});
21
+ .tf-ctl-choices { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 8px 0 0; padding: 0; border: 0; }
22
+ .tf-ctl-choices legend { float: left; margin-right: 4px; padding: 0; font-weight: 600; }
23
+ .tf-ctl-choice { position: relative; display: inline-flex; }
24
+ .tf-ctl-choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
25
+ .tf-ctl-choice span { display: inline-block; padding: 6px 12px; border-radius: var(--tf-ctl-radius); background: var(--tf-ctl-bg); cursor: pointer; }
26
+ .tf-ctl-choice input:checked + span { background: var(--tf-ctl-accent); color: #fff; }
27
+ .tf-ctl-choice input:focus-visible + span { outline: 2px solid var(--tf-ctl-accent); outline-offset: 2px; }
28
+ .tf-ctl-choice-slider { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0 0; }
29
+ .tf-ctl-choice-slider span { font-weight: 600; }
30
+ .tf-ctl-choice-slider input { flex: 1 1 140px; accent-color: var(--tf-ctl-accent); }
31
+ .tf-ctl-choice-slider input:focus-visible { outline: 2px solid var(--tf-ctl-accent); outline-offset: 2px; }
32
+ .tf-ctl-choice-slider output { font-variant-numeric: tabular-nums; min-width: 4em; }
33
+ .tf-ctl-fullscreen { margin-left: auto; display: inline-flex; align-items: center; justify-content: center; }
34
+ .tf-ctl-fullscreen svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
35
+ /* Full screen, by either route. The figure becomes a column: the drawing takes the room
36
+ that's left after the controls and captions. !important because the host page's own
37
+ figure rules (a max-width, a min-width that makes a diagram scroll on phones) would
38
+ otherwise keep the drawing at its in-page size. */
39
+ .tf-fullscreen { box-sizing: border-box !important; display: flex !important; flex-direction: column; width: 100% !important; max-width: none !important; height: 100vh; height: 100dvh; margin: 0 !important; padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)) !important; overflow: auto !important; background: var(--tf-fullscreen-bg, #fff); }
40
+ .tf-fullscreen > * { flex: none; }
41
+ .tf-fullscreen > svg, .tf-fullscreen > canvas { flex: 1 1 0; min-height: 0; width: 100% !important; min-width: 0 !important; height: 100% !important; }
42
+ .tf-fullscreen-overlay { position: fixed !important; inset: 0; z-index: 2147483000; }
43
+ /* A short landscape screen (a phone on its side): stacking the controls under the drawing
44
+ leaves the drawing a thin strip, so put them in a column beside it instead. */
45
+ @media (orientation: landscape) and (max-height: 520px) {
46
+ .tf-fullscreen { display: grid !important; grid-template-columns: minmax(0, 1fr) minmax(200px, 34%); grid-auto-rows: min-content; column-gap: 12px; align-content: start; }
47
+ .tf-fullscreen > svg, .tf-fullscreen > canvas { grid-column: 1; grid-row: 1 / span 12; height: calc(100vh - 24px) !important; height: calc(100dvh - 24px) !important; }
48
+ .tf-fullscreen > :not(svg):not(canvas) { grid-column: 2; }
49
+ }
50
+ `;let Fn=0;function Xn(e){if(e.getElementById(se))return;const t=e.createElement("style");t.id=se,t.textContent=Nn,e.head.appendChild(t)}function ie(e,t,n={}){const s=t.ownerDocument;Xn(s);const i={...ne,...n.labels},r=n.speeds??[.5,1,2],a=()=>e.markers.length>0,o=()=>e.markers.some(w=>w.label!==void 0||e.caption(w.id)!==void 0),c=s.createElement("div");c.className="tf-ctl";const l=s.createElement("div");l.className="tf-ctl-bar",l.setAttribute("role","group");const u=(w,E,F,N="")=>{const D=s.createElement("button");return D.type="button",D.className=`tf-ctl-btn ${N}`.trim(),D.setAttribute("aria-label",w),D.title=w,D.textContent=E,D.addEventListener("click",F),D},h=u(i.restart,"⟲",()=>{e.pause(),e.seek(0)}),d=u(i.prev,"◀",()=>e.prev()),f=u(i.play,"▶",()=>e.isPlaying?e.pause():p(),"tf-ctl-primary"),g=u(i.next,"▶|",()=>e.next()),p=()=>{e.currentTime>=e.duration-.5&&e.seek(0),e.play()},m=s.createElement("input");m.type="range",m.className="tf-ctl-scrub",m.min="0",m.max="1000",m.step="1",m.setAttribute("aria-label",i.scrub),m.addEventListener("input",()=>{e.pause(),e.seek(Number(m.value)/1e3*e.duration)});const b=s.createElement("span");b.className="tf-ctl-step";const v=s.createElement("select");v.className="tf-ctl-speed",v.setAttribute("aria-label",i.speed);for(const w of r){const E=s.createElement("option");E.value=String(w),E.textContent=`${w}×`,w===1&&(E.selected=!0),v.appendChild(E)}v.addEventListener("change",()=>e.setSpeed(Number(v.value))),l.append(h,d,f,g,m,b),r.length>0&&l.append(v),c.append(l);const k=n.fullscreen?Wn(t,s,i):void 0;k&&l.append(k.button);const M=s.createElement("p");M.className="tf-ctl-caption",M.setAttribute("aria-live","polite"),n.captions!==!1&&c.append(M);const y=s.createElement("div");y.className="tf-ctl-question",y.hidden=!0;const S=s.createElement("span"),x=u(i.reveal,i.reveal,()=>e.play(),"tf-ctl-primary");y.append(S,x),c.append(y);const P=Yn(e,s,i.scenario,n.scenarioControl??"buttons");P&&c.append(P.element);const W=n.mount;W?W.appendChild(c):t.insertAdjacentElement("afterend",c);const T=()=>{const w=e.isPlaying;f.textContent=w?"❚❚":"▶",f.setAttribute("aria-label",w?i.pause:i.play),f.title=w?i.pause:i.play;const E=e.duration;s.activeElement!==m&&(m.value=String(E>0?Math.round(e.currentTime/E*1e3):0));const F=e.markers;if(d.hidden=g.hidden=b.hidden=F.length===0,F.length>0){const N=e.currentMarker,D=N?F.indexOf(N)+1:0;b.textContent=i.stepFormat.replace("{index}",String(D)).replace("{total}",String(F.length)),b.setAttribute("aria-label",`${i.step} ${D} ${i.of} ${F.length}`),d.disabled=e.currentTime<=.5,g.disabled=e.currentTime>=E-.5;const A=e.caption()??"";M.textContent!==A&&(M.textContent=A),M.hidden=!o();const I=!w&&N?.question!==void 0&&Math.abs(e.currentTime-N.time)<1;y.hidden=!I,I&&S.textContent!==N.question&&(S.textContent=N.question)}else y.hidden=!0,M.hidden=!0;P?.update()},R=e.subscribe(T);T();const _=n.keyboardScope??t;!_.hasAttribute("tabindex")&&_.tabIndex<0&&(_.tabIndex=0);const C=new WeakSet,O=w=>{if(C.has(w)||(C.add(w),w.defaultPrevented||w.altKey||w.ctrlKey||w.metaKey))return;const E=w.target;if(!(E.tagName==="INPUT"||E.tagName==="SELECT")&&!(w.key===" "&&E.tagName==="BUTTON"))switch(w.key){case" ":w.preventDefault(),e.isPlaying?e.pause():p();break;case"ArrowRight":if(!a())return;w.preventDefault(),e.next();break;case"ArrowLeft":if(!a())return;w.preventDefault(),e.prev();break;case"Home":w.preventDefault(),e.pause(),e.seek(0);break;case"f":case"F":if(!k)return;w.preventDefault(),k.active?k.exit():k.enter();break}};return _.addEventListener("keydown",O),c.addEventListener("keydown",O),{element:c,fullscreen:k&&{get active(){return k.active},enter:k.enter,exit:k.exit},destroy(){k?.destroy(),R(),_.removeEventListener("keydown",O),c.removeEventListener("keydown",O),c.remove()}}}function Yn(e,t,n,s){const i=e.scenarios;if(i.length<2)return;if(s==="slider"){const u=t.createElement("div");u.className="tf-ctl-choice-slider";const h=t.createElement("span");h.textContent=n,h.setAttribute("aria-hidden","true");const d=t.createElement("input");d.type="range",d.min="0",d.max=String(i.length-1),d.step="1",d.setAttribute("aria-label",n);const f=t.createElement("output");return f.setAttribute("aria-hidden","true"),d.addEventListener("input",()=>{const p=i[Number(d.value)];p&&e.setScenario(p.id)}),u.append(h,d,f),{element:u,update:()=>{const p=Math.max(0,i.findIndex(b=>b.id===e.scenario));t.activeElement!==d&&(d.value=String(p));const m=i[p].label;f.textContent!==m&&(f.textContent=m),d.setAttribute("aria-valuetext",m)}}}const r=t.createElement("fieldset");r.className="tf-ctl-choices";const a=t.createElement("legend");a.textContent=n,r.append(a);const o=`tf-ctl-scenario-${++Fn}`,c=i.map(u=>{const h=t.createElement("label");h.className="tf-ctl-choice";const d=t.createElement("input");d.type="radio",d.name=o,d.value=u.id,d.addEventListener("change",()=>{d.checked&&e.setScenario(u.id)});const f=t.createElement("span");return f.textContent=u.label,h.append(d,f),r.append(h),d});return{element:r,update:()=>{for(const u of c){const h=u.value===e.scenario;u.checked!==h&&(u.checked=h)}}}}const qn='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',Vn='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';function Wn(e,t,n){const s=t,i=e,r=t.createElement("button");r.type="button",r.className="tf-ctl-btn tf-ctl-fullscreen";let a,o="";const c=()=>{const p=a!==void 0;r.innerHTML=p?Vn:qn;const m=p?n.exitFullscreen:n.fullscreen;r.setAttribute("aria-label",m),r.title=m,r.setAttribute("aria-pressed",String(p)),e.classList.toggle("tf-fullscreen",p),e.classList.toggle("tf-fullscreen-overlay",a==="overlay")},l=()=>s.fullscreenElement??s.webkitFullscreenElement??null,u=()=>{l()===e?a="native":a==="native"&&(a=void 0),c()},h=p=>{p.key==="Escape"&&g()},d=()=>{a="overlay",o=t.documentElement.style.overflow,t.documentElement.style.overflow="hidden",t.addEventListener("keydown",h),c()};async function f(){if(a)return;const p=i.requestFullscreen?.bind(i)??i.webkitRequestFullscreen?.bind(i),m=s.fullscreenEnabled??s.webkitFullscreenEnabled??!1;if(p&&m)try{if(await p(),l()===e){a="native",c();return}}catch{}d()}async function g(){if(a==="overlay")t.removeEventListener("keydown",h),t.documentElement.style.overflow=o,a=void 0,c();else if(a==="native"){a=void 0,c();const p=s.exitFullscreen?.bind(s)??s.webkitExitFullscreen?.bind(s);l()===e&&p&&await p()}}return r.addEventListener("click",()=>{a?g():f()}),t.addEventListener("fullscreenchange",u),t.addEventListener("webkitfullscreenchange",u),c(),{button:r,get active(){return a!==void 0},enter:f,exit:g,destroy(){g(),t.removeEventListener("fullscreenchange",u),t.removeEventListener("webkitfullscreenchange",u),r.remove()}}}const re="tinyfly-choices-style",Bn=`
51
+ [data-tinyfly-choose] { cursor: pointer; }
52
+ [data-tinyfly-choose]:focus-visible { outline: 2px solid var(--tf-ctl-accent, #c2410c); outline-offset: 2px; }
53
+ `;function Un(e){if(e.getElementById(re))return;const t=e.createElement("style");t.id=re,t.textContent=Bn,e.head.appendChild(t)}function ae(e,t){const n=Array.from(t.querySelectorAll("[data-tinyfly-choose]"));if(n.length===0)return()=>{};Un(t.ownerDocument);const s=[],i=[];for(const o of n){const c=o.getAttribute("data-tinyfly-choose")??"",l=[],u=(g,p)=>{o.hasAttribute(g)||(o.setAttribute(g,p),l.push(g))};u("role","button"),u("tabindex","0");const h=e.scenarios.find(g=>g.id===c)?.label;h!==void 0&&u("aria-label",h),o.setAttribute("aria-pressed","false"),l.push("aria-pressed"),s.push({element:o,attributes:l});const d=()=>e.setScenario(c),f=g=>{const p=g.key;p!=="Enter"&&p!==" "||(g.preventDefault(),d())};o.addEventListener("click",d),o.addEventListener("keydown",f),i.push(()=>{o.removeEventListener("click",d),o.removeEventListener("keydown",f)})}const r=()=>{for(const{element:o}of s)o.setAttribute("aria-pressed",String(o.getAttribute("data-tinyfly-choose")===e.scenario))},a=e.subscribe(r);return r(),()=>{a();for(const o of i)o();for(const{element:o,attributes:c}of s)for(const l of c)o.removeAttribute(l)}}const ot=new WeakMap,Mt=new WeakMap;let jn=0;function J(e,t,n){if(e)try{return JSON.parse(e)}catch(s){console.warn(`tinyfly: invalid ${t} JSON on`,n,s);return}}async function oe(e,t={}){const n=ot.get(e);if(n)return n;const s=Array.from(e.querySelectorAll("script[data-tinyfly-timeline]")),i=s[0],r=e.getAttribute("data-src"),a=zn(e.getAttribute("data-markers")),o=s.length>1||i?.hasAttribute("data-scenario")?Hn(s,a,e):void 0;if(o&&o.length===0)return;let c=i&&!o?J(i.textContent,"timeline",e):void 0;if(!c&&r&&a){const f=await fetch(r);f.ok&&(c=await f.json())}if(c&&a&&(c=ce(c,a)),!c&&!r&&!o){console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)',e);return}const l=J(e.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",e),u={playWhenVisible:!0,...t.player,...l&&{captions:l},...J(e.getAttribute("data-options"),"data-options",e)};Qn(e);const h=new at(e,u),d={element:e,player:h};if(ot.set(e,d),e.setAttribute("data-tinyfly-mounted",""),o){const f=e.getAttribute("data-scenario")??void 0;await h.loadScenarios(o,{initial:o.some(g=>g.id===f)?f:void 0}),Mt.set(e,ae(h,e))}else await h.load(c??r);if(e.getAttribute("data-controls")!=="false"){const f=J(e.getAttribute("data-labels"),"data-labels",e),g=e.querySelector("figcaption"),p=e.getAttribute("data-scenario-legend"),m=e.getAttribute("data-scenario-control");d.controls=ie(h,e,{...t.controls,...e.getAttribute("data-fullscreen")==="true"?{fullscreen:!0}:{},...m==="slider"||m==="buttons"?{scenarioControl:m}:{},labels:{...t.controls?.labels,...f,...p?{scenario:p}:{}},mount:void 0}),g?e.insertBefore(d.controls.element,g):e.appendChild(d.controls.element)}return d}function Hn(e,t,n){const s=[];return e.forEach((i,r)=>{const a=J(i.textContent,"timeline",n);if(!a)return;const o=i.getAttribute("data-scenario")||`scenario-${r+1}`;if(s.some(l=>l.id===o)){console.warn(`tinyfly: scenario id "${o}" is used more than once; the later one is skipped`,n);return}const c=i.getAttribute("data-scenario-label")??void 0;s.push({id:o,label:c,timeline:t?ce(a,t):a})}),s}function ce(e,t){return e.config.markers?.length?e:{...e,config:{...e.config,markers:t.map((n,s)=>({id:`step-${s+1}`,time:n}))}}}function zn(e){if(!e)return;const t=e.split(/[\s,]+/).filter(Boolean).map(Number).filter(n=>Number.isFinite(n)&&n>=0).sort((n,s)=>n-s);return t.length>0?t:void 0}async function le(e=document,t={}){const n=Array.from(e.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(n.map(i=>oe(i,t)))).filter(i=>i!==void 0)}function Gn(e){const t=ot.get(e);t&&(Mt.get(e)?.(),Mt.delete(e),t.controls?.destroy(),t.player.destroy(),ot.delete(e),e.removeAttribute("data-tinyfly-mounted"))}function Qn(e){const t=e.querySelector("svg");if(!t||t.hasAttribute("role")||t.hasAttribute("aria-hidden"))return;const n=e.getAttribute("data-alt"),s=e.querySelector("figcaption");t.setAttribute("role","img"),n?t.setAttribute("aria-label",n):s&&(s.id||=`tinyfly-caption-${++jn}`,t.setAttribute("aria-labelledby",s.id))}function Zn(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const t=()=>{le()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}function St(e){const t=new Set;for(const n of e.matchAll(/data-tinyfly\s*=\s*("([^"]*)"|'([^']*)')/g))t.add(n[2]??n[3]);return[...t]}function he(e,t={}){const n=[],s=l=>n.push({level:"error",message:l}),i=l=>n.push({level:"warning",message:l});if((e.formatVersion??1)>H)return s(`format version ${e.formatVersion} is newer than this tinyfly reads (${H})`),n;let r=0;try{r=rt(e).duration}catch(l){return s(`the timeline does not load: ${l instanceof Error?l.message:String(l)}`),n}const a=e.config?.duration;if(a!==void 0)for(const l of e.tracks){if(!("keyframes"in l))continue;const u=l.keyframes.filter(h=>h.time>a);u.length>0&&s(`track "${l.id}" has a keyframe at ${u[0].time}ms, after the ${a}ms duration`)}const o=e.config?.markers??[],c=new Set;o.forEach((l,u)=>{c.has(l.id)&&s(`marker id "${l.id}" is used more than once`),c.add(l.id),(l.time<0||l.time>r)&&s(`marker "${l.id}" at ${l.time}ms is outside the animation (0–${r}ms)`),u>0&&l.time<o[u-1].time&&s(`marker "${l.id}" comes before "${o[u-1].id}" in time; list markers in order`)});for(const[l,u]of Object.entries(e.captions??{})){for(const h of Object.keys(u))c.has(h)||s(`caption "${h}" (${l}) has no marker with that id`);for(const h of c)h in u||i(`marker "${h}" has no ${l} caption; its label is shown instead`)}if(t.markup!==void 0){const l=new Set(St(t.markup)),u=new Set;for(const h of e.tracks)for(const d of[h.target,...h.targets??[]])u.add(d),l.has(d)||s(`track "${h.id}" targets "${d}", but no element has data-tinyfly="${d}"`);for(const h of l)u.has(h)||i(`data-tinyfly="${h}" is never animated`)}return n}function Kn(e){const t=new Set;for(const n of e.matchAll(/data-tinyfly-choose\s*=\s*("([^"]*)"|'([^']*)')/g))t.add(n[2]??n[3]);return[...t]}function Jn(e,t={}){const n=[];e.length===1&&n.push({level:"warning",message:"only one scenario, so the reader has nothing to choose"});const s=new Set,i=new Set;for(const r of e){if(s.has(r.id)){n.push({level:"error",message:`scenario id "${r.id}" is used more than once`});continue}s.add(r.id);for(const a of he(r.timeline,t))/is never animated$/.test(a.message)||n.push({level:a.level,message:`scenario "${r.id}": ${a.message}`});for(const a of r.timeline.tracks)for(const o of[a.target,...a.targets??[]])i.add(o)}if(t.markup!==void 0){for(const r of Kn(t.markup))s.has(r)||n.push({level:"error",message:`data-tinyfly-choose="${r}" names no scenario`});for(const r of St(t.markup))i.has(r)||n.push({level:"warning",message:`data-tinyfly="${r}" is never animated in any scenario`})}return n}function ts(e,t,n="end"){const s=rt(t),i=t.config?.markers??[],r=n==="start"?0:n==="end"?s.duration:typeof n=="number"?n:i.find(d=>d.id===n)?.time??s.duration,a=s.getStateAtTime(Math.max(0,Math.min(s.duration,r))),o=new wt,c=new Map,l=ns(e);for(const d of e.matchAll(ue)){const f=/data-tinyfly\s*=\s*("([^"]*)"|'([^']*)')/.exec(d[2]??"");if(!f)continue;const g=f[2]??f[3];if(c.has(g))continue;const p=es(l(d.index??0));c.set(g,p),o.registerTarget(g,p)}o.applyState(a);let u="",h=0;for(const d of e.matchAll(ue)){const[f,g,p="",m]=d,b=d.index??0,v=/data-tinyfly\s*=\s*("([^"]*)"|'([^']*)')/.exec(p),k=v?c.get(v[2]??v[3]):void 0;if(!k||Object.keys(k.style).length===0&&k.text===void 0)continue;u+=e.slice(h,b);const M=Object.entries(k.style).map(([x,P])=>`${ss(x)}: ${P}`).join("; "),y=/\sstyle\s*=\s*("([^"]*)"|'([^']*)')/.exec(p);let S=p;if(M)if(y){const x=`${(y[2]??y[3]).trim().replace(/;?$/,";")} ${M}`.trim();S=p.replace(y[0],` style="${de(x)}"`)}else S=`${p} style="${de(M)}"`;if(u+=`<${g}${S}${m?" /":""}>`,h=b+f.length,k.text!==void 0&&!m){const x=e.indexOf(`</${g}`,h),P=x===-1?"":e.slice(h,x);x!==-1&&!P.includes("<")&&(u+=is(k.text),h=x)}}return u+e.slice(h)}const ue=/<([a-zA-Z][\w:-]*)((?:\s+[^\s=>/]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+))?)*)\s*(\/?)>/g;function es(e){const t={style:{},dataset:{},namespaceURI:e?"http://www.w3.org/2000/svg":"http://www.w3.org/1999/xhtml",childNodes:[],get textContent(){return t.text??""},set textContent(n){t.text=n}};return e&&(t.ownerSVGElement=null),t}function ns(e){const t=[],n=/<svg[\s>]/gi;let s;for(;s=n.exec(e);){const i=e.toLowerCase().indexOf("</svg>",s.index);t.push([s.index+1,i===-1?e.length:i])}return i=>t.some(([r,a])=>i>r&&i<a)}function ss(e){const t=e.replace(/[A-Z]/g,n=>`-${n.toLowerCase()}`);return/^(webkit|moz|ms)-/.test(t)?`-${t}`:t}function de(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;")}function is(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;")}Zn(),$.DEFAULT_LABELS=ne,$.TinyflyPlayer=at,$.bindChoiceHotspots=ae,$.create=On,$.createControls=ie,$.mount=oe,$.mountAll=le,$.play=Ln,$.renderFrame=ts,$.targetNamesIn=St,$.unmount=Gn,$.validateEmbed=he,$.validateScenarios=Jn,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})})(this.tinyfly=this.tinyfly||{});