@algorisys/tinyfly 0.114.0 → 0.116.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -8
- package/docs/api-reference.md +2 -1
- package/docs/character-appearance.md +27 -2
- package/docs/editor-guide.md +1 -1
- package/docs/examples.md +1 -1
- package/docs/getting-started.md +1 -1
- package/docs/gsap-compat.md +1 -1
- package/docs/llm-guide.md +18 -0
- package/docs/maps.md +2 -2
- package/docs/math.md +280 -0
- package/docs/teaching.md +1 -1
- package/lib/addons/characters.js +2646 -2584
- package/lib/addons/{cricket-play-BZNhfgOK.js → cricket-play-C5CkNOc6.js} +2187 -2005
- package/lib/addons/math.js +2864 -0
- package/lib/addons/sports.js +1 -1
- package/lib/browser/tinyfly-math.iife.js +53 -0
- package/lib/browser/tinyfly.iife.js +12 -12
- package/lib/browser/tinyfly.js +4948 -4699
- package/lib/browser/tinyfly.umd.js +12 -12
- package/lib/embed/tinyfly-embed.iife.js +1 -1
- package/lib/embed/tinyfly-embed.js +8 -0
- package/lib/player/tinyfly-player.es.js +8 -0
- package/lib/player/tinyfly-player.iife.js +1 -1
- package/lib/player/tinyfly-player.umd.js +1 -1
- package/lib/types/characters/capabilities.d.ts +8 -0
- package/lib/types/characters/character.d.ts +4 -0
- package/lib/types/characters/index.d.ts +2 -0
- package/lib/types/characters/look/illustrated-pen.d.ts +36 -0
- package/lib/types/characters/look/illustration-color.d.ts +13 -0
- package/lib/types/characters/look/pen.d.ts +18 -5
- package/lib/types/math/browser-entry.d.ts +3 -0
- package/lib/types/math/embed/auto-mount-math.d.ts +7 -0
- package/lib/types/math/embed/explorable.d.ts +46 -0
- package/lib/types/math/embed/mount-math.d.ts +31 -0
- package/lib/types/math/expr/differentiate.d.ts +7 -0
- package/lib/types/math/expr/evaluate.d.ts +21 -0
- package/lib/types/math/expr/parse-expression.d.ts +50 -0
- package/lib/types/math/figure/derived.d.ts +17 -0
- package/lib/types/math/figure/display-list.d.ts +87 -0
- package/lib/types/math/figure/figure-spec.d.ts +239 -0
- package/lib/types/math/figure/item-context.d.ts +33 -0
- package/lib/types/math/figure/items/calculus.d.ts +7 -0
- package/lib/types/math/figure/items/curves.d.ts +7 -0
- package/lib/types/math/figure/items/grid.d.ts +5 -0
- package/lib/types/math/figure/items/regions.d.ts +5 -0
- package/lib/types/math/figure/items/text.d.ts +5 -0
- package/lib/types/math/figure/items/vectors.d.ts +9 -0
- package/lib/types/math/figure/layout-figure.d.ts +13 -0
- package/lib/types/math/figure/plane.d.ts +20 -0
- package/lib/types/math/figure/validate-spec.d.ts +2 -0
- package/lib/types/math/index.d.ts +43 -0
- package/lib/types/math/linear/mat2.d.ts +41 -0
- package/lib/types/math/linear/vec2.d.ts +18 -0
- package/lib/types/math/presets/calculus.d.ts +59 -0
- package/lib/types/math/presets/linear-algebra.d.ts +42 -0
- package/lib/types/math/render/arrow.d.ts +10 -0
- package/lib/types/math/render/display-list-to-svg.d.ts +10 -0
- package/lib/types/math/render/draw-display-list.d.ts +6 -0
- package/lib/types/math/steps/math-steps.d.ts +34 -0
- package/lib/types/math/targets/math-target.d.ts +43 -0
- package/lib/types/math/tex/equation-morph.d.ts +21 -0
- package/lib/types/math/tex/glyph-metrics.d.ts +24 -0
- package/lib/types/math/tex/tex-layout.d.ts +59 -0
- package/lib/types/math/tex/tex-parser.d.ts +88 -0
- package/lib/types/player/player.d.ts +6 -0
- package/llms-full.txt +388 -12
- package/llms.txt +32 -31
- package/package.json +6 -2
- package/skills/tinyfly/SKILL.md +13 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
(function(v,N){typeof exports=="object"&&typeof module<"u"?N(exports):typeof define=="function"&&define.amd?define(["exports"],N):(v=typeof globalThis<"u"?globalThis:v||self,N(v.tinyfly=v.tinyfly||{}))})(this,(function(v){"use strict";function N(i){return typeof i=="object"&&i!==null&&i.type==="cubic-bezier"}function ie(i){return typeof i=="object"&&i!==null&&i.type!=="cubic-bezier"}const St=2;function se(i){return i.some(t=>t.interpolation!==void 0)?2:1}function Mt(i){return i.property==="text"&&"textConfig"in i}function nt(i){return i.kind==="inertia"&&"inertia"in i}function rt(i){return i.kind==="spring"&&"spring"in i}function ne(i){return i.property==="motionPath"&&"motionPathConfig"in i}function re(i,t){if(!(t>0))return i;const e=1e3/t;return Math.floor(i/e+1e-9)*e}function _t(i,t,e="start"){if(t<=1)return 0;if(typeof e=="number"){const s=Math.max(0,Math.min(t-1,e));return Math.abs(i-s)}switch(e){case"end":return t-1-i;case"center":return Math.abs(i-(t-1)/2);case"edges":return(t-1)/2-Math.abs(i-(t-1)/2);default:return i}}function ae(i,t="start"){if(i<=1)return 0;let e=0;for(let s=0;s<i;s++)e=Math.max(e,_t(s,i,t));return e}function kt(i,t,e){if(e.offsets)return e.offsets[i]??0;const s=e.from??"start",n=_t(i,t,s);if(e.amount!==void 0){const r=ae(t,s);return r===0?0:e.amount*n/r}return e.each!==void 0?e.each*n:0}function oe(i,t){return Array.from({length:i},(e,s)=>kt(s,i,t))}function at(i,t){return i<=1?0:Math.max(...oe(i,t))}const q=1,wt=6e4,G=wt/q,X={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1};class ce{from;to;stiffness;damping;mass;restDelta;restSpeed;distance;samples;velocity;settledStep=null;constructor(t){this.from=t.from,this.to=t.to,this.stiffness=t.stiffness??X.stiffness,this.damping=t.damping??X.damping,this.mass=t.mass??X.mass,this.restDelta=t.restDelta??X.restDelta,this.restSpeed=t.restSpeed??X.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=t.velocity??X.velocity,this.isAtRest(this.from)&&(this.settledStep=0)}isAtRest(t){return Math.abs(t-this.to)<this.restDelta*this.distance&&Math.abs(this.velocity)<this.restSpeed*this.distance}valueAt(t){if(t<=0)return this.from;const e=Math.floor(t/q);if(this.simulateTo(e+1),this.settledStep!==null&&e>=this.settledStep)return this.to;const s=this.samples[Math.min(e,this.samples.length-1)],n=this.samples[Math.min(e+1,this.samples.length-1)],r=t/q-e;return s+(n-s)*r}settleTime(){return this.simulateTo(G+1),this.settledStep!==null?this.settledStep*q:wt}simulateTo(t){if(this.settledStep!==null)return;const e=Math.min(t,G+1),s=q/1e3;for(;this.samples.length<e;){const n=this.samples[this.samples.length-1],r=n-this.to,a=-this.stiffness*r,o=-this.damping*this.velocity,c=(a+o)/this.mass;this.velocity+=c*s;const h=n+this.velocity*s;if(this.samples.push(h),this.isAtRest(h)){this.settledStep=this.samples.length-1;return}}this.samples.length>G&&(this.settledStep=G)}}const Pt=4,he=.002,le=1e-4,ue=6e4;function ot(i){const t=i.friction??Pt;return t>0?t:Pt}function de(i){return i.from+i.velocity/ot(i)}function fe(i,t){if(t===void 0)return i;if(typeof t=="number")return t>0?Math.round(i/t)*t:i;if(t.length===0)return i;let e=t[0];for(const s of t)Math.abs(s-i)<Math.abs(e-i)&&(e=s);return e}function vt(i){let t=fe(de(i),i.end);return i.min!==void 0&&(t=Math.max(i.min,t)),i.max!==void 0&&(t=Math.min(i.max,t)),t}function xt(i){const t=Math.abs(vt(i)-i.from);if(t===0)return 0;const e=i.restDelta??Math.max(le,t*he);if(e>=t)return 0;const s=Math.log(t/e)/ot(i);return Math.min(ue,s*1e3)}function It(i,t){if(t<=0)return i.from;const e=vt(i);if(t>=xt(i))return e;const s=ot(i);return i.from+(e-i.from)*(1-Math.exp(-s*t/1e3))}const ct=i=>i,pe=i=>i*i,me=i=>1-(1-i)*(1-i),ge=i=>i<.5?2*i*i:1-Math.pow(-2*i+2,2)/2,Ct=i=>i*i*i,Rt=i=>1-Math.pow(1-i,3),Dt=i=>i<.5?4*i*i*i:1-Math.pow(-2*i+2,3)/2,ye={linear:ct,"ease-in":Ct,"ease-out":Rt,"ease-in-out":Dt,"ease-in-quad":pe,"ease-out-quad":me,"ease-in-out-quad":ge,"ease-in-cubic":Ct,"ease-out-cubic":Rt,"ease-in-out-cubic":Dt};function Te(i){const[t,e,s,n]=i,r=3*t,a=3*(s-t)-r,o=1-r-a,c=3*e,h=3*(n-e)-c,u=1-c-h,l=d=>((o*d+a)*d+r)*d,g=d=>((u*d+h)*d+c)*d,p=d=>(3*o*d+2*a)*d+r,f=d=>{let m=d;for(let A=0;A<8;A++){const M=l(m)-d;if(Math.abs(M)<1e-7)return m;const y=p(m);if(Math.abs(y)<1e-7)break;m-=M/y}let T=0,b=1;for(m=d;T<b;){const A=l(m);if(Math.abs(A-d)<1e-7)return m;d>A?T=m:b=m,m=(T+b)/2}return m};return d=>{if(d<=0)return 0;if(d>=1)return 1;const m=f(d);return g(m)}}function ht(i,t="out"){if(t==="out")return i;const e=s=>1-i(1-s);return t==="in"?e:s=>s<.5?e(s*2)/2:i(s*2-1)/2+.5}function be(i=1,t=.3){const e=Math.max(1,i),s=t/(2*Math.PI)*Math.asin(1/e);return n=>n<=0?0:n>=1?1:e*Math.pow(2,-10*n)*Math.sin((n-s)*(2*Math.PI)/t)+1}const Ae=i=>{if(i<=0)return 0;if(i>=1)return 1;if(i<1/2.75)return 7.5625*i*i;if(i<2/2.75){const n=i-.5454545454545454;return 7.5625*n*n+.75}if(i<2.5/2.75){const n=i-.8181818181818182;return 7.5625*n*n+.9375}const s=i-2.625/2.75;return 7.5625*s*s+.984375};function Se(i=1.70158){return t=>{if(t<=0)return 0;if(t>=1)return 1;const e=t-1;return e*e*((i+1)*e+i)+1}}function Me(i,t="end"){const e=Math.max(1,Math.floor(i));return s=>{if(s>=1)return 1;if(s<=0)return t==="start"||t==="both"?t==="start"?1/e:1/(e+1):0;const n=Math.floor(s*e);switch(t){case"start":return Math.min(1,(n+1)/e);case"both":return(n+1)/(e+1);case"none":return e===1?0:Math.min(1,n/(e-1));default:return n/e}}}function _e(i){switch(i.type){case"steps":return Me(i.count,i.position);case"elastic":return ht(be(i.amplitude,i.period),i.mode);case"bounce":return ht(Ae,i.mode);case"back":return ht(Se(i.overshoot),i.mode)}}function ke(i){return i===void 0?ct:N(i)?Te(i.points):ie(i)?_e(i):ye[i]??ct}const Et=32,we=256,V=new Map,Pe=/[MmLlHhVvCcSsQqTtAaZz]/,ve=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,xe={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function Ie(i){const t=[];let e=0,s=null;const n=()=>{for(;e<i.length&&/[\s,]/.test(i[e]);)e++};for(;e<i.length&&(n(),!(e>=i.length));){const r=i[e];if(Pe.test(r)){s={type:r,args:[]},t.push(s),e++;continue}if(!s)break;const a=s.type==="A"||s.type==="a",o=s.args.length%7;if(a&&(o===3||o===4)){if(r!=="0"&&r!=="1")break;s.args.push(r==="1"?1:0),e++;continue}const c=ve.exec(i.slice(e));if(!c)break;s.args.push(parseFloat(c[0])),e+=c[0].length}return t}function Ce(i,t,e,s,n,r,a,o,c){if(i===o&&t===c)return[];let h=Math.abs(e),u=Math.abs(s);if(h===0||u===0)return[[i,t,o,c,o,c]];const l=n*Math.PI/180,g=Math.cos(l),p=Math.sin(l),f=(i-o)/2,d=(t-c)/2,m=g*f+p*d,T=-p*f+g*d,b=m*m/(h*h)+T*T/(u*u);if(b>1){const w=Math.sqrt(b);h*=w,u*=w}const A=r===a?-1:1,M=h*h*u*u-h*h*T*T-u*u*m*m,y=h*h*T*T+u*u*m*m,_=A*Math.sqrt(Math.max(0,M/y)),S=_*h*T/u,E=-_*u*m/h,et=g*S-p*E+(i+o)/2,k=p*S+g*E+(t+c)/2,C=(w,I,R,Y)=>{const At=w*R+I*Y,st=Math.sqrt((w*w+I*I)*(R*R+Y*Y)),z=Math.acos(Math.max(-1,Math.min(1,At/st)));return w*Y-I*R<0?-z:z},P=C(1,0,(m-S)/h,(T-E)/u);let x=C((m-S)/h,(T-E)/u,(-m-S)/h,(-T-E)/u);!a&&x>0&&(x-=2*Math.PI),a&&x<0&&(x+=2*Math.PI);const $=Math.max(1,Math.ceil(Math.abs(x)/(Math.PI/2))),bt=x/$,it=4/3*Math.tan(bt/4),Jt=w=>{const I=h*Math.cos(w),R=u*Math.sin(w);return[g*I-p*R+et,p*I+g*R+k]},te=w=>{const I=-h*Math.sin(w),R=u*Math.cos(w);return[g*I-p*R,p*I+g*R]},ee=[];for(let w=0;w<$;w++){const I=P+w*bt,R=I+bt,[Y,At]=Jt(I),[st,z]=w===$-1?[o,c]:Jt(R),[Xi,Fi]=te(I),[Yi,Ni]=te(R);ee.push([Y+it*Xi,At+it*Fi,st-it*Yi,z-it*Ni,st,z])}return ee}function B(i,t,e,s,n){const r=1-n;return r*r*r*i+3*r*r*n*t+3*r*n*n*e+n*n*n*s}function Bt(i,t,e,s,n){const r=1-n;return 3*r*r*(t-i)+6*r*n*(e-t)+3*n*n*(s-e)}function W(i,t,e,s){return{subpath:0,type:"L",points:[e,s],startX:i,startY:t,endX:e,endY:s,length:Math.hypot(e-i,s-t)}}function Z(i,t,e){const[s,n,r,a,o,c]=e,h=[0];let u=i,l=t,g=0;for(let p=1;p<=Et;p++){const f=p/Et,d=B(i,s,r,o,f),m=B(t,n,a,c,f);g+=Math.hypot(d-u,m-l),h.push(g),u=d,l=m}return{subpath:0,type:"C",points:[s,n,r,a,o,c],startX:i,startY:t,endX:o,endY:c,length:g,lengths:h}}function K(i){const t=V.get(i);if(t)return t;const e=[];let s=0,n=0,r=0,a=0,o=null,c=null,h=-1;const u=new Set,l=d=>{h<0&&(h=0),d.subpath=h,e.push(d)};for(const{type:d,args:m}of Ie(i)){const T=d.toUpperCase(),b=d!==T,A=xe[T];if(T==="Z"){(s!==r||n!==a)&&l(W(s,n,r,a)),h>=0&&u.add(h),s=r,n=a,o=c=null;continue}for(let M=0;M+A<=m.length;M+=A){const y=m.slice(M,M+A),_=b?s:0,S=b?n:0;let E=null,et=null;switch(T){case"M":M===0?(s=y[0]+_,n=y[1]+S,r=s,a=n,(h<0||e[e.length-1]?.subpath===h)&&h++):(l(W(s,n,y[0]+_,y[1]+S)),s=y[0]+_,n=y[1]+S);break;case"L":l(W(s,n,y[0]+_,y[1]+S)),s=y[0]+_,n=y[1]+S;break;case"H":l(W(s,n,y[0]+_,n)),s=y[0]+_;break;case"V":l(W(s,n,s,y[0]+S)),n=y[0]+S;break;case"C":{const k=[y[0]+_,y[1]+S,y[2]+_,y[3]+S,y[4]+_,y[5]+S];l(Z(s,n,k)),E=[k[2],k[3]],s=k[4],n=k[5];break}case"S":{const[k,C]=o?[2*s-o[0],2*n-o[1]]:[s,n],P=[k,C,y[0]+_,y[1]+S,y[2]+_,y[3]+S];l(Z(s,n,P)),E=[P[2],P[3]],s=P[4],n=P[5];break}case"Q":case"T":{let k=s,C=n;T==="Q"?(k=y[0]+_,C=y[1]+S):c&&(k=2*s-c[0],C=2*n-c[1]);const P=T==="Q"?y[2]+_:y[0]+_,x=T==="Q"?y[3]+S:y[1]+S;l(Z(s,n,[s+2/3*(k-s),n+2/3*(C-n),P+2/3*(k-P),x+2/3*(C-x),P,x])),et=[k,C],s=P,n=x;break}case"A":{const k=y[5]+_,C=y[6]+S;let P=s,x=n;for(const $ of Ce(s,n,y[0],y[1],y[2],y[3],y[4],k,C))l(Z(P,x,$)),P=$[4],x=$[5];s=k,n=C;break}}o=E,c=et}}const g=e.reduce((d,m)=>d+m.length,0),p=[];for(let d=0;d<e.length;){const m=e[d].subpath;let T=d,b=0;for(;T<e.length&&e[T].subpath===m;)b+=e[T++].length;const A=e[d],M=e[T-1],y=u.has(m)||Math.abs(M.endX-A.startX)<1e-9&&Math.abs(M.endY-A.startY)<1e-9;p.push({start:d,end:T,length:b,closed:y}),d=T}const f={segments:e,totalLength:g,subpaths:p};return V.size>=we&&V.delete(V.keys().next().value),V.set(i,f),f}function Re(i,t){const e=i.lengths;if(t<=0)return 0;if(t>=i.length)return 1;let s=0,n=e.length-1;for(;s<n-1;){const o=s+n>>1;e[o]<t?s=o:n=o}const r=e[n]-e[s],a=r>0?(t-e[s])/r:0;return(s+a)/(e.length-1)}function De(i,t){if(i.type==="L"){const l=i.length>0?Math.max(0,Math.min(1,t/i.length)):0;return{x:i.startX+(i.endX-i.startX)*l,y:i.startY+(i.endY-i.startY)*l,angle:Math.atan2(i.endY-i.startY,i.endX-i.startX)*180/Math.PI}}const[e,s,n,r,a,o]=i.points,c=Re(i,t);let h=Bt(i.startX,e,n,a,c),u=Bt(i.startY,s,r,o,c);if(Math.hypot(h,u)<1e-9){const l=c<.5?Math.min(1,c+.001):Math.max(0,c-.001),g=B(i.startX,e,n,a,l),p=B(i.startY,s,r,o,l),f=B(i.startX,e,n,a,c),d=B(i.startY,s,r,o,c);h=c<.5?g-f:f-g,u=c<.5?p-d:d-p}return{x:B(i.startX,e,n,a,c),y:B(i.startY,s,r,o,c),angle:Math.atan2(u,h)*180/Math.PI}}function Ot(i,t,e=0,s=i.length){if(s<=e)return{x:0,y:0,angle:0};let n=0;for(let r=e;r<s;r++){const a=i[r];if(n+a.length>=t||r===s-1)return De(a,t-n);n+=a.length}return{x:0,y:0,angle:0}}function Ee(i,t){const{segments:e,totalLength:s}=K(i);return Ot(e,Math.max(0,Math.min(1,t))*s)}const Be=24,Oe=320,Le=2.5,U=72,$e=.2,Xe=128,J=new Map;let lt=0,O;const Lt=i=>Math.round(i*100)/100;function $t(i,t){const{segments:e,subpaths:s,totalLength:n}=K(i);if(e.length===0)return[];if(t){const r=s.every(a=>a.closed);return[{segments:e,start:0,end:e.length,length:n,closed:r}]}return s.filter(r=>r.length>0).map(r=>({segments:e,start:r.start,end:r.end,length:r.length,closed:r.closed}))}function ut(i,t){const e=i.closed?(t%1+1)%1:Math.max(0,Math.min(1,t)),s=Ot(i.segments,e*i.length,i.start,i.end);return[s.x,s.y]}function Xt(i){const t=[];let e=0;for(let s=i.start;s<i.end;s++)e+=i.segments[s].length,i.length>0&&t.push(e/i.length);return t}function Ft(i,t){const e=[];for(let s=0;s<t;s++)e.push(ut(i,i.closed?s/t:s/(t-1)));return e}function Yt(i){let t=0,e=0;for(const[s,n]of i)t+=s,e+=n;return t/=i.length,e/=i.length,i.map(([s,n])=>[s-t,n-e])}function Fe(i,t,e){const s=i.closed&&t.closed;if(e!==void 0)return{offset:s?Math.abs(e)%U/U:0,reversed:e<0};const n=Yt(Ft(i,U)),r=Yt(Ft(t,U)),a=U;let o={offset:0,reversed:!1},c=1/0;for(const h of[!1,!0]){const u=s?a:1;for(let l=0;l<u;l++){let g=0;for(let p=0;p<a&&g<c;p++){const f=s?h?(l-p+a)%a:(p+l)%a:h?a-1-p:p,d=n[p][0]-r[f][0],m=n[p][1]-r[f][1];g+=d*d+m*m}g<c&&(c=g,o={offset:s?l/a:0,reversed:h})}}return o}function Ye(i,t,e){return e?((t.reversed?t.offset-i:i+t.offset)%1+1)%1:t.reversed?1-i:i}function Ne(i,t,e){return e?((t.reversed?t.offset-i:i-t.offset)%1+1)%1:t.reversed?1-i:i}function qe(i,t,e){const s=i.closed&&t.closed,n=Fe(i,t,e.shapeIndex),r=Math.max(Be,Math.min(Oe,Math.ceil(Math.max(i.length,t.length)/Le))),a=new Set,o=l=>a.add(Math.round(l*1e7)/1e7);for(let l=0;l<=r;l++)o(l/r);for(const l of Xt(i))o(l);for(const l of Xt(t))o(Ne(l,n,s));let c=[...a].sort((l,g)=>l-g);s&&(c=c.filter(l=>l<1));const h=[],u=[];for(const l of c)h.push(...ut(i,l)),u.push(...ut(t,Ye(l,n,s)));return Ve({from:h,to:u,closed:s})}function Ve(i){const t=i.from.length/2;if(t<=3)return i;const e=new Uint8Array(t);e[0]=1,e[t-1]=1;const s=[[0,t-1]];for(;s.length>0;){const[a,o]=s.pop();let c=-1,h=$e;for(let u=a+1;u<o;u++){const l=Math.max(Nt(i.from,a,o,u),Nt(i.to,a,o,u));l>h&&(h=l,c=u)}c!==-1&&(e[c]=1,s.push([a,c],[c,o]))}const n=[],r=[];for(let a=0;a<t;a++)e[a]&&(n.push(i.from[a*2],i.from[a*2+1]),r.push(i.to[a*2],i.to[a*2+1]));return{from:n,to:r,closed:i.closed}}function Nt(i,t,e,s){const n=i[t*2],r=i[t*2+1],a=i[e*2]-n,o=i[e*2+1]-r,c=i[s*2]-n,h=i[s*2+1]-r,u=a*a+o*o,l=u===0?0:Math.max(0,Math.min(1,(c*a+h*o)/u));return Math.hypot(c-l*a,h-l*o)}function We(i,t,e){const s=e.shapeIndex;if(O&&O.from===i&&O.to===t&&O.shapeIndex===s)return O.plan;const r=J.get(String(s??"auto"))?.get(i)?.get(t);if(r)return O={from:i,to:t,shapeIndex:s,plan:r},r;const a=K(i).subpaths.filter(p=>p.length>0).length===K(t).subpaths.filter(p=>p.length>0).length,o=$t(i,!a),c=$t(t,!a),h={pairs:o.map((p,f)=>qe(p,c[f],e))};lt>=Xe&&(J.clear(),lt=0);const u=String(s??"auto"),l=J.get(u)??new Map;J.set(u,l);const g=l.get(i)??new Map;return l.set(i,g),g.set(t,h),lt++,O={from:i,to:t,shapeIndex:s,plan:h},h}function Ue(i,t,e,s={}){if(!i)return t;if(!t)return i;const n=Math.max(0,Math.min(1,e));if(n===0)return i;if(n===1)return t;const r=We(i,t,s);if(r.pairs.length===0)return n<.5?i:t;let a="";for(const o of r.pairs){for(let c=0;c<o.from.length;c+=2){const h=Lt(o.from[c]+(o.to[c]-o.from[c])*n),u=Lt(o.from[c+1]+(o.to[c+1]-o.from[c+1])*n);a+=`${c===0?a?" M":"M":" L"}${h} ${u}`}o.closed&&(a+=" Z")}return a}function He(i){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(i)}const Qe=.9995;function je(){return[0,0,0,1]}function ze(i,t){return i[0]*t[0]+i[1]*t[1]+i[2]*t[2]+i[3]*t[3]}function Ge(i){return Math.hypot(i[0],i[1],i[2],i[3])}function H(i){const t=Ge(i);return t===0?je():[i[0]/t,i[1]/t,i[2]/t,i[3]/t]}function Ze(i,t,e){const s=H(i);let n=H(t),r=ze(s,n);if(r<0&&(n=[-n[0],-n[1],-n[2],-n[3]],r=-r),r>Qe)return H([s[0]+(n[0]-s[0])*e,s[1]+(n[1]-s[1])*e,s[2]+(n[2]-s[2])*e,s[3]+(n[3]-s[3])*e]);const a=Math.acos(r),o=Math.sin(a),c=Math.sin((1-e)*a)/o,h=Math.sin(e*a)/o;return H([s[0]*c+n[0]*h,s[1]*c+n[1]*h,s[2]*c+n[2]*h,s[3]*c+n[3]*h])}const D=(i,t,e)=>i+(t-i)*e,qt=512,dt=new Map,ft=new Map;function Vt(i){const t=dt.get(i);if(t)return t;const e=i.replace("#",""),s=[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)];return dt.size<qt&&dt.set(i,s),s}const Wt=i=>i.charCodeAt(0)===35,Ut=i=>i.startsWith("rgb"),Ht=i=>i.startsWith("rgba"),Ke=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,pt=i=>Math.round(i).toString(16).padStart(2,"0");function Je(i,t,e){return`#${pt(i)}${pt(t)}${pt(e)}`}function Qt(i){const t=ft.get(i);if(t)return t;const e=i.match(Ke);if(!e)throw new Error(`Invalid rgb color: ${i}`);const s=parseInt(e[1],10),n=parseInt(e[2],10),r=parseInt(e[3],10),a=e[4]!==void 0?[s,n,r,parseFloat(e[4])]:[s,n,r];return ft.size<qt&&ft.set(i,a),a}const ti=(i,t,e)=>{if(Wt(i)&&Wt(t)){const[s,n,r]=Vt(i),[a,o,c]=Vt(t),h=D(s,a,e),u=D(n,o,e),l=D(r,c,e);return Je(h,u,l)}if((Ut(i)||Ht(i))&&(Ut(t)||Ht(t))){const s=Qt(i),n=Qt(t),r=Math.round(D(s[0],n[0],e)),a=Math.round(D(s[1],n[1],e)),o=Math.round(D(s[2],n[2],e));if(s.length===4||n.length===4){const c=s[3]??1,h=n[3]??1,u=D(c,h,e);return`rgba(${r}, ${a}, ${o}, ${u})`}return`rgb(${r}, ${a}, ${o})`}return e<1?i:t},ei=(i,t,e)=>{const s=Math.min(i.length,t.length),n=[];for(let r=0;r<s;r++)n.push(D(i[r],t[r],e));return n},ii=(i,t,e)=>Ze(i,t,e),jt=(i,t,e)=>e<1?i:t,si=(i,t,e)=>Ue(i,t,e);function ni(i,t){return t==="slerp"?ii:typeof i=="number"?D:Array.isArray(i)?ei:typeof i=="string"?i.startsWith("#")||i.startsWith("rgb")?ti:He(i)?si:jt:jt}function ri(i){const t=[...i.keyframes].sort((e,s)=>e.time-s.time);return{...i,keyframes:t}}function L(i){return i.targets&&i.targets.length>0?i.targets:[i.target]}function F(i,t,e,s){const n=e??0;return!s||t<=1?n:n+kt(i,t,s)}class mt{track;targets;constructor(t){this.track=t,this.targets=L(t)}getValueAtTime(t){return this.valueForOffset(t-F(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=F(n,e,this.track.delay,this.track.stagger),a=this.valueForOffset(t-r);a!==void 0&&s.push({target:this.targets[n],value:a,start:r+this.track.keyframes[0].time})}return s}getDuration(){const{keyframes:t}=this.track;if(t.length===0)return 0;const e=t[t.length-1].time,s=this.track.stagger?at(this.targets.length,this.track.stagger):0;return e+(this.track.delay??0)+s+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(t){const{keyframes:e}=this.track;if(e.length===0)return;if(e.length===1||t<=e[0].time)return e[0].value;if(t>=e[e.length-1].time)return e[e.length-1].value;const{from:s,to:n}=this.findSurroundingKeyframes(t);if(!s||!n)return;if(s.time===t)return s.value;const r=n.time-s.time,a=(t-s.time)/r,c=ke(n.easing)(a);return ni(s.value,this.track.interpolation)(s.value,n.value,c)}findSurroundingKeyframes(t){const{keyframes:e}=this.track;for(let s=0;s<e.length-1;s++)if(t>=e[s].time&&t<=e[s+1].time)return{from:e[s],to:e[s+1]};return{from:null,to:null}}}class ai{track;targets;sampler;constructor(t){this.track=t,this.targets=L(t),this.sampler=new ce(t.spring)}getValueAtTime(t){return this.sampler.valueAt(t-F(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=F(n,e,this.track.delay,this.track.stagger);s.push({target:this.targets[n],value:this.sampler.valueAt(t-r),start:r})}return s}getDuration(){const t=this.track.stagger?at(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+t}getTrack(){return this.track}}class oi{track;targets;duration;constructor(t){this.track=t,this.targets=L(t),this.duration=xt(t.inertia)}getValueAtTime(t){return It(this.track.inertia,t-F(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(t){const e=this.targets.length,s=[];for(let n=0;n<e;n++){const r=F(n,e,this.track.delay,this.track.stagger);s.push({target:this.targets[n],value:It(this.track.inertia,t-r),start:r})}return s}getDuration(){const t=this.track.stagger?at(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+t}getTrack(){return this.track}}function ci(i,t){const e={...Ee(i.pathData,t)};if(i.matrix){const[s,n,r,a,o,c]=i.matrix,{x:h,y:u}=e;e.x=s*h+r*u+o,e.y=n*h+a*u+c;const l=e.angle*Math.PI/180,g=Math.cos(l),p=Math.sin(l);e.angle=Math.atan2(n*g+a*p,s*g+r*p)*180/Math.PI}return i.autoRotate&&i.rotateOffset&&(e.angle+=i.rotateOffset),e}const gt={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},hi=20;function li(i){const t=gt[i??"upperCase"]??i??gt.upperCase,e=Array.from(t);return e.length>0?e:Array.from(gt.upperCase)}function ui(i,t,e){let s=(i|0)^Math.imul(t+1,2654435761)^Math.imul(e+1,2246822507);return s=Math.imul(s^s>>>16,2146121005),s=Math.imul(s^s>>>15,2221713035),(s^s>>>16)>>>0}function di(i,t,e=0){const s=i.from??"",n=i.to,r=Math.max(0,Math.min(1,t));if(r<=0)return s;if(r>=1)return n;const a=Array.from(s),o=Array.from(n),c=i.rightToLeft??!1;if(i.mode==="type"){const b=Math.round(r*Math.max(a.length,o.length));return c?a.slice(0,Math.max(0,a.length-b)).join("")+o.slice(Math.max(0,o.length-b)).join(""):o.slice(0,b).join("")+a.slice(b).join("")}const h=Math.max(0,Math.min(.999,i.revealDelay??0)),u=Math.max(0,(r-h)/(1-h)),l=Math.floor(u*o.length),g=i.tweenLength===!1?o.length:Math.round(a.length+(o.length-a.length)*r),p=li(i.chars),f=i.refreshRate??hi,d=f>0?Math.floor(e*f/1e3):0,m=i.seed??1;let T="";for(let b=0;b<g;b++){const A=c?b>=g-l:b<l,M=c?o[o.length-(g-b)]:o[b];A&&M!==void 0||M===" "||M===`
|
|
2
|
-
`?T+=M:T+=p[ui(m,b,d)%p.length]}return T}class fi{id;name;_captions;_tracks=[];_trackPlayers=new Map;_motionPathTracks=new Map;_springTracks=new Map;_textTracks=new Map;_config;_currentTime=0;_playbackState="idle";_direction="forward";_loopIteration=0;_explicitDuration;_repeatDelayRemaining=0;_wrapAfterDelay=!1;onUpdate=null;onComplete=null;constructor(t){if(this.id=t.id,this.name=t.name,this._captions=t.captions,this._config=t.config??{},this._explicitDuration=t.config?.duration,t.tracks)for(const e of t.tracks)this.addTrack(e)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(t){if(this._explicitDuration=t,t!==void 0)this._config={...this._config,duration:t};else if(this._config.duration!==void 0){const e={...this._config};delete e.duration,this._config=e}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(t){this._config.speed=t}get drawingRate(){return this._config.drawingRate??0}set drawingRate(t){const e={...this._config};t>0?e.drawingRate=t:delete e.drawingRate,this._config=e}play(){const t=this.duration;this._direction==="forward"&&this._currentTime>=t&&t>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&t>0&&(this._currentTime=t,this._loopIteration=0),this._playbackState="playing"}pause(){this._playbackState="paused"}stop(){this._playbackState="idle",this._repeatDelayRemaining=0,this._wrapAfterDelay=!1,this._currentTime=0,this._loopIteration=0,this._direction="forward"}seek(t){const e=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(t,e)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(t){if(this._playbackState!=="playing")return;const e=this.duration;if(e<=0)return;let n=t*this.speed;if(this._repeatDelayRemaining>0){const o=Math.min(this._repeatDelayRemaining,n);if(this._repeatDelayRemaining-=o,n-=o,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const r=1e3;for(let o=0;o<r&&n>0&&this._playbackState==="playing";o++)if(this._direction==="forward"){const c=e-this._currentTime;if(n>=c){if(n-=c,this._currentTime=e,!this._handleEndReached())break}else this._currentTime+=n,n=0}else{const c=this._currentTime;if(n>=c){if(n-=c,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=n,n=0}const a=this.getStateAtTime(this._currentTime);this.onUpdate?.(a)}getStateAtTime(t){const e=new Map;if(t=re(t,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(t,e);else for(const[s,n]of this._trackPlayers){const r=n.getTrack().property;for(const{target:a,value:o,start:c}of n.getTargetValues(t))this._write(e,s,a,r,o,t-c)}return{values:e,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(t,e){const s=new Map;for(const[n,r]of this._trackPlayers){const a=r.getTrack().property;for(const{target:o,value:c,start:h}of r.getTargetValues(t)){const u=`${o}\0${a}`,l=h<=t,g=s.get(u);(!g||(l!==g.started?l:l?h>=g.start:h<=g.start))&&s.set(u,{trackId:n,target:o,property:a,value:c,start:h,started:l})}}for(const{trackId:n,target:r,property:a,value:o,start:c}of s.values())this._write(e,n,r,a,o,t-c)}_write(t,e,s,n,r,a){if(r===void 0)return;let o=t.get(s);o||(o=new Map,t.set(s,o));const c=this._textTracks.get(e);if(c&&typeof r=="number"){o.set("text",di(c.textConfig,r,Math.max(0,a)));return}const h=this._motionPathTracks.get(e);if(h&&typeof r=="number"){const u=ci(h.motionPathConfig,r);o.set("motionPathX",u.x),o.set("motionPathY",u.y),h.motionPathConfig.autoRotate&&o.set("motionPathRotate",u.angle)}else o.set(n,r)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const t=new Set;this._sharedWrites=!1;t:for(const e of this._tracks)for(const s of L(e)){const n=`${s}\0${e.property}`;if(t.has(n)){this._sharedWrites=!0;break t}t.add(n)}}return this._sharedWrites}addTrack(t){if(this._tracks.push(t),this._sharedWrites=null,nt(t)){this._trackPlayers.set(t.id,new oi(t));return}if(rt(t)){this._trackPlayers.set(t.id,new ai(t)),this._springTracks.set(t.id,t);return}if(Mt(t))this._trackPlayers.set(t.id,new mt(t)),this._textTracks.set(t.id,t);else if(ne(t)){const e={id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,delay:t.delay,endDelay:t.endDelay,targets:t.targets,stagger:t.stagger};this._trackPlayers.set(t.id,new mt(e)),this._motionPathTracks.set(t.id,t)}else this._trackPlayers.set(t.id,new mt(t))}replaceTrack(t,e){const s=this._tracks.findIndex(r=>r.id===t);if(s<0)return;const n=this._tracks.slice(s+1);this.removeTrack(t);for(const r of n)this.removeTrack(r.id);this.addTrack(e);for(const r of n)this.addTrack(r)}removeTrack(t){this._tracks=this._tracks.filter(e=>e.id!==t),this._sharedWrites=null,this._trackPlayers.delete(t),this._motionPathTracks.delete(t),this._springTracks.delete(t),this._textTracks.delete(t)}getTracks(t={}){return this._tracks.filter(e=>this._matches(e,t))}removeTracks(t={}){const e=this.getTracks(t).map(s=>s.id);for(const s of e)this.removeTrack(s);return e}getTrackSpan(t){const e=this._trackPlayers.get(t);if(!e)return;const s=e.getTrack(),n=s.delay??0;if(rt(s)||nt(s))return{from:n,to:e.getDuration()};const r=s.keyframes;if(!(!r||r.length===0))return{from:r[0].time+n,to:e.getDuration()}}findConflicts(){const t=[];for(let e=0;e<this._tracks.length;e++){const s=this._tracks[e],n=this.getTrackSpan(s.id);if(n)for(let r=0;r<e;r++){const a=this._tracks[r];if(a.property!==s.property)continue;const o=L(a).filter(l=>L(s).includes(l));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=n.to&&n.from<=c.to))continue;const u=n.from>=c.from;for(const l of o)t.push({target:l,property:s.property,losingTrackId:u?a.id:s.id,winningTrackId:u?s.id:a.id})}}return t}_matches(t,e){if(e.id!==void 0&&t.id!==e.id||e.property!==void 0&&t.property!==e.property||e.target!==void 0&&!L(t).includes(e.target))return!1;if(e.timeRange){const s=this.getTrackSpan(t.id);if(!s||s.to<e.timeRange.from||s.from>e.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:se(this._tracks),id:this.id,name:this.name,config:{...this._config},tracks:[...this._tracks],...this.captions&&{captions:this.captions}}}get config(){return this._config}get markers(){return[...this._config.markers??[]].sort((t,e)=>t.time-e.time)}setMarkers(t){const e=t&&t.length>0?[...t].sort((n,r)=>n.time-r.time).map(n=>({...n})):void 0,s={...this._config};e?s.markers=e:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(t){const e={};for(const[s,n]of Object.entries(t??{}))e[s]={...n};this._captions=Object.keys(e).length>0?e:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let t=0;for(const[,e]of this._trackPlayers)t=Math.max(t,e.getDuration());return t}_handleEndReached(){const t=this._config.loop??0;return t===-1||this._loopIteration<t?(this._loopIteration++,this._armRepeatDelay(),this._config.alternate?this._direction="reverse":this._repeatDelayRemaining>0?this._wrapAfterDelay=!0:this._currentTime=0,this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}_handleStartReached(){const t=this._config.loop??0;return this._config.alternate&&(t===-1||this._loopIteration<t)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const pi=100;function mi(i,t,e,s){const n=[],r=[],{duration:a,alternate:o}=s,c=(p,f,d,m)=>{r.push([p,f]);const T=[];i.forEach((b,A)=>{(d==="forward"?(m?b>=p:b>p)&&b<=f:(m?b<=p:b<p)&&b>=f)&&T.push(A)}),T.sort((b,A)=>(d==="forward"?i[b]-i[A]:i[A]-i[b])||b-A);for(const b of T)n.push({kind:"event",index:b,direction:d})};let h=t.time,u=t.direction,l=t.fresh===!0;const g=Math.min(pi,Math.max(0,e.iteration-t.iteration));for(let p=0;p<g;p++){const f=u==="forward"?a:0;c(h,f,u,l),n.push({kind:"repeat"}),o?(u=u==="forward"?"reverse":"forward",h=f,l=!1):(h=u==="forward"?0:a,l=!0)}return g>0&&s.holding&&!o?{crossings:n,passes:r}:(c(h,e.time,u,l),{crossings:n,passes:r})}function gi(i){return{...i,...Array.isArray(i.end)&&{end:[...i.end]}}}function Q(i){const t=i.endDelay;return{...i.delay!==void 0&&{delay:i.delay},...t!==void 0&&{endDelay:t},...i.targets!==void 0&&{targets:[...i.targets]},...i.stagger!==void 0&&{stagger:{...i.stagger}}}}function yi(i){if(nt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:gi(t.inertia),...Q(t)}}if(rt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...Q(t)}}if(Mt(i)){const t=i;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((e,s)=>e.time-s.time),...Q(t)}}if(i.property==="motionPath"&&"motionPathConfig"in i){const t=i,e=[...t.keyframes].sort((s,n)=>s.time-n.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:e,...Q(t)}}return ri({id:i.id,target:i.target,property:i.property,keyframes:i.keyframes,...i.interpolation!==void 0&&{interpolation:i.interpolation},...Q(i)})}function tt(i){const t=i.formatVersion??1;if(t>St)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${St}. Update tinyfly to play it.`);return new fi({id:i.id,name:i.name,config:i.config,tracks:i.tracks.map(yi),captions:i.captions})}function Ti(i){const[t,e,s,n]=i;return[1-2*(e*e+s*s),2*(t*e+s*n),2*(t*s-e*n),0,2*(t*e-s*n),1-2*(t*t+s*s),2*(e*s+t*n),0,2*(t*s+e*n),2*(e*s-t*n),1-2*(t*t+e*e),0,0,0,0,1]}function bi(i){return!Array.isArray(i)||i.length!==4?null:`matrix3d(${Ti(H(i)).map(e=>Math.round(e*1e6)/1e6+0).join(", ")})`}const Ai=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),Si="#ffffff",Mi="rgba(0, 0, 0, 0.5)";function _i(i){const t=[];if(i.blur!==void 0&&t.push(`blur(${Math.max(0,i.blur)}px)`),i.brightness!==void 0&&t.push(`brightness(${Math.max(0,i.brightness)})`),i.glow!==void 0&&t.push(`drop-shadow(0 0 ${Math.max(0,i.glow)}px ${i.glowColor??Si})`),i.shadowX!==void 0||i.shadowY!==void 0||i.shadowBlur!==void 0){const e=i.shadowX??0,s=i.shadowY??0,n=Math.max(0,i.shadowBlur??0);t.push(`drop-shadow(${e}px ${s}px ${n}px ${i.shadowColor??Mi})`)}return t.length>0?t.join(" "):null}function ki(i,t){const e=i.childNodes.length===1?i.firstChild:null;if(e&&e.nodeType===3){const s=e;s.data!==t&&(s.data=t);return}i.textContent!==t&&(i.textContent=t)}function wi(i){if(!("ownerSVGElement"in i))return;const t=i.style;!t||t.transformBox||(t.transformBox="fill-box",t.transformOrigin||(t.transformOrigin="50% 50%"))}const zt=new Set(["width","height","top","right","bottom","left","margin","marginTop","marginRight","marginBottom","marginLeft","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","borderRadius","borderWidth","fontSize","lineHeight","letterSpacing","outlineWidth","gap","rowGap","columnGap"]),Pi=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),vi=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],xi=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),Ii=new Set(["originX","originY"]),Ci=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Ri=new Set(["drawOn"]),Di={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},Gt={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},Ei="http://www.w3.org/2000/svg";class j{targets=new Map;registerTarget(t,e){this.targets.set(t,e)}unregisterTarget(t){this.targets.delete(t)}getTarget(t){return this.targets.get(t)}clearTargets(){this.targets.clear()}applyState(t){for(const[e,s]of t.values){const n=this.targets.get(e);n&&this.applyProperties(n,s)}}applyProperties(t,e){let s=null,n=null,r=null,a=null,o=null;const c=e.has("motionPathX"),h=e.has("motionPathY"),u=e.has("motionPathRotate");for(const[f,d]of e)if(!(f==="x"&&c)&&!(f==="y"&&h)&&!((f==="rotate"||f==="rotateZ")&&u)&&!Ri.has(f)){if(Pi.has(f))(s??={})[f]=d;else if(xi.has(f))typeof d=="number"&&((n??={})[f]=d);else if(Ii.has(f))typeof d=="number"&&((r??={})[f]=d);else if(Ci.has(f))typeof d=="number"&&((a??={})[f]=d);else if(Ai.has(f))(o??={})[f]=d;else if(f!=="perspective"){if(f!=="shine")if(f==="text"&&typeof d=="string")ki(t,d);else if(f==="d"&&typeof d=="string"){const m=t;(m.tagName?.toLowerCase()==="path"?m:m.querySelector?.("path"))?.setAttribute?.("d",d)}else this.applyStyleProperty(t,f,d)}}const l=e.get("shine");typeof l=="number"&&this.applyShine(t,l);const g=[],p=e.get("perspective");if(typeof p=="number"&&p>0&&g.push(`perspective(${p}px)`),s)for(const f of vi){const d=s[f];if(d===void 0)continue;const m=this.buildTransformPart(f,d);m&&g.push(m)}if(g.length>0&&(t.style.transform=g.join(" "),wi(t)),n&&(n.childPerspective!==void 0&&(t.style.perspective=`${n.childPerspective}px`),(n.perspectiveOriginX!==void 0||n.perspectiveOriginY!==void 0)&&(t.style.perspectiveOrigin=`${n.perspectiveOriginX??50}% ${n.perspectiveOriginY??50}%`)),r){const f=r.originX??50,d=r.originY??50;t.style.transformOrigin=`${f}% ${d}%`}if(a){const f=a.clipTop??0,d=a.clipRight??0,m=a.clipBottom??0,T=a.clipLeft??0;t.style.clipPath=`inset(${f}% ${d}% ${m}% ${T}%)`}if(o){const f=_i(o);f&&(t.style.filter=f)}}buildTransformPart(t,e){if(t==="quaternion")return bi(e);if(typeof e!="number")return null;switch(t){case"x":case"motionPathX":return`translateX(${e}px)`;case"y":case"motionPathY":return`translateY(${e}px)`;case"z":return`translateZ(${e}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${e}deg)`;case"rotateX":return`rotateX(${e}deg)`;case"rotateY":return`rotateY(${e}deg)`;case"scale":return`scale(${e})`;case"scaleX":return`scaleX(${e})`;case"scaleY":return`scaleY(${e})`;case"scaleZ":return`scaleZ(${e})`;case"skewX":return`skewX(${e}deg)`;case"skewY":return`skewY(${e}deg)`;default:return null}}applyShine(t,e){t.dataset.shineBase||(t.dataset.shineBase=t.style.color||"currentColor");const s=t.dataset.shineBase,n=-20+e*140,r=t.style;r.color="transparent",r.backgroundImage=`linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${s}, ${s})`,r.backgroundSize="250% 100%, 100% 100%",r.backgroundPosition=`${n}% 0, 0 0`,r.backgroundRepeat="no-repeat",r.webkitBackgroundClip="text",r.backgroundClip="text"}applyStyleProperty(t,e,s){let n;if(t.namespaceURI===Ei&&e in Gt){const o=Array.isArray(s)?s.join(", "):String(s);t.style[Gt[e]]=o;return}else e==="fill"&&t.dataset?.elementType==="text"?n="color":n=Di[e]??e;let a;typeof s=="number"?zt.has(e)||zt.has(n)?a=`${s}px`:a=String(s):Array.isArray(s)?a=s.join(", "):a=s,t.style[n]=a}}class yt{media;offset;driftTolerance;constructor(t,e={}){this.media=t,this.offset=e.offset??0,this.driftTolerance=Math.max(0,e.driftTolerance??.15)}targetTime(t){return Math.max(0,t/1e3+this.offset)}update(t,e){const s=this.targetTime(t);e?(this.media.paused&&this.safePlay(),Math.abs(this.media.currentTime-s)>this.driftTolerance&&(this.media.currentTime=s)):(this.media.paused||this.media.pause(),this.media.currentTime!==s&&(this.media.currentTime=s))}seek(t){this.media.currentTime=this.targetTime(t)}setRate(t){this.media.playbackRate=t}dispose(){this.media.paused||this.media.pause()}safePlay(){const t=this.media.play();t&&typeof t.catch=="function"&&t.catch(()=>{})}}function Zt(i,t,e,s,n){const r=e-n;if(r<0){t.paused||t.pause(),t.currentTime=0;return}i.update(r,s)}class Tt{container;timeline=null;adapter;animationFrameId;lastTime;options;targets={};isDestroyed=!1;mediaSync;mediaTargets=[];symbolInstances=[];scenarioList=[];scenarioId;authored=new Map;markerList=[];listeners=new Set;playhead={time:0,iteration:0,direction:"forward"};stepping=!1;lastMarkerId=null;reducedQuery;onReducedChange=()=>this.applyReducedMotion();visibilityObserver;onScreen=!0;pausedByVisibility=!1;autoplayWhenSeen=!1;onDocumentVisibility=()=>this.updateVisibility();constructor(t,e={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=e,this.adapter=new j}async load(t){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(t)}async loadSource(t){let e;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load animation: ${s.statusText}`);e=await s.json()}else e=t;this.useDefinition(e),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(t){const e={...t.config};this.options.speed!==void 0&&(e.speed=this.options.speed),this.options.loop!==void 0&&(e.loop=this.options.loop),this.options.alternate!==void 0&&(e.alternate=this.options.alternate),this.timeline=tt({...t,config:e}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(t,e={}){if(t.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const s=new Set;for(const r of t){if(s.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);s.add(r.id)}const n=e.initial===void 0?t[0]:t.find(r=>r.id===e.initial);if(!n)throw new Error(`tinyfly: there is no scenario "${e.initial}"`);this.scenarioList=[...t],this.scenarioId=n.id,await this.loadSource(n.timeline)}get scenarios(){return this.scenarioList.map(t=>({id:t.id,label:t.label??t.id}))}get scenario(){return this.scenarioId}setScenario(t){const e=this.scenarioList.find(o=>o.id===t);if(!e||!this.timeline)return!1;if(t===this.scenarioId)return!0;const s=this.isPlaying,n=this.currentTime>=this.duration-.5,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=t,this.useDefinition(e.timeline),this.lastMarkerId=null;let a=0;return this.reducedMotion||n?a=this.duration:r!==void 0&&(a=this.markers.find(o=>o.id===r)?.time??0),this.seek(a),s&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(t){if(this.authored.has(t))return;const e={style:t.getAttribute("style")};t.children.length===0&&(e.text=t.textContent??"");const s=t.tagName.toLowerCase()==="path"?t:t.querySelector("path");s&&(e.path={element:s,d:s.getAttribute("d")}),this.authored.set(t,e)}restoreAuthored(){for(const[t,e]of this.authored){e.style===null?t.removeAttribute("style"):t.setAttribute("style",e.style),e.text!==void 0&&t.textContent!==e.text&&(t.textContent=e.text),e.path&&(e.path.d===null?e.path.element.removeAttribute("d"):e.path.element.setAttribute("d",e.path.d));const s=t.dataset;s&&delete s.shineBase}}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notify(){for(const t of this.listeners)t()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const t=this.currentTime;let e;for(const s of this.markers)if(s.time<=t+.5)e=s;else break;return e}caption(t,e){const s=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!s)return;const n=e??this.language(),r=a=>a?.[n]?.[s.id]??a?.[n.split("-")[0]]?.[s.id];return r(this.options.captions)??r(this.timeline?.captions)??s.label}next(){if(!this.timeline)return;const t=this.currentTime,e=this.markers.find(s=>s.time>t+.5);if(this.reducedMotion){this.seek(e?e.time:this.duration);return}t>=this.duration-.5||(this.stepping=e!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const t=this.currentTime,e=[...this.markers].reverse().find(s=>s.time<t-.5);this.pause(),this.seek(e?e.time:0)}goToMarker(t){const e=this.markers.find(s=>s.id===t);e&&(this.pause(),this.seek(e.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const t=this.options.initialFrame??"start";if(t==="none")return;const e=t==="end"?this.timeline.duration:t==="start"?0:t;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,e))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(e=>{for(const s of e)this.onScreen=s.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const t=this.container.getBoundingClientRect?.();t&&(t.width>0||t.height>0)&&(this.onScreen=t.bottom>0&&t.top<window.innerHeight&&t.right>0&&t.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const t=this.onScreen&&document.visibilityState!=="hidden";!t&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):t&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const t=this.currentMarker,e=t?.id;e!==this.lastMarkerId&&(this.lastMarkerId=e,this.options.onMarker(t))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(e=>{const s=e,n=Number(s.getAttribute("data-tinyfly-start")??"0")||0,r=s.getAttribute("data-volume");r!==null&&(s.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:s,startTime:n,sync:new yt(s)})})}syncAllMedia(t,e){for(const s of this.mediaTargets)Zt(s.sync,s.el,t,e,s.startTime)}loadFromString(t){const e=JSON.parse(t);this.load(e)}registerTarget(t,e){if(typeof e=="string"){const s=this.container.querySelector(e);s&&(this.rememberAuthored(s),this.targets[t]=s,this.adapter.registerTarget(t,s))}else this.rememberAuthored(e),this.targets[t]=e,this.adapter.registerTarget(t,e)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(e=>{const s=e.closest("[data-tinyfly-symbol]");if(s&&s!==e)return;const n=e.getAttribute("data-tinyfly");n&&this.registerTarget(n,e)}),this.timeline&&new Set(this.timeline.tracks.map(s=>s.target)).forEach(s=>{if(!this.targets[s]){const n=this.container.querySelector(`[data-tinyfly="${s}"]`)||this.container.querySelector(`.${s}`)||this.container.querySelector(`#${s}`);n&&this.registerTarget(s,n)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const e=new Map(t.map(s=>[s.id,s]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const n=s.getAttribute("data-tinyfly-symbol");if(!n)return;const r=e.get(n);if(!r||!r.timeline.tracks?.length)return;const a=new j;s.querySelectorAll("[data-tinyfly]").forEach(o=>{const c=o.getAttribute("data-tinyfly");c&&a.registerTarget(c,o)}),this.symbolInstances.push({adapter:a,timeline:tt(r.timeline)})})}attachMedia(t,e){this.mediaSync=new yt(t,e),this.timeline&&(this.mediaSync.setRate(this.timeline.speed),this.mediaSync.update(this.timeline.currentTime,this.isPlaying))}detachMedia(){this.mediaSync?.dispose(),this.mediaSync=void 0}play(){!this.timeline||this.isDestroyed||(this.autoplayWhenSeen=!1,this.stepping=this.options.stepMode===!0,this.startPlaying())}startPlaying(){if(!this.timeline||this.isDestroyed)return;const t=this.timeline.playbackState==="idle";this.timeline.play(),t&&this.timeline.currentTime===0&&this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.update(this.timeline.currentTime,!0),this.syncAllMedia(this.timeline.currentTime,!0),this.startAnimationLoop(),this.notify()}pause(){this.timeline&&(this.stepping=!1,this.timeline.pause(),this.notify(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1),this.stopAnimationLoop())}stop(){this.timeline&&(this.timeline.stop(),this.stopAnimationLoop(),this.applyState(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1))}seek(t){this.timeline&&(this.timeline.seek(t),this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.seek(this.timeline.currentTime),this.syncAllMedia(this.timeline.currentTime,this.isPlaying))}setSpeed(t){this.timeline&&(this.timeline.speed=t,this.mediaSync?.setRate(t))}reverse(){this.timeline&&this.timeline.reverse()}get currentTime(){return this.timeline?.currentTime??0}get duration(){return this.timeline?.duration??0}get isPlaying(){return this.timeline?.playbackState==="playing"}destroy(){this.isDestroyed=!0,this.stopAnimationLoop(),this.reducedQuery?.removeEventListener?.("change",this.onReducedChange),this.visibilityObserver?.disconnect(),typeof document<"u"&&document.removeEventListener("visibilitychange",this.onDocumentVisibility),this.mediaSync?.dispose(),this.mediaSync=void 0;for(const t of this.mediaTargets)t.el.paused||t.el.pause();this.mediaTargets=[],this.adapter.clearTargets();for(const t of this.symbolInstances)t.adapter.clearTargets();this.symbolInstances=[],this.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=e=>{if(this.isDestroyed||!this.timeline)return;const s=e-(this.lastTime??e);this.lastTime=e;const n=this.playhead;this.timeline.tick(s),this.stopAtMarker(n),this.applyState();const r=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,r),this.syncAllMedia(this.timeline.currentTime,r),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(t):(this.animationFrameId=void 0,this.notify())};this.animationFrameId=requestAnimationFrame(t)}stopAtMarker(t){const e=this.timeline,s={time:e.currentTime,iteration:e.loopIteration,direction:e.direction};this.playhead=s;const n=this.markers;if(n.length===0)return;const{crossings:r}=mi(n.map(a=>a.time),t,s,{duration:e.duration,alternate:e.config.alternate===!0,holding:e.repeatDelayRemaining>0});for(const a of r){if(a.kind!=="event")continue;const o=n[a.index];if(this.stepping||o.pause){this.stepping=!1,e.pause(),e.seek(o.time),this.playhead={time:o.time,iteration:e.loopIteration,direction:e.direction};return}}}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}applyState(){if(!this.timeline)return;const t=this.timeline.currentTime;this.adapter.applyState(this.timeline.getStateAtTime(t)),this.announceMarker(),this.notify();for(const e of this.symbolInstances){const s=e.timeline.duration;e.adapter.applyState(e.timeline.getStateAtTime(s>0?t%s:t))}}}async function Bi(i,t,e={}){const s=new Tt(i,{...e,autoplay:!0});return await s.load(t),s}function Oi(i,t={}){return new Tt(i,t)}class Kt{container;containerA;containerB;adapterA;adapterB;timelineA=null;timelineB=null;symbolDefs=new Map;nestedByAdapter=new Map;sequence=null;options;_currentSceneIndex=0;_state="idle";_isPlaying=!1;_isDestroyed=!1;loopIteration=0;animationFrameId;lastTime;transitionTimer;constructor(t,e={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=e,this.container.style.position="relative",this.container.style.overflow="hidden",this.containerA=this.createSceneContainer(),this.containerB=this.createSceneContainer(),this.container.appendChild(this.containerA),this.container.appendChild(this.containerB),this.containerB.style.visibility="hidden",this.adapterA=new j,this.adapterB=new j}async load(t){let e;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load sequence: ${s.statusText}`);e=await s.json()}else e=t;this.sequence=e,this.symbolDefs.clear();for(const s of e.symbols??[])s.timeline?.tracks?.length&&this.symbolDefs.set(s.id,s.timeline);this.container.style.width=`${e.canvas.width}px`,this.container.style.height=`${e.canvas.height}px`,e.scenes.length>0&&(this.renderScene(e.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(e.scenes[0])),this.options.autoplay&&this.play()}play(){if(!(!this.sequence||this._isDestroyed)&&this.sequence.scenes.length!==0){if(this._isPlaying=!0,this._state==="idle"){if(this._state="playing-scene",this._currentSceneIndex=0,this.timelineA)this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play();else{this.onSceneComplete();return}this.options.onSceneChange?.(0)}else this._state==="playing-scene"&&this.timelineA&&this.timelineA.play();this.startAnimationLoop()}}pause(){this._isPlaying&&(this._isPlaying=!1,this.timelineA&&this.timelineA.pause(),this.timelineB&&this.timelineB.pause(),this.stopAnimationLoop())}stop(){if(this._isPlaying=!1,this._state="idle",this._currentSceneIndex=0,this.loopIteration=0,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.stopAnimationLoop(),this.sequence&&this.sequence.scenes.length>0&&(this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this.renderScene(this.sequence.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(this.sequence.scenes[0]),this.timelineA)){const t=this.timelineA.getStateAtTime(0);this.adapterA.applyState(t),this.applyNested(this.adapterA,0)}}goToScene(t){if(!this.sequence||t<0||t>=this.sequence.scenes.length)return;const e=this._isPlaying;this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this._currentSceneIndex=t,this._state=e?"playing-scene":"idle",this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB);const s=this.sequence.scenes[t];if(this.renderScene(s,this.containerA,this.adapterA),this.timelineA=this.createTimeline(s),this.options.onSceneChange?.(t),e)this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play(),this.startAnimationLoop()):this.onSceneComplete();else if(this.timelineA){const n=this.timelineA.getStateAtTime(0);this.adapterA.applyState(n),this.applyNested(this.adapterA,0)}}destroy(){this._isDestroyed=!0,this._isPlaying=!1,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.adapterA.clearTargets(),this.adapterB.clearTargets();for(const t of this.nestedByAdapter.values())for(const e of t)e.adapter.clearTargets();this.nestedByAdapter.clear(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.timelineA=null,this.timelineB=null,this.containerA.parentNode&&this.containerA.remove(),this.containerB.parentNode&&this.containerB.remove(),this.sequence=null}get currentSceneIndex(){return this._currentSceneIndex}get sceneCount(){return this.sequence?.scenes.length??0}get isPlaying(){return this._isPlaying}get state(){return this._state}createSceneContainer(){const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.width="100%",t.style.height="100%",t}renderScene(t,e,s){e.innerHTML="",s.clearTargets();const n=document.createElement("div");n.style.cssText="position:absolute;inset:0;transform-origin:center center",n.setAttribute("data-tinyfly","Camera"),e.appendChild(n),s.registerTarget("Camera",n);for(const r of t.elements){if(!r.html)continue;const a=document.createElement("div");a.innerHTML=r.html.trim();const o=a.firstElementChild;if(o){n.appendChild(o);const c=o.getAttribute("data-tinyfly");c&&s.registerTarget(c,o)}}this.setupNested(n,s)}setupNested(t,e){const s=[];t.querySelectorAll("[data-tinyfly-symbol]").forEach(n=>{const r=n.getAttribute("data-tinyfly-symbol");if(!r)return;const a=this.symbolDefs.get(r);if(!a)return;const o=new j;n.querySelectorAll("[data-tinyfly]").forEach(c=>{const h=c.getAttribute("data-tinyfly");h&&o.registerTarget(h,c)}),s.push({adapter:o,timeline:tt(a)})}),s.length?this.nestedByAdapter.set(e,s):this.nestedByAdapter.delete(e)}applyNested(t,e){const s=this.nestedByAdapter.get(t);if(s)for(const n of s){const r=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(r>0?e%r:e))}}clearContainer(t){t.innerHTML=""}createTimeline(t){return t.timeline?tt(t.timeline):null}onSceneComplete(){if(this._isDestroyed||!this.sequence)return;const t=this._currentSceneIndex+1;if(t>=this.sequence.scenes.length){const e=this.options.loop??this.sequence.loop??0;e===-1||e>0&&this.loopIteration<e-1?(this.loopIteration++,this.beginTransitionTo(0)):(this._isPlaying=!1,this._state="idle",this.stopAnimationLoop(),this.options.onComplete?.())}else this.beginTransitionTo(t)}beginTransitionTo(t){if(!this.sequence||this._isDestroyed)return;const e=this.sequence.scenes[t],s=e.transition;if(s.type==="none"||s.duration<=0){this.switchToScene(t);return}this._state="transitioning",this.containerB.style.visibility="visible",this.renderScene(e,this.containerB,this.adapterB),this.timelineB=this.createTimeline(e),this.timelineB&&this.timelineB.play(),this.applyTransition(s.type,s.duration),this.transitionTimer=window.setTimeout(()=>{this.finishTransition(t)},s.duration)}applyTransition(t,e){const s=`${e}ms`,n="ease-in-out";switch(this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),t){case"fade":this.containerB.style.opacity="0";break;case"slide-left":this.containerB.style.transform="translateX(100%)";break;case"slide-right":this.containerB.style.transform="translateX(-100%)";break;case"slide-up":this.containerB.style.transform="translateY(100%)";break;case"slide-down":this.containerB.style.transform="translateY(-100%)";break}switch(this.containerB.offsetHeight,this.containerA.style.transition=`opacity ${s} ${n}, transform ${s} ${n}`,this.containerB.style.transition=`opacity ${s} ${n}, transform ${s} ${n}`,t){case"fade":this.containerA.style.opacity="0",this.containerB.style.opacity="1";break;case"slide-left":this.containerA.style.transform="translateX(-100%)",this.containerB.style.transform="translateX(0)";break;case"slide-right":this.containerA.style.transform="translateX(100%)",this.containerB.style.transform="translateX(0)";break;case"slide-up":this.containerA.style.transform="translateY(-100%)",this.containerB.style.transform="translateY(0)";break;case"slide-down":this.containerA.style.transform="translateY(100%)",this.containerB.style.transform="translateY(0)";break}}resetTransitionStyles(t){t.style.transition="",t.style.opacity="1",t.style.transform=""}finishTransition(t){this.transitionTimer=void 0,this.timelineA&&(this.timelineA.stop(),this.timelineA=null),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.containerA;this.containerA=this.containerB,this.containerB=e;const s=this.adapterA;this.adapterA=this.adapterB,this.adapterB=s,this.timelineA=this.timelineB,this.timelineB=null,this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.playbackState!=="playing"&&this.timelineA.play()):this.onSceneComplete()}switchToScene(t){if(!this.sequence||this._isDestroyed)return;this.timelineA&&this.timelineA.stop(),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.sequence.scenes[t];this.renderScene(e,this.containerA,this.adapterA),this.timelineA=this.createTimeline(e),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play()):this.onSceneComplete()}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=e=>{if(this._isDestroyed||!this._isPlaying)return;const s=e-(this.lastTime??e);if(this.lastTime=e,this.timelineA&&this.timelineA.playbackState==="playing"){this.timelineA.tick(s);const n=this.timelineA.getStateAtTime(this.timelineA.currentTime);this.adapterA.applyState(n),this.applyNested(this.adapterA,this.timelineA.currentTime)}if(this._state==="transitioning"&&this.timelineB&&this.timelineB.playbackState==="playing"){this.timelineB.tick(s);const n=this.timelineB.getStateAtTime(this.timelineB.currentTime);this.adapterB.applyState(n),this.applyNested(this.adapterB,this.timelineB.currentTime)}this._isPlaying?this.animationFrameId=requestAnimationFrame(t):this.animationFrameId=void 0};this.animationFrameId=requestAnimationFrame(t)}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}}async function Li(i,t,e={}){const s=new Kt(i,{...e,autoplay:!0});return await s.load(t),s}const $i={type:"none",duration:0};v.DEFAULT_TRANSITION=$i,v.MediaSync=yt,v.TinyflyPlayer=Tt,v.TinyflySequencer=Kt,v.create=Oi,v.play=Bi,v.playSequence=Li,v.syncMediaElement=Zt,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
|
|
2
|
+
`?T+=M:T+=p[ui(m,b,d)%p.length]}return T}class fi{id;name;_captions;_tracks=[];_trackPlayers=new Map;_motionPathTracks=new Map;_springTracks=new Map;_textTracks=new Map;_config;_currentTime=0;_playbackState="idle";_direction="forward";_loopIteration=0;_explicitDuration;_repeatDelayRemaining=0;_wrapAfterDelay=!1;onUpdate=null;onComplete=null;constructor(t){if(this.id=t.id,this.name=t.name,this._captions=t.captions,this._config=t.config??{},this._explicitDuration=t.config?.duration,t.tracks)for(const e of t.tracks)this.addTrack(e)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(t){if(this._explicitDuration=t,t!==void 0)this._config={...this._config,duration:t};else if(this._config.duration!==void 0){const e={...this._config};delete e.duration,this._config=e}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(t){this._config.speed=t}get drawingRate(){return this._config.drawingRate??0}set drawingRate(t){const e={...this._config};t>0?e.drawingRate=t:delete e.drawingRate,this._config=e}play(){const t=this.duration;this._direction==="forward"&&this._currentTime>=t&&t>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&t>0&&(this._currentTime=t,this._loopIteration=0),this._playbackState="playing"}pause(){this._playbackState="paused"}stop(){this._playbackState="idle",this._repeatDelayRemaining=0,this._wrapAfterDelay=!1,this._currentTime=0,this._loopIteration=0,this._direction="forward"}seek(t){const e=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(t,e)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(t){if(this._playbackState!=="playing")return;const e=this.duration;if(e<=0)return;let n=t*this.speed;if(this._repeatDelayRemaining>0){const o=Math.min(this._repeatDelayRemaining,n);if(this._repeatDelayRemaining-=o,n-=o,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const r=1e3;for(let o=0;o<r&&n>0&&this._playbackState==="playing";o++)if(this._direction==="forward"){const c=e-this._currentTime;if(n>=c){if(n-=c,this._currentTime=e,!this._handleEndReached())break}else this._currentTime+=n,n=0}else{const c=this._currentTime;if(n>=c){if(n-=c,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=n,n=0}const a=this.getStateAtTime(this._currentTime);this.onUpdate?.(a)}getStateAtTime(t){const e=new Map;if(t=re(t,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(t,e);else for(const[s,n]of this._trackPlayers){const r=n.getTrack().property;for(const{target:a,value:o,start:c}of n.getTargetValues(t))this._write(e,s,a,r,o,t-c)}return{values:e,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(t,e){const s=new Map;for(const[n,r]of this._trackPlayers){const a=r.getTrack().property;for(const{target:o,value:c,start:h}of r.getTargetValues(t)){const u=`${o}\0${a}`,l=h<=t,g=s.get(u);(!g||(l!==g.started?l:l?h>=g.start:h<=g.start))&&s.set(u,{trackId:n,target:o,property:a,value:c,start:h,started:l})}}for(const{trackId:n,target:r,property:a,value:o,start:c}of s.values())this._write(e,n,r,a,o,t-c)}_write(t,e,s,n,r,a){if(r===void 0)return;let o=t.get(s);o||(o=new Map,t.set(s,o));const c=this._textTracks.get(e);if(c&&typeof r=="number"){o.set("text",di(c.textConfig,r,Math.max(0,a)));return}const h=this._motionPathTracks.get(e);if(h&&typeof r=="number"){const u=ci(h.motionPathConfig,r);o.set("motionPathX",u.x),o.set("motionPathY",u.y),h.motionPathConfig.autoRotate&&o.set("motionPathRotate",u.angle)}else o.set(n,r)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const t=new Set;this._sharedWrites=!1;t:for(const e of this._tracks)for(const s of L(e)){const n=`${s}\0${e.property}`;if(t.has(n)){this._sharedWrites=!0;break t}t.add(n)}}return this._sharedWrites}addTrack(t){if(this._tracks.push(t),this._sharedWrites=null,nt(t)){this._trackPlayers.set(t.id,new oi(t));return}if(rt(t)){this._trackPlayers.set(t.id,new ai(t)),this._springTracks.set(t.id,t);return}if(Mt(t))this._trackPlayers.set(t.id,new mt(t)),this._textTracks.set(t.id,t);else if(ne(t)){const e={id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,delay:t.delay,endDelay:t.endDelay,targets:t.targets,stagger:t.stagger};this._trackPlayers.set(t.id,new mt(e)),this._motionPathTracks.set(t.id,t)}else this._trackPlayers.set(t.id,new mt(t))}replaceTrack(t,e){const s=this._tracks.findIndex(r=>r.id===t);if(s<0)return;const n=this._tracks.slice(s+1);this.removeTrack(t);for(const r of n)this.removeTrack(r.id);this.addTrack(e);for(const r of n)this.addTrack(r)}removeTrack(t){this._tracks=this._tracks.filter(e=>e.id!==t),this._sharedWrites=null,this._trackPlayers.delete(t),this._motionPathTracks.delete(t),this._springTracks.delete(t),this._textTracks.delete(t)}getTracks(t={}){return this._tracks.filter(e=>this._matches(e,t))}removeTracks(t={}){const e=this.getTracks(t).map(s=>s.id);for(const s of e)this.removeTrack(s);return e}getTrackSpan(t){const e=this._trackPlayers.get(t);if(!e)return;const s=e.getTrack(),n=s.delay??0;if(rt(s)||nt(s))return{from:n,to:e.getDuration()};const r=s.keyframes;if(!(!r||r.length===0))return{from:r[0].time+n,to:e.getDuration()}}findConflicts(){const t=[];for(let e=0;e<this._tracks.length;e++){const s=this._tracks[e],n=this.getTrackSpan(s.id);if(n)for(let r=0;r<e;r++){const a=this._tracks[r];if(a.property!==s.property)continue;const o=L(a).filter(l=>L(s).includes(l));if(o.length===0)continue;const c=this.getTrackSpan(a.id);if(!c||!(c.from<=n.to&&n.from<=c.to))continue;const u=n.from>=c.from;for(const l of o)t.push({target:l,property:s.property,losingTrackId:u?a.id:s.id,winningTrackId:u?s.id:a.id})}}return t}_matches(t,e){if(e.id!==void 0&&t.id!==e.id||e.property!==void 0&&t.property!==e.property||e.target!==void 0&&!L(t).includes(e.target))return!1;if(e.timeRange){const s=this.getTrackSpan(t.id);if(!s||s.to<e.timeRange.from||s.from>e.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:se(this._tracks),id:this.id,name:this.name,config:{...this._config},tracks:[...this._tracks],...this.captions&&{captions:this.captions}}}get config(){return this._config}get markers(){return[...this._config.markers??[]].sort((t,e)=>t.time-e.time)}setMarkers(t){const e=t&&t.length>0?[...t].sort((n,r)=>n.time-r.time).map(n=>({...n})):void 0,s={...this._config};e?s.markers=e:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(t){const e={};for(const[s,n]of Object.entries(t??{}))e[s]={...n};this._captions=Object.keys(e).length>0?e:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let t=0;for(const[,e]of this._trackPlayers)t=Math.max(t,e.getDuration());return t}_handleEndReached(){const t=this._config.loop??0;return t===-1||this._loopIteration<t?(this._loopIteration++,this._armRepeatDelay(),this._config.alternate?this._direction="reverse":this._repeatDelayRemaining>0?this._wrapAfterDelay=!0:this._currentTime=0,this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}_handleStartReached(){const t=this._config.loop??0;return this._config.alternate&&(t===-1||this._loopIteration<t)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const pi=100;function mi(i,t,e,s){const n=[],r=[],{duration:a,alternate:o}=s,c=(p,f,d,m)=>{r.push([p,f]);const T=[];i.forEach((b,A)=>{(d==="forward"?(m?b>=p:b>p)&&b<=f:(m?b<=p:b<p)&&b>=f)&&T.push(A)}),T.sort((b,A)=>(d==="forward"?i[b]-i[A]:i[A]-i[b])||b-A);for(const b of T)n.push({kind:"event",index:b,direction:d})};let h=t.time,u=t.direction,l=t.fresh===!0;const g=Math.min(pi,Math.max(0,e.iteration-t.iteration));for(let p=0;p<g;p++){const f=u==="forward"?a:0;c(h,f,u,l),n.push({kind:"repeat"}),o?(u=u==="forward"?"reverse":"forward",h=f,l=!1):(h=u==="forward"?0:a,l=!0)}return g>0&&s.holding&&!o?{crossings:n,passes:r}:(c(h,e.time,u,l),{crossings:n,passes:r})}function gi(i){return{...i,...Array.isArray(i.end)&&{end:[...i.end]}}}function Q(i){const t=i.endDelay;return{...i.delay!==void 0&&{delay:i.delay},...t!==void 0&&{endDelay:t},...i.targets!==void 0&&{targets:[...i.targets]},...i.stagger!==void 0&&{stagger:{...i.stagger}}}}function yi(i){if(nt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:gi(t.inertia),...Q(t)}}if(rt(i)){const t=i;return{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...Q(t)}}if(Mt(i)){const t=i;return{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:[...t.keyframes].sort((e,s)=>e.time-s.time),...Q(t)}}if(i.property==="motionPath"&&"motionPathConfig"in i){const t=i,e=[...t.keyframes].sort((s,n)=>s.time-n.time);return{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:e,...Q(t)}}return ri({id:i.id,target:i.target,property:i.property,keyframes:i.keyframes,...i.interpolation!==void 0&&{interpolation:i.interpolation},...Q(i)})}function tt(i){const t=i.formatVersion??1;if(t>St)throw new Error(`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${St}. Update tinyfly to play it.`);return new fi({id:i.id,name:i.name,config:i.config,tracks:i.tracks.map(yi),captions:i.captions})}function Ti(i){const[t,e,s,n]=i;return[1-2*(e*e+s*s),2*(t*e+s*n),2*(t*s-e*n),0,2*(t*e-s*n),1-2*(t*t+s*s),2*(e*s+t*n),0,2*(t*s+e*n),2*(e*s-t*n),1-2*(t*t+e*e),0,0,0,0,1]}function bi(i){return!Array.isArray(i)||i.length!==4?null:`matrix3d(${Ti(H(i)).map(e=>Math.round(e*1e6)/1e6+0).join(", ")})`}const Ai=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),Si="#ffffff",Mi="rgba(0, 0, 0, 0.5)";function _i(i){const t=[];if(i.blur!==void 0&&t.push(`blur(${Math.max(0,i.blur)}px)`),i.brightness!==void 0&&t.push(`brightness(${Math.max(0,i.brightness)})`),i.glow!==void 0&&t.push(`drop-shadow(0 0 ${Math.max(0,i.glow)}px ${i.glowColor??Si})`),i.shadowX!==void 0||i.shadowY!==void 0||i.shadowBlur!==void 0){const e=i.shadowX??0,s=i.shadowY??0,n=Math.max(0,i.shadowBlur??0);t.push(`drop-shadow(${e}px ${s}px ${n}px ${i.shadowColor??Mi})`)}return t.length>0?t.join(" "):null}function ki(i,t){const e=i.childNodes.length===1?i.firstChild:null;if(e&&e.nodeType===3){const s=e;s.data!==t&&(s.data=t);return}i.textContent!==t&&(i.textContent=t)}function wi(i){if(!("ownerSVGElement"in i))return;const t=i.style;!t||t.transformBox||(t.transformBox="fill-box",t.transformOrigin||(t.transformOrigin="50% 50%"))}const zt=new Set(["width","height","top","right","bottom","left","margin","marginTop","marginRight","marginBottom","marginLeft","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","borderRadius","borderWidth","fontSize","lineHeight","letterSpacing","outlineWidth","gap","rowGap","columnGap"]),Pi=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),vi=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],xi=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),Ii=new Set(["originX","originY"]),Ci=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Ri=new Set(["drawOn"]),Di={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},Gt={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},Ei="http://www.w3.org/2000/svg";class j{targets=new Map;registerTarget(t,e){this.targets.set(t,e)}unregisterTarget(t){this.targets.delete(t)}getTarget(t){return this.targets.get(t)}clearTargets(){this.targets.clear()}applyState(t){for(const[e,s]of t.values){const n=this.targets.get(e);n&&this.applyProperties(n,s)}}applyProperties(t,e){let s=null,n=null,r=null,a=null,o=null;const c=e.has("motionPathX"),h=e.has("motionPathY"),u=e.has("motionPathRotate");for(const[f,d]of e)if(!(f==="x"&&c)&&!(f==="y"&&h)&&!((f==="rotate"||f==="rotateZ")&&u)&&!Ri.has(f)){if(Pi.has(f))(s??={})[f]=d;else if(xi.has(f))typeof d=="number"&&((n??={})[f]=d);else if(Ii.has(f))typeof d=="number"&&((r??={})[f]=d);else if(Ci.has(f))typeof d=="number"&&((a??={})[f]=d);else if(Ai.has(f))(o??={})[f]=d;else if(f!=="perspective"){if(f!=="shine")if(f==="text"&&typeof d=="string")ki(t,d);else if(f==="d"&&typeof d=="string"){const m=t;(m.tagName?.toLowerCase()==="path"?m:m.querySelector?.("path"))?.setAttribute?.("d",d)}else this.applyStyleProperty(t,f,d)}}const l=e.get("shine");typeof l=="number"&&this.applyShine(t,l);const g=[],p=e.get("perspective");if(typeof p=="number"&&p>0&&g.push(`perspective(${p}px)`),s)for(const f of vi){const d=s[f];if(d===void 0)continue;const m=this.buildTransformPart(f,d);m&&g.push(m)}if(g.length>0&&(t.style.transform=g.join(" "),wi(t)),n&&(n.childPerspective!==void 0&&(t.style.perspective=`${n.childPerspective}px`),(n.perspectiveOriginX!==void 0||n.perspectiveOriginY!==void 0)&&(t.style.perspectiveOrigin=`${n.perspectiveOriginX??50}% ${n.perspectiveOriginY??50}%`)),r){const f=r.originX??50,d=r.originY??50;t.style.transformOrigin=`${f}% ${d}%`}if(a){const f=a.clipTop??0,d=a.clipRight??0,m=a.clipBottom??0,T=a.clipLeft??0;t.style.clipPath=`inset(${f}% ${d}% ${m}% ${T}%)`}if(o){const f=_i(o);f&&(t.style.filter=f)}}buildTransformPart(t,e){if(t==="quaternion")return bi(e);if(typeof e!="number")return null;switch(t){case"x":case"motionPathX":return`translateX(${e}px)`;case"y":case"motionPathY":return`translateY(${e}px)`;case"z":return`translateZ(${e}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${e}deg)`;case"rotateX":return`rotateX(${e}deg)`;case"rotateY":return`rotateY(${e}deg)`;case"scale":return`scale(${e})`;case"scaleX":return`scaleX(${e})`;case"scaleY":return`scaleY(${e})`;case"scaleZ":return`scaleZ(${e})`;case"skewX":return`skewX(${e}deg)`;case"skewY":return`skewY(${e}deg)`;default:return null}}applyShine(t,e){t.dataset.shineBase||(t.dataset.shineBase=t.style.color||"currentColor");const s=t.dataset.shineBase,n=-20+e*140,r=t.style;r.color="transparent",r.backgroundImage=`linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${s}, ${s})`,r.backgroundSize="250% 100%, 100% 100%",r.backgroundPosition=`${n}% 0, 0 0`,r.backgroundRepeat="no-repeat",r.webkitBackgroundClip="text",r.backgroundClip="text"}applyStyleProperty(t,e,s){let n;if(t.namespaceURI===Ei&&e in Gt){const o=Array.isArray(s)?s.join(", "):String(s);t.style[Gt[e]]=o;return}else e==="fill"&&t.dataset?.elementType==="text"?n="color":n=Di[e]??e;let a;typeof s=="number"?zt.has(e)||zt.has(n)?a=`${s}px`:a=String(s):Array.isArray(s)?a=s.join(", "):a=s,t.style[n]=a}}class yt{media;offset;driftTolerance;constructor(t,e={}){this.media=t,this.offset=e.offset??0,this.driftTolerance=Math.max(0,e.driftTolerance??.15)}targetTime(t){return Math.max(0,t/1e3+this.offset)}update(t,e){const s=this.targetTime(t);e?(this.media.paused&&this.safePlay(),Math.abs(this.media.currentTime-s)>this.driftTolerance&&(this.media.currentTime=s)):(this.media.paused||this.media.pause(),this.media.currentTime!==s&&(this.media.currentTime=s))}seek(t){this.media.currentTime=this.targetTime(t)}setRate(t){this.media.playbackRate=t}dispose(){this.media.paused||this.media.pause()}safePlay(){const t=this.media.play();t&&typeof t.catch=="function"&&t.catch(()=>{})}}function Zt(i,t,e,s,n){const r=e-n;if(r<0){t.paused||t.pause(),t.currentTime=0;return}i.update(r,s)}class Tt{container;timeline=null;adapter;animationFrameId;lastTime;options;targets={};isDestroyed=!1;mediaSync;mediaTargets=[];symbolInstances=[];scenarioList=[];scenarioId;authored=new Map;markerList=[];listeners=new Set;playhead={time:0,iteration:0,direction:"forward"};stepping=!1;lastMarkerId=null;reducedQuery;onReducedChange=()=>this.applyReducedMotion();visibilityObserver;onScreen=!0;pausedByVisibility=!1;autoplayWhenSeen=!1;onDocumentVisibility=()=>this.updateVisibility();constructor(t,e={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=e,this.adapter=new j}async load(t){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(t)}async loadSource(t){let e;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load animation: ${s.statusText}`);e=await s.json()}else e=t;this.useDefinition(e),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(t){const e={...t.config};this.options.speed!==void 0&&(e.speed=this.options.speed),this.options.loop!==void 0&&(e.loop=this.options.loop),this.options.alternate!==void 0&&(e.alternate=this.options.alternate),this.timeline=tt({...t,config:e}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(t,e={}){if(t.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const s=new Set;for(const r of t){if(s.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);s.add(r.id)}const n=e.initial===void 0?t[0]:t.find(r=>r.id===e.initial);if(!n)throw new Error(`tinyfly: there is no scenario "${e.initial}"`);this.scenarioList=[...t],this.scenarioId=n.id,await this.loadSource(n.timeline)}get scenarios(){return this.scenarioList.map(t=>({id:t.id,label:t.label??t.id}))}get scenario(){return this.scenarioId}setScenario(t){const e=this.scenarioList.find(o=>o.id===t);if(!e||!this.timeline)return!1;if(t===this.scenarioId)return!0;const s=this.isPlaying,n=this.currentTime>=this.duration-.5,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=t,this.useDefinition(e.timeline),this.lastMarkerId=null;let a=0;return this.reducedMotion||n?a=this.duration:r!==void 0&&(a=this.markers.find(o=>o.id===r)?.time??0),this.seek(a),s&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(t){if(this.authored.has(t))return;const e={style:t.getAttribute("style")};t.children.length===0&&(e.text=t.textContent??"");const s=t.tagName.toLowerCase()==="path"?t:t.querySelector("path");s&&(e.path={element:s,d:s.getAttribute("d")}),this.authored.set(t,e)}restoreAuthored(){for(const[t,e]of this.authored){e.style===null?t.removeAttribute("style"):t.setAttribute("style",e.style),e.text!==void 0&&t.textContent!==e.text&&(t.textContent=e.text),e.path&&(e.path.d===null?e.path.element.removeAttribute("d"):e.path.element.setAttribute("d",e.path.d));const s=t.dataset;s&&delete s.shineBase}}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notify(){for(const t of this.listeners)t()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const t=this.currentTime;let e;for(const s of this.markers)if(s.time<=t+.5)e=s;else break;return e}caption(t,e){const s=t?this.markers.find(a=>a.id===t):this.currentMarker;if(!s)return;const n=e??this.language(),r=a=>a?.[n]?.[s.id]??a?.[n.split("-")[0]]?.[s.id];return r(this.options.captions)??r(this.timeline?.captions)??s.label}next(){if(!this.timeline)return;const t=this.currentTime,e=this.markers.find(s=>s.time>t+.5);if(this.reducedMotion){this.seek(e?e.time:this.duration);return}t>=this.duration-.5||(this.stepping=e!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const t=this.currentTime,e=[...this.markers].reverse().find(s=>s.time<t-.5);this.pause(),this.seek(e?e.time:0)}goToMarker(t){const e=this.markers.find(s=>s.id===t);e&&(this.pause(),this.seek(e.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const t=this.options.initialFrame??"start";if(t==="none")return;const e=t==="end"?this.timeline.duration:t==="start"?0:t;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,e))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(e=>{for(const s of e)this.onScreen=s.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const t=this.container.getBoundingClientRect?.();t&&(t.width>0||t.height>0)&&(this.onScreen=t.bottom>0&&t.top<window.innerHeight&&t.right>0&&t.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const t=this.onScreen&&document.visibilityState!=="hidden";!t&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):t&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const t=this.currentMarker,e=t?.id;e!==this.lastMarkerId&&(this.lastMarkerId=e,this.options.onMarker(t))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(e=>{const s=e,n=Number(s.getAttribute("data-tinyfly-start")??"0")||0,r=s.getAttribute("data-volume");r!==null&&(s.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:s,startTime:n,sync:new yt(s)})})}syncAllMedia(t,e){for(const s of this.mediaTargets)Zt(s.sync,s.el,t,e,s.startTime)}loadFromString(t){const e=JSON.parse(t);this.load(e)}registerTarget(t,e){if(typeof e=="string"){const s=this.container.querySelector(e);s&&(this.rememberAuthored(s),this.targets[t]=s,this.adapter.registerTarget(t,s))}else this.rememberAuthored(e),this.targets[t]=e,this.adapter.registerTarget(t,e)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(e=>{const s=e.closest("[data-tinyfly-symbol]");if(s&&s!==e)return;const n=e.getAttribute("data-tinyfly");n&&this.registerTarget(n,e)}),this.timeline&&new Set(this.timeline.tracks.map(s=>s.target)).forEach(s=>{if(!this.targets[s]){const n=this.container.querySelector(`[data-tinyfly="${s}"]`)||this.container.querySelector(`.${s}`)||this.container.querySelector(`#${s}`);n&&this.registerTarget(s,n)}})}setupSymbolInstances(){this.symbolInstances=[];const t=this.options.symbols;if(!t||t.length===0)return;const e=new Map(t.map(s=>[s.id,s]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const n=s.getAttribute("data-tinyfly-symbol");if(!n)return;const r=e.get(n);if(!r||!r.timeline.tracks?.length)return;const a=new j;s.querySelectorAll("[data-tinyfly]").forEach(o=>{const c=o.getAttribute("data-tinyfly");c&&a.registerTarget(c,o)}),this.symbolInstances.push({adapter:a,timeline:tt(r.timeline)})})}attachMedia(t,e){this.mediaSync=new yt(t,e),this.timeline&&(this.mediaSync.setRate(this.timeline.speed),this.mediaSync.update(this.timeline.currentTime,this.isPlaying))}detachMedia(){this.mediaSync?.dispose(),this.mediaSync=void 0}play(){!this.timeline||this.isDestroyed||(this.autoplayWhenSeen=!1,this.stepping=this.options.stepMode===!0,this.startPlaying())}startPlaying(){if(!this.timeline||this.isDestroyed)return;const t=this.timeline.playbackState==="idle";this.timeline.play(),t&&this.timeline.currentTime===0&&this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.update(this.timeline.currentTime,!0),this.syncAllMedia(this.timeline.currentTime,!0),this.startAnimationLoop(),this.notify()}pause(){this.timeline&&(this.stepping=!1,this.timeline.pause(),this.notify(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1),this.stopAnimationLoop())}stop(){this.timeline&&(this.timeline.stop(),this.stopAnimationLoop(),this.applyState(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1))}seek(t){this.timeline&&(this.timeline.seek(t),this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.seek(this.timeline.currentTime),this.syncAllMedia(this.timeline.currentTime,this.isPlaying))}setSpeed(t){this.timeline&&(this.timeline.speed=t,this.mediaSync?.setRate(t))}reverse(){this.timeline&&this.timeline.reverse()}get currentTime(){return this.timeline?.currentTime??0}get state(){return this.timeline?.getStateAtTime(this.timeline.currentTime)}get duration(){return this.timeline?.duration??0}get isPlaying(){return this.timeline?.playbackState==="playing"}destroy(){this.isDestroyed=!0,this.stopAnimationLoop(),this.reducedQuery?.removeEventListener?.("change",this.onReducedChange),this.visibilityObserver?.disconnect(),typeof document<"u"&&document.removeEventListener("visibilitychange",this.onDocumentVisibility),this.mediaSync?.dispose(),this.mediaSync=void 0;for(const t of this.mediaTargets)t.el.paused||t.el.pause();this.mediaTargets=[],this.adapter.clearTargets();for(const t of this.symbolInstances)t.adapter.clearTargets();this.symbolInstances=[],this.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=e=>{if(this.isDestroyed||!this.timeline)return;const s=e-(this.lastTime??e);this.lastTime=e;const n=this.playhead;this.timeline.tick(s),this.stopAtMarker(n),this.applyState();const r=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,r),this.syncAllMedia(this.timeline.currentTime,r),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(t):(this.animationFrameId=void 0,this.notify())};this.animationFrameId=requestAnimationFrame(t)}stopAtMarker(t){const e=this.timeline,s={time:e.currentTime,iteration:e.loopIteration,direction:e.direction};this.playhead=s;const n=this.markers;if(n.length===0)return;const{crossings:r}=mi(n.map(a=>a.time),t,s,{duration:e.duration,alternate:e.config.alternate===!0,holding:e.repeatDelayRemaining>0});for(const a of r){if(a.kind!=="event")continue;const o=n[a.index];if(this.stepping||o.pause){this.stepping=!1,e.pause(),e.seek(o.time),this.playhead={time:o.time,iteration:e.loopIteration,direction:e.direction};return}}}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}applyState(){if(!this.timeline)return;const t=this.timeline.currentTime;this.adapter.applyState(this.timeline.getStateAtTime(t)),this.announceMarker(),this.notify();for(const e of this.symbolInstances){const s=e.timeline.duration;e.adapter.applyState(e.timeline.getStateAtTime(s>0?t%s:t))}}}async function Bi(i,t,e={}){const s=new Tt(i,{...e,autoplay:!0});return await s.load(t),s}function Oi(i,t={}){return new Tt(i,t)}class Kt{container;containerA;containerB;adapterA;adapterB;timelineA=null;timelineB=null;symbolDefs=new Map;nestedByAdapter=new Map;sequence=null;options;_currentSceneIndex=0;_state="idle";_isPlaying=!1;_isDestroyed=!1;loopIteration=0;animationFrameId;lastTime;transitionTimer;constructor(t,e={}){if(typeof t=="string"){const s=document.querySelector(t);if(!s)throw new Error(`Container not found: ${t}`);this.container=s}else this.container=t;this.options=e,this.container.style.position="relative",this.container.style.overflow="hidden",this.containerA=this.createSceneContainer(),this.containerB=this.createSceneContainer(),this.container.appendChild(this.containerA),this.container.appendChild(this.containerB),this.containerB.style.visibility="hidden",this.adapterA=new j,this.adapterB=new j}async load(t){let e;if(typeof t=="string"){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to load sequence: ${s.statusText}`);e=await s.json()}else e=t;this.sequence=e,this.symbolDefs.clear();for(const s of e.symbols??[])s.timeline?.tracks?.length&&this.symbolDefs.set(s.id,s.timeline);this.container.style.width=`${e.canvas.width}px`,this.container.style.height=`${e.canvas.height}px`,e.scenes.length>0&&(this.renderScene(e.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(e.scenes[0])),this.options.autoplay&&this.play()}play(){if(!(!this.sequence||this._isDestroyed)&&this.sequence.scenes.length!==0){if(this._isPlaying=!0,this._state==="idle"){if(this._state="playing-scene",this._currentSceneIndex=0,this.timelineA)this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play();else{this.onSceneComplete();return}this.options.onSceneChange?.(0)}else this._state==="playing-scene"&&this.timelineA&&this.timelineA.play();this.startAnimationLoop()}}pause(){this._isPlaying&&(this._isPlaying=!1,this.timelineA&&this.timelineA.pause(),this.timelineB&&this.timelineB.pause(),this.stopAnimationLoop())}stop(){if(this._isPlaying=!1,this._state="idle",this._currentSceneIndex=0,this.loopIteration=0,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.stopAnimationLoop(),this.sequence&&this.sequence.scenes.length>0&&(this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this.renderScene(this.sequence.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(this.sequence.scenes[0]),this.timelineA)){const t=this.timelineA.getStateAtTime(0);this.adapterA.applyState(t),this.applyNested(this.adapterA,0)}}goToScene(t){if(!this.sequence||t<0||t>=this.sequence.scenes.length)return;const e=this._isPlaying;this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this._currentSceneIndex=t,this._state=e?"playing-scene":"idle",this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB);const s=this.sequence.scenes[t];if(this.renderScene(s,this.containerA,this.adapterA),this.timelineA=this.createTimeline(s),this.options.onSceneChange?.(t),e)this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play(),this.startAnimationLoop()):this.onSceneComplete();else if(this.timelineA){const n=this.timelineA.getStateAtTime(0);this.adapterA.applyState(n),this.applyNested(this.adapterA,0)}}destroy(){this._isDestroyed=!0,this._isPlaying=!1,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.adapterA.clearTargets(),this.adapterB.clearTargets();for(const t of this.nestedByAdapter.values())for(const e of t)e.adapter.clearTargets();this.nestedByAdapter.clear(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.timelineA=null,this.timelineB=null,this.containerA.parentNode&&this.containerA.remove(),this.containerB.parentNode&&this.containerB.remove(),this.sequence=null}get currentSceneIndex(){return this._currentSceneIndex}get sceneCount(){return this.sequence?.scenes.length??0}get isPlaying(){return this._isPlaying}get state(){return this._state}createSceneContainer(){const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.width="100%",t.style.height="100%",t}renderScene(t,e,s){e.innerHTML="",s.clearTargets();const n=document.createElement("div");n.style.cssText="position:absolute;inset:0;transform-origin:center center",n.setAttribute("data-tinyfly","Camera"),e.appendChild(n),s.registerTarget("Camera",n);for(const r of t.elements){if(!r.html)continue;const a=document.createElement("div");a.innerHTML=r.html.trim();const o=a.firstElementChild;if(o){n.appendChild(o);const c=o.getAttribute("data-tinyfly");c&&s.registerTarget(c,o)}}this.setupNested(n,s)}setupNested(t,e){const s=[];t.querySelectorAll("[data-tinyfly-symbol]").forEach(n=>{const r=n.getAttribute("data-tinyfly-symbol");if(!r)return;const a=this.symbolDefs.get(r);if(!a)return;const o=new j;n.querySelectorAll("[data-tinyfly]").forEach(c=>{const h=c.getAttribute("data-tinyfly");h&&o.registerTarget(h,c)}),s.push({adapter:o,timeline:tt(a)})}),s.length?this.nestedByAdapter.set(e,s):this.nestedByAdapter.delete(e)}applyNested(t,e){const s=this.nestedByAdapter.get(t);if(s)for(const n of s){const r=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(r>0?e%r:e))}}clearContainer(t){t.innerHTML=""}createTimeline(t){return t.timeline?tt(t.timeline):null}onSceneComplete(){if(this._isDestroyed||!this.sequence)return;const t=this._currentSceneIndex+1;if(t>=this.sequence.scenes.length){const e=this.options.loop??this.sequence.loop??0;e===-1||e>0&&this.loopIteration<e-1?(this.loopIteration++,this.beginTransitionTo(0)):(this._isPlaying=!1,this._state="idle",this.stopAnimationLoop(),this.options.onComplete?.())}else this.beginTransitionTo(t)}beginTransitionTo(t){if(!this.sequence||this._isDestroyed)return;const e=this.sequence.scenes[t],s=e.transition;if(s.type==="none"||s.duration<=0){this.switchToScene(t);return}this._state="transitioning",this.containerB.style.visibility="visible",this.renderScene(e,this.containerB,this.adapterB),this.timelineB=this.createTimeline(e),this.timelineB&&this.timelineB.play(),this.applyTransition(s.type,s.duration),this.transitionTimer=window.setTimeout(()=>{this.finishTransition(t)},s.duration)}applyTransition(t,e){const s=`${e}ms`,n="ease-in-out";switch(this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),t){case"fade":this.containerB.style.opacity="0";break;case"slide-left":this.containerB.style.transform="translateX(100%)";break;case"slide-right":this.containerB.style.transform="translateX(-100%)";break;case"slide-up":this.containerB.style.transform="translateY(100%)";break;case"slide-down":this.containerB.style.transform="translateY(-100%)";break}switch(this.containerB.offsetHeight,this.containerA.style.transition=`opacity ${s} ${n}, transform ${s} ${n}`,this.containerB.style.transition=`opacity ${s} ${n}, transform ${s} ${n}`,t){case"fade":this.containerA.style.opacity="0",this.containerB.style.opacity="1";break;case"slide-left":this.containerA.style.transform="translateX(-100%)",this.containerB.style.transform="translateX(0)";break;case"slide-right":this.containerA.style.transform="translateX(100%)",this.containerB.style.transform="translateX(0)";break;case"slide-up":this.containerA.style.transform="translateY(-100%)",this.containerB.style.transform="translateY(0)";break;case"slide-down":this.containerA.style.transform="translateY(100%)",this.containerB.style.transform="translateY(0)";break}}resetTransitionStyles(t){t.style.transition="",t.style.opacity="1",t.style.transform=""}finishTransition(t){this.transitionTimer=void 0,this.timelineA&&(this.timelineA.stop(),this.timelineA=null),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.containerA;this.containerA=this.containerB,this.containerB=e;const s=this.adapterA;this.adapterA=this.adapterB,this.adapterB=s,this.timelineA=this.timelineB,this.timelineB=null,this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.playbackState!=="playing"&&this.timelineA.play()):this.onSceneComplete()}switchToScene(t){if(!this.sequence||this._isDestroyed)return;this.timelineA&&this.timelineA.stop(),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.sequence.scenes[t];this.renderScene(e,this.containerA,this.adapterA),this.timelineA=this.createTimeline(e),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play()):this.onSceneComplete()}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=e=>{if(this._isDestroyed||!this._isPlaying)return;const s=e-(this.lastTime??e);if(this.lastTime=e,this.timelineA&&this.timelineA.playbackState==="playing"){this.timelineA.tick(s);const n=this.timelineA.getStateAtTime(this.timelineA.currentTime);this.adapterA.applyState(n),this.applyNested(this.adapterA,this.timelineA.currentTime)}if(this._state==="transitioning"&&this.timelineB&&this.timelineB.playbackState==="playing"){this.timelineB.tick(s);const n=this.timelineB.getStateAtTime(this.timelineB.currentTime);this.adapterB.applyState(n),this.applyNested(this.adapterB,this.timelineB.currentTime)}this._isPlaying?this.animationFrameId=requestAnimationFrame(t):this.animationFrameId=void 0};this.animationFrameId=requestAnimationFrame(t)}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}}async function Li(i,t,e={}){const s=new Kt(i,{...e,autoplay:!0});return await s.load(t),s}const $i={type:"none",duration:0};v.DEFAULT_TRANSITION=$i,v.MediaSync=yt,v.TinyflyPlayer=Tt,v.TinyflySequencer=Kt,v.create=Oi,v.play=Bi,v.playSequence=Li,v.syncMediaElement=Zt,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -119,6 +119,14 @@ export interface Capabilities {
|
|
|
119
119
|
surfaceScript: Record<string, string>;
|
|
120
120
|
cameraShots: Record<string, string>;
|
|
121
121
|
teach: Record<string, string>;
|
|
122
|
+
/** `@algorisys/tinyfly/math`: maths figures, equations and lessons */
|
|
123
|
+
math: {
|
|
124
|
+
api: Record<string, string>;
|
|
125
|
+
items: Record<string, string>;
|
|
126
|
+
props: Record<string, string>;
|
|
127
|
+
functions: string[];
|
|
128
|
+
tex: string;
|
|
129
|
+
};
|
|
122
130
|
cli: Record<string, string>;
|
|
123
131
|
}
|
|
124
132
|
/** The catalog; pass a cast (or a persona's `cast`) to list its own actions and gaits too. */
|
|
@@ -5,6 +5,7 @@ import type { FrameInfo } from '../headless/video-scene';
|
|
|
5
5
|
import type { BodyPlan, Pose, Vec3 } from './rig/body-plan';
|
|
6
6
|
import { type SolvedHead, type ViewProjection } from './rig/skeleton';
|
|
7
7
|
import { type Look, type Pen, type PencilOptions } from './look/pen';
|
|
8
|
+
import { type IllustratedOptions, type ResolvedIllustration } from './look/illustrated-pen';
|
|
8
9
|
import { type OrganicBody, type OrganicBodyOptions } from './body/organic-body';
|
|
9
10
|
import { type OrganicBodyContours } from './body/organic-geometry';
|
|
10
11
|
import { type FaceOptions } from './head/face';
|
|
@@ -63,6 +64,8 @@ export interface CharacterOptions extends HeadLookOptions {
|
|
|
63
64
|
/** Opt-in organic contours, skin material and independent outline settings. */
|
|
64
65
|
body?: OrganicBodyOptions;
|
|
65
66
|
look?: Look;
|
|
67
|
+
/** The `illustrated` look's ink weight, taper, shadow and highlight (light defaults to the body's skin light) */
|
|
68
|
+
illustrated?: IllustratedOptions;
|
|
66
69
|
/** Feet to top of head, px (default 300) */
|
|
67
70
|
height?: number;
|
|
68
71
|
/** `bold` (default): head 30% of the height, line 4.5%. `thin`: head 24%, line 2.2%, as the reference sheets */
|
|
@@ -111,6 +114,7 @@ export interface Character {
|
|
|
111
114
|
figure: FigureStyle;
|
|
112
115
|
body?: OrganicBody;
|
|
113
116
|
look: Look;
|
|
117
|
+
illustrated: ResolvedIllustration;
|
|
114
118
|
height: number;
|
|
115
119
|
lineWidth: number;
|
|
116
120
|
ink: string;
|
|
@@ -39,6 +39,8 @@ export { meetHands, meetingSpacing, HAND_MEETINGS, embrace, embraceSpacing, EMBR
|
|
|
39
39
|
export * from './species/human-motion';
|
|
40
40
|
export type { BodyPlan, ChainSpec, BoneSpec, BoneAngles, ContactSpec, HeadSpec, Pose as CharacterPose, Vec3 } from './rig/body-plan';
|
|
41
41
|
export { createPen, ellipsePoints, type Pen, type Look, type PencilOptions, type PenOptions } from './look/pen';
|
|
42
|
+
export { resolveIllustration, type IllustratedOptions, type ResolvedIllustration } from './look/illustrated-pen';
|
|
43
|
+
export { illustrationTones, type IllustrationTones } from './look/illustration-color';
|
|
42
44
|
export { basicOutfit, type BasicOutfitOptions } from './wardrobe/basic-outfit';
|
|
43
45
|
export { outfitPreset, OUTFIT_PRESETS, type OutfitCategory } from './wardrobe/outfit-preset';
|
|
44
46
|
export * from './head';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Pen } from './pen';
|
|
2
|
+
/**
|
|
3
|
+
* The `illustrated` look: a clean pen drawn the way an illustrator inks and
|
|
4
|
+
* paints, from the same shapes every other look draws.
|
|
5
|
+
*
|
|
6
|
+
* - Ink has weight: an outline thickens on the side turned from the light and
|
|
7
|
+
* thins on the lit side, and open strokes (brows, mouths, folds, strands)
|
|
8
|
+
* taper at their ends like a brush.
|
|
9
|
+
* - Filled shapes are painted with form: a soft shadow band and a narrower
|
|
10
|
+
* core shadow on the side away from the light, and a highlight on the lit
|
|
11
|
+
* side, in tones mixed from the fill itself (see illustrationTones).
|
|
12
|
+
*
|
|
13
|
+
* Deterministic: everything follows from the points, the fill and the light.
|
|
14
|
+
*/
|
|
15
|
+
export interface IllustratedOptions {
|
|
16
|
+
/** Toward the light, screen space (default [-0.8, -0.6]: from the upper left) */
|
|
17
|
+
light?: [number, number];
|
|
18
|
+
/** How much ink thickens on the shadow side and thins on the lit side, 0..1 (default 0.6) */
|
|
19
|
+
weight?: number;
|
|
20
|
+
/** How much open strokes taper toward their ends, 0..1 (default 0.7) */
|
|
21
|
+
taper?: number;
|
|
22
|
+
/** Strength of the shadow and core-shadow bands, 0..1 (default 1) */
|
|
23
|
+
shadow?: number;
|
|
24
|
+
/** Strength of the lit-side highlight, 0..1 (default 0.6) */
|
|
25
|
+
highlight?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface ResolvedIllustration {
|
|
28
|
+
light: [number, number];
|
|
29
|
+
weight: number;
|
|
30
|
+
taper: number;
|
|
31
|
+
shadow: number;
|
|
32
|
+
highlight: number;
|
|
33
|
+
}
|
|
34
|
+
/** Every option filled in and checked; `light` defaults to the given one (a body's skin light). */
|
|
35
|
+
export declare function resolveIllustration(options?: IllustratedOptions, light?: [number, number]): ResolvedIllustration;
|
|
36
|
+
export declare function createIllustratedPen(ctx: CanvasRenderingContext2D, ink: string, lineWidth: number, style: ResolvedIllustration): Pen;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Painted tones for one fill colour, as an illustrator mixes them: shadows
|
|
3
|
+
* are not the fill with black added but deeper, more saturated and shifted
|
|
4
|
+
* toward red-violet (warm skin shades into rose, not grey); highlights are
|
|
5
|
+
* lighter and shifted toward a warm yellow. Pure functions of the colour.
|
|
6
|
+
*/
|
|
7
|
+
export interface IllustrationTones {
|
|
8
|
+
shadow: string;
|
|
9
|
+
core: string;
|
|
10
|
+
highlight: string;
|
|
11
|
+
}
|
|
12
|
+
/** The shadow, core-shadow and highlight tones for a fill; undefined for a fill that is not a colour. */
|
|
13
|
+
export declare function illustrationTones(fill: string): IllustrationTones | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Point } from '../../adapters/canvas/sketch';
|
|
2
|
+
import { type ResolvedIllustration } from './illustrated-pen';
|
|
2
3
|
/**
|
|
3
4
|
* The pen every part of a character is drawn with: its body, face, hair,
|
|
4
5
|
* clothes and props. A look is a pen, so whatever draws through it (the
|
|
@@ -9,11 +10,14 @@ import { type Point } from '../../adapters/canvas/sketch';
|
|
|
9
10
|
* few times a second, pressure that thins and thickens along each stroke,
|
|
10
11
|
* faint construction guides, and the odd rubbed-out earlier attempt.
|
|
11
12
|
* - `silhouette`: everything filled solid in the ink, for a readability check.
|
|
13
|
+
* - `illustrated`: inked and painted. Line weight follows the light, strokes
|
|
14
|
+
* taper like a brush, and fills get shadow, core shadow and highlight tones
|
|
15
|
+
* mixed from their own colour (see illustrated-pen.ts).
|
|
12
16
|
*
|
|
13
17
|
* Deterministic: the pencil's wobble and pressure are seeded by the seed, the
|
|
14
18
|
* boil frame and the stroke's place in the drawing order, never Math.random.
|
|
15
19
|
*/
|
|
16
|
-
export type Look = 'clean' | 'pencil' | 'silhouette';
|
|
20
|
+
export type Look = 'clean' | 'pencil' | 'silhouette' | 'illustrated';
|
|
17
21
|
export interface PencilOptions {
|
|
18
22
|
/** Largest wobble, px (default: 12% of the line width, at least 1) */
|
|
19
23
|
roughness?: number;
|
|
@@ -33,10 +37,18 @@ export interface Pen {
|
|
|
33
37
|
readonly ink: string;
|
|
34
38
|
/** A stroke through `points` whose width runs from `from` to `to` px */
|
|
35
39
|
limb(points: Point[], from: number, to: number): void;
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
/**
|
|
41
|
+
* An even stroke. `outside` says which side of it is the outside of a
|
|
42
|
+
* shape (+1 the right of the direction of travel, −1 the left), for looks
|
|
43
|
+
* whose ink weight follows the light; others ignore it.
|
|
44
|
+
*/
|
|
45
|
+
line(points: Point[], width: number, outside?: 1 | -1): void;
|
|
46
|
+
/**
|
|
47
|
+
* A closed shape: filled with `fill` (none when null) and outlined (not when
|
|
48
|
+
* `outline` is 0). `flat` keeps a look that paints form into fills from
|
|
49
|
+
* painting this one (an eye, a mouth: features with their own shading).
|
|
50
|
+
*/
|
|
51
|
+
shape(points: Point[], fill: string | null, outline: number, flat?: boolean): void;
|
|
40
52
|
/** An ellipse: filled with `fill` (none when null) and outlined */
|
|
41
53
|
ellipse(cx: number, cy: number, rx: number, ry: number, angle: number, fill: string | null, outline: number): void;
|
|
42
54
|
/** A filled dot in the ink */
|
|
@@ -53,6 +65,7 @@ export interface PenOptions {
|
|
|
53
65
|
seed: number;
|
|
54
66
|
time: number;
|
|
55
67
|
pencil?: PencilOptions;
|
|
68
|
+
illustrated?: ResolvedIllustration;
|
|
56
69
|
}
|
|
57
70
|
/** Points around an ellipse, from `start` radians, `turns` of a full turn. */
|
|
58
71
|
export declare function ellipsePoints(cx: number, cy: number, rx: number, ry: number, angle: number, start?: number, turns?: number, samples?: number): Point[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mount every `[data-tinyfly-math]` figure when the page is ready, if the
|
|
3
|
+
* script running now was loaded with `data-tinyfly-auto`. Call it at the top
|
|
4
|
+
* level of a bundle's entry: `document.currentScript` is only set while a
|
|
5
|
+
* classic script first runs.
|
|
6
|
+
*/
|
|
7
|
+
export declare function autoMountMathFromCurrentScript(): void;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { MathFigureSpec } from '../figure/figure-spec';
|
|
2
|
+
import { type MathProps } from '../figure/layout-figure';
|
|
3
|
+
/**
|
|
4
|
+
* A figure the reader changes by hand: sliders bound to number values, and
|
|
5
|
+
* handles to drag on vector values or on a matrix's columns (drag î and ĵ to
|
|
6
|
+
* build the matrix). Every change re-lays the figure out from its values, so
|
|
7
|
+
* what the reader sees is exactly what the same values give in a video.
|
|
8
|
+
*
|
|
9
|
+
* mathExplorable(element, linearMapFigure(), {
|
|
10
|
+
* drag: [{ matrix: 'M', column: 0 }, { matrix: 'M', column: 1 }],
|
|
11
|
+
* sliders: [{ value: 'k', min: 0, max: 4, step: 0.1, label: 'k' }],
|
|
12
|
+
* })
|
|
13
|
+
*/
|
|
14
|
+
export interface SliderControl {
|
|
15
|
+
/** A number value of the figure */
|
|
16
|
+
value: string;
|
|
17
|
+
min: number;
|
|
18
|
+
max: number;
|
|
19
|
+
step?: number;
|
|
20
|
+
/** What the reader sees beside the slider (default the value's name) */
|
|
21
|
+
label?: string;
|
|
22
|
+
}
|
|
23
|
+
/** A vector value's tip, or one column of a matrix value (0: where î lands, 1: ĵ). */
|
|
24
|
+
export type DragHandle = {
|
|
25
|
+
vector: string;
|
|
26
|
+
} | {
|
|
27
|
+
matrix: string;
|
|
28
|
+
column: 0 | 1;
|
|
29
|
+
};
|
|
30
|
+
export interface ExplorableOptions {
|
|
31
|
+
sliders?: SliderControl[];
|
|
32
|
+
drag?: DragHandle[];
|
|
33
|
+
/** Round dragged coordinates to this step in world units (default 0.1; 0 for none) */
|
|
34
|
+
snap?: number;
|
|
35
|
+
/** Called with the values after every change */
|
|
36
|
+
onChange?: (values: MathProps) => void;
|
|
37
|
+
}
|
|
38
|
+
export interface MathExplorable {
|
|
39
|
+
/** Current values */
|
|
40
|
+
readonly values: MathProps;
|
|
41
|
+
/** Change a value, as the reader would */
|
|
42
|
+
set(name: string, value: number | number[]): void;
|
|
43
|
+
/** Remove the controls and listeners (the drawing stays) */
|
|
44
|
+
destroy(): void;
|
|
45
|
+
}
|
|
46
|
+
export declare function mathExplorable(element: HTMLElement, figure: MathFigureSpec, options?: ExplorableOptions): MathExplorable;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type MountedEmbed, type MountOptions } from '../../embed/mount';
|
|
2
|
+
import type { TinyflyPlayer } from '../../player/player';
|
|
3
|
+
import type { MathFigureSpec } from '../figure/figure-spec';
|
|
4
|
+
/**
|
|
5
|
+
* Maths figures in lesson pages, stepped like any tinyfly embed:
|
|
6
|
+
*
|
|
7
|
+
* <figure data-tinyfly-math data-target="fig" data-options='{"stepMode": true}'>
|
|
8
|
+
* <script type="application/json" data-tinyfly-figure>{ …MathFigureSpec… }</script>
|
|
9
|
+
* <script type="application/json" data-tinyfly-timeline>{ …timeline JSON… }</script>
|
|
10
|
+
* <figcaption>A shear keeps î and slides ĵ.</figcaption>
|
|
11
|
+
* </figure>
|
|
12
|
+
*
|
|
13
|
+
* The figure is drawn into an `<svg>` it creates, and redrawn from the
|
|
14
|
+
* timeline's values (tracks whose target is `data-target`, default `fig`)
|
|
15
|
+
* every time the player moves: playing, stepping, seeking, or showing the
|
|
16
|
+
* final frame under reduced motion. Everything else (markers, step controls,
|
|
17
|
+
* captions, questions, scenarios, pausing off screen) is the ordinary embed.
|
|
18
|
+
*/
|
|
19
|
+
export interface MountedMathFigure {
|
|
20
|
+
element: HTMLElement;
|
|
21
|
+
/** The embed's player; absent for a still figure with no timeline */
|
|
22
|
+
player?: TinyflyPlayer;
|
|
23
|
+
controls?: MountedEmbed['controls'];
|
|
24
|
+
figure: MathFigureSpec;
|
|
25
|
+
/** Draw now (the player redraws on its own; call after changing values yourself) */
|
|
26
|
+
redraw(): void;
|
|
27
|
+
}
|
|
28
|
+
/** Mount one maths figure (idempotent). */
|
|
29
|
+
export declare function mountMath(element: HTMLElement, options?: MountOptions): Promise<MountedMathFigure | undefined>;
|
|
30
|
+
/** Mount every `[data-tinyfly-math]` figure in `root` (default the document). */
|
|
31
|
+
export declare function mountAllMath(root?: ParentNode, options?: MountOptions): Promise<MountedMathFigure[]>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Expression } from './parse-expression';
|
|
2
|
+
/** d/d`variable` of `e`, simplified. Throws for functions with no derivative rule (floor, round …). */
|
|
3
|
+
export declare function differentiate(e: Expression, variable?: string): Expression;
|
|
4
|
+
/** The n-th derivative (n = 0 gives the expression itself). */
|
|
5
|
+
export declare function nthDerivative(e: Expression, n: number, variable?: string): Expression;
|
|
6
|
+
/** Back to source text, for showing or caching a derived expression. */
|
|
7
|
+
export declare function expressionToString(e: Expression): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Expression } from './parse-expression';
|
|
2
|
+
/** Variable values by name: `{ x: 1.5, k: 2 }`. */
|
|
3
|
+
export type Scope = Record<string, number>;
|
|
4
|
+
/**
|
|
5
|
+
* The value of a parsed expression for the given variables. Throws when a
|
|
6
|
+
* name is neither in `scope` nor a constant. Results can be NaN or ±Infinity
|
|
7
|
+
* (`1/0`, `sqrt(-1)`): plotting treats those as gaps.
|
|
8
|
+
*/
|
|
9
|
+
export declare function evaluate(expression: Expression, scope?: Scope): number;
|
|
10
|
+
/**
|
|
11
|
+
* A function of one variable from source text, parsed once:
|
|
12
|
+
* `compile('sin(k x)', 'x')` gives `(x, scope) => number`. Parameters other
|
|
13
|
+
* than the variable come from `scope` at call time.
|
|
14
|
+
*/
|
|
15
|
+
export declare function compile(source: string, variable?: string): (value: number, scope?: Scope) => number;
|
|
16
|
+
/**
|
|
17
|
+
* The n-th derivative of a function of one variable from source text,
|
|
18
|
+
* differentiated symbolically once and cached: `compileDerivative('sin(x)', 1)`
|
|
19
|
+
* evaluates cos(x). n = 0 is the function itself.
|
|
20
|
+
*/
|
|
21
|
+
export declare function compileDerivative(source: string, n: number, variable?: string): (value: number, scope?: Scope) => number;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small, safe expression language for functions written as data:
|
|
3
|
+
* `"sin(x) * k"`, `"x^2 - 1"`, `"exp(-x^2 / 2) / sqrt(2 * pi)"`.
|
|
4
|
+
*
|
|
5
|
+
* - Numbers (`2`, `0.5`, `1e-3`), names (`x`, `t`, any parameter), `pi`, `e`
|
|
6
|
+
* - `+ - * / ^` with the usual precedence; `^` binds right (`2^3^2` is 2^9),
|
|
7
|
+
* and tighter than unary minus (`-x^2` is −(x²))
|
|
8
|
+
* - Function calls from a fixed list (see FUNCTIONS); nothing else is callable
|
|
9
|
+
* - Implicit multiplication between a number and a name or bracket: `2x`, `3(x + 1)`
|
|
10
|
+
*
|
|
11
|
+
* Parsing builds a plain AST that can be evaluated many times. Nothing is ever
|
|
12
|
+
* passed to `eval` or `Function`, so an expression can only read the names it
|
|
13
|
+
* is given and call the listed functions.
|
|
14
|
+
*/
|
|
15
|
+
export type Expression = {
|
|
16
|
+
type: 'number';
|
|
17
|
+
value: number;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'name';
|
|
20
|
+
name: string;
|
|
21
|
+
} | {
|
|
22
|
+
type: 'unary';
|
|
23
|
+
operator: '-' | '+';
|
|
24
|
+
operand: Expression;
|
|
25
|
+
} | {
|
|
26
|
+
type: 'binary';
|
|
27
|
+
operator: '+' | '-' | '*' | '/' | '^';
|
|
28
|
+
left: Expression;
|
|
29
|
+
right: Expression;
|
|
30
|
+
} | {
|
|
31
|
+
type: 'call';
|
|
32
|
+
name: string;
|
|
33
|
+
args: Expression[];
|
|
34
|
+
};
|
|
35
|
+
/** Callable functions and how many arguments each takes. */
|
|
36
|
+
export declare const FUNCTIONS: Record<string, {
|
|
37
|
+
arity: number;
|
|
38
|
+
apply: (...args: number[]) => number;
|
|
39
|
+
}>;
|
|
40
|
+
export declare const CONSTANTS: Record<string, number>;
|
|
41
|
+
export declare class ExpressionError extends Error {
|
|
42
|
+
readonly source: string;
|
|
43
|
+
/** 0-based index into the source */
|
|
44
|
+
readonly position: number;
|
|
45
|
+
constructor(message: string, source: string, position: number);
|
|
46
|
+
}
|
|
47
|
+
/** Parse `source` into an AST; throws an ExpressionError naming the position. */
|
|
48
|
+
export declare function parseExpression(source: string): Expression;
|
|
49
|
+
/** Every variable name the expression reads (constants excluded), sorted. */
|
|
50
|
+
export declare function expressionNames(expression: Expression): string[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Scope } from '../expr/evaluate';
|
|
2
|
+
import type { MathItem } from './figure-spec';
|
|
3
|
+
import { type Values } from './item-context';
|
|
4
|
+
/**
|
|
5
|
+
* Numbers items work out from the figure's values, so TeX can show them with
|
|
6
|
+
* `\val{…}`: a tangent's `ID.slope`, `ID.x` and `ID.y`; a Riemann sum's
|
|
7
|
+
* `ID.sum`, `ID.exact` (the integral) and `ID.n`; an area's `ID.value`; a
|
|
8
|
+
* point on a curve's `ID.x` and `ID.y`; a Taylor polynomial's `ID.order` and `ID.degree`.
|
|
9
|
+
* Pure: worked out again from the values at every moment.
|
|
10
|
+
*/
|
|
11
|
+
/** ∫ f from a to b by Simpson's rule (512 panels): accurate for smooth teaching functions. */
|
|
12
|
+
export declare function integrate(f: (x: number) => number, a: number, b: number, panels?: number): number;
|
|
13
|
+
/** The sample points of a Riemann sum's pieces: [left, right, height] each. */
|
|
14
|
+
export declare function riemannPieces(f: (x: number) => number, a: number, b: number, n: number, rule: 'left' | 'right' | 'midpoint' | 'trapezoid'): [number, number, number, number][];
|
|
15
|
+
/** How many Riemann pieces a value asks for: a whole number from 1 to 400. */
|
|
16
|
+
export declare const pieceCount: (n: number) => number;
|
|
17
|
+
export declare function derivedValues(items: MathItem[], values: Values, scope: Scope): Scope;
|