@algorisys/tinyfly 0.95.0 → 0.97.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.
@@ -1,5 +1,5 @@
1
- (function(y,De){typeof exports=="object"&&typeof module<"u"?De(exports):typeof define=="function"&&define.amd?define(["exports"],De):(y=typeof globalThis<"u"?globalThis:y||self,De(y.tinyfly=y.tinyfly||{}))})(this,(function(y){"use strict";function De(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function yn(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const Ei=2;function Ai(t){return t.some(e=>e.interpolation!==void 0)?2:1}function es(t){return t.property==="text"&&"textConfig"in t}function ie(t){return t.kind==="inertia"&&"inertia"in t}function oe(t){return t.kind==="spring"&&"spring"in t}function Pi(t){return t.property==="motionPath"&&"motionPathConfig"in t}function of(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"angle"in t}function la(t){return"keyframes"in t}class rf{_currentTime=0;_isRunning=!1;onTick=null;get currentTime(){return this._currentTime}get isRunning(){return this._isRunning}start(){this._isRunning=!0}stop(){this._isRunning=!1}tick(e){this._currentTime+=e,this.onTick?.(e,this._currentTime)}reset(){this._currentTime=0}seek(e){this._currentTime=e}}class af{_currentTime=0;_isRunning=!1;_lastFrameTime=null;_rafId=null;_speed;onTick=null;constructor(e={}){this._speed=e.speed??1}get currentTime(){return this._currentTime}get isRunning(){return this._isRunning}get speed(){return this._speed}set speed(e){this._speed=e}start(){this._isRunning||(this._isRunning=!0,this._lastFrameTime=null,this._scheduleFrame())}stop(){this._isRunning=!1,this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null)}reset(){this._currentTime=0,this._lastFrameTime=null}seek(e){this._currentTime=e}_scheduleFrame(){this._rafId=requestAnimationFrame(this._onFrame.bind(this))}_onFrame(e){if(this._isRunning){if(this._lastFrameTime!==null){const s=(e-this._lastFrameTime)*this._speed;this._currentTime+=s,this.onTick?.(s,this._currentTime)}this._lastFrameTime=e,this._scheduleFrame()}}}function ca(t,e){if(!(e>0))return t;const n=1e3/e;return Math.floor(t/n+1e-9)*n}function $i(t,e,n="start"){if(e<=1)return 0;if(typeof n=="number"){const s=Math.max(0,Math.min(e-1,n));return Math.abs(t-s)}switch(n){case"end":return e-1-t;case"center":return Math.abs(t-(e-1)/2);case"edges":return(e-1)/2-Math.abs(t-(e-1)/2);default:return t}}function xi(t,e="start"){if(t<=1)return 0;let n=0;for(let s=0;s<t;s++)n=Math.max(n,$i(s,t,e));return n}function ns(t,e,n){if(n.offsets)return n.offsets[t]??0;const s=n.from??"start",i=$i(t,e,s);if(n.amount!==void 0){const o=xi(e,s);return o===0?0:n.amount*i/o}return n.each!==void 0?n.each*i:0}function ss(t,e){return Array.from({length:t},(n,s)=>ns(s,t,e))}function bn(t,e){return t<=1?0:Math.max(...ss(t,e))}const Ne=1,_i=6e4,is=_i/Ne,Nt={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1},os={gentle:{stiffness:120,damping:18,mass:1},default:{stiffness:180,damping:12,mass:1},snappy:{stiffness:280,damping:20,mass:1},bouncy:{stiffness:220,damping:8,mass:1},wobbly:{stiffness:180,damping:5,mass:1},stiff:{stiffness:400,damping:30,mass:1}};class wn{from;to;stiffness;damping;mass;restDelta;restSpeed;distance;samples;velocity;settledStep=null;constructor(e){this.from=e.from,this.to=e.to,this.stiffness=e.stiffness??Nt.stiffness,this.damping=e.damping??Nt.damping,this.mass=e.mass??Nt.mass,this.restDelta=e.restDelta??Nt.restDelta,this.restSpeed=e.restSpeed??Nt.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=e.velocity??Nt.velocity,this.isAtRest(this.from)&&(this.settledStep=0)}isAtRest(e){return Math.abs(e-this.to)<this.restDelta*this.distance&&Math.abs(this.velocity)<this.restSpeed*this.distance}valueAt(e){if(e<=0)return this.from;const n=Math.floor(e/Ne);if(this.simulateTo(n+1),this.settledStep!==null&&n>=this.settledStep)return this.to;const s=this.samples[Math.min(n,this.samples.length-1)],i=this.samples[Math.min(n+1,this.samples.length-1)],o=e/Ne-n;return s+(i-s)*o}settleTime(){return this.simulateTo(is+1),this.settledStep!==null?this.settledStep*Ne:_i}simulateTo(e){if(this.settledStep!==null)return;const n=Math.min(e,is+1),s=Ne/1e3;for(;this.samples.length<n;){const i=this.samples[this.samples.length-1],o=i-this.to,r=-this.stiffness*o,a=-this.damping*this.velocity,l=(r+a)/this.mass;this.velocity+=l*s;const c=i+this.velocity*s;if(this.samples.push(c),this.isAtRest(c)){this.settledStep=this.samples.length-1;return}}this.samples.length>is&&(this.settledStep=is)}}function lf(t,e){return new wn(t).valueAt(e)}function ha(t){return new wn(t).settleTime()}function cf(t){const e=t.stiffness??Nt.stiffness,n=t.damping??Nt.damping,s=t.mass??Nt.mass;return n<2*Math.sqrt(e*s)}function hf(t){const e=t.stiffness??Nt.stiffness,n=t.mass??Nt.mass;return 2*Math.sqrt(e*n)}const Ii=4,uf=.002,df=1e-4,ua=6e4;function rs(t){const e=t.friction??Ii;return e>0?e:Ii}function kn(t){return t.from+t.velocity/rs(t)}function ff(t,e){if(e===void 0)return t;if(typeof e=="number")return e>0?Math.round(t/e)*e:t;if(e.length===0)return t;let n=e[0];for(const s of e)Math.abs(s-t)<Math.abs(n-t)&&(n=s);return n}function Be(t){let e=ff(kn(t),t.end);return t.min!==void 0&&(e=Math.max(t.min,e)),t.max!==void 0&&(e=Math.min(t.max,e)),e}function We(t){const e=Math.abs(Be(t)-t.from);if(e===0)return 0;const n=t.restDelta??Math.max(df,e*uf);if(n>=e)return 0;const s=Math.log(e/n)/rs(t);return Math.min(ua,s*1e3)}function as(t,e){if(e<=0)return t.from;const n=Be(t);if(e>=We(t))return n;const s=rs(t);return t.from+(n-t.from)*(1-Math.exp(-s*e/1e3))}function pf(t,e){const n=rs(t),s=Be(t);return e>=We(t)?0:(s-t.from)*n*Math.exp(-n*Math.max(0,e)/1e3)}const ls=t=>t,da=t=>t*t,fa=t=>1-(1-t)*(1-t),pa=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,Oi=t=>t*t*t,Ci=t=>1-Math.pow(1-t,3),vn=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,ga=Oi,ma=Ci,ya=vn,gf={linear:ls,"ease-in":ga,"ease-out":ma,"ease-in-out":ya,"ease-in-quad":da,"ease-out-quad":fa,"ease-in-out-quad":pa,"ease-in-cubic":Oi,"ease-out-cubic":Ci,"ease-in-out-cubic":vn};function ba(t){const[e,n,s,i]=t,o=3*e,r=3*(s-e)-o,a=1-o-r,l=3*n,c=3*(i-n)-l,h=1-l-c,u=p=>((a*p+r)*p+o)*p,d=p=>((h*p+c)*p+l)*p,f=p=>(3*a*p+2*r)*p+o,g=p=>{let m=p;for(let w=0;w<8;w++){const M=u(m)-p;if(Math.abs(M)<1e-7)return m;const S=f(m);if(Math.abs(S)<1e-7)break;m-=M/S}let b=0,k=1;for(m=p;b<k;){const w=u(m);if(Math.abs(w-p)<1e-7)return m;p>w?b=m:k=m,m=(b+k)/2}return m};return p=>{if(p<=0)return 0;if(p>=1)return 1;const m=g(p);return d(m)}}function Hi(t,e="out"){if(e==="out")return t;const n=s=>1-t(1-s);return e==="in"?n:s=>s<.5?n(s*2)/2:t(s*2-1)/2+.5}function wa(t=1,e=.3){const n=Math.max(1,t),s=e/(2*Math.PI)*Math.asin(1/n);return i=>i<=0?0:i>=1?1:n*Math.pow(2,-10*i)*Math.sin((i-s)*(2*Math.PI)/e)+1}const ka=t=>{if(t<=0)return 0;if(t>=1)return 1;if(t<1/2.75)return 7.5625*t*t;if(t<2/2.75){const i=t-.5454545454545454;return 7.5625*i*i+.75}if(t<2.5/2.75){const i=t-.8181818181818182;return 7.5625*i*i+.9375}const s=t-2.625/2.75;return 7.5625*s*s+.984375};function va(t=1.70158){return e=>{if(e<=0)return 0;if(e>=1)return 1;const n=e-1;return n*n*((t+1)*n+t)+1}}function Ma(t,e="end"){const n=Math.max(1,Math.floor(t));return s=>{if(s>=1)return 1;if(s<=0)return e==="start"||e==="both"?e==="start"?1/n:1/(n+1):0;const i=Math.floor(s*n);switch(e){case"start":return Math.min(1,(i+1)/n);case"both":return(i+1)/(n+1);case"none":return n===1?0:Math.min(1,i/(n-1));default:return i/n}}}function Sa(t){switch(t.type){case"steps":return Ma(t.count,t.position);case"elastic":return Hi(wa(t.amplitude,t.period),t.mode);case"bounce":return Hi(ka,t.mode);case"back":return Hi(va(t.overshoot),t.mode)}}function $t(t){return t===void 0?ls:De(t)?ba(t.points):yn(t)?Sa(t):gf[t]??ls}const Ta=32,mf=256,je=new Map,yf=/[MmLlHhVvCcSsQqTtAaZz]/,bf=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,wf={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function kf(t){const e=[];let n=0,s=null;const i=()=>{for(;n<t.length&&/[\s,]/.test(t[n]);)n++};for(;n<t.length&&(i(),!(n>=t.length));){const o=t[n];if(yf.test(o)){s={type:o,args:[]},e.push(s),n++;continue}if(!s)break;const r=s.type==="A"||s.type==="a",a=s.args.length%7;if(r&&(a===3||a===4)){if(o!=="0"&&o!=="1")break;s.args.push(o==="1"?1:0),n++;continue}const l=bf.exec(t.slice(n));if(!l)break;s.args.push(parseFloat(l[0])),n+=l[0].length}return e}function vf(t,e,n,s,i,o,r,a,l){if(t===a&&e===l)return[];let c=Math.abs(n),h=Math.abs(s);if(c===0||h===0)return[[t,e,a,l,a,l]];const u=i*Math.PI/180,d=Math.cos(u),f=Math.sin(u),g=(t-a)/2,p=(e-l)/2,m=d*g+f*p,b=-f*g+d*p,k=m*m/(c*c)+b*b/(h*h);if(k>1){const J=Math.sqrt(k);c*=J,h*=J}const w=o===r?-1:1,M=c*c*h*h-c*c*b*b-h*h*m*m,S=c*c*b*b+h*h*m*m,A=w*Math.sqrt(Math.max(0,M/S)),E=A*c*b/h,$=-A*h*m/c,v=d*E-f*$+(t+a)/2,O=f*E+d*$+(e+l)/2,x=(J,P,H,T)=>{const C=J*H+P*T,D=Math.sqrt((J*J+P*P)*(H*H+T*T)),q=Math.acos(Math.max(-1,Math.min(1,C/D)));return J*T-P*H<0?-q:q},_=x(1,0,(m-E)/c,(b-$)/h);let F=x((m-E)/c,(b-$)/h,(-m-E)/c,(-b-$)/h);!r&&F>0&&(F-=2*Math.PI),r&&F<0&&(F+=2*Math.PI);const I=Math.max(1,Math.ceil(Math.abs(F)/(Math.PI/2))),L=F/I,N=4/3*Math.tan(L/4),Y=J=>{const P=c*Math.cos(J),H=h*Math.sin(J);return[d*P-f*H+v,f*P+d*H+O]},j=J=>{const P=-c*Math.sin(J),H=h*Math.cos(J);return[d*P-f*H,f*P+d*H]},U=[];for(let J=0;J<I;J++){const P=_+J*L,H=P+L,[T,C]=Y(P),[D,q]=J===I-1?[a,l]:Y(H),[st,K]=j(P),[tt,R]=j(H);U.push([T+N*st,C+N*K,D-N*tt,q-N*R,D,q])}return U}function re(t,e,n,s,i){const o=1-i;return o*o*o*t+3*o*o*i*e+3*o*i*i*n+i*i*i*s}function Ea(t,e,n,s,i){const o=1-i;return 3*o*o*(e-t)+6*o*i*(n-e)+3*i*i*(s-n)}function Mn(t,e,n,s){return{subpath:0,type:"L",points:[n,s],startX:t,startY:e,endX:n,endY:s,length:Math.hypot(n-t,s-e)}}function cs(t,e,n){const[s,i,o,r,a,l]=n,c=[0];let h=t,u=e,d=0;for(let f=1;f<=Ta;f++){const g=f/Ta,p=re(t,s,o,a,g),m=re(e,i,r,l,g);d+=Math.hypot(p-h,m-u),c.push(d),h=p,u=m}return{subpath:0,type:"C",points:[s,i,o,r,a,l],startX:t,startY:e,endX:a,endY:l,length:d,lengths:c}}function Se(t){const e=je.get(t);if(e)return e;const n=[];let s=0,i=0,o=0,r=0,a=null,l=null,c=-1;const h=new Set,u=p=>{c<0&&(c=0),p.subpath=c,n.push(p)};for(const{type:p,args:m}of kf(t)){const b=p.toUpperCase(),k=p!==b,w=wf[b];if(b==="Z"){(s!==o||i!==r)&&u(Mn(s,i,o,r)),c>=0&&h.add(c),s=o,i=r,a=l=null;continue}for(let M=0;M+w<=m.length;M+=w){const S=m.slice(M,M+w),A=k?s:0,E=k?i:0;let $=null,v=null;switch(b){case"M":M===0?(s=S[0]+A,i=S[1]+E,o=s,r=i,(c<0||n[n.length-1]?.subpath===c)&&c++):(u(Mn(s,i,S[0]+A,S[1]+E)),s=S[0]+A,i=S[1]+E);break;case"L":u(Mn(s,i,S[0]+A,S[1]+E)),s=S[0]+A,i=S[1]+E;break;case"H":u(Mn(s,i,S[0]+A,i)),s=S[0]+A;break;case"V":u(Mn(s,i,s,S[0]+E)),i=S[0]+E;break;case"C":{const O=[S[0]+A,S[1]+E,S[2]+A,S[3]+E,S[4]+A,S[5]+E];u(cs(s,i,O)),$=[O[2],O[3]],s=O[4],i=O[5];break}case"S":{const[O,x]=a?[2*s-a[0],2*i-a[1]]:[s,i],_=[O,x,S[0]+A,S[1]+E,S[2]+A,S[3]+E];u(cs(s,i,_)),$=[_[2],_[3]],s=_[4],i=_[5];break}case"Q":case"T":{let O=s,x=i;b==="Q"?(O=S[0]+A,x=S[1]+E):l&&(O=2*s-l[0],x=2*i-l[1]);const _=b==="Q"?S[2]+A:S[0]+A,F=b==="Q"?S[3]+E:S[1]+E;u(cs(s,i,[s+2/3*(O-s),i+2/3*(x-i),_+2/3*(O-_),F+2/3*(x-F),_,F])),v=[O,x],s=_,i=F;break}case"A":{const O=S[5]+A,x=S[6]+E;let _=s,F=i;for(const I of vf(s,i,S[0],S[1],S[2],S[3],S[4],O,x))u(cs(_,F,I)),_=I[4],F=I[5];s=O,i=x;break}}a=$,l=v}}const d=n.reduce((p,m)=>p+m.length,0),f=[];for(let p=0;p<n.length;){const m=n[p].subpath;let b=p,k=0;for(;b<n.length&&n[b].subpath===m;)k+=n[b++].length;const w=n[p],M=n[b-1],S=h.has(m)||Math.abs(M.endX-w.startX)<1e-9&&Math.abs(M.endY-w.startY)<1e-9;f.push({start:p,end:b,length:k,closed:S}),p=b}const g={segments:n,totalLength:d,subpaths:f};return je.size>=mf&&je.delete(je.keys().next().value),je.set(t,g),g}function Mf(t,e){const n=t.lengths;if(e<=0)return 0;if(e>=t.length)return 1;let s=0,i=n.length-1;for(;s<i-1;){const a=s+i>>1;n[a]<e?s=a:i=a}const o=n[i]-n[s],r=o>0?(e-n[s])/o:0;return(s+r)/(n.length-1)}function Sf(t,e){if(t.type==="L"){const u=t.length>0?Math.max(0,Math.min(1,e/t.length)):0;return{x:t.startX+(t.endX-t.startX)*u,y:t.startY+(t.endY-t.startY)*u,angle:Math.atan2(t.endY-t.startY,t.endX-t.startX)*180/Math.PI}}const[n,s,i,o,r,a]=t.points,l=Mf(t,e);let c=Ea(t.startX,n,i,r,l),h=Ea(t.startY,s,o,a,l);if(Math.hypot(c,h)<1e-9){const u=l<.5?Math.min(1,l+.001):Math.max(0,l-.001),d=re(t.startX,n,i,r,u),f=re(t.startY,s,o,a,u),g=re(t.startX,n,i,r,l),p=re(t.startY,s,o,a,l);c=l<.5?d-g:g-d,h=l<.5?f-p:p-f}return{x:re(t.startX,n,i,r,l),y:re(t.startY,s,o,a,l),angle:Math.atan2(h,c)*180/Math.PI}}function Ri(t,e,n=0,s=t.length){if(s<=n)return{x:0,y:0,angle:0};let i=0;for(let o=n;o<s;o++){const r=t[o];if(i+r.length>=e||o===s-1)return Sf(r,e-i);i+=r.length}return{x:0,y:0,angle:0}}function Aa(t,e){const{segments:n,totalLength:s}=Se(t);return Ri(n,Math.max(0,Math.min(1,e))*s)}function Tf(){je.clear()}function Ef(t){return Se(t).totalLength}const Af=24,Pf=320,$f=2.5,Sn=72,xf=64,_f=.2,If=128,Tn=new Map;let hs=0,ae;const Pa=t=>Math.round(t*100)/100;function $a(t,e){const{segments:n,subpaths:s,totalLength:i}=Se(t);if(n.length===0)return[];if(e){const o=s.every(r=>r.closed);return[{segments:n,start:0,end:n.length,length:i,closed:o}]}return s.filter(o=>o.length>0).map(o=>({segments:n,start:o.start,end:o.end,length:o.length,closed:o.closed}))}function Li(t,e){const n=t.closed?(e%1+1)%1:Math.max(0,Math.min(1,e)),s=Ri(t.segments,n*t.length,t.start,t.end);return[s.x,s.y]}function xa(t){const e=[];let n=0;for(let s=t.start;s<t.end;s++)n+=t.segments[s].length,t.length>0&&e.push(n/t.length);return e}function _a(t,e){const n=[];for(let s=0;s<e;s++)n.push(Li(t,t.closed?s/e:s/(e-1)));return n}function Ia(t){let e=0,n=0;for(const[s,i]of t)e+=s,n+=i;return e/=t.length,n/=t.length,t.map(([s,i])=>[s-e,i-n])}function Of(t,e,n){const s=t.closed&&e.closed;if(n!==void 0)return{offset:s?Math.abs(n)%Sn/Sn:0,reversed:n<0};const i=Ia(_a(t,Sn)),o=Ia(_a(e,Sn)),r=Sn;let a={offset:0,reversed:!1},l=1/0;for(const c of[!1,!0]){const h=s?r:1;for(let u=0;u<h;u++){let d=0;for(let f=0;f<r&&d<l;f++){const g=s?c?(u-f+r)%r:(f+u)%r:c?r-1-f:f,p=i[f][0]-o[g][0],m=i[f][1]-o[g][1];d+=p*p+m*m}d<l&&(l=d,a={offset:s?u/r:0,reversed:c})}}return a}function Cf(t,e,n){return n?((e.reversed?e.offset-t:t+e.offset)%1+1)%1:e.reversed?1-t:t}function Hf(t,e,n){return n?((e.reversed?e.offset-t:t-e.offset)%1+1)%1:e.reversed?1-t:t}function Rf(t,e,n){const s=t.closed&&e.closed,i=Of(t,e,n.shapeIndex),o=Math.max(Af,Math.min(Pf,Math.ceil(Math.max(t.length,e.length)/$f))),r=new Set,a=u=>r.add(Math.round(u*1e7)/1e7);for(let u=0;u<=o;u++)a(u/o);for(const u of xa(t))a(u);for(const u of xa(e))a(Hf(u,i,s));let l=[...r].sort((u,d)=>u-d);s&&(l=l.filter(u=>u<1));const c=[],h=[];for(const u of l)c.push(...Li(t,u)),h.push(...Li(e,Cf(u,i,s)));return Lf({from:c,to:h,closed:s})}function Lf(t){const e=t.from.length/2;if(e<=3)return t;const n=new Uint8Array(e);n[0]=1,n[e-1]=1;const s=[[0,e-1]];for(;s.length>0;){const[r,a]=s.pop();let l=-1,c=_f;for(let h=r+1;h<a;h++){const u=Math.max(Oa(t.from,r,a,h),Oa(t.to,r,a,h));u>c&&(c=u,l=h)}l!==-1&&(n[l]=1,s.push([r,l],[l,a]))}const i=[],o=[];for(let r=0;r<e;r++)n[r]&&(i.push(t.from[r*2],t.from[r*2+1]),o.push(t.to[r*2],t.to[r*2+1]));return{from:i,to:o,closed:t.closed}}function Oa(t,e,n,s){const i=t[e*2],o=t[e*2+1],r=t[n*2]-i,a=t[n*2+1]-o,l=t[s*2]-i,c=t[s*2+1]-o,h=r*r+a*a,u=h===0?0:Math.max(0,Math.min(1,(l*r+c*a)/h));return Math.hypot(l-u*r,c-u*a)}function Ff(t,e,n){const s=n.shapeIndex;if(ae&&ae.from===t&&ae.to===e&&ae.shapeIndex===s)return ae.plan;const o=Tn.get(String(s??"auto"))?.get(t)?.get(e);if(o)return ae={from:t,to:e,shapeIndex:s,plan:o},o;const r=Se(t).subpaths.filter(f=>f.length>0).length===Se(e).subpaths.filter(f=>f.length>0).length,a=$a(t,!r),l=$a(e,!r),c={pairs:a.map((f,g)=>Rf(f,l[g],n))};hs>=If&&(Tn.clear(),hs=0);const h=String(s??"auto"),u=Tn.get(h)??new Map;Tn.set(h,u);const d=u.get(t)??new Map;return u.set(t,d),d.set(e,c),hs++,ae={from:t,to:e,shapeIndex:s,plan:c},c}function Ca(t,e,n,s={}){if(!t)return e;if(!e)return t;const i=Math.max(0,Math.min(1,n));if(i===0)return t;if(i===1)return e;const o=Ff(t,e,s);if(o.pairs.length===0)return i<.5?t:e;let r="";for(const a of o.pairs){for(let l=0;l<a.from.length;l+=2){const c=Pa(a.from[l]+(a.to[l]-a.from[l])*i),h=Pa(a.from[l+1]+(a.to[l+1]-a.from[l+1])*i);r+=`${l===0?r?" M":"M":" L"}${c} ${h}`}a.closed&&(r+=" Z")}return r}function Df(){Tn.clear(),hs=0,ae=void 0}function qe(t){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(t)}const Ke=Math.PI/180,Nf=.9995;function Fi(){return[0,0,0,1]}function Bt(t,e){const n=Math.hypot(t[0],t[1],t[2]);if(n===0)return Fi();const s=e*Ke/2,i=Math.sin(s)/n;return[t[0]*i,t[1]*i,t[2]*i,Math.cos(s)]}function Bf(t,e,n){return Di(Di(Bt([0,1,0],e),Bt([1,0,0],t)),Bt([0,0,1],n))}function Wf(t){const[e,n,s,i]=le(t),o=2*(e*s+n*i),r=2*(e*n+s*i),a=1-2*(e*e+s*s),l=2*(n*s-e*i),c=1-2*(n*n+s*s),h=2*(e*s-n*i),u=1-2*(e*e+n*n),d=Math.asin(Math.max(-1,Math.min(1,-l)));return Math.abs(l)<.9999999?[d/Ke,Math.atan2(o,u)/Ke,Math.atan2(r,a)/Ke]:[d/Ke,Math.atan2(-h,c)/Ke,0]}function Di(t,e){const[n,s,i,o]=t,[r,a,l,c]=e;return[o*r+n*c+s*l-i*a,o*a-n*l+s*c+i*r,o*l+n*a-s*r+i*c,o*c-n*r-s*a-i*l]}function Ha(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function Ra(t){return Math.hypot(t[0],t[1],t[2],t[3])}function le(t){const e=Ra(t);return e===0?Fi():[t[0]/e,t[1]/e,t[2]/e,t[3]/e]}function jf(t){return[-t[0],-t[1],-t[2],t[3]]}function La(t,e,n){const s=le(t);let i=le(e),o=Ha(s,i);if(o<0&&(i=[-i[0],-i[1],-i[2],-i[3]],o=-o),o>Nf)return le([s[0]+(i[0]-s[0])*n,s[1]+(i[1]-s[1])*n,s[2]+(i[2]-s[2])*n,s[3]+(i[3]-s[3])*n]);const r=Math.acos(o),a=Math.sin(r),l=Math.sin((1-n)*r)/a,c=Math.sin(n*r)/a;return le([s[0]*l+i[0]*c,s[1]*l+i[1]*c,s[2]*l+i[2]*c,s[3]*l+i[3]*c])}function qf(t,e){const[n,s,i,o]=le(t),r=2*(s*e[2]-i*e[1]),a=2*(i*e[0]-n*e[2]),l=2*(n*e[1]-s*e[0]);return[e[0]+o*r+(s*l-i*a),e[1]+o*a+(i*r-n*l),e[2]+o*l+(n*a-s*r)]}const Kf=Object.freeze(Object.defineProperty({__proto__:null,conjugate:jf,dot:Ha,fromAxisAngle:Bt,fromEuler:Bf,identity:Fi,length:Ra,multiply:Di,normalize:le,rotateVec3:qf,slerp:La,toEuler:Wf},Symbol.toStringTag,{value:"Module"})),Gt=(t,e,n)=>t+(e-t)*n,Fa=512,Ni=new Map,Bi=new Map;function Da(t){const e=Ni.get(t);if(e)return e;const n=t.replace("#",""),s=[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)];return Ni.size<Fa&&Ni.set(t,s),s}const Na=t=>t.charCodeAt(0)===35,Ba=t=>t.startsWith("rgb"),Wa=t=>t.startsWith("rgba"),Yf=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,Wi=t=>Math.round(t).toString(16).padStart(2,"0");function zf(t,e,n){return`#${Wi(t)}${Wi(e)}${Wi(n)}`}function ja(t){const e=Bi.get(t);if(e)return e;const n=t.match(Yf);if(!n)throw new Error(`Invalid rgb color: ${t}`);const s=parseInt(n[1],10),i=parseInt(n[2],10),o=parseInt(n[3],10),r=n[4]!==void 0?[s,i,o,parseFloat(n[4])]:[s,i,o];return Bi.size<Fa&&Bi.set(t,r),r}const qa=(t,e,n)=>{if(Na(t)&&Na(e)){const[s,i,o]=Da(t),[r,a,l]=Da(e),c=Gt(s,r,n),h=Gt(i,a,n),u=Gt(o,l,n);return zf(c,h,u)}if((Ba(t)||Wa(t))&&(Ba(e)||Wa(e))){const s=ja(t),i=ja(e),o=Math.round(Gt(s[0],i[0],n)),r=Math.round(Gt(s[1],i[1],n)),a=Math.round(Gt(s[2],i[2],n));if(s.length===4||i.length===4){const l=s[3]??1,c=i[3]??1,h=Gt(l,c,n);return`rgba(${o}, ${r}, ${a}, ${h})`}return`rgb(${o}, ${r}, ${a})`}return n<1?t:e},Ka=(t,e,n)=>{const s=Math.min(t.length,e.length),i=[];for(let o=0;o<s;o++)i.push(Gt(t[o],e[o],n));return i},Ya=(t,e,n)=>La(t,e,n),ji=(t,e,n)=>n<1?t:e,za=(t,e,n)=>Ca(t,e,n);function En(t,e){return e==="slerp"?Ya:typeof t=="number"?Gt:Array.isArray(t)?Ka:typeof t=="string"?t.startsWith("#")||t.startsWith("rgb")?qa:qe(t)?za:ji:ji}const qi=1e3/60;function Ki(t,e={}){if(!oe(t))throw new Error(`bakeSpringTrack: track "${t.id}" is not a spring track`);const n=new wn(t.spring);return Xa(t,s=>n.valueAt(s),n.settleTime(),t.spring.from,t.spring.to,e)}function Yi(t,e={}){if(!ie(t))throw new Error(`bakeInertiaTrack: track "${t.id}" is not an inertia track`);const n=t.inertia;return Xa(t,s=>as(n,s),We(n),n.from,Be(n),e)}function Xa(t,e,n,s,i,o){const r=o.intervalMs??qi,a=o.tolerance??.01,l=t.delay??0,c=[];for(let u=0;u<=n;u+=r)c.push({time:u+l,value:e(u),easing:"linear"});const h=c[c.length-1];return!h||h.time<n+l?c.push({time:n+l,value:i,easing:"linear"}):h.value=i,l>0&&c.unshift({time:0,value:s,easing:"linear"}),{id:t.id,target:t.target,property:t.property,keyframes:a>0?Ua(c,a):c,...t.targets&&{targets:[...t.targets]},...t.stagger&&{stagger:{...t.stagger}}}}function zi(t,e,n,s={}){const i=s.intervalMs??qi,o=typeof n=="function"?n:$t(n),r=En(t.value,s.interpolation),a=e.time-t.time;if(a<=0)return[e];const l=[];for(let h=i;h<a;h+=i){const u=h/a;l.push({time:t.time+h,value:r(t.value,e.value,o(u)),easing:"linear"})}const c=o(1);return l.push({...e,...c!==1&&{value:r(t.value,e.value,c)},easing:"linear"}),l}function Xf(t,e){return oe(t)?Ki(t,e):ie(t)?Yi(t,e):t}function Ga(t,e={}){const n=t.keyframes;if(!n.some(o=>yn(o.easing)))return t;const s=n.length>0?[n[0]]:[],i={...e,interpolation:t.interpolation??e.interpolation};for(let o=1;o<n.length;o++){const r=n[o];yn(r.easing)?s.push(...zi(n[o-1],r,r.easing,i)):s.push(r)}return{...t,keyframes:s}}function Gf(t,e){return t.filter(la).map(n=>Ga(n,e)).concat(t.filter(oe).map(n=>Ki(n,e)),t.filter(ie).map(n=>Yi(n,e)))}function Ua(t,e){if(t.length<=2)return t;const n=[t[0]];for(let s=1;s<t.length-1;s++){const i=n[n.length-1],o=t[s],r=t[s+1],a=r.time-i.time;if(a<=0)continue;const l=(o.time-i.time)/a,c=i.value+(r.value-i.value)*l;Math.abs(o.value-c)>e&&n.push(o)}return n.push(t[t.length-1]),n}function us(t){const e=[...t.keyframes].sort((n,s)=>n.time-s.time);return{...t,keyframes:e}}function ce(t){return t.targets&&t.targets.length>0?t.targets:[t.target]}function Ye(t,e,n,s){const i=n??0;return!s||e<=1?i:i+ns(t,e,s)}class ds{track;targets;constructor(e){this.track=e,this.targets=ce(e)}getValueAtTime(e){return this.valueForOffset(e-Ye(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const o=Ye(i,n,this.track.delay,this.track.stagger),r=this.valueForOffset(e-o);r!==void 0&&s.push({target:this.targets[i],value:r,start:o+this.track.keyframes[0].time})}return s}getDuration(){const{keyframes:e}=this.track;if(e.length===0)return 0;const n=e[e.length-1].time,s=this.track.stagger?bn(this.targets.length,this.track.stagger):0;return n+(this.track.delay??0)+s+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(e){const{keyframes:n}=this.track;if(n.length===0)return;if(n.length===1||e<=n[0].time)return n[0].value;if(e>=n[n.length-1].time)return n[n.length-1].value;const{from:s,to:i}=this.findSurroundingKeyframes(e);if(!s||!i)return;if(s.time===e)return s.value;const o=i.time-s.time,r=(e-s.time)/o,l=$t(i.easing)(r);return En(s.value,this.track.interpolation)(s.value,i.value,l)}findSurroundingKeyframes(e){const{keyframes:n}=this.track;for(let s=0;s<n.length-1;s++)if(e>=n[s].time&&e<=n[s+1].time)return{from:n[s],to:n[s+1]};return{from:null,to:null}}}class Va{track;targets;sampler;constructor(e){this.track=e,this.targets=ce(e),this.sampler=new wn(e.spring)}getValueAtTime(e){return this.sampler.valueAt(e-Ye(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const o=Ye(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:this.sampler.valueAt(e-o),start:o})}return s}getDuration(){const e=this.track.stagger?bn(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+e}getTrack(){return this.track}}class Ja{track;targets;duration;constructor(e){this.track=e,this.targets=ce(e),this.duration=We(e.inertia)}getValueAtTime(e){return as(this.track.inertia,e-Ye(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const o=Ye(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:as(this.track.inertia,e-o),start:o})}return s}getDuration(){const e=this.track.stagger?bn(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+e}getTrack(){return this.track}}function Xi(t,e){const n={...Aa(t.pathData,e)};if(t.matrix){const[s,i,o,r,a,l]=t.matrix,{x:c,y:h}=n;n.x=s*c+o*h+a,n.y=i*c+r*h+l;const u=n.angle*Math.PI/180,d=Math.cos(u),f=Math.sin(u);n.angle=Math.atan2(i*d+r*f,s*d+o*f)*180/Math.PI}return t.autoRotate&&t.rotateOffset&&(n.angle+=t.rotateOffset),n}function Uf(t,e,n,s){const i=e+(n-e)*s;return Xi(t,i)}const Gi={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},Vf=20;function Za(t){const e=Gi[t??"upperCase"]??t??Gi.upperCase,n=Array.from(e);return n.length>0?n:Array.from(Gi.upperCase)}function Jf(t,e,n){let s=(t|0)^Math.imul(e+1,2654435761)^Math.imul(n+1,2246822507);return s=Math.imul(s^s>>>16,2146121005),s=Math.imul(s^s>>>15,2221713035),(s^s>>>16)>>>0}function Qa(t,e,n=0){const s=t.from??"",i=t.to,o=Math.max(0,Math.min(1,e));if(o<=0)return s;if(o>=1)return i;const r=Array.from(s),a=Array.from(i),l=t.rightToLeft??!1;if(t.mode==="type"){const k=Math.round(o*Math.max(r.length,a.length));return l?r.slice(0,Math.max(0,r.length-k)).join("")+a.slice(Math.max(0,a.length-k)).join(""):a.slice(0,k).join("")+r.slice(k).join("")}const c=Math.max(0,Math.min(.999,t.revealDelay??0)),h=Math.max(0,(o-c)/(1-c)),u=Math.floor(h*a.length),d=t.tweenLength===!1?a.length:Math.round(r.length+(a.length-r.length)*o),f=Za(t.chars),g=t.refreshRate??Vf,p=g>0?Math.floor(n*g/1e3):0,m=t.seed??1;let b="";for(let k=0;k<d;k++){const w=l?k>=d-u:k<u,M=l?a[a.length-(d-k)]:a[k];w&&M!==void 0||M===" "||M===`
2
- `?b+=M:b+=f[Jf(m,k,p)%f.length]}return b}class Wt{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(e){if(this.id=e.id,this.name=e.name,this._captions=e.captions,this._config=e.config??{},this._explicitDuration=e.config?.duration,e.tracks)for(const n of e.tracks)this.addTrack(n)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(e){if(this._explicitDuration=e,e!==void 0)this._config={...this._config,duration:e};else if(this._config.duration!==void 0){const n={...this._config};delete n.duration,this._config=n}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(e){this._config.speed=e}get drawingRate(){return this._config.drawingRate??0}set drawingRate(e){const n={...this._config};e>0?n.drawingRate=e:delete n.drawingRate,this._config=n}play(){const e=this.duration;this._direction==="forward"&&this._currentTime>=e&&e>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&e>0&&(this._currentTime=e,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(e){const n=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(e,n)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(e){if(this._playbackState!=="playing")return;const n=this.duration;if(n<=0)return;let i=e*this.speed;if(this._repeatDelayRemaining>0){const a=Math.min(this._repeatDelayRemaining,i);if(this._repeatDelayRemaining-=a,i-=a,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const o=1e3;for(let a=0;a<o&&i>0&&this._playbackState==="playing";a++)if(this._direction==="forward"){const l=n-this._currentTime;if(i>=l){if(i-=l,this._currentTime=n,!this._handleEndReached())break}else this._currentTime+=i,i=0}else{const l=this._currentTime;if(i>=l){if(i-=l,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=i,i=0}const r=this.getStateAtTime(this._currentTime);this.onUpdate?.(r)}getStateAtTime(e){const n=new Map;if(e=ca(e,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(e,n);else for(const[s,i]of this._trackPlayers){const o=i.getTrack().property;for(const{target:r,value:a,start:l}of i.getTargetValues(e))this._write(n,s,r,o,a,e-l)}return{values:n,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(e,n){const s=new Map;for(const[i,o]of this._trackPlayers){const r=o.getTrack().property;for(const{target:a,value:l,start:c}of o.getTargetValues(e)){const h=`${a}\0${r}`,u=c<=e,d=s.get(h);(!d||(u!==d.started?u:u?c>=d.start:c<=d.start))&&s.set(h,{trackId:i,target:a,property:r,value:l,start:c,started:u})}}for(const{trackId:i,target:o,property:r,value:a,start:l}of s.values())this._write(n,i,o,r,a,e-l)}_write(e,n,s,i,o,r){if(o===void 0)return;let a=e.get(s);a||(a=new Map,e.set(s,a));const l=this._textTracks.get(n);if(l&&typeof o=="number"){a.set("text",Qa(l.textConfig,o,Math.max(0,r)));return}const c=this._motionPathTracks.get(n);if(c&&typeof o=="number"){const h=Xi(c.motionPathConfig,o);a.set("motionPathX",h.x),a.set("motionPathY",h.y),c.motionPathConfig.autoRotate&&a.set("motionPathRotate",h.angle)}else a.set(i,o)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const e=new Set;this._sharedWrites=!1;t:for(const n of this._tracks)for(const s of ce(n)){const i=`${s}\0${n.property}`;if(e.has(i)){this._sharedWrites=!0;break t}e.add(i)}}return this._sharedWrites}addTrack(e){if(this._tracks.push(e),this._sharedWrites=null,ie(e)){this._trackPlayers.set(e.id,new Ja(e));return}if(oe(e)){this._trackPlayers.set(e.id,new Va(e)),this._springTracks.set(e.id,e);return}if(es(e))this._trackPlayers.set(e.id,new ds(e)),this._textTracks.set(e.id,e);else if(Pi(e)){const n={id:e.id,target:e.target,property:e.property,keyframes:e.keyframes,delay:e.delay,endDelay:e.endDelay,targets:e.targets,stagger:e.stagger};this._trackPlayers.set(e.id,new ds(n)),this._motionPathTracks.set(e.id,e)}else this._trackPlayers.set(e.id,new ds(e))}replaceTrack(e,n){const s=this._tracks.findIndex(o=>o.id===e);if(s<0)return;const i=this._tracks.slice(s+1);this.removeTrack(e);for(const o of i)this.removeTrack(o.id);this.addTrack(n);for(const o of i)this.addTrack(o)}removeTrack(e){this._tracks=this._tracks.filter(n=>n.id!==e),this._sharedWrites=null,this._trackPlayers.delete(e),this._motionPathTracks.delete(e),this._springTracks.delete(e),this._textTracks.delete(e)}getTracks(e={}){return this._tracks.filter(n=>this._matches(n,e))}removeTracks(e={}){const n=this.getTracks(e).map(s=>s.id);for(const s of n)this.removeTrack(s);return n}getTrackSpan(e){const n=this._trackPlayers.get(e);if(!n)return;const s=n.getTrack(),i=s.delay??0;if(oe(s)||ie(s))return{from:i,to:n.getDuration()};const o=s.keyframes;if(!(!o||o.length===0))return{from:o[0].time+i,to:n.getDuration()}}findConflicts(){const e=[];for(let n=0;n<this._tracks.length;n++){const s=this._tracks[n],i=this.getTrackSpan(s.id);if(i)for(let o=0;o<n;o++){const r=this._tracks[o];if(r.property!==s.property)continue;const a=ce(r).filter(u=>ce(s).includes(u));if(a.length===0)continue;const l=this.getTrackSpan(r.id);if(!l||!(l.from<=i.to&&i.from<=l.to))continue;const h=i.from>=l.from;for(const u of a)e.push({target:u,property:s.property,losingTrackId:h?r.id:s.id,winningTrackId:h?s.id:r.id})}}return e}_matches(e,n){if(n.id!==void 0&&e.id!==n.id||n.property!==void 0&&e.property!==n.property||n.target!==void 0&&!ce(e).includes(n.target))return!1;if(n.timeRange){const s=this.getTrackSpan(e.id);if(!s||s.to<n.timeRange.from||s.from>n.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:Ai(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((e,n)=>e.time-n.time)}setMarkers(e){const n=e&&e.length>0?[...e].sort((i,o)=>i.time-o.time).map(i=>({...i})):void 0,s={...this._config};n?s.markers=n:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(e){const n={};for(const[s,i]of Object.entries(e??{}))n[s]={...i};this._captions=Object.keys(n).length>0?n:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let e=0;for(const[,n]of this._trackPlayers)e=Math.max(e,n.getDuration());return e}_handleEndReached(){const e=this._config.loop??0;return e===-1||this._loopIteration<e?(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 e=this._config.loop??0;return this._config.alternate&&(e===-1||this._loopIteration<e)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const Zf=100;function Ui(t,e,n,s){const i=[],o=[],{duration:r,alternate:a}=s,l=(f,g,p,m)=>{o.push([f,g]);const b=[];t.forEach((k,w)=>{(p==="forward"?(m?k>=f:k>f)&&k<=g:(m?k<=f:k<f)&&k>=g)&&b.push(w)}),b.sort((k,w)=>(p==="forward"?t[k]-t[w]:t[w]-t[k])||k-w);for(const k of b)i.push({kind:"event",index:k,direction:p})};let c=e.time,h=e.direction,u=e.fresh===!0;const d=Math.min(Zf,Math.max(0,n.iteration-e.iteration));for(let f=0;f<d;f++){const g=h==="forward"?r:0;l(c,g,h,u),i.push({kind:"repeat"}),a?(h=h==="forward"?"reverse":"forward",c=g,u=!1):(c=h==="forward"?0:r,u=!0)}return d>0&&s.holding&&!a?{crossings:i,passes:o}:(l(c,n.time,h,u),{crossings:i,passes:o})}function tl(t){return ie(t)?{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:el(t.inertia),...Ut(t)}:oe(t)?{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...Ut(t)}:es(t)?{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:t.keyframes.map(Vi),...Ut(t)}:Pi(t)?{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:t.keyframes.map(Vi),...Ut(t)}:{id:t.id,target:t.target,property:t.property,keyframes:t.keyframes.map(Vi),...t.interpolation!==void 0&&{interpolation:t.interpolation},...Ut(t)}}function el(t){return{...t,...Array.isArray(t.end)&&{end:[...t.end]}}}function Vi(t){return{time:t.time,value:t.value,...t.easing&&{easing:t.easing}}}function Ut(t){const e=t.endDelay;return{...t.delay!==void 0&&{delay:t.delay},...e!==void 0&&{endDelay:e},...t.targets!==void 0&&{targets:[...t.targets]},...t.stagger!==void 0&&{stagger:{...t.stagger}}}}function nl(t){if(ie(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"inertia",inertia:el(e.inertia),...Ut(e)}}if(oe(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"spring",spring:{...e.spring},...Ut(e)}}if(es(t)){const e=t;return{id:e.id,target:e.target,property:"text",textConfig:{...e.textConfig},keyframes:[...e.keyframes].sort((n,s)=>n.time-s.time),...Ut(e)}}if(t.property==="motionPath"&&"motionPathConfig"in t){const e=t,n=[...e.keyframes].sort((s,i)=>s.time-i.time);return{id:e.id,target:e.target,property:"motionPath",motionPathConfig:{...e.motionPathConfig},keyframes:n,...Ut(e)}}return us({id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,...t.interpolation!==void 0&&{interpolation:t.interpolation},...Ut(t)})}function sl(t){const e=t._config.markers;return{formatVersion:Ai(t.tracks),id:t.id,name:t.name,config:{duration:t.duration>0?t.duration:void 0,loop:t._config.loop,speed:t._config.speed,alternate:t._config.alternate,repeatDelay:t._config.repeatDelay,...t._config.drawingRate?{drawingRate:t._config.drawingRate}:{},...e&&{markers:e.map(n=>({...n}))}},tracks:t.tracks.map(tl),...t.captions&&{captions:JSON.parse(JSON.stringify(t.captions))}}}function ze(t){const e=t.formatVersion??1;if(e>Ei)throw new Error(`tinyfly: this animation uses format version ${e}, but this tinyfly reads up to version ${Ei}. Update tinyfly to play it.`);return new Wt({id:t.id,name:t.name,config:t.config,tracks:t.tracks.map(nl),captions:t.captions})}function Qf(t){return JSON.stringify(sl(t))}function t0(t){const e=JSON.parse(t);return ze(e)}function Kt(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e>>>0}function Xe(t){let e=t>>>0||2654435769;return{seed:t>>>0,next(){return e^=e<<13,e>>>=0,e^=e>>17,e^=e<<5,e>>>=0,e/4294967296}}}function Ji(t,e,n){return e+t.next()*(n-e)}function il(t,e,n,s){if(s<=0)return Ji(t,e,n);const i=Math.floor((n-e)/s),o=Math.round(t.next()*i);return e+o*s}function e0(t,e){if(e.length!==0)return e[Math.floor(t.next()*e.length)]}const ol=/^([+\-*/])=\s*(-?[\d.]+)$/,rl=/^random\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*(?:,\s*(-?[\d.]+)\s*)?\)$/i;function n0(t){return typeof t!="string"?!1:ol.test(t.trim())||rl.test(t.trim())}function Zi(t,e={}){if(typeof t!="string")return t;const n=t.trim(),s=ol.exec(n);if(s){const[,o,r]=s,a=e.base??0,l=Number.parseFloat(r);switch(o){case"+":return a+l;case"-":return a-l;case"*":return a*l;case"/":return l===0?a:a/l}}const i=rl.exec(n);if(i){if(!e.random)throw new Error(`resolveValue: "${n}" needs a random source — pass one via context.random`);const o=Number.parseFloat(i[1]),r=Number.parseFloat(i[2]),a=i[3]!==void 0?Number.parseFloat(i[3]):void 0;return a!==void 0?il(e.random,o,r,a):Ji(e.random,o,r)}return t}function al(t,e=0,n){const s=[];let i=e;for(const o of t){const r=Zi(o,{base:i,random:n});s.push(r),typeof r=="number"&&(i=r)}return s}class s0{random;constructor(e){this.random=Xe(e)}get seed(){return this.random.seed}resolve(e,n=0){return Zi(e,{base:n,random:this.random})}resolveSequence(e,n=0){return al(e,n,this.random)}}const i0=600;function ll(t){if(Array.isArray(t)){const[d,f,g,p]=t;return{fn:ul(d,f,g,p),bezier:[d,f,g,p]}}const{segments:e}=Se(t);if(e.length===0)throw new Error(`customEase: no curve in "${t}"`);const n=e[0].startX,s=e[0].startY,i=e[e.length-1],o=i.endX-n,r=i.endY-s;if(o===0||r===0)throw new Error(`customEase: "${t}" must move along both axes`);const a=d=>(d-n)/o,l=d=>(d-s)/r;if(e.length===1&&i.type==="C"){const[d,f,g,p]=i.points,m=[a(d),l(f),a(g),l(p)];return{fn:ul(...m),bezier:m}}const c=[],h=[],u=Math.max(8,Math.ceil(i0/e.length));for(const d of e)for(let f=c.length===0?0:1;f<=u;f++){const[g,p]=o0(d,f/u);c.push(a(g)),h.push(l(p))}return{fn:r0(c,h)}}function cl(t={}){const n=.1+Math.max(0,Math.min(1,t.strength??.7))*.7,s=[1];for(let o=n;o>.002;o*=n)s.push(2*Math.sqrt(o));const i=s.reduce((o,r)=>o+r,0);return o=>{if(o<=0)return 0;if(o>=1)return 1;let r=o*i;for(let a=0;a<s.length;a++){if(r<=s[a]){if(a===0)return(r/s[0])**2;const l=s[a]/2,c=l*l,h=r-l;return 1-(c-h*h)}r-=s[a]}return 1}}function hl(t={}){const e=Math.max(1,t.wiggles??10),n=t.type??"easeOut",s=i=>n==="uniform"?1:n==="easeInOut"?Math.sin(Math.PI*i):(1-i)**2;return i=>i<=0||i>=1?0:Math.sin(i*e*Math.PI*2)*s(i)}function o0(t,e){if(t.type==="L"){const[c,h]=t.points;return[t.startX+(c-t.startX)*e,t.startY+(h-t.startY)*e]}const[n,s,i,o,r,a]=t.points,l=1-e;return[l*l*l*t.startX+3*l*l*e*n+3*l*e*e*i+e*e*e*r,l*l*l*t.startY+3*l*l*e*s+3*l*e*e*o+e*e*e*a]}function r0(t,e){return n=>{if(n<=t[0])return e[0];if(n>=t[t.length-1])return e[e.length-1];let s=0,i=t.length-1;for(;i-s>1;){const r=s+i>>1;t[r]<=n?s=r:i=r}const o=t[i]-t[s];return o===0?e[i]:e[s]+(n-t[s])/o*(e[i]-e[s])}}function ul(t,e,n,s){const i=(r,a,l)=>3*(1-r)*(1-r)*r*a+3*(1-r)*r*r*l+r*r*r,o=(r,a,l)=>3*(1-r)*(1-r)*a+6*(1-r)*r*(l-a)+3*r*r*(1-l);return r=>{if(r<=0)return 0;if(r>=1)return 1;let a=r;for(let h=0;h<8;h++){const u=i(a,t,n)-r,d=o(a,t,n);if(Math.abs(u)<1e-6)return i(a,e,s);if(Math.abs(d)<1e-6)break;a-=u/d}let l=0,c=1;a=r;for(let h=0;h<40;h++)i(a,t,n)<r?l=a:c=a,a=(l+c)/2;return i(a,e,s)}}const a0=350,l0=300,c0=550;function h0(t,e={}){const n=e.lead??a0,s=e.gap??l0,i=e.tail??c0,o=[];let r=0;return t.forEach((a,l)=>{const c=[];let h=r+n;a.lines.forEach((d,f)=>{if(!(d.duration>=0))throw new Error(`narration: scene ${l} line ${f} has an invalid duration (${d.duration})`);f>0&&(h+=s),c.push({id:d.id??`s${l}-l${f}`,scene:l,line:f,start:h,end:h+d.duration,text:d.text}),h+=d.duration});const u=h+i+(a.tail??0);o.push({id:a.id??`s${l}`,start:r,duration:u-r,cues:c}),r=u}),{duration:r,scenes:o,cues:o.flatMap(a=>a.cues)}}function u0(t){return t.cues.map(e=>({id:e.id,time:e.start,label:e.text}))}function d0(t,e){let n=t.scenes[0];for(const s of t.scenes)if(e>=s.start)n=s;else break;return n}const Qi=t=>6e4/t.bpm;function fs(t,e){return t.offset+e*Qi(t)}function ps(t,e){return(e-t.offset)/Qi(t)}function f0(t,e){return fs(t,Math.round(ps(t,e)))}function p0(t,e){return fs(t,Math.ceil(ps(t,e)-1e-9))}function g0(t,e,n){const s=Math.max(1,Math.round(t.beatsPerBar??4)),i=[];if(!(t.bpm>0)||n<e)return i;for(let o=Math.ceil(ps(t,e)-1e-9);;o++){const r=fs(t,o);if(r>n+1e-9)break;i.push({time:r,bar:(o%s+s)%s===0,n:o})}return i}const Ge=100;function m0(t,e,n={}){const s=n.minBpm??70,i=n.maxBpm??180,o=Math.max(1,Math.round(e/Ge)),r=Math.min(t.length,Math.round((n.maxSeconds??60)*e)),a=Math.floor(r/o);if(a<4)return{bpm:120,offset:0,confidence:0};const l=new Float64Array(a);for(let v=0;v<a;v++){let O=0;for(let x=v*o;x<(v+1)*o;x++)O+=t[x]*t[x];l[v]=Math.log(1e-6+O/o)}const c=new Float64Array(a);for(let v=1;v<a;v++)c[v]=Math.max(0,l[v]-l[v-1]);const h=c.reduce((v,O)=>v+O,0)/a;for(let v=0;v<a;v++)c[v]=Math.max(0,c[v]-h);const u=Math.max(1,Math.floor(60*Ge/i)),d=Math.min(a-1,Math.ceil(60*Ge/s)),f=v=>{let O=0;for(let x=v;x<a;x++)O+=c[x]*c[x-v];return O/(a-v)};let g=0;for(let v=0;v<a;v++)g+=c[v]*c[v];g/=a;let p=u,m=-1/0;for(let v=u;v<=d;v++){const O=60*Ge/v,x=Math.exp(-.5*(Math.log2(O/120)/.9)**2),_=f(v)*x;_>m&&(m=_,p=v)}const b=v=>{const O=Math.floor(v);return O<0||O+1>=a?0:c[O]+(c[O+1]-c[O])*(v-O)},k=(v,O)=>{let x=0;for(let _=O;_<a;_+=v)x+=b(_);return x};let w=p,M=0,S=-1/0;for(let v=p-.6;v<=p+.6+1e-9;v+=.02){if(v<1)continue;const O=Math.max(1,Math.round(v*4));for(let x=0;x<O;x++){const _=x/O*v,F=k(v,_);F>S&&(S=F,M=_,w=v)}}const A=60*Ge/w,E=g>0?Math.max(0,Math.min(1,f(p)/g)):0,$=(M+.5)*1e3/Ge;return{bpm:Math.round(A*100)/100,offset:Math.round($%(6e4/A)),confidence:E}}const y0=600,b0=250,dl=1;function w0(t,e){const n=e.target??"Camera",s={x:e.stage.width/2,y:e.stage.height/2},i={},o=(u,d,f,g)=>{const p=i[u]??=[];for(;p.length>0&&p[p.length-1].time>=d;)p.pop();p.push({time:d,value:f,...g?{easing:g}:{}})},r=u=>{const d=u.rotate*Math.PI/180,f=(u.focusX-s.x)*u.scale,g=(u.focusY-s.y)*u.scale;return{x:-(f*Math.cos(d)-g*Math.sin(d)),y:-(f*Math.sin(d)+g*Math.cos(d)),scale:u.scale,rotate:u.rotate}},a=(u,d,f)=>{const g=r(d);for(const p of["x","y","scale","rotate"])o(p,u,g[p],f)};let l={focusX:s.x,focusY:s.y,scale:1,rotate:0};const c=[...t].sort((u,d)=>u.at-d.at),h=c.filter(u=>!("shake"in u));h.length>0&&a(0,l);for(const u of h)if("frame"in u){const d=Math.max(dl,u.duration??y0);a(u.at,l),l={focusX:u.frame.focus?.x??s.x,focusY:u.frame.focus?.y??s.y,scale:u.frame.scale??1,rotate:u.frame.rotate??0},a(u.at+d,l,u.easing??(d>dl?"ease-in-out":void 0))}else{const{follow:d}=u,f=d.lag??b0,g=new Wt({id:"follow",tracks:[{id:"x",target:"s",property:"x",keyframes:d.x}]}),p=k=>g.getStateAtTime(k).values.get("s")?.get("x")??l.focusX,m=[u.at,...d.x.map(k=>k.time).filter(k=>k>u.at&&k<u.until),u.until];a(u.at,l);const b=k=>({focusX:p(k)+(d.lead??0),focusY:d.y??l.focusY,scale:d.scale??l.scale,rotate:l.rotate});for(const k of m){const w=d.x.find(M=>M.time===k)?.easing;a(k+f,b(k),k===u.at?"ease-in-out":w)}l=b(u.until)}for(const u of c.filter(d=>"shake"in d)){const d=u.shake.strength??12,f=u.shake.roll??1.5,g=1e3/(u.shake.frequency??24),p=Xe(u.shake.seed??Math.round(u.at)+1),m=()=>p.next()*2-1;for(const b of["shakeX","shakeY","shakeRotate"])o(b,u.at,0);for(let b=u.at+g;b<u.at+u.duration;b+=g){const k=1-(b-u.at)/u.duration;o("shakeX",b,m()*d*k),o("shakeY",b,m()*d*k),o("shakeRotate",b,m()*f*k)}for(const b of["shakeX","shakeY","shakeRotate"])o(b,u.at+u.duration,0,"ease-out")}return Object.entries(i).map(([u,d])=>({id:`${n}-${u}`,target:n,property:u,keyframes:d}))}function fl(t,e){const n=t.toLowerCase(),s=e.toLowerCase();let i=Array.from({length:s.length+1},(o,r)=>r);for(let o=1;o<=n.length;o++){const r=[o];for(let a=1;a<=s.length;a++)r[a]=Math.min(i[a]+1,r[a-1]+1,i[a-1]+(n[o-1]===s[a-1]?0:1));i=r}return i[s.length]}function An(t,e){const n=t.toLowerCase(),s=e.find(r=>r.toLowerCase().includes(n)||n.includes(r.toLowerCase()));if(s&&Math.min(t.length,s.length)>=3)return s;let i,o=1/0;for(const r of e){const a=fl(t,r);a<o&&(o=a,i=r)}return i!==void 0&&o<=Math.max(2,Math.floor(t.length/3))?i:void 0}function ft(t,e,n,s){const i=typeof e=="string"?s??An(e,n):void 0;return`Unknown ${t} ${JSON.stringify(e)}${i?`: did you mean "${i}"?`:"."} Known: ${n.join(", ")}`}function pl(t,e){const n=e.step??33,s=e.stiffness??120,i=e.damping??9,o=e.mass??1;let r=t(e.start),a=0;const l=[{time:e.start,value:r}];let c=e.start+n;for(let h=e.start+1;h<=e.end;h++){const d=s*(t(h)-r)-i*a;a+=d/o*.001,r+=a*.001,(h>=c||h===e.end)&&(l.push({time:h,value:r}),c+=n)}return l}const Vt=t=>Math.round(t*1e3)/1e3;function gl(t,e={}){if(t.length===0)return"";const n=e.curviness??1,s=e.closed??!1,i=t.length;let o=`M${Vt(t[0].x)} ${Vt(t[0].y)}`;if(i===1)return o;const r=l=>s?t[(l%i+i)%i]:t[Math.max(0,Math.min(i-1,l))],a=s?i:i-1;for(let l=0;l<a;l++){const c=r(l-1),h=r(l),u=r(l+1),d=r(l+2);if(n===0){o+=` L${Vt(u.x)} ${Vt(u.y)}`;continue}const f=n/6,g=h.x+(u.x-c.x)*f,p=h.y+(u.y-c.y)*f,m=u.x-(d.x-h.x)*f,b=u.y-(d.y-h.y)*f;o+=` C${Vt(g)} ${Vt(p)} ${Vt(m)} ${Vt(b)} ${Vt(u.x)} ${Vt(u.y)}`}return s?`${o} Z`:o}const At=(t,e=0)=>{const n=parseFloat(t??"");return Number.isFinite(n)?n:e};function k0(t){const e=(t??"").trim().split(/[\s,]+/).filter(Boolean).map(Number),n=[];for(let s=0;s+1<e.length;s+=2)n.push({x:e[s],y:e[s+1]});return n}function gs(t){const e=t.attributes;switch(t.tag.toLowerCase()){case"path":return e.d??null;case"circle":case"ellipse":{const n=At(e.cx),s=At(e.cy),i=t.tag.toLowerCase()==="circle"?At(e.r):At(e.rx),o=t.tag.toLowerCase()==="circle"?At(e.r):At(e.ry);return`M${n+i} ${s} A${i} ${o} 0 1 1 ${n-i} ${s} A${i} ${o} 0 1 1 ${n+i} ${s} Z`}case"rect":{const n=At(e.x),s=At(e.y),i=At(e.width),o=At(e.height);let r=e.rx!=null?At(e.rx):e.ry!=null?At(e.ry):0,a=e.ry!=null?At(e.ry):r;return r=Math.min(r,i/2),a=Math.min(a,o/2),r===0||a===0?`M${n} ${s} H${n+i} V${s+o} H${n} Z`:`M${n+r} ${s} H${n+i-r} A${r} ${a} 0 0 1 ${n+i} ${s+a} V${s+o-a} A${r} ${a} 0 0 1 ${n+i-r} ${s+o} H${n+r} A${r} ${a} 0 0 1 ${n} ${s+o-a} V${s+a} A${r} ${a} 0 0 1 ${n+r} ${s} Z`}case"line":return`M${At(e.x1)} ${At(e.y1)} L${At(e.x2)} ${At(e.y2)}`;case"polyline":case"polygon":{const n=k0(e.points);if(n.length===0)return null;const s=n.map((i,o)=>`${o===0?"M":"L"}${i.x} ${i.y}`).join(" ");return t.tag.toLowerCase()==="polygon"?`${s} Z`:s}default:return null}}function v0(t,e,n){const s=Math.max(2,Math.round(n.samples??32)),i=Math.max(0,n.length),o=n.since!==void 0?Math.max(e-i,n.since):e-i;if(o>=e)return[];const r=n.period,a=[];for(let l=0;l<s;l++){const c=o+(e-o)*l/(s-1),h=r&&r>0&&l<s-1?(c%r+r)%r:c;a.push({at:t(h),time:c,age:i>0?(e-c)/i:0})}return a}const M0=2.5;function ml(t){const e=[],n=[],s=t.length,i=(o,r)=>{for(let a=o+r;a>=0&&a<s;a+=r){const l=(t[a].x-t[o].x)*r,c=(t[a].y-t[o].y)*r,h=Math.hypot(l,c);if(h>1e-9)return[l/h,c/h]}return null};for(let o=0;o<s;o++){const r=t[o],a=i(o,-1),l=i(o,1),c=a??l??[1,0],h=l??a??[1,0];let u=c[0]+h[0],d=c[1]+h[1];const f=Math.hypot(u,d);f<1e-9?(u=c[0],d=c[1]):(u/=f,d/=f);const g=u*c[0]+d*c[1],p=Math.min(M0,1/Math.max(g,1e-6)),m=r.width/2*p;e.push({x:r.x-d*m,y:r.y+u*m}),n.push({x:r.x+d*m,y:r.y-u*m})}return{left:e,right:n}}function yl(t){const e=t.length;if(e<2)return null;const n=t[e-1];for(let s=e-2;s>=0;s--){const i=n.x-t[s].x,o=n.y-t[s].y,r=Math.hypot(i,o);if(r>1e-9)return{x:n.x,y:n.y,radius:n.width/2,start:Math.atan2(i/r,-o/r)}}return null}function ms(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function Ue(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function Ve(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function he(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function ys(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function bs(t){return Math.hypot(t[0],t[1],t[2])}function to(t,e){return bs(Ue(t,e))}function Te(t){const e=bs(t);return e===0?[0,0,0]:Ve(t,1/e)}function bl(t,e,n){return[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n,t[2]+(e[2]-t[2])*n]}const S0=Object.freeze(Object.defineProperty({__proto__:null,add:ms,cross:ys,distance:to,dot:he,length:bs,lerp:bl,normalize:Te,scale:Ve,subtract:Ue},Symbol.toStringTag,{value:"Module"})),T0=Math.PI/180;function ws(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function bt(t,e){const n=new Array(16);for(let s=0;s<4;s++)for(let i=0;i<4;i++){let o=0;for(let r=0;r<4;r++)o+=t[r*4+i]*e[s*4+r];n[s*4+i]=o}return n}function Ee(t){return[1,0,0,0,0,1,0,0,0,0,1,0,t[0],t[1],t[2],1]}function Ae(t){return[t[0],0,0,0,0,t[1],0,0,0,0,t[2],0,0,0,0,1]}function Yt(t){const[e,n,s,i]=t;return[1-2*(n*n+s*s),2*(e*n+s*i),2*(e*s-n*i),0,2*(e*n-s*i),1-2*(e*e+s*s),2*(n*s+e*i),0,2*(e*s+n*i),2*(n*s-e*i),1-2*(e*e+n*n),0,0,0,0,1]}function eo(t,e,n){const s=Yt(e);for(let i=0;i<3;i++)s[i]*=n[0],s[4+i]*=n[1],s[8+i]*=n[2];return s[12]=t[0],s[13]=t[1],s[14]=t[2],s}function E0(t){const e=new Array(16);for(let n=0;n<4;n++)for(let s=0;s<4;s++)e[s*4+n]=t[n*4+s];return e}function no(t){const[e,n,s,i,o,r,a,l,c,h,u,d,f,g,p,m]=t,b=e*r-n*o,k=e*a-s*o,w=e*l-i*o,M=n*a-s*r,S=n*l-i*r,A=s*l-i*a,E=c*g-h*f,$=c*p-u*f,v=c*m-d*f,O=h*p-u*g,x=h*m-d*g,_=u*m-d*p,F=b*_-k*x+w*O+M*v-S*$+A*E;if(Math.abs(F)<1e-12)return null;const I=1/F;return[(r*_-a*x+l*O)*I,(s*x-n*_-i*O)*I,(g*A-p*S+m*M)*I,(u*S-h*A-d*M)*I,(a*v-o*_-l*$)*I,(e*_-s*v+i*$)*I,(p*w-f*A-m*k)*I,(c*A-u*w+d*k)*I,(o*x-r*v+l*E)*I,(n*v-e*x-i*E)*I,(f*S-g*w+m*b)*I,(h*w-c*S-d*b)*I,(r*$-o*O-a*E)*I,(e*O-n*$+s*E)*I,(g*k-f*M-p*b)*I,(c*M-h*k+u*b)*I]}function A0(t,e,n,s){const i=1/Math.tan(t*T0/2),o=1/(n-s);return[i/e,0,0,0,0,i,0,0,0,0,(s+n)*o,-1,0,0,2*s*n*o,0]}function P0(t,e,n,s,i,o){const r=1/(e-t),a=1/(s-n),l=1/(o-i);return[2*r,0,0,0,0,2*a,0,0,0,0,-2*l,0,-(e+t)*r,-(s+n)*a,-(o+i)*l,1]}function $0(t,e,n=[0,1,0]){const s=Te(Ue(t,e)),i=Te(ys(n,s)),o=ys(s,i);return[i[0],o[0],s[0],0,i[1],o[1],s[1],0,i[2],o[2],s[2],0,-he(i,t),-he(o,t),-he(s,t),1]}function Ct(t,e){const n=t[0]*e[0]+t[4]*e[1]+t[8]*e[2]+t[12],s=t[1]*e[0]+t[5]*e[1]+t[9]*e[2]+t[13],i=t[2]*e[0]+t[6]*e[1]+t[10]*e[2]+t[14],o=t[3]*e[0]+t[7]*e[1]+t[11]*e[2]+t[15];return o===1||o===0?[n,s,i]:[n/o,s/o,i/o]}const x0=Object.freeze(Object.defineProperty({__proto__:null,compose:eo,fromQuat:Yt,identity:ws,invert:no,lookAt:$0,multiply:bt,orthographic:P0,perspective:A0,scaling:Ae,transformPoint:Ct,translation:Ee,transpose:E0},Symbol.toStringTag,{value:"Module"})),ks={"power1.in":[.55,.085,.68,.53],"power1.out":[.25,.46,.45,.94],"power1.inout":[.455,.03,.515,.955],"power2.in":[.55,.055,.675,.19],"power2.out":[.215,.61,.355,1],"power2.inout":[.645,.045,.355,1],"power3.in":[.895,.03,.685,.22],"power3.out":[.165,.84,.44,1],"power3.inout":[.77,0,.175,1],"power4.in":[.755,.05,.855,.06],"power4.out":[.23,1,.32,1],"power4.inout":[.86,0,.07,1],"sine.in":[.47,0,.745,.715],"sine.out":[.39,.575,.565,1],"sine.inout":[.445,.05,.55,.95],"expo.in":[.95,.05,.795,.035],"expo.out":[.19,1,.22,1],"expo.inout":[1,0,0,1],"circ.in":[.6,.04,.98,.335],"circ.out":[.075,.82,.165,1],"circ.inout":[.785,.135,.15,.86],"back.in":[.6,-.28,.735,.045],"back.out":[.175,.885,.32,1.275],"back.inout":[.68,-.55,.265,1.55]},wl={none:"linear",linear:"linear","linear.none":"linear","power1.in":"ease-in-quad","power1.out":"ease-out-quad","power1.inout":"ease-in-out-quad","power2.in":"ease-in-cubic","power2.out":"ease-out-cubic","power2.inout":"ease-in-out-cubic"};function _0(t){let e=t.trim().toLowerCase();e=e.replace(/\.ease(in|out|inout)$/,".$1");const n=/^([a-z]+\d?)(\(.*\))?$/.exec(e);return n&&n[1]!=="steps"&&e!=="none"&&e!=="linear"&&(e=`${n[1]}.out${n[2]??""}`),e}$t({type:"bounce",mode:"in"}),$t({type:"bounce",mode:"in-out"});function Pn(t){const e=kl.get(t.trim().toLowerCase());if(e)return e;const n=_0(t),s=/^steps\(\s*(\d+)\s*\)$/.exec(n);if(s){const r={type:"steps",count:Math.max(1,Number.parseInt(s[1],10))+1,position:"none"};return{easing:r,fn:$t(r)}}const i=/^(elastic|bounce|back)\.(in|out|inout)(?:\(([^)]*)\))?$/.exec(n);if(i){const[,o,r,a]=i,l=(a??"").split(",").map(u=>Number.parseFloat(u)).filter(u=>Number.isFinite(u)),c=r==="inout"?"in-out":r;if(o==="back"&&l.length===0&&n in ks)return{easing:{type:"cubic-bezier",points:ks[n]}};const h=o==="elastic"?{type:"elastic",mode:c,...l[0]!==void 0&&{amplitude:l[0]},...l[1]!==void 0&&{period:l[1]}}:o==="bounce"?{type:"bounce",mode:c}:{type:"back",mode:c,...l[0]!==void 0&&{overshoot:l[0]}};return{easing:h,fn:$t(h)}}return n in wl?{easing:wl[n]}:n in ks?{easing:{type:"cubic-bezier",points:ks[n]}}:{easing:"ease-out"}}const kl=new Map;function so(t,e){return kl.set(t.trim().toLowerCase(),e.bezier?{easing:{type:"cubic-bezier",points:e.bezier},fn:e.fn}:{fn:e.fn,requiresBaking:"custom"}),t}function io(t){let e=t>>>0;return()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}const vl=/^\s*random\(\s*(\[.*\]|[^)]*)\s*\)\s*$/;function Ml(t){return typeof t=="string"&&vl.test(t)}function I0(t=1){let e=io(t);const n=(l,c)=>((...h)=>h.length>=l?c(...h):u=>c(...h,u)),s=(l,c,h)=>Math.min(Math.max(h,Math.min(l,c)),Math.max(l,c)),i=(l,c,h,u,d)=>c===l?h:h+(d-l)/(c-l)*(u-h),o=(l,c)=>{if(typeof l=="number")return l===0?c:Math.round(c/l)*l;if(Array.isArray(l))return Sl(l,c,1/0);if("values"in l)return Sl(l.values,c,l.radius??1/0);const h=Math.round(c/l.increment)*l.increment;return Math.abs(h-c)<=(l.radius??1/0)?h:c},r=(l,c,h)=>{const u=l+e()*(c-l);return h?Math.round(u/h)*h:u};return{clamp:n(3,s),mapRange:n(5,i),normalize:n(3,(l,c,h)=>i(l,c,0,1,h)),interpolate:n(3,(l,c,h)=>{if(typeof l=="object"&&!Array.isArray(l)){const u={};for(const d of Object.keys(l))u[d]=En(l[d])(l[d],c[d],h);return u}return En(l)(l,c,h)}),wrap:((l,c,h)=>{if(Array.isArray(l)){const p=l,m=b=>p[(Math.round(b)%p.length+p.length)%p.length];return c===void 0?m:m(c)}const u=l,f=c-u,g=p=>f===0?u:((p-u)%f+f)%f+u;return h===void 0?g:g(h)}),wrapYoyo:n(3,(l,c,h)=>{const u=c-l;if(u===0)return l;const d=((h-l)%(u*2)+u*2)%(u*2);return l+(d>u?u*2-d:d)}),snap:n(2,o),random:((l,c,h,u)=>{if(Array.isArray(l)){const f=()=>l[Math.floor(e()*l.length)];return c===!0?f:f()}const d=()=>r(l,c,h);return u?d:d()}),shuffle:l=>{for(let c=l.length-1;c>0;c--){const h=Math.floor(e()*(c+1));[l[c],l[h]]=[l[h],l[c]]}return l},distribute:({base:l=0,amount:c,each:h,from:u="start",ease:d})=>(f,g,p)=>{const m=p.length,k=ns(f,m,{...c!==void 0?{amount:c}:{each:h??1},from:u}),w=c!==void 0?c:(h??1)*xi(m,u),M=d&&w>0?d(k/w)*w:k;return l+M},pipe:(...l)=>c=>l.reduce((h,u)=>u(h),c),splitColor:l=>O0(l),getUnit:l=>typeof l=="number"?"":/^-?[\d.]+(?:e[-+]?\d+)?([a-z%]*)$/i.exec(l.trim())?.[1]??"",seed:l=>{e=io(l)},resolveRandomString:l=>{const c=vl.exec(l)?.[1]??"";if(c.startsWith("[")){const g=c.slice(1,-1).split(",").map(p=>p.trim()).filter(Boolean).map(p=>Number.isFinite(Number(p))?Number(p):p.replace(/^['"]|['"]$/g,""));return g[Math.floor(e()*g.length)]}const[h,u,d]=c.split(",").map(f=>Number.parseFloat(f));return r(h,u,Number.isFinite(d)?d:void 0)}}}function Sl(t,e,n){let s=e,i=1/0;for(const o of t){const r=Math.abs(o-e);r<i&&(i=r,s=o)}return i<=n?s:e}function O0(t){const e=t.trim(),n=/^#([0-9a-f]{3,8})$/i.exec(e)?.[1];if(n){const o=(n.length<=4?[...n].map(r=>r+r).join(""):n).match(/../g).map(r=>Number.parseInt(r,16));return o.length>=4?[o[0],o[1],o[2],Math.round(o[3]/255*1e3)/1e3]:[o[0],o[1],o[2]]}const s=(/rgba?\(([^)]+)\)/i.exec(e)?.[1]??"0,0,0").split(/[\s,/]+/).filter(Boolean).map(i=>Number.parseFloat(i));return s.length>=4?[s[0],s[1],s[2],s[3]]:[s[0]??0,s[1]??0,s[2]??0]}const C0=/^([+-])=\s*(-?[\d.]+)$/,H0=/^([<>])\s*(?:([+-])?=?\s*(-?[\d.]+))?$/;function $n(t,e){const n=e.scale??1,s=c=>Number.parseFloat(c)*n;if(t===void 0)return e.cursor;if(typeof t=="number")return t*n;const i=t.trim();if(i==="")return e.cursor;const o=C0.exec(i);if(o){const c=s(o[2]);return e.cursor+(o[1]==="-"?-c:c)}const r=H0.exec(i);if(r){const c=r[1]==="<"?e.previousStart:e.previousEnd;if(r[3]===void 0)return c;const h=s(r[3]);return c+(r[2]==="-"?-h:h)}const a=/^(.+?)([+-])=\s*(-?[\d.]+)$/.exec(i);if(a){const c=e.labels.get(a[1].trim());if(c!==void 0){const h=s(a[3]);return c+(a[2]==="-"?-h:h)}}const l=e.labels.get(i);return l!==void 0?l:/^-?[\d.]+$/.test(i)?s(i):e.cursor}function R0(t){if(typeof t!="object"||t===null)return!1;const e=t;return e.grid!==void 0||e.from==="random"||Array.isArray(e.from)||e.ease!==void 0||e.axis!==void 0}function L0(t,e,n={}){if(t===0)return[];const s=e.grid==="auto"?Math.max(1,Math.min(t,n.columnsFromLayout?.()??t)):Array.isArray(e.grid)?Math.max(1,e.grid[1]):t,i=Array.isArray(e.grid)?Math.max(1,e.grid[0]):Math.ceil(t/s),o=g=>({x:g%s,y:Math.floor(g/s)}),r=e.from??"start",a=Array.isArray(r)?{x:r[0]*(s-1),y:r[1]*(i-1)}:typeof r=="number"?o(Math.max(0,Math.min(t-1,r))):r==="end"?o(t-1):r==="center"||r==="edges"?{x:(s-1)/2,y:(i-1)/2}:{x:0,y:0},l=g=>{const{x:p,y:m}=o(g),b=Math.abs(p-a.x),k=Math.abs(m-a.y);return e.axis==="x"?b:e.axis==="y"?k:Math.hypot(b,k)};let c=Array.from({length:t},(g,p)=>l(p));const h=Math.max(...c);if(r==="edges"&&(c=c.map(g=>h-g)),r==="random"){const g=n.random??Math.random;c=c.map(()=>g()*h)}const u=e.amount!==void 0?e.amount:(e.each??0)*h,d=e.ease?Pn(e.ease):void 0,f=d?d.fn??$t(d.easing):void 0;return c.map(g=>{const p=h===0?0:g/h;return(f?f(p):p)*u})}const oo=new Set(["duration","delay","ease","repeat","repeatDelay","yoyo","stagger","onComplete","onUpdate","onStart","onRepeat","onReverseComplete","repeatRefresh","keyframes","easeEach","scrollTo","id","immediateRender","overwrite","paused","scrollTrigger","spring"]),F0={rotation:"rotate",rotationZ:"rotate",rotationX:"rotateX",rotationY:"rotateY",transformPerspective:"perspective",perspective:"childPerspective"};function vs(t){const e={},n={};for(const[s,i]of Object.entries(t))oo.has(s)?e[s]=i:n[F0[s]??s]=i;return{config:e,properties:n}}function Ms(t,e){return t===void 0?e:t*1e3}function ro(t,e){if(t!==void 0)return typeof t=="number"?{each:t*1e3}:R0(t)?{offsets:L0(e?.count??0,t,e??{}).map(s=>s*1e3)}:{...t.each!==void 0&&{each:t.each*1e3},...t.amount!==void 0&&{amount:t.amount*1e3},...t.from!==void 0&&{from:t.from}}}const D0={opacity:1,x:0,y:0,z:0,rotate:0,rotateX:0,rotateY:0,rotateZ:0,scale:1,scaleX:1,scaleY:1,scaleZ:1,skewX:0,skewY:0,originX:50,originY:50,perspective:0,blur:0,glow:0,clipTop:0,clipRight:0,clipBottom:0,clipLeft:0};function Tl(t){return D0[t]}function N0(t){const e=typeof t=="string"||Array.isArray(t)?{path:t}:t;if(!e||typeof e.path!="string"&&!Array.isArray(e.path))throw new Error("gsap-compat: motionPath needs a path — SVG path data or an array of { x, y } points.");let n;if(Array.isArray(e.path))n=gl(e.path,{curviness:e.curviness});else if(qe(e.path))n=e.path;else throw new Error(`gsap-compat: motionPath "${e.path}" is not path data. Selectors and elements are resolved by live.to(); timeline() and tf need the path data itself.`);const s={pathData:n};return e.autoRotate!==void 0&&e.autoRotate!==!1&&(s.autoRotate=!0,typeof e.autoRotate=="number"&&(s.rotateOffset=e.autoRotate)),e.matrix&&(s.matrix=e.matrix),{config:s,start:e.start??0,end:e.end??1}}function B0(t){const e=typeof t=="string"||Array.isArray(t)?{path:t}:{...t};return{...e,start:e.end??1,end:e.start??0}}function El(t){return typeof t=="object"&&t!==null&&"shape"in t?t.shape:t}function W0(t){if(t.morphSVG===void 0)return t;const{morphSVG:e,...n}=t,s=El(e);if(typeof s!="string"||!qe(s))throw new Error(`gsap-compat: morphSVG "${String(s)}" is not path data. Selectors and elements are resolved by live.to(); timeline() and tf need the path data itself.`);return{...n,d:s}}function j0(t,e){if(t===!0)return[0,e];if(t===!1)return[0,0];if(typeof t=="number")return[0,Al(t,e)];const n=t.trim().split(/[\s,]+/).filter(Boolean),s=r=>{const a=Number.parseFloat(r);if(Number.isNaN(a))throw new Error(`gsap-compat: drawSVG "${t}" is not a length or percentage`);return Al(r.endsWith("%")?e*a/100:a,e)};if(n.length===0)return[0,e];if(n.length===1)return[0,s(n[0])];const i=s(n[0]),o=s(n[1]);return i<=o?[i,o]:[o,i]}function q0(t,e){const[n,s]=j0(t,e);return{strokeDasharray:[s-n,e],strokeDashoffset:-n}}function K0(t,e){if(t.drawSVG===void 0)return t;const{drawSVG:n,...s}=t;return{...s,...q0(n,e)}}function Y0(t){if(t.drawSVG!==void 0)throw new Error("gsap-compat: drawSVG needs the stroke length from the page. Use live.to(), or animate strokeDasharray / strokeDashoffset directly (see drawSvgProperties).");return t}function Al(t,e){return Math.max(0,Math.min(e,t))}function z0(t){let e=2166136261;for(let n=0;n<t.length;n++)e=Math.imul(e^t.charCodeAt(n),16777619);return e>>>0}function X0(t,e,n){if(t.scrambleText!==void 0){const s=t.scrambleText,i=typeof s=="string"?{text:s}:s;if(typeof i?.text!="string")throw new Error("gsap-compat: scrambleText needs the text to end on — a string, or { text }.");const o=i.revealDelay&&n>0?i.revealDelay*1e3/n:void 0;return{to:i.text,mode:"scramble",...i.chars!==void 0&&{chars:i.chars},...i.speed!==void 0&&{refreshRate:20*i.speed},...o!==void 0&&{revealDelay:Math.min(o,.999)},...i.tweenLength!==void 0&&{tweenLength:i.tweenLength},...i.rightToLeft!==void 0&&{rightToLeft:i.rightToLeft},seed:i.seed??z0(`${e}|${i.text}`)}}if(t.text!==void 0){const s=t.text,i=typeof s=="string"?{value:s}:s;if(typeof i?.value!="string")throw new Error("gsap-compat: text needs the text to end on — a string, or { value }.");return{to:i.value,mode:"type",...i.rightToLeft!==void 0&&{rightToLeft:i.rightToLeft}}}}function ao(t){return Math.max(.1,t/25)}function G0(t,e){const n=typeof e=="number"?{velocity:e}:e;if(typeof n?.velocity!="number"||!Number.isFinite(n.velocity))throw new Error("gsap-compat: inertia needs a velocity for each property — a number, or { velocity }.");const s=n.friction??(n.resistance!==void 0?ao(n.resistance):void 0),i={from:t,velocity:n.velocity,...s!==void 0&&{friction:s},...n.min!==void 0&&{min:n.min},...n.max!==void 0&&{max:n.max}};return typeof n.end=="function"?i.end=[n.end(kn(i))]:n.end!==void 0&&(i.end=Array.isArray(n.end)?[...n.end]:n.end),i}function U0(t){const e=t===!0?{}:typeof t=="string"?{preset:t}:t;if(e.preset!==void 0&&!(e.preset in os))throw new Error(`gsap-compat: unknown spring preset "${e.preset}" — use one of ${Object.keys(os).join(", ")}`);return{...e.preset?os[e.preset]:{},...e.stiffness!==void 0&&{stiffness:e.stiffness},...e.damping!==void 0&&{damping:e.damping},...e.mass!==void 0&&{mass:e.mass},...e.restDelta!==void 0&&{restDelta:e.restDelta}}}function V0(t,e){if(t===!0||typeof t=="string")return;const n=t.velocity;return typeof n=="number"?n:n?.[e]}class Pe{timeline;options;cursor=0;fallbackRandom=io(1);previousStart=0;previousEnd=0;labels=new Map;trackCounter=0;lastValues=new Map;constructor(e={}){this.options=e,this.timeline=new Wt({id:e.id??"gsap-compat",name:e.name,config:{...e.repeat!==void 0&&{loop:e.repeat},...e.yoyo!==void 0&&{alternate:e.yoyo},...e.repeatDelay!==void 0&&{repeatDelay:e.repeatDelay*1e3},...e.timeScale!==void 0&&{speed:e.timeScale}}})}to(e,n,s){return this.build(e,void 0,xn(n),s)}from(e,n,s){const{config:i,properties:o}=vs(xn(n)),{motionPath:r,text:a,scrambleText:l,...c}=o,h=this.targetsOf(e)[0],u={...i};for(const g of Object.keys(c))u[g]=this.resolveStart(h,g);r!==void 0&&(u.motionPath=B0(r));const d={},f=String(this.resolveStart(h,"text"));return a!==void 0&&(d.text=lo(a),u.text=typeof a=="object"?{...a,value:f}:f),l!==void 0&&(d.text=lo(l),u.scrambleText=typeof l=="object"?{...l,text:f}:f),this.build(e,{...c,...d},u,s)}fromTo(e,n,s,i){const{properties:o}=vs(xn(n));return this.build(e,o,xn(s),i)}set(e,n,s){return this.build(e,void 0,{...xn(n),duration:0},s)}get lastStart(){return this.previousStart}get lastEnd(){return this.previousEnd}addEvent(e){const n=Math.max(0,$n(e,this.context()));return this.previousStart=n,this.previousEnd=n,this.cursor=Math.max(this.cursor,n),n}timeOf(e){return $n(e,this.context())}addLabel(e,n){return this.labels.set(e,$n(n,this.context())),this}labelTimes(){return[...this.labels.values()].sort((e,n)=>e-n)}labelTime(e){return this.labels.get(e)}add(e,n){const s=$n(n,this.context());for(const o of e.timeline.tracks){if(!("keyframes"in o))continue;const r=us({...o,id:this.nextTrackId(`nested-${o.id}`),keyframes:o.keyframes.map(a=>({...a,time:a.time+s}))});this.timeline.addTrack(r)}const i=s+e.timeline.duration;return this.previousStart=s,this.previousEnd=i,this.cursor=Math.max(this.cursor,i),this}play(){return this.timeline.play(),this}pause(){return this.timeline.pause(),this}restart(){return this.timeline.stop(),this.timeline.play(),this}reverse(){return this.timeline.reverse(),this}kill(){return this.timeline.removeTracks(),this}reset(){return this.timeline.removeTracks(),this.cursor=0,this.previousStart=0,this.previousEnd=0,this.labels.clear(),this.lastValues.clear(),this.trackCounter=0,this}seek(e){if(typeof e=="string"){const n=this.labels.get(e);return n!==void 0&&this.timeline.seek(n),this}return this.timeline.seek(e*1e3),this}progress(e){const n=this.timeline.duration;return e!==void 0&&n>0&&this.timeline.seek(e*n),n>0?this.timeline.currentTime/n:0}timeScale(e){return e!==void 0&&(this.timeline.speed=e),this.timeline.speed}duration(){return this.timeline.duration/1e3}tick(e){return this.timeline.tick(e),this}toDefinition(){return this.timeline.toDefinition()}build(e,n,s,i){const{config:o,properties:r}=vs(s),{motionPath:a,text:l,scrambleText:c,inertia:h,...u}=r,d=this.targetsOf(e),f=$n(i,this.context()),g=Ms(o.delay,0),p=Ms(o.duration,500),m=ro(o.stagger,{count:d.length,columnsFromLayout:this.options.layoutColumns?()=>this.options.layoutColumns(d):void 0,random:this.options.random??this.fallbackRandom}),b=this.easingFor(o.ease),k=[],w=o.spring;let M=0,S=!1;for(const[x,_]of Object.entries(u)){const F=_;let I=n?.[x]!==void 0?n[x]:this.resolveStart(d[0],x);if(typeof I!=typeof F&&(this.warn(`no usable start value for "${x}" on "${d[0]}" — it will snap to ${String(F)}. Use fromTo() to animate it.`),I=F),w!==void 0&&(typeof I!="number"||typeof F!="number")&&this.warn(`spring works on numbers, so "${x}" on "${d[0]}" eases instead`),w!==void 0&&typeof I=="number"&&typeof F=="number"){const Y={...U0(w),from:I,to:F,velocity:V0(w,x)??this.options.startVelocity?.(d[0],x)??0},j=this.nextTrackId(`${d[0]}-${x}-spring`),U={id:j,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:x,kind:"spring",spring:Y,delay:f+g};this.timeline.addTrack(U),k.push(j),M=Math.max(M,ha(Y));for(const J of d)this.lastValues.set(`${J}|${x}`,F);continue}S=!0;const L=this.keyframesFor(I,F,p,b,o.ease),N=this.nextTrackId(`${d[0]}-${x}`);this.timeline.addTrack(us({id:N,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:x,delay:f+g,keyframes:L,...x==="quaternion"&&{interpolation:"slerp"}})),k.push(N);for(const Y of d)this.lastValues.set(`${Y}|${x}`,F)}const A=X0({text:l,scrambleText:c},d[0],p);if(A){const x=n?.text??n?.scrambleText,_=x!==void 0?lo(x):this.resolveStart(d[0],"text"),F=this.nextTrackId(`${d[0]}-text`),I={id:F,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:"text",textConfig:{from:typeof _=="string"?_:String(_??""),...A},delay:f+g,keyframes:this.keyframesFor(0,1,p,b,o.ease)};this.timeline.addTrack(I),k.push(F);for(const L of d)this.lastValues.set(`${L}|text`,A.to)}if(a!==void 0){const{config:x,start:_,end:F}=N0(a),I=this.nextTrackId(`${d[0]}-motionPath`),L={id:I,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:"motionPath",motionPathConfig:x,delay:f+g,keyframes:this.keyframesFor(_,F,p,b,o.ease)};this.timeline.addTrack(L),k.push(I)}if(h!==void 0)for(const[x,_]of Object.entries(h)){const F=this.resolveStart(d[0],x);if(typeof F!="number"){this.warn(`inertia on "${x}" needs a numeric start value; skipped`);continue}const I=G0(F,_),L=this.nextTrackId(`${d[0]}-${x}-inertia`),N={id:L,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:x,kind:"inertia",inertia:I,delay:f+g};this.timeline.addTrack(N),k.push(L),M=Math.max(M,We(I));for(const Y of d)this.lastValues.set(`${Y}|${x}`,Be(I))}const v=((h!==void 0||w!==void 0)&&!S&&!A&&a===void 0?M:Math.max(p,M))+(m&&d.length>1?bn(d.length,m):0),O=f+g+v;return this.previousStart=f+g,this.previousEnd=O,this.cursor=Math.max(this.cursor,O),{trackIds:k,start:f+g,end:O,kill:()=>{for(const x of k)this.timeline.removeTrack(x)}}}keyframesFor(e,n,s,i,o){const r={time:0,value:e};if(s<=0)return[{time:0,value:n}];const a=typeof o=="string"?Pn(o):void 0;if(a?.requiresBaking==="custom"||this.options.bakeEases&&yn(i)){const c=a?.fn??$t(i);return[r,...zi(r,{time:s,value:n},c,{intervalMs:this.options.bakeIntervalMs})]}return[r,{time:s,value:n,...i&&{easing:i}}]}resolveStart(e,n){const s=this.lastValues.get(`${e}|${n}`);if(s!==void 0)return s;const i=this.options.startValue?.(e,n);if(i!==void 0)return i;const o=this.options.defaults?.[n];if(o!==void 0)return o;if(n==="text")return"";if(n==="quaternion")return[0,0,0,1];if(n==="d")throw new Error(`gsap-compat: no starting shape for "${e}". Use fromTo({ d: … }, { morphSVG: … }), or live.to(), which reads the element's current shape.`);const r=Tl(n);return r!==void 0?(this.warn(`no start value for "${n}" on "${e}" — using the static default ${r}. GSAP would read the live DOM here; tinyfly cannot, so pass an explicit fromTo() or a defaults map.`),r):(this.warn(`no start value or default for "${n}" on "${e}" — using 0`),0)}easingFor(e){if(e!==void 0){if(typeof e=="string")return Pn(e).easing;if(typeof e=="function")throw new Error('gsap-compat: function eases cannot be serialized. Use a named ease, or a cubic-bezier via { type: "cubic-bezier", points: [...] }.');return e}}targetsOf(e){return Array.isArray(e)?e:[e]}context(){return{cursor:this.cursor,previousStart:this.previousStart,previousEnd:this.previousEnd,labels:this.labels,scale:1e3}}nextTrackId(e){return this.trackCounter+=1,`${e}-${this.trackCounter}`}warn(e){this.options.onWarning?.(`gsap-compat: ${e}`)}}function lo(t){if(typeof t=="string")return t;if(t&&typeof t=="object"){const e=t;return String(e.value??e.text??"")}return String(t??"")}function J0(t){return new Pe(t)}function xn(t){return Y0(W0(t))}function Z0(t){return!Array.isArray(t)||t.length!==4?null:`matrix3d(${Yt(le(t)).map(n=>Math.round(n*1e6)/1e6+0).join(", ")})`}const Q0=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),tp="#ffffff",ep="rgba(0, 0, 0, 0.5)";function np(t){const e=[];if(t.blur!==void 0&&e.push(`blur(${Math.max(0,t.blur)}px)`),t.brightness!==void 0&&e.push(`brightness(${Math.max(0,t.brightness)})`),t.glow!==void 0&&e.push(`drop-shadow(0 0 ${Math.max(0,t.glow)}px ${t.glowColor??tp})`),t.shadowX!==void 0||t.shadowY!==void 0||t.shadowBlur!==void 0){const n=t.shadowX??0,s=t.shadowY??0,i=Math.max(0,t.shadowBlur??0);e.push(`drop-shadow(${n}px ${s}px ${i}px ${t.shadowColor??ep})`)}return e.length>0?e.join(" "):null}function sp(t,e){const n=t.childNodes.length===1?t.firstChild:null;if(n&&n.nodeType===3){const s=n;s.data!==e&&(s.data=e);return}t.textContent!==e&&(t.textContent=e)}function ip(t){if(!("ownerSVGElement"in t))return;const e=t.style;!e||e.transformBox||(e.transformBox="fill-box",e.transformOrigin||(e.transformOrigin="50% 50%"))}const Pl=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"]),op=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),rp=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],ap=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),lp=new Set(["originX","originY"]),cp=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),hp=new Set(["drawOn"]),up={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},$l={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},dp="http://www.w3.org/2000/svg";class $e{targets=new Map;registerTarget(e,n){this.targets.set(e,n)}unregisterTarget(e){this.targets.delete(e)}getTarget(e){return this.targets.get(e)}clearTargets(){this.targets.clear()}applyState(e){for(const[n,s]of e.values){const i=this.targets.get(n);i&&this.applyProperties(i,s)}}applyProperties(e,n){let s=null,i=null,o=null,r=null,a=null;const l=n.has("motionPathX"),c=n.has("motionPathY"),h=n.has("motionPathRotate");for(const[g,p]of n)if(!(g==="x"&&l)&&!(g==="y"&&c)&&!((g==="rotate"||g==="rotateZ")&&h)&&!hp.has(g)){if(op.has(g))(s??={})[g]=p;else if(ap.has(g))typeof p=="number"&&((i??={})[g]=p);else if(lp.has(g))typeof p=="number"&&((o??={})[g]=p);else if(cp.has(g))typeof p=="number"&&((r??={})[g]=p);else if(Q0.has(g))(a??={})[g]=p;else if(g!=="perspective"){if(g!=="shine")if(g==="text"&&typeof p=="string")sp(e,p);else if(g==="d"&&typeof p=="string"){const m=e;(m.tagName?.toLowerCase()==="path"?m:m.querySelector?.("path"))?.setAttribute?.("d",p)}else this.applyStyleProperty(e,g,p)}}const u=n.get("shine");typeof u=="number"&&this.applyShine(e,u);const d=[],f=n.get("perspective");if(typeof f=="number"&&f>0&&d.push(`perspective(${f}px)`),s)for(const g of rp){const p=s[g];if(p===void 0)continue;const m=this.buildTransformPart(g,p);m&&d.push(m)}if(d.length>0&&(e.style.transform=d.join(" "),ip(e)),i&&(i.childPerspective!==void 0&&(e.style.perspective=`${i.childPerspective}px`),(i.perspectiveOriginX!==void 0||i.perspectiveOriginY!==void 0)&&(e.style.perspectiveOrigin=`${i.perspectiveOriginX??50}% ${i.perspectiveOriginY??50}%`)),o){const g=o.originX??50,p=o.originY??50;e.style.transformOrigin=`${g}% ${p}%`}if(r){const g=r.clipTop??0,p=r.clipRight??0,m=r.clipBottom??0,b=r.clipLeft??0;e.style.clipPath=`inset(${g}% ${p}% ${m}% ${b}%)`}if(a){const g=np(a);g&&(e.style.filter=g)}}buildTransformPart(e,n){if(e==="quaternion")return Z0(n);if(typeof n!="number")return null;switch(e){case"x":case"motionPathX":return`translateX(${n}px)`;case"y":case"motionPathY":return`translateY(${n}px)`;case"z":return`translateZ(${n}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${n}deg)`;case"rotateX":return`rotateX(${n}deg)`;case"rotateY":return`rotateY(${n}deg)`;case"scale":return`scale(${n})`;case"scaleX":return`scaleX(${n})`;case"scaleY":return`scaleY(${n})`;case"scaleZ":return`scaleZ(${n})`;case"skewX":return`skewX(${n}deg)`;case"skewY":return`skewY(${n}deg)`;default:return null}}applyShine(e,n){e.dataset.shineBase||(e.dataset.shineBase=e.style.color||"currentColor");const s=e.dataset.shineBase,i=-20+n*140,o=e.style;o.color="transparent",o.backgroundImage=`linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${s}, ${s})`,o.backgroundSize="250% 100%, 100% 100%",o.backgroundPosition=`${i}% 0, 0 0`,o.backgroundRepeat="no-repeat",o.webkitBackgroundClip="text",o.backgroundClip="text"}applyStyleProperty(e,n,s){let i;if(e.namespaceURI===dp&&n in $l){const a=Array.isArray(s)?s.join(", "):String(s);e.style[$l[n]]=a;return}else n==="fill"&&e.dataset?.elementType==="text"?i="color":i=up[n]??n;let r;typeof s=="number"?Pl.has(n)||Pl.has(i)?r=`${s}px`:r=String(s):Array.isArray(s)?r=s.join(", "):r=s,e.style[i]=r}}const fp={request:t=>requestAnimationFrame(t),cancel:t=>cancelAnimationFrame(t)};class xl{adapter=new $e;scheduler;rootOption;onWarning;names=new WeakMap;elements=new Map;nameCounter=0;objectNames=new WeakMap;objects=new Map;owned=new Set;currentCollector;tickerCallbacks=new Set;tickerTime=0;tickerFrame=0;liveTimelines=new Set;utils=I0();active=new Map;applied=new Map;dirty=new Set;frameId=null;lastTimestamp=null;destroyed=!1;constructor(e={}){this.scheduler=e.scheduler??fp,this.rootOption=e.root,this.onWarning=e.onWarning}get root(){return this.rootOption??document}resolveTargets(e){const n=[];for(const s of this.targetsOf(e)){const i=this.nameFor(s);co(s)&&this.currentCollector?.touch(s,i),n.push(i)}return n}query(e){return this.selectorRoot.querySelector(e)}get collector(){return this.currentCollector}setCollector(e){this.currentCollector=e}forget(e){this.applied.delete(e),this.dirty.delete(e)}get selectorRoot(){return this.currentCollector?.scope??this.root}elementFor(e){return this.elements.get(e)}objectFor(e){return this.objects.get(e)}appliedValue(e,n){return this.applied.get(e)?.get(n)}velocityOf(e,n){for(const i of[...this.active.keys()].reverse()){if(i.getTracks({target:e,property:n}).length===0)continue;const o=i.currentTime;if(o<4)return 0;const r=i.getStateAtTime(o).values.get(e)?.get(n),a=i.getStateAtTime(o-4).values.get(e)?.get(n);if(typeof r!="number"||typeof a!="number")return;const l=(r-a)/4;return(i.direction==="reverse"?-l:l)*1e3}}ticker={add:e=>{this.destroyed||(this.tickerCallbacks.size===0&&(this.tickerTime=0,this.tickerFrame=0),this.tickerCallbacks.add(e),this.currentCollector?.track({revert:()=>this.ticker.remove(e)}),this.startLoop())},remove:e=>{this.tickerCallbacks.delete(e),this.running||this.stopLoop()}};activate(e,n={}){this.destroyed||(e.onUpdate=s=>this.write(s),this.active.delete(e),this.active.set(e,n),this.startLoop())}deactivate(e){this.active.delete(e),this.running||this.stopLoop()}own(e){return this.destroyed?e.destroy():this.owned.add(e),e}destroy(){this.destroyed=!0;for(const e of this.owned)e.destroy();this.owned.clear();for(const e of this.active.keys())e.stop();this.active.clear(),this.stopLoop(),this.adapter.clearTargets(),this.elements.clear(),this.names=new WeakMap,this.objects.clear(),this.objectNames=new WeakMap,this.tickerCallbacks.clear(),this.liveTimelines.clear(),this.applied.clear(),this.dirty.clear()}apply(e,n){if(this.destroyed)return;const s=new Map(Object.entries(n));this.write({values:new Map([[e,s]]),currentTime:0,playbackState:"idle",direction:"forward",loopIteration:0}),this.flush()}render(e){this.destroyed||(this.write(e.getStateAtTime(e.currentTime)),this.flush())}tick(e){const n=[...this.active];for(const[s]of n)s.duration<=0?(this.write(s.getStateAtTime(0)),s.stop()):s.tick(e);this.flush();for(const[s,i]of n)i.onUpdate?.(),s.playbackState!=="playing"&&this.active.get(s)===i&&this.active.delete(s);this.flush(),this.runTicker(e),this.running||this.stopLoop()}get running(){return this.active.size>0||this.tickerCallbacks.size>0}runTicker(e){if(this.tickerCallbacks.size!==0){this.tickerTime+=e,this.tickerFrame+=1;for(const n of[...this.tickerCallbacks])n(this.tickerTime/1e3,e,this.tickerFrame)}}write(e){for(const[n,s]of e.values){let i=this.applied.get(n);i||(i=new Map,this.applied.set(n,i));for(const[o,r]of s)i.set(o,r);this.dirty.add(n)}}flush(){if(this.dirty.size===0)return;const e=new Map;for(const n of this.dirty){const s=this.applied.get(n),i=this.objects.get(n);if(i)for(const[o,r]of s)i[o]=r;else e.set(n,s)}this.dirty.clear(),e.size!==0&&this.adapter.applyState({values:e,currentTime:0,playbackState:"playing",direction:"forward",loopIteration:0})}frame=e=>{this.frameId=null;const n=this.lastTimestamp===null?0:e-this.lastTimestamp;this.lastTimestamp=e,n>0&&this.tick(n),this.running&&this.frameId===null&&(this.frameId=this.scheduler.request(this.frame))};startLoop(){this.frameId===null&&(this.lastTimestamp=null,this.frameId=this.scheduler.request(this.frame))}stopLoop(){this.frameId!==null&&this.scheduler.cancel(this.frameId),this.frameId=null,this.lastTimestamp=null}targetsOf(e){if(typeof e=="string")return Array.from(this.selectorRoot.querySelectorAll(e));if(co(e))return[e];if(!pp(e))return[e];const n=[];for(const s of Array.from(e))n.push(...this.targetsOf(s));return n}nameFor(e){return co(e)?this.elementName(e):this.objectName(e)}objectName(e){const n=this.objectNames.get(e);if(n)return n;let s;do this.nameCounter+=1,s=`obj-${this.nameCounter}`;while(this.objects.has(s)||this.elements.has(s));return this.objectNames.set(e,s),this.objects.set(s,e),s}elementName(e){const n=this.names.get(e);if(n)return n;let s=e.id?`#${e.id}`:"";if(!s||this.elements.has(s))do this.nameCounter+=1,s=`el-${this.nameCounter}`;while(this.elements.has(s));return this.names.set(e,s),this.elements.set(s,e),this.adapter.registerTarget(s,e),s}}function co(t){return typeof t=="object"&&t!==null&&t.nodeType===1}function pp(t){if(Array.isArray(t))return!0;const e=t;return typeof e.length=="number"&&typeof e.item=="function"}function Ss(t){const e=t.style;if(!e)return t.getBoundingClientRect();const n=e.transform;e.transform="none";const s=t.getBoundingClientRect();return e.transform=n,s}const _l=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function gp(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function mp(t){const e=t.getScreenCTM?.();if(e)return[e.a,e.b,e.c,e.d,e.e,e.f];const n=t.getBoundingClientRect();return[1,0,0,1,n.left,n.top]}function yp(t,e){const n=typeof t=="string"||Array.isArray(t)||_l(t)?{path:t}:t,{align:s,alignOrigin:i,path:o,...r}=n,a=A=>{const E=_l(A)?A:e.query(A);return E||e.warn(`gsap-compat: motionPath could not find "${String(A)}"`),E};let l=null,c="";if(Array.isArray(o)||typeof o=="string"&&qe(o))c=o;else{l=a(o);const A=l&&gs({tag:l.localName,attributes:gp(l)});l&&!A&&e.warn(`gsap-compat: motionPath element <${l.localName}> has no path geometry`),c=A??""}const h={...r,path:c};if(s===void 0||s===!1)return h;const u=s===!0?l:a(s);if(!u)return s===!0&&e.warn("gsap-compat: motionPath align: true needs the path to be an element"),h;const d=e.targets[0];if(!d)return h;const[f,g,p,m,b,k]=mp(u),w=Ss(d),[M,S]=i??[.5,.5];for(const A of e.targets.slice(1)){const E=Ss(A);if(Math.abs(E.left-w.left)>.5||Math.abs(E.top-w.top)>.5){e.warn("gsap-compat: motionPath align measures the first target; the others are laid out elsewhere");break}}return h.matrix=[f,g,p,m,b-w.left-M*w.width,k-w.top-S*w.height],h}const Il=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function Ol(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function Cl(t){if(!t)return null;const e=gs({tag:t.localName,attributes:Ol(t)});return e||(t.querySelector("path")?.getAttribute("d")??null)}function bp(t,e,n){const s=El(t);if(typeof s=="string"&&qe(s))return s;const i=Il(s)?s:typeof s=="string"?e(s):null,o=Cl(i);return o||(n(`gsap-compat: morphSVG could not find a shape for "${String(s)}"`),"")}const wp=new Set(["cx","cy","r","rx","ry","x","y","width","height","x1","y1","x2","y2","points"]);function kp(t,e=document){return(typeof t=="string"?Array.from(e.querySelectorAll(t)):Il(t)?[t]:Array.from(t)).map(s=>{if(s.localName==="path")return s;const i=gs({tag:s.localName,attributes:Ol(s)});if(!i||!s.parentNode)return s;const o=s.ownerDocument.createElementNS("http://www.w3.org/2000/svg","path");for(const r of Array.from(s.attributes))wp.has(r.name)||o.setAttribute(r.name,r.value);return o.setAttribute("d",i),s.parentNode.replaceChild(o,s),o})}const Hl=.3;class Rl{options;target;running=!1;dragging=!1;passedTolerance=!1;lastX=0;lastY=0;startX=0;startY=0;velocityX=0;velocityY=0;lastTime=0;constructor(e){this.options=e,this.target=e.target}start(){if(this.running)return;this.running=!0;const e=this.options.type??["pointer","touch"];e.includes("pointer")&&(this.target.addEventListener("pointerdown",this.onPointerDown),this.target.addEventListener("pointermove",this.onPointerMove),this.target.addEventListener("pointerup",this.onPointerUp),this.target.addEventListener("pointercancel",this.onPointerUp)),e.includes("touch")&&(this.target.addEventListener("touchstart",this.onTouchStart,{passive:!1}),this.target.addEventListener("touchmove",this.onTouchMove,{passive:!1}),this.target.addEventListener("touchend",this.onTouchEnd)),e.includes("wheel")&&this.target.addEventListener("wheel",this.onWheel,{passive:!1})}stop(){this.running&&(this.running=!1,this.target.removeEventListener("pointerdown",this.onPointerDown),this.target.removeEventListener("pointermove",this.onPointerMove),this.target.removeEventListener("pointerup",this.onPointerUp),this.target.removeEventListener("pointercancel",this.onPointerUp),this.target.removeEventListener("touchstart",this.onTouchStart),this.target.removeEventListener("touchmove",this.onTouchMove),this.target.removeEventListener("touchend",this.onTouchEnd),this.target.removeEventListener("wheel",this.onWheel))}destroy(){this.stop()}get velocity(){return{x:this.velocityX,y:this.velocityY}}begin(e,n,s){this.dragging=!0,this.passedTolerance=!1,this.startX=e,this.startY=n,this.lastX=e,this.lastY=n,this.velocityX=0,this.velocityY=0,this.lastTime=Ll(),this.options.onPress?.(this.stateFrom(0,0,s))}move(e,n,s){if(!this.dragging)return;const i=e-this.lastX,o=n-this.lastY;this.lastX=e,this.lastY=n;const r=e-this.startX,a=n-this.startY,l=this.options.tolerance??3;if(!this.passedTolerance){if(Math.hypot(r,a)<l)return;this.passedTolerance=!0}this.updateVelocity(i,o),this.options.preventDefault!==!1&&s.cancelable&&s.preventDefault(),this.options.onMove?.(this.stateFrom(i,o,s))}end(e){this.dragging&&(this.dragging=!1,this.options.onRelease?.(this.stateFrom(0,0,e)))}updateVelocity(e,n){const s=Ll(),i=Math.max(1,s-this.lastTime);this.lastTime=s;const o=e/i*1e3,r=n/i*1e3;this.velocityX+=(o-this.velocityX)*Hl,this.velocityY+=(r-this.velocityY)*Hl}stateFrom(e,n,s){return{deltaX:e,deltaY:n,velocityX:this.velocityX,velocityY:this.velocityY,totalX:this.lastX-this.startX,totalY:this.lastY-this.startY,isDragging:this.dragging,event:s}}onPointerDown=e=>{const n=e,s=this.target;if(typeof n.pointerId=="number"&&typeof s.setPointerCapture=="function")try{s.setPointerCapture(n.pointerId)}catch{}this.begin(n.clientX,n.clientY,e)};onPointerMove=e=>{const n=e;this.move(n.clientX,n.clientY,e)};onPointerUp=e=>this.end(e);onTouchStart=e=>{const n=e.touches[0];n&&this.begin(n.clientX,n.clientY,e)};onTouchMove=e=>{const n=e.touches[0];n&&this.move(n.clientX,n.clientY,e)};onTouchEnd=e=>this.end(e);onWheel=e=>{const n=e;this.options.preventDefault!==!1&&n.cancelable&&n.preventDefault(),this.updateVelocity(n.deltaX,n.deltaY),this.options.onMove?.({deltaX:n.deltaX,deltaY:n.deltaY,velocityX:this.velocityX,velocityY:this.velocityY,totalX:0,totalY:0,isDragging:!1,event:e})}}function Ll(){return typeof performance<"u"?performance.now():Date.now()}function Fl(t,e,n){let s={delta:0,line:null},i=n;for(const o of t)for(const r of e){const a=Math.abs(r-o);a<=i&&(i=a,s={delta:r-o,line:r})}return s}function Dl(t,e){return e<=0?[]:t.map(n=>Math.round(n/e)*e)}class ho{options;observer;x;y;originX=0;originY=0;snappedX=null;snappedY=null;constructor(e){this.options=e,this.x=e.initialX??0,this.y=e.initialY??0,this.observer=new Rl({target:e.target,onPress:n=>{const s=e.getPosition?.();s&&(this.x=s.x,this.y=s.y),this.originX=this.x,this.originY=this.y,e.onPress?.(n)},onMove:n=>this.handleMove(n),onRelease:n=>e.onRelease?.(n)})}start(){this.observer.start()}stop(){this.observer.stop()}destroy(){this.observer.destroy()}get position(){return{x:this.x,y:this.y}}get velocity(){return this.observer.velocity}setPosition(e,n){const s=this.options.axis??"both";this.x=s==="y"?this.x:this.applyConstraints(e,"x"),this.y=s==="x"?this.y:this.applyConstraints(n,"y")}get snapLines(){return{x:this.snappedX,y:this.snappedY}}snapThreshold(){if(this.options.snapThreshold!==void 0)return this.options.snapThreshold;const e=this.options.snap??0;return e>0?e/2:8}handleMove(e){this.setPosition(this.originX+e.totalX,this.originY+e.totalY),this.options.mode==="scrub"&&this.scrub(),this.options.onDrag?.(this.position,e),this.options.onSnap?.(this.snapLines)}scrub(){const e=this.options.timeline;if(!e)return;const n=e.duration;if(n<=0)return;const s=this.options.scrubDistance??500;if(s===0)return;const i=(this.options.axis??"both")==="y"?this.y:this.x,o=vp(i/s);e.pause(),e.seek(o*n)}applyConstraints(e,n){let s=e;const i=[...Dl([s],this.options.snap??0),...(n==="x"?this.options.snapLinesX:this.options.snapLinesY)??[]],o=Fl([s],i,this.snapThreshold());s+=o.delta,n==="x"?this.snappedX=o.line:this.snappedY=o.line;const r=this.options.bounds;if(r){const a=n==="x"?r.minX:r.minY,l=n==="x"?r.maxX:r.maxY;a!==void 0&&(s=Math.max(a,s)),l!==void 0&&(s=Math.min(l,s))}return s}}function vp(t){return t<0?0:t>1?1:t}function Mp(t){const e=new ho(t);return e.start(),e}const Sp={x:"x",y:"y","x,y":"both"},uo=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function Nl(t,e){const n=Ss(t),s=e.getBoundingClientRect();return{minX:s.left-n.left,maxX:s.right-n.right,minY:s.top-n.top,maxY:s.bottom-n.bottom}}function Bl(t){return Array.isArray(t)?[...t]:t}function Tp(t,e,n,s={}){const[i]=e.resolveTargets(n),o=i?e.elementFor(i):void 0;if(!i||!o)throw new Error(`gsap-compat: live.draggable could not find ${String(n)}`);if(s.type==="rotation")return Ep(t,e,i,o,s);const r=Sp[s.type??"x,y"],a=()=>{const p=e.appliedValue(i,"x"),m=e.appliedValue(i,"y");return{x:typeof p=="number"?p:0,y:typeof m=="number"?m:0}},l=typeof s.bounds=="string"?e.query(s.bounds):uo(s.bounds)?s.bounds:null,h={bounds:(!l&&s.bounds&&!uo(s.bounds)?s.bounds:void 0)??(l?Nl(o,l):void 0)};let u=null;const d=()=>{u?.kill(),u=null},f=p=>{const m=s.inertia===!0?{}:s.inertia,b=m.friction??(m.resistance!==void 0?ao(m.resistance):4),k=a(),w=h.bounds??{};let M,S;const A=m.end;if(Array.isArray(A)){const $=kn({from:k.x,velocity:r==="y"?0:p.x,friction:b}),v=kn({from:k.y,velocity:r==="x"?0:p.y,friction:b});let O=A[0];for(const x of A)Math.hypot(x.x-$,x.y-v)<Math.hypot(O.x-$,O.y-v)&&(O=x);O&&(M=[O.x],S=[O.y])}else typeof A=="number"?(M=A,S=A):A&&(M=Bl(A.x),S=Bl(A.y));const E={};r!=="y"&&(E.x={velocity:p.x,friction:b,min:w.minX,max:w.maxX,end:M}),r!=="x"&&(E.y={velocity:p.y,friction:b,min:w.minY,max:w.maxY,end:S}),u=t.to(o,{inertia:E,onComplete:()=>s.onThrowComplete?.()})},g=new ho({target:o,axis:r,snap:s.snap,get bounds(){return h.bounds},getPosition:a,onPress:()=>{d(),l&&(h.bounds=Nl(o,l)),s.onPress?.()},onDrag:p=>{e.apply(i,r==="x"?{x:p.x}:r==="y"?{y:p.y}:{x:p.x,y:p.y}),s.onDrag?.(p)},onRelease:()=>{const p=g.velocity;s.onRelease?.(p),s.inertia&&f(p)}});return g.start(),{draggable:g,get position(){return a()},get rotation(){const p=e.appliedValue(i,"rotate");return typeof p=="number"?p:0},destroy(){d(),g.destroy()}}}function Ep(t,e,n,s,i){const o=typeof i.bounds=="object"&&i.bounds!==null&&!uo(i.bounds)?i.bounds:{},r=()=>{const w=e.appliedValue(n,"rotate");return typeof w=="number"?w:0},a=w=>Math.min(o.maxRotation??1/0,Math.max(o.minRotation??-1/0,w));let l=null,c=!1,h,u={x:0,y:0},d=0,f=0,g=[];const p=w=>Math.atan2(w.clientY-u.y,w.clientX-u.x)*180/Math.PI,m=w=>{if(c)return;l?.kill(),l=null,c=!0,h=w.pointerId,s.setPointerCapture?.(w.pointerId);const M=s.getBoundingClientRect();u={x:M.left+M.width/2,y:M.top+M.height/2},d=p(w),f=r(),g=[{time:performance.now(),rotation:f}],i.onPress?.()},b=w=>{if(!c||w.pointerId!==h)return;const M=p(w);let S=M-d;S>180&&(S-=360),S<-180&&(S+=360),d=M,f+=S;let A=a(f);i.snap&&(A=a(Math.round(A/i.snap)*i.snap)),e.apply(n,{rotate:A});const E=performance.now();for(g.push({time:E,rotation:A});g.length>2&&E-g[0].time>100;)g.shift();const $={x:0,y:0};i.onDrag?.($)},k=w=>{if(!c||w.pointerId!==h)return;c=!1;const M=g[0],S=g[g.length-1],A=M&&S?(S.time-M.time)/1e3:0,E=A>0?(S.rotation-M.rotation)/A:0;if(i.onRelease?.({x:E,y:0}),!i.inertia)return;const $=i.inertia===!0?{}:i.inertia,v=$.friction??($.resistance!==void 0?ao($.resistance):4),O=typeof $.end=="number"||Array.isArray($.end)?$.end:void 0;l=t.to(s,{inertia:{rotate:{velocity:E,friction:v,min:o.minRotation,max:o.maxRotation,end:Array.isArray(O)?O.filter(x=>typeof x=="number"):O}},onComplete:()=>i.onThrowComplete?.()})};return s.addEventListener("pointerdown",m),s.addEventListener("pointermove",b),s.addEventListener("pointerup",k),s.addEventListener("pointercancel",k),s.style.touchAction="none",{draggable:void 0,position:{x:0,y:0},get rotation(){return r()},destroy(){l?.kill(),s.removeEventListener("pointerdown",m),s.removeEventListener("pointermove",b),s.removeEventListener("pointerup",k),s.removeEventListener("pointercancel",k)}}}const Ap={opacity:0,scale:.6};function Pp(t){const e=t.getBoundingClientRect();return e.width===0&&e.height===0?null:{cx:e.left+e.width/2,cy:e.top+e.height/2,width:e.width,height:e.height}}function Wl(t){const e=Ss(t);return e.width===0&&e.height===0?null:{cx:e.left+e.width/2,cy:e.top+e.height/2,width:e.width,height:e.height}}function fo(t,e){const s=t.resolveTargets(e).map(r=>t.elementFor(r)).filter(r=>!!r),i=new Map,o=new Map;for(const r of s){const a=Pp(r);i.set(r,a);const l=jl(r);a&&l!==void 0&&!o.has(l)&&o.set(l,{element:r,box:a})}return{elements:s,boxes:i,ids:o}}const po=new WeakMap;function go(t,e,n,s={}){const i=s.duration??.6,o=s.ease??"power2.inOut",r=s.stagger??0,a=s.scale!==!1,l=s.enter===void 0?Ap:s.enter,c=new Set(n.elements);if(s.targets!==void 0)for(const f of t.resolveTargets(s.targets)){const g=t.elementFor(f);g&&c.add(g)}const h=[...c].sort((f,g)=>f===g?0:f.compareDocumentPosition(g)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1),u=e({onComplete:s.onComplete});let d=0;for(const f of h){const g=Wl(f);if(!g)continue;let p=n.boxes.get(f)??null,m;const b=jl(f),k=!p&&b!==void 0?n.ids.get(b):void 0;k&&k.element!==f&&(p=k.box,m=k.element);const[w]=t.resolveTargets(f);po.get(f)?.timeline.removeTracks({target:w});const M=d*r;if(!p){if(l===!1)continue;u.fromTo(f,{x:0,y:0,scaleX:1,scaleY:1,...l},{...ql(l),x:0,y:0,scaleX:1,scaleY:1,duration:i,ease:o,delay:M},0),po.set(f,u),d++;continue}const S=p.cx-g.cx,A=p.cy-g.cy,E=a?p.width/g.width:1,$=a?p.height/g.height:1;if(!(Math.abs(S)>.5||Math.abs(A)>.5||Math.abs(E-1)>.001||Math.abs($-1)>.001)){const x=(_,F)=>{const I=t.appliedValue(w,_);return typeof I=="number"&&Math.abs(I-F)>1e-6};(x("x",0)||x("y",0)||x("scaleX",1)||x("scaleY",1))&&u.set(f,{x:0,y:0,scaleX:1,scaleY:1},0);continue}const O=s.fade===!0&&m!==void 0;u.fromTo(f,{x:S,y:A,scaleX:E,scaleY:$,...O&&{opacity:0}},{x:0,y:0,scaleX:1,scaleY:1,...O&&{opacity:1},duration:i,ease:o,delay:M},0),O&&m&&Wl(m)&&u.fromTo(m,{opacity:1},{opacity:0,duration:i,ease:o,delay:M},0),po.set(f,u),d++}return u}function jl(t){return t.dataset?.flipId}function ql(t){const e={};for(const n of Object.keys(t))e[n]=n==="opacity"||n.startsWith("scale")?1:0;return e}function $p(t,e={}){const n=new Set((e.type??"chars,words,lines").split(",").map(p=>p.trim())),s={chars:e.charsClass??"char",words:e.wordsClass??"word",lines:e.linesClass??"line"},i=e.aria!==!1,o=t.map(p=>({element:p,html:p.innerHTML,ariaLabel:p.getAttribute("aria-label")}));let r={chars:[],words:[],lines:[],masks:[]},a,l,c=!1;const h=()=>{for(const{element:p,html:m,ariaLabel:b}of o)p.innerHTML=m,b===null?p.removeAttribute("aria-label"):p.setAttribute("aria-label",b)},u=()=>{a&&(a.revert?a.revert():a.kill?.(),a=void 0)},d=()=>{const p={chars:[],words:[],lines:[],masks:[]};for(const{element:m}of o){const b=(m.textContent??"").replace(/\s+/g," ").trim(),k=xp(m,s.words),w=n.has("chars")?k.flatMap(A=>_p(A,s.chars)):[],M=n.has("lines")?Op(m,k,s.lines):[];if(i){!m.hasAttribute("aria-label")&&b&&m.setAttribute("aria-label",b);for(const A of k)A.setAttribute("aria-hidden","true")}if(n.has("words"))p.words.push(...k);else for(const A of k)A.removeAttribute("class");p.chars.push(...w),p.lines.push(...M);const S=e.mask==="lines"?M:e.mask==="words"?k:e.mask==="chars"?w:[];for(const A of S)p.masks.push(Cp(A,`${s[e.mask]}-mask`))}r=p},f={elements:t,get chars(){return r.chars},get words(){return r.words},get lines(){return r.lines},get masks(){return r.masks},split(){c||(u(),h(),d(),a=e.onSplit?.(f))},revert(){c=!0,l?.disconnect(),u(),h()}};d(),a=e.onSplit?.(f),e.autoSplit&&g();function g(){const p=new Map;let m=!1;const b=()=>{if(m)return;m=!0;const w=()=>{m=!1,f.split()};typeof requestAnimationFrame=="function"?requestAnimationFrame(w):setTimeout(w,0)};if(typeof ResizeObserver=="function"){l=new ResizeObserver(w=>{let M=!1;for(const S of w){const A=Math.round(S.contentRect.width),E=p.get(S.target);p.set(S.target,A),E!==void 0&&E!==A&&(M=!0)}M&&b()});for(const w of t)l.observe(w)}const k=t[0]?.ownerDocument?.fonts;k&&k.status!=="loaded"&&k.ready.then(()=>b())}return f}function xp(t,e){const n=t.ownerDocument,s=[],i=n.createTreeWalker(t,4),o=[];for(let r=i.nextNode();r;r=i.nextNode())o.push(r);for(const r of o){const a=r.data.match(/\s+|\S+/g)??[];if(a.length===0)continue;const l=n.createDocumentFragment();for(const c of a){if(/^\s/.test(c)){l.appendChild(n.createTextNode(c));continue}const h=n.createElement("span");h.className=e,h.style.display="inline-block",h.textContent=c,l.appendChild(h),s.push(h)}r.replaceWith(l)}return s}function _p(t,e){const n=t.ownerDocument,s=Ip(t.textContent??"").map(i=>{const o=n.createElement("span");return o.className=e,o.style.display="inline-block",o.textContent=i,o});return t.replaceChildren(...s),s}function Ip(t){const e=Intl.Segmenter;return e?Array.from(new e(void 0,{granularity:"grapheme"}).segment(t),n=>n.segment):Array.from(t)}function Op(t,e,n){const s=t.ownerDocument,i=new Map(e.map(g=>[g,g.getBoundingClientRect()])),o=[],r=g=>{for(const p of Array.from(g.childNodes))p.nodeType===3||i.has(p)||p.tagName==="BR"?o.push(p):r(p)};r(t);const a=[];let l=null,c=0,h=0,u=!1,d=[];const f=()=>{l=s.createElement("span"),l.className=n,l.style.display="block",a.push(l),d=[]};for(const g of o){if(g.tagName==="BR"){u=!0;continue}const p=i.get(g);if(p&&(!l||u||p.top>c+h)&&(f(),c=p.top,h=p.height/2,u=!1),!l)continue;const m=[];for(let w=g.parentNode;w&&w!==t;w=w.parentNode)m.unshift(w);let b=0;for(;b<d.length&&b<m.length&&d[b].original===m[b];)b++;d.length=b;let k=b===0?l:d[b-1].clone;for(const w of m.slice(b)){const M=w.cloneNode(!1);k.appendChild(M),d.push({original:w,clone:M}),k=M}k.appendChild(g)}return t.replaceChildren(...a),a}function Cp(t,e){const n=t.ownerDocument.createElement("span");return n.className=e,n.style.display=t.style.display==="block"?"block":"inline-block",n.style.overflow="clip",n.style.paddingBottom="0.12em",n.style.marginBottom="-0.12em",t.replaceWith(n),n.appendChild(t),n}const Kl={top:0,left:0,start:0,center:.5,centre:.5,middle:.5,bottom:1,right:1,end:1};function mo(t){const e=t.trim().toLowerCase();if(e in Kl)return Kl[e];if(e.endsWith("%")){const n=Number.parseFloat(e.slice(0,-1));return Number.isNaN(n)?void 0:n/100}}function yo(t){if(typeof t=="number")return{elementFraction:0,viewportFraction:0,offsetPx:0,absolutePx:t};let e=0;const s=t.replace(/([+-])=\s*(-?[\d.]+)/g,(r,a,l)=>(e+=(a==="-"?-1:1)*Number.parseFloat(l),"")).trim().split(/\s+/).filter(Boolean);if(s.length===1&&/^-?[\d.]+$/.test(s[0]))return{elementFraction:0,viewportFraction:0,offsetPx:0,absolutePx:Number.parseFloat(s[0])+e};const i=s[0]!==void 0?mo(s[0]):void 0,o=s[1]!==void 0?mo(s[1]):void 0;return{elementFraction:i??0,viewportFraction:o??0,offsetPx:e}}function Je(t,e,n){const s=yo(n),i=s.absolutePx!==void 0?t.top+s.absolutePx:t.top+t.height*s.elementFraction,o=e*s.viewportFraction;return i-o+s.offsetPx}function Hp(t,e,n,s){const i=Je(t,e,n),r=Je(t,e,s)-i;return r<=0?i<=0?1:0:bo(-i/r)}function bo(t){return t<0?0:t>1?1:t===0?0:t}function Yl(t,e,n,s){if(n<=0)return e;const i=1-Math.exp(-(s/1e3)/n);return t+(e-t)*i}function wo(t,e,n,s,i){const o=h=>Je({top:t+i(h),bottom:t+i(h)+e,height:e},n,s),r=o(0),a=o(1);if(Math.sign(r)===Math.sign(a)||r===0||a===0)return r===0?0:a===0?1:Math.abs(r)<Math.abs(a)?0:1;let l=0,c=1;for(let h=0;h<40;h++){const u=(l+c)/2;Math.sign(o(u))===Math.sign(r)?l=u:c=u}return(l+c)/2}class zl{timeline;trigger;behaviour;options;observer=null;hasPlayed=!1;running=!1;constructor(e){this.timeline=e.timeline,this.trigger=e.trigger,this.behaviour=e.behaviour??"once",this.options=e}start(){if(!this.running){if(this.running=!0,typeof IntersectionObserver>"u"){this.enter();return}this.observer=new IntersectionObserver(e=>{for(const n of e)n.isIntersecting?this.enter():this.leave()},{threshold:this.options.threshold??.15,rootMargin:this.options.rootMargin,root:this.options.root??null}),this.observer.observe(this.trigger)}}stop(){this.running=!1,this.observer?.disconnect(),this.observer=null}destroy(){this.stop()}reset(){this.hasPlayed=!1,this.timeline.stop()}enter(){this.options.onEnter?.(),!(this.behaviour==="once"&&this.hasPlayed)&&(this.hasPlayed=!0,this.behaviour!=="once"&&this.timeline.seek(0),this.timeline.play())}leave(){this.options.onLeave?.(),this.behaviour==="reset"&&this.timeline.stop()}}function Rp(t){const e=new zl(t);return e.start(),e}class Xl{element;spacer;saved;axis;spacing;constructor(e,n={}){this.element=e,this.axis=n.axis??"y",this.spacing=n.spacing??!0;const s=e.ownerDocument;this.spacer=s.createElement("div"),this.spacer.className="pin-spacer",this.saved={position:e.style.position,top:e.style.top,left:e.style.left},this.axis==="x"&&(this.spacer.style.flexShrink="0"),e.replaceWith(this.spacer),this.spacer.appendChild(e)}release(){this.element.style.position=this.saved.position,this.element.style.top=this.saved.top,this.element.style.left=this.saved.left}apply(e,n){const s=Math.max(0,n);this.element.style.position="sticky",this.axis==="x"?(this.spacer.style.width=`${this.element.offsetWidth+s}px`,this.spacer.style.marginRight=this.spacing?"":`-${s}px`,this.element.style.left=`${e}px`):(this.spacer.style.height=`${this.element.offsetHeight+s}px`,this.spacer.style.marginBottom=this.spacing?"":`-${s}px`,this.element.style.top=`${e}px`)}destroy(){this.element.style.position=this.saved.position,this.element.style.top=this.saved.top,this.element.style.left=this.saved.left,this.spacer.parentNode&&this.spacer.replaceWith(this.element)}}const Lp=.15;function Gl(t){return typeof t=="object"&&!Array.isArray(t)?t:{snapTo:t}}function Ul(t,e,n){const s=Ts(t+e*Lp);if(typeof n=="function")return Ts(n(s));if(typeof n=="number")return n<=0?t:Ts(Math.round(s/n)*n);if(n.length===0)return t;let i=n[0];for(const o of n)Math.abs(o-s)<Math.abs(i-s)&&(i=o);return Ts(i)}function Vl(t,e,n){const s=t.duration??{min:.2,max:.8};if(typeof s=="number")return s;const i=Math.min(1,Math.abs(e)/Math.max(1,n));return s.min+(s.max-s.min)*i}class Jl{rafId=null;cancelEvents=["wheel","touchstart","pointerdown","keydown"];onInterrupt=()=>this.cancel();write;eventTarget;constructor(e,n){this.write=e,this.eventTarget=n}get active(){return this.rafId!==null}animate(e,n,s,i=vn,o){if(this.cancel(),typeof requestAnimationFrame>"u"||s<=0){this.write(n),o?.();return}for(const l of this.cancelEvents)this.eventTarget?.addEventListener(l,this.onInterrupt,{passive:!0});let r=null;const a=l=>{r??=l;const c=Math.min(1,(l-r)/(s*1e3));this.write(e+(n-e)*i(c)),c<1?this.rafId=requestAnimationFrame(a):(this.rafId=null,this.detach(),o?.())};this.rafId=requestAnimationFrame(a)}cancel(){this.rafId!==null&&typeof cancelAnimationFrame<"u"&&cancelAnimationFrame(this.rafId),this.rafId=null,this.detach()}detach(){for(const e of this.cancelEvents)this.eventTarget?.removeEventListener(e,this.onInterrupt)}}function Ts(t){return Math.max(0,Math.min(1,t))}class Zl{options;scroller;nodes=[];scrollerStart;scrollerEnd;start;end;constructor(e,n,s){this.options=s===!0?{}:s,this.scroller=n;const{startColor:i="#3ecf7a",endColor:o="#ff5a5a",id:r}=this.options,a=r?`${r} `:"",l=(c,h,u)=>{const d=e.createElement("div");return d.textContent=`${a}${c}`,d.setAttribute("aria-hidden","true"),d.className="scroll-marker",Object.assign(d.style,{position:u?"fixed":"absolute",right:`${this.options.indent??0}px`,zIndex:"2147483646",pointerEvents:"none",borderTop:`1px solid ${h}`,color:h,font:`${this.options.fontSize??"11px"} ui-monospace, monospace`,padding:"2px 6px",whiteSpace:"nowrap",background:"rgba(0, 0, 0, 0.35)"}),(n??e.body).appendChild(d),this.nodes.push(d),d};this.scrollerStart=l("scroller-start",i,!n),this.scrollerEnd=l("scroller-end",o,!n),this.start=l("start",i,!1),this.end=l("end",o,!1),n&&getComputedStyle(n).position==="static"&&(n.style.position="relative")}place(e,n){this.start.style.top=`${e.startPage}px`,this.end.style.top=`${e.endPage}px`;const s=this.scroller?n:0;this.scrollerStart.style.top=`${s+e.startViewport}px`,this.scrollerEnd.style.top=`${s+e.endViewport}px`}follow(e,n){this.scroller&&this.place(e,n)}destroy(){for(const e of this.nodes.splice(0))e.remove()}}const Fp=120,Ze=[],Qe=new Set;let ko=!1;const Dp=()=>{ko||Qe.size===0||(ko=!0,queueMicrotask(()=>{ko=!1;for(const t of Qe)t.afterRefresh()}))},Ql=()=>{for(const t of Qe)t.beforeRefresh();for(const t of Ze)t.refresh();for(const t of Qe)t.afterRefresh()};let tn={width:0,height:0};const tc=()=>{const t=window.innerWidth,e=window.innerHeight,n=t===tn.width&&e!==tn.height,s=Math.abs(e-tn.height)<tn.height*.25,i=typeof navigator<"u"&&(navigator.maxTouchPoints??0)>0;n&&s&&i||(tn={width:t,height:e},Ql())};class _n{timeline;options;running=!1;pin=null;startPx=0;endPx=0;targetProgress=0;displayProgress=0;zone="before";measured=!1;lastScroll=null;lastScrollTime=0;velocityPxPerSecond=0;idleTimer=null;lastEmitted=null;rafId=null;lastFrameTime=null;onScroll=()=>this.update();releaseVelocity=0;snapper;snapTimer=null;markers=null;markerGeometry=null;constructor(e){this.timeline=e.timeline,this.options=e,this.snapper=new Jl(n=>this.scrollTo(n),typeof window<"u"?window:null)}start(){if(this.running)return;this.running=!0,this.timeline?.pause();const e=this.options.pin===!0?this.options.trigger:this.options.pin||null;e&&!this.options.container&&(this.pin=new Xl(e,{axis:this.options.horizontal?"x":"y",spacing:this.options.pinSpacing!==!1})),this.options.markers&&!this.options.horizontal&&typeof document<"u"&&(this.markers=new Zl(document,this.options.scroller??null,this.options.markers)),this.scrollTarget()?.addEventListener("scroll",this.onScroll,{passive:!0}),Ze.length===0&&typeof window<"u"&&(tn={width:window.innerWidth,height:window.innerHeight},window.addEventListener("resize",tc,{passive:!0})),Ze.push(this),this.refresh()}stop(){this.running&&(this.running=!1,this.scrollTarget()?.removeEventListener("scroll",this.onScroll),Ze.splice(Ze.indexOf(this),1),Ze.length===0&&typeof window<"u"&&window.removeEventListener("resize",tc),this.stopSmoothing(),this.idleTimer!==null&&clearTimeout(this.idleTimer),this.idleTimer=null,this.snapTimer!==null&&clearTimeout(this.snapTimer),this.snapTimer=null,this.snapper.cancel())}destroy(){this.stop(),this.pin?.destroy(),this.pin=null,this.markers?.destroy(),this.markers=null}get startOffset(){return this.startPx}get endOffset(){return this.endPx}static refreshAll(){Ql()}static onRefresh(e){return Qe.add(e),()=>Qe.delete(e)}get progress(){return this.targetProgress}get velocity(){return this.velocityPxPerSecond}refresh(){if(!this.running)return;this.measured&&this.options.onRefresh?.();const e=this.scrollPosition();this.pin?.release();const n=this.triggerRect();if(n&&this.options.container)this.measureInContainer(this.options.container);else if(n){const s=this.viewportHeight();if(this.startPx=e+Je(n,s,In(this.options.start)??"top bottom"),this.endPx=this.resolveEnd(n,s,e),this.pin){const i=this.relativeRect(this.pin.element.getBoundingClientRect());this.pin.apply(i.top-(this.startPx-e),this.endPx-this.startPx)}this.markerGeometry=this.markers?this.markersFor(s):null}this.markers&&this.markerGeometry&&this.markers.place(this.markerGeometry,e),this.lastScroll=null,this.updateFrom(e,!this.measured),this.measured=!0,Dp()}sample(){this.refresh()}update(e){this.running&&this.updateFrom(e??this.scrollPosition(),!1)}updateFrom(e,n){this.trackVelocity(e),this.markers&&this.markerGeometry&&this.markers.follow(this.markerGeometry,e);const s=this.endPx-this.startPx,i=this.zone;this.targetProgress=s>0?bo((e-this.startPx)/s):e>=this.startPx?1:0,this.zone=s>0?e<=this.startPx?"before":e>=this.endPx?"after":"active":e>=this.startPx?"after":"before",this.fireBoundaryCallbacks(i,this.zone),n||this.smoothing()<=0?(this.displayProgress=this.targetProgress,this.applyProgress()):(this.emitUpdate(),this.startSmoothing())}smoothing(){const e=this.options.scrub;return typeof e=="number"?Math.max(0,e):0}resolveEnd(e,n,s){const i=In(this.options.end)??"bottom top",o=typeof i=="string"?i.trim().match(/^\+=\s*(-?[\d.]+)\s*(%|px)?$/):null;if(o){const r=Number.parseFloat(o[1]);return this.startPx+(o[2]==="%"?n*r/100:r)}return s+Je(e,n,i)}applyProgress(){const e=this.timeline?.duration??0;this.timeline&&e>0&&this.timeline.seek(this.displayProgress*e),this.emitUpdate()}emitUpdate(){if(!this.options.onUpdate)return;const e=[this.displayProgress,this.velocityPxPerSecond];this.lastEmitted&&this.lastEmitted[0]===e[0]&&this.lastEmitted[1]===e[1]||(this.lastEmitted=e,this.options.onUpdate(e[0],e[1]))}trackVelocity(e){const n=typeof performance<"u"?performance.now():Date.now();this.lastScroll!==null&&n>this.lastScrollTime&&e!==this.lastScroll&&(this.velocityPxPerSecond=(e-this.lastScroll)/(n-this.lastScrollTime)*1e3),(this.lastScroll===null||e!==this.lastScroll)&&(this.lastScroll=e,this.lastScrollTime=n),!(this.velocityPxPerSecond===0||typeof setTimeout>"u")&&(this.idleTimer!==null&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.idleTimer=null,this.releaseVelocity=this.velocityPxPerSecond,this.velocityPxPerSecond=0,this.emitUpdate(),this.scheduleSnap()},Fp))}fireBoundaryCallbacks(e,n){if(e===n)return;const{onEnter:s,onLeave:i,onEnterBack:o,onLeaveBack:r}=this.options;e==="before"?(s?.(),n==="after"&&i?.()):e==="after"?(o?.(),n==="before"&&r?.()):n==="after"?i?.():r?.()}scheduleSnap(){const e=this.options.snap;if(e===void 0||this.snapper.active)return;const n=Gl(e),s=()=>{this.snapTimer=null;const i=this.endPx-this.startPx,o=this.scrollPosition();if(!this.running||i<=0||o<=this.startPx||o>=this.endPx)return;const r=(o-this.startPx)/i,a=this.startPx+Ul(r,this.releaseVelocity/i,n.snapTo)*i;Math.abs(a-o)<1||this.snapper.animate(o,a,Vl(n,a-o,this.viewportHeight()),n.ease)};n.delay?this.snapTimer=setTimeout(s,n.delay*1e3):s()}scrollTo(e){const n=this.options.scroller,s=this.options.horizontal?{left:e}:{top:e};n?typeof n.scrollTo=="function"?n.scrollTo({...s,behavior:"instant"}):this.options.horizontal?n.scrollLeft=e:n.scrollTop=e:typeof window<"u"&&window.scrollTo({...s,behavior:"instant"})}measureInContainer(e){const n=this.options.trigger;if(typeof n?.getBoundingClientRect!="function")return;const s=n.getBoundingClientRect(),i=this.options.scroller?.getBoundingClientRect?.().left??0,o=this.options.scroller?this.options.scroller.clientWidth:typeof window<"u"?window.innerWidth:0,r=s.left-i-e.shiftAt(e.progress()),{start:a,end:l}=e.range(),c=f=>a+f*(l-a),h=wo(r,s.width,o,In(this.options.start)??"left right",e.shiftAt);this.startPx=c(h);const u=In(this.options.end)??"right left",d=typeof u=="string"?u.trim().match(/^\+=\s*(-?[\d.]+)\s*(px)?$/):null;this.endPx=d?this.startPx+Number.parseFloat(d[1]):c(wo(r,s.width,o,u,e.shiftAt)),this.markerGeometry=null}markersFor(e){const n=(o,r)=>{const a=In(o)??r;if(typeof a=="number")return 0;if(/^\s*\+=/.test(a))return;const l=yo(a);return e*l.viewportFraction-l.offsetPx},s=n(this.options.start,"top bottom")??0,i=n(this.options.end,"bottom top")??s;return{startViewport:s,endViewport:i,startPage:this.startPx+s,endPage:this.endPx+i}}startSmoothing(){if(this.rafId!==null||typeof requestAnimationFrame>"u")return;const e=n=>{if(this.rafId=null,!this.running)return;const s=this.lastFrameTime===null?16.67:n-this.lastFrameTime;this.lastFrameTime=n,this.displayProgress=Yl(this.displayProgress,this.targetProgress,this.smoothing(),s);const i=Math.abs(this.targetProgress-this.displayProgress)<1e-4;i&&(this.displayProgress=this.targetProgress),this.applyProgress(),i?this.lastFrameTime=null:this.rafId=requestAnimationFrame(e)};this.rafId=requestAnimationFrame(e)}stopSmoothing(){this.rafId!==null&&typeof cancelAnimationFrame<"u"&&cancelAnimationFrame(this.rafId),this.rafId=null,this.lastFrameTime=null}scrollTarget(){return this.options.scroller??(typeof window<"u"?window:null)}scrollPosition(){const e=this.options.scroller,n=this.options.horizontal;return e?(n?e.scrollLeft:e.scrollTop)??0:typeof window<"u"?(n?window.scrollX:window.scrollY)??0:0}triggerRect(){const e=this.options.trigger;return typeof e?.getBoundingClientRect!="function"?null:this.relativeRect(e.getBoundingClientRect())}relativeRect(e){const n=this.options.horizontal,s=n?e.left??0:e.top,i=n?e.right??0:e.bottom,o=n?e.width??0:e.height,r=this.options.scroller;if(r&&typeof r.getBoundingClientRect=="function"){const a=r.getBoundingClientRect(),l=n?a.left:a.top;return{top:s-l,bottom:i-l,height:o}}return{top:s,bottom:i,height:o}}viewportHeight(){const e=this.options.scroller,n=this.options.horizontal;return e?n?e.clientWidth:e.clientHeight:typeof window<"u"?n?window.innerWidth:window.innerHeight:0}}function In(t){return typeof t=="function"?t():t}function Np(t){const e=new _n(t);return e.start(),e}const vo=new Set,Bp=16,ec=.5,Wp=2;class Mo{options;frames;running=!1;reduced=!1;current=0;target=0;written=null;velocityPxPerSecond=0;frameId=null;lastTime=null;journey=null;pausedState=!1;effects=[];onWheel=e=>this.wheel(e);onScroll=()=>this.nativeScroll();onResize=()=>this.refresh();onLoad=()=>this.refresh();stopListening=null;constructor(e={}){this.options=e,this.frames=e.frames??{request:n=>requestAnimationFrame(n),cancel:n=>cancelAnimationFrame(n)}}start(){if(this.running||typeof window>"u")return this;this.running=!0,this.reduced=this.options.reducedMotion??(typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches),this.current=this.target=this.position();const e=this.options.scroller??window;return e.addEventListener("wheel",this.onWheel,{passive:!1}),e.addEventListener("scroll",this.onScroll,{passive:!0}),window.addEventListener("resize",this.onResize,{passive:!0}),window.addEventListener("load",this.onLoad),vo.add(this),this.stopListening=_n.onRefresh({beforeRefresh:()=>this.rest(),afterRefresh:()=>this.refresh()}),this.refresh(),this}static refreshAll(){for(const e of vo)e.refresh()}stop(){if(!this.running)return this;this.running=!1;const e=this.options.scroller??window;return e.removeEventListener("wheel",this.onWheel),e.removeEventListener("scroll",this.onScroll),window.removeEventListener("resize",this.onResize),window.removeEventListener("load",this.onLoad),vo.delete(this),this.stopListening?.(),this.stopListening=null,this.cancelFrame(),this.journey=null,this}destroy(){this.stop();for(const e of this.effects)So(e.element,e.saved);this.effects=[]}kill(){this.destroy()}get state(){const e=this.limit();return{scroll:this.current,target:this.target,progress:e>0?this.current/e:0,velocity:this.velocityPxPerSecond}}paused(e){return e!==void 0&&(this.pausedState=e,e&&(this.target=this.current,this.journey=null)),this.pausedState}scrollTo(e,n={}){if(!this.running)return;const s=this.clamp(this.resolve(e)+(n.offset??0)),i=Math.abs(s-this.current),o=this.reduced?0:n.duration??Math.min(1.2,Math.max(.4,i/2500));if(o<=0){this.journey=null,this.current=this.target=s,this.write(s),this.applyEffects(0);return}this.target=s,this.journey={from:this.current,to:s,ms:o*1e3,ease:n.ease??vn,elapsed:0},this.requestFrame()}refresh(){if(!this.running)return;this.rest(),this.effects=[];const e=this.options.effects===!0?"[data-speed], [data-lag]":this.options.effects||"";if(e&&!this.reduced){const n=this.options.scroller??document,s=this.position(),i=this.viewportHeight(),o=this.options.scroller?.getBoundingClientRect().top??0;for(const r of n.querySelectorAll(e)){const a=Number.parseFloat(r.dataset.speed??""),l=Number.parseFloat(r.dataset.lag??""),c=r.getBoundingClientRect(),h=c.top-o+s;this.effects.push({element:r,speed:Number.isFinite(a)?a:void 0,lag:Number.isFinite(l)&&l>0?l:void 0,centre:h+c.height/2-i/2,lagged:s,shift:0,saved:r.style.getPropertyValue("translate")})}}this.current=this.target=this.clamp(this.position()),this.applyEffects(0)}rest(){for(const e of this.effects)So(e.element,e.saved)}wheel(e){if(this.pausedState||this.reduced||(this.options.smooth??.8)<=0||e.ctrlKey||Math.abs(e.deltaX)>Math.abs(e.deltaY)||this.nestedScrollerTakes(e))return;const n=e.deltaMode===1?Bp:e.deltaMode===2?this.viewportHeight():1,s=e.deltaY*n*(this.options.wheelMultiplier??1),i=this.clamp(this.target+s);i===this.target&&i===this.current||(e.preventDefault(),this.journey=null,this.target=i,this.requestFrame())}nativeScroll(){const e=this.position();this.written!==null&&Math.abs(e-this.written)<=Wp||(this.written=null,this.journey=null,this.cancelFrame(),this.current=this.target=e,this.requestFrame())}nestedScrollerTakes(e){const n=this.options.scroller??document.documentElement;for(let s=e.target;s&&s!==n&&s!==document.body;s=s.parentElement){if(s.hasAttribute?.("data-smooth-ignore"))return!0;const i=getComputedStyle(s);if(!/(auto|scroll)/.test(i.overflowY)||s.scrollHeight<=s.clientHeight)continue;if(e.deltaY<0?s.scrollTop>0:s.scrollTop+s.clientHeight<s.scrollHeight-1)return!0}return!1}requestFrame(){this.frameId!==null||!this.running||(this.frameId=this.frames.request(e=>this.frame(e)))}cancelFrame(){this.frameId!==null&&this.frames.cancel(this.frameId),this.frameId=null,this.lastTime=null}frame(e){this.frameId=null;const n=this.lastTime===null?1e3/60:Math.min(100,e-this.lastTime);this.lastTime=e;const s=this.current;if(this.journey){const o=this.journey;o.elapsed+=n;const r=Math.min(1,o.elapsed/o.ms);this.current=o.from+(o.to-o.from)*o.ease(r),r>=1&&(this.journey=null)}else if(this.current!==this.target){const o=(this.options.smooth??.8)*1e3/3;this.current+=(this.target-this.current)*(1-Math.exp(-n/o)),Math.abs(this.target-this.current)<ec&&(this.current=this.target)}this.current!==s&&this.write(this.current),this.velocityPxPerSecond=n>0?(this.current-s)*1e3/n:0;const i=this.applyEffects(n);this.current!==s&&this.options.onUpdate?.(this.state),this.journey||this.current!==this.target||i?this.requestFrame():(this.lastTime=null,this.velocityPxPerSecond=0)}applyEffects(e){let n=!1;const s=this.current;for(const i of this.effects){let o=0;if(i.speed!==void 0&&(o+=(s-i.centre)*(1-i.speed)),i.lag!==void 0){const r=i.lag*1e3/3;i.lagged=e===0?s:i.lagged+(s-i.lagged)*(1-Math.exp(-e/r)),Math.abs(s-i.lagged)<ec?i.lagged=s:n=!0,o+=s-i.lagged}So(i.element,o===0?i.saved:`0 ${jp(o)}px`),i.shift=o}return n}write(e){const n=Math.round(e);this.written=n;const s=this.options.scroller;s?s.scrollTop=n:window.scrollTo({top:n,behavior:"instant"})}position(){const e=this.options.scroller;return e?e.scrollTop:window.scrollY}viewportHeight(){const e=this.options.scroller;return e?e.clientHeight:window.innerHeight}limit(){const e=this.options.scroller??document.documentElement;return Math.max(0,e.scrollHeight-this.viewportHeight())}clamp(e){return Math.max(0,Math.min(this.limit(),e))}resolve(e){if(typeof e=="number")return e;const n=this.options.scroller??document,s=typeof e=="string"?n.querySelector(e):e;if(!s)return this.current;const i=this.options.scroller?.getBoundingClientRect().top??0,o=this.effects.find(r=>r.element===s)?.shift??0;return s.getBoundingClientRect().top-i+this.position()-o}}function So(t,e){e?t.style.setProperty("translate",e):t.style.removeProperty("translate")}function jp(t){return Math.round(t*100)/100}function qp(t,e){switch(e){case"play":if(t.progress()>=1)break;t.reversed()?t.reverse():t.play();break;case"reverse":if(t.progress()<=0)break;t.reversed()?t.play():t.reverse();break;case"pause":t.pause();break;case"resume":t.resume();break;case"restart":t.restart();break;case"reset":t.pause(),t.progress(0);break;case"complete":t.pause(),t.progress(1);break}}function To(t,e,n,s,i=()=>{}){const o=f=>typeof f=="string"?t.query(f)??void 0:f,r=o(e.trigger)??s;if(!r){i(`gsap-compat: scrollTrigger has no trigger element${typeof e.trigger=="string"?` for "${e.trigger}"`:""}`);return}const a=e.scrub===void 0||e.scrub===!1?!1:e.scrub,l=(e.toggleActions??"play none none none").trim().split(/\s+/);let c=0,h;const u=(f,g)=>()=>{g?.(),n&&!a&&qp(n,l[f]??"none"),e.once&&f===0&&queueMicrotask(()=>h.destroy())},d=e.containerAnimation?zp(t,e.containerAnimation,r,i):void 0;return h=new _n({trigger:r,start:e.start,end:e.end,scrub:a===!1?void 0:a,pin:e.pin===!0?!0:o(e.pin),scroller:o(e.scroller),horizontal:e.horizontal,pinSpacing:e.pinSpacing,onRefresh:e.invalidateOnRefresh&&n?.invalidate?()=>n.invalidate():void 0,snap:e.snap===void 0?void 0:Kp(e.snap,n),markers:e.markers,container:d,onUpdate:(f,g)=>{if(n&&a!==!1&&n.progress(f),e.onUpdate){const p=f<c||g<0?-1:1;e.onUpdate({progress:f,velocity:g,direction:p})}c=f},onEnter:u(0,e.onEnter),onLeave:u(1,e.onLeave),onEnterBack:u(2,e.onEnterBack),onLeaveBack:u(3,e.onLeaveBack)}),n&&a===!1&&n.progress(0),h.start(),t.own(h)}function Kp(t,e){const n=i=>i==="labels"?o=>Yp(o,e?.labelProgresses?.()??[]):i;if(typeof t!="object"||Array.isArray(t))return n(t);const s=t.ease?Pn(t.ease):void 0;return{snapTo:n(t.snapTo),duration:t.duration,delay:t.delay,ease:s?s.fn??$t(s.easing):void 0}}function Yp(t,e){return e.reduce((n,s)=>Math.abs(s-t)<Math.abs(n-t)?s:n,e[0]??t)}function zp(t,e,n,s){const i=()=>e.timeline.getTracks({property:"x"}).map(o=>o.target).filter(o=>{const r=t.elementFor(o);return!!r&&r!==n&&r.contains(n)});return i().length===0&&s("gsap-compat: containerAnimation does not move an ancestor of the trigger along x"),{range:()=>{const o=e.scrollTrigger;return o||s("gsap-compat: containerAnimation needs its own scrollTrigger (created before this one)"),{start:o?.startOffset??0,end:o?.endOffset??0}},progress:()=>e.progress(),shiftAt:o=>{const r=e.timeline.getStateAtTime(o*e.timeline.duration);let a=0;for(const l of i()){const c=r.values.get(l)?.get("x");typeof c=="number"&&(a+=c)}return a}}}class nc{conditions={};scope;host;items=[];snapshots=new Map;constructor(e,n){this.host=e,this.scope=n}add(e){const n=this.host.collector;this.host.setCollector(this);try{const s=e();return typeof s=="function"&&this.items.push({revert:s}),s}finally{this.host.setCollector(n)}}track(e){this.items.push(e)}touch(e,n){this.snapshots.has(e)||this.snapshots.set(e,{name:n,style:e.getAttribute("style"),d:e.getAttribute("d")})}revert(){for(const e of this.items.splice(0).reverse())e.revert?e.revert():e.kill?e.kill():e.destroy?.();for(const[e,{name:n,style:s,d:i}]of this.snapshots)s===null?e.removeAttribute("style"):e.setAttribute("style",s),i!==null&&e.setAttribute("d",i),this.host.forget(n);this.snapshots.clear()}kill(){this.revert()}}class Xp{host;scope;entries=[];listeners=[];scheduled=!1;constructor(e,n){this.host=e,this.scope=n}add(e,n){const s={conditions:e,setup:n,queries:new Map},i=typeof e=="string"?{matches:e}:e;if(typeof window<"u"&&typeof window.matchMedia=="function")for(const[o,r]of Object.entries(i)){const a=window.matchMedia(r);s.queries.set(o,a);const l=()=>this.scheduleUpdate();a.addEventListener("change",l),this.listeners.push(()=>a.removeEventListener("change",l))}return this.entries.push(s),this.update(s),this}revert(){for(const e of this.listeners.splice(0))e();for(const e of this.entries.splice(0))e.context?.revert()}kill(){this.revert()}scheduleUpdate(){this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1;for(const e of this.entries)this.update(e)}))}update(e){const n={};for(const[r,a]of e.queries)n[r]=a.matches;const s=Object.values(n).some(Boolean),i=s?JSON.stringify(n):void 0;if(i===e.key||(e.context?.revert(),e.context=void 0,e.key=i,!s))return;const o=new nc(this.host,this.scope);o.conditions=n,o.add(()=>e.setup(o)),e.context=o}}class Gp{frames;canvas;context;options;images;ready;current=0;drawn=-1;loadedCount=0;inFlight=0;destroyed=!1;onResize=()=>this.resize();constructor(e,n){this.canvas=e,this.context=e.getContext("2d"),this.options=n,this.frames=Math.max(1,Math.floor(n.frames)),this.images=new Array(this.frames),this.ready=new Array(this.frames).fill(!1),typeof window<"u"&&window.addEventListener("resize",this.onResize,{passive:!0}),this.resize(),this.pump()}get frame(){return this.current}set frame(e){this.current=Math.max(0,Math.min(this.frames-1,e)),this.draw()}get loaded(){return this.loadedCount}destroy(){this.destroyed=!0,typeof window<"u"&&window.removeEventListener("resize",this.onResize);for(const e of this.images)e&&(e.src="")}resize(){const e=typeof window<"u"?Math.min(window.devicePixelRatio||1,2):1,n=Math.round(this.canvas.clientWidth*e),s=Math.round(this.canvas.clientHeight*e);n>0&&s>0&&(this.canvas.width!==n||this.canvas.height!==s)&&(this.canvas.width=n,this.canvas.height=s),this.drawn=-1,this.draw()}draw(){const e=Math.round(this.current),n=this.nearestReady(e);if(n===-1||n===this.drawn||!this.context)return;const s=this.images[n],{width:i,height:o}=this.canvas,r=(this.options.fit??"cover")==="cover"?Math.max(i/s.naturalWidth,o/s.naturalHeight):Math.min(i/s.naturalWidth,o/s.naturalHeight),a=s.naturalWidth*r,l=s.naturalHeight*r;this.context.clearRect(0,0,i,o),this.context.drawImage(s,(i-a)/2,(o-l)/2,a,l),this.drawn=n,this.pump()}nearestReady(e){for(let n=0;n<this.frames;n++){if(e-n>=0&&this.ready[e-n])return e-n;if(e+n<this.frames&&this.ready[e+n])return e+n}return-1}pump(){const e=this.options.concurrency??6,n=Math.round(this.current);for(let s=0;s<this.frames&&this.inFlight<e;s++)for(const i of s===0?[n]:[n+s,n-s])i<0||i>=this.frames||this.images[i]||this.inFlight>=e||this.load(i)}load(e){const n=new Image;n.decoding="async",this.images[e]=n,this.inFlight++;const s=i=>{if(!this.destroyed){if(this.inFlight--,i){this.ready[e]=!0,this.loadedCount++,this.options.onProgress?.(this.loadedCount,this.frames);const o=Math.round(this.current);(Math.abs(e-o)<Math.abs(this.drawn-o)||this.drawn===-1)&&(this.drawn=-1,this.draw())}this.pump()}};n.onload=()=>s(!0),n.onerror=()=>s(!1),n.src=this.options.url(e)}}const Up={opacity:0,y:-16},Vp={opacity:0,y:16};async function Jp(t,e,n,s){const i=e.collector?.scope??e.root,o=i.ownerDocument??i,r=()=>s.shared?[...i.querySelectorAll(s.shared)]:[];if(s.native&&typeof o.startViewTransition=="function")return Zp(o,s,r);const a=s.duration??.35,l=s.ease??"power2.inOut",c=m=>new Promise(b=>{m(b)||b()}),h=r(),u=h.length?fo(e,h):void 0,d=s.from!==void 0?sc(e,s.from,s.shared):[];if(d.length&&s.leave!==!1){const m=s.leave??Up;await c(b=>t.to(d,{...m,duration:a,ease:l,onComplete:b}))}await s.update();const f=[],g=typeof s.to=="function"?s.to():s.to,p=g!==void 0?sc(e,g,s.shared):[];if(p.length&&s.enter!==!1){const m=s.enter??Vp;f.push(c(b=>t.fromTo(p,m,{...ql(m),duration:a,ease:l,onComplete:b})))}if(u){const m=r().filter(b=>!h.includes(b));m.length&&f.push(c(b=>go(e,n,u,{targets:m,duration:a*1.4,ease:l,enter:!1,onComplete:b})))}await Promise.all(f)}function sc(t,e,n){const s=t.resolveTargets(e).map(i=>t.elementFor(i)).filter(i=>!!i);return n?s.flatMap(i=>!i.querySelector(n)&&!i.matches(n)?[i]:[...i.children].filter(o=>!o.matches(n)&&!o.querySelector(n))):s}async function Zp(t,e,n){const s=(a,l)=>{const c=a.dataset?.flipId;c&&a.style.setProperty("view-transition-name",l?`tf-${c.replace(/[^\w-]/g,"-")}`:"")},i=n();i.forEach(a=>s(a,!0));let o=[];await t.startViewTransition(async()=>{i.forEach(a=>s(a,!1)),await e.update(),o=n(),o.forEach(a=>s(a,!0))}).finished,o.forEach(a=>s(a,!1))}const ic={create:(t,e)=>so(t,ll(e))},oc={create:(t,e)=>so(t,{fn:cl(e)})},rc={create:(t,e)=>so(t,{fn:hl(e)})},Qp=new Set(["keyframes","duration","delay","ease","easeEach","stagger","repeat","repeatDelay","yoyo","repeatRefresh","paused","id","onStart","onUpdate","onComplete","onRepeat","onReverseComplete","scrollTrigger"]),ac=.5,tg="power1.inOut";function eg(t){return t.keyframes!==void 0&&t.keyframes!==null}function ng(t){const e=t.keyframes,n={};for(const[c,h]of Object.entries(t))Qp.has(c)||(n[c]=h);if(Array.isArray(e))return e.map(c=>({...n,...c,duration:c.duration??t.duration??ac}));const s=Object.entries(e),i=t.duration??ac,o=e.easeEach??t.easeEach??tg;if(s.length>0&&s.every(([c])=>/^\s*-?\d+(\.\d+)?\s*%\s*$/.test(c)||c==="easeEach")){const c=s.filter(([d])=>d!=="easeEach").map(([d,f])=>({at:Number.parseFloat(d)/100,step:f})).sort((d,f)=>d.at-f.at),h=[];let u=0;for(const{at:d,step:f}of c){const g=Math.max(0,d-u);h.push({...n,ease:o,...f,duration:g*i}),u=d}return h}const r=s.filter(([c,h])=>c!=="easeEach"&&Array.isArray(h)),a=Math.max(0,...r.map(([,c])=>c.length)),l=[];for(let c=0;c<a;c++){const h={...n,ease:o,duration:i/a};for(const[u,d]of r)c<d.length&&(h[u]=d[c]);l.push(h)}return l}function lc(t,e,n,s={}){const i=e.collector?.scope??e.root,o=typeof s.scroller=="string"?i.querySelector(s.scroller):s.scroller??null,r={x:o?o.scrollLeft:window.scrollX,y:o?o.scrollTop:window.scrollY},a={x:o?o.scrollWidth-o.clientWidth:document.documentElement.scrollWidth-window.innerWidth,y:o?o.scrollHeight-o.clientHeight:document.documentElement.scrollHeight-window.innerHeight},l=(k,w)=>{if(w===void 0)return r[k];if(typeof w=="number")return w;if(w==="max")return a[k];const M=typeof w=="string"?i.querySelector(w):w;if(!M)return r[k];const S=M.getBoundingClientRect(),A=o?.getBoundingClientRect(),E=(k==="x"?s.offsetX:s.offsetY)??s.offset??0;return k==="x"?S.left-(A?.left??0)+r.x-E:S.top-(A?.top??0)+r.y-E},c=typeof n=="object"&&n!==null&&!("nodeType"in n)?{x:l("x",n.x),y:l("y",n.y)}:{x:r.x,y:l("y",n)},h={x:Math.max(0,Math.min(a.x,c.x)),y:Math.max(0,Math.min(a.y,c.y))},u={...r},d=()=>{o?(o.scrollLeft=u.x,o.scrollTop=u.y):window.scrollTo({left:u.x,top:u.y,behavior:"instant"})},f=["wheel","touchstart","keydown"],g=o??window,p=()=>{b.kill(),m()},m=()=>{for(const k of f)g.removeEventListener(k,p)},b=t.to(u,{x:h.x,y:h.y,duration:s.duration??1,ease:s.ease??"power2.inOut",onStart:s.onStart,onUpdate:()=>{d(),s.onUpdate?.()},onComplete:()=>{m(),s.onComplete?.()}});if(s.autoKill!==!1)for(const k of f)g.addEventListener(k,p,{passive:!0});return b}function sg(t,e,n){const s=t.collector?.scope??t.root,i=typeof e=="string"?[...s.querySelectorAll(e)]:"nodeType"in e?[e]:Array.from(e),{interval:o=.1,batchMax:r,onEnter:a,onLeave:l,onEnterBack:c,onLeaveBack:h,...u}=n,d={onEnter:a,onLeave:l,onEnterBack:c,onLeaveBack:h},f={onEnter:[],onLeave:[],onEnterBack:[],onLeaveBack:[]},g={},p=b=>{g[b]!==void 0&&clearTimeout(g[b]),g[b]=void 0;const k=f[b].splice(0);k.length>0&&d[b]?.(k)},m=(b,k)=>{if(d[b]){if(f[b].push(k),r!==void 0&&f[b].length>=r)return p(b);g[b]===void 0&&(g[b]=setTimeout(()=>p(b),o*1e3))}};return i.map(b=>To(t,{...u,trigger:b,onEnter:()=>m("onEnter",b),onLeave:()=>m("onLeave",b),onEnterBack:()=>m("onEnterBack",b),onLeaveBack:()=>m("onLeaveBack",b)})).filter(b=>b!==void 0)}class Jt{compat;stage;options;autoplayPending;started=!1;killed=!1;recipe=[];firstElement;scrollDriver;events=[];ranges=[];playhead={time:0,iteration:0,direction:"forward",fresh:!0};waitingToWrap=!1;finishedThisFrame=!1;backwards=!1;constructor(e,n={}){this.stage=e;const s={...n,onWarning:n.onWarning??e.onWarning};if(this.options=s,this.compat=new Pe({...s,startValue:(i,o)=>{const r=e.objectFor(i);if(r)return rg(r[o]);const a=e.appliedValue(i,o);if(a!==void 0)return a;if(o==="d")return Cl(e.elementFor(i))??void 0;if(o==="text")return e.elementFor(i)?.textContent??void 0;if(o==="strokeDasharray"||o==="strokeDashoffset"){const l=fc(e.elementFor(i));if(l!==void 0)return o==="strokeDasharray"?[l,l]:0}},startVelocity:(i,o)=>e.velocityOf(i,o),layoutColumns:i=>dc(i.map(o=>e.elementFor(o))),random:()=>e.utils.random(0,1)}),this.compat.timeline.onComplete=()=>{this.finishedThisFrame=!0},e.collector?.track(this),e.liveTimelines.add(this),this.autoplayPending=!s.paused&&!s.scrollTrigger,s.scrollTrigger){const i=s.scrollTrigger;queueMicrotask(()=>{this.killed||(this.scrollDriver=To(e,i,this,this.firstElement,o=>s.onWarning?.(o)))})}this.autoplayPending&&queueMicrotask(()=>{this.autoplayPending&&this.play()})}get timeline(){return this.compat.timeline}get scrollTrigger(){return this.scrollDriver}to(e,n,s){return eg(n)?this.record(()=>this.keyframed(e,n,s)):this.record(()=>this.tween(e,[n],s,([i],o,r)=>this.compat.to(o,i,r)))}from(e,n,s){return this.record(()=>this.tween(e,[n],s,([i],o,r)=>this.compat.from(o,i,r)))}fromTo(e,n,s,i){return this.record(()=>this.tween(e,[n,s],i,([o,r],a,l)=>this.compat.fromTo(a,o,r,l)))}set(e,n,s){return this.record(()=>this.tween(e,[n],s,([i],o,r)=>this.compat.set(o,i,r)))}addLabel(e,n){return this.record(()=>this.compat.addLabel(e,n))}add(e,n){return this.record(()=>{e.autoplayPending=!1,e.timeline.stop(),e.stage.deactivate(e.timeline),this.compat.add(e.compat,n)})}invalidate(){const e=this.compat.progress();this.compat.progress(0),this.stage.render(this.timeline),this.compat.reset(),this.events=[],this.ranges=[];for(const n of this.recipe)n();return this.syncDuration(),this.compat.progress(e),this.stage.render(this.timeline),this}call(e,n=[],s){return this.record(()=>{const i=this.compat.addEvent(s);this.events.push({time:i,run:()=>e(...n)})})}addPause(e,n,s=[]){return this.record(()=>{const i=this.compat.addEvent(e);this.events.push({time:i,pause:!0,run:()=>n?.(...s)})})}tweenTo(e,n={}){return this.tweenFromTo(this.timeline.currentTime/1e3,e,n)}tweenFromTo(e,n,s={}){this.pause(),this.seek(e);const i=this.timeline.currentTime,o=Math.max(0,Math.min(this.timeline.duration,this.compat.timeOf(n))),r={time:i},a=s.duration??Math.abs(o-i)/1e3/(this.timeScale()||1),l=new Jt(this.stage,{onStart:s.onStart,onComplete:s.onComplete});return l.to(r,{time:o,duration:a,ease:s.ease??"none",onUpdate:()=>{this.moveTo(r.time),s.onUpdate?.()}}),l}play(){this.autoplayPending=!1,this.started||(this.started=!0,this.options.onStart?.());const e=this.timeline.playbackState==="playing",n=this.timeline.playbackState==="paused";if(this.timeline.play(),!e){const s=this.timeline,i=s.direction==="forward"?s.currentTime===0:s.currentTime===s.duration;this.playhead={...this.readPlayhead(),fresh:i&&!n},this.waitingToWrap=!1}return this.stage.liveTimelines.add(this),this.stage.render(this.timeline),this.stage.activate(this.timeline,{onUpdate:()=>this.afterFrame()}),this}pause(){return this.autoplayPending=!1,this.timeline.pause(),this.stage.deactivate(this.timeline),this}resume(){return this.play()}restart(){return this.timeline.stop(),this.backwards=!1,this.play()}reverse(){this.backwards=!this.backwards;const e=this.timeline.playbackState==="idle"&&this.timeline.direction==="forward";return this.timeline.reverse(),e&&this.timeline.currentTime===0&&this.timeline.seek(this.timeline.duration),this.play()}labelProgresses(){const e=this.timeline.duration;return e>0?this.compat.labelTimes().map(n=>n/e):[]}reversed(){return this.timeline.direction==="reverse"}seek(e){return this.autoplayPending=!1,this.compat.seek(e),this.stage.render(this.timeline),this.playhead=this.readPlayhead(),this.waitingToWrap=!1,this.options.onUpdate?.(),this}progress(e){return e===void 0?this.compat.progress():(this.autoplayPending=!1,this.moveTo(Math.max(0,Math.min(1,e))*this.timeline.duration),this.compat.progress())}timeScale(e){return this.compat.timeScale(e)}duration(){return this.compat.duration()}isActive(){return this.timeline.playbackState==="playing"}kill(){return this.killed=!0,this.stage.liveTimelines.delete(this),this.scrollDriver?.destroy(),this.scrollDriver=void 0,this.autoplayPending=!1,this.timeline.stop(),this.stage.deactivate(this.timeline),this.compat.kill(),this}toDefinition(){return this.compat.toDefinition()}killTweensOf(e,n){for(const s of e)for(const i of n??[void 0])this.timeline.removeTracks({target:s,...i!==void 0&&{property:i}});this.timeline.tracks.length===0&&this.events.length===0&&this.kill()}record(e){return this.recipe.push(e),e(),this.syncDuration(),this}syncDuration(){if(this.events.length===0)return;this.timeline.setDuration(void 0);const e=Math.max(...this.events.map(n=>n.time));e>this.timeline.duration&&this.timeline.setDuration(e)}readPlayhead(){const e=this.timeline;return{time:e.currentTime,iteration:e.loopIteration,direction:e.direction}}moveTo(e){const n=this.playhead;this.timeline.seek(e),this.stage.render(this.timeline);const s={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:e>=n.time?"forward":"reverse"},i={...n,iteration:s.iteration,direction:s.direction};this.playhead={...this.readPlayhead()},this.waitingToWrap=!1,this.runCrossings(i,s,!1),this.options.onUpdate?.()}refreshForRepeat(){const e=this.timeline.currentTime;this.compat.reset(),this.events=[],this.ranges=[];for(const n of this.recipe)n();this.syncDuration(),this.timeline.seek(Math.min(e,this.timeline.duration))}afterFrame(){const e=this.timeline,n=e.repeatDelayRemaining>0;if(this.waitingToWrap&&n){this.options.onUpdate?.();return}this.waitingToWrap=!1;const s=this.playhead,i=this.readPlayhead();this.playhead=i;const o=this.options.yoyo===!0;n&&!o&&i.iteration>s.iteration&&(this.playhead={time:0,iteration:i.iteration,direction:"forward",fresh:!0},this.waitingToWrap=!0);const r=this.runCrossings(s,i,n);if(this.options.onUpdate?.(),this.finishedThisFrame&&!r){this.finishedThisFrame=!1;const a=e.currentTime===0&&e.direction==="reverse";!this.scrollDriver&&!o&&this.stage.liveTimelines.delete(this),a&&this.backwards?this.options.onReverseComplete?.():this.options.onComplete?.()}this.finishedThisFrame=!1}runCrossings(e,n,s){if(this.events.length===0&&this.ranges.length===0&&!this.options.onRepeat&&!this.options.repeatRefresh)return!1;const i=this.events,{crossings:o,passes:r}=Ui(i.map(a=>a.time),e,n,{duration:this.timeline.duration,alternate:this.options.yoyo===!0,holding:s});for(const a of o){if(this.killed)return!0;if(a.kind==="repeat"){this.options.repeatRefresh&&this.refreshForRepeat(),this.options.onRepeat?.();continue}const l=i[a.index];if(!(l.direction&&l.direction!==a.direction)){if(l.pause)return this.timeline.seek(l.time),this.stage.render(this.timeline),this.pause(),this.playhead=this.readPlayhead(),this.waitingToWrap=!1,l.run(),!0;l.run()}}for(const a of this.ranges)r.some(([c,h])=>c!==h&&Math.max(c,h)>=a.start&&Math.min(c,h)<=a.end)&&a.run();return!1}tween(e,n,s,i){const o=this.resolve(e);if(!o)return;const{onStart:r,onUpdate:a,onComplete:l}=n[n.length-1];if(r||a||l){let c=1/0,h=-1/0;const u=(d,f,g)=>{i(d,f,g),c=Math.min(c,this.compat.lastStart),h=Math.max(h,this.compat.lastEnd)};if(this.buildTween(o,n,s,u),c===1/0)return;r&&this.events.push({time:c,direction:"forward",run:r}),a&&this.ranges.push({start:c,end:h,run:a}),l&&this.events.push({time:h,direction:"forward",run:l});return}this.buildTween(o,n,s,i)}keyframed(e,n,s){const i=this.resolve(e);if(!i)return;const o=ng(n);if(o.length===0)return;const r=i.length>1?ro(n.stagger,this.staggerContext(i)):void 0,a=i.map(m=>this.targetFor(m)).filter(m=>m!==void 0),l=r?a.map(m=>[m]):[a],c=r?ss(i.length,r).map(m=>m/1e3):[0],h=this.compat.timeOf(s)/1e3+Ms(n.delay,0)/1e3;let u=1/0,d=-1/0;if(l.forEach((m,b)=>{o.forEach((k,w)=>{const M=w===0?h+c[b]:">";this.tween(m,[k],M,([S],A,E)=>this.compat.to(A,S,E)),u=Math.min(u,this.compat.lastStart),d=Math.max(d,this.compat.lastEnd)})}),u===1/0)return;const{onStart:f,onUpdate:g,onComplete:p}=n;f&&this.events.push({time:u,direction:"forward",run:f}),g&&this.ranges.push({start:u,end:d,run:g}),p&&this.events.push({time:d,direction:"forward",run:p})}staggerContext(e){return{count:e.length,columnsFromLayout:()=>dc(e.map(n=>this.stage.elementFor(n))),random:()=>this.stage.utils.random(0,1)}}buildTween(e,n,s,i){const o=e.map(d=>this.targetFor(d));if(!(e.length>1&&(n.some(og)||e.some(d=>this.stage.objectFor(d)!==void 0)))){const d=this.targetFor(e[0]);i(n.map(f=>this.prepare(uc(f,0,d,this.stage.utils,o),e)),e,s);return}const a=n.length-1,{stagger:l,...c}=n[a],h=ro(l,this.staggerContext(e)),u=h?ss(e.length,h).map(d=>d/1e3):e.map(()=>0);e.forEach((d,f)=>{const g=f===0?Ms(c.delay,0)/1e3+u[0]:0,p=f===0?0:u[f]-u[f-1],m=f===0?s:`<${p<0?"-":"+"}${Math.abs(p).toFixed(6)}`,k=n.map((w,M)=>M===a?{...c,delay:g}:w).map(w=>this.prepare(uc(w,f,this.targetFor(d),this.stage.utils,o),[d]));i(k,[d],m)})}targetFor(e){return this.stage.elementFor(e)??this.stage.objectFor(e)}prepare(e,n){const s=r=>this.options.onWarning?.(r),i=r=>this.stage.query(r);let o=e;if(e.motionPath!==void 0){const r=yp(e.motionPath,{query:i,targets:n.map(a=>this.stage.elementFor(a)).filter(a=>!!a),warn:s});o={...o,motionPath:r}}if(e.morphSVG!==void 0){const r=bp(e.morphSVG,i,s),{morphSVG:a,...l}=o;o=r?{...o,morphSVG:r}:l}if(e.drawSVG!==void 0){const r=fc(this.stage.elementFor(n[0]));if(r===void 0){s("gsap-compat: drawSVG needs an SVG shape with a stroke (path, line, circle…)");const{drawSVG:a,...l}=o;o=l}else o=K0(o,r)}return o}resolve(e){const n=this.stage.resolveTargets(e);if(n.length===0){this.options.onWarning?.(`gsap-compat: no elements found for target ${ag(e)}`);return}return this.firstElement??=n.map(s=>this.stage.elementFor(s)).find(s=>s!==void 0),n}}function cc(t=new xl){const e=o=>{const{config:r}=vs(o);return new Jt(t,{repeat:r.repeat,yoyo:r.yoyo,repeatDelay:r.repeatDelay,paused:r.paused,onStart:r.onStart,onUpdate:r.onUpdate,onComplete:r.onComplete,onRepeat:r.onRepeat,onReverseComplete:r.onReverseComplete,repeatRefresh:r.repeatRefresh,scrollTrigger:r.scrollTrigger})},n=o=>{const{onStart:r,onUpdate:a,onComplete:l,onRepeat:c,onReverseComplete:h,repeatRefresh:u,...d}=o;return d},s=o=>(o&&t.collector?.track(o),o),i={stage:t,ticker:t.ticker,utils:t.utils,getProperty:(o,r)=>{const[a]=t.resolveTargets(o);if(a===void 0)return;const l=t.objectFor(a);return l?l[r]:t.appliedValue(a,r)??Tl(r)},scrollTrigger:o=>s(To(t,o)),scrollBatch:(o,r)=>sg(t,o,r).map(a=>s(a)),scrollTo:(o,r)=>lc(i,t,o,r),refreshScroll:()=>{_n.refreshAll(),Mo.refreshAll()},smoothScroll:(o={})=>{const r=typeof o.scroller=="string"?(t.collector?.scope??t.root).querySelector(o.scroller):o.scroller;return s(new Mo({...o,scroller:r}).start())},context:(o,r)=>{const a=new nc(t,r);return o&&a.add(()=>o(a)),a},matchMedia:o=>new Xp(t,o),customEase:ic.create,customBounce:oc.create,customWiggle:rc.create,pageTransition:o=>Jp(i,t,r=>new Jt(t,r),o),imageSequence:(o,r)=>{const a=typeof o=="string"?(t.collector?.scope??t.root).querySelector(o):o;if(!(a instanceof HTMLCanvasElement))throw new Error(`gsap-compat: imageSequence needs a <canvas>, got ${String(o)}`);return s(new Gp(a,r))},quickTo:(o,r,a={})=>{const l=new Jt(t,{paused:!0}),[c]=t.resolveTargets(o);return Object.assign(u=>{if(!c)return;const d=a.spring!==void 0?t.velocityOf(c,r)??0:0;l.compat.reset(),l.compat.to(c,{[r]:u,duration:a.duration??.4,ease:a.ease??"power3.out",...a.spring!==void 0&&{spring:ig(a.spring,r,d)}}),l.timeline.stop(),l.timeline.play(),t.activate(l.timeline)},{tween:l,kill:()=>l.kill()})},timeline:o=>new Jt(t,o),to:(o,r)=>{if(r.scrollTo!==void 0){const{scrollTo:a,...l}=r,c=typeof a=="object"&&a!==null&&!("nodeType"in a)?a:{},h=typeof o!="string"&&o!==window&&o.nodeType===1;return lc(i,t,a,{...l,offsetX:c.offsetX,offsetY:c.offsetY,scroller:h?o:void 0})}return e(r).to(o,n(r))},from:(o,r)=>e(r).from(o,n(r)),fromTo:(o,r,a)=>e(a).fromTo(o,r,n(a)),set:(o,r)=>e(r).set(o,n(r)),delayedCall:(o,r,a)=>new Jt(t).call(r,a,o),killTweensOf:(o,r)=>{const a=t.resolveTargets(o),l=typeof r=="string"?r.split(",").map(c=>c.trim()).filter(Boolean):r;for(const c of[...t.liveTimelines])c.killTweensOf(a,l)},convertToPath:o=>kp(o,t.root),splitText:(o,r)=>{const a=t.collector?.scope??t.root,l=typeof o=="string"?Array.from(a.querySelectorAll(o)):"nodeType"in o?[o]:Array.from(o);return s($p(l,r))},draggable:(o,r)=>s(Tp(i,t,o,r)),getFlipState:o=>fo(t,o),flipFrom:(o,r)=>go(t,a=>new Jt(t,a),o,r),flip:(o,r,a)=>{const l=fo(t,o);return r(),go(t,c=>new Jt(t,c),l,{targets:o,...a})}};return i}const Ht=cc();function ig(t,e,n){return t===!0?{velocity:{[e]:n}}:typeof t=="string"?{preset:t,velocity:{[e]:n}}:{...t,velocity:{[e]:n}}}function og(t){return t.morphSVG!==void 0||t.drawSVG!==void 0||t.text!==void 0||t.scrambleText!==void 0||hc(t)}function hc(t){return Object.entries(t).some(([e,n])=>(typeof n=="function"||Ml(n))&&!oo.has(e))}function uc(t,e,n,s,i){if(!hc(t))return t;const o={};for(const[r,a]of Object.entries(t))oo.has(r)?o[r]=a:typeof a=="function"?o[r]=a(e,n,i):Ml(a)?o[r]=s.resolveRandomString(a):o[r]=a;return o}function dc(t){const e=t.map(s=>s?.getBoundingClientRect().top);if(e[0]===void 0)return t.length;let n=0;for(const s of e){if(s===void 0||Math.abs(s-e[0])>1)break;n++}return Math.max(1,n)}function fc(t){const e=t;if(typeof e?.getTotalLength=="function")return e.getTotalLength()}function rg(t){if(typeof t=="number"||typeof t=="string"||Array.isArray(t)&&t.every(e=>typeof e=="number"))return t}function ag(t){return typeof t=="string"?`"${t}"`:String(t)}class Eo{media;offset;driftTolerance;constructor(e,n={}){this.media=e,this.offset=n.offset??0,this.driftTolerance=Math.max(0,n.driftTolerance??.15)}targetTime(e){return Math.max(0,e/1e3+this.offset)}update(e,n){const s=this.targetTime(e);n?(this.media.paused&&this.safePlay(),Math.abs(this.media.currentTime-s)>this.driftTolerance&&(this.media.currentTime=s)):(this.media.paused||this.media.pause(),this.media.currentTime!==s&&(this.media.currentTime=s))}seek(e){this.media.currentTime=this.targetTime(e)}setRate(e){this.media.playbackRate=e}dispose(){this.media.paused||this.media.pause()}safePlay(){const e=this.media.play();e&&typeof e.catch=="function"&&e.catch(()=>{})}}function pc(t,e,n,s,i){const o=n-i;if(o<0){e.paused||e.pause(),e.currentTime=0;return}t.update(o,s)}class Es{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(e,n={}){if(typeof e=="string"){const s=document.querySelector(e);if(!s)throw new Error(`Container not found: ${e}`);this.container=s}else this.container=e;this.options=n,this.adapter=new $e}async load(e){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(e)}async loadSource(e){let n;if(typeof e=="string"){const s=await fetch(e);if(!s.ok)throw new Error(`Failed to load animation: ${s.statusText}`);n=await s.json()}else n=e;this.useDefinition(n),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(e){const n={...e.config};this.options.speed!==void 0&&(n.speed=this.options.speed),this.options.loop!==void 0&&(n.loop=this.options.loop),this.options.alternate!==void 0&&(n.alternate=this.options.alternate),this.timeline=ze({...e,config:n}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(e,n={}){if(e.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const s=new Set;for(const o of e){if(s.has(o.id))throw new Error(`tinyfly: scenario id "${o.id}" is used more than once`);s.add(o.id)}const i=n.initial===void 0?e[0]:e.find(o=>o.id===n.initial);if(!i)throw new Error(`tinyfly: there is no scenario "${n.initial}"`);this.scenarioList=[...e],this.scenarioId=i.id,await this.loadSource(i.timeline)}get scenarios(){return this.scenarioList.map(e=>({id:e.id,label:e.label??e.id}))}get scenario(){return this.scenarioId}setScenario(e){const n=this.scenarioList.find(a=>a.id===e);if(!n||!this.timeline)return!1;if(e===this.scenarioId)return!0;const s=this.isPlaying,i=this.currentTime>=this.duration-.5,o=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=e,this.useDefinition(n.timeline),this.lastMarkerId=null;let r=0;return this.reducedMotion||i?r=this.duration:o!==void 0&&(r=this.markers.find(a=>a.id===o)?.time??0),this.seek(r),s&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(e){if(this.authored.has(e))return;const n={style:e.getAttribute("style")};e.children.length===0&&(n.text=e.textContent??"");const s=e.tagName.toLowerCase()==="path"?e:e.querySelector("path");s&&(n.path={element:s,d:s.getAttribute("d")}),this.authored.set(e,n)}restoreAuthored(){for(const[e,n]of this.authored){n.style===null?e.removeAttribute("style"):e.setAttribute("style",n.style),n.text!==void 0&&e.textContent!==n.text&&(e.textContent=n.text),n.path&&(n.path.d===null?n.path.element.removeAttribute("d"):n.path.element.setAttribute("d",n.path.d));const s=e.dataset;s&&delete s.shineBase}}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){for(const e of this.listeners)e()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const e=this.currentTime;let n;for(const s of this.markers)if(s.time<=e+.5)n=s;else break;return n}caption(e,n){const s=e?this.markers.find(r=>r.id===e):this.currentMarker;if(!s)return;const i=n??this.language(),o=r=>r?.[i]?.[s.id]??r?.[i.split("-")[0]]?.[s.id];return o(this.options.captions)??o(this.timeline?.captions)??s.label}next(){if(!this.timeline)return;const e=this.currentTime,n=this.markers.find(s=>s.time>e+.5);if(this.reducedMotion){this.seek(n?n.time:this.duration);return}e>=this.duration-.5||(this.stepping=n!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const e=this.currentTime,n=[...this.markers].reverse().find(s=>s.time<e-.5);this.pause(),this.seek(n?n.time:0)}goToMarker(e){const n=this.markers.find(s=>s.id===e);n&&(this.pause(),this.seek(n.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const e=this.options.initialFrame??"start";if(e==="none")return;const n=e==="end"?this.timeline.duration:e==="start"?0:e;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,n))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(n=>{for(const s of n)this.onScreen=s.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const e=this.container.getBoundingClientRect?.();e&&(e.width>0||e.height>0)&&(this.onScreen=e.bottom>0&&e.top<window.innerHeight&&e.right>0&&e.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const e=this.onScreen&&document.visibilityState!=="hidden";!e&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):e&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const e=this.currentMarker,n=e?.id;n!==this.lastMarkerId&&(this.lastMarkerId=n,this.options.onMarker(e))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(n=>{const s=n,i=Number(s.getAttribute("data-tinyfly-start")??"0")||0,o=s.getAttribute("data-volume");o!==null&&(s.volume=Math.max(0,Math.min(1,Number(o)||0))),this.mediaTargets.push({el:s,startTime:i,sync:new Eo(s)})})}syncAllMedia(e,n){for(const s of this.mediaTargets)pc(s.sync,s.el,e,n,s.startTime)}loadFromString(e){const n=JSON.parse(e);this.load(n)}registerTarget(e,n){if(typeof n=="string"){const s=this.container.querySelector(n);s&&(this.rememberAuthored(s),this.targets[e]=s,this.adapter.registerTarget(e,s))}else this.rememberAuthored(n),this.targets[e]=n,this.adapter.registerTarget(e,n)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(n=>{const s=n.closest("[data-tinyfly-symbol]");if(s&&s!==n)return;const i=n.getAttribute("data-tinyfly");i&&this.registerTarget(i,n)}),this.timeline&&new Set(this.timeline.tracks.map(s=>s.target)).forEach(s=>{if(!this.targets[s]){const i=this.container.querySelector(`[data-tinyfly="${s}"]`)||this.container.querySelector(`.${s}`)||this.container.querySelector(`#${s}`);i&&this.registerTarget(s,i)}})}setupSymbolInstances(){this.symbolInstances=[];const e=this.options.symbols;if(!e||e.length===0)return;const n=new Map(e.map(s=>[s.id,s]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const i=s.getAttribute("data-tinyfly-symbol");if(!i)return;const o=n.get(i);if(!o||!o.timeline.tracks?.length)return;const r=new $e;s.querySelectorAll("[data-tinyfly]").forEach(a=>{const l=a.getAttribute("data-tinyfly");l&&r.registerTarget(l,a)}),this.symbolInstances.push({adapter:r,timeline:ze(o.timeline)})})}attachMedia(e,n){this.mediaSync=new Eo(e,n),this.timeline&&(this.mediaSync.setRate(this.timeline.speed),this.mediaSync.update(this.timeline.currentTime,this.isPlaying))}detachMedia(){this.mediaSync?.dispose(),this.mediaSync=void 0}play(){!this.timeline||this.isDestroyed||(this.autoplayWhenSeen=!1,this.stepping=this.options.stepMode===!0,this.startPlaying())}startPlaying(){if(!this.timeline||this.isDestroyed)return;const e=this.timeline.playbackState==="idle";this.timeline.play(),e&&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(e){this.timeline&&(this.timeline.seek(e),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(e){this.timeline&&(this.timeline.speed=e,this.mediaSync?.setRate(e))}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 e of this.mediaTargets)e.el.paused||e.el.pause();this.mediaTargets=[],this.adapter.clearTargets();for(const e of this.symbolInstances)e.adapter.clearTargets();this.symbolInstances=[],this.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const e=n=>{if(this.isDestroyed||!this.timeline)return;const s=n-(this.lastTime??n);this.lastTime=n;const i=this.playhead;this.timeline.tick(s),this.stopAtMarker(i),this.applyState();const o=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,o),this.syncAllMedia(this.timeline.currentTime,o),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(e):(this.animationFrameId=void 0,this.notify())};this.animationFrameId=requestAnimationFrame(e)}stopAtMarker(e){const n=this.timeline,s={time:n.currentTime,iteration:n.loopIteration,direction:n.direction};this.playhead=s;const i=this.markers;if(i.length===0)return;const{crossings:o}=Ui(i.map(r=>r.time),e,s,{duration:n.duration,alternate:n.config.alternate===!0,holding:n.repeatDelayRemaining>0});for(const r of o){if(r.kind!=="event")continue;const a=i[r.index];if(this.stepping||a.pause){this.stepping=!1,n.pause(),n.seek(a.time),this.playhead={time:a.time,iteration:n.loopIteration,direction:n.direction};return}}}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}applyState(){if(!this.timeline)return;const e=this.timeline.currentTime;this.adapter.applyState(this.timeline.getStateAtTime(e)),this.announceMarker(),this.notify();for(const n of this.symbolInstances){const s=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(s>0?e%s:e))}}}async function lg(t,e,n={}){const s=new Es(t,{...n,autoplay:!0});return await s.load(e),s}function cg(t,e={}){return new Es(t,e)}const gc={play:"Play",pause:"Pause",prev:"Previous step",next:"Next step",restart:"Restart",scrub:"Position",speed:"Speed",reveal:"Reveal",step:"Step",of:"of",stepFormat:"{index} / {total}",scenario:"Scenario",fullscreen:"Full screen",exitFullscreen:"Exit full screen"},mc="tinyfly-controls-style",hg=`
1
+ (function(w,Ye){typeof exports=="object"&&typeof module<"u"?Ye(exports):typeof define=="function"&&define.amd?define(["exports"],Ye):(w=typeof globalThis<"u"?globalThis:w||self,Ye(w.tinyfly=w.tinyfly||{}))})(this,(function(w){"use strict";function Ye(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function An(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const Wi=2;function qi(t){return t.some(e=>e.interpolation!==void 0)?2:1}function ps(t){return t.property==="text"&&"textConfig"in t}function re(t){return t.kind==="inertia"&&"inertia"in t}function ae(t){return t.kind==="spring"&&"spring"in t}function Ki(t){return t.property==="motionPath"&&"motionPathConfig"in t}function Cf(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"angle"in t}function Ia(t){return"keyframes"in t}class Hf{_currentTime=0;_isRunning=!1;onTick=null;get currentTime(){return this._currentTime}get isRunning(){return this._isRunning}start(){this._isRunning=!0}stop(){this._isRunning=!1}tick(e){this._currentTime+=e,this.onTick?.(e,this._currentTime)}reset(){this._currentTime=0}seek(e){this._currentTime=e}}class Rf{_currentTime=0;_isRunning=!1;_lastFrameTime=null;_rafId=null;_speed;onTick=null;constructor(e={}){this._speed=e.speed??1}get currentTime(){return this._currentTime}get isRunning(){return this._isRunning}get speed(){return this._speed}set speed(e){this._speed=e}start(){this._isRunning||(this._isRunning=!0,this._lastFrameTime=null,this._scheduleFrame())}stop(){this._isRunning=!1,this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null)}reset(){this._currentTime=0,this._lastFrameTime=null}seek(e){this._currentTime=e}_scheduleFrame(){this._rafId=requestAnimationFrame(this._onFrame.bind(this))}_onFrame(e){if(this._isRunning){if(this._lastFrameTime!==null){const s=(e-this._lastFrameTime)*this._speed;this._currentTime+=s,this.onTick?.(s,this._currentTime)}this._lastFrameTime=e,this._scheduleFrame()}}}function Oa(t,e){if(!(e>0))return t;const n=1e3/e;return Math.floor(t/n+1e-9)*n}function Yi(t,e,n="start"){if(e<=1)return 0;if(typeof n=="number"){const s=Math.max(0,Math.min(e-1,n));return Math.abs(t-s)}switch(n){case"end":return e-1-t;case"center":return Math.abs(t-(e-1)/2);case"edges":return(e-1)/2-Math.abs(t-(e-1)/2);default:return t}}function zi(t,e="start"){if(t<=1)return 0;let n=0;for(let s=0;s<t;s++)n=Math.max(n,Yi(s,t,e));return n}function gs(t,e,n){if(n.offsets)return n.offsets[t]??0;const s=n.from??"start",i=Yi(t,e,s);if(n.amount!==void 0){const o=zi(e,s);return o===0?0:n.amount*i/o}return n.each!==void 0?n.each*i:0}function ms(t,e){return Array.from({length:t},(n,s)=>gs(s,t,e))}function $n(t,e){return t<=1?0:Math.max(...ms(t,e))}const ze=1,Xi=6e4,ys=Xi/ze,Bt={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1},bs={gentle:{stiffness:120,damping:18,mass:1},default:{stiffness:180,damping:12,mass:1},snappy:{stiffness:280,damping:20,mass:1},bouncy:{stiffness:220,damping:8,mass:1},wobbly:{stiffness:180,damping:5,mass:1},stiff:{stiffness:400,damping:30,mass:1}};class Pn{from;to;stiffness;damping;mass;restDelta;restSpeed;distance;samples;velocity;settledStep=null;constructor(e){this.from=e.from,this.to=e.to,this.stiffness=e.stiffness??Bt.stiffness,this.damping=e.damping??Bt.damping,this.mass=e.mass??Bt.mass,this.restDelta=e.restDelta??Bt.restDelta,this.restSpeed=e.restSpeed??Bt.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=e.velocity??Bt.velocity,this.isAtRest(this.from)&&(this.settledStep=0)}isAtRest(e){return Math.abs(e-this.to)<this.restDelta*this.distance&&Math.abs(this.velocity)<this.restSpeed*this.distance}valueAt(e){if(e<=0)return this.from;const n=Math.floor(e/ze);if(this.simulateTo(n+1),this.settledStep!==null&&n>=this.settledStep)return this.to;const s=this.samples[Math.min(n,this.samples.length-1)],i=this.samples[Math.min(n+1,this.samples.length-1)],o=e/ze-n;return s+(i-s)*o}settleTime(){return this.simulateTo(ys+1),this.settledStep!==null?this.settledStep*ze:Xi}simulateTo(e){if(this.settledStep!==null)return;const n=Math.min(e,ys+1),s=ze/1e3;for(;this.samples.length<n;){const i=this.samples[this.samples.length-1],o=i-this.to,r=-this.stiffness*o,a=-this.damping*this.velocity,l=(r+a)/this.mass;this.velocity+=l*s;const c=i+this.velocity*s;if(this.samples.push(c),this.isAtRest(c)){this.settledStep=this.samples.length-1;return}}this.samples.length>ys&&(this.settledStep=ys)}}function Lf(t,e){return new Pn(t).valueAt(e)}function _a(t){return new Pn(t).settleTime()}function Nf(t){const e=t.stiffness??Bt.stiffness,n=t.damping??Bt.damping,s=t.mass??Bt.mass;return n<2*Math.sqrt(e*s)}function Df(t){const e=t.stiffness??Bt.stiffness,n=t.mass??Bt.mass;return 2*Math.sqrt(e*n)}const Ui=4,Ff=.002,jf=1e-4,Ca=6e4;function ws(t){const e=t.friction??Ui;return e>0?e:Ui}function xn(t){return t.from+t.velocity/ws(t)}function Bf(t,e){if(e===void 0)return t;if(typeof e=="number")return e>0?Math.round(t/e)*e:t;if(e.length===0)return t;let n=e[0];for(const s of e)Math.abs(s-t)<Math.abs(n-t)&&(n=s);return n}function Xe(t){let e=Bf(xn(t),t.end);return t.min!==void 0&&(e=Math.max(t.min,e)),t.max!==void 0&&(e=Math.min(t.max,e)),e}function Ue(t){const e=Math.abs(Xe(t)-t.from);if(e===0)return 0;const n=t.restDelta??Math.max(jf,e*Ff);if(n>=e)return 0;const s=Math.log(e/n)/ws(t);return Math.min(Ca,s*1e3)}function ks(t,e){if(e<=0)return t.from;const n=Xe(t);if(e>=Ue(t))return n;const s=ws(t);return t.from+(n-t.from)*(1-Math.exp(-s*e/1e3))}function Wf(t,e){const n=ws(t),s=Xe(t);return e>=Ue(t)?0:(s-t.from)*n*Math.exp(-n*Math.max(0,e)/1e3)}const vs=t=>t,Ha=t=>t*t,Ra=t=>1-(1-t)*(1-t),La=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,Gi=t=>t*t*t,Vi=t=>1-Math.pow(1-t,3),In=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,Na=Gi,Da=Vi,Fa=In,qf={linear:vs,"ease-in":Na,"ease-out":Da,"ease-in-out":Fa,"ease-in-quad":Ha,"ease-out-quad":Ra,"ease-in-out-quad":La,"ease-in-cubic":Gi,"ease-out-cubic":Vi,"ease-in-out-cubic":In};function ja(t){const[e,n,s,i]=t,o=3*e,r=3*(s-e)-o,a=1-o-r,l=3*n,c=3*(i-n)-l,h=1-l-c,d=p=>((a*p+r)*p+o)*p,u=p=>((h*p+c)*p+l)*p,f=p=>(3*a*p+2*r)*p+o,g=p=>{let m=p;for(let k=0;k<8;k++){const y=d(m)-p;if(Math.abs(y)<1e-7)return m;const M=f(m);if(Math.abs(M)<1e-7)break;m-=y/M}let b=0,S=1;for(m=p;b<S;){const k=d(m);if(Math.abs(k-p)<1e-7)return m;p>k?b=m:S=m,m=(b+S)/2}return m};return p=>{if(p<=0)return 0;if(p>=1)return 1;const m=g(p);return u(m)}}function Ji(t,e="out"){if(e==="out")return t;const n=s=>1-t(1-s);return e==="in"?n:s=>s<.5?n(s*2)/2:t(s*2-1)/2+.5}function Ba(t=1,e=.3){const n=Math.max(1,t),s=e/(2*Math.PI)*Math.asin(1/n);return i=>i<=0?0:i>=1?1:n*Math.pow(2,-10*i)*Math.sin((i-s)*(2*Math.PI)/e)+1}const Wa=t=>{if(t<=0)return 0;if(t>=1)return 1;if(t<1/2.75)return 7.5625*t*t;if(t<2/2.75){const i=t-.5454545454545454;return 7.5625*i*i+.75}if(t<2.5/2.75){const i=t-.8181818181818182;return 7.5625*i*i+.9375}const s=t-2.625/2.75;return 7.5625*s*s+.984375};function qa(t=1.70158){return e=>{if(e<=0)return 0;if(e>=1)return 1;const n=e-1;return n*n*((t+1)*n+t)+1}}function Ka(t,e="end"){const n=Math.max(1,Math.floor(t));return s=>{if(s>=1)return 1;if(s<=0)return e==="start"||e==="both"?e==="start"?1/n:1/(n+1):0;const i=Math.floor(s*n);switch(e){case"start":return Math.min(1,(i+1)/n);case"both":return(i+1)/(n+1);case"none":return n===1?0:Math.min(1,i/(n-1));default:return i/n}}}function Ya(t){switch(t.type){case"steps":return Ka(t.count,t.position);case"elastic":return Ji(Ba(t.amplitude,t.period),t.mode);case"bounce":return Ji(Wa,t.mode);case"back":return Ji(qa(t.overshoot),t.mode)}}function xt(t){return t===void 0?vs:Ye(t)?ja(t.points):An(t)?Ya(t):qf[t]??vs}const za=32,Kf=256,Ge=new Map,Yf=/[MmLlHhVvCcSsQqTtAaZz]/,zf=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,Xf={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function Uf(t){const e=[];let n=0,s=null;const i=()=>{for(;n<t.length&&/[\s,]/.test(t[n]);)n++};for(;n<t.length&&(i(),!(n>=t.length));){const o=t[n];if(Yf.test(o)){s={type:o,args:[]},e.push(s),n++;continue}if(!s)break;const r=s.type==="A"||s.type==="a",a=s.args.length%7;if(r&&(a===3||a===4)){if(o!=="0"&&o!=="1")break;s.args.push(o==="1"?1:0),n++;continue}const l=zf.exec(t.slice(n));if(!l)break;s.args.push(parseFloat(l[0])),n+=l[0].length}return e}function Gf(t,e,n,s,i,o,r,a,l){if(t===a&&e===l)return[];let c=Math.abs(n),h=Math.abs(s);if(c===0||h===0)return[[t,e,a,l,a,l]];const d=i*Math.PI/180,u=Math.cos(d),f=Math.sin(d),g=(t-a)/2,p=(e-l)/2,m=u*g+f*p,b=-f*g+u*p,S=m*m/(c*c)+b*b/(h*h);if(S>1){const _=Math.sqrt(S);c*=_,h*=_}const k=o===r?-1:1,y=c*c*h*h-c*c*b*b-h*h*m*m,M=c*c*b*b+h*h*m*m,$=k*Math.sqrt(Math.max(0,y/M)),E=$*c*b/h,A=-$*h*m/c,T=u*E-f*A+(t+a)/2,I=f*E+u*A+(e+l)/2,v=(_,L,N,x)=>{const R=_*N+L*x,q=Math.sqrt((_*_+L*L)*(N*N+x*x)),U=Math.acos(Math.max(-1,Math.min(1,R/q)));return _*x-L*N<0?-U:U},P=v(1,0,(m-E)/c,(b-A)/h);let H=v((m-E)/c,(b-A)/h,(-m-E)/c,(-b-A)/h);!r&&H>0&&(H-=2*Math.PI),r&&H<0&&(H+=2*Math.PI);const O=Math.max(1,Math.ceil(Math.abs(H)/(Math.PI/2))),C=H/O,j=4/3*Math.tan(C/4),D=_=>{const L=c*Math.cos(_),N=h*Math.sin(_);return[u*L-f*N+T,f*L+u*N+I]},W=_=>{const L=-c*Math.sin(_),N=h*Math.cos(_);return[u*L-f*N,f*L+u*N]},B=[];for(let _=0;_<O;_++){const L=P+_*C,N=L+C,[x,R]=D(L),[q,U]=_===O-1?[a,l]:D(N),[Y,Z]=W(L),[nt,F]=W(N);B.push([x+j*Y,R+j*Z,q-j*nt,U-j*F,q,U])}return B}function le(t,e,n,s,i){const o=1-i;return o*o*o*t+3*o*o*i*e+3*o*i*i*n+i*i*i*s}function Xa(t,e,n,s,i){const o=1-i;return 3*o*o*(e-t)+6*o*i*(n-e)+3*i*i*(s-n)}function On(t,e,n,s){return{subpath:0,type:"L",points:[n,s],startX:t,startY:e,endX:n,endY:s,length:Math.hypot(n-t,s-e)}}function Ms(t,e,n){const[s,i,o,r,a,l]=n,c=[0];let h=t,d=e,u=0;for(let f=1;f<=za;f++){const g=f/za,p=le(t,s,o,a,g),m=le(e,i,r,l,g);u+=Math.hypot(p-h,m-d),c.push(u),h=p,d=m}return{subpath:0,type:"C",points:[s,i,o,r,a,l],startX:t,startY:e,endX:a,endY:l,length:u,lengths:c}}function Ae(t){const e=Ge.get(t);if(e)return e;const n=[];let s=0,i=0,o=0,r=0,a=null,l=null,c=-1;const h=new Set,d=p=>{c<0&&(c=0),p.subpath=c,n.push(p)};for(const{type:p,args:m}of Uf(t)){const b=p.toUpperCase(),S=p!==b,k=Xf[b];if(b==="Z"){(s!==o||i!==r)&&d(On(s,i,o,r)),c>=0&&h.add(c),s=o,i=r,a=l=null;continue}for(let y=0;y+k<=m.length;y+=k){const M=m.slice(y,y+k),$=S?s:0,E=S?i:0;let A=null,T=null;switch(b){case"M":y===0?(s=M[0]+$,i=M[1]+E,o=s,r=i,(c<0||n[n.length-1]?.subpath===c)&&c++):(d(On(s,i,M[0]+$,M[1]+E)),s=M[0]+$,i=M[1]+E);break;case"L":d(On(s,i,M[0]+$,M[1]+E)),s=M[0]+$,i=M[1]+E;break;case"H":d(On(s,i,M[0]+$,i)),s=M[0]+$;break;case"V":d(On(s,i,s,M[0]+E)),i=M[0]+E;break;case"C":{const I=[M[0]+$,M[1]+E,M[2]+$,M[3]+E,M[4]+$,M[5]+E];d(Ms(s,i,I)),A=[I[2],I[3]],s=I[4],i=I[5];break}case"S":{const[I,v]=a?[2*s-a[0],2*i-a[1]]:[s,i],P=[I,v,M[0]+$,M[1]+E,M[2]+$,M[3]+E];d(Ms(s,i,P)),A=[P[2],P[3]],s=P[4],i=P[5];break}case"Q":case"T":{let I=s,v=i;b==="Q"?(I=M[0]+$,v=M[1]+E):l&&(I=2*s-l[0],v=2*i-l[1]);const P=b==="Q"?M[2]+$:M[0]+$,H=b==="Q"?M[3]+E:M[1]+E;d(Ms(s,i,[s+2/3*(I-s),i+2/3*(v-i),P+2/3*(I-P),H+2/3*(v-H),P,H])),T=[I,v],s=P,i=H;break}case"A":{const I=M[5]+$,v=M[6]+E;let P=s,H=i;for(const O of Gf(s,i,M[0],M[1],M[2],M[3],M[4],I,v))d(Ms(P,H,O)),P=O[4],H=O[5];s=I,i=v;break}}a=A,l=T}}const u=n.reduce((p,m)=>p+m.length,0),f=[];for(let p=0;p<n.length;){const m=n[p].subpath;let b=p,S=0;for(;b<n.length&&n[b].subpath===m;)S+=n[b++].length;const k=n[p],y=n[b-1],M=h.has(m)||Math.abs(y.endX-k.startX)<1e-9&&Math.abs(y.endY-k.startY)<1e-9;f.push({start:p,end:b,length:S,closed:M}),p=b}const g={segments:n,totalLength:u,subpaths:f};return Ge.size>=Kf&&Ge.delete(Ge.keys().next().value),Ge.set(t,g),g}function Vf(t,e){const n=t.lengths;if(e<=0)return 0;if(e>=t.length)return 1;let s=0,i=n.length-1;for(;s<i-1;){const a=s+i>>1;n[a]<e?s=a:i=a}const o=n[i]-n[s],r=o>0?(e-n[s])/o:0;return(s+r)/(n.length-1)}function Jf(t,e){if(t.type==="L"){const d=t.length>0?Math.max(0,Math.min(1,e/t.length)):0;return{x:t.startX+(t.endX-t.startX)*d,y:t.startY+(t.endY-t.startY)*d,angle:Math.atan2(t.endY-t.startY,t.endX-t.startX)*180/Math.PI}}const[n,s,i,o,r,a]=t.points,l=Vf(t,e);let c=Xa(t.startX,n,i,r,l),h=Xa(t.startY,s,o,a,l);if(Math.hypot(c,h)<1e-9){const d=l<.5?Math.min(1,l+.001):Math.max(0,l-.001),u=le(t.startX,n,i,r,d),f=le(t.startY,s,o,a,d),g=le(t.startX,n,i,r,l),p=le(t.startY,s,o,a,l);c=l<.5?u-g:g-u,h=l<.5?f-p:p-f}return{x:le(t.startX,n,i,r,l),y:le(t.startY,s,o,a,l),angle:Math.atan2(h,c)*180/Math.PI}}function Zi(t,e,n=0,s=t.length){if(s<=n)return{x:0,y:0,angle:0};let i=0;for(let o=n;o<s;o++){const r=t[o];if(i+r.length>=e||o===s-1)return Jf(r,e-i);i+=r.length}return{x:0,y:0,angle:0}}function Ua(t,e){const{segments:n,totalLength:s}=Ae(t);return Zi(n,Math.max(0,Math.min(1,e))*s)}function Zf(){Ge.clear()}function Qf(t){return Ae(t).totalLength}const t0=24,e0=320,n0=2.5,_n=72,s0=64,i0=.2,o0=128,Cn=new Map;let Ss=0,ce;const Ga=t=>Math.round(t*100)/100;function Va(t,e){const{segments:n,subpaths:s,totalLength:i}=Ae(t);if(n.length===0)return[];if(e){const o=s.every(r=>r.closed);return[{segments:n,start:0,end:n.length,length:i,closed:o}]}return s.filter(o=>o.length>0).map(o=>({segments:n,start:o.start,end:o.end,length:o.length,closed:o.closed}))}function Qi(t,e){const n=t.closed?(e%1+1)%1:Math.max(0,Math.min(1,e)),s=Zi(t.segments,n*t.length,t.start,t.end);return[s.x,s.y]}function Ja(t){const e=[];let n=0;for(let s=t.start;s<t.end;s++)n+=t.segments[s].length,t.length>0&&e.push(n/t.length);return e}function Za(t,e){const n=[];for(let s=0;s<e;s++)n.push(Qi(t,t.closed?s/e:s/(e-1)));return n}function Qa(t){let e=0,n=0;for(const[s,i]of t)e+=s,n+=i;return e/=t.length,n/=t.length,t.map(([s,i])=>[s-e,i-n])}function r0(t,e,n){const s=t.closed&&e.closed;if(n!==void 0)return{offset:s?Math.abs(n)%_n/_n:0,reversed:n<0};const i=Qa(Za(t,_n)),o=Qa(Za(e,_n)),r=_n;let a={offset:0,reversed:!1},l=1/0;for(const c of[!1,!0]){const h=s?r:1;for(let d=0;d<h;d++){let u=0;for(let f=0;f<r&&u<l;f++){const g=s?c?(d-f+r)%r:(f+d)%r:c?r-1-f:f,p=i[f][0]-o[g][0],m=i[f][1]-o[g][1];u+=p*p+m*m}u<l&&(l=u,a={offset:s?d/r:0,reversed:c})}}return a}function a0(t,e,n){return n?((e.reversed?e.offset-t:t+e.offset)%1+1)%1:e.reversed?1-t:t}function l0(t,e,n){return n?((e.reversed?e.offset-t:t-e.offset)%1+1)%1:e.reversed?1-t:t}function c0(t,e,n){const s=t.closed&&e.closed,i=r0(t,e,n.shapeIndex),o=Math.max(t0,Math.min(e0,Math.ceil(Math.max(t.length,e.length)/n0))),r=new Set,a=d=>r.add(Math.round(d*1e7)/1e7);for(let d=0;d<=o;d++)a(d/o);for(const d of Ja(t))a(d);for(const d of Ja(e))a(l0(d,i,s));let l=[...r].sort((d,u)=>d-u);s&&(l=l.filter(d=>d<1));const c=[],h=[];for(const d of l)c.push(...Qi(t,d)),h.push(...Qi(e,a0(d,i,s)));return h0({from:c,to:h,closed:s})}function h0(t){const e=t.from.length/2;if(e<=3)return t;const n=new Uint8Array(e);n[0]=1,n[e-1]=1;const s=[[0,e-1]];for(;s.length>0;){const[r,a]=s.pop();let l=-1,c=i0;for(let h=r+1;h<a;h++){const d=Math.max(tl(t.from,r,a,h),tl(t.to,r,a,h));d>c&&(c=d,l=h)}l!==-1&&(n[l]=1,s.push([r,l],[l,a]))}const i=[],o=[];for(let r=0;r<e;r++)n[r]&&(i.push(t.from[r*2],t.from[r*2+1]),o.push(t.to[r*2],t.to[r*2+1]));return{from:i,to:o,closed:t.closed}}function tl(t,e,n,s){const i=t[e*2],o=t[e*2+1],r=t[n*2]-i,a=t[n*2+1]-o,l=t[s*2]-i,c=t[s*2+1]-o,h=r*r+a*a,d=h===0?0:Math.max(0,Math.min(1,(l*r+c*a)/h));return Math.hypot(l-d*r,c-d*a)}function d0(t,e,n){const s=n.shapeIndex;if(ce&&ce.from===t&&ce.to===e&&ce.shapeIndex===s)return ce.plan;const o=Cn.get(String(s??"auto"))?.get(t)?.get(e);if(o)return ce={from:t,to:e,shapeIndex:s,plan:o},o;const r=Ae(t).subpaths.filter(f=>f.length>0).length===Ae(e).subpaths.filter(f=>f.length>0).length,a=Va(t,!r),l=Va(e,!r),c={pairs:a.map((f,g)=>c0(f,l[g],n))};Ss>=o0&&(Cn.clear(),Ss=0);const h=String(s??"auto"),d=Cn.get(h)??new Map;Cn.set(h,d);const u=d.get(t)??new Map;return d.set(t,u),u.set(e,c),Ss++,ce={from:t,to:e,shapeIndex:s,plan:c},c}function el(t,e,n,s={}){if(!t)return e;if(!e)return t;const i=Math.max(0,Math.min(1,n));if(i===0)return t;if(i===1)return e;const o=d0(t,e,s);if(o.pairs.length===0)return i<.5?t:e;let r="";for(const a of o.pairs){for(let l=0;l<a.from.length;l+=2){const c=Ga(a.from[l]+(a.to[l]-a.from[l])*i),h=Ga(a.from[l+1]+(a.to[l+1]-a.from[l+1])*i);r+=`${l===0?r?" M":"M":" L"}${c} ${h}`}a.closed&&(r+=" Z")}return r}function u0(){Cn.clear(),Ss=0,ce=void 0}function Ve(t){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(t)}const Je=Math.PI/180,f0=.9995;function to(){return[0,0,0,1]}function Wt(t,e){const n=Math.hypot(t[0],t[1],t[2]);if(n===0)return to();const s=e*Je/2,i=Math.sin(s)/n;return[t[0]*i,t[1]*i,t[2]*i,Math.cos(s)]}function p0(t,e,n){return eo(eo(Wt([0,1,0],e),Wt([1,0,0],t)),Wt([0,0,1],n))}function g0(t){const[e,n,s,i]=he(t),o=2*(e*s+n*i),r=2*(e*n+s*i),a=1-2*(e*e+s*s),l=2*(n*s-e*i),c=1-2*(n*n+s*s),h=2*(e*s-n*i),d=1-2*(e*e+n*n),u=Math.asin(Math.max(-1,Math.min(1,-l)));return Math.abs(l)<.9999999?[u/Je,Math.atan2(o,d)/Je,Math.atan2(r,a)/Je]:[u/Je,Math.atan2(-h,c)/Je,0]}function eo(t,e){const[n,s,i,o]=t,[r,a,l,c]=e;return[o*r+n*c+s*l-i*a,o*a-n*l+s*c+i*r,o*l+n*a-s*r+i*c,o*c-n*r-s*a-i*l]}function nl(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function sl(t){return Math.hypot(t[0],t[1],t[2],t[3])}function he(t){const e=sl(t);return e===0?to():[t[0]/e,t[1]/e,t[2]/e,t[3]/e]}function m0(t){return[-t[0],-t[1],-t[2],t[3]]}function il(t,e,n){const s=he(t);let i=he(e),o=nl(s,i);if(o<0&&(i=[-i[0],-i[1],-i[2],-i[3]],o=-o),o>f0)return he([s[0]+(i[0]-s[0])*n,s[1]+(i[1]-s[1])*n,s[2]+(i[2]-s[2])*n,s[3]+(i[3]-s[3])*n]);const r=Math.acos(o),a=Math.sin(r),l=Math.sin((1-n)*r)/a,c=Math.sin(n*r)/a;return he([s[0]*l+i[0]*c,s[1]*l+i[1]*c,s[2]*l+i[2]*c,s[3]*l+i[3]*c])}function y0(t,e){const[n,s,i,o]=he(t),r=2*(s*e[2]-i*e[1]),a=2*(i*e[0]-n*e[2]),l=2*(n*e[1]-s*e[0]);return[e[0]+o*r+(s*l-i*a),e[1]+o*a+(i*r-n*l),e[2]+o*l+(n*a-s*r)]}const b0=Object.freeze(Object.defineProperty({__proto__:null,conjugate:m0,dot:nl,fromAxisAngle:Wt,fromEuler:p0,identity:to,length:sl,multiply:eo,normalize:he,rotateVec3:y0,slerp:il,toEuler:g0},Symbol.toStringTag,{value:"Module"})),Gt=(t,e,n)=>t+(e-t)*n,ol=512,no=new Map,so=new Map;function rl(t){const e=no.get(t);if(e)return e;const n=t.replace("#",""),s=[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)];return no.size<ol&&no.set(t,s),s}const al=t=>t.charCodeAt(0)===35,ll=t=>t.startsWith("rgb"),cl=t=>t.startsWith("rgba"),w0=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,io=t=>Math.round(t).toString(16).padStart(2,"0");function k0(t,e,n){return`#${io(t)}${io(e)}${io(n)}`}function hl(t){const e=so.get(t);if(e)return e;const n=t.match(w0);if(!n)throw new Error(`Invalid rgb color: ${t}`);const s=parseInt(n[1],10),i=parseInt(n[2],10),o=parseInt(n[3],10),r=n[4]!==void 0?[s,i,o,parseFloat(n[4])]:[s,i,o];return so.size<ol&&so.set(t,r),r}const dl=(t,e,n)=>{if(al(t)&&al(e)){const[s,i,o]=rl(t),[r,a,l]=rl(e),c=Gt(s,r,n),h=Gt(i,a,n),d=Gt(o,l,n);return k0(c,h,d)}if((ll(t)||cl(t))&&(ll(e)||cl(e))){const s=hl(t),i=hl(e),o=Math.round(Gt(s[0],i[0],n)),r=Math.round(Gt(s[1],i[1],n)),a=Math.round(Gt(s[2],i[2],n));if(s.length===4||i.length===4){const l=s[3]??1,c=i[3]??1,h=Gt(l,c,n);return`rgba(${o}, ${r}, ${a}, ${h})`}return`rgb(${o}, ${r}, ${a})`}return n<1?t:e},ul=(t,e,n)=>{const s=Math.min(t.length,e.length),i=[];for(let o=0;o<s;o++)i.push(Gt(t[o],e[o],n));return i},fl=(t,e,n)=>il(t,e,n),oo=(t,e,n)=>n<1?t:e,pl=(t,e,n)=>el(t,e,n);function Hn(t,e){return e==="slerp"?fl:typeof t=="number"?Gt:Array.isArray(t)?ul:typeof t=="string"?t.startsWith("#")||t.startsWith("rgb")?dl:Ve(t)?pl:oo:oo}const ro=1e3/60;function ao(t,e={}){if(!ae(t))throw new Error(`bakeSpringTrack: track "${t.id}" is not a spring track`);const n=new Pn(t.spring);return gl(t,s=>n.valueAt(s),n.settleTime(),t.spring.from,t.spring.to,e)}function lo(t,e={}){if(!re(t))throw new Error(`bakeInertiaTrack: track "${t.id}" is not an inertia track`);const n=t.inertia;return gl(t,s=>ks(n,s),Ue(n),n.from,Xe(n),e)}function gl(t,e,n,s,i,o){const r=o.intervalMs??ro,a=o.tolerance??.01,l=t.delay??0,c=[];for(let d=0;d<=n;d+=r)c.push({time:d+l,value:e(d),easing:"linear"});const h=c[c.length-1];return!h||h.time<n+l?c.push({time:n+l,value:i,easing:"linear"}):h.value=i,l>0&&c.unshift({time:0,value:s,easing:"linear"}),{id:t.id,target:t.target,property:t.property,keyframes:a>0?yl(c,a):c,...t.targets&&{targets:[...t.targets]},...t.stagger&&{stagger:{...t.stagger}}}}function co(t,e,n,s={}){const i=s.intervalMs??ro,o=typeof n=="function"?n:xt(n),r=Hn(t.value,s.interpolation),a=e.time-t.time;if(a<=0)return[e];const l=[];for(let h=i;h<a;h+=i){const d=h/a;l.push({time:t.time+h,value:r(t.value,e.value,o(d)),easing:"linear"})}const c=o(1);return l.push({...e,...c!==1&&{value:r(t.value,e.value,c)},easing:"linear"}),l}function v0(t,e){return ae(t)?ao(t,e):re(t)?lo(t,e):t}function ml(t,e={}){const n=t.keyframes;if(!n.some(o=>An(o.easing)))return t;const s=n.length>0?[n[0]]:[],i={...e,interpolation:t.interpolation??e.interpolation};for(let o=1;o<n.length;o++){const r=n[o];An(r.easing)?s.push(...co(n[o-1],r,r.easing,i)):s.push(r)}return{...t,keyframes:s}}function M0(t,e){return t.filter(Ia).map(n=>ml(n,e)).concat(t.filter(ae).map(n=>ao(n,e)),t.filter(re).map(n=>lo(n,e)))}function yl(t,e){if(t.length<=2)return t;const n=[t[0]];for(let s=1;s<t.length-1;s++){const i=n[n.length-1],o=t[s],r=t[s+1],a=r.time-i.time;if(a<=0)continue;const l=(o.time-i.time)/a,c=i.value+(r.value-i.value)*l;Math.abs(o.value-c)>e&&n.push(o)}return n.push(t[t.length-1]),n}function Ts(t){const e=[...t.keyframes].sort((n,s)=>n.time-s.time);return{...t,keyframes:e}}function de(t){return t.targets&&t.targets.length>0?t.targets:[t.target]}function Ze(t,e,n,s){const i=n??0;return!s||e<=1?i:i+gs(t,e,s)}class Es{track;targets;constructor(e){this.track=e,this.targets=de(e)}getValueAtTime(e){return this.valueForOffset(e-Ze(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const o=Ze(i,n,this.track.delay,this.track.stagger),r=this.valueForOffset(e-o);r!==void 0&&s.push({target:this.targets[i],value:r,start:o+this.track.keyframes[0].time})}return s}getDuration(){const{keyframes:e}=this.track;if(e.length===0)return 0;const n=e[e.length-1].time,s=this.track.stagger?$n(this.targets.length,this.track.stagger):0;return n+(this.track.delay??0)+s+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(e){const{keyframes:n}=this.track;if(n.length===0)return;if(n.length===1||e<=n[0].time)return n[0].value;if(e>=n[n.length-1].time)return n[n.length-1].value;const{from:s,to:i}=this.findSurroundingKeyframes(e);if(!s||!i)return;if(s.time===e)return s.value;const o=i.time-s.time,r=(e-s.time)/o,l=xt(i.easing)(r);return Hn(s.value,this.track.interpolation)(s.value,i.value,l)}findSurroundingKeyframes(e){const{keyframes:n}=this.track;for(let s=0;s<n.length-1;s++)if(e>=n[s].time&&e<=n[s+1].time)return{from:n[s],to:n[s+1]};return{from:null,to:null}}}class bl{track;targets;sampler;constructor(e){this.track=e,this.targets=de(e),this.sampler=new Pn(e.spring)}getValueAtTime(e){return this.sampler.valueAt(e-Ze(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const o=Ze(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:this.sampler.valueAt(e-o),start:o})}return s}getDuration(){const e=this.track.stagger?$n(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+e}getTrack(){return this.track}}class wl{track;targets;duration;constructor(e){this.track=e,this.targets=de(e),this.duration=Ue(e.inertia)}getValueAtTime(e){return ks(this.track.inertia,e-Ze(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const o=Ze(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:ks(this.track.inertia,e-o),start:o})}return s}getDuration(){const e=this.track.stagger?$n(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+e}getTrack(){return this.track}}function ho(t,e){const n={...Ua(t.pathData,e)};if(t.matrix){const[s,i,o,r,a,l]=t.matrix,{x:c,y:h}=n;n.x=s*c+o*h+a,n.y=i*c+r*h+l;const d=n.angle*Math.PI/180,u=Math.cos(d),f=Math.sin(d);n.angle=Math.atan2(i*u+r*f,s*u+o*f)*180/Math.PI}return t.autoRotate&&t.rotateOffset&&(n.angle+=t.rotateOffset),n}function S0(t,e,n,s){const i=e+(n-e)*s;return ho(t,i)}const uo={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},T0=20;function kl(t){const e=uo[t??"upperCase"]??t??uo.upperCase,n=Array.from(e);return n.length>0?n:Array.from(uo.upperCase)}function E0(t,e,n){let s=(t|0)^Math.imul(e+1,2654435761)^Math.imul(n+1,2246822507);return s=Math.imul(s^s>>>16,2146121005),s=Math.imul(s^s>>>15,2221713035),(s^s>>>16)>>>0}function vl(t,e,n=0){const s=t.from??"",i=t.to,o=Math.max(0,Math.min(1,e));if(o<=0)return s;if(o>=1)return i;const r=Array.from(s),a=Array.from(i),l=t.rightToLeft??!1;if(t.mode==="type"){const S=Math.round(o*Math.max(r.length,a.length));return l?r.slice(0,Math.max(0,r.length-S)).join("")+a.slice(Math.max(0,a.length-S)).join(""):a.slice(0,S).join("")+r.slice(S).join("")}const c=Math.max(0,Math.min(.999,t.revealDelay??0)),h=Math.max(0,(o-c)/(1-c)),d=Math.floor(h*a.length),u=t.tweenLength===!1?a.length:Math.round(r.length+(a.length-r.length)*o),f=kl(t.chars),g=t.refreshRate??T0,p=g>0?Math.floor(n*g/1e3):0,m=t.seed??1;let b="";for(let S=0;S<u;S++){const k=l?S>=u-d:S<d,y=l?a[a.length-(u-S)]:a[S];k&&y!==void 0||y===" "||y===`
2
+ `?b+=y:b+=f[E0(m,S,p)%f.length]}return b}class Ht{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(e){if(this.id=e.id,this.name=e.name,this._captions=e.captions,this._config=e.config??{},this._explicitDuration=e.config?.duration,e.tracks)for(const n of e.tracks)this.addTrack(n)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(e){if(this._explicitDuration=e,e!==void 0)this._config={...this._config,duration:e};else if(this._config.duration!==void 0){const n={...this._config};delete n.duration,this._config=n}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(e){this._config.speed=e}get drawingRate(){return this._config.drawingRate??0}set drawingRate(e){const n={...this._config};e>0?n.drawingRate=e:delete n.drawingRate,this._config=n}play(){const e=this.duration;this._direction==="forward"&&this._currentTime>=e&&e>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&e>0&&(this._currentTime=e,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(e){const n=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(e,n)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(e){if(this._playbackState!=="playing")return;const n=this.duration;if(n<=0)return;let i=e*this.speed;if(this._repeatDelayRemaining>0){const a=Math.min(this._repeatDelayRemaining,i);if(this._repeatDelayRemaining-=a,i-=a,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const o=1e3;for(let a=0;a<o&&i>0&&this._playbackState==="playing";a++)if(this._direction==="forward"){const l=n-this._currentTime;if(i>=l){if(i-=l,this._currentTime=n,!this._handleEndReached())break}else this._currentTime+=i,i=0}else{const l=this._currentTime;if(i>=l){if(i-=l,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=i,i=0}const r=this.getStateAtTime(this._currentTime);this.onUpdate?.(r)}getStateAtTime(e){const n=new Map;if(e=Oa(e,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(e,n);else for(const[s,i]of this._trackPlayers){const o=i.getTrack().property;for(const{target:r,value:a,start:l}of i.getTargetValues(e))this._write(n,s,r,o,a,e-l)}return{values:n,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(e,n){const s=new Map;for(const[i,o]of this._trackPlayers){const r=o.getTrack().property;for(const{target:a,value:l,start:c}of o.getTargetValues(e)){const h=`${a}\0${r}`,d=c<=e,u=s.get(h);(!u||(d!==u.started?d:d?c>=u.start:c<=u.start))&&s.set(h,{trackId:i,target:a,property:r,value:l,start:c,started:d})}}for(const{trackId:i,target:o,property:r,value:a,start:l}of s.values())this._write(n,i,o,r,a,e-l)}_write(e,n,s,i,o,r){if(o===void 0)return;let a=e.get(s);a||(a=new Map,e.set(s,a));const l=this._textTracks.get(n);if(l&&typeof o=="number"){a.set("text",vl(l.textConfig,o,Math.max(0,r)));return}const c=this._motionPathTracks.get(n);if(c&&typeof o=="number"){const h=ho(c.motionPathConfig,o);a.set("motionPathX",h.x),a.set("motionPathY",h.y),c.motionPathConfig.autoRotate&&a.set("motionPathRotate",h.angle)}else a.set(i,o)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const e=new Set;this._sharedWrites=!1;t:for(const n of this._tracks)for(const s of de(n)){const i=`${s}\0${n.property}`;if(e.has(i)){this._sharedWrites=!0;break t}e.add(i)}}return this._sharedWrites}addTrack(e){if(this._tracks.push(e),this._sharedWrites=null,re(e)){this._trackPlayers.set(e.id,new wl(e));return}if(ae(e)){this._trackPlayers.set(e.id,new bl(e)),this._springTracks.set(e.id,e);return}if(ps(e))this._trackPlayers.set(e.id,new Es(e)),this._textTracks.set(e.id,e);else if(Ki(e)){const n={id:e.id,target:e.target,property:e.property,keyframes:e.keyframes,delay:e.delay,endDelay:e.endDelay,targets:e.targets,stagger:e.stagger};this._trackPlayers.set(e.id,new Es(n)),this._motionPathTracks.set(e.id,e)}else this._trackPlayers.set(e.id,new Es(e))}replaceTrack(e,n){const s=this._tracks.findIndex(o=>o.id===e);if(s<0)return;const i=this._tracks.slice(s+1);this.removeTrack(e);for(const o of i)this.removeTrack(o.id);this.addTrack(n);for(const o of i)this.addTrack(o)}removeTrack(e){this._tracks=this._tracks.filter(n=>n.id!==e),this._sharedWrites=null,this._trackPlayers.delete(e),this._motionPathTracks.delete(e),this._springTracks.delete(e),this._textTracks.delete(e)}getTracks(e={}){return this._tracks.filter(n=>this._matches(n,e))}removeTracks(e={}){const n=this.getTracks(e).map(s=>s.id);for(const s of n)this.removeTrack(s);return n}getTrackSpan(e){const n=this._trackPlayers.get(e);if(!n)return;const s=n.getTrack(),i=s.delay??0;if(ae(s)||re(s))return{from:i,to:n.getDuration()};const o=s.keyframes;if(!(!o||o.length===0))return{from:o[0].time+i,to:n.getDuration()}}findConflicts(){const e=[];for(let n=0;n<this._tracks.length;n++){const s=this._tracks[n],i=this.getTrackSpan(s.id);if(i)for(let o=0;o<n;o++){const r=this._tracks[o];if(r.property!==s.property)continue;const a=de(r).filter(d=>de(s).includes(d));if(a.length===0)continue;const l=this.getTrackSpan(r.id);if(!l||!(l.from<=i.to&&i.from<=l.to))continue;const h=i.from>=l.from;for(const d of a)e.push({target:d,property:s.property,losingTrackId:h?r.id:s.id,winningTrackId:h?s.id:r.id})}}return e}_matches(e,n){if(n.id!==void 0&&e.id!==n.id||n.property!==void 0&&e.property!==n.property||n.target!==void 0&&!de(e).includes(n.target))return!1;if(n.timeRange){const s=this.getTrackSpan(e.id);if(!s||s.to<n.timeRange.from||s.from>n.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:qi(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((e,n)=>e.time-n.time)}setMarkers(e){const n=e&&e.length>0?[...e].sort((i,o)=>i.time-o.time).map(i=>({...i})):void 0,s={...this._config};n?s.markers=n:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(e){const n={};for(const[s,i]of Object.entries(e??{}))n[s]={...i};this._captions=Object.keys(n).length>0?n:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let e=0;for(const[,n]of this._trackPlayers)e=Math.max(e,n.getDuration());return e}_handleEndReached(){const e=this._config.loop??0;return e===-1||this._loopIteration<e?(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 e=this._config.loop??0;return this._config.alternate&&(e===-1||this._loopIteration<e)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const A0=100;function fo(t,e,n,s){const i=[],o=[],{duration:r,alternate:a}=s,l=(f,g,p,m)=>{o.push([f,g]);const b=[];t.forEach((S,k)=>{(p==="forward"?(m?S>=f:S>f)&&S<=g:(m?S<=f:S<f)&&S>=g)&&b.push(k)}),b.sort((S,k)=>(p==="forward"?t[S]-t[k]:t[k]-t[S])||S-k);for(const S of b)i.push({kind:"event",index:S,direction:p})};let c=e.time,h=e.direction,d=e.fresh===!0;const u=Math.min(A0,Math.max(0,n.iteration-e.iteration));for(let f=0;f<u;f++){const g=h==="forward"?r:0;l(c,g,h,d),i.push({kind:"repeat"}),a?(h=h==="forward"?"reverse":"forward",c=g,d=!1):(c=h==="forward"?0:r,d=!0)}return u>0&&s.holding&&!a?{crossings:i,passes:o}:(l(c,n.time,h,d),{crossings:i,passes:o})}function Ml(t){return re(t)?{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:Sl(t.inertia),...Vt(t)}:ae(t)?{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...Vt(t)}:ps(t)?{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:t.keyframes.map(po),...Vt(t)}:Ki(t)?{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:t.keyframes.map(po),...Vt(t)}:{id:t.id,target:t.target,property:t.property,keyframes:t.keyframes.map(po),...t.interpolation!==void 0&&{interpolation:t.interpolation},...Vt(t)}}function Sl(t){return{...t,...Array.isArray(t.end)&&{end:[...t.end]}}}function po(t){return{time:t.time,value:t.value,...t.easing&&{easing:t.easing}}}function Vt(t){const e=t.endDelay;return{...t.delay!==void 0&&{delay:t.delay},...e!==void 0&&{endDelay:e},...t.targets!==void 0&&{targets:[...t.targets]},...t.stagger!==void 0&&{stagger:{...t.stagger}}}}function Tl(t){if(re(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"inertia",inertia:Sl(e.inertia),...Vt(e)}}if(ae(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"spring",spring:{...e.spring},...Vt(e)}}if(ps(t)){const e=t;return{id:e.id,target:e.target,property:"text",textConfig:{...e.textConfig},keyframes:[...e.keyframes].sort((n,s)=>n.time-s.time),...Vt(e)}}if(t.property==="motionPath"&&"motionPathConfig"in t){const e=t,n=[...e.keyframes].sort((s,i)=>s.time-i.time);return{id:e.id,target:e.target,property:"motionPath",motionPathConfig:{...e.motionPathConfig},keyframes:n,...Vt(e)}}return Ts({id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,...t.interpolation!==void 0&&{interpolation:t.interpolation},...Vt(t)})}function El(t){const e=t._config.markers;return{formatVersion:qi(t.tracks),id:t.id,name:t.name,config:{duration:t.duration>0?t.duration:void 0,loop:t._config.loop,speed:t._config.speed,alternate:t._config.alternate,repeatDelay:t._config.repeatDelay,...t._config.drawingRate?{drawingRate:t._config.drawingRate}:{},...e&&{markers:e.map(n=>({...n}))}},tracks:t.tracks.map(Ml),...t.captions&&{captions:JSON.parse(JSON.stringify(t.captions))}}}function Qe(t){const e=t.formatVersion??1;if(e>Wi)throw new Error(`tinyfly: this animation uses format version ${e}, but this tinyfly reads up to version ${Wi}. Update tinyfly to play it.`);return new Ht({id:t.id,name:t.name,config:t.config,tracks:t.tracks.map(Tl),captions:t.captions})}function $0(t){return JSON.stringify(El(t))}function P0(t){const e=JSON.parse(t);return Qe(e)}function qt(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e>>>0}function $e(t){let e=t>>>0||2654435769;return{seed:t>>>0,next(){return e^=e<<13,e>>>=0,e^=e>>17,e^=e<<5,e>>>=0,e/4294967296}}}function go(t,e,n){return e+t.next()*(n-e)}function Al(t,e,n,s){if(s<=0)return go(t,e,n);const i=Math.floor((n-e)/s),o=Math.round(t.next()*i);return e+o*s}function x0(t,e){if(e.length!==0)return e[Math.floor(t.next()*e.length)]}const $l=/^([+\-*/])=\s*(-?[\d.]+)$/,Pl=/^random\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*(?:,\s*(-?[\d.]+)\s*)?\)$/i;function I0(t){return typeof t!="string"?!1:$l.test(t.trim())||Pl.test(t.trim())}function mo(t,e={}){if(typeof t!="string")return t;const n=t.trim(),s=$l.exec(n);if(s){const[,o,r]=s,a=e.base??0,l=Number.parseFloat(r);switch(o){case"+":return a+l;case"-":return a-l;case"*":return a*l;case"/":return l===0?a:a/l}}const i=Pl.exec(n);if(i){if(!e.random)throw new Error(`resolveValue: "${n}" needs a random source — pass one via context.random`);const o=Number.parseFloat(i[1]),r=Number.parseFloat(i[2]),a=i[3]!==void 0?Number.parseFloat(i[3]):void 0;return a!==void 0?Al(e.random,o,r,a):go(e.random,o,r)}return t}function xl(t,e=0,n){const s=[];let i=e;for(const o of t){const r=mo(o,{base:i,random:n});s.push(r),typeof r=="number"&&(i=r)}return s}class O0{random;constructor(e){this.random=$e(e)}get seed(){return this.random.seed}resolve(e,n=0){return mo(e,{base:n,random:this.random})}resolveSequence(e,n=0){return xl(e,n,this.random)}}const _0=600;function Il(t){if(Array.isArray(t)){const[u,f,g,p]=t;return{fn:Cl(u,f,g,p),bezier:[u,f,g,p]}}const{segments:e}=Ae(t);if(e.length===0)throw new Error(`customEase: no curve in "${t}"`);const n=e[0].startX,s=e[0].startY,i=e[e.length-1],o=i.endX-n,r=i.endY-s;if(o===0||r===0)throw new Error(`customEase: "${t}" must move along both axes`);const a=u=>(u-n)/o,l=u=>(u-s)/r;if(e.length===1&&i.type==="C"){const[u,f,g,p]=i.points,m=[a(u),l(f),a(g),l(p)];return{fn:Cl(...m),bezier:m}}const c=[],h=[],d=Math.max(8,Math.ceil(_0/e.length));for(const u of e)for(let f=c.length===0?0:1;f<=d;f++){const[g,p]=C0(u,f/d);c.push(a(g)),h.push(l(p))}return{fn:H0(c,h)}}function Ol(t={}){const n=.1+Math.max(0,Math.min(1,t.strength??.7))*.7,s=[1];for(let o=n;o>.002;o*=n)s.push(2*Math.sqrt(o));const i=s.reduce((o,r)=>o+r,0);return o=>{if(o<=0)return 0;if(o>=1)return 1;let r=o*i;for(let a=0;a<s.length;a++){if(r<=s[a]){if(a===0)return(r/s[0])**2;const l=s[a]/2,c=l*l,h=r-l;return 1-(c-h*h)}r-=s[a]}return 1}}function _l(t={}){const e=Math.max(1,t.wiggles??10),n=t.type??"easeOut",s=i=>n==="uniform"?1:n==="easeInOut"?Math.sin(Math.PI*i):(1-i)**2;return i=>i<=0||i>=1?0:Math.sin(i*e*Math.PI*2)*s(i)}function C0(t,e){if(t.type==="L"){const[c,h]=t.points;return[t.startX+(c-t.startX)*e,t.startY+(h-t.startY)*e]}const[n,s,i,o,r,a]=t.points,l=1-e;return[l*l*l*t.startX+3*l*l*e*n+3*l*e*e*i+e*e*e*r,l*l*l*t.startY+3*l*l*e*s+3*l*e*e*o+e*e*e*a]}function H0(t,e){return n=>{if(n<=t[0])return e[0];if(n>=t[t.length-1])return e[e.length-1];let s=0,i=t.length-1;for(;i-s>1;){const r=s+i>>1;t[r]<=n?s=r:i=r}const o=t[i]-t[s];return o===0?e[i]:e[s]+(n-t[s])/o*(e[i]-e[s])}}function Cl(t,e,n,s){const i=(r,a,l)=>3*(1-r)*(1-r)*r*a+3*(1-r)*r*r*l+r*r*r,o=(r,a,l)=>3*(1-r)*(1-r)*a+6*(1-r)*r*(l-a)+3*r*r*(1-l);return r=>{if(r<=0)return 0;if(r>=1)return 1;let a=r;for(let h=0;h<8;h++){const d=i(a,t,n)-r,u=o(a,t,n);if(Math.abs(d)<1e-6)return i(a,e,s);if(Math.abs(u)<1e-6)break;a-=d/u}let l=0,c=1;a=r;for(let h=0;h<40;h++)i(a,t,n)<r?l=a:c=a,a=(l+c)/2;return i(a,e,s)}}const R0=350,L0=300,N0=550;function D0(t,e={}){const n=e.lead??R0,s=e.gap??L0,i=e.tail??N0,o=[];let r=0;return t.forEach((a,l)=>{const c=[];let h=r+n;a.lines.forEach((u,f)=>{if(!(u.duration>=0))throw new Error(`narration: scene ${l} line ${f} has an invalid duration (${u.duration})`);f>0&&(h+=s),c.push({id:u.id??`s${l}-l${f}`,scene:l,line:f,start:h,end:h+u.duration,text:u.text}),h+=u.duration});const d=h+i+(a.tail??0);o.push({id:a.id??`s${l}`,start:r,duration:d-r,cues:c}),r=d}),{duration:r,scenes:o,cues:o.flatMap(a=>a.cues)}}function F0(t){return t.cues.map(e=>({id:e.id,time:e.start,label:e.text}))}function j0(t,e){let n=t.scenes[0];for(const s of t.scenes)if(e>=s.start)n=s;else break;return n}const yo=t=>6e4/t.bpm;function As(t,e){return t.offset+e*yo(t)}function $s(t,e){return(e-t.offset)/yo(t)}function B0(t,e){return As(t,Math.round($s(t,e)))}function W0(t,e){return As(t,Math.ceil($s(t,e)-1e-9))}function q0(t,e,n){const s=Math.max(1,Math.round(t.beatsPerBar??4)),i=[];if(!(t.bpm>0)||n<e)return i;for(let o=Math.ceil($s(t,e)-1e-9);;o++){const r=As(t,o);if(r>n+1e-9)break;i.push({time:r,bar:(o%s+s)%s===0,n:o})}return i}const tn=100;function K0(t,e,n={}){const s=n.minBpm??70,i=n.maxBpm??180,o=Math.max(1,Math.round(e/tn)),r=Math.min(t.length,Math.round((n.maxSeconds??60)*e)),a=Math.floor(r/o);if(a<4)return{bpm:120,offset:0,confidence:0};const l=new Float64Array(a);for(let T=0;T<a;T++){let I=0;for(let v=T*o;v<(T+1)*o;v++)I+=t[v]*t[v];l[T]=Math.log(1e-6+I/o)}const c=new Float64Array(a);for(let T=1;T<a;T++)c[T]=Math.max(0,l[T]-l[T-1]);const h=c.reduce((T,I)=>T+I,0)/a;for(let T=0;T<a;T++)c[T]=Math.max(0,c[T]-h);const d=Math.max(1,Math.floor(60*tn/i)),u=Math.min(a-1,Math.ceil(60*tn/s)),f=T=>{let I=0;for(let v=T;v<a;v++)I+=c[v]*c[v-T];return I/(a-T)};let g=0;for(let T=0;T<a;T++)g+=c[T]*c[T];g/=a;let p=d,m=-1/0;for(let T=d;T<=u;T++){const I=60*tn/T,v=Math.exp(-.5*(Math.log2(I/120)/.9)**2),P=f(T)*v;P>m&&(m=P,p=T)}const b=T=>{const I=Math.floor(T);return I<0||I+1>=a?0:c[I]+(c[I+1]-c[I])*(T-I)},S=(T,I)=>{let v=0;for(let P=I;P<a;P+=T)v+=b(P);return v};let k=p,y=0,M=-1/0;for(let T=p-.6;T<=p+.6+1e-9;T+=.02){if(T<1)continue;const I=Math.max(1,Math.round(T*4));for(let v=0;v<I;v++){const P=v/I*T,H=S(T,P);H>M&&(M=H,y=P,k=T)}}const $=60*tn/k,E=g>0?Math.max(0,Math.min(1,f(p)/g)):0,A=(y+.5)*1e3/tn;return{bpm:Math.round($*100)/100,offset:Math.round(A%(6e4/$)),confidence:E}}const Y0=600,z0=250,Hl=1;function X0(t,e){const n=e.target??"Camera",s={x:e.stage.width/2,y:e.stage.height/2},i={},o=(d,u,f,g)=>{const p=i[d]??=[];for(;p.length>0&&p[p.length-1].time>=u;)p.pop();p.push({time:u,value:f,...g?{easing:g}:{}})},r=d=>{const u=d.rotate*Math.PI/180,f=(d.focusX-s.x)*d.scale,g=(d.focusY-s.y)*d.scale;return{x:-(f*Math.cos(u)-g*Math.sin(u)),y:-(f*Math.sin(u)+g*Math.cos(u)),scale:d.scale,rotate:d.rotate}},a=(d,u,f)=>{const g=r(u);for(const p of["x","y","scale","rotate"])o(p,d,g[p],f)};let l={focusX:s.x,focusY:s.y,scale:1,rotate:0};const c=[...t].sort((d,u)=>d.at-u.at),h=c.filter(d=>!("shake"in d));h.length>0&&a(0,l);for(const d of h)if("frame"in d){const u=Math.max(Hl,d.duration??Y0);a(d.at,l),l={focusX:d.frame.focus?.x??s.x,focusY:d.frame.focus?.y??s.y,scale:d.frame.scale??1,rotate:d.frame.rotate??0},a(d.at+u,l,d.easing??(u>Hl?"ease-in-out":void 0))}else{const{follow:u}=d,f=u.lag??z0,g=new Ht({id:"follow",tracks:[{id:"x",target:"s",property:"x",keyframes:u.x}]}),p=S=>g.getStateAtTime(S).values.get("s")?.get("x")??l.focusX,m=[d.at,...u.x.map(S=>S.time).filter(S=>S>d.at&&S<d.until),d.until];a(d.at,l);const b=S=>({focusX:p(S)+(u.lead??0),focusY:u.y??l.focusY,scale:u.scale??l.scale,rotate:l.rotate});for(const S of m){const k=u.x.find(y=>y.time===S)?.easing;a(S+f,b(S),S===d.at?"ease-in-out":k)}l=b(d.until)}for(const d of c.filter(u=>"shake"in u)){const u=d.shake.strength??12,f=d.shake.roll??1.5,g=1e3/(d.shake.frequency??24),p=$e(d.shake.seed??Math.round(d.at)+1),m=()=>p.next()*2-1;for(const b of["shakeX","shakeY","shakeRotate"])o(b,d.at,0);for(let b=d.at+g;b<d.at+d.duration;b+=g){const S=1-(b-d.at)/d.duration;o("shakeX",b,m()*u*S),o("shakeY",b,m()*u*S),o("shakeRotate",b,m()*f*S)}for(const b of["shakeX","shakeY","shakeRotate"])o(b,d.at+d.duration,0,"ease-out")}return Object.entries(i).map(([d,u])=>({id:`${n}-${d}`,target:n,property:d,keyframes:u}))}function Rl(t,e){const n=t.toLowerCase(),s=e.toLowerCase();let i=Array.from({length:s.length+1},(o,r)=>r);for(let o=1;o<=n.length;o++){const r=[o];for(let a=1;a<=s.length;a++)r[a]=Math.min(i[a]+1,r[a-1]+1,i[a-1]+(n[o-1]===s[a-1]?0:1));i=r}return i[s.length]}function Rn(t,e){const n=t.toLowerCase(),s=e.find(r=>r.toLowerCase().includes(n)||n.includes(r.toLowerCase()));if(s&&Math.min(t.length,s.length)>=3)return s;let i,o=1/0;for(const r of e){const a=Rl(t,r);a<o&&(o=a,i=r)}return i!==void 0&&o<=Math.max(2,Math.floor(t.length/3))?i:void 0}function ot(t,e,n,s){const i=typeof e=="string"?s??Rn(e,n):void 0;return`Unknown ${t} ${JSON.stringify(e)}${i?`: did you mean "${i}"?`:"."} Known: ${n.join(", ")}`}function Ll(t,e){const n=e.step??33,s=e.stiffness??120,i=e.damping??9,o=e.mass??1;let r=t(e.start),a=0;const l=[{time:e.start,value:r}];let c=e.start+n;for(let h=e.start+1;h<=e.end;h++){const u=s*(t(h)-r)-i*a;a+=u/o*.001,r+=a*.001,(h>=c||h===e.end)&&(l.push({time:h,value:r}),c+=n)}return l}const Jt=t=>Math.round(t*1e3)/1e3;function Nl(t,e={}){if(t.length===0)return"";const n=e.curviness??1,s=e.closed??!1,i=t.length;let o=`M${Jt(t[0].x)} ${Jt(t[0].y)}`;if(i===1)return o;const r=l=>s?t[(l%i+i)%i]:t[Math.max(0,Math.min(i-1,l))],a=s?i:i-1;for(let l=0;l<a;l++){const c=r(l-1),h=r(l),d=r(l+1),u=r(l+2);if(n===0){o+=` L${Jt(d.x)} ${Jt(d.y)}`;continue}const f=n/6,g=h.x+(d.x-c.x)*f,p=h.y+(d.y-c.y)*f,m=d.x-(u.x-h.x)*f,b=d.y-(u.y-h.y)*f;o+=` C${Jt(g)} ${Jt(p)} ${Jt(m)} ${Jt(b)} ${Jt(d.x)} ${Jt(d.y)}`}return s?`${o} Z`:o}const $t=(t,e=0)=>{const n=parseFloat(t??"");return Number.isFinite(n)?n:e};function U0(t){const e=(t??"").trim().split(/[\s,]+/).filter(Boolean).map(Number),n=[];for(let s=0;s+1<e.length;s+=2)n.push({x:e[s],y:e[s+1]});return n}function Ps(t){const e=t.attributes;switch(t.tag.toLowerCase()){case"path":return e.d??null;case"circle":case"ellipse":{const n=$t(e.cx),s=$t(e.cy),i=t.tag.toLowerCase()==="circle"?$t(e.r):$t(e.rx),o=t.tag.toLowerCase()==="circle"?$t(e.r):$t(e.ry);return`M${n+i} ${s} A${i} ${o} 0 1 1 ${n-i} ${s} A${i} ${o} 0 1 1 ${n+i} ${s} Z`}case"rect":{const n=$t(e.x),s=$t(e.y),i=$t(e.width),o=$t(e.height);let r=e.rx!=null?$t(e.rx):e.ry!=null?$t(e.ry):0,a=e.ry!=null?$t(e.ry):r;return r=Math.min(r,i/2),a=Math.min(a,o/2),r===0||a===0?`M${n} ${s} H${n+i} V${s+o} H${n} Z`:`M${n+r} ${s} H${n+i-r} A${r} ${a} 0 0 1 ${n+i} ${s+a} V${s+o-a} A${r} ${a} 0 0 1 ${n+i-r} ${s+o} H${n+r} A${r} ${a} 0 0 1 ${n} ${s+o-a} V${s+a} A${r} ${a} 0 0 1 ${n+r} ${s} Z`}case"line":return`M${$t(e.x1)} ${$t(e.y1)} L${$t(e.x2)} ${$t(e.y2)}`;case"polyline":case"polygon":{const n=U0(e.points);if(n.length===0)return null;const s=n.map((i,o)=>`${o===0?"M":"L"}${i.x} ${i.y}`).join(" ");return t.tag.toLowerCase()==="polygon"?`${s} Z`:s}default:return null}}function G0(t,e,n){const s=Math.max(2,Math.round(n.samples??32)),i=Math.max(0,n.length),o=n.since!==void 0?Math.max(e-i,n.since):e-i;if(o>=e)return[];const r=n.period,a=[];for(let l=0;l<s;l++){const c=o+(e-o)*l/(s-1),h=r&&r>0&&l<s-1?(c%r+r)%r:c;a.push({at:t(h),time:c,age:i>0?(e-c)/i:0})}return a}const V0=2.5;function Dl(t){const e=[],n=[],s=t.length,i=(o,r)=>{for(let a=o+r;a>=0&&a<s;a+=r){const l=(t[a].x-t[o].x)*r,c=(t[a].y-t[o].y)*r,h=Math.hypot(l,c);if(h>1e-9)return[l/h,c/h]}return null};for(let o=0;o<s;o++){const r=t[o],a=i(o,-1),l=i(o,1),c=a??l??[1,0],h=l??a??[1,0];let d=c[0]+h[0],u=c[1]+h[1];const f=Math.hypot(d,u);f<1e-9?(d=c[0],u=c[1]):(d/=f,u/=f);const g=d*c[0]+u*c[1],p=Math.min(V0,1/Math.max(g,1e-6)),m=r.width/2*p;e.push({x:r.x-u*m,y:r.y+d*m}),n.push({x:r.x+u*m,y:r.y-d*m})}return{left:e,right:n}}function Fl(t){const e=t.length;if(e<2)return null;const n=t[e-1];for(let s=e-2;s>=0;s--){const i=n.x-t[s].x,o=n.y-t[s].y,r=Math.hypot(i,o);if(r>1e-9)return{x:n.x,y:n.y,radius:n.width/2,start:Math.atan2(i/r,-o/r)}}return null}function xs(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function en(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function nn(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function ue(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Is(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function Os(t){return Math.hypot(t[0],t[1],t[2])}function bo(t,e){return Os(en(t,e))}function Pe(t){const e=Os(t);return e===0?[0,0,0]:nn(t,1/e)}function jl(t,e,n){return[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n,t[2]+(e[2]-t[2])*n]}const J0=Object.freeze(Object.defineProperty({__proto__:null,add:xs,cross:Is,distance:bo,dot:ue,length:Os,lerp:jl,normalize:Pe,scale:nn,subtract:en},Symbol.toStringTag,{value:"Module"})),Z0=Math.PI/180;function _s(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function mt(t,e){const n=new Array(16);for(let s=0;s<4;s++)for(let i=0;i<4;i++){let o=0;for(let r=0;r<4;r++)o+=t[r*4+i]*e[s*4+r];n[s*4+i]=o}return n}function xe(t){return[1,0,0,0,0,1,0,0,0,0,1,0,t[0],t[1],t[2],1]}function Ie(t){return[t[0],0,0,0,0,t[1],0,0,0,0,t[2],0,0,0,0,1]}function zt(t){const[e,n,s,i]=t;return[1-2*(n*n+s*s),2*(e*n+s*i),2*(e*s-n*i),0,2*(e*n-s*i),1-2*(e*e+s*s),2*(n*s+e*i),0,2*(e*s+n*i),2*(n*s-e*i),1-2*(e*e+n*n),0,0,0,0,1]}function wo(t,e,n){const s=zt(e);for(let i=0;i<3;i++)s[i]*=n[0],s[4+i]*=n[1],s[8+i]*=n[2];return s[12]=t[0],s[13]=t[1],s[14]=t[2],s}function Q0(t){const e=new Array(16);for(let n=0;n<4;n++)for(let s=0;s<4;s++)e[s*4+n]=t[n*4+s];return e}function ko(t){const[e,n,s,i,o,r,a,l,c,h,d,u,f,g,p,m]=t,b=e*r-n*o,S=e*a-s*o,k=e*l-i*o,y=n*a-s*r,M=n*l-i*r,$=s*l-i*a,E=c*g-h*f,A=c*p-d*f,T=c*m-u*f,I=h*p-d*g,v=h*m-u*g,P=d*m-u*p,H=b*P-S*v+k*I+y*T-M*A+$*E;if(Math.abs(H)<1e-12)return null;const O=1/H;return[(r*P-a*v+l*I)*O,(s*v-n*P-i*I)*O,(g*$-p*M+m*y)*O,(d*M-h*$-u*y)*O,(a*T-o*P-l*A)*O,(e*P-s*T+i*A)*O,(p*k-f*$-m*S)*O,(c*$-d*k+u*S)*O,(o*v-r*T+l*E)*O,(n*T-e*v-i*E)*O,(f*M-g*k+m*b)*O,(h*k-c*M-u*b)*O,(r*A-o*I-a*E)*O,(e*I-n*A+s*E)*O,(g*S-f*y-p*b)*O,(c*y-h*S+d*b)*O]}function tp(t,e,n,s){const i=1/Math.tan(t*Z0/2),o=1/(n-s);return[i/e,0,0,0,0,i,0,0,0,0,(s+n)*o,-1,0,0,2*s*n*o,0]}function ep(t,e,n,s,i,o){const r=1/(e-t),a=1/(s-n),l=1/(o-i);return[2*r,0,0,0,0,2*a,0,0,0,0,-2*l,0,-(e+t)*r,-(s+n)*a,-(o+i)*l,1]}function np(t,e,n=[0,1,0]){const s=Pe(en(t,e)),i=Pe(Is(n,s)),o=Is(s,i);return[i[0],o[0],s[0],0,i[1],o[1],s[1],0,i[2],o[2],s[2],0,-ue(i,t),-ue(o,t),-ue(s,t),1]}function Rt(t,e){const n=t[0]*e[0]+t[4]*e[1]+t[8]*e[2]+t[12],s=t[1]*e[0]+t[5]*e[1]+t[9]*e[2]+t[13],i=t[2]*e[0]+t[6]*e[1]+t[10]*e[2]+t[14],o=t[3]*e[0]+t[7]*e[1]+t[11]*e[2]+t[15];return o===1||o===0?[n,s,i]:[n/o,s/o,i/o]}const sp=Object.freeze(Object.defineProperty({__proto__:null,compose:wo,fromQuat:zt,identity:_s,invert:ko,lookAt:np,multiply:mt,orthographic:ep,perspective:tp,scaling:Ie,transformPoint:Rt,translation:xe,transpose:Q0},Symbol.toStringTag,{value:"Module"})),Cs={"power1.in":[.55,.085,.68,.53],"power1.out":[.25,.46,.45,.94],"power1.inout":[.455,.03,.515,.955],"power2.in":[.55,.055,.675,.19],"power2.out":[.215,.61,.355,1],"power2.inout":[.645,.045,.355,1],"power3.in":[.895,.03,.685,.22],"power3.out":[.165,.84,.44,1],"power3.inout":[.77,0,.175,1],"power4.in":[.755,.05,.855,.06],"power4.out":[.23,1,.32,1],"power4.inout":[.86,0,.07,1],"sine.in":[.47,0,.745,.715],"sine.out":[.39,.575,.565,1],"sine.inout":[.445,.05,.55,.95],"expo.in":[.95,.05,.795,.035],"expo.out":[.19,1,.22,1],"expo.inout":[1,0,0,1],"circ.in":[.6,.04,.98,.335],"circ.out":[.075,.82,.165,1],"circ.inout":[.785,.135,.15,.86],"back.in":[.6,-.28,.735,.045],"back.out":[.175,.885,.32,1.275],"back.inout":[.68,-.55,.265,1.55]},Bl={none:"linear",linear:"linear","linear.none":"linear","power1.in":"ease-in-quad","power1.out":"ease-out-quad","power1.inout":"ease-in-out-quad","power2.in":"ease-in-cubic","power2.out":"ease-out-cubic","power2.inout":"ease-in-out-cubic"};function ip(t){let e=t.trim().toLowerCase();e=e.replace(/\.ease(in|out|inout)$/,".$1");const n=/^([a-z]+\d?)(\(.*\))?$/.exec(e);return n&&n[1]!=="steps"&&e!=="none"&&e!=="linear"&&(e=`${n[1]}.out${n[2]??""}`),e}xt({type:"bounce",mode:"in"}),xt({type:"bounce",mode:"in-out"});function Ln(t){const e=Wl.get(t.trim().toLowerCase());if(e)return e;const n=ip(t),s=/^steps\(\s*(\d+)\s*\)$/.exec(n);if(s){const r={type:"steps",count:Math.max(1,Number.parseInt(s[1],10))+1,position:"none"};return{easing:r,fn:xt(r)}}const i=/^(elastic|bounce|back)\.(in|out|inout)(?:\(([^)]*)\))?$/.exec(n);if(i){const[,o,r,a]=i,l=(a??"").split(",").map(d=>Number.parseFloat(d)).filter(d=>Number.isFinite(d)),c=r==="inout"?"in-out":r;if(o==="back"&&l.length===0&&n in Cs)return{easing:{type:"cubic-bezier",points:Cs[n]}};const h=o==="elastic"?{type:"elastic",mode:c,...l[0]!==void 0&&{amplitude:l[0]},...l[1]!==void 0&&{period:l[1]}}:o==="bounce"?{type:"bounce",mode:c}:{type:"back",mode:c,...l[0]!==void 0&&{overshoot:l[0]}};return{easing:h,fn:xt(h)}}return n in Bl?{easing:Bl[n]}:n in Cs?{easing:{type:"cubic-bezier",points:Cs[n]}}:{easing:"ease-out"}}const Wl=new Map;function vo(t,e){return Wl.set(t.trim().toLowerCase(),e.bezier?{easing:{type:"cubic-bezier",points:e.bezier},fn:e.fn}:{fn:e.fn,requiresBaking:"custom"}),t}function Mo(t){let e=t>>>0;return()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}const ql=/^\s*random\(\s*(\[.*\]|[^)]*)\s*\)\s*$/;function Kl(t){return typeof t=="string"&&ql.test(t)}function op(t=1){let e=Mo(t);const n=(l,c)=>((...h)=>h.length>=l?c(...h):d=>c(...h,d)),s=(l,c,h)=>Math.min(Math.max(h,Math.min(l,c)),Math.max(l,c)),i=(l,c,h,d,u)=>c===l?h:h+(u-l)/(c-l)*(d-h),o=(l,c)=>{if(typeof l=="number")return l===0?c:Math.round(c/l)*l;if(Array.isArray(l))return Yl(l,c,1/0);if("values"in l)return Yl(l.values,c,l.radius??1/0);const h=Math.round(c/l.increment)*l.increment;return Math.abs(h-c)<=(l.radius??1/0)?h:c},r=(l,c,h)=>{const d=l+e()*(c-l);return h?Math.round(d/h)*h:d};return{clamp:n(3,s),mapRange:n(5,i),normalize:n(3,(l,c,h)=>i(l,c,0,1,h)),interpolate:n(3,(l,c,h)=>{if(typeof l=="object"&&!Array.isArray(l)){const d={};for(const u of Object.keys(l))d[u]=Hn(l[u])(l[u],c[u],h);return d}return Hn(l)(l,c,h)}),wrap:((l,c,h)=>{if(Array.isArray(l)){const p=l,m=b=>p[(Math.round(b)%p.length+p.length)%p.length];return c===void 0?m:m(c)}const d=l,f=c-d,g=p=>f===0?d:((p-d)%f+f)%f+d;return h===void 0?g:g(h)}),wrapYoyo:n(3,(l,c,h)=>{const d=c-l;if(d===0)return l;const u=((h-l)%(d*2)+d*2)%(d*2);return l+(u>d?d*2-u:u)}),snap:n(2,o),random:((l,c,h,d)=>{if(Array.isArray(l)){const f=()=>l[Math.floor(e()*l.length)];return c===!0?f:f()}const u=()=>r(l,c,h);return d?u:u()}),shuffle:l=>{for(let c=l.length-1;c>0;c--){const h=Math.floor(e()*(c+1));[l[c],l[h]]=[l[h],l[c]]}return l},distribute:({base:l=0,amount:c,each:h,from:d="start",ease:u})=>(f,g,p)=>{const m=p.length,S=gs(f,m,{...c!==void 0?{amount:c}:{each:h??1},from:d}),k=c!==void 0?c:(h??1)*zi(m,d),y=u&&k>0?u(S/k)*k:S;return l+y},pipe:(...l)=>c=>l.reduce((h,d)=>d(h),c),splitColor:l=>rp(l),getUnit:l=>typeof l=="number"?"":/^-?[\d.]+(?:e[-+]?\d+)?([a-z%]*)$/i.exec(l.trim())?.[1]??"",seed:l=>{e=Mo(l)},resolveRandomString:l=>{const c=ql.exec(l)?.[1]??"";if(c.startsWith("[")){const g=c.slice(1,-1).split(",").map(p=>p.trim()).filter(Boolean).map(p=>Number.isFinite(Number(p))?Number(p):p.replace(/^['"]|['"]$/g,""));return g[Math.floor(e()*g.length)]}const[h,d,u]=c.split(",").map(f=>Number.parseFloat(f));return r(h,d,Number.isFinite(u)?u:void 0)}}}function Yl(t,e,n){let s=e,i=1/0;for(const o of t){const r=Math.abs(o-e);r<i&&(i=r,s=o)}return i<=n?s:e}function rp(t){const e=t.trim(),n=/^#([0-9a-f]{3,8})$/i.exec(e)?.[1];if(n){const o=(n.length<=4?[...n].map(r=>r+r).join(""):n).match(/../g).map(r=>Number.parseInt(r,16));return o.length>=4?[o[0],o[1],o[2],Math.round(o[3]/255*1e3)/1e3]:[o[0],o[1],o[2]]}const s=(/rgba?\(([^)]+)\)/i.exec(e)?.[1]??"0,0,0").split(/[\s,/]+/).filter(Boolean).map(i=>Number.parseFloat(i));return s.length>=4?[s[0],s[1],s[2],s[3]]:[s[0]??0,s[1]??0,s[2]??0]}const ap=/^([+-])=\s*(-?[\d.]+)$/,lp=/^([<>])\s*(?:([+-])?=?\s*(-?[\d.]+))?$/;function Nn(t,e){const n=e.scale??1,s=c=>Number.parseFloat(c)*n;if(t===void 0)return e.cursor;if(typeof t=="number")return t*n;const i=t.trim();if(i==="")return e.cursor;const o=ap.exec(i);if(o){const c=s(o[2]);return e.cursor+(o[1]==="-"?-c:c)}const r=lp.exec(i);if(r){const c=r[1]==="<"?e.previousStart:e.previousEnd;if(r[3]===void 0)return c;const h=s(r[3]);return c+(r[2]==="-"?-h:h)}const a=/^(.+?)([+-])=\s*(-?[\d.]+)$/.exec(i);if(a){const c=e.labels.get(a[1].trim());if(c!==void 0){const h=s(a[3]);return c+(a[2]==="-"?-h:h)}}const l=e.labels.get(i);return l!==void 0?l:/^-?[\d.]+$/.test(i)?s(i):e.cursor}function cp(t){if(typeof t!="object"||t===null)return!1;const e=t;return e.grid!==void 0||e.from==="random"||Array.isArray(e.from)||e.ease!==void 0||e.axis!==void 0}function hp(t,e,n={}){if(t===0)return[];const s=e.grid==="auto"?Math.max(1,Math.min(t,n.columnsFromLayout?.()??t)):Array.isArray(e.grid)?Math.max(1,e.grid[1]):t,i=Array.isArray(e.grid)?Math.max(1,e.grid[0]):Math.ceil(t/s),o=g=>({x:g%s,y:Math.floor(g/s)}),r=e.from??"start",a=Array.isArray(r)?{x:r[0]*(s-1),y:r[1]*(i-1)}:typeof r=="number"?o(Math.max(0,Math.min(t-1,r))):r==="end"?o(t-1):r==="center"||r==="edges"?{x:(s-1)/2,y:(i-1)/2}:{x:0,y:0},l=g=>{const{x:p,y:m}=o(g),b=Math.abs(p-a.x),S=Math.abs(m-a.y);return e.axis==="x"?b:e.axis==="y"?S:Math.hypot(b,S)};let c=Array.from({length:t},(g,p)=>l(p));const h=Math.max(...c);if(r==="edges"&&(c=c.map(g=>h-g)),r==="random"){const g=n.random??Math.random;c=c.map(()=>g()*h)}const d=e.amount!==void 0?e.amount:(e.each??0)*h,u=e.ease?Ln(e.ease):void 0,f=u?u.fn??xt(u.easing):void 0;return c.map(g=>{const p=h===0?0:g/h;return(f?f(p):p)*d})}const So=new Set(["duration","delay","ease","repeat","repeatDelay","yoyo","stagger","onComplete","onUpdate","onStart","onRepeat","onReverseComplete","repeatRefresh","keyframes","easeEach","scrollTo","id","immediateRender","overwrite","paused","scrollTrigger","spring"]),dp={rotation:"rotate",rotationZ:"rotate",rotationX:"rotateX",rotationY:"rotateY",transformPerspective:"perspective",perspective:"childPerspective"};function Hs(t){const e={},n={};for(const[s,i]of Object.entries(t))So.has(s)?e[s]=i:n[dp[s]??s]=i;return{config:e,properties:n}}function Rs(t,e){return t===void 0?e:t*1e3}function To(t,e){if(t!==void 0)return typeof t=="number"?{each:t*1e3}:cp(t)?{offsets:hp(e?.count??0,t,e??{}).map(s=>s*1e3)}:{...t.each!==void 0&&{each:t.each*1e3},...t.amount!==void 0&&{amount:t.amount*1e3},...t.from!==void 0&&{from:t.from}}}const up={opacity:1,x:0,y:0,z:0,rotate:0,rotateX:0,rotateY:0,rotateZ:0,scale:1,scaleX:1,scaleY:1,scaleZ:1,skewX:0,skewY:0,originX:50,originY:50,perspective:0,blur:0,glow:0,clipTop:0,clipRight:0,clipBottom:0,clipLeft:0};function zl(t){return up[t]}function fp(t){const e=typeof t=="string"||Array.isArray(t)?{path:t}:t;if(!e||typeof e.path!="string"&&!Array.isArray(e.path))throw new Error("gsap-compat: motionPath needs a path — SVG path data or an array of { x, y } points.");let n;if(Array.isArray(e.path))n=Nl(e.path,{curviness:e.curviness});else if(Ve(e.path))n=e.path;else throw new Error(`gsap-compat: motionPath "${e.path}" is not path data. Selectors and elements are resolved by live.to(); timeline() and tf need the path data itself.`);const s={pathData:n};return e.autoRotate!==void 0&&e.autoRotate!==!1&&(s.autoRotate=!0,typeof e.autoRotate=="number"&&(s.rotateOffset=e.autoRotate)),e.matrix&&(s.matrix=e.matrix),{config:s,start:e.start??0,end:e.end??1}}function pp(t){const e=typeof t=="string"||Array.isArray(t)?{path:t}:{...t};return{...e,start:e.end??1,end:e.start??0}}function Xl(t){return typeof t=="object"&&t!==null&&"shape"in t?t.shape:t}function gp(t){if(t.morphSVG===void 0)return t;const{morphSVG:e,...n}=t,s=Xl(e);if(typeof s!="string"||!Ve(s))throw new Error(`gsap-compat: morphSVG "${String(s)}" is not path data. Selectors and elements are resolved by live.to(); timeline() and tf need the path data itself.`);return{...n,d:s}}function mp(t,e){if(t===!0)return[0,e];if(t===!1)return[0,0];if(typeof t=="number")return[0,Ul(t,e)];const n=t.trim().split(/[\s,]+/).filter(Boolean),s=r=>{const a=Number.parseFloat(r);if(Number.isNaN(a))throw new Error(`gsap-compat: drawSVG "${t}" is not a length or percentage`);return Ul(r.endsWith("%")?e*a/100:a,e)};if(n.length===0)return[0,e];if(n.length===1)return[0,s(n[0])];const i=s(n[0]),o=s(n[1]);return i<=o?[i,o]:[o,i]}function yp(t,e){const[n,s]=mp(t,e);return{strokeDasharray:[s-n,e],strokeDashoffset:-n}}function bp(t,e){if(t.drawSVG===void 0)return t;const{drawSVG:n,...s}=t;return{...s,...yp(n,e)}}function wp(t){if(t.drawSVG!==void 0)throw new Error("gsap-compat: drawSVG needs the stroke length from the page. Use live.to(), or animate strokeDasharray / strokeDashoffset directly (see drawSvgProperties).");return t}function Ul(t,e){return Math.max(0,Math.min(e,t))}function kp(t){let e=2166136261;for(let n=0;n<t.length;n++)e=Math.imul(e^t.charCodeAt(n),16777619);return e>>>0}function vp(t,e,n){if(t.scrambleText!==void 0){const s=t.scrambleText,i=typeof s=="string"?{text:s}:s;if(typeof i?.text!="string")throw new Error("gsap-compat: scrambleText needs the text to end on — a string, or { text }.");const o=i.revealDelay&&n>0?i.revealDelay*1e3/n:void 0;return{to:i.text,mode:"scramble",...i.chars!==void 0&&{chars:i.chars},...i.speed!==void 0&&{refreshRate:20*i.speed},...o!==void 0&&{revealDelay:Math.min(o,.999)},...i.tweenLength!==void 0&&{tweenLength:i.tweenLength},...i.rightToLeft!==void 0&&{rightToLeft:i.rightToLeft},seed:i.seed??kp(`${e}|${i.text}`)}}if(t.text!==void 0){const s=t.text,i=typeof s=="string"?{value:s}:s;if(typeof i?.value!="string")throw new Error("gsap-compat: text needs the text to end on — a string, or { value }.");return{to:i.value,mode:"type",...i.rightToLeft!==void 0&&{rightToLeft:i.rightToLeft}}}}function Eo(t){return Math.max(.1,t/25)}function Mp(t,e){const n=typeof e=="number"?{velocity:e}:e;if(typeof n?.velocity!="number"||!Number.isFinite(n.velocity))throw new Error("gsap-compat: inertia needs a velocity for each property — a number, or { velocity }.");const s=n.friction??(n.resistance!==void 0?Eo(n.resistance):void 0),i={from:t,velocity:n.velocity,...s!==void 0&&{friction:s},...n.min!==void 0&&{min:n.min},...n.max!==void 0&&{max:n.max}};return typeof n.end=="function"?i.end=[n.end(xn(i))]:n.end!==void 0&&(i.end=Array.isArray(n.end)?[...n.end]:n.end),i}function Sp(t){const e=t===!0?{}:typeof t=="string"?{preset:t}:t;if(e.preset!==void 0&&!(e.preset in bs))throw new Error(`gsap-compat: unknown spring preset "${e.preset}" — use one of ${Object.keys(bs).join(", ")}`);return{...e.preset?bs[e.preset]:{},...e.stiffness!==void 0&&{stiffness:e.stiffness},...e.damping!==void 0&&{damping:e.damping},...e.mass!==void 0&&{mass:e.mass},...e.restDelta!==void 0&&{restDelta:e.restDelta}}}function Tp(t,e){if(t===!0||typeof t=="string")return;const n=t.velocity;return typeof n=="number"?n:n?.[e]}class Oe{timeline;options;cursor=0;fallbackRandom=Mo(1);previousStart=0;previousEnd=0;labels=new Map;trackCounter=0;lastValues=new Map;constructor(e={}){this.options=e,this.timeline=new Ht({id:e.id??"gsap-compat",name:e.name,config:{...e.repeat!==void 0&&{loop:e.repeat},...e.yoyo!==void 0&&{alternate:e.yoyo},...e.repeatDelay!==void 0&&{repeatDelay:e.repeatDelay*1e3},...e.timeScale!==void 0&&{speed:e.timeScale}}})}to(e,n,s){return this.build(e,void 0,Dn(n),s)}from(e,n,s){const{config:i,properties:o}=Hs(Dn(n)),{motionPath:r,text:a,scrambleText:l,...c}=o,h=this.targetsOf(e)[0],d={...i};for(const g of Object.keys(c))d[g]=this.resolveStart(h,g);r!==void 0&&(d.motionPath=pp(r));const u={},f=String(this.resolveStart(h,"text"));return a!==void 0&&(u.text=Ao(a),d.text=typeof a=="object"?{...a,value:f}:f),l!==void 0&&(u.text=Ao(l),d.scrambleText=typeof l=="object"?{...l,text:f}:f),this.build(e,{...c,...u},d,s)}fromTo(e,n,s,i){const{properties:o}=Hs(Dn(n));return this.build(e,o,Dn(s),i)}set(e,n,s){return this.build(e,void 0,{...Dn(n),duration:0},s)}get lastStart(){return this.previousStart}get lastEnd(){return this.previousEnd}addEvent(e){const n=Math.max(0,Nn(e,this.context()));return this.previousStart=n,this.previousEnd=n,this.cursor=Math.max(this.cursor,n),n}timeOf(e){return Nn(e,this.context())}addLabel(e,n){return this.labels.set(e,Nn(n,this.context())),this}labelTimes(){return[...this.labels.values()].sort((e,n)=>e-n)}labelTime(e){return this.labels.get(e)}add(e,n){const s=Nn(n,this.context());for(const o of e.timeline.tracks){if(!("keyframes"in o))continue;const r=Ts({...o,id:this.nextTrackId(`nested-${o.id}`),keyframes:o.keyframes.map(a=>({...a,time:a.time+s}))});this.timeline.addTrack(r)}const i=s+e.timeline.duration;return this.previousStart=s,this.previousEnd=i,this.cursor=Math.max(this.cursor,i),this}play(){return this.timeline.play(),this}pause(){return this.timeline.pause(),this}restart(){return this.timeline.stop(),this.timeline.play(),this}reverse(){return this.timeline.reverse(),this}kill(){return this.timeline.removeTracks(),this}reset(){return this.timeline.removeTracks(),this.cursor=0,this.previousStart=0,this.previousEnd=0,this.labels.clear(),this.lastValues.clear(),this.trackCounter=0,this}seek(e){if(typeof e=="string"){const n=this.labels.get(e);return n!==void 0&&this.timeline.seek(n),this}return this.timeline.seek(e*1e3),this}progress(e){const n=this.timeline.duration;return e!==void 0&&n>0&&this.timeline.seek(e*n),n>0?this.timeline.currentTime/n:0}timeScale(e){return e!==void 0&&(this.timeline.speed=e),this.timeline.speed}duration(){return this.timeline.duration/1e3}tick(e){return this.timeline.tick(e),this}toDefinition(){return this.timeline.toDefinition()}build(e,n,s,i){const{config:o,properties:r}=Hs(s),{motionPath:a,text:l,scrambleText:c,inertia:h,...d}=r,u=this.targetsOf(e),f=Nn(i,this.context()),g=Rs(o.delay,0),p=Rs(o.duration,500),m=To(o.stagger,{count:u.length,columnsFromLayout:this.options.layoutColumns?()=>this.options.layoutColumns(u):void 0,random:this.options.random??this.fallbackRandom}),b=this.easingFor(o.ease),S=[],k=o.spring;let y=0,M=!1;for(const[v,P]of Object.entries(d)){const H=P;let O=n?.[v]!==void 0?n[v]:this.resolveStart(u[0],v);if(typeof O!=typeof H&&(this.warn(`no usable start value for "${v}" on "${u[0]}" — it will snap to ${String(H)}. Use fromTo() to animate it.`),O=H),k!==void 0&&(typeof O!="number"||typeof H!="number")&&this.warn(`spring works on numbers, so "${v}" on "${u[0]}" eases instead`),k!==void 0&&typeof O=="number"&&typeof H=="number"){const D={...Sp(k),from:O,to:H,velocity:Tp(k,v)??this.options.startVelocity?.(u[0],v)??0},W=this.nextTrackId(`${u[0]}-${v}-spring`),B={id:W,target:u[0],...u.length>1&&{targets:u},...m&&u.length>1&&{stagger:m},property:v,kind:"spring",spring:D,delay:f+g};this.timeline.addTrack(B),S.push(W),y=Math.max(y,_a(D));for(const _ of u)this.lastValues.set(`${_}|${v}`,H);continue}M=!0;const C=this.keyframesFor(O,H,p,b,o.ease),j=this.nextTrackId(`${u[0]}-${v}`);this.timeline.addTrack(Ts({id:j,target:u[0],...u.length>1&&{targets:u},...m&&u.length>1&&{stagger:m},property:v,delay:f+g,keyframes:C,...v==="quaternion"&&{interpolation:"slerp"}})),S.push(j);for(const D of u)this.lastValues.set(`${D}|${v}`,H)}const $=vp({text:l,scrambleText:c},u[0],p);if($){const v=n?.text??n?.scrambleText,P=v!==void 0?Ao(v):this.resolveStart(u[0],"text"),H=this.nextTrackId(`${u[0]}-text`),O={id:H,target:u[0],...u.length>1&&{targets:u},...m&&u.length>1&&{stagger:m},property:"text",textConfig:{from:typeof P=="string"?P:String(P??""),...$},delay:f+g,keyframes:this.keyframesFor(0,1,p,b,o.ease)};this.timeline.addTrack(O),S.push(H);for(const C of u)this.lastValues.set(`${C}|text`,$.to)}if(a!==void 0){const{config:v,start:P,end:H}=fp(a),O=this.nextTrackId(`${u[0]}-motionPath`),C={id:O,target:u[0],...u.length>1&&{targets:u},...m&&u.length>1&&{stagger:m},property:"motionPath",motionPathConfig:v,delay:f+g,keyframes:this.keyframesFor(P,H,p,b,o.ease)};this.timeline.addTrack(C),S.push(O)}if(h!==void 0)for(const[v,P]of Object.entries(h)){const H=this.resolveStart(u[0],v);if(typeof H!="number"){this.warn(`inertia on "${v}" needs a numeric start value; skipped`);continue}const O=Mp(H,P),C=this.nextTrackId(`${u[0]}-${v}-inertia`),j={id:C,target:u[0],...u.length>1&&{targets:u},...m&&u.length>1&&{stagger:m},property:v,kind:"inertia",inertia:O,delay:f+g};this.timeline.addTrack(j),S.push(C),y=Math.max(y,Ue(O));for(const D of u)this.lastValues.set(`${D}|${v}`,Xe(O))}const T=((h!==void 0||k!==void 0)&&!M&&!$&&a===void 0?y:Math.max(p,y))+(m&&u.length>1?$n(u.length,m):0),I=f+g+T;return this.previousStart=f+g,this.previousEnd=I,this.cursor=Math.max(this.cursor,I),{trackIds:S,start:f+g,end:I,kill:()=>{for(const v of S)this.timeline.removeTrack(v)}}}keyframesFor(e,n,s,i,o){const r={time:0,value:e};if(s<=0)return[{time:0,value:n}];const a=typeof o=="string"?Ln(o):void 0;if(a?.requiresBaking==="custom"||this.options.bakeEases&&An(i)){const c=a?.fn??xt(i);return[r,...co(r,{time:s,value:n},c,{intervalMs:this.options.bakeIntervalMs})]}return[r,{time:s,value:n,...i&&{easing:i}}]}resolveStart(e,n){const s=this.lastValues.get(`${e}|${n}`);if(s!==void 0)return s;const i=this.options.startValue?.(e,n);if(i!==void 0)return i;const o=this.options.defaults?.[n];if(o!==void 0)return o;if(n==="text")return"";if(n==="quaternion")return[0,0,0,1];if(n==="d")throw new Error(`gsap-compat: no starting shape for "${e}". Use fromTo({ d: … }, { morphSVG: … }), or live.to(), which reads the element's current shape.`);const r=zl(n);return r!==void 0?(this.warn(`no start value for "${n}" on "${e}" — using the static default ${r}. GSAP would read the live DOM here; tinyfly cannot, so pass an explicit fromTo() or a defaults map.`),r):(this.warn(`no start value or default for "${n}" on "${e}" — using 0`),0)}easingFor(e){if(e!==void 0){if(typeof e=="string")return Ln(e).easing;if(typeof e=="function")throw new Error('gsap-compat: function eases cannot be serialized. Use a named ease, or a cubic-bezier via { type: "cubic-bezier", points: [...] }.');return e}}targetsOf(e){return Array.isArray(e)?e:[e]}context(){return{cursor:this.cursor,previousStart:this.previousStart,previousEnd:this.previousEnd,labels:this.labels,scale:1e3}}nextTrackId(e){return this.trackCounter+=1,`${e}-${this.trackCounter}`}warn(e){this.options.onWarning?.(`gsap-compat: ${e}`)}}function Ao(t){if(typeof t=="string")return t;if(t&&typeof t=="object"){const e=t;return String(e.value??e.text??"")}return String(t??"")}function Ep(t){return new Oe(t)}function Dn(t){return wp(gp(t))}function Ap(t){return!Array.isArray(t)||t.length!==4?null:`matrix3d(${zt(he(t)).map(n=>Math.round(n*1e6)/1e6+0).join(", ")})`}const $p=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),Pp="#ffffff",xp="rgba(0, 0, 0, 0.5)";function Ip(t){const e=[];if(t.blur!==void 0&&e.push(`blur(${Math.max(0,t.blur)}px)`),t.brightness!==void 0&&e.push(`brightness(${Math.max(0,t.brightness)})`),t.glow!==void 0&&e.push(`drop-shadow(0 0 ${Math.max(0,t.glow)}px ${t.glowColor??Pp})`),t.shadowX!==void 0||t.shadowY!==void 0||t.shadowBlur!==void 0){const n=t.shadowX??0,s=t.shadowY??0,i=Math.max(0,t.shadowBlur??0);e.push(`drop-shadow(${n}px ${s}px ${i}px ${t.shadowColor??xp})`)}return e.length>0?e.join(" "):null}function Op(t,e){const n=t.childNodes.length===1?t.firstChild:null;if(n&&n.nodeType===3){const s=n;s.data!==e&&(s.data=e);return}t.textContent!==e&&(t.textContent=e)}function _p(t){if(!("ownerSVGElement"in t))return;const e=t.style;!e||e.transformBox||(e.transformBox="fill-box",e.transformOrigin||(e.transformOrigin="50% 50%"))}const Gl=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"]),Cp=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),Hp=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],Rp=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),Lp=new Set(["originX","originY"]),Np=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Dp=new Set(["drawOn"]),Fp={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},Vl={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},jp="http://www.w3.org/2000/svg";class _e{targets=new Map;registerTarget(e,n){this.targets.set(e,n)}unregisterTarget(e){this.targets.delete(e)}getTarget(e){return this.targets.get(e)}clearTargets(){this.targets.clear()}applyState(e){for(const[n,s]of e.values){const i=this.targets.get(n);i&&this.applyProperties(i,s)}}applyProperties(e,n){let s=null,i=null,o=null,r=null,a=null;const l=n.has("motionPathX"),c=n.has("motionPathY"),h=n.has("motionPathRotate");for(const[g,p]of n)if(!(g==="x"&&l)&&!(g==="y"&&c)&&!((g==="rotate"||g==="rotateZ")&&h)&&!Dp.has(g)){if(Cp.has(g))(s??={})[g]=p;else if(Rp.has(g))typeof p=="number"&&((i??={})[g]=p);else if(Lp.has(g))typeof p=="number"&&((o??={})[g]=p);else if(Np.has(g))typeof p=="number"&&((r??={})[g]=p);else if($p.has(g))(a??={})[g]=p;else if(g!=="perspective"){if(g!=="shine")if(g==="text"&&typeof p=="string")Op(e,p);else if(g==="d"&&typeof p=="string"){const m=e;(m.tagName?.toLowerCase()==="path"?m:m.querySelector?.("path"))?.setAttribute?.("d",p)}else this.applyStyleProperty(e,g,p)}}const d=n.get("shine");typeof d=="number"&&this.applyShine(e,d);const u=[],f=n.get("perspective");if(typeof f=="number"&&f>0&&u.push(`perspective(${f}px)`),s)for(const g of Hp){const p=s[g];if(p===void 0)continue;const m=this.buildTransformPart(g,p);m&&u.push(m)}if(u.length>0&&(e.style.transform=u.join(" "),_p(e)),i&&(i.childPerspective!==void 0&&(e.style.perspective=`${i.childPerspective}px`),(i.perspectiveOriginX!==void 0||i.perspectiveOriginY!==void 0)&&(e.style.perspectiveOrigin=`${i.perspectiveOriginX??50}% ${i.perspectiveOriginY??50}%`)),o){const g=o.originX??50,p=o.originY??50;e.style.transformOrigin=`${g}% ${p}%`}if(r){const g=r.clipTop??0,p=r.clipRight??0,m=r.clipBottom??0,b=r.clipLeft??0;e.style.clipPath=`inset(${g}% ${p}% ${m}% ${b}%)`}if(a){const g=Ip(a);g&&(e.style.filter=g)}}buildTransformPart(e,n){if(e==="quaternion")return Ap(n);if(typeof n!="number")return null;switch(e){case"x":case"motionPathX":return`translateX(${n}px)`;case"y":case"motionPathY":return`translateY(${n}px)`;case"z":return`translateZ(${n}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${n}deg)`;case"rotateX":return`rotateX(${n}deg)`;case"rotateY":return`rotateY(${n}deg)`;case"scale":return`scale(${n})`;case"scaleX":return`scaleX(${n})`;case"scaleY":return`scaleY(${n})`;case"scaleZ":return`scaleZ(${n})`;case"skewX":return`skewX(${n}deg)`;case"skewY":return`skewY(${n}deg)`;default:return null}}applyShine(e,n){e.dataset.shineBase||(e.dataset.shineBase=e.style.color||"currentColor");const s=e.dataset.shineBase,i=-20+n*140,o=e.style;o.color="transparent",o.backgroundImage=`linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${s}, ${s})`,o.backgroundSize="250% 100%, 100% 100%",o.backgroundPosition=`${i}% 0, 0 0`,o.backgroundRepeat="no-repeat",o.webkitBackgroundClip="text",o.backgroundClip="text"}applyStyleProperty(e,n,s){let i;if(e.namespaceURI===jp&&n in Vl){const a=Array.isArray(s)?s.join(", "):String(s);e.style[Vl[n]]=a;return}else n==="fill"&&e.dataset?.elementType==="text"?i="color":i=Fp[n]??n;let r;typeof s=="number"?Gl.has(n)||Gl.has(i)?r=`${s}px`:r=String(s):Array.isArray(s)?r=s.join(", "):r=s,e.style[i]=r}}const Bp={request:t=>requestAnimationFrame(t),cancel:t=>cancelAnimationFrame(t)};class Jl{adapter=new _e;scheduler;rootOption;onWarning;names=new WeakMap;elements=new Map;nameCounter=0;objectNames=new WeakMap;objects=new Map;owned=new Set;currentCollector;tickerCallbacks=new Set;tickerTime=0;tickerFrame=0;liveTimelines=new Set;utils=op();active=new Map;applied=new Map;dirty=new Set;frameId=null;lastTimestamp=null;destroyed=!1;constructor(e={}){this.scheduler=e.scheduler??Bp,this.rootOption=e.root,this.onWarning=e.onWarning}get root(){return this.rootOption??document}resolveTargets(e){const n=[];for(const s of this.targetsOf(e)){const i=this.nameFor(s);$o(s)&&this.currentCollector?.touch(s,i),n.push(i)}return n}query(e){return this.selectorRoot.querySelector(e)}get collector(){return this.currentCollector}setCollector(e){this.currentCollector=e}forget(e){this.applied.delete(e),this.dirty.delete(e)}get selectorRoot(){return this.currentCollector?.scope??this.root}elementFor(e){return this.elements.get(e)}objectFor(e){return this.objects.get(e)}appliedValue(e,n){return this.applied.get(e)?.get(n)}velocityOf(e,n){for(const i of[...this.active.keys()].reverse()){if(i.getTracks({target:e,property:n}).length===0)continue;const o=i.currentTime;if(o<4)return 0;const r=i.getStateAtTime(o).values.get(e)?.get(n),a=i.getStateAtTime(o-4).values.get(e)?.get(n);if(typeof r!="number"||typeof a!="number")return;const l=(r-a)/4;return(i.direction==="reverse"?-l:l)*1e3}}ticker={add:e=>{this.destroyed||(this.tickerCallbacks.size===0&&(this.tickerTime=0,this.tickerFrame=0),this.tickerCallbacks.add(e),this.currentCollector?.track({revert:()=>this.ticker.remove(e)}),this.startLoop())},remove:e=>{this.tickerCallbacks.delete(e),this.running||this.stopLoop()}};activate(e,n={}){this.destroyed||(e.onUpdate=s=>this.write(s),this.active.delete(e),this.active.set(e,n),this.startLoop())}deactivate(e){this.active.delete(e),this.running||this.stopLoop()}own(e){return this.destroyed?e.destroy():this.owned.add(e),e}destroy(){this.destroyed=!0;for(const e of this.owned)e.destroy();this.owned.clear();for(const e of this.active.keys())e.stop();this.active.clear(),this.stopLoop(),this.adapter.clearTargets(),this.elements.clear(),this.names=new WeakMap,this.objects.clear(),this.objectNames=new WeakMap,this.tickerCallbacks.clear(),this.liveTimelines.clear(),this.applied.clear(),this.dirty.clear()}apply(e,n){if(this.destroyed)return;const s=new Map(Object.entries(n));this.write({values:new Map([[e,s]]),currentTime:0,playbackState:"idle",direction:"forward",loopIteration:0}),this.flush()}render(e){this.destroyed||(this.write(e.getStateAtTime(e.currentTime)),this.flush())}tick(e){const n=[...this.active];for(const[s]of n)s.duration<=0?(this.write(s.getStateAtTime(0)),s.stop()):s.tick(e);this.flush();for(const[s,i]of n)i.onUpdate?.(),s.playbackState!=="playing"&&this.active.get(s)===i&&this.active.delete(s);this.flush(),this.runTicker(e),this.running||this.stopLoop()}get running(){return this.active.size>0||this.tickerCallbacks.size>0}runTicker(e){if(this.tickerCallbacks.size!==0){this.tickerTime+=e,this.tickerFrame+=1;for(const n of[...this.tickerCallbacks])n(this.tickerTime/1e3,e,this.tickerFrame)}}write(e){for(const[n,s]of e.values){let i=this.applied.get(n);i||(i=new Map,this.applied.set(n,i));for(const[o,r]of s)i.set(o,r);this.dirty.add(n)}}flush(){if(this.dirty.size===0)return;const e=new Map;for(const n of this.dirty){const s=this.applied.get(n),i=this.objects.get(n);if(i)for(const[o,r]of s)i[o]=r;else e.set(n,s)}this.dirty.clear(),e.size!==0&&this.adapter.applyState({values:e,currentTime:0,playbackState:"playing",direction:"forward",loopIteration:0})}frame=e=>{this.frameId=null;const n=this.lastTimestamp===null?0:e-this.lastTimestamp;this.lastTimestamp=e,n>0&&this.tick(n),this.running&&this.frameId===null&&(this.frameId=this.scheduler.request(this.frame))};startLoop(){this.frameId===null&&(this.lastTimestamp=null,this.frameId=this.scheduler.request(this.frame))}stopLoop(){this.frameId!==null&&this.scheduler.cancel(this.frameId),this.frameId=null,this.lastTimestamp=null}targetsOf(e){if(typeof e=="string")return Array.from(this.selectorRoot.querySelectorAll(e));if($o(e))return[e];if(!Wp(e))return[e];const n=[];for(const s of Array.from(e))n.push(...this.targetsOf(s));return n}nameFor(e){return $o(e)?this.elementName(e):this.objectName(e)}objectName(e){const n=this.objectNames.get(e);if(n)return n;let s;do this.nameCounter+=1,s=`obj-${this.nameCounter}`;while(this.objects.has(s)||this.elements.has(s));return this.objectNames.set(e,s),this.objects.set(s,e),s}elementName(e){const n=this.names.get(e);if(n)return n;let s=e.id?`#${e.id}`:"";if(!s||this.elements.has(s))do this.nameCounter+=1,s=`el-${this.nameCounter}`;while(this.elements.has(s));return this.names.set(e,s),this.elements.set(s,e),this.adapter.registerTarget(s,e),s}}function $o(t){return typeof t=="object"&&t!==null&&t.nodeType===1}function Wp(t){if(Array.isArray(t))return!0;const e=t;return typeof e.length=="number"&&typeof e.item=="function"}function Ls(t){const e=t.style;if(!e)return t.getBoundingClientRect();const n=e.transform;e.transform="none";const s=t.getBoundingClientRect();return e.transform=n,s}const Zl=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function qp(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function Kp(t){const e=t.getScreenCTM?.();if(e)return[e.a,e.b,e.c,e.d,e.e,e.f];const n=t.getBoundingClientRect();return[1,0,0,1,n.left,n.top]}function Yp(t,e){const n=typeof t=="string"||Array.isArray(t)||Zl(t)?{path:t}:t,{align:s,alignOrigin:i,path:o,...r}=n,a=$=>{const E=Zl($)?$:e.query($);return E||e.warn(`gsap-compat: motionPath could not find "${String($)}"`),E};let l=null,c="";if(Array.isArray(o)||typeof o=="string"&&Ve(o))c=o;else{l=a(o);const $=l&&Ps({tag:l.localName,attributes:qp(l)});l&&!$&&e.warn(`gsap-compat: motionPath element <${l.localName}> has no path geometry`),c=$??""}const h={...r,path:c};if(s===void 0||s===!1)return h;const d=s===!0?l:a(s);if(!d)return s===!0&&e.warn("gsap-compat: motionPath align: true needs the path to be an element"),h;const u=e.targets[0];if(!u)return h;const[f,g,p,m,b,S]=Kp(d),k=Ls(u),[y,M]=i??[.5,.5];for(const $ of e.targets.slice(1)){const E=Ls($);if(Math.abs(E.left-k.left)>.5||Math.abs(E.top-k.top)>.5){e.warn("gsap-compat: motionPath align measures the first target; the others are laid out elsewhere");break}}return h.matrix=[f,g,p,m,b-k.left-y*k.width,S-k.top-M*k.height],h}const Ql=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function tc(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function ec(t){if(!t)return null;const e=Ps({tag:t.localName,attributes:tc(t)});return e||(t.querySelector("path")?.getAttribute("d")??null)}function zp(t,e,n){const s=Xl(t);if(typeof s=="string"&&Ve(s))return s;const i=Ql(s)?s:typeof s=="string"?e(s):null,o=ec(i);return o||(n(`gsap-compat: morphSVG could not find a shape for "${String(s)}"`),"")}const Xp=new Set(["cx","cy","r","rx","ry","x","y","width","height","x1","y1","x2","y2","points"]);function Up(t,e=document){return(typeof t=="string"?Array.from(e.querySelectorAll(t)):Ql(t)?[t]:Array.from(t)).map(s=>{if(s.localName==="path")return s;const i=Ps({tag:s.localName,attributes:tc(s)});if(!i||!s.parentNode)return s;const o=s.ownerDocument.createElementNS("http://www.w3.org/2000/svg","path");for(const r of Array.from(s.attributes))Xp.has(r.name)||o.setAttribute(r.name,r.value);return o.setAttribute("d",i),s.parentNode.replaceChild(o,s),o})}const nc=.3;class sc{options;target;running=!1;dragging=!1;passedTolerance=!1;lastX=0;lastY=0;startX=0;startY=0;velocityX=0;velocityY=0;lastTime=0;constructor(e){this.options=e,this.target=e.target}start(){if(this.running)return;this.running=!0;const e=this.options.type??["pointer","touch"];e.includes("pointer")&&(this.target.addEventListener("pointerdown",this.onPointerDown),this.target.addEventListener("pointermove",this.onPointerMove),this.target.addEventListener("pointerup",this.onPointerUp),this.target.addEventListener("pointercancel",this.onPointerUp)),e.includes("touch")&&(this.target.addEventListener("touchstart",this.onTouchStart,{passive:!1}),this.target.addEventListener("touchmove",this.onTouchMove,{passive:!1}),this.target.addEventListener("touchend",this.onTouchEnd)),e.includes("wheel")&&this.target.addEventListener("wheel",this.onWheel,{passive:!1})}stop(){this.running&&(this.running=!1,this.target.removeEventListener("pointerdown",this.onPointerDown),this.target.removeEventListener("pointermove",this.onPointerMove),this.target.removeEventListener("pointerup",this.onPointerUp),this.target.removeEventListener("pointercancel",this.onPointerUp),this.target.removeEventListener("touchstart",this.onTouchStart),this.target.removeEventListener("touchmove",this.onTouchMove),this.target.removeEventListener("touchend",this.onTouchEnd),this.target.removeEventListener("wheel",this.onWheel))}destroy(){this.stop()}get velocity(){return{x:this.velocityX,y:this.velocityY}}begin(e,n,s){this.dragging=!0,this.passedTolerance=!1,this.startX=e,this.startY=n,this.lastX=e,this.lastY=n,this.velocityX=0,this.velocityY=0,this.lastTime=ic(),this.options.onPress?.(this.stateFrom(0,0,s))}move(e,n,s){if(!this.dragging)return;const i=e-this.lastX,o=n-this.lastY;this.lastX=e,this.lastY=n;const r=e-this.startX,a=n-this.startY,l=this.options.tolerance??3;if(!this.passedTolerance){if(Math.hypot(r,a)<l)return;this.passedTolerance=!0}this.updateVelocity(i,o),this.options.preventDefault!==!1&&s.cancelable&&s.preventDefault(),this.options.onMove?.(this.stateFrom(i,o,s))}end(e){this.dragging&&(this.dragging=!1,this.options.onRelease?.(this.stateFrom(0,0,e)))}updateVelocity(e,n){const s=ic(),i=Math.max(1,s-this.lastTime);this.lastTime=s;const o=e/i*1e3,r=n/i*1e3;this.velocityX+=(o-this.velocityX)*nc,this.velocityY+=(r-this.velocityY)*nc}stateFrom(e,n,s){return{deltaX:e,deltaY:n,velocityX:this.velocityX,velocityY:this.velocityY,totalX:this.lastX-this.startX,totalY:this.lastY-this.startY,isDragging:this.dragging,event:s}}onPointerDown=e=>{const n=e,s=this.target;if(typeof n.pointerId=="number"&&typeof s.setPointerCapture=="function")try{s.setPointerCapture(n.pointerId)}catch{}this.begin(n.clientX,n.clientY,e)};onPointerMove=e=>{const n=e;this.move(n.clientX,n.clientY,e)};onPointerUp=e=>this.end(e);onTouchStart=e=>{const n=e.touches[0];n&&this.begin(n.clientX,n.clientY,e)};onTouchMove=e=>{const n=e.touches[0];n&&this.move(n.clientX,n.clientY,e)};onTouchEnd=e=>this.end(e);onWheel=e=>{const n=e;this.options.preventDefault!==!1&&n.cancelable&&n.preventDefault(),this.updateVelocity(n.deltaX,n.deltaY),this.options.onMove?.({deltaX:n.deltaX,deltaY:n.deltaY,velocityX:this.velocityX,velocityY:this.velocityY,totalX:0,totalY:0,isDragging:!1,event:e})}}function ic(){return typeof performance<"u"?performance.now():Date.now()}function oc(t,e,n){let s={delta:0,line:null},i=n;for(const o of t)for(const r of e){const a=Math.abs(r-o);a<=i&&(i=a,s={delta:r-o,line:r})}return s}function rc(t,e){return e<=0?[]:t.map(n=>Math.round(n/e)*e)}class Po{options;observer;x;y;originX=0;originY=0;snappedX=null;snappedY=null;constructor(e){this.options=e,this.x=e.initialX??0,this.y=e.initialY??0,this.observer=new sc({target:e.target,onPress:n=>{const s=e.getPosition?.();s&&(this.x=s.x,this.y=s.y),this.originX=this.x,this.originY=this.y,e.onPress?.(n)},onMove:n=>this.handleMove(n),onRelease:n=>e.onRelease?.(n)})}start(){this.observer.start()}stop(){this.observer.stop()}destroy(){this.observer.destroy()}get position(){return{x:this.x,y:this.y}}get velocity(){return this.observer.velocity}setPosition(e,n){const s=this.options.axis??"both";this.x=s==="y"?this.x:this.applyConstraints(e,"x"),this.y=s==="x"?this.y:this.applyConstraints(n,"y")}get snapLines(){return{x:this.snappedX,y:this.snappedY}}snapThreshold(){if(this.options.snapThreshold!==void 0)return this.options.snapThreshold;const e=this.options.snap??0;return e>0?e/2:8}handleMove(e){this.setPosition(this.originX+e.totalX,this.originY+e.totalY),this.options.mode==="scrub"&&this.scrub(),this.options.onDrag?.(this.position,e),this.options.onSnap?.(this.snapLines)}scrub(){const e=this.options.timeline;if(!e)return;const n=e.duration;if(n<=0)return;const s=this.options.scrubDistance??500;if(s===0)return;const i=(this.options.axis??"both")==="y"?this.y:this.x,o=Gp(i/s);e.pause(),e.seek(o*n)}applyConstraints(e,n){let s=e;const i=[...rc([s],this.options.snap??0),...(n==="x"?this.options.snapLinesX:this.options.snapLinesY)??[]],o=oc([s],i,this.snapThreshold());s+=o.delta,n==="x"?this.snappedX=o.line:this.snappedY=o.line;const r=this.options.bounds;if(r){const a=n==="x"?r.minX:r.minY,l=n==="x"?r.maxX:r.maxY;a!==void 0&&(s=Math.max(a,s)),l!==void 0&&(s=Math.min(l,s))}return s}}function Gp(t){return t<0?0:t>1?1:t}function Vp(t){const e=new Po(t);return e.start(),e}const Jp={x:"x",y:"y","x,y":"both"},xo=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function ac(t,e){const n=Ls(t),s=e.getBoundingClientRect();return{minX:s.left-n.left,maxX:s.right-n.right,minY:s.top-n.top,maxY:s.bottom-n.bottom}}function lc(t){return Array.isArray(t)?[...t]:t}function Zp(t,e,n,s={}){const[i]=e.resolveTargets(n),o=i?e.elementFor(i):void 0;if(!i||!o)throw new Error(`gsap-compat: live.draggable could not find ${String(n)}`);if(s.type==="rotation")return Qp(t,e,i,o,s);const r=Jp[s.type??"x,y"],a=()=>{const p=e.appliedValue(i,"x"),m=e.appliedValue(i,"y");return{x:typeof p=="number"?p:0,y:typeof m=="number"?m:0}},l=typeof s.bounds=="string"?e.query(s.bounds):xo(s.bounds)?s.bounds:null,h={bounds:(!l&&s.bounds&&!xo(s.bounds)?s.bounds:void 0)??(l?ac(o,l):void 0)};let d=null;const u=()=>{d?.kill(),d=null},f=p=>{const m=s.inertia===!0?{}:s.inertia,b=m.friction??(m.resistance!==void 0?Eo(m.resistance):4),S=a(),k=h.bounds??{};let y,M;const $=m.end;if(Array.isArray($)){const A=xn({from:S.x,velocity:r==="y"?0:p.x,friction:b}),T=xn({from:S.y,velocity:r==="x"?0:p.y,friction:b});let I=$[0];for(const v of $)Math.hypot(v.x-A,v.y-T)<Math.hypot(I.x-A,I.y-T)&&(I=v);I&&(y=[I.x],M=[I.y])}else typeof $=="number"?(y=$,M=$):$&&(y=lc($.x),M=lc($.y));const E={};r!=="y"&&(E.x={velocity:p.x,friction:b,min:k.minX,max:k.maxX,end:y}),r!=="x"&&(E.y={velocity:p.y,friction:b,min:k.minY,max:k.maxY,end:M}),d=t.to(o,{inertia:E,onComplete:()=>s.onThrowComplete?.()})},g=new Po({target:o,axis:r,snap:s.snap,get bounds(){return h.bounds},getPosition:a,onPress:()=>{u(),l&&(h.bounds=ac(o,l)),s.onPress?.()},onDrag:p=>{e.apply(i,r==="x"?{x:p.x}:r==="y"?{y:p.y}:{x:p.x,y:p.y}),s.onDrag?.(p)},onRelease:()=>{const p=g.velocity;s.onRelease?.(p),s.inertia&&f(p)}});return g.start(),{draggable:g,get position(){return a()},get rotation(){const p=e.appliedValue(i,"rotate");return typeof p=="number"?p:0},destroy(){u(),g.destroy()}}}function Qp(t,e,n,s,i){const o=typeof i.bounds=="object"&&i.bounds!==null&&!xo(i.bounds)?i.bounds:{},r=()=>{const k=e.appliedValue(n,"rotate");return typeof k=="number"?k:0},a=k=>Math.min(o.maxRotation??1/0,Math.max(o.minRotation??-1/0,k));let l=null,c=!1,h,d={x:0,y:0},u=0,f=0,g=[];const p=k=>Math.atan2(k.clientY-d.y,k.clientX-d.x)*180/Math.PI,m=k=>{if(c)return;l?.kill(),l=null,c=!0,h=k.pointerId,s.setPointerCapture?.(k.pointerId);const y=s.getBoundingClientRect();d={x:y.left+y.width/2,y:y.top+y.height/2},u=p(k),f=r(),g=[{time:performance.now(),rotation:f}],i.onPress?.()},b=k=>{if(!c||k.pointerId!==h)return;const y=p(k);let M=y-u;M>180&&(M-=360),M<-180&&(M+=360),u=y,f+=M;let $=a(f);i.snap&&($=a(Math.round($/i.snap)*i.snap)),e.apply(n,{rotate:$});const E=performance.now();for(g.push({time:E,rotation:$});g.length>2&&E-g[0].time>100;)g.shift();const A={x:0,y:0};i.onDrag?.(A)},S=k=>{if(!c||k.pointerId!==h)return;c=!1;const y=g[0],M=g[g.length-1],$=y&&M?(M.time-y.time)/1e3:0,E=$>0?(M.rotation-y.rotation)/$:0;if(i.onRelease?.({x:E,y:0}),!i.inertia)return;const A=i.inertia===!0?{}:i.inertia,T=A.friction??(A.resistance!==void 0?Eo(A.resistance):4),I=typeof A.end=="number"||Array.isArray(A.end)?A.end:void 0;l=t.to(s,{inertia:{rotate:{velocity:E,friction:T,min:o.minRotation,max:o.maxRotation,end:Array.isArray(I)?I.filter(v=>typeof v=="number"):I}},onComplete:()=>i.onThrowComplete?.()})};return s.addEventListener("pointerdown",m),s.addEventListener("pointermove",b),s.addEventListener("pointerup",S),s.addEventListener("pointercancel",S),s.style.touchAction="none",{draggable:void 0,position:{x:0,y:0},get rotation(){return r()},destroy(){l?.kill(),s.removeEventListener("pointerdown",m),s.removeEventListener("pointermove",b),s.removeEventListener("pointerup",S),s.removeEventListener("pointercancel",S)}}}const tg={opacity:0,scale:.6};function eg(t){const e=t.getBoundingClientRect();return e.width===0&&e.height===0?null:{cx:e.left+e.width/2,cy:e.top+e.height/2,width:e.width,height:e.height}}function cc(t){const e=Ls(t);return e.width===0&&e.height===0?null:{cx:e.left+e.width/2,cy:e.top+e.height/2,width:e.width,height:e.height}}function Io(t,e){const s=t.resolveTargets(e).map(r=>t.elementFor(r)).filter(r=>!!r),i=new Map,o=new Map;for(const r of s){const a=eg(r);i.set(r,a);const l=hc(r);a&&l!==void 0&&!o.has(l)&&o.set(l,{element:r,box:a})}return{elements:s,boxes:i,ids:o}}const Oo=new WeakMap;function _o(t,e,n,s={}){const i=s.duration??.6,o=s.ease??"power2.inOut",r=s.stagger??0,a=s.scale!==!1,l=s.enter===void 0?tg:s.enter,c=new Set(n.elements);if(s.targets!==void 0)for(const f of t.resolveTargets(s.targets)){const g=t.elementFor(f);g&&c.add(g)}const h=[...c].sort((f,g)=>f===g?0:f.compareDocumentPosition(g)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1),d=e({onComplete:s.onComplete});let u=0;for(const f of h){const g=cc(f);if(!g)continue;let p=n.boxes.get(f)??null,m;const b=hc(f),S=!p&&b!==void 0?n.ids.get(b):void 0;S&&S.element!==f&&(p=S.box,m=S.element);const[k]=t.resolveTargets(f);Oo.get(f)?.timeline.removeTracks({target:k});const y=u*r;if(!p){if(l===!1)continue;d.fromTo(f,{x:0,y:0,scaleX:1,scaleY:1,...l},{...dc(l),x:0,y:0,scaleX:1,scaleY:1,duration:i,ease:o,delay:y},0),Oo.set(f,d),u++;continue}const M=p.cx-g.cx,$=p.cy-g.cy,E=a?p.width/g.width:1,A=a?p.height/g.height:1;if(!(Math.abs(M)>.5||Math.abs($)>.5||Math.abs(E-1)>.001||Math.abs(A-1)>.001)){const v=(P,H)=>{const O=t.appliedValue(k,P);return typeof O=="number"&&Math.abs(O-H)>1e-6};(v("x",0)||v("y",0)||v("scaleX",1)||v("scaleY",1))&&d.set(f,{x:0,y:0,scaleX:1,scaleY:1},0);continue}const I=s.fade===!0&&m!==void 0;d.fromTo(f,{x:M,y:$,scaleX:E,scaleY:A,...I&&{opacity:0}},{x:0,y:0,scaleX:1,scaleY:1,...I&&{opacity:1},duration:i,ease:o,delay:y},0),I&&m&&cc(m)&&d.fromTo(m,{opacity:1},{opacity:0,duration:i,ease:o,delay:y},0),Oo.set(f,d),u++}return d}function hc(t){return t.dataset?.flipId}function dc(t){const e={};for(const n of Object.keys(t))e[n]=n==="opacity"||n.startsWith("scale")?1:0;return e}function ng(t,e={}){const n=new Set((e.type??"chars,words,lines").split(",").map(p=>p.trim())),s={chars:e.charsClass??"char",words:e.wordsClass??"word",lines:e.linesClass??"line"},i=e.aria!==!1,o=t.map(p=>({element:p,html:p.innerHTML,ariaLabel:p.getAttribute("aria-label")}));let r={chars:[],words:[],lines:[],masks:[]},a,l,c=!1;const h=()=>{for(const{element:p,html:m,ariaLabel:b}of o)p.innerHTML=m,b===null?p.removeAttribute("aria-label"):p.setAttribute("aria-label",b)},d=()=>{a&&(a.revert?a.revert():a.kill?.(),a=void 0)},u=()=>{const p={chars:[],words:[],lines:[],masks:[]};for(const{element:m}of o){const b=(m.textContent??"").replace(/\s+/g," ").trim(),S=sg(m,s.words),k=n.has("chars")?S.flatMap($=>ig($,s.chars)):[],y=n.has("lines")?rg(m,S,s.lines):[];if(i){!m.hasAttribute("aria-label")&&b&&m.setAttribute("aria-label",b);for(const $ of S)$.setAttribute("aria-hidden","true")}if(n.has("words"))p.words.push(...S);else for(const $ of S)$.removeAttribute("class");p.chars.push(...k),p.lines.push(...y);const M=e.mask==="lines"?y:e.mask==="words"?S:e.mask==="chars"?k:[];for(const $ of M)p.masks.push(ag($,`${s[e.mask]}-mask`))}r=p},f={elements:t,get chars(){return r.chars},get words(){return r.words},get lines(){return r.lines},get masks(){return r.masks},split(){c||(d(),h(),u(),a=e.onSplit?.(f))},revert(){c=!0,l?.disconnect(),d(),h()}};u(),a=e.onSplit?.(f),e.autoSplit&&g();function g(){const p=new Map;let m=!1;const b=()=>{if(m)return;m=!0;const k=()=>{m=!1,f.split()};typeof requestAnimationFrame=="function"?requestAnimationFrame(k):setTimeout(k,0)};if(typeof ResizeObserver=="function"){l=new ResizeObserver(k=>{let y=!1;for(const M of k){const $=Math.round(M.contentRect.width),E=p.get(M.target);p.set(M.target,$),E!==void 0&&E!==$&&(y=!0)}y&&b()});for(const k of t)l.observe(k)}const S=t[0]?.ownerDocument?.fonts;S&&S.status!=="loaded"&&S.ready.then(()=>b())}return f}function sg(t,e){const n=t.ownerDocument,s=[],i=n.createTreeWalker(t,4),o=[];for(let r=i.nextNode();r;r=i.nextNode())o.push(r);for(const r of o){const a=r.data.match(/\s+|\S+/g)??[];if(a.length===0)continue;const l=n.createDocumentFragment();for(const c of a){if(/^\s/.test(c)){l.appendChild(n.createTextNode(c));continue}const h=n.createElement("span");h.className=e,h.style.display="inline-block",h.textContent=c,l.appendChild(h),s.push(h)}r.replaceWith(l)}return s}function ig(t,e){const n=t.ownerDocument,s=og(t.textContent??"").map(i=>{const o=n.createElement("span");return o.className=e,o.style.display="inline-block",o.textContent=i,o});return t.replaceChildren(...s),s}function og(t){const e=Intl.Segmenter;return e?Array.from(new e(void 0,{granularity:"grapheme"}).segment(t),n=>n.segment):Array.from(t)}function rg(t,e,n){const s=t.ownerDocument,i=new Map(e.map(g=>[g,g.getBoundingClientRect()])),o=[],r=g=>{for(const p of Array.from(g.childNodes))p.nodeType===3||i.has(p)||p.tagName==="BR"?o.push(p):r(p)};r(t);const a=[];let l=null,c=0,h=0,d=!1,u=[];const f=()=>{l=s.createElement("span"),l.className=n,l.style.display="block",a.push(l),u=[]};for(const g of o){if(g.tagName==="BR"){d=!0;continue}const p=i.get(g);if(p&&(!l||d||p.top>c+h)&&(f(),c=p.top,h=p.height/2,d=!1),!l)continue;const m=[];for(let k=g.parentNode;k&&k!==t;k=k.parentNode)m.unshift(k);let b=0;for(;b<u.length&&b<m.length&&u[b].original===m[b];)b++;u.length=b;let S=b===0?l:u[b-1].clone;for(const k of m.slice(b)){const y=k.cloneNode(!1);S.appendChild(y),u.push({original:k,clone:y}),S=y}S.appendChild(g)}return t.replaceChildren(...a),a}function ag(t,e){const n=t.ownerDocument.createElement("span");return n.className=e,n.style.display=t.style.display==="block"?"block":"inline-block",n.style.overflow="clip",n.style.paddingBottom="0.12em",n.style.marginBottom="-0.12em",t.replaceWith(n),n.appendChild(t),n}const uc={top:0,left:0,start:0,center:.5,centre:.5,middle:.5,bottom:1,right:1,end:1};function Co(t){const e=t.trim().toLowerCase();if(e in uc)return uc[e];if(e.endsWith("%")){const n=Number.parseFloat(e.slice(0,-1));return Number.isNaN(n)?void 0:n/100}}function Ho(t){if(typeof t=="number")return{elementFraction:0,viewportFraction:0,offsetPx:0,absolutePx:t};let e=0;const s=t.replace(/([+-])=\s*(-?[\d.]+)/g,(r,a,l)=>(e+=(a==="-"?-1:1)*Number.parseFloat(l),"")).trim().split(/\s+/).filter(Boolean);if(s.length===1&&/^-?[\d.]+$/.test(s[0]))return{elementFraction:0,viewportFraction:0,offsetPx:0,absolutePx:Number.parseFloat(s[0])+e};const i=s[0]!==void 0?Co(s[0]):void 0,o=s[1]!==void 0?Co(s[1]):void 0;return{elementFraction:i??0,viewportFraction:o??0,offsetPx:e}}function sn(t,e,n){const s=Ho(n),i=s.absolutePx!==void 0?t.top+s.absolutePx:t.top+t.height*s.elementFraction,o=e*s.viewportFraction;return i-o+s.offsetPx}function lg(t,e,n,s){const i=sn(t,e,n),r=sn(t,e,s)-i;return r<=0?i<=0?1:0:Ro(-i/r)}function Ro(t){return t<0?0:t>1?1:t===0?0:t}function fc(t,e,n,s){if(n<=0)return e;const i=1-Math.exp(-(s/1e3)/n);return t+(e-t)*i}function Lo(t,e,n,s,i){const o=h=>sn({top:t+i(h),bottom:t+i(h)+e,height:e},n,s),r=o(0),a=o(1);if(Math.sign(r)===Math.sign(a)||r===0||a===0)return r===0?0:a===0?1:Math.abs(r)<Math.abs(a)?0:1;let l=0,c=1;for(let h=0;h<40;h++){const d=(l+c)/2;Math.sign(o(d))===Math.sign(r)?l=d:c=d}return(l+c)/2}class pc{timeline;trigger;behaviour;options;observer=null;hasPlayed=!1;running=!1;constructor(e){this.timeline=e.timeline,this.trigger=e.trigger,this.behaviour=e.behaviour??"once",this.options=e}start(){if(!this.running){if(this.running=!0,typeof IntersectionObserver>"u"){this.enter();return}this.observer=new IntersectionObserver(e=>{for(const n of e)n.isIntersecting?this.enter():this.leave()},{threshold:this.options.threshold??.15,rootMargin:this.options.rootMargin,root:this.options.root??null}),this.observer.observe(this.trigger)}}stop(){this.running=!1,this.observer?.disconnect(),this.observer=null}destroy(){this.stop()}reset(){this.hasPlayed=!1,this.timeline.stop()}enter(){this.options.onEnter?.(),!(this.behaviour==="once"&&this.hasPlayed)&&(this.hasPlayed=!0,this.behaviour!=="once"&&this.timeline.seek(0),this.timeline.play())}leave(){this.options.onLeave?.(),this.behaviour==="reset"&&this.timeline.stop()}}function cg(t){const e=new pc(t);return e.start(),e}class gc{element;spacer;saved;axis;spacing;constructor(e,n={}){this.element=e,this.axis=n.axis??"y",this.spacing=n.spacing??!0;const s=e.ownerDocument;this.spacer=s.createElement("div"),this.spacer.className="pin-spacer",this.saved={position:e.style.position,top:e.style.top,left:e.style.left},this.axis==="x"&&(this.spacer.style.flexShrink="0"),e.replaceWith(this.spacer),this.spacer.appendChild(e)}release(){this.element.style.position=this.saved.position,this.element.style.top=this.saved.top,this.element.style.left=this.saved.left}apply(e,n){const s=Math.max(0,n);this.element.style.position="sticky",this.axis==="x"?(this.spacer.style.width=`${this.element.offsetWidth+s}px`,this.spacer.style.marginRight=this.spacing?"":`-${s}px`,this.element.style.left=`${e}px`):(this.spacer.style.height=`${this.element.offsetHeight+s}px`,this.spacer.style.marginBottom=this.spacing?"":`-${s}px`,this.element.style.top=`${e}px`)}destroy(){this.element.style.position=this.saved.position,this.element.style.top=this.saved.top,this.element.style.left=this.saved.left,this.spacer.parentNode&&this.spacer.replaceWith(this.element)}}const hg=.15;function mc(t){return typeof t=="object"&&!Array.isArray(t)?t:{snapTo:t}}function yc(t,e,n){const s=Ns(t+e*hg);if(typeof n=="function")return Ns(n(s));if(typeof n=="number")return n<=0?t:Ns(Math.round(s/n)*n);if(n.length===0)return t;let i=n[0];for(const o of n)Math.abs(o-s)<Math.abs(i-s)&&(i=o);return Ns(i)}function bc(t,e,n){const s=t.duration??{min:.2,max:.8};if(typeof s=="number")return s;const i=Math.min(1,Math.abs(e)/Math.max(1,n));return s.min+(s.max-s.min)*i}class wc{rafId=null;cancelEvents=["wheel","touchstart","pointerdown","keydown"];onInterrupt=()=>this.cancel();write;eventTarget;constructor(e,n){this.write=e,this.eventTarget=n}get active(){return this.rafId!==null}animate(e,n,s,i=In,o){if(this.cancel(),typeof requestAnimationFrame>"u"||s<=0){this.write(n),o?.();return}for(const l of this.cancelEvents)this.eventTarget?.addEventListener(l,this.onInterrupt,{passive:!0});let r=null;const a=l=>{r??=l;const c=Math.min(1,(l-r)/(s*1e3));this.write(e+(n-e)*i(c)),c<1?this.rafId=requestAnimationFrame(a):(this.rafId=null,this.detach(),o?.())};this.rafId=requestAnimationFrame(a)}cancel(){this.rafId!==null&&typeof cancelAnimationFrame<"u"&&cancelAnimationFrame(this.rafId),this.rafId=null,this.detach()}detach(){for(const e of this.cancelEvents)this.eventTarget?.removeEventListener(e,this.onInterrupt)}}function Ns(t){return Math.max(0,Math.min(1,t))}class kc{options;scroller;nodes=[];scrollerStart;scrollerEnd;start;end;constructor(e,n,s){this.options=s===!0?{}:s,this.scroller=n;const{startColor:i="#3ecf7a",endColor:o="#ff5a5a",id:r}=this.options,a=r?`${r} `:"",l=(c,h,d)=>{const u=e.createElement("div");return u.textContent=`${a}${c}`,u.setAttribute("aria-hidden","true"),u.className="scroll-marker",Object.assign(u.style,{position:d?"fixed":"absolute",right:`${this.options.indent??0}px`,zIndex:"2147483646",pointerEvents:"none",borderTop:`1px solid ${h}`,color:h,font:`${this.options.fontSize??"11px"} ui-monospace, monospace`,padding:"2px 6px",whiteSpace:"nowrap",background:"rgba(0, 0, 0, 0.35)"}),(n??e.body).appendChild(u),this.nodes.push(u),u};this.scrollerStart=l("scroller-start",i,!n),this.scrollerEnd=l("scroller-end",o,!n),this.start=l("start",i,!1),this.end=l("end",o,!1),n&&getComputedStyle(n).position==="static"&&(n.style.position="relative")}place(e,n){this.start.style.top=`${e.startPage}px`,this.end.style.top=`${e.endPage}px`;const s=this.scroller?n:0;this.scrollerStart.style.top=`${s+e.startViewport}px`,this.scrollerEnd.style.top=`${s+e.endViewport}px`}follow(e,n){this.scroller&&this.place(e,n)}destroy(){for(const e of this.nodes.splice(0))e.remove()}}const dg=120,on=[],rn=new Set;let No=!1;const ug=()=>{No||rn.size===0||(No=!0,queueMicrotask(()=>{No=!1;for(const t of rn)t.afterRefresh()}))},vc=()=>{for(const t of rn)t.beforeRefresh();for(const t of on)t.refresh();for(const t of rn)t.afterRefresh()};let an={width:0,height:0};const Mc=()=>{const t=window.innerWidth,e=window.innerHeight,n=t===an.width&&e!==an.height,s=Math.abs(e-an.height)<an.height*.25,i=typeof navigator<"u"&&(navigator.maxTouchPoints??0)>0;n&&s&&i||(an={width:t,height:e},vc())};class Fn{timeline;options;running=!1;pin=null;startPx=0;endPx=0;targetProgress=0;displayProgress=0;zone="before";measured=!1;lastScroll=null;lastScrollTime=0;velocityPxPerSecond=0;idleTimer=null;lastEmitted=null;rafId=null;lastFrameTime=null;onScroll=()=>this.update();releaseVelocity=0;snapper;snapTimer=null;markers=null;markerGeometry=null;constructor(e){this.timeline=e.timeline,this.options=e,this.snapper=new wc(n=>this.scrollTo(n),typeof window<"u"?window:null)}start(){if(this.running)return;this.running=!0,this.timeline?.pause();const e=this.options.pin===!0?this.options.trigger:this.options.pin||null;e&&!this.options.container&&(this.pin=new gc(e,{axis:this.options.horizontal?"x":"y",spacing:this.options.pinSpacing!==!1})),this.options.markers&&!this.options.horizontal&&typeof document<"u"&&(this.markers=new kc(document,this.options.scroller??null,this.options.markers)),this.scrollTarget()?.addEventListener("scroll",this.onScroll,{passive:!0}),on.length===0&&typeof window<"u"&&(an={width:window.innerWidth,height:window.innerHeight},window.addEventListener("resize",Mc,{passive:!0})),on.push(this),this.refresh()}stop(){this.running&&(this.running=!1,this.scrollTarget()?.removeEventListener("scroll",this.onScroll),on.splice(on.indexOf(this),1),on.length===0&&typeof window<"u"&&window.removeEventListener("resize",Mc),this.stopSmoothing(),this.idleTimer!==null&&clearTimeout(this.idleTimer),this.idleTimer=null,this.snapTimer!==null&&clearTimeout(this.snapTimer),this.snapTimer=null,this.snapper.cancel())}destroy(){this.stop(),this.pin?.destroy(),this.pin=null,this.markers?.destroy(),this.markers=null}get startOffset(){return this.startPx}get endOffset(){return this.endPx}static refreshAll(){vc()}static onRefresh(e){return rn.add(e),()=>rn.delete(e)}get progress(){return this.targetProgress}get velocity(){return this.velocityPxPerSecond}refresh(){if(!this.running)return;this.measured&&this.options.onRefresh?.();const e=this.scrollPosition();this.pin?.release();const n=this.triggerRect();if(n&&this.options.container)this.measureInContainer(this.options.container);else if(n){const s=this.viewportHeight();if(this.startPx=e+sn(n,s,jn(this.options.start)??"top bottom"),this.endPx=this.resolveEnd(n,s,e),this.pin){const i=this.relativeRect(this.pin.element.getBoundingClientRect());this.pin.apply(i.top-(this.startPx-e),this.endPx-this.startPx)}this.markerGeometry=this.markers?this.markersFor(s):null}this.markers&&this.markerGeometry&&this.markers.place(this.markerGeometry,e),this.lastScroll=null,this.updateFrom(e,!this.measured),this.measured=!0,ug()}sample(){this.refresh()}update(e){this.running&&this.updateFrom(e??this.scrollPosition(),!1)}updateFrom(e,n){this.trackVelocity(e),this.markers&&this.markerGeometry&&this.markers.follow(this.markerGeometry,e);const s=this.endPx-this.startPx,i=this.zone;this.targetProgress=s>0?Ro((e-this.startPx)/s):e>=this.startPx?1:0,this.zone=s>0?e<=this.startPx?"before":e>=this.endPx?"after":"active":e>=this.startPx?"after":"before",this.fireBoundaryCallbacks(i,this.zone),n||this.smoothing()<=0?(this.displayProgress=this.targetProgress,this.applyProgress()):(this.emitUpdate(),this.startSmoothing())}smoothing(){const e=this.options.scrub;return typeof e=="number"?Math.max(0,e):0}resolveEnd(e,n,s){const i=jn(this.options.end)??"bottom top",o=typeof i=="string"?i.trim().match(/^\+=\s*(-?[\d.]+)\s*(%|px)?$/):null;if(o){const r=Number.parseFloat(o[1]);return this.startPx+(o[2]==="%"?n*r/100:r)}return s+sn(e,n,i)}applyProgress(){const e=this.timeline?.duration??0;this.timeline&&e>0&&this.timeline.seek(this.displayProgress*e),this.emitUpdate()}emitUpdate(){if(!this.options.onUpdate)return;const e=[this.displayProgress,this.velocityPxPerSecond];this.lastEmitted&&this.lastEmitted[0]===e[0]&&this.lastEmitted[1]===e[1]||(this.lastEmitted=e,this.options.onUpdate(e[0],e[1]))}trackVelocity(e){const n=typeof performance<"u"?performance.now():Date.now();this.lastScroll!==null&&n>this.lastScrollTime&&e!==this.lastScroll&&(this.velocityPxPerSecond=(e-this.lastScroll)/(n-this.lastScrollTime)*1e3),(this.lastScroll===null||e!==this.lastScroll)&&(this.lastScroll=e,this.lastScrollTime=n),!(this.velocityPxPerSecond===0||typeof setTimeout>"u")&&(this.idleTimer!==null&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.idleTimer=null,this.releaseVelocity=this.velocityPxPerSecond,this.velocityPxPerSecond=0,this.emitUpdate(),this.scheduleSnap()},dg))}fireBoundaryCallbacks(e,n){if(e===n)return;const{onEnter:s,onLeave:i,onEnterBack:o,onLeaveBack:r}=this.options;e==="before"?(s?.(),n==="after"&&i?.()):e==="after"?(o?.(),n==="before"&&r?.()):n==="after"?i?.():r?.()}scheduleSnap(){const e=this.options.snap;if(e===void 0||this.snapper.active)return;const n=mc(e),s=()=>{this.snapTimer=null;const i=this.endPx-this.startPx,o=this.scrollPosition();if(!this.running||i<=0||o<=this.startPx||o>=this.endPx)return;const r=(o-this.startPx)/i,a=this.startPx+yc(r,this.releaseVelocity/i,n.snapTo)*i;Math.abs(a-o)<1||this.snapper.animate(o,a,bc(n,a-o,this.viewportHeight()),n.ease)};n.delay?this.snapTimer=setTimeout(s,n.delay*1e3):s()}scrollTo(e){const n=this.options.scroller,s=this.options.horizontal?{left:e}:{top:e};n?typeof n.scrollTo=="function"?n.scrollTo({...s,behavior:"instant"}):this.options.horizontal?n.scrollLeft=e:n.scrollTop=e:typeof window<"u"&&window.scrollTo({...s,behavior:"instant"})}measureInContainer(e){const n=this.options.trigger;if(typeof n?.getBoundingClientRect!="function")return;const s=n.getBoundingClientRect(),i=this.options.scroller?.getBoundingClientRect?.().left??0,o=this.options.scroller?this.options.scroller.clientWidth:typeof window<"u"?window.innerWidth:0,r=s.left-i-e.shiftAt(e.progress()),{start:a,end:l}=e.range(),c=f=>a+f*(l-a),h=Lo(r,s.width,o,jn(this.options.start)??"left right",e.shiftAt);this.startPx=c(h);const d=jn(this.options.end)??"right left",u=typeof d=="string"?d.trim().match(/^\+=\s*(-?[\d.]+)\s*(px)?$/):null;this.endPx=u?this.startPx+Number.parseFloat(u[1]):c(Lo(r,s.width,o,d,e.shiftAt)),this.markerGeometry=null}markersFor(e){const n=(o,r)=>{const a=jn(o)??r;if(typeof a=="number")return 0;if(/^\s*\+=/.test(a))return;const l=Ho(a);return e*l.viewportFraction-l.offsetPx},s=n(this.options.start,"top bottom")??0,i=n(this.options.end,"bottom top")??s;return{startViewport:s,endViewport:i,startPage:this.startPx+s,endPage:this.endPx+i}}startSmoothing(){if(this.rafId!==null||typeof requestAnimationFrame>"u")return;const e=n=>{if(this.rafId=null,!this.running)return;const s=this.lastFrameTime===null?16.67:n-this.lastFrameTime;this.lastFrameTime=n,this.displayProgress=fc(this.displayProgress,this.targetProgress,this.smoothing(),s);const i=Math.abs(this.targetProgress-this.displayProgress)<1e-4;i&&(this.displayProgress=this.targetProgress),this.applyProgress(),i?this.lastFrameTime=null:this.rafId=requestAnimationFrame(e)};this.rafId=requestAnimationFrame(e)}stopSmoothing(){this.rafId!==null&&typeof cancelAnimationFrame<"u"&&cancelAnimationFrame(this.rafId),this.rafId=null,this.lastFrameTime=null}scrollTarget(){return this.options.scroller??(typeof window<"u"?window:null)}scrollPosition(){const e=this.options.scroller,n=this.options.horizontal;return e?(n?e.scrollLeft:e.scrollTop)??0:typeof window<"u"?(n?window.scrollX:window.scrollY)??0:0}triggerRect(){const e=this.options.trigger;return typeof e?.getBoundingClientRect!="function"?null:this.relativeRect(e.getBoundingClientRect())}relativeRect(e){const n=this.options.horizontal,s=n?e.left??0:e.top,i=n?e.right??0:e.bottom,o=n?e.width??0:e.height,r=this.options.scroller;if(r&&typeof r.getBoundingClientRect=="function"){const a=r.getBoundingClientRect(),l=n?a.left:a.top;return{top:s-l,bottom:i-l,height:o}}return{top:s,bottom:i,height:o}}viewportHeight(){const e=this.options.scroller,n=this.options.horizontal;return e?n?e.clientWidth:e.clientHeight:typeof window<"u"?n?window.innerWidth:window.innerHeight:0}}function jn(t){return typeof t=="function"?t():t}function fg(t){const e=new Fn(t);return e.start(),e}const Do=new Set,pg=16,Sc=.5,gg=2;class Fo{options;frames;running=!1;reduced=!1;current=0;target=0;written=null;velocityPxPerSecond=0;frameId=null;lastTime=null;journey=null;pausedState=!1;effects=[];onWheel=e=>this.wheel(e);onScroll=()=>this.nativeScroll();onResize=()=>this.refresh();onLoad=()=>this.refresh();stopListening=null;constructor(e={}){this.options=e,this.frames=e.frames??{request:n=>requestAnimationFrame(n),cancel:n=>cancelAnimationFrame(n)}}start(){if(this.running||typeof window>"u")return this;this.running=!0,this.reduced=this.options.reducedMotion??(typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches),this.current=this.target=this.position();const e=this.options.scroller??window;return e.addEventListener("wheel",this.onWheel,{passive:!1}),e.addEventListener("scroll",this.onScroll,{passive:!0}),window.addEventListener("resize",this.onResize,{passive:!0}),window.addEventListener("load",this.onLoad),Do.add(this),this.stopListening=Fn.onRefresh({beforeRefresh:()=>this.rest(),afterRefresh:()=>this.refresh()}),this.refresh(),this}static refreshAll(){for(const e of Do)e.refresh()}stop(){if(!this.running)return this;this.running=!1;const e=this.options.scroller??window;return e.removeEventListener("wheel",this.onWheel),e.removeEventListener("scroll",this.onScroll),window.removeEventListener("resize",this.onResize),window.removeEventListener("load",this.onLoad),Do.delete(this),this.stopListening?.(),this.stopListening=null,this.cancelFrame(),this.journey=null,this}destroy(){this.stop();for(const e of this.effects)jo(e.element,e.saved);this.effects=[]}kill(){this.destroy()}get state(){const e=this.limit();return{scroll:this.current,target:this.target,progress:e>0?this.current/e:0,velocity:this.velocityPxPerSecond}}paused(e){return e!==void 0&&(this.pausedState=e,e&&(this.target=this.current,this.journey=null)),this.pausedState}scrollTo(e,n={}){if(!this.running)return;const s=this.clamp(this.resolve(e)+(n.offset??0)),i=Math.abs(s-this.current),o=this.reduced?0:n.duration??Math.min(1.2,Math.max(.4,i/2500));if(o<=0){this.journey=null,this.current=this.target=s,this.write(s),this.applyEffects(0);return}this.target=s,this.journey={from:this.current,to:s,ms:o*1e3,ease:n.ease??In,elapsed:0},this.requestFrame()}refresh(){if(!this.running)return;this.rest(),this.effects=[];const e=this.options.effects===!0?"[data-speed], [data-lag]":this.options.effects||"";if(e&&!this.reduced){const n=this.options.scroller??document,s=this.position(),i=this.viewportHeight(),o=this.options.scroller?.getBoundingClientRect().top??0;for(const r of n.querySelectorAll(e)){const a=Number.parseFloat(r.dataset.speed??""),l=Number.parseFloat(r.dataset.lag??""),c=r.getBoundingClientRect(),h=c.top-o+s;this.effects.push({element:r,speed:Number.isFinite(a)?a:void 0,lag:Number.isFinite(l)&&l>0?l:void 0,centre:h+c.height/2-i/2,lagged:s,shift:0,saved:r.style.getPropertyValue("translate")})}}this.current=this.target=this.clamp(this.position()),this.applyEffects(0)}rest(){for(const e of this.effects)jo(e.element,e.saved)}wheel(e){if(this.pausedState||this.reduced||(this.options.smooth??.8)<=0||e.ctrlKey||Math.abs(e.deltaX)>Math.abs(e.deltaY)||this.nestedScrollerTakes(e))return;const n=e.deltaMode===1?pg:e.deltaMode===2?this.viewportHeight():1,s=e.deltaY*n*(this.options.wheelMultiplier??1),i=this.clamp(this.target+s);i===this.target&&i===this.current||(e.preventDefault(),this.journey=null,this.target=i,this.requestFrame())}nativeScroll(){const e=this.position();this.written!==null&&Math.abs(e-this.written)<=gg||(this.written=null,this.journey=null,this.cancelFrame(),this.current=this.target=e,this.requestFrame())}nestedScrollerTakes(e){const n=this.options.scroller??document.documentElement;for(let s=e.target;s&&s!==n&&s!==document.body;s=s.parentElement){if(s.hasAttribute?.("data-smooth-ignore"))return!0;const i=getComputedStyle(s);if(!/(auto|scroll)/.test(i.overflowY)||s.scrollHeight<=s.clientHeight)continue;if(e.deltaY<0?s.scrollTop>0:s.scrollTop+s.clientHeight<s.scrollHeight-1)return!0}return!1}requestFrame(){this.frameId!==null||!this.running||(this.frameId=this.frames.request(e=>this.frame(e)))}cancelFrame(){this.frameId!==null&&this.frames.cancel(this.frameId),this.frameId=null,this.lastTime=null}frame(e){this.frameId=null;const n=this.lastTime===null?1e3/60:Math.min(100,e-this.lastTime);this.lastTime=e;const s=this.current;if(this.journey){const o=this.journey;o.elapsed+=n;const r=Math.min(1,o.elapsed/o.ms);this.current=o.from+(o.to-o.from)*o.ease(r),r>=1&&(this.journey=null)}else if(this.current!==this.target){const o=(this.options.smooth??.8)*1e3/3;this.current+=(this.target-this.current)*(1-Math.exp(-n/o)),Math.abs(this.target-this.current)<Sc&&(this.current=this.target)}this.current!==s&&this.write(this.current),this.velocityPxPerSecond=n>0?(this.current-s)*1e3/n:0;const i=this.applyEffects(n);this.current!==s&&this.options.onUpdate?.(this.state),this.journey||this.current!==this.target||i?this.requestFrame():(this.lastTime=null,this.velocityPxPerSecond=0)}applyEffects(e){let n=!1;const s=this.current;for(const i of this.effects){let o=0;if(i.speed!==void 0&&(o+=(s-i.centre)*(1-i.speed)),i.lag!==void 0){const r=i.lag*1e3/3;i.lagged=e===0?s:i.lagged+(s-i.lagged)*(1-Math.exp(-e/r)),Math.abs(s-i.lagged)<Sc?i.lagged=s:n=!0,o+=s-i.lagged}jo(i.element,o===0?i.saved:`0 ${mg(o)}px`),i.shift=o}return n}write(e){const n=Math.round(e);this.written=n;const s=this.options.scroller;s?s.scrollTop=n:window.scrollTo({top:n,behavior:"instant"})}position(){const e=this.options.scroller;return e?e.scrollTop:window.scrollY}viewportHeight(){const e=this.options.scroller;return e?e.clientHeight:window.innerHeight}limit(){const e=this.options.scroller??document.documentElement;return Math.max(0,e.scrollHeight-this.viewportHeight())}clamp(e){return Math.max(0,Math.min(this.limit(),e))}resolve(e){if(typeof e=="number")return e;const n=this.options.scroller??document,s=typeof e=="string"?n.querySelector(e):e;if(!s)return this.current;const i=this.options.scroller?.getBoundingClientRect().top??0,o=this.effects.find(r=>r.element===s)?.shift??0;return s.getBoundingClientRect().top-i+this.position()-o}}function jo(t,e){e?t.style.setProperty("translate",e):t.style.removeProperty("translate")}function mg(t){return Math.round(t*100)/100}function yg(t,e){switch(e){case"play":if(t.progress()>=1)break;t.reversed()?t.reverse():t.play();break;case"reverse":if(t.progress()<=0)break;t.reversed()?t.play():t.reverse();break;case"pause":t.pause();break;case"resume":t.resume();break;case"restart":t.restart();break;case"reset":t.pause(),t.progress(0);break;case"complete":t.pause(),t.progress(1);break}}function Bo(t,e,n,s,i=()=>{}){const o=f=>typeof f=="string"?t.query(f)??void 0:f,r=o(e.trigger)??s;if(!r){i(`gsap-compat: scrollTrigger has no trigger element${typeof e.trigger=="string"?` for "${e.trigger}"`:""}`);return}const a=e.scrub===void 0||e.scrub===!1?!1:e.scrub,l=(e.toggleActions??"play none none none").trim().split(/\s+/);let c=0,h;const d=(f,g)=>()=>{g?.(),n&&!a&&yg(n,l[f]??"none"),e.once&&f===0&&queueMicrotask(()=>h.destroy())},u=e.containerAnimation?kg(t,e.containerAnimation,r,i):void 0;return h=new Fn({trigger:r,start:e.start,end:e.end,scrub:a===!1?void 0:a,pin:e.pin===!0?!0:o(e.pin),scroller:o(e.scroller),horizontal:e.horizontal,pinSpacing:e.pinSpacing,onRefresh:e.invalidateOnRefresh&&n?.invalidate?()=>n.invalidate():void 0,snap:e.snap===void 0?void 0:bg(e.snap,n),markers:e.markers,container:u,onUpdate:(f,g)=>{if(n&&a!==!1&&n.progress(f),e.onUpdate){const p=f<c||g<0?-1:1;e.onUpdate({progress:f,velocity:g,direction:p})}c=f},onEnter:d(0,e.onEnter),onLeave:d(1,e.onLeave),onEnterBack:d(2,e.onEnterBack),onLeaveBack:d(3,e.onLeaveBack)}),n&&a===!1&&n.progress(0),h.start(),t.own(h)}function bg(t,e){const n=i=>i==="labels"?o=>wg(o,e?.labelProgresses?.()??[]):i;if(typeof t!="object"||Array.isArray(t))return n(t);const s=t.ease?Ln(t.ease):void 0;return{snapTo:n(t.snapTo),duration:t.duration,delay:t.delay,ease:s?s.fn??xt(s.easing):void 0}}function wg(t,e){return e.reduce((n,s)=>Math.abs(s-t)<Math.abs(n-t)?s:n,e[0]??t)}function kg(t,e,n,s){const i=()=>e.timeline.getTracks({property:"x"}).map(o=>o.target).filter(o=>{const r=t.elementFor(o);return!!r&&r!==n&&r.contains(n)});return i().length===0&&s("gsap-compat: containerAnimation does not move an ancestor of the trigger along x"),{range:()=>{const o=e.scrollTrigger;return o||s("gsap-compat: containerAnimation needs its own scrollTrigger (created before this one)"),{start:o?.startOffset??0,end:o?.endOffset??0}},progress:()=>e.progress(),shiftAt:o=>{const r=e.timeline.getStateAtTime(o*e.timeline.duration);let a=0;for(const l of i()){const c=r.values.get(l)?.get("x");typeof c=="number"&&(a+=c)}return a}}}class Tc{conditions={};scope;host;items=[];snapshots=new Map;constructor(e,n){this.host=e,this.scope=n}add(e){const n=this.host.collector;this.host.setCollector(this);try{const s=e();return typeof s=="function"&&this.items.push({revert:s}),s}finally{this.host.setCollector(n)}}track(e){this.items.push(e)}touch(e,n){this.snapshots.has(e)||this.snapshots.set(e,{name:n,style:e.getAttribute("style"),d:e.getAttribute("d")})}revert(){for(const e of this.items.splice(0).reverse())e.revert?e.revert():e.kill?e.kill():e.destroy?.();for(const[e,{name:n,style:s,d:i}]of this.snapshots)s===null?e.removeAttribute("style"):e.setAttribute("style",s),i!==null&&e.setAttribute("d",i),this.host.forget(n);this.snapshots.clear()}kill(){this.revert()}}class vg{host;scope;entries=[];listeners=[];scheduled=!1;constructor(e,n){this.host=e,this.scope=n}add(e,n){const s={conditions:e,setup:n,queries:new Map},i=typeof e=="string"?{matches:e}:e;if(typeof window<"u"&&typeof window.matchMedia=="function")for(const[o,r]of Object.entries(i)){const a=window.matchMedia(r);s.queries.set(o,a);const l=()=>this.scheduleUpdate();a.addEventListener("change",l),this.listeners.push(()=>a.removeEventListener("change",l))}return this.entries.push(s),this.update(s),this}revert(){for(const e of this.listeners.splice(0))e();for(const e of this.entries.splice(0))e.context?.revert()}kill(){this.revert()}scheduleUpdate(){this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1;for(const e of this.entries)this.update(e)}))}update(e){const n={};for(const[r,a]of e.queries)n[r]=a.matches;const s=Object.values(n).some(Boolean),i=s?JSON.stringify(n):void 0;if(i===e.key||(e.context?.revert(),e.context=void 0,e.key=i,!s))return;const o=new Tc(this.host,this.scope);o.conditions=n,o.add(()=>e.setup(o)),e.context=o}}class Mg{frames;canvas;context;options;images;ready;current=0;drawn=-1;loadedCount=0;inFlight=0;destroyed=!1;onResize=()=>this.resize();constructor(e,n){this.canvas=e,this.context=e.getContext("2d"),this.options=n,this.frames=Math.max(1,Math.floor(n.frames)),this.images=new Array(this.frames),this.ready=new Array(this.frames).fill(!1),typeof window<"u"&&window.addEventListener("resize",this.onResize,{passive:!0}),this.resize(),this.pump()}get frame(){return this.current}set frame(e){this.current=Math.max(0,Math.min(this.frames-1,e)),this.draw()}get loaded(){return this.loadedCount}destroy(){this.destroyed=!0,typeof window<"u"&&window.removeEventListener("resize",this.onResize);for(const e of this.images)e&&(e.src="")}resize(){const e=typeof window<"u"?Math.min(window.devicePixelRatio||1,2):1,n=Math.round(this.canvas.clientWidth*e),s=Math.round(this.canvas.clientHeight*e);n>0&&s>0&&(this.canvas.width!==n||this.canvas.height!==s)&&(this.canvas.width=n,this.canvas.height=s),this.drawn=-1,this.draw()}draw(){const e=Math.round(this.current),n=this.nearestReady(e);if(n===-1||n===this.drawn||!this.context)return;const s=this.images[n],{width:i,height:o}=this.canvas,r=(this.options.fit??"cover")==="cover"?Math.max(i/s.naturalWidth,o/s.naturalHeight):Math.min(i/s.naturalWidth,o/s.naturalHeight),a=s.naturalWidth*r,l=s.naturalHeight*r;this.context.clearRect(0,0,i,o),this.context.drawImage(s,(i-a)/2,(o-l)/2,a,l),this.drawn=n,this.pump()}nearestReady(e){for(let n=0;n<this.frames;n++){if(e-n>=0&&this.ready[e-n])return e-n;if(e+n<this.frames&&this.ready[e+n])return e+n}return-1}pump(){const e=this.options.concurrency??6,n=Math.round(this.current);for(let s=0;s<this.frames&&this.inFlight<e;s++)for(const i of s===0?[n]:[n+s,n-s])i<0||i>=this.frames||this.images[i]||this.inFlight>=e||this.load(i)}load(e){const n=new Image;n.decoding="async",this.images[e]=n,this.inFlight++;const s=i=>{if(!this.destroyed){if(this.inFlight--,i){this.ready[e]=!0,this.loadedCount++,this.options.onProgress?.(this.loadedCount,this.frames);const o=Math.round(this.current);(Math.abs(e-o)<Math.abs(this.drawn-o)||this.drawn===-1)&&(this.drawn=-1,this.draw())}this.pump()}};n.onload=()=>s(!0),n.onerror=()=>s(!1),n.src=this.options.url(e)}}const Sg={opacity:0,y:-16},Tg={opacity:0,y:16};async function Eg(t,e,n,s){const i=e.collector?.scope??e.root,o=i.ownerDocument??i,r=()=>s.shared?[...i.querySelectorAll(s.shared)]:[];if(s.native&&typeof o.startViewTransition=="function")return Ag(o,s,r);const a=s.duration??.35,l=s.ease??"power2.inOut",c=m=>new Promise(b=>{m(b)||b()}),h=r(),d=h.length?Io(e,h):void 0,u=s.from!==void 0?Ec(e,s.from,s.shared):[];if(u.length&&s.leave!==!1){const m=s.leave??Sg;await c(b=>t.to(u,{...m,duration:a,ease:l,onComplete:b}))}await s.update();const f=[],g=typeof s.to=="function"?s.to():s.to,p=g!==void 0?Ec(e,g,s.shared):[];if(p.length&&s.enter!==!1){const m=s.enter??Tg;f.push(c(b=>t.fromTo(p,m,{...dc(m),duration:a,ease:l,onComplete:b})))}if(d){const m=r().filter(b=>!h.includes(b));m.length&&f.push(c(b=>_o(e,n,d,{targets:m,duration:a*1.4,ease:l,enter:!1,onComplete:b})))}await Promise.all(f)}function Ec(t,e,n){const s=t.resolveTargets(e).map(i=>t.elementFor(i)).filter(i=>!!i);return n?s.flatMap(i=>!i.querySelector(n)&&!i.matches(n)?[i]:[...i.children].filter(o=>!o.matches(n)&&!o.querySelector(n))):s}async function Ag(t,e,n){const s=(a,l)=>{const c=a.dataset?.flipId;c&&a.style.setProperty("view-transition-name",l?`tf-${c.replace(/[^\w-]/g,"-")}`:"")},i=n();i.forEach(a=>s(a,!0));let o=[];await t.startViewTransition(async()=>{i.forEach(a=>s(a,!1)),await e.update(),o=n(),o.forEach(a=>s(a,!0))}).finished,o.forEach(a=>s(a,!1))}const Ac={create:(t,e)=>vo(t,Il(e))},$c={create:(t,e)=>vo(t,{fn:Ol(e)})},Pc={create:(t,e)=>vo(t,{fn:_l(e)})},$g=new Set(["keyframes","duration","delay","ease","easeEach","stagger","repeat","repeatDelay","yoyo","repeatRefresh","paused","id","onStart","onUpdate","onComplete","onRepeat","onReverseComplete","scrollTrigger"]),xc=.5,Pg="power1.inOut";function xg(t){return t.keyframes!==void 0&&t.keyframes!==null}function Ig(t){const e=t.keyframes,n={};for(const[c,h]of Object.entries(t))$g.has(c)||(n[c]=h);if(Array.isArray(e))return e.map(c=>({...n,...c,duration:c.duration??t.duration??xc}));const s=Object.entries(e),i=t.duration??xc,o=e.easeEach??t.easeEach??Pg;if(s.length>0&&s.every(([c])=>/^\s*-?\d+(\.\d+)?\s*%\s*$/.test(c)||c==="easeEach")){const c=s.filter(([u])=>u!=="easeEach").map(([u,f])=>({at:Number.parseFloat(u)/100,step:f})).sort((u,f)=>u.at-f.at),h=[];let d=0;for(const{at:u,step:f}of c){const g=Math.max(0,u-d);h.push({...n,ease:o,...f,duration:g*i}),d=u}return h}const r=s.filter(([c,h])=>c!=="easeEach"&&Array.isArray(h)),a=Math.max(0,...r.map(([,c])=>c.length)),l=[];for(let c=0;c<a;c++){const h={...n,ease:o,duration:i/a};for(const[d,u]of r)c<u.length&&(h[d]=u[c]);l.push(h)}return l}function Ic(t,e,n,s={}){const i=e.collector?.scope??e.root,o=typeof s.scroller=="string"?i.querySelector(s.scroller):s.scroller??null,r={x:o?o.scrollLeft:window.scrollX,y:o?o.scrollTop:window.scrollY},a={x:o?o.scrollWidth-o.clientWidth:document.documentElement.scrollWidth-window.innerWidth,y:o?o.scrollHeight-o.clientHeight:document.documentElement.scrollHeight-window.innerHeight},l=(S,k)=>{if(k===void 0)return r[S];if(typeof k=="number")return k;if(k==="max")return a[S];const y=typeof k=="string"?i.querySelector(k):k;if(!y)return r[S];const M=y.getBoundingClientRect(),$=o?.getBoundingClientRect(),E=(S==="x"?s.offsetX:s.offsetY)??s.offset??0;return S==="x"?M.left-($?.left??0)+r.x-E:M.top-($?.top??0)+r.y-E},c=typeof n=="object"&&n!==null&&!("nodeType"in n)?{x:l("x",n.x),y:l("y",n.y)}:{x:r.x,y:l("y",n)},h={x:Math.max(0,Math.min(a.x,c.x)),y:Math.max(0,Math.min(a.y,c.y))},d={...r},u=()=>{o?(o.scrollLeft=d.x,o.scrollTop=d.y):window.scrollTo({left:d.x,top:d.y,behavior:"instant"})},f=["wheel","touchstart","keydown"],g=o??window,p=()=>{b.kill(),m()},m=()=>{for(const S of f)g.removeEventListener(S,p)},b=t.to(d,{x:h.x,y:h.y,duration:s.duration??1,ease:s.ease??"power2.inOut",onStart:s.onStart,onUpdate:()=>{u(),s.onUpdate?.()},onComplete:()=>{m(),s.onComplete?.()}});if(s.autoKill!==!1)for(const S of f)g.addEventListener(S,p,{passive:!0});return b}function Og(t,e,n){const s=t.collector?.scope??t.root,i=typeof e=="string"?[...s.querySelectorAll(e)]:"nodeType"in e?[e]:Array.from(e),{interval:o=.1,batchMax:r,onEnter:a,onLeave:l,onEnterBack:c,onLeaveBack:h,...d}=n,u={onEnter:a,onLeave:l,onEnterBack:c,onLeaveBack:h},f={onEnter:[],onLeave:[],onEnterBack:[],onLeaveBack:[]},g={},p=b=>{g[b]!==void 0&&clearTimeout(g[b]),g[b]=void 0;const S=f[b].splice(0);S.length>0&&u[b]?.(S)},m=(b,S)=>{if(u[b]){if(f[b].push(S),r!==void 0&&f[b].length>=r)return p(b);g[b]===void 0&&(g[b]=setTimeout(()=>p(b),o*1e3))}};return i.map(b=>Bo(t,{...d,trigger:b,onEnter:()=>m("onEnter",b),onLeave:()=>m("onLeave",b),onEnterBack:()=>m("onEnterBack",b),onLeaveBack:()=>m("onLeaveBack",b)})).filter(b=>b!==void 0)}class Zt{compat;stage;options;autoplayPending;started=!1;killed=!1;recipe=[];firstElement;scrollDriver;events=[];ranges=[];playhead={time:0,iteration:0,direction:"forward",fresh:!0};waitingToWrap=!1;finishedThisFrame=!1;backwards=!1;constructor(e,n={}){this.stage=e;const s={...n,onWarning:n.onWarning??e.onWarning};if(this.options=s,this.compat=new Oe({...s,startValue:(i,o)=>{const r=e.objectFor(i);if(r)return Hg(r[o]);const a=e.appliedValue(i,o);if(a!==void 0)return a;if(o==="d")return ec(e.elementFor(i))??void 0;if(o==="text")return e.elementFor(i)?.textContent??void 0;if(o==="strokeDasharray"||o==="strokeDashoffset"){const l=Rc(e.elementFor(i));if(l!==void 0)return o==="strokeDasharray"?[l,l]:0}},startVelocity:(i,o)=>e.velocityOf(i,o),layoutColumns:i=>Hc(i.map(o=>e.elementFor(o))),random:()=>e.utils.random(0,1)}),this.compat.timeline.onComplete=()=>{this.finishedThisFrame=!0},e.collector?.track(this),e.liveTimelines.add(this),this.autoplayPending=!s.paused&&!s.scrollTrigger,s.scrollTrigger){const i=s.scrollTrigger;queueMicrotask(()=>{this.killed||(this.scrollDriver=Bo(e,i,this,this.firstElement,o=>s.onWarning?.(o)))})}this.autoplayPending&&queueMicrotask(()=>{this.autoplayPending&&this.play()})}get timeline(){return this.compat.timeline}get scrollTrigger(){return this.scrollDriver}to(e,n,s){return xg(n)?this.record(()=>this.keyframed(e,n,s)):this.record(()=>this.tween(e,[n],s,([i],o,r)=>this.compat.to(o,i,r)))}from(e,n,s){return this.record(()=>this.tween(e,[n],s,([i],o,r)=>this.compat.from(o,i,r)))}fromTo(e,n,s,i){return this.record(()=>this.tween(e,[n,s],i,([o,r],a,l)=>this.compat.fromTo(a,o,r,l)))}set(e,n,s){return this.record(()=>this.tween(e,[n],s,([i],o,r)=>this.compat.set(o,i,r)))}addLabel(e,n){return this.record(()=>this.compat.addLabel(e,n))}add(e,n){return this.record(()=>{e.autoplayPending=!1,e.timeline.stop(),e.stage.deactivate(e.timeline),this.compat.add(e.compat,n)})}invalidate(){const e=this.compat.progress();this.compat.progress(0),this.stage.render(this.timeline),this.compat.reset(),this.events=[],this.ranges=[];for(const n of this.recipe)n();return this.syncDuration(),this.compat.progress(e),this.stage.render(this.timeline),this}call(e,n=[],s){return this.record(()=>{const i=this.compat.addEvent(s);this.events.push({time:i,run:()=>e(...n)})})}addPause(e,n,s=[]){return this.record(()=>{const i=this.compat.addEvent(e);this.events.push({time:i,pause:!0,run:()=>n?.(...s)})})}tweenTo(e,n={}){return this.tweenFromTo(this.timeline.currentTime/1e3,e,n)}tweenFromTo(e,n,s={}){this.pause(),this.seek(e);const i=this.timeline.currentTime,o=Math.max(0,Math.min(this.timeline.duration,this.compat.timeOf(n))),r={time:i},a=s.duration??Math.abs(o-i)/1e3/(this.timeScale()||1),l=new Zt(this.stage,{onStart:s.onStart,onComplete:s.onComplete});return l.to(r,{time:o,duration:a,ease:s.ease??"none",onUpdate:()=>{this.moveTo(r.time),s.onUpdate?.()}}),l}play(){this.autoplayPending=!1,this.started||(this.started=!0,this.options.onStart?.());const e=this.timeline.playbackState==="playing",n=this.timeline.playbackState==="paused";if(this.timeline.play(),!e){const s=this.timeline,i=s.direction==="forward"?s.currentTime===0:s.currentTime===s.duration;this.playhead={...this.readPlayhead(),fresh:i&&!n},this.waitingToWrap=!1}return this.stage.liveTimelines.add(this),this.stage.render(this.timeline),this.stage.activate(this.timeline,{onUpdate:()=>this.afterFrame()}),this}pause(){return this.autoplayPending=!1,this.timeline.pause(),this.stage.deactivate(this.timeline),this}resume(){return this.play()}restart(){return this.timeline.stop(),this.backwards=!1,this.play()}reverse(){this.backwards=!this.backwards;const e=this.timeline.playbackState==="idle"&&this.timeline.direction==="forward";return this.timeline.reverse(),e&&this.timeline.currentTime===0&&this.timeline.seek(this.timeline.duration),this.play()}labelProgresses(){const e=this.timeline.duration;return e>0?this.compat.labelTimes().map(n=>n/e):[]}reversed(){return this.timeline.direction==="reverse"}seek(e){return this.autoplayPending=!1,this.compat.seek(e),this.stage.render(this.timeline),this.playhead=this.readPlayhead(),this.waitingToWrap=!1,this.options.onUpdate?.(),this}progress(e){return e===void 0?this.compat.progress():(this.autoplayPending=!1,this.moveTo(Math.max(0,Math.min(1,e))*this.timeline.duration),this.compat.progress())}timeScale(e){return this.compat.timeScale(e)}duration(){return this.compat.duration()}isActive(){return this.timeline.playbackState==="playing"}kill(){return this.killed=!0,this.stage.liveTimelines.delete(this),this.scrollDriver?.destroy(),this.scrollDriver=void 0,this.autoplayPending=!1,this.timeline.stop(),this.stage.deactivate(this.timeline),this.compat.kill(),this}toDefinition(){return this.compat.toDefinition()}killTweensOf(e,n){for(const s of e)for(const i of n??[void 0])this.timeline.removeTracks({target:s,...i!==void 0&&{property:i}});this.timeline.tracks.length===0&&this.events.length===0&&this.kill()}record(e){return this.recipe.push(e),e(),this.syncDuration(),this}syncDuration(){if(this.events.length===0)return;this.timeline.setDuration(void 0);const e=Math.max(...this.events.map(n=>n.time));e>this.timeline.duration&&this.timeline.setDuration(e)}readPlayhead(){const e=this.timeline;return{time:e.currentTime,iteration:e.loopIteration,direction:e.direction}}moveTo(e){const n=this.playhead;this.timeline.seek(e),this.stage.render(this.timeline);const s={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:e>=n.time?"forward":"reverse"},i={...n,iteration:s.iteration,direction:s.direction};this.playhead={...this.readPlayhead()},this.waitingToWrap=!1,this.runCrossings(i,s,!1),this.options.onUpdate?.()}refreshForRepeat(){const e=this.timeline.currentTime;this.compat.reset(),this.events=[],this.ranges=[];for(const n of this.recipe)n();this.syncDuration(),this.timeline.seek(Math.min(e,this.timeline.duration))}afterFrame(){const e=this.timeline,n=e.repeatDelayRemaining>0;if(this.waitingToWrap&&n){this.options.onUpdate?.();return}this.waitingToWrap=!1;const s=this.playhead,i=this.readPlayhead();this.playhead=i;const o=this.options.yoyo===!0;n&&!o&&i.iteration>s.iteration&&(this.playhead={time:0,iteration:i.iteration,direction:"forward",fresh:!0},this.waitingToWrap=!0);const r=this.runCrossings(s,i,n);if(this.options.onUpdate?.(),this.finishedThisFrame&&!r){this.finishedThisFrame=!1;const a=e.currentTime===0&&e.direction==="reverse";!this.scrollDriver&&!o&&this.stage.liveTimelines.delete(this),a&&this.backwards?this.options.onReverseComplete?.():this.options.onComplete?.()}this.finishedThisFrame=!1}runCrossings(e,n,s){if(this.events.length===0&&this.ranges.length===0&&!this.options.onRepeat&&!this.options.repeatRefresh)return!1;const i=this.events,{crossings:o,passes:r}=fo(i.map(a=>a.time),e,n,{duration:this.timeline.duration,alternate:this.options.yoyo===!0,holding:s});for(const a of o){if(this.killed)return!0;if(a.kind==="repeat"){this.options.repeatRefresh&&this.refreshForRepeat(),this.options.onRepeat?.();continue}const l=i[a.index];if(!(l.direction&&l.direction!==a.direction)){if(l.pause)return this.timeline.seek(l.time),this.stage.render(this.timeline),this.pause(),this.playhead=this.readPlayhead(),this.waitingToWrap=!1,l.run(),!0;l.run()}}for(const a of this.ranges)r.some(([c,h])=>c!==h&&Math.max(c,h)>=a.start&&Math.min(c,h)<=a.end)&&a.run();return!1}tween(e,n,s,i){const o=this.resolve(e);if(!o)return;const{onStart:r,onUpdate:a,onComplete:l}=n[n.length-1];if(r||a||l){let c=1/0,h=-1/0;const d=(u,f,g)=>{i(u,f,g),c=Math.min(c,this.compat.lastStart),h=Math.max(h,this.compat.lastEnd)};if(this.buildTween(o,n,s,d),c===1/0)return;r&&this.events.push({time:c,direction:"forward",run:r}),a&&this.ranges.push({start:c,end:h,run:a}),l&&this.events.push({time:h,direction:"forward",run:l});return}this.buildTween(o,n,s,i)}keyframed(e,n,s){const i=this.resolve(e);if(!i)return;const o=Ig(n);if(o.length===0)return;const r=i.length>1?To(n.stagger,this.staggerContext(i)):void 0,a=i.map(m=>this.targetFor(m)).filter(m=>m!==void 0),l=r?a.map(m=>[m]):[a],c=r?ms(i.length,r).map(m=>m/1e3):[0],h=this.compat.timeOf(s)/1e3+Rs(n.delay,0)/1e3;let d=1/0,u=-1/0;if(l.forEach((m,b)=>{o.forEach((S,k)=>{const y=k===0?h+c[b]:">";this.tween(m,[S],y,([M],$,E)=>this.compat.to($,M,E)),d=Math.min(d,this.compat.lastStart),u=Math.max(u,this.compat.lastEnd)})}),d===1/0)return;const{onStart:f,onUpdate:g,onComplete:p}=n;f&&this.events.push({time:d,direction:"forward",run:f}),g&&this.ranges.push({start:d,end:u,run:g}),p&&this.events.push({time:u,direction:"forward",run:p})}staggerContext(e){return{count:e.length,columnsFromLayout:()=>Hc(e.map(n=>this.stage.elementFor(n))),random:()=>this.stage.utils.random(0,1)}}buildTween(e,n,s,i){const o=e.map(u=>this.targetFor(u));if(!(e.length>1&&(n.some(Cg)||e.some(u=>this.stage.objectFor(u)!==void 0)))){const u=this.targetFor(e[0]);i(n.map(f=>this.prepare(Cc(f,0,u,this.stage.utils,o),e)),e,s);return}const a=n.length-1,{stagger:l,...c}=n[a],h=To(l,this.staggerContext(e)),d=h?ms(e.length,h).map(u=>u/1e3):e.map(()=>0);e.forEach((u,f)=>{const g=f===0?Rs(c.delay,0)/1e3+d[0]:0,p=f===0?0:d[f]-d[f-1],m=f===0?s:`<${p<0?"-":"+"}${Math.abs(p).toFixed(6)}`,S=n.map((k,y)=>y===a?{...c,delay:g}:k).map(k=>this.prepare(Cc(k,f,this.targetFor(u),this.stage.utils,o),[u]));i(S,[u],m)})}targetFor(e){return this.stage.elementFor(e)??this.stage.objectFor(e)}prepare(e,n){const s=r=>this.options.onWarning?.(r),i=r=>this.stage.query(r);let o=e;if(e.motionPath!==void 0){const r=Yp(e.motionPath,{query:i,targets:n.map(a=>this.stage.elementFor(a)).filter(a=>!!a),warn:s});o={...o,motionPath:r}}if(e.morphSVG!==void 0){const r=zp(e.morphSVG,i,s),{morphSVG:a,...l}=o;o=r?{...o,morphSVG:r}:l}if(e.drawSVG!==void 0){const r=Rc(this.stage.elementFor(n[0]));if(r===void 0){s("gsap-compat: drawSVG needs an SVG shape with a stroke (path, line, circle…)");const{drawSVG:a,...l}=o;o=l}else o=bp(o,r)}return o}resolve(e){const n=this.stage.resolveTargets(e);if(n.length===0){this.options.onWarning?.(`gsap-compat: no elements found for target ${Rg(e)}`);return}return this.firstElement??=n.map(s=>this.stage.elementFor(s)).find(s=>s!==void 0),n}}function Oc(t=new Jl){const e=o=>{const{config:r}=Hs(o);return new Zt(t,{repeat:r.repeat,yoyo:r.yoyo,repeatDelay:r.repeatDelay,paused:r.paused,onStart:r.onStart,onUpdate:r.onUpdate,onComplete:r.onComplete,onRepeat:r.onRepeat,onReverseComplete:r.onReverseComplete,repeatRefresh:r.repeatRefresh,scrollTrigger:r.scrollTrigger})},n=o=>{const{onStart:r,onUpdate:a,onComplete:l,onRepeat:c,onReverseComplete:h,repeatRefresh:d,...u}=o;return u},s=o=>(o&&t.collector?.track(o),o),i={stage:t,ticker:t.ticker,utils:t.utils,getProperty:(o,r)=>{const[a]=t.resolveTargets(o);if(a===void 0)return;const l=t.objectFor(a);return l?l[r]:t.appliedValue(a,r)??zl(r)},scrollTrigger:o=>s(Bo(t,o)),scrollBatch:(o,r)=>Og(t,o,r).map(a=>s(a)),scrollTo:(o,r)=>Ic(i,t,o,r),refreshScroll:()=>{Fn.refreshAll(),Fo.refreshAll()},smoothScroll:(o={})=>{const r=typeof o.scroller=="string"?(t.collector?.scope??t.root).querySelector(o.scroller):o.scroller;return s(new Fo({...o,scroller:r}).start())},context:(o,r)=>{const a=new Tc(t,r);return o&&a.add(()=>o(a)),a},matchMedia:o=>new vg(t,o),customEase:Ac.create,customBounce:$c.create,customWiggle:Pc.create,pageTransition:o=>Eg(i,t,r=>new Zt(t,r),o),imageSequence:(o,r)=>{const a=typeof o=="string"?(t.collector?.scope??t.root).querySelector(o):o;if(!(a instanceof HTMLCanvasElement))throw new Error(`gsap-compat: imageSequence needs a <canvas>, got ${String(o)}`);return s(new Mg(a,r))},quickTo:(o,r,a={})=>{const l=new Zt(t,{paused:!0}),[c]=t.resolveTargets(o);return Object.assign(d=>{if(!c)return;const u=a.spring!==void 0?t.velocityOf(c,r)??0:0;l.compat.reset(),l.compat.to(c,{[r]:d,duration:a.duration??.4,ease:a.ease??"power3.out",...a.spring!==void 0&&{spring:_g(a.spring,r,u)}}),l.timeline.stop(),l.timeline.play(),t.activate(l.timeline)},{tween:l,kill:()=>l.kill()})},timeline:o=>new Zt(t,o),to:(o,r)=>{if(r.scrollTo!==void 0){const{scrollTo:a,...l}=r,c=typeof a=="object"&&a!==null&&!("nodeType"in a)?a:{},h=typeof o!="string"&&o!==window&&o.nodeType===1;return Ic(i,t,a,{...l,offsetX:c.offsetX,offsetY:c.offsetY,scroller:h?o:void 0})}return e(r).to(o,n(r))},from:(o,r)=>e(r).from(o,n(r)),fromTo:(o,r,a)=>e(a).fromTo(o,r,n(a)),set:(o,r)=>e(r).set(o,n(r)),delayedCall:(o,r,a)=>new Zt(t).call(r,a,o),killTweensOf:(o,r)=>{const a=t.resolveTargets(o),l=typeof r=="string"?r.split(",").map(c=>c.trim()).filter(Boolean):r;for(const c of[...t.liveTimelines])c.killTweensOf(a,l)},convertToPath:o=>Up(o,t.root),splitText:(o,r)=>{const a=t.collector?.scope??t.root,l=typeof o=="string"?Array.from(a.querySelectorAll(o)):"nodeType"in o?[o]:Array.from(o);return s(ng(l,r))},draggable:(o,r)=>s(Zp(i,t,o,r)),getFlipState:o=>Io(t,o),flipFrom:(o,r)=>_o(t,a=>new Zt(t,a),o,r),flip:(o,r,a)=>{const l=Io(t,o);return r(),_o(t,c=>new Zt(t,c),l,{targets:o,...a})}};return i}const Lt=Oc();function _g(t,e,n){return t===!0?{velocity:{[e]:n}}:typeof t=="string"?{preset:t,velocity:{[e]:n}}:{...t,velocity:{[e]:n}}}function Cg(t){return t.morphSVG!==void 0||t.drawSVG!==void 0||t.text!==void 0||t.scrambleText!==void 0||_c(t)}function _c(t){return Object.entries(t).some(([e,n])=>(typeof n=="function"||Kl(n))&&!So.has(e))}function Cc(t,e,n,s,i){if(!_c(t))return t;const o={};for(const[r,a]of Object.entries(t))So.has(r)?o[r]=a:typeof a=="function"?o[r]=a(e,n,i):Kl(a)?o[r]=s.resolveRandomString(a):o[r]=a;return o}function Hc(t){const e=t.map(s=>s?.getBoundingClientRect().top);if(e[0]===void 0)return t.length;let n=0;for(const s of e){if(s===void 0||Math.abs(s-e[0])>1)break;n++}return Math.max(1,n)}function Rc(t){const e=t;if(typeof e?.getTotalLength=="function")return e.getTotalLength()}function Hg(t){if(typeof t=="number"||typeof t=="string"||Array.isArray(t)&&t.every(e=>typeof e=="number"))return t}function Rg(t){return typeof t=="string"?`"${t}"`:String(t)}class Wo{media;offset;driftTolerance;constructor(e,n={}){this.media=e,this.offset=n.offset??0,this.driftTolerance=Math.max(0,n.driftTolerance??.15)}targetTime(e){return Math.max(0,e/1e3+this.offset)}update(e,n){const s=this.targetTime(e);n?(this.media.paused&&this.safePlay(),Math.abs(this.media.currentTime-s)>this.driftTolerance&&(this.media.currentTime=s)):(this.media.paused||this.media.pause(),this.media.currentTime!==s&&(this.media.currentTime=s))}seek(e){this.media.currentTime=this.targetTime(e)}setRate(e){this.media.playbackRate=e}dispose(){this.media.paused||this.media.pause()}safePlay(){const e=this.media.play();e&&typeof e.catch=="function"&&e.catch(()=>{})}}function Lc(t,e,n,s,i){const o=n-i;if(o<0){e.paused||e.pause(),e.currentTime=0;return}t.update(o,s)}class Ds{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(e,n={}){if(typeof e=="string"){const s=document.querySelector(e);if(!s)throw new Error(`Container not found: ${e}`);this.container=s}else this.container=e;this.options=n,this.adapter=new _e}async load(e){this.scenarioList=[],this.scenarioId=void 0,await this.loadSource(e)}async loadSource(e){let n;if(typeof e=="string"){const s=await fetch(e);if(!s.ok)throw new Error(`Failed to load animation: ${s.statusText}`);n=await s.json()}else n=e;this.useDefinition(n),this.showInitialFrame(),this.watchReducedMotion(),this.watchVisibility(),this.options.autoplay&&!this.reducedMotion&&(this.options.playWhenVisible&&!this.onScreen?this.autoplayWhenSeen=!0:this.play())}useDefinition(e){const n={...e.config};this.options.speed!==void 0&&(n.speed=this.options.speed),this.options.loop!==void 0&&(n.loop=this.options.loop),this.options.alternate!==void 0&&(n.alternate=this.options.alternate),this.timeline=Qe({...e,config:n}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(e,n={}){if(e.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const s=new Set;for(const o of e){if(s.has(o.id))throw new Error(`tinyfly: scenario id "${o.id}" is used more than once`);s.add(o.id)}const i=n.initial===void 0?e[0]:e.find(o=>o.id===n.initial);if(!i)throw new Error(`tinyfly: there is no scenario "${n.initial}"`);this.scenarioList=[...e],this.scenarioId=i.id,await this.loadSource(i.timeline)}get scenarios(){return this.scenarioList.map(e=>({id:e.id,label:e.label??e.id}))}get scenario(){return this.scenarioId}setScenario(e){const n=this.scenarioList.find(a=>a.id===e);if(!n||!this.timeline)return!1;if(e===this.scenarioId)return!0;const s=this.isPlaying,i=this.currentTime>=this.duration-.5,o=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=e,this.useDefinition(n.timeline),this.lastMarkerId=null;let r=0;return this.reducedMotion||i?r=this.duration:o!==void 0&&(r=this.markers.find(a=>a.id===o)?.time??0),this.seek(r),s&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(e){if(this.authored.has(e))return;const n={style:e.getAttribute("style")};e.children.length===0&&(n.text=e.textContent??"");const s=e.tagName.toLowerCase()==="path"?e:e.querySelector("path");s&&(n.path={element:s,d:s.getAttribute("d")}),this.authored.set(e,n)}restoreAuthored(){for(const[e,n]of this.authored){n.style===null?e.removeAttribute("style"):e.setAttribute("style",n.style),n.text!==void 0&&e.textContent!==n.text&&(e.textContent=n.text),n.path&&(n.path.d===null?n.path.element.removeAttribute("d"):n.path.element.setAttribute("d",n.path.d));const s=e.dataset;s&&delete s.shineBase}}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){for(const e of this.listeners)e()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const e=this.currentTime;let n;for(const s of this.markers)if(s.time<=e+.5)n=s;else break;return n}caption(e,n){const s=e?this.markers.find(r=>r.id===e):this.currentMarker;if(!s)return;const i=n??this.language(),o=r=>r?.[i]?.[s.id]??r?.[i.split("-")[0]]?.[s.id];return o(this.options.captions)??o(this.timeline?.captions)??s.label}next(){if(!this.timeline)return;const e=this.currentTime,n=this.markers.find(s=>s.time>e+.5);if(this.reducedMotion){this.seek(n?n.time:this.duration);return}e>=this.duration-.5||(this.stepping=n!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const e=this.currentTime,n=[...this.markers].reverse().find(s=>s.time<e-.5);this.pause(),this.seek(n?n.time:0)}goToMarker(e){const n=this.markers.find(s=>s.id===e);n&&(this.pause(),this.seek(n.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const e=this.options.initialFrame??"start";if(e==="none")return;const n=e==="end"?this.timeline.duration:e==="start"?0:e;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,n))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(n=>{for(const s of n)this.onScreen=s.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const e=this.container.getBoundingClientRect?.();e&&(e.width>0||e.height>0)&&(this.onScreen=e.bottom>0&&e.top<window.innerHeight&&e.right>0&&e.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const e=this.onScreen&&document.visibilityState!=="hidden";!e&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):e&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const e=this.currentMarker,n=e?.id;n!==this.lastMarkerId&&(this.lastMarkerId=n,this.options.onMarker(e))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(n=>{const s=n,i=Number(s.getAttribute("data-tinyfly-start")??"0")||0,o=s.getAttribute("data-volume");o!==null&&(s.volume=Math.max(0,Math.min(1,Number(o)||0))),this.mediaTargets.push({el:s,startTime:i,sync:new Wo(s)})})}syncAllMedia(e,n){for(const s of this.mediaTargets)Lc(s.sync,s.el,e,n,s.startTime)}loadFromString(e){const n=JSON.parse(e);this.load(n)}registerTarget(e,n){if(typeof n=="string"){const s=this.container.querySelector(n);s&&(this.rememberAuthored(s),this.targets[e]=s,this.adapter.registerTarget(e,s))}else this.rememberAuthored(n),this.targets[e]=n,this.adapter.registerTarget(e,n)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(n=>{const s=n.closest("[data-tinyfly-symbol]");if(s&&s!==n)return;const i=n.getAttribute("data-tinyfly");i&&this.registerTarget(i,n)}),this.timeline&&new Set(this.timeline.tracks.map(s=>s.target)).forEach(s=>{if(!this.targets[s]){const i=this.container.querySelector(`[data-tinyfly="${s}"]`)||this.container.querySelector(`.${s}`)||this.container.querySelector(`#${s}`);i&&this.registerTarget(s,i)}})}setupSymbolInstances(){this.symbolInstances=[];const e=this.options.symbols;if(!e||e.length===0)return;const n=new Map(e.map(s=>[s.id,s]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const i=s.getAttribute("data-tinyfly-symbol");if(!i)return;const o=n.get(i);if(!o||!o.timeline.tracks?.length)return;const r=new _e;s.querySelectorAll("[data-tinyfly]").forEach(a=>{const l=a.getAttribute("data-tinyfly");l&&r.registerTarget(l,a)}),this.symbolInstances.push({adapter:r,timeline:Qe(o.timeline)})})}attachMedia(e,n){this.mediaSync=new Wo(e,n),this.timeline&&(this.mediaSync.setRate(this.timeline.speed),this.mediaSync.update(this.timeline.currentTime,this.isPlaying))}detachMedia(){this.mediaSync?.dispose(),this.mediaSync=void 0}play(){!this.timeline||this.isDestroyed||(this.autoplayWhenSeen=!1,this.stepping=this.options.stepMode===!0,this.startPlaying())}startPlaying(){if(!this.timeline||this.isDestroyed)return;const e=this.timeline.playbackState==="idle";this.timeline.play(),e&&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(e){this.timeline&&(this.timeline.seek(e),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(e){this.timeline&&(this.timeline.speed=e,this.mediaSync?.setRate(e))}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 e of this.mediaTargets)e.el.paused||e.el.pause();this.mediaTargets=[],this.adapter.clearTargets();for(const e of this.symbolInstances)e.adapter.clearTargets();this.symbolInstances=[],this.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const e=n=>{if(this.isDestroyed||!this.timeline)return;const s=n-(this.lastTime??n);this.lastTime=n;const i=this.playhead;this.timeline.tick(s),this.stopAtMarker(i),this.applyState();const o=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,o),this.syncAllMedia(this.timeline.currentTime,o),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(e):(this.animationFrameId=void 0,this.notify())};this.animationFrameId=requestAnimationFrame(e)}stopAtMarker(e){const n=this.timeline,s={time:n.currentTime,iteration:n.loopIteration,direction:n.direction};this.playhead=s;const i=this.markers;if(i.length===0)return;const{crossings:o}=fo(i.map(r=>r.time),e,s,{duration:n.duration,alternate:n.config.alternate===!0,holding:n.repeatDelayRemaining>0});for(const r of o){if(r.kind!=="event")continue;const a=i[r.index];if(this.stepping||a.pause){this.stepping=!1,n.pause(),n.seek(a.time),this.playhead={time:a.time,iteration:n.loopIteration,direction:n.direction};return}}}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}applyState(){if(!this.timeline)return;const e=this.timeline.currentTime;this.adapter.applyState(this.timeline.getStateAtTime(e)),this.announceMarker(),this.notify();for(const n of this.symbolInstances){const s=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(s>0?e%s:e))}}}async function Lg(t,e,n={}){const s=new Ds(t,{...n,autoplay:!0});return await s.load(e),s}function Ng(t,e={}){return new Ds(t,e)}const Nc={play:"Play",pause:"Pause",prev:"Previous step",next:"Next step",restart:"Restart",scrub:"Position",speed:"Speed",reveal:"Reveal",step:"Step",of:"of",stepFormat:"{index} / {total}",scenario:"Scenario",fullscreen:"Full screen",exitFullscreen:"Exit full screen"},Dc="tinyfly-controls-style",Dg=`
3
3
  .tf-ctl { --tf-ctl-fg: #1d1d1f; --tf-ctl-bg: #f4f2ee; --tf-ctl-accent: #c2410c; --tf-ctl-radius: 8px;
4
4
  font: 14px/1.4 var(--tf-ctl-font, system-ui, sans-serif); color: var(--tf-ctl-fg); margin-top: 8px; }
5
5
  .tf-ctl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px; border-radius: var(--tf-ctl-radius); background: var(--tf-ctl-bg); }
@@ -47,18 +47,20 @@
47
47
  .tf-fullscreen > svg, .tf-fullscreen > canvas { grid-column: 1; grid-row: 1 / span 12; height: calc(100vh - 24px) !important; height: calc(100dvh - 24px) !important; }
48
48
  .tf-fullscreen > :not(svg):not(canvas) { grid-column: 2; }
49
49
  }
50
- `;let ug=0;function dg(t){if(t.getElementById(mc))return;const e=t.createElement("style");e.id=mc,e.textContent=hg,t.head.appendChild(e)}function yc(t,e,n={}){const s=e.ownerDocument;dg(s);const i={...gc,...n.labels},o=n.speeds??[.5,1,2],r=()=>t.markers.length>0,a=()=>t.markers.some(L=>L.label!==void 0||t.caption(L.id)!==void 0),l=s.createElement("div");l.className="tf-ctl";const c=s.createElement("div");c.className="tf-ctl-bar",c.setAttribute("role","group");const h=(L,N,Y,j="")=>{const U=s.createElement("button");return U.type="button",U.className=`tf-ctl-btn ${j}`.trim(),U.setAttribute("aria-label",L),U.title=L,U.textContent=N,U.addEventListener("click",Y),U},u=h(i.restart,"⟲",()=>{t.pause(),t.seek(0)}),d=h(i.prev,"|◀",()=>t.prev()),f=h(i.play,"▶",()=>t.isPlaying?t.pause():p(),"tf-ctl-primary"),g=h(i.next,"▶|",()=>t.next()),p=()=>{t.currentTime>=t.duration-.5&&t.seek(0),t.play()},m=s.createElement("input");m.type="range",m.className="tf-ctl-scrub",m.min="0",m.max="1000",m.step="1",m.setAttribute("aria-label",i.scrub),m.addEventListener("input",()=>{t.pause(),t.seek(Number(m.value)/1e3*t.duration)});const b=s.createElement("span");b.className="tf-ctl-step";const k=s.createElement("select");k.className="tf-ctl-speed",k.setAttribute("aria-label",i.speed);for(const L of o){const N=s.createElement("option");N.value=String(L),N.textContent=`${L}×`,L===1&&(N.selected=!0),k.appendChild(N)}k.addEventListener("change",()=>t.setSpeed(Number(k.value))),c.append(u,d,f,g,m,b),o.length>0&&c.append(k),l.append(c);const w=n.fullscreen?mg(e,s,i):void 0;w&&c.append(w.button);const M=s.createElement("p");M.className="tf-ctl-caption",M.setAttribute("aria-live","polite"),n.captions!==!1&&l.append(M);const S=s.createElement("div");S.className="tf-ctl-question",S.hidden=!0;const A=s.createElement("span"),E=h(i.reveal,i.reveal,()=>t.play(),"tf-ctl-primary");S.append(A,E),l.append(S);const $=fg(t,s,i.scenario,n.scenarioControl??"buttons");$&&l.append($.element);const v=n.mount;v?v.appendChild(l):e.insertAdjacentElement("afterend",l);const O=()=>{const L=t.isPlaying;f.textContent=L?"❚❚":"▶",f.setAttribute("aria-label",L?i.pause:i.play),f.title=L?i.pause:i.play;const N=t.duration;s.activeElement!==m&&(m.value=String(N>0?Math.round(t.currentTime/N*1e3):0));const Y=t.markers;if(d.hidden=g.hidden=b.hidden=Y.length===0,Y.length>0){const j=t.currentMarker,U=j?Y.indexOf(j)+1:0;b.textContent=i.stepFormat.replace("{index}",String(U)).replace("{total}",String(Y.length)),b.setAttribute("aria-label",`${i.step} ${U} ${i.of} ${Y.length}`),d.disabled=t.currentTime<=.5,g.disabled=t.currentTime>=N-.5;const J=t.caption()??"";M.textContent!==J&&(M.textContent=J),M.hidden=!a();const P=!L&&j?.question!==void 0&&Math.abs(t.currentTime-j.time)<1;S.hidden=!P,P&&A.textContent!==j.question&&(A.textContent=j.question)}else S.hidden=!0,M.hidden=!0;$?.update()},x=t.subscribe(O);O();const _=n.keyboardScope??e;!_.hasAttribute("tabindex")&&_.tabIndex<0&&(_.tabIndex=0);const F=new WeakSet,I=L=>{if(F.has(L)||(F.add(L),L.defaultPrevented||L.altKey||L.ctrlKey||L.metaKey))return;const N=L.target;if(!(N.tagName==="INPUT"||N.tagName==="SELECT")&&!(L.key===" "&&N.tagName==="BUTTON"))switch(L.key){case" ":L.preventDefault(),t.isPlaying?t.pause():p();break;case"ArrowRight":if(!r())return;L.preventDefault(),t.next();break;case"ArrowLeft":if(!r())return;L.preventDefault(),t.prev();break;case"Home":L.preventDefault(),t.pause(),t.seek(0);break;case"f":case"F":if(!w)return;L.preventDefault(),w.active?w.exit():w.enter();break}};return _.addEventListener("keydown",I),l.addEventListener("keydown",I),{element:l,fullscreen:w&&{get active(){return w.active},enter:w.enter,exit:w.exit},destroy(){w?.destroy(),x(),_.removeEventListener("keydown",I),l.removeEventListener("keydown",I),l.remove()}}}function fg(t,e,n,s){const i=t.scenarios;if(i.length<2)return;if(s==="slider"){const h=e.createElement("div");h.className="tf-ctl-choice-slider";const u=e.createElement("span");u.textContent=n,u.setAttribute("aria-hidden","true");const d=e.createElement("input");d.type="range",d.min="0",d.max=String(i.length-1),d.step="1",d.setAttribute("aria-label",n);const f=e.createElement("output");return f.setAttribute("aria-hidden","true"),d.addEventListener("input",()=>{const p=i[Number(d.value)];p&&t.setScenario(p.id)}),h.append(u,d,f),{element:h,update:()=>{const p=Math.max(0,i.findIndex(b=>b.id===t.scenario));e.activeElement!==d&&(d.value=String(p));const m=i[p].label;f.textContent!==m&&(f.textContent=m),d.setAttribute("aria-valuetext",m)}}}const o=e.createElement("fieldset");o.className="tf-ctl-choices";const r=e.createElement("legend");r.textContent=n,o.append(r);const a=`tf-ctl-scenario-${++ug}`,l=i.map(h=>{const u=e.createElement("label");u.className="tf-ctl-choice";const d=e.createElement("input");d.type="radio",d.name=a,d.value=h.id,d.addEventListener("change",()=>{d.checked&&t.setScenario(h.id)});const f=e.createElement("span");return f.textContent=h.label,u.append(d,f),o.append(u),d});return{element:o,update:()=>{for(const h of l){const u=h.value===t.scenario;h.checked!==u&&(h.checked=u)}}}}const pg='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',gg='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';function mg(t,e,n){const s=e,i=t,o=e.createElement("button");o.type="button",o.className="tf-ctl-btn tf-ctl-fullscreen";let r,a="";const l=()=>{const p=r!==void 0;o.innerHTML=p?gg:pg;const m=p?n.exitFullscreen:n.fullscreen;o.setAttribute("aria-label",m),o.title=m,o.setAttribute("aria-pressed",String(p)),t.classList.toggle("tf-fullscreen",p),t.classList.toggle("tf-fullscreen-overlay",r==="overlay")},c=()=>s.fullscreenElement??s.webkitFullscreenElement??null,h=()=>{c()===t?r="native":r==="native"&&(r=void 0),l()},u=p=>{p.key==="Escape"&&g()},d=()=>{r="overlay",a=e.documentElement.style.overflow,e.documentElement.style.overflow="hidden",e.addEventListener("keydown",u),l()};async function f(){if(r)return;const p=i.requestFullscreen?.bind(i)??i.webkitRequestFullscreen?.bind(i),m=s.fullscreenEnabled??s.webkitFullscreenEnabled??!1;if(p&&m)try{if(await p(),c()===t){r="native",l();return}}catch{}d()}async function g(){if(r==="overlay")e.removeEventListener("keydown",u),e.documentElement.style.overflow=a,r=void 0,l();else if(r==="native"){r=void 0,l();const p=s.exitFullscreen?.bind(s)??s.webkitExitFullscreen?.bind(s);c()===t&&p&&await p()}}return o.addEventListener("click",()=>{r?g():f()}),e.addEventListener("fullscreenchange",h),e.addEventListener("webkitfullscreenchange",h),l(),{button:o,get active(){return r!==void 0},enter:f,exit:g,destroy(){g(),e.removeEventListener("fullscreenchange",h),e.removeEventListener("webkitfullscreenchange",h),o.remove()}}}const bc="tinyfly-choices-style",yg=`
50
+ `;let Fg=0;function jg(t){if(t.getElementById(Dc))return;const e=t.createElement("style");e.id=Dc,e.textContent=Dg,t.head.appendChild(e)}function Fc(t,e,n={}){const s=e.ownerDocument;jg(s);const i={...Nc,...n.labels},o=n.speeds??[.5,1,2],r=()=>t.markers.length>0,a=()=>t.markers.some(C=>C.label!==void 0||t.caption(C.id)!==void 0),l=s.createElement("div");l.className="tf-ctl";const c=s.createElement("div");c.className="tf-ctl-bar",c.setAttribute("role","group");const h=(C,j,D,W="")=>{const B=s.createElement("button");return B.type="button",B.className=`tf-ctl-btn ${W}`.trim(),B.setAttribute("aria-label",C),B.title=C,B.textContent=j,B.addEventListener("click",D),B},d=h(i.restart,"⟲",()=>{t.pause(),t.seek(0)}),u=h(i.prev,"|◀",()=>t.prev()),f=h(i.play,"▶",()=>t.isPlaying?t.pause():p(),"tf-ctl-primary"),g=h(i.next,"▶|",()=>t.next()),p=()=>{t.currentTime>=t.duration-.5&&t.seek(0),t.play()},m=s.createElement("input");m.type="range",m.className="tf-ctl-scrub",m.min="0",m.max="1000",m.step="1",m.setAttribute("aria-label",i.scrub),m.addEventListener("input",()=>{t.pause(),t.seek(Number(m.value)/1e3*t.duration)});const b=s.createElement("span");b.className="tf-ctl-step";const S=s.createElement("select");S.className="tf-ctl-speed",S.setAttribute("aria-label",i.speed);for(const C of o){const j=s.createElement("option");j.value=String(C),j.textContent=`${C}×`,C===1&&(j.selected=!0),S.appendChild(j)}S.addEventListener("change",()=>t.setSpeed(Number(S.value))),c.append(d,u,f,g,m,b),o.length>0&&c.append(S),l.append(c);const k=n.fullscreen?Kg(e,s,i):void 0;k&&c.append(k.button);const y=s.createElement("p");y.className="tf-ctl-caption",y.setAttribute("aria-live","polite"),n.captions!==!1&&l.append(y);const M=s.createElement("div");M.className="tf-ctl-question",M.hidden=!0;const $=s.createElement("span"),E=h(i.reveal,i.reveal,()=>t.play(),"tf-ctl-primary");M.append($,E),l.append(M);const A=Bg(t,s,i.scenario,n.scenarioControl??"buttons");A&&l.append(A.element);const T=n.mount;T?T.appendChild(l):e.insertAdjacentElement("afterend",l);const I=()=>{const C=t.isPlaying;f.textContent=C?"❚❚":"▶",f.setAttribute("aria-label",C?i.pause:i.play),f.title=C?i.pause:i.play;const j=t.duration;s.activeElement!==m&&(m.value=String(j>0?Math.round(t.currentTime/j*1e3):0));const D=t.markers;if(u.hidden=g.hidden=b.hidden=D.length===0,D.length>0){const W=t.currentMarker,B=W?D.indexOf(W)+1:0;b.textContent=i.stepFormat.replace("{index}",String(B)).replace("{total}",String(D.length)),b.setAttribute("aria-label",`${i.step} ${B} ${i.of} ${D.length}`),u.disabled=t.currentTime<=.5,g.disabled=t.currentTime>=j-.5;const _=t.caption()??"";y.textContent!==_&&(y.textContent=_),y.hidden=!a();const L=!C&&W?.question!==void 0&&Math.abs(t.currentTime-W.time)<1;M.hidden=!L,L&&$.textContent!==W.question&&($.textContent=W.question)}else M.hidden=!0,y.hidden=!0;A?.update()},v=t.subscribe(I);I();const P=n.keyboardScope??e;!P.hasAttribute("tabindex")&&P.tabIndex<0&&(P.tabIndex=0);const H=new WeakSet,O=C=>{if(H.has(C)||(H.add(C),C.defaultPrevented||C.altKey||C.ctrlKey||C.metaKey))return;const j=C.target;if(!(j.tagName==="INPUT"||j.tagName==="SELECT")&&!(C.key===" "&&j.tagName==="BUTTON"))switch(C.key){case" ":C.preventDefault(),t.isPlaying?t.pause():p();break;case"ArrowRight":if(!r())return;C.preventDefault(),t.next();break;case"ArrowLeft":if(!r())return;C.preventDefault(),t.prev();break;case"Home":C.preventDefault(),t.pause(),t.seek(0);break;case"f":case"F":if(!k)return;C.preventDefault(),k.active?k.exit():k.enter();break}};return P.addEventListener("keydown",O),l.addEventListener("keydown",O),{element:l,fullscreen:k&&{get active(){return k.active},enter:k.enter,exit:k.exit},destroy(){k?.destroy(),v(),P.removeEventListener("keydown",O),l.removeEventListener("keydown",O),l.remove()}}}function Bg(t,e,n,s){const i=t.scenarios;if(i.length<2)return;if(s==="slider"){const h=e.createElement("div");h.className="tf-ctl-choice-slider";const d=e.createElement("span");d.textContent=n,d.setAttribute("aria-hidden","true");const u=e.createElement("input");u.type="range",u.min="0",u.max=String(i.length-1),u.step="1",u.setAttribute("aria-label",n);const f=e.createElement("output");return f.setAttribute("aria-hidden","true"),u.addEventListener("input",()=>{const p=i[Number(u.value)];p&&t.setScenario(p.id)}),h.append(d,u,f),{element:h,update:()=>{const p=Math.max(0,i.findIndex(b=>b.id===t.scenario));e.activeElement!==u&&(u.value=String(p));const m=i[p].label;f.textContent!==m&&(f.textContent=m),u.setAttribute("aria-valuetext",m)}}}const o=e.createElement("fieldset");o.className="tf-ctl-choices";const r=e.createElement("legend");r.textContent=n,o.append(r);const a=`tf-ctl-scenario-${++Fg}`,l=i.map(h=>{const d=e.createElement("label");d.className="tf-ctl-choice";const u=e.createElement("input");u.type="radio",u.name=a,u.value=h.id,u.addEventListener("change",()=>{u.checked&&t.setScenario(h.id)});const f=e.createElement("span");return f.textContent=h.label,d.append(u,f),o.append(d),u});return{element:o,update:()=>{for(const h of l){const d=h.value===t.scenario;h.checked!==d&&(h.checked=d)}}}}const Wg='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',qg='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';function Kg(t,e,n){const s=e,i=t,o=e.createElement("button");o.type="button",o.className="tf-ctl-btn tf-ctl-fullscreen";let r,a="";const l=()=>{const p=r!==void 0;o.innerHTML=p?qg:Wg;const m=p?n.exitFullscreen:n.fullscreen;o.setAttribute("aria-label",m),o.title=m,o.setAttribute("aria-pressed",String(p)),t.classList.toggle("tf-fullscreen",p),t.classList.toggle("tf-fullscreen-overlay",r==="overlay")},c=()=>s.fullscreenElement??s.webkitFullscreenElement??null,h=()=>{c()===t?r="native":r==="native"&&(r=void 0),l()},d=p=>{p.key==="Escape"&&g()},u=()=>{r="overlay",a=e.documentElement.style.overflow,e.documentElement.style.overflow="hidden",e.addEventListener("keydown",d),l()};async function f(){if(r)return;const p=i.requestFullscreen?.bind(i)??i.webkitRequestFullscreen?.bind(i),m=s.fullscreenEnabled??s.webkitFullscreenEnabled??!1;if(p&&m)try{if(await p(),c()===t){r="native",l();return}}catch{}u()}async function g(){if(r==="overlay")e.removeEventListener("keydown",d),e.documentElement.style.overflow=a,r=void 0,l();else if(r==="native"){r=void 0,l();const p=s.exitFullscreen?.bind(s)??s.webkitExitFullscreen?.bind(s);c()===t&&p&&await p()}}return o.addEventListener("click",()=>{r?g():f()}),e.addEventListener("fullscreenchange",h),e.addEventListener("webkitfullscreenchange",h),l(),{button:o,get active(){return r!==void 0},enter:f,exit:g,destroy(){g(),e.removeEventListener("fullscreenchange",h),e.removeEventListener("webkitfullscreenchange",h),o.remove()}}}const jc="tinyfly-choices-style",Yg=`
51
51
  [data-tinyfly-choose] { cursor: pointer; }
52
52
  [data-tinyfly-choose]:focus-visible { outline: 2px solid var(--tf-ctl-accent, #c2410c); outline-offset: 2px; }
53
- `;function bg(t){if(t.getElementById(bc))return;const e=t.createElement("style");e.id=bc,e.textContent=yg,t.head.appendChild(e)}function wc(t,e){const n=Array.from(e.querySelectorAll("[data-tinyfly-choose]"));if(n.length===0)return()=>{};bg(e.ownerDocument);const s=[],i=[];for(const a of n){const l=a.getAttribute("data-tinyfly-choose")??"",c=[],h=(g,p)=>{a.hasAttribute(g)||(a.setAttribute(g,p),c.push(g))};h("role","button"),h("tabindex","0");const u=t.scenarios.find(g=>g.id===l)?.label;u!==void 0&&h("aria-label",u),a.setAttribute("aria-pressed","false"),c.push("aria-pressed"),s.push({element:a,attributes:c});const d=()=>t.setScenario(l),f=g=>{const p=g.key;p!=="Enter"&&p!==" "||(g.preventDefault(),d())};a.addEventListener("click",d),a.addEventListener("keydown",f),i.push(()=>{a.removeEventListener("click",d),a.removeEventListener("keydown",f)})}const o=()=>{for(const{element:a}of s)a.setAttribute("aria-pressed",String(a.getAttribute("data-tinyfly-choose")===t.scenario))},r=t.subscribe(o);return o(),()=>{r();for(const a of i)a();for(const{element:a,attributes:l}of s)for(const c of l)a.removeAttribute(c)}}const As=new WeakMap,Ao=new WeakMap;let wg=0;function On(t,e,n){if(t)try{return JSON.parse(t)}catch(s){console.warn(`tinyfly: invalid ${e} JSON on`,n,s);return}}async function kc(t,e={}){const n=As.get(t);if(n)return n;const s=Array.from(t.querySelectorAll("script[data-tinyfly-timeline]")),i=s[0],o=t.getAttribute("data-src"),r=vg(t.getAttribute("data-markers")),a=s.length>1||i?.hasAttribute("data-scenario")?kg(s,r,t):void 0;if(a&&a.length===0)return;let l=i&&!a?On(i.textContent,"timeline",t):void 0;if(!l&&o&&r){const f=await fetch(o);f.ok&&(l=await f.json())}if(l&&r&&(l=vc(l,r)),!l&&!o&&!a){console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)',t);return}const c=On(t.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",t),h={playWhenVisible:!0,...e.player,...c&&{captions:c},...On(t.getAttribute("data-options"),"data-options",t)};Sg(t);const u=new Es(t,h),d={element:t,player:u};if(As.set(t,d),t.setAttribute("data-tinyfly-mounted",""),a){const f=t.getAttribute("data-scenario")??void 0;await u.loadScenarios(a,{initial:a.some(g=>g.id===f)?f:void 0}),Ao.set(t,wc(u,t))}else await u.load(l??o);if(t.getAttribute("data-controls")!=="false"){const f=On(t.getAttribute("data-labels"),"data-labels",t),g=t.querySelector("figcaption"),p=t.getAttribute("data-scenario-legend"),m=t.getAttribute("data-scenario-control");d.controls=yc(u,t,{...e.controls,...t.getAttribute("data-fullscreen")==="true"?{fullscreen:!0}:{},...m==="slider"||m==="buttons"?{scenarioControl:m}:{},labels:{...e.controls?.labels,...f,...p?{scenario:p}:{}},mount:void 0}),g?t.insertBefore(d.controls.element,g):t.appendChild(d.controls.element)}return d}function kg(t,e,n){const s=[];return t.forEach((i,o)=>{const r=On(i.textContent,"timeline",n);if(!r)return;const a=i.getAttribute("data-scenario")||`scenario-${o+1}`;if(s.some(c=>c.id===a)){console.warn(`tinyfly: scenario id "${a}" is used more than once; the later one is skipped`,n);return}const l=i.getAttribute("data-scenario-label")??void 0;s.push({id:a,label:l,timeline:e?vc(r,e):r})}),s}function vc(t,e){return t.config.markers?.length?t:{...t,config:{...t.config,markers:e.map((n,s)=>({id:`step-${s+1}`,time:n}))}}}function vg(t){if(!t)return;const e=t.split(/[\s,]+/).filter(Boolean).map(Number).filter(n=>Number.isFinite(n)&&n>=0).sort((n,s)=>n-s);return e.length>0?e:void 0}async function Mc(t=document,e={}){const n=Array.from(t.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(n.map(i=>kc(i,e)))).filter(i=>i!==void 0)}function Mg(t){const e=As.get(t);e&&(Ao.get(t)?.(),Ao.delete(t),e.controls?.destroy(),e.player.destroy(),As.delete(t),t.removeAttribute("data-tinyfly-mounted"))}function Sg(t){const e=t.querySelector("svg");if(!e||e.hasAttribute("role")||e.hasAttribute("aria-hidden"))return;const n=t.getAttribute("data-alt"),s=t.querySelector("figcaption");e.setAttribute("role","img"),n?e.setAttribute("aria-label",n):s&&(s.id||=`tinyfly-caption-${++wg}`,e.setAttribute("aria-labelledby",s.id))}function Tg(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const e=()=>{Mc()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}class Sc{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(e,n={}){if(typeof e=="string"){const s=document.querySelector(e);if(!s)throw new Error(`Container not found: ${e}`);this.container=s}else this.container=e;this.options=n,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 $e,this.adapterB=new $e}async load(e){let n;if(typeof e=="string"){const s=await fetch(e);if(!s.ok)throw new Error(`Failed to load sequence: ${s.statusText}`);n=await s.json()}else n=e;this.sequence=n,this.symbolDefs.clear();for(const s of n.symbols??[])s.timeline?.tracks?.length&&this.symbolDefs.set(s.id,s.timeline);this.container.style.width=`${n.canvas.width}px`,this.container.style.height=`${n.canvas.height}px`,n.scenes.length>0&&(this.renderScene(n.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(n.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 e=this.timelineA.getStateAtTime(0);this.adapterA.applyState(e),this.applyNested(this.adapterA,0)}}goToScene(e){if(!this.sequence||e<0||e>=this.sequence.scenes.length)return;const n=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=e,this._state=n?"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[e];if(this.renderScene(s,this.containerA,this.adapterA),this.timelineA=this.createTimeline(s),this.options.onSceneChange?.(e),n)this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play(),this.startAnimationLoop()):this.onSceneComplete();else if(this.timelineA){const i=this.timelineA.getStateAtTime(0);this.adapterA.applyState(i),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 e of this.nestedByAdapter.values())for(const n of e)n.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 e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.width="100%",e.style.height="100%",e}renderScene(e,n,s){n.innerHTML="",s.clearTargets();const i=document.createElement("div");i.style.cssText="position:absolute;inset:0;transform-origin:center center",i.setAttribute("data-tinyfly","Camera"),n.appendChild(i),s.registerTarget("Camera",i);for(const o of e.elements){if(!o.html)continue;const r=document.createElement("div");r.innerHTML=o.html.trim();const a=r.firstElementChild;if(a){i.appendChild(a);const l=a.getAttribute("data-tinyfly");l&&s.registerTarget(l,a)}}this.setupNested(i,s)}setupNested(e,n){const s=[];e.querySelectorAll("[data-tinyfly-symbol]").forEach(i=>{const o=i.getAttribute("data-tinyfly-symbol");if(!o)return;const r=this.symbolDefs.get(o);if(!r)return;const a=new $e;i.querySelectorAll("[data-tinyfly]").forEach(l=>{const c=l.getAttribute("data-tinyfly");c&&a.registerTarget(c,l)}),s.push({adapter:a,timeline:ze(r)})}),s.length?this.nestedByAdapter.set(n,s):this.nestedByAdapter.delete(n)}applyNested(e,n){const s=this.nestedByAdapter.get(e);if(s)for(const i of s){const o=i.timeline.duration;i.adapter.applyState(i.timeline.getStateAtTime(o>0?n%o:n))}}clearContainer(e){e.innerHTML=""}createTimeline(e){return e.timeline?ze(e.timeline):null}onSceneComplete(){if(this._isDestroyed||!this.sequence)return;const e=this._currentSceneIndex+1;if(e>=this.sequence.scenes.length){const n=this.options.loop??this.sequence.loop??0;n===-1||n>0&&this.loopIteration<n-1?(this.loopIteration++,this.beginTransitionTo(0)):(this._isPlaying=!1,this._state="idle",this.stopAnimationLoop(),this.options.onComplete?.())}else this.beginTransitionTo(e)}beginTransitionTo(e){if(!this.sequence||this._isDestroyed)return;const n=this.sequence.scenes[e],s=n.transition;if(s.type==="none"||s.duration<=0){this.switchToScene(e);return}this._state="transitioning",this.containerB.style.visibility="visible",this.renderScene(n,this.containerB,this.adapterB),this.timelineB=this.createTimeline(n),this.timelineB&&this.timelineB.play(),this.applyTransition(s.type,s.duration),this.transitionTimer=window.setTimeout(()=>{this.finishTransition(e)},s.duration)}applyTransition(e,n){const s=`${n}ms`,i="ease-in-out";switch(this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),e){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} ${i}, transform ${s} ${i}`,this.containerB.style.transition=`opacity ${s} ${i}, transform ${s} ${i}`,e){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(e){e.style.transition="",e.style.opacity="1",e.style.transform=""}finishTransition(e){this.transitionTimer=void 0,this.timelineA&&(this.timelineA.stop(),this.timelineA=null),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const n=this.containerA;this.containerA=this.containerB,this.containerB=n;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=e,this._state="playing-scene",this.options.onSceneChange?.(e),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.playbackState!=="playing"&&this.timelineA.play()):this.onSceneComplete()}switchToScene(e){if(!this.sequence||this._isDestroyed)return;this.timelineA&&this.timelineA.stop(),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const n=this.sequence.scenes[e];this.renderScene(n,this.containerA,this.adapterA),this.timelineA=this.createTimeline(n),this._currentSceneIndex=e,this._state="playing-scene",this.options.onSceneChange?.(e),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play()):this.onSceneComplete()}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const e=n=>{if(this._isDestroyed||!this._isPlaying)return;const s=n-(this.lastTime??n);if(this.lastTime=n,this.timelineA&&this.timelineA.playbackState==="playing"){this.timelineA.tick(s);const i=this.timelineA.getStateAtTime(this.timelineA.currentTime);this.adapterA.applyState(i),this.applyNested(this.adapterA,this.timelineA.currentTime)}if(this._state==="transitioning"&&this.timelineB&&this.timelineB.playbackState==="playing"){this.timelineB.tick(s);const i=this.timelineB.getStateAtTime(this.timelineB.currentTime);this.adapterB.applyState(i),this.applyNested(this.adapterB,this.timelineB.currentTime)}this._isPlaying?this.animationFrameId=requestAnimationFrame(e):this.animationFrameId=void 0};this.animationFrameId=requestAnimationFrame(e)}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}}async function Eg(t,e,n={}){const s=new Sc(t,{...n,autoplay:!0});return await s.load(e),s}const Ag={type:"none",duration:0},wt=t=>({description:t,unit:"degrees"}),pt=(t,e=0,n=1)=>({description:t,unit:`${e}..${n}`,min:e,max:n}),Tc={lean:wt("Upper body tipped about the hips (+ toward the way it faces)"),bend:wt("Line of action: the spine curved (+ curls forward, − arches back)"),headTilt:wt("Head tilt"),leftShoulder:wt("Left upper arm: 0 hangs down, 90 straight out to its side, 180 straight up; in profile, forward is negative for the left arm"),rightShoulder:wt("Right upper arm: 0 hangs down, 90 straight out (forward, in profile), 180 straight up"),leftElbow:wt("Left elbow bend, added to the upper arm"),rightElbow:wt("Right elbow bend, added to the upper arm"),leftHip:wt("Left thigh: 0 straight down; in profile negative is forward"),rightHip:wt("Right thigh: 0 straight down; in profile positive is forward"),leftKnee:wt("Left knee bend (negative folds the shin back)"),rightKnee:wt("Right knee bend (positive folds the shin back)"),leftWrist:wt("Left wrist bend, added to the forearm"),rightWrist:wt("Right wrist bend, added to the forearm"),leftAnkle:wt("Left ankle: + points the toe down (tiptoe), − onto the heel"),rightAnkle:wt("Right ankle: + points the toe down (tiptoe), − onto the heel"),leftFootOut:pt("Left foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),rightFootOut:pt("Right foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),mouth:pt("Mouth open: 0 closed, 1 wide open"),smile:pt("−1 frown, 0 flat, 1 smile",-1,1),mouthWidth:{description:"Mouth width: 1 normal, 0.5 pursed, 1.5 wide",unit:"factor",min:.3,max:2},blink:pt("Eyes closed by a blink: 0 open, 1 shut"),leftEye:{description:"Left eye openness: 0 shut, 1 normal, 1.6 wide",unit:"factor",min:0,max:2},rightEye:{description:"Right eye openness: 0 shut, 1 normal, 1.6 wide",unit:"factor",min:0,max:2},leftBrow:pt("Left eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),rightBrow:pt("Right eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),browTilt:pt("Eyebrow slant: −1 angry, 1 worried",-1,1),lookX:pt("Eyes look across: + the way it faces",-1,1),lookY:pt("Eyes look down (+) or up (−)",-1,1),stretch:{description:"Squash and stretch: 1 normal, above taller (a jump), below squashed (a landing)",unit:"factor",min:.3,max:3},turn:pt("0 front-on, 1 in profile, turned the way it faces"),sit:pt("0 standing, 1 seated"),spin:wt("Whole body turned about the hips: + rolls forward (a front flip), 360 a full turn"),rise:{description:"Lift off the ground, as a fraction of its height (the arc of a jump)",unit:"× height"}},Ec={walk:{description:"Walk-cycle phase, in strides: animate 0 → n for n strides",unit:"strides"},walking:pt("How much of the walk cycle is applied (0 standing)"),gait:{description:"How it walks: a gait name (walk, bouncy, doubleBounce, sneak, strut, tired, run, shove); a string track switches it",kind:"string"},talk:pt("How much the mouth chatters"),rubber:pt("Limbs from jointed (0) to rubber hose (1)"),facing:{description:"Which way it faces: 1 right, −1 left (key the flip while turn is near 0)",unit:"±1",min:-1,max:1},beat:{description:"Beats into its dance (with a dance)",unit:"beats"},dancing:pt("How much of the dance is applied")},Ac={"thumb.curl":pt("Thumb curled in"),"thumb.across":pt("Thumb across the palm"),"index.curl":pt("Index finger curled"),"middle.curl":pt("Middle finger curled"),"ring.curl":pt("Ring finger curled"),"pinky.curl":pt("Little finger curled"),spread:pt("Fingers spread apart"),turn:wt("Hand turned about the forearm"),bend:wt("Hand bent at the wrist, palm-ward"),tilt:wt("Hand tilted sideways"),roll:wt("Hand rolled to show the back or the palm")};let Pc;function Pg(t){Pc=t}function $g(t){return Pc?.(t)??{}}function $c(t){let e=0;for(let n=1;n<t.length;n++)e+=Math.hypot(t[n].x-t[n-1].x,t[n].y-t[n-1].y);return e}function en(t,e){const n=Math.min(1,Math.max(0,e));if(t.length<2||n===1)return t.slice();if(n===0)return t.slice(0,1);let s=$c(t)*n;const i=[t[0]];for(let o=1;o<t.length;o++){const r=t[o-1],a=t[o],l=Math.hypot(a.x-r.x,a.y-r.y);if(l>=s){const c=l===0?0:s/l;return i.push({x:r.x+(a.x-r.x)*c,y:r.y+(a.y-r.y)*c}),i}i.push(a),s-=l}return i}function Ps(t,e){const n=en(t,e);return n[n.length-1]}function Po(t,e){return e>0?Math.floor(Math.max(0,t)*e/1e3):0}function $s(t,e,n){const s=e.roughness??2,i=Math.max(1,Math.round(e.passes??2)),o=Po(n,e.boil??8);let r=0;const a=()=>{const d=r++;return f=>Xe(Kt(`${e.seed??1}:${o}:${d}:${f}`))},l=(d,f)=>(d.next()*2-1)*f,c=d=>{const f=a(),g=t.lineWidth,p=t.globalAlpha;for(let m=0;m<i;m++)t.lineWidth=m===0?g:g*.55,t.globalAlpha=m===0?p:p*.6,d(f(m));t.lineWidth=g,t.globalAlpha=p},h=(d,f=1)=>{if(d.length<2)return;const g=d.slice(1).map((m,b)=>Math.hypot(m.x-d[b].x,m.y-d[b].y)),p=g.reduce((m,b)=>m+b,0)*Math.min(1,Math.max(0,f));c(m=>{const b=[],k=[];if(d.forEach((M,S)=>{b.push({x:M.x+l(m,s*.5),y:M.y+l(m,s*.5)}),S>0&&k.push([m.next()*2-1,m.next()*2-1])}),p<=0)return;t.beginPath(),t.moveTo(b[0].x,b[0].y);let w=0;for(let M=1;M<b.length;M++){const S=xg(b[M-1],b[M],s,k[M-1]),A=g[M-1];if(w+A<=p){t.bezierCurveTo(S[1].x,S[1].y,S[2].x,S[2].y,S[3].x,S[3].y),w+=A;continue}const E=_g(S,A===0?1:(p-w)/A);t.bezierCurveTo(E[1].x,E[1].y,E[2].x,E[2].y,E[3].x,E[3].y);break}t.stroke()})},u=(d,f,g,p,m=1)=>{c(b=>{const w=b.next()*Math.PI*2,M=Math.PI*2+.15+b.next()*.3,S=[];for(let E=0;E<=14;E++){const $=w+M*E/14,v=l(b,s*.6);S.push({x:d+Math.cos($)*(g+v),y:f+Math.sin($)*(p+v)})}const A=en(S,m);A.length<2||(xc(t,A),t.stroke())})};return{line:h,curve(d,f=1){if(d.length<2)return;const g=d[0],p=d[d.length-1],m=Math.hypot(p.x-g.x,p.y-g.y)||1,b=-(p.y-g.y)/m,k=(p.x-g.x)/m;c(w=>{const M={x:l(w,s*.5),y:l(w,s*.5)},S={x:l(w,s*.5),y:l(w,s*.5)},A=l(w,s*Math.min(1.5,Math.max(.3,m/80))),E=d.map((v,O)=>{const x=O/(d.length-1),_=Math.sin(Math.PI*x)*A;return{x:v.x+M.x+(S.x-M.x)*x+b*_,y:v.y+M.y+(S.y-M.y)*x+k*_}}),$=en(E,f);$.length<2||(xc(t,$),t.stroke())})},circle(d,f,g,p=1){u(d,f,g,g,p)},ellipse:u,nudge(d=.5){const f=a()(0);return{x:l(f,s*d),y:l(f,s*d)}}}}function xg(t,e,n,s){const i=e.x-t.x,o=e.y-t.y,r=Math.hypot(i,o)||1,a=n*Math.min(1.5,Math.max(.3,r/80)),l=-o/r,c=i/r;return[t,{x:t.x+i/3+l*s[0]*a,y:t.y+o/3+c*s[0]*a},{x:t.x+2*i/3+l*s[1]*a,y:t.y+2*o/3+c*s[1]*a},e]}function _g([t,e,n,s],i){const o=(u,d)=>({x:u.x+(d.x-u.x)*i,y:u.y+(d.y-u.y)*i}),r=o(t,e),a=o(e,n),l=o(n,s),c=o(r,a),h=o(a,l);return[t,r,c,o(c,h)]}function xc(t,e){t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let s=1;s<e.length-1;s++){const i={x:(e[s].x+e[s+1].x)/2,y:(e[s].y+e[s+1].y)/2};t.quadraticCurveTo(e[s].x,e[s].y,i.x,i.y)}const n=e[e.length-1];t.lineTo(n.x,n.y)}function Cn(t,e,n){const s=t.length;if(s<2)return[];const i=[],o=[],r=a=>e+(n-e)*a/(s-1);return t.forEach((a,l)=>{const c=t[Math.max(0,l-1)],h=t[Math.min(s-1,l+1)],u=Math.hypot(h.x-c.x,h.y-c.y)||1,d=r(l)/2,f=-(h.y-c.y)/u*d,g=(h.x-c.x)/u*d;i.push({x:a.x+f,y:a.y+g}),o.push({x:a.x-f,y:a.y-g})}),[...i,...o.reverse()]}function xs(t,e,n,s){const i=e.length;if(i<2)return;const o=Cn(e,n,s),r=a=>n+(s-n)*a/(i-1);t.beginPath(),t.moveTo(o[0].x,o[0].y);for(const a of o.slice(1))t.lineTo(a.x,a.y);t.closePath(),t.fill(),e.forEach((a,l)=>{l!==0&&l!==i-1&&i>3||(t.beginPath(),t.arc(a.x,a.y,r(l)/2,0,Math.PI*2),t.fill())})}function xe(t,e,n,s,i=16){const o={x:2*e.x-(t.x+n.x)/2,y:2*e.y-(t.y+n.y)/2},r=[];for(let a=0;a<=i;a++){const l=a/i,c=l<.5?{x:t.x+(e.x-t.x)*2*l,y:t.y+(e.y-t.y)*2*l}:{x:e.x+(n.x-e.x)*(2*l-1),y:e.y+(n.y-e.y)*(2*l-1)},h=1-l,u={x:h*h*t.x+2*h*l*o.x+l*l*n.x,y:h*h*t.y+2*h*l*o.y+l*l*n.y};r.push({x:c.x+(u.x-c.x)*s,y:c.y+(u.y-c.y)*s})}return r}function $o(t,e,n,s,i,o=0,r=1,a=40){const l=Math.cos(i),c=Math.sin(i);return Array.from({length:a+1},(h,u)=>{const d=o+Math.PI*2*r*u/a,f=Math.cos(d)*n,g=Math.sin(d)*s;return{x:t+f*l-g*c,y:e+f*c+g*l}})}function Hn(t,e){return e.look==="pencil"?Hg(t,e):Ig(t,e.ink,e.look)}function _s(t,e,n=!1){t.beginPath(),t.moveTo(e[0].x,e[0].y);for(const s of e.slice(1))t.lineTo(s.x,s.y);n&&t.closePath()}function Ig(t,e,n){const s=n==="silhouette",i=s?1.25:1;return{look:n,ink:e,limb(o,r,a){t.fillStyle=e,xs(t,o,r*i,a*i)},line(o,r){o.length<2||(t.strokeStyle=e,t.lineWidth=r*i,t.lineCap="round",t.lineJoin="round",_s(t,o),t.stroke())},shape(o,r,a){_s(t,o,!0),(r!==null||s)&&(t.fillStyle=s?e:r,t.fill()),!(a<=0)&&(t.strokeStyle=e,t.lineWidth=a*i,t.lineJoin="round",t.stroke())},ellipse(o,r,a,l,c,h,u){t.beginPath(),t.ellipse(o,r,a,l,c,0,Math.PI*2),(h!==null||s)&&(t.fillStyle=s?e:h,t.fill()),!(u<=0)&&(t.strokeStyle=e,t.lineWidth=u*i,t.stroke())},dot(o,r,a){t.fillStyle=e,t.beginPath(),t.arc(o,r,a*i,0,Math.PI*2),t.fill()},guide(){},guideEllipse(){}}}function Og(t,e){const n=[t[0]];let s=0;for(let r=1;r<t.length;r++){const a=t[r-1],l=t[r],c=Math.hypot(l.x-a.x,l.y-a.y);let h=e-s;for(;h<c;){const u=h/c;n.push({x:a.x+(l.x-a.x)*u,y:a.y+(l.y-a.y)*u}),h+=e}s=c-(h-e)}const i=t[t.length-1],o=n[n.length-1];return Math.hypot(i.x-o.x,i.y-o.y)>e*.25?n.push(i):n[n.length-1]=i,n}function Cg(t,e){const n=t.length;return t.map((s,i)=>{const o=t[Math.max(0,i-1)],r=t[Math.min(n-1,i+1)],a=Math.hypot(r.x-o.x,r.y-o.y)||1,l=e(n===1?0:i/(n-1));return{x:s.x-(r.y-o.y)/a*l,y:s.y+(r.x-o.x)/a*l}})}function _c(t){const e=[.6,1.4,2.9].map(s=>({frequency:s*(.8+t.next()*.4),phase:t.next()*Math.PI*2,amount:.5+t.next()*.5})),n=e.reduce((s,i)=>s+i.amount,0);return s=>e.reduce((i,o)=>i+o.amount*Math.sin(Math.PI*2*o.frequency*s+o.phase),0)/n}function Hg(t,e){const n=e.pencil??{},s=e.ink,i=n.roughness??Math.max(1,e.lineWidth*.12),o=Math.max(1,Math.round(n.passes??2)),r=Math.min(1,Math.max(0,n.pressure??.25)),a=Math.min(1,Math.max(0,n.rubbedOut??.15)),l=Po(e.time,n.boil??8);let c=0;const h=(g,p,m=!1)=>Xe(Kt(`${e.seed}:${m?"paper":l}:${g}:${p}`)),u=(g,p,m,b,k,w=0)=>{if(g.length<2)return;const M=g.slice(1).reduce((x,_,F)=>x+Math.hypot(_.x-g[F].x,_.y-g[F].y),0);let S=Og(g,Math.max(1.5,Math.min(e.lineWidth*.8,M/24)));if(w>0&&S.length>=2){const[x,_]=[S[S.length-2],S[S.length-1]],F=Math.hypot(_.x-x.x,_.y-x.y)||1;S=[...S,{x:_.x+(_.x-x.x)/F*w,y:_.y+(_.y-x.y)/F*w}]}const A=_c(m),E=_c(m),$=S.length,v=[],O=[];S.forEach((x,_)=>{const F=$===1?0:_/($-1),I=S[Math.max(0,_-1)],L=S[Math.min($-1,_+1)],N=Math.hypot(L.x-I.x,L.y-I.y)||1,Y=-(L.y-I.y)/N,j=(L.x-I.x)/N,U=A(F)*k,J=Math.min(1,F/.08,(1-F)/.08),P=(.55+.45*Math.sqrt(Math.max(0,J)))*(1+r*E(F)),H=Math.max(.3,p(F)*P/2),T=x.x+Y*U,C=x.y+j*U;v.push({x:T+Y*H,y:C+j*H}),O.push({x:T-Y*H,y:C-j*H})}),t.save(),t.globalAlpha*=b,t.fillStyle=s,_s(t,[...v,...O.reverse()],!0),t.fill(),t.restore()},d=(g,p)=>{const m=c++,b=h(m,99,!0);if(b.next()<a){const S=(b.next()*2-1)*e.lineWidth*1.4,A=(b.next()*2-1)*e.lineWidth*1.4,E=g.map($=>({x:$.x+S,y:$.y+A}));u(E,$=>p($)*1.8,h(m,98,!0),.035,i),u(E,$=>p($)*.45,h(m,97,!0),.12,i*1.5)}const k=g.slice(1).reduce((S,A,E)=>S+Math.hypot(A.x-g[E].x,A.y-g[E].y),0),w=p(.5)>4&&k>p(.5)*6,M=w?[-.3,.3,0]:[0];for(let S=0;S<o;S++){const A=S===0;M.forEach((E,$)=>{const v=h(m,S*10+$),O=E===0?g:Cg(g,_=>p(_)*E*Math.sqrt(Math.sin(Math.PI*_))),x=!A&&E===0?e.lineWidth*(.3+v.next()*.8):0;u(O,_=>p(_)*(w?.5:1)*(A?1:.6),v,A?.85:.45,i*(A?.6:1),x)})}},f=(g,p,m,b,k,w)=>{const S=h(c,50).next()*Math.PI*2;d($o(g,p,m,b,k,S,1.08,48),()=>w)};return{look:"pencil",ink:s,limb(g,p,m){d(g,b=>p+(m-p)*b)},line(g,p){d(g,()=>p)},shape(g,p,m){p!==null&&(t.save(),t.globalAlpha*=.88,t.fillStyle=p,_s(t,g,!0),t.fill(),t.restore()),m>0&&d([...g,g[0]],()=>m)},ellipse(g,p,m,b,k,w,M){w!==null&&(t.save(),t.globalAlpha*=.9,t.fillStyle=w,t.beginPath(),t.ellipse(g,p,m,b,k,0,Math.PI*2),t.fill(),t.restore()),f(g,p,m,b,k,M)},dot(g,p,m){t.save(),t.globalAlpha*=.9,t.fillStyle=s,t.beginPath(),t.arc(g,p,m,0,Math.PI*2),t.fill(),t.restore()},guide(g){if(n.construction===!1||g.length<2)return;const p=c++;u(g,()=>Math.max(.6,e.lineWidth*.18),h(p,0),.28,i*1.2,e.lineWidth)},guideEllipse(g,p,m,b,k){if(n.construction===!1)return;const w=c++,M=h(w,0),S=$o(g,p,m,b,k,M.next()*Math.PI*2,1.12,48);u(S,()=>Math.max(.6,e.lineWidth*.18),M,.28,i*1.5)}}}const Ic=["thumb","index","middle","ring","pinky"],kt={"thumb.curl":.15,"thumb.across":.15,"index.curl":.12,"middle.curl":.16,"ring.curl":.2,"pinky.curl":.25,spread:.25,turn:0,bend:0,tilt:0,roll:0};function vt(t={}){return{...kt,...t}}const Rt=(t,e,n,s,i)=>({"thumb.curl":t,"index.curl":e,"middle.curl":n,"ring.curl":s,"pinky.curl":i}),St={relaxed:kt,open:vt({...Rt(0,0,0,0,0),"thumb.across":0,spread:.55}),spread:vt({...Rt(0,0,0,0,0),"thumb.across":0,spread:1}),flat:vt({...Rt(0,0,0,0,0),"thumb.across":.35,spread:0}),fist:vt({...Rt(.7,1,1,1,1),"thumb.across":.9,spread:0}),point:vt({...Rt(.75,0,1,1,1),"thumb.across":.9,spread:0}),thumbsUp:vt({...Rt(0,1,1,1,1),"thumb.across":0,spread:0,roll:70}),peace:vt({...Rt(.75,0,0,1,1),"thumb.across":.9,spread:1}),ok:vt({...Rt(.12,.6,.1,.15,.2),"thumb.across":.55,spread:.6}),pinch:vt({...Rt(.1,.65,.75,.85,.9),"thumb.across":.55,spread:0}),cupped:vt({...Rt(.25,.4,.4,.4,.4),"thumb.across":.4,spread:.05,turn:2}),wave:vt({...Rt(0,.05,.05,.1,.12),"thumb.across":0,spread:.7,turn:2}),pencilGrip:vt({...Rt(.1,.6,.72,.88,.95),"thumb.across":.5,spread:0,turn:.8,bend:10}),hold:vt({...Rt(.5,.7,.72,.74,.76),"thumb.across":.75,spread:0,turn:1})};function nn(t,e,n){const s={...t};for(const[i,o]of Object.entries(e)){const r=t[i]??o;s[i]=r+(o-r)*n}return s}const Rg={index:{knuckle:[-.16,.47,-.02],bones:[.2,.125,.1],width:.125,fan:-1},middle:{knuckle:[-.055,.49,-.02],bones:[.22,.135,.1],width:.13,fan:-.2},ring:{knuckle:[.05,.475,-.02],bones:[.2,.125,.1],width:.122,fan:.55},pinky:{knuckle:[.15,.43,-.02],bones:[.16,.1,.085],width:.108,fan:1.25}},Lg={index:{knuckle:[-.14,.47,-.02],bones:[.2,.125,.1],width:.15,fan:-1},middle:{knuckle:[0,.49,-.02],bones:[.22,.135,.1],width:.155,fan:0},pinky:{knuckle:[.14,.45,-.02],bones:[.19,.115,.095],width:.145,fan:1}},Qt={base:[-.11,.1,-.05],bones:[.2,.15,.12],widths:[.2,.145,.135],out:[-.7,.68,-.22],across:[.35,.5,-.8]},Fg=[82,100,62],Dg=[48,72],Ng=3,Bg=13,Wg=.035,jg=-.075,qg=[[-.17,0],[-.215,.12],[-.235,.26],[-.225,.4],[-.185,.49],[-.075,.525],[.05,.51],[.16,.465],[.215,.4],[.225,.26],[.2,.1],[.16,0]],ue=t=>t*Math.PI/180,xo=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Is=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],_o=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],Rn=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function de(t,e,n){const s=Math.cos(n),i=Math.sin(n),o=_o(e,t),r=e[0]*t[0]+e[1]*t[1]+e[2]*t[2];return[t[0]*s+o[0]*i+e[0]*r*(1-s),t[1]*s+o[1]*i+e[1]*r*(1-s),t[2]*s+o[2]*i+e[2]*r*(1-s)]}const Oc=[1,0,0],Cc=[0,1,0],Ln=[0,0,1];function Kg(t,e,n){const s=ue(t.fan*(Ng+Bg*n)),i=[Math.sin(s),Math.cos(s),0],o=[Math.cos(s),-Math.sin(s),0],r=[t.knuckle];let a=0;t.bones.forEach((h,u)=>{a+=ue(Fg[u]*e),r.push(xo(r[u],Is(de(i,o,-a),h)))});const l=de(Ln,o,-a),c=r.map((h,u)=>t.width*(1-.14*(u/(r.length-1))));return{joints:r,back:l,widths:c}}function Yg(t,e,n=1,s=1){const i=Math.min(1,Math.max(0,e)),o=Rn(xo(Is(Rn(Qt.out),1-i),Is(Rn(Qt.across),i))),r=Rn(_o(Ln,o)),a=Rn(_o(o,r)),l=[[Qt.base[0]*s,Qt.base[1],Qt.base[2]]];let c=0;Qt.bones.forEach((d,f)=>{f>0&&(c+=ue(Dg[f-1]*t)),l.push(xo(l[f],Is(de(o,r,c),d)))});const h=de(a,r,c),u=[...Qt.widths,Qt.widths[Qt.widths.length-1]*.92].map(d=>d*n);return{joints:l,back:h,widths:u}}function Os(t,e={}){const n={...kt,...t},s=e.size??100,i=e.side??"right",o=i==="left"?-1:1,r=ue(e.angle??0),a=e.fingers===4,l=Math.max(.5,e.plump??1),c=1+(l-1)*.7,h=_=>({..._,knuckle:[_.knuckle[0]*c,_.knuckle[1],_.knuckle[2]],width:_.width*l}),u=ue(n.bend??0),d=ue(n.tilt??0),f=ue(90*(n.turn??0)),g=_=>de(de(de(_,Oc,-u),Ln,-d),Cc,f),p=Math.cos(r),m=Math.sin(r),b=ue(n.roll??0),k=Math.cos(b),w=Math.sin(b),M=_=>{const F=_[0]*s,I=-_[1]*s,L=(F*k-I*w)*o,N=F*w+I*k;return{x:L*p-N*m,y:L*m+N*p}},S=_=>{const F=M(_),I=Math.hypot(F.x,F.y);return I>1e-6*s?{x:F.x/I,y:F.y/I}:{x:0,y:0}},A={thumb:Yg(n["thumb.curl"]??0,n["thumb.across"]??0,l,c)},E=a?Lg:Rg;for(const _ of Ic){const F=E[_];F&&(A[_]=Kg(h(F),n[`${_}.curl`]??0,n.spread??0))}const $={};for(const[_,F]of Object.entries(A)){const I=F.joints.map(g),L=g(F.back);$[_]={points:I.map(M),depths:I.map(N=>N[2]*s),widths:F.widths.map(N=>N*s),nail:L[2],back:S(L)}}const v=qg.flatMap(([_,F])=>[g([_*c,F,Wg]),g([_*c,F,jg])]),O=zg(v.map(M)),x=v.reduce((_,F)=>_+F[2],0)/v.length*s;return{size:s,side:i,wrist:{x:0,y:0},palm:O,palmDepth:x,palmFacing:-g(Ln)[2],fingers:$,axes:{up:S(g(Cc)),across:S(g(Oc)),out:S(g(Ln))},curls:Object.fromEntries(Object.keys($).map(_=>[_,n[`${_}.curl`]??0]))}}function Hc(t,e){const n=i=>({x:i.x+e.x-t.wrist.x,y:i.y+e.y-t.wrist.y}),s={};for(const[i,o]of Object.entries(t.fingers))s[i]={...o,points:o.points.map(n)};return{...t,wrist:n(t.wrist),palm:t.palm.map(n),fingers:s}}function zg(t){const e=[...t].sort((o,r)=>o.x-r.x||o.y-r.y);if(e.length<3)return e;const n=(o,r,a)=>(r.x-o.x)*(a.y-o.y)-(r.y-o.y)*(a.x-o.x),s=[];for(const o of e){for(;s.length>=2&&n(s[s.length-2],s[s.length-1],o)<=0;)s.pop();s.push(o)}const i=[];for(const o of[...e].reverse()){for(;i.length>=2&&n(i[i.length-2],i[i.length-1],o)<=0;)i.pop();i.push(o)}return[...s.slice(0,-1),...i.slice(0,-1)]}const Xg="#f1c9a5",Gg="#2f2f33";function Cs(t,e,n,s={},i=0){const o=Hc(Os(n,s),e),r=s.ink??Gg,a=s.lineWidth??o.size*.035,l=s.pen??Hn(t,{look:s.look??"clean",ink:r,lineWidth:a,seed:s.seed??1,time:i,pencil:{construction:!1,...s.pencil}}),c=s.skin??Xg,h=s.nails??!0,u=[{depth:o.palmDepth,draw:()=>Ug(l,o,c,a)}];for(const d of Object.values(o.fingers)){const f=d.depths.reduce((g,p)=>g+p,0)/d.depths.length;u.push({depth:f,draw:()=>Vg(t,l,d,c,a,h)})}if(s.prop){const d=s.prop;u.push({depth:d.depth,draw:()=>d.draw(l)})}t.save(),t.lineCap="round",t.lineJoin="round";for(const d of[...u].sort((f,g)=>f.depth-g.depth))d.draw();return t.restore(),o}function Ug(t,e,n,s){if(t.shape(e.palm,n,s),e.palmFacing<-.3&&t.look!=="silhouette"){const{up:i}=e.axes;for(const[o,r]of Object.entries(e.fingers)){const a=e.curls[o]??0;if(o==="thumb"||a<.5)continue;const l=r.points[0],c=r.widths[0]*.42,h={x:l.x-i.x*c*.2,y:l.y-i.y*c*.2},u=Math.atan2(i.y,i.x),d=Array.from({length:7},(f,g)=>{const p=u-Math.PI/2+Math.PI*g/6;return{x:h.x+Math.cos(p)*c,y:h.y+Math.sin(p)*c}});t.line(d,s*.6)}}if(e.palmFacing>.45&&t.look!=="silhouette"){const{up:i,across:o}=e.axes,r=e.size,a=e.wrist,l=(h,u)=>({x:a.x+(o.x*h+i.x*u)*r,y:a.y+(o.y*h+i.y*u)*r}),c=e.side==="left"?-1:1;t.line([l(-.15*c,.36),l(-.04*c,.3),l(.1*c,.33)],s*.5)}}function Vg(t,e,n,s,i,o){const{widths:r}=n,a=Jg(n.points,2),l=n.points[0],c=a[a.length-1],h=r[0],u=r[r.length-1];if(t.save(),e.look!=="silhouette"){t.beginPath(),t.rect(l.x-1e5,l.y-1e5,2e5,2e5);const p=h/2+i*1.6;t.moveTo(l.x+p,l.y),t.arc(l.x,l.y,p,0,Math.PI*2),t.clip("evenodd")}if(e.limb(a,h+2*i,u+2*i),t.restore(),e.look!=="silhouette"&&(t.fillStyle=s,xs(t,a,h,u)),e.look==="silhouette"||!o||n.nail<.25)return;const d=a[a.length-2],f=Zg({x:c.x-d.x,y:c.y-d.y})??{x:0,y:-1},g={x:c.x-f.x*u*.22+n.back.x*u*.1,y:c.y-f.y*u*.22+n.back.y*u*.1};e.ellipse(g.x,g.y,u*.24*Math.max(.35,n.nail),u*.19,Math.atan2(f.y,f.x),"#f8e3d3",i*.45)}function Jg(t,e){let n=t;for(let s=0;s<e;s++){if(n.length<3)return n;const i=[n[0]];for(let o=0;o<n.length-1;o++){const r=n[o],a=n[o+1];o>0&&i.push({x:r.x*.75+a.x*.25,y:r.y*.75+a.y*.25}),o<n.length-2&&i.push({x:r.x*.25+a.x*.75,y:r.y*.25+a.y*.75})}i.push(n[n.length-1]),n=i}return n}const Zg=t=>{const e=Math.hypot(t.x,t.y);return e>1e-6?{x:t.x/e,y:t.y/e}:null},_t={walk:{swing:24,knee:30,arm:22,elbow:28,lean:4},bouncy:{swing:26,knee:45,arm:34,elbow:30,lean:2,bend:-4,bounce:.035,squash:.06},doubleBounce:{swing:22,knee:40,arm:26,elbow:24,lean:3,bounce:.02,bounces:2,squash:.04},sneak:{swing:28,knee:70,arm:6,elbow:0,forearm:110,shoulder:55,lean:16,bend:14,headTilt:-8,crouch:50,tiptoe:25},strut:{swing:26,knee:30,arm:30,elbow:20,lean:-4,bend:-10,headTilt:-6,sway:4,bounce:.01},tired:{swing:14,knee:14,arm:6,elbow:6,lean:10,bend:16,headTilt:12},run:{swing:40,knee:95,arm:45,elbow:0,forearm:90,lean:16,bend:6,bounce:.05,squash:.06},shove:{swing:18,knee:28,arm:0,elbow:0,lean:0}},Qg=40;function Fn(t){return t===void 0?_t.walk:typeof t=="string"?_t[t]??_t.walk:t}function Rc(t,e,n=it,s=1){const i=Fn(t);if(i===_t.walk)return Bc(e,n,s);const o=e*Math.PI*2,r=Math.sin(o)*s,a=Math.cos(o)*s,l=b=>Math.abs(b)<=Qg,c=i.shoulder??0,h=(b,k)=>l(b)?k*c+i.arm*r:b,u=i.forearm??0,d=l(n.leftShoulder)?n.leftElbow-u-i.elbow*Math.max(0,-r):n.leftElbow,f=l(n.rightShoulder)?n.rightElbow+u+i.elbow*Math.max(0,r):n.rightElbow,g=i.bounces??1,p=(1+Math.cos(o*2*g))/2,m=i.crouch??0;return{...n,lean:n.lean+i.lean*s+(i.sway??0)*Math.sin(o)*(1-(n.turn??0)),bend:(n.bend??0)+(i.bend??0),headTilt:n.headTilt-i.lean*.5*s+(i.headTilt??0),leftElbow:d,rightElbow:f,leftHip:-i.swing*r-m*.5,rightHip:-i.swing*r+m*.5,leftKnee:-i.knee*Math.max(0,a)-m,rightKnee:i.knee*Math.max(0,-a)+m,leftAnkle:(n.leftAnkle??0)+(i.tiptoe??0),rightAnkle:(n.rightAnkle??0)+(i.tiptoe??0),leftShoulder:h(n.leftShoulder,-1),rightShoulder:h(n.rightShoulder,1),rise:(n.rise??0)+(i.bounce??0)*s*p,stretch:n.stretch*(1+(i.squash??0)*(p-.5))}}function Io(t,e,n=1){const s=Fn(t),i=_t.walk.swing,o=r=>Math.sin(r*Math.PI/180);return Wc(e,n)*o(s.swing*n)/o(i*n)}const it={lean:0,bend:0,headTilt:0,leftShoulder:18,rightShoulder:18,leftElbow:-6,rightElbow:-6,leftHip:8,rightHip:8,leftKnee:0,rightKnee:0,leftWrist:0,rightWrist:0,leftAnkle:0,rightAnkle:0,leftFootOut:0,rightFootOut:0,mouth:0,smile:.6,mouthWidth:1,blink:0,leftEye:1,rightEye:1,leftBrow:0,rightBrow:0,browTilt:0,lookX:0,lookY:0,stretch:1,turn:0,sit:0,spin:0,rise:0};function Tt(t){return{...it,...t}}const Lc={mouth:0,smile:0,mouthWidth:1,leftEye:1,rightEye:1,leftBrow:0,rightBrow:0,browTilt:0,lookX:0,lookY:0},Pt=t=>({...Lc,...t}),dt={neutral:Lc,happy:Pt({smile:.9,leftBrow:.2,rightBrow:.2}),joyful:Pt({mouth:.6,smile:1,mouthWidth:1.2,leftEye:0,rightEye:0,leftBrow:.4,rightBrow:.4}),sad:Pt({smile:-.8,leftEye:.8,rightEye:.8,browTilt:.9,leftBrow:-.1,rightBrow:-.1,lookY:.6}),crying:Pt({mouth:.45,smile:-1,leftEye:0,rightEye:0,browTilt:1,lookY:.4}),surprised:Pt({mouth:.7,mouthWidth:.7,leftEye:1.5,rightEye:1.5,leftBrow:1,rightBrow:1}),shocked:Pt({mouth:1,mouthWidth:.8,leftEye:1.6,rightEye:1.6,leftBrow:1,rightBrow:1,browTilt:.4}),angry:Pt({smile:-.6,mouthWidth:.9,leftEye:.8,rightEye:.8,leftBrow:-.6,rightBrow:-.6,browTilt:-1}),furious:Pt({mouth:.5,smile:-1,mouthWidth:1.3,leftEye:.9,rightEye:.9,leftBrow:-.9,rightBrow:-.9,browTilt:-1}),worried:Pt({smile:-.3,mouthWidth:.8,leftEye:1.1,rightEye:1.1,leftBrow:.3,rightBrow:.3,browTilt:.8,lookX:-.5}),scared:Pt({mouth:.35,smile:-.5,mouthWidth:.8,leftEye:1.45,rightEye:1.45,leftBrow:.8,rightBrow:.8,browTilt:.9}),confused:Pt({smile:-.2,mouthWidth:.8,leftEye:.9,rightEye:1.15,leftBrow:-.3,rightBrow:.8,lookX:.5,lookY:-.4}),skeptical:Pt({smile:-.1,leftEye:.6,rightEye:1,leftBrow:-.4,rightBrow:.7,lookX:.4}),thinking:Pt({smile:0,mouthWidth:.7,leftBrow:.3,rightBrow:.5,lookX:.6,lookY:-.8}),sleepy:Pt({smile:.1,leftEye:.25,rightEye:.25,leftBrow:-.3,rightBrow:-.3,lookY:.5}),disgusted:Pt({smile:-.7,mouthWidth:.9,leftEye:.6,rightEye:.75,leftBrow:-.5,rightBrow:-.2,browTilt:-.4,lookX:-.6}),smug:Pt({smile:.6,mouthWidth:.9,leftEye:.6,rightEye:.6,leftBrow:.1,rightBrow:.5,lookX:.5}),wink:Pt({smile:.9,leftEye:0,rightEye:1,leftBrow:-.2,rightBrow:.3})};function fe(t,e){return{...t,...typeof e=="string"?dt[e]:e}}const Lt={rest:it,wave:Tt({rightShoulder:135,rightElbow:30,headTilt:6,...dt.happy}),cheer:Tt({leftShoulder:125,leftElbow:20,rightShoulder:125,rightElbow:20,...dt.joyful}),shrug:Tt({leftShoulder:30,leftElbow:85,rightShoulder:30,rightElbow:85,headTilt:-10,...dt.confused,lookX:0,lookY:0}),point:Tt({rightShoulder:90,rightElbow:0,lean:4,smile:.4}),think:Tt({rightShoulder:60,rightElbow:150,headTilt:10,...dt.thinking}),handsOnHips:Tt({leftShoulder:45,leftElbow:-100,rightShoulder:45,rightElbow:-100,leftHip:14,rightHip:14,smile:.8}),sad:Tt({leftShoulder:14,rightShoulder:14,leftElbow:-4,rightElbow:-4,headTilt:-14,lean:-3,...dt.sad}),surprised:Tt({leftShoulder:70,leftElbow:60,rightShoulder:70,rightElbow:60,...dt.surprised}),crouch:Tt({stretch:.72,leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50,leftHip:22,rightHip:22,headTilt:-4}),sit:Tt({sit:1,turn:.5,leftShoulder:-25,rightShoulder:25,leftElbow:-55,rightElbow:55}),jump:Tt({stretch:1.22,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4,...dt.joyful}),duck:Tt({stretch:.62,bend:28,headTilt:-8,leftShoulder:150,rightShoulder:150,leftElbow:130,rightElbow:130,leftHip:25,rightHip:25,...dt.scared}),lie:Tt({spin:-90,rise:-.42,leftShoulder:165,rightShoulder:165,leftElbow:150,rightElbow:150,...dt.sleepy}),sideSplit:Tt({leftHip:90,rightHip:90,leftAnkle:-45,rightAnkle:-45,leftShoulder:120,rightShoulder:120,leftElbow:10,rightElbow:10,...dt.happy}),frontSplit:Tt({turn:1,leftHip:-90,rightHip:-90,leftAnkle:-45,rightAnkle:-45,leftShoulder:-150,rightShoulder:150,leftElbow:10,rightElbow:-10,...dt.happy})},Fc=Object.keys(it);function sn(t,e,n){const s={...t};for(const i of Fc)s[i]=t[i]+(e[i]-t[i])*n;return s}const Oo=24,Dc=4,Nc=28,tm=40;function Bc(t,e=it,n=1){const s=Math.sin(t*Math.PI*2)*n,i=Math.cos(t*Math.PI*2)*n,o=c=>Math.abs(c)<=tm,r=c=>o(c)?22*s:c,a=o(e.leftShoulder)?e.leftElbow-Nc*Math.max(0,-s):e.leftElbow,l=o(e.rightShoulder)?e.rightElbow+Nc*Math.max(0,s):e.rightElbow;return{...e,lean:e.lean+Dc*n,headTilt:e.headTilt-Dc*.5*n,leftElbow:a,rightElbow:l,leftHip:-Oo*s,rightHip:-Oo*s,leftKnee:-30*Math.max(0,i),rightKnee:30*Math.max(0,-i),leftShoulder:r(e.leftShoulder),rightShoulder:r(e.rightShoulder)}}function Wc(t,e=1){return 4*((Co+Hs)*t)*Math.sin(Oo*e*Math.PI/180)}function jc(t){const e=Math.abs(Math.sin(t/65)),n=.55+.45*Math.sin(t/310);return e*n}const qc=.12,Kc=.46,em=1-2*qc,nm=.1,sm=.21,im=.19,Co=.24,Hs=.22,Yc=.12,om=.14,zc=.33,Xc=.7,Gc=.3,rm=.35,am=[1.7,1.05],lm=[1.3,.75],Uc=[1.45,.85],cm=[1.15,.75],Vc=.06,hm=.7,um=.65,Jc=.075,dm=.3,fm=.02,pm=.012,gm=12,mm=.25,Rs=90,ym=.25,bm=.04,Zc=.01,_e=t=>Math.min(1,Math.max(0,t??0));function wm(t,e=1){return Hs*t*e}const Ho=-.12,Qc=.4,jt=t=>t*Math.PI/180,km=(t,e)=>({x:e*Math.sin(jt(t)),y:Math.cos(jt(t))}),th=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),eh=(t,e,n,s)=>t-.3*e-n*.14*e-Math.max(0,s-1)*.12*e;function vm(t,e,n,s,i,o){const r=Math.max(1,Math.min(o*.6,om*n)),a=_e(e.turn),l=(Yc+zc*a)*n,c=s+Ho*n,h=l+e.lookX*.08*n,u=e.lookY*.07*n,d=[{x:-.34*n*(1-Xc*a),squeeze:1-Xc*a,open:e.leftEye,brow:e.leftBrow,side:-1},{x:.34*n*(1-Gc*a),squeeze:1-Gc*a,open:e.rightEye,brow:e.rightBrow,side:1}];t.fillStyle=i,t.strokeStyle=i,t.lineWidth=r;for(const b of d){const k=th(b.open,e.blink);if(k<.2){const A=e.smile>.5?-.12*n:.06*n;t.beginPath(),t.moveTo(b.x+l-.12*n,c),t.quadraticCurveTo(b.x+l,c+A,b.x+l+.12*n,c),t.stroke()}else{if(k>1.2){const E=.13*n*k;t.beginPath(),t.ellipse(b.x+l,c,E*.85,E,0,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.stroke(),t.fillStyle=i}const A=k>1.2?.075*n:.1*n;t.beginPath(),t.ellipse(b.x+h,c+u,A,A*1.1*Math.min(k,1),0,0,Math.PI*2),t.fill()}const w=eh(c,n,b.brow,k),M=b.x+l-b.side*.13*n*b.squeeze,S=b.x+l+b.side*.13*n*b.squeeze;t.beginPath(),t.moveTo(S,w),t.lineTo(M,w-e.browTilt*.1*n),t.stroke()}const f=s+Qc*n,g=.25*n*Math.max(.3,e.mouthWidth)*(1-rm*a),p=Math.min(1,Math.max(0,e.mouth));if(t.beginPath(),p<=.05){t.moveTo(l-g,f),t.quadraticCurveTo(l,f+e.smile*.25*n,l+g,f),t.stroke();return}const m=.3*n*p;e.smile>.3?(t.moveTo(l-g,f-.05*n),t.lineTo(l+g,f-.05*n),t.quadraticCurveTo(l,f+m*2,l-g,f-.05*n)):e.smile<-.3?(t.moveTo(l-g,f+m*.6),t.lineTo(l+g,f+m*.6),t.quadraticCurveTo(l,f-m*1.4,l-g,f+m*.6)):t.ellipse(l,f,g*.8,m,0,0,Math.PI*2),t.fill()}function nh(t,e){const n=e.height??300,s=Math.min(3,Math.max(.3,t.stretch??1)),i=Math.sqrt(s),o=(e.headSize??2*qc)/2,r=e.headSize===void 0?em:1-2*o,a=o*n,l=_e(t.sit),c=t.leftHip+(-Rs-t.leftHip)*l,h=t.leftKnee+(-Rs-t.leftKnee)*l,u=t.rightHip+(Rs-t.rightHip)*l,d=t.rightKnee+(Rs-t.rightKnee)*l,f=e.classic===!0,g=_e(t.turn),p=(j,U,J,P,H)=>{const T=Math.max(-Math.PI/2,Math.min(Math.PI/2,Math.abs(jt(U-J)/2)+jt(P))),C=Math.max(-1,Math.min(1,hm+H)),D=g+(1-g)*j*C;return f?{x:0,y:0}:{x:Math.cos(T)*Vc*D,y:Math.sin(T)*Vc}},m={left:t.leftAnkle??0,right:t.rightAnkle??0},b={left:t.leftFootOut??0,right:t.rightFootOut??0};let k=0;if(l>0||!f){const j=(H,T,C,D,q)=>Co*Math.cos(jt(T))+Hs*Math.cos(jt(T-C))+Math.max(0,p(H,T,C,D,q).y),U=Math.max(j(-1,c,h,m.left,b.left),j(1,u,d,m.right,b.right)),J=1-_e((t.rise??0)/bm),P=(f?Math.min(1,l/ym):1)*J;k=(Kc-U)*P*n*s}const w=-Kc*n*s+k,M=-r*n*s+k,S=f?0:(fm*_e(t.turn)+pm*l)*n*s,A=jt(t.bend??0),E={end:ih(w,M,A,1),bend:A};let $;if(A!==0){$=[];for(let j=0;j<=sh;j++){const U=j/sh,J=ih(w,M,A,U);$.push({x:J.x-S*Math.sin(Math.PI*U),y:J.y})}}else $=S===0?[{x:0,y:w},{x:0,y:M}]:xe({x:0,y:w},{x:-S,y:(w+M)/2},{x:0,y:M},1,8);const v=M+nm*n*s,O=(e.shoulderWidth??0)*n*Math.cos(g*Math.PI/2),x=(j,U,J,P,H)=>{const T=km(J,P);return{x:j+T.x*H*n,y:U+T.y*H*n}},_=(j,U,J)=>{const P=x(0,w,U,j,Co*s);return{root:{x:0,y:w},joint:P,end:x(P.x,P.y,U-J,j,Hs*s)}},F=(j,U,J)=>{const P={x:j*O,y:v},H=x(P.x,P.y,U,j,sm*i);return{root:P,joint:H,end:x(H.x,H.y,U+J,j,im*i)}},I={left:_(-1,c,h),right:_(1,u,d)},L=(j,U,J,P,H,T)=>{const C=p(j,J,P,H,T);return{x:U.end.x+C.x*n*s,y:U.end.y+C.y*n*s}},N=(j,U,J,P,H)=>x(U.end.x,U.end.y,J+P+H,j,Jc*i),Y={left:F(-1,t.leftShoulder,t.leftElbow),right:F(1,t.rightShoulder,t.rightElbow)};return{height:n,facing:(e.facing??1)<0?-1:1,stretch:s,lineWidth:e.lineWidth??n*.025,rubber:Math.min(1,Math.max(f?0:dm,e.rubber??0)),r:a,headRx:a/Math.sqrt(s),headRy:a*Math.sqrt(s),hipY:w,neckY:M,drop:k,lean:f?t.lean:t.lean+gm*Math.sin(Math.PI*l),classic:f,legs:I,toes:{left:L(-1,I.left,c,h,m.left,b.left),right:L(1,I.right,u,d,m.right,b.right)},spine:$,chest:E,arms:Y,handTips:{left:N(-1,Y.left,t.leftShoulder,t.leftElbow,t.leftWrist??0),right:N(1,Y.right,t.rightShoulder,t.rightElbow,t.rightWrist??0)}}}const sh=10;function ih(t,e,n,s){const i=t-e,o=n*s;if(Math.abs(n)<1e-9)return{x:0,y:t-i*s};const r=i/n;return{x:r*(1-Math.cos(o)),y:t-r*Math.sin(o)}}function Mm(t,e){if(t.chest.bend===0)return e;const n=Nn(e,{x:0,y:t.neckY},t.chest.bend);return{x:n.x+t.chest.end.x,y:n.y+t.chest.end.y-t.neckY}}const Dn=(t,e)=>e===0?[t.root,t.joint,t.end]:xe(t.root,t.joint,t.end,e);function Nn(t,e,n){const s=Math.cos(n),i=Math.sin(n),o=t.x-e.x,r=t.y-e.y;return{x:e.x+o*s-r*i,y:e.y+o*i+r*s}}function oh(t,e,n=!0){const s=Tm(t,e),i=e.spin??0,o=e.rise??0;return n&&(i!==0||o!==0)?Sm(s,t,i,o):s}function rh(t,e,n){return{pivot:{x:0,y:t.hipY},angle:t.facing*jt(e),lift:n*t.height}}function Sm(t,e,n,s){const{pivot:i,angle:o,lift:r}=rh(e,n,s),a=d=>{const f=Nn(d,i,o);return{x:f.x,y:f.y-r}},l=d=>({left:a(d.left),right:a(d.right)}),c={left:Math.max(a(t.feet.left).y,a(t.toes.left).y),right:Math.max(a(t.feet.right).y,a(t.toes.right).y)},h=Math.max(c.left,c.right),u=Zc*e.height;return{...t,hip:a(t.hip),neck:a(t.neck),shoulders:l(t.shoulders),elbows:l(t.elbows),hands:l(t.hands),fingertips:l(t.fingertips),knees:l(t.knees),feet:l(t.feet),toes:l(t.toes),feetY:h,grounded:{left:c.left>=h-u,right:c.right>=h-u},handAngle:{left:t.handAngle.left+o,right:t.handAngle.right+o},limbs:{leftArm:t.limbs.leftArm.map(a),rightArm:t.limbs.rightArm.map(a),leftLeg:t.limbs.leftLeg.map(a),rightLeg:t.limbs.rightLeg.map(a),spine:t.limbs.spine.map(a)},head:{...t.head,center:a(t.head.center),angle:t.head.angle+o}}}function Tm(t,e){const n=jt(t.lean),s=jt(e.headTilt),i={x:0,y:t.hipY},o=M=>({x:t.facing*M.x,y:M.y}),r=M=>o(Nn(M,i,n)),a=M=>r(Mm(t,M)),l=M=>a(Nn({x:M.x,y:M.y+t.neckY},{x:0,y:t.neckY},s)),c=Dn(t.arms.left,t.rubber).map(a),h=Dn(t.arms.right,t.rubber).map(a),u=(M,S)=>Math.atan2(S.y-M.y,S.x-M.x),d={left:a(t.handTips.left),right:a(t.handTips.right)},f=(M,S)=>{const[A,E]=M.slice(-2),$=t.arms[S],v=u(a($.end),d[S])-u(a($.joint),a($.end));return u(A,E)+v};let g=1/0;for(const[M,S]of[[e.leftBrow,e.leftEye],[e.rightBrow,e.rightEye]]){const A=eh(Ho,1,M,th(S,e.blink));g=Math.min(g,A,A-e.browTilt*.1)}const p={left:o(t.legs.left.end),right:o(t.legs.right.end)},m={left:o(t.toes.left),right:o(t.toes.right)},b={left:Math.max(p.left.y,m.left.y),right:Math.max(p.right.y,m.right.y)},k=Math.max(b.left,b.right),w=Zc*t.height;return{facing:t.facing,height:t.height,stretch:t.stretch,lineWidth:t.lineWidth,hip:i,neck:a({x:0,y:t.neckY}),shoulders:{left:a(t.arms.left.root),right:a(t.arms.right.root)},elbows:{left:a(t.arms.left.joint),right:a(t.arms.right.joint)},hands:{left:a(t.arms.left.end),right:a(t.arms.right.end)},knees:{left:o(t.legs.left.joint),right:o(t.legs.right.joint)},feet:p,toes:m,feetY:k,grounded:{left:b.left>=k-w,right:b.right>=k-w},fingertips:d,handAngle:{left:f(c,"left"),right:f(h,"right")},limbs:{leftArm:c,rightArm:h,leftLeg:Dn(t.legs.left,t.rubber).map(o),rightLeg:Dn(t.legs.right,t.rubber).map(o),spine:t.spine.map(r)},head:{center:l({x:0,y:-t.headRy}),rx:t.headRx,ry:t.headRy,angle:t.facing*(n+t.chest.bend+s),eyeY:Ho,browTopY:g,mouthY:Qc,faceX:t.facing*(Yc+zc*_e(e.turn))}}}function pe(t,e={}){return oh(nh(t,e),t)}function Em(t,e,n){return Nn({x:t.center.x+e*t.rx,y:t.center.y+n*t.ry},t.center,t.angle)}function ah(t,e,n){const s=o=>({x:o.x+e,y:o.y+n}),i=o=>({left:s(o.left),right:s(o.right)});return{...t,hip:s(t.hip),neck:s(t.neck),shoulders:i(t.shoulders),elbows:i(t.elbows),hands:i(t.hands),fingertips:i(t.fingertips),knees:i(t.knees),feet:i(t.feet),toes:i(t.toes),feetY:t.feetY+n,grounded:{...t.grounded},handAngle:{...t.handAngle},limbs:{leftArm:t.limbs.leftArm.map(s),rightArm:t.limbs.rightArm.map(s),leftLeg:t.limbs.leftLeg.map(s),rightLeg:t.limbs.rightLeg.map(s),spine:t.limbs.spine.map(s)},head:{...t.head,center:s(t.head.center)}}}function lh(t,e,n={},s=0){const i=nh(e,n),o=n.color??"#1e293b",r=n.layers??{},a=n.layers?oh(i,e,!1):void 0,l=n.sketch?$s(t,n.sketch,s):void 0,c=n.sketch&&n.layers?$s(t,n.sketch,s):void 0,h=E=>{t.save(),E(),t.restore()},u=E=>{E&&a&&h(()=>E(t,a,s,c))},d=()=>t.scale(i.facing,1),f=()=>{d(),t.translate(0,i.hipY),t.rotate(jt(i.lean)),t.translate(0,-i.hipY)},g=()=>{f(),i.chest.bend!==0&&(t.translate(i.chest.end.x,i.chest.end.y),t.rotate(i.chest.bend),t.translate(0,-i.neckY))},p=(E,$,v)=>{if(l)return $?l.curve(E):l.line(E);if(i.classic){t.beginPath(),t.moveTo(E[0].x,E[0].y);for(const O of E.slice(1))t.lineTo(O.x,O.y);t.stroke();return}xs(t,E,v[0]*i.lineWidth,v[1]*i.lineWidth)},m=(E,$)=>p(Dn(E,i.rubber),i.rubber>0,$),b=E=>{i.classic||p([i.legs[E].end,i.toes[E]],!1,cm)},k=E=>{if(n.hands&&!i.classic)return M(E);if(i.classic||l)return;const $=i.arms[E].end;t.beginPath(),t.arc($.x,$.y,um*i.lineWidth,0,Math.PI*2),t.fill()};t.save(),t.strokeStyle=o,t.fillStyle=o,t.lineWidth=i.lineWidth,t.lineCap="round",t.lineJoin="round";const w=rh(i,e.spin??0,e.rise??0);(w.angle!==0||w.lift!==0)&&(t.translate(0,-w.lift),t.translate(w.pivot.x,w.pivot.y),t.rotate(w.angle),t.translate(-w.pivot.x,-w.pivot.y));function M(E){const $=n.hands??{},v=i.arms[E].end,O=i.handTips[E],x=n.headFill??"#ffffff";Cs(t,v,$[E]??kt,{side:E,angle:Math.atan2(O.x-v.x,v.y-O.y)*180/Math.PI,size:($.size??Jc)*i.height*Math.sqrt(i.stretch),skin:$.skin??(x==="none"?void 0:x),ink:o,lineWidth:i.lineWidth*.45,fingers:$.fingers,plump:$.plump,look:n.sketch?"pencil":"clean",seed:n.sketch?.seed},s)}const S=E=>{h(()=>{g(),m(i.arms[E],lm),k(E)});const $=r.sleeve;$&&a&&h(()=>$(t,a,E,s,c))},A=_e(e.turn)>mm;u(r.behind),h(()=>{d(),m(i.legs.left,Uc),b("left"),m(i.legs.right,Uc),b("right")}),A&&S("left"),h(()=>{f(),p(i.spine,i.spine.length>2,am)}),h(()=>{g();const{left:E,right:$}={left:i.arms.left.root,right:i.arms.right.root};if(E.x!==$.x)if(i.classic)p([E,$],!1,[1,1]);else{const v={x:(E.x+$.x)/2,y:E.y-.3*Math.abs($.x-E.x)};p(xe(E,v,$,1,8),!0,[1.1,1.1])}}),u(r.body),A||S("left"),S("right"),u(r.behindHead),h(()=>{g(),t.translate(0,i.neckY),t.rotate(jt(e.headTilt));const E=-i.headRy;t.beginPath(),t.ellipse(0,E,i.headRx,i.headRy,0,0,Math.PI*2);const $=n.headFill??"#ffffff";if($!=="none"&&(t.fillStyle=$,t.fill()),l){l.ellipse(0,E,i.headRx,i.headRy);const v=l.nudge();t.translate(v.x,v.y)}else t.stroke();t.translate(0,E),t.scale(i.headRx/i.r,i.headRy/i.r),vm(t,e,i.r,0,o,i.lineWidth)}),u(r.overHead),u(r.front),t.restore(),n.label&&(t.save(),t.fillStyle=o,t.font=n.labelFont??`700 ${Math.round(i.height*.11)}px sans-serif`,t.textAlign="center",t.textBaseline="bottom",t.fillText(n.label,0,-i.height*i.stretch-.04*i.height+i.drop),t.restore())}function Ro(t,e,n,s){const i={...t},o=t.gait&&s?.[t.gait]||t.gait;let r=t.walking>0?sn(i,Rc(o,t.walk,i),t.walking):i,a=Am(t);const l=t.dancing??0;if(n&&l>0){const c=n(t.beat??0);if(r=sn(r,c.pose,l),c.hands){const h=(u,d)=>d?nn(u??kt,d,l):u;a={left:h(a?.left,c.hands.left),right:h(a?.right,c.hands.right)}}}return t.talk>0&&(r={...r,mouth:Math.max(r.mouth,t.talk*jc(e))}),{pose:r,hands:a}}function ch(t,e,n,s){return Ro(t,e,n,s).pose}const hh=(t,e)=>(t.facing??e.facing??1)<0?-1:1,Bn=(t,e)=>`hand.${t}.${e}`;function Am(t){const e=i=>{if(typeof t[Bn(i,"spread")]=="number")return Object.fromEntries(Object.keys(kt).map(o=>[o,t[Bn(i,o)]]))},n=e("left"),s=e("right");return n||s?{left:n,right:s}:void 0}function Pm(t,e){return!e||!t.hands?t:{...t,hands:{...t.hands,left:e.left??t.hands.left,right:e.right??t.hands.right}}}function Lo(t){const e=t.style??{},n=e.height??300,s=n*.8,i={...Tt(t.pose??{}),walk:0,walking:0,gait:"walk",facing:(e.facing??1)<0?-1:1,talk:0,rubber:e.rubber??0,beat:0,dancing:0},o={};if(e.hands)for(const r of["left","right"]){const a=e.hands[r]??kt;for(const l of Object.keys(kt))o[Bn(r,l)]=a[l]??kt[l]}return{type:"custom",x:t.x-s/2,y:t.y-n,width:s,height:n,props:{...i,...o},about:$m(Object.keys(o),t.cast),figureStyle:e,figureDance:t.dance,figureGaits:t.cast?.gaits,draw(r,a,l){const c=a.props,h=Ro(c,l,t.dance,t.cast?.gaits);r.translate(s/2,n),lh(r,h.pose,Pm({...e,rubber:c.rubber,facing:hh(c,e)},h.hands),l)}}}function $m(t,e){const n={...Tc,...Ec};for(const s of t){const[,i,...o]=s.split("."),r=Ac[o.join(".")];r&&(n[s]={...r,description:`${i==="left"?"Left":"Right"} hand: ${r.description.toLowerCase()}`})}return{kind:"stick figure",summary:"A poseable stick figure: pose it with joint tracks, or give it beats (`scriptTracks`) that compile into acted tracks.",props:n,get actions(){return $g(e)}}}function Fo(t,e,n){const s=t.figureStyle;if(!s)throw new Error("stickFigureAt: the target was not made by stickFigureTarget");const i={...t.props};let o=0,r=0;for(const[c,h]of e.state?.values.get(n)??[])c==="gait"&&typeof h=="string"&&(i.gait=h),typeof h=="number"&&(c==="x"||c==="motionPathX"?o=h:c==="y"||c==="motionPathY"?r=h:c in i&&(i[c]=h));const a=ch(i,e.time,t.figureDance,t.figureGaits),l=pe(a,{...s,rubber:i.rubber,facing:hh(i,s)});return{pose:a,joints:ah(l,t.x+o+t.width/2,t.y+r+t.height)}}function Do(t){const e=[];return t.forEach((n,s)=>{const i=s===0?it:e[s-1],o=typeof n.pose=="string"?Lt[n.pose]:{...i,...n.pose};e.push(n.expression?fe(o,n.expression):o)}),e}function xm(t,e){const n=Do(e);return Fc.filter(s=>n.some(i=>i[s]!==it[s])).map(s=>({id:`${t}-${s}`,target:t,property:s,keyframes:e.map((i,o)=>({time:i.time,value:n[o][s],...i.easing?{easing:i.easing}:{}}))}))}const No=.5,Ls={pataka:vt({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:0,turn:2}),tripataka:vt({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":1,"pinky.curl":0,spread:0,turn:2}),alapadma:vt({"thumb.curl":.1,"thumb.across":0,"index.curl":.05,"middle.curl":.15,"ring.curl":.25,"pinky.curl":.35,spread:1,turn:2}),mushti:St.fist,shikhara:St.thumbsUp,hamsasya:vt({"thumb.curl":.15,"thumb.across":.6,"index.curl":.6,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:.7,turn:2}),katakamukha:vt({"thumb.curl":.2,"thumb.across":.6,"index.curl":.65,"middle.curl":.7,"ring.curl":0,"pinky.curl":0,spread:.4,turn:2})};function Fs(t){return typeof t!="string"?t:t in Ls?Ls[t]:St[t]}function uh(t,e,n){const s=[];for(const i of t.keys){const o=s[s.length-1],r=!o||i.reset?{pose:e,...n}:o;s.push({beat:i.beat,pose:{...r.pose,...i.pose},left:i.hands?.left?Fs(i.hands.left):r.left,right:i.hands?.right?Fs(i.hands.right):r.right,easing:i.easing??t.easing})}return s}const Bo=(t,e)=>(t%e+e)%e;function _m(t,e,n,s){const i=uh(t,n,s);if(i.length===0)return{pose:n,hands:s};const o=Bo(e,t.beats);let r=i.length-1;for(let f=0;f<i.length;f++)i[f].beat<=o&&(r=f);const a=i[r],l=i[(r+1)%i.length],c=a.beat<=o?a.beat:a.beat-t.beats,h=l.beat>c?l.beat:l.beat+t.beats,u=h>c?(o-c)/(h-c):0,d=$t(l.easing??"ease-in-out")(Math.min(1,Math.max(0,u)));return{pose:sn(a.pose,l.pose,d),hands:{left:nn(a.left,l.left,d),right:nn(a.right,l.right,d)}}}const Im=[["leftShoulder","rightShoulder"],["leftElbow","rightElbow"],["leftWrist","rightWrist"],["leftHip","rightHip"],["leftKnee","rightKnee"],["leftAnkle","rightAnkle"],["leftFootOut","rightFootOut"],["leftEye","rightEye"],["leftBrow","rightBrow"]],Om=["lean","headTilt","lookX","spin"],Cm=new Set(["leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee"]);function dh(t){const e={...t},n=(t.turn??0)>=.5;for(const[s,i]of Im){const o=n&&Cm.has(s)?-1:1;e[s]=o*t[i],e[i]=o*t[s]}if(!n)for(const s of Om)e[s]=-t[s];return e}const Hm=t=>Math.min(1,Math.max(-1,(.5-t)*4));function fh(t,e,n){const s=Bo(n,1),i=(1+Math.cos(2*Math.PI*s))/2,o=e.bounce*(e.accent==="up"?1-i:i),r=Math.min(1,Math.max(0,t.turn??0)),a=Hm(r);return{...t,leftHip:t.leftHip+a*o/2,rightHip:t.rightHip+o/2,leftKnee:t.leftKnee+a*o,rightKnee:t.rightKnee+o,lean:t.lean+(e.sway??0)*(1-r)*Math.sin(Math.PI*n)}}function Ds(t){const e={...it,...t.stance};return t.expression?fe(e,t.expression):e}function ph(t){return{left:t.hands?.left?Fs(t.hands.left):kt,right:t.hands?.right?Fs(t.hands.right):kt}}function Wo(t,e,n){const s=t.moves[e.move];if(!s)throw new Error(`dance: "${t.label}" has no move "${e.move}"`);const i=_m(s,n,Ds(t),ph(t));return e.mirror?{pose:dh(i.pose),hands:{left:i.hands?.right,right:i.hands?.left}}:i}function Ns(t,e,n={}){const s=typeof t=="string"?ge[t]:t;let i;if(n.move)i=Wo(s,{move:n.move,mirror:n.mirror},e);else{const o=s.routine,r=o.reduce((u,d)=>u+d.beats,0),a=Bo(e,r);let l=0,c=0;for(;c<o.length-1&&a>=l+o[c].beats;)l+=o[c++].beats;const h=a-l;if(i=Wo(s,o[c],h),h<No&&o.length>1&&e>=No){const u=o[(c-1+o.length)%o.length],d=Wo(s,u,u.beats+h),f=$t("ease-in-out")(h/No);i={pose:sn(d.pose,i.pose,f),hands:{left:nn(d.hands.left,i.hands.left,f),right:nn(d.hands.right,i.hands.right,f)}}}}return{...i,pose:fh(i.pose,s.groove,e)}}function Rm(t,e,n={}){return Ns(t,e,n).pose}function Bs(t){return(typeof t=="string"?ge[t]:t).routine.reduce((n,s)=>n+s.beats,0)}const Lm={leftToe:"rightToe",rightToe:"leftToe",leftHeel:"rightHeel",rightHeel:"leftHeel"};function gh(t,e,n,s,i,o,r){for(let a=0;a*t.beats<n;a++)for(const l of t.keys){const c=a*t.beats+l.beat,h=e+c;if(!(c>=n||h<o||h>=r))for(const u of l.taps??[])i.push({beat:h,tap:s?Lm[u]:u})}}function Fm(t,e,n,s={}){const i=typeof t=="string"?ge[t]:t,o=[];if(n<=e)return o;if(s.move){const r=i.moves[s.move],a=Math.floor(e/r.beats)*r.beats;gh(r,a,Math.ceil((n-a)/r.beats)*r.beats,s.mirror,o,e,n)}else{const r=Bs(i);for(let a=Math.floor(e/r)*r;a<n;a+=r){let l=a;for(const c of i.routine)gh(i.moves[c.move],l,c.beats,c.mirror,o,e,n),l+=c.beats}}return o.sort((r,a)=>r.beat-a.beat)}function mh(t,e){const n=t.moves[e.move];if(!n?.travel)return 0;const s=n.travel/n.beats;return e.mirror?(uh(n,Ds(t),ph(t))[0]?.pose.turn??Ds(t).turn??0)>=.5?s:-s:s}function yh(t,e){return e.move?[{move:e.move,beats:t.moves[e.move].beats,mirror:e.mirror}]:t.routine}function Ws(t,e,n={}){const s=typeof t=="string"?ge[t]:t,i=yh(s,n),o=i.reduce((h,u)=>h+u.beats,0),r=i.reduce((h,u)=>h+mh(s,u)*u.beats,0),a=Math.floor(e/o);let l=a*r,c=e-a*o;for(const h of i){const u=Math.min(h.beats,c);if(l+=mh(s,h)*u,c-=u,c<=0)break}return l}function Dm(t,e,n){const s=yh(t,n),i=[0];let o=0;for(let r=0;o<e;r=(r+1)%s.length)o+=s[r].beats,i.push(Math.min(o,e));return i}const Nm=8;function bh(t,e,n){const s=typeof e=="string"?ge[e]:e,i=n.bpm??s.bpm,o=n.beats??(n.move?s.moves[n.move].beats:Bs(s)),r=Dm(s,o,n);if(r.every(b=>Ws(s,b,n)===0))return;const a=Math.min(n.fade??1,o/2),l=$t("ease-in-out"),c=b=>a<=0?1:Math.min(l(Math.min(1,b/a)),l(Math.min(1,(o-b)/a))),h=Math.ceil(a*Nm),u=a<=0?[]:Array.from({length:h+1},(b,k)=>[k/h*a,o-k/h*a]).flat(),d=[...new Set([...r,...u])].sort((b,k)=>b-k);let f=0;const g=d.map((b,k)=>{if(k>0){const w=d[k-1],M=Math.max(1,Math.ceil((b-w)*16));for(let S=0;S<M;S++){const A=w+(b-w)*S/M,E=w+(b-w)*(S+1)/M;f+=(Ws(s,E,n)-Ws(s,A,n))*c((A+E)/2)}}return{beat:b,travel:f}}),p=n.start??0,m=n.x??0;return{id:`${t}-x`,target:t,property:"x",keyframes:g.map(b=>({time:p+b.beat*6e4/i,value:m+n.height*b.travel,easing:"linear"}))}}function Bm(t,e,n=0){return(t-n)*e/6e4}function Wm(t,e={}){return n=>Ns(t,n,e)}function jm(t,e){const n=e.start??0,s=6e4/e.bpm,i=n+e.beats*s,o=Math.min((e.fade??1)*s,(i-n)/2);return[{id:`${t}-beat`,target:t,property:"beat",keyframes:[{time:n,value:0},{time:i,value:e.beats,easing:"linear"}]},{id:`${t}-dancing`,target:t,property:"dancing",keyframes:[{time:n,value:0},{time:n+o,value:1,easing:"ease-in-out"},{time:i-o,value:1},{time:i,value:0,easing:"ease-in-out"}]}]}function qm(t,e,n={}){const s=typeof e=="string"?ge[e]:e,i=n.bpm??s.bpm,o=n.beats??(n.move?s.moves[n.move].beats:Bs(s)),r=n.samplesPerBeat??4,a=n.start??0,l=Math.round(o*r),c=Array.from({length:l+1},(p,m)=>{const b=m/r;return{time:a+b*6e4/i,frame:Ns(s,b,n)}}),h=(p,m)=>({id:`${t}-${p}`,target:t,property:p,keyframes:c.map(b=>({time:b.time,value:m(b.frame)}))}),d=Object.keys(it).filter(p=>c.some(m=>m.frame.pose[p]!==c[0].frame.pose[p])||c[0].frame.pose[p]!==it[p]).map(p=>h(p,m=>m.pose[p])),f=n.height===void 0?void 0:bh(t,s,{...n,bpm:i,beats:o,start:a,height:n.height,fade:0});if(f&&d.push(f),n.hands===!1)return d;const g=[];for(const p of["left","right"])for(const m of Object.keys(kt)){const b=k=>k.hands?.[p]?.[m]??kt[m];c.some(k=>b(k.frame)!==kt[m])&&g.push(h(Bn(p,m),b))}return[...d,...g]}const Wn={type:"back",mode:"out",overshoot:1.1},It="ease-out-cubic",Km={label:"Disco",bpm:120,stance:{leftHip:10,rightHip:10,leftKnee:6,rightKnee:6},expression:{smile:.9,mouth:.15,leftBrow:.3,rightBrow:.3},groove:{bounce:10,accent:"down",sway:2},moves:{point:{label:"The point",beats:2,easing:It,keys:[{beat:0,pose:{rightShoulder:150,rightElbow:0,rightWrist:0,leftShoulder:40,leftElbow:-105,leftWrist:-20,lean:-5,headTilt:8,rightHip:18,leftHip:6,lookX:.6,lookY:-.7},hands:{right:"point",left:"fist"}},{beat:1,pose:{rightShoulder:-30,rightWrist:10,lean:5,headTilt:-6,rightHip:6,leftHip:18,lookX:-.4,lookY:.6}}]},roll:{label:"Roll the arms",beats:2,easing:"linear",keys:[{beat:0,pose:{leftShoulder:42,leftElbow:-128,rightShoulder:26,rightElbow:-100,rightHip:18,leftHip:6,lean:-3},hands:{left:"fist",right:"fist"}},{beat:.5,pose:{leftShoulder:26,leftElbow:-100,rightShoulder:42,rightElbow:-128}},{beat:1,pose:{leftShoulder:42,leftElbow:-128,rightShoulder:26,rightElbow:-100,rightHip:6,leftHip:18,lean:3}},{beat:1.5,pose:{leftShoulder:26,leftElbow:-100,rightShoulder:42,rightElbow:-128}}]},bump:{label:"Bump and clap",beats:4,keys:[{beat:0,pose:{lean:-10,rightHip:22,leftHip:4,leftShoulder:140,rightShoulder:140,leftElbow:0,rightElbow:0,leftWrist:20,rightWrist:20},hands:{left:"spread",right:"spread"},easing:It},{beat:1,pose:{lean:0,rightHip:10,leftHip:10,leftShoulder:168,rightShoulder:168,leftElbow:22,rightElbow:22,leftWrist:0,rightWrist:0},hands:{left:"flat",right:"flat"}},{beat:2,pose:{lean:10,rightHip:4,leftHip:22,leftShoulder:140,rightShoulder:140,leftElbow:0,rightElbow:0,leftWrist:20,rightWrist:20},hands:{left:"spread",right:"spread"},easing:It},{beat:3,pose:{lean:0,rightHip:10,leftHip:10,leftShoulder:168,rightShoulder:168,leftElbow:22,rightElbow:22,leftWrist:0,rightWrist:0},hands:{left:"flat",right:"flat"}}]}},routine:[{move:"point",beats:8},{move:"roll",beats:4},{move:"point",beats:8,mirror:!0},{move:"bump",beats:8}]},Ym={label:"Hip hop",bpm:95,stance:{leftHip:14,rightHip:14,leftKnee:20,rightKnee:20,leftShoulder:22,rightShoulder:22,leftElbow:-30,rightElbow:-30,leftFootOut:.15,rightFootOut:.15},expression:"smug",hands:{left:"relaxed",right:"relaxed"},groove:{bounce:18,accent:"down"},moves:{bounce:{label:"Bounce",beats:2,keys:[{beat:0,pose:{leftShoulder:30,rightShoulder:30,leftElbow:-50,rightElbow:-50,lean:-3,headTilt:-5,leftWrist:-20,rightWrist:-20}},{beat:1,pose:{leftShoulder:14,rightShoulder:14,leftElbow:-18,rightElbow:-18,lean:3,headTilt:5,leftWrist:0,rightWrist:0}}]},runningMan:{label:"Running man",beats:2,keys:[{beat:0,reset:!0,pose:{turn:.85,leftHip:-84,leftKnee:-112,leftAnkle:25,rightHip:-26,rightKnee:8,leftShoulder:35,leftElbow:-50,rightShoulder:45,rightElbow:75,lean:6},hands:{left:"fist",right:"fist"}},{beat:.5,pose:{leftHip:-4,leftKnee:-18,leftAnkle:0,rightHip:4,rightKnee:18,leftShoulder:5,leftElbow:-40,rightShoulder:5,rightElbow:40}},{beat:1,pose:{rightHip:84,rightKnee:112,rightAnkle:25,leftHip:26,leftKnee:-8,rightShoulder:-35,rightElbow:50,leftShoulder:-45,leftElbow:-75}},{beat:1.5,pose:{rightHip:4,rightKnee:18,rightAnkle:0,leftHip:-4,leftKnee:-18,rightShoulder:-5,rightElbow:40,leftShoulder:-5,leftElbow:-40}}]},armWave:{label:"Arm wave",beats:4,keys:[{beat:0,reset:!0,pose:{leftShoulder:90,rightShoulder:90,leftElbow:0,rightElbow:0},hands:{left:"flat",right:"flat"}},{beat:.5,pose:{leftWrist:45,leftElbow:-15}},{beat:1,pose:{leftWrist:-35,leftElbow:40,leftShoulder:84}},{beat:1.5,pose:{leftWrist:0,leftElbow:-10,leftShoulder:102,headTilt:-8}},{beat:2,pose:{leftElbow:0,leftShoulder:90,rightShoulder:102,headTilt:8}},{beat:2.5,pose:{rightShoulder:84,rightElbow:40,headTilt:0}},{beat:3,pose:{rightElbow:-15,rightWrist:45}},{beat:3.5,pose:{rightElbow:0,rightWrist:-35}}]}},routine:[{move:"bounce",beats:8},{move:"runningMan",beats:8},{move:"armWave",beats:8},{move:"bounce",beats:4}]},zm={label:"Breaking (toprock)",bpm:110,stance:{leftHip:14,rightHip:14,leftKnee:14,rightKnee:14,leftShoulder:35,rightShoulder:35,leftElbow:-90,rightElbow:-90},expression:{smile:.3,leftBrow:-.3,rightBrow:-.3,browTilt:-.3},hands:{left:"fist",right:"fist"},groove:{bounce:8,accent:"down"},moves:{toprock:{label:"Toprock (Indian step)",beats:4,keys:[{beat:0,pose:{rightHip:-24,rightKnee:10,leftHip:10,leftShoulder:80,leftElbow:40,rightShoulder:55,rightElbow:-50,lean:6,headTilt:-6},easing:It},{beat:1,reset:!0,pose:{leftHip:18,rightHip:18}},{beat:2,pose:{leftHip:-24,leftKnee:10,rightHip:10,rightShoulder:80,rightElbow:40,leftShoulder:55,leftElbow:-50,lean:-6,headTilt:6},easing:It},{beat:3,reset:!0,pose:{leftHip:18,rightHip:18}}]},kick:{label:"Kick out",beats:2,keys:[{beat:0,pose:{rightHip:72,rightKnee:4,rightAnkle:-20,leftHip:4,lean:-12,leftShoulder:100,leftElbow:20},easing:It},{beat:1,reset:!0}]},freeze:{label:"B-boy stance",beats:4,keys:[{beat:0,reset:!0,pose:{leftShoulder:26,leftElbow:-122,rightShoulder:22,rightElbow:-118,leftHip:18,rightHip:18,leftKnee:6,rightKnee:6,lean:-4,headTilt:10,smile:.6,leftEye:.6,rightEye:.6},easing:Wn},{beat:2,pose:{headTilt:14,lean:-6}}]}},routine:[{move:"toprock",beats:8},{move:"kick",beats:4},{move:"toprock",beats:8},{move:"kick",beats:4,mirror:!0},{move:"freeze",beats:4}]},Xm={label:"Jazz",bpm:130,stance:{leftHip:10,rightHip:10},expression:{mouth:.55,smile:1,mouthWidth:1.2,leftBrow:.6,rightBrow:.6},hands:{left:"spread",right:"spread"},groove:{bounce:6,accent:"up"},moves:{jazzHands:{label:"Jazz hands",beats:2,easing:"linear",keys:[0,.25,.5,.75,1,1.25,1.5,1.75].map((t,e)=>({beat:t,pose:{leftShoulder:128,rightShoulder:128,leftElbow:8,rightElbow:8,leftWrist:e%2?4:26,rightWrist:e%2?26:4,leftHip:16,rightHip:16,leftKnee:t<1?26:8,rightKnee:t<1?26:8},hands:e===0?{left:{...St.spread,turn:2},right:{...St.spread,turn:2}}:void 0}))},kickBallChange:{label:"Kick ball change",beats:2,keys:[{beat:0,reset:!0,pose:{rightHip:88,rightKnee:0,rightAnkle:55,leftHip:4,lean:-12,leftShoulder:112,rightShoulder:112,leftWrist:15,rightWrist:15},hands:{left:"flat",right:"flat"},easing:It},{beat:1,reset:!0,pose:{rightHip:10,rightKnee:24,rightAnkle:45,leftShoulder:60,rightShoulder:60,leftElbow:-20,rightElbow:-20}},{beat:1.5,pose:{rightAnkle:0,rightKnee:6,leftAnkle:45,leftKnee:20}}]},splitDrop:{label:"Drop into the splits",beats:8,keys:[{beat:0,reset:!0},{beat:2,reset:!0,pose:{leftHip:90,rightHip:90,leftKnee:0,rightKnee:0,leftAnkle:-45,rightAnkle:-45,leftShoulder:125,rightShoulder:125,leftElbow:10,rightElbow:10},easing:"ease-in-out-cubic"},{beat:4,pose:{leftShoulder:95,rightShoulder:95,leftElbow:0,rightElbow:0,leftWrist:50,rightWrist:50,headTilt:8}},{beat:6,reset:!0,pose:{leftHip:30,rightHip:30,leftKnee:60,rightKnee:60,leftShoulder:40,rightShoulder:40},easing:"ease-in-out-cubic"},{beat:7.5,reset:!0}]},jazzSquare:{label:"Jazz square",beats:4,keys:[{beat:0,reset:!0,pose:{rightHip:-18,leftHip:8,leftShoulder:38,rightShoulder:46,leftElbow:100,rightElbow:96,lean:4},hands:{left:"pinch",right:"pinch"}},{beat:1,pose:{leftHip:18,rightHip:6,leftShoulder:46,rightShoulder:38,lean:-4}},{beat:2,pose:{rightHip:22,leftHip:6,leftShoulder:38,rightShoulder:46,lean:4}},{beat:3,pose:{leftHip:10,rightHip:10,leftShoulder:46,rightShoulder:38,lean:0}}]}},routine:[{move:"jazzHands",beats:4},{move:"kickBallChange",beats:4},{move:"kickBallChange",beats:4,mirror:!0},{move:"jazzSquare",beats:8},{move:"jazzHands",beats:4},{move:"splitDrop",beats:8}]},Gm={label:"K-pop",bpm:125,stance:{leftHip:9,rightHip:9,leftKnee:4,rightKnee:4},expression:"happy",groove:{bounce:5,accent:"down"},moves:{pointCombo:{label:"Point combo",beats:4,easing:Wn,keys:[{beat:0,reset:!0,pose:{rightShoulder:142,rightElbow:0,leftShoulder:25,leftElbow:-125,headTilt:6,lean:-3,lookX:.6,lookY:-.6},hands:{right:"point",left:"flat"}},{beat:1,pose:{rightShoulder:-38,headTilt:-6,lean:3,lookX:-.3,lookY:.5,rightHip:18}},{beat:2,reset:!0,pose:{leftShoulder:36,leftElbow:-96,rightShoulder:36,rightElbow:-96,leftWrist:20,rightWrist:20},hands:{left:"fist",right:"fist"}},{beat:3,reset:!0,pose:{leftShoulder:96,rightShoulder:96,leftElbow:0,rightElbow:0,leftWrist:50,rightWrist:50,headTilt:8,leftHip:18,rightHip:18},hands:{left:"flat",right:"flat"}}]},heart:{label:"Big heart, finger heart",beats:4,keys:[{beat:0,reset:!0,pose:{leftShoulder:165,rightShoulder:165,leftElbow:46,rightElbow:46,headTilt:-8,lean:-4},hands:{left:"cupped",right:"cupped"},easing:Wn},{beat:1,pose:{headTilt:8,lean:4}},{beat:2,reset:!0,pose:{rightShoulder:32,rightElbow:112,rightWrist:10,leftShoulder:20,leftElbow:-30,headTilt:10,leftEye:0,smile:1},hands:{right:"pinch",left:"relaxed"},easing:Wn},{beat:3,pose:{headTilt:4}}]},isolations:{label:"Isolations",beats:2,easing:It,keys:[{beat:0,reset:!0,pose:{lean:-9,headTilt:11,leftShoulder:55,leftElbow:-112,rightShoulder:55,rightElbow:-112,rightHip:18},hands:{left:"fist",right:"fist"}},{beat:.5,pose:{lean:0,headTilt:0,rightHip:9}},{beat:1,pose:{lean:9,headTilt:-11,leftHip:18}},{beat:1.5,pose:{lean:0,headTilt:0,leftHip:9}}]}},routine:[{move:"pointCombo",beats:8},{move:"isolations",beats:4},{move:"heart",beats:8},{move:"pointCombo",beats:8,mirror:!0},{move:"isolations",beats:4}]},Um={label:"Bollywood",bpm:120,stance:{leftHip:10,rightHip:10},expression:{smile:1,mouth:.3,leftBrow:.4,rightBrow:.4},groove:{bounce:8,accent:"down",sway:3},moves:{lightBulb:{label:"Screw the bulb, pat the dog",beats:2,keys:[{beat:0,reset:!0,pose:{rightShoulder:160,rightElbow:12,rightWrist:-15,leftShoulder:40,leftElbow:-12,leftWrist:-45,lean:-4,rightHip:16,lookX:.5,lookY:-.6},hands:{right:{...St.cupped,roll:-30},left:{...St.flat,turn:0}}},{beat:.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{...St.cupped,roll:30}}},{beat:1,pose:{rightWrist:-15,rightElbow:12,leftWrist:-45,lean:-4,rightHip:16,leftHip:6},hands:{right:{...St.cupped,roll:-30}}},{beat:1.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{...St.cupped,roll:30}}}]},thumka:{label:"Thumka",beats:2,keys:[{beat:0,reset:!0,pose:{lean:-11,rightHip:22,leftHip:2,leftKnee:14,rightShoulder:45,rightElbow:-105,leftShoulder:128,leftElbow:18,leftWrist:35,headTilt:10,lookX:-.5},hands:{right:"fist",left:{...St.open,turn:2}},easing:It},{beat:.5,pose:{lean:-4,rightHip:12,headTilt:6}},{beat:1,pose:{lean:-11,rightHip:22,headTilt:10},easing:It},{beat:1.5,pose:{lean:-4,rightHip:12,headTilt:6}}]},flick:{label:"Cross and flick",beats:4,keys:[{beat:0,reset:!0,pose:{leftShoulder:22,rightShoulder:22,leftElbow:-62,rightElbow:-62,leftHip:16,rightHip:16,leftKnee:26,rightKnee:26},hands:{left:"fist",right:"fist"}},{beat:1,pose:{leftShoulder:132,rightShoulder:132,leftElbow:0,rightElbow:0,leftWrist:30,rightWrist:30,leftKnee:0,rightKnee:0,leftHip:10,rightHip:10,stretch:1.03},hands:{left:"spread",right:"spread"},easing:It},{beat:2,pose:{leftShoulder:22,rightShoulder:22,leftElbow:-62,rightElbow:-62,leftWrist:0,rightWrist:0,leftHip:16,rightHip:16,leftKnee:26,rightKnee:26,stretch:1},hands:{left:"fist",right:"fist"}},{beat:3,pose:{leftShoulder:62,rightShoulder:62,leftElbow:0,rightElbow:0,leftWrist:35,rightWrist:35,leftKnee:0,rightKnee:0,leftHip:10,rightHip:10},hands:{left:"spread",right:"spread"},easing:It}]}},routine:[{move:"thumka",beats:4},{move:"lightBulb",beats:8},{move:"flick",beats:8},{move:"thumka",beats:4,mirror:!0},{move:"lightBulb",beats:8,mirror:!0}]},Vm={label:"Bhangra",bpm:100,stance:{leftShoulder:150,rightShoulder:150,leftElbow:18,rightElbow:18,leftHip:10,rightHip:10},expression:{mouth:.6,smile:1,mouthWidth:1.2,leftBrow:.5,rightBrow:.5},hands:{left:"open",right:"open"},groove:{bounce:12,accent:"down"},moves:{basic:{label:"Bhangra step",beats:2,keys:[{beat:0,reset:!0,pose:{rightHip:58,rightKnee:104,rightAnkle:30,leftShoulder:162,rightShoulder:140,headTilt:7}},{beat:.5,reset:!0,pose:{stretch:.98}},{beat:1,reset:!0,pose:{leftHip:58,leftKnee:104,leftAnkle:30,rightShoulder:162,leftShoulder:140,headTilt:-7}},{beat:1.5,reset:!0,pose:{stretch:.98}}]},dhamaal:{label:"Dhamaal (jump, arms up)",beats:2,keys:[{beat:0,reset:!0,pose:{leftHip:20,rightHip:20,leftKnee:40,rightKnee:40,stretch:.94}},{beat:.5,reset:!0,pose:{rise:.07,stretch:1.06,leftHip:6,rightHip:6,leftAnkle:45,rightAnkle:45,leftShoulder:172,rightShoulder:172,leftElbow:0,rightElbow:0},hands:{left:"point",right:"point"},easing:"ease-out-quad"},{beat:1,reset:!0,pose:{leftHip:20,rightHip:20,leftKnee:40,rightKnee:40,stretch:.94},hands:{left:"open",right:"open"},easing:"ease-in-quad"},{beat:1.5,reset:!0,pose:{rise:.07,stretch:1.06,leftHip:6,rightHip:6,leftAnkle:45,rightAnkle:45,leftShoulder:172,rightShoulder:172,leftElbow:0,rightElbow:0},hands:{left:"point",right:"point"},easing:"ease-out-quad"}]}},routine:[{move:"basic",beats:8},{move:"dhamaal",beats:4},{move:"basic",beats:8},{move:"dhamaal",beats:4}]},Jm={label:"Bharatanatyam",bpm:80,stance:{...{leftHip:42,rightHip:42,leftKnee:82,rightKnee:82,leftFootOut:.3,rightFootOut:.3},leftShoulder:90,rightShoulder:90,leftElbow:0,rightElbow:0,leftWrist:75,rightWrist:75},expression:{smile:.5,leftEye:1.2,rightEye:1.2,leftBrow:.3,rightBrow:.3},hands:{left:"pataka",right:"pataka"},groove:{bounce:0},moves:{tatta:{label:"Tatta adavu (stamps)",beats:2,keys:[{beat:0,reset:!0,pose:{rightHip:48,rightKnee:104,rightAnkle:-18}},{beat:.3,reset:!0,easing:"ease-in-quad",taps:["rightToe","rightHeel"]},{beat:1,reset:!0,pose:{leftHip:48,leftKnee:104,leftAnkle:-18}},{beat:1.3,reset:!0,easing:"ease-in-quad",taps:["leftToe","leftHeel"]}]},natta:{label:"Natta adavu (stretch and look)",beats:4,keys:[{beat:0,reset:!0,pose:{rightHip:52,rightKnee:0,rightAnkle:-40,rightShoulder:125,rightWrist:60,leftShoulder:25,leftElbow:-125,leftWrist:0,headTilt:8,lookX:.9,lookY:-.4,lean:-6}},{beat:1,reset:!0},{beat:2,reset:!0,pose:{leftHip:52,leftKnee:0,leftAnkle:-40,leftShoulder:125,leftWrist:60,rightShoulder:25,rightElbow:-125,rightWrist:0,headTilt:-8,lookX:-.9,lookY:-.4,lean:6}},{beat:3,reset:!0}]},alapadma:{label:"Alapadma (lotus) to the sky",beats:4,keys:[{beat:0,reset:!0,pose:{rightShoulder:145,rightElbow:20,rightWrist:30,leftShoulder:28,leftElbow:-125,leftWrist:0,lookX:.7,lookY:-.9,headTilt:6},hands:{right:"alapadma",left:"pataka"}},{beat:1,pose:{rightWrist:55,headTilt:9}},{beat:2,reset:!0,pose:{leftShoulder:145,leftElbow:20,leftWrist:30,rightShoulder:28,rightElbow:-125,rightWrist:0,lookX:-.7,lookY:-.9,headTilt:-6},hands:{left:"alapadma",right:"pataka"}},{beat:3,pose:{leftWrist:55,headTilt:-9}}]}},routine:[{move:"tatta",beats:8},{move:"natta",beats:8},{move:"alapadma",beats:8},{move:"tatta",beats:4}]},Zm={label:"Charleston",bpm:150,stance:{leftHip:10,rightHip:10,leftKnee:10,rightKnee:10,leftShoulder:30,rightShoulder:30,leftElbow:20,rightElbow:20},expression:{mouth:.4,smile:1,leftBrow:.5,rightBrow:.5},hands:{left:{...St.spread,turn:2},right:{...St.spread,turn:2}},groove:{bounce:8,accent:"down"},moves:{basic:{label:"Kick forward, kick back",beats:4,keys:[{beat:0,reset:!0,pose:{rightHip:48,rightKnee:8,rightAnkle:45,leftShoulder:75,rightShoulder:15,leftElbow:30,rightElbow:-10,lean:-7,headTilt:-5},easing:It},{beat:1,reset:!0},{beat:2,reset:!0,pose:{leftHip:18,leftKnee:85,leftAnkle:35,rightShoulder:75,leftShoulder:15,rightElbow:30,leftElbow:-10,lean:7,headTilt:5},easing:It},{beat:3,reset:!0}]},twist:{label:"Swivel (heels in, heels out)",beats:2,keys:[{beat:0,reset:!0,pose:{leftFootOut:-.9,rightFootOut:-.9,leftHip:4,rightHip:4,leftKnee:4,rightKnee:4,leftAnkle:-10,rightAnkle:-10,leftShoulder:18,rightShoulder:48,leftElbow:-10,rightElbow:50}},{beat:.5,pose:{leftFootOut:.6,rightFootOut:.6,leftHip:16,rightHip:16,leftKnee:22,rightKnee:22,leftAnkle:10,rightAnkle:10,leftShoulder:48,rightShoulder:18,leftElbow:50,rightElbow:-10}},{beat:1,pose:{leftFootOut:-.9,rightFootOut:-.9,leftHip:4,rightHip:4,leftKnee:4,rightKnee:4,leftAnkle:-10,rightAnkle:-10,leftShoulder:18,rightShoulder:48,leftElbow:-10,rightElbow:50}},{beat:1.5,pose:{leftFootOut:.6,rightFootOut:.6,leftHip:16,rightHip:16,leftKnee:22,rightKnee:22,leftAnkle:10,rightAnkle:10,leftShoulder:48,rightShoulder:18,leftElbow:50,rightElbow:-10}}]},kneeCross:{label:"Crossing knees",beats:2,keys:[{beat:0,reset:!0,pose:{leftHip:-6,rightHip:-6,leftKnee:-16,rightKnee:-16,leftFootOut:-.4,rightFootOut:-.4,leftShoulder:-12,rightShoulder:-12,leftElbow:0,rightElbow:0,lean:0,lookY:.6}},{beat:.5,pose:{leftHip:18,rightHip:18,leftKnee:28,rightKnee:28,leftFootOut:.3,rightFootOut:.3,leftShoulder:16,rightShoulder:16,lookY:0}},{beat:1,pose:{leftHip:-6,rightHip:-6,leftKnee:-16,rightKnee:-16,leftFootOut:-.4,rightFootOut:-.4,leftShoulder:-12,rightShoulder:-12,lookY:.6}},{beat:1.5,pose:{leftHip:18,rightHip:18,leftKnee:28,rightKnee:28,leftFootOut:.3,rightFootOut:.3,leftShoulder:16,rightShoulder:16,lookY:0}}]}},routine:[{move:"basic",beats:8},{move:"twist",beats:8},{move:"kneeCross",beats:8},{move:"basic",beats:8,mirror:!0},{move:"twist",beats:4}]},Qm={label:"Tap",bpm:120,stance:{turn:.8,leftHip:-3,rightHip:3,leftKnee:-10,rightKnee:10,leftShoulder:12,rightShoulder:12,leftElbow:-40,rightElbow:40,leftWrist:-15,rightWrist:15,lean:4},expression:{smile:.9,mouth:.2,leftBrow:.3,rightBrow:.3,lookY:.3},hands:{left:"relaxed",right:"relaxed"},groove:{bounce:6,accent:"down"},moves:{shuffleBallChange:{label:"Shuffle ball change",beats:2,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:34,rightKnee:8,rightAnkle:30,leftShoulder:30,rightShoulder:-10},taps:["rightToe"]},{beat:.25,pose:{rightHip:24,rightKnee:62,rightAnkle:40},taps:["rightToe"]},{beat:.5,pose:{rightHip:-8,rightKnee:14,rightAnkle:50,leftAnkle:15,leftShoulder:12,rightShoulder:12},taps:["rightToe"]},{beat:.75,pose:{rightHip:3,rightKnee:10,rightAnkle:0,leftAnkle:0},taps:["leftHeel"]},{beat:1,reset:!0,pose:{leftHip:-34,leftKnee:-8,leftAnkle:30,rightShoulder:-30,leftShoulder:10},taps:["leftToe"]},{beat:1.25,pose:{leftHip:-24,leftKnee:-62,leftAnkle:40},taps:["leftToe"]},{beat:1.5,pose:{leftHip:8,leftKnee:-14,leftAnkle:50,rightAnkle:15,leftShoulder:12,rightShoulder:12},taps:["leftToe"]},{beat:1.75,pose:{leftHip:-3,leftKnee:-10,leftAnkle:0,rightAnkle:0},taps:["rightHeel"]}]},timeStep:{label:"Single time step",beats:4,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:8,rightKnee:4,rightAnkle:0,leftShoulder:25,rightShoulder:-20},taps:["rightToe","rightHeel"]},{beat:.5,pose:{rightHip:34,rightKnee:8,rightAnkle:30},taps:["rightToe"]},{beat:.75,pose:{rightHip:22,rightKnee:62,rightAnkle:40},taps:["rightToe"]},{beat:1,pose:{rise:.05,leftAnkle:45,leftKnee:-4,leftHip:-2,rightHip:26,rightKnee:70,stretch:1.03}},{beat:1.25,pose:{rise:0,leftAnkle:0,leftKnee:-14,stretch:1},taps:["leftToe"]},{beat:1.5,pose:{rightHip:4,rightKnee:12,rightAnkle:0,rightShoulder:25,leftShoulder:-20},taps:["rightToe"]},{beat:2,pose:{leftHip:-30,leftKnee:-6,leftAnkle:35},taps:["leftToe"]},{beat:2.25,pose:{leftHip:-4,leftKnee:-12,leftAnkle:0},taps:["leftToe"]},{beat:3,pose:{rightHip:10,rightAnkle:35,rightKnee:18,leftShoulder:12,rightShoulder:12},taps:["rightToe"]},{beat:3.5,pose:{rightHip:3,rightKnee:10,rightAnkle:0}}]},heelToe:{label:"Heel toe",beats:2,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:26,rightKnee:0,rightAnkle:-35,leftShoulder:30,rightShoulder:-20},taps:["rightHeel"]},{beat:.5,pose:{rightHip:-16,rightKnee:24,rightAnkle:55,leftShoulder:-15,rightShoulder:25},taps:["rightToe"]},{beat:1,reset:!0,pose:{leftHip:-26,leftKnee:0,leftAnkle:-35,rightShoulder:-30,leftShoulder:20},taps:["leftHeel"]},{beat:1.5,pose:{leftHip:16,leftKnee:-24,leftAnkle:55,rightShoulder:15,leftShoulder:-25},taps:["leftToe"]}]},crampRoll:{label:"Cramp roll",beats:2,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:12,rightKnee:26,leftHip:-12,leftKnee:-26}},{beat:.5,pose:{rightAnkle:40,rise:.02},taps:["rightToe"]},{beat:.625,pose:{leftAnkle:40},taps:["leftToe"]},{beat:.75,pose:{rightAnkle:0,rise:0},taps:["rightHeel"]},{beat:.875,pose:{leftAnkle:0},taps:["leftHeel"]},{beat:1,pose:{rightShoulder:135,leftShoulder:125,leftElbow:0,rightElbow:0,leftWrist:0,rightWrist:30,rightKnee:8,leftKnee:-8,rightHip:4,leftHip:-4},hands:{left:{...St.spread,turn:2},right:{...St.spread,turn:2}}},{beat:1.75,reset:!0}]}},routine:[{move:"shuffleBallChange",beats:8},{move:"timeStep",beats:4},{move:"timeStep",beats:4,mirror:!0},{move:"heelToe",beats:8},{move:"crampRoll",beats:4}]},ge={disco:Km,hipHop:Ym,breaking:zm,jazz:Xm,kpop:Gm,bollywood:Um,bhangra:Vm,bharatanatyam:Jm,charleston:Zm,tap:Qm,popping:{label:"Popping (glides, moonwalk)",bpm:100,stance:{leftHip:9,rightHip:9,leftShoulder:16,rightShoulder:16,leftElbow:-24,rightElbow:-24},expression:{smile:.35,leftEye:.85,rightEye:.85,leftBrow:-.2,rightBrow:-.2},hands:{left:"relaxed",right:"relaxed"},groove:{bounce:0},moves:{sideGlide:{label:"Side glide",beats:2,easing:"linear",travel:.2,keys:[{beat:0,reset:!0,pose:{leftHip:11,leftKnee:0,leftAnkle:0,rightHip:36,rightKnee:45,rightAnkle:45,rightShoulder:80,rightElbow:-10,rightWrist:10,leftShoulder:28,leftElbow:18,lean:-2,headTilt:4,lookX:.7},hands:{right:"flat",left:"relaxed"}},{beat:1,pose:{leftHip:27,leftKnee:54,leftAnkle:45,rightHip:-1,rightKnee:0,rightAnkle:0,rightShoulder:74,rightWrist:-10,lean:2}}]},moonwalk:{label:"Moonwalk",beats:2,easing:"linear",travel:-.29,keys:[{beat:0,reset:!0,pose:{turn:.9,lean:4,headTilt:-4,leftHip:-12,leftKnee:0,leftAnkle:0,rightHip:23,rightKnee:57,rightAnkle:45,leftShoulder:-10,leftElbow:-45,rightShoulder:14,rightElbow:50}},{beat:1,pose:{leftHip:-23,leftKnee:-57,leftAnkle:45,rightHip:12,rightKnee:0,rightAnkle:0,leftShoulder:-14,leftElbow:-50,rightShoulder:10,rightElbow:45}}]},forwardGlide:{label:"Forward glide",beats:2,easing:"linear",travel:.29,keys:[{beat:0,reset:!0,pose:{turn:.9,lean:2,leftHip:16,leftKnee:0,leftAnkle:0,rightHip:33,rightKnee:59,rightAnkle:45,leftShoulder:12,leftElbow:-40,rightShoulder:-12,rightElbow:40}},{beat:1,pose:{leftHip:-33,leftKnee:-59,leftAnkle:45,rightHip:-16,rightKnee:0,rightAnkle:0,leftShoulder:-12,leftElbow:-40,rightShoulder:12,rightElbow:40}}]},toeStand:{label:"Toe stand",beats:4,keys:[{beat:0,reset:!0,pose:{leftHip:6,rightHip:6,leftKnee:0,rightKnee:0,leftAnkle:65,rightAnkle:65,rightShoulder:150,rightElbow:75,leftShoulder:30,leftElbow:20,headTilt:-10,lookY:.4},hands:{right:"fist",left:"fist"},easing:Wn},{beat:2,pose:{headTilt:-14,lean:-2}}]}},routine:[{move:"sideGlide",beats:4},{move:"sideGlide",beats:4,mirror:!0},{move:"moonwalk",beats:8},{move:"forwardGlide",beats:8},{move:"toeStand",beats:4}]}},js=t=>Math.min(1,Math.max(0,t));function t1(t){const e={...it,turn:t.view},n=[];for(const s of t.keys){const i=n[n.length-1],o=!i||s.reset?e:i.pose;n.push({at:s.at,pose:{...o,...s.pose},easing:s.easing})}return n}function e1(t){return t-n1*Math.sin(2*Math.PI*t)/(2*Math.PI)}const n1=.5;function s1(t,e){if(!(e<=t.takeoff||e>=t.landing))return(e-t.takeoff)/(t.landing-t.takeoff)}function wh(t,e){const n=typeof t=="string"?jn[t]:t,s=t1(n),i=js(e);let o=0;for(let u=0;u<s.length;u++)s[u].at<=i&&(o=u);const r=s[o],a=s[Math.min(o+1,s.length-1)],l=a.at>r.at?(i-r.at)/(a.at-r.at):0,c=sn(r.pose,a.pose,$t(a.easing??"ease-in-out")(js(l))),h=s1(n,i);return h===void 0?{...c,spin:0,rise:0}:{...c,spin:n.spin*e1(h),rise:4*n.height*h*(1-h)}}function kh(t,e,n){const s=typeof t=="string"?jn[t]:t,i=js(e),o=js((i-s.takeoff)/(s.landing-s.takeoff));return s.travel*n*o}function i1(t,e,n={}){const s=typeof e=="string"?jn[e]:e,i=n.start??0,o=n.duration??s.duration,r=n.samples??48,a=Array.from({length:r+1},(h,u)=>{const d=u/r;return{time:i+d*o,progress:d,pose:wh(s,d)}}),c=Object.keys(it).filter(h=>a.some(u=>u.pose[h]!==it[h])).map(h=>({id:`${t}-${h}`,target:t,property:h,keyframes:a.map(u=>({time:u.time,value:u.pose[h]}))}));if(n.height!==void 0&&s.travel!==0){const h=(n.facing??1)<0?-1:1;c.push({id:`${t}-x`,target:t,property:"x",keyframes:a.map(u=>({time:u.time,value:(n.x??0)+h*kh(s,u.progress,n.height)}))})}return c}const o1={leftHip:-55,leftKnee:-95,rightHip:55,rightKnee:95,leftShoulder:45,rightShoulder:-45,leftElbow:10,rightElbow:-10,lean:22,stretch:.94,headTilt:6},r1={leftHip:0,leftKnee:0,rightHip:0,rightKnee:0,leftAnkle:55,rightAnkle:55,leftShoulder:-172,rightShoulder:172,leftElbow:0,rightElbow:0,lean:0,stretch:1.08,headTilt:0},qs={leftHip:-128,leftKnee:-152,rightHip:128,rightKnee:152,leftAnkle:30,rightAnkle:30,leftShoulder:-78,rightShoulder:78,leftElbow:-48,rightElbow:48,lean:26,stretch:1,headTilt:14},a1={leftHip:-22,leftKnee:-30,rightHip:22,rightKnee:30,leftAnkle:10,rightAnkle:10,leftShoulder:-125,rightShoulder:125,leftElbow:0,rightElbow:0,lean:8,headTilt:0},l1={leftHip:-58,leftKnee:-100,rightHip:58,rightKnee:100,leftAnkle:0,rightAnkle:0,leftShoulder:-80,rightShoulder:80,leftElbow:-10,rightElbow:10,lean:20,stretch:.93};function on(t,e,n,s,i,o=1300){return{label:t,view:1,spin:e,height:n,travel:s,takeoff:.27,landing:.8,duration:o,keys:[{at:0,reset:!0},{at:.16,pose:o1},{at:.27,pose:r1,easing:"ease-out-quad"},...i,{at:.76,pose:a1},{at:.86,pose:l1,easing:"ease-out-quad"},{at:1,reset:!0}]}}const jn={frontFlip:on("Front flip (tuck)",360,.56,.35,[{at:.38,pose:qs,easing:"ease-out-cubic"},{at:.64,pose:qs}]),backFlip:on("Back flip (tuck)",-360,.58,-.15,[{at:.36,pose:{...qs,lean:18},easing:"ease-out-cubic"},{at:.64,pose:{...qs,lean:18}}]),layout:on("Back layout (straight body)",-360,.66,-.2,[{at:.4,pose:{leftHip:8,rightHip:-8,leftKnee:0,rightKnee:0,leftAnkle:60,rightAnkle:60,leftShoulder:-178,rightShoulder:178,lean:-18,headTilt:-14}},{at:.64,pose:{leftHip:-4,rightHip:4,lean:-6,headTilt:-4,leftShoulder:-150,rightShoulder:150}}],1400),scissorFlip:on("Scissor flip",360,.6,.45,[{at:.36,pose:{leftHip:-105,leftKnee:0,rightHip:-40,rightKnee:-20,leftAnkle:50,rightAnkle:50,leftShoulder:-150,rightShoulder:150,leftElbow:0,rightElbow:0,lean:12},easing:"ease-out-cubic"},{at:.52,pose:{leftHip:40,leftKnee:20,rightHip:105,rightKnee:0,leftShoulder:-140,rightShoulder:140}},{at:.66,pose:{leftHip:-30,leftKnee:-20,rightHip:30,rightKnee:20,leftShoulder:-110,rightShoulder:110,lean:6}}]),sideFlip:{label:"Side flip (tuck)",view:0,spin:360,height:.55,travel:.4,takeoff:.27,landing:.8,duration:1300,keys:[{at:0,reset:!0},{at:.16,pose:{leftHip:22,rightHip:22,leftKnee:44,rightKnee:44,leftShoulder:20,rightShoulder:20,lean:-10,stretch:.94}},{at:.27,pose:{leftHip:4,rightHip:4,leftKnee:0,rightKnee:0,leftAnkle:55,rightAnkle:55,leftShoulder:165,rightShoulder:165,lean:6,stretch:1.08},easing:"ease-out-quad"},{at:.38,pose:{leftHip:105,rightHip:105,leftKnee:135,rightKnee:135,leftShoulder:40,rightShoulder:40,leftElbow:-95,rightElbow:-95,lean:0,stretch:1,headTilt:10},easing:"ease-out-cubic"},{at:.64,pose:{}},{at:.76,pose:{leftHip:20,rightHip:20,leftKnee:20,rightKnee:20,leftAnkle:10,rightAnkle:10,leftShoulder:100,rightShoulder:100,leftElbow:0,rightElbow:0,headTilt:0}},{at:.86,pose:{leftHip:24,rightHip:24,leftKnee:48,rightKnee:48,leftAnkle:0,rightAnkle:0,leftShoulder:70,rightShoulder:70,stretch:.93},easing:"ease-out-quad"},{at:1,reset:!0}]},cartwheel:{label:"Cartwheel",view:0,spin:360,height:.155,travel:.9,takeoff:.2,landing:.86,duration:1600,keys:[{at:0,reset:!0},{at:.12,pose:{leftShoulder:165,rightShoulder:165,rightHip:30,rightKnee:0,lean:-6}},{at:.24,pose:{leftShoulder:172,rightShoulder:172,leftHip:55,rightHip:55,leftKnee:0,rightKnee:0,leftAnkle:40,rightAnkle:40,lean:0}},{at:.75,pose:{}},{at:.9,pose:{leftHip:30,rightHip:12,leftAnkle:0,rightAnkle:0,leftShoulder:150,rightShoulder:150}},{at:1,reset:!0}]},splitLeap:on("Split leap (grand jeté)",0,.36,.9,[{at:.4,pose:{leftHip:-96,rightHip:-84,leftKnee:0,rightKnee:0,leftAnkle:55,rightAnkle:55,leftShoulder:-130,rightShoulder:-105,leftElbow:0,rightElbow:0,lean:4,headTilt:-6},easing:"ease-out-cubic"},{at:.64,pose:{lean:2}}]),toeTouch:{label:"Toe touch (straddle jump)",view:0,spin:0,height:.36,travel:0,takeoff:.27,landing:.8,duration:1200,keys:[{at:0,reset:!0},{at:.16,pose:{leftHip:22,rightHip:22,leftKnee:44,rightKnee:44,leftShoulder:-20,rightShoulder:-20,stretch:.94}},{at:.27,pose:{leftHip:4,rightHip:4,leftKnee:0,rightKnee:0,leftAnkle:55,rightAnkle:55,leftShoulder:170,rightShoulder:170,stretch:1.06},easing:"ease-out-quad"},{at:.42,pose:{leftHip:104,rightHip:104,leftShoulder:96,rightShoulder:96,leftElbow:0,rightElbow:0,stretch:1,headTilt:0},easing:"ease-out-cubic"},{at:.62,pose:{}},{at:.76,pose:{leftHip:12,rightHip:12,leftAnkle:10,rightAnkle:10,leftShoulder:120,rightShoulder:120}},{at:.86,pose:{leftHip:22,rightHip:22,leftKnee:44,rightKnee:44,leftAnkle:0,rightAnkle:0,leftShoulder:60,rightShoulder:60,stretch:.94},easing:"ease-out-quad"},{at:1,reset:!0}]},backHandspring:on("Back handspring",-360,.16,-.7,[{at:.38,pose:{leftHip:10,rightHip:-10,leftKnee:0,rightKnee:0,leftShoulder:-178,rightShoulder:178,lean:-26,headTilt:-20}},{at:.6,pose:{leftHip:-40,rightHip:40,leftKnee:-20,rightKnee:20,lean:6,headTilt:0}}],1200)},jo=.215,qo=.205,c1=.065,vh=.035,h1=.165,u1=.155,d1=12,f1=.3,p1=.7,g1=.35,m1=t=>t*Math.PI/180,mt={turn:0,lean:0,bend:0,side:0,"head.turn":0,"head.nod":0,"head.tilt":0,"arm.left.swing":0,"arm.left.spread":12,"arm.left.elbow":8,"arm.left.bend":0,"arm.right.swing":0,"arm.right.spread":12,"arm.right.elbow":8,"arm.right.bend":0,"leg.left.swing":0,"leg.left.spread":3,"leg.left.knee":0,"leg.left.ankle":0,"leg.left.toeOut":0,"leg.left.rotate":0,"leg.right.swing":0,"leg.right.spread":3,"leg.right.knee":0,"leg.right.ankle":0,"leg.right.toeOut":0,"leg.right.rotate":0,stretch:1,lift:0,roll:0,mouth:0,smile:.5,mouthWidth:1,blink:0,"eye.left":1,"eye.right":1,"brow.left":0,"brow.right":0,browTilt:0,lookX:0,lookY:0};function Ft(t={}){return{...mt,...t}}const y1=new Set(["turn","side","head.turn","head.tilt","roll","lookX"]);function b1(t){const e={};for(const[n,s]of Object.entries(t)){const i=n.replace(/(^|\.)(left|right)(\.|$)/,(o,r,a,l)=>`${r}${a==="left"?"right":"left"}${l}`);e[i]=y1.has(n)?-s:s}return e}function qt(t,e){const n={};for(const s of["left","right"])for(const[i,o]of Object.entries(e))n[`${t}.${s}.${i}`]=o;return n}const Ie={rest:mt,wave:Ft({"arm.right.spread":115,"arm.right.bend":55,"arm.right.elbow":0,"head.tilt":-6,smile:.9}),cheer:Ft({...qt("arm",{spread:140,bend:20,elbow:0}),mouth:.6,smile:1,"eye.left":0,"eye.right":0}),point:Ft({"arm.right.spread":88,"arm.right.elbow":0,"arm.right.bend":0,"head.turn":-20,smile:.4}),handsOnHips:Ft({...qt("arm",{spread:50,bend:-105,elbow:0}),...qt("leg",{spread:9}),smile:.8}),think:Ft({"arm.right.spread":22,"arm.right.bend":-150,"arm.right.elbow":0,"head.tilt":10,lookX:-.5,lookY:-.8,smile:0}),shrug:Ft({...qt("arm",{spread:35,bend:75,elbow:0}),"head.tilt":-10,smile:-.2}),sit:Ft({...qt("leg",{swing:90,knee:90,spread:4}),...qt("arm",{swing:25,elbow:45,spread:8})}),kneel:Ft({"leg.left.swing":90,"leg.left.knee":90,"leg.right.swing":-18,"leg.right.knee":108,"leg.right.ankle":16,...qt("arm",{swing:20,elbow:30})}),crouch:Ft({...qt("leg",{swing:75,knee:140,spread:6}),lean:25,...qt("arm",{swing:50,elbow:40}),"head.nod":-15}),crawl:Ft({lean:82,"head.nod":-35,...qt("arm",{swing:80,elbow:0,spread:4}),...qt("leg",{knee:92,ankle:-88})}),lieDown:Ft({roll:90,...qt("arm",{spread:8}),"head.nod":0})};function Mh(t={}){const e=t.headSize??.3,n=t.shoulderWidth??.06,s=t.hipWidth??.022,i=Math.max(.12,1-e-vh-(jo+qo)),o=l=>({id:`arm.${l}`,parent:"spine",offset:[(l==="left"?1:-1)*n,-.035,0],rest:[0,-1,0],side:l==="left"?1:-1,bones:[{length:h1,width:[1.25,.9]},{length:u1,width:[.9,.75]}]}),r=l=>({id:`leg.${l}`,parent:null,offset:[(l==="left"?1:-1)*s,0,0],rest:[0,-1,0],side:l==="left"?1:-1,bones:[{length:jo,width:[1.45,1.05]},{length:qo,width:[1.05,.85]},{length:c1,width:[.95,.7]}]}),a=(l,c)=>l[c]??mt[c]??0;return{id:"human",hipHeight:jo+qo,chains:[r("left"),r("right"),{id:"spine",parent:null,rest:[0,1,0],bones:[{length:i/2,width:[1.7,1.4]},{length:i/2,width:[1.4,1.1]}]},{id:"neck",parent:"spine",rest:[0,1,0],bones:[{length:vh,width:[1,.9]}]},o("left"),o("right")],head:{on:"neck",size:e},contacts:[...["left","right"].flatMap(l=>[{chain:`leg.${l}`,joint:1},{chain:`leg.${l}`,joint:2},{chain:`leg.${l}`,joint:3},{chain:`arm.${l}`,joint:1},{chain:`arm.${l}`,joint:2}]),{chain:"spine",joint:0},{chain:"spine",joint:1},{chain:"spine",joint:2},{head:"top"}],angles(l,c){if(c.id==="spine"){const p=-a(l,"lean")/2,m=a(l,"side")/2,b=-a(l,"bend");return[{swing:p+b*f1,spread:m},{swing:p+b*p1,spread:m}]}if(c.id==="neck")return[{swing:-a(l,"bend")*g1,spread:0}];const[h,u]=c.id.split("."),d=p=>a(l,`${h}.${u}.${p}`);if(h==="arm")return[{swing:d("swing"),spread:d("spread")},{swing:d("elbow"),spread:d("bend")}];const f=(c.side??1)*d("rotate"),g=1-Math.cos(m1(d("rotate")));return[{swing:d("swing"),spread:d("spread"),yaw:f},{swing:-d("knee"),spread:0,yaw:f},{swing:90+d("ankle")-g*(d("swing")-d("knee")),spread:0,yaw:(d1+d("toeOut"))*(c.side??1)}]},withAngles(l,c,h){const[u,d]=c.id.split("."),f=g=>`${u}.${d}.${g}`;return u==="arm"?{...l,[f("swing")]:h[0].swing,[f("spread")]:h[0].spread,[f("elbow")]:h[1].swing,[f("bend")]:h[1].spread}:u==="leg"?{...l,[f("swing")]:h[0].swing,[f("spread")]:h[0].spread,[f("knee")]:-h[1].swing}:l},boneScale(l,c){const h=Math.min(3,Math.max(.3,a(l,"stretch")));return c?.id.startsWith("arm.")?Math.sqrt(h):h},headPose(l){const c=Math.min(3,Math.max(.3,a(l,"stretch")));return{yaw:a(l,"head.turn"),nod:a(l,"head.nod"),tilt:a(l,"head.tilt"),sx:1/Math.sqrt(c),sy:Math.sqrt(c)}},landmarks:{neck:["neck",0],"shoulder.left":["arm.left",0],"elbow.left":["arm.left",1],"hand.left":["arm.left",2],"shoulder.right":["arm.right",0],"elbow.right":["arm.right",1],"hand.right":["arm.right",2],"hip.left":["leg.left",0],"knee.left":["leg.left",1],"ankle.left":["leg.left",2],"toe.left":["leg.left",3],"hip.right":["leg.right",0],"knee.right":["leg.right",1],"ankle.right":["leg.right",2],"toe.right":["leg.right",3]}}}function w1(t){const e=t.split(".");if(e[0]==="hand"&&e.length>=3){const s=`${e[1]==="left"?"Left":"Right"} hand`,i={spread:"finger spread",turn:"wrist turn",bend:"wrist bend",tilt:"wrist tilt",roll:"roll"},o=e.slice(2).join(".");return`${s} · ${i[o]??o.replace(".curl"," curl").replace(".across"," across")}`}if(e.length===3){const[s,i,o]=e;return`${`${i==="left"?"Left":"Right"} ${s}`} · ${{swing:"forward / back",spread:"out / in",elbow:"elbow bend",bend:"forearm out / in",knee:"knee bend",ankle:"foot tilt",toeOut:"toes out / in",rotate:"turn out at the hip"}[o]??o}`}return{turn:"View (front → side → back)",lean:"Lean forward / back",bend:"Back curve (line of action)",side:"Lean sideways","head.turn":"Head · turn","head.nod":"Head · nod","head.tilt":"Head · tilt",stretch:"Squash / stretch",lift:"Lift off the ground",roll:"Roll (whole figure)",mouth:"Mouth open",smile:"Smile",mouthWidth:"Mouth width",blink:"Blink","eye.left":"Left eye open","eye.right":"Right eye open","brow.left":"Left brow","brow.right":"Right brow",browTilt:"Brow slant",lookX:"Look left / right",lookY:"Look up / down"}[t]??t}const k1={leftEye:"eye.left",rightEye:"eye.right",leftBrow:"brow.left",rightBrow:"brow.right"},Ko=Object.fromEntries(Object.entries(dt).map(([t,e])=>[t,Object.fromEntries(Object.entries(e).map(([n,s])=>[k1[n]??n,s]))]));function v1(t,e){const n=Math.min(1,Math.max(0,t.turn??0)),s=1-n,i={...mt,turn:n},o=[{stick:"right",human:"left",s:1},{stick:"left",human:"right",s:-1}];for(const{stick:a,human:l,s:c}of o){const h=t[`${a}Shoulder`],u=t[`${a}Elbow`];i[`arm.${l}.spread`]=h*s,i[`arm.${l}.swing`]=c*h*n,i[`arm.${l}.bend`]=u*s,i[`arm.${l}.elbow`]=c*u*n;const d=t[`${a}Hip`],f=t[`${a}Knee`],g=s+c*n;i[`leg.${l}.rotate`]=90*s,i[`leg.${l}.spread`]=0,i[`leg.${l}.swing`]=d*g,i[`leg.${l}.knee`]=f*g,i[`leg.${l}.ankle`]=-(t[`${a}Ankle`]??0),i[`leg.${l}.toeOut`]=(t[`${a}FootOut`]??0)*M1,i[`eye.${l}`]=t[`${a}Eye`],i[`brow.${l}`]=t[`${a}Brow`],e&&Object.assign(i,S1(l,e[a]??kt,t[`${a}Wrist`]??0,n))}const r=t.bend??0;i.lean=t.lean*n,i.bend=r*n,i.side=(t.lean+r*.5)*s,i["head.tilt"]=(t.headTilt+r*.5)*s,i["head.nod"]=t.headTilt*n;for(const a of["mouth","smile","mouthWidth","blink","browTilt","lookX","lookY","stretch"])i[a]=t[a];return i.lift=t.rise??0,i.roll=t.spin??0,i}const M1=70;function S1(t,e,n,s){const i=t==="right"?1-s:1+s,o={};for(const r of Object.keys(kt))o[`hand.${t}.${r}`]=e[r]??kt[r];return o[`hand.${t}.turn`]=(e.turn??0)-i,o[`hand.${t}.roll`]=(e.roll??0)+n,o}const zt=t=>t*Math.PI/180;function Yo([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t,e*i+n*o,-e*o+n*i]}function zo([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i-e*o,t*o+e*i,n]}function me([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i+n*o,e,-t*o+n*i]}const ye=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Ks=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],Ys=(t,e)=>zo(Yo(t,e.swing),e.spread);function Xo(t,e){const n=me(t,e);return{point:{x:n[0],y:-n[1]},depth:n[2]}}function zs(t,e,n){const s=n,o=[0,t.hipHeight*s*(t.boneScale?.(e,null)??1),0],r={};for(const p of t.chains){const m=p.parent?r[p.parent]:void 0;if(p.parent&&!m)throw new Error(`body plan ${t.id}: chain ${p.id} comes before its parent ${p.parent}`);const b=p.at??(m?m.joints3.length-1:0),k=m?m.joints3[b]:o,w=m?m.frames[Math.max(0,b-1)]:{swing:0,spread:0},M=p.offset?ye(k,Ys(Ks(p.offset,s),w)):k,S=p.side??1,A=t.boneScale?.(e,p)??1,E=t.angles(e,p),$=[M],v=[];let O=w.swing,x=w.spread;p.bones.forEach((_,F)=>{const I=E[F]??{swing:0,spread:0};O+=zt(I.swing),x+=zt(I.spread)*S,v.push({swing:O,spread:x});const L=me(Ys(p.rest,{swing:O,spread:x}),zt(I.yaw??0));$.push(ye($[F],Ks(L,_.length*s*A)))}),r[p.id]={joints3:$,frames:v}}const a=r[t.head.on],l=t.headPose?.(e)??{yaw:0,nod:0,tilt:0,sx:1,sy:1},c=a.frames[a.frames.length-1],h=t.head.size/2*s,u=h*l.sx,d=h*l.sy,f=p=>Ys(me(Yo(zo(p,-zt(l.tilt)),-zt(l.nod)),zt(l.yaw)),c),g=ye(a.joints3[a.joints3.length-1],f([0,d,0]));return{height:s,root:o,chains:r,head:{center:g,rx:u,ry:d,toBody:f}}}function Go(t,e,n){const s=n.height,i=zt(90*(e.turn??0)),o=zs(t,e,s),{root:r}=o,a=o.chains,{rx:l,ry:c}=o.head,h=o.head.toBody,u=o.head.center,d={};for(const v of t.chains){const{joints3:O,frames:x}=a[v.id],_=O.map(F=>Xo(F,i));d[v.id]={id:v.id,joints3:O,frames:x,points:_.map(F=>F.point),depths:_.map(F=>F.depth)}}const f=Xo(u,i),g=[[1,0,0],[0,1,0],[0,0,1]].map(v=>me(h(v),i)),p=Xo(r,i).point,m=zt(e.roll??0),b=v=>{const O=v.x-p.x,x=v.y-p.y;return{x:p.x+O*Math.cos(m)-x*Math.sin(m),y:p.y+O*Math.sin(m)+x*Math.cos(m)}},k=([v,O,x])=>[v*Math.cos(m)+O*Math.sin(m),-v*Math.sin(m)+O*Math.cos(m),x];for(const v of Object.values(d))v.points=v.points.map(b);const w={center:b(f.point),depth:f.depth,rx:l,ry:c,angle:0,axes:g.map(k)},M=w.axes[1];w.angle=Math.atan2(M[0],M[1]);const S=v=>{if("head"in v)return{x:w.center.x+M[0]*c,y:w.center.y-M[1]*c};const O=d[v.chain];return O.points[Math.min(v.joint,O.points.length-1)]};let A=0;(n.contact??"ground")==="ground"&&(A=-Math.max(...t.contacts.map(v=>S(v).y))),A-=(e.lift??0)*s;const E=v=>({x:v.x,y:v.y+A});for(const v of Object.values(d))v.points=v.points.map(E);w.center=E(w.center);const $=t.contacts.map(v=>({spec:v,point:S(v)}));return{height:s,view:i,chains:d,head:w,hip:E(b(p)),contacts:$,groundY:Math.max(...$.map(v=>v.point.y))}}const Uo=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Sh=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function Xs(t,e,n){const s=n.height,i=zt(90*(e.turn??0)),o=zt(e.roll??0),r=zs(t,e,s),a=me(r.root,i),l=m=>ye(zo(Uo(me(m,i),a),-o),a),c={};for(const m of t.chains)c[m.id]=r.chains[m.id].joints3.map(l);const h=l(r.head.center),u=m=>Sh(Uo(l(ye(r.head.center,r.head.toBody(m))),h)),d=[u([1,0,0]),u([0,1,0]),u([0,0,1])],f=m=>{if("head"in m)return ye(h,Ks(d[1],r.head.ry));const b=c[m.chain];return b[Math.min(m.joint,b.length-1)]};let g=0;(n.contact??"ground")==="ground"&&(g=-Math.min(...t.contacts.map(m=>f(m)[1]))),g+=(e.lift??0)*s;const p=m=>[m[0],m[1]+g,m[2]];return{height:s,hip:p(a),chains:Object.fromEntries(Object.entries(c).map(([m,b])=>[m,b.map(p)])),head:{center:p(h),rx:r.head.rx,ry:r.head.ry,axes:d}}}function Gs(t,e,n,s){const i=n.height,o=zt(90*(e.turn??0)),r=zs(t,e,i),a=Xs(t,e,n),l=a.hip,c=a.chains,h=a.head.center,u=v=>{if("head"in v)return ye(h,Ks(a.head.axes[1],a.head.ry));const O=c[v.chain];return O[Math.min(v.joint,O.length-1)]},d=s.toView(l),f=s.toScreen(d),g=s.toScreen([d[0]+1,d[1],d[2]]),p=Math.hypot(g.x-f.x,g.y-f.y),m=v=>{const O=s.toView(v);return{point:s.toScreen(O),depth:O[2]*p}},b={};for(const v of t.chains){const O=c[v.id].map(m);b[v.id]={id:v.id,joints3:r.chains[v.id].joints3,frames:r.chains[v.id].frames,points:O.map(x=>x.point),depths:O.map(x=>x.depth)}}const k=s.toView(h),w=s.toScreen(k),M=s.toScreen([k[0]+1,k[1],k[2]]),S=Math.hypot(M.x-w.x,M.y-w.y),A=a.head.axes.map(v=>Sh(Uo(s.toView(ye(h,v)),k))),E={center:w,depth:k[2]*p,rx:r.head.rx*S,ry:r.head.ry*S,angle:Math.atan2(A[1][0],A[1][1]),axes:A},$=t.contacts.map(v=>({spec:v,point:m(u(v)).point}));return{height:i*p,view:o,chains:b,head:E,hip:f,contacts:$,groundY:Math.max(...$.map(v=>v.point.y))}}function Th(t,[e,n,s]){const[i,o,r]=t.axes,a=[i[0]*e*t.rx+o[0]*n*t.ry+r[0]*s*t.rx,i[1]*e*t.rx+o[1]*n*t.ry+r[1]*s*t.rx,i[2]*e*t.rx+o[2]*n*t.ry+r[2]*s*t.rx],l=Math.hypot(e,n,s)||1,c=(i[2]*e+o[2]*n+r[2]*s)/l;return{point:{x:t.center.x+a[0],y:t.center.y-a[1]},depth:t.depth+a[2],facing:c}}class Eh{positions=[];normals=[];indices=[];vertex(e,n,s,i,o,r){const a=Math.hypot(i,o,r)||1;return this.positions.push(e,n,s),this.normals.push(i/a,o/a,r/a),this.positions.length/3-1}triangle(e,n,s){this.indices.push(e,n,s)}quad(e,n,s,i){this.indices.push(e,n,s,e,s,i)}build(){return{positions:this.positions,normals:this.normals,indices:this.indices}}}function T1(t){const e=new Map,n=[];for(let i=0;i<t.positions.length/3;i++){const o=[0,1,2].map(r=>Math.round(t.positions[i*3+r]*1e6)).join(",");e.has(o)||e.set(o,i),n.push(e.get(o))}const s=new Map;for(let i=0;i<t.indices.length/3;i++)for(let o=0;o<3;o++){const r=n[t.indices[i*3+o]],a=n[t.indices[i*3+(o+1)%3]];if(r===a)continue;const l=r<a?`${r}-${a}`:`${a}-${r}`,c=s.get(l);c?c.faces.push(i):s.set(l,{a:Math.min(r,a),b:Math.max(r,a),faces:[i]})}return[...s.values()]}const Vo=Math.PI*2;function E1(t,e=16){const n=new Eh,s=Math.max(6,Math.round(e)),i=Math.max(3,Math.round(s/2)),o=[];for(let r=0;r<=i;r++){const a=r/i*Math.PI,l=[];for(let c=0;c<=s;c++){const h=c/s*Vo,u=Math.sin(a)*Math.sin(h),d=Math.cos(a),f=Math.sin(a)*Math.cos(h);l.push(n.vertex(u*t,d*t,f*t,u,d,f))}o.push(l)}for(let r=0;r<i;r++)for(let a=0;a<s;a++){const l=o[r][a],c=o[r+1][a],h=o[r+1][a+1],u=o[r][a+1];r>0&&n.triangle(l,c,u),r<i-1&&n.triangle(c,h,u)}return n.build()}function Ah(t,e,n,s,i){const o=t.vertex(0,n,0,0,s,0),r=Array.from({length:i},(a,l)=>{const c=l/i*Vo;return t.vertex(Math.sin(c)*e,n,Math.cos(c)*e,0,s,0)});for(let a=0;a<i;a++){const l=r[a],c=r[(a+1)%i];s===1?t.triangle(o,l,c):t.triangle(o,c,l)}}function Ph(t,e,n=24){const s=new Eh,i=Math.max(6,Math.round(n)),o=e/2,r=-e/2,a=h=>Array.from({length:i+1},(u,d)=>{const f=d/i*Vo;return s.vertex(Math.sin(f)*t,h,Math.cos(f)*t,Math.sin(f),0,Math.cos(f))}),l=a(r),c=a(o);for(let h=0;h<i;h++)s.quad(l[h],l[h+1],c[h+1],c[h]);return Ah(s,t,o,1,i),Ah(s,t,r,-1,i),s.build()}function Us(t){const e=Array.from({length:t.indices.length/3},()=>[]);for(const n of T1(t))for(const s of n.faces){const i=n.faces.find(o=>o!==s)??-1;e[s].push({a:n.a,b:n.b,across:i})}return{...t,faceEdges:e}}const Vs=t=>t*180/Math.PI,rn=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Jo=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],qn=t=>Math.hypot(t[0],t[1],t[2]),Zo=t=>{const e=qn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},Js=t=>Math.atan2(Math.sin(t),Math.cos(t));function $h(t){const[e,n,s]=Zo(t);return{swing:Math.asin(Math.max(-1,Math.min(1,s))),spread:Math.atan2(e,-n)}}function A1(t,e,n,s,i){const o=t.chains.find(O=>O.id===n);if(!o)throw new Error(`reach: no chain ${n} in ${t.id}`);if(o.bones.length<2||o.rest[1]>-.99)throw new Error(`reach: ${n} is not a hanging limb of two bones or more`);if(!t.withAngles)throw new Error(`reach: the ${t.id} plan cannot set angles`);const r=Go(t,{...e,turn:0,roll:0,lift:0},{height:i.height,contact:"none"}),a=r.chains[n],l=a.joints3[0],c=qn(rn(a.joints3[1],a.joints3[0])),h=qn(rn(a.joints3[2],a.joints3[1])),u=o.parent?r.chains[o.parent].frames[Math.max(0,(o.at??r.chains[o.parent].joints3.length-1)-1)]:{swing:0,spread:0},d=rn(s,l),f=Math.min(c+h-1e-6,Math.max(Math.abs(c-h)+1e-6,qn(d))),g=Zo(d),p=o.parent!==null,m=Ys(o.pole??(p?[0,-.35,-1]:[0,0,1]),u);let b=rn(m,[g[0]*Jo(m,g),g[1]*Jo(m,g),g[2]*Jo(m,g)]);qn(b)<1e-6&&(b=me([1,0,0],0)),b=Zo(b);const k=(c*c+f*f-h*h)/(2*c*f),w=Math.sqrt(Math.max(0,1-k*k)),M=[l[0]+c*(k*g[0]+w*b[0]),l[1]+c*(k*g[1]+w*b[1]),l[2]+c*(k*g[2]+w*b[2])],S=[l[0]+g[0]*f,l[1]+g[1]*f,l[2]+g[2]*f],A=o.side??1,E=$h(rn(M,l)),$=$h(rn(S,M)),v=[{swing:Vs(Js(E.swing-u.swing)),spread:Vs(Js(E.spread-u.spread))*A},{swing:Vs(Js($.swing-E.swing)),spread:Vs(Js($.spread-E.spread))*A}];return t.withAngles(e,o,v)}const P1=.34,be=.12,Zt=-.4,te=(t,e,n)=>t[e]??n,$1=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),x1=.45,_1=.35,I1=.7;function Zs(t,e,n){const s=f=>Math.sqrt(Math.max(0,1-f.x*f.x-f.y*f.y)),i=Th(t,[n.x,n.y,s(n)]).facing,o=t.axes[2],r=Math.atan2(o[0],o[2]),a=Math.cos(r),l=a>=0?1:-1,c=l*Math.max(_1,Math.abs(a)),h=l*Math.max(I1,Math.abs(a)),u=Math.cos(t.angle),d=Math.sin(t.angle);return{facing:i,points:e.map(f=>{const g=x1*Math.sin(r)+n.x*c+(f.x-n.x)*h,p=f.y+o[1]*s(f),m=g*t.rx,b=p*t.ry;return{x:t.center.x+m*u+b*d,y:t.center.y+m*d-b*u}})}}const Qs=(t,e,n,s=12)=>Array.from({length:s+1},(i,o)=>{const r=o/s,a=1-r;return{x:a*a*t.x+2*a*r*e.x+r*r*n.x,y:a*a*t.y+2*a*r*e.y+r*r*n.y}}),Qo=(t,e,n,s,i=16)=>Array.from({length:i},(o,r)=>{const a=Math.PI*2*r/i;return{x:t+Math.cos(a)*n,y:e+Math.sin(a)*s}}),xh=.05;function O1(t,e,n,s){const i=Math.max(1,Math.min(s*.6,.14*e.rx)),o=(b,k)=>Zs(e,b,k).points,r=(b,k)=>Zs(e,[],{x:b,y:k}).facing,a=te(n,"smile",0),l=te(n,"blink",0),c=te(n,"lookX",0),h=te(n,"lookY",0),u=te(n,"browTilt",0);for(const b of[1,-1]){const k=b===1?"left":"right",w=P1*b;if(r(w,be)<xh)continue;const M={x:w,y:be},S=$1(te(n,`eye.${k}`,1),l);if(S<.2){const v=a>.5?.12:-.06;t.line(o(Qs({x:w-.12,y:be},{x:w,y:be+v},{x:w+.12,y:be}),M),i)}else{if(S>1.2){const _=.13*S;t.shape(o(Qo(w,be,_*.85,_),M),"#ffffff",i)}const v=S>1.2?.075:.1,O=w+c*.08,x=be-h*.07;t.shape(o(Qo(O,x,v,v*1.1*Math.min(S,1)),M),t.ink,0)}const A=be+.3+te(n,`brow.${k}`,0)*.14+Math.max(0,S-1)*.12,E={x:w+b*.13,y:A},$={x:w-b*.13,y:A+u*.1};t.line(o([E,{x:(E.x+$.x)/2,y:(E.y+$.y)/2},$],{x:w,y:A}),i)}const d={x:0,y:Zt};if(r(0,Zt)<-xh)return;const f=.25*Math.max(.3,te(n,"mouthWidth",1)),g=Math.min(1,Math.max(0,te(n,"mouth",0)));if(g<=.05){t.line(o(Qs({x:-f,y:Zt},{x:0,y:Zt-a*.25},{x:f,y:Zt}),d),i);return}const p=.3*g;let m;if(a>.3){const b=Zt+.05;m=[...Qs({x:f,y:b},{x:0,y:Zt-p*2},{x:-f,y:b})]}else if(a<-.3){const b=Zt-p*.6;m=[...Qs({x:f,y:b},{x:0,y:Zt+p*1.4},{x:-f,y:b})]}else m=Qo(0,Zt,f*.8,p);t.shape(o(m,d),t.ink,0)}function tr(t={}){const e=(t.proportions??"bold")==="bold",n=t.figure??"fluid",s=t.look??"clean",i=t.height??300,o=n==="stick";return{plan:t.plan??Mh({headSize:t.headSize??(e?.3:.24),shoulderWidth:o?0:t.shoulderWidth??.06,hipWidth:o?0:t.hipWidth??.022}),figure:n,look:s,height:i,lineWidth:t.lineWidth??i*(e?.045:.022),ink:t.ink??(s==="pencil"?"#2f2f33":"#1e293b"),skin:t.skin??(s==="pencil"?"none":"#ffffff"),seed:t.seed??1,pencil:t.pencil??{},layers:t.layers??{},contact:t.contact??"ground",hands:t.hands??"dot",handStyle:t.handStyle??"glove",handSize:t.handSize??(t.handStyle==="natural"?.14:.17)}}function C1(t,e,n,s){const{point:i,facing:o}=Th(t,[e,n,s]);return{point:i,facing:o}}const er=t=>t.rest[1]<-.5,H1=.3;function R1(t,e,n){return t.figure==="stick"?er(e)?n.slice(0,3):n:er(e)&&n.length>=3?xe(n[0],n[1],n[2],H1):n.length===3?xe(n[0],n[1],n[2],1):n}function nr(t,e){const n=t.plan.id==="human"?{...mt,...e}:e;return ti(t,n,Go(t.plan,n,{height:t.height,contact:t.contact}))}function ti(t,e,n){const s={},i={},o={},r=.01*t.height;t.plan.chains.forEach(d=>{const f=n.chains[d.id];s[d.id]=f.points;const g=f.depths.reduce((k,w)=>k+w,0)/f.depths.length,p=d.parent?n.chains[d.parent]:void 0,m=p?p.depths[d.at??p.depths.length-1]:0,b=g-m;o[d.id]=Math.abs(b)<r?0:b,i[d.id]={points:R1(t,d,f.points),depth:g}}),i.head={points:[n.head.center],depth:n.head.depth},o.head=0;const a=[...t.plan.chains.map(d=>d.id),"head"],l=[...a].sort((d,f)=>o[d]-o[f]||a.indexOf(d)-a.indexOf(f)),c={hip:n.hip};for(const[d,[f,g]]of Object.entries(t.plan.landmarks??{})){const p=n.chains[f]?.points;p&&(c[d]=p[Math.min(g,p.length-1)])}const h={};for(const[d,f]of Object.entries(c))h[d]=f.y>=n.groundY-.01*t.height;const u={height:t.height,lineWidth:t.lineWidth,turn:e.turn??0,points:c,chains:s,parts:i,head:n.head,groundY:n.groundY,grounded:h};return{skeleton:n,joints:u,order:l}}function _h(t,e){return nr(t,e).joints}function Ih(t,e,n){const{head:s}=n;t.guideEllipse(s.center.x,s.center.y,s.rx*1.03,s.ry*1.03,s.angle);const i=Array.from({length:13},(l,c)=>({x:0,y:-.95+1.9*c/12})),o=Array.from({length:13},(l,c)=>({x:-.95+1.9*c/12,y:.12})),r=Zs(s,i,{x:0,y:0});r.facing>0&&t.guide(r.points),t.guide(Zs(s,o,{x:0,y:.12}).points),t.guide(n.chains.spine??[]);const a=e.lineWidth*.9;for(const l of["shoulder.left","shoulder.right","elbow.left","elbow.right","hip.left","hip.right","knee.left","knee.right"]){const c=n.points[l];c&&t.guideEllipse(c.x,c.y,a,a,0)}}function Oh(t,e,n,s,i,o){const r=n.lineWidth;if(i==="head"){const{head:f}=s,g=n.skin==="none"?null:n.skin;e.ellipse(f.center.x,f.center.y,f.rx,f.ry,f.angle,g,r),e.look!=="silhouette"&&O1(e,f,o,r);return}const a=n.plan.chains.find(f=>f.id===i),l=s.chains[i],c=s.parts[i].points;if(n.figure==="stick"){if(i==="neck")return;const f=i==="spine"?[...l,...s.chains.neck?.slice(1)??[]]:c;e.line(f,r);return}const h=(f,g)=>[a.bones[f].width[0]*r,a.bones[g].width[1]*r];if(er(a)){const[f,g]=h(0,1);if(e.limb(c,f,g),a.bones.length>=3)e.limb([l[2],l[3]],a.bones[2].width[0]*r,a.bones[2].width[1]*r);else if(n.hands==="cartoon"&&i.startsWith("arm."))L1(t,e,n,l,i.endsWith(".left")?"left":"right",o);else{const p=l[l.length-1];e.dot(p.x,p.y,r*.62)}return}if(i==="spine"){const f=s.points["hip.left"],g=s.points["hip.right"];f&&g&&Math.hypot(f.x-g.x,f.y-g.y)>.5&&e.limb([f,g],r*1.3,r*1.3);const[p,m]=h(0,a.bones.length-1);e.limb(c,p,m);const b=s.points["shoulder.left"],k=s.points["shoulder.right"];b&&k&&Math.hypot(b.x-k.x,b.y-k.y)>.5&&e.limb(xe(b,l[l.length-1],k,1,10),r*1.15,r*1.15);return}const[u,d]=h(0,a.bones.length-1);e.limb(c,u,d)}function Ch(t,e){const n=`hand.${e}.`,s={};for(const[r,a]of Object.entries(t))r.startsWith(n)&&(s[r.slice(n.length)]=a);const i=t.turn??0,o=e==="right"?1-i:1+i;return{...kt,...s,turn:o+(s.turn??0)}}function L1(t,e,n,s,i,o){const r=s[s.length-1],a=s[s.length-2],l=Math.atan2(r.x-a.x,-(r.y-a.y))*180/Math.PI;Cs(t,r,Ch(o,i),{size:n.handSize*n.height,side:i,angle:l,pen:e,skin:n.skin==="none"?"#ffffff":n.skin,fingers:n.handStyle==="natural"?5:4,plump:n.handStyle==="natural"?1.15:1.6,lineWidth:n.lineWidth*.3})}function Hh(t,e,n,s=0){const i=e.plan.id==="human"?{...mt,...n}:n;Lh(t,e,i,nr(e,i),s)}function sr(t,e){const n=e/t.height;return{...t,height:e,lineWidth:t.lineWidth*n}}function F1(t,e,n,s){const i=t.plan.id==="human"?{...mt,...e}:e,o=Gs(t.plan,i,{height:s.height,contact:t.contact},n);return ti(sr(t,o.height),i,o).joints}function D1(t,e,n,s,i){const o=e.plan.id==="human"?{...mt,...n}:n,r=Gs(e.plan,o,{height:i.height,contact:e.contact},s),a=sr(e,r.height);Lh(t,a,o,ti(a,o,r),i.time??0)}function Rh(t,e,n,s){const i=t.plan.id==="human"?{...mt,...e}:e,o=Gs(t.plan,i,{height:s.height,contact:t.contact},n),r=sr(t,o.height),{joints:a,order:l}=ti(r,i,o),c=o.height/s.height;return l.map((h,u)=>({part:h,depth:(a.parts[h]?.depth??0)/c,draw(d,f=0){const g=Hn(d,{look:r.look,ink:r.ink,lineWidth:r.lineWidth,seed:Kt(`${r.seed}:${h}`),time:f,pencil:r.pencil}),p=b=>{b&&(d.save(),b(d,a,g,f),d.restore())};d.save(),d.lineCap="round",d.lineJoin="round",u===0&&(r.look==="pencil"&&r.pencil.construction!==!1&&Ih(g,r,a),p(r.layers.behind));const m=r.layers.parts?.[h];p(m?.under),Oh(d,g,r,a,h,i),p(m?.over),u===l.length-1&&p(r.layers.front),d.restore()}}))}function Lh(t,e,n,s,i){const{joints:o,order:r}=s,a=Hn(t,{look:e.look,ink:e.ink,lineWidth:e.lineWidth,seed:e.seed,time:i,pencil:e.pencil}),l=c=>{c&&(t.save(),c(t,o,a,i),t.restore())};t.save(),t.lineCap="round",t.lineJoin="round",e.look==="pencil"&&e.pencil.construction!==!1&&Ih(a,e,o),l(e.layers.behind);for(const c of r){const h=e.layers.parts?.[c];l(h?.under),Oh(t,a,e,o,c,n),l(h?.over)}l(e.layers.front),t.restore()}function N1(t,e,n){const s={...t};for(const[i,o]of Object.entries(e)){const r=t[i]??o;s[i]=r+(o-r)*n}return s}function B1(t,e,n,s){const i=t.plan.id==="human"?{...mt,...e}:e;let o;if(Array.isArray(s))o=s;else{const{skeleton:r}=nr(t,i),a=Go(t.plan,{...i,roll:0},{height:t.height,contact:"none"}),l=(i.roll??0)*Math.PI/180,c=s.x-r.hip.x,h=s.y-r.hip.y,u=a.hip.x+c*Math.cos(-l)-h*Math.sin(-l),d=a.hip.y+c*Math.sin(-l)+h*Math.cos(-l),f=Math.PI/2*(i.turn??0),g=s.depth??r.chains[n].depths[r.chains[n].depths.length-1],p=Math.cos(f),m=Math.sin(f);o=[u*p-g*m,-d,u*m+g*p]}return A1(t.plan,i,n,o,{height:t.height})}function W1(t){const{character:e}=t,n=e.height*.8,s=e.height,i=e.plan.id==="human"?mt:{};return{type:"custom",x:t.x-n/2,y:t.y-s,width:n,height:s,props:{...i,...t.pose},character:e,draw(o,r,a){o.translate(n/2,s),Hh(o,e,r.props,a)}}}function Fh(t,e,n){const s=o=>({x:o.x+e,y:o.y+n}),i=o=>Object.fromEntries(Object.entries(o).map(([r,a])=>[r,a.map(s)]));return{...t,points:Object.fromEntries(Object.entries(t.points).map(([o,r])=>[o,s(r)])),chains:i(t.chains),parts:Object.fromEntries(Object.entries(t.parts).map(([o,r])=>[o,{...r,points:r.points.map(s)}])),head:{...t.head,center:s(t.head.center)},groundY:t.groundY+n}}function j1(t,e,n){const s=t.character;if(!s)throw new Error("characterAt: the target was not made by characterTarget");const i={...t.props};let o=0,r=0;for(const[l,c]of e.state?.values.get(n)??[])typeof c=="number"&&(l==="x"||l==="motionPathX"?o=c:l==="y"||l==="motionPathY"?r=c:l in i&&(i[l]=c));const a=_h(s,i);return{pose:i,joints:Fh(a,t.x+o+t.width/2,t.y+r+t.height)}}function ir(t,e=mt){const n=[];return t.forEach((s,i)=>{const o=i===0?e:n[i-1],r=typeof s.pose=="string"?Ie[s.pose]:void 0;n.push(r?{...r,turn:o.turn??0}:{...o,...s.pose})}),n}function q1(t,e,n=mt){const s=ir(e,n);return Object.keys(n).filter(o=>s.some(r=>(r[o]??n[o])!==n[o])).map(o=>({id:`${t}-${o}`,target:t,property:o,keyframes:e.map((r,a)=>({time:r.time,value:s[a][o]??n[o],...r.easing?{easing:r.easing}:{}}))}))}const or=new Map;function K1(t){const e=or.get(t);if(e)return e;let n=[1,1,1];const s=t.trim().replace("#","");if(t.trim().startsWith("#")&&(s.length===3||s.length===6)){const i=s.length===3?s.split("").map(o=>o+o).join(""):s;n=[0,2,4].map(o=>Number.parseInt(i.slice(o,o+2),16)/255)}else{const i=t.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/);i&&(n=[Number(i[1])/255,Number(i[2])/255,Number(i[3])/255])}return or.size<512&&or.set(t,n),n}Te([-3,-5,-4]);const Y1=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)};function Dh(t,e,n){const s=[0,0,0];for(const i of n){const o=K1(i.color);let r;if(i.light==="ambient")r=i.intensity;else if(i.light==="directional")r=i.intensity*Math.max(0,-he(e,i.direction));else{const a=Ue(i.position,t),l=bs(a),c=l>0?Ve(a,1/l):e,h=i.range?Math.max(0,1-l/i.range)**2:1;if(r=i.intensity*Math.max(0,he(e,c))*h,i.light==="spot"){const u=Math.cos(i.angle*Math.PI/180),d=Math.cos(i.angle*.8*Math.PI/180);r*=Y1(u,d,-he(c,i.direction))}}s[0]+=o[0]*r,s[1]+=o[1]*r,s[2]+=o[2]*r}return s}function Nh(t,e){return t?Math.min(1,Math.max(0,(e-t.near)/(t.far-t.near))):0}function rr(t,e,n={}){t.save(),z1(t,e,n),t.restore()}function z1(t,e,n){const s=ar(e,n);n.shadow!==!1&&lr(t,e,n);for(const i of e.under)ur(t,i,s,n);if(n.rider){if(t.save(),e.openings.length>0){t.beginPath();for(const i of e.openings){t.moveTo(i[0].x,i[0].y);for(const o of i.slice(1))t.lineTo(o.x,o.y);t.closePath()}t.clip("nonzero")}n.rider(t),t.restore()}for(const i of e.over)ur(t,i,s,n)}function ar(t,e={}){return e.lineWidth??Math.max(1.3,t.sizePx*.022)}function lr(t,e,n={}){e.shadow.opacity<=0||e.shadow.points.length<3||(t.save(),t.globalAlpha=e.shadow.opacity,ei(t,e.shadow.points,n.ink??"#26262b",!1),t.restore())}function X1(t,e,n,s={}){t.save(),ur(t,e,n,s),t.restore()}function Bh(t,e,n,s={}){const i=s.style==="stick",o=e.flatMap(h=>{if(i&&h.part.solidOnly)return[];const u=h.part.layer??0;return i&&h.spine?[{depth:h.depth,layer:u,part:h}]:h.faces.map(d=>({depth:d.depth,layer:u,part:h,face:d}))}),r=new Map;for(const h of o){const u=h.face?.normal;if(!h.face?.center||!u)continue;const d=Math.abs(u[0])>=Math.abs(u[1])&&Math.abs(u[0])>=Math.abs(u[2])?0:Math.abs(u[1])>=Math.abs(u[2])?1:2,f=d*2+(u[d]<0?1:0);r.set(f,[...r.get(f)??[],h])}for(const h of r.values())for(const u of h){const{center:d,normal:f}=u.face;for(const g of h){if(g.part.part.id===u.part.part.id)continue;const p=g.face;if(p.normal[0]*f[0]+p.normal[1]*f[1]+p.normal[2]*f[2]<=.8)continue;const b=p.normal[0]*(d[0]-p.center[0])+p.normal[1]*(d[1]-p.center[1])+p.normal[2]*(d[2]-p.center[2]);b>-Wh/5&&b<Wh&&(u.layer=Math.max(u.layer,g.layer),u.depth=Math.max(u.depth,g.depth+1e-6))}}o.sort((h,u)=>h.layer-u.layer||h.depth-u.depth);const a=new Map,l=h=>{let u=a.get(h.part.id);return u||a.set(h.part.id,u=cr(t,h,n,s)),u};t.save();const c=t.globalAlpha;for(const{part:h,face:u}of o){t.globalAlpha=c*h.opacity;const d=l(h);if(!u)d.line(h.spine,n*1.15);else{const f=i?jh(h,s):u.light?G1(h,u,s):hr(h);f&&(!i&&s.look==="silhouette"?d.shape(u.points,f,0):ei(t,u.points,i||u.light?f:ni(f,u.tone),!0,h.cut?1.6:.8));const g=(h.part.outline??1)*n;if(g>0)for(const p of u.edges??[])p.length>1&&d.line(p,g);for(const p of u.marks??[])d.line(p,n*.7)}}t.restore()}const Wh=.05;function cr(t,e,n,s){return Hn(t,{look:s.look??"clean",ink:e.part.ink??s.ink??"#26262b",lineWidth:n,seed:Kt(`${s.seed??0}:${e.part.id}`),time:s.time??0,pencil:{construction:!1,rubbedOut:0,...s.pencil}})}function hr(t){const{part:e}=t;return e.glow&&t.glow>0&&e.fill?pr(e.fill,e.glow.color,t.glow):e.fill}function G1(t,e,n){const{part:s}=t;if(!s.fill)return;const i=fr(s.fill,e.light,e.fog??0,n.fog);return s.glow&&t.glow>0?pr(i,s.glow.color,t.glow):i}function jh(t,e){const n=hr(t);return n&&(V1(n)||t.glow>0)?n:e.paper??"#fbf8ef"}function ur(t,e,n,s){e.opacity<1?(t.save(),t.globalAlpha*=e.opacity,qh(t,e,n,s),t.restore()):qh(t,e,n,s)}function qh(t,e,n,s){if(s.style==="stick")return U1(t,e,n,s);const{part:i}=e,o=cr(t,e,n,s),r=hr(e),a=s.look==="silhouette";for(const c of e.faces)r&&(a?o.shape(c.points,r,0):ei(t,c.points,ni(r,c.tone)));const l=(i.outline??1)*n;if(l>0)for(const c of e.edges)c.length>1&&o.line(c,l);for(const c of e.marks)o.line(c,n*.7)}function U1(t,e,n,s){const{part:i}=e;if(i.solidOnly)return;const o=cr(t,e,n,s);if(e.spine){o.line(e.spine,n*1.15);return}const r=jh(e,s);for(const l of e.faces)ei(t,l.points,r);const a=(i.outline??1)*n;if(a>0)for(const l of e.edges)l.length>1&&o.line(l,a);for(const l of e.marks)o.line(l,n*.7)}function V1(t){const e=an(t);return e?(.299*e[0]+.587*e[1]+.114*e[2])/255<.3:!1}function ei(t,e,n,s=!0,i=.8){t.fillStyle=n,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let o=1;o<e.length;o++)t.lineTo(e[o].x,e[o].y);t.closePath(),t.fill(),s&&(t.strokeStyle=n,t.lineWidth=i,t.lineJoin="round",t.stroke())}function an(t){const e=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim());if(!e)return;const n=e[1].length===3?e[1].replace(/./g,s=>s+s):e[1];return[0,2,4].map(s=>parseInt(n.slice(s,s+2),16))}const dr=t=>`#${t.map(e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0")).join("")}`;function ni(t,e){const n=an(t);return n?dr(e>=1?n.map(s=>s+(255-s)*(e-1)*2):n.map(s=>s*e)):t}function fr(t,e,n,s){const i=an(t);if(!i)return t;let o=i.map((a,l)=>a*e[l]);const r=s?an(s):void 0;return r&&n>0&&(o=o.map((a,l)=>a+(r[l]-a)*n)),dr(o)}function pr(t,e,n){const s=an(t),i=an(e);return!s||!i?n<.5?t:e:dr(s.map((o,r)=>o+(i[r]-o)*n))}const Kh=40,J1=.215+.205,Dt=(t,e)=>{const n={};for(const s of["left","right"])for(const[i,o]of Object.entries(e))n[`${t}.${s}.${i}`]=o;return n},lt=(t,e)=>t[e]??mt[e]??0;function Yh(t,e,n=mt,s=1){const i=Fn(t),o=e*Math.PI*2,r=Math.sin(o)*s,a=Math.cos(o)*s,l=(1+Math.cos(o*2*(i.bounces??1)))/2,c=i.crouch??0,h=i.shoulder??0,u=i.forearm??0,d={...mt,...n};d["leg.left.swing"]=i.swing*r+c*.6,d["leg.right.swing"]=-i.swing*r+c*.6,d["leg.left.knee"]=i.knee*Math.max(0,a)+c*1.2,d["leg.right.knee"]=i.knee*Math.max(0,-a)+c*1.2,d["leg.left.ankle"]=lt(n,"leg.left.ankle")-(i.tiptoe??0),d["leg.right.ankle"]=lt(n,"leg.right.ankle")-(i.tiptoe??0);for(const[f,g]of[["left",-1],["right",1]])lt(n,`arm.${f}.spread`)>Kh||lt(n,`arm.${f}.swing`)>Kh||(d[`arm.${f}.swing`]=h+g*i.arm*r,d[`arm.${f}.elbow`]=lt(n,`arm.${f}.elbow`)+u+i.elbow*Math.max(0,g*r));return d.lean=lt(n,"lean")+i.lean*s,d.bend=lt(n,"bend")+(i.bend??0),d["head.nod"]=lt(n,"head.nod")-i.lean*.5*s+(i.headTilt??0),d.side=lt(n,"side")+(i.sway??0)*Math.sin(o),d.lift=lt(n,"lift")+(i.bounce??0)*s*l,d.stretch=lt(n,"stretch")*(1+(i.squash??0)*(l-.5)),d}function zh(t,e,n=1){const s=Fn(t);return 4*J1*e*Math.sin(s.swing*n*Math.PI/180)}const ln=t=>Ko[t],si={take:t=>[{after:140,pose:{stretch:.8,bend:10,lean:lt(t,"lean")-4,...Dt("arm",{spread:6,swing:0,elbow:10}),"eye.left":.35,"eye.right":.35,"brow.left":-.6,"brow.right":-.6,mouth:0},easing:"ease-in-out"},{after:260,pose:{stretch:.78}},{after:360,pose:{lift:.22,stretch:1.35,bend:-14,...Dt("arm",{spread:150,bend:35,swing:0,elbow:0}),...Dt("leg",{swing:25,knee:60}),...ln("shocked")},easing:"ease-out-cubic"},{after:720,pose:{lift:.25,stretch:1.25,bend:-10,...Dt("arm",{spread:140})},easing:"ease-in-out"},{after:900,pose:{lift:0,stretch:.74,bend:12,...Dt("arm",{spread:70,bend:0}),...Dt("leg",{swing:30,knee:60})},easing:"ease-in-quad"},{after:1060,pose:{stretch:1.06,bend:-3,...Dt("arm",{spread:60}),"leg.left.swing":lt(t,"leg.left.swing"),"leg.right.swing":lt(t,"leg.right.swing"),"leg.left.knee":lt(t,"leg.left.knee"),"leg.right.knee":lt(t,"leg.right.knee")},easing:"ease-out"},{after:1260,pose:{stretch:lt(t,"stretch"),bend:lt(t,"bend"),...ln("surprised"),...Dt("arm",{spread:55,bend:60})},easing:"ease-in-out"}],doubleTake:t=>[{after:160,pose:{lookX:1,lookY:0,"head.turn":0},easing:"ease-out"},{after:520,pose:{lookX:-.6,"head.turn":30,"head.nod":lt(t,"head.nod")-4,smile:.6,mouth:0},easing:"ease-in-out"},{after:1100,pose:{lookX:-.6}},{after:1180,pose:{"head.turn":0,"head.nod":lt(t,"head.nod")-10,bend:lt(t,"bend")-10,lift:.05,stretch:1.18,...ln("shocked"),lookX:1,lookY:0},easing:"ease-out-cubic"},{after:1360,pose:{lift:0,stretch:.88,"head.nod":lt(t,"head.nod")-4,bend:lt(t,"bend")+4},easing:"ease-in-quad"},{after:1560,pose:{stretch:lt(t,"stretch"),"head.nod":lt(t,"head.nod"),bend:lt(t,"bend")},easing:{type:"elastic",mode:"out",amplitude:1,period:.35}}],windUp:()=>[{after:220,pose:{lean:-18,bend:-16,"head.nod":-6,"arm.left.swing":60,"arm.left.elbow":100,"arm.right.swing":-40,"arm.right.elbow":90,"leg.left.swing":55,"leg.left.knee":95,stretch:.92,...ln("angry"),lookX:1},easing:"ease-out"},{after:620,pose:{lean:-20,bend:-18,stretch:.9}},{after:700,pose:{lean:28,bend:14,"head.nod":6,"arm.left.swing":-30,"arm.right.swing":60,"leg.left.swing":-20,"leg.left.knee":30,"leg.right.swing":20,stretch:1.12},easing:"ease-out-cubic"}],land:t=>[{after:120,pose:{lift:0,stretch:.7,bend:14,...Dt("arm",{spread:75}),...Dt("leg",{swing:25,knee:50})},easing:"ease-in-quad"},{after:300,pose:{stretch:1.05,bend:-4,"arm.left.spread":lt(t,"arm.left.spread"),"arm.right.spread":lt(t,"arm.right.spread")},easing:"ease-out"},{after:460,pose:{lift:0,stretch:lt(t,"stretch"),bend:lt(t,"bend"),...Dt("leg",{swing:0,knee:0})},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...ln("scared"),...Dt("arm",{swing:40,elbow:110,spread:14}),stretch:.94,bend:lt(t,"bend")+8},easing:"ease-out"}];for(let n=1;n<=14;n++){const s=n%2===0?1:-1;e.push({after:80+n*45,pose:{side:lt(t,"side")+2.5*s,"head.tilt":lt(t,"head.tilt")-2*s}})}return e.push({after:755,pose:{side:lt(t,"side"),"head.tilt":lt(t,"head.tilt"),bend:lt(t,"bend")}}),e},deflate:t=>[{after:260,pose:{stretch:1.04,"head.nod":lt(t,"head.nod")-4,"brow.left":.3,"brow.right":.3},easing:"ease-in-out"},{after:900,pose:{...ln("sad"),bend:18,stretch:.92,lean:lt(t,"lean")+5,"head.nod":14,...Dt("arm",{spread:6,swing:0,elbow:4,bend:0})},easing:"ease-in-out"}]};function Xh(t,e){const n=Ft(e.from??{}),s=e.speed??1;let i=n;return[{time:e.at,pose:n},...si[t](n).map(o=>(i={...i,...o.pose},{time:e.at+o.after*s,pose:i,act:!1,...o.easing?{easing:o.easing}:{}}))]}const Z1=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),Q1=new Set(["walk","walking","gait"]),Gh=t=>typeof t=="number"?t:void 0,ty=1.7;function ey(t,e,n){const s=Array.from({length:24},(i,o)=>{const r=o/24*Math.PI*2,a=e.toView([Math.cos(r)*n,0,Math.sin(r)*n*.8]);return a[2]<-.001?e.toScreen(a):null});s.some(i=>i===null)||(t.beginPath(),s.forEach((i,o)=>o===0?t.moveTo(i.x,i.y):t.lineTo(i.x,i.y)),t.closePath(),t.fillStyle="rgba(0, 0, 0, 0.22)",t.fill())}function ny(t){const e=he([0,1,0],t);if(e>.999999)return ws();if(e<-.999999)return Yt(Bt([1,0,0],180));const n=ys([0,1,0],t);return Yt(Bt(n,Math.acos(e)*180/Math.PI))}function sy(t,e,n,s,i){const o=t.solid??{},r=o.outline===!1?void 0:o.outline??{width:2,color:"#0f172a"},a={color:o.color??"#475569",shading:o.shading??"toon",outline:r},l={color:o.skin??"#f2c49b",shading:o.shading??"toon",outline:r},c={color:"#0f172a",shading:"unlit"},h=s.height*.034,u=[],d=(w,M,S)=>u.push({mesh:w,world:bt(i,M),material:S}),f=(w,M,S)=>d(e.sphere,eo(w,[0,0,0,1],[M,M,M]),S);for(const w of n.chains){const M=s.chains[w.id],S=w.id==="spine"?1.9:1;w.bones.forEach((A,E)=>{const $=M[E],v=M[E+1],O=to($,v),[x,_]=A.width??[1,1],F=h*S*(x+_)/2;if(O>1e-6){const I=bl($,v,.5),L=ny(Te(Ue(v,$)));d(e.cylinder,bt(Ee(I),bt(L,Ae([F,O,F]))),a)}f($,h*S*x,a),f(v,h*S*_,a)}),w.id.startsWith("arm.")&&f(M[M.length-1],h*1.5,l)}const{center:g,rx:p,ry:m,axes:b}=s.head,k=[...b[0],0,...b[1],0,...b[2],0,...g,1];d(e.sphere,bt(k,Ae([p,m,p])),l);for(const w of[-1,1]){const M=Te([w*.36,.15,.92]),S=ms(g,ms(ms(Ve(b[0],M[0]*p*1.04),Ve(b[1],M[1]*m*1.04)),Ve(b[2],M[2]*p*1.04))),A=[...b[0],0,...b[1],0,...b[2],0,...S,1];d(e.sphere,bt(A,Ae([p*.11,m*.14,p*.03])),c)}return u}const iy={kind:"character",validate(t){const e=t;return e.height!==void 0&&!(e.height>0)?["a character's height must be positive"]:[]},prepare(t){return{who:tr({...t.character,height:1}),cylinder:Us(Ph(1,1,16)),sphere:Us(E1(1,20))}},resolve({object:t,prepared:e,values:n,world:s,camera:i,lights:o=[],fog:r,toScreen:a}){const l=t,c=e,h=c.who;let u={...mt,...l.pose};for(const[$,v]of n)typeof v=="number"&&!Z1.has($)&&!Q1.has($)&&(u[$]=v);const d=Math.max(0,Math.min(1,Gh(n.get("walking"))??l.walking??0));if(d>0){const $=typeof n.get("gait")=="string"?n.get("gait"):l.gait,v=Yh($,Gh(n.get("walk"))??0,u);u=Object.fromEntries(Object.keys({...u,...v}).map(O=>[O,(u[O]??0)+((v[O]??0)-(u[O]??0))*d]))}const f=l.height??ty,g=bt(i.view,s),p={toView:$=>Ct(g,$),toScreen:$=>a($)},b=-p.toView([0,f/2,0])[2];if(b<=i.near)return null;const k=l.shadow===!1?[]:[{depth:b+f,draw:$=>ey($,p,f*.18)}];if(l.look==="solid"){const $=Xs(h.plan,u,{height:f,contact:h.contact});return{meshes:sy(l,c,h.plan,$,s),drawables:k}}const w=Ct(s,[0,f*.6,0]),M=Te(Ue(i.position,w)),S=Dh(w,M,o).map($=>Math.min(1,$)),A=o.length>0&&h.skin!=="none"?{...h,skin:fr(h.skin,S,Nh(r,to(w,i.position)),r?.color)}:h,E=Rh(A,u,p,{height:f});return{drawables:[...k,...E.map(($,v)=>({depth:-$.depth-v*1e-6,draw:(O,x)=>$.draw(O,x.time)}))]}}},Kn=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function Uh([t,e,n]){const[s,i,o]=[t/2,e/2,n/2];return{vertices:[[-s,-i,-o],[s,-i,-o],[s,i,-o],[-s,i,-o],[-s,-i,o],[s,-i,o],[s,i,o],[-s,i,o]],faces:[{corners:[4,5,6,7],normal:[0,0,1]},{corners:[1,0,3,2],normal:[0,0,-1]},{corners:[5,1,2,6],normal:[1,0,0]},{corners:[0,4,7,3],normal:[-1,0,0]},{corners:[7,6,2,3],normal:[0,1,0]},{corners:[0,1,5,4],normal:[0,-1,0]}]}}const cn=(t,[e,n,s])=>t==="z"?[e,n,s]:t==="x"?[s,n,e]:[e,s,n];function Vh(t,e,n="x",s=20,i=0){const o=[],r=e/2;for(const c of[-r,r])for(let h=0;h<s;h++){const u=Math.PI*2*h/s;o.push(cn(n,[Math.cos(u)*t,Math.sin(u)*t,c]))}const a=[{corners:Array.from({length:s},(c,h)=>s-1-h),normal:cn(n,[0,0,-1])},{corners:Array.from({length:s},(c,h)=>s+h),normal:cn(n,[0,0,1])}];for(let c=0;c<s;c++){const h=(c+1)%s,u=Math.PI*2*(c+.5)/s;a.push({corners:[c,h,s+h,s+c],normal:cn(n,[Math.cos(u),Math.sin(u),0])})}const l=[];if(i>0)for(const c of[-r,r]){const h=o.push(cn(n,[0,0,c*1.01]))-1;for(let u=0;u<i;u++){const d=Math.PI*2*u/i,f=o.push(cn(n,[Math.cos(d)*t*.82,Math.sin(d)*t*.82,c*1.01]))-1;l.push([h,f])}}return{vertices:o,faces:a,marks:l,creases:!0}}function Jh([t,e,n],s=16){const i=Math.max(4,Math.round(s/2)),o=[[0,e,0]];for(let h=1;h<i;h++){const u=Math.PI*h/i;for(let d=0;d<s;d++){const f=Math.PI*2*d/s;o.push([Math.sin(u)*Math.cos(f)*t,Math.cos(u)*e,Math.sin(u)*Math.sin(f)*n])}}const r=o.push([0,-e,0])-1,a=(h,u)=>1+(h-1)*s+u%s,l=h=>{const u=h.reduce((d,f)=>[d[0]+o[f][0],d[1]+o[f][1],d[2]+o[f][2]],[0,0,0]);return Kn([u[0]/(t*t),u[1]/(e*e),u[2]/(n*n)])},c=[];for(let h=0;h<s;h++){const u=[0,a(1,h+1),a(1,h)];c.push({corners:u,normal:l(u)});for(let f=1;f<i-1;f++){const g=[a(f,h),a(f,h+1),a(f+1,h+1),a(f+1,h)];c.push({corners:g,normal:l(g)})}const d=[a(i-1,h),a(i-1,h+1),r];c.push({corners:d,normal:l(d)})}return{vertices:o,faces:c,creases:!1}}const oy=t=>t.reduce((e,[n,s],i)=>{const[o,r]=t[(i+1)%t.length];return e+n*r-o*s},0)/2;function Zh(t,e){const n=oy(t)<0?[...t].reverse():t,s=n.length,i=e/2,o=[...n.map(([a,l])=>[i,l,a]),...n.map(([a,l])=>[-i,l,a])],r=[{corners:Array.from({length:s},(a,l)=>s-1-l),normal:[1,0,0]},{corners:Array.from({length:s},(a,l)=>s+l),normal:[-1,0,0]}];for(let a=0;a<s;a++){const l=(a+1)%s,[c,h]=[n[l][0]-n[a][0],n[l][1]-n[a][1]];r.push({corners:[a,l,s+l,s+a],normal:Kn([0,-c,h])})}return{vertices:o,faces:r,creases:!0}}function Qh(t,e){const n={left:([i,o])=>[0,o,i],right:([i,o])=>[0,o,i],front:([i,o])=>[i,o,0],back:([i,o])=>[i,o,0],up:([i,o])=>[i,0,o]},s={left:[1,0,0],right:[-1,0,0],front:[0,0,1],back:[0,0,-1],up:[0,1,0]};return{vertices:t.map(n[e]),faces:[{corners:t.map((i,o)=>o),normal:s[e]}]}}function tu(t,e,n=8){const s=r=>Array.isArray(e)?e[Math.min(r,e.length-1)]:e,i=[],o=[];t.forEach((r,a)=>{const l=t[Math.min(a+1,t.length-1)],c=t[Math.max(a-1,0)],h=Kn([l[0]-c[0],l[1]-c[1],l[2]-c[2]]),u=Math.abs(h[1])<.9?[0,1,0]:[1,0,0],d=Kn(eu(h,u)),f=eu(d,h);for(let g=0;g<n;g++){const p=Math.PI*2*g/n,m=Math.cos(p)*s(a),b=Math.sin(p)*s(a);i.push([r[0]+d[0]*m+f[0]*b,r[1]+d[1]*m+f[1]*b,r[2]+d[2]*m+f[2]*b])}});for(let r=0;r<t.length-1;r++)for(let a=0;a<n;a++){const l=(a+1)%n,c=[r*n+a,r*n+l,(r+1)*n+l,(r+1)*n+a],h=c.reduce((d,f)=>[d[0]+i[f][0]/4,d[1]+i[f][1]/4,d[2]+i[f][2]/4],[0,0,0]),u=[(t[r][0]+t[r+1][0])/2,(t[r][1]+t[r+1][1])/2,(t[r][2]+t[r+1][2])/2];o.push({corners:c,normal:Kn([h[0]-u[0],h[1]-u[1],h[2]-u[2]])})}return{vertices:i,faces:o,creases:!1}}function eu(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function nu(t){switch(t.type){case"box":return Uh(t.size);case"cylinder":return Vh(t.radius,t.length,t.axis,t.segments,t.spokes);case"ellipsoid":return Jh(t.radii,t.segments);case"extrude":return Zh(t.profile,t.width);case"panel":return Qh(t.points,t.facing);case"tube":return{...tu(t.points,t.radius,t.segments),joined:t.joined}}}function gr(t,e){if(t.length<2)return t;const n=i=>t[Math.max(0,Math.min(t.length-1,i))],s=i=>{const o=i*(t.length-1),r=Math.min(t.length-2,Math.floor(o)),a=o-r,[l,c,h,u]=[n(r-1),n(r),n(r+1),n(r+2)];return[0,1,2].map(d=>{const f=l[d],g=c[d],p=h[d],m=u[d];return .5*(2*g+(-f+p)*a+(2*f-5*g+4*p-m)*a*a+(-f+3*g-3*p+m)*a*a*a)})};return Array.from({length:e},(i,o)=>s(o/(e-1)))}const Oe=t=>Array.isArray(t)&&t.length===2&&t.every(e=>typeof e=="number"&&Number.isFinite(e));function ii(t,e){return((e-t)%360+540)%360-180}function su(t){const e=t.map((n,s)=>({frame:n,i:s})).sort((n,s)=>n.frame.time-s.frame.time||n.i-s.i).map(({frame:n})=>n);return e.filter((n,s)=>s+1>=e.length||e[s+1].time!==n.time)}function hn(t,e){return Math.atan2(e[0]-t[0],e[1]-t[1])*180/Math.PI}function iu(t){const e=t.filter((i,o)=>o===0||Math.hypot(i[0]-t[o-1][0],i[1]-t[o-1][1])>1e-6);if(e.length<2)return[];const n=e.length===2?e:gr(e.map(([i,o])=>[i,0,o]),(e.length-1)*12).map(([i,,o])=>[i,o]);let s=0;return n.map((i,o)=>(o>0&&(s+=Math.hypot(i[0]-n[o-1][0],i[1]-n[o-1][1])),{point:i,at:s}))}function ou(t,e){let n=1;for(;n<t.length-1&&t[n].at<e;)n++;const s=t[n-1],i=t[n],o=i.at>s.at?Math.max(0,Math.min(1,(e-s.at)/(i.at-s.at))):0;return{point:[s.point[0]+(i.point[0]-s.point[0])*o,s.point[1]+(i.point[1]-s.point[1])*o],direction:[i.point[0]-s.point[0],i.point[1]-s.point[1]]}}function ru(t,e){if(e<=0)return 0;if(e>=1)return 1;let n=0,s=1;for(let i=0;i<40;i++){const o=(n+s)/2;t(o)<e?n=o:s=o}return(n+s)/2}const mr=["do","at","for","to","through","toward","speed","pose","gag"],au={walk:1.3,bouncy:1.4,doubleBounce:1.2,sneak:.6,strut:1.2,tired:.8,run:3.6,shove:.7},yr=Object.keys(_t),br=Object.keys(Ie),wr=Object.keys(si),ry=.25,ay=700/180,ly=200,cy=300;function lu(t){if(!Array.isArray(t))return[{beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const e=[...yr,"face","hold","pose","gag","place"],n=[];return t.forEach((s,i)=>{const o=c=>n.push({beat:i,message:c});if(!s||typeof s!="object"||Array.isArray(s))return o("Each beat must be an object like { do: 'walk', to: [x, z] }.");const r=s,a={duration:"for",path:"through",position:"to",heading:"toward",direction:"toward"};for(const c of Object.keys(r))mr.includes(c)||o(ft("beat field",c,mr,a[c]));const l=typeof r.do=="string"?br.includes(r.do)?"pose":wr.includes(r.do)?"gag":r.do==="turn"?"face":void 0:void 0;if(typeof r.do!="string"||!e.includes(r.do))return o(ft("character 3D beat",r.do,e,l));yr.includes(r.do)&&(r.to===void 0&&r.through===void 0&&o(`\`${r.do}\` needs \`to\` ([x, z] metres) or \`through\` (a list of them).`),r.to!==void 0&&!Oe(r.to)&&o(`\`to\` is a point on the ground, [x, z] metres (got ${JSON.stringify(r.to)}).`),r.through!==void 0&&!(Array.isArray(r.through)&&r.through.length>0&&r.through.every(Oe))&&o("`through` is a list of points on the ground, each [x, z] metres.")),r.do==="place"&&!Oe(r.to)&&o("`place` needs `to`: a point on the ground, [x, z] metres."),r.do==="face"&&!(Oe(r.toward)||typeof r.toward=="number")&&o("`face` needs `toward`: a point [x, z] or a heading in degrees."),r.do==="pose"&&!(typeof r.pose=="object"&&r.pose!==null)&&!br.includes(r.pose)&&o(ft("pose",r.pose,br)),r.do==="gag"&&!wr.includes(r.gag)&&o(ft("gag",r.gag,wr))}),n}function hy(t,e,n){const s=lu(e);if(s.length>0)throw new Error(`characterScript3D: ${s.length} problem(s) in the beats:
54
- ${s.map(M=>` beat ${M.beat}: ${M.message}`).join(`
55
- `)}`);const i=n.height??1.7,o={...mt,...n.pose};let[r,a]=n.position??[0,0],l=n.heading??0,c=0;const h=new Map,u=[],d=(M,S,A,E="linear")=>{const $=h.get(M)??[];$.push({time:S,value:A,easing:E}),h.set(M,$)};d("x",0,r),d("z",0,a),d("rotateY",0,l);const f=(M,S)=>{const A=ii(l,S);if(Math.abs(A)<1)return M;const E=Math.max(ly,Math.abs(A)*ay);return d("rotateY",M,l),l+=A,d("rotateY",M+E,l,"ease-in-out"),M+E},g=(M,S,A,E="ease-in-out")=>{for(const[$,v]of Object.entries(A))o[$]!==v&&(d($,M,o[$]??0),d($,S,v,E),o[$]=v)},p=(M,S,A)=>{const E=iu([[r,a],...S.through??[S.to]]);if(E.length<2)return A;const $=f(A,hn(E[0].point,E[1].point)),v=E[E.length-1].at,O=S.speed??au[M]*Math.sqrt(i/1.7),x=S.for??v/O*1e3,_=zh(M,i),F=$t("ease-in-out"),I=Math.min(cy,x/4);u.push({time:$,value:M}),d("walking",$,0),d("walking",$+I,1,"ease-out"),d("walking",$+x-I,1),d("walking",$+x,0,"ease-in");const L=c;let N=l;for(let Y=0;;Y=Math.min(v,Y+ry)){const j=$+ru(F,Y/v)*x,{point:U,direction:J}=ou(E,Y);if(N+=ii(N,hn([0,0],J)),d("x",j,U[0]),d("z",j,U[1]),d("rotateY",j,N),d("walk",j,L+Y/_),Y>=v)break}return c=L+v/_,[r,a]=E[E.length-1].point,l=N,$+x},m=[];let b=0;for(const M of e){const S=M.at??b;let A=S;if(yr.includes(M.do))A=p(M.do,M,S);else if(M.do==="face")A=f(S,typeof M.toward=="number"?M.toward:hn([r,a],M.toward));else if(M.do==="hold")A=S+(M.for??1e3);else if(M.do==="place")d("x",S,r),d("z",S,a),[r,a]=M.to,d("x",S+1,r),d("z",S+1,a),typeof M.toward=="number"&&(d("rotateY",S,l),l=M.toward,d("rotateY",S+1,l)),A=S+1;else if(M.do==="pose"){A=S+(M.for??500);const E=typeof M.pose=="string"?Ie[M.pose]:M.pose;g(S,A,E)}else if(M.do==="gag"){const E=Xh(M.gag,{at:S,from:{...o}});let $=E[0];for(const v of E.slice(1))g($.time,v.time,Object.fromEntries(Object.entries(v.pose).filter(([O,x])=>o[O]!==x)),v.easing??"ease-in-out"),$=v;A=$.time}m.push({do:M.do,start:S,end:A}),b=A}const k=`${n.scene}/${t}`,w=[...h].map(([M,S])=>({id:`${t}-${M}`,target:k,property:M,keyframes:su(S)}));return u.length>0&&w.push({id:`${t}-gait`,target:k,property:"gait",keyframes:u}),{tracks:w,duration:b,beats:m,end:{position:[r,a],heading:l,pose:{...o}}}}const cu={x:0,y:0,scale:1,rotate:0,shakeX:0,shakeY:0,shakeRotate:0};function uy(t){const e=n=>{const s=t?.get(n);return typeof s=="number"?s:cu[n]};return{x:e("x"),y:e("y"),scale:e("scale"),rotate:e("rotate"),shakeX:e("shakeX"),shakeY:e("shakeY"),shakeRotate:e("shakeRotate")}}function dy(t,e,n){const s=n.width/2,i=n.height/2,r=1+2*Math.max(Math.abs(e.shakeX),Math.abs(e.shakeY))/Math.max(1,Math.min(n.width,n.height));t.translate(s+e.x+e.shakeX,i+e.y+e.shakeY),t.rotate((e.rotate+e.shakeRotate)*Math.PI/180),t.scale(e.scale*r,e.scale*r),t.translate(-s,-i)}function fy(t,e,n){const s=e.width/2,i=e.height/2,o=(t.rotate+t.shakeRotate)*Math.PI/180,r=(n.x-s)*t.scale,a=(n.y-i)*t.scale;return{x:s+t.x+t.shakeX+r*Math.cos(o)-a*Math.sin(o),y:i+t.y+t.shakeY+r*Math.sin(o)+a*Math.cos(o)}}function hu(t,e,n={},s){const i=n.length??240,o=9,r=28,a=i-22;t.save(),t.translate(e.x,e.y),t.rotate((n.angle??-30)*Math.PI/180),t.fillStyle=n.color??"#f4c542",t.fillRect(r,-o,a-r,2*o),t.fillStyle="#e8b4a0",t.fillRect(a,-o,i-a,2*o),t.fillStyle="#f1dcbf",t.beginPath(),t.moveTo(0,0),t.lineTo(r,-o),t.lineTo(r,o),t.closePath(),t.fill(),t.fillStyle=n.outline??"#2f2f33",t.beginPath(),t.moveTo(0,0),t.lineTo(r*.35,-o*.35),t.lineTo(r*.35,o*.35),t.closePath(),t.fill(),t.strokeStyle=n.outline??"#2f2f33",t.lineWidth=3,t.lineJoin="round",t.lineCap="round";const l=[[{x:0,y:0},{x:r,y:-o},{x:i,y:-o},{x:i,y:o},{x:r,y:o},{x:0,y:0}],[{x:r,y:-o},{x:r,y:o}],[{x:a,y:-o},{x:a,y:o}]];for(const c of l)fu(t,c,s);t.restore()}function kr(t,e,n={},s){const i=n.length??90,o=n.thickness??34;t.save(),t.translate(e.x,e.y),t.rotate((n.angle??-35)*Math.PI/180);const r=-o/2;t.fillStyle=n.color??"#f4a7b9",t.fillRect(0,r,i,o),t.fillStyle="#e9edf2",t.fillRect(i*.45,r,i*.55,o),t.strokeStyle=n.outline??"#2f2f33",t.lineWidth=3,t.lineJoin="round";const a=[{x:0,y:r},{x:i,y:r},{x:i,y:-r},{x:0,y:-r},{x:0,y:r}],l=[{x:i*.45,y:r},{x:i*.45,y:-r}];if(s)s.line(a),s.line(l);else for(const c of[a,l]){t.beginPath(),t.moveTo(c[0].x,c[0].y);for(const h of c.slice(1))t.lineTo(h.x,h.y);t.stroke()}t.restore()}const uu=150,py={pencil:44,eraser:30};function vr(t,e,n={},s){const i=n.tool??"pencil",o=n.skin??"#f1c9a5",r=n.outline??"#2f2f33",a=n.scale??1,l=Math.min(1,Math.max(0,n.lift??0)),c=(n.angle??-30)*Math.PI/180,h=s?s.nudge(.6):{x:0,y:0},u=uu*a*(1+.05*l);l>0&&(t.save(),t.fillStyle=r,t.globalAlpha=.15*l,t.beginPath(),t.ellipse(e.x,e.y,9*a,4*a,0,0,Math.PI*2),t.fill(),t.restore());const d={x:e.x+h.x+6*l*a,y:e.y+h.y-18*l*a},f=St.pencilGrip,g=E=>{const $=E.fingers.thumb,v=E.fingers.index,O=E.fingers.middle,x=du([$.points[3],v.points[3],O.points[3]]),_=du([$.points[1],v.points[0]]),F=($.depths[3]+v.depths[3]+O.depths[3])/3;return{pinch:x,direction:Math.atan2(_.y-x.y,_.x-x.x),depth:F}},p=Os(f,{size:u}),m=c-g(p).direction,b=Os(f,{size:u,angle:m*180/Math.PI}),k=g(b),w=py[i]*a,M={x:k.pinch.x-Math.cos(c)*w,y:k.pinch.y-Math.sin(c)*w},S={x:d.x-M.x,y:d.y-M.y},A=b.axes.up;gy(t,S,{x:-A.x,y:-A.y},u,n.arm??300*a,o,n.sleeve??"#5b7db1",r),Cs(t,S,f,{size:u,angle:m*180/Math.PI,skin:o,ink:r,lineWidth:3*a,prop:{depth:k.depth,draw:()=>{t.save(),t.translate(d.x,d.y),t.scale(a,a),i==="eraser"?kr(t,{x:0,y:0},{angle:c*180/Math.PI,outline:r},s):hu(t,{x:0,y:0},{angle:c*180/Math.PI,length:190,outline:r},s),t.restore()}}})}const du=t=>({x:t.reduce((e,n)=>e+n.x,0)/t.length,y:t.reduce((e,n)=>e+n.y,0)/t.length});function gy(t,e,n,s,i,o,r,a){const l={x:-n.y,y:n.x},c=s*.15,h=(p,m,b)=>({x:e.x+n.x*p+l.x*m*b,y:e.y+n.y*p+l.y*m*b}),u=h(i,0,0),d=p=>{const m=t.createLinearGradient(e.x,e.y,u.x,u.y);return m.addColorStop(0,p),m.addColorStop(.6,p),m.addColorStop(1,wy(p)),m},f=Math.min(s*.55,i*.35);t.save(),t.lineJoin="round",t.lineCap="round",t.lineWidth=3*(s/uu),t.beginPath(),t.moveTo(h(-s*.1,-1,c).x,h(-s*.1,-1,c).y),t.lineTo(h(f+4,-1,c*1.1).x,h(f+4,-1,c*1.1).y),t.lineTo(h(f+4,1,c*1.1).x,h(f+4,1,c*1.1).y),t.lineTo(h(-s*.1,1,c).x,h(-s*.1,1,c).y),t.closePath(),t.fillStyle=o,t.fill(),t.strokeStyle=a,t.beginPath(),t.moveTo(h(0,-1,c).x,h(0,-1,c).y),t.lineTo(h(f,-1,c*1.1).x,h(f,-1,c*1.1).y),t.moveTo(h(0,1,c).x,h(0,1,c).y),t.lineTo(h(f,1,c*1.1).x,h(f,1,c*1.1).y),t.stroke();const g=[h(f,-1,c*1.3),h(i,-1,c*1.5),h(i,1,c*1.5),h(f,1,c*1.3)];t.beginPath(),g.forEach((p,m)=>m?t.lineTo(p.x,p.y):t.moveTo(p.x,p.y)),t.closePath(),t.fillStyle=d(r),t.fill(),t.strokeStyle=d(a),t.beginPath(),t.moveTo(g[1].x,g[1].y),t.lineTo(g[0].x,g[0].y),t.lineTo(g[3].x,g[3].y),t.lineTo(g[2].x,g[2].y),t.stroke(),t.restore()}function my(t,e,n={}){const s=n.offstage??{x:2e3,y:1400},i=n.enter??450,o=n.exit??450,r=n.linger??1500,a=[...t].filter(p=>p.path.length>0).sort((p,m)=>p.start-m.start),l=p=>p.tool??"pencil",c=p=>{const m=Math.min(1,Math.max(0,p));return m*m*(3-2*m)},h=(p,m,b)=>({x:p.x+(m.x-p.x)*b,y:p.y+(m.y-p.y)*b}),u=a.find(p=>e>=p.start&&e<=p.end);if(u){const p=u.end-u.start,m=p>0?(e-u.start)/p:1;return{at:Ps(u.path,m),tool:l(u),lift:0,drawing:!0}}const d=[...a].reverse().find(p=>p.end<e),f=a.find(p=>p.start>e),g=p=>p.path[p.path.length-1];if(d&&f&&f.start-d.end<=r){const p=(e-d.end)/(f.start-d.end),m=p<.5?l(d):l(f);return{at:h(g(d),f.path[0],c(p)),tool:m,lift:Math.sin(Math.PI*p),drawing:!1}}if(f&&f.start-e<=i){const p=1-(f.start-e)/i;return{at:h(s,f.path[0],c(p)),tool:l(f),lift:1-c(p),drawing:!1}}if(d&&e-d.end<=o){const p=(e-d.end)/o;return{at:h(g(d),s,c(p)),tool:l(d),lift:c(p),drawing:!1}}return null}function yy(t,e,n,s=.08,i=32){const o=Math.PI*2*(1+s),r=[];for(let a=0;a<=i;a++){const l=-Math.PI/2+o*a/i;r.push({x:t+Math.cos(l)*n,y:e+Math.sin(l)*n})}return r}function by(t){const{path:e}=t,n=e.map(a=>a.x),s=e.map(a=>a.y),i=Math.min(...n),o=Math.min(...s),r=t.hand===!1?void 0:t.hand===!0||t.hand===void 0?{}:t.hand;return{type:"custom",x:i,y:o,width:Math.max(1,Math.max(...n)-i),height:Math.max(1,Math.max(...s)-o),props:{draw:0},draw(a,l,c){const h=Math.min(1,Math.max(0,Number(l.props?.draw??0)));a.translate(-i,-o),a.strokeStyle=t.color??"#2f2f33",a.lineWidth=t.lineWidth??5,a.lineCap="round",a.lineJoin="round";const u=t.sketch?$s(a,t.sketch,c):void 0;h>0&&(u?t.smooth?u.curve(e,h):u.line(e,h):fu(a,en(e,h))),r&&h>0&&h<1&&vr(a,Ps(e,h),r,u)}}}function wy(t){const e=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim());if(!e)return"rgba(0, 0, 0, 0)";const n=e[1].length===3?[...e[1]].map(r=>r+r).join(""):e[1],[s,i,o]=[0,2,4].map(r=>parseInt(n.slice(r,r+2),16));return`rgba(${s}, ${i}, ${o}, 0)`}function fu(t,e,n){if(!(e.length<2)){if(n)return n.line(e);t.beginPath(),t.moveTo(e[0].x,e[0].y);for(const s of e.slice(1))t.lineTo(s.x,s.y);t.stroke()}}const oi=1e5;function ky(t,e,n,s,i=6){const o=[],r=Math.max(1,Math.round(i));for(let a=0;a<=r;a++)o.push({x:a%2===0?t:t+n,y:e+s*a/r});return o}function Mr(t,e,n,s){if(s<=0||e.length===0)return;const i=en(e,s),o=n/2,r=a=>{t.beginPath(),t.rect(-oi,-oi,2*oi,2*oi),a(),t.clip("evenodd")};for(const a of i)r(()=>{t.moveTo(a.x+o,a.y),t.arc(a.x,a.y,o,0,Math.PI*2)});for(let a=1;a<i.length;a++){const l=i[a-1],c=i[a],h=Math.hypot(c.x-l.x,c.y-l.y);if(h===0)continue;const u=-(c.y-l.y)/h*o,d=(c.x-l.x)/h*o;r(()=>{t.moveTo(l.x+u,l.y+d),t.lineTo(c.x+u,c.y+d),t.lineTo(c.x-u,c.y-d),t.lineTo(l.x-u,l.y-d),t.closePath()})}}function vy(t,e,n,s,i){t.save(),Mr(t,e,n,s),i(),t.restore()}function My(t,e){const n=e.width??40,s=e.hand===!0?{}:e.hand||void 0,i=e.eraser===!1?void 0:e.eraser===!0||e.eraser===void 0?{}:e.eraser;return{...t,props:{...t.props,erase:0},draw(o,r,a){const l=Number(r.props?.erase??0);if(o.save(),Mr(o,e.path,n,l),t.draw(o,r,a),o.restore(),!i||l<=0||l>=1)return;const c=Ps(e.path,l);s?vr(o,c,{...s,tool:"eraser"}):kr(o,c,i)}}}const pu={background:"#1e1e2e",gutter:"#6c7086",text:"#cdd6f4",keyword:"#cba6f7",string:"#a6e3a1",number:"#fab387",comment:"#7f849c",highlight:"rgba(249, 226, 175, 0.22)",strike:"#f38ba8",font:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"},ri=["wipe","fly","blur"],Sy=.0016,Ty=.6,Yn=33,Ey=.9,Ay=8;function Py(t){const e={...pu,...t.theme},n=t.code.replace(/\t/g," ").replace(/\n$/,"").split(`
56
- `),s=t.fontSize??16,i=(t.lineHeight??1.6)*s,o=(t.charWidth??.6)*s,r=t.padding??12,a=t.lineNumbers===!1?0:(String(n.length).length+2)*o,l=Math.max(1,...n.map(P=>P.length)),c=t.width??r*2+a+l*o,h=r*2+n.length*i,u=t.x+r+a,d=new Set(t.hidden??[]),f=t.language??"plain";if(!li.includes(f))throw new Error(`codePanel: ${ft("language",f,li)}`);const g=n.map(P=>mu(P,f).flatMap(H=>Array.from(H.text,()=>e[H.kind]))),p=new Map,m=[],b=new Map,k=[],w=[],M=P=>{if(!Number.isInteger(P)||P<1||P>n.length)throw new Error(`codePanel: no line ${P} (it has ${n.length})`)},S=(P,...H)=>p.set(P,[...p.get(P)??[],...H]),A=(P,H,T,C,D=300)=>S(P,{time:C.at,value:H},{time:C.at+(C.duration??D),value:T,...C.easing?{easing:C.easing}:{}}),E=(P,H,T,C,D,q=300)=>{M(P),A(`line.${P}.${H}`,T,C,D,q)},$=(P,H)=>m.filter(T=>T.line<P&&T.closed<=H).length,v=(P,H,T,C)=>({x:P+T/2,y:H+C/2,left:P,right:P+T,top:H,bottom:H+C,width:T,height:C}),O=P=>t.y+r+(P-1)*i,x=P=>Array.isArray(P)?P:[P],_=(P,H)=>{const T=p.get(P);return T?[...T].sort((C,D)=>C.time-D.time)[T.length-1].value:H},F=(P,H,T)=>{let C=-1;for(let D=0;D<T;D++)if(C=n[P-1].indexOf(H,C+1),C<0)throw new Error(`codePanel: line ${P} has no ${T>1?`${T}th `:""}"${H}"`);return C},I={};n.forEach((P,H)=>{const T=H+1;I[`line.${T}.highlight`]=0,I[`line.${T}.strike`]=0,I[`line.${T}.wipe`]=0,I[`line.${T}.reveal`]=d.has(T)?0:1,I[`line.${T}.shift`]=0});const L={type:"custom",x:t.x,y:t.y,width:c,height:h,props:I,about:{kind:"code panel",summary:`${n.length} lines of ${f} code. Its lines and words are places in the scene (line(), token(), spot()); its edits are methods that record tracks (tracks()).`,get props(){return xy(Object.keys(I))},actions:Sr},draw(P,H){const T=H.props??{},C=K=>Number(T[K]??I[K]),D=r+a,q=K=>r+(K-1)*i-C(`line.${K}.shift`)*i;P.fillStyle=e.background,gu(P,0,0,c,h,8),P.fill(),P.font=`${s}px ${e.font}`,P.textBaseline="middle",P.textAlign="left";const st=(K,tt,R,B,W)=>{const Z=n[K-1];for(let G=tt;G<R;G++)Z[G]!==" "&&(P.fillStyle=g[K-1][G],P.fillText(Z[G],B+(G-tt)*o,W))};P.save(),gu(P,0,0,c,h,8),P.clip(),n.forEach((K,tt)=>{const R=tt+1,B=C(`line.${R}.wipe`);if(B>=1)return;const W=q(R),Z=W+i/2,G=Math.max(1,K.length)*o,et=Math.round(C(`line.${R}.reveal`)*K.length),ot=b.get(R)??{style:"wipe",from:"left"};P.save(),B>0&&$y(P,ot,B,{left:D-a,top:W,width:a+G+o,height:i},c);const ut=C(`line.${R}.highlight`);ut>0&&(P.globalAlpha*=Math.min(1,ut),P.fillStyle=e.highlight,P.fillRect(D-o/2,W,G+o,i),P.globalAlpha/=Math.min(1,ut)),a>0&&et>0&&(P.fillStyle=e.gutter,P.textAlign="right",P.fillText(String(R),D-o,Z),P.textAlign="left");const gt=[...k.filter(V=>V.line===R).map(V=>({column:V.column,length:V.text.length,piece:V,insert:void 0})),...w.filter(V=>V.line===R).map(V=>({column:V.column,length:0,piece:void 0,insert:V}))].sort((V,rt)=>V.column-rt.column||V.length-rt.length);let ct=0,Q=D;for(const V of gt){st(R,ct,Math.min(V.column,et),Q,Z),Q+=(V.column-ct)*o;let rt=V.length,z="";if(V.piece){const X=V.piece.written??"",at=C(`piece.${V.piece.id}.write`);X&&at>0?(z=X.slice(0,Math.round(at*X.length)),rt=V.length+(X.length-V.length)*Math.min(1,at*2)):rt=V.length*(1-C(`piece.${V.piece.id}.away`))}else V.insert&&(rt=V.insert.chars*C(`insert.${V.insert.id}.open`),V.insert.text&&(z=V.insert.text.slice(0,Math.round(C(`insert.${V.insert.id}.type`)*V.insert.text.length))));P.fillStyle=e.text;for(let X=0;X<z.length;X++)z[X]!==" "&&P.fillText(z[X],Q+X*o,Z);Q+=rt*o,ct=V.column+V.length}st(R,ct,Math.max(ct,et),Q,Z);const nt=C(`line.${R}.strike`);nt>0&&(P.strokeStyle=e.strike,P.lineWidth=Math.max(1.5,s/10),P.beginPath(),P.moveTo(D,Z),P.lineTo(D+G*Math.min(1,nt),Z),P.stroke()),P.restore()});for(const K of k){const tt=C(`piece.${K.id}.opacity`);if(tt<=0||C(`line.${K.line}.wipe`)>=1)continue;const R=D+(K.column+K.text.length/2)*o+C(`piece.${K.id}.x`),B=q(K.line)+i/2+C(`piece.${K.id}.y`);P.save(),P.globalAlpha=Math.min(1,tt),P.translate(R,B),P.rotate(C(`piece.${K.id}.rotate`)*Math.PI/180),st(K.line,K.column,K.column+K.text.length,-K.text.length*o/2,0),P.restore()}P.restore()}},N=(P,H)=>({x:P.home.x+zn(p.get(`piece.${P.id}.x`),H),y:P.home.y+zn(p.get(`piece.${P.id}.y`),H)}),Y=(P,H)=>{for(const T of["x","y","rotate"]){const C=`piece.${P.id}.${T}`,D=(p.get(C)??[]).filter(q=>q.time<=H);p.set(C,D)}},j={target:L,lines:n,box:v(t.x,t.y,c,h),line(P,H=1/0){return M(P),v(u,O(P)-$(P,H)*i,Math.max(1,n[P-1].length)*o,i)},token(P,H,T=1,C=1/0){M(P);const D=F(P,H,T);return v(u+D*o,O(P)-$(P,C)*i,H.length*o,i)},highlight(P,H){for(const T of x(P)){const C=_(`line.${T}.highlight`,0);E(T,"highlight",C,H.on===!1?0:1,H,200)}return j},strike(P,H){for(const T of x(P))E(T,"strike",_(`line.${T}.strike`,0),1,H);return j},remove(P,H){const T=x(P),C=H.style??"wipe";if(!ri.includes(C))throw new Error(`codePanel.remove: ${ft("style",C,ri)}`);const D=C==="wipe"?300:450,q=H.at+(H.duration??D),st=H.close??250;for(const K of T)E(K,"wipe",0,1,{...H,easing:H.easing??(C==="fly"?"ease-in":void 0)},D),b.set(K,{style:C,from:H.from??"left"}),m.push({line:K,closed:q+st});for(let K=1;K<=n.length;K++){if(T.includes(K))continue;const tt=T.filter(B=>B<K).length;if(tt===0)continue;const R=_(`line.${K}.shift`,0);E(K,"shift",R,R+tt,{at:q,duration:st,easing:"ease-in-out"})}return j},type(P,H){return E(P,"reveal",0,1,{duration:n[P-1].length*45,...H}),j},piece(P,H,T=1){M(P);const C=F(P,H,T),D=k.find(st=>st.line===P&&st.column===C&&st.text===H);if(D)return D;if(k.some(st=>st.line===P&&C<st.column+st.text.length&&st.column<C+H.length))throw new Error(`codePanel: "${H}" on line ${P} overlaps another piece`);const q={id:k.length+1,line:P,column:C,text:H,home:j.token(P,H,T,0)};k.push(q);for(const st of["x","y","rotate","write","away"])I[`piece.${q.id}.${st}`]=0;return I[`piece.${q.id}.opacity`]=1,q},follow(P,H){for(const T of H)S(`piece.${P.id}.x`,{time:T.time,value:T.x-P.home.x}),S(`piece.${P.id}.y`,{time:T.time,value:T.y-P.home.y});return j},fling(P,H){const T=N(P,H.at),C=H.velocity??J(P,H.at)??{x:.5,y:-.6},D=H.gravity??Sy,q=H.duration??900,st=(H.spin??Ty)*(C.x<0?-1:1),K=zn(p.get(`piece.${P.id}.rotate`),H.at);Y(P,H.at);for(let tt=0;tt<=q;tt+=Yn){const R=T.x+C.x*tt,B=T.y+C.y*tt+.5*D*tt*tt;S(`piece.${P.id}.x`,{time:H.at+tt,value:R-P.home.x}),S(`piece.${P.id}.y`,{time:H.at+tt,value:B-P.home.y}),S(`piece.${P.id}.rotate`,{time:H.at+tt,value:K+st*tt})}return A(`piece.${P.id}.opacity`,1,0,{at:H.at+q*.6,duration:q*.4}),j},move(P,H){const T=N(P,H.at);return A(`piece.${P.id}.x`,T.x-P.home.x,H.to.x-P.home.x,H,400),A(`piece.${P.id}.y`,T.y-P.home.y,H.to.y-P.home.y,H,400),j},write(P,H,T){return P.written=H,A(`piece.${P.id}.write`,0,1,{duration:Math.max(1,H.length)*70,...T}),j},spot(P,H,T=1,C=1/0){M(P);const D=w.filter(q=>q.line===P&&q.column<=H&&q.at<=C).reduce((q,st)=>q+st.chars,0);return v(u+(H+D)*o,O(P)-$(P,C)*i,T*o,i)},insert(P,H,T,C){M(P);const D={id:w.length+1,line:P,column:H,chars:T.length,text:T,at:C.at};w.push(D),I[`insert.${D.id}.open`]=0,I[`insert.${D.id}.type`]=0;const q=C.duration??T.length*70;return A(`insert.${D.id}.open`,0,1,{at:C.at,duration:q*.6,easing:"ease-out"}),A(`insert.${D.id}.type`,0,1,{at:C.at,duration:q}),j},drop(P,H,T,C){M(H);const D=C.duration??250,q=H===P.line,st=C.easing??(q?"linear":"ease-out"),K=j.landing(P,H,T,C.at),tt={id:w.length+1,line:H,column:T,chars:P.text.length,at:C.at};return w.push(tt),I[`insert.${tt.id}.open`]=0,A(`insert.${tt.id}.open`,0,1,{at:C.at,duration:D,easing:q?st:"ease-out"}),A(`piece.${P.id}.away`,_(`piece.${P.id}.away`,0),1,{at:C.at,duration:D,easing:q?st:"ease-in-out"}),Y(P,C.at),j.move(P,{at:C.at,duration:D,easing:st,to:{x:K.x,y:K.y}}),A(`piece.${P.id}.rotate`,zn(p.get(`piece.${P.id}.rotate`),C.at),0,{at:C.at,duration:D}),j},landing(P,H,T,C=1/0){const D=j.spot(H,T,P.text.length,C),q=H===P.line&&T>P.column?P.text.length*o:0;return v(D.left-q,D.top,D.width,D.height)},ride(P,H,T){return U(P,H,T.ground,T.every??Yn)},tracks(P){return[...p].filter(([,H])=>H.length>0).map(([H,T])=>({id:`${P}-${H}`,target:P,property:H,keyframes:_y(T)}))}};function U(P,H,T,C){const D=n.map((Q,nt)=>p.get(`line.${nt+1}.shift`)??[]);if(D.every(Q=>Q.length===0))return P;const q=P.find(Q=>Q.target===H&&Q.property==="y"),st=new Wt({id:`${H}-ride`,tracks:q?[q]:[]}),K=Q=>q?Number(st.getStateAtTime(Q).values.get(H)?.get("y")??0):0,tt=Q=>{const nt=T+K(Q);return n.findIndex((V,rt)=>Math.abs(O(rt+1)-nt)<.5)},R=(q?.keyframes??[]).map(Q=>Q.time),B=Q=>{const nt=at=>at<0?0:-zn(D[at],Q)*i,V=tt(Q);if(V>=0)return nt(V);if(Math.abs(K(Q))<.5)return 0;const rt=at=>tt(at)>=0||Math.abs(K(at))<.5,z=[...R].reverse().find(at=>at<=Q&&rt(at)),X=R.find(at=>at>=Q&&rt(at));return z===void 0&&X===void 0?0:z===void 0?nt(tt(X)):X===void 0||X===z?nt(tt(z)):nt(tt(z))+(nt(tt(X))-nt(tt(z)))*(Q-z)/(X-z)},W=D.flatMap(Q=>{const nt=[...Q].sort((V,rt)=>V.time-rt.time);return nt.slice(1).flatMap((V,rt)=>V.value!==nt[rt].value?[{start:nt[rt].time,end:V.time}]:[])}),Z=(Q,nt)=>W.some(V=>V.start<nt&&V.end>Q)||B(Q)!==B(nt),G=q?[...q.keyframes]:[{time:0,value:0}],et=[{...G[0],value:G[0].value+B(G[0].time)}],ot=(Q,nt)=>{const V=new Set([nt]);for(let rt=Q+C;rt<nt;rt+=C)V.add(rt);for(const rt of W)for(const z of[rt.start,rt.end])z>Q&&z<nt&&V.add(z);for(const rt of[...V].sort((z,X)=>z-X))et.push({time:rt,value:K(rt)+B(rt)})};for(let Q=1;Q<G.length;Q++){const nt=G[Q-1].time,V=G[Q].time;Z(nt,V)?ot(nt,V):et.push({...G[Q],value:G[Q].value+B(V)})}const ut=G[G.length-1].time,gt=Math.max(ut,...W.map(Q=>Q.end));gt>ut&&ot(ut,gt);const ct={id:q?.id??`${H}-y`,target:H,property:"y",keyframes:et};return q?P.map(Q=>Q===q?ct:Q):[...P,ct]}function J(P,H){const T=p.get(`piece.${P.id}.x`);if(!T||T.length<2)return;const C=N(P,H-Yn),D=N(P,H);return{x:(D.x-C.x)/Yn,y:(D.y-C.y)/Yn}}return j}function $y(t,e,n,s,i){if(e.style==="wipe"){t.beginPath(),e.from==="right"?t.rect(s.left,s.top,s.width*(1-n),s.height):t.rect(s.left+n*s.width,s.top,s.width*(1-n),s.height),t.clip();return}const o=Ay*n;if(o>.2&&"filter"in t&&(t.filter=`blur(${o.toFixed(1)}px)`),t.globalAlpha*=1-n,e.style==="fly"){const r=e.from==="right"?-1:1;t.translate(r*n*Ey*i,0),t.rotate(r*n*.08)}else{const r=1+.08*n,a=s.left+s.width/2,l=s.top+s.height/2;t.translate(a,l),t.scale(r,r),t.translate(-a,-l)}}function zn(t,e){if(!t||t.length===0)return 0;const n=[...t].sort((s,i)=>s.time-i.time);if(e<=n[0].time)return n[0].value;for(let s=1;s<n.length;s++)if(e<=n[s].time){const i=n[s-1],o=n[s];return o.time===i.time?o.value:i.value+(o.value-i.value)*(e-i.time)/(o.time-i.time)}return n[n.length-1].value}const Sr={highlight:"highlight(n | n[], { at, duration?, on? }): tint lines (on: false clears)",strike:"strike(n | n[], { at, duration? }): strike lines through, left to right",remove:"remove(n | n[], { at, duration?, style?: wipe | fly | blur, from?: left | right, close? }): take lines away; the lines below close the gap",type:"type(n, { at, duration? }): type in a line given in `hidden`",piece:"piece(n, text, occurrence?): make a word a piece that can come loose (returns it, with its home box)",follow:"follow(piece, path): carry a piece along timed points (handPath() gives a hand’s)",fling:"fling(piece, { at, velocity?, spin?, gravity?, duration? }): throw or kick a piece away on a spinning arc",move:"move(piece, { at, to: { x, y }, duration?, easing? }): move a piece’s centre to a point",write:"write(piece, text, { at, duration? }): type new text into a piece’s place",insert:"insert(n, column, text, { at, duration? }): type new text into a line; the line makes room",drop:"drop(piece, n, column, { at, duration? }): put a piece into a line (into its own line it slides, the text closing behind it)",ride:"ride(tracks, figureId, { ground }): a figure’s tracks with it carried by the line it stands on"};function xy(t){const e=[[/^line\.\d+\.highlight$/,{description:"How much the line is tinted",unit:"0..1",min:0,max:1}],[/^line\.\d+\.strike$/,{description:"How far the strike-through has drawn",unit:"0..1",min:0,max:1}],[/^line\.\d+\.wipe$/,{description:"How far the line has gone (wiped, flown off or blurred)",unit:"0..1",min:0,max:1}],[/^line\.\d+\.reveal$/,{description:"How much of the line is typed in",unit:"0..1",min:0,max:1}],[/^line\.\d+\.shift$/,{description:"How many rows the line has moved up",unit:"rows"}],[/^piece\.\d+\.(x|y)$/,{description:"The piece moved from its home",unit:"px"}],[/^piece\.\d+\.rotate$/,{description:"The piece turned",unit:"degrees"}],[/^piece\.\d+\.opacity$/,{description:"How opaque the piece is",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.write$/,{description:"How much of the text written into its place is typed",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.away$/,{description:"How far its old place has closed",unit:"0..1",min:0,max:1}],[/^insert\.\d+\.open$/,{description:"How much room the insert has opened",unit:"0..1",min:0,max:1}],[/^insert\.\d+\.type$/,{description:"How much of the inserted text is typed",unit:"0..1",min:0,max:1}]],n={};for(const s of t){const i=e.find(([o])=>o.test(s));i&&(n[s]=i[1])}return n}function _y(t){return[...t].sort((n,s)=>n.time-s.time).map(n=>({time:n.time,value:n.value,...n.easing?{easing:n.easing}:{}}))}function gu(t,e,n,s,i,o){t.beginPath(),t.moveTo(e+o,n),t.arcTo(e+s,n,e+s,n+i,o),t.arcTo(e+s,n+i,e,n+i,o),t.arcTo(e,n+i,e,n,o),t.arcTo(e,n,e+s,n,o),t.closePath()}const ai={go:["break","case","chan","const","continue","default","defer","else","fallthrough","for","func","go","goto","if","import","interface","map","package","range","return","select","struct","switch","type","var","nil","true","false"],rust:["as","async","await","break","const","continue","crate","else","enum","extern","false","fn","for","if","impl","in","let","loop","match","mod","move","mut","pub","ref","return","self","Self","static","struct","super","trait","true","type","unsafe","use","where","while","Some","None","Ok","Err"],csharp:["abstract","async","await","base","bool","break","case","catch","class","const","continue","default","do","else","enum","false","finally","for","foreach","if","in","int","interface","internal","is","namespace","new","null","object","out","override","private","protected","public","readonly","ref","return","sealed","static","string","struct","switch","this","throw","true","try","using","var","virtual","void","while"],javascript:["async","await","break","case","catch","class","const","continue","default","delete","do","else","export","extends","false","finally","for","function","if","import","in","instanceof","let","new","null","of","return","static","super","switch","this","throw","true","try","typeof","undefined","var","void","while","yield"],typescript:[],python:["and","as","assert","async","await","break","class","continue","def","del","elif","else","except","False","finally","for","from","global","if","import","in","is","lambda","None","nonlocal","not","or","pass","raise","return","True","try","while","with","yield"],plain:[]};ai.typescript=[...ai.javascript,"enum","interface","type","implements","private","public","readonly","keyof","as","declare","namespace"];const li=Object.keys(ai),Iy={go:"//",rust:"//",csharp:"//",javascript:"//",typescript:"//",python:"#",plain:null};function mu(t,e){const n=new Set(ai[e]),s=Iy[e],i=[],o=(a,l)=>{const c=i[i.length-1];c&&c.kind===l?c.text+=a:i.push({text:a,kind:l})};let r=0;for(;r<t.length;){const a=t[r];if(e!=="plain"&&s&&t.startsWith(s,r)){o(t.slice(r),"comment");break}if(e!=="plain"&&(a==='"'||a==="'"||a==="`")){let h=r+1;for(;h<t.length&&t[h]!==a;)h+=t[h]==="\\"?2:1;o(t.slice(r,h+1),"string"),r=h+1;continue}const l=/^[A-Za-z_][A-Za-z0-9_]*/.exec(t.slice(r));if(l){o(l[0],n.has(l[0])?"keyword":"text"),r+=l[0].length;continue}const c=/^\d[\d_.]*/.exec(t.slice(r));if(c&&e!=="plain"){o(c[0],"number"),r+=c[0].length;continue}o(a,"text"),r++}return i}const Oy=(t,e,n)=>t.slice(Math.floor((t.length-1)*e),Math.ceil((t.length-1)*n)+1);function Cy(t={}){const e=t.shirt??"#e2493b",n=t.trousers??"#24476b",s=a=>a.lineWidth*.45,i=(a,l,c)=>{const h=a.parts[`leg.${c}`].points;l.shape(Cn(h,a.height*.08,a.height*.05),n,s(a))},o=(a,l)=>{const c=a.chains.spine,h=c[0],u=c[c.length-1],d={x:h.x-(u.x-h.x)*.25,y:h.y-(u.y-h.y)*.25};l.shape(Cn([d,...a.parts.spine.points],a.height*.15,a.height*.14),e,s(a))},r=(a,l,c)=>{const h=a.parts[`arm.${c}`].points,u=h[0],d=a.chains.spine[a.chains.spine.length-1],g=[{x:u.x+(d.x-u.x)*.45,y:u.y+(d.y-u.y)*.45},...Oy(h,0,.45)],p=Cn(g,a.height*.085,a.height*.06),m=g.length,b=p.slice(0,m),k=p.slice(m).reverse();l.shape(p,e,0);const w=A=>Math.hypot(A[1].x-d.x,A[1].y-d.y),[M,S]=w(b)>w(k)?[b,k]:[k,b];l.line(M.slice(1),s(a)),l.line(S.slice(Math.ceil(m*.45)),s(a)),l.line([b[m-1],k[m-1]],s(a))};return{parts:{"leg.left":{over:(a,l,c)=>i(l,c,"left")},"leg.right":{over:(a,l,c)=>i(l,c,"right")},spine:{over:(a,l,c)=>o(l,c)},"arm.left":{over:(a,l,c)=>r(l,c,"left")},"arm.right":{over:(a,l,c)=>r(l,c,"right")}}}}const Ce={full:{anticipation:.12,anticipationTime:.3,hold:0,overshoot:.08,settle:220,settleEase:"ease-in-out",actionEase:"ease-in-out-cubic",overlap:45,eyeLead:120,eyeDart:160,drift:.12,blinks:!0,jumpSquash:1},snappy:{anticipation:.2,anticipationTime:.35,hold:.12,overshoot:.12,settle:320,settleEase:{type:"elastic",mode:"out",amplitude:1,period:.35},actionEase:"ease-out-cubic",overlap:35,eyeLead:100,eyeDart:100,drift:.1,blinks:!0,jumpSquash:1.3},limited:{anticipation:.06,anticipationTime:.25,hold:0,overshoot:0,settle:0,settleEase:"ease-out",actionEase:"ease-in-out",overlap:30,eyeLead:80,eyeDart:120,drift:0,blinks:!0,jumpSquash:.6},none:{anticipation:0,anticipationTime:0,hold:0,overshoot:0,settle:0,settleEase:"linear",actionEase:"linear",overlap:0,eyeLead:0,eyeDart:0,drift:0,blinks:!1,jumpSquash:0}};function Tr(t){if(t===void 0)return Ce.full;if(typeof t=="string")return Ce[t];const{base:e,...n}=t;return{...Ce[e??"full"],...n}}const Er=160,Hy=120,Ry=700,Ar=60,Ly=90,ci=3200,un=1,He=1e-6;function hi(t,e,n={}){const s=Tr(n.style),i=n.seed??1,o={};if(t.length===0)return o;const r=Object.keys(t[0].pose).filter(u=>t.some(d=>Math.abs(d.pose[u]-t[0].pose[u])>He));for(const u of r)o[u]=Fy(u,t,e,s,i);const a=e.blink,l=a!==void 0&&r.includes(a);if(s.blinks&&a!==void 0&&!l&&a in t[0].pose){const u=Dy(t,e,s,i,t[0].pose[a]);u.length>0&&(o[a]=u)}const{lift:c,stretch:h}=e;if(s.jumpSquash>0&&c&&h&&r.includes(c)&&!r.includes(h)&&h in t[0].pose){const u=Ny(t,c,t[0].pose[h],s.jumpSquash);u.length>0&&(o[h]=u)}return o}function Fy(t,e,n,s,i){const o=n.eyes.includes(t),r=n.limits[t],a=r!==void 0,l=o?-s.eyeLead:(n.depth[t]??1)*s.overlap,c=f=>{const g=(e[f].time-e[f-1].time)/2;return Math.max(-g,Math.min(g,l))},h=[{time:e[0].time,value:e[0].pose[t]}],u=(f,g,p)=>{const m=h[h.length-1];if(f<=m.time+un){h[h.length-1]={...m,value:g,...p?{easing:p}:{}};return}h.push({time:f,value:g,...p?{easing:p}:{}})};let d=e[0].pose[t];for(let f=1;f<e.length;f++){const g=e[f],p=e[f-1].pose[t],m=g.pose[t],b=m-p,k=h[h.length-1].time,w=g.act!==!1;if(Math.abs(b)<=He){const x=g.time+(w?c(f):0);if(f===e.length-1)Math.abs(d-m)>He&&u(Math.max(x,k+Er),m,"ease-in-out"),d=m;else if(w&&a&&s.drift>0&&n.drift.includes(t)&&x-k>=Ry){const _=Kt(`${i}:${t}:${f}`)%2===0?1:-1;d=m+_*s.drift*r,u(x,d,"ease-in-out")}continue}if(!w){u(e[f-1].time,d),u(g.time,m,g.easing),d=m;continue}const M=c(f),S=Math.max(e[f-1].time+M,k);let A=g.time+M;o&&s.eyeDart>0&&(A=Math.min(A,S+s.eyeDart));const E=A-S;if(E<=un){u(g.time,m,g.easing),d=m;continue}u(S,d);const $=Math.sign(b);if(a&&s.anticipation>0&&r>0&&E>=Er){const x=d-$*Math.min(Math.abs(b)*s.anticipation,r),_=S+E*s.anticipationTime;u(_,x,"ease-in-out"),s.hold>0&&u(_+E*s.hold,x)}const v=f+1<e.length?e[f+1].time-g.time:1/0,O=Math.min(s.settle,v/2);if(a&&s.overshoot>0&&r>0&&E>=Hy&&O>un){const x=Math.min(Math.abs(b)*s.overshoot,r);u(A,m+$*x,g.easing??s.actionEase),u(A+O,m,s.settleEase)}else u(A,m,g.easing??s.actionEase);d=m}return h}function Dy(t,e,n,s,i){const o=[],r=Ar+Ly;for(let f=1;f<t.length;f++){const g=t[f-1].pose,p=t[f].pose;Object.entries(e.headTurns).some(([b,k])=>Math.abs((p[b]??0)-(g[b]??0))>k)&&t[f].act!==!1&&o.push(Math.max(t[0].time,t[f-1].time-n.eyeLead))}const a=t[0].time,l=t[t.length-1].time,c=[...o];let h=a+ci*.6,u=0;for(;h<l;){c.some(p=>Math.abs(p-h)<ci/2)||o.push(h);const g=(Kt(`${s}:blink:${u++}`)%1e3/1e3-.5)*(ci*.66);h+=ci+g}o.sort((f,g)=>f-g);const d=[{time:a,value:i}];for(const f of o){const g=d[d.length-1].time;f+Ar<=g+un||(f>g+un&&d.push({time:f,value:i}),d.push({time:f+Ar,value:1,easing:"ease-in"}),d.push({time:f+r,value:i,easing:"ease-out"}))}return d.length>1?d:[]}function Ny(t,e,n,s){const i=n*(1-.18*s),o=n*(1+.14*s),r=[{time:t[0].time,value:n}],a=(l,c,h)=>{const u=r[r.length-1];l<=u.time+un||r.push({time:l,value:c,...h?{easing:h}:{}})};for(let l=1;l<t.length;l++){const c=t[l-1].pose[e],h=t[l].pose[e],u=t[l-1].time,d=t[l].time,f=d-u;if(!(f<Er||t[l].act===!1)){if(c<=He&&h>He)a(u,n),a(u+f*.2,i,"ease-out"),a(u+f*.45,o,"ease-out"),a(d,n,"ease-in-out");else if(c>He&&h<=He){const g=l+1<t.length?t[l+1].time-d:400;a(u+f*.5,n),a(d-Math.min(60,f*.15),o,"ease-in"),a(d,i,"ease-out"),a(d+Math.min(260,g/2),n,{type:"back",mode:"out",overshoot:1.4})}}}return r.length>1?r:[]}const yu={depth:{lean:0,bend:0,rise:0,sit:0,spin:0,stretch:0,turn:0,leftHip:0,rightHip:0,headTilt:1,leftShoulder:1,rightShoulder:1,leftKnee:1,rightKnee:1,leftBrow:1,rightBrow:1,browTilt:1,leftEye:1,rightEye:1,leftElbow:2,rightElbow:2,leftAnkle:2,rightAnkle:2,leftFootOut:2,rightFootOut:2,mouth:2,smile:2,mouthWidth:2,leftWrist:3,rightWrist:3},limits:{lean:10,bend:10,headTilt:12,spin:25,turn:.06,sit:.06,stretch:.08,rise:0,leftShoulder:20,rightShoulder:20,leftElbow:18,rightElbow:18,leftWrist:15,rightWrist:15,leftHip:12,rightHip:12,leftKnee:15,rightKnee:15,leftAnkle:10,rightAnkle:10,leftBrow:.25,rightBrow:.25,leftEye:.15,rightEye:.15},eyes:["lookX","lookY"],blink:"blink",headTurns:{turn:.15,headTilt:8,lookX:.5,spin:45},drift:["lean","bend","headTilt","leftShoulder","rightShoulder","leftElbow","rightElbow"],lift:"rise",stretch:"stretch"};function By(t){return/^(turn|lean|bend|side|lift|roll|stretch)$/.test(t)?{depth:0,limit:{turn:.06,lean:10,bend:10,side:8,lift:0,roll:25,stretch:.08}[t]}:/^leg\.\w+\.(swing|spread|rotate)$/.test(t)?{depth:0,limit:12}:/^head\./.test(t)?{depth:1,limit:12}:/^arm\.\w+\.(swing|spread)$/.test(t)?{depth:1,limit:20}:/^leg\.\w+\.knee$/.test(t)?{depth:1,limit:15}:/^(brow\.|browTilt$)/.test(t)?{depth:1,limit:t==="browTilt"?void 0:.25}:/^eye\./.test(t)?{depth:1,limit:.15}:/^arm\.\w+\.(elbow|bend)$/.test(t)?{depth:2,limit:18}:/^leg\.\w+\.(ankle|toeOut)$/.test(t)?{depth:2,limit:10}:/^(mouth|smile|mouthWidth)$/.test(t)?{depth:2}:/^hand\./.test(t)?{depth:3}:{depth:1}}function Wy(){const t={},e={};for(const n of Object.keys(mt)){const s=By(n);t[n]=s.depth,s.limit!==void 0&&(e[n]=s.limit)}return{depth:t,limits:e,eyes:["lookX","lookY"],blink:"blink",headTurns:{turn:.15,"head.turn":15,"head.nod":12,lookX:.5,roll:45},drift:["lean","bend","head.tilt","head.nod","arm.left.spread","arm.right.spread","arm.left.elbow","arm.right.elbow"],lift:"lift",stretch:"stretch"}}const bu=Wy();function wu(t,e){return Object.entries(e).map(([n,s])=>({id:`${t}-${n}`,target:t,property:n,keyframes:s}))}function ku(t,e,n={}){const s=Do(e),i=e.map((o,r)=>({time:o.time,pose:{...s[r]},easing:o.easing,act:o.act}));return wu(t,hi(i,n.rig??yu,n))}function jy(t,e,n={}){const s=n.rest??mt,i=ir(e,s),o=e.map((r,a)=>({time:r.time,pose:{...s,...i[a]},easing:r.easing,act:r.act}));return wu(t,hi(o,n.rig??bu,n))}const vu=dt.shocked,qy=dt.scared,we={take:t=>[{after:140,pose:{stretch:.8,bend:10,lean:t.lean-4,leftShoulder:8,rightShoulder:8,leftEye:.35,rightEye:.35,leftBrow:-.6,rightBrow:-.6,mouth:0},easing:"ease-in-out"},{after:260,pose:{stretch:.78}},{after:360,pose:{rise:.22,stretch:1.35,bend:-14,leftShoulder:150,rightShoulder:150,leftElbow:35,rightElbow:35,leftHip:22,rightHip:22,leftKnee:45,rightKnee:45,...vu,headTilt:0},easing:"ease-out-cubic"},{after:720,pose:{rise:.25,stretch:1.25,bend:-10,leftShoulder:140,rightShoulder:140},easing:"ease-in-out"},{after:900,pose:{rise:0,stretch:.74,bend:12,leftShoulder:70,rightShoulder:70,leftHip:18,rightHip:18,leftKnee:30,rightKnee:30},easing:"ease-in-quad"},{after:1060,pose:{stretch:1.06,bend:-3,leftShoulder:60,rightShoulder:60,leftHip:t.leftHip,rightHip:t.rightHip,leftKnee:t.leftKnee,rightKnee:t.rightKnee},easing:"ease-out"},{after:1260,pose:{stretch:t.stretch,bend:t.bend,...dt.surprised,leftShoulder:70,rightShoulder:70,leftElbow:60,rightElbow:60},easing:"ease-in-out"}],doubleTake:t=>[{after:160,pose:{lookX:1,lookY:0},easing:"ease-out"},{after:520,pose:{lookX:-.6,headTilt:t.headTilt-4,smile:.6,mouth:0},easing:"ease-in-out"},{after:1100,pose:{lookX:-.6}},{after:1180,pose:{bend:t.bend-10,headTilt:t.headTilt+10,rise:.05,stretch:1.18,...vu,lookX:1,lookY:0},easing:"ease-out-cubic"},{after:1360,pose:{rise:0,stretch:.88,bend:t.bend+4,headTilt:t.headTilt+4},easing:"ease-in-quad"},{after:1560,pose:{stretch:t.stretch,bend:t.bend,headTilt:t.headTilt},easing:{type:"elastic",mode:"out",amplitude:1,period:.35}}],windUp:()=>[{after:220,pose:{lean:-18,bend:-16,headTilt:-6,leftShoulder:70,leftElbow:-100,rightShoulder:40,rightElbow:100,leftHip:-45,leftKnee:-80,stretch:.92,...dt.angry,lookX:1},easing:"ease-out"},{after:620,pose:{lean:-20,bend:-18,stretch:.9}},{after:700,pose:{lean:28,bend:14,headTilt:6,leftShoulder:30,rightShoulder:60,leftHip:30,leftKnee:-30,rightHip:-20,stretch:1.12},easing:"ease-out-cubic"}],land:t=>[{after:120,pose:{rise:0,stretch:.7,bend:14,leftShoulder:75,rightShoulder:75,leftHip:20,rightHip:20,leftKnee:35,rightKnee:35},easing:"ease-in-quad"},{after:300,pose:{stretch:1.05,bend:-4,leftShoulder:t.leftShoulder,rightShoulder:t.rightShoulder},easing:"ease-out"},{after:460,pose:{rise:0,stretch:t.stretch,bend:t.bend,leftHip:it.leftHip,rightHip:it.rightHip,leftKnee:0,rightKnee:0},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...qy,bend:t.bend+8,leftShoulder:40,rightShoulder:40,leftElbow:110,rightElbow:110,stretch:.94},easing:"ease-out"}];for(let n=1;n<=14;n++)e.push({after:80+n*45,pose:{lean:t.lean+(n%2===0?2.5:-2.5),headTilt:t.headTilt+(n%2===0?-2:2)}});return e.push({after:755,pose:{lean:t.lean,headTilt:t.headTilt,bend:t.bend}}),e},deflate:t=>[{after:260,pose:{stretch:1.04,headTilt:t.headTilt+4,leftBrow:.3,rightBrow:.3},easing:"ease-in-out"},{after:900,pose:{...Lt.sad,bend:18,stretch:.92,lean:t.lean+5,turn:t.turn,sit:t.sit},easing:"ease-in-out"}]};function Pr(t,e){const n=typeof e.from=="string"?Lt[e.from]:e.from??it;return $r(we[t](n),{...e,from:n})}function $r(t,e){const n=e.speed??1;let s=e.from;return[{time:e.at,pose:e.from},...t.map(i=>(s={...s,...i.pose},{time:e.at+i.after*n,pose:s,act:!1,...i.easing?{easing:i.easing}:{}}))]}function Xn(t,e=1){const n=we[t](it);return n[n.length-1].after*e}function Mu(t,e,n={}){if(e.length<2)return;const s=Math.max(1,Math.round(n.lines??3)),i=n.spacing??5,o=n.lineWidth??2,r=n.opacity??.7;t.save(),t.strokeStyle=n.color??"#222",t.lineCap="round";for(let a=0;a<s;a++){const l=(a-(s-1)/2)*i,c=Math.floor(Math.abs(l)/Math.max(i,1)*(e.length/6));for(let h=c+1;h<e.length;h++){const u=e[h-1],d=e[h],f=d.x-u.x,g=d.y-u.y,p=Math.hypot(f,g)||1,m=-g/p,b=f/p,k=1-h/(e.length-1);t.globalAlpha=r*(1-k),t.lineWidth=o*(1-k*.7),t.beginPath(),t.moveTo(u.x+m*l,u.y+b*l),t.lineTo(d.x+m*l,d.y+b*l),t.stroke()}}t.restore()}const Ky={hands:[{name:"left hand",at:t=>t.hands.left},{name:"right hand",at:t=>t.hands.right}],toes:[{name:"left toe",at:t=>t.toes.left},{name:"right toe",at:t=>t.toes.right}],head:[{name:"head",at:t=>t.head.center}],body:[{name:"hip",at:t=>t.hip},{name:"neck",at:t=>t.neck}]};function Yy(t,e,n,s,i={}){const o=n.stateAt;if(!o)return;const r=i.length??120,a=Math.max(2,Math.round(i.samples??8)),l=Math.max(0,n.time-r);if(n.time-l<1)return;const c=[];for(let f=0;f<a;f++){const g=l+(n.time-l)*f/(a-1);c.push(Fo(e,{time:g,state:o(g)},s).joints)}const h=c[c.length-1].height,u=(i.threshold??1.2)*h,d=(i.parts??["hands","toes","head"]).flatMap(f=>Ky[f]);for(const f of d){const g=c.map(f.at);let p=0;for(let k=1;k<g.length;k++)p+=Math.hypot(g[k].x-g[k-1].x,g[k].y-g[k-1].y);const m=p/((n.time-l)/1e3);if(m<=u)continue;const b=Math.min(1,(m-u)/(u*.5));Mu(t,g,{...i,opacity:(i.opacity??.7)*b,spacing:i.spacing??h*.02})}}function Su(t,e,n,s={}){if(n<=0||n>=1)return;const i=s.size??40,o=s.seed??1,r=.45+.55*(1-(1-n)**3);t.save(),t.strokeStyle=s.color??"#555",t.lineWidth=Math.max(1,i*.03),t.globalAlpha=Math.min(1,n/.08)*(1-n);for(let a=0;a<5;a++){const l=Kt(`${o}:puff:${a}`)%1e3/1e3,c=a-2,h=e.x+c*i*.3*r,u=e.y-i*(.06+.12*l)*r+Math.abs(c)*i*.03,d=i*(.11+.07*l)*r;t.beginPath(),t.arc(h,u,d,Math.PI*.95,Math.PI*2.05),t.stroke()}t.restore()}function zy(t,e,n,s={}){if(n<=0||n>=1)return;const i=s.size??40,o=5,r=1-(1-n)**2;t.save(),t.strokeStyle=s.color??"#222",t.lineWidth=Math.max(1,i*.035),t.lineJoin="round",t.globalAlpha=n<.7?1:(1-n)/.3;for(let a=0;a<o;a++){const l=-Math.PI/2+(a-(o-1)/2)*Math.PI/(o+1),c=i*(.3+.7*r),h=e.x+Math.cos(l)*c,u=e.y+Math.sin(l)*c;Xy(t,h,u,i*.14,n*Math.PI+a),t.stroke()}t.restore()}function Xy(t,e,n,s,i){t.beginPath();for(let o=0;o<10;o++){const r=o%2===0?s:s*.45,a=i+o*Math.PI/5-Math.PI/2,l=e+Math.cos(a)*r,c=n+Math.sin(a)*r;o===0?t.moveTo(l,c):t.lineTo(l,c)}t.closePath()}const ke={rest:{mouth:0,mouthWidth:1},a:{mouth:.75,mouthWidth:1.1},e:{mouth:.45,mouthWidth:1.3},i:{mouth:.28,mouthWidth:1.45},o:{mouth:.6,mouthWidth:.7},u:{mouth:.32,mouthWidth:.55},m:{mouth:0,mouthWidth:.9},f:{mouth:.1,mouthWidth:1.05},l:{mouth:.3,mouthWidth:1},c:{mouth:.2,mouthWidth:1}},Gn=1,ui=.55,Tu=.35,Gy=1.6,Eu={a:"a",e:"e",i:"i",y:"i",o:"o",u:"u"},Au={m:"m",b:"m",p:"m",f:"f",v:"f",w:"u",q:"u",l:"l",n:"l",d:"l",t:"l"},Pu={अ:"a",आ:"a",इ:"i",ई:"i",उ:"u",ऊ:"u",ऋ:"i",ए:"e",ऐ:"e",ओ:"o",औ:"o",ऍ:"e",ऑ:"o"},$u={"ा":"a","ि":"i","ी":"i","ु":"u","ू":"u","ृ":"i","े":"e","ै":"e","ो":"o","ौ":"o","ॅ":"e","ॉ":"o"},Uy={प:"m",फ:"m",ब:"m",भ:"m",म:"m",व:"u"},Vy="्",xu="़",Jy=t=>t>="क"&&t<="ह",_u=new Set([".",",","!","?",";",":","…","।","॥","—","-"]);function Iu(t){const e=[],n=Array.from(t.toLowerCase()),s=(i,o)=>{const r=e[e.length-1];r&&r.viseme===i?r.weight+=o*.5:e.push({viseme:i,weight:o})};for(let i=0;i<n.length;i++){const o=n[i],r=n[i+1];if(_u.has(o))s("rest",Gy);else if(/\s/.test(o)){const a=e[e.length-1];a&&a.viseme!=="rest"&&e.push({viseme:"c",weight:Tu})}else if((o==="o"||o==="e")&&r===o)s(o==="o"?"u":"i",Gn),i++;else if(o in Eu)s(Eu[o],Gn);else if(o in Au)s(Au[o],ui);else{if(o==="h")continue;if(/[a-z]/.test(o))s("c",ui);else if(o in Pu)s(Pu[o],Gn);else if(Jy(o)){const a=r===xu?o==="फ"?"f":void 0:Uy[o];s(a??"c",ui);let l=i+1;n[l]===xu&&l++;const c=n[l];c===Vy?i=l:c&&c in $u?(s($u[c],Gn),i=l):(!c||/\s/.test(c)||_u.has(c)||s("a",Gn*.6),i=l-1)}else(o==="ं"||o==="ँ")&&s("l",ui*.6)}}for(;e.length>0&&(e[e.length-1].viseme==="rest"||e[e.length-1].weight===Tu);)e.pop();return e}function xr(t,e={}){const n=e.fields?.mouth??"mouth",s=e.fields?.mouthWidth??"mouthWidth",i=e.energy??1,o=Iu(t.text),r=[{time:t.start,value:ke.rest.mouth}],a=[{time:t.start,value:ke.rest.mouthWidth}],l=o.reduce((h,u)=>h+u.weight,0),c=t.end-t.start;if(l>0&&c>0){let h=t.start;for(const u of o){const d=c*u.weight/l,f=h+Math.min(d*.4,60);if(f>r[r.length-1].time){const g=ke[u.viseme];r.push({time:f,value:g.mouth*i,easing:"ease-out"}),a.push({time:f,value:1+(g.mouthWidth-1)*Math.min(1.3,i),easing:"ease-out"})}h+=d}}return t.end>r[r.length-1].time&&(r.push({time:t.end,value:ke.rest.mouth,easing:"ease-in-out"}),a.push({time:t.end,value:ke.rest.mouthWidth,easing:"ease-in-out"})),{[n]:r,[s]:a}}function Zy(t,e,n={}){const s={};for(const i of[...e].sort((o,r)=>o.start-r.start))for(const[o,r]of Object.entries(xr(i,n))){const a=s[o]??=[],l=a.length>0?a[a.length-1].time:-1/0;a.push(...r.filter(c=>c.time>l))}return Object.entries(s).map(([i,o])=>({id:`${t}-${i}`,target:t,property:i,keyframes:o}))}function Ou(t,e,n,s={}){if(n.length===0)return e;const i=s.fields?.mouth??"mouth",o=s.fields?.mouthWidth??"mouthWidth",r={[i]:ke.rest.mouth,[o]:ke.rest.mouthWidth,...s.rest},a=new Wt({id:"before-speech",tracks:e}),l=(u,d)=>a.getStateAtTime(d).values.get(t)?.get(u)??r[u],c=[i,o],h=e.filter(u=>u.target!==t||!c.includes(u.property));for(const u of c){const d=e.find(g=>g.target===t&&g.property===u);let f=d?[...d.keyframes]:[{time:0,value:l(u,0)}];for(const g of n){const p=xr(g,s)[u];p[0]={...p[0],value:l(u,g.start)},p[p.length-1]={...p[p.length-1],value:l(u,g.end)},f=[...f.filter(m=>m.time<g.start||m.time>g.end),...p],f.sort((m,b)=>m.time-b.time)}h.push({id:d?.id??`${t}-${u}`,target:t,property:u,keyframes:f})}return h}const Un={look:{summary:"Turns the head and eyes toward a scene x, `viewer`, `ahead` or `back`.",uses:["toward"]},face:{summary:"Turns the whole figure toward a scene x (turning round if needed), `viewer`, `ahead` or `back`.",uses:["toward"]},say:{summary:"Lip-syncs the `say` line with small nods; the beat lasts as long as the line.",needs:["say"]},hold:{summary:"Holds the pose (the acting pass drifts long holds)."},stand:{summary:"Back to its resting stance (a character’s own, else the rest pose), keeping the way it is turned."},go:{summary:"Walks to `to` in its own gait (a character’s, else walk).",needs:["to"]},zip:{summary:"The cartoon exit: winds up, wheels its legs in place, then shoots off to `to`, leaving dust.",needs:["to"]},leap:{summary:"Crouches, springs, arcs and lands squashed at `to`, on the floor `onto` (a scene y).",uses:["to","onto"]},swipe:{summary:"Winds an arm up, then slides along the target with the arm out so the hand crosses it edge to edge.",uses:["target"]},grab:{summary:"Steps to where its arm reaches the target (crouching for low things), takes it and lifts it overhead.",needs:["target"]},throw:{summary:"Winds the arm back and throws forward and up toward `to` (or the target); `release` is when it lets go.",uses:["to","target"]},kick:{summary:"Steps to a leg’s length from the target, draws the leg back and kicks through it.",needs:["target"]},put:{summary:"Steps to where its arm reaches the spot and sets the thing down there.",needs:["target"]},write:{summary:"Reaches a pen to the spot and writes along it left to right (moving along when it is wide).",needs:["target"]},push:{summary:"Sets both hands on the target’s near side and walks it along until its centre is at `to`.",needs:["target","to"]}};function _r(t={}){return[...Object.keys(_t),...Object.keys(Lt),...Object.keys(we),...Object.keys(Un),...Object.keys(t.gaits??{}),...Object.keys(t.actions??{})]}function Ir(t={}){const e=new Set(_r()),n=[];for(const s of[...Object.keys(t.actions??{}),...Object.keys(t.gaits??{})])e.has(s)&&n.push(`Custom action or gait "${s}" has the name of a built-in one; give it its own name.`);for(const s of Object.keys(t.actions??{}))t.gaits&&s in t.gaits&&n.push(`"${s}" is both a custom action and a custom gait.`);return n}function Or(t={}){const e={};for(const n of Object.keys(_t))e[n]=`Walks to \`to\` in the ${n} gait, feet planted, turning round first if needed.`;for(const n of Object.keys(Lt))e[n]=`Moves into the ${n} pose and holds it.`;for(const n of Object.keys(we))e[n]=`The ${n} gag, built on the current pose.`;for(const[n,s]of Object.entries(Un))e[n]=s.summary;for(const[n,s]of Object.entries(t.gaits??{}))e[n]=s.summary??`Walks to \`to\` in the ${n} gait (custom).`;for(const[n,s]of Object.entries(t.actions??{}))e[n]=s.summary;return e}const di=["do","at","for","to","toward","mood","say","pose","target","onto"],Qy={action:"do",type:"do",verb:"do",time:"at",start:"at",delay:"at",duration:"for",length:"for",ms:"for",x:"to",position:"to",destination:"to",expression:"mood",emotion:"mood",face:"mood",feeling:"mood",text:"say",line:"say",speech:"say",dialogue:"say",joints:"pose",y:"onto",floor:"onto",ground:"onto",object:"target",at_target:"target"},fi=["viewer","ahead","back"],Re=t=>typeof t=="number"&&Number.isFinite(t);function Cr(t,e={}){const n=Ir(e).map(l=>({level:"error",beat:-1,message:l}));if(!Array.isArray(t))return[...n,{level:"error",beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const s=_r(e),i=l=>l in _t||l in(e.gaits??{}),o=Object.keys(dt),r=Object.keys(it);let a=-1/0;return t.forEach((l,c)=>{const h=p=>n.push({level:"error",beat:c,message:p}),u=p=>n.push({level:"warning",beat:c,message:p});if(!l||typeof l!="object"||Array.isArray(l)){h(`Each beat must be an object like { do: 'walk', to: 400 } (got ${JSON.stringify(l)}).`);return}const d=l;for(const p of Object.keys(d))di.includes(p)||h(ft("beat field",p,di,Qy[p.toLowerCase()]));const f=d.do;if(f===void 0){h(`A beat needs \`do\` (what happens). Actions: ${s.join(", ")}`);return}if(typeof f!="string"||!s.includes(f)){h(ft("action",f,s));return}const g=Un[f]??e.actions?.[f];for(const p of g?.needs??[])d[p]===void 0&&h(`\`${f}\` needs \`${p}\`.`);if(i(f)&&d.to===void 0&&u(`\`${f}\` without \`to\` walks nowhere.`),f==="leap"&&d.to===void 0&&d.onto===void 0&&u("`leap` without `to` or `onto` jumps on the spot."),d.mood!==void 0&&(typeof d.mood!="string"||!o.includes(d.mood))&&h(ft("mood",d.mood,o)),d.pose!==void 0)if(!d.pose||typeof d.pose!="object"||Array.isArray(d.pose))h("`pose` is joints to change, an object like { rightShoulder: 90 } (for a named pose, use it as the action).");else for(const[p,m]of Object.entries(d.pose))r.includes(p)?Re(m)||h(`Pose joint \`${p}\` must be a number (got ${JSON.stringify(m)}).`):h(ft("pose joint",p,r));for(const p of["at","for"]){const m=d[p];m!==void 0&&!(Re(m)&&m>=0)&&h(`\`${p}\` is milliseconds, a number ≥ 0 (got ${JSON.stringify(m)}).`)}Re(d.at)&&(d.at<a&&u(`\`at\` ${d.at} is before an earlier beat's \`at\` (${a}); beats run in order, so it starts when the one before ends.`),a=d.at);for(const p of["to","onto"]){const m=d[p];m!==void 0&&!Re(m)&&h(`\`${p}\` is a scene ${p==="to"?"x":"y"} in px, a number (got ${JSON.stringify(m)}).`)}if(d.toward!==void 0&&!Re(d.toward)&&!fi.includes(d.toward)&&h(`\`toward\` is a scene x or one of ${fi.join(", ")}${typeof d.toward=="string"&&An(d.toward,fi)?` (did you mean "${An(d.toward,fi)}"?)`:""} (got ${JSON.stringify(d.toward)}).`),d.say!==void 0&&typeof d.say!="string"&&h(`\`say\` is the line spoken, a string (got ${JSON.stringify(d.say)}).`),d.target!==void 0){const p=d.target;(!p||typeof p!="object"||!Re(p.x)||!Re(p.y))&&h("`target` is a point or box in scene px: { x, y } (a code panel’s line(), token() or spot() fits).")}}),n}function Hr(t,e={},n="scriptTracks"){const s=Cr(t,e).filter(i=>i.level==="error");if(s.length!==0)throw new Error(`${n}: ${s.length} problem(s) in the beats:
53
+ `;function zg(t){if(t.getElementById(jc))return;const e=t.createElement("style");e.id=jc,e.textContent=Yg,t.head.appendChild(e)}function Bc(t,e){const n=Array.from(e.querySelectorAll("[data-tinyfly-choose]"));if(n.length===0)return()=>{};zg(e.ownerDocument);const s=[],i=[];for(const a of n){const l=a.getAttribute("data-tinyfly-choose")??"",c=[],h=(g,p)=>{a.hasAttribute(g)||(a.setAttribute(g,p),c.push(g))};h("role","button"),h("tabindex","0");const d=t.scenarios.find(g=>g.id===l)?.label;d!==void 0&&h("aria-label",d),a.setAttribute("aria-pressed","false"),c.push("aria-pressed"),s.push({element:a,attributes:c});const u=()=>t.setScenario(l),f=g=>{const p=g.key;p!=="Enter"&&p!==" "||(g.preventDefault(),u())};a.addEventListener("click",u),a.addEventListener("keydown",f),i.push(()=>{a.removeEventListener("click",u),a.removeEventListener("keydown",f)})}const o=()=>{for(const{element:a}of s)a.setAttribute("aria-pressed",String(a.getAttribute("data-tinyfly-choose")===t.scenario))},r=t.subscribe(o);return o(),()=>{r();for(const a of i)a();for(const{element:a,attributes:l}of s)for(const c of l)a.removeAttribute(c)}}const Fs=new WeakMap,qo=new WeakMap;let Xg=0;function Bn(t,e,n){if(t)try{return JSON.parse(t)}catch(s){console.warn(`tinyfly: invalid ${e} JSON on`,n,s);return}}async function Wc(t,e={}){const n=Fs.get(t);if(n)return n;const s=Array.from(t.querySelectorAll("script[data-tinyfly-timeline]")),i=s[0],o=t.getAttribute("data-src"),r=Gg(t.getAttribute("data-markers")),a=s.length>1||i?.hasAttribute("data-scenario")?Ug(s,r,t):void 0;if(a&&a.length===0)return;let l=i&&!a?Bn(i.textContent,"timeline",t):void 0;if(!l&&o&&r){const f=await fetch(o);f.ok&&(l=await f.json())}if(l&&r&&(l=qc(l,r)),!l&&!o&&!a){console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)',t);return}const c=Bn(t.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",t),h={playWhenVisible:!0,...e.player,...c&&{captions:c},...Bn(t.getAttribute("data-options"),"data-options",t)};Jg(t);const d=new Ds(t,h),u={element:t,player:d};if(Fs.set(t,u),t.setAttribute("data-tinyfly-mounted",""),a){const f=t.getAttribute("data-scenario")??void 0;await d.loadScenarios(a,{initial:a.some(g=>g.id===f)?f:void 0}),qo.set(t,Bc(d,t))}else await d.load(l??o);if(t.getAttribute("data-controls")!=="false"){const f=Bn(t.getAttribute("data-labels"),"data-labels",t),g=t.querySelector("figcaption"),p=t.getAttribute("data-scenario-legend"),m=t.getAttribute("data-scenario-control");u.controls=Fc(d,t,{...e.controls,...t.getAttribute("data-fullscreen")==="true"?{fullscreen:!0}:{},...m==="slider"||m==="buttons"?{scenarioControl:m}:{},labels:{...e.controls?.labels,...f,...p?{scenario:p}:{}},mount:void 0}),g?t.insertBefore(u.controls.element,g):t.appendChild(u.controls.element)}return u}function Ug(t,e,n){const s=[];return t.forEach((i,o)=>{const r=Bn(i.textContent,"timeline",n);if(!r)return;const a=i.getAttribute("data-scenario")||`scenario-${o+1}`;if(s.some(c=>c.id===a)){console.warn(`tinyfly: scenario id "${a}" is used more than once; the later one is skipped`,n);return}const l=i.getAttribute("data-scenario-label")??void 0;s.push({id:a,label:l,timeline:e?qc(r,e):r})}),s}function qc(t,e){return t.config.markers?.length?t:{...t,config:{...t.config,markers:e.map((n,s)=>({id:`step-${s+1}`,time:n}))}}}function Gg(t){if(!t)return;const e=t.split(/[\s,]+/).filter(Boolean).map(Number).filter(n=>Number.isFinite(n)&&n>=0).sort((n,s)=>n-s);return e.length>0?e:void 0}async function Kc(t=document,e={}){const n=Array.from(t.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(n.map(i=>Wc(i,e)))).filter(i=>i!==void 0)}function Vg(t){const e=Fs.get(t);e&&(qo.get(t)?.(),qo.delete(t),e.controls?.destroy(),e.player.destroy(),Fs.delete(t),t.removeAttribute("data-tinyfly-mounted"))}function Jg(t){const e=t.querySelector("svg");if(!e||e.hasAttribute("role")||e.hasAttribute("aria-hidden"))return;const n=t.getAttribute("data-alt"),s=t.querySelector("figcaption");e.setAttribute("role","img"),n?e.setAttribute("aria-label",n):s&&(s.id||=`tinyfly-caption-${++Xg}`,e.setAttribute("aria-labelledby",s.id))}function Zg(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const e=()=>{Kc()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}class Yc{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(e,n={}){if(typeof e=="string"){const s=document.querySelector(e);if(!s)throw new Error(`Container not found: ${e}`);this.container=s}else this.container=e;this.options=n,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 _e,this.adapterB=new _e}async load(e){let n;if(typeof e=="string"){const s=await fetch(e);if(!s.ok)throw new Error(`Failed to load sequence: ${s.statusText}`);n=await s.json()}else n=e;this.sequence=n,this.symbolDefs.clear();for(const s of n.symbols??[])s.timeline?.tracks?.length&&this.symbolDefs.set(s.id,s.timeline);this.container.style.width=`${n.canvas.width}px`,this.container.style.height=`${n.canvas.height}px`,n.scenes.length>0&&(this.renderScene(n.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(n.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 e=this.timelineA.getStateAtTime(0);this.adapterA.applyState(e),this.applyNested(this.adapterA,0)}}goToScene(e){if(!this.sequence||e<0||e>=this.sequence.scenes.length)return;const n=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=e,this._state=n?"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[e];if(this.renderScene(s,this.containerA,this.adapterA),this.timelineA=this.createTimeline(s),this.options.onSceneChange?.(e),n)this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play(),this.startAnimationLoop()):this.onSceneComplete();else if(this.timelineA){const i=this.timelineA.getStateAtTime(0);this.adapterA.applyState(i),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 e of this.nestedByAdapter.values())for(const n of e)n.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 e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.width="100%",e.style.height="100%",e}renderScene(e,n,s){n.innerHTML="",s.clearTargets();const i=document.createElement("div");i.style.cssText="position:absolute;inset:0;transform-origin:center center",i.setAttribute("data-tinyfly","Camera"),n.appendChild(i),s.registerTarget("Camera",i);for(const o of e.elements){if(!o.html)continue;const r=document.createElement("div");r.innerHTML=o.html.trim();const a=r.firstElementChild;if(a){i.appendChild(a);const l=a.getAttribute("data-tinyfly");l&&s.registerTarget(l,a)}}this.setupNested(i,s)}setupNested(e,n){const s=[];e.querySelectorAll("[data-tinyfly-symbol]").forEach(i=>{const o=i.getAttribute("data-tinyfly-symbol");if(!o)return;const r=this.symbolDefs.get(o);if(!r)return;const a=new _e;i.querySelectorAll("[data-tinyfly]").forEach(l=>{const c=l.getAttribute("data-tinyfly");c&&a.registerTarget(c,l)}),s.push({adapter:a,timeline:Qe(r)})}),s.length?this.nestedByAdapter.set(n,s):this.nestedByAdapter.delete(n)}applyNested(e,n){const s=this.nestedByAdapter.get(e);if(s)for(const i of s){const o=i.timeline.duration;i.adapter.applyState(i.timeline.getStateAtTime(o>0?n%o:n))}}clearContainer(e){e.innerHTML=""}createTimeline(e){return e.timeline?Qe(e.timeline):null}onSceneComplete(){if(this._isDestroyed||!this.sequence)return;const e=this._currentSceneIndex+1;if(e>=this.sequence.scenes.length){const n=this.options.loop??this.sequence.loop??0;n===-1||n>0&&this.loopIteration<n-1?(this.loopIteration++,this.beginTransitionTo(0)):(this._isPlaying=!1,this._state="idle",this.stopAnimationLoop(),this.options.onComplete?.())}else this.beginTransitionTo(e)}beginTransitionTo(e){if(!this.sequence||this._isDestroyed)return;const n=this.sequence.scenes[e],s=n.transition;if(s.type==="none"||s.duration<=0){this.switchToScene(e);return}this._state="transitioning",this.containerB.style.visibility="visible",this.renderScene(n,this.containerB,this.adapterB),this.timelineB=this.createTimeline(n),this.timelineB&&this.timelineB.play(),this.applyTransition(s.type,s.duration),this.transitionTimer=window.setTimeout(()=>{this.finishTransition(e)},s.duration)}applyTransition(e,n){const s=`${n}ms`,i="ease-in-out";switch(this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),e){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} ${i}, transform ${s} ${i}`,this.containerB.style.transition=`opacity ${s} ${i}, transform ${s} ${i}`,e){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(e){e.style.transition="",e.style.opacity="1",e.style.transform=""}finishTransition(e){this.transitionTimer=void 0,this.timelineA&&(this.timelineA.stop(),this.timelineA=null),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const n=this.containerA;this.containerA=this.containerB,this.containerB=n;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=e,this._state="playing-scene",this.options.onSceneChange?.(e),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.playbackState!=="playing"&&this.timelineA.play()):this.onSceneComplete()}switchToScene(e){if(!this.sequence||this._isDestroyed)return;this.timelineA&&this.timelineA.stop(),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const n=this.sequence.scenes[e];this.renderScene(n,this.containerA,this.adapterA),this.timelineA=this.createTimeline(n),this._currentSceneIndex=e,this._state="playing-scene",this.options.onSceneChange?.(e),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play()):this.onSceneComplete()}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const e=n=>{if(this._isDestroyed||!this._isPlaying)return;const s=n-(this.lastTime??n);if(this.lastTime=n,this.timelineA&&this.timelineA.playbackState==="playing"){this.timelineA.tick(s);const i=this.timelineA.getStateAtTime(this.timelineA.currentTime);this.adapterA.applyState(i),this.applyNested(this.adapterA,this.timelineA.currentTime)}if(this._state==="transitioning"&&this.timelineB&&this.timelineB.playbackState==="playing"){this.timelineB.tick(s);const i=this.timelineB.getStateAtTime(this.timelineB.currentTime);this.adapterB.applyState(i),this.applyNested(this.adapterB,this.timelineB.currentTime)}this._isPlaying?this.animationFrameId=requestAnimationFrame(e):this.animationFrameId=void 0};this.animationFrameId=requestAnimationFrame(e)}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}}async function Qg(t,e,n={}){const s=new Yc(t,{...n,autoplay:!0});return await s.load(e),s}const tm={type:"none",duration:0},yt=t=>({description:t,unit:"degrees"}),dt=(t,e=0,n=1)=>({description:t,unit:`${e}..${n}`,min:e,max:n}),zc={lean:yt("Upper body tipped about the hips (+ toward the way it faces)"),bend:yt("Line of action: the spine curved (+ curls forward, − arches back)"),headTilt:yt("Head tilt"),leftShoulder:yt("Left upper arm: 0 hangs down, 90 straight out to its side, 180 straight up; in profile, forward is negative for the left arm"),rightShoulder:yt("Right upper arm: 0 hangs down, 90 straight out (forward, in profile), 180 straight up"),leftElbow:yt("Left elbow bend, added to the upper arm"),rightElbow:yt("Right elbow bend, added to the upper arm"),leftHip:yt("Left thigh: 0 straight down; in profile negative is forward"),rightHip:yt("Right thigh: 0 straight down; in profile positive is forward"),leftKnee:yt("Left knee bend (negative folds the shin back)"),rightKnee:yt("Right knee bend (positive folds the shin back)"),leftWrist:yt("Left wrist bend, added to the forearm"),rightWrist:yt("Right wrist bend, added to the forearm"),leftAnkle:yt("Left ankle: + points the toe down (tiptoe), − onto the heel"),rightAnkle:yt("Right ankle: + points the toe down (tiptoe), − onto the heel"),leftFootOut:dt("Left foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),rightFootOut:dt("Right foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),mouth:dt("Mouth open: 0 closed, 1 wide open"),smile:dt("−1 frown, 0 flat, 1 smile",-1,1),mouthWidth:{description:"Mouth width: 1 normal, 0.5 pursed, 1.5 wide",unit:"factor",min:.3,max:2},blink:dt("Eyes closed by a blink: 0 open, 1 shut"),leftEye:{description:"Left eye openness: 0 shut, 1 normal, 1.6 wide",unit:"factor",min:0,max:2},rightEye:{description:"Right eye openness: 0 shut, 1 normal, 1.6 wide",unit:"factor",min:0,max:2},leftBrow:dt("Left eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),rightBrow:dt("Right eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),browTilt:dt("Eyebrow slant: −1 angry, 1 worried",-1,1),lookX:dt("Eyes look across: + the way it faces",-1,1),lookY:dt("Eyes look down (+) or up (−)",-1,1),stretch:{description:"Squash and stretch: 1 normal, above taller (a jump), below squashed (a landing)",unit:"factor",min:.3,max:3},turn:dt("0 front-on, 1 in profile, turned the way it faces"),sit:dt("0 standing, 1 seated"),spin:yt("Whole body turned about the hips: + rolls forward (a front flip), 360 a full turn"),rise:{description:"Lift off the ground, as a fraction of its height (the arc of a jump)",unit:"× height"}},Xc={walk:{description:"Walk-cycle phase, in strides: animate 0 → n for n strides",unit:"strides"},walking:dt("How much of the walk cycle is applied (0 standing)"),gait:{description:"How it walks: a gait name (walk, bouncy, doubleBounce, sneak, strut, tired, run, shove); a string track switches it",kind:"string"},talk:dt("How much the mouth chatters"),rubber:dt("Limbs from jointed (0) to rubber hose (1)"),facing:{description:"Which way it faces: 1 right, −1 left (key the flip while turn is near 0)",unit:"±1",min:-1,max:1},beat:{description:"Beats into its dance (with a dance)",unit:"beats"},dancing:dt("How much of the dance is applied")},Uc={"thumb.curl":dt("Thumb curled in"),"thumb.across":dt("Thumb across the palm"),"index.curl":dt("Index finger curled"),"middle.curl":dt("Middle finger curled"),"ring.curl":dt("Ring finger curled"),"pinky.curl":dt("Little finger curled"),spread:dt("Fingers spread apart"),turn:yt("Hand turned about the forearm"),bend:yt("Hand bent at the wrist, palm-ward"),tilt:yt("Hand tilted sideways"),roll:yt("Hand rolled to show the back or the palm")};let Gc;function em(t){Gc=t}function nm(t){return Gc?.(t)??{}}function Vc(t){let e=0;for(let n=1;n<t.length;n++)e+=Math.hypot(t[n].x-t[n-1].x,t[n].y-t[n-1].y);return e}function ln(t,e){const n=Math.min(1,Math.max(0,e));if(t.length<2||n===1)return t.slice();if(n===0)return t.slice(0,1);let s=Vc(t)*n;const i=[t[0]];for(let o=1;o<t.length;o++){const r=t[o-1],a=t[o],l=Math.hypot(a.x-r.x,a.y-r.y);if(l>=s){const c=l===0?0:s/l;return i.push({x:r.x+(a.x-r.x)*c,y:r.y+(a.y-r.y)*c}),i}i.push(a),s-=l}return i}function js(t,e){const n=ln(t,e);return n[n.length-1]}function Ko(t,e){return e>0?Math.floor(Math.max(0,t)*e/1e3):0}function Bs(t,e,n){const s=e.roughness??2,i=Math.max(1,Math.round(e.passes??2)),o=Ko(n,e.boil??8);let r=0;const a=()=>{const u=r++;return f=>$e(qt(`${e.seed??1}:${o}:${u}:${f}`))},l=(u,f)=>(u.next()*2-1)*f,c=u=>{const f=a(),g=t.lineWidth,p=t.globalAlpha;for(let m=0;m<i;m++)t.lineWidth=m===0?g:g*.55,t.globalAlpha=m===0?p:p*.6,u(f(m));t.lineWidth=g,t.globalAlpha=p},h=(u,f=1)=>{if(u.length<2)return;const g=u.slice(1).map((m,b)=>Math.hypot(m.x-u[b].x,m.y-u[b].y)),p=g.reduce((m,b)=>m+b,0)*Math.min(1,Math.max(0,f));c(m=>{const b=[],S=[];if(u.forEach((y,M)=>{b.push({x:y.x+l(m,s*.5),y:y.y+l(m,s*.5)}),M>0&&S.push([m.next()*2-1,m.next()*2-1])}),p<=0)return;t.beginPath(),t.moveTo(b[0].x,b[0].y);let k=0;for(let y=1;y<b.length;y++){const M=sm(b[y-1],b[y],s,S[y-1]),$=g[y-1];if(k+$<=p){t.bezierCurveTo(M[1].x,M[1].y,M[2].x,M[2].y,M[3].x,M[3].y),k+=$;continue}const E=im(M,$===0?1:(p-k)/$);t.bezierCurveTo(E[1].x,E[1].y,E[2].x,E[2].y,E[3].x,E[3].y);break}t.stroke()})},d=(u,f,g,p,m=1)=>{c(b=>{const k=b.next()*Math.PI*2,y=Math.PI*2+.15+b.next()*.3,M=[];for(let E=0;E<=14;E++){const A=k+y*E/14,T=l(b,s*.6);M.push({x:u+Math.cos(A)*(g+T),y:f+Math.sin(A)*(p+T)})}const $=ln(M,m);$.length<2||(Jc(t,$),t.stroke())})};return{line:h,curve(u,f=1){if(u.length<2)return;const g=u[0],p=u[u.length-1],m=Math.hypot(p.x-g.x,p.y-g.y)||1,b=-(p.y-g.y)/m,S=(p.x-g.x)/m;c(k=>{const y={x:l(k,s*.5),y:l(k,s*.5)},M={x:l(k,s*.5),y:l(k,s*.5)},$=l(k,s*Math.min(1.5,Math.max(.3,m/80))),E=u.map((T,I)=>{const v=I/(u.length-1),P=Math.sin(Math.PI*v)*$;return{x:T.x+y.x+(M.x-y.x)*v+b*P,y:T.y+y.y+(M.y-y.y)*v+S*P}}),A=ln(E,f);A.length<2||(Jc(t,A),t.stroke())})},circle(u,f,g,p=1){d(u,f,g,g,p)},ellipse:d,nudge(u=.5){const f=a()(0);return{x:l(f,s*u),y:l(f,s*u)}}}}function sm(t,e,n,s){const i=e.x-t.x,o=e.y-t.y,r=Math.hypot(i,o)||1,a=n*Math.min(1.5,Math.max(.3,r/80)),l=-o/r,c=i/r;return[t,{x:t.x+i/3+l*s[0]*a,y:t.y+o/3+c*s[0]*a},{x:t.x+2*i/3+l*s[1]*a,y:t.y+2*o/3+c*s[1]*a},e]}function im([t,e,n,s],i){const o=(d,u)=>({x:d.x+(u.x-d.x)*i,y:d.y+(u.y-d.y)*i}),r=o(t,e),a=o(e,n),l=o(n,s),c=o(r,a),h=o(a,l);return[t,r,c,o(c,h)]}function Jc(t,e){t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let s=1;s<e.length-1;s++){const i={x:(e[s].x+e[s+1].x)/2,y:(e[s].y+e[s+1].y)/2};t.quadraticCurveTo(e[s].x,e[s].y,i.x,i.y)}const n=e[e.length-1];t.lineTo(n.x,n.y)}function Wn(t,e,n){const s=t.length;if(s<2)return[];const i=[],o=[],r=a=>e+(n-e)*a/(s-1);return t.forEach((a,l)=>{const c=t[Math.max(0,l-1)],h=t[Math.min(s-1,l+1)],d=Math.hypot(h.x-c.x,h.y-c.y)||1,u=r(l)/2,f=-(h.y-c.y)/d*u,g=(h.x-c.x)/d*u;i.push({x:a.x+f,y:a.y+g}),o.push({x:a.x-f,y:a.y-g})}),[...i,...o.reverse()]}function Ws(t,e,n,s){const i=e.length;if(i<2)return;const o=Wn(e,n,s),r=a=>n+(s-n)*a/(i-1);t.beginPath(),t.moveTo(o[0].x,o[0].y);for(const a of o.slice(1))t.lineTo(a.x,a.y);t.closePath(),t.fill(),e.forEach((a,l)=>{l!==0&&l!==i-1&&i>3||(t.beginPath(),t.arc(a.x,a.y,r(l)/2,0,Math.PI*2),t.fill())})}function Ce(t,e,n,s,i=16){const o={x:2*e.x-(t.x+n.x)/2,y:2*e.y-(t.y+n.y)/2},r=[];for(let a=0;a<=i;a++){const l=a/i,c=l<.5?{x:t.x+(e.x-t.x)*2*l,y:t.y+(e.y-t.y)*2*l}:{x:e.x+(n.x-e.x)*(2*l-1),y:e.y+(n.y-e.y)*(2*l-1)},h=1-l,d={x:h*h*t.x+2*h*l*o.x+l*l*n.x,y:h*h*t.y+2*h*l*o.y+l*l*n.y};r.push({x:c.x+(d.x-c.x)*s,y:c.y+(d.y-c.y)*s})}return r}function Yo(t,e,n,s,i,o=0,r=1,a=40){const l=Math.cos(i),c=Math.sin(i);return Array.from({length:a+1},(h,d)=>{const u=o+Math.PI*2*r*d/a,f=Math.cos(u)*n,g=Math.sin(u)*s;return{x:t+f*l-g*c,y:e+f*c+g*l}})}function qn(t,e){return e.look==="pencil"?lm(t,e):om(t,e.ink,e.look)}function qs(t,e,n=!1){t.beginPath(),t.moveTo(e[0].x,e[0].y);for(const s of e.slice(1))t.lineTo(s.x,s.y);n&&t.closePath()}function om(t,e,n){const s=n==="silhouette",i=s?1.25:1;return{look:n,ink:e,limb(o,r,a){t.fillStyle=e,Ws(t,o,r*i,a*i)},line(o,r){o.length<2||(t.strokeStyle=e,t.lineWidth=r*i,t.lineCap="round",t.lineJoin="round",qs(t,o),t.stroke())},shape(o,r,a){qs(t,o,!0),(r!==null||s)&&(t.fillStyle=s?e:r,t.fill()),!(a<=0)&&(t.strokeStyle=e,t.lineWidth=a*i,t.lineJoin="round",t.stroke())},ellipse(o,r,a,l,c,h,d){t.beginPath(),t.ellipse(o,r,a,l,c,0,Math.PI*2),(h!==null||s)&&(t.fillStyle=s?e:h,t.fill()),!(d<=0)&&(t.strokeStyle=e,t.lineWidth=d*i,t.stroke())},dot(o,r,a){t.fillStyle=e,t.beginPath(),t.arc(o,r,a*i,0,Math.PI*2),t.fill()},guide(){},guideEllipse(){}}}function rm(t,e){const n=[t[0]];let s=0;for(let r=1;r<t.length;r++){const a=t[r-1],l=t[r],c=Math.hypot(l.x-a.x,l.y-a.y);let h=e-s;for(;h<c;){const d=h/c;n.push({x:a.x+(l.x-a.x)*d,y:a.y+(l.y-a.y)*d}),h+=e}s=c-(h-e)}const i=t[t.length-1],o=n[n.length-1];return Math.hypot(i.x-o.x,i.y-o.y)>e*.25?n.push(i):n[n.length-1]=i,n}function am(t,e){const n=t.length;return t.map((s,i)=>{const o=t[Math.max(0,i-1)],r=t[Math.min(n-1,i+1)],a=Math.hypot(r.x-o.x,r.y-o.y)||1,l=e(n===1?0:i/(n-1));return{x:s.x-(r.y-o.y)/a*l,y:s.y+(r.x-o.x)/a*l}})}function Zc(t){const e=[.6,1.4,2.9].map(s=>({frequency:s*(.8+t.next()*.4),phase:t.next()*Math.PI*2,amount:.5+t.next()*.5})),n=e.reduce((s,i)=>s+i.amount,0);return s=>e.reduce((i,o)=>i+o.amount*Math.sin(Math.PI*2*o.frequency*s+o.phase),0)/n}function lm(t,e){const n=e.pencil??{},s=e.ink,i=n.roughness??Math.max(1,e.lineWidth*.12),o=Math.max(1,Math.round(n.passes??2)),r=Math.min(1,Math.max(0,n.pressure??.25)),a=Math.min(1,Math.max(0,n.rubbedOut??.15)),l=Ko(e.time,n.boil??8);let c=0;const h=(g,p,m=!1)=>$e(qt(`${e.seed}:${m?"paper":l}:${g}:${p}`)),d=(g,p,m,b,S,k=0)=>{if(g.length<2)return;const y=g.slice(1).reduce((v,P,H)=>v+Math.hypot(P.x-g[H].x,P.y-g[H].y),0);let M=rm(g,Math.max(1.5,Math.min(e.lineWidth*.8,y/24)));if(k>0&&M.length>=2){const[v,P]=[M[M.length-2],M[M.length-1]],H=Math.hypot(P.x-v.x,P.y-v.y)||1;M=[...M,{x:P.x+(P.x-v.x)/H*k,y:P.y+(P.y-v.y)/H*k}]}const $=Zc(m),E=Zc(m),A=M.length,T=[],I=[];M.forEach((v,P)=>{const H=A===1?0:P/(A-1),O=M[Math.max(0,P-1)],C=M[Math.min(A-1,P+1)],j=Math.hypot(C.x-O.x,C.y-O.y)||1,D=-(C.y-O.y)/j,W=(C.x-O.x)/j,B=$(H)*S,_=Math.min(1,H/.08,(1-H)/.08),L=(.55+.45*Math.sqrt(Math.max(0,_)))*(1+r*E(H)),N=Math.max(.3,p(H)*L/2),x=v.x+D*B,R=v.y+W*B;T.push({x:x+D*N,y:R+W*N}),I.push({x:x-D*N,y:R-W*N})}),t.save(),t.globalAlpha*=b,t.fillStyle=s,qs(t,[...T,...I.reverse()],!0),t.fill(),t.restore()},u=(g,p)=>{const m=c++,b=h(m,99,!0);if(b.next()<a){const M=(b.next()*2-1)*e.lineWidth*1.4,$=(b.next()*2-1)*e.lineWidth*1.4,E=g.map(A=>({x:A.x+M,y:A.y+$}));d(E,A=>p(A)*1.8,h(m,98,!0),.035,i),d(E,A=>p(A)*.45,h(m,97,!0),.12,i*1.5)}const S=g.slice(1).reduce((M,$,E)=>M+Math.hypot($.x-g[E].x,$.y-g[E].y),0),k=p(.5)>4&&S>p(.5)*6,y=k?[-.3,.3,0]:[0];for(let M=0;M<o;M++){const $=M===0;y.forEach((E,A)=>{const T=h(m,M*10+A),I=E===0?g:am(g,P=>p(P)*E*Math.sqrt(Math.sin(Math.PI*P))),v=!$&&E===0?e.lineWidth*(.3+T.next()*.8):0;d(I,P=>p(P)*(k?.5:1)*($?1:.6),T,$?.85:.45,i*($?.6:1),v)})}},f=(g,p,m,b,S,k)=>{const M=h(c,50).next()*Math.PI*2;u(Yo(g,p,m,b,S,M,1.08,48),()=>k)};return{look:"pencil",ink:s,limb(g,p,m){u(g,b=>p+(m-p)*b)},line(g,p){u(g,()=>p)},shape(g,p,m){p!==null&&(t.save(),t.globalAlpha*=.88,t.fillStyle=p,qs(t,g,!0),t.fill(),t.restore()),m>0&&u([...g,g[0]],()=>m)},ellipse(g,p,m,b,S,k,y){k!==null&&(t.save(),t.globalAlpha*=.9,t.fillStyle=k,t.beginPath(),t.ellipse(g,p,m,b,S,0,Math.PI*2),t.fill(),t.restore()),f(g,p,m,b,S,y)},dot(g,p,m){t.save(),t.globalAlpha*=.9,t.fillStyle=s,t.beginPath(),t.arc(g,p,m,0,Math.PI*2),t.fill(),t.restore()},guide(g){if(n.construction===!1||g.length<2)return;const p=c++;d(g,()=>Math.max(.6,e.lineWidth*.18),h(p,0),.28,i*1.2,e.lineWidth)},guideEllipse(g,p,m,b,S){if(n.construction===!1)return;const k=c++,y=h(k,0),M=Yo(g,p,m,b,S,y.next()*Math.PI*2,1.12,48);d(M,()=>Math.max(.6,e.lineWidth*.18),y,.28,i*1.5)}}}const Qc=["thumb","index","middle","ring","pinky"],vt={"thumb.curl":.15,"thumb.across":.15,"index.curl":.12,"middle.curl":.16,"ring.curl":.2,"pinky.curl":.25,spread:.25,turn:0,bend:0,tilt:0,roll:0};function Mt(t={}){return{...vt,...t}}const Nt=(t,e,n,s,i)=>({"thumb.curl":t,"index.curl":e,"middle.curl":n,"ring.curl":s,"pinky.curl":i}),Tt={relaxed:vt,open:Mt({...Nt(0,0,0,0,0),"thumb.across":0,spread:.55}),spread:Mt({...Nt(0,0,0,0,0),"thumb.across":0,spread:1}),flat:Mt({...Nt(0,0,0,0,0),"thumb.across":.35,spread:0}),fist:Mt({...Nt(.7,1,1,1,1),"thumb.across":.9,spread:0}),point:Mt({...Nt(.75,0,1,1,1),"thumb.across":.9,spread:0}),thumbsUp:Mt({...Nt(0,1,1,1,1),"thumb.across":0,spread:0,roll:70}),peace:Mt({...Nt(.75,0,0,1,1),"thumb.across":.9,spread:1}),ok:Mt({...Nt(.12,.6,.1,.15,.2),"thumb.across":.55,spread:.6}),pinch:Mt({...Nt(.1,.65,.75,.85,.9),"thumb.across":.55,spread:0}),cupped:Mt({...Nt(.25,.4,.4,.4,.4),"thumb.across":.4,spread:.05,turn:2}),wave:Mt({...Nt(0,.05,.05,.1,.12),"thumb.across":0,spread:.7,turn:2}),pencilGrip:Mt({...Nt(.1,.6,.72,.88,.95),"thumb.across":.5,spread:0,turn:.8,bend:10}),hold:Mt({...Nt(.5,.7,.72,.74,.76),"thumb.across":.75,spread:0,turn:1})};function cn(t,e,n){const s={...t};for(const[i,o]of Object.entries(e)){const r=t[i]??o;s[i]=r+(o-r)*n}return s}const cm={index:{knuckle:[-.16,.47,-.02],bones:[.2,.125,.1],width:.125,fan:-1},middle:{knuckle:[-.055,.49,-.02],bones:[.22,.135,.1],width:.13,fan:-.2},ring:{knuckle:[.05,.475,-.02],bones:[.2,.125,.1],width:.122,fan:.55},pinky:{knuckle:[.15,.43,-.02],bones:[.16,.1,.085],width:.108,fan:1.25}},hm={index:{knuckle:[-.14,.47,-.02],bones:[.2,.125,.1],width:.15,fan:-1},middle:{knuckle:[0,.49,-.02],bones:[.22,.135,.1],width:.155,fan:0},pinky:{knuckle:[.14,.45,-.02],bones:[.19,.115,.095],width:.145,fan:1}},te={base:[-.11,.1,-.05],bones:[.2,.15,.12],widths:[.2,.145,.135],out:[-.7,.68,-.22],across:[.35,.5,-.8]},dm=[82,100,62],um=[48,72],fm=3,pm=13,gm=.035,mm=-.075,ym=[[-.17,0],[-.215,.12],[-.235,.26],[-.225,.4],[-.185,.49],[-.075,.525],[.05,.51],[.16,.465],[.215,.4],[.225,.26],[.2,.1],[.16,0]],fe=t=>t*Math.PI/180,zo=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Ks=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],Xo=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],Kn=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function pe(t,e,n){const s=Math.cos(n),i=Math.sin(n),o=Xo(e,t),r=e[0]*t[0]+e[1]*t[1]+e[2]*t[2];return[t[0]*s+o[0]*i+e[0]*r*(1-s),t[1]*s+o[1]*i+e[1]*r*(1-s),t[2]*s+o[2]*i+e[2]*r*(1-s)]}const th=[1,0,0],eh=[0,1,0],Yn=[0,0,1];function bm(t,e,n){const s=fe(t.fan*(fm+pm*n)),i=[Math.sin(s),Math.cos(s),0],o=[Math.cos(s),-Math.sin(s),0],r=[t.knuckle];let a=0;t.bones.forEach((h,d)=>{a+=fe(dm[d]*e),r.push(zo(r[d],Ks(pe(i,o,-a),h)))});const l=pe(Yn,o,-a),c=r.map((h,d)=>t.width*(1-.14*(d/(r.length-1))));return{joints:r,back:l,widths:c}}function wm(t,e,n=1,s=1){const i=Math.min(1,Math.max(0,e)),o=Kn(zo(Ks(Kn(te.out),1-i),Ks(Kn(te.across),i))),r=Kn(Xo(Yn,o)),a=Kn(Xo(o,r)),l=[[te.base[0]*s,te.base[1],te.base[2]]];let c=0;te.bones.forEach((u,f)=>{f>0&&(c+=fe(um[f-1]*t)),l.push(zo(l[f],Ks(pe(o,r,c),u)))});const h=pe(a,r,c),d=[...te.widths,te.widths[te.widths.length-1]*.92].map(u=>u*n);return{joints:l,back:h,widths:d}}function Ys(t,e={}){const n={...vt,...t},s=e.size??100,i=e.side??"right",o=i==="left"?-1:1,r=fe(e.angle??0),a=e.fingers===4,l=Math.max(.5,e.plump??1),c=1+(l-1)*.7,h=P=>({...P,knuckle:[P.knuckle[0]*c,P.knuckle[1],P.knuckle[2]],width:P.width*l}),d=fe(n.bend??0),u=fe(n.tilt??0),f=fe(90*(n.turn??0)),g=P=>pe(pe(pe(P,th,-d),Yn,-u),eh,f),p=Math.cos(r),m=Math.sin(r),b=fe(n.roll??0),S=Math.cos(b),k=Math.sin(b),y=P=>{const H=P[0]*s,O=-P[1]*s,C=(H*S-O*k)*o,j=H*k+O*S;return{x:C*p-j*m,y:C*m+j*p}},M=P=>{const H=y(P),O=Math.hypot(H.x,H.y);return O>1e-6*s?{x:H.x/O,y:H.y/O}:{x:0,y:0}},$={thumb:wm(n["thumb.curl"]??0,n["thumb.across"]??0,l,c)},E=a?hm:cm;for(const P of Qc){const H=E[P];H&&($[P]=bm(h(H),n[`${P}.curl`]??0,n.spread??0))}const A={};for(const[P,H]of Object.entries($)){const O=H.joints.map(g),C=g(H.back);A[P]={points:O.map(y),depths:O.map(j=>j[2]*s),widths:H.widths.map(j=>j*s),nail:C[2],back:M(C)}}const T=ym.flatMap(([P,H])=>[g([P*c,H,gm]),g([P*c,H,mm])]),I=km(T.map(y)),v=T.reduce((P,H)=>P+H[2],0)/T.length*s;return{size:s,side:i,wrist:{x:0,y:0},palm:I,palmDepth:v,palmFacing:-g(Yn)[2],fingers:A,axes:{up:M(g(eh)),across:M(g(th)),out:M(g(Yn))},curls:Object.fromEntries(Object.keys(A).map(P=>[P,n[`${P}.curl`]??0]))}}function nh(t,e){const n=i=>({x:i.x+e.x-t.wrist.x,y:i.y+e.y-t.wrist.y}),s={};for(const[i,o]of Object.entries(t.fingers))s[i]={...o,points:o.points.map(n)};return{...t,wrist:n(t.wrist),palm:t.palm.map(n),fingers:s}}function km(t){const e=[...t].sort((o,r)=>o.x-r.x||o.y-r.y);if(e.length<3)return e;const n=(o,r,a)=>(r.x-o.x)*(a.y-o.y)-(r.y-o.y)*(a.x-o.x),s=[];for(const o of e){for(;s.length>=2&&n(s[s.length-2],s[s.length-1],o)<=0;)s.pop();s.push(o)}const i=[];for(const o of[...e].reverse()){for(;i.length>=2&&n(i[i.length-2],i[i.length-1],o)<=0;)i.pop();i.push(o)}return[...s.slice(0,-1),...i.slice(0,-1)]}const vm="#f1c9a5",Mm="#2f2f33";function zs(t,e,n,s={},i=0){const o=nh(Ys(n,s),e),r=s.ink??Mm,a=s.lineWidth??o.size*.035,l=s.pen??qn(t,{look:s.look??"clean",ink:r,lineWidth:a,seed:s.seed??1,time:i,pencil:{construction:!1,...s.pencil}}),c=s.skin??vm,h=s.nails??!0,d=[{depth:o.palmDepth,draw:()=>Sm(l,o,c,a)}];for(const u of Object.values(o.fingers)){const f=u.depths.reduce((g,p)=>g+p,0)/u.depths.length;d.push({depth:f,draw:()=>Tm(t,l,u,c,a,h)})}if(s.prop){const u=s.prop;d.push({depth:u.depth,draw:()=>u.draw(l)})}t.save(),t.lineCap="round",t.lineJoin="round";for(const u of[...d].sort((f,g)=>f.depth-g.depth))u.draw();return t.restore(),o}function Sm(t,e,n,s){if(t.shape(e.palm,n,s),e.palmFacing<-.3&&t.look!=="silhouette"){const{up:i}=e.axes;for(const[o,r]of Object.entries(e.fingers)){const a=e.curls[o]??0;if(o==="thumb"||a<.5)continue;const l=r.points[0],c=r.widths[0]*.42,h={x:l.x-i.x*c*.2,y:l.y-i.y*c*.2},d=Math.atan2(i.y,i.x),u=Array.from({length:7},(f,g)=>{const p=d-Math.PI/2+Math.PI*g/6;return{x:h.x+Math.cos(p)*c,y:h.y+Math.sin(p)*c}});t.line(u,s*.6)}}if(e.palmFacing>.45&&t.look!=="silhouette"){const{up:i,across:o}=e.axes,r=e.size,a=e.wrist,l=(h,d)=>({x:a.x+(o.x*h+i.x*d)*r,y:a.y+(o.y*h+i.y*d)*r}),c=e.side==="left"?-1:1;t.line([l(-.15*c,.36),l(-.04*c,.3),l(.1*c,.33)],s*.5)}}function Tm(t,e,n,s,i,o){const{widths:r}=n,a=Em(n.points,2),l=n.points[0],c=a[a.length-1],h=r[0],d=r[r.length-1];if(t.save(),e.look!=="silhouette"){t.beginPath(),t.rect(l.x-1e5,l.y-1e5,2e5,2e5);const p=h/2+i*1.6;t.moveTo(l.x+p,l.y),t.arc(l.x,l.y,p,0,Math.PI*2),t.clip("evenodd")}if(e.limb(a,h+2*i,d+2*i),t.restore(),e.look!=="silhouette"&&(t.fillStyle=s,Ws(t,a,h,d)),e.look==="silhouette"||!o||n.nail<.25)return;const u=a[a.length-2],f=Am({x:c.x-u.x,y:c.y-u.y})??{x:0,y:-1},g={x:c.x-f.x*d*.22+n.back.x*d*.1,y:c.y-f.y*d*.22+n.back.y*d*.1};e.ellipse(g.x,g.y,d*.24*Math.max(.35,n.nail),d*.19,Math.atan2(f.y,f.x),"#f8e3d3",i*.45)}function Em(t,e){let n=t;for(let s=0;s<e;s++){if(n.length<3)return n;const i=[n[0]];for(let o=0;o<n.length-1;o++){const r=n[o],a=n[o+1];o>0&&i.push({x:r.x*.75+a.x*.25,y:r.y*.75+a.y*.25}),o<n.length-2&&i.push({x:r.x*.25+a.x*.75,y:r.y*.25+a.y*.75})}i.push(n[n.length-1]),n=i}return n}const Am=t=>{const e=Math.hypot(t.x,t.y);return e>1e-6?{x:t.x/e,y:t.y/e}:null},Ot={walk:{swing:24,knee:30,arm:22,elbow:28,lean:4},bouncy:{swing:26,knee:45,arm:34,elbow:30,lean:2,bend:-4,bounce:.035,squash:.06},doubleBounce:{swing:22,knee:40,arm:26,elbow:24,lean:3,bounce:.02,bounces:2,squash:.04},sneak:{swing:28,knee:70,arm:6,elbow:0,forearm:110,shoulder:55,lean:16,bend:14,headTilt:-8,crouch:50,tiptoe:25},strut:{swing:26,knee:30,arm:30,elbow:20,lean:-4,bend:-10,headTilt:-6,sway:4,bounce:.01},tired:{swing:14,knee:14,arm:6,elbow:6,lean:10,bend:16,headTilt:12},run:{swing:40,knee:95,arm:45,elbow:0,forearm:90,lean:16,bend:6,bounce:.05,squash:.06},shove:{swing:18,knee:28,arm:0,elbow:0,lean:0}},$m=40;function zn(t){return t===void 0?Ot.walk:typeof t=="string"?Ot[t]??Ot.walk:t}function sh(t,e,n=et,s=1){const i=zn(t);if(i===Ot.walk)return lh(e,n,s);const o=e*Math.PI*2,r=Math.sin(o)*s,a=Math.cos(o)*s,l=b=>Math.abs(b)<=$m,c=i.shoulder??0,h=(b,S)=>l(b)?S*c+i.arm*r:b,d=i.forearm??0,u=l(n.leftShoulder)?n.leftElbow-d-i.elbow*Math.max(0,-r):n.leftElbow,f=l(n.rightShoulder)?n.rightElbow+d+i.elbow*Math.max(0,r):n.rightElbow,g=i.bounces??1,p=(1+Math.cos(o*2*g))/2,m=i.crouch??0;return{...n,lean:n.lean+i.lean*s+(i.sway??0)*Math.sin(o)*(1-(n.turn??0)),bend:(n.bend??0)+(i.bend??0),headTilt:n.headTilt-i.lean*.5*s+(i.headTilt??0),leftElbow:u,rightElbow:f,leftHip:-i.swing*r-m*.5,rightHip:-i.swing*r+m*.5,leftKnee:-i.knee*Math.max(0,a)-m,rightKnee:i.knee*Math.max(0,-a)+m,leftAnkle:(n.leftAnkle??0)+(i.tiptoe??0),rightAnkle:(n.rightAnkle??0)+(i.tiptoe??0),leftShoulder:h(n.leftShoulder,-1),rightShoulder:h(n.rightShoulder,1),rise:(n.rise??0)+(i.bounce??0)*s*p,stretch:n.stretch*(1+(i.squash??0)*(p-.5))}}function Uo(t,e,n=1){const s=zn(t),i=Ot.walk.swing,o=r=>Math.sin(r*Math.PI/180);return ch(e,n)*o(s.swing*n)/o(i*n)}const et={lean:0,bend:0,headTilt:0,leftShoulder:18,rightShoulder:18,leftElbow:-6,rightElbow:-6,leftHip:8,rightHip:8,leftKnee:0,rightKnee:0,leftWrist:0,rightWrist:0,leftAnkle:0,rightAnkle:0,leftFootOut:0,rightFootOut:0,mouth:0,smile:.6,mouthWidth:1,blink:0,leftEye:1,rightEye:1,leftBrow:0,rightBrow:0,browTilt:0,lookX:0,lookY:0,stretch:1,turn:0,sit:0,spin:0,rise:0};function Et(t){return{...et,...t}}const ih={mouth:0,smile:0,mouthWidth:1,leftEye:1,rightEye:1,leftBrow:0,rightBrow:0,browTilt:0,lookX:0,lookY:0},Pt=t=>({...ih,...t}),ct={neutral:ih,happy:Pt({smile:.9,leftBrow:.2,rightBrow:.2}),joyful:Pt({mouth:.6,smile:1,mouthWidth:1.2,leftEye:0,rightEye:0,leftBrow:.4,rightBrow:.4}),sad:Pt({smile:-.8,leftEye:.8,rightEye:.8,browTilt:.9,leftBrow:-.1,rightBrow:-.1,lookY:.6}),crying:Pt({mouth:.45,smile:-1,leftEye:0,rightEye:0,browTilt:1,lookY:.4}),surprised:Pt({mouth:.7,mouthWidth:.7,leftEye:1.5,rightEye:1.5,leftBrow:1,rightBrow:1}),shocked:Pt({mouth:1,mouthWidth:.8,leftEye:1.6,rightEye:1.6,leftBrow:1,rightBrow:1,browTilt:.4}),angry:Pt({smile:-.6,mouthWidth:.9,leftEye:.8,rightEye:.8,leftBrow:-.6,rightBrow:-.6,browTilt:-1}),furious:Pt({mouth:.5,smile:-1,mouthWidth:1.3,leftEye:.9,rightEye:.9,leftBrow:-.9,rightBrow:-.9,browTilt:-1}),worried:Pt({smile:-.3,mouthWidth:.8,leftEye:1.1,rightEye:1.1,leftBrow:.3,rightBrow:.3,browTilt:.8,lookX:-.5}),scared:Pt({mouth:.35,smile:-.5,mouthWidth:.8,leftEye:1.45,rightEye:1.45,leftBrow:.8,rightBrow:.8,browTilt:.9}),confused:Pt({smile:-.2,mouthWidth:.8,leftEye:.9,rightEye:1.15,leftBrow:-.3,rightBrow:.8,lookX:.5,lookY:-.4}),skeptical:Pt({smile:-.1,leftEye:.6,rightEye:1,leftBrow:-.4,rightBrow:.7,lookX:.4}),thinking:Pt({smile:0,mouthWidth:.7,leftBrow:.3,rightBrow:.5,lookX:.6,lookY:-.8}),sleepy:Pt({smile:.1,leftEye:.25,rightEye:.25,leftBrow:-.3,rightBrow:-.3,lookY:.5}),disgusted:Pt({smile:-.7,mouthWidth:.9,leftEye:.6,rightEye:.75,leftBrow:-.5,rightBrow:-.2,browTilt:-.4,lookX:-.6}),smug:Pt({smile:.6,mouthWidth:.9,leftEye:.6,rightEye:.6,leftBrow:.1,rightBrow:.5,lookX:.5}),wink:Pt({smile:.9,leftEye:0,rightEye:1,leftBrow:-.2,rightBrow:.3})};function ge(t,e){return{...t,...typeof e=="string"?ct[e]:e}}const Dt={rest:et,wave:Et({rightShoulder:135,rightElbow:30,headTilt:6,...ct.happy}),cheer:Et({leftShoulder:125,leftElbow:20,rightShoulder:125,rightElbow:20,...ct.joyful}),shrug:Et({leftShoulder:30,leftElbow:85,rightShoulder:30,rightElbow:85,headTilt:-10,...ct.confused,lookX:0,lookY:0}),point:Et({rightShoulder:90,rightElbow:0,lean:4,smile:.4}),think:Et({rightShoulder:60,rightElbow:150,headTilt:10,...ct.thinking}),handsOnHips:Et({leftShoulder:45,leftElbow:-100,rightShoulder:45,rightElbow:-100,leftHip:14,rightHip:14,smile:.8}),sad:Et({leftShoulder:14,rightShoulder:14,leftElbow:-4,rightElbow:-4,headTilt:-14,lean:-3,...ct.sad}),surprised:Et({leftShoulder:70,leftElbow:60,rightShoulder:70,rightElbow:60,...ct.surprised}),crouch:Et({stretch:.72,leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50,leftHip:22,rightHip:22,headTilt:-4}),sit:Et({sit:1,turn:.5,leftShoulder:-25,rightShoulder:25,leftElbow:-55,rightElbow:55}),jump:Et({stretch:1.22,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4,...ct.joyful}),duck:Et({stretch:.62,bend:28,headTilt:-8,leftShoulder:150,rightShoulder:150,leftElbow:130,rightElbow:130,leftHip:25,rightHip:25,...ct.scared}),lie:Et({spin:-90,rise:-.42,leftShoulder:165,rightShoulder:165,leftElbow:150,rightElbow:150,...ct.sleepy}),sideSplit:Et({leftHip:90,rightHip:90,leftAnkle:-45,rightAnkle:-45,leftShoulder:120,rightShoulder:120,leftElbow:10,rightElbow:10,...ct.happy}),frontSplit:Et({turn:1,leftHip:-90,rightHip:-90,leftAnkle:-45,rightAnkle:-45,leftShoulder:-150,rightShoulder:150,leftElbow:10,rightElbow:-10,...ct.happy})},oh=Object.keys(et);function hn(t,e,n){const s={...t};for(const i of oh)s[i]=t[i]+(e[i]-t[i])*n;return s}const Go=24,rh=4,ah=28,Pm=40;function lh(t,e=et,n=1){const s=Math.sin(t*Math.PI*2)*n,i=Math.cos(t*Math.PI*2)*n,o=c=>Math.abs(c)<=Pm,r=c=>o(c)?22*s:c,a=o(e.leftShoulder)?e.leftElbow-ah*Math.max(0,-s):e.leftElbow,l=o(e.rightShoulder)?e.rightElbow+ah*Math.max(0,s):e.rightElbow;return{...e,lean:e.lean+rh*n,headTilt:e.headTilt-rh*.5*n,leftElbow:a,rightElbow:l,leftHip:-Go*s,rightHip:-Go*s,leftKnee:-30*Math.max(0,i),rightKnee:30*Math.max(0,-i),leftShoulder:r(e.leftShoulder),rightShoulder:r(e.rightShoulder)}}function ch(t,e=1){return 4*((Vo+Xs)*t)*Math.sin(Go*e*Math.PI/180)}function hh(t){const e=Math.abs(Math.sin(t/65)),n=.55+.45*Math.sin(t/310);return e*n}const dh=.12,uh=.46,xm=1-2*dh,Im=.1,Om=.21,_m=.19,Vo=.24,Xs=.22,fh=.12,Cm=.14,ph=.33,gh=.7,mh=.3,Hm=.35,Rm=[1.7,1.05],Lm=[1.3,.75],yh=[1.45,.85],Nm=[1.15,.75],bh=.06,Dm=.7,Fm=.65,wh=.075,jm=.3,Bm=.02,Wm=.012,qm=12,Km=.25,Us=90,Ym=.25,zm=.04,kh=.01,He=t=>Math.min(1,Math.max(0,t??0));function Xm(t,e=1){return Xs*t*e}const Jo=-.12,vh=.4,Kt=t=>t*Math.PI/180,Um=(t,e)=>({x:e*Math.sin(Kt(t)),y:Math.cos(Kt(t))}),Mh=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),Sh=(t,e,n,s)=>t-.3*e-n*.14*e-Math.max(0,s-1)*.12*e;function Gm(t,e,n,s,i,o){const r=Math.max(1,Math.min(o*.6,Cm*n)),a=He(e.turn),l=(fh+ph*a)*n,c=s+Jo*n,h=l+e.lookX*.08*n,d=e.lookY*.07*n,u=[{x:-.34*n*(1-gh*a),squeeze:1-gh*a,open:e.leftEye,brow:e.leftBrow,side:-1},{x:.34*n*(1-mh*a),squeeze:1-mh*a,open:e.rightEye,brow:e.rightBrow,side:1}];t.fillStyle=i,t.strokeStyle=i,t.lineWidth=r;for(const b of u){const S=Mh(b.open,e.blink);if(S<.2){const $=e.smile>.5?-.12*n:.06*n;t.beginPath(),t.moveTo(b.x+l-.12*n,c),t.quadraticCurveTo(b.x+l,c+$,b.x+l+.12*n,c),t.stroke()}else{if(S>1.2){const E=.13*n*S;t.beginPath(),t.ellipse(b.x+l,c,E*.85,E,0,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.stroke(),t.fillStyle=i}const $=S>1.2?.075*n:.1*n;t.beginPath(),t.ellipse(b.x+h,c+d,$,$*1.1*Math.min(S,1),0,0,Math.PI*2),t.fill()}const k=Sh(c,n,b.brow,S),y=b.x+l-b.side*.13*n*b.squeeze,M=b.x+l+b.side*.13*n*b.squeeze;t.beginPath(),t.moveTo(M,k),t.lineTo(y,k-e.browTilt*.1*n),t.stroke()}const f=s+vh*n,g=.25*n*Math.max(.3,e.mouthWidth)*(1-Hm*a),p=Math.min(1,Math.max(0,e.mouth));if(t.beginPath(),p<=.05){t.moveTo(l-g,f),t.quadraticCurveTo(l,f+e.smile*.25*n,l+g,f),t.stroke();return}const m=.3*n*p;e.smile>.3?(t.moveTo(l-g,f-.05*n),t.lineTo(l+g,f-.05*n),t.quadraticCurveTo(l,f+m*2,l-g,f-.05*n)):e.smile<-.3?(t.moveTo(l-g,f+m*.6),t.lineTo(l+g,f+m*.6),t.quadraticCurveTo(l,f-m*1.4,l-g,f+m*.6)):t.ellipse(l,f,g*.8,m,0,0,Math.PI*2),t.fill()}function Th(t,e){const n=e.height??300,s=Math.min(3,Math.max(.3,t.stretch??1)),i=Math.sqrt(s),o=(e.headSize??2*dh)/2,r=e.headSize===void 0?xm:1-2*o,a=o*n,l=He(t.sit),c=t.leftHip+(-Us-t.leftHip)*l,h=t.leftKnee+(-Us-t.leftKnee)*l,d=t.rightHip+(Us-t.rightHip)*l,u=t.rightKnee+(Us-t.rightKnee)*l,f=e.classic===!0,g=He(t.turn),p=(W,B,_,L,N)=>{const x=Math.max(-Math.PI/2,Math.min(Math.PI/2,Math.abs(Kt(B-_)/2)+Kt(L))),R=Math.max(-1,Math.min(1,Dm+N)),q=g+(1-g)*W*R;return f?{x:0,y:0}:{x:Math.cos(x)*bh*q,y:Math.sin(x)*bh}},m={left:t.leftAnkle??0,right:t.rightAnkle??0},b={left:t.leftFootOut??0,right:t.rightFootOut??0};let S=0;if(l>0||!f){const W=(N,x,R,q,U)=>Vo*Math.cos(Kt(x))+Xs*Math.cos(Kt(x-R))+Math.max(0,p(N,x,R,q,U).y),B=Math.max(W(-1,c,h,m.left,b.left),W(1,d,u,m.right,b.right)),_=1-He((t.rise??0)/zm),L=(f?Math.min(1,l/Ym):1)*_;S=(uh-B)*L*n*s}const k=-uh*n*s+S,y=-r*n*s+S,M=f?0:(Bm*He(t.turn)+Wm*l)*n*s,$=Kt(t.bend??0),E={end:Ah(k,y,$,1),bend:$};let A;if($!==0){A=[];for(let W=0;W<=Eh;W++){const B=W/Eh,_=Ah(k,y,$,B);A.push({x:_.x-M*Math.sin(Math.PI*B),y:_.y})}}else A=M===0?[{x:0,y:k},{x:0,y}]:Ce({x:0,y:k},{x:-M,y:(k+y)/2},{x:0,y},1,8);const T=y+Im*n*s,I=(e.shoulderWidth??0)*n*Math.cos(g*Math.PI/2),v=(W,B,_,L,N)=>{const x=Um(_,L);return{x:W+x.x*N*n,y:B+x.y*N*n}},P=(W,B,_)=>{const L=v(0,k,B,W,Vo*s);return{root:{x:0,y:k},joint:L,end:v(L.x,L.y,B-_,W,Xs*s)}},H=(W,B,_)=>{const L={x:W*I,y:T},N=v(L.x,L.y,B,W,Om*i);return{root:L,joint:N,end:v(N.x,N.y,B+_,W,_m*i)}},O={left:P(-1,c,h),right:P(1,d,u)},C=(W,B,_,L,N,x)=>{const R=p(W,_,L,N,x);return{x:B.end.x+R.x*n*s,y:B.end.y+R.y*n*s}},j=(W,B,_,L,N)=>v(B.end.x,B.end.y,_+L+N,W,wh*i),D={left:H(-1,t.leftShoulder,t.leftElbow),right:H(1,t.rightShoulder,t.rightElbow)};return{height:n,facing:(e.facing??1)<0?-1:1,stretch:s,lineWidth:e.lineWidth??n*.025,rubber:Math.min(1,Math.max(f?0:jm,e.rubber??0)),r:a,headRx:a/Math.sqrt(s),headRy:a*Math.sqrt(s),hipY:k,neckY:y,drop:S,lean:f?t.lean:t.lean+qm*Math.sin(Math.PI*l),classic:f,legs:O,toes:{left:C(-1,O.left,c,h,m.left,b.left),right:C(1,O.right,d,u,m.right,b.right)},spine:A,chest:E,arms:D,handTips:{left:j(-1,D.left,t.leftShoulder,t.leftElbow,t.leftWrist??0),right:j(1,D.right,t.rightShoulder,t.rightElbow,t.rightWrist??0)}}}const Eh=10;function Ah(t,e,n,s){const i=t-e,o=n*s;if(Math.abs(n)<1e-9)return{x:0,y:t-i*s};const r=i/n;return{x:r*(1-Math.cos(o)),y:t-r*Math.sin(o)}}function Vm(t,e){if(t.chest.bend===0)return e;const n=Un(e,{x:0,y:t.neckY},t.chest.bend);return{x:n.x+t.chest.end.x,y:n.y+t.chest.end.y-t.neckY}}const Xn=(t,e)=>e===0?[t.root,t.joint,t.end]:Ce(t.root,t.joint,t.end,e);function Un(t,e,n){const s=Math.cos(n),i=Math.sin(n),o=t.x-e.x,r=t.y-e.y;return{x:e.x+o*s-r*i,y:e.y+o*i+r*s}}function $h(t,e,n=!0){const s=Zm(t,e),i=e.spin??0,o=e.rise??0;return n&&(i!==0||o!==0)?Jm(s,t,i,o):s}function Ph(t,e,n){return{pivot:{x:0,y:t.hipY},angle:t.facing*Kt(e),lift:n*t.height}}function Jm(t,e,n,s){const{pivot:i,angle:o,lift:r}=Ph(e,n,s),a=u=>{const f=Un(u,i,o);return{x:f.x,y:f.y-r}},l=u=>({left:a(u.left),right:a(u.right)}),c={left:Math.max(a(t.feet.left).y,a(t.toes.left).y),right:Math.max(a(t.feet.right).y,a(t.toes.right).y)},h=Math.max(c.left,c.right),d=kh*e.height;return{...t,hip:a(t.hip),neck:a(t.neck),shoulders:l(t.shoulders),elbows:l(t.elbows),hands:l(t.hands),fingertips:l(t.fingertips),knees:l(t.knees),feet:l(t.feet),toes:l(t.toes),feetY:h,grounded:{left:c.left>=h-d,right:c.right>=h-d},handAngle:{left:t.handAngle.left+o,right:t.handAngle.right+o},limbs:{leftArm:t.limbs.leftArm.map(a),rightArm:t.limbs.rightArm.map(a),leftLeg:t.limbs.leftLeg.map(a),rightLeg:t.limbs.rightLeg.map(a),spine:t.limbs.spine.map(a)},head:{...t.head,center:a(t.head.center),angle:t.head.angle+o}}}function Zm(t,e){const n=Kt(t.lean),s=Kt(e.headTilt),i={x:0,y:t.hipY},o=y=>({x:t.facing*y.x,y:y.y}),r=y=>o(Un(y,i,n)),a=y=>r(Vm(t,y)),l=y=>a(Un({x:y.x,y:y.y+t.neckY},{x:0,y:t.neckY},s)),c=Xn(t.arms.left,t.rubber).map(a),h=Xn(t.arms.right,t.rubber).map(a),d=(y,M)=>Math.atan2(M.y-y.y,M.x-y.x),u={left:a(t.handTips.left),right:a(t.handTips.right)},f=(y,M)=>{const[$,E]=y.slice(-2),A=t.arms[M],T=d(a(A.end),u[M])-d(a(A.joint),a(A.end));return d($,E)+T};let g=1/0;for(const[y,M]of[[e.leftBrow,e.leftEye],[e.rightBrow,e.rightEye]]){const $=Sh(Jo,1,y,Mh(M,e.blink));g=Math.min(g,$,$-e.browTilt*.1)}const p={left:o(t.legs.left.end),right:o(t.legs.right.end)},m={left:o(t.toes.left),right:o(t.toes.right)},b={left:Math.max(p.left.y,m.left.y),right:Math.max(p.right.y,m.right.y)},S=Math.max(b.left,b.right),k=kh*t.height;return{facing:t.facing,height:t.height,stretch:t.stretch,lineWidth:t.lineWidth,hip:i,neck:a({x:0,y:t.neckY}),shoulders:{left:a(t.arms.left.root),right:a(t.arms.right.root)},elbows:{left:a(t.arms.left.joint),right:a(t.arms.right.joint)},hands:{left:a(t.arms.left.end),right:a(t.arms.right.end)},knees:{left:o(t.legs.left.joint),right:o(t.legs.right.joint)},feet:p,toes:m,feetY:S,grounded:{left:b.left>=S-k,right:b.right>=S-k},fingertips:u,handAngle:{left:f(c,"left"),right:f(h,"right")},limbs:{leftArm:c,rightArm:h,leftLeg:Xn(t.legs.left,t.rubber).map(o),rightLeg:Xn(t.legs.right,t.rubber).map(o),spine:t.spine.map(r)},head:{center:l({x:0,y:-t.headRy}),rx:t.headRx,ry:t.headRy,angle:t.facing*(n+t.chest.bend+s),eyeY:Jo,browTopY:g,mouthY:vh,faceX:t.facing*(fh+ph*He(e.turn))}}}function me(t,e={}){return $h(Th(t,e),t)}function Qm(t,e,n){return Un({x:t.center.x+e*t.rx,y:t.center.y+n*t.ry},t.center,t.angle)}function xh(t,e,n){const s=o=>({x:o.x+e,y:o.y+n}),i=o=>({left:s(o.left),right:s(o.right)});return{...t,hip:s(t.hip),neck:s(t.neck),shoulders:i(t.shoulders),elbows:i(t.elbows),hands:i(t.hands),fingertips:i(t.fingertips),knees:i(t.knees),feet:i(t.feet),toes:i(t.toes),feetY:t.feetY+n,grounded:{...t.grounded},handAngle:{...t.handAngle},limbs:{leftArm:t.limbs.leftArm.map(s),rightArm:t.limbs.rightArm.map(s),leftLeg:t.limbs.leftLeg.map(s),rightLeg:t.limbs.rightLeg.map(s),spine:t.limbs.spine.map(s)},head:{...t.head,center:s(t.head.center)}}}function Ih(t,e,n={},s=0){const i=Th(e,n),o=n.color??"#1e293b",r=n.layers??{},a=n.layers?$h(i,e,!1):void 0,l=n.sketch?Bs(t,n.sketch,s):void 0,c=n.sketch&&n.layers?Bs(t,n.sketch,s):void 0,h=E=>{t.save(),E(),t.restore()},d=E=>{E&&a&&h(()=>E(t,a,s,c))},u=()=>t.scale(i.facing,1),f=()=>{u(),t.translate(0,i.hipY),t.rotate(Kt(i.lean)),t.translate(0,-i.hipY)},g=()=>{f(),i.chest.bend!==0&&(t.translate(i.chest.end.x,i.chest.end.y),t.rotate(i.chest.bend),t.translate(0,-i.neckY))},p=(E,A,T)=>{if(l)return A?l.curve(E):l.line(E);if(i.classic){t.beginPath(),t.moveTo(E[0].x,E[0].y);for(const I of E.slice(1))t.lineTo(I.x,I.y);t.stroke();return}Ws(t,E,T[0]*i.lineWidth,T[1]*i.lineWidth)},m=(E,A)=>p(Xn(E,i.rubber),i.rubber>0,A),b=E=>{i.classic||p([i.legs[E].end,i.toes[E]],!1,Nm)},S=E=>{if(n.hands&&!i.classic)return y(E);if(i.classic||l)return;const A=i.arms[E].end;t.beginPath(),t.arc(A.x,A.y,Fm*i.lineWidth,0,Math.PI*2),t.fill()};t.save(),t.strokeStyle=o,t.fillStyle=o,t.lineWidth=i.lineWidth,t.lineCap="round",t.lineJoin="round";const k=Ph(i,e.spin??0,e.rise??0);(k.angle!==0||k.lift!==0)&&(t.translate(0,-k.lift),t.translate(k.pivot.x,k.pivot.y),t.rotate(k.angle),t.translate(-k.pivot.x,-k.pivot.y));function y(E){const A=n.hands??{},T=i.arms[E].end,I=i.handTips[E],v=n.headFill??"#ffffff";zs(t,T,A[E]??vt,{side:E,angle:Math.atan2(I.x-T.x,T.y-I.y)*180/Math.PI,size:(A.size??wh)*i.height*Math.sqrt(i.stretch),skin:A.skin??(v==="none"?void 0:v),ink:o,lineWidth:i.lineWidth*.45,fingers:A.fingers,plump:A.plump,look:n.sketch?"pencil":"clean",seed:n.sketch?.seed},s)}const M=E=>{h(()=>{g(),m(i.arms[E],Lm),S(E)});const A=r.sleeve;A&&a&&h(()=>A(t,a,E,s,c))},$=He(e.turn)>Km;d(r.behind),h(()=>{u(),m(i.legs.left,yh),b("left"),m(i.legs.right,yh),b("right")}),$&&M("left"),h(()=>{f(),p(i.spine,i.spine.length>2,Rm)}),h(()=>{g();const{left:E,right:A}={left:i.arms.left.root,right:i.arms.right.root};if(E.x!==A.x)if(i.classic)p([E,A],!1,[1,1]);else{const T={x:(E.x+A.x)/2,y:E.y-.3*Math.abs(A.x-E.x)};p(Ce(E,T,A,1,8),!0,[1.1,1.1])}}),d(r.body),$||M("left"),M("right"),d(r.behindHead),h(()=>{g(),t.translate(0,i.neckY),t.rotate(Kt(e.headTilt));const E=-i.headRy;t.beginPath(),t.ellipse(0,E,i.headRx,i.headRy,0,0,Math.PI*2);const A=n.headFill??"#ffffff";if(A!=="none"&&(t.fillStyle=A,t.fill()),l){l.ellipse(0,E,i.headRx,i.headRy);const T=l.nudge();t.translate(T.x,T.y)}else t.stroke();t.translate(0,E),t.scale(i.headRx/i.r,i.headRy/i.r),Gm(t,e,i.r,0,o,i.lineWidth)}),d(r.overHead),d(r.front),t.restore(),n.label&&(t.save(),t.fillStyle=o,t.font=n.labelFont??`700 ${Math.round(i.height*.11)}px sans-serif`,t.textAlign="center",t.textBaseline="bottom",t.fillText(n.label,0,-i.height*i.stretch-.04*i.height+i.drop),t.restore())}function Zo(t,e,n,s){const i={...t},o=t.gait&&s?.[t.gait]||t.gait;let r=t.walking>0?hn(i,sh(o,t.walk,i),t.walking):i,a=t1(t);const l=t.dancing??0;if(n&&l>0){const c=n(t.beat??0);if(r=hn(r,c.pose,l),c.hands){const h=(d,u)=>u?cn(d??vt,u,l):d;a={left:h(a?.left,c.hands.left),right:h(a?.right,c.hands.right)}}}return t.talk>0&&(r={...r,mouth:Math.max(r.mouth,t.talk*hh(e))}),{pose:r,hands:a}}function Oh(t,e,n,s){return Zo(t,e,n,s).pose}const _h=(t,e)=>(t.facing??e.facing??1)<0?-1:1,Gn=(t,e)=>`hand.${t}.${e}`;function t1(t){const e=i=>{if(typeof t[Gn(i,"spread")]=="number")return Object.fromEntries(Object.keys(vt).map(o=>[o,t[Gn(i,o)]]))},n=e("left"),s=e("right");return n||s?{left:n,right:s}:void 0}function e1(t,e){return!e||!t.hands?t:{...t,hands:{...t.hands,left:e.left??t.hands.left,right:e.right??t.hands.right}}}function Qo(t){const e=t.style??{},n=e.height??300,s=n*.8,i={...Et(t.pose??{}),walk:0,walking:0,gait:"walk",facing:(e.facing??1)<0?-1:1,talk:0,rubber:e.rubber??0,beat:0,dancing:0},o={};if(e.hands)for(const r of["left","right"]){const a=e.hands[r]??vt;for(const l of Object.keys(vt))o[Gn(r,l)]=a[l]??vt[l]}return{type:"custom",x:t.x-s/2,y:t.y-n,width:s,height:n,props:{...i,...o},about:n1(Object.keys(o),t.cast),figureStyle:e,figureDance:t.dance,figureGaits:t.cast?.gaits,draw(r,a,l){const c=a.props,h=Zo(c,l,t.dance,t.cast?.gaits);r.translate(s/2,n),Ih(r,h.pose,e1({...e,rubber:c.rubber,facing:_h(c,e)},h.hands),l)}}}function n1(t,e){const n={...zc,...Xc};for(const s of t){const[,i,...o]=s.split("."),r=Uc[o.join(".")];r&&(n[s]={...r,description:`${i==="left"?"Left":"Right"} hand: ${r.description.toLowerCase()}`})}return{kind:"stick figure",summary:"A poseable stick figure: pose it with joint tracks, or give it beats (`scriptTracks`) that compile into acted tracks.",props:n,get actions(){return nm(e)}}}function tr(t,e,n){const s=t.figureStyle;if(!s)throw new Error("stickFigureAt: the target was not made by stickFigureTarget");const i={...t.props};let o=0,r=0;for(const[c,h]of e.state?.values.get(n)??[])c==="gait"&&typeof h=="string"&&(i.gait=h),typeof h=="number"&&(c==="x"||c==="motionPathX"?o=h:c==="y"||c==="motionPathY"?r=h:c in i&&(i[c]=h));const a=Oh(i,e.time,t.figureDance,t.figureGaits),l=me(a,{...s,rubber:i.rubber,facing:_h(i,s)});return{pose:a,joints:xh(l,t.x+o+t.width/2,t.y+r+t.height)}}function er(t){const e=[];return t.forEach((n,s)=>{const i=s===0?et:e[s-1],o=typeof n.pose=="string"?Dt[n.pose]:{...i,...n.pose};e.push(n.expression?ge(o,n.expression):o)}),e}function s1(t,e){const n=er(e);return oh.filter(s=>n.some(i=>i[s]!==et[s])).map(s=>({id:`${t}-${s}`,target:t,property:s,keyframes:e.map((i,o)=>({time:i.time,value:n[o][s],...i.easing?{easing:i.easing}:{}}))}))}const nr=.5,Gs={pataka:Mt({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:0,turn:2}),tripataka:Mt({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":1,"pinky.curl":0,spread:0,turn:2}),alapadma:Mt({"thumb.curl":.1,"thumb.across":0,"index.curl":.05,"middle.curl":.15,"ring.curl":.25,"pinky.curl":.35,spread:1,turn:2}),mushti:Tt.fist,shikhara:Tt.thumbsUp,hamsasya:Mt({"thumb.curl":.15,"thumb.across":.6,"index.curl":.6,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:.7,turn:2}),katakamukha:Mt({"thumb.curl":.2,"thumb.across":.6,"index.curl":.65,"middle.curl":.7,"ring.curl":0,"pinky.curl":0,spread:.4,turn:2})};function Vs(t){return typeof t!="string"?t:t in Gs?Gs[t]:Tt[t]}function Ch(t,e,n){const s=[];for(const i of t.keys){const o=s[s.length-1],r=!o||i.reset?{pose:e,...n}:o;s.push({beat:i.beat,pose:{...r.pose,...i.pose},left:i.hands?.left?Vs(i.hands.left):r.left,right:i.hands?.right?Vs(i.hands.right):r.right,easing:i.easing??t.easing})}return s}const sr=(t,e)=>(t%e+e)%e;function i1(t,e,n,s){const i=Ch(t,n,s);if(i.length===0)return{pose:n,hands:s};const o=sr(e,t.beats);let r=i.length-1;for(let f=0;f<i.length;f++)i[f].beat<=o&&(r=f);const a=i[r],l=i[(r+1)%i.length],c=a.beat<=o?a.beat:a.beat-t.beats,h=l.beat>c?l.beat:l.beat+t.beats,d=h>c?(o-c)/(h-c):0,u=xt(l.easing??"ease-in-out")(Math.min(1,Math.max(0,d)));return{pose:hn(a.pose,l.pose,u),hands:{left:cn(a.left,l.left,u),right:cn(a.right,l.right,u)}}}const o1=[["leftShoulder","rightShoulder"],["leftElbow","rightElbow"],["leftWrist","rightWrist"],["leftHip","rightHip"],["leftKnee","rightKnee"],["leftAnkle","rightAnkle"],["leftFootOut","rightFootOut"],["leftEye","rightEye"],["leftBrow","rightBrow"]],r1=["lean","headTilt","lookX","spin"],a1=new Set(["leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee"]);function Hh(t){const e={...t},n=(t.turn??0)>=.5;for(const[s,i]of o1){const o=n&&a1.has(s)?-1:1;e[s]=o*t[i],e[i]=o*t[s]}if(!n)for(const s of r1)e[s]=-t[s];return e}const l1=t=>Math.min(1,Math.max(-1,(.5-t)*4));function Rh(t,e,n){const s=sr(n,1),i=(1+Math.cos(2*Math.PI*s))/2,o=e.bounce*(e.accent==="up"?1-i:i),r=Math.min(1,Math.max(0,t.turn??0)),a=l1(r);return{...t,leftHip:t.leftHip+a*o/2,rightHip:t.rightHip+o/2,leftKnee:t.leftKnee+a*o,rightKnee:t.rightKnee+o,lean:t.lean+(e.sway??0)*(1-r)*Math.sin(Math.PI*n)}}function Js(t){const e={...et,...t.stance};return t.expression?ge(e,t.expression):e}function Lh(t){return{left:t.hands?.left?Vs(t.hands.left):vt,right:t.hands?.right?Vs(t.hands.right):vt}}function ir(t,e,n){const s=t.moves[e.move];if(!s)throw new Error(`dance: "${t.label}" has no move "${e.move}"`);const i=i1(s,n,Js(t),Lh(t));return e.mirror?{pose:Hh(i.pose),hands:{left:i.hands?.right,right:i.hands?.left}}:i}function Zs(t,e,n={}){const s=typeof t=="string"?ye[t]:t;let i;if(n.move)i=ir(s,{move:n.move,mirror:n.mirror},e);else{const o=s.routine,r=o.reduce((d,u)=>d+u.beats,0),a=sr(e,r);let l=0,c=0;for(;c<o.length-1&&a>=l+o[c].beats;)l+=o[c++].beats;const h=a-l;if(i=ir(s,o[c],h),h<nr&&o.length>1&&e>=nr){const d=o[(c-1+o.length)%o.length],u=ir(s,d,d.beats+h),f=xt("ease-in-out")(h/nr);i={pose:hn(u.pose,i.pose,f),hands:{left:cn(u.hands.left,i.hands.left,f),right:cn(u.hands.right,i.hands.right,f)}}}}return{...i,pose:Rh(i.pose,s.groove,e)}}function c1(t,e,n={}){return Zs(t,e,n).pose}function Qs(t){return(typeof t=="string"?ye[t]:t).routine.reduce((n,s)=>n+s.beats,0)}const h1={leftToe:"rightToe",rightToe:"leftToe",leftHeel:"rightHeel",rightHeel:"leftHeel"};function Nh(t,e,n,s,i,o,r){for(let a=0;a*t.beats<n;a++)for(const l of t.keys){const c=a*t.beats+l.beat,h=e+c;if(!(c>=n||h<o||h>=r))for(const d of l.taps??[])i.push({beat:h,tap:s?h1[d]:d})}}function d1(t,e,n,s={}){const i=typeof t=="string"?ye[t]:t,o=[];if(n<=e)return o;if(s.move){const r=i.moves[s.move],a=Math.floor(e/r.beats)*r.beats;Nh(r,a,Math.ceil((n-a)/r.beats)*r.beats,s.mirror,o,e,n)}else{const r=Qs(i);for(let a=Math.floor(e/r)*r;a<n;a+=r){let l=a;for(const c of i.routine)Nh(i.moves[c.move],l,c.beats,c.mirror,o,e,n),l+=c.beats}}return o.sort((r,a)=>r.beat-a.beat)}function Dh(t,e){const n=t.moves[e.move];if(!n?.travel)return 0;const s=n.travel/n.beats;return e.mirror?(Ch(n,Js(t),Lh(t))[0]?.pose.turn??Js(t).turn??0)>=.5?s:-s:s}function Fh(t,e){return e.move?[{move:e.move,beats:t.moves[e.move].beats,mirror:e.mirror}]:t.routine}function ti(t,e,n={}){const s=typeof t=="string"?ye[t]:t,i=Fh(s,n),o=i.reduce((h,d)=>h+d.beats,0),r=i.reduce((h,d)=>h+Dh(s,d)*d.beats,0),a=Math.floor(e/o);let l=a*r,c=e-a*o;for(const h of i){const d=Math.min(h.beats,c);if(l+=Dh(s,h)*d,c-=d,c<=0)break}return l}function u1(t,e,n){const s=Fh(t,n),i=[0];let o=0;for(let r=0;o<e;r=(r+1)%s.length)o+=s[r].beats,i.push(Math.min(o,e));return i}const f1=8;function jh(t,e,n){const s=typeof e=="string"?ye[e]:e,i=n.bpm??s.bpm,o=n.beats??(n.move?s.moves[n.move].beats:Qs(s)),r=u1(s,o,n);if(r.every(b=>ti(s,b,n)===0))return;const a=Math.min(n.fade??1,o/2),l=xt("ease-in-out"),c=b=>a<=0?1:Math.min(l(Math.min(1,b/a)),l(Math.min(1,(o-b)/a))),h=Math.ceil(a*f1),d=a<=0?[]:Array.from({length:h+1},(b,S)=>[S/h*a,o-S/h*a]).flat(),u=[...new Set([...r,...d])].sort((b,S)=>b-S);let f=0;const g=u.map((b,S)=>{if(S>0){const k=u[S-1],y=Math.max(1,Math.ceil((b-k)*16));for(let M=0;M<y;M++){const $=k+(b-k)*M/y,E=k+(b-k)*(M+1)/y;f+=(ti(s,E,n)-ti(s,$,n))*c(($+E)/2)}}return{beat:b,travel:f}}),p=n.start??0,m=n.x??0;return{id:`${t}-x`,target:t,property:"x",keyframes:g.map(b=>({time:p+b.beat*6e4/i,value:m+n.height*b.travel,easing:"linear"}))}}function p1(t,e,n=0){return(t-n)*e/6e4}function g1(t,e={}){return n=>Zs(t,n,e)}function m1(t,e){const n=e.start??0,s=6e4/e.bpm,i=n+e.beats*s,o=Math.min((e.fade??1)*s,(i-n)/2);return[{id:`${t}-beat`,target:t,property:"beat",keyframes:[{time:n,value:0},{time:i,value:e.beats,easing:"linear"}]},{id:`${t}-dancing`,target:t,property:"dancing",keyframes:[{time:n,value:0},{time:n+o,value:1,easing:"ease-in-out"},{time:i-o,value:1},{time:i,value:0,easing:"ease-in-out"}]}]}function y1(t,e,n={}){const s=typeof e=="string"?ye[e]:e,i=n.bpm??s.bpm,o=n.beats??(n.move?s.moves[n.move].beats:Qs(s)),r=n.samplesPerBeat??4,a=n.start??0,l=Math.round(o*r),c=Array.from({length:l+1},(p,m)=>{const b=m/r;return{time:a+b*6e4/i,frame:Zs(s,b,n)}}),h=(p,m)=>({id:`${t}-${p}`,target:t,property:p,keyframes:c.map(b=>({time:b.time,value:m(b.frame)}))}),u=Object.keys(et).filter(p=>c.some(m=>m.frame.pose[p]!==c[0].frame.pose[p])||c[0].frame.pose[p]!==et[p]).map(p=>h(p,m=>m.pose[p])),f=n.height===void 0?void 0:jh(t,s,{...n,bpm:i,beats:o,start:a,height:n.height,fade:0});if(f&&u.push(f),n.hands===!1)return u;const g=[];for(const p of["left","right"])for(const m of Object.keys(vt)){const b=S=>S.hands?.[p]?.[m]??vt[m];c.some(S=>b(S.frame)!==vt[m])&&g.push(h(Gn(p,m),b))}return[...u,...g]}const Vn={type:"back",mode:"out",overshoot:1.1},_t="ease-out-cubic",b1={label:"Disco",bpm:120,stance:{leftHip:10,rightHip:10,leftKnee:6,rightKnee:6},expression:{smile:.9,mouth:.15,leftBrow:.3,rightBrow:.3},groove:{bounce:10,accent:"down",sway:2},moves:{point:{label:"The point",beats:2,easing:_t,keys:[{beat:0,pose:{rightShoulder:150,rightElbow:0,rightWrist:0,leftShoulder:40,leftElbow:-105,leftWrist:-20,lean:-5,headTilt:8,rightHip:18,leftHip:6,lookX:.6,lookY:-.7},hands:{right:"point",left:"fist"}},{beat:1,pose:{rightShoulder:-30,rightWrist:10,lean:5,headTilt:-6,rightHip:6,leftHip:18,lookX:-.4,lookY:.6}}]},roll:{label:"Roll the arms",beats:2,easing:"linear",keys:[{beat:0,pose:{leftShoulder:42,leftElbow:-128,rightShoulder:26,rightElbow:-100,rightHip:18,leftHip:6,lean:-3},hands:{left:"fist",right:"fist"}},{beat:.5,pose:{leftShoulder:26,leftElbow:-100,rightShoulder:42,rightElbow:-128}},{beat:1,pose:{leftShoulder:42,leftElbow:-128,rightShoulder:26,rightElbow:-100,rightHip:6,leftHip:18,lean:3}},{beat:1.5,pose:{leftShoulder:26,leftElbow:-100,rightShoulder:42,rightElbow:-128}}]},bump:{label:"Bump and clap",beats:4,keys:[{beat:0,pose:{lean:-10,rightHip:22,leftHip:4,leftShoulder:140,rightShoulder:140,leftElbow:0,rightElbow:0,leftWrist:20,rightWrist:20},hands:{left:"spread",right:"spread"},easing:_t},{beat:1,pose:{lean:0,rightHip:10,leftHip:10,leftShoulder:168,rightShoulder:168,leftElbow:22,rightElbow:22,leftWrist:0,rightWrist:0},hands:{left:"flat",right:"flat"}},{beat:2,pose:{lean:10,rightHip:4,leftHip:22,leftShoulder:140,rightShoulder:140,leftElbow:0,rightElbow:0,leftWrist:20,rightWrist:20},hands:{left:"spread",right:"spread"},easing:_t},{beat:3,pose:{lean:0,rightHip:10,leftHip:10,leftShoulder:168,rightShoulder:168,leftElbow:22,rightElbow:22,leftWrist:0,rightWrist:0},hands:{left:"flat",right:"flat"}}]}},routine:[{move:"point",beats:8},{move:"roll",beats:4},{move:"point",beats:8,mirror:!0},{move:"bump",beats:8}]},w1={label:"Hip hop",bpm:95,stance:{leftHip:14,rightHip:14,leftKnee:20,rightKnee:20,leftShoulder:22,rightShoulder:22,leftElbow:-30,rightElbow:-30,leftFootOut:.15,rightFootOut:.15},expression:"smug",hands:{left:"relaxed",right:"relaxed"},groove:{bounce:18,accent:"down"},moves:{bounce:{label:"Bounce",beats:2,keys:[{beat:0,pose:{leftShoulder:30,rightShoulder:30,leftElbow:-50,rightElbow:-50,lean:-3,headTilt:-5,leftWrist:-20,rightWrist:-20}},{beat:1,pose:{leftShoulder:14,rightShoulder:14,leftElbow:-18,rightElbow:-18,lean:3,headTilt:5,leftWrist:0,rightWrist:0}}]},runningMan:{label:"Running man",beats:2,keys:[{beat:0,reset:!0,pose:{turn:.85,leftHip:-84,leftKnee:-112,leftAnkle:25,rightHip:-26,rightKnee:8,leftShoulder:35,leftElbow:-50,rightShoulder:45,rightElbow:75,lean:6},hands:{left:"fist",right:"fist"}},{beat:.5,pose:{leftHip:-4,leftKnee:-18,leftAnkle:0,rightHip:4,rightKnee:18,leftShoulder:5,leftElbow:-40,rightShoulder:5,rightElbow:40}},{beat:1,pose:{rightHip:84,rightKnee:112,rightAnkle:25,leftHip:26,leftKnee:-8,rightShoulder:-35,rightElbow:50,leftShoulder:-45,leftElbow:-75}},{beat:1.5,pose:{rightHip:4,rightKnee:18,rightAnkle:0,leftHip:-4,leftKnee:-18,rightShoulder:-5,rightElbow:40,leftShoulder:-5,leftElbow:-40}}]},armWave:{label:"Arm wave",beats:4,keys:[{beat:0,reset:!0,pose:{leftShoulder:90,rightShoulder:90,leftElbow:0,rightElbow:0},hands:{left:"flat",right:"flat"}},{beat:.5,pose:{leftWrist:45,leftElbow:-15}},{beat:1,pose:{leftWrist:-35,leftElbow:40,leftShoulder:84}},{beat:1.5,pose:{leftWrist:0,leftElbow:-10,leftShoulder:102,headTilt:-8}},{beat:2,pose:{leftElbow:0,leftShoulder:90,rightShoulder:102,headTilt:8}},{beat:2.5,pose:{rightShoulder:84,rightElbow:40,headTilt:0}},{beat:3,pose:{rightElbow:-15,rightWrist:45}},{beat:3.5,pose:{rightElbow:0,rightWrist:-35}}]}},routine:[{move:"bounce",beats:8},{move:"runningMan",beats:8},{move:"armWave",beats:8},{move:"bounce",beats:4}]},k1={label:"Breaking (toprock)",bpm:110,stance:{leftHip:14,rightHip:14,leftKnee:14,rightKnee:14,leftShoulder:35,rightShoulder:35,leftElbow:-90,rightElbow:-90},expression:{smile:.3,leftBrow:-.3,rightBrow:-.3,browTilt:-.3},hands:{left:"fist",right:"fist"},groove:{bounce:8,accent:"down"},moves:{toprock:{label:"Toprock (Indian step)",beats:4,keys:[{beat:0,pose:{rightHip:-24,rightKnee:10,leftHip:10,leftShoulder:80,leftElbow:40,rightShoulder:55,rightElbow:-50,lean:6,headTilt:-6},easing:_t},{beat:1,reset:!0,pose:{leftHip:18,rightHip:18}},{beat:2,pose:{leftHip:-24,leftKnee:10,rightHip:10,rightShoulder:80,rightElbow:40,leftShoulder:55,leftElbow:-50,lean:-6,headTilt:6},easing:_t},{beat:3,reset:!0,pose:{leftHip:18,rightHip:18}}]},kick:{label:"Kick out",beats:2,keys:[{beat:0,pose:{rightHip:72,rightKnee:4,rightAnkle:-20,leftHip:4,lean:-12,leftShoulder:100,leftElbow:20},easing:_t},{beat:1,reset:!0}]},freeze:{label:"B-boy stance",beats:4,keys:[{beat:0,reset:!0,pose:{leftShoulder:26,leftElbow:-122,rightShoulder:22,rightElbow:-118,leftHip:18,rightHip:18,leftKnee:6,rightKnee:6,lean:-4,headTilt:10,smile:.6,leftEye:.6,rightEye:.6},easing:Vn},{beat:2,pose:{headTilt:14,lean:-6}}]}},routine:[{move:"toprock",beats:8},{move:"kick",beats:4},{move:"toprock",beats:8},{move:"kick",beats:4,mirror:!0},{move:"freeze",beats:4}]},v1={label:"Jazz",bpm:130,stance:{leftHip:10,rightHip:10},expression:{mouth:.55,smile:1,mouthWidth:1.2,leftBrow:.6,rightBrow:.6},hands:{left:"spread",right:"spread"},groove:{bounce:6,accent:"up"},moves:{jazzHands:{label:"Jazz hands",beats:2,easing:"linear",keys:[0,.25,.5,.75,1,1.25,1.5,1.75].map((t,e)=>({beat:t,pose:{leftShoulder:128,rightShoulder:128,leftElbow:8,rightElbow:8,leftWrist:e%2?4:26,rightWrist:e%2?26:4,leftHip:16,rightHip:16,leftKnee:t<1?26:8,rightKnee:t<1?26:8},hands:e===0?{left:{...Tt.spread,turn:2},right:{...Tt.spread,turn:2}}:void 0}))},kickBallChange:{label:"Kick ball change",beats:2,keys:[{beat:0,reset:!0,pose:{rightHip:88,rightKnee:0,rightAnkle:55,leftHip:4,lean:-12,leftShoulder:112,rightShoulder:112,leftWrist:15,rightWrist:15},hands:{left:"flat",right:"flat"},easing:_t},{beat:1,reset:!0,pose:{rightHip:10,rightKnee:24,rightAnkle:45,leftShoulder:60,rightShoulder:60,leftElbow:-20,rightElbow:-20}},{beat:1.5,pose:{rightAnkle:0,rightKnee:6,leftAnkle:45,leftKnee:20}}]},splitDrop:{label:"Drop into the splits",beats:8,keys:[{beat:0,reset:!0},{beat:2,reset:!0,pose:{leftHip:90,rightHip:90,leftKnee:0,rightKnee:0,leftAnkle:-45,rightAnkle:-45,leftShoulder:125,rightShoulder:125,leftElbow:10,rightElbow:10},easing:"ease-in-out-cubic"},{beat:4,pose:{leftShoulder:95,rightShoulder:95,leftElbow:0,rightElbow:0,leftWrist:50,rightWrist:50,headTilt:8}},{beat:6,reset:!0,pose:{leftHip:30,rightHip:30,leftKnee:60,rightKnee:60,leftShoulder:40,rightShoulder:40},easing:"ease-in-out-cubic"},{beat:7.5,reset:!0}]},jazzSquare:{label:"Jazz square",beats:4,keys:[{beat:0,reset:!0,pose:{rightHip:-18,leftHip:8,leftShoulder:38,rightShoulder:46,leftElbow:100,rightElbow:96,lean:4},hands:{left:"pinch",right:"pinch"}},{beat:1,pose:{leftHip:18,rightHip:6,leftShoulder:46,rightShoulder:38,lean:-4}},{beat:2,pose:{rightHip:22,leftHip:6,leftShoulder:38,rightShoulder:46,lean:4}},{beat:3,pose:{leftHip:10,rightHip:10,leftShoulder:46,rightShoulder:38,lean:0}}]}},routine:[{move:"jazzHands",beats:4},{move:"kickBallChange",beats:4},{move:"kickBallChange",beats:4,mirror:!0},{move:"jazzSquare",beats:8},{move:"jazzHands",beats:4},{move:"splitDrop",beats:8}]},M1={label:"K-pop",bpm:125,stance:{leftHip:9,rightHip:9,leftKnee:4,rightKnee:4},expression:"happy",groove:{bounce:5,accent:"down"},moves:{pointCombo:{label:"Point combo",beats:4,easing:Vn,keys:[{beat:0,reset:!0,pose:{rightShoulder:142,rightElbow:0,leftShoulder:25,leftElbow:-125,headTilt:6,lean:-3,lookX:.6,lookY:-.6},hands:{right:"point",left:"flat"}},{beat:1,pose:{rightShoulder:-38,headTilt:-6,lean:3,lookX:-.3,lookY:.5,rightHip:18}},{beat:2,reset:!0,pose:{leftShoulder:36,leftElbow:-96,rightShoulder:36,rightElbow:-96,leftWrist:20,rightWrist:20},hands:{left:"fist",right:"fist"}},{beat:3,reset:!0,pose:{leftShoulder:96,rightShoulder:96,leftElbow:0,rightElbow:0,leftWrist:50,rightWrist:50,headTilt:8,leftHip:18,rightHip:18},hands:{left:"flat",right:"flat"}}]},heart:{label:"Big heart, finger heart",beats:4,keys:[{beat:0,reset:!0,pose:{leftShoulder:165,rightShoulder:165,leftElbow:46,rightElbow:46,headTilt:-8,lean:-4},hands:{left:"cupped",right:"cupped"},easing:Vn},{beat:1,pose:{headTilt:8,lean:4}},{beat:2,reset:!0,pose:{rightShoulder:32,rightElbow:112,rightWrist:10,leftShoulder:20,leftElbow:-30,headTilt:10,leftEye:0,smile:1},hands:{right:"pinch",left:"relaxed"},easing:Vn},{beat:3,pose:{headTilt:4}}]},isolations:{label:"Isolations",beats:2,easing:_t,keys:[{beat:0,reset:!0,pose:{lean:-9,headTilt:11,leftShoulder:55,leftElbow:-112,rightShoulder:55,rightElbow:-112,rightHip:18},hands:{left:"fist",right:"fist"}},{beat:.5,pose:{lean:0,headTilt:0,rightHip:9}},{beat:1,pose:{lean:9,headTilt:-11,leftHip:18}},{beat:1.5,pose:{lean:0,headTilt:0,leftHip:9}}]}},routine:[{move:"pointCombo",beats:8},{move:"isolations",beats:4},{move:"heart",beats:8},{move:"pointCombo",beats:8,mirror:!0},{move:"isolations",beats:4}]},S1={label:"Bollywood",bpm:120,stance:{leftHip:10,rightHip:10},expression:{smile:1,mouth:.3,leftBrow:.4,rightBrow:.4},groove:{bounce:8,accent:"down",sway:3},moves:{lightBulb:{label:"Screw the bulb, pat the dog",beats:2,keys:[{beat:0,reset:!0,pose:{rightShoulder:160,rightElbow:12,rightWrist:-15,leftShoulder:40,leftElbow:-12,leftWrist:-45,lean:-4,rightHip:16,lookX:.5,lookY:-.6},hands:{right:{...Tt.cupped,roll:-30},left:{...Tt.flat,turn:0}}},{beat:.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{...Tt.cupped,roll:30}}},{beat:1,pose:{rightWrist:-15,rightElbow:12,leftWrist:-45,lean:-4,rightHip:16,leftHip:6},hands:{right:{...Tt.cupped,roll:-30}}},{beat:1.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{...Tt.cupped,roll:30}}}]},thumka:{label:"Thumka",beats:2,keys:[{beat:0,reset:!0,pose:{lean:-11,rightHip:22,leftHip:2,leftKnee:14,rightShoulder:45,rightElbow:-105,leftShoulder:128,leftElbow:18,leftWrist:35,headTilt:10,lookX:-.5},hands:{right:"fist",left:{...Tt.open,turn:2}},easing:_t},{beat:.5,pose:{lean:-4,rightHip:12,headTilt:6}},{beat:1,pose:{lean:-11,rightHip:22,headTilt:10},easing:_t},{beat:1.5,pose:{lean:-4,rightHip:12,headTilt:6}}]},flick:{label:"Cross and flick",beats:4,keys:[{beat:0,reset:!0,pose:{leftShoulder:22,rightShoulder:22,leftElbow:-62,rightElbow:-62,leftHip:16,rightHip:16,leftKnee:26,rightKnee:26},hands:{left:"fist",right:"fist"}},{beat:1,pose:{leftShoulder:132,rightShoulder:132,leftElbow:0,rightElbow:0,leftWrist:30,rightWrist:30,leftKnee:0,rightKnee:0,leftHip:10,rightHip:10,stretch:1.03},hands:{left:"spread",right:"spread"},easing:_t},{beat:2,pose:{leftShoulder:22,rightShoulder:22,leftElbow:-62,rightElbow:-62,leftWrist:0,rightWrist:0,leftHip:16,rightHip:16,leftKnee:26,rightKnee:26,stretch:1},hands:{left:"fist",right:"fist"}},{beat:3,pose:{leftShoulder:62,rightShoulder:62,leftElbow:0,rightElbow:0,leftWrist:35,rightWrist:35,leftKnee:0,rightKnee:0,leftHip:10,rightHip:10},hands:{left:"spread",right:"spread"},easing:_t}]}},routine:[{move:"thumka",beats:4},{move:"lightBulb",beats:8},{move:"flick",beats:8},{move:"thumka",beats:4,mirror:!0},{move:"lightBulb",beats:8,mirror:!0}]},T1={label:"Bhangra",bpm:100,stance:{leftShoulder:150,rightShoulder:150,leftElbow:18,rightElbow:18,leftHip:10,rightHip:10},expression:{mouth:.6,smile:1,mouthWidth:1.2,leftBrow:.5,rightBrow:.5},hands:{left:"open",right:"open"},groove:{bounce:12,accent:"down"},moves:{basic:{label:"Bhangra step",beats:2,keys:[{beat:0,reset:!0,pose:{rightHip:58,rightKnee:104,rightAnkle:30,leftShoulder:162,rightShoulder:140,headTilt:7}},{beat:.5,reset:!0,pose:{stretch:.98}},{beat:1,reset:!0,pose:{leftHip:58,leftKnee:104,leftAnkle:30,rightShoulder:162,leftShoulder:140,headTilt:-7}},{beat:1.5,reset:!0,pose:{stretch:.98}}]},dhamaal:{label:"Dhamaal (jump, arms up)",beats:2,keys:[{beat:0,reset:!0,pose:{leftHip:20,rightHip:20,leftKnee:40,rightKnee:40,stretch:.94}},{beat:.5,reset:!0,pose:{rise:.07,stretch:1.06,leftHip:6,rightHip:6,leftAnkle:45,rightAnkle:45,leftShoulder:172,rightShoulder:172,leftElbow:0,rightElbow:0},hands:{left:"point",right:"point"},easing:"ease-out-quad"},{beat:1,reset:!0,pose:{leftHip:20,rightHip:20,leftKnee:40,rightKnee:40,stretch:.94},hands:{left:"open",right:"open"},easing:"ease-in-quad"},{beat:1.5,reset:!0,pose:{rise:.07,stretch:1.06,leftHip:6,rightHip:6,leftAnkle:45,rightAnkle:45,leftShoulder:172,rightShoulder:172,leftElbow:0,rightElbow:0},hands:{left:"point",right:"point"},easing:"ease-out-quad"}]}},routine:[{move:"basic",beats:8},{move:"dhamaal",beats:4},{move:"basic",beats:8},{move:"dhamaal",beats:4}]},E1={label:"Bharatanatyam",bpm:80,stance:{...{leftHip:42,rightHip:42,leftKnee:82,rightKnee:82,leftFootOut:.3,rightFootOut:.3},leftShoulder:90,rightShoulder:90,leftElbow:0,rightElbow:0,leftWrist:75,rightWrist:75},expression:{smile:.5,leftEye:1.2,rightEye:1.2,leftBrow:.3,rightBrow:.3},hands:{left:"pataka",right:"pataka"},groove:{bounce:0},moves:{tatta:{label:"Tatta adavu (stamps)",beats:2,keys:[{beat:0,reset:!0,pose:{rightHip:48,rightKnee:104,rightAnkle:-18}},{beat:.3,reset:!0,easing:"ease-in-quad",taps:["rightToe","rightHeel"]},{beat:1,reset:!0,pose:{leftHip:48,leftKnee:104,leftAnkle:-18}},{beat:1.3,reset:!0,easing:"ease-in-quad",taps:["leftToe","leftHeel"]}]},natta:{label:"Natta adavu (stretch and look)",beats:4,keys:[{beat:0,reset:!0,pose:{rightHip:52,rightKnee:0,rightAnkle:-40,rightShoulder:125,rightWrist:60,leftShoulder:25,leftElbow:-125,leftWrist:0,headTilt:8,lookX:.9,lookY:-.4,lean:-6}},{beat:1,reset:!0},{beat:2,reset:!0,pose:{leftHip:52,leftKnee:0,leftAnkle:-40,leftShoulder:125,leftWrist:60,rightShoulder:25,rightElbow:-125,rightWrist:0,headTilt:-8,lookX:-.9,lookY:-.4,lean:6}},{beat:3,reset:!0}]},alapadma:{label:"Alapadma (lotus) to the sky",beats:4,keys:[{beat:0,reset:!0,pose:{rightShoulder:145,rightElbow:20,rightWrist:30,leftShoulder:28,leftElbow:-125,leftWrist:0,lookX:.7,lookY:-.9,headTilt:6},hands:{right:"alapadma",left:"pataka"}},{beat:1,pose:{rightWrist:55,headTilt:9}},{beat:2,reset:!0,pose:{leftShoulder:145,leftElbow:20,leftWrist:30,rightShoulder:28,rightElbow:-125,rightWrist:0,lookX:-.7,lookY:-.9,headTilt:-6},hands:{left:"alapadma",right:"pataka"}},{beat:3,pose:{leftWrist:55,headTilt:-9}}]}},routine:[{move:"tatta",beats:8},{move:"natta",beats:8},{move:"alapadma",beats:8},{move:"tatta",beats:4}]},A1={label:"Charleston",bpm:150,stance:{leftHip:10,rightHip:10,leftKnee:10,rightKnee:10,leftShoulder:30,rightShoulder:30,leftElbow:20,rightElbow:20},expression:{mouth:.4,smile:1,leftBrow:.5,rightBrow:.5},hands:{left:{...Tt.spread,turn:2},right:{...Tt.spread,turn:2}},groove:{bounce:8,accent:"down"},moves:{basic:{label:"Kick forward, kick back",beats:4,keys:[{beat:0,reset:!0,pose:{rightHip:48,rightKnee:8,rightAnkle:45,leftShoulder:75,rightShoulder:15,leftElbow:30,rightElbow:-10,lean:-7,headTilt:-5},easing:_t},{beat:1,reset:!0},{beat:2,reset:!0,pose:{leftHip:18,leftKnee:85,leftAnkle:35,rightShoulder:75,leftShoulder:15,rightElbow:30,leftElbow:-10,lean:7,headTilt:5},easing:_t},{beat:3,reset:!0}]},twist:{label:"Swivel (heels in, heels out)",beats:2,keys:[{beat:0,reset:!0,pose:{leftFootOut:-.9,rightFootOut:-.9,leftHip:4,rightHip:4,leftKnee:4,rightKnee:4,leftAnkle:-10,rightAnkle:-10,leftShoulder:18,rightShoulder:48,leftElbow:-10,rightElbow:50}},{beat:.5,pose:{leftFootOut:.6,rightFootOut:.6,leftHip:16,rightHip:16,leftKnee:22,rightKnee:22,leftAnkle:10,rightAnkle:10,leftShoulder:48,rightShoulder:18,leftElbow:50,rightElbow:-10}},{beat:1,pose:{leftFootOut:-.9,rightFootOut:-.9,leftHip:4,rightHip:4,leftKnee:4,rightKnee:4,leftAnkle:-10,rightAnkle:-10,leftShoulder:18,rightShoulder:48,leftElbow:-10,rightElbow:50}},{beat:1.5,pose:{leftFootOut:.6,rightFootOut:.6,leftHip:16,rightHip:16,leftKnee:22,rightKnee:22,leftAnkle:10,rightAnkle:10,leftShoulder:48,rightShoulder:18,leftElbow:50,rightElbow:-10}}]},kneeCross:{label:"Crossing knees",beats:2,keys:[{beat:0,reset:!0,pose:{leftHip:-6,rightHip:-6,leftKnee:-16,rightKnee:-16,leftFootOut:-.4,rightFootOut:-.4,leftShoulder:-12,rightShoulder:-12,leftElbow:0,rightElbow:0,lean:0,lookY:.6}},{beat:.5,pose:{leftHip:18,rightHip:18,leftKnee:28,rightKnee:28,leftFootOut:.3,rightFootOut:.3,leftShoulder:16,rightShoulder:16,lookY:0}},{beat:1,pose:{leftHip:-6,rightHip:-6,leftKnee:-16,rightKnee:-16,leftFootOut:-.4,rightFootOut:-.4,leftShoulder:-12,rightShoulder:-12,lookY:.6}},{beat:1.5,pose:{leftHip:18,rightHip:18,leftKnee:28,rightKnee:28,leftFootOut:.3,rightFootOut:.3,leftShoulder:16,rightShoulder:16,lookY:0}}]}},routine:[{move:"basic",beats:8},{move:"twist",beats:8},{move:"kneeCross",beats:8},{move:"basic",beats:8,mirror:!0},{move:"twist",beats:4}]},$1={label:"Tap",bpm:120,stance:{turn:.8,leftHip:-3,rightHip:3,leftKnee:-10,rightKnee:10,leftShoulder:12,rightShoulder:12,leftElbow:-40,rightElbow:40,leftWrist:-15,rightWrist:15,lean:4},expression:{smile:.9,mouth:.2,leftBrow:.3,rightBrow:.3,lookY:.3},hands:{left:"relaxed",right:"relaxed"},groove:{bounce:6,accent:"down"},moves:{shuffleBallChange:{label:"Shuffle ball change",beats:2,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:34,rightKnee:8,rightAnkle:30,leftShoulder:30,rightShoulder:-10},taps:["rightToe"]},{beat:.25,pose:{rightHip:24,rightKnee:62,rightAnkle:40},taps:["rightToe"]},{beat:.5,pose:{rightHip:-8,rightKnee:14,rightAnkle:50,leftAnkle:15,leftShoulder:12,rightShoulder:12},taps:["rightToe"]},{beat:.75,pose:{rightHip:3,rightKnee:10,rightAnkle:0,leftAnkle:0},taps:["leftHeel"]},{beat:1,reset:!0,pose:{leftHip:-34,leftKnee:-8,leftAnkle:30,rightShoulder:-30,leftShoulder:10},taps:["leftToe"]},{beat:1.25,pose:{leftHip:-24,leftKnee:-62,leftAnkle:40},taps:["leftToe"]},{beat:1.5,pose:{leftHip:8,leftKnee:-14,leftAnkle:50,rightAnkle:15,leftShoulder:12,rightShoulder:12},taps:["leftToe"]},{beat:1.75,pose:{leftHip:-3,leftKnee:-10,leftAnkle:0,rightAnkle:0},taps:["rightHeel"]}]},timeStep:{label:"Single time step",beats:4,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:8,rightKnee:4,rightAnkle:0,leftShoulder:25,rightShoulder:-20},taps:["rightToe","rightHeel"]},{beat:.5,pose:{rightHip:34,rightKnee:8,rightAnkle:30},taps:["rightToe"]},{beat:.75,pose:{rightHip:22,rightKnee:62,rightAnkle:40},taps:["rightToe"]},{beat:1,pose:{rise:.05,leftAnkle:45,leftKnee:-4,leftHip:-2,rightHip:26,rightKnee:70,stretch:1.03}},{beat:1.25,pose:{rise:0,leftAnkle:0,leftKnee:-14,stretch:1},taps:["leftToe"]},{beat:1.5,pose:{rightHip:4,rightKnee:12,rightAnkle:0,rightShoulder:25,leftShoulder:-20},taps:["rightToe"]},{beat:2,pose:{leftHip:-30,leftKnee:-6,leftAnkle:35},taps:["leftToe"]},{beat:2.25,pose:{leftHip:-4,leftKnee:-12,leftAnkle:0},taps:["leftToe"]},{beat:3,pose:{rightHip:10,rightAnkle:35,rightKnee:18,leftShoulder:12,rightShoulder:12},taps:["rightToe"]},{beat:3.5,pose:{rightHip:3,rightKnee:10,rightAnkle:0}}]},heelToe:{label:"Heel toe",beats:2,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:26,rightKnee:0,rightAnkle:-35,leftShoulder:30,rightShoulder:-20},taps:["rightHeel"]},{beat:.5,pose:{rightHip:-16,rightKnee:24,rightAnkle:55,leftShoulder:-15,rightShoulder:25},taps:["rightToe"]},{beat:1,reset:!0,pose:{leftHip:-26,leftKnee:0,leftAnkle:-35,rightShoulder:-30,leftShoulder:20},taps:["leftHeel"]},{beat:1.5,pose:{leftHip:16,leftKnee:-24,leftAnkle:55,rightShoulder:15,leftShoulder:-25},taps:["leftToe"]}]},crampRoll:{label:"Cramp roll",beats:2,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:12,rightKnee:26,leftHip:-12,leftKnee:-26}},{beat:.5,pose:{rightAnkle:40,rise:.02},taps:["rightToe"]},{beat:.625,pose:{leftAnkle:40},taps:["leftToe"]},{beat:.75,pose:{rightAnkle:0,rise:0},taps:["rightHeel"]},{beat:.875,pose:{leftAnkle:0},taps:["leftHeel"]},{beat:1,pose:{rightShoulder:135,leftShoulder:125,leftElbow:0,rightElbow:0,leftWrist:0,rightWrist:30,rightKnee:8,leftKnee:-8,rightHip:4,leftHip:-4},hands:{left:{...Tt.spread,turn:2},right:{...Tt.spread,turn:2}}},{beat:1.75,reset:!0}]}},routine:[{move:"shuffleBallChange",beats:8},{move:"timeStep",beats:4},{move:"timeStep",beats:4,mirror:!0},{move:"heelToe",beats:8},{move:"crampRoll",beats:4}]},ye={disco:b1,hipHop:w1,breaking:k1,jazz:v1,kpop:M1,bollywood:S1,bhangra:T1,bharatanatyam:E1,charleston:A1,tap:$1,popping:{label:"Popping (glides, moonwalk)",bpm:100,stance:{leftHip:9,rightHip:9,leftShoulder:16,rightShoulder:16,leftElbow:-24,rightElbow:-24},expression:{smile:.35,leftEye:.85,rightEye:.85,leftBrow:-.2,rightBrow:-.2},hands:{left:"relaxed",right:"relaxed"},groove:{bounce:0},moves:{sideGlide:{label:"Side glide",beats:2,easing:"linear",travel:.2,keys:[{beat:0,reset:!0,pose:{leftHip:11,leftKnee:0,leftAnkle:0,rightHip:36,rightKnee:45,rightAnkle:45,rightShoulder:80,rightElbow:-10,rightWrist:10,leftShoulder:28,leftElbow:18,lean:-2,headTilt:4,lookX:.7},hands:{right:"flat",left:"relaxed"}},{beat:1,pose:{leftHip:27,leftKnee:54,leftAnkle:45,rightHip:-1,rightKnee:0,rightAnkle:0,rightShoulder:74,rightWrist:-10,lean:2}}]},moonwalk:{label:"Moonwalk",beats:2,easing:"linear",travel:-.29,keys:[{beat:0,reset:!0,pose:{turn:.9,lean:4,headTilt:-4,leftHip:-12,leftKnee:0,leftAnkle:0,rightHip:23,rightKnee:57,rightAnkle:45,leftShoulder:-10,leftElbow:-45,rightShoulder:14,rightElbow:50}},{beat:1,pose:{leftHip:-23,leftKnee:-57,leftAnkle:45,rightHip:12,rightKnee:0,rightAnkle:0,leftShoulder:-14,leftElbow:-50,rightShoulder:10,rightElbow:45}}]},forwardGlide:{label:"Forward glide",beats:2,easing:"linear",travel:.29,keys:[{beat:0,reset:!0,pose:{turn:.9,lean:2,leftHip:16,leftKnee:0,leftAnkle:0,rightHip:33,rightKnee:59,rightAnkle:45,leftShoulder:12,leftElbow:-40,rightShoulder:-12,rightElbow:40}},{beat:1,pose:{leftHip:-33,leftKnee:-59,leftAnkle:45,rightHip:-16,rightKnee:0,rightAnkle:0,leftShoulder:-12,leftElbow:-40,rightShoulder:12,rightElbow:40}}]},toeStand:{label:"Toe stand",beats:4,keys:[{beat:0,reset:!0,pose:{leftHip:6,rightHip:6,leftKnee:0,rightKnee:0,leftAnkle:65,rightAnkle:65,rightShoulder:150,rightElbow:75,leftShoulder:30,leftElbow:20,headTilt:-10,lookY:.4},hands:{right:"fist",left:"fist"},easing:Vn},{beat:2,pose:{headTilt:-14,lean:-2}}]}},routine:[{move:"sideGlide",beats:4},{move:"sideGlide",beats:4,mirror:!0},{move:"moonwalk",beats:8},{move:"forwardGlide",beats:8},{move:"toeStand",beats:4}]}},ei=t=>Math.min(1,Math.max(0,t));function P1(t){const e={...et,turn:t.view},n=[];for(const s of t.keys){const i=n[n.length-1],o=!i||s.reset?e:i.pose;n.push({at:s.at,pose:{...o,...s.pose},easing:s.easing})}return n}function x1(t){return t-I1*Math.sin(2*Math.PI*t)/(2*Math.PI)}const I1=.5;function O1(t,e){if(!(e<=t.takeoff||e>=t.landing))return(e-t.takeoff)/(t.landing-t.takeoff)}function Bh(t,e){const n=typeof t=="string"?Jn[t]:t,s=P1(n),i=ei(e);let o=0;for(let d=0;d<s.length;d++)s[d].at<=i&&(o=d);const r=s[o],a=s[Math.min(o+1,s.length-1)],l=a.at>r.at?(i-r.at)/(a.at-r.at):0,c=hn(r.pose,a.pose,xt(a.easing??"ease-in-out")(ei(l))),h=O1(n,i);return h===void 0?{...c,spin:0,rise:0}:{...c,spin:n.spin*x1(h),rise:4*n.height*h*(1-h)}}function Wh(t,e,n){const s=typeof t=="string"?Jn[t]:t,i=ei(e),o=ei((i-s.takeoff)/(s.landing-s.takeoff));return s.travel*n*o}function _1(t,e,n={}){const s=typeof e=="string"?Jn[e]:e,i=n.start??0,o=n.duration??s.duration,r=n.samples??48,a=Array.from({length:r+1},(h,d)=>{const u=d/r;return{time:i+u*o,progress:u,pose:Bh(s,u)}}),c=Object.keys(et).filter(h=>a.some(d=>d.pose[h]!==et[h])).map(h=>({id:`${t}-${h}`,target:t,property:h,keyframes:a.map(d=>({time:d.time,value:d.pose[h]}))}));if(n.height!==void 0&&s.travel!==0){const h=(n.facing??1)<0?-1:1;c.push({id:`${t}-x`,target:t,property:"x",keyframes:a.map(d=>({time:d.time,value:(n.x??0)+h*Wh(s,d.progress,n.height)}))})}return c}const C1={leftHip:-55,leftKnee:-95,rightHip:55,rightKnee:95,leftShoulder:45,rightShoulder:-45,leftElbow:10,rightElbow:-10,lean:22,stretch:.94,headTilt:6},H1={leftHip:0,leftKnee:0,rightHip:0,rightKnee:0,leftAnkle:55,rightAnkle:55,leftShoulder:-172,rightShoulder:172,leftElbow:0,rightElbow:0,lean:0,stretch:1.08,headTilt:0},ni={leftHip:-128,leftKnee:-152,rightHip:128,rightKnee:152,leftAnkle:30,rightAnkle:30,leftShoulder:-78,rightShoulder:78,leftElbow:-48,rightElbow:48,lean:26,stretch:1,headTilt:14},R1={leftHip:-22,leftKnee:-30,rightHip:22,rightKnee:30,leftAnkle:10,rightAnkle:10,leftShoulder:-125,rightShoulder:125,leftElbow:0,rightElbow:0,lean:8,headTilt:0},L1={leftHip:-58,leftKnee:-100,rightHip:58,rightKnee:100,leftAnkle:0,rightAnkle:0,leftShoulder:-80,rightShoulder:80,leftElbow:-10,rightElbow:10,lean:20,stretch:.93};function dn(t,e,n,s,i,o=1300){return{label:t,view:1,spin:e,height:n,travel:s,takeoff:.27,landing:.8,duration:o,keys:[{at:0,reset:!0},{at:.16,pose:C1},{at:.27,pose:H1,easing:"ease-out-quad"},...i,{at:.76,pose:R1},{at:.86,pose:L1,easing:"ease-out-quad"},{at:1,reset:!0}]}}const Jn={frontFlip:dn("Front flip (tuck)",360,.56,.35,[{at:.38,pose:ni,easing:"ease-out-cubic"},{at:.64,pose:ni}]),backFlip:dn("Back flip (tuck)",-360,.58,-.15,[{at:.36,pose:{...ni,lean:18},easing:"ease-out-cubic"},{at:.64,pose:{...ni,lean:18}}]),layout:dn("Back layout (straight body)",-360,.66,-.2,[{at:.4,pose:{leftHip:8,rightHip:-8,leftKnee:0,rightKnee:0,leftAnkle:60,rightAnkle:60,leftShoulder:-178,rightShoulder:178,lean:-18,headTilt:-14}},{at:.64,pose:{leftHip:-4,rightHip:4,lean:-6,headTilt:-4,leftShoulder:-150,rightShoulder:150}}],1400),scissorFlip:dn("Scissor flip",360,.6,.45,[{at:.36,pose:{leftHip:-105,leftKnee:0,rightHip:-40,rightKnee:-20,leftAnkle:50,rightAnkle:50,leftShoulder:-150,rightShoulder:150,leftElbow:0,rightElbow:0,lean:12},easing:"ease-out-cubic"},{at:.52,pose:{leftHip:40,leftKnee:20,rightHip:105,rightKnee:0,leftShoulder:-140,rightShoulder:140}},{at:.66,pose:{leftHip:-30,leftKnee:-20,rightHip:30,rightKnee:20,leftShoulder:-110,rightShoulder:110,lean:6}}]),sideFlip:{label:"Side flip (tuck)",view:0,spin:360,height:.55,travel:.4,takeoff:.27,landing:.8,duration:1300,keys:[{at:0,reset:!0},{at:.16,pose:{leftHip:22,rightHip:22,leftKnee:44,rightKnee:44,leftShoulder:20,rightShoulder:20,lean:-10,stretch:.94}},{at:.27,pose:{leftHip:4,rightHip:4,leftKnee:0,rightKnee:0,leftAnkle:55,rightAnkle:55,leftShoulder:165,rightShoulder:165,lean:6,stretch:1.08},easing:"ease-out-quad"},{at:.38,pose:{leftHip:105,rightHip:105,leftKnee:135,rightKnee:135,leftShoulder:40,rightShoulder:40,leftElbow:-95,rightElbow:-95,lean:0,stretch:1,headTilt:10},easing:"ease-out-cubic"},{at:.64,pose:{}},{at:.76,pose:{leftHip:20,rightHip:20,leftKnee:20,rightKnee:20,leftAnkle:10,rightAnkle:10,leftShoulder:100,rightShoulder:100,leftElbow:0,rightElbow:0,headTilt:0}},{at:.86,pose:{leftHip:24,rightHip:24,leftKnee:48,rightKnee:48,leftAnkle:0,rightAnkle:0,leftShoulder:70,rightShoulder:70,stretch:.93},easing:"ease-out-quad"},{at:1,reset:!0}]},cartwheel:{label:"Cartwheel",view:0,spin:360,height:.155,travel:.9,takeoff:.2,landing:.86,duration:1600,keys:[{at:0,reset:!0},{at:.12,pose:{leftShoulder:165,rightShoulder:165,rightHip:30,rightKnee:0,lean:-6}},{at:.24,pose:{leftShoulder:172,rightShoulder:172,leftHip:55,rightHip:55,leftKnee:0,rightKnee:0,leftAnkle:40,rightAnkle:40,lean:0}},{at:.75,pose:{}},{at:.9,pose:{leftHip:30,rightHip:12,leftAnkle:0,rightAnkle:0,leftShoulder:150,rightShoulder:150}},{at:1,reset:!0}]},splitLeap:dn("Split leap (grand jeté)",0,.36,.9,[{at:.4,pose:{leftHip:-96,rightHip:-84,leftKnee:0,rightKnee:0,leftAnkle:55,rightAnkle:55,leftShoulder:-130,rightShoulder:-105,leftElbow:0,rightElbow:0,lean:4,headTilt:-6},easing:"ease-out-cubic"},{at:.64,pose:{lean:2}}]),toeTouch:{label:"Toe touch (straddle jump)",view:0,spin:0,height:.36,travel:0,takeoff:.27,landing:.8,duration:1200,keys:[{at:0,reset:!0},{at:.16,pose:{leftHip:22,rightHip:22,leftKnee:44,rightKnee:44,leftShoulder:-20,rightShoulder:-20,stretch:.94}},{at:.27,pose:{leftHip:4,rightHip:4,leftKnee:0,rightKnee:0,leftAnkle:55,rightAnkle:55,leftShoulder:170,rightShoulder:170,stretch:1.06},easing:"ease-out-quad"},{at:.42,pose:{leftHip:104,rightHip:104,leftShoulder:96,rightShoulder:96,leftElbow:0,rightElbow:0,stretch:1,headTilt:0},easing:"ease-out-cubic"},{at:.62,pose:{}},{at:.76,pose:{leftHip:12,rightHip:12,leftAnkle:10,rightAnkle:10,leftShoulder:120,rightShoulder:120}},{at:.86,pose:{leftHip:22,rightHip:22,leftKnee:44,rightKnee:44,leftAnkle:0,rightAnkle:0,leftShoulder:60,rightShoulder:60,stretch:.94},easing:"ease-out-quad"},{at:1,reset:!0}]},backHandspring:dn("Back handspring",-360,.16,-.7,[{at:.38,pose:{leftHip:10,rightHip:-10,leftKnee:0,rightKnee:0,leftShoulder:-178,rightShoulder:178,lean:-26,headTilt:-20}},{at:.6,pose:{leftHip:-40,rightHip:40,leftKnee:-20,rightKnee:20,lean:6,headTilt:0}}],1200)},or=.215,rr=.205,N1=.065,qh=.035,D1=.165,F1=.155,j1=12,B1=.3,W1=.7,q1=.35,K1=t=>t*Math.PI/180,ut={turn:0,lean:0,bend:0,side:0,"head.turn":0,"head.nod":0,"head.tilt":0,"arm.left.swing":0,"arm.left.spread":12,"arm.left.elbow":8,"arm.left.bend":0,"arm.right.swing":0,"arm.right.spread":12,"arm.right.elbow":8,"arm.right.bend":0,"leg.left.swing":0,"leg.left.spread":3,"leg.left.knee":0,"leg.left.ankle":0,"leg.left.toeOut":0,"leg.left.rotate":0,"leg.right.swing":0,"leg.right.spread":3,"leg.right.knee":0,"leg.right.ankle":0,"leg.right.toeOut":0,"leg.right.rotate":0,stretch:1,lift:0,roll:0,mouth:0,smile:.5,mouthWidth:1,blink:0,"eye.left":1,"eye.right":1,"brow.left":0,"brow.right":0,browTilt:0,lookX:0,lookY:0};function Ft(t={}){return{...ut,...t}}const Y1=new Set(["turn","side","head.turn","head.tilt","roll","lookX"]);function z1(t){const e={};for(const[n,s]of Object.entries(t)){const i=n.replace(/(^|\.)(left|right)(\.|$)/,(o,r,a,l)=>`${r}${a==="left"?"right":"left"}${l}`);e[i]=Y1.has(n)?-s:s}return e}function Yt(t,e){const n={};for(const s of["left","right"])for(const[i,o]of Object.entries(e))n[`${t}.${s}.${i}`]=o;return n}const Re={rest:ut,wave:Ft({"arm.right.spread":115,"arm.right.bend":55,"arm.right.elbow":0,"head.tilt":-6,smile:.9}),cheer:Ft({...Yt("arm",{spread:140,bend:20,elbow:0}),mouth:.6,smile:1,"eye.left":0,"eye.right":0}),point:Ft({"arm.right.spread":88,"arm.right.elbow":0,"arm.right.bend":0,"head.turn":-20,smile:.4}),handsOnHips:Ft({...Yt("arm",{spread:50,bend:-105,elbow:0}),...Yt("leg",{spread:9}),smile:.8}),think:Ft({"arm.right.spread":22,"arm.right.bend":-150,"arm.right.elbow":0,"head.tilt":10,lookX:-.5,lookY:-.8,smile:0}),shrug:Ft({...Yt("arm",{spread:35,bend:75,elbow:0}),"head.tilt":-10,smile:-.2}),sit:Ft({...Yt("leg",{swing:90,knee:90,spread:4}),...Yt("arm",{swing:25,elbow:45,spread:8})}),kneel:Ft({"leg.left.swing":90,"leg.left.knee":90,"leg.right.swing":-18,"leg.right.knee":108,"leg.right.ankle":16,...Yt("arm",{swing:20,elbow:30})}),crouch:Ft({...Yt("leg",{swing:75,knee:140,spread:6}),lean:25,...Yt("arm",{swing:50,elbow:40}),"head.nod":-15}),crawl:Ft({lean:82,"head.nod":-35,...Yt("arm",{swing:80,elbow:0,spread:4}),...Yt("leg",{knee:92,ankle:-88})}),lieDown:Ft({roll:90,...Yt("arm",{spread:8}),"head.nod":0})};function Kh(t={}){const e=t.headSize??.3,n=t.shoulderWidth??.06,s=t.hipWidth??.022,i=Math.max(.12,1-e-qh-(or+rr)),o=l=>({id:`arm.${l}`,parent:"spine",offset:[(l==="left"?1:-1)*n,-.035,0],rest:[0,-1,0],side:l==="left"?1:-1,bones:[{length:D1,width:[1.25,.9]},{length:F1,width:[.9,.75]}]}),r=l=>({id:`leg.${l}`,parent:null,offset:[(l==="left"?1:-1)*s,0,0],rest:[0,-1,0],side:l==="left"?1:-1,bones:[{length:or,width:[1.45,1.05]},{length:rr,width:[1.05,.85]},{length:N1,width:[.95,.7]}]}),a=(l,c)=>l[c]??ut[c]??0;return{id:"human",hipHeight:or+rr,chains:[r("left"),r("right"),{id:"spine",parent:null,rest:[0,1,0],bones:[{length:i/2,width:[1.7,1.4]},{length:i/2,width:[1.4,1.1]}]},{id:"neck",parent:"spine",rest:[0,1,0],bones:[{length:qh,width:[1,.9]}]},o("left"),o("right")],head:{on:"neck",size:e},contacts:[...["left","right"].flatMap(l=>[{chain:`leg.${l}`,joint:1},{chain:`leg.${l}`,joint:2},{chain:`leg.${l}`,joint:3},{chain:`arm.${l}`,joint:1},{chain:`arm.${l}`,joint:2}]),{chain:"spine",joint:0},{chain:"spine",joint:1},{chain:"spine",joint:2},{head:"top"}],angles(l,c){if(c.id==="spine"){const p=-a(l,"lean")/2,m=a(l,"side")/2,b=-a(l,"bend");return[{swing:p+b*B1,spread:m},{swing:p+b*W1,spread:m}]}if(c.id==="neck")return[{swing:-a(l,"bend")*q1,spread:0}];const[h,d]=c.id.split("."),u=p=>a(l,`${h}.${d}.${p}`);if(h==="arm")return[{swing:u("swing"),spread:u("spread")},{swing:u("elbow"),spread:u("bend")}];const f=(c.side??1)*u("rotate"),g=1-Math.cos(K1(u("rotate")));return[{swing:u("swing"),spread:u("spread"),yaw:f},{swing:-u("knee"),spread:0,yaw:f},{swing:90+u("ankle")-g*(u("swing")-u("knee")),spread:0,yaw:(j1+u("toeOut"))*(c.side??1)}]},withAngles(l,c,h){const[d,u]=c.id.split("."),f=g=>`${d}.${u}.${g}`;return d==="arm"?{...l,[f("swing")]:h[0].swing,[f("spread")]:h[0].spread,[f("elbow")]:h[1].swing,[f("bend")]:h[1].spread}:d==="leg"?{...l,[f("swing")]:h[0].swing,[f("spread")]:h[0].spread,[f("knee")]:-h[1].swing}:l},boneScale(l,c){const h=Math.min(3,Math.max(.3,a(l,"stretch")));return c?.id.startsWith("arm.")?Math.sqrt(h):h},headPose(l){const c=Math.min(3,Math.max(.3,a(l,"stretch")));return{yaw:a(l,"head.turn"),nod:a(l,"head.nod"),tilt:a(l,"head.tilt"),sx:1/Math.sqrt(c),sy:Math.sqrt(c)}},landmarks:{neck:["neck",0],"shoulder.left":["arm.left",0],"elbow.left":["arm.left",1],"hand.left":["arm.left",2],"shoulder.right":["arm.right",0],"elbow.right":["arm.right",1],"hand.right":["arm.right",2],"hip.left":["leg.left",0],"knee.left":["leg.left",1],"ankle.left":["leg.left",2],"toe.left":["leg.left",3],"hip.right":["leg.right",0],"knee.right":["leg.right",1],"ankle.right":["leg.right",2],"toe.right":["leg.right",3]}}}function X1(t){const e=t.split(".");if(e[0]==="hand"&&e.length>=3){const s=`${e[1]==="left"?"Left":"Right"} hand`,i={spread:"finger spread",turn:"wrist turn",bend:"wrist bend",tilt:"wrist tilt",roll:"roll"},o=e.slice(2).join(".");return`${s} · ${i[o]??o.replace(".curl"," curl").replace(".across"," across")}`}if(e.length===3){const[s,i,o]=e;return`${`${i==="left"?"Left":"Right"} ${s}`} · ${{swing:"forward / back",spread:"out / in",elbow:"elbow bend",bend:"forearm out / in",knee:"knee bend",ankle:"foot tilt",toeOut:"toes out / in",rotate:"turn out at the hip"}[o]??o}`}return{turn:"View (front → side → back)",lean:"Lean forward / back",bend:"Back curve (line of action)",side:"Lean sideways","head.turn":"Head · turn","head.nod":"Head · nod","head.tilt":"Head · tilt",stretch:"Squash / stretch",lift:"Lift off the ground",roll:"Roll (whole figure)",mouth:"Mouth open",smile:"Smile",mouthWidth:"Mouth width",blink:"Blink","eye.left":"Left eye open","eye.right":"Right eye open","brow.left":"Left brow","brow.right":"Right brow",browTilt:"Brow slant",lookX:"Look left / right",lookY:"Look up / down"}[t]??t}const U1={leftEye:"eye.left",rightEye:"eye.right",leftBrow:"brow.left",rightBrow:"brow.right"},ar=Object.fromEntries(Object.entries(ct).map(([t,e])=>[t,Object.fromEntries(Object.entries(e).map(([n,s])=>[U1[n]??n,s]))]));function G1(t,e){const n=Math.min(1,Math.max(0,t.turn??0)),s=1-n,i={...ut,turn:n},o=[{stick:"right",human:"left",s:1},{stick:"left",human:"right",s:-1}];for(const{stick:a,human:l,s:c}of o){const h=t[`${a}Shoulder`],d=t[`${a}Elbow`];i[`arm.${l}.spread`]=h*s,i[`arm.${l}.swing`]=c*h*n,i[`arm.${l}.bend`]=d*s,i[`arm.${l}.elbow`]=c*d*n;const u=t[`${a}Hip`],f=t[`${a}Knee`],g=s+c*n;i[`leg.${l}.rotate`]=90*s,i[`leg.${l}.spread`]=0,i[`leg.${l}.swing`]=u*g,i[`leg.${l}.knee`]=f*g,i[`leg.${l}.ankle`]=-(t[`${a}Ankle`]??0),i[`leg.${l}.toeOut`]=(t[`${a}FootOut`]??0)*V1,i[`eye.${l}`]=t[`${a}Eye`],i[`brow.${l}`]=t[`${a}Brow`],e&&Object.assign(i,J1(l,e[a]??vt,t[`${a}Wrist`]??0,n))}const r=t.bend??0;i.lean=t.lean*n,i.bend=r*n,i.side=(t.lean+r*.5)*s,i["head.tilt"]=(t.headTilt+r*.5)*s,i["head.nod"]=t.headTilt*n;for(const a of["mouth","smile","mouthWidth","blink","browTilt","lookX","lookY","stretch"])i[a]=t[a];return i.lift=t.rise??0,i.roll=t.spin??0,i}const V1=70;function J1(t,e,n,s){const i=t==="right"?1-s:1+s,o={};for(const r of Object.keys(vt))o[`hand.${t}.${r}`]=e[r]??vt[r];return o[`hand.${t}.turn`]=(e.turn??0)-i,o[`hand.${t}.roll`]=(e.roll??0)+n,o}const Xt=t=>t*Math.PI/180;function lr([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t,e*i+n*o,-e*o+n*i]}function cr([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i-e*o,t*o+e*i,n]}function be([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i+n*o,e,-t*o+n*i]}const we=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],si=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],ii=(t,e)=>cr(lr(t,e.swing),e.spread);function hr(t,e){const n=be(t,e);return{point:{x:n[0],y:-n[1]},depth:n[2]}}function oi(t,e,n){const s=n,o=[0,t.hipHeight*s*(t.boneScale?.(e,null)??1),0],r={};for(const p of t.chains){const m=p.parent?r[p.parent]:void 0;if(p.parent&&!m)throw new Error(`body plan ${t.id}: chain ${p.id} comes before its parent ${p.parent}`);const b=p.at??(m?m.joints3.length-1:0),S=m?m.joints3[b]:o,k=m?m.frames[Math.max(0,b-1)]:{swing:0,spread:0},y=p.offset?we(S,ii(si(p.offset,s),k)):S,M=p.side??1,$=t.boneScale?.(e,p)??1,E=t.angles(e,p),A=[y],T=[];let I=k.swing,v=k.spread;p.bones.forEach((P,H)=>{const O=E[H]??{swing:0,spread:0};I+=Xt(O.swing),v+=Xt(O.spread)*M,T.push({swing:I,spread:v});const C=be(ii(p.rest,{swing:I,spread:v}),Xt(O.yaw??0));A.push(we(A[H],si(C,P.length*s*$)))}),r[p.id]={joints3:A,frames:T}}const a=r[t.head.on],l=t.headPose?.(e)??{yaw:0,nod:0,tilt:0,sx:1,sy:1},c=a.frames[a.frames.length-1],h=t.head.size/2*s,d=h*l.sx,u=h*l.sy,f=p=>ii(be(lr(cr(p,-Xt(l.tilt)),-Xt(l.nod)),Xt(l.yaw)),c),g=we(a.joints3[a.joints3.length-1],f([0,u,0]));return{height:s,root:o,chains:r,head:{center:g,rx:d,ry:u,toBody:f}}}function dr(t,e,n){const s=n.height,i=Xt(90*(e.turn??0)),o=oi(t,e,s),{root:r}=o,a=o.chains,{rx:l,ry:c}=o.head,h=o.head.toBody,d=o.head.center,u={};for(const T of t.chains){const{joints3:I,frames:v}=a[T.id],P=I.map(H=>hr(H,i));u[T.id]={id:T.id,joints3:I,frames:v,points:P.map(H=>H.point),depths:P.map(H=>H.depth)}}const f=hr(d,i),g=[[1,0,0],[0,1,0],[0,0,1]].map(T=>be(h(T),i)),p=hr(r,i).point,m=Xt(e.roll??0),b=T=>{const I=T.x-p.x,v=T.y-p.y;return{x:p.x+I*Math.cos(m)-v*Math.sin(m),y:p.y+I*Math.sin(m)+v*Math.cos(m)}},S=([T,I,v])=>[T*Math.cos(m)+I*Math.sin(m),-T*Math.sin(m)+I*Math.cos(m),v];for(const T of Object.values(u))T.points=T.points.map(b);const k={center:b(f.point),depth:f.depth,rx:l,ry:c,angle:0,axes:g.map(S)},y=k.axes[1];k.angle=Math.atan2(y[0],y[1]);const M=T=>{if("head"in T)return{x:k.center.x+y[0]*c,y:k.center.y-y[1]*c};const I=u[T.chain];return I.points[Math.min(T.joint,I.points.length-1)]};let $=0;(n.contact??"ground")==="ground"&&($=-Math.max(...t.contacts.map(T=>M(T).y))),$-=(e.lift??0)*s;const E=T=>({x:T.x,y:T.y+$});for(const T of Object.values(u))T.points=T.points.map(E);k.center=E(k.center);const A=t.contacts.map(T=>({spec:T,point:M(T)}));return{height:s,view:i,chains:u,head:k,hip:E(b(p)),contacts:A,groundY:Math.max(...A.map(T=>T.point.y))}}const ur=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Yh=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function ri(t,e,n){const s=n.height,i=Xt(90*(e.turn??0)),o=Xt(e.roll??0),r=oi(t,e,s),a=be(r.root,i),l=m=>we(cr(ur(be(m,i),a),-o),a),c={};for(const m of t.chains)c[m.id]=r.chains[m.id].joints3.map(l);const h=l(r.head.center),d=m=>Yh(ur(l(we(r.head.center,r.head.toBody(m))),h)),u=[d([1,0,0]),d([0,1,0]),d([0,0,1])],f=m=>{if("head"in m)return we(h,si(u[1],r.head.ry));const b=c[m.chain];return b[Math.min(m.joint,b.length-1)]};let g=0;(n.contact??"ground")==="ground"&&(g=-Math.min(...t.contacts.map(m=>f(m)[1]))),g+=(e.lift??0)*s;const p=m=>[m[0],m[1]+g,m[2]];return{height:s,hip:p(a),chains:Object.fromEntries(Object.entries(c).map(([m,b])=>[m,b.map(p)])),head:{center:p(h),rx:r.head.rx,ry:r.head.ry,axes:u}}}function ai(t,e,n,s){const i=n.height,o=Xt(90*(e.turn??0)),r=oi(t,e,i),a=ri(t,e,n),l=a.hip,c=a.chains,h=a.head.center,d=T=>{if("head"in T)return we(h,si(a.head.axes[1],a.head.ry));const I=c[T.chain];return I[Math.min(T.joint,I.length-1)]},u=s.toView(l),f=s.toScreen(u),g=s.toScreen([u[0]+1,u[1],u[2]]),p=Math.hypot(g.x-f.x,g.y-f.y),m=T=>{const I=s.toView(T);return{point:s.toScreen(I),depth:I[2]*p}},b={};for(const T of t.chains){const I=c[T.id].map(m);b[T.id]={id:T.id,joints3:r.chains[T.id].joints3,frames:r.chains[T.id].frames,points:I.map(v=>v.point),depths:I.map(v=>v.depth)}}const S=s.toView(h),k=s.toScreen(S),y=s.toScreen([S[0]+1,S[1],S[2]]),M=Math.hypot(y.x-k.x,y.y-k.y),$=a.head.axes.map(T=>Yh(ur(s.toView(we(h,T)),S))),E={center:k,depth:S[2]*p,rx:r.head.rx*M,ry:r.head.ry*M,angle:Math.atan2($[1][0],$[1][1]),axes:$},A=t.contacts.map(T=>({spec:T,point:m(d(T)).point}));return{height:i*p,view:o,chains:b,head:E,hip:f,contacts:A,groundY:Math.max(...A.map(T=>T.point.y))}}function zh(t,[e,n,s]){const[i,o,r]=t.axes,a=[i[0]*e*t.rx+o[0]*n*t.ry+r[0]*s*t.rx,i[1]*e*t.rx+o[1]*n*t.ry+r[1]*s*t.rx,i[2]*e*t.rx+o[2]*n*t.ry+r[2]*s*t.rx],l=Math.hypot(e,n,s)||1,c=(i[2]*e+o[2]*n+r[2]*s)/l;return{point:{x:t.center.x+a[0],y:t.center.y-a[1]},depth:t.depth+a[2],facing:c}}class Xh{positions=[];normals=[];indices=[];vertex(e,n,s,i,o,r){const a=Math.hypot(i,o,r)||1;return this.positions.push(e,n,s),this.normals.push(i/a,o/a,r/a),this.positions.length/3-1}triangle(e,n,s){this.indices.push(e,n,s)}quad(e,n,s,i){this.indices.push(e,n,s,e,s,i)}build(){return{positions:this.positions,normals:this.normals,indices:this.indices}}}function Z1(t){const e=new Map,n=[];for(let i=0;i<t.positions.length/3;i++){const o=[0,1,2].map(r=>Math.round(t.positions[i*3+r]*1e6)).join(",");e.has(o)||e.set(o,i),n.push(e.get(o))}const s=new Map;for(let i=0;i<t.indices.length/3;i++)for(let o=0;o<3;o++){const r=n[t.indices[i*3+o]],a=n[t.indices[i*3+(o+1)%3]];if(r===a)continue;const l=r<a?`${r}-${a}`:`${a}-${r}`,c=s.get(l);c?c.faces.push(i):s.set(l,{a:Math.min(r,a),b:Math.max(r,a),faces:[i]})}return[...s.values()]}const fr=Math.PI*2;function Q1(t,e=16){const n=new Xh,s=Math.max(6,Math.round(e)),i=Math.max(3,Math.round(s/2)),o=[];for(let r=0;r<=i;r++){const a=r/i*Math.PI,l=[];for(let c=0;c<=s;c++){const h=c/s*fr,d=Math.sin(a)*Math.sin(h),u=Math.cos(a),f=Math.sin(a)*Math.cos(h);l.push(n.vertex(d*t,u*t,f*t,d,u,f))}o.push(l)}for(let r=0;r<i;r++)for(let a=0;a<s;a++){const l=o[r][a],c=o[r+1][a],h=o[r+1][a+1],d=o[r][a+1];r>0&&n.triangle(l,c,d),r<i-1&&n.triangle(c,h,d)}return n.build()}function Uh(t,e,n,s,i){const o=t.vertex(0,n,0,0,s,0),r=Array.from({length:i},(a,l)=>{const c=l/i*fr;return t.vertex(Math.sin(c)*e,n,Math.cos(c)*e,0,s,0)});for(let a=0;a<i;a++){const l=r[a],c=r[(a+1)%i];s===1?t.triangle(o,l,c):t.triangle(o,c,l)}}function Gh(t,e,n=24){const s=new Xh,i=Math.max(6,Math.round(n)),o=e/2,r=-e/2,a=h=>Array.from({length:i+1},(d,u)=>{const f=u/i*fr;return s.vertex(Math.sin(f)*t,h,Math.cos(f)*t,Math.sin(f),0,Math.cos(f))}),l=a(r),c=a(o);for(let h=0;h<i;h++)s.quad(l[h],l[h+1],c[h+1],c[h]);return Uh(s,t,o,1,i),Uh(s,t,r,-1,i),s.build()}function li(t){const e=Array.from({length:t.indices.length/3},()=>[]);for(const n of Z1(t))for(const s of n.faces){const i=n.faces.find(o=>o!==s)??-1;e[s].push({a:n.a,b:n.b,across:i})}return{...t,faceEdges:e}}const ci=t=>t*180/Math.PI,un=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],pr=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Zn=t=>Math.hypot(t[0],t[1],t[2]),gr=t=>{const e=Zn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},hi=t=>Math.atan2(Math.sin(t),Math.cos(t));function Vh(t){const[e,n,s]=gr(t);return{swing:Math.asin(Math.max(-1,Math.min(1,s))),spread:Math.atan2(e,-n)}}function ty(t,e,n,s,i){const o=t.chains.find(I=>I.id===n);if(!o)throw new Error(`reach: no chain ${n} in ${t.id}`);if(o.bones.length<2||o.rest[1]>-.99)throw new Error(`reach: ${n} is not a hanging limb of two bones or more`);if(!t.withAngles)throw new Error(`reach: the ${t.id} plan cannot set angles`);const r=dr(t,{...e,turn:0,roll:0,lift:0},{height:i.height,contact:"none"}),a=r.chains[n],l=a.joints3[0],c=Zn(un(a.joints3[1],a.joints3[0])),h=Zn(un(a.joints3[2],a.joints3[1])),d=o.parent?r.chains[o.parent].frames[Math.max(0,(o.at??r.chains[o.parent].joints3.length-1)-1)]:{swing:0,spread:0},u=un(s,l),f=Math.min(c+h-1e-6,Math.max(Math.abs(c-h)+1e-6,Zn(u))),g=gr(u),p=o.parent!==null,m=ii(o.pole??(p?[0,-.35,-1]:[0,0,1]),d);let b=un(m,[g[0]*pr(m,g),g[1]*pr(m,g),g[2]*pr(m,g)]);Zn(b)<1e-6&&(b=be([1,0,0],0)),b=gr(b);const S=(c*c+f*f-h*h)/(2*c*f),k=Math.sqrt(Math.max(0,1-S*S)),y=[l[0]+c*(S*g[0]+k*b[0]),l[1]+c*(S*g[1]+k*b[1]),l[2]+c*(S*g[2]+k*b[2])],M=[l[0]+g[0]*f,l[1]+g[1]*f,l[2]+g[2]*f],$=o.side??1,E=Vh(un(y,l)),A=Vh(un(M,y)),T=[{swing:ci(hi(E.swing-d.swing)),spread:ci(hi(E.spread-d.spread))*$},{swing:ci(hi(A.swing-E.swing)),spread:ci(hi(A.spread-E.spread))*$}];return t.withAngles(e,o,T)}const ey=.34,ke=.12,Qt=-.4,ee=(t,e,n)=>t[e]??n,ny=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),sy=.45,iy=.35,oy=.7;function di(t,e,n){const s=f=>Math.sqrt(Math.max(0,1-f.x*f.x-f.y*f.y)),i=zh(t,[n.x,n.y,s(n)]).facing,o=t.axes[2],r=Math.atan2(o[0],o[2]),a=Math.cos(r),l=a>=0?1:-1,c=l*Math.max(iy,Math.abs(a)),h=l*Math.max(oy,Math.abs(a)),d=Math.cos(t.angle),u=Math.sin(t.angle);return{facing:i,points:e.map(f=>{const g=sy*Math.sin(r)+n.x*c+(f.x-n.x)*h,p=f.y+o[1]*s(f),m=g*t.rx,b=p*t.ry;return{x:t.center.x+m*d+b*u,y:t.center.y+m*u-b*d}})}}const ui=(t,e,n,s=12)=>Array.from({length:s+1},(i,o)=>{const r=o/s,a=1-r;return{x:a*a*t.x+2*a*r*e.x+r*r*n.x,y:a*a*t.y+2*a*r*e.y+r*r*n.y}}),mr=(t,e,n,s,i=16)=>Array.from({length:i},(o,r)=>{const a=Math.PI*2*r/i;return{x:t+Math.cos(a)*n,y:e+Math.sin(a)*s}}),Jh=.05;function ry(t,e,n,s){const i=Math.max(1,Math.min(s*.6,.14*e.rx)),o=(b,S)=>di(e,b,S).points,r=(b,S)=>di(e,[],{x:b,y:S}).facing,a=ee(n,"smile",0),l=ee(n,"blink",0),c=ee(n,"lookX",0),h=ee(n,"lookY",0),d=ee(n,"browTilt",0);for(const b of[1,-1]){const S=b===1?"left":"right",k=ey*b;if(r(k,ke)<Jh)continue;const y={x:k,y:ke},M=ny(ee(n,`eye.${S}`,1),l);if(M<.2){const T=a>.5?.12:-.06;t.line(o(ui({x:k-.12,y:ke},{x:k,y:ke+T},{x:k+.12,y:ke}),y),i)}else{if(M>1.2){const P=.13*M;t.shape(o(mr(k,ke,P*.85,P),y),"#ffffff",i)}const T=M>1.2?.075:.1,I=k+c*.08,v=ke-h*.07;t.shape(o(mr(I,v,T,T*1.1*Math.min(M,1)),y),t.ink,0)}const $=ke+.3+ee(n,`brow.${S}`,0)*.14+Math.max(0,M-1)*.12,E={x:k+b*.13,y:$},A={x:k-b*.13,y:$+d*.1};t.line(o([E,{x:(E.x+A.x)/2,y:(E.y+A.y)/2},A],{x:k,y:$}),i)}const u={x:0,y:Qt};if(r(0,Qt)<-Jh)return;const f=.25*Math.max(.3,ee(n,"mouthWidth",1)),g=Math.min(1,Math.max(0,ee(n,"mouth",0)));if(g<=.05){t.line(o(ui({x:-f,y:Qt},{x:0,y:Qt-a*.25},{x:f,y:Qt}),u),i);return}const p=.3*g;let m;if(a>.3){const b=Qt+.05;m=[...ui({x:f,y:b},{x:0,y:Qt-p*2},{x:-f,y:b})]}else if(a<-.3){const b=Qt-p*.6;m=[...ui({x:f,y:b},{x:0,y:Qt+p*1.4},{x:-f,y:b})]}else m=mr(0,Qt,f*.8,p);t.shape(o(m,u),t.ink,0)}function yr(t={}){const e=(t.proportions??"bold")==="bold",n=t.figure??"fluid",s=t.look??"clean",i=t.height??300,o=n==="stick";return{plan:t.plan??Kh({headSize:t.headSize??(e?.3:.24),shoulderWidth:o?0:t.shoulderWidth??.06,hipWidth:o?0:t.hipWidth??.022}),figure:n,look:s,height:i,lineWidth:t.lineWidth??i*(e?.045:.022),ink:t.ink??(s==="pencil"?"#2f2f33":"#1e293b"),skin:t.skin??(s==="pencil"?"none":"#ffffff"),seed:t.seed??1,pencil:t.pencil??{},layers:t.layers??{},contact:t.contact??"ground",hands:t.hands??"dot",handStyle:t.handStyle??"glove",handSize:t.handSize??(t.handStyle==="natural"?.14:.17)}}function ay(t,e,n,s){const{point:i,facing:o}=zh(t,[e,n,s]);return{point:i,facing:o}}const br=t=>t.rest[1]<-.5,ly=.3;function cy(t,e,n){return t.figure==="stick"?br(e)?n.slice(0,3):n:br(e)&&n.length>=3?Ce(n[0],n[1],n[2],ly):n.length===3?Ce(n[0],n[1],n[2],1):n}function wr(t,e){const n=t.plan.id==="human"?{...ut,...e}:e;return fi(t,n,dr(t.plan,n,{height:t.height,contact:t.contact}))}function fi(t,e,n){const s={},i={},o={},r=.01*t.height;t.plan.chains.forEach(u=>{const f=n.chains[u.id];s[u.id]=f.points;const g=f.depths.reduce((S,k)=>S+k,0)/f.depths.length,p=u.parent?n.chains[u.parent]:void 0,m=p?p.depths[u.at??p.depths.length-1]:0,b=g-m;o[u.id]=Math.abs(b)<r?0:b,i[u.id]={points:cy(t,u,f.points),depth:g}}),i.head={points:[n.head.center],depth:n.head.depth},o.head=0;const a=[...t.plan.chains.map(u=>u.id),"head"],l=[...a].sort((u,f)=>o[u]-o[f]||a.indexOf(u)-a.indexOf(f)),c={hip:n.hip};for(const[u,[f,g]]of Object.entries(t.plan.landmarks??{})){const p=n.chains[f]?.points;p&&(c[u]=p[Math.min(g,p.length-1)])}const h={};for(const[u,f]of Object.entries(c))h[u]=f.y>=n.groundY-.01*t.height;const d={height:t.height,lineWidth:t.lineWidth,turn:e.turn??0,points:c,chains:s,parts:i,head:n.head,groundY:n.groundY,grounded:h};return{skeleton:n,joints:d,order:l}}function Zh(t,e){return wr(t,e).joints}function Qh(t,e,n){const{head:s}=n;t.guideEllipse(s.center.x,s.center.y,s.rx*1.03,s.ry*1.03,s.angle);const i=Array.from({length:13},(l,c)=>({x:0,y:-.95+1.9*c/12})),o=Array.from({length:13},(l,c)=>({x:-.95+1.9*c/12,y:.12})),r=di(s,i,{x:0,y:0});r.facing>0&&t.guide(r.points),t.guide(di(s,o,{x:0,y:.12}).points),t.guide(n.chains.spine??[]);const a=e.lineWidth*.9;for(const l of["shoulder.left","shoulder.right","elbow.left","elbow.right","hip.left","hip.right","knee.left","knee.right"]){const c=n.points[l];c&&t.guideEllipse(c.x,c.y,a,a,0)}}function td(t,e,n,s,i,o){const r=n.lineWidth;if(i==="head"){const{head:f}=s,g=n.skin==="none"?null:n.skin;e.ellipse(f.center.x,f.center.y,f.rx,f.ry,f.angle,g,r),e.look!=="silhouette"&&ry(e,f,o,r);return}const a=n.plan.chains.find(f=>f.id===i),l=s.chains[i],c=s.parts[i].points;if(n.figure==="stick"){if(i==="neck")return;const f=i==="spine"?[...l,...s.chains.neck?.slice(1)??[]]:c;e.line(f,r);return}const h=(f,g)=>[a.bones[f].width[0]*r,a.bones[g].width[1]*r];if(br(a)){const[f,g]=h(0,1);if(e.limb(c,f,g),a.bones.length>=3)e.limb([l[2],l[3]],a.bones[2].width[0]*r,a.bones[2].width[1]*r);else if(n.hands==="cartoon"&&i.startsWith("arm."))hy(t,e,n,l,i.endsWith(".left")?"left":"right",o);else{const p=l[l.length-1];e.dot(p.x,p.y,r*.62)}return}if(i==="spine"){const f=s.points["hip.left"],g=s.points["hip.right"];f&&g&&Math.hypot(f.x-g.x,f.y-g.y)>.5&&e.limb([f,g],r*1.3,r*1.3);const[p,m]=h(0,a.bones.length-1);e.limb(c,p,m);const b=s.points["shoulder.left"],S=s.points["shoulder.right"];b&&S&&Math.hypot(b.x-S.x,b.y-S.y)>.5&&e.limb(Ce(b,l[l.length-1],S,1,10),r*1.15,r*1.15);return}const[d,u]=h(0,a.bones.length-1);e.limb(c,d,u)}function ed(t,e){const n=`hand.${e}.`,s={};for(const[r,a]of Object.entries(t))r.startsWith(n)&&(s[r.slice(n.length)]=a);const i=t.turn??0,o=e==="right"?1-i:1+i;return{...vt,...s,turn:o+(s.turn??0)}}function hy(t,e,n,s,i,o){const r=s[s.length-1],a=s[s.length-2],l=Math.atan2(r.x-a.x,-(r.y-a.y))*180/Math.PI;zs(t,r,ed(o,i),{size:n.handSize*n.height,side:i,angle:l,pen:e,skin:n.skin==="none"?"#ffffff":n.skin,fingers:n.handStyle==="natural"?5:4,plump:n.handStyle==="natural"?1.15:1.6,lineWidth:n.lineWidth*.3})}function nd(t,e,n,s=0){const i=e.plan.id==="human"?{...ut,...n}:n;id(t,e,i,wr(e,i),s)}function kr(t,e){const n=e/t.height;return{...t,height:e,lineWidth:t.lineWidth*n}}function dy(t,e,n,s){const i=t.plan.id==="human"?{...ut,...e}:e,o=ai(t.plan,i,{height:s.height,contact:t.contact},n);return fi(kr(t,o.height),i,o).joints}function uy(t,e,n,s,i){const o=e.plan.id==="human"?{...ut,...n}:n,r=ai(e.plan,o,{height:i.height,contact:e.contact},s),a=kr(e,r.height);id(t,a,o,fi(a,o,r),i.time??0)}function sd(t,e,n,s){const i=t.plan.id==="human"?{...ut,...e}:e,o=ai(t.plan,i,{height:s.height,contact:t.contact},n),r=kr(t,o.height),{joints:a,order:l}=fi(r,i,o),c=o.height/s.height;return l.map((h,d)=>({part:h,depth:(a.parts[h]?.depth??0)/c,draw(u,f=0){const g=qn(u,{look:r.look,ink:r.ink,lineWidth:r.lineWidth,seed:qt(`${r.seed}:${h}`),time:f,pencil:r.pencil}),p=b=>{b&&(u.save(),b(u,a,g,f),u.restore())};u.save(),u.lineCap="round",u.lineJoin="round",d===0&&(r.look==="pencil"&&r.pencil.construction!==!1&&Qh(g,r,a),p(r.layers.behind));const m=r.layers.parts?.[h];p(m?.under),td(u,g,r,a,h,i),p(m?.over),d===l.length-1&&p(r.layers.front),u.restore()}}))}function id(t,e,n,s,i){const{joints:o,order:r}=s,a=qn(t,{look:e.look,ink:e.ink,lineWidth:e.lineWidth,seed:e.seed,time:i,pencil:e.pencil}),l=c=>{c&&(t.save(),c(t,o,a,i),t.restore())};t.save(),t.lineCap="round",t.lineJoin="round",e.look==="pencil"&&e.pencil.construction!==!1&&Qh(a,e,o),l(e.layers.behind);for(const c of r){const h=e.layers.parts?.[c];l(h?.under),td(t,a,e,o,c,n),l(h?.over)}l(e.layers.front),t.restore()}function fy(t,e,n){const s={...t};for(const[i,o]of Object.entries(e)){const r=t[i]??o;s[i]=r+(o-r)*n}return s}function py(t,e,n,s){const i=t.plan.id==="human"?{...ut,...e}:e;let o;if(Array.isArray(s))o=s;else{const{skeleton:r}=wr(t,i),a=dr(t.plan,{...i,roll:0},{height:t.height,contact:"none"}),l=(i.roll??0)*Math.PI/180,c=s.x-r.hip.x,h=s.y-r.hip.y,d=a.hip.x+c*Math.cos(-l)-h*Math.sin(-l),u=a.hip.y+c*Math.sin(-l)+h*Math.cos(-l),f=Math.PI/2*(i.turn??0),g=s.depth??r.chains[n].depths[r.chains[n].depths.length-1],p=Math.cos(f),m=Math.sin(f);o=[d*p-g*m,-u,d*m+g*p]}return ty(t.plan,i,n,o,{height:t.height})}function gy(t){const{character:e}=t,n=e.height*.8,s=e.height,i=e.plan.id==="human"?ut:{};return{type:"custom",x:t.x-n/2,y:t.y-s,width:n,height:s,props:{...i,...t.pose},character:e,draw(o,r,a){o.translate(n/2,s),nd(o,e,r.props,a)}}}function od(t,e,n){const s=o=>({x:o.x+e,y:o.y+n}),i=o=>Object.fromEntries(Object.entries(o).map(([r,a])=>[r,a.map(s)]));return{...t,points:Object.fromEntries(Object.entries(t.points).map(([o,r])=>[o,s(r)])),chains:i(t.chains),parts:Object.fromEntries(Object.entries(t.parts).map(([o,r])=>[o,{...r,points:r.points.map(s)}])),head:{...t.head,center:s(t.head.center)},groundY:t.groundY+n}}function my(t,e,n){const s=t.character;if(!s)throw new Error("characterAt: the target was not made by characterTarget");const i={...t.props};let o=0,r=0;for(const[l,c]of e.state?.values.get(n)??[])typeof c=="number"&&(l==="x"||l==="motionPathX"?o=c:l==="y"||l==="motionPathY"?r=c:l in i&&(i[l]=c));const a=Zh(s,i);return{pose:i,joints:od(a,t.x+o+t.width/2,t.y+r+t.height)}}function vr(t,e=ut){const n=[];return t.forEach((s,i)=>{const o=i===0?e:n[i-1],r=typeof s.pose=="string"?Re[s.pose]:void 0;n.push(r?{...r,turn:o.turn??0}:{...o,...s.pose})}),n}function yy(t,e,n=ut){const s=vr(e,n);return Object.keys(n).filter(o=>s.some(r=>(r[o]??n[o])!==n[o])).map(o=>({id:`${t}-${o}`,target:t,property:o,keyframes:e.map((r,a)=>({time:r.time,value:s[a][o]??n[o],...r.easing?{easing:r.easing}:{}}))}))}const Mr=new Map;function by(t){const e=Mr.get(t);if(e)return e;let n=[1,1,1];const s=t.trim().replace("#","");if(t.trim().startsWith("#")&&(s.length===3||s.length===6)){const i=s.length===3?s.split("").map(o=>o+o).join(""):s;n=[0,2,4].map(o=>Number.parseInt(i.slice(o,o+2),16)/255)}else{const i=t.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/);i&&(n=[Number(i[1])/255,Number(i[2])/255,Number(i[3])/255])}return Mr.size<512&&Mr.set(t,n),n}Pe([-3,-5,-4]);const wy=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)};function rd(t,e,n){const s=[0,0,0];for(const i of n){const o=by(i.color);let r;if(i.light==="ambient")r=i.intensity;else if(i.light==="directional")r=i.intensity*Math.max(0,-ue(e,i.direction));else{const a=en(i.position,t),l=Os(a),c=l>0?nn(a,1/l):e,h=i.range?Math.max(0,1-l/i.range)**2:1;if(r=i.intensity*Math.max(0,ue(e,c))*h,i.light==="spot"){const d=Math.cos(i.angle*Math.PI/180),u=Math.cos(i.angle*.8*Math.PI/180);r*=wy(d,u,-ue(c,i.direction))}}s[0]+=o[0]*r,s[1]+=o[1]*r,s[2]+=o[2]*r}return s}function ad(t,e){return t?Math.min(1,Math.max(0,(e-t.near)/(t.far-t.near))):0}function Sr(t,e,n={}){t.save(),ky(t,e,n),t.restore()}function ky(t,e,n){const s=Tr(e,n);n.shadow!==!1&&Er(t,e,n);for(const i of e.under)Pr(t,i,s,n);if(n.rider){if(t.save(),e.openings.length>0){t.beginPath();for(const i of e.openings){t.moveTo(i[0].x,i[0].y);for(const o of i.slice(1))t.lineTo(o.x,o.y);t.closePath()}t.clip("nonzero")}n.rider(t),t.restore()}for(const i of e.over)Pr(t,i,s,n)}function Tr(t,e={}){return e.lineWidth??Math.max(1.3,t.sizePx*.022)}function Er(t,e,n={}){e.shadow.opacity<=0||e.shadow.points.length<3||(t.save(),t.globalAlpha=e.shadow.opacity,pi(t,e.shadow.points,n.ink??"#26262b",!1),t.restore())}function vy(t,e,n,s={}){t.save(),Pr(t,e,n,s),t.restore()}function ld(t,e,n,s={}){const i=s.style==="stick",o=e.flatMap(h=>{if(i&&h.part.solidOnly)return[];const d=h.part.layer??0;return i&&h.spine?[{depth:h.depth,layer:d,part:h}]:h.faces.map(u=>({depth:u.depth,layer:d,part:h,face:u}))}),r=new Map;for(const h of o){const d=h.face?.normal;if(!h.face?.center||!d)continue;const u=Math.abs(d[0])>=Math.abs(d[1])&&Math.abs(d[0])>=Math.abs(d[2])?0:Math.abs(d[1])>=Math.abs(d[2])?1:2,f=u*2+(d[u]<0?1:0);r.set(f,[...r.get(f)??[],h])}for(const h of r.values())for(const d of h){const{center:u,normal:f}=d.face;for(const g of h){if(g.part.part.id===d.part.part.id)continue;const p=g.face;if(p.normal[0]*f[0]+p.normal[1]*f[1]+p.normal[2]*f[2]<=.8)continue;const b=p.normal[0]*(u[0]-p.center[0])+p.normal[1]*(u[1]-p.center[1])+p.normal[2]*(u[2]-p.center[2]);b>-cd/5&&b<cd&&(d.layer=Math.max(d.layer,g.layer),d.depth=Math.max(d.depth,g.depth+1e-6))}}o.sort((h,d)=>h.layer-d.layer||h.depth-d.depth);const a=new Map,l=h=>{let d=a.get(h.part.id);return d||a.set(h.part.id,d=Ar(t,h,n,s)),d};t.save();const c=t.globalAlpha;for(const{part:h,face:d}of o){t.globalAlpha=c*h.opacity;const u=l(h);if(!d)u.line(h.spine,n*1.15);else{const f=i?hd(h,s):d.light?My(h,d,s):$r(h);f&&(!i&&s.look==="silhouette"?u.shape(d.points,f,0):pi(t,d.points,i||d.light?f:gi(f,d.tone),!0,h.cut?1.6:.8));const g=(h.part.outline??1)*n;if(g>0)for(const p of d.edges??[])p.length>1&&u.line(p,g);for(const p of d.marks??[])u.line(p,n*.7)}}t.restore()}const cd=.05;function Ar(t,e,n,s){return qn(t,{look:s.look??"clean",ink:e.part.ink??s.ink??"#26262b",lineWidth:n,seed:qt(`${s.seed??0}:${e.part.id}`),time:s.time??0,pencil:{construction:!1,rubbedOut:0,...s.pencil}})}function $r(t){const{part:e}=t;return e.glow&&t.glow>0&&e.fill?Or(e.fill,e.glow.color,t.glow):e.fill}function My(t,e,n){const{part:s}=t;if(!s.fill)return;const i=Ir(s.fill,e.light,e.fog??0,n.fog);return s.glow&&t.glow>0?Or(i,s.glow.color,t.glow):i}function hd(t,e){const n=$r(t);return n&&(Ty(n)||t.glow>0)?n:e.paper??"#fbf8ef"}function Pr(t,e,n,s){e.opacity<1?(t.save(),t.globalAlpha*=e.opacity,dd(t,e,n,s),t.restore()):dd(t,e,n,s)}function dd(t,e,n,s){if(s.style==="stick")return Sy(t,e,n,s);const{part:i}=e,o=Ar(t,e,n,s),r=$r(e),a=s.look==="silhouette";for(const c of e.faces)r&&(a?o.shape(c.points,r,0):pi(t,c.points,gi(r,c.tone)));const l=(i.outline??1)*n;if(l>0)for(const c of e.edges)c.length>1&&o.line(c,l);for(const c of e.marks)o.line(c,n*.7)}function Sy(t,e,n,s){const{part:i}=e;if(i.solidOnly)return;const o=Ar(t,e,n,s);if(e.spine){o.line(e.spine,n*1.15);return}const r=hd(e,s);for(const l of e.faces)pi(t,l.points,r);const a=(i.outline??1)*n;if(a>0)for(const l of e.edges)l.length>1&&o.line(l,a);for(const l of e.marks)o.line(l,n*.7)}function Ty(t){const e=fn(t);return e?(.299*e[0]+.587*e[1]+.114*e[2])/255<.3:!1}function pi(t,e,n,s=!0,i=.8){t.fillStyle=n,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let o=1;o<e.length;o++)t.lineTo(e[o].x,e[o].y);t.closePath(),t.fill(),s&&(t.strokeStyle=n,t.lineWidth=i,t.lineJoin="round",t.stroke())}function fn(t){const e=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim());if(!e)return;const n=e[1].length===3?e[1].replace(/./g,s=>s+s):e[1];return[0,2,4].map(s=>parseInt(n.slice(s,s+2),16))}const xr=t=>`#${t.map(e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0")).join("")}`;function gi(t,e){const n=fn(t);return n?xr(e>=1?n.map(s=>s+(255-s)*(e-1)*2):n.map(s=>s*e)):t}function Ir(t,e,n,s){const i=fn(t);if(!i)return t;let o=i.map((a,l)=>a*e[l]);const r=s?fn(s):void 0;return r&&n>0&&(o=o.map((a,l)=>a+(r[l]-a)*n)),xr(o)}function Or(t,e,n){const s=fn(t),i=fn(e);return!s||!i?n<.5?t:e:xr(s.map((o,r)=>o+(i[r]-o)*n))}const ud=40,Ey=.215+.205,jt=(t,e)=>{const n={};for(const s of["left","right"])for(const[i,o]of Object.entries(e))n[`${t}.${s}.${i}`]=o;return n},it=(t,e)=>t[e]??ut[e]??0;function fd(t,e,n=ut,s=1){const i=zn(t),o=e*Math.PI*2,r=Math.sin(o)*s,a=Math.cos(o)*s,l=(1+Math.cos(o*2*(i.bounces??1)))/2,c=i.crouch??0,h=i.shoulder??0,d=i.forearm??0,u={...ut,...n};u["leg.left.swing"]=i.swing*r+c*.6,u["leg.right.swing"]=-i.swing*r+c*.6,u["leg.left.knee"]=i.knee*Math.max(0,a)+c*1.2,u["leg.right.knee"]=i.knee*Math.max(0,-a)+c*1.2,u["leg.left.ankle"]=it(n,"leg.left.ankle")-(i.tiptoe??0),u["leg.right.ankle"]=it(n,"leg.right.ankle")-(i.tiptoe??0);for(const[f,g]of[["left",-1],["right",1]])it(n,`arm.${f}.spread`)>ud||it(n,`arm.${f}.swing`)>ud||(u[`arm.${f}.swing`]=h+g*i.arm*r,u[`arm.${f}.elbow`]=it(n,`arm.${f}.elbow`)+d+i.elbow*Math.max(0,g*r));return u.lean=it(n,"lean")+i.lean*s,u.bend=it(n,"bend")+(i.bend??0),u["head.nod"]=it(n,"head.nod")-i.lean*.5*s+(i.headTilt??0),u.side=it(n,"side")+(i.sway??0)*Math.sin(o),u.lift=it(n,"lift")+(i.bounce??0)*s*l,u.stretch=it(n,"stretch")*(1+(i.squash??0)*(l-.5)),u}function pd(t,e,n=1){const s=zn(t);return 4*Ey*e*Math.sin(s.swing*n*Math.PI/180)}const pn=t=>ar[t],mi={take:t=>[{after:140,pose:{stretch:.8,bend:10,lean:it(t,"lean")-4,...jt("arm",{spread:6,swing:0,elbow:10}),"eye.left":.35,"eye.right":.35,"brow.left":-.6,"brow.right":-.6,mouth:0},easing:"ease-in-out"},{after:260,pose:{stretch:.78}},{after:360,pose:{lift:.22,stretch:1.35,bend:-14,...jt("arm",{spread:150,bend:35,swing:0,elbow:0}),...jt("leg",{swing:25,knee:60}),...pn("shocked")},easing:"ease-out-cubic"},{after:720,pose:{lift:.25,stretch:1.25,bend:-10,...jt("arm",{spread:140})},easing:"ease-in-out"},{after:900,pose:{lift:0,stretch:.74,bend:12,...jt("arm",{spread:70,bend:0}),...jt("leg",{swing:30,knee:60})},easing:"ease-in-quad"},{after:1060,pose:{stretch:1.06,bend:-3,...jt("arm",{spread:60}),"leg.left.swing":it(t,"leg.left.swing"),"leg.right.swing":it(t,"leg.right.swing"),"leg.left.knee":it(t,"leg.left.knee"),"leg.right.knee":it(t,"leg.right.knee")},easing:"ease-out"},{after:1260,pose:{stretch:it(t,"stretch"),bend:it(t,"bend"),...pn("surprised"),...jt("arm",{spread:55,bend:60})},easing:"ease-in-out"}],doubleTake:t=>[{after:160,pose:{lookX:1,lookY:0,"head.turn":0},easing:"ease-out"},{after:520,pose:{lookX:-.6,"head.turn":30,"head.nod":it(t,"head.nod")-4,smile:.6,mouth:0},easing:"ease-in-out"},{after:1100,pose:{lookX:-.6}},{after:1180,pose:{"head.turn":0,"head.nod":it(t,"head.nod")-10,bend:it(t,"bend")-10,lift:.05,stretch:1.18,...pn("shocked"),lookX:1,lookY:0},easing:"ease-out-cubic"},{after:1360,pose:{lift:0,stretch:.88,"head.nod":it(t,"head.nod")-4,bend:it(t,"bend")+4},easing:"ease-in-quad"},{after:1560,pose:{stretch:it(t,"stretch"),"head.nod":it(t,"head.nod"),bend:it(t,"bend")},easing:{type:"elastic",mode:"out",amplitude:1,period:.35}}],windUp:()=>[{after:220,pose:{lean:-18,bend:-16,"head.nod":-6,"arm.left.swing":60,"arm.left.elbow":100,"arm.right.swing":-40,"arm.right.elbow":90,"leg.left.swing":55,"leg.left.knee":95,stretch:.92,...pn("angry"),lookX:1},easing:"ease-out"},{after:620,pose:{lean:-20,bend:-18,stretch:.9}},{after:700,pose:{lean:28,bend:14,"head.nod":6,"arm.left.swing":-30,"arm.right.swing":60,"leg.left.swing":-20,"leg.left.knee":30,"leg.right.swing":20,stretch:1.12},easing:"ease-out-cubic"}],land:t=>[{after:120,pose:{lift:0,stretch:.7,bend:14,...jt("arm",{spread:75}),...jt("leg",{swing:25,knee:50})},easing:"ease-in-quad"},{after:300,pose:{stretch:1.05,bend:-4,"arm.left.spread":it(t,"arm.left.spread"),"arm.right.spread":it(t,"arm.right.spread")},easing:"ease-out"},{after:460,pose:{lift:0,stretch:it(t,"stretch"),bend:it(t,"bend"),...jt("leg",{swing:0,knee:0})},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...pn("scared"),...jt("arm",{swing:40,elbow:110,spread:14}),stretch:.94,bend:it(t,"bend")+8},easing:"ease-out"}];for(let n=1;n<=14;n++){const s=n%2===0?1:-1;e.push({after:80+n*45,pose:{side:it(t,"side")+2.5*s,"head.tilt":it(t,"head.tilt")-2*s}})}return e.push({after:755,pose:{side:it(t,"side"),"head.tilt":it(t,"head.tilt"),bend:it(t,"bend")}}),e},deflate:t=>[{after:260,pose:{stretch:1.04,"head.nod":it(t,"head.nod")-4,"brow.left":.3,"brow.right":.3},easing:"ease-in-out"},{after:900,pose:{...pn("sad"),bend:18,stretch:.92,lean:it(t,"lean")+5,"head.nod":14,...jt("arm",{spread:6,swing:0,elbow:4,bend:0})},easing:"ease-in-out"}]};function gd(t,e){const n=Ft(e.from??{}),s=e.speed??1;let i=n;return[{time:e.at,pose:n},...mi[t](n).map(o=>(i={...i,...o.pose},{time:e.at+o.after*s,pose:i,act:!1,...o.easing?{easing:o.easing}:{}}))]}const Ay=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),$y=new Set(["walk","walking","gait"]),md=t=>typeof t=="number"?t:void 0,Py=1.7;function xy(t,e,n){const s=Array.from({length:24},(i,o)=>{const r=o/24*Math.PI*2,a=e.toView([Math.cos(r)*n,0,Math.sin(r)*n*.8]);return a[2]<-.001?e.toScreen(a):null});s.some(i=>i===null)||(t.beginPath(),s.forEach((i,o)=>o===0?t.moveTo(i.x,i.y):t.lineTo(i.x,i.y)),t.closePath(),t.fillStyle="rgba(0, 0, 0, 0.22)",t.fill())}function Iy(t){const e=ue([0,1,0],t);if(e>.999999)return _s();if(e<-.999999)return zt(Wt([1,0,0],180));const n=Is([0,1,0],t);return zt(Wt(n,Math.acos(e)*180/Math.PI))}function Oy(t,e,n,s,i){const o=t.solid??{},r=o.outline===!1?void 0:o.outline??{width:2,color:"#0f172a"},a={color:o.color??"#475569",shading:o.shading??"toon",outline:r},l={color:o.skin??"#f2c49b",shading:o.shading??"toon",outline:r},c={color:"#0f172a",shading:"unlit"},h=s.height*.034,d=[],u=(k,y,M)=>d.push({mesh:k,world:mt(i,y),material:M}),f=(k,y,M)=>u(e.sphere,wo(k,[0,0,0,1],[y,y,y]),M);for(const k of n.chains){const y=s.chains[k.id],M=k.id==="spine"?1.9:1;k.bones.forEach(($,E)=>{const A=y[E],T=y[E+1],I=bo(A,T),[v,P]=$.width??[1,1],H=h*M*(v+P)/2;if(I>1e-6){const O=jl(A,T,.5),C=Iy(Pe(en(T,A)));u(e.cylinder,mt(xe(O),mt(C,Ie([H,I,H]))),a)}f(A,h*M*v,a),f(T,h*M*P,a)}),k.id.startsWith("arm.")&&f(y[y.length-1],h*1.5,l)}const{center:g,rx:p,ry:m,axes:b}=s.head,S=[...b[0],0,...b[1],0,...b[2],0,...g,1];u(e.sphere,mt(S,Ie([p,m,p])),l);for(const k of[-1,1]){const y=Pe([k*.36,.15,.92]),M=xs(g,xs(xs(nn(b[0],y[0]*p*1.04),nn(b[1],y[1]*m*1.04)),nn(b[2],y[2]*p*1.04))),$=[...b[0],0,...b[1],0,...b[2],0,...M,1];u(e.sphere,mt($,Ie([p*.11,m*.14,p*.03])),c)}return d}const _y={kind:"character",validate(t){const e=t;return e.height!==void 0&&!(e.height>0)?["a character's height must be positive"]:[]},prepare(t){return{who:yr({...t.character,height:1}),cylinder:li(Gh(1,1,16)),sphere:li(Q1(1,20))}},resolve({object:t,prepared:e,values:n,world:s,camera:i,lights:o=[],fog:r,toScreen:a}){const l=t,c=e,h=c.who;let d={...ut,...l.pose};for(const[A,T]of n)typeof T=="number"&&!Ay.has(A)&&!$y.has(A)&&(d[A]=T);const u=Math.max(0,Math.min(1,md(n.get("walking"))??l.walking??0));if(u>0){const A=typeof n.get("gait")=="string"?n.get("gait"):l.gait,T=fd(A,md(n.get("walk"))??0,d);d=Object.fromEntries(Object.keys({...d,...T}).map(I=>[I,(d[I]??0)+((T[I]??0)-(d[I]??0))*u]))}const f=l.height??Py,g=mt(i.view,s),p={toView:A=>Rt(g,A),toScreen:A=>a(A)},b=-p.toView([0,f/2,0])[2];if(b<=i.near)return null;const S=l.shadow===!1?[]:[{depth:b+f,draw:A=>xy(A,p,f*.18)}];if(l.look==="solid"){const A=ri(h.plan,d,{height:f,contact:h.contact});return{meshes:Oy(l,c,h.plan,A,s),drawables:S}}const k=Rt(s,[0,f*.6,0]),y=Pe(en(i.position,k)),M=rd(k,y,o).map(A=>Math.min(1,A)),$=o.length>0&&h.skin!=="none"?{...h,skin:Ir(h.skin,M,ad(r,bo(k,i.position)),r?.color)}:h,E=sd($,d,p,{height:f});return{drawables:[...S,...E.map((A,T)=>({depth:-A.depth-T*1e-6,draw:(I,v)=>A.draw(I,v.time)}))]}}},Qn=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function yd([t,e,n]){const[s,i,o]=[t/2,e/2,n/2];return{vertices:[[-s,-i,-o],[s,-i,-o],[s,i,-o],[-s,i,-o],[-s,-i,o],[s,-i,o],[s,i,o],[-s,i,o]],faces:[{corners:[4,5,6,7],normal:[0,0,1]},{corners:[1,0,3,2],normal:[0,0,-1]},{corners:[5,1,2,6],normal:[1,0,0]},{corners:[0,4,7,3],normal:[-1,0,0]},{corners:[7,6,2,3],normal:[0,1,0]},{corners:[0,1,5,4],normal:[0,-1,0]}]}}const gn=(t,[e,n,s])=>t==="z"?[e,n,s]:t==="x"?[s,n,e]:[e,s,n];function bd(t,e,n="x",s=20,i=0){const o=[],r=e/2;for(const c of[-r,r])for(let h=0;h<s;h++){const d=Math.PI*2*h/s;o.push(gn(n,[Math.cos(d)*t,Math.sin(d)*t,c]))}const a=[{corners:Array.from({length:s},(c,h)=>s-1-h),normal:gn(n,[0,0,-1])},{corners:Array.from({length:s},(c,h)=>s+h),normal:gn(n,[0,0,1])}];for(let c=0;c<s;c++){const h=(c+1)%s,d=Math.PI*2*(c+.5)/s;a.push({corners:[c,h,s+h,s+c],normal:gn(n,[Math.cos(d),Math.sin(d),0])})}const l=[];if(i>0)for(const c of[-r,r]){const h=o.push(gn(n,[0,0,c*1.01]))-1;for(let d=0;d<i;d++){const u=Math.PI*2*d/i,f=o.push(gn(n,[Math.cos(u)*t*.82,Math.sin(u)*t*.82,c*1.01]))-1;l.push([h,f])}}return{vertices:o,faces:a,marks:l,creases:!0}}function wd([t,e,n],s=16){const i=Math.max(4,Math.round(s/2)),o=[[0,e,0]];for(let h=1;h<i;h++){const d=Math.PI*h/i;for(let u=0;u<s;u++){const f=Math.PI*2*u/s;o.push([Math.sin(d)*Math.cos(f)*t,Math.cos(d)*e,Math.sin(d)*Math.sin(f)*n])}}const r=o.push([0,-e,0])-1,a=(h,d)=>1+(h-1)*s+d%s,l=h=>{const d=h.reduce((u,f)=>[u[0]+o[f][0],u[1]+o[f][1],u[2]+o[f][2]],[0,0,0]);return Qn([d[0]/(t*t),d[1]/(e*e),d[2]/(n*n)])},c=[];for(let h=0;h<s;h++){const d=[0,a(1,h+1),a(1,h)];c.push({corners:d,normal:l(d)});for(let f=1;f<i-1;f++){const g=[a(f,h),a(f,h+1),a(f+1,h+1),a(f+1,h)];c.push({corners:g,normal:l(g)})}const u=[a(i-1,h),a(i-1,h+1),r];c.push({corners:u,normal:l(u)})}return{vertices:o,faces:c,creases:!1}}const Cy=t=>t.reduce((e,[n,s],i)=>{const[o,r]=t[(i+1)%t.length];return e+n*r-o*s},0)/2;function kd(t,e){const n=Cy(t)<0?[...t].reverse():t,s=n.length,i=e/2,o=[...n.map(([a,l])=>[i,l,a]),...n.map(([a,l])=>[-i,l,a])],r=[{corners:Array.from({length:s},(a,l)=>s-1-l),normal:[1,0,0]},{corners:Array.from({length:s},(a,l)=>s+l),normal:[-1,0,0]}];for(let a=0;a<s;a++){const l=(a+1)%s,[c,h]=[n[l][0]-n[a][0],n[l][1]-n[a][1]];r.push({corners:[a,l,s+l,s+a],normal:Qn([0,-c,h])})}return{vertices:o,faces:r,creases:!0}}function vd(t,e){const n={left:([i,o])=>[0,o,i],right:([i,o])=>[0,o,i],front:([i,o])=>[i,o,0],back:([i,o])=>[i,o,0],up:([i,o])=>[i,0,o]},s={left:[1,0,0],right:[-1,0,0],front:[0,0,1],back:[0,0,-1],up:[0,1,0]};return{vertices:t.map(n[e]),faces:[{corners:t.map((i,o)=>o),normal:s[e]}]}}function Md(t,e,n=8){const s=r=>Array.isArray(e)?e[Math.min(r,e.length-1)]:e,i=[],o=[];t.forEach((r,a)=>{const l=t[Math.min(a+1,t.length-1)],c=t[Math.max(a-1,0)],h=Qn([l[0]-c[0],l[1]-c[1],l[2]-c[2]]),d=Math.abs(h[1])<.9?[0,1,0]:[1,0,0],u=Qn(Sd(h,d)),f=Sd(u,h);for(let g=0;g<n;g++){const p=Math.PI*2*g/n,m=Math.cos(p)*s(a),b=Math.sin(p)*s(a);i.push([r[0]+u[0]*m+f[0]*b,r[1]+u[1]*m+f[1]*b,r[2]+u[2]*m+f[2]*b])}});for(let r=0;r<t.length-1;r++)for(let a=0;a<n;a++){const l=(a+1)%n,c=[r*n+a,r*n+l,(r+1)*n+l,(r+1)*n+a],h=c.reduce((u,f)=>[u[0]+i[f][0]/4,u[1]+i[f][1]/4,u[2]+i[f][2]/4],[0,0,0]),d=[(t[r][0]+t[r+1][0])/2,(t[r][1]+t[r+1][1])/2,(t[r][2]+t[r+1][2])/2];o.push({corners:c,normal:Qn([h[0]-d[0],h[1]-d[1],h[2]-d[2]])})}return{vertices:i,faces:o,creases:!1}}function Sd(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function Td(t){switch(t.type){case"box":return yd(t.size);case"cylinder":return bd(t.radius,t.length,t.axis,t.segments,t.spokes);case"ellipsoid":return wd(t.radii,t.segments);case"extrude":return kd(t.profile,t.width);case"panel":return vd(t.points,t.facing);case"tube":return{...Md(t.points,t.radius,t.segments),joined:t.joined}}}function _r(t,e){if(t.length<2)return t;const n=i=>t[Math.max(0,Math.min(t.length-1,i))],s=i=>{const o=i*(t.length-1),r=Math.min(t.length-2,Math.floor(o)),a=o-r,[l,c,h,d]=[n(r-1),n(r),n(r+1),n(r+2)];return[0,1,2].map(u=>{const f=l[u],g=c[u],p=h[u],m=d[u];return .5*(2*g+(-f+p)*a+(2*f-5*g+4*p-m)*a*a+(-f+3*g-3*p+m)*a*a*a)})};return Array.from({length:e},(i,o)=>s(o/(e-1)))}const Le=t=>Array.isArray(t)&&t.length===2&&t.every(e=>typeof e=="number"&&Number.isFinite(e));function yi(t,e){return((e-t)%360+540)%360-180}function Ed(t){const e=t.map((n,s)=>({frame:n,i:s})).sort((n,s)=>n.frame.time-s.frame.time||n.i-s.i).map(({frame:n})=>n);return e.filter((n,s)=>s+1>=e.length||e[s+1].time!==n.time)}function mn(t,e){return Math.atan2(e[0]-t[0],e[1]-t[1])*180/Math.PI}function Ad(t){const e=t.filter((i,o)=>o===0||Math.hypot(i[0]-t[o-1][0],i[1]-t[o-1][1])>1e-6);if(e.length<2)return[];const n=e.length===2?e:_r(e.map(([i,o])=>[i,0,o]),(e.length-1)*12).map(([i,,o])=>[i,o]);let s=0;return n.map((i,o)=>(o>0&&(s+=Math.hypot(i[0]-n[o-1][0],i[1]-n[o-1][1])),{point:i,at:s}))}function $d(t,e){let n=1;for(;n<t.length-1&&t[n].at<e;)n++;const s=t[n-1],i=t[n],o=i.at>s.at?Math.max(0,Math.min(1,(e-s.at)/(i.at-s.at))):0;return{point:[s.point[0]+(i.point[0]-s.point[0])*o,s.point[1]+(i.point[1]-s.point[1])*o],direction:[i.point[0]-s.point[0],i.point[1]-s.point[1]]}}function Pd(t,e){if(e<=0)return 0;if(e>=1)return 1;let n=0,s=1;for(let i=0;i<40;i++){const o=(n+s)/2;t(o)<e?n=o:s=o}return(n+s)/2}const Cr=["do","at","for","to","through","toward","speed","pose","gag"],xd={walk:1.3,bouncy:1.4,doubleBounce:1.2,sneak:.6,strut:1.2,tired:.8,run:3.6,shove:.7},Hr=Object.keys(Ot),Rr=Object.keys(Re),Lr=Object.keys(mi),Hy=.25,Ry=700/180,Ly=200,Ny=300;function Id(t){if(!Array.isArray(t))return[{beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const e=[...Hr,"face","hold","pose","gag","place"],n=[];return t.forEach((s,i)=>{const o=c=>n.push({beat:i,message:c});if(!s||typeof s!="object"||Array.isArray(s))return o("Each beat must be an object like { do: 'walk', to: [x, z] }.");const r=s,a={duration:"for",path:"through",position:"to",heading:"toward",direction:"toward"};for(const c of Object.keys(r))Cr.includes(c)||o(ot("beat field",c,Cr,a[c]));const l=typeof r.do=="string"?Rr.includes(r.do)?"pose":Lr.includes(r.do)?"gag":r.do==="turn"?"face":void 0:void 0;if(typeof r.do!="string"||!e.includes(r.do))return o(ot("character 3D beat",r.do,e,l));Hr.includes(r.do)&&(r.to===void 0&&r.through===void 0&&o(`\`${r.do}\` needs \`to\` ([x, z] metres) or \`through\` (a list of them).`),r.to!==void 0&&!Le(r.to)&&o(`\`to\` is a point on the ground, [x, z] metres (got ${JSON.stringify(r.to)}).`),r.through!==void 0&&!(Array.isArray(r.through)&&r.through.length>0&&r.through.every(Le))&&o("`through` is a list of points on the ground, each [x, z] metres.")),r.do==="place"&&!Le(r.to)&&o("`place` needs `to`: a point on the ground, [x, z] metres."),r.do==="face"&&!(Le(r.toward)||typeof r.toward=="number")&&o("`face` needs `toward`: a point [x, z] or a heading in degrees."),r.do==="pose"&&!(typeof r.pose=="object"&&r.pose!==null)&&!Rr.includes(r.pose)&&o(ot("pose",r.pose,Rr)),r.do==="gag"&&!Lr.includes(r.gag)&&o(ot("gag",r.gag,Lr))}),n}function Dy(t,e,n){const s=Id(e);if(s.length>0)throw new Error(`characterScript3D: ${s.length} problem(s) in the beats:
54
+ ${s.map(y=>` beat ${y.beat}: ${y.message}`).join(`
55
+ `)}`);const i=n.height??1.7,o={...ut,...n.pose};let[r,a]=n.position??[0,0],l=n.heading??0,c=0;const h=new Map,d=[],u=(y,M,$,E="linear")=>{const A=h.get(y)??[];A.push({time:M,value:$,easing:E}),h.set(y,A)};u("x",0,r),u("z",0,a),u("rotateY",0,l);const f=(y,M)=>{const $=yi(l,M);if(Math.abs($)<1)return y;const E=Math.max(Ly,Math.abs($)*Ry);return u("rotateY",y,l),l+=$,u("rotateY",y+E,l,"ease-in-out"),y+E},g=(y,M,$,E="ease-in-out")=>{for(const[A,T]of Object.entries($))o[A]!==T&&(u(A,y,o[A]??0),u(A,M,T,E),o[A]=T)},p=(y,M,$)=>{const E=Ad([[r,a],...M.through??[M.to]]);if(E.length<2)return $;const A=f($,mn(E[0].point,E[1].point)),T=E[E.length-1].at,I=M.speed??xd[y]*Math.sqrt(i/1.7),v=M.for??T/I*1e3,P=pd(y,i),H=xt("ease-in-out"),O=Math.min(Ny,v/4);d.push({time:A,value:y}),u("walking",A,0),u("walking",A+O,1,"ease-out"),u("walking",A+v-O,1),u("walking",A+v,0,"ease-in");const C=c;let j=l;for(let D=0;;D=Math.min(T,D+Hy)){const W=A+Pd(H,D/T)*v,{point:B,direction:_}=$d(E,D);if(j+=yi(j,mn([0,0],_)),u("x",W,B[0]),u("z",W,B[1]),u("rotateY",W,j),u("walk",W,C+D/P),D>=T)break}return c=C+T/P,[r,a]=E[E.length-1].point,l=j,A+v},m=[];let b=0;for(const y of e){const M=y.at??b;let $=M;if(Hr.includes(y.do))$=p(y.do,y,M);else if(y.do==="face")$=f(M,typeof y.toward=="number"?y.toward:mn([r,a],y.toward));else if(y.do==="hold")$=M+(y.for??1e3);else if(y.do==="place")u("x",M,r),u("z",M,a),[r,a]=y.to,u("x",M+1,r),u("z",M+1,a),typeof y.toward=="number"&&(u("rotateY",M,l),l=y.toward,u("rotateY",M+1,l)),$=M+1;else if(y.do==="pose"){$=M+(y.for??500);const E=typeof y.pose=="string"?Re[y.pose]:y.pose;g(M,$,E)}else if(y.do==="gag"){const E=gd(y.gag,{at:M,from:{...o}});let A=E[0];for(const T of E.slice(1))g(A.time,T.time,Object.fromEntries(Object.entries(T.pose).filter(([I,v])=>o[I]!==v)),T.easing??"ease-in-out"),A=T;$=A.time}m.push({do:y.do,start:M,end:$}),b=$}const S=`${n.scene}/${t}`,k=[...h].map(([y,M])=>({id:`${t}-${y}`,target:S,property:y,keyframes:Ed(M)}));return d.length>0&&k.push({id:`${t}-gait`,target:S,property:"gait",keyframes:d}),{tracks:k,duration:b,beats:m,end:{position:[r,a],heading:l,pose:{...o}}}}const Od={x:0,y:0,scale:1,rotate:0,shakeX:0,shakeY:0,shakeRotate:0};function Fy(t){const e=n=>{const s=t?.get(n);return typeof s=="number"?s:Od[n]};return{x:e("x"),y:e("y"),scale:e("scale"),rotate:e("rotate"),shakeX:e("shakeX"),shakeY:e("shakeY"),shakeRotate:e("shakeRotate")}}function jy(t,e,n){const s=n.width/2,i=n.height/2,r=1+2*Math.max(Math.abs(e.shakeX),Math.abs(e.shakeY))/Math.max(1,Math.min(n.width,n.height));t.translate(s+e.x+e.shakeX,i+e.y+e.shakeY),t.rotate((e.rotate+e.shakeRotate)*Math.PI/180),t.scale(e.scale*r,e.scale*r),t.translate(-s,-i)}function By(t,e,n){const s=e.width/2,i=e.height/2,o=(t.rotate+t.shakeRotate)*Math.PI/180,r=(n.x-s)*t.scale,a=(n.y-i)*t.scale;return{x:s+t.x+t.shakeX+r*Math.cos(o)-a*Math.sin(o),y:i+t.y+t.shakeY+r*Math.sin(o)+a*Math.cos(o)}}function _d(t,e,n={},s){const i=n.length??240,o=9,r=28,a=i-22;t.save(),t.translate(e.x,e.y),t.rotate((n.angle??-30)*Math.PI/180),t.fillStyle=n.color??"#f4c542",t.fillRect(r,-o,a-r,2*o),t.fillStyle="#e8b4a0",t.fillRect(a,-o,i-a,2*o),t.fillStyle="#f1dcbf",t.beginPath(),t.moveTo(0,0),t.lineTo(r,-o),t.lineTo(r,o),t.closePath(),t.fill(),t.fillStyle=n.outline??"#2f2f33",t.beginPath(),t.moveTo(0,0),t.lineTo(r*.35,-o*.35),t.lineTo(r*.35,o*.35),t.closePath(),t.fill(),t.strokeStyle=n.outline??"#2f2f33",t.lineWidth=3,t.lineJoin="round",t.lineCap="round";const l=[[{x:0,y:0},{x:r,y:-o},{x:i,y:-o},{x:i,y:o},{x:r,y:o},{x:0,y:0}],[{x:r,y:-o},{x:r,y:o}],[{x:a,y:-o},{x:a,y:o}]];for(const c of l)Rd(t,c,s);t.restore()}function Nr(t,e,n={},s){const i=n.length??90,o=n.thickness??34;t.save(),t.translate(e.x,e.y),t.rotate((n.angle??-35)*Math.PI/180);const r=-o/2;t.fillStyle=n.color??"#f4a7b9",t.fillRect(0,r,i,o),t.fillStyle="#e9edf2",t.fillRect(i*.45,r,i*.55,o),t.strokeStyle=n.outline??"#2f2f33",t.lineWidth=3,t.lineJoin="round";const a=[{x:0,y:r},{x:i,y:r},{x:i,y:-r},{x:0,y:-r},{x:0,y:r}],l=[{x:i*.45,y:r},{x:i*.45,y:-r}];if(s)s.line(a),s.line(l);else for(const c of[a,l]){t.beginPath(),t.moveTo(c[0].x,c[0].y);for(const h of c.slice(1))t.lineTo(h.x,h.y);t.stroke()}t.restore()}const Cd=150,Wy={pencil:44,eraser:30};function Dr(t,e,n={},s){const i=n.tool??"pencil",o=n.skin??"#f1c9a5",r=n.outline??"#2f2f33",a=n.scale??1,l=Math.min(1,Math.max(0,n.lift??0)),c=(n.angle??-30)*Math.PI/180,h=s?s.nudge(.6):{x:0,y:0},d=Cd*a*(1+.05*l);l>0&&(t.save(),t.fillStyle=r,t.globalAlpha=.15*l,t.beginPath(),t.ellipse(e.x,e.y,9*a,4*a,0,0,Math.PI*2),t.fill(),t.restore());const u={x:e.x+h.x+6*l*a,y:e.y+h.y-18*l*a},f=Tt.pencilGrip,g=E=>{const A=E.fingers.thumb,T=E.fingers.index,I=E.fingers.middle,v=Hd([A.points[3],T.points[3],I.points[3]]),P=Hd([A.points[1],T.points[0]]),H=(A.depths[3]+T.depths[3]+I.depths[3])/3;return{pinch:v,direction:Math.atan2(P.y-v.y,P.x-v.x),depth:H}},p=Ys(f,{size:d}),m=c-g(p).direction,b=Ys(f,{size:d,angle:m*180/Math.PI}),S=g(b),k=Wy[i]*a,y={x:S.pinch.x-Math.cos(c)*k,y:S.pinch.y-Math.sin(c)*k},M={x:u.x-y.x,y:u.y-y.y},$=b.axes.up;qy(t,M,{x:-$.x,y:-$.y},d,n.arm??300*a,o,n.sleeve??"#5b7db1",r),zs(t,M,f,{size:d,angle:m*180/Math.PI,skin:o,ink:r,lineWidth:3*a,prop:{depth:S.depth,draw:()=>{t.save(),t.translate(u.x,u.y),t.scale(a,a),i==="eraser"?Nr(t,{x:0,y:0},{angle:c*180/Math.PI,outline:r},s):_d(t,{x:0,y:0},{angle:c*180/Math.PI,length:190,outline:r},s),t.restore()}}})}const Hd=t=>({x:t.reduce((e,n)=>e+n.x,0)/t.length,y:t.reduce((e,n)=>e+n.y,0)/t.length});function qy(t,e,n,s,i,o,r,a){const l={x:-n.y,y:n.x},c=s*.15,h=(p,m,b)=>({x:e.x+n.x*p+l.x*m*b,y:e.y+n.y*p+l.y*m*b}),d=h(i,0,0),u=p=>{const m=t.createLinearGradient(e.x,e.y,d.x,d.y);return m.addColorStop(0,p),m.addColorStop(.6,p),m.addColorStop(1,Xy(p)),m},f=Math.min(s*.55,i*.35);t.save(),t.lineJoin="round",t.lineCap="round",t.lineWidth=3*(s/Cd),t.beginPath(),t.moveTo(h(-s*.1,-1,c).x,h(-s*.1,-1,c).y),t.lineTo(h(f+4,-1,c*1.1).x,h(f+4,-1,c*1.1).y),t.lineTo(h(f+4,1,c*1.1).x,h(f+4,1,c*1.1).y),t.lineTo(h(-s*.1,1,c).x,h(-s*.1,1,c).y),t.closePath(),t.fillStyle=o,t.fill(),t.strokeStyle=a,t.beginPath(),t.moveTo(h(0,-1,c).x,h(0,-1,c).y),t.lineTo(h(f,-1,c*1.1).x,h(f,-1,c*1.1).y),t.moveTo(h(0,1,c).x,h(0,1,c).y),t.lineTo(h(f,1,c*1.1).x,h(f,1,c*1.1).y),t.stroke();const g=[h(f,-1,c*1.3),h(i,-1,c*1.5),h(i,1,c*1.5),h(f,1,c*1.3)];t.beginPath(),g.forEach((p,m)=>m?t.lineTo(p.x,p.y):t.moveTo(p.x,p.y)),t.closePath(),t.fillStyle=u(r),t.fill(),t.strokeStyle=u(a),t.beginPath(),t.moveTo(g[1].x,g[1].y),t.lineTo(g[0].x,g[0].y),t.lineTo(g[3].x,g[3].y),t.lineTo(g[2].x,g[2].y),t.stroke(),t.restore()}function Ky(t,e,n={}){const s=n.offstage??{x:2e3,y:1400},i=n.enter??450,o=n.exit??450,r=n.linger??1500,a=[...t].filter(p=>p.path.length>0).sort((p,m)=>p.start-m.start),l=p=>p.tool??"pencil",c=p=>{const m=Math.min(1,Math.max(0,p));return m*m*(3-2*m)},h=(p,m,b)=>({x:p.x+(m.x-p.x)*b,y:p.y+(m.y-p.y)*b}),d=a.find(p=>e>=p.start&&e<=p.end);if(d){const p=d.end-d.start,m=p>0?(e-d.start)/p:1;return{at:js(d.path,m),tool:l(d),lift:0,drawing:!0}}const u=[...a].reverse().find(p=>p.end<e),f=a.find(p=>p.start>e),g=p=>p.path[p.path.length-1];if(u&&f&&f.start-u.end<=r){const p=(e-u.end)/(f.start-u.end),m=p<.5?l(u):l(f);return{at:h(g(u),f.path[0],c(p)),tool:m,lift:Math.sin(Math.PI*p),drawing:!1}}if(f&&f.start-e<=i){const p=1-(f.start-e)/i;return{at:h(s,f.path[0],c(p)),tool:l(f),lift:1-c(p),drawing:!1}}if(u&&e-u.end<=o){const p=(e-u.end)/o;return{at:h(g(u),s,c(p)),tool:l(u),lift:c(p),drawing:!1}}return null}function Yy(t,e,n,s=.08,i=32){const o=Math.PI*2*(1+s),r=[];for(let a=0;a<=i;a++){const l=-Math.PI/2+o*a/i;r.push({x:t+Math.cos(l)*n,y:e+Math.sin(l)*n})}return r}function zy(t){const{path:e}=t,n=e.map(a=>a.x),s=e.map(a=>a.y),i=Math.min(...n),o=Math.min(...s),r=t.hand===!1?void 0:t.hand===!0||t.hand===void 0?{}:t.hand;return{type:"custom",x:i,y:o,width:Math.max(1,Math.max(...n)-i),height:Math.max(1,Math.max(...s)-o),props:{draw:0},draw(a,l,c){const h=Math.min(1,Math.max(0,Number(l.props?.draw??0)));a.translate(-i,-o),a.strokeStyle=t.color??"#2f2f33",a.lineWidth=t.lineWidth??5,a.lineCap="round",a.lineJoin="round";const d=t.sketch?Bs(a,t.sketch,c):void 0;h>0&&(d?t.smooth?d.curve(e,h):d.line(e,h):Rd(a,ln(e,h))),r&&h>0&&h<1&&Dr(a,js(e,h),r,d)}}}function Xy(t){const e=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim());if(!e)return"rgba(0, 0, 0, 0)";const n=e[1].length===3?[...e[1]].map(r=>r+r).join(""):e[1],[s,i,o]=[0,2,4].map(r=>parseInt(n.slice(r,r+2),16));return`rgba(${s}, ${i}, ${o}, 0)`}function Rd(t,e,n){if(!(e.length<2)){if(n)return n.line(e);t.beginPath(),t.moveTo(e[0].x,e[0].y);for(const s of e.slice(1))t.lineTo(s.x,s.y);t.stroke()}}const bi=1e5;function Uy(t,e,n,s,i=6){const o=[],r=Math.max(1,Math.round(i));for(let a=0;a<=r;a++)o.push({x:a%2===0?t:t+n,y:e+s*a/r});return o}function Fr(t,e,n,s){if(s<=0||e.length===0)return;const i=ln(e,s),o=n/2,r=a=>{t.beginPath(),t.rect(-bi,-bi,2*bi,2*bi),a(),t.clip("evenodd")};for(const a of i)r(()=>{t.moveTo(a.x+o,a.y),t.arc(a.x,a.y,o,0,Math.PI*2)});for(let a=1;a<i.length;a++){const l=i[a-1],c=i[a],h=Math.hypot(c.x-l.x,c.y-l.y);if(h===0)continue;const d=-(c.y-l.y)/h*o,u=(c.x-l.x)/h*o;r(()=>{t.moveTo(l.x+d,l.y+u),t.lineTo(c.x+d,c.y+u),t.lineTo(c.x-d,c.y-u),t.lineTo(l.x-d,l.y-u),t.closePath()})}}function Gy(t,e,n,s,i){t.save(),Fr(t,e,n,s),i(),t.restore()}function Vy(t,e){const n=e.width??40,s=e.hand===!0?{}:e.hand||void 0,i=e.eraser===!1?void 0:e.eraser===!0||e.eraser===void 0?{}:e.eraser;return{...t,props:{...t.props,erase:0},draw(o,r,a){const l=Number(r.props?.erase??0);if(o.save(),Fr(o,e.path,n,l),t.draw(o,r,a),o.restore(),!i||l<=0||l>=1)return;const c=js(e.path,l);s?Dr(o,c,{...s,tool:"eraser"}):Nr(o,c,i)}}}function ts(){const t=new Map,e=(n,...s)=>t.set(n,[...t.get(n)??[],...s]);return{keys:n=>t.get(n),push:e,tween(n,s,i,o,r=300){e(n,{time:o.at,value:s},{time:o.at+(o.duration??r),value:i,...o.easing?{easing:o.easing}:{}})},last(n,s){const i=t.get(n);return i?[...i].sort((o,r)=>o.time-r.time)[i.length-1].value:s},valueAt:(n,s)=>wi(t.get(n),s),cutAfter(n,s){for(const i of n)t.set(i,(t.get(i)??[]).filter(o=>o.time<=s))},tracks(n){return[...t].filter(([,s])=>s.length>0).map(([s,i])=>({id:`${n}-${s}`,target:n,property:s,keyframes:Jy(i)}))}}}function wi(t,e){if(!t||t.length===0)return 0;const n=[...t].sort((s,i)=>s.time-i.time);if(e<=n[0].time)return n[0].value;for(let s=1;s<n.length;s++)if(e<=n[s].time){const i=n[s-1],o=n[s];return o.time===i.time?o.value:i.value+(o.value-i.value)*(e-i.time)/(o.time-i.time)}return n[n.length-1].value}function ki(t){const e=[...t??[]].sort((n,s)=>n.time-s.time);return e.slice(1).flatMap((n,s)=>n.value!==e[s].value?[{start:e[s].time,end:n.time}]:[])}function Jy(t){return[...t].sort((n,s)=>n.time-s.time).map(n=>({time:n.time,value:n.value,...n.easing?{easing:n.easing}:{}}))}const Zy=.0016,Qy=.6,Ne=33;function es(t){const e=(o,r)=>`piece.${o.id}.${r}`,n=(o,r)=>({x:o.home.x+t.valueAt(e(o,"x"),r),y:o.home.y+t.valueAt(e(o,"y"),r)}),s=(o,r)=>{const a=t.keys(e(o,"x"));if(!a||a.length<2)return;const l=n(o,r-Ne),c=n(o,r);return{x:(c.x-l.x)/Ne,y:(c.y-l.y)/Ne}},i=(o,r)=>t.cutAfter(["x","y","rotate"].map(a=>e(o,a)),r);return{at:n,cutAfter:i,follow(o,r){for(const a of r)t.push(e(o,"x"),{time:a.time,value:a.x-o.home.x}),t.push(e(o,"y"),{time:a.time,value:a.y-o.home.y})},fling(o,r){const a=n(o,r.at),l=r.velocity??s(o,r.at)??{x:.5,y:-.6},c=r.gravity??Zy,h=r.duration??900,d=(r.spin??Qy)*(l.x<0?-1:1),u=t.valueAt(e(o,"rotate"),r.at);i(o,r.at);for(let f=0;f<=h;f+=Ne){const g=a.x+l.x*f,p=a.y+l.y*f+.5*c*f*f;t.push(e(o,"x"),{time:r.at+f,value:g-o.home.x}),t.push(e(o,"y"),{time:r.at+f,value:p-o.home.y}),t.push(e(o,"rotate"),{time:r.at+f,value:u+d*f})}t.tween(e(o,"opacity"),1,0,{at:r.at+h*.6,duration:h*.4})},move(o,r){const a=n(o,r.at);t.tween(e(o,"x"),a.x-o.home.x,r.to.x-o.home.x,r,400),t.tween(e(o,"y"),a.y-o.home.y,r.to.y-o.home.y,r,400)}}}function jr(t,e,{ground:n,every:s,floors:i}){if(i.every(k=>k.windows.length===0))return t;const o=t.find(k=>k.target===e&&k.property==="y"),r=new Ht({id:`${e}-ride`,tracks:o?[o]:[]}),a=k=>o?Number(r.getStateAtTime(k).values.get(e)?.get("y")??0):0,l=k=>{const y=n+a(k);return i.findIndex(M=>Math.abs(M.top-y)<.5)},c=(o?.keyframes??[]).map(k=>k.time),h=k=>{const y=T=>T<0?0:i[T].offset(k),M=l(k);if(M>=0)return y(M);if(Math.abs(a(k))<.5)return 0;const $=T=>l(T)>=0||Math.abs(a(T))<.5,E=[...c].reverse().find(T=>T<=k&&$(T)),A=c.find(T=>T>=k&&$(T));return E===void 0&&A===void 0?0:E===void 0?y(l(A)):A===void 0||A===E?y(l(E)):y(l(E))+(y(l(A))-y(l(E)))*(k-E)/(A-E)},d=i.flatMap(k=>k.windows),u=(k,y)=>d.some(M=>M.start<y&&M.end>k)||h(k)!==h(y),f=o?[...o.keyframes]:[{time:0,value:0}],g=[{...f[0],value:f[0].value+h(f[0].time)}],p=(k,y)=>{const M=new Set([y]);for(let $=k+s;$<y;$+=s)M.add($);for(const $ of d)for(const E of[$.start,$.end])E>k&&E<y&&M.add(E);for(const $ of[...M].sort((E,A)=>E-A))g.push({time:$,value:a($)+h($)})};for(let k=1;k<f.length;k++){const y=f[k-1].time,M=f[k].time;u(y,M)?p(y,M):g.push({...f[k],value:f[k].value+h(M)})}const m=f[f.length-1].time,b=Math.max(m,...d.map(k=>k.end));b>m&&p(m,b);const S={id:o?.id??`${e}-y`,target:e,property:"y",keyframes:g};return o?t.map(k=>k===o?S:k):[...t,S]}function De(t){const e=t.indexOf(":");return e<0?{kind:t,rest:""}:{kind:t.slice(0,e),rest:t.slice(e+1)}}function ve(t,e,n,s){const i=Object.keys(n.anchors).map(r=>De(r).kind),{kind:o}=De(e);return i.includes(o)?new Error(`${t}: no anchor "${e}"${s?`: ${s}`:""} (anchors: ${Object.keys(n.anchors).join(", ")})`):new Error(`${t}: ${ot("anchor",o,i)} (anchors: ${Object.keys(n.anchors).join(", ")})`)}function ns(t,e,n){return new Error(`${t}.edit: ${ot("edit",e,Object.keys(n.edits))}`)}function bt(t,e,n,s){return{x:t+n/2,y:e+s/2,left:t,right:t+n,top:e,bottom:e+s,width:n,height:s}}const Ld={background:"#1e1e2e",gutter:"#6c7086",text:"#cdd6f4",keyword:"#cba6f7",string:"#a6e3a1",number:"#fab387",comment:"#7f849c",highlight:"rgba(249, 226, 175, 0.22)",strike:"#f38ba8",font:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"},vi=["wipe","fly","blur"],ss={kind:"code",create:"codePanel({ code, language?, x, y, fontSize?, lineHeight?, width?, hidden? })",anchors:{box:"the whole panel","line:N":"line N’s text (lines count from 1): stand on top, point at x, y, swipe left to right","token:N:TEXT":"the first TEXT on line N (token:N#K:TEXT for the Kth): a word, which can come loose as a piece","spot:N:C":"a place in line N before column C (0 is before its first character); spot:N:C:W is W characters wide. Aim a put or a write here"},edits:{highlight:"line anchors; { at, duration?, on? }: tint lines (on: false clears)",strike:"line anchors; { at, duration? }: strike lines through, left to right",remove:"line anchors; { at, duration?, style?: wipe | fly | blur, from?: left | right, close? }: take lines away; the lines below close the gap",type:"line anchors given in `hidden`; { at, duration? }: type them in",insert:"a spot; { at, text, duration? }: type new text into the line there; the line makes room",write:"a token; { at, text, duration? }: write new text into the word’s place",drop:"a token; { at, into: a spot, duration? }: put the word into a line there",move:"a token; { at, to: an anchor name or { x, y }, duration? }: move the word there",fling:"a token; { at, velocity?, spin?, gravity?, duration? }: throw or kick the word away on a spinning arc"}},tb=.9,eb=8;function nb(t){const e={...Ld,...t.theme},n=t.code.replace(/\t/g," ").replace(/\n$/,"").split(`
56
+ `),s=t.fontSize??16,i=(t.lineHeight??1.6)*s,o=(t.charWidth??.6)*s,r=t.padding??12,a=t.lineNumbers===!1?0:(String(n.length).length+2)*o,l=Math.max(1,...n.map(_=>_.length)),c=t.width??r*2+a+l*o,h=r*2+n.length*i,d=t.x+r+a,u=new Set(t.hidden??[]),f=t.language??"plain";if(!Si.includes(f))throw new Error(`codePanel: ${ot("language",f,Si)}`);const g=n.map(_=>Dd(_,f).flatMap(L=>Array.from(L.text,()=>e[L.kind]))),p=ts(),m=es(p),b=[],S=new Map,k=[],y=[],M=_=>{if(!Number.isInteger(_)||_<1||_>n.length)throw new Error(`codePanel: no line ${_} (it has ${n.length})`)},$=p.tween,E=p.last,A=(_,L,N,x,R,q=300)=>{M(_),$(`line.${_}.${L}`,N,x,R,q)},T=(_,L)=>b.filter(N=>N.line<_&&N.closed<=L).length,I=bt,v=_=>t.y+r+(_-1)*i,P=_=>Array.isArray(_)?_:[_],H=(_,L,N)=>{let x=-1;for(let R=0;R<N;R++)if(x=n[_-1].indexOf(L,x+1),x<0)throw new Error(`codePanel: line ${_} has no ${N>1?`${N}th `:""}"${L}"`);return x},O={};n.forEach((_,L)=>{const N=L+1;O[`line.${N}.highlight`]=0,O[`line.${N}.strike`]=0,O[`line.${N}.wipe`]=0,O[`line.${N}.reveal`]=u.has(N)?0:1,O[`line.${N}.shift`]=0});const C={type:"custom",x:t.x,y:t.y,width:c,height:h,props:O,about:{kind:"code panel",summary:`${n.length} lines of ${f} code. Its lines and words are places in the scene (line(), token(), spot()); its edits are methods that record tracks (tracks()).`,get props(){return ib(Object.keys(O))},actions:Br},draw(_,L){const N=L.props??{},x=Y=>Number(N[Y]??O[Y]),R=r+a,q=Y=>r+(Y-1)*i-x(`line.${Y}.shift`)*i;_.fillStyle=e.background,Nd(_,0,0,c,h,8),_.fill(),_.font=`${s}px ${e.font}`,_.textBaseline="middle",_.textAlign="left";const U=(Y,Z,nt,F,z)=>{const K=n[Y-1];for(let V=Z;V<nt;V++)K[V]!==" "&&(_.fillStyle=g[Y-1][V],_.fillText(K[V],F+(V-Z)*o,z))};_.save(),Nd(_,0,0,c,h,8),_.clip(),n.forEach((Y,Z)=>{const nt=Z+1,F=x(`line.${nt}.wipe`);if(F>=1)return;const z=q(nt),K=z+i/2,V=Math.max(1,Y.length)*o,Q=Math.round(x(`line.${nt}.reveal`)*Y.length),tt=S.get(nt)??{style:"wipe",from:"left"};_.save(),F>0&&sb(_,tt,F,{left:R-a,top:z,width:a+V+o,height:i},c);const st=x(`line.${nt}.highlight`);st>0&&(_.globalAlpha*=Math.min(1,st),_.fillStyle=e.highlight,_.fillRect(R-o/2,z,V+o,i),_.globalAlpha/=Math.min(1,st)),a>0&&Q>0&&(_.fillStyle=e.gutter,_.textAlign="right",_.fillText(String(nt),R-o,K),_.textAlign="left");const pt=[...k.filter(J=>J.line===nt).map(J=>({column:J.column,length:J.text.length,piece:J,insert:void 0})),...y.filter(J=>J.line===nt).map(J=>({column:J.column,length:0,piece:void 0,insert:J}))].sort((J,kt)=>J.column-kt.column||J.length-kt.length);let ht=0,rt=R;for(const J of pt){U(nt,ht,Math.min(J.column,Q),rt,K),rt+=(J.column-ht)*o;let kt=J.length,gt="";if(J.piece){const X=J.piece.written??"",G=x(`piece.${J.piece.id}.write`);X&&G>0?(gt=X.slice(0,Math.round(G*X.length)),kt=J.length+(X.length-J.length)*Math.min(1,G*2)):kt=J.length*(1-x(`piece.${J.piece.id}.away`))}else J.insert&&(kt=J.insert.chars*x(`insert.${J.insert.id}.open`),J.insert.text&&(gt=J.insert.text.slice(0,Math.round(x(`insert.${J.insert.id}.type`)*J.insert.text.length))));_.fillStyle=e.text;for(let X=0;X<gt.length;X++)gt[X]!==" "&&_.fillText(gt[X],rt+X*o,K);rt+=kt*o,ht=J.column+J.length}U(nt,ht,Math.max(ht,Q),rt,K);const wt=x(`line.${nt}.strike`);wt>0&&(_.strokeStyle=e.strike,_.lineWidth=Math.max(1.5,s/10),_.beginPath(),_.moveTo(R,K),_.lineTo(R+V*Math.min(1,wt),K),_.stroke()),_.restore()});for(const Y of k){const Z=x(`piece.${Y.id}.opacity`);if(Z<=0||x(`line.${Y.line}.wipe`)>=1)continue;const nt=R+(Y.column+Y.text.length/2)*o+x(`piece.${Y.id}.x`),F=q(Y.line)+i/2+x(`piece.${Y.id}.y`);_.save(),_.globalAlpha=Math.min(1,Z),_.translate(nt,F),_.rotate(x(`piece.${Y.id}.rotate`)*Math.PI/180),U(Y.line,Y.column,Y.column+Y.text.length,-Y.text.length*o/2,0),_.restore()}_.restore()}},j=_=>{const{kind:L,rest:N}=De(_),x=R=>ve("codePanel",_,ss,R);if(L==="box"){if(N)throw x("box takes no arguments");return{kind:L}}if(L==="line"){if(!/^\d+$/.test(N))throw x("write it line:N");return{kind:L,n:Number(N)}}if(L==="token"){const R=/^(\d+)(?:#(\d+))?:(.+)$/.exec(N);if(!R)throw x("write it token:N:TEXT, or token:N#K:TEXT for the Kth");return{kind:L,n:Number(R[1]),occurrence:R[2]?Number(R[2]):1,text:R[3]}}if(L==="spot"){const R=/^(\d+):(\d+)(?::(\d+))?$/.exec(N);if(!R)throw x("write it spot:N:C, or spot:N:C:W for W characters");return{kind:L,n:Number(R[1]),column:Number(R[2]),width:R[3]?Number(R[3]):1}}throw x()},D=(_,L,N,x=!1)=>{const R=Array.isArray(L)?L:[L];if(R.length===0||x&&R.length>1)throw new Error(`codePanel.edit: ${_} takes ${x?"one":"at least one"} ${N} anchor`);return R.map(q=>{const U=j(q);if(U.kind!==N)throw new Error(`codePanel.edit: ${_} takes ${N} anchors (${N}:…), not "${q}"`);return U})},W=(_,L)=>{if(typeof L.text!="string")throw new Error(`codePanel.edit: ${_} needs \`text\` (the text to write)`);return L.text},B={kind:"code",about:ss,target:C,lines:n,box:I(t.x,t.y,c,h),line(_,L=1/0){return M(_),I(d,v(_)-T(_,L)*i,Math.max(1,n[_-1].length)*o,i)},token(_,L,N=1,x=1/0){M(_);const R=H(_,L,N);return I(d+R*o,v(_)-T(_,x)*i,L.length*o,i)},highlight(_,L){for(const N of P(_)){const x=E(`line.${N}.highlight`,0);A(N,"highlight",x,L.on===!1?0:1,L,200)}return B},strike(_,L){for(const N of P(_))A(N,"strike",E(`line.${N}.strike`,0),1,L);return B},remove(_,L){const N=P(_),x=L.style??"wipe";if(!vi.includes(x))throw new Error(`codePanel.remove: ${ot("style",x,vi)}`);const R=x==="wipe"?300:450,q=L.at+(L.duration??R),U=L.close??250;for(const Y of N)A(Y,"wipe",0,1,{...L,easing:L.easing??(x==="fly"?"ease-in":void 0)},R),S.set(Y,{style:x,from:L.from??"left"}),b.push({line:Y,closed:q+U});for(let Y=1;Y<=n.length;Y++){if(N.includes(Y))continue;const Z=N.filter(F=>F<Y).length;if(Z===0)continue;const nt=E(`line.${Y}.shift`,0);A(Y,"shift",nt,nt+Z,{at:q,duration:U,easing:"ease-in-out"})}return B},type(_,L){return A(_,"reveal",0,1,{duration:n[_-1].length*45,...L}),B},piece(_,L,N=1){if(typeof _=="string"){const Y=j(_);if(Y.kind!=="token")throw new Error(`codePanel.piece: a piece is a word, token:N:TEXT, not "${_}"`);return B.piece(Y.n,Y.text,Y.occurrence)}const x=_;if(L===void 0)throw new Error('codePanel.piece: which word? piece(n, text) or piece("token:N:TEXT")');M(x);const R=H(x,L,N),q=k.find(Y=>Y.line===x&&Y.column===R&&Y.text===L);if(q)return q;if(k.some(Y=>Y.line===x&&R<Y.column+Y.text.length&&Y.column<R+L.length))throw new Error(`codePanel: "${L}" on line ${x} overlaps another piece`);const U={id:k.length+1,line:x,column:R,text:L,home:B.token(x,L,N,0)};k.push(U);for(const Y of["x","y","rotate","write","away"])O[`piece.${U.id}.${Y}`]=0;return O[`piece.${U.id}.opacity`]=1,U},follow(_,L){return m.follow(_,L),B},fling(_,L){return m.fling(_,L),B},move(_,L){return m.move(_,L),B},write(_,L,N){return _.written=L,$(`piece.${_.id}.write`,0,1,{duration:Math.max(1,L.length)*70,...N}),B},spot(_,L,N=1,x=1/0){M(_);const R=y.filter(q=>q.line===_&&q.column<=L&&q.at<=x).reduce((q,U)=>q+U.chars,0);return I(d+(L+R)*o,v(_)-T(_,x)*i,N*o,i)},insert(_,L,N,x){M(_);const R={id:y.length+1,line:_,column:L,chars:N.length,text:N,at:x.at};y.push(R),O[`insert.${R.id}.open`]=0,O[`insert.${R.id}.type`]=0;const q=x.duration??N.length*70;return $(`insert.${R.id}.open`,0,1,{at:x.at,duration:q*.6,easing:"ease-out"}),$(`insert.${R.id}.type`,0,1,{at:x.at,duration:q}),B},drop(_,L,N,x){M(L);const R=x.duration??250,q=L===_.line,U=x.easing??(q?"linear":"ease-out"),Y=B.landing(_,L,N,x.at),Z={id:y.length+1,line:L,column:N,chars:_.text.length,at:x.at};return y.push(Z),O[`insert.${Z.id}.open`]=0,$(`insert.${Z.id}.open`,0,1,{at:x.at,duration:R,easing:q?U:"ease-out"}),$(`piece.${_.id}.away`,E(`piece.${_.id}.away`,0),1,{at:x.at,duration:R,easing:q?U:"ease-in-out"}),m.cutAfter(_,x.at),B.move(_,{at:x.at,duration:R,easing:U,to:{x:Y.x,y:Y.y}}),$(`piece.${_.id}.rotate`,p.valueAt(`piece.${_.id}.rotate`,x.at),0,{at:x.at,duration:R}),B},landing(_,L,N,x=1/0){const R=B.spot(L,N,_.text.length,x),q=L===_.line&&N>_.column?_.text.length*o:0;return I(R.left-q,R.top,R.width,R.height)},ride(_,L,N){const x=n.map((R,q)=>{const U=p.keys(`line.${q+1}.shift`)??[];return{top:v(q+1),offset:Y=>-wi(U,Y)*i,windows:ki(U)}});return jr(_,L,{ground:N.ground,every:N.every??Ne,floors:x})},tracks:p.tracks,anchor(_,L=1/0){const N=j(_);return N.kind==="box"?B.box:N.kind==="line"?B.line(N.n,L):N.kind==="token"?B.token(N.n,N.text,N.occurrence,L):B.spot(N.n,N.column,N.width,L)},edit(_,L,N){const x=()=>D(_,L,"line").map(R=>R.n);if(_==="highlight")return B.highlight(x(),N);if(_==="strike")return B.strike(x(),N);if(_==="remove")return B.remove(x(),N);if(_==="type"){for(const R of x())B.type(R,N);return B}if(_==="insert"){const[R]=D(_,L,"spot",!0);return B.insert(R.n,R.column,W(_,N),N)}if(_==="write"||_==="drop"||_==="move"||_==="fling"){const[R]=D(_,L,"token",!0),q=B.piece(R.n,R.text,R.occurrence);if(_==="write")return B.write(q,W(_,N),N);if(_==="fling")return B.fling(q,N);if(_==="drop"){const Y=typeof N.into=="string"?j(N.into):void 0;if(Y?.kind!=="spot")throw new Error("codePanel.edit: drop needs `into`, a spot anchor (spot:N:C)");return B.drop(q,Y.n,Y.column,N)}const U=typeof N.to=="string"?B.anchor(N.to,N.at):N.to;if(!U||typeof U.x!="number"||typeof U.y!="number")throw new Error("codePanel.edit: move needs `to`, an anchor name or { x, y }");return B.move(q,{...N,to:U})}throw ns("codePanel",_,ss)}};return B}function sb(t,e,n,s,i){if(e.style==="wipe"){t.beginPath(),e.from==="right"?t.rect(s.left,s.top,s.width*(1-n),s.height):t.rect(s.left+n*s.width,s.top,s.width*(1-n),s.height),t.clip();return}const o=eb*n;if(o>.2&&"filter"in t&&(t.filter=`blur(${o.toFixed(1)}px)`),t.globalAlpha*=1-n,e.style==="fly"){const r=e.from==="right"?-1:1;t.translate(r*n*tb*i,0),t.rotate(r*n*.08)}else{const r=1+.08*n,a=s.left+s.width/2,l=s.top+s.height/2;t.translate(a,l),t.scale(r,r),t.translate(-a,-l)}}const Br={highlight:"highlight(n | n[], { at, duration?, on? }): tint lines (on: false clears)",strike:"strike(n | n[], { at, duration? }): strike lines through, left to right",remove:"remove(n | n[], { at, duration?, style?: wipe | fly | blur, from?: left | right, close? }): take lines away; the lines below close the gap",type:"type(n, { at, duration? }): type in a line given in `hidden`",piece:"piece(n, text, occurrence?): make a word a piece that can come loose (returns it, with its home box)",follow:"follow(piece, path): carry a piece along timed points (handPath() gives a hand’s)",fling:"fling(piece, { at, velocity?, spin?, gravity?, duration? }): throw or kick a piece away on a spinning arc",move:"move(piece, { at, to: { x, y }, duration?, easing? }): move a piece’s centre to a point",write:"write(piece, text, { at, duration? }): type new text into a piece’s place",insert:"insert(n, column, text, { at, duration? }): type new text into a line; the line makes room",drop:"drop(piece, n, column, { at, duration? }): put a piece into a line (into its own line it slides, the text closing behind it)",ride:"ride(tracks, figureId, { ground }): a figure’s tracks with it carried by the line it stands on"};function ib(t){const e=[[/^line\.\d+\.highlight$/,{description:"How much the line is tinted",unit:"0..1",min:0,max:1}],[/^line\.\d+\.strike$/,{description:"How far the strike-through has drawn",unit:"0..1",min:0,max:1}],[/^line\.\d+\.wipe$/,{description:"How far the line has gone (wiped, flown off or blurred)",unit:"0..1",min:0,max:1}],[/^line\.\d+\.reveal$/,{description:"How much of the line is typed in",unit:"0..1",min:0,max:1}],[/^line\.\d+\.shift$/,{description:"How many rows the line has moved up",unit:"rows"}],[/^piece\.\d+\.(x|y)$/,{description:"The piece moved from its home",unit:"px"}],[/^piece\.\d+\.rotate$/,{description:"The piece turned",unit:"degrees"}],[/^piece\.\d+\.opacity$/,{description:"How opaque the piece is",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.write$/,{description:"How much of the text written into its place is typed",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.away$/,{description:"How far its old place has closed",unit:"0..1",min:0,max:1}],[/^insert\.\d+\.open$/,{description:"How much room the insert has opened",unit:"0..1",min:0,max:1}],[/^insert\.\d+\.type$/,{description:"How much of the inserted text is typed",unit:"0..1",min:0,max:1}]],n={};for(const s of t){const i=e.find(([o])=>o.test(s));i&&(n[s]=i[1])}return n}function Nd(t,e,n,s,i,o){t.beginPath(),t.moveTo(e+o,n),t.arcTo(e+s,n,e+s,n+i,o),t.arcTo(e+s,n+i,e,n+i,o),t.arcTo(e,n+i,e,n,o),t.arcTo(e,n,e+s,n,o),t.closePath()}const Mi={go:["break","case","chan","const","continue","default","defer","else","fallthrough","for","func","go","goto","if","import","interface","map","package","range","return","select","struct","switch","type","var","nil","true","false"],rust:["as","async","await","break","const","continue","crate","else","enum","extern","false","fn","for","if","impl","in","let","loop","match","mod","move","mut","pub","ref","return","self","Self","static","struct","super","trait","true","type","unsafe","use","where","while","Some","None","Ok","Err"],csharp:["abstract","async","await","base","bool","break","case","catch","class","const","continue","default","do","else","enum","false","finally","for","foreach","if","in","int","interface","internal","is","namespace","new","null","object","out","override","private","protected","public","readonly","ref","return","sealed","static","string","struct","switch","this","throw","true","try","using","var","virtual","void","while"],javascript:["async","await","break","case","catch","class","const","continue","default","delete","do","else","export","extends","false","finally","for","function","if","import","in","instanceof","let","new","null","of","return","static","super","switch","this","throw","true","try","typeof","undefined","var","void","while","yield"],typescript:[],python:["and","as","assert","async","await","break","class","continue","def","del","elif","else","except","False","finally","for","from","global","if","import","in","is","lambda","None","nonlocal","not","or","pass","raise","return","True","try","while","with","yield"],plain:[]};Mi.typescript=[...Mi.javascript,"enum","interface","type","implements","private","public","readonly","keyof","as","declare","namespace"];const Si=Object.keys(Mi),ob={go:"//",rust:"//",csharp:"//",javascript:"//",typescript:"//",python:"#",plain:null};function Dd(t,e){const n=new Set(Mi[e]),s=ob[e],i=[],o=(a,l)=>{const c=i[i.length-1];c&&c.kind===l?c.text+=a:i.push({text:a,kind:l})};let r=0;for(;r<t.length;){const a=t[r];if(e!=="plain"&&s&&t.startsWith(s,r)){o(t.slice(r),"comment");break}if(e!=="plain"&&(a==='"'||a==="'"||a==="`")){let h=r+1;for(;h<t.length&&t[h]!==a;)h+=t[h]==="\\"?2:1;o(t.slice(r,h+1),"string"),r=h+1;continue}const l=/^[A-Za-z_][A-Za-z0-9_]*/.exec(t.slice(r));if(l){o(l[0],n.has(l[0])?"keyword":"text"),r+=l[0].length;continue}const c=/^\d[\d_.]*/.exec(t.slice(r));if(c&&e!=="plain"){o(c[0],"number"),r+=c[0].length;continue}o(a,"text"),r++}return i}const Fd='"Segoe Print", "Bradley Hand", "Comic Sans MS", "Chalkboard SE", cursive',is={whiteboard:{background:"#f7f7f2",frame:"#b8bcc4",ink:"#1f2a44",colors:{ink:"#1f2a44",red:"#d03b3b",blue:"#2f6fd0",green:"#2e9a52",orange:"#e07b1a"},font:Fd,stroke:.09,opacity:1},chalkboard:{background:"#2f4a3a",frame:"#7a5a3a",ink:"#f1f1e8",colors:{ink:"#f1f1e8",red:"#f2a3a3",blue:"#a8c8f0",green:"#b7e4a8",orange:"#f5c98a",yellow:"#f6ef9a"},font:Fd,stroke:.1,opacity:.9}},Wr=["circle","box","underline","arrow"],ne={kind:"board",create:"whiteboard({ x, y, width, height, theme?: whiteboard | chalkboard, fontSize?, items: [{ id, text, at: [x, y], size?, color?, hidden? } | { id, mark: circle | box | underline | arrow, around? | from?, to?, color?, hidden? }] })",anchors:{box:"the whole board","text:ID":"a text item: write along it from left to right, point at it","term:ID:TEXT":"the first TEXT in text ID (term:ID#K:TEXT for the Kth): a term, which can come loose as a piece","mark:ID":"a mark (circle, box, underline or arrow)"},edits:{write:"text anchors given `hidden`; { at, duration? }: write them in by hand. Or a term; { at, text, duration? }: write new text in its place (move or erase the term first)",draw:"mark anchors given `hidden`; { at, duration? }: draw them in",erase:"text, term or mark anchors; { at, duration? }: wipe them off",strike:"text or term anchors; { at, duration? }: cross them out",move:"a term; { at, to: an anchor name or { x, y }, duration? }: move the term there",fling:"a term; { at, velocity?, spin?, gravity?, duration? }: throw or knock the term off on a spinning arc"}},jd=90,Bd=300,rb=.3;function ab(t){const e=typeof t.theme=="string"?t.theme:"whiteboard";if(!(e in is))throw new Error(`whiteboard: ${ot("theme",e,Object.keys(is))}`);const n=typeof t.theme=="object"?{...is.whiteboard,...t.theme}:is[e],s=t.fontSize??28,i=t.charWidth??.55,o=y=>y===void 0?n.ink:n.colors[y]??y,r=y=>bt(t.x+y.left,t.y+y.top,y.width,y.height),a=ts(),l=es(a),c={},h=new Map,d=[],u=[],f=(y,M,$,E)=>{const A=h.get(y);if(!A||A.kind!=="text")throw ve("whiteboard",E,ne,`there is no text "${y}" (texts: ${g().join(", ")||"none"})`);let T=-1;for(let v=0;v<$;v++)if(T=A.item.text.indexOf(M,T+1),T<0)throw ve("whiteboard",E,ne,`text "${y}" has no ${$>1?`${$}th `:""}"${M}"`);const I=A.size*i;return{column:T,box:bt(A.box.left+T*I,A.box.top,M.length*I,A.box.height)}},g=()=>[...h.values()].filter(y=>y.kind==="text").map(y=>y.item.id),p=y=>{const{kind:M,rest:$}=De(y),E=A=>ve("whiteboard",y,ne,A);if(M==="box"){if($)throw E("box takes no arguments");return{kind:M}}if(M==="text"||M==="mark"){if(!$)throw E(`write it ${M}:ID`);return{kind:M,id:$}}if(M==="term"){const A=/^([^:#]+)(?:#(\d+))?:(.+)$/.exec($);if(!A)throw E("write it term:ID:TEXT, or term:ID#K:TEXT for the Kth");return{kind:M,id:A[1],occurrence:A[2]?Number(A[2]):1,text:A[3]}}throw E()},m=y=>{const M=p(y);if(M.kind==="box")return bt(0,0,t.width,t.height);if(M.kind==="term")return f(M.id,M.text,M.occurrence,y).box;const $=h.get(M.id);if(!$||$.kind!==M.kind){const E=[...h.values()].filter(A=>A.kind===M.kind).map(A=>A.item.id);throw ve("whiteboard",y,ne,`there is no ${M.kind} "${M.id}" (${M.kind}s: ${E.join(", ")||"none"})`)}return $.box};for(const y of t.items??[]){if(!y||typeof y.id!="string"||!y.id||/[:#]/.test(y.id))throw new Error(`whiteboard: every item needs an \`id\` without ":" or "#" (got ${JSON.stringify(y?.id)})`);if(h.has(y.id))throw new Error(`whiteboard: two items are called "${y.id}"`);if("text"in y){if(!Array.isArray(y.at)||y.at.length!==2||!y.at.every(T=>typeof T=="number"))throw new Error(`whiteboard: text "${y.id}" needs \`at\`, [x, y] from the board's top-left`);const E=y.size??s,A=bt(y.at[0],y.at[1],Math.max(1,y.text.length)*E*i,E*1.3);h.set(y.id,{kind:"text",item:y,size:E,color:o(y.color),box:A}),c[`text.${y.id}.write`]=y.hidden?0:1,c[`text.${y.id}.erase`]=0;continue}if(!Wr.includes(y.mark))throw new Error(`whiteboard: mark "${y.id}": ${ot("mark",y.mark,Wr)}`);const M=y.mark==="arrow"?["from","to"]:["around"];for(const E of M)if(typeof y[E]!="string")throw new Error(`whiteboard: ${y.mark} "${y.id}" needs \`${E}\`, a place on the board (an item before it)`);const $=lb(y,m,s);h.set(y.id,{kind:"mark",item:y,color:o(y.color),points:$,box:hb($)}),c[`mark.${y.id}.draw`]=y.hidden?0:1,c[`mark.${y.id}.erase`]=0}const b=y=>d.filter(M=>M.item===y),S={type:"custom",x:t.x,y:t.y,width:t.width,height:t.height,props:c,about:{kind:"whiteboard",summary:`A board with ${h.size} items. Its texts, terms and marks are places in the scene (anchor()); its edits record tracks (edit(), tracks()).`,get props(){return ub(Object.keys(c))},actions:ne.edits},draw(y,M){const $=M.props??{},E=A=>Number($[A]??c[A]??0);y.save(),y.fillStyle=n.background,db(y,0,0,t.width,t.height,10),y.fill(),y.lineWidth=Math.max(4,t.width*.012),y.strokeStyle=n.frame,y.stroke(),y.textAlign="center",y.textBaseline="middle",y.lineCap="round",y.lineJoin="round",y.globalAlpha=n.opacity;for(const A of h.values()){if(y.save(),qr(y,A.box,E(`${A.kind}.${A.item.id}.erase`)),A.kind==="text"){const T=b(A.item.id),I=E(`text.${A.item.id}.write`)*A.item.text.length;y.font=`${A.size}px ${n.font}`,y.fillStyle=A.color;for(let v=0;v<Math.ceil(I);v++)A.item.text[v]===" "||T.some(P=>v>=P.column&&v<P.column+P.text.length)||(y.globalAlpha=n.opacity*Math.min(1,I-v),y.fillText(A.item.text[v],A.box.left+(v+.5)*A.size*i,A.box.y))}else qd(y,A.points,E(`mark.${A.item.id}.draw`),A.color,s*n.stroke,A.item.mark==="arrow");y.restore()}for(const A of u){const T=E(`strike.${A.id}.draw`);if(T<=0)continue;const{box:I}=A,v=I.height*.15;qd(y,[{x:I.left-3,y:I.y+v},{x:I.right+3,y:I.y-v}],T,n.colors.red??n.ink,s*n.stroke*.8,!1)}for(const A of d){const T=h.get(A.item),I=T.size*i;y.font=`${T.size}px ${n.font}`,y.fillStyle=T.color;const v=A.written;if(v){const C=E(`piece.${A.id}.write`)*v.length,j=A.home.x-t.x-v.length*I/2;for(let D=0;D<Math.ceil(C);D++)v[D]!==" "&&(y.globalAlpha=n.opacity*Math.min(1,C-D),y.fillText(v[D],j+(D+.5)*I,A.home.y-t.y))}const P=E(`piece.${A.id}.opacity`)*Math.min(1,E(`text.${A.item}.write`)*T.item.text.length-A.column);if(P<=0)continue;y.save();const H={x:A.home.x-t.x,y:A.home.y-t.y},O={x:E(`piece.${A.id}.x`),y:E(`piece.${A.id}.y`)};qr(y,bt(H.x+O.x-A.home.width/2,H.y+O.y-A.home.height/2,A.home.width,A.home.height),E(`piece.${A.id}.erase`)),Math.hypot(O.x,O.y)<1&&qr(y,T.box,E(`text.${A.item}.erase`)),y.globalAlpha=n.opacity*Math.min(1,P),y.translate(H.x+O.x,H.y+O.y),y.rotate(E(`piece.${A.id}.rotate`)*Math.PI/180);for(let C=0;C<A.text.length;C++)A.text[C]!==" "&&y.fillText(A.text[C],(C+.5-A.text.length/2)*I,0);y.restore()}y.restore()}},k={kind:"board",about:ne,target:S,box:bt(t.x,t.y,t.width,t.height),anchor(y){return r(m(y))},piece(y){const M=p(y);if(M.kind!=="term")throw new Error(`whiteboard.piece: a piece is a term, term:ID:TEXT, not "${y}"`);const{column:$,box:E}=f(M.id,M.text,M.occurrence,y),A=d.find(I=>I.item===M.id&&I.column===$&&I.text===M.text);if(A)return A;if(d.some(I=>I.item===M.id&&$<I.column+I.text.length&&I.column<$+M.text.length))throw new Error(`whiteboard: "${M.text}" in "${M.id}" overlaps another piece`);const T={id:d.length+1,item:M.id,column:$,text:M.text,home:r(E)};d.push(T);for(const I of["x","y","rotate","erase","write"])c[`piece.${T.id}.${I}`]=0;return c[`piece.${T.id}.opacity`]=1,T},edit(y,M,$){const E=Array.isArray(M)?M:[M];if(E.length===0)throw new Error(`whiteboard.edit: ${y} takes at least one anchor`);const A=E.map(v=>({name:v,anchor:p(v)}));for(const{name:v}of A)m(v);const T=(v,P=!1)=>{const H=A.find(O=>!v.includes(O.anchor.kind));if(H)throw new Error(`whiteboard.edit: ${y} takes ${v.join(" or ")} anchors, not "${H.name}"`);if(P&&A.length>1)throw new Error(`whiteboard.edit: ${y} takes one ${v.join(" or ")} anchor`)},I=()=>k.piece(A[0].name);if(y==="write"){if(A.some(v=>v.anchor.kind==="term")){if(T(["term"],!0),typeof $.text!="string")throw new Error("whiteboard.edit: write into a term needs `text` (the new text)");const v=I();return v.written=$.text,a.tween(`piece.${v.id}.write`,0,1,{duration:Math.max(Bd,$.text.length*jd),...$}),k}T(["text"]);for(const{anchor:v}of A){const P=v.id,H=h.get(P).item.text;a.tween(`text.${P}.write`,0,1,{duration:Math.max(Bd,H.length*jd),...$})}return k}if(y==="draw"){T(["mark"]);for(const{anchor:v}of A)a.tween(`mark.${v.id}.draw`,0,1,{duration:500,...$});return k}if(y==="erase"){T(["text","term","mark"]);for(const v of A){const P=v.anchor.kind==="term"?`piece.${k.piece(v.name).id}.erase`:`${v.anchor.kind}.${v.anchor.id}.erase`;a.tween(P,0,1,{duration:400,...$})}return k}if(y==="strike"){T(["text","term"]);for(const v of A){const P={id:u.length+1,box:m(v.name)};u.push(P),c[`strike.${P.id}.draw`]=0,a.tween(`strike.${P.id}.draw`,0,1,{duration:250,...$})}return k}if(y==="move"){T(["term"],!0);const v=typeof $.to=="string"?k.anchor($.to):$.to;if(!v||typeof v.x!="number"||typeof v.y!="number")throw new Error("whiteboard.edit: move needs `to`, an anchor name or { x, y }");return k.move(I(),{...$,to:v})}if(y==="fling")return T(["term"],!0),k.fling(I(),$);throw ns("whiteboard",y,ne)},follow(y,M){return l.follow(y,M),k},fling(y,M){return l.fling(y,M),k},move(y,M){return l.move(y,M),k},ride(y){return y},tracks:a.tracks};return k}function lb(t,e,n){const s=$e(qt(t.id)),i=g=>(s.next()*2-1)*g,o=n*rb;if(t.mark==="arrow"){const g=e(t.from),p=e(t.to),m=Wd(g,p,o*.6),b=Wd(p,g,o*.6),S=Math.hypot(b.x-m.x,b.y-m.y)*(.06+i(.04)),k=cb(m,b),y={x:(m.x+b.x)/2+k.x*S,y:(m.y+b.y)/2+k.y*S},M=[];for(let $=0;$<=24;$++){const E=$/24;M.push({x:(1-E)**2*m.x+2*(1-E)*E*y.x+E*E*b.x,y:(1-E)**2*m.y+2*(1-E)*E*y.y+E*E*b.y})}return M}const r=e(t.around);if(t.mark==="underline"){const g=r.bottom+o*.4;return[{x:r.left-o*.3,y:g+i(2)},{x:r.x,y:g+2+i(2)},{x:r.right+o*.5,y:g-1+i(3)}]}if(t.mark==="box"){const g=r.left-o,p=r.right+o,m=r.top-o*.6,b=r.bottom+o*.6,S=(y,M)=>({x:y+i(o*.2),y:M+i(o*.2)}),k=S(g,m);return[k,S(p,m),S(p,b),S(g,b),k,{x:k.x+o*.8,y:k.y+i(2)}]}const a=r.width/2+o,l=r.height/2+o*.6,c=-2.2+i(.3),h=s.next()*Math.PI*2,d=1.12,u=64,f=[];for(let g=0;g<=u*d;g++){const p=g/u,m=c+p*Math.PI*2,b=1+.035*Math.sin(p*Math.PI*4+h)+.06*p;f.push({x:r.x+Math.cos(m)*a*b,y:r.y+Math.sin(m)*l*b})}return f}function Wd(t,e,n){const s=e.x-t.x,i=e.y-t.y;if(s===0&&i===0)return{x:t.x,y:t.y};const o=Math.min(s===0?1/0:(t.width/2+n)/Math.abs(s),i===0?1/0:(t.height/2+n)/Math.abs(i));return{x:t.x+s*o,y:t.y+i*o}}function cb(t,e){const n=Math.hypot(e.x-t.x,e.y-t.y)||1;return{x:-(e.y-t.y)/n,y:(e.x-t.x)/n}}function hb(t){const e=t.map(o=>o.x),n=t.map(o=>o.y),s=Math.min(...e),i=Math.min(...n);return bt(s,i,Math.max(...e)-s,Math.max(...n)-i)}function qd(t,e,n,s,i,o){if(n<=0||e.length<2)return;const r=[0];for(let g=1;g<e.length;g++)r.push(r[g-1]+Math.hypot(e[g].x-e[g-1].x,e[g].y-e[g-1].y));const l=r[r.length-1]*Math.min(1,n/(o?.85:1));t.strokeStyle=s,t.lineWidth=i,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let g=1;g<e.length;g++){if(r[g]<=l){t.lineTo(e[g].x,e[g].y);continue}const p=(l-r[g-1])/(r[g]-r[g-1]||1);t.lineTo(e[g-1].x+(e[g].x-e[g-1].x)*p,e[g-1].y+(e[g].y-e[g-1].y)*p);break}if(t.stroke(),!o||n<=.85)return;const c=(n-.85)/.15,h=e[e.length-1],d=e[e.length-3]??e[0],u=Math.atan2(h.y-d.y,h.x-d.x),f=i*4.5*c;t.beginPath();for(const g of[-1,1])t.moveTo(h.x,h.y),t.lineTo(h.x-Math.cos(u+g*.45)*f,h.y-Math.sin(u+g*.45)*f);t.stroke()}function qr(t,e,n){if(n<=0)return;const s=8;t.beginPath(),t.rect(e.left-s+n*(e.width+s*2),e.top-s*4,(1-n)*(e.width+s*2),e.height+s*8),t.clip()}function db(t,e,n,s,i,o){t.beginPath(),t.moveTo(e+o,n),t.arcTo(e+s,n,e+s,n+i,o),t.arcTo(e+s,n+i,e,n+i,o),t.arcTo(e,n+i,e,n,o),t.arcTo(e,n,e+s,n,o),t.closePath()}function ub(t){const e=[[/^text\..+\.write$/,{description:"How much of the text is written",unit:"0..1",min:0,max:1}],[/^(text|mark)\..+\.erase$/,{description:"How far it has been wiped off, left to right",unit:"0..1",min:0,max:1}],[/^mark\..+\.draw$/,{description:"How much of the mark is drawn",unit:"0..1",min:0,max:1}],[/^strike\.\d+\.draw$/,{description:"How far the strike-through has drawn",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.(x|y)$/,{description:"The term moved from its home",unit:"px"}],[/^piece\.\d+\.rotate$/,{description:"The term turned",unit:"degrees"}],[/^piece\.\d+\.opacity$/,{description:"How opaque the term is",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.erase$/,{description:"How far the term has been wiped off",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.write$/,{description:"How much of the text written into its place is written",unit:"0..1",min:0,max:1}]],n={};for(const s of t){const i=e.find(([o])=>o.test(s));i&&(n[s]=i[1])}return n}const Kr=["bar","line"],os={light:{background:"#ffffff",text:"#3b4252",grid:"#d8dee9",color:"#4c7bd9",highlight:"#e8833a",font:'system-ui, -apple-system, "Segoe UI", sans-serif'},dark:{background:"#1e2230",text:"#cdd6f4",grid:"#3a4055",color:"#89b4fa",highlight:"#fab387",font:'system-ui, -apple-system, "Segoe UI", sans-serif'}},Fe={kind:"chart",create:"chart({ x, y, width, height, kind: bar | line, data: [{ id, label?, value, hidden? }], max?, title?, theme?: light | dark, decimals?, prefix?, suffix?, values? })",anchors:{box:"the whole chart","bar:ID":"a bar (bar charts), as it stands at the time: stand on its top (it carries a figure as it grows), point at it","point:ID":"a point on the line (line charts), as it stands at the time","label:ID":"its label under the axis","value:ID":"its value label, above it"},edits:{set:"bar or point anchors; { at, value, duration? }: animate to a new value; its value label counts along",show:"bar or point anchors given `hidden`; { at, duration?, on? }: grow a bar in from the axis, or draw the line out to a point (on: false takes it back)",highlight:"bar or point anchors; { at, duration?, on? }: colour it out (on: false clears)"}},fb=600,pb=500,gb=200;function mb(t){if(!Kr.includes(t.kind))throw new Error(`chart: ${ot("kind",t.kind,Kr)}`);const e=typeof t.theme=="string"?t.theme:"light";if(!(e in os))throw new Error(`chart: ${ot("theme",e,Object.keys(os))}`);const n=typeof t.theme=="object"?{...os.light,...t.theme}:os[e];if(!Array.isArray(t.data)||t.data.length===0)throw new Error("chart: `data` needs at least one { id, value }");const s=new Set;for(const v of t.data){if(typeof v?.id!="string"||!v.id||v.id.includes(":"))throw new Error(`chart: every datum needs an \`id\` without ":" (got ${JSON.stringify(v?.id)})`);if(s.has(v.id))throw new Error(`chart: two data are called "${v.id}"`);if(typeof v.value!="number"||!Number.isFinite(v.value))throw new Error(`chart: "${v.id}" needs a \`value\`, a number`);s.add(v.id)}const i=t.kind,o=i==="bar"?"bar":"point",r=t.max??Kd(Math.max(...t.data.map(v=>v.value))*1.1);if(!(r>0))throw new Error(`chart: \`max\` must be above 0 (got ${r})`);const a=Math.max(10,Math.min(16,t.height/20)),l={left:a*3.6,right:t.width-a,top:t.title?a*3:a*1.6,bottom:t.height-a*2.4},c=l.bottom-l.top,h=(l.right-l.left)/t.data.length,d=h*.6,u=Math.max(4,a*.35),f=c/r,g=new Map(t.data.map((v,P)=>[v.id,P])),p=v=>l.left+h*(g.get(v)+.5),m=ts(),b=es(m),S={};for(const v of t.data)S[`${o}.${v.id}.value`]=v.value,S[`${o}.${v.id}.show`]=v.hidden?0:1,S[`${o}.${v.id}.highlight`]=0;const k=(v,P)=>m.keys(v)?.length?wi(m.keys(v),P):S[v],y=(v,P)=>k(`${o}.${v}.value`,P)*(i==="bar"?k(`${o}.${v}.show`,P):1)*f,M=v=>{const{kind:P,rest:H}=De(v),O=C=>ve("chart",v,Fe,C);if(P==="box"){if(H)throw O("box takes no arguments");return{kind:"box"}}if(P==="bar"||P==="point"||P==="label"||P==="value"){if(!H)throw O(`write it ${P}:ID`);if(!g.has(H))throw O(`there is no "${H}" (data: ${[...g.keys()].join(", ")})`);if((P==="bar"||P==="point")&&P!==o)throw O(`a ${i} chart has ${o}s, not ${P}s: ${o}:${H}`);return{kind:P,id:H}}throw O()},$=(v,P)=>{if(v.kind==="box")return bt(0,0,t.width,t.height);const H=p(v.id),O=l.bottom-y(v.id,P);if(v.kind==="bar")return bt(H-d/2,O,d,l.bottom-O);if(v.kind==="point")return bt(H-u,O-u,u*2,u*2);if(v.kind==="label")return bt(H-h/2,l.bottom+a*.4,h,a*1.4);const C=O-(i==="line"?u:0)-a*.3;return bt(H-h/2,C-a*1.3,h,a*1.3)},E=v=>bt(t.x+v.left,t.y+v.top,v.width,v.height),A=v=>`${t.prefix??""}${v.toFixed(t.decimals??0)}${t.suffix??""}`,T={type:"custom",x:t.x,y:t.y,width:t.width,height:t.height,props:S,about:{kind:`${i} chart`,summary:`A ${i} chart of ${t.data.length} values (${t.data.map(v=>v.id).join(", ")}), scaled to ${r}. Its ${o}s and labels are places in the scene (anchor()); its edits record tracks (edit(), tracks()).`,props:Object.fromEntries(Object.keys(S).map(v=>[v,kb(v)])),actions:Fe.edits},draw(v,P){const H=P.props??{},O=D=>Number(H[D]??S[D]??0);v.save(),v.fillStyle=n.background,bb(v,0,0,t.width,t.height,8),v.fill(),v.font=`${a}px ${n.font}`,v.textBaseline="middle",t.title&&(v.fillStyle=n.text,v.textAlign="left",v.font=`600 ${a*1.2}px ${n.font}`,v.fillText(t.title,l.left,a*1.5),v.font=`${a}px ${n.font}`),v.lineWidth=1,v.textAlign="right";for(let D=0;D<=4;D++){const W=l.bottom-c*D/4;v.strokeStyle=n.grid,v.beginPath(),v.moveTo(l.left,W),v.lineTo(l.right,W),v.stroke(),v.fillStyle=n.text,v.globalAlpha=.7,v.fillText(yb(r*D/4),l.left-a*.5,W),v.globalAlpha=1}const C=D=>O(`${o}.${D}.value`)*(i==="bar"?O(`${o}.${D}.show`):1)*f,j=D=>Yd(n.color,n.highlight,O(`${o}.${D}.highlight`));i==="line"&&(v.lineWidth=Math.max(2,a*.2),v.lineJoin="round",v.lineCap="round",v.strokeStyle=n.color,v.beginPath(),t.data.forEach((D,W)=>{const B={x:p(D.id),y:l.bottom-C(D.id)},_=O(`point.${D.id}.show`);if(W===0){_>0&&v.moveTo(B.x,B.y);return}const L=t.data[W-1];if(O(`point.${L.id}.show`)<1||_<=0)return;const N={x:p(L.id),y:l.bottom-C(L.id)};v.lineTo(N.x+(B.x-N.x)*_,N.y+(B.y-N.y)*_)}),v.stroke()),v.textAlign="center";for(const D of t.data){const W=p(D.id),B=C(D.id),_=O(`${o}.${D.id}.show`);if(v.fillStyle=j(D.id),i==="bar"?B>.5&&(wb(v,W-d/2,l.bottom-B,d,B,Math.min(6,d/4)),v.fill()):_>0&&(v.beginPath(),v.arc(W,l.bottom-B,u*Math.min(1,_*1.5)*(1+.3*O(`point.${D.id}.highlight`)),0,Math.PI*2),v.fill()),v.fillStyle=n.text,v.fillText(D.label??D.id,W,l.bottom+a*1.1),t.values!==!1&&_>0){v.globalAlpha=Math.min(1,_*2),v.font=`600 ${a}px ${n.font}`,v.fillStyle=Yd(n.text,n.highlight,O(`${o}.${D.id}.highlight`));const L=l.bottom-B-(i==="line"?u:0)-a*.95;v.fillText(A(O(`${o}.${D.id}.value`)),W,L),v.font=`${a}px ${n.font}`,v.globalAlpha=1}}v.strokeStyle=n.text,v.lineWidth=1.5,v.beginPath(),v.moveTo(l.left,l.bottom),v.lineTo(l.right,l.bottom),v.stroke(),v.restore()}},I={kind:"chart",chartKind:i,about:Fe,target:T,max:r,box:bt(t.x,t.y,t.width,t.height),anchor(v,P=1/0){return E($(M(v),P))},piece(v){throw new Error(`chart: a chart has no pieces to come loose ("${v}"); change it with edit('set' | 'show' | 'highlight', …)`)},edit(v,P,H){const O=Array.isArray(P)?P:[P];if(O.length===0)throw new Error(`chart.edit: ${v} takes at least one anchor`);if(!(v in Fe.edits))throw ns("chart",v,Fe);const C=O.map(j=>{const D=M(j);if(D.kind!==o)throw new Error(`chart.edit: ${v} takes ${o} anchors (${o}:ID), not "${j}"`);return D.id});for(const j of C){const D=W=>`${o}.${j}.${W}`;if(v==="set"){if(typeof H.value!="number"||!Number.isFinite(H.value))throw new Error("chart.edit: set needs `value`, a number");m.tween(D("value"),k(D("value"),H.at),H.value,H,fb)}else v==="show"?m.tween(D("show"),k(D("show"),H.at),H.on===!1?0:1,H,pb):m.tween(D("highlight"),k(D("highlight"),H.at),H.on===!1?0:1,H,gb)}return I},follow(v,P){return b.follow(v,P),I},fling(v,P){return b.fling(v,P),I},move(v,P){return b.move(v,P),I},ride(v,P,H){if(i!=="bar")return v;const O=t.data.map(C=>{const j=y(C.id,0),D=[...ki(m.keys(`bar.${C.id}.value`)),...ki(m.keys(`bar.${C.id}.show`))];return{top:t.y+l.bottom-j,offset:W=>j-y(C.id,W),windows:D}});return jr(v,P,{ground:H.ground,every:H.every??Ne,floors:O})},tracks:m.tracks};return I}function Kd(t){if(!(t>0))return 1;const e=10**Math.floor(Math.log10(t));for(const n of[1,2,2.5,5,10])if(n*e>=t-1e-9)return n*e;return 10*e}function yb(t){return Number.isInteger(t)?String(t):String(Number(t.toFixed(2)))}function Yd(t,e,n){if(n<=0)return t;if(n>=1)return e;const s=r=>[1,3,5].map(a=>parseInt(r.slice(a,a+2),16));if(!/^#[0-9a-f]{6}$/i.test(t)||!/^#[0-9a-f]{6}$/i.test(e))return n<.5?t:e;const[i,o]=[s(t),s(e)];return`#${i.map((r,a)=>Math.round(r+(o[a]-r)*n).toString(16).padStart(2,"0")).join("")}`}function bb(t,e,n,s,i,o){t.beginPath(),t.moveTo(e+o,n),t.arcTo(e+s,n,e+s,n+i,o),t.arcTo(e+s,n+i,e,n+i,o),t.arcTo(e,n+i,e,n,o),t.arcTo(e,n,e+s,n,o),t.closePath()}function wb(t,e,n,s,i,o){const r=Math.min(o,i);t.beginPath(),t.moveTo(e,n+i),t.lineTo(e,n+r),t.arcTo(e,n,e+r,n,r),t.lineTo(e+s-r,n),t.arcTo(e+s,n,e+s,n+r,r),t.lineTo(e+s,n+i),t.closePath()}function kb(t){return t.endsWith(".value")?{description:"Its value (the bar’s height or the point’s, and its value label)",unit:"value"}:t.endsWith(".show")?{description:"How much of it is shown: a bar grown in from the axis, the line drawn out to the point",unit:"0..1",min:0,max:1}:{description:"How much it is coloured out",unit:"0..1",min:0,max:1}}const vb=(t,e,n)=>t.slice(Math.floor((t.length-1)*e),Math.ceil((t.length-1)*n)+1);function Mb(t={}){const e=t.shirt??"#e2493b",n=t.trousers??"#24476b",s=a=>a.lineWidth*.45,i=(a,l,c)=>{const h=a.parts[`leg.${c}`].points;l.shape(Wn(h,a.height*.08,a.height*.05),n,s(a))},o=(a,l)=>{const c=a.chains.spine,h=c[0],d=c[c.length-1],u={x:h.x-(d.x-h.x)*.25,y:h.y-(d.y-h.y)*.25};l.shape(Wn([u,...a.parts.spine.points],a.height*.15,a.height*.14),e,s(a))},r=(a,l,c)=>{const h=a.parts[`arm.${c}`].points,d=h[0],u=a.chains.spine[a.chains.spine.length-1],g=[{x:d.x+(u.x-d.x)*.45,y:d.y+(u.y-d.y)*.45},...vb(h,0,.45)],p=Wn(g,a.height*.085,a.height*.06),m=g.length,b=p.slice(0,m),S=p.slice(m).reverse();l.shape(p,e,0);const k=$=>Math.hypot($[1].x-u.x,$[1].y-u.y),[y,M]=k(b)>k(S)?[b,S]:[S,b];l.line(y.slice(1),s(a)),l.line(M.slice(Math.ceil(m*.45)),s(a)),l.line([b[m-1],S[m-1]],s(a))};return{parts:{"leg.left":{over:(a,l,c)=>i(l,c,"left")},"leg.right":{over:(a,l,c)=>i(l,c,"right")},spine:{over:(a,l,c)=>o(l,c)},"arm.left":{over:(a,l,c)=>r(l,c,"left")},"arm.right":{over:(a,l,c)=>r(l,c,"right")}}}}const je={full:{anticipation:.12,anticipationTime:.3,hold:0,overshoot:.08,settle:220,settleEase:"ease-in-out",actionEase:"ease-in-out-cubic",overlap:45,eyeLead:120,eyeDart:160,drift:.12,blinks:!0,jumpSquash:1},snappy:{anticipation:.2,anticipationTime:.35,hold:.12,overshoot:.12,settle:320,settleEase:{type:"elastic",mode:"out",amplitude:1,period:.35},actionEase:"ease-out-cubic",overlap:35,eyeLead:100,eyeDart:100,drift:.1,blinks:!0,jumpSquash:1.3},limited:{anticipation:.06,anticipationTime:.25,hold:0,overshoot:0,settle:0,settleEase:"ease-out",actionEase:"ease-in-out",overlap:30,eyeLead:80,eyeDart:120,drift:0,blinks:!0,jumpSquash:.6},none:{anticipation:0,anticipationTime:0,hold:0,overshoot:0,settle:0,settleEase:"linear",actionEase:"linear",overlap:0,eyeLead:0,eyeDart:0,drift:0,blinks:!1,jumpSquash:0}};function Yr(t){if(t===void 0)return je.full;if(typeof t=="string")return je[t];const{base:e,...n}=t;return{...je[e??"full"],...n}}const zr=160,Sb=120,Tb=700,Xr=60,Eb=90,Ti=3200,yn=1,Be=1e-6;function Ei(t,e,n={}){const s=Yr(n.style),i=n.seed??1,o={};if(t.length===0)return o;const r=Object.keys(t[0].pose).filter(d=>t.some(u=>Math.abs(u.pose[d]-t[0].pose[d])>Be));for(const d of r)o[d]=Ab(d,t,e,s,i);const a=e.blink,l=a!==void 0&&r.includes(a);if(s.blinks&&a!==void 0&&!l&&a in t[0].pose){const d=$b(t,e,s,i,t[0].pose[a]);d.length>0&&(o[a]=d)}const{lift:c,stretch:h}=e;if(s.jumpSquash>0&&c&&h&&r.includes(c)&&!r.includes(h)&&h in t[0].pose){const d=Pb(t,c,t[0].pose[h],s.jumpSquash);d.length>0&&(o[h]=d)}return o}function Ab(t,e,n,s,i){const o=n.eyes.includes(t),r=n.limits[t],a=r!==void 0,l=o?-s.eyeLead:(n.depth[t]??1)*s.overlap,c=f=>{const g=(e[f].time-e[f-1].time)/2;return Math.max(-g,Math.min(g,l))},h=[{time:e[0].time,value:e[0].pose[t]}],d=(f,g,p)=>{const m=h[h.length-1];if(f<=m.time+yn){h[h.length-1]={...m,value:g,...p?{easing:p}:{}};return}h.push({time:f,value:g,...p?{easing:p}:{}})};let u=e[0].pose[t];for(let f=1;f<e.length;f++){const g=e[f],p=e[f-1].pose[t],m=g.pose[t],b=m-p,S=h[h.length-1].time,k=g.act!==!1;if(Math.abs(b)<=Be){const v=g.time+(k?c(f):0);if(f===e.length-1)Math.abs(u-m)>Be&&d(Math.max(v,S+zr),m,"ease-in-out"),u=m;else if(k&&a&&s.drift>0&&n.drift.includes(t)&&v-S>=Tb){const P=qt(`${i}:${t}:${f}`)%2===0?1:-1;u=m+P*s.drift*r,d(v,u,"ease-in-out")}continue}if(!k){d(e[f-1].time,u),d(g.time,m,g.easing),u=m;continue}const y=c(f),M=Math.max(e[f-1].time+y,S);let $=g.time+y;o&&s.eyeDart>0&&($=Math.min($,M+s.eyeDart));const E=$-M;if(E<=yn){d(g.time,m,g.easing),u=m;continue}d(M,u);const A=Math.sign(b);if(a&&s.anticipation>0&&r>0&&E>=zr){const v=u-A*Math.min(Math.abs(b)*s.anticipation,r),P=M+E*s.anticipationTime;d(P,v,"ease-in-out"),s.hold>0&&d(P+E*s.hold,v)}const T=f+1<e.length?e[f+1].time-g.time:1/0,I=Math.min(s.settle,T/2);if(a&&s.overshoot>0&&r>0&&E>=Sb&&I>yn){const v=Math.min(Math.abs(b)*s.overshoot,r);d($,m+A*v,g.easing??s.actionEase),d($+I,m,s.settleEase)}else d($,m,g.easing??s.actionEase);u=m}return h}function $b(t,e,n,s,i){const o=[],r=Xr+Eb;for(let f=1;f<t.length;f++){const g=t[f-1].pose,p=t[f].pose;Object.entries(e.headTurns).some(([b,S])=>Math.abs((p[b]??0)-(g[b]??0))>S)&&t[f].act!==!1&&o.push(Math.max(t[0].time,t[f-1].time-n.eyeLead))}const a=t[0].time,l=t[t.length-1].time,c=[...o];let h=a+Ti*.6,d=0;for(;h<l;){c.some(p=>Math.abs(p-h)<Ti/2)||o.push(h);const g=(qt(`${s}:blink:${d++}`)%1e3/1e3-.5)*(Ti*.66);h+=Ti+g}o.sort((f,g)=>f-g);const u=[{time:a,value:i}];for(const f of o){const g=u[u.length-1].time;f+Xr<=g+yn||(f>g+yn&&u.push({time:f,value:i}),u.push({time:f+Xr,value:1,easing:"ease-in"}),u.push({time:f+r,value:i,easing:"ease-out"}))}return u.length>1?u:[]}function Pb(t,e,n,s){const i=n*(1-.18*s),o=n*(1+.14*s),r=[{time:t[0].time,value:n}],a=(l,c,h)=>{const d=r[r.length-1];l<=d.time+yn||r.push({time:l,value:c,...h?{easing:h}:{}})};for(let l=1;l<t.length;l++){const c=t[l-1].pose[e],h=t[l].pose[e],d=t[l-1].time,u=t[l].time,f=u-d;if(!(f<zr||t[l].act===!1)){if(c<=Be&&h>Be)a(d,n),a(d+f*.2,i,"ease-out"),a(d+f*.45,o,"ease-out"),a(u,n,"ease-in-out");else if(c>Be&&h<=Be){const g=l+1<t.length?t[l+1].time-u:400;a(d+f*.5,n),a(u-Math.min(60,f*.15),o,"ease-in"),a(u,i,"ease-out"),a(u+Math.min(260,g/2),n,{type:"back",mode:"out",overshoot:1.4})}}}return r.length>1?r:[]}const zd={depth:{lean:0,bend:0,rise:0,sit:0,spin:0,stretch:0,turn:0,leftHip:0,rightHip:0,headTilt:1,leftShoulder:1,rightShoulder:1,leftKnee:1,rightKnee:1,leftBrow:1,rightBrow:1,browTilt:1,leftEye:1,rightEye:1,leftElbow:2,rightElbow:2,leftAnkle:2,rightAnkle:2,leftFootOut:2,rightFootOut:2,mouth:2,smile:2,mouthWidth:2,leftWrist:3,rightWrist:3},limits:{lean:10,bend:10,headTilt:12,spin:25,turn:.06,sit:.06,stretch:.08,rise:0,leftShoulder:20,rightShoulder:20,leftElbow:18,rightElbow:18,leftWrist:15,rightWrist:15,leftHip:12,rightHip:12,leftKnee:15,rightKnee:15,leftAnkle:10,rightAnkle:10,leftBrow:.25,rightBrow:.25,leftEye:.15,rightEye:.15},eyes:["lookX","lookY"],blink:"blink",headTurns:{turn:.15,headTilt:8,lookX:.5,spin:45},drift:["lean","bend","headTilt","leftShoulder","rightShoulder","leftElbow","rightElbow"],lift:"rise",stretch:"stretch"};function xb(t){return/^(turn|lean|bend|side|lift|roll|stretch)$/.test(t)?{depth:0,limit:{turn:.06,lean:10,bend:10,side:8,lift:0,roll:25,stretch:.08}[t]}:/^leg\.\w+\.(swing|spread|rotate)$/.test(t)?{depth:0,limit:12}:/^head\./.test(t)?{depth:1,limit:12}:/^arm\.\w+\.(swing|spread)$/.test(t)?{depth:1,limit:20}:/^leg\.\w+\.knee$/.test(t)?{depth:1,limit:15}:/^(brow\.|browTilt$)/.test(t)?{depth:1,limit:t==="browTilt"?void 0:.25}:/^eye\./.test(t)?{depth:1,limit:.15}:/^arm\.\w+\.(elbow|bend)$/.test(t)?{depth:2,limit:18}:/^leg\.\w+\.(ankle|toeOut)$/.test(t)?{depth:2,limit:10}:/^(mouth|smile|mouthWidth)$/.test(t)?{depth:2}:/^hand\./.test(t)?{depth:3}:{depth:1}}function Ib(){const t={},e={};for(const n of Object.keys(ut)){const s=xb(n);t[n]=s.depth,s.limit!==void 0&&(e[n]=s.limit)}return{depth:t,limits:e,eyes:["lookX","lookY"],blink:"blink",headTurns:{turn:.15,"head.turn":15,"head.nod":12,lookX:.5,roll:45},drift:["lean","bend","head.tilt","head.nod","arm.left.spread","arm.right.spread","arm.left.elbow","arm.right.elbow"],lift:"lift",stretch:"stretch"}}const Xd=Ib();function Ud(t,e){return Object.entries(e).map(([n,s])=>({id:`${t}-${n}`,target:t,property:n,keyframes:s}))}function Gd(t,e,n={}){const s=er(e),i=e.map((o,r)=>({time:o.time,pose:{...s[r]},easing:o.easing,act:o.act}));return Ud(t,Ei(i,n.rig??zd,n))}function Ob(t,e,n={}){const s=n.rest??ut,i=vr(e,s),o=e.map((r,a)=>({time:r.time,pose:{...s,...i[a]},easing:r.easing,act:r.act}));return Ud(t,Ei(o,n.rig??Xd,n))}const Vd=ct.shocked,_b=ct.scared,Me={take:t=>[{after:140,pose:{stretch:.8,bend:10,lean:t.lean-4,leftShoulder:8,rightShoulder:8,leftEye:.35,rightEye:.35,leftBrow:-.6,rightBrow:-.6,mouth:0},easing:"ease-in-out"},{after:260,pose:{stretch:.78}},{after:360,pose:{rise:.22,stretch:1.35,bend:-14,leftShoulder:150,rightShoulder:150,leftElbow:35,rightElbow:35,leftHip:22,rightHip:22,leftKnee:45,rightKnee:45,...Vd,headTilt:0},easing:"ease-out-cubic"},{after:720,pose:{rise:.25,stretch:1.25,bend:-10,leftShoulder:140,rightShoulder:140},easing:"ease-in-out"},{after:900,pose:{rise:0,stretch:.74,bend:12,leftShoulder:70,rightShoulder:70,leftHip:18,rightHip:18,leftKnee:30,rightKnee:30},easing:"ease-in-quad"},{after:1060,pose:{stretch:1.06,bend:-3,leftShoulder:60,rightShoulder:60,leftHip:t.leftHip,rightHip:t.rightHip,leftKnee:t.leftKnee,rightKnee:t.rightKnee},easing:"ease-out"},{after:1260,pose:{stretch:t.stretch,bend:t.bend,...ct.surprised,leftShoulder:70,rightShoulder:70,leftElbow:60,rightElbow:60},easing:"ease-in-out"}],doubleTake:t=>[{after:160,pose:{lookX:1,lookY:0},easing:"ease-out"},{after:520,pose:{lookX:-.6,headTilt:t.headTilt-4,smile:.6,mouth:0},easing:"ease-in-out"},{after:1100,pose:{lookX:-.6}},{after:1180,pose:{bend:t.bend-10,headTilt:t.headTilt+10,rise:.05,stretch:1.18,...Vd,lookX:1,lookY:0},easing:"ease-out-cubic"},{after:1360,pose:{rise:0,stretch:.88,bend:t.bend+4,headTilt:t.headTilt+4},easing:"ease-in-quad"},{after:1560,pose:{stretch:t.stretch,bend:t.bend,headTilt:t.headTilt},easing:{type:"elastic",mode:"out",amplitude:1,period:.35}}],windUp:()=>[{after:220,pose:{lean:-18,bend:-16,headTilt:-6,leftShoulder:70,leftElbow:-100,rightShoulder:40,rightElbow:100,leftHip:-45,leftKnee:-80,stretch:.92,...ct.angry,lookX:1},easing:"ease-out"},{after:620,pose:{lean:-20,bend:-18,stretch:.9}},{after:700,pose:{lean:28,bend:14,headTilt:6,leftShoulder:30,rightShoulder:60,leftHip:30,leftKnee:-30,rightHip:-20,stretch:1.12},easing:"ease-out-cubic"}],land:t=>[{after:120,pose:{rise:0,stretch:.7,bend:14,leftShoulder:75,rightShoulder:75,leftHip:20,rightHip:20,leftKnee:35,rightKnee:35},easing:"ease-in-quad"},{after:300,pose:{stretch:1.05,bend:-4,leftShoulder:t.leftShoulder,rightShoulder:t.rightShoulder},easing:"ease-out"},{after:460,pose:{rise:0,stretch:t.stretch,bend:t.bend,leftHip:et.leftHip,rightHip:et.rightHip,leftKnee:0,rightKnee:0},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{..._b,bend:t.bend+8,leftShoulder:40,rightShoulder:40,leftElbow:110,rightElbow:110,stretch:.94},easing:"ease-out"}];for(let n=1;n<=14;n++)e.push({after:80+n*45,pose:{lean:t.lean+(n%2===0?2.5:-2.5),headTilt:t.headTilt+(n%2===0?-2:2)}});return e.push({after:755,pose:{lean:t.lean,headTilt:t.headTilt,bend:t.bend}}),e},deflate:t=>[{after:260,pose:{stretch:1.04,headTilt:t.headTilt+4,leftBrow:.3,rightBrow:.3},easing:"ease-in-out"},{after:900,pose:{...Dt.sad,bend:18,stretch:.92,lean:t.lean+5,turn:t.turn,sit:t.sit},easing:"ease-in-out"}]};function Ur(t,e){const n=typeof e.from=="string"?Dt[e.from]:e.from??et;return Gr(Me[t](n),{...e,from:n})}function Gr(t,e){const n=e.speed??1;let s=e.from;return[{time:e.at,pose:e.from},...t.map(i=>(s={...s,...i.pose},{time:e.at+i.after*n,pose:s,act:!1,...i.easing?{easing:i.easing}:{}}))]}function rs(t,e=1){const n=Me[t](et);return n[n.length-1].after*e}function Jd(t,e,n={}){if(e.length<2)return;const s=Math.max(1,Math.round(n.lines??3)),i=n.spacing??5,o=n.lineWidth??2,r=n.opacity??.7;t.save(),t.strokeStyle=n.color??"#222",t.lineCap="round";for(let a=0;a<s;a++){const l=(a-(s-1)/2)*i,c=Math.floor(Math.abs(l)/Math.max(i,1)*(e.length/6));for(let h=c+1;h<e.length;h++){const d=e[h-1],u=e[h],f=u.x-d.x,g=u.y-d.y,p=Math.hypot(f,g)||1,m=-g/p,b=f/p,S=1-h/(e.length-1);t.globalAlpha=r*(1-S),t.lineWidth=o*(1-S*.7),t.beginPath(),t.moveTo(d.x+m*l,d.y+b*l),t.lineTo(u.x+m*l,u.y+b*l),t.stroke()}}t.restore()}const Cb={hands:[{name:"left hand",at:t=>t.hands.left},{name:"right hand",at:t=>t.hands.right}],toes:[{name:"left toe",at:t=>t.toes.left},{name:"right toe",at:t=>t.toes.right}],head:[{name:"head",at:t=>t.head.center}],body:[{name:"hip",at:t=>t.hip},{name:"neck",at:t=>t.neck}]};function Hb(t,e,n,s,i={}){const o=n.stateAt;if(!o)return;const r=i.length??120,a=Math.max(2,Math.round(i.samples??8)),l=Math.max(0,n.time-r);if(n.time-l<1)return;const c=[];for(let f=0;f<a;f++){const g=l+(n.time-l)*f/(a-1);c.push(tr(e,{time:g,state:o(g)},s).joints)}const h=c[c.length-1].height,d=(i.threshold??1.2)*h,u=(i.parts??["hands","toes","head"]).flatMap(f=>Cb[f]);for(const f of u){const g=c.map(f.at);let p=0;for(let S=1;S<g.length;S++)p+=Math.hypot(g[S].x-g[S-1].x,g[S].y-g[S-1].y);const m=p/((n.time-l)/1e3);if(m<=d)continue;const b=Math.min(1,(m-d)/(d*.5));Jd(t,g,{...i,opacity:(i.opacity??.7)*b,spacing:i.spacing??h*.02})}}function Zd(t,e,n,s={}){if(n<=0||n>=1)return;const i=s.size??40,o=s.seed??1,r=.45+.55*(1-(1-n)**3);t.save(),t.strokeStyle=s.color??"#555",t.lineWidth=Math.max(1,i*.03),t.globalAlpha=Math.min(1,n/.08)*(1-n);for(let a=0;a<5;a++){const l=qt(`${o}:puff:${a}`)%1e3/1e3,c=a-2,h=e.x+c*i*.3*r,d=e.y-i*(.06+.12*l)*r+Math.abs(c)*i*.03,u=i*(.11+.07*l)*r;t.beginPath(),t.arc(h,d,u,Math.PI*.95,Math.PI*2.05),t.stroke()}t.restore()}function Rb(t,e,n,s={}){if(n<=0||n>=1)return;const i=s.size??40,o=5,r=1-(1-n)**2;t.save(),t.strokeStyle=s.color??"#222",t.lineWidth=Math.max(1,i*.035),t.lineJoin="round",t.globalAlpha=n<.7?1:(1-n)/.3;for(let a=0;a<o;a++){const l=-Math.PI/2+(a-(o-1)/2)*Math.PI/(o+1),c=i*(.3+.7*r),h=e.x+Math.cos(l)*c,d=e.y+Math.sin(l)*c;Lb(t,h,d,i*.14,n*Math.PI+a),t.stroke()}t.restore()}function Lb(t,e,n,s,i){t.beginPath();for(let o=0;o<10;o++){const r=o%2===0?s:s*.45,a=i+o*Math.PI/5-Math.PI/2,l=e+Math.cos(a)*r,c=n+Math.sin(a)*r;o===0?t.moveTo(l,c):t.lineTo(l,c)}t.closePath()}const Se={rest:{mouth:0,mouthWidth:1},a:{mouth:.75,mouthWidth:1.1},e:{mouth:.45,mouthWidth:1.3},i:{mouth:.28,mouthWidth:1.45},o:{mouth:.6,mouthWidth:.7},u:{mouth:.32,mouthWidth:.55},m:{mouth:0,mouthWidth:.9},f:{mouth:.1,mouthWidth:1.05},l:{mouth:.3,mouthWidth:1},c:{mouth:.2,mouthWidth:1}},as=1,Ai=.55,Qd=.35,Nb=1.6,tu={a:"a",e:"e",i:"i",y:"i",o:"o",u:"u"},eu={m:"m",b:"m",p:"m",f:"f",v:"f",w:"u",q:"u",l:"l",n:"l",d:"l",t:"l"},nu={अ:"a",आ:"a",इ:"i",ई:"i",उ:"u",ऊ:"u",ऋ:"i",ए:"e",ऐ:"e",ओ:"o",औ:"o",ऍ:"e",ऑ:"o"},su={"ा":"a","ि":"i","ी":"i","ु":"u","ू":"u","ृ":"i","े":"e","ै":"e","ो":"o","ौ":"o","ॅ":"e","ॉ":"o"},Db={प:"m",फ:"m",ब:"m",भ:"m",म:"m",व:"u"},Fb="्",iu="़",jb=t=>t>="क"&&t<="ह",ou=new Set([".",",","!","?",";",":","…","।","॥","—","-"]);function ru(t){const e=[],n=Array.from(t.toLowerCase()),s=(i,o)=>{const r=e[e.length-1];r&&r.viseme===i?r.weight+=o*.5:e.push({viseme:i,weight:o})};for(let i=0;i<n.length;i++){const o=n[i],r=n[i+1];if(ou.has(o))s("rest",Nb);else if(/\s/.test(o)){const a=e[e.length-1];a&&a.viseme!=="rest"&&e.push({viseme:"c",weight:Qd})}else if((o==="o"||o==="e")&&r===o)s(o==="o"?"u":"i",as),i++;else if(o in tu)s(tu[o],as);else if(o in eu)s(eu[o],Ai);else{if(o==="h")continue;if(/[a-z]/.test(o))s("c",Ai);else if(o in nu)s(nu[o],as);else if(jb(o)){const a=r===iu?o==="फ"?"f":void 0:Db[o];s(a??"c",Ai);let l=i+1;n[l]===iu&&l++;const c=n[l];c===Fb?i=l:c&&c in su?(s(su[c],as),i=l):(!c||/\s/.test(c)||ou.has(c)||s("a",as*.6),i=l-1)}else(o==="ं"||o==="ँ")&&s("l",Ai*.6)}}for(;e.length>0&&(e[e.length-1].viseme==="rest"||e[e.length-1].weight===Qd);)e.pop();return e}function Vr(t,e={}){const n=e.fields?.mouth??"mouth",s=e.fields?.mouthWidth??"mouthWidth",i=e.energy??1,o=ru(t.text),r=[{time:t.start,value:Se.rest.mouth}],a=[{time:t.start,value:Se.rest.mouthWidth}],l=o.reduce((h,d)=>h+d.weight,0),c=t.end-t.start;if(l>0&&c>0){let h=t.start;for(const d of o){const u=c*d.weight/l,f=h+Math.min(u*.4,60);if(f>r[r.length-1].time){const g=Se[d.viseme];r.push({time:f,value:g.mouth*i,easing:"ease-out"}),a.push({time:f,value:1+(g.mouthWidth-1)*Math.min(1.3,i),easing:"ease-out"})}h+=u}}return t.end>r[r.length-1].time&&(r.push({time:t.end,value:Se.rest.mouth,easing:"ease-in-out"}),a.push({time:t.end,value:Se.rest.mouthWidth,easing:"ease-in-out"})),{[n]:r,[s]:a}}function Bb(t,e,n={}){const s={};for(const i of[...e].sort((o,r)=>o.start-r.start))for(const[o,r]of Object.entries(Vr(i,n))){const a=s[o]??=[],l=a.length>0?a[a.length-1].time:-1/0;a.push(...r.filter(c=>c.time>l))}return Object.entries(s).map(([i,o])=>({id:`${t}-${i}`,target:t,property:i,keyframes:o}))}function au(t,e,n,s={}){if(n.length===0)return e;const i=s.fields?.mouth??"mouth",o=s.fields?.mouthWidth??"mouthWidth",r={[i]:Se.rest.mouth,[o]:Se.rest.mouthWidth,...s.rest},a=new Ht({id:"before-speech",tracks:e}),l=(d,u)=>a.getStateAtTime(u).values.get(t)?.get(d)??r[d],c=[i,o],h=e.filter(d=>d.target!==t||!c.includes(d.property));for(const d of c){const u=e.find(g=>g.target===t&&g.property===d);let f=u?[...u.keyframes]:[{time:0,value:l(d,0)}];for(const g of n){const p=Vr(g,s)[d];p[0]={...p[0],value:l(d,g.start)},p[p.length-1]={...p[p.length-1],value:l(d,g.end)},f=[...f.filter(m=>m.time<g.start||m.time>g.end),...p],f.sort((m,b)=>m.time-b.time)}h.push({id:u?.id??`${t}-${d}`,target:t,property:d,keyframes:f})}return h}const ls={look:{summary:"Turns the head and eyes toward a scene x, `viewer`, `ahead` or `back`.",uses:["toward"]},face:{summary:"Turns the whole figure toward a scene x (turning round if needed), `viewer`, `ahead` or `back`.",uses:["toward"]},say:{summary:"Lip-syncs the `say` line with small nods; the beat lasts as long as the line.",needs:["say"]},hold:{summary:"Holds the pose (the acting pass drifts long holds)."},stand:{summary:"Back to its resting stance (a character’s own, else the rest pose), keeping the way it is turned."},go:{summary:"Walks to `to` in its own gait (a character’s, else walk).",needs:["to"]},zip:{summary:"The cartoon exit: winds up, wheels its legs in place, then shoots off to `to`, leaving dust.",needs:["to"]},leap:{summary:"Crouches, springs, arcs and lands squashed at `to`, on the floor `onto` (a scene y).",uses:["to","onto"]},swipe:{summary:"Winds an arm up, then slides along the target with the arm out so the hand crosses it edge to edge.",uses:["target"]},grab:{summary:"Steps to where its arm reaches the target (crouching for low things), takes it and lifts it overhead.",needs:["target"]},throw:{summary:"Winds the arm back and throws forward and up toward `to` (or the target); `release` is when it lets go.",uses:["to","target"]},kick:{summary:"Steps to a leg’s length from the target, draws the leg back and kicks through it.",needs:["target"]},put:{summary:"Steps to where its arm reaches the spot and sets the thing down there.",needs:["target"]},write:{summary:"Reaches a pen to the spot and writes along it left to right (moving along when it is wide).",needs:["target"]},push:{summary:"Sets both hands on the target’s near side and walks it along until its centre is at `to`.",needs:["target","to"]}};function Jr(t={}){return[...Object.keys(Ot),...Object.keys(Dt),...Object.keys(Me),...Object.keys(ls),...Object.keys(t.gaits??{}),...Object.keys(t.actions??{})]}function Zr(t={}){const e=new Set(Jr()),n=[];for(const s of[...Object.keys(t.actions??{}),...Object.keys(t.gaits??{})])e.has(s)&&n.push(`Custom action or gait "${s}" has the name of a built-in one; give it its own name.`);for(const s of Object.keys(t.actions??{}))t.gaits&&s in t.gaits&&n.push(`"${s}" is both a custom action and a custom gait.`);return n}function Qr(t={}){const e={};for(const n of Object.keys(Ot))e[n]=`Walks to \`to\` in the ${n} gait, feet planted, turning round first if needed.`;for(const n of Object.keys(Dt))e[n]=`Moves into the ${n} pose and holds it.`;for(const n of Object.keys(Me))e[n]=`The ${n} gag, built on the current pose.`;for(const[n,s]of Object.entries(ls))e[n]=s.summary;for(const[n,s]of Object.entries(t.gaits??{}))e[n]=s.summary??`Walks to \`to\` in the ${n} gait (custom).`;for(const[n,s]of Object.entries(t.actions??{}))e[n]=s.summary;return e}const $i=["do","at","for","to","toward","mood","say","pose","target","onto"],Wb={action:"do",type:"do",verb:"do",time:"at",start:"at",delay:"at",duration:"for",length:"for",ms:"for",x:"to",position:"to",destination:"to",expression:"mood",emotion:"mood",face:"mood",feeling:"mood",text:"say",line:"say",speech:"say",dialogue:"say",joints:"pose",y:"onto",floor:"onto",ground:"onto",object:"target",at_target:"target"},Pi=["viewer","ahead","back"],We=t=>typeof t=="number"&&Number.isFinite(t);function cs(t,e={}){const n=Zr(e).map(l=>({level:"error",beat:-1,message:l}));if(!Array.isArray(t))return[...n,{level:"error",beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const s=Jr(e),i=l=>l in Ot||l in(e.gaits??{}),o=Object.keys(ct),r=Object.keys(et);let a=-1/0;return t.forEach((l,c)=>{const h=p=>n.push({level:"error",beat:c,message:p}),d=p=>n.push({level:"warning",beat:c,message:p});if(!l||typeof l!="object"||Array.isArray(l)){h(`Each beat must be an object like { do: 'walk', to: 400 } (got ${JSON.stringify(l)}).`);return}const u=l;for(const p of Object.keys(u))$i.includes(p)||h(ot("beat field",p,$i,Wb[p.toLowerCase()]));const f=u.do;if(f===void 0){h(`A beat needs \`do\` (what happens). Actions: ${s.join(", ")}`);return}if(typeof f!="string"||!s.includes(f)){h(ot("action",f,s));return}const g=ls[f]??e.actions?.[f];for(const p of g?.needs??[])u[p]===void 0&&h(`\`${f}\` needs \`${p}\`.`);if(i(f)&&u.to===void 0&&d(`\`${f}\` without \`to\` walks nowhere.`),f==="leap"&&u.to===void 0&&u.onto===void 0&&d("`leap` without `to` or `onto` jumps on the spot."),u.mood!==void 0&&(typeof u.mood!="string"||!o.includes(u.mood))&&h(ot("mood",u.mood,o)),u.pose!==void 0)if(!u.pose||typeof u.pose!="object"||Array.isArray(u.pose))h("`pose` is joints to change, an object like { rightShoulder: 90 } (for a named pose, use it as the action).");else for(const[p,m]of Object.entries(u.pose))r.includes(p)?We(m)||h(`Pose joint \`${p}\` must be a number (got ${JSON.stringify(m)}).`):h(ot("pose joint",p,r));for(const p of["at","for"]){const m=u[p];m!==void 0&&!(We(m)&&m>=0)&&h(`\`${p}\` is milliseconds, a number ≥ 0 (got ${JSON.stringify(m)}).`)}We(u.at)&&(u.at<a&&d(`\`at\` ${u.at} is before an earlier beat's \`at\` (${a}); beats run in order, so it starts when the one before ends.`),a=u.at);for(const p of["to","onto"]){const m=u[p];m!==void 0&&!We(m)&&h(`\`${p}\` is a scene ${p==="to"?"x":"y"} in px, a number (got ${JSON.stringify(m)}).`)}if(u.toward!==void 0&&!We(u.toward)&&!Pi.includes(u.toward)&&h(`\`toward\` is a scene x or one of ${Pi.join(", ")}${typeof u.toward=="string"&&Rn(u.toward,Pi)?` (did you mean "${Rn(u.toward,Pi)}"?)`:""} (got ${JSON.stringify(u.toward)}).`),u.say!==void 0&&typeof u.say!="string"&&h(`\`say\` is the line spoken, a string (got ${JSON.stringify(u.say)}).`),u.target!==void 0){const p=u.target;(!p||typeof p!="object"||!We(p.x)||!We(p.y))&&h("`target` is a point or box in scene px: { x, y } (a code panel’s line(), token() or spot() fits).")}}),n}function ta(t,e={},n="scriptTracks"){const s=cs(t,e).filter(i=>i.level==="error");if(s.length!==0)throw new Error(`${n}: ${s.length} problem(s) in the beats:
57
57
  ${s.map(i=>` ${i.beat>=0?`beat ${i.beat}: `:""}${i.message}`).join(`
58
- `)}`)}Pg(Or);function tb(t){const e="steps"in t&&typeof t.steps=="function",n="beats"in t&&typeof t.beats=="function";if(e===n)throw new Error("defineAction: give either `steps: (from, beat) => [...]` or `beats: (beat) => [...]`");if(!t.summary)throw new Error("defineAction: give a `summary`: one line on what the figure does");return t}function eb(t){for(const e of["swing","knee","arm","elbow","lean"])if(typeof t[e]!="number")throw new Error(`defineGait: \`${e}\` must be a number (degrees)`);if(t.cycle!==void 0&&!(t.cycle>0))throw new Error("defineGait: `cycle` is ms per two steps, above 0");return t}const Cu=8;function Rr(t,e={},n=0){if(n>Cu)throw new Error(`scriptTracks: custom actions nest more than ${Cu} deep (does one build itself?)`);return t.flatMap(s=>{const i=e[s.do];if(!i||!("beats"in i))return[s];const o=i.beats(s).map((r,a)=>a===0?{...r,...s.at!==void 0&&r.at===void 0?{at:s.at}:{},...s.mood&&!r.mood?{mood:s.mood}:{},...s.say&&!r.say?{say:s.say}:{}}:r);return Rr(o,e,n+1)})}function Hu(t){return t.length===0?0:Math.max(...t.map(e=>e.after))}const Lr={walk:1e3,bouncy:900,doubleBounce:1100,sneak:1600,strut:1100,tired:1500,shove:1300,run:560},nb=450,sb=2.4,ib=160,Ru=2.5,ob=200,rb=340,ab=1.1,Lu=[380,900],lb=.35,pi=300,Fr=150,cb=260,hb=1.2,Dr=160,Fu=400,Vn=300,ub=450,Du=500,Nr=350,Nu=150,db=120,Br=180,Bu=420,fb=300,Wu=300,pb=140,Wr=150,ju=450,gb=450,jr=150,qu=350,Ku=400,mb=12,yb=600,Yu=90,zu=400,bb=200,wb=.09,Xu=350,ee=450,qr=1200,kb=700,dn=320,ne=220,vb=65,Mb=700,Gu=t=>t in we,Sb=t=>t in Lt;function Uu(t){return Math.max(Mb,Array.from(t).length*vb)}function Vu(t,e,n={}){const s={actions:n.actions,gaits:n.gaits};Hr(e,s);const i=n.gait??"walk",o=Rr(e,n.actions).map(T=>T.do==="go"?{...T,do:i}:T);Hr(o,s,"scriptTracks (after expanding custom actions)");const r=T=>_t[T]??n.gaits?.[T],a=T=>Lr[T]??n.gaits?.[T]?.cycle??1e3,l=T=>{const C=n.actions?.[T];return C&&"steps"in C?C:void 0},c=n.from??0,h=n.ground??0,u=n.height??300;let d=c,f=h,g=n.facing??1,p=n.start??it,m=0,b=0;const k=[{time:0,pose:p}],w=[{time:0,value:0}],M=[{time:0,value:0}],S=[{time:0,value:0}],A=[{time:0,value:0}],E=[{time:0,value:"walk"}],$=[{time:0,value:g}],v=[],O=[],x=[],_=(T,C,D,q)=>{p={...p,...C},D&&(p=fe(p,D)),k.push({time:T,pose:p,...q===!1?{act:q}:{}})},F=(T,C,D)=>(_(T+dn/2,{turn:0},D),$.push({time:T+dn/2,value:g},{time:T+dn/2+1,value:C}),g=C,_(T+dn,{turn:1}),T+dn),I=T=>T<d?-1:1,L=(T,C,D)=>I(C)!==g?F(T,I(C),D):T,N=(T,C,D,q="arm")=>{const st=q==="arm",K=pe({...T,...st?{rightShoulder:0,rightElbow:0}:{rightHip:0,rightKnee:0}},{height:u,facing:g}),tt=st?K.shoulders.right:K.hip,R=st?K.elbows.right:K.knees.right,B=(G,et)=>Math.atan2(g*G,et)*180/Math.PI,Z=((B(C-(d+tt.x),D-(f+tt.y))-B(R.x-tt.x,R.y-tt.y))%360+360)%360;return Z>270?Z-360:Z},Y=(T,C,D,q)=>{const st=q==="arm",K=pe({...T,...st?{rightShoulder:90,rightElbow:0,rightWrist:0}:{rightHip:90,rightKnee:0}},{height:u,facing:g}),tt=st?K.shoulders.right:K.hip,R=st?{x:(K.hands.right.x+K.fingertips.right.x)/2,y:(K.hands.right.y+K.fingertips.right.y)/2}:K.feet.right,B=Math.hypot(R.x-tt.x,R.y-tt.y),W=D-(f+tt.y),Z=Math.abs(W)<B?Math.sqrt(B*B-W*W):B*.1;return C-tt.x-g*Z},j=T=>{const C=pe(T,{height:u,facing:g});return{x:d+(C.hands.right.x+C.fingertips.right.x)/2,y:f+(C.hands.right.y+C.fingertips.right.y)/2}},U=(T,C,D)=>{const q={...T,rightWrist:0,rightElbow:0,rightShoulder:N(T,C,D)},st=pe(q,{height:u,facing:g}),K={x:d+st.shoulders.right.x,y:f+st.shoulders.right.y},tt={x:d+st.elbows.right.x,y:f+st.elbows.right.y},R=j(q),B=Math.hypot(tt.x-K.x,tt.y-K.y),W=Math.hypot(R.x-tt.x,R.y-tt.y),Z=Math.min(B+W-.01,Math.max(Math.abs(B-W)+.01,Math.hypot(C-K.x,D-K.y))),G=ct=>ct*180/Math.PI,et=G(Math.acos((B*B+Z*Z-W*W)/(2*B*Z))),ot=180-G(Math.acos((B*B+W*W-Z*Z)/(2*B*W)));let ut={rightShoulder:q.rightShoulder,rightElbow:0},gt=1/0;for(const ct of[1,-1])for(const Q of[1,-1]){const nt={rightShoulder:q.rightShoulder+ct*et,rightElbow:Q*ot},V={...T,rightWrist:0,...nt},rt=j(V),X=Math.hypot(rt.x-C,rt.y-D)-pe(V,{height:u,facing:g}).elbows.right.y*.001;X<gt&&(gt=X,ut=nt)}return ut},J=(T,C,D)=>Math.abs(C-d)<2?T:(w.push({time:T,value:d-c},{time:T+D,value:C-c,easing:"ease-in-out"}),d=C,T+D);for(const T of o){const C=Math.max(T.at??b,b===0?0:k[k.length-1].time);let D=C,q,st;const K=T.pose??{},tt=l(T.do);if(r(T.do)){const R=T.to??d,B=R===d?g:I(R);let W=C;B!==g?W=F(C,B,T.mood):p.turn<1?(W=C+ne,_(W,{turn:1,...K},T.mood)):(T.mood||T.pose)&&_(C+ne,K,T.mood);const G=Math.abs(R-d)/Io(r(T.do),u),et=T.for??Math.max(ne*2,G*a(T.do)),ot=W+et;E.push({time:W,value:T.do}),A.push({time:W,value:0},{time:W+ne,value:1,easing:"ease-out"}),A.push({time:ot-ne,value:1},{time:ot,value:0,easing:"ease-in"}),S.push({time:W,value:m},{time:ot,value:m+G}),w.push({time:W,value:d-c},{time:ot,value:R-c}),m+=G,d=R,_(ot,{}),D=ot}else if(T.do==="zip"){const R=T.to??d,B=R===d?g:I(R);let W=C;B!==g?W=F(C,B,T.mood):p.turn<1&&(W=C+ne,_(W,{turn:1},T.mood));const Z=Pr("windUp",{at:W,from:T.mood?fe(p,T.mood):p});k.push(...Z),p=Z[Z.length-1].pose;const G=W+Xn("windUp"),et=G+nb,ot=et+Math.max(ib,Math.abs(R-d)/sb);E.push({time:G,value:"run"}),A.push({time:G,value:0},{time:G+80,value:1,easing:"ease-out"},{time:ot,value:1},{time:ot+120,value:0}),S.push({time:G,value:m},{time:et,value:m+Ru,easing:"ease-in"}),m+=Ru+(ot-et)/Lr.run*1.5,S.push({time:ot,value:m}),w.push({time:et,value:d-c},{time:ot,value:R-c,easing:"ease-in"}),x.push({kind:"dust",time:et,x:d,y:f,length:900}),d=R,_(ot,{}),D=ot}else if(T.do==="leap"){const R=T.to??d,B=T.onto??f;let W=R===d?C:L(C,R,T.mood);p.turn<1&&(W+=ne,_(W,{turn:1},T.mood));const Z={leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50};_(W+ob,{stretch:.75,bend:12,leftHip:22,rightHip:22,...Z},T.mood,!1);const G=W+rb;_(G-40,{stretch:.72},void 0,!1),_(G,{stretch:1.2,bend:-6,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4},void 0,!1);const et=Math.hypot(R-d,B-f),ot=T.for??Math.min(Lu[1],Math.max(Lu[0],300+et*ab)),ut=Math.min(f,B)-lb*u,gt=Math.sqrt(f-ut),ct=Math.sqrt(B-ut),Q=G+ot*gt/(gt+ct),nt=G+ot;_(Q,{stretch:1,bend:4,leftHip:-55,leftKnee:-80,rightHip:55,rightKnee:80,leftShoulder:110,rightShoulder:110},void 0,!1),_(nt,{stretch:.72,bend:12,leftShoulder:75,rightShoulder:75,leftElbow:0,rightElbow:0,leftHip:18,rightHip:18,leftKnee:0,rightKnee:0},void 0,!1),_(nt+180,{stretch:1.05,bend:-3},void 0,!1),_(nt+340,{stretch:1,bend:0,leftHip:it.leftHip,rightHip:it.rightHip,leftShoulder:it.leftShoulder,rightShoulder:it.rightShoulder,leftElbow:it.leftElbow,rightElbow:it.rightElbow},void 0,!1),w.push({time:G,value:d-c},{time:nt,value:R-c}),M.push({time:G,value:f-h},{time:Q,value:ut-h,easing:"ease-out-quad"},{time:nt,value:B-h,easing:"ease-in-quad"}),d=R,f=B,x.push({kind:"dust",time:nt,x:d,y:f,length:500}),D=nt+340,q=nt}else if(T.do==="point"&&T.target){const R=T.target,B=L(C,R.x,T.mood),W={...p,...T.mood?dt[T.mood]:{},turn:Math.max(p.turn,.6),rightElbow:0,rightWrist:0,...K},Z=pe(W,{height:u,facing:g}).head.center,G=Math.abs(R.x-(d+Z.x)),et=R.y-(f+Z.y),ot=B+ee;_(ot,{...W,rightShoulder:N(W,R.x,R.y),lookX:1,lookY:Tb(et/Math.max(1,Math.hypot(G,et)))*.8}),D=ot+(T.for??qr),q=ot,st=D}else if(T.do==="swipe"){const R=T.target??{x:d+g*u*.5,y:f-u*.6},B=I(R.x),W=L(C,R.x,T.mood),Z=B===1?R.left??R.x:R.right??R.x,G=B===1?R.right??R.x:R.left??R.x,et={...p,turn:1,lean:-10,bend:-8,rightElbow:40,lookX:1,...K};_(W+pi,{...et,rightShoulder:N(et,d-g*u*.3,f-u*1.1)},T.mood,!1);const ot={...p,lean:6,bend:4,rightElbow:0,rightWrist:0},ut={...p,lean:14,bend:12,rightElbow:0,rightWrist:0};J(W,Y(ot,Z,R.y,"arm"),pi+Fr),_(W+pi+Fr,{lean:-12},void 0,!1);const gt=W+pi+Fr+80;_(gt,{...ot,rightShoulder:N(ot,Z,R.y)},void 0,!1);const ct=gt+(T.for??Math.max(cb,Math.abs(G-Z)/hb));w.push({time:gt,value:d-c}),d=Y(ut,G,R.y,"arm"),w.push({time:ct,value:d-c}),_(ct,{...ut,rightShoulder:N(ut,G,R.y)},void 0,!1),_(ct+Dr,{lean:16,bend:14,rightShoulder:N(p,G+B*u*.4,R.y+u*.25)},void 0,!1),_(ct+Dr+Fu,{lean:0,bend:0,rightShoulder:it.rightShoulder,rightElbow:it.rightElbow}),D=ct+Dr+Fu,q=gt,st=ct}else if(T.do==="grab"&&T.target){const R=T.target,B=L(C,R.x,T.mood),W=R.y>f-u*.5,Z={...p,turn:1,rightElbow:0,bend:W?35:0,lean:W?12:0,stretch:W?.75:1,lookX:1,lookY:W?.8:0,...K},et=J(B,Y(Z,R.x,R.y,"arm"),Vn)+ub;_(et,{...Z,rightShoulder:N(Z,R.x,R.y)},T.mood,!1),_(et+120,{},void 0,!1),_(et+Du,{bend:0,lean:-3,stretch:1,rightShoulder:165,rightElbow:20,lookY:-.6}),D=et+Du+150,q=et}else if(T.do==="throw"){const R=T.target?.x??T.to??d+g*u,B=L(C,R,T.mood),W={...p,turn:1,lean:-12,bend:-10,rightElbow:60,stretch:.95,lookX:1,lookY:-.3,...K};_(B+Nr,{...W,rightShoulder:N(W,d-g*u*.4,f-u*1.05)},T.mood,!1),_(B+Nr+Nu,{lean:-14},void 0,!1);const Z=B+Nr+Nu+db,G={...p,lean:14,bend:12,rightElbow:0,stretch:1.04};k.push({time:Z,pose:p={...G,rightShoulder:N(G,d+g*u,f-u*1.1)},easing:"ease-in",act:!1}),_(Z+Br,{lean:18,bend:14,rightShoulder:55,stretch:1},void 0,!1),_(Z+Br+Bu,{lean:0,bend:0,rightShoulder:it.rightShoulder,rightElbow:it.rightElbow,lookY:0}),D=Z+Br+Bu,q=Z,st=Z}else if(T.do==="kick"&&T.target){const R=T.target,B=L(C,R.x,T.mood),W={...p,turn:1,lean:-12,bend:-6,rightKnee:0,leftShoulder:100,rightShoulder:70},Z=J(B,Y(W,R.x,R.y,"leg"),fb),G={leftShoulder:70,rightShoulder:50,leftElbow:-20,rightElbow:20};_(Z+Wu,{turn:1,lean:8,bend:6,rightHip:-40,rightKnee:80,lookX:1,lookY:.7,...G,...K},T.mood,!1);const et=Z+Wu+pb,ot=N(W,R.x,R.y,"leg");k.push({time:et,pose:p={...p,...W,rightHip:ot},easing:"ease-in",act:!1}),_(et+Wr,{lean:-15,rightHip:ot+20},void 0,!1),_(et+Wr+ju,{lean:0,bend:0,rightHip:it.rightHip,rightKnee:0,leftShoulder:it.leftShoulder,rightShoulder:it.rightShoulder,leftElbow:it.leftElbow,rightElbow:it.rightElbow,lookY:0}),D=et+Wr+ju,q=et}else if(T.do==="put"&&T.target){const R=T.target,B=L(C,R.x,T.mood),W=R.y>f-u*.5,Z={...p,turn:1,rightElbow:0,rightWrist:0,bend:W?35:0,lean:W?12:0,stretch:W?.75:1,lookX:1,lookY:W?.8:0,...K},et=J(B,Y(Z,R.x,R.y,"arm"),Vn)+gb;_(et,{...Z,rightShoulder:N(Z,R.x,R.y)},T.mood,!1),_(et+jr,{},void 0,!1),_(et+jr+qu,{bend:0,lean:0,stretch:1,rightShoulder:it.rightShoulder,rightElbow:it.rightElbow,lookY:0}),D=et+jr+qu,q=et}else if(T.do==="write"&&T.target){const R=T.target,B=R.left??R.x,W=R.right??R.x,Z=L(C,(B+W)/2,T.mood),G={...p,turn:1,rightElbow:0,rightWrist:0,...dt.thinking,lookX:1,lookY:0,...K},et=rt=>Y(G,rt,R.y,"arm")+g*u*.08,ot=rt=>{const z=j({...G,...U(G,rt,R.y),rightWrist:0});return Math.hypot(z.x-rt,z.y-R.y)<2},ut=g===1?B:W,gt=J(Z,et((B+W)/2),Vn),ct=!ot(B)||!ot(W),Q=ct?J(gt,et(B),Vn)+Ku:gt+Ku;_(Q,{...G,...U(G,ct?B:ut,R.y)},T.mood,!1);const nt=T.for??Math.max(yb,Math.abs(W-B)*mb);ct&&w.push({time:Q,value:d-c});for(let rt=Yu,z=0;rt<=nt;rt+=Yu,z++){const X=B+(W-B)*Math.min(rt,nt)/nt;ct&&(d=et(X),w.push({time:Q+rt,value:d-c}));const at=(z%2===0?-1:1)*u*.02;_(Q+rt,U(G,X,R.y+at),void 0,!1)}const V=Q+nt;_(V,U(G,W,R.y),void 0,!1),_(V+zu,{rightShoulder:it.rightShoulder,rightElbow:it.rightElbow,...dt.happy}),D=V+zu,q=Q,st=V}else if(T.do==="push"&&T.target){const R=T.target,B=T.to??R.x,W=L(C,d+(B>=R.x?1:-1),T.mood),Z=g===1?R.left??R.x:R.right??R.x,G={...p,turn:1,lean:16,bend:8,rightWrist:0,leftWrist:0,lookX:1,...K},et=Y(G,Z,R.y,"arm"),ot=J(W,et+g*u*.06,Vn),ut=U(G,Z,R.y),gt={...G,...ut,leftShoulder:-ut.rightShoulder,leftElbow:-ut.rightElbow},ct=ot+bb;_(ct,gt,T.mood,!1);const Q=Math.abs(B-R.x),nt=ct+(T.for??Math.max(600,Q/wb)),V=Q/Io("shove",u);E.push({time:ct,value:"shove"}),A.push({time:ct,value:0},{time:ct+ne,value:1,easing:"ease-out"},{time:nt-ne,value:1},{time:nt,value:0,easing:"ease-in"}),S.push({time:ct,value:m},{time:nt,value:m+V}),m+=V,w.push({time:ct,value:d-c},{time:nt,value:d+(B-R.x)-c}),d+=B-R.x,_(nt,{},void 0,!1),_(nt+Xu,{lean:0,bend:0,rightShoulder:it.rightShoulder,leftShoulder:it.leftShoulder,rightElbow:it.rightElbow,leftElbow:it.leftElbow}),D=nt+Xu,q=ct,st=nt}else if(tt){const R=T.mood?fe(p,T.mood):p,B=tt.steps(R,T),W=$r(B,{at:C,from:R});k.push(...W),p=W[W.length-1].pose,D=C+Math.max(Hu(B),T.for??0)}else if(Gu(T.do)){const R=Pr(T.do,{at:C,from:T.mood?fe(p,T.mood):p});k.push(...R),p=R[R.length-1].pose,D=C+Xn(T.do),T.do==="take"&&x.push({kind:"dust",time:C+900,x:d,y:f,length:500}),T.do==="land"&&x.push({kind:"dust",time:C+120,x:d,y:f,length:500})}else if(T.do==="look"||T.do==="face"){const R=T.toward??"viewer",B=T.for??kb;if(R==="viewer")_(C+ee,{turn:0,lookX:0,lookY:0,...K},T.mood);else if(R==="ahead")_(C+ee,{turn:T.do==="face"?1:.6,lookX:1,...K},T.mood);else if(R==="back")_(C+ee,{turn:.2,lookX:-1,...K},T.mood);else{const W=I(R);W!==g&&T.do==="face"?(F(C,W,T.mood),_(C+dn+1,{lookX:1,...K})):W!==g?_(C+ee,{turn:.25,lookX:-1,...K},T.mood):_(C+ee,{turn:T.do==="face"?1:.6,lookX:1,...K},T.mood)}D=C+Math.max(B,ee)}else if(Sb(T.do)||T.do==="stand"){const R=T.do==="stand"?n.rest??it:Lt[T.do],B=R.turn!==it.turn?R.turn:p.turn,W=T.mood?dt[T.mood]:{lookX:p.lookX,lookY:p.lookY};_(C+ee,{...R,turn:B,...W,...K}),D=C+(T.for??qr)}else{const R=T.for??(T.say?Uu(T.say):qr);(T.mood||T.pose)&&_(C+Math.min(ee,R/2),K,T.mood),D=C+R}if(T.say){const R=r(T.do)||Gu(T.do)||tt?C:C+Math.min(150,(D-C)/4),B=r(T.do)?D:Math.max(R+200,D-100);v.push({text:T.say,start:R,end:B}),T.do==="say"&&Pb(k,p,R,B)}T.onto!==void 0&&T.do!=="leap"&&T.onto!==f&&(M.push({time:C,value:f-h},{time:D,value:T.onto-h,easing:"ease-in-out"}),f=T.onto),D>k[k.length-1].time&&k.push({time:D,pose:p}),O.push({start:C,end:D,...q!==void 0?{contact:q}:{},...st!==void 0?{release:st}:{}}),b=D}const P=ku(t,Ab(k),n),H=[{id:`${t}-x`,target:t,property:"x",keyframes:w},{id:`${t}-y`,target:t,property:"y",keyframes:M},{id:`${t}-walk`,target:t,property:"walk",keyframes:S},{id:`${t}-walking`,target:t,property:"walking",keyframes:A},{id:`${t}-gait`,target:t,property:"gait",keyframes:E},{id:`${t}-facing`,target:t,property:"facing",keyframes:$}].filter(T=>T.keyframes.length>1||T.property==="x");return{tracks:[...Ou(t,P,v,{energy:n.energy}),...H],duration:b,lines:v,keys:k,beats:O,effects:x}}const Tb=t=>Math.max(-1,Math.min(1,t)),Eb=30;function Ab(t){const e=[];for(const n of t){const s=e[e.length-1];s&&n.time-s.time<Eb?e[e.length-1]={...n,time:s.time}:e.push(n)}return e}function Pb(t,e,n,s){const o=t.filter(l=>l.time>n),r=t.filter(l=>l.time<=n),a=[];for(let l=n+520,c=0;l<s-520/2;l+=520,c++){const h=c%2===0?3:-2;a.push({time:l,pose:{...e,headTilt:e.headTilt+h,leftBrow:e.leftBrow+(c%2===0?.25:0),rightBrow:e.rightBrow+(c%2===0?.25:0)}})}a.length>0&&a.push({time:s,pose:e}),t.length=0,t.push(...r,...a.filter(l=>!o.some(c=>Math.abs(c.time-l.time)<60)),...o),t.sort((l,c)=>l.time-c.time)}function Ju(t,e,n){const s=new Wt({id:`${t}-hand`,tracks:e.filter(l=>l.target===t)}),i=Lo({x:n.x,y:n.y,style:n.style,cast:n.cast}),o=n.side??"right",r=n.every??33,a=[];for(let l=n.start;;l=Math.min(n.end,l+r)){const{joints:c}=Fo(i,{time:l,state:s.getStateAtTime(l)},t),h=c.hands[o],u=c.fingertips[o];if(a.push({time:l,x:(h.x+u.x)/2,y:(h.y+u.y)/2}),l>=n.end)break}return a}function $b(t){const e={actions:t.actions,gaits:t.gaits},n=Ir(e);if(n.length>0)throw new Error(`persona "${t.name}": ${n.join(" ")}`);const s=[...Object.keys(_t),...Object.keys(t.gaits??{})],i=t.gait??"walk";if(!s.includes(i))throw new Error(`persona "${t.name}": ${ft("gait",i,s)}`);if(t.mood&&!(t.mood in dt))throw new Error(`persona "${t.name}": ${ft("mood",t.mood,Object.keys(dt))}`);const o=t.acting??"snappy";if(typeof o=="string"&&!(o in Ce))throw new Error(`persona "${t.name}": ${ft("acting style",o,Object.keys(Ce))}`);if(typeof t.stance=="string"&&!(t.stance in Lt))throw new Error(`persona "${t.name}": ${ft("stance",t.stance,Object.keys(Lt))}`);const r=t.height??120,a=typeof t.stance=="string"?Lt[t.stance]:Tt(t.stance??{}),l=t.mood?fe(a,t.mood):a,c={...t.look,height:r},h=t.summary??`${t.name}, a stick figure`;return{name:t.name,summary:h,cast:e,rest:l,height:r,figure:u=>Lo({x:u.x,y:u.y,pose:l,style:{...c,...u.facing?{facing:u.facing}:{}},cast:e}),script:(u,d,f={})=>Vu(u,d,{...e,from:f.from,ground:f.ground,facing:f.facing,height:r,style:o,gait:i,start:l,rest:l,energy:t.energy}),check:u=>Cr(u,e),handPath:(u,d,f)=>Ju(u,d,{...f,style:c,cast:e}),describe:()=>({name:t.name,summary:h,habits:{height:r,acting:typeof o=="string"?o:"custom",gait:i,...t.mood?{mood:t.mood}:{},stance:typeof t.stance=="string"?t.stance:t.stance?"custom":"rest"},actions:Or(e),own:{actions:Object.keys(t.actions??{}),gaits:Object.keys(t.gaits??{})}})}}const ht=["rect","circle","text","line","path","image","custom"],gi={x:{description:"Moves it right by this much from where it was placed (an offset; the target’s own x is its place)",unit:"px",types:ht},y:{description:"Moves it down by this much from where it was placed (an offset)",unit:"px",types:ht},opacity:{description:"How opaque it is",unit:"0..1",min:0,max:1,types:ht},rotate:{description:"Turns it clockwise about its origin",unit:"degrees",types:ht},rotateX:{description:"Tips it about the horizontal axis (3D; shows with perspective)",unit:"degrees",types:ht},rotateY:{description:"Turns it about the vertical axis (3D; shows with perspective)",unit:"degrees",types:ht},z:{description:"Depth toward the viewer (shows with perspective)",unit:"px",types:ht},perspective:{description:"Distance from the viewer: nearer parts grow, further ones shrink",unit:"px",min:1,types:ht},scale:{description:"Size, both ways",unit:"factor",types:ht},scaleX:{description:"Width factor",unit:"factor",types:ht},scaleY:{description:"Height factor",unit:"factor",types:ht},skewX:{description:"Slants it sideways",unit:"degrees",types:ht},skewY:{description:"Slants it up and down",unit:"degrees",types:ht},originX:{description:"Transform pivot across its box",unit:"% (0 left, 50 centre, 100 right)",min:0,max:100,types:ht},originY:{description:"Transform pivot down its box",unit:"% (0 top, 50 centre, 100 bottom)",min:0,max:100,types:ht},fill:{description:"Fill colour (also written fillStyle)",kind:"color",types:ht},stroke:{description:"Outline colour (also written strokeStyle)",kind:"color",types:ht},strokeWidth:{description:"Outline width (also written lineWidth)",unit:"px",min:0,types:ht},clipTop:{description:"Hides this much from the top edge, for reveals",unit:"% of its height",min:0,max:100,types:ht},clipRight:{description:"Hides this much from the right edge",unit:"% of its width",min:0,max:100,types:ht},clipBottom:{description:"Hides this much from the bottom edge",unit:"% of its height",min:0,max:100,types:ht},clipLeft:{description:"Hides this much from the left edge",unit:"% of its width",min:0,max:100,types:ht},blur:{description:"Gaussian blur",unit:"px",min:0,types:ht},brightness:{description:"Brightness factor (1 unchanged)",unit:"factor",min:0,types:ht},glow:{description:"Soft glow around it, in glowColor",unit:"px",min:0,types:ht},glowColor:{description:"Colour of the glow",kind:"color",types:ht},shadowX:{description:"Drop shadow offset right",unit:"px",types:ht},shadowY:{description:"Drop shadow offset down",unit:"px",types:ht},shadowBlur:{description:"Drop shadow softness",unit:"px",min:0,types:ht},shadowColor:{description:"Drop shadow colour",kind:"color",types:ht},shine:{description:"A highlight sweeping across the fill",unit:"0..1 (progress)",min:0,max:1,types:ht},drawOn:{description:"How much of the outline is drawn, for drawing a shape on; the fill appears when it is complete",unit:"0..1",min:0,max:1,types:["rect","circle","line","path"]},width:{description:"Box width",unit:"px",min:0,types:["rect","image"]},height:{description:"Box height",unit:"px",min:0,types:["rect","image"]},borderRadius:{description:"Rounded corners",unit:"px",min:0,types:["rect","image"]},radius:{description:"Circle radius",unit:"px",min:0,types:["circle"]},x2:{description:"Line end, x",unit:"px",types:["line"]},y2:{description:"Line end, y",unit:"px",types:["line"]},d:{description:"SVG path data; tween between paths to morph",kind:"string",types:["path"]},text:{description:"The text shown (a text track types or scrambles it)",kind:"string",types:["text"]},fontSize:{description:"Font size",unit:"px",min:0,types:["text"]},fontWeight:{description:"Font weight",unit:"100..900",min:100,max:900,types:["text"]},motionPath:{description:"Moves it along an SVG path (a motion-path track writes motionPathX/Y and, aligned, rotate)",kind:"string",types:ht},quaternion:{description:'A rotation as [x, y, z, w] (a track with interpolation: "slerp")',kind:"list",types:ht}},Kr={fillStyle:"fill",strokeStyle:"stroke",lineWidth:"strokeWidth",rotateZ:"rotate",motionPathX:"x",motionPathY:"y",motionPathRotate:"rotate"},xb={rotation:"rotate",angle:"rotate",alpha:"opacity",fade:"opacity",color:"fill",colour:"fill",background:"fill",size:"scale",left:"x",top:"y",translateX:"x",translateY:"y",r:"radius",path:"d",content:"text"};function Zu(t){const e=t,n=Object.entries(gi).filter(([,i])=>i.types.includes(t.type)).map(([i,{types:o,...r}])=>({name:i,...r,...e[i]!==void 0&&typeof e[i]!="object"?{value:e[i]}:{}}));if(t.type!=="custom")return{type:t.type,properties:n};const s=t.about;for(const[i,o]of Object.entries(t.props??{}))n.push({name:i,description:s?.props?.[i]?.description??"",...s?.props?.[i],value:o});return{type:"custom",...s?{kind:s.kind,summary:s.summary}:{},properties:n,...s?.actions?{actions:s.actions}:{}}}function Qu(t){const e=Zu(t).properties.map(n=>n.name);return[...e,...Object.keys(Kr).filter(n=>e.includes(Kr[n]))]}function _b(t,e){const n=[],s=Object.keys(e);for(const i of t){const o=d=>n.push({level:"error",track:i.id,message:d}),r=e[i.target];if(!r){o(ft("target",i.target,s));continue}const a=Qu(r),l=r.type==="custom"&&r.acceptsProp?.(i.property);if(!a.includes(i.property)&&!l){o(`${i.target}: ${ft("property",i.property,a,xb[i.property])}`);continue}const c=i.keyframes??[];for(let d=1;d<c.length;d++)c[d].time<c[d-1].time&&o(`${i.target}.${i.property}: keyframes out of time order (${c[d-1].time} ms, then ${c[d].time} ms).`);const h=gi[Kr[i.property]??i.property]??r.about?.props?.[i.property],u=h&&(h.kind??"number")==="number";for(const d of c){if(u&&typeof d.value!="number"){o(`${i.target}.${i.property}: values are numbers${h.unit?` (${h.unit})`:""} (got ${JSON.stringify(d.value)} at ${d.time} ms).`);break}if(u&&typeof d.value=="number"&&(h.min!==void 0&&d.value<h.min||h.max!==void 0&&d.value>h.max)){n.push({level:"warning",track:i.id,message:`${i.target}.${i.property}: ${d.value} at ${d.time} ms is outside ${h.min??"−∞"}..${h.max??"∞"}${h.unit?` (${h.unit})`:""}.`});break}}}return n}const fn=(t,e)=>t[2]<=-e;function Yr(t,e,n){const s=(-n-t[2])/(e[2]-t[2]);return[t[0]+(e[0]-t[0])*s,t[1]+(e[1]-t[1])*s,-n]}function td(t,e){if(t.every(s=>fn(s,e)))return t;const n=[];return t.forEach((s,i)=>{const o=t[(i+t.length-1)%t.length],r=fn(s,e),a=fn(o,e);r!==a&&n.push(Yr(o,s,e)),r&&n.push(s)}),n.length>=3?n:[]}function Ib(t,e){if(t.every(i=>fn(i,e)))return[t];const n=[];let s=[];return t.forEach((i,o)=>{const r=fn(i,e);if(o>0){const a=t[o-1],l=fn(a,e);l&&!r?(s.push(Yr(a,i,e)),n.push(s),s=[]):!l&&r&&s.push(Yr(a,i,e))}r&&s.push(i)}),s.length>0&&n.push(s),n.filter(i=>i.length>=2)}function ed(t,e,n){const s=e-t;if(!(s>=n*1.5))return[t,e];const i=Math.round(s/n);return Array.from({length:i+1},(o,r)=>t+s*r/i)}function Ob(t,e,n){const s=(i,o)=>Math.max(0,Math.min(i.length-2,i.findIndex((r,a)=>a>0&&o<=r)-1));return[s(t,n[0]),s(e,n[2])]}function Cb(t,e){const n=s=>{const i=[e[0]*s[0]+e[4]*s[1]+e[8]*s[2],e[1]*s[0]+e[5]*s[1]+e[9]*s[2],e[2]*s[0]+e[6]*s[1]+e[10]*s[2]],o=Math.hypot(...i)||1;return[i[0]/o,i[1]/o,i[2]/o]};return{...t,vertices:t.vertices.map(s=>Ct(e,s)),faces:t.faces.map(s=>({corners:s.corners,normal:n(s.normal)}))}}function mi(t,e,n,s){const i=r=>(r[e]-n)*s>=0;if(t.every(i))return t;const o=[];return t.forEach((r,a)=>{const l=t[(a+t.length-1)%t.length];if(i(r)!==i(l)){const c=(n-l[e])/(r[e]-l[e]);o.push([0,1,2].map(h=>h===e?n:l[h]+(r[h]-l[h])*c))}i(r)&&o.push(r)}),o.length>=3?o:[]}function Hb(t,e,n){const s=t.faces.map(r=>({points:r.corners.map(a=>t.vertices[a]),normal:r.normal})),i=[],o={x:e.slice(1,-1),z:n.slice(1,-1)};for(let r=0;r+1<e.length;r++)for(let a=0;a+1<n.length;a++){const l=[],c=new Map,h=g=>{const p=g.map(b=>Math.round(b*1e6)).join(",");let m=c.get(p);return m===void 0&&(m=l.length,l.push(g),c.set(p,m)),m},u=[],d=g=>g===0,f=(g,p)=>g+2===p.length;for(const g of s){let p=g.points;d(r)||(p=mi(p,0,e[r],1)),p.length&&!f(r,e)&&(p=mi(p,0,e[r+1],-1)),p.length&&!d(a)&&(p=mi(p,2,n[a],1)),p.length&&!f(a,n)&&(p=mi(p,2,n[a+1],-1)),p.length>=3&&u.push({corners:p.map(h),normal:g.normal})}u.length>0&&i.push({cell:[r,a],mesh:{vertices:l,faces:u,creases:t.creases,joined:t.joined,walls:o}})}return i}const Rb=new WeakMap,Lb=new WeakMap,Fb=48,nd=t=>t.map(e=>Math.round(e*1e5)).join(",");function sd(t,e,n,s){let i=t.get(e);i||t.set(e,i=new Map);let o=i.get(n);return o===void 0&&(i.size>=Fb&&i.clear(),i.set(n,o=s())),o}function zr(t,e){const n=nd(e);return sd(Rb,t,n,()=>{const s=Cb(t,e),i=[1/0,1/0,1/0],o=[-1/0,-1/0,-1/0];for(const r of s.vertices)for(const a of[0,1,2])i[a]=Math.min(i[a],r[a]),o[a]=Math.max(o[a],r[a]);return{key:n,inSpace:s,low:i,high:o}})}function Db(t,e){const n=t.map(h=>({...h,...zr(h.mesh,h.local)})),s=[1/0,1/0,1/0],i=[-1/0,-1/0,-1/0];for(const h of n)for(const u of[0,1,2])s[u]=Math.min(s[u],h.low[u]),i[u]=Math.max(i[u],h.high[u]);const o=ed(s[0],i[0],e),r=ed(s[2],i[2],e),a=`${o.join(",")}|${r.join(",")}`,l=n.flatMap(h=>{if(h.high[0]-h.low[0]<=e*2.5&&h.high[2]-h.low[2]<=e*2.5||h.whole||h.mesh.joined||(h.mesh.marks?.length??0)>0){const d=[(h.low[0]+h.high[0])/2,(h.low[1]+h.high[1])/2,(h.low[2]+h.high[2])/2];return[{part:h.part,mesh:h.mesh,cut:!1,cell:Ob(o,r,d)}]}return sd(Lb,h.inSpace,a,()=>Hb(h.inSpace,o,r)).map(d=>({part:h.part,mesh:d.mesh,cut:!0,cell:d.cell}))}),c=(s[1]+i[1])/2;return{pieces:l,middle:([h,u])=>[(o[h]+o[h+1])/2,c,(r[u]+r[u+1])/2]}}const id=.004,Xr=.05,od=new WeakMap;function Nb(t){let e=od.get(t);return e===void 0&&(e=!t.joined&&!t.walls&&t.faces.length>=4&&t.faces.every(n=>{const s=t.vertices[n.corners[0]];return t.vertices.every(i=>n.normal[0]*(i[0]-s[0])+n.normal[1]*(i[1]-s[1])+n.normal[2]*(i[2]-s[2])<=1e-6)}),od.set(t,e)),e}const rd=new WeakMap;function ad(t){return t.filter(({mesh:e})=>Nb(e)).map(({part:e,key:n,inSpace:s,low:i,high:o})=>{let r=rd.get(s);return r||(r=s.faces.map(a=>{const l=s.vertices[a.corners[0]];return{normal:a.normal,offset:a.normal[0]*l[0]+a.normal[1]*l[1]+a.normal[2]*l[2]}}),rd.set(s,r)),{part:e,key:n,planes:r,low:i,high:o}})}function Bb(t,e,n,s){const i=e.reduce((o,r)=>[o[0]+r[0]/e.length,o[1]+r[1]/e.length,o[2]+r[2]/e.length],[0,0,0]);for(const o of s){if(o.part===t||[0,1,2].some(a=>i[a]<o.low[a]-Xr||i[a]>o.high[a]+Xr))continue;if(o.planes.every(a=>{const l=a.normal[0]*n[0]+a.normal[1]*n[1]+a.normal[2]*n[2],c=e.map(u=>a.normal[0]*u[0]+a.normal[1]*u[1]+a.normal[2]*u[2]-a.offset);if(c.every(u=>Math.abs(u)<=id))return l<-.9;const h=Math.abs(l)<.5?Xr:id;return c.every(u=>u<=h)}))return!0}return!1}const ld=new WeakMap;function cd(t,e,n,s,i){const o=`${s}|${i.map(l=>l.key).join(";")}`;let r=ld.get(e);r||ld.set(e,r=new Map);let a=r.get(o);if(!a){r.size>=48&&r.clear();const l=h=>{const u=[n[0]*h[0]+n[4]*h[1]+n[8]*h[2],n[1]*h[0]+n[5]*h[1]+n[9]*h[2],n[2]*h[0]+n[6]*h[1]+n[10]*h[2]],d=Math.hypot(...u)||1;return[u[0]/d,u[1]/d,u[2]/d]},c=e.vertices.map(h=>Ct(n,h));a=e.faces.map(h=>Bb(t,h.corners.map(u=>c[u]),l(h.normal),i)),r.set(o,a)}return a}const pn={turn:{description:"Which way it faces: 0 toward the viewer, 1 screen-right, 2 away, 3 (or −1) screen-left; in between turns it in 3D",unit:"quarter turns"},tilt:{description:"How far the camera looks down on it: 0 level, 12 the ¾ look, 90 straight down",unit:"degrees",default:12,min:-90,max:90},pitch:{description:"Nose up (+) or down (−), about its middle on the ground",unit:"degrees"},roll:{description:"Tipped onto its right (+) or left (−) side",unit:"degrees"},squash:{description:"Squash and stretch about the ground, keeping its volume: 1 normal, below squashed, above stretched",unit:"factor",default:1,min:.3,max:3},lift:{description:"Off the ground",unit:"metres"},lean:{description:"The top sheared forward (+) or back (−): speed and drag",unit:"shear"},size:{description:"Its size, about the ground: 1 as built, 0 gone (pop it in or out)",unit:"factor",default:1,min:0}},Gr=Math.PI/180;function hd(t,e,n){return{toView:s=>Yo(me(s,t*90*Gr),-e*Gr),toScreen:s=>({x:s[0]*n,y:-s[1]*n})}}const ud=new WeakMap,Jn=t=>yi(t),yi=t=>{let e=ud.get(t);return e||ud.set(t,e=nu(t)),e};function yt(t,e,n){return e[n]??t.controls[n]?.default??pn[n]?.default??0}function Zn(t,e){const n=Math.max(.05,yt(t,e,"squash")),s=1/Math.sqrt(n),o=[1,0,0,0,0,1,yt(t,e,"lean"),0,0,0,1,0,0,0,0,1];return[Ee([0,yt(t,e,"lift"),0]),Yt(Bt([1,0,0],-yt(t,e,"pitch"))),Yt(Bt([0,0,1],yt(t,e,"roll"))),o,Ae([s,n,s]),Ae(Array(3).fill(Math.max(0,yt(t,e,"size"))))].reduce((r,a)=>bt(r,a))}function Ur(t,e){const n=Zn(t,e),s=new Map,i=Object.entries(t.controls).flatMap(([r,a])=>(a.bind??[]).map(l=>({value:yt(t,e,r),bind:l}))),o=r=>{const a=s.get(r.id);if(a)return a;const l=r.parent?t.parts.find(h=>h.id===r.parent):void 0;if(r.parent&&!l)throw new Error(`prop rig: part "${r.id}" hangs from "${r.parent}", which is not a part`);let c=bt(l?o(l):n,Ee(r.at??[0,0,0]));if(r.rotate){const[h,u,d]=r.rotate;h&&(c=bt(c,Yt(Bt([1,0,0],h)))),u&&(c=bt(c,Yt(Bt([0,1,0],u)))),d&&(c=bt(c,Yt(Bt([0,0,1],d))))}for(const{value:h,bind:u}of i)if(!(!u.parts.includes(r.id)||h===0)){if(u.translate&&(c=bt(c,Ee([u.translate[0]*h,u.translate[1]*h,u.translate[2]*h]))),u.rotate){const d=u.rotate.pivot??[0,0,0],f=u.rotate.axis==="x"?[1,0,0]:u.rotate.axis==="y"?[0,1,0]:[0,0,1];c=[c,Ee(d),Yt(Bt(f,u.rotate.degrees*h)),Ee([-d[0],-d[1],-d[2]])].reduce((g,p)=>bt(g,p))}u.scale&&(c=bt(c,Ae([1+(u.scale[0]-1)*h,1+(u.scale[1]-1)*h,1+(u.scale[2]-1)*h])))}return s.set(r.id,c),c};for(const r of t.parts)o(r);return s}const Vr=(()=>{const t=[-.45,.75,.5],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),Wb=Math.cos(35*Gr);function Jr(t,e,n,s,i={}){const o=t.derive?{...e,...t.derive(e)}:e,r=Ur(t,o),a=n.toView([0,0,0]),l=I=>L=>[I[0]*L[0]+I[4]*L[1]+I[8]*L[2],I[1]*L[0]+I[5]*L[1]+I[9]*L[2],I[2]*L[0]+I[6]*L[1]+I[10]*L[2]],c=Zn(t,o),h=i.slice===void 0?null:no(c),u=h?t.parts.map(I=>({part:I,mesh:yi(I.shape),local:bt(h,r.get(I.id)),whole:I.shape.type==="tube"})):void 0,d=u?Db(u,i.slice):void 0,f=u?ad(u.map(I=>({part:I.part.id,mesh:I.mesh,...zr(I.mesh,I.local)}))):void 0,g=(I,L,N,Y)=>{const j=z=>n.toView(Ct(N,z)),U=L.vertices.map(j),J=U.map(z=>n.toScreen(z)),P=i.perspective?i.near:void 0,H=z=>z.map(X=>n.toScreen(X)),T=z=>P===void 0?z:td(z,P),C=z=>P===void 0?[z]:Ib(z,P),D=l(N),q=L.faces.map(z=>{const X=n.toView(D(z.normal)),at=[X[0]-a[0],X[1]-a[1],X[2]-a[2]],Mt=Math.hypot(...at)||1;return[at[0]/Mt,at[1]/Mt,at[2]/Mt]}),st=f&&Y?cd(I.id,L,Y,nd(Y),f):void 0,K=z=>st?.[z]??!1,tt=q.map((z,X)=>{if(K(X))return!1;if(!i.perspective)return z[2]>1e-6;const Mt=L.faces[X].corners.reduce((Ot,Et)=>[Ot[0]+U[Et][0],Ot[1]+U[Et][1],Ot[2]+U[Et][2]],[0,0,0]);return-(z[0]*Mt[0]+z[1]*Mt[1]+z[2]*Mt[2])>1e-9}),R=z=>L.faces[z].corners.reduce((X,at)=>X+U[at][2],0)/L.faces[z].corners.length,B=L.faces.map((z,X)=>({face:z,i:X})).filter(({i:z})=>tt[z]).map(({face:z,i:X})=>({i:X,solved:{points:P===void 0?z.corners.map(at=>J[at]):H(T(z.corners.map(at=>U[at]))),depth:R(X),tone:.72+.33*Math.max(0,q[X][0]*Vr[0]+q[X][1]*Vr[1]+q[X][2]*Vr[2])}})).filter(z=>z.solved.points.length>=3).sort((z,X)=>z.solved.depth-X.solved.depth);if(i.light){const z=l(N);for(const{i:X,solved:at}of B){const Mt=L.faces[X].corners,Ot=Mt.reduce((ra,dk)=>{const aa=Ct(N,L.vertices[dk]);return[ra[0]+aa[0]/Mt.length,ra[1]+aa[1]/Mt.length,ra[2]+aa[2]/Mt.length]},[0,0,0]),Et=z(L.faces[X].normal),Fe=Math.hypot(...Et)||1,sf=i.light(Ot,[Et[0]/Fe,Et[1]/Fe,Et[2]/Fe]);at.light=sf.light,at.fog=sf.fog}}const W=B.map(z=>z.solved),Z=jb(L),G=[],et=[];for(const[z,X]of Z){const at=X.filter(Ot=>tt[Ot]).length;if(at===0)continue;const Mt=X.length===2&&at===2&&L.creases!==!1&&q[X[0]][0]*q[X[1]][0]+q[X[0]][1]*q[X[1]][1]+q[X[0]][2]*q[X[1]][2]<Wb;X.length===1&&(L.joined||qb(L,z))||(X.length===1||at===1||Mt)&&(G.push(z.split("-").map(Number)),et.push(X.filter(Ot=>tt[Ot]).reduce((Ot,Et)=>R(Et)>R(Ot)?Et:Ot)))}const ot=z=>L.faces.findIndex(X=>X.corners.length>4&&Math.sign(Yb(L.vertices[z],X.normal))>0),ut=(L.marks??[]).filter(([z])=>ot(z)<0||tt[ot(z)]),gt=([z,X])=>P===void 0?[[J[z],J[X]]]:C([U[z],U[X]]).map(H),ct=ut.flatMap(gt),Q=z=>P===void 0?[z.map(X=>J[X])]:C(z.map(X=>U[X])).map(H);if(i.slice!==void 0){const z=new Map;G.forEach((X,at)=>z.set(et[at],[...z.get(et[at])??[],X]));for(const{i:X,solved:at}of B){at.edges=gd(z.get(X)??[]).flatMap(Q);const Mt=L.faces[X].corners;at.center=Mt.reduce((Et,Fe)=>[Et[0]+U[Fe][0]/Mt.length,Et[1]+U[Fe][1]/Mt.length,Et[2]+U[Fe][2]/Mt.length],[0,0,0]),at.normal=q[X];const Ot=B[B.length-1].i;at.marks=ut.filter(([Et])=>(ot(Et)>=0?ot(Et):Ot)===X).flatMap(gt)}}const nt=I.glow?Math.max(0,Math.min(1,yt(t,o,I.glow.control))):0,V=I.fade?Math.max(0,Math.min(1,yt(t,o,I.fade.control))):0,rt=I.fade?Math.max(0,Math.min(1,I.fade.from+(I.fade.to-I.fade.from)*V)):1;return{part:I,depth:U.reduce((z,X)=>z+X[2],0)/Math.max(1,U.length),faces:W,edges:gd(G).flatMap(Q),marks:ct,glow:nt,opacity:rt,...I.shape.type==="tube"?{spine:Kb(C(I.shape.points.map(j)).map(H))}:{},...L.walls?{cut:!0}:{}}},p=new Map(u?.map(I=>[I.part.id,I.local])),b=(d?d.pieces.map(I=>({part:I.part,mesh:I.mesh,m:I.cut?c:r.get(I.part.id),local:I.cut?ws():p.get(I.part.id),cell:I.cell})):t.parts.map(I=>({part:I,mesh:yi(I.shape),m:r.get(I.id),local:void 0,cell:void 0}))).map(I=>({cell:I.cell,solved:g(I.part,I.mesh,I.m,I.local)})),k=b.map(I=>I.solved),w=I=>I.filter(L=>L.faces.length>0&&L.opacity>.01).sort((L,N)=>L.depth-N.depth);let M;if(d){const I=new Map(t.parts.map(N=>{const Y=r.get(N.id),j=yi(N.shape).vertices;return[N.id,j.reduce((U,J)=>U+n.toView(Ct(Y,J))[2],0)/Math.max(1,j.length)]})),L=new Map;for(const N of b){const Y=N.cell.join(",");L.has(Y)||L.set(Y,{cell:N.cell,parts:[]}),L.get(Y).parts.push(N.solved),N.solved.depth=I.get(N.solved.part.id)}M=[...L.values()].map(({cell:N,parts:Y})=>({depth:n.toView(Ct(c,d.middle(N)))[2],parts:w(Y)})).filter(N=>N.parts.length>0)}const S={};for(const[I,L]of Object.entries(t.anchors??{})){const N=L.part?r.get(L.part):Zn(t,o);if(!N)throw new Error(`prop rig: anchor "${I}" is on "${L.part}", which is not a part`);const Y=n.toView(Ct(N,L.at));S[I]={point:n.toScreen(Y),depth:Y[2]}}const[A,E]=t.footprint??[t.length*.45,t.length],$=Math.max(0,yt(t,o,"lift")),v=Math.max(0,yt(t,o,"size"))/(1+$*.8),O=Array.from({length:24},(I,L)=>{const N=Math.PI*2*L/24;return n.toView([Math.cos(N)*A*.55*v,0,Math.sin(N)*E*.55*v])}),x=i.perspective?i.near:void 0,_={points:(x===void 0?O:td(O,x)).map(I=>n.toScreen(I)),opacity:.16*v},F=k.filter(I=>I.part.seeThrough&&I.opacity>.01).flatMap(I=>I.faces.map(L=>L.points));return{under:w(k.filter(I=>!I.part.overRider)),over:w(k.filter(I=>I.part.overRider)),...M?{cells:M}:{},anchors:S,openings:F,shadow:_,pxPerUnit:s,sizePx:t.height*s}}const dd=new WeakMap;function jb(t){let e=dd.get(t);if(!e){e=new Map;for(let n=0;n<t.faces.length;n++){const s=t.faces[n].corners;for(let i=0;i<s.length;i++){const o=s[i],r=s[(i+1)%s.length],a=o<r?`${o}-${r}`:`${r}-${o}`,l=e.get(a);l?l.push(n):e.set(a,[n])}}dd.set(t,e)}return e}function fd(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=Ur(t,n),i=no(Zn(t,n))??ws(),o=r=>Math.max(0,Math.min(1,r));return t.parts.map(r=>{const a=r.fade?o(yt(t,n,r.fade.control)):0;return{part:r,matrix:s.get(r.id),local:bt(i,s.get(r.id)),glow:r.glow?o(yt(t,n,r.glow.control)):0,opacity:r.fade?o(r.fade.from+(r.fade.to-r.fade.from)*a):1}})}function pd(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=Ur(t,n),i=Zn(t,n),o={};for(const[r,a]of Object.entries(t.anchors??{})){const l=a.part?s.get(a.part):i;if(!l)throw new Error(`prop rig: anchor "${r}" is on "${a.part}", which is not a part`);o[r]=Ct(l,a.at)}return o}function qb(t,e){if(!t.walls)return!1;const[n,s]=e.split("-").map(o=>t.vertices[Number(o)]),i=(o,r)=>r.some(a=>Math.abs(n[o]-a)<1e-6&&Math.abs(s[o]-a)<1e-6);return i(0,t.walls.x)||i(2,t.walls.z)}function Kb(t){return t.reduce((e,n)=>!e||n.length>e.length?n:e,void 0)}const Yb=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2];function gd(t){const e=t.map(s=>[...s]),n=[];for(;e.length>0;){const s=[...e.shift()];let i=!0;for(;i;){i=!1;for(let o=0;o<e.length;o++){const[r,a]=e[o],l=s[s.length-1],c=s[0];if(r===l)s.push(a);else if(a===l)s.push(r);else if(a===c)s.unshift(r);else if(r===c)s.unshift(a);else continue;e.splice(o,1),i=!0;break}}n.push(s)}return n}const zb={body:"#e8574a",trim:"#3b3b44",glass:"#bfe3f2",tyre:"#2c2c33",hub:"#c9ccd3",light:"#fff4b8",tail:"#ff5a4f",inside:"#3b3640",seat:"#6d5d55"};function se(t){const e={...zb,...t.colors},n=[],{forwardMost:s,backMost:i,top:o}=md(t);t.body&&n.push({id:"body",shape:{type:"extrude",profile:t.body,width:t.width},fill:e.body});for(const[h,u]of(t.frame??[]).entries())n.push({id:`frame-${h}`,shape:{type:"tube",points:u.points,radius:u.radius??.035,segments:6},fill:u.color??e.body,outline:.7});for(const[h,u]of(t.windows??[]).entries())for(const d of[1,-1])n.push({id:`window-${h}-${d>0?"left":"right"}`,shape:{type:"panel",points:[[u.from,u.low],[u.to,u.low],[u.to,u.high],[u.from,u.high]],facing:d>0?"left":"right"},at:[d*(t.width/2+.01),0,0],fill:e.glass,outline:.7,seeThrough:!0,glow:t.lights?{control:"lights",color:"#ffe9a3"}:void 0});for(const h of t.extras??[])n.push(h);if(t.cabin){const h=t.cabin.width??t.width*.85;n.push({id:"cabin",shape:{type:"extrude",profile:t.cabin.profile,width:h},fill:e.glass,outline:.9,seeThrough:!0,layer:1});const u=Math.min(...t.cabin.profile.map(([,f])=>f)),d=Math.max(...t.cabin.profile.map(([,f])=>f));for(const[f,g]of(t.cabin.pillars??[]).entries())n.push({id:`pillar-${f}`,shape:{type:"box",size:[h+.02,d-u,.1]},at:[0,(u+d)/2,g],fill:e.body,outline:.8,layer:1})}const r=t.wheels[0]?.radius??.4,a=[];t.wheels.forEach((h,u)=>{const d=h.side===0?[0]:[1,-1],f=h.thickness??(h.style==="spoked"?.05:.26);for(const g of d){const p=`wheel-${u}-${g>0?"left":g<0?"right":"middle"}`;if(a.push({parts:[p],rotate:{axis:"x",degrees:r/h.radius}}),n.push({id:p,shape:{type:"cylinder",radius:h.radius,length:f,axis:"x",segments:20,spokes:h.style==="spoked"?8:0},at:[g*h.side,h.radius,h.forward],fill:h.style==="spoked"?void 0:e.tyre,ink:h.style==="spoked"?e.tyre:void 0,outline:h.style==="spoked"?1.3:1}),h.style!=="spoked")for(const m of g===0?[1,-1]:[g])n.push({id:`${p}-hub${g===0?m>0?"-left":"-right":""}`,parent:p,shape:{type:"cylinder",radius:h.radius*.55,length:.02,axis:"x",segments:14,spokes:5},at:[m*(f/2+.012),0,0],fill:e.hub,outline:.6})}});const l={wheelSpin:{description:"How far the wheels have turned (keyed exactly with the distance driven, so they never skate)",unit:"degrees",bind:a}};if(t.door){const{from:h,to:u,low:d,high:f}=t.door,g=[[h,d],[u,d],[u,f],[h,f]];for(const p of[1,-1]){const m=p>0?"left":"right";n.push({id:`doorway-${m}`,shape:{type:"panel",points:g,facing:p>0?"left":"right"},at:[p*(t.width/2+.004),0,0],fill:e.inside,outline:.5,seeThrough:!0});const b=h+(u-h)*.15,k=h+(u-h)*.55;n.push({id:`seat-back-${m}`,shape:{type:"panel",points:[[b,d+.05],[k,d+.05],[k-.08,f-.06],[b+.06,f-.04]],facing:p>0?"left":"right"},at:[p*(t.width/2+.006),0,0],fill:e.seat,outline:.4}),n.push({id:`door-${m}`,shape:{type:"panel",points:g.map(([w,M])=>[w-u,M]),facing:p>0?"left":"right"},at:[p*(t.width/2+.01),0,u],fill:e.body,outline:.7,overRider:!0})}l.door={description:"Doors open: 0 shut, 1 open (hinged at the front)",unit:"0..1",min:0,max:1,bind:[{parts:["door-left"],rotate:{axis:"y",degrees:-70}},{parts:["door-right"],rotate:{axis:"y",degrees:70}}]}}if(t.lights){const{across:h,low:u,high:d,front:f,back:g}=t.lights,p=(t.lights.size??.32)/2,m=[[-p,u],[p,u],[p,d],[-p,d]];for(const b of[1,-1])n.push({id:`headlight-${b}`,shape:{type:"panel",points:m,facing:"front"},at:[b*h,0,f],fill:e.light,outline:.6,glow:{control:"lights",color:"#ffffff"}}),n.push({id:`taillight-${b}`,shape:{type:"panel",points:m,facing:"back"},at:[b*h,0,g],fill:ni(e.tail,.62),outline:.6,glow:{control:"lights",color:e.tail}});l.lights={description:"Lights on: 0 off, 1 on",unit:"0..1",min:0,max:1}}t.antenna&&(n.push({id:"antenna",shape:{type:"tube",points:[[0,0,0],[0,.75,0]],radius:.018,segments:5},at:t.antenna,fill:e.trim,outline:.6}),n.push({id:"antenna-tip",parent:"antenna",shape:{type:"ellipsoid",radii:[.05,.05,.05],segments:8},at:[0,.77,0],fill:e.tail,outline:.6}),l.antenna={description:"Antenna bend (follow-through: it trails the motion on a spring)",unit:"degrees",bind:[{parts:["antenna"],rotate:{axis:"x",degrees:1}}]});const c={parts:n,controls:l,length:s-i,height:o,footprint:[t.width,s-i],anchors:{...t.seat?{seat:{at:t.seat}}:{},front:{at:[0,o*.45,s]},back:{at:[0,o*.45,i]},roof:{at:[0,o,0]},...t.door?{door:{at:[-t.width/2,(t.door.low+t.door.high)/2,(t.door.from+t.door.to)/2]}}:{},...t.anchors}};return{kind:t.kind??"vehicle",family:"vehicle",summary:t.summary??"A wheeled vehicle",rig:c,actions:Xb(t),acting:yd,colors:{body:e.body,ink:"#26262b"},follow:t.antenna?[{control:"antenna",of:"x",per:.9,stiffness:140,damping:7,limit:35}]:void 0,wheelRadius:r,...t.wheels.length>0?{moves:{drive:{speed:t.speed??6,perMetre:{wheelSpin:180/(Math.PI*r)}}}}:{}}}function md(t){const e=[...(t.body??[]).map(([s])=>s),...(t.frame??[]).flatMap(s=>s.points.map(i=>i[2])),...t.wheels.flatMap(s=>[s.forward+s.radius,s.forward-s.radius])],n=[...(t.body??[]).map(([,s])=>s),...(t.cabin?.profile??[]).map(([,s])=>s),...(t.frame??[]).flatMap(s=>s.points.map(i=>i[1])),...t.wheels.map(s=>s.radius*2)];return{forwardMost:Math.max(...e),backMost:Math.min(...e),top:Math.max(...n)}}const yd={depth:{turn:0,lift:0,lights:0,pitch:1,roll:1,squash:1,lean:1,door:2},limits:{turn:.08,pitch:5,roll:4,lean:.1,squash:.06,door:.12,lift:0},eyes:[],headTurns:{},drift:[]};function bi(t,e,n,s,i,o,r=!1){const a=t.facing()||Math.sign(s-t.x)||1,l=t.values.wheelSpin??0,c=(s-t.x)*a/t.scale;t.set("wheelSpin",e,l),t.move(e,n,s,{easing:i}),t.set("wheelSpin",n,r?l:l+c/o*(180/Math.PI),i)}const bd=.4;function Xb(t){const e=t.wheels[0]?.radius??.4,{forwardMost:n,backMost:s}=md(t),i=(n-s)/2,o=(a,l,c)=>{const h=a.exaggeration;let u=l;return a.facing()!==c&&(u=a.turnTo(u,c>0?"right":"left")),a.key(u+200,{pitch:4*h,squash:1-.07*h,lean:-.1*h},{act:!1,easing:"ease-out"}),bi(a,u,u+200,a.x-c*.15*h*a.scale,"ease-out",e),a.effect({kind:"exhaust",time:u+150,x:a.x-c*i*a.scale,y:a.floor-.3*a.scale,length:900,direction:-c}),u+260},r=(a,l,c)=>{const h=a.exaggeration*(c?1.8:1);a.key(l,{pitch:-5*h,lean:-.08*h,squash:.95},{act:!1,easing:"ease-out"}),a.key(l+380,{pitch:0,lean:0,squash:1})};return{drive:{summary:"Drives to `to`: rocks back and squats, lunges forward stretched, and stops with a nose-dive that settles; wheels roll exactly the distance.",needs:["to"],uses:["speed","for"],run(a,l,c){const h=Math.sign(l.to-a.x);if(h===0)return{end:c};const u=o(a,c,h),d=a.exaggeration,f=Math.abs(l.to-a.x),g=l.for??Math.max(500,f/(l.speed??bd));return a.effect({kind:"dust",time:u,x:a.x-h*i*a.scale,y:a.floor,length:600,direction:-h}),a.key(u+140,{pitch:-1.5*d,squash:1+.05*d,lean:.12*d},{act:!1,easing:"ease-out"}),a.key(u+Math.max(160,g-160),{pitch:0,lean:.08*d,squash:1.02},{act:!1}),bi(a,u,u+g,l.to,"ease-in-out",e),r(a,u+g,!1),{end:u+g+380,contact:u,release:u+g}}},brake:{summary:"Drives toward `to` and slams on the brakes: the wheels lock and it skids the last stretch, nose diving, leaving skid marks.",needs:["to"],uses:["speed","for"],run(a,l,c){const h=Math.sign(l.to-a.x);if(h===0)return{end:c};const u=o(a,c,h),d=a.exaggeration,f=a.x,g=Math.abs(l.to-f),p=l.for??Math.max(600,g/(l.speed??bd*1.2)),m=u+p*.55,b=f+(l.to-f)*.65;return a.key(u+140,{pitch:-1.5*d,squash:1+.06*d,lean:.14*d},{act:!1,easing:"ease-out"}),bi(a,u,m,b,"ease-in",e),a.key(m+80,{pitch:-7*d,lean:-.12*d,squash:.94},{act:!1,easing:"ease-out"}),bi(a,m,u+p,l.to,"ease-out",e,!0),a.effect({kind:"skid",time:m,x:b,toX:l.to,y:a.floor,length:p*.45+1500}),a.effect({kind:"dust",time:u+p,x:l.to+h*i*a.scale,y:a.floor,length:600,direction:h}),r(a,u+p,!0),{end:u+p+380,contact:m,release:u+p}}},bump:{summary:"Hits a bump: squashes, hops up stretched, lands squashed with dust, and springs back.",uses:["for"],run(a,l,c){const h=a.exaggeration;return a.key(c+90,{squash:1-.16*h,pitch:3*h},{act:!1,easing:"ease-out"}),a.key(c+300,{lift:.35*h,squash:1+.12*h,pitch:-3*h},{act:!1,easing:"ease-out"}),a.key(c+540,{lift:0,squash:1-.2*h,pitch:0},{act:!1,easing:"ease-in"}),a.key(c+820,{squash:1}),a.effect({kind:"dust",time:c+540,x:a.x,y:a.floor,length:500}),{end:c+820,contact:c+540}}},honk:{summary:"Honks: a stretch and squash pulse, with honk lines from the front.",run(a,l,c){const h=a.exaggeration;a.key(c+110,{squash:1+.12*h,lean:.04*h},{act:!1,easing:"ease-out"}),a.key(c+240,{squash:1-.06*h,lean:0},{act:!1}),a.key(c+520,{squash:1});const u=a.facing();return a.effect({kind:"honk",time:c+60,x:a.x+(u||1)*i*a.scale,y:a.floor-.7*a.scale,length:700,direction:u||1}),{end:c+520,contact:c+60}}},...t.door?{door:{summary:"Opens the doors (`open: true`) or shuts them (`open: false`).",needs:["open"],run(a,l,c){return a.key(c+450,{door:l.open?1:0}),{end:c+600,contact:c+450}}}}:{},...t.lights?{lights:{summary:"Switches the lights on (`on: true`) or off.",needs:["on"],run(a,l,c){return a.key(c+120,{lights:l.on?1:0},{act:!1}),{end:c+300,contact:c+120}}}}:{}}}function wd(t={}){return se({kind:"car",summary:"A cartoon car: drives, brakes, bumps, honks, opens its doors, lights up, and turns toward the camera.",body:[[-2,.32],[2,.32],[2.08,.52],[1.98,.82],[1.05,.95],[-1.72,.98],[-2.02,.86],[-2.08,.5]],width:1.8,cabin:{profile:[[-1.5,.94],[.92,.94],[.3,1.52],[-1.22,1.54]],width:1.56,pillars:[-.42]},wheels:[{forward:1.28,side:.8,radius:.4},{forward:-1.28,side:.8,radius:.4}],door:{from:-.4,to:.88,low:.36,high:.92},lights:{across:.58,low:.55,high:.72,front:2.05,back:-2.06},antenna:t.antenna===!1?void 0:[.5,1.5,-1.05],seat:[0,.3,-.15],colors:t.colors})}function kd(t={}){return se({kind:"truck",summary:"A box truck: drives, brakes, bumps, honks, opens its cab doors, lights up, turns toward the camera.",body:[[-3.2,.5],[3.1,.5],[3.15,.95],[3,1.85],[2.3,2.25],[1.2,2.25],[1.2,1],[-3.2,1]],width:2,cabin:{profile:[[1.6,1.35],[2.95,1.35],[2.85,1.85],[2.3,2.15],[1.6,2.15]],width:2.04},extras:[{id:"cargo",shape:{type:"box",size:[2.1,1.75,4.2]},at:[0,1.9,-1.05],fill:t.cargo??"#f1f1ee"}],wheels:[{forward:2.2,side:.85,radius:.48,thickness:.32},{forward:-1.4,side:.85,radius:.48,thickness:.32},{forward:-2.45,side:.85,radius:.48,thickness:.32}],door:{from:1.4,to:2.25,low:.6,high:1.9},lights:{across:.7,low:.62,high:.82,front:3.13,back:-3.22,size:.28},seat:[0,1.15,1.9],colors:{body:"#2f6fb7",...t.colors}})}function vd(t={}){return se({kind:"bus",summary:"A bus: drives, brakes, bumps, honks, opens its front doors, lights its windows, turns toward the camera.",body:[[-4.5,.45],[4.5,.45],[4.6,.9],[4.55,2.9],[4.3,3],[-4.4,3],[-4.55,2.75],[-4.55,.6]],width:2.4,windows:Array.from({length:6},(e,n)=>({from:-4+n*1.18,to:-4+n*1.18+1,low:1.55,high:2.6})),extras:[{id:"windscreen",shape:{type:"panel",points:[[-1.05,1.35],[1.05,1.35],[1.05,2.75],[-1.05,2.75]],facing:"front"},at:[0,0,4.58],fill:"#bfe3f2",outline:.8,seeThrough:!0}],wheels:[{forward:3,side:1,radius:.5,thickness:.34},{forward:-2.8,side:1,radius:.5,thickness:.34}],door:{from:3.2,to:4.2,low:.5,high:2.6},lights:{across:.85,low:.65,high:.85,front:4.6,back:-4.56,size:.3},seat:[0,1.2,3.6],colors:{body:"#f2c230",...t.colors}})}function Md(t={}){return se({kind:"tractor",summary:"A tractor: big rear wheels and small front ones turning at their own rates; drives, brakes, bumps, honks.",body:[[-.5,.75],[2,.75],[2.12,1.25],[1.9,1.52],[-.5,1.52]],width:1,cabin:{profile:[[-1.35,1],[-.25,1],[-.25,2.55],[-1.35,2.55]],width:1.35},extras:[{id:"roof",shape:{type:"box",size:[1.55,.1,1.35]},at:[0,2.62,-.8],fill:"#3f9b47"},{id:"exhaust",shape:{type:"tube",points:[[.28,1.5,1.25],[.28,2.35,1.25]],radius:.06,segments:6},fill:"#3b3b44",outline:.7}],wheels:[{forward:-.85,side:.85,radius:.78,thickness:.45},{forward:1.55,side:.7,radius:.42,thickness:.26}],lights:{across:.3,low:1,high:1.18,front:2.1,back:-.52,size:.2},seat:[0,1.25,-.8],colors:{body:"#3f9b47",hub:"#e9c64a",...t.colors}})}function Sd(t={}){const e=t.colors?.body??"#a8743f";return se({kind:"cart",summary:"A wooden cart on spoked wheels with shafts: rolls when pulled (drive), bumps, tips.",body:[[-1.25,.78],[1.25,.78],[1.35,1.18],[-1.35,1.18]],width:1.4,frame:[{points:[[.5,.9,1],[.5,.95,2.7]],radius:.05,color:e},{points:[[-.5,.9,1],[-.5,.95,2.7]],radius:.05,color:e}],wheels:[{forward:0,side:.82,radius:.66,style:"spoked"}],seat:[0,1.2,0],anchors:{shafts:{at:[0,.95,2.7]}},colors:{body:e,tyre:"#5a3a1f",...t.colors}})}function Td(t={}){return se({kind:"train carriage",summary:"A railway carriage: rolls along (drive), brakes, lights its windows, turns toward the camera.",body:[[-4,.72],[4,.72],[4,2.8],[3.6,3.12],[-3.6,3.12],[-4,2.8]],width:2.6,windows:Array.from({length:5},(e,n)=>({from:-3.3+n*1.4,to:-3.3+n*1.4+1,low:1.7,high:2.5})),wheels:[{forward:3,side:1,radius:.36,thickness:.16},{forward:2.2,side:1,radius:.36,thickness:.16},{forward:-2.2,side:1,radius:.36,thickness:.16},{forward:-3,side:1,radius:.36,thickness:.16}],lights:{across:.9,low:1,high:1.2,front:4.01,back:-4.01,size:.22},seat:[0,1,1.5],colors:{body:"#2f7d6d",...t.colors}})}function Ed(t={}){const e=t.colors?.body??"#e0473b",n=[0,.32,-.05],s=[0,.86,-.22],i=[0,.9,.42],o=[0,.34,.56],r=[0,.34,-.56];return se({kind:"bike",summary:"A bicycle: rides (drive) with its wire wheels turning, brakes, bumps, rings its bell (honk).",width:.5,frame:[{points:[r,n]},{points:[n,s]},{points:[s,r]},{points:[s,i]},{points:[n,i]},{points:[i,o]},{points:[[.24,.98,.44],[-.24,.98,.44]],radius:.025,color:"#3b3b44"},{points:[i,[0,.98,.44]],radius:.025,color:"#3b3b44"}],extras:[{id:"saddle",shape:{type:"ellipsoid",radii:[.08,.035,.15],segments:10},at:[0,.89,-.22],fill:"#3b3b44",outline:.7}],wheels:[{forward:.56,side:0,radius:.34,style:"spoked"},{forward:-.56,side:0,radius:.34,style:"spoked"}],seat:[0,.9,-.22],colors:{body:e,tyre:"#2c2c33",...t.colors}})}function Ad(t={}){return se({kind:"motorbike",summary:"A motorbike: rides (drive) with a lunge, brakes into a skid, bumps, honks, lights up.",body:[[-.62,.62],[.42,.62],[.55,.95],[.3,1.02],[-.1,.92],[-.8,.88],[-.86,.72]],width:.4,frame:[{points:[[0,.33,.78],[0,1.05,.5]],radius:.04,color:"#8c8f98"},{points:[[.3,1.08,.48],[-.3,1.08,.48]],radius:.025,color:"#3b3b44"},{points:[[.12,.42,-.2],[.12,.5,-.95]],radius:.04,color:"#8c8f98"}],extras:[{id:"engine",shape:{type:"box",size:[.38,.34,.5]},at:[0,.45,.05],fill:"#5b5f6a",outline:.8}],wheels:[{forward:.78,side:0,radius:.33,thickness:.14},{forward:-.72,side:0,radius:.33,thickness:.14}],lights:{across:0,low:.9,high:1.04,front:.62,back:-.87,size:.14},seat:[0,.92,-.3],colors:{body:"#1f1f26",hub:"#c9ccd3",...t.colors}})}function Pd(t={}){const e=t.height??2.4,n=t.trunkRadius??.16,s=t.canopy?.radius??1.1,i=t.canopy?.shape==="tall",o={trunk:"#8a5a3b",leaves:"#5cae5a",...t.colors},r=Xe(t.canopy?.seed??7),a=[{id:"trunk",shape:{type:"tube",points:[[0,0,0],[.06,e*.5,0],[-.02,e,0]],radius:n,segments:8},fill:o.trunk},{id:"branch",parent:"trunk",shape:{type:"tube",points:[[0,0,0],[.45,.4,.1]],radius:n*.45,segments:6},at:[.04,e*.62,0],fill:o.trunk},{id:"canopy",parent:"trunk",shape:{type:"ellipsoid",radii:[s,s*(i?1.35:.88),s],segments:14},at:[-.02,e+s*.55,0],fill:o.leaves}],l=t.canopy?.lobes??7;for(let h=0;h<l;h++){const u=Math.PI*2*h/l+r.next()*.6,d=(r.next()-.25)*s*(i?1.1:.7),f=s*(.48+r.next()*.22),g=[Math.cos(u)*s*.78,d,Math.sin(u)*s*.6];a.push({id:`lobe-${h}`,parent:"canopy",shape:{type:"ellipsoid",radii:[f,f*.86,f],segments:12},at:g,fill:o.leaves})}const c={parts:a,controls:{sway:{description:"The whole tree bending in the wind, about its base",unit:"degrees",bind:[{parts:["trunk"],rotate:{axis:"z",degrees:1}}]},canopySway:{description:"The canopy bending further than the trunk (it trails the sway)",unit:"degrees",bind:[{parts:["canopy"],rotate:{axis:"z",degrees:1,pivot:[0,-s*.8,0]}}]}},length:s*2.2,height:e+s*2,footprint:[s*1.6,s*1.6],anchors:{canopy:{part:"canopy",at:[0,0,0]},top:{part:"canopy",at:[0,s*.9,0]},base:{at:[0,0,0]},branch:{part:"branch",at:[.45,.4,.1]}}};return{kind:t.kind??"tree",family:"plant",summary:t.summary??"A tree: sways in the wind with its canopy trailing, shakes, sheds leaves, pops up.",rig:c,actions:Gb(),acting:$d,colors:{body:o.leaves}}}const $d={depth:{sway:1,canopySway:2,size:0,squash:1},limits:{sway:2,canopySway:3,squash:.08},eyes:[],headTurns:{},drift:[]};function Gb(){const t=(e,n,s,i)=>{const o=e.anchor("canopy");e.effect({kind:"leaves",time:n,x:o.x,y:o.y,length:s,direction:i,toY:e.floor})};return{sway:{summary:"Sways in gusts of `wind` (0..1, default 0.5) for `for` ms (default 3000); the canopy trails the trunk, and a strong wind sheds leaves.",uses:["wind","for"],run(e,n,s){const i=n.wind??.5,o=n.for??3e3,r=e.exaggeration,a=260;let l=0;for(let c=a;c<o;c+=a){const h=.55+.45*Math.sin(c/o*Math.PI*2.3),u=Math.sin(c/170)*.35,d=-i*9*r*(h+u*i);e.key(s+c,{sway:d,canopySway:l*1.3},{act:!1,easing:"ease-in-out"}),l=d}if(e.key(s+o,{sway:0,canopySway:0}),i>.45)for(let c=0;c<o;c+=700)t(e,s+c,2200,1);return{end:s+o}}},shake:{summary:"Shakes (something hit it): a quick wobble that dies away, shedding leaves.",uses:["for"],run(e,n,s){const i=n.for??900,o=e.exaggeration,r=6;for(let a=1;a<=r;a++){const l=1-a/(r+1),c=a%2===0?1:-1;e.key(s+i*a/(r+1),{sway:c*5*o*l,canopySway:-c*6*o*l},{act:!1,easing:"ease-in-out"})}return e.key(s+i,{sway:0,canopySway:0}),t(e,s+60,1800,1),t(e,s+260,1800,-1),{end:s+i,contact:s}}},shedLeaves:{summary:"Leaves fall from the canopy for `for` ms (default 2000).",uses:["for"],run(e,n,s){const i=n.for??2e3;for(let o=0;o<i;o+=500)t(e,s+o,2e3,o%1e3===0?1:-1);return{end:s+i}}}}}function xd(t={}){const e=t.width??4,n=t.depth??3.2,s=t.wallHeight??2.5,i=t.roofHeight??1.5,o=t.overhang??.25,r={walls:"#f1d9a8",roof:"#b8433a",door:"#7a4b2a",doorway:"#3a2a22",glass:"#bfe3f2",lit:"#ffd66b",chimney:"#9b5a45",...t.colors},a=n/2+.01,l=t.door?.width??.9,c=t.door?.height??1.9,h=t.door?.at??0,u=t.windows??[{at:-1.25,low:1,width:.8,height:.8},{at:1.25,low:1,width:.8,height:.8}],d=[{id:"walls",shape:{type:"box",size:[e,s,n]},at:[0,s/2,0],fill:r.walls},{id:"roof",shape:{type:"extrude",profile:[[-n/2-o,s],[n/2+o,s],[0,s+i]],width:e+o*2},fill:r.roof,layer:1},{id:"doorway",shape:{type:"panel",points:[[0,0],[l,0],[l,c],[0,c]],facing:"front"},at:[h-l/2,0,a-.005],fill:r.doorway,outline:.6,seeThrough:!0},{id:"door",shape:{type:"panel",points:[[0,0],[l,0],[l,c],[0,c]],facing:"front"},at:[h-l/2,0,a+.005],fill:r.door,outline:.8,overRider:!0}];u.forEach((p,m)=>{d.push({id:`window-${m}`,shape:{type:"panel",points:[[-p.width/2,p.low],[p.width/2,p.low],[p.width/2,p.low+p.height],[-p.width/2,p.low+p.height]],facing:"front"},at:[p.at,0,a+.01],fill:r.glass,outline:.8,glow:{control:"lights",color:r.lit}})});for(const p of[1,-1])d.push({id:`side-window-${p>0?"left":"right"}`,shape:{type:"panel",points:[[-.4,1],[.4,1],[.4,1.8],[-.4,1.8]],facing:p>0?"left":"right"},at:[p*(e/2+.01),0,0],fill:r.glass,outline:.8,glow:{control:"lights",color:r.lit}});const f=t.chimney===!1?void 0:{at:t.chimney?.at??e*.28,back:t.chimney?.back??-n*.18};if(f){const p=s+i*(1-Math.abs(f.back)/(n/2+o)),m=s+i+.45;d.push({id:"chimney",shape:{type:"box",size:[.42,m-p+.3,.42]},at:[f.at,(m+p-.3)/2,f.back],fill:r.chimney,layer:1})}const g={parts:d,controls:{door:{description:"The front door open: 0 shut, 1 open",unit:"0..1",min:0,max:1,bind:[{parts:["door"],rotate:{axis:"y",degrees:-80}}]},lights:{description:"The windows lit: 0 dark, 1 lit",unit:"0..1",min:0,max:1}},length:n+o*2,height:s+i+.6,footprint:[e+.6,n+.6],anchors:{door:{at:[h,c/2,a]},doorstep:{at:[h,0,a+.4]},ridge:{at:[0,s+i,0]},...f?{chimney:{at:[f.at,s+i+.5,f.back]}}:{}}};return{kind:t.kind??"house",family:"building",summary:t.summary??"A house: opens its door, lights its windows, puffs chimney smoke, shakes, pops up.",rig:g,actions:Ub(!!f),acting:_d,colors:{body:r.walls}}}const _d={depth:{door:1,lights:0,roll:1,squash:1,size:0},limits:{door:.1,roll:1.5,squash:.05},eyes:[],headTurns:{},drift:[]};function Ub(t){return{door:{summary:"Opens the front door (`open: true`) or shuts it (`open: false`).",needs:["open"],run(e,n,s){return e.key(s+500,{door:n.open?1:0}),{end:s+650,contact:s+500}}},lights:{summary:"Lights the windows (`on: true`) or puts them out.",needs:["on"],run(e,n,s){return e.key(s+150,{lights:n.on?1:0},{act:!1}),{end:s+300,contact:s+150}}},shake:{summary:"Shakes, as when a door slams or something lands on it: a squash and a wobble that dies away, with dust.",uses:["for"],run(e,n,s){const i=n.for??700,o=e.exaggeration;e.key(s+80,{squash:1-.06*o},{act:!1,easing:"ease-out"});for(let r=1;r<=5;r++){const a=1-r/6;e.key(s+80+i*r/6,{roll:(r%2===0?1:-1)*2.2*o*a,squash:1+.02*a},{act:!1,easing:"ease-in-out"})}return e.key(s+i+80,{roll:0,squash:1}),e.effect({kind:"dust",time:s+80,x:e.x,y:e.floor,length:600}),{end:s+i+80,contact:s+80}}},...t?{smoke:{summary:"Starts smoke puffing from the chimney for `for` ms (default 3000), drifting with the wind; the next beat starts at once (the smoke carries on).",uses:["for","wind"],run(e,n,s){const i=n.for??3e3,o=e.anchor("chimney");return e.effect({kind:"smoke",time:s,x:o.x,y:o.y,length:i+1500,direction:(n.wind??.4)>=0?1:-1}),{end:s+50,release:s+i}}}}:{}}}function Id(t={}){const e={body:"#3f86c8",glass:"#cfeaf5",trim:"#2c2c33",rotor:"#3b3b44",...t.colors},n=2.15,i={parts:[{id:"cabin",shape:{type:"extrude",profile:[[-1.2,.6],[.9,.55],[1.6,.85],[1.65,1.25],[1.2,1.75],[-.6,1.85],[-1.3,1.45]],width:1.5},fill:e.body},{id:"window",shape:{type:"extrude",profile:[[.75,1],[1.6,.95],[1.6,1.3],[1.15,1.72],[.6,1.72]],width:1.54},fill:e.glass,outline:.8},{id:"boom",shape:{type:"tube",points:[[0,1.4,-1.2],[0,1.55,-3.4]],radius:.16,segments:8},fill:e.body},{id:"fin",shape:{type:"extrude",profile:[[-3.55,1.45],[-3.2,1.5],[-3.35,2.25],[-3.6,2.25]],width:.12},fill:e.body},{id:"mast",shape:{type:"tube",points:[[0,1.82,.1],[0,n,.1]],radius:.07,segments:6},fill:e.trim},{id:"rotor-disc",shape:{type:"cylinder",radius:2.4,length:.01,axis:"y",segments:28},at:[0,n+.02,.1],fill:"#c9d4dd",outline:.4,fade:{control:"blur",from:0,to:.45}},{id:"blades",shape:{type:"box",size:[.16,.03,4.8]},at:[0,n+.05,.1],fill:e.rotor,outline:.7,fade:{control:"blur",from:1,to:.3}},{id:"tail-rotor",shape:{type:"box",size:[.04,.9,.12]},at:[.12,1.85,-3.45],fill:e.rotor,outline:.6},{id:"skid-left",shape:{type:"tube",points:[[0,.08,-1.1],[0,.08,1.2],[0,.22,1.45]],radius:.05,segments:6},at:[.7,0,0],fill:e.trim},{id:"skid-right",shape:{type:"tube",points:[[0,.08,-1.1],[0,.08,1.2],[0,.22,1.45]],radius:.05,segments:6},at:[-.7,0,0],fill:e.trim},{id:"strut-left",shape:{type:"tube",points:[[.7,.08,.6],[.55,.62,.5]],radius:.04,segments:5},fill:e.trim},{id:"strut-right",shape:{type:"tube",points:[[-.7,.08,.6],[-.55,.62,.5]],radius:.04,segments:5},fill:e.trim}],controls:{rotor:{description:"How far the rotors have turned (keyed exactly, not acted; the blades blur into a disc when they spin fast)",unit:"degrees",bind:[{parts:["blades"],rotate:{axis:"y",degrees:1}},{parts:["tail-rotor"],rotate:{axis:"x",degrees:3,pivot:[0,0,0]}}]},blur:{description:"How blurred the main rotor is: 0 still blades, 1 a spinning disc",unit:"0..1",min:0,max:1}},length:5.2,height:2.4,footprint:[1.8,3.4],anchors:{seat:{at:[0,.75,.7]},door:{at:[-.76,1,.2]},rotor:{at:[0,n,.1]},skids:{at:[0,0,.2]},hook:{at:[0,.4,0]}}};return{kind:t.kind??"helicopter",family:"aircraft",summary:t.summary??"A cartoon helicopter: spools up and takes off, flies nose-down banking into its moves, hovers with a bob, and lands with a squash.",rig:i,actions:Vb(),acting:Zr,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:15,flies:!0,hold:{blur:1},perSecond:{rotor:ve*1e3}}}}}const Zr={depth:{turn:0,lift:0,blur:0,pitch:1,roll:1,squash:1,lean:1,size:0},limits:{turn:.08,pitch:6,roll:6,squash:.06,lift:.15},eyes:[],headTurns:{},drift:[]},ve=2.6;function Vb(){const t=(n,s,i,o,r)=>{const a=n.values.rotor??0;n.set("rotor",s,a);const l=r?o*(i-s)*.5:o*(i-s);n.set("rotor",i,a+l,r)},e=n=>n.values.lift>.05;return{takeOff:{summary:"Spools the rotor up (the skids squash as it bites), then lifts off nose-down to `height` metres (default 3).",uses:["height"],run(n,s,i){const o=n.exaggeration,r=s.height??3;t(n,i,i+900,ve,"ease-in"),n.key(i+900,{blur:1},{act:!1,easing:"ease-in"}),n.key(i+700,{squash:1-.08*o},{act:!1,easing:"ease-in"});const a=i+1e3;return n.key(a+150,{squash:1+.06*o,lift:.3},{act:!1,easing:"ease-out"}),n.key(a+1300,{squash:1,lift:r,pitch:-4*o},{act:!1,easing:"ease-in-out"}),n.key(a+1700,{pitch:0}),t(n,i+900,a+1700,ve),n.effect({kind:"dust",time:a,x:n.x,y:n.floor,length:900}),{end:a+1700,contact:a}}},fly:{summary:"Flies to `to` (and to `height`, if given): nose down and banked into the move, nose up and leveling as it stops.",needs:["to"],uses:["height","speed","for"],run(n,s,i){const o=n.exaggeration,r=Math.sign(s.to-n.x);let a=i;r!==0&&n.facing()!==r&&(a=n.turnTo(a,r>0?"right":"left"));const l=Math.abs(s.to-n.x),c=s.for??Math.max(700,l/(s.speed??.3)),h=s.height??n.values.lift;return n.key(a+300,{pitch:-9*o,roll:6*o},{act:!1,easing:"ease-out"}),n.key(a+c-250,{pitch:-4*o,roll:3*o,lift:h},{act:!1}),n.key(a+c,{pitch:7*o,roll:0},{act:!1,easing:"ease-out"}),n.key(a+c+450,{pitch:0}),n.move(a,a+c,s.to,{easing:"ease-in-out"}),t(n,i,a+c+450,ve),{end:a+c+450,contact:a,release:a+c}}},hover:{summary:"Hovers in place for `for` ms (default 2000), bobbing gently.",uses:["for"],run(n,s,i){const o=s.for??2e3,r=n.values.lift,a=n.exaggeration;for(let l=350,c=0;l<o;l+=350,c++)n.key(i+l,{lift:r+(c%2===0?.12:-.06)*a,roll:(c%2===0?1.5:-1.5)*a},{act:!1,easing:"ease-in-out"});return n.key(i+o,{lift:r,roll:0},{act:!1,easing:"ease-in-out"}),(e(n)||r>0)&&t(n,i,i+o,ve),{end:i+o}}},land:{summary:"Settles down onto its skids: a flare, a squash on touchdown with dust, and the rotor spools down.",run(n,s,i){const o=n.exaggeration,r=i+Math.max(900,n.values.lift*450);return n.key(i+400,{pitch:3*o},{act:!1,easing:"ease-out"}),n.key(r,{lift:0,pitch:0,squash:1-.14*o},{act:!1,easing:"ease-in"}),n.key(r+280,{squash:1}),t(n,i,r,ve),t(n,r,r+1600,ve,"ease-out"),n.key(r+1600,{blur:0},{act:!1,easing:"ease-out"}),n.effect({kind:"dust",time:r,x:n.x,y:n.floor,length:800}),{end:r+1600,contact:r}}}}}function Od(t={}){const e={body:"#e9e4d8",wings:"#d9483b",glass:"#cfeaf5",trim:"#2c2c33",...t.colors},n=3.15,i={parts:[{id:"fuselage",shape:{type:"extrude",profile:[[-3.7,1.55],[-2.6,1.05],[2.4,.85],[3,1],[3.1,1.4],[2.7,1.75],[1.4,1.9],[-2.9,1.85]],width:1},fill:e.body},{id:"canopy",shape:{type:"extrude",profile:[[.4,1.85],[1.6,1.85],[1.1,2.3],[.5,2.3]],width:.7},fill:e.glass,outline:.8},{id:"wing-left",shape:{type:"box",size:[3.6,.1,1.35]},at:[2.05,1.15,.55],fill:e.wings},{id:"wing-right",shape:{type:"box",size:[3.6,.1,1.35]},at:[-2.05,1.15,.55],fill:e.wings},{id:"tailplane-left",shape:{type:"box",size:[1.1,.07,.65]},at:[.6,1.7,-3.35],fill:e.wings},{id:"tailplane-right",shape:{type:"box",size:[1.1,.07,.65]},at:[-.6,1.7,-3.35],fill:e.wings},{id:"fin",shape:{type:"extrude",profile:[[-3.75,1.75],[-3,1.82],[-3.45,2.75],[-3.8,2.75]],width:.1},fill:e.wings},{id:"gear-left",shape:{type:"tube",points:[[.55,.95,1.2],[.75,.28,1.3]],radius:.04,segments:5},fill:e.trim},{id:"gear-right",shape:{type:"tube",points:[[-.55,.95,1.2],[-.75,.28,1.3]],radius:.04,segments:5},fill:e.trim},{id:"wheel-left",shape:{type:"cylinder",radius:.26,length:.14,axis:"x",segments:14},at:[.78,.26,1.3],fill:e.trim},{id:"wheel-right",shape:{type:"cylinder",radius:.26,length:.14,axis:"x",segments:14},at:[-.78,.26,1.3],fill:e.trim},{id:"tail-wheel",shape:{type:"cylinder",radius:.12,length:.08,axis:"x",segments:10},at:[0,.12,-3],fill:e.trim},{id:"tail-strut",shape:{type:"tube",points:[[0,.12,-3],[0,1.2,-2.9]],radius:.03,segments:5},fill:e.trim},{id:"spinner",shape:{type:"ellipsoid",radii:[.18,.18,.22],segments:10},at:[0,1.22,n],fill:e.wings,outline:.7},{id:"prop-disc",shape:{type:"cylinder",radius:.95,length:.01,axis:"z",segments:24},at:[0,1.22,n+.08],fill:"#c9d4dd",outline:.4,fade:{control:"blur",from:0,to:.45}},{id:"propeller",shape:{type:"box",size:[.12,1.85,.04]},at:[0,1.22,n+.1],fill:e.trim,outline:.6,fade:{control:"blur",from:1,to:.3}}],controls:{rotor:{description:"How far the propeller has turned (keyed exactly; it blurs into a disc at speed)",unit:"degrees",bind:[{parts:["propeller"],rotate:{axis:"z",degrees:1}}]},blur:{description:"How blurred the propeller is: 0 still, 1 a spinning disc",unit:"0..1",min:0,max:1}},length:7,height:2.8,footprint:[7.2,6.5],anchors:{seat:{at:[0,1.55,1]},nose:{at:[0,1.22,n+.2]},tail:{at:[0,1.6,-3.7]},wingtip:{at:[3.6,1.15,.55]}}};return{kind:t.kind??"airplane",family:"aircraft",summary:t.summary??"A propeller plane: takes off from a run, flies banked, loops the loop, and lands with a flare and a squash.",rig:i,actions:Zb(),acting:Zr,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:30,flies:!0,hold:{blur:1},perSecond:{rotor:ve*1e3}}}}}const Jb=3.2;function Zb(){const t=(n,s,i,o)=>{const r=n.values.rotor??0;n.set("rotor",s,r),n.set("rotor",i,r+Jb*(i-s)*(o?.5:1),o)},e=(n,s,i)=>{const o=Math.sign(i-n.x);return o!==0&&n.facing()!==o?n.turnTo(s,o>0?"right":"left"):s};return{takeOff:{summary:"Spins the propeller up, runs along the ground toward `to`, lifts its nose and climbs to `height` metres (default 4).",needs:["to"],uses:["height","for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to);t(n,r,r+700,"ease-in"),n.key(r+700,{blur:1},{act:!1,easing:"ease-in"});const a=s.for??2600,l=n.x,c=r+700+a*.55,h=l+(s.to-l)*.45;return n.move(r+700,c,h,{easing:"ease-in"}),n.key(c,{pitch:8*o,squash:1+.04*o},{act:!1,easing:"ease-out"}),n.key(r+700+a,{lift:s.height??4,pitch:10*o,squash:1},{act:!1,easing:"ease-in-out"}),n.move(c,r+700+a,s.to),n.key(r+700+a+500,{pitch:0}),t(n,r+700,r+700+a+500),n.effect({kind:"dust",time:c,x:h,y:n.floor,length:700}),{end:r+700+a+500,contact:c}}},fly:{summary:"Flies to `to` (and `height`), banking into the move and leveling out.",needs:["to"],uses:["height","speed","for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to),a=s.for??Math.max(800,Math.abs(s.to-n.x)/(s.speed??.45)),l=s.height??n.values.lift;return n.key(r+350,{roll:10*o,pitch:l>n.values.lift?6*o:-3*o},{act:!1,easing:"ease-out"}),n.key(r+a-300,{roll:4*o,lift:l},{act:!1}),n.key(r+a,{roll:0,pitch:0}),n.move(r,r+a,s.to,{easing:"ease-in-out"}),t(n,i,r+a),{end:r+a,contact:r,release:r+a}}},loop:{summary:"Loops the loop: pulls up and over in a full circle (`for` ms, default 2400), carrying on the way it was going.",uses:["for"],run(n,s,i){const o=s.for??2400,r=2.2*n.exaggeration,a=n.facing()||1,l=16,c=n.x,h=n.values.lift,u=n.values.pitch;for(let d=1;d<=l;d++){const f=Math.PI*2*d/l,g=i+o*d/l;n.key(g,{lift:h+r*(1-Math.cos(f)),pitch:u+360*d/l},{act:!1}),n.move(i+o*(d-1)/l,g,c+a*(r*Math.sin(f)+d/l*r*1.2)*n.scale)}return n.key(i+o+1,{pitch:u},{act:!1}),t(n,i,i+o),{end:i+o+1}}},land:{summary:"Comes down toward `to`: descends, flares nose-up, touches down with a squash and dust, rolls to a stop and the propeller spools down.",needs:["to"],uses:["for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to),a=n.x,l=s.for??2200,c=r+l,h=a+(s.to-a)*.7;return n.key(r+l*.4,{pitch:-4*o},{act:!1,easing:"ease-out"}),n.key(c-250,{pitch:6*o,lift:.15},{act:!1,easing:"ease-in-out"}),n.key(c,{lift:0,pitch:0,squash:1-.12*o},{act:!1,easing:"ease-in"}),n.key(c+260,{squash:1}),n.move(r,c,h),n.move(c,c+1200,s.to,{easing:"ease-out"}),t(n,i,c),t(n,c,c+1600,"ease-out"),n.key(c+1600,{blur:0},{act:!1,easing:"ease-out"}),n.effect({kind:"dust",time:c,x:h,y:n.floor,length:700}),{end:c+1600,contact:c}}}}}const gn=["walk","trot","canter","gallop"],Qb=gn,Cd=["fl","fr","hl","hr"],wi={walk:{offsets:{hl:0,fl:.25,hr:.5,fr:.75},swing:16,lift:45,bob:.02,rock:0,cycle:1100},trot:{offsets:{fl:0,hr:0,fr:.5,hl:.5},swing:22,lift:75,bob:.05,rock:0,cycle:640},canter:{offsets:{hr:0,hl:.33,fr:.33,fl:.66},swing:30,lift:70,bob:.08,rock:5,cycle:560},gallop:{offsets:{hr:0,hl:.1,fr:.5,fl:.6},swing:40,lift:80,bob:.1,rock:7,cycle:460}},Le=Math.PI/180;function ki(t,e){return 4*t*Math.sin(wi[e].swing*Le)}function Qn(t){const{legs:e,colors:n}=t,s=e.upper+e.lower+e.foot,i=s+t.body.rise,o=(u,d)=>[d*u[0],u[1],u[2]],r=[{id:"body",shape:{type:"ellipsoid",radii:t.body.radii,segments:18},at:[0,i,0],fill:n.coat},{id:"neck",shape:{type:"tube",points:t.neck.points,radius:t.neck.points.map((u,d,f)=>t.neck.radius*(1.25-.4*d/Math.max(1,f.length-1))),segments:12},at:t.neck.at,fill:n.coat},{id:"head",parent:"neck",shape:{type:"ellipsoid",radii:t.head.radii,segments:14},at:t.head.at,rotate:t.head.rotate,fill:n.coat},...ew(t,n,i)];t.mane&&r.push({id:"mane",parent:"neck",shape:{type:"tube",points:t.mane.points,radius:t.mane.radius,segments:6},fill:n.dark,outline:.7}),t.muzzle&&r.push({id:"muzzle",parent:"head",shape:{type:"ellipsoid",radii:t.muzzle.radii,segments:10},at:t.muzzle.at,fill:n.muzzle,outline:.8});for(const u of[1,-1]){const d=u>0?"left":"right",f=t.ears.rotate?o(t.ears.rotate,1).map((g,p)=>p===2?u*g:g):void 0;r.push({id:`ear-${d}`,parent:"head",shape:{type:"ellipsoid",radii:t.ears.radii,segments:8},at:o(t.ears.at,u),rotate:f,fill:n.coat,outline:.7},{id:`eye-${d}`,parent:"head",shape:{type:"ellipsoid",radii:[t.eyes.size*.8,t.eyes.size,t.eyes.size*.9],segments:8},at:o(t.eyes.at,u),fill:"#1d1d22",outline:.4})}r.push(...t.extras?.(n)??[]);const a={walk:{description:"Phase of the stride, in full cycles (keyed in step with the distance covered)",unit:"cycles"},walking:{description:"How much of the gait is applied: 0 standing, 1 moving",unit:"0..1",min:0,max:1},gait:{description:`Which gait: ${t.gaits.map(u=>`${gn.indexOf(u)} ${u}`).join(", ")}`,unit:"index",min:0,max:3},neck:{description:"Neck bent down (+, eating, sniffing) or up (−, alert)",unit:"degrees",bind:[{parts:["neck"],rotate:{axis:"x",degrees:1}}]},tail:{description:"Tail flicked up and back (+), curling along its length, on a spring behind the motion",unit:"degrees",bind:[{parts:Xt,rotate:{axis:"x",degrees:1/Xt.length}}]},wag:{description:"Tail swung side to side, curling",unit:"degrees",bind:[{parts:Xt,rotate:{axis:"y",degrees:1/Xt.length}}]}};for(const u of Cd){const d=u[0]==="f",f=u[1]==="l"?1:-1,g=d?e.thickness[0]:e.thickness[1];r.push({id:`${u}-upper`,shape:{type:"tube",points:[[0,e.upper*.2,0],[0,-e.upper*.5,0],[0,-e.upper,0]],radius:[g,g*.85,e.lowerThickness*1.15],segments:10},at:[f*e.across,s,d?e.front:e.hind],fill:n.coat},{id:`${u}-knee`,parent:`${u}-upper`,shape:{type:"ellipsoid",radii:Array(3).fill(e.lowerThickness*1.08),segments:10},at:[0,-e.upper,0],fill:n.coat,solidOnly:!0},{id:`${u}-lower`,parent:`${u}-upper`,shape:{type:"tube",points:[[0,0,0],[0,-e.lower,0]],radius:[e.lowerThickness*1.1,e.lowerThickness*.85],segments:10},at:[0,-e.upper,0],fill:n.coat},{id:`${u}-foot`,parent:`${u}-lower`,shape:{type:"ellipsoid",radii:[e.footSize[0]/2,e.foot/2+.004,e.footSize[1]/2],segments:12},at:[0,-e.lower-e.foot/2,e.footSize[1]*.12],fill:n.foot,outline:.8});const p=`${d?"Front":"Hind"} ${f>0?"left":"right"} leg`;a[`${u}.swing`]={description:`${p}: forward (+) or back (−) from the hip`,unit:"degrees",bind:[{parts:[`${u}-upper`],rotate:{axis:"x",degrees:-1}}]},a[`${u}.knee`]={description:`${p}: knee (hock) folded`,unit:"degrees",bind:[{parts:[`${u}-lower`],rotate:{axis:"x",degrees:d?1:-1}}]},a[`${u}.ankle`]={description:`${p}: foot turned at the ankle (+ toe forward)`,unit:"degrees",bind:[{parts:[`${u}-foot`],rotate:{axis:"x",degrees:-1,pivot:[0,e.foot/2,-e.footSize[1]*.12]}}]}}const l=t.neck.points[t.neck.points.length-1],c={parts:r,controls:a,length:t.body.radii[2]*2+Math.max(0,t.neck.at[2]+l[2]+t.head.radii[2]-t.body.radii[2])+.3,height:t.neck.at[1]+l[1]+t.head.radii[1]*2,footprint:[e.across*2+t.body.radii[0],(e.front-e.hind)*1.4],anchors:{back:{at:[0,i+t.body.radii[1],-t.body.radii[2]*.05]},head:{part:"head",at:[0,0,0]},mouth:{part:t.muzzle?"muzzle":"head",at:t.muzzle?[0,0,t.muzzle.radii[2]]:[0,0,t.head.radii[2]]},front:{at:[0,i,t.body.radii[2]]},...t.anchors},derive:u=>nw(u,t,s)},h={legLength:s,upper:e.upper,lower:e.lower,foot:e.foot,tailHangs:t.tail.points[t.tail.points.length-1][1]<0,front:e.front,hind:e.hind,call(u,d){const f=u.anchor("mouth");u.effect({kind:"honk",time:d,x:f.x,y:f.y,length:800,direction:u.facing()||1})}};return{kind:t.kind,family:"animal",summary:t.summary,rig:c,actions:{...iw(t,h),...t.actions?.(h)},acting:Qr,colors:{body:n.coat,ink:"#26262b"},follow:[{control:"tail",of:"x",per:.6,stiffness:90,damping:6,limit:40}],moves:tw(t,s)}}function tw(t,e){const n=i=>{const o=ki(e,i);return{speed:o/(wi[i].cycle*(t.cycleScale??1)/1e3),set:{gait:gn.indexOf(i)},hold:{walking:1},perMetre:{walk:1/o}}},s=Object.fromEntries(t.gaits.map(i=>[i==="gallop"&&!t.gaits.includes("canter")?"run":i,n(i)]));return t.gaits.includes("gallop")&&!s.gallop&&(s.gallop=n("gallop")),s}const Xt=Array.from({length:7},(t,e)=>e===0?"tail":`tail-${e}`);function ew(t,e,n){const s=gr(t.tail.points,Xt.length+1),[,i,o]=t.body.radii,r=(t.tail.at[1]-n)/i,a=Math.abs(r)<1?-o*Math.sqrt(1-r*r):t.tail.at[2],l=[t.tail.at[0],t.tail.at[1],a+Math.min(.04,o*.08)],c=f=>t.tail.radius*(1-.5*f/Xt.length),h=Xt.map((f,g)=>{const p=s[g],m=s[g+1],b=[m[0]-p[0],m[1]-p[1],m[2]-p[2]],k=g===0?void 0:s[g-1];return{id:f,...g>0?{parent:Xt[g-1]}:{},shape:{type:"tube",points:[[0,0,0],b],radius:[c(g),c(g+1)],segments:8,joined:!0},at:g===0?l:[p[0]-k[0],p[1]-k[1],p[2]-k[2]],fill:e.dark,outline:.8}}),u=s[s.length-1],d=s[s.length-2];return h.push({id:"tail-tip",parent:Xt[Xt.length-1],shape:{type:"ellipsoid",radii:Array(3).fill(c(Xt.length)*1.05),segments:8},at:[u[0]-d[0],u[1]-d[1],u[2]-d[2]],fill:e.dark,outline:.8,solidOnly:!0}),h}function nw(t,e,n){const s=Math.max(0,Math.min(1,t.walking??0));if(s===0)return{};const i=gn[Math.max(0,Math.min(3,Math.round(t.gait??0)))],o=wi[e.gaits.includes(i)?i:e.gaits[0]],r=t.walk??0,a={};for(const c of Cd){const h=Math.PI*2*(r+o.offsets[c]);a[`${c}.swing`]=(t[`${c}.swing`]??0)+s*o.swing*Math.sin(h),a[`${c}.knee`]=(t[`${c}.knee`]??0)+s*o.lift*Math.max(0,Math.cos(h))}const l=Math.PI*2*r;return a.lift=(t.lift??0)+s*o.bob*n*Math.abs(Math.sin(l*2)),a.pitch=(t.pitch??0)+s*o.rock*Math.sin(l),a.neck=(t.neck??0)+s*(o.rock>0?-o.rock*1.4:5)*Math.sin(l*2),a}function Hd(t){const n=Math.sin(32*Le),s=t.legLength-(t.front-t.hind)*n,i=72,r=(s-t.upper*Math.cos(i*Le)-t.foot)/t.lower,a=r>=1?0:r<=-1?180:Math.acos(r)/Le,l={pitch:32,lift:t.legLength*(1-Math.cos(32*Le))-t.front*n,neck:-10,tail:t.tailHangs?35:-40,"fl.swing":-32,"fr.swing":-32};for(const c of["hl","hr"])l[`${c}.swing`]=i-32,l[`${c}.knee`]=-(i+a),l[`${c}.ankle`]=a;return l}const Qr={depth:{turn:0,lift:0,pitch:1,roll:1,squash:1,neck:2,tail:3,wag:3,"fl.swing":2,"fr.swing":2,"hl.swing":2,"hr.swing":2,"fl.knee":3,"fr.knee":3,"hl.knee":3,"hr.knee":3},limits:{pitch:6,neck:8,tail:10,wag:8,"fl.swing":8,"fr.swing":8,"hl.swing":8,"hr.swing":8,lift:0},eyes:[],headTurns:{},drift:[]},sw=Qr;function iw(t,e){const n=t.cycleScale??1,s=r=>({summary:{walk:"Walks to `to` (four beats), its head bobbing.",trot:"Trots to `to`: legs in diagonal pairs, the body bouncing.",canter:"Canters to `to`: three beats, the body rocking.",gallop:"Gallops (runs) to `to`: legs reaching, the body rocking hard, kicking up dust."}[r],needs:["to"],uses:["for"],run(a,l,c){const h=Math.sign(l.to-a.x);if(h===0)return{end:c};let u=c;a.facing()!==h&&(u=a.turnTo(u,h>0?"right":"left"));const d=a.exaggeration;a.key(u+180,{neck:-12*d},{act:!1,easing:"ease-out"});const g=Math.abs(l.to-a.x)/a.scale/ki(e.legLength,r),p=l.for??Math.max(500,g*wi[r].cycle*n),m=a.values.walk??0;return a.set("gait",u,a.values.gait??0),a.set("gait",u+1,gn.indexOf(r)),a.set("walking",u,0),a.set("walking",u+240,1,"ease-out"),a.set("walking",u+p-240,1),a.set("walking",u+p,0,"ease-in"),a.set("walk",u,m),a.move(u,u+p,l.to,{easing:"ease-in-out"}),a.set("walk",u+p,m+g,"ease-in-out"),a.key(u+p+300,{neck:0}),(r==="gallop"||r==="canter")&&(a.effect({kind:"dust",time:u+200,x:a.x-h*e.legLength*a.scale,y:a.floor,length:700,direction:-h}),a.effect({kind:"dust",time:u+p,x:l.to+h*e.legLength*.6*a.scale,y:a.floor,length:600,direction:h})),{end:u+p+300,contact:u,release:u+p}}}),i=Object.fromEntries(t.gaits.map(r=>[r==="gallop"&&!t.gaits.includes("canter")?"run":r,s(r)]));t.gaits.includes("gallop")&&!i.gallop&&(i.gallop=s("gallop"));const o={...i,[t.call]:{summary:`Throws its head up and ${t.call}s.`,run(r,a,l){const c=r.exaggeration;return r.key(l+150,{neck:10*c},{act:!1,easing:"ease-out"}),r.key(l+380,{neck:-28*c,squash:1.05},{act:!1,easing:"ease-out"}),r.key(l+680,{neck:-20*c},{act:!1}),r.key(l+980,{neck:0,squash:1}),e.call(r,l+380),{end:l+980,contact:l+380}}},sit:{summary:"Sits on its haunches for `for` ms (default 1500): the rump goes down onto folded hind legs, paws flat on the ground, the front legs stay planted; then it gets up.",uses:["for"],run(r,a,l){const c=Hd(e),h=l+450;r.key(h,c,{act:!1,easing:"ease-in-out"}),r.key(h+(a.for??1500),c,{act:!1});const u=h+(a.for??1500)+450,d={};for(const f of Object.keys(c))d[f]=0;return r.key(u,d),{end:u,contact:h,release:u-450}}},jump:{summary:"Crouches and jumps (forward to `to`, or up on the spot), legs tucked in the air, landing with a squash and dust.",uses:["to"],run(r,a,l){const c=r.exaggeration,h=e.legLength*.8*c,u=l+260,d=u+90,f=d+520;if(r.key(u,{squash:.86,"hl.knee":40,"hr.knee":40,"fl.knee":25,"fr.knee":25,neck:8},{act:!1,easing:"ease-out"}),r.key(d,{squash:1.12,"hl.knee":0,"hr.knee":0,"fl.knee":0,"fr.knee":0,pitch:8,"fl.swing":35,"fr.swing":35,"hl.swing":-35,"hr.swing":-35},{act:!1,easing:"ease-out"}),r.key((d+f)/2,{lift:h,squash:1,pitch:0,"fl.knee":60,"fr.knee":60,"hl.knee":60,"hr.knee":60,"fl.swing":25,"fr.swing":25,"hl.swing":-20,"hr.swing":-20},{act:!1,easing:"ease-out"}),r.key(f,{lift:0,squash:.85,pitch:-4,"fl.knee":0,"fr.knee":0,"hl.knee":0,"hr.knee":0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0},{act:!1,easing:"ease-in"}),r.key(f+280,{squash:1,pitch:0,neck:0}),a.to!==void 0){const g=Math.sign(a.to-r.x);g!==0&&r.facing()!==g&&r.turnTo(l,g>0?"right":"left"),r.move(d,f,a.to)}return r.effect({kind:"dust",time:f,x:r.x,y:r.floor,length:550}),{end:f+280,contact:f}}},nod:{summary:"Nods its head twice.",run(r,a,l){return r.key(l+200,{neck:20},{act:!1,easing:"ease-out"}),r.key(l+400,{neck:-5},{act:!1,easing:"ease-in-out"}),r.key(l+600,{neck:18},{act:!1,easing:"ease-in-out"}),r.key(l+900,{neck:0}),{end:l+900}}},swish:{summary:"Swishes its tail a few times.",uses:["for"],run(r,a,l){const c=a.for??900;for(let h=1;h<=4;h++)r.key(l+c*h/5,{tail:h%2===0?10:35},{act:!1,easing:"ease-in-out"});return r.key(l+c,{tail:0}),{end:l+c}}}};return t.grazes&&(o.graze={summary:"Lowers its head to graze for `for` ms (default 1800), nibbling, then looks up.",uses:["for"],run(r,a,l){const c=a.for??1800;r.key(l+600,{neck:75},{act:!1,easing:"ease-in-out"});for(let h=900;h<600+c;h+=400)r.key(l+h,{neck:h%800===100?70:78},{act:!1,easing:"ease-in-out"});return r.key(l+600+c+500,{neck:0}),{end:l+600+c+500}}}),o}function Rd(t={}){return Qn({kind:t.kind??"horse",summary:t.summary??"A cartoon horse: walks, trots, canters and gallops with its hooves in step with the ground, rears, bucks, neighs, grazes and swishes its tail.",legs:{upper:.5,lower:.42,foot:.08,footSize:[.12,.16],front:.62,hind:-.62,across:.2,thickness:[.075,.09],lowerThickness:.05},body:{radii:[.32,.36,.95],rise:.25},neck:{at:[0,1.42,.7],points:[[0,0,0],[0,.5,.3]],radius:.15},head:{at:[0,.48,.5],radii:[.13,.14,.3],rotate:[38,0,0]},muzzle:{at:[0,-.02,.24],radii:[.11,.1,.1]},ears:{at:[.07,.16,-.17],radii:[.035,.1,.05]},eyes:{at:[.115,.05,-.04],size:.04},tail:{at:[0,1.4,-.9],points:[[0,0,0],[0,-.22,-.2],[0,-.62,-.24]],radius:.08},mane:{points:[[0,.1,-.12],[0,.55,.17]],radius:.07},colors:{coat:"#b5763a",dark:"#4a2e1a",foot:"#3a2a22",muzzle:"#8d5a2c",accent:"#e8c9a0",...t.colors},gaits:["walk","trot","canter","gallop"],call:"neigh",grazes:!0,anchors:{hitch:{at:[0,.95,-.15]},saddle:{at:[0,1.6,-.05]}},actions:e=>({rear:{summary:"Rears up on its hind legs, front legs tucked and pawing, neighs, and drops back down with dust.",uses:["for"],run(n,s,i){const o=n.exaggeration,r=Math.min(55,32*o),a=-e.hind*Math.sin(r*Le),l=s.for??700;n.key(i+200,{pitch:-4,neck:6,"hl.knee":12,"hr.knee":12},{act:!1,easing:"ease-out"}),n.key(i+520,{pitch:r,lift:a,neck:-25,"fl.swing":55,"fl.knee":95,"fr.swing":40,"fr.knee":80,"hl.knee":0,"hr.knee":0},{act:!1,easing:"ease-out"}),n.key(i+520+l*.5,{"fl.swing":35,"fl.knee":70,"fr.swing":58,"fr.knee":100},{act:!1,easing:"ease-in-out"}),n.key(i+520+l,{"fl.swing":55,"fl.knee":95,"fr.swing":40,"fr.knee":80},{act:!1,easing:"ease-in-out"});const c=i+520+l+380;return n.key(c,{pitch:0,lift:0,neck:8,squash:.94,"fl.swing":0,"fl.knee":0,"fr.swing":0,"fr.knee":0},{act:!1,easing:"ease-in"}),n.key(c+320,{neck:0,squash:1}),e.call(n,i+520),n.effect({kind:"dust",time:c,x:n.x+(n.facing()||1)*e.front*n.scale,y:n.floor,length:600}),{end:c+320,contact:c}}},buck:{summary:"Bucks: drops its head and kicks both hind legs up and back.",run(n,s,i){const o=n.exaggeration,r=Math.min(35,18*o),a=e.front*Math.sin(r*Le);return n.key(i+220,{pitch:3,squash:.95},{act:!1,easing:"ease-out"}),n.key(i+480,{pitch:-r,lift:a,neck:30,"hl.swing":-65,"hr.swing":-60,"hl.knee":10,"hr.knee":10},{act:!1,easing:"ease-out"}),n.key(i+900,{pitch:0,lift:0,neck:0,squash:.95,"hl.swing":0,"hr.swing":0,"hl.knee":0,"hr.knee":0},{act:!1,easing:"ease-in"}),n.key(i+1150,{squash:1}),n.effect({kind:"dust",time:i+900,x:n.x-(n.facing()||1)*.6*n.scale,y:n.floor,length:600}),{end:i+1150,contact:i+480}}}})})}function Ld(t={}){return Qn({kind:t.kind??"dog",summary:t.summary??"A cartoon dog: walks, trots and runs, barks, wags its tail, sits, jumps, sniffs the ground.",legs:{upper:.19,lower:.16,foot:.05,footSize:[.07,.1],front:.24,hind:-.24,across:.09,thickness:[.04,.05],lowerThickness:.032},body:{radii:[.14,.15,.36],rise:.1},neck:{at:[0,.56,.27],points:[[0,0,0],[0,.14,.06]],radius:.075},head:{at:[0,.15,.08],radii:[.12,.11,.13]},muzzle:{at:[0,-.03,.13],radii:[.065,.055,.08]},ears:{at:[.11,0,-.02],radii:[.025,.09,.05],rotate:[0,0,18]},eyes:{at:[.08,.04,.08],size:.025},tail:{at:[0,.58,-.34],points:[[0,0,0],[0,.1,-.08],[0,.2,-.1]],radius:.03},extras:e=>[{id:"nose",parent:"muzzle",shape:{type:"ellipsoid",radii:[.025,.02,.02],segments:8},at:[0,.03,.08],fill:"#1d1d22",outline:.4},{id:"patch",parent:"body",shape:{type:"ellipsoid",radii:[.012,.09,.11],segments:10},at:[.135,.04,-.06],fill:e.accent,outline:.5}],colors:{coat:"#d9a066",dark:"#a8703a",foot:"#a8703a",muzzle:"#f0d2a8",accent:"#f6ead8",...t.colors},gaits:["walk","trot","gallop"],cycleScale:.55,call:"bark",anchors:{leash:{part:"neck",at:[0,.06,0]}},actions:()=>({wag:{summary:"Wags its tail fast for `for` ms (default 1200).",uses:["for"],run(e,n,s){const i=n.for??1200;for(let o=80,r=0;o<i;o+=80,r++)e.key(s+o,{wag:r%2===0?35:-35,tail:25},{act:!1,easing:"ease-in-out"});return e.key(s+i,{wag:0,tail:0}),{end:s+i}}},sniff:{summary:"Puts its nose to the ground and sniffs (`for` ms, default 1400).",uses:["for"],run(e,n,s){const i=n.for??1400;e.key(s+350,{neck:70,pitch:-6},{act:!1,easing:"ease-in-out"});for(let o=500,r=0;o<i;o+=140,r++)e.key(s+o,{neck:r%2===0?74:66},{act:!1});return e.key(s+i+300,{neck:0,pitch:0}),{end:s+i+300}}}})})}function Fd(t={}){return Qn({kind:t.kind??"cat",summary:t.summary??"A cartoon cat: walks, trots and runs, meows, arches its back, pounces, sits and swishes its tail.",legs:{upper:.13,lower:.11,foot:.035,footSize:[.05,.07],front:.17,hind:-.18,across:.06,thickness:[.028,.035],lowerThickness:.022},body:{radii:[.1,.105,.27],rise:.07},neck:{at:[0,.39,.2],points:[[0,0,0],[0,.08,.04]],radius:.05},head:{at:[0,.1,.05],radii:[.095,.085,.085]},muzzle:{at:[0,-.03,.07],radii:[.04,.03,.03]},ears:{at:[.055,.085,-.01],radii:[.03,.055,.02],rotate:[0,0,-12]},eyes:{at:[.045,.02,.07],size:.022},tail:{at:[0,.42,-.26],points:[[0,0,0],[0,.08,-.12],[0,.24,-.16],[0,.34,-.1]],radius:.022},extras:()=>[{id:"nose",parent:"muzzle",shape:{type:"ellipsoid",radii:[.014,.01,.01],segments:8},at:[0,.015,.03],fill:"#e48a9a",outline:.4}],colors:{coat:"#8f8a86",dark:"#5f5a57",foot:"#f2efe9",muzzle:"#f2efe9",accent:"#f2efe9",...t.colors},gaits:["walk","trot","gallop"],cycleScale:.5,call:"meow",actions:e=>({arch:{summary:"Arches its back, fur up and tail high, for `for` ms (default 1200): a startled cat.",uses:["for"],run(n,s,i){const o=n.exaggeration,r=s.for??1200,a={squash:1+.25*o,neck:25,tail:-45,"fl.swing":-8,"fr.swing":-8,"hl.swing":8,"hr.swing":8};return n.key(i+180,a,{act:!1,easing:"ease-out"}),n.key(i+180+r,a,{act:!1}),n.key(i+r+520,{squash:1,neck:0,tail:0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0}),{end:i+r+520,contact:i+180}}},pounce:{summary:"Crouches low, wiggles, and pounces to `to`, landing with a squash.",needs:["to"],run(n,s,i){const o=n.exaggeration,r=Math.sign(s.to-n.x);let a=i;r!==0&&n.facing()!==r&&(a=n.turnTo(a,r>0?"right":"left"));const l={squash:.75,"hl.knee":60,"hr.knee":60,"fl.knee":45,"fr.knee":45,neck:10,tail:-15};n.key(a+300,l,{act:!1,easing:"ease-out"});for(let u=1;u<=4;u++)n.key(a+300+u*110,{roll:u%2===0?3:-3},{act:!1});const c=a+300+550,h=c+480;return n.key(c,{roll:0,squash:1.2,"hl.knee":0,"hr.knee":0,"fl.knee":0,"fr.knee":0,"fl.swing":45,"fr.swing":45,"hl.swing":-45,"hr.swing":-45,tail:20},{act:!1,easing:"ease-out"}),n.key((c+h)/2,{lift:e.legLength*.9*o,squash:1.1,pitch:-6},{act:!1,easing:"ease-out"}),n.key(h,{lift:0,squash:.8,pitch:0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0,neck:0,tail:0},{act:!1,easing:"ease-in"}),n.key(h+260,{squash:1}),n.move(c,h,s.to),n.effect({kind:"dust",time:h,x:s.to,y:n.floor,length:450}),{end:h+260,contact:h}}}})})}function Dd(t={}){return Qn({kind:t.kind??"cow",summary:t.summary??"A cartoon cow: walks and trots, moos, grazes, sits and swishes its tail.",legs:{upper:.42,lower:.36,foot:.08,footSize:[.13,.15],front:.68,hind:-.66,across:.24,thickness:[.085,.1],lowerThickness:.06},body:{radii:[.4,.42,1],rise:.32},neck:{at:[0,1.3,.85],points:[[0,0,0],[0,.22,.25]],radius:.19},head:{at:[0,.18,.4],radii:[.17,.19,.27],rotate:[30,0,0]},muzzle:{at:[0,-.06,.22],radii:[.15,.11,.1]},ears:{at:[.17,.06,-.12],radii:[.11,.035,.05],rotate:[0,0,-15]},eyes:{at:[.13,.06,.02],size:.04},tail:{at:[0,1.48,-1],points:[[0,0,0],[0,-.25,-.12],[0,-.7,-.14]],radius:.035},extras:e=>[{id:"horn-left",parent:"head",shape:{type:"tube",points:[[0,0,0],[.08,.12,.02]],radius:.025,segments:6},at:[.1,.16,-.14],fill:"#efe6d2",outline:.6},{id:"horn-right",parent:"head",shape:{type:"tube",points:[[0,0,0],[-.08,.12,.02]],radius:.025,segments:6},at:[-.1,.16,-.14],fill:"#efe6d2",outline:.6},{id:"udder",shape:{type:"ellipsoid",radii:[.16,.12,.18],segments:10},at:[0,.98,-.45],fill:"#f0a6b6",outline:.6},{id:"spot-1",parent:"body",shape:{type:"ellipsoid",radii:[.02,.2,.26],segments:10},at:[.39,.06,.2],fill:e.accent,outline:.4},{id:"spot-2",parent:"body",shape:{type:"ellipsoid",radii:[.02,.16,.22],segments:10},at:[-.39,.1,-.35],fill:e.accent,outline:.4},{id:"spot-3",parent:"body",shape:{type:"ellipsoid",radii:[.2,.02,.24],segments:10},at:[0,.41,-.2],fill:e.accent,outline:.4}],colors:{coat:"#f4f1ea",dark:"#2e2b2a",foot:"#3a3330",muzzle:"#f0b8c4",accent:"#2e2b2a",...t.colors},gaits:["walk","trot"],cycleScale:1.15,call:"moo",grazes:!0})}function ow(t){return ki(1,t)}const Me=.6,Nd=75,ta=80;function vi(t){const{colors:e}=t,[n,s,i]=t.body.radii,o=(t.tail.raised??15)*Math.PI/180,r=t.tail.length*.4,a=[{id:"body",shape:{type:"ellipsoid",radii:t.body.radii,segments:16},at:[0,t.body.height,0],fill:e.body},{id:"neck",shape:{type:"ellipsoid",radii:[n*.55,s*.55,i*.3],segments:10},at:[0,t.body.height+s*.45,i*.65],fill:e.body,outline:.5,solidOnly:!0},{id:"head",parent:"neck",shape:{type:"ellipsoid",radii:[t.head.radius,t.head.radius*1.02,t.head.radius*1.05],segments:14},at:[t.head.at[0],t.head.at[1]-(t.body.height+s*.45),t.head.at[2]-i*.65],fill:e.body},{id:"beak",parent:"head",shape:{type:"tube",points:[[0,0,0],[0,-t.beak.thickness*.4,t.beak.length]],radius:[t.beak.thickness,t.beak.thickness*.08],segments:8},at:[0,-t.head.radius*.1,t.head.radius*.8],fill:e.beak,outline:.8},{id:"tail",shape:{type:"ellipsoid",radii:[t.tail.width/2,.012*(i/.08),t.tail.length/2],segments:10},at:[t.tail.at[0],t.tail.at[1]+r*Math.sin(o),t.tail.at[2]-r*Math.cos(o)],rotate:[t.tail.raised??15,0,0],fill:e.wing,outline:.8}];if(e.belly&&a.push({id:"belly",parent:"body",shape:{type:"ellipsoid",radii:[n*.82,s*.7,i*.75],segments:12},at:[0,-s*.25,i*.12],fill:e.belly,outline:.4}),t.comb){const h=t.head.radius;a.push({id:"comb",parent:"head",shape:{type:"extrude",profile:[[-h*.5,h*.6],[h*.6,h*.6],[h*.5,h*1.3],[h*.15,h*1.05],[-h*.05,h*1.4],[-h*.3,h*1.05],[-h*.6,h*1.25]],width:h*.25},fill:e.comb??"#d9372e",outline:.7},{id:"wattle",parent:"head",shape:{type:"ellipsoid",radii:[h*.15,h*.35,h*.2],segments:8},at:[0,-h*.7,h*.6],fill:e.comb??"#d9372e",outline:.6})}for(const h of[1,-1]){const u=h>0?"left":"right",d=t.head.radius;a.push({id:`eye-${u}`,parent:"head",shape:{type:"ellipsoid",radii:[d*.16,d*.2,d*.18],segments:8},at:[h*d*.72,d*.18,d*.42],fill:"#1d1d22",outline:.3}),a.push({id:`wing-${u}`,shape:{type:"ellipsoid",radii:[.004,.004,.004],segments:4},at:[h*t.wing.shoulder[0],t.wing.shoulder[1],t.wing.shoulder[2]],rotate:[-8,h*90,0],outline:0}),a.push({id:`wing-${u}-blade`,parent:`wing-${u}`,shape:{type:"ellipsoid",radii:[t.wing.span*Me/2,t.wing.chord*.1,t.wing.chord/2],segments:12},at:[h*t.wing.span*Me/2,0,-t.wing.chord*.1],rotate:[-ta,0,0],fill:e.wing,outline:.8}),a.push({id:`wing-${u}-tip`,parent:`wing-${u}-blade`,shape:{type:"ellipsoid",radii:[t.wing.span*Me/2.4,t.wing.chord*.06,t.wing.chord*.3],segments:10},at:[h*t.wing.span*Me/4,0,-t.wing.chord*.3],rotate:[0,h*14,0],fill:e.wing,outline:.8}),a.push({id:`leg-${u}`,shape:{type:"tube",points:[[0,0,0],[0,-t.legs.length,0]],radius:Math.max(.004,t.legs.length*.05),segments:5},at:[h*t.legs.across,t.legs.length,0],fill:e.legs,outline:.6}),a.push({id:`toes-${u}`,parent:`leg-${u}`,shape:{type:"tube",points:[[0,0,-t.legs.length*.15],[0,0,t.legs.length*.35]],radius:Math.max(.003,t.legs.length*.04),segments:5},at:[0,-t.legs.length,0],fill:e.legs,outline:.6})}const l={spread:{description:"Wings: 0 folded back along the body, 1 spread out",unit:"0..1",min:0,max:1,bind:[{parts:["wing-left"],rotate:{axis:"y",degrees:-90}},{parts:["wing-right"],rotate:{axis:"y",degrees:90}},{parts:["wing-left-blade"],translate:[t.wing.span*(1-Me)/2,0,0],rotate:{axis:"x",degrees:ta},scale:[1/Me,1,1]},{parts:["wing-right-blade"],translate:[-t.wing.span*(1-Me)/2,0,0],rotate:{axis:"x",degrees:ta},scale:[1/Me,1,1]}]},flap:{description:"Wings raised (+) or lowered (−) at the shoulders",unit:"degrees",bind:[{parts:["wing-left"],rotate:{axis:"z",degrees:1}},{parts:["wing-right"],rotate:{axis:"z",degrees:-1}}]},wingbeat:{description:"Phase of the wingbeat, in beats (keyed steadily while flapping)",unit:"beats"},flapping:{description:"How hard the wings beat: 0 still, 1 full beats",unit:"0..1",min:0,max:1},peck:{description:"Head bobbed down and forward (+, pecking) or up (−)",unit:"degrees",bind:[{parts:["neck"],rotate:{axis:"x",degrees:1},translate:[0,-(t.neckReach??0)/Nd,0]}]},step:{description:"Phase of a walk, in steps (a chicken’s legs)",unit:"steps"},stepping:{description:"How much of the walk is applied",unit:"0..1",min:0,max:1},"leg.left":{description:"Left leg swung forward (+)",unit:"degrees",bind:[{parts:["leg-left"],rotate:{axis:"x",degrees:-1}}]},"leg.right":{description:"Right leg swung forward (+)",unit:"degrees",bind:[{parts:["leg-right"],rotate:{axis:"x",degrees:-1}}]}},c={parts:a,controls:l,length:i*2+t.tail.length+t.beak.length,height:t.head.at[1]+t.head.radius,footprint:[n*2.2,i*2.4],anchors:{beak:{part:"beak",at:[0,0,t.beak.length]},head:{part:"head",at:[0,0,0]},back:{at:[0,t.body.height+s,0]},feet:{at:[0,0,0]}},derive:h=>{const u={},d=Math.max(0,Math.min(1,h.flapping??0));d>0&&(u.flap=(h.flap??0)+d*48*Math.sin(Math.PI*2*(h.wingbeat??0)));const f=Math.max(0,Math.min(1,h.stepping??0));if(f>0){const g=Math.sin(Math.PI*2*(h.step??0));u["leg.left"]=(h["leg.left"]??0)+f*28*g,u["leg.right"]=(h["leg.right"]??0)-f*28*g,u.peck=(h.peck??0)+f*12*Math.sin(Math.PI*4*(h.step??0))}return u}};return{kind:t.kind,family:"bird",summary:t.summary,rig:c,actions:aw(t),acting:Bd,colors:{body:e.body,ink:"#26262b"},moves:rw(t)}}function rw(t){const e=t.legs.length*1.2,n={walk:{speed:e/.42,hold:{stepping:1},perMetre:{step:.5/e}}};return t.flies!==!1&&(n.fly={speed:4+t.wing.span*12,flies:!0,hold:{flapping:1,spread:1},perSecond:{wingbeat:t.beatsPerSecond??4}}),n}const Bd={depth:{turn:0,lift:0,pitch:1,roll:1,squash:1,spread:1,flap:2,peck:2},limits:{pitch:6,roll:6,squash:.06,peck:8,flap:10,lift:0},eyes:[],headTurns:{},drift:[]};function aw(t){const e=(t.beatsPerSecond??4)/1e3,n=(r,a,l)=>{const c=r.values.wingbeat??0;r.set("wingbeat",a,c),r.set("wingbeat",l,c+(l-a)*e)},s=(r,a,l)=>{const c=Math.sign(l-r.x);return c!==0&&r.facing()!==c?r.turnTo(a,c>0?"right":"left"):a},i=(r,a)=>{const l=r.anchor("beak");r.effect({kind:"honk",time:a,x:l.x,y:l.y,length:600,direction:r.facing()||1})},o={hop:{summary:"Hops to `to` in little bounces, wings twitching.",needs:["to"],run(r,a,l){const c=s(r,l,a.to),h=r.x,u=Math.abs(a.to-h),d=Math.max(1,Math.round(u/(t.body.radii[2]*3*r.scale))),f=260;for(let g=0;g<d;g++){const p=c+g*f;r.key(p+60,{squash:.85},{act:!1,easing:"ease-out"}),r.key(p+150,{squash:1.1,lift:t.legs.length*1.4,spread:.15},{act:!1,easing:"ease-out"}),r.key(p+f,{squash:.9,lift:0,spread:0},{act:!1,easing:"ease-in"}),r.move(p+60,p+f,h+(a.to-h)*(g+1)/d,{easing:"ease-in-out"})}return r.key(c+d*f+120,{squash:1}),{end:c+d*f+120}}},walk:{summary:"Walks to `to` on its two legs, its head bobbing with each step.",needs:["to"],uses:["for"],run(r,a,l){const c=s(r,l,a.to),h=Math.abs(a.to-r.x)/r.scale,u=t.legs.length*1.2,d=h/u,f=a.for??Math.max(400,d*420),g=r.values.step??0;return r.set("stepping",c,0),r.set("stepping",c+150,1,"ease-out"),r.set("stepping",c+f-150,1),r.set("stepping",c+f,0,"ease-in"),r.set("step",c,g),r.move(c,c+f,a.to,{easing:"ease-in-out"}),r.set("step",c+f,g+d/2,"ease-in-out"),{end:c+f,contact:c,release:c+f}}},peck:{summary:"Pecks at the ground (`for` ms, default 900): quick jabs of the head.",uses:["for"],run(r,a,l){const c=a.for??900,h=Math.max(1,Math.round(c/300));r.key(l+120,{pitch:-(t.stoop??12)},{act:!1,easing:"ease-out"});for(let u=0;u<h;u++)r.key(l+120+u*300+90,{peck:Nd},{act:!1,easing:"ease-in"}),r.key(l+120+u*300+260,{peck:20},{act:!1,easing:"ease-out"});return r.key(l+120+h*300+200,{peck:0,pitch:0}),{end:l+120+h*300+200,contact:l+210}}},flap:{summary:"Flaps its wings on the spot (`for` ms, default 900), lifting a little.",uses:["for"],run(r,a,l){const c=a.for??900;return r.key(l+120,{spread:1},{act:!1,easing:"ease-out"}),r.set("flapping",l,0),r.set("flapping",l+150,1,"ease-out"),r.set("flapping",l+c-150,1),r.set("flapping",l+c,0,"ease-in"),n(r,l,l+c),r.key(l+c*.5,{lift:t.legs.length*.6},{act:!1,easing:"ease-out"}),r.key(l+c,{lift:0,spread:0},{act:!1,easing:"ease-in"}),{end:l+c+80}}},[t.call]:{summary:`${t.call[0].toUpperCase()}${t.call.slice(1)}s: its head comes up and its beak opens to call.`,run(r,a,l){return r.key(l+120,{peck:-25,squash:1.06},{act:!1,easing:"ease-out"}),r.key(l+500,{peck:-20},{act:!1}),r.key(l+760,{peck:0,squash:1}),i(r,l+150),{end:l+760,contact:l+150}}}};return t.flies!==!1?(o.fly={summary:"Takes off (a crouch and a leap, wings beating) and flies to `to` at `height` metres (default 2); `land` brings it down.",needs:["to"],uses:["height","for"],run(r,a,l){const c=r.exaggeration,h=s(r,l,a.to),u=a.height??2,d=a.for??Math.max(700,Math.abs(a.to-r.x)/.35),f=r.values.lift>t.legs.length,g=f?h:h+200;return f||(r.key(h+160,{squash:1-.18*c,spread:.6},{act:!1,easing:"ease-out"}),r.effect({kind:"dust",time:g,x:r.x,y:r.floor,length:400})),r.key(g+100,{spread:1,squash:1.08,pitch:10},{act:!1,easing:"ease-out"}),r.set("flapping",g,r.values.flapping??0),r.set("flapping",g+100,1,"ease-out"),r.set("flapping",g+d,.6),n(r,g,g+d),r.key(g+d*.4,{lift:u,pitch:-5,squash:1},{act:!1,easing:"ease-out"}),r.key(g+d,{lift:u,pitch:0},{act:!1,easing:"ease-in-out"}),r.move(g,g+d,a.to,{easing:"ease-in-out"}),{end:g+d,contact:g,release:g+d}}},o.land={summary:"Comes down to the floor it is over (or to `height` metres above it, a branch or a roof): wings braking, a squash on touchdown.",uses:["height","to"],run(r,a,l){const h=a.height??0;return r.set("flapping",l,r.values.flapping??1),r.set("flapping",l+700-120,1),r.set("flapping",l+700,0,"ease-in"),n(r,l,l+700),r.key(l+700*.6,{pitch:14},{act:!1,easing:"ease-out"}),r.key(l+700,{lift:h,pitch:0,squash:.85},{act:!1,easing:"ease-in"}),a.to!==void 0&&r.move(l,l+700,a.to,{easing:"ease-out"}),r.key(l+700+160,{squash:1,spread:0}),{end:l+700+200,contact:l+700}}}):o.flutter={summary:"Flutters up a little way and back down, wings beating hard (a chicken’s flight).",run(r,a,l){return r.key(l+100,{spread:1,squash:.9},{act:!1,easing:"ease-out"}),r.set("flapping",l+80,0),r.set("flapping",l+160,1,"ease-out"),r.set("flapping",l+900-100,1),r.set("flapping",l+900,0,"ease-in"),n(r,l+80,l+900),r.key(l+900*.5,{lift:t.legs.length*2.5,squash:1.08},{act:!1,easing:"ease-out"}),r.key(l+900,{lift:0,squash:.85,spread:0},{act:!1,easing:"ease-in"}),r.key(l+900+160,{squash:1}),{end:l+900+160,contact:l+900}}},o}function Wd(t={}){return vi({kind:"songbird",summary:"A small songbird: hops, pecks, tweets, flaps, flies and lands (on the ground, a branch or a roof).",body:{radii:[.05,.05,.075],height:.085},head:{at:[0,.145,.065],radius:.036},beak:{length:.03,thickness:.01},wing:{shoulder:[.04,.1,.03],span:.11,chord:.06},tail:{at:[0,.095,-.07],length:.07,width:.045},legs:{length:.04,across:.018},colors:{body:"#7b6a58",wing:"#5c4c3d",beak:"#e7a43a",legs:"#c47a35",belly:"#e9c8a3",...t.colors},call:"tweet",beatsPerSecond:9})}function jd(t={}){return vi({kind:"crow",summary:"A crow: walks and hops, pecks, caws, flaps, flies and lands (on the ground, a branch or a roof).",body:{radii:[.09,.09,.17],height:.2},head:{at:[0,.32,.15],radius:.065},beak:{length:.08,thickness:.022},wing:{shoulder:[.07,.24,.06],span:.32,chord:.14},tail:{at:[0,.2,-.15],length:.16,width:.09},legs:{length:.1,across:.035},colors:{body:"#2b2b33",wing:"#1e1e25",beak:"#3b3b44",legs:"#3b3b44",...t.colors},call:"caw",beatsPerSecond:4})}function qd(t={}){return vi({kind:"chicken",summary:"A chicken: walks with a bobbing head, pecks, clucks, and flutters up and down (it cannot really fly).",body:{radii:[.13,.14,.19],height:.3},head:{at:[0,.5,.16],radius:.07},beak:{length:.05,thickness:.02},wing:{shoulder:[.11,.34,.04],span:.24,chord:.15},tail:{at:[0,.38,-.15],length:.16,width:.13,raised:50},legs:{length:.17,across:.05},comb:!0,stoop:20,neckReach:.12,colors:{body:"#f4ede0",wing:"#e6dccb",beak:"#e7a43a",legs:"#e7a43a",comb:"#d9372e",...t.colors},call:"cluck",flies:!1})}const mn={car:wd,truck:kd,bus:vd,tractor:Md,cart:Sd,trainCar:Td,bike:Ed,motorbike:Ad,tree:Pd,house:xd,helicopter:Id,airplane:Od,horse:Rd,dog:Ld,cat:Fd,cow:Dd,songbird:Wd,crow:jd,chicken:qd};function Kd(t,e={}){const n=mn[t];if(!n)throw new Error(ft("prop preset",t,Object.keys(mn)));return n(e)}function Yd(t){const e={};for(const[n,s]of Object.entries({...pn,...t.rig.controls})){const{bind:i,...o}=s;e[n]=o}return e}function lw(t){const{prop:e}=t,n=t.scale??60,s=e.rig.length*n*1.4,i=e.rig.height*n*1.6,o=Yd(e),r={};for(const[l,c]of Object.entries(o))r[l]=t.values?.[l]??c.default??0;const a={look:t.look,ink:t.ink,lineWidth:t.lineWidth,pencil:t.pencil,seed:t.seed,style:t.style,paper:t.paper};return{type:"custom",x:t.x-s/2,y:t.y-i,width:s,height:i,props:r,prop:e,propScale:n,propDraw:a,about:{kind:e.kind,summary:e.summary,props:o,actions:Object.fromEntries(Object.entries(e.actions).map(([l,c])=>[l,c.summary]))},draw(l,c,h){const u=c.props??{};l.translate(s/2,i),rr(l,ts(e,u,n),{...a,time:h})}}}function ts(t,e,n){const s=hd(yt(t.rig,e,"turn"),yt(t.rig,e,"tilt"),n);return Jr(t.rig,e,s,n)}function Mi(t,e,n){const s={...t.props};let i=0,o=0;for(const[l,c]of e.state?.values.get(n)??[])typeof c=="number"&&(l==="x"?i=c:l==="y"?o=c:l in s&&(s[l]=c));const r={x:t.x+t.width/2+i,y:t.y+t.height+o},a=ts(t.prop,s,t.propScale);return{values:s,origin:r,solved:a,anchor(l){const c=a.anchors[l];if(!c)throw new Error(`${t.prop.kind}: no anchor "${l}" (it has ${Object.keys(a.anchors).join(", ")||"none"})`);return{x:r.x+c.point.x,y:r.y+c.point.y,depth:c.depth}}}}function cw(t,e,n,s,i={}){const o=Mi(e,n,s);return t.save(),t.translate(o.origin.x,o.origin.y),rr(t,o.solved,{...e.propDraw,time:n.time,rider:i.rider?r=>{r.save(),r.translate(-o.origin.x,-o.origin.y),i.rider(r),r.restore()}:void 0}),t.restore(),o}const Si=["do","at","for","to","toward","speed","open","on","height","wind"],ea={viewer:0,right:1,away:2,left:3},hw=420,na={hold:{summary:"Holds still (`for` ms, default 1000).",run:(t,e,n)=>({end:n+(e.for??1e3)})},turn:{summary:"Turns to face `toward`: viewer, right, away, left, or a quarter-turn value (it turns in 3D, through the nearer way).",needs:["toward"],run:(t,e,n)=>({end:t.turnTo(n,e.toward)})},pop:{summary:"Pops into being: grows from nothing, stretched, overshoots and settles (`for` ms, default 500).",uses:["for"],run(t,e,n){const s=e.for??500,i=t.exaggeration;return t.key(n,{size:0,squash:1},{act:!1}),t.key(n+s*.6,{size:1+.15*i,squash:1+.15*i},{act:!1,easing:"ease-out"}),t.key(n+s,{size:1,squash:1}),{end:n+s,contact:n}}},vanish:{summary:"Shrinks away to nothing, with a little stretch first (`for` ms, default 400).",uses:["for"],run(t,e,n){const s=e.for??400,i=t.exaggeration;return t.key(n+s*.3,{size:1+.08*i,squash:1+.12*i},{act:!1,easing:"ease-out"}),t.key(n+s,{size:0,squash:1},{act:!1,easing:"ease-in"}),{end:n+s,release:n+s}}}};function Ti(t){return{...na,...t.actions}}const sa=t=>typeof t=="number"&&Number.isFinite(t);function zd(t,e){if(!Array.isArray(t))return[{level:"error",beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const n=Ti(e),s=Object.keys(n),i=[];return t.forEach((o,r)=>{const a=c=>i.push({level:"error",beat:r,message:c});if(!o||typeof o!="object"||Array.isArray(o))return a(`Each beat must be an object like { do: '${s[s.length-1]}' }.`);const l=o;for(const c of Object.keys(l))Si.includes(c)||a(ft("beat field",c,Si,c==="duration"?"for":c==="direction"?"toward":void 0));if(typeof l.do!="string"||!s.includes(l.do))return a(ft(`${e.kind} action`,l.do,s));for(const c of n[l.do].needs??[])l[c]===void 0&&a(`\`${l.do}\` needs \`${c}\`.`);for(const c of["at","for","speed","height","wind"])l[c]!==void 0&&!(sa(l[c])&&l[c]>=0)&&a(`\`${c}\` must be a number ≥ 0 (got ${JSON.stringify(l[c])}).`);if(l.to!==void 0&&!sa(l.to)&&a(`\`to\` is a scene x in px (got ${JSON.stringify(l.to)}).`),l.toward!==void 0&&!sa(l.toward)&&!(typeof l.toward=="string"&&l.toward in ea)){const c=typeof l.toward=="string"?An(l.toward,Object.keys(ea)):void 0;a(`\`toward\` is viewer, right, away, left or a quarter-turn number${c?` (did you mean "${c}"?)`:""} (got ${JSON.stringify(l.toward)}).`)}for(const c of["open","on"])l[c]!==void 0&&typeof l[c]!="boolean"&&a(`\`${c}\` is true or false (got ${JSON.stringify(l[c])}).`)}),i}function Xd(t,e,n,s={}){const i=zd(n,e).filter(v=>v.level==="error");if(i.length>0)throw new Error(`propScript (${e.kind}): ${i.length} problem(s) in the beats:
59
- ${i.map(v=>` beat ${v.beat}: ${v.message}`).join(`
60
- `)}`);const o=s.from??0,r=s.ground??0,a=s.scale??60,l=s.exaggeration??1,c=Ti(e),h={};for(const v of[...Object.keys(pn),...Object.keys(e.rig.controls)])h[v]=s.start?.[v]??yt(e.rig,{},v);const u=[{time:0,pose:{...h}}],d=new Map,f=[];let g=o,p=r;const m=(v,O,x,_)=>{const F=d.get(v)??[{time:0,value:v==="x"||v==="y"?0:h[v]}];F.push({time:O,value:x,..._?{easing:_}:{}}),d.set(v,F),v!=="x"&&v!=="y"&&(h[v]=x)},b=(v,O)=>{const x=v==="x"?g-o:v==="y"?p-r:h[v],_=d.get(v);(!_||_[_.length-1].time<O)&&m(v,O,x)},k={prop:e,scale:a,exaggeration:l,get x(){return g},get floor(){return p},values:h,facing(){const v=Math.sin(h.turn*Math.PI/2);return Math.abs(v)<.5?0:v>0?1:-1},key(v,O,x={}){Object.assign(h,O),u.push({time:v,pose:{...h},...x.act===!1?{act:!1}:{},...x.easing?{easing:x.easing}:{}})},move(v,O,x,_={}){b("x",v),m("x",O,x-o,_.easing),g=x,_.floor!==void 0&&(b("y",v),m("y",O,_.floor-r,_.easing),p=_.floor)},set(v,O,x,_){m(v,O,x,_)},turnTo(v,O){const x=typeof O=="number"?O:ea[O],_=h.turn,I=[x-4,x,x+4].map(N=>({t:N,d:Math.abs(N-_)})).sort((N,Y)=>N.d-Y.d||Math.abs(N.t)-Math.abs(Y.t))[0];if(I.d<.001)return v;const L=v+hw*Math.max(1,I.d);return k.key(L,{turn:I.t}),L},effect(v){f.push(v)},anchor(v){const x=ts(e,h,a).anchors[v];if(!x)throw new Error(`${e.kind}: no anchor "${v}"`);return{x:g+x.point.x,y:p+x.point.y}}},w=[];let M=0;for(const v of n){const O=Math.max(v.at??M,u[u.length-1].time),x=c[v.do].run(k,v,O);x.end>u[u.length-1].time&&u.push({time:x.end,pose:{...h}}),w.push({start:O,end:x.end,...x.contact!==void 0?{contact:x.contact}:{},...x.release!==void 0?{release:x.release}:{}}),M=x.end}const S=Tr(s.style??"snappy"),A={...S,anticipation:S.anticipation*l,overshoot:S.overshoot*l},E=hi(pw(u),e.acting,{style:A}),$=[...Object.entries(E).filter(([v])=>!d.has(v)).map(([v,O])=>({id:`${t}-${v}`,target:t,property:v,keyframes:O})),...[...d].map(([v,O])=>({id:`${t}-${v}`,target:t,property:v,keyframes:gw(O)}))];for(const v of dw(t,e,$,M,u[0].pose)){const O=$.findIndex(F=>F.property===v.property);if(O<0){$.push(v);continue}const x=new Wt({id:`${t}-own`,tracks:[$[O]]}),_=F=>Number(x.getStateAtTime(F).values.get(t)?.get(v.property)??0);$[O]={...v,keyframes:v.keyframes.map(F=>({time:F.time,value:Number(F.value)+_(F.time)}))}}return{tracks:$,duration:M,beats:w,effects:f}}const uw=1500;function dw(t,e,n,s,i){if(!e.follow?.length)return[];const o=new Wt({id:`${t}-follow`,tracks:n.filter(a=>a.property==="turn"||e.follow.some(l=>l.of===a.property))}),r=(a,l)=>{const c=o.getStateAtTime(a).values.get(t)?.get(l);return typeof c=="number"?c:i[l]??0};return e.follow.map(a=>{const l=s+uw,c=pl(d=>r(d,a.of),{start:0,end:l,stiffness:a.stiffness,damping:a.damping}),h=a.limit??1/0,u=c.map(({time:d,value:f})=>{const g=Math.sin(r(d,"turn")*Math.PI/2),p=(f-r(d,a.of))*g;return{time:d,value:Math.max(-h,Math.min(h,p*a.per))}});return{id:`${t}-${a.control}`,target:t,property:a.control,keyframes:u}})}const fw=20;function pw(t){const e=[...t].sort((s,i)=>s.time-i.time),n=[];for(const s of e){const i=n[n.length-1];i&&s.time-i.time<fw?n[n.length-1]={...s,time:i.time}:n.push(s)}return n}function gw(t){const e=t.map((s,i)=>({k:s,i})).sort((s,i)=>s.k.time-i.k.time||s.i-i.i),n=[];for(const{k:s}of e)n.length>0&&n[n.length-1].time===s.time?n[n.length-1]=s:n.push(s);return n}const mw={linear:!0,"ease-in":!0,"ease-out":!0,"ease-in-out":!0,"ease-in-quad":!0,"ease-out-quad":!0,"ease-in-out-quad":!0,"ease-in-cubic":!0,"ease-out-cubic":!0,"ease-in-out-cubic":!0};function Gd(t,e={}){const n={};for(const s of Object.keys(_t))n[s]={summary:`Walks to \`to\` in the ${s} gait.`,needs:["to"]};for(const s of Object.keys(Lt))n[s]={summary:`Moves into the ${s} pose and holds it (\`for\` ms).`};for(const s of Object.keys(we))n[s]={summary:`The ${s} gag (${Xn(s)} ms).`};for(const[s,i]of Object.entries(Un))n[s]={...i};return{...t?{version:t}:{},timing:"JSON timelines and tracks are in milliseconds; the GSAP-style API (live.to, tf.timeline) takes seconds. Scene x grows right, y grows down, in px.",easings:{named:Object.keys(mw),parametric:{"cubic-bezier":'{ type: "cubic-bezier", points: [x1, y1, x2, y2] }',steps:'{ type: "steps", count, position?: start | end | none | both }',elastic:'{ type: "elastic", mode?: in | out | in-out, amplitude?, period? }',bounce:'{ type: "bounce", mode?: in | out | in-out }',back:'{ type: "back", mode?: in | out | in-out, overshoot? }'}},trackKinds:{keyframe:"{ id, target, property, keyframes: [{ time, value, easing? }] }: values between keys are interpolated (numbers, colours, paths)",spring:'{ id, target, property, kind: "spring", spring: { from, to, stiffness?, damping?, mass?, velocity? }, delay? }: physics settle',inertia:'{ id, target, property, kind: "inertia", inertia: { from, velocity, friction?, min?, max?, end? }, delay? }: a flick that slows (end snaps to a value or the nearest of a list)',motionPath:'{ property: "motionPath", path, align? }: moves along an SVG path',text:'{ property: "text", … }: types or scrambles text'},canvasProperties:gi,stickFigure:{poseFields:Tc,props:Ec,handFields:Ac,poses:Object.keys(Lt),expressions:Object.keys(dt),gags:Object.fromEntries(Object.keys(we).map(s=>[s,Xn(s)])),gaits:Object.keys(_t),actingStyles:Object.keys(Ce),beatFields:di,actions:n,dances:Object.fromEntries(Object.entries(ge).map(([s,i])=>[s,Object.keys(i.moves)])),flips:Object.fromEntries(Object.entries(jn).map(([s,i])=>[s,i.label])),handShapes:Object.keys(St),mudras:Object.keys(Ls)},props:{api:{"car() · truck() · bus() · tractor() · cart() · trainCar() · bike() · motorbike()":"wheeled vehicles (vehicle(spec) makes your own)","tree() · house()":"environment (tree(spec), house(spec))","helicopter() · airplane()":"aircraft","horse() · dog() · cat() · cow()":"animals (quadruped(spec) makes your own): gaits with footfall patterns keyed in step with the distance, sit, jump, their calls, species actions","songbird() · crow() · chicken()":"birds (bird(spec) makes your own): hop, walk, peck, flap, fly and land (a chicken flutters), their calls; wings fold and beat in rhythm","{ kind: 'prop', prop: 'car', position, rotation, values } with loadScene3D(scene, { kinds: [characterObjects, propObjects] })":"props in 3D scenes, by preset name, seen in perspective by the scene camera; controls are tracks on the object","characterScript3D(id, beats, { scene, position?, heading?, height?, pose? })":"a v2 character in a 3D scene in world metres: gaits to [x, z] or through points (its walk phase keyed with the distance), face, hold, pose, gag; checkCharacterBeats3D checks the beats","propRide3D({ prop, propId, propTracks, scene, placement, anchor, riderId, pose, start, end, mount?, dismount? })":"a character riding a prop in a 3D scene: hips on a seat anchor (saddle, seat) as it moves, hopping on and off; RIDING_POSES.astride / .seated","propScript3D(id, prop, beats, { scene, position?, heading?, values? })":"props scripted in world metres for 3D scenes: moves to [x, z] or through points (wheels and strides keyed with the distance), face, hold, and their actions; checkPropBeats3D checks the beats","propPreset(name, options?)":"a prop preset by name (did-you-mean on a wrong one)","propTarget({ …, style: 'stick' })":"line art to go with stick figures: tubes as single strokes, shapes outlined over paper","propTow({ leader, leaderId, leaderTracks, hitch, towed, towedId, anchor, start, end })":"a prop towed by another (a cart behind a horse): turns with it, its wheels roll exactly","propTarget({ x, y, prop, scale?, values?, look?, ink? })":"a canvas target that draws a prop (x, y: its middle on the ground; scale px per metre, default 60)","propScript(id, prop, beats, { from, ground, scale, style?, exaggeration?, start? })":"beats → acted tracks, with contact times and effect cues; checkPropBeats(beats, prop) checks them","drawProp(ctx, target, frame, id, { rider? })":"draw it as it is in a frame (a rider is drawn between its far and near parts)","propAt(target, frame, id).anchor(name)":"where an anchor (seat, door, chimney…) is, in scene px","propRide({ prop, propId, propTracks, anchor, figure, figureId, start, end, offset? })":"a figure carried at an anchor, turning with the prop; spliceTracks() puts it into the figure’s tracks","drawPropEffects(ctx, effects, time)":"dust, exhaust, skid marks, honk lines, leaves, smoke"},beatFields:Si,commonControls:Object.fromEntries(Object.entries(pn).map(([s,i])=>[s,`${i.description}${i.unit?` (${i.unit})`:""}`])),commonActions:Object.fromEntries(Object.entries(na).map(([s,i])=>[s,i.summary])),presets:Object.fromEntries(Object.entries(mn).map(([s,i])=>{const o=i();return[s,{family:o.family,summary:o.summary,actions:Object.fromEntries(Object.entries(o.actions).map(([r,a])=>[r,{summary:a.summary,...a.needs?{needs:a.needs}:{}}])),controls:Object.keys(o.rig.controls),anchors:Object.keys(o.rig.anchors??{})}]}))},custom:{api:{"defineAction({ summary, needs?, steps: (from, beat) => [{ after, pose, easing? }] })":"a new action written as timed pose steps from the current pose, like a gag","defineAction({ summary, needs?, beats: (beat) => [beats] })":"a new action built from other beats (which may be custom too)","defineGait({ swing, knee, arm, elbow, lean, cycle?, … })":"a new gait (the Gait fields in degrees; cycle is ms per two steps)","scriptTracks(id, beats, { actions, gaits })":"beats may then use those names; checkBeats(beats, { actions, gaits }) knows them","stickFigureTarget({ …, cast: { actions, gaits } })":"a figure that draws the gaits and lists the actions in describeTarget","persona({ name, summary?, height?, look?, acting?, gait?, mood?, stance?, energy?, actions?, gaits? })":"a character’s look, acting style and habits: .figure({ x, y }), .script(id, beats, { from, ground }), .check(beats), .handPath(…), .describe(); `go` walks in its gait, `stand` returns to its stance and face"},actions:Object.fromEntries(Object.entries(e.actions??{}).map(([s,i])=>[s,{summary:i.summary,...i.needs?{needs:i.needs}:{}}])),gaits:Object.fromEntries(Object.entries(e.gaits??{}).map(([s,i])=>[s,i.summary??"custom gait"]))},character:{poses:Object.keys(Ie),expressions:Object.keys(Ko),gags:Object.keys(si)},codePanel:{languages:li,removeStyles:ri,anchors:{"line(n, time?)":"line n’s text box { x, y, left, right, top, bottom, width, height }: stand on top, point at x, y","token(n, text, occurrence?, time?)":"a word on a line","spot(n, column, width?, time?)":"a place in a line, for put and write","landing(piece, n, column)":"where a dropped piece will land",box:"the whole panel"},edits:Sr},cameraShots:{frame:"{ at, duration?, easing?, frame: { focus?: { x, y }, scale?, rotate? } }: push in, pull out, or cut (duration 0)",shake:"{ at, duration, shake: { strength?, frequency?, roll?, seed? } }",follow:"{ at, until, follow: { x: <the subject’s x keyframes>, lead?, y?, lag?, scale? } }: keeps a subject centred"},teach:{"lesson({ id })":"steps as timeline JSON: to, set, together, wait, marker (with pause, question, captions)","cells, pointer, stack, queue, table, pipeline":"diagram primitives (SVG markup + step helpers)","figure({ width, height, children })":"the SVG holding the pieces"},cli:{"tinyfly capabilities [--json]":"this catalog","tinyfly check <beats.json>":"check a beat script (names, fields) with suggestions","tinyfly validate <timeline.json> [--markup file]":"check a timeline against its markup","tinyfly render <timeline.json> <markup> [--at …]":"a frame as static markup","tinyfly video <scene.mjs> [--stills dir --times …]":"MP4, or PNG stills to look at"}}}const xt=t=>t.map(e=>`\`${e}\``).join(", "),Ud=t=>Object.entries(t).map(([e,n])=>`| \`${e}\` | ${n.unit??n.kind??""} | ${n.description} |`).join(`
61
- `);function yw(t,e={}){const n=Gd(t,e),s=n.stickFigure;return[`# tinyfly capabilities${n.version?` (v${n.version})`:""}`,"","Generated from the library itself: every name below is accepted, and names not listed are rejected (beat scripts, code panels and `checkTracks` say which name was probably meant).","",`**Timing.** ${n.timing}`,"","## Easings","",`Named: ${xt(n.easings.named)}.`,"",...Object.entries(n.easings.parametric).map(([o,r])=>`- ${o}: \`${r}\``),"","## Track kinds","",...Object.entries(n.trackKinds).map(([o,r])=>`- **${o}**: ${r}`),"","## Canvas targets","","Types: `rect`, `circle`, `text`, `line`, `path`, `image`, `custom`. `describeTarget(target)` lists what one can animate with its values; `checkTracks(tracks, targets)` checks tracks before playing them.","","| Property | Unit | What it does | Types |","|---|---|---|---|",...Object.entries(n.canvasProperties).map(([o,r])=>`| \`${o}\` | ${r.unit??r.kind??""} | ${r.description} | ${r.types.length===7?"all":r.types.join(", ")} |`),"","## Stick figure (`@algorisys/tinyfly/characters`)","","`stickFigureTarget({ x, y, style })` is a custom canvas target; its props are the pose fields and the props below. Pose it with tracks (`poseTracks`), or write beats (`scriptTracks`).","","### Pose fields","","| Field | Unit | What it does |","|---|---|---|",Ud(s.poseFields),"","### Other props","","| Prop | Unit | What it does |","|---|---|---|",Ud(s.props),"",`With \`style.hands\`, each hand has \`hand.left.<field>\` / \`hand.right.<field>\` props: ${xt(Object.keys(s.handFields))}.`,"",`**Poses** (a beat's \`do\`, or a pose key): ${xt(s.poses)}.`,"",`**Expressions** (a beat's \`mood\`): ${xt(s.expressions)}.`,"",`**Gags** (ms): ${Object.entries(s.gags).map(([o,r])=>`\`${o}\` (${r})`).join(", ")}.`,"",`**Gaits**: ${xt(s.gaits)}. **Acting styles** (\`style\`): ${xt(s.actingStyles)}.`,"","### Beat scripts","",`\`scriptTracks(target, beats, { from, ground, height, facing, style })\`. A beat has these fields only: ${xt(s.beatFields)}. Times are ms; \`to\` and \`target\` are scene px; \`onto\` is a floor's scene y.`,"","| `do` | Needs | What happens |","|---|---|---|",...Object.entries(s.actions).map(([o,r])=>`| \`${o}\` | ${(r.needs??[]).map(a=>`\`${a}\``).join(", ")} | ${r.summary} |`),"","Beats that touch something report `contact` (and `release`) times in `result.beats[i]`; key the thing they touch to those.","",`**Dances** (\`dancer(style, { move })\`): ${Object.entries(s.dances).map(([o,r])=>`\`${o}\` (${r.join(", ")})`).join("; ")}.`,"",`**Flips**: ${Object.entries(s.flips).map(([o,r])=>`\`${o}\` (${r})`).join(", ")}.`,"",`**Hand shapes**: ${xt(s.handShapes)}. **Mudras**: ${xt(s.mudras)}.`,"","### Your own actions, gaits and personas","","Nothing is registered globally: pass your definitions where they are used.","",...Object.entries(n.custom.api).map(([o,r])=>`- \`${o}\`: ${r}`),"",...Object.keys(n.custom.actions).length||Object.keys(n.custom.gaits).length?["**This cast’s own:**","",...Object.entries(n.custom.actions).map(([o,r])=>`- \`${o}\`${r.needs?.length?` (needs ${r.needs.map(a=>`\`${a}\``).join(", ")})`:""}: ${r.summary}`),...Object.entries(n.custom.gaits).map(([o,r])=>`- \`${o}\` (gait): ${r}`),""]:[],"## Props (everyday objects with behaviours)","","A prop is a 3D rig of simple parts drawn with the characters’ pens (clean, pencil, silhouette), so it turns toward the camera (`turn`), and its beats go through the same acting pass (anticipation, overshoot, overlap; `exaggeration` scales them).","",...Object.entries(n.props.api).map(([o,r])=>`- \`${o}\`: ${r}`),"",`Prop beat fields: ${xt(n.props.beatFields)}. Every prop has the controls ${Object.keys(n.props.commonControls).map(o=>`\`${o}\``).join(", ")} and the actions ${Object.keys(n.props.commonActions).map(o=>`\`${o}\``).join(", ")}.`,"","| Preset | Family | Actions (needs) | Controls | Anchors |","|---|---|---|---|---|",...Object.entries(n.props.presets).map(([o,r])=>`| \`${o}()\` | ${r.family} | ${Object.entries(r.actions).map(([a,l])=>`\`${a}\`${l.needs?.length?` (${l.needs.join(", ")})`:""}`).join(", ")} | ${r.controls.map(a=>`\`${a}\``).join(", ")} | ${r.anchors.join(", ")} |`),"","## Character (v2 human)","",`Poses: ${xt(n.character.poses)}. Expressions: ${xt(n.character.expressions)}. Gags: ${xt(n.character.gags)}.`,"","## Code panel","",`\`codePanel({ code, language, x, y, fontSize?, lineHeight?, width? })\`: a code listing as a scene object. Languages: ${xt(n.codePanel.languages)}. Remove styles: ${xt(n.codePanel.removeStyles)}.`,"",...Object.entries(n.codePanel.anchors).map(([o,r])=>`- \`${o}\`: ${r}`),"",...Object.values(n.codePanel.edits).map(o=>`- \`${o.split(":")[0]}\`:${o.split(":").slice(1).join(":")}`),"","## Camera shots (`cameraTracks(shots, { stage })`)","",...Object.entries(n.cameraShots).map(([o,r])=>`- **${o}**: \`${r}\``),"","## Teaching (`@algorisys/tinyfly/teach`)","",...Object.entries(n.teach).map(([o,r])=>`- \`${o}\`: ${r}`),"","## Command line","",...Object.entries(n.cli).map(([o,r])=>`- \`${o}\`: ${r}`),""].join(`
62
- `)}function bw(t,e,n,s={}){const i=s.color??"#555",o=s.size??60;for(const r of e){const a=(n-r.time)/r.length;if(a<=0||a>=1)continue;const l=Kt(`${r.kind}:${r.time}:${r.x}`);r.kind==="dust"?Su(t,{x:r.x,y:r.y},a,{size:o,color:i,seed:l}):r.kind==="exhaust"?vw(t,r,a,o,i,l):r.kind==="skid"?Mw(t,r,a,n,i):r.kind==="honk"?Sw(t,r,a,o,i):r.kind==="smoke"?ww(t,r,n,o,i):r.kind==="leaves"&&kw(t,r,a,o,s.leafColor??"#5cae5a",i,l)}}function ww(t,e,n,s,i,o){const r=e.direction??1,a=380,l=1500;t.save(),t.strokeStyle=i,t.lineWidth=Math.max(1,s*.025);for(let c=e.time;c<=e.time+e.length-l;c+=a){const h=(n-c)/l;if(h<=0||h>=1)continue;const u=Math.sin(c/97+h*4)*s*.06,d=e.x+r*h*s*.7+u,f=e.y-h*s*1.6;t.globalAlpha=Math.min(1,h*6)*(1-h)*.85,t.beginPath(),t.arc(d,f,s*(.07+h*.2),0,Math.PI*2),t.stroke()}t.restore()}function kw(t,e,n,s,i,o,r){const a=e.direction??1,l=e.toY??e.y+s*3;t.save(),t.lineWidth=Math.max(1,s*.02),t.strokeStyle=o,t.fillStyle=i;for(let c=0;c<4;c++){const h=Kt(`${r}:${c}`)%1e3/1e3,u=Math.min(1,n*(1.1+h*.4)),d=e.x+(h-.5)*s*1.2,f=e.y+(h-.3)*s*.4,g=u*u*.4+u*.6,p=d+a*u*s*(.6+h)+Math.sin(u*9+h*6)*s*.18,m=Math.min(l-2,f+(l-f)*g);t.globalAlpha=n>.85?(1-n)/.15:1,t.save(),t.translate(p,m),t.rotate(Math.sin(u*7+h*5)*1.2),t.beginPath(),t.ellipse(0,0,s*.07,s*.035,0,0,Math.PI*2),t.fill(),t.stroke(),t.restore()}t.restore()}function vw(t,e,n,s,i,o){const r=e.direction??-1;t.save(),t.strokeStyle=i,t.lineWidth=Math.max(1,s*.025);for(let a=0;a<3;a++){const l=n*1.6-a*.25;if(l<=0||l>=1)continue;const c=(Kt(`${o}:${a}`)%100/100-.5)*s*.1,h=e.x+r*l*s*.9,u=e.y-l*s*.45+c;t.globalAlpha=(1-l)*.9,t.beginPath(),t.arc(h,u,s*(.06+l*.14),0,Math.PI*2),t.stroke()}t.restore()}function Mw(t,e,n,s,i){const o=e.toX??e.x,r=Math.min(1,(s-e.time)/e.length*3),a=e.x+(o-e.x)*r;t.save(),t.strokeStyle=i,t.lineCap="round",t.globalAlpha=n<.6?.8:.8*(1-(n-.6)/.4),t.lineWidth=3;for(const l of[-2,4])t.beginPath(),t.moveTo(e.x,e.y+l),t.lineTo(a,e.y+l),t.stroke();t.restore()}function Sw(t,e,n,s,i){const o=e.direction??1;t.save(),t.strokeStyle=i,t.lineWidth=Math.max(1.5,s*.04),t.lineCap="round",t.globalAlpha=n<.7?1:(1-n)/.3;const r=s*(.15+.5*(1-(1-n)**2));for(let a=-1;a<=1;a++){const l=a*Math.PI/7,c=e.x+o*Math.cos(l)*r,h=e.y+Math.sin(l)*r;t.beginPath(),t.arc(c,h,s*.12,o>0?-Math.PI/3:Math.PI*2/3,o>0?Math.PI/3:Math.PI*4/3),t.stroke()}t.restore()}function Tw(t){const e=new Wt({id:`${t.propId}-ride`,tracks:t.propTracks.filter(h=>h.target===t.propId)}),n=t.every??33,s=[],i=[],o=[],r=[];let a=1;for(let h=t.start;;h=Math.min(t.end,h+n)){const u=Mi(t.prop,{state:e.getStateAtTime(h)},t.propId),d=u.anchor(t.anchor);s.push({time:h,value:d.x+(t.offset?.x??0)-t.figure.x}),i.push({time:h,value:d.y+(t.offset?.y??0)-t.figure.y});const f=Math.sin(u.values.turn*Math.PI/2);if(Math.abs(f)>.15&&(a=f>0?1:-1),o.push({time:h,value:Math.abs(f)}),r.push({time:h,value:a}),h>=t.end)break}const l=t.figureId,c=[{id:`${l}-x`,target:l,property:"x",keyframes:s},{id:`${l}-y`,target:l,property:"y",keyframes:i}];return t.turn!==!1&&c.push({id:`${l}-turn`,target:l,property:"turn",keyframes:o},{id:`${l}-facing`,target:l,property:"facing",keyframes:Ew(r)}),c}function Ew(t){const e=[];for(const n of t){const s=e[e.length-1];s&&s.value!==n.value&&e.push({time:n.time-1,value:s.value}),(!s||s.value!==n.value||n===t[t.length-1])&&e.push(n)}return e}function Aw(t,e,n){const s=r=>`${r.target}\0${r.property}`,i=new Map(e.map(r=>[s(r),r]));return[...t.map(r=>{const a=i.get(s(r));if(!a)return r;i.delete(s(r));const c=[...(r.keyframes??[]).filter(h=>h.time<n.from||h.time>n.to),...a.keyframes??[]].sort((h,u)=>h.time-u.time);return{...r,keyframes:c}}),...i.values()]}function Pw(t){const e=new Wt({id:`${t.leaderId}-tow`,tracks:t.leaderTracks.filter(f=>f.target===t.leaderId)}),n=t.every??33,s=t.towed,i=s.x+s.width/2,o=s.props,r=s.prop.wheelRadius,a=[],l=[],c=[];let h=o.wheelSpin??0,u;for(let f=t.start;;f=Math.min(t.end,f+n)){const g=Mi(t.leader,{state:e.getStateAtTime(f)},t.leaderId),p=g.anchor(t.hitch),m=g.values.turn,b=ts(s.prop,{...o,turn:m},s.propScale).anchors[t.anchor];if(!b)throw new Error(`propTow: ${s.prop.kind} has no anchor "${t.anchor}"`);const k=p.x-b.point.x;if(u!==void 0&&r){const w=Math.sin(m*Math.PI/2);h+=(k-u)*(w||1)/s.propScale/r*(180/Math.PI)}if(u=k,a.push({time:f,value:k-i}),l.push({time:f,value:m}),c.push({time:f,value:h}),f>=t.end)break}const d=t.towedId;return[{id:`${d}-x`,target:d,property:"x",keyframes:a},{id:`${d}-turn`,target:d,property:"turn",keyframes:l},...r?[{id:`${d}-wheelSpin`,target:d,property:"wheelSpin",keyframes:c}]:[]]}const Vd=new WeakMap;function $w(t,e){const n=e?.some(Boolean)?e.map(d=>d?1:0).join(""):"";let s=Vd.get(t);s||Vd.set(t,s=new Map);const i=s.get(n);if(i)return i;const o=Jn(t),r={vertices:o.vertices,faces:o.faces.filter((d,f)=>!e?.[f])},a=r.vertices.flatMap(d=>[d[0],d[1],d[2]]),l=r.vertices.map(()=>[0,0,0]),c=[];r.faces.forEach(d=>{for(const p of d.corners)for(const m of[0,1,2])l[p][m]+=d.normal[m];const[f,...g]=d.corners;for(let p=0;p+1<g.length;p++){const[m,b,k]=[f,g[p],g[p+1]],[w,M,S]=[r.vertices[m],r.vertices[b],r.vertices[k]],A=[M[0]-w[0],M[1]-w[1],M[2]-w[2]],E=[S[0]-w[0],S[1]-w[1],S[2]-w[2]],$=[A[1]*E[2]-A[2]*E[1],A[2]*E[0]-A[0]*E[2],A[0]*E[1]-A[1]*E[0]],v=$[0]*d.normal[0]+$[1]*d.normal[1]+$[2]*d.normal[2];c.push(...v>=0?[m,b,k]:[m,k,b])}});const h=l.flatMap(d=>{const f=Math.hypot(...d)||1;return[d[0]/f,d[1]/f,d[2]/f]}),u=Us({positions:a,normals:h,indices:c});return s.size>=16&&s.clear(),s.set(n,u),u}function xw(t,e,n={}){const s=t.ink??n.ink??"#26262b",i=(n.outline??2)*(t.outline??1),o=t.glow&&e.glow>0?_w(t.glow.color,e.glow):void 0;return{color:t.fill??s,creases:Jn(t.shape).creases!==!1,shading:n.shading??"toon",...i>0?{outline:{width:i,color:s}}:{},...o?{emissive:o}:{},...t.seeThrough?{opacity:.45*e.opacity}:e.opacity<1?{opacity:e.opacity}:{}}}function _w(t,e){const n=/^#([0-9a-f]{6})$/i.exec(t.trim());return n?`#${[0,2,4].map(i=>Math.round(parseInt(n[1].slice(i,i+2),16)*Math.max(0,Math.min(1,e)))).map(i=>i.toString(16).padStart(2,"0")).join("")}`:t}const Iw=Us(Ph(1,.002,28));function Ow(t,e,n){const s=t.rig,[i,o]=s.footprint??[s.length*.45,s.length],r=Math.max(0,yt(s,e,"lift")),a=Math.max(0,yt(s,e,"size"))/(1+r*.8);return{mesh:Iw,world:bt(n,eo([0,.004,0],[0,0,0,1],[i*.55*a||1e-4,1,o*.55*a||1e-4])),material:{color:"#000000",shading:"unlit",opacity:.16*a}}}const Cw=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),Hw=1,Rw={kind:"prop",validate(t){const e=t,n=typeof e.prop=="string"&&e.prop in mn?[]:[ft("prop preset",e.prop,Object.keys(mn))];for(const[s,i]of[[0,"rotateX"],[1,"rotateY"],[2,"rotateZ"]])i in e&&n.push(`${i} is a track, not a field: place it turned with rotation: [${[0,1,2].map(o=>o===s?e[i]:0).join(", ")}]`);return n},prepare(t){const e=t;return Kd(e.prop,e.options)},resolve({object:t,prepared:e,values:n,world:s,camera:i,lights:o=[],fog:r,toScreen:a}){const l=t,c=e,h={...l.values};for(const[E,$]of n)typeof $=="number"&&!Cw.has(E)&&(h[E]=$);h.turn=0,h.tilt=0;const u=bt(i.view,s),d={toView:E=>Ct(u,E),toScreen:E=>a(E)},f=d.toView([0,c.rig.height/2,0]);if(-f[2]<=i.near)return null;if(l.look==="mesh"){const E=fd(c.rig,h),$=E.map(({part:x,local:_})=>({part:x.id,mesh:Jn(x.shape),...zr(Jn(x.shape),_)})),v=ad($),O=E.map((x,_)=>({...x,hidden:cd(x.part.id,$[_].mesh,x.local,$[_].key,v)})).filter(({opacity:x})=>x>.01).map(({part:x,matrix:_,glow:F,opacity:I,hidden:L})=>({mesh:$w(x.shape,L),world:bt(s,_),material:xw(x,{glow:F,opacity:I},{shading:l.shading,ink:l.ink,outline:l.outline})}));return{meshes:l.shadow===!1?O:[Ow(c,h,s),...O]}}const g=a(f),p=a(d.toView([0,c.rig.height/2+1,0])),m=Math.hypot(p.x-g.x,p.y-g.y),b=o.length===0?void 0:(E,$)=>{const v=Ct(s,E),O=[s[0]*$[0]+s[4]*$[1]+s[8]*$[2],s[1]*$[0]+s[5]*$[1]+s[9]*$[2],s[2]*$[0]+s[6]*$[1]+s[10]*$[2]],x=Math.hypot(...O)||1;return{light:Dh(v,[O[0]/x,O[1]/x,O[2]/x],o),fog:Nh(r,Math.hypot(v[0]-i.position[0],v[1]-i.position[1],v[2]-i.position[2]))}},k=Jr(c.rig,h,d,m,{perspective:!0,near:i.near,slice:Hw,light:b}),w={look:l.look,style:l.style,ink:l.ink,paper:l.paper,fog:r?.color},M=ar(k),S=k.cells??[],A=Math.max(...S.map(E=>-E.depth),-f[2]);return{drawables:[...l.shadow===!1?[]:[{depth:A+c.rig.length,draw:E=>lr(E,k,w)}],...S.map(E=>({depth:-E.depth,draw($,v){$.lineCap="round",$.lineJoin="round",Bh($,E.parts,M,{...w,time:v.time})}}))]}}},ia=["do","at","for","to","through","toward","speed","height","open","on","wind"],Lw=.25,Fw=800/180,Dw=220,Nw=300,Bw=["turn"];function Ww(t){const e=Ti(t),n=Object.keys(t.moves??{});return Object.keys(e).filter(s=>!n.includes(s)&&!Bw.includes(s)&&!(e[s].needs??[]).includes("to"))}function Jd(t,e){if(!Array.isArray(t))return[{beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const n=Object.keys(e.moves??{}),s=Ww(e),i=[...n,"face","hold",...s.filter(r=>r!=="hold")],o=[];return t.forEach((r,a)=>{const l=u=>o.push({beat:a,message:u});if(!r||typeof r!="object"||Array.isArray(r))return l(`Each beat must be an object like { do: '${i[0]??"hold"}' }.`);const c=r,h={duration:"for",path:"through",points:"through",position:"to",heading:"toward",direction:"toward"};for(const u of Object.keys(c))ia.includes(u)||l(ft("beat field",u,ia,h[u]));if(typeof c.do!="string"||!i.includes(c.do)){const u=c.do==="turn"?"face":void 0;return l(ft(`${e.kind} 3D beat`,c.do,i,u))}n.includes(c.do)&&(c.to===void 0&&c.through===void 0&&l(`\`${c.do}\` needs \`to\` ([x, z] metres) or \`through\` (a list of them).`),c.to!==void 0&&!Oe(c.to)&&l(`\`to\` is a point on the ground, [x, z] metres (got ${JSON.stringify(c.to)}).`),c.through!==void 0&&!(Array.isArray(c.through)&&c.through.length>0&&c.through.every(Oe))&&l("`through` is a list of points on the ground, each [x, z] metres.")),c.do==="face"&&!(Oe(c.toward)||typeof c.toward=="number")&&l("`face` needs `toward`: a point [x, z] or a heading in degrees.")}),o}function jw(t,e,n,s){const i=Jd(n,e);if(i.length>0)throw new Error(`propScript3D (${e.kind}): ${i.length} problem(s) in the beats:
63
- ${i.map(w=>` beat ${w.beat}: ${w.message}`).join(`
64
- `)}`);const o={};for(const w of[...Object.keys(pn),...Object.keys(e.rig.controls)])o[w]=s.values?.[w]??yt(e.rig,{},w);let[r,a]=s.position??[0,0],l=s.heading??0;const c=new Map,h=(w,M,S,A="linear")=>{const E=c.get(w)??[];E.push({time:M,value:S,easing:A}),c.set(w,E)},u=(w,M,S)=>h(w,M,S);h("x",0,r),h("z",0,a),h("rotateY",0,l);const d=(w,M)=>{const S=ii(l,M);if(Math.abs(S)<1)return w;const A=Math.max(Dw,Math.abs(S)*Fw);return u("rotateY",w,l),l+=S,h("rotateY",w+A,l,"ease-in-out"),w+A},f=(w,M,S)=>{const A=iu([[r,a],...M.through??[M.to]]);if(A.length<2)return S;const E=d(S,hn(A[0].point,A[1].point)),$=A[A.length-1].at,v=M.for??$/(M.speed??w.speed)*1e3,O=$t("ease-in-out"),x=Math.min(Nw,v/4);for(const[Y,j]of Object.entries(w.set??{}))u(Y,E,o[Y]),h(Y,E+1,j),o[Y]=j;const _=w.flies?M.height??(o.lift>.05?o.lift:2):void 0,F=_!==void 0&&_>.05;for(const[Y,j]of Object.entries(w.hold??{}))u(Y,E,o[Y]),h(Y,E+x,j,"ease-out"),F||(h(Y,E+v-x,j),h(Y,E+v,0,"ease-in")),o[Y]=F?j:0;_!==void 0&&(u("lift",E,o.lift),h("lift",E+Math.min(v*.35,1400),_,"ease-out"),h("lift",E+v,_),o.lift=_);const I={...o};let L=l;for(let Y=0;;Y=Math.min($,Y+Lw)){const j=E+ru(O,Y/$)*v,{point:U,direction:J}=ou(A,Y);L+=ii(L,hn([0,0],J)),h("x",j,U[0]),h("z",j,U[1]),h("rotateY",j,L);for(const[P,H]of Object.entries(w.perMetre??{}))h(P,j,I[P]+Y*H);for(const[P,H]of Object.entries(w.perSecond??{}))h(P,j,I[P]+(j-E)/1e3*H);if(Y>=$)break}for(const[Y,j]of Object.entries(w.perMetre??{}))o[Y]=I[Y]+$*j;for(const[Y,j]of Object.entries(w.perSecond??{}))o[Y]=I[Y]+v/1e3*j;return[r,a]=A[A.length-1].point,l=L,E+v},g=(w,M)=>{const S=Object.fromEntries(Object.entries(w).filter(([E])=>!["at","to","through","toward"].includes(E))),A=Xd(t,e,[S],{start:{...o,turn:1},scale:100,style:s.style,exaggeration:s.exaggeration});for(const E of A.tracks){if(qw.includes(E.property))continue;const $=E.keyframes??[],v=o[E.property];if(!$.every(O=>O.value===v)){u(E.property,M,v);for(const O of $)O.time>0&&c.get(E.property).push({...O,time:M+O.time});o[E.property]=$[$.length-1].value}}return M+A.duration},p=[];let m=0;for(const w of n){const M=w.at??m;let S=M;const A=e.moves?.[w.do];A?S=f(A,w,M):w.do==="face"?S=d(M,typeof w.toward=="number"?w.toward:hn([r,a],w.toward)):w.do==="hold"?S=M+(w.for??1e3):S=g(w,M),p.push({do:w.do,start:M,end:S}),m=S}const b=`${s.scene}/${t}`;return{tracks:[...c].map(([w,M])=>({id:`${t}-${w}`,target:b,property:w,keyframes:su(M)})),duration:m,beats:p,end:{position:[r,a],heading:l,values:{...o}}}}const qw=["x","y","turn","facing","tilt"],Kw=.35,Zd={seated:Ie.sit,astride:{...Ie.sit,"leg.left.spread":26,"leg.right.spread":26,"leg.left.swing":40,"leg.right.swing":40,"leg.left.knee":70,"leg.right.knee":70}},Qd=(t,e)=>{const n=e*Math.PI/180;return[t[0]*Math.cos(n)+t[2]*Math.sin(n),t[1],-t[0]*Math.sin(n)+t[2]*Math.cos(n)]};function Yw(t){const e=`${t.scene}/${t.propId}`,n=new Wt({id:`${t.propId}-ride-3d`,tracks:t.propTracks.filter(m=>m.target===e)}),s=t.placement??{},[i,o,r]=s.position??[0,0,0],a=t.prop.rig,l=tr({...t.character,height:1}),c={...mt,...t.pose??Zd.seated},h=Xs(l.plan,c,{height:t.height??1.7,contact:l.contact}).hip,u=t.facing??0,d=t.every??33,f={x:[],y:[],z:[],rotateY:[]};for(let m=t.start;;m=Math.min(t.end,m+d)){const b=n.getStateAtTime(m).values.get(e)??new Map,k=(I,L)=>{const N=b.get(I);return typeof N=="number"?N:L},w={...s.values};for(const I of Object.keys(a.controls))w[I]=k(I,s.values?.[I]??yt(a,{},I));for(const I of["pitch","roll","squash","lift","lean","size"])w[I]=k(I,s.values?.[I]??yt(a,{},I));const M=pd(a,w)[t.anchor];if(!M)throw new Error(`propRide3D: ${t.prop.kind} has no anchor "${t.anchor}" (it has ${Object.keys(a.anchors??{}).join(", ")||"none"})`);const S=k("rotateY",s.heading??0),A=Qd(M,S),E=[k("x",i)+A[0],k("y",o)+A[1],k("z",r)+A[2]],$=S+u,v=Qd(h,$);let O=[E[0]-v[0],E[1]-v[1],E[2]-v[2]];const x=(I,L)=>{const N=L*L*(3-2*L);return[I[0]+(O[0]-I[0])*N,O[1]*N+Kw*Math.sin(Math.PI*L),I[1]+(O[2]-I[1])*N]},_=t.mount?Math.max(1,t.mount.for??450):0,F=t.dismount?Math.max(1,t.dismount.for??450):0;if(t.mount&&m<t.start+_?O=x(t.mount.from,(m-t.start)/_):t.dismount&&m>t.end-F&&(O=x(t.dismount.to,(t.end-m)/F)),f.x.push({time:m,value:O[0]}),f.y.push({time:m,value:O[1]}),f.z.push({time:m,value:O[2]}),f.rotateY.push({time:m,value:$}),m>=t.end)break}const g=t.riderId,p=`${t.scene}/${g}`;return Object.keys(f).map(m=>({id:`${g}-${m}`,target:p,property:m,keyframes:f[m]}))}function zw(t){const{timeline:e}=t,n=new $e;for(const[c,h]of Object.entries(t.targets)){const u=typeof h=="string"?document.querySelector(h):h;if(!u)throw new Error(`quickPlay: no element found for target "${c}" (${String(h)})`);n.registerTarget(c,u)}e.onUpdate=c=>{n.applyState(c),t.onUpdate?.(c)},t.onComplete&&(e.onComplete=t.onComplete);let s=null,i=null,o=!1;const r=c=>{if(o)return;const h=i===null?0:c-i;i=c,h>0&&e.tick(h),s=requestAnimationFrame(r)},a=()=>{s!==null||o||(i=null,s=requestAnimationFrame(r))},l=()=>{s!==null&&cancelAnimationFrame(s),s=null,i=null};return n.applyState(e.getStateAtTime(e.currentTime)),t.autoplay!==!1&&(e.play(),a()),{timeline:e,adapter:n,play(){e.play(),a()},pause(){e.pause(),l()},restart(){e.stop(),e.play(),a()},seek(c){e.seek(c*1e3),n.applyState(e.getStateAtTime(e.currentTime))},destroy(){o=!0,l(),e.stop(),n.clearTargets()}}}const Xw={timeline:J0,to(t,e,n){const s=new Pe(n);return s.to(t,e),s},from(t,e,n){const s=new Pe(n);return s.from(t,e),s},fromTo(t,e,n,s){const i=new Pe(s);return i.fromTo(t,e,n),i},set(t,e,n){const s=new Pe(n);return s.set(t,e),s}};function tf(t,e,n){if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(e,n);const s=t.canvas;if(s?.ownerDocument){const i=s.ownerDocument.createElement("canvas");return i.width=e,i.height=n,i}try{return s?.constructor?new s.constructor(e,n):null}catch{return null}}function Gw(t,e){const n=t.length/4,s=new Float32Array(n*3),i=Math.min(.999,Math.max(0,e));for(let o=0;o<n;o++){const r=t[o*4]/255,a=t[o*4+1]/255,l=t[o*4+2]/255,c=t[o*4+3]/255,h=Math.max(r,a,l);if(h<=i)continue;const u=(h-i)/(1-i)*c/h;s[o*3]=r*u,s[o*3+1]=a*u,s[o*3+2]=l*u}return s}function ef(t,e,n,s,i){const o=new Float32Array(t.length),r=i?n:e,a=i?e:n,l=(h,u)=>(i?h*e+u:u*e+h)*3,c=s*2+1;for(let h=0;h<r;h++)for(let u=0;u<3;u++){let d=0;for(let f=-s;f<=s;f++)d+=t[l(h,Math.min(a-1,Math.max(0,f)))+u];for(let f=0;f<a;f++){o[l(h,f)+u]=d/c;const g=t[l(h,Math.max(0,f-s))+u],p=t[l(h,Math.min(a-1,f+s+1))+u];d+=p-g}}return o}function nf(t,e,n,s){const i=Math.max(1,Math.round(s/Math.sqrt(3)));let o=t;for(let r=0;r<3;r++)o=ef(o,e,n,i,!0),o=ef(o,e,n,i,!1);return o}function Uw(t,e={}){const n=t.canvas,s=n.width,i=n.height;if(!(s>0&&i>0))return;const o=Math.max(1,Math.round(e.downsample??4)),r=Math.max(1,Math.ceil(s/o)),a=Math.max(1,Math.ceil(i/o)),l=tf(t,r,a),c=l?.getContext("2d");if(!l||!c)return;c.imageSmoothingEnabled=!0,c.drawImage(t.canvas,0,0,r,a);const h=Gw(c.getImageData(0,0,r,a).data,e.threshold??.55),u=(e.radius??Math.max(s,i)*.02)/o,d=nf(h,r,a,u),f=nf(h,r,a,u*3),g=e.halo??.6,p=c.createImageData(r,a);for(let m=0;m<r*a;m++){for(let b=0;b<3;b++)p.data[m*4+b]=Math.round(Math.min(1,d[m*3+b]+f[m*3+b]*g)*255);p.data[m*4+3]=255}c.putImageData(p,0,0),t.save(),t.setTransform(1,0,0,1,0,0),t.globalCompositeOperation="lighter",t.globalAlpha=Math.max(0,e.strength??.9),t.imageSmoothingEnabled=!0,t.drawImage(l,0,0,s,i),t.restore()}function Vw(t,e,n){const s=n.width??6,i=n.taper??1,o=n.fade??1,r=n.opacity??1,a=n.blend==="add";if(t.save(),e.length>=2){const c=Zw(e,s,i,o,r);a?(t.globalCompositeOperation="lighter",oa(t,c,n.color)):Qw(t,c,n.color)}const l=e[e.length-1];if(n.head&&l&&n.head.radius>0){a&&(t.globalCompositeOperation="lighter");const c=n.head.color??n.color,h=t.createRadialGradient(l.at.x,l.at.y,0,l.at.x,l.at.y,n.head.radius);h.addColorStop(0,c),h.addColorStop(.35,c),h.addColorStop(1,Jw(t,c)),t.globalAlpha=r,t.fillStyle=h,t.beginPath(),t.arc(l.at.x,l.at.y,n.head.radius,0,Math.PI*2),t.fill()}t.restore()}function Jw(t,e){t.fillStyle=e;const n=String(t.fillStyle),s=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i.exec(n);if(s)return`rgba(${parseInt(s[1],16)}, ${parseInt(s[2],16)}, ${parseInt(s[3],16)}, 0)`;const i=/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i.exec(n);return i?`rgba(${i[1]}, ${i[2]}, ${i[3]}, 0)`:"rgba(0, 0, 0, 0)"}function Zw(t,e,n,s,i){const o=t.map(c=>({x:c.at.x,y:c.at.y,width:e*(1-n*c.age)})),r=ml(o),a=yl(o)??void 0,l=[];for(let c=0;c+1<t.length;c++){const h=(t[c].age+t[c+1].age)/2,u=i*(1-s*h);if(u<=0)continue;const d=c+2===t.length;l.push({corners:[r.left[c],r.left[c+1],r.right[c+1],r.right[c]],alpha:u,...d&&a&&{cap:a}})}return l}function oa(t,e,n){t.fillStyle=n;for(const s of e){const[i,o,r,a]=s.corners;t.globalAlpha=Math.min(1,s.alpha),t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(o.x,o.y),s.cap&&t.arc(s.cap.x,s.cap.y,s.cap.radius,s.cap.start,s.cap.start-Math.PI,!0),t.lineTo(r.x,r.y),t.lineTo(a.x,a.y),t.closePath(),t.fill()}}function Qw(t,e,n){const s=typeof t.getTransform=="function"?t.getTransform():null,i=p=>s?{x:s.a*p.x+s.c*p.y+s.e,y:s.b*p.x+s.d*p.y+s.f}:p,o=s?Math.sqrt(Math.abs(s.a*s.d-s.b*s.c)):1,r=e.map(p=>({...p,corners:p.corners.map(i),...p.cap&&{cap:{...p.cap,...i(p.cap),radius:p.cap.radius*o,start:p.cap.start+(s?Math.atan2(s.b,s.a):0)}}}));let a=1/0,l=1/0,c=-1/0,h=-1/0;for(const p of r){const m=p.cap?[{x:p.cap.x-p.cap.radius,y:p.cap.y-p.cap.radius},{x:p.cap.x+p.cap.radius,y:p.cap.y+p.cap.radius}]:[];for(const b of[...p.corners,...m])a=Math.min(a,b.x),l=Math.min(l,b.y),c=Math.max(c,b.x),h=Math.max(h,b.y)}if(!(c>a&&h>l))return;const u=Math.floor(a)-1,d=Math.floor(l)-1,f=s?tf(t,Math.ceil(c)+1-u,Math.ceil(h)+1-d):null,g=f?.getContext("2d");if(!f||!g){oa(t,e,n);return}g.translate(-u,-d),g.globalCompositeOperation="lighter",oa(g,r,n),t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=1,t.drawImage(f,u,d),t.restore()}const tk=Ht.to,ek=Ht.from,nk=Ht.fromTo,sk=Ht.set,ik=Ht.timeline,ok=Ht.ticker,rk=Ht.splitText,ak=Ht.context,lk=Ht.matchMedia,ck=Ht.quickTo,hk=Ht.imageSequence,uk=Ht.pageTransition;Tg(),y.ACTING_STYLES=Ce,y.AIRCRAFT_ACTING=Zr,y.ANIMAL_GAITS=gn,y.BEAT_FIELDS=di,y.BIRD_ACTING=Bd,y.CANVAS_PROPERTIES=gi,y.CHARACTER_BEAT_3D_FIELDS=mr,y.CHARACTER_GAIT_SPEEDS=au,y.CODE_LANGUAGES=li,y.CODE_PANEL_EDITS=Sr,y.CODE_THEME=pu,y.Clock=af,y.CompatTimeline=Pe,y.CustomBounce=oc,y.CustomEase=ic,y.CustomWiggle=rc,y.DANCE_STYLES=ge,y.DEFAULT_BAKE_INTERVAL_MS=qi,y.DEFAULT_INERTIA_FRICTION=Ii,y.DEFAULT_LABELS=gc,y.DEFAULT_SPRING=Nt,y.DEFAULT_TRANSITION=Ag,y.Draggable=ho,y.EXPRESSIONS=dt,y.FINGERS=Ic,y.FLIPS=jn,y.FORMAT_VERSION=Ei,y.GAGS=we,y.GAITS=_t,y.GAIT_CYCLE_MS=Lr,y.HAND_REST=kt,y.HAND_SHAPES=St,y.HORSE_ACTING=sw,y.HORSE_GAITS=Qb,y.HOUSE_ACTING=_d,y.HUMAN_ACTING_RIG=bu,y.HUMAN_EXPRESSIONS=Ko,y.HUMAN_GAGS=si,y.HUMAN_POSES=Ie,y.HUMAN_REST=mt,y.IDENTITY_CAMERA=cu,y.INERTIA_MAX_DURATION_MS=ua,y.InertiaTrackPlayer=Ja,y.LiveTimeline=Jt,y.MORPH_SAMPLES=xf,y.MUDRAS=Ls,y.ManualClock=rf,y.MediaSync=Eo,y.Observer=Rl,y.POSES=Lt,y.PROP_BEAT_3D_FIELDS=ia,y.PROP_BEAT_FIELDS=Si,y.PROP_COMMON_ACTIONS=na,y.PROP_COMMON_CONTROLS=pn,y.PROP_PRESETS=mn,y.QUADRUPED_ACTING=Qr,y.REMOVE_STYLES=ri,y.REST_POSE=it,y.RIDING_POSES=Zd,y.SCRIPT_ACTIONS=Un,y.SPRING_MAX_DURATION_MS=_i,y.SPRING_PRESETS=os,y.SPRING_STEP_MS=Ne,y.STICK_ACTING_RIG=yu,y.ScrollAnimator=Jl,y.ScrollDriver=_n,y.ScrollMarkers=Zl,y.ScrollPin=Xl,y.SmoothScroll=Mo,y.SpringSampler=wn,y.SpringTrackPlayer=Va,y.Stage=xl,y.TREE_ACTING=$d,y.Timeline=Wt,y.TinyflyPlayer=Es,y.TinyflySequencer=Sc,y.TrackPlayer=ds,y.VEHICLE_ACTING=yd,y.VISEMES=ke,y.ValueResolver=s0,y.VisibilityDriver=zl,y.actCharacterTracks=jy,y.actKeyframes=hi,y.actTracks=ku,y.actionNames=_r,y.airplane=Od,y.animalStrideLength=ki,y.animatableProperties=Qu,y.applyBloom=Uw,y.applyCamera=dy,y.applyGroove=fh,y.assertBeats=Hr,y.backOut=va,y.bakeDanceTracks=qm,y.bakeEasing=zi,y.bakeInertiaTrack=Yi,y.bakeSpringTrack=Ki,y.basicOutfit=Cy,y.beatAt=Bm,y.beatAtTime=ps,y.beatLength=Qi,y.beatTime=fs,y.beatsBetween=g0,y.bike=Ed,y.bindChoiceHotspots=wc,y.bird=vi,y.blendPose=sn,y.boilFrame=Po,y.bounceOut=ka,y.boxMesh=Uh,y.bus=vd,y.cameraFromValues=uy,y.cameraPoint=fy,y.cameraTracks=w0,y.capabilities=Gd,y.capabilitiesMarkdown=yw,y.car=wd,y.cart=Sd,y.cat=Fd,y.character=tr,y.characterAt=j1,y.characterHandPose=Ch,y.characterJoints=_h,y.characterJointsInView=F1,y.characterObjects=iy,y.characterPartsInView=Rh,y.characterPoseTracks=q1,y.characterScript3D=hy,y.characterTarget=W1,y.charactersFor=Za,y.checkBeats=Cr,y.checkCast=Ir,y.checkCharacterBeats3D=lu,y.checkPropBeats=zd,y.checkPropBeats3D=Jd,y.checkTracks=_b,y.chicken=qd,y.circlePath=yy,y.clamp01=bo,y.clearMorphCache=Df,y.clearPathCache=Tf,y.clipErased=Mr,y.closestName=An,y.codePanel=Py,y.codeTokens=mu,y.containerProgressAt=wo,y.context=ak,y.controlValue=yt,y.cow=Dd,y.create=cg,y.createControls=yc,y.createCubicBezier=ba,y.createLive=cc,y.createPen=Hn,y.createRandom=Xe,y.createTrack=us,y.criticalDamping=hf,y.crow=jd,y.customBounce=cl,y.customEase=ll,y.customWiggle=hl,y.cylinderMesh=Vh,y.danceFrame=Ns,y.dancePose=Rm,y.danceStance=Ds,y.danceTaps=Fm,y.danceTracks=jm,y.danceTravel=Ws,y.danceTravelTrack=bh,y.dancer=Wm,y.defineAction=tb,y.defineGait=eb,y.describeTarget=Zu,y.deserializeTimeline=ze,y.deserializeTrack=nl,y.detectTempo=m0,y.dog=Ld,y.draggable=Mp,y.drawCartoonHand=Cs,y.drawCharacter=Hh,y.drawCharacterInView=D1,y.drawDustPuff=Su,y.drawEraser=kr,y.drawHand=vr,y.drawImpactStars=zy,y.drawPencil=hu,y.drawProp=cw,y.drawPropEffects=bw,y.drawPropShadow=lr,y.drawSolvedFaces=Bh,y.drawSolvedPart=X1,y.drawSolvedProp=rr,y.drawSpeedLines=Mu,y.drawStickFigure=lh,y.drawStickSmear=Yy,y.drawTrail=Vw,y.drawnPathTarget=by,y.easeIn=ga,y.easeInCubic=Oi,y.easeInOut=ya,y.easeInOutCubic=vn,y.easeInOutQuad=pa,y.easeInQuad=da,y.easeOut=ma,y.easeOutCubic=Ci,y.easeOutQuad=fa,y.editDistance=fl,y.elasticOut=wa,y.ellipsePoints=$o,y.ellipsoidMesh=Jh,y.erasable=My,y.expandBeats=Rr,y.expandParametricEasings=Ga,y.extrudeMesh=Zh,y.flipPose=wh,y.flipTracks=i1,y.flipTravel=kh,y.formatVersionFor=Ai,y.from=ek,y.fromJSON=t0,y.fromTo=nk,y.gag=Pr,y.gagDuration=Xn,y.gaitPose=Rc,y.gaitStrideLength=Io,y.getEasingFunction=$t,y.getInterpolator=En,y.getMotionPathPoint=Xi,y.getPathLength=Ef,y.getPointAtProgress=Aa,y.gridLinesFor=Dl,y.handAt=my,y.handJoints=Os,y.handJointsAt=Hc,y.handPath=Ju,y.handPose=vt,y.handProp=Bn,y.hasKeyframes=la,y.hashSeed=Kt,y.headPoint=Em,y.heldTime=ca,y.helicopter=Id,y.horse=Rd,y.horseStrideLength=ow,y.house=xd,y.humanFieldLabel=w1,y.humanGag=Xh,y.humanGaitPose=Yh,y.humanGaitStrideLength=zh,y.humanPlan=Mh,y.humanPose=Ft,y.imageSequence=hk,y.inertiaDuration=We,y.inertiaRest=Be,y.inertiaValueAt=as,y.inertiaVelocityAt=pf,y.interpolateArray=Ka,y.interpolateColor=qa,y.interpolateMotionPath=Uf,y.interpolateNumber=Gt,y.interpolatePathString=za,y.interpolateQuaternion=Ya,y.interpolateString=ji,y.isCubicBezierEasing=De,y.isInertiaTrack=ie,y.isMotionPathPoint=of,y.isMotionPathTrack=Pi,y.isParametricEasing=yn,y.isPathData=qe,y.isSpringTrack=oe,y.isTextTrack=es,y.isUnderdamped=cf,y.isUnresolved=n0,y.jointsInScene=Fh,y.jointsToScene=ah,y.linear=ls,y.lipSyncKeyframes=xr,y.lipSyncOver=Ou,y.lipSyncTracks=Zy,y.lit=fr,y.live=Ht,y.mapEase=Pn,y.mat4=x0,y.matchMedia=lk,y.maxStaggerDistance=xi,y.mirrorHumanPose=b1,y.mirrorPose=dh,y.mixColors=pr,y.mixHandPoses=nn,y.mixPoses=N1,y.morphPath=Ca,y.motorbike=Ad,y.mount=kc,y.mountAll=Mc,y.narrationMarkers=u0,y.narrationSceneAt=d0,y.naturalRest=kn,y.nearestBeat=f0,y.nextBeat=p0,y.pageTransition=uk,y.panelMesh=Qh,y.parametricEasing=Sa,y.parseEdge=mo,y.parsePath=Se,y.parseTrigger=yo,y.partialPath=en,y.pathLength=$c,y.persona=$b,y.planNarration=h0,y.play=lg,y.playSequence=Eg,y.playWhenVisible=Rp,y.playheadCrossings=Ui,y.pointAlong=Ps,y.pointAtDistance=Ri,y.pointOnHead=C1,y.pointsToPath=gl,y.pose=Tt,y.poseTracks=xm,y.propActions=Ti,y.propAnchors3D=pd,y.propAt=Mi,y.propControls=Yd,y.propLineWidth=ar,y.propObjects=Rw,y.propPartsInSpace=fd,y.propPreset=Kd,y.propRide=Tw,y.propRide3D=Yw,y.propScript=Xd,y.propScript3D=jw,y.propShapeMesh=Jn,y.propTarget=lw,y.propTow=Pw,y.propView=hd,y.quadruped=Qn,y.quat=Kf,y.quickPlay=zw,y.quickTo=ck,y.randomBetween=Ji,y.randomChoice=e0,y.randomSnapped=il,y.reachCharacter=B1,y.resolveActingStyle=Tr,y.resolveCharacterPoseKeys=ir,y.resolveGait=Fn,y.resolvePoseKeys=Do,y.resolveSequence=al,y.resolveStickFrame=Ro,y.resolveStickPose=ch,y.resolveValue=Zi,y.ribbon=ml,y.ribbonHeadCap=yl,y.rotateAbout=de,y.routineBeats=Bs,y.rubberLimb=xe,y.scriptActionSummaries=Or,y.scriptTracks=Vu,y.scrollProgress=Hp,y.scrubOnScroll=Np,y.scrubPath=ky,y.seatHeight=wm,y.serializeTimeline=sl,y.serializeTrack=tl,y.set=sk,y.shade=ni,y.shapeMesh=nu,y.shapeToPathData=gs,y.simplifyKeyframes=Ua,y.sittingPose=Hd,y.skeletonInView=Gs,y.sketchPen=$s,y.smoothPath=gr,y.smoothToward=Yl,y.snapAxis=Fl,y.snapConfig=Gl,y.snapDuration=Vl,y.snapProgress=Ul,y.solveAt=ts,y.solvePlanSpace=zs,y.solveProp=Jr,y.songbird=Wd,y.soundsOf=Iu,y.speechDuration=Uu,y.spliceTracks=Aw,y.splitText=rk,y.springDuration=ha,y.springFollow=pl,y.springValueAt=lf,y.stagePlanSpace=Xs,y.staggerDistance=$i,y.staggerOffset=ns,y.staggerOffsets=ss,y.staggerSpan=bn,y.stepsDuration=Hu,y.stepsEasing=Ma,y.stepsToKeys=$r,y.stickFigureAt=Fo,y.stickFigureJoints=pe,y.stickFigureTarget=Lo,y.stickToHuman=v1,y.strideLength=Wc,y.syncMediaElement=pc,y.talkingMouth=jc,y.taperedLine=xs,y.taperedOutline=Cn,y.textAt=Qa,y.tf=Xw,y.ticker=ok,y.timeline=ik,y.to=tk,y.toJSON=Qf,y.toKeyframedTrack=Xf,y.toKeyframedTracks=Gf,y.trackTargets=ce,y.tractor=Md,y.trailSamples=v0,y.trainCar=Td,y.tree=Pd,y.triggerDistance=Je,y.truck=kd,y.tubeMesh=tu,y.unknownName=ft,y.unmount=Mg,y.vec3=S0,y.vehicle=se,y.walkPose=Bc,y.withErased=vy,y.withExpression=fe,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));
58
+ `)}`)}em(Qr);function qb(t){const e="steps"in t&&typeof t.steps=="function",n="beats"in t&&typeof t.beats=="function";if(e===n)throw new Error("defineAction: give either `steps: (from, beat) => [...]` or `beats: (beat) => [...]`");if(!t.summary)throw new Error("defineAction: give a `summary`: one line on what the figure does");return t}function Kb(t){for(const e of["swing","knee","arm","elbow","lean"])if(typeof t[e]!="number")throw new Error(`defineGait: \`${e}\` must be a number (degrees)`);if(t.cycle!==void 0&&!(t.cycle>0))throw new Error("defineGait: `cycle` is ms per two steps, above 0");return t}const lu=8;function xi(t,e={},n=0){if(n>lu)throw new Error(`scriptTracks: custom actions nest more than ${lu} deep (does one build itself?)`);return t.flatMap(s=>{const i=e[s.do];if(!i||!("beats"in i))return[s];const o=i.beats(s).map((r,a)=>a===0?{...r,...s.at!==void 0&&r.at===void 0?{at:s.at}:{},...s.mood&&!r.mood?{mood:s.mood}:{},...s.say&&!r.say?{say:s.say}:{}}:r);return xi(o,e,n+1)})}function cu(t){return t.length===0?0:Math.max(...t.map(e=>e.after))}const ea={walk:1e3,bouncy:900,doubleBounce:1100,sneak:1600,strut:1100,tired:1500,shove:1300,run:560},Yb=450,zb=2.4,Xb=160,hu=2.5,Ub=200,Gb=340,Vb=1.1,du=[380,900],Jb=.35,Ii=300,na=150,Zb=260,Qb=1.2,sa=160,uu=400,hs=300,tw=450,fu=500,ia=350,pu=150,ew=120,oa=180,gu=420,nw=300,mu=300,sw=140,ra=150,yu=450,iw=450,aa=150,bu=350,wu=400,ow=12,rw=600,ku=90,vu=400,aw=200,lw=.09,Mu=350,se=450,la=1200,cw=700,bn=320,ie=220,hw=65,dw=700,Su=t=>t in Me,uw=t=>t in Dt;function Tu(t){return Math.max(dw,Array.from(t).length*hw)}function ca(t,e,n={}){const s={actions:n.actions,gaits:n.gaits};ta(e,s);const i=n.gait??"walk",o=xi(e,n.actions).map(x=>x.do==="go"?{...x,do:i}:x);ta(o,s,"scriptTracks (after expanding custom actions)");const r=x=>Ot[x]??n.gaits?.[x],a=x=>ea[x]??n.gaits?.[x]?.cycle??1e3,l=x=>{const R=n.actions?.[x];return R&&"steps"in R?R:void 0},c=n.from??0,h=n.ground??0,d=n.height??300;let u=c,f=h,g=n.facing??1,p=n.start??et,m=0,b=0;const S=[{time:0,pose:p}],k=[{time:0,value:0}],y=[{time:0,value:0}],M=[{time:0,value:0}],$=[{time:0,value:0}],E=[{time:0,value:"walk"}],A=[{time:0,value:g}],T=[],I=[],v=[],P=(x,R,q,U)=>{p={...p,...R},q&&(p=ge(p,q)),S.push({time:x,pose:p,...U===!1?{act:U}:{}})},H=(x,R,q)=>(P(x+bn/2,{turn:0},q),A.push({time:x+bn/2,value:g},{time:x+bn/2+1,value:R}),g=R,P(x+bn,{turn:1}),x+bn),O=x=>x<u?-1:1,C=(x,R,q)=>O(R)!==g?H(x,O(R),q):x,j=(x,R,q,U="arm")=>{const Y=U==="arm",Z=me({...x,...Y?{rightShoulder:0,rightElbow:0}:{rightHip:0,rightKnee:0}},{height:d,facing:g}),nt=Y?Z.shoulders.right:Z.hip,F=Y?Z.elbows.right:Z.knees.right,z=(Q,tt)=>Math.atan2(g*Q,tt)*180/Math.PI,V=((z(R-(u+nt.x),q-(f+nt.y))-z(F.x-nt.x,F.y-nt.y))%360+360)%360;return V>270?V-360:V},D=(x,R,q,U)=>{const Y=U==="arm",Z=me({...x,...Y?{rightShoulder:90,rightElbow:0,rightWrist:0}:{rightHip:90,rightKnee:0}},{height:d,facing:g}),nt=Y?Z.shoulders.right:Z.hip,F=Y?{x:(Z.hands.right.x+Z.fingertips.right.x)/2,y:(Z.hands.right.y+Z.fingertips.right.y)/2}:Z.feet.right,z=Math.hypot(F.x-nt.x,F.y-nt.y),K=q-(f+nt.y),V=Math.abs(K)<z?Math.sqrt(z*z-K*K):z*.1;return R-nt.x-g*V},W=x=>{const R=me(x,{height:d,facing:g});return{x:u+(R.hands.right.x+R.fingertips.right.x)/2,y:f+(R.hands.right.y+R.fingertips.right.y)/2}},B=(x,R,q)=>{const U={...x,rightWrist:0,rightElbow:0,rightShoulder:j(x,R,q)},Y=me(U,{height:d,facing:g}),Z={x:u+Y.shoulders.right.x,y:f+Y.shoulders.right.y},nt={x:u+Y.elbows.right.x,y:f+Y.elbows.right.y},F=W(U),z=Math.hypot(nt.x-Z.x,nt.y-Z.y),K=Math.hypot(F.x-nt.x,F.y-nt.y),V=Math.min(z+K-.01,Math.max(Math.abs(z-K)+.01,Math.hypot(R-Z.x,q-Z.y))),Q=rt=>rt*180/Math.PI,tt=Q(Math.acos((z*z+V*V-K*K)/(2*z*V))),st=180-Q(Math.acos((z*z+K*K-V*V)/(2*z*K)));let pt={rightShoulder:U.rightShoulder,rightElbow:0},ht=1/0;for(const rt of[1,-1])for(const wt of[1,-1]){const J={rightShoulder:U.rightShoulder+rt*tt,rightElbow:wt*st},kt={...x,rightWrist:0,...J},gt=W(kt),G=Math.hypot(gt.x-R,gt.y-q)-me(kt,{height:d,facing:g}).elbows.right.y*.001;G<ht&&(ht=G,pt=J)}return pt},_=(x,R,q)=>Math.abs(R-u)<2?x:(k.push({time:x,value:u-c},{time:x+q,value:R-c,easing:"ease-in-out"}),u=R,x+q);for(const x of o){const R=Math.max(x.at??b,b===0?0:S[S.length-1].time);let q=R,U,Y;const Z=x.pose??{},nt=l(x.do);if(r(x.do)){const F=x.to??u,z=F===u?g:O(F);let K=R;z!==g?K=H(R,z,x.mood):p.turn<1?(K=R+ie,P(K,{turn:1,...Z},x.mood)):(x.mood||x.pose)&&P(R+ie,Z,x.mood);const Q=Math.abs(F-u)/Uo(r(x.do),d),tt=x.for??Math.max(ie*2,Q*a(x.do)),st=K+tt;E.push({time:K,value:x.do}),$.push({time:K,value:0},{time:K+ie,value:1,easing:"ease-out"}),$.push({time:st-ie,value:1},{time:st,value:0,easing:"ease-in"}),M.push({time:K,value:m},{time:st,value:m+Q}),k.push({time:K,value:u-c},{time:st,value:F-c}),m+=Q,u=F,P(st,{}),q=st}else if(x.do==="zip"){const F=x.to??u,z=F===u?g:O(F);let K=R;z!==g?K=H(R,z,x.mood):p.turn<1&&(K=R+ie,P(K,{turn:1},x.mood));const V=Ur("windUp",{at:K,from:x.mood?ge(p,x.mood):p});S.push(...V),p=V[V.length-1].pose;const Q=K+rs("windUp"),tt=Q+Yb,st=tt+Math.max(Xb,Math.abs(F-u)/zb);E.push({time:Q,value:"run"}),$.push({time:Q,value:0},{time:Q+80,value:1,easing:"ease-out"},{time:st,value:1},{time:st+120,value:0}),M.push({time:Q,value:m},{time:tt,value:m+hu,easing:"ease-in"}),m+=hu+(st-tt)/ea.run*1.5,M.push({time:st,value:m}),k.push({time:tt,value:u-c},{time:st,value:F-c,easing:"ease-in"}),v.push({kind:"dust",time:tt,x:u,y:f,length:900}),u=F,P(st,{}),q=st}else if(x.do==="leap"){const F=x.to??u,z=x.onto??f;let K=F===u?R:C(R,F,x.mood);p.turn<1&&(K+=ie,P(K,{turn:1},x.mood));const V={leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50};P(K+Ub,{stretch:.75,bend:12,leftHip:22,rightHip:22,...V},x.mood,!1);const Q=K+Gb;P(Q-40,{stretch:.72},void 0,!1),P(Q,{stretch:1.2,bend:-6,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4},void 0,!1);const tt=Math.hypot(F-u,z-f),st=x.for??Math.min(du[1],Math.max(du[0],300+tt*Vb)),pt=Math.min(f,z)-Jb*d,ht=Math.sqrt(f-pt),rt=Math.sqrt(z-pt),wt=Q+st*ht/(ht+rt),J=Q+st;P(wt,{stretch:1,bend:4,leftHip:-55,leftKnee:-80,rightHip:55,rightKnee:80,leftShoulder:110,rightShoulder:110},void 0,!1),P(J,{stretch:.72,bend:12,leftShoulder:75,rightShoulder:75,leftElbow:0,rightElbow:0,leftHip:18,rightHip:18,leftKnee:0,rightKnee:0},void 0,!1),P(J+180,{stretch:1.05,bend:-3},void 0,!1),P(J+340,{stretch:1,bend:0,leftHip:et.leftHip,rightHip:et.rightHip,leftShoulder:et.leftShoulder,rightShoulder:et.rightShoulder,leftElbow:et.leftElbow,rightElbow:et.rightElbow},void 0,!1),k.push({time:Q,value:u-c},{time:J,value:F-c}),y.push({time:Q,value:f-h},{time:wt,value:pt-h,easing:"ease-out-quad"},{time:J,value:z-h,easing:"ease-in-quad"}),u=F,f=z,v.push({kind:"dust",time:J,x:u,y:f,length:500}),q=J+340,U=J}else if(x.do==="point"&&x.target){const F=x.target,z=C(R,F.x,x.mood),K={...p,...x.mood?ct[x.mood]:{},turn:Math.max(p.turn,.6),rightElbow:0,rightWrist:0,...Z},V=me(K,{height:d,facing:g}).head.center,Q=Math.abs(F.x-(u+V.x)),tt=F.y-(f+V.y),st=z+se;P(st,{...K,rightShoulder:j(K,F.x,F.y),lookX:1,lookY:fw(tt/Math.max(1,Math.hypot(Q,tt)))*.8}),q=st+(x.for??la),U=st,Y=q}else if(x.do==="swipe"){const F=x.target??{x:u+g*d*.5,y:f-d*.6},z=O(F.x),K=C(R,F.x,x.mood),V=z===1?F.left??F.x:F.right??F.x,Q=z===1?F.right??F.x:F.left??F.x,tt={...p,turn:1,lean:-10,bend:-8,rightElbow:40,lookX:1,...Z};P(K+Ii,{...tt,rightShoulder:j(tt,u-g*d*.3,f-d*1.1)},x.mood,!1);const st={...p,lean:6,bend:4,rightElbow:0,rightWrist:0},pt={...p,lean:14,bend:12,rightElbow:0,rightWrist:0};_(K,D(st,V,F.y,"arm"),Ii+na),P(K+Ii+na,{lean:-12},void 0,!1);const ht=K+Ii+na+80;P(ht,{...st,rightShoulder:j(st,V,F.y)},void 0,!1);const rt=ht+(x.for??Math.max(Zb,Math.abs(Q-V)/Qb));k.push({time:ht,value:u-c}),u=D(pt,Q,F.y,"arm"),k.push({time:rt,value:u-c}),P(rt,{...pt,rightShoulder:j(pt,Q,F.y)},void 0,!1),P(rt+sa,{lean:16,bend:14,rightShoulder:j(p,Q+z*d*.4,F.y+d*.25)},void 0,!1),P(rt+sa+uu,{lean:0,bend:0,rightShoulder:et.rightShoulder,rightElbow:et.rightElbow}),q=rt+sa+uu,U=ht,Y=rt}else if(x.do==="grab"&&x.target){const F=x.target,z=C(R,F.x,x.mood),K=F.y>f-d*.5,V={...p,turn:1,rightElbow:0,bend:K?35:0,lean:K?12:0,stretch:K?.75:1,lookX:1,lookY:K?.8:0,...Z},tt=_(z,D(V,F.x,F.y,"arm"),hs)+tw;P(tt,{...V,rightShoulder:j(V,F.x,F.y)},x.mood,!1),P(tt+120,{},void 0,!1),P(tt+fu,{bend:0,lean:-3,stretch:1,rightShoulder:165,rightElbow:20,lookY:-.6}),q=tt+fu+150,U=tt}else if(x.do==="throw"){const F=x.target?.x??x.to??u+g*d,z=C(R,F,x.mood),K={...p,turn:1,lean:-12,bend:-10,rightElbow:60,stretch:.95,lookX:1,lookY:-.3,...Z};P(z+ia,{...K,rightShoulder:j(K,u-g*d*.4,f-d*1.05)},x.mood,!1),P(z+ia+pu,{lean:-14},void 0,!1);const V=z+ia+pu+ew,Q={...p,lean:14,bend:12,rightElbow:0,stretch:1.04};S.push({time:V,pose:p={...Q,rightShoulder:j(Q,u+g*d,f-d*1.1)},easing:"ease-in",act:!1}),P(V+oa,{lean:18,bend:14,rightShoulder:55,stretch:1},void 0,!1),P(V+oa+gu,{lean:0,bend:0,rightShoulder:et.rightShoulder,rightElbow:et.rightElbow,lookY:0}),q=V+oa+gu,U=V,Y=V}else if(x.do==="kick"&&x.target){const F=x.target,z=C(R,F.x,x.mood),K={...p,turn:1,lean:-12,bend:-6,rightKnee:0,leftShoulder:100,rightShoulder:70},V=_(z,D(K,F.x,F.y,"leg"),nw),Q={leftShoulder:70,rightShoulder:50,leftElbow:-20,rightElbow:20};P(V+mu,{turn:1,lean:8,bend:6,rightHip:-40,rightKnee:80,lookX:1,lookY:.7,...Q,...Z},x.mood,!1);const tt=V+mu+sw,st=j(K,F.x,F.y,"leg");S.push({time:tt,pose:p={...p,...K,rightHip:st},easing:"ease-in",act:!1}),P(tt+ra,{lean:-15,rightHip:st+20},void 0,!1),P(tt+ra+yu,{lean:0,bend:0,rightHip:et.rightHip,rightKnee:0,leftShoulder:et.leftShoulder,rightShoulder:et.rightShoulder,leftElbow:et.leftElbow,rightElbow:et.rightElbow,lookY:0}),q=tt+ra+yu,U=tt}else if(x.do==="put"&&x.target){const F=x.target,z=C(R,F.x,x.mood),K=F.y>f-d*.5,V={...p,turn:1,rightElbow:0,rightWrist:0,bend:K?35:0,lean:K?12:0,stretch:K?.75:1,lookX:1,lookY:K?.8:0,...Z},tt=_(z,D(V,F.x,F.y,"arm"),hs)+iw;P(tt,{...V,rightShoulder:j(V,F.x,F.y)},x.mood,!1),P(tt+aa,{},void 0,!1),P(tt+aa+bu,{bend:0,lean:0,stretch:1,rightShoulder:et.rightShoulder,rightElbow:et.rightElbow,lookY:0}),q=tt+aa+bu,U=tt}else if(x.do==="write"&&x.target){const F=x.target,z=F.left??F.x,K=F.right??F.x,V=C(R,(z+K)/2,x.mood),Q={...p,turn:1,rightElbow:0,rightWrist:0,...ct.thinking,lookX:1,lookY:0,...Z},tt=gt=>D(Q,gt,F.y,"arm")+g*d*.08,st=gt=>{const X=W({...Q,...B(Q,gt,F.y),rightWrist:0});return Math.hypot(X.x-gt,X.y-F.y)<2},pt=g===1?z:K,ht=_(V,tt((z+K)/2),hs),rt=!st(z)||!st(K),wt=rt?_(ht,tt(z),hs)+wu:ht+wu;P(wt,{...Q,...B(Q,rt?z:pt,F.y)},x.mood,!1);const J=x.for??Math.max(rw,Math.abs(K-z)*ow);rt&&k.push({time:wt,value:u-c});for(let gt=ku,X=0;gt<=J;gt+=ku,X++){const G=z+(K-z)*Math.min(gt,J)/J;rt&&(u=tt(G),k.push({time:wt+gt,value:u-c}));const lt=(X%2===0?-1:1)*d*.02;P(wt+gt,B(Q,G,F.y+lt),void 0,!1)}const kt=wt+J;P(kt,B(Q,K,F.y),void 0,!1),P(kt+vu,{rightShoulder:et.rightShoulder,rightElbow:et.rightElbow,...ct.happy}),q=kt+vu,U=wt,Y=kt}else if(x.do==="push"&&x.target){const F=x.target,z=x.to??F.x,K=C(R,u+(z>=F.x?1:-1),x.mood),V=g===1?F.left??F.x:F.right??F.x,Q={...p,turn:1,lean:16,bend:8,rightWrist:0,leftWrist:0,lookX:1,...Z},tt=D(Q,V,F.y,"arm"),st=_(K,tt+g*d*.06,hs),pt=B(Q,V,F.y),ht={...Q,...pt,leftShoulder:-pt.rightShoulder,leftElbow:-pt.rightElbow},rt=st+aw;P(rt,ht,x.mood,!1);const wt=Math.abs(z-F.x),J=rt+(x.for??Math.max(600,wt/lw)),kt=wt/Uo("shove",d);E.push({time:rt,value:"shove"}),$.push({time:rt,value:0},{time:rt+ie,value:1,easing:"ease-out"},{time:J-ie,value:1},{time:J,value:0,easing:"ease-in"}),M.push({time:rt,value:m},{time:J,value:m+kt}),m+=kt,k.push({time:rt,value:u-c},{time:J,value:u+(z-F.x)-c}),u+=z-F.x,P(J,{},void 0,!1),P(J+Mu,{lean:0,bend:0,rightShoulder:et.rightShoulder,leftShoulder:et.leftShoulder,rightElbow:et.rightElbow,leftElbow:et.leftElbow}),q=J+Mu,U=rt,Y=J}else if(nt){const F=x.mood?ge(p,x.mood):p,z=nt.steps(F,x),K=Gr(z,{at:R,from:F});S.push(...K),p=K[K.length-1].pose,q=R+Math.max(cu(z),x.for??0)}else if(Su(x.do)){const F=Ur(x.do,{at:R,from:x.mood?ge(p,x.mood):p});S.push(...F),p=F[F.length-1].pose,q=R+rs(x.do),x.do==="take"&&v.push({kind:"dust",time:R+900,x:u,y:f,length:500}),x.do==="land"&&v.push({kind:"dust",time:R+120,x:u,y:f,length:500})}else if(x.do==="look"||x.do==="face"){const F=x.toward??"viewer",z=x.for??cw;if(F==="viewer")P(R+se,{turn:0,lookX:0,lookY:0,...Z},x.mood);else if(F==="ahead")P(R+se,{turn:x.do==="face"?1:.6,lookX:1,...Z},x.mood);else if(F==="back")P(R+se,{turn:.2,lookX:-1,...Z},x.mood);else{const K=O(F);K!==g&&x.do==="face"?(H(R,K,x.mood),P(R+bn+1,{lookX:1,...Z})):K!==g?P(R+se,{turn:.25,lookX:-1,...Z},x.mood):P(R+se,{turn:x.do==="face"?1:.6,lookX:1,...Z},x.mood)}q=R+Math.max(z,se)}else if(uw(x.do)||x.do==="stand"){const F=x.do==="stand"?n.rest??et:Dt[x.do],z=F.turn!==et.turn?F.turn:p.turn,K=x.mood?ct[x.mood]:{lookX:p.lookX,lookY:p.lookY};P(R+se,{...F,turn:z,...K,...Z}),q=R+(x.for??la)}else{const F=x.for??(x.say?Tu(x.say):la);(x.mood||x.pose)&&P(R+Math.min(se,F/2),Z,x.mood),q=R+F}if(x.say){const F=r(x.do)||Su(x.do)||nt?R:R+Math.min(150,(q-R)/4),z=r(x.do)?q:Math.max(F+200,q-100);T.push({text:x.say,start:F,end:z}),x.do==="say"&&mw(S,p,F,z)}x.onto!==void 0&&x.do!=="leap"&&x.onto!==f&&(y.push({time:R,value:f-h},{time:q,value:x.onto-h,easing:"ease-in-out"}),f=x.onto),q>S[S.length-1].time&&S.push({time:q,pose:p}),I.push({start:R,end:q,...U!==void 0?{contact:U}:{},...Y!==void 0?{release:Y}:{}}),b=q}const L=Gd(t,gw(S),n),N=[{id:`${t}-x`,target:t,property:"x",keyframes:k},{id:`${t}-y`,target:t,property:"y",keyframes:y},{id:`${t}-walk`,target:t,property:"walk",keyframes:M},{id:`${t}-walking`,target:t,property:"walking",keyframes:$},{id:`${t}-gait`,target:t,property:"gait",keyframes:E},{id:`${t}-facing`,target:t,property:"facing",keyframes:A}].filter(x=>x.keyframes.length>1||x.property==="x"||x.property==="facing"&&x.keyframes[0].value===-1);return{tracks:[...au(t,L,T,{energy:n.energy}),...N],duration:b,lines:T,keys:S,beats:I,effects:v}}const fw=t=>Math.max(-1,Math.min(1,t)),pw=30;function gw(t){const e=[];for(const n of t){const s=e[e.length-1];s&&n.time-s.time<pw?e[e.length-1]={...n,time:s.time}:e.push(n)}return e}function mw(t,e,n,s){const o=t.filter(l=>l.time>n),r=t.filter(l=>l.time<=n),a=[];for(let l=n+520,c=0;l<s-520/2;l+=520,c++){const h=c%2===0?3:-2;a.push({time:l,pose:{...e,headTilt:e.headTilt+h,leftBrow:e.leftBrow+(c%2===0?.25:0),rightBrow:e.rightBrow+(c%2===0?.25:0)}})}a.length>0&&a.push({time:s,pose:e}),t.length=0,t.push(...r,...a.filter(l=>!o.some(c=>Math.abs(c.time-l.time)<60)),...o),t.sort((l,c)=>l.time-c.time)}function ha(t,e,n){const s=new Ht({id:`${t}-hand`,tracks:e.filter(l=>l.target===t)}),i=Qo({x:n.x,y:n.y,style:n.style,cast:n.cast}),o=n.side??"right",r=n.every??33,a=[];for(let l=n.start;;l=Math.min(n.end,l+r)){const{joints:c}=tr(i,{time:l,state:s.getStateAtTime(l)},t),h=c.hands[o],d=c.fingertips[o];if(a.push({time:l,x:(h.x+d.x)/2,y:(h.y+d.y)/2}),l>=n.end)break}return a}const wn=["start","contact","release","end"],yw=["surface","edit","anchor","at","until"],bw=["carry"],Oi=t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&"surface"in t&&"anchor"in t,ww=t=>t.then===void 0?[]:Array.isArray(t.then)?t.then:[t.then];function kw(t,e,n,s={}){const i=Eu(n,e,s).filter(u=>u.level==="error");if(i.length>0)throw new Error(`surfaceScript: ${i.length} problem(s) in the beats:
59
+ ${i.map(u=>` ${u.beat>=0?`beat ${u.beat}: `:""}${u.message}`).join(`
60
+ `)}`);const o=n.map(u=>Au(u,e)),r=ca(t,o,s),a=vw(o,r.beats,s),l=s.ground??0,c=u=>s.ride===!1?u:Object.values(e).reduce((f,g)=>g.ride(f,t,{ground:l}),u);n.forEach((u,f)=>{for(const g of ww(u)){const p=y=>new Error(`surfaceScript: beat ${f} (${u.do}), ${g.edit} on ${g.surface}: ${y}`),m=(y,M)=>{const $=typeof y=="object"?y.beat:f,E=(typeof y=="object"?y.at:y)??M??"start",A=a[$][E];if(A===void 0){const T=wn.filter(I=>a[$][I]!==void 0).join(", ");throw p(`beat ${$} (${n[$].do}) has no ${E} (it has ${T})`)}return A},b=e[g.surface],S=m(g.at??(a[f].contact!==void 0?"contact":"start")),k=g.until===void 0?void 0:m(g.until,"end");if(k!==void 0&&k<S)throw p(`it ends (${k} ms) before it starts (${S} ms)`);try{if(g.edit==="carry"){const M=b.piece(g.anchor),$=ha(t,c(r.tracks),{x:s.from??0,y:l,style:s.figureStyle??(s.height?{height:s.height}:void 0),cast:s,start:S,end:k});b.follow(M,$);continue}const y=Object.fromEntries(Object.entries(g).filter(([M])=>!yw.includes(M)));b.edit(g.edit,g.anchor,{...y,at:S,...k!==void 0?{duration:k-S}:{}})}catch(y){throw p(y.message)}}});const h=c(r.tracks),d=Object.entries(e).flatMap(([u,f])=>f.tracks(u));return{...r,tracks:[...h,...d],figureTracks:h}}function Eu(t,e,n={}){if(!Array.isArray(t))return cs(t,n);const s=[],i=Object.keys(e),o=(c,h,d)=>{const u=typeof h=="string"?e[h]:void 0;return u||s.push({level:"error",beat:c,message:`${d}: ${ot("surface",h,i)}`}),u},r=(c,h,d,u)=>{if(typeof d!="string"){s.push({level:"error",beat:c,message:`${u}: \`anchor\` is a place name such as ${Object.keys(h.about.anchors).join(", ")} (got ${JSON.stringify(d)}).`});return}try{h.anchor(d,0)}catch(f){s.push({level:"error",beat:c,message:`${u}: ${f.message}`})}},a=(c,h,d)=>{const u=typeof h=="object"&&h!==null?h.at:h;if(typeof h=="object"&&h!==null){const f=h.beat;if((typeof f!="number"||!Number.isInteger(f)||f<c||f>=t.length)&&s.push({level:"error",beat:c,message:`${d}: \`beat\` is the index of this beat or a later one, ${c} to ${t.length-1} (got ${JSON.stringify(f)}).`}),u===void 0)return}typeof u=="number"?s.push({level:"error",beat:c,message:`${d}: a cue starts at a moment of its beat (${wn.join(", ")}), not at ms; set the beat's own \`at\` to move it.`}):(typeof u!="string"||!wn.includes(u))&&s.push({level:"error",beat:c,message:`${d}: ${ot("moment",u,wn)}`})};t.forEach((c,h)=>{if(!c||typeof c!="object"||Array.isArray(c))return;const d=c;for(const f of["target","to","onto"]){if(!Oi(d[f]))continue;const g=d[f],p=o(h,g.surface,`\`${f}\``);p&&r(h,p,g.anchor,`\`${f}\``)}if(d.then===void 0)return;(Array.isArray(d.then)?d.then:[d.then]).forEach(f=>{if(!f||typeof f!="object"||Array.isArray(f)){s.push({level:"error",beat:h,message:"`then` is a cue, { surface, edit, anchor, at?, until? }, or a list of them."});return}const g=f,p=o(h,g.surface,"`then`");if(!p)return;const m=`\`then\` (${String(g.edit)} on ${String(g.surface)})`,b=[...Object.keys(p.about.edits),...bw];if(typeof g.edit!="string"||!b.includes(g.edit)){s.push({level:"error",beat:h,message:`\`then\`: ${ot("edit",g.edit,b)}`});return}for(const S of Array.isArray(g.anchor)?g.anchor:[g.anchor])r(h,p,S,m);g.edit==="carry"&&typeof g.anchor!="string"&&s.push({level:"error",beat:h,message:`${m}: \`carry\` takes one anchor, the piece it carries.`}),g.edit==="carry"&&g.until===void 0&&s.push({level:"error",beat:h,message:`${m}: \`carry\` needs \`until\` (when it lets go, such as { beat: ${h+1}, at: 'release' }).`}),g.at!==void 0&&a(h,g.at,`${m} \`at\``),g.until!==void 0&&a(h,g.until,`${m} \`until\``),g.until!==void 0&&g.duration!==void 0&&s.push({level:"error",beat:h,message:`${m}: give \`until\` or \`duration\`, not both.`})})});const l=t.map(c=>c&&typeof c=="object"&&!Array.isArray(c)?Au(c,e,!0):c);return[...cs(l,n),...s]}function Au(t,e,n=!1){const{then:s,...i}=t,o=a=>{try{return e[a.surface].anchor(a.anchor,0)}catch(l){if(n)return{x:0,y:0,left:0,right:0,top:0,bottom:0,width:0,height:0};throw l}},r={...i};return Oi(t.target)&&(r.target=o(t.target)),Oi(t.to)&&(r.to=o(t.to).x),Oi(t.onto)&&(r.onto=o(t.onto).top),r}function vw(t,e,n){let s=0;return t.map(i=>{const o=xi([i],n.actions).length,r=e.slice(s,s+o);s+=o;const a=r.find(c=>c.contact!==void 0)?.contact,l=[...r].reverse().find(c=>c.release!==void 0)?.release;return{start:r[0]?.start,end:r[r.length-1]?.end,...a!==void 0?{contact:a}:{},...l!==void 0?{release:l}:{}}})}function Mw(t){const e={actions:t.actions,gaits:t.gaits},n=Zr(e);if(n.length>0)throw new Error(`persona "${t.name}": ${n.join(" ")}`);const s=[...Object.keys(Ot),...Object.keys(t.gaits??{})],i=t.gait??"walk";if(!s.includes(i))throw new Error(`persona "${t.name}": ${ot("gait",i,s)}`);if(t.mood&&!(t.mood in ct))throw new Error(`persona "${t.name}": ${ot("mood",t.mood,Object.keys(ct))}`);const o=t.acting??"snappy";if(typeof o=="string"&&!(o in je))throw new Error(`persona "${t.name}": ${ot("acting style",o,Object.keys(je))}`);if(typeof t.stance=="string"&&!(t.stance in Dt))throw new Error(`persona "${t.name}": ${ot("stance",t.stance,Object.keys(Dt))}`);const r=t.height??120,a=typeof t.stance=="string"?Dt[t.stance]:Et(t.stance??{}),l=t.mood?ge(a,t.mood):a,c={...t.look,height:r},h=t.summary??`${t.name}, a stick figure`;return{name:t.name,summary:h,cast:e,rest:l,height:r,figure:d=>Qo({x:d.x,y:d.y,pose:l,style:{...c,...d.facing?{facing:d.facing}:{}},cast:e}),script:(d,u,f={})=>ca(d,u,{...e,from:f.from,ground:f.ground,facing:f.facing,height:r,style:o,gait:i,start:l,rest:l,energy:t.energy}),check:d=>cs(d,e),handPath:(d,u,f)=>ha(d,u,{...f,style:c,cast:e}),describe:()=>({name:t.name,summary:h,habits:{height:r,acting:typeof o=="string"?o:"custom",gait:i,...t.mood?{mood:t.mood}:{},stance:typeof t.stance=="string"?t.stance:t.stance?"custom":"rest"},actions:Qr(e),own:{actions:Object.keys(t.actions??{}),gaits:Object.keys(t.gaits??{})}})}}const at=["rect","circle","text","line","path","image","custom"],_i={x:{description:"Moves it right by this much from where it was placed (an offset; the target’s own x is its place)",unit:"px",types:at},y:{description:"Moves it down by this much from where it was placed (an offset)",unit:"px",types:at},opacity:{description:"How opaque it is",unit:"0..1",min:0,max:1,types:at},rotate:{description:"Turns it clockwise about its origin",unit:"degrees",types:at},rotateX:{description:"Tips it about the horizontal axis (3D; shows with perspective)",unit:"degrees",types:at},rotateY:{description:"Turns it about the vertical axis (3D; shows with perspective)",unit:"degrees",types:at},z:{description:"Depth toward the viewer (shows with perspective)",unit:"px",types:at},perspective:{description:"Distance from the viewer: nearer parts grow, further ones shrink",unit:"px",min:1,types:at},scale:{description:"Size, both ways",unit:"factor",types:at},scaleX:{description:"Width factor",unit:"factor",types:at},scaleY:{description:"Height factor",unit:"factor",types:at},skewX:{description:"Slants it sideways",unit:"degrees",types:at},skewY:{description:"Slants it up and down",unit:"degrees",types:at},originX:{description:"Transform pivot across its box",unit:"% (0 left, 50 centre, 100 right)",min:0,max:100,types:at},originY:{description:"Transform pivot down its box",unit:"% (0 top, 50 centre, 100 bottom)",min:0,max:100,types:at},fill:{description:"Fill colour (also written fillStyle)",kind:"color",types:at},stroke:{description:"Outline colour (also written strokeStyle)",kind:"color",types:at},strokeWidth:{description:"Outline width (also written lineWidth)",unit:"px",min:0,types:at},clipTop:{description:"Hides this much from the top edge, for reveals",unit:"% of its height",min:0,max:100,types:at},clipRight:{description:"Hides this much from the right edge",unit:"% of its width",min:0,max:100,types:at},clipBottom:{description:"Hides this much from the bottom edge",unit:"% of its height",min:0,max:100,types:at},clipLeft:{description:"Hides this much from the left edge",unit:"% of its width",min:0,max:100,types:at},blur:{description:"Gaussian blur",unit:"px",min:0,types:at},brightness:{description:"Brightness factor (1 unchanged)",unit:"factor",min:0,types:at},glow:{description:"Soft glow around it, in glowColor",unit:"px",min:0,types:at},glowColor:{description:"Colour of the glow",kind:"color",types:at},shadowX:{description:"Drop shadow offset right",unit:"px",types:at},shadowY:{description:"Drop shadow offset down",unit:"px",types:at},shadowBlur:{description:"Drop shadow softness",unit:"px",min:0,types:at},shadowColor:{description:"Drop shadow colour",kind:"color",types:at},shine:{description:"A highlight sweeping across the fill",unit:"0..1 (progress)",min:0,max:1,types:at},drawOn:{description:"How much of the outline is drawn, for drawing a shape on; the fill appears when it is complete",unit:"0..1",min:0,max:1,types:["rect","circle","line","path"]},width:{description:"Box width",unit:"px",min:0,types:["rect","image"]},height:{description:"Box height",unit:"px",min:0,types:["rect","image"]},borderRadius:{description:"Rounded corners",unit:"px",min:0,types:["rect","image"]},radius:{description:"Circle radius",unit:"px",min:0,types:["circle"]},x2:{description:"Line end, x",unit:"px",types:["line"]},y2:{description:"Line end, y",unit:"px",types:["line"]},d:{description:"SVG path data; tween between paths to morph",kind:"string",types:["path"]},text:{description:"The text shown (a text track types or scrambles it)",kind:"string",types:["text"]},fontSize:{description:"Font size",unit:"px",min:0,types:["text"]},fontWeight:{description:"Font weight",unit:"100..900",min:100,max:900,types:["text"]},motionPath:{description:"Moves it along an SVG path (a motion-path track writes motionPathX/Y and, aligned, rotate)",kind:"string",types:at},quaternion:{description:'A rotation as [x, y, z, w] (a track with interpolation: "slerp")',kind:"list",types:at}},da={fillStyle:"fill",strokeStyle:"stroke",lineWidth:"strokeWidth",rotateZ:"rotate",motionPathX:"x",motionPathY:"y",motionPathRotate:"rotate"},Sw={rotation:"rotate",angle:"rotate",alpha:"opacity",fade:"opacity",color:"fill",colour:"fill",background:"fill",size:"scale",left:"x",top:"y",translateX:"x",translateY:"y",r:"radius",path:"d",content:"text"};function $u(t){const e=t,n=Object.entries(_i).filter(([,i])=>i.types.includes(t.type)).map(([i,{types:o,...r}])=>({name:i,...r,...e[i]!==void 0&&typeof e[i]!="object"?{value:e[i]}:{}}));if(t.type!=="custom")return{type:t.type,properties:n};const s=t.about;for(const[i,o]of Object.entries(t.props??{}))n.push({name:i,description:s?.props?.[i]?.description??"",...s?.props?.[i],value:o});return{type:"custom",...s?{kind:s.kind,summary:s.summary}:{},properties:n,...s?.actions?{actions:s.actions}:{}}}function Pu(t){const e=$u(t).properties.map(n=>n.name);return[...e,...Object.keys(da).filter(n=>e.includes(da[n]))]}function Tw(t,e){const n=[],s=Object.keys(e);for(const i of t){const o=u=>n.push({level:"error",track:i.id,message:u}),r=e[i.target];if(!r){o(ot("target",i.target,s));continue}const a=Pu(r),l=r.type==="custom"&&r.acceptsProp?.(i.property);if(!a.includes(i.property)&&!l){o(`${i.target}: ${ot("property",i.property,a,Sw[i.property])}`);continue}const c=i.keyframes??[];for(let u=1;u<c.length;u++)c[u].time<c[u-1].time&&o(`${i.target}.${i.property}: keyframes out of time order (${c[u-1].time} ms, then ${c[u].time} ms).`);const h=_i[da[i.property]??i.property]??r.about?.props?.[i.property],d=h&&(h.kind??"number")==="number";for(const u of c){if(d&&typeof u.value!="number"){o(`${i.target}.${i.property}: values are numbers${h.unit?` (${h.unit})`:""} (got ${JSON.stringify(u.value)} at ${u.time} ms).`);break}if(d&&typeof u.value=="number"&&(h.min!==void 0&&u.value<h.min||h.max!==void 0&&u.value>h.max)){n.push({level:"warning",track:i.id,message:`${i.target}.${i.property}: ${u.value} at ${u.time} ms is outside ${h.min??"−∞"}..${h.max??"∞"}${h.unit?` (${h.unit})`:""}.`});break}}}return n}const kn=(t,e)=>t[2]<=-e;function ua(t,e,n){const s=(-n-t[2])/(e[2]-t[2]);return[t[0]+(e[0]-t[0])*s,t[1]+(e[1]-t[1])*s,-n]}function xu(t,e){if(t.every(s=>kn(s,e)))return t;const n=[];return t.forEach((s,i)=>{const o=t[(i+t.length-1)%t.length],r=kn(s,e),a=kn(o,e);r!==a&&n.push(ua(o,s,e)),r&&n.push(s)}),n.length>=3?n:[]}function Ew(t,e){if(t.every(i=>kn(i,e)))return[t];const n=[];let s=[];return t.forEach((i,o)=>{const r=kn(i,e);if(o>0){const a=t[o-1],l=kn(a,e);l&&!r?(s.push(ua(a,i,e)),n.push(s),s=[]):!l&&r&&s.push(ua(a,i,e))}r&&s.push(i)}),s.length>0&&n.push(s),n.filter(i=>i.length>=2)}function Iu(t,e,n){const s=e-t;if(!(s>=n*1.5))return[t,e];const i=Math.round(s/n);return Array.from({length:i+1},(o,r)=>t+s*r/i)}function Aw(t,e,n){const s=(i,o)=>Math.max(0,Math.min(i.length-2,i.findIndex((r,a)=>a>0&&o<=r)-1));return[s(t,n[0]),s(e,n[2])]}function $w(t,e){const n=s=>{const i=[e[0]*s[0]+e[4]*s[1]+e[8]*s[2],e[1]*s[0]+e[5]*s[1]+e[9]*s[2],e[2]*s[0]+e[6]*s[1]+e[10]*s[2]],o=Math.hypot(...i)||1;return[i[0]/o,i[1]/o,i[2]/o]};return{...t,vertices:t.vertices.map(s=>Rt(e,s)),faces:t.faces.map(s=>({corners:s.corners,normal:n(s.normal)}))}}function Ci(t,e,n,s){const i=r=>(r[e]-n)*s>=0;if(t.every(i))return t;const o=[];return t.forEach((r,a)=>{const l=t[(a+t.length-1)%t.length];if(i(r)!==i(l)){const c=(n-l[e])/(r[e]-l[e]);o.push([0,1,2].map(h=>h===e?n:l[h]+(r[h]-l[h])*c))}i(r)&&o.push(r)}),o.length>=3?o:[]}function Pw(t,e,n){const s=t.faces.map(r=>({points:r.corners.map(a=>t.vertices[a]),normal:r.normal})),i=[],o={x:e.slice(1,-1),z:n.slice(1,-1)};for(let r=0;r+1<e.length;r++)for(let a=0;a+1<n.length;a++){const l=[],c=new Map,h=g=>{const p=g.map(b=>Math.round(b*1e6)).join(",");let m=c.get(p);return m===void 0&&(m=l.length,l.push(g),c.set(p,m)),m},d=[],u=g=>g===0,f=(g,p)=>g+2===p.length;for(const g of s){let p=g.points;u(r)||(p=Ci(p,0,e[r],1)),p.length&&!f(r,e)&&(p=Ci(p,0,e[r+1],-1)),p.length&&!u(a)&&(p=Ci(p,2,n[a],1)),p.length&&!f(a,n)&&(p=Ci(p,2,n[a+1],-1)),p.length>=3&&d.push({corners:p.map(h),normal:g.normal})}d.length>0&&i.push({cell:[r,a],mesh:{vertices:l,faces:d,creases:t.creases,joined:t.joined,walls:o}})}return i}const xw=new WeakMap,Iw=new WeakMap,Ow=48,Ou=t=>t.map(e=>Math.round(e*1e5)).join(",");function _u(t,e,n,s){let i=t.get(e);i||t.set(e,i=new Map);let o=i.get(n);return o===void 0&&(i.size>=Ow&&i.clear(),i.set(n,o=s())),o}function fa(t,e){const n=Ou(e);return _u(xw,t,n,()=>{const s=$w(t,e),i=[1/0,1/0,1/0],o=[-1/0,-1/0,-1/0];for(const r of s.vertices)for(const a of[0,1,2])i[a]=Math.min(i[a],r[a]),o[a]=Math.max(o[a],r[a]);return{key:n,inSpace:s,low:i,high:o}})}function _w(t,e){const n=t.map(h=>({...h,...fa(h.mesh,h.local)})),s=[1/0,1/0,1/0],i=[-1/0,-1/0,-1/0];for(const h of n)for(const d of[0,1,2])s[d]=Math.min(s[d],h.low[d]),i[d]=Math.max(i[d],h.high[d]);const o=Iu(s[0],i[0],e),r=Iu(s[2],i[2],e),a=`${o.join(",")}|${r.join(",")}`,l=n.flatMap(h=>{if(h.high[0]-h.low[0]<=e*2.5&&h.high[2]-h.low[2]<=e*2.5||h.whole||h.mesh.joined||(h.mesh.marks?.length??0)>0){const u=[(h.low[0]+h.high[0])/2,(h.low[1]+h.high[1])/2,(h.low[2]+h.high[2])/2];return[{part:h.part,mesh:h.mesh,cut:!1,cell:Aw(o,r,u)}]}return _u(Iw,h.inSpace,a,()=>Pw(h.inSpace,o,r)).map(u=>({part:h.part,mesh:u.mesh,cut:!0,cell:u.cell}))}),c=(s[1]+i[1])/2;return{pieces:l,middle:([h,d])=>[(o[h]+o[h+1])/2,c,(r[d]+r[d+1])/2]}}const Cu=.004,pa=.05,Hu=new WeakMap;function Cw(t){let e=Hu.get(t);return e===void 0&&(e=!t.joined&&!t.walls&&t.faces.length>=4&&t.faces.every(n=>{const s=t.vertices[n.corners[0]];return t.vertices.every(i=>n.normal[0]*(i[0]-s[0])+n.normal[1]*(i[1]-s[1])+n.normal[2]*(i[2]-s[2])<=1e-6)}),Hu.set(t,e)),e}const Ru=new WeakMap;function Lu(t){return t.filter(({mesh:e})=>Cw(e)).map(({part:e,key:n,inSpace:s,low:i,high:o})=>{let r=Ru.get(s);return r||(r=s.faces.map(a=>{const l=s.vertices[a.corners[0]];return{normal:a.normal,offset:a.normal[0]*l[0]+a.normal[1]*l[1]+a.normal[2]*l[2]}}),Ru.set(s,r)),{part:e,key:n,planes:r,low:i,high:o}})}function Hw(t,e,n,s){const i=e.reduce((o,r)=>[o[0]+r[0]/e.length,o[1]+r[1]/e.length,o[2]+r[2]/e.length],[0,0,0]);for(const o of s){if(o.part===t||[0,1,2].some(a=>i[a]<o.low[a]-pa||i[a]>o.high[a]+pa))continue;if(o.planes.every(a=>{const l=a.normal[0]*n[0]+a.normal[1]*n[1]+a.normal[2]*n[2],c=e.map(d=>a.normal[0]*d[0]+a.normal[1]*d[1]+a.normal[2]*d[2]-a.offset);if(c.every(d=>Math.abs(d)<=Cu))return l<-.9;const h=Math.abs(l)<.5?pa:Cu;return c.every(d=>d<=h)}))return!0}return!1}const Nu=new WeakMap;function Du(t,e,n,s,i){const o=`${s}|${i.map(l=>l.key).join(";")}`;let r=Nu.get(e);r||Nu.set(e,r=new Map);let a=r.get(o);if(!a){r.size>=48&&r.clear();const l=h=>{const d=[n[0]*h[0]+n[4]*h[1]+n[8]*h[2],n[1]*h[0]+n[5]*h[1]+n[9]*h[2],n[2]*h[0]+n[6]*h[1]+n[10]*h[2]],u=Math.hypot(...d)||1;return[d[0]/u,d[1]/u,d[2]/u]},c=e.vertices.map(h=>Rt(n,h));a=e.faces.map(h=>Hw(t,h.corners.map(d=>c[d]),l(h.normal),i)),r.set(o,a)}return a}const vn={turn:{description:"Which way it faces: 0 toward the viewer, 1 screen-right, 2 away, 3 (or −1) screen-left; in between turns it in 3D",unit:"quarter turns"},tilt:{description:"How far the camera looks down on it: 0 level, 12 the ¾ look, 90 straight down",unit:"degrees",default:12,min:-90,max:90},pitch:{description:"Nose up (+) or down (−), about its middle on the ground",unit:"degrees"},roll:{description:"Tipped onto its right (+) or left (−) side",unit:"degrees"},squash:{description:"Squash and stretch about the ground, keeping its volume: 1 normal, below squashed, above stretched",unit:"factor",default:1,min:.3,max:3},lift:{description:"Off the ground",unit:"metres"},lean:{description:"The top sheared forward (+) or back (−): speed and drag",unit:"shear"},size:{description:"Its size, about the ground: 1 as built, 0 gone (pop it in or out)",unit:"factor",default:1,min:0}},ga=Math.PI/180;function Fu(t,e,n){return{toView:s=>lr(be(s,t*90*ga),-e*ga),toScreen:s=>({x:s[0]*n,y:-s[1]*n})}}const ju=new WeakMap,ds=t=>Hi(t),Hi=t=>{let e=ju.get(t);return e||ju.set(t,e=Td(t)),e};function ft(t,e,n){return e[n]??t.controls[n]?.default??vn[n]?.default??0}function us(t,e){const n=Math.max(.05,ft(t,e,"squash")),s=1/Math.sqrt(n),o=[1,0,0,0,0,1,ft(t,e,"lean"),0,0,0,1,0,0,0,0,1];return[xe([0,ft(t,e,"lift"),0]),zt(Wt([1,0,0],-ft(t,e,"pitch"))),zt(Wt([0,0,1],ft(t,e,"roll"))),o,Ie([s,n,s]),Ie(Array(3).fill(Math.max(0,ft(t,e,"size"))))].reduce((r,a)=>mt(r,a))}function ma(t,e){const n=us(t,e),s=new Map,i=Object.entries(t.controls).flatMap(([r,a])=>(a.bind??[]).map(l=>({value:ft(t,e,r),bind:l}))),o=r=>{const a=s.get(r.id);if(a)return a;const l=r.parent?t.parts.find(h=>h.id===r.parent):void 0;if(r.parent&&!l)throw new Error(`prop rig: part "${r.id}" hangs from "${r.parent}", which is not a part`);let c=mt(l?o(l):n,xe(r.at??[0,0,0]));if(r.rotate){const[h,d,u]=r.rotate;h&&(c=mt(c,zt(Wt([1,0,0],h)))),d&&(c=mt(c,zt(Wt([0,1,0],d)))),u&&(c=mt(c,zt(Wt([0,0,1],u))))}for(const{value:h,bind:d}of i)if(!(!d.parts.includes(r.id)||h===0)){if(d.translate&&(c=mt(c,xe([d.translate[0]*h,d.translate[1]*h,d.translate[2]*h]))),d.rotate){const u=d.rotate.pivot??[0,0,0],f=d.rotate.axis==="x"?[1,0,0]:d.rotate.axis==="y"?[0,1,0]:[0,0,1];c=[c,xe(u),zt(Wt(f,d.rotate.degrees*h)),xe([-u[0],-u[1],-u[2]])].reduce((g,p)=>mt(g,p))}d.scale&&(c=mt(c,Ie([1+(d.scale[0]-1)*h,1+(d.scale[1]-1)*h,1+(d.scale[2]-1)*h])))}return s.set(r.id,c),c};for(const r of t.parts)o(r);return s}const ya=(()=>{const t=[-.45,.75,.5],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),Rw=Math.cos(35*ga);function ba(t,e,n,s,i={}){const o=t.derive?{...e,...t.derive(e)}:e,r=ma(t,o),a=n.toView([0,0,0]),l=O=>C=>[O[0]*C[0]+O[4]*C[1]+O[8]*C[2],O[1]*C[0]+O[5]*C[1]+O[9]*C[2],O[2]*C[0]+O[6]*C[1]+O[10]*C[2]],c=us(t,o),h=i.slice===void 0?null:ko(c),d=h?t.parts.map(O=>({part:O,mesh:Hi(O.shape),local:mt(h,r.get(O.id)),whole:O.shape.type==="tube"})):void 0,u=d?_w(d,i.slice):void 0,f=d?Lu(d.map(O=>({part:O.part.id,mesh:O.mesh,...fa(O.mesh,O.local)}))):void 0,g=(O,C,j,D)=>{const W=X=>n.toView(Rt(j,X)),B=C.vertices.map(W),_=B.map(X=>n.toScreen(X)),L=i.perspective?i.near:void 0,N=X=>X.map(G=>n.toScreen(G)),x=X=>L===void 0?X:xu(X,L),R=X=>L===void 0?[X]:Ew(X,L),q=l(j),U=C.faces.map(X=>{const G=n.toView(q(X.normal)),lt=[G[0]-a[0],G[1]-a[1],G[2]-a[2]],St=Math.hypot(...lt)||1;return[lt[0]/St,lt[1]/St,lt[2]/St]}),Y=f&&D?Du(O.id,C,D,Ou(D),f):void 0,Z=X=>Y?.[X]??!1,nt=U.map((X,G)=>{if(Z(G))return!1;if(!i.perspective)return X[2]>1e-6;const St=C.faces[G].corners.reduce((Ct,At)=>[Ct[0]+B[At][0],Ct[1]+B[At][1],Ct[2]+B[At][2]],[0,0,0]);return-(X[0]*St[0]+X[1]*St[1]+X[2]*St[2])>1e-9}),F=X=>C.faces[X].corners.reduce((G,lt)=>G+B[lt][2],0)/C.faces[X].corners.length,z=C.faces.map((X,G)=>({face:X,i:G})).filter(({i:X})=>nt[X]).map(({face:X,i:G})=>({i:G,solved:{points:L===void 0?X.corners.map(lt=>_[lt]):N(x(X.corners.map(lt=>B[lt]))),depth:F(G),tone:.72+.33*Math.max(0,U[G][0]*ya[0]+U[G][1]*ya[1]+U[G][2]*ya[2])}})).filter(X=>X.solved.points.length>=3).sort((X,G)=>X.solved.depth-G.solved.depth);if(i.light){const X=l(j);for(const{i:G,solved:lt}of z){const St=C.faces[G].corners,Ct=St.reduce((Pa,c2)=>{const xa=Rt(j,C.vertices[c2]);return[Pa[0]+xa[0]/St.length,Pa[1]+xa[1]/St.length,Pa[2]+xa[2]/St.length]},[0,0,0]),At=X(C.faces[G].normal),Ke=Math.hypot(...At)||1,_f=i.light(Ct,[At[0]/Ke,At[1]/Ke,At[2]/Ke]);lt.light=_f.light,lt.fog=_f.fog}}const K=z.map(X=>X.solved),V=Lw(C),Q=[],tt=[];for(const[X,G]of V){const lt=G.filter(Ct=>nt[Ct]).length;if(lt===0)continue;const St=G.length===2&&lt===2&&C.creases!==!1&&U[G[0]][0]*U[G[1]][0]+U[G[0]][1]*U[G[1]][1]+U[G[0]][2]*U[G[1]][2]<Rw;G.length===1&&(C.joined||Nw(C,X))||(G.length===1||lt===1||St)&&(Q.push(X.split("-").map(Number)),tt.push(G.filter(Ct=>nt[Ct]).reduce((Ct,At)=>F(At)>F(Ct)?At:Ct)))}const st=X=>C.faces.findIndex(G=>G.corners.length>4&&Math.sign(Fw(C.vertices[X],G.normal))>0),pt=(C.marks??[]).filter(([X])=>st(X)<0||nt[st(X)]),ht=([X,G])=>L===void 0?[[_[X],_[G]]]:R([B[X],B[G]]).map(N),rt=pt.flatMap(ht),wt=X=>L===void 0?[X.map(G=>_[G])]:R(X.map(G=>B[G])).map(N);if(i.slice!==void 0){const X=new Map;Q.forEach((G,lt)=>X.set(tt[lt],[...X.get(tt[lt])??[],G]));for(const{i:G,solved:lt}of z){lt.edges=Ku(X.get(G)??[]).flatMap(wt);const St=C.faces[G].corners;lt.center=St.reduce((At,Ke)=>[At[0]+B[Ke][0]/St.length,At[1]+B[Ke][1]/St.length,At[2]+B[Ke][2]/St.length],[0,0,0]),lt.normal=U[G];const Ct=z[z.length-1].i;lt.marks=pt.filter(([At])=>(st(At)>=0?st(At):Ct)===G).flatMap(ht)}}const J=O.glow?Math.max(0,Math.min(1,ft(t,o,O.glow.control))):0,kt=O.fade?Math.max(0,Math.min(1,ft(t,o,O.fade.control))):0,gt=O.fade?Math.max(0,Math.min(1,O.fade.from+(O.fade.to-O.fade.from)*kt)):1;return{part:O,depth:B.reduce((X,G)=>X+G[2],0)/Math.max(1,B.length),faces:K,edges:Ku(Q).flatMap(wt),marks:rt,glow:J,opacity:gt,...O.shape.type==="tube"?{spine:Dw(R(O.shape.points.map(W)).map(N))}:{},...C.walls?{cut:!0}:{}}},p=new Map(d?.map(O=>[O.part.id,O.local])),b=(u?u.pieces.map(O=>({part:O.part,mesh:O.mesh,m:O.cut?c:r.get(O.part.id),local:O.cut?_s():p.get(O.part.id),cell:O.cell})):t.parts.map(O=>({part:O,mesh:Hi(O.shape),m:r.get(O.id),local:void 0,cell:void 0}))).map(O=>({cell:O.cell,solved:g(O.part,O.mesh,O.m,O.local)})),S=b.map(O=>O.solved),k=O=>O.filter(C=>C.faces.length>0&&C.opacity>.01).sort((C,j)=>C.depth-j.depth);let y;if(u){const O=new Map(t.parts.map(j=>{const D=r.get(j.id),W=Hi(j.shape).vertices;return[j.id,W.reduce((B,_)=>B+n.toView(Rt(D,_))[2],0)/Math.max(1,W.length)]})),C=new Map;for(const j of b){const D=j.cell.join(",");C.has(D)||C.set(D,{cell:j.cell,parts:[]}),C.get(D).parts.push(j.solved),j.solved.depth=O.get(j.solved.part.id)}y=[...C.values()].map(({cell:j,parts:D})=>({depth:n.toView(Rt(c,u.middle(j)))[2],parts:k(D)})).filter(j=>j.parts.length>0)}const M={};for(const[O,C]of Object.entries(t.anchors??{})){const j=C.part?r.get(C.part):us(t,o);if(!j)throw new Error(`prop rig: anchor "${O}" is on "${C.part}", which is not a part`);const D=n.toView(Rt(j,C.at));M[O]={point:n.toScreen(D),depth:D[2]}}const[$,E]=t.footprint??[t.length*.45,t.length],A=Math.max(0,ft(t,o,"lift")),T=Math.max(0,ft(t,o,"size"))/(1+A*.8),I=Array.from({length:24},(O,C)=>{const j=Math.PI*2*C/24;return n.toView([Math.cos(j)*$*.55*T,0,Math.sin(j)*E*.55*T])}),v=i.perspective?i.near:void 0,P={points:(v===void 0?I:xu(I,v)).map(O=>n.toScreen(O)),opacity:.16*T},H=S.filter(O=>O.part.seeThrough&&O.opacity>.01).flatMap(O=>O.faces.map(C=>C.points));return{under:k(S.filter(O=>!O.part.overRider)),over:k(S.filter(O=>O.part.overRider)),...y?{cells:y}:{},anchors:M,openings:H,shadow:P,pxPerUnit:s,sizePx:t.height*s}}const Bu=new WeakMap;function Lw(t){let e=Bu.get(t);if(!e){e=new Map;for(let n=0;n<t.faces.length;n++){const s=t.faces[n].corners;for(let i=0;i<s.length;i++){const o=s[i],r=s[(i+1)%s.length],a=o<r?`${o}-${r}`:`${r}-${o}`,l=e.get(a);l?l.push(n):e.set(a,[n])}}Bu.set(t,e)}return e}function Wu(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=ma(t,n),i=ko(us(t,n))??_s(),o=r=>Math.max(0,Math.min(1,r));return t.parts.map(r=>{const a=r.fade?o(ft(t,n,r.fade.control)):0;return{part:r,matrix:s.get(r.id),local:mt(i,s.get(r.id)),glow:r.glow?o(ft(t,n,r.glow.control)):0,opacity:r.fade?o(r.fade.from+(r.fade.to-r.fade.from)*a):1}})}function qu(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=ma(t,n),i=us(t,n),o={};for(const[r,a]of Object.entries(t.anchors??{})){const l=a.part?s.get(a.part):i;if(!l)throw new Error(`prop rig: anchor "${r}" is on "${a.part}", which is not a part`);o[r]=Rt(l,a.at)}return o}function Nw(t,e){if(!t.walls)return!1;const[n,s]=e.split("-").map(o=>t.vertices[Number(o)]),i=(o,r)=>r.some(a=>Math.abs(n[o]-a)<1e-6&&Math.abs(s[o]-a)<1e-6);return i(0,t.walls.x)||i(2,t.walls.z)}function Dw(t){return t.reduce((e,n)=>!e||n.length>e.length?n:e,void 0)}const Fw=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2];function Ku(t){const e=t.map(s=>[...s]),n=[];for(;e.length>0;){const s=[...e.shift()];let i=!0;for(;i;){i=!1;for(let o=0;o<e.length;o++){const[r,a]=e[o],l=s[s.length-1],c=s[0];if(r===l)s.push(a);else if(a===l)s.push(r);else if(a===c)s.unshift(r);else if(r===c)s.unshift(a);else continue;e.splice(o,1),i=!0;break}}n.push(s)}return n}function wa(t){const e={};for(const[n,s]of Object.entries({...vn,...t.rig.controls})){const{bind:i,...o}=s;e[n]=o}return e}function jw(t){const{prop:e}=t,n=t.scale??60,s=e.rig.length*n*1.4,i=e.rig.height*n*1.6,o=wa(e),r={};for(const[l,c]of Object.entries(o))r[l]=t.values?.[l]??c.default??0;const a={look:t.look,ink:t.ink,lineWidth:t.lineWidth,pencil:t.pencil,seed:t.seed,style:t.style,paper:t.paper};return{type:"custom",x:t.x-s/2,y:t.y-i,width:s,height:i,props:r,prop:e,propScale:n,propDraw:a,about:{kind:e.kind,summary:e.summary,props:o,actions:Object.fromEntries(Object.entries(e.actions).map(([l,c])=>[l,c.summary]))},draw(l,c,h){const d=c.props??{};l.translate(s/2,i),Sr(l,Mn(e,d,n),{...a,time:h})}}}function Mn(t,e,n){const s=Fu(ft(t.rig,e,"turn"),ft(t.rig,e,"tilt"),n);return ba(t.rig,e,s,n)}function Ri(t,e,n){const s={...t.props};let i=0,o=0;for(const[l,c]of e.state?.values.get(n)??[])typeof c=="number"&&(l==="x"?i=c:l==="y"?o=c:l in s&&(s[l]=c));const r={x:t.x+t.width/2+i,y:t.y+t.height+o},a=Mn(t.prop,s,t.propScale);return{values:s,origin:r,solved:a,anchor(l){const c=a.anchors[l];if(!c)throw new Error(`${t.prop.kind}: no anchor "${l}" (it has ${Object.keys(a.anchors).join(", ")||"none"})`);return{x:r.x+c.point.x,y:r.y+c.point.y,depth:c.depth}}}}function Bw(t,e,n,s,i={}){const o=Ri(e,n,s);return t.save(),t.translate(o.origin.x,o.origin.y),Sr(t,o.solved,{...e.propDraw,time:n.time,rider:i.rider?r=>{r.save(),r.translate(-o.origin.x,-o.origin.y),i.rider(r),r.restore()}:void 0}),t.restore(),o}const Sn={kind:"prop",create:"propSurface(propTarget({ x, y, prop }), { tracks? }): its controls and anchors are those the catalog lists for its preset",anchors:{box:"the prop’s whole box","anchor:NAME":"one of its rig’s anchors (door, seat, branch, ridge…), as posed at the time","part:ID":"one of its parts as seen at the time (window-1, door-left, wheel-0-left…)","control:NAME":"where the parts a control moves or lights are (control:door is the doors, control:lights the lamps)"},edits:{set:"control anchors; { at, value, duration? }: move a control to a value",switch:"control anchors; { at, on?, duration? }: a control to its full value (open, on), or back to its rest value with on: false"}},Ww=400,qw=.2;function Kw(t,e={}){const{prop:n}=t,s=wa(n),i=Object.keys(s),o=Object.keys(n.rig.anchors??{}),r=n.rig.parts.map(m=>m.id),a=ts(),l=es(a),c=e.tracks?.length?new Ht({id:`${n.kind}-surface`,tracks:e.tracks}):void 0,h=Math.max(0,...(e.tracks??[]).flatMap(m=>m.keyframes.map(b=>b.time))),d=m=>{const b={...t.props};let S=0,k=0;if(c){const y=c.getStateAtTime(Math.min(m,h));for(const M of y.values.values())for(const[$,E]of M)typeof E=="number"&&($==="x"?S=E:$==="y"?k=E:$ in b&&(b[$]=E))}for(const y of i)a.keys(y)?.length&&(b[y]=a.valueAt(y,m));return{values:b,origin:{x:t.x+t.width/2+S,y:t.y+t.height+k}}},u=m=>{const{kind:b,rest:S}=De(m),k=y=>ve(n.kind,m,Sn,y);if(b==="box"){if(S)throw k("box takes no arguments");return{kind:b}}if(b==="anchor"){if(!o.includes(S))throw k(ot(`${n.kind} anchor`,S,o));return{kind:b,name:S}}if(b==="part"){if(!r.includes(S))throw k(ot(`${n.kind} part`,S,r));return{kind:b,name:S}}if(b==="control"){if(!i.includes(S))throw k(ot(`${n.kind} control`,S,i));return{kind:b,name:S}}throw k()},f=m=>{const b=(n.rig.controls[m]?.bind??[]).flatMap(k=>k.parts),S=n.rig.parts.filter(k=>k.glow?.control===m).map(k=>k.id);return new Set([...b,...S])},g=(m,b)=>{const S=u(m),{values:k,origin:y}=d(b);if(S.kind==="box")return bt(y.x-t.width/2,y.y-t.height,t.width,t.height);const M=Mn(n,k,t.propScale);if(S.kind==="anchor"){const A=M.anchors[S.name].point,T=qw*t.propScale;return bt(y.x+A.x-T/2,y.y+A.y-T/2,T,T)}if(S.kind==="part")return E(new Set([S.name]),`part "${S.name}" is`);const $=f(S.name);if($.size===0)throw new Error(`${n.kind}: control "${S.name}" moves no parts of its own (it moves the whole ${n.kind}): aim at box`);return E($,`the parts control "${S.name}" moves are`);function E(A,T){const I=[...M.under,...M.over].filter(C=>A.has(C.part.id)).flatMap(C=>C.faces.flatMap(j=>j.points));if(I.length===0){const C=Number.isFinite(b)?`at ${b} ms`:"after its edits";throw new Error(`${n.kind}: ${T} turned away from the viewer ${C}; aim at an anchor (${o.map(j=>`anchor:${j}`).join(", ")||"none"}) or box`)}const v=I.map(C=>C.x),P=I.map(C=>C.y),H=Math.min(...v),O=Math.min(...P);return bt(y.x+H,y.y+O,Math.max(...v)-H,Math.max(...P)-O)}},p={kind:"prop",prop:t,about:Sn,target:t,box:bt(t.x,t.y,t.width,t.height),anchor(m,b=1/0){return g(m,b)},piece(m){throw new Error(`${n.kind}: a prop has no pieces to come loose ("${m}"); change it with edit('set' | 'switch', 'control:NAME', …)`)},edit(m,b,S){if(!(m in Sn.edits))throw ns(n.kind,m,Sn);const k=Array.isArray(b)?b:[b];if(k.length===0)throw new Error(`${n.kind}.edit: ${m} takes at least one control anchor`);for(const y of k){const M=u(y);if(M.kind!=="control")throw new Error(`${n.kind}.edit: ${m} takes control anchors (control:${i.join(", control:")}), not "${y}"`);const $=s[M.name];let E;if(m==="set"){if(typeof S.value!="number"||!Number.isFinite(S.value))throw new Error(`${n.kind}.edit: set needs \`value\`, a number (${M.name}: ${$.description})`);E=S.value}else E=S.on===!1?$.default??$.min??0:$.max??1;a.tween(M.name,d(S.at).values[M.name],E,S,Ww)}return p},follow(m,b){return l.follow(m,b),p},fling(m,b){return l.fling(m,b),p},move(m,b){return l.move(m,b),p},ride(m){return m},tracks:a.tracks};return p}const Yw={body:"#e8574a",trim:"#3b3b44",glass:"#bfe3f2",tyre:"#2c2c33",hub:"#c9ccd3",light:"#fff4b8",tail:"#ff5a4f",inside:"#3b3640",seat:"#6d5d55"};function oe(t){const e={...Yw,...t.colors},n=[],{forwardMost:s,backMost:i,top:o}=Yu(t);t.body&&n.push({id:"body",shape:{type:"extrude",profile:t.body,width:t.width},fill:e.body});for(const[h,d]of(t.frame??[]).entries())n.push({id:`frame-${h}`,shape:{type:"tube",points:d.points,radius:d.radius??.035,segments:6},fill:d.color??e.body,outline:.7});for(const[h,d]of(t.windows??[]).entries())for(const u of[1,-1])n.push({id:`window-${h}-${u>0?"left":"right"}`,shape:{type:"panel",points:[[d.from,d.low],[d.to,d.low],[d.to,d.high],[d.from,d.high]],facing:u>0?"left":"right"},at:[u*(t.width/2+.01),0,0],fill:e.glass,outline:.7,seeThrough:!0,glow:t.lights?{control:"lights",color:"#ffe9a3"}:void 0});for(const h of t.extras??[])n.push(h);if(t.cabin){const h=t.cabin.width??t.width*.85;n.push({id:"cabin",shape:{type:"extrude",profile:t.cabin.profile,width:h},fill:e.glass,outline:.9,seeThrough:!0,layer:1});const d=Math.min(...t.cabin.profile.map(([,f])=>f)),u=Math.max(...t.cabin.profile.map(([,f])=>f));for(const[f,g]of(t.cabin.pillars??[]).entries())n.push({id:`pillar-${f}`,shape:{type:"box",size:[h+.02,u-d,.1]},at:[0,(d+u)/2,g],fill:e.body,outline:.8,layer:1})}const r=t.wheels[0]?.radius??.4,a=[];t.wheels.forEach((h,d)=>{const u=h.side===0?[0]:[1,-1],f=h.thickness??(h.style==="spoked"?.05:.26);for(const g of u){const p=`wheel-${d}-${g>0?"left":g<0?"right":"middle"}`;if(a.push({parts:[p],rotate:{axis:"x",degrees:r/h.radius}}),n.push({id:p,shape:{type:"cylinder",radius:h.radius,length:f,axis:"x",segments:20,spokes:h.style==="spoked"?8:0},at:[g*h.side,h.radius,h.forward],fill:h.style==="spoked"?void 0:e.tyre,ink:h.style==="spoked"?e.tyre:void 0,outline:h.style==="spoked"?1.3:1}),h.style!=="spoked")for(const m of g===0?[1,-1]:[g])n.push({id:`${p}-hub${g===0?m>0?"-left":"-right":""}`,parent:p,shape:{type:"cylinder",radius:h.radius*.55,length:.02,axis:"x",segments:14,spokes:5},at:[m*(f/2+.012),0,0],fill:e.hub,outline:.6})}});const l={wheelSpin:{description:"How far the wheels have turned (keyed exactly with the distance driven, so they never skate)",unit:"degrees",bind:a}};if(t.door){const{from:h,to:d,low:u,high:f}=t.door,g=[[h,u],[d,u],[d,f],[h,f]];for(const p of[1,-1]){const m=p>0?"left":"right";n.push({id:`doorway-${m}`,shape:{type:"panel",points:g,facing:p>0?"left":"right"},at:[p*(t.width/2+.004),0,0],fill:e.inside,outline:.5,seeThrough:!0});const b=h+(d-h)*.15,S=h+(d-h)*.55;n.push({id:`seat-back-${m}`,shape:{type:"panel",points:[[b,u+.05],[S,u+.05],[S-.08,f-.06],[b+.06,f-.04]],facing:p>0?"left":"right"},at:[p*(t.width/2+.006),0,0],fill:e.seat,outline:.4}),n.push({id:`door-${m}`,shape:{type:"panel",points:g.map(([k,y])=>[k-d,y]),facing:p>0?"left":"right"},at:[p*(t.width/2+.01),0,d],fill:e.body,outline:.7,overRider:!0})}l.door={description:"Doors open: 0 shut, 1 open (hinged at the front)",unit:"0..1",min:0,max:1,bind:[{parts:["door-left"],rotate:{axis:"y",degrees:-70}},{parts:["door-right"],rotate:{axis:"y",degrees:70}}]}}if(t.lights){const{across:h,low:d,high:u,front:f,back:g}=t.lights,p=(t.lights.size??.32)/2,m=[[-p,d],[p,d],[p,u],[-p,u]];for(const b of[1,-1])n.push({id:`headlight-${b}`,shape:{type:"panel",points:m,facing:"front"},at:[b*h,0,f],fill:e.light,outline:.6,glow:{control:"lights",color:"#ffffff"}}),n.push({id:`taillight-${b}`,shape:{type:"panel",points:m,facing:"back"},at:[b*h,0,g],fill:gi(e.tail,.62),outline:.6,glow:{control:"lights",color:e.tail}});l.lights={description:"Lights on: 0 off, 1 on",unit:"0..1",min:0,max:1}}t.antenna&&(n.push({id:"antenna",shape:{type:"tube",points:[[0,0,0],[0,.75,0]],radius:.018,segments:5},at:t.antenna,fill:e.trim,outline:.6}),n.push({id:"antenna-tip",parent:"antenna",shape:{type:"ellipsoid",radii:[.05,.05,.05],segments:8},at:[0,.77,0],fill:e.tail,outline:.6}),l.antenna={description:"Antenna bend (follow-through: it trails the motion on a spring)",unit:"degrees",bind:[{parts:["antenna"],rotate:{axis:"x",degrees:1}}]});const c={parts:n,controls:l,length:s-i,height:o,footprint:[t.width,s-i],anchors:{...t.seat?{seat:{at:t.seat}}:{},front:{at:[0,o*.45,s]},back:{at:[0,o*.45,i]},roof:{at:[0,o,0]},...t.door?{door:{at:[-t.width/2,(t.door.low+t.door.high)/2,(t.door.from+t.door.to)/2]}}:{},...t.anchors}};return{kind:t.kind??"vehicle",family:"vehicle",summary:t.summary??"A wheeled vehicle",rig:c,actions:zw(t),acting:zu,colors:{body:e.body,ink:"#26262b"},follow:t.antenna?[{control:"antenna",of:"x",per:.9,stiffness:140,damping:7,limit:35}]:void 0,wheelRadius:r,...t.wheels.length>0?{moves:{drive:{speed:t.speed??6,perMetre:{wheelSpin:180/(Math.PI*r)}}}}:{}}}function Yu(t){const e=[...(t.body??[]).map(([s])=>s),...(t.frame??[]).flatMap(s=>s.points.map(i=>i[2])),...t.wheels.flatMap(s=>[s.forward+s.radius,s.forward-s.radius])],n=[...(t.body??[]).map(([,s])=>s),...(t.cabin?.profile??[]).map(([,s])=>s),...(t.frame??[]).flatMap(s=>s.points.map(i=>i[1])),...t.wheels.map(s=>s.radius*2)];return{forwardMost:Math.max(...e),backMost:Math.min(...e),top:Math.max(...n)}}const zu={depth:{turn:0,lift:0,lights:0,pitch:1,roll:1,squash:1,lean:1,door:2},limits:{turn:.08,pitch:5,roll:4,lean:.1,squash:.06,door:.12,lift:0},eyes:[],headTurns:{},drift:[]};function Li(t,e,n,s,i,o,r=!1){const a=t.facing()||Math.sign(s-t.x)||1,l=t.values.wheelSpin??0,c=(s-t.x)*a/t.scale;t.set("wheelSpin",e,l),t.move(e,n,s,{easing:i}),t.set("wheelSpin",n,r?l:l+c/o*(180/Math.PI),i)}const Xu=.4;function zw(t){const e=t.wheels[0]?.radius??.4,{forwardMost:n,backMost:s}=Yu(t),i=(n-s)/2,o=(a,l,c)=>{const h=a.exaggeration;let d=l;return a.facing()!==c&&(d=a.turnTo(d,c>0?"right":"left")),a.key(d+200,{pitch:4*h,squash:1-.07*h,lean:-.1*h},{act:!1,easing:"ease-out"}),Li(a,d,d+200,a.x-c*.15*h*a.scale,"ease-out",e),a.effect({kind:"exhaust",time:d+150,x:a.x-c*i*a.scale,y:a.floor-.3*a.scale,length:900,direction:-c}),d+260},r=(a,l,c)=>{const h=a.exaggeration*(c?1.8:1);a.key(l,{pitch:-5*h,lean:-.08*h,squash:.95},{act:!1,easing:"ease-out"}),a.key(l+380,{pitch:0,lean:0,squash:1})};return{drive:{summary:"Drives to `to`: rocks back and squats, lunges forward stretched, and stops with a nose-dive that settles; wheels roll exactly the distance.",needs:["to"],uses:["speed","for"],run(a,l,c){const h=Math.sign(l.to-a.x);if(h===0)return{end:c};const d=o(a,c,h),u=a.exaggeration,f=Math.abs(l.to-a.x),g=l.for??Math.max(500,f/(l.speed??Xu));return a.effect({kind:"dust",time:d,x:a.x-h*i*a.scale,y:a.floor,length:600,direction:-h}),a.key(d+140,{pitch:-1.5*u,squash:1+.05*u,lean:.12*u},{act:!1,easing:"ease-out"}),a.key(d+Math.max(160,g-160),{pitch:0,lean:.08*u,squash:1.02},{act:!1}),Li(a,d,d+g,l.to,"ease-in-out",e),r(a,d+g,!1),{end:d+g+380,contact:d,release:d+g}}},brake:{summary:"Drives toward `to` and slams on the brakes: the wheels lock and it skids the last stretch, nose diving, leaving skid marks.",needs:["to"],uses:["speed","for"],run(a,l,c){const h=Math.sign(l.to-a.x);if(h===0)return{end:c};const d=o(a,c,h),u=a.exaggeration,f=a.x,g=Math.abs(l.to-f),p=l.for??Math.max(600,g/(l.speed??Xu*1.2)),m=d+p*.55,b=f+(l.to-f)*.65;return a.key(d+140,{pitch:-1.5*u,squash:1+.06*u,lean:.14*u},{act:!1,easing:"ease-out"}),Li(a,d,m,b,"ease-in",e),a.key(m+80,{pitch:-7*u,lean:-.12*u,squash:.94},{act:!1,easing:"ease-out"}),Li(a,m,d+p,l.to,"ease-out",e,!0),a.effect({kind:"skid",time:m,x:b,toX:l.to,y:a.floor,length:p*.45+1500}),a.effect({kind:"dust",time:d+p,x:l.to+h*i*a.scale,y:a.floor,length:600,direction:h}),r(a,d+p,!0),{end:d+p+380,contact:m,release:d+p}}},bump:{summary:"Hits a bump: squashes, hops up stretched, lands squashed with dust, and springs back.",uses:["for"],run(a,l,c){const h=a.exaggeration;return a.key(c+90,{squash:1-.16*h,pitch:3*h},{act:!1,easing:"ease-out"}),a.key(c+300,{lift:.35*h,squash:1+.12*h,pitch:-3*h},{act:!1,easing:"ease-out"}),a.key(c+540,{lift:0,squash:1-.2*h,pitch:0},{act:!1,easing:"ease-in"}),a.key(c+820,{squash:1}),a.effect({kind:"dust",time:c+540,x:a.x,y:a.floor,length:500}),{end:c+820,contact:c+540}}},honk:{summary:"Honks: a stretch and squash pulse, with honk lines from the front.",run(a,l,c){const h=a.exaggeration;a.key(c+110,{squash:1+.12*h,lean:.04*h},{act:!1,easing:"ease-out"}),a.key(c+240,{squash:1-.06*h,lean:0},{act:!1}),a.key(c+520,{squash:1});const d=a.facing();return a.effect({kind:"honk",time:c+60,x:a.x+(d||1)*i*a.scale,y:a.floor-.7*a.scale,length:700,direction:d||1}),{end:c+520,contact:c+60}}},...t.door?{door:{summary:"Opens the doors (`open: true`) or shuts them (`open: false`).",needs:["open"],run(a,l,c){return a.key(c+450,{door:l.open?1:0}),{end:c+600,contact:c+450}}}}:{},...t.lights?{lights:{summary:"Switches the lights on (`on: true`) or off.",needs:["on"],run(a,l,c){return a.key(c+120,{lights:l.on?1:0},{act:!1}),{end:c+300,contact:c+120}}}}:{}}}function Uu(t={}){return oe({kind:"car",summary:"A cartoon car: drives, brakes, bumps, honks, opens its doors, lights up, and turns toward the camera.",body:[[-2,.32],[2,.32],[2.08,.52],[1.98,.82],[1.05,.95],[-1.72,.98],[-2.02,.86],[-2.08,.5]],width:1.8,cabin:{profile:[[-1.5,.94],[.92,.94],[.3,1.52],[-1.22,1.54]],width:1.56,pillars:[-.42]},wheels:[{forward:1.28,side:.8,radius:.4},{forward:-1.28,side:.8,radius:.4}],door:{from:-.4,to:.88,low:.36,high:.92},lights:{across:.58,low:.55,high:.72,front:2.05,back:-2.06},antenna:t.antenna===!1?void 0:[.5,1.5,-1.05],seat:[0,.3,-.15],colors:t.colors})}function Gu(t={}){return oe({kind:"truck",summary:"A box truck: drives, brakes, bumps, honks, opens its cab doors, lights up, turns toward the camera.",body:[[-3.2,.5],[3.1,.5],[3.15,.95],[3,1.85],[2.3,2.25],[1.2,2.25],[1.2,1],[-3.2,1]],width:2,cabin:{profile:[[1.6,1.35],[2.95,1.35],[2.85,1.85],[2.3,2.15],[1.6,2.15]],width:2.04},extras:[{id:"cargo",shape:{type:"box",size:[2.1,1.75,4.2]},at:[0,1.9,-1.05],fill:t.cargo??"#f1f1ee"}],wheels:[{forward:2.2,side:.85,radius:.48,thickness:.32},{forward:-1.4,side:.85,radius:.48,thickness:.32},{forward:-2.45,side:.85,radius:.48,thickness:.32}],door:{from:1.4,to:2.25,low:.6,high:1.9},lights:{across:.7,low:.62,high:.82,front:3.13,back:-3.22,size:.28},seat:[0,1.15,1.9],colors:{body:"#2f6fb7",...t.colors}})}function Vu(t={}){return oe({kind:"bus",summary:"A bus: drives, brakes, bumps, honks, opens its front doors, lights its windows, turns toward the camera.",body:[[-4.5,.45],[4.5,.45],[4.6,.9],[4.55,2.9],[4.3,3],[-4.4,3],[-4.55,2.75],[-4.55,.6]],width:2.4,windows:Array.from({length:6},(e,n)=>({from:-4+n*1.18,to:-4+n*1.18+1,low:1.55,high:2.6})),extras:[{id:"windscreen",shape:{type:"panel",points:[[-1.05,1.35],[1.05,1.35],[1.05,2.75],[-1.05,2.75]],facing:"front"},at:[0,0,4.58],fill:"#bfe3f2",outline:.8,seeThrough:!0}],wheels:[{forward:3,side:1,radius:.5,thickness:.34},{forward:-2.8,side:1,radius:.5,thickness:.34}],door:{from:3.2,to:4.2,low:.5,high:2.6},lights:{across:.85,low:.65,high:.85,front:4.6,back:-4.56,size:.3},seat:[0,1.2,3.6],colors:{body:"#f2c230",...t.colors}})}function Ju(t={}){return oe({kind:"tractor",summary:"A tractor: big rear wheels and small front ones turning at their own rates; drives, brakes, bumps, honks.",body:[[-.5,.75],[2,.75],[2.12,1.25],[1.9,1.52],[-.5,1.52]],width:1,cabin:{profile:[[-1.35,1],[-.25,1],[-.25,2.55],[-1.35,2.55]],width:1.35},extras:[{id:"roof",shape:{type:"box",size:[1.55,.1,1.35]},at:[0,2.62,-.8],fill:"#3f9b47"},{id:"exhaust",shape:{type:"tube",points:[[.28,1.5,1.25],[.28,2.35,1.25]],radius:.06,segments:6},fill:"#3b3b44",outline:.7}],wheels:[{forward:-.85,side:.85,radius:.78,thickness:.45},{forward:1.55,side:.7,radius:.42,thickness:.26}],lights:{across:.3,low:1,high:1.18,front:2.1,back:-.52,size:.2},seat:[0,1.25,-.8],colors:{body:"#3f9b47",hub:"#e9c64a",...t.colors}})}function Zu(t={}){const e=t.colors?.body??"#a8743f";return oe({kind:"cart",summary:"A wooden cart on spoked wheels with shafts: rolls when pulled (drive), bumps, tips.",body:[[-1.25,.78],[1.25,.78],[1.35,1.18],[-1.35,1.18]],width:1.4,frame:[{points:[[.5,.9,1],[.5,.95,2.7]],radius:.05,color:e},{points:[[-.5,.9,1],[-.5,.95,2.7]],radius:.05,color:e}],wheels:[{forward:0,side:.82,radius:.66,style:"spoked"}],seat:[0,1.2,0],anchors:{shafts:{at:[0,.95,2.7]}},colors:{body:e,tyre:"#5a3a1f",...t.colors}})}function Qu(t={}){return oe({kind:"train carriage",summary:"A railway carriage: rolls along (drive), brakes, lights its windows, turns toward the camera.",body:[[-4,.72],[4,.72],[4,2.8],[3.6,3.12],[-3.6,3.12],[-4,2.8]],width:2.6,windows:Array.from({length:5},(e,n)=>({from:-3.3+n*1.4,to:-3.3+n*1.4+1,low:1.7,high:2.5})),wheels:[{forward:3,side:1,radius:.36,thickness:.16},{forward:2.2,side:1,radius:.36,thickness:.16},{forward:-2.2,side:1,radius:.36,thickness:.16},{forward:-3,side:1,radius:.36,thickness:.16}],lights:{across:.9,low:1,high:1.2,front:4.01,back:-4.01,size:.22},seat:[0,1,1.5],colors:{body:"#2f7d6d",...t.colors}})}function tf(t={}){const e=t.colors?.body??"#e0473b",n=[0,.32,-.05],s=[0,.86,-.22],i=[0,.9,.42],o=[0,.34,.56],r=[0,.34,-.56];return oe({kind:"bike",summary:"A bicycle: rides (drive) with its wire wheels turning, brakes, bumps, rings its bell (honk).",width:.5,frame:[{points:[r,n]},{points:[n,s]},{points:[s,r]},{points:[s,i]},{points:[n,i]},{points:[i,o]},{points:[[.24,.98,.44],[-.24,.98,.44]],radius:.025,color:"#3b3b44"},{points:[i,[0,.98,.44]],radius:.025,color:"#3b3b44"}],extras:[{id:"saddle",shape:{type:"ellipsoid",radii:[.08,.035,.15],segments:10},at:[0,.89,-.22],fill:"#3b3b44",outline:.7}],wheels:[{forward:.56,side:0,radius:.34,style:"spoked"},{forward:-.56,side:0,radius:.34,style:"spoked"}],seat:[0,.9,-.22],colors:{body:e,tyre:"#2c2c33",...t.colors}})}function ef(t={}){return oe({kind:"motorbike",summary:"A motorbike: rides (drive) with a lunge, brakes into a skid, bumps, honks, lights up.",body:[[-.62,.62],[.42,.62],[.55,.95],[.3,1.02],[-.1,.92],[-.8,.88],[-.86,.72]],width:.4,frame:[{points:[[0,.33,.78],[0,1.05,.5]],radius:.04,color:"#8c8f98"},{points:[[.3,1.08,.48],[-.3,1.08,.48]],radius:.025,color:"#3b3b44"},{points:[[.12,.42,-.2],[.12,.5,-.95]],radius:.04,color:"#8c8f98"}],extras:[{id:"engine",shape:{type:"box",size:[.38,.34,.5]},at:[0,.45,.05],fill:"#5b5f6a",outline:.8}],wheels:[{forward:.78,side:0,radius:.33,thickness:.14},{forward:-.72,side:0,radius:.33,thickness:.14}],lights:{across:0,low:.9,high:1.04,front:.62,back:-.87,size:.14},seat:[0,.92,-.3],colors:{body:"#1f1f26",hub:"#c9ccd3",...t.colors}})}function nf(t={}){const e=t.height??2.4,n=t.trunkRadius??.16,s=t.canopy?.radius??1.1,i=t.canopy?.shape==="tall",o={trunk:"#8a5a3b",leaves:"#5cae5a",...t.colors},r=$e(t.canopy?.seed??7),a=[{id:"trunk",shape:{type:"tube",points:[[0,0,0],[.06,e*.5,0],[-.02,e,0]],radius:n,segments:8},fill:o.trunk},{id:"branch",parent:"trunk",shape:{type:"tube",points:[[0,0,0],[.45,.4,.1]],radius:n*.45,segments:6},at:[.04,e*.62,0],fill:o.trunk},{id:"canopy",parent:"trunk",shape:{type:"ellipsoid",radii:[s,s*(i?1.35:.88),s],segments:14},at:[-.02,e+s*.55,0],fill:o.leaves}],l=t.canopy?.lobes??7;for(let h=0;h<l;h++){const d=Math.PI*2*h/l+r.next()*.6,u=(r.next()-.25)*s*(i?1.1:.7),f=s*(.48+r.next()*.22),g=[Math.cos(d)*s*.78,u,Math.sin(d)*s*.6];a.push({id:`lobe-${h}`,parent:"canopy",shape:{type:"ellipsoid",radii:[f,f*.86,f],segments:12},at:g,fill:o.leaves})}const c={parts:a,controls:{sway:{description:"The whole tree bending in the wind, about its base",unit:"degrees",bind:[{parts:["trunk"],rotate:{axis:"z",degrees:1}}]},canopySway:{description:"The canopy bending further than the trunk (it trails the sway)",unit:"degrees",bind:[{parts:["canopy"],rotate:{axis:"z",degrees:1,pivot:[0,-s*.8,0]}}]}},length:s*2.2,height:e+s*2,footprint:[s*1.6,s*1.6],anchors:{canopy:{part:"canopy",at:[0,0,0]},top:{part:"canopy",at:[0,s*.9,0]},base:{at:[0,0,0]},branch:{part:"branch",at:[.45,.4,.1]}}};return{kind:t.kind??"tree",family:"plant",summary:t.summary??"A tree: sways in the wind with its canopy trailing, shakes, sheds leaves, pops up.",rig:c,actions:Xw(),acting:sf,colors:{body:o.leaves}}}const sf={depth:{sway:1,canopySway:2,size:0,squash:1},limits:{sway:2,canopySway:3,squash:.08},eyes:[],headTurns:{},drift:[]};function Xw(){const t=(e,n,s,i)=>{const o=e.anchor("canopy");e.effect({kind:"leaves",time:n,x:o.x,y:o.y,length:s,direction:i,toY:e.floor})};return{sway:{summary:"Sways in gusts of `wind` (0..1, default 0.5) for `for` ms (default 3000); the canopy trails the trunk, and a strong wind sheds leaves.",uses:["wind","for"],run(e,n,s){const i=n.wind??.5,o=n.for??3e3,r=e.exaggeration,a=260;let l=0;for(let c=a;c<o;c+=a){const h=.55+.45*Math.sin(c/o*Math.PI*2.3),d=Math.sin(c/170)*.35,u=-i*9*r*(h+d*i);e.key(s+c,{sway:u,canopySway:l*1.3},{act:!1,easing:"ease-in-out"}),l=u}if(e.key(s+o,{sway:0,canopySway:0}),i>.45)for(let c=0;c<o;c+=700)t(e,s+c,2200,1);return{end:s+o}}},shake:{summary:"Shakes (something hit it): a quick wobble that dies away, shedding leaves.",uses:["for"],run(e,n,s){const i=n.for??900,o=e.exaggeration,r=6;for(let a=1;a<=r;a++){const l=1-a/(r+1),c=a%2===0?1:-1;e.key(s+i*a/(r+1),{sway:c*5*o*l,canopySway:-c*6*o*l},{act:!1,easing:"ease-in-out"})}return e.key(s+i,{sway:0,canopySway:0}),t(e,s+60,1800,1),t(e,s+260,1800,-1),{end:s+i,contact:s}}},shedLeaves:{summary:"Leaves fall from the canopy for `for` ms (default 2000).",uses:["for"],run(e,n,s){const i=n.for??2e3;for(let o=0;o<i;o+=500)t(e,s+o,2e3,o%1e3===0?1:-1);return{end:s+i}}}}}function of(t={}){const e=t.width??4,n=t.depth??3.2,s=t.wallHeight??2.5,i=t.roofHeight??1.5,o=t.overhang??.25,r={walls:"#f1d9a8",roof:"#b8433a",door:"#7a4b2a",doorway:"#3a2a22",glass:"#bfe3f2",lit:"#ffd66b",chimney:"#9b5a45",...t.colors},a=n/2+.01,l=t.door?.width??.9,c=t.door?.height??1.9,h=t.door?.at??0,d=t.windows??[{at:-1.25,low:1,width:.8,height:.8},{at:1.25,low:1,width:.8,height:.8}],u=[{id:"walls",shape:{type:"box",size:[e,s,n]},at:[0,s/2,0],fill:r.walls},{id:"roof",shape:{type:"extrude",profile:[[-n/2-o,s],[n/2+o,s],[0,s+i]],width:e+o*2},fill:r.roof,layer:1},{id:"doorway",shape:{type:"panel",points:[[0,0],[l,0],[l,c],[0,c]],facing:"front"},at:[h-l/2,0,a-.005],fill:r.doorway,outline:.6,seeThrough:!0},{id:"door",shape:{type:"panel",points:[[0,0],[l,0],[l,c],[0,c]],facing:"front"},at:[h-l/2,0,a+.005],fill:r.door,outline:.8,overRider:!0}];d.forEach((p,m)=>{u.push({id:`window-${m}`,shape:{type:"panel",points:[[-p.width/2,p.low],[p.width/2,p.low],[p.width/2,p.low+p.height],[-p.width/2,p.low+p.height]],facing:"front"},at:[p.at,0,a+.01],fill:r.glass,outline:.8,glow:{control:"lights",color:r.lit}})});for(const p of[1,-1])u.push({id:`side-window-${p>0?"left":"right"}`,shape:{type:"panel",points:[[-.4,1],[.4,1],[.4,1.8],[-.4,1.8]],facing:p>0?"left":"right"},at:[p*(e/2+.01),0,0],fill:r.glass,outline:.8,glow:{control:"lights",color:r.lit}});const f=t.chimney===!1?void 0:{at:t.chimney?.at??e*.28,back:t.chimney?.back??-n*.18};if(f){const p=s+i*(1-Math.abs(f.back)/(n/2+o)),m=s+i+.45;u.push({id:"chimney",shape:{type:"box",size:[.42,m-p+.3,.42]},at:[f.at,(m+p-.3)/2,f.back],fill:r.chimney,layer:1})}const g={parts:u,controls:{door:{description:"The front door open: 0 shut, 1 open",unit:"0..1",min:0,max:1,bind:[{parts:["door"],rotate:{axis:"y",degrees:-80}}]},lights:{description:"The windows lit: 0 dark, 1 lit",unit:"0..1",min:0,max:1}},length:n+o*2,height:s+i+.6,footprint:[e+.6,n+.6],anchors:{door:{at:[h,c/2,a]},doorstep:{at:[h,0,a+.4]},ridge:{at:[0,s+i,0]},...f?{chimney:{at:[f.at,s+i+.5,f.back]}}:{}}};return{kind:t.kind??"house",family:"building",summary:t.summary??"A house: opens its door, lights its windows, puffs chimney smoke, shakes, pops up.",rig:g,actions:Uw(!!f),acting:rf,colors:{body:r.walls}}}const rf={depth:{door:1,lights:0,roll:1,squash:1,size:0},limits:{door:.1,roll:1.5,squash:.05},eyes:[],headTurns:{},drift:[]};function Uw(t){return{door:{summary:"Opens the front door (`open: true`) or shuts it (`open: false`).",needs:["open"],run(e,n,s){return e.key(s+500,{door:n.open?1:0}),{end:s+650,contact:s+500}}},lights:{summary:"Lights the windows (`on: true`) or puts them out.",needs:["on"],run(e,n,s){return e.key(s+150,{lights:n.on?1:0},{act:!1}),{end:s+300,contact:s+150}}},shake:{summary:"Shakes, as when a door slams or something lands on it: a squash and a wobble that dies away, with dust.",uses:["for"],run(e,n,s){const i=n.for??700,o=e.exaggeration;e.key(s+80,{squash:1-.06*o},{act:!1,easing:"ease-out"});for(let r=1;r<=5;r++){const a=1-r/6;e.key(s+80+i*r/6,{roll:(r%2===0?1:-1)*2.2*o*a,squash:1+.02*a},{act:!1,easing:"ease-in-out"})}return e.key(s+i+80,{roll:0,squash:1}),e.effect({kind:"dust",time:s+80,x:e.x,y:e.floor,length:600}),{end:s+i+80,contact:s+80}}},...t?{smoke:{summary:"Starts smoke puffing from the chimney for `for` ms (default 3000), drifting with the wind; the next beat starts at once (the smoke carries on).",uses:["for","wind"],run(e,n,s){const i=n.for??3e3,o=e.anchor("chimney");return e.effect({kind:"smoke",time:s,x:o.x,y:o.y,length:i+1500,direction:(n.wind??.4)>=0?1:-1}),{end:s+50,release:s+i}}}}:{}}}function af(t={}){const e={body:"#3f86c8",glass:"#cfeaf5",trim:"#2c2c33",rotor:"#3b3b44",...t.colors},n=2.15,i={parts:[{id:"cabin",shape:{type:"extrude",profile:[[-1.2,.6],[.9,.55],[1.6,.85],[1.65,1.25],[1.2,1.75],[-.6,1.85],[-1.3,1.45]],width:1.5},fill:e.body},{id:"window",shape:{type:"extrude",profile:[[.75,1],[1.6,.95],[1.6,1.3],[1.15,1.72],[.6,1.72]],width:1.54},fill:e.glass,outline:.8},{id:"boom",shape:{type:"tube",points:[[0,1.4,-1.2],[0,1.55,-3.4]],radius:.16,segments:8},fill:e.body},{id:"fin",shape:{type:"extrude",profile:[[-3.55,1.45],[-3.2,1.5],[-3.35,2.25],[-3.6,2.25]],width:.12},fill:e.body},{id:"mast",shape:{type:"tube",points:[[0,1.82,.1],[0,n,.1]],radius:.07,segments:6},fill:e.trim},{id:"rotor-disc",shape:{type:"cylinder",radius:2.4,length:.01,axis:"y",segments:28},at:[0,n+.02,.1],fill:"#c9d4dd",outline:.4,fade:{control:"blur",from:0,to:.45}},{id:"blades",shape:{type:"box",size:[.16,.03,4.8]},at:[0,n+.05,.1],fill:e.rotor,outline:.7,fade:{control:"blur",from:1,to:.3}},{id:"tail-rotor",shape:{type:"box",size:[.04,.9,.12]},at:[.12,1.85,-3.45],fill:e.rotor,outline:.6},{id:"skid-left",shape:{type:"tube",points:[[0,.08,-1.1],[0,.08,1.2],[0,.22,1.45]],radius:.05,segments:6},at:[.7,0,0],fill:e.trim},{id:"skid-right",shape:{type:"tube",points:[[0,.08,-1.1],[0,.08,1.2],[0,.22,1.45]],radius:.05,segments:6},at:[-.7,0,0],fill:e.trim},{id:"strut-left",shape:{type:"tube",points:[[.7,.08,.6],[.55,.62,.5]],radius:.04,segments:5},fill:e.trim},{id:"strut-right",shape:{type:"tube",points:[[-.7,.08,.6],[-.55,.62,.5]],radius:.04,segments:5},fill:e.trim}],controls:{rotor:{description:"How far the rotors have turned (keyed exactly, not acted; the blades blur into a disc when they spin fast)",unit:"degrees",bind:[{parts:["blades"],rotate:{axis:"y",degrees:1}},{parts:["tail-rotor"],rotate:{axis:"x",degrees:3,pivot:[0,0,0]}}]},blur:{description:"How blurred the main rotor is: 0 still blades, 1 a spinning disc",unit:"0..1",min:0,max:1}},length:5.2,height:2.4,footprint:[1.8,3.4],anchors:{seat:{at:[0,.75,.7]},door:{at:[-.76,1,.2]},rotor:{at:[0,n,.1]},skids:{at:[0,0,.2]},hook:{at:[0,.4,0]}}};return{kind:t.kind??"helicopter",family:"aircraft",summary:t.summary??"A cartoon helicopter: spools up and takes off, flies nose-down banking into its moves, hovers with a bob, and lands with a squash.",rig:i,actions:Gw(),acting:ka,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:15,flies:!0,hold:{blur:1},perSecond:{rotor:Te*1e3}}}}}const ka={depth:{turn:0,lift:0,blur:0,pitch:1,roll:1,squash:1,lean:1,size:0},limits:{turn:.08,pitch:6,roll:6,squash:.06,lift:.15},eyes:[],headTurns:{},drift:[]},Te=2.6;function Gw(){const t=(n,s,i,o,r)=>{const a=n.values.rotor??0;n.set("rotor",s,a);const l=r?o*(i-s)*.5:o*(i-s);n.set("rotor",i,a+l,r)},e=n=>n.values.lift>.05;return{takeOff:{summary:"Spools the rotor up (the skids squash as it bites), then lifts off nose-down to `height` metres (default 3).",uses:["height"],run(n,s,i){const o=n.exaggeration,r=s.height??3;t(n,i,i+900,Te,"ease-in"),n.key(i+900,{blur:1},{act:!1,easing:"ease-in"}),n.key(i+700,{squash:1-.08*o},{act:!1,easing:"ease-in"});const a=i+1e3;return n.key(a+150,{squash:1+.06*o,lift:.3},{act:!1,easing:"ease-out"}),n.key(a+1300,{squash:1,lift:r,pitch:-4*o},{act:!1,easing:"ease-in-out"}),n.key(a+1700,{pitch:0}),t(n,i+900,a+1700,Te),n.effect({kind:"dust",time:a,x:n.x,y:n.floor,length:900}),{end:a+1700,contact:a}}},fly:{summary:"Flies to `to` (and to `height`, if given): nose down and banked into the move, nose up and leveling as it stops.",needs:["to"],uses:["height","speed","for"],run(n,s,i){const o=n.exaggeration,r=Math.sign(s.to-n.x);let a=i;r!==0&&n.facing()!==r&&(a=n.turnTo(a,r>0?"right":"left"));const l=Math.abs(s.to-n.x),c=s.for??Math.max(700,l/(s.speed??.3)),h=s.height??n.values.lift;return n.key(a+300,{pitch:-9*o,roll:6*o},{act:!1,easing:"ease-out"}),n.key(a+c-250,{pitch:-4*o,roll:3*o,lift:h},{act:!1}),n.key(a+c,{pitch:7*o,roll:0},{act:!1,easing:"ease-out"}),n.key(a+c+450,{pitch:0}),n.move(a,a+c,s.to,{easing:"ease-in-out"}),t(n,i,a+c+450,Te),{end:a+c+450,contact:a,release:a+c}}},hover:{summary:"Hovers in place for `for` ms (default 2000), bobbing gently.",uses:["for"],run(n,s,i){const o=s.for??2e3,r=n.values.lift,a=n.exaggeration;for(let l=350,c=0;l<o;l+=350,c++)n.key(i+l,{lift:r+(c%2===0?.12:-.06)*a,roll:(c%2===0?1.5:-1.5)*a},{act:!1,easing:"ease-in-out"});return n.key(i+o,{lift:r,roll:0},{act:!1,easing:"ease-in-out"}),(e(n)||r>0)&&t(n,i,i+o,Te),{end:i+o}}},land:{summary:"Settles down onto its skids: a flare, a squash on touchdown with dust, and the rotor spools down.",run(n,s,i){const o=n.exaggeration,r=i+Math.max(900,n.values.lift*450);return n.key(i+400,{pitch:3*o},{act:!1,easing:"ease-out"}),n.key(r,{lift:0,pitch:0,squash:1-.14*o},{act:!1,easing:"ease-in"}),n.key(r+280,{squash:1}),t(n,i,r,Te),t(n,r,r+1600,Te,"ease-out"),n.key(r+1600,{blur:0},{act:!1,easing:"ease-out"}),n.effect({kind:"dust",time:r,x:n.x,y:n.floor,length:800}),{end:r+1600,contact:r}}}}}function lf(t={}){const e={body:"#e9e4d8",wings:"#d9483b",glass:"#cfeaf5",trim:"#2c2c33",...t.colors},n=3.15,i={parts:[{id:"fuselage",shape:{type:"extrude",profile:[[-3.7,1.55],[-2.6,1.05],[2.4,.85],[3,1],[3.1,1.4],[2.7,1.75],[1.4,1.9],[-2.9,1.85]],width:1},fill:e.body},{id:"canopy",shape:{type:"extrude",profile:[[.4,1.85],[1.6,1.85],[1.1,2.3],[.5,2.3]],width:.7},fill:e.glass,outline:.8},{id:"wing-left",shape:{type:"box",size:[3.6,.1,1.35]},at:[2.05,1.15,.55],fill:e.wings},{id:"wing-right",shape:{type:"box",size:[3.6,.1,1.35]},at:[-2.05,1.15,.55],fill:e.wings},{id:"tailplane-left",shape:{type:"box",size:[1.1,.07,.65]},at:[.6,1.7,-3.35],fill:e.wings},{id:"tailplane-right",shape:{type:"box",size:[1.1,.07,.65]},at:[-.6,1.7,-3.35],fill:e.wings},{id:"fin",shape:{type:"extrude",profile:[[-3.75,1.75],[-3,1.82],[-3.45,2.75],[-3.8,2.75]],width:.1},fill:e.wings},{id:"gear-left",shape:{type:"tube",points:[[.55,.95,1.2],[.75,.28,1.3]],radius:.04,segments:5},fill:e.trim},{id:"gear-right",shape:{type:"tube",points:[[-.55,.95,1.2],[-.75,.28,1.3]],radius:.04,segments:5},fill:e.trim},{id:"wheel-left",shape:{type:"cylinder",radius:.26,length:.14,axis:"x",segments:14},at:[.78,.26,1.3],fill:e.trim},{id:"wheel-right",shape:{type:"cylinder",radius:.26,length:.14,axis:"x",segments:14},at:[-.78,.26,1.3],fill:e.trim},{id:"tail-wheel",shape:{type:"cylinder",radius:.12,length:.08,axis:"x",segments:10},at:[0,.12,-3],fill:e.trim},{id:"tail-strut",shape:{type:"tube",points:[[0,.12,-3],[0,1.2,-2.9]],radius:.03,segments:5},fill:e.trim},{id:"spinner",shape:{type:"ellipsoid",radii:[.18,.18,.22],segments:10},at:[0,1.22,n],fill:e.wings,outline:.7},{id:"prop-disc",shape:{type:"cylinder",radius:.95,length:.01,axis:"z",segments:24},at:[0,1.22,n+.08],fill:"#c9d4dd",outline:.4,fade:{control:"blur",from:0,to:.45}},{id:"propeller",shape:{type:"box",size:[.12,1.85,.04]},at:[0,1.22,n+.1],fill:e.trim,outline:.6,fade:{control:"blur",from:1,to:.3}}],controls:{rotor:{description:"How far the propeller has turned (keyed exactly; it blurs into a disc at speed)",unit:"degrees",bind:[{parts:["propeller"],rotate:{axis:"z",degrees:1}}]},blur:{description:"How blurred the propeller is: 0 still, 1 a spinning disc",unit:"0..1",min:0,max:1}},length:7,height:2.8,footprint:[7.2,6.5],anchors:{seat:{at:[0,1.55,1]},nose:{at:[0,1.22,n+.2]},tail:{at:[0,1.6,-3.7]},wingtip:{at:[3.6,1.15,.55]}}};return{kind:t.kind??"airplane",family:"aircraft",summary:t.summary??"A propeller plane: takes off from a run, flies banked, loops the loop, and lands with a flare and a squash.",rig:i,actions:Jw(),acting:ka,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:30,flies:!0,hold:{blur:1},perSecond:{rotor:Te*1e3}}}}}const Vw=3.2;function Jw(){const t=(n,s,i,o)=>{const r=n.values.rotor??0;n.set("rotor",s,r),n.set("rotor",i,r+Vw*(i-s)*(o?.5:1),o)},e=(n,s,i)=>{const o=Math.sign(i-n.x);return o!==0&&n.facing()!==o?n.turnTo(s,o>0?"right":"left"):s};return{takeOff:{summary:"Spins the propeller up, runs along the ground toward `to`, lifts its nose and climbs to `height` metres (default 4).",needs:["to"],uses:["height","for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to);t(n,r,r+700,"ease-in"),n.key(r+700,{blur:1},{act:!1,easing:"ease-in"});const a=s.for??2600,l=n.x,c=r+700+a*.55,h=l+(s.to-l)*.45;return n.move(r+700,c,h,{easing:"ease-in"}),n.key(c,{pitch:8*o,squash:1+.04*o},{act:!1,easing:"ease-out"}),n.key(r+700+a,{lift:s.height??4,pitch:10*o,squash:1},{act:!1,easing:"ease-in-out"}),n.move(c,r+700+a,s.to),n.key(r+700+a+500,{pitch:0}),t(n,r+700,r+700+a+500),n.effect({kind:"dust",time:c,x:h,y:n.floor,length:700}),{end:r+700+a+500,contact:c}}},fly:{summary:"Flies to `to` (and `height`), banking into the move and leveling out.",needs:["to"],uses:["height","speed","for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to),a=s.for??Math.max(800,Math.abs(s.to-n.x)/(s.speed??.45)),l=s.height??n.values.lift;return n.key(r+350,{roll:10*o,pitch:l>n.values.lift?6*o:-3*o},{act:!1,easing:"ease-out"}),n.key(r+a-300,{roll:4*o,lift:l},{act:!1}),n.key(r+a,{roll:0,pitch:0}),n.move(r,r+a,s.to,{easing:"ease-in-out"}),t(n,i,r+a),{end:r+a,contact:r,release:r+a}}},loop:{summary:"Loops the loop: pulls up and over in a full circle (`for` ms, default 2400), carrying on the way it was going.",uses:["for"],run(n,s,i){const o=s.for??2400,r=2.2*n.exaggeration,a=n.facing()||1,l=16,c=n.x,h=n.values.lift,d=n.values.pitch;for(let u=1;u<=l;u++){const f=Math.PI*2*u/l,g=i+o*u/l;n.key(g,{lift:h+r*(1-Math.cos(f)),pitch:d+360*u/l},{act:!1}),n.move(i+o*(u-1)/l,g,c+a*(r*Math.sin(f)+u/l*r*1.2)*n.scale)}return n.key(i+o+1,{pitch:d},{act:!1}),t(n,i,i+o),{end:i+o+1}}},land:{summary:"Comes down toward `to`: descends, flares nose-up, touches down with a squash and dust, rolls to a stop and the propeller spools down.",needs:["to"],uses:["for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to),a=n.x,l=s.for??2200,c=r+l,h=a+(s.to-a)*.7;return n.key(r+l*.4,{pitch:-4*o},{act:!1,easing:"ease-out"}),n.key(c-250,{pitch:6*o,lift:.15},{act:!1,easing:"ease-in-out"}),n.key(c,{lift:0,pitch:0,squash:1-.12*o},{act:!1,easing:"ease-in"}),n.key(c+260,{squash:1}),n.move(r,c,h),n.move(c,c+1200,s.to,{easing:"ease-out"}),t(n,i,c),t(n,c,c+1600,"ease-out"),n.key(c+1600,{blur:0},{act:!1,easing:"ease-out"}),n.effect({kind:"dust",time:c,x:h,y:n.floor,length:700}),{end:c+1600,contact:c}}}}}const Tn=["walk","trot","canter","gallop"],Zw=Tn,cf=["fl","fr","hl","hr"],Ni={walk:{offsets:{hl:0,fl:.25,hr:.5,fr:.75},swing:16,lift:45,bob:.02,rock:0,cycle:1100},trot:{offsets:{fl:0,hr:0,fr:.5,hl:.5},swing:22,lift:75,bob:.05,rock:0,cycle:640},canter:{offsets:{hr:0,hl:.33,fr:.33,fl:.66},swing:30,lift:70,bob:.08,rock:5,cycle:560},gallop:{offsets:{hr:0,hl:.1,fr:.5,fl:.6},swing:40,lift:80,bob:.1,rock:7,cycle:460}},qe=Math.PI/180;function Di(t,e){return 4*t*Math.sin(Ni[e].swing*qe)}function fs(t){const{legs:e,colors:n}=t,s=e.upper+e.lower+e.foot,i=s+t.body.rise,o=(d,u)=>[u*d[0],d[1],d[2]],r=[{id:"body",shape:{type:"ellipsoid",radii:t.body.radii,segments:18},at:[0,i,0],fill:n.coat},{id:"neck",shape:{type:"tube",points:t.neck.points,radius:t.neck.points.map((d,u,f)=>t.neck.radius*(1.25-.4*u/Math.max(1,f.length-1))),segments:12},at:t.neck.at,fill:n.coat},{id:"head",parent:"neck",shape:{type:"ellipsoid",radii:t.head.radii,segments:14},at:t.head.at,rotate:t.head.rotate,fill:n.coat},...tk(t,n,i)];t.mane&&r.push({id:"mane",parent:"neck",shape:{type:"tube",points:t.mane.points,radius:t.mane.radius,segments:6},fill:n.dark,outline:.7}),t.muzzle&&r.push({id:"muzzle",parent:"head",shape:{type:"ellipsoid",radii:t.muzzle.radii,segments:10},at:t.muzzle.at,fill:n.muzzle,outline:.8});for(const d of[1,-1]){const u=d>0?"left":"right",f=t.ears.rotate?o(t.ears.rotate,1).map((g,p)=>p===2?d*g:g):void 0;r.push({id:`ear-${u}`,parent:"head",shape:{type:"ellipsoid",radii:t.ears.radii,segments:8},at:o(t.ears.at,d),rotate:f,fill:n.coat,outline:.7},{id:`eye-${u}`,parent:"head",shape:{type:"ellipsoid",radii:[t.eyes.size*.8,t.eyes.size,t.eyes.size*.9],segments:8},at:o(t.eyes.at,d),fill:"#1d1d22",outline:.4})}r.push(...t.extras?.(n)??[]);const a={walk:{description:"Phase of the stride, in full cycles (keyed in step with the distance covered)",unit:"cycles"},walking:{description:"How much of the gait is applied: 0 standing, 1 moving",unit:"0..1",min:0,max:1},gait:{description:`Which gait: ${t.gaits.map(d=>`${Tn.indexOf(d)} ${d}`).join(", ")}`,unit:"index",min:0,max:3},neck:{description:"Neck bent down (+, eating, sniffing) or up (−, alert)",unit:"degrees",bind:[{parts:["neck"],rotate:{axis:"x",degrees:1}}]},tail:{description:"Tail flicked up and back (+), curling along its length, on a spring behind the motion",unit:"degrees",bind:[{parts:Ut,rotate:{axis:"x",degrees:1/Ut.length}}]},wag:{description:"Tail swung side to side, curling",unit:"degrees",bind:[{parts:Ut,rotate:{axis:"y",degrees:1/Ut.length}}]}};for(const d of cf){const u=d[0]==="f",f=d[1]==="l"?1:-1,g=u?e.thickness[0]:e.thickness[1];r.push({id:`${d}-upper`,shape:{type:"tube",points:[[0,e.upper*.2,0],[0,-e.upper*.5,0],[0,-e.upper,0]],radius:[g,g*.85,e.lowerThickness*1.15],segments:10},at:[f*e.across,s,u?e.front:e.hind],fill:n.coat},{id:`${d}-knee`,parent:`${d}-upper`,shape:{type:"ellipsoid",radii:Array(3).fill(e.lowerThickness*1.08),segments:10},at:[0,-e.upper,0],fill:n.coat,solidOnly:!0},{id:`${d}-lower`,parent:`${d}-upper`,shape:{type:"tube",points:[[0,0,0],[0,-e.lower,0]],radius:[e.lowerThickness*1.1,e.lowerThickness*.85],segments:10},at:[0,-e.upper,0],fill:n.coat},{id:`${d}-foot`,parent:`${d}-lower`,shape:{type:"ellipsoid",radii:[e.footSize[0]/2,e.foot/2+.004,e.footSize[1]/2],segments:12},at:[0,-e.lower-e.foot/2,e.footSize[1]*.12],fill:n.foot,outline:.8});const p=`${u?"Front":"Hind"} ${f>0?"left":"right"} leg`;a[`${d}.swing`]={description:`${p}: forward (+) or back (−) from the hip`,unit:"degrees",bind:[{parts:[`${d}-upper`],rotate:{axis:"x",degrees:-1}}]},a[`${d}.knee`]={description:`${p}: knee (hock) folded`,unit:"degrees",bind:[{parts:[`${d}-lower`],rotate:{axis:"x",degrees:u?1:-1}}]},a[`${d}.ankle`]={description:`${p}: foot turned at the ankle (+ toe forward)`,unit:"degrees",bind:[{parts:[`${d}-foot`],rotate:{axis:"x",degrees:-1,pivot:[0,e.foot/2,-e.footSize[1]*.12]}}]}}const l=t.neck.points[t.neck.points.length-1],c={parts:r,controls:a,length:t.body.radii[2]*2+Math.max(0,t.neck.at[2]+l[2]+t.head.radii[2]-t.body.radii[2])+.3,height:t.neck.at[1]+l[1]+t.head.radii[1]*2,footprint:[e.across*2+t.body.radii[0],(e.front-e.hind)*1.4],anchors:{back:{at:[0,i+t.body.radii[1],-t.body.radii[2]*.05]},head:{part:"head",at:[0,0,0]},mouth:{part:t.muzzle?"muzzle":"head",at:t.muzzle?[0,0,t.muzzle.radii[2]]:[0,0,t.head.radii[2]]},front:{at:[0,i,t.body.radii[2]]},...t.anchors},derive:d=>ek(d,t,s)},h={legLength:s,upper:e.upper,lower:e.lower,foot:e.foot,tailHangs:t.tail.points[t.tail.points.length-1][1]<0,front:e.front,hind:e.hind,call(d,u){const f=d.anchor("mouth");d.effect({kind:"honk",time:u,x:f.x,y:f.y,length:800,direction:d.facing()||1})}};return{kind:t.kind,family:"animal",summary:t.summary,rig:c,actions:{...sk(t,h),...t.actions?.(h)},acting:va,colors:{body:n.coat,ink:"#26262b"},follow:[{control:"tail",of:"x",per:.6,stiffness:90,damping:6,limit:40}],moves:Qw(t,s)}}function Qw(t,e){const n=i=>{const o=Di(e,i);return{speed:o/(Ni[i].cycle*(t.cycleScale??1)/1e3),set:{gait:Tn.indexOf(i)},hold:{walking:1},perMetre:{walk:1/o}}},s=Object.fromEntries(t.gaits.map(i=>[i==="gallop"&&!t.gaits.includes("canter")?"run":i,n(i)]));return t.gaits.includes("gallop")&&!s.gallop&&(s.gallop=n("gallop")),s}const Ut=Array.from({length:7},(t,e)=>e===0?"tail":`tail-${e}`);function tk(t,e,n){const s=_r(t.tail.points,Ut.length+1),[,i,o]=t.body.radii,r=(t.tail.at[1]-n)/i,a=Math.abs(r)<1?-o*Math.sqrt(1-r*r):t.tail.at[2],l=[t.tail.at[0],t.tail.at[1],a+Math.min(.04,o*.08)],c=f=>t.tail.radius*(1-.5*f/Ut.length),h=Ut.map((f,g)=>{const p=s[g],m=s[g+1],b=[m[0]-p[0],m[1]-p[1],m[2]-p[2]],S=g===0?void 0:s[g-1];return{id:f,...g>0?{parent:Ut[g-1]}:{},shape:{type:"tube",points:[[0,0,0],b],radius:[c(g),c(g+1)],segments:8,joined:!0},at:g===0?l:[p[0]-S[0],p[1]-S[1],p[2]-S[2]],fill:e.dark,outline:.8}}),d=s[s.length-1],u=s[s.length-2];return h.push({id:"tail-tip",parent:Ut[Ut.length-1],shape:{type:"ellipsoid",radii:Array(3).fill(c(Ut.length)*1.05),segments:8},at:[d[0]-u[0],d[1]-u[1],d[2]-u[2]],fill:e.dark,outline:.8,solidOnly:!0}),h}function ek(t,e,n){const s=Math.max(0,Math.min(1,t.walking??0));if(s===0)return{};const i=Tn[Math.max(0,Math.min(3,Math.round(t.gait??0)))],o=Ni[e.gaits.includes(i)?i:e.gaits[0]],r=t.walk??0,a={};for(const c of cf){const h=Math.PI*2*(r+o.offsets[c]);a[`${c}.swing`]=(t[`${c}.swing`]??0)+s*o.swing*Math.sin(h),a[`${c}.knee`]=(t[`${c}.knee`]??0)+s*o.lift*Math.max(0,Math.cos(h))}const l=Math.PI*2*r;return a.lift=(t.lift??0)+s*o.bob*n*Math.abs(Math.sin(l*2)),a.pitch=(t.pitch??0)+s*o.rock*Math.sin(l),a.neck=(t.neck??0)+s*(o.rock>0?-o.rock*1.4:5)*Math.sin(l*2),a}function hf(t){const n=Math.sin(32*qe),s=t.legLength-(t.front-t.hind)*n,i=72,r=(s-t.upper*Math.cos(i*qe)-t.foot)/t.lower,a=r>=1?0:r<=-1?180:Math.acos(r)/qe,l={pitch:32,lift:t.legLength*(1-Math.cos(32*qe))-t.front*n,neck:-10,tail:t.tailHangs?35:-40,"fl.swing":-32,"fr.swing":-32};for(const c of["hl","hr"])l[`${c}.swing`]=i-32,l[`${c}.knee`]=-(i+a),l[`${c}.ankle`]=a;return l}const va={depth:{turn:0,lift:0,pitch:1,roll:1,squash:1,neck:2,tail:3,wag:3,"fl.swing":2,"fr.swing":2,"hl.swing":2,"hr.swing":2,"fl.knee":3,"fr.knee":3,"hl.knee":3,"hr.knee":3},limits:{pitch:6,neck:8,tail:10,wag:8,"fl.swing":8,"fr.swing":8,"hl.swing":8,"hr.swing":8,lift:0},eyes:[],headTurns:{},drift:[]},nk=va;function sk(t,e){const n=t.cycleScale??1,s=r=>({summary:{walk:"Walks to `to` (four beats), its head bobbing.",trot:"Trots to `to`: legs in diagonal pairs, the body bouncing.",canter:"Canters to `to`: three beats, the body rocking.",gallop:"Gallops (runs) to `to`: legs reaching, the body rocking hard, kicking up dust."}[r],needs:["to"],uses:["for"],run(a,l,c){const h=Math.sign(l.to-a.x);if(h===0)return{end:c};let d=c;a.facing()!==h&&(d=a.turnTo(d,h>0?"right":"left"));const u=a.exaggeration;a.key(d+180,{neck:-12*u},{act:!1,easing:"ease-out"});const g=Math.abs(l.to-a.x)/a.scale/Di(e.legLength,r),p=l.for??Math.max(500,g*Ni[r].cycle*n),m=a.values.walk??0;return a.set("gait",d,a.values.gait??0),a.set("gait",d+1,Tn.indexOf(r)),a.set("walking",d,0),a.set("walking",d+240,1,"ease-out"),a.set("walking",d+p-240,1),a.set("walking",d+p,0,"ease-in"),a.set("walk",d,m),a.move(d,d+p,l.to,{easing:"ease-in-out"}),a.set("walk",d+p,m+g,"ease-in-out"),a.key(d+p+300,{neck:0}),(r==="gallop"||r==="canter")&&(a.effect({kind:"dust",time:d+200,x:a.x-h*e.legLength*a.scale,y:a.floor,length:700,direction:-h}),a.effect({kind:"dust",time:d+p,x:l.to+h*e.legLength*.6*a.scale,y:a.floor,length:600,direction:h})),{end:d+p+300,contact:d,release:d+p}}}),i=Object.fromEntries(t.gaits.map(r=>[r==="gallop"&&!t.gaits.includes("canter")?"run":r,s(r)]));t.gaits.includes("gallop")&&!i.gallop&&(i.gallop=s("gallop"));const o={...i,[t.call]:{summary:`Throws its head up and ${t.call}s.`,run(r,a,l){const c=r.exaggeration;return r.key(l+150,{neck:10*c},{act:!1,easing:"ease-out"}),r.key(l+380,{neck:-28*c,squash:1.05},{act:!1,easing:"ease-out"}),r.key(l+680,{neck:-20*c},{act:!1}),r.key(l+980,{neck:0,squash:1}),e.call(r,l+380),{end:l+980,contact:l+380}}},sit:{summary:"Sits on its haunches for `for` ms (default 1500): the rump goes down onto folded hind legs, paws flat on the ground, the front legs stay planted; then it gets up.",uses:["for"],run(r,a,l){const c=hf(e),h=l+450;r.key(h,c,{act:!1,easing:"ease-in-out"}),r.key(h+(a.for??1500),c,{act:!1});const d=h+(a.for??1500)+450,u={};for(const f of Object.keys(c))u[f]=0;return r.key(d,u),{end:d,contact:h,release:d-450}}},jump:{summary:"Crouches and jumps (forward to `to`, or up on the spot), legs tucked in the air, landing with a squash and dust.",uses:["to"],run(r,a,l){const c=r.exaggeration,h=e.legLength*.8*c,d=l+260,u=d+90,f=u+520;if(r.key(d,{squash:.86,"hl.knee":40,"hr.knee":40,"fl.knee":25,"fr.knee":25,neck:8},{act:!1,easing:"ease-out"}),r.key(u,{squash:1.12,"hl.knee":0,"hr.knee":0,"fl.knee":0,"fr.knee":0,pitch:8,"fl.swing":35,"fr.swing":35,"hl.swing":-35,"hr.swing":-35},{act:!1,easing:"ease-out"}),r.key((u+f)/2,{lift:h,squash:1,pitch:0,"fl.knee":60,"fr.knee":60,"hl.knee":60,"hr.knee":60,"fl.swing":25,"fr.swing":25,"hl.swing":-20,"hr.swing":-20},{act:!1,easing:"ease-out"}),r.key(f,{lift:0,squash:.85,pitch:-4,"fl.knee":0,"fr.knee":0,"hl.knee":0,"hr.knee":0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0},{act:!1,easing:"ease-in"}),r.key(f+280,{squash:1,pitch:0,neck:0}),a.to!==void 0){const g=Math.sign(a.to-r.x);g!==0&&r.facing()!==g&&r.turnTo(l,g>0?"right":"left"),r.move(u,f,a.to)}return r.effect({kind:"dust",time:f,x:r.x,y:r.floor,length:550}),{end:f+280,contact:f}}},nod:{summary:"Nods its head twice.",run(r,a,l){return r.key(l+200,{neck:20},{act:!1,easing:"ease-out"}),r.key(l+400,{neck:-5},{act:!1,easing:"ease-in-out"}),r.key(l+600,{neck:18},{act:!1,easing:"ease-in-out"}),r.key(l+900,{neck:0}),{end:l+900}}},swish:{summary:"Swishes its tail a few times.",uses:["for"],run(r,a,l){const c=a.for??900;for(let h=1;h<=4;h++)r.key(l+c*h/5,{tail:h%2===0?10:35},{act:!1,easing:"ease-in-out"});return r.key(l+c,{tail:0}),{end:l+c}}}};return t.grazes&&(o.graze={summary:"Lowers its head to graze for `for` ms (default 1800), nibbling, then looks up.",uses:["for"],run(r,a,l){const c=a.for??1800;r.key(l+600,{neck:75},{act:!1,easing:"ease-in-out"});for(let h=900;h<600+c;h+=400)r.key(l+h,{neck:h%800===100?70:78},{act:!1,easing:"ease-in-out"});return r.key(l+600+c+500,{neck:0}),{end:l+600+c+500}}}),o}function df(t={}){return fs({kind:t.kind??"horse",summary:t.summary??"A cartoon horse: walks, trots, canters and gallops with its hooves in step with the ground, rears, bucks, neighs, grazes and swishes its tail.",legs:{upper:.5,lower:.42,foot:.08,footSize:[.12,.16],front:.62,hind:-.62,across:.2,thickness:[.075,.09],lowerThickness:.05},body:{radii:[.32,.36,.95],rise:.25},neck:{at:[0,1.42,.7],points:[[0,0,0],[0,.5,.3]],radius:.15},head:{at:[0,.48,.5],radii:[.13,.14,.3],rotate:[38,0,0]},muzzle:{at:[0,-.02,.24],radii:[.11,.1,.1]},ears:{at:[.07,.16,-.17],radii:[.035,.1,.05]},eyes:{at:[.115,.05,-.04],size:.04},tail:{at:[0,1.4,-.9],points:[[0,0,0],[0,-.22,-.2],[0,-.62,-.24]],radius:.08},mane:{points:[[0,.1,-.12],[0,.55,.17]],radius:.07},colors:{coat:"#b5763a",dark:"#4a2e1a",foot:"#3a2a22",muzzle:"#8d5a2c",accent:"#e8c9a0",...t.colors},gaits:["walk","trot","canter","gallop"],call:"neigh",grazes:!0,anchors:{hitch:{at:[0,.95,-.15]},saddle:{at:[0,1.6,-.05]}},actions:e=>({rear:{summary:"Rears up on its hind legs, front legs tucked and pawing, neighs, and drops back down with dust.",uses:["for"],run(n,s,i){const o=n.exaggeration,r=Math.min(55,32*o),a=-e.hind*Math.sin(r*qe),l=s.for??700;n.key(i+200,{pitch:-4,neck:6,"hl.knee":12,"hr.knee":12},{act:!1,easing:"ease-out"}),n.key(i+520,{pitch:r,lift:a,neck:-25,"fl.swing":55,"fl.knee":95,"fr.swing":40,"fr.knee":80,"hl.knee":0,"hr.knee":0},{act:!1,easing:"ease-out"}),n.key(i+520+l*.5,{"fl.swing":35,"fl.knee":70,"fr.swing":58,"fr.knee":100},{act:!1,easing:"ease-in-out"}),n.key(i+520+l,{"fl.swing":55,"fl.knee":95,"fr.swing":40,"fr.knee":80},{act:!1,easing:"ease-in-out"});const c=i+520+l+380;return n.key(c,{pitch:0,lift:0,neck:8,squash:.94,"fl.swing":0,"fl.knee":0,"fr.swing":0,"fr.knee":0},{act:!1,easing:"ease-in"}),n.key(c+320,{neck:0,squash:1}),e.call(n,i+520),n.effect({kind:"dust",time:c,x:n.x+(n.facing()||1)*e.front*n.scale,y:n.floor,length:600}),{end:c+320,contact:c}}},buck:{summary:"Bucks: drops its head and kicks both hind legs up and back.",run(n,s,i){const o=n.exaggeration,r=Math.min(35,18*o),a=e.front*Math.sin(r*qe);return n.key(i+220,{pitch:3,squash:.95},{act:!1,easing:"ease-out"}),n.key(i+480,{pitch:-r,lift:a,neck:30,"hl.swing":-65,"hr.swing":-60,"hl.knee":10,"hr.knee":10},{act:!1,easing:"ease-out"}),n.key(i+900,{pitch:0,lift:0,neck:0,squash:.95,"hl.swing":0,"hr.swing":0,"hl.knee":0,"hr.knee":0},{act:!1,easing:"ease-in"}),n.key(i+1150,{squash:1}),n.effect({kind:"dust",time:i+900,x:n.x-(n.facing()||1)*.6*n.scale,y:n.floor,length:600}),{end:i+1150,contact:i+480}}}})})}function uf(t={}){return fs({kind:t.kind??"dog",summary:t.summary??"A cartoon dog: walks, trots and runs, barks, wags its tail, sits, jumps, sniffs the ground.",legs:{upper:.19,lower:.16,foot:.05,footSize:[.07,.1],front:.24,hind:-.24,across:.09,thickness:[.04,.05],lowerThickness:.032},body:{radii:[.14,.15,.36],rise:.1},neck:{at:[0,.56,.27],points:[[0,0,0],[0,.14,.06]],radius:.075},head:{at:[0,.15,.08],radii:[.12,.11,.13]},muzzle:{at:[0,-.03,.13],radii:[.065,.055,.08]},ears:{at:[.11,0,-.02],radii:[.025,.09,.05],rotate:[0,0,18]},eyes:{at:[.08,.04,.08],size:.025},tail:{at:[0,.58,-.34],points:[[0,0,0],[0,.1,-.08],[0,.2,-.1]],radius:.03},extras:e=>[{id:"nose",parent:"muzzle",shape:{type:"ellipsoid",radii:[.025,.02,.02],segments:8},at:[0,.03,.08],fill:"#1d1d22",outline:.4},{id:"patch",parent:"body",shape:{type:"ellipsoid",radii:[.012,.09,.11],segments:10},at:[.135,.04,-.06],fill:e.accent,outline:.5}],colors:{coat:"#d9a066",dark:"#a8703a",foot:"#a8703a",muzzle:"#f0d2a8",accent:"#f6ead8",...t.colors},gaits:["walk","trot","gallop"],cycleScale:.55,call:"bark",anchors:{leash:{part:"neck",at:[0,.06,0]}},actions:()=>({wag:{summary:"Wags its tail fast for `for` ms (default 1200).",uses:["for"],run(e,n,s){const i=n.for??1200;for(let o=80,r=0;o<i;o+=80,r++)e.key(s+o,{wag:r%2===0?35:-35,tail:25},{act:!1,easing:"ease-in-out"});return e.key(s+i,{wag:0,tail:0}),{end:s+i}}},sniff:{summary:"Puts its nose to the ground and sniffs (`for` ms, default 1400).",uses:["for"],run(e,n,s){const i=n.for??1400;e.key(s+350,{neck:70,pitch:-6},{act:!1,easing:"ease-in-out"});for(let o=500,r=0;o<i;o+=140,r++)e.key(s+o,{neck:r%2===0?74:66},{act:!1});return e.key(s+i+300,{neck:0,pitch:0}),{end:s+i+300}}}})})}function ff(t={}){return fs({kind:t.kind??"cat",summary:t.summary??"A cartoon cat: walks, trots and runs, meows, arches its back, pounces, sits and swishes its tail.",legs:{upper:.13,lower:.11,foot:.035,footSize:[.05,.07],front:.17,hind:-.18,across:.06,thickness:[.028,.035],lowerThickness:.022},body:{radii:[.1,.105,.27],rise:.07},neck:{at:[0,.39,.2],points:[[0,0,0],[0,.08,.04]],radius:.05},head:{at:[0,.1,.05],radii:[.095,.085,.085]},muzzle:{at:[0,-.03,.07],radii:[.04,.03,.03]},ears:{at:[.055,.085,-.01],radii:[.03,.055,.02],rotate:[0,0,-12]},eyes:{at:[.045,.02,.07],size:.022},tail:{at:[0,.42,-.26],points:[[0,0,0],[0,.08,-.12],[0,.24,-.16],[0,.34,-.1]],radius:.022},extras:()=>[{id:"nose",parent:"muzzle",shape:{type:"ellipsoid",radii:[.014,.01,.01],segments:8},at:[0,.015,.03],fill:"#e48a9a",outline:.4}],colors:{coat:"#8f8a86",dark:"#5f5a57",foot:"#f2efe9",muzzle:"#f2efe9",accent:"#f2efe9",...t.colors},gaits:["walk","trot","gallop"],cycleScale:.5,call:"meow",actions:e=>({arch:{summary:"Arches its back, fur up and tail high, for `for` ms (default 1200): a startled cat.",uses:["for"],run(n,s,i){const o=n.exaggeration,r=s.for??1200,a={squash:1+.25*o,neck:25,tail:-45,"fl.swing":-8,"fr.swing":-8,"hl.swing":8,"hr.swing":8};return n.key(i+180,a,{act:!1,easing:"ease-out"}),n.key(i+180+r,a,{act:!1}),n.key(i+r+520,{squash:1,neck:0,tail:0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0}),{end:i+r+520,contact:i+180}}},pounce:{summary:"Crouches low, wiggles, and pounces to `to`, landing with a squash.",needs:["to"],run(n,s,i){const o=n.exaggeration,r=Math.sign(s.to-n.x);let a=i;r!==0&&n.facing()!==r&&(a=n.turnTo(a,r>0?"right":"left"));const l={squash:.75,"hl.knee":60,"hr.knee":60,"fl.knee":45,"fr.knee":45,neck:10,tail:-15};n.key(a+300,l,{act:!1,easing:"ease-out"});for(let d=1;d<=4;d++)n.key(a+300+d*110,{roll:d%2===0?3:-3},{act:!1});const c=a+300+550,h=c+480;return n.key(c,{roll:0,squash:1.2,"hl.knee":0,"hr.knee":0,"fl.knee":0,"fr.knee":0,"fl.swing":45,"fr.swing":45,"hl.swing":-45,"hr.swing":-45,tail:20},{act:!1,easing:"ease-out"}),n.key((c+h)/2,{lift:e.legLength*.9*o,squash:1.1,pitch:-6},{act:!1,easing:"ease-out"}),n.key(h,{lift:0,squash:.8,pitch:0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0,neck:0,tail:0},{act:!1,easing:"ease-in"}),n.key(h+260,{squash:1}),n.move(c,h,s.to),n.effect({kind:"dust",time:h,x:s.to,y:n.floor,length:450}),{end:h+260,contact:h}}}})})}function pf(t={}){return fs({kind:t.kind??"cow",summary:t.summary??"A cartoon cow: walks and trots, moos, grazes, sits and swishes its tail.",legs:{upper:.42,lower:.36,foot:.08,footSize:[.13,.15],front:.68,hind:-.66,across:.24,thickness:[.085,.1],lowerThickness:.06},body:{radii:[.4,.42,1],rise:.32},neck:{at:[0,1.3,.85],points:[[0,0,0],[0,.22,.25]],radius:.19},head:{at:[0,.18,.4],radii:[.17,.19,.27],rotate:[30,0,0]},muzzle:{at:[0,-.06,.22],radii:[.15,.11,.1]},ears:{at:[.17,.06,-.12],radii:[.11,.035,.05],rotate:[0,0,-15]},eyes:{at:[.13,.06,.02],size:.04},tail:{at:[0,1.48,-1],points:[[0,0,0],[0,-.25,-.12],[0,-.7,-.14]],radius:.035},extras:e=>[{id:"horn-left",parent:"head",shape:{type:"tube",points:[[0,0,0],[.08,.12,.02]],radius:.025,segments:6},at:[.1,.16,-.14],fill:"#efe6d2",outline:.6},{id:"horn-right",parent:"head",shape:{type:"tube",points:[[0,0,0],[-.08,.12,.02]],radius:.025,segments:6},at:[-.1,.16,-.14],fill:"#efe6d2",outline:.6},{id:"udder",shape:{type:"ellipsoid",radii:[.16,.12,.18],segments:10},at:[0,.98,-.45],fill:"#f0a6b6",outline:.6},{id:"spot-1",parent:"body",shape:{type:"ellipsoid",radii:[.02,.2,.26],segments:10},at:[.39,.06,.2],fill:e.accent,outline:.4},{id:"spot-2",parent:"body",shape:{type:"ellipsoid",radii:[.02,.16,.22],segments:10},at:[-.39,.1,-.35],fill:e.accent,outline:.4},{id:"spot-3",parent:"body",shape:{type:"ellipsoid",radii:[.2,.02,.24],segments:10},at:[0,.41,-.2],fill:e.accent,outline:.4}],colors:{coat:"#f4f1ea",dark:"#2e2b2a",foot:"#3a3330",muzzle:"#f0b8c4",accent:"#2e2b2a",...t.colors},gaits:["walk","trot"],cycleScale:1.15,call:"moo",grazes:!0})}function ik(t){return Di(1,t)}const Ee=.6,gf=75,Ma=80;function Fi(t){const{colors:e}=t,[n,s,i]=t.body.radii,o=(t.tail.raised??15)*Math.PI/180,r=t.tail.length*.4,a=[{id:"body",shape:{type:"ellipsoid",radii:t.body.radii,segments:16},at:[0,t.body.height,0],fill:e.body},{id:"neck",shape:{type:"ellipsoid",radii:[n*.55,s*.55,i*.3],segments:10},at:[0,t.body.height+s*.45,i*.65],fill:e.body,outline:.5,solidOnly:!0},{id:"head",parent:"neck",shape:{type:"ellipsoid",radii:[t.head.radius,t.head.radius*1.02,t.head.radius*1.05],segments:14},at:[t.head.at[0],t.head.at[1]-(t.body.height+s*.45),t.head.at[2]-i*.65],fill:e.body},{id:"beak",parent:"head",shape:{type:"tube",points:[[0,0,0],[0,-t.beak.thickness*.4,t.beak.length]],radius:[t.beak.thickness,t.beak.thickness*.08],segments:8},at:[0,-t.head.radius*.1,t.head.radius*.8],fill:e.beak,outline:.8},{id:"tail",shape:{type:"ellipsoid",radii:[t.tail.width/2,.012*(i/.08),t.tail.length/2],segments:10},at:[t.tail.at[0],t.tail.at[1]+r*Math.sin(o),t.tail.at[2]-r*Math.cos(o)],rotate:[t.tail.raised??15,0,0],fill:e.wing,outline:.8}];if(e.belly&&a.push({id:"belly",parent:"body",shape:{type:"ellipsoid",radii:[n*.82,s*.7,i*.75],segments:12},at:[0,-s*.25,i*.12],fill:e.belly,outline:.4}),t.comb){const h=t.head.radius;a.push({id:"comb",parent:"head",shape:{type:"extrude",profile:[[-h*.5,h*.6],[h*.6,h*.6],[h*.5,h*1.3],[h*.15,h*1.05],[-h*.05,h*1.4],[-h*.3,h*1.05],[-h*.6,h*1.25]],width:h*.25},fill:e.comb??"#d9372e",outline:.7},{id:"wattle",parent:"head",shape:{type:"ellipsoid",radii:[h*.15,h*.35,h*.2],segments:8},at:[0,-h*.7,h*.6],fill:e.comb??"#d9372e",outline:.6})}for(const h of[1,-1]){const d=h>0?"left":"right",u=t.head.radius;a.push({id:`eye-${d}`,parent:"head",shape:{type:"ellipsoid",radii:[u*.16,u*.2,u*.18],segments:8},at:[h*u*.72,u*.18,u*.42],fill:"#1d1d22",outline:.3}),a.push({id:`wing-${d}`,shape:{type:"ellipsoid",radii:[.004,.004,.004],segments:4},at:[h*t.wing.shoulder[0],t.wing.shoulder[1],t.wing.shoulder[2]],rotate:[-8,h*90,0],outline:0}),a.push({id:`wing-${d}-blade`,parent:`wing-${d}`,shape:{type:"ellipsoid",radii:[t.wing.span*Ee/2,t.wing.chord*.1,t.wing.chord/2],segments:12},at:[h*t.wing.span*Ee/2,0,-t.wing.chord*.1],rotate:[-Ma,0,0],fill:e.wing,outline:.8}),a.push({id:`wing-${d}-tip`,parent:`wing-${d}-blade`,shape:{type:"ellipsoid",radii:[t.wing.span*Ee/2.4,t.wing.chord*.06,t.wing.chord*.3],segments:10},at:[h*t.wing.span*Ee/4,0,-t.wing.chord*.3],rotate:[0,h*14,0],fill:e.wing,outline:.8}),a.push({id:`leg-${d}`,shape:{type:"tube",points:[[0,0,0],[0,-t.legs.length,0]],radius:Math.max(.004,t.legs.length*.05),segments:5},at:[h*t.legs.across,t.legs.length,0],fill:e.legs,outline:.6}),a.push({id:`toes-${d}`,parent:`leg-${d}`,shape:{type:"tube",points:[[0,0,-t.legs.length*.15],[0,0,t.legs.length*.35]],radius:Math.max(.003,t.legs.length*.04),segments:5},at:[0,-t.legs.length,0],fill:e.legs,outline:.6})}const l={spread:{description:"Wings: 0 folded back along the body, 1 spread out",unit:"0..1",min:0,max:1,bind:[{parts:["wing-left"],rotate:{axis:"y",degrees:-90}},{parts:["wing-right"],rotate:{axis:"y",degrees:90}},{parts:["wing-left-blade"],translate:[t.wing.span*(1-Ee)/2,0,0],rotate:{axis:"x",degrees:Ma},scale:[1/Ee,1,1]},{parts:["wing-right-blade"],translate:[-t.wing.span*(1-Ee)/2,0,0],rotate:{axis:"x",degrees:Ma},scale:[1/Ee,1,1]}]},flap:{description:"Wings raised (+) or lowered (−) at the shoulders",unit:"degrees",bind:[{parts:["wing-left"],rotate:{axis:"z",degrees:1}},{parts:["wing-right"],rotate:{axis:"z",degrees:-1}}]},wingbeat:{description:"Phase of the wingbeat, in beats (keyed steadily while flapping)",unit:"beats"},flapping:{description:"How hard the wings beat: 0 still, 1 full beats",unit:"0..1",min:0,max:1},peck:{description:"Head bobbed down and forward (+, pecking) or up (−)",unit:"degrees",bind:[{parts:["neck"],rotate:{axis:"x",degrees:1},translate:[0,-(t.neckReach??0)/gf,0]}]},step:{description:"Phase of a walk, in steps (a chicken’s legs)",unit:"steps"},stepping:{description:"How much of the walk is applied",unit:"0..1",min:0,max:1},"leg.left":{description:"Left leg swung forward (+)",unit:"degrees",bind:[{parts:["leg-left"],rotate:{axis:"x",degrees:-1}}]},"leg.right":{description:"Right leg swung forward (+)",unit:"degrees",bind:[{parts:["leg-right"],rotate:{axis:"x",degrees:-1}}]}},c={parts:a,controls:l,length:i*2+t.tail.length+t.beak.length,height:t.head.at[1]+t.head.radius,footprint:[n*2.2,i*2.4],anchors:{beak:{part:"beak",at:[0,0,t.beak.length]},head:{part:"head",at:[0,0,0]},back:{at:[0,t.body.height+s,0]},feet:{at:[0,0,0]}},derive:h=>{const d={},u=Math.max(0,Math.min(1,h.flapping??0));u>0&&(d.flap=(h.flap??0)+u*48*Math.sin(Math.PI*2*(h.wingbeat??0)));const f=Math.max(0,Math.min(1,h.stepping??0));if(f>0){const g=Math.sin(Math.PI*2*(h.step??0));d["leg.left"]=(h["leg.left"]??0)+f*28*g,d["leg.right"]=(h["leg.right"]??0)-f*28*g,d.peck=(h.peck??0)+f*12*Math.sin(Math.PI*4*(h.step??0))}return d}};return{kind:t.kind,family:"bird",summary:t.summary,rig:c,actions:rk(t),acting:mf,colors:{body:e.body,ink:"#26262b"},moves:ok(t)}}function ok(t){const e=t.legs.length*1.2,n={walk:{speed:e/.42,hold:{stepping:1},perMetre:{step:.5/e}}};return t.flies!==!1&&(n.fly={speed:4+t.wing.span*12,flies:!0,hold:{flapping:1,spread:1},perSecond:{wingbeat:t.beatsPerSecond??4}}),n}const mf={depth:{turn:0,lift:0,pitch:1,roll:1,squash:1,spread:1,flap:2,peck:2},limits:{pitch:6,roll:6,squash:.06,peck:8,flap:10,lift:0},eyes:[],headTurns:{},drift:[]};function rk(t){const e=(t.beatsPerSecond??4)/1e3,n=(r,a,l)=>{const c=r.values.wingbeat??0;r.set("wingbeat",a,c),r.set("wingbeat",l,c+(l-a)*e)},s=(r,a,l)=>{const c=Math.sign(l-r.x);return c!==0&&r.facing()!==c?r.turnTo(a,c>0?"right":"left"):a},i=(r,a)=>{const l=r.anchor("beak");r.effect({kind:"honk",time:a,x:l.x,y:l.y,length:600,direction:r.facing()||1})},o={hop:{summary:"Hops to `to` in little bounces, wings twitching.",needs:["to"],run(r,a,l){const c=s(r,l,a.to),h=r.x,d=Math.abs(a.to-h),u=Math.max(1,Math.round(d/(t.body.radii[2]*3*r.scale))),f=260;for(let g=0;g<u;g++){const p=c+g*f;r.key(p+60,{squash:.85},{act:!1,easing:"ease-out"}),r.key(p+150,{squash:1.1,lift:t.legs.length*1.4,spread:.15},{act:!1,easing:"ease-out"}),r.key(p+f,{squash:.9,lift:0,spread:0},{act:!1,easing:"ease-in"}),r.move(p+60,p+f,h+(a.to-h)*(g+1)/u,{easing:"ease-in-out"})}return r.key(c+u*f+120,{squash:1}),{end:c+u*f+120}}},walk:{summary:"Walks to `to` on its two legs, its head bobbing with each step.",needs:["to"],uses:["for"],run(r,a,l){const c=s(r,l,a.to),h=Math.abs(a.to-r.x)/r.scale,d=t.legs.length*1.2,u=h/d,f=a.for??Math.max(400,u*420),g=r.values.step??0;return r.set("stepping",c,0),r.set("stepping",c+150,1,"ease-out"),r.set("stepping",c+f-150,1),r.set("stepping",c+f,0,"ease-in"),r.set("step",c,g),r.move(c,c+f,a.to,{easing:"ease-in-out"}),r.set("step",c+f,g+u/2,"ease-in-out"),{end:c+f,contact:c,release:c+f}}},peck:{summary:"Pecks at the ground (`for` ms, default 900): quick jabs of the head.",uses:["for"],run(r,a,l){const c=a.for??900,h=Math.max(1,Math.round(c/300));r.key(l+120,{pitch:-(t.stoop??12)},{act:!1,easing:"ease-out"});for(let d=0;d<h;d++)r.key(l+120+d*300+90,{peck:gf},{act:!1,easing:"ease-in"}),r.key(l+120+d*300+260,{peck:20},{act:!1,easing:"ease-out"});return r.key(l+120+h*300+200,{peck:0,pitch:0}),{end:l+120+h*300+200,contact:l+210}}},flap:{summary:"Flaps its wings on the spot (`for` ms, default 900), lifting a little.",uses:["for"],run(r,a,l){const c=a.for??900;return r.key(l+120,{spread:1},{act:!1,easing:"ease-out"}),r.set("flapping",l,0),r.set("flapping",l+150,1,"ease-out"),r.set("flapping",l+c-150,1),r.set("flapping",l+c,0,"ease-in"),n(r,l,l+c),r.key(l+c*.5,{lift:t.legs.length*.6},{act:!1,easing:"ease-out"}),r.key(l+c,{lift:0,spread:0},{act:!1,easing:"ease-in"}),{end:l+c+80}}},[t.call]:{summary:`${t.call[0].toUpperCase()}${t.call.slice(1)}s: its head comes up and its beak opens to call.`,run(r,a,l){return r.key(l+120,{peck:-25,squash:1.06},{act:!1,easing:"ease-out"}),r.key(l+500,{peck:-20},{act:!1}),r.key(l+760,{peck:0,squash:1}),i(r,l+150),{end:l+760,contact:l+150}}}};return t.flies!==!1?(o.fly={summary:"Takes off (a crouch and a leap, wings beating) and flies to `to` at `height` metres (default 2); `land` brings it down.",needs:["to"],uses:["height","for"],run(r,a,l){const c=r.exaggeration,h=s(r,l,a.to),d=a.height??2,u=a.for??Math.max(700,Math.abs(a.to-r.x)/.35),f=r.values.lift>t.legs.length,g=f?h:h+200;return f||(r.key(h+160,{squash:1-.18*c,spread:.6},{act:!1,easing:"ease-out"}),r.effect({kind:"dust",time:g,x:r.x,y:r.floor,length:400})),r.key(g+100,{spread:1,squash:1.08,pitch:10},{act:!1,easing:"ease-out"}),r.set("flapping",g,r.values.flapping??0),r.set("flapping",g+100,1,"ease-out"),r.set("flapping",g+u,.6),n(r,g,g+u),r.key(g+u*.4,{lift:d,pitch:-5,squash:1},{act:!1,easing:"ease-out"}),r.key(g+u,{lift:d,pitch:0},{act:!1,easing:"ease-in-out"}),r.move(g,g+u,a.to,{easing:"ease-in-out"}),{end:g+u,contact:g,release:g+u}}},o.land={summary:"Comes down to the floor it is over (or to `height` metres above it, a branch or a roof): wings braking, a squash on touchdown.",uses:["height","to"],run(r,a,l){const h=a.height??0;return r.set("flapping",l,r.values.flapping??1),r.set("flapping",l+700-120,1),r.set("flapping",l+700,0,"ease-in"),n(r,l,l+700),r.key(l+700*.6,{pitch:14},{act:!1,easing:"ease-out"}),r.key(l+700,{lift:h,pitch:0,squash:.85},{act:!1,easing:"ease-in"}),a.to!==void 0&&r.move(l,l+700,a.to,{easing:"ease-out"}),r.key(l+700+160,{squash:1,spread:0}),{end:l+700+200,contact:l+700}}}):o.flutter={summary:"Flutters up a little way and back down, wings beating hard (a chicken’s flight).",run(r,a,l){return r.key(l+100,{spread:1,squash:.9},{act:!1,easing:"ease-out"}),r.set("flapping",l+80,0),r.set("flapping",l+160,1,"ease-out"),r.set("flapping",l+900-100,1),r.set("flapping",l+900,0,"ease-in"),n(r,l+80,l+900),r.key(l+900*.5,{lift:t.legs.length*2.5,squash:1.08},{act:!1,easing:"ease-out"}),r.key(l+900,{lift:0,squash:.85,spread:0},{act:!1,easing:"ease-in"}),r.key(l+900+160,{squash:1}),{end:l+900+160,contact:l+900}}},o}function yf(t={}){return Fi({kind:"songbird",summary:"A small songbird: hops, pecks, tweets, flaps, flies and lands (on the ground, a branch or a roof).",body:{radii:[.05,.05,.075],height:.085},head:{at:[0,.145,.065],radius:.036},beak:{length:.03,thickness:.01},wing:{shoulder:[.04,.1,.03],span:.11,chord:.06},tail:{at:[0,.095,-.07],length:.07,width:.045},legs:{length:.04,across:.018},colors:{body:"#7b6a58",wing:"#5c4c3d",beak:"#e7a43a",legs:"#c47a35",belly:"#e9c8a3",...t.colors},call:"tweet",beatsPerSecond:9})}function bf(t={}){return Fi({kind:"crow",summary:"A crow: walks and hops, pecks, caws, flaps, flies and lands (on the ground, a branch or a roof).",body:{radii:[.09,.09,.17],height:.2},head:{at:[0,.32,.15],radius:.065},beak:{length:.08,thickness:.022},wing:{shoulder:[.07,.24,.06],span:.32,chord:.14},tail:{at:[0,.2,-.15],length:.16,width:.09},legs:{length:.1,across:.035},colors:{body:"#2b2b33",wing:"#1e1e25",beak:"#3b3b44",legs:"#3b3b44",...t.colors},call:"caw",beatsPerSecond:4})}function wf(t={}){return Fi({kind:"chicken",summary:"A chicken: walks with a bobbing head, pecks, clucks, and flutters up and down (it cannot really fly).",body:{radii:[.13,.14,.19],height:.3},head:{at:[0,.5,.16],radius:.07},beak:{length:.05,thickness:.02},wing:{shoulder:[.11,.34,.04],span:.24,chord:.15},tail:{at:[0,.38,-.15],length:.16,width:.13,raised:50},legs:{length:.17,across:.05},comb:!0,stoop:20,neckReach:.12,colors:{body:"#f4ede0",wing:"#e6dccb",beak:"#e7a43a",legs:"#e7a43a",comb:"#d9372e",...t.colors},call:"cluck",flies:!1})}const En={car:Uu,truck:Gu,bus:Vu,tractor:Ju,cart:Zu,trainCar:Qu,bike:tf,motorbike:ef,tree:nf,house:of,helicopter:af,airplane:lf,horse:df,dog:uf,cat:ff,cow:pf,songbird:yf,crow:bf,chicken:wf};function kf(t,e={}){const n=En[t];if(!n)throw new Error(ot("prop preset",t,Object.keys(En)));return n(e)}const ji=["do","at","for","to","toward","speed","open","on","height","wind"],Sa={viewer:0,right:1,away:2,left:3},ak=420,Ta={hold:{summary:"Holds still (`for` ms, default 1000).",run:(t,e,n)=>({end:n+(e.for??1e3)})},turn:{summary:"Turns to face `toward`: viewer, right, away, left, or a quarter-turn value (it turns in 3D, through the nearer way).",needs:["toward"],run:(t,e,n)=>({end:t.turnTo(n,e.toward)})},pop:{summary:"Pops into being: grows from nothing, stretched, overshoots and settles (`for` ms, default 500).",uses:["for"],run(t,e,n){const s=e.for??500,i=t.exaggeration;return t.key(n,{size:0,squash:1},{act:!1}),t.key(n+s*.6,{size:1+.15*i,squash:1+.15*i},{act:!1,easing:"ease-out"}),t.key(n+s,{size:1,squash:1}),{end:n+s,contact:n}}},vanish:{summary:"Shrinks away to nothing, with a little stretch first (`for` ms, default 400).",uses:["for"],run(t,e,n){const s=e.for??400,i=t.exaggeration;return t.key(n+s*.3,{size:1+.08*i,squash:1+.12*i},{act:!1,easing:"ease-out"}),t.key(n+s,{size:0,squash:1},{act:!1,easing:"ease-in"}),{end:n+s,release:n+s}}}};function Bi(t){return{...Ta,...t.actions}}const Ea=t=>typeof t=="number"&&Number.isFinite(t);function vf(t,e){if(!Array.isArray(t))return[{level:"error",beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const n=Bi(e),s=Object.keys(n),i=[];return t.forEach((o,r)=>{const a=c=>i.push({level:"error",beat:r,message:c});if(!o||typeof o!="object"||Array.isArray(o))return a(`Each beat must be an object like { do: '${s[s.length-1]}' }.`);const l=o;for(const c of Object.keys(l))ji.includes(c)||a(ot("beat field",c,ji,c==="duration"?"for":c==="direction"?"toward":void 0));if(typeof l.do!="string"||!s.includes(l.do))return a(ot(`${e.kind} action`,l.do,s));for(const c of n[l.do].needs??[])l[c]===void 0&&a(`\`${l.do}\` needs \`${c}\`.`);for(const c of["at","for","speed","height","wind"])l[c]!==void 0&&!(Ea(l[c])&&l[c]>=0)&&a(`\`${c}\` must be a number ≥ 0 (got ${JSON.stringify(l[c])}).`);if(l.to!==void 0&&!Ea(l.to)&&a(`\`to\` is a scene x in px (got ${JSON.stringify(l.to)}).`),l.toward!==void 0&&!Ea(l.toward)&&!(typeof l.toward=="string"&&l.toward in Sa)){const c=typeof l.toward=="string"?Rn(l.toward,Object.keys(Sa)):void 0;a(`\`toward\` is viewer, right, away, left or a quarter-turn number${c?` (did you mean "${c}"?)`:""} (got ${JSON.stringify(l.toward)}).`)}for(const c of["open","on"])l[c]!==void 0&&typeof l[c]!="boolean"&&a(`\`${c}\` is true or false (got ${JSON.stringify(l[c])}).`)}),i}function Mf(t,e,n,s={}){const i=vf(n,e).filter(T=>T.level==="error");if(i.length>0)throw new Error(`propScript (${e.kind}): ${i.length} problem(s) in the beats:
61
+ ${i.map(T=>` beat ${T.beat}: ${T.message}`).join(`
62
+ `)}`);const o=s.from??0,r=s.ground??0,a=s.scale??60,l=s.exaggeration??1,c=Bi(e),h={};for(const T of[...Object.keys(vn),...Object.keys(e.rig.controls)])h[T]=s.start?.[T]??ft(e.rig,{},T);const d=[{time:0,pose:{...h}}],u=new Map,f=[];let g=o,p=r;const m=(T,I,v,P)=>{const H=u.get(T)??[{time:0,value:T==="x"||T==="y"?0:h[T]}];H.push({time:I,value:v,...P?{easing:P}:{}}),u.set(T,H),T!=="x"&&T!=="y"&&(h[T]=v)},b=(T,I)=>{const v=T==="x"?g-o:T==="y"?p-r:h[T],P=u.get(T);(!P||P[P.length-1].time<I)&&m(T,I,v)},S={prop:e,scale:a,exaggeration:l,get x(){return g},get floor(){return p},values:h,facing(){const T=Math.sin(h.turn*Math.PI/2);return Math.abs(T)<.5?0:T>0?1:-1},key(T,I,v={}){Object.assign(h,I),d.push({time:T,pose:{...h},...v.act===!1?{act:!1}:{},...v.easing?{easing:v.easing}:{}})},move(T,I,v,P={}){b("x",T),m("x",I,v-o,P.easing),g=v,P.floor!==void 0&&(b("y",T),m("y",I,P.floor-r,P.easing),p=P.floor)},set(T,I,v,P){m(T,I,v,P)},turnTo(T,I){const v=typeof I=="number"?I:Sa[I],P=h.turn,O=[v-4,v,v+4].map(j=>({t:j,d:Math.abs(j-P)})).sort((j,D)=>j.d-D.d||Math.abs(j.t)-Math.abs(D.t))[0];if(O.d<.001)return T;const C=T+ak*Math.max(1,O.d);return S.key(C,{turn:O.t}),C},effect(T){f.push(T)},anchor(T){const v=Mn(e,h,a).anchors[T];if(!v)throw new Error(`${e.kind}: no anchor "${T}"`);return{x:g+v.point.x,y:p+v.point.y}}},k=[];let y=0;for(const T of n){const I=Math.max(T.at??y,d[d.length-1].time),v=c[T.do].run(S,T,I);v.end>d[d.length-1].time&&d.push({time:v.end,pose:{...h}}),k.push({start:I,end:v.end,...v.contact!==void 0?{contact:v.contact}:{},...v.release!==void 0?{release:v.release}:{}}),y=v.end}const M=Yr(s.style??"snappy"),$={...M,anticipation:M.anticipation*l,overshoot:M.overshoot*l},E=Ei(dk(d),e.acting,{style:$}),A=[...Object.entries(E).filter(([T])=>!u.has(T)).map(([T,I])=>({id:`${t}-${T}`,target:t,property:T,keyframes:I})),...[...u].map(([T,I])=>({id:`${t}-${T}`,target:t,property:T,keyframes:uk(I)}))];for(const T of ck(t,e,A,y,d[0].pose)){const I=A.findIndex(H=>H.property===T.property);if(I<0){A.push(T);continue}const v=new Ht({id:`${t}-own`,tracks:[A[I]]}),P=H=>Number(v.getStateAtTime(H).values.get(t)?.get(T.property)??0);A[I]={...T,keyframes:T.keyframes.map(H=>({time:H.time,value:Number(H.value)+P(H.time)}))}}return{tracks:A,duration:y,beats:k,effects:f}}const lk=1500;function ck(t,e,n,s,i){if(!e.follow?.length)return[];const o=new Ht({id:`${t}-follow`,tracks:n.filter(a=>a.property==="turn"||e.follow.some(l=>l.of===a.property))}),r=(a,l)=>{const c=o.getStateAtTime(a).values.get(t)?.get(l);return typeof c=="number"?c:i[l]??0};return e.follow.map(a=>{const l=s+lk,c=Ll(u=>r(u,a.of),{start:0,end:l,stiffness:a.stiffness,damping:a.damping}),h=a.limit??1/0,d=c.map(({time:u,value:f})=>{const g=Math.sin(r(u,"turn")*Math.PI/2),p=(f-r(u,a.of))*g;return{time:u,value:Math.max(-h,Math.min(h,p*a.per))}});return{id:`${t}-${a.control}`,target:t,property:a.control,keyframes:d}})}const hk=20;function dk(t){const e=[...t].sort((s,i)=>s.time-i.time),n=[];for(const s of e){const i=n[n.length-1];i&&s.time-i.time<hk?n[n.length-1]={...s,time:i.time}:n.push(s)}return n}function uk(t){const e=t.map((s,i)=>({k:s,i})).sort((s,i)=>s.k.time-i.k.time||s.i-i.i),n=[];for(const{k:s}of e)n.length>0&&n[n.length-1].time===s.time?n[n.length-1]=s:n.push(s);return n}const fk={linear:!0,"ease-in":!0,"ease-out":!0,"ease-in-out":!0,"ease-in-quad":!0,"ease-out-quad":!0,"ease-in-out-quad":!0,"ease-in-cubic":!0,"ease-out-cubic":!0,"ease-in-out-cubic":!0};function Sf(t,e={}){const n={};for(const s of Object.keys(Ot))n[s]={summary:`Walks to \`to\` in the ${s} gait.`,needs:["to"]};for(const s of Object.keys(Dt))n[s]={summary:`Moves into the ${s} pose and holds it (\`for\` ms).`};for(const s of Object.keys(Me))n[s]={summary:`The ${s} gag (${rs(s)} ms).`};for(const[s,i]of Object.entries(ls))n[s]={...i};return{...t?{version:t}:{},timing:"JSON timelines and tracks are in milliseconds; the GSAP-style API (live.to, tf.timeline) takes seconds. Scene x grows right, y grows down, in px.",easings:{named:Object.keys(fk),parametric:{"cubic-bezier":'{ type: "cubic-bezier", points: [x1, y1, x2, y2] }',steps:'{ type: "steps", count, position?: start | end | none | both }',elastic:'{ type: "elastic", mode?: in | out | in-out, amplitude?, period? }',bounce:'{ type: "bounce", mode?: in | out | in-out }',back:'{ type: "back", mode?: in | out | in-out, overshoot? }'}},trackKinds:{keyframe:"{ id, target, property, keyframes: [{ time, value, easing? }] }: values between keys are interpolated (numbers, colours, paths)",spring:'{ id, target, property, kind: "spring", spring: { from, to, stiffness?, damping?, mass?, velocity? }, delay? }: physics settle',inertia:'{ id, target, property, kind: "inertia", inertia: { from, velocity, friction?, min?, max?, end? }, delay? }: a flick that slows (end snaps to a value or the nearest of a list)',motionPath:'{ property: "motionPath", path, align? }: moves along an SVG path',text:'{ property: "text", … }: types or scrambles text'},canvasProperties:_i,stickFigure:{poseFields:zc,props:Xc,handFields:Uc,poses:Object.keys(Dt),expressions:Object.keys(ct),gags:Object.fromEntries(Object.keys(Me).map(s=>[s,rs(s)])),gaits:Object.keys(Ot),actingStyles:Object.keys(je),beatFields:$i,actions:n,dances:Object.fromEntries(Object.entries(ye).map(([s,i])=>[s,Object.keys(i.moves)])),flips:Object.fromEntries(Object.entries(Jn).map(([s,i])=>[s,i.label])),handShapes:Object.keys(Tt),mudras:Object.keys(Gs)},props:{api:{"car() · truck() · bus() · tractor() · cart() · trainCar() · bike() · motorbike()":"wheeled vehicles (vehicle(spec) makes your own)","tree() · house()":"environment (tree(spec), house(spec))","helicopter() · airplane()":"aircraft","horse() · dog() · cat() · cow()":"animals (quadruped(spec) makes your own): gaits with footfall patterns keyed in step with the distance, sit, jump, their calls, species actions","songbird() · crow() · chicken()":"birds (bird(spec) makes your own): hop, walk, peck, flap, fly and land (a chicken flutters), their calls; wings fold and beat in rhythm","{ kind: 'prop', prop: 'car', position, rotation, values } with loadScene3D(scene, { kinds: [characterObjects, propObjects] })":"props in 3D scenes, by preset name, seen in perspective by the scene camera; controls are tracks on the object","characterScript3D(id, beats, { scene, position?, heading?, height?, pose? })":"a v2 character in a 3D scene in world metres: gaits to [x, z] or through points (its walk phase keyed with the distance), face, hold, pose, gag; checkCharacterBeats3D checks the beats","propRide3D({ prop, propId, propTracks, scene, placement, anchor, riderId, pose, start, end, mount?, dismount? })":"a character riding a prop in a 3D scene: hips on a seat anchor (saddle, seat) as it moves, hopping on and off; RIDING_POSES.astride / .seated","propScript3D(id, prop, beats, { scene, position?, heading?, values? })":"props scripted in world metres for 3D scenes: moves to [x, z] or through points (wheels and strides keyed with the distance), face, hold, and their actions; checkPropBeats3D checks the beats","propPreset(name, options?)":"a prop preset by name (did-you-mean on a wrong one)","propTarget({ …, style: 'stick' })":"line art to go with stick figures: tubes as single strokes, shapes outlined over paper","propTow({ leader, leaderId, leaderTracks, hitch, towed, towedId, anchor, start, end })":"a prop towed by another (a cart behind a horse): turns with it, its wheels roll exactly","propTarget({ x, y, prop, scale?, values?, look?, ink? })":"a canvas target that draws a prop (x, y: its middle on the ground; scale px per metre, default 60)","propScript(id, prop, beats, { from, ground, scale, style?, exaggeration?, start? })":"beats → acted tracks, with contact times and effect cues; checkPropBeats(beats, prop) checks them","drawProp(ctx, target, frame, id, { rider? })":"draw it as it is in a frame (a rider is drawn between its far and near parts)","propAt(target, frame, id).anchor(name)":"where an anchor (seat, door, chimney…) is, in scene px","propRide({ prop, propId, propTracks, anchor, figure, figureId, start, end, offset? })":"a figure carried at an anchor, turning with the prop; spliceTracks() puts it into the figure’s tracks","drawPropEffects(ctx, effects, time)":"dust, exhaust, skid marks, honk lines, leaves, smoke"},beatFields:ji,commonControls:Object.fromEntries(Object.entries(vn).map(([s,i])=>[s,`${i.description}${i.unit?` (${i.unit})`:""}`])),commonActions:Object.fromEntries(Object.entries(Ta).map(([s,i])=>[s,i.summary])),presets:Object.fromEntries(Object.entries(En).map(([s,i])=>{const o=i();return[s,{family:o.family,summary:o.summary,actions:Object.fromEntries(Object.entries(o.actions).map(([r,a])=>[r,{summary:a.summary,...a.needs?{needs:a.needs}:{}}])),controls:Object.keys(o.rig.controls),anchors:Object.keys(o.rig.anchors??{})}]}))},custom:{api:{"defineAction({ summary, needs?, steps: (from, beat) => [{ after, pose, easing? }] })":"a new action written as timed pose steps from the current pose, like a gag","defineAction({ summary, needs?, beats: (beat) => [beats] })":"a new action built from other beats (which may be custom too)","defineGait({ swing, knee, arm, elbow, lean, cycle?, … })":"a new gait (the Gait fields in degrees; cycle is ms per two steps)","scriptTracks(id, beats, { actions, gaits })":"beats may then use those names; checkBeats(beats, { actions, gaits }) knows them","stickFigureTarget({ …, cast: { actions, gaits } })":"a figure that draws the gaits and lists the actions in describeTarget","persona({ name, summary?, height?, look?, acting?, gait?, mood?, stance?, energy?, actions?, gaits? })":"a character’s look, acting style and habits: .figure({ x, y }), .script(id, beats, { from, ground }), .check(beats), .handPath(…), .describe(); `go` walks in its gait, `stand` returns to its stance and face"},actions:Object.fromEntries(Object.entries(e.actions??{}).map(([s,i])=>[s,{summary:i.summary,...i.needs?{needs:i.needs}:{}}])),gaits:Object.fromEntries(Object.entries(e.gaits??{}).map(([s,i])=>[s,i.summary??"custom gait"]))},character:{poses:Object.keys(Re),expressions:Object.keys(ar),gags:Object.keys(mi)},codePanel:{languages:Si,removeStyles:vi,anchors:{"line(n, time?)":"line n’s text box { x, y, left, right, top, bottom, width, height }: stand on top, point at x, y","token(n, text, occurrence?, time?)":"a word on a line","spot(n, column, width?, time?)":"a place in a line, for put and write","landing(piece, n, column)":"where a dropped piece will land",box:"the whole panel"},edits:Br},surfaces:{code:ss,board:ne,chart:Fe,prop:Sn},surfaceScript:{"surfaceScript(figureId, { name: surface }, beats, options)":"compiles beats that act on surfaces: returns the script result with `tracks` (the figure’s, ridden, then every surface’s, keyed by its name) and `figureTracks`; options are scriptTracks’ plus `figureStyle` (for carry) and `ride` (default true)","checkSurfaceBeats(beats, surfaces, cast?)":"every problem checkBeats finds, plus unknown surfaces, places, edits and moments, with suggestions","{ surface, anchor }":"a named place, where a beat takes `target` (its box), `to` (its centre x) or `onto` (its top); as laid out, before any edit moves it","then: { surface, edit, anchor, at?, until?, …options }":"what the surface does in answer to the beat (or a list of them): one of its edits, or `carry` (the piece follows the hand until `until`); the other fields are the edit’s options",at:`a moment of the beat: ${wn.join(", ")} (default contact, or start when the beat has none); not ms`,until:"a moment of this beat, or { beat: index, at? } of a later one; sets the edit’s duration (carry needs it)"},cameraShots:{frame:"{ at, duration?, easing?, frame: { focus?: { x, y }, scale?, rotate? } }: push in, pull out, or cut (duration 0)",shake:"{ at, duration, shake: { strength?, frequency?, roll?, seed? } }",follow:"{ at, until, follow: { x: <the subject’s x keyframes>, lead?, y?, lag?, scale? } }: keeps a subject centred"},teach:{"lesson({ id })":"steps as timeline JSON: to, set, together, wait, marker (with pause, question, captions)","cells, pointer, stack, queue, table, pipeline":"diagram primitives (SVG markup + step helpers)","figure({ width, height, children })":"the SVG holding the pieces"},cli:{"tinyfly capabilities [--json]":"this catalog","tinyfly check <beats.json>":"check a beat script (names, fields) with suggestions","tinyfly validate <timeline.json> [--markup file]":"check a timeline against its markup","tinyfly render <timeline.json> <markup> [--at …]":"a frame as static markup","tinyfly video <scene.mjs> [--stills dir --times …]":"MP4, or PNG stills to look at"}}}const It=t=>t.map(e=>`\`${e}\``).join(", "),Tf=t=>Object.entries(t).map(([e,n])=>`| \`${e}\` | ${n.unit??n.kind??""} | ${n.description} |`).join(`
63
+ `);function pk(t,e={}){const n=Sf(t,e),s=n.stickFigure;return[`# tinyfly capabilities${n.version?` (v${n.version})`:""}`,"","Generated from the library itself: every name below is accepted, and names not listed are rejected (beat scripts, code panels and `checkTracks` say which name was probably meant).","",`**Timing.** ${n.timing}`,"","## Easings","",`Named: ${It(n.easings.named)}.`,"",...Object.entries(n.easings.parametric).map(([o,r])=>`- ${o}: \`${r}\``),"","## Track kinds","",...Object.entries(n.trackKinds).map(([o,r])=>`- **${o}**: ${r}`),"","## Canvas targets","","Types: `rect`, `circle`, `text`, `line`, `path`, `image`, `custom`. `describeTarget(target)` lists what one can animate with its values; `checkTracks(tracks, targets)` checks tracks before playing them.","","| Property | Unit | What it does | Types |","|---|---|---|---|",...Object.entries(n.canvasProperties).map(([o,r])=>`| \`${o}\` | ${r.unit??r.kind??""} | ${r.description} | ${r.types.length===7?"all":r.types.join(", ")} |`),"","## Stick figure (`@algorisys/tinyfly/characters`)","","`stickFigureTarget({ x, y, style })` is a custom canvas target; its props are the pose fields and the props below. Pose it with tracks (`poseTracks`), or write beats (`scriptTracks`).","","### Pose fields","","| Field | Unit | What it does |","|---|---|---|",Tf(s.poseFields),"","### Other props","","| Prop | Unit | What it does |","|---|---|---|",Tf(s.props),"",`With \`style.hands\`, each hand has \`hand.left.<field>\` / \`hand.right.<field>\` props: ${It(Object.keys(s.handFields))}.`,"",`**Poses** (a beat's \`do\`, or a pose key): ${It(s.poses)}.`,"",`**Expressions** (a beat's \`mood\`): ${It(s.expressions)}.`,"",`**Gags** (ms): ${Object.entries(s.gags).map(([o,r])=>`\`${o}\` (${r})`).join(", ")}.`,"",`**Gaits**: ${It(s.gaits)}. **Acting styles** (\`style\`): ${It(s.actingStyles)}.`,"","### Beat scripts","",`\`scriptTracks(target, beats, { from, ground, height, facing, style })\`. A beat has these fields only: ${It(s.beatFields)}. Times are ms; \`to\` and \`target\` are scene px; \`onto\` is a floor's scene y.`,"","| `do` | Needs | What happens |","|---|---|---|",...Object.entries(s.actions).map(([o,r])=>`| \`${o}\` | ${(r.needs??[]).map(a=>`\`${a}\``).join(", ")} | ${r.summary} |`),"","Beats that touch something report `contact` (and `release`) times in `result.beats[i]`; key the thing they touch to those.","",`**Dances** (\`dancer(style, { move })\`): ${Object.entries(s.dances).map(([o,r])=>`\`${o}\` (${r.join(", ")})`).join("; ")}.`,"",`**Flips**: ${Object.entries(s.flips).map(([o,r])=>`\`${o}\` (${r})`).join(", ")}.`,"",`**Hand shapes**: ${It(s.handShapes)}. **Mudras**: ${It(s.mudras)}.`,"","### Your own actions, gaits and personas","","Nothing is registered globally: pass your definitions where they are used.","",...Object.entries(n.custom.api).map(([o,r])=>`- \`${o}\`: ${r}`),"",...Object.keys(n.custom.actions).length||Object.keys(n.custom.gaits).length?["**This cast’s own:**","",...Object.entries(n.custom.actions).map(([o,r])=>`- \`${o}\`${r.needs?.length?` (needs ${r.needs.map(a=>`\`${a}\``).join(", ")})`:""}: ${r.summary}`),...Object.entries(n.custom.gaits).map(([o,r])=>`- \`${o}\` (gait): ${r}`),""]:[],"## Props (everyday objects with behaviours)","","A prop is a 3D rig of simple parts drawn with the characters’ pens (clean, pencil, silhouette), so it turns toward the camera (`turn`), and its beats go through the same acting pass (anticipation, overshoot, overlap; `exaggeration` scales them).","",...Object.entries(n.props.api).map(([o,r])=>`- \`${o}\`: ${r}`),"",`Prop beat fields: ${It(n.props.beatFields)}. Every prop has the controls ${Object.keys(n.props.commonControls).map(o=>`\`${o}\``).join(", ")} and the actions ${Object.keys(n.props.commonActions).map(o=>`\`${o}\``).join(", ")}.`,"","| Preset | Family | Actions (needs) | Controls | Anchors |","|---|---|---|---|---|",...Object.entries(n.props.presets).map(([o,r])=>`| \`${o}()\` | ${r.family} | ${Object.entries(r.actions).map(([a,l])=>`\`${a}\`${l.needs?.length?` (${l.needs.join(", ")})`:""}`).join(", ")} | ${r.controls.map(a=>`\`${a}\``).join(", ")} | ${r.anchors.join(", ")} |`),"","## Character (v2 human)","",`Poses: ${It(n.character.poses)}. Expressions: ${It(n.character.expressions)}. Gags: ${It(n.character.gags)}.`,"","## Code panel","",`\`codePanel({ code, language, x, y, fontSize?, lineHeight?, width? })\`: a code listing as a scene object. Languages: ${It(n.codePanel.languages)}. Remove styles: ${It(n.codePanel.removeStyles)}.`,"",...Object.entries(n.codePanel.anchors).map(([o,r])=>`- \`${o}\`: ${r}`),"",...Object.values(n.codePanel.edits).map(o=>`- \`${o.split(":")[0]}\`:${o.split(":").slice(1).join(":")}`),"","## Surfaces","","Scene objects figures act on. Places are named `kind:args`: `surface.anchor(name)` gives the box there (stand on `top`, point at `x`, `y`; pass it as a beat `target`), `surface.piece(name)` makes the part there come loose, and `surface.edit(name, anchor, options)` changes the surface at a time (`at`, ms).","","Beats name places and say what surfaces do in answer (`surfaceScript`):","",...Object.entries(n.surfaceScript).map(([o,r])=>`- \`${o}\`: ${r}`),"",...Object.entries(n.surfaces).flatMap(([o,r])=>[`### ${o}`,"",...r.create?[`\`${r.create}\``,""]:[],"Anchors:",...Object.entries(r.anchors).map(([a,l])=>`- \`${a}\`: ${l}`),"","Edits:",...Object.entries(r.edits).map(([a,l])=>`- \`${a}\`: ${l}`),""]),"## Camera shots (`cameraTracks(shots, { stage })`)","",...Object.entries(n.cameraShots).map(([o,r])=>`- **${o}**: \`${r}\``),"","## Teaching (`@algorisys/tinyfly/teach`)","",...Object.entries(n.teach).map(([o,r])=>`- \`${o}\`: ${r}`),"","## Command line","",...Object.entries(n.cli).map(([o,r])=>`- \`${o}\`: ${r}`),""].join(`
64
+ `)}function gk(t,e,n,s={}){const i=s.color??"#555",o=s.size??60;for(const r of e){const a=(n-r.time)/r.length;if(a<=0||a>=1)continue;const l=qt(`${r.kind}:${r.time}:${r.x}`);r.kind==="dust"?Zd(t,{x:r.x,y:r.y},a,{size:o,color:i,seed:l}):r.kind==="exhaust"?bk(t,r,a,o,i,l):r.kind==="skid"?wk(t,r,a,n,i):r.kind==="honk"?kk(t,r,a,o,i):r.kind==="smoke"?mk(t,r,n,o,i):r.kind==="leaves"&&yk(t,r,a,o,s.leafColor??"#5cae5a",i,l)}}function mk(t,e,n,s,i,o){const r=e.direction??1,a=380,l=1500;t.save(),t.strokeStyle=i,t.lineWidth=Math.max(1,s*.025);for(let c=e.time;c<=e.time+e.length-l;c+=a){const h=(n-c)/l;if(h<=0||h>=1)continue;const d=Math.sin(c/97+h*4)*s*.06,u=e.x+r*h*s*.7+d,f=e.y-h*s*1.6;t.globalAlpha=Math.min(1,h*6)*(1-h)*.85,t.beginPath(),t.arc(u,f,s*(.07+h*.2),0,Math.PI*2),t.stroke()}t.restore()}function yk(t,e,n,s,i,o,r){const a=e.direction??1,l=e.toY??e.y+s*3;t.save(),t.lineWidth=Math.max(1,s*.02),t.strokeStyle=o,t.fillStyle=i;for(let c=0;c<4;c++){const h=qt(`${r}:${c}`)%1e3/1e3,d=Math.min(1,n*(1.1+h*.4)),u=e.x+(h-.5)*s*1.2,f=e.y+(h-.3)*s*.4,g=d*d*.4+d*.6,p=u+a*d*s*(.6+h)+Math.sin(d*9+h*6)*s*.18,m=Math.min(l-2,f+(l-f)*g);t.globalAlpha=n>.85?(1-n)/.15:1,t.save(),t.translate(p,m),t.rotate(Math.sin(d*7+h*5)*1.2),t.beginPath(),t.ellipse(0,0,s*.07,s*.035,0,0,Math.PI*2),t.fill(),t.stroke(),t.restore()}t.restore()}function bk(t,e,n,s,i,o){const r=e.direction??-1;t.save(),t.strokeStyle=i,t.lineWidth=Math.max(1,s*.025);for(let a=0;a<3;a++){const l=n*1.6-a*.25;if(l<=0||l>=1)continue;const c=(qt(`${o}:${a}`)%100/100-.5)*s*.1,h=e.x+r*l*s*.9,d=e.y-l*s*.45+c;t.globalAlpha=(1-l)*.9,t.beginPath(),t.arc(h,d,s*(.06+l*.14),0,Math.PI*2),t.stroke()}t.restore()}function wk(t,e,n,s,i){const o=e.toX??e.x,r=Math.min(1,(s-e.time)/e.length*3),a=e.x+(o-e.x)*r;t.save(),t.strokeStyle=i,t.lineCap="round",t.globalAlpha=n<.6?.8:.8*(1-(n-.6)/.4),t.lineWidth=3;for(const l of[-2,4])t.beginPath(),t.moveTo(e.x,e.y+l),t.lineTo(a,e.y+l),t.stroke();t.restore()}function kk(t,e,n,s,i){const o=e.direction??1;t.save(),t.strokeStyle=i,t.lineWidth=Math.max(1.5,s*.04),t.lineCap="round",t.globalAlpha=n<.7?1:(1-n)/.3;const r=s*(.15+.5*(1-(1-n)**2));for(let a=-1;a<=1;a++){const l=a*Math.PI/7,c=e.x+o*Math.cos(l)*r,h=e.y+Math.sin(l)*r;t.beginPath(),t.arc(c,h,s*.12,o>0?-Math.PI/3:Math.PI*2/3,o>0?Math.PI/3:Math.PI*4/3),t.stroke()}t.restore()}function vk(t){const e=new Ht({id:`${t.propId}-ride`,tracks:t.propTracks.filter(h=>h.target===t.propId)}),n=t.every??33,s=[],i=[],o=[],r=[];let a=1;for(let h=t.start;;h=Math.min(t.end,h+n)){const d=Ri(t.prop,{state:e.getStateAtTime(h)},t.propId),u=d.anchor(t.anchor);s.push({time:h,value:u.x+(t.offset?.x??0)-t.figure.x}),i.push({time:h,value:u.y+(t.offset?.y??0)-t.figure.y});const f=Math.sin(d.values.turn*Math.PI/2);if(Math.abs(f)>.15&&(a=f>0?1:-1),o.push({time:h,value:Math.abs(f)}),r.push({time:h,value:a}),h>=t.end)break}const l=t.figureId,c=[{id:`${l}-x`,target:l,property:"x",keyframes:s},{id:`${l}-y`,target:l,property:"y",keyframes:i}];return t.turn!==!1&&c.push({id:`${l}-turn`,target:l,property:"turn",keyframes:o},{id:`${l}-facing`,target:l,property:"facing",keyframes:Mk(r)}),c}function Mk(t){const e=[];for(const n of t){const s=e[e.length-1];s&&s.value!==n.value&&e.push({time:n.time-1,value:s.value}),(!s||s.value!==n.value||n===t[t.length-1])&&e.push(n)}return e}function Sk(t,e,n){const s=r=>`${r.target}\0${r.property}`,i=new Map(e.map(r=>[s(r),r]));return[...t.map(r=>{const a=i.get(s(r));if(!a)return r;i.delete(s(r));const c=[...(r.keyframes??[]).filter(h=>h.time<n.from||h.time>n.to),...a.keyframes??[]].sort((h,d)=>h.time-d.time);return{...r,keyframes:c}}),...i.values()]}function Tk(t){const e=new Ht({id:`${t.leaderId}-tow`,tracks:t.leaderTracks.filter(f=>f.target===t.leaderId)}),n=t.every??33,s=t.towed,i=s.x+s.width/2,o=s.props,r=s.prop.wheelRadius,a=[],l=[],c=[];let h=o.wheelSpin??0,d;for(let f=t.start;;f=Math.min(t.end,f+n)){const g=Ri(t.leader,{state:e.getStateAtTime(f)},t.leaderId),p=g.anchor(t.hitch),m=g.values.turn,b=Mn(s.prop,{...o,turn:m},s.propScale).anchors[t.anchor];if(!b)throw new Error(`propTow: ${s.prop.kind} has no anchor "${t.anchor}"`);const S=p.x-b.point.x;if(d!==void 0&&r){const k=Math.sin(m*Math.PI/2);h+=(S-d)*(k||1)/s.propScale/r*(180/Math.PI)}if(d=S,a.push({time:f,value:S-i}),l.push({time:f,value:m}),c.push({time:f,value:h}),f>=t.end)break}const u=t.towedId;return[{id:`${u}-x`,target:u,property:"x",keyframes:a},{id:`${u}-turn`,target:u,property:"turn",keyframes:l},...r?[{id:`${u}-wheelSpin`,target:u,property:"wheelSpin",keyframes:c}]:[]]}const Ef=new WeakMap;function Ek(t,e){const n=e?.some(Boolean)?e.map(u=>u?1:0).join(""):"";let s=Ef.get(t);s||Ef.set(t,s=new Map);const i=s.get(n);if(i)return i;const o=ds(t),r={vertices:o.vertices,faces:o.faces.filter((u,f)=>!e?.[f])},a=r.vertices.flatMap(u=>[u[0],u[1],u[2]]),l=r.vertices.map(()=>[0,0,0]),c=[];r.faces.forEach(u=>{for(const p of u.corners)for(const m of[0,1,2])l[p][m]+=u.normal[m];const[f,...g]=u.corners;for(let p=0;p+1<g.length;p++){const[m,b,S]=[f,g[p],g[p+1]],[k,y,M]=[r.vertices[m],r.vertices[b],r.vertices[S]],$=[y[0]-k[0],y[1]-k[1],y[2]-k[2]],E=[M[0]-k[0],M[1]-k[1],M[2]-k[2]],A=[$[1]*E[2]-$[2]*E[1],$[2]*E[0]-$[0]*E[2],$[0]*E[1]-$[1]*E[0]],T=A[0]*u.normal[0]+A[1]*u.normal[1]+A[2]*u.normal[2];c.push(...T>=0?[m,b,S]:[m,S,b])}});const h=l.flatMap(u=>{const f=Math.hypot(...u)||1;return[u[0]/f,u[1]/f,u[2]/f]}),d=li({positions:a,normals:h,indices:c});return s.size>=16&&s.clear(),s.set(n,d),d}function Ak(t,e,n={}){const s=t.ink??n.ink??"#26262b",i=(n.outline??2)*(t.outline??1),o=t.glow&&e.glow>0?$k(t.glow.color,e.glow):void 0;return{color:t.fill??s,creases:ds(t.shape).creases!==!1,shading:n.shading??"toon",...i>0?{outline:{width:i,color:s}}:{},...o?{emissive:o}:{},...t.seeThrough?{opacity:.45*e.opacity}:e.opacity<1?{opacity:e.opacity}:{}}}function $k(t,e){const n=/^#([0-9a-f]{6})$/i.exec(t.trim());return n?`#${[0,2,4].map(i=>Math.round(parseInt(n[1].slice(i,i+2),16)*Math.max(0,Math.min(1,e)))).map(i=>i.toString(16).padStart(2,"0")).join("")}`:t}const Pk=li(Gh(1,.002,28));function xk(t,e,n){const s=t.rig,[i,o]=s.footprint??[s.length*.45,s.length],r=Math.max(0,ft(s,e,"lift")),a=Math.max(0,ft(s,e,"size"))/(1+r*.8);return{mesh:Pk,world:mt(n,wo([0,.004,0],[0,0,0,1],[i*.55*a||1e-4,1,o*.55*a||1e-4])),material:{color:"#000000",shading:"unlit",opacity:.16*a}}}const Ik=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),Ok=1,_k={kind:"prop",validate(t){const e=t,n=typeof e.prop=="string"&&e.prop in En?[]:[ot("prop preset",e.prop,Object.keys(En))];for(const[s,i]of[[0,"rotateX"],[1,"rotateY"],[2,"rotateZ"]])i in e&&n.push(`${i} is a track, not a field: place it turned with rotation: [${[0,1,2].map(o=>o===s?e[i]:0).join(", ")}]`);return n},prepare(t){const e=t;return kf(e.prop,e.options)},resolve({object:t,prepared:e,values:n,world:s,camera:i,lights:o=[],fog:r,toScreen:a}){const l=t,c=e,h={...l.values};for(const[E,A]of n)typeof A=="number"&&!Ik.has(E)&&(h[E]=A);h.turn=0,h.tilt=0;const d=mt(i.view,s),u={toView:E=>Rt(d,E),toScreen:E=>a(E)},f=u.toView([0,c.rig.height/2,0]);if(-f[2]<=i.near)return null;if(l.look==="mesh"){const E=Wu(c.rig,h),A=E.map(({part:v,local:P})=>({part:v.id,mesh:ds(v.shape),...fa(ds(v.shape),P)})),T=Lu(A),I=E.map((v,P)=>({...v,hidden:Du(v.part.id,A[P].mesh,v.local,A[P].key,T)})).filter(({opacity:v})=>v>.01).map(({part:v,matrix:P,glow:H,opacity:O,hidden:C})=>({mesh:Ek(v.shape,C),world:mt(s,P),material:Ak(v,{glow:H,opacity:O},{shading:l.shading,ink:l.ink,outline:l.outline})}));return{meshes:l.shadow===!1?I:[xk(c,h,s),...I]}}const g=a(f),p=a(u.toView([0,c.rig.height/2+1,0])),m=Math.hypot(p.x-g.x,p.y-g.y),b=o.length===0?void 0:(E,A)=>{const T=Rt(s,E),I=[s[0]*A[0]+s[4]*A[1]+s[8]*A[2],s[1]*A[0]+s[5]*A[1]+s[9]*A[2],s[2]*A[0]+s[6]*A[1]+s[10]*A[2]],v=Math.hypot(...I)||1;return{light:rd(T,[I[0]/v,I[1]/v,I[2]/v],o),fog:ad(r,Math.hypot(T[0]-i.position[0],T[1]-i.position[1],T[2]-i.position[2]))}},S=ba(c.rig,h,u,m,{perspective:!0,near:i.near,slice:Ok,light:b}),k={look:l.look,style:l.style,ink:l.ink,paper:l.paper,fog:r?.color},y=Tr(S),M=S.cells??[],$=Math.max(...M.map(E=>-E.depth),-f[2]);return{drawables:[...l.shadow===!1?[]:[{depth:$+c.rig.length,draw:E=>Er(E,S,k)}],...M.map(E=>({depth:-E.depth,draw(A,T){A.lineCap="round",A.lineJoin="round",ld(A,E.parts,y,{...k,time:T.time})}}))]}}},Aa=["do","at","for","to","through","toward","speed","height","open","on","wind"],Ck=.25,Hk=800/180,Rk=220,Lk=300,Nk=["turn"];function Dk(t){const e=Bi(t),n=Object.keys(t.moves??{});return Object.keys(e).filter(s=>!n.includes(s)&&!Nk.includes(s)&&!(e[s].needs??[]).includes("to"))}function Af(t,e){if(!Array.isArray(t))return[{beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const n=Object.keys(e.moves??{}),s=Dk(e),i=[...n,"face","hold",...s.filter(r=>r!=="hold")],o=[];return t.forEach((r,a)=>{const l=d=>o.push({beat:a,message:d});if(!r||typeof r!="object"||Array.isArray(r))return l(`Each beat must be an object like { do: '${i[0]??"hold"}' }.`);const c=r,h={duration:"for",path:"through",points:"through",position:"to",heading:"toward",direction:"toward"};for(const d of Object.keys(c))Aa.includes(d)||l(ot("beat field",d,Aa,h[d]));if(typeof c.do!="string"||!i.includes(c.do)){const d=c.do==="turn"?"face":void 0;return l(ot(`${e.kind} 3D beat`,c.do,i,d))}n.includes(c.do)&&(c.to===void 0&&c.through===void 0&&l(`\`${c.do}\` needs \`to\` ([x, z] metres) or \`through\` (a list of them).`),c.to!==void 0&&!Le(c.to)&&l(`\`to\` is a point on the ground, [x, z] metres (got ${JSON.stringify(c.to)}).`),c.through!==void 0&&!(Array.isArray(c.through)&&c.through.length>0&&c.through.every(Le))&&l("`through` is a list of points on the ground, each [x, z] metres.")),c.do==="face"&&!(Le(c.toward)||typeof c.toward=="number")&&l("`face` needs `toward`: a point [x, z] or a heading in degrees.")}),o}function Fk(t,e,n,s){const i=Af(n,e);if(i.length>0)throw new Error(`propScript3D (${e.kind}): ${i.length} problem(s) in the beats:
65
+ ${i.map(k=>` beat ${k.beat}: ${k.message}`).join(`
66
+ `)}`);const o={};for(const k of[...Object.keys(vn),...Object.keys(e.rig.controls)])o[k]=s.values?.[k]??ft(e.rig,{},k);let[r,a]=s.position??[0,0],l=s.heading??0;const c=new Map,h=(k,y,M,$="linear")=>{const E=c.get(k)??[];E.push({time:y,value:M,easing:$}),c.set(k,E)},d=(k,y,M)=>h(k,y,M);h("x",0,r),h("z",0,a),h("rotateY",0,l);const u=(k,y)=>{const M=yi(l,y);if(Math.abs(M)<1)return k;const $=Math.max(Rk,Math.abs(M)*Hk);return d("rotateY",k,l),l+=M,h("rotateY",k+$,l,"ease-in-out"),k+$},f=(k,y,M)=>{const $=Ad([[r,a],...y.through??[y.to]]);if($.length<2)return M;const E=u(M,mn($[0].point,$[1].point)),A=$[$.length-1].at,T=y.for??A/(y.speed??k.speed)*1e3,I=xt("ease-in-out"),v=Math.min(Lk,T/4);for(const[D,W]of Object.entries(k.set??{}))d(D,E,o[D]),h(D,E+1,W),o[D]=W;const P=k.flies?y.height??(o.lift>.05?o.lift:2):void 0,H=P!==void 0&&P>.05;for(const[D,W]of Object.entries(k.hold??{}))d(D,E,o[D]),h(D,E+v,W,"ease-out"),H||(h(D,E+T-v,W),h(D,E+T,0,"ease-in")),o[D]=H?W:0;P!==void 0&&(d("lift",E,o.lift),h("lift",E+Math.min(T*.35,1400),P,"ease-out"),h("lift",E+T,P),o.lift=P);const O={...o};let C=l;for(let D=0;;D=Math.min(A,D+Ck)){const W=E+Pd(I,D/A)*T,{point:B,direction:_}=$d($,D);C+=yi(C,mn([0,0],_)),h("x",W,B[0]),h("z",W,B[1]),h("rotateY",W,C);for(const[L,N]of Object.entries(k.perMetre??{}))h(L,W,O[L]+D*N);for(const[L,N]of Object.entries(k.perSecond??{}))h(L,W,O[L]+(W-E)/1e3*N);if(D>=A)break}for(const[D,W]of Object.entries(k.perMetre??{}))o[D]=O[D]+A*W;for(const[D,W]of Object.entries(k.perSecond??{}))o[D]=O[D]+T/1e3*W;return[r,a]=$[$.length-1].point,l=C,E+T},g=(k,y)=>{const M=Object.fromEntries(Object.entries(k).filter(([E])=>!["at","to","through","toward"].includes(E))),$=Mf(t,e,[M],{start:{...o,turn:1},scale:100,style:s.style,exaggeration:s.exaggeration});for(const E of $.tracks){if(jk.includes(E.property))continue;const A=E.keyframes??[],T=o[E.property];if(!A.every(I=>I.value===T)){d(E.property,y,T);for(const I of A)I.time>0&&c.get(E.property).push({...I,time:y+I.time});o[E.property]=A[A.length-1].value}}return y+$.duration},p=[];let m=0;for(const k of n){const y=k.at??m;let M=y;const $=e.moves?.[k.do];$?M=f($,k,y):k.do==="face"?M=u(y,typeof k.toward=="number"?k.toward:mn([r,a],k.toward)):k.do==="hold"?M=y+(k.for??1e3):M=g(k,y),p.push({do:k.do,start:y,end:M}),m=M}const b=`${s.scene}/${t}`;return{tracks:[...c].map(([k,y])=>({id:`${t}-${k}`,target:b,property:k,keyframes:Ed(y)})),duration:m,beats:p,end:{position:[r,a],heading:l,values:{...o}}}}const jk=["x","y","turn","facing","tilt"],Bk=.35,$f={seated:Re.sit,astride:{...Re.sit,"leg.left.spread":26,"leg.right.spread":26,"leg.left.swing":40,"leg.right.swing":40,"leg.left.knee":70,"leg.right.knee":70}},Pf=(t,e)=>{const n=e*Math.PI/180;return[t[0]*Math.cos(n)+t[2]*Math.sin(n),t[1],-t[0]*Math.sin(n)+t[2]*Math.cos(n)]};function Wk(t){const e=`${t.scene}/${t.propId}`,n=new Ht({id:`${t.propId}-ride-3d`,tracks:t.propTracks.filter(m=>m.target===e)}),s=t.placement??{},[i,o,r]=s.position??[0,0,0],a=t.prop.rig,l=yr({...t.character,height:1}),c={...ut,...t.pose??$f.seated},h=ri(l.plan,c,{height:t.height??1.7,contact:l.contact}).hip,d=t.facing??0,u=t.every??33,f={x:[],y:[],z:[],rotateY:[]};for(let m=t.start;;m=Math.min(t.end,m+u)){const b=n.getStateAtTime(m).values.get(e)??new Map,S=(O,C)=>{const j=b.get(O);return typeof j=="number"?j:C},k={...s.values};for(const O of Object.keys(a.controls))k[O]=S(O,s.values?.[O]??ft(a,{},O));for(const O of["pitch","roll","squash","lift","lean","size"])k[O]=S(O,s.values?.[O]??ft(a,{},O));const y=qu(a,k)[t.anchor];if(!y)throw new Error(`propRide3D: ${t.prop.kind} has no anchor "${t.anchor}" (it has ${Object.keys(a.anchors??{}).join(", ")||"none"})`);const M=S("rotateY",s.heading??0),$=Pf(y,M),E=[S("x",i)+$[0],S("y",o)+$[1],S("z",r)+$[2]],A=M+d,T=Pf(h,A);let I=[E[0]-T[0],E[1]-T[1],E[2]-T[2]];const v=(O,C)=>{const j=C*C*(3-2*C);return[O[0]+(I[0]-O[0])*j,I[1]*j+Bk*Math.sin(Math.PI*C),O[1]+(I[2]-O[1])*j]},P=t.mount?Math.max(1,t.mount.for??450):0,H=t.dismount?Math.max(1,t.dismount.for??450):0;if(t.mount&&m<t.start+P?I=v(t.mount.from,(m-t.start)/P):t.dismount&&m>t.end-H&&(I=v(t.dismount.to,(t.end-m)/H)),f.x.push({time:m,value:I[0]}),f.y.push({time:m,value:I[1]}),f.z.push({time:m,value:I[2]}),f.rotateY.push({time:m,value:A}),m>=t.end)break}const g=t.riderId,p=`${t.scene}/${g}`;return Object.keys(f).map(m=>({id:`${g}-${m}`,target:p,property:m,keyframes:f[m]}))}function qk(t){const{timeline:e}=t,n=new _e;for(const[c,h]of Object.entries(t.targets)){const d=typeof h=="string"?document.querySelector(h):h;if(!d)throw new Error(`quickPlay: no element found for target "${c}" (${String(h)})`);n.registerTarget(c,d)}e.onUpdate=c=>{n.applyState(c),t.onUpdate?.(c)},t.onComplete&&(e.onComplete=t.onComplete);let s=null,i=null,o=!1;const r=c=>{if(o)return;const h=i===null?0:c-i;i=c,h>0&&e.tick(h),s=requestAnimationFrame(r)},a=()=>{s!==null||o||(i=null,s=requestAnimationFrame(r))},l=()=>{s!==null&&cancelAnimationFrame(s),s=null,i=null};return n.applyState(e.getStateAtTime(e.currentTime)),t.autoplay!==!1&&(e.play(),a()),{timeline:e,adapter:n,play(){e.play(),a()},pause(){e.pause(),l()},restart(){e.stop(),e.play(),a()},seek(c){e.seek(c*1e3),n.applyState(e.getStateAtTime(e.currentTime))},destroy(){o=!0,l(),e.stop(),n.clearTargets()}}}const Kk={timeline:Ep,to(t,e,n){const s=new Oe(n);return s.to(t,e),s},from(t,e,n){const s=new Oe(n);return s.from(t,e),s},fromTo(t,e,n,s){const i=new Oe(s);return i.fromTo(t,e,n),i},set(t,e,n){const s=new Oe(n);return s.set(t,e),s}};function xf(t,e,n){if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(e,n);const s=t.canvas;if(s?.ownerDocument){const i=s.ownerDocument.createElement("canvas");return i.width=e,i.height=n,i}try{return s?.constructor?new s.constructor(e,n):null}catch{return null}}function Yk(t,e){const n=t.length/4,s=new Float32Array(n*3),i=Math.min(.999,Math.max(0,e));for(let o=0;o<n;o++){const r=t[o*4]/255,a=t[o*4+1]/255,l=t[o*4+2]/255,c=t[o*4+3]/255,h=Math.max(r,a,l);if(h<=i)continue;const d=(h-i)/(1-i)*c/h;s[o*3]=r*d,s[o*3+1]=a*d,s[o*3+2]=l*d}return s}function If(t,e,n,s,i){const o=new Float32Array(t.length),r=i?n:e,a=i?e:n,l=(h,d)=>(i?h*e+d:d*e+h)*3,c=s*2+1;for(let h=0;h<r;h++)for(let d=0;d<3;d++){let u=0;for(let f=-s;f<=s;f++)u+=t[l(h,Math.min(a-1,Math.max(0,f)))+d];for(let f=0;f<a;f++){o[l(h,f)+d]=u/c;const g=t[l(h,Math.max(0,f-s))+d],p=t[l(h,Math.min(a-1,f+s+1))+d];u+=p-g}}return o}function Of(t,e,n,s){const i=Math.max(1,Math.round(s/Math.sqrt(3)));let o=t;for(let r=0;r<3;r++)o=If(o,e,n,i,!0),o=If(o,e,n,i,!1);return o}function zk(t,e={}){const n=t.canvas,s=n.width,i=n.height;if(!(s>0&&i>0))return;const o=Math.max(1,Math.round(e.downsample??4)),r=Math.max(1,Math.ceil(s/o)),a=Math.max(1,Math.ceil(i/o)),l=xf(t,r,a),c=l?.getContext("2d");if(!l||!c)return;c.imageSmoothingEnabled=!0,c.drawImage(t.canvas,0,0,r,a);const h=Yk(c.getImageData(0,0,r,a).data,e.threshold??.55),d=(e.radius??Math.max(s,i)*.02)/o,u=Of(h,r,a,d),f=Of(h,r,a,d*3),g=e.halo??.6,p=c.createImageData(r,a);for(let m=0;m<r*a;m++){for(let b=0;b<3;b++)p.data[m*4+b]=Math.round(Math.min(1,u[m*3+b]+f[m*3+b]*g)*255);p.data[m*4+3]=255}c.putImageData(p,0,0),t.save(),t.setTransform(1,0,0,1,0,0),t.globalCompositeOperation="lighter",t.globalAlpha=Math.max(0,e.strength??.9),t.imageSmoothingEnabled=!0,t.drawImage(l,0,0,s,i),t.restore()}function Xk(t,e,n){const s=n.width??6,i=n.taper??1,o=n.fade??1,r=n.opacity??1,a=n.blend==="add";if(t.save(),e.length>=2){const c=Gk(e,s,i,o,r);a?(t.globalCompositeOperation="lighter",$a(t,c,n.color)):Vk(t,c,n.color)}const l=e[e.length-1];if(n.head&&l&&n.head.radius>0){a&&(t.globalCompositeOperation="lighter");const c=n.head.color??n.color,h=t.createRadialGradient(l.at.x,l.at.y,0,l.at.x,l.at.y,n.head.radius);h.addColorStop(0,c),h.addColorStop(.35,c),h.addColorStop(1,Uk(t,c)),t.globalAlpha=r,t.fillStyle=h,t.beginPath(),t.arc(l.at.x,l.at.y,n.head.radius,0,Math.PI*2),t.fill()}t.restore()}function Uk(t,e){t.fillStyle=e;const n=String(t.fillStyle),s=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i.exec(n);if(s)return`rgba(${parseInt(s[1],16)}, ${parseInt(s[2],16)}, ${parseInt(s[3],16)}, 0)`;const i=/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i.exec(n);return i?`rgba(${i[1]}, ${i[2]}, ${i[3]}, 0)`:"rgba(0, 0, 0, 0)"}function Gk(t,e,n,s,i){const o=t.map(c=>({x:c.at.x,y:c.at.y,width:e*(1-n*c.age)})),r=Dl(o),a=Fl(o)??void 0,l=[];for(let c=0;c+1<t.length;c++){const h=(t[c].age+t[c+1].age)/2,d=i*(1-s*h);if(d<=0)continue;const u=c+2===t.length;l.push({corners:[r.left[c],r.left[c+1],r.right[c+1],r.right[c]],alpha:d,...u&&a&&{cap:a}})}return l}function $a(t,e,n){t.fillStyle=n;for(const s of e){const[i,o,r,a]=s.corners;t.globalAlpha=Math.min(1,s.alpha),t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(o.x,o.y),s.cap&&t.arc(s.cap.x,s.cap.y,s.cap.radius,s.cap.start,s.cap.start-Math.PI,!0),t.lineTo(r.x,r.y),t.lineTo(a.x,a.y),t.closePath(),t.fill()}}function Vk(t,e,n){const s=typeof t.getTransform=="function"?t.getTransform():null,i=p=>s?{x:s.a*p.x+s.c*p.y+s.e,y:s.b*p.x+s.d*p.y+s.f}:p,o=s?Math.sqrt(Math.abs(s.a*s.d-s.b*s.c)):1,r=e.map(p=>({...p,corners:p.corners.map(i),...p.cap&&{cap:{...p.cap,...i(p.cap),radius:p.cap.radius*o,start:p.cap.start+(s?Math.atan2(s.b,s.a):0)}}}));let a=1/0,l=1/0,c=-1/0,h=-1/0;for(const p of r){const m=p.cap?[{x:p.cap.x-p.cap.radius,y:p.cap.y-p.cap.radius},{x:p.cap.x+p.cap.radius,y:p.cap.y+p.cap.radius}]:[];for(const b of[...p.corners,...m])a=Math.min(a,b.x),l=Math.min(l,b.y),c=Math.max(c,b.x),h=Math.max(h,b.y)}if(!(c>a&&h>l))return;const d=Math.floor(a)-1,u=Math.floor(l)-1,f=s?xf(t,Math.ceil(c)+1-d,Math.ceil(h)+1-u):null,g=f?.getContext("2d");if(!f||!g){$a(t,e,n);return}g.translate(-d,-u),g.globalCompositeOperation="lighter",$a(g,r,n),t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=1,t.drawImage(f,d,u),t.restore()}const Jk=Lt.to,Zk=Lt.from,Qk=Lt.fromTo,t2=Lt.set,e2=Lt.timeline,n2=Lt.ticker,s2=Lt.splitText,i2=Lt.context,o2=Lt.matchMedia,r2=Lt.quickTo,a2=Lt.imageSequence,l2=Lt.pageTransition;Zg(),w.ACTING_STYLES=je,w.AIRCRAFT_ACTING=ka,w.ANIMAL_GAITS=Tn,w.BEAT_FIELDS=$i,w.BEAT_MOMENTS=wn,w.BIRD_ACTING=mf,w.BOARD_MARKS=Wr,w.BOARD_THEMES=is,w.CANVAS_PROPERTIES=_i,w.CHARACTER_BEAT_3D_FIELDS=Cr,w.CHARACTER_GAIT_SPEEDS=xd,w.CHART_KINDS=Kr,w.CHART_SURFACE=Fe,w.CHART_THEMES=os,w.CODE_LANGUAGES=Si,w.CODE_PANEL_EDITS=Br,w.CODE_SURFACE=ss,w.CODE_THEME=Ld,w.Clock=Rf,w.CompatTimeline=Oe,w.CustomBounce=$c,w.CustomEase=Ac,w.CustomWiggle=Pc,w.DANCE_STYLES=ye,w.DEFAULT_BAKE_INTERVAL_MS=ro,w.DEFAULT_INERTIA_FRICTION=Ui,w.DEFAULT_LABELS=Nc,w.DEFAULT_SPRING=Bt,w.DEFAULT_TRANSITION=tm,w.Draggable=Po,w.EXPRESSIONS=ct,w.FINGERS=Qc,w.FLIPS=Jn,w.FORMAT_VERSION=Wi,w.GAGS=Me,w.GAITS=Ot,w.GAIT_CYCLE_MS=ea,w.HAND_REST=vt,w.HAND_SHAPES=Tt,w.HORSE_ACTING=nk,w.HORSE_GAITS=Zw,w.HOUSE_ACTING=rf,w.HUMAN_ACTING_RIG=Xd,w.HUMAN_EXPRESSIONS=ar,w.HUMAN_GAGS=mi,w.HUMAN_POSES=Re,w.HUMAN_REST=ut,w.IDENTITY_CAMERA=Od,w.INERTIA_MAX_DURATION_MS=Ca,w.InertiaTrackPlayer=wl,w.LiveTimeline=Zt,w.MORPH_SAMPLES=s0,w.MUDRAS=Gs,w.ManualClock=Hf,w.MediaSync=Wo,w.Observer=sc,w.POSES=Dt,w.PROP_BEAT_3D_FIELDS=Aa,w.PROP_BEAT_FIELDS=ji,w.PROP_COMMON_ACTIONS=Ta,w.PROP_COMMON_CONTROLS=vn,w.PROP_PRESETS=En,w.PROP_SURFACE=Sn,w.QUADRUPED_ACTING=va,w.REMOVE_STYLES=vi,w.REST_POSE=et,w.RIDING_POSES=$f,w.SAMPLE_STEP=Ne,w.SCRIPT_ACTIONS=ls,w.SPRING_MAX_DURATION_MS=Xi,w.SPRING_PRESETS=bs,w.SPRING_STEP_MS=ze,w.STICK_ACTING_RIG=zd,w.ScrollAnimator=wc,w.ScrollDriver=Fn,w.ScrollMarkers=kc,w.ScrollPin=gc,w.SmoothScroll=Fo,w.SpringSampler=Pn,w.SpringTrackPlayer=bl,w.Stage=Jl,w.TREE_ACTING=sf,w.Timeline=Ht,w.TinyflyPlayer=Ds,w.TinyflySequencer=Yc,w.TrackPlayer=Es,w.VEHICLE_ACTING=zu,w.VISEMES=Se,w.ValueResolver=O0,w.VisibilityDriver=pc,w.WHITEBOARD_SURFACE=ne,w.actCharacterTracks=Ob,w.actKeyframes=Ei,w.actTracks=Gd,w.actionNames=Jr,w.airplane=lf,w.anchorError=ve,w.animalStrideLength=Di,w.animatableProperties=Pu,w.applyBloom=zk,w.applyCamera=jy,w.applyGroove=Rh,w.assertBeats=ta,w.backOut=qa,w.bakeDanceTracks=y1,w.bakeEasing=co,w.bakeInertiaTrack=lo,w.bakeSpringTrack=ao,w.basicOutfit=Mb,w.beatAt=p1,w.beatAtTime=$s,w.beatLength=yo,w.beatTime=As,w.beatsBetween=q0,w.bike=tf,w.bindChoiceHotspots=Bc,w.bird=Fi,w.blendPose=hn,w.boilFrame=Ko,w.bounceOut=Wa,w.boxMesh=yd,w.bus=Vu,w.cameraFromValues=Fy,w.cameraPoint=By,w.cameraTracks=X0,w.capabilities=Sf,w.capabilitiesMarkdown=pk,w.car=Uu,w.cart=Zu,w.cat=ff,w.changingWindows=ki,w.character=yr,w.characterAt=my,w.characterHandPose=ed,w.characterJoints=Zh,w.characterJointsInView=dy,w.characterObjects=_y,w.characterPartsInView=sd,w.characterPoseTracks=yy,w.characterScript3D=Dy,w.characterTarget=gy,w.charactersFor=kl,w.chart=mb,w.checkBeats=cs,w.checkCast=Zr,w.checkCharacterBeats3D=Id,w.checkPropBeats=vf,w.checkPropBeats3D=Af,w.checkSurfaceBeats=Eu,w.checkTracks=Tw,w.chicken=wf,w.circlePath=Yy,w.clamp01=Ro,w.clearMorphCache=u0,w.clearPathCache=Zf,w.clipErased=Fr,w.closestName=Rn,w.codePanel=nb,w.codeTokens=Dd,w.containerProgressAt=Lo,w.context=i2,w.controlValue=ft,w.cow=pf,w.create=Ng,w.createControls=Fc,w.createCubicBezier=ja,w.createLive=Oc,w.createPen=qn,w.createRandom=$e,w.createTrack=Ts,w.criticalDamping=Df,w.crow=bf,w.customBounce=Ol,w.customEase=Il,w.customWiggle=_l,w.cylinderMesh=bd,w.danceFrame=Zs,w.dancePose=c1,w.danceStance=Js,w.danceTaps=d1,w.danceTracks=m1,w.danceTravel=ti,w.danceTravelTrack=jh,w.dancer=g1,w.defineAction=qb,w.defineGait=Kb,w.describeTarget=$u,w.deserializeTimeline=Qe,w.deserializeTrack=Tl,w.detectTempo=K0,w.dog=uf,w.draggable=Vp,w.drawCartoonHand=zs,w.drawCharacter=nd,w.drawCharacterInView=uy,w.drawDustPuff=Zd,w.drawEraser=Nr,w.drawHand=Dr,w.drawImpactStars=Rb,w.drawPencil=_d,w.drawProp=Bw,w.drawPropEffects=gk,w.drawPropShadow=Er,w.drawSolvedFaces=ld,w.drawSolvedPart=vy,w.drawSolvedProp=Sr,w.drawSpeedLines=Jd,w.drawStickFigure=Ih,w.drawStickSmear=Hb,w.drawTrail=Xk,w.drawnPathTarget=zy,w.easeIn=Na,w.easeInCubic=Gi,w.easeInOut=Fa,w.easeInOutCubic=In,w.easeInOutQuad=La,w.easeInQuad=Ha,w.easeOut=Da,w.easeOutCubic=Vi,w.easeOutQuad=Ra,w.editDistance=Rl,w.editError=ns,w.editLog=ts,w.elasticOut=Ba,w.ellipsePoints=Yo,w.ellipsoidMesh=wd,w.erasable=Vy,w.expandBeats=xi,w.expandParametricEasings=ml,w.extrudeMesh=kd,w.flipPose=Bh,w.flipTracks=_1,w.flipTravel=Wh,w.formatVersionFor=qi,w.from=Zk,w.fromJSON=P0,w.fromTo=Qk,w.gag=Ur,w.gagDuration=rs,w.gaitPose=sh,w.gaitStrideLength=Uo,w.getEasingFunction=xt,w.getInterpolator=Hn,w.getMotionPathPoint=ho,w.getPathLength=Qf,w.getPointAtProgress=Ua,w.gridLinesFor=rc,w.handAt=Ky,w.handJoints=Ys,w.handJointsAt=nh,w.handPath=ha,w.handPose=Mt,w.handProp=Gn,w.hasKeyframes=Ia,w.hashSeed=qt,w.headPoint=Qm,w.heldTime=Oa,w.helicopter=af,w.horse=df,w.horseStrideLength=ik,w.house=of,w.humanFieldLabel=X1,w.humanGag=gd,w.humanGaitPose=fd,w.humanGaitStrideLength=pd,w.humanPlan=Kh,w.humanPose=Ft,w.imageSequence=a2,w.inertiaDuration=Ue,w.inertiaRest=Xe,w.inertiaValueAt=ks,w.inertiaVelocityAt=Wf,w.interpolateArray=ul,w.interpolateColor=dl,w.interpolateMotionPath=S0,w.interpolateNumber=Gt,w.interpolatePathString=pl,w.interpolateQuaternion=fl,w.interpolateString=oo,w.isCubicBezierEasing=Ye,w.isInertiaTrack=re,w.isMotionPathPoint=Cf,w.isMotionPathTrack=Ki,w.isParametricEasing=An,w.isPathData=Ve,w.isSpringTrack=ae,w.isTextTrack=ps,w.isUnderdamped=Nf,w.isUnresolved=I0,w.jointsInScene=od,w.jointsToScene=xh,w.linear=vs,w.lipSyncKeyframes=Vr,w.lipSyncOver=au,w.lipSyncTracks=Bb,w.lit=Ir,w.live=Lt,w.mapEase=Ln,w.mat4=sp,w.matchMedia=o2,w.maxStaggerDistance=zi,w.mirrorHumanPose=z1,w.mirrorPose=Hh,w.mixColors=Or,w.mixHandPoses=cn,w.mixPoses=fy,w.morphPath=el,w.motorbike=ef,w.mount=Wc,w.mountAll=Kc,w.narrationMarkers=F0,w.narrationSceneAt=j0,w.naturalRest=xn,w.nearestBeat=B0,w.nextBeat=W0,w.niceCeiling=Kd,w.pageTransition=l2,w.panelMesh=vd,w.parametricEasing=Ya,w.parseAnchor=De,w.parseEdge=Co,w.parsePath=Ae,w.parseTrigger=Ho,w.partialPath=ln,w.pathLength=Vc,w.persona=Mw,w.pieceMotion=es,w.planNarration=D0,w.play=Lg,w.playSequence=Qg,w.playWhenVisible=cg,w.playheadCrossings=fo,w.pointAlong=js,w.pointAtDistance=Zi,w.pointOnHead=ay,w.pointsToPath=Nl,w.pose=Et,w.poseTracks=s1,w.propActions=Bi,w.propAnchors3D=qu,w.propAt=Ri,w.propControls=wa,w.propLineWidth=Tr,w.propObjects=_k,w.propPartsInSpace=Wu,w.propPreset=kf,w.propRide=vk,w.propRide3D=Wk,w.propScript=Mf,w.propScript3D=Fk,w.propShapeMesh=ds,w.propSurface=Kw,w.propTarget=jw,w.propTow=Tk,w.propView=Fu,w.quadruped=fs,w.quat=b0,w.quickPlay=qk,w.quickTo=r2,w.randomBetween=go,w.randomChoice=x0,w.randomSnapped=Al,w.reachCharacter=py,w.resolveActingStyle=Yr,w.resolveCharacterPoseKeys=vr,w.resolveGait=zn,w.resolvePoseKeys=er,w.resolveSequence=xl,w.resolveStickFrame=Zo,w.resolveStickPose=Oh,w.resolveValue=mo,w.ribbon=Dl,w.ribbonHeadCap=Fl,w.rideFloors=jr,w.rotateAbout=pe,w.routineBeats=Qs,w.rubberLimb=Ce,w.scriptActionSummaries=Qr,w.scriptTracks=ca,w.scrollProgress=lg,w.scrubOnScroll=fg,w.scrubPath=Uy,w.seatHeight=Xm,w.serializeTimeline=El,w.serializeTrack=Ml,w.set=t2,w.shade=gi,w.shapeMesh=Td,w.shapeToPathData=Ps,w.simplifyKeyframes=yl,w.sittingPose=hf,w.skeletonInView=ai,w.sketchPen=Bs,w.smoothPath=_r,w.smoothToward=fc,w.snapAxis=oc,w.snapConfig=mc,w.snapDuration=bc,w.snapProgress=yc,w.solveAt=Mn,w.solvePlanSpace=oi,w.solveProp=ba,w.songbird=yf,w.soundsOf=ru,w.speechDuration=Tu,w.spliceTracks=Sk,w.splitText=s2,w.springDuration=_a,w.springFollow=Ll,w.springValueAt=Lf,w.stagePlanSpace=ri,w.staggerDistance=Yi,w.staggerOffset=gs,w.staggerOffsets=ms,w.staggerSpan=$n,w.stepsDuration=cu,w.stepsEasing=Ka,w.stepsToKeys=Gr,w.stickFigureAt=tr,w.stickFigureJoints=me,w.stickFigureTarget=Qo,w.stickToHuman=G1,w.strideLength=ch,w.surfaceBox=bt,w.surfaceScript=kw,w.syncMediaElement=Lc,w.talkingMouth=hh,w.taperedLine=Ws,w.taperedOutline=Wn,w.textAt=vl,w.tf=Kk,w.ticker=n2,w.timeline=e2,w.to=Jk,w.toJSON=$0,w.toKeyframedTrack=v0,w.toKeyframedTracks=M0,w.trackTargets=de,w.tractor=Ju,w.trailSamples=G0,w.trainCar=Qu,w.tree=nf,w.triggerDistance=sn,w.truck=Gu,w.tubeMesh=Md,w.unknownName=ot,w.unmount=Vg,w.valueAt=wi,w.vec3=J0,w.vehicle=oe,w.walkPose=lh,w.whiteboard=ab,w.withErased=Gy,w.withExpression=ge,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})}));