@algorisys/tinyfly 0.68.1 → 0.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -15
- package/bin/tinyfly.mjs +20 -6
- package/lib/browser/tinyfly.iife.js +18 -3
- package/lib/browser/tinyfly.js +1486 -1291
- package/lib/browser/tinyfly.umd.js +18 -3
- package/lib/cli/tools.js +34 -1
- package/lib/embed/tinyfly-embed.iife.js +18 -3
- package/lib/embed/tinyfly-embed.js +972 -749
- package/lib/player/tinyfly-player.es.js +200 -128
- package/lib/player/tinyfly-player.iife.js +2 -2
- package/lib/player/tinyfly-player.umd.js +2 -2
- package/lib/types/browser/index.d.ts +1 -0
- package/lib/types/embed/choices.d.ts +3 -0
- package/lib/types/embed/controls.d.ts +10 -2
- package/lib/types/embed/index.d.ts +3 -2
- package/lib/types/embed/mount.d.ts +7 -0
- package/lib/types/embed/tools.d.ts +10 -0
- package/lib/types/player/index.d.ts +1 -1
- package/lib/types/player/player.d.ts +50 -0
- package/package.json +1 -1
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(R){"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 j=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,s="start"){if(t<=1)return 0;if(typeof s=="number"){const i=Math.max(0,Math.min(t-1,s));return Math.abs(e-i)}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 ge(e,t="start"){if(e<=1)return 0;let s=0;for(let i=0;i<e;i++)s=Math.max(s,At(i,e,t));return s}function Pt(e,t,s){if(s.offsets)return s.offsets[e]??0;const i=s.from??"start",n=At(e,t,i);if(s.amount!==void 0){const r=ge(t,i);return r===0?0:s.amount*n/r}return s.each!==void 0?s.each*n:0}function ye(e,t){return Array.from({length:e},(s,i)=>Pt(i,e,t))}function ut(e,t){return e<=1?0:Math.max(...ye(e,t))}const H=1,Ct=6e4,et=Ct/H,W={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??W.stiffness,this.damping=t.damping??W.damping,this.mass=t.mass??W.mass,this.restDelta=t.restDelta??W.restDelta,this.restSpeed=t.restSpeed??W.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=t.velocity??W.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/H);if(this.simulateTo(s+1),this.settledStep!==null&&s>=this.settledStep)return this.to;const i=this.samples[Math.min(s,this.samples.length-1)],n=this.samples[Math.min(s+1,this.samples.length-1)],r=t/H-s;return i+(n-i)*r}settleTime(){return this.simulateTo(et+1),this.settledStep!==null?this.settledStep*H:Ct}simulateTo(t){if(this.settledStep!==null)return;const s=Math.min(t,et+1),i=H/1e3;for(;this.samples.length<s;){const n=this.samples[this.samples.length-1],r=n-this.to,a=-this.stiffness*r,o=-this.damping*this.velocity,c=(a+o)/this.mass;this.velocity+=c*i;const l=n+this.velocity*i;if(this.samples.push(l),this.isAtRest(l)){this.settledStep=this.samples.length-1;return}}this.samples.length>et&&(this.settledStep=et)}}const It=4,ke=.002,Me=1e-4,Se=6e4;function dt(e){const t=e.friction??It;return t>0?t:It}function we(e){return e.from+e.velocity/dt(e)}function xe(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 i of t)Math.abs(i-e)<Math.abs(s-e)&&(s=i);return s}function Et(e){let t=xe(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(Et(e)-e.from);if(t===0)return 0;const s=e.restDelta??Math.max(Me,t*ke);if(s>=t)return 0;const i=Math.log(t/s)/dt(e);return Math.min(Se,i*1e3)}function $t(e,t){if(t<=0)return e.from;const s=Et(e);if(t>=Rt(e))return s;const i=dt(e);return e.from+(s-e.from)*(1-Math.exp(-i*t/1e3))}const ft=e=>e,ve=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":ve,"ease-out-quad":Te,"ease-in-out-quad":_e,"ease-in-cubic":Dt,"ease-out-cubic":Lt,"ease-in-out-cubic":Ot};function Pe(e){const[t,s,i,n]=e,r=3*t,a=3*(i-t)-r,o=1-r-a,c=3*s,l=3*(n-s)-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 M=0;M<8;M++){const x=h(m)-p;if(Math.abs(x)<1e-7)return m;const y=f(m);if(Math.abs(y)<1e-7)break;m-=x/y}let b=0,k=1;for(m=p;b<k;){const M=h(m);if(Math.abs(M-p)<1e-7)return m;p>M?b=m:k=m,m=(b+k)/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 s=i=>1-e(1-i);return t==="in"?s:i=>i<.5?s(i*2)/2:e(i*2-1)/2+.5}function Ce(e=1,t=.3){const s=Math.max(1,e),i=t/(2*Math.PI)*Math.asin(1/s);return n=>n<=0?0:n>=1?1:s*Math.pow(2,-10*n)*Math.sin((n-i)*(2*Math.PI)/t)+1}const Ie=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 n=e-.5454545454545454;return 7.5625*n*n+.75}if(e<2.5/2.75){const n=e-.8181818181818182;return 7.5625*n*n+.9375}const i=e-2.625/2.75;return 7.5625*i*i+.984375};function Ee(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 Re(e,t="end"){const s=Math.max(1,Math.floor(e));return i=>{if(i>=1)return 1;if(i<=0)return t==="start"||t==="both"?t==="start"?1/s:1/(s+1):0;const n=Math.floor(i*s);switch(t){case"start":return Math.min(1,(n+1)/s);case"both":return(n+1)/(s+1);case"none":return s===1?0:Math.min(1,n/(s-1));default:return n/s}}}function $e(e){switch(e.type){case"steps":return Re(e.count,e.position);case"elastic":return pt(Ce(e.amplitude,e.period),e.mode);case"bounce":return pt(Ie,e.mode);case"back":return pt(Ee(e.overshoot),e.mode)}}function De(e){return e===void 0?ft:fe(e)?Pe(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 s=0,i=null;const n=()=>{for(;s<e.length&&/[\s,]/.test(e[s]);)s++};for(;s<e.length&&(n(),!(s>=e.length));){const r=e[s];if(Oe.test(r)){i={type:r,args:[]},t.push(i),s++;continue}if(!i)break;const a=i.type==="A"||i.type==="a",o=i.args.length%7;if(a&&(o===3||o===4)){if(r!=="0"&&r!=="1")break;i.args.push(r==="1"?1:0),s++;continue}const c=Ne.exec(e.slice(s));if(!c)break;i.args.push(parseFloat(c[0])),s+=c[0].length}return t}function Ye(e,t,s,i,n,r,a,o,c){if(e===o&&t===c)return[];let l=Math.abs(s),u=Math.abs(i);if(l===0||u===0)return[[e,t,o,c,o,c]];const h=n*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,k=m*m/(l*l)+b*b/(u*u);if(k>1){const T=Math.sqrt(k);l*=T,u*=T}const M=r===a?-1:1,x=l*l*u*u-l*l*b*b-u*u*m*m,y=l*l*b*b+u*u*m*m,v=M*Math.sqrt(Math.max(0,x/y)),w=v*l*b/u,E=-v*u*m/l,V=d*w-f*E+(e+o)/2,_=f*w+d*E+(t+c)/2,A=(T,$,L,U)=>{const Tt=T*L+$*U,ct=Math.sqrt((T*T+$*$)*(L*L+U*U)),tt=Math.acos(Math.max(-1,Math.min(1,Tt/ct)));return T*U-$*L<0?-tt:tt},C=A(1,0,(m-w)/l,(b-E)/u);let P=A((m-w)/l,(b-E)/u,(-m-w)/l,(-b-E)/u);!a&&P>0&&(P-=2*Math.PI),a&&P<0&&(P+=2*Math.PI);const S=Math.max(1,Math.ceil(Math.abs(P)/(Math.PI/2))),I=P/S,O=4/3*Math.tan(I/4),N=T=>{const $=l*Math.cos(T),L=u*Math.sin(T);return[d*$-f*L+V,f*$+d*L+_]},D=T=>{const $=-l*Math.sin(T),L=u*Math.cos(T);return[d*$-f*L,f*$+d*L]},J=[];for(let T=0;T<S;T++){const $=C+T*I,L=$+I,[U,Tt]=N($),[ct,tt]=T===S-1?[o,c]:N(L),[ei,si]=D($),[ii,ni]=D(L);J.push([U+O*ei,Tt+O*si,ct-O*ii,tt-O*ni,ct,tt])}return J}function X(e,t,s,i,n){const r=1-n;return r*r*r*e+3*r*r*n*t+3*r*n*n*s+n*n*n*i}function Ft(e,t,s,i,n){const r=1-n;return 3*r*r*(t-e)+6*r*n*(s-t)+3*n*n*(i-s)}function z(e,t,s,i){return{subpath:0,type:"L",points:[s,i],startX:e,startY:t,endX:s,endY:i,length:Math.hypot(s-e,i-t)}}function st(e,t,s){const[i,n,r,a,o,c]=s,l=[0];let u=e,h=t,d=0;for(let f=1;f<=Nt;f++){const g=f/Nt,p=X(e,i,r,o,g),m=X(t,n,a,c,g);d+=Math.hypot(p-u,m-h),l.push(d),u=p,h=m}return{subpath:0,type:"C",points:[i,n,r,a,o,c],startX:e,startY:t,endX:o,endY:c,length:d,lengths:l}}function it(e){const t=G.get(e);if(t)return t;const s=[];let i=0,n=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 Xe(e)){const b=p.toUpperCase(),k=p!==b,M=Fe[b];if(b==="Z"){(i!==r||n!==a)&&h(z(i,n,r,a)),l>=0&&u.add(l),i=r,n=a,o=c=null;continue}for(let x=0;x+M<=m.length;x+=M){const y=m.slice(x,x+M),v=k?i:0,w=k?n:0;let E=null,V=null;switch(b){case"M":x===0?(i=y[0]+v,n=y[1]+w,r=i,a=n,(l<0||s[s.length-1]?.subpath===l)&&l++):(h(z(i,n,y[0]+v,y[1]+w)),i=y[0]+v,n=y[1]+w);break;case"L":h(z(i,n,y[0]+v,y[1]+w)),i=y[0]+v,n=y[1]+w;break;case"H":h(z(i,n,y[0]+v,n)),i=y[0]+v;break;case"V":h(z(i,n,i,y[0]+w)),n=y[0]+w;break;case"C":{const _=[y[0]+v,y[1]+w,y[2]+v,y[3]+w,y[4]+v,y[5]+w];h(st(i,n,_)),E=[_[2],_[3]],i=_[4],n=_[5];break}case"S":{const[_,A]=o?[2*i-o[0],2*n-o[1]]:[i,n],C=[_,A,y[0]+v,y[1]+w,y[2]+v,y[3]+w];h(st(i,n,C)),E=[C[2],C[3]],i=C[4],n=C[5];break}case"Q":case"T":{let _=i,A=n;b==="Q"?(_=y[0]+v,A=y[1]+w):c&&(_=2*i-c[0],A=2*n-c[1]);const C=b==="Q"?y[2]+v:y[0]+v,P=b==="Q"?y[3]+w:y[1]+w;h(st(i,n,[i+2/3*(_-i),n+2/3*(A-n),C+2/3*(_-C),P+2/3*(A-P),C,P])),V=[_,A],i=C,n=P;break}case"A":{const _=y[5]+v,A=y[6]+w;let C=i,P=n;for(const S of Ye(i,n,y[0],y[1],y[2],y[3],y[4],_,A))h(st(C,P,S)),C=S[4],P=S[5];i=_,n=A;break}}o=E,c=V}}const d=s.reduce((p,m)=>p+m.length,0),f=[];for(let p=0;p<s.length;){const m=s[p].subpath;let b=p,k=0;for(;b<s.length&&s[b].subpath===m;)k+=s[b++].length;const M=s[p],x=s[b-1],y=u.has(m)||Math.abs(x.endX-M.startX)<1e-9&&Math.abs(x.endY-M.startY)<1e-9;f.push({start:p,end:b,length:k,closed:y}),p=b}const g={segments:s,totalLength:d,subpaths:f};return G.size>=Le&&G.delete(G.keys().next().value),G.set(e,g),g}function qe(e,t){const s=e.lengths;if(t<=0)return 0;if(t>=e.length)return 1;let i=0,n=s.length-1;for(;i<n-1;){const o=i+n>>1;s[o]<t?i=o:n=o}const r=s[n]-s[i],a=r>0?(t-s[i])/r:0;return(i+a)/(s.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[s,i,n,r,a,o]=e.points,c=qe(e,t);let l=Ft(e.startX,s,n,a,c),u=Ft(e.startY,i,r,o,c);if(Math.hypot(l,u)<1e-9){const h=c<.5?Math.min(1,c+.001):Math.max(0,c-.001),d=X(e.startX,s,n,a,h),f=X(e.startY,i,r,o,h),g=X(e.startX,s,n,a,c),p=X(e.startY,i,r,o,c);l=c<.5?d-g:g-d,u=c<.5?f-p:p-f}return{x:X(e.startX,s,n,a,c),y:X(e.startY,i,r,o,c),angle:Math.atan2(u,l)*180/Math.PI}}function Xt(e,t,s=0,i=e.length){if(i<=s)return{x:0,y:0,angle:0};let n=0;for(let r=s;r<i;r++){const a=e[r];if(n+a.length>=t||r===i-1)return Ve(a,t-n);n+=a.length}return{x:0,y:0,angle:0}}function We(e,t){const{segments:s,totalLength:i}=it(e);return Xt(s,Math.max(0,Math.min(1,t))*i)}const Be=24,Ue=320,je=2.5,Q=72,He=.2,Ge=128,nt=new Map;let mt=0,Y;const Yt=e=>Math.round(e*100)/100;function qt(e,t){const{segments:s,subpaths:i,totalLength:n}=it(e);if(s.length===0)return[];if(t){const r=i.every(a=>a.closed);return[{segments:s,start:0,end:s.length,length:n,closed:r}]}return i.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)),i=Xt(e.segments,s*e.length,e.start,e.end);return[i.x,i.y]}function Vt(e){const t=[];let s=0;for(let i=e.start;i<e.end;i++)s+=e.segments[i].length,e.length>0&&t.push(s/e.length);return t}function Wt(e,t){const s=[];for(let i=0;i<t;i++)s.push(gt(e,e.closed?i/t:i/(t-1)));return s}function Bt(e){let t=0,s=0;for(const[i,n]of e)t+=i,s+=n;return t/=e.length,s/=e.length,e.map(([i,n])=>[i-t,n-s])}function ze(e,t,s){const i=e.closed&&t.closed;if(s!==void 0)return{offset:i?Math.abs(s)%Q/Q:0,reversed:s<0};const n=Bt(Wt(e,Q)),r=Bt(Wt(t,Q)),a=Q;let o={offset:0,reversed:!1},c=1/0;for(const l of[!1,!0]){const u=i?a:1;for(let h=0;h<u;h++){let d=0;for(let f=0;f<a&&d<c;f++){const g=i?l?(h-f+a)%a:(f+h)%a:l?a-1-f:f,p=n[f][0]-r[g][0],m=n[f][1]-r[g][1];d+=p*p+m*m}d<c&&(c=d,o={offset:i?h/a:0,reversed:l})}}return o}function Qe(e,t,s){return s?((t.reversed?t.offset-e:e+t.offset)%1+1)%1:t.reversed?1-e:e}function Ze(e,t,s){return s?((t.reversed?t.offset-e:e-t.offset)%1+1)%1:t.reversed?1-e:e}function Ke(e,t,s){const i=e.closed&&t.closed,n=ze(e,t,s.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,n,i));let c=[...a].sort((h,d)=>h-d);i&&(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,n,i)));return Je({from:l,to:u,closed:i})}function Je(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 i=[[0,t-1]];for(;i.length>0;){const[a,o]=i.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&&(s[c]=1,i.push([a,c],[c,o]))}const n=[],r=[];for(let a=0;a<t;a++)s[a]&&(n.push(e.from[a*2],e.from[a*2+1]),r.push(e.to[a*2],e.to[a*2+1]));return{from:n,to:r,closed:e.closed}}function Ut(e,t,s,i){const n=e[t*2],r=e[t*2+1],a=e[s*2]-n,o=e[s*2+1]-r,c=e[i*2]-n,l=e[i*2+1]-r,u=a*a+o*o,h=u===0?0:Math.max(0,Math.min(1,(c*a+l*o)/u));return Math.hypot(c-h*a,l-h*o)}function ts(e,t,s){const i=s.shapeIndex;if(Y&&Y.from===e&&Y.to===t&&Y.shapeIndex===i)return Y.plan;const r=nt.get(String(i??"auto"))?.get(e)?.get(t);if(r)return Y={from:e,to:t,shapeIndex:i,plan:r},r;const a=it(e).subpaths.filter(f=>f.length>0).length===it(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],s))};mt>=Ge&&(nt.clear(),mt=0);const u=String(i??"auto"),h=nt.get(u)??new Map;nt.set(u,h);const d=h.get(e)??new Map;return h.set(e,d),d.set(t,l),mt++,Y={from:e,to:t,shapeIndex:i,plan:l},l}function es(e,t,s,i={}){if(!e)return t;if(!t)return e;const n=Math.max(0,Math.min(1,s));if(n===0)return e;if(n===1)return t;const r=ts(e,t,i);if(r.pairs.length===0)return n<.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])*n),u=Yt(o.from[c+1]+(o.to[c+1]-o.from[c+1])*n);a+=`${c===0?a?" M":"M":" L"}${l} ${u}`}o.closed&&(a+=" Z")}return a}function ss(e){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(e)}const F=(e,t,s)=>e+(t-e)*s,jt=512,yt=new Map,bt=new Map;function Ht(e){const t=yt.get(e);if(t)return t;const s=e.replace("#",""),i=[parseInt(s.slice(0,2),16),parseInt(s.slice(2,4),16),parseInt(s.slice(4,6),16)];return yt.size<jt&&yt.set(e,i),i}const Gt=e=>e.charCodeAt(0)===35,zt=e=>e.startsWith("rgb"),Qt=e=>e.startsWith("rgba"),is=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,kt=e=>Math.round(e).toString(16).padStart(2,"0");function ns(e,t,s){return`#${kt(e)}${kt(t)}${kt(s)}`}function Zt(e){const t=bt.get(e);if(t)return t;const s=e.match(is);if(!s)throw new Error(`Invalid rgb color: ${e}`);const i=parseInt(s[1],10),n=parseInt(s[2],10),r=parseInt(s[3],10),a=s[4]!==void 0?[i,n,r,parseFloat(s[4])]:[i,n,r];return bt.size<jt&&bt.set(e,a),a}const rs=(e,t,s)=>{if(Gt(e)&&Gt(t)){const[i,n,r]=Ht(e),[a,o,c]=Ht(t),l=F(i,a,s),u=F(n,o,s),h=F(r,c,s);return ns(l,u,h)}if((zt(e)||Qt(e))&&(zt(t)||Qt(t))){const i=Zt(e),n=Zt(t),r=Math.round(F(i[0],n[0],s)),a=Math.round(F(i[1],n[1],s)),o=Math.round(F(i[2],n[2],s));if(i.length===4||n.length===4){const c=i[3]??1,l=n[3]??1,u=F(c,l,s);return`rgba(${r}, ${a}, ${o}, ${u})`}return`rgb(${r}, ${a}, ${o})`}return s<1?e:t},as=(e,t,s)=>{const i=Math.min(e.length,t.length),n=[];for(let r=0;r<i;r++)n.push(F(e[r],t[r],s));return n},Kt=(e,t,s)=>s<1?e:t,os=(e,t,s)=>es(e,t,s);function cs(e){return typeof e=="number"?F:Array.isArray(e)?as:typeof e=="string"?e.startsWith("#")||e.startsWith("rgb")?rs:ss(e)?os:Kt:Kt}function ls(e){const t=[...e.keyframes].sort((s,i)=>s.time-i.time);return{...e,keyframes:t}}function q(e){return e.targets&&e.targets.length>0?e.targets:[e.target]}function B(e,t,s,i){const n=s??0;return!i||t<=1?n:n+Pt(e,t,i)}class Mt{track;targets;constructor(t){this.track=t,this.targets=q(t)}getValueAtTime(t){return this.valueForOffset(t-B(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const s=this.targets.length,i=[];for(let n=0;n<s;n++){const r=B(n,s,this.track.delay,this.track.stagger),a=this.valueForOffset(t-r);a!==void 0&&i.push({target:this.targets[n],value:a,start:r+this.track.keyframes[0].time})}return i}getDuration(){const{keyframes:t}=this.track;if(t.length===0)return 0;const s=t[t.length-1].time,i=this.track.stagger?ut(this.targets.length,this.track.stagger):0;return s+(this.track.delay??0)+i+(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:i,to:n}=this.findSurroundingKeyframes(t);if(!i||!n)return;if(i.time===t)return i.value;const r=n.time-i.time,a=(t-i.time)/r,c=De(n.easing)(a);return cs(i.value)(i.value,n.value,c)}findSurroundingKeyframes(t){const{keyframes:s}=this.track;for(let i=0;i<s.length-1;i++)if(t>=s[i].time&&t<=s[i+1].time)return{from:s[i],to:s[i+1]};return{from:null,to:null}}}class hs{track;targets;sampler;constructor(t){this.track=t,this.targets=q(t),this.sampler=new be(t.spring)}getValueAtTime(t){return this.sampler.valueAt(t-B(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const s=this.targets.length,i=[];for(let n=0;n<s;n++){const r=B(n,s,this.track.delay,this.track.stagger);i.push({target:this.targets[n],value:this.sampler.valueAt(t-r),start:r})}return i}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 us{track;targets;duration;constructor(t){this.track=t,this.targets=q(t),this.duration=Rt(t.inertia)}getValueAtTime(t){return $t(this.track.inertia,t-B(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const s=this.targets.length,i=[];for(let n=0;n<s;n++){const r=B(n,s,this.track.delay,this.track.stagger);i.push({target:this.targets[n],value:$t(this.track.inertia,t-r),start:r})}return i}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 ds(e,t){const s={...We(e.pathData,t)};if(e.matrix){const[i,n,r,a,o,c]=e.matrix,{x:l,y:u}=s;s.x=i*l+r*u+o,s.y=n*l+a*u+c;const h=s.angle*Math.PI/180,d=Math.cos(h),f=Math.sin(h);s.angle=Math.atan2(n*d+a*f,i*d+r*f)*180/Math.PI}return e.autoRotate&&e.rotateOffset&&(s.angle+=e.rotateOffset),s}const St={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},fs=20;function ps(e){const t=St[e??"upperCase"]??e??St.upperCase,s=Array.from(t);return s.length>0?s:Array.from(St.upperCase)}function ms(e,t,s){let i=(e|0)^Math.imul(t+1,2654435761)^Math.imul(s+1,2246822507);return i=Math.imul(i^i>>>16,2146121005),i=Math.imul(i^i>>>15,2221713035),(i^i>>>16)>>>0}function gs(e,t,s=0){const i=e.from??"",n=e.to,r=Math.max(0,Math.min(1,t));if(r<=0)return i;if(r>=1)return n;const a=Array.from(i),o=Array.from(n),c=e.rightToLeft??!1;if(e.mode==="type"){const k=Math.round(r*Math.max(a.length,o.length));return c?a.slice(0,Math.max(0,a.length-k)).join("")+o.slice(Math.max(0,o.length-k)).join(""):o.slice(0,k).join("")+a.slice(k).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=ps(e.chars),g=e.refreshRate??fs,p=g>0?Math.floor(s*g/1e3):0,m=e.seed??1;let b="";for(let k=0;k<d;k++){const M=c?k>=d-h:k<h,x=c?o[o.length-(d-k)]:o[k];M&&x!==void 0||x===" "||x===`
|
|
2
|
+
`?b+=x:b+=f[ms(m,k,p)%f.length]}return b}class ys{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 n=t*this.speed;if(this._repeatDelayRemaining>0){const o=Math.min(this._repeatDelayRemaining,n);if(this._repeatDelayRemaining-=o,n-=o,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const r=1e3;for(let o=0;o<r&&n>0&&this._playbackState==="playing";o++)if(this._direction==="forward"){const c=s-this._currentTime;if(n>=c){if(n-=c,this._currentTime=s,!this._handleEndReached())break}else this._currentTime+=n,n=0}else{const c=this._currentTime;if(n>=c){if(n-=c,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=n,n=0}const a=this.getStateAtTime(this._currentTime);this.onUpdate?.(a)}getStateAtTime(t){const s=new Map;if(this._hasSharedWrites())this._resolveShared(t,s);else for(const[i,n]of this._trackPlayers){const r=n.getTrack().property;for(const{target:a,value:o,start:c}of n.getTargetValues(t))this._write(s,i,a,r,o,t-c)}return{values:s,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(t,s){const i=new Map;for(const[n,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=i.get(u);(!d||(h!==d.started?h:h?l>=d.start:l<=d.start))&&i.set(u,{trackId:n,target:o,property:a,value:c,start:l,started:h})}}for(const{trackId:n,target:r,property:a,value:o,start:c}of i.values())this._write(s,n,r,a,o,t-c)}_write(t,s,i,n,r,a){if(r===void 0)return;let o=t.get(i);o||(o=new Map,t.set(i,o));const c=this._textTracks.get(s);if(c&&typeof r=="number"){o.set("text",gs(c.textConfig,r,Math.max(0,a)));return}const l=this._motionPathTracks.get(s);if(l&&typeof r=="number"){const u=ds(l.motionPathConfig,r);o.set("motionPathX",u.x),o.set("motionPathY",u.y),l.motionPathConfig.autoRotate&&o.set("motionPathRotate",u.angle)}else o.set(n,r)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const t=new Set;this._sharedWrites=!1;t:for(const s of this._tracks)for(const i of q(s)){const n=`${i}\0${s.property}`;if(t.has(n)){this._sharedWrites=!0;break t}t.add(n)}}return this._sharedWrites}addTrack(t){if(this._tracks.push(t),this._sharedWrites=null,lt(t)){this._trackPlayers.set(t.id,new us(t));return}if(ht(t)){this._trackPlayers.set(t.id,new hs(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(me(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 i=this._tracks.findIndex(r=>r.id===t);if(i<0)return;const n=this._tracks.slice(i+1);this.removeTrack(t);for(const r of n)this.removeTrack(r.id);this.addTrack(s);for(const r of n)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(i=>i.id);for(const i of s)this.removeTrack(i);return s}getTrackSpan(t){const s=this._trackPlayers.get(t);if(!s)return;const i=s.getTrack(),n=i.delay??0;if(ht(i)||lt(i))return{from:n,to:s.getDuration()};const r=i.keyframes;if(!(!r||r.length===0))return{from:r[0].time+n,to:s.getDuration()}}findConflicts(){const t=[];for(let s=0;s<this._tracks.length;s++){const i=this._tracks[s],n=this.getTrackSpan(i.id);if(n)for(let r=0;r<s;r++){const a=this._tracks[r];if(a.property!==i.property)continue;const o=q(a).filter(h=>q(i).includes(h));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=n.to&&n.from<=c.to))continue;const u=n.from>=c.from;for(const h of o)t.push({target:h,property:i.property,losingTrackId:u?a.id:i.id,winningTrackId:u?i.id:a.id})}}return t}_matches(t,s){if(s.id!==void 0&&t.id!==s.id||s.property!==void 0&&t.property!==s.property||s.target!==void 0&&!q(t).includes(s.target))return!1;if(s.timeRange){const i=this.getTrackSpan(t.id);if(!i||i.to<s.timeRange.from||i.from>s.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:j,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((n,r)=>n.time-r.time).map(n=>({...n})):void 0,i={...this._config};s?i.markers=s:delete i.markers,this._config=i}get captions(){return this._captions}setCaptions(t){const s={};for(const[i,n]of Object.entries(t??{}))s[i]={...n};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 bs=100;function ks(e,t,s,i){const n=[],r=[],{duration:a,alternate:o}=i,c=(f,g,p,m)=>{r.push([f,g]);const b=[];e.forEach((k,M)=>{(p==="forward"?(m?k>=f:k>f)&&k<=g:(m?k<=f:k<f)&&k>=g)&&b.push(M)}),b.sort((k,M)=>(p==="forward"?e[k]-e[M]:e[M]-e[k])||k-M);for(const k of b)n.push({kind:"event",index:k,direction:p})};let l=t.time,u=t.direction,h=t.fresh===!0;const d=Math.min(bs,Math.max(0,s.iteration-t.iteration));for(let f=0;f<d;f++){const g=u==="forward"?a:0;c(l,g,u,h),n.push({kind:"repeat"}),o?(u=u==="forward"?"reverse":"forward",l=g,h=!1):(l=u==="forward"?0:a,h=!0)}return d>0&&i.holding&&!o?{crossings:n,passes:r}:(c(l,s.time,u,h),{crossings:n,passes:r})}function Ms(e){return{...e,...Array.isArray(e.end)&&{end:[...e.end]}}}function Z(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 Ss(e){if(lt(e)){const t=e;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:Ms(t.inertia),...Z(t)}}if(ht(e)){const t=e;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...Z(t)}}if(_t(e)){const t=e;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((s,i)=>s.time-i.time),...Z(t)}}if(e.property==="motionPath"&&"motionPathConfig"in e){const t=e,s=[...t.keyframes].sort((i,n)=>i.time-n.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:s,...Z(t)}}return ls({id:e.id,target:e.target,property:e.property,keyframes:e.keyframes,...Z(e)})}function rt(e){const t=e.formatVersion??1;if(t>j)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${j}. Update tinyfly to play it.`);return new ys({id:e.id,name:e.name,config:e.config,tracks:e.tracks.map(Ss),captions:e.captions})}const ws=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),xs="#ffffff",vs="rgba(0, 0, 0, 0.5)";function Ts(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??xs})`),e.shadowX!==void 0||e.shadowY!==void 0||e.shadowBlur!==void 0){const s=e.shadowX??0,i=e.shadowY??0,n=Math.max(0,e.shadowBlur??0);t.push(`drop-shadow(${s}px ${i}px ${n}px ${e.shadowColor??vs})`)}return t.length>0?t.join(" "):null}function _s(e,t){const s=e.childNodes.length===1?e.firstChild:null;if(s&&s.nodeType===3){const i=s;i.data!==t&&(i.data=t);return}e.textContent!==t&&(e.textContent=t)}function As(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"]),Ps=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","motionPathX","motionPathY","motionPathRotate"]),Cs=new Set(["originX","originY"]),Is=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Es={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"},Rs="http://www.w3.org/2000/svg";class wt{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,i]of t.values){const n=this.targets.get(s);n&&this.applyProperties(n,i)}}applyProperties(t,s){const i=[];let n=null,r=null,a=null;const o=s.has("motionPathX"),c=s.has("motionPathY"),l=s.has("motionPathRotate");for(const[d,f]of s)if(!(d==="x"&&o)&&!(d==="y"&&c)&&!((d==="rotate"||d==="rotateZ")&&l)){if(Ps.has(d)){const g=this.buildTransformPart(d,f);g&&i.push(g)}else if(Cs.has(d))typeof f=="number"&&((n??={})[d]=f);else if(Is.has(d))typeof f=="number"&&((r??={})[d]=f);else if(ws.has(d))(a??={})[d]=f;else if(d!=="perspective"){if(d!=="shine")if(d==="text"&&typeof f=="string")_s(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=s.get("shine");typeof u=="number"&&this.applyShine(t,u);const h=s.get("perspective");if(typeof h=="number"&&i.unshift(`perspective(${h}px)`),i.length>0&&(t.style.transform=i.join(" "),As(t)),n){const d=n.originX??50,f=n.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=Ts(a);d&&(t.style.filter=d)}}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 i=t.dataset.shineBase,n=-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(${i}, ${i})`,r.backgroundSize="250% 100%, 100% 100%",r.backgroundPosition=`${n}% 0, 0 0`,r.backgroundRepeat="no-repeat",r.webkitBackgroundClip="text",r.backgroundClip="text"}applyStyleProperty(t,s,i){let n;if(t.namespaceURI===Rs&&s in te){const o=Array.isArray(i)?i.join(", "):String(i);t.style[te[s]]=o;return}else s==="fill"&&t.dataset?.elementType==="text"?n="color":n=Es[s]??s;let a;typeof i=="number"?Jt.has(s)||Jt.has(n)?a=`${i}px`:a=String(i):Array.isArray(i)?a=i.join(", "):a=i,t.style[n]=a}}class ee{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 i=this.targetTime(t);s?(this.media.paused&&this.safePlay(),Math.abs(this.media.currentTime-i)>this.driftTolerance&&(this.media.currentTime=i)):(this.media.paused||this.media.pause(),this.media.currentTime!==i&&(this.media.currentTime=i))}seek(t){this.media.currentTime=this.targetTime(t)}setRate(t){this.media.playbackRate=t}dispose(){this.media.paused||this.media.pause()}safePlay(){const t=this.media.play();t&&typeof t.catch=="function"&&t.catch(()=>{})}}function $s(e,t,s,i,n){const r=s-n;if(r<0){t.paused||t.pause(),t.currentTime=0;return}e.update(r,i)}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,s={}){if(typeof t=="string"){const i=document.querySelector(t);if(!i)throw new Error(`Container not found: ${t}`);this.container=i}else this.container=t;this.options=s,this.adapter=new wt}async load(t){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(t)}async loadSource(t){let s;if(typeof t=="string"){const i=await fetch(t);if(!i.ok)throw new Error(`Failed to load animation: ${i.statusText}`);s=await i.json()}else s=t;this.useDefinition(s),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(t){const s={...t.config};this.options.speed!==void 0&&(s.speed=this.options.speed),this.options.loop!==void 0&&(s.loop=this.options.loop),this.options.alternate!==void 0&&(s.alternate=this.options.alternate),this.timeline=rt({...t,config: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()}async loadScenarios(t,s={}){if(t.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const i=new Set;for(const r of t){if(i.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);i.add(r.id)}const n=s.initial===void 0?t[0]:t.find(r=>r.id===s.initial);if(!n)throw new Error(`tinyfly: there is no scenario "${s.initial}"`);this.scenarioList=[...t],this.scenarioId=n.id,await this.loadSource(n.timeline)}get scenarios(){return this.scenarioList.map(t=>({id:t.id,label:t.label??t.id}))}get scenario(){return this.scenarioId}setScenario(t){const s=this.scenarioList.find(o=>o.id===t);if(!s||!this.timeline)return!1;if(t===this.scenarioId)return!0;const i=this.isPlaying,n=this.currentTime>=this.duration-.5,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=t,this.useDefinition(s.timeline),this.lastMarkerId=null;let a=0;return this.reducedMotion||n?a=this.duration:r!==void 0&&(a=this.markers.find(o=>o.id===r)?.time??0),this.seek(a),i&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(t){if(this.authored.has(t))return;const s={style:t.getAttribute("style")};t.children.length===0&&(s.text=t.textContent??"");const i=t.tagName.toLowerCase()==="path"?t:t.querySelector("path");i&&(s.path={element:i,d:i.getAttribute("d")}),this.authored.set(t,s)}restoreAuthored(){for(const[t,s]of this.authored){s.style===null?t.removeAttribute("style"):t.setAttribute("style",s.style),s.text!==void 0&&t.textContent!==s.text&&(t.textContent=s.text),s.path&&(s.path.d===null?s.path.element.removeAttribute("d"):s.path.element.setAttribute("d",s.path.d));const i=t.dataset;i&&delete i.shineBase}}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notify(){for(const t of this.listeners)t()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const t=this.currentTime;let s;for(const i of this.markers)if(i.time<=t+.5)s=i;else break;return s}caption(t,s){const i=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!i)return;const n=s??this.language(),r=a=>a?.[n]?.[i.id]??a?.[n.split("-")[0]]?.[i.id];return r(this.options.captions)??r(this.timeline?.captions)??i.label}next(){if(!this.timeline)return;const t=this.currentTime,s=this.markers.find(i=>i.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(i=>i.time<t-.5);this.pause(),this.seek(s?s.time:0)}goToMarker(t){const s=this.markers.find(i=>i.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.visibilityObserver=new IntersectionObserver(s=>{for(const i of s)this.onScreen=i.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const t=this.container.getBoundingClientRect?.();t&&(t.width>0||t.height>0)&&(this.onScreen=t.bottom>0&&t.top<window.innerHeight&&t.right>0&&t.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const t=this.onScreen&&document.visibilityState!=="hidden";!t&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):t&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const t=this.currentMarker,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 i=s,n=Number(i.getAttribute("data-tinyfly-start")??"0")||0,r=i.getAttribute("data-volume");r!==null&&(i.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:i,startTime:n,sync:new ee(i)})})}syncAllMedia(t,s){for(const i of this.mediaTargets)$s(i.sync,i.el,t,s,i.startTime)}loadFromString(t){const s=JSON.parse(t);this.load(s)}registerTarget(t,s){if(typeof s=="string"){const i=this.container.querySelector(s);i&&(this.rememberAuthored(i),this.targets[t]=i,this.adapter.registerTarget(t,i))}else this.rememberAuthored(s),this.targets[t]=s,this.adapter.registerTarget(t,s)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(s=>{const i=s.closest("[data-tinyfly-symbol]");if(i&&i!==s)return;const n=s.getAttribute("data-tinyfly");n&&this.registerTarget(n,s)}),this.timeline&&new Set(this.timeline.tracks.map(i=>i.target)).forEach(i=>{if(!this.targets[i]){const n=this.container.querySelector(`[data-tinyfly="${i}"]`)||this.container.querySelector(`.${i}`)||this.container.querySelector(`#${i}`);n&&this.registerTarget(i,n)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const s=new Map(t.map(i=>[i.id,i]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(i=>{const n=i.getAttribute("data-tinyfly-symbol");if(!n)return;const r=s.get(n);if(!r||!r.timeline.tracks?.length)return;const a=new wt;i.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,s){this.mediaSync=new ee(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.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=s=>{if(this.isDestroyed||!this.timeline)return;const i=s-(this.lastTime??s);this.lastTime=s;const n=this.playhead;this.timeline.tick(i),this.stopAtMarker(n),this.applyState();const r=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,r),this.syncAllMedia(this.timeline.currentTime,r),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(t):(this.animationFrameId=void 0,this.notify())};this.animationFrameId=requestAnimationFrame(t)}stopAtMarker(t){const s=this.timeline,i={time:s.currentTime,iteration:s.loopIteration,direction:s.direction};this.playhead=i;const n=this.markers;if(n.length===0)return;const{crossings:r}=ks(n.map(a=>a.time),t,i,{duration:s.duration,alternate:s.config.alternate===!0,holding:s.repeatDelayRemaining>0});for(const a of r){if(a.kind!=="event")continue;const o=n[a.index];if(this.stepping||o.pause){this.stepping=!1,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 i=s.timeline.duration;s.adapter.applyState(s.timeline.getStateAtTime(i>0?t%i:t))}}}async function Ds(e,t,s={}){const i=new at(e,{...s,autoplay:!0});return await i.load(t),i}function Ls(e,t={}){return new at(e,t)}const se={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"},ie="tinyfly-controls-style",Os=`
|
|
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,19 @@
|
|
|
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
|
-
|
|
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
|
+
`;let Ns=0;function Fs(e){if(e.getElementById(ie))return;const t=e.createElement("style");t.id=ie,t.textContent=Os,e.head.appendChild(t)}function ne(e,t,s={}){const i=t.ownerDocument;Fs(i);const n={...se,...s.labels},r=s.speeds??[.5,1,2],a=()=>e.markers.length>0,o=()=>e.markers.some(S=>S.label!==void 0||e.caption(S.id)!==void 0),c=i.createElement("div");c.className="tf-ctl";const l=i.createElement("div");l.className="tf-ctl-bar",l.setAttribute("role","group");const u=(S,I,O,N="")=>{const D=i.createElement("button");return D.type="button",D.className=`tf-ctl-btn ${N}`.trim(),D.setAttribute("aria-label",S),D.title=S,D.textContent=I,D.addEventListener("click",O),D},h=u(n.restart,"⟲",()=>{e.pause(),e.seek(0)}),d=u(n.prev,"◀",()=>e.prev()),f=u(n.play,"▶",()=>e.isPlaying?e.pause():p(),"tf-ctl-primary"),g=u(n.next,"▶|",()=>e.next()),p=()=>{e.currentTime>=e.duration-.5&&e.seek(0),e.play()},m=i.createElement("input");m.type="range",m.className="tf-ctl-scrub",m.min="0",m.max="1000",m.step="1",m.setAttribute("aria-label",n.scrub),m.addEventListener("input",()=>{e.pause(),e.seek(Number(m.value)/1e3*e.duration)});const b=i.createElement("span");b.className="tf-ctl-step";const k=i.createElement("select");k.className="tf-ctl-speed",k.setAttribute("aria-label",n.speed);for(const S of r){const I=i.createElement("option");I.value=String(S),I.textContent=`${S}×`,S===1&&(I.selected=!0),k.appendChild(I)}k.addEventListener("change",()=>e.setSpeed(Number(k.value))),l.append(h,d,f,g,m,b),r.length>0&&l.append(k),c.append(l);const M=i.createElement("p");M.className="tf-ctl-caption",M.setAttribute("aria-live","polite"),s.captions!==!1&&c.append(M);const x=i.createElement("div");x.className="tf-ctl-question",x.hidden=!0;const y=i.createElement("span"),v=u(n.reveal,n.reveal,()=>e.play(),"tf-ctl-primary");x.append(y,v),c.append(x);const w=Xs(e,i,n.scenario,s.scenarioControl??"buttons");w&&c.append(w.element);const E=s.mount;E?E.appendChild(c):t.insertAdjacentElement("afterend",c);const V=()=>{const S=e.isPlaying;f.textContent=S?"❚❚":"▶",f.setAttribute("aria-label",S?n.pause:n.play),f.title=S?n.pause:n.play;const I=e.duration;i.activeElement!==m&&(m.value=String(I>0?Math.round(e.currentTime/I*1e3):0));const O=e.markers;if(d.hidden=g.hidden=b.hidden=O.length===0,O.length>0){const N=e.currentMarker,D=N?O.indexOf(N)+1:0;b.textContent=n.stepFormat.replace("{index}",String(D)).replace("{total}",String(O.length)),b.setAttribute("aria-label",`${n.step} ${D} ${n.of} ${O.length}`),d.disabled=e.currentTime<=.5,g.disabled=e.currentTime>=I-.5;const J=e.caption()??"";M.textContent!==J&&(M.textContent=J),M.hidden=!o();const T=!S&&N?.question!==void 0&&Math.abs(e.currentTime-N.time)<1;x.hidden=!T,T&&y.textContent!==N.question&&(y.textContent=N.question)}else x.hidden=!0,M.hidden=!0;w?.update()},_=e.subscribe(V);V();const A=s.keyboardScope??t;!A.hasAttribute("tabindex")&&A.tabIndex<0&&(A.tabIndex=0);const C=new WeakSet,P=S=>{if(C.has(S)||(C.add(S),S.defaultPrevented||S.altKey||S.ctrlKey||S.metaKey))return;const I=S.target;if(!(I.tagName==="INPUT"||I.tagName==="SELECT")&&!(S.key===" "&&I.tagName==="BUTTON"))switch(S.key){case" ":S.preventDefault(),e.isPlaying?e.pause():p();break;case"ArrowRight":if(!a())return;S.preventDefault(),e.next();break;case"ArrowLeft":if(!a())return;S.preventDefault(),e.prev();break;case"Home":S.preventDefault(),e.pause(),e.seek(0);break}};return A.addEventListener("keydown",P),c.addEventListener("keydown",P),{element:c,destroy(){_(),A.removeEventListener("keydown",P),c.removeEventListener("keydown",P),c.remove()}}}function Xs(e,t,s,i){const n=e.scenarios;if(n.length<2)return;if(i==="slider"){const u=t.createElement("div");u.className="tf-ctl-choice-slider";const h=t.createElement("span");h.textContent=s,h.setAttribute("aria-hidden","true");const d=t.createElement("input");d.type="range",d.min="0",d.max=String(n.length-1),d.step="1",d.setAttribute("aria-label",s);const f=t.createElement("output");return f.setAttribute("aria-hidden","true"),d.addEventListener("input",()=>{const p=n[Number(d.value)];p&&e.setScenario(p.id)}),u.append(h,d,f),{element:u,update:()=>{const p=Math.max(0,n.findIndex(b=>b.id===e.scenario));t.activeElement!==d&&(d.value=String(p));const m=n[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=s,r.append(a);const o=`tf-ctl-scenario-${++Ns}`,c=n.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 re="tinyfly-choices-style",Ys=`
|
|
34
|
+
[data-tinyfly-choose] { cursor: pointer; }
|
|
35
|
+
[data-tinyfly-choose]:focus-visible { outline: 2px solid var(--tf-ctl-accent, #c2410c); outline-offset: 2px; }
|
|
36
|
+
`;function qs(e){if(e.getElementById(re))return;const t=e.createElement("style");t.id=re,t.textContent=Ys,e.head.appendChild(t)}function ae(e,t){const s=Array.from(t.querySelectorAll("[data-tinyfly-choose]"));if(s.length===0)return()=>{};qs(t.ownerDocument);const i=[],n=[];for(const o of s){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"),i.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),n.push(()=>{o.removeEventListener("click",d),o.removeEventListener("keydown",f)})}const r=()=>{for(const{element:o}of i)o.setAttribute("aria-pressed",String(o.getAttribute("data-tinyfly-choose")===e.scenario))},a=e.subscribe(r);return r(),()=>{a();for(const o of n)o();for(const{element:o,attributes:c}of i)for(const l of c)o.removeAttribute(l)}}const ot=new WeakMap,xt=new WeakMap;let Vs=0;function K(e,t,s){if(e)try{return JSON.parse(e)}catch(i){console.warn(`tinyfly: invalid ${t} JSON on`,s,i);return}}async function oe(e,t={}){const s=ot.get(e);if(s)return s;const i=Array.from(e.querySelectorAll("script[data-tinyfly-timeline]")),n=i[0],r=e.getAttribute("data-src"),a=Bs(e.getAttribute("data-markers")),o=i.length>1||n?.hasAttribute("data-scenario")?Ws(i,a,e):void 0;if(o&&o.length===0)return;let c=n&&!o?K(n.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=K(e.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",e),u={playWhenVisible:!0,...t.player,...l&&{captions:l},...K(e.getAttribute("data-options"),"data-options",e)};js(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}),xt.set(e,ae(h,e))}else await h.load(c??r);if(e.getAttribute("data-controls")!=="false"){const f=K(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=ne(h,e,{...t.controls,...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 Ws(e,t,s){const i=[];return e.forEach((n,r)=>{const a=K(n.textContent,"timeline",s);if(!a)return;const o=n.getAttribute("data-scenario")||`scenario-${r+1}`;if(i.some(l=>l.id===o)){console.warn(`tinyfly: scenario id "${o}" is used more than once; the later one is skipped`,s);return}const c=n.getAttribute("data-scenario-label")??void 0;i.push({id:o,label:c,timeline:t?ce(a,t):a})}),i}function ce(e,t){return e.config.markers?.length?e:{...e,config:{...e.config,markers:t.map((s,i)=>({id:`step-${i+1}`,time:s}))}}}function Bs(e){if(!e)return;const t=e.split(/[\s,]+/).filter(Boolean).map(Number).filter(s=>Number.isFinite(s)&&s>=0).sort((s,i)=>s-i);return t.length>0?t:void 0}async function le(e=document,t={}){const s=Array.from(e.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(s.map(n=>oe(n,t)))).filter(n=>n!==void 0)}function Us(e){const t=ot.get(e);t&&(xt.get(e)?.(),xt.delete(e),t.controls?.destroy(),t.player.destroy(),ot.delete(e),e.removeAttribute("data-tinyfly-mounted"))}function js(e){const t=e.querySelector("svg");if(!t||t.hasAttribute("role")||t.hasAttribute("aria-hidden"))return;const s=e.getAttribute("data-alt"),i=e.querySelector("figcaption");t.setAttribute("role","img"),s?t.setAttribute("aria-label",s):i&&(i.id||=`tinyfly-caption-${++Vs}`,t.setAttribute("aria-labelledby",i.id))}function Hs(){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 vt(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 he(e,t={}){const s=[],i=l=>s.push({level:"error",message:l}),n=l=>s.push({level:"warning",message:l});if((e.formatVersion??1)>j)return i(`format version ${e.formatVersion} is newer than this tinyfly reads (${j})`),s;let r=0;try{r=rt(e).duration}catch(l){return i(`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&&i(`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)&&i(`marker id "${l.id}" is used more than once`),c.add(l.id),(l.time<0||l.time>r)&&i(`marker "${l.id}" at ${l.time}ms is outside the animation (0–${r}ms)`),u>0&&l.time<o[u-1].time&&i(`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)||i(`caption "${h}" (${l}) has no marker with that id`);for(const h of c)h in u||n(`marker "${h}" has no ${l} caption; its label is shown instead`)}if(t.markup!==void 0){const l=new Set(vt(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)||i(`track "${h.id}" targets "${d}", but no element has data-tinyfly="${d}"`);for(const h of l)u.has(h)||n(`data-tinyfly="${h}" is never animated`)}return s}function Gs(e){const t=new Set;for(const s of e.matchAll(/data-tinyfly-choose\s*=\s*("([^"]*)"|'([^']*)')/g))t.add(s[2]??s[3]);return[...t]}function zs(e,t={}){const s=[];e.length===1&&s.push({level:"warning",message:"only one scenario, so the reader has nothing to choose"});const i=new Set,n=new Set;for(const r of e){if(i.has(r.id)){s.push({level:"error",message:`scenario id "${r.id}" is used more than once`});continue}i.add(r.id);for(const a of he(r.timeline,t))/is never animated$/.test(a.message)||s.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??[]])n.add(o)}if(t.markup!==void 0){for(const r of Gs(t.markup))i.has(r)||s.push({level:"error",message:`data-tinyfly-choose="${r}" names no scenario`});for(const r of vt(t.markup))n.has(r)||s.push({level:"warning",message:`data-tinyfly="${r}" is never animated in any scenario`})}return s}function Qs(e,t,s="end"){const i=rt(t),n=t.config?.markers??[],r=s==="start"?0:s==="end"?i.duration:typeof s=="number"?s:n.find(d=>d.id===s)?.time??i.duration,a=i.getStateAtTime(Math.max(0,Math.min(i.duration,r))),o=new wt,c=new Map,l=Ks(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=Zs(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,k=/data-tinyfly\s*=\s*("([^"]*)"|'([^']*)')/.exec(p),M=k?c.get(k[2]??k[3]):void 0;if(!M||Object.keys(M.style).length===0&&M.text===void 0)continue;u+=e.slice(h,b);const x=Object.entries(M.style).map(([w,E])=>`${Js(w)}: ${E}`).join("; "),y=/\sstyle\s*=\s*("([^"]*)"|'([^']*)')/.exec(p);let v=p;if(x)if(y){const w=`${(y[2]??y[3]).trim().replace(/;?$/,";")} ${x}`.trim();v=p.replace(y[0],` style="${de(w)}"`)}else v=`${p} style="${de(x)}"`;if(u+=`<${g}${v}${m?" /":""}>`,h=b+f.length,M.text!==void 0&&!m){const w=e.indexOf(`</${g}`,h),E=w===-1?"":e.slice(h,w);w!==-1&&!E.includes("<")&&(u+=ti(M.text),h=w)}}return u+e.slice(h)}const ue=/<([a-zA-Z][\w:-]*)((?:\s+[^\s=>/]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+))?)*)\s*(\/?)>/g;function Zs(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 Ks(e){const t=[],s=/<svg[\s>]/gi;let i;for(;i=s.exec(e);){const n=e.toLowerCase().indexOf("</svg>",i.index);t.push([i.index+1,n===-1?e.length:n])}return n=>t.some(([r,a])=>n>r&&n<a)}function Js(e){const t=e.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`);return/^(webkit|moz|ms)-/.test(t)?`-${t}`:t}function de(e){return e.replace(/&/g,"&").replace(/"/g,""")}function ti(e){return e.replace(/&/g,"&").replace(/</g,"<")}Hs(),R.DEFAULT_LABELS=se,R.TinyflyPlayer=at,R.bindChoiceHotspots=ae,R.create=Ls,R.createControls=ne,R.mount=oe,R.mountAll=le,R.play=Ds,R.renderFrame=Qs,R.targetNamesIn=vt,R.unmount=Us,R.validateEmbed=he,R.validateScenarios=zs,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})})(this.tinyfly=this.tinyfly||{});
|