@algorisys/tinyfly 0.110.0 → 0.111.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(b,Ln){typeof exports=="object"&&typeof module<"u"?Ln(exports):typeof define=="function"&&define.amd?define(["exports"],Ln):(b=typeof globalThis<"u"?globalThis:b||self,Ln(b.tinyfly=b.tinyfly||{}))})(this,(function(b){"use strict";function Ln(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function _s(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const Wr=2;function Dr(t){return t.some(e=>e.interpolation!==void 0)?2:1}function Bi(t){return t.property==="text"&&"textConfig"in t}function Ne(t){return t.kind==="inertia"&&"inertia"in t}function We(t){return t.kind==="spring"&&"spring"in t}function Br(t){return t.property==="motionPath"&&"motionPathConfig"in t}function _1(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"angle"in t}function mh(t){return"keyframes"in t}class C1{_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 H1{_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 yh(t,e){if(!(e>0))return t;const n=1e3/e;return Math.floor(t/n+1e-9)*n}function zr(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 qr(t,e="start"){if(t<=1)return 0;let n=0;for(let s=0;s<t;s++)n=Math.max(n,zr(s,t,e));return n}function zi(t,e,n){if(n.offsets)return n.offsets[t]??0;const s=n.from??"start",i=zr(t,e,s);if(n.amount!==void 0){const o=qr(e,s);return o===0?0:n.amount*i/o}return n.each!==void 0?n.each*i:0}function qi(t,e){return Array.from({length:t},(n,s)=>zi(s,t,e))}function Cs(t,e){return t<=1?0:Math.max(...qi(t,e))}const Fn=1,jr=6e4,ji=jr/Fn,ce={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1},Yi={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 Hs{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??ce.stiffness,this.damping=e.damping??ce.damping,this.mass=e.mass??ce.mass,this.restDelta=e.restDelta??ce.restDelta,this.restSpeed=e.restSpeed??ce.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=e.velocity??ce.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/Fn);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/Fn-n;return s+(i-s)*o}settleTime(){return this.simulateTo(ji+1),this.settledStep!==null?this.settledStep*Fn:jr}simulateTo(e){if(this.settledStep!==null)return;const n=Math.min(e,ji+1),s=Fn/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>ji&&(this.settledStep=ji)}}function R1(t,e){return new Hs(t).valueAt(e)}function bh(t){return new Hs(t).settleTime()}function L1(t){const e=t.stiffness??ce.stiffness,n=t.damping??ce.damping,s=t.mass??ce.mass;return n<2*Math.sqrt(e*s)}function F1(t){const e=t.stiffness??ce.stiffness,n=t.mass??ce.mass;return 2*Math.sqrt(e*n)}const Yr=4,N1=.002,W1=1e-4,wh=6e4;function Ki(t){const e=t.friction??Yr;return e>0?e:Yr}function Rs(t){return t.from+t.velocity/Ki(t)}function D1(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 Nn(t){let e=D1(Rs(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 Wn(t){const e=Math.abs(Nn(t)-t.from);if(e===0)return 0;const n=t.restDelta??Math.max(W1,e*N1);if(n>=e)return 0;const s=Math.log(e/n)/Ki(t);return Math.min(wh,s*1e3)}function Xi(t,e){if(e<=0)return t.from;const n=Nn(t);if(e>=Wn(t))return n;const s=Ki(t);return t.from+(n-t.from)*(1-Math.exp(-s*e/1e3))}function B1(t,e){const n=Ki(t),s=Nn(t);return e>=Wn(t)?0:(s-t.from)*n*Math.exp(-n*Math.max(0,e)/1e3)}const Gi=t=>t,kh=t=>t*t,vh=t=>1-(1-t)*(1-t),Mh=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,Kr=t=>t*t*t,Xr=t=>1-Math.pow(1-t,3),Ls=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,Sh=Kr,xh=Xr,Th=Ls,z1={linear:Gi,"ease-in":Sh,"ease-out":xh,"ease-in-out":Th,"ease-in-quad":kh,"ease-out-quad":vh,"ease-in-out-quad":Mh,"ease-in-cubic":Kr,"ease-out-cubic":Xr,"ease-in-out-cubic":Ls};function Eh(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=g=>((a*g+r)*g+o)*g,d=g=>((h*g+c)*g+l)*g,f=g=>(3*a*g+2*r)*g+o,p=g=>{let m=g;for(let k=0;k<8;k++){const y=u(m)-g;if(Math.abs(y)<1e-7)return m;const x=f(m);if(Math.abs(x)<1e-7)break;m-=y/x}let w=0,v=1;for(m=g;w<v;){const k=u(m);if(Math.abs(k-g)<1e-7)return m;g>k?w=m:v=m,m=(w+v)/2}return m};return g=>{if(g<=0)return 0;if(g>=1)return 1;const m=p(g);return d(m)}}function Gr(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 Ah(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 $h=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 Ph(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 Ih(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 Oh(t){switch(t.type){case"steps":return Ih(t.count,t.position);case"elastic":return Gr(Ah(t.amplitude,t.period),t.mode);case"bounce":return Gr($h,t.mode);case"back":return Gr(Ph(t.overshoot),t.mode)}}function Wt(t){return t===void 0?Gi:Ln(t)?Eh(t.points):_s(t)?Oh(t):z1[t]??Gi}const _h=32,q1=256,Dn=new Map,j1=/[MmLlHhVvCcSsQqTtAaZz]/,Y1=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,K1={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function X1(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(j1.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=Y1.exec(t.slice(n));if(!l)break;s.args.push(parseFloat(l[0])),n+=l[0].length}return e}function G1(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),p=(t-a)/2,g=(e-l)/2,m=d*p+f*g,w=-f*p+d*g,v=m*m/(c*c)+w*w/(h*h);if(v>1){const F=Math.sqrt(v);c*=F,h*=F}const k=o===r?-1:1,y=c*c*h*h-c*c*w*w-h*h*m*m,x=c*c*w*w+h*h*m*m,P=k*Math.sqrt(Math.max(0,y/x)),M=P*c*w/h,T=-P*h*m/c,S=d*M-f*T+(t+a)/2,E=f*M+d*T+(e+l)/2,$=(F,H,W,_)=>{const B=F*W+H*_,Q=Math.sqrt((F*F+H*H)*(W*W+_*_)),O=Math.acos(Math.max(-1,Math.min(1,B/Q)));return F*_-H*W<0?-O:O},A=$(1,0,(m-M)/c,(w-T)/h);let I=$((m-M)/c,(w-T)/h,(-m-M)/c,(-w-T)/h);!r&&I>0&&(I-=2*Math.PI),r&&I<0&&(I+=2*Math.PI);const C=Math.max(1,Math.ceil(Math.abs(I)/(Math.PI/2))),D=I/C,j=4/3*Math.tan(D/4),V=F=>{const H=c*Math.cos(F),W=h*Math.sin(F);return[d*H-f*W+S,f*H+d*W+E]},et=F=>{const H=-c*Math.sin(F),W=h*Math.cos(F);return[d*H-f*W,f*H+d*W]},G=[];for(let F=0;F<C;F++){const H=A+F*D,W=H+D,[_,B]=V(H),[Q,O]=F===C-1?[a,l]:V(W),[R,z]=et(H),[K,N]=et(W);G.push([_+j*R,B+j*z,Q-j*K,O-j*N,Q,O])}return G}function De(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 Ch(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 Fs(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 Ui(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<=_h;f++){const p=f/_h,g=De(t,s,o,a,p),m=De(e,i,r,l,p);d+=Math.hypot(g-h,m-u),c.push(d),h=g,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 hn(t){const e=Dn.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=g=>{c<0&&(c=0),g.subpath=c,n.push(g)};for(const{type:g,args:m}of X1(t)){const w=g.toUpperCase(),v=g!==w,k=K1[w];if(w==="Z"){(s!==o||i!==r)&&u(Fs(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 x=m.slice(y,y+k),P=v?s:0,M=v?i:0;let T=null,S=null;switch(w){case"M":y===0?(s=x[0]+P,i=x[1]+M,o=s,r=i,(c<0||n[n.length-1]?.subpath===c)&&c++):(u(Fs(s,i,x[0]+P,x[1]+M)),s=x[0]+P,i=x[1]+M);break;case"L":u(Fs(s,i,x[0]+P,x[1]+M)),s=x[0]+P,i=x[1]+M;break;case"H":u(Fs(s,i,x[0]+P,i)),s=x[0]+P;break;case"V":u(Fs(s,i,s,x[0]+M)),i=x[0]+M;break;case"C":{const E=[x[0]+P,x[1]+M,x[2]+P,x[3]+M,x[4]+P,x[5]+M];u(Ui(s,i,E)),T=[E[2],E[3]],s=E[4],i=E[5];break}case"S":{const[E,$]=a?[2*s-a[0],2*i-a[1]]:[s,i],A=[E,$,x[0]+P,x[1]+M,x[2]+P,x[3]+M];u(Ui(s,i,A)),T=[A[2],A[3]],s=A[4],i=A[5];break}case"Q":case"T":{let E=s,$=i;w==="Q"?(E=x[0]+P,$=x[1]+M):l&&(E=2*s-l[0],$=2*i-l[1]);const A=w==="Q"?x[2]+P:x[0]+P,I=w==="Q"?x[3]+M:x[1]+M;u(Ui(s,i,[s+2/3*(E-s),i+2/3*($-i),A+2/3*(E-A),I+2/3*($-I),A,I])),S=[E,$],s=A,i=I;break}case"A":{const E=x[5]+P,$=x[6]+M;let A=s,I=i;for(const C of G1(s,i,x[0],x[1],x[2],x[3],x[4],E,$))u(Ui(A,I,C)),A=C[4],I=C[5];s=E,i=$;break}}a=T,l=S}}const d=n.reduce((g,m)=>g+m.length,0),f=[];for(let g=0;g<n.length;){const m=n[g].subpath;let w=g,v=0;for(;w<n.length&&n[w].subpath===m;)v+=n[w++].length;const k=n[g],y=n[w-1],x=h.has(m)||Math.abs(y.endX-k.startX)<1e-9&&Math.abs(y.endY-k.startY)<1e-9;f.push({start:g,end:w,length:v,closed:x}),g=w}const p={segments:n,totalLength:d,subpaths:f};return Dn.size>=q1&&Dn.delete(Dn.keys().next().value),Dn.set(t,p),p}function U1(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 V1(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=U1(t,e);let c=Ch(t.startX,n,i,r,l),h=Ch(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=De(t.startX,n,i,r,u),f=De(t.startY,s,o,a,u),p=De(t.startX,n,i,r,l),g=De(t.startY,s,o,a,l);c=l<.5?d-p:p-d,h=l<.5?f-g:g-f}return{x:De(t.startX,n,i,r,l),y:De(t.startY,s,o,a,l),angle:Math.atan2(h,c)*180/Math.PI}}function Ur(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 V1(r,e-i);i+=r.length}return{x:0,y:0,angle:0}}function Hh(t,e){const{segments:n,totalLength:s}=hn(t);return Ur(n,Math.max(0,Math.min(1,e))*s)}function J1(){Dn.clear()}function Z1(t){return hn(t).totalLength}const Q1=24,ty=320,ey=2.5,Ns=72,ny=64,sy=.2,iy=128,Ws=new Map;let Vi=0,Be;const Rh=t=>Math.round(t*100)/100;function Lh(t,e){const{segments:n,subpaths:s,totalLength:i}=hn(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 Vr(t,e){const n=t.closed?(e%1+1)%1:Math.max(0,Math.min(1,e)),s=Ur(t.segments,n*t.length,t.start,t.end);return[s.x,s.y]}function Fh(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 Nh(t,e){const n=[];for(let s=0;s<e;s++)n.push(Vr(t,t.closed?s/e:s/(e-1)));return n}function Wh(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 oy(t,e,n){const s=t.closed&&e.closed;if(n!==void 0)return{offset:s?Math.abs(n)%Ns/Ns:0,reversed:n<0};const i=Wh(Nh(t,Ns)),o=Wh(Nh(e,Ns)),r=Ns;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 p=s?c?(u-f+r)%r:(f+u)%r:c?r-1-f:f,g=i[f][0]-o[p][0],m=i[f][1]-o[p][1];d+=g*g+m*m}d<l&&(l=d,a={offset:s?u/r:0,reversed:c})}}return a}function ry(t,e,n){return n?((e.reversed?e.offset-t:t+e.offset)%1+1)%1:e.reversed?1-t:t}function ay(t,e,n){return n?((e.reversed?e.offset-t:t-e.offset)%1+1)%1:e.reversed?1-t:t}function ly(t,e,n){const s=t.closed&&e.closed,i=oy(t,e,n.shapeIndex),o=Math.max(Q1,Math.min(ty,Math.ceil(Math.max(t.length,e.length)/ey))),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 Fh(t))a(u);for(const u of Fh(e))a(ay(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(...Vr(t,u)),h.push(...Vr(e,ry(u,i,s)));return cy({from:c,to:h,closed:s})}function cy(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=sy;for(let h=r+1;h<a;h++){const u=Math.max(Dh(t.from,r,a,h),Dh(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 Dh(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 hy(t,e,n){const s=n.shapeIndex;if(Be&&Be.from===t&&Be.to===e&&Be.shapeIndex===s)return Be.plan;const o=Ws.get(String(s??"auto"))?.get(t)?.get(e);if(o)return Be={from:t,to:e,shapeIndex:s,plan:o},o;const r=hn(t).subpaths.filter(f=>f.length>0).length===hn(e).subpaths.filter(f=>f.length>0).length,a=Lh(t,!r),l=Lh(e,!r),c={pairs:a.map((f,p)=>ly(f,l[p],n))};Vi>=iy&&(Ws.clear(),Vi=0);const h=String(s??"auto"),u=Ws.get(h)??new Map;Ws.set(h,u);const d=u.get(t)??new Map;return u.set(t,d),d.set(e,c),Vi++,Be={from:t,to:e,shapeIndex:s,plan:c},c}function Bh(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=hy(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=Rh(a.from[l]+(a.to[l]-a.from[l])*i),h=Rh(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 uy(){Ws.clear(),Vi=0,Be=void 0}function Bn(t){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(t)}const zn=Math.PI/180,dy=.9995;function Jr(){return[0,0,0,1]}function Vt(t,e){const n=Math.hypot(t[0],t[1],t[2]);if(n===0)return Jr();const s=e*zn/2,i=Math.sin(s)/n;return[t[0]*i,t[1]*i,t[2]*i,Math.cos(s)]}function fy(t,e,n){return Zr(Zr(Vt([0,1,0],e),Vt([1,0,0],t)),Vt([0,0,1],n))}function gy(t){const[e,n,s,i]=ze(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/zn,Math.atan2(o,u)/zn,Math.atan2(r,a)/zn]:[d/zn,Math.atan2(-h,c)/zn,0]}function Zr(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 zh(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function qh(t){return Math.hypot(t[0],t[1],t[2],t[3])}function ze(t){const e=qh(t);return e===0?Jr():[t[0]/e,t[1]/e,t[2]/e,t[3]/e]}function py(t){return[-t[0],-t[1],-t[2],t[3]]}function jh(t,e,n){const s=ze(t);let i=ze(e),o=zh(s,i);if(o<0&&(i=[-i[0],-i[1],-i[2],-i[3]],o=-o),o>dy)return ze([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 ze([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 my(t,e){const[n,s,i,o]=ze(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 yy=Object.freeze(Object.defineProperty({__proto__:null,conjugate:py,dot:zh,fromAxisAngle:Vt,fromEuler:fy,identity:Jr,length:qh,multiply:Zr,normalize:ze,rotateVec3:my,slerp:jh,toEuler:gy},Symbol.toStringTag,{value:"Module"})),we=(t,e,n)=>t+(e-t)*n,Yh=512,Qr=new Map,ta=new Map;function Kh(t){const e=Qr.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 Qr.size<Yh&&Qr.set(t,s),s}const Xh=t=>t.charCodeAt(0)===35,Gh=t=>t.startsWith("rgb"),Uh=t=>t.startsWith("rgba"),by=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,ea=t=>Math.round(t).toString(16).padStart(2,"0");function wy(t,e,n){return`#${ea(t)}${ea(e)}${ea(n)}`}function Vh(t){const e=ta.get(t);if(e)return e;const n=t.match(by);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 ta.size<Yh&&ta.set(t,r),r}const Jh=(t,e,n)=>{if(Xh(t)&&Xh(e)){const[s,i,o]=Kh(t),[r,a,l]=Kh(e),c=we(s,r,n),h=we(i,a,n),u=we(o,l,n);return wy(c,h,u)}if((Gh(t)||Uh(t))&&(Gh(e)||Uh(e))){const s=Vh(t),i=Vh(e),o=Math.round(we(s[0],i[0],n)),r=Math.round(we(s[1],i[1],n)),a=Math.round(we(s[2],i[2],n));if(s.length===4||i.length===4){const l=s[3]??1,c=i[3]??1,h=we(l,c,n);return`rgba(${o}, ${r}, ${a}, ${h})`}return`rgb(${o}, ${r}, ${a})`}return n<1?t:e},Zh=(t,e,n)=>{const s=Math.min(t.length,e.length),i=[];for(let o=0;o<s;o++)i.push(we(t[o],e[o],n));return i},Qh=(t,e,n)=>jh(t,e,n),na=(t,e,n)=>n<1?t:e,t0=(t,e,n)=>Bh(t,e,n);function Ds(t,e){return e==="slerp"?Qh:typeof t=="number"?we:Array.isArray(t)?Zh:typeof t=="string"?t.startsWith("#")||t.startsWith("rgb")?Jh:Bn(t)?t0:na:na}const sa=1e3/60;function ia(t,e={}){if(!We(t))throw new Error(`bakeSpringTrack: track "${t.id}" is not a spring track`);const n=new Hs(t.spring);return e0(t,s=>n.valueAt(s),n.settleTime(),t.spring.from,t.spring.to,e)}function oa(t,e={}){if(!Ne(t))throw new Error(`bakeInertiaTrack: track "${t.id}" is not an inertia track`);const n=t.inertia;return e0(t,s=>Xi(n,s),Wn(n),n.from,Nn(n),e)}function e0(t,e,n,s,i,o){const r=o.intervalMs??sa,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?s0(c,a):c,...t.targets&&{targets:[...t.targets]},...t.stagger&&{stagger:{...t.stagger}}}}function ra(t,e,n,s={}){const i=s.intervalMs??sa,o=typeof n=="function"?n:Wt(n),r=Ds(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 ky(t,e){return We(t)?ia(t,e):Ne(t)?oa(t,e):t}function n0(t,e={}){const n=t.keyframes;if(!n.some(o=>_s(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];_s(r.easing)?s.push(...ra(n[o-1],r,r.easing,i)):s.push(r)}return{...t,keyframes:s}}function vy(t,e){return t.filter(mh).map(n=>n0(n,e)).concat(t.filter(We).map(n=>ia(n,e)),t.filter(Ne).map(n=>oa(n,e)))}function s0(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 Ji(t){const e=[...t.keyframes].sort((n,s)=>n.time-s.time);return{...t,keyframes:e}}function qe(t){return t.targets&&t.targets.length>0?t.targets:[t.target]}function qn(t,e,n,s){const i=n??0;return!s||e<=1?i:i+zi(t,e,s)}class un{track;targets;constructor(e){this.track=e,this.targets=qe(e)}getValueAtTime(e){return this.valueForOffset(e-qn(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=qn(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?Cs(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=Wt(i.easing)(r);return Ds(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 i0{track;targets;sampler;constructor(e){this.track=e,this.targets=qe(e),this.sampler=new Hs(e.spring)}getValueAtTime(e){return this.sampler.valueAt(e-qn(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=qn(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?Cs(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+e}getTrack(){return this.track}}class o0{track;targets;duration;constructor(e){this.track=e,this.targets=qe(e),this.duration=Wn(e.inertia)}getValueAtTime(e){return Xi(this.track.inertia,e-qn(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=qn(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:Xi(this.track.inertia,e-o),start:o})}return s}getDuration(){const e=this.track.stagger?Cs(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+e}getTrack(){return this.track}}function aa(t,e){const n={...Hh(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 My(t,e,n,s){const i=e+(n-e)*s;return aa(t,i)}const la={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},Sy=20;function r0(t){const e=la[t??"upperCase"]??t??la.upperCase,n=Array.from(e);return n.length>0?n:Array.from(la.upperCase)}function xy(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 a0(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 v=Math.round(o*Math.max(r.length,a.length));return l?r.slice(0,Math.max(0,r.length-v)).join("")+a.slice(Math.max(0,a.length-v)).join(""):a.slice(0,v).join("")+r.slice(v).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=r0(t.chars),p=t.refreshRate??Sy,g=p>0?Math.floor(n*p/1e3):0,m=t.seed??1;let w="";for(let v=0;v<d;v++){const k=l?v>=d-u:v<u,y=l?a[a.length-(d-v)]:a[v];k&&y!==void 0||y===" "||y===`
2
- `?w+=y:w+=f[xy(m,v,g)%f.length]}return w}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=yh(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",a0(l.textConfig,o,Math.max(0,r)));return}const c=this._motionPathTracks.get(n);if(c&&typeof o=="number"){const h=aa(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 qe(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,Ne(e)){this._trackPlayers.set(e.id,new o0(e));return}if(We(e)){this._trackPlayers.set(e.id,new i0(e)),this._springTracks.set(e.id,e);return}if(Bi(e))this._trackPlayers.set(e.id,new un(e)),this._textTracks.set(e.id,e);else if(Br(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 un(n)),this._motionPathTracks.set(e.id,e)}else this._trackPlayers.set(e.id,new un(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(We(s)||Ne(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=qe(r).filter(u=>qe(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&&!qe(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:Dr(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 Ty=100;function ca(t,e,n,s){const i=[],o=[],{duration:r,alternate:a}=s,l=(f,p,g,m)=>{o.push([f,p]);const w=[];t.forEach((v,k)=>{(g==="forward"?(m?v>=f:v>f)&&v<=p:(m?v<=f:v<f)&&v>=p)&&w.push(k)}),w.sort((v,k)=>(g==="forward"?t[v]-t[k]:t[k]-t[v])||v-k);for(const v of w)i.push({kind:"event",index:v,direction:g})};let c=e.time,h=e.direction,u=e.fresh===!0;const d=Math.min(Ty,Math.max(0,n.iteration-e.iteration));for(let f=0;f<d;f++){const p=h==="forward"?r:0;l(c,p,h,u),i.push({kind:"repeat"}),a?(h=h==="forward"?"reverse":"forward",c=p,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 l0(t){return Ne(t)?{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:c0(t.inertia),...ke(t)}:We(t)?{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...ke(t)}:Bi(t)?{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:t.keyframes.map(ha),...ke(t)}:Br(t)?{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:t.keyframes.map(ha),...ke(t)}:{id:t.id,target:t.target,property:t.property,keyframes:t.keyframes.map(ha),...t.interpolation!==void 0&&{interpolation:t.interpolation},...ke(t)}}function c0(t){return{...t,...Array.isArray(t.end)&&{end:[...t.end]}}}function ha(t){return{time:t.time,value:t.value,...t.easing&&{easing:t.easing}}}function ke(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 h0(t){if(Ne(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"inertia",inertia:c0(e.inertia),...ke(e)}}if(We(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"spring",spring:{...e.spring},...ke(e)}}if(Bi(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),...ke(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,...ke(e)}}return Ji({id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,...t.interpolation!==void 0&&{interpolation:t.interpolation},...ke(t)})}function u0(t){const e=t._config.markers;return{formatVersion:Dr(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(l0),...t.captions&&{captions:JSON.parse(JSON.stringify(t.captions))}}}function jn(t){const e=t.formatVersion??1;if(e>Wr)throw new Error(`tinyfly: this animation uses format version ${e}, but this tinyfly reads up to version ${Wr}. Update tinyfly to play it.`);return new Ht({id:t.id,name:t.name,config:t.config,tracks:t.tracks.map(h0),captions:t.captions})}function Ey(t){return JSON.stringify(u0(t))}function Ay(t){const e=JSON.parse(t);return jn(e)}function ne(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 je(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 ua(t,e,n){return e+t.next()*(n-e)}function d0(t,e,n,s){if(s<=0)return ua(t,e,n);const i=Math.floor((n-e)/s),o=Math.round(t.next()*i);return e+o*s}function $y(t,e){if(e.length!==0)return e[Math.floor(t.next()*e.length)]}const f0=/^([+\-*/])=\s*(-?[\d.]+)$/,g0=/^random\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*(?:,\s*(-?[\d.]+)\s*)?\)$/i;function Py(t){return typeof t!="string"?!1:f0.test(t.trim())||g0.test(t.trim())}function da(t,e={}){if(typeof t!="string")return t;const n=t.trim(),s=f0.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=g0.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?d0(e.random,o,r,a):ua(e.random,o,r)}return t}function p0(t,e=0,n){const s=[];let i=e;for(const o of t){const r=da(o,{base:i,random:n});s.push(r),typeof r=="number"&&(i=r)}return s}class Iy{random;constructor(e){this.random=je(e)}get seed(){return this.random.seed}resolve(e,n=0){return da(e,{base:n,random:this.random})}resolveSequence(e,n=0){return p0(e,n,this.random)}}const Oy=600;function m0(t){if(Array.isArray(t)){const[d,f,p,g]=t;return{fn:w0(d,f,p,g),bezier:[d,f,p,g]}}const{segments:e}=hn(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,p,g]=i.points,m=[a(d),l(f),a(p),l(g)];return{fn:w0(...m),bezier:m}}const c=[],h=[],u=Math.max(8,Math.ceil(Oy/e.length));for(const d of e)for(let f=c.length===0?0:1;f<=u;f++){const[p,g]=_y(d,f/u);c.push(a(p)),h.push(l(g))}return{fn:Cy(c,h)}}function y0(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 b0(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 _y(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 Cy(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 w0(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 Hy=350,Ry=300,Ly=550;function Fy(t,e={}){const n=e.lead??Hy,s=e.gap??Ry,i=e.tail??Ly,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 Ny(t){return t.cues.map(e=>({id:e.id,time:e.start,label:e.text}))}function Wy(t,e){let n=t.scenes[0];for(const s of t.scenes)if(e>=s.start)n=s;else break;return n}const Bs=t=>6e4/t.bpm;function Zi(t,e){return t.offset+e*Bs(t)}function zs(t,e){return(e-t.offset)/Bs(t)}function Dy(t,e){return Zi(t,Math.round(zs(t,e)))}function By(t,e){return Zi(t,Math.ceil(zs(t,e)-1e-9))}function zy(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(zs(t,e)-1e-9);;o++){const r=Zi(t,o);if(r>n+1e-9)break;i.push({time:r,bar:(o%s+s)%s===0,n:o})}return i}const Yn=100;function qy(t,e,n={}){const s=n.minBpm??70,i=n.maxBpm??180,o=Math.max(1,Math.round(e/Yn)),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 S=0;S<a;S++){let E=0;for(let $=S*o;$<(S+1)*o;$++)E+=t[$]*t[$];l[S]=Math.log(1e-6+E/o)}const c=new Float64Array(a);for(let S=1;S<a;S++)c[S]=Math.max(0,l[S]-l[S-1]);const h=c.reduce((S,E)=>S+E,0)/a;for(let S=0;S<a;S++)c[S]=Math.max(0,c[S]-h);const u=Math.max(1,Math.floor(60*Yn/i)),d=Math.min(a-1,Math.ceil(60*Yn/s)),f=S=>{let E=0;for(let $=S;$<a;$++)E+=c[$]*c[$-S];return E/(a-S)};let p=0;for(let S=0;S<a;S++)p+=c[S]*c[S];p/=a;let g=u,m=-1/0;for(let S=u;S<=d;S++){const E=60*Yn/S,$=Math.exp(-.5*(Math.log2(E/120)/.9)**2),A=f(S)*$;A>m&&(m=A,g=S)}const w=S=>{const E=Math.floor(S);return E<0||E+1>=a?0:c[E]+(c[E+1]-c[E])*(S-E)},v=(S,E)=>{let $=0;for(let A=E;A<a;A+=S)$+=w(A);return $};let k=g,y=0,x=-1/0;for(let S=g-.6;S<=g+.6+1e-9;S+=.02){if(S<1)continue;const E=Math.max(1,Math.round(S*4));for(let $=0;$<E;$++){const A=$/E*S,I=v(S,A);I>x&&(x=I,y=A,k=S)}}const P=60*Yn/k,M=p>0?Math.max(0,Math.min(1,f(g)/p)):0,T=(y+.5)*1e3/Yn;return{bpm:Math.round(P*100)/100,offset:Math.round(T%(6e4/P)),confidence:M}}const jy=600,Yy=250,k0=1;function Ky(t,e){const n=e.target??"Camera",s={x:e.stage.width/2,y:e.stage.height/2},i={},o=(u,d,f,p)=>{const g=i[u]??=[];for(;g.length>0&&g[g.length-1].time>=d;)g.pop();g.push({time:d,value:f,...p?{easing:p}:{}})},r=u=>{const d=u.rotate*Math.PI/180,f=(u.focusX-s.x)*u.scale,p=(u.focusY-s.y)*u.scale;return{x:-(f*Math.cos(d)-p*Math.sin(d)),y:-(f*Math.sin(d)+p*Math.cos(d)),scale:u.scale,rotate:u.rotate}},a=(u,d,f)=>{const p=r(d);for(const g of["x","y","scale","rotate"])o(g,u,p[g],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(k0,u.duration??jy);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>k0?"ease-in-out":void 0))}else{const{follow:d}=u,f=d.lag??Yy,p=new Ht({id:"follow",tracks:[{id:"x",target:"s",property:"x",keyframes:d.x}]}),g=v=>p.getStateAtTime(v).values.get("s")?.get("x")??l.focusX,m=[u.at,...d.x.map(v=>v.time).filter(v=>v>u.at&&v<u.until),u.until];a(u.at,l);const w=v=>({focusX:g(v)+(d.lead??0),focusY:d.y??l.focusY,scale:d.scale??l.scale,rotate:l.rotate});for(const v of m){const k=d.x.find(y=>y.time===v)?.easing;a(v+f,w(v),v===u.at?"ease-in-out":k)}l=w(u.until)}for(const u of c.filter(d=>"shake"in d)){const d=u.shake.strength??12,f=u.shake.roll??1.5,p=1e3/(u.shake.frequency??24),g=je(u.shake.seed??Math.round(u.at)+1),m=()=>g.next()*2-1;for(const w of["shakeX","shakeY","shakeRotate"])o(w,u.at,0);for(let w=u.at+p;w<u.at+u.duration;w+=p){const v=1-(w-u.at)/u.duration;o("shakeX",w,m()*d*v),o("shakeY",w,m()*d*v),o("shakeRotate",w,m()*f*v)}for(const w of["shakeX","shakeY","shakeRotate"])o(w,u.at+u.duration,0,"ease-out")}return Object.entries(i).map(([u,d])=>({id:`${n}-${u}`,target:n,property:u,keyframes:d}))}function v0(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 qs(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=v0(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??qs(e,n):void 0;return`Unknown ${t} ${JSON.stringify(e)}${i?`: did you mean "${i}"?`:"."} Known: ${n.join(", ")}`}function js(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}function dn(t,e,n=1){if(!(e>0))return 0;const s=t*n/e;return s-Math.floor(s)}function fa(t){const e=t-Math.floor(t);return 1-Math.abs(e*2-1)}function Xy(t,e){const n=Math.max(1,Math.round(e.cycles??1)),s=e.amplitude??1,i=dn(t,e.period,n)+(e.phase??0),o=i-Math.floor(i);switch(e.shape??"sine"){case"triangle":return s*(fa(o+.25)*2-1);case"square":return o<.5?s:-s;default:return s*Math.sin(o*Math.PI*2)}}function Gy(t,e){const n=Math.max(1,Math.round(e.cycles??1)),s=typeof e.easing=="function"?e.easing:Wt(e.easing??"ease-in-out"),i=dn(t,e.period,n)+(e.phase??0);return s(fa(i))}function Uy(t,e){const n=M0(e.seed),s=Math.max(1,Math.round(e.cycles??1)),i=(dn(t,e.period,1)+(e.phase??0))*Math.PI*2,o=s/Math.PI;return S0([Math.cos(i)*o+7.31,Math.sin(i)*o+3.17],n,e.octaves??1)}function Vy(t,e,n){const s=M0(n.seed),i=Math.max(1,Math.round(n.cycles??1)),o=Math.max(1,Math.round(n.cyclesAlong??1)),r=dn(t,n.period,1)*Math.PI*2,a=dn(e,n.periodAlong,1)*Math.PI*2,l=i/Math.PI,c=o/Math.PI;return S0([Math.cos(r)*l+5.13,Math.sin(r)*l+9.47,Math.cos(a)*c+2.71,Math.sin(a)*c+6.29],s,n.octaves??1)}const M0=t=>typeof t=="string"?ne(t):(t??0)>>>0;function S0(t,e,n){const s=Math.max(1,Math.min(6,Math.round(n)));let i=0,o=1,r=0;for(let a=0;a<s;a++){const l=2**a;i+=o*Jy(t.map(c=>c*l),e+a*1013),r+=o,o*=.5}return i/r}function Jy(t,e){const n=t.length,s=t.map(Math.floor),o=t.map((a,l)=>a-s[l]).map(a=>a*a*(3-2*a));let r=0;for(let a=0;a<1<<n;a++){let l=1;const c=[];for(let h=0;h<n;h++){const u=a>>h&1;l*=u?o[h]:1-o[h],c.push(s[h]+u)}l!==0&&(r+=l*Zy(c,e))}return r}function Zy(t,e){let n=(e^2654435769)>>>0;for(const s of t)n=Math.imul(n^(s|0),2246822507)>>>0,n=(n^n>>>13)>>>0,n=Math.imul(n,3266489909)>>>0,n=(n^n>>>16)>>>0;return n/4294967296*2-1}function Qy(t,e={}){if(t.length===0)throw new Error("curve: needs at least one key");const s={id:"curve",target:"curve",property:"value",keyframes:t.map(o=>({time:o.at,value:o.value,easing:o.easing})).sort((o,r)=>o.time-r.time),interpolation:e.interpolation},i=new un(s);return o=>i.getValueAtTime(o)}function tb(t,e){return e*Bs({bpm:t.bpm})}function eb(t,e){const n=Math.max(1,Math.round(t/Bs(e)));return{beats:n,grid:{...e,bpm:n*6e4/t}}}function nb(t,e,n={}){const s=Math.max(1e-6,n.attack??.05),i=Math.max(1e-6,n.decay??.4),o=zs(e,t),r=o-Math.floor(o),a=r<s?r/s:Math.max(0,1-(r-s)/i),l=n.barAccent??0;if(l<=0)return a;const c=Math.max(1,Math.round(e.beatsPerBar??4)),u=(Math.floor(o)%c+c)%c===0;return a*(u?1+l:1)/(1+l)}function sb(t,e,n={}){const s=n.fps??30,i=Math.max(1,Math.round(e/s)),o=Math.max(1,Math.ceil(t.length/i)),r=new Float32Array(o),a=Math.min(.99,Math.max(0,n.smoothing??.5));let l=0,c=0;for(let h=0;h<o;h++){let u=0;const d=h*i,f=Math.min(t.length,d+i);for(let g=d;g<f;g++)u+=t[g]*t[g];const p=f>d?Math.sqrt(u/(f-d)):0;l=p>l?p:l*a+p*(1-a),r[h]=l,c=Math.max(c,l)}if(n.normalize!==!1&&c>0)for(let h=0;h<o;h++)r[h]/=c;return r}function ib(t,e,n=30,s){if(t.length===0)return 0;const o=(s?dn(e,s)*s:e)*n/1e3,r=Math.floor(o),a=t[Math.min(t.length-1,Math.max(0,r))],l=t[Math.min(t.length-1,Math.max(0,r+1))];return a+(l-a)*(o-r)}const x0={"16:9":16/9,"2.39:1":2.39,"4:3":4/3,"1:1":1,"9:16":9/16,"4:5":4/5},ga=t=>typeof t=="number"?t:x0[t];function ob(t,e){const n=ga(e),s=t.width/t.height;if(n>=s){const o=t.width/n;return{x:0,y:(t.height-o)/2,width:t.width,height:o}}const i=t.height*n;return{x:(t.width-i)/2,y:0,width:i,height:t.height}}function rb(t,e){const n=ga(t),s=i=>Math.max(2,Math.round(i/2)*2);return"width"in e?{width:s(e.width),height:s(e.width/n)}:{width:s(e.height*n),height:s(e.height)}}function ab(t,e={}){const n=s=>({x:t.x+t.width*(1-s)/2,y:t.y+t.height*(1-s)/2,width:t.width*s,height:t.height*s});return{action:n(e.action??.9),title:n(e.title??.8)}}const ve=t=>Math.round(t*1e3)/1e3;function T0(t,e={}){if(t.length===0)return"";const n=e.curviness??1,s=e.closed??!1,i=t.length;let o=`M${ve(t[0].x)} ${ve(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${ve(u.x)} ${ve(u.y)}`;continue}const f=n/6,p=h.x+(u.x-c.x)*f,g=h.y+(u.y-c.y)*f,m=u.x-(d.x-h.x)*f,w=u.y-(d.y-h.y)*f;o+=` C${ve(p)} ${ve(g)} ${ve(m)} ${ve(w)} ${ve(u.x)} ${ve(u.y)}`}return s?`${o} Z`:o}const Bt=(t,e=0)=>{const n=parseFloat(t??"");return Number.isFinite(n)?n:e};function lb(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 Qi(t){const e=t.attributes;switch(t.tag.toLowerCase()){case"path":return e.d??null;case"circle":case"ellipse":{const n=Bt(e.cx),s=Bt(e.cy),i=t.tag.toLowerCase()==="circle"?Bt(e.r):Bt(e.rx),o=t.tag.toLowerCase()==="circle"?Bt(e.r):Bt(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=Bt(e.x),s=Bt(e.y),i=Bt(e.width),o=Bt(e.height);let r=e.rx!=null?Bt(e.rx):e.ry!=null?Bt(e.ry):0,a=e.ry!=null?Bt(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${Bt(e.x1)} ${Bt(e.y1)} L${Bt(e.x2)} ${Bt(e.y2)}`;case"polyline":case"polygon":{const n=lb(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 cb(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 hb=2.5;function E0(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 p=u*c[0]+d*c[1],g=Math.min(hb,1/Math.max(p,1e-6)),m=r.width/2*g;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 A0(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}const ub={scale:1,turn:0,x:0,y:0};function db(t={}){return{scale:t.scale??1,turn:t.turn??0,x:t.x??0,y:t.y??0}}function $0(t,e,n){const{ax:s,ay:i}=to(t,e);return{scale:t,turn:e,x:n.x-(s*n.x-i*n.y),y:n.y-(i*n.x+s*n.y)}}function pa(t,e){const{ax:n,ay:s}=to(t.scale,t.turn);return{x:n*e.x-s*e.y+t.x,y:s*e.x+n*e.y+t.y}}function fb(t,e){const n=pa(e,{x:t.x,y:t.y});return{scale:t.scale*e.scale,turn:t.turn+e.turn,x:n.x,y:n.y}}function gb(t){if(t.scale===0)throw new Error("invertSimilarity: a scale of 0 cannot be undone");const e={scale:1/t.scale,turn:-t.turn,x:0,y:0},n=pa(e,{x:t.x,y:t.y});return{...e,x:-n.x,y:-n.y}}function P0(t){const{ax:e,ay:n}=to(t.scale,t.turn),s=1-e,i=-n,o=s*s+i*i;return o<1e-18?null:{x:(t.x*s+t.y*i)/o,y:(t.y*s-t.x*i)/o}}function pb(t,e){if(t.scale<=0)throw new Error("powSimilarity: the scale must be positive");const n=Math.pow(t.scale,e),s=t.turn*e,i=P0(t);return i?$0(n,s,i):{scale:n,turn:s,x:t.x*e,y:t.y*e}}function mb(t){const{ax:e,ay:n}=to(t.scale,t.turn);return[e,n,-n,e,t.x,t.y]}const to=(t,e)=>{const n=e*Math.PI/180;return{ax:t*Math.cos(n),ay:t*Math.sin(n)}};function eo([t,e,n],s={}){const i=s.scale??1,o=s.centre??{x:0,y:0},r=Math.sqrt(3)/2;return{x:o.x+(t-e)*r*i,y:o.y+((t+e)*.5-n)*i}}const ma=([t,e,n])=>t+e+n;function ya(t,e={}){const[n,s,i]=t.min,[o,r,a]=t.max,l=d=>eo(d,e),c=[(n+o)/2,(s+r)/2,(i+a)/2],h=ma(c),u=[{side:"top",depth:h,tag:t.tag,points:[l([n,s,a]),l([o,s,a]),l([o,r,a]),l([n,r,a])]},{side:"left",depth:h,tag:t.tag,points:[l([n,r,i]),l([o,r,i]),l([o,r,a]),l([n,r,a])]},{side:"right",depth:h,tag:t.tag,points:[l([o,s,i]),l([o,r,i]),l([o,r,a]),l([o,s,a])]}];return t.hide?u.filter(d=>!t.hide.includes(d.side)):u}function ba(t,e={}){return t.map(n=>({box:n,depth:ma([(n.min[0]+n.max[0])/2,(n.min[1]+n.max[1])/2,(n.min[2]+n.max[2])/2])})).sort((n,s)=>n.depth-s.depth).flatMap(({box:n})=>ya(n,e))}function yb(t={}){const e=t.size??10,s=(t.thickness??2)/2,i=[{tag:0,min:[-s,-s,-s],max:[e-s,s,s]},{tag:1,min:[e-s,-s,-s],max:[e+s,e-s,s]},{tag:2,min:[e-s,e-s,-s],max:[e+s,e+s,e]}],o=t.centre??{x:0,y:0},r=eo([2*e/3,e/3,e/3],{scale:t.scale}),a={centre:{x:o.x-r.x,y:o.y-r.y},scale:t.scale};return{boxes:i,faces:[...ba(i,a),...ya({...i[0],hide:["right"]},a)]}}function bb(t={}){const e=Math.max(2,Math.round(t.steps??8)),n=t.tread??1.5,s=t.rise??.25,i=t.width??3,o=t.base??1.5,r=Math.max(1,Math.round(e*(n-2*s)/(n+2*s))),a=2*(e+r),l=n*(e-r)/a,c=[{dir:[1,0,0],across:[0,1,0],count:e},{dir:[0,1,0],across:[-1,0,0],count:e},{dir:[-1,0,0],across:[0,-1,0],count:r},{dir:[0,-1,0],across:[1,0,0],count:r}],h=[];let u=[0,0,0],d=0;for(const w of c){for(let v=0;v<w.count;v++){const k=d*l,y=[u[0]+w.dir[0]*v*n,u[1]+w.dir[1]*v*n,0],x=[y[0]+w.dir[0]*n+w.across[0]*i,y[1]+w.dir[1]*n+w.across[1]*i,0];h.push({tag:d,min:[Math.min(y[0],x[0]),Math.min(y[1],x[1]),0],max:[Math.max(y[0],x[0]),Math.max(y[1],x[1]),k+o]}),d++}u=[u[0]+w.dir[0]*w.count*n,u[1]+w.dir[1]*w.count*n,0]}const f=a*l,p=t.centre??{x:0,y:0},g=eo([e*n/2,e*n/2,f/2+o],{scale:t.scale}),m={centre:{x:p.x-g.x,y:p.y-g.y},scale:t.scale};return{boxes:h,faces:ba(h,m),rise:l}}function I0(t,e,n){let s=0;for(const i of t){const o=(e-i.x)**2+(n-i.y)**2;s+=o>1e-9?i.r*i.r/o:1e9}return s}function wb(t,e={}){if(t.length===0)return[];const n=e.threshold??1,s=Math.max(.5,e.cell??4),i=Math.sqrt(1/n)*1.6,o=e.bounds??{x:Math.min(...t.map(f=>f.x-f.r*i)),y:Math.min(...t.map(f=>f.y-f.r*i)),width:Math.max(...t.map(f=>f.x+f.r*i))-Math.min(...t.map(f=>f.x-f.r*i)),height:Math.max(...t.map(f=>f.y+f.r*i))-Math.min(...t.map(f=>f.y-f.r*i))},r=Math.max(2,Math.ceil(o.width/s)+1),a=Math.max(2,Math.ceil(o.height/s)+1),l=new Float64Array(r*a);for(let f=0;f<a;f++)for(let p=0;p<r;p++)l[f*r+p]=I0(t,o.x+p*s,o.y+f*s)-n;const c=(f,p)=>l[p*r+f],h=(f,p,g,m,w,v)=>{const k=g===v?.5:g/(g-v);return{x:f+(m-f)*k,y:p+(w-p)*k}},u=[];for(let f=0;f+1<a;f++)for(let p=0;p+1<r;p++){const g=o.x+p*s,m=o.y+f*s,w=g+s,v=m+s,k=[c(p,f),c(p+1,f),c(p+1,f+1),c(p,f+1)],y=(k[0]>0?1:0)|(k[1]>0?2:0)|(k[2]>0?4:0)|(k[3]>0?8:0);if(y===0||y===15)continue;const x=()=>h(g,m,k[0],w,m,k[1]),P=()=>h(w,m,k[1],w,v,k[2]),M=()=>h(g,v,k[3],w,v,k[2]),T=()=>h(g,m,k[0],g,v,k[3]),S=(k[0]+k[1]+k[2]+k[3])/4>0;switch(y){case 1:case 14:u.push([T(),x()]);break;case 2:case 13:u.push([x(),P()]);break;case 3:case 12:u.push([T(),P()]);break;case 4:case 11:u.push([P(),M()]);break;case 6:case 9:u.push([x(),M()]);break;case 7:case 8:u.push([T(),M()]);break;case 5:S?u.push([T(),M()],[x(),P()]):u.push([T(),x()],[P(),M()]);break;case 10:S?u.push([T(),x()],[P(),M()]):u.push([T(),M()],[x(),P()]);break}}const d=kb(u);return e.smooth===!1?d:d.map(f=>O0(O0(f)))}function kb(t){const e=o=>`${Math.round(o.x*1e3)},${Math.round(o.y*1e3)}`,n=new Map;t.forEach(([o,r],a)=>{for(const l of[o,r]){const c=e(l);n.has(c)||n.set(c,[]),n.get(c).push(a)}});const s=new Array(t.length).fill(!1),i=[];for(let o=0;o<t.length;o++){if(s[o])continue;s[o]=!0;const r=[t[o][0],t[o][1]];let a=t[o][1];for(;;){const l=(n.get(e(a))??[]).find(u=>!s[u]);if(l===void 0)break;s[l]=!0;const[c,h]=t[l];if(a=e(c)===e(a)?h:c,e(a)===e(r[0]))break;r.push(a)}r.length>=3&&i.push(r)}return i}function O0(t){const e=[];for(let n=0;n<t.length;n++){const s=t[n],i=t[(n+1)%t.length];e.push({x:s.x*.75+i.x*.25,y:s.y*.75+i.y*.25},{x:s.x*.25+i.x*.75,y:s.y*.25+i.y*.75})}return e}function vb(t){const e=Math.min(1,Math.max(0,t.progress));if(e<=0)return[];const n=t.width/2,s=n*(.55+.75*e),i=Math.max(t.length*e,s*1.2),o=t.x,r=t.y+i-s,a=Math.max(.1,n*(.35-.3*e)),l=r-Math.sqrt(Math.max(0,s*s-a*a)),c=Math.max(0,l-t.y),h=8,u=[],d=[];for(let v=0;v<=h;v++){const k=v/h,y=a+(n-a)*Math.pow(1-k,1.6+1.4*e);u.push({x:o-y,y:t.y+c*k}),d.push({x:o+y,y:t.y+c*k})}const f=Math.max(8,Math.round(t.segments??12)),p=Math.acos(Math.min(1,a/s)),g=-p,m=Math.PI+p,w=[];for(let v=1;v<f;v++){const k=g+(m-g)*v/f;w.push({x:o+Math.cos(k)*s,y:r+Math.sin(k)*s})}return[...d,...w,...u.reverse()]}function Mb(t){const e=Math.min(1,Math.max(0,t.grow??1)),n=e>=1?1:1-Math.pow(1-e,3)+.08*Math.sin(e*Math.PI)*e,s=t.r*Math.max(0,n);if(s<=0)return[];const i=Math.max(12,Math.round(t.segments??48)),o=t.wobble??.05,r=t.time??0,a=t.period?r/t.period:r/2500,l=(a-Math.floor(a))*Math.PI*2,c=t.seed??0,h=[];for(let u=0;u<i;u++){const d=u/i*Math.PI*2,f=1+o*(Math.sin(2*d+l+c)*.6+Math.sin(3*d-2*l+c*1.7)*.4);h.push({x:t.x+Math.cos(d)*s*f,y:t.y+Math.sin(d)*s*f})}return h}function Sb(t){const e=t.progress;if(e<=0||e>=1)return[];const n=Math.max(3,Math.round(t.pieces??8)),s=[],i=t.r*(1+1.2*e),o=Math.PI*2/n*.6*(1-e);for(let r=0;r<n;r++){const a=r/n*Math.PI*2+.3,l=[];for(let c=0;c<=4;c++){const h=a-o/2+o*c/4;l.push({x:t.x+Math.cos(h)*i,y:t.y+Math.sin(h)*i})}s.push(l)}return s}function xb(t,e={}){const n=Math.max(.05,1+t);return{sx:e.keep==="volume"?1/Math.sqrt(n):1/n,sy:n}}function Tb(t,e,n={x:0,y:0}){return t.map(s=>({x:n.x+(s.x-n.x)*e.sx,y:n.y+(s.y-n.y)*e.sy}))}function Ys(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function se(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function fn(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function Ae(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Ks(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 no(t){return Math.hypot(t[0],t[1],t[2])}function Xs(t,e){return no(se(t,e))}function Jt(t){const e=no(t);return e===0?[0,0,0]:fn(t,1/e)}function gn(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 Eb=Object.freeze(Object.defineProperty({__proto__:null,add:Ys,cross:Ks,distance:Xs,dot:Ae,length:no,lerp:gn,normalize:Jt,scale:fn,subtract:se},Symbol.toStringTag,{value:"Module"})),Ab=Math.PI/180;function so(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function Rt(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 pn(t){return[1,0,0,0,0,1,0,0,0,0,1,0,t[0],t[1],t[2],1]}function mn(t){return[t[0],0,0,0,0,t[1],0,0,0,0,t[2],0,0,0,0,1]}function pe(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 wa(t,e,n){const s=pe(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 $b(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 ka(t){const[e,n,s,i,o,r,a,l,c,h,u,d,f,p,g,m]=t,w=e*r-n*o,v=e*a-s*o,k=e*l-i*o,y=n*a-s*r,x=n*l-i*r,P=s*l-i*a,M=c*p-h*f,T=c*g-u*f,S=c*m-d*f,E=h*g-u*p,$=h*m-d*p,A=u*m-d*g,I=w*A-v*$+k*E+y*S-x*T+P*M;if(Math.abs(I)<1e-12)return null;const C=1/I;return[(r*A-a*$+l*E)*C,(s*$-n*A-i*E)*C,(p*P-g*x+m*y)*C,(u*x-h*P-d*y)*C,(a*S-o*A-l*T)*C,(e*A-s*S+i*T)*C,(g*k-f*P-m*v)*C,(c*P-u*k+d*v)*C,(o*$-r*S+l*M)*C,(n*S-e*$-i*M)*C,(f*x-p*k+m*w)*C,(h*k-c*x-d*w)*C,(r*T-o*E-a*M)*C,(e*E-n*T+s*M)*C,(p*v-f*y-g*w)*C,(c*y-h*v+u*w)*C]}function Pb(t,e,n,s){const i=1/Math.tan(t*Ab/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 Ib(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 Ob(t,e,n=[0,1,0]){const s=Jt(se(t,e)),i=Jt(Ks(n,s)),o=Ks(s,i);return[i[0],o[0],s[0],0,i[1],o[1],s[1],0,i[2],o[2],s[2],0,-Ae(i,t),-Ae(o,t),-Ae(s,t),1]}function ie(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 _b=Object.freeze(Object.defineProperty({__proto__:null,compose:wa,fromQuat:pe,identity:so,invert:ka,lookAt:Ob,multiply:Rt,orthographic:Ib,perspective:Pb,scaling:mn,transformPoint:ie,translation:pn,transpose:$b},Symbol.toStringTag,{value:"Module"})),io={"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]},_0={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 Cb(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}Wt({type:"bounce",mode:"in"}),Wt({type:"bounce",mode:"in-out"});function Gs(t){const e=C0.get(t.trim().toLowerCase());if(e)return e;const n=Cb(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:Wt(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 io)return{easing:{type:"cubic-bezier",points:io[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:Wt(h)}}return n in _0?{easing:_0[n]}:n in io?{easing:{type:"cubic-bezier",points:io[n]}}:{easing:"ease-out"}}const C0=new Map;function va(t,e){return C0.set(t.trim().toLowerCase(),e.bezier?{easing:{type:"cubic-bezier",points:e.bezier},fn:e.fn}:{fn:e.fn,requiresBaking:"custom"}),t}function Ma(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 H0=/^\s*random\(\s*(\[.*\]|[^)]*)\s*\)\s*$/;function R0(t){return typeof t=="string"&&H0.test(t)}function Hb(t=1){let e=Ma(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 L0(l,c,1/0);if("values"in l)return L0(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]=Ds(l[d])(l[d],c[d],h);return u}return Ds(l)(l,c,h)}),wrap:((l,c,h)=>{if(Array.isArray(l)){const g=l,m=w=>g[(Math.round(w)%g.length+g.length)%g.length];return c===void 0?m:m(c)}const u=l,f=c-u,p=g=>f===0?u:((g-u)%f+f)%f+u;return h===void 0?p:p(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,p,g)=>{const m=g.length,v=zi(f,m,{...c!==void 0?{amount:c}:{each:h??1},from:u}),k=c!==void 0?c:(h??1)*qr(m,u),y=d&&k>0?d(v/k)*k:v;return l+y},pipe:(...l)=>c=>l.reduce((h,u)=>u(h),c),splitColor:l=>Rb(l),getUnit:l=>typeof l=="number"?"":/^-?[\d.]+(?:e[-+]?\d+)?([a-z%]*)$/i.exec(l.trim())?.[1]??"",seed:l=>{e=Ma(l)},resolveRandomString:l=>{const c=H0.exec(l)?.[1]??"";if(c.startsWith("[")){const p=c.slice(1,-1).split(",").map(g=>g.trim()).filter(Boolean).map(g=>Number.isFinite(Number(g))?Number(g):g.replace(/^['"]|['"]$/g,""));return p[Math.floor(e()*p.length)]}const[h,u,d]=c.split(",").map(f=>Number.parseFloat(f));return r(h,u,Number.isFinite(d)?d:void 0)}}}function L0(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 Rb(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 Lb=/^([+-])=\s*(-?[\d.]+)$/,Fb=/^([<>])\s*(?:([+-])?=?\s*(-?[\d.]+))?$/;function Us(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=Lb.exec(i);if(o){const c=s(o[2]);return e.cursor+(o[1]==="-"?-c:c)}const r=Fb.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 Nb(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 Wb(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=p=>({x:p%s,y:Math.floor(p/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=p=>{const{x:g,y:m}=o(p),w=Math.abs(g-a.x),v=Math.abs(m-a.y);return e.axis==="x"?w:e.axis==="y"?v:Math.hypot(w,v)};let c=Array.from({length:t},(p,g)=>l(g));const h=Math.max(...c);if(r==="edges"&&(c=c.map(p=>h-p)),r==="random"){const p=n.random??Math.random;c=c.map(()=>p()*h)}const u=e.amount!==void 0?e.amount:(e.each??0)*h,d=e.ease?Gs(e.ease):void 0,f=d?d.fn??Wt(d.easing):void 0;return c.map(p=>{const g=h===0?0:p/h;return(f?f(g):g)*u})}const Sa=new Set(["duration","delay","ease","repeat","repeatDelay","yoyo","stagger","onComplete","onUpdate","onStart","onRepeat","onReverseComplete","repeatRefresh","keyframes","easeEach","scrollTo","id","immediateRender","overwrite","paused","scrollTrigger","spring"]),Db={rotation:"rotate",rotationZ:"rotate",rotationX:"rotateX",rotationY:"rotateY",transformPerspective:"perspective",perspective:"childPerspective"};function oo(t){const e={},n={};for(const[s,i]of Object.entries(t))Sa.has(s)?e[s]=i:n[Db[s]??s]=i;return{config:e,properties:n}}function ro(t,e){return t===void 0?e:t*1e3}function xa(t,e){if(t!==void 0)return typeof t=="number"?{each:t*1e3}:Nb(t)?{offsets:Wb(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 Bb={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 F0(t){return Bb[t]}function zb(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=T0(e.path,{curviness:e.curviness});else if(Bn(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 qb(t){const e=typeof t=="string"||Array.isArray(t)?{path:t}:{...t};return{...e,start:e.end??1,end:e.start??0}}function N0(t){return typeof t=="object"&&t!==null&&"shape"in t?t.shape:t}function jb(t){if(t.morphSVG===void 0)return t;const{morphSVG:e,...n}=t,s=N0(e);if(typeof s!="string"||!Bn(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 Yb(t,e){if(t===!0)return[0,e];if(t===!1)return[0,0];if(typeof t=="number")return[0,W0(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 W0(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 Kb(t,e){const[n,s]=Yb(t,e);return{strokeDasharray:[s-n,e],strokeDashoffset:-n}}function Xb(t,e){if(t.drawSVG===void 0)return t;const{drawSVG:n,...s}=t;return{...s,...Kb(n,e)}}function Gb(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 W0(t,e){return Math.max(0,Math.min(e,t))}function Ub(t){let e=2166136261;for(let n=0;n<t.length;n++)e=Math.imul(e^t.charCodeAt(n),16777619);return e>>>0}function Vb(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??Ub(`${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 Ta(t){return Math.max(.1,t/25)}function Jb(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?Ta(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(Rs(i))]:n.end!==void 0&&(i.end=Array.isArray(n.end)?[...n.end]:n.end),i}function Zb(t){const e=t===!0?{}:typeof t=="string"?{preset:t}:t;if(e.preset!==void 0&&!(e.preset in Yi))throw new Error(`gsap-compat: unknown spring preset "${e.preset}" — use one of ${Object.keys(Yi).join(", ")}`);return{...e.preset?Yi[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 Qb(t,e){if(t===!0||typeof t=="string")return;const n=t.velocity;return typeof n=="number"?n:n?.[e]}class yn{timeline;options;cursor=0;fallbackRandom=Ma(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,Vs(n),s)}from(e,n,s){const{config:i,properties:o}=oo(Vs(n)),{motionPath:r,text:a,scrambleText:l,...c}=o,h=this.targetsOf(e)[0],u={...i};for(const p of Object.keys(c))u[p]=this.resolveStart(h,p);r!==void 0&&(u.motionPath=qb(r));const d={},f=String(this.resolveStart(h,"text"));return a!==void 0&&(d.text=Ea(a),u.text=typeof a=="object"?{...a,value:f}:f),l!==void 0&&(d.text=Ea(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}=oo(Vs(n));return this.build(e,o,Vs(s),i)}set(e,n,s){return this.build(e,void 0,{...Vs(n),duration:0},s)}get lastStart(){return this.previousStart}get lastEnd(){return this.previousEnd}addEvent(e){const n=Math.max(0,Us(e,this.context()));return this.previousStart=n,this.previousEnd=n,this.cursor=Math.max(this.cursor,n),n}timeOf(e){return Us(e,this.context())}addLabel(e,n){return this.labels.set(e,Us(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=Us(n,this.context());for(const o of e.timeline.tracks){if(!("keyframes"in o))continue;const r=Ji({...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}=oo(s),{motionPath:a,text:l,scrambleText:c,inertia:h,...u}=r,d=this.targetsOf(e),f=Us(i,this.context()),p=ro(o.delay,0),g=ro(o.duration,500),m=xa(o.stagger,{count:d.length,columnsFromLayout:this.options.layoutColumns?()=>this.options.layoutColumns(d):void 0,random:this.options.random??this.fallbackRandom}),w=this.easingFor(o.ease),v=[],k=o.spring;let y=0,x=!1;for(const[$,A]of Object.entries(u)){const I=A;let C=n?.[$]!==void 0?n[$]:this.resolveStart(d[0],$);if(typeof C!=typeof I&&(this.warn(`no usable start value for "${$}" on "${d[0]}" — it will snap to ${String(I)}. Use fromTo() to animate it.`),C=I),k!==void 0&&(typeof C!="number"||typeof I!="number")&&this.warn(`spring works on numbers, so "${$}" on "${d[0]}" eases instead`),k!==void 0&&typeof C=="number"&&typeof I=="number"){const V={...Zb(k),from:C,to:I,velocity:Qb(k,$)??this.options.startVelocity?.(d[0],$)??0},et=this.nextTrackId(`${d[0]}-${$}-spring`),G={id:et,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:$,kind:"spring",spring:V,delay:f+p};this.timeline.addTrack(G),v.push(et),y=Math.max(y,bh(V));for(const F of d)this.lastValues.set(`${F}|${$}`,I);continue}x=!0;const D=this.keyframesFor(C,I,g,w,o.ease),j=this.nextTrackId(`${d[0]}-${$}`);this.timeline.addTrack(Ji({id:j,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:$,delay:f+p,keyframes:D,...$==="quaternion"&&{interpolation:"slerp"}})),v.push(j);for(const V of d)this.lastValues.set(`${V}|${$}`,I)}const P=Vb({text:l,scrambleText:c},d[0],g);if(P){const $=n?.text??n?.scrambleText,A=$!==void 0?Ea($):this.resolveStart(d[0],"text"),I=this.nextTrackId(`${d[0]}-text`),C={id:I,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:"text",textConfig:{from:typeof A=="string"?A:String(A??""),...P},delay:f+p,keyframes:this.keyframesFor(0,1,g,w,o.ease)};this.timeline.addTrack(C),v.push(I);for(const D of d)this.lastValues.set(`${D}|text`,P.to)}if(a!==void 0){const{config:$,start:A,end:I}=zb(a),C=this.nextTrackId(`${d[0]}-motionPath`),D={id:C,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:"motionPath",motionPathConfig:$,delay:f+p,keyframes:this.keyframesFor(A,I,g,w,o.ease)};this.timeline.addTrack(D),v.push(C)}if(h!==void 0)for(const[$,A]of Object.entries(h)){const I=this.resolveStart(d[0],$);if(typeof I!="number"){this.warn(`inertia on "${$}" needs a numeric start value; skipped`);continue}const C=Jb(I,A),D=this.nextTrackId(`${d[0]}-${$}-inertia`),j={id:D,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:$,kind:"inertia",inertia:C,delay:f+p};this.timeline.addTrack(j),v.push(D),y=Math.max(y,Wn(C));for(const V of d)this.lastValues.set(`${V}|${$}`,Nn(C))}const S=((h!==void 0||k!==void 0)&&!x&&!P&&a===void 0?y:Math.max(g,y))+(m&&d.length>1?Cs(d.length,m):0),E=f+p+S;return this.previousStart=f+p,this.previousEnd=E,this.cursor=Math.max(this.cursor,E),{trackIds:v,start:f+p,end:E,kill:()=>{for(const $ of v)this.timeline.removeTrack($)}}}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"?Gs(o):void 0;if(a?.requiresBaking==="custom"||this.options.bakeEases&&_s(i)){const c=a?.fn??Wt(i);return[r,...ra(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=F0(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 Gs(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 Ea(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 tw(t){return new yn(t)}function Vs(t){return Gb(jb(t))}function ew(t){return!Array.isArray(t)||t.length!==4?null:`matrix3d(${pe(ze(t)).map(n=>Math.round(n*1e6)/1e6+0).join(", ")})`}const nw=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),sw="#ffffff",iw="rgba(0, 0, 0, 0.5)";function ow(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??sw})`),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??iw})`)}return e.length>0?e.join(" "):null}function rw(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 aw(t){if(!("ownerSVGElement"in t))return;const e=t.style;!e||e.transformBox||(e.transformBox="fill-box",e.transformOrigin||(e.transformOrigin="50% 50%"))}const D0=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"]),lw=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),cw=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],hw=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),uw=new Set(["originX","originY"]),dw=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),fw=new Set(["drawOn"]),gw={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},B0={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},pw="http://www.w3.org/2000/svg";class bn{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[p,g]of n)if(!(p==="x"&&l)&&!(p==="y"&&c)&&!((p==="rotate"||p==="rotateZ")&&h)&&!fw.has(p)){if(lw.has(p))(s??={})[p]=g;else if(hw.has(p))typeof g=="number"&&((i??={})[p]=g);else if(uw.has(p))typeof g=="number"&&((o??={})[p]=g);else if(dw.has(p))typeof g=="number"&&((r??={})[p]=g);else if(nw.has(p))(a??={})[p]=g;else if(p!=="perspective"){if(p!=="shine")if(p==="text"&&typeof g=="string")rw(e,g);else if(p==="d"&&typeof g=="string"){const m=e;(m.tagName?.toLowerCase()==="path"?m:m.querySelector?.("path"))?.setAttribute?.("d",g)}else this.applyStyleProperty(e,p,g)}}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 p of cw){const g=s[p];if(g===void 0)continue;const m=this.buildTransformPart(p,g);m&&d.push(m)}if(d.length>0&&(e.style.transform=d.join(" "),aw(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 p=o.originX??50,g=o.originY??50;e.style.transformOrigin=`${p}% ${g}%`}if(r){const p=r.clipTop??0,g=r.clipRight??0,m=r.clipBottom??0,w=r.clipLeft??0;e.style.clipPath=`inset(${p}% ${g}% ${m}% ${w}%)`}if(a){const p=ow(a);p&&(e.style.filter=p)}}buildTransformPart(e,n){if(e==="quaternion")return ew(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===pw&&n in B0){const a=Array.isArray(s)?s.join(", "):String(s);e.style[B0[n]]=a;return}else n==="fill"&&e.dataset?.elementType==="text"?i="color":i=gw[n]??n;let r;typeof s=="number"?D0.has(n)||D0.has(i)?r=`${s}px`:r=String(s):Array.isArray(s)?r=s.join(", "):r=s,e.style[i]=r}}const mw={request:t=>requestAnimationFrame(t),cancel:t=>cancelAnimationFrame(t)};class z0{adapter=new bn;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=Hb();active=new Map;applied=new Map;dirty=new Set;frameId=null;lastTimestamp=null;destroyed=!1;constructor(e={}){this.scheduler=e.scheduler??mw,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);Aa(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(Aa(e))return[e];if(!yw(e))return[e];const n=[];for(const s of Array.from(e))n.push(...this.targetsOf(s));return n}nameFor(e){return Aa(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 Aa(t){return typeof t=="object"&&t!==null&&t.nodeType===1}function yw(t){if(Array.isArray(t))return!0;const e=t;return typeof e.length=="number"&&typeof e.item=="function"}function ao(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 q0=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function bw(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function ww(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 kw(t,e){const n=typeof t=="string"||Array.isArray(t)||q0(t)?{path:t}:t,{align:s,alignOrigin:i,path:o,...r}=n,a=P=>{const M=q0(P)?P:e.query(P);return M||e.warn(`gsap-compat: motionPath could not find "${String(P)}"`),M};let l=null,c="";if(Array.isArray(o)||typeof o=="string"&&Bn(o))c=o;else{l=a(o);const P=l&&Qi({tag:l.localName,attributes:bw(l)});l&&!P&&e.warn(`gsap-compat: motionPath element <${l.localName}> has no path geometry`),c=P??""}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,p,g,m,w,v]=ww(u),k=ao(d),[y,x]=i??[.5,.5];for(const P of e.targets.slice(1)){const M=ao(P);if(Math.abs(M.left-k.left)>.5||Math.abs(M.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,p,g,m,w-k.left-y*k.width,v-k.top-x*k.height],h}const j0=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function Y0(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function K0(t){if(!t)return null;const e=Qi({tag:t.localName,attributes:Y0(t)});return e||(t.querySelector("path")?.getAttribute("d")??null)}function vw(t,e,n){const s=N0(t);if(typeof s=="string"&&Bn(s))return s;const i=j0(s)?s:typeof s=="string"?e(s):null,o=K0(i);return o||(n(`gsap-compat: morphSVG could not find a shape for "${String(s)}"`),"")}const Mw=new Set(["cx","cy","r","rx","ry","x","y","width","height","x1","y1","x2","y2","points"]);function Sw(t,e=document){return(typeof t=="string"?Array.from(e.querySelectorAll(t)):j0(t)?[t]:Array.from(t)).map(s=>{if(s.localName==="path")return s;const i=Qi({tag:s.localName,attributes:Y0(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))Mw.has(r.name)||o.setAttribute(r.name,r.value);return o.setAttribute("d",i),s.parentNode.replaceChild(o,s),o})}const X0=.3;class G0{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=U0(),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=U0(),i=Math.max(1,s-this.lastTime);this.lastTime=s;const o=e/i*1e3,r=n/i*1e3;this.velocityX+=(o-this.velocityX)*X0,this.velocityY+=(r-this.velocityY)*X0}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 U0(){return typeof performance<"u"?performance.now():Date.now()}function V0(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 J0(t,e){return e<=0?[]:t.map(n=>Math.round(n/e)*e)}class $a{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 G0({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=xw(i/s);e.pause(),e.seek(o*n)}applyConstraints(e,n){let s=e;const i=[...J0([s],this.options.snap??0),...(n==="x"?this.options.snapLinesX:this.options.snapLinesY)??[]],o=V0([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 xw(t){return t<0?0:t>1?1:t}function Tw(t){const e=new $a(t);return e.start(),e}const Ew={x:"x",y:"y","x,y":"both"},Pa=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function Z0(t,e){const n=ao(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 Q0(t){return Array.isArray(t)?[...t]:t}function Aw(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 $w(t,e,i,o,s);const r=Ew[s.type??"x,y"],a=()=>{const g=e.appliedValue(i,"x"),m=e.appliedValue(i,"y");return{x:typeof g=="number"?g:0,y:typeof m=="number"?m:0}},l=typeof s.bounds=="string"?e.query(s.bounds):Pa(s.bounds)?s.bounds:null,h={bounds:(!l&&s.bounds&&!Pa(s.bounds)?s.bounds:void 0)??(l?Z0(o,l):void 0)};let u=null;const d=()=>{u?.kill(),u=null},f=g=>{const m=s.inertia===!0?{}:s.inertia,w=m.friction??(m.resistance!==void 0?Ta(m.resistance):4),v=a(),k=h.bounds??{};let y,x;const P=m.end;if(Array.isArray(P)){const T=Rs({from:v.x,velocity:r==="y"?0:g.x,friction:w}),S=Rs({from:v.y,velocity:r==="x"?0:g.y,friction:w});let E=P[0];for(const $ of P)Math.hypot($.x-T,$.y-S)<Math.hypot(E.x-T,E.y-S)&&(E=$);E&&(y=[E.x],x=[E.y])}else typeof P=="number"?(y=P,x=P):P&&(y=Q0(P.x),x=Q0(P.y));const M={};r!=="y"&&(M.x={velocity:g.x,friction:w,min:k.minX,max:k.maxX,end:y}),r!=="x"&&(M.y={velocity:g.y,friction:w,min:k.minY,max:k.maxY,end:x}),u=t.to(o,{inertia:M,onComplete:()=>s.onThrowComplete?.()})},p=new $a({target:o,axis:r,snap:s.snap,get bounds(){return h.bounds},getPosition:a,onPress:()=>{d(),l&&(h.bounds=Z0(o,l)),s.onPress?.()},onDrag:g=>{e.apply(i,r==="x"?{x:g.x}:r==="y"?{y:g.y}:{x:g.x,y:g.y}),s.onDrag?.(g)},onRelease:()=>{const g=p.velocity;s.onRelease?.(g),s.inertia&&f(g)}});return p.start(),{draggable:p,get position(){return a()},get rotation(){const g=e.appliedValue(i,"rotate");return typeof g=="number"?g:0},destroy(){d(),p.destroy()}}}function $w(t,e,n,s,i){const o=typeof i.bounds=="object"&&i.bounds!==null&&!Pa(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,u={x:0,y:0},d=0,f=0,p=[];const g=k=>Math.atan2(k.clientY-u.y,k.clientX-u.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();u={x:y.left+y.width/2,y:y.top+y.height/2},d=g(k),f=r(),p=[{time:performance.now(),rotation:f}],i.onPress?.()},w=k=>{if(!c||k.pointerId!==h)return;const y=g(k);let x=y-d;x>180&&(x-=360),x<-180&&(x+=360),d=y,f+=x;let P=a(f);i.snap&&(P=a(Math.round(P/i.snap)*i.snap)),e.apply(n,{rotate:P});const M=performance.now();for(p.push({time:M,rotation:P});p.length>2&&M-p[0].time>100;)p.shift();const T={x:0,y:0};i.onDrag?.(T)},v=k=>{if(!c||k.pointerId!==h)return;c=!1;const y=p[0],x=p[p.length-1],P=y&&x?(x.time-y.time)/1e3:0,M=P>0?(x.rotation-y.rotation)/P:0;if(i.onRelease?.({x:M,y:0}),!i.inertia)return;const T=i.inertia===!0?{}:i.inertia,S=T.friction??(T.resistance!==void 0?Ta(T.resistance):4),E=typeof T.end=="number"||Array.isArray(T.end)?T.end:void 0;l=t.to(s,{inertia:{rotate:{velocity:M,friction:S,min:o.minRotation,max:o.maxRotation,end:Array.isArray(E)?E.filter($=>typeof $=="number"):E}},onComplete:()=>i.onThrowComplete?.()})};return s.addEventListener("pointerdown",m),s.addEventListener("pointermove",w),s.addEventListener("pointerup",v),s.addEventListener("pointercancel",v),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",w),s.removeEventListener("pointerup",v),s.removeEventListener("pointercancel",v)}}}const Pw={opacity:0,scale:.6};function Iw(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 tu(t){const e=ao(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 Ia(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=Iw(r);i.set(r,a);const l=eu(r);a&&l!==void 0&&!o.has(l)&&o.set(l,{element:r,box:a})}return{elements:s,boxes:i,ids:o}}const Oa=new WeakMap;function _a(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?Pw:s.enter,c=new Set(n.elements);if(s.targets!==void 0)for(const f of t.resolveTargets(s.targets)){const p=t.elementFor(f);p&&c.add(p)}const h=[...c].sort((f,p)=>f===p?0:f.compareDocumentPosition(p)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1),u=e({onComplete:s.onComplete});let d=0;for(const f of h){const p=tu(f);if(!p)continue;let g=n.boxes.get(f)??null,m;const w=eu(f),v=!g&&w!==void 0?n.ids.get(w):void 0;v&&v.element!==f&&(g=v.box,m=v.element);const[k]=t.resolveTargets(f);Oa.get(f)?.timeline.removeTracks({target:k});const y=d*r;if(!g){if(l===!1)continue;u.fromTo(f,{x:0,y:0,scaleX:1,scaleY:1,...l},{...nu(l),x:0,y:0,scaleX:1,scaleY:1,duration:i,ease:o,delay:y},0),Oa.set(f,u),d++;continue}const x=g.cx-p.cx,P=g.cy-p.cy,M=a?g.width/p.width:1,T=a?g.height/p.height:1;if(!(Math.abs(x)>.5||Math.abs(P)>.5||Math.abs(M-1)>.001||Math.abs(T-1)>.001)){const $=(A,I)=>{const C=t.appliedValue(k,A);return typeof C=="number"&&Math.abs(C-I)>1e-6};($("x",0)||$("y",0)||$("scaleX",1)||$("scaleY",1))&&u.set(f,{x:0,y:0,scaleX:1,scaleY:1},0);continue}const E=s.fade===!0&&m!==void 0;u.fromTo(f,{x,y:P,scaleX:M,scaleY:T,...E&&{opacity:0}},{x:0,y:0,scaleX:1,scaleY:1,...E&&{opacity:1},duration:i,ease:o,delay:y},0),E&&m&&tu(m)&&u.fromTo(m,{opacity:1},{opacity:0,duration:i,ease:o,delay:y},0),Oa.set(f,u),d++}return u}function eu(t){return t.dataset?.flipId}function nu(t){const e={};for(const n of Object.keys(t))e[n]=n==="opacity"||n.startsWith("scale")?1:0;return e}function Ow(t,e={}){const n=new Set((e.type??"chars,words,lines").split(",").map(g=>g.trim())),s={chars:e.charsClass??"char",words:e.wordsClass??"word",lines:e.linesClass??"line"},i=e.aria!==!1,o=t.map(g=>({element:g,html:g.innerHTML,ariaLabel:g.getAttribute("aria-label")}));let r={chars:[],words:[],lines:[],masks:[]},a,l,c=!1;const h=()=>{for(const{element:g,html:m,ariaLabel:w}of o)g.innerHTML=m,w===null?g.removeAttribute("aria-label"):g.setAttribute("aria-label",w)},u=()=>{a&&(a.revert?a.revert():a.kill?.(),a=void 0)},d=()=>{const g={chars:[],words:[],lines:[],masks:[]};for(const{element:m}of o){const w=(m.textContent??"").replace(/\s+/g," ").trim(),v=_w(m,s.words),k=n.has("chars")?v.flatMap(P=>Cw(P,s.chars)):[],y=n.has("lines")?Rw(m,v,s.lines):[];if(i){!m.hasAttribute("aria-label")&&w&&m.setAttribute("aria-label",w);for(const P of v)P.setAttribute("aria-hidden","true")}if(n.has("words"))g.words.push(...v);else for(const P of v)P.removeAttribute("class");g.chars.push(...k),g.lines.push(...y);const x=e.mask==="lines"?y:e.mask==="words"?v:e.mask==="chars"?k:[];for(const P of x)g.masks.push(Lw(P,`${s[e.mask]}-mask`))}r=g},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&&p();function p(){const g=new Map;let m=!1;const w=()=>{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 x of k){const P=Math.round(x.contentRect.width),M=g.get(x.target);g.set(x.target,P),M!==void 0&&M!==P&&(y=!0)}y&&w()});for(const k of t)l.observe(k)}const v=t[0]?.ownerDocument?.fonts;v&&v.status!=="loaded"&&v.ready.then(()=>w())}return f}function _w(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 Cw(t,e){const n=t.ownerDocument,s=Hw(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 Hw(t){const e=Intl.Segmenter;return e?Array.from(new e(void 0,{granularity:"grapheme"}).segment(t),n=>n.segment):Array.from(t)}function Rw(t,e,n){const s=t.ownerDocument,i=new Map(e.map(p=>[p,p.getBoundingClientRect()])),o=[],r=p=>{for(const g of Array.from(p.childNodes))g.nodeType===3||i.has(g)||g.tagName==="BR"?o.push(g):r(g)};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 p of o){if(p.tagName==="BR"){u=!0;continue}const g=i.get(p);if(g&&(!l||u||g.top>c+h)&&(f(),c=g.top,h=g.height/2,u=!1),!l)continue;const m=[];for(let k=p.parentNode;k&&k!==t;k=k.parentNode)m.unshift(k);let w=0;for(;w<d.length&&w<m.length&&d[w].original===m[w];)w++;d.length=w;let v=w===0?l:d[w-1].clone;for(const k of m.slice(w)){const y=k.cloneNode(!1);v.appendChild(y),d.push({original:k,clone:y}),v=y}v.appendChild(p)}return t.replaceChildren(...a),a}function Lw(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 su={top:0,left:0,start:0,center:.5,centre:.5,middle:.5,bottom:1,right:1,end:1};function Ca(t){const e=t.trim().toLowerCase();if(e in su)return su[e];if(e.endsWith("%")){const n=Number.parseFloat(e.slice(0,-1));return Number.isNaN(n)?void 0:n/100}}function Ha(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?Ca(s[0]):void 0,o=s[1]!==void 0?Ca(s[1]):void 0;return{elementFraction:i??0,viewportFraction:o??0,offsetPx:e}}function Kn(t,e,n){const s=Ha(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 Fw(t,e,n,s){const i=Kn(t,e,n),r=Kn(t,e,s)-i;return r<=0?i<=0?1:0:Ra(-i/r)}function Ra(t){return t<0?0:t>1?1:t===0?0:t}function iu(t,e,n,s){if(n<=0)return e;const i=1-Math.exp(-(s/1e3)/n);return t+(e-t)*i}function La(t,e,n,s,i){const o=h=>Kn({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 ou{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 Nw(t){const e=new ou(t);return e.start(),e}class ru{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 Ww=.15;function au(t){return typeof t=="object"&&!Array.isArray(t)?t:{snapTo:t}}function lu(t,e,n){const s=lo(t+e*Ww);if(typeof n=="function")return lo(n(s));if(typeof n=="number")return n<=0?t:lo(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 lo(i)}function cu(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 hu{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=Ls,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 lo(t){return Math.max(0,Math.min(1,t))}class uu{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 Dw=120,Xn=[],Gn=new Set;let Fa=!1;const Bw=()=>{Fa||Gn.size===0||(Fa=!0,queueMicrotask(()=>{Fa=!1;for(const t of Gn)t.afterRefresh()}))},du=()=>{for(const t of Gn)t.beforeRefresh();for(const t of Xn)t.refresh();for(const t of Gn)t.afterRefresh()};let Un={width:0,height:0};const fu=()=>{const t=window.innerWidth,e=window.innerHeight,n=t===Un.width&&e!==Un.height,s=Math.abs(e-Un.height)<Un.height*.25,i=typeof navigator<"u"&&(navigator.maxTouchPoints??0)>0;n&&s&&i||(Un={width:t,height:e},du())};class Js{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 hu(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 ru(e,{axis:this.options.horizontal?"x":"y",spacing:this.options.pinSpacing!==!1})),this.options.markers&&!this.options.horizontal&&typeof document<"u"&&(this.markers=new uu(document,this.options.scroller??null,this.options.markers)),this.scrollTarget()?.addEventListener("scroll",this.onScroll,{passive:!0}),Xn.length===0&&typeof window<"u"&&(Un={width:window.innerWidth,height:window.innerHeight},window.addEventListener("resize",fu,{passive:!0})),Xn.push(this),this.refresh()}stop(){this.running&&(this.running=!1,this.scrollTarget()?.removeEventListener("scroll",this.onScroll),Xn.splice(Xn.indexOf(this),1),Xn.length===0&&typeof window<"u"&&window.removeEventListener("resize",fu),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(){du()}static onRefresh(e){return Gn.add(e),()=>Gn.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+Kn(n,s,Zs(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,Bw()}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?Ra((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=Zs(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+Kn(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()},Dw))}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=au(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+lu(r,this.releaseVelocity/i,n.snapTo)*i;Math.abs(a-o)<1||this.snapper.animate(o,a,cu(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=La(r,s.width,o,Zs(this.options.start)??"left right",e.shiftAt);this.startPx=c(h);const u=Zs(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(La(r,s.width,o,u,e.shiftAt)),this.markerGeometry=null}markersFor(e){const n=(o,r)=>{const a=Zs(o)??r;if(typeof a=="number")return 0;if(/^\s*\+=/.test(a))return;const l=Ha(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=iu(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 Zs(t){return typeof t=="function"?t():t}function zw(t){const e=new Js(t);return e.start(),e}const Na=new Set,qw=16,gu=.5,jw=2;class Wa{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),Na.add(this),this.stopListening=Js.onRefresh({beforeRefresh:()=>this.rest(),afterRefresh:()=>this.refresh()}),this.refresh(),this}static refreshAll(){for(const e of Na)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),Na.delete(this),this.stopListening?.(),this.stopListening=null,this.cancelFrame(),this.journey=null,this}destroy(){this.stop();for(const e of this.effects)Da(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??Ls,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)Da(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?qw: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)<=jw||(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)<gu&&(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)<gu?i.lagged=s:n=!0,o+=s-i.lagged}Da(i.element,o===0?i.saved:`0 ${Yw(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 Da(t,e){e?t.style.setProperty("translate",e):t.style.removeProperty("translate")}function Yw(t){return Math.round(t*100)/100}function Kw(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 Ba(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,p)=>()=>{p?.(),n&&!a&&Kw(n,l[f]??"none"),e.once&&f===0&&queueMicrotask(()=>h.destroy())},d=e.containerAnimation?Uw(t,e.containerAnimation,r,i):void 0;return h=new Js({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:Xw(e.snap,n),markers:e.markers,container:d,onUpdate:(f,p)=>{if(n&&a!==!1&&n.progress(f),e.onUpdate){const g=f<c||p<0?-1:1;e.onUpdate({progress:f,velocity:p,direction:g})}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 Xw(t,e){const n=i=>i==="labels"?o=>Gw(o,e?.labelProgresses?.()??[]):i;if(typeof t!="object"||Array.isArray(t))return n(t);const s=t.ease?Gs(t.ease):void 0;return{snapTo:n(t.snapTo),duration:t.duration,delay:t.delay,ease:s?s.fn??Wt(s.easing):void 0}}function Gw(t,e){return e.reduce((n,s)=>Math.abs(s-t)<Math.abs(n-t)?s:n,e[0]??t)}function Uw(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 pu{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 Vw{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 pu(this.host,this.scope);o.conditions=n,o.add(()=>e.setup(o)),e.context=o}}class Jw{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 Zw={opacity:0,y:-16},Qw={opacity:0,y:16};async function t2(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 e2(o,s,r);const a=s.duration??.35,l=s.ease??"power2.inOut",c=m=>new Promise(w=>{m(w)||w()}),h=r(),u=h.length?Ia(e,h):void 0,d=s.from!==void 0?mu(e,s.from,s.shared):[];if(d.length&&s.leave!==!1){const m=s.leave??Zw;await c(w=>t.to(d,{...m,duration:a,ease:l,onComplete:w}))}await s.update();const f=[],p=typeof s.to=="function"?s.to():s.to,g=p!==void 0?mu(e,p,s.shared):[];if(g.length&&s.enter!==!1){const m=s.enter??Qw;f.push(c(w=>t.fromTo(g,m,{...nu(m),duration:a,ease:l,onComplete:w})))}if(u){const m=r().filter(w=>!h.includes(w));m.length&&f.push(c(w=>_a(e,n,u,{targets:m,duration:a*1.4,ease:l,enter:!1,onComplete:w})))}await Promise.all(f)}function mu(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 e2(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 yu={create:(t,e)=>va(t,m0(e))},bu={create:(t,e)=>va(t,{fn:y0(e)})},wu={create:(t,e)=>va(t,{fn:b0(e)})},n2=new Set(["keyframes","duration","delay","ease","easeEach","stagger","repeat","repeatDelay","yoyo","repeatRefresh","paused","id","onStart","onUpdate","onComplete","onRepeat","onReverseComplete","scrollTrigger"]),ku=.5,s2="power1.inOut";function i2(t){return t.keyframes!==void 0&&t.keyframes!==null}function o2(t){const e=t.keyframes,n={};for(const[c,h]of Object.entries(t))n2.has(c)||(n[c]=h);if(Array.isArray(e))return e.map(c=>({...n,...c,duration:c.duration??t.duration??ku}));const s=Object.entries(e),i=t.duration??ku,o=e.easeEach??t.easeEach??s2;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 p=Math.max(0,d-u);h.push({...n,ease:o,...f,duration:p*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 vu(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=(v,k)=>{if(k===void 0)return r[v];if(typeof k=="number")return k;if(k==="max")return a[v];const y=typeof k=="string"?i.querySelector(k):k;if(!y)return r[v];const x=y.getBoundingClientRect(),P=o?.getBoundingClientRect(),M=(v==="x"?s.offsetX:s.offsetY)??s.offset??0;return v==="x"?x.left-(P?.left??0)+r.x-M:x.top-(P?.top??0)+r.y-M},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"],p=o??window,g=()=>{w.kill(),m()},m=()=>{for(const v of f)p.removeEventListener(v,g)},w=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 v of f)p.addEventListener(v,g,{passive:!0});return w}function r2(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:[]},p={},g=w=>{p[w]!==void 0&&clearTimeout(p[w]),p[w]=void 0;const v=f[w].splice(0);v.length>0&&d[w]?.(v)},m=(w,v)=>{if(d[w]){if(f[w].push(v),r!==void 0&&f[w].length>=r)return g(w);p[w]===void 0&&(p[w]=setTimeout(()=>g(w),o*1e3))}};return i.map(w=>Ba(t,{...u,trigger:w,onEnter:()=>m("onEnter",w),onLeave:()=>m("onLeave",w),onEnterBack:()=>m("onEnterBack",w),onLeaveBack:()=>m("onLeaveBack",w)})).filter(w=>w!==void 0)}class Me{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 yn({...s,startValue:(i,o)=>{const r=e.objectFor(i);if(r)return c2(r[o]);const a=e.appliedValue(i,o);if(a!==void 0)return a;if(o==="d")return K0(e.elementFor(i))??void 0;if(o==="text")return e.elementFor(i)?.textContent??void 0;if(o==="strokeDasharray"||o==="strokeDashoffset"){const l=Eu(e.elementFor(i));if(l!==void 0)return o==="strokeDasharray"?[l,l]:0}},startVelocity:(i,o)=>e.velocityOf(i,o),layoutColumns:i=>Tu(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=Ba(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 i2(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 Me(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}=ca(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,p)=>{i(d,f,p),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=o2(n);if(o.length===0)return;const r=i.length>1?xa(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?qi(i.length,r).map(m=>m/1e3):[0],h=this.compat.timeOf(s)/1e3+ro(n.delay,0)/1e3;let u=1/0,d=-1/0;if(l.forEach((m,w)=>{o.forEach((v,k)=>{const y=k===0?h+c[w]:">";this.tween(m,[v],y,([x],P,M)=>this.compat.to(P,x,M)),u=Math.min(u,this.compat.lastStart),d=Math.max(d,this.compat.lastEnd)})}),u===1/0)return;const{onStart:f,onUpdate:p,onComplete:g}=n;f&&this.events.push({time:u,direction:"forward",run:f}),p&&this.ranges.push({start:u,end:d,run:p}),g&&this.events.push({time:d,direction:"forward",run:g})}staggerContext(e){return{count:e.length,columnsFromLayout:()=>Tu(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(l2)||e.some(d=>this.stage.objectFor(d)!==void 0)))){const d=this.targetFor(e[0]);i(n.map(f=>this.prepare(xu(f,0,d,this.stage.utils,o),e)),e,s);return}const a=n.length-1,{stagger:l,...c}=n[a],h=xa(l,this.staggerContext(e)),u=h?qi(e.length,h).map(d=>d/1e3):e.map(()=>0);e.forEach((d,f)=>{const p=f===0?ro(c.delay,0)/1e3+u[0]:0,g=f===0?0:u[f]-u[f-1],m=f===0?s:`<${g<0?"-":"+"}${Math.abs(g).toFixed(6)}`,v=n.map((k,y)=>y===a?{...c,delay:p}:k).map(k=>this.prepare(xu(k,f,this.targetFor(d),this.stage.utils,o),[d]));i(v,[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=kw(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=vw(e.morphSVG,i,s),{morphSVG:a,...l}=o;o=r?{...o,morphSVG:r}:l}if(e.drawSVG!==void 0){const r=Eu(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=Xb(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 ${h2(e)}`);return}return this.firstElement??=n.map(s=>this.stage.elementFor(s)).find(s=>s!==void 0),n}}function Mu(t=new z0){const e=o=>{const{config:r}=oo(o);return new Me(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)??F0(r)},scrollTrigger:o=>s(Ba(t,o)),scrollBatch:(o,r)=>r2(t,o,r).map(a=>s(a)),scrollTo:(o,r)=>vu(i,t,o,r),refreshScroll:()=>{Js.refreshAll(),Wa.refreshAll()},smoothScroll:(o={})=>{const r=typeof o.scroller=="string"?(t.collector?.scope??t.root).querySelector(o.scroller):o.scroller;return s(new Wa({...o,scroller:r}).start())},context:(o,r)=>{const a=new pu(t,r);return o&&a.add(()=>o(a)),a},matchMedia:o=>new Vw(t,o),customEase:yu.create,customBounce:bu.create,customWiggle:wu.create,pageTransition:o=>t2(i,t,r=>new Me(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 Jw(a,r))},quickTo:(o,r,a={})=>{const l=new Me(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:a2(a.spring,r,d)}}),l.timeline.stop(),l.timeline.play(),t.activate(l.timeline)},{tween:l,kill:()=>l.kill()})},timeline:o=>new Me(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 vu(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 Me(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=>Sw(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(Ow(l,r))},draggable:(o,r)=>s(Aw(i,t,o,r)),getFlipState:o=>Ia(t,o),flipFrom:(o,r)=>_a(t,a=>new Me(t,a),o,r),flip:(o,r,a)=>{const l=Ia(t,o);return r(),_a(t,c=>new Me(t,c),l,{targets:o,...a})}};return i}const oe=Mu();function a2(t,e,n){return t===!0?{velocity:{[e]:n}}:typeof t=="string"?{preset:t,velocity:{[e]:n}}:{...t,velocity:{[e]:n}}}function l2(t){return t.morphSVG!==void 0||t.drawSVG!==void 0||t.text!==void 0||t.scrambleText!==void 0||Su(t)}function Su(t){return Object.entries(t).some(([e,n])=>(typeof n=="function"||R0(n))&&!Sa.has(e))}function xu(t,e,n,s,i){if(!Su(t))return t;const o={};for(const[r,a]of Object.entries(t))Sa.has(r)?o[r]=a:typeof a=="function"?o[r]=a(e,n,i):R0(a)?o[r]=s.resolveRandomString(a):o[r]=a;return o}function Tu(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 Eu(t){const e=t;if(typeof e?.getTotalLength=="function")return e.getTotalLength()}function c2(t){if(typeof t=="number"||typeof t=="string"||Array.isArray(t)&&t.every(e=>typeof e=="number"))return t}function h2(t){return typeof t=="string"?`"${t}"`:String(t)}class za{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 Au(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 co{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 bn}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=jn({...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 za(s)})})}syncAllMedia(e,n){for(const s of this.mediaTargets)Au(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 bn;s.querySelectorAll("[data-tinyfly]").forEach(a=>{const l=a.getAttribute("data-tinyfly");l&&r.registerTarget(l,a)}),this.symbolInstances.push({adapter:r,timeline:jn(o.timeline)})})}attachMedia(e,n){this.mediaSync=new za(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}=ca(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 u2(t,e,n={}){const s=new co(t,{...n,autoplay:!0});return await s.load(e),s}function d2(t,e={}){return new co(t,e)}const $u={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"},Pu="tinyfly-controls-style",f2=`
1
+ (function(b,Ln){typeof exports=="object"&&typeof module<"u"?Ln(exports):typeof define=="function"&&define.amd?define(["exports"],Ln):(b=typeof globalThis<"u"?globalThis:b||self,Ln(b.tinyfly=b.tinyfly||{}))})(this,(function(b){"use strict";function Ln(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function Hs(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const Br=2;function zr(t){return t.some(e=>e.interpolation!==void 0)?2:1}function qi(t){return t.property==="text"&&"textConfig"in t}function Ne(t){return t.kind==="inertia"&&"inertia"in t}function We(t){return t.kind==="spring"&&"spring"in t}function qr(t){return t.property==="motionPath"&&"motionPathConfig"in t}function R1(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"angle"in t}function yh(t){return"keyframes"in t}class L1{_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 F1{_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 bh(t,e){if(!(e>0))return t;const n=1e3/e;return Math.floor(t/n+1e-9)*n}function jr(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 Yr(t,e="start"){if(t<=1)return 0;let n=0;for(let s=0;s<t;s++)n=Math.max(n,jr(s,t,e));return n}function ji(t,e,n){if(n.offsets)return n.offsets[t]??0;const s=n.from??"start",i=jr(t,e,s);if(n.amount!==void 0){const o=Yr(e,s);return o===0?0:n.amount*i/o}return n.each!==void 0?n.each*i:0}function Yi(t,e){return Array.from({length:t},(n,s)=>ji(s,t,e))}function Rs(t,e){return t<=1?0:Math.max(...Yi(t,e))}const Fn=1,Kr=6e4,Ki=Kr/Fn,ce={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1},Xi={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 Ls{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??ce.stiffness,this.damping=e.damping??ce.damping,this.mass=e.mass??ce.mass,this.restDelta=e.restDelta??ce.restDelta,this.restSpeed=e.restSpeed??ce.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=e.velocity??ce.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/Fn);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/Fn-n;return s+(i-s)*o}settleTime(){return this.simulateTo(Ki+1),this.settledStep!==null?this.settledStep*Fn:Kr}simulateTo(e){if(this.settledStep!==null)return;const n=Math.min(e,Ki+1),s=Fn/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>Ki&&(this.settledStep=Ki)}}function N1(t,e){return new Ls(t).valueAt(e)}function wh(t){return new Ls(t).settleTime()}function W1(t){const e=t.stiffness??ce.stiffness,n=t.damping??ce.damping,s=t.mass??ce.mass;return n<2*Math.sqrt(e*s)}function D1(t){const e=t.stiffness??ce.stiffness,n=t.mass??ce.mass;return 2*Math.sqrt(e*n)}const Xr=4,B1=.002,z1=1e-4,kh=6e4;function Gi(t){const e=t.friction??Xr;return e>0?e:Xr}function Fs(t){return t.from+t.velocity/Gi(t)}function q1(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 Nn(t){let e=q1(Fs(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 Wn(t){const e=Math.abs(Nn(t)-t.from);if(e===0)return 0;const n=t.restDelta??Math.max(z1,e*B1);if(n>=e)return 0;const s=Math.log(e/n)/Gi(t);return Math.min(kh,s*1e3)}function Ui(t,e){if(e<=0)return t.from;const n=Nn(t);if(e>=Wn(t))return n;const s=Gi(t);return t.from+(n-t.from)*(1-Math.exp(-s*e/1e3))}function j1(t,e){const n=Gi(t),s=Nn(t);return e>=Wn(t)?0:(s-t.from)*n*Math.exp(-n*Math.max(0,e)/1e3)}const Vi=t=>t,vh=t=>t*t,Mh=t=>1-(1-t)*(1-t),Sh=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,Gr=t=>t*t*t,Ur=t=>1-Math.pow(1-t,3),Ns=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,xh=Gr,Th=Ur,Eh=Ns,Y1={linear:Vi,"ease-in":xh,"ease-out":Th,"ease-in-out":Eh,"ease-in-quad":vh,"ease-out-quad":Mh,"ease-in-out-quad":Sh,"ease-in-cubic":Gr,"ease-out-cubic":Ur,"ease-in-out-cubic":Ns};function Ah(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=g=>((a*g+r)*g+o)*g,d=g=>((h*g+c)*g+l)*g,f=g=>(3*a*g+2*r)*g+o,p=g=>{let m=g;for(let k=0;k<8;k++){const y=u(m)-g;if(Math.abs(y)<1e-7)return m;const x=f(m);if(Math.abs(x)<1e-7)break;m-=y/x}let w=0,v=1;for(m=g;w<v;){const k=u(m);if(Math.abs(k-g)<1e-7)return m;g>k?w=m:v=m,m=(w+v)/2}return m};return g=>{if(g<=0)return 0;if(g>=1)return 1;const m=p(g);return d(m)}}function Vr(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 $h(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 Ph=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 Ih(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 Oh(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 _h(t){switch(t.type){case"steps":return Oh(t.count,t.position);case"elastic":return Vr($h(t.amplitude,t.period),t.mode);case"bounce":return Vr(Ph,t.mode);case"back":return Vr(Ih(t.overshoot),t.mode)}}function Wt(t){return t===void 0?Vi:Ln(t)?Ah(t.points):Hs(t)?_h(t):Y1[t]??Vi}const Ch=32,K1=256,Dn=new Map,X1=/[MmLlHhVvCcSsQqTtAaZz]/,G1=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,U1={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function V1(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(X1.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=G1.exec(t.slice(n));if(!l)break;s.args.push(parseFloat(l[0])),n+=l[0].length}return e}function J1(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),p=(t-a)/2,g=(e-l)/2,m=d*p+f*g,w=-f*p+d*g,v=m*m/(c*c)+w*w/(h*h);if(v>1){const F=Math.sqrt(v);c*=F,h*=F}const k=o===r?-1:1,y=c*c*h*h-c*c*w*w-h*h*m*m,x=c*c*w*w+h*h*m*m,P=k*Math.sqrt(Math.max(0,y/x)),M=P*c*w/h,T=-P*h*m/c,S=d*M-f*T+(t+a)/2,E=f*M+d*T+(e+l)/2,$=(F,H,W,_)=>{const B=F*W+H*_,Q=Math.sqrt((F*F+H*H)*(W*W+_*_)),O=Math.acos(Math.max(-1,Math.min(1,B/Q)));return F*_-H*W<0?-O:O},A=$(1,0,(m-M)/c,(w-T)/h);let I=$((m-M)/c,(w-T)/h,(-m-M)/c,(-w-T)/h);!r&&I>0&&(I-=2*Math.PI),r&&I<0&&(I+=2*Math.PI);const C=Math.max(1,Math.ceil(Math.abs(I)/(Math.PI/2))),D=I/C,j=4/3*Math.tan(D/4),V=F=>{const H=c*Math.cos(F),W=h*Math.sin(F);return[d*H-f*W+S,f*H+d*W+E]},et=F=>{const H=-c*Math.sin(F),W=h*Math.cos(F);return[d*H-f*W,f*H+d*W]},G=[];for(let F=0;F<C;F++){const H=A+F*D,W=H+D,[_,B]=V(H),[Q,O]=F===C-1?[a,l]:V(W),[R,z]=et(H),[K,N]=et(W);G.push([_+j*R,B+j*z,Q-j*K,O-j*N,Q,O])}return G}function De(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 Hh(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 Ws(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 Ji(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<=Ch;f++){const p=f/Ch,g=De(t,s,o,a,p),m=De(e,i,r,l,p);d+=Math.hypot(g-h,m-u),c.push(d),h=g,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 hn(t){const e=Dn.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=g=>{c<0&&(c=0),g.subpath=c,n.push(g)};for(const{type:g,args:m}of V1(t)){const w=g.toUpperCase(),v=g!==w,k=U1[w];if(w==="Z"){(s!==o||i!==r)&&u(Ws(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 x=m.slice(y,y+k),P=v?s:0,M=v?i:0;let T=null,S=null;switch(w){case"M":y===0?(s=x[0]+P,i=x[1]+M,o=s,r=i,(c<0||n[n.length-1]?.subpath===c)&&c++):(u(Ws(s,i,x[0]+P,x[1]+M)),s=x[0]+P,i=x[1]+M);break;case"L":u(Ws(s,i,x[0]+P,x[1]+M)),s=x[0]+P,i=x[1]+M;break;case"H":u(Ws(s,i,x[0]+P,i)),s=x[0]+P;break;case"V":u(Ws(s,i,s,x[0]+M)),i=x[0]+M;break;case"C":{const E=[x[0]+P,x[1]+M,x[2]+P,x[3]+M,x[4]+P,x[5]+M];u(Ji(s,i,E)),T=[E[2],E[3]],s=E[4],i=E[5];break}case"S":{const[E,$]=a?[2*s-a[0],2*i-a[1]]:[s,i],A=[E,$,x[0]+P,x[1]+M,x[2]+P,x[3]+M];u(Ji(s,i,A)),T=[A[2],A[3]],s=A[4],i=A[5];break}case"Q":case"T":{let E=s,$=i;w==="Q"?(E=x[0]+P,$=x[1]+M):l&&(E=2*s-l[0],$=2*i-l[1]);const A=w==="Q"?x[2]+P:x[0]+P,I=w==="Q"?x[3]+M:x[1]+M;u(Ji(s,i,[s+2/3*(E-s),i+2/3*($-i),A+2/3*(E-A),I+2/3*($-I),A,I])),S=[E,$],s=A,i=I;break}case"A":{const E=x[5]+P,$=x[6]+M;let A=s,I=i;for(const C of J1(s,i,x[0],x[1],x[2],x[3],x[4],E,$))u(Ji(A,I,C)),A=C[4],I=C[5];s=E,i=$;break}}a=T,l=S}}const d=n.reduce((g,m)=>g+m.length,0),f=[];for(let g=0;g<n.length;){const m=n[g].subpath;let w=g,v=0;for(;w<n.length&&n[w].subpath===m;)v+=n[w++].length;const k=n[g],y=n[w-1],x=h.has(m)||Math.abs(y.endX-k.startX)<1e-9&&Math.abs(y.endY-k.startY)<1e-9;f.push({start:g,end:w,length:v,closed:x}),g=w}const p={segments:n,totalLength:d,subpaths:f};return Dn.size>=K1&&Dn.delete(Dn.keys().next().value),Dn.set(t,p),p}function Z1(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 Q1(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=Z1(t,e);let c=Hh(t.startX,n,i,r,l),h=Hh(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=De(t.startX,n,i,r,u),f=De(t.startY,s,o,a,u),p=De(t.startX,n,i,r,l),g=De(t.startY,s,o,a,l);c=l<.5?d-p:p-d,h=l<.5?f-g:g-f}return{x:De(t.startX,n,i,r,l),y:De(t.startY,s,o,a,l),angle:Math.atan2(h,c)*180/Math.PI}}function Jr(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 Q1(r,e-i);i+=r.length}return{x:0,y:0,angle:0}}function Rh(t,e){const{segments:n,totalLength:s}=hn(t);return Jr(n,Math.max(0,Math.min(1,e))*s)}function ty(){Dn.clear()}function ey(t){return hn(t).totalLength}const ny=24,sy=320,iy=2.5,Ds=72,oy=64,ry=.2,ay=128,Bs=new Map;let Zi=0,Be;const Lh=t=>Math.round(t*100)/100;function Fh(t,e){const{segments:n,subpaths:s,totalLength:i}=hn(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 Zr(t,e){const n=t.closed?(e%1+1)%1:Math.max(0,Math.min(1,e)),s=Jr(t.segments,n*t.length,t.start,t.end);return[s.x,s.y]}function Nh(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 Wh(t,e){const n=[];for(let s=0;s<e;s++)n.push(Zr(t,t.closed?s/e:s/(e-1)));return n}function Dh(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 ly(t,e,n){const s=t.closed&&e.closed;if(n!==void 0)return{offset:s?Math.abs(n)%Ds/Ds:0,reversed:n<0};const i=Dh(Wh(t,Ds)),o=Dh(Wh(e,Ds)),r=Ds;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 p=s?c?(u-f+r)%r:(f+u)%r:c?r-1-f:f,g=i[f][0]-o[p][0],m=i[f][1]-o[p][1];d+=g*g+m*m}d<l&&(l=d,a={offset:s?u/r:0,reversed:c})}}return a}function cy(t,e,n){return n?((e.reversed?e.offset-t:t+e.offset)%1+1)%1:e.reversed?1-t:t}function hy(t,e,n){return n?((e.reversed?e.offset-t:t-e.offset)%1+1)%1:e.reversed?1-t:t}function uy(t,e,n){const s=t.closed&&e.closed,i=ly(t,e,n.shapeIndex),o=Math.max(ny,Math.min(sy,Math.ceil(Math.max(t.length,e.length)/iy))),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 Nh(t))a(u);for(const u of Nh(e))a(hy(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(...Zr(t,u)),h.push(...Zr(e,cy(u,i,s)));return dy({from:c,to:h,closed:s})}function dy(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=ry;for(let h=r+1;h<a;h++){const u=Math.max(Bh(t.from,r,a,h),Bh(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 Bh(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 fy(t,e,n){const s=n.shapeIndex;if(Be&&Be.from===t&&Be.to===e&&Be.shapeIndex===s)return Be.plan;const o=Bs.get(String(s??"auto"))?.get(t)?.get(e);if(o)return Be={from:t,to:e,shapeIndex:s,plan:o},o;const r=hn(t).subpaths.filter(f=>f.length>0).length===hn(e).subpaths.filter(f=>f.length>0).length,a=Fh(t,!r),l=Fh(e,!r),c={pairs:a.map((f,p)=>uy(f,l[p],n))};Zi>=ay&&(Bs.clear(),Zi=0);const h=String(s??"auto"),u=Bs.get(h)??new Map;Bs.set(h,u);const d=u.get(t)??new Map;return u.set(t,d),d.set(e,c),Zi++,Be={from:t,to:e,shapeIndex:s,plan:c},c}function zh(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=fy(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=Lh(a.from[l]+(a.to[l]-a.from[l])*i),h=Lh(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 gy(){Bs.clear(),Zi=0,Be=void 0}function Bn(t){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(t)}const zn=Math.PI/180,py=.9995;function Qr(){return[0,0,0,1]}function Vt(t,e){const n=Math.hypot(t[0],t[1],t[2]);if(n===0)return Qr();const s=e*zn/2,i=Math.sin(s)/n;return[t[0]*i,t[1]*i,t[2]*i,Math.cos(s)]}function my(t,e,n){return ta(ta(Vt([0,1,0],e),Vt([1,0,0],t)),Vt([0,0,1],n))}function yy(t){const[e,n,s,i]=ze(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/zn,Math.atan2(o,u)/zn,Math.atan2(r,a)/zn]:[d/zn,Math.atan2(-h,c)/zn,0]}function ta(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 qh(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function jh(t){return Math.hypot(t[0],t[1],t[2],t[3])}function ze(t){const e=jh(t);return e===0?Qr():[t[0]/e,t[1]/e,t[2]/e,t[3]/e]}function by(t){return[-t[0],-t[1],-t[2],t[3]]}function Yh(t,e,n){const s=ze(t);let i=ze(e),o=qh(s,i);if(o<0&&(i=[-i[0],-i[1],-i[2],-i[3]],o=-o),o>py)return ze([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 ze([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 wy(t,e){const[n,s,i,o]=ze(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 ky=Object.freeze(Object.defineProperty({__proto__:null,conjugate:by,dot:qh,fromAxisAngle:Vt,fromEuler:my,identity:Qr,length:jh,multiply:ta,normalize:ze,rotateVec3:wy,slerp:Yh,toEuler:yy},Symbol.toStringTag,{value:"Module"})),we=(t,e,n)=>t+(e-t)*n,Kh=512,ea=new Map,na=new Map;function Xh(t){const e=ea.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 ea.size<Kh&&ea.set(t,s),s}const Gh=t=>t.charCodeAt(0)===35,Uh=t=>t.startsWith("rgb"),Vh=t=>t.startsWith("rgba"),vy=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,sa=t=>Math.round(t).toString(16).padStart(2,"0");function My(t,e,n){return`#${sa(t)}${sa(e)}${sa(n)}`}function Jh(t){const e=na.get(t);if(e)return e;const n=t.match(vy);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 na.size<Kh&&na.set(t,r),r}const Zh=(t,e,n)=>{if(Gh(t)&&Gh(e)){const[s,i,o]=Xh(t),[r,a,l]=Xh(e),c=we(s,r,n),h=we(i,a,n),u=we(o,l,n);return My(c,h,u)}if((Uh(t)||Vh(t))&&(Uh(e)||Vh(e))){const s=Jh(t),i=Jh(e),o=Math.round(we(s[0],i[0],n)),r=Math.round(we(s[1],i[1],n)),a=Math.round(we(s[2],i[2],n));if(s.length===4||i.length===4){const l=s[3]??1,c=i[3]??1,h=we(l,c,n);return`rgba(${o}, ${r}, ${a}, ${h})`}return`rgb(${o}, ${r}, ${a})`}return n<1?t:e},Qh=(t,e,n)=>{const s=Math.min(t.length,e.length),i=[];for(let o=0;o<s;o++)i.push(we(t[o],e[o],n));return i},t0=(t,e,n)=>Yh(t,e,n),ia=(t,e,n)=>n<1?t:e,e0=(t,e,n)=>zh(t,e,n);function zs(t,e){return e==="slerp"?t0:typeof t=="number"?we:Array.isArray(t)?Qh:typeof t=="string"?t.startsWith("#")||t.startsWith("rgb")?Zh:Bn(t)?e0:ia:ia}const oa=1e3/60;function ra(t,e={}){if(!We(t))throw new Error(`bakeSpringTrack: track "${t.id}" is not a spring track`);const n=new Ls(t.spring);return n0(t,s=>n.valueAt(s),n.settleTime(),t.spring.from,t.spring.to,e)}function aa(t,e={}){if(!Ne(t))throw new Error(`bakeInertiaTrack: track "${t.id}" is not an inertia track`);const n=t.inertia;return n0(t,s=>Ui(n,s),Wn(n),n.from,Nn(n),e)}function n0(t,e,n,s,i,o){const r=o.intervalMs??oa,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?i0(c,a):c,...t.targets&&{targets:[...t.targets]},...t.stagger&&{stagger:{...t.stagger}}}}function la(t,e,n,s={}){const i=s.intervalMs??oa,o=typeof n=="function"?n:Wt(n),r=zs(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 Sy(t,e){return We(t)?ra(t,e):Ne(t)?aa(t,e):t}function s0(t,e={}){const n=t.keyframes;if(!n.some(o=>Hs(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];Hs(r.easing)?s.push(...la(n[o-1],r,r.easing,i)):s.push(r)}return{...t,keyframes:s}}function xy(t,e){return t.filter(yh).map(n=>s0(n,e)).concat(t.filter(We).map(n=>ra(n,e)),t.filter(Ne).map(n=>aa(n,e)))}function i0(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 Qi(t){const e=[...t.keyframes].sort((n,s)=>n.time-s.time);return{...t,keyframes:e}}function qe(t){return t.targets&&t.targets.length>0?t.targets:[t.target]}function qn(t,e,n,s){const i=n??0;return!s||e<=1?i:i+ji(t,e,s)}class un{track;targets;constructor(e){this.track=e,this.targets=qe(e)}getValueAtTime(e){return this.valueForOffset(e-qn(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=qn(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?Rs(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=Wt(i.easing)(r);return zs(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 o0{track;targets;sampler;constructor(e){this.track=e,this.targets=qe(e),this.sampler=new Ls(e.spring)}getValueAtTime(e){return this.sampler.valueAt(e-qn(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=qn(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?Rs(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+e}getTrack(){return this.track}}class r0{track;targets;duration;constructor(e){this.track=e,this.targets=qe(e),this.duration=Wn(e.inertia)}getValueAtTime(e){return Ui(this.track.inertia,e-qn(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=qn(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:Ui(this.track.inertia,e-o),start:o})}return s}getDuration(){const e=this.track.stagger?Rs(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+e}getTrack(){return this.track}}function ca(t,e){const n={...Rh(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 Ty(t,e,n,s){const i=e+(n-e)*s;return ca(t,i)}const ha={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},Ey=20;function a0(t){const e=ha[t??"upperCase"]??t??ha.upperCase,n=Array.from(e);return n.length>0?n:Array.from(ha.upperCase)}function Ay(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 l0(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 v=Math.round(o*Math.max(r.length,a.length));return l?r.slice(0,Math.max(0,r.length-v)).join("")+a.slice(Math.max(0,a.length-v)).join(""):a.slice(0,v).join("")+r.slice(v).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=a0(t.chars),p=t.refreshRate??Ey,g=p>0?Math.floor(n*p/1e3):0,m=t.seed??1;let w="";for(let v=0;v<d;v++){const k=l?v>=d-u:v<u,y=l?a[a.length-(d-v)]:a[v];k&&y!==void 0||y===" "||y===`
2
+ `?w+=y:w+=f[Ay(m,v,g)%f.length]}return w}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=bh(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",l0(l.textConfig,o,Math.max(0,r)));return}const c=this._motionPathTracks.get(n);if(c&&typeof o=="number"){const h=ca(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 qe(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,Ne(e)){this._trackPlayers.set(e.id,new r0(e));return}if(We(e)){this._trackPlayers.set(e.id,new o0(e)),this._springTracks.set(e.id,e);return}if(qi(e))this._trackPlayers.set(e.id,new un(e)),this._textTracks.set(e.id,e);else if(qr(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 un(n)),this._motionPathTracks.set(e.id,e)}else this._trackPlayers.set(e.id,new un(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(We(s)||Ne(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=qe(r).filter(u=>qe(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&&!qe(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:zr(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 $y=100;function ua(t,e,n,s){const i=[],o=[],{duration:r,alternate:a}=s,l=(f,p,g,m)=>{o.push([f,p]);const w=[];t.forEach((v,k)=>{(g==="forward"?(m?v>=f:v>f)&&v<=p:(m?v<=f:v<f)&&v>=p)&&w.push(k)}),w.sort((v,k)=>(g==="forward"?t[v]-t[k]:t[k]-t[v])||v-k);for(const v of w)i.push({kind:"event",index:v,direction:g})};let c=e.time,h=e.direction,u=e.fresh===!0;const d=Math.min($y,Math.max(0,n.iteration-e.iteration));for(let f=0;f<d;f++){const p=h==="forward"?r:0;l(c,p,h,u),i.push({kind:"repeat"}),a?(h=h==="forward"?"reverse":"forward",c=p,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 c0(t){return Ne(t)?{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:h0(t.inertia),...ke(t)}:We(t)?{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...ke(t)}:qi(t)?{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:t.keyframes.map(da),...ke(t)}:qr(t)?{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:t.keyframes.map(da),...ke(t)}:{id:t.id,target:t.target,property:t.property,keyframes:t.keyframes.map(da),...t.interpolation!==void 0&&{interpolation:t.interpolation},...ke(t)}}function h0(t){return{...t,...Array.isArray(t.end)&&{end:[...t.end]}}}function da(t){return{time:t.time,value:t.value,...t.easing&&{easing:t.easing}}}function ke(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 u0(t){if(Ne(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"inertia",inertia:h0(e.inertia),...ke(e)}}if(We(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"spring",spring:{...e.spring},...ke(e)}}if(qi(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),...ke(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,...ke(e)}}return Qi({id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,...t.interpolation!==void 0&&{interpolation:t.interpolation},...ke(t)})}function d0(t){const e=t._config.markers;return{formatVersion:zr(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(c0),...t.captions&&{captions:JSON.parse(JSON.stringify(t.captions))}}}function jn(t){const e=t.formatVersion??1;if(e>Br)throw new Error(`tinyfly: this animation uses format version ${e}, but this tinyfly reads up to version ${Br}. Update tinyfly to play it.`);return new Ht({id:t.id,name:t.name,config:t.config,tracks:t.tracks.map(u0),captions:t.captions})}function Py(t){return JSON.stringify(d0(t))}function Iy(t){const e=JSON.parse(t);return jn(e)}function ne(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 je(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 fa(t,e,n){return e+t.next()*(n-e)}function f0(t,e,n,s){if(s<=0)return fa(t,e,n);const i=Math.floor((n-e)/s),o=Math.round(t.next()*i);return e+o*s}function Oy(t,e){if(e.length!==0)return e[Math.floor(t.next()*e.length)]}const g0=/^([+\-*/])=\s*(-?[\d.]+)$/,p0=/^random\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*(?:,\s*(-?[\d.]+)\s*)?\)$/i;function _y(t){return typeof t!="string"?!1:g0.test(t.trim())||p0.test(t.trim())}function ga(t,e={}){if(typeof t!="string")return t;const n=t.trim(),s=g0.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=p0.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?f0(e.random,o,r,a):fa(e.random,o,r)}return t}function m0(t,e=0,n){const s=[];let i=e;for(const o of t){const r=ga(o,{base:i,random:n});s.push(r),typeof r=="number"&&(i=r)}return s}class Cy{random;constructor(e){this.random=je(e)}get seed(){return this.random.seed}resolve(e,n=0){return ga(e,{base:n,random:this.random})}resolveSequence(e,n=0){return m0(e,n,this.random)}}const Hy=600;function y0(t){if(Array.isArray(t)){const[d,f,p,g]=t;return{fn:k0(d,f,p,g),bezier:[d,f,p,g]}}const{segments:e}=hn(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,p,g]=i.points,m=[a(d),l(f),a(p),l(g)];return{fn:k0(...m),bezier:m}}const c=[],h=[],u=Math.max(8,Math.ceil(Hy/e.length));for(const d of e)for(let f=c.length===0?0:1;f<=u;f++){const[p,g]=Ry(d,f/u);c.push(a(p)),h.push(l(g))}return{fn:Ly(c,h)}}function b0(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 w0(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 Ry(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 Ly(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 k0(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 Fy=350,Ny=300,Wy=550;function Dy(t,e={}){const n=e.lead??Fy,s=e.gap??Ny,i=e.tail??Wy,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 By(t){return t.cues.map(e=>({id:e.id,time:e.start,label:e.text}))}function zy(t,e){let n=t.scenes[0];for(const s of t.scenes)if(e>=s.start)n=s;else break;return n}const qs=t=>6e4/t.bpm;function to(t,e){return t.offset+e*qs(t)}function js(t,e){return(e-t.offset)/qs(t)}function qy(t,e){return to(t,Math.round(js(t,e)))}function jy(t,e){return to(t,Math.ceil(js(t,e)-1e-9))}function Yy(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(js(t,e)-1e-9);;o++){const r=to(t,o);if(r>n+1e-9)break;i.push({time:r,bar:(o%s+s)%s===0,n:o})}return i}const Yn=100;function Ky(t,e,n={}){const s=n.minBpm??70,i=n.maxBpm??180,o=Math.max(1,Math.round(e/Yn)),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 S=0;S<a;S++){let E=0;for(let $=S*o;$<(S+1)*o;$++)E+=t[$]*t[$];l[S]=Math.log(1e-6+E/o)}const c=new Float64Array(a);for(let S=1;S<a;S++)c[S]=Math.max(0,l[S]-l[S-1]);const h=c.reduce((S,E)=>S+E,0)/a;for(let S=0;S<a;S++)c[S]=Math.max(0,c[S]-h);const u=Math.max(1,Math.floor(60*Yn/i)),d=Math.min(a-1,Math.ceil(60*Yn/s)),f=S=>{let E=0;for(let $=S;$<a;$++)E+=c[$]*c[$-S];return E/(a-S)};let p=0;for(let S=0;S<a;S++)p+=c[S]*c[S];p/=a;let g=u,m=-1/0;for(let S=u;S<=d;S++){const E=60*Yn/S,$=Math.exp(-.5*(Math.log2(E/120)/.9)**2),A=f(S)*$;A>m&&(m=A,g=S)}const w=S=>{const E=Math.floor(S);return E<0||E+1>=a?0:c[E]+(c[E+1]-c[E])*(S-E)},v=(S,E)=>{let $=0;for(let A=E;A<a;A+=S)$+=w(A);return $};let k=g,y=0,x=-1/0;for(let S=g-.6;S<=g+.6+1e-9;S+=.02){if(S<1)continue;const E=Math.max(1,Math.round(S*4));for(let $=0;$<E;$++){const A=$/E*S,I=v(S,A);I>x&&(x=I,y=A,k=S)}}const P=60*Yn/k,M=p>0?Math.max(0,Math.min(1,f(g)/p)):0,T=(y+.5)*1e3/Yn;return{bpm:Math.round(P*100)/100,offset:Math.round(T%(6e4/P)),confidence:M}}const Xy=600,Gy=250,v0=1;function Uy(t,e){const n=e.target??"Camera",s={x:e.stage.width/2,y:e.stage.height/2},i={},o=(u,d,f,p)=>{const g=i[u]??=[];for(;g.length>0&&g[g.length-1].time>=d;)g.pop();g.push({time:d,value:f,...p?{easing:p}:{}})},r=u=>{const d=u.rotate*Math.PI/180,f=(u.focusX-s.x)*u.scale,p=(u.focusY-s.y)*u.scale;return{x:-(f*Math.cos(d)-p*Math.sin(d)),y:-(f*Math.sin(d)+p*Math.cos(d)),scale:u.scale,rotate:u.rotate}},a=(u,d,f)=>{const p=r(d);for(const g of["x","y","scale","rotate"])o(g,u,p[g],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(v0,u.duration??Xy);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>v0?"ease-in-out":void 0))}else{const{follow:d}=u,f=d.lag??Gy,p=new Ht({id:"follow",tracks:[{id:"x",target:"s",property:"x",keyframes:d.x}]}),g=v=>p.getStateAtTime(v).values.get("s")?.get("x")??l.focusX,m=[u.at,...d.x.map(v=>v.time).filter(v=>v>u.at&&v<u.until),u.until];a(u.at,l);const w=v=>({focusX:g(v)+(d.lead??0),focusY:d.y??l.focusY,scale:d.scale??l.scale,rotate:l.rotate});for(const v of m){const k=d.x.find(y=>y.time===v)?.easing;a(v+f,w(v),v===u.at?"ease-in-out":k)}l=w(u.until)}for(const u of c.filter(d=>"shake"in d)){const d=u.shake.strength??12,f=u.shake.roll??1.5,p=1e3/(u.shake.frequency??24),g=je(u.shake.seed??Math.round(u.at)+1),m=()=>g.next()*2-1;for(const w of["shakeX","shakeY","shakeRotate"])o(w,u.at,0);for(let w=u.at+p;w<u.at+u.duration;w+=p){const v=1-(w-u.at)/u.duration;o("shakeX",w,m()*d*v),o("shakeY",w,m()*d*v),o("shakeRotate",w,m()*f*v)}for(const w of["shakeX","shakeY","shakeRotate"])o(w,u.at+u.duration,0,"ease-out")}return Object.entries(i).map(([u,d])=>({id:`${n}-${u}`,target:n,property:u,keyframes:d}))}function M0(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 Ys(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=M0(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??Ys(e,n):void 0;return`Unknown ${t} ${JSON.stringify(e)}${i?`: did you mean "${i}"?`:"."} Known: ${n.join(", ")}`}function Ks(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}function dn(t,e,n=1){if(!(e>0))return 0;const s=t*n/e;return s-Math.floor(s)}function pa(t){const e=t-Math.floor(t);return 1-Math.abs(e*2-1)}function Vy(t,e){const n=Math.max(1,Math.round(e.cycles??1)),s=e.amplitude??1,i=dn(t,e.period,n)+(e.phase??0),o=i-Math.floor(i);switch(e.shape??"sine"){case"triangle":return s*(pa(o+.25)*2-1);case"square":return o<.5?s:-s;default:return s*Math.sin(o*Math.PI*2)}}function Jy(t,e){const n=Math.max(1,Math.round(e.cycles??1)),s=typeof e.easing=="function"?e.easing:Wt(e.easing??"ease-in-out"),i=dn(t,e.period,n)+(e.phase??0);return s(pa(i))}function Zy(t,e){const n=S0(e.seed),s=Math.max(1,Math.round(e.cycles??1)),i=(dn(t,e.period,1)+(e.phase??0))*Math.PI*2,o=s/Math.PI;return x0([Math.cos(i)*o+7.31,Math.sin(i)*o+3.17],n,e.octaves??1)}function Qy(t,e,n){const s=S0(n.seed),i=Math.max(1,Math.round(n.cycles??1)),o=Math.max(1,Math.round(n.cyclesAlong??1)),r=dn(t,n.period,1)*Math.PI*2,a=dn(e,n.periodAlong,1)*Math.PI*2,l=i/Math.PI,c=o/Math.PI;return x0([Math.cos(r)*l+5.13,Math.sin(r)*l+9.47,Math.cos(a)*c+2.71,Math.sin(a)*c+6.29],s,n.octaves??1)}const S0=t=>typeof t=="string"?ne(t):(t??0)>>>0;function x0(t,e,n){const s=Math.max(1,Math.min(6,Math.round(n)));let i=0,o=1,r=0;for(let a=0;a<s;a++){const l=2**a;i+=o*tb(t.map(c=>c*l),e+a*1013),r+=o,o*=.5}return i/r}function tb(t,e){const n=t.length,s=t.map(Math.floor),o=t.map((a,l)=>a-s[l]).map(a=>a*a*(3-2*a));let r=0;for(let a=0;a<1<<n;a++){let l=1;const c=[];for(let h=0;h<n;h++){const u=a>>h&1;l*=u?o[h]:1-o[h],c.push(s[h]+u)}l!==0&&(r+=l*eb(c,e))}return r}function eb(t,e){let n=(e^2654435769)>>>0;for(const s of t)n=Math.imul(n^(s|0),2246822507)>>>0,n=(n^n>>>13)>>>0,n=Math.imul(n,3266489909)>>>0,n=(n^n>>>16)>>>0;return n/4294967296*2-1}function nb(t,e={}){if(t.length===0)throw new Error("curve: needs at least one key");const s={id:"curve",target:"curve",property:"value",keyframes:t.map(o=>({time:o.at,value:o.value,easing:o.easing})).sort((o,r)=>o.time-r.time),interpolation:e.interpolation},i=new un(s);return o=>i.getValueAtTime(o)}function sb(t,e){return e*qs({bpm:t.bpm})}function ib(t,e){const n=Math.max(1,Math.round(t/qs(e)));return{beats:n,grid:{...e,bpm:n*6e4/t}}}function ob(t,e,n={}){const s=Math.max(1e-6,n.attack??.05),i=Math.max(1e-6,n.decay??.4),o=js(e,t),r=o-Math.floor(o),a=r<s?r/s:Math.max(0,1-(r-s)/i),l=n.barAccent??0;if(l<=0)return a;const c=Math.max(1,Math.round(e.beatsPerBar??4)),u=(Math.floor(o)%c+c)%c===0;return a*(u?1+l:1)/(1+l)}function rb(t,e,n={}){const s=n.fps??30,i=Math.max(1,Math.round(e/s)),o=Math.max(1,Math.ceil(t.length/i)),r=new Float32Array(o),a=Math.min(.99,Math.max(0,n.smoothing??.5));let l=0,c=0;for(let h=0;h<o;h++){let u=0;const d=h*i,f=Math.min(t.length,d+i);for(let g=d;g<f;g++)u+=t[g]*t[g];const p=f>d?Math.sqrt(u/(f-d)):0;l=p>l?p:l*a+p*(1-a),r[h]=l,c=Math.max(c,l)}if(n.normalize!==!1&&c>0)for(let h=0;h<o;h++)r[h]/=c;return r}function ab(t,e,n=30,s){if(t.length===0)return 0;const o=(s?dn(e,s)*s:e)*n/1e3,r=Math.floor(o),a=t[Math.min(t.length-1,Math.max(0,r))],l=t[Math.min(t.length-1,Math.max(0,r+1))];return a+(l-a)*(o-r)}const T0={"16:9":16/9,"2.39:1":2.39,"4:3":4/3,"1:1":1,"9:16":9/16,"4:5":4/5},ma=t=>typeof t=="number"?t:T0[t];function lb(t,e){const n=ma(e),s=t.width/t.height;if(n>=s){const o=t.width/n;return{x:0,y:(t.height-o)/2,width:t.width,height:o}}const i=t.height*n;return{x:(t.width-i)/2,y:0,width:i,height:t.height}}function cb(t,e){const n=ma(t),s=i=>Math.max(2,Math.round(i/2)*2);return"width"in e?{width:s(e.width),height:s(e.width/n)}:{width:s(e.height*n),height:s(e.height)}}function hb(t,e={}){const n=s=>({x:t.x+t.width*(1-s)/2,y:t.y+t.height*(1-s)/2,width:t.width*s,height:t.height*s});return{action:n(e.action??.9),title:n(e.title??.8)}}const ve=t=>Math.round(t*1e3)/1e3;function E0(t,e={}){if(t.length===0)return"";const n=e.curviness??1,s=e.closed??!1,i=t.length;let o=`M${ve(t[0].x)} ${ve(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${ve(u.x)} ${ve(u.y)}`;continue}const f=n/6,p=h.x+(u.x-c.x)*f,g=h.y+(u.y-c.y)*f,m=u.x-(d.x-h.x)*f,w=u.y-(d.y-h.y)*f;o+=` C${ve(p)} ${ve(g)} ${ve(m)} ${ve(w)} ${ve(u.x)} ${ve(u.y)}`}return s?`${o} Z`:o}const Bt=(t,e=0)=>{const n=parseFloat(t??"");return Number.isFinite(n)?n:e};function ub(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 eo(t){const e=t.attributes;switch(t.tag.toLowerCase()){case"path":return e.d??null;case"circle":case"ellipse":{const n=Bt(e.cx),s=Bt(e.cy),i=t.tag.toLowerCase()==="circle"?Bt(e.r):Bt(e.rx),o=t.tag.toLowerCase()==="circle"?Bt(e.r):Bt(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=Bt(e.x),s=Bt(e.y),i=Bt(e.width),o=Bt(e.height);let r=e.rx!=null?Bt(e.rx):e.ry!=null?Bt(e.ry):0,a=e.ry!=null?Bt(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${Bt(e.x1)} ${Bt(e.y1)} L${Bt(e.x2)} ${Bt(e.y2)}`;case"polyline":case"polygon":{const n=ub(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 db(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 fb=2.5;function A0(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 p=u*c[0]+d*c[1],g=Math.min(fb,1/Math.max(p,1e-6)),m=r.width/2*g;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 $0(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}const gb={scale:1,turn:0,x:0,y:0};function pb(t={}){return{scale:t.scale??1,turn:t.turn??0,x:t.x??0,y:t.y??0}}function P0(t,e,n){const{ax:s,ay:i}=no(t,e);return{scale:t,turn:e,x:n.x-(s*n.x-i*n.y),y:n.y-(i*n.x+s*n.y)}}function ya(t,e){const{ax:n,ay:s}=no(t.scale,t.turn);return{x:n*e.x-s*e.y+t.x,y:s*e.x+n*e.y+t.y}}function mb(t,e){const n=ya(e,{x:t.x,y:t.y});return{scale:t.scale*e.scale,turn:t.turn+e.turn,x:n.x,y:n.y}}function yb(t){if(t.scale===0)throw new Error("invertSimilarity: a scale of 0 cannot be undone");const e={scale:1/t.scale,turn:-t.turn,x:0,y:0},n=ya(e,{x:t.x,y:t.y});return{...e,x:-n.x,y:-n.y}}function I0(t){const{ax:e,ay:n}=no(t.scale,t.turn),s=1-e,i=-n,o=s*s+i*i;return o<1e-18?null:{x:(t.x*s+t.y*i)/o,y:(t.y*s-t.x*i)/o}}function bb(t,e){if(t.scale<=0)throw new Error("powSimilarity: the scale must be positive");const n=Math.pow(t.scale,e),s=t.turn*e,i=I0(t);return i?P0(n,s,i):{scale:n,turn:s,x:t.x*e,y:t.y*e}}function wb(t){const{ax:e,ay:n}=no(t.scale,t.turn);return[e,n,-n,e,t.x,t.y]}const no=(t,e)=>{const n=e*Math.PI/180;return{ax:t*Math.cos(n),ay:t*Math.sin(n)}};function so([t,e,n],s={}){const i=s.scale??1,o=s.centre??{x:0,y:0},r=Math.sqrt(3)/2;return{x:o.x+(t-e)*r*i,y:o.y+((t+e)*.5-n)*i}}const ba=([t,e,n])=>t+e+n;function wa(t,e={}){const[n,s,i]=t.min,[o,r,a]=t.max,l=d=>so(d,e),c=[(n+o)/2,(s+r)/2,(i+a)/2],h=ba(c),u=[{side:"top",depth:h,tag:t.tag,points:[l([n,s,a]),l([o,s,a]),l([o,r,a]),l([n,r,a])]},{side:"left",depth:h,tag:t.tag,points:[l([n,r,i]),l([o,r,i]),l([o,r,a]),l([n,r,a])]},{side:"right",depth:h,tag:t.tag,points:[l([o,s,i]),l([o,r,i]),l([o,r,a]),l([o,s,a])]}];return t.hide?u.filter(d=>!t.hide.includes(d.side)):u}function ka(t,e={}){return t.map(n=>({box:n,depth:ba([(n.min[0]+n.max[0])/2,(n.min[1]+n.max[1])/2,(n.min[2]+n.max[2])/2])})).sort((n,s)=>n.depth-s.depth).flatMap(({box:n})=>wa(n,e))}function kb(t={}){const e=t.size??10,s=(t.thickness??2)/2,i=[{tag:0,min:[-s,-s,-s],max:[e-s,s,s]},{tag:1,min:[e-s,-s,-s],max:[e+s,e-s,s]},{tag:2,min:[e-s,e-s,-s],max:[e+s,e+s,e]}],o=t.centre??{x:0,y:0},r=so([2*e/3,e/3,e/3],{scale:t.scale}),a={centre:{x:o.x-r.x,y:o.y-r.y},scale:t.scale};return{boxes:i,faces:[...ka(i,a),...wa({...i[0],hide:["right"]},a)]}}function vb(t={}){const e=Math.max(2,Math.round(t.steps??8)),n=t.tread??1.5,s=t.rise??.25,i=t.width??3,o=t.base??1.5,r=Math.max(1,Math.round(e*(n-2*s)/(n+2*s))),a=2*(e+r),l=n*(e-r)/a,c=[{dir:[1,0,0],across:[0,1,0],count:e},{dir:[0,1,0],across:[-1,0,0],count:e},{dir:[-1,0,0],across:[0,-1,0],count:r},{dir:[0,-1,0],across:[1,0,0],count:r}],h=[];let u=[0,0,0],d=0;for(const w of c){for(let v=0;v<w.count;v++){const k=d*l,y=[u[0]+w.dir[0]*v*n,u[1]+w.dir[1]*v*n,0],x=[y[0]+w.dir[0]*n+w.across[0]*i,y[1]+w.dir[1]*n+w.across[1]*i,0];h.push({tag:d,min:[Math.min(y[0],x[0]),Math.min(y[1],x[1]),0],max:[Math.max(y[0],x[0]),Math.max(y[1],x[1]),k+o]}),d++}u=[u[0]+w.dir[0]*w.count*n,u[1]+w.dir[1]*w.count*n,0]}const f=a*l,p=t.centre??{x:0,y:0},g=so([e*n/2,e*n/2,f/2+o],{scale:t.scale}),m={centre:{x:p.x-g.x,y:p.y-g.y},scale:t.scale};return{boxes:h,faces:ka(h,m),rise:l}}function O0(t,e,n){let s=0;for(const i of t){const o=(e-i.x)**2+(n-i.y)**2;s+=o>1e-9?i.r*i.r/o:1e9}return s}function Mb(t,e={}){if(t.length===0)return[];const n=e.threshold??1,s=Math.max(.5,e.cell??4),i=Math.sqrt(1/n)*1.6,o=e.bounds??{x:Math.min(...t.map(f=>f.x-f.r*i)),y:Math.min(...t.map(f=>f.y-f.r*i)),width:Math.max(...t.map(f=>f.x+f.r*i))-Math.min(...t.map(f=>f.x-f.r*i)),height:Math.max(...t.map(f=>f.y+f.r*i))-Math.min(...t.map(f=>f.y-f.r*i))},r=Math.max(2,Math.ceil(o.width/s)+1),a=Math.max(2,Math.ceil(o.height/s)+1),l=new Float64Array(r*a);for(let f=0;f<a;f++)for(let p=0;p<r;p++)l[f*r+p]=O0(t,o.x+p*s,o.y+f*s)-n;const c=(f,p)=>l[p*r+f],h=(f,p,g,m,w,v)=>{const k=g===v?.5:g/(g-v);return{x:f+(m-f)*k,y:p+(w-p)*k}},u=[];for(let f=0;f+1<a;f++)for(let p=0;p+1<r;p++){const g=o.x+p*s,m=o.y+f*s,w=g+s,v=m+s,k=[c(p,f),c(p+1,f),c(p+1,f+1),c(p,f+1)],y=(k[0]>0?1:0)|(k[1]>0?2:0)|(k[2]>0?4:0)|(k[3]>0?8:0);if(y===0||y===15)continue;const x=()=>h(g,m,k[0],w,m,k[1]),P=()=>h(w,m,k[1],w,v,k[2]),M=()=>h(g,v,k[3],w,v,k[2]),T=()=>h(g,m,k[0],g,v,k[3]),S=(k[0]+k[1]+k[2]+k[3])/4>0;switch(y){case 1:case 14:u.push([T(),x()]);break;case 2:case 13:u.push([x(),P()]);break;case 3:case 12:u.push([T(),P()]);break;case 4:case 11:u.push([P(),M()]);break;case 6:case 9:u.push([x(),M()]);break;case 7:case 8:u.push([T(),M()]);break;case 5:S?u.push([T(),M()],[x(),P()]):u.push([T(),x()],[P(),M()]);break;case 10:S?u.push([T(),x()],[P(),M()]):u.push([T(),M()],[x(),P()]);break}}const d=Sb(u);return e.smooth===!1?d:d.map(f=>_0(_0(f)))}function Sb(t){const e=o=>`${Math.round(o.x*1e3)},${Math.round(o.y*1e3)}`,n=new Map;t.forEach(([o,r],a)=>{for(const l of[o,r]){const c=e(l);n.has(c)||n.set(c,[]),n.get(c).push(a)}});const s=new Array(t.length).fill(!1),i=[];for(let o=0;o<t.length;o++){if(s[o])continue;s[o]=!0;const r=[t[o][0],t[o][1]];let a=t[o][1];for(;;){const l=(n.get(e(a))??[]).find(u=>!s[u]);if(l===void 0)break;s[l]=!0;const[c,h]=t[l];if(a=e(c)===e(a)?h:c,e(a)===e(r[0]))break;r.push(a)}r.length>=3&&i.push(r)}return i}function _0(t){const e=[];for(let n=0;n<t.length;n++){const s=t[n],i=t[(n+1)%t.length];e.push({x:s.x*.75+i.x*.25,y:s.y*.75+i.y*.25},{x:s.x*.25+i.x*.75,y:s.y*.25+i.y*.75})}return e}function xb(t){const e=Math.min(1,Math.max(0,t.progress));if(e<=0)return[];const n=t.width/2,s=n*(.55+.75*e),i=Math.max(t.length*e,s*1.2),o=t.x,r=t.y+i-s,a=Math.max(.1,n*(.35-.3*e)),l=r-Math.sqrt(Math.max(0,s*s-a*a)),c=Math.max(0,l-t.y),h=8,u=[],d=[];for(let v=0;v<=h;v++){const k=v/h,y=a+(n-a)*Math.pow(1-k,1.6+1.4*e);u.push({x:o-y,y:t.y+c*k}),d.push({x:o+y,y:t.y+c*k})}const f=Math.max(8,Math.round(t.segments??12)),p=Math.acos(Math.min(1,a/s)),g=-p,m=Math.PI+p,w=[];for(let v=1;v<f;v++){const k=g+(m-g)*v/f;w.push({x:o+Math.cos(k)*s,y:r+Math.sin(k)*s})}return[...d,...w,...u.reverse()]}function Tb(t){const e=Math.min(1,Math.max(0,t.grow??1)),n=e>=1?1:1-Math.pow(1-e,3)+.08*Math.sin(e*Math.PI)*e,s=t.r*Math.max(0,n);if(s<=0)return[];const i=Math.max(12,Math.round(t.segments??48)),o=t.wobble??.05,r=t.time??0,a=t.period?r/t.period:r/2500,l=(a-Math.floor(a))*Math.PI*2,c=t.seed??0,h=[];for(let u=0;u<i;u++){const d=u/i*Math.PI*2,f=1+o*(Math.sin(2*d+l+c)*.6+Math.sin(3*d-2*l+c*1.7)*.4);h.push({x:t.x+Math.cos(d)*s*f,y:t.y+Math.sin(d)*s*f})}return h}function Eb(t){const e=t.progress;if(e<=0||e>=1)return[];const n=Math.max(3,Math.round(t.pieces??8)),s=[],i=t.r*(1+1.2*e),o=Math.PI*2/n*.6*(1-e);for(let r=0;r<n;r++){const a=r/n*Math.PI*2+.3,l=[];for(let c=0;c<=4;c++){const h=a-o/2+o*c/4;l.push({x:t.x+Math.cos(h)*i,y:t.y+Math.sin(h)*i})}s.push(l)}return s}function Ab(t,e={}){const n=Math.max(.05,1+t);return{sx:e.keep==="volume"?1/Math.sqrt(n):1/n,sy:n}}function $b(t,e,n={x:0,y:0}){return t.map(s=>({x:n.x+(s.x-n.x)*e.sx,y:n.y+(s.y-n.y)*e.sy}))}function Xs(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function se(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function fn(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function $e(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Gs(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 io(t){return Math.hypot(t[0],t[1],t[2])}function Us(t,e){return io(se(t,e))}function Jt(t){const e=io(t);return e===0?[0,0,0]:fn(t,1/e)}function gn(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 Pb=Object.freeze(Object.defineProperty({__proto__:null,add:Xs,cross:Gs,distance:Us,dot:$e,length:io,lerp:gn,normalize:Jt,scale:fn,subtract:se},Symbol.toStringTag,{value:"Module"})),Ib=Math.PI/180;function oo(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function Rt(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 pn(t){return[1,0,0,0,0,1,0,0,0,0,1,0,t[0],t[1],t[2],1]}function mn(t){return[t[0],0,0,0,0,t[1],0,0,0,0,t[2],0,0,0,0,1]}function pe(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 va(t,e,n){const s=pe(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 Ob(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 Ma(t){const[e,n,s,i,o,r,a,l,c,h,u,d,f,p,g,m]=t,w=e*r-n*o,v=e*a-s*o,k=e*l-i*o,y=n*a-s*r,x=n*l-i*r,P=s*l-i*a,M=c*p-h*f,T=c*g-u*f,S=c*m-d*f,E=h*g-u*p,$=h*m-d*p,A=u*m-d*g,I=w*A-v*$+k*E+y*S-x*T+P*M;if(Math.abs(I)<1e-12)return null;const C=1/I;return[(r*A-a*$+l*E)*C,(s*$-n*A-i*E)*C,(p*P-g*x+m*y)*C,(u*x-h*P-d*y)*C,(a*S-o*A-l*T)*C,(e*A-s*S+i*T)*C,(g*k-f*P-m*v)*C,(c*P-u*k+d*v)*C,(o*$-r*S+l*M)*C,(n*S-e*$-i*M)*C,(f*x-p*k+m*w)*C,(h*k-c*x-d*w)*C,(r*T-o*E-a*M)*C,(e*E-n*T+s*M)*C,(p*v-f*y-g*w)*C,(c*y-h*v+u*w)*C]}function _b(t,e,n,s){const i=1/Math.tan(t*Ib/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 Cb(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 Hb(t,e,n=[0,1,0]){const s=Jt(se(t,e)),i=Jt(Gs(n,s)),o=Gs(s,i);return[i[0],o[0],s[0],0,i[1],o[1],s[1],0,i[2],o[2],s[2],0,-$e(i,t),-$e(o,t),-$e(s,t),1]}function ie(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 Rb=Object.freeze(Object.defineProperty({__proto__:null,compose:va,fromQuat:pe,identity:oo,invert:Ma,lookAt:Hb,multiply:Rt,orthographic:Cb,perspective:_b,scaling:mn,transformPoint:ie,translation:pn,transpose:Ob},Symbol.toStringTag,{value:"Module"})),ro={"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]},C0={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 Lb(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}Wt({type:"bounce",mode:"in"}),Wt({type:"bounce",mode:"in-out"});function Vs(t){const e=H0.get(t.trim().toLowerCase());if(e)return e;const n=Lb(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:Wt(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 ro)return{easing:{type:"cubic-bezier",points:ro[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:Wt(h)}}return n in C0?{easing:C0[n]}:n in ro?{easing:{type:"cubic-bezier",points:ro[n]}}:{easing:"ease-out"}}const H0=new Map;function Sa(t,e){return H0.set(t.trim().toLowerCase(),e.bezier?{easing:{type:"cubic-bezier",points:e.bezier},fn:e.fn}:{fn:e.fn,requiresBaking:"custom"}),t}function xa(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 R0=/^\s*random\(\s*(\[.*\]|[^)]*)\s*\)\s*$/;function L0(t){return typeof t=="string"&&R0.test(t)}function Fb(t=1){let e=xa(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 F0(l,c,1/0);if("values"in l)return F0(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]=zs(l[d])(l[d],c[d],h);return u}return zs(l)(l,c,h)}),wrap:((l,c,h)=>{if(Array.isArray(l)){const g=l,m=w=>g[(Math.round(w)%g.length+g.length)%g.length];return c===void 0?m:m(c)}const u=l,f=c-u,p=g=>f===0?u:((g-u)%f+f)%f+u;return h===void 0?p:p(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,p,g)=>{const m=g.length,v=ji(f,m,{...c!==void 0?{amount:c}:{each:h??1},from:u}),k=c!==void 0?c:(h??1)*Yr(m,u),y=d&&k>0?d(v/k)*k:v;return l+y},pipe:(...l)=>c=>l.reduce((h,u)=>u(h),c),splitColor:l=>Nb(l),getUnit:l=>typeof l=="number"?"":/^-?[\d.]+(?:e[-+]?\d+)?([a-z%]*)$/i.exec(l.trim())?.[1]??"",seed:l=>{e=xa(l)},resolveRandomString:l=>{const c=R0.exec(l)?.[1]??"";if(c.startsWith("[")){const p=c.slice(1,-1).split(",").map(g=>g.trim()).filter(Boolean).map(g=>Number.isFinite(Number(g))?Number(g):g.replace(/^['"]|['"]$/g,""));return p[Math.floor(e()*p.length)]}const[h,u,d]=c.split(",").map(f=>Number.parseFloat(f));return r(h,u,Number.isFinite(d)?d:void 0)}}}function F0(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 Nb(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 Wb=/^([+-])=\s*(-?[\d.]+)$/,Db=/^([<>])\s*(?:([+-])?=?\s*(-?[\d.]+))?$/;function Js(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=Wb.exec(i);if(o){const c=s(o[2]);return e.cursor+(o[1]==="-"?-c:c)}const r=Db.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 Bb(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 zb(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=p=>({x:p%s,y:Math.floor(p/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=p=>{const{x:g,y:m}=o(p),w=Math.abs(g-a.x),v=Math.abs(m-a.y);return e.axis==="x"?w:e.axis==="y"?v:Math.hypot(w,v)};let c=Array.from({length:t},(p,g)=>l(g));const h=Math.max(...c);if(r==="edges"&&(c=c.map(p=>h-p)),r==="random"){const p=n.random??Math.random;c=c.map(()=>p()*h)}const u=e.amount!==void 0?e.amount:(e.each??0)*h,d=e.ease?Vs(e.ease):void 0,f=d?d.fn??Wt(d.easing):void 0;return c.map(p=>{const g=h===0?0:p/h;return(f?f(g):g)*u})}const Ta=new Set(["duration","delay","ease","repeat","repeatDelay","yoyo","stagger","onComplete","onUpdate","onStart","onRepeat","onReverseComplete","repeatRefresh","keyframes","easeEach","scrollTo","id","immediateRender","overwrite","paused","scrollTrigger","spring"]),qb={rotation:"rotate",rotationZ:"rotate",rotationX:"rotateX",rotationY:"rotateY",transformPerspective:"perspective",perspective:"childPerspective"};function ao(t){const e={},n={};for(const[s,i]of Object.entries(t))Ta.has(s)?e[s]=i:n[qb[s]??s]=i;return{config:e,properties:n}}function lo(t,e){return t===void 0?e:t*1e3}function Ea(t,e){if(t!==void 0)return typeof t=="number"?{each:t*1e3}:Bb(t)?{offsets:zb(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 jb={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 N0(t){return jb[t]}function Yb(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=E0(e.path,{curviness:e.curviness});else if(Bn(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 Kb(t){const e=typeof t=="string"||Array.isArray(t)?{path:t}:{...t};return{...e,start:e.end??1,end:e.start??0}}function W0(t){return typeof t=="object"&&t!==null&&"shape"in t?t.shape:t}function Xb(t){if(t.morphSVG===void 0)return t;const{morphSVG:e,...n}=t,s=W0(e);if(typeof s!="string"||!Bn(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 Gb(t,e){if(t===!0)return[0,e];if(t===!1)return[0,0];if(typeof t=="number")return[0,D0(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 D0(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 Ub(t,e){const[n,s]=Gb(t,e);return{strokeDasharray:[s-n,e],strokeDashoffset:-n}}function Vb(t,e){if(t.drawSVG===void 0)return t;const{drawSVG:n,...s}=t;return{...s,...Ub(n,e)}}function Jb(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 D0(t,e){return Math.max(0,Math.min(e,t))}function Zb(t){let e=2166136261;for(let n=0;n<t.length;n++)e=Math.imul(e^t.charCodeAt(n),16777619);return e>>>0}function Qb(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??Zb(`${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 Aa(t){return Math.max(.1,t/25)}function tw(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?Aa(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(Fs(i))]:n.end!==void 0&&(i.end=Array.isArray(n.end)?[...n.end]:n.end),i}function ew(t){const e=t===!0?{}:typeof t=="string"?{preset:t}:t;if(e.preset!==void 0&&!(e.preset in Xi))throw new Error(`gsap-compat: unknown spring preset "${e.preset}" — use one of ${Object.keys(Xi).join(", ")}`);return{...e.preset?Xi[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 nw(t,e){if(t===!0||typeof t=="string")return;const n=t.velocity;return typeof n=="number"?n:n?.[e]}class yn{timeline;options;cursor=0;fallbackRandom=xa(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,Zs(n),s)}from(e,n,s){const{config:i,properties:o}=ao(Zs(n)),{motionPath:r,text:a,scrambleText:l,...c}=o,h=this.targetsOf(e)[0],u={...i};for(const p of Object.keys(c))u[p]=this.resolveStart(h,p);r!==void 0&&(u.motionPath=Kb(r));const d={},f=String(this.resolveStart(h,"text"));return a!==void 0&&(d.text=$a(a),u.text=typeof a=="object"?{...a,value:f}:f),l!==void 0&&(d.text=$a(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}=ao(Zs(n));return this.build(e,o,Zs(s),i)}set(e,n,s){return this.build(e,void 0,{...Zs(n),duration:0},s)}get lastStart(){return this.previousStart}get lastEnd(){return this.previousEnd}addEvent(e){const n=Math.max(0,Js(e,this.context()));return this.previousStart=n,this.previousEnd=n,this.cursor=Math.max(this.cursor,n),n}timeOf(e){return Js(e,this.context())}addLabel(e,n){return this.labels.set(e,Js(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=Js(n,this.context());for(const o of e.timeline.tracks){if(!("keyframes"in o))continue;const r=Qi({...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}=ao(s),{motionPath:a,text:l,scrambleText:c,inertia:h,...u}=r,d=this.targetsOf(e),f=Js(i,this.context()),p=lo(o.delay,0),g=lo(o.duration,500),m=Ea(o.stagger,{count:d.length,columnsFromLayout:this.options.layoutColumns?()=>this.options.layoutColumns(d):void 0,random:this.options.random??this.fallbackRandom}),w=this.easingFor(o.ease),v=[],k=o.spring;let y=0,x=!1;for(const[$,A]of Object.entries(u)){const I=A;let C=n?.[$]!==void 0?n[$]:this.resolveStart(d[0],$);if(typeof C!=typeof I&&(this.warn(`no usable start value for "${$}" on "${d[0]}" — it will snap to ${String(I)}. Use fromTo() to animate it.`),C=I),k!==void 0&&(typeof C!="number"||typeof I!="number")&&this.warn(`spring works on numbers, so "${$}" on "${d[0]}" eases instead`),k!==void 0&&typeof C=="number"&&typeof I=="number"){const V={...ew(k),from:C,to:I,velocity:nw(k,$)??this.options.startVelocity?.(d[0],$)??0},et=this.nextTrackId(`${d[0]}-${$}-spring`),G={id:et,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:$,kind:"spring",spring:V,delay:f+p};this.timeline.addTrack(G),v.push(et),y=Math.max(y,wh(V));for(const F of d)this.lastValues.set(`${F}|${$}`,I);continue}x=!0;const D=this.keyframesFor(C,I,g,w,o.ease),j=this.nextTrackId(`${d[0]}-${$}`);this.timeline.addTrack(Qi({id:j,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:$,delay:f+p,keyframes:D,...$==="quaternion"&&{interpolation:"slerp"}})),v.push(j);for(const V of d)this.lastValues.set(`${V}|${$}`,I)}const P=Qb({text:l,scrambleText:c},d[0],g);if(P){const $=n?.text??n?.scrambleText,A=$!==void 0?$a($):this.resolveStart(d[0],"text"),I=this.nextTrackId(`${d[0]}-text`),C={id:I,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:"text",textConfig:{from:typeof A=="string"?A:String(A??""),...P},delay:f+p,keyframes:this.keyframesFor(0,1,g,w,o.ease)};this.timeline.addTrack(C),v.push(I);for(const D of d)this.lastValues.set(`${D}|text`,P.to)}if(a!==void 0){const{config:$,start:A,end:I}=Yb(a),C=this.nextTrackId(`${d[0]}-motionPath`),D={id:C,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:"motionPath",motionPathConfig:$,delay:f+p,keyframes:this.keyframesFor(A,I,g,w,o.ease)};this.timeline.addTrack(D),v.push(C)}if(h!==void 0)for(const[$,A]of Object.entries(h)){const I=this.resolveStart(d[0],$);if(typeof I!="number"){this.warn(`inertia on "${$}" needs a numeric start value; skipped`);continue}const C=tw(I,A),D=this.nextTrackId(`${d[0]}-${$}-inertia`),j={id:D,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:$,kind:"inertia",inertia:C,delay:f+p};this.timeline.addTrack(j),v.push(D),y=Math.max(y,Wn(C));for(const V of d)this.lastValues.set(`${V}|${$}`,Nn(C))}const S=((h!==void 0||k!==void 0)&&!x&&!P&&a===void 0?y:Math.max(g,y))+(m&&d.length>1?Rs(d.length,m):0),E=f+p+S;return this.previousStart=f+p,this.previousEnd=E,this.cursor=Math.max(this.cursor,E),{trackIds:v,start:f+p,end:E,kill:()=>{for(const $ of v)this.timeline.removeTrack($)}}}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"?Vs(o):void 0;if(a?.requiresBaking==="custom"||this.options.bakeEases&&Hs(i)){const c=a?.fn??Wt(i);return[r,...la(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=N0(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 Vs(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 $a(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 sw(t){return new yn(t)}function Zs(t){return Jb(Xb(t))}function iw(t){return!Array.isArray(t)||t.length!==4?null:`matrix3d(${pe(ze(t)).map(n=>Math.round(n*1e6)/1e6+0).join(", ")})`}const ow=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),rw="#ffffff",aw="rgba(0, 0, 0, 0.5)";function lw(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??rw})`),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??aw})`)}return e.length>0?e.join(" "):null}function cw(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 hw(t){if(!("ownerSVGElement"in t))return;const e=t.style;!e||e.transformBox||(e.transformBox="fill-box",e.transformOrigin||(e.transformOrigin="50% 50%"))}const B0=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"]),uw=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),dw=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],fw=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),gw=new Set(["originX","originY"]),pw=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),mw=new Set(["drawOn"]),yw={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},z0={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},bw="http://www.w3.org/2000/svg";class bn{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[p,g]of n)if(!(p==="x"&&l)&&!(p==="y"&&c)&&!((p==="rotate"||p==="rotateZ")&&h)&&!mw.has(p)){if(uw.has(p))(s??={})[p]=g;else if(fw.has(p))typeof g=="number"&&((i??={})[p]=g);else if(gw.has(p))typeof g=="number"&&((o??={})[p]=g);else if(pw.has(p))typeof g=="number"&&((r??={})[p]=g);else if(ow.has(p))(a??={})[p]=g;else if(p!=="perspective"){if(p!=="shine")if(p==="text"&&typeof g=="string")cw(e,g);else if(p==="d"&&typeof g=="string"){const m=e;(m.tagName?.toLowerCase()==="path"?m:m.querySelector?.("path"))?.setAttribute?.("d",g)}else this.applyStyleProperty(e,p,g)}}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 p of dw){const g=s[p];if(g===void 0)continue;const m=this.buildTransformPart(p,g);m&&d.push(m)}if(d.length>0&&(e.style.transform=d.join(" "),hw(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 p=o.originX??50,g=o.originY??50;e.style.transformOrigin=`${p}% ${g}%`}if(r){const p=r.clipTop??0,g=r.clipRight??0,m=r.clipBottom??0,w=r.clipLeft??0;e.style.clipPath=`inset(${p}% ${g}% ${m}% ${w}%)`}if(a){const p=lw(a);p&&(e.style.filter=p)}}buildTransformPart(e,n){if(e==="quaternion")return iw(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===bw&&n in z0){const a=Array.isArray(s)?s.join(", "):String(s);e.style[z0[n]]=a;return}else n==="fill"&&e.dataset?.elementType==="text"?i="color":i=yw[n]??n;let r;typeof s=="number"?B0.has(n)||B0.has(i)?r=`${s}px`:r=String(s):Array.isArray(s)?r=s.join(", "):r=s,e.style[i]=r}}const ww={request:t=>requestAnimationFrame(t),cancel:t=>cancelAnimationFrame(t)};class q0{adapter=new bn;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=Fb();active=new Map;applied=new Map;dirty=new Set;frameId=null;lastTimestamp=null;destroyed=!1;constructor(e={}){this.scheduler=e.scheduler??ww,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);Pa(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(Pa(e))return[e];if(!kw(e))return[e];const n=[];for(const s of Array.from(e))n.push(...this.targetsOf(s));return n}nameFor(e){return Pa(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 Pa(t){return typeof t=="object"&&t!==null&&t.nodeType===1}function kw(t){if(Array.isArray(t))return!0;const e=t;return typeof e.length=="number"&&typeof e.item=="function"}function co(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 j0=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function vw(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function Mw(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 Sw(t,e){const n=typeof t=="string"||Array.isArray(t)||j0(t)?{path:t}:t,{align:s,alignOrigin:i,path:o,...r}=n,a=P=>{const M=j0(P)?P:e.query(P);return M||e.warn(`gsap-compat: motionPath could not find "${String(P)}"`),M};let l=null,c="";if(Array.isArray(o)||typeof o=="string"&&Bn(o))c=o;else{l=a(o);const P=l&&eo({tag:l.localName,attributes:vw(l)});l&&!P&&e.warn(`gsap-compat: motionPath element <${l.localName}> has no path geometry`),c=P??""}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,p,g,m,w,v]=Mw(u),k=co(d),[y,x]=i??[.5,.5];for(const P of e.targets.slice(1)){const M=co(P);if(Math.abs(M.left-k.left)>.5||Math.abs(M.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,p,g,m,w-k.left-y*k.width,v-k.top-x*k.height],h}const Y0=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function K0(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function X0(t){if(!t)return null;const e=eo({tag:t.localName,attributes:K0(t)});return e||(t.querySelector("path")?.getAttribute("d")??null)}function xw(t,e,n){const s=W0(t);if(typeof s=="string"&&Bn(s))return s;const i=Y0(s)?s:typeof s=="string"?e(s):null,o=X0(i);return o||(n(`gsap-compat: morphSVG could not find a shape for "${String(s)}"`),"")}const Tw=new Set(["cx","cy","r","rx","ry","x","y","width","height","x1","y1","x2","y2","points"]);function Ew(t,e=document){return(typeof t=="string"?Array.from(e.querySelectorAll(t)):Y0(t)?[t]:Array.from(t)).map(s=>{if(s.localName==="path")return s;const i=eo({tag:s.localName,attributes:K0(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))Tw.has(r.name)||o.setAttribute(r.name,r.value);return o.setAttribute("d",i),s.parentNode.replaceChild(o,s),o})}const G0=.3;class U0{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=V0(),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=V0(),i=Math.max(1,s-this.lastTime);this.lastTime=s;const o=e/i*1e3,r=n/i*1e3;this.velocityX+=(o-this.velocityX)*G0,this.velocityY+=(r-this.velocityY)*G0}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 V0(){return typeof performance<"u"?performance.now():Date.now()}function J0(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 Z0(t,e){return e<=0?[]:t.map(n=>Math.round(n/e)*e)}class Ia{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 U0({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=Aw(i/s);e.pause(),e.seek(o*n)}applyConstraints(e,n){let s=e;const i=[...Z0([s],this.options.snap??0),...(n==="x"?this.options.snapLinesX:this.options.snapLinesY)??[]],o=J0([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 Aw(t){return t<0?0:t>1?1:t}function $w(t){const e=new Ia(t);return e.start(),e}const Pw={x:"x",y:"y","x,y":"both"},Oa=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function Q0(t,e){const n=co(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 tu(t){return Array.isArray(t)?[...t]:t}function Iw(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 Ow(t,e,i,o,s);const r=Pw[s.type??"x,y"],a=()=>{const g=e.appliedValue(i,"x"),m=e.appliedValue(i,"y");return{x:typeof g=="number"?g:0,y:typeof m=="number"?m:0}},l=typeof s.bounds=="string"?e.query(s.bounds):Oa(s.bounds)?s.bounds:null,h={bounds:(!l&&s.bounds&&!Oa(s.bounds)?s.bounds:void 0)??(l?Q0(o,l):void 0)};let u=null;const d=()=>{u?.kill(),u=null},f=g=>{const m=s.inertia===!0?{}:s.inertia,w=m.friction??(m.resistance!==void 0?Aa(m.resistance):4),v=a(),k=h.bounds??{};let y,x;const P=m.end;if(Array.isArray(P)){const T=Fs({from:v.x,velocity:r==="y"?0:g.x,friction:w}),S=Fs({from:v.y,velocity:r==="x"?0:g.y,friction:w});let E=P[0];for(const $ of P)Math.hypot($.x-T,$.y-S)<Math.hypot(E.x-T,E.y-S)&&(E=$);E&&(y=[E.x],x=[E.y])}else typeof P=="number"?(y=P,x=P):P&&(y=tu(P.x),x=tu(P.y));const M={};r!=="y"&&(M.x={velocity:g.x,friction:w,min:k.minX,max:k.maxX,end:y}),r!=="x"&&(M.y={velocity:g.y,friction:w,min:k.minY,max:k.maxY,end:x}),u=t.to(o,{inertia:M,onComplete:()=>s.onThrowComplete?.()})},p=new Ia({target:o,axis:r,snap:s.snap,get bounds(){return h.bounds},getPosition:a,onPress:()=>{d(),l&&(h.bounds=Q0(o,l)),s.onPress?.()},onDrag:g=>{e.apply(i,r==="x"?{x:g.x}:r==="y"?{y:g.y}:{x:g.x,y:g.y}),s.onDrag?.(g)},onRelease:()=>{const g=p.velocity;s.onRelease?.(g),s.inertia&&f(g)}});return p.start(),{draggable:p,get position(){return a()},get rotation(){const g=e.appliedValue(i,"rotate");return typeof g=="number"?g:0},destroy(){d(),p.destroy()}}}function Ow(t,e,n,s,i){const o=typeof i.bounds=="object"&&i.bounds!==null&&!Oa(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,u={x:0,y:0},d=0,f=0,p=[];const g=k=>Math.atan2(k.clientY-u.y,k.clientX-u.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();u={x:y.left+y.width/2,y:y.top+y.height/2},d=g(k),f=r(),p=[{time:performance.now(),rotation:f}],i.onPress?.()},w=k=>{if(!c||k.pointerId!==h)return;const y=g(k);let x=y-d;x>180&&(x-=360),x<-180&&(x+=360),d=y,f+=x;let P=a(f);i.snap&&(P=a(Math.round(P/i.snap)*i.snap)),e.apply(n,{rotate:P});const M=performance.now();for(p.push({time:M,rotation:P});p.length>2&&M-p[0].time>100;)p.shift();const T={x:0,y:0};i.onDrag?.(T)},v=k=>{if(!c||k.pointerId!==h)return;c=!1;const y=p[0],x=p[p.length-1],P=y&&x?(x.time-y.time)/1e3:0,M=P>0?(x.rotation-y.rotation)/P:0;if(i.onRelease?.({x:M,y:0}),!i.inertia)return;const T=i.inertia===!0?{}:i.inertia,S=T.friction??(T.resistance!==void 0?Aa(T.resistance):4),E=typeof T.end=="number"||Array.isArray(T.end)?T.end:void 0;l=t.to(s,{inertia:{rotate:{velocity:M,friction:S,min:o.minRotation,max:o.maxRotation,end:Array.isArray(E)?E.filter($=>typeof $=="number"):E}},onComplete:()=>i.onThrowComplete?.()})};return s.addEventListener("pointerdown",m),s.addEventListener("pointermove",w),s.addEventListener("pointerup",v),s.addEventListener("pointercancel",v),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",w),s.removeEventListener("pointerup",v),s.removeEventListener("pointercancel",v)}}}const _w={opacity:0,scale:.6};function Cw(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 eu(t){const e=co(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 _a(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=Cw(r);i.set(r,a);const l=nu(r);a&&l!==void 0&&!o.has(l)&&o.set(l,{element:r,box:a})}return{elements:s,boxes:i,ids:o}}const Ca=new WeakMap;function Ha(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?_w:s.enter,c=new Set(n.elements);if(s.targets!==void 0)for(const f of t.resolveTargets(s.targets)){const p=t.elementFor(f);p&&c.add(p)}const h=[...c].sort((f,p)=>f===p?0:f.compareDocumentPosition(p)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1),u=e({onComplete:s.onComplete});let d=0;for(const f of h){const p=eu(f);if(!p)continue;let g=n.boxes.get(f)??null,m;const w=nu(f),v=!g&&w!==void 0?n.ids.get(w):void 0;v&&v.element!==f&&(g=v.box,m=v.element);const[k]=t.resolveTargets(f);Ca.get(f)?.timeline.removeTracks({target:k});const y=d*r;if(!g){if(l===!1)continue;u.fromTo(f,{x:0,y:0,scaleX:1,scaleY:1,...l},{...su(l),x:0,y:0,scaleX:1,scaleY:1,duration:i,ease:o,delay:y},0),Ca.set(f,u),d++;continue}const x=g.cx-p.cx,P=g.cy-p.cy,M=a?g.width/p.width:1,T=a?g.height/p.height:1;if(!(Math.abs(x)>.5||Math.abs(P)>.5||Math.abs(M-1)>.001||Math.abs(T-1)>.001)){const $=(A,I)=>{const C=t.appliedValue(k,A);return typeof C=="number"&&Math.abs(C-I)>1e-6};($("x",0)||$("y",0)||$("scaleX",1)||$("scaleY",1))&&u.set(f,{x:0,y:0,scaleX:1,scaleY:1},0);continue}const E=s.fade===!0&&m!==void 0;u.fromTo(f,{x,y:P,scaleX:M,scaleY:T,...E&&{opacity:0}},{x:0,y:0,scaleX:1,scaleY:1,...E&&{opacity:1},duration:i,ease:o,delay:y},0),E&&m&&eu(m)&&u.fromTo(m,{opacity:1},{opacity:0,duration:i,ease:o,delay:y},0),Ca.set(f,u),d++}return u}function nu(t){return t.dataset?.flipId}function su(t){const e={};for(const n of Object.keys(t))e[n]=n==="opacity"||n.startsWith("scale")?1:0;return e}function Hw(t,e={}){const n=new Set((e.type??"chars,words,lines").split(",").map(g=>g.trim())),s={chars:e.charsClass??"char",words:e.wordsClass??"word",lines:e.linesClass??"line"},i=e.aria!==!1,o=t.map(g=>({element:g,html:g.innerHTML,ariaLabel:g.getAttribute("aria-label")}));let r={chars:[],words:[],lines:[],masks:[]},a,l,c=!1;const h=()=>{for(const{element:g,html:m,ariaLabel:w}of o)g.innerHTML=m,w===null?g.removeAttribute("aria-label"):g.setAttribute("aria-label",w)},u=()=>{a&&(a.revert?a.revert():a.kill?.(),a=void 0)},d=()=>{const g={chars:[],words:[],lines:[],masks:[]};for(const{element:m}of o){const w=(m.textContent??"").replace(/\s+/g," ").trim(),v=Rw(m,s.words),k=n.has("chars")?v.flatMap(P=>Lw(P,s.chars)):[],y=n.has("lines")?Nw(m,v,s.lines):[];if(i){!m.hasAttribute("aria-label")&&w&&m.setAttribute("aria-label",w);for(const P of v)P.setAttribute("aria-hidden","true")}if(n.has("words"))g.words.push(...v);else for(const P of v)P.removeAttribute("class");g.chars.push(...k),g.lines.push(...y);const x=e.mask==="lines"?y:e.mask==="words"?v:e.mask==="chars"?k:[];for(const P of x)g.masks.push(Ww(P,`${s[e.mask]}-mask`))}r=g},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&&p();function p(){const g=new Map;let m=!1;const w=()=>{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 x of k){const P=Math.round(x.contentRect.width),M=g.get(x.target);g.set(x.target,P),M!==void 0&&M!==P&&(y=!0)}y&&w()});for(const k of t)l.observe(k)}const v=t[0]?.ownerDocument?.fonts;v&&v.status!=="loaded"&&v.ready.then(()=>w())}return f}function Rw(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 Lw(t,e){const n=t.ownerDocument,s=Fw(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 Fw(t){const e=Intl.Segmenter;return e?Array.from(new e(void 0,{granularity:"grapheme"}).segment(t),n=>n.segment):Array.from(t)}function Nw(t,e,n){const s=t.ownerDocument,i=new Map(e.map(p=>[p,p.getBoundingClientRect()])),o=[],r=p=>{for(const g of Array.from(p.childNodes))g.nodeType===3||i.has(g)||g.tagName==="BR"?o.push(g):r(g)};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 p of o){if(p.tagName==="BR"){u=!0;continue}const g=i.get(p);if(g&&(!l||u||g.top>c+h)&&(f(),c=g.top,h=g.height/2,u=!1),!l)continue;const m=[];for(let k=p.parentNode;k&&k!==t;k=k.parentNode)m.unshift(k);let w=0;for(;w<d.length&&w<m.length&&d[w].original===m[w];)w++;d.length=w;let v=w===0?l:d[w-1].clone;for(const k of m.slice(w)){const y=k.cloneNode(!1);v.appendChild(y),d.push({original:k,clone:y}),v=y}v.appendChild(p)}return t.replaceChildren(...a),a}function Ww(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 iu={top:0,left:0,start:0,center:.5,centre:.5,middle:.5,bottom:1,right:1,end:1};function Ra(t){const e=t.trim().toLowerCase();if(e in iu)return iu[e];if(e.endsWith("%")){const n=Number.parseFloat(e.slice(0,-1));return Number.isNaN(n)?void 0:n/100}}function La(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?Ra(s[0]):void 0,o=s[1]!==void 0?Ra(s[1]):void 0;return{elementFraction:i??0,viewportFraction:o??0,offsetPx:e}}function Kn(t,e,n){const s=La(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 Dw(t,e,n,s){const i=Kn(t,e,n),r=Kn(t,e,s)-i;return r<=0?i<=0?1:0:Fa(-i/r)}function Fa(t){return t<0?0:t>1?1:t===0?0:t}function ou(t,e,n,s){if(n<=0)return e;const i=1-Math.exp(-(s/1e3)/n);return t+(e-t)*i}function Na(t,e,n,s,i){const o=h=>Kn({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 ru{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 Bw(t){const e=new ru(t);return e.start(),e}class au{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 zw=.15;function lu(t){return typeof t=="object"&&!Array.isArray(t)?t:{snapTo:t}}function cu(t,e,n){const s=ho(t+e*zw);if(typeof n=="function")return ho(n(s));if(typeof n=="number")return n<=0?t:ho(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 ho(i)}function hu(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 uu{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=Ns,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 ho(t){return Math.max(0,Math.min(1,t))}class du{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 qw=120,Xn=[],Gn=new Set;let Wa=!1;const jw=()=>{Wa||Gn.size===0||(Wa=!0,queueMicrotask(()=>{Wa=!1;for(const t of Gn)t.afterRefresh()}))},fu=()=>{for(const t of Gn)t.beforeRefresh();for(const t of Xn)t.refresh();for(const t of Gn)t.afterRefresh()};let Un={width:0,height:0};const gu=()=>{const t=window.innerWidth,e=window.innerHeight,n=t===Un.width&&e!==Un.height,s=Math.abs(e-Un.height)<Un.height*.25,i=typeof navigator<"u"&&(navigator.maxTouchPoints??0)>0;n&&s&&i||(Un={width:t,height:e},fu())};class Qs{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 uu(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 au(e,{axis:this.options.horizontal?"x":"y",spacing:this.options.pinSpacing!==!1})),this.options.markers&&!this.options.horizontal&&typeof document<"u"&&(this.markers=new du(document,this.options.scroller??null,this.options.markers)),this.scrollTarget()?.addEventListener("scroll",this.onScroll,{passive:!0}),Xn.length===0&&typeof window<"u"&&(Un={width:window.innerWidth,height:window.innerHeight},window.addEventListener("resize",gu,{passive:!0})),Xn.push(this),this.refresh()}stop(){this.running&&(this.running=!1,this.scrollTarget()?.removeEventListener("scroll",this.onScroll),Xn.splice(Xn.indexOf(this),1),Xn.length===0&&typeof window<"u"&&window.removeEventListener("resize",gu),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(){fu()}static onRefresh(e){return Gn.add(e),()=>Gn.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+Kn(n,s,ti(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,jw()}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?Fa((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=ti(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+Kn(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()},qw))}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=lu(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+cu(r,this.releaseVelocity/i,n.snapTo)*i;Math.abs(a-o)<1||this.snapper.animate(o,a,hu(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=Na(r,s.width,o,ti(this.options.start)??"left right",e.shiftAt);this.startPx=c(h);const u=ti(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(Na(r,s.width,o,u,e.shiftAt)),this.markerGeometry=null}markersFor(e){const n=(o,r)=>{const a=ti(o)??r;if(typeof a=="number")return 0;if(/^\s*\+=/.test(a))return;const l=La(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=ou(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 ti(t){return typeof t=="function"?t():t}function Yw(t){const e=new Qs(t);return e.start(),e}const Da=new Set,Kw=16,pu=.5,Xw=2;class Ba{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),Da.add(this),this.stopListening=Qs.onRefresh({beforeRefresh:()=>this.rest(),afterRefresh:()=>this.refresh()}),this.refresh(),this}static refreshAll(){for(const e of Da)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),Da.delete(this),this.stopListening?.(),this.stopListening=null,this.cancelFrame(),this.journey=null,this}destroy(){this.stop();for(const e of this.effects)za(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??Ns,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)za(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?Kw: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)<=Xw||(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)<pu&&(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)<pu?i.lagged=s:n=!0,o+=s-i.lagged}za(i.element,o===0?i.saved:`0 ${Gw(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 za(t,e){e?t.style.setProperty("translate",e):t.style.removeProperty("translate")}function Gw(t){return Math.round(t*100)/100}function Uw(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 qa(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,p)=>()=>{p?.(),n&&!a&&Uw(n,l[f]??"none"),e.once&&f===0&&queueMicrotask(()=>h.destroy())},d=e.containerAnimation?Zw(t,e.containerAnimation,r,i):void 0;return h=new Qs({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:Vw(e.snap,n),markers:e.markers,container:d,onUpdate:(f,p)=>{if(n&&a!==!1&&n.progress(f),e.onUpdate){const g=f<c||p<0?-1:1;e.onUpdate({progress:f,velocity:p,direction:g})}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 Vw(t,e){const n=i=>i==="labels"?o=>Jw(o,e?.labelProgresses?.()??[]):i;if(typeof t!="object"||Array.isArray(t))return n(t);const s=t.ease?Vs(t.ease):void 0;return{snapTo:n(t.snapTo),duration:t.duration,delay:t.delay,ease:s?s.fn??Wt(s.easing):void 0}}function Jw(t,e){return e.reduce((n,s)=>Math.abs(s-t)<Math.abs(n-t)?s:n,e[0]??t)}function Zw(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 mu{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 Qw{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 mu(this.host,this.scope);o.conditions=n,o.add(()=>e.setup(o)),e.context=o}}class t2{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 e2={opacity:0,y:-16},n2={opacity:0,y:16};async function s2(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 i2(o,s,r);const a=s.duration??.35,l=s.ease??"power2.inOut",c=m=>new Promise(w=>{m(w)||w()}),h=r(),u=h.length?_a(e,h):void 0,d=s.from!==void 0?yu(e,s.from,s.shared):[];if(d.length&&s.leave!==!1){const m=s.leave??e2;await c(w=>t.to(d,{...m,duration:a,ease:l,onComplete:w}))}await s.update();const f=[],p=typeof s.to=="function"?s.to():s.to,g=p!==void 0?yu(e,p,s.shared):[];if(g.length&&s.enter!==!1){const m=s.enter??n2;f.push(c(w=>t.fromTo(g,m,{...su(m),duration:a,ease:l,onComplete:w})))}if(u){const m=r().filter(w=>!h.includes(w));m.length&&f.push(c(w=>Ha(e,n,u,{targets:m,duration:a*1.4,ease:l,enter:!1,onComplete:w})))}await Promise.all(f)}function yu(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 i2(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 bu={create:(t,e)=>Sa(t,y0(e))},wu={create:(t,e)=>Sa(t,{fn:b0(e)})},ku={create:(t,e)=>Sa(t,{fn:w0(e)})},o2=new Set(["keyframes","duration","delay","ease","easeEach","stagger","repeat","repeatDelay","yoyo","repeatRefresh","paused","id","onStart","onUpdate","onComplete","onRepeat","onReverseComplete","scrollTrigger"]),vu=.5,r2="power1.inOut";function a2(t){return t.keyframes!==void 0&&t.keyframes!==null}function l2(t){const e=t.keyframes,n={};for(const[c,h]of Object.entries(t))o2.has(c)||(n[c]=h);if(Array.isArray(e))return e.map(c=>({...n,...c,duration:c.duration??t.duration??vu}));const s=Object.entries(e),i=t.duration??vu,o=e.easeEach??t.easeEach??r2;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 p=Math.max(0,d-u);h.push({...n,ease:o,...f,duration:p*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 Mu(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=(v,k)=>{if(k===void 0)return r[v];if(typeof k=="number")return k;if(k==="max")return a[v];const y=typeof k=="string"?i.querySelector(k):k;if(!y)return r[v];const x=y.getBoundingClientRect(),P=o?.getBoundingClientRect(),M=(v==="x"?s.offsetX:s.offsetY)??s.offset??0;return v==="x"?x.left-(P?.left??0)+r.x-M:x.top-(P?.top??0)+r.y-M},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"],p=o??window,g=()=>{w.kill(),m()},m=()=>{for(const v of f)p.removeEventListener(v,g)},w=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 v of f)p.addEventListener(v,g,{passive:!0});return w}function c2(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:[]},p={},g=w=>{p[w]!==void 0&&clearTimeout(p[w]),p[w]=void 0;const v=f[w].splice(0);v.length>0&&d[w]?.(v)},m=(w,v)=>{if(d[w]){if(f[w].push(v),r!==void 0&&f[w].length>=r)return g(w);p[w]===void 0&&(p[w]=setTimeout(()=>g(w),o*1e3))}};return i.map(w=>qa(t,{...u,trigger:w,onEnter:()=>m("onEnter",w),onLeave:()=>m("onLeave",w),onEnterBack:()=>m("onEnterBack",w),onLeaveBack:()=>m("onLeaveBack",w)})).filter(w=>w!==void 0)}class Me{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 yn({...s,startValue:(i,o)=>{const r=e.objectFor(i);if(r)return d2(r[o]);const a=e.appliedValue(i,o);if(a!==void 0)return a;if(o==="d")return X0(e.elementFor(i))??void 0;if(o==="text")return e.elementFor(i)?.textContent??void 0;if(o==="strokeDasharray"||o==="strokeDashoffset"){const l=Au(e.elementFor(i));if(l!==void 0)return o==="strokeDasharray"?[l,l]:0}},startVelocity:(i,o)=>e.velocityOf(i,o),layoutColumns:i=>Eu(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=qa(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 a2(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 Me(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}=ua(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,p)=>{i(d,f,p),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=l2(n);if(o.length===0)return;const r=i.length>1?Ea(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?Yi(i.length,r).map(m=>m/1e3):[0],h=this.compat.timeOf(s)/1e3+lo(n.delay,0)/1e3;let u=1/0,d=-1/0;if(l.forEach((m,w)=>{o.forEach((v,k)=>{const y=k===0?h+c[w]:">";this.tween(m,[v],y,([x],P,M)=>this.compat.to(P,x,M)),u=Math.min(u,this.compat.lastStart),d=Math.max(d,this.compat.lastEnd)})}),u===1/0)return;const{onStart:f,onUpdate:p,onComplete:g}=n;f&&this.events.push({time:u,direction:"forward",run:f}),p&&this.ranges.push({start:u,end:d,run:p}),g&&this.events.push({time:d,direction:"forward",run:g})}staggerContext(e){return{count:e.length,columnsFromLayout:()=>Eu(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(u2)||e.some(d=>this.stage.objectFor(d)!==void 0)))){const d=this.targetFor(e[0]);i(n.map(f=>this.prepare(Tu(f,0,d,this.stage.utils,o),e)),e,s);return}const a=n.length-1,{stagger:l,...c}=n[a],h=Ea(l,this.staggerContext(e)),u=h?Yi(e.length,h).map(d=>d/1e3):e.map(()=>0);e.forEach((d,f)=>{const p=f===0?lo(c.delay,0)/1e3+u[0]:0,g=f===0?0:u[f]-u[f-1],m=f===0?s:`<${g<0?"-":"+"}${Math.abs(g).toFixed(6)}`,v=n.map((k,y)=>y===a?{...c,delay:p}:k).map(k=>this.prepare(Tu(k,f,this.targetFor(d),this.stage.utils,o),[d]));i(v,[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=Sw(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=xw(e.morphSVG,i,s),{morphSVG:a,...l}=o;o=r?{...o,morphSVG:r}:l}if(e.drawSVG!==void 0){const r=Au(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=Vb(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 ${f2(e)}`);return}return this.firstElement??=n.map(s=>this.stage.elementFor(s)).find(s=>s!==void 0),n}}function Su(t=new q0){const e=o=>{const{config:r}=ao(o);return new Me(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)??N0(r)},scrollTrigger:o=>s(qa(t,o)),scrollBatch:(o,r)=>c2(t,o,r).map(a=>s(a)),scrollTo:(o,r)=>Mu(i,t,o,r),refreshScroll:()=>{Qs.refreshAll(),Ba.refreshAll()},smoothScroll:(o={})=>{const r=typeof o.scroller=="string"?(t.collector?.scope??t.root).querySelector(o.scroller):o.scroller;return s(new Ba({...o,scroller:r}).start())},context:(o,r)=>{const a=new mu(t,r);return o&&a.add(()=>o(a)),a},matchMedia:o=>new Qw(t,o),customEase:bu.create,customBounce:wu.create,customWiggle:ku.create,pageTransition:o=>s2(i,t,r=>new Me(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 t2(a,r))},quickTo:(o,r,a={})=>{const l=new Me(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:h2(a.spring,r,d)}}),l.timeline.stop(),l.timeline.play(),t.activate(l.timeline)},{tween:l,kill:()=>l.kill()})},timeline:o=>new Me(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 Mu(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 Me(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=>Ew(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(Hw(l,r))},draggable:(o,r)=>s(Iw(i,t,o,r)),getFlipState:o=>_a(t,o),flipFrom:(o,r)=>Ha(t,a=>new Me(t,a),o,r),flip:(o,r,a)=>{const l=_a(t,o);return r(),Ha(t,c=>new Me(t,c),l,{targets:o,...a})}};return i}const oe=Su();function h2(t,e,n){return t===!0?{velocity:{[e]:n}}:typeof t=="string"?{preset:t,velocity:{[e]:n}}:{...t,velocity:{[e]:n}}}function u2(t){return t.morphSVG!==void 0||t.drawSVG!==void 0||t.text!==void 0||t.scrambleText!==void 0||xu(t)}function xu(t){return Object.entries(t).some(([e,n])=>(typeof n=="function"||L0(n))&&!Ta.has(e))}function Tu(t,e,n,s,i){if(!xu(t))return t;const o={};for(const[r,a]of Object.entries(t))Ta.has(r)?o[r]=a:typeof a=="function"?o[r]=a(e,n,i):L0(a)?o[r]=s.resolveRandomString(a):o[r]=a;return o}function Eu(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 Au(t){const e=t;if(typeof e?.getTotalLength=="function")return e.getTotalLength()}function d2(t){if(typeof t=="number"||typeof t=="string"||Array.isArray(t)&&t.every(e=>typeof e=="number"))return t}function f2(t){return typeof t=="string"?`"${t}"`:String(t)}class ja{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 $u(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 uo{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 bn}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=jn({...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 ja(s)})})}syncAllMedia(e,n){for(const s of this.mediaTargets)$u(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 bn;s.querySelectorAll("[data-tinyfly]").forEach(a=>{const l=a.getAttribute("data-tinyfly");l&&r.registerTarget(l,a)}),this.symbolInstances.push({adapter:r,timeline:jn(o.timeline)})})}attachMedia(e,n){this.mediaSync=new ja(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}=ua(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 g2(t,e,n={}){const s=new uo(t,{...n,autoplay:!0});return await s.load(e),s}function p2(t,e={}){return new uo(t,e)}const Pu={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"},Iu="tinyfly-controls-style",m2=`
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,20 +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 g2=0;function p2(t){if(t.getElementById(Pu))return;const e=t.createElement("style");e.id=Pu,e.textContent=f2,t.head.appendChild(e)}function Iu(t,e,n={}){const s=e.ownerDocument;p2(s);const i={...$u,...n.labels},o=n.speeds??[.5,1,2],r=()=>t.markers.length>0,a=()=>t.markers.some(D=>D.label!==void 0||t.caption(D.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=(D,j,V,et="")=>{const G=s.createElement("button");return G.type="button",G.className=`tf-ctl-btn ${et}`.trim(),G.setAttribute("aria-label",D),G.title=D,G.textContent=j,G.addEventListener("click",V),G},u=h(i.restart,"⟲",()=>{t.pause(),t.seek(0)}),d=h(i.prev,"|◀",()=>t.prev()),f=h(i.play,"▶",()=>t.isPlaying?t.pause():g(),"tf-ctl-primary"),p=h(i.next,"▶|",()=>t.next()),g=()=>{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 w=s.createElement("span");w.className="tf-ctl-step";const v=s.createElement("select");v.className="tf-ctl-speed",v.setAttribute("aria-label",i.speed);for(const D of o){const j=s.createElement("option");j.value=String(D),j.textContent=`${D}×`,D===1&&(j.selected=!0),v.appendChild(j)}v.addEventListener("change",()=>t.setSpeed(Number(v.value))),c.append(u,d,f,p,m,w),o.length>0&&c.append(v),l.append(c);const k=n.fullscreen?w2(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 x=s.createElement("div");x.className="tf-ctl-question",x.hidden=!0;const P=s.createElement("span"),M=h(i.reveal,i.reveal,()=>t.play(),"tf-ctl-primary");x.append(P,M),l.append(x);const T=m2(t,s,i.scenario,n.scenarioControl??"buttons");T&&l.append(T.element);const S=n.mount;S?S.appendChild(l):e.insertAdjacentElement("afterend",l);const E=()=>{const D=t.isPlaying;f.textContent=D?"❚❚":"▶",f.setAttribute("aria-label",D?i.pause:i.play),f.title=D?i.pause:i.play;const j=t.duration;s.activeElement!==m&&(m.value=String(j>0?Math.round(t.currentTime/j*1e3):0));const V=t.markers;if(d.hidden=p.hidden=w.hidden=V.length===0,V.length>0){const et=t.currentMarker,G=et?V.indexOf(et)+1:0;w.textContent=i.stepFormat.replace("{index}",String(G)).replace("{total}",String(V.length)),w.setAttribute("aria-label",`${i.step} ${G} ${i.of} ${V.length}`),d.disabled=t.currentTime<=.5,p.disabled=t.currentTime>=j-.5;const F=t.caption()??"";y.textContent!==F&&(y.textContent=F),y.hidden=!a();const H=!D&&et?.question!==void 0&&Math.abs(t.currentTime-et.time)<1;x.hidden=!H,H&&P.textContent!==et.question&&(P.textContent=et.question)}else x.hidden=!0,y.hidden=!0;T?.update()},$=t.subscribe(E);E();const A=n.keyboardScope??e;!A.hasAttribute("tabindex")&&A.tabIndex<0&&(A.tabIndex=0);const I=new WeakSet,C=D=>{if(I.has(D)||(I.add(D),D.defaultPrevented||D.altKey||D.ctrlKey||D.metaKey))return;const j=D.target;if(!(j.tagName==="INPUT"||j.tagName==="SELECT")&&!(D.key===" "&&j.tagName==="BUTTON"))switch(D.key){case" ":D.preventDefault(),t.isPlaying?t.pause():g();break;case"ArrowRight":if(!r())return;D.preventDefault(),t.next();break;case"ArrowLeft":if(!r())return;D.preventDefault(),t.prev();break;case"Home":D.preventDefault(),t.pause(),t.seek(0);break;case"f":case"F":if(!k)return;D.preventDefault(),k.active?k.exit():k.enter();break}};return A.addEventListener("keydown",C),l.addEventListener("keydown",C),{element:l,fullscreen:k&&{get active(){return k.active},enter:k.enter,exit:k.exit},destroy(){k?.destroy(),$(),A.removeEventListener("keydown",C),l.removeEventListener("keydown",C),l.remove()}}}function m2(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 g=i[Number(d.value)];g&&t.setScenario(g.id)}),h.append(u,d,f),{element:h,update:()=>{const g=Math.max(0,i.findIndex(w=>w.id===t.scenario));e.activeElement!==d&&(d.value=String(g));const m=i[g].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-${++g2}`,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 y2='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',b2='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';function w2(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 g=r!==void 0;o.innerHTML=g?b2:y2;const m=g?n.exitFullscreen:n.fullscreen;o.setAttribute("aria-label",m),o.title=m,o.setAttribute("aria-pressed",String(g)),t.classList.toggle("tf-fullscreen",g),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=g=>{g.key==="Escape"&&p()},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 g=i.requestFullscreen?.bind(i)??i.webkitRequestFullscreen?.bind(i),m=s.fullscreenEnabled??s.webkitFullscreenEnabled??!1;if(g&&m)try{if(await g(),c()===t){r="native",l();return}}catch{}d()}async function p(){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 g=s.exitFullscreen?.bind(s)??s.webkitExitFullscreen?.bind(s);c()===t&&g&&await g()}}return o.addEventListener("click",()=>{r?p():f()}),e.addEventListener("fullscreenchange",h),e.addEventListener("webkitfullscreenchange",h),l(),{button:o,get active(){return r!==void 0},enter:f,exit:p,destroy(){p(),e.removeEventListener("fullscreenchange",h),e.removeEventListener("webkitfullscreenchange",h),o.remove()}}}const Ou="tinyfly-choices-style",k2=`
50
+ `;let y2=0;function b2(t){if(t.getElementById(Iu))return;const e=t.createElement("style");e.id=Iu,e.textContent=m2,t.head.appendChild(e)}function Ou(t,e,n={}){const s=e.ownerDocument;b2(s);const i={...Pu,...n.labels},o=n.speeds??[.5,1,2],r=()=>t.markers.length>0,a=()=>t.markers.some(D=>D.label!==void 0||t.caption(D.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=(D,j,V,et="")=>{const G=s.createElement("button");return G.type="button",G.className=`tf-ctl-btn ${et}`.trim(),G.setAttribute("aria-label",D),G.title=D,G.textContent=j,G.addEventListener("click",V),G},u=h(i.restart,"⟲",()=>{t.pause(),t.seek(0)}),d=h(i.prev,"|◀",()=>t.prev()),f=h(i.play,"▶",()=>t.isPlaying?t.pause():g(),"tf-ctl-primary"),p=h(i.next,"▶|",()=>t.next()),g=()=>{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 w=s.createElement("span");w.className="tf-ctl-step";const v=s.createElement("select");v.className="tf-ctl-speed",v.setAttribute("aria-label",i.speed);for(const D of o){const j=s.createElement("option");j.value=String(D),j.textContent=`${D}×`,D===1&&(j.selected=!0),v.appendChild(j)}v.addEventListener("change",()=>t.setSpeed(Number(v.value))),c.append(u,d,f,p,m,w),o.length>0&&c.append(v),l.append(c);const k=n.fullscreen?M2(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 x=s.createElement("div");x.className="tf-ctl-question",x.hidden=!0;const P=s.createElement("span"),M=h(i.reveal,i.reveal,()=>t.play(),"tf-ctl-primary");x.append(P,M),l.append(x);const T=w2(t,s,i.scenario,n.scenarioControl??"buttons");T&&l.append(T.element);const S=n.mount;S?S.appendChild(l):e.insertAdjacentElement("afterend",l);const E=()=>{const D=t.isPlaying;f.textContent=D?"❚❚":"▶",f.setAttribute("aria-label",D?i.pause:i.play),f.title=D?i.pause:i.play;const j=t.duration;s.activeElement!==m&&(m.value=String(j>0?Math.round(t.currentTime/j*1e3):0));const V=t.markers;if(d.hidden=p.hidden=w.hidden=V.length===0,V.length>0){const et=t.currentMarker,G=et?V.indexOf(et)+1:0;w.textContent=i.stepFormat.replace("{index}",String(G)).replace("{total}",String(V.length)),w.setAttribute("aria-label",`${i.step} ${G} ${i.of} ${V.length}`),d.disabled=t.currentTime<=.5,p.disabled=t.currentTime>=j-.5;const F=t.caption()??"";y.textContent!==F&&(y.textContent=F),y.hidden=!a();const H=!D&&et?.question!==void 0&&Math.abs(t.currentTime-et.time)<1;x.hidden=!H,H&&P.textContent!==et.question&&(P.textContent=et.question)}else x.hidden=!0,y.hidden=!0;T?.update()},$=t.subscribe(E);E();const A=n.keyboardScope??e;!A.hasAttribute("tabindex")&&A.tabIndex<0&&(A.tabIndex=0);const I=new WeakSet,C=D=>{if(I.has(D)||(I.add(D),D.defaultPrevented||D.altKey||D.ctrlKey||D.metaKey))return;const j=D.target;if(!(j.tagName==="INPUT"||j.tagName==="SELECT")&&!(D.key===" "&&j.tagName==="BUTTON"))switch(D.key){case" ":D.preventDefault(),t.isPlaying?t.pause():g();break;case"ArrowRight":if(!r())return;D.preventDefault(),t.next();break;case"ArrowLeft":if(!r())return;D.preventDefault(),t.prev();break;case"Home":D.preventDefault(),t.pause(),t.seek(0);break;case"f":case"F":if(!k)return;D.preventDefault(),k.active?k.exit():k.enter();break}};return A.addEventListener("keydown",C),l.addEventListener("keydown",C),{element:l,fullscreen:k&&{get active(){return k.active},enter:k.enter,exit:k.exit},destroy(){k?.destroy(),$(),A.removeEventListener("keydown",C),l.removeEventListener("keydown",C),l.remove()}}}function w2(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 g=i[Number(d.value)];g&&t.setScenario(g.id)}),h.append(u,d,f),{element:h,update:()=>{const g=Math.max(0,i.findIndex(w=>w.id===t.scenario));e.activeElement!==d&&(d.value=String(g));const m=i[g].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-${++y2}`,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 k2='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',v2='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';function M2(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 g=r!==void 0;o.innerHTML=g?v2:k2;const m=g?n.exitFullscreen:n.fullscreen;o.setAttribute("aria-label",m),o.title=m,o.setAttribute("aria-pressed",String(g)),t.classList.toggle("tf-fullscreen",g),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=g=>{g.key==="Escape"&&p()},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 g=i.requestFullscreen?.bind(i)??i.webkitRequestFullscreen?.bind(i),m=s.fullscreenEnabled??s.webkitFullscreenEnabled??!1;if(g&&m)try{if(await g(),c()===t){r="native",l();return}}catch{}d()}async function p(){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 g=s.exitFullscreen?.bind(s)??s.webkitExitFullscreen?.bind(s);c()===t&&g&&await g()}}return o.addEventListener("click",()=>{r?p():f()}),e.addEventListener("fullscreenchange",h),e.addEventListener("webkitfullscreenchange",h),l(),{button:o,get active(){return r!==void 0},enter:f,exit:p,destroy(){p(),e.removeEventListener("fullscreenchange",h),e.removeEventListener("webkitfullscreenchange",h),o.remove()}}}const _u="tinyfly-choices-style",S2=`
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 v2(t){if(t.getElementById(Ou))return;const e=t.createElement("style");e.id=Ou,e.textContent=k2,t.head.appendChild(e)}function _u(t,e){const n=Array.from(e.querySelectorAll("[data-tinyfly-choose]"));if(n.length===0)return()=>{};v2(e.ownerDocument);const s=[],i=[];for(const a of n){const l=a.getAttribute("data-tinyfly-choose")??"",c=[],h=(p,g)=>{a.hasAttribute(p)||(a.setAttribute(p,g),c.push(p))};h("role","button"),h("tabindex","0");const u=t.scenarios.find(p=>p.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=p=>{const g=p.key;g!=="Enter"&&g!==" "||(p.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 ho=new WeakMap,qa=new WeakMap;let M2=0;function Qs(t,e,n){if(t)try{return JSON.parse(t)}catch(s){console.warn(`tinyfly: invalid ${e} JSON on`,n,s);return}}async function Cu(t,e={}){const n=ho.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=x2(t.getAttribute("data-markers")),a=s.length>1||i?.hasAttribute("data-scenario")?S2(s,r,t):void 0;if(a&&a.length===0)return;let l=i&&!a?Qs(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=Hu(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=Qs(t.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",t),h={playWhenVisible:!0,...e.player,...c&&{captions:c},...Qs(t.getAttribute("data-options"),"data-options",t)};E2(t);const u=new co(t,h),d={element:t,player:u};if(ho.set(t,d),t.setAttribute("data-tinyfly-mounted",""),a){const f=t.getAttribute("data-scenario")??void 0;await u.loadScenarios(a,{initial:a.some(p=>p.id===f)?f:void 0}),qa.set(t,_u(u,t))}else await u.load(l??o);if(t.getAttribute("data-controls")!=="false"){const f=Qs(t.getAttribute("data-labels"),"data-labels",t),p=t.querySelector("figcaption"),g=t.getAttribute("data-scenario-legend"),m=t.getAttribute("data-scenario-control");d.controls=Iu(u,t,{...e.controls,...t.getAttribute("data-fullscreen")==="true"?{fullscreen:!0}:{},...m==="slider"||m==="buttons"?{scenarioControl:m}:{},labels:{...e.controls?.labels,...f,...g?{scenario:g}:{}},mount:void 0}),p?t.insertBefore(d.controls.element,p):t.appendChild(d.controls.element)}return d}function S2(t,e,n){const s=[];return t.forEach((i,o)=>{const r=Qs(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?Hu(r,e):r})}),s}function Hu(t,e){return t.config.markers?.length?t:{...t,config:{...t.config,markers:e.map((n,s)=>({id:`step-${s+1}`,time:n}))}}}function x2(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 Ru(t=document,e={}){const n=Array.from(t.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(n.map(i=>Cu(i,e)))).filter(i=>i!==void 0)}function T2(t){const e=ho.get(t);e&&(qa.get(t)?.(),qa.delete(t),e.controls?.destroy(),e.player.destroy(),ho.delete(t),t.removeAttribute("data-tinyfly-mounted"))}function E2(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-${++M2}`,e.setAttribute("aria-labelledby",s.id))}function A2(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const e=()=>{Ru()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}class Lu{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 bn,this.adapterB=new bn}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 bn;i.querySelectorAll("[data-tinyfly]").forEach(l=>{const c=l.getAttribute("data-tinyfly");c&&a.registerTarget(c,l)}),s.push({adapter:a,timeline:jn(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?jn(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 $2(t,e,n={}){const s=new Lu(t,{...n,autoplay:!0});return await s.load(e),s}const P2={type:"none",duration:0},Lt=t=>({description:t,unit:"degrees"}),At=(t,e=0,n=1)=>({description:t,unit:`${e}..${n}`,min:e,max:n}),Fu={lean:Lt("Upper body tipped about the hips (+ toward the way it faces)"),bend:Lt("Line of action: the spine curved (+ curls forward, − arches back)"),headTilt:Lt("Head tilt"),leftShoulder:Lt("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:Lt("Right upper arm: 0 hangs down, 90 straight out (forward, in profile), 180 straight up"),leftElbow:Lt("Left elbow bend, added to the upper arm"),rightElbow:Lt("Right elbow bend, added to the upper arm"),leftHip:Lt("Left thigh: 0 straight down; in profile negative is forward"),rightHip:Lt("Right thigh: 0 straight down; in profile positive is forward"),leftKnee:Lt("Left knee bend (negative folds the shin back)"),rightKnee:Lt("Right knee bend (positive folds the shin back)"),leftWrist:Lt("Left wrist bend, added to the forearm"),rightWrist:Lt("Right wrist bend, added to the forearm"),leftAnkle:Lt("Left ankle: + points the toe down (tiptoe), − onto the heel"),rightAnkle:Lt("Right ankle: + points the toe down (tiptoe), − onto the heel"),leftFootOut:At("Left foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),rightFootOut:At("Right foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),mouth:At("Mouth open: 0 closed, 1 wide open"),smile:At("−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:At("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:At("Left eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),rightBrow:At("Right eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),browTilt:At("Eyebrow slant: −1 angry, 1 worried",-1,1),lookX:At("Eyes look across: + the way it faces",-1,1),lookY:At("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:At("0 front-on, 1 in profile, turned the way it faces"),sit:At("0 standing, 1 seated"),spin:Lt("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"}},Nu={walk:{description:"Walk-cycle phase, in strides: animate 0 → n for n strides",unit:"strides"},walking:At("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:At("How much the mouth chatters"),rubber:At("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:At("How much of the dance is applied")},Wu={"thumb.curl":At("Thumb curled in"),"thumb.across":At("Thumb across the palm"),"index.curl":At("Index finger curled"),"middle.curl":At("Middle finger curled"),"ring.curl":At("Ring finger curled"),"pinky.curl":At("Little finger curled"),spread:At("Fingers spread apart"),turn:Lt("Hand turned about the forearm"),bend:Lt("Hand bent at the wrist, palm-ward"),tilt:Lt("Hand tilted sideways"),roll:Lt("Hand rolled to show the back or the palm")};let Du;function I2(t){Du=t}function O2(t){return Du?.(t)??{}}function Bu(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 Vn(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=Bu(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 uo(t,e){const n=Vn(t,e);return n[n.length-1]}function ja(t,e){return e>0?Math.floor(Math.max(0,t)*e/1e3):0}function fo(t,e,n){const s=e.roughness??2,i=Math.max(1,Math.round(e.passes??2)),o=ja(n,e.boil??8);let r=0;const a=()=>{const d=r++;return f=>je(ne(`${e.seed??1}:${o}:${d}:${f}`))},l=(d,f)=>(d.next()*2-1)*f,c=d=>{const f=a(),p=t.lineWidth,g=t.globalAlpha;for(let m=0;m<i;m++)t.lineWidth=m===0?p:p*.55,t.globalAlpha=m===0?g:g*.6,d(f(m));t.lineWidth=p,t.globalAlpha=g},h=(d,f=1)=>{if(d.length<2)return;const p=d.slice(1).map((m,w)=>Math.hypot(m.x-d[w].x,m.y-d[w].y)),g=p.reduce((m,w)=>m+w,0)*Math.min(1,Math.max(0,f));c(m=>{const w=[],v=[];if(d.forEach((y,x)=>{w.push({x:y.x+l(m,s*.5),y:y.y+l(m,s*.5)}),x>0&&v.push([m.next()*2-1,m.next()*2-1])}),g<=0)return;t.beginPath(),t.moveTo(w[0].x,w[0].y);let k=0;for(let y=1;y<w.length;y++){const x=_2(w[y-1],w[y],s,v[y-1]),P=p[y-1];if(k+P<=g){t.bezierCurveTo(x[1].x,x[1].y,x[2].x,x[2].y,x[3].x,x[3].y),k+=P;continue}const M=C2(x,P===0?1:(g-k)/P);t.bezierCurveTo(M[1].x,M[1].y,M[2].x,M[2].y,M[3].x,M[3].y);break}t.stroke()})},u=(d,f,p,g,m=1)=>{c(w=>{const k=w.next()*Math.PI*2,y=Math.PI*2+.15+w.next()*.3,x=[];for(let M=0;M<=14;M++){const T=k+y*M/14,S=l(w,s*.6);x.push({x:d+Math.cos(T)*(p+S),y:f+Math.sin(T)*(g+S)})}const P=Vn(x,m);P.length<2||(zu(t,P),t.stroke())})};return{line:h,curve(d,f=1){if(d.length<2)return;const p=d[0],g=d[d.length-1],m=Math.hypot(g.x-p.x,g.y-p.y)||1,w=-(g.y-p.y)/m,v=(g.x-p.x)/m;c(k=>{const y={x:l(k,s*.5),y:l(k,s*.5)},x={x:l(k,s*.5),y:l(k,s*.5)},P=l(k,s*Math.min(1.5,Math.max(.3,m/80))),M=d.map((S,E)=>{const $=E/(d.length-1),A=Math.sin(Math.PI*$)*P;return{x:S.x+y.x+(x.x-y.x)*$+w*A,y:S.y+y.y+(x.y-y.y)*$+v*A}}),T=Vn(M,f);T.length<2||(zu(t,T),t.stroke())})},circle(d,f,p,g=1){u(d,f,p,p,g)},ellipse:u,nudge(d=.5){const f=a()(0);return{x:l(f,s*d),y:l(f,s*d)}}}}function _2(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 C2([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 zu(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 zt(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,p=(h.x-c.x)/u*d;i.push({x:a.x+f,y:a.y+p}),o.push({x:a.x-f,y:a.y-p})}),[...i,...o.reverse()]}function go(t,e,n,s){const i=e.length;if(i<2)return;const o=zt(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 wn(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 po(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,p=Math.sin(d)*s;return{x:t+f*l-p*c,y:e+f*c+p*l}})}function ti(t,e){return e.look==="pencil"?L2(t,e):qu(t,e.ink,e.look)}function mo(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 ei(t,e){return e.look==="silhouette"?qu(t,e.ink,"silhouette",!1):e}function qu(t,e,n,s=!0){const i=n==="silhouette",o=i?1.25:1;return{look:n,ink:e,limb(r,a,l){t.fillStyle=e,go(t,r,a*o,l*o)},line(r,a){r.length<2||(t.strokeStyle=e,t.lineWidth=a*o,t.lineCap="round",t.lineJoin="round",mo(t,r),t.stroke())},shape(r,a,l){mo(t,r,!0),(a!==null||i&&s)&&(t.fillStyle=i?e:a,t.fill()),!(l<=0)&&(t.strokeStyle=e,t.lineWidth=l*o,t.lineJoin="round",t.stroke())},ellipse(r,a,l,c,h,u,d){t.beginPath(),t.ellipse(r,a,l,c,h,0,Math.PI*2),(u!==null||i&&s)&&(t.fillStyle=i?e:u,t.fill()),!(d<=0)&&(t.strokeStyle=e,t.lineWidth=d*o,t.stroke())},dot(r,a,l){t.fillStyle=e,t.beginPath(),t.arc(r,a,l*o,0,Math.PI*2),t.fill()},guide(){},guideEllipse(){}}}function H2(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 R2(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 ju(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 L2(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=ja(e.time,n.boil??8);let c=0;const h=(p,g,m=!1)=>je(ne(`${e.seed}:${m?"paper":l}:${p}:${g}`)),u=(p,g,m,w,v,k=0)=>{if(p.length<2)return;const y=p.slice(1).reduce(($,A,I)=>$+Math.hypot(A.x-p[I].x,A.y-p[I].y),0);let x=H2(p,Math.max(1.5,Math.min(e.lineWidth*.8,y/24)));if(k>0&&x.length>=2){const[$,A]=[x[x.length-2],x[x.length-1]],I=Math.hypot(A.x-$.x,A.y-$.y)||1;x=[...x,{x:A.x+(A.x-$.x)/I*k,y:A.y+(A.y-$.y)/I*k}]}const P=ju(m),M=ju(m),T=x.length,S=[],E=[];x.forEach(($,A)=>{const I=T===1?0:A/(T-1),C=x[Math.max(0,A-1)],D=x[Math.min(T-1,A+1)],j=Math.hypot(D.x-C.x,D.y-C.y)||1,V=-(D.y-C.y)/j,et=(D.x-C.x)/j,G=P(I)*v,F=Math.min(1,I/.08,(1-I)/.08),H=(.55+.45*Math.sqrt(Math.max(0,F)))*(1+r*M(I)),W=Math.max(.3,g(I)*H/2),_=$.x+V*G,B=$.y+et*G;S.push({x:_+V*W,y:B+et*W}),E.push({x:_-V*W,y:B-et*W})}),t.save(),t.globalAlpha*=w,t.fillStyle=s,mo(t,[...S,...E.reverse()],!0),t.fill(),t.restore()},d=(p,g)=>{const m=c++,w=h(m,99,!0);if(w.next()<a){const x=(w.next()*2-1)*e.lineWidth*1.4,P=(w.next()*2-1)*e.lineWidth*1.4,M=p.map(T=>({x:T.x+x,y:T.y+P}));u(M,T=>g(T)*1.8,h(m,98,!0),.035,i),u(M,T=>g(T)*.45,h(m,97,!0),.12,i*1.5)}const v=p.slice(1).reduce((x,P,M)=>x+Math.hypot(P.x-p[M].x,P.y-p[M].y),0),k=g(.5)>4&&v>g(.5)*6,y=k?[-.3,.3,0]:[0];for(let x=0;x<o;x++){const P=x===0;y.forEach((M,T)=>{const S=h(m,x*10+T),E=M===0?p:R2(p,A=>g(A)*M*Math.sqrt(Math.sin(Math.PI*A))),$=!P&&M===0?e.lineWidth*(.3+S.next()*.8):0;u(E,A=>g(A)*(k?.5:1)*(P?1:.6),S,P?.85:.45,i*(P?.6:1),$)})}},f=(p,g,m,w,v,k)=>{const x=h(c,50).next()*Math.PI*2;d(po(p,g,m,w,v,x,1.08,48),()=>k)};return{look:"pencil",ink:s,limb(p,g,m){d(p,w=>g+(m-g)*w)},line(p,g){d(p,()=>g)},shape(p,g,m){g!==null&&(t.save(),t.globalAlpha*=.88,t.fillStyle=g,mo(t,p,!0),t.fill(),t.restore()),m>0&&d([...p,p[0]],()=>m)},ellipse(p,g,m,w,v,k,y){k!==null&&(t.save(),t.globalAlpha*=.9,t.fillStyle=k,t.beginPath(),t.ellipse(p,g,m,w,v,0,Math.PI*2),t.fill(),t.restore()),f(p,g,m,w,v,y)},dot(p,g,m){t.save(),t.globalAlpha*=.9,t.fillStyle=s,t.beginPath(),t.arc(p,g,m,0,Math.PI*2),t.fill(),t.restore()},guide(p){if(n.construction===!1||p.length<2)return;const g=c++;u(p,()=>Math.max(.6,e.lineWidth*.18),h(g,0),.28,i*1.2,e.lineWidth)},guideEllipse(p,g,m,w,v){if(n.construction===!1)return;const k=c++,y=h(k,0),x=po(p,g,m,w,v,y.next()*Math.PI*2,1.12,48);u(x,()=>Math.max(.6,e.lineWidth*.18),y,.28,i*1.5)}}}const Yu=["thumb","index","middle","ring","pinky"],Ot={"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 Nt(t={}){return{...Ot,...t}}const re=(t,e,n,s,i)=>({"thumb.curl":t,"index.curl":e,"middle.curl":n,"ring.curl":s,"pinky.curl":i}),St={relaxed:Ot,open:Nt({...re(0,0,0,0,0),"thumb.across":0,spread:.55}),spread:Nt({...re(0,0,0,0,0),"thumb.across":0,spread:1}),flat:Nt({...re(0,0,0,0,0),"thumb.across":.35,spread:0}),fist:Nt({...re(.7,1,1,1,1),"thumb.across":.9,spread:0}),point:Nt({...re(.75,0,1,1,1),"thumb.across":.9,spread:0}),thumbsUp:Nt({...re(0,1,1,1,1),"thumb.across":0,spread:0,roll:70}),peace:Nt({...re(.75,0,0,1,1),"thumb.across":.9,spread:1}),ok:Nt({...re(.12,.6,.1,.15,.2),"thumb.across":.55,spread:.6}),pinch:Nt({...re(.1,.65,.75,.85,.9),"thumb.across":.55,spread:0}),cupped:Nt({...re(.25,.4,.4,.4,.4),"thumb.across":.4,spread:.05,turn:2}),wave:Nt({...re(0,.05,.05,.1,.12),"thumb.across":0,spread:.7,turn:2}),pencilGrip:Nt({...re(.1,.6,.72,.88,.95),"thumb.across":.5,spread:0,turn:.8,bend:10}),hold:Nt({...re(.5,.7,.72,.74,.76),"thumb.across":.75,spread:0,turn:1})};function Jn(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 F2={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}},N2={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}},$e={base:[-.11,.1,-.05],bones:[.2,.15,.12],widths:[.2,.145,.135],out:[-.7,.68,-.22],across:[.35,.5,-.8]},W2=[82,100,62],D2=[48,72],B2=3,z2=13,q2=.035,j2=-.075,Y2=[[-.17,0],[-.215,.12],[-.235,.26],[-.225,.4],[-.185,.49],[-.075,.525],[.05,.51],[.16,.465],[.215,.4],[.225,.26],[.2,.1],[.16,0]],Ye=t=>t*Math.PI/180,Ya=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],yo=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],Ka=(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]],ni=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function Ke(t,e,n){const s=Math.cos(n),i=Math.sin(n),o=Ka(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 Ku=[1,0,0],Xu=[0,1,0],si=[0,0,1];function K2(t,e,n){const s=Ye(t.fan*(B2+z2*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+=Ye(W2[u]*e),r.push(Ya(r[u],yo(Ke(i,o,-a),h)))});const l=Ke(si,o,-a),c=r.map((h,u)=>t.width*(1-.14*(u/(r.length-1))));return{joints:r,back:l,widths:c}}function X2(t,e,n=1,s=1){const i=Math.min(1,Math.max(0,e)),o=ni(Ya(yo(ni($e.out),1-i),yo(ni($e.across),i))),r=ni(Ka(si,o)),a=ni(Ka(o,r)),l=[[$e.base[0]*s,$e.base[1],$e.base[2]]];let c=0;$e.bones.forEach((d,f)=>{f>0&&(c+=Ye(D2[f-1]*t)),l.push(Ya(l[f],yo(Ke(o,r,c),d)))});const h=Ke(a,r,c),u=[...$e.widths,$e.widths[$e.widths.length-1]*.92].map(d=>d*n);return{joints:l,back:h,widths:u}}function bo(t,e={}){const n={...Ot,...t},s=e.size??100,i=e.side??"right",o=i==="left"?-1:1,r=Ye(e.angle??0),a=e.fingers===4,l=Math.max(.5,e.plump??1),c=1+(l-1)*.7,h=A=>({...A,knuckle:[A.knuckle[0]*c,A.knuckle[1],A.knuckle[2]],width:A.width*l}),u=Ye(n.bend??0),d=Ye(n.tilt??0),f=Ye(90*(n.turn??0)),p=A=>Ke(Ke(Ke(A,Ku,-u),si,-d),Xu,f),g=Math.cos(r),m=Math.sin(r),w=Ye(n.roll??0),v=Math.cos(w),k=Math.sin(w),y=A=>{const I=A[0]*s,C=-A[1]*s,D=(I*v-C*k)*o,j=I*k+C*v;return{x:D*g-j*m,y:D*m+j*g}},x=A=>{const I=y(A),C=Math.hypot(I.x,I.y);return C>1e-6*s?{x:I.x/C,y:I.y/C}:{x:0,y:0}},P={thumb:X2(n["thumb.curl"]??0,n["thumb.across"]??0,l,c)},M=a?N2:F2;for(const A of Yu){const I=M[A];I&&(P[A]=K2(h(I),n[`${A}.curl`]??0,n.spread??0))}const T={};for(const[A,I]of Object.entries(P)){const C=I.joints.map(p),D=p(I.back);T[A]={points:C.map(y),depths:C.map(j=>j[2]*s),widths:I.widths.map(j=>j*s),nail:D[2],back:x(D)}}const S=Y2.flatMap(([A,I])=>[p([A*c,I,q2]),p([A*c,I,j2])]),E=G2(S.map(y)),$=S.reduce((A,I)=>A+I[2],0)/S.length*s;return{size:s,side:i,wrist:{x:0,y:0},palm:E,palmDepth:$,palmFacing:-p(si)[2],fingers:T,axes:{up:x(p(Xu)),across:x(p(Ku)),out:x(p(si))},curls:Object.fromEntries(Object.keys(T).map(A=>[A,n[`${A}.curl`]??0]))}}function Gu(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 G2(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)]}function Uu(t,e,n,s){if(s.mode!=="cel"||e.length<3)return;const i=Math.hypot(...s.light),o=e.map(a=>{const l=a.x-n.x,c=a.y-n.y,h=(l*s.light[0]+c*s.light[1])/((Math.hypot(l,c)||1)*i),u=Math.max(0,-h)*.24;return{x:a.x-l*u,y:a.y-c*u}}),r=a=>{t.beginPath(),t.moveTo(a[0].x,a[0].y);for(const l of a.slice(1))t.lineTo(l.x,l.y);t.closePath()};t.save(),r(e),t.clip(),r([...e,...o.reverse()]),t.globalAlpha*=s.opacity,t.fillStyle=s.shadow,t.fill(),t.restore()}const U2="#f1c9a5",V2="#2f2f33";function wo(t,e,n,s={},i=0){const o=Gu(bo(n,s),e),r=s.ink??V2,a=s.lineWidth??o.size*.035;let l=s.pen??ti(t,{look:s.look??"clean",ink:r,lineWidth:a,seed:s.seed??1,time:i,pencil:{construction:!1,...s.pencil}});const c=s.skin??U2;c==="none"&&(l=ei(t,l));const h=s.nails??!0,u=[{depth:o.palmDepth,draw:()=>J2(t,l,o,c,a,s)}];for(const d of Object.values(o.fingers)){const f=d.depths.reduce((p,g)=>p+g,0)/d.depths.length;u.push({depth:f,draw:()=>Z2(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,p)=>f.depth-p.depth))d.draw();return t.restore(),o}function J2(t,e,n,s,i,o){if(e.shape(n.palm,s==="none"?null:s,o.connected?0:i),s!=="none"&&o.shading&&e.look==="clean"){const r=n.palm.reduce((a,l)=>({x:a.x+l.x/n.palm.length,y:a.y+l.y/n.palm.length}),{x:0,y:0});Uu(t,n.palm,r,o.shading)}if(o.connected&&i>0&&(e.look!=="silhouette"||s==="none")){const{up:r}=n.axes;let a=[];for(let l=0;l<=n.palm.length;l++){const c=n.palm[l%n.palm.length],h=n.palm[(l+1)%n.palm.length];((c.x+h.x)/2-n.wrist.x)*r.x+((c.y+h.y)/2-n.wrist.y)*r.y<n.size*.08?(a.length>1&&e.line(a,i),a=[]):(a.length===0&&a.push(c),a.push(h))}a.length>1&&e.line(a,i)}if(n.palmFacing<-.3&&e.look!=="silhouette"){const{up:r}=n.axes;for(const[a,l]of Object.entries(n.fingers)){const c=n.curls[a]??0;if(a==="thumb"||c<.5)continue;const h=l.points[0],u=l.widths[0]*.42,d={x:h.x-r.x*u*.2,y:h.y-r.y*u*.2},f=Math.atan2(r.y,r.x),p=Array.from({length:7},(g,m)=>{const w=f-Math.PI/2+Math.PI*m/6;return{x:d.x+Math.cos(w)*u,y:d.y+Math.sin(w)*u}});e.line(p,i*.6)}}if(n.palmFacing>.45&&e.look!=="silhouette"){const{up:r,across:a}=n.axes,l=n.size,c=n.wrist,h=(d,f)=>({x:c.x+(a.x*d+r.x*f)*l,y:c.y+(a.y*d+r.y*f)*l}),u=n.side==="left"?-1:1;e.line([h(-.15*u,.36),h(-.04*u,.3),h(.1*u,.33)],i*.5)}}function Z2(t,e,n,s,i,o){const{widths:r}=n,a=Q2(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"||s==="none"){t.beginPath(),t.rect(l.x-1e5,l.y-1e5,2e5,2e5);const g=h/2+i*1.6;t.moveTo(l.x+g,l.y),t.arc(l.x,l.y,g,0,Math.PI*2),t.clip("evenodd")}if(s==="none"){const g=zt(a,h,u),m=a[a.length-2],w=Math.atan2(c.y-m.y,c.x-m.x),v=Array.from({length:13},(k,y)=>{const x=w+Math.PI/2-y*Math.PI/12;return{x:c.x+Math.cos(x)*u/2,y:c.y+Math.sin(x)*u/2}});e.shape([...g.slice(0,a.length),...v.slice(1),...g.slice(a.length)],null,i)}else e.limb(a,h+2*i,u+2*i);if(t.restore(),s!=="none"&&e.look!=="silhouette"&&(t.fillStyle=s,go(t,a,h,u)),s==="none"||e.look==="silhouette"||!o||n.nail<.25)return;const d=a[a.length-2],f=tk({x:c.x-d.x,y:c.y-d.y})??{x:0,y:-1},p={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(p.x,p.y,u*.24*Math.max(.35,n.nail),u*.19,Math.atan2(f.y,f.x),"#f8e3d3",i*.45)}function Q2(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 tk=t=>{const e=Math.hypot(t.x,t.y);return e>1e-6?{x:t.x/e,y:t.y/e}:null},Yt={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}},ek=40;function ii(t){return t===void 0?Yt.walk:typeof t=="string"?Yt[t]??Yt.walk:t}function Vu(t,e,n=ut,s=1){const i=ii(t);if(i===Yt.walk)return ed(e,n,s);const o=e*Math.PI*2,r=Math.sin(o)*s,a=Math.cos(o)*s,l=w=>Math.abs(w)<=ek,c=i.shoulder??0,h=(w,v)=>l(w)?v*c+i.arm*r:w,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,p=i.bounces??1,g=(1+Math.cos(o*2*p))/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*g,stretch:n.stretch*(1+(i.squash??0)*(g-.5))}}function ko(t,e,n=1){const s=ii(t),i=Yt.walk.swing,o=r=>Math.sin(r*Math.PI/180);return nd(e,n)*o(s.swing*n)/o(i*n)}const ut={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 Dt(t){return{...ut,...t}}const Ju={mouth:0,smile:0,mouthWidth:1,leftEye:1,rightEye:1,leftBrow:0,rightBrow:0,browTilt:0,lookX:0,lookY:0},qt=t=>({...Ju,...t}),vt={neutral:Ju,happy:qt({smile:.9,leftBrow:.2,rightBrow:.2}),joyful:qt({mouth:.6,smile:1,mouthWidth:1.2,leftEye:0,rightEye:0,leftBrow:.4,rightBrow:.4}),sad:qt({smile:-.8,leftEye:.8,rightEye:.8,browTilt:.9,leftBrow:-.1,rightBrow:-.1,lookY:.6}),crying:qt({mouth:.45,smile:-1,leftEye:0,rightEye:0,browTilt:1,lookY:.4}),surprised:qt({mouth:.7,mouthWidth:.7,leftEye:1.5,rightEye:1.5,leftBrow:1,rightBrow:1}),shocked:qt({mouth:1,mouthWidth:.8,leftEye:1.6,rightEye:1.6,leftBrow:1,rightBrow:1,browTilt:.4}),angry:qt({smile:-.6,mouthWidth:.9,leftEye:.8,rightEye:.8,leftBrow:-.6,rightBrow:-.6,browTilt:-1}),furious:qt({mouth:.5,smile:-1,mouthWidth:1.3,leftEye:.9,rightEye:.9,leftBrow:-.9,rightBrow:-.9,browTilt:-1}),worried:qt({smile:-.3,mouthWidth:.8,leftEye:1.1,rightEye:1.1,leftBrow:.3,rightBrow:.3,browTilt:.8,lookX:-.5}),scared:qt({mouth:.35,smile:-.5,mouthWidth:.8,leftEye:1.45,rightEye:1.45,leftBrow:.8,rightBrow:.8,browTilt:.9}),confused:qt({smile:-.2,mouthWidth:.8,leftEye:.9,rightEye:1.15,leftBrow:-.3,rightBrow:.8,lookX:.5,lookY:-.4}),skeptical:qt({smile:-.1,leftEye:.6,rightEye:1,leftBrow:-.4,rightBrow:.7,lookX:.4}),thinking:qt({smile:0,mouthWidth:.7,leftBrow:.3,rightBrow:.5,lookX:.6,lookY:-.8}),sleepy:qt({smile:.1,leftEye:.25,rightEye:.25,leftBrow:-.3,rightBrow:-.3,lookY:.5}),disgusted:qt({smile:-.7,mouthWidth:.9,leftEye:.6,rightEye:.75,leftBrow:-.5,rightBrow:-.2,browTilt:-.4,lookX:-.6}),smug:qt({smile:.6,mouthWidth:.9,leftEye:.6,rightEye:.6,leftBrow:.1,rightBrow:.5,lookX:.5}),wink:qt({smile:.9,leftEye:0,rightEye:1,leftBrow:-.2,rightBrow:.3})};function Xe(t,e){return{...t,...typeof e=="string"?vt[e]:e}}const ae={rest:ut,wave:Dt({rightShoulder:135,rightElbow:30,headTilt:6,...vt.happy}),cheer:Dt({leftShoulder:125,leftElbow:20,rightShoulder:125,rightElbow:20,...vt.joyful}),shrug:Dt({leftShoulder:30,leftElbow:85,rightShoulder:30,rightElbow:85,headTilt:-10,...vt.confused,lookX:0,lookY:0}),point:Dt({rightShoulder:90,rightElbow:0,lean:4,smile:.4}),think:Dt({rightShoulder:60,rightElbow:150,headTilt:10,...vt.thinking}),handsOnHips:Dt({leftShoulder:45,leftElbow:-100,rightShoulder:45,rightElbow:-100,leftHip:14,rightHip:14,smile:.8}),sad:Dt({leftShoulder:14,rightShoulder:14,leftElbow:-4,rightElbow:-4,headTilt:-14,lean:-3,...vt.sad}),surprised:Dt({leftShoulder:70,leftElbow:60,rightShoulder:70,rightElbow:60,...vt.surprised}),crouch:Dt({stretch:.72,leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50,leftHip:22,rightHip:22,headTilt:-4}),sit:Dt({sit:1,turn:.5,leftShoulder:-25,rightShoulder:25,leftElbow:-55,rightElbow:55}),jump:Dt({stretch:1.22,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4,...vt.joyful}),duck:Dt({stretch:.62,bend:28,headTilt:-8,leftShoulder:150,rightShoulder:150,leftElbow:130,rightElbow:130,leftHip:25,rightHip:25,...vt.scared}),lie:Dt({spin:-90,rise:-.42,leftShoulder:165,rightShoulder:165,leftElbow:150,rightElbow:150,...vt.sleepy}),sideSplit:Dt({leftHip:90,rightHip:90,leftAnkle:-45,rightAnkle:-45,leftShoulder:120,rightShoulder:120,leftElbow:10,rightElbow:10,...vt.happy}),frontSplit:Dt({turn:1,leftHip:-90,rightHip:-90,leftAnkle:-45,rightAnkle:-45,leftShoulder:-150,rightShoulder:150,leftElbow:10,rightElbow:-10,...vt.happy})},Zu=Object.keys(ut);function Zn(t,e,n){const s={...t};for(const i of Zu)s[i]=t[i]+(e[i]-t[i])*n;return s}const Xa=24,Qu=4,td=28,nk=40;function ed(t,e=ut,n=1){const s=Math.sin(t*Math.PI*2)*n,i=Math.cos(t*Math.PI*2)*n,o=c=>Math.abs(c)<=nk,r=c=>o(c)?22*s:c,a=o(e.leftShoulder)?e.leftElbow-td*Math.max(0,-s):e.leftElbow,l=o(e.rightShoulder)?e.rightElbow+td*Math.max(0,s):e.rightElbow;return{...e,lean:e.lean+Qu*n,headTilt:e.headTilt-Qu*.5*n,leftElbow:a,rightElbow:l,leftHip:-Xa*s,rightHip:-Xa*s,leftKnee:-30*Math.max(0,i),rightKnee:30*Math.max(0,-i),leftShoulder:r(e.leftShoulder),rightShoulder:r(e.rightShoulder)}}function nd(t,e=1){return 4*((Ga+vo)*t)*Math.sin(Xa*e*Math.PI/180)}function sd(t){const e=Math.abs(Math.sin(t/65)),n=.55+.45*Math.sin(t/310);return e*n}const id=.12,od=.46,sk=1-2*id,ik=.1,ok=.21,rk=.19,Ga=.24,vo=.22,rd=.12,ak=.14,ad=.33,ld=.7,cd=.3,lk=.35,ck=[1.7,1.05],hk=[1.3,.75],hd=[1.45,.85],uk=[1.15,.75],ud=.06,dk=.7,fk=.65,dd=.075,gk=.3,pk=.02,mk=.012,yk=12,bk=.25,Mo=90,wk=.25,kk=.04,fd=.01,kn=t=>Math.min(1,Math.max(0,t??0));function vk(t,e=1){return vo*t*e}const Ua=-.12,gd=.4,he=t=>t*Math.PI/180,Mk=(t,e)=>({x:e*Math.sin(he(t)),y:Math.cos(he(t))}),pd=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),md=(t,e,n,s)=>t-.3*e-n*.14*e-Math.max(0,s-1)*.12*e;function Sk(t,e,n,s,i,o){const r=Math.max(1,Math.min(o*.6,ak*n)),a=kn(e.turn),l=(rd+ad*a)*n,c=s+Ua*n,h=l+e.lookX*.08*n,u=e.lookY*.07*n,d=[{x:-.34*n*(1-ld*a),squeeze:1-ld*a,open:e.leftEye,brow:e.leftBrow,side:-1},{x:.34*n*(1-cd*a),squeeze:1-cd*a,open:e.rightEye,brow:e.rightBrow,side:1}];t.fillStyle=i,t.strokeStyle=i,t.lineWidth=r;for(const w of d){const v=pd(w.open,e.blink);if(v<.2){const P=e.smile>.5?-.12*n:.06*n;t.beginPath(),t.moveTo(w.x+l-.12*n,c),t.quadraticCurveTo(w.x+l,c+P,w.x+l+.12*n,c),t.stroke()}else{if(v>1.2){const M=.13*n*v;t.beginPath(),t.ellipse(w.x+l,c,M*.85,M,0,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.stroke(),t.fillStyle=i}const P=v>1.2?.075*n:.1*n;t.beginPath(),t.ellipse(w.x+h,c+u,P,P*1.1*Math.min(v,1),0,0,Math.PI*2),t.fill()}const k=md(c,n,w.brow,v),y=w.x+l-w.side*.13*n*w.squeeze,x=w.x+l+w.side*.13*n*w.squeeze;t.beginPath(),t.moveTo(x,k),t.lineTo(y,k-e.browTilt*.1*n),t.stroke()}const f=s+gd*n,p=.25*n*Math.max(.3,e.mouthWidth)*(1-lk*a),g=Math.min(1,Math.max(0,e.mouth));if(t.beginPath(),g<=.05){t.moveTo(l-p,f),t.quadraticCurveTo(l,f+e.smile*.25*n,l+p,f),t.stroke();return}const m=.3*n*g;e.smile>.3?(t.moveTo(l-p,f-.05*n),t.lineTo(l+p,f-.05*n),t.quadraticCurveTo(l,f+m*2,l-p,f-.05*n)):e.smile<-.3?(t.moveTo(l-p,f+m*.6),t.lineTo(l+p,f+m*.6),t.quadraticCurveTo(l,f-m*1.4,l-p,f+m*.6)):t.ellipse(l,f,p*.8,m,0,0,Math.PI*2),t.fill()}function yd(t,e){const n=e.height??300,s=Math.min(3,Math.max(.3,t.stretch??1)),i=Math.sqrt(s),o=e.armLength??1;if(!Number.isFinite(o)||o<=0)throw new Error("stick figure: armLength must be a positive finite multiplier");const r=(e.headSize??2*id)/2,a=e.headSize===void 0?sk:1-2*r,l=r*n,c=kn(t.sit),h=t.leftHip+(-Mo-t.leftHip)*c,u=t.leftKnee+(-Mo-t.leftKnee)*c,d=t.rightHip+(Mo-t.rightHip)*c,f=t.rightKnee+(Mo-t.rightKnee)*c,p=e.classic===!0,g=kn(t.turn),m=(G,F,H,W,_)=>{const B=Math.max(-Math.PI/2,Math.min(Math.PI/2,Math.abs(he(F-H)/2)+he(W))),Q=Math.max(-1,Math.min(1,dk+_)),O=g+(1-g)*G*Q;return p?{x:0,y:0}:{x:Math.cos(B)*ud*O,y:Math.sin(B)*ud}},w={left:t.leftAnkle??0,right:t.rightAnkle??0},v={left:t.leftFootOut??0,right:t.rightFootOut??0};let k=0;if(c>0||!p){const G=(_,B,Q,O,R)=>Ga*Math.cos(he(B))+vo*Math.cos(he(B-Q))+Math.max(0,m(_,B,Q,O,R).y),F=Math.max(G(-1,h,u,w.left,v.left),G(1,d,f,w.right,v.right)),H=1-kn((t.rise??0)/kk),W=(p?Math.min(1,c/wk):1)*H;k=(od-F)*W*n*s}const y=-od*n*s+k,x=-a*n*s+k,P=p?0:(pk*kn(t.turn)+mk*c)*n*s,M=he(t.bend??0),T={end:wd(y,x,M,1),bend:M};let S;if(M!==0){S=[];for(let G=0;G<=bd;G++){const F=G/bd,H=wd(y,x,M,F);S.push({x:H.x-P*Math.sin(Math.PI*F),y:H.y})}}else S=P===0?[{x:0,y},{x:0,y:x}]:wn({x:0,y},{x:-P,y:(y+x)/2},{x:0,y:x},1,8);const E=x+ik*n*s,$=(e.shoulderWidth??0)*n*Math.cos(g*Math.PI/2),A=(G,F,H,W,_)=>{const B=Mk(H,W);return{x:G+B.x*_*n,y:F+B.y*_*n}},I=(G,F,H)=>{const W=A(0,y,F,G,Ga*s);return{root:{x:0,y},joint:W,end:A(W.x,W.y,F-H,G,vo*s)}},C=(G,F,H)=>{const W={x:G*$,y:E},_=A(W.x,W.y,F,G,ok*i*o);return{root:W,joint:_,end:A(_.x,_.y,F+H,G,rk*i*o)}},D={left:I(-1,h,u),right:I(1,d,f)},j=(G,F,H,W,_,B)=>{const Q=m(G,H,W,_,B);return{x:F.end.x+Q.x*n*s,y:F.end.y+Q.y*n*s}},V=(G,F,H,W,_)=>A(F.end.x,F.end.y,H+W+_,G,dd*i),et={left:C(-1,t.leftShoulder,t.leftElbow),right:C(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(p?0:gk,e.rubber??0)),r:l,headRx:l/Math.sqrt(s),headRy:l*Math.sqrt(s),hipY:y,neckY:x,drop:k,lean:p?t.lean:t.lean+yk*Math.sin(Math.PI*c),classic:p,legs:D,toes:{left:j(-1,D.left,h,u,w.left,v.left),right:j(1,D.right,d,f,w.right,v.right)},spine:S,chest:T,arms:et,handTips:{left:V(-1,et.left,t.leftShoulder,t.leftElbow,t.leftWrist??0),right:V(1,et.right,t.rightShoulder,t.rightElbow,t.rightWrist??0)}}}const bd=10;function wd(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 xk(t,e){if(t.chest.bend===0)return e;const n=ri(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 oi=(t,e)=>e===0?[t.root,t.joint,t.end]:wn(t.root,t.joint,t.end,e);function ri(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 kd(t,e,n=!0){const s=Ek(t,e),i=e.spin??0,o=e.rise??0;return n&&(i!==0||o!==0)?Tk(s,t,i,o):s}function vd(t,e,n){return{pivot:{x:0,y:t.hipY},angle:t.facing*he(e),lift:n*t.height}}function Tk(t,e,n,s){const{pivot:i,angle:o,lift:r}=vd(e,n,s),a=d=>{const f=ri(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=fd*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 Ek(t,e){const n=he(t.lean),s=he(e.headTilt),i={x:0,y:t.hipY},o=y=>({x:t.facing*y.x,y:y.y}),r=y=>o(ri(y,i,n)),a=y=>r(xk(t,y)),l=y=>a(ri({x:y.x,y:y.y+t.neckY},{x:0,y:t.neckY},s)),c=oi(t.arms.left,t.rubber).map(a),h=oi(t.arms.right,t.rubber).map(a),u=(y,x)=>Math.atan2(x.y-y.y,x.x-y.x),d={left:a(t.handTips.left),right:a(t.handTips.right)},f=(y,x)=>{const[P,M]=y.slice(-2),T=t.arms[x],S=u(a(T.end),d[x])-u(a(T.joint),a(T.end));return u(P,M)+S};let p=1/0;for(const[y,x]of[[e.leftBrow,e.leftEye],[e.rightBrow,e.rightEye]]){const P=md(Ua,1,y,pd(x,e.blink));p=Math.min(p,P,P-e.browTilt*.1)}const g={left:o(t.legs.left.end),right:o(t.legs.right.end)},m={left:o(t.toes.left),right:o(t.toes.right)},w={left:Math.max(g.left.y,m.left.y),right:Math.max(g.right.y,m.right.y)},v=Math.max(w.left,w.right),k=fd*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:g,toes:m,feetY:v,grounded:{left:w.left>=v-k,right:w.right>=v-k},fingertips:d,handAngle:{left:f(c,"left"),right:f(h,"right")},limbs:{leftArm:c,rightArm:h,leftLeg:oi(t.legs.left,t.rubber).map(o),rightLeg:oi(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:Ua,browTopY:p,mouthY:gd,faceX:t.facing*(rd+ad*kn(e.turn))}}}function me(t,e={}){return kd(yd(t,e),t)}function Ak(t,e,n){return ri({x:t.center.x+e*t.rx,y:t.center.y+n*t.ry},t.center,t.angle)}function Md(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 Sd(t,e,n={},s=0){const i=yd(e,n),o=n.color??"#1e293b",r=n.layers??{},a=n.layers?kd(i,e,!1):void 0,l=n.sketch?fo(t,n.sketch,s):void 0,c=n.sketch&&n.layers?fo(t,n.sketch,s):void 0,h=M=>{t.save(),M(),t.restore()},u=M=>{M&&a&&h(()=>M(t,a,s,c))},d=()=>t.scale(i.facing,1),f=()=>{d(),t.translate(0,i.hipY),t.rotate(he(i.lean)),t.translate(0,-i.hipY)},p=()=>{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))},g=(M,T,S)=>{if(l)return T?l.curve(M):l.line(M);if(i.classic){t.beginPath(),t.moveTo(M[0].x,M[0].y);for(const E of M.slice(1))t.lineTo(E.x,E.y);t.stroke();return}go(t,M,S[0]*i.lineWidth,S[1]*i.lineWidth)},m=(M,T)=>g(oi(M,i.rubber),i.rubber>0,T),w=M=>{i.classic||g([i.legs[M].end,i.toes[M]],!1,uk)},v=M=>{if(n.hands&&!i.classic)return y(M);if(i.classic||l)return;const T=i.arms[M].end;t.beginPath(),t.arc(T.x,T.y,fk*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=vd(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(M){const T=n.hands??{},S=i.arms[M].end,E=i.handTips[M],$=n.headFill??"#ffffff";wo(t,S,T[M]??Ot,{side:M,angle:Math.atan2(E.x-S.x,S.y-E.y)*180/Math.PI,size:(T.size??dd)*i.height*Math.sqrt(i.stretch),skin:T.skin??($==="none"?void 0:$),ink:o,lineWidth:i.lineWidth*.45,fingers:T.fingers,plump:T.plump,look:n.sketch?"pencil":"clean",seed:n.sketch?.seed},s)}const x=M=>{h(()=>{p(),m(i.arms[M],hk),v(M)});const T=r.sleeve;T&&a&&h(()=>T(t,a,M,s,c))},P=kn(e.turn)>bk;u(r.behind),h(()=>{d(),m(i.legs.left,hd),w("left"),m(i.legs.right,hd),w("right")}),P&&x("left"),h(()=>{f(),g(i.spine,i.spine.length>2,ck)}),h(()=>{p();const{left:M,right:T}={left:i.arms.left.root,right:i.arms.right.root};if(M.x!==T.x)if(i.classic)g([M,T],!1,[1,1]);else{const S={x:(M.x+T.x)/2,y:M.y-.3*Math.abs(T.x-M.x)};g(wn(M,S,T,1,8),!0,[1.1,1.1])}}),u(r.body),P||x("left"),x("right"),u(r.behindHead),h(()=>{p(),t.translate(0,i.neckY),t.rotate(he(e.headTilt));const M=-i.headRy;t.beginPath(),t.ellipse(0,M,i.headRx,i.headRy,0,0,Math.PI*2);const T=n.headFill??"#ffffff";if(T!=="none"&&(t.fillStyle=T,t.fill()),l){l.ellipse(0,M,i.headRx,i.headRy);const S=l.nudge();t.translate(S.x,S.y)}else t.stroke();t.translate(0,M),t.scale(i.headRx/i.r,i.headRy/i.r),Sk(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 Va(t,e,n,s){const i={...t},o=t.gait&&s?.[t.gait]||t.gait;let r=t.walking>0?Zn(i,Vu(o,t.walk,i),t.walking):i,a=$k(t);const l=t.dancing??0;if(n&&l>0){const c=n(t.beat??0);if(r=Zn(r,c.pose,l),c.hands){const h=(u,d)=>d?Jn(u??Ot,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*sd(e))}),{pose:r,hands:a}}function xd(t,e,n,s){return Va(t,e,n,s).pose}const Td=(t,e)=>(t.facing??e.facing??1)<0?-1:1,ai=(t,e)=>`hand.${t}.${e}`;function $k(t){const e=i=>{if(typeof t[ai(i,"spread")]=="number")return Object.fromEntries(Object.keys(Ot).map(o=>[o,t[ai(i,o)]]))},n=e("left"),s=e("right");return n||s?{left:n,right:s}:void 0}function Pk(t,e){return!e||!t.hands?t:{...t,hands:{...t.hands,left:e.left??t.hands.left,right:e.right??t.hands.right}}}function Ja(t){const e=t.style??{},n=e.height??300,s=n*.8,i={...Dt(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]??Ot;for(const l of Object.keys(Ot))o[ai(r,l)]=a[l]??Ot[l]}return{type:"custom",x:t.x-s/2,y:t.y-n,width:s,height:n,props:{...i,...o},about:Ik(Object.keys(o),t.cast),figureStyle:e,figureDance:t.dance,figureGaits:t.cast?.gaits,draw(r,a,l){const c=a.props,h=Va(c,l,t.dance,t.cast?.gaits);r.translate(s/2,n),Sd(r,h.pose,Pk({...e,rubber:c.rubber,facing:Td(c,e)},h.hands),l)}}}function Ik(t,e){const n={...Fu,...Nu};for(const s of t){const[,i,...o]=s.split("."),r=Wu[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 O2(e)}}}function Za(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=xd(i,e.time,t.figureDance,t.figureGaits),l=me(a,{...s,rubber:i.rubber,facing:Td(i,s)});return{pose:a,joints:Md(l,t.x+o+t.width/2,t.y+r+t.height)}}function So(t){const e=[];return t.forEach((n,s)=>{const i=s===0?ut:e[s-1],o=typeof n.pose=="string"?ae[n.pose]:{...i,...n.pose};e.push(n.expression?Xe(o,n.expression):o)}),e}function Ok(t,e){const n=So(e);return Zu.filter(s=>n.some(i=>i[s]!==ut[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 Qa=.5,xo={pataka:Nt({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:0,turn:2}),tripataka:Nt({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":1,"pinky.curl":0,spread:0,turn:2}),alapadma:Nt({"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:Nt({"thumb.curl":.15,"thumb.across":.6,"index.curl":.6,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:.7,turn:2}),katakamukha:Nt({"thumb.curl":.2,"thumb.across":.6,"index.curl":.65,"middle.curl":.7,"ring.curl":0,"pinky.curl":0,spread:.4,turn:2})};function To(t){return typeof t!="string"?t:t in xo?xo[t]:St[t]}function Ed(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?To(i.hands.left):r.left,right:i.hands?.right?To(i.hands.right):r.right,easing:i.easing??t.easing})}return s}const tl=(t,e)=>(t%e+e)%e;function _k(t,e,n,s){const i=Ed(t,n,s);if(i.length===0)return{pose:n,hands:s};const o=tl(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=Wt(l.easing??"ease-in-out")(Math.min(1,Math.max(0,u)));return{pose:Zn(a.pose,l.pose,d),hands:{left:Jn(a.left,l.left,d),right:Jn(a.right,l.right,d)}}}const Ck=[["leftShoulder","rightShoulder"],["leftElbow","rightElbow"],["leftWrist","rightWrist"],["leftHip","rightHip"],["leftKnee","rightKnee"],["leftAnkle","rightAnkle"],["leftFootOut","rightFootOut"],["leftEye","rightEye"],["leftBrow","rightBrow"]],Hk=["lean","headTilt","lookX","spin"],Rk=new Set(["leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee"]);function Ad(t){const e={...t},n=(t.turn??0)>=.5;for(const[s,i]of Ck){const o=n&&Rk.has(s)?-1:1;e[s]=o*t[i],e[i]=o*t[s]}if(!n)for(const s of Hk)e[s]=-t[s];return e}const Lk=t=>Math.min(1,Math.max(-1,(.5-t)*4));function $d(t,e,n){const s=tl(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=Lk(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 Eo(t){const e={...ut,...t.stance};return t.expression?Xe(e,t.expression):e}function Pd(t){return{left:t.hands?.left?To(t.hands.left):Ot,right:t.hands?.right?To(t.hands.right):Ot}}function el(t,e,n){const s=t.moves[e.move];if(!s)throw new Error(`dance: "${t.label}" has no move "${e.move}"`);const i=_k(s,n,Eo(t),Pd(t));return e.mirror?{pose:Ad(i.pose),hands:{left:i.hands?.right,right:i.hands?.left}}:i}function Ao(t,e,n={}){const s=typeof t=="string"?Ge[t]:t;let i;if(n.move)i=el(s,{move:n.move,mirror:n.mirror},e);else{const o=s.routine,r=o.reduce((u,d)=>u+d.beats,0),a=tl(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=el(s,o[c],h),h<Qa&&o.length>1&&e>=Qa){const u=o[(c-1+o.length)%o.length],d=el(s,u,u.beats+h),f=Wt("ease-in-out")(h/Qa);i={pose:Zn(d.pose,i.pose,f),hands:{left:Jn(d.hands.left,i.hands.left,f),right:Jn(d.hands.right,i.hands.right,f)}}}}return{...i,pose:$d(i.pose,s.groove,e)}}function Fk(t,e,n={}){return Ao(t,e,n).pose}function $o(t){return(typeof t=="string"?Ge[t]:t).routine.reduce((n,s)=>n+s.beats,0)}const Nk={leftToe:"rightToe",rightToe:"leftToe",leftHeel:"rightHeel",rightHeel:"leftHeel"};function Id(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?Nk[u]:u})}}function Wk(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;Id(r,a,Math.ceil((n-a)/r.beats)*r.beats,s.mirror,o,e,n)}else{const r=$o(i);for(let a=Math.floor(e/r)*r;a<n;a+=r){let l=a;for(const c of i.routine)Id(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 Od(t,e){const n=t.moves[e.move];if(!n?.travel)return 0;const s=n.travel/n.beats;return e.mirror?(Ed(n,Eo(t),Pd(t))[0]?.pose.turn??Eo(t).turn??0)>=.5?s:-s:s}function _d(t,e){return e.move?[{move:e.move,beats:t.moves[e.move].beats,mirror:e.mirror}]:t.routine}function Po(t,e,n={}){const s=typeof t=="string"?Ge[t]:t,i=_d(s,n),o=i.reduce((h,u)=>h+u.beats,0),r=i.reduce((h,u)=>h+Od(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+=Od(s,h)*u,c-=u,c<=0)break}return l}function Dk(t,e,n){const s=_d(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 Bk=8;function Cd(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:$o(s)),r=Dk(s,o,n);if(r.every(w=>Po(s,w,n)===0))return;const a=Math.min(n.fade??1,o/2),l=Wt("ease-in-out"),c=w=>a<=0?1:Math.min(l(Math.min(1,w/a)),l(Math.min(1,(o-w)/a))),h=Math.ceil(a*Bk),u=a<=0?[]:Array.from({length:h+1},(w,v)=>[v/h*a,o-v/h*a]).flat(),d=[...new Set([...r,...u])].sort((w,v)=>w-v);let f=0;const p=d.map((w,v)=>{if(v>0){const k=d[v-1],y=Math.max(1,Math.ceil((w-k)*16));for(let x=0;x<y;x++){const P=k+(w-k)*x/y,M=k+(w-k)*(x+1)/y;f+=(Po(s,M,n)-Po(s,P,n))*c((P+M)/2)}}return{beat:w,travel:f}}),g=n.start??0,m=n.x??0;return{id:`${t}-x`,target:t,property:"x",keyframes:p.map(w=>({time:g+w.beat*6e4/i,value:m+n.height*w.travel,easing:"linear"}))}}function zk(t,e,n=0){return(t-n)*e/6e4}function qk(t,e={}){return n=>Ao(t,n,e)}function jk(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 Yk(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:$o(s)),r=n.samplesPerBeat??4,a=n.start??0,l=Math.round(o*r),c=Array.from({length:l+1},(g,m)=>{const w=m/r;return{time:a+w*6e4/i,frame:Ao(s,w,n)}}),h=(g,m)=>({id:`${t}-${g}`,target:t,property:g,keyframes:c.map(w=>({time:w.time,value:m(w.frame)}))}),d=Object.keys(ut).filter(g=>c.some(m=>m.frame.pose[g]!==c[0].frame.pose[g])||c[0].frame.pose[g]!==ut[g]).map(g=>h(g,m=>m.pose[g])),f=n.height===void 0?void 0:Cd(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 p=[];for(const g of["left","right"])for(const m of Object.keys(Ot)){const w=v=>v.hands?.[g]?.[m]??Ot[m];c.some(v=>w(v.frame)!==Ot[m])&&p.push(h(ai(g,m),w))}return[...d,...p]}const li={type:"back",mode:"out",overshoot:1.1},Zt="ease-out-cubic",Kk={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:Zt,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:Zt},{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:Zt},{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}]},Xk={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}]},Gk={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:Zt},{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:Zt},{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:Zt},{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:li},{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}]},Uk={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:Zt},{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}]},Vk={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:li,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:li},{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:li},{beat:3,pose:{headTilt:4}}]},isolations:{label:"Isolations",beats:2,easing:Zt,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}]},Jk={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:Zt},{beat:.5,pose:{lean:-4,rightHip:12,headTilt:6}},{beat:1,pose:{lean:-11,rightHip:22,headTilt:10},easing:Zt},{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:Zt},{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:Zt}]}},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}]},Zk={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}]},Qk={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}]},t5={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:Zt},{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:Zt},{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}]},e5={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:Kk,hipHop:Xk,breaking:Gk,jazz:Uk,kpop:Vk,bollywood:Jk,bhangra:Zk,bharatanatyam:Qk,charleston:t5,tap:e5,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:li},{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}]}},Io={standard:{},slim:{headSize:.24,shoulderWidth:.05,hipWidth:.02},tall:{headSize:.25,legLength:1.1,armLength:1.05},short:{headSize:.33,legLength:.92,shoulderWidth:.065,hipWidth:.03},broad:{shoulderWidth:.11,hipWidth:.04},curvy:{shoulderWidth:.055,hipWidth:.065},stocky:{headSize:.34,shoulderWidth:.1,hipWidth:.06},kid:{headSize:.42},child:{headSize:.4,legLength:.88,armLength:.9,shoulderWidth:.05,hipWidth:.02},toddler:{headSize:.46,legLength:.78,armLength:.82,shoulderWidth:.05,hipWidth:.025}},nl=.215,sl=.205,n5=.065,Hd=.035,s5=.165,i5=.155,o5=12,r5=.3,a5=.7,l5=.35,c5=t=>t*Math.PI/180,lt={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,pupil:1,lid:0,bulge:0,"brow.left":0,"brow.right":0,browTilt:0,lookX:0,lookY:0,blush:0,tears:0,sweat:0,"hair.swing":0,"hair.trail":0,"hair.lift":0,"held.left":1,"held.right":1,"held.both":1};function kt(t={}){return{...lt,...t}}const h5=new Set(["turn","side","head.turn","head.tilt","roll","lookX","hair.swing"]);function Rd(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]=h5.has(n)?-s:s}return e}function $t(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 ye={rest:lt,wave:kt({"arm.right.spread":115,"arm.right.bend":55,"arm.right.elbow":0,"head.tilt":-6,smile:.9}),cheer:kt({...$t("arm",{spread:140,bend:20,elbow:0}),mouth:.6,smile:1,"eye.left":0,"eye.right":0}),point:kt({"arm.right.spread":88,"arm.right.elbow":0,"arm.right.bend":0,"head.turn":-20,smile:.4}),handsOnHips:kt({...$t("arm",{spread:50,bend:-105,elbow:0}),...$t("leg",{spread:9}),smile:.8}),think:kt({"arm.right.spread":22,"arm.right.bend":-150,"arm.right.elbow":0,"head.tilt":10,lookX:-.5,lookY:-.8,smile:0}),shrug:kt({...$t("arm",{spread:35,bend:75,elbow:0}),"head.tilt":-10,smile:-.2}),sit:kt({...$t("leg",{swing:90,knee:90,spread:4}),...$t("arm",{swing:25,elbow:45,spread:8})}),kneel:kt({"leg.left.swing":90,"leg.left.knee":90,"leg.right.swing":-18,"leg.right.knee":108,"leg.right.ankle":16,...$t("arm",{swing:20,elbow:30})}),crouch:kt({...$t("leg",{swing:75,knee:140,spread:6}),lean:25,...$t("arm",{swing:50,elbow:40}),"head.nod":-15}),crawl:kt({lean:82,"head.nod":-35,...$t("arm",{swing:80,elbow:0,spread:4}),...$t("leg",{knee:92,ankle:-88})}),lieDown:kt({roll:90,...$t("arm",{spread:8}),"head.nod":0}),sleep:kt({roll:90,...$t("arm",{spread:8,swing:20,elbow:40}),"leg.left.knee":20,"leg.left.swing":15,blink:1,smile:.2}),stretch:kt({side:-16,"arm.left.spread":165,"arm.left.bend":35,"arm.left.elbow":0,"arm.right.spread":40,"arm.right.bend":-110,"arm.right.elbow":0,"head.tilt":-10,"eye.left":0,"eye.right":0,smile:.4}),sitFloor:kt({...$t("leg",{swing:80,spread:22,rotate:75,knee:145}),...$t("arm",{swing:25,spread:18,elbow:30}),lean:5,smile:.5}),carry:kt({...$t("arm",{spread:16,elbow:4}),lean:-3,smile:.4}),cane:kt({"arm.right.swing":16,"arm.right.spread":10,"arm.right.elbow":0,"arm.right.bend":0,"arm.left.swing":2,side:-3,lean:4,"leg.right.swing":4,smile:.3}),lift:kt({...$t("arm",{swing:28,spread:24,elbow:85,bend:-45}),...$t("leg",{swing:12,knee:22,spread:6}),lean:-4,smile:.2}),push:kt({lean:28,...$t("arm",{swing:82,spread:12,elbow:18}),"leg.left.swing":28,"leg.left.knee":30,"leg.right.swing":-28,"leg.right.knee":6,"head.nod":-20,browTilt:-.6,smile:-.2}),pull:kt({lean:-22,...$t("arm",{swing:70,spread:6,elbow:0}),"leg.left.swing":32,"leg.left.knee":8,"leg.right.swing":-8,"leg.right.knee":34,"head.nod":12,browTilt:-.6,smile:-.2}),drink:kt({"arm.right.swing":85,"arm.right.spread":8,"arm.right.elbow":120,"arm.right.bend":0,"head.nod":-14,"eye.left":.5,"eye.right":.5,smile:0}),phone:kt({"arm.right.swing":80,"arm.right.spread":8,"arm.right.elbow":80,"arm.right.bend":-10,"head.nod":18,lookY:.7,lookX:-.3,smile:.4}),read:kt({...$t("arm",{swing:32,spread:10,elbow:82,bend:-28}),"head.nod":22,lookY:.8,smile:.2}),type:kt({...$t("leg",{swing:90,knee:90,spread:4}),...$t("arm",{swing:40,spread:10,elbow:55,bend:-20}),lean:8,"head.nod":10,lookY:.5,smile:0})},Ld=["round","flat","pointed","big"],u5={round:{length:1,width:[.95,.7]},flat:{length:1.12,width:[.85,.85]},pointed:{length:1.25,width:[1,.3]},big:{length:1.5,width:[1.25,1.1]}};function il(t={}){const e=t.headSize??.3,n=t.shoulderWidth??.06,s=t.hipWidth??.022,i=t.legLength??1,o=t.armLength??1,r=u5[t.feet??"round"],a=Math.max(.12,1-e-Hd-(nl+sl)*i),l=u=>({id:`arm.${u}`,parent:"spine",offset:[(u==="left"?1:-1)*n,-.035,0],rest:[0,-1,0],side:u==="left"?1:-1,bones:[{length:s5*o,width:[1.25,.9]},{length:i5*o,width:[.9,.75]}]}),c=u=>({id:`leg.${u}`,parent:null,offset:[(u==="left"?1:-1)*s,0,0],rest:[0,-1,0],side:u==="left"?1:-1,bones:[{length:nl*i,width:[1.45,1.05]},{length:sl*i,width:[1.05,.85]},{length:n5*Math.sqrt(i)*r.length,width:r.width}]}),h=(u,d)=>u[d]??lt[d]??0;return{id:"human",hipHeight:(nl+sl)*i,chains:[c("left"),c("right"),{id:"spine",parent:null,rest:[0,1,0],bones:[{length:a/2,width:[1.7,1.4]},{length:a/2,width:[1.4,1.1]}]},{id:"neck",parent:"spine",rest:[0,1,0],bones:[{length:Hd,width:[1,.9]}]},l("left"),l("right")],head:{on:"neck",size:e},contacts:[...["left","right"].flatMap(u=>[{chain:`leg.${u}`,joint:1},{chain:`leg.${u}`,joint:2},{chain:`leg.${u}`,joint:3},{chain:`arm.${u}`,joint:1},{chain:`arm.${u}`,joint:2}]),{chain:"spine",joint:0},{chain:"spine",joint:1},{chain:"spine",joint:2},{head:"top"}],angles(u,d){if(d.id==="spine"){const v=-h(u,"lean")/2,k=h(u,"side")/2,y=-h(u,"bend");return[{swing:v+y*r5,spread:k},{swing:v+y*a5,spread:k}]}if(d.id==="neck")return[{swing:-h(u,"bend")*l5,spread:0}];const[f,p]=d.id.split("."),g=v=>h(u,`${f}.${p}.${v}`);if(f==="arm")return[{swing:g("swing"),spread:g("spread")},{swing:g("elbow"),spread:g("bend")}];const m=(d.side??1)*g("rotate"),w=1-Math.cos(c5(g("rotate")));return[{swing:g("swing"),spread:g("spread"),yaw:m},{swing:-g("knee"),spread:0,yaw:m},{swing:90+g("ankle")-w*(g("swing")-g("knee")),spread:0,yaw:(o5+g("toeOut"))*(d.side??1)}]},withAngles(u,d,f){const[p,g]=d.id.split("."),m=w=>`${p}.${g}.${w}`;return p==="arm"?{...u,[m("swing")]:f[0].swing,[m("spread")]:f[0].spread,[m("elbow")]:f[1].swing,[m("bend")]:f[1].spread}:p==="leg"?{...u,[m("swing")]:f[0].swing,[m("spread")]:f[0].spread,[m("knee")]:-f[1].swing}:u},boneScale(u,d){const f=Math.min(3,Math.max(.3,h(u,"stretch")));return d?.id.startsWith("arm.")?Math.sqrt(f):f},headPose(u){const d=Math.min(3,Math.max(.3,h(u,"stretch")));return{yaw:h(u,"head.turn"),nod:h(u,"head.nod"),tilt:h(u,"head.tilt"),sx:1/Math.sqrt(d),sy:Math.sqrt(d)}},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 d5(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",pupil:"Pupil size",lid:"Eyelids lowered",bulge:"Eyes bulging","brow.left":"Left brow","brow.right":"Right brow",browTilt:"Brow slant",lookX:"Look left / right",lookY:"Look up / down",blush:"Blush",tears:"Tears",sweat:"Sweat","hair.swing":"Hair · swing","hair.trail":"Hair · trail","hair.lift":"Hair · lift","held.left":"Left hand · holding","held.right":"Right hand · holding","held.both":"Both hands · holding"}[t]??t}const f5={leftEye:"eye.left",rightEye:"eye.right",leftBrow:"brow.left",rightBrow:"brow.right"},g5={blush:0,tears:0,sweat:0,pupil:1,lid:0,bulge:0},vn=Object.fromEntries(Object.entries(vt).map(([t,e])=>[t,{...Object.fromEntries(Object.entries(e).map(([n,s])=>[f5[n]??n,s])),...g5}]));vn.crying.tears=1,vn.scared.sweat=.8,vn.scared.bulge=.4,vn.sleepy.lid=.5,vn.worried.sweat=.6;const ue=t=>({...vn.neutral,...t}),ol={...vn,laughing:ue({mouth:.75,smile:1,mouthWidth:1.25,"eye.left":0,"eye.right":0,"brow.left":.5,"brow.right":.5}),afraid:ue({mouth:.4,smile:-.6,mouthWidth:.9,"eye.left":1.3,"eye.right":1.3,"brow.left":.6,"brow.right":.6,browTilt:1,sweat:1,pupil:.8,bulge:.5}),bored:ue({smile:-.05,mouthWidth:.6,"eye.left":.45,"eye.right":.45,"brow.left":-.4,"brow.right":-.4,lookX:.5}),tired:ue({mouth:.2,smile:-.3,mouthWidth:.7,"eye.left":.3,"eye.right":.3,"brow.left":-.1,"brow.right":-.1,browTilt:.6,lookY:.6}),embarrassed:ue({smile:.4,mouthWidth:.7,"eye.left":.9,"eye.right":.9,browTilt:.7,"brow.left":.2,"brow.right":.2,lookX:-.6,lookY:.5,blush:1}),proud:ue({smile:.75,mouthWidth:1,"eye.left":.75,"eye.right":.75,"brow.left":.5,"brow.right":.5,lookY:-.2}),determined:ue({smile:.35,mouthWidth:.8,"eye.left":.85,"eye.right":.85,"brow.left":-.5,"brow.right":-.5,browTilt:-.9}),affectionate:ue({smile:.85,"eye.left":0,"eye.right":0,"brow.left":.3,"brow.right":.3,blush:.8}),hurt:ue({smile:-.7,mouthWidth:.8,"eye.left":1.1,"eye.right":1.1,"brow.left":.2,"brow.right":.2,browTilt:1,lookY:.3,tears:.35}),suspicious:ue({smile:-.25,mouthWidth:.7,"eye.left":.5,"eye.right":.85,"brow.left":-.6,"brow.right":.4,browTilt:-.3,lookX:.8,lid:.3}),relieved:ue({smile:.7,"eye.left":0,"eye.right":0,"brow.left":.4,"brow.right":.4,browTilt:.4}),excited:ue({mouth:.6,smile:1,mouthWidth:1.1,"eye.left":1.4,"eye.right":1.4,"brow.left":.9,"brow.right":.9,blush:.4,pupil:1.3})},de=t=>t*Math.PI/180;function rl([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t,e*i+n*o,-e*o+n*i]}function Qn([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i-e*o,t*o+e*i,n]}function Qt([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i+n*o,e,-t*o+n*i]}const Pe=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Oo=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],_o=(t,e)=>Qn(rl(t,e.swing),e.spread);function Co(t,e){const n=Qt(t,e);return{point:{x:n[0],y:-n[1]},depth:n[2]}}function ts(t,e,n){const s=n,o=[0,t.hipHeight*s*(t.boneScale?.(e,null)??1),0],r={};for(const g of t.chains){const m=g.parent?r[g.parent]:void 0;if(g.parent&&!m)throw new Error(`body plan ${t.id}: chain ${g.id} comes before its parent ${g.parent}`);const w=g.at??(m?m.joints3.length-1:0),v=m?m.joints3[w]:o,k=m?m.frames[Math.max(0,w-1)]:{swing:0,spread:0},y=g.offset?Pe(v,_o(Oo(g.offset,s),k)):v,x=g.side??1,P=t.boneScale?.(e,g)??1,M=t.angles(e,g),T=[y],S=[];let E=k.swing,$=k.spread;g.bones.forEach((A,I)=>{const C=M[I]??{swing:0,spread:0};E+=de(C.swing),$+=de(C.spread)*x,S.push({swing:E,spread:$});const D=Qt(_o(g.rest,{swing:E,spread:$}),de(C.yaw??0));T.push(Pe(T[I],Oo(D,A.length*s*P)))}),r[g.id]={joints3:T,frames:S}}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=g=>_o(Qt(rl(Qn(g,-de(l.tilt)),-de(l.nod)),de(l.yaw)),c),p=Pe(a.joints3[a.joints3.length-1],f([0,d,0]));return{height:s,root:o,chains:r,head:{center:p,rx:u,ry:d,toBody:f}}}function al(t,e,n){const s=n.height,i=de(90*(e.turn??0)),o=ts(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 S of t.chains){const{joints3:E,frames:$}=a[S.id],A=E.map(I=>Co(I,i));d[S.id]={id:S.id,joints3:E,frames:$,points:A.map(I=>I.point),depths:A.map(I=>I.depth)}}const f=Co(u,i),p=[[1,0,0],[0,1,0],[0,0,1]].map(S=>Qt(h(S),i)),g=Co(r,i).point,m=de(e.roll??0),w=S=>{const E=S.x-g.x,$=S.y-g.y;return{x:g.x+E*Math.cos(m)-$*Math.sin(m),y:g.y+E*Math.sin(m)+$*Math.cos(m)}},v=([S,E,$])=>[S*Math.cos(m)+E*Math.sin(m),-S*Math.sin(m)+E*Math.cos(m),$];for(const S of Object.values(d))S.points=S.points.map(w);const k={center:w(f.point),depth:f.depth,rx:l,ry:c,angle:0,axes:p.map(v)},y=k.axes[1];k.angle=Math.atan2(y[0],y[1]);const x=S=>{if("head"in S)return{x:k.center.x+y[0]*c,y:k.center.y-y[1]*c};const E=d[S.chain];return E.points[Math.min(S.joint,E.points.length-1)]};let P=0;(n.contact??"ground")==="ground"&&(P=-Math.max(...t.contacts.map(S=>x(S).y))),P-=(e.lift??0)*s;const M=S=>({x:S.x,y:S.y+P});for(const S of Object.values(d))S.points=S.points.map(M);k.center=M(k.center);const T=t.contacts.map(S=>({spec:S,point:x(S)}));return{height:s,view:i,chains:d,head:k,hip:M(w(g)),hipDepth:Co(r,i).depth,contacts:T,groundY:Math.max(...T.map(S=>S.point.y))}}const Ho=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],ll=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function Ue(t,e,n){const s=n.height,i=de(90*(e.turn??0)),o=de(e.roll??0),r=ts(t,e,s),a=Qt(r.root,i),l=m=>Pe(Qn(Ho(Qt(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=>ll(Ho(l(Pe(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 Pe(h,Oo(d[1],r.head.ry));const w=c[m.chain];return w[Math.min(m.joint,w.length-1)]};let p=0;(n.contact??"ground")==="ground"&&(p=-Math.min(...t.contacts.map(m=>f(m)[1]))),p+=(e.lift??0)*s;const g=m=>[m[0],m[1]+p,m[2]];return{height:s,hip:g(a),chains:Object.fromEntries(Object.entries(c).map(([m,w])=>[m,w.map(g)])),head:{center:g(h),rx:r.head.rx,ry:r.head.ry,axes:d}}}function Ro(t,e,n,s){const i=n.height,o=de(90*(e.turn??0)),r=ts(t,e,i),a=Ue(t,e,n),l=a.hip,c=a.chains,h=a.head.center,u=$=>{if("head"in $)return Pe(h,Oo(a.head.axes[1],a.head.ry));const A=c[$.chain];return A[Math.min($.joint,A.length-1)]},d=s.toView(l),f=Qn(Qt([0,0,1],o),-de(e.roll??0)),p=ll(Ho(s.toView(Pe(l,f)),d)),g=s.toScreen(d),m=s.toScreen([d[0]+1,d[1],d[2]]),w=Math.hypot(m.x-g.x,m.y-g.y),v=$=>{const A=s.toView($);return{point:s.toScreen(A),depth:A[2]*w}},k={};for(const $ of t.chains){const A=c[$.id].map(v);k[$.id]={id:$.id,joints3:r.chains[$.id].joints3,frames:r.chains[$.id].frames,points:A.map(I=>I.point),depths:A.map(I=>I.depth)}}const y=s.toView(h),x=s.toScreen(y),P=s.toScreen([y[0]+1,y[1],y[2]]),M=Math.hypot(P.x-x.x,P.y-x.y),T=a.head.axes.map($=>ll(Ho(s.toView(Pe(h,$)),y))),S={center:x,depth:y[2]*w,rx:r.head.rx*M,ry:r.head.ry*M,angle:Math.atan2(T[1][0],T[1][1]),axes:T},E=t.contacts.map($=>({spec:$,point:v(u($)).point}));return{height:i*w,view:o,bodyForward:p,chains:k,head:S,hip:g,hipDepth:d[2]*w,contacts:E,groundY:Math.max(...E.map($=>$.point.y))}}function es(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}}const Lo=t=>t*180/Math.PI,Mn=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],cl=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],ns=t=>Math.hypot(t[0],t[1],t[2]),hl=t=>{const e=ns(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},Fo=t=>Math.atan2(Math.sin(t),Math.cos(t));function Fd(t){const[e,n,s]=hl(t);return{swing:Math.asin(Math.max(-1,Math.min(1,s))),spread:Math.atan2(e,-n)}}function ci(t,e,n,s,i){const o=t.chains.find(A=>A.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=al(t,{...e,turn:0,roll:0,lift:0},{height:i.height,contact:"none"}),a=r.chains[n];if(ns(Mn(s,a.joints3[2]))<i.height*1e-12)return e;const l=a.joints3[0],c=ns(Mn(a.joints3[1],a.joints3[0])),h=ns(Mn(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=Mn(s,l),f=t.angles(e,o),p=A=>(f[A]?.yaw??0)*Math.PI/180,g=Math.min(c+h-1e-6,Math.max(Math.abs(c-h)+1e-6,ns(d))),m=hl(d),w=o.parent!==null,v=Qt(_o(o.pole??(w?[0,-.35,-1]:[0,0,1]),u),p(0));let k=Mn(v,[m[0]*cl(v,m),m[1]*cl(v,m),m[2]*cl(v,m)]);ns(k)<1e-6&&(k=Qt([1,0,0],p(0))),k=hl(k);const y=(c*c+g*g-h*h)/(2*c*g),x=Math.sqrt(Math.max(0,1-y*y)),P=[l[0]+c*(y*m[0]+x*k[0]),l[1]+c*(y*m[1]+x*k[1]),l[2]+c*(y*m[2]+x*k[2])],M=[l[0]+m[0]*g,l[1]+m[1]*g,l[2]+m[2]*g],T=o.side??1,S=Fd(Qt(Mn(P,l),-p(0))),E=Fd(Qt(Mn(M,P),-p(1))),$=[{swing:Lo(Fo(S.swing-u.swing)),spread:Lo(Fo(S.spread-u.spread))*T},{swing:Lo(Fo(E.swing-S.swing)),spread:Lo(Fo(E.spread-S.spread))*T}];return t.withAngles(e,o,$)}const ss=(t,e)=>(t%e+e)%e,Nd=t=>t*t*(3-2*t),p5=t=>Object.fromEntries(["left","right"].flatMap(e=>Object.entries(St[t]).map(([n,s])=>[`hand.${e}.${n}`,s])));function ul(t,e=!1){const n=il(),s=ci(n,lt,"arm.left",[.015,.68,.2],{height:1}),i=ci(n,s,"arm.right",[-.015,.68,.2],{height:1});return Array.from({length:32},(o,r)=>{const a=r/4,l=Math.floor(a),c=a-l,h=l%2===0,u=Math.sin(Math.PI*c),d=Math.max(0,...t.map(p=>1-Math.min(ss(a-p,8),ss(p-a,8))/.5)),f={side:(h?1:-1)*5*Math.sin(Math.PI*c),bend:2+3*u,"head.tilt":(h?-1:1)*3*u,"head.nod":-2*u,"leg.left.swing":h?-4*u:17*u,"leg.right.swing":h?17*u:-4*u,"leg.left.knee":h?5*u:36*u,"leg.right.knee":h?36*u:5*u,"leg.left.spread":4,"leg.right.spread":4,"arm.left.swing":22+d*(e?45:42),"arm.right.swing":22+d*(e?45:42),"arm.left.spread":28-22*d,"arm.right.spread":28-22*d,"arm.left.elbow":48+22*d,"arm.right.elbow":48+22*d,"arm.left.bend":-35*d,"arm.right.bend":-35*d,smile:.9,...p5(e?"hold":"spread")};if(!e)for(const p of Object.keys(i))p.startsWith("arm.")&&(f[p]+=(i[p]-f[p])*d);return{beat:a,pose:f}})}const Sn={garba:{label:"Garba · two clap",bpm:120,beats:8,strikes:[2,3,6,7],keys:ul([2,3,6,7])},garbaThreeClap:{label:"Garba · three clap",bpm:120,beats:8,strikes:[1,2,3,5,6,7],keys:ul([1,2,3,5,6,7])},dandiya:{label:"Dandiya · partner strikes",bpm:120,beats:8,strikes:[1,3,5,7],keys:ul([1,3,5,7],!0)}};function Wd(t){const e=typeof t=="string"&&Object.hasOwn(Sn,t)?Sn[t]:typeof t=="string"?void 0:t;if(!e||!Number.isFinite(e.beats)||e.beats<=0||!Array.isArray(e.keys)||!e.keys.length||!Array.isArray(e.strikes)||!e.keys.every((n,s)=>Number.isFinite(n.beat)&&n.beat>=0&&n.beat<e.beats&&(s===0||n.beat>e.keys[s-1].beat)&&n.pose&&Object.values(n.pose).every(Number.isFinite))||!e.strikes.every(n=>Number.isFinite(n)&&n>=0&&n<e.beats))throw new Error("humanDanceFrame: a dance with positive finite beats, ordered pose keys and strike beats within its loop is required");return e}function hi(t,e,n=lt){const s=Wd(t);if(!Number.isFinite(e))throw new Error("humanDanceFrame: beat must be finite");const i=ss(e,s.beats);let o=s.keys.length-1;for(let m=0;m<s.keys.length;m++)s.keys[m].beat<=i&&(o=m);const r=s.keys[o],a=s.keys[(o+1)%s.keys.length],l=r.beat>i?r.beat-s.beats:r.beat,c=a.beat<=r.beat?a.beat+s.beats:a.beat,h=Nd((i-l)/(c-r.beat)),u={...lt,...n};for(const m of new Set(s.keys.flatMap(w=>Object.keys(w.pose)))){if(m==="turn"||m==="roll")continue;const w=m.match(/^hand\.(?:left|right)\.(.+)$/)?.[1],v=n[m]??lt[m]??(w?Ot[w]:void 0)??0,k=r.pose[m]??v;u[m]=k+((a.pose[m]??v)-k)*h}const d=Math.floor(e),f=e-d,p=f<=.6?1:1-Nd((f-.6)/.4),g=Math.max(0,...s.strikes.map(m=>1-Math.min(ss(i-m,s.beats),ss(m-i,s.beats))/.25));return{pose:u,contact:{side:ss(d,2)===0?"left":"right",start:d,weight:p},strike:g}}function m5(t,e){const n=Wd(e.style),s=e.bpm??n.bpm,i=e.beats??n.beats,o=e.samplesPerBeat??16;if(![s,i,o].every(l=>Number.isFinite(l)&&l>0))throw new Error("humanDanceTracks: bpm, beats and samplesPerBeat must be positive and finite");if(!Number.isFinite(e.start??0))throw new Error("humanDanceTracks: start must be finite");const r=Math.max(1,Math.ceil(i*o)),a=Array.from({length:r+1},(l,c)=>({time:(e.start??0)+i*c/r*6e4/s,pose:hi(n,i*c/r,e.pose).pose}));return Object.keys(a[0].pose).filter(l=>l!=="turn"&&l!=="roll"&&a.some(c=>c.pose[l]!==(e.pose?.[l]??lt[l]))).map(l=>({id:`${t}-dance-${l}`,target:t,property:l,keyframes:a.map(c=>({time:c.time,value:c.pose[l],easing:"linear"}))}))}function is(t,e,n,s){if(!Number.isFinite(t)||t<n||t>s)throw new Error(`organic body: ${e} must be ${n}..${s}`);return t}function No(t,e){if(t.length<2||t[0].at!==0||t.at(-1).at!==1)throw new Error(`organic body: ${e} must run from 0 to 1`);return t.map((n,s)=>{if(is(n.at,`${e}.at`,0,1),is(n.width,`${e}.width`,.001,.3),s>0&&n.at<=t[s-1].at)throw new Error(`organic body: ${e} positions must increase`);return{at:n.at,width:n.width}})}function Dd(t,e){const n=Math.max(.095,e.shoulderWidth+.025),s=Math.max(.085,e.hipWidth+.032),i=t.shading??{},o=i.light??[-.8,-.6];if(o.length!==2||!o.every(Number.isFinite)||Math.hypot(...o)===0)throw new Error("organic body: light must be a finite nonzero 2D vector");if(i.mode!==void 0&&i.mode!=="none"&&i.mode!=="cel")throw new Error("organic body: unknown shading mode");return{torso:No(t.torso??[{at:0,width:s},{at:.2,width:s},{at:.42,width:s*.72},{at:.68,width:n*.9},{at:.86,width:n},{at:1,width:.024}],"torso"),arm:No(t.arm??[{at:0,width:.028},{at:.22,width:.027},{at:.5,width:.019},{at:.68,width:.023},{at:1,width:.012}],"arm"),leg:No(t.leg??[{at:0,width:.04},{at:.24,width:.042},{at:.5,width:.027},{at:.68,width:.032},{at:1,width:.016}],"leg"),neck:No(t.neck??[{at:0,width:.024},{at:1,width:.023}],"neck"),depth:is(t.depth??.55,"depth",.2,1),fill:t.fill??e.skin,outline:{color:t.outline?.color??e.ink,width:is(t.outline?.width??e.lineWidth,"outline.width",0,100)},shading:{mode:i.mode??"cel",light:[...o],shadow:i.shadow??"#633923",opacity:is(i.opacity??.17,"shading.opacity",0,1),highlight:is(i.highlight??.12,"shading.highlight",0,1)}}}function Bd(t,e){const n=Math.min(1,Math.max(0,e)),s=t.findIndex(a=>a.at>=n);if(s<=0)return t[0].width;const i=t[s-1],o=t[s],r=(n-i.at)/(o.at-i.at);return i.width+(o.width-i.width)*r*r*(3-2*r)}const zd=8,y5=(t,e,n)=>({x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n}),xn=(t,e)=>{const n=Math.hypot(e.x-t.x,e.y-t.y)||1;return{x:(e.x-t.x)/n,y:(e.y-t.y)/n}},Wo=(t,e,n)=>({x:t.x+e.x*n,y:t.y+e.y*n});function ui(t,e=12){if(!Number.isInteger(e)||e<1||e>128)throw new Error("organicCenterLine: steps must be an integer from 1 to 128");if(t.length<2)return t.map(i=>({...i}));const n=t.map((i,o)=>{const r=xn(t[Math.max(0,o-1)],i),a=xn(i,t[Math.min(t.length-1,o+1)]),l=Math.hypot(r.x+a.x,r.y+a.y);return l>1e-6?{x:(r.x+a.x)/l,y:(r.y+a.y)/l}:a}),s=[];for(let i=0;i<t.length-1;i++){const o=t[i],r=t[i+1],a=Math.hypot(r.x-o.x,r.y-o.y)*.28,l=Wo(o,n[i],a),c=Wo(r,n[i+1],-a);for(let h=i===0?0:1;h<=e;h++){const u=h/e,d=1-u;s.push({x:d**3*o.x+3*d*d*u*l.x+3*d*u*u*c.x+u**3*r.x,y:d**3*o.y+3*d*d*u*l.y+3*d*u*u*c.y+u**3*r.y})}}return s}function Do(t,e,n,s=1,i=1){const o=t.map((h,u)=>{const d=t[Math.max(0,u-1)],f=t[Math.min(t.length-1,u+1)];let p=xn(d,f);Math.hypot(p.x,p.y)<1e-6&&(p={x:0,y:1});const g={x:-p.y,y:p.x},m=u/Math.max(1,t.length-1),w=Bd(e,m)*n*s,v=xn(d,h),k=xn(h,f),y=v.x*k.y-v.y*k.x,x=Math.acos(Math.min(1,Math.max(-1,v.x*k.x+v.y*k.y))),P=(Math.hypot(h.x-d.x,h.y-d.y)+Math.hypot(f.x-h.x,f.y-h.y))/(2*Math.max(1e-6,x)),M=Math.min(w,Math.max(w*.2,P*.8));return{center:h,width:w,at:m,left:Wo(h,g,y>0?M:w),right:Wo(h,g,y<0?-M:-w)}}),r=[],a=[],l=(h,u)=>{r.push(h),a.push(u)};for(const h of o)l(h.left,h.at);const c=(h,u,d)=>{const f={x:-u.y,y:u.x};for(let p=1;p<zd;p++){const g=p*Math.PI/zd,m=(d?1:-1)*Math.cos(g),w=(d?1:-i)*Math.sin(g);l({x:h.center.x+h.width*(f.x*m+u.x*w),y:h.center.y+h.width*(f.y*m+u.y*w)},h.at)}};c(o.at(-1),xn(t[Math.max(0,t.length-2)],t.at(-1)),!0);for(const h of[...o].reverse())l(h.right,h.at);return c(o[0],xn(t[0],t[Math.min(1,t.length-1)]),!1),{outline:r,samples:o,positions:a}}function qd(t,e,n){const s={},i=e.height,o=e.chains.spine;if(o?.length>=2){const r=e.points["shoulder.left"],a=e.points["shoulder.right"],l=n.chains.find(f=>f.id==="arm.left")?.offset?.[0]??.07,c=Math.max(1e-6,Math.abs(l)*i*2),h=r&&a?Math.min(1,Math.hypot(r.x-a.x,r.y-a.y)/c):Math.abs(Math.cos(e.turn*Math.PI/2)),u=Math.sqrt(h*h+t.depth*t.depth*(1-h*h)),d=[y5(o[0],o[1],-.16),...o.slice(1)];s.spine=Do(ui(d),t.torso,i,u,.25)}e.chains.neck?.length>=2&&(s.neck=Do(ui(e.chains.neck),t.neck,i));for(const r of["left","right"])for(const a of["arm","leg"]){const l=e.chains[`${a}.${r}`];!l||l.length<3||(s[`${a}.${r}`]=Do(ui(l.slice(0,3)),t[a],i),a==="leg"&&l.length>3&&(s[`foot.${r}`]=Do(ui(l.slice(2)),[{at:0,width:.019},{at:1,width:.014}],i)))}return s}function jd(t,e){let n=!1;for(let s=0,i=e.length-1;s<e.length;i=s++){const o=e[s],r=e[i];o.y>t.y!=r.y>t.y&&t.x<(r.x-o.x)*(t.y-o.y)/(r.y-o.y)+o.x&&(n=!n)}return n}function dl(t,e,n,s=0){const i=t.samples.filter(a=>a.at>=e&&a.at<=n),o=(a,l)=>{const c=a[l],h=a.center,u=Math.hypot(c.x-h.x,c.y-h.y)||1;return{x:c.x+(c.x-h.x)*s/u,y:c.y+(c.y-h.y)*s/u}},r=[...i.map(a=>o(a,"left")),...[...i].reverse().map(a=>o(a,"right"))];{const a=t.samples[0].center;for(const l of t.outline.slice(-7)){const c=Math.hypot(l.x-a.x,l.y-a.y)||1;r.push({x:l.x+(l.x-a.x)*s/c,y:l.y+(l.y-a.y)*s/c})}}return r}function Yd(t,e){t.beginPath(),t.moveTo(e[0].x,e[0].y);for(const n of e.slice(1))t.lineTo(n.x,n.y);t.closePath()}function b5(t,e,n){const s=n.shading;if(s.mode==="none"||n.fill==="none")return;const i=Math.hypot(...s.light),o={x:s.light[0]/i,y:s.light[1]/i},r=t.globalAlpha;t.save(),Yd(t,e.outline),t.clip();for(const a of["left","right"]){const l=e.samples.map(h=>h[a]),c=e.samples.map(h=>{const u=h[a],d=h.center,f=u.x-d.x,p=u.y-d.y,g=(f*o.x+p*o.y)/(Math.hypot(f,p)||1),m=Math.max(0,-g)*.44;return{x:u.x+(d.x-u.x)*m,y:u.y+(d.y-u.y)*m}});if(Yd(t,[...l,...c.reverse()]),t.fillStyle=s.shadow,t.globalAlpha=r*s.opacity,t.fill(),s.highlight>0){const h=e.samples.map(f=>{const p=f[a],g=f.center;return{x:p.x+(g.x-p.x)*.2,y:p.y+(g.y-p.y)*.2}}),u=e.samples[Math.floor(e.samples.length/2)][a],d=e.samples[Math.floor(e.samples.length/2)].center;if((u.x-d.x)*o.x+(u.y-d.y)*o.y>0){t.globalAlpha=r*s.highlight,t.strokeStyle="#ffffff",t.lineWidth=Math.max(1,e.samples[0].width*.16),t.beginPath(),t.moveTo(h[0].x,h[0].y);for(const f of h.slice(1))t.lineTo(f.x,f.y);t.stroke()}}}t.restore()}function w5(t,e,n,s){const i=s.bodyContours,o=r=>i[r]&&jd(t,i[r].outline);if(n.startsWith("arm."))return e<.2&&o("spine");if(n.startsWith("leg."))return e<.2&&o("spine")||e>.85&&o(n.replace("leg.","foot."));if(n.startsWith("foot."))return e<.25&&o(n.replace("foot.","leg."));if(n==="neck")return e<.6&&o("spine");if(n==="spine"){if(e>.85&&o("neck"))return!0;for(const r of["left","right"]){if(e>.6&&o(`arm.${r}`)){const a=s.chains[`arm.${r}`]?.[0];if(a&&Math.hypot(a.x-t.x,a.y-t.y)<s.height*.07)return!0}if(e<.25&&o(`leg.${r}`))return!0}}return!1}function Kd(t,e,n,s,i){const o=s.bodyContours?.[i];if(!o)return!1;if(n.fill==="none"&&(e=ei(t,e)),e.shape(o.outline,n.fill==="none"?null:n.fill,0),e.look==="clean"&&b5(t,o,n),(e.look!=="silhouette"||n.fill==="none")&&s.lineWidth>0){let r=[];for(let a=0;a<=o.outline.length;a++){const l=a%o.outline.length,c=o.outline[l],h=o.outline[(l+1)%o.outline.length],u={x:(c.x+h.x)/2,y:(c.y+h.y)/2};i.startsWith("arm.")&&o.positions[l]===1||w5(u,o.positions[l],i,s)?(r.length>=2&&e.line(r,s.lineWidth),r=[]):(r.length===0&&r.push(c),r.push(h))}r.length>=2&&e.line(r,s.lineWidth)}return!0}function Xd(t){return[[.01,-.12,.8],[0,-.25,.98],[-.04,-.31,.8]].map(e=>es(t,e).point)}function Gd(t,e){const n=e.shape==="angular"?k5(t,e):e.projection==="volume"?v5(t):po(t.center.x,t.center.y,t.rx,t.ry,t.angle);if(e.projection!=="volume"||!e.nose)return n;const s=Math.cos(t.angle),i=Math.sin(t.angle),o=u=>({x:((u.x-t.center.x)*s+(u.y-t.center.y)*i)/t.rx,y:((u.x-t.center.x)*i-(u.y-t.center.y)*s)/t.ry}),r=o(Xd(t)[1]),a=Math.sign(r.x),l=r.y,c=n.flatMap((u,d)=>{const f=o(u),p=o(n[(d+1)%n.length]);if(f.y>l==p.y>l)return[];const g=(l-f.y)/(p.y-f.y);return[(f.x+(p.x-f.x)*g)*a]}),h=Math.max(0,r.x*a-Math.max(...c));return!Number.isFinite(h)||h===0?n:n.flatMap((u,d)=>{const f=n[(d+1)%n.length],p=o(u),g=o(f),m=Math.max(1,Math.ceil(Math.hypot(g.x-p.x,g.y-p.y)/.025));return Array.from({length:m},(w,v)=>{const k=v/m,y={x:u.x+(f.x-u.x)*k,y:u.y+(f.y-u.y)*k},x=o(y),P=(x.y-l+.115)/.23;if(x.x*a<.5||P<=0||P>=1)return y;const M=Math.sin(P*Math.PI)**2*h*t.rx*a;return{x:y.x+M*s,y:y.y+M*i}})})}function k5(t,e){const n=Math.min(.95,Math.max(.55,e.jawWidth??.74)),s=Math.min(.35,Math.max(.03,e.chinWidth??.14)),i=[[-1,0],[-.92,s],[-.5,n],[-.12,Math.sqrt(1-.12**2)]];for(let o=0;o<=12;o++){const r=o*Math.PI/24;i.push([Math.sin(r),Math.cos(r)])}return Ud(t,i,e.jawRoundness??0,e.projection==="volume")}function v5(t){const e=Array.from({length:41},(n,s)=>{const i=-Math.PI/2+s*Math.PI/40;return[Math.sin(i),Math.cos(i)]});return Ud(t,e,0,!0)}function Ud(t,e,n,s){const i=[];for(const[a,l]of e)for(let c=0;c<40;c++){const h=c*Math.PI/20,u=l*Math.sin(h);i.push(es(t,[l*Math.cos(h),a,s?Math.min(u,.82):u]).point)}let o=fl(i);if(n=Math.min(1,Math.max(0,n)),n===0)return o;const r=n*.25;for(let a=0;a<3;a++)o=o.flatMap((l,c)=>{const h=o[(c+1)%o.length];return[{x:l.x+(h.x-l.x)*r,y:l.y+(h.y-l.y)*r},{x:h.x+(l.x-h.x)*r,y:h.y+(l.y-h.y)*r}]});return o}function fl(t){const e=t.sort((i,o)=>i.x-o.x||i.y-o.y),n=(i,o,r)=>(o.x-i.x)*(r.y-i.y)-(o.y-i.y)*(r.x-i.x),s=i=>{const o=[];for(const r of i){for(;o.length>=2&&n(o[o.length-2],o[o.length-1],r)<=0;)o.pop();o.push(r)}return o.slice(0,-1)};return[...s(e),...s([...e].reverse())]}const Vd=.34,Kt=.12,Xt=-.4,Gt=(t,e,n)=>t[e]??n,M5=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),S5=.45,x5=.35,T5=.7,Jd=.78;function xt(t,e,n,s="cartoon"){const i=f=>Math.sqrt(Math.max(0,1-f.x*f.x-f.y*f.y));let o=es(t,[n.x,n.y,i(n)]).facing;const r=t.axes[2];s==="volume"&&n.x*r[0]>0&&(o=Math.max(o,r[2]));const a=Math.atan2(r[0],r[2]),l=Math.cos(a),c=Math.max(x5,l),h=Math.max(T5,l),u=Math.cos(t.angle),d=Math.sin(t.angle);if(s==="volume"){const f=es(t,[n.x,n.y,i(n)*Jd]).point,p=Math.abs(n.x)>.1?Math.min(1,Math.max(0,o)/.25):1,g=Math.max(n.x*r[0]>0?.2:.5,l);return{facing:o,points:e.map(m=>{const w=(m.x-n.x)*g*t.rx*p,v=(m.y-n.y+r[1]*(i(m)-i(n))*Jd)*t.ry*p;return{x:f.x+w*u+v*d,y:f.y+w*d-v*u}})}}return{facing:o,points:e.map(f=>{const p=S5*Math.sin(a)+n.x*c+(f.x-n.x)*h,g=f.y+r[1]*i(f),m=p*t.rx,w=g*t.ry;return{x:t.center.x+m*u+w*d,y:t.center.y+m*d-w*u}})}}const Ve=(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}}),di=(t,e,n,s)=>{const i=Math.min(1,Math.max(0,(s-t.x)/(n.x-t.x))),o=1-i;return o*o*t.y+2*o*i*e.y+i*i*n.y},Ie=(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}}),Tn=.05,E5=.3,A5="#e06b7d";function $5(t,e,n,s,i={},o){const r=Math.max(1,Math.min(s*.6,.14*e.rx)),a=(A,I)=>xt(e,A,I,i.projection).points,l=(A,I)=>xt(e,[],{x:A,y:I},i.projection).facing,c=Gt(n,"smile",0),h=Gt(n,"blink",0),u=Gt(n,"lookX",0),d=Gt(n,"lookY",0),f=Gt(n,"browTilt",0),p=Math.max(.2,Gt(n,"pupil",1)),g=Math.min(1,Math.max(0,Gt(n,"lid",0))),m=Math.min(1,Math.max(0,Gt(n,"bulge",0)));for(const A of[1,-1]){const I=A===1?"left":"right",C=Vd*A;if(l(C,Kt)<Tn)continue;const D={x:C,y:Kt},j=M5(Gt(n,`eye.${I}`,1),h);if(j<.2||i.style==="anime"&&g>=.98){const F=c>.5?.12:-.06;t.line(a(Ve({x:C-.12,y:Kt},{x:C,y:Kt+F},{x:C+.12,y:Kt}),D),r)}else if(i.style==="anime")P5(t,e,D,A,j,g,m,p,u,d,r,i,o);else{const F=j>1.2||m>.02,H=.13*Math.max(j,1)*(1+m*.7);F&&t.shape(a(Ie(C,Kt,H*.85,H),D),"#ffffff",r);const W=(j>1.2?.075:.1)*p*(1+m*.3),_=C+u*.08,B=Kt-d*.07,Q=Ie(_,B,W,W*1.1*Math.min(j,1));if(t.shape(a(Q,D),t.ink,0),i.inPupil&&o){const[O]=a([{x:_,y:B}],D),R=a(Q,D),z=Math.min(...R.map(K=>Math.hypot(K.x-O.x,K.y-O.y)));z>.5&&(o.save(),o.beginPath(),o.arc(O.x,O.y,z,0,Math.PI*2),o.clip(),i.inPupil(o,{x:O.x,y:O.y,r:z,side:I}),o.restore())}if(g>.02){const O=F?H*1.15:W*1.4,R=Kt+O,z=R-O*2*g,K=O*1.1;t.shape(a([{x:C-K,y:R+.02},{x:C+K,y:R+.02},{x:C+K,y:z},{x:C-K,y:z}],D),i.skin??"#ffffff",0),t.line(a([{x:C-K,y:z},{x:C+K,y:z}],D),r)}}const V=Kt+(i.style==="anime"?.38:.3)+Gt(n,`brow.${I}`,0)*.14+Math.max(0,j-1)*.12,et={x:C+A*.13,y:V},G={x:C-A*.13,y:V+f*.1};t.line(a([et,{x:(et.x+G.x)/2,y:(et.y+G.y)/2},G],{x:C,y:V}),r)}O5(t,e,n,r,i.projection),I5(t,e,i.ageLines??0,r,i.projection);const w={x:0,y:Xt};if(l(0,Xt)<-Tn)return;i.nose&&l(0,Kt-.15)>=Tn&&(i.projection==="volume"?t.line(Xd(e),r):t.line(a([{x:.01,y:Kt-.1},{x:.03,y:Xt+.2},{x:-.05,y:Xt+.17}],{x:0,y:Xt+.22}),r));const v=.25*Math.max(.3,Gt(n,"mouthWidth",1)),k=Math.min(1,Math.max(0,Gt(n,"mouth",0)));if(k<=.05){t.line(a(Ve({x:-v,y:Xt},{x:0,y:Xt-c*.25},{x:v,y:Xt}),w),r);return}const y=.3*k;let x,P,M,T;if(c>.3){const A=Xt+.05,I={x:0,y:Xt-y*2};x=[...Ve({x:v,y:A},I,{x:-v,y:A})],P=()=>A,M=C=>di({x:v,y:A},I,{x:-v,y:A},C),T=.85}else if(c<-.3){const A=Xt-y*.6,I={x:0,y:Xt+y*1.4};x=[...Ve({x:v,y:A},I,{x:-v,y:A})],P=C=>di({x:v,y:A},I,{x:-v,y:A},C),M=()=>A,T=.5}else{const A=v*.8;x=Ie(0,Xt,A,y);const I=C=>y*Math.sqrt(Math.max(0,1-(C/A)**2));P=C=>Xt+I(C),M=C=>Xt-I(C),T=.5}if(t.shape(a(x,w),t.ink,0),k<E5)return;const S=P(0)-M(0),E=v*T,$=(A,I,C=8)=>Array.from({length:C+1},(D,j)=>A+(I-A)*j/C);if(i.tongue){const A=E*.55,I=$(A,-A).map(D=>({x:D,y:M(D)})),C=Ve({x:-A,y:M(-A)},{x:0,y:M(0)+S*.8},{x:A,y:M(A)},8);t.shape(a([...I,...C.slice(1,-1)],w),A5,0)}if(i.teeth){const A=Math.min(.06,S*.4),I=$(-E,E).map(D=>({x:D,y:P(D)})),C=I.map(({x:D,y:j})=>({x:D*.92,y:j-A})).reverse();t.shape(a([...I,...C],w),"#ffffff",0);for(const D of[-.5,0,.5]){const j=E*D;t.line(a([{x:j,y:P(j)},{x:j*.92,y:P(j)-A}],w),r*.6)}}}function P5(t,e,n,s,i,o,r,a,l,c,h,u,d){const{x:f,y:p}=n,g=Math.min(1.2,Math.max(.5,u.eyeScale??1)),m=Math.min(1.2,Math.max(.45,u.eyeAspect??1)),w=.21*g*(1+r*.15),v=.25*g*m*Math.min(i,1.6)*(1-o)*(1+r*.3),k={x:f-w,y:p},y={x:f+w,y:p},x={x:f,y:p+v*1.9},P={x:f,y:p-v*1.35},M=Ve(k,x,y),T=Ve(y,P,k),S=V=>xt(e,V,n,u.projection).points,E=V=>V.map(et=>{const G=Math.min(y.x,Math.max(k.x,et.x));return{x:G,y:Math.min(di(k,x,y,G),Math.max(di(y,P,k,G),et.y))}});t.shape(S([...M,...T.slice(1,-1)]),"#ffffff",h*.5);const $=f+Math.max(-1,Math.min(1,l))*.07*g,A=p-Math.max(-1,Math.min(1,c))*.055*g,I=.115*g,C=.185*g;t.shape(S(E(Ie($,A,I,C,24))),u.iris??"#4b7fce",h*.4),t.shape(S(E(Ie($,A-.075*g,I*.7,C*.35))),"rgba(255,255,255,0.25)",0);const D=Math.min(.085,.042*a)*g,j=E(Ie($,A,D,D*1.35));if(t.shape(S(j),t.ink,0),u.inPupil&&d){const[V]=S([{x:$,y:A}]),et=Math.min(...S(j).map(G=>Math.hypot(G.x-V.x,G.y-V.y)));et>.5&&(d.save(),d.beginPath(),d.arc(V.x,V.y,et,0,Math.PI*2),d.clip(),u.inPupil(d,{...V,r:et,side:s===1?"left":"right"}),d.restore())}if(t.shape(S(E(Ie($-.038*g,A+.075*g,.035*g,.045*g))),"#ffffff",0),t.shape(S(E(Ie($+.04*g,A-.04*g,.014*g,.02*g))),"#ffffff",0),t.line(S(M),h*1.1),u.lashes!==!1)for(const V of[0,.035]){const et=f+s*(w-V),G=di(k,x,y,et);t.line(S([{x:et,y:G},{x:et+s*.055,y:G+.07}]),h*.75)}}function I5(t,e,n,s,i){const o=Math.min(1,Math.max(0,n));if(!(o<=0))for(const r of[-1,1]){const a={x:r*.59,y:Kt};if(xt(e,[],a,i).facing<Tn)continue;for(const h of[-.06,.035]){const u=[{x:a.x,y:a.y},{x:a.x+r*.1,y:a.y+h}];t.line(xt(e,u,a,i).points,s*.45*o)}const l={x:r*.3,y:-.38},c=Ve({x:l.x,y:-.31},{x:l.x+r*.07,y:-.4},{x:l.x+r*.035,y:-.49});t.line(xt(e,c,l,i).points,s*.35*o)}}const Zd="#8fd0f5",Qd=(t,e,n)=>Array.from({length:18},(s,i)=>{const o=Math.PI*2*i/18,r=Math.sin(o/2);return{x:t+Math.sin(o)*n*r,y:e-n*.9+Math.cos(o)*n*1.6*(.55+.45*r)-n*.4}});function O5(t,e,n,s,i){const o=Math.min(1,Math.max(0,Gt(n,"blush",0))),r=Math.min(1,Math.max(0,Gt(n,"tears",0))),a=Math.min(1,Math.max(0,Gt(n,"sweat",0)));if(!(o+r+a<=.01)){for(const l of[1,-1]){const c={x:.5*l,y:-.16},h=xt(e,[],c,i).facing>=Tn;if(o>.01&&h){const{points:d}=xt(e,Ie(c.x,c.y,.17,.1),c,i);if(t.shape(d,`rgba(240, 120, 140, ${(.75*o).toFixed(3)})`,0),o>.5)for(const f of[-.07,0,.07]){const p=[{x:c.x+f-.018,y:c.y-.03},{x:c.x+f+.018,y:c.y+.03}];t.line(xt(e,p,c,i).points,s*.3)}}const u={x:Vd*l,y:Kt};if(r>.01&&xt(e,[],u,i).facing>=Tn){const d=.05+.04*r,f={x:u.x+.06*l,y:Kt-.2-.12*r};if(t.shape(xt(e,Qd(f.x,f.y,d),f,i).points,Zd,s*.35),r>.6){const p=[{x:u.x+.05*l,y:Kt-.1},{x:f.x,y:f.y+d*.8}];t.line(xt(e,p,f,i).points,s*.3)}}}if(a>.01){const l={x:.64,y:.42};xt(e,[],l,i).facing>=Tn&&t.shape(xt(e,Qd(l.x,l.y,.05+.05*a),l,i).points,Zd,s*.35)}}}const _5=15;function Se(t,e){const n=Math.sqrt(Math.max(0,1-e*e));return[n*Math.sin(t),e,n*Math.cos(t)]}const C5=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function te(t,[e,n,s]){const[i,o,r]=t.axes;return i[2]*e+o[2]*n+r[2]*s}function _t(t,e){return es(t,e).point}function Bo(t,e){const n=Math.abs(t-e)%(Math.PI*2);return n>Math.PI?Math.PI*2-n:n}function zo(t,e,n=64){const s=e.top??1,i=e.bottom??-1,o=Math.max(8,Math.ceil((s-i)*_5)),r=p=>Math.min(s,Math.max(i,s-(s-i)*(p-1)/o)),a=p=>-Math.PI+Math.PI*2*p/n,l=(p,g)=>e.normal?e.normal(p,g):C5(e.position(p,g)),c=o+3,h=new Float64Array(n*c),u=new Float64Array(n*c);for(let p=0;p<c;p++){const g=p===0||p===c-1,m=r(p);for(let w=0;w<n;w++){const v=p*n+w;if(g){h[v]=-1;continue}const k=a(w);h[v]=e.inside(k,m),u[v]=h[v]>-.35?te(t,l(k,m)):0}}const d=p=>(p%n+n)%n,f=p=>{const g=n+1,m=new Float64Array(g*c);for(let A=0;A<c;A++)for(let I=0;I<=n;I++){const C=A*n+(I===n?0:I);m[A*g+I]=Math.min(h[C],p*u[C])}const w=(A,I)=>m[I*g+A],v=(A,I,C,D)=>{const j=w(A,I),V=w(C,D),et=j===V?.5:Math.min(1,Math.max(0,j/(j-V)));return _t(t,e.position(a(A+(C-A)*et),r(I+(D-I)*et)))},k=n*c*2,y=new Int32Array(k).fill(-1),x=new Int32Array(k).fill(-1),P=new Map,M=(A,I,C)=>{const D=(C*n+d(I))*2+(A?1:0);return P.has(D)||P.set(D,A?v(d(I),C,d(I),C+1):v(I,C,I+1,C)),D},T=(A,I)=>{y[A]===-1?y[A]=I:x[A]=I},S=(A,I)=>{T(A,I),T(I,A)};for(let A=0;A<c-1;A++)for(let I=0;I<n;I++){const C=A*g+I,D=(m[C]>0?8:0)|(m[C+1]>0?4:0)|(m[C+g+1]>0?2:0)|(m[C+g]>0?1:0);if(D===0||D===15)continue;const j=()=>M(!1,I,A),V=()=>M(!1,I,A+1),et=()=>M(!0,I,A),G=()=>M(!0,I+1,A);switch(D){case 1:case 14:S(et(),V());break;case 2:case 13:S(V(),G());break;case 3:case 12:S(et(),G());break;case 4:case 11:S(j(),G());break;case 6:case 9:S(j(),V());break;case 7:case 8:S(et(),j());break;case 5:case 10:{const F=(w(I,A)+w(I+1,A)+w(I+1,A+1)+w(I,A+1))/4>0;D===5===F?(S(et(),j()),S(V(),G())):(S(et(),V()),S(j(),G()));break}}}const E=[],$=new Uint8Array(k);for(const A of P.keys()){if($[A])continue;const I=[];let C=-1,D=A;for(;D!==-1&&!$[D];){$[D]=1,I.push(P.get(D));const j=y[D],V=x[D],et=j!==-1&&j!==C&&!$[j]?j:V!==-1&&V!==C&&!$[V]?V:-1;C=D,D=et}I.length>=3&&E.push(I)}return E};return{near:f(1),far:f(-1)}}const tf=new WeakMap;function gl(t,e,n){let s=tf.get(t);s||tf.set(t,s=new Map);let i=s.get(e);return i||s.set(e,i=n()),i}function pl(t,e,n,s){if(t.save(),t.beginPath(),t.rect(-1e5,-1e5,2e5,2e5),s?.length){t.moveTo(s[0].x,s[0].y);for(const i of s.slice(1))t.lineTo(i.x,i.y);t.closePath()}else t.ellipse(e.center.x,e.center.y,e.rx,e.ry,e.angle,0,Math.PI*2);t.clip("evenodd"),n(),t.restore()}function ef(t,e,n,s=.04){const i=[];let o=[];return e.forEach((r,a)=>{te(t,n[a])>s?o.push(_t(t,r)):(o.length>=2&&i.push(o),o=[])}),o.length>=2&&i.push(o),i}const nf=t=>t*Math.PI/180,ml=t=>{const e=Math.hypot(...t)||1;return t.map(n=>n/e)},H5=(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]];function sf(t,e,n){return t>=e+n?t:t<=e-n?e:e+(t-e+n)**2/(4*n)}function yl(t,e,n){const s=ml(n),i=t.reduce((c,h,u)=>c+h*s[u],0),r=t.map((c,h)=>c-i*s[h]).reduce((c,h)=>c+h*h,0),a=Math.sqrt(sf(1-r,e*e,e*e)),l=sf(i,a,e)-i;return l===0?t:t.map((c,h)=>c+s[h]*l)}function R5(t){if(t.path.length<4||(t.path.length-1)%3!==0)throw new Error("hair: a lock path needs a root and groups of three cubic points");if(!Number.isFinite(t.width)||t.width<=0||t.follow!==void 0&&(!Number.isFinite(t.follow)||t.follow<0))throw new Error("hair: lock width must be positive and follow must be nonnegative");for(const n of t.path)if(!Number.isFinite(n.around)||!Number.isFinite(n.up)||n.up>1||n.lift!==void 0&&(!Number.isFinite(n.lift)||n.lift<0))throw new Error("hair: lock points need finite around/up values, up <= 1 and nonnegative lift");const e=t.path[0];if(e.up<0||(e.lift??0)!==0)throw new Error("hair: a lock root must lie on the scalp (up 0..1, lift 0)");return{...t,path:t.path.map(n=>({...n}))}}function L5(t,e,n,s){const i=(t.path.length-1)/3,o=i*20,r=[],a=[],l=s.trail!==0||s.lift!==0,c=Math.max(0,e+n);for(let h=0;h<=o;h++){const u=h/o,d=Math.min(i-1,Math.floor(u*i)),f=u*i-d,p=1-f,g=[p**3,3*p*p*f,3*p*f*f,f**3],m=t.path.slice(d*3,d*3+4),w=nf(m.reduce((C,D,j)=>C+D.around*g[j],0)),v=m.reduce((C,D,j)=>C+D.up*g[j],0),k=m.reduce((C,D,j)=>C+(D.lift??0)*g[j],0),y=1+e+n+k,x=v>=0?Math.sqrt(Math.max(0,1-v*v)):1,P=u*u*(t.follow??1),M=nf(s.swing)*P,T=w-M,S=[Math.sin(T)*x*y,v*(v>=0?y:1),Math.cos(T)*x*y],E=[S[0],S[1]+s.lift*P,S[2]-s.trail*P],$=[Math.sin(T)*x,Math.max(0,v),Math.cos(T)*x],A=ml(S),I=l&&P>0?yl(E,c,A):E;a.push(A),r.push({center:I,normal:$,left:I,right:I,t:u})}return r.forEach((h,u)=>{const d=r[Math.max(0,u-1)].center,p=r[Math.min(o,u+1)].center.map((w,v)=>w-d[v]),g=ml(H5(h.normal,p)),m=t.width*Math.sin(Math.PI*h.t)**.6*.5;h.left=h.center.map((w,v)=>w+g[v]*m),h.right=h.center.map((w,v)=>w-g[v]*m),l&&h.t>0&&(t.follow??1)>0&&(h.left=yl(h.left,c,a[u]),h.right=yl(h.right,c,a[u]))}),r}const os=(t,e,n)=>t.map((s,i)=>s+(e[i]-s)*n);function F5(t,e,n){const s=n?1:-1,i=[];let o=[];for(let r=0;r<e.length;r++){const a=e[r],l=s*te(t,a.normal)>=0;if(r>0){const c=e[r-1],h=s*te(t,c.normal),u=s*te(t,a.normal);if(h>=0!==l){const d=h/(h-u),f={center:os(c.center,a.center,d),left:os(c.left,a.left,d),right:os(c.right,a.right,d),normal:os(c.normal,a.normal,d),t:c.t+(a.t-c.t)*d};l?o=[f]:(o.push(f),o.length>=2&&i.push(o),o=[])}}l&&o.push(a)}return o.length>=2&&i.push(o),i}function of(t,e,n,s,i,o,r){const a=(n.locks??[]).map(h=>L5(h,n.volume,s,i)),l=h=>h.reduce((u,d)=>u+te(e,d.center),0)/h.length;a.sort((h,u)=>l(h)-l(u));const c=Math.max(.7,o*.35);for(const h of a)for(const u of F5(e,h,r)){const d=u.map(g=>_t(e,g.left)),f=u.map(g=>_t(e,g.right));if(t.shape([...d,...f.slice().reverse()],n.color,0),t.look==="clean"&&(n.shine??0)>0){const g=u.filter(m=>m.t>=.2&&m.t<=.75);if(g.length>=3){const m=g.map((v,k)=>{const y=.16*Math.sin(Math.PI*k/(g.length-1));return _t(e,os(v.center,v.left,.16+y))}),w=g.map(v=>_t(e,os(v.center,v.left,.16)));t.shape([...m,...w.reverse()],`rgba(255,255,255,${n.shine})`,0)}}const p=u.filter(g=>g.t>.3);p.length>=2&&t.line(p.map(g=>_t(e,g.left)),c)}}const Pt=(t,e,n=0)=>({around:t,up:e,lift:n}),bl=()=>[{width:.66,follow:.22,path:[Pt(-38,.88),Pt(-12,.94,.08),Pt(58,.76,.09),Pt(94,.16,.03)]},{width:.58,follow:.3,path:[Pt(-42,.8),Pt(-24,.7,.12),Pt(18,.57,.09),Pt(64,.3)]},{width:.36,follow:.18,path:[Pt(-58,.76),Pt(-76,.56,.07),Pt(-90,.12,.06),Pt(-102,-.36)]}];function rf(t){return[-100,-130,-160,-190,-220,-250,-280].map((e,n)=>{const s=n%2===0?1:-1,i=t?-2.45-n%3*.12:-1.06-n%3*.09;return{width:t?.88:.92,follow:t?.8+n%3*.12:.38+n%3*.08,path:t?[Pt(e,.7),Pt(e+s*9,.2,.12),Pt(e-s*13,-.5,.2),Pt(e-s*8,-.95,.16),Pt(e-s*3,-1.4,.12),Pt(e+s*18,i+.35,.22),Pt(e+s*12,i,.03)]:[Pt(e,.7),Pt(e+s*7,.15,.2),Pt(e-s*8,-.75,.25),Pt(e+s*5,i)]}})}const N5={softSweep:{volume:.12,shine:.16,part:-38,strands:"part",sweep:-.08,hairline:{front:.64,side:.12,back:-.8},locks:bl()},flowingBob:{volume:.15,shine:.16,length:.96,fall:{taper:.08,wave:.08},part:-38,strands:"part",sweep:-.08,hairline:{front:.64,side:.08,back:-.8},coversEars:!0,locks:[...rf(!1),...bl()]},cascadingWaves:{volume:.16,shine:.16,length:2.38,fall:{taper:.18,wave:.12},part:-38,strands:"part",sweep:-.08,hairline:{front:.64,side:.08,back:-.8},coversEars:!0,locks:[...rf(!0),...bl()]}},rs={swing:0,trail:0,lift:0};function fi(t){if(!t)return rs;const e=t["hair.swing"]??0,n=t["hair.trail"]??0,s=t["hair.lift"]??0;return e===0&&n===0&&s===0?rs:{swing:e,trail:n,lift:s}}const af=t=>t.swing===0&&t.trail===0&&t.lift===0;function lf(t){return t.length>0||t.ties.some(e=>e.kind!=="bun")||(t.locks??[]).some(e=>(e.follow??1)>0)}function wl([t,e,n],s){if(s===0)return[t,e,n];const i=Math.cos(s),o=Math.sin(s);return[t*i-n*o,e,n*i+t*o]}const cf={color:"#6b4630",volume:.1,hairline:{front:.5,side:.12,back:-.82},sweep:0,recede:0,length:0,opening:84,texture:"smooth",textureAmount:0,quiff:0,flat:0,part:null,strands:"none",fill:"solid",ties:[],coversEars:!1},hf=1.75,kl={...N5,bald:{volume:0,hairline:{front:2,side:2,back:2}},buzzCut:{volume:0,fill:"stipple",hairline:{front:.52,side:.1,back:-.8}},crewCut:{volume:.1,texture:"spiky",textureAmount:.07,hairline:{front:.55,side:.1,back:-.8}},short:{volume:.12,texture:"spiky",textureAmount:.1,hairline:{front:.42,side:.1,back:-.82},sweep:.12},sidePart:{volume:.14,part:35,strands:"sweep",sweep:-.22,hairline:{front:.5,side:.08,back:-.82}},sideSwept:{volume:.15,part:45,strands:"sweep",sweep:-.38,hairline:{front:.42,side:.05,back:-.82}},slickBack:{volume:.12,strands:"combed",hairline:{front:.62,side:.15,back:-.8}},quiff:{volume:.12,quiff:.42,strands:"combed",hairline:{front:.6,side:.15,back:-.8}},spiky:{volume:.12,texture:"spiky",textureAmount:.34,hairline:{front:.5,side:.12,back:-.8}},mangaSpikes:{volume:.12,texture:"spiky",textureAmount:.08,hairline:{front:.55,side:.12,back:-.7},spikes:[{around:-100,up:.4,length:.55,width:.24},{around:-65,up:.7,length:.6,width:.25},{around:-25,up:.93,length:.6,width:.24},{around:40,up:.87,length:.7,width:.25},{around:85,up:.55,length:.55,width:.24},{around:160,up:.8,length:.5,width:.24},{around:-160,up:.65,length:.55,width:.24}]},mangaSweep:{volume:.14,texture:"spiky",textureAmount:.1,sweep:-.35,hairline:{front:.5,side:.08,back:-.8},spikes:[{around:-95,up:.45,length:.35,width:.2},{around:-60,up:.8,length:.4,width:.24},{around:75,up:.55,length:.4,width:.23},{around:150,up:.75,length:.35,width:.2}]},undercut:{volume:.16,quiff:.18,part:40,strands:"sweep",sweep:-.15,hairline:{front:.55,side:.42,back:-.3}},curlyCrop:{volume:.14,texture:"curly",textureAmount:.12,hairline:{front:.5,side:.1,back:-.8}},afro:{volume:.5,texture:"curly",textureAmount:.12,hairline:{front:.5,side:-.1,back:-.85},coversEars:!0},wavyCrop:{volume:.16,texture:"wavy",textureAmount:.08,part:30,hairline:{front:.45,side:.05,back:-.82}},shortLocs:{volume:.16,texture:"locs",textureAmount:.1,hairline:{front:.38,side:-.25,back:-.85},strands:"hanging",coversEars:!0},flatTop:{volume:.1,flat:.42,hairline:{front:.5,side:.15,back:-.78}},receding:{volume:.14,recede:.28,strands:"thin",hairline:{front:.74,side:.1,back:-.8}},thinning:{volume:.05,strands:"thin",hairline:{front:.72,side:.05,back:-.78}},pixie:{volume:.16,texture:"spiky",textureAmount:.07,sweep:.3,hairline:{front:.32,side:-.1,back:-.82}},bob:{volume:.2,length:1.05,opening:84,sweep:.2,part:-25,hairline:{front:.34,side:.05,back:-.85},coversEars:!0},longBob:{volume:.18,length:1.35,opening:84,part:0,strands:"part",hairline:{front:.5,side:.05,back:-.85},coversEars:!0},wavyBob:{volume:.22,length:1.2,opening:84,part:18,texture:"wavy",textureAmount:.1,hairline:{front:.45,side:.05,back:-.85},coversEars:!0},shoulderStraight:{volume:.16,length:hf,opening:84,part:0,strands:"part",hairline:{front:.5,side:.05,back:-.85},coversEars:!0},shoulderWaves:{volume:.22,length:hf,opening:84,part:22,texture:"wavy",textureAmount:.12,hairline:{front:.45,side:.05,back:-.85},coversEars:!0},longStraight:{volume:.14,length:2.6,opening:84,part:0,strands:"hanging",hairline:{front:.5,side:.05,back:-.85},coversEars:!0},longWaves:{volume:.2,length:2.5,opening:84,part:20,texture:"wavy",textureAmount:.14,hairline:{front:.45,side:.05,back:-.85},coversEars:!0},longCurls:{volume:.26,length:2.5,opening:84,texture:"curly",textureAmount:.13,hairline:{front:.45,side:.05,back:-.85},coversEars:!0},longLocs:{volume:.2,length:2.6,opening:84,texture:"locs",textureAmount:.12,strands:"hanging",part:0,hairline:{front:.45,side:.05,back:-.85},coversEars:!0},lowPonytail:{volume:.12,part:0,strands:"combed",hairline:{front:.5,side:.1,back:-.82},ties:[{kind:"ponytail",at:"low",length:1.5}]},highPonytail:{volume:.12,part:18,strands:"combed",hairline:{front:.45,side:.1,back:-.78},ties:[{kind:"ponytail",at:"high",length:2}]},ponytail:{volume:.12,sweep:.2,hairline:{front:.42,side:.1,back:-.78},ties:[{kind:"ponytail",at:"high",length:1.8}]},sidePonytail:{volume:.12,part:-20,strands:"combed",hairline:{front:.45,side:.1,back:-.82},ties:[{kind:"ponytail",at:"left",length:1.5}]},topBun:{volume:.12,part:0,strands:"combed",hairline:{front:.5,side:.1,back:-.8},ties:[{kind:"bun",at:"top",size:.32}]},lowBun:{volume:.12,part:0,strands:"combed",hairline:{front:.5,side:.1,back:-.8},ties:[{kind:"bun",at:"low",size:.34}]},singleBraid:{volume:.12,part:0,strands:"combed",hairline:{front:.5,side:.1,back:-.82},ties:[{kind:"braid",at:"low",length:2.2}]},twinBraids:{volume:.12,part:0,strands:"part",hairline:{front:.5,side:.05,back:-.82},ties:[{kind:"braid",at:"left",length:1.9},{kind:"braid",at:"right",length:1.9}],coversEars:!0},braids:{volume:.12,part:0,strands:"part",hairline:{front:.5,side:.05,back:-.82},ties:[{kind:"braid",at:"left",length:1.6},{kind:"braid",at:"right",length:1.6}],coversEars:!0}},xe={black:"#22201f",brown:"#6b4630",chestnut:"#7b4a2b",auburn:"#9a4426",blond:"#d9b55a",ginger:"#c8662f",gray:"#a7a29c",white:"#ecebe7"};function uf(t){const e=typeof t=="string"?{style:t}:t,n=e.style?kl[e.style]:{};if(e.style&&!n)throw new Error(`hair: unknown style '${e.style}'`);const{style:s,hairline:i,...o}=e,r={...cf,...n,...o,hairline:{...cf.hairline,...n.hairline,...i},ties:(o.ties??n.ties??[]).map(a=>({...a})),...o.spikes??n.spikes?{spikes:(o.spikes??n.spikes).map(a=>({...a}))}:{},...o.locks??n.locks?{locks:(o.locks??n.locks).map(R5)}:{},...o.fall??n.fall?{fall:{...o.fall??n.fall}}:{}};if(r.shine!==void 0&&(!Number.isFinite(r.shine)||r.shine<0||r.shine>1))throw new Error("hair: shine must be between 0 and 1");if(r.fall&&(!Number.isFinite(r.fall.taper)||r.fall.taper<0||r.fall.taper>1||!Number.isFinite(r.fall.wave)||r.fall.wave<0))throw new Error("hair: fall needs taper between 0 and 1 and nonnegative wave");return r}const En=t=>t*Math.PI/180,as=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},vl=t=>1-Math.abs(2*(t-Math.floor(t))-1);function gi(t,e){const{front:n,side:s,back:i}=t.hairline,o=(n-i)/2,r=(n+i)/2,a=(r+s)/2,l=(r-s)/2,c=Math.max(0,Math.cos(e));let h=a+o*Math.cos(e)+l*Math.cos(2*e);return h-=t.sweep*Math.sin(e)*c,h+=t.recede*Math.exp(-(((Math.abs(e)-.75)/.32)**2)),(t.texture==="spiky"||t.texture==="curly")&&(h-=t.textureAmount*.6*vl(e*11/(Math.PI*2))*c),h}function df(t,e,n){const s=t.textureAmount;switch(t.texture){case"spiky":return s*(vl(e*11/(Math.PI*2))*vl(n*2.6+.5))**1.2*as(-.3,.4,n);case"curly":return s*Math.sqrt(Math.abs(Math.sin(e*7))*Math.abs(Math.sin(n*Math.PI*2.6)));case"wavy":return s*(.5+.5*Math.sin(e*6+n*6));case"locs":return s*Math.abs(Math.sin(e*10))**.6;default:return 0}}function ff(t,e,n=rs){const s=t.length>0,i=new Map,o=h=>{let u=i.get(h);return u===void 0&&i.set(h,u=gi(t,h)),u},r=En(t.opening),a=h=>t.length+(t.texture==="wavy"||t.texture==="curly"||t.texture==="locs"?.12*Math.sin(h*9):0)+(t.fall?.wave??0)*Math.cos(h*3+.6),l=(h,u,d)=>{if(t.flat<=0||u<.45)return null;const f=(u-.45)/.55,p=Math.sqrt(1-.45*.45)*d*(1-f**5),g=.45+(1+t.flat-.45)*Math.min(1,f*1.8);return[p*Math.sin(h),g*(1+e),p*Math.cos(h)]},c={top:1,bottom:s?-(t.length+.25+Math.abs(t.fall?.wave??0)):-1,inside(h,u){const d=u-o(h);if(!s)return d;const f=Math.min(u+a(h),Bo(h,0)-r);return Math.max(d,f)},position(h,u){if(s&&u<0){const k=t.length<1.5?.14*as(-t.length+.45,-t.length-.1,u):0,y=(t.fall?.taper??0)*as(0,-Math.max(.1,a(h)),u),x=1+e+t.volume*(1-k*2.5)+df(t,h,u)-k-y;return[x*Math.sin(h),u,x*Math.cos(h)]}const d=.4+.6*as(0,.3,u-gi(t,h)),f=1+e+(t.volume+df(t,h,u))*d,p=l(h,u,f);if(p)return p;const[g,m,w]=Se(h,u),v=[g*f,m*f,w*f];if(t.quiff>0){const k=t.quiff*Math.exp(-((h/.7)**2))*as(.15,.85,u);v[1]+=k*.7,v[2]+=k*.45}return v},normal(h,u){return s&&u<0?[Math.sin(h),0,Math.cos(h)]:Se(h,u)}};return s&&!af(n)?W5(c,t,n):c}function W5(t,e,n){const s=o=>o<0?as(-.15,-Math.max(.7,e.length),o):0,i=o=>En(n.swing)*s(o);return{top:t.top,bottom:t.bottom,inside:(o,r)=>t.inside(o+i(r),r),position(o,r){const a=s(r);if(a===0)return t.position(o,r);const l=i(r),[c,h,u]=wl(t.position(o+l,r),l);return[c,h+n.lift*a,u-n.trail*a]},normal:(o,r)=>wl(t.normal(o+i(r),r),i(r))}}const D5=t=>t.texture==="spiky"||t.texture==="curly"||t.texture==="locs"?104:t.texture==="wavy"?80:64;function gf(t,e,n,s){return gl(t,z5(e,s),()=>zo(t,n,D5(e)))}const pf=new WeakMap;let B5=1;function z5(t,e){if(af(e))return t;let n=pf.get(t);return n||pf.set(t,n=B5++),`${n}:${e.swing}:${e.trail}:${e.lift}`}function mf(t){switch(t){case"top":return{point:[0,1.02,-.12],out:[0,1,-.15]};case"high":return{point:[0,.72,-.78],out:[0,.55,-.85]};case"low":return{point:[0,-.2,-1.02],out:[0,-.1,-1]};case"left":return{point:[.82,-.32,-.45],out:[.8,-.2,-.5]};case"right":return{point:[-.82,-.32,-.45],out:[-.8,-.2,-.5]}}}function Ml(t,[e,n,s]){const i=_t(t,[e,n,s]);return{x:i.x-t.center.x,y:i.y-t.center.y}}function q5(t,e,n,s=16){return 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}})}function j5(t,e,n,s,i){const o=t.ry,r=(e.length??1.8)*o,a=Ml(t,wl(s,En(i.swing))),l=Ml(t,[0,i.lift,-i.trail]),c=Math.hypot(a.x,a.y)||1,h=e.at==="high"||e.at==="low"||e.at==="top"?Ml(t,[.95,0,0]):{x:0},u=e.kind==="braid"?.15:.5,d={x:n.x+a.x/c*o*u+h.x*.9+l.x*.5,y:n.y+a.y/c*o*u*.6+l.y*.5},f={x:n.x+a.x/c*o*u*.6+h.x*1.3+l.x,y:n.y+r+l.y};return q5(n,d,f)}const qo=t=>Math.max(1,t*.5),yf=(t,e)=>Math.max(.8,Math.min(t*.4,.1*e.rx));function bf(t,e,n,s,i,o){const{point:r,out:a}=mf(s.at),l=1+n.volume,c=_t(e,[r[0]*l,r[1]*l,r[2]*l]),h=qo(i),u=yf(i,e);if(s.kind==="bun"){const g=s.size??.32,m=_t(e,[r[0]*l+a[0]*g,r[1]*l+a[1]*g,r[2]*l+a[2]*g]);t.ellipse(m.x,m.y,g*e.rx,g*e.ry,e.angle,n.color,h);const w=g*e.rx*.55;t.line(Array.from({length:9},(v,k)=>{const y=-.4+k/8*Math.PI*1.3;return{x:m.x+Math.cos(y)*w,y:m.y+Math.sin(y)*w*.8}}),u);return}const d=j5(e,s,c,a,o),f=(s.size??(s.kind==="braid"?.2:.34))*e.rx*2;if(s.kind==="ponytail")t.shape(zt(d,f,f*.15),n.color,h),t.line(d.slice(3,d.length-3),u);else{const m=d.slice(0,d.length-3);for(let k=0;k<7;k++){const y=m[Math.floor(k/7*(m.length-1))],x=m[Math.floor((k+1)/7*(m.length-1))],P=Math.atan2(x.y-y.y,x.x-y.x),M=Math.hypot(x.x-y.x,x.y-y.y),T=f*(1-k/(7*2.2)),S=(k%2===0?1:-1)*.35,E={x:(y.x+x.x)/2,y:(y.y+x.y)/2};t.ellipse(E.x,E.y,M*.62,T*.5,P+S,n.color,h*.8)}const w=m[m.length-1],v=d[d.length-1];t.shape(zt([w,v],f*.7,f*.2),n.color,h*.8)}const p=d[s.kind==="braid"?d.length-4:2];t.ellipse(p.x,p.y,f*.32,f*.22,e.angle,n.color,h)}function wf(t,e){return te(t,mf(e.at).out)<-.2}function Y5(t){const e=(i,o,r=0,a=14)=>Array.from({length:a+1},(l,c)=>{const h=c/a;return[i[0]+(o[0]-i[0])*h+r*Math.sin(Math.PI*h),i[1]+(o[1]-i[1])*h]}),n=En(t.part??0),s=i=>gi(t,i)+.04;switch(t.strands){case"part":return[e([n,s(n)],[n,.97])];case"sweep":{const i=Math.sign(t.sweep||-1),o=[.9,.72,.55].map((r,a)=>{const l=n+i*(.6+a*.35);return e([n,r],[l,Math.max(s(l)+.05,r-.35)],.05*i)});return[e([n,s(n)],[n,.97]),...o]}case"combed":return[-.75,-.35,.35,.75].map(i=>e([i,s(i)+.02],[i*.3,.86]));case"thin":return[-.5,.05,.6].map(i=>e([i,s(i)+.02],[i*.5,.95],.12));case"hanging":{const i=t.length>0?-t.length+.25:-.4,o=[-2.6,-2,-1.4,1.4,2,2.6,3.05].map(r=>e([r,gi(t,r)<.9?.6:.9],[r,i],0));return t.part!==null&&o.push(e([n,s(n)],[n,.97])),o}default:return[]}}function K5(t,e,n,s,i){if(s.fill==="stipple"||s.hairline.front>1.5)return;const o=i.motion??rs,r=i.lineWidth*.45/n.rx,{far:a}=gf(n,s,ff(s,r,o),o);pl(e,n,()=>{for(const l of s.ties)wf(n,l)&&bf(t,n,s,l,i.lineWidth,o);kf(t,n,s,i.lineWidth,r,!1);for(const l of a)t.shape(l,s.color,qo(i.lineWidth));of(t,n,s,r,o,i.lineWidth,!1)},i.headOutline)}function Sl(t,e,n,s){if(n.hairline.front>1.5)return;const i=s.motion??rs,o=s.lineWidth*.45/e.rx,r=ff(n,o,i),a=yf(s.lineWidth,e);if(n.fill==="stipple"){for(let h=.97;h>-1;h-=.17)for(let u=-Math.PI;u<Math.PI;u+=.27){const d=Math.round(h*100)%2*.13;if(r.inside(u+d,h)<.02)continue;const f=Se(u+d,h);if(te(e,f)<.12)continue;const p=_t(e,f);t.dot(p.x,p.y,a*.4)}return}const{near:l}=gf(e,n,r,i),c=qo(s.lineWidth);kf(t,e,n,s.lineWidth,o,!0);for(const h of l)t.shape(h,n.color,c);of(t,e,n,o,i,s.lineWidth,!0);for(const h of Y5(n)){const u=h.map(([f,p])=>{const[g,m,w]=r.position(f,p);return[g*.985,m*.985,w*.985]}),d=h.map(([f,p])=>r.normal(f,p));for(const f of ef(e,u,d,.12))t.line(f,a)}for(const h of n.ties)wf(e,h)||bf(t,e,n,h,s.lineWidth,i)}function kf(t,e,n,s,i,o){for(const r of n.spikes??[]){const a=Se(En(r.around),Math.max(-1,Math.min(1,r.up)));if(te(e,a)>=0!==o)continue;const l=[Math.cos(En(r.around)),0,-Math.sin(En(r.around))],c=[a[1]*l[2],a[2]*l[0]-a[0]*l[2],-a[1]*l[0]],h=1+n.volume+i,u=Math.max(0,r.width),d=Math.max(0,r.length),f=[_t(e,a.map(p=>p*(h+d)))];for(let p=0;p<8;p++){const g=p*Math.PI/4,m=a.map((w,v)=>w*h+u*(l[v]*Math.cos(g)+c[v]*Math.sin(g)));f.push(_t(e,m))}t.shape(fl(f),n.color,qo(s))}}const vf=.35,xl=t=>({centre:[t*.98,-.02,-.08],out:[t,0,-.12]});function Mf(t,e,n,s,i){const{centre:o,out:r}=xl(n),a=te(e,r),l=Math.max(1,s.lineWidth*.55),c=s.skin==="none"?null:s.skin,h=e.ry*.27;if(!i){const m=_t(e,[o[0]*1.06,o[1],o[2]]);t.ellipse(m.x,m.y,e.rx*.17,h,e.angle,c,l);return}const u=_t(e,o),d=e.rx*(.12+.08*a);t.ellipse(u.x,u.y,d,h,e.angle,c,l);const f=Math.cos(e.angle),p=Math.sin(e.angle),g=Array.from({length:9},(m,w)=>{const v=-Math.PI*.55+w/8*Math.PI*1.1,k=Math.cos(v)*d*.45*-n,y=Math.sin(v)*h*.55;return{x:u.x+k*f-y*p,y:u.y+k*p+y*f}});t.line(g,Math.max(.8,l*.7))}function X5(t,e,n,s){pl(e,n,()=>{for(const i of[1,-1])te(n,xl(i).out)<vf&&Mf(t,n,i,s,!1)},s.headOutline)}function G5(t,e,n){for(const s of[1,-1])te(e,xl(s).out)>=vf&&Mf(t,e,s,n,!0)}const Tl={cleanShaven:{moustache:"none",beard:"none"},stubble:{moustache:"none",beard:"stubble"},pencilMoustache:{moustache:"pencil",beard:"none"},shortMoustache:{moustache:"short",beard:"none"},chevron:{moustache:"chevron",beard:"none"},handlebar:{moustache:"handlebar",beard:"none"},walrus:{moustache:"walrus",beard:"none"},goatee:{moustache:"none",beard:"goatee"},vanDyke:{moustache:"chevron",beard:"goatee"},circleBeard:{moustache:"short",beard:"circle"},shortBoxed:{moustache:"short",beard:"boxed"},fullBeard:{moustache:"chevron",beard:"full"},longBeard:{moustache:"walrus",beard:"long"},roundedBeard:{moustache:"chevron",beard:"rounded"},pointedBeard:{moustache:"chevron",beard:"pointed"},chinStrap:{moustache:"none",beard:"chinStrap"},soulPatch:{moustache:"none",beard:"soulPatch"},sideburns:{moustache:"none",beard:"sideburns"},muttonChops:{moustache:"none",beard:"muttonChops"},moustacheStubble:{moustache:"short",beard:"stubble"}};function Sf(t,e){const n=typeof t=="string"?{style:t}:t,s=n.style?Tl[n.style]:void 0;if(n.style&&!s)throw new Error(`facialHair: unknown style '${n.style}'`);return{color:n.color??e??"#6b4630",moustache:n.moustache??s?.moustache??"none",beard:n.beard??s?.beard??"none"}}const Je=t=>t*Math.PI/180,jo=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},xf={goatee:{top:[-.55,-.55],reach:22,band:0,length:.22,shape:"point",volume:.06,aroundMouth:!1},circle:{top:[-.24,-.3],reach:42,band:0,length:.08,shape:"round",volume:.06,aroundMouth:!0},boxed:{top:[-.38,.02],reach:100,band:0,length:.18,shape:"square",volume:.08,aroundMouth:!0},full:{top:[-.36,.05],reach:100,band:0,length:.32,shape:"round",volume:.12,aroundMouth:!0},rounded:{top:[-.36,.05],reach:100,band:0,length:.55,shape:"round",volume:.14,aroundMouth:!0},pointed:{top:[-.36,.05],reach:100,band:0,length:.8,shape:"point",volume:.12,aroundMouth:!0},long:{top:[-.36,.05],reach:100,band:0,length:1.4,shape:"round",volume:.14,aroundMouth:!0},chinStrap:{top:[-.68,.05],reach:100,band:.18,length:0,shape:"round",volume:.04,aroundMouth:!1},sideburns:{top:[.08,.08],reach:100,band:.42,length:0,shape:"round",volume:.05,aroundMouth:!1},muttonChops:{top:[.08,.08],reach:100,band:.75,length:0,shape:"round",volume:.08,aroundMouth:!1}},U5=(t,e)=>{const n=jo(Je(48),Je(100),Bo(e,0));return t.top[0]+(t.top[1]-t.top[0])*n},V5=t=>t==="sideburns"||t==="muttonChops";function El(t,e){const n=xf[t];if(!n)return null;const s=Je(n.reach),i=o=>{const r=Bo(o,0);return n.shape==="point"?Math.exp(-((r/.42)**2)):n.shape==="square"?1-jo(Je(45),Je(85),r):Math.cos(Math.min(r,Math.PI/2))**.7};return{top:Math.max(n.top[0],n.top[1])+.05,bottom:-1,inside(o,r){const a=Bo(o,0),l=U5(n,o);let c=Math.min(l-r,s-a);if(n.band>0&&(c=Math.min(c,r-(l-n.band))),V5(t)){const h=t==="muttonChops"?Je(70)-Je(22)*jo(.08,-.6,r):Je(72);c=Math.min(c,a-h)}return c},position(o,r){const[a,l,c]=Se(o,r),h=1+e+n.volume,u=n.length*i(o)*jo(-.45,-1,r);return[a*h,l*h-u,c*h+u*.25]},normal:(o,r)=>Se(o,r)}}function J5(t){const n=s=>s.map(([i,o])=>({x:i,y:-.24+o}));switch(t){case"short":return n([[-.17,-.02],[-.1,.04],[0,.03],[.1,.04],[.17,-.02],[.08,-.05],[0,-.03],[-.08,-.05]]);case"chevron":return n([[-.28,-.1],[-.16,.05],[0,.07],[.16,.05],[.28,-.1],[.12,-.08],[0,-.06],[-.12,-.08]]);case"walrus":return n([[-.38,-.2],[-.3,.02],[-.12,.09],[0,.07],[.12,.09],[.3,.02],[.38,-.2],[.2,-.13],[0,-.11],[-.2,-.13]]);case"handlebar":return n([[-.24,-.03],[-.12,.04],[0,.03],[.12,.04],[.24,-.03],[.1,-.05],[0,-.03],[-.1,-.05]]);default:return null}}const pi=t=>Math.max(1,t*.45);function Z5(t,e,n,s){for(let i=.1;i>-1;i-=.13)for(let o=-Math.PI/1.7;o<Math.PI/1.7;o+=.2){const r=Math.round(i*100)%2*.1;if(n.inside(o+r,i)<.02)continue;const a=Se(o+r,i);if(te(e,a)<.15)continue;const l=_t(e,a);t.dot(l.x,l.y,s)}}function Q5(t,e,n,s,i){const o=s.beard==="stubble"?null:El(s.beard,i.lineWidth*.45/n.rx);if(!o)return;const{far:r}=gl(n,s,()=>zo(n,o));pl(e,n,()=>{for(const a of r)t.shape(a,s.color,pi(i.lineWidth))},i.headOutline)}function tv(t,e,n,s,i){if(n.beard==="none")return;const o=s.lineWidth*.45/e.rx;if(n.beard==="stubble"){Z5(t,e,El("full",o),Math.max(.5,s.lineWidth*.09));return}if(n.beard==="soulPatch"){const l=[{x:-.05,y:-.55},{x:.05,y:-.55},{x:0,y:-.68}],{points:c,facing:h}=xt(e,l,{x:0,y:-.6},s.face?.projection);h>-.05&&t.shape(c,n.color,pi(s.lineWidth)*.7);return}const r=El(n.beard,o);if(!r)return;const{near:a}=gl(e,n,()=>zo(e,r));for(const l of a)t.shape(l,n.color,pi(s.lineWidth));if(xf[n.beard]?.aroundMouth){const l=.27*Math.max(.3,i),c=Array.from({length:20},(d,f)=>{const p=Math.PI*2*f/20;return{x:Math.cos(p)*l,y:-.42+Math.sin(p)*.13}}),{points:h,facing:u}=xt(e,c,{x:0,y:-.42},s.face?.projection);u>-.05&&t.shape(h,s.skin==="none"?"#ffffff":s.skin,0)}}function ev(t,e,n,s){if(n.moustache==="none")return;const i={x:0,y:-.24};if(n.moustache==="pencil"){const l=[-.2,-.1,0,.1,.2].map(u=>({x:u,y:-.25+.03*Math.cos(u/.2*Math.PI)})),{points:c,facing:h}=xt(e,l,i,s.face?.projection);h>-.05&&t.line(c,Math.max(1,s.lineWidth*.32));return}const o=J5(n.moustache);if(!o)return;const{points:r,facing:a}=xt(e,o,i,s.face?.projection);if(!(a<=-.05)&&(t.shape(r,n.color,pi(s.lineWidth)*.8),n.moustache==="handlebar"))for(const l of[1,-1]){const c=Array.from({length:10},(h,u)=>{const d=-Math.PI/2+u/9*Math.PI*1.4;return{x:l*(.27+.05*Math.cos(d)),y:-.21+.05*(1+Math.sin(d))}});c.unshift({x:l*.22,y:-.27}),t.line(xt(e,c,i,s.face?.projection).points,pi(s.lineWidth)*.8)}}const Al={round:!0,square:!0,sunglasses:!0};function Tf(t){const n=(typeof t=="string"?{style:t}:t).style??"round";if(!(n in Al))throw new Error(`glasses: unknown style '${n}'`);return{style:n}}const Ef=.34,Te=.12,nv=.05;function sv(t,e){return Array.from({length:28},(s,i)=>{const o=Math.PI*2*i/28;if(t==="round")return{x:e+Math.cos(o)*.2,y:Te+Math.sin(o)*.19};const r=Math.cos(o),a=Math.sin(o),l=t==="sunglasses"?.22:.21,c=t==="sunglasses"?.17:.16;return{x:e+Math.sign(r)*Math.abs(r)**.45*l,y:Te-.01+Math.sign(a)*Math.abs(a)**.45*c}})}function iv(t,e,n,s){const i=Math.max(1,Math.min(s.lineWidth*.5,.11*e.rx)),o=[];for(const r of[1,-1]){const a=Ef*r,{points:l,facing:c}=xt(e,sv(n.style,a),{x:a,y:Te},s.face?.projection);if(c<nv)continue;o.push(r),t.shape(l,n.style==="sunglasses"?"#1f2328":null,i);const h=[r*.97,Te+.02,-.1];if(te(e,[r,0,0])>.15){const u=xt(e,[{x:a+r*.21,y:Te+.02}],{x:a,y:Te},s.face?.projection).points[0];t.line([u,_t(e,h)],i*.9)}}if(o.length===2){const r=[{x:Ef-.2,y:Te+.02},{x:0,y:Te+.07},{x:-.14,y:Te+.02}];t.line(xt(e,r,{x:0,y:Te},s.face?.projection).points,i)}}const Yo={cap:{color:"#d64535",brim:[.36,.16],height:1,peak:.7,detail:"seams"},beanie:{color:"#3a6ea5",brim:[.3,.12],height:1.08,detail:"fold"},hardHat:{color:"#f2c230",brim:[.34,.22],height:1.12,ring:.16,detail:"ridge"},sunHat:{color:"#e3c98f",brim:[.36,.3],height:1.02,ring:.62,detail:"band"},bowler:{color:"#2f2b2a",brim:[.36,.28],height:1.15,ring:.2,detail:"band"}};function Af(t){const e=typeof t=="string"?{style:t}:t,n=e.style??"cap",s=Yo[n];if(!s)throw new Error(`hat: unknown style '${n}'`);return{style:n,color:e.color??s.color}}const An=(t,e)=>t.brim[1]+(t.brim[0]-t.brim[1])*(1+Math.cos(e))/2;function ov(t,e){return{top:1,bottom:Math.min(...t.brim)-.05,inside:(n,s)=>s-An(t,n),position(n,s){const[i,o,r]=Se(n,s),a=An(t,n),l=s>a?(o-a)*(t.height-1):0;return[i*e,o*e+l,r*e]},normal:(n,s)=>Se(n,s)}}function rv(t,e,n){const i=(o,r,a)=>{const l=An(e,o)*n-a;return[Math.sin(o)*r,l,Math.cos(o)*r]};if(e.peak){const o=[],r=[];for(let a=0;a<=24;a++){const l=(-80+160*a/24)*(Math.PI/180),c=e.peak*Math.cos(l)**.6;o.push(_t(t,[Math.sin(l)*(n+c*.25),An(e,l)*n-.07*Math.cos(l),Math.cos(l)*(n+c)])),r.push(_t(t,i(l,n,0)))}return[...o,...r.reverse()]}return e.ring?Array.from({length:48},(o,r)=>_t(t,i(Math.PI*2*r/48,n+e.ring,.07))):null}function av(t){const e=s=>Array.from({length:13},(i,o)=>[s,An(t,s)+(.97-An(t,s))*o/12]),n=s=>Array.from({length:49},(i,o)=>{const r=-Math.PI+Math.PI*2*o/48;return[r,An(t,r)+s]});switch(t.detail){case"seams":return[e(.55),e(-.55)];case"fold":return[n(.2)];case"ridge":return[e(0),e(Math.PI)];case"band":return[n(.12)]}}function $f(t,e,n,s){const i=Yo[n.style],r=1+s.lineWidth*.45/e.rx+Math.max(.05,Math.min(.3,s.hairVolume)+.04),a=Math.max(1,s.lineWidth*.5),l=rv(e,i,r);l&&t.shape(l,n.color,a);const c=ov(i,r),{near:h,far:u}=zo(e,c);for(const f of[...u,...h])t.shape(f,n.color,a);const d=Math.max(.8,a*.7);for(const f of av(i)){const p=f.map(([m,w])=>{const[v,k,y]=c.position(m,w);return[v*.99,k*.99,y*.99]}),g=f.map(([m,w])=>Se(m,w));for(const m of ef(e,p,g,.1))t.line(m,d)}if(i.detail==="seams"){const f=_t(e,[0,r*1.01,0]);t.dot(f.x,f.y,a*.9)}}function Pf(t){const e=t.hair?uf(t.hair):null;return{hair:e,facialHair:t.facialHair?Sf(t.facialHair,e?.color):null,glasses:t.glasses?Tf(t.glasses):null,hat:t.hat?Af(t.hat):null,ears:t.ears??!1}}const If=t=>!t.hair&&!t.facialHair&&!t.glasses&&!t.hat&&!t.ears,Of=t=>t.axes[2][2]<-.3,_f=t=>t.ears&&!t.hair?.coversEars;function Cf(t,e,n,s,i,o){if(If(n))return;const r={...o,headOutline:o.face&&(o.face.shape==="angular"||o.face.projection==="volume")?Gd(s,o.face):void 0};n.hair&&K5(e,t,s,n.hair,{...r,motion:fi(i)}),n.facialHair&&Q5(e,t,s,n.facialHair,r),_f(n)&&X5(e,t,s,r)}function lv(t,e,n,s,i,o,r){if(If(n)){r();return}const a=Of(s);_f(n)&&G5(e,s,o),n.hair&&!a&&!o.faceUnderHair&&Sl(e,s,n.hair,{...o,motion:fi(i)}),n.facialHair&&tv(e,s,n.facialHair,o,i.mouthWidth??1),r(),n.hair&&!a&&o.faceUnderHair&&Sl(e,s,n.hair,{...o,motion:fi(i)}),n.facialHair&&ev(e,s,n.facialHair,o),n.glasses&&iv(e,s,n.glasses,o),n.hat&&!a&&$f(e,s,n.hat,{lineWidth:o.lineWidth,hairVolume:n.hair?.volume??0})}function Hf(t,e,n,s,i,o){Of(s)&&(n.hair&&Sl(e,s,n.hair,{...o,motion:fi(i)}),n.hat&&$f(e,s,n.hat,{lineWidth:o.lineWidth,hairVolume:n.hair?.volume??0}))}const Rf=40,cv=.215+.205,le=(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},gt=(t,e)=>t[e]??lt[e]??0;function Ko(t,e,n=lt,s=1){const i=ii(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={...lt,...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"]=gt(n,"leg.left.ankle")-(i.tiptoe??0),d["leg.right.ankle"]=gt(n,"leg.right.ankle")-(i.tiptoe??0);for(const[f,p]of[["left",-1],["right",1]])gt(n,`arm.${f}.spread`)>Rf||gt(n,`arm.${f}.swing`)>Rf||(d[`arm.${f}.swing`]=h+p*i.arm*r,d[`arm.${f}.elbow`]=gt(n,`arm.${f}.elbow`)+u+i.elbow*Math.max(0,p*r));return d.lean=gt(n,"lean")+i.lean*s,d.bend=gt(n,"bend")+(i.bend??0),d["head.nod"]=gt(n,"head.nod")-i.lean*.5*s+(i.headTilt??0),d.side=gt(n,"side")+(i.sway??0)*Math.sin(o),d.lift=gt(n,"lift")+(i.bounce??0)*s*l,d.stretch=gt(n,"stretch")*(1+(i.squash??0)*(l-.5)),d}function Xo(t,e,n=1,s=1){const i=ii(t);return 4*cv*s*e*Math.sin(i.swing*n*Math.PI/180)}const ls=t=>ol[t],Go={take:t=>[{after:140,pose:{stretch:.8,bend:10,lean:gt(t,"lean")-4,...le("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,...le("arm",{spread:150,bend:35,swing:0,elbow:0}),...le("leg",{swing:25,knee:60}),...ls("shocked")},easing:"ease-out-cubic"},{after:720,pose:{lift:.25,stretch:1.25,bend:-10,...le("arm",{spread:140})},easing:"ease-in-out"},{after:900,pose:{lift:0,stretch:.74,bend:12,...le("arm",{spread:70,bend:0}),...le("leg",{swing:30,knee:60})},easing:"ease-in-quad"},{after:1060,pose:{stretch:1.06,bend:-3,...le("arm",{spread:60}),"leg.left.swing":gt(t,"leg.left.swing"),"leg.right.swing":gt(t,"leg.right.swing"),"leg.left.knee":gt(t,"leg.left.knee"),"leg.right.knee":gt(t,"leg.right.knee")},easing:"ease-out"},{after:1260,pose:{stretch:gt(t,"stretch"),bend:gt(t,"bend"),...ls("surprised"),...le("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":gt(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":gt(t,"head.nod")-10,bend:gt(t,"bend")-10,lift:.05,stretch:1.18,...ls("shocked"),lookX:1,lookY:0},easing:"ease-out-cubic"},{after:1360,pose:{lift:0,stretch:.88,"head.nod":gt(t,"head.nod")-4,bend:gt(t,"bend")+4},easing:"ease-in-quad"},{after:1560,pose:{stretch:gt(t,"stretch"),"head.nod":gt(t,"head.nod"),bend:gt(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,...ls("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,...le("arm",{spread:75}),...le("leg",{swing:25,knee:50})},easing:"ease-in-quad"},{after:300,pose:{stretch:1.05,bend:-4,"arm.left.spread":gt(t,"arm.left.spread"),"arm.right.spread":gt(t,"arm.right.spread")},easing:"ease-out"},{after:460,pose:{lift:0,stretch:gt(t,"stretch"),bend:gt(t,"bend"),...le("leg",{swing:0,knee:0})},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...ls("scared"),...le("arm",{swing:40,elbow:110,spread:14}),stretch:.94,bend:gt(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:gt(t,"side")+2.5*s,"head.tilt":gt(t,"head.tilt")-2*s}})}return e.push({after:755,pose:{side:gt(t,"side"),"head.tilt":gt(t,"head.tilt"),bend:gt(t,"bend")}}),e},deflate:t=>[{after:260,pose:{stretch:1.04,"head.nod":gt(t,"head.nod")-4,"brow.left":.3,"brow.right":.3},easing:"ease-in-out"},{after:900,pose:{...ls("sad"),bend:18,stretch:.92,lean:gt(t,"lean")+5,"head.nod":14,...le("arm",{spread:6,swing:0,elbow:4,bend:0})},easing:"ease-in-out"}]};function Lf(t,e){const n=kt(e.from??{}),s=e.speed??1;let i=n;return[{time:e.at,pose:n},...Go[t](n).map(o=>(i={...i,...o.pose},{time:e.at+o.after*s,pose:i,act:!1,...o.easing?{easing:o.easing}:{}}))]}function Ff(t,e=lt){const n=t*Math.PI*2,s=Math.sin(n);return{...e,lean:(e.lean??0)+14,bend:(e.bend??0)+8,side:5*s,"head.nod":22,"arm.right.swing":38+22*s,"arm.right.spread":6,"arm.right.elbow":20+10*Math.max(0,-s),"arm.right.bend":-10,"arm.left.swing":52+22*s,"arm.left.spread":14,"arm.left.elbow":35+10*Math.max(0,s),"arm.left.bend":-20,"leg.left.swing":10,"leg.right.swing":-10,"leg.left.knee":8,"leg.right.knee":4,"leg.left.spread":8,"leg.right.spread":8}}function Nf(t,e=lt){const n=t*Math.PI*2,s=Math.sin(n),i=Math.cos(n);return{...e,lean:(e.lean??0)+4,side:2*s,"head.nod":6,"arm.right.swing":62,"arm.right.spread":18+16*s,"arm.right.elbow":48-18*Math.abs(s),"arm.right.bend":-30+8*i,"arm.left.swing":12,"arm.left.spread":14,"arm.left.elbow":12,"leg.left.spread":6,"leg.right.spread":6}}const $l={sweeping:Ff,brushing:Nf};function hv(t,e,n=lt){const s=$l[t];if(!s)throw new Error(`humanCyclePose: ${ft("cycle",t,Object.keys($l))}`);return s(e,n)}function Wf(t){const e=t.top??!0,n=t.length??.32,s=t.color??"#638c39",i=t.accent??"#87ae4e";if(typeof e!="boolean")throw new Error("leafOutfit: top must be a boolean");if(!Number.isFinite(n)||n<.2||n>.45)throw new Error("leafOutfit: length must be 0.2..0.45");if(typeof s!="string"||typeof i!="string")throw new Error("leafOutfit: color and accent must be strings");return{top:e,length:n,color:s,accent:i}}function Df(t,e){const n=t.flatMap(i=>Array.from({length:8},(o,r)=>({x:i.x+Math.cos(r*Math.PI/4)*e,y:i.y+Math.sin(r*Math.PI/4)*e})));let s=fl(n);for(let i=0;i<2;i++)s=s.flatMap((o,r)=>{const a=s[(r+1)%s.length];return[{x:o.x*.75+a.x*.25,y:o.y*.75+a.y*.25},{x:o.x*.25+a.x*.75,y:o.y*.25+a.y*.75}]});return s}const Bf=t=>t.flatMap(e=>[e.left,e.right]);function Pl(t,e={}){const{top:n,length:s}=Wf(e),i=t.bodyContours;if(!i?.spine)throw new Error("leafOutfit requires organic body contours");const o=i.spine.samples.filter(a=>a.at<=.3),r=["left","right"].flatMap(a=>i[`leg.${a}`]?.samples.filter(l=>l.at<=s)??[]);return{...n?{top:Df(Bf(i.spine.samples.filter(a=>a.at>=.52&&a.at<=.91)),t.height*.01)}:{},skirt:Df(Bf([...o,...r]),t.height*.012)}}function uv(t,e){t.beginPath(),t.moveTo(e[0].x,e[0].y);for(const n of e.slice(1))t.lineTo(n.x,n.y);t.closePath()}function dv(t,e,n){const s=e.x-t.x,i=e.y-t.y,o=Math.hypot(s,i)||1,r=-i/o,a=s/o,l=[];for(const c of[1,-1])for(let h=0;h<=16;h++){const u=c===1?h/16:1-h/16,f=3*(1-u)*u*n*c;l.push({x:t.x+s*u+r*f,y:t.y+i*u+a*f})}return l}function zf(t,e,n,s,i,o){const r=e.lineWidth*.7;if(n.shape(s,i,r),n.look==="silhouette")return;t.save(),uv(t,s),t.clip();const a=Math.min(...s.map(f=>f.x)),l=Math.max(...s.map(f=>f.x)),c=Math.min(...s.map(f=>f.y)),h=Math.max(...s.map(f=>f.y)),u=l-a,d=h-c;for(let f=0;f<2;f++)for(let p=0;p<5;p++){const g={x:a+u*(p/4+(f?.07:-.04)),y:c+d*(f?.38:-.1)},m={x:g.x+u*.09,y:g.y+d*.78};n.shape(dv(g,m,u*.13),(p+f)%2?i:o,r*.6),n.line([g,{x:g.x*.45+m.x*.55,y:g.y*.45+m.y*.55},m],r*.45);for(const w of[.32,.52,.7]){const v={x:g.x+(m.x-g.x)*w,y:g.y+(m.y-g.y)*w};n.line([{x:v.x-u*.045,y:v.y-d*.065},v,{x:v.x+u*.045,y:v.y-d*.05}],r*.3)}}t.restore()}function qf(t={}){const e=Wf(t),{color:n,accent:s}=e,i=o=>(r,a,l)=>{const c=Pl(a,e);o==="spine"&&c.top&&zf(r,a,l,c.top,n,s);const h=["spine","leg.left","leg.right"].reduce((u,d)=>a.parts[u].order>a.parts[d].order?u:d);o===h&&zf(r,a,l,c.skirt,n,s)};return{parts:{spine:{over:i("spine")},"leg.left":{over:i("leg.left")},"leg.right":{over:i("leg.right")}}}}const fv={apron:"#d8b48a",labCoat:"#f4f6f8",hoodie:"#6b7280",cardigan:"#6b8e4e",overalls:"",sari:"#16a34a"},Il=(t,e,n)=>t.slice(Math.floor((t.length-1)*e),Math.ceil((t.length-1)*n)+1),pt=(t,e,n)=>({x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n});function gv(t){return t.parts["leg.left"].order>t.parts["leg.right"].order?"left":"right"}const jf=t=>Math.max(t.parts["leg.left"].order,t.parts["leg.right"].order)>t.parts.spine.order,ee=t=>t.bodyForward?.[2]??Math.cos(t.turn*Math.PI/2),Oe=t=>t.bodyForward?.[0]??Math.sin(t.turn*Math.PI/2);function Yf(t,e,n){t.save(),t.beginPath(),t.moveTo(e[0].x,e[0].y);for(const s of e.slice(1))t.lineTo(s.x,s.y);t.closePath(),t.clip(),n(),t.restore()}function Kf(t,e,n=0){const s=e*(t.length-1),i=Math.min(t.length-2,Math.floor(s)),o=t[i],r=t[i+1],a=pt(o,r,s-i),l=Math.hypot(r.x-o.x,r.y-o.y)||1;return{x:a.x+(r.y-o.y)/l*n,y:a.y-(r.x-o.x)/l*n}}function Xf(t={}){if(t={...t},t.top!==void 0&&!["tshirt","shirt","blouse","dress"].includes(t.top))throw new Error(`basicOutfit: unknown top '${t.top}'`);if(t.trouserStyle!==void 0&&!["plain","jeans","cargo"].includes(t.trouserStyle))throw new Error(`basicOutfit: unknown trouser style '${t.trouserStyle}'`);const e=t.top,n=t.trouserStyle??"plain",s=t.collar??e==="shirt",i=t.shirt??"#e2493b",o=e==="dress"?i:t.trousers??"#24476b",r=t.sleeves??"short",a=e==="dress"?"skirt":t.bottom??"trousers",l=t.over==="labCoat",c=t.over==="hoodie",h=t.over==="cardigan",u=t.over==="overalls",d=t.over==="sari",f=t.overColor??(t.over&&t.over!=="overalls"?fv[t.over]:o),p=t.shoes==="boots",g=t.shoeColor??"#3b2a1e",m=O=>O.lineWidth*.45,w=(O,R,z,K)=>{const N=R.parts[`leg.${K}`].points;if(a==="skirt"&&!u)return;const q=a==="shorts"&&!u,Y=R.bodyContours?.[`leg.${K}`],J=Y?dl(Y,0,q?.5:1,R.height*.006):zt(q?Il(N,0,.5):N,R.height*(q?.085:.08),R.height*(q?.07:.05));z.shape(J,o,m(R)),!(n==="plain"||ee(R)<.15)&&Yf(O,J,()=>{const X=(tt,nt=0)=>Kf(N,tt,nt*R.height);if(n==="jeans")z.line([X(.07,-.018),X(.17,-.02),X(.23,0),X(.17,.02),X(.07,.018)],m(R)*.65),z.line([X(.27,.013),...[.4,.55,.7,.85,.96].filter(tt=>!q||tt<.5).map(tt=>X(tt,.013))],m(R)*.5);else{const tt=[X(.25,-.024),X(.25,.024),X(.43,.024),X(.43,-.024)];z.shape(tt,o,m(R)*.65),z.line([X(.28,-.024),X(.32,0),X(.28,.024)],m(R)*.65);const nt=X(.32);z.dot(nt.x,nt.y,m(R)*.8)}})},v=(O,R,z)=>{const K=O.parts[`leg.${z}`].points,N=Il(K,.7,1);if(N.length<2)return;R.shape(zt(N,O.height*.075,O.height*.07),g,m(O));const q=N[0],Y=N[1],J=Y.x-q.x,X=Y.y-q.y,tt=Math.hypot(J,X)||1,nt=O.height*.04;R.line([{x:q.x-X/tt*nt,y:q.y+J/tt*nt},{x:q.x+X/tt*nt,y:q.y-J/tt*nt}],m(O)*.9)},k=O=>{const R=O.chains.spine,z=R[0],K=R[R.length-1],N={x:z.x-(K.x-z.x)*.25,y:z.y-(K.y-z.y)*.25};return{hip:z,top:K,below:N,line:[N,...O.parts.spine.points]}},y=O=>{if(O.bodyContours?.spine)return dl(O.bodyContours.spine,0,.97,O.height*(c?.014:.006));const R=c?1.14:1,z=Math.hypot(O.points["hip.left"].x-O.points["hip.right"].x,O.points["hip.left"].y-O.points["hip.right"].y),K=Math.max(O.height*.15*R,z+Math.max(O.height*.08,O.lineWidth*1.45)+m(O));return zt(k(O).line,K,O.height*.14*R)},x=(O,R)=>{const z=[y(R)],{top:K,hip:N}=k(R);h&&z.push(zt([K,pt(K,N,.5),pt(K,N,1.08)],R.height*.155,R.height*.15)),l&&z.push(zt([K,pt(K,N,.5),N],R.height*.14,R.height*.15));const q=Object.values(R.points),Y=Math.min(...q.map(nt=>nt.x))-R.height,J=Math.min(...q.map(nt=>nt.y))-R.height,X=Math.max(...q.map(nt=>nt.x))+R.height,tt=Math.max(...q.map(nt=>nt.y))+R.height;for(const nt of z){O.beginPath(),O.rect(Y,J,X-Y,tt-J),O.moveTo(nt[0].x,nt[0].y);for(const L of nt.slice(1))O.lineTo(L.x,L.y);O.closePath(),O.clip("evenodd")}},P=(O,R)=>{const z=c?f:i;R.shape(y(O),z,m(O))},M=(O,R,z)=>{const K=ee(R);if(!e||K<.2||c)return;const{top:N,hip:q}=k(R),Y=Oe(R)*R.height*.025,J=[N,q],X=(tt,nt=0)=>Kf(J,tt,Y+nt*R.height*K);Yf(O,y(R),()=>{if(e==="shirt"){z.line([X(.12),X(.92)],m(R)*.65);for(const tt of[.24,.4,.56,.72,.88]){const nt=X(tt,.008);z.dot(nt.x,nt.y,m(R)*.9)}}else if(e==="blouse"){z.line([X(.025,-.04),X(.24),X(.025,.04)],m(R)*.75);const tt=X(.31);z.dot(tt.x,tt.y,m(R))}else e==="dress"?z.line([X(.04,-.035),X(.17,-.028),X(.17,.028),X(.04,.035)],m(R)*.75):z.line([X(.025,-.035),X(.1,-.02),X(.12),X(.1,.02),X(.025,.035)],m(R)*.65)})},T=(O,R)=>{const z=ee(O),{top:K,hip:N}=k(O),q=O.height*.07,Y={x:(K.x-N.x)*.16,y:(K.y-N.y)*.16};if(z>=0){R.shape([{x:K.x-q,y:K.y+Y.y*.25},{x:K.x-q*.8+Y.x,y:K.y+Y.y},{x:K.x+Y.x*1.2,y:K.y+Y.y*1.35},{x:K.x+q*.8+Y.x,y:K.y+Y.y},{x:K.x+q,y:K.y+Y.y*.25}],f,m(O));return}const J=pt(K,N,.42);R.shape([{x:K.x-q*.9,y:K.y},{x:K.x+q*.9,y:K.y},{x:J.x+q*.7,y:J.y},{x:J.x,y:J.y+O.height*.02},{x:J.x-q*.7,y:J.y}],f,m(O))},S=(O,R)=>{const z=ee(O);if(z<.2)return;const{top:K,hip:N}=k(O),q=Oe(O)*O.height*.03,Y=O.height*.06*z,J=pt(K,N,.62),X=pt(K,N,.9);R.line([{x:J.x+q-Y,y:J.y},{x:X.x+q-Y*1.1,y:X.y}],m(O)*.7),R.line([{x:J.x+q+Y,y:J.y},{x:X.x+q+Y*1.1,y:X.y}],m(O)*.7);const tt=pt(K,N,.1);for(const nt of[-1,1])R.line([{x:tt.x+q+nt*Y*.2,y:tt.y},{x:tt.x+q+nt*Y*.35,y:tt.y+O.height*.07}],m(O)*.6)},E=(O,R)=>{const{top:z,hip:K}=k(O),N=ee(O);if(R.shape(zt([z,pt(z,K,.5),pt(z,K,1.08)],O.height*.155,O.height*.15),f,m(O)),N<.2)return;const q=Oe(O)*O.height*.03,Y=O.height*.02*N,J=pt(z,K,.12),X=pt(z,K,1.05);R.shape([{x:J.x+q-Y,y:J.y},{x:J.x+q+Y,y:J.y},{x:X.x+q+Y*1.3,y:X.y},{x:X.x+q-Y*1.3,y:X.y}],i,m(O)*.7);for(const tt of[.35,.55,.75]){const nt=pt(z,K,tt);R.dot(nt.x+q+Y*1.6,nt.y,m(O)*1.2)}},$=(O,R)=>{const z=ee(O),{top:K,hip:N}=k(O),q=Oe(O)*O.height*.04,Y=pt(N,K,.12),J=pt(N,K,.74);if(z<.15){if(z<-.3){const L=O.points["shoulder.left"],U=O.points["shoulder.right"];R.line([L,{x:Y.x+O.height*.03,y:Y.y}],m(O)*.8),R.line([U,{x:Y.x-O.height*.03,y:Y.y}],m(O)*.8)}return}const X=O.height*.07*z;R.shape([{x:J.x+q-X*.75,y:J.y},{x:J.x+q+X*.75,y:J.y},{x:Y.x+q+X*1.1,y:Y.y},{x:Y.x+q-X*1.1,y:Y.y}],o,m(O));for(const L of["left","right"]){const U=O.points[`shoulder.${L}`],ot={x:J.x+q+(U.x>J.x+q?1:-1)*X*.55,y:J.y};R.line([ot,{x:U.x+(ot.x-U.x)*.15,y:U.y+(ot.y-U.y)*.15}],m(O)*1.6)}const tt=pt(J,Y,.3),nt=X*.4;R.line([{x:tt.x+q-nt,y:tt.y},{x:tt.x+q-nt,y:tt.y+nt*1.4},{x:tt.x+q+nt,y:tt.y+nt*1.4},{x:tt.x+q+nt,y:tt.y}],m(O)*.6)},A=(O,R)=>{const{hip:z,top:K}=k(O),N=pt(z,K,.2),q=[O.points["ankle.left"],O.points["ankle.right"]],Y=pt(z,{x:(q[0].x+q[1].x)/2,y:(q[0].y+q[1].y)/2},.98),J=O.height*.075,X=Math.max(O.height*.12,Math.abs(q[0].x-q[1].x)/2+O.height*.07),tt=Y.x-N.x,nt=Y.y-N.y,L=Math.hypot(tt,nt)||1,U={x:-nt/L,y:tt/L};if(R.shape([{x:N.x+U.x*J,y:N.y+U.y*J},{x:Y.x+U.x*X,y:Y.y+U.y*X},{x:Y.x-U.x*X,y:Y.y-U.y*X},{x:N.x-U.x*J,y:N.y-U.y*J}],f,m(O)),ee(O)>.2){const at=Oe(O)*O.height*.03;for(const it of[-.35,0,.35]){const ct=J*.5*it,st=X*.45*it;R.line([{x:N.x+at+U.x*ct,y:N.y+U.y*ct+O.height*.02},{x:Y.x+at+U.x*st,y:Y.y+U.y*st}],m(O)*.5)}}},I=(O,R)=>{const z=ee(O),{top:K,hip:N}=k(O),q=Oe(O),Y=q>=0?"left":"right",J=Y==="left"?"right":"left",X=O.points[`shoulder.${Y}`],tt=O.height*.035;if(z<.15){const U=pt(K,N,.9);R.shape(zt([X,{x:U.x+(X.x-K.x)*.5,y:U.y}],tt*2.2,tt*2.6),f,m(O));return}const nt={x:N.x+(O.points[`hip.${J}`].x-N.x)*1.2,y:pt(N,K,.08).y};R.shape(zt([nt,pt(nt,X,.5),X],tt*2.4,tt*2),f,m(O));const L={x:X.x-(N.x-X.x)*.05-q*O.height*.03,y:X.y+O.height*.16};R.shape(zt([X,L],tt*2,tt*1.6),f,m(O))},C=(O,R)=>{if(O.bodyContours){R.shape(Pl(O,{top:!1,length:.45}).skirt,o,m(O));return}const{hip:z,top:K}=k(O),N=pt(z,K,.18),q=[O.points["knee.left"],O.points["knee.right"]],Y=pt(z,{x:(q[0].x+q[1].x)/2,y:(q[0].y+q[1].y)/2},1.05),J=O.height*.075,X=Math.max(O.height*.13,Math.abs(q[0].x-q[1].x)/2+O.height*.08),tt=Y.x-N.x,nt=Y.y-N.y,L=Math.hypot(tt,nt)||1,U={x:-nt/L,y:tt/L};R.shape([{x:N.x+U.x*J,y:N.y+U.y*J},{x:Y.x+U.x*X,y:Y.y+U.y*X},{x:Y.x-U.x*X,y:Y.y-U.y*X},{x:N.x-U.x*J,y:N.y-U.y*J}],o,m(O))},D=(O,R)=>{const z=ee(O);if(z<.2)return;const{top:K,hip:N}=k(O),q={x:(N.x-K.x)*.12,y:(N.y-K.y)*.12},Y=O.height*.045*z;for(const J of[-1,1])R.shape([{x:K.x+J*Y*.2,y:K.y+q.y*.1},{x:K.x+J*Y*1.3,y:K.y-q.y*.1},{x:K.x+J*Y*.6+q.x,y:K.y+q.y}],i,m(O)*.8)},j=(O,R,z)=>{const K=ee(O);if(K<.25)return;const{top:N,hip:q}=k(O),Y=Oe(O)*O.height*.03,J=L=>({x:pt(N,q,L).x+Y,y:pt(N,q,L).y}),X=O.height*.022*K,tt=J(.08),nt=J(.62);R.shape([{x:tt.x-X,y:tt.y-X},{x:tt.x+X,y:tt.y-X},{x:tt.x+X*.6,y:tt.y+X},{x:tt.x-X*.6,y:tt.y+X}],z,m(O)*.7),R.shape([{x:tt.x-X*.6,y:tt.y+X},{x:tt.x+X*.6,y:tt.y+X},{x:nt.x+X*1.4,y:nt.y-X*2},nt,{x:nt.x-X*1.4,y:nt.y-X*2}],z,m(O)*.7)},V=(O,R)=>{const z=ee(O),{top:K,hip:N}=k(O),q=pt(N,K,.72),Y=[O.points["knee.left"],O.points["knee.right"]],J=pt(N,{x:(Y[0].x+Y[1].x)/2,y:(Y[0].y+Y[1].y)/2},.9),X=Oe(O)*O.height*.04;if(z<.15){const L=pt(N,K,.2);z<-.3&&R.line([{x:L.x-O.height*.05,y:L.y},{x:L.x+O.height*.05,y:L.y}],m(O));return}const tt=O.height*.075*z,nt=pt(N,K,.2);R.shape([{x:q.x+X-tt*.7,y:q.y},{x:q.x+X+tt*.7,y:q.y},{x:nt.x+X+tt,y:nt.y},{x:J.x+X+tt*1.15,y:J.y},{x:J.x+X-tt*1.15,y:J.y},{x:nt.x+X-tt,y:nt.y}],f,m(O)),R.line([{x:q.x+X-tt*.6,y:q.y},{x:K.x-tt*.2,y:K.y},{x:q.x+X+tt*.6,y:q.y}],m(O)*.8)},et=(O,R,z)=>{const{top:K,hip:N}=k(O),q=[O.points["knee.left"],O.points["knee.right"]],Y=pt(N,{x:(q[0].x+q[1].x)/2,y:(q[0].y+q[1].y)/2},.95);z?R.shape(zt([pt(K,N,.8),N,Y],O.height*.145,O.height*.17),f,m(O)):R.shape(zt([K,pt(K,N,.5),N],O.height*.14,O.height*.15),f,m(O));const J=ee(O);if(J>.2){const X=Oe(O)*O.height*.03,[tt,nt]=z?[N,Y]:[K,N];if(R.line([{x:tt.x+X,y:tt.y},{x:nt.x+X,y:nt.y}],m(O)*.8),!z){const L=pt(K,N,.35),U=O.height*.025*J;R.shape([{x:L.x+X-U*2.4,y:L.y},{x:L.x+X-U*.6,y:L.y},{x:L.x+X-U*.6,y:L.y+U*1.6},{x:L.x+X-U*2.4,y:L.y+U*1.6}],f,m(O)*.6)}}},G=(O,R,z,K,N)=>{const q=O.bodyContours?.[`arm.${z}`];if(q){const Z=dl(q,0,N,O.height*.006);R.shape(Z,K,0);const rt=y(O);for(let ht=0;ht<Z.length;ht++){const dt=Z[ht],bt=Z[(ht+1)%Z.length];jd({x:(dt.x+bt.x)/2,y:(dt.y+bt.y)/2},rt)||R.line([dt,bt],m(O))}return}const Y=O.parts[`arm.${z}`].points,J=Y[0],X=O.chains.spine[O.chains.spine.length-1],nt=[{x:J.x+(X.x-J.x)*.45,y:J.y+(X.y-J.y)*.45},...Il(Y,0,N)],L=zt(nt,O.height*.085,O.height*(N>.6?.045:.06)),U=nt.length,ot=L.slice(0,U),at=L.slice(U).reverse();R.shape(L,K,0);const it=Z=>Math.hypot(Z[1].x-X.x,Z[1].y-X.y),[ct,st]=it(ot)>it(at)?[ot,at]:[at,ot];R.line(ct.slice(1),m(O)),R.line(st.slice(Math.ceil(U*.45)),m(O)),R.line([ot[U-1],at[U-1]],m(O))},F=l||c||h,H=F?f:i,W=F||r==="long"?.95:.45,_=F||r!=="none",B=(O,R)=>{a==="skirt"&&!u&&!d&&C(O,R),d&&A(O,R),l&&et(O,R,!0),t.over==="apron"&&V(O,R)},Q=O=>(R,z,K)=>{R.save(),x(R,z),w(R,z,K,O),p&&v(z,K,O),R.restore(),gv(z)===O&&jf(z)&&B(z,K)};return{parts:{"leg.left":{clip:x,over:Q("left")},"leg.right":{clip:x,over:Q("right")},spine:{over:(O,R,z)=>{c&&ee(R)>=0&&T(R,z),P(R,z),M(O,R,z),s&&!c&&D(R,z),t.tie&&!c&&j(R,z,t.tie),l&&et(R,z,!1),h&&E(R,z),c&&(ee(R)<0&&T(R,z),S(R,z)),u&&$(R,z),d&&I(R,z),jf(R)||B(R,z)}},"arm.left":{over:_?(O,R,z)=>G(R,z,"left",H,W):void 0},"arm.right":{over:_?(O,R,z)=>G(R,z,"right",H,W):void 0}}}}const Ol={mug:{color:"#e2493b",hands:"one"},phone:{color:"#2b2f36",hands:"one"},book:{color:"#3a6ea5",hands:"either"},bag:{color:"#e9d8b4",hands:"one"},briefcase:{color:"#6b4630",hands:"one"},umbrella:{color:"#3c9a6e",hands:"one"},broom:{color:"#c8963e",hands:"one"},cane:{color:"#6b4630",hands:"one"},parcel:{color:"#c9a06a",hands:"both"}};function Gf(t){const e={};for(const n of["left","right","both"]){const s=t[n];if(!s)continue;const i=typeof s=="string"?s:s.item,o=Ol[i];if(!o)throw new Error(`holding: unknown item '${i}'`);if(n==="both"&&o.hands==="one")throw new Error(`holding: a ${i} is held in one hand ('left' or 'right'), not 'both'`);if(n!=="both"&&o.hands==="both")throw new Error(`holding: a ${i} is held in both hands ('both')`);e[n]={item:i,color:(typeof s=="object"?s.color:void 0)??o.color}}return e}function Uo(t,e){const n=t.chains[`arm.${e}`],s=n[n.length-1],i=n[n.length-2],o=Math.hypot(s.x-i.x,s.y-i.y)||1,r={x:(s.x-i.x)/o,y:(s.y-i.y)/o},a=t.lineWidth*.5;return{point:{x:s.x+r.x*a,y:s.y+r.y*a},along:r,depth:t.parts[`arm.${e}`]?.depth??0}}function cs(t,e,n,s=0){const i=Math.cos(s),o=Math.sin(s);return[[-e/2,-n/2],[e/2,-n/2],[e/2,n/2],[-e/2,n/2]].map(([r,a])=>({x:t.x+r*i-a*o,y:t.y+r*o+a*i}))}const hs=(t,e,n,s,i=12)=>Array.from({length:i+1},(o,r)=>{const a=n+(s-n)*r/i;return{x:t.x+Math.cos(a)*e,y:t.y+Math.sin(a)*e}});function _l(t,e,n,s,i,o=1,r){const{point:a,along:l}=n,c=s/300;switch(e.item){case"mug":{const h=cs({x:a.x,y:a.y-4*c},20*c,24*c);t.line(hs({x:a.x+10*c*Math.sign(o||1),y:a.y-4*c},7*c,-Math.PI/2,Math.PI/2).map(u=>({x:a.x+(u.x-a.x)*Math.sign(o||1),y:u.y})),i),t.shape(h,e.color,i);return}case"phone":{const h=Math.atan2(l.y,l.x)-Math.PI/2;t.shape(cs(a,13*c,24*c,h),e.color,i),t.shape(cs(a,9*c,17*c,h),"#8fd0f5",0);return}case"book":{const h=26*c,u=34*c;t.shape([{x:a.x,y:a.y-u/2},{x:a.x-h,y:a.y-u/2-3*c},{x:a.x-h,y:a.y+u/2-3*c},{x:a.x,y:a.y+u/2}],e.color,i),t.shape([{x:a.x,y:a.y-u/2},{x:a.x+h,y:a.y-u/2-3*c},{x:a.x+h,y:a.y+u/2-3*c},{x:a.x,y:a.y+u/2}],e.color,i);for(const d of[-1,1])for(const f of[.3,.5,.7]){const p=a.y-u/2+u*f;t.line([{x:a.x+d*5*c,y:p},{x:a.x+d*(h-5*c),y:p-2*c}],Math.max(.8,i*.5))}return}case"bag":{const h=a.y+10*c;t.line([{x:a.x-9*c,y:h},{x:a.x-5*c,y:a.y-2*c},{x:a.x+5*c,y:a.y-2*c},{x:a.x+9*c,y:h}],i),t.shape([{x:a.x-17*c,y:h},{x:a.x+17*c,y:h},{x:a.x+20*c,y:h+40*c},{x:a.x-20*c,y:h+40*c}],e.color,i);return}case"briefcase":{t.line(hs({x:a.x,y:a.y+6*c},7*c,Math.PI,Math.PI*2),i),t.shape(cs({x:a.x,y:a.y+22*c},46*c,32*c),e.color,i),t.line([{x:a.x-23*c,y:a.y+14*c},{x:a.x+23*c,y:a.y+14*c}],Math.max(.8,i*.6));return}case"umbrella":{const h=78*c,u=(r??a.y-120*c)-14*c,d={x:a.x,y:Math.min(a.y-60*c,u-h*.55)};t.line([{x:a.x,y:a.y+10*c},d],i),t.line(hs({x:a.x+5*c,y:a.y+10*c},5*c,Math.PI,0,8),i);const f=[...hs({x:d.x,y:d.y+h*.55},h,Math.PI,Math.PI*2,24)],p=[];for(let g=4;g>=0;g--){const m=d.x-h+2*h*g/5;p.push(...hs({x:m+h/5,y:d.y+h*.55},h/5,0,-Math.PI,6).reverse())}t.shape([...f,...p],e.color,i);return}case"broom":{const h={x:l.x*.4+.25*Math.sign(o||1),y:Math.max(.6,l.y)},u=Math.hypot(h.x,h.y),d={x:h.x/u,y:h.y/u},f={x:a.x-d.x*40*c,y:a.y-d.y*40*c},p={x:a.x+d.x*120*c,y:a.y+d.y*120*c};t.line([f,p],i*1.1);const g={x:-d.y,y:d.x},m=[{x:p.x+g.x*6*c,y:p.y+g.y*6*c},{x:p.x-g.x*6*c,y:p.y-g.y*6*c},{x:p.x-g.x*16*c+d.x*34*c,y:p.y-g.y*16*c+d.y*34*c},{x:p.x+g.x*16*c+d.x*34*c,y:p.y+g.y*16*c+d.y*34*c}];t.shape(m,e.color,i);return}case"cane":{const h=Math.min(.56*s,Math.max(.3*s,-a.y)),u=.12*Math.sign(o||1),d={x:u/Math.hypot(u,1),y:1/Math.hypot(u,1)},f={x:a.x+d.x*h,y:a.y+d.y*h},p=hs({x:a.x+7*c*Math.sign(o||1),y:a.y-2*c},7*c,Math.PI,Math.PI*2,8).map(g=>({x:a.x+(g.x-a.x)*Math.sign(o||1),y:g.y}));t.line([...p,{x:a.x,y:a.y+2*c},f],i*1.2),t.shape(cs({x:f.x,y:f.y-3*c},9*c,7*c),e.color,0);return}case"parcel":{const h={x:a.x,y:a.y-6*c};t.shape(cs(h,50*c,40*c),e.color,i),t.line([{x:h.x-25*c,y:h.y-6*c},{x:h.x+25*c,y:h.y-6*c}],Math.max(.8,i*.7)),t.line([{x:h.x,y:h.y-20*c},{x:h.x,y:h.y+20*c}],Math.max(.8,i*.7));return}}}const Cl=(t,e)=>(t[`held.${e}`]??1)>=.5,Uf=t=>Math.sin(t*Math.PI/2);function Vf(t){const e=o=>Math.max(1,o.lineWidth*.45),n=o=>(r,a,l,c,h)=>{const u=t[o];u&&Cl(h??{},o)&&_l(l,u,Uo(a,o),a.height,e(a),Uf(a.turn),a.head.center.y-a.head.ry)},s=(o,r,a,l,c)=>{const h=t.both;if(!h||!Cl(c??{},"both"))return;const u=Uo(r,"left"),d=Uo(r,"right"),f={point:{x:(u.point.x+d.point.x)/2,y:(u.point.y+d.point.y)/2},along:{x:(u.along.x+d.along.x)/2,y:(u.along.y+d.along.y)/2},depth:(u.depth+d.depth)/2};_l(a,h,f,r.height,e(r),Uf(r.turn),r.head.center.y-r.head.ry)},i={parts:{}};if(t.left&&(i.parts["arm.left"]={over:n("left")}),t.right&&(i.parts["arm.right"]={over:n("right")}),t.both){const o=r=>(a,l,c,h,u)=>{const d=r==="left"?"right":"left";(r==="left"?l.parts["arm.left"].depth>=l.parts["arm.right"].depth:l.parts["arm.right"].depth>l.parts[`arm.${d}`].depth)&&s(a,l,c,h,u)};for(const r of["left","right"])i.parts[`arm.${r}`]={...i.parts[`arm.${r}`],over:pv(i.parts[`arm.${r}`]?.over,o(r))}}return i}function pv(t,e){return t?(n,s,i,o,r)=>{t(n,s,i,o,r),e(n,s,i,o,r)}:e}function Hl(t,e){const n=(i,o)=>i&&o?(r,a,l,c,h)=>{i(r,a,l,c,h),o(r,a,l,c,h)}:i??o,s={};for(const i of new Set([...Object.keys(t.parts??{}),...Object.keys(e.parts??{})])){const o=t.parts?.[i],r=e.parts?.[i];s[i]={under:n(o?.under,r?.under),clip:n(o?.clip,r?.clip),over:n(o?.over,r?.over)}}return{behind:n(t.behind,e.behind),parts:s,front:n(t.front,e.front)}}function us(t={}){if(t.build&&!(t.build in Io))throw new Error(`character: unknown build '${t.build}'`);const e=t.build?Io[t.build]:{},n=(t.proportions??"bold")==="bold",s=t.figure??"fluid",i=t.look??"clean",o=t.height??300,r=s==="stick",a=s==="organic",l=t.shoulderWidth??e.shoulderWidth??(a?.07:.06),c=t.hipWidth??e.hipWidth??(a?.045:.022),h=t.lineWidth??o*(a?.005:n?.045:.022),u=t.ink??(a?"#53362d":i==="pencil"?"#2f2f33":"#1e293b"),d=t.skin??(a?"#f1bf98":i==="pencil"?"none":"#ffffff"),f=a?Dd(t.body??{},{skin:d,ink:u,lineWidth:h,shoulderWidth:l,hipWidth:c}):void 0;if(t.leafOutfit&&!a)throw new Error("character: leafOutfit requires figure: 'organic'");const p=t.outfit?Xf(t.outfit):null,g=t.holding?Gf(t.holding):{};let m=p?Hl(p,t.layers??{}):t.layers??{};return t.leafOutfit&&(m=Hl(qf(t.leafOutfit),m)),Object.keys(g).length>0&&(m=Hl(m,Vf(g))),{plan:t.plan??il({headSize:t.headSize??e.headSize??(a?.27:n?.3:.24),shoulderWidth:r?0:l,hipWidth:r?0:c,legLength:t.legLength??e.legLength??1,armLength:t.armLength??e.armLength??1,feet:t.feet??e.feet}),figure:s,...f?{body:f}:{},look:i,height:o,lineWidth:f?.outline.width??h,ink:f?.outline.color??u,skin:f?.fill??d,seed:t.seed??1,pencil:a?{construction:!1,...t.pencil}:t.pencil??{},layers:m,holding:g,contact:t.contact??"ground",hands:t.hands??(a?"cartoon":"dot"),handStyle:t.handStyle??(a?"natural":"glove"),handSize:t.handSize??(a?.073:t.handStyle==="natural"?.14:.17),head:Pf(t),face:{...a?{style:"anime",projection:"volume",iris:"#66422e",nose:!0}:{},...t.face,teeth:t.face?.teeth??!1,tongue:t.face?.tongue??!1}}}function mv(t,e,n,s){const{point:i,facing:o}=es(t,[e,n,s]);return{point:i,facing:o}}const Rl=t=>t.rest[1]<-.5,yv=.3;function bv(t,e,n){return t.figure==="stick"?Rl(e)?n.slice(0,3):n:Rl(e)&&n.length>=3?wn(n[0],n[1],n[2],yv):n.length===3?wn(n[0],n[1],n[2],1):n}function mi(t,e){const n=t.plan.id==="human"?{...lt,...e}:e;return Vo(t,n,al(t.plan,n,{height:t.height,contact:t.contact}))}function Vo(t,e,n){const s={},i={},o={},r=.01*t.height;t.plan.chains.forEach(f=>{const p=n.chains[f.id];s[f.id]=p.points;const g=p.depths.reduce((k,y)=>k+y,0)/p.depths.length,m=f.parent?n.chains[f.parent]:void 0,w=m?m.depths[f.at??m.depths.length-1]:n.hipDepth,v=g-w;o[f.id]=Math.abs(v)<r?0:v,i[f.id]={points:bv(t,f,p.points),depth:g,order:0}}),i.head={points:[n.head.center],depth:n.head.depth,order:0},o.head=0;const a=[...t.plan.chains.map(f=>f.id),"head"],l=f=>t.body&&f.startsWith("arm.")&&o[f]>=0?1:0,c=[...a].sort((f,p)=>l(f)-l(p)||o[f]-o[p]||a.indexOf(f)-a.indexOf(p));c.forEach((f,p)=>{i[f].order=p});const h={hip:n.hip};for(const[f,[p,g]]of Object.entries(t.plan.landmarks??{})){const m=n.chains[p]?.points;m&&(h[f]=m[Math.min(g,m.length-1)])}const u={};for(const[f,p]of Object.entries(h))u[f]=p.y>=n.groundY-.01*t.height;const d={height:t.height,lineWidth:t.lineWidth,turn:e.turn??0,...n.bodyForward?{bodyForward:n.bodyForward}:{},points:h,chains:s,parts:i,head:n.head,groundY:n.groundY,grounded:u};return t.body&&(d.bodyContours=qd(t.body,d,t.plan)),{skeleton:n,joints:d,order:c}}function fe(t,e){return mi(t,e).joints}function Jf(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=xt(s,i,{x:0,y:0});r.facing>0&&t.guide(r.points),t.guide(xt(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 Zf(t,e,n,s,i,o){const r=n.lineWidth;if(n.body&&n.skin==="none"&&(e=ei(t,e)),i==="head"){const{head:f}=s;let p;const g=()=>p??=Gd(f,n.face),m=n.skin==="none"?null:n.skin;n.face.projection==="volume"||n.face.shape==="angular"?e.shape(g(),m,r):e.ellipse(f.center.x,f.center.y,f.rx,f.ry,f.angle,m,r),n.body&&n.skin!=="none"&&e.look==="clean"&&Uu(t,g(),f.center,n.body.shading),lv(t,e,n.head,f,o,{lineWidth:r,skin:n.skin,face:n.face,faceUnderHair:!!n.body},()=>{e.look!=="silhouette"&&(t.save(),n.body&&(t.beginPath(),g().forEach((w,v)=>v?t.lineTo(w.x,w.y):t.moveTo(w.x,w.y)),t.closePath(),t.clip()),$5(e,f,o,r,{...n.face,skin:n.skin==="none"?"#ffffff":n.skin},t),t.restore())});return}const a=n.plan.chains.find(f=>f.id===i),l=s.chains[i],c=s.parts[i].points;if(n.body&&Kd(t,e,n.body,s,i)){if(i.startsWith("leg.")&&Kd(t,e,n.body,s,i.replace("leg.","foot.")),i.startsWith("arm."))if(n.hands==="cartoon")tg(t,e,n,l,i.endsWith(".left")?"left":"right",o);else{const f=l.at(-1);e.ellipse(f.x,f.y,n.height*.014,n.height*.014,0,n.skin==="none"?null:n.skin,r)}return}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,p)=>[a.bones[f].width[0]*r,a.bones[p].width[1]*r];if(Rl(a)){const[f,p]=h(0,1);if(e.limb(c,f,p),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."))tg(t,e,n,l,i.endsWith(".left")?"left":"right",o);else{const g=l[l.length-1];e.dot(g.x,g.y,r*.62)}return}if(i==="spine"){const f=s.points["hip.left"],p=s.points["hip.right"];f&&p&&Math.hypot(f.x-p.x,f.y-p.y)>.5&&e.limb([f,p],r*1.3,r*1.3);const[g,m]=h(0,a.bones.length-1);e.limb(c,g,m);const w=s.points["shoulder.left"],v=s.points["shoulder.right"];w&&v&&Math.hypot(w.x-v.x,w.y-v.y)>.5&&e.limb(wn(w,l[l.length-1],v,1,10),r*1.15,r*1.15);return}const[u,d]=h(0,a.bones.length-1);e.limb(c,u,d)}function Qf(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{...Ot,...s,turn:o+(s.turn??0)}}function tg(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;wo(t,r,Qf(o,i),{size:n.handSize*n.height,side:i,angle:l,pen:e,skin:n.skin==="none"&&!n.body?"#ffffff":n.skin,fingers:n.handStyle==="natural"?5:4,plump:n.handStyle==="natural"?1.15:1.6,lineWidth:n.lineWidth*(n.body?.65:.3),connected:!!n.body,shading:n.body?.shading,nails:n.body?!1:void 0})}function eg(t,e,n,s=0){const i=e.plan.id==="human"?{...lt,...n}:n;Ll(t,e,i,mi(e,i),s)}function Jo(t,e){const n=e/t.height;return{...t,height:e,lineWidth:t.lineWidth*n}}function wv(t,e,n,s){const i=t.plan.id==="human"?{...lt,...e}:e,o=Ro(t.plan,i,{height:s.height,contact:t.contact},n);return Vo(Jo(t,o.height),i,o).joints}function kv(t,e,n,s,i){const o=e.plan.id==="human"?{...lt,...n}:n,r=Ro(e.plan,o,{height:i.height,contact:e.contact},s),a=Jo(e,r.height);Ll(t,a,o,Vo(a,o,r),i.time??0)}function ng(t,e,n,s){const i=t.plan.id==="human"?{...lt,...e}:e,o=Ro(t.plan,i,{height:s.height,contact:t.contact},n),r=Jo(t,o.height),{joints:a,order:l}=Vo(r,i,o),c=o.height/s.height,h=l.map(p=>(a.parts[p]?.depth??0)/c),u=l.filter(p=>p==="spine"||p.startsWith("leg.")),d=Math.max(...u.map(p=>a.parts[p].depth/c)),f=Math.max(...u.map(p=>a.parts[p].order));return l.map((p,g)=>({part:p,depth:h[g],...r.body?{sortDepth:p.startsWith("arm.")&&g>f?Math.max(h[g],d):h[g]}:{},draw(m,w=0){const v=ti(m,{look:r.look,ink:r.ink,lineWidth:r.lineWidth,seed:ne(`${r.seed}:${p}`),time:w,pencil:r.pencil}),k=x=>{x&&(m.save(),x(m,a,v,w,i),m.restore())};m.save(),m.lineCap="round",m.lineJoin="round",g===0&&(r.look==="pencil"&&r.pencil.construction!==!1&&Jf(v,r,a),k(r.layers.behind),Cf(m,r.body&&r.skin==="none"?ei(m,v):v,r.head,a.head,i,{lineWidth:r.lineWidth,skin:r.skin,face:r.face}));const y=r.layers.parts?.[p];k(y?.under),m.save(),y?.clip?.(m,a,v,w,i),Zf(m,v,r,a,p,i),m.restore(),k(y?.over),p==="head"&&Hf(m,v,r.head,a.head,i,{lineWidth:r.lineWidth,skin:r.skin,face:r.face}),g===l.length-1&&k(r.layers.front),m.restore()}}))}function Ll(t,e,n,s,i,o){const{joints:r}=s,a=o?s.order.filter(h=>o.has(h)):s.order,l=ti(t,{look:e.look,ink:e.ink,lineWidth:e.lineWidth,seed:e.seed,time:i,pencil:e.pencil}),c=h=>{h&&(t.save(),h(t,r,l,i,n),t.restore())};t.save(),t.lineCap="round",t.lineJoin="round",!o&&e.look==="pencil"&&e.pencil.construction!==!1&&Jf(l,e,r),o||c(e.layers.behind),Cf(t,e.body&&e.skin==="none"?ei(t,l):l,e.head,r.head,n,{lineWidth:e.lineWidth,skin:e.skin,face:e.face});for(const h of a){const u=e.layers.parts?.[h];c(u?.under),t.save(),u?.clip?.(t,r,l,i,n),Zf(t,l,e,r,h,n),t.restore(),c(u?.over)}Hf(t,l,e.head,r.head,n,{lineWidth:e.lineWidth,skin:e.skin}),o||c(e.layers.front),t.restore()}function vv(t,e,n,s){const i=e.plan.id==="human"?{...lt,...n}:n,o=mi(e,i).joints.head.rx,r=Jo(e,e.height*s.radius/Math.max(1e-6,o)),a=mi(r,i);t.save(),t.translate(s.x-a.joints.head.center.x,s.y-a.joints.head.center.y),Ll(t,r,i,a,s.time??0,new Set(["head"])),t.restore()}function Fl(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 _e(t,e,n,s){const i=t.plan.id==="human"?{...lt,...e}:e;let o;if(Array.isArray(s))o=s;else{const{skeleton:r}=mi(t,i),a=al(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),p=s.depth??r.chains[n].depths[r.chains[n].depths.length-1],g=Math.cos(f),m=Math.sin(f);o=[u*g-p*m,-d,u*m+p*g]}return ci(t.plan,i,n,o,{height:t.height})}const sg=new Set(["walk","walking","gait"]);function Zo(t,e=lt,n){let s={...e};for(const[o,r]of Object.entries(t))typeof r=="number"&&!sg.has(o)&&(s[o]=r);const i=Math.max(0,Math.min(1,typeof t.walking=="number"?t.walking:0));if(i>0){const o=typeof t.gait=="string"?t.gait:void 0,r=o?n?.[o]??o:void 0,a=Ko(r,typeof t.walk=="number"?t.walk:0,s);s=Object.fromEntries(Object.keys({...s,...a}).map(l=>[l,(s[l]??0)+((a[l]??0)-(s[l]??0))*i]))}return s}function Mv(t){const{character:e}=t,n=e.height*.8,s=e.height,i=e.plan.id==="human"?lt:{};return{type:"custom",x:t.x-n/2,y:t.y-s,width:n,height:s,props:{...i,...t.pose},character:e,...t.gaits?{gaits:t.gaits}:{},draw(o,r,a){o.translate(n/2,s),eg(o,e,Zo(r.props??{},i,t.gaits),a)}}}function ig(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,...t.bodyContours?{bodyContours:Object.fromEntries(Object.entries(t.bodyContours).map(([o,r])=>[o,{...r,outline:r.outline.map(s),samples:r.samples.map(a=>({...a,center:s(a.center),left:s(a.left),right:s(a.right)}))}]))}:{},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 Sv(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[c,h]of e.state?.values.get(n)??[])c==="x"||c==="motionPathX"?o=typeof h=="number"?h:o:c==="y"||c==="motionPathY"?r=typeof h=="number"?h:r:(typeof h=="number"||sg.has(c))&&(i[c]=h);const a=Zo(i,s.plan.id==="human"?lt:{},t.gaits),l=fe(s,a);return{pose:a,joints:ig(l,t.x+o+t.width/2,t.y+r+t.height)}}function Nl(t,e=lt){const n=[];return t.forEach((s,i)=>{const o=i===0?e:n[i-1],r=typeof s.pose=="string"?ye[s.pose]:void 0;n.push(r?{...r,turn:o.turn??0}:{...o,...s.pose})}),n}function xv(t,e,n=lt){const s=Nl(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 Qo=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Ee=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],tr=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],Wl=t=>Math.hypot(...t),og=t=>tr(t,1/(Wl(t)||1)),er=t=>({...lt,...t}),Dl=t=>Ue(t.character.plan,er(t.pose),{height:t.character.height,contact:t.character.contact});function $n(t,e,n){return Qo(t.position,Dl(t).chains[e][n])}function rg(t,e,n){const s=er(t.pose),i=Dl(t).hip,o=ts(t.character.plan,s,t.character.height),r=Ee(Ee(n,t.position),i),a=Qn(r,(s.roll??0)*Math.PI/180),l=Qo(o.root,Qt(a,-(s.turn??0)*Math.PI/2));return ci(t.character.plan,s,e,l,{height:t.character.height})}function ag(t,e,n,s="toe"){const i=`leg.${e}`,o=s==="toe"?3:2;let r={...t,pose:er(t.pose),position:[...t.position]};for(let l=0;l<6;l++){const c=Dl(r).chains[i],h=Ee(c[o],c[2]);r={...r,pose:rg(r,i,Ee(n,h))};const u=$n(r,i,o);r.position[1]+=n[1]-u[1]}const a=Wl(Ee($n(r,i,o),n));return{...r,reached:a<t.character.height*.002}}function lg(t,e){const n=$n(t,`arm.${e}`,2),s=$n(t,`arm.${e}`,1);return Qo(n,tr(og(Ee(n,s)),t.character.lineWidth*.5))}function Tv(t,e,n={}){const s=Math.min(t.character.height,e.character.height),i=n.length??s*.22;if(!(i>0)||!Number.isFinite(i))throw new Error("meetDandiya: stick length must be positive and finite");const o=n.point??[(t.position[0]+e.position[0])/2,Math.max(t.position[1],e.position[1])+s*.62,(t.position[2]+e.position[2])/2],r=(c,h)=>{const u=og([o[0]-c.position[0],s*.2,o[2]-c.position[2]]),d=Ee(o,tr(u,i));let f=er(c.pose);for(let g=0;g<6;g++){const m={...c,pose:f},w=$n(m,`arm.${h}`,2);f=rg(m,`arm.${h}`,Ee(d,Ee(lg(m,h),w)))}for(const[g,m]of Object.entries(St.hold))f[`hand.${h}.${g}`]=m;const p=lg({...c,pose:f},h);return{pose:f,stick:{grip:p,tip:Qo(p,tr(u,i))}}},a=r(t,n.sideA??"right"),l=r(e,n.sideB??"right");return{a:a.pose,b:l.pose,sticks:[a.stick,l.stick],point:o,reached:[a.stick,l.stick].every(c=>Wl(Ee(c.tip,o))<s*.002)}}function cg(t,e){const n=e.count??8,s=e.beatsPerTurn??32;if(!Number.isFinite(t)||!Number.isFinite(e.radius)||e.radius<=0||!Number.isInteger(n)||n<1||!Number.isFinite(s)||s<=0)throw new Error("danceCircleAt: finite beat, positive radius/beatsPerTurn and a positive integer count are required");const i=e.center??[0,0],o=e.direction??1;if(i.length!==2||!i.every(Number.isFinite)||!Number.isFinite(e.angle??0)||!Number.isFinite(e.spins??0)||![1,-1].includes(o)||e.facing!==void 0&&!(typeof e.facing=="number"?Number.isFinite(e.facing):["inward","outward","tangent"].includes(e.facing)))throw new Error("danceCircleAt: center, angle, spins and facing must be finite; direction is 1 or -1");const r=e.character??us({height:1.7}),a=e.style??"garba",l=(h,u)=>{const d=(e.angle??0)+360*u/n+o*360*h/s,f=d*Math.PI/180,p=e.facing??"inward",g=(typeof p=="number"?p:d+(p==="inward"?180:p==="tangent"?o*90:0))+(e.spins??0)*360*h/s,m=hi(a,h,{...e.pose,turn:g/90});return{character:r,position:[i[0]+e.radius*Math.sin(f),0,i[1]+e.radius*Math.cos(f)],pose:m.pose,heading:g,strike:m.strike}},c=hi(a,t).contact;return Array.from({length:n},(h,u)=>{const d=l(t,u);if(e.plantFeet===!1)return{...d,planted:!1};const f=l(c.start,u),p=$n(f,`leg.${c.side}`,3),g=ag(d,c.side,p);return{...d,pose:Fl(d.pose,g.pose,c.weight),position:[d.position[0],g.position[1]*c.weight,d.position[2]],planted:g.reached&&c.weight===1}})}function Ev(t,e){if(e.count!==void 0&&e.count!==t.length)throw new Error("danceCircleTracks: count must match targets.length");const n=e.bpm??120,s=e.samplesPerBeat??16;if(!t.length||![n,e.beats,s].every(l=>Number.isFinite(l)&&l>0))throw new Error("danceCircleTracks: targets and positive finite bpm, beats and samplesPerBeat are required");if(!Number.isFinite(e.start??0))throw new Error("danceCircleTracks: start must be finite");const i=Math.max(1,Math.ceil(e.beats*s)),o=Array.from({length:i+1},(l,c)=>({time:(e.start??0)+e.beats*c/i*6e4/n,members:cg(e.beats*c/i,{...e,count:t.length})})),r=o.some(l=>l.members.some(c=>c.pose.roll!==0)),a=new Set(["x","y","z","rotateY",...r?["turn","roll"]:[]]);return t.flatMap((l,c)=>{const h=o.map(u=>{const d=u.members[c],{turn:f,...p}=d.pose;return{time:u.time,pose:{...r?d.pose:p,x:d.position[0],y:d.position[1],z:d.position[2],rotateY:r?0:d.heading}}});return Object.keys(h[0].pose).filter(u=>a.has(u)||h.some(d=>d.pose[u]!==(e.pose?.[u]??lt[u]))).map(u=>({id:`${l}-circle-${u}`,target:l,property:u,keyframes:h.map(d=>({time:d.time,value:d.pose[u],easing:"linear"}))}))})}const nr=t=>Math.min(1,Math.max(0,t));function Av(t){const e={...ut,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 $v(t){return t-Pv*Math.sin(2*Math.PI*t)/(2*Math.PI)}const Pv=.5;function Iv(t,e){if(!(e<=t.takeoff||e>=t.landing))return(e-t.takeoff)/(t.landing-t.takeoff)}function hg(t,e){const n=typeof t=="string"?yi[t]:t,s=Av(n),i=nr(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=Zn(r.pose,a.pose,Wt(a.easing??"ease-in-out")(nr(l))),h=Iv(n,i);return h===void 0?{...c,spin:0,rise:0}:{...c,spin:n.spin*$v(h),rise:4*n.height*h*(1-h)}}function ug(t,e,n){const s=typeof t=="string"?yi[t]:t,i=nr(e),o=nr((i-s.takeoff)/(s.landing-s.takeoff));return s.travel*n*o}function Ov(t,e,n={}){const s=typeof e=="string"?yi[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:hg(s,d)}}),c=Object.keys(ut).filter(h=>a.some(u=>u.pose[h]!==ut[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*ug(s,u.progress,n.height)}))})}return c}const _v={leftHip:-55,leftKnee:-95,rightHip:55,rightKnee:95,leftShoulder:45,rightShoulder:-45,leftElbow:10,rightElbow:-10,lean:22,stretch:.94,headTilt:6},Cv={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},sr={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},Hv={leftHip:-22,leftKnee:-30,rightHip:22,rightKnee:30,leftAnkle:10,rightAnkle:10,leftShoulder:-125,rightShoulder:125,leftElbow:0,rightElbow:0,lean:8,headTilt:0},Rv={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 ds(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:_v},{at:.27,pose:Cv,easing:"ease-out-quad"},...i,{at:.76,pose:Hv},{at:.86,pose:Rv,easing:"ease-out-quad"},{at:1,reset:!0}]}}const yi={frontFlip:ds("Front flip (tuck)",360,.56,.35,[{at:.38,pose:sr,easing:"ease-out-cubic"},{at:.64,pose:sr}]),backFlip:ds("Back flip (tuck)",-360,.58,-.15,[{at:.36,pose:{...sr,lean:18},easing:"ease-out-cubic"},{at:.64,pose:{...sr,lean:18}}]),layout:ds("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:ds("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:ds("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:ds("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)};function dg(t,e){const n=Math.min(1,Math.max(0,t.turn??0)),s=1-n,i={...lt,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`],p=s+c*n;i[`leg.${l}.rotate`]=90*s,i[`leg.${l}.spread`]=0,i[`leg.${l}.swing`]=d*p,i[`leg.${l}.knee`]=f*p,i[`leg.${l}.ankle`]=-(t[`${a}Ankle`]??0),i[`leg.${l}.toeOut`]=(t[`${a}FootOut`]??0)*Lv,i[`eye.${l}`]=t[`${a}Eye`],i[`brow.${l}`]=t[`${a}Brow`],e&&Object.assign(i,Fv(l,e[a]??Ot,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 Lv=70;function Fv(t,e,n,s){const i=t==="right"?1-s:1+s,o={};for(const r of Object.keys(Ot))o[`hand.${t}.${r}`]=e[r]??Ot[r];return o[`hand.${t}.turn`]=(e.turn??0)-i,o[`hand.${t}.roll`]=(e.roll??0)+n,o}class fg{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 Nv(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 Bl=Math.PI*2;function Wv(t,e=16){const n=new fg,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*Bl,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 gg(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*Bl;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 pg(t,e,n=24){const s=new fg,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*Bl;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 gg(s,t,o,1,i),gg(s,t,r,-1,i),s.build()}function ir(t){const e=Array.from({length:t.indices.length/3},()=>[]);for(const n of Nv(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 zl=new Map;function Dv(t){const e=zl.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 zl.size<512&&zl.set(t,n),n}Jt([-3,-5,-4]);const Bv=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)};function mg(t,e,n){const s=[0,0,0];for(const i of n){const o=Dv(i.color);let r;if(i.light==="ambient")r=i.intensity;else if(i.light==="directional")r=i.intensity*Math.max(0,-Ae(e,i.direction));else{const a=se(i.position,t),l=no(a),c=l>0?fn(a,1/l):e,h=i.range?Math.max(0,1-l/i.range)**2:1;if(r=i.intensity*Math.max(0,Ae(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*=Bv(u,d,-Ae(c,i.direction))}}s[0]+=o[0]*r,s[1]+=o[1]*r,s[2]+=o[2]*r}return s}function yg(t,e){return t?Math.min(1,Math.max(0,(e-t.near)/(t.far-t.near))):0}function ql(t,e,n={}){t.save(),zv(t,e,n),t.restore()}function zv(t,e,n){const s=jl(e,n);n.shadow!==!1&&Yl(t,e,n);for(const i of e.under)bg(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)bg(t,i,s,n)}function bg(t,e,n,s){const i=s.loose?.[e.part.id];if(!i){Gl(t,e,n,s);return}if(i.opacity<=0)return;const o=e.faces.flatMap(c=>c.points);if(o.length===0)return;const r=o.map(c=>c.x),a=o.map(c=>c.y),l={x:(Math.min(...r)+Math.max(...r))/2,y:(Math.min(...a)+Math.max(...a))/2};t.save(),t.globalAlpha*=Math.min(1,i.opacity),t.translate(l.x+i.x,l.y+i.y),t.rotate(i.rotate*Math.PI/180),t.translate(-l.x,-l.y),Gl(t,e,n,s),t.restore()}function jl(t,e={}){return e.lineWidth??Math.max(1.3,t.sizePx*.022)}function Yl(t,e,n={}){e.shadow.opacity<=0||e.shadow.points.length<3||(t.save(),t.globalAlpha=e.shadow.opacity,or(t,e.shadow.points,n.ink??"#26262b",!1),t.restore())}function qv(t,e,n,s={}){t.save(),Gl(t,e,n,s),t.restore()}function wg(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 p of h){if(p.part.part.id===u.part.part.id)continue;const g=p.face;if(g.normal[0]*f[0]+g.normal[1]*f[1]+g.normal[2]*f[2]<=.8)continue;const w=g.normal[0]*(d[0]-g.center[0])+g.normal[1]*(d[1]-g.center[1])+g.normal[2]*(d[2]-g.center[2]);w>-kg/5&&w<kg&&(u.layer=Math.max(u.layer,p.layer),u.depth=Math.max(u.depth,p.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=Kl(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?vg(h,s):u.light?jv(h,u,s):Xl(h);f&&(!i&&s.look==="silhouette"?d.shape(u.points,f,0):or(t,u.points,i||u.light?f:rr(f,u.tone),!0,h.cut?1.6:.8));const p=(h.part.outline??1)*n;if(p>0)for(const g of u.edges??[])g.length>1&&d.line(g,p);for(const g of u.marks??[])d.line(g,n*.7)}}t.restore()}const kg=.05;function Kl(t,e,n,s){return ti(t,{look:s.look??"clean",ink:e.part.ink??s.ink??"#26262b",lineWidth:n,seed:ne(`${s.seed??0}:${e.part.id}`),time:s.time??0,pencil:{construction:!1,rubbedOut:0,...s.pencil}})}function Xl(t){const{part:e}=t;return e.glow&&t.glow>0&&e.fill?Jl(e.fill,e.glow.color,t.glow):e.fill}function jv(t,e,n){const{part:s}=t;if(!s.fill)return;const i=Vl(s.fill,e.light,e.fog??0,n.fog);return s.glow&&t.glow>0?Jl(i,s.glow.color,t.glow):i}function vg(t,e){const n=Xl(t);return n&&(Kv(n)||t.glow>0)?n:e.paper??"#fbf8ef"}function Gl(t,e,n,s){e.opacity<1?(t.save(),t.globalAlpha*=e.opacity,Mg(t,e,n,s),t.restore()):Mg(t,e,n,s)}function Mg(t,e,n,s){if(s.style==="stick")return Yv(t,e,n,s);const{part:i}=e,o=Kl(t,e,n,s),r=Xl(e),a=s.look==="silhouette";for(const c of e.faces)r&&(a?o.shape(c.points,r,0):or(t,c.points,rr(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 Yv(t,e,n,s){const{part:i}=e;if(i.solidOnly)return;const o=Kl(t,e,n,s);if(e.spine){o.line(e.spine,n*1.15);return}const r=vg(e,s);for(const l of e.faces)or(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 Kv(t){const e=fs(t);return e?(.299*e[0]+.587*e[1]+.114*e[2])/255<.3:!1}function or(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 fs(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 Ul=t=>`#${t.map(e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0")).join("")}`;function rr(t,e){const n=fs(t);return n?Ul(e>=1?n.map(s=>s+(255-s)*(e-1)*2):n.map(s=>s*e)):t}function Vl(t,e,n,s){const i=fs(t);if(!i)return t;let o=i.map((a,l)=>a*e[l]);const r=s?fs(s):void 0;return r&&n>0&&(o=o.map((a,l)=>a+(r[l]-a)*n)),Ul(o)}function Jl(t,e,n){const s=fs(t),i=fs(e);return!s||!i?n<.5?t:e:Ul(s.map((o,r)=>o+(i[r]-o)*n))}const Xv=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),Gv=new Set(["walk","walking","gait"]),Sg=t=>typeof t=="number"?t:void 0,Uv=1.7;function Vv(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 Jv(t){const e=Ae([0,1,0],t);if(e>.999999)return so();if(e<-.999999)return pe(Vt([1,0,0],180));const n=Ks([0,1,0],t);return pe(Vt(n,Math.acos(e)*180/Math.PI))}function Zv(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=(k,y,x)=>u.push({mesh:k,world:Rt(i,y),material:x}),f=(k,y,x)=>d(e.sphere,wa(k,[0,0,0,1],[y,y,y]),x);for(const k of n.chains){const y=s.chains[k.id],x=k.id==="spine"?1.9:1;k.bones.forEach((P,M)=>{const T=y[M],S=y[M+1],E=Xs(T,S),[$,A]=P.width??[1,1],I=h*x*($+A)/2;if(E>1e-6){const C=gn(T,S,.5),D=Jv(Jt(se(S,T)));d(e.cylinder,Rt(pn(C),Rt(D,mn([I,E,I]))),a)}f(T,h*x*$,a),f(S,h*x*A,a)}),k.id.startsWith("arm.")&&f(y[y.length-1],h*1.5,l)}const{center:p,rx:g,ry:m,axes:w}=s.head,v=[...w[0],0,...w[1],0,...w[2],0,...p,1];d(e.sphere,Rt(v,mn([g,m,g])),l);for(const k of[-1,1]){const y=Jt([k*.36,.15,.92]),x=Ys(p,Ys(Ys(fn(w[0],y[0]*g*1.04),fn(w[1],y[1]*m*1.04)),fn(w[2],y[2]*g*1.04))),P=[...w[0],0,...w[1],0,...w[2],0,...x,1];d(e.sphere,Rt(P,mn([g*.11,m*.14,g*.03])),c)}return u}const Qv={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:us({...t.character,height:1}),cylinder:ir(pg(1,1,16)),sphere:ir(Wv(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={...lt,...l.pose};for(const[T,S]of n)typeof S=="number"&&!Xv.has(T)&&!Gv.has(T)&&(u[T]=S);const d=Math.max(0,Math.min(1,Sg(n.get("walking"))??l.walking??0));if(d>0){const T=typeof n.get("gait")=="string"?n.get("gait"):l.gait,S=Ko(T,Sg(n.get("walk"))??0,u);u=Object.fromEntries(Object.keys({...u,...S}).map(E=>[E,(u[E]??0)+((S[E]??0)-(u[E]??0))*d]))}const f=l.height??Uv,p=Rt(i.view,s),g={toView:T=>ie(p,T),toScreen:T=>a(T)},w=-g.toView([0,f/2,0])[2];if(w<=i.near)return null;const v=l.shadow===!1?[]:[{depth:w+f,draw:T=>Vv(T,g,f*.18)}];if(l.look==="solid"){const T=Ue(h.plan,u,{height:f,contact:h.contact});return{meshes:Zv(l,c,h.plan,T,s),drawables:v}}const k=ie(s,[0,f*.6,0]),y=Jt(se(i.position,k)),x=mg(k,y,o).map(T=>Math.min(1,T));let P=h;if(o.length>0&&h.skin!=="none"){const T=Vl(h.skin,x,yg(r,Xs(k,i.position)),r?.color);P={...h,skin:T,...h.body?{body:{...h.body,fill:T}}:{}}}const M=ng(P,u,g,{height:f});return{drawables:[...v,...M.map((T,S)=>({depth:-(T.sortDepth??T.depth)-S*1e-6,draw:(E,$)=>T.draw(E,$.time)}))]}}},Ze={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}},bi=1,ar=.55,xg=.35,tM=1.6,Tg={a:"a",e:"e",i:"i",y:"i",o:"o",u:"u"},Eg={m:"m",b:"m",p:"m",f:"f",v:"f",w:"u",q:"u",l:"l",n:"l",d:"l",t:"l"},Ag={अ:"a",आ:"a",इ:"i",ई:"i",उ:"u",ऊ:"u",ऋ:"i",ए:"e",ऐ:"e",ओ:"o",औ:"o",ऍ:"e",ऑ:"o"},$g={"ा":"a","ि":"i","ी":"i","ु":"u","ू":"u","ृ":"i","े":"e","ै":"e","ो":"o","ौ":"o","ॅ":"e","ॉ":"o"},eM={प:"m",फ:"m",ब:"m",भ:"m",म:"m",व:"u"},nM="्",Pg="़",sM=t=>t>="क"&&t<="ह",Ig=new Set([".",",","!","?",";",":","…","।","॥","—","-"]);function Og(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(Ig.has(o))s("rest",tM);else if(/\s/.test(o)){const a=e[e.length-1];a&&a.viseme!=="rest"&&e.push({viseme:"c",weight:xg})}else if((o==="o"||o==="e")&&r===o)s(o==="o"?"u":"i",bi),i++;else if(o in Tg)s(Tg[o],bi);else if(o in Eg)s(Eg[o],ar);else{if(o==="h")continue;if(/[a-z]/.test(o))s("c",ar);else if(o in Ag)s(Ag[o],bi);else if(sM(o)){const a=r===Pg?o==="फ"?"f":void 0:eM[o];s(a??"c",ar);let l=i+1;n[l]===Pg&&l++;const c=n[l];c===nM?i=l:c&&c in $g?(s($g[c],bi),i=l):(!c||/\s/.test(c)||Ig.has(c)||s("a",bi*.6),i=l-1)}else(o==="ं"||o==="ँ")&&s("l",ar*.6)}}for(;e.length>0&&(e[e.length-1].viseme==="rest"||e[e.length-1].weight===xg);)e.pop();return e}function Zl(t,e={}){const n=e.fields?.mouth??"mouth",s=e.fields?.mouthWidth??"mouthWidth",i=e.energy??1,o=Og(t.text),r=[{time:t.start,value:Ze.rest.mouth}],a=[{time:t.start,value:Ze.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 p=Ze[u.viseme];r.push({time:f,value:p.mouth*i,easing:"ease-out"}),a.push({time:f,value:1+(p.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:Ze.rest.mouth,easing:"ease-in-out"}),a.push({time:t.end,value:Ze.rest.mouthWidth,easing:"ease-in-out"})),{[n]:r,[s]:a}}function iM(t,e,n={}){const s={};for(const i of[...e].sort((o,r)=>o.start-r.start))for(const[o,r]of Object.entries(Zl(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 lr(t,e,n,s={}){if(n.length===0)return e;const i=s.fields?.mouth??"mouth",o=s.fields?.mouthWidth??"mouthWidth",r={[i]:Ze.rest.mouth,[o]:Ze.rest.mouthWidth,...s.rest},a=new Ht({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(p=>p.target===t&&p.property===u);let f=d?[...d.keyframes]:[{time:0,value:l(u,0)}];for(const p of n){const g=Zl(p,s)[u];g[0]={...g[0],value:l(u,p.start)},g[g.length-1]={...g[g.length-1],value:l(u,p.end)},f=[...f.filter(m=>m.time<p.start||m.time>p.end),...g],f.sort((m,w)=>m.time-w.time)}h.push({id:d?.id??`${t}-${u}`,target:t,property:u,keyframes:f})}return h}const wi=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function _g([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 gs=(t,[e,n,s])=>t==="z"?[e,n,s]:t==="x"?[s,n,e]:[e,s,n];function Cg(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(gs(n,[Math.cos(u)*t,Math.sin(u)*t,c]))}const a=[{corners:Array.from({length:s},(c,h)=>s-1-h),normal:gs(n,[0,0,-1])},{corners:Array.from({length:s},(c,h)=>s+h),normal:gs(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:gs(n,[Math.cos(u),Math.sin(u),0])})}const l=[];if(i>0)for(const c of[-r,r]){const h=o.push(gs(n,[0,0,c*1.01]))-1;for(let u=0;u<i;u++){const d=Math.PI*2*u/i,f=o.push(gs(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 Hg([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 wi([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 p=[a(f,h),a(f,h+1),a(f+1,h+1),a(f+1,h)];c.push({corners:p,normal:l(p)})}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 oM=t=>t.reduce((e,[n,s],i)=>{const[o,r]=t[(i+1)%t.length];return e+n*r-o*s},0)/2;function Rg(t,e){const n=oM(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:wi([0,-c,h])})}return{vertices:o,faces:r,creases:!0}}function Lg(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 Fg(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=wi([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=wi(Ng(h,u)),f=Ng(d,h);for(let p=0;p<n;p++){const g=Math.PI*2*p/n,m=Math.cos(g)*s(a),w=Math.sin(g)*s(a);i.push([r[0]+d[0]*m+f[0]*w,r[1]+d[1]*m+f[1]*w,r[2]+d[2]*m+f[2]*w])}});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:wi([h[0]-u[0],h[1]-u[1],h[2]-u[2]])})}return{vertices:i,faces:o,creases:!1}}function Ng(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 Wg(t){switch(t.type){case"box":return _g(t.size);case"cylinder":return Cg(t.radius,t.length,t.axis,t.segments,t.spokes);case"ellipsoid":return Hg(t.radii,t.segments);case"extrude":return Rg(t.profile,t.width);case"panel":return Lg(t.points,t.facing);case"tube":return{...Fg(t.points,t.radius,t.segments),joined:t.joined}}}function Ql(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],p=c[d],g=h[d],m=u[d];return .5*(2*p+(-f+g)*a+(2*f-5*p+4*g-m)*a*a+(-f+3*p-3*g+m)*a*a*a)})};return Array.from({length:e},(i,o)=>s(o/(e-1)))}const Pn=t=>Array.isArray(t)&&t.length===2&&t.every(e=>typeof e=="number"&&Number.isFinite(e));function cr(t,e){return((e-t)%360+540)%360-180}function Dg(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 ps(t,e){return Math.atan2(e[0]-t[0],e[1]-t[1])*180/Math.PI}function Bg(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:Ql(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 zg(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 qg(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 ki=520,tc=["do","at","for","to","through","toward","speed","pose","gag","say","look","turns","dance","bpm","beats"],jg=t=>Math.max(700,Array.from(t).length*65),Yg=70,Kg=35;function ec(t,e){const n=e[0]-t.x,s=e[1]-t.eyeHeight,i=e[2]-t.z,o=t.heading*Math.PI/180,r=n*Math.cos(o)-i*Math.sin(o),a=n*Math.sin(o)+i*Math.cos(o),l=Math.atan2(r,a)*180/Math.PI,c=Math.hypot(r,a),h=-Math.atan2(s,c)*180/Math.PI,u=Math.max(-Yg,Math.min(Yg,l*.75)),d=Math.max(-Kg,Math.min(Kg,h*.7));return{"head.turn":u,"head.nod":d,lookX:Math.max(-1,Math.min(1,(l-u)/45)),lookY:Math.max(-1,Math.min(1,(h-d)/30))}}const Xg={walk:1.3,bouncy:1.4,doubleBounce:1.2,sneak:.6,strut:1.2,tired:.8,run:3.6,shove:.7},nc=Object.keys(Yt),sc=Object.keys(ye),ic=Object.keys(Go),rM=.25,aM=700/180,lM=200,cM=300;function Gg(t){if(!Array.isArray(t))return[{beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const e=[...nc,"face","spin","dance","hold","pose","gag","place","say","look"],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))tc.includes(c)||o(ft("beat field",c,tc,a[c]));const l=typeof r.do=="string"?sc.includes(r.do)?"pose":ic.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));for(const c of["at","for","turns","bpm","beats"]){const h=r[c];h!==void 0&&(typeof h!="number"||!Number.isFinite(h)||(c==="at"?h<0:c!=="turns"&&h<=0))&&o(`\`${c}\` must be finite${c==="turns"?"":c==="at"?" and non-negative":" and positive"}.`)}if(r.do==="dance"&&!(typeof r.dance=="string"&&Object.hasOwn(Sn,r.dance))&&o(ft("native dance",r.dance,Object.keys(Sn))),nc.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&&!Pn(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(Pn))&&o("`through` is a list of points on the ground, each [x, z] metres.")),r.do==="place"&&!Pn(r.to)&&o("`place` needs `to`: a point on the ground, [x, z] metres."),r.do==="face"&&!(Pn(r.toward)||typeof r.toward=="number"&&Number.isFinite(r.toward))&&o("`face` needs `toward`: a point [x, z] or a finite heading in degrees."),r.do==="say"&&!(typeof r.say=="string"&&r.say.trim().length>0)&&o("`say` needs `say`: the line spoken."),r.do==="look"){const c=r.look??r.toward;Array.isArray(c)&&(c.length===2||c.length===3)&&c.every(u=>typeof u=="number"&&Number.isFinite(u))||c==="camera"||o("`look` needs `look`: a point [x, z] or [x, y, z] to look at, or `camera`.")}r.do==="pose"&&!(typeof r.pose=="object"&&r.pose!==null)&&!sc.includes(r.pose)&&o(ft("pose",r.pose,sc)),r.do==="gag"&&!ic.includes(r.gag)&&o(ft("gag",r.gag,ic))}),n}function hM(t,e,n){const s=Gg(e);if(s.length>0)throw new Error(`characterScript3D: ${s.length} problem(s) in the beats:
53
+ `;function x2(t){if(t.getElementById(_u))return;const e=t.createElement("style");e.id=_u,e.textContent=S2,t.head.appendChild(e)}function Cu(t,e){const n=Array.from(e.querySelectorAll("[data-tinyfly-choose]"));if(n.length===0)return()=>{};x2(e.ownerDocument);const s=[],i=[];for(const a of n){const l=a.getAttribute("data-tinyfly-choose")??"",c=[],h=(p,g)=>{a.hasAttribute(p)||(a.setAttribute(p,g),c.push(p))};h("role","button"),h("tabindex","0");const u=t.scenarios.find(p=>p.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=p=>{const g=p.key;g!=="Enter"&&g!==" "||(p.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 fo=new WeakMap,Ya=new WeakMap;let T2=0;function ei(t,e,n){if(t)try{return JSON.parse(t)}catch(s){console.warn(`tinyfly: invalid ${e} JSON on`,n,s);return}}async function Hu(t,e={}){const n=fo.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=A2(t.getAttribute("data-markers")),a=s.length>1||i?.hasAttribute("data-scenario")?E2(s,r,t):void 0;if(a&&a.length===0)return;let l=i&&!a?ei(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=Ru(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=ei(t.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",t),h={playWhenVisible:!0,...e.player,...c&&{captions:c},...ei(t.getAttribute("data-options"),"data-options",t)};P2(t);const u=new uo(t,h),d={element:t,player:u};if(fo.set(t,d),t.setAttribute("data-tinyfly-mounted",""),a){const f=t.getAttribute("data-scenario")??void 0;await u.loadScenarios(a,{initial:a.some(p=>p.id===f)?f:void 0}),Ya.set(t,Cu(u,t))}else await u.load(l??o);if(t.getAttribute("data-controls")!=="false"){const f=ei(t.getAttribute("data-labels"),"data-labels",t),p=t.querySelector("figcaption"),g=t.getAttribute("data-scenario-legend"),m=t.getAttribute("data-scenario-control");d.controls=Ou(u,t,{...e.controls,...t.getAttribute("data-fullscreen")==="true"?{fullscreen:!0}:{},...m==="slider"||m==="buttons"?{scenarioControl:m}:{},labels:{...e.controls?.labels,...f,...g?{scenario:g}:{}},mount:void 0}),p?t.insertBefore(d.controls.element,p):t.appendChild(d.controls.element)}return d}function E2(t,e,n){const s=[];return t.forEach((i,o)=>{const r=ei(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?Ru(r,e):r})}),s}function Ru(t,e){return t.config.markers?.length?t:{...t,config:{...t.config,markers:e.map((n,s)=>({id:`step-${s+1}`,time:n}))}}}function A2(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 Lu(t=document,e={}){const n=Array.from(t.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(n.map(i=>Hu(i,e)))).filter(i=>i!==void 0)}function $2(t){const e=fo.get(t);e&&(Ya.get(t)?.(),Ya.delete(t),e.controls?.destroy(),e.player.destroy(),fo.delete(t),t.removeAttribute("data-tinyfly-mounted"))}function P2(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-${++T2}`,e.setAttribute("aria-labelledby",s.id))}function I2(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const e=()=>{Lu()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}class Fu{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 bn,this.adapterB=new bn}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 bn;i.querySelectorAll("[data-tinyfly]").forEach(l=>{const c=l.getAttribute("data-tinyfly");c&&a.registerTarget(c,l)}),s.push({adapter:a,timeline:jn(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?jn(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 O2(t,e,n={}){const s=new Fu(t,{...n,autoplay:!0});return await s.load(e),s}const _2={type:"none",duration:0},Lt=t=>({description:t,unit:"degrees"}),At=(t,e=0,n=1)=>({description:t,unit:`${e}..${n}`,min:e,max:n}),Nu={lean:Lt("Upper body tipped about the hips (+ toward the way it faces)"),bend:Lt("Line of action: the spine curved (+ curls forward, − arches back)"),headTilt:Lt("Head tilt"),leftShoulder:Lt("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:Lt("Right upper arm: 0 hangs down, 90 straight out (forward, in profile), 180 straight up"),leftElbow:Lt("Left elbow bend, added to the upper arm"),rightElbow:Lt("Right elbow bend, added to the upper arm"),leftHip:Lt("Left thigh: 0 straight down; in profile negative is forward"),rightHip:Lt("Right thigh: 0 straight down; in profile positive is forward"),leftKnee:Lt("Left knee bend (negative folds the shin back)"),rightKnee:Lt("Right knee bend (positive folds the shin back)"),leftWrist:Lt("Left wrist bend, added to the forearm"),rightWrist:Lt("Right wrist bend, added to the forearm"),leftAnkle:Lt("Left ankle: + points the toe down (tiptoe), − onto the heel"),rightAnkle:Lt("Right ankle: + points the toe down (tiptoe), − onto the heel"),leftFootOut:At("Left foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),rightFootOut:At("Right foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),mouth:At("Mouth open: 0 closed, 1 wide open"),smile:At("−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:At("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:At("Left eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),rightBrow:At("Right eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),browTilt:At("Eyebrow slant: −1 angry, 1 worried",-1,1),lookX:At("Eyes look across: + the way it faces",-1,1),lookY:At("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:At("0 front-on, 1 in profile, turned the way it faces"),sit:At("0 standing, 1 seated"),spin:Lt("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"}},Wu={walk:{description:"Walk-cycle phase, in strides: animate 0 → n for n strides",unit:"strides"},walking:At("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:At("How much the mouth chatters"),rubber:At("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:At("How much of the dance is applied")},Du={"thumb.curl":At("Thumb curled in"),"thumb.across":At("Thumb across the palm"),"index.curl":At("Index finger curled"),"middle.curl":At("Middle finger curled"),"ring.curl":At("Ring finger curled"),"pinky.curl":At("Little finger curled"),spread:At("Fingers spread apart"),turn:Lt("Hand turned about the forearm"),bend:Lt("Hand bent at the wrist, palm-ward"),tilt:Lt("Hand tilted sideways"),roll:Lt("Hand rolled to show the back or the palm")};let Bu;function C2(t){Bu=t}function H2(t){return Bu?.(t)??{}}function zu(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 Vn(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=zu(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 go(t,e){const n=Vn(t,e);return n[n.length-1]}function Ka(t,e){return e>0?Math.floor(Math.max(0,t)*e/1e3):0}function po(t,e,n){const s=e.roughness??2,i=Math.max(1,Math.round(e.passes??2)),o=Ka(n,e.boil??8);let r=0;const a=()=>{const d=r++;return f=>je(ne(`${e.seed??1}:${o}:${d}:${f}`))},l=(d,f)=>(d.next()*2-1)*f,c=d=>{const f=a(),p=t.lineWidth,g=t.globalAlpha;for(let m=0;m<i;m++)t.lineWidth=m===0?p:p*.55,t.globalAlpha=m===0?g:g*.6,d(f(m));t.lineWidth=p,t.globalAlpha=g},h=(d,f=1)=>{if(d.length<2)return;const p=d.slice(1).map((m,w)=>Math.hypot(m.x-d[w].x,m.y-d[w].y)),g=p.reduce((m,w)=>m+w,0)*Math.min(1,Math.max(0,f));c(m=>{const w=[],v=[];if(d.forEach((y,x)=>{w.push({x:y.x+l(m,s*.5),y:y.y+l(m,s*.5)}),x>0&&v.push([m.next()*2-1,m.next()*2-1])}),g<=0)return;t.beginPath(),t.moveTo(w[0].x,w[0].y);let k=0;for(let y=1;y<w.length;y++){const x=R2(w[y-1],w[y],s,v[y-1]),P=p[y-1];if(k+P<=g){t.bezierCurveTo(x[1].x,x[1].y,x[2].x,x[2].y,x[3].x,x[3].y),k+=P;continue}const M=L2(x,P===0?1:(g-k)/P);t.bezierCurveTo(M[1].x,M[1].y,M[2].x,M[2].y,M[3].x,M[3].y);break}t.stroke()})},u=(d,f,p,g,m=1)=>{c(w=>{const k=w.next()*Math.PI*2,y=Math.PI*2+.15+w.next()*.3,x=[];for(let M=0;M<=14;M++){const T=k+y*M/14,S=l(w,s*.6);x.push({x:d+Math.cos(T)*(p+S),y:f+Math.sin(T)*(g+S)})}const P=Vn(x,m);P.length<2||(qu(t,P),t.stroke())})};return{line:h,curve(d,f=1){if(d.length<2)return;const p=d[0],g=d[d.length-1],m=Math.hypot(g.x-p.x,g.y-p.y)||1,w=-(g.y-p.y)/m,v=(g.x-p.x)/m;c(k=>{const y={x:l(k,s*.5),y:l(k,s*.5)},x={x:l(k,s*.5),y:l(k,s*.5)},P=l(k,s*Math.min(1.5,Math.max(.3,m/80))),M=d.map((S,E)=>{const $=E/(d.length-1),A=Math.sin(Math.PI*$)*P;return{x:S.x+y.x+(x.x-y.x)*$+w*A,y:S.y+y.y+(x.y-y.y)*$+v*A}}),T=Vn(M,f);T.length<2||(qu(t,T),t.stroke())})},circle(d,f,p,g=1){u(d,f,p,p,g)},ellipse:u,nudge(d=.5){const f=a()(0);return{x:l(f,s*d),y:l(f,s*d)}}}}function R2(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 L2([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 qu(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 zt(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,p=(h.x-c.x)/u*d;i.push({x:a.x+f,y:a.y+p}),o.push({x:a.x-f,y:a.y-p})}),[...i,...o.reverse()]}function mo(t,e,n,s){const i=e.length;if(i<2)return;const o=zt(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 wn(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 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,u)=>{const d=o+Math.PI*2*r*u/a,f=Math.cos(d)*n,p=Math.sin(d)*s;return{x:t+f*l-p*c,y:e+f*c+p*l}})}function ni(t,e){return e.look==="pencil"?W2(t,e):ju(t,e.ink,e.look)}function bo(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 si(t,e){return e.look==="silhouette"?ju(t,e.ink,"silhouette",!1):e}function ju(t,e,n,s=!0){const i=n==="silhouette",o=i?1.25:1;return{look:n,ink:e,limb(r,a,l){t.fillStyle=e,mo(t,r,a*o,l*o)},line(r,a){r.length<2||(t.strokeStyle=e,t.lineWidth=a*o,t.lineCap="round",t.lineJoin="round",bo(t,r),t.stroke())},shape(r,a,l){bo(t,r,!0),(a!==null||i&&s)&&(t.fillStyle=i?e:a,t.fill()),!(l<=0)&&(t.strokeStyle=e,t.lineWidth=l*o,t.lineJoin="round",t.stroke())},ellipse(r,a,l,c,h,u,d){t.beginPath(),t.ellipse(r,a,l,c,h,0,Math.PI*2),(u!==null||i&&s)&&(t.fillStyle=i?e:u,t.fill()),!(d<=0)&&(t.strokeStyle=e,t.lineWidth=d*o,t.stroke())},dot(r,a,l){t.fillStyle=e,t.beginPath(),t.arc(r,a,l*o,0,Math.PI*2),t.fill()},guide(){},guideEllipse(){}}}function F2(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 N2(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 Yu(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 W2(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=Ka(e.time,n.boil??8);let c=0;const h=(p,g,m=!1)=>je(ne(`${e.seed}:${m?"paper":l}:${p}:${g}`)),u=(p,g,m,w,v,k=0)=>{if(p.length<2)return;const y=p.slice(1).reduce(($,A,I)=>$+Math.hypot(A.x-p[I].x,A.y-p[I].y),0);let x=F2(p,Math.max(1.5,Math.min(e.lineWidth*.8,y/24)));if(k>0&&x.length>=2){const[$,A]=[x[x.length-2],x[x.length-1]],I=Math.hypot(A.x-$.x,A.y-$.y)||1;x=[...x,{x:A.x+(A.x-$.x)/I*k,y:A.y+(A.y-$.y)/I*k}]}const P=Yu(m),M=Yu(m),T=x.length,S=[],E=[];x.forEach(($,A)=>{const I=T===1?0:A/(T-1),C=x[Math.max(0,A-1)],D=x[Math.min(T-1,A+1)],j=Math.hypot(D.x-C.x,D.y-C.y)||1,V=-(D.y-C.y)/j,et=(D.x-C.x)/j,G=P(I)*v,F=Math.min(1,I/.08,(1-I)/.08),H=(.55+.45*Math.sqrt(Math.max(0,F)))*(1+r*M(I)),W=Math.max(.3,g(I)*H/2),_=$.x+V*G,B=$.y+et*G;S.push({x:_+V*W,y:B+et*W}),E.push({x:_-V*W,y:B-et*W})}),t.save(),t.globalAlpha*=w,t.fillStyle=s,bo(t,[...S,...E.reverse()],!0),t.fill(),t.restore()},d=(p,g)=>{const m=c++,w=h(m,99,!0);if(w.next()<a){const x=(w.next()*2-1)*e.lineWidth*1.4,P=(w.next()*2-1)*e.lineWidth*1.4,M=p.map(T=>({x:T.x+x,y:T.y+P}));u(M,T=>g(T)*1.8,h(m,98,!0),.035,i),u(M,T=>g(T)*.45,h(m,97,!0),.12,i*1.5)}const v=p.slice(1).reduce((x,P,M)=>x+Math.hypot(P.x-p[M].x,P.y-p[M].y),0),k=g(.5)>4&&v>g(.5)*6,y=k?[-.3,.3,0]:[0];for(let x=0;x<o;x++){const P=x===0;y.forEach((M,T)=>{const S=h(m,x*10+T),E=M===0?p:N2(p,A=>g(A)*M*Math.sqrt(Math.sin(Math.PI*A))),$=!P&&M===0?e.lineWidth*(.3+S.next()*.8):0;u(E,A=>g(A)*(k?.5:1)*(P?1:.6),S,P?.85:.45,i*(P?.6:1),$)})}},f=(p,g,m,w,v,k)=>{const x=h(c,50).next()*Math.PI*2;d(yo(p,g,m,w,v,x,1.08,48),()=>k)};return{look:"pencil",ink:s,limb(p,g,m){d(p,w=>g+(m-g)*w)},line(p,g){d(p,()=>g)},shape(p,g,m){g!==null&&(t.save(),t.globalAlpha*=.88,t.fillStyle=g,bo(t,p,!0),t.fill(),t.restore()),m>0&&d([...p,p[0]],()=>m)},ellipse(p,g,m,w,v,k,y){k!==null&&(t.save(),t.globalAlpha*=.9,t.fillStyle=k,t.beginPath(),t.ellipse(p,g,m,w,v,0,Math.PI*2),t.fill(),t.restore()),f(p,g,m,w,v,y)},dot(p,g,m){t.save(),t.globalAlpha*=.9,t.fillStyle=s,t.beginPath(),t.arc(p,g,m,0,Math.PI*2),t.fill(),t.restore()},guide(p){if(n.construction===!1||p.length<2)return;const g=c++;u(p,()=>Math.max(.6,e.lineWidth*.18),h(g,0),.28,i*1.2,e.lineWidth)},guideEllipse(p,g,m,w,v){if(n.construction===!1)return;const k=c++,y=h(k,0),x=yo(p,g,m,w,v,y.next()*Math.PI*2,1.12,48);u(x,()=>Math.max(.6,e.lineWidth*.18),y,.28,i*1.5)}}}const Ku=["thumb","index","middle","ring","pinky"],Ot={"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 Nt(t={}){return{...Ot,...t}}const re=(t,e,n,s,i)=>({"thumb.curl":t,"index.curl":e,"middle.curl":n,"ring.curl":s,"pinky.curl":i}),St={relaxed:Ot,open:Nt({...re(0,0,0,0,0),"thumb.across":0,spread:.55}),spread:Nt({...re(0,0,0,0,0),"thumb.across":0,spread:1}),flat:Nt({...re(0,0,0,0,0),"thumb.across":.35,spread:0}),fist:Nt({...re(.7,1,1,1,1),"thumb.across":.9,spread:0}),point:Nt({...re(.75,0,1,1,1),"thumb.across":.9,spread:0}),thumbsUp:Nt({...re(0,1,1,1,1),"thumb.across":0,spread:0,roll:70}),peace:Nt({...re(.75,0,0,1,1),"thumb.across":.9,spread:1}),ok:Nt({...re(.12,.6,.1,.15,.2),"thumb.across":.55,spread:.6}),pinch:Nt({...re(.1,.65,.75,.85,.9),"thumb.across":.55,spread:0}),cupped:Nt({...re(.25,.4,.4,.4,.4),"thumb.across":.4,spread:.05,turn:2}),wave:Nt({...re(0,.05,.05,.1,.12),"thumb.across":0,spread:.7,turn:2}),pencilGrip:Nt({...re(.1,.6,.72,.88,.95),"thumb.across":.5,spread:0,turn:.8,bend:10}),hold:Nt({...re(.5,.7,.72,.74,.76),"thumb.across":.75,spread:0,turn:1})};function Jn(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 D2={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}},B2={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}},Pe={base:[-.11,.1,-.05],bones:[.2,.15,.12],widths:[.2,.145,.135],out:[-.7,.68,-.22],across:[.35,.5,-.8]},z2=[82,100,62],q2=[48,72],j2=3,Y2=13,K2=.035,X2=-.075,G2=[[-.17,0],[-.215,.12],[-.235,.26],[-.225,.4],[-.185,.49],[-.075,.525],[.05,.51],[.16,.465],[.215,.4],[.225,.26],[.2,.1],[.16,0]],Ye=t=>t*Math.PI/180,Xa=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],wo=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],Ga=(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]],ii=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function Ke(t,e,n){const s=Math.cos(n),i=Math.sin(n),o=Ga(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 Xu=[1,0,0],Gu=[0,1,0],oi=[0,0,1];function U2(t,e,n){const s=Ye(t.fan*(j2+Y2*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+=Ye(z2[u]*e),r.push(Xa(r[u],wo(Ke(i,o,-a),h)))});const l=Ke(oi,o,-a),c=r.map((h,u)=>t.width*(1-.14*(u/(r.length-1))));return{joints:r,back:l,widths:c}}function V2(t,e,n=1,s=1){const i=Math.min(1,Math.max(0,e)),o=ii(Xa(wo(ii(Pe.out),1-i),wo(ii(Pe.across),i))),r=ii(Ga(oi,o)),a=ii(Ga(o,r)),l=[[Pe.base[0]*s,Pe.base[1],Pe.base[2]]];let c=0;Pe.bones.forEach((d,f)=>{f>0&&(c+=Ye(q2[f-1]*t)),l.push(Xa(l[f],wo(Ke(o,r,c),d)))});const h=Ke(a,r,c),u=[...Pe.widths,Pe.widths[Pe.widths.length-1]*.92].map(d=>d*n);return{joints:l,back:h,widths:u}}function ko(t,e={}){const n={...Ot,...t},s=e.size??100,i=e.side??"right",o=i==="left"?-1:1,r=Ye(e.angle??0),a=e.fingers===4,l=Math.max(.5,e.plump??1),c=1+(l-1)*.7,h=A=>({...A,knuckle:[A.knuckle[0]*c,A.knuckle[1],A.knuckle[2]],width:A.width*l}),u=Ye(n.bend??0),d=Ye(n.tilt??0),f=Ye(90*(n.turn??0)),p=A=>Ke(Ke(Ke(A,Xu,-u),oi,-d),Gu,f),g=Math.cos(r),m=Math.sin(r),w=Ye(n.roll??0),v=Math.cos(w),k=Math.sin(w),y=A=>{const I=A[0]*s,C=-A[1]*s,D=(I*v-C*k)*o,j=I*k+C*v;return{x:D*g-j*m,y:D*m+j*g}},x=A=>{const I=y(A),C=Math.hypot(I.x,I.y);return C>1e-6*s?{x:I.x/C,y:I.y/C}:{x:0,y:0}},P={thumb:V2(n["thumb.curl"]??0,n["thumb.across"]??0,l,c)},M=a?B2:D2;for(const A of Ku){const I=M[A];I&&(P[A]=U2(h(I),n[`${A}.curl`]??0,n.spread??0))}const T={};for(const[A,I]of Object.entries(P)){const C=I.joints.map(p),D=p(I.back);T[A]={points:C.map(y),depths:C.map(j=>j[2]*s),widths:I.widths.map(j=>j*s),nail:D[2],back:x(D)}}const S=G2.flatMap(([A,I])=>[p([A*c,I,K2]),p([A*c,I,X2])]),E=J2(S.map(y)),$=S.reduce((A,I)=>A+I[2],0)/S.length*s;return{size:s,side:i,wrist:{x:0,y:0},palm:E,palmDepth:$,palmFacing:-p(oi)[2],fingers:T,axes:{up:x(p(Gu)),across:x(p(Xu)),out:x(p(oi))},curls:Object.fromEntries(Object.keys(T).map(A=>[A,n[`${A}.curl`]??0]))}}function Uu(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 J2(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)]}function Vu(t,e,n,s){if(s.mode!=="cel"||e.length<3)return;const i=Math.hypot(...s.light),o=e.map(a=>{const l=a.x-n.x,c=a.y-n.y,h=(l*s.light[0]+c*s.light[1])/((Math.hypot(l,c)||1)*i),u=Math.max(0,-h)*.24;return{x:a.x-l*u,y:a.y-c*u}}),r=a=>{t.beginPath(),t.moveTo(a[0].x,a[0].y);for(const l of a.slice(1))t.lineTo(l.x,l.y);t.closePath()};t.save(),r(e),t.clip(),r([...e,...o.reverse()]),t.globalAlpha*=s.opacity,t.fillStyle=s.shadow,t.fill(),t.restore()}const Z2="#f1c9a5",Q2="#2f2f33";function vo(t,e,n,s={},i=0){const o=Uu(ko(n,s),e),r=s.ink??Q2,a=s.lineWidth??o.size*.035;let l=s.pen??ni(t,{look:s.look??"clean",ink:r,lineWidth:a,seed:s.seed??1,time:i,pencil:{construction:!1,...s.pencil}});const c=s.skin??Z2;c==="none"&&(l=si(t,l));const h=s.nails??!0,u=[{depth:o.palmDepth,draw:()=>tk(t,l,o,c,a,s)}];for(const d of Object.values(o.fingers)){const f=d.depths.reduce((p,g)=>p+g,0)/d.depths.length;u.push({depth:f,draw:()=>ek(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,p)=>f.depth-p.depth))d.draw();return t.restore(),o}function tk(t,e,n,s,i,o){if(e.shape(n.palm,s==="none"?null:s,o.connected?0:i),s!=="none"&&o.shading&&e.look==="clean"){const r=n.palm.reduce((a,l)=>({x:a.x+l.x/n.palm.length,y:a.y+l.y/n.palm.length}),{x:0,y:0});Vu(t,n.palm,r,o.shading)}if(o.connected&&i>0&&(e.look!=="silhouette"||s==="none")){const{up:r}=n.axes;let a=[];for(let l=0;l<=n.palm.length;l++){const c=n.palm[l%n.palm.length],h=n.palm[(l+1)%n.palm.length];((c.x+h.x)/2-n.wrist.x)*r.x+((c.y+h.y)/2-n.wrist.y)*r.y<n.size*.08?(a.length>1&&e.line(a,i),a=[]):(a.length===0&&a.push(c),a.push(h))}a.length>1&&e.line(a,i)}if(n.palmFacing<-.3&&e.look!=="silhouette"){const{up:r}=n.axes;for(const[a,l]of Object.entries(n.fingers)){const c=n.curls[a]??0;if(a==="thumb"||c<.5)continue;const h=l.points[0],u=l.widths[0]*.42,d={x:h.x-r.x*u*.2,y:h.y-r.y*u*.2},f=Math.atan2(r.y,r.x),p=Array.from({length:7},(g,m)=>{const w=f-Math.PI/2+Math.PI*m/6;return{x:d.x+Math.cos(w)*u,y:d.y+Math.sin(w)*u}});e.line(p,i*.6)}}if(n.palmFacing>.45&&e.look!=="silhouette"){const{up:r,across:a}=n.axes,l=n.size,c=n.wrist,h=(d,f)=>({x:c.x+(a.x*d+r.x*f)*l,y:c.y+(a.y*d+r.y*f)*l}),u=n.side==="left"?-1:1;e.line([h(-.15*u,.36),h(-.04*u,.3),h(.1*u,.33)],i*.5)}}function ek(t,e,n,s,i,o){const{widths:r}=n,a=nk(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"||s==="none"){t.beginPath(),t.rect(l.x-1e5,l.y-1e5,2e5,2e5);const g=h/2+i*1.6;t.moveTo(l.x+g,l.y),t.arc(l.x,l.y,g,0,Math.PI*2),t.clip("evenodd")}if(s==="none"){const g=zt(a,h,u),m=a[a.length-2],w=Math.atan2(c.y-m.y,c.x-m.x),v=Array.from({length:13},(k,y)=>{const x=w+Math.PI/2-y*Math.PI/12;return{x:c.x+Math.cos(x)*u/2,y:c.y+Math.sin(x)*u/2}});e.shape([...g.slice(0,a.length),...v.slice(1),...g.slice(a.length)],null,i)}else e.limb(a,h+2*i,u+2*i);if(t.restore(),s!=="none"&&e.look!=="silhouette"&&(t.fillStyle=s,mo(t,a,h,u)),s==="none"||e.look==="silhouette"||!o||n.nail<.25)return;const d=a[a.length-2],f=sk({x:c.x-d.x,y:c.y-d.y})??{x:0,y:-1},p={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(p.x,p.y,u*.24*Math.max(.35,n.nail),u*.19,Math.atan2(f.y,f.x),"#f8e3d3",i*.45)}function nk(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 sk=t=>{const e=Math.hypot(t.x,t.y);return e>1e-6?{x:t.x/e,y:t.y/e}:null},Yt={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}},ik=40;function ri(t){return t===void 0?Yt.walk:typeof t=="string"?Yt[t]??Yt.walk:t}function Ju(t,e,n=ut,s=1){const i=ri(t);if(i===Yt.walk)return nd(e,n,s);const o=e*Math.PI*2,r=Math.sin(o)*s,a=Math.cos(o)*s,l=w=>Math.abs(w)<=ik,c=i.shoulder??0,h=(w,v)=>l(w)?v*c+i.arm*r:w,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,p=i.bounces??1,g=(1+Math.cos(o*2*p))/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*g,stretch:n.stretch*(1+(i.squash??0)*(g-.5))}}function Mo(t,e,n=1){const s=ri(t),i=Yt.walk.swing,o=r=>Math.sin(r*Math.PI/180);return sd(e,n)*o(s.swing*n)/o(i*n)}const ut={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 Dt(t){return{...ut,...t}}const Zu={mouth:0,smile:0,mouthWidth:1,leftEye:1,rightEye:1,leftBrow:0,rightBrow:0,browTilt:0,lookX:0,lookY:0},qt=t=>({...Zu,...t}),vt={neutral:Zu,happy:qt({smile:.9,leftBrow:.2,rightBrow:.2}),joyful:qt({mouth:.6,smile:1,mouthWidth:1.2,leftEye:0,rightEye:0,leftBrow:.4,rightBrow:.4}),sad:qt({smile:-.8,leftEye:.8,rightEye:.8,browTilt:.9,leftBrow:-.1,rightBrow:-.1,lookY:.6}),crying:qt({mouth:.45,smile:-1,leftEye:0,rightEye:0,browTilt:1,lookY:.4}),surprised:qt({mouth:.7,mouthWidth:.7,leftEye:1.5,rightEye:1.5,leftBrow:1,rightBrow:1}),shocked:qt({mouth:1,mouthWidth:.8,leftEye:1.6,rightEye:1.6,leftBrow:1,rightBrow:1,browTilt:.4}),angry:qt({smile:-.6,mouthWidth:.9,leftEye:.8,rightEye:.8,leftBrow:-.6,rightBrow:-.6,browTilt:-1}),furious:qt({mouth:.5,smile:-1,mouthWidth:1.3,leftEye:.9,rightEye:.9,leftBrow:-.9,rightBrow:-.9,browTilt:-1}),worried:qt({smile:-.3,mouthWidth:.8,leftEye:1.1,rightEye:1.1,leftBrow:.3,rightBrow:.3,browTilt:.8,lookX:-.5}),scared:qt({mouth:.35,smile:-.5,mouthWidth:.8,leftEye:1.45,rightEye:1.45,leftBrow:.8,rightBrow:.8,browTilt:.9}),confused:qt({smile:-.2,mouthWidth:.8,leftEye:.9,rightEye:1.15,leftBrow:-.3,rightBrow:.8,lookX:.5,lookY:-.4}),skeptical:qt({smile:-.1,leftEye:.6,rightEye:1,leftBrow:-.4,rightBrow:.7,lookX:.4}),thinking:qt({smile:0,mouthWidth:.7,leftBrow:.3,rightBrow:.5,lookX:.6,lookY:-.8}),sleepy:qt({smile:.1,leftEye:.25,rightEye:.25,leftBrow:-.3,rightBrow:-.3,lookY:.5}),disgusted:qt({smile:-.7,mouthWidth:.9,leftEye:.6,rightEye:.75,leftBrow:-.5,rightBrow:-.2,browTilt:-.4,lookX:-.6}),smug:qt({smile:.6,mouthWidth:.9,leftEye:.6,rightEye:.6,leftBrow:.1,rightBrow:.5,lookX:.5}),wink:qt({smile:.9,leftEye:0,rightEye:1,leftBrow:-.2,rightBrow:.3})};function Xe(t,e){return{...t,...typeof e=="string"?vt[e]:e}}const ae={rest:ut,wave:Dt({rightShoulder:135,rightElbow:30,headTilt:6,...vt.happy}),cheer:Dt({leftShoulder:125,leftElbow:20,rightShoulder:125,rightElbow:20,...vt.joyful}),shrug:Dt({leftShoulder:30,leftElbow:85,rightShoulder:30,rightElbow:85,headTilt:-10,...vt.confused,lookX:0,lookY:0}),point:Dt({rightShoulder:90,rightElbow:0,lean:4,smile:.4}),think:Dt({rightShoulder:60,rightElbow:150,headTilt:10,...vt.thinking}),handsOnHips:Dt({leftShoulder:45,leftElbow:-100,rightShoulder:45,rightElbow:-100,leftHip:14,rightHip:14,smile:.8}),sad:Dt({leftShoulder:14,rightShoulder:14,leftElbow:-4,rightElbow:-4,headTilt:-14,lean:-3,...vt.sad}),surprised:Dt({leftShoulder:70,leftElbow:60,rightShoulder:70,rightElbow:60,...vt.surprised}),crouch:Dt({stretch:.72,leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50,leftHip:22,rightHip:22,headTilt:-4}),sit:Dt({sit:1,turn:.5,leftShoulder:-25,rightShoulder:25,leftElbow:-55,rightElbow:55}),jump:Dt({stretch:1.22,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4,...vt.joyful}),duck:Dt({stretch:.62,bend:28,headTilt:-8,leftShoulder:150,rightShoulder:150,leftElbow:130,rightElbow:130,leftHip:25,rightHip:25,...vt.scared}),lie:Dt({spin:-90,rise:-.42,leftShoulder:165,rightShoulder:165,leftElbow:150,rightElbow:150,...vt.sleepy}),sideSplit:Dt({leftHip:90,rightHip:90,leftAnkle:-45,rightAnkle:-45,leftShoulder:120,rightShoulder:120,leftElbow:10,rightElbow:10,...vt.happy}),frontSplit:Dt({turn:1,leftHip:-90,rightHip:-90,leftAnkle:-45,rightAnkle:-45,leftShoulder:-150,rightShoulder:150,leftElbow:10,rightElbow:-10,...vt.happy})},Qu=Object.keys(ut);function Zn(t,e,n){const s={...t};for(const i of Qu)s[i]=t[i]+(e[i]-t[i])*n;return s}const Ua=24,td=4,ed=28,ok=40;function nd(t,e=ut,n=1){const s=Math.sin(t*Math.PI*2)*n,i=Math.cos(t*Math.PI*2)*n,o=c=>Math.abs(c)<=ok,r=c=>o(c)?22*s:c,a=o(e.leftShoulder)?e.leftElbow-ed*Math.max(0,-s):e.leftElbow,l=o(e.rightShoulder)?e.rightElbow+ed*Math.max(0,s):e.rightElbow;return{...e,lean:e.lean+td*n,headTilt:e.headTilt-td*.5*n,leftElbow:a,rightElbow:l,leftHip:-Ua*s,rightHip:-Ua*s,leftKnee:-30*Math.max(0,i),rightKnee:30*Math.max(0,-i),leftShoulder:r(e.leftShoulder),rightShoulder:r(e.rightShoulder)}}function sd(t,e=1){return 4*((Va+So)*t)*Math.sin(Ua*e*Math.PI/180)}function id(t){const e=Math.abs(Math.sin(t/65)),n=.55+.45*Math.sin(t/310);return e*n}const od=.12,rd=.46,rk=1-2*od,ak=.1,lk=.21,ck=.19,Va=.24,So=.22,ad=.12,hk=.14,ld=.33,cd=.7,hd=.3,uk=.35,dk=[1.7,1.05],fk=[1.3,.75],ud=[1.45,.85],gk=[1.15,.75],dd=.06,pk=.7,mk=.65,fd=.075,yk=.3,bk=.02,wk=.012,kk=12,vk=.25,xo=90,Mk=.25,Sk=.04,gd=.01,kn=t=>Math.min(1,Math.max(0,t??0));function xk(t,e=1){return So*t*e}const Ja=-.12,pd=.4,he=t=>t*Math.PI/180,Tk=(t,e)=>({x:e*Math.sin(he(t)),y:Math.cos(he(t))}),md=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),yd=(t,e,n,s)=>t-.3*e-n*.14*e-Math.max(0,s-1)*.12*e;function Ek(t,e,n,s,i,o){const r=Math.max(1,Math.min(o*.6,hk*n)),a=kn(e.turn),l=(ad+ld*a)*n,c=s+Ja*n,h=l+e.lookX*.08*n,u=e.lookY*.07*n,d=[{x:-.34*n*(1-cd*a),squeeze:1-cd*a,open:e.leftEye,brow:e.leftBrow,side:-1},{x:.34*n*(1-hd*a),squeeze:1-hd*a,open:e.rightEye,brow:e.rightBrow,side:1}];t.fillStyle=i,t.strokeStyle=i,t.lineWidth=r;for(const w of d){const v=md(w.open,e.blink);if(v<.2){const P=e.smile>.5?-.12*n:.06*n;t.beginPath(),t.moveTo(w.x+l-.12*n,c),t.quadraticCurveTo(w.x+l,c+P,w.x+l+.12*n,c),t.stroke()}else{if(v>1.2){const M=.13*n*v;t.beginPath(),t.ellipse(w.x+l,c,M*.85,M,0,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.stroke(),t.fillStyle=i}const P=v>1.2?.075*n:.1*n;t.beginPath(),t.ellipse(w.x+h,c+u,P,P*1.1*Math.min(v,1),0,0,Math.PI*2),t.fill()}const k=yd(c,n,w.brow,v),y=w.x+l-w.side*.13*n*w.squeeze,x=w.x+l+w.side*.13*n*w.squeeze;t.beginPath(),t.moveTo(x,k),t.lineTo(y,k-e.browTilt*.1*n),t.stroke()}const f=s+pd*n,p=.25*n*Math.max(.3,e.mouthWidth)*(1-uk*a),g=Math.min(1,Math.max(0,e.mouth));if(t.beginPath(),g<=.05){t.moveTo(l-p,f),t.quadraticCurveTo(l,f+e.smile*.25*n,l+p,f),t.stroke();return}const m=.3*n*g;e.smile>.3?(t.moveTo(l-p,f-.05*n),t.lineTo(l+p,f-.05*n),t.quadraticCurveTo(l,f+m*2,l-p,f-.05*n)):e.smile<-.3?(t.moveTo(l-p,f+m*.6),t.lineTo(l+p,f+m*.6),t.quadraticCurveTo(l,f-m*1.4,l-p,f+m*.6)):t.ellipse(l,f,p*.8,m,0,0,Math.PI*2),t.fill()}function bd(t,e){const n=e.height??300,s=Math.min(3,Math.max(.3,t.stretch??1)),i=Math.sqrt(s),o=e.armLength??1;if(!Number.isFinite(o)||o<=0)throw new Error("stick figure: armLength must be a positive finite multiplier");const r=(e.headSize??2*od)/2,a=e.headSize===void 0?rk:1-2*r,l=r*n,c=kn(t.sit),h=t.leftHip+(-xo-t.leftHip)*c,u=t.leftKnee+(-xo-t.leftKnee)*c,d=t.rightHip+(xo-t.rightHip)*c,f=t.rightKnee+(xo-t.rightKnee)*c,p=e.classic===!0,g=kn(t.turn),m=(G,F,H,W,_)=>{const B=Math.max(-Math.PI/2,Math.min(Math.PI/2,Math.abs(he(F-H)/2)+he(W))),Q=Math.max(-1,Math.min(1,pk+_)),O=g+(1-g)*G*Q;return p?{x:0,y:0}:{x:Math.cos(B)*dd*O,y:Math.sin(B)*dd}},w={left:t.leftAnkle??0,right:t.rightAnkle??0},v={left:t.leftFootOut??0,right:t.rightFootOut??0};let k=0;if(c>0||!p){const G=(_,B,Q,O,R)=>Va*Math.cos(he(B))+So*Math.cos(he(B-Q))+Math.max(0,m(_,B,Q,O,R).y),F=Math.max(G(-1,h,u,w.left,v.left),G(1,d,f,w.right,v.right)),H=1-kn((t.rise??0)/Sk),W=(p?Math.min(1,c/Mk):1)*H;k=(rd-F)*W*n*s}const y=-rd*n*s+k,x=-a*n*s+k,P=p?0:(bk*kn(t.turn)+wk*c)*n*s,M=he(t.bend??0),T={end:kd(y,x,M,1),bend:M};let S;if(M!==0){S=[];for(let G=0;G<=wd;G++){const F=G/wd,H=kd(y,x,M,F);S.push({x:H.x-P*Math.sin(Math.PI*F),y:H.y})}}else S=P===0?[{x:0,y},{x:0,y:x}]:wn({x:0,y},{x:-P,y:(y+x)/2},{x:0,y:x},1,8);const E=x+ak*n*s,$=(e.shoulderWidth??0)*n*Math.cos(g*Math.PI/2),A=(G,F,H,W,_)=>{const B=Tk(H,W);return{x:G+B.x*_*n,y:F+B.y*_*n}},I=(G,F,H)=>{const W=A(0,y,F,G,Va*s);return{root:{x:0,y},joint:W,end:A(W.x,W.y,F-H,G,So*s)}},C=(G,F,H)=>{const W={x:G*$,y:E},_=A(W.x,W.y,F,G,lk*i*o);return{root:W,joint:_,end:A(_.x,_.y,F+H,G,ck*i*o)}},D={left:I(-1,h,u),right:I(1,d,f)},j=(G,F,H,W,_,B)=>{const Q=m(G,H,W,_,B);return{x:F.end.x+Q.x*n*s,y:F.end.y+Q.y*n*s}},V=(G,F,H,W,_)=>A(F.end.x,F.end.y,H+W+_,G,fd*i),et={left:C(-1,t.leftShoulder,t.leftElbow),right:C(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(p?0:yk,e.rubber??0)),r:l,headRx:l/Math.sqrt(s),headRy:l*Math.sqrt(s),hipY:y,neckY:x,drop:k,lean:p?t.lean:t.lean+kk*Math.sin(Math.PI*c),classic:p,legs:D,toes:{left:j(-1,D.left,h,u,w.left,v.left),right:j(1,D.right,d,f,w.right,v.right)},spine:S,chest:T,arms:et,handTips:{left:V(-1,et.left,t.leftShoulder,t.leftElbow,t.leftWrist??0),right:V(1,et.right,t.rightShoulder,t.rightElbow,t.rightWrist??0)}}}const wd=10;function kd(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 Ak(t,e){if(t.chest.bend===0)return e;const n=li(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 ai=(t,e)=>e===0?[t.root,t.joint,t.end]:wn(t.root,t.joint,t.end,e);function li(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 vd(t,e,n=!0){const s=Pk(t,e),i=e.spin??0,o=e.rise??0;return n&&(i!==0||o!==0)?$k(s,t,i,o):s}function Md(t,e,n){return{pivot:{x:0,y:t.hipY},angle:t.facing*he(e),lift:n*t.height}}function $k(t,e,n,s){const{pivot:i,angle:o,lift:r}=Md(e,n,s),a=d=>{const f=li(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=gd*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 Pk(t,e){const n=he(t.lean),s=he(e.headTilt),i={x:0,y:t.hipY},o=y=>({x:t.facing*y.x,y:y.y}),r=y=>o(li(y,i,n)),a=y=>r(Ak(t,y)),l=y=>a(li({x:y.x,y:y.y+t.neckY},{x:0,y:t.neckY},s)),c=ai(t.arms.left,t.rubber).map(a),h=ai(t.arms.right,t.rubber).map(a),u=(y,x)=>Math.atan2(x.y-y.y,x.x-y.x),d={left:a(t.handTips.left),right:a(t.handTips.right)},f=(y,x)=>{const[P,M]=y.slice(-2),T=t.arms[x],S=u(a(T.end),d[x])-u(a(T.joint),a(T.end));return u(P,M)+S};let p=1/0;for(const[y,x]of[[e.leftBrow,e.leftEye],[e.rightBrow,e.rightEye]]){const P=yd(Ja,1,y,md(x,e.blink));p=Math.min(p,P,P-e.browTilt*.1)}const g={left:o(t.legs.left.end),right:o(t.legs.right.end)},m={left:o(t.toes.left),right:o(t.toes.right)},w={left:Math.max(g.left.y,m.left.y),right:Math.max(g.right.y,m.right.y)},v=Math.max(w.left,w.right),k=gd*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:g,toes:m,feetY:v,grounded:{left:w.left>=v-k,right:w.right>=v-k},fingertips:d,handAngle:{left:f(c,"left"),right:f(h,"right")},limbs:{leftArm:c,rightArm:h,leftLeg:ai(t.legs.left,t.rubber).map(o),rightLeg:ai(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:Ja,browTopY:p,mouthY:pd,faceX:t.facing*(ad+ld*kn(e.turn))}}}function me(t,e={}){return vd(bd(t,e),t)}function Ik(t,e,n){return li({x:t.center.x+e*t.rx,y:t.center.y+n*t.ry},t.center,t.angle)}function Sd(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 xd(t,e,n={},s=0){const i=bd(e,n),o=n.color??"#1e293b",r=n.layers??{},a=n.layers?vd(i,e,!1):void 0,l=n.sketch?po(t,n.sketch,s):void 0,c=n.sketch&&n.layers?po(t,n.sketch,s):void 0,h=M=>{t.save(),M(),t.restore()},u=M=>{M&&a&&h(()=>M(t,a,s,c))},d=()=>t.scale(i.facing,1),f=()=>{d(),t.translate(0,i.hipY),t.rotate(he(i.lean)),t.translate(0,-i.hipY)},p=()=>{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))},g=(M,T,S)=>{if(l)return T?l.curve(M):l.line(M);if(i.classic){t.beginPath(),t.moveTo(M[0].x,M[0].y);for(const E of M.slice(1))t.lineTo(E.x,E.y);t.stroke();return}mo(t,M,S[0]*i.lineWidth,S[1]*i.lineWidth)},m=(M,T)=>g(ai(M,i.rubber),i.rubber>0,T),w=M=>{i.classic||g([i.legs[M].end,i.toes[M]],!1,gk)},v=M=>{if(n.hands&&!i.classic)return y(M);if(i.classic||l)return;const T=i.arms[M].end;t.beginPath(),t.arc(T.x,T.y,mk*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=Md(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(M){const T=n.hands??{},S=i.arms[M].end,E=i.handTips[M],$=n.headFill??"#ffffff";vo(t,S,T[M]??Ot,{side:M,angle:Math.atan2(E.x-S.x,S.y-E.y)*180/Math.PI,size:(T.size??fd)*i.height*Math.sqrt(i.stretch),skin:T.skin??($==="none"?void 0:$),ink:o,lineWidth:i.lineWidth*.45,fingers:T.fingers,plump:T.plump,look:n.sketch?"pencil":"clean",seed:n.sketch?.seed},s)}const x=M=>{h(()=>{p(),m(i.arms[M],fk),v(M)});const T=r.sleeve;T&&a&&h(()=>T(t,a,M,s,c))},P=kn(e.turn)>vk;u(r.behind),h(()=>{d(),m(i.legs.left,ud),w("left"),m(i.legs.right,ud),w("right")}),P&&x("left"),h(()=>{f(),g(i.spine,i.spine.length>2,dk)}),h(()=>{p();const{left:M,right:T}={left:i.arms.left.root,right:i.arms.right.root};if(M.x!==T.x)if(i.classic)g([M,T],!1,[1,1]);else{const S={x:(M.x+T.x)/2,y:M.y-.3*Math.abs(T.x-M.x)};g(wn(M,S,T,1,8),!0,[1.1,1.1])}}),u(r.body),P||x("left"),x("right"),u(r.behindHead),h(()=>{p(),t.translate(0,i.neckY),t.rotate(he(e.headTilt));const M=-i.headRy;t.beginPath(),t.ellipse(0,M,i.headRx,i.headRy,0,0,Math.PI*2);const T=n.headFill??"#ffffff";if(T!=="none"&&(t.fillStyle=T,t.fill()),l){l.ellipse(0,M,i.headRx,i.headRy);const S=l.nudge();t.translate(S.x,S.y)}else t.stroke();t.translate(0,M),t.scale(i.headRx/i.r,i.headRy/i.r),Ek(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 Za(t,e,n,s){const i={...t},o=t.gait&&s?.[t.gait]||t.gait;let r=t.walking>0?Zn(i,Ju(o,t.walk,i),t.walking):i,a=Ok(t);const l=t.dancing??0;if(n&&l>0){const c=n(t.beat??0);if(r=Zn(r,c.pose,l),c.hands){const h=(u,d)=>d?Jn(u??Ot,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*id(e))}),{pose:r,hands:a}}function Td(t,e,n,s){return Za(t,e,n,s).pose}const Ed=(t,e)=>(t.facing??e.facing??1)<0?-1:1,ci=(t,e)=>`hand.${t}.${e}`;function Ok(t){const e=i=>{if(typeof t[ci(i,"spread")]=="number")return Object.fromEntries(Object.keys(Ot).map(o=>[o,t[ci(i,o)]]))},n=e("left"),s=e("right");return n||s?{left:n,right:s}:void 0}function _k(t,e){return!e||!t.hands?t:{...t,hands:{...t.hands,left:e.left??t.hands.left,right:e.right??t.hands.right}}}function Qa(t){const e=t.style??{},n=e.height??300,s=n*.8,i={...Dt(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]??Ot;for(const l of Object.keys(Ot))o[ci(r,l)]=a[l]??Ot[l]}return{type:"custom",x:t.x-s/2,y:t.y-n,width:s,height:n,props:{...i,...o},about:Ck(Object.keys(o),t.cast),figureStyle:e,figureDance:t.dance,figureGaits:t.cast?.gaits,draw(r,a,l){const c=a.props,h=Za(c,l,t.dance,t.cast?.gaits);r.translate(s/2,n),xd(r,h.pose,_k({...e,rubber:c.rubber,facing:Ed(c,e)},h.hands),l)}}}function Ck(t,e){const n={...Nu,...Wu};for(const s of t){const[,i,...o]=s.split("."),r=Du[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 H2(e)}}}function tl(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=Td(i,e.time,t.figureDance,t.figureGaits),l=me(a,{...s,rubber:i.rubber,facing:Ed(i,s)});return{pose:a,joints:Sd(l,t.x+o+t.width/2,t.y+r+t.height)}}function To(t){const e=[];return t.forEach((n,s)=>{const i=s===0?ut:e[s-1],o=typeof n.pose=="string"?ae[n.pose]:{...i,...n.pose};e.push(n.expression?Xe(o,n.expression):o)}),e}function Hk(t,e){const n=To(e);return Qu.filter(s=>n.some(i=>i[s]!==ut[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 el=.5,Eo={pataka:Nt({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:0,turn:2}),tripataka:Nt({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":1,"pinky.curl":0,spread:0,turn:2}),alapadma:Nt({"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:Nt({"thumb.curl":.15,"thumb.across":.6,"index.curl":.6,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:.7,turn:2}),katakamukha:Nt({"thumb.curl":.2,"thumb.across":.6,"index.curl":.65,"middle.curl":.7,"ring.curl":0,"pinky.curl":0,spread:.4,turn:2})};function Ao(t){return typeof t!="string"?t:t in Eo?Eo[t]:St[t]}function Ad(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?Ao(i.hands.left):r.left,right:i.hands?.right?Ao(i.hands.right):r.right,easing:i.easing??t.easing})}return s}const nl=(t,e)=>(t%e+e)%e;function Rk(t,e,n,s){const i=Ad(t,n,s);if(i.length===0)return{pose:n,hands:s};const o=nl(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=Wt(l.easing??"ease-in-out")(Math.min(1,Math.max(0,u)));return{pose:Zn(a.pose,l.pose,d),hands:{left:Jn(a.left,l.left,d),right:Jn(a.right,l.right,d)}}}const Lk=[["leftShoulder","rightShoulder"],["leftElbow","rightElbow"],["leftWrist","rightWrist"],["leftHip","rightHip"],["leftKnee","rightKnee"],["leftAnkle","rightAnkle"],["leftFootOut","rightFootOut"],["leftEye","rightEye"],["leftBrow","rightBrow"]],Fk=["lean","headTilt","lookX","spin"],Nk=new Set(["leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee"]);function $d(t){const e={...t},n=(t.turn??0)>=.5;for(const[s,i]of Lk){const o=n&&Nk.has(s)?-1:1;e[s]=o*t[i],e[i]=o*t[s]}if(!n)for(const s of Fk)e[s]=-t[s];return e}const Wk=t=>Math.min(1,Math.max(-1,(.5-t)*4));function Pd(t,e,n){const s=nl(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=Wk(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 $o(t){const e={...ut,...t.stance};return t.expression?Xe(e,t.expression):e}function Id(t){return{left:t.hands?.left?Ao(t.hands.left):Ot,right:t.hands?.right?Ao(t.hands.right):Ot}}function sl(t,e,n){const s=t.moves[e.move];if(!s)throw new Error(`dance: "${t.label}" has no move "${e.move}"`);const i=Rk(s,n,$o(t),Id(t));return e.mirror?{pose:$d(i.pose),hands:{left:i.hands?.right,right:i.hands?.left}}:i}function Po(t,e,n={}){const s=typeof t=="string"?Ge[t]:t;let i;if(n.move)i=sl(s,{move:n.move,mirror:n.mirror},e);else{const o=s.routine,r=o.reduce((u,d)=>u+d.beats,0),a=nl(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=sl(s,o[c],h),h<el&&o.length>1&&e>=el){const u=o[(c-1+o.length)%o.length],d=sl(s,u,u.beats+h),f=Wt("ease-in-out")(h/el);i={pose:Zn(d.pose,i.pose,f),hands:{left:Jn(d.hands.left,i.hands.left,f),right:Jn(d.hands.right,i.hands.right,f)}}}}return{...i,pose:Pd(i.pose,s.groove,e)}}function Dk(t,e,n={}){return Po(t,e,n).pose}function Io(t){return(typeof t=="string"?Ge[t]:t).routine.reduce((n,s)=>n+s.beats,0)}const Bk={leftToe:"rightToe",rightToe:"leftToe",leftHeel:"rightHeel",rightHeel:"leftHeel"};function Od(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?Bk[u]:u})}}function zk(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;Od(r,a,Math.ceil((n-a)/r.beats)*r.beats,s.mirror,o,e,n)}else{const r=Io(i);for(let a=Math.floor(e/r)*r;a<n;a+=r){let l=a;for(const c of i.routine)Od(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 _d(t,e){const n=t.moves[e.move];if(!n?.travel)return 0;const s=n.travel/n.beats;return e.mirror?(Ad(n,$o(t),Id(t))[0]?.pose.turn??$o(t).turn??0)>=.5?s:-s:s}function Cd(t,e){return e.move?[{move:e.move,beats:t.moves[e.move].beats,mirror:e.mirror}]:t.routine}function Oo(t,e,n={}){const s=typeof t=="string"?Ge[t]:t,i=Cd(s,n),o=i.reduce((h,u)=>h+u.beats,0),r=i.reduce((h,u)=>h+_d(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+=_d(s,h)*u,c-=u,c<=0)break}return l}function qk(t,e,n){const s=Cd(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 jk=8;function Hd(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:Io(s)),r=qk(s,o,n);if(r.every(w=>Oo(s,w,n)===0))return;const a=Math.min(n.fade??1,o/2),l=Wt("ease-in-out"),c=w=>a<=0?1:Math.min(l(Math.min(1,w/a)),l(Math.min(1,(o-w)/a))),h=Math.ceil(a*jk),u=a<=0?[]:Array.from({length:h+1},(w,v)=>[v/h*a,o-v/h*a]).flat(),d=[...new Set([...r,...u])].sort((w,v)=>w-v);let f=0;const p=d.map((w,v)=>{if(v>0){const k=d[v-1],y=Math.max(1,Math.ceil((w-k)*16));for(let x=0;x<y;x++){const P=k+(w-k)*x/y,M=k+(w-k)*(x+1)/y;f+=(Oo(s,M,n)-Oo(s,P,n))*c((P+M)/2)}}return{beat:w,travel:f}}),g=n.start??0,m=n.x??0;return{id:`${t}-x`,target:t,property:"x",keyframes:p.map(w=>({time:g+w.beat*6e4/i,value:m+n.height*w.travel,easing:"linear"}))}}function Yk(t,e,n=0){return(t-n)*e/6e4}function Kk(t,e={}){return n=>Po(t,n,e)}function Xk(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 Gk(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:Io(s)),r=n.samplesPerBeat??4,a=n.start??0,l=Math.round(o*r),c=Array.from({length:l+1},(g,m)=>{const w=m/r;return{time:a+w*6e4/i,frame:Po(s,w,n)}}),h=(g,m)=>({id:`${t}-${g}`,target:t,property:g,keyframes:c.map(w=>({time:w.time,value:m(w.frame)}))}),d=Object.keys(ut).filter(g=>c.some(m=>m.frame.pose[g]!==c[0].frame.pose[g])||c[0].frame.pose[g]!==ut[g]).map(g=>h(g,m=>m.pose[g])),f=n.height===void 0?void 0:Hd(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 p=[];for(const g of["left","right"])for(const m of Object.keys(Ot)){const w=v=>v.hands?.[g]?.[m]??Ot[m];c.some(v=>w(v.frame)!==Ot[m])&&p.push(h(ci(g,m),w))}return[...d,...p]}const hi={type:"back",mode:"out",overshoot:1.1},Zt="ease-out-cubic",Uk={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:Zt,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:Zt},{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:Zt},{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}]},Vk={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}]},Jk={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:Zt},{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:Zt},{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:Zt},{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:hi},{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}]},Zk={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:Zt},{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}]},Qk={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:hi,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:hi},{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:hi},{beat:3,pose:{headTilt:4}}]},isolations:{label:"Isolations",beats:2,easing:Zt,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}]},t5={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:Zt},{beat:.5,pose:{lean:-4,rightHip:12,headTilt:6}},{beat:1,pose:{lean:-11,rightHip:22,headTilt:10},easing:Zt},{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:Zt},{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:Zt}]}},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}]},e5={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}]},n5={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}]},s5={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:Zt},{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:Zt},{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}]},i5={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:Uk,hipHop:Vk,breaking:Jk,jazz:Zk,kpop:Qk,bollywood:t5,bhangra:e5,bharatanatyam:n5,charleston:s5,tap:i5,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:hi},{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}]}},_o={standard:{},slim:{headSize:.24,shoulderWidth:.05,hipWidth:.02},tall:{headSize:.25,legLength:1.1,armLength:1.05},short:{headSize:.33,legLength:.92,shoulderWidth:.065,hipWidth:.03},broad:{shoulderWidth:.11,hipWidth:.04},curvy:{shoulderWidth:.055,hipWidth:.065},stocky:{headSize:.34,shoulderWidth:.1,hipWidth:.06},kid:{headSize:.42},child:{headSize:.4,legLength:.88,armLength:.9,shoulderWidth:.05,hipWidth:.02},toddler:{headSize:.46,legLength:.78,armLength:.82,shoulderWidth:.05,hipWidth:.025}},il=.215,ol=.205,o5=.065,Rd=.035,r5=.165,a5=.155,l5=12,c5=.3,h5=.7,u5=.35,d5=t=>t*Math.PI/180,lt={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,pupil:1,lid:0,bulge:0,"brow.left":0,"brow.right":0,browTilt:0,lookX:0,lookY:0,blush:0,tears:0,sweat:0,"hair.swing":0,"hair.trail":0,"hair.lift":0,"held.left":1,"held.right":1,"held.both":1};function kt(t={}){return{...lt,...t}}const f5=new Set(["turn","side","head.turn","head.tilt","roll","lookX","hair.swing"]);function Ld(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]=f5.has(n)?-s:s}return e}function $t(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 ye={rest:lt,wave:kt({"arm.right.spread":115,"arm.right.bend":55,"arm.right.elbow":0,"head.tilt":-6,smile:.9}),cheer:kt({...$t("arm",{spread:140,bend:20,elbow:0}),mouth:.6,smile:1,"eye.left":0,"eye.right":0}),point:kt({"arm.right.spread":88,"arm.right.elbow":0,"arm.right.bend":0,"head.turn":-20,smile:.4}),handsOnHips:kt({...$t("arm",{spread:50,bend:-105,elbow:0}),...$t("leg",{spread:9}),smile:.8}),think:kt({"arm.right.spread":22,"arm.right.bend":-150,"arm.right.elbow":0,"head.tilt":10,lookX:-.5,lookY:-.8,smile:0}),shrug:kt({...$t("arm",{spread:35,bend:75,elbow:0}),"head.tilt":-10,smile:-.2}),sit:kt({...$t("leg",{swing:90,knee:90,spread:4}),...$t("arm",{swing:25,elbow:45,spread:8})}),kneel:kt({"leg.left.swing":90,"leg.left.knee":90,"leg.right.swing":-18,"leg.right.knee":108,"leg.right.ankle":16,...$t("arm",{swing:20,elbow:30})}),crouch:kt({...$t("leg",{swing:75,knee:140,spread:6}),lean:25,...$t("arm",{swing:50,elbow:40}),"head.nod":-15}),crawl:kt({lean:82,"head.nod":-35,...$t("arm",{swing:80,elbow:0,spread:4}),...$t("leg",{knee:92,ankle:-88})}),lieDown:kt({roll:90,...$t("arm",{spread:8}),"head.nod":0}),sleep:kt({roll:90,...$t("arm",{spread:8,swing:20,elbow:40}),"leg.left.knee":20,"leg.left.swing":15,blink:1,smile:.2}),stretch:kt({side:-16,"arm.left.spread":165,"arm.left.bend":35,"arm.left.elbow":0,"arm.right.spread":40,"arm.right.bend":-110,"arm.right.elbow":0,"head.tilt":-10,"eye.left":0,"eye.right":0,smile:.4}),sitFloor:kt({...$t("leg",{swing:80,spread:22,rotate:75,knee:145}),...$t("arm",{swing:25,spread:18,elbow:30}),lean:5,smile:.5}),carry:kt({...$t("arm",{spread:16,elbow:4}),lean:-3,smile:.4}),cane:kt({"arm.right.swing":16,"arm.right.spread":10,"arm.right.elbow":0,"arm.right.bend":0,"arm.left.swing":2,side:-3,lean:4,"leg.right.swing":4,smile:.3}),lift:kt({...$t("arm",{swing:28,spread:24,elbow:85,bend:-45}),...$t("leg",{swing:12,knee:22,spread:6}),lean:-4,smile:.2}),push:kt({lean:28,...$t("arm",{swing:82,spread:12,elbow:18}),"leg.left.swing":28,"leg.left.knee":30,"leg.right.swing":-28,"leg.right.knee":6,"head.nod":-20,browTilt:-.6,smile:-.2}),pull:kt({lean:-22,...$t("arm",{swing:70,spread:6,elbow:0}),"leg.left.swing":32,"leg.left.knee":8,"leg.right.swing":-8,"leg.right.knee":34,"head.nod":12,browTilt:-.6,smile:-.2}),drink:kt({"arm.right.swing":85,"arm.right.spread":8,"arm.right.elbow":120,"arm.right.bend":0,"head.nod":-14,"eye.left":.5,"eye.right":.5,smile:0}),phone:kt({"arm.right.swing":80,"arm.right.spread":8,"arm.right.elbow":80,"arm.right.bend":-10,"head.nod":18,lookY:.7,lookX:-.3,smile:.4}),read:kt({...$t("arm",{swing:32,spread:10,elbow:82,bend:-28}),"head.nod":22,lookY:.8,smile:.2}),type:kt({...$t("leg",{swing:90,knee:90,spread:4}),...$t("arm",{swing:40,spread:10,elbow:55,bend:-20}),lean:8,"head.nod":10,lookY:.5,smile:0})},Fd=["round","flat","pointed","big"],g5={round:{length:1,width:[.95,.7]},flat:{length:1.12,width:[.85,.85]},pointed:{length:1.25,width:[1,.3]},big:{length:1.5,width:[1.25,1.1]}};function rl(t={}){const e=t.headSize??.3,n=t.shoulderWidth??.06,s=t.hipWidth??.022,i=t.legLength??1,o=t.armLength??1,r=g5[t.feet??"round"],a=Math.max(.12,1-e-Rd-(il+ol)*i),l=u=>({id:`arm.${u}`,parent:"spine",offset:[(u==="left"?1:-1)*n,-.035,0],rest:[0,-1,0],side:u==="left"?1:-1,bones:[{length:r5*o,width:[1.25,.9]},{length:a5*o,width:[.9,.75]}]}),c=u=>({id:`leg.${u}`,parent:null,offset:[(u==="left"?1:-1)*s,0,0],rest:[0,-1,0],side:u==="left"?1:-1,bones:[{length:il*i,width:[1.45,1.05]},{length:ol*i,width:[1.05,.85]},{length:o5*Math.sqrt(i)*r.length,width:r.width}]}),h=(u,d)=>u[d]??lt[d]??0;return{id:"human",hipHeight:(il+ol)*i,chains:[c("left"),c("right"),{id:"spine",parent:null,rest:[0,1,0],bones:[{length:a/2,width:[1.7,1.4]},{length:a/2,width:[1.4,1.1]}]},{id:"neck",parent:"spine",rest:[0,1,0],bones:[{length:Rd,width:[1,.9]}]},l("left"),l("right")],head:{on:"neck",size:e},contacts:[...["left","right"].flatMap(u=>[{chain:`leg.${u}`,joint:1},{chain:`leg.${u}`,joint:2},{chain:`leg.${u}`,joint:3},{chain:`arm.${u}`,joint:1},{chain:`arm.${u}`,joint:2}]),{chain:"spine",joint:0},{chain:"spine",joint:1},{chain:"spine",joint:2},{head:"top"}],angles(u,d){if(d.id==="spine"){const v=-h(u,"lean")/2,k=h(u,"side")/2,y=-h(u,"bend");return[{swing:v+y*c5,spread:k},{swing:v+y*h5,spread:k}]}if(d.id==="neck")return[{swing:-h(u,"bend")*u5,spread:0}];const[f,p]=d.id.split("."),g=v=>h(u,`${f}.${p}.${v}`);if(f==="arm")return[{swing:g("swing"),spread:g("spread")},{swing:g("elbow"),spread:g("bend")}];const m=(d.side??1)*g("rotate"),w=1-Math.cos(d5(g("rotate")));return[{swing:g("swing"),spread:g("spread"),yaw:m},{swing:-g("knee"),spread:0,yaw:m},{swing:90+g("ankle")-w*(g("swing")-g("knee")),spread:0,yaw:(l5+g("toeOut"))*(d.side??1)}]},withAngles(u,d,f){const[p,g]=d.id.split("."),m=w=>`${p}.${g}.${w}`;return p==="arm"?{...u,[m("swing")]:f[0].swing,[m("spread")]:f[0].spread,[m("elbow")]:f[1].swing,[m("bend")]:f[1].spread}:p==="leg"?{...u,[m("swing")]:f[0].swing,[m("spread")]:f[0].spread,[m("knee")]:-f[1].swing}:u},boneScale(u,d){const f=Math.min(3,Math.max(.3,h(u,"stretch")));return d?.id.startsWith("arm.")?Math.sqrt(f):f},headPose(u){const d=Math.min(3,Math.max(.3,h(u,"stretch")));return{yaw:h(u,"head.turn"),nod:h(u,"head.nod"),tilt:h(u,"head.tilt"),sx:1/Math.sqrt(d),sy:Math.sqrt(d)}},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 p5(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",pupil:"Pupil size",lid:"Eyelids lowered",bulge:"Eyes bulging","brow.left":"Left brow","brow.right":"Right brow",browTilt:"Brow slant",lookX:"Look left / right",lookY:"Look up / down",blush:"Blush",tears:"Tears",sweat:"Sweat","hair.swing":"Hair · swing","hair.trail":"Hair · trail","hair.lift":"Hair · lift","held.left":"Left hand · holding","held.right":"Right hand · holding","held.both":"Both hands · holding"}[t]??t}const m5={leftEye:"eye.left",rightEye:"eye.right",leftBrow:"brow.left",rightBrow:"brow.right"},y5={blush:0,tears:0,sweat:0,pupil:1,lid:0,bulge:0},vn=Object.fromEntries(Object.entries(vt).map(([t,e])=>[t,{...Object.fromEntries(Object.entries(e).map(([n,s])=>[m5[n]??n,s])),...y5}]));vn.crying.tears=1,vn.scared.sweat=.8,vn.scared.bulge=.4,vn.sleepy.lid=.5,vn.worried.sweat=.6;const ue=t=>({...vn.neutral,...t}),al={...vn,laughing:ue({mouth:.75,smile:1,mouthWidth:1.25,"eye.left":0,"eye.right":0,"brow.left":.5,"brow.right":.5}),afraid:ue({mouth:.4,smile:-.6,mouthWidth:.9,"eye.left":1.3,"eye.right":1.3,"brow.left":.6,"brow.right":.6,browTilt:1,sweat:1,pupil:.8,bulge:.5}),bored:ue({smile:-.05,mouthWidth:.6,"eye.left":.45,"eye.right":.45,"brow.left":-.4,"brow.right":-.4,lookX:.5}),tired:ue({mouth:.2,smile:-.3,mouthWidth:.7,"eye.left":.3,"eye.right":.3,"brow.left":-.1,"brow.right":-.1,browTilt:.6,lookY:.6}),embarrassed:ue({smile:.4,mouthWidth:.7,"eye.left":.9,"eye.right":.9,browTilt:.7,"brow.left":.2,"brow.right":.2,lookX:-.6,lookY:.5,blush:1}),proud:ue({smile:.75,mouthWidth:1,"eye.left":.75,"eye.right":.75,"brow.left":.5,"brow.right":.5,lookY:-.2}),determined:ue({smile:.35,mouthWidth:.8,"eye.left":.85,"eye.right":.85,"brow.left":-.5,"brow.right":-.5,browTilt:-.9}),affectionate:ue({smile:.85,"eye.left":0,"eye.right":0,"brow.left":.3,"brow.right":.3,blush:.8}),hurt:ue({smile:-.7,mouthWidth:.8,"eye.left":1.1,"eye.right":1.1,"brow.left":.2,"brow.right":.2,browTilt:1,lookY:.3,tears:.35}),suspicious:ue({smile:-.25,mouthWidth:.7,"eye.left":.5,"eye.right":.85,"brow.left":-.6,"brow.right":.4,browTilt:-.3,lookX:.8,lid:.3}),relieved:ue({smile:.7,"eye.left":0,"eye.right":0,"brow.left":.4,"brow.right":.4,browTilt:.4}),excited:ue({mouth:.6,smile:1,mouthWidth:1.1,"eye.left":1.4,"eye.right":1.4,"brow.left":.9,"brow.right":.9,blush:.4,pupil:1.3})},de=t=>t*Math.PI/180;function ll([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t,e*i+n*o,-e*o+n*i]}function Qn([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i-e*o,t*o+e*i,n]}function Qt([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i+n*o,e,-t*o+n*i]}const Ie=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Co=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],Ho=(t,e)=>Qn(ll(t,e.swing),e.spread);function Ro(t,e){const n=Qt(t,e);return{point:{x:n[0],y:-n[1]},depth:n[2]}}function ts(t,e,n){const s=n,o=[0,t.hipHeight*s*(t.boneScale?.(e,null)??1),0],r={};for(const g of t.chains){const m=g.parent?r[g.parent]:void 0;if(g.parent&&!m)throw new Error(`body plan ${t.id}: chain ${g.id} comes before its parent ${g.parent}`);const w=g.at??(m?m.joints3.length-1:0),v=m?m.joints3[w]:o,k=m?m.frames[Math.max(0,w-1)]:{swing:0,spread:0},y=g.offset?Ie(v,Ho(Co(g.offset,s),k)):v,x=g.side??1,P=t.boneScale?.(e,g)??1,M=t.angles(e,g),T=[y],S=[];let E=k.swing,$=k.spread;g.bones.forEach((A,I)=>{const C=M[I]??{swing:0,spread:0};E+=de(C.swing),$+=de(C.spread)*x,S.push({swing:E,spread:$});const D=Qt(Ho(g.rest,{swing:E,spread:$}),de(C.yaw??0));T.push(Ie(T[I],Co(D,A.length*s*P)))}),r[g.id]={joints3:T,frames:S}}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=g=>Ho(Qt(ll(Qn(g,-de(l.tilt)),-de(l.nod)),de(l.yaw)),c),p=Ie(a.joints3[a.joints3.length-1],f([0,d,0]));return{height:s,root:o,chains:r,head:{center:p,rx:u,ry:d,toBody:f}}}function cl(t,e,n){const s=n.height,i=de(90*(e.turn??0)),o=ts(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 S of t.chains){const{joints3:E,frames:$}=a[S.id],A=E.map(I=>Ro(I,i));d[S.id]={id:S.id,joints3:E,frames:$,points:A.map(I=>I.point),depths:A.map(I=>I.depth)}}const f=Ro(u,i),p=[[1,0,0],[0,1,0],[0,0,1]].map(S=>Qt(h(S),i)),g=Ro(r,i).point,m=de(e.roll??0),w=S=>{const E=S.x-g.x,$=S.y-g.y;return{x:g.x+E*Math.cos(m)-$*Math.sin(m),y:g.y+E*Math.sin(m)+$*Math.cos(m)}},v=([S,E,$])=>[S*Math.cos(m)+E*Math.sin(m),-S*Math.sin(m)+E*Math.cos(m),$];for(const S of Object.values(d))S.points=S.points.map(w);const k={center:w(f.point),depth:f.depth,rx:l,ry:c,angle:0,axes:p.map(v)},y=k.axes[1];k.angle=Math.atan2(y[0],y[1]);const x=S=>{if("head"in S)return{x:k.center.x+y[0]*c,y:k.center.y-y[1]*c};const E=d[S.chain];return E.points[Math.min(S.joint,E.points.length-1)]};let P=0;(n.contact??"ground")==="ground"&&(P=-Math.max(...t.contacts.map(S=>x(S).y))),P-=(e.lift??0)*s;const M=S=>({x:S.x,y:S.y+P});for(const S of Object.values(d))S.points=S.points.map(M);k.center=M(k.center);const T=t.contacts.map(S=>({spec:S,point:x(S)}));return{height:s,view:i,chains:d,head:k,hip:M(w(g)),hipDepth:Ro(r,i).depth,contacts:T,groundY:Math.max(...T.map(S=>S.point.y))}}const Lo=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],hl=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function Ue(t,e,n){const s=n.height,i=de(90*(e.turn??0)),o=de(e.roll??0),r=ts(t,e,s),a=Qt(r.root,i),l=m=>Ie(Qn(Lo(Qt(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=>hl(Lo(l(Ie(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 Ie(h,Co(d[1],r.head.ry));const w=c[m.chain];return w[Math.min(m.joint,w.length-1)]};let p=0;(n.contact??"ground")==="ground"&&(p=-Math.min(...t.contacts.map(m=>f(m)[1]))),p+=(e.lift??0)*s;const g=m=>[m[0],m[1]+p,m[2]];return{height:s,hip:g(a),chains:Object.fromEntries(Object.entries(c).map(([m,w])=>[m,w.map(g)])),head:{center:g(h),rx:r.head.rx,ry:r.head.ry,axes:d}}}function Fo(t,e,n,s){const i=n.height,o=de(90*(e.turn??0)),r=ts(t,e,i),a=Ue(t,e,n),l=a.hip,c=a.chains,h=a.head.center,u=$=>{if("head"in $)return Ie(h,Co(a.head.axes[1],a.head.ry));const A=c[$.chain];return A[Math.min($.joint,A.length-1)]},d=s.toView(l),f=Qn(Qt([0,0,1],o),-de(e.roll??0)),p=hl(Lo(s.toView(Ie(l,f)),d)),g=s.toScreen(d),m=s.toScreen([d[0]+1,d[1],d[2]]),w=Math.hypot(m.x-g.x,m.y-g.y),v=$=>{const A=s.toView($);return{point:s.toScreen(A),depth:A[2]*w}},k={};for(const $ of t.chains){const A=c[$.id].map(v);k[$.id]={id:$.id,joints3:r.chains[$.id].joints3,frames:r.chains[$.id].frames,points:A.map(I=>I.point),depths:A.map(I=>I.depth)}}const y=s.toView(h),x=s.toScreen(y),P=s.toScreen([y[0]+1,y[1],y[2]]),M=Math.hypot(P.x-x.x,P.y-x.y),T=a.head.axes.map($=>hl(Lo(s.toView(Ie(h,$)),y))),S={center:x,depth:y[2]*w,rx:r.head.rx*M,ry:r.head.ry*M,angle:Math.atan2(T[1][0],T[1][1]),axes:T},E=t.contacts.map($=>({spec:$,point:v(u($)).point}));return{height:i*w,view:o,bodyForward:p,chains:k,head:S,hip:g,hipDepth:d[2]*w,contacts:E,groundY:Math.max(...E.map($=>$.point.y))}}function es(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}}const No=t=>t*180/Math.PI,Mn=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],ul=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],ns=t=>Math.hypot(t[0],t[1],t[2]),dl=t=>{const e=ns(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},Wo=t=>Math.atan2(Math.sin(t),Math.cos(t));function Nd(t){const[e,n,s]=dl(t);return{swing:Math.asin(Math.max(-1,Math.min(1,s))),spread:Math.atan2(e,-n)}}function ui(t,e,n,s,i){const o=t.chains.find(A=>A.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=cl(t,{...e,turn:0,roll:0,lift:0},{height:i.height,contact:"none"}),a=r.chains[n];if(ns(Mn(s,a.joints3[2]))<i.height*1e-12)return e;const l=a.joints3[0],c=ns(Mn(a.joints3[1],a.joints3[0])),h=ns(Mn(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=Mn(s,l),f=t.angles(e,o),p=A=>(f[A]?.yaw??0)*Math.PI/180,g=Math.min(c+h-1e-6,Math.max(Math.abs(c-h)+1e-6,ns(d))),m=dl(d),w=o.parent!==null,v=Qt(Ho(o.pole??(w?[0,-.35,-1]:[0,0,1]),u),p(0));let k=Mn(v,[m[0]*ul(v,m),m[1]*ul(v,m),m[2]*ul(v,m)]);ns(k)<1e-6&&(k=Qt([1,0,0],p(0))),k=dl(k);const y=(c*c+g*g-h*h)/(2*c*g),x=Math.sqrt(Math.max(0,1-y*y)),P=[l[0]+c*(y*m[0]+x*k[0]),l[1]+c*(y*m[1]+x*k[1]),l[2]+c*(y*m[2]+x*k[2])],M=[l[0]+m[0]*g,l[1]+m[1]*g,l[2]+m[2]*g],T=o.side??1,S=Nd(Qt(Mn(P,l),-p(0))),E=Nd(Qt(Mn(M,P),-p(1))),$=[{swing:No(Wo(S.swing-u.swing)),spread:No(Wo(S.spread-u.spread))*T},{swing:No(Wo(E.swing-S.swing)),spread:No(Wo(E.spread-S.spread))*T}];return t.withAngles(e,o,$)}const ss=(t,e)=>(t%e+e)%e,Wd=t=>t*t*(3-2*t),b5=t=>Object.fromEntries(["left","right"].flatMap(e=>Object.entries(St[t]).map(([n,s])=>[`hand.${e}.${n}`,s])));function fl(t,e=!1){const n=rl(),s=ui(n,lt,"arm.left",[.015,.68,.2],{height:1}),i=ui(n,s,"arm.right",[-.015,.68,.2],{height:1});return Array.from({length:32},(o,r)=>{const a=r/4,l=Math.floor(a),c=a-l,h=l%2===0,u=Math.sin(Math.PI*c),d=Math.max(0,...t.map(p=>1-Math.min(ss(a-p,8),ss(p-a,8))/.5)),f={side:(h?1:-1)*5*Math.sin(Math.PI*c),bend:2+3*u,"head.tilt":(h?-1:1)*3*u,"head.nod":-2*u,"leg.left.swing":h?-4*u:17*u,"leg.right.swing":h?17*u:-4*u,"leg.left.knee":h?5*u:36*u,"leg.right.knee":h?36*u:5*u,"leg.left.spread":4,"leg.right.spread":4,"arm.left.swing":22+d*(e?45:42),"arm.right.swing":22+d*(e?45:42),"arm.left.spread":28-22*d,"arm.right.spread":28-22*d,"arm.left.elbow":48+22*d,"arm.right.elbow":48+22*d,"arm.left.bend":-35*d,"arm.right.bend":-35*d,smile:.9,...b5(e?"hold":"spread")};if(!e)for(const p of Object.keys(i))p.startsWith("arm.")&&(f[p]+=(i[p]-f[p])*d);return{beat:a,pose:f}})}const Sn={garba:{label:"Garba · two clap",bpm:120,beats:8,strikes:[2,3,6,7],keys:fl([2,3,6,7])},garbaThreeClap:{label:"Garba · three clap",bpm:120,beats:8,strikes:[1,2,3,5,6,7],keys:fl([1,2,3,5,6,7])},dandiya:{label:"Dandiya · partner strikes",bpm:120,beats:8,strikes:[1,3,5,7],keys:fl([1,3,5,7],!0)}};function Dd(t){const e=typeof t=="string"&&Object.hasOwn(Sn,t)?Sn[t]:typeof t=="string"?void 0:t;if(!e||!Number.isFinite(e.beats)||e.beats<=0||!Array.isArray(e.keys)||!e.keys.length||!Array.isArray(e.strikes)||!e.keys.every((n,s)=>Number.isFinite(n.beat)&&n.beat>=0&&n.beat<e.beats&&(s===0||n.beat>e.keys[s-1].beat)&&n.pose&&Object.values(n.pose).every(Number.isFinite))||!e.strikes.every(n=>Number.isFinite(n)&&n>=0&&n<e.beats))throw new Error("humanDanceFrame: a dance with positive finite beats, ordered pose keys and strike beats within its loop is required");return e}function di(t,e,n=lt){const s=Dd(t);if(!Number.isFinite(e))throw new Error("humanDanceFrame: beat must be finite");const i=ss(e,s.beats);let o=s.keys.length-1;for(let m=0;m<s.keys.length;m++)s.keys[m].beat<=i&&(o=m);const r=s.keys[o],a=s.keys[(o+1)%s.keys.length],l=r.beat>i?r.beat-s.beats:r.beat,c=a.beat<=r.beat?a.beat+s.beats:a.beat,h=Wd((i-l)/(c-r.beat)),u={...lt,...n};for(const m of new Set(s.keys.flatMap(w=>Object.keys(w.pose)))){if(m==="turn"||m==="roll")continue;const w=m.match(/^hand\.(?:left|right)\.(.+)$/)?.[1],v=n[m]??lt[m]??(w?Ot[w]:void 0)??0,k=r.pose[m]??v;u[m]=k+((a.pose[m]??v)-k)*h}const d=Math.floor(e),f=e-d,p=f<=.6?1:1-Wd((f-.6)/.4),g=Math.max(0,...s.strikes.map(m=>1-Math.min(ss(i-m,s.beats),ss(m-i,s.beats))/.25));return{pose:u,contact:{side:ss(d,2)===0?"left":"right",start:d,weight:p},strike:g}}function w5(t,e){const n=Dd(e.style),s=e.bpm??n.bpm,i=e.beats??n.beats,o=e.samplesPerBeat??16;if(![s,i,o].every(l=>Number.isFinite(l)&&l>0))throw new Error("humanDanceTracks: bpm, beats and samplesPerBeat must be positive and finite");if(!Number.isFinite(e.start??0))throw new Error("humanDanceTracks: start must be finite");const r=Math.max(1,Math.ceil(i*o)),a=Array.from({length:r+1},(l,c)=>({time:(e.start??0)+i*c/r*6e4/s,pose:di(n,i*c/r,e.pose).pose}));return Object.keys(a[0].pose).filter(l=>l!=="turn"&&l!=="roll"&&a.some(c=>c.pose[l]!==(e.pose?.[l]??lt[l]))).map(l=>({id:`${t}-dance-${l}`,target:t,property:l,keyframes:a.map(c=>({time:c.time,value:c.pose[l],easing:"linear"}))}))}function is(t,e,n,s){if(!Number.isFinite(t)||t<n||t>s)throw new Error(`organic body: ${e} must be ${n}..${s}`);return t}function Do(t,e){if(t.length<2||t[0].at!==0||t.at(-1).at!==1)throw new Error(`organic body: ${e} must run from 0 to 1`);return t.map((n,s)=>{if(is(n.at,`${e}.at`,0,1),is(n.width,`${e}.width`,.001,.3),s>0&&n.at<=t[s-1].at)throw new Error(`organic body: ${e} positions must increase`);return{at:n.at,width:n.width}})}function Bd(t,e){const n=Math.max(.095,e.shoulderWidth+.025),s=Math.max(.085,e.hipWidth+.032),i=t.shading??{},o=i.light??[-.8,-.6];if(o.length!==2||!o.every(Number.isFinite)||Math.hypot(...o)===0)throw new Error("organic body: light must be a finite nonzero 2D vector");if(i.mode!==void 0&&i.mode!=="none"&&i.mode!=="cel")throw new Error("organic body: unknown shading mode");return{torso:Do(t.torso??[{at:0,width:s},{at:.2,width:s},{at:.42,width:s*.72},{at:.68,width:n*.9},{at:.86,width:n},{at:1,width:.024}],"torso"),arm:Do(t.arm??[{at:0,width:.028},{at:.22,width:.027},{at:.5,width:.019},{at:.68,width:.023},{at:1,width:.012}],"arm"),leg:Do(t.leg??[{at:0,width:.04},{at:.24,width:.042},{at:.5,width:.027},{at:.68,width:.032},{at:1,width:.016}],"leg"),neck:Do(t.neck??[{at:0,width:.024},{at:1,width:.023}],"neck"),depth:is(t.depth??.55,"depth",.2,1),fill:t.fill??e.skin,outline:{color:t.outline?.color??e.ink,width:is(t.outline?.width??e.lineWidth,"outline.width",0,100)},shading:{mode:i.mode??"cel",light:[...o],shadow:i.shadow??"#633923",opacity:is(i.opacity??.17,"shading.opacity",0,1),highlight:is(i.highlight??.12,"shading.highlight",0,1)}}}function zd(t,e){const n=Math.min(1,Math.max(0,e)),s=t.findIndex(a=>a.at>=n);if(s<=0)return t[0].width;const i=t[s-1],o=t[s],r=(n-i.at)/(o.at-i.at);return i.width+(o.width-i.width)*r*r*(3-2*r)}const qd=8,k5=(t,e,n)=>({x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n}),xn=(t,e)=>{const n=Math.hypot(e.x-t.x,e.y-t.y)||1;return{x:(e.x-t.x)/n,y:(e.y-t.y)/n}},Bo=(t,e,n)=>({x:t.x+e.x*n,y:t.y+e.y*n});function fi(t,e=12){if(!Number.isInteger(e)||e<1||e>128)throw new Error("organicCenterLine: steps must be an integer from 1 to 128");if(t.length<2)return t.map(i=>({...i}));const n=t.map((i,o)=>{const r=xn(t[Math.max(0,o-1)],i),a=xn(i,t[Math.min(t.length-1,o+1)]),l=Math.hypot(r.x+a.x,r.y+a.y);return l>1e-6?{x:(r.x+a.x)/l,y:(r.y+a.y)/l}:a}),s=[];for(let i=0;i<t.length-1;i++){const o=t[i],r=t[i+1],a=Math.hypot(r.x-o.x,r.y-o.y)*.28,l=Bo(o,n[i],a),c=Bo(r,n[i+1],-a);for(let h=i===0?0:1;h<=e;h++){const u=h/e,d=1-u;s.push({x:d**3*o.x+3*d*d*u*l.x+3*d*u*u*c.x+u**3*r.x,y:d**3*o.y+3*d*d*u*l.y+3*d*u*u*c.y+u**3*r.y})}}return s}function zo(t,e,n,s=1,i=1){const o=t.map((h,u)=>{const d=t[Math.max(0,u-1)],f=t[Math.min(t.length-1,u+1)];let p=xn(d,f);Math.hypot(p.x,p.y)<1e-6&&(p={x:0,y:1});const g={x:-p.y,y:p.x},m=u/Math.max(1,t.length-1),w=zd(e,m)*n*s,v=xn(d,h),k=xn(h,f),y=v.x*k.y-v.y*k.x,x=Math.acos(Math.min(1,Math.max(-1,v.x*k.x+v.y*k.y))),P=(Math.hypot(h.x-d.x,h.y-d.y)+Math.hypot(f.x-h.x,f.y-h.y))/(2*Math.max(1e-6,x)),M=Math.min(w,Math.max(w*.2,P*.8));return{center:h,width:w,at:m,left:Bo(h,g,y>0?M:w),right:Bo(h,g,y<0?-M:-w)}}),r=[],a=[],l=(h,u)=>{r.push(h),a.push(u)};for(const h of o)l(h.left,h.at);const c=(h,u,d)=>{const f={x:-u.y,y:u.x};for(let p=1;p<qd;p++){const g=p*Math.PI/qd,m=(d?1:-1)*Math.cos(g),w=(d?1:-i)*Math.sin(g);l({x:h.center.x+h.width*(f.x*m+u.x*w),y:h.center.y+h.width*(f.y*m+u.y*w)},h.at)}};c(o.at(-1),xn(t[Math.max(0,t.length-2)],t.at(-1)),!0);for(const h of[...o].reverse())l(h.right,h.at);return c(o[0],xn(t[0],t[Math.min(1,t.length-1)]),!1),{outline:r,samples:o,positions:a}}function jd(t,e,n){const s={},i=e.height,o=e.chains.spine;if(o?.length>=2){const r=e.points["shoulder.left"],a=e.points["shoulder.right"],l=n.chains.find(f=>f.id==="arm.left")?.offset?.[0]??.07,c=Math.max(1e-6,Math.abs(l)*i*2),h=r&&a?Math.min(1,Math.hypot(r.x-a.x,r.y-a.y)/c):Math.abs(Math.cos(e.turn*Math.PI/2)),u=Math.sqrt(h*h+t.depth*t.depth*(1-h*h)),d=[k5(o[0],o[1],-.16),...o.slice(1)];s.spine=zo(fi(d),t.torso,i,u,.25)}e.chains.neck?.length>=2&&(s.neck=zo(fi(e.chains.neck),t.neck,i));for(const r of["left","right"])for(const a of["arm","leg"]){const l=e.chains[`${a}.${r}`];!l||l.length<3||(s[`${a}.${r}`]=zo(fi(l.slice(0,3)),t[a],i),a==="leg"&&l.length>3&&(s[`foot.${r}`]=zo(fi(l.slice(2)),[{at:0,width:.019},{at:1,width:.014}],i)))}return s}function Yd(t,e){let n=!1;for(let s=0,i=e.length-1;s<e.length;i=s++){const o=e[s],r=e[i];o.y>t.y!=r.y>t.y&&t.x<(r.x-o.x)*(t.y-o.y)/(r.y-o.y)+o.x&&(n=!n)}return n}function gl(t,e,n,s=0){const i=t.samples.filter(a=>a.at>=e&&a.at<=n),o=(a,l)=>{const c=a[l],h=a.center,u=Math.hypot(c.x-h.x,c.y-h.y)||1;return{x:c.x+(c.x-h.x)*s/u,y:c.y+(c.y-h.y)*s/u}},r=[...i.map(a=>o(a,"left")),...[...i].reverse().map(a=>o(a,"right"))];{const a=t.samples[0].center;for(const l of t.outline.slice(-7)){const c=Math.hypot(l.x-a.x,l.y-a.y)||1;r.push({x:l.x+(l.x-a.x)*s/c,y:l.y+(l.y-a.y)*s/c})}}return r}function Kd(t,e){t.beginPath(),t.moveTo(e[0].x,e[0].y);for(const n of e.slice(1))t.lineTo(n.x,n.y);t.closePath()}function v5(t,e,n){const s=n.shading;if(s.mode==="none"||n.fill==="none")return;const i=Math.hypot(...s.light),o={x:s.light[0]/i,y:s.light[1]/i},r=t.globalAlpha;t.save(),Kd(t,e.outline),t.clip();for(const a of["left","right"]){const l=e.samples.map(h=>h[a]),c=e.samples.map(h=>{const u=h[a],d=h.center,f=u.x-d.x,p=u.y-d.y,g=(f*o.x+p*o.y)/(Math.hypot(f,p)||1),m=Math.max(0,-g)*.44;return{x:u.x+(d.x-u.x)*m,y:u.y+(d.y-u.y)*m}});if(Kd(t,[...l,...c.reverse()]),t.fillStyle=s.shadow,t.globalAlpha=r*s.opacity,t.fill(),s.highlight>0){const h=e.samples.map(f=>{const p=f[a],g=f.center;return{x:p.x+(g.x-p.x)*.2,y:p.y+(g.y-p.y)*.2}}),u=e.samples[Math.floor(e.samples.length/2)][a],d=e.samples[Math.floor(e.samples.length/2)].center;if((u.x-d.x)*o.x+(u.y-d.y)*o.y>0){t.globalAlpha=r*s.highlight,t.strokeStyle="#ffffff",t.lineWidth=Math.max(1,e.samples[0].width*.16),t.beginPath(),t.moveTo(h[0].x,h[0].y);for(const f of h.slice(1))t.lineTo(f.x,f.y);t.stroke()}}}t.restore()}function M5(t,e,n,s){const i=s.bodyContours,o=r=>i[r]&&Yd(t,i[r].outline);if(n.startsWith("arm."))return e<.2&&o("spine");if(n.startsWith("leg."))return e<.2&&o("spine")||e>.85&&o(n.replace("leg.","foot."));if(n.startsWith("foot."))return e<.25&&o(n.replace("foot.","leg."));if(n==="neck")return e<.6&&o("spine");if(n==="spine"){if(e>.85&&o("neck"))return!0;for(const r of["left","right"]){if(e>.6&&o(`arm.${r}`)){const a=s.chains[`arm.${r}`]?.[0];if(a&&Math.hypot(a.x-t.x,a.y-t.y)<s.height*.07)return!0}if(e<.25&&o(`leg.${r}`))return!0}}return!1}function Xd(t,e,n,s,i){const o=s.bodyContours?.[i];if(!o)return!1;if(n.fill==="none"&&(e=si(t,e)),e.shape(o.outline,n.fill==="none"?null:n.fill,0),e.look==="clean"&&v5(t,o,n),(e.look!=="silhouette"||n.fill==="none")&&s.lineWidth>0){let r=[];for(let a=0;a<=o.outline.length;a++){const l=a%o.outline.length,c=o.outline[l],h=o.outline[(l+1)%o.outline.length],u={x:(c.x+h.x)/2,y:(c.y+h.y)/2};i.startsWith("arm.")&&o.positions[l]===1||M5(u,o.positions[l],i,s)?(r.length>=2&&e.line(r,s.lineWidth),r=[]):(r.length===0&&r.push(c),r.push(h))}r.length>=2&&e.line(r,s.lineWidth)}return!0}function Gd(t){return[[.01,-.12,.8],[0,-.25,.98],[-.04,-.31,.8]].map(e=>es(t,e).point)}function Ud(t,e){const n=e.shape==="angular"?S5(t,e):e.projection==="volume"?x5(t):yo(t.center.x,t.center.y,t.rx,t.ry,t.angle);if(e.projection!=="volume"||!e.nose)return n;const s=Math.cos(t.angle),i=Math.sin(t.angle),o=u=>({x:((u.x-t.center.x)*s+(u.y-t.center.y)*i)/t.rx,y:((u.x-t.center.x)*i-(u.y-t.center.y)*s)/t.ry}),r=o(Gd(t)[1]),a=Math.sign(r.x),l=r.y,c=n.flatMap((u,d)=>{const f=o(u),p=o(n[(d+1)%n.length]);if(f.y>l==p.y>l)return[];const g=(l-f.y)/(p.y-f.y);return[(f.x+(p.x-f.x)*g)*a]}),h=Math.max(0,r.x*a-Math.max(...c));return!Number.isFinite(h)||h===0?n:n.flatMap((u,d)=>{const f=n[(d+1)%n.length],p=o(u),g=o(f),m=Math.max(1,Math.ceil(Math.hypot(g.x-p.x,g.y-p.y)/.025));return Array.from({length:m},(w,v)=>{const k=v/m,y={x:u.x+(f.x-u.x)*k,y:u.y+(f.y-u.y)*k},x=o(y),P=(x.y-l+.115)/.23;if(x.x*a<.5||P<=0||P>=1)return y;const M=Math.sin(P*Math.PI)**2*h*t.rx*a;return{x:y.x+M*s,y:y.y+M*i}})})}function S5(t,e){const n=Math.min(.95,Math.max(.55,e.jawWidth??.74)),s=Math.min(.35,Math.max(.03,e.chinWidth??.14)),i=[[-1,0],[-.92,s],[-.5,n],[-.12,Math.sqrt(1-.12**2)]];for(let o=0;o<=12;o++){const r=o*Math.PI/24;i.push([Math.sin(r),Math.cos(r)])}return Vd(t,i,e.jawRoundness??0,e.projection==="volume")}function x5(t){const e=Array.from({length:41},(n,s)=>{const i=-Math.PI/2+s*Math.PI/40;return[Math.sin(i),Math.cos(i)]});return Vd(t,e,0,!0)}function Vd(t,e,n,s){const i=[];for(const[a,l]of e)for(let c=0;c<40;c++){const h=c*Math.PI/20,u=l*Math.sin(h);i.push(es(t,[l*Math.cos(h),a,s?Math.min(u,.82):u]).point)}let o=pl(i);if(n=Math.min(1,Math.max(0,n)),n===0)return o;const r=n*.25;for(let a=0;a<3;a++)o=o.flatMap((l,c)=>{const h=o[(c+1)%o.length];return[{x:l.x+(h.x-l.x)*r,y:l.y+(h.y-l.y)*r},{x:h.x+(l.x-h.x)*r,y:h.y+(l.y-h.y)*r}]});return o}function pl(t){const e=t.sort((i,o)=>i.x-o.x||i.y-o.y),n=(i,o,r)=>(o.x-i.x)*(r.y-i.y)-(o.y-i.y)*(r.x-i.x),s=i=>{const o=[];for(const r of i){for(;o.length>=2&&n(o[o.length-2],o[o.length-1],r)<=0;)o.pop();o.push(r)}return o.slice(0,-1)};return[...s(e),...s([...e].reverse())]}const Jd=.34,Kt=.12,Xt=-.4,Gt=(t,e,n)=>t[e]??n,T5=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),E5=.45,A5=.35,$5=.7,Zd=.78;function xt(t,e,n,s="cartoon"){const i=f=>Math.sqrt(Math.max(0,1-f.x*f.x-f.y*f.y));let o=es(t,[n.x,n.y,i(n)]).facing;const r=t.axes[2];s==="volume"&&n.x*r[0]>0&&(o=Math.max(o,r[2]));const a=Math.atan2(r[0],r[2]),l=Math.cos(a),c=Math.max(A5,l),h=Math.max($5,l),u=Math.cos(t.angle),d=Math.sin(t.angle);if(s==="volume"){const f=es(t,[n.x,n.y,i(n)*Zd]).point,p=Math.abs(n.x)>.1?Math.min(1,Math.max(0,o)/.25):1,g=Math.max(n.x*r[0]>0?.2:.5,l);return{facing:o,points:e.map(m=>{const w=(m.x-n.x)*g*t.rx*p,v=(m.y-n.y+r[1]*(i(m)-i(n))*Zd)*t.ry*p;return{x:f.x+w*u+v*d,y:f.y+w*d-v*u}})}}return{facing:o,points:e.map(f=>{const p=E5*Math.sin(a)+n.x*c+(f.x-n.x)*h,g=f.y+r[1]*i(f),m=p*t.rx,w=g*t.ry;return{x:t.center.x+m*u+w*d,y:t.center.y+m*d-w*u}})}}const Ve=(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}}),gi=(t,e,n,s)=>{const i=Math.min(1,Math.max(0,(s-t.x)/(n.x-t.x))),o=1-i;return o*o*t.y+2*o*i*e.y+i*i*n.y},Oe=(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}}),Tn=.05,P5=.3,I5="#e06b7d";function O5(t,e,n,s,i={},o){const r=Math.max(1,Math.min(s*.6,.14*e.rx)),a=(A,I)=>xt(e,A,I,i.projection).points,l=(A,I)=>xt(e,[],{x:A,y:I},i.projection).facing,c=Gt(n,"smile",0),h=Gt(n,"blink",0),u=Gt(n,"lookX",0),d=Gt(n,"lookY",0),f=Gt(n,"browTilt",0),p=Math.max(.2,Gt(n,"pupil",1)),g=Math.min(1,Math.max(0,Gt(n,"lid",0))),m=Math.min(1,Math.max(0,Gt(n,"bulge",0)));for(const A of[1,-1]){const I=A===1?"left":"right",C=Jd*A;if(l(C,Kt)<Tn)continue;const D={x:C,y:Kt},j=T5(Gt(n,`eye.${I}`,1),h);if(j<.2||i.style==="anime"&&g>=.98){const F=c>.5?.12:-.06;t.line(a(Ve({x:C-.12,y:Kt},{x:C,y:Kt+F},{x:C+.12,y:Kt}),D),r)}else if(i.style==="anime")_5(t,e,D,A,j,g,m,p,u,d,r,i,o);else{const F=j>1.2||m>.02,H=.13*Math.max(j,1)*(1+m*.7);F&&t.shape(a(Oe(C,Kt,H*.85,H),D),"#ffffff",r);const W=(j>1.2?.075:.1)*p*(1+m*.3),_=C+u*.08,B=Kt-d*.07,Q=Oe(_,B,W,W*1.1*Math.min(j,1));if(t.shape(a(Q,D),t.ink,0),i.inPupil&&o){const[O]=a([{x:_,y:B}],D),R=a(Q,D),z=Math.min(...R.map(K=>Math.hypot(K.x-O.x,K.y-O.y)));z>.5&&(o.save(),o.beginPath(),o.arc(O.x,O.y,z,0,Math.PI*2),o.clip(),i.inPupil(o,{x:O.x,y:O.y,r:z,side:I}),o.restore())}if(g>.02){const O=F?H*1.15:W*1.4,R=Kt+O,z=R-O*2*g,K=O*1.1;t.shape(a([{x:C-K,y:R+.02},{x:C+K,y:R+.02},{x:C+K,y:z},{x:C-K,y:z}],D),i.skin??"#ffffff",0),t.line(a([{x:C-K,y:z},{x:C+K,y:z}],D),r)}}const V=Kt+(i.style==="anime"?.38:.3)+Gt(n,`brow.${I}`,0)*.14+Math.max(0,j-1)*.12,et={x:C+A*.13,y:V},G={x:C-A*.13,y:V+f*.1};t.line(a([et,{x:(et.x+G.x)/2,y:(et.y+G.y)/2},G],{x:C,y:V}),r)}H5(t,e,n,r,i.projection),C5(t,e,i.ageLines??0,r,i.projection);const w={x:0,y:Xt};if(l(0,Xt)<-Tn)return;i.nose&&l(0,Kt-.15)>=Tn&&(i.projection==="volume"?t.line(Gd(e),r):t.line(a([{x:.01,y:Kt-.1},{x:.03,y:Xt+.2},{x:-.05,y:Xt+.17}],{x:0,y:Xt+.22}),r));const v=.25*Math.max(.3,Gt(n,"mouthWidth",1)),k=Math.min(1,Math.max(0,Gt(n,"mouth",0)));if(k<=.05){t.line(a(Ve({x:-v,y:Xt},{x:0,y:Xt-c*.25},{x:v,y:Xt}),w),r);return}const y=.3*k;let x,P,M,T;if(c>.3){const A=Xt+.05,I={x:0,y:Xt-y*2};x=[...Ve({x:v,y:A},I,{x:-v,y:A})],P=()=>A,M=C=>gi({x:v,y:A},I,{x:-v,y:A},C),T=.85}else if(c<-.3){const A=Xt-y*.6,I={x:0,y:Xt+y*1.4};x=[...Ve({x:v,y:A},I,{x:-v,y:A})],P=C=>gi({x:v,y:A},I,{x:-v,y:A},C),M=()=>A,T=.5}else{const A=v*.8;x=Oe(0,Xt,A,y);const I=C=>y*Math.sqrt(Math.max(0,1-(C/A)**2));P=C=>Xt+I(C),M=C=>Xt-I(C),T=.5}if(t.shape(a(x,w),t.ink,0),k<P5)return;const S=P(0)-M(0),E=v*T,$=(A,I,C=8)=>Array.from({length:C+1},(D,j)=>A+(I-A)*j/C);if(i.tongue){const A=E*.55,I=$(A,-A).map(D=>({x:D,y:M(D)})),C=Ve({x:-A,y:M(-A)},{x:0,y:M(0)+S*.8},{x:A,y:M(A)},8);t.shape(a([...I,...C.slice(1,-1)],w),I5,0)}if(i.teeth){const A=Math.min(.06,S*.4),I=$(-E,E).map(D=>({x:D,y:P(D)})),C=I.map(({x:D,y:j})=>({x:D*.92,y:j-A})).reverse();t.shape(a([...I,...C],w),"#ffffff",0);for(const D of[-.5,0,.5]){const j=E*D;t.line(a([{x:j,y:P(j)},{x:j*.92,y:P(j)-A}],w),r*.6)}}}function _5(t,e,n,s,i,o,r,a,l,c,h,u,d){const{x:f,y:p}=n,g=Math.min(1.2,Math.max(.5,u.eyeScale??1)),m=Math.min(1.2,Math.max(.45,u.eyeAspect??1)),w=.21*g*(1+r*.15),v=.25*g*m*Math.min(i,1.6)*(1-o)*(1+r*.3),k={x:f-w,y:p},y={x:f+w,y:p},x={x:f,y:p+v*1.9},P={x:f,y:p-v*1.35},M=Ve(k,x,y),T=Ve(y,P,k),S=V=>xt(e,V,n,u.projection).points,E=V=>V.map(et=>{const G=Math.min(y.x,Math.max(k.x,et.x));return{x:G,y:Math.min(gi(k,x,y,G),Math.max(gi(y,P,k,G),et.y))}});t.shape(S([...M,...T.slice(1,-1)]),"#ffffff",h*.5);const $=f+Math.max(-1,Math.min(1,l))*.07*g,A=p-Math.max(-1,Math.min(1,c))*.055*g,I=.115*g,C=.185*g;t.shape(S(E(Oe($,A,I,C,24))),u.iris??"#4b7fce",h*.4),t.shape(S(E(Oe($,A-.075*g,I*.7,C*.35))),"rgba(255,255,255,0.25)",0);const D=Math.min(.085,.042*a)*g,j=E(Oe($,A,D,D*1.35));if(t.shape(S(j),t.ink,0),u.inPupil&&d){const[V]=S([{x:$,y:A}]),et=Math.min(...S(j).map(G=>Math.hypot(G.x-V.x,G.y-V.y)));et>.5&&(d.save(),d.beginPath(),d.arc(V.x,V.y,et,0,Math.PI*2),d.clip(),u.inPupil(d,{...V,r:et,side:s===1?"left":"right"}),d.restore())}if(t.shape(S(E(Oe($-.038*g,A+.075*g,.035*g,.045*g))),"#ffffff",0),t.shape(S(E(Oe($+.04*g,A-.04*g,.014*g,.02*g))),"#ffffff",0),t.line(S(M),h*1.1),u.lashes!==!1)for(const V of[0,.035]){const et=f+s*(w-V),G=gi(k,x,y,et);t.line(S([{x:et,y:G},{x:et+s*.055,y:G+.07}]),h*.75)}}function C5(t,e,n,s,i){const o=Math.min(1,Math.max(0,n));if(!(o<=0))for(const r of[-1,1]){const a={x:r*.59,y:Kt};if(xt(e,[],a,i).facing<Tn)continue;for(const h of[-.06,.035]){const u=[{x:a.x,y:a.y},{x:a.x+r*.1,y:a.y+h}];t.line(xt(e,u,a,i).points,s*.45*o)}const l={x:r*.3,y:-.38},c=Ve({x:l.x,y:-.31},{x:l.x+r*.07,y:-.4},{x:l.x+r*.035,y:-.49});t.line(xt(e,c,l,i).points,s*.35*o)}}const Qd="#8fd0f5",tf=(t,e,n)=>Array.from({length:18},(s,i)=>{const o=Math.PI*2*i/18,r=Math.sin(o/2);return{x:t+Math.sin(o)*n*r,y:e-n*.9+Math.cos(o)*n*1.6*(.55+.45*r)-n*.4}});function H5(t,e,n,s,i){const o=Math.min(1,Math.max(0,Gt(n,"blush",0))),r=Math.min(1,Math.max(0,Gt(n,"tears",0))),a=Math.min(1,Math.max(0,Gt(n,"sweat",0)));if(!(o+r+a<=.01)){for(const l of[1,-1]){const c={x:.5*l,y:-.16},h=xt(e,[],c,i).facing>=Tn;if(o>.01&&h){const{points:d}=xt(e,Oe(c.x,c.y,.17,.1),c,i);if(t.shape(d,`rgba(240, 120, 140, ${(.75*o).toFixed(3)})`,0),o>.5)for(const f of[-.07,0,.07]){const p=[{x:c.x+f-.018,y:c.y-.03},{x:c.x+f+.018,y:c.y+.03}];t.line(xt(e,p,c,i).points,s*.3)}}const u={x:Jd*l,y:Kt};if(r>.01&&xt(e,[],u,i).facing>=Tn){const d=.05+.04*r,f={x:u.x+.06*l,y:Kt-.2-.12*r};if(t.shape(xt(e,tf(f.x,f.y,d),f,i).points,Qd,s*.35),r>.6){const p=[{x:u.x+.05*l,y:Kt-.1},{x:f.x,y:f.y+d*.8}];t.line(xt(e,p,f,i).points,s*.3)}}}if(a>.01){const l={x:.64,y:.42};xt(e,[],l,i).facing>=Tn&&t.shape(xt(e,tf(l.x,l.y,.05+.05*a),l,i).points,Qd,s*.35)}}}const R5=15;function Se(t,e){const n=Math.sqrt(Math.max(0,1-e*e));return[n*Math.sin(t),e,n*Math.cos(t)]}const L5=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function te(t,[e,n,s]){const[i,o,r]=t.axes;return i[2]*e+o[2]*n+r[2]*s}function _t(t,e){return es(t,e).point}function qo(t,e){const n=Math.abs(t-e)%(Math.PI*2);return n>Math.PI?Math.PI*2-n:n}function jo(t,e,n=64){const s=e.top??1,i=e.bottom??-1,o=Math.max(8,Math.ceil((s-i)*R5)),r=p=>Math.min(s,Math.max(i,s-(s-i)*(p-1)/o)),a=p=>-Math.PI+Math.PI*2*p/n,l=(p,g)=>e.normal?e.normal(p,g):L5(e.position(p,g)),c=o+3,h=new Float64Array(n*c),u=new Float64Array(n*c);for(let p=0;p<c;p++){const g=p===0||p===c-1,m=r(p);for(let w=0;w<n;w++){const v=p*n+w;if(g){h[v]=-1;continue}const k=a(w);h[v]=e.inside(k,m),u[v]=h[v]>-.35?te(t,l(k,m)):0}}const d=p=>(p%n+n)%n,f=p=>{const g=n+1,m=new Float64Array(g*c);for(let A=0;A<c;A++)for(let I=0;I<=n;I++){const C=A*n+(I===n?0:I);m[A*g+I]=Math.min(h[C],p*u[C])}const w=(A,I)=>m[I*g+A],v=(A,I,C,D)=>{const j=w(A,I),V=w(C,D),et=j===V?.5:Math.min(1,Math.max(0,j/(j-V)));return _t(t,e.position(a(A+(C-A)*et),r(I+(D-I)*et)))},k=n*c*2,y=new Int32Array(k).fill(-1),x=new Int32Array(k).fill(-1),P=new Map,M=(A,I,C)=>{const D=(C*n+d(I))*2+(A?1:0);return P.has(D)||P.set(D,A?v(d(I),C,d(I),C+1):v(I,C,I+1,C)),D},T=(A,I)=>{y[A]===-1?y[A]=I:x[A]=I},S=(A,I)=>{T(A,I),T(I,A)};for(let A=0;A<c-1;A++)for(let I=0;I<n;I++){const C=A*g+I,D=(m[C]>0?8:0)|(m[C+1]>0?4:0)|(m[C+g+1]>0?2:0)|(m[C+g]>0?1:0);if(D===0||D===15)continue;const j=()=>M(!1,I,A),V=()=>M(!1,I,A+1),et=()=>M(!0,I,A),G=()=>M(!0,I+1,A);switch(D){case 1:case 14:S(et(),V());break;case 2:case 13:S(V(),G());break;case 3:case 12:S(et(),G());break;case 4:case 11:S(j(),G());break;case 6:case 9:S(j(),V());break;case 7:case 8:S(et(),j());break;case 5:case 10:{const F=(w(I,A)+w(I+1,A)+w(I+1,A+1)+w(I,A+1))/4>0;D===5===F?(S(et(),j()),S(V(),G())):(S(et(),V()),S(j(),G()));break}}}const E=[],$=new Uint8Array(k);for(const A of P.keys()){if($[A])continue;const I=[];let C=-1,D=A;for(;D!==-1&&!$[D];){$[D]=1,I.push(P.get(D));const j=y[D],V=x[D],et=j!==-1&&j!==C&&!$[j]?j:V!==-1&&V!==C&&!$[V]?V:-1;C=D,D=et}I.length>=3&&E.push(I)}return E};return{near:f(1),far:f(-1)}}const ef=new WeakMap;function ml(t,e,n){let s=ef.get(t);s||ef.set(t,s=new Map);let i=s.get(e);return i||s.set(e,i=n()),i}function yl(t,e,n,s){if(t.save(),t.beginPath(),t.rect(-1e5,-1e5,2e5,2e5),s?.length){t.moveTo(s[0].x,s[0].y);for(const i of s.slice(1))t.lineTo(i.x,i.y);t.closePath()}else t.ellipse(e.center.x,e.center.y,e.rx,e.ry,e.angle,0,Math.PI*2);t.clip("evenodd"),n(),t.restore()}function nf(t,e,n,s=.04){const i=[];let o=[];return e.forEach((r,a)=>{te(t,n[a])>s?o.push(_t(t,r)):(o.length>=2&&i.push(o),o=[])}),o.length>=2&&i.push(o),i}const sf=t=>t*Math.PI/180,bl=t=>{const e=Math.hypot(...t)||1;return t.map(n=>n/e)},F5=(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]];function of(t,e,n){return t>=e+n?t:t<=e-n?e:e+(t-e+n)**2/(4*n)}function wl(t,e,n){const s=bl(n),i=t.reduce((c,h,u)=>c+h*s[u],0),r=t.map((c,h)=>c-i*s[h]).reduce((c,h)=>c+h*h,0),a=Math.sqrt(of(1-r,e*e,e*e)),l=of(i,a,e)-i;return l===0?t:t.map((c,h)=>c+s[h]*l)}function N5(t){if(t.path.length<4||(t.path.length-1)%3!==0)throw new Error("hair: a lock path needs a root and groups of three cubic points");if(!Number.isFinite(t.width)||t.width<=0||t.follow!==void 0&&(!Number.isFinite(t.follow)||t.follow<0))throw new Error("hair: lock width must be positive and follow must be nonnegative");for(const n of t.path)if(!Number.isFinite(n.around)||!Number.isFinite(n.up)||n.up>1||n.lift!==void 0&&(!Number.isFinite(n.lift)||n.lift<0))throw new Error("hair: lock points need finite around/up values, up <= 1 and nonnegative lift");const e=t.path[0];if(e.up<0||(e.lift??0)!==0)throw new Error("hair: a lock root must lie on the scalp (up 0..1, lift 0)");return{...t,path:t.path.map(n=>({...n}))}}function W5(t,e,n,s){const i=(t.path.length-1)/3,o=i*20,r=[],a=[],l=s.trail!==0||s.lift!==0,c=Math.max(0,e+n);for(let h=0;h<=o;h++){const u=h/o,d=Math.min(i-1,Math.floor(u*i)),f=u*i-d,p=1-f,g=[p**3,3*p*p*f,3*p*f*f,f**3],m=t.path.slice(d*3,d*3+4),w=sf(m.reduce((C,D,j)=>C+D.around*g[j],0)),v=m.reduce((C,D,j)=>C+D.up*g[j],0),k=m.reduce((C,D,j)=>C+(D.lift??0)*g[j],0),y=1+e+n+k,x=v>=0?Math.sqrt(Math.max(0,1-v*v)):1,P=u*u*(t.follow??1),M=sf(s.swing)*P,T=w-M,S=[Math.sin(T)*x*y,v*(v>=0?y:1),Math.cos(T)*x*y],E=[S[0],S[1]+s.lift*P,S[2]-s.trail*P],$=[Math.sin(T)*x,Math.max(0,v),Math.cos(T)*x],A=bl(S),I=l&&P>0?wl(E,c,A):E;a.push(A),r.push({center:I,normal:$,left:I,right:I,t:u})}return r.forEach((h,u)=>{const d=r[Math.max(0,u-1)].center,p=r[Math.min(o,u+1)].center.map((w,v)=>w-d[v]),g=bl(F5(h.normal,p)),m=t.width*Math.sin(Math.PI*h.t)**.6*.5;h.left=h.center.map((w,v)=>w+g[v]*m),h.right=h.center.map((w,v)=>w-g[v]*m),l&&h.t>0&&(t.follow??1)>0&&(h.left=wl(h.left,c,a[u]),h.right=wl(h.right,c,a[u]))}),r}const os=(t,e,n)=>t.map((s,i)=>s+(e[i]-s)*n);function D5(t,e,n){const s=n?1:-1,i=[];let o=[];for(let r=0;r<e.length;r++){const a=e[r],l=s*te(t,a.normal)>=0;if(r>0){const c=e[r-1],h=s*te(t,c.normal),u=s*te(t,a.normal);if(h>=0!==l){const d=h/(h-u),f={center:os(c.center,a.center,d),left:os(c.left,a.left,d),right:os(c.right,a.right,d),normal:os(c.normal,a.normal,d),t:c.t+(a.t-c.t)*d};l?o=[f]:(o.push(f),o.length>=2&&i.push(o),o=[])}}l&&o.push(a)}return o.length>=2&&i.push(o),i}function rf(t,e,n,s,i,o,r){const a=(n.locks??[]).map(h=>W5(h,n.volume,s,i)),l=h=>h.reduce((u,d)=>u+te(e,d.center),0)/h.length;a.sort((h,u)=>l(h)-l(u));const c=Math.max(.7,o*.35);for(const h of a)for(const u of D5(e,h,r)){const d=u.map(g=>_t(e,g.left)),f=u.map(g=>_t(e,g.right));if(t.shape([...d,...f.slice().reverse()],n.color,0),t.look==="clean"&&(n.shine??0)>0){const g=u.filter(m=>m.t>=.2&&m.t<=.75);if(g.length>=3){const m=g.map((v,k)=>{const y=.16*Math.sin(Math.PI*k/(g.length-1));return _t(e,os(v.center,v.left,.16+y))}),w=g.map(v=>_t(e,os(v.center,v.left,.16)));t.shape([...m,...w.reverse()],`rgba(255,255,255,${n.shine})`,0)}}const p=u.filter(g=>g.t>.3);p.length>=2&&t.line(p.map(g=>_t(e,g.left)),c)}}const Pt=(t,e,n=0)=>({around:t,up:e,lift:n}),kl=()=>[{width:.66,follow:.22,path:[Pt(-38,.88),Pt(-12,.94,.08),Pt(58,.76,.09),Pt(94,.16,.03)]},{width:.58,follow:.3,path:[Pt(-42,.8),Pt(-24,.7,.12),Pt(18,.57,.09),Pt(64,.3)]},{width:.36,follow:.18,path:[Pt(-58,.76),Pt(-76,.56,.07),Pt(-90,.12,.06),Pt(-102,-.36)]}];function af(t){return[-100,-130,-160,-190,-220,-250,-280].map((e,n)=>{const s=n%2===0?1:-1,i=t?-2.45-n%3*.12:-1.06-n%3*.09;return{width:t?.88:.92,follow:t?.8+n%3*.12:.38+n%3*.08,path:t?[Pt(e,.7),Pt(e+s*9,.2,.12),Pt(e-s*13,-.5,.2),Pt(e-s*8,-.95,.16),Pt(e-s*3,-1.4,.12),Pt(e+s*18,i+.35,.22),Pt(e+s*12,i,.03)]:[Pt(e,.7),Pt(e+s*7,.15,.2),Pt(e-s*8,-.75,.25),Pt(e+s*5,i)]}})}const B5={softSweep:{volume:.12,shine:.16,part:-38,strands:"part",sweep:-.08,hairline:{front:.64,side:.12,back:-.8},locks:kl()},flowingBob:{volume:.15,shine:.16,length:.96,fall:{taper:.08,wave:.08},part:-38,strands:"part",sweep:-.08,hairline:{front:.64,side:.08,back:-.8},coversEars:!0,locks:[...af(!1),...kl()]},cascadingWaves:{volume:.16,shine:.16,length:2.38,fall:{taper:.18,wave:.12},part:-38,strands:"part",sweep:-.08,hairline:{front:.64,side:.08,back:-.8},coversEars:!0,locks:[...af(!0),...kl()]}},rs={swing:0,trail:0,lift:0};function pi(t){if(!t)return rs;const e=t["hair.swing"]??0,n=t["hair.trail"]??0,s=t["hair.lift"]??0;return e===0&&n===0&&s===0?rs:{swing:e,trail:n,lift:s}}const lf=t=>t.swing===0&&t.trail===0&&t.lift===0;function cf(t){return t.length>0||t.ties.some(e=>e.kind!=="bun")||(t.locks??[]).some(e=>(e.follow??1)>0)}function vl([t,e,n],s){if(s===0)return[t,e,n];const i=Math.cos(s),o=Math.sin(s);return[t*i-n*o,e,n*i+t*o]}const hf={color:"#6b4630",volume:.1,hairline:{front:.5,side:.12,back:-.82},sweep:0,recede:0,length:0,opening:84,texture:"smooth",textureAmount:0,quiff:0,flat:0,part:null,strands:"none",fill:"solid",ties:[],coversEars:!1},uf=1.75,Ml={...B5,bald:{volume:0,hairline:{front:2,side:2,back:2}},buzzCut:{volume:0,fill:"stipple",hairline:{front:.52,side:.1,back:-.8}},crewCut:{volume:.1,texture:"spiky",textureAmount:.07,hairline:{front:.55,side:.1,back:-.8}},short:{volume:.12,texture:"spiky",textureAmount:.1,hairline:{front:.42,side:.1,back:-.82},sweep:.12},sidePart:{volume:.14,part:35,strands:"sweep",sweep:-.22,hairline:{front:.5,side:.08,back:-.82}},sideSwept:{volume:.15,part:45,strands:"sweep",sweep:-.38,hairline:{front:.42,side:.05,back:-.82}},slickBack:{volume:.12,strands:"combed",hairline:{front:.62,side:.15,back:-.8}},quiff:{volume:.12,quiff:.42,strands:"combed",hairline:{front:.6,side:.15,back:-.8}},spiky:{volume:.12,texture:"spiky",textureAmount:.34,hairline:{front:.5,side:.12,back:-.8}},mangaSpikes:{volume:.12,texture:"spiky",textureAmount:.08,hairline:{front:.55,side:.12,back:-.7},spikes:[{around:-100,up:.4,length:.55,width:.24},{around:-65,up:.7,length:.6,width:.25},{around:-25,up:.93,length:.6,width:.24},{around:40,up:.87,length:.7,width:.25},{around:85,up:.55,length:.55,width:.24},{around:160,up:.8,length:.5,width:.24},{around:-160,up:.65,length:.55,width:.24}]},mangaSweep:{volume:.14,texture:"spiky",textureAmount:.1,sweep:-.35,hairline:{front:.5,side:.08,back:-.8},spikes:[{around:-95,up:.45,length:.35,width:.2},{around:-60,up:.8,length:.4,width:.24},{around:75,up:.55,length:.4,width:.23},{around:150,up:.75,length:.35,width:.2}]},undercut:{volume:.16,quiff:.18,part:40,strands:"sweep",sweep:-.15,hairline:{front:.55,side:.42,back:-.3}},curlyCrop:{volume:.14,texture:"curly",textureAmount:.12,hairline:{front:.5,side:.1,back:-.8}},afro:{volume:.5,texture:"curly",textureAmount:.12,hairline:{front:.5,side:-.1,back:-.85},coversEars:!0},wavyCrop:{volume:.16,texture:"wavy",textureAmount:.08,part:30,hairline:{front:.45,side:.05,back:-.82}},shortLocs:{volume:.16,texture:"locs",textureAmount:.1,hairline:{front:.38,side:-.25,back:-.85},strands:"hanging",coversEars:!0},flatTop:{volume:.1,flat:.42,hairline:{front:.5,side:.15,back:-.78}},receding:{volume:.14,recede:.28,strands:"thin",hairline:{front:.74,side:.1,back:-.8}},thinning:{volume:.05,strands:"thin",hairline:{front:.72,side:.05,back:-.78}},pixie:{volume:.16,texture:"spiky",textureAmount:.07,sweep:.3,hairline:{front:.32,side:-.1,back:-.82}},bob:{volume:.2,length:1.05,opening:84,sweep:.2,part:-25,hairline:{front:.34,side:.05,back:-.85},coversEars:!0},longBob:{volume:.18,length:1.35,opening:84,part:0,strands:"part",hairline:{front:.5,side:.05,back:-.85},coversEars:!0},wavyBob:{volume:.22,length:1.2,opening:84,part:18,texture:"wavy",textureAmount:.1,hairline:{front:.45,side:.05,back:-.85},coversEars:!0},shoulderStraight:{volume:.16,length:uf,opening:84,part:0,strands:"part",hairline:{front:.5,side:.05,back:-.85},coversEars:!0},shoulderWaves:{volume:.22,length:uf,opening:84,part:22,texture:"wavy",textureAmount:.12,hairline:{front:.45,side:.05,back:-.85},coversEars:!0},longStraight:{volume:.14,length:2.6,opening:84,part:0,strands:"hanging",hairline:{front:.5,side:.05,back:-.85},coversEars:!0},longWaves:{volume:.2,length:2.5,opening:84,part:20,texture:"wavy",textureAmount:.14,hairline:{front:.45,side:.05,back:-.85},coversEars:!0},longCurls:{volume:.26,length:2.5,opening:84,texture:"curly",textureAmount:.13,hairline:{front:.45,side:.05,back:-.85},coversEars:!0},longLocs:{volume:.2,length:2.6,opening:84,texture:"locs",textureAmount:.12,strands:"hanging",part:0,hairline:{front:.45,side:.05,back:-.85},coversEars:!0},lowPonytail:{volume:.12,part:0,strands:"combed",hairline:{front:.5,side:.1,back:-.82},ties:[{kind:"ponytail",at:"low",length:1.5}]},highPonytail:{volume:.12,part:18,strands:"combed",hairline:{front:.45,side:.1,back:-.78},ties:[{kind:"ponytail",at:"high",length:2}]},ponytail:{volume:.12,sweep:.2,hairline:{front:.42,side:.1,back:-.78},ties:[{kind:"ponytail",at:"high",length:1.8}]},sidePonytail:{volume:.12,part:-20,strands:"combed",hairline:{front:.45,side:.1,back:-.82},ties:[{kind:"ponytail",at:"left",length:1.5}]},topBun:{volume:.12,part:0,strands:"combed",hairline:{front:.5,side:.1,back:-.8},ties:[{kind:"bun",at:"top",size:.32}]},lowBun:{volume:.12,part:0,strands:"combed",hairline:{front:.5,side:.1,back:-.8},ties:[{kind:"bun",at:"low",size:.34}]},singleBraid:{volume:.12,part:0,strands:"combed",hairline:{front:.5,side:.1,back:-.82},ties:[{kind:"braid",at:"low",length:2.2}]},twinBraids:{volume:.12,part:0,strands:"part",hairline:{front:.5,side:.05,back:-.82},ties:[{kind:"braid",at:"left",length:1.9},{kind:"braid",at:"right",length:1.9}],coversEars:!0},braids:{volume:.12,part:0,strands:"part",hairline:{front:.5,side:.05,back:-.82},ties:[{kind:"braid",at:"left",length:1.6},{kind:"braid",at:"right",length:1.6}],coversEars:!0}},xe={black:"#22201f",brown:"#6b4630",chestnut:"#7b4a2b",auburn:"#9a4426",blond:"#d9b55a",ginger:"#c8662f",gray:"#a7a29c",white:"#ecebe7"};function df(t){const e=typeof t=="string"?{style:t}:t,n=e.style?Ml[e.style]:{};if(e.style&&!n)throw new Error(`hair: unknown style '${e.style}'`);const{style:s,hairline:i,...o}=e,r={...hf,...n,...o,hairline:{...hf.hairline,...n.hairline,...i},ties:(o.ties??n.ties??[]).map(a=>({...a})),...o.spikes??n.spikes?{spikes:(o.spikes??n.spikes).map(a=>({...a}))}:{},...o.locks??n.locks?{locks:(o.locks??n.locks).map(N5)}:{},...o.fall??n.fall?{fall:{...o.fall??n.fall}}:{}};if(r.shine!==void 0&&(!Number.isFinite(r.shine)||r.shine<0||r.shine>1))throw new Error("hair: shine must be between 0 and 1");if(r.fall&&(!Number.isFinite(r.fall.taper)||r.fall.taper<0||r.fall.taper>1||!Number.isFinite(r.fall.wave)||r.fall.wave<0))throw new Error("hair: fall needs taper between 0 and 1 and nonnegative wave");return r}const En=t=>t*Math.PI/180,as=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},Sl=t=>1-Math.abs(2*(t-Math.floor(t))-1);function mi(t,e){const{front:n,side:s,back:i}=t.hairline,o=(n-i)/2,r=(n+i)/2,a=(r+s)/2,l=(r-s)/2,c=Math.max(0,Math.cos(e));let h=a+o*Math.cos(e)+l*Math.cos(2*e);return h-=t.sweep*Math.sin(e)*c,h+=t.recede*Math.exp(-(((Math.abs(e)-.75)/.32)**2)),(t.texture==="spiky"||t.texture==="curly")&&(h-=t.textureAmount*.6*Sl(e*11/(Math.PI*2))*c),h}function ff(t,e,n){const s=t.textureAmount;switch(t.texture){case"spiky":return s*(Sl(e*11/(Math.PI*2))*Sl(n*2.6+.5))**1.2*as(-.3,.4,n);case"curly":return s*Math.sqrt(Math.abs(Math.sin(e*7))*Math.abs(Math.sin(n*Math.PI*2.6)));case"wavy":return s*(.5+.5*Math.sin(e*6+n*6));case"locs":return s*Math.abs(Math.sin(e*10))**.6;default:return 0}}function gf(t,e,n=rs){const s=t.length>0,i=new Map,o=h=>{let u=i.get(h);return u===void 0&&i.set(h,u=mi(t,h)),u},r=En(t.opening),a=h=>t.length+(t.texture==="wavy"||t.texture==="curly"||t.texture==="locs"?.12*Math.sin(h*9):0)+(t.fall?.wave??0)*Math.cos(h*3+.6),l=(h,u,d)=>{if(t.flat<=0||u<.45)return null;const f=(u-.45)/.55,p=Math.sqrt(1-.45*.45)*d*(1-f**5),g=.45+(1+t.flat-.45)*Math.min(1,f*1.8);return[p*Math.sin(h),g*(1+e),p*Math.cos(h)]},c={top:1,bottom:s?-(t.length+.25+Math.abs(t.fall?.wave??0)):-1,inside(h,u){const d=u-o(h);if(!s)return d;const f=Math.min(u+a(h),qo(h,0)-r);return Math.max(d,f)},position(h,u){if(s&&u<0){const k=t.length<1.5?.14*as(-t.length+.45,-t.length-.1,u):0,y=(t.fall?.taper??0)*as(0,-Math.max(.1,a(h)),u),x=1+e+t.volume*(1-k*2.5)+ff(t,h,u)-k-y;return[x*Math.sin(h),u,x*Math.cos(h)]}const d=.4+.6*as(0,.3,u-mi(t,h)),f=1+e+(t.volume+ff(t,h,u))*d,p=l(h,u,f);if(p)return p;const[g,m,w]=Se(h,u),v=[g*f,m*f,w*f];if(t.quiff>0){const k=t.quiff*Math.exp(-((h/.7)**2))*as(.15,.85,u);v[1]+=k*.7,v[2]+=k*.45}return v},normal(h,u){return s&&u<0?[Math.sin(h),0,Math.cos(h)]:Se(h,u)}};return s&&!lf(n)?z5(c,t,n):c}function z5(t,e,n){const s=o=>o<0?as(-.15,-Math.max(.7,e.length),o):0,i=o=>En(n.swing)*s(o);return{top:t.top,bottom:t.bottom,inside:(o,r)=>t.inside(o+i(r),r),position(o,r){const a=s(r);if(a===0)return t.position(o,r);const l=i(r),[c,h,u]=vl(t.position(o+l,r),l);return[c,h+n.lift*a,u-n.trail*a]},normal:(o,r)=>vl(t.normal(o+i(r),r),i(r))}}const q5=t=>t.texture==="spiky"||t.texture==="curly"||t.texture==="locs"?104:t.texture==="wavy"?80:64;function pf(t,e,n,s){return ml(t,Y5(e,s),()=>jo(t,n,q5(e)))}const mf=new WeakMap;let j5=1;function Y5(t,e){if(lf(e))return t;let n=mf.get(t);return n||mf.set(t,n=j5++),`${n}:${e.swing}:${e.trail}:${e.lift}`}function yf(t){switch(t){case"top":return{point:[0,1.02,-.12],out:[0,1,-.15]};case"high":return{point:[0,.72,-.78],out:[0,.55,-.85]};case"low":return{point:[0,-.2,-1.02],out:[0,-.1,-1]};case"left":return{point:[.82,-.32,-.45],out:[.8,-.2,-.5]};case"right":return{point:[-.82,-.32,-.45],out:[-.8,-.2,-.5]}}}function xl(t,[e,n,s]){const i=_t(t,[e,n,s]);return{x:i.x-t.center.x,y:i.y-t.center.y}}function K5(t,e,n,s=16){return 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}})}function X5(t,e,n,s,i){const o=t.ry,r=(e.length??1.8)*o,a=xl(t,vl(s,En(i.swing))),l=xl(t,[0,i.lift,-i.trail]),c=Math.hypot(a.x,a.y)||1,h=e.at==="high"||e.at==="low"||e.at==="top"?xl(t,[.95,0,0]):{x:0},u=e.kind==="braid"?.15:.5,d={x:n.x+a.x/c*o*u+h.x*.9+l.x*.5,y:n.y+a.y/c*o*u*.6+l.y*.5},f={x:n.x+a.x/c*o*u*.6+h.x*1.3+l.x,y:n.y+r+l.y};return K5(n,d,f)}const Yo=t=>Math.max(1,t*.5),bf=(t,e)=>Math.max(.8,Math.min(t*.4,.1*e.rx));function wf(t,e,n,s,i,o){const{point:r,out:a}=yf(s.at),l=1+n.volume,c=_t(e,[r[0]*l,r[1]*l,r[2]*l]),h=Yo(i),u=bf(i,e);if(s.kind==="bun"){const g=s.size??.32,m=_t(e,[r[0]*l+a[0]*g,r[1]*l+a[1]*g,r[2]*l+a[2]*g]);t.ellipse(m.x,m.y,g*e.rx,g*e.ry,e.angle,n.color,h);const w=g*e.rx*.55;t.line(Array.from({length:9},(v,k)=>{const y=-.4+k/8*Math.PI*1.3;return{x:m.x+Math.cos(y)*w,y:m.y+Math.sin(y)*w*.8}}),u);return}const d=X5(e,s,c,a,o),f=(s.size??(s.kind==="braid"?.2:.34))*e.rx*2;if(s.kind==="ponytail")t.shape(zt(d,f,f*.15),n.color,h),t.line(d.slice(3,d.length-3),u);else{const m=d.slice(0,d.length-3);for(let k=0;k<7;k++){const y=m[Math.floor(k/7*(m.length-1))],x=m[Math.floor((k+1)/7*(m.length-1))],P=Math.atan2(x.y-y.y,x.x-y.x),M=Math.hypot(x.x-y.x,x.y-y.y),T=f*(1-k/(7*2.2)),S=(k%2===0?1:-1)*.35,E={x:(y.x+x.x)/2,y:(y.y+x.y)/2};t.ellipse(E.x,E.y,M*.62,T*.5,P+S,n.color,h*.8)}const w=m[m.length-1],v=d[d.length-1];t.shape(zt([w,v],f*.7,f*.2),n.color,h*.8)}const p=d[s.kind==="braid"?d.length-4:2];t.ellipse(p.x,p.y,f*.32,f*.22,e.angle,n.color,h)}function kf(t,e){return te(t,yf(e.at).out)<-.2}function G5(t){const e=(i,o,r=0,a=14)=>Array.from({length:a+1},(l,c)=>{const h=c/a;return[i[0]+(o[0]-i[0])*h+r*Math.sin(Math.PI*h),i[1]+(o[1]-i[1])*h]}),n=En(t.part??0),s=i=>mi(t,i)+.04;switch(t.strands){case"part":return[e([n,s(n)],[n,.97])];case"sweep":{const i=Math.sign(t.sweep||-1),o=[.9,.72,.55].map((r,a)=>{const l=n+i*(.6+a*.35);return e([n,r],[l,Math.max(s(l)+.05,r-.35)],.05*i)});return[e([n,s(n)],[n,.97]),...o]}case"combed":return[-.75,-.35,.35,.75].map(i=>e([i,s(i)+.02],[i*.3,.86]));case"thin":return[-.5,.05,.6].map(i=>e([i,s(i)+.02],[i*.5,.95],.12));case"hanging":{const i=t.length>0?-t.length+.25:-.4,o=[-2.6,-2,-1.4,1.4,2,2.6,3.05].map(r=>e([r,mi(t,r)<.9?.6:.9],[r,i],0));return t.part!==null&&o.push(e([n,s(n)],[n,.97])),o}default:return[]}}function U5(t,e,n,s,i){if(s.fill==="stipple"||s.hairline.front>1.5)return;const o=i.motion??rs,r=i.lineWidth*.45/n.rx,{far:a}=pf(n,s,gf(s,r,o),o);yl(e,n,()=>{for(const l of s.ties)kf(n,l)&&wf(t,n,s,l,i.lineWidth,o);vf(t,n,s,i.lineWidth,r,!1);for(const l of a)t.shape(l,s.color,Yo(i.lineWidth));rf(t,n,s,r,o,i.lineWidth,!1)},i.headOutline)}function Tl(t,e,n,s){if(n.hairline.front>1.5)return;const i=s.motion??rs,o=s.lineWidth*.45/e.rx,r=gf(n,o,i),a=bf(s.lineWidth,e);if(n.fill==="stipple"){for(let h=.97;h>-1;h-=.17)for(let u=-Math.PI;u<Math.PI;u+=.27){const d=Math.round(h*100)%2*.13;if(r.inside(u+d,h)<.02)continue;const f=Se(u+d,h);if(te(e,f)<.12)continue;const p=_t(e,f);t.dot(p.x,p.y,a*.4)}return}const{near:l}=pf(e,n,r,i),c=Yo(s.lineWidth);vf(t,e,n,s.lineWidth,o,!0);for(const h of l)t.shape(h,n.color,c);rf(t,e,n,o,i,s.lineWidth,!0);for(const h of G5(n)){const u=h.map(([f,p])=>{const[g,m,w]=r.position(f,p);return[g*.985,m*.985,w*.985]}),d=h.map(([f,p])=>r.normal(f,p));for(const f of nf(e,u,d,.12))t.line(f,a)}for(const h of n.ties)kf(e,h)||wf(t,e,n,h,s.lineWidth,i)}function vf(t,e,n,s,i,o){for(const r of n.spikes??[]){const a=Se(En(r.around),Math.max(-1,Math.min(1,r.up)));if(te(e,a)>=0!==o)continue;const l=[Math.cos(En(r.around)),0,-Math.sin(En(r.around))],c=[a[1]*l[2],a[2]*l[0]-a[0]*l[2],-a[1]*l[0]],h=1+n.volume+i,u=Math.max(0,r.width),d=Math.max(0,r.length),f=[_t(e,a.map(p=>p*(h+d)))];for(let p=0;p<8;p++){const g=p*Math.PI/4,m=a.map((w,v)=>w*h+u*(l[v]*Math.cos(g)+c[v]*Math.sin(g)));f.push(_t(e,m))}t.shape(pl(f),n.color,Yo(s))}}const Mf=.35,El=t=>({centre:[t*.98,-.02,-.08],out:[t,0,-.12]});function Sf(t,e,n,s,i){const{centre:o,out:r}=El(n),a=te(e,r),l=Math.max(1,s.lineWidth*.55),c=s.skin==="none"?null:s.skin,h=e.ry*.27;if(!i){const m=_t(e,[o[0]*1.06,o[1],o[2]]);t.ellipse(m.x,m.y,e.rx*.17,h,e.angle,c,l);return}const u=_t(e,o),d=e.rx*(.12+.08*a);t.ellipse(u.x,u.y,d,h,e.angle,c,l);const f=Math.cos(e.angle),p=Math.sin(e.angle),g=Array.from({length:9},(m,w)=>{const v=-Math.PI*.55+w/8*Math.PI*1.1,k=Math.cos(v)*d*.45*-n,y=Math.sin(v)*h*.55;return{x:u.x+k*f-y*p,y:u.y+k*p+y*f}});t.line(g,Math.max(.8,l*.7))}function V5(t,e,n,s){yl(e,n,()=>{for(const i of[1,-1])te(n,El(i).out)<Mf&&Sf(t,n,i,s,!1)},s.headOutline)}function J5(t,e,n){for(const s of[1,-1])te(e,El(s).out)>=Mf&&Sf(t,e,s,n,!0)}const Al={cleanShaven:{moustache:"none",beard:"none"},stubble:{moustache:"none",beard:"stubble"},pencilMoustache:{moustache:"pencil",beard:"none"},shortMoustache:{moustache:"short",beard:"none"},chevron:{moustache:"chevron",beard:"none"},handlebar:{moustache:"handlebar",beard:"none"},walrus:{moustache:"walrus",beard:"none"},goatee:{moustache:"none",beard:"goatee"},vanDyke:{moustache:"chevron",beard:"goatee"},circleBeard:{moustache:"short",beard:"circle"},shortBoxed:{moustache:"short",beard:"boxed"},fullBeard:{moustache:"chevron",beard:"full"},longBeard:{moustache:"walrus",beard:"long"},roundedBeard:{moustache:"chevron",beard:"rounded"},pointedBeard:{moustache:"chevron",beard:"pointed"},chinStrap:{moustache:"none",beard:"chinStrap"},soulPatch:{moustache:"none",beard:"soulPatch"},sideburns:{moustache:"none",beard:"sideburns"},muttonChops:{moustache:"none",beard:"muttonChops"},moustacheStubble:{moustache:"short",beard:"stubble"}};function xf(t,e){const n=typeof t=="string"?{style:t}:t,s=n.style?Al[n.style]:void 0;if(n.style&&!s)throw new Error(`facialHair: unknown style '${n.style}'`);return{color:n.color??e??"#6b4630",moustache:n.moustache??s?.moustache??"none",beard:n.beard??s?.beard??"none"}}const Je=t=>t*Math.PI/180,Ko=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},Tf={goatee:{top:[-.55,-.55],reach:22,band:0,length:.22,shape:"point",volume:.06,aroundMouth:!1},circle:{top:[-.24,-.3],reach:42,band:0,length:.08,shape:"round",volume:.06,aroundMouth:!0},boxed:{top:[-.38,.02],reach:100,band:0,length:.18,shape:"square",volume:.08,aroundMouth:!0},full:{top:[-.36,.05],reach:100,band:0,length:.32,shape:"round",volume:.12,aroundMouth:!0},rounded:{top:[-.36,.05],reach:100,band:0,length:.55,shape:"round",volume:.14,aroundMouth:!0},pointed:{top:[-.36,.05],reach:100,band:0,length:.8,shape:"point",volume:.12,aroundMouth:!0},long:{top:[-.36,.05],reach:100,band:0,length:1.4,shape:"round",volume:.14,aroundMouth:!0},chinStrap:{top:[-.68,.05],reach:100,band:.18,length:0,shape:"round",volume:.04,aroundMouth:!1},sideburns:{top:[.08,.08],reach:100,band:.42,length:0,shape:"round",volume:.05,aroundMouth:!1},muttonChops:{top:[.08,.08],reach:100,band:.75,length:0,shape:"round",volume:.08,aroundMouth:!1}},Z5=(t,e)=>{const n=Ko(Je(48),Je(100),qo(e,0));return t.top[0]+(t.top[1]-t.top[0])*n},Q5=t=>t==="sideburns"||t==="muttonChops";function $l(t,e){const n=Tf[t];if(!n)return null;const s=Je(n.reach),i=o=>{const r=qo(o,0);return n.shape==="point"?Math.exp(-((r/.42)**2)):n.shape==="square"?1-Ko(Je(45),Je(85),r):Math.cos(Math.min(r,Math.PI/2))**.7};return{top:Math.max(n.top[0],n.top[1])+.05,bottom:-1,inside(o,r){const a=qo(o,0),l=Z5(n,o);let c=Math.min(l-r,s-a);if(n.band>0&&(c=Math.min(c,r-(l-n.band))),Q5(t)){const h=t==="muttonChops"?Je(70)-Je(22)*Ko(.08,-.6,r):Je(72);c=Math.min(c,a-h)}return c},position(o,r){const[a,l,c]=Se(o,r),h=1+e+n.volume,u=n.length*i(o)*Ko(-.45,-1,r);return[a*h,l*h-u,c*h+u*.25]},normal:(o,r)=>Se(o,r)}}function tv(t){const n=s=>s.map(([i,o])=>({x:i,y:-.24+o}));switch(t){case"short":return n([[-.17,-.02],[-.1,.04],[0,.03],[.1,.04],[.17,-.02],[.08,-.05],[0,-.03],[-.08,-.05]]);case"chevron":return n([[-.28,-.1],[-.16,.05],[0,.07],[.16,.05],[.28,-.1],[.12,-.08],[0,-.06],[-.12,-.08]]);case"walrus":return n([[-.38,-.2],[-.3,.02],[-.12,.09],[0,.07],[.12,.09],[.3,.02],[.38,-.2],[.2,-.13],[0,-.11],[-.2,-.13]]);case"handlebar":return n([[-.24,-.03],[-.12,.04],[0,.03],[.12,.04],[.24,-.03],[.1,-.05],[0,-.03],[-.1,-.05]]);default:return null}}const yi=t=>Math.max(1,t*.45);function ev(t,e,n,s){for(let i=.1;i>-1;i-=.13)for(let o=-Math.PI/1.7;o<Math.PI/1.7;o+=.2){const r=Math.round(i*100)%2*.1;if(n.inside(o+r,i)<.02)continue;const a=Se(o+r,i);if(te(e,a)<.15)continue;const l=_t(e,a);t.dot(l.x,l.y,s)}}function nv(t,e,n,s,i){const o=s.beard==="stubble"?null:$l(s.beard,i.lineWidth*.45/n.rx);if(!o)return;const{far:r}=ml(n,s,()=>jo(n,o));yl(e,n,()=>{for(const a of r)t.shape(a,s.color,yi(i.lineWidth))},i.headOutline)}function sv(t,e,n,s,i){if(n.beard==="none")return;const o=s.lineWidth*.45/e.rx;if(n.beard==="stubble"){ev(t,e,$l("full",o),Math.max(.5,s.lineWidth*.09));return}if(n.beard==="soulPatch"){const l=[{x:-.05,y:-.55},{x:.05,y:-.55},{x:0,y:-.68}],{points:c,facing:h}=xt(e,l,{x:0,y:-.6},s.face?.projection);h>-.05&&t.shape(c,n.color,yi(s.lineWidth)*.7);return}const r=$l(n.beard,o);if(!r)return;const{near:a}=ml(e,n,()=>jo(e,r));for(const l of a)t.shape(l,n.color,yi(s.lineWidth));if(Tf[n.beard]?.aroundMouth){const l=.27*Math.max(.3,i),c=Array.from({length:20},(d,f)=>{const p=Math.PI*2*f/20;return{x:Math.cos(p)*l,y:-.42+Math.sin(p)*.13}}),{points:h,facing:u}=xt(e,c,{x:0,y:-.42},s.face?.projection);u>-.05&&t.shape(h,s.skin==="none"?"#ffffff":s.skin,0)}}function iv(t,e,n,s){if(n.moustache==="none")return;const i={x:0,y:-.24};if(n.moustache==="pencil"){const l=[-.2,-.1,0,.1,.2].map(u=>({x:u,y:-.25+.03*Math.cos(u/.2*Math.PI)})),{points:c,facing:h}=xt(e,l,i,s.face?.projection);h>-.05&&t.line(c,Math.max(1,s.lineWidth*.32));return}const o=tv(n.moustache);if(!o)return;const{points:r,facing:a}=xt(e,o,i,s.face?.projection);if(!(a<=-.05)&&(t.shape(r,n.color,yi(s.lineWidth)*.8),n.moustache==="handlebar"))for(const l of[1,-1]){const c=Array.from({length:10},(h,u)=>{const d=-Math.PI/2+u/9*Math.PI*1.4;return{x:l*(.27+.05*Math.cos(d)),y:-.21+.05*(1+Math.sin(d))}});c.unshift({x:l*.22,y:-.27}),t.line(xt(e,c,i,s.face?.projection).points,yi(s.lineWidth)*.8)}}const Pl={round:!0,square:!0,sunglasses:!0};function Ef(t){const n=(typeof t=="string"?{style:t}:t).style??"round";if(!(n in Pl))throw new Error(`glasses: unknown style '${n}'`);return{style:n}}const Af=.34,Te=.12,ov=.05;function rv(t,e){return Array.from({length:28},(s,i)=>{const o=Math.PI*2*i/28;if(t==="round")return{x:e+Math.cos(o)*.2,y:Te+Math.sin(o)*.19};const r=Math.cos(o),a=Math.sin(o),l=t==="sunglasses"?.22:.21,c=t==="sunglasses"?.17:.16;return{x:e+Math.sign(r)*Math.abs(r)**.45*l,y:Te-.01+Math.sign(a)*Math.abs(a)**.45*c}})}function av(t,e,n,s){const i=Math.max(1,Math.min(s.lineWidth*.5,.11*e.rx)),o=[];for(const r of[1,-1]){const a=Af*r,{points:l,facing:c}=xt(e,rv(n.style,a),{x:a,y:Te},s.face?.projection);if(c<ov)continue;o.push(r),t.shape(l,n.style==="sunglasses"?"#1f2328":null,i);const h=[r*.97,Te+.02,-.1];if(te(e,[r,0,0])>.15){const u=xt(e,[{x:a+r*.21,y:Te+.02}],{x:a,y:Te},s.face?.projection).points[0];t.line([u,_t(e,h)],i*.9)}}if(o.length===2){const r=[{x:Af-.2,y:Te+.02},{x:0,y:Te+.07},{x:-.14,y:Te+.02}];t.line(xt(e,r,{x:0,y:Te},s.face?.projection).points,i)}}const Xo={cap:{color:"#d64535",brim:[.36,.16],height:1,peak:.7,detail:"seams"},beanie:{color:"#3a6ea5",brim:[.3,.12],height:1.08,detail:"fold"},hardHat:{color:"#f2c230",brim:[.34,.22],height:1.12,ring:.16,detail:"ridge"},sunHat:{color:"#e3c98f",brim:[.36,.3],height:1.02,ring:.62,detail:"band"},bowler:{color:"#2f2b2a",brim:[.36,.28],height:1.15,ring:.2,detail:"band"}};function $f(t){const e=typeof t=="string"?{style:t}:t,n=e.style??"cap",s=Xo[n];if(!s)throw new Error(`hat: unknown style '${n}'`);return{style:n,color:e.color??s.color}}const An=(t,e)=>t.brim[1]+(t.brim[0]-t.brim[1])*(1+Math.cos(e))/2;function lv(t,e){return{top:1,bottom:Math.min(...t.brim)-.05,inside:(n,s)=>s-An(t,n),position(n,s){const[i,o,r]=Se(n,s),a=An(t,n),l=s>a?(o-a)*(t.height-1):0;return[i*e,o*e+l,r*e]},normal:(n,s)=>Se(n,s)}}function cv(t,e,n){const i=(o,r,a)=>{const l=An(e,o)*n-a;return[Math.sin(o)*r,l,Math.cos(o)*r]};if(e.peak){const o=[],r=[];for(let a=0;a<=24;a++){const l=(-80+160*a/24)*(Math.PI/180),c=e.peak*Math.cos(l)**.6;o.push(_t(t,[Math.sin(l)*(n+c*.25),An(e,l)*n-.07*Math.cos(l),Math.cos(l)*(n+c)])),r.push(_t(t,i(l,n,0)))}return[...o,...r.reverse()]}return e.ring?Array.from({length:48},(o,r)=>_t(t,i(Math.PI*2*r/48,n+e.ring,.07))):null}function hv(t){const e=s=>Array.from({length:13},(i,o)=>[s,An(t,s)+(.97-An(t,s))*o/12]),n=s=>Array.from({length:49},(i,o)=>{const r=-Math.PI+Math.PI*2*o/48;return[r,An(t,r)+s]});switch(t.detail){case"seams":return[e(.55),e(-.55)];case"fold":return[n(.2)];case"ridge":return[e(0),e(Math.PI)];case"band":return[n(.12)]}}function Pf(t,e,n,s){const i=Xo[n.style],r=1+s.lineWidth*.45/e.rx+Math.max(.05,Math.min(.3,s.hairVolume)+.04),a=Math.max(1,s.lineWidth*.5),l=cv(e,i,r);l&&t.shape(l,n.color,a);const c=lv(i,r),{near:h,far:u}=jo(e,c);for(const f of[...u,...h])t.shape(f,n.color,a);const d=Math.max(.8,a*.7);for(const f of hv(i)){const p=f.map(([m,w])=>{const[v,k,y]=c.position(m,w);return[v*.99,k*.99,y*.99]}),g=f.map(([m,w])=>Se(m,w));for(const m of nf(e,p,g,.1))t.line(m,d)}if(i.detail==="seams"){const f=_t(e,[0,r*1.01,0]);t.dot(f.x,f.y,a*.9)}}function If(t){const e=t.hair?df(t.hair):null;return{hair:e,facialHair:t.facialHair?xf(t.facialHair,e?.color):null,glasses:t.glasses?Ef(t.glasses):null,hat:t.hat?$f(t.hat):null,ears:t.ears??!1}}const Of=t=>!t.hair&&!t.facialHair&&!t.glasses&&!t.hat&&!t.ears,_f=t=>t.axes[2][2]<-.3,Cf=t=>t.ears&&!t.hair?.coversEars;function Hf(t,e,n,s,i,o){if(Of(n))return;const r={...o,headOutline:o.face&&(o.face.shape==="angular"||o.face.projection==="volume")?Ud(s,o.face):void 0};n.hair&&U5(e,t,s,n.hair,{...r,motion:pi(i)}),n.facialHair&&nv(e,t,s,n.facialHair,r),Cf(n)&&V5(e,t,s,r)}function uv(t,e,n,s,i,o,r){if(Of(n)){r();return}const a=_f(s);Cf(n)&&J5(e,s,o),n.hair&&!a&&!o.faceUnderHair&&Tl(e,s,n.hair,{...o,motion:pi(i)}),n.facialHair&&sv(e,s,n.facialHair,o,i.mouthWidth??1),r(),n.hair&&!a&&o.faceUnderHair&&Tl(e,s,n.hair,{...o,motion:pi(i)}),n.facialHair&&iv(e,s,n.facialHair,o),n.glasses&&av(e,s,n.glasses,o),n.hat&&!a&&Pf(e,s,n.hat,{lineWidth:o.lineWidth,hairVolume:n.hair?.volume??0})}function Rf(t,e,n,s,i,o){_f(s)&&(n.hair&&Tl(e,s,n.hair,{...o,motion:pi(i)}),n.hat&&Pf(e,s,n.hat,{lineWidth:o.lineWidth,hairVolume:n.hair?.volume??0}))}const Lf=40,dv=.215+.205,le=(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},gt=(t,e)=>t[e]??lt[e]??0;function Go(t,e,n=lt,s=1){const i=ri(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={...lt,...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"]=gt(n,"leg.left.ankle")-(i.tiptoe??0),d["leg.right.ankle"]=gt(n,"leg.right.ankle")-(i.tiptoe??0);for(const[f,p]of[["left",-1],["right",1]])gt(n,`arm.${f}.spread`)>Lf||gt(n,`arm.${f}.swing`)>Lf||(d[`arm.${f}.swing`]=h+p*i.arm*r,d[`arm.${f}.elbow`]=gt(n,`arm.${f}.elbow`)+u+i.elbow*Math.max(0,p*r));return d.lean=gt(n,"lean")+i.lean*s,d.bend=gt(n,"bend")+(i.bend??0),d["head.nod"]=gt(n,"head.nod")-i.lean*.5*s+(i.headTilt??0),d.side=gt(n,"side")+(i.sway??0)*Math.sin(o),d.lift=gt(n,"lift")+(i.bounce??0)*s*l,d.stretch=gt(n,"stretch")*(1+(i.squash??0)*(l-.5)),d}function Uo(t,e,n=1,s=1){const i=ri(t);return 4*dv*s*e*Math.sin(i.swing*n*Math.PI/180)}const ls=t=>al[t],Vo={take:t=>[{after:140,pose:{stretch:.8,bend:10,lean:gt(t,"lean")-4,...le("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,...le("arm",{spread:150,bend:35,swing:0,elbow:0}),...le("leg",{swing:25,knee:60}),...ls("shocked")},easing:"ease-out-cubic"},{after:720,pose:{lift:.25,stretch:1.25,bend:-10,...le("arm",{spread:140})},easing:"ease-in-out"},{after:900,pose:{lift:0,stretch:.74,bend:12,...le("arm",{spread:70,bend:0}),...le("leg",{swing:30,knee:60})},easing:"ease-in-quad"},{after:1060,pose:{stretch:1.06,bend:-3,...le("arm",{spread:60}),"leg.left.swing":gt(t,"leg.left.swing"),"leg.right.swing":gt(t,"leg.right.swing"),"leg.left.knee":gt(t,"leg.left.knee"),"leg.right.knee":gt(t,"leg.right.knee")},easing:"ease-out"},{after:1260,pose:{stretch:gt(t,"stretch"),bend:gt(t,"bend"),...ls("surprised"),...le("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":gt(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":gt(t,"head.nod")-10,bend:gt(t,"bend")-10,lift:.05,stretch:1.18,...ls("shocked"),lookX:1,lookY:0},easing:"ease-out-cubic"},{after:1360,pose:{lift:0,stretch:.88,"head.nod":gt(t,"head.nod")-4,bend:gt(t,"bend")+4},easing:"ease-in-quad"},{after:1560,pose:{stretch:gt(t,"stretch"),"head.nod":gt(t,"head.nod"),bend:gt(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,...ls("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,...le("arm",{spread:75}),...le("leg",{swing:25,knee:50})},easing:"ease-in-quad"},{after:300,pose:{stretch:1.05,bend:-4,"arm.left.spread":gt(t,"arm.left.spread"),"arm.right.spread":gt(t,"arm.right.spread")},easing:"ease-out"},{after:460,pose:{lift:0,stretch:gt(t,"stretch"),bend:gt(t,"bend"),...le("leg",{swing:0,knee:0})},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...ls("scared"),...le("arm",{swing:40,elbow:110,spread:14}),stretch:.94,bend:gt(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:gt(t,"side")+2.5*s,"head.tilt":gt(t,"head.tilt")-2*s}})}return e.push({after:755,pose:{side:gt(t,"side"),"head.tilt":gt(t,"head.tilt"),bend:gt(t,"bend")}}),e},deflate:t=>[{after:260,pose:{stretch:1.04,"head.nod":gt(t,"head.nod")-4,"brow.left":.3,"brow.right":.3},easing:"ease-in-out"},{after:900,pose:{...ls("sad"),bend:18,stretch:.92,lean:gt(t,"lean")+5,"head.nod":14,...le("arm",{spread:6,swing:0,elbow:4,bend:0})},easing:"ease-in-out"}]};function Ff(t,e){const n=kt(e.from??{}),s=e.speed??1;let i=n;return[{time:e.at,pose:n},...Vo[t](n).map(o=>(i={...i,...o.pose},{time:e.at+o.after*s,pose:i,act:!1,...o.easing?{easing:o.easing}:{}}))]}function Nf(t,e=lt){const n=t*Math.PI*2,s=Math.sin(n);return{...e,lean:(e.lean??0)+14,bend:(e.bend??0)+8,side:5*s,"head.nod":22,"arm.right.swing":38+22*s,"arm.right.spread":6,"arm.right.elbow":20+10*Math.max(0,-s),"arm.right.bend":-10,"arm.left.swing":52+22*s,"arm.left.spread":14,"arm.left.elbow":35+10*Math.max(0,s),"arm.left.bend":-20,"leg.left.swing":10,"leg.right.swing":-10,"leg.left.knee":8,"leg.right.knee":4,"leg.left.spread":8,"leg.right.spread":8}}function Wf(t,e=lt){const n=t*Math.PI*2,s=Math.sin(n),i=Math.cos(n);return{...e,lean:(e.lean??0)+4,side:2*s,"head.nod":6,"arm.right.swing":62,"arm.right.spread":18+16*s,"arm.right.elbow":48-18*Math.abs(s),"arm.right.bend":-30+8*i,"arm.left.swing":12,"arm.left.spread":14,"arm.left.elbow":12,"leg.left.spread":6,"leg.right.spread":6}}const Il={sweeping:Nf,brushing:Wf};function fv(t,e,n=lt){const s=Il[t];if(!s)throw new Error(`humanCyclePose: ${ft("cycle",t,Object.keys(Il))}`);return s(e,n)}function Df(t){const e=t.top??!0,n=t.length??.32,s=t.color??"#638c39",i=t.accent??"#87ae4e";if(typeof e!="boolean")throw new Error("leafOutfit: top must be a boolean");if(!Number.isFinite(n)||n<.2||n>.45)throw new Error("leafOutfit: length must be 0.2..0.45");if(typeof s!="string"||typeof i!="string")throw new Error("leafOutfit: color and accent must be strings");return{top:e,length:n,color:s,accent:i}}function Bf(t,e){const n=t.flatMap(i=>Array.from({length:8},(o,r)=>({x:i.x+Math.cos(r*Math.PI/4)*e,y:i.y+Math.sin(r*Math.PI/4)*e})));let s=pl(n);for(let i=0;i<2;i++)s=s.flatMap((o,r)=>{const a=s[(r+1)%s.length];return[{x:o.x*.75+a.x*.25,y:o.y*.75+a.y*.25},{x:o.x*.25+a.x*.75,y:o.y*.25+a.y*.75}]});return s}const zf=t=>t.flatMap(e=>[e.left,e.right]);function Ol(t,e={}){const{top:n,length:s}=Df(e),i=t.bodyContours;if(!i?.spine)throw new Error("leafOutfit requires organic body contours");const o=i.spine.samples.filter(a=>a.at<=.3),r=["left","right"].flatMap(a=>i[`leg.${a}`]?.samples.filter(l=>l.at<=s)??[]);return{...n?{top:Bf(zf(i.spine.samples.filter(a=>a.at>=.52&&a.at<=.91)),t.height*.01)}:{},skirt:Bf(zf([...o,...r]),t.height*.012)}}function gv(t,e){t.beginPath(),t.moveTo(e[0].x,e[0].y);for(const n of e.slice(1))t.lineTo(n.x,n.y);t.closePath()}function pv(t,e,n){const s=e.x-t.x,i=e.y-t.y,o=Math.hypot(s,i)||1,r=-i/o,a=s/o,l=[];for(const c of[1,-1])for(let h=0;h<=16;h++){const u=c===1?h/16:1-h/16,f=3*(1-u)*u*n*c;l.push({x:t.x+s*u+r*f,y:t.y+i*u+a*f})}return l}function qf(t,e,n,s,i,o){const r=e.lineWidth*.7;if(n.shape(s,i,r),n.look==="silhouette")return;t.save(),gv(t,s),t.clip();const a=Math.min(...s.map(f=>f.x)),l=Math.max(...s.map(f=>f.x)),c=Math.min(...s.map(f=>f.y)),h=Math.max(...s.map(f=>f.y)),u=l-a,d=h-c;for(let f=0;f<2;f++)for(let p=0;p<5;p++){const g={x:a+u*(p/4+(f?.07:-.04)),y:c+d*(f?.38:-.1)},m={x:g.x+u*.09,y:g.y+d*.78};n.shape(pv(g,m,u*.13),(p+f)%2?i:o,r*.6),n.line([g,{x:g.x*.45+m.x*.55,y:g.y*.45+m.y*.55},m],r*.45);for(const w of[.32,.52,.7]){const v={x:g.x+(m.x-g.x)*w,y:g.y+(m.y-g.y)*w};n.line([{x:v.x-u*.045,y:v.y-d*.065},v,{x:v.x+u*.045,y:v.y-d*.05}],r*.3)}}t.restore()}function jf(t={}){const e=Df(t),{color:n,accent:s}=e,i=o=>(r,a,l)=>{const c=Ol(a,e);o==="spine"&&c.top&&qf(r,a,l,c.top,n,s);const h=["spine","leg.left","leg.right"].reduce((u,d)=>a.parts[u].order>a.parts[d].order?u:d);o===h&&qf(r,a,l,c.skirt,n,s)};return{parts:{spine:{over:i("spine")},"leg.left":{over:i("leg.left")},"leg.right":{over:i("leg.right")}}}}const mv={apron:"#d8b48a",labCoat:"#f4f6f8",hoodie:"#6b7280",cardigan:"#6b8e4e",overalls:"",sari:"#16a34a"},_l=(t,e,n)=>t.slice(Math.floor((t.length-1)*e),Math.ceil((t.length-1)*n)+1),pt=(t,e,n)=>({x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n});function yv(t){return t.parts["leg.left"].order>t.parts["leg.right"].order?"left":"right"}const Yf=t=>Math.max(t.parts["leg.left"].order,t.parts["leg.right"].order)>t.parts.spine.order,ee=t=>t.bodyForward?.[2]??Math.cos(t.turn*Math.PI/2),_e=t=>t.bodyForward?.[0]??Math.sin(t.turn*Math.PI/2);function Kf(t,e,n){t.save(),t.beginPath(),t.moveTo(e[0].x,e[0].y);for(const s of e.slice(1))t.lineTo(s.x,s.y);t.closePath(),t.clip(),n(),t.restore()}function Xf(t,e,n=0){const s=e*(t.length-1),i=Math.min(t.length-2,Math.floor(s)),o=t[i],r=t[i+1],a=pt(o,r,s-i),l=Math.hypot(r.x-o.x,r.y-o.y)||1;return{x:a.x+(r.y-o.y)/l*n,y:a.y-(r.x-o.x)/l*n}}function Gf(t={}){if(t={...t},t.top!==void 0&&!["tshirt","shirt","blouse","dress"].includes(t.top))throw new Error(`basicOutfit: unknown top '${t.top}'`);if(t.trouserStyle!==void 0&&!["plain","jeans","cargo"].includes(t.trouserStyle))throw new Error(`basicOutfit: unknown trouser style '${t.trouserStyle}'`);const e=t.top,n=t.trouserStyle??"plain",s=t.collar??e==="shirt",i=t.shirt??"#e2493b",o=e==="dress"?i:t.trousers??"#24476b",r=t.sleeves??"short",a=e==="dress"?"skirt":t.bottom??"trousers",l=t.over==="labCoat",c=t.over==="hoodie",h=t.over==="cardigan",u=t.over==="overalls",d=t.over==="sari",f=t.overColor??(t.over&&t.over!=="overalls"?mv[t.over]:o),p=t.shoes==="boots",g=t.shoeColor??"#3b2a1e",m=O=>O.lineWidth*.45,w=(O,R,z,K)=>{const N=R.parts[`leg.${K}`].points;if(a==="skirt"&&!u)return;const q=a==="shorts"&&!u,Y=R.bodyContours?.[`leg.${K}`],J=Y?gl(Y,0,q?.5:1,R.height*.006):zt(q?_l(N,0,.5):N,R.height*(q?.085:.08),R.height*(q?.07:.05));z.shape(J,o,m(R)),!(n==="plain"||ee(R)<.15)&&Kf(O,J,()=>{const X=(tt,nt=0)=>Xf(N,tt,nt*R.height);if(n==="jeans")z.line([X(.07,-.018),X(.17,-.02),X(.23,0),X(.17,.02),X(.07,.018)],m(R)*.65),z.line([X(.27,.013),...[.4,.55,.7,.85,.96].filter(tt=>!q||tt<.5).map(tt=>X(tt,.013))],m(R)*.5);else{const tt=[X(.25,-.024),X(.25,.024),X(.43,.024),X(.43,-.024)];z.shape(tt,o,m(R)*.65),z.line([X(.28,-.024),X(.32,0),X(.28,.024)],m(R)*.65);const nt=X(.32);z.dot(nt.x,nt.y,m(R)*.8)}})},v=(O,R,z)=>{const K=O.parts[`leg.${z}`].points,N=_l(K,.7,1);if(N.length<2)return;R.shape(zt(N,O.height*.075,O.height*.07),g,m(O));const q=N[0],Y=N[1],J=Y.x-q.x,X=Y.y-q.y,tt=Math.hypot(J,X)||1,nt=O.height*.04;R.line([{x:q.x-X/tt*nt,y:q.y+J/tt*nt},{x:q.x+X/tt*nt,y:q.y-J/tt*nt}],m(O)*.9)},k=O=>{const R=O.chains.spine,z=R[0],K=R[R.length-1],N={x:z.x-(K.x-z.x)*.25,y:z.y-(K.y-z.y)*.25};return{hip:z,top:K,below:N,line:[N,...O.parts.spine.points]}},y=O=>{if(O.bodyContours?.spine)return gl(O.bodyContours.spine,0,.97,O.height*(c?.014:.006));const R=c?1.14:1,z=Math.hypot(O.points["hip.left"].x-O.points["hip.right"].x,O.points["hip.left"].y-O.points["hip.right"].y),K=Math.max(O.height*.15*R,z+Math.max(O.height*.08,O.lineWidth*1.45)+m(O));return zt(k(O).line,K,O.height*.14*R)},x=(O,R)=>{const z=[y(R)],{top:K,hip:N}=k(R);h&&z.push(zt([K,pt(K,N,.5),pt(K,N,1.08)],R.height*.155,R.height*.15)),l&&z.push(zt([K,pt(K,N,.5),N],R.height*.14,R.height*.15));const q=Object.values(R.points),Y=Math.min(...q.map(nt=>nt.x))-R.height,J=Math.min(...q.map(nt=>nt.y))-R.height,X=Math.max(...q.map(nt=>nt.x))+R.height,tt=Math.max(...q.map(nt=>nt.y))+R.height;for(const nt of z){O.beginPath(),O.rect(Y,J,X-Y,tt-J),O.moveTo(nt[0].x,nt[0].y);for(const L of nt.slice(1))O.lineTo(L.x,L.y);O.closePath(),O.clip("evenodd")}},P=(O,R)=>{const z=c?f:i;R.shape(y(O),z,m(O))},M=(O,R,z)=>{const K=ee(R);if(!e||K<.2||c)return;const{top:N,hip:q}=k(R),Y=_e(R)*R.height*.025,J=[N,q],X=(tt,nt=0)=>Xf(J,tt,Y+nt*R.height*K);Kf(O,y(R),()=>{if(e==="shirt"){z.line([X(.12),X(.92)],m(R)*.65);for(const tt of[.24,.4,.56,.72,.88]){const nt=X(tt,.008);z.dot(nt.x,nt.y,m(R)*.9)}}else if(e==="blouse"){z.line([X(.025,-.04),X(.24),X(.025,.04)],m(R)*.75);const tt=X(.31);z.dot(tt.x,tt.y,m(R))}else e==="dress"?z.line([X(.04,-.035),X(.17,-.028),X(.17,.028),X(.04,.035)],m(R)*.75):z.line([X(.025,-.035),X(.1,-.02),X(.12),X(.1,.02),X(.025,.035)],m(R)*.65)})},T=(O,R)=>{const z=ee(O),{top:K,hip:N}=k(O),q=O.height*.07,Y={x:(K.x-N.x)*.16,y:(K.y-N.y)*.16};if(z>=0){R.shape([{x:K.x-q,y:K.y+Y.y*.25},{x:K.x-q*.8+Y.x,y:K.y+Y.y},{x:K.x+Y.x*1.2,y:K.y+Y.y*1.35},{x:K.x+q*.8+Y.x,y:K.y+Y.y},{x:K.x+q,y:K.y+Y.y*.25}],f,m(O));return}const J=pt(K,N,.42);R.shape([{x:K.x-q*.9,y:K.y},{x:K.x+q*.9,y:K.y},{x:J.x+q*.7,y:J.y},{x:J.x,y:J.y+O.height*.02},{x:J.x-q*.7,y:J.y}],f,m(O))},S=(O,R)=>{const z=ee(O);if(z<.2)return;const{top:K,hip:N}=k(O),q=_e(O)*O.height*.03,Y=O.height*.06*z,J=pt(K,N,.62),X=pt(K,N,.9);R.line([{x:J.x+q-Y,y:J.y},{x:X.x+q-Y*1.1,y:X.y}],m(O)*.7),R.line([{x:J.x+q+Y,y:J.y},{x:X.x+q+Y*1.1,y:X.y}],m(O)*.7);const tt=pt(K,N,.1);for(const nt of[-1,1])R.line([{x:tt.x+q+nt*Y*.2,y:tt.y},{x:tt.x+q+nt*Y*.35,y:tt.y+O.height*.07}],m(O)*.6)},E=(O,R)=>{const{top:z,hip:K}=k(O),N=ee(O);if(R.shape(zt([z,pt(z,K,.5),pt(z,K,1.08)],O.height*.155,O.height*.15),f,m(O)),N<.2)return;const q=_e(O)*O.height*.03,Y=O.height*.02*N,J=pt(z,K,.12),X=pt(z,K,1.05);R.shape([{x:J.x+q-Y,y:J.y},{x:J.x+q+Y,y:J.y},{x:X.x+q+Y*1.3,y:X.y},{x:X.x+q-Y*1.3,y:X.y}],i,m(O)*.7);for(const tt of[.35,.55,.75]){const nt=pt(z,K,tt);R.dot(nt.x+q+Y*1.6,nt.y,m(O)*1.2)}},$=(O,R)=>{const z=ee(O),{top:K,hip:N}=k(O),q=_e(O)*O.height*.04,Y=pt(N,K,.12),J=pt(N,K,.74);if(z<.15){if(z<-.3){const L=O.points["shoulder.left"],U=O.points["shoulder.right"];R.line([L,{x:Y.x+O.height*.03,y:Y.y}],m(O)*.8),R.line([U,{x:Y.x-O.height*.03,y:Y.y}],m(O)*.8)}return}const X=O.height*.07*z;R.shape([{x:J.x+q-X*.75,y:J.y},{x:J.x+q+X*.75,y:J.y},{x:Y.x+q+X*1.1,y:Y.y},{x:Y.x+q-X*1.1,y:Y.y}],o,m(O));for(const L of["left","right"]){const U=O.points[`shoulder.${L}`],ot={x:J.x+q+(U.x>J.x+q?1:-1)*X*.55,y:J.y};R.line([ot,{x:U.x+(ot.x-U.x)*.15,y:U.y+(ot.y-U.y)*.15}],m(O)*1.6)}const tt=pt(J,Y,.3),nt=X*.4;R.line([{x:tt.x+q-nt,y:tt.y},{x:tt.x+q-nt,y:tt.y+nt*1.4},{x:tt.x+q+nt,y:tt.y+nt*1.4},{x:tt.x+q+nt,y:tt.y}],m(O)*.6)},A=(O,R)=>{const{hip:z,top:K}=k(O),N=pt(z,K,.2),q=[O.points["ankle.left"],O.points["ankle.right"]],Y=pt(z,{x:(q[0].x+q[1].x)/2,y:(q[0].y+q[1].y)/2},.98),J=O.height*.075,X=Math.max(O.height*.12,Math.abs(q[0].x-q[1].x)/2+O.height*.07),tt=Y.x-N.x,nt=Y.y-N.y,L=Math.hypot(tt,nt)||1,U={x:-nt/L,y:tt/L};if(R.shape([{x:N.x+U.x*J,y:N.y+U.y*J},{x:Y.x+U.x*X,y:Y.y+U.y*X},{x:Y.x-U.x*X,y:Y.y-U.y*X},{x:N.x-U.x*J,y:N.y-U.y*J}],f,m(O)),ee(O)>.2){const at=_e(O)*O.height*.03;for(const it of[-.35,0,.35]){const ct=J*.5*it,st=X*.45*it;R.line([{x:N.x+at+U.x*ct,y:N.y+U.y*ct+O.height*.02},{x:Y.x+at+U.x*st,y:Y.y+U.y*st}],m(O)*.5)}}},I=(O,R)=>{const z=ee(O),{top:K,hip:N}=k(O),q=_e(O),Y=q>=0?"left":"right",J=Y==="left"?"right":"left",X=O.points[`shoulder.${Y}`],tt=O.height*.035;if(z<.15){const U=pt(K,N,.9);R.shape(zt([X,{x:U.x+(X.x-K.x)*.5,y:U.y}],tt*2.2,tt*2.6),f,m(O));return}const nt={x:N.x+(O.points[`hip.${J}`].x-N.x)*1.2,y:pt(N,K,.08).y};R.shape(zt([nt,pt(nt,X,.5),X],tt*2.4,tt*2),f,m(O));const L={x:X.x-(N.x-X.x)*.05-q*O.height*.03,y:X.y+O.height*.16};R.shape(zt([X,L],tt*2,tt*1.6),f,m(O))},C=(O,R)=>{if(O.bodyContours){R.shape(Ol(O,{top:!1,length:.45}).skirt,o,m(O));return}const{hip:z,top:K}=k(O),N=pt(z,K,.18),q=[O.points["knee.left"],O.points["knee.right"]],Y=pt(z,{x:(q[0].x+q[1].x)/2,y:(q[0].y+q[1].y)/2},1.05),J=O.height*.075,X=Math.max(O.height*.13,Math.abs(q[0].x-q[1].x)/2+O.height*.08),tt=Y.x-N.x,nt=Y.y-N.y,L=Math.hypot(tt,nt)||1,U={x:-nt/L,y:tt/L};R.shape([{x:N.x+U.x*J,y:N.y+U.y*J},{x:Y.x+U.x*X,y:Y.y+U.y*X},{x:Y.x-U.x*X,y:Y.y-U.y*X},{x:N.x-U.x*J,y:N.y-U.y*J}],o,m(O))},D=(O,R)=>{const z=ee(O);if(z<.2)return;const{top:K,hip:N}=k(O),q={x:(N.x-K.x)*.12,y:(N.y-K.y)*.12},Y=O.height*.045*z;for(const J of[-1,1])R.shape([{x:K.x+J*Y*.2,y:K.y+q.y*.1},{x:K.x+J*Y*1.3,y:K.y-q.y*.1},{x:K.x+J*Y*.6+q.x,y:K.y+q.y}],i,m(O)*.8)},j=(O,R,z)=>{const K=ee(O);if(K<.25)return;const{top:N,hip:q}=k(O),Y=_e(O)*O.height*.03,J=L=>({x:pt(N,q,L).x+Y,y:pt(N,q,L).y}),X=O.height*.022*K,tt=J(.08),nt=J(.62);R.shape([{x:tt.x-X,y:tt.y-X},{x:tt.x+X,y:tt.y-X},{x:tt.x+X*.6,y:tt.y+X},{x:tt.x-X*.6,y:tt.y+X}],z,m(O)*.7),R.shape([{x:tt.x-X*.6,y:tt.y+X},{x:tt.x+X*.6,y:tt.y+X},{x:nt.x+X*1.4,y:nt.y-X*2},nt,{x:nt.x-X*1.4,y:nt.y-X*2}],z,m(O)*.7)},V=(O,R)=>{const z=ee(O),{top:K,hip:N}=k(O),q=pt(N,K,.72),Y=[O.points["knee.left"],O.points["knee.right"]],J=pt(N,{x:(Y[0].x+Y[1].x)/2,y:(Y[0].y+Y[1].y)/2},.9),X=_e(O)*O.height*.04;if(z<.15){const L=pt(N,K,.2);z<-.3&&R.line([{x:L.x-O.height*.05,y:L.y},{x:L.x+O.height*.05,y:L.y}],m(O));return}const tt=O.height*.075*z,nt=pt(N,K,.2);R.shape([{x:q.x+X-tt*.7,y:q.y},{x:q.x+X+tt*.7,y:q.y},{x:nt.x+X+tt,y:nt.y},{x:J.x+X+tt*1.15,y:J.y},{x:J.x+X-tt*1.15,y:J.y},{x:nt.x+X-tt,y:nt.y}],f,m(O)),R.line([{x:q.x+X-tt*.6,y:q.y},{x:K.x-tt*.2,y:K.y},{x:q.x+X+tt*.6,y:q.y}],m(O)*.8)},et=(O,R,z)=>{const{top:K,hip:N}=k(O),q=[O.points["knee.left"],O.points["knee.right"]],Y=pt(N,{x:(q[0].x+q[1].x)/2,y:(q[0].y+q[1].y)/2},.95);z?R.shape(zt([pt(K,N,.8),N,Y],O.height*.145,O.height*.17),f,m(O)):R.shape(zt([K,pt(K,N,.5),N],O.height*.14,O.height*.15),f,m(O));const J=ee(O);if(J>.2){const X=_e(O)*O.height*.03,[tt,nt]=z?[N,Y]:[K,N];if(R.line([{x:tt.x+X,y:tt.y},{x:nt.x+X,y:nt.y}],m(O)*.8),!z){const L=pt(K,N,.35),U=O.height*.025*J;R.shape([{x:L.x+X-U*2.4,y:L.y},{x:L.x+X-U*.6,y:L.y},{x:L.x+X-U*.6,y:L.y+U*1.6},{x:L.x+X-U*2.4,y:L.y+U*1.6}],f,m(O)*.6)}}},G=(O,R,z,K,N)=>{const q=O.bodyContours?.[`arm.${z}`];if(q){const Z=gl(q,0,N,O.height*.006);R.shape(Z,K,0);const rt=y(O);for(let ht=0;ht<Z.length;ht++){const dt=Z[ht],bt=Z[(ht+1)%Z.length];Yd({x:(dt.x+bt.x)/2,y:(dt.y+bt.y)/2},rt)||R.line([dt,bt],m(O))}return}const Y=O.parts[`arm.${z}`].points,J=Y[0],X=O.chains.spine[O.chains.spine.length-1],nt=[{x:J.x+(X.x-J.x)*.45,y:J.y+(X.y-J.y)*.45},..._l(Y,0,N)],L=zt(nt,O.height*.085,O.height*(N>.6?.045:.06)),U=nt.length,ot=L.slice(0,U),at=L.slice(U).reverse();R.shape(L,K,0);const it=Z=>Math.hypot(Z[1].x-X.x,Z[1].y-X.y),[ct,st]=it(ot)>it(at)?[ot,at]:[at,ot];R.line(ct.slice(1),m(O)),R.line(st.slice(Math.ceil(U*.45)),m(O)),R.line([ot[U-1],at[U-1]],m(O))},F=l||c||h,H=F?f:i,W=F||r==="long"?.95:.45,_=F||r!=="none",B=(O,R)=>{a==="skirt"&&!u&&!d&&C(O,R),d&&A(O,R),l&&et(O,R,!0),t.over==="apron"&&V(O,R)},Q=O=>(R,z,K)=>{R.save(),x(R,z),w(R,z,K,O),p&&v(z,K,O),R.restore(),yv(z)===O&&Yf(z)&&B(z,K)};return{parts:{"leg.left":{clip:x,over:Q("left")},"leg.right":{clip:x,over:Q("right")},spine:{over:(O,R,z)=>{c&&ee(R)>=0&&T(R,z),P(R,z),M(O,R,z),s&&!c&&D(R,z),t.tie&&!c&&j(R,z,t.tie),l&&et(R,z,!1),h&&E(R,z),c&&(ee(R)<0&&T(R,z),S(R,z)),u&&$(R,z),d&&I(R,z),Yf(R)||B(R,z)}},"arm.left":{over:_?(O,R,z)=>G(R,z,"left",H,W):void 0},"arm.right":{over:_?(O,R,z)=>G(R,z,"right",H,W):void 0}}}}const Cl={mug:{color:"#e2493b",hands:"one"},phone:{color:"#2b2f36",hands:"one"},book:{color:"#3a6ea5",hands:"either"},bag:{color:"#e9d8b4",hands:"one"},briefcase:{color:"#6b4630",hands:"one"},umbrella:{color:"#3c9a6e",hands:"one"},broom:{color:"#c8963e",hands:"one"},cane:{color:"#6b4630",hands:"one"},parcel:{color:"#c9a06a",hands:"both"}};function Uf(t){const e={};for(const n of["left","right","both"]){const s=t[n];if(!s)continue;const i=typeof s=="string"?s:s.item,o=Cl[i];if(!o)throw new Error(`holding: unknown item '${i}'`);if(n==="both"&&o.hands==="one")throw new Error(`holding: a ${i} is held in one hand ('left' or 'right'), not 'both'`);if(n!=="both"&&o.hands==="both")throw new Error(`holding: a ${i} is held in both hands ('both')`);e[n]={item:i,color:(typeof s=="object"?s.color:void 0)??o.color}}return e}function Jo(t,e){const n=t.chains[`arm.${e}`],s=n[n.length-1],i=n[n.length-2],o=Math.hypot(s.x-i.x,s.y-i.y)||1,r={x:(s.x-i.x)/o,y:(s.y-i.y)/o},a=t.lineWidth*.5;return{point:{x:s.x+r.x*a,y:s.y+r.y*a},along:r,depth:t.parts[`arm.${e}`]?.depth??0}}function cs(t,e,n,s=0){const i=Math.cos(s),o=Math.sin(s);return[[-e/2,-n/2],[e/2,-n/2],[e/2,n/2],[-e/2,n/2]].map(([r,a])=>({x:t.x+r*i-a*o,y:t.y+r*o+a*i}))}const hs=(t,e,n,s,i=12)=>Array.from({length:i+1},(o,r)=>{const a=n+(s-n)*r/i;return{x:t.x+Math.cos(a)*e,y:t.y+Math.sin(a)*e}});function Hl(t,e,n,s,i,o=1,r){const{point:a,along:l}=n,c=s/300;switch(e.item){case"mug":{const h=cs({x:a.x,y:a.y-4*c},20*c,24*c);t.line(hs({x:a.x+10*c*Math.sign(o||1),y:a.y-4*c},7*c,-Math.PI/2,Math.PI/2).map(u=>({x:a.x+(u.x-a.x)*Math.sign(o||1),y:u.y})),i),t.shape(h,e.color,i);return}case"phone":{const h=Math.atan2(l.y,l.x)-Math.PI/2;t.shape(cs(a,13*c,24*c,h),e.color,i),t.shape(cs(a,9*c,17*c,h),"#8fd0f5",0);return}case"book":{const h=26*c,u=34*c;t.shape([{x:a.x,y:a.y-u/2},{x:a.x-h,y:a.y-u/2-3*c},{x:a.x-h,y:a.y+u/2-3*c},{x:a.x,y:a.y+u/2}],e.color,i),t.shape([{x:a.x,y:a.y-u/2},{x:a.x+h,y:a.y-u/2-3*c},{x:a.x+h,y:a.y+u/2-3*c},{x:a.x,y:a.y+u/2}],e.color,i);for(const d of[-1,1])for(const f of[.3,.5,.7]){const p=a.y-u/2+u*f;t.line([{x:a.x+d*5*c,y:p},{x:a.x+d*(h-5*c),y:p-2*c}],Math.max(.8,i*.5))}return}case"bag":{const h=a.y+10*c;t.line([{x:a.x-9*c,y:h},{x:a.x-5*c,y:a.y-2*c},{x:a.x+5*c,y:a.y-2*c},{x:a.x+9*c,y:h}],i),t.shape([{x:a.x-17*c,y:h},{x:a.x+17*c,y:h},{x:a.x+20*c,y:h+40*c},{x:a.x-20*c,y:h+40*c}],e.color,i);return}case"briefcase":{t.line(hs({x:a.x,y:a.y+6*c},7*c,Math.PI,Math.PI*2),i),t.shape(cs({x:a.x,y:a.y+22*c},46*c,32*c),e.color,i),t.line([{x:a.x-23*c,y:a.y+14*c},{x:a.x+23*c,y:a.y+14*c}],Math.max(.8,i*.6));return}case"umbrella":{const h=78*c,u=(r??a.y-120*c)-14*c,d={x:a.x,y:Math.min(a.y-60*c,u-h*.55)};t.line([{x:a.x,y:a.y+10*c},d],i),t.line(hs({x:a.x+5*c,y:a.y+10*c},5*c,Math.PI,0,8),i);const f=[...hs({x:d.x,y:d.y+h*.55},h,Math.PI,Math.PI*2,24)],p=[];for(let g=4;g>=0;g--){const m=d.x-h+2*h*g/5;p.push(...hs({x:m+h/5,y:d.y+h*.55},h/5,0,-Math.PI,6).reverse())}t.shape([...f,...p],e.color,i);return}case"broom":{const h={x:l.x*.4+.25*Math.sign(o||1),y:Math.max(.6,l.y)},u=Math.hypot(h.x,h.y),d={x:h.x/u,y:h.y/u},f={x:a.x-d.x*40*c,y:a.y-d.y*40*c},p={x:a.x+d.x*120*c,y:a.y+d.y*120*c};t.line([f,p],i*1.1);const g={x:-d.y,y:d.x},m=[{x:p.x+g.x*6*c,y:p.y+g.y*6*c},{x:p.x-g.x*6*c,y:p.y-g.y*6*c},{x:p.x-g.x*16*c+d.x*34*c,y:p.y-g.y*16*c+d.y*34*c},{x:p.x+g.x*16*c+d.x*34*c,y:p.y+g.y*16*c+d.y*34*c}];t.shape(m,e.color,i);return}case"cane":{const h=Math.min(.56*s,Math.max(.3*s,-a.y)),u=.12*Math.sign(o||1),d={x:u/Math.hypot(u,1),y:1/Math.hypot(u,1)},f={x:a.x+d.x*h,y:a.y+d.y*h},p=hs({x:a.x+7*c*Math.sign(o||1),y:a.y-2*c},7*c,Math.PI,Math.PI*2,8).map(g=>({x:a.x+(g.x-a.x)*Math.sign(o||1),y:g.y}));t.line([...p,{x:a.x,y:a.y+2*c},f],i*1.2),t.shape(cs({x:f.x,y:f.y-3*c},9*c,7*c),e.color,0);return}case"parcel":{const h={x:a.x,y:a.y-6*c};t.shape(cs(h,50*c,40*c),e.color,i),t.line([{x:h.x-25*c,y:h.y-6*c},{x:h.x+25*c,y:h.y-6*c}],Math.max(.8,i*.7)),t.line([{x:h.x,y:h.y-20*c},{x:h.x,y:h.y+20*c}],Math.max(.8,i*.7));return}}}const Rl=(t,e)=>(t[`held.${e}`]??1)>=.5,Vf=t=>Math.sin(t*Math.PI/2);function Jf(t){const e=o=>Math.max(1,o.lineWidth*.45),n=o=>(r,a,l,c,h)=>{const u=t[o];u&&Rl(h??{},o)&&Hl(l,u,Jo(a,o),a.height,e(a),Vf(a.turn),a.head.center.y-a.head.ry)},s=(o,r,a,l,c)=>{const h=t.both;if(!h||!Rl(c??{},"both"))return;const u=Jo(r,"left"),d=Jo(r,"right"),f={point:{x:(u.point.x+d.point.x)/2,y:(u.point.y+d.point.y)/2},along:{x:(u.along.x+d.along.x)/2,y:(u.along.y+d.along.y)/2},depth:(u.depth+d.depth)/2};Hl(a,h,f,r.height,e(r),Vf(r.turn),r.head.center.y-r.head.ry)},i={parts:{}};if(t.left&&(i.parts["arm.left"]={over:n("left")}),t.right&&(i.parts["arm.right"]={over:n("right")}),t.both){const o=r=>(a,l,c,h,u)=>{const d=r==="left"?"right":"left";(r==="left"?l.parts["arm.left"].depth>=l.parts["arm.right"].depth:l.parts["arm.right"].depth>l.parts[`arm.${d}`].depth)&&s(a,l,c,h,u)};for(const r of["left","right"])i.parts[`arm.${r}`]={...i.parts[`arm.${r}`],over:bv(i.parts[`arm.${r}`]?.over,o(r))}}return i}function bv(t,e){return t?(n,s,i,o,r)=>{t(n,s,i,o,r),e(n,s,i,o,r)}:e}function Ll(t,e){const n=(i,o)=>i&&o?(r,a,l,c,h)=>{i(r,a,l,c,h),o(r,a,l,c,h)}:i??o,s={};for(const i of new Set([...Object.keys(t.parts??{}),...Object.keys(e.parts??{})])){const o=t.parts?.[i],r=e.parts?.[i];s[i]={under:n(o?.under,r?.under),clip:n(o?.clip,r?.clip),over:n(o?.over,r?.over)}}return{behind:n(t.behind,e.behind),parts:s,front:n(t.front,e.front)}}function us(t={}){if(t.build&&!(t.build in _o))throw new Error(`character: unknown build '${t.build}'`);const e=t.build?_o[t.build]:{},n=(t.proportions??"bold")==="bold",s=t.figure??"fluid",i=t.look??"clean",o=t.height??300,r=s==="stick",a=s==="organic",l=t.shoulderWidth??e.shoulderWidth??(a?.07:.06),c=t.hipWidth??e.hipWidth??(a?.045:.022),h=t.lineWidth??o*(a?.005:n?.045:.022),u=t.ink??(a?"#53362d":i==="pencil"?"#2f2f33":"#1e293b"),d=t.skin??(a?"#f1bf98":i==="pencil"?"none":"#ffffff"),f=a?Bd(t.body??{},{skin:d,ink:u,lineWidth:h,shoulderWidth:l,hipWidth:c}):void 0;if(t.leafOutfit&&!a)throw new Error("character: leafOutfit requires figure: 'organic'");const p=t.outfit?Gf(t.outfit):null,g=t.holding?Uf(t.holding):{};let m=p?Ll(p,t.layers??{}):t.layers??{};return t.leafOutfit&&(m=Ll(jf(t.leafOutfit),m)),Object.keys(g).length>0&&(m=Ll(m,Jf(g))),{plan:t.plan??rl({headSize:t.headSize??e.headSize??(a?.27:n?.3:.24),shoulderWidth:r?0:l,hipWidth:r?0:c,legLength:t.legLength??e.legLength??1,armLength:t.armLength??e.armLength??1,feet:t.feet??e.feet}),figure:s,...f?{body:f}:{},look:i,height:o,lineWidth:f?.outline.width??h,ink:f?.outline.color??u,skin:f?.fill??d,seed:t.seed??1,pencil:a?{construction:!1,...t.pencil}:t.pencil??{},layers:m,holding:g,contact:t.contact??"ground",hands:t.hands??(a?"cartoon":"dot"),handStyle:t.handStyle??(a?"natural":"glove"),handSize:t.handSize??(a?.073:t.handStyle==="natural"?.14:.17),head:If(t),face:{...a?{style:"anime",projection:"volume",iris:"#66422e",nose:!0}:{},...t.face,teeth:t.face?.teeth??!1,tongue:t.face?.tongue??!1}}}function wv(t,e,n,s){const{point:i,facing:o}=es(t,[e,n,s]);return{point:i,facing:o}}const Fl=t=>t.rest[1]<-.5,kv=.3;function vv(t,e,n){return t.figure==="stick"?Fl(e)?n.slice(0,3):n:Fl(e)&&n.length>=3?wn(n[0],n[1],n[2],kv):n.length===3?wn(n[0],n[1],n[2],1):n}function bi(t,e){const n=t.plan.id==="human"?{...lt,...e}:e;return Zo(t,n,cl(t.plan,n,{height:t.height,contact:t.contact}))}function Zo(t,e,n){const s={},i={},o={},r=.01*t.height;t.plan.chains.forEach(f=>{const p=n.chains[f.id];s[f.id]=p.points;const g=p.depths.reduce((k,y)=>k+y,0)/p.depths.length,m=f.parent?n.chains[f.parent]:void 0,w=m?m.depths[f.at??m.depths.length-1]:n.hipDepth,v=g-w;o[f.id]=Math.abs(v)<r?0:v,i[f.id]={points:vv(t,f,p.points),depth:g,order:0}}),i.head={points:[n.head.center],depth:n.head.depth,order:0},o.head=0;const a=[...t.plan.chains.map(f=>f.id),"head"],l=f=>t.body&&f.startsWith("arm.")&&o[f]>=0?1:0,c=[...a].sort((f,p)=>l(f)-l(p)||o[f]-o[p]||a.indexOf(f)-a.indexOf(p));c.forEach((f,p)=>{i[f].order=p});const h={hip:n.hip};for(const[f,[p,g]]of Object.entries(t.plan.landmarks??{})){const m=n.chains[p]?.points;m&&(h[f]=m[Math.min(g,m.length-1)])}const u={};for(const[f,p]of Object.entries(h))u[f]=p.y>=n.groundY-.01*t.height;const d={height:t.height,lineWidth:t.lineWidth,turn:e.turn??0,...n.bodyForward?{bodyForward:n.bodyForward}:{},points:h,chains:s,parts:i,head:n.head,groundY:n.groundY,grounded:u};return t.body&&(d.bodyContours=jd(t.body,d,t.plan)),{skeleton:n,joints:d,order:c}}function fe(t,e){return bi(t,e).joints}function Zf(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=xt(s,i,{x:0,y:0});r.facing>0&&t.guide(r.points),t.guide(xt(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 Qf(t,e,n,s,i,o){const r=n.lineWidth;if(n.body&&n.skin==="none"&&(e=si(t,e)),i==="head"){const{head:f}=s;let p;const g=()=>p??=Ud(f,n.face),m=n.skin==="none"?null:n.skin;n.face.projection==="volume"||n.face.shape==="angular"?e.shape(g(),m,r):e.ellipse(f.center.x,f.center.y,f.rx,f.ry,f.angle,m,r),n.body&&n.skin!=="none"&&e.look==="clean"&&Vu(t,g(),f.center,n.body.shading),uv(t,e,n.head,f,o,{lineWidth:r,skin:n.skin,face:n.face,faceUnderHair:!!n.body},()=>{e.look!=="silhouette"&&(t.save(),n.body&&(t.beginPath(),g().forEach((w,v)=>v?t.lineTo(w.x,w.y):t.moveTo(w.x,w.y)),t.closePath(),t.clip()),O5(e,f,o,r,{...n.face,skin:n.skin==="none"?"#ffffff":n.skin},t),t.restore())});return}const a=n.plan.chains.find(f=>f.id===i),l=s.chains[i],c=s.parts[i].points;if(n.body&&Xd(t,e,n.body,s,i)){if(i.startsWith("leg.")&&Xd(t,e,n.body,s,i.replace("leg.","foot.")),i.startsWith("arm."))if(n.hands==="cartoon")eg(t,e,n,l,i.endsWith(".left")?"left":"right",o);else{const f=l.at(-1);e.ellipse(f.x,f.y,n.height*.014,n.height*.014,0,n.skin==="none"?null:n.skin,r)}return}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,p)=>[a.bones[f].width[0]*r,a.bones[p].width[1]*r];if(Fl(a)){const[f,p]=h(0,1);if(e.limb(c,f,p),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."))eg(t,e,n,l,i.endsWith(".left")?"left":"right",o);else{const g=l[l.length-1];e.dot(g.x,g.y,r*.62)}return}if(i==="spine"){const f=s.points["hip.left"],p=s.points["hip.right"];f&&p&&Math.hypot(f.x-p.x,f.y-p.y)>.5&&e.limb([f,p],r*1.3,r*1.3);const[g,m]=h(0,a.bones.length-1);e.limb(c,g,m);const w=s.points["shoulder.left"],v=s.points["shoulder.right"];w&&v&&Math.hypot(w.x-v.x,w.y-v.y)>.5&&e.limb(wn(w,l[l.length-1],v,1,10),r*1.15,r*1.15);return}const[u,d]=h(0,a.bones.length-1);e.limb(c,u,d)}function tg(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{...Ot,...s,turn:o+(s.turn??0)}}function eg(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;vo(t,r,tg(o,i),{size:n.handSize*n.height,side:i,angle:l,pen:e,skin:n.skin==="none"&&!n.body?"#ffffff":n.skin,fingers:n.handStyle==="natural"?5:4,plump:n.handStyle==="natural"?1.15:1.6,lineWidth:n.lineWidth*(n.body?.65:.3),connected:!!n.body,shading:n.body?.shading,nails:n.body?!1:void 0})}function ng(t,e,n,s=0){const i=e.plan.id==="human"?{...lt,...n}:n;Nl(t,e,i,bi(e,i),s)}function Qo(t,e){const n=e/t.height;return{...t,height:e,lineWidth:t.lineWidth*n}}function Mv(t,e,n,s){const i=t.plan.id==="human"?{...lt,...e}:e,o=Fo(t.plan,i,{height:s.height,contact:t.contact},n);return Zo(Qo(t,o.height),i,o).joints}function Sv(t,e,n,s,i){const o=e.plan.id==="human"?{...lt,...n}:n,r=Fo(e.plan,o,{height:i.height,contact:e.contact},s),a=Qo(e,r.height);Nl(t,a,o,Zo(a,o,r),i.time??0)}function sg(t,e,n,s){const i=t.plan.id==="human"?{...lt,...e}:e,o=Fo(t.plan,i,{height:s.height,contact:t.contact},n),r=Qo(t,o.height),{joints:a,order:l}=Zo(r,i,o),c=o.height/s.height,h=l.map(p=>(a.parts[p]?.depth??0)/c),u=l.filter(p=>p==="spine"||p.startsWith("leg.")),d=Math.max(...u.map(p=>a.parts[p].depth/c)),f=Math.max(...u.map(p=>a.parts[p].order));return l.map((p,g)=>({part:p,depth:h[g],...r.body?{sortDepth:p.startsWith("arm.")&&g>f?Math.max(h[g],d):h[g]}:{},draw(m,w=0){const v=ni(m,{look:r.look,ink:r.ink,lineWidth:r.lineWidth,seed:ne(`${r.seed}:${p}`),time:w,pencil:r.pencil}),k=x=>{x&&(m.save(),x(m,a,v,w,i),m.restore())};m.save(),m.lineCap="round",m.lineJoin="round",g===0&&(r.look==="pencil"&&r.pencil.construction!==!1&&Zf(v,r,a),k(r.layers.behind),Hf(m,r.body&&r.skin==="none"?si(m,v):v,r.head,a.head,i,{lineWidth:r.lineWidth,skin:r.skin,face:r.face}));const y=r.layers.parts?.[p];k(y?.under),m.save(),y?.clip?.(m,a,v,w,i),Qf(m,v,r,a,p,i),m.restore(),k(y?.over),p==="head"&&Rf(m,v,r.head,a.head,i,{lineWidth:r.lineWidth,skin:r.skin,face:r.face}),g===l.length-1&&k(r.layers.front),m.restore()}}))}function Nl(t,e,n,s,i,o){const{joints:r}=s,a=o?s.order.filter(h=>o.has(h)):s.order,l=ni(t,{look:e.look,ink:e.ink,lineWidth:e.lineWidth,seed:e.seed,time:i,pencil:e.pencil}),c=h=>{h&&(t.save(),h(t,r,l,i,n),t.restore())};t.save(),t.lineCap="round",t.lineJoin="round",!o&&e.look==="pencil"&&e.pencil.construction!==!1&&Zf(l,e,r),o||c(e.layers.behind),Hf(t,e.body&&e.skin==="none"?si(t,l):l,e.head,r.head,n,{lineWidth:e.lineWidth,skin:e.skin,face:e.face});for(const h of a){const u=e.layers.parts?.[h];c(u?.under),t.save(),u?.clip?.(t,r,l,i,n),Qf(t,l,e,r,h,n),t.restore(),c(u?.over)}Rf(t,l,e.head,r.head,n,{lineWidth:e.lineWidth,skin:e.skin}),o||c(e.layers.front),t.restore()}function xv(t,e,n,s){const i=e.plan.id==="human"?{...lt,...n}:n,o=bi(e,i).joints.head.rx,r=Qo(e,e.height*s.radius/Math.max(1e-6,o)),a=bi(r,i);t.save(),t.translate(s.x-a.joints.head.center.x,s.y-a.joints.head.center.y),Nl(t,r,i,a,s.time??0,new Set(["head"])),t.restore()}function Wl(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 Ce(t,e,n,s){const i=t.plan.id==="human"?{...lt,...e}:e;let o;if(Array.isArray(s))o=s;else{const{skeleton:r}=bi(t,i),a=cl(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),p=s.depth??r.chains[n].depths[r.chains[n].depths.length-1],g=Math.cos(f),m=Math.sin(f);o=[u*g-p*m,-d,u*m+p*g]}return ui(t.plan,i,n,o,{height:t.height})}const ig=new Set(["walk","walking","gait"]);function tr(t,e=lt,n){let s={...e};for(const[o,r]of Object.entries(t))typeof r=="number"&&!ig.has(o)&&(s[o]=r);const i=Math.max(0,Math.min(1,typeof t.walking=="number"?t.walking:0));if(i>0){const o=typeof t.gait=="string"?t.gait:void 0,r=o?n?.[o]??o:void 0,a=Go(r,typeof t.walk=="number"?t.walk:0,s);s=Object.fromEntries(Object.keys({...s,...a}).map(l=>[l,(s[l]??0)+((a[l]??0)-(s[l]??0))*i]))}return s}function Tv(t){const{character:e}=t,n=e.height*.8,s=e.height,i=e.plan.id==="human"?lt:{};return{type:"custom",x:t.x-n/2,y:t.y-s,width:n,height:s,props:{...i,...t.pose},character:e,...t.gaits?{gaits:t.gaits}:{},draw(o,r,a){o.translate(n/2,s),ng(o,e,tr(r.props??{},i,t.gaits),a)}}}function og(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,...t.bodyContours?{bodyContours:Object.fromEntries(Object.entries(t.bodyContours).map(([o,r])=>[o,{...r,outline:r.outline.map(s),samples:r.samples.map(a=>({...a,center:s(a.center),left:s(a.left),right:s(a.right)}))}]))}:{},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 Ev(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[c,h]of e.state?.values.get(n)??[])c==="x"||c==="motionPathX"?o=typeof h=="number"?h:o:c==="y"||c==="motionPathY"?r=typeof h=="number"?h:r:(typeof h=="number"||ig.has(c))&&(i[c]=h);const a=tr(i,s.plan.id==="human"?lt:{},t.gaits),l=fe(s,a);return{pose:a,joints:og(l,t.x+o+t.width/2,t.y+r+t.height)}}function Dl(t,e=lt){const n=[];return t.forEach((s,i)=>{const o=i===0?e:n[i-1],r=typeof s.pose=="string"?ye[s.pose]:void 0;n.push(r?{...r,turn:o.turn??0}:{...o,...s.pose})}),n}function Av(t,e,n=lt){const s=Dl(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 er=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Ee=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],nr=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],Bl=t=>Math.hypot(...t),rg=t=>nr(t,1/(Bl(t)||1)),sr=t=>({...lt,...t}),zl=t=>Ue(t.character.plan,sr(t.pose),{height:t.character.height,contact:t.character.contact});function $n(t,e,n){return er(t.position,zl(t).chains[e][n])}function ag(t,e,n){const s=sr(t.pose),i=zl(t).hip,o=ts(t.character.plan,s,t.character.height),r=Ee(Ee(n,t.position),i),a=Qn(r,(s.roll??0)*Math.PI/180),l=er(o.root,Qt(a,-(s.turn??0)*Math.PI/2));return ui(t.character.plan,s,e,l,{height:t.character.height})}function lg(t,e,n,s="toe"){const i=`leg.${e}`,o=s==="toe"?3:2;let r={...t,pose:sr(t.pose),position:[...t.position]};for(let l=0;l<6;l++){const c=zl(r).chains[i],h=Ee(c[o],c[2]);r={...r,pose:ag(r,i,Ee(n,h))};const u=$n(r,i,o);r.position[1]+=n[1]-u[1]}const a=Bl(Ee($n(r,i,o),n));return{...r,reached:a<t.character.height*.002}}function cg(t,e){const n=$n(t,`arm.${e}`,2),s=$n(t,`arm.${e}`,1);return er(n,nr(rg(Ee(n,s)),t.character.lineWidth*.5))}function $v(t,e,n={}){const s=Math.min(t.character.height,e.character.height),i=n.length??s*.22;if(!(i>0)||!Number.isFinite(i))throw new Error("meetDandiya: stick length must be positive and finite");const o=n.point??[(t.position[0]+e.position[0])/2,Math.max(t.position[1],e.position[1])+s*.62,(t.position[2]+e.position[2])/2],r=(c,h)=>{const u=rg([o[0]-c.position[0],s*.2,o[2]-c.position[2]]),d=Ee(o,nr(u,i));let f=sr(c.pose);for(let g=0;g<6;g++){const m={...c,pose:f},w=$n(m,`arm.${h}`,2);f=ag(m,`arm.${h}`,Ee(d,Ee(cg(m,h),w)))}for(const[g,m]of Object.entries(St.hold))f[`hand.${h}.${g}`]=m;const p=cg({...c,pose:f},h);return{pose:f,stick:{grip:p,tip:er(p,nr(u,i))}}},a=r(t,n.sideA??"right"),l=r(e,n.sideB??"right");return{a:a.pose,b:l.pose,sticks:[a.stick,l.stick],point:o,reached:[a.stick,l.stick].every(c=>Bl(Ee(c.tip,o))<s*.002)}}function hg(t,e){const n=e.count??8,s=e.beatsPerTurn??32;if(!Number.isFinite(t)||!Number.isFinite(e.radius)||e.radius<=0||!Number.isInteger(n)||n<1||!Number.isFinite(s)||s<=0)throw new Error("danceCircleAt: finite beat, positive radius/beatsPerTurn and a positive integer count are required");const i=e.center??[0,0],o=e.direction??1;if(i.length!==2||!i.every(Number.isFinite)||!Number.isFinite(e.angle??0)||!Number.isFinite(e.spins??0)||![1,-1].includes(o)||e.facing!==void 0&&!(typeof e.facing=="number"?Number.isFinite(e.facing):["inward","outward","tangent"].includes(e.facing)))throw new Error("danceCircleAt: center, angle, spins and facing must be finite; direction is 1 or -1");const r=e.character??us({height:1.7}),a=e.style??"garba",l=(h,u)=>{const d=(e.angle??0)+360*u/n+o*360*h/s,f=d*Math.PI/180,p=e.facing??"inward",g=(typeof p=="number"?p:d+(p==="inward"?180:p==="tangent"?o*90:0))+(e.spins??0)*360*h/s,m=di(a,h,{...e.pose,turn:g/90});return{character:r,position:[i[0]+e.radius*Math.sin(f),0,i[1]+e.radius*Math.cos(f)],pose:m.pose,heading:g,strike:m.strike}},c=di(a,t).contact;return Array.from({length:n},(h,u)=>{const d=l(t,u);if(e.plantFeet===!1)return{...d,planted:!1};const f=l(c.start,u),p=$n(f,`leg.${c.side}`,3),g=lg(d,c.side,p);return{...d,pose:Wl(d.pose,g.pose,c.weight),position:[d.position[0],g.position[1]*c.weight,d.position[2]],planted:g.reached&&c.weight===1}})}function Pv(t,e){if(e.count!==void 0&&e.count!==t.length)throw new Error("danceCircleTracks: count must match targets.length");const n=e.bpm??120,s=e.samplesPerBeat??16;if(!t.length||![n,e.beats,s].every(l=>Number.isFinite(l)&&l>0))throw new Error("danceCircleTracks: targets and positive finite bpm, beats and samplesPerBeat are required");if(!Number.isFinite(e.start??0))throw new Error("danceCircleTracks: start must be finite");const i=Math.max(1,Math.ceil(e.beats*s)),o=Array.from({length:i+1},(l,c)=>({time:(e.start??0)+e.beats*c/i*6e4/n,members:hg(e.beats*c/i,{...e,count:t.length})})),r=o.some(l=>l.members.some(c=>c.pose.roll!==0)),a=new Set(["x","y","z","rotateY",...r?["turn","roll"]:[]]);return t.flatMap((l,c)=>{const h=o.map(u=>{const d=u.members[c],{turn:f,...p}=d.pose;return{time:u.time,pose:{...r?d.pose:p,x:d.position[0],y:d.position[1],z:d.position[2],rotateY:r?0:d.heading}}});return Object.keys(h[0].pose).filter(u=>a.has(u)||h.some(d=>d.pose[u]!==(e.pose?.[u]??lt[u]))).map(u=>({id:`${l}-circle-${u}`,target:l,property:u,keyframes:h.map(d=>({time:d.time,value:d.pose[u],easing:"linear"}))}))})}const ir=t=>Math.min(1,Math.max(0,t));function Iv(t){const e={...ut,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 Ov(t){return t-_v*Math.sin(2*Math.PI*t)/(2*Math.PI)}const _v=.5;function Cv(t,e){if(!(e<=t.takeoff||e>=t.landing))return(e-t.takeoff)/(t.landing-t.takeoff)}function ug(t,e){const n=typeof t=="string"?wi[t]:t,s=Iv(n),i=ir(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=Zn(r.pose,a.pose,Wt(a.easing??"ease-in-out")(ir(l))),h=Cv(n,i);return h===void 0?{...c,spin:0,rise:0}:{...c,spin:n.spin*Ov(h),rise:4*n.height*h*(1-h)}}function dg(t,e,n){const s=typeof t=="string"?wi[t]:t,i=ir(e),o=ir((i-s.takeoff)/(s.landing-s.takeoff));return s.travel*n*o}function Hv(t,e,n={}){const s=typeof e=="string"?wi[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:ug(s,d)}}),c=Object.keys(ut).filter(h=>a.some(u=>u.pose[h]!==ut[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*dg(s,u.progress,n.height)}))})}return c}const Rv={leftHip:-55,leftKnee:-95,rightHip:55,rightKnee:95,leftShoulder:45,rightShoulder:-45,leftElbow:10,rightElbow:-10,lean:22,stretch:.94,headTilt:6},Lv={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},or={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},Fv={leftHip:-22,leftKnee:-30,rightHip:22,rightKnee:30,leftAnkle:10,rightAnkle:10,leftShoulder:-125,rightShoulder:125,leftElbow:0,rightElbow:0,lean:8,headTilt:0},Nv={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 ds(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:Rv},{at:.27,pose:Lv,easing:"ease-out-quad"},...i,{at:.76,pose:Fv},{at:.86,pose:Nv,easing:"ease-out-quad"},{at:1,reset:!0}]}}const wi={frontFlip:ds("Front flip (tuck)",360,.56,.35,[{at:.38,pose:or,easing:"ease-out-cubic"},{at:.64,pose:or}]),backFlip:ds("Back flip (tuck)",-360,.58,-.15,[{at:.36,pose:{...or,lean:18},easing:"ease-out-cubic"},{at:.64,pose:{...or,lean:18}}]),layout:ds("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:ds("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:ds("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:ds("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)};function fg(t,e){const n=Math.min(1,Math.max(0,t.turn??0)),s=1-n,i={...lt,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`],p=s+c*n;i[`leg.${l}.rotate`]=90*s,i[`leg.${l}.spread`]=0,i[`leg.${l}.swing`]=d*p,i[`leg.${l}.knee`]=f*p,i[`leg.${l}.ankle`]=-(t[`${a}Ankle`]??0),i[`leg.${l}.toeOut`]=(t[`${a}FootOut`]??0)*Wv,i[`eye.${l}`]=t[`${a}Eye`],i[`brow.${l}`]=t[`${a}Brow`],e&&Object.assign(i,Dv(l,e[a]??Ot,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 Wv=70;function Dv(t,e,n,s){const i=t==="right"?1-s:1+s,o={};for(const r of Object.keys(Ot))o[`hand.${t}.${r}`]=e[r]??Ot[r];return o[`hand.${t}.turn`]=(e.turn??0)-i,o[`hand.${t}.roll`]=(e.roll??0)+n,o}class gg{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 Bv(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 ql=Math.PI*2;function zv(t,e=16){const n=new gg,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*ql,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 pg(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*ql;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 mg(t,e,n=24){const s=new gg,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*ql;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 pg(s,t,o,1,i),pg(s,t,r,-1,i),s.build()}function rr(t){const e=Array.from({length:t.indices.length/3},()=>[]);for(const n of Bv(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 jl=new Map;function qv(t){const e=jl.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 jl.size<512&&jl.set(t,n),n}Jt([-3,-5,-4]);const jv=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)};function yg(t,e,n){const s=[0,0,0];for(const i of n){const o=qv(i.color);let r;if(i.light==="ambient")r=i.intensity;else if(i.light==="directional")r=i.intensity*Math.max(0,-$e(e,i.direction));else{const a=se(i.position,t),l=io(a),c=l>0?fn(a,1/l):e,h=i.range?Math.max(0,1-l/i.range)**2:1;if(r=i.intensity*Math.max(0,$e(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*=jv(u,d,-$e(c,i.direction))}}s[0]+=o[0]*r,s[1]+=o[1]*r,s[2]+=o[2]*r}return s}function bg(t,e){return t?Math.min(1,Math.max(0,(e-t.near)/(t.far-t.near))):0}function Yl(t,e,n={}){t.save(),Yv(t,e,n),t.restore()}function Yv(t,e,n){const s=Kl(e,n);n.shadow!==!1&&Xl(t,e,n);for(const i of e.under)wg(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)wg(t,i,s,n)}function wg(t,e,n,s){const i=s.loose?.[e.part.id];if(!i){Vl(t,e,n,s);return}if(i.opacity<=0)return;const o=e.faces.flatMap(c=>c.points);if(o.length===0)return;const r=o.map(c=>c.x),a=o.map(c=>c.y),l={x:(Math.min(...r)+Math.max(...r))/2,y:(Math.min(...a)+Math.max(...a))/2};t.save(),t.globalAlpha*=Math.min(1,i.opacity),t.translate(l.x+i.x,l.y+i.y),t.rotate(i.rotate*Math.PI/180),t.translate(-l.x,-l.y),Vl(t,e,n,s),t.restore()}function Kl(t,e={}){return e.lineWidth??Math.max(1.3,t.sizePx*.022)}function Xl(t,e,n={}){e.shadow.opacity<=0||e.shadow.points.length<3||(t.save(),t.globalAlpha=e.shadow.opacity,ar(t,e.shadow.points,n.ink??"#26262b",!1),t.restore())}function Kv(t,e,n,s={}){t.save(),Vl(t,e,n,s),t.restore()}function kg(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 p of h){if(p.part.part.id===u.part.part.id)continue;const g=p.face;if(g.normal[0]*f[0]+g.normal[1]*f[1]+g.normal[2]*f[2]<=.8)continue;const w=g.normal[0]*(d[0]-g.center[0])+g.normal[1]*(d[1]-g.center[1])+g.normal[2]*(d[2]-g.center[2]);w>-vg/5&&w<vg&&(u.layer=Math.max(u.layer,p.layer),u.depth=Math.max(u.depth,p.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=Gl(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?Mg(h,s):u.light?Xv(h,u,s):Ul(h);f&&(!i&&s.look==="silhouette"?d.shape(u.points,f,0):ar(t,u.points,i||u.light?f:lr(f,u.tone),!0,h.cut?1.6:.8));const p=(h.part.outline??1)*n;if(p>0)for(const g of u.edges??[])g.length>1&&d.line(g,p);for(const g of u.marks??[])d.line(g,n*.7)}}t.restore()}const vg=.05;function Gl(t,e,n,s){return ni(t,{look:s.look??"clean",ink:e.part.ink??s.ink??"#26262b",lineWidth:n,seed:ne(`${s.seed??0}:${e.part.id}`),time:s.time??0,pencil:{construction:!1,rubbedOut:0,...s.pencil}})}function Ul(t){const{part:e}=t;return e.glow&&t.glow>0&&e.fill?Ql(e.fill,e.glow.color,t.glow):e.fill}function Xv(t,e,n){const{part:s}=t;if(!s.fill)return;const i=Zl(s.fill,e.light,e.fog??0,n.fog);return s.glow&&t.glow>0?Ql(i,s.glow.color,t.glow):i}function Mg(t,e){const n=Ul(t);return n&&(Uv(n)||t.glow>0)?n:e.paper??"#fbf8ef"}function Vl(t,e,n,s){e.opacity<1?(t.save(),t.globalAlpha*=e.opacity,Sg(t,e,n,s),t.restore()):Sg(t,e,n,s)}function Sg(t,e,n,s){if(s.style==="stick")return Gv(t,e,n,s);const{part:i}=e,o=Gl(t,e,n,s),r=Ul(e),a=s.look==="silhouette";for(const c of e.faces)r&&(a?o.shape(c.points,r,0):ar(t,c.points,lr(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 Gv(t,e,n,s){const{part:i}=e;if(i.solidOnly)return;const o=Gl(t,e,n,s);if(e.spine){o.line(e.spine,n*1.15);return}const r=Mg(e,s);for(const l of e.faces)ar(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 Uv(t){const e=fs(t);return e?(.299*e[0]+.587*e[1]+.114*e[2])/255<.3:!1}function ar(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 fs(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 Jl=t=>`#${t.map(e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0")).join("")}`;function lr(t,e){const n=fs(t);return n?Jl(e>=1?n.map(s=>s+(255-s)*(e-1)*2):n.map(s=>s*e)):t}function Zl(t,e,n,s){const i=fs(t);if(!i)return t;let o=i.map((a,l)=>a*e[l]);const r=s?fs(s):void 0;return r&&n>0&&(o=o.map((a,l)=>a+(r[l]-a)*n)),Jl(o)}function Ql(t,e,n){const s=fs(t),i=fs(e);return!s||!i?n<.5?t:e:Jl(s.map((o,r)=>o+(i[r]-o)*n))}const Vv=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),Jv=new Set(["walk","walking","gait"]),xg=t=>typeof t=="number"?t:void 0,Zv=1.7;function Qv(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 tM(t){const e=$e([0,1,0],t);if(e>.999999)return oo();if(e<-.999999)return pe(Vt([1,0,0],180));const n=Gs([0,1,0],t);return pe(Vt(n,Math.acos(e)*180/Math.PI))}function eM(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=(k,y,x)=>u.push({mesh:k,world:Rt(i,y),material:x}),f=(k,y,x)=>d(e.sphere,va(k,[0,0,0,1],[y,y,y]),x);for(const k of n.chains){const y=s.chains[k.id],x=k.id==="spine"?1.9:1;k.bones.forEach((P,M)=>{const T=y[M],S=y[M+1],E=Us(T,S),[$,A]=P.width??[1,1],I=h*x*($+A)/2;if(E>1e-6){const C=gn(T,S,.5),D=tM(Jt(se(S,T)));d(e.cylinder,Rt(pn(C),Rt(D,mn([I,E,I]))),a)}f(T,h*x*$,a),f(S,h*x*A,a)}),k.id.startsWith("arm.")&&f(y[y.length-1],h*1.5,l)}const{center:p,rx:g,ry:m,axes:w}=s.head,v=[...w[0],0,...w[1],0,...w[2],0,...p,1];d(e.sphere,Rt(v,mn([g,m,g])),l);for(const k of[-1,1]){const y=Jt([k*.36,.15,.92]),x=Xs(p,Xs(Xs(fn(w[0],y[0]*g*1.04),fn(w[1],y[1]*m*1.04)),fn(w[2],y[2]*g*1.04))),P=[...w[0],0,...w[1],0,...w[2],0,...x,1];d(e.sphere,Rt(P,mn([g*.11,m*.14,g*.03])),c)}return u}const nM={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:us({...t.character,height:1}),cylinder:rr(mg(1,1,16)),sphere:rr(zv(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={...lt,...l.pose};for(const[T,S]of n)typeof S=="number"&&!Vv.has(T)&&!Jv.has(T)&&(u[T]=S);const d=Math.max(0,Math.min(1,xg(n.get("walking"))??l.walking??0));if(d>0){const T=typeof n.get("gait")=="string"?n.get("gait"):l.gait,S=Go(T,xg(n.get("walk"))??0,u);u=Object.fromEntries(Object.keys({...u,...S}).map(E=>[E,(u[E]??0)+((S[E]??0)-(u[E]??0))*d]))}const f=l.height??Zv,p=Rt(i.view,s),g={toView:T=>ie(p,T),toScreen:T=>a(T)},w=-g.toView([0,f/2,0])[2];if(w<=i.near)return null;const v=l.shadow===!1?[]:[{depth:w+f,draw:T=>Qv(T,g,f*.18)}];if(l.look==="solid"){const T=Ue(h.plan,u,{height:f,contact:h.contact});return{meshes:eM(l,c,h.plan,T,s),drawables:v}}const k=ie(s,[0,f*.6,0]),y=Jt(se(i.position,k)),x=yg(k,y,o).map(T=>Math.min(1,T));let P=h;if(o.length>0&&h.skin!=="none"){const T=Zl(h.skin,x,bg(r,Us(k,i.position)),r?.color);P={...h,skin:T,...h.body?{body:{...h.body,fill:T}}:{}}}const M=sg(P,u,g,{height:f});return{drawables:[...v,...M.map((T,S)=>({depth:-(T.sortDepth??T.depth)-S*1e-6,draw:(E,$)=>T.draw(E,$.time)}))]}}},Ze={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}},ki=1,cr=.55,Tg=.35,sM=1.6,Eg={a:"a",e:"e",i:"i",y:"i",o:"o",u:"u"},Ag={m:"m",b:"m",p:"m",f:"f",v:"f",w:"u",q:"u",l:"l",n:"l",d:"l",t:"l"},$g={अ:"a",आ:"a",इ:"i",ई:"i",उ:"u",ऊ:"u",ऋ:"i",ए:"e",ऐ:"e",ओ:"o",औ:"o",ऍ:"e",ऑ:"o"},Pg={"ा":"a","ि":"i","ी":"i","ु":"u","ू":"u","ृ":"i","े":"e","ै":"e","ो":"o","ौ":"o","ॅ":"e","ॉ":"o"},iM={प:"m",फ:"m",ब:"m",भ:"m",म:"m",व:"u"},oM="्",Ig="़",rM=t=>t>="क"&&t<="ह",Og=new Set([".",",","!","?",";",":","…","।","॥","—","-"]);function _g(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(Og.has(o))s("rest",sM);else if(/\s/.test(o)){const a=e[e.length-1];a&&a.viseme!=="rest"&&e.push({viseme:"c",weight:Tg})}else if((o==="o"||o==="e")&&r===o)s(o==="o"?"u":"i",ki),i++;else if(o in Eg)s(Eg[o],ki);else if(o in Ag)s(Ag[o],cr);else{if(o==="h")continue;if(/[a-z]/.test(o))s("c",cr);else if(o in $g)s($g[o],ki);else if(rM(o)){const a=r===Ig?o==="फ"?"f":void 0:iM[o];s(a??"c",cr);let l=i+1;n[l]===Ig&&l++;const c=n[l];c===oM?i=l:c&&c in Pg?(s(Pg[c],ki),i=l):(!c||/\s/.test(c)||Og.has(c)||s("a",ki*.6),i=l-1)}else(o==="ं"||o==="ँ")&&s("l",cr*.6)}}for(;e.length>0&&(e[e.length-1].viseme==="rest"||e[e.length-1].weight===Tg);)e.pop();return e}function tc(t,e={}){const n=e.fields?.mouth??"mouth",s=e.fields?.mouthWidth??"mouthWidth",i=e.energy??1,o=_g(t.text),r=[{time:t.start,value:Ze.rest.mouth}],a=[{time:t.start,value:Ze.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 p=Ze[u.viseme];r.push({time:f,value:p.mouth*i,easing:"ease-out"}),a.push({time:f,value:1+(p.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:Ze.rest.mouth,easing:"ease-in-out"}),a.push({time:t.end,value:Ze.rest.mouthWidth,easing:"ease-in-out"})),{[n]:r,[s]:a}}function aM(t,e,n={}){const s={};for(const i of[...e].sort((o,r)=>o.start-r.start))for(const[o,r]of Object.entries(tc(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 hr(t,e,n,s={}){if(n.length===0)return e;const i=s.fields?.mouth??"mouth",o=s.fields?.mouthWidth??"mouthWidth",r={[i]:Ze.rest.mouth,[o]:Ze.rest.mouthWidth,...s.rest},a=new Ht({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(p=>p.target===t&&p.property===u);let f=d?[...d.keyframes]:[{time:0,value:l(u,0)}];for(const p of n){const g=tc(p,s)[u];g[0]={...g[0],value:l(u,p.start)},g[g.length-1]={...g[g.length-1],value:l(u,p.end)},f=[...f.filter(m=>m.time<p.start||m.time>p.end),...g],f.sort((m,w)=>m.time-w.time)}h.push({id:d?.id??`${t}-${u}`,target:t,property:u,keyframes:f})}return h}const vi=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function Cg([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 gs=(t,[e,n,s])=>t==="z"?[e,n,s]:t==="x"?[s,n,e]:[e,s,n];function Hg(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(gs(n,[Math.cos(u)*t,Math.sin(u)*t,c]))}const a=[{corners:Array.from({length:s},(c,h)=>s-1-h),normal:gs(n,[0,0,-1])},{corners:Array.from({length:s},(c,h)=>s+h),normal:gs(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:gs(n,[Math.cos(u),Math.sin(u),0])})}const l=[];if(i>0)for(const c of[-r,r]){const h=o.push(gs(n,[0,0,c*1.01]))-1;for(let u=0;u<i;u++){const d=Math.PI*2*u/i,f=o.push(gs(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 Rg([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 vi([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 p=[a(f,h),a(f,h+1),a(f+1,h+1),a(f+1,h)];c.push({corners:p,normal:l(p)})}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 lM=t=>t.reduce((e,[n,s],i)=>{const[o,r]=t[(i+1)%t.length];return e+n*r-o*s},0)/2;function Lg(t,e){const n=lM(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:vi([0,-c,h])})}return{vertices:o,faces:r,creases:!0}}function Fg(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 Ng(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=vi([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=vi(Wg(h,u)),f=Wg(d,h);for(let p=0;p<n;p++){const g=Math.PI*2*p/n,m=Math.cos(g)*s(a),w=Math.sin(g)*s(a);i.push([r[0]+d[0]*m+f[0]*w,r[1]+d[1]*m+f[1]*w,r[2]+d[2]*m+f[2]*w])}});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:vi([h[0]-u[0],h[1]-u[1],h[2]-u[2]])})}return{vertices:i,faces:o,creases:!1}}function Wg(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 Dg(t){switch(t.type){case"box":return Cg(t.size);case"cylinder":return Hg(t.radius,t.length,t.axis,t.segments,t.spokes);case"ellipsoid":return Rg(t.radii,t.segments);case"extrude":return Lg(t.profile,t.width);case"panel":return Fg(t.points,t.facing);case"tube":return{...Ng(t.points,t.radius,t.segments),joined:t.joined}}}function ec(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],p=c[d],g=h[d],m=u[d];return .5*(2*p+(-f+g)*a+(2*f-5*p+4*g-m)*a*a+(-f+3*p-3*g+m)*a*a*a)})};return Array.from({length:e},(i,o)=>s(o/(e-1)))}const Pn=t=>Array.isArray(t)&&t.length===2&&t.every(e=>typeof e=="number"&&Number.isFinite(e));function ur(t,e){return((e-t)%360+540)%360-180}function Bg(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 ps(t,e){return Math.atan2(e[0]-t[0],e[1]-t[1])*180/Math.PI}function zg(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:ec(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 qg(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 jg(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 Mi=520,nc=["do","at","for","to","through","toward","speed","pose","gag","say","look","turns","dance","bpm","beats"],Yg=t=>Math.max(700,Array.from(t).length*65),Kg=70,Xg=35;function sc(t,e){const n=e[0]-t.x,s=e[1]-t.eyeHeight,i=e[2]-t.z,o=t.heading*Math.PI/180,r=n*Math.cos(o)-i*Math.sin(o),a=n*Math.sin(o)+i*Math.cos(o),l=Math.atan2(r,a)*180/Math.PI,c=Math.hypot(r,a),h=-Math.atan2(s,c)*180/Math.PI,u=Math.max(-Kg,Math.min(Kg,l*.75)),d=Math.max(-Xg,Math.min(Xg,h*.7));return{"head.turn":u,"head.nod":d,lookX:Math.max(-1,Math.min(1,(l-u)/45)),lookY:Math.max(-1,Math.min(1,(h-d)/30))}}const Gg={walk:1.3,bouncy:1.4,doubleBounce:1.2,sneak:.6,strut:1.2,tired:.8,run:3.6,shove:.7},ic=Object.keys(Yt),oc=Object.keys(ye),rc=Object.keys(Vo),cM=.25,hM=700/180,uM=200,dM=300;function Ug(t){if(!Array.isArray(t))return[{beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const e=[...ic,"face","spin","dance","hold","pose","gag","place","say","look"],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))nc.includes(c)||o(ft("beat field",c,nc,a[c]));const l=typeof r.do=="string"?oc.includes(r.do)?"pose":rc.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));for(const c of["at","for","turns","bpm","beats"]){const h=r[c];h!==void 0&&(typeof h!="number"||!Number.isFinite(h)||(c==="at"?h<0:c!=="turns"&&h<=0))&&o(`\`${c}\` must be finite${c==="turns"?"":c==="at"?" and non-negative":" and positive"}.`)}if(r.do==="dance"&&!(typeof r.dance=="string"&&Object.hasOwn(Sn,r.dance))&&o(ft("native dance",r.dance,Object.keys(Sn))),ic.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&&!Pn(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(Pn))&&o("`through` is a list of points on the ground, each [x, z] metres.")),r.do==="place"&&!Pn(r.to)&&o("`place` needs `to`: a point on the ground, [x, z] metres."),r.do==="face"&&!(Pn(r.toward)||typeof r.toward=="number"&&Number.isFinite(r.toward))&&o("`face` needs `toward`: a point [x, z] or a finite heading in degrees."),r.do==="say"&&!(typeof r.say=="string"&&r.say.trim().length>0)&&o("`say` needs `say`: the line spoken."),r.do==="look"){const c=r.look??r.toward;Array.isArray(c)&&(c.length===2||c.length===3)&&c.every(u=>typeof u=="number"&&Number.isFinite(u))||c==="camera"||o("`look` needs `look`: a point [x, z] or [x, y, z] to look at, or `camera`.")}r.do==="pose"&&!(typeof r.pose=="object"&&r.pose!==null)&&!oc.includes(r.pose)&&o(ft("pose",r.pose,oc)),r.do==="gag"&&!rc.includes(r.gag)&&o(ft("gag",r.gag,rc))}),n}function fM(t,e,n){const s=Ug(e);if(s.length>0)throw new Error(`characterScript3D: ${s.length} problem(s) in the beats:
54
54
  ${s.map(M=>` beat ${M.beat}: ${M.message}`).join(`
55
- `)}`);const i=n.height??1.7,o={...lt,...n.pose},r=(M,T=o)=>{const S=M.match(/^hand\.(?:left|right)\.(.+)$/)?.[1];return T[M]??lt[M]??(S?Ot[S]:void 0)??0};let[a,l]=n.position??[0,0],c=n.heading??0,h=0;const u=new Map,d=[],f=(M,T,S,E="linear")=>{const $=u.get(M)??[];$.push({time:T,value:S,easing:E}),u.set(M,$)},p=(M,T,S)=>{const E=u.get(M)??[];for(let $=E.length-1;$>=0;$--)if(E[$].time===T){if(E[$].value===S)return;break}f(M,T,S)};f("x",0,a),f("z",0,l),f("rotateY",0,c);const g=(M,T,S)=>{const E=cr(c,T);if(Math.abs(E)<1)return S!==void 0&&(p("rotateY",M,c),f("rotateY",M+S,c)),M+(S??0);const $=S??Math.max(lM,Math.abs(E)*aM);return p("rotateY",M,c),c+=E,f("rotateY",M+$,c,"ease-in-out"),M+$},m=(M,T,S,E="ease-in-out")=>{for(const[$,A]of Object.entries(S))r($)!==A&&(p($,M,r($)),f($,T,A,E),o[$]=A)},w=(M,T,S)=>{const E=Bg([[a,l],...T.through??[T.to]]);if(E.length<2)return S;const $=g(S,ps(E[0].point,E[1].point)),A=E[E.length-1].at,I=T.speed??Xg[M]*Math.sqrt(i/1.7),C=T.for??A/I*1e3,D=Xo(M,i),j=Wt("ease-in-out"),V=Math.min(cM,C/4);d.push({time:$,value:M}),p("walking",$,0),f("walking",$+V,1,"ease-out"),f("walking",$+C-V,1),f("walking",$+C,0,"ease-in");const et=h;let G=c;for(let F=0;;F=Math.min(A,F+rM)){const H=$+qg(j,F/A)*C,{point:W,direction:_}=zg(E,F);G+=cr(G,ps([0,0],_));const B=F===0?p:f;if(B("x",H,W[0]),B("z",H,W[1]),B("rotateY",H,G),B("walk",H,et+F/D),F>=A)break}return h=et+A/D,[a,l]=E[E.length-1].point,c=G,$+C},v=[],k=[];let y=0;for(const M of e){const T=M.at??y;let S=T;if(nc.includes(M.do))S=w(M.do,M,T);else if(M.do==="face")S=g(T,typeof M.toward=="number"?M.toward:ps([a,l],M.toward),M.for);else if(M.do==="spin")S=T+(M.for??1e3),p("rotateY",T,c),c+=(M.turns??1)*360,f("rotateY",S,c,"linear");else if(M.do==="dance"){const E=Sn[M.dance],$=M.bpm??E.bpm,A=M.beats??(M.for!==void 0?M.for*$/6e4:E.beats);S=T+(M.for??A*6e4/$);const I={...o},C=Math.max(1,Math.ceil(A*16)),D=Array.from({length:C+1},(V,et)=>hi(M.dance,A*et/C,I).pose),j=Math.min(150,(S-T)/4);for(const V of Object.keys(D[0])){const et=r(V,I);V==="turn"||V==="roll"||D.every(G=>G[V]===et)||(p(V,T,et),D.slice(1).forEach((G,F)=>{const H=T+(S-T)*(F+1)/C,W=Math.min(1,(H-T)/j),_=W*W*(3-2*W);f(V,H,et+(G[V]-et)*_)}),o[V]=D[C][V])}}else if(M.do==="hold")S=T+(M.for??1e3);else if(M.do==="place")p("x",T,a),p("z",T,l),[a,l]=M.to,f("x",T+1,a),f("z",T+1,l),typeof M.toward=="number"&&(p("rotateY",T,c),c=M.toward,f("rotateY",T+1,c)),S=T+1;else if(M.do==="pose"){S=T+(M.for??500);const E=typeof M.pose=="string"?ye[M.pose]:M.pose;m(T,S,E)}else if(M.do==="gag"){const E=Lf(M.gag,{at:T,from:{...o}});let $=E[0];for(const A of E.slice(1))m($.time,A.time,Object.fromEntries(Object.entries(A.pose).filter(([I,C])=>o[I]!==C)),A.easing??"ease-in-out"),$=A;S=$.time}else if(M.do==="say"){S=T+(M.for??jg(M.say)),k.push({text:M.say,start:T,end:S});const E={tilt:o["head.tilt"]??0,left:o["brow.left"]??0,right:o["brow.right"]??0};let $=0;for(let A=T+ki;A<S-ki/2;A+=ki,$++){const I=$%2===0;m(A-ki/2,A,{"head.tilt":E.tilt+(I?3:-2),"brow.left":E.left+(I?.25:0),"brow.right":E.right+(I?.25:0)})}$>0&&m(S-ki/2,S,{"head.tilt":E.tilt,"brow.left":E.left,"brow.right":E.right})}else if(M.do==="look"){const E=M.look??M.toward,$=i*.9,A=E==="camera"?n.camera??[0,1.6,8]:E.length===3?E:[E[0],$,E[1]];S=T+(M.for??500),m(T,S,ec({x:a,z:l,heading:c,eyeHeight:$},A),"ease-out")}v.push({do:M.do,start:T,end:S}),y=S}const x=`${n.scene}/${t}`;let P=[...u].map(([M,T])=>({id:`${t}-${M}`,target:x,property:M,keyframes:Dg(T)}));return d.length>0&&P.push({id:`${t}-gait`,target:x,property:"gait",keyframes:d}),k.length>0&&(P=lr(x,P,k,{rest:{mouth:n.pose?.mouth??lt.mouth??0,mouthWidth:n.pose?.mouthWidth??lt.mouthWidth??1}})),{tracks:P,duration:y,beats:v,end:{position:[a,l],heading:c,pose:{...o}}}}function oc(t,e,n=[0,0,0]){const s=t.filter(o=>o.target===e),i=new Ht({id:`${e}-position`,tracks:s});return o=>{const r=i.getStateAtTime(o).values.get(e),a=r?.get("position");if(Array.isArray(a)&&a.length===3)return[a[0],a[1],a[2]];const l=(c,h)=>{const u=r?.get(c);return typeof u=="number"?u:h};return[l("x",n[0]),l("y",n[1]),l("z",n[2])]}}function uM(t,e){const n=`${e.scene}/${e.character}`,s=e.height??1.7,i=Math.max(1,e.every??66),o=e.objects?.[e.character]??[0,0,0],r=new Ht({id:`${n}-own`,tracks:t.filter(u=>u.target===n)}),a=e.at,l=typeof a=="function"?a:Array.isArray(a)?()=>a:"camera"in a?oc(t,`${e.scene}/${a.camera}`,e.objects?.[a.camera]??[0,1.6,8]):(()=>{const u=oc(t,`${e.scene}/${a.object}`,e.objects?.[a.object]??[0,0,0]),d=a.eyeHeight??s*.9;return f=>{const p=u(f);return[p[0],p[1]+d,p[2]]}})(),c=["head.turn","head.nod","lookX","lookY"],h={"head.turn":[],"head.nod":[],lookX:[],lookY:[]};for(let u=e.start;;u=Math.min(e.end,u+i)){const d=r.getStateAtTime(u).values.get(n),f=(g,m)=>{const w=d?.get(g);return typeof w=="number"?w:m},p=ec({x:f("x",o[0]),z:f("z",o[2]),heading:f("rotateY",0),eyeHeight:f("y",o[1])+s*.9},l(u));for(const g of c)h[g].push({time:u,value:p[g]??0});if(u>=e.end)break}return c.map(u=>({id:`${n}-lookAt-${u}`,target:n,property:u,keyframes:h[u]}))}function dM(t){const e=Math.max(1,Math.round(t.count)),[n,s]=t.centre??[0,0],i=t.spacing??1.2,o=t.shape??"line",r=[];if(o==="circle"){const h=e<2?0:Math.max(i,i*e/(Math.PI*2));for(let u=0;u<e;u++){const d=u/e*Math.PI*2,f=n+Math.sin(d)*h,p=s+Math.cos(d)*h;r.push({position:[f,p],heading:(Math.atan2(n-f,s-p)*180/Math.PI+360)%360})}return r}if(o==="cluster"){let h=(t.seed??1)>>>0||7;const u=()=>(h^=h<<13,h>>>=0,h^=h>>17,h^=h<<5,h>>>=0,h/4294967296),d=[];for(let f=0;f<e;f++){let p=[n,s],g=-1/0;for(let m=0;m<24;m++){const w=Math.sqrt(u())*i*Math.max(1,Math.sqrt(e)*.9),v=u()*Math.PI*2,k=[n+Math.cos(v)*w,s+Math.sin(v)*w],y=d.length===0?1/0:Math.min(...d.map(x=>Math.hypot(x[0]-k[0],x[1]-k[1])));if(y>g&&(g=y,p=k),y>=i)break}d.push(p),r.push({position:p,heading:0})}return r}const a=(t.heading??90)*Math.PI/180,l=i*(e-1),c=(t.bend??60)*Math.PI/180;for(let h=0;h<e;h++){const u=e===1?0:h/(e-1)-.5,d=u*l;let f=n+Math.sin(a)*d,p=s+Math.cos(a)*d,g=((t.heading??90)-90+360)%360;if(o==="arc"){const m=(1-Math.cos(u*c))*l*.5;f-=Math.cos(a)*m,p+=Math.sin(a)*m,g=(g-u*(t.bend??60)+360)%360}r.push({position:[f,p],heading:g})}return r}const Ug={x:0,y:0,scale:1,rotate:0,shakeX:0,shakeY:0,shakeRotate:0};function fM(t){const e=n=>{const s=t?.get(n);return typeof s=="number"?s:Ug[n]};return{x:e("x"),y:e("y"),scale:e("scale"),rotate:e("rotate"),shakeX:e("shakeX"),shakeY:e("shakeY"),shakeRotate:e("shakeRotate")}}function gM(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 pM(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 Vg(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)Qg(t,c,s);t.restore()}function rc(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 Jg=150,mM={pencil:44,eraser:30};function ac(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=Jg*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,p=M=>{const T=M.fingers.thumb,S=M.fingers.index,E=M.fingers.middle,$=Zg([T.points[3],S.points[3],E.points[3]]),A=Zg([T.points[1],S.points[0]]),I=(T.depths[3]+S.depths[3]+E.depths[3])/3;return{pinch:$,direction:Math.atan2(A.y-$.y,A.x-$.x),depth:I}},g=bo(f,{size:u}),m=c-p(g).direction,w=bo(f,{size:u,angle:m*180/Math.PI}),v=p(w),k=mM[i]*a,y={x:v.pinch.x-Math.cos(c)*k,y:v.pinch.y-Math.sin(c)*k},x={x:d.x-y.x,y:d.y-y.y},P=w.axes.up;yM(t,x,{x:-P.x,y:-P.y},u,n.arm??300*a,o,n.sleeve??"#5b7db1",r),wo(t,x,f,{size:u,angle:m*180/Math.PI,skin:o,ink:r,lineWidth:3*a,prop:{depth:v.depth,draw:()=>{t.save(),t.translate(d.x,d.y),t.scale(a,a),i==="eraser"?rc(t,{x:0,y:0},{angle:c*180/Math.PI,outline:r},s):Vg(t,{x:0,y:0},{angle:c*180/Math.PI,length:190,outline:r},s),t.restore()}}})}const Zg=t=>({x:t.reduce((e,n)=>e+n.x,0)/t.length,y:t.reduce((e,n)=>e+n.y,0)/t.length});function yM(t,e,n,s,i,o,r,a){const l={x:-n.y,y:n.x},c=s*.15,h=(g,m,w)=>({x:e.x+n.x*g+l.x*m*w,y:e.y+n.y*g+l.y*m*w}),u=h(i,0,0),d=g=>{const m=t.createLinearGradient(e.x,e.y,u.x,u.y);return m.addColorStop(0,g),m.addColorStop(.6,g),m.addColorStop(1,vM(g)),m},f=Math.min(s*.55,i*.35);t.save(),t.lineJoin="round",t.lineCap="round",t.lineWidth=3*(s/Jg),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 p=[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(),p.forEach((g,m)=>m?t.lineTo(g.x,g.y):t.moveTo(g.x,g.y)),t.closePath(),t.fillStyle=d(r),t.fill(),t.strokeStyle=d(a),t.beginPath(),t.moveTo(p[1].x,p[1].y),t.lineTo(p[0].x,p[0].y),t.lineTo(p[3].x,p[3].y),t.lineTo(p[2].x,p[2].y),t.stroke(),t.restore()}function bM(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(g=>g.path.length>0).sort((g,m)=>g.start-m.start),l=g=>g.tool??"pencil",c=g=>{const m=Math.min(1,Math.max(0,g));return m*m*(3-2*m)},h=(g,m,w)=>({x:g.x+(m.x-g.x)*w,y:g.y+(m.y-g.y)*w}),u=a.find(g=>e>=g.start&&e<=g.end);if(u){const g=u.end-u.start,m=g>0?(e-u.start)/g:1;return{at:uo(u.path,m),tool:l(u),lift:0,drawing:!0}}const d=[...a].reverse().find(g=>g.end<e),f=a.find(g=>g.start>e),p=g=>g.path[g.path.length-1];if(d&&f&&f.start-d.end<=r){const g=(e-d.end)/(f.start-d.end),m=g<.5?l(d):l(f);return{at:h(p(d),f.path[0],c(g)),tool:m,lift:Math.sin(Math.PI*g),drawing:!1}}if(f&&f.start-e<=i){const g=1-(f.start-e)/i;return{at:h(s,f.path[0],c(g)),tool:l(f),lift:1-c(g),drawing:!1}}if(d&&e-d.end<=o){const g=(e-d.end)/o;return{at:h(p(d),s,c(g)),tool:l(d),lift:c(g),drawing:!1}}return null}function wM(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 kM(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?fo(a,t.sketch,c):void 0;h>0&&(u?t.smooth?u.curve(e,h):u.line(e,h):Qg(a,Vn(e,h))),r&&h>0&&h<1&&ac(a,uo(e,h),r,u)}}}function vM(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 Qg(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 hr=1e5;function MM(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 lc(t,e,n,s){if(s<=0||e.length===0)return;const i=Vn(e,s),o=n/2,r=a=>{t.beginPath(),t.rect(-hr,-hr,2*hr,2*hr),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 SM(t,e,n,s,i){t.save(),lc(t,e,n,s),i(),t.restore()}function xM(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(),lc(o,e.path,n,l),t.draw(o,r,a),o.restore(),!i||l<=0||l>=1)return;const c=uo(e.path,l);s?ac(o,c,{...s,tool:"eraser"}):rc(o,c,i)}}}function ms(){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)=>ur(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:TM(i)}))}}}function ur(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 ys(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 TM(t){return[...t].sort((n,s)=>n.time-s.time).map(n=>({time:n.time,value:n.value,...n.easing?{easing:n.easing}:{}}))}const EM=.0016,AM=.6,Qe=33;function vi(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-Qe),c=n(o,r);return{x:(c.x-l.x)/Qe,y:(c.y-l.y)/Qe}},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??EM,h=r.duration??900,u=(r.spin??AM)*(l.x<0?-1:1),d=t.valueAt(e(o,"rotate"),r.at);i(o,r.at);for(let f=0;f<=h;f+=Qe){const p=a.x+l.x*f,g=a.y+l.y*f+.5*c*f*f;t.push(e(o,"x"),{time:r.at+f,value:p-o.home.x}),t.push(e(o,"y"),{time:r.at+f,value:g-o.home.y}),t.push(e(o,"rotate"),{time:r.at+f,value:d+u*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 dr(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(x=>Math.abs(x.top-y)<.5)},c=(o?.keyframes??[]).map(k=>k.time),h=k=>{const y=S=>S<0?0:i[S].offset(k),x=l(k);if(x>=0)return y(x);if(Math.abs(a(k))<.5)return 0;const P=S=>l(S)>=0||Math.abs(a(S))<.5,M=[...c].reverse().find(S=>S<=k&&P(S)),T=c.find(S=>S>=k&&P(S));return M===void 0&&T===void 0?0:M===void 0?y(l(T)):T===void 0||T===M?y(l(M)):y(l(M))+(y(l(T))-y(l(M)))*(k-M)/(T-M)},u=i.flatMap(k=>k.windows),d=(k,y)=>u.some(x=>x.start<y&&x.end>k)||h(k)!==h(y),f=o?[...o.keyframes]:[{time:0,value:0}],p=[{...f[0],value:f[0].value+h(f[0].time)}],g=(k,y)=>{const x=new Set([y]);for(let P=k+s;P<y;P+=s)x.add(P);for(const P of u)for(const M of[P.start,P.end])M>k&&M<y&&x.add(M);for(const P of[...x].sort((M,T)=>M-T))p.push({time:P,value:a(P)+h(P)})};for(let k=1;k<f.length;k++){const y=f[k-1].time,x=f[k].time;d(y,x)?g(y,x):p.push({...f[k],value:f[k].value+h(x)})}const m=f[f.length-1].time,w=Math.max(m,...u.map(k=>k.end));w>m&&g(m,w);const v={id:o?.id??`${e}-y`,target:e,property:"y",keyframes:p};return o?t.map(k=>k===o?v:k):[...t,v]}function In(t){const e=t.indexOf(":");return e<0?{kind:t,rest:""}:{kind:t.slice(0,e),rest:t.slice(e+1)}}function tn(t,e,n,s){const i=Object.keys(n.anchors).map(r=>In(r).kind),{kind:o}=In(e);return i.includes(o)?new Error(`${t}: no anchor "${e}"${s?`: ${s}`:""} (anchors: ${Object.keys(n.anchors).join(", ")})`):new Error(`${t}: ${ft("anchor",o,i)} (anchors: ${Object.keys(n.anchors).join(", ")})`)}function Mi(t,e,n){return new Error(`${t}.edit: ${ft("edit",e,Object.keys(n.edits))}`)}function Mt(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 tp={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"},fr=["wipe","fly","blur"],Si={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"}},$M=.9,PM=8;function IM(t){const e={...tp,...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(F=>F.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(!pr.includes(f))throw new Error(`codePanel: ${ft("language",f,pr)}`);const p=n.map(F=>np(F,f).flatMap(H=>Array.from(H.text,()=>e[H.kind]))),g=ms(),m=vi(g),w=[],v=new Map,k=[],y=[],x=F=>{if(!Number.isInteger(F)||F<1||F>n.length)throw new Error(`codePanel: no line ${F} (it has ${n.length})`)},P=g.tween,M=g.last,T=(F,H,W,_,B,Q=300)=>{x(F),P(`line.${F}.${H}`,W,_,B,Q)},S=(F,H)=>w.filter(W=>W.line<F&&W.closed<=H).length,E=Mt,$=F=>t.y+r+(F-1)*i,A=F=>Array.isArray(F)?F:[F],I=(F,H,W)=>{let _=-1;for(let B=0;B<W;B++)if(_=n[F-1].indexOf(H,_+1),_<0)throw new Error(`codePanel: line ${F} has no ${W>1?`${W}th `:""}"${H}"`);return _},C={};n.forEach((F,H)=>{const W=H+1;C[`line.${W}.highlight`]=0,C[`line.${W}.strike`]=0,C[`line.${W}.wipe`]=0,C[`line.${W}.reveal`]=d.has(W)?0:1,C[`line.${W}.shift`]=0});const D={type:"custom",x:t.x,y:t.y,width:c,height:h,props:C,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 _M(Object.keys(C))},actions:cc},draw(F,H){const W=H.props??{},_=R=>Number(W[R]??C[R]),B=r+a,Q=R=>r+(R-1)*i-_(`line.${R}.shift`)*i;F.fillStyle=e.background,ep(F,0,0,c,h,8),F.fill(),F.font=`${s}px ${e.font}`,F.textBaseline="middle",F.textAlign="left";const O=(R,z,K,N,q)=>{const Y=n[R-1];for(let J=z;J<K;J++)Y[J]!==" "&&(F.fillStyle=p[R-1][J],F.fillText(Y[J],N+(J-z)*o,q))};F.save(),ep(F,0,0,c,h,8),F.clip(),n.forEach((R,z)=>{const K=z+1,N=_(`line.${K}.wipe`);if(N>=1)return;const q=Q(K),Y=q+i/2,J=Math.max(1,R.length)*o,X=Math.round(_(`line.${K}.reveal`)*R.length),tt=v.get(K)??{style:"wipe",from:"left"};F.save(),N>0&&OM(F,tt,N,{left:B-a,top:q,width:a+J+o,height:i},c);const nt=_(`line.${K}.highlight`);nt>0&&(F.globalAlpha*=Math.min(1,nt),F.fillStyle=e.highlight,F.fillRect(B-o/2,q,J+o,i),F.globalAlpha/=Math.min(1,nt)),a>0&&X>0&&(F.fillStyle=e.gutter,F.textAlign="right",F.fillText(String(K),B-o,Y),F.textAlign="left");const L=[...k.filter(it=>it.line===K).map(it=>({column:it.column,length:it.text.length,piece:it,insert:void 0})),...y.filter(it=>it.line===K).map(it=>({column:it.column,length:0,piece:void 0,insert:it}))].sort((it,ct)=>it.column-ct.column||it.length-ct.length);let U=0,ot=B;for(const it of L){O(K,U,Math.min(it.column,X),ot,Y),ot+=(it.column-U)*o;let ct=it.length,st="";if(it.piece){const Z=it.piece.written??"",rt=_(`piece.${it.piece.id}.write`);Z&&rt>0?(st=Z.slice(0,Math.round(rt*Z.length)),ct=it.length+(Z.length-it.length)*Math.min(1,rt*2)):ct=it.length*(1-_(`piece.${it.piece.id}.away`))}else it.insert&&(ct=it.insert.chars*_(`insert.${it.insert.id}.open`),it.insert.text&&(st=it.insert.text.slice(0,Math.round(_(`insert.${it.insert.id}.type`)*it.insert.text.length))));F.fillStyle=e.text;for(let Z=0;Z<st.length;Z++)st[Z]!==" "&&F.fillText(st[Z],ot+Z*o,Y);ot+=ct*o,U=it.column+it.length}O(K,U,Math.max(U,X),ot,Y);const at=_(`line.${K}.strike`);at>0&&(F.strokeStyle=e.strike,F.lineWidth=Math.max(1.5,s/10),F.beginPath(),F.moveTo(B,Y),F.lineTo(B+J*Math.min(1,at),Y),F.stroke()),F.restore()});for(const R of k){const z=_(`piece.${R.id}.opacity`);if(z<=0||_(`line.${R.line}.wipe`)>=1)continue;const K=B+(R.column+R.text.length/2)*o+_(`piece.${R.id}.x`),N=Q(R.line)+i/2+_(`piece.${R.id}.y`);F.save(),F.globalAlpha=Math.min(1,z),F.translate(K,N),F.rotate(_(`piece.${R.id}.rotate`)*Math.PI/180),O(R.line,R.column,R.column+R.text.length,-R.text.length*o/2,0),F.restore()}F.restore()}},j=F=>{const{kind:H,rest:W}=In(F),_=B=>tn("codePanel",F,Si,B);if(H==="box"){if(W)throw _("box takes no arguments");return{kind:H}}if(H==="line"){if(!/^\d+$/.test(W))throw _("write it line:N");return{kind:H,n:Number(W)}}if(H==="token"){const B=/^(\d+)(?:#(\d+))?:(.+)$/.exec(W);if(!B)throw _("write it token:N:TEXT, or token:N#K:TEXT for the Kth");return{kind:H,n:Number(B[1]),occurrence:B[2]?Number(B[2]):1,text:B[3]}}if(H==="spot"){const B=/^(\d+):(\d+)(?::(\d+))?$/.exec(W);if(!B)throw _("write it spot:N:C, or spot:N:C:W for W characters");return{kind:H,n:Number(B[1]),column:Number(B[2]),width:B[3]?Number(B[3]):1}}throw _()},V=(F,H,W,_=!1)=>{const B=Array.isArray(H)?H:[H];if(B.length===0||_&&B.length>1)throw new Error(`codePanel.edit: ${F} takes ${_?"one":"at least one"} ${W} anchor`);return B.map(Q=>{const O=j(Q);if(O.kind!==W)throw new Error(`codePanel.edit: ${F} takes ${W} anchors (${W}:…), not "${Q}"`);return O})},et=(F,H)=>{if(typeof H.text!="string")throw new Error(`codePanel.edit: ${F} needs \`text\` (the text to write)`);return H.text},G={kind:"code",about:Si,target:D,lines:n,box:E(t.x,t.y,c,h),line(F,H=1/0){return x(F),E(u,$(F)-S(F,H)*i,Math.max(1,n[F-1].length)*o,i)},token(F,H,W=1,_=1/0){x(F);const B=I(F,H,W);return E(u+B*o,$(F)-S(F,_)*i,H.length*o,i)},highlight(F,H){for(const W of A(F)){const _=M(`line.${W}.highlight`,0);T(W,"highlight",_,H.on===!1?0:1,H,200)}return G},strike(F,H){for(const W of A(F))T(W,"strike",M(`line.${W}.strike`,0),1,H);return G},remove(F,H){const W=A(F),_=H.style??"wipe";if(!fr.includes(_))throw new Error(`codePanel.remove: ${ft("style",_,fr)}`);const B=_==="wipe"?300:450,Q=H.at+(H.duration??B),O=H.close??250;for(const R of W)T(R,"wipe",0,1,{...H,easing:H.easing??(_==="fly"?"ease-in":void 0)},B),v.set(R,{style:_,from:H.from??"left"}),w.push({line:R,closed:Q+O});for(let R=1;R<=n.length;R++){if(W.includes(R))continue;const z=W.filter(N=>N<R).length;if(z===0)continue;const K=M(`line.${R}.shift`,0);T(R,"shift",K,K+z,{at:Q,duration:O,easing:"ease-in-out"})}return G},type(F,H){return T(F,"reveal",0,1,{duration:n[F-1].length*45,...H}),G},piece(F,H,W=1){if(typeof F=="string"){const R=j(F);if(R.kind!=="token")throw new Error(`codePanel.piece: a piece is a word, token:N:TEXT, not "${F}"`);return G.piece(R.n,R.text,R.occurrence)}const _=F;if(H===void 0)throw new Error('codePanel.piece: which word? piece(n, text) or piece("token:N:TEXT")');x(_);const B=I(_,H,W),Q=k.find(R=>R.line===_&&R.column===B&&R.text===H);if(Q)return Q;if(k.some(R=>R.line===_&&B<R.column+R.text.length&&R.column<B+H.length))throw new Error(`codePanel: "${H}" on line ${_} overlaps another piece`);const O={id:k.length+1,line:_,column:B,text:H,home:G.token(_,H,W,0)};k.push(O);for(const R of["x","y","rotate","write","away"])C[`piece.${O.id}.${R}`]=0;return C[`piece.${O.id}.opacity`]=1,O},follow(F,H){return m.follow(F,H),G},fling(F,H){return m.fling(F,H),G},move(F,H){return m.move(F,H),G},write(F,H,W){return F.written=H,P(`piece.${F.id}.write`,0,1,{duration:Math.max(1,H.length)*70,...W}),G},spot(F,H,W=1,_=1/0){x(F);const B=y.filter(Q=>Q.line===F&&Q.column<=H&&Q.at<=_).reduce((Q,O)=>Q+O.chars,0);return E(u+(H+B)*o,$(F)-S(F,_)*i,W*o,i)},insert(F,H,W,_){x(F);const B={id:y.length+1,line:F,column:H,chars:W.length,text:W,at:_.at};y.push(B),C[`insert.${B.id}.open`]=0,C[`insert.${B.id}.type`]=0;const Q=_.duration??W.length*70;return P(`insert.${B.id}.open`,0,1,{at:_.at,duration:Q*.6,easing:"ease-out"}),P(`insert.${B.id}.type`,0,1,{at:_.at,duration:Q}),G},drop(F,H,W,_){x(H);const B=_.duration??250,Q=H===F.line,O=_.easing??(Q?"linear":"ease-out"),R=G.landing(F,H,W,_.at),z={id:y.length+1,line:H,column:W,chars:F.text.length,at:_.at};return y.push(z),C[`insert.${z.id}.open`]=0,P(`insert.${z.id}.open`,0,1,{at:_.at,duration:B,easing:Q?O:"ease-out"}),P(`piece.${F.id}.away`,M(`piece.${F.id}.away`,0),1,{at:_.at,duration:B,easing:Q?O:"ease-in-out"}),m.cutAfter(F,_.at),G.move(F,{at:_.at,duration:B,easing:O,to:{x:R.x,y:R.y}}),P(`piece.${F.id}.rotate`,g.valueAt(`piece.${F.id}.rotate`,_.at),0,{at:_.at,duration:B}),G},landing(F,H,W,_=1/0){const B=G.spot(H,W,F.text.length,_),Q=H===F.line&&W>F.column?F.text.length*o:0;return E(B.left-Q,B.top,B.width,B.height)},ride(F,H,W){const _=n.map((B,Q)=>{const O=g.keys(`line.${Q+1}.shift`)??[];return{top:$(Q+1),offset:R=>-ur(O,R)*i,windows:ys(O)}});return dr(F,H,{ground:W.ground,every:W.every??Qe,floors:_})},tracks:g.tracks,anchor(F,H=1/0){const W=j(F);return W.kind==="box"?G.box:W.kind==="line"?G.line(W.n,H):W.kind==="token"?G.token(W.n,W.text,W.occurrence,H):G.spot(W.n,W.column,W.width,H)},edit(F,H,W){const _=()=>V(F,H,"line").map(B=>B.n);if(F==="highlight")return G.highlight(_(),W);if(F==="strike")return G.strike(_(),W);if(F==="remove")return G.remove(_(),W);if(F==="type"){for(const B of _())G.type(B,W);return G}if(F==="insert"){const[B]=V(F,H,"spot",!0);return G.insert(B.n,B.column,et(F,W),W)}if(F==="write"||F==="drop"||F==="move"||F==="fling"){const[B]=V(F,H,"token",!0),Q=G.piece(B.n,B.text,B.occurrence);if(F==="write")return G.write(Q,et(F,W),W);if(F==="fling")return G.fling(Q,W);if(F==="drop"){const R=typeof W.into=="string"?j(W.into):void 0;if(R?.kind!=="spot")throw new Error("codePanel.edit: drop needs `into`, a spot anchor (spot:N:C)");return G.drop(Q,R.n,R.column,W)}const O=typeof W.to=="string"?G.anchor(W.to,W.at):W.to;if(!O||typeof O.x!="number"||typeof O.y!="number")throw new Error("codePanel.edit: move needs `to`, an anchor name or { x, y }");return G.move(Q,{...W,to:O})}throw Mi("codePanel",F,Si)}};return G}function OM(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=PM*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*$M*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 cc={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 _M(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 ep(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 gr={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:[]};gr.typescript=[...gr.javascript,"enum","interface","type","implements","private","public","readonly","keyof","as","declare","namespace"];const pr=Object.keys(gr),CM={go:"//",rust:"//",csharp:"//",javascript:"//",typescript:"//",python:"#",plain:null};function np(t,e){const n=new Set(gr[e]),s=CM[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 hc='"Patrick Hand", "Segoe Print", "Bradley Hand", "Comic Sans MS", "Chalkboard SE", cursive',xi={whiteboard:{background:"#f7f7f2",frame:"#b8bcc4",ink:"#1f2a44",colors:{ink:"#1f2a44",red:"#d03b3b",blue:"#2f6fd0",green:"#2e9a52",orange:"#e07b1a"},font:hc,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:hc,stroke:.1,opacity:.9},lines:{background:"#fffdf5",frame:"#d9d3c0",ink:"#24315c",colors:{ink:"#24315c",red:"#c73b3b",blue:"#2f6fd0",green:"#2e9a52",orange:"#e07b1a",pencil:"#6b6b6b"},font:hc,stroke:.08,opacity:1,rule:{color:"#c9d6ec",spacing:1.55,margin:"#f0a3a3"}}},uc=["circle","box","underline","arrow"],Ce={kind:"board",create:"whiteboard({ x, y, width, height, theme?: whiteboard | chalkboard | lines, fontSize?, items: [{ id, text, at: [x, y], size?, color?, hidden? } | { id, mark: circle | box | underline | arrow, around? | from?, to?, bend?, 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"}},sp=90,ip=300,HM=.3;function RM(t){const e=typeof t.theme=="string"?t.theme:"whiteboard";if(!(e in xi))throw new Error(`whiteboard: ${ft("theme",e,Object.keys(xi))}`);const n=typeof t.theme=="object"?{...xi.whiteboard,...t.theme}:xi[e],s=t.fontSize??28,i=t.charWidth??.55,o=y=>y===void 0?n.ink:n.colors[y]??y,r=y=>Mt(t.x+y.left,t.y+y.top,y.width,y.height),a=ms(),l=vi(a),c={},h=new Map,u=[],d=[],f=(y,x,P,M)=>{const T=h.get(y);if(!T||T.kind!=="text")throw tn("whiteboard",M,Ce,`there is no text "${y}" (texts: ${p().join(", ")||"none"})`);let S=-1;for(let $=0;$<P;$++)if(S=T.item.text.indexOf(x,S+1),S<0)throw tn("whiteboard",M,Ce,`text "${y}" has no ${P>1?`${P}th `:""}"${x}"`);const E=T.size*i;return{column:S,box:Mt(T.box.left+S*E,T.box.top,x.length*E,T.box.height)}},p=()=>[...h.values()].filter(y=>y.kind==="text").map(y=>y.item.id),g=y=>{const{kind:x,rest:P}=In(y),M=T=>tn("whiteboard",y,Ce,T);if(x==="box"){if(P)throw M("box takes no arguments");return{kind:x}}if(x==="text"||x==="mark"){if(!P)throw M(`write it ${x}:ID`);return{kind:x,id:P}}if(x==="term"){const T=/^([^:#]+)(?:#(\d+))?:(.+)$/.exec(P);if(!T)throw M("write it term:ID:TEXT, or term:ID#K:TEXT for the Kth");return{kind:x,id:T[1],occurrence:T[2]?Number(T[2]):1,text:T[3]}}throw M()},m=y=>{const x=g(y);if(x.kind==="box")return Mt(0,0,t.width,t.height);if(x.kind==="term")return f(x.id,x.text,x.occurrence,y).box;const P=h.get(x.id);if(!P||P.kind!==x.kind){const M=[...h.values()].filter(T=>T.kind===x.kind).map(T=>T.item.id);throw tn("whiteboard",y,Ce,`there is no ${x.kind} "${x.id}" (${x.kind}s: ${M.join(", ")||"none"})`)}return P.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($=>typeof $=="number"))throw new Error(`whiteboard: text "${y.id}" needs \`at\`, [x, y] from the board's top-left`);const S=y.size??s,E=Mt(y.at[0],y.at[1],Math.max(1,y.text.length)*S*i,S*1.3);h.set(y.id,{kind:"text",item:y,size:S,color:o(y.color),box:E}),c[`text.${y.id}.write`]=y.hidden?0:1,c[`text.${y.id}.erase`]=0;continue}if(!uc.includes(y.mark))throw new Error(`whiteboard: mark "${y.id}": ${ft("mark",y.mark,uc)}`);const x=y.mark==="arrow"?["from","to"]:["around"];for(const S of x)if(typeof y[S]!="string")throw new Error(`whiteboard: ${y.mark} "${y.id}" needs \`${S}\`, a place on the board (an item before it)`);const P=new Set([y.from,y.to].filter(S=>typeof S=="string").map(S=>S.split(":")[1])),M=y.mark==="arrow"?[...h.values()].filter(S=>S.kind==="text"&&!P.has(S.item.id)).map(S=>S.box):[],T=LM(y,m,s,M);h.set(y.id,{kind:"mark",item:y,color:o(y.color),points:T,box:WM(T)}),c[`mark.${y.id}.draw`]=y.hidden?0:1,c[`mark.${y.id}.erase`]=0}const w=y=>u.filter(x=>x.item===y),v={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 DM(Object.keys(c))},actions:Ce.edits},draw(y,x){const P=x.props??{},M=T=>Number(P[T]??c[T]??0);if(y.save(),y.fillStyle=n.background,ap(y,0,0,t.width,t.height,10),y.fill(),y.lineWidth=Math.max(4,t.width*.012),y.strokeStyle=n.frame,y.stroke(),n.rule){y.save(),y.beginPath(),ap(y,0,0,t.width,t.height,10),y.clip(),y.lineWidth=1,y.strokeStyle=n.rule.color;const T=s*(n.rule.spacing??1.55);for(let S=T;S<t.height;S+=T)y.beginPath(),y.moveTo(0,S),y.lineTo(t.width,S),y.stroke();n.rule.margin&&(y.strokeStyle=n.rule.margin,y.beginPath(),y.moveTo(s*2.2,0),y.lineTo(s*2.2,t.height),y.stroke()),y.restore()}y.textAlign="center",y.textBaseline="middle",y.lineCap="round",y.lineJoin="round",y.globalAlpha=n.opacity;for(const T of h.values()){if(y.save(),dc(y,T.box,M(`${T.kind}.${T.item.id}.erase`)),T.kind==="text"){const S=w(T.item.id),E=M(`text.${T.item.id}.write`)*T.item.text.length;y.font=`${T.size}px ${n.font}`,y.fillStyle=T.color;for(let $=0;$<Math.ceil(E);$++)T.item.text[$]===" "||S.some(A=>$>=A.column&&$<A.column+A.text.length)||(y.globalAlpha=n.opacity*Math.min(1,E-$),y.fillText(T.item.text[$],T.box.left+($+.5)*T.size*i,T.box.y))}else rp(y,T.points,M(`mark.${T.item.id}.draw`),T.color,s*n.stroke,T.item.mark==="arrow");y.restore()}for(const T of d){const S=M(`strike.${T.id}.draw`);if(S<=0)continue;const{box:E}=T,$=E.height*.15;rp(y,[{x:E.left-3,y:E.y+$},{x:E.right+3,y:E.y-$}],S,n.colors.red??n.ink,s*n.stroke*.8,!1)}for(const T of u){const S=h.get(T.item),E=S.size*i;y.font=`${S.size}px ${n.font}`,y.fillStyle=S.color;const $=T.written;if($){const D=M(`piece.${T.id}.write`)*$.length,j=T.home.x-t.x-$.length*E/2;for(let V=0;V<Math.ceil(D);V++)$[V]!==" "&&(y.globalAlpha=n.opacity*Math.min(1,D-V),y.fillText($[V],j+(V+.5)*E,T.home.y-t.y))}const A=M(`piece.${T.id}.opacity`)*Math.min(1,M(`text.${T.item}.write`)*S.item.text.length-T.column);if(A<=0)continue;y.save();const I={x:T.home.x-t.x,y:T.home.y-t.y},C={x:M(`piece.${T.id}.x`),y:M(`piece.${T.id}.y`)};dc(y,Mt(I.x+C.x-T.home.width/2,I.y+C.y-T.home.height/2,T.home.width,T.home.height),M(`piece.${T.id}.erase`)),Math.hypot(C.x,C.y)<1&&dc(y,S.box,M(`text.${T.item}.erase`)),y.globalAlpha=n.opacity*Math.min(1,A),y.translate(I.x+C.x,I.y+C.y),y.rotate(M(`piece.${T.id}.rotate`)*Math.PI/180);for(let D=0;D<T.text.length;D++)T.text[D]!==" "&&y.fillText(T.text[D],(D+.5-T.text.length/2)*E,0);y.restore()}y.restore()}},k={kind:"board",about:Ce,target:v,box:Mt(t.x,t.y,t.width,t.height),anchor(y){return r(m(y))},piece(y){const x=g(y);if(x.kind!=="term")throw new Error(`whiteboard.piece: a piece is a term, term:ID:TEXT, not "${y}"`);const{column:P,box:M}=f(x.id,x.text,x.occurrence,y),T=u.find(E=>E.item===x.id&&E.column===P&&E.text===x.text);if(T)return T;if(u.some(E=>E.item===x.id&&P<E.column+E.text.length&&E.column<P+x.text.length))throw new Error(`whiteboard: "${x.text}" in "${x.id}" overlaps another piece`);const S={id:u.length+1,item:x.id,column:P,text:x.text,home:r(M)};u.push(S);for(const E of["x","y","rotate","erase","write"])c[`piece.${S.id}.${E}`]=0;return c[`piece.${S.id}.opacity`]=1,S},edit(y,x,P){const M=Array.isArray(x)?x:[x];if(M.length===0)throw new Error(`whiteboard.edit: ${y} takes at least one anchor`);const T=M.map($=>({name:$,anchor:g($)}));for(const{name:$}of T)m($);const S=($,A=!1)=>{const I=T.find(C=>!$.includes(C.anchor.kind));if(I)throw new Error(`whiteboard.edit: ${y} takes ${$.join(" or ")} anchors, not "${I.name}"`);if(A&&T.length>1)throw new Error(`whiteboard.edit: ${y} takes one ${$.join(" or ")} anchor`)},E=()=>k.piece(T[0].name);if(y==="write"){if(T.some($=>$.anchor.kind==="term")){if(S(["term"],!0),typeof P.text!="string")throw new Error("whiteboard.edit: write into a term needs `text` (the new text)");const $=E();return $.written=P.text,a.tween(`piece.${$.id}.write`,0,1,{duration:Math.max(ip,P.text.length*sp),...P}),k}S(["text"]);for(const{anchor:$}of T){const A=$.id,I=h.get(A).item.text;a.tween(`text.${A}.write`,0,1,{duration:Math.max(ip,I.length*sp),...P})}return k}if(y==="draw"){S(["mark"]);for(const{anchor:$}of T)a.tween(`mark.${$.id}.draw`,0,1,{duration:500,...P});return k}if(y==="erase"){S(["text","term","mark"]);for(const $ of T){const A=$.anchor.kind==="term"?`piece.${k.piece($.name).id}.erase`:`${$.anchor.kind}.${$.anchor.id}.erase`;a.tween(A,0,1,{duration:400,...P})}return k}if(y==="strike"){S(["text","term"]);for(const $ of T){const A={id:d.length+1,box:m($.name)};d.push(A),c[`strike.${A.id}.draw`]=0,a.tween(`strike.${A.id}.draw`,0,1,{duration:250,...P})}return k}if(y==="move"){S(["term"],!0);const $=typeof P.to=="string"?k.anchor(P.to):P.to;if(!$||typeof $.x!="number"||typeof $.y!="number")throw new Error("whiteboard.edit: move needs `to`, an anchor name or { x, y }");return k.move(E(),{...P,to:$})}if(y==="fling")return S(["term"],!0),k.fling(E(),P);throw Mi("whiteboard",y,Ce)},follow(y,x){return l.follow(y,x),k},fling(y,x){return l.fling(y,x),k},move(y,x){return l.move(y,x),k},ride(y){return y},tracks:a.tracks};return k}function LM(t,e,n,s=[]){const i=je(ne(t.id)),o=g=>(i.next()*2-1)*g,r=n*HM;if(t.mark==="arrow"){const g=e(t.from),m=e(t.to),w=op(g,m,r*.6),v=op(m,g,r*.6),k=Math.hypot(v.x-w.x,v.y-w.y),y=NM(w,v);let x=k*(.06+o(.04));if(t.bend!==void 0)x=k*t.bend;else{const T=FM(w,v,y,s,r);T!==0&&(x=T)}const P={x:(w.x+v.x)/2+y.x*x,y:(w.y+v.y)/2+y.y*x},M=[];for(let T=0;T<=24;T++){const S=T/24;M.push({x:(1-S)**2*w.x+2*(1-S)*S*P.x+S*S*v.x,y:(1-S)**2*w.y+2*(1-S)*S*P.y+S*S*v.y})}return M}const a=e(t.around);if(t.mark==="underline"){const g=a.bottom+r*.4;return[{x:a.left-r*.3,y:g+o(2)},{x:a.x,y:g+2+o(2)},{x:a.right+r*.5,y:g-1+o(3)}]}if(t.mark==="box"){const g=a.left-r,m=a.right+r,w=a.top-r*.6,v=a.bottom+r*.6,k=(x,P)=>({x:x+o(r*.2),y:P+o(r*.2)}),y=k(g,w);return[y,k(m,w),k(m,v),k(g,v),y,{x:y.x+r*.8,y:y.y+o(2)}]}const l=a.width/2+r,c=a.height/2+r*.6,h=-2.2+o(.3),u=i.next()*Math.PI*2,d=1.12,f=64,p=[];for(let g=0;g<=f*d;g++){const m=g/f,w=h+m*Math.PI*2,v=1+.035*Math.sin(m*Math.PI*4+u)+.06*m;p.push({x:a.x+Math.cos(w)*l*v,y:a.y+Math.sin(w)*c*v})}return p}function FM(t,e,n,s,i){const o=Math.hypot(e.x-t.x,e.y-t.y);if(o<1e-6)return 0;const r={x:(e.x-t.x)/o,y:(e.y-t.y)/o};let a=0,l=0;for(const c of s){const u=[{x:c.left,y:c.top},{x:c.right,y:c.top},{x:c.right,y:c.bottom},{x:c.left,y:c.bottom}].map(p=>({t:(p.x-t.x)*r.x+(p.y-t.y)*r.y,n:(p.x-t.x)*n.x+(p.y-t.y)*n.y})),d=u.some(p=>p.t>0&&p.t<o),f=u.some(p=>p.n>0)&&u.some(p=>p.n<0);!d||!f||(a=Math.max(a,...u.map(p=>p.n)),l=Math.min(l,...u.map(p=>p.n)))}return a===0&&l===0?0:a<=-l?2*(a+i):2*(l-i)}function op(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 NM(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 WM(t){const e=t.map(o=>o.x),n=t.map(o=>o.y),s=Math.min(...e),i=Math.min(...n);return Mt(s,i,Math.max(...e)-s,Math.max(...n)-i)}function rp(t,e,n,s,i,o){if(n<=0||e.length<2)return;const r=[0];for(let p=1;p<e.length;p++)r.push(r[p-1]+Math.hypot(e[p].x-e[p-1].x,e[p].y-e[p-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 p=1;p<e.length;p++){if(r[p]<=l){t.lineTo(e[p].x,e[p].y);continue}const g=(l-r[p-1])/(r[p]-r[p-1]||1);t.lineTo(e[p-1].x+(e[p].x-e[p-1].x)*g,e[p-1].y+(e[p].y-e[p-1].y)*g);break}if(t.stroke(),!o||n<=.85)return;const c=(n-.85)/.15,h=e[e.length-1],u=e[e.length-3]??e[0],d=Math.atan2(h.y-u.y,h.x-u.x),f=i*4.5*c;t.beginPath();for(const p of[-1,1])t.moveTo(h.x,h.y),t.lineTo(h.x-Math.cos(d+p*.45)*f,h.y-Math.sin(d+p*.45)*f);t.stroke()}function dc(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 ap(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 DM(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 fc=["bar","line","pie","donut"],lp='system-ui, -apple-system, "Segoe UI", sans-serif',Ti={light:{background:"#ffffff",text:"#3b4252",grid:"#d8dee9",color:"#4c7bd9",highlight:"#e8833a",palette:["#4c7bd9","#3fa66b","#b05cc9","#d9c04c","#4cb8c4","#d95c6f","#8a7a5a","#6b7a99"],font:lp},dark:{background:"#1e2230",text:"#cdd6f4",grid:"#3a4055",color:"#89b4fa",highlight:"#fab387",palette:["#89b4fa","#a6e3a1","#cba6f7","#f9e2af","#94e2d5","#f38ba8","#b4a58a","#9399b2"],font:lp}},On={kind:"chart",create:"chart({ x, y, width, height, kind: bar | line | pie | donut, data: [{ id, label?, value | values: { SERIES: value }, hidden? }], series?: [{ id, label?, color? }], max?, title?, axis?: { x?, y? }, legend?, theme?: light | dark, decimals?, prefix?, suffix?, values? })",anchors:{box:"the whole chart","bar:ID":"a bar (bar charts; bar:ID:SERIES with several series), 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; point:ID:SERIES with several series), as it stands at the time","slice:ID":"a slice of a pie or donut, as it stands at the time (its middle; pulled out, it moves): point at it, make it a piece","label:ID":"its label: under the axis, or beside the slice","value:ID":"its value label: above the bar or point (value:ID:SERIES), or on the slice","legend:SERIES":"a series in the legend (several series)"},edits:{set:"bar, point or slice anchors; { at, value, duration? }: animate to a new value; its value label counts along (a pie re-shares the circle)",show:"bar, point or slice anchors given `hidden`; { at, duration?, on? }: grow a bar in from the axis, draw the line out to a point, or open a slice (on: false takes it back)",highlight:"bar, point or slice anchors; { at, duration?, on? }: colour it out (on: false clears)",pull:"slice anchors; { at, duration?, on? }: pull the slice out from the centre (on: false puts it back)"}},BM=600,zM=500,qM=200,jM=400,YM=.14,KM=Math.PI*2;function XM(t){if(!fc.includes(t.kind))throw new Error(`chart: ${ft("kind",t.kind,fc)}`);const e=typeof t.theme=="string"?t.theme:"light";if(!(e in Ti))throw new Error(`chart: ${ft("theme",e,Object.keys(Ti))}`);const n=typeof t.theme=="object"?{...Ti.light,...t.theme}:Ti[e];if(!Array.isArray(t.data)||t.data.length===0)throw new Error("chart: `data` needs at least one { id, value }");const s=t.kind,i=s==="pie"||s==="donut",o=Array.isArray(t.series)&&t.series.length>1,r=Array.isArray(t.series)&&t.series.length>0?t.series:[{id:"value"}];if(i&&o)throw new Error(`chart: a ${s} shows one series (got ${r.length}); make a chart per series`);const a=new Set;for(const L of r){if(typeof L?.id!="string"||!L.id||/[:.]/.test(L.id))throw new Error(`chart: every series needs an \`id\` without ":" or "." (got ${JSON.stringify(L?.id)})`);if(a.has(L.id))throw new Error(`chart: two series are called "${L.id}"`);a.add(L.id)}const l=new Map(r.map((L,U)=>[L.id,U])),c=L=>r[l.get(L)].color??(l.get(L)===0?n.color:n.palette[l.get(L)%n.palette.length]),h=new Set,u=(L,U)=>{const ot=L.values?.[U.id]??(t.series?void 0:L.value)??L.value;if(typeof ot!="number"||!Number.isFinite(ot))throw new Error(o?`chart: "${L.id}" needs a value for series "${U.id}" (\`values: { ${U.id}: … }\`)`:`chart: "${L.id}" needs a \`value\`, a number`);return ot};for(const L of t.data){if(typeof L?.id!="string"||!L.id||/[:.]/.test(L.id))throw new Error(`chart: every datum needs an \`id\` without ":" or "." (got ${JSON.stringify(L?.id)})`);if(h.has(L.id))throw new Error(`chart: two data are called "${L.id}"`);for(const U of r)u(L,U);h.add(L.id)}const d=s==="bar"?"bar":s==="line"?"point":"slice",f=Math.max(...t.data.flatMap(L=>r.map(U=>u(L,U)))),p=i?t.data.reduce((L,U)=>L+u(U,r[0]),0):t.max??cp(f*1.1);if(!i&&!(p>0))throw new Error(`chart: \`max\` must be above 0 (got ${p})`);const g=Math.max(10,Math.min(16,t.height/20)),m=o&&t.legend!==!1,w=i?void 0:t.axis?.x,v=i?void 0:t.axis?.y,k=t.title?g*2.3:g*.5,y={left:g*3.6+(v?g*1.5:0),right:t.width-g,top:(t.title?g*3:g*1.6)+(m?g*1.6:0),bottom:t.height-g*2.4-(w?g*1.4:0)},x=y.bottom-y.top,P=(y.right-y.left)/t.data.length,M=o?P*.72/r.length:P*.6,T=o?M*.86:M,S=Math.max(4,g*.35),E=x/p,$=new Map(t.data.map((L,U)=>[L.id,U])),A=L=>y.left+P*($.get(L)+.5),I=(L,U)=>o?A(L)-P*.36+M*l.get(U)+(M-T)/2:A(L)-T/2,C=(L,U)=>I(L,U)+T/2,D=t.height-g*1.2,j={cx:t.width/2,cy:(y.top+D)/2,r:Math.max(10,Math.min(t.width/2,(D-y.top)/2)-g*2.6)},V=s==="donut"?j.r*.55:0,et=s==="donut"?(V+j.r)/2:j.r*.62,G=new Map;if(m){let L=y.right;for(const U of[...r].reverse()){const ot=U.label??U.id,at=g*.62*ot.length+g*1.9;G.set(U.id,Mt(L-at,k,at,g*1.4)),L-=at+g*.6}}const F=ms(),H=vi(F),W={},_=(L,U,ot)=>o?`${d}.${L}.${U}.${ot}`:`${d}.${L}.${ot}`;for(const L of t.data)for(const U of r)W[_(L.id,U.id,"value")]=u(L,U),W[_(L.id,U.id,"show")]=L.hidden?0:1,W[_(L.id,U.id,"highlight")]=0,i&&(W[_(L.id,U.id,"pull")]=0);const B=(L,U)=>F.keys(L)?.length?ur(F.keys(L),U):W[L],Q=(L,U,ot)=>B(_(L,U,"value"),ot)*(s==="bar"?B(_(L,U,"show"),ot):1)*E,O=L=>{const U=r[0].id,ot=t.data.map(st=>Math.max(0,L(_(st.id,U,"value")))*Math.max(0,Math.min(1,L(_(st.id,U,"show"))))),at=ot.reduce((st,Z)=>st+Z,0),it=new Map;let ct=-Math.PI/2;return t.data.forEach((st,Z)=>{const rt=at>0?KM*ot[Z]/at:0,ht=ct+rt/2,dt=Math.max(0,Math.min(1,L(_(st.id,U,"pull"))))*j.r*YM;it.set(st.id,{start:ct,sweep:rt,mid:ht,out:dt,centre:{x:j.cx+Math.cos(ht)*(et+dt),y:j.cy+Math.sin(ht)*(et+dt)}}),ct+=rt}),it},R=L=>O(U=>B(U,L)),z=L=>{const{kind:U,rest:ot}=In(L),at=it=>tn("chart",L,On,it);if(U==="box"){if(ot)throw at("box takes no arguments");return{kind:"box"}}if(U==="legend"){if(!G.has(ot))throw at(m?`there is no series "${ot}" (series: ${r.map(it=>it.id).join(", ")})`:"only a chart with several series has a legend");return{kind:"legend",series:ot}}if(U==="bar"||U==="point"||U==="slice"||U==="label"||U==="value"){if(!ot)throw at(`write it ${U}:ID`);const it=ot.indexOf(":"),ct=it<0?ot:ot.slice(0,it),st=it<0?r[0].id:ot.slice(it+1);if(!$.has(ct))throw at(`there is no "${ct}" (data: ${[...$.keys()].join(", ")})`);if(!a.has(st))throw at(`there is no series "${st}" (series: ${r.map(Z=>Z.id).join(", ")})`);if(U==="label"&&it>=0)throw at("a label is one per datum: label:ID");if((U==="bar"||U==="point"||U==="slice")&&U!==d)throw at(`a ${s} chart has ${d}s, not ${U}s: ${d}:${ct}`);return{kind:U,id:ct,series:st}}throw at()},K=(L,U)=>{if(L.kind==="box")return Mt(0,0,t.width,t.height);if(L.kind==="legend")return G.get(L.series);if(i){const st=R(U).get(L.id),Z=Math.max(g*1.5,j.r*.42);if(L.kind==="slice")return Mt(st.centre.x-Z/2,st.centre.y-Z/2,Z,Z);const rt=N(st);return L.kind==="label"?rt:st.sweep>=.3?Mt(st.centre.x-g*1.6,st.centre.y-g*.65,g*3.2,g*1.3):Mt(rt.left,rt.bottom,rt.width,g*1.3)}const ot=L.kind==="label"?A(L.id):C(L.id,L.series),at=y.bottom-Q(L.id,L.series,U);if(L.kind==="bar")return Mt(ot-T/2,at,T,y.bottom-at);if(L.kind==="point")return Mt(A(L.id)-S,at-S,S*2,S*2);if(L.kind==="label")return Mt(ot-P/2,y.bottom+g*.4,P,g*1.4);const it=at-(s==="line"?S:0)-g*.3,ct=o&&s==="bar"?M:P;return Mt((s==="line"?A(L.id):ot)-ct/2,it-g*1.3,ct,g*1.3)},N=L=>{const U=j.r+L.out+g*.9,ot={x:j.cx+Math.cos(L.mid)*U,y:j.cy+Math.sin(L.mid)*U},at=g*4.2,it=Math.cos(L.mid),ct=it>.2?ot.x:it<-.2?ot.x-at:ot.x-at/2;return Mt(ct,ot.y-g*.7,at,g*1.4)},q=L=>Mt(t.x+L.left,t.y+L.top,L.width,L.height),Y=L=>`${t.prefix??""}${L.toFixed(t.decimals??0)}${t.suffix??""}`,J=new Map,X={type:"custom",x:t.x,y:t.y,width:t.width,height:t.height,props:W,about:{kind:`${s} chart`,summary:`A ${s} chart of ${t.data.length} values (${t.data.map(L=>L.id).join(", ")})${o?` in ${r.length} series (${r.map(L=>L.id).join(", ")})`:""}${i?"":`, scaled to ${p}`}. Its ${d}s and labels are places in the scene (anchor()); its edits record tracks (edit(), tracks()).`,props:Object.fromEntries(Object.keys(W).map(L=>[L,VM(L)])),actions:On.edits},draw(L,U){const ot=U.props??{},at=st=>Number(ot[st]??W[st]??0);if(L.save(),L.fillStyle=n.background,hp(L,0,0,t.width,t.height,8),L.fill(),L.font=`${g}px ${n.font}`,L.textBaseline="middle",t.title&&(L.fillStyle=n.text,L.textAlign="left",L.font=`600 ${g*1.2}px ${n.font}`,L.fillText(t.title,i?g:y.left,g*1.5),L.font=`${g}px ${n.font}`),m){L.textAlign="left";for(const st of r){const Z=G.get(st.id);L.fillStyle=c(st.id),hp(L,Z.left,Z.top+g*.25,g*.9,g*.9,2),L.fill(),L.fillStyle=n.text,L.fillText(st.label??st.id,Z.left+g*1.3,Z.top+Z.height/2)}}if(i){tt(L,at),L.restore();return}L.lineWidth=1,L.textAlign="right";for(let st=0;st<=4;st++){const Z=y.bottom-x*st/4;L.strokeStyle=n.grid,L.beginPath(),L.moveTo(y.left,Z),L.lineTo(y.right,Z),L.stroke(),L.fillStyle=n.text,L.globalAlpha=.7,L.fillText(GM(p*st/4),y.left-g*.5,Z),L.globalAlpha=1}(v||w)&&(L.fillStyle=n.text,L.textAlign="center",L.globalAlpha=.85,v&&(L.save(),L.translate(g*.9,(y.top+y.bottom)/2),L.rotate(-Math.PI/2),L.fillText(v,0,0),L.restore()),w&&L.fillText(w,(y.left+y.right)/2,y.bottom+g*2.3),L.globalAlpha=1);const it=(st,Z)=>at(_(st,Z,"value"))*(s==="bar"?at(_(st,Z,"show")):1)*E,ct=(st,Z)=>gc(c(Z),n.highlight,at(_(st,Z,"highlight")));if(s==="line"){L.lineWidth=Math.max(2,g*.2),L.lineJoin="round",L.lineCap="round";for(const st of r)L.strokeStyle=c(st.id),L.beginPath(),t.data.forEach((Z,rt)=>{const ht={x:A(Z.id),y:y.bottom-it(Z.id,st.id)},dt=at(_(Z.id,st.id,"show"));if(rt===0){dt>0&&L.moveTo(ht.x,ht.y);return}const bt=t.data[rt-1];if(at(_(bt.id,st.id,"show"))<1||dt<=0)return;const wt={x:A(bt.id),y:y.bottom-it(bt.id,st.id)};L.lineTo(wt.x+(ht.x-wt.x)*dt,wt.y+(ht.y-wt.y)*dt)}),L.stroke()}L.textAlign="center";for(const st of t.data){for(const Z of r){const rt=s==="bar"?C(st.id,Z.id):A(st.id),ht=it(st.id,Z.id),dt=at(_(st.id,Z.id,"show"));if(L.fillStyle=ct(st.id,Z.id),s==="bar"?ht>.5&&(UM(L,rt-T/2,y.bottom-ht,T,ht,Math.min(6,T/4)),L.fill()):dt>0&&(L.beginPath(),L.arc(rt,y.bottom-ht,S*Math.min(1,dt*1.5)*(1+.3*at(_(st.id,Z.id,"highlight"))),0,Math.PI*2),L.fill()),t.values!==!1&&dt>0){L.globalAlpha=Math.min(1,dt*2),L.font=`600 ${o?g*.85:g}px ${n.font}`,L.fillStyle=gc(n.text,n.highlight,at(_(st.id,Z.id,"highlight")));const bt=y.bottom-ht-(s==="line"?S:0)-g*.95;L.fillText(Y(at(_(st.id,Z.id,"value"))),rt,bt),L.font=`${g}px ${n.font}`,L.globalAlpha=1}}L.fillStyle=n.text,L.fillText(st.label??st.id,A(st.id),y.bottom+g*1.1)}L.strokeStyle=n.text,L.lineWidth=1.5,L.beginPath(),L.moveTo(y.left,y.bottom),L.lineTo(y.right,y.bottom),L.stroke(),L.restore()}};function tt(L,U){const ot=r[0].id,at=O(U);t.data.forEach((it,ct)=>{const st=at.get(it.id);if(st.sweep<=1e-4)return;const Z=J.get(it.id),rt=Z?{x:U(`piece.${Z.id}.x`),y:U(`piece.${Z.id}.y`)}:{x:0,y:0},ht=Z?U(`piece.${Z.id}.rotate`)*Math.PI/180:0,dt=Z?U(`piece.${Z.id}.opacity`):1;if(dt<=0)return;L.save(),L.globalAlpha=dt;const bt={x:j.cx+Math.cos(st.mid)*st.out,y:j.cy+Math.sin(st.mid)*st.out};L.translate(st.centre.x+rt.x,st.centre.y+rt.y),L.rotate(ht),L.translate(-st.centre.x,-st.centre.y),L.beginPath(),L.arc(bt.x,bt.y,j.r,st.start,st.start+st.sweep),V>0?L.arc(bt.x,bt.y,V,st.start+st.sweep,st.start,!0):L.lineTo(bt.x,bt.y),L.closePath(),L.fillStyle=gc(n.palette[ct%n.palette.length],n.highlight,U(_(it.id,ot,"highlight"))),L.fill(),L.strokeStyle=n.background,L.lineWidth=Math.max(1.5,g*.15),L.stroke(),t.values!==!1&&st.sweep>=.3&&(L.fillStyle=n.background,L.font=`600 ${g}px ${n.font}`,L.textAlign="center",L.fillText(Y(U(_(it.id,ot,"value"))),st.centre.x,st.centre.y),L.font=`${g}px ${n.font}`),L.restore();const wt=N(st),ge=Math.cos(st.mid);L.globalAlpha=dt,L.fillStyle=n.text,L.textAlign=ge>.2?"left":ge<-.2?"right":"center";const Di=ge>.2?wt.left:ge<-.2?wt.right:wt.left+wt.width/2;L.fillText(it.label??it.id,Di,wt.top+wt.height/2),t.values!==!1&&st.sweep<.3&&(L.globalAlpha=dt*.8,L.fillText(Y(U(_(it.id,ot,"value"))),Di,wt.bottom+g*.65)),L.globalAlpha=1})}const nt={kind:"chart",chartKind:s,about:On,target:X,max:p,box:Mt(t.x,t.y,t.width,t.height),anchor(L,U=1/0){return q(K(z(L),U))},piece(L){const U=z(L);if(U.kind!=="slice")throw new Error(i?`chart: a piece is a slice, slice:ID, not "${L}"`:`chart: a ${d} is not a piece; slices of a pie or donut are (slice:ID). Change a ${d} with edit('set' | 'show' | 'highlight', …)`);const ot=J.get(U.id);if(ot)return ot;const at={id:J.size+1,datum:U.id,home:q(K(U,0))};J.set(U.id,at);for(const it of["x","y","rotate"])W[`piece.${at.id}.${it}`]=0;return W[`piece.${at.id}.opacity`]=1,at},edit(L,U,ot){const at=Array.isArray(U)?U:[U];if(at.length===0)throw new Error(`chart.edit: ${L} takes at least one anchor`);if(!(L in On.edits))throw Mi("chart",L,On);if(L==="pull"&&!i)throw new Error(`chart.edit: pull takes slice anchors of a pie or donut; a ${s} chart has ${d}s`);const it=at.map(ct=>{const st=z(ct);if(st.kind!==d)throw new Error(`chart.edit: ${L} takes ${d} anchors (${d}:ID), not "${ct}"`);return st});for(const{id:ct,series:st}of it){const Z=rt=>_(ct,st,rt);if(L==="set"){if(typeof ot.value!="number"||!Number.isFinite(ot.value))throw new Error("chart.edit: set needs `value`, a number");F.tween(Z("value"),B(Z("value"),ot.at),ot.value,ot,BM)}else L==="show"?F.tween(Z("show"),B(Z("show"),ot.at),ot.on===!1?0:1,ot,zM):L==="pull"?F.tween(Z("pull"),B(Z("pull"),ot.at),ot.on===!1?0:1,ot,jM):F.tween(Z("highlight"),B(Z("highlight"),ot.at),ot.on===!1?0:1,ot,qM)}return nt},follow(L,U){return H.follow(L,U),nt},fling(L,U){return H.fling(L,U),nt},move(L,U){return H.move(L,U),nt},ride(L,U,ot){if(s!=="bar")return L;const at=t.data.flatMap(it=>r.map(ct=>{const st=Q(it.id,ct.id,0),Z=[...ys(F.keys(_(it.id,ct.id,"value"))),...ys(F.keys(_(it.id,ct.id,"show")))];return{top:t.y+y.bottom-st,offset:rt=>st-Q(it.id,ct.id,rt),windows:Z}}));return dr(L,U,{ground:ot.ground,every:ot.every??Qe,floors:at})},tracks:F.tracks};return nt}function cp(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 GM(t){return Number.isInteger(t)?String(t):String(Number(t.toFixed(2)))}function gc(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 hp(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 UM(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 VM(t){return t.endsWith(".value")?{description:"Its value (the bar’s height, the point’s, or the slice’s share, 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, a slice opened",unit:"0..1",min:0,max:1}:t.endsWith(".pull")?{description:"How far the slice is pulled out from the centre",unit:"0..1",min:0,max:1}:t.startsWith("piece.")?{description:t.endsWith(".opacity")?"The loose slice’s opacity":t.endsWith(".rotate")?"The loose slice’s turn, degrees":"The loose slice’s offset from home, px",unit:t.endsWith(".rotate")?"degrees":t.endsWith(".opacity")?"0..1":"px"}:{description:"How much it is coloured out",unit:"0..1",min:0,max:1}}function up(){return{torso:[{at:0,width:.083},{at:.25,width:.08},{at:.5,width:.075},{at:.8,width:.085},{at:1,width:.023}],arm:[{at:0,width:.026},{at:.3,width:.024},{at:.5,width:.018},{at:.7,width:.021},{at:1,width:.012}],leg:[{at:0,width:.036},{at:.3,width:.037},{at:.5,width:.026},{at:.7,width:.029},{at:1,width:.015}]}}const Ei={youngMan:{figure:"organic",skin:"#edb98d",ink:"#53372d",headSize:.28,shoulderWidth:.074,hipWidth:.045,handSize:.078,hair:{style:"softSweep",color:"#38291f"},ears:!0,face:{style:"anime",shape:"angular",jawWidth:.83,chinWidth:.35,jawRoundness:1,eyeScale:.95,eyeAspect:1.1,nose:!0,iris:"#6a472d"},outfit:{shirt:"#bc7050",trousers:"#495a67",sleeves:"short"}},youngWoman:{figure:"organic",skin:"#f1c299",ink:"#53372d",headSize:.28,shoulderWidth:.065,hipWidth:.054,handSize:.075,body:{torso:[{at:0,width:.098},{at:.18,width:.097},{at:.44,width:.061},{at:.7,width:.087},{at:.85,width:.09},{at:1,width:.024}]},hair:{style:"flowingBob",color:"#38291f"},ears:!0,face:{style:"anime",shape:"angular",jawWidth:.78,chinWidth:.32,jawRoundness:1,eyeScale:.95,eyeAspect:1.1,nose:!0,iris:"#6a472d",lashes:!0},outfit:{shirt:"#72958b",trousers:"#6b6888",sleeves:"short",bottom:"skirt"}},childBoy:{figure:"organic",height:230,skin:"#edb98d",ink:"#53372d",headSize:.36,shoulderWidth:.052,hipWidth:.038,legLength:.82,armLength:.8,handSize:.074,body:up(),hair:{style:"softSweep",color:"#38291f"},ears:!0,face:{style:"anime",shape:"round",eyeScale:1,eyeAspect:1.1,nose:!0,iris:"#6a472d"},outfit:{shirt:"#d99843",trousers:"#497b91",sleeves:"short",bottom:"shorts"}},childGirl:{figure:"organic",height:225,skin:"#f1c299",ink:"#53372d",headSize:.36,shoulderWidth:.052,hipWidth:.038,legLength:.82,armLength:.8,handSize:.074,body:up(),hair:{style:"flowingBob",color:"#38291f"},ears:!0,face:{style:"anime",shape:"round",eyeScale:1,eyeAspect:1.1,nose:!0,iris:"#6a472d",lashes:!0},outfit:{shirt:"#ae7396",trousers:"#648769",sleeves:"short",bottom:"skirt"}}};function JM(t,e={}){if(!Object.prototype.hasOwnProperty.call(Ei,t))throw new Error(`softCartoonCharacter: unknown actor '${t}'`);const n=Ei[t];return us({...n,...e,body:{...n.body,...e.body},face:{...n.face,...e.face}})}const dp={animeBoy:{label:"Anime boy",group:"anime",scale:.68,options:{figure:"fluid",look:"clean",proportions:"thin",build:"child",headSize:.34,skin:"#f2c7a5",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"spiky",color:"#263c68"},face:{style:"anime",iris:"#318fa5",lashes:!1},outfit:{shirt:"#efac45",trousers:"#375a91",bottom:"shorts",shoes:"boots"}}},animeGirl:{label:"Anime girl",group:"anime",scale:.68,options:{figure:"fluid",look:"clean",proportions:"thin",build:"child",headSize:.34,skin:"#e8ad8c",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"bob",color:"#4f304e"},face:{style:"anime",iris:"#9d5f32"},outfit:{shirt:"#e9779f",trousers:"#5c4c86",bottom:"shorts",shoes:"boots"}}},animeYoungMan:{label:"Anime young man",group:"anime",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"tall",headSize:.23,skin:"#efbf9c",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"spiky",color:"#243552"},face:{style:"anime",iris:"#507bcc",lashes:!1},outfit:{shirt:"#57bbc0",trousers:"#334967",sleeves:"long",over:"hoodie",overColor:"#57bbc0",shoes:"boots"}}},animeYoungWoman:{label:"Anime young woman",group:"anime",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"slim",headSize:.23,skin:"#f3cbb4",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"highPonytail",color:"#773853"},face:{style:"anime",iris:"#9163c4"},outfit:{shirt:"#ae7cda",trousers:"#35456c",sleeves:"long",shoes:"boots"}}},animeMan:{label:"Anime man",group:"anime",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"broad",headSize:.23,skin:"#b67f62",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"sidePart",color:"#302839"},face:{style:"anime",iris:"#9b713b",lashes:!1},outfit:{shirt:"#677aab",trousers:"#343848",sleeves:"long",collar:!0,shoes:"boots"}}},animeWoman:{label:"Anime woman",group:"anime",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"standard",headSize:.23,skin:"#d59a73",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"shoulderWaves",color:"#382c4c"},face:{style:"anime",iris:"#2b8f82"},outfit:{shirt:"#df6c79",trousers:"#46506c",sleeves:"long",bottom:"skirt",shoes:"boots"}}},animeOlderMan:{label:"Anime older man",group:"anime",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"stocky",headSize:.25,skin:"#e0b291",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"receding",color:"#b8c4d1"},facialHair:{style:"shortBoxed",color:"#dae0e8"},face:{style:"anime",iris:"#557c8b",lashes:!1,ageLines:.8},outfit:{shirt:"#9c846c",trousers:"#46505c",sleeves:"long",collar:!0,shoes:"boots"}}},animeOlderWoman:{label:"Anime older woman",group:"anime",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"standard",headSize:.25,skin:"#c4947b",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"topBun",color:"#d1d3df"},face:{style:"anime",iris:"#7a6998",ageLines:.8},outfit:{shirt:"#6d9b93",trousers:"#66597a",sleeves:"long",over:"cardigan",overColor:"#6d9b93",shoes:"boots"}}}},fp={mangaYoungMan:{label:"Manga young man",group:"manga",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"tall",headSize:.21,lineWidth:2.8,skin:"#edbf9b",ink:"#252536",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"mangaSpikes",color:"#27354c"},face:{style:"anime",shape:"angular",jawWidth:.78,chinWidth:.16,eyeScale:.8,eyeAspect:.63,iris:"#3a9baa",lashes:!1,nose:!0},outfit:{shirt:"#c65a49",trousers:"#293c56",sleeves:"long",collar:!0,shoes:"boots"}}},mangaYoungWoman:{label:"Manga young woman",group:"manga",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"slim",headSize:.21,lineWidth:2.8,skin:"#e2a482",ink:"#252536",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"mangaSweep",color:"#683e64"},face:{style:"anime",shape:"angular",jawWidth:.69,chinWidth:.1,eyeScale:.85,eyeAspect:.72,iris:"#8462b7",nose:!0},outfit:{shirt:"#518c96",trousers:"#364361",sleeves:"long",shoes:"boots"}}},mangaRival:{label:"Manga rival",group:"manga",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"broad",headSize:.21,lineWidth:2.8,skin:"#b77e5f",ink:"#252536",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"mangaSpikes",color:"#e6e0cc",volume:.16},face:{style:"anime",shape:"angular",jawWidth:.9,chinWidth:.25,eyeScale:.75,eyeAspect:.55,iris:"#ba8445",lashes:!1,nose:!0},outfit:{shirt:"#4c4b75",trousers:"#303348",sleeves:"long",over:"hoodie",shoes:"boots"}}},mangaHeroine:{label:"Manga heroine",group:"manga",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"tall",headSize:.21,lineWidth:2.8,skin:"#f0c5aa",ink:"#252536",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"highPonytail",color:"#263647",texture:"spiky",textureAmount:.35},face:{style:"anime",shape:"angular",jawWidth:.73,chinWidth:.12,eyeScale:.83,eyeAspect:.65,iris:"#427e9b",nose:!0},outfit:{shirt:"#b65e7c",trousers:"#31405b",sleeves:"long",collar:!0,shoes:"boots"}}}},pc={boy:{label:"Boy",group:"family",scale:.66,options:{build:"child",hair:"short",ears:!0,outfit:{shirt:"#4f8fd6",trousers:"#2f4d6b",bottom:"shorts"}}},girl:{label:"Girl",group:"family",scale:.66,options:{build:"child",hair:{style:"bob",color:xe.chestnut},ears:!0,outfit:{shirt:"#e86a92",trousers:"#4a5b8c",bottom:"skirt"}}},youngMan:{label:"Young man",group:"family",scale:1,options:{build:"tall",hair:"spiky",ears:!0,outfit:{shirt:"#3c9a6e",trousers:"#2d3a4f"}}},youngWoman:{label:"Young woman",group:"family",scale:.96,options:{build:"slim",hair:{style:"highPonytail",color:xe.auburn},ears:!0,outfit:{shirt:"#f0b43c",trousers:"#36507a"}}},man:{label:"Man",group:"family",scale:1,options:{build:"broad",hair:"sidePart",facialHair:"chevron",ears:!0,outfit:{shirt:"#7a8fa6",trousers:"#3b3f46",sleeves:"long",collar:!0,tie:"#2b4f8c"}}},woman:{label:"Woman",group:"family",scale:.95,options:{build:"curvy",hair:{style:"shoulderWaves",color:xe.black},ears:!0,outfit:{shirt:"#9b5fc0",trousers:"#2f2f3a",sleeves:"long"}}},grandpa:{label:"Grandpa",group:"family",scale:.96,options:{build:"stocky",hair:{style:"receding",color:xe.gray},facialHair:{style:"shortBoxed",color:xe.white},glasses:"square",ears:!0,outfit:{shirt:"#b98a5a",trousers:"#4b4440",sleeves:"long",collar:!0}}},grandma:{label:"Grandma",group:"family",scale:.9,options:{build:"short",hair:{style:"topBun",color:xe.white},glasses:"round",ears:!0,outfit:{shirt:"#5d9fa8",trousers:"#5a4a5e",sleeves:"long",bottom:"skirt"}}},doctor:{label:"Doctor",group:"work",scale:.97,options:{build:"slim",hair:{style:"lowPonytail",color:xe.black},ears:!0,outfit:{shirt:"#8fb8d8",trousers:"#36507a",over:"labCoat",collar:!0}}},cook:{label:"Cook",group:"work",scale:1,options:{build:"stocky",hair:"crewCut",facialHair:"shortMoustache",ears:!0,outfit:{shirt:"#f4f6f8",trousers:"#3b3f46",sleeves:"long",over:"apron",overColor:"#e2493b"}}},builder:{label:"Builder",group:"work",scale:1,options:{build:"broad",hair:"short",facialHair:"stubble",hat:"hardHat",ears:!0,outfit:{shirt:"#f08a3c",trousers:"#4a5b8c"}}},courier:{label:"Courier",group:"work",scale:.98,options:{build:"standard",hair:"short",hat:{style:"cap",color:"#d64535"},ears:!0,outfit:{shirt:"#c94a3b",trousers:"#2f2f3a",bottom:"shorts"}}},teacher:{label:"Teacher",group:"work",scale:1,options:{build:"tall",hair:"slickBack",glasses:"square",ears:!0,outfit:{shirt:"#f4f6f8",trousers:"#3b3f46",sleeves:"long",collar:!0,tie:"#9a4426"}}},farmer:{label:"Farmer",group:"work",scale:.97,options:{build:"stocky",hair:{style:"shoulderStraight",color:xe.blond},hat:"sunHat",ears:!0,outfit:{shirt:"#d64535",trousers:"#4f6b3a",sleeves:"long"}}},...dp,...fp};function ZM(t,e=300,n={}){const s=pc[t];if(!s)throw new Error(`castMember: unknown cast member '${t}'`);return{...s.options,height:Math.round(e*s.scale),...n}}const Ai={handshake:{height:.47,spacing:.42,lean:6},highFive:{height:.9,spacing:.4,lean:4},fistBump:{height:.55,spacing:.44,lean:6},handOver:{height:.52,spacing:.46,lean:8}};function QM(t,e,n){return Ai[t].spacing*Math.min(e.height,n.height)}const gp=.075;function tS(t,e,n,s={}){const i=Ai[t];if(!i)throw new Error(`meetHands: unknown meeting '${t}' (one of ${Object.keys(Ai).join(", ")})`);const[o,r]=e.x<=n.x?[e,n]:[n,e],a=s.view==="side",l=Math.min(o.character.height,r.character.height),c={x:(o.x+r.x)/2,y:-(s.height??i.height)*l},h=(m,w)=>{const v=w?a?1:.62:a?3:3.38;let k={...lt,...m.pose,turn:v,lean:(m.pose?.lean??0)+i.lean};const y=w?1:-1,x=(P,M,T)=>{k=_e(m.character,k,P,{x:c.x+M-m.x,y:c.y,depth:T})};if(t==="handOver"){const P=gp*l;x("arm.left",-y*P*.9,P),x("arm.right",-y*P*.9,-P)}else x("arm.right",0,0);return t==="fistBump"&&(k={...k,"hand.right.index.curl":1,"hand.right.middle.curl":1,"hand.right.ring.curl":1,"hand.right.pinky.curl":1}),k},u=h(o,!0),d=h(r,!1),f=.03*l,p=(m,w)=>{const v=fe(m.character,w),k=t==="handOver"?["hand.left","hand.right"]:["hand.right"],y=t==="handOver"?gp*l+f:f;return k.every(x=>Math.abs(v.points[x].y-c.y)<f&&Math.abs(v.points[x].x+m.x-c.x)<y)},g=p(o,u)&&p(r,d);return e.x<=n.x?{a:u,b:d,point:c,reached:g}:{a:d,b:u,point:c,reached:g}}const mr={spacing:.3,lean:10,tilt:8};function eS(t,e){return mr.spacing*Math.min(t.height,e.height)}function nS(t,e,n={}){const[s,i]=t.x<=e.x?[t,e]:[e,t],o=n.view==="side",r=Math.min(s.character.height,i.character.height),a=(p,g,m)=>({over:{x:g.x-m*.02*r-p.x,y:-.72*r,depth:-.08*r},round:{x:g.x-m*.04*r-p.x,y:-.5*r,depth:.06*r}}),l=(p,g,m)=>{const w=m?o?1:.62:o?3:3.38,v=m?1:-1;let k={...lt,...p.pose,turn:w,lean:(p.pose?.lean??0)+mr.lean,"head.tilt":(p.pose?.["head.tilt"]??0)+v*mr.tilt};const{over:y,round:x}=a(p,g,v);return k=_e(p.character,k,"arm.right",y),k=_e(p.character,k,"arm.left",x),k},c=l(s,i,!0),h=l(i,s,!1),u=.05*r,d=(p,g,m,w)=>{const v=fe(p.character,w).points,{over:k,round:y}=a(p,g,m);return Math.hypot(v["hand.right"].x-k.x,v["hand.right"].y-k.y)<u&&Math.hypot(v["hand.left"].x-y.x,v["hand.left"].y-y.y)<u},f=d(s,i,1,c)&&d(i,s,-1,h);return t.x<=e.x?{a:c,b:h,reached:f}:{a:h,b:c,reached:f}}const _n={spacing:.32,low:.3,high:.5,helperLean:40,helperBend:16};function sS(t,e){return _n.spacing*Math.min(t.height,e.height)}function iS(t,e,n,s={}){const i=Math.max(0,Math.min(1,n)),o=s.view==="side",r=t.x<=e.x,a=Math.min(t.character.height,e.character.height),l={x:(t.x+e.x)/2,y:-(_n.low+(_n.high-_n.low)*i)*a},c=m=>m?o?1:.62:o?3:3.38;let h={...lt,...t.pose,turn:c(r),lean:(t.pose?.lean??0)+_n.helperLean*(1-i)+4,bend:(t.pose?.bend??0)+_n.helperBend*(1-i),"head.nod":18*(1-i)};h=_e(t.character,h,"arm.right",{x:l.x-t.x,y:l.y});const u={...ye.sitFloor,...e.pose,turn:c(!r)},d={...lt,...e.pose,turn:c(!r)};let f=Fl(u,d,i);f=_e(e.character,f,"arm.right",{x:l.x-e.x,y:l.y});const p=.04*a,g=(m,w)=>{const v=fe(m.character,w).points["hand.right"];return Math.hypot(v.x+m.x-l.x,v.y-l.y)<p};return{helper:h,sitter:f,point:l,reached:g(t,h)&&g(e,f)}}const mc=Object.freeze({everyday:Object.freeze({shirt:"#bc7050",trousers:"#495a67",sleeves:"short",bottom:"trousers",collar:!1,tie:null}),formal:Object.freeze({top:"shirt",shirt:"#f4ede2",trousers:"#394653",sleeves:"long",bottom:"trousers",trouserStyle:"plain",collar:!0,tie:"#804453"}),casual:Object.freeze({top:"tshirt",shirt:"#648a83",trousers:"#426683",sleeves:"short",bottom:"trousers",trouserStyle:"jeans",collar:!1,tie:null})});function pp(t,e={}){if(!Object.prototype.hasOwnProperty.call(mc,t))throw new Error(`outfitPreset: unknown category '${t}'`);const n={...mc[t],...e};return e.top&&e.top!=="shirt"&&(n.collar=e.collar??!1,n.tie=e.tie??null),n.top==="dress"&&(n.bottom="skirt"),n}const oS=.7,rS=50,aS=1.2,lS=.8,cS=3,hS=30,uS=.8,dS=.6,yc=(t,e)=>Math.max(-e,Math.min(e,t)),fS=["hair.swing","hair.trail","hair.lift"];function mp(t,e){const n=e.start??0,s=e.amount??1,i=Math.max(1e-6,e.headRadius);let o=NaN,r={x:0,y:0,turn:0};const a=f=>(f!==o&&(r=t(f),o=f),r),l=f=>{const p=a(f);return p.turn*90+(p.headTurn??0)},c={start:n,end:e.end,step:e.step,stiffness:e.stiffness??70,damping:e.damping??6},h=js(l,c),u=js(f=>a(f).x,c),d=js(f=>a(f).y,c);return h.map((f,p)=>{const g=a(f.time),m=f.value-l(f.time),w=u[p].value-g.x-(e.wind??0)*oS*i,v=d[p].value-g.y,k=Math.sin(g.turn*Math.PI/2),y=Math.cos(g.turn*Math.PI/2),x=m*cS+w*y/i*hS,P=-w*k/i*uS,M=-v/i*dS;return{time:f.time,swing:yc(x*s,rS),trail:yc(P*s,aS),lift:yc(M*s,lS)}})}function gS(t,e){if(t.length===0)return{"hair.swing":0,"hair.trail":0,"hair.lift":0};if(e<=t[0].time)return yp(t[0]);if(e>=t[t.length-1].time)return yp(t[t.length-1]);let n=0,s=t.length-1;for(;s-n>1;){const a=n+s>>1;t[a].time<=e?n=a:s=a}const i=t[n],o=t[s],r=o.time===i.time?0:(e-i.time)/(o.time-i.time);return{"hair.swing":i.swing+(o.swing-i.swing)*r,"hair.trail":i.trail+(o.trail-i.trail)*r,"hair.lift":i.lift+(o.lift-i.lift)*r}}const yp=t=>({"hair.swing":t.swing,"hair.trail":t.trail,"hair.lift":t.lift}),bs=16,pS=1500;function mS(t,e,n,s={}){const i=n.head.hair;if(!i||!lf(i))return[];const o=e.filter(v=>v.target===t),r=o.reduce((v,k)=>k.keyframes.reduce((y,x)=>Math.max(y,x.time),v),0),a=lt,l=new Set(["x","y","turn","head.turn"]),c=new Ht({id:`${t}-hair-follow`,tracks:o.filter(v=>l.has(v.property))}),h=(v,k,y)=>{const x=c.getStateAtTime(v).values.get(t)?.get(k);return typeof x=="number"?x:y},u=new Ht({id:`${t}-hair-pose`,tracks:o}),d=v=>u.getStateAtTime(v).values.get(t),f=new Map,p=v=>{const k=Math.round(v/bs);let y=f.get(k);if(!y){const x={};for(const[M,T]of d(k*bs)??[])x[M]=T;const P=fe(n,Zo(x,a,s.gaits)).head.center;f.set(k,y={x:P.x,y:P.y})}return y},g=v=>{const k=Math.floor(v/bs),y=v/bs-k,x=p(k*bs),P=p((k+1)*bs);return{x:x.x+(P.x-x.x)*y,y:x.y+(P.y-x.y)*y}},m=mp(v=>{const k=g(v);return{x:h(v,"x",0)+k.x,y:h(v,"y",0)+k.y,turn:h(v,"turn",a.turn??0),headTurn:h(v,"head.turn",a["head.turn"]??0)}},{start:0,end:r+(s.settle??pS),headRadius:fe(n,lt).head.rx,step:s.step,stiffness:s.stiffness,damping:s.damping,amount:s.amount,wind:s.wind}),w=[];for(const v of fS){const k=v.slice(5);let y=m.map(P=>({time:P.time,value:P[k]}));if(y.every(P=>Math.abs(P.value)<.001))continue;const x=o.find(P=>P.property===v);if(x){const P=new Ht({id:`${t}-${v}-own`,tracks:[x]}),M=T=>Number(P.getStateAtTime(T).values.get(t)?.get(v)??0);y=y.map(T=>({time:T.time,value:T.value+M(T.time)}))}w.push({id:`${t}-${v}`,target:t,property:v,keyframes:y})}return w}const Cn={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 bc(t){if(t===void 0)return Cn.full;if(typeof t=="string")return Cn[t];const{base:e,...n}=t;return{...Cn[e??"full"],...n}}const wc=160,yS=120,bS=700,kc=60,wS=90,yr=3200,ws=1,Hn=1e-6;function br(t,e,n={}){const s=bc(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])>Hn));for(const u of r)o[u]=kS(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=vS(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=MS(t,c,t[0].pose[h],s.jumpSquash);u.length>0&&(o[h]=u)}return o}function kS(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 p=(e[f].time-e[f-1].time)/2;return Math.max(-p,Math.min(p,l))},h=[{time:e[0].time,value:e[0].pose[t]}],u=(f,p,g)=>{const m=h[h.length-1];if(f<=m.time+ws){h[h.length-1]={...m,value:p,...g?{easing:g}:{}};return}h.push({time:f,value:p,...g?{easing:g}:{}})};let d=e[0].pose[t];for(let f=1;f<e.length;f++){const p=e[f],g=e[f-1].pose[t],m=p.pose[t],w=m-g,v=h[h.length-1].time,k=p.act!==!1;if(Math.abs(w)<=Hn){const $=p.time+(k?c(f):0);if(f===e.length-1)Math.abs(d-m)>Hn&&u(Math.max($,v+wc),m,"ease-in-out"),d=m;else if(k&&a&&s.drift>0&&n.drift.includes(t)&&$-v>=bS){const A=ne(`${i}:${t}:${f}`)%2===0?1:-1;d=m+A*s.drift*r,u($,d,"ease-in-out")}continue}if(!k){u(e[f-1].time,d),u(p.time,m,p.easing),d=m;continue}const y=c(f),x=Math.max(e[f-1].time+y,v);let P=p.time+y;o&&s.eyeDart>0&&(P=Math.min(P,x+s.eyeDart));const M=P-x;if(M<=ws){u(p.time,m,p.easing),d=m;continue}u(x,d);const T=Math.sign(w);if(a&&s.anticipation>0&&r>0&&M>=wc){const $=d-T*Math.min(Math.abs(w)*s.anticipation,r),A=x+M*s.anticipationTime;u(A,$,"ease-in-out"),s.hold>0&&u(A+M*s.hold,$)}const S=f+1<e.length?e[f+1].time-p.time:1/0,E=Math.min(s.settle,S/2);if(a&&s.overshoot>0&&r>0&&M>=yS&&E>ws){const $=Math.min(Math.abs(w)*s.overshoot,r);u(P,m+T*$,p.easing??s.actionEase),u(P+E,m,s.settleEase)}else u(P,m,p.easing??s.actionEase);d=m}return h}function vS(t,e,n,s,i){const o=[],r=kc+wS;for(let f=1;f<t.length;f++){const p=t[f-1].pose,g=t[f].pose;Object.entries(e.headTurns).some(([w,v])=>Math.abs((g[w]??0)-(p[w]??0))>v)&&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+yr*.6,u=0;for(;h<l;){c.some(g=>Math.abs(g-h)<yr/2)||o.push(h);const p=(ne(`${s}:blink:${u++}`)%1e3/1e3-.5)*(yr*.66);h+=yr+p}o.sort((f,p)=>f-p);const d=[{time:a,value:i}];for(const f of o){const p=d[d.length-1].time;f+kc<=p+ws||(f>p+ws&&d.push({time:f,value:i}),d.push({time:f+kc,value:1,easing:"ease-in"}),d.push({time:f+r,value:i,easing:"ease-out"}))}return d.length>1?d:[]}function MS(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+ws||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<wc||t[l].act===!1)){if(c<=Hn&&h>Hn)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>Hn&&h<=Hn){const p=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,p/2),n,{type:"back",mode:"out",overshoot:1.4})}}}return r.length>1?r:[]}const bp={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 SS(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 xS(){const t={},e={};for(const n of Object.keys(lt)){const s=SS(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 wp=xS();function kp(t,e){return Object.entries(e).map(([n,s])=>({id:`${t}-${n}`,target:t,property:n,keyframes:s}))}function vp(t,e,n={}){const s=So(e),i=e.map((o,r)=>({time:o.time,pose:{...s[r]},easing:o.easing,act:o.act}));return kp(t,br(i,n.rig??bp,n))}function Mp(t,e,n={}){const s=n.rest??lt,i=Nl(e,s),o=e.map((r,a)=>({time:r.time,pose:{...s,...i[a]},easing:r.easing,act:r.act}));return kp(t,br(o,n.rig??wp,n))}const Sp=vt.shocked,TS=vt.scared,en={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,...Sp,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,...vt.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,...Sp,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,...vt.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:ut.leftHip,rightHip:ut.rightHip,leftKnee:0,rightKnee:0},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...TS,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:{...ae.sad,bend:18,stretch:.92,lean:t.lean+5,turn:t.turn,sit:t.sit},easing:"ease-in-out"}]};function vc(t,e){const n=typeof e.from=="string"?ae[e.from]:e.from??ut;return Mc(en[t](n),{...e,from:n})}function Mc(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 $i(t,e=1){const n=en[t](ut);return n[n.length-1].after*e}function xp(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,p=d.y-u.y,g=Math.hypot(f,p)||1,m=-p/g,w=f/g,v=1-h/(e.length-1);t.globalAlpha=r*(1-v),t.lineWidth=o*(1-v*.7),t.beginPath(),t.moveTo(u.x+m*l,u.y+w*l),t.lineTo(d.x+m*l,d.y+w*l),t.stroke()}}t.restore()}const ES={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 AS(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 p=l+(n.time-l)*f/(a-1);c.push(Za(e,{time:p,state:o(p)},s).joints)}const h=c[c.length-1].height,u=(i.threshold??1.2)*h,d=(i.parts??["hands","toes","head"]).flatMap(f=>ES[f]);for(const f of d){const p=c.map(f.at);let g=0;for(let v=1;v<p.length;v++)g+=Math.hypot(p[v].x-p[v-1].x,p[v].y-p[v-1].y);const m=g/((n.time-l)/1e3);if(m<=u)continue;const w=Math.min(1,(m-u)/(u*.5));xp(t,p,{...i,opacity:(i.opacity??.7)*w,spacing:i.spacing??h*.02})}}function Tp(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=ne(`${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 $S(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;PS(t,h,u,i*.14,n*Math.PI+a),t.stroke()}t.restore()}function PS(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 Pi={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 Sc(t={}){return[...Object.keys(Yt),...Object.keys(ae),...Object.keys(en),...Object.keys(Pi),...Object.keys(t.gaits??{}),...Object.keys(t.actions??{})]}function xc(t={}){const e=new Set(Sc()),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 Tc(t={}){const e={};for(const n of Object.keys(Yt))e[n]=`Walks to \`to\` in the ${n} gait, feet planted, turning round first if needed.`;for(const n of Object.keys(ae))e[n]=`Moves into the ${n} pose and holds it.`;for(const n of Object.keys(en))e[n]=`The ${n} gag, built on the current pose.`;for(const[n,s]of Object.entries(Pi))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 wr=["do","at","for","to","toward","mood","say","pose","target","onto"],IS={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"},kr=["viewer","ahead","back"],Rn=t=>typeof t=="number"&&Number.isFinite(t);function Ii(t,e={}){const n=xc(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=Sc(e),i=l=>l in Yt||l in(e.gaits??{}),o=Object.keys(vt),r=Object.keys(ut);let a=-1/0;return t.forEach((l,c)=>{const h=g=>n.push({level:"error",beat:c,message:g}),u=g=>n.push({level:"warning",beat:c,message:g});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 g of Object.keys(d))wr.includes(g)||h(ft("beat field",g,wr,IS[g.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 p=Pi[f]??e.actions?.[f];for(const g of p?.needs??[])d[g]===void 0&&h(`\`${f}\` needs \`${g}\`.`);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[g,m]of Object.entries(d.pose))r.includes(g)?Rn(m)||h(`Pose joint \`${g}\` must be a number (got ${JSON.stringify(m)}).`):h(ft("pose joint",g,r));for(const g of["at","for"]){const m=d[g];m!==void 0&&!(Rn(m)&&m>=0)&&h(`\`${g}\` is milliseconds, a number ≥ 0 (got ${JSON.stringify(m)}).`)}Rn(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 g of["to","onto"]){const m=d[g];m!==void 0&&!Rn(m)&&h(`\`${g}\` is a scene ${g==="to"?"x":"y"} in px, a number (got ${JSON.stringify(m)}).`)}if(d.toward!==void 0&&!Rn(d.toward)&&!kr.includes(d.toward)&&h(`\`toward\` is a scene x or one of ${kr.join(", ")}${typeof d.toward=="string"&&qs(d.toward,kr)?` (did you mean "${qs(d.toward,kr)}"?)`:""} (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 g=d.target;(!g||typeof g!="object"||!Rn(g.x)||!Rn(g.y))&&h("`target` is a point or box in scene px: { x, y } (a code panel’s line(), token() or spot() fits).")}}),n}function Ec(t,e={},n="scriptTracks"){const s=Ii(t,e).filter(i=>i.level==="error");if(s.length!==0)throw new Error(`${n}: ${s.length} problem(s) in the beats:
55
+ `)}`);const i=n.height??1.7,o={...lt,...n.pose},r=(M,T=o)=>{const S=M.match(/^hand\.(?:left|right)\.(.+)$/)?.[1];return T[M]??lt[M]??(S?Ot[S]:void 0)??0};let[a,l]=n.position??[0,0],c=n.heading??0,h=0;const u=new Map,d=[],f=(M,T,S,E="linear")=>{const $=u.get(M)??[];$.push({time:T,value:S,easing:E}),u.set(M,$)},p=(M,T,S)=>{const E=u.get(M)??[];for(let $=E.length-1;$>=0;$--)if(E[$].time===T){if(E[$].value===S)return;break}f(M,T,S)};f("x",0,a),f("z",0,l),f("rotateY",0,c);const g=(M,T,S)=>{const E=ur(c,T);if(Math.abs(E)<1)return S!==void 0&&(p("rotateY",M,c),f("rotateY",M+S,c)),M+(S??0);const $=S??Math.max(uM,Math.abs(E)*hM);return p("rotateY",M,c),c+=E,f("rotateY",M+$,c,"ease-in-out"),M+$},m=(M,T,S,E="ease-in-out")=>{for(const[$,A]of Object.entries(S))r($)!==A&&(p($,M,r($)),f($,T,A,E),o[$]=A)},w=(M,T,S)=>{const E=zg([[a,l],...T.through??[T.to]]);if(E.length<2)return S;const $=g(S,ps(E[0].point,E[1].point)),A=E[E.length-1].at,I=T.speed??Gg[M]*Math.sqrt(i/1.7),C=T.for??A/I*1e3,D=Uo(M,i),j=Wt("ease-in-out"),V=Math.min(dM,C/4);d.push({time:$,value:M}),p("walking",$,0),f("walking",$+V,1,"ease-out"),f("walking",$+C-V,1),f("walking",$+C,0,"ease-in");const et=h;let G=c;for(let F=0;;F=Math.min(A,F+cM)){const H=$+jg(j,F/A)*C,{point:W,direction:_}=qg(E,F);G+=ur(G,ps([0,0],_));const B=F===0?p:f;if(B("x",H,W[0]),B("z",H,W[1]),B("rotateY",H,G),B("walk",H,et+F/D),F>=A)break}return h=et+A/D,[a,l]=E[E.length-1].point,c=G,$+C},v=[],k=[];let y=0;for(const M of e){const T=M.at??y;let S=T;if(ic.includes(M.do))S=w(M.do,M,T);else if(M.do==="face")S=g(T,typeof M.toward=="number"?M.toward:ps([a,l],M.toward),M.for);else if(M.do==="spin")S=T+(M.for??1e3),p("rotateY",T,c),c+=(M.turns??1)*360,f("rotateY",S,c,"linear");else if(M.do==="dance"){const E=Sn[M.dance],$=M.bpm??E.bpm,A=M.beats??(M.for!==void 0?M.for*$/6e4:E.beats);S=T+(M.for??A*6e4/$);const I={...o},C=Math.max(1,Math.ceil(A*16)),D=Array.from({length:C+1},(V,et)=>di(M.dance,A*et/C,I).pose),j=Math.min(150,(S-T)/4);for(const V of Object.keys(D[0])){const et=r(V,I);V==="turn"||V==="roll"||D.every(G=>G[V]===et)||(p(V,T,et),D.slice(1).forEach((G,F)=>{const H=T+(S-T)*(F+1)/C,W=Math.min(1,(H-T)/j),_=W*W*(3-2*W);f(V,H,et+(G[V]-et)*_)}),o[V]=D[C][V])}}else if(M.do==="hold")S=T+(M.for??1e3);else if(M.do==="place")p("x",T,a),p("z",T,l),[a,l]=M.to,f("x",T+1,a),f("z",T+1,l),typeof M.toward=="number"&&(p("rotateY",T,c),c=M.toward,f("rotateY",T+1,c)),S=T+1;else if(M.do==="pose"){S=T+(M.for??500);const E=typeof M.pose=="string"?ye[M.pose]:M.pose;m(T,S,E)}else if(M.do==="gag"){const E=Ff(M.gag,{at:T,from:{...o}});let $=E[0];for(const A of E.slice(1))m($.time,A.time,Object.fromEntries(Object.entries(A.pose).filter(([I,C])=>o[I]!==C)),A.easing??"ease-in-out"),$=A;S=$.time}else if(M.do==="say"){S=T+(M.for??Yg(M.say)),k.push({text:M.say,start:T,end:S});const E={tilt:o["head.tilt"]??0,left:o["brow.left"]??0,right:o["brow.right"]??0};let $=0;for(let A=T+Mi;A<S-Mi/2;A+=Mi,$++){const I=$%2===0;m(A-Mi/2,A,{"head.tilt":E.tilt+(I?3:-2),"brow.left":E.left+(I?.25:0),"brow.right":E.right+(I?.25:0)})}$>0&&m(S-Mi/2,S,{"head.tilt":E.tilt,"brow.left":E.left,"brow.right":E.right})}else if(M.do==="look"){const E=M.look??M.toward,$=i*.9,A=E==="camera"?n.camera??[0,1.6,8]:E.length===3?E:[E[0],$,E[1]];S=T+(M.for??500),m(T,S,sc({x:a,z:l,heading:c,eyeHeight:$},A),"ease-out")}v.push({do:M.do,start:T,end:S}),y=S}const x=`${n.scene}/${t}`;let P=[...u].map(([M,T])=>({id:`${t}-${M}`,target:x,property:M,keyframes:Bg(T)}));return d.length>0&&P.push({id:`${t}-gait`,target:x,property:"gait",keyframes:d}),k.length>0&&(P=hr(x,P,k,{rest:{mouth:n.pose?.mouth??lt.mouth??0,mouthWidth:n.pose?.mouthWidth??lt.mouthWidth??1}})),{tracks:P,duration:y,beats:v,end:{position:[a,l],heading:c,pose:{...o}}}}function ac(t,e,n=[0,0,0]){const s=t.filter(o=>o.target===e),i=new Ht({id:`${e}-position`,tracks:s});return o=>{const r=i.getStateAtTime(o).values.get(e),a=r?.get("position");if(Array.isArray(a)&&a.length===3)return[a[0],a[1],a[2]];const l=(c,h)=>{const u=r?.get(c);return typeof u=="number"?u:h};return[l("x",n[0]),l("y",n[1]),l("z",n[2])]}}function gM(t,e){const n=`${e.scene}/${e.character}`,s=e.height??1.7,i=Math.max(1,e.every??66),o=e.objects?.[e.character]??[0,0,0],r=new Ht({id:`${n}-own`,tracks:t.filter(u=>u.target===n)}),a=e.at,l=typeof a=="function"?a:Array.isArray(a)?()=>a:"camera"in a?ac(t,`${e.scene}/${a.camera}`,e.objects?.[a.camera]??[0,1.6,8]):(()=>{const u=ac(t,`${e.scene}/${a.object}`,e.objects?.[a.object]??[0,0,0]),d=a.eyeHeight??s*.9;return f=>{const p=u(f);return[p[0],p[1]+d,p[2]]}})(),c=["head.turn","head.nod","lookX","lookY"],h={"head.turn":[],"head.nod":[],lookX:[],lookY:[]};for(let u=e.start;;u=Math.min(e.end,u+i)){const d=r.getStateAtTime(u).values.get(n),f=(g,m)=>{const w=d?.get(g);return typeof w=="number"?w:m},p=sc({x:f("x",o[0]),z:f("z",o[2]),heading:f("rotateY",0),eyeHeight:f("y",o[1])+s*.9},l(u));for(const g of c)h[g].push({time:u,value:p[g]??0});if(u>=e.end)break}return c.map(u=>({id:`${n}-lookAt-${u}`,target:n,property:u,keyframes:h[u]}))}function pM(t){const e=Math.max(1,Math.round(t.count)),[n,s]=t.centre??[0,0],i=t.spacing??1.2,o=t.shape??"line",r=[];if(o==="circle"){const h=e<2?0:Math.max(i,i*e/(Math.PI*2));for(let u=0;u<e;u++){const d=u/e*Math.PI*2,f=n+Math.sin(d)*h,p=s+Math.cos(d)*h;r.push({position:[f,p],heading:(Math.atan2(n-f,s-p)*180/Math.PI+360)%360})}return r}if(o==="cluster"){let h=(t.seed??1)>>>0||7;const u=()=>(h^=h<<13,h>>>=0,h^=h>>17,h^=h<<5,h>>>=0,h/4294967296),d=[];for(let f=0;f<e;f++){let p=[n,s],g=-1/0;for(let m=0;m<24;m++){const w=Math.sqrt(u())*i*Math.max(1,Math.sqrt(e)*.9),v=u()*Math.PI*2,k=[n+Math.cos(v)*w,s+Math.sin(v)*w],y=d.length===0?1/0:Math.min(...d.map(x=>Math.hypot(x[0]-k[0],x[1]-k[1])));if(y>g&&(g=y,p=k),y>=i)break}d.push(p),r.push({position:p,heading:0})}return r}const a=(t.heading??90)*Math.PI/180,l=i*(e-1),c=(t.bend??60)*Math.PI/180;for(let h=0;h<e;h++){const u=e===1?0:h/(e-1)-.5,d=u*l;let f=n+Math.sin(a)*d,p=s+Math.cos(a)*d,g=((t.heading??90)-90+360)%360;if(o==="arc"){const m=(1-Math.cos(u*c))*l*.5;f-=Math.cos(a)*m,p+=Math.sin(a)*m,g=(g-u*(t.bend??60)+360)%360}r.push({position:[f,p],heading:g})}return r}const Vg={x:0,y:0,scale:1,rotate:0,shakeX:0,shakeY:0,shakeRotate:0};function mM(t){const e=n=>{const s=t?.get(n);return typeof s=="number"?s:Vg[n]};return{x:e("x"),y:e("y"),scale:e("scale"),rotate:e("rotate"),shakeX:e("shakeX"),shakeY:e("shakeY"),shakeRotate:e("shakeRotate")}}function yM(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 bM(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 Jg(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)tp(t,c,s);t.restore()}function lc(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 Zg=150,wM={pencil:44,eraser:30};function cc(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=Zg*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,p=M=>{const T=M.fingers.thumb,S=M.fingers.index,E=M.fingers.middle,$=Qg([T.points[3],S.points[3],E.points[3]]),A=Qg([T.points[1],S.points[0]]),I=(T.depths[3]+S.depths[3]+E.depths[3])/3;return{pinch:$,direction:Math.atan2(A.y-$.y,A.x-$.x),depth:I}},g=ko(f,{size:u}),m=c-p(g).direction,w=ko(f,{size:u,angle:m*180/Math.PI}),v=p(w),k=wM[i]*a,y={x:v.pinch.x-Math.cos(c)*k,y:v.pinch.y-Math.sin(c)*k},x={x:d.x-y.x,y:d.y-y.y},P=w.axes.up;kM(t,x,{x:-P.x,y:-P.y},u,n.arm??300*a,o,n.sleeve??"#5b7db1",r),vo(t,x,f,{size:u,angle:m*180/Math.PI,skin:o,ink:r,lineWidth:3*a,prop:{depth:v.depth,draw:()=>{t.save(),t.translate(d.x,d.y),t.scale(a,a),i==="eraser"?lc(t,{x:0,y:0},{angle:c*180/Math.PI,outline:r},s):Jg(t,{x:0,y:0},{angle:c*180/Math.PI,length:190,outline:r},s),t.restore()}}})}const Qg=t=>({x:t.reduce((e,n)=>e+n.x,0)/t.length,y:t.reduce((e,n)=>e+n.y,0)/t.length});function kM(t,e,n,s,i,o,r,a){const l={x:-n.y,y:n.x},c=s*.15,h=(g,m,w)=>({x:e.x+n.x*g+l.x*m*w,y:e.y+n.y*g+l.y*m*w}),u=h(i,0,0),d=g=>{const m=t.createLinearGradient(e.x,e.y,u.x,u.y);return m.addColorStop(0,g),m.addColorStop(.6,g),m.addColorStop(1,xM(g)),m},f=Math.min(s*.55,i*.35);t.save(),t.lineJoin="round",t.lineCap="round",t.lineWidth=3*(s/Zg),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 p=[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(),p.forEach((g,m)=>m?t.lineTo(g.x,g.y):t.moveTo(g.x,g.y)),t.closePath(),t.fillStyle=d(r),t.fill(),t.strokeStyle=d(a),t.beginPath(),t.moveTo(p[1].x,p[1].y),t.lineTo(p[0].x,p[0].y),t.lineTo(p[3].x,p[3].y),t.lineTo(p[2].x,p[2].y),t.stroke(),t.restore()}function vM(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(g=>g.path.length>0).sort((g,m)=>g.start-m.start),l=g=>g.tool??"pencil",c=g=>{const m=Math.min(1,Math.max(0,g));return m*m*(3-2*m)},h=(g,m,w)=>({x:g.x+(m.x-g.x)*w,y:g.y+(m.y-g.y)*w}),u=a.find(g=>e>=g.start&&e<=g.end);if(u){const g=u.end-u.start,m=g>0?(e-u.start)/g:1;return{at:go(u.path,m),tool:l(u),lift:0,drawing:!0}}const d=[...a].reverse().find(g=>g.end<e),f=a.find(g=>g.start>e),p=g=>g.path[g.path.length-1];if(d&&f&&f.start-d.end<=r){const g=(e-d.end)/(f.start-d.end),m=g<.5?l(d):l(f);return{at:h(p(d),f.path[0],c(g)),tool:m,lift:Math.sin(Math.PI*g),drawing:!1}}if(f&&f.start-e<=i){const g=1-(f.start-e)/i;return{at:h(s,f.path[0],c(g)),tool:l(f),lift:1-c(g),drawing:!1}}if(d&&e-d.end<=o){const g=(e-d.end)/o;return{at:h(p(d),s,c(g)),tool:l(d),lift:c(g),drawing:!1}}return null}function MM(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 SM(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?po(a,t.sketch,c):void 0;h>0&&(u?t.smooth?u.curve(e,h):u.line(e,h):tp(a,Vn(e,h))),r&&h>0&&h<1&&cc(a,go(e,h),r,u)}}}function xM(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 tp(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 dr=1e5;function TM(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 hc(t,e,n,s){if(s<=0||e.length===0)return;const i=Vn(e,s),o=n/2,r=a=>{t.beginPath(),t.rect(-dr,-dr,2*dr,2*dr),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 EM(t,e,n,s,i){t.save(),hc(t,e,n,s),i(),t.restore()}function AM(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(),hc(o,e.path,n,l),t.draw(o,r,a),o.restore(),!i||l<=0||l>=1)return;const c=go(e.path,l);s?cc(o,c,{...s,tool:"eraser"}):lc(o,c,i)}}}function ms(){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)=>fr(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:$M(i)}))}}}function fr(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 ys(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 $M(t){return[...t].sort((n,s)=>n.time-s.time).map(n=>({time:n.time,value:n.value,...n.easing?{easing:n.easing}:{}}))}const PM=.0016,IM=.6,Qe=33;function Si(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-Qe),c=n(o,r);return{x:(c.x-l.x)/Qe,y:(c.y-l.y)/Qe}},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??PM,h=r.duration??900,u=(r.spin??IM)*(l.x<0?-1:1),d=t.valueAt(e(o,"rotate"),r.at);i(o,r.at);for(let f=0;f<=h;f+=Qe){const p=a.x+l.x*f,g=a.y+l.y*f+.5*c*f*f;t.push(e(o,"x"),{time:r.at+f,value:p-o.home.x}),t.push(e(o,"y"),{time:r.at+f,value:g-o.home.y}),t.push(e(o,"rotate"),{time:r.at+f,value:d+u*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 gr(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(x=>Math.abs(x.top-y)<.5)},c=(o?.keyframes??[]).map(k=>k.time),h=k=>{const y=S=>S<0?0:i[S].offset(k),x=l(k);if(x>=0)return y(x);if(Math.abs(a(k))<.5)return 0;const P=S=>l(S)>=0||Math.abs(a(S))<.5,M=[...c].reverse().find(S=>S<=k&&P(S)),T=c.find(S=>S>=k&&P(S));return M===void 0&&T===void 0?0:M===void 0?y(l(T)):T===void 0||T===M?y(l(M)):y(l(M))+(y(l(T))-y(l(M)))*(k-M)/(T-M)},u=i.flatMap(k=>k.windows),d=(k,y)=>u.some(x=>x.start<y&&x.end>k)||h(k)!==h(y),f=o?[...o.keyframes]:[{time:0,value:0}],p=[{...f[0],value:f[0].value+h(f[0].time)}],g=(k,y)=>{const x=new Set([y]);for(let P=k+s;P<y;P+=s)x.add(P);for(const P of u)for(const M of[P.start,P.end])M>k&&M<y&&x.add(M);for(const P of[...x].sort((M,T)=>M-T))p.push({time:P,value:a(P)+h(P)})};for(let k=1;k<f.length;k++){const y=f[k-1].time,x=f[k].time;d(y,x)?g(y,x):p.push({...f[k],value:f[k].value+h(x)})}const m=f[f.length-1].time,w=Math.max(m,...u.map(k=>k.end));w>m&&g(m,w);const v={id:o?.id??`${e}-y`,target:e,property:"y",keyframes:p};return o?t.map(k=>k===o?v:k):[...t,v]}function In(t){const e=t.indexOf(":");return e<0?{kind:t,rest:""}:{kind:t.slice(0,e),rest:t.slice(e+1)}}function tn(t,e,n,s){const i=Object.keys(n.anchors).map(r=>In(r).kind),{kind:o}=In(e);return i.includes(o)?new Error(`${t}: no anchor "${e}"${s?`: ${s}`:""} (anchors: ${Object.keys(n.anchors).join(", ")})`):new Error(`${t}: ${ft("anchor",o,i)} (anchors: ${Object.keys(n.anchors).join(", ")})`)}function xi(t,e,n){return new Error(`${t}.edit: ${ft("edit",e,Object.keys(n.edits))}`)}function Mt(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 ep={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"},pr=["wipe","fly","blur"],Ti={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"}},OM=.9,_M=8;function CM(t){const e={...ep,...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(F=>F.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(!yr.includes(f))throw new Error(`codePanel: ${ft("language",f,yr)}`);const p=n.map(F=>sp(F,f).flatMap(H=>Array.from(H.text,()=>e[H.kind]))),g=ms(),m=Si(g),w=[],v=new Map,k=[],y=[],x=F=>{if(!Number.isInteger(F)||F<1||F>n.length)throw new Error(`codePanel: no line ${F} (it has ${n.length})`)},P=g.tween,M=g.last,T=(F,H,W,_,B,Q=300)=>{x(F),P(`line.${F}.${H}`,W,_,B,Q)},S=(F,H)=>w.filter(W=>W.line<F&&W.closed<=H).length,E=Mt,$=F=>t.y+r+(F-1)*i,A=F=>Array.isArray(F)?F:[F],I=(F,H,W)=>{let _=-1;for(let B=0;B<W;B++)if(_=n[F-1].indexOf(H,_+1),_<0)throw new Error(`codePanel: line ${F} has no ${W>1?`${W}th `:""}"${H}"`);return _},C={};n.forEach((F,H)=>{const W=H+1;C[`line.${W}.highlight`]=0,C[`line.${W}.strike`]=0,C[`line.${W}.wipe`]=0,C[`line.${W}.reveal`]=d.has(W)?0:1,C[`line.${W}.shift`]=0});const D={type:"custom",x:t.x,y:t.y,width:c,height:h,props:C,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 RM(Object.keys(C))},actions:uc},draw(F,H){const W=H.props??{},_=R=>Number(W[R]??C[R]),B=r+a,Q=R=>r+(R-1)*i-_(`line.${R}.shift`)*i;F.fillStyle=e.background,np(F,0,0,c,h,8),F.fill(),F.font=`${s}px ${e.font}`,F.textBaseline="middle",F.textAlign="left";const O=(R,z,K,N,q)=>{const Y=n[R-1];for(let J=z;J<K;J++)Y[J]!==" "&&(F.fillStyle=p[R-1][J],F.fillText(Y[J],N+(J-z)*o,q))};F.save(),np(F,0,0,c,h,8),F.clip(),n.forEach((R,z)=>{const K=z+1,N=_(`line.${K}.wipe`);if(N>=1)return;const q=Q(K),Y=q+i/2,J=Math.max(1,R.length)*o,X=Math.round(_(`line.${K}.reveal`)*R.length),tt=v.get(K)??{style:"wipe",from:"left"};F.save(),N>0&&HM(F,tt,N,{left:B-a,top:q,width:a+J+o,height:i},c);const nt=_(`line.${K}.highlight`);nt>0&&(F.globalAlpha*=Math.min(1,nt),F.fillStyle=e.highlight,F.fillRect(B-o/2,q,J+o,i),F.globalAlpha/=Math.min(1,nt)),a>0&&X>0&&(F.fillStyle=e.gutter,F.textAlign="right",F.fillText(String(K),B-o,Y),F.textAlign="left");const L=[...k.filter(it=>it.line===K).map(it=>({column:it.column,length:it.text.length,piece:it,insert:void 0})),...y.filter(it=>it.line===K).map(it=>({column:it.column,length:0,piece:void 0,insert:it}))].sort((it,ct)=>it.column-ct.column||it.length-ct.length);let U=0,ot=B;for(const it of L){O(K,U,Math.min(it.column,X),ot,Y),ot+=(it.column-U)*o;let ct=it.length,st="";if(it.piece){const Z=it.piece.written??"",rt=_(`piece.${it.piece.id}.write`);Z&&rt>0?(st=Z.slice(0,Math.round(rt*Z.length)),ct=it.length+(Z.length-it.length)*Math.min(1,rt*2)):ct=it.length*(1-_(`piece.${it.piece.id}.away`))}else it.insert&&(ct=it.insert.chars*_(`insert.${it.insert.id}.open`),it.insert.text&&(st=it.insert.text.slice(0,Math.round(_(`insert.${it.insert.id}.type`)*it.insert.text.length))));F.fillStyle=e.text;for(let Z=0;Z<st.length;Z++)st[Z]!==" "&&F.fillText(st[Z],ot+Z*o,Y);ot+=ct*o,U=it.column+it.length}O(K,U,Math.max(U,X),ot,Y);const at=_(`line.${K}.strike`);at>0&&(F.strokeStyle=e.strike,F.lineWidth=Math.max(1.5,s/10),F.beginPath(),F.moveTo(B,Y),F.lineTo(B+J*Math.min(1,at),Y),F.stroke()),F.restore()});for(const R of k){const z=_(`piece.${R.id}.opacity`);if(z<=0||_(`line.${R.line}.wipe`)>=1)continue;const K=B+(R.column+R.text.length/2)*o+_(`piece.${R.id}.x`),N=Q(R.line)+i/2+_(`piece.${R.id}.y`);F.save(),F.globalAlpha=Math.min(1,z),F.translate(K,N),F.rotate(_(`piece.${R.id}.rotate`)*Math.PI/180),O(R.line,R.column,R.column+R.text.length,-R.text.length*o/2,0),F.restore()}F.restore()}},j=F=>{const{kind:H,rest:W}=In(F),_=B=>tn("codePanel",F,Ti,B);if(H==="box"){if(W)throw _("box takes no arguments");return{kind:H}}if(H==="line"){if(!/^\d+$/.test(W))throw _("write it line:N");return{kind:H,n:Number(W)}}if(H==="token"){const B=/^(\d+)(?:#(\d+))?:(.+)$/.exec(W);if(!B)throw _("write it token:N:TEXT, or token:N#K:TEXT for the Kth");return{kind:H,n:Number(B[1]),occurrence:B[2]?Number(B[2]):1,text:B[3]}}if(H==="spot"){const B=/^(\d+):(\d+)(?::(\d+))?$/.exec(W);if(!B)throw _("write it spot:N:C, or spot:N:C:W for W characters");return{kind:H,n:Number(B[1]),column:Number(B[2]),width:B[3]?Number(B[3]):1}}throw _()},V=(F,H,W,_=!1)=>{const B=Array.isArray(H)?H:[H];if(B.length===0||_&&B.length>1)throw new Error(`codePanel.edit: ${F} takes ${_?"one":"at least one"} ${W} anchor`);return B.map(Q=>{const O=j(Q);if(O.kind!==W)throw new Error(`codePanel.edit: ${F} takes ${W} anchors (${W}:…), not "${Q}"`);return O})},et=(F,H)=>{if(typeof H.text!="string")throw new Error(`codePanel.edit: ${F} needs \`text\` (the text to write)`);return H.text},G={kind:"code",about:Ti,target:D,lines:n,box:E(t.x,t.y,c,h),line(F,H=1/0){return x(F),E(u,$(F)-S(F,H)*i,Math.max(1,n[F-1].length)*o,i)},token(F,H,W=1,_=1/0){x(F);const B=I(F,H,W);return E(u+B*o,$(F)-S(F,_)*i,H.length*o,i)},highlight(F,H){for(const W of A(F)){const _=M(`line.${W}.highlight`,0);T(W,"highlight",_,H.on===!1?0:1,H,200)}return G},strike(F,H){for(const W of A(F))T(W,"strike",M(`line.${W}.strike`,0),1,H);return G},remove(F,H){const W=A(F),_=H.style??"wipe";if(!pr.includes(_))throw new Error(`codePanel.remove: ${ft("style",_,pr)}`);const B=_==="wipe"?300:450,Q=H.at+(H.duration??B),O=H.close??250;for(const R of W)T(R,"wipe",0,1,{...H,easing:H.easing??(_==="fly"?"ease-in":void 0)},B),v.set(R,{style:_,from:H.from??"left"}),w.push({line:R,closed:Q+O});for(let R=1;R<=n.length;R++){if(W.includes(R))continue;const z=W.filter(N=>N<R).length;if(z===0)continue;const K=M(`line.${R}.shift`,0);T(R,"shift",K,K+z,{at:Q,duration:O,easing:"ease-in-out"})}return G},type(F,H){return T(F,"reveal",0,1,{duration:n[F-1].length*45,...H}),G},piece(F,H,W=1){if(typeof F=="string"){const R=j(F);if(R.kind!=="token")throw new Error(`codePanel.piece: a piece is a word, token:N:TEXT, not "${F}"`);return G.piece(R.n,R.text,R.occurrence)}const _=F;if(H===void 0)throw new Error('codePanel.piece: which word? piece(n, text) or piece("token:N:TEXT")');x(_);const B=I(_,H,W),Q=k.find(R=>R.line===_&&R.column===B&&R.text===H);if(Q)return Q;if(k.some(R=>R.line===_&&B<R.column+R.text.length&&R.column<B+H.length))throw new Error(`codePanel: "${H}" on line ${_} overlaps another piece`);const O={id:k.length+1,line:_,column:B,text:H,home:G.token(_,H,W,0)};k.push(O);for(const R of["x","y","rotate","write","away"])C[`piece.${O.id}.${R}`]=0;return C[`piece.${O.id}.opacity`]=1,O},follow(F,H){return m.follow(F,H),G},fling(F,H){return m.fling(F,H),G},move(F,H){return m.move(F,H),G},write(F,H,W){return F.written=H,P(`piece.${F.id}.write`,0,1,{duration:Math.max(1,H.length)*70,...W}),G},spot(F,H,W=1,_=1/0){x(F);const B=y.filter(Q=>Q.line===F&&Q.column<=H&&Q.at<=_).reduce((Q,O)=>Q+O.chars,0);return E(u+(H+B)*o,$(F)-S(F,_)*i,W*o,i)},insert(F,H,W,_){x(F);const B={id:y.length+1,line:F,column:H,chars:W.length,text:W,at:_.at};y.push(B),C[`insert.${B.id}.open`]=0,C[`insert.${B.id}.type`]=0;const Q=_.duration??W.length*70;return P(`insert.${B.id}.open`,0,1,{at:_.at,duration:Q*.6,easing:"ease-out"}),P(`insert.${B.id}.type`,0,1,{at:_.at,duration:Q}),G},drop(F,H,W,_){x(H);const B=_.duration??250,Q=H===F.line,O=_.easing??(Q?"linear":"ease-out"),R=G.landing(F,H,W,_.at),z={id:y.length+1,line:H,column:W,chars:F.text.length,at:_.at};return y.push(z),C[`insert.${z.id}.open`]=0,P(`insert.${z.id}.open`,0,1,{at:_.at,duration:B,easing:Q?O:"ease-out"}),P(`piece.${F.id}.away`,M(`piece.${F.id}.away`,0),1,{at:_.at,duration:B,easing:Q?O:"ease-in-out"}),m.cutAfter(F,_.at),G.move(F,{at:_.at,duration:B,easing:O,to:{x:R.x,y:R.y}}),P(`piece.${F.id}.rotate`,g.valueAt(`piece.${F.id}.rotate`,_.at),0,{at:_.at,duration:B}),G},landing(F,H,W,_=1/0){const B=G.spot(H,W,F.text.length,_),Q=H===F.line&&W>F.column?F.text.length*o:0;return E(B.left-Q,B.top,B.width,B.height)},ride(F,H,W){const _=n.map((B,Q)=>{const O=g.keys(`line.${Q+1}.shift`)??[];return{top:$(Q+1),offset:R=>-fr(O,R)*i,windows:ys(O)}});return gr(F,H,{ground:W.ground,every:W.every??Qe,floors:_})},tracks:g.tracks,anchor(F,H=1/0){const W=j(F);return W.kind==="box"?G.box:W.kind==="line"?G.line(W.n,H):W.kind==="token"?G.token(W.n,W.text,W.occurrence,H):G.spot(W.n,W.column,W.width,H)},edit(F,H,W){const _=()=>V(F,H,"line").map(B=>B.n);if(F==="highlight")return G.highlight(_(),W);if(F==="strike")return G.strike(_(),W);if(F==="remove")return G.remove(_(),W);if(F==="type"){for(const B of _())G.type(B,W);return G}if(F==="insert"){const[B]=V(F,H,"spot",!0);return G.insert(B.n,B.column,et(F,W),W)}if(F==="write"||F==="drop"||F==="move"||F==="fling"){const[B]=V(F,H,"token",!0),Q=G.piece(B.n,B.text,B.occurrence);if(F==="write")return G.write(Q,et(F,W),W);if(F==="fling")return G.fling(Q,W);if(F==="drop"){const R=typeof W.into=="string"?j(W.into):void 0;if(R?.kind!=="spot")throw new Error("codePanel.edit: drop needs `into`, a spot anchor (spot:N:C)");return G.drop(Q,R.n,R.column,W)}const O=typeof W.to=="string"?G.anchor(W.to,W.at):W.to;if(!O||typeof O.x!="number"||typeof O.y!="number")throw new Error("codePanel.edit: move needs `to`, an anchor name or { x, y }");return G.move(Q,{...W,to:O})}throw xi("codePanel",F,Ti)}};return G}function HM(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=_M*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*OM*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 uc={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 RM(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 np(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 mr={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:[]};mr.typescript=[...mr.javascript,"enum","interface","type","implements","private","public","readonly","keyof","as","declare","namespace"];const yr=Object.keys(mr),LM={go:"//",rust:"//",csharp:"//",javascript:"//",typescript:"//",python:"#",plain:null};function sp(t,e){const n=new Set(mr[e]),s=LM[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 dc='"Patrick Hand", "Segoe Print", "Bradley Hand", "Comic Sans MS", "Chalkboard SE", cursive',Ei={whiteboard:{background:"#f7f7f2",frame:"#b8bcc4",ink:"#1f2a44",colors:{ink:"#1f2a44",red:"#d03b3b",blue:"#2f6fd0",green:"#2e9a52",orange:"#e07b1a"},font:dc,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:dc,stroke:.1,opacity:.9},lines:{background:"#fffdf5",frame:"#d9d3c0",ink:"#24315c",colors:{ink:"#24315c",red:"#c73b3b",blue:"#2f6fd0",green:"#2e9a52",orange:"#e07b1a",pencil:"#6b6b6b"},font:dc,stroke:.08,opacity:1,rule:{color:"#c9d6ec",spacing:1.55,margin:"#f0a3a3"}}},fc=["circle","box","underline","arrow"],He={kind:"board",create:"whiteboard({ x, y, width, height, theme?: whiteboard | chalkboard | lines, fontSize?, items: [{ id, text, at: [x, y], size?, color?, hidden? } | { id, mark: circle | box | underline | arrow, around? | from?, to?, bend?, 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"}},ip=90,op=300,FM=.3;function NM(t){const e=typeof t.theme=="string"?t.theme:"whiteboard";if(!(e in Ei))throw new Error(`whiteboard: ${ft("theme",e,Object.keys(Ei))}`);const n=typeof t.theme=="object"?{...Ei.whiteboard,...t.theme}:Ei[e],s=t.fontSize??28,i=t.charWidth??.55,o=y=>y===void 0?n.ink:n.colors[y]??y,r=y=>Mt(t.x+y.left,t.y+y.top,y.width,y.height),a=ms(),l=Si(a),c={},h=new Map,u=[],d=[],f=(y,x,P,M)=>{const T=h.get(y);if(!T||T.kind!=="text")throw tn("whiteboard",M,He,`there is no text "${y}" (texts: ${p().join(", ")||"none"})`);let S=-1;for(let $=0;$<P;$++)if(S=T.item.text.indexOf(x,S+1),S<0)throw tn("whiteboard",M,He,`text "${y}" has no ${P>1?`${P}th `:""}"${x}"`);const E=T.size*i;return{column:S,box:Mt(T.box.left+S*E,T.box.top,x.length*E,T.box.height)}},p=()=>[...h.values()].filter(y=>y.kind==="text").map(y=>y.item.id),g=y=>{const{kind:x,rest:P}=In(y),M=T=>tn("whiteboard",y,He,T);if(x==="box"){if(P)throw M("box takes no arguments");return{kind:x}}if(x==="text"||x==="mark"){if(!P)throw M(`write it ${x}:ID`);return{kind:x,id:P}}if(x==="term"){const T=/^([^:#]+)(?:#(\d+))?:(.+)$/.exec(P);if(!T)throw M("write it term:ID:TEXT, or term:ID#K:TEXT for the Kth");return{kind:x,id:T[1],occurrence:T[2]?Number(T[2]):1,text:T[3]}}throw M()},m=y=>{const x=g(y);if(x.kind==="box")return Mt(0,0,t.width,t.height);if(x.kind==="term")return f(x.id,x.text,x.occurrence,y).box;const P=h.get(x.id);if(!P||P.kind!==x.kind){const M=[...h.values()].filter(T=>T.kind===x.kind).map(T=>T.item.id);throw tn("whiteboard",y,He,`there is no ${x.kind} "${x.id}" (${x.kind}s: ${M.join(", ")||"none"})`)}return P.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($=>typeof $=="number"))throw new Error(`whiteboard: text "${y.id}" needs \`at\`, [x, y] from the board's top-left`);const S=y.size??s,E=Mt(y.at[0],y.at[1],Math.max(1,y.text.length)*S*i,S*1.3);h.set(y.id,{kind:"text",item:y,size:S,color:o(y.color),box:E}),c[`text.${y.id}.write`]=y.hidden?0:1,c[`text.${y.id}.erase`]=0;continue}if(!fc.includes(y.mark))throw new Error(`whiteboard: mark "${y.id}": ${ft("mark",y.mark,fc)}`);const x=y.mark==="arrow"?["from","to"]:["around"];for(const S of x)if(typeof y[S]!="string")throw new Error(`whiteboard: ${y.mark} "${y.id}" needs \`${S}\`, a place on the board (an item before it)`);const P=new Set([y.from,y.to].filter(S=>typeof S=="string").map(S=>S.split(":")[1])),M=y.mark==="arrow"?[...h.values()].filter(S=>S.kind==="text"&&!P.has(S.item.id)).map(S=>S.box):[],T=WM(y,m,s,M);h.set(y.id,{kind:"mark",item:y,color:o(y.color),points:T,box:zM(T)}),c[`mark.${y.id}.draw`]=y.hidden?0:1,c[`mark.${y.id}.erase`]=0}const w=y=>u.filter(x=>x.item===y),v={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 qM(Object.keys(c))},actions:He.edits},draw(y,x){const P=x.props??{},M=T=>Number(P[T]??c[T]??0);if(y.save(),y.fillStyle=n.background,lp(y,0,0,t.width,t.height,10),y.fill(),y.lineWidth=Math.max(4,t.width*.012),y.strokeStyle=n.frame,y.stroke(),n.rule){y.save(),y.beginPath(),lp(y,0,0,t.width,t.height,10),y.clip(),y.lineWidth=1,y.strokeStyle=n.rule.color;const T=s*(n.rule.spacing??1.55);for(let S=T;S<t.height;S+=T)y.beginPath(),y.moveTo(0,S),y.lineTo(t.width,S),y.stroke();n.rule.margin&&(y.strokeStyle=n.rule.margin,y.beginPath(),y.moveTo(s*2.2,0),y.lineTo(s*2.2,t.height),y.stroke()),y.restore()}y.textAlign="center",y.textBaseline="middle",y.lineCap="round",y.lineJoin="round",y.globalAlpha=n.opacity;for(const T of h.values()){if(y.save(),gc(y,T.box,M(`${T.kind}.${T.item.id}.erase`)),T.kind==="text"){const S=w(T.item.id),E=M(`text.${T.item.id}.write`)*T.item.text.length;y.font=`${T.size}px ${n.font}`,y.fillStyle=T.color;for(let $=0;$<Math.ceil(E);$++)T.item.text[$]===" "||S.some(A=>$>=A.column&&$<A.column+A.text.length)||(y.globalAlpha=n.opacity*Math.min(1,E-$),y.fillText(T.item.text[$],T.box.left+($+.5)*T.size*i,T.box.y))}else ap(y,T.points,M(`mark.${T.item.id}.draw`),T.color,s*n.stroke,T.item.mark==="arrow");y.restore()}for(const T of d){const S=M(`strike.${T.id}.draw`);if(S<=0)continue;const{box:E}=T,$=E.height*.15;ap(y,[{x:E.left-3,y:E.y+$},{x:E.right+3,y:E.y-$}],S,n.colors.red??n.ink,s*n.stroke*.8,!1)}for(const T of u){const S=h.get(T.item),E=S.size*i;y.font=`${S.size}px ${n.font}`,y.fillStyle=S.color;const $=T.written;if($){const D=M(`piece.${T.id}.write`)*$.length,j=T.home.x-t.x-$.length*E/2;for(let V=0;V<Math.ceil(D);V++)$[V]!==" "&&(y.globalAlpha=n.opacity*Math.min(1,D-V),y.fillText($[V],j+(V+.5)*E,T.home.y-t.y))}const A=M(`piece.${T.id}.opacity`)*Math.min(1,M(`text.${T.item}.write`)*S.item.text.length-T.column);if(A<=0)continue;y.save();const I={x:T.home.x-t.x,y:T.home.y-t.y},C={x:M(`piece.${T.id}.x`),y:M(`piece.${T.id}.y`)};gc(y,Mt(I.x+C.x-T.home.width/2,I.y+C.y-T.home.height/2,T.home.width,T.home.height),M(`piece.${T.id}.erase`)),Math.hypot(C.x,C.y)<1&&gc(y,S.box,M(`text.${T.item}.erase`)),y.globalAlpha=n.opacity*Math.min(1,A),y.translate(I.x+C.x,I.y+C.y),y.rotate(M(`piece.${T.id}.rotate`)*Math.PI/180);for(let D=0;D<T.text.length;D++)T.text[D]!==" "&&y.fillText(T.text[D],(D+.5-T.text.length/2)*E,0);y.restore()}y.restore()}},k={kind:"board",about:He,target:v,box:Mt(t.x,t.y,t.width,t.height),anchor(y){return r(m(y))},piece(y){const x=g(y);if(x.kind!=="term")throw new Error(`whiteboard.piece: a piece is a term, term:ID:TEXT, not "${y}"`);const{column:P,box:M}=f(x.id,x.text,x.occurrence,y),T=u.find(E=>E.item===x.id&&E.column===P&&E.text===x.text);if(T)return T;if(u.some(E=>E.item===x.id&&P<E.column+E.text.length&&E.column<P+x.text.length))throw new Error(`whiteboard: "${x.text}" in "${x.id}" overlaps another piece`);const S={id:u.length+1,item:x.id,column:P,text:x.text,home:r(M)};u.push(S);for(const E of["x","y","rotate","erase","write"])c[`piece.${S.id}.${E}`]=0;return c[`piece.${S.id}.opacity`]=1,S},edit(y,x,P){const M=Array.isArray(x)?x:[x];if(M.length===0)throw new Error(`whiteboard.edit: ${y} takes at least one anchor`);const T=M.map($=>({name:$,anchor:g($)}));for(const{name:$}of T)m($);const S=($,A=!1)=>{const I=T.find(C=>!$.includes(C.anchor.kind));if(I)throw new Error(`whiteboard.edit: ${y} takes ${$.join(" or ")} anchors, not "${I.name}"`);if(A&&T.length>1)throw new Error(`whiteboard.edit: ${y} takes one ${$.join(" or ")} anchor`)},E=()=>k.piece(T[0].name);if(y==="write"){if(T.some($=>$.anchor.kind==="term")){if(S(["term"],!0),typeof P.text!="string")throw new Error("whiteboard.edit: write into a term needs `text` (the new text)");const $=E();return $.written=P.text,a.tween(`piece.${$.id}.write`,0,1,{duration:Math.max(op,P.text.length*ip),...P}),k}S(["text"]);for(const{anchor:$}of T){const A=$.id,I=h.get(A).item.text;a.tween(`text.${A}.write`,0,1,{duration:Math.max(op,I.length*ip),...P})}return k}if(y==="draw"){S(["mark"]);for(const{anchor:$}of T)a.tween(`mark.${$.id}.draw`,0,1,{duration:500,...P});return k}if(y==="erase"){S(["text","term","mark"]);for(const $ of T){const A=$.anchor.kind==="term"?`piece.${k.piece($.name).id}.erase`:`${$.anchor.kind}.${$.anchor.id}.erase`;a.tween(A,0,1,{duration:400,...P})}return k}if(y==="strike"){S(["text","term"]);for(const $ of T){const A={id:d.length+1,box:m($.name)};d.push(A),c[`strike.${A.id}.draw`]=0,a.tween(`strike.${A.id}.draw`,0,1,{duration:250,...P})}return k}if(y==="move"){S(["term"],!0);const $=typeof P.to=="string"?k.anchor(P.to):P.to;if(!$||typeof $.x!="number"||typeof $.y!="number")throw new Error("whiteboard.edit: move needs `to`, an anchor name or { x, y }");return k.move(E(),{...P,to:$})}if(y==="fling")return S(["term"],!0),k.fling(E(),P);throw xi("whiteboard",y,He)},follow(y,x){return l.follow(y,x),k},fling(y,x){return l.fling(y,x),k},move(y,x){return l.move(y,x),k},ride(y){return y},tracks:a.tracks};return k}function WM(t,e,n,s=[]){const i=je(ne(t.id)),o=g=>(i.next()*2-1)*g,r=n*FM;if(t.mark==="arrow"){const g=e(t.from),m=e(t.to),w=rp(g,m,r*.6),v=rp(m,g,r*.6),k=Math.hypot(v.x-w.x,v.y-w.y),y=BM(w,v);let x=k*(.06+o(.04));if(t.bend!==void 0)x=k*t.bend;else{const T=DM(w,v,y,s,r);T!==0&&(x=T)}const P={x:(w.x+v.x)/2+y.x*x,y:(w.y+v.y)/2+y.y*x},M=[];for(let T=0;T<=24;T++){const S=T/24;M.push({x:(1-S)**2*w.x+2*(1-S)*S*P.x+S*S*v.x,y:(1-S)**2*w.y+2*(1-S)*S*P.y+S*S*v.y})}return M}const a=e(t.around);if(t.mark==="underline"){const g=a.bottom+r*.4;return[{x:a.left-r*.3,y:g+o(2)},{x:a.x,y:g+2+o(2)},{x:a.right+r*.5,y:g-1+o(3)}]}if(t.mark==="box"){const g=a.left-r,m=a.right+r,w=a.top-r*.6,v=a.bottom+r*.6,k=(x,P)=>({x:x+o(r*.2),y:P+o(r*.2)}),y=k(g,w);return[y,k(m,w),k(m,v),k(g,v),y,{x:y.x+r*.8,y:y.y+o(2)}]}const l=a.width/2+r,c=a.height/2+r*.6,h=-2.2+o(.3),u=i.next()*Math.PI*2,d=1.12,f=64,p=[];for(let g=0;g<=f*d;g++){const m=g/f,w=h+m*Math.PI*2,v=1+.035*Math.sin(m*Math.PI*4+u)+.06*m;p.push({x:a.x+Math.cos(w)*l*v,y:a.y+Math.sin(w)*c*v})}return p}function DM(t,e,n,s,i){const o=Math.hypot(e.x-t.x,e.y-t.y);if(o<1e-6)return 0;const r={x:(e.x-t.x)/o,y:(e.y-t.y)/o};let a=0,l=0;for(const c of s){const u=[{x:c.left,y:c.top},{x:c.right,y:c.top},{x:c.right,y:c.bottom},{x:c.left,y:c.bottom}].map(p=>({t:(p.x-t.x)*r.x+(p.y-t.y)*r.y,n:(p.x-t.x)*n.x+(p.y-t.y)*n.y})),d=u.some(p=>p.t>0&&p.t<o),f=u.some(p=>p.n>0)&&u.some(p=>p.n<0);!d||!f||(a=Math.max(a,...u.map(p=>p.n)),l=Math.min(l,...u.map(p=>p.n)))}return a===0&&l===0?0:a<=-l?2*(a+i):2*(l-i)}function rp(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 BM(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 zM(t){const e=t.map(o=>o.x),n=t.map(o=>o.y),s=Math.min(...e),i=Math.min(...n);return Mt(s,i,Math.max(...e)-s,Math.max(...n)-i)}function ap(t,e,n,s,i,o){if(n<=0||e.length<2)return;const r=[0];for(let p=1;p<e.length;p++)r.push(r[p-1]+Math.hypot(e[p].x-e[p-1].x,e[p].y-e[p-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 p=1;p<e.length;p++){if(r[p]<=l){t.lineTo(e[p].x,e[p].y);continue}const g=(l-r[p-1])/(r[p]-r[p-1]||1);t.lineTo(e[p-1].x+(e[p].x-e[p-1].x)*g,e[p-1].y+(e[p].y-e[p-1].y)*g);break}if(t.stroke(),!o||n<=.85)return;const c=(n-.85)/.15,h=e[e.length-1],u=e[e.length-3]??e[0],d=Math.atan2(h.y-u.y,h.x-u.x),f=i*4.5*c;t.beginPath();for(const p of[-1,1])t.moveTo(h.x,h.y),t.lineTo(h.x-Math.cos(d+p*.45)*f,h.y-Math.sin(d+p*.45)*f);t.stroke()}function gc(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 lp(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 qM(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 pc=["bar","line","pie","donut"],cp='system-ui, -apple-system, "Segoe UI", sans-serif',Ai={light:{background:"#ffffff",text:"#3b4252",grid:"#d8dee9",color:"#4c7bd9",highlight:"#e8833a",palette:["#4c7bd9","#3fa66b","#b05cc9","#d9c04c","#4cb8c4","#d95c6f","#8a7a5a","#6b7a99"],font:cp},dark:{background:"#1e2230",text:"#cdd6f4",grid:"#3a4055",color:"#89b4fa",highlight:"#fab387",palette:["#89b4fa","#a6e3a1","#cba6f7","#f9e2af","#94e2d5","#f38ba8","#b4a58a","#9399b2"],font:cp}},On={kind:"chart",create:"chart({ x, y, width, height, kind: bar | line | pie | donut, data: [{ id, label?, value | values: { SERIES: value }, hidden? }], series?: [{ id, label?, color? }], max?, title?, axis?: { x?, y? }, legend?, theme?: light | dark, decimals?, prefix?, suffix?, values? })",anchors:{box:"the whole chart","bar:ID":"a bar (bar charts; bar:ID:SERIES with several series), 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; point:ID:SERIES with several series), as it stands at the time","slice:ID":"a slice of a pie or donut, as it stands at the time (its middle; pulled out, it moves): point at it, make it a piece","label:ID":"its label: under the axis, or beside the slice","value:ID":"its value label: above the bar or point (value:ID:SERIES), or on the slice","legend:SERIES":"a series in the legend (several series)"},edits:{set:"bar, point or slice anchors; { at, value, duration? }: animate to a new value; its value label counts along (a pie re-shares the circle)",show:"bar, point or slice anchors given `hidden`; { at, duration?, on? }: grow a bar in from the axis, draw the line out to a point, or open a slice (on: false takes it back)",highlight:"bar, point or slice anchors; { at, duration?, on? }: colour it out (on: false clears)",pull:"slice anchors; { at, duration?, on? }: pull the slice out from the centre (on: false puts it back)"}},jM=600,YM=500,KM=200,XM=400,GM=.14,UM=Math.PI*2;function VM(t){if(!pc.includes(t.kind))throw new Error(`chart: ${ft("kind",t.kind,pc)}`);const e=typeof t.theme=="string"?t.theme:"light";if(!(e in Ai))throw new Error(`chart: ${ft("theme",e,Object.keys(Ai))}`);const n=typeof t.theme=="object"?{...Ai.light,...t.theme}:Ai[e];if(!Array.isArray(t.data)||t.data.length===0)throw new Error("chart: `data` needs at least one { id, value }");const s=t.kind,i=s==="pie"||s==="donut",o=Array.isArray(t.series)&&t.series.length>1,r=Array.isArray(t.series)&&t.series.length>0?t.series:[{id:"value"}];if(i&&o)throw new Error(`chart: a ${s} shows one series (got ${r.length}); make a chart per series`);const a=new Set;for(const L of r){if(typeof L?.id!="string"||!L.id||/[:.]/.test(L.id))throw new Error(`chart: every series needs an \`id\` without ":" or "." (got ${JSON.stringify(L?.id)})`);if(a.has(L.id))throw new Error(`chart: two series are called "${L.id}"`);a.add(L.id)}const l=new Map(r.map((L,U)=>[L.id,U])),c=L=>r[l.get(L)].color??(l.get(L)===0?n.color:n.palette[l.get(L)%n.palette.length]),h=new Set,u=(L,U)=>{const ot=L.values?.[U.id]??(t.series?void 0:L.value)??L.value;if(typeof ot!="number"||!Number.isFinite(ot))throw new Error(o?`chart: "${L.id}" needs a value for series "${U.id}" (\`values: { ${U.id}: … }\`)`:`chart: "${L.id}" needs a \`value\`, a number`);return ot};for(const L of t.data){if(typeof L?.id!="string"||!L.id||/[:.]/.test(L.id))throw new Error(`chart: every datum needs an \`id\` without ":" or "." (got ${JSON.stringify(L?.id)})`);if(h.has(L.id))throw new Error(`chart: two data are called "${L.id}"`);for(const U of r)u(L,U);h.add(L.id)}const d=s==="bar"?"bar":s==="line"?"point":"slice",f=Math.max(...t.data.flatMap(L=>r.map(U=>u(L,U)))),p=i?t.data.reduce((L,U)=>L+u(U,r[0]),0):t.max??hp(f*1.1);if(!i&&!(p>0))throw new Error(`chart: \`max\` must be above 0 (got ${p})`);const g=Math.max(10,Math.min(16,t.height/20)),m=o&&t.legend!==!1,w=i?void 0:t.axis?.x,v=i?void 0:t.axis?.y,k=t.title?g*2.3:g*.5,y={left:g*3.6+(v?g*1.5:0),right:t.width-g,top:(t.title?g*3:g*1.6)+(m?g*1.6:0),bottom:t.height-g*2.4-(w?g*1.4:0)},x=y.bottom-y.top,P=(y.right-y.left)/t.data.length,M=o?P*.72/r.length:P*.6,T=o?M*.86:M,S=Math.max(4,g*.35),E=x/p,$=new Map(t.data.map((L,U)=>[L.id,U])),A=L=>y.left+P*($.get(L)+.5),I=(L,U)=>o?A(L)-P*.36+M*l.get(U)+(M-T)/2:A(L)-T/2,C=(L,U)=>I(L,U)+T/2,D=t.height-g*1.2,j={cx:t.width/2,cy:(y.top+D)/2,r:Math.max(10,Math.min(t.width/2,(D-y.top)/2)-g*2.6)},V=s==="donut"?j.r*.55:0,et=s==="donut"?(V+j.r)/2:j.r*.62,G=new Map;if(m){let L=y.right;for(const U of[...r].reverse()){const ot=U.label??U.id,at=g*.62*ot.length+g*1.9;G.set(U.id,Mt(L-at,k,at,g*1.4)),L-=at+g*.6}}const F=ms(),H=Si(F),W={},_=(L,U,ot)=>o?`${d}.${L}.${U}.${ot}`:`${d}.${L}.${ot}`;for(const L of t.data)for(const U of r)W[_(L.id,U.id,"value")]=u(L,U),W[_(L.id,U.id,"show")]=L.hidden?0:1,W[_(L.id,U.id,"highlight")]=0,i&&(W[_(L.id,U.id,"pull")]=0);const B=(L,U)=>F.keys(L)?.length?fr(F.keys(L),U):W[L],Q=(L,U,ot)=>B(_(L,U,"value"),ot)*(s==="bar"?B(_(L,U,"show"),ot):1)*E,O=L=>{const U=r[0].id,ot=t.data.map(st=>Math.max(0,L(_(st.id,U,"value")))*Math.max(0,Math.min(1,L(_(st.id,U,"show"))))),at=ot.reduce((st,Z)=>st+Z,0),it=new Map;let ct=-Math.PI/2;return t.data.forEach((st,Z)=>{const rt=at>0?UM*ot[Z]/at:0,ht=ct+rt/2,dt=Math.max(0,Math.min(1,L(_(st.id,U,"pull"))))*j.r*GM;it.set(st.id,{start:ct,sweep:rt,mid:ht,out:dt,centre:{x:j.cx+Math.cos(ht)*(et+dt),y:j.cy+Math.sin(ht)*(et+dt)}}),ct+=rt}),it},R=L=>O(U=>B(U,L)),z=L=>{const{kind:U,rest:ot}=In(L),at=it=>tn("chart",L,On,it);if(U==="box"){if(ot)throw at("box takes no arguments");return{kind:"box"}}if(U==="legend"){if(!G.has(ot))throw at(m?`there is no series "${ot}" (series: ${r.map(it=>it.id).join(", ")})`:"only a chart with several series has a legend");return{kind:"legend",series:ot}}if(U==="bar"||U==="point"||U==="slice"||U==="label"||U==="value"){if(!ot)throw at(`write it ${U}:ID`);const it=ot.indexOf(":"),ct=it<0?ot:ot.slice(0,it),st=it<0?r[0].id:ot.slice(it+1);if(!$.has(ct))throw at(`there is no "${ct}" (data: ${[...$.keys()].join(", ")})`);if(!a.has(st))throw at(`there is no series "${st}" (series: ${r.map(Z=>Z.id).join(", ")})`);if(U==="label"&&it>=0)throw at("a label is one per datum: label:ID");if((U==="bar"||U==="point"||U==="slice")&&U!==d)throw at(`a ${s} chart has ${d}s, not ${U}s: ${d}:${ct}`);return{kind:U,id:ct,series:st}}throw at()},K=(L,U)=>{if(L.kind==="box")return Mt(0,0,t.width,t.height);if(L.kind==="legend")return G.get(L.series);if(i){const st=R(U).get(L.id),Z=Math.max(g*1.5,j.r*.42);if(L.kind==="slice")return Mt(st.centre.x-Z/2,st.centre.y-Z/2,Z,Z);const rt=N(st);return L.kind==="label"?rt:st.sweep>=.3?Mt(st.centre.x-g*1.6,st.centre.y-g*.65,g*3.2,g*1.3):Mt(rt.left,rt.bottom,rt.width,g*1.3)}const ot=L.kind==="label"?A(L.id):C(L.id,L.series),at=y.bottom-Q(L.id,L.series,U);if(L.kind==="bar")return Mt(ot-T/2,at,T,y.bottom-at);if(L.kind==="point")return Mt(A(L.id)-S,at-S,S*2,S*2);if(L.kind==="label")return Mt(ot-P/2,y.bottom+g*.4,P,g*1.4);const it=at-(s==="line"?S:0)-g*.3,ct=o&&s==="bar"?M:P;return Mt((s==="line"?A(L.id):ot)-ct/2,it-g*1.3,ct,g*1.3)},N=L=>{const U=j.r+L.out+g*.9,ot={x:j.cx+Math.cos(L.mid)*U,y:j.cy+Math.sin(L.mid)*U},at=g*4.2,it=Math.cos(L.mid),ct=it>.2?ot.x:it<-.2?ot.x-at:ot.x-at/2;return Mt(ct,ot.y-g*.7,at,g*1.4)},q=L=>Mt(t.x+L.left,t.y+L.top,L.width,L.height),Y=L=>`${t.prefix??""}${L.toFixed(t.decimals??0)}${t.suffix??""}`,J=new Map,X={type:"custom",x:t.x,y:t.y,width:t.width,height:t.height,props:W,about:{kind:`${s} chart`,summary:`A ${s} chart of ${t.data.length} values (${t.data.map(L=>L.id).join(", ")})${o?` in ${r.length} series (${r.map(L=>L.id).join(", ")})`:""}${i?"":`, scaled to ${p}`}. Its ${d}s and labels are places in the scene (anchor()); its edits record tracks (edit(), tracks()).`,props:Object.fromEntries(Object.keys(W).map(L=>[L,QM(L)])),actions:On.edits},draw(L,U){const ot=U.props??{},at=st=>Number(ot[st]??W[st]??0);if(L.save(),L.fillStyle=n.background,up(L,0,0,t.width,t.height,8),L.fill(),L.font=`${g}px ${n.font}`,L.textBaseline="middle",t.title&&(L.fillStyle=n.text,L.textAlign="left",L.font=`600 ${g*1.2}px ${n.font}`,L.fillText(t.title,i?g:y.left,g*1.5),L.font=`${g}px ${n.font}`),m){L.textAlign="left";for(const st of r){const Z=G.get(st.id);L.fillStyle=c(st.id),up(L,Z.left,Z.top+g*.25,g*.9,g*.9,2),L.fill(),L.fillStyle=n.text,L.fillText(st.label??st.id,Z.left+g*1.3,Z.top+Z.height/2)}}if(i){tt(L,at),L.restore();return}L.lineWidth=1,L.textAlign="right";for(let st=0;st<=4;st++){const Z=y.bottom-x*st/4;L.strokeStyle=n.grid,L.beginPath(),L.moveTo(y.left,Z),L.lineTo(y.right,Z),L.stroke(),L.fillStyle=n.text,L.globalAlpha=.7,L.fillText(JM(p*st/4),y.left-g*.5,Z),L.globalAlpha=1}(v||w)&&(L.fillStyle=n.text,L.textAlign="center",L.globalAlpha=.85,v&&(L.save(),L.translate(g*.9,(y.top+y.bottom)/2),L.rotate(-Math.PI/2),L.fillText(v,0,0),L.restore()),w&&L.fillText(w,(y.left+y.right)/2,y.bottom+g*2.3),L.globalAlpha=1);const it=(st,Z)=>at(_(st,Z,"value"))*(s==="bar"?at(_(st,Z,"show")):1)*E,ct=(st,Z)=>mc(c(Z),n.highlight,at(_(st,Z,"highlight")));if(s==="line"){L.lineWidth=Math.max(2,g*.2),L.lineJoin="round",L.lineCap="round";for(const st of r)L.strokeStyle=c(st.id),L.beginPath(),t.data.forEach((Z,rt)=>{const ht={x:A(Z.id),y:y.bottom-it(Z.id,st.id)},dt=at(_(Z.id,st.id,"show"));if(rt===0){dt>0&&L.moveTo(ht.x,ht.y);return}const bt=t.data[rt-1];if(at(_(bt.id,st.id,"show"))<1||dt<=0)return;const wt={x:A(bt.id),y:y.bottom-it(bt.id,st.id)};L.lineTo(wt.x+(ht.x-wt.x)*dt,wt.y+(ht.y-wt.y)*dt)}),L.stroke()}L.textAlign="center";for(const st of t.data){for(const Z of r){const rt=s==="bar"?C(st.id,Z.id):A(st.id),ht=it(st.id,Z.id),dt=at(_(st.id,Z.id,"show"));if(L.fillStyle=ct(st.id,Z.id),s==="bar"?ht>.5&&(ZM(L,rt-T/2,y.bottom-ht,T,ht,Math.min(6,T/4)),L.fill()):dt>0&&(L.beginPath(),L.arc(rt,y.bottom-ht,S*Math.min(1,dt*1.5)*(1+.3*at(_(st.id,Z.id,"highlight"))),0,Math.PI*2),L.fill()),t.values!==!1&&dt>0){L.globalAlpha=Math.min(1,dt*2),L.font=`600 ${o?g*.85:g}px ${n.font}`,L.fillStyle=mc(n.text,n.highlight,at(_(st.id,Z.id,"highlight")));const bt=y.bottom-ht-(s==="line"?S:0)-g*.95;L.fillText(Y(at(_(st.id,Z.id,"value"))),rt,bt),L.font=`${g}px ${n.font}`,L.globalAlpha=1}}L.fillStyle=n.text,L.fillText(st.label??st.id,A(st.id),y.bottom+g*1.1)}L.strokeStyle=n.text,L.lineWidth=1.5,L.beginPath(),L.moveTo(y.left,y.bottom),L.lineTo(y.right,y.bottom),L.stroke(),L.restore()}};function tt(L,U){const ot=r[0].id,at=O(U);t.data.forEach((it,ct)=>{const st=at.get(it.id);if(st.sweep<=1e-4)return;const Z=J.get(it.id),rt=Z?{x:U(`piece.${Z.id}.x`),y:U(`piece.${Z.id}.y`)}:{x:0,y:0},ht=Z?U(`piece.${Z.id}.rotate`)*Math.PI/180:0,dt=Z?U(`piece.${Z.id}.opacity`):1;if(dt<=0)return;L.save(),L.globalAlpha=dt;const bt={x:j.cx+Math.cos(st.mid)*st.out,y:j.cy+Math.sin(st.mid)*st.out};L.translate(st.centre.x+rt.x,st.centre.y+rt.y),L.rotate(ht),L.translate(-st.centre.x,-st.centre.y),L.beginPath(),L.arc(bt.x,bt.y,j.r,st.start,st.start+st.sweep),V>0?L.arc(bt.x,bt.y,V,st.start+st.sweep,st.start,!0):L.lineTo(bt.x,bt.y),L.closePath(),L.fillStyle=mc(n.palette[ct%n.palette.length],n.highlight,U(_(it.id,ot,"highlight"))),L.fill(),L.strokeStyle=n.background,L.lineWidth=Math.max(1.5,g*.15),L.stroke(),t.values!==!1&&st.sweep>=.3&&(L.fillStyle=n.background,L.font=`600 ${g}px ${n.font}`,L.textAlign="center",L.fillText(Y(U(_(it.id,ot,"value"))),st.centre.x,st.centre.y),L.font=`${g}px ${n.font}`),L.restore();const wt=N(st),ge=Math.cos(st.mid);L.globalAlpha=dt,L.fillStyle=n.text,L.textAlign=ge>.2?"left":ge<-.2?"right":"center";const zi=ge>.2?wt.left:ge<-.2?wt.right:wt.left+wt.width/2;L.fillText(it.label??it.id,zi,wt.top+wt.height/2),t.values!==!1&&st.sweep<.3&&(L.globalAlpha=dt*.8,L.fillText(Y(U(_(it.id,ot,"value"))),zi,wt.bottom+g*.65)),L.globalAlpha=1})}const nt={kind:"chart",chartKind:s,about:On,target:X,max:p,box:Mt(t.x,t.y,t.width,t.height),anchor(L,U=1/0){return q(K(z(L),U))},piece(L){const U=z(L);if(U.kind!=="slice")throw new Error(i?`chart: a piece is a slice, slice:ID, not "${L}"`:`chart: a ${d} is not a piece; slices of a pie or donut are (slice:ID). Change a ${d} with edit('set' | 'show' | 'highlight', …)`);const ot=J.get(U.id);if(ot)return ot;const at={id:J.size+1,datum:U.id,home:q(K(U,0))};J.set(U.id,at);for(const it of["x","y","rotate"])W[`piece.${at.id}.${it}`]=0;return W[`piece.${at.id}.opacity`]=1,at},edit(L,U,ot){const at=Array.isArray(U)?U:[U];if(at.length===0)throw new Error(`chart.edit: ${L} takes at least one anchor`);if(!(L in On.edits))throw xi("chart",L,On);if(L==="pull"&&!i)throw new Error(`chart.edit: pull takes slice anchors of a pie or donut; a ${s} chart has ${d}s`);const it=at.map(ct=>{const st=z(ct);if(st.kind!==d)throw new Error(`chart.edit: ${L} takes ${d} anchors (${d}:ID), not "${ct}"`);return st});for(const{id:ct,series:st}of it){const Z=rt=>_(ct,st,rt);if(L==="set"){if(typeof ot.value!="number"||!Number.isFinite(ot.value))throw new Error("chart.edit: set needs `value`, a number");F.tween(Z("value"),B(Z("value"),ot.at),ot.value,ot,jM)}else L==="show"?F.tween(Z("show"),B(Z("show"),ot.at),ot.on===!1?0:1,ot,YM):L==="pull"?F.tween(Z("pull"),B(Z("pull"),ot.at),ot.on===!1?0:1,ot,XM):F.tween(Z("highlight"),B(Z("highlight"),ot.at),ot.on===!1?0:1,ot,KM)}return nt},follow(L,U){return H.follow(L,U),nt},fling(L,U){return H.fling(L,U),nt},move(L,U){return H.move(L,U),nt},ride(L,U,ot){if(s!=="bar")return L;const at=t.data.flatMap(it=>r.map(ct=>{const st=Q(it.id,ct.id,0),Z=[...ys(F.keys(_(it.id,ct.id,"value"))),...ys(F.keys(_(it.id,ct.id,"show")))];return{top:t.y+y.bottom-st,offset:rt=>st-Q(it.id,ct.id,rt),windows:Z}}));return gr(L,U,{ground:ot.ground,every:ot.every??Qe,floors:at})},tracks:F.tracks};return nt}function hp(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 JM(t){return Number.isInteger(t)?String(t):String(Number(t.toFixed(2)))}function mc(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 up(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 ZM(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 QM(t){return t.endsWith(".value")?{description:"Its value (the bar’s height, the point’s, or the slice’s share, 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, a slice opened",unit:"0..1",min:0,max:1}:t.endsWith(".pull")?{description:"How far the slice is pulled out from the centre",unit:"0..1",min:0,max:1}:t.startsWith("piece.")?{description:t.endsWith(".opacity")?"The loose slice’s opacity":t.endsWith(".rotate")?"The loose slice’s turn, degrees":"The loose slice’s offset from home, px",unit:t.endsWith(".rotate")?"degrees":t.endsWith(".opacity")?"0..1":"px"}:{description:"How much it is coloured out",unit:"0..1",min:0,max:1}}function dp(){return{torso:[{at:0,width:.083},{at:.25,width:.08},{at:.5,width:.075},{at:.8,width:.085},{at:1,width:.023}],arm:[{at:0,width:.026},{at:.3,width:.024},{at:.5,width:.018},{at:.7,width:.021},{at:1,width:.012}],leg:[{at:0,width:.036},{at:.3,width:.037},{at:.5,width:.026},{at:.7,width:.029},{at:1,width:.015}]}}const $i={youngMan:{figure:"organic",skin:"#edb98d",ink:"#53372d",headSize:.28,shoulderWidth:.074,hipWidth:.045,handSize:.078,hair:{style:"softSweep",color:"#38291f"},ears:!0,face:{style:"anime",shape:"angular",jawWidth:.83,chinWidth:.35,jawRoundness:1,eyeScale:.95,eyeAspect:1.1,nose:!0,iris:"#6a472d"},outfit:{shirt:"#bc7050",trousers:"#495a67",sleeves:"short"}},youngWoman:{figure:"organic",skin:"#f1c299",ink:"#53372d",headSize:.28,shoulderWidth:.065,hipWidth:.054,handSize:.075,body:{torso:[{at:0,width:.098},{at:.18,width:.097},{at:.44,width:.061},{at:.7,width:.087},{at:.85,width:.09},{at:1,width:.024}]},hair:{style:"flowingBob",color:"#38291f"},ears:!0,face:{style:"anime",shape:"angular",jawWidth:.78,chinWidth:.32,jawRoundness:1,eyeScale:.95,eyeAspect:1.1,nose:!0,iris:"#6a472d",lashes:!0},outfit:{shirt:"#72958b",trousers:"#6b6888",sleeves:"short",bottom:"skirt"}},childBoy:{figure:"organic",height:230,skin:"#edb98d",ink:"#53372d",headSize:.36,shoulderWidth:.052,hipWidth:.038,legLength:.82,armLength:.8,handSize:.074,body:dp(),hair:{style:"softSweep",color:"#38291f"},ears:!0,face:{style:"anime",shape:"round",eyeScale:1,eyeAspect:1.1,nose:!0,iris:"#6a472d"},outfit:{shirt:"#d99843",trousers:"#497b91",sleeves:"short",bottom:"shorts"}},childGirl:{figure:"organic",height:225,skin:"#f1c299",ink:"#53372d",headSize:.36,shoulderWidth:.052,hipWidth:.038,legLength:.82,armLength:.8,handSize:.074,body:dp(),hair:{style:"flowingBob",color:"#38291f"},ears:!0,face:{style:"anime",shape:"round",eyeScale:1,eyeAspect:1.1,nose:!0,iris:"#6a472d",lashes:!0},outfit:{shirt:"#ae7396",trousers:"#648769",sleeves:"short",bottom:"skirt"}}};function tS(t,e={}){if(!Object.prototype.hasOwnProperty.call($i,t))throw new Error(`softCartoonCharacter: unknown actor '${t}'`);const n=$i[t];return us({...n,...e,body:{...n.body,...e.body},face:{...n.face,...e.face}})}const fp={animeBoy:{label:"Anime boy",group:"anime",scale:.68,options:{figure:"fluid",look:"clean",proportions:"thin",build:"child",headSize:.34,skin:"#f2c7a5",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"spiky",color:"#263c68"},face:{style:"anime",iris:"#318fa5",lashes:!1},outfit:{shirt:"#efac45",trousers:"#375a91",bottom:"shorts",shoes:"boots"}}},animeGirl:{label:"Anime girl",group:"anime",scale:.68,options:{figure:"fluid",look:"clean",proportions:"thin",build:"child",headSize:.34,skin:"#e8ad8c",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"bob",color:"#4f304e"},face:{style:"anime",iris:"#9d5f32"},outfit:{shirt:"#e9779f",trousers:"#5c4c86",bottom:"shorts",shoes:"boots"}}},animeYoungMan:{label:"Anime young man",group:"anime",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"tall",headSize:.23,skin:"#efbf9c",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"spiky",color:"#243552"},face:{style:"anime",iris:"#507bcc",lashes:!1},outfit:{shirt:"#57bbc0",trousers:"#334967",sleeves:"long",over:"hoodie",overColor:"#57bbc0",shoes:"boots"}}},animeYoungWoman:{label:"Anime young woman",group:"anime",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"slim",headSize:.23,skin:"#f3cbb4",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"highPonytail",color:"#773853"},face:{style:"anime",iris:"#9163c4"},outfit:{shirt:"#ae7cda",trousers:"#35456c",sleeves:"long",shoes:"boots"}}},animeMan:{label:"Anime man",group:"anime",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"broad",headSize:.23,skin:"#b67f62",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"sidePart",color:"#302839"},face:{style:"anime",iris:"#9b713b",lashes:!1},outfit:{shirt:"#677aab",trousers:"#343848",sleeves:"long",collar:!0,shoes:"boots"}}},animeWoman:{label:"Anime woman",group:"anime",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"standard",headSize:.23,skin:"#d59a73",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"shoulderWaves",color:"#382c4c"},face:{style:"anime",iris:"#2b8f82"},outfit:{shirt:"#df6c79",trousers:"#46506c",sleeves:"long",bottom:"skirt",shoes:"boots"}}},animeOlderMan:{label:"Anime older man",group:"anime",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"stocky",headSize:.25,skin:"#e0b291",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"receding",color:"#b8c4d1"},facialHair:{style:"shortBoxed",color:"#dae0e8"},face:{style:"anime",iris:"#557c8b",lashes:!1,ageLines:.8},outfit:{shirt:"#9c846c",trousers:"#46505c",sleeves:"long",collar:!0,shoes:"boots"}}},animeOlderWoman:{label:"Anime older woman",group:"anime",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"standard",headSize:.25,skin:"#c4947b",ink:"#302c48",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"topBun",color:"#d1d3df"},face:{style:"anime",iris:"#7a6998",ageLines:.8},outfit:{shirt:"#6d9b93",trousers:"#66597a",sleeves:"long",over:"cardigan",overColor:"#6d9b93",shoes:"boots"}}}},gp={mangaYoungMan:{label:"Manga young man",group:"manga",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"tall",headSize:.21,lineWidth:2.8,skin:"#edbf9b",ink:"#252536",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"mangaSpikes",color:"#27354c"},face:{style:"anime",shape:"angular",jawWidth:.78,chinWidth:.16,eyeScale:.8,eyeAspect:.63,iris:"#3a9baa",lashes:!1,nose:!0},outfit:{shirt:"#c65a49",trousers:"#293c56",sleeves:"long",collar:!0,shoes:"boots"}}},mangaYoungWoman:{label:"Manga young woman",group:"manga",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"slim",headSize:.21,lineWidth:2.8,skin:"#e2a482",ink:"#252536",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"mangaSweep",color:"#683e64"},face:{style:"anime",shape:"angular",jawWidth:.69,chinWidth:.1,eyeScale:.85,eyeAspect:.72,iris:"#8462b7",nose:!0},outfit:{shirt:"#518c96",trousers:"#364361",sleeves:"long",shoes:"boots"}}},mangaRival:{label:"Manga rival",group:"manga",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"broad",headSize:.21,lineWidth:2.8,skin:"#b77e5f",ink:"#252536",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"mangaSpikes",color:"#e6e0cc",volume:.16},face:{style:"anime",shape:"angular",jawWidth:.9,chinWidth:.25,eyeScale:.75,eyeAspect:.55,iris:"#ba8445",lashes:!1,nose:!0},outfit:{shirt:"#4c4b75",trousers:"#303348",sleeves:"long",over:"hoodie",shoes:"boots"}}},mangaHeroine:{label:"Manga heroine",group:"manga",scale:1,options:{figure:"fluid",look:"clean",proportions:"thin",build:"tall",headSize:.21,lineWidth:2.8,skin:"#f0c5aa",ink:"#252536",ears:!0,hands:"cartoon",handStyle:"natural",hair:{style:"highPonytail",color:"#263647",texture:"spiky",textureAmount:.35},face:{style:"anime",shape:"angular",jawWidth:.73,chinWidth:.12,eyeScale:.83,eyeAspect:.65,iris:"#427e9b",nose:!0},outfit:{shirt:"#b65e7c",trousers:"#31405b",sleeves:"long",collar:!0,shoes:"boots"}}}},yc={boy:{label:"Boy",group:"family",scale:.66,options:{build:"child",hair:"short",ears:!0,outfit:{shirt:"#4f8fd6",trousers:"#2f4d6b",bottom:"shorts"}}},girl:{label:"Girl",group:"family",scale:.66,options:{build:"child",hair:{style:"bob",color:xe.chestnut},ears:!0,outfit:{shirt:"#e86a92",trousers:"#4a5b8c",bottom:"skirt"}}},youngMan:{label:"Young man",group:"family",scale:1,options:{build:"tall",hair:"spiky",ears:!0,outfit:{shirt:"#3c9a6e",trousers:"#2d3a4f"}}},youngWoman:{label:"Young woman",group:"family",scale:.96,options:{build:"slim",hair:{style:"highPonytail",color:xe.auburn},ears:!0,outfit:{shirt:"#f0b43c",trousers:"#36507a"}}},man:{label:"Man",group:"family",scale:1,options:{build:"broad",hair:"sidePart",facialHair:"chevron",ears:!0,outfit:{shirt:"#7a8fa6",trousers:"#3b3f46",sleeves:"long",collar:!0,tie:"#2b4f8c"}}},woman:{label:"Woman",group:"family",scale:.95,options:{build:"curvy",hair:{style:"shoulderWaves",color:xe.black},ears:!0,outfit:{shirt:"#9b5fc0",trousers:"#2f2f3a",sleeves:"long"}}},grandpa:{label:"Grandpa",group:"family",scale:.96,options:{build:"stocky",hair:{style:"receding",color:xe.gray},facialHair:{style:"shortBoxed",color:xe.white},glasses:"square",ears:!0,outfit:{shirt:"#b98a5a",trousers:"#4b4440",sleeves:"long",collar:!0}}},grandma:{label:"Grandma",group:"family",scale:.9,options:{build:"short",hair:{style:"topBun",color:xe.white},glasses:"round",ears:!0,outfit:{shirt:"#5d9fa8",trousers:"#5a4a5e",sleeves:"long",bottom:"skirt"}}},doctor:{label:"Doctor",group:"work",scale:.97,options:{build:"slim",hair:{style:"lowPonytail",color:xe.black},ears:!0,outfit:{shirt:"#8fb8d8",trousers:"#36507a",over:"labCoat",collar:!0}}},cook:{label:"Cook",group:"work",scale:1,options:{build:"stocky",hair:"crewCut",facialHair:"shortMoustache",ears:!0,outfit:{shirt:"#f4f6f8",trousers:"#3b3f46",sleeves:"long",over:"apron",overColor:"#e2493b"}}},builder:{label:"Builder",group:"work",scale:1,options:{build:"broad",hair:"short",facialHair:"stubble",hat:"hardHat",ears:!0,outfit:{shirt:"#f08a3c",trousers:"#4a5b8c"}}},courier:{label:"Courier",group:"work",scale:.98,options:{build:"standard",hair:"short",hat:{style:"cap",color:"#d64535"},ears:!0,outfit:{shirt:"#c94a3b",trousers:"#2f2f3a",bottom:"shorts"}}},teacher:{label:"Teacher",group:"work",scale:1,options:{build:"tall",hair:"slickBack",glasses:"square",ears:!0,outfit:{shirt:"#f4f6f8",trousers:"#3b3f46",sleeves:"long",collar:!0,tie:"#9a4426"}}},farmer:{label:"Farmer",group:"work",scale:.97,options:{build:"stocky",hair:{style:"shoulderStraight",color:xe.blond},hat:"sunHat",ears:!0,outfit:{shirt:"#d64535",trousers:"#4f6b3a",sleeves:"long"}}},...fp,...gp};function eS(t,e=300,n={}){const s=yc[t];if(!s)throw new Error(`castMember: unknown cast member '${t}'`);return{...s.options,height:Math.round(e*s.scale),...n}}const Pi={handshake:{height:.47,spacing:.42,lean:6},highFive:{height:.9,spacing:.4,lean:4},fistBump:{height:.55,spacing:.44,lean:6},handOver:{height:.52,spacing:.46,lean:8}};function nS(t,e,n){return Pi[t].spacing*Math.min(e.height,n.height)}const pp=.075;function sS(t,e,n,s={}){const i=Pi[t];if(!i)throw new Error(`meetHands: unknown meeting '${t}' (one of ${Object.keys(Pi).join(", ")})`);const[o,r]=e.x<=n.x?[e,n]:[n,e],a=s.view==="side",l=Math.min(o.character.height,r.character.height),c={x:(o.x+r.x)/2,y:-(s.height??i.height)*l},h=(m,w)=>{const v=w?a?1:.62:a?3:3.38;let k={...lt,...m.pose,turn:v,lean:(m.pose?.lean??0)+i.lean};const y=w?1:-1,x=(P,M,T)=>{k=Ce(m.character,k,P,{x:c.x+M-m.x,y:c.y,depth:T})};if(t==="handOver"){const P=pp*l;x("arm.left",-y*P*.9,P),x("arm.right",-y*P*.9,-P)}else x("arm.right",0,0);return t==="fistBump"&&(k={...k,"hand.right.index.curl":1,"hand.right.middle.curl":1,"hand.right.ring.curl":1,"hand.right.pinky.curl":1}),k},u=h(o,!0),d=h(r,!1),f=.03*l,p=(m,w)=>{const v=fe(m.character,w),k=t==="handOver"?["hand.left","hand.right"]:["hand.right"],y=t==="handOver"?pp*l+f:f;return k.every(x=>Math.abs(v.points[x].y-c.y)<f&&Math.abs(v.points[x].x+m.x-c.x)<y)},g=p(o,u)&&p(r,d);return e.x<=n.x?{a:u,b:d,point:c,reached:g}:{a:d,b:u,point:c,reached:g}}const br={spacing:.3,lean:10,tilt:8};function iS(t,e){return br.spacing*Math.min(t.height,e.height)}function oS(t,e,n={}){const[s,i]=t.x<=e.x?[t,e]:[e,t],o=n.view==="side",r=Math.min(s.character.height,i.character.height),a=(p,g,m)=>({over:{x:g.x-m*.02*r-p.x,y:-.72*r,depth:-.08*r},round:{x:g.x-m*.04*r-p.x,y:-.5*r,depth:.06*r}}),l=(p,g,m)=>{const w=m?o?1:.62:o?3:3.38,v=m?1:-1;let k={...lt,...p.pose,turn:w,lean:(p.pose?.lean??0)+br.lean,"head.tilt":(p.pose?.["head.tilt"]??0)+v*br.tilt};const{over:y,round:x}=a(p,g,v);return k=Ce(p.character,k,"arm.right",y),k=Ce(p.character,k,"arm.left",x),k},c=l(s,i,!0),h=l(i,s,!1),u=.05*r,d=(p,g,m,w)=>{const v=fe(p.character,w).points,{over:k,round:y}=a(p,g,m);return Math.hypot(v["hand.right"].x-k.x,v["hand.right"].y-k.y)<u&&Math.hypot(v["hand.left"].x-y.x,v["hand.left"].y-y.y)<u},f=d(s,i,1,c)&&d(i,s,-1,h);return t.x<=e.x?{a:c,b:h,reached:f}:{a:h,b:c,reached:f}}const _n={spacing:.32,low:.3,high:.5,helperLean:40,helperBend:16};function rS(t,e){return _n.spacing*Math.min(t.height,e.height)}function aS(t,e,n,s={}){const i=Math.max(0,Math.min(1,n)),o=s.view==="side",r=t.x<=e.x,a=Math.min(t.character.height,e.character.height),l={x:(t.x+e.x)/2,y:-(_n.low+(_n.high-_n.low)*i)*a},c=m=>m?o?1:.62:o?3:3.38;let h={...lt,...t.pose,turn:c(r),lean:(t.pose?.lean??0)+_n.helperLean*(1-i)+4,bend:(t.pose?.bend??0)+_n.helperBend*(1-i),"head.nod":18*(1-i)};h=Ce(t.character,h,"arm.right",{x:l.x-t.x,y:l.y});const u={...ye.sitFloor,...e.pose,turn:c(!r)},d={...lt,...e.pose,turn:c(!r)};let f=Wl(u,d,i);f=Ce(e.character,f,"arm.right",{x:l.x-e.x,y:l.y});const p=.04*a,g=(m,w)=>{const v=fe(m.character,w).points["hand.right"];return Math.hypot(v.x+m.x-l.x,v.y-l.y)<p};return{helper:h,sitter:f,point:l,reached:g(t,h)&&g(e,f)}}const bc=Object.freeze({everyday:Object.freeze({shirt:"#bc7050",trousers:"#495a67",sleeves:"short",bottom:"trousers",collar:!1,tie:null}),formal:Object.freeze({top:"shirt",shirt:"#f4ede2",trousers:"#394653",sleeves:"long",bottom:"trousers",trouserStyle:"plain",collar:!0,tie:"#804453"}),casual:Object.freeze({top:"tshirt",shirt:"#648a83",trousers:"#426683",sleeves:"short",bottom:"trousers",trouserStyle:"jeans",collar:!1,tie:null})});function mp(t,e={}){if(!Object.prototype.hasOwnProperty.call(bc,t))throw new Error(`outfitPreset: unknown category '${t}'`);const n={...bc[t],...e};return e.top&&e.top!=="shirt"&&(n.collar=e.collar??!1,n.tie=e.tie??null),n.top==="dress"&&(n.bottom="skirt"),n}const lS=.7,cS=50,hS=1.2,uS=.8,dS=3,fS=30,gS=.8,pS=.6,wc=(t,e)=>Math.max(-e,Math.min(e,t)),mS=["hair.swing","hair.trail","hair.lift"];function yp(t,e){const n=e.start??0,s=e.amount??1,i=Math.max(1e-6,e.headRadius);let o=NaN,r={x:0,y:0,turn:0};const a=f=>(f!==o&&(r=t(f),o=f),r),l=f=>{const p=a(f);return p.turn*90+(p.headTurn??0)},c={start:n,end:e.end,step:e.step,stiffness:e.stiffness??70,damping:e.damping??6},h=Ks(l,c),u=Ks(f=>a(f).x,c),d=Ks(f=>a(f).y,c);return h.map((f,p)=>{const g=a(f.time),m=f.value-l(f.time),w=u[p].value-g.x-(e.wind??0)*lS*i,v=d[p].value-g.y,k=Math.sin(g.turn*Math.PI/2),y=Math.cos(g.turn*Math.PI/2),x=m*dS+w*y/i*fS,P=-w*k/i*gS,M=-v/i*pS;return{time:f.time,swing:wc(x*s,cS),trail:wc(P*s,hS),lift:wc(M*s,uS)}})}function yS(t,e){if(t.length===0)return{"hair.swing":0,"hair.trail":0,"hair.lift":0};if(e<=t[0].time)return bp(t[0]);if(e>=t[t.length-1].time)return bp(t[t.length-1]);let n=0,s=t.length-1;for(;s-n>1;){const a=n+s>>1;t[a].time<=e?n=a:s=a}const i=t[n],o=t[s],r=o.time===i.time?0:(e-i.time)/(o.time-i.time);return{"hair.swing":i.swing+(o.swing-i.swing)*r,"hair.trail":i.trail+(o.trail-i.trail)*r,"hair.lift":i.lift+(o.lift-i.lift)*r}}const bp=t=>({"hair.swing":t.swing,"hair.trail":t.trail,"hair.lift":t.lift}),bs=16,bS=1500;function wS(t,e,n,s={}){const i=n.head.hair;if(!i||!cf(i))return[];const o=e.filter(v=>v.target===t),r=o.reduce((v,k)=>k.keyframes.reduce((y,x)=>Math.max(y,x.time),v),0),a=lt,l=new Set(["x","y","turn","head.turn"]),c=new Ht({id:`${t}-hair-follow`,tracks:o.filter(v=>l.has(v.property))}),h=(v,k,y)=>{const x=c.getStateAtTime(v).values.get(t)?.get(k);return typeof x=="number"?x:y},u=new Ht({id:`${t}-hair-pose`,tracks:o}),d=v=>u.getStateAtTime(v).values.get(t),f=new Map,p=v=>{const k=Math.round(v/bs);let y=f.get(k);if(!y){const x={};for(const[M,T]of d(k*bs)??[])x[M]=T;const P=fe(n,tr(x,a,s.gaits)).head.center;f.set(k,y={x:P.x,y:P.y})}return y},g=v=>{const k=Math.floor(v/bs),y=v/bs-k,x=p(k*bs),P=p((k+1)*bs);return{x:x.x+(P.x-x.x)*y,y:x.y+(P.y-x.y)*y}},m=yp(v=>{const k=g(v);return{x:h(v,"x",0)+k.x,y:h(v,"y",0)+k.y,turn:h(v,"turn",a.turn??0),headTurn:h(v,"head.turn",a["head.turn"]??0)}},{start:0,end:r+(s.settle??bS),headRadius:fe(n,lt).head.rx,step:s.step,stiffness:s.stiffness,damping:s.damping,amount:s.amount,wind:s.wind}),w=[];for(const v of mS){const k=v.slice(5);let y=m.map(P=>({time:P.time,value:P[k]}));if(y.every(P=>Math.abs(P.value)<.001))continue;const x=o.find(P=>P.property===v);if(x){const P=new Ht({id:`${t}-${v}-own`,tracks:[x]}),M=T=>Number(P.getStateAtTime(T).values.get(t)?.get(v)??0);y=y.map(T=>({time:T.time,value:T.value+M(T.time)}))}w.push({id:`${t}-${v}`,target:t,property:v,keyframes:y})}return w}const Cn={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 kc(t){if(t===void 0)return Cn.full;if(typeof t=="string")return Cn[t];const{base:e,...n}=t;return{...Cn[e??"full"],...n}}const vc=160,kS=120,vS=700,Mc=60,MS=90,wr=3200,ws=1,Hn=1e-6;function kr(t,e,n={}){const s=kc(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])>Hn));for(const u of r)o[u]=SS(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=xS(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=TS(t,c,t[0].pose[h],s.jumpSquash);u.length>0&&(o[h]=u)}return o}function SS(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 p=(e[f].time-e[f-1].time)/2;return Math.max(-p,Math.min(p,l))},h=[{time:e[0].time,value:e[0].pose[t]}],u=(f,p,g)=>{const m=h[h.length-1];if(f<=m.time+ws){h[h.length-1]={...m,value:p,...g?{easing:g}:{}};return}h.push({time:f,value:p,...g?{easing:g}:{}})};let d=e[0].pose[t];for(let f=1;f<e.length;f++){const p=e[f],g=e[f-1].pose[t],m=p.pose[t],w=m-g,v=h[h.length-1].time,k=p.act!==!1;if(Math.abs(w)<=Hn){const $=p.time+(k?c(f):0);if(f===e.length-1)Math.abs(d-m)>Hn&&u(Math.max($,v+vc),m,"ease-in-out"),d=m;else if(k&&a&&s.drift>0&&n.drift.includes(t)&&$-v>=vS){const A=ne(`${i}:${t}:${f}`)%2===0?1:-1;d=m+A*s.drift*r,u($,d,"ease-in-out")}continue}if(!k){u(e[f-1].time,d),u(p.time,m,p.easing),d=m;continue}const y=c(f),x=Math.max(e[f-1].time+y,v);let P=p.time+y;o&&s.eyeDart>0&&(P=Math.min(P,x+s.eyeDart));const M=P-x;if(M<=ws){u(p.time,m,p.easing),d=m;continue}u(x,d);const T=Math.sign(w);if(a&&s.anticipation>0&&r>0&&M>=vc){const $=d-T*Math.min(Math.abs(w)*s.anticipation,r),A=x+M*s.anticipationTime;u(A,$,"ease-in-out"),s.hold>0&&u(A+M*s.hold,$)}const S=f+1<e.length?e[f+1].time-p.time:1/0,E=Math.min(s.settle,S/2);if(a&&s.overshoot>0&&r>0&&M>=kS&&E>ws){const $=Math.min(Math.abs(w)*s.overshoot,r);u(P,m+T*$,p.easing??s.actionEase),u(P+E,m,s.settleEase)}else u(P,m,p.easing??s.actionEase);d=m}return h}function xS(t,e,n,s,i){const o=[],r=Mc+MS;for(let f=1;f<t.length;f++){const p=t[f-1].pose,g=t[f].pose;Object.entries(e.headTurns).some(([w,v])=>Math.abs((g[w]??0)-(p[w]??0))>v)&&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+wr*.6,u=0;for(;h<l;){c.some(g=>Math.abs(g-h)<wr/2)||o.push(h);const p=(ne(`${s}:blink:${u++}`)%1e3/1e3-.5)*(wr*.66);h+=wr+p}o.sort((f,p)=>f-p);const d=[{time:a,value:i}];for(const f of o){const p=d[d.length-1].time;f+Mc<=p+ws||(f>p+ws&&d.push({time:f,value:i}),d.push({time:f+Mc,value:1,easing:"ease-in"}),d.push({time:f+r,value:i,easing:"ease-out"}))}return d.length>1?d:[]}function TS(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+ws||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<vc||t[l].act===!1)){if(c<=Hn&&h>Hn)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>Hn&&h<=Hn){const p=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,p/2),n,{type:"back",mode:"out",overshoot:1.4})}}}return r.length>1?r:[]}const wp={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 ES(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 AS(){const t={},e={};for(const n of Object.keys(lt)){const s=ES(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 kp=AS();function vp(t,e){return Object.entries(e).map(([n,s])=>({id:`${t}-${n}`,target:t,property:n,keyframes:s}))}function Mp(t,e,n={}){const s=To(e),i=e.map((o,r)=>({time:o.time,pose:{...s[r]},easing:o.easing,act:o.act}));return vp(t,kr(i,n.rig??wp,n))}function Sp(t,e,n={}){const s=n.rest??lt,i=Dl(e,s),o=e.map((r,a)=>({time:r.time,pose:{...s,...i[a]},easing:r.easing,act:r.act}));return vp(t,kr(o,n.rig??kp,n))}const xp=vt.shocked,$S=vt.scared,en={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,...xp,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,...vt.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,...xp,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,...vt.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:ut.leftHip,rightHip:ut.rightHip,leftKnee:0,rightKnee:0},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...$S,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:{...ae.sad,bend:18,stretch:.92,lean:t.lean+5,turn:t.turn,sit:t.sit},easing:"ease-in-out"}]};function Sc(t,e){const n=typeof e.from=="string"?ae[e.from]:e.from??ut;return xc(en[t](n),{...e,from:n})}function xc(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 Ii(t,e=1){const n=en[t](ut);return n[n.length-1].after*e}function Tp(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,p=d.y-u.y,g=Math.hypot(f,p)||1,m=-p/g,w=f/g,v=1-h/(e.length-1);t.globalAlpha=r*(1-v),t.lineWidth=o*(1-v*.7),t.beginPath(),t.moveTo(u.x+m*l,u.y+w*l),t.lineTo(d.x+m*l,d.y+w*l),t.stroke()}}t.restore()}const PS={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 IS(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 p=l+(n.time-l)*f/(a-1);c.push(tl(e,{time:p,state:o(p)},s).joints)}const h=c[c.length-1].height,u=(i.threshold??1.2)*h,d=(i.parts??["hands","toes","head"]).flatMap(f=>PS[f]);for(const f of d){const p=c.map(f.at);let g=0;for(let v=1;v<p.length;v++)g+=Math.hypot(p[v].x-p[v-1].x,p[v].y-p[v-1].y);const m=g/((n.time-l)/1e3);if(m<=u)continue;const w=Math.min(1,(m-u)/(u*.5));Tp(t,p,{...i,opacity:(i.opacity??.7)*w,spacing:i.spacing??h*.02})}}function Ep(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=ne(`${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 OS(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;_S(t,h,u,i*.14,n*Math.PI+a),t.stroke()}t.restore()}function _S(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 Oi={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 Tc(t={}){return[...Object.keys(Yt),...Object.keys(ae),...Object.keys(en),...Object.keys(Oi),...Object.keys(t.gaits??{}),...Object.keys(t.actions??{})]}function Ec(t={}){const e=new Set(Tc()),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 Ac(t={}){const e={};for(const n of Object.keys(Yt))e[n]=`Walks to \`to\` in the ${n} gait, feet planted, turning round first if needed.`;for(const n of Object.keys(ae))e[n]=`Moves into the ${n} pose and holds it.`;for(const n of Object.keys(en))e[n]=`The ${n} gag, built on the current pose.`;for(const[n,s]of Object.entries(Oi))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 vr=["do","at","for","to","toward","mood","say","pose","target","onto"],CS={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"},Mr=["viewer","ahead","back"],Rn=t=>typeof t=="number"&&Number.isFinite(t);function _i(t,e={}){const n=Ec(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=Tc(e),i=l=>l in Yt||l in(e.gaits??{}),o=Object.keys(vt),r=Object.keys(ut);let a=-1/0;return t.forEach((l,c)=>{const h=g=>n.push({level:"error",beat:c,message:g}),u=g=>n.push({level:"warning",beat:c,message:g});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 g of Object.keys(d))vr.includes(g)||h(ft("beat field",g,vr,CS[g.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 p=Oi[f]??e.actions?.[f];for(const g of p?.needs??[])d[g]===void 0&&h(`\`${f}\` needs \`${g}\`.`);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[g,m]of Object.entries(d.pose))r.includes(g)?Rn(m)||h(`Pose joint \`${g}\` must be a number (got ${JSON.stringify(m)}).`):h(ft("pose joint",g,r));for(const g of["at","for"]){const m=d[g];m!==void 0&&!(Rn(m)&&m>=0)&&h(`\`${g}\` is milliseconds, a number ≥ 0 (got ${JSON.stringify(m)}).`)}Rn(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 g of["to","onto"]){const m=d[g];m!==void 0&&!Rn(m)&&h(`\`${g}\` is a scene ${g==="to"?"x":"y"} in px, a number (got ${JSON.stringify(m)}).`)}if(d.toward!==void 0&&!Rn(d.toward)&&!Mr.includes(d.toward)&&h(`\`toward\` is a scene x or one of ${Mr.join(", ")}${typeof d.toward=="string"&&Ys(d.toward,Mr)?` (did you mean "${Ys(d.toward,Mr)}"?)`:""} (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 g=d.target;(!g||typeof g!="object"||!Rn(g.x)||!Rn(g.y))&&h("`target` is a point or box in scene px: { x, y } (a code panel’s line(), token() or spot() fits).")}}),n}function $c(t,e={},n="scriptTracks"){const s=_i(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
- `)}`)}I2(Tc);function OS(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 _S(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 Ep=8;function vr(t,e={},n=0){if(n>Ep)throw new Error(`scriptTracks: custom actions nest more than ${Ep} 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 vr(o,e,n+1)})}function Ap(t){return t.length===0?0:Math.max(...t.map(e=>e.after))}const Ac={walk:1e3,bouncy:900,doubleBounce:1100,sneak:1600,strut:1100,tired:1500,shove:1300,run:560},CS=450,HS=2.4,RS=160,$p=2.5,LS=200,FS=340,NS=1.1,Pp=[380,900],WS=.35,Mr=300,$c=150,DS=260,BS=1.2,Pc=160,Ip=400,Oi=300,zS=450,Op=500,Ic=350,_p=150,qS=120,Oc=180,Cp=420,jS=300,Hp=300,YS=140,_c=150,Rp=450,KS=450,Cc=150,Lp=350,Fp=400,XS=12,GS=600,Np=90,Wp=400,US=200,VS=.09,Dp=350,He=450,Hc=1200,JS=700,ks=320,Re=220,ZS=65,QS=700,Bp=t=>t in en,t3=t=>t in ae;function zp(t){return Math.max(QS,Array.from(t).length*ZS)}function Sr(t,e,n={}){const s={actions:n.actions,gaits:n.gaits};Ec(e,s);const i=n.gait??"walk",o=vr(e,n.actions).map(_=>_.do==="go"?{..._,do:i}:_);Ec(o,s,"scriptTracks (after expanding custom actions)");const r=_=>Yt[_]??n.gaits?.[_],a=_=>Ac[_]??n.gaits?.[_]?.cycle??1e3,l=_=>{const B=n.actions?.[_];return B&&"steps"in B?B:void 0},c=n.from??0,h=n.ground??0,u=n.height??300;let d=c,f=h,p=n.facing??1,g=n.start??ut,m=0,w=0;const v=[{time:0,pose:g}],k=[{time:0,value:0}],y=[{time:0,value:0}],x=[{time:0,value:0}],P=[{time:0,value:0}],M=[{time:0,value:"walk"}],T=[{time:0,value:p}],S=[],E=[],$=[],A=(_,B,Q,O)=>{g={...g,...B},Q&&(g=Xe(g,Q)),v.push({time:_,pose:g,...O===!1?{act:O}:{}})},I=(_,B,Q)=>(A(_+ks/2,{turn:0},Q),T.push({time:_+ks/2,value:p},{time:_+ks/2+1,value:B}),p=B,A(_+ks,{turn:1}),_+ks),C=_=>_<d?-1:1,D=(_,B,Q)=>C(B)!==p?I(_,C(B),Q):_,j=(_,B,Q,O="arm")=>{const R=O==="arm",z=me({..._,...R?{rightShoulder:0,rightElbow:0}:{rightHip:0,rightKnee:0}},{height:u,facing:p}),K=R?z.shoulders.right:z.hip,N=R?z.elbows.right:z.knees.right,q=(X,tt)=>Math.atan2(p*X,tt)*180/Math.PI,J=((q(B-(d+K.x),Q-(f+K.y))-q(N.x-K.x,N.y-K.y))%360+360)%360;return J>270?J-360:J},V=(_,B,Q,O)=>{const R=O==="arm",z=me({..._,...R?{rightShoulder:90,rightElbow:0,rightWrist:0}:{rightHip:90,rightKnee:0}},{height:u,facing:p}),K=R?z.shoulders.right:z.hip,N=R?{x:(z.hands.right.x+z.fingertips.right.x)/2,y:(z.hands.right.y+z.fingertips.right.y)/2}:z.feet.right,q=Math.hypot(N.x-K.x,N.y-K.y)*((R?n.reach?.arm:n.reach?.leg)??1),Y=Q-(f+K.y),J=Math.abs(Y)<q?Math.sqrt(q*q-Y*Y):q*.1;return B-K.x-p*J},et=_=>{const B=me(_,{height:u,facing:p});return{x:d+(B.hands.right.x+B.fingertips.right.x)/2,y:f+(B.hands.right.y+B.fingertips.right.y)/2}},G=(_,B,Q)=>{const O={..._,rightWrist:0,rightElbow:0,rightShoulder:j(_,B,Q)},R=me(O,{height:u,facing:p}),z={x:d+R.shoulders.right.x,y:f+R.shoulders.right.y},K={x:d+R.elbows.right.x,y:f+R.elbows.right.y},N=et(O),q=Math.hypot(K.x-z.x,K.y-z.y),Y=Math.hypot(N.x-K.x,N.y-K.y),J=Math.min(q+Y-.01,Math.max(Math.abs(q-Y)+.01,Math.hypot(B-z.x,Q-z.y))),X=ot=>ot*180/Math.PI,tt=X(Math.acos((q*q+J*J-Y*Y)/(2*q*J))),nt=180-X(Math.acos((q*q+Y*Y-J*J)/(2*q*Y)));let L={rightShoulder:O.rightShoulder,rightElbow:0},U=1/0;for(const ot of[1,-1])for(const at of[1,-1]){const it={rightShoulder:O.rightShoulder+ot*tt,rightElbow:at*nt},ct={..._,rightWrist:0,...it},st=et(ct),rt=Math.hypot(st.x-B,st.y-Q)-me(ct,{height:u,facing:p}).elbows.right.y*.001;rt<U&&(U=rt,L=it)}return L},F=(_,B,Q)=>Math.abs(B-d)<2?_:(k.push({time:_,value:d-c},{time:_+Q,value:B-c,easing:"ease-in-out"}),d=B,_+Q);for(const _ of o){const B=Math.max(_.at??w,w===0?0:v[v.length-1].time);let Q=B,O,R;const z=_.pose??{},K=l(_.do);if(r(_.do)){const N=_.to??d,q=N===d?p:C(N);let Y=B;q!==p?Y=I(B,q,_.mood):g.turn<1?(Y=B+Re,A(Y,{turn:1,...z},_.mood)):(_.mood||_.pose)&&A(B+Re,z,_.mood);const X=Math.abs(N-d)/ko(r(_.do),u),tt=_.for??Math.max(Re*2,X*a(_.do)),nt=Y+tt;M.push({time:Y,value:_.do}),P.push({time:Y,value:0},{time:Y+Re,value:1,easing:"ease-out"}),P.push({time:nt-Re,value:1},{time:nt,value:0,easing:"ease-in"}),x.push({time:Y,value:m},{time:nt,value:m+X}),k.push({time:Y,value:d-c},{time:nt,value:N-c}),m+=X,d=N,A(nt,{}),Q=nt}else if(_.do==="zip"){const N=_.to??d,q=N===d?p:C(N);let Y=B;q!==p?Y=I(B,q,_.mood):g.turn<1&&(Y=B+Re,A(Y,{turn:1},_.mood));const J=vc("windUp",{at:Y,from:_.mood?Xe(g,_.mood):g});v.push(...J),g=J[J.length-1].pose;const X=Y+$i("windUp"),tt=X+CS,nt=tt+Math.max(RS,Math.abs(N-d)/HS);M.push({time:X,value:"run"}),P.push({time:X,value:0},{time:X+80,value:1,easing:"ease-out"},{time:nt,value:1},{time:nt+120,value:0}),x.push({time:X,value:m},{time:tt,value:m+$p,easing:"ease-in"}),m+=$p+(nt-tt)/Ac.run*1.5,x.push({time:nt,value:m}),k.push({time:tt,value:d-c},{time:nt,value:N-c,easing:"ease-in"}),$.push({kind:"dust",time:tt,x:d,y:f,length:900}),d=N,A(nt,{}),Q=nt}else if(_.do==="leap"){const N=_.to??d,q=_.onto??f;let Y=N===d?B:D(B,N,_.mood);g.turn<1&&(Y+=Re,A(Y,{turn:1},_.mood));const J={leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50};A(Y+LS,{stretch:.75,bend:12,leftHip:22,rightHip:22,...J},_.mood,!1);const X=Y+FS;A(X-40,{stretch:.72},void 0,!1),A(X,{stretch:1.2,bend:-6,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4},void 0,!1);const tt=Math.hypot(N-d,q-f),nt=_.for??Math.min(Pp[1],Math.max(Pp[0],300+tt*NS)),L=Math.min(f,q)-WS*u,U=Math.sqrt(f-L),ot=Math.sqrt(q-L),at=X+nt*U/(U+ot),it=X+nt;A(at,{stretch:1,bend:4,leftHip:-55,leftKnee:-80,rightHip:55,rightKnee:80,leftShoulder:110,rightShoulder:110},void 0,!1),A(it,{stretch:.72,bend:12,leftShoulder:75,rightShoulder:75,leftElbow:0,rightElbow:0,leftHip:18,rightHip:18,leftKnee:0,rightKnee:0},void 0,!1),A(it+180,{stretch:1.05,bend:-3},void 0,!1),A(it+340,{stretch:1,bend:0,leftHip:ut.leftHip,rightHip:ut.rightHip,leftShoulder:ut.leftShoulder,rightShoulder:ut.rightShoulder,leftElbow:ut.leftElbow,rightElbow:ut.rightElbow},void 0,!1),k.push({time:X,value:d-c},{time:it,value:N-c}),y.push({time:X,value:f-h},{time:at,value:L-h,easing:"ease-out-quad"},{time:it,value:q-h,easing:"ease-in-quad"}),d=N,f=q,$.push({kind:"dust",time:it,x:d,y:f,length:500}),Q=it+340,O=it}else if(_.do==="point"&&_.target){const N=_.target,q=D(B,N.x,_.mood),Y={...g,..._.mood?vt[_.mood]:{},turn:Math.max(g.turn,.6),rightElbow:0,rightWrist:0,...z},J=me(Y,{height:u,facing:p}).head.center,X=Math.abs(N.x-(d+J.x)),tt=N.y-(f+J.y),nt=q+He;A(nt,{...Y,rightShoulder:j(Y,N.x,N.y),lookX:1,lookY:e3(tt/Math.max(1,Math.hypot(X,tt)))*.8}),Q=nt+(_.for??Hc),O=nt,R=Q}else if(_.do==="swipe"){const N=_.target??{x:d+p*u*.5,y:f-u*.6},q=C(N.x),Y=D(B,N.x,_.mood),J=q===1?N.left??N.x:N.right??N.x,X=q===1?N.right??N.x:N.left??N.x,tt={...g,turn:1,lean:-10,bend:-8,rightElbow:40,lookX:1,...z};A(Y+Mr,{...tt,rightShoulder:j(tt,d-p*u*.3,f-u*1.1)},_.mood,!1);const nt={...g,lean:6,bend:4,rightElbow:0,rightWrist:0},L={...g,lean:14,bend:12,rightElbow:0,rightWrist:0};F(Y,V(nt,J,N.y,"arm"),Mr+$c),A(Y+Mr+$c,{lean:-12},void 0,!1);const U=Y+Mr+$c+80;A(U,{...nt,rightShoulder:j(nt,J,N.y)},void 0,!1);const ot=U+(_.for??Math.max(DS,Math.abs(X-J)/BS));k.push({time:U,value:d-c}),d=V(L,X,N.y,"arm"),k.push({time:ot,value:d-c}),A(ot,{...L,rightShoulder:j(L,X,N.y)},void 0,!1),A(ot+Pc,{lean:16,bend:14,rightShoulder:j(g,X+q*u*.4,N.y+u*.25)},void 0,!1),A(ot+Pc+Ip,{lean:0,bend:0,rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow}),Q=ot+Pc+Ip,O=U,R=ot}else if(_.do==="grab"&&_.target){const N=_.target,q=D(B,N.x,_.mood),Y=N.y>f-u*.5,J={...g,turn:1,rightElbow:0,bend:Y?35:0,lean:Y?12:0,stretch:Y?.75:1,lookX:1,lookY:Y?.8:0,...z},tt=F(q,V(J,N.x,N.y,"arm"),Oi)+zS;A(tt,{...J,rightShoulder:j(J,N.x,N.y)},_.mood,!1),A(tt+120,{},void 0,!1),A(tt+Op,{bend:0,lean:-3,stretch:1,rightShoulder:165,rightElbow:20,lookY:-.6}),Q=tt+Op+150,O=tt}else if(_.do==="throw"){const N=_.target?.x??_.to??d+p*u,q=D(B,N,_.mood),Y={...g,turn:1,lean:-12,bend:-10,rightElbow:60,stretch:.95,lookX:1,lookY:-.3,...z};A(q+Ic,{...Y,rightShoulder:j(Y,d-p*u*.4,f-u*1.05)},_.mood,!1),A(q+Ic+_p,{lean:-14},void 0,!1);const J=q+Ic+_p+qS,X={...g,lean:14,bend:12,rightElbow:0,stretch:1.04};v.push({time:J,pose:g={...X,rightShoulder:j(X,d+p*u,f-u*1.1)},easing:"ease-in",act:!1}),A(J+Oc,{lean:18,bend:14,rightShoulder:55,stretch:1},void 0,!1),A(J+Oc+Cp,{lean:0,bend:0,rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow,lookY:0}),Q=J+Oc+Cp,O=J,R=J}else if(_.do==="kick"&&_.target){const N=_.target,q=D(B,N.x,_.mood),Y={...g,turn:1,lean:-12,bend:-6,rightKnee:0,leftShoulder:100,rightShoulder:70},J=F(q,V(Y,N.x,N.y,"leg"),jS),X={leftShoulder:70,rightShoulder:50,leftElbow:-20,rightElbow:20};A(J+Hp,{turn:1,lean:8,bend:6,rightHip:-40,rightKnee:80,lookX:1,lookY:.7,...X,...z},_.mood,!1);const tt=J+Hp+YS,nt=j(Y,N.x,N.y,"leg");v.push({time:tt,pose:g={...g,...Y,rightHip:nt},easing:"ease-in",act:!1}),A(tt+_c,{lean:-15,rightHip:nt+20},void 0,!1),A(tt+_c+Rp,{lean:0,bend:0,rightHip:ut.rightHip,rightKnee:0,leftShoulder:ut.leftShoulder,rightShoulder:ut.rightShoulder,leftElbow:ut.leftElbow,rightElbow:ut.rightElbow,lookY:0}),Q=tt+_c+Rp,O=tt}else if(_.do==="put"&&_.target){const N=_.target,q=D(B,N.x,_.mood),Y=N.y>f-u*.5,J={...g,turn:1,rightElbow:0,rightWrist:0,bend:Y?35:0,lean:Y?12:0,stretch:Y?.75:1,lookX:1,lookY:Y?.8:0,...z},tt=F(q,V(J,N.x,N.y,"arm"),Oi)+KS;A(tt,{...J,rightShoulder:j(J,N.x,N.y)},_.mood,!1),A(tt+Cc,{},void 0,!1),A(tt+Cc+Lp,{bend:0,lean:0,stretch:1,rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow,lookY:0}),Q=tt+Cc+Lp,O=tt}else if(_.do==="write"&&_.target){const N=_.target,q=N.left??N.x,Y=N.right??N.x,J=D(B,(q+Y)/2,_.mood),X={...g,turn:1,rightElbow:0,rightWrist:0,...vt.thinking,lookX:1,lookY:0,...z},tt=st=>V(X,st,N.y,"arm")+p*u*.08,nt=st=>{const Z=et({...X,...G(X,st,N.y),rightWrist:0});return Math.hypot(Z.x-st,Z.y-N.y)<2},L=p===1?q:Y,U=F(J,tt((q+Y)/2),Oi),ot=!nt(q)||!nt(Y),at=ot?F(U,tt(q),Oi)+Fp:U+Fp;A(at,{...X,...G(X,ot?q:L,N.y)},_.mood,!1);const it=_.for??Math.max(GS,Math.abs(Y-q)*XS);ot&&k.push({time:at,value:d-c});for(let st=Np,Z=0;st<=it;st+=Np,Z++){const rt=q+(Y-q)*Math.min(st,it)/it;ot&&(d=tt(rt),k.push({time:at+st,value:d-c}));const ht=(Z%2===0?-1:1)*u*.02;A(at+st,G(X,rt,N.y+ht),void 0,!1)}const ct=at+it;A(ct,G(X,Y,N.y),void 0,!1),A(ct+Wp,{rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow,...vt.happy}),Q=ct+Wp,O=at,R=ct}else if(_.do==="push"&&_.target){const N=_.target,q=_.to??N.x,Y=D(B,d+(q>=N.x?1:-1),_.mood),J=p===1?N.left??N.x:N.right??N.x,X={...g,turn:1,lean:16,bend:8,rightWrist:0,leftWrist:0,lookX:1,...z},tt=V(X,J,N.y,"arm"),nt=F(Y,tt+p*u*.06,Oi),L=G(X,J,N.y),U={...X,...L,leftShoulder:-L.rightShoulder,leftElbow:-L.rightElbow},ot=nt+US;A(ot,U,_.mood,!1);const at=Math.abs(q-N.x),it=ot+(_.for??Math.max(600,at/VS)),ct=at/ko("shove",u);M.push({time:ot,value:"shove"}),P.push({time:ot,value:0},{time:ot+Re,value:1,easing:"ease-out"},{time:it-Re,value:1},{time:it,value:0,easing:"ease-in"}),x.push({time:ot,value:m},{time:it,value:m+ct}),m+=ct,k.push({time:ot,value:d-c},{time:it,value:d+(q-N.x)-c}),d+=q-N.x,A(it,{},void 0,!1),A(it+Dp,{lean:0,bend:0,rightShoulder:ut.rightShoulder,leftShoulder:ut.leftShoulder,rightElbow:ut.rightElbow,leftElbow:ut.leftElbow}),Q=it+Dp,O=ot,R=it}else if(K){const N=_.mood?Xe(g,_.mood):g,q=K.steps(N,_),Y=Mc(q,{at:B,from:N});v.push(...Y),g=Y[Y.length-1].pose,Q=B+Math.max(Ap(q),_.for??0)}else if(Bp(_.do)){const N=vc(_.do,{at:B,from:_.mood?Xe(g,_.mood):g});v.push(...N),g=N[N.length-1].pose,Q=B+$i(_.do),_.do==="take"&&$.push({kind:"dust",time:B+900,x:d,y:f,length:500}),_.do==="land"&&$.push({kind:"dust",time:B+120,x:d,y:f,length:500})}else if(_.do==="look"||_.do==="face"){const N=_.toward??"viewer",q=_.for??JS;if(N==="viewer")A(B+He,{turn:0,lookX:0,lookY:0,...z},_.mood);else if(N==="ahead")A(B+He,{turn:_.do==="face"?1:.6,lookX:1,...z},_.mood);else if(N==="back")A(B+He,{turn:.2,lookX:-1,...z},_.mood);else{const Y=C(N);Y!==p&&_.do==="face"?(I(B,Y,_.mood),A(B+ks+1,{lookX:1,...z})):Y!==p?A(B+He,{turn:.25,lookX:-1,...z},_.mood):A(B+He,{turn:_.do==="face"?1:.6,lookX:1,...z},_.mood)}Q=B+Math.max(q,He)}else if(t3(_.do)||_.do==="stand"){const N=_.do==="stand"?n.rest??ut:ae[_.do],q=N.turn!==ut.turn?N.turn:g.turn,Y=_.mood?vt[_.mood]:{lookX:g.lookX,lookY:g.lookY};A(B+He,{...N,turn:q,...Y,...z}),Q=B+(_.for??Hc)}else{const N=_.for??(_.say?zp(_.say):Hc);(_.mood||_.pose)&&A(B+Math.min(He,N/2),z,_.mood),Q=B+N}if(_.say){const N=r(_.do)||Bp(_.do)||K?B:B+Math.min(150,(Q-B)/4),q=r(_.do)?Q:Math.max(N+200,Q-100);S.push({text:_.say,start:N,end:q}),_.do==="say"&&i3(v,g,N,q)}_.onto!==void 0&&_.do!=="leap"&&_.onto!==f&&(y.push({time:B,value:f-h},{time:Q,value:_.onto-h,easing:"ease-in-out"}),f=_.onto),Q>v[v.length-1].time&&v.push({time:Q,pose:g}),E.push({start:B,end:Q,...O!==void 0?{contact:O}:{},...R!==void 0?{release:R}:{}}),w=Q}const H=vp(t,s3(v),n),W=[{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:x},{id:`${t}-walking`,target:t,property:"walking",keyframes:P},{id:`${t}-gait`,target:t,property:"gait",keyframes:M},{id:`${t}-facing`,target:t,property:"facing",keyframes:T}].filter(_=>_.keyframes.length>1||_.property==="x"||_.property==="facing"&&_.keyframes[0].value===-1);return{tracks:[...lr(t,H,S,{energy:n.energy}),...W],duration:w,lines:S,keys:v,beats:E,effects:$}}const e3=t=>Math.max(-1,Math.min(1,t)),n3=30;function s3(t){const e=[];for(const n of t){const s=e[e.length-1];s&&n.time-s.time<n3?e[e.length-1]={...n,time:s.time}:e.push(n)}return e}function i3(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 Rc(t,e,n){const s=new Ht({id:`${t}-hand`,tracks:e.filter(l=>l.target===t)}),i=Ja({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}=Za(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}const vs=["start","contact","release","end"],o3=["surface","edit","anchor","at","until"],r3=["carry"],xr=t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&"surface"in t&&"anchor"in t,a3=t=>t.then===void 0?[]:Array.isArray(t.then)?t.then:[t.then];function l3(t,e,n,s={}){const i=qp(n,e,s).filter(d=>d.level==="error");if(i.length>0)throw new Error(`surfaceScript: ${i.length} problem(s) in the beats:
58
+ `)}`)}C2(Ac);function HS(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 RS(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 Ap=8;function Sr(t,e={},n=0){if(n>Ap)throw new Error(`scriptTracks: custom actions nest more than ${Ap} 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 Sr(o,e,n+1)})}function $p(t){return t.length===0?0:Math.max(...t.map(e=>e.after))}const Pc={walk:1e3,bouncy:900,doubleBounce:1100,sneak:1600,strut:1100,tired:1500,shove:1300,run:560},LS=450,FS=2.4,NS=160,Pp=2.5,WS=200,DS=340,BS=1.1,Ip=[380,900],zS=.35,xr=300,Ic=150,qS=260,jS=1.2,Oc=160,Op=400,Ci=300,YS=450,_p=500,_c=350,Cp=150,KS=120,Cc=180,Hp=420,XS=300,Rp=300,GS=140,Hc=150,Lp=450,US=450,Rc=150,Fp=350,Np=400,VS=12,JS=600,Wp=90,Dp=400,ZS=200,QS=.09,Bp=350,Re=450,Lc=1200,t3=700,ks=320,Le=220,e3=65,n3=700,zp=t=>t in en,s3=t=>t in ae;function qp(t){return Math.max(n3,Array.from(t).length*e3)}function Tr(t,e,n={}){const s={actions:n.actions,gaits:n.gaits};$c(e,s);const i=n.gait??"walk",o=Sr(e,n.actions).map(_=>_.do==="go"?{..._,do:i}:_);$c(o,s,"scriptTracks (after expanding custom actions)");const r=_=>Yt[_]??n.gaits?.[_],a=_=>Pc[_]??n.gaits?.[_]?.cycle??1e3,l=_=>{const B=n.actions?.[_];return B&&"steps"in B?B:void 0},c=n.from??0,h=n.ground??0,u=n.height??300;let d=c,f=h,p=n.facing??1,g=n.start??ut,m=0,w=0;const v=[{time:0,pose:g}],k=[{time:0,value:0}],y=[{time:0,value:0}],x=[{time:0,value:0}],P=[{time:0,value:0}],M=[{time:0,value:"walk"}],T=[{time:0,value:p}],S=[],E=[],$=[],A=(_,B,Q,O)=>{g={...g,...B},Q&&(g=Xe(g,Q)),v.push({time:_,pose:g,...O===!1?{act:O}:{}})},I=(_,B,Q)=>(A(_+ks/2,{turn:0},Q),T.push({time:_+ks/2,value:p},{time:_+ks/2+1,value:B}),p=B,A(_+ks,{turn:1}),_+ks),C=_=>_<d?-1:1,D=(_,B,Q)=>C(B)!==p?I(_,C(B),Q):_,j=(_,B,Q,O="arm")=>{const R=O==="arm",z=me({..._,...R?{rightShoulder:0,rightElbow:0}:{rightHip:0,rightKnee:0}},{height:u,facing:p}),K=R?z.shoulders.right:z.hip,N=R?z.elbows.right:z.knees.right,q=(X,tt)=>Math.atan2(p*X,tt)*180/Math.PI,J=((q(B-(d+K.x),Q-(f+K.y))-q(N.x-K.x,N.y-K.y))%360+360)%360;return J>270?J-360:J},V=(_,B,Q,O)=>{const R=O==="arm",z=me({..._,...R?{rightShoulder:90,rightElbow:0,rightWrist:0}:{rightHip:90,rightKnee:0}},{height:u,facing:p}),K=R?z.shoulders.right:z.hip,N=R?{x:(z.hands.right.x+z.fingertips.right.x)/2,y:(z.hands.right.y+z.fingertips.right.y)/2}:z.feet.right,q=Math.hypot(N.x-K.x,N.y-K.y)*((R?n.reach?.arm:n.reach?.leg)??1),Y=Q-(f+K.y),J=Math.abs(Y)<q?Math.sqrt(q*q-Y*Y):q*.1;return B-K.x-p*J},et=_=>{const B=me(_,{height:u,facing:p});return{x:d+(B.hands.right.x+B.fingertips.right.x)/2,y:f+(B.hands.right.y+B.fingertips.right.y)/2}},G=(_,B,Q)=>{const O={..._,rightWrist:0,rightElbow:0,rightShoulder:j(_,B,Q)},R=me(O,{height:u,facing:p}),z={x:d+R.shoulders.right.x,y:f+R.shoulders.right.y},K={x:d+R.elbows.right.x,y:f+R.elbows.right.y},N=et(O),q=Math.hypot(K.x-z.x,K.y-z.y),Y=Math.hypot(N.x-K.x,N.y-K.y),J=Math.min(q+Y-.01,Math.max(Math.abs(q-Y)+.01,Math.hypot(B-z.x,Q-z.y))),X=ot=>ot*180/Math.PI,tt=X(Math.acos((q*q+J*J-Y*Y)/(2*q*J))),nt=180-X(Math.acos((q*q+Y*Y-J*J)/(2*q*Y)));let L={rightShoulder:O.rightShoulder,rightElbow:0},U=1/0;for(const ot of[1,-1])for(const at of[1,-1]){const it={rightShoulder:O.rightShoulder+ot*tt,rightElbow:at*nt},ct={..._,rightWrist:0,...it},st=et(ct),rt=Math.hypot(st.x-B,st.y-Q)-me(ct,{height:u,facing:p}).elbows.right.y*.001;rt<U&&(U=rt,L=it)}return L},F=(_,B,Q)=>Math.abs(B-d)<2?_:(k.push({time:_,value:d-c},{time:_+Q,value:B-c,easing:"ease-in-out"}),d=B,_+Q);for(const _ of o){const B=Math.max(_.at??w,w===0?0:v[v.length-1].time);let Q=B,O,R;const z=_.pose??{},K=l(_.do);if(r(_.do)){const N=_.to??d,q=N===d?p:C(N);let Y=B;q!==p?Y=I(B,q,_.mood):g.turn<1?(Y=B+Le,A(Y,{turn:1,...z},_.mood)):(_.mood||_.pose)&&A(B+Le,z,_.mood);const X=Math.abs(N-d)/Mo(r(_.do),u),tt=_.for??Math.max(Le*2,X*a(_.do)),nt=Y+tt;M.push({time:Y,value:_.do}),P.push({time:Y,value:0},{time:Y+Le,value:1,easing:"ease-out"}),P.push({time:nt-Le,value:1},{time:nt,value:0,easing:"ease-in"}),x.push({time:Y,value:m},{time:nt,value:m+X}),k.push({time:Y,value:d-c},{time:nt,value:N-c}),m+=X,d=N,A(nt,{}),Q=nt}else if(_.do==="zip"){const N=_.to??d,q=N===d?p:C(N);let Y=B;q!==p?Y=I(B,q,_.mood):g.turn<1&&(Y=B+Le,A(Y,{turn:1},_.mood));const J=Sc("windUp",{at:Y,from:_.mood?Xe(g,_.mood):g});v.push(...J),g=J[J.length-1].pose;const X=Y+Ii("windUp"),tt=X+LS,nt=tt+Math.max(NS,Math.abs(N-d)/FS);M.push({time:X,value:"run"}),P.push({time:X,value:0},{time:X+80,value:1,easing:"ease-out"},{time:nt,value:1},{time:nt+120,value:0}),x.push({time:X,value:m},{time:tt,value:m+Pp,easing:"ease-in"}),m+=Pp+(nt-tt)/Pc.run*1.5,x.push({time:nt,value:m}),k.push({time:tt,value:d-c},{time:nt,value:N-c,easing:"ease-in"}),$.push({kind:"dust",time:tt,x:d,y:f,length:900}),d=N,A(nt,{}),Q=nt}else if(_.do==="leap"){const N=_.to??d,q=_.onto??f;let Y=N===d?B:D(B,N,_.mood);g.turn<1&&(Y+=Le,A(Y,{turn:1},_.mood));const J={leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50};A(Y+WS,{stretch:.75,bend:12,leftHip:22,rightHip:22,...J},_.mood,!1);const X=Y+DS;A(X-40,{stretch:.72},void 0,!1),A(X,{stretch:1.2,bend:-6,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4},void 0,!1);const tt=Math.hypot(N-d,q-f),nt=_.for??Math.min(Ip[1],Math.max(Ip[0],300+tt*BS)),L=Math.min(f,q)-zS*u,U=Math.sqrt(f-L),ot=Math.sqrt(q-L),at=X+nt*U/(U+ot),it=X+nt;A(at,{stretch:1,bend:4,leftHip:-55,leftKnee:-80,rightHip:55,rightKnee:80,leftShoulder:110,rightShoulder:110},void 0,!1),A(it,{stretch:.72,bend:12,leftShoulder:75,rightShoulder:75,leftElbow:0,rightElbow:0,leftHip:18,rightHip:18,leftKnee:0,rightKnee:0},void 0,!1),A(it+180,{stretch:1.05,bend:-3},void 0,!1),A(it+340,{stretch:1,bend:0,leftHip:ut.leftHip,rightHip:ut.rightHip,leftShoulder:ut.leftShoulder,rightShoulder:ut.rightShoulder,leftElbow:ut.leftElbow,rightElbow:ut.rightElbow},void 0,!1),k.push({time:X,value:d-c},{time:it,value:N-c}),y.push({time:X,value:f-h},{time:at,value:L-h,easing:"ease-out-quad"},{time:it,value:q-h,easing:"ease-in-quad"}),d=N,f=q,$.push({kind:"dust",time:it,x:d,y:f,length:500}),Q=it+340,O=it}else if(_.do==="point"&&_.target){const N=_.target,q=D(B,N.x,_.mood),Y={...g,..._.mood?vt[_.mood]:{},turn:Math.max(g.turn,.6),rightElbow:0,rightWrist:0,...z},J=me(Y,{height:u,facing:p}).head.center,X=Math.abs(N.x-(d+J.x)),tt=N.y-(f+J.y),nt=q+Re;A(nt,{...Y,rightShoulder:j(Y,N.x,N.y),lookX:1,lookY:i3(tt/Math.max(1,Math.hypot(X,tt)))*.8}),Q=nt+(_.for??Lc),O=nt,R=Q}else if(_.do==="swipe"){const N=_.target??{x:d+p*u*.5,y:f-u*.6},q=C(N.x),Y=D(B,N.x,_.mood),J=q===1?N.left??N.x:N.right??N.x,X=q===1?N.right??N.x:N.left??N.x,tt={...g,turn:1,lean:-10,bend:-8,rightElbow:40,lookX:1,...z};A(Y+xr,{...tt,rightShoulder:j(tt,d-p*u*.3,f-u*1.1)},_.mood,!1);const nt={...g,lean:6,bend:4,rightElbow:0,rightWrist:0},L={...g,lean:14,bend:12,rightElbow:0,rightWrist:0};F(Y,V(nt,J,N.y,"arm"),xr+Ic),A(Y+xr+Ic,{lean:-12},void 0,!1);const U=Y+xr+Ic+80;A(U,{...nt,rightShoulder:j(nt,J,N.y)},void 0,!1);const ot=U+(_.for??Math.max(qS,Math.abs(X-J)/jS));k.push({time:U,value:d-c}),d=V(L,X,N.y,"arm"),k.push({time:ot,value:d-c}),A(ot,{...L,rightShoulder:j(L,X,N.y)},void 0,!1),A(ot+Oc,{lean:16,bend:14,rightShoulder:j(g,X+q*u*.4,N.y+u*.25)},void 0,!1),A(ot+Oc+Op,{lean:0,bend:0,rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow}),Q=ot+Oc+Op,O=U,R=ot}else if(_.do==="grab"&&_.target){const N=_.target,q=D(B,N.x,_.mood),Y=N.y>f-u*.5,J={...g,turn:1,rightElbow:0,bend:Y?35:0,lean:Y?12:0,stretch:Y?.75:1,lookX:1,lookY:Y?.8:0,...z},tt=F(q,V(J,N.x,N.y,"arm"),Ci)+YS;A(tt,{...J,rightShoulder:j(J,N.x,N.y)},_.mood,!1),A(tt+120,{},void 0,!1),A(tt+_p,{bend:0,lean:-3,stretch:1,rightShoulder:165,rightElbow:20,lookY:-.6}),Q=tt+_p+150,O=tt}else if(_.do==="throw"){const N=_.target?.x??_.to??d+p*u,q=D(B,N,_.mood),Y={...g,turn:1,lean:-12,bend:-10,rightElbow:60,stretch:.95,lookX:1,lookY:-.3,...z};A(q+_c,{...Y,rightShoulder:j(Y,d-p*u*.4,f-u*1.05)},_.mood,!1),A(q+_c+Cp,{lean:-14},void 0,!1);const J=q+_c+Cp+KS,X={...g,lean:14,bend:12,rightElbow:0,stretch:1.04};v.push({time:J,pose:g={...X,rightShoulder:j(X,d+p*u,f-u*1.1)},easing:"ease-in",act:!1}),A(J+Cc,{lean:18,bend:14,rightShoulder:55,stretch:1},void 0,!1),A(J+Cc+Hp,{lean:0,bend:0,rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow,lookY:0}),Q=J+Cc+Hp,O=J,R=J}else if(_.do==="kick"&&_.target){const N=_.target,q=D(B,N.x,_.mood),Y={...g,turn:1,lean:-12,bend:-6,rightKnee:0,leftShoulder:100,rightShoulder:70},J=F(q,V(Y,N.x,N.y,"leg"),XS),X={leftShoulder:70,rightShoulder:50,leftElbow:-20,rightElbow:20};A(J+Rp,{turn:1,lean:8,bend:6,rightHip:-40,rightKnee:80,lookX:1,lookY:.7,...X,...z},_.mood,!1);const tt=J+Rp+GS,nt=j(Y,N.x,N.y,"leg");v.push({time:tt,pose:g={...g,...Y,rightHip:nt},easing:"ease-in",act:!1}),A(tt+Hc,{lean:-15,rightHip:nt+20},void 0,!1),A(tt+Hc+Lp,{lean:0,bend:0,rightHip:ut.rightHip,rightKnee:0,leftShoulder:ut.leftShoulder,rightShoulder:ut.rightShoulder,leftElbow:ut.leftElbow,rightElbow:ut.rightElbow,lookY:0}),Q=tt+Hc+Lp,O=tt}else if(_.do==="put"&&_.target){const N=_.target,q=D(B,N.x,_.mood),Y=N.y>f-u*.5,J={...g,turn:1,rightElbow:0,rightWrist:0,bend:Y?35:0,lean:Y?12:0,stretch:Y?.75:1,lookX:1,lookY:Y?.8:0,...z},tt=F(q,V(J,N.x,N.y,"arm"),Ci)+US;A(tt,{...J,rightShoulder:j(J,N.x,N.y)},_.mood,!1),A(tt+Rc,{},void 0,!1),A(tt+Rc+Fp,{bend:0,lean:0,stretch:1,rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow,lookY:0}),Q=tt+Rc+Fp,O=tt}else if(_.do==="write"&&_.target){const N=_.target,q=N.left??N.x,Y=N.right??N.x,J=D(B,(q+Y)/2,_.mood),X={...g,turn:1,rightElbow:0,rightWrist:0,...vt.thinking,lookX:1,lookY:0,...z},tt=st=>V(X,st,N.y,"arm")+p*u*.08,nt=st=>{const Z=et({...X,...G(X,st,N.y),rightWrist:0});return Math.hypot(Z.x-st,Z.y-N.y)<2},L=p===1?q:Y,U=F(J,tt((q+Y)/2),Ci),ot=!nt(q)||!nt(Y),at=ot?F(U,tt(q),Ci)+Np:U+Np;A(at,{...X,...G(X,ot?q:L,N.y)},_.mood,!1);const it=_.for??Math.max(JS,Math.abs(Y-q)*VS);ot&&k.push({time:at,value:d-c});for(let st=Wp,Z=0;st<=it;st+=Wp,Z++){const rt=q+(Y-q)*Math.min(st,it)/it;ot&&(d=tt(rt),k.push({time:at+st,value:d-c}));const ht=(Z%2===0?-1:1)*u*.02;A(at+st,G(X,rt,N.y+ht),void 0,!1)}const ct=at+it;A(ct,G(X,Y,N.y),void 0,!1),A(ct+Dp,{rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow,...vt.happy}),Q=ct+Dp,O=at,R=ct}else if(_.do==="push"&&_.target){const N=_.target,q=_.to??N.x,Y=D(B,d+(q>=N.x?1:-1),_.mood),J=p===1?N.left??N.x:N.right??N.x,X={...g,turn:1,lean:16,bend:8,rightWrist:0,leftWrist:0,lookX:1,...z},tt=V(X,J,N.y,"arm"),nt=F(Y,tt+p*u*.06,Ci),L=G(X,J,N.y),U={...X,...L,leftShoulder:-L.rightShoulder,leftElbow:-L.rightElbow},ot=nt+ZS;A(ot,U,_.mood,!1);const at=Math.abs(q-N.x),it=ot+(_.for??Math.max(600,at/QS)),ct=at/Mo("shove",u);M.push({time:ot,value:"shove"}),P.push({time:ot,value:0},{time:ot+Le,value:1,easing:"ease-out"},{time:it-Le,value:1},{time:it,value:0,easing:"ease-in"}),x.push({time:ot,value:m},{time:it,value:m+ct}),m+=ct,k.push({time:ot,value:d-c},{time:it,value:d+(q-N.x)-c}),d+=q-N.x,A(it,{},void 0,!1),A(it+Bp,{lean:0,bend:0,rightShoulder:ut.rightShoulder,leftShoulder:ut.leftShoulder,rightElbow:ut.rightElbow,leftElbow:ut.leftElbow}),Q=it+Bp,O=ot,R=it}else if(K){const N=_.mood?Xe(g,_.mood):g,q=K.steps(N,_),Y=xc(q,{at:B,from:N});v.push(...Y),g=Y[Y.length-1].pose,Q=B+Math.max($p(q),_.for??0)}else if(zp(_.do)){const N=Sc(_.do,{at:B,from:_.mood?Xe(g,_.mood):g});v.push(...N),g=N[N.length-1].pose,Q=B+Ii(_.do),_.do==="take"&&$.push({kind:"dust",time:B+900,x:d,y:f,length:500}),_.do==="land"&&$.push({kind:"dust",time:B+120,x:d,y:f,length:500})}else if(_.do==="look"||_.do==="face"){const N=_.toward??"viewer",q=_.for??t3;if(N==="viewer")A(B+Re,{turn:0,lookX:0,lookY:0,...z},_.mood);else if(N==="ahead")A(B+Re,{turn:_.do==="face"?1:.6,lookX:1,...z},_.mood);else if(N==="back")A(B+Re,{turn:.2,lookX:-1,...z},_.mood);else{const Y=C(N);Y!==p&&_.do==="face"?(I(B,Y,_.mood),A(B+ks+1,{lookX:1,...z})):Y!==p?A(B+Re,{turn:.25,lookX:-1,...z},_.mood):A(B+Re,{turn:_.do==="face"?1:.6,lookX:1,...z},_.mood)}Q=B+Math.max(q,Re)}else if(s3(_.do)||_.do==="stand"){const N=_.do==="stand"?n.rest??ut:ae[_.do],q=N.turn!==ut.turn?N.turn:g.turn,Y=_.mood?vt[_.mood]:{lookX:g.lookX,lookY:g.lookY};A(B+Re,{...N,turn:q,...Y,...z}),Q=B+(_.for??Lc)}else{const N=_.for??(_.say?qp(_.say):Lc);(_.mood||_.pose)&&A(B+Math.min(Re,N/2),z,_.mood),Q=B+N}if(_.say){const N=r(_.do)||zp(_.do)||K?B:B+Math.min(150,(Q-B)/4),q=r(_.do)?Q:Math.max(N+200,Q-100);S.push({text:_.say,start:N,end:q}),_.do==="say"&&a3(v,g,N,q)}_.onto!==void 0&&_.do!=="leap"&&_.onto!==f&&(y.push({time:B,value:f-h},{time:Q,value:_.onto-h,easing:"ease-in-out"}),f=_.onto),Q>v[v.length-1].time&&v.push({time:Q,pose:g}),E.push({start:B,end:Q,...O!==void 0?{contact:O}:{},...R!==void 0?{release:R}:{}}),w=Q}const H=Mp(t,r3(v),n),W=[{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:x},{id:`${t}-walking`,target:t,property:"walking",keyframes:P},{id:`${t}-gait`,target:t,property:"gait",keyframes:M},{id:`${t}-facing`,target:t,property:"facing",keyframes:T}].filter(_=>_.keyframes.length>1||_.property==="x"||_.property==="facing"&&_.keyframes[0].value===-1);return{tracks:[...hr(t,H,S,{energy:n.energy}),...W],duration:w,lines:S,keys:v,beats:E,effects:$}}const i3=t=>Math.max(-1,Math.min(1,t)),o3=30;function r3(t){const e=[];for(const n of t){const s=e[e.length-1];s&&n.time-s.time<o3?e[e.length-1]={...n,time:s.time}:e.push(n)}return e}function a3(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 Fc(t,e,n){const s=new Ht({id:`${t}-hand`,tracks:e.filter(l=>l.target===t)}),i=Qa({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}=tl(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}const vs=["start","contact","release","end"],l3=["surface","edit","anchor","at","until"],c3=["carry"],Er=t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&"surface"in t&&"anchor"in t,h3=t=>t.then===void 0?[]:Array.isArray(t.then)?t.then:[t.then];function u3(t,e,n,s={}){const i=jp(n,e,s).filter(d=>d.level==="error");if(i.length>0)throw new Error(`surfaceScript: ${i.length} problem(s) in the beats:
59
59
  ${i.map(d=>` ${d.beat>=0?`beat ${d.beat}: `:""}${d.message}`).join(`
60
- `)}`);const o=n.map(d=>jp(d,e)),r=Sr(t,o,s),a=c3(o,r.beats,s),l=s.ground??0,c=d=>s.ride===!1?d:Object.values(e).reduce((f,p)=>p.ride(f,t,{ground:l}),d);n.forEach((d,f)=>{for(const p of a3(d)){const g=y=>new Error(`surfaceScript: beat ${f} (${d.do}), ${p.edit} on ${p.surface}: ${y}`),m=(y,x)=>{const P=typeof y=="object"?y.beat:f,M=(typeof y=="object"?y.at:y)??x??"start",T=a[P][M];if(T===void 0){const S=vs.filter(E=>a[P][E]!==void 0).join(", ");throw g(`beat ${P} (${n[P].do}) has no ${M} (it has ${S})`)}return T},w=e[p.surface],v=m(p.at??(a[f].contact!==void 0?"contact":"start")),k=p.until===void 0?void 0:m(p.until,"end");if(k!==void 0&&k<v)throw g(`it ends (${k} ms) before it starts (${v} ms)`);try{if(p.edit==="carry"){const x=w.piece(p.anchor),P=Rc(t,c(r.tracks),{x:s.from??0,y:l,style:s.figureStyle??(s.height?{height:s.height}:void 0),cast:s,start:v,end:k});w.follow(x,P);continue}const y=Object.fromEntries(Object.entries(p).filter(([x])=>!o3.includes(x)));w.edit(p.edit,p.anchor,{...y,at:v,...k!==void 0?{duration:k-v}:{}})}catch(y){throw g(y.message)}}});const h=c(r.tracks),u=Object.entries(e).flatMap(([d,f])=>f.tracks(d));return{...r,tracks:[...h,...u],figureTracks:h}}function qp(t,e,n={}){if(!Array.isArray(t))return Ii(t,n);const s=[],i=Object.keys(e),o=(c,h,u)=>{const d=typeof h=="string"?e[h]:void 0;return d||s.push({level:"error",beat:c,message:`${u}: ${ft("surface",h,i)}`}),d},r=(c,h,u,d)=>{if(typeof u!="string"){s.push({level:"error",beat:c,message:`${d}: \`anchor\` is a place name such as ${Object.keys(h.about.anchors).join(", ")} (got ${JSON.stringify(u)}).`});return}try{h.anchor(u,0)}catch(f){s.push({level:"error",beat:c,message:`${d}: ${f.message}`})}},a=(c,h,u)=>{const d=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:`${u}: \`beat\` is the index of this beat or a later one, ${c} to ${t.length-1} (got ${JSON.stringify(f)}).`}),d===void 0)return}typeof d=="number"?s.push({level:"error",beat:c,message:`${u}: a cue starts at a moment of its beat (${vs.join(", ")}), not at ms; set the beat's own \`at\` to move it.`}):(typeof d!="string"||!vs.includes(d))&&s.push({level:"error",beat:c,message:`${u}: ${ft("moment",d,vs)}`})};t.forEach((c,h)=>{if(!c||typeof c!="object"||Array.isArray(c))return;const u=c;for(const f of["target","to","onto"]){if(!xr(u[f]))continue;const p=u[f],g=o(h,p.surface,`\`${f}\``);g&&r(h,g,p.anchor,`\`${f}\``)}if(u.then===void 0)return;(Array.isArray(u.then)?u.then:[u.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 p=f,g=o(h,p.surface,"`then`");if(!g)return;const m=`\`then\` (${String(p.edit)} on ${String(p.surface)})`,w=[...Object.keys(g.about.edits),...r3];if(typeof p.edit!="string"||!w.includes(p.edit)){s.push({level:"error",beat:h,message:`\`then\`: ${ft("edit",p.edit,w)}`});return}for(const v of Array.isArray(p.anchor)?p.anchor:[p.anchor])r(h,g,v,m);p.edit==="carry"&&typeof p.anchor!="string"&&s.push({level:"error",beat:h,message:`${m}: \`carry\` takes one anchor, the piece it carries.`}),p.edit==="carry"&&p.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' }).`}),p.at!==void 0&&a(h,p.at,`${m} \`at\``),p.until!==void 0&&a(h,p.until,`${m} \`until\``),p.until!==void 0&&p.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)?jp(c,e,!0):c);return[...Ii(l,n),...s]}function jp(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 xr(t.target)&&(r.target=o(t.target)),xr(t.to)&&(r.to=o(t.to).x),xr(t.onto)&&(r.onto=o(t.onto).top),r}function c3(t,e,n){let s=0;return t.map(i=>{const o=vr([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 h3(t){const e={actions:t.actions,gaits:t.gaits},n=xc(e);if(n.length>0)throw new Error(`persona "${t.name}": ${n.join(" ")}`);const s=[...Object.keys(Yt),...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 vt))throw new Error(`persona "${t.name}": ${ft("mood",t.mood,Object.keys(vt))}`);const o=t.acting??"snappy";if(typeof o=="string"&&!(o in Cn))throw new Error(`persona "${t.name}": ${ft("acting style",o,Object.keys(Cn))}`);if(typeof t.stance=="string"&&!(t.stance in ae))throw new Error(`persona "${t.name}": ${ft("stance",t.stance,Object.keys(ae))}`);const r=t.height??120,a=typeof t.stance=="string"?ae[t.stance]:Dt(t.stance??{}),l=t.mood?Xe(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=>Ja({x:u.x,y:u.y,pose:l,style:{...c,...u.facing?{facing:u.facing}:{}},cast:e}),script:(u,d,f={})=>Sr(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=>Ii(u,e),handPath:(u,d,f)=>Rc(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:Tc(e),own:{actions:Object.keys(t.actions??{}),gaits:Object.keys(t.gaits??{})}})}}const u3=new Set(["x","y","walking","gait"]),Yp=.215+.205;function Kp(t,e,n=1){const{points:s}=fe(t,lt),i=s["hip.left"],o=s["knee.left"],r=s["ankle.left"],a=i&&o&&r?Math.hypot(o.x-i.x,o.y-i.y)+Math.hypot(r.x-o.x,r.y-o.y):Yp*t.height;return Xo(e,a/Yp,n)}function d3(t,e,n,s={}){const i=Sr(t,n,{...s,height:e.height,reach:s.reach??Xp(e)}),o=i.tracks.find(w=>w.property==="facing")?.keyframes??[],r=w=>{let v=s.facing??1;for(const k of o)k.time<=w&&(v=k.value);return v},a=So(i.keys),l=i.keys.map((w,v)=>{const k=dg(a[v]);return{time:w.time,pose:r(w.time)<0?Rd(k):k,...w.easing?{easing:w.easing}:{},...w.act===!1?{act:!1}:{}}}),{rest:c,start:h,...u}=s;p3(l,a,n,i,e,r,s);const d=Mp(t,l,u),f=lr(t,d,i.lines,{energy:s.energy}),p=i.tracks.filter(w=>u3.has(w.property)),g=i.tracks.find(w=>w.property==="walk");return{tracks:g?[...f,...p,v3(t,g,i.tracks,e,s)]:[...f,...p],duration:i.duration,lines:i.lines,keys:l,beats:i.beats,effects:i.effects}}function Xp(t){const e=kt({"arm.left.spread":90,"arm.left.elbow":0,"arm.left.bend":0,"leg.left.knee":0}),n=fe(t,e).points,s=Math.hypot(n["hand.left"].x-n["shoulder.left"].x,n["hand.left"].y-n["shoulder.left"].y),i=Math.hypot(n["toe.left"].x-n["hip.left"].x,n["toe.left"].y-n["hip.left"].y),o=me({...ut,rightShoulder:90,rightElbow:0,rightWrist:0},{height:t.height,facing:1}),r=me({...ut,rightHip:90,rightKnee:0},{height:t.height,facing:1}),a={x:(o.hands.right.x+o.fingertips.right.x)/2,y:(o.hands.right.y+o.fingertips.right.y)/2},l=Math.hypot(a.x-o.shoulders.right.x,a.y-o.shoulders.right.y),c=Math.hypot(r.feet.right.x-r.hip.x,r.feet.right.y-r.hip.y);return{arm:l>0?s/l:1,leg:c>0?i/c:1}}const f3={point:"arm",grab:"arm",put:"arm",write:"arm",swipe:"arm",push:"arm",kick:"leg"},g3=new Set(["point","grab","put","kick"]);function p3(t,e,n,s,i,o,r){const a=s.beats;if(n.length!==a.length)return;const l=new Ht({id:"placed",tracks:s.tracks.filter(h=>h.property==="x"||h.property==="y")}),c=h=>{const u=l.getStateAtTime(h).values.get(s.tracks[0]?.target??"");return{x:(r.from??0)+Number(u?.get("x")??0),y:(r.ground??0)+Number(u?.get("y")??0)}};n.forEach((h,u)=>{const d=f3[h.do],f=a[u];if(!d||f.contact===void 0||h.do!=="swipe"&&!h.target)return;const p=f.contact,g=f.release??f.contact;t.forEach((m,w)=>{if(m.time<p-1||m.time>g+1)return;const v=o(m.time),k=me(e[w],{height:i.height,facing:v<0?-1:1}),y=c(m.time),x=g3.has(h.do)&&h.target?{x:h.target.x-y.x,y:h.target.y-y.y}:void 0,P={x:(k.hands.right.x+k.fingertips.right.x)/2,y:(k.hands.right.y+k.fingertips.right.y)/2},M=x??(d==="arm"?P:k.toes.right),T=v<0?"right":"left",S=`${d}.${T}`;let E=m.pose;if(h.do==="point")E=_e(i,E,S,M);else if(d==="arm")E=_e(i,k3(i,E,T,M),S,M);else for(let $=0;$<3;$++){const A=fe(i,E).points,I=A[`ankle.${T}`],C=A[`toe.${T}`];E=_e(i,E,S,{x:M.x-(C.x-I.x),y:M.y-(C.y-I.y)})}t[w]={...m,pose:E}})})}function m3(t,e){const n=kt({[`arm.${e}.spread`]:90,[`arm.${e}.elbow`]:0,[`arm.${e}.bend`]:0}),s=fe(t,n).points;return Math.hypot(s[`hand.${e}`].x-s[`shoulder.${e}`].x,s[`hand.${e}`].y-s[`shoulder.${e}`].y)}const y3=5,b3=4,w3=8;function k3(t,e,n,s){const i=m3(t,n)*.9,o=a=>{const l=fe(t,a).points[`shoulder.${n}`];return Math.hypot(s.x-l.x,s.y-l.y)<=i};if(o(e))return e;let r=e;for(let a=1;a<=w3;a++)if(r={...e,lean:(e.lean??0)+y3*a,bend:(e.bend??0)+b3*a},o(r))return r;return r}function v3(t,e,n,s,i){const o=n.find(u=>u.property==="gait"),r=o?new Ht({id:`${t}-gait-of`,tracks:[o]}):void 0,a=u=>{const d=r?.getStateAtTime(u).values.get(t)?.get("gait");if(typeof d=="string")return Yt[d]??i.gaits?.[d]??d},l=e.keyframes,c=[];let h=l[0]?.value??0;return l.forEach((u,d)=>{if(d>0){const f=l[d-1],p=a((f.time+u.time)/2),g=ko(p,s.height),m=Kp(s,p);h+=(u.value-f.value)*(m>0?g/m:1)}else h=u.value;c.push({...u,value:h})}),{...e,keyframes:c}}const mt=["rect","circle","text","line","path","image","custom"],Tr={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:mt},y:{description:"Moves it down by this much from where it was placed (an offset)",unit:"px",types:mt},opacity:{description:"How opaque it is",unit:"0..1",min:0,max:1,types:mt},rotate:{description:"Turns it clockwise about its origin",unit:"degrees",types:mt},rotateX:{description:"Tips it about the horizontal axis (3D; shows with perspective)",unit:"degrees",types:mt},rotateY:{description:"Turns it about the vertical axis (3D; shows with perspective)",unit:"degrees",types:mt},z:{description:"Depth toward the viewer (shows with perspective)",unit:"px",types:mt},perspective:{description:"Distance from the viewer: nearer parts grow, further ones shrink",unit:"px",min:1,types:mt},scale:{description:"Size, both ways",unit:"factor",types:mt},scaleX:{description:"Width factor",unit:"factor",types:mt},scaleY:{description:"Height factor",unit:"factor",types:mt},skewX:{description:"Slants it sideways",unit:"degrees",types:mt},skewY:{description:"Slants it up and down",unit:"degrees",types:mt},originX:{description:"Transform pivot across its box",unit:"% (0 left, 50 centre, 100 right)",min:0,max:100,types:mt},originY:{description:"Transform pivot down its box",unit:"% (0 top, 50 centre, 100 bottom)",min:0,max:100,types:mt},fill:{description:"Fill colour (also written fillStyle)",kind:"color",types:mt},stroke:{description:"Outline colour (also written strokeStyle)",kind:"color",types:mt},strokeWidth:{description:"Outline width (also written lineWidth)",unit:"px",min:0,types:mt},clipTop:{description:"Hides this much from the top edge, for reveals",unit:"% of its height",min:0,max:100,types:mt},clipRight:{description:"Hides this much from the right edge",unit:"% of its width",min:0,max:100,types:mt},clipBottom:{description:"Hides this much from the bottom edge",unit:"% of its height",min:0,max:100,types:mt},clipLeft:{description:"Hides this much from the left edge",unit:"% of its width",min:0,max:100,types:mt},blur:{description:"Gaussian blur",unit:"px",min:0,types:mt},brightness:{description:"Brightness factor (1 unchanged)",unit:"factor",min:0,types:mt},glow:{description:"Soft glow around it, in glowColor",unit:"px",min:0,types:mt},glowColor:{description:"Colour of the glow",kind:"color",types:mt},shadowX:{description:"Drop shadow offset right",unit:"px",types:mt},shadowY:{description:"Drop shadow offset down",unit:"px",types:mt},shadowBlur:{description:"Drop shadow softness",unit:"px",min:0,types:mt},shadowColor:{description:"Drop shadow colour",kind:"color",types:mt},shine:{description:"A highlight sweeping across the fill",unit:"0..1 (progress)",min:0,max:1,types:mt},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:mt},quaternion:{description:'A rotation as [x, y, z, w] (a track with interpolation: "slerp")',kind:"list",types:mt}},Lc={fillStyle:"fill",strokeStyle:"stroke",lineWidth:"strokeWidth",rotateZ:"rotate",motionPathX:"x",motionPathY:"y",motionPathRotate:"rotate"},M3={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 Gp(t){const e=t,n=Object.entries(Tr).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 Up(t){const e=Gp(t).properties.map(n=>n.name);return[...e,...Object.keys(Lc).filter(n=>e.includes(Lc[n]))]}function S3(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=Up(r),l=r.type==="custom"&&r.acceptsProp?.(i.property);if(!a.includes(i.property)&&!l){o(`${i.target}: ${ft("property",i.property,a,M3[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=Tr[Lc[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 Ms=(t,e)=>t[2]<=-e;function Fc(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 Vp(t,e){if(t.every(s=>Ms(s,e)))return t;const n=[];return t.forEach((s,i)=>{const o=t[(i+t.length-1)%t.length],r=Ms(s,e),a=Ms(o,e);r!==a&&n.push(Fc(o,s,e)),r&&n.push(s)}),n.length>=3?n:[]}function x3(t,e){if(t.every(i=>Ms(i,e)))return[t];const n=[];let s=[];return t.forEach((i,o)=>{const r=Ms(i,e);if(o>0){const a=t[o-1],l=Ms(a,e);l&&!r?(s.push(Fc(a,i,e)),n.push(s),s=[]):!l&&r&&s.push(Fc(a,i,e))}r&&s.push(i)}),s.length>0&&n.push(s),n.filter(i=>i.length>=2)}function Jp(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 T3(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 E3(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=>ie(e,s)),faces:t.faces.map(s=>({corners:s.corners,normal:n(s.normal)}))}}function Er(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 A3(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=p=>{const g=p.map(w=>Math.round(w*1e6)).join(",");let m=c.get(g);return m===void 0&&(m=l.length,l.push(p),c.set(g,m)),m},u=[],d=p=>p===0,f=(p,g)=>p+2===g.length;for(const p of s){let g=p.points;d(r)||(g=Er(g,0,e[r],1)),g.length&&!f(r,e)&&(g=Er(g,0,e[r+1],-1)),g.length&&!d(a)&&(g=Er(g,2,n[a],1)),g.length&&!f(a,n)&&(g=Er(g,2,n[a+1],-1)),g.length>=3&&u.push({corners:g.map(h),normal:p.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 $3=new WeakMap,P3=new WeakMap,I3=48,Zp=t=>t.map(e=>Math.round(e*1e5)).join(",");function Qp(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>=I3&&i.clear(),i.set(n,o=s())),o}function Nc(t,e){const n=Zp(e);return Qp($3,t,n,()=>{const s=E3(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 O3(t,e){const n=t.map(h=>({...h,...Nc(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=Jp(s[0],i[0],e),r=Jp(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:T3(o,r,d)}]}return Qp(P3,h.inSpace,a,()=>A3(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 tm=.004,Wc=.05,em=new WeakMap;function _3(t){let e=em.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)}),em.set(t,e)),e}const nm=new WeakMap;function sm(t){return t.filter(({mesh:e})=>_3(e)).map(({part:e,key:n,inSpace:s,low:i,high:o})=>{let r=nm.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]}}),nm.set(s,r)),{part:e,key:n,planes:r,low:i,high:o}})}function C3(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]-Wc||i[a]>o.high[a]+Wc))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)<=tm))return l<-.9;const h=Math.abs(l)<.5?Wc:tm;return c.every(u=>u<=h)}))return!0}return!1}const im=new WeakMap;function om(t,e,n,s,i){const o=`${s}|${i.map(l=>l.key).join(";")}`;let r=im.get(e);r||im.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=>ie(n,h));a=e.faces.map(h=>C3(t,h.corners.map(u=>c[u]),l(h.normal),i)),r.set(o,a)}return a}const Ss={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}},Dc=Math.PI/180;function rm(t,e,n){return{toView:s=>rl(Qt(s,t*90*Dc),-e*Dc),toScreen:s=>({x:s[0]*n,y:-s[1]*n})}}const am=new WeakMap,_i=t=>Ar(t),Ar=t=>{let e=am.get(t);return e||am.set(t,e=Wg(t)),e};function It(t,e,n){return e[n]??t.controls[n]?.default??Ss[n]?.default??0}function Ci(t,e){const n=Math.max(.05,It(t,e,"squash")),s=1/Math.sqrt(n),o=[1,0,0,0,0,1,It(t,e,"lean"),0,0,0,1,0,0,0,0,1];return[pn([0,It(t,e,"lift"),0]),pe(Vt([1,0,0],-It(t,e,"pitch"))),pe(Vt([0,0,1],It(t,e,"roll"))),o,mn([s,n,s]),mn(Array(3).fill(Math.max(0,It(t,e,"size"))))].reduce((r,a)=>Rt(r,a))}function Bc(t,e){const n=Ci(t,e),s=new Map,i=Object.entries(t.controls).flatMap(([r,a])=>(a.bind??[]).map(l=>({value:It(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=Rt(l?o(l):n,pn(r.at??[0,0,0]));if(r.rotate){const[h,u,d]=r.rotate;h&&(c=Rt(c,pe(Vt([1,0,0],h)))),u&&(c=Rt(c,pe(Vt([0,1,0],u)))),d&&(c=Rt(c,pe(Vt([0,0,1],d))))}for(const{value:h,bind:u}of i)if(!(!u.parts.includes(r.id)||h===0)){if(u.translate&&(c=Rt(c,pn([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,pn(d),pe(Vt(f,u.rotate.degrees*h)),pn([-d[0],-d[1],-d[2]])].reduce((p,g)=>Rt(p,g))}u.scale&&(c=Rt(c,mn([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 zc=(()=>{const t=[-.45,.75,.5],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),H3=Math.cos(35*Dc);function qc(t,e,n,s,i={}){const o=t.derive?{...e,...t.derive(e)}:e,r=Bc(t,o),a=n.toView([0,0,0]),l=C=>D=>[C[0]*D[0]+C[4]*D[1]+C[8]*D[2],C[1]*D[0]+C[5]*D[1]+C[9]*D[2],C[2]*D[0]+C[6]*D[1]+C[10]*D[2]],c=Ci(t,o),h=i.slice===void 0?null:ka(c),u=h?t.parts.map(C=>({part:C,mesh:Ar(C.shape),local:Rt(h,r.get(C.id)),whole:C.shape.type==="tube"})):void 0,d=u?O3(u,i.slice):void 0,f=u?sm(u.map(C=>({part:C.part.id,mesh:C.mesh,...Nc(C.mesh,C.local)}))):void 0,p=(C,D,j,V)=>{const et=Z=>n.toView(ie(j,Z)),G=D.vertices.map(et),F=G.map(Z=>n.toScreen(Z)),H=i.perspective?i.near:void 0,W=Z=>Z.map(rt=>n.toScreen(rt)),_=Z=>H===void 0?Z:Vp(Z,H),B=Z=>H===void 0?[Z]:x3(Z,H),Q=l(j),O=D.faces.map(Z=>{const rt=n.toView(Q(Z.normal)),ht=[rt[0]-a[0],rt[1]-a[1],rt[2]-a[2]],dt=Math.hypot(...ht)||1;return[ht[0]/dt,ht[1]/dt,ht[2]/dt]}),R=f&&V?om(C.id,D,V,Zp(V),f):void 0,z=Z=>R?.[Z]??!1,K=O.map((Z,rt)=>{if(z(rt))return!1;if(!i.perspective)return Z[2]>1e-6;const dt=D.faces[rt].corners.reduce((bt,wt)=>[bt[0]+G[wt][0],bt[1]+G[wt][1],bt[2]+G[wt][2]],[0,0,0]);return-(Z[0]*dt[0]+Z[1]*dt[1]+Z[2]*dt[2])>1e-9}),N=Z=>D.faces[Z].corners.reduce((rt,ht)=>rt+G[ht][2],0)/D.faces[Z].corners.length,q=D.faces.map((Z,rt)=>({face:Z,i:rt})).filter(({i:Z})=>K[Z]).map(({face:Z,i:rt})=>({i:rt,solved:{points:H===void 0?Z.corners.map(ht=>F[ht]):W(_(Z.corners.map(ht=>G[ht]))),depth:N(rt),tone:.72+.33*Math.max(0,O[rt][0]*zc[0]+O[rt][1]*zc[1]+O[rt][2]*zc[2])}})).filter(Z=>Z.solved.points.length>=3).sort((Z,rt)=>Z.solved.depth-rt.solved.depth);if(i.light){const Z=l(j);for(const{i:rt,solved:ht}of q){const dt=D.faces[rt].corners,bt=dt.reduce((gh,Cx)=>{const ph=ie(j,D.vertices[Cx]);return[gh[0]+ph[0]/dt.length,gh[1]+ph[1]/dt.length,gh[2]+ph[2]/dt.length]},[0,0,0]),wt=Z(D.faces[rt].normal),ge=Math.hypot(...wt)||1,Di=i.light(bt,[wt[0]/ge,wt[1]/ge,wt[2]/ge]);ht.light=Di.light,ht.fog=Di.fog}}const Y=q.map(Z=>Z.solved),J=R3(D),X=[],tt=[];for(const[Z,rt]of J){const ht=rt.filter(bt=>K[bt]).length;if(ht===0)continue;const dt=rt.length===2&&ht===2&&D.creases!==!1&&O[rt[0]][0]*O[rt[1]][0]+O[rt[0]][1]*O[rt[1]][1]+O[rt[0]][2]*O[rt[1]][2]<H3;rt.length===1&&(D.joined||L3(D,Z))||(rt.length===1||ht===1||dt)&&(X.push(Z.split("-").map(Number)),tt.push(rt.filter(bt=>K[bt]).reduce((bt,wt)=>N(wt)>N(bt)?wt:bt)))}const nt=Z=>D.faces.findIndex(rt=>rt.corners.length>4&&Math.sign(N3(D.vertices[Z],rt.normal))>0),L=(D.marks??[]).filter(([Z])=>nt(Z)<0||K[nt(Z)]),U=([Z,rt])=>H===void 0?[[F[Z],F[rt]]]:B([G[Z],G[rt]]).map(W),ot=L.flatMap(U),at=Z=>H===void 0?[Z.map(rt=>F[rt])]:B(Z.map(rt=>G[rt])).map(W);if(i.slice!==void 0){const Z=new Map;X.forEach((rt,ht)=>Z.set(tt[ht],[...Z.get(tt[ht])??[],rt]));for(const{i:rt,solved:ht}of q){ht.edges=um(Z.get(rt)??[]).flatMap(at);const dt=D.faces[rt].corners;ht.center=dt.reduce((wt,ge)=>[wt[0]+G[ge][0]/dt.length,wt[1]+G[ge][1]/dt.length,wt[2]+G[ge][2]/dt.length],[0,0,0]),ht.normal=O[rt];const bt=q[q.length-1].i;ht.marks=L.filter(([wt])=>(nt(wt)>=0?nt(wt):bt)===rt).flatMap(U)}}const it=C.glow?Math.max(0,Math.min(1,It(t,o,C.glow.control))):0,ct=C.fade?Math.max(0,Math.min(1,It(t,o,C.fade.control))):0,st=C.fade?Math.max(0,Math.min(1,C.fade.from+(C.fade.to-C.fade.from)*ct)):1;return{part:C,depth:G.reduce((Z,rt)=>Z+rt[2],0)/Math.max(1,G.length),faces:Y,edges:um(X).flatMap(at),marks:ot,glow:it,opacity:st,...C.shape.type==="tube"?{spine:F3(B(C.shape.points.map(et)).map(W))}:{},...D.walls?{cut:!0}:{}}},g=new Map(u?.map(C=>[C.part.id,C.local])),w=(d?d.pieces.map(C=>({part:C.part,mesh:C.mesh,m:C.cut?c:r.get(C.part.id),local:C.cut?so():g.get(C.part.id),cell:C.cell})):t.parts.map(C=>({part:C,mesh:Ar(C.shape),m:r.get(C.id),local:void 0,cell:void 0}))).map(C=>({cell:C.cell,solved:p(C.part,C.mesh,C.m,C.local)})),v=w.map(C=>C.solved),k=C=>C.filter(D=>D.faces.length>0&&D.opacity>.01).sort((D,j)=>D.depth-j.depth);let y;if(d){const C=new Map(t.parts.map(j=>{const V=r.get(j.id),et=Ar(j.shape).vertices;return[j.id,et.reduce((G,F)=>G+n.toView(ie(V,F))[2],0)/Math.max(1,et.length)]})),D=new Map;for(const j of w){const V=j.cell.join(",");D.has(V)||D.set(V,{cell:j.cell,parts:[]}),D.get(V).parts.push(j.solved),j.solved.depth=C.get(j.solved.part.id)}y=[...D.values()].map(({cell:j,parts:V})=>({depth:n.toView(ie(c,d.middle(j)))[2],parts:k(V)})).filter(j=>j.parts.length>0)}const x={};for(const[C,D]of Object.entries(t.anchors??{})){const j=D.part?r.get(D.part):Ci(t,o);if(!j)throw new Error(`prop rig: anchor "${C}" is on "${D.part}", which is not a part`);const V=n.toView(ie(j,D.at));x[C]={point:n.toScreen(V),depth:V[2]}}const[P,M]=t.footprint??[t.length*.45,t.length],T=Math.max(0,It(t,o,"lift")),S=Math.max(0,It(t,o,"size"))/(1+T*.8),E=Array.from({length:24},(C,D)=>{const j=Math.PI*2*D/24;return n.toView([Math.cos(j)*P*.55*S,0,Math.sin(j)*M*.55*S])}),$=i.perspective?i.near:void 0,A={points:($===void 0?E:Vp(E,$)).map(C=>n.toScreen(C)),opacity:.16*S},I=v.filter(C=>C.part.seeThrough&&C.opacity>.01).flatMap(C=>C.faces.map(D=>D.points));return{under:k(v.filter(C=>!C.part.overRider)),over:k(v.filter(C=>C.part.overRider)),...y?{cells:y}:{},anchors:x,openings:I,shadow:A,pxPerUnit:s,sizePx:t.height*s}}const lm=new WeakMap;function R3(t){let e=lm.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])}}lm.set(t,e)}return e}function cm(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=Bc(t,n),i=ka(Ci(t,n))??so(),o=r=>Math.max(0,Math.min(1,r));return t.parts.map(r=>{const a=r.fade?o(It(t,n,r.fade.control)):0;return{part:r,matrix:s.get(r.id),local:Rt(i,s.get(r.id)),glow:r.glow?o(It(t,n,r.glow.control)):0,opacity:r.fade?o(r.fade.from+(r.fade.to-r.fade.from)*a):1}})}function hm(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=Bc(t,n),i=Ci(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]=ie(l,a.at)}return o}function L3(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 F3(t){return t.reduce((e,n)=>!e||n.length>e.length?n:e,void 0)}const N3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2];function um(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 jc(t,e){if(!t.loose?.size)return;const n={};for(const[s,i]of t.loose)n[s]={x:e[`piece.${i}.x`]??0,y:e[`piece.${i}.y`]??0,rotate:e[`piece.${i}.rotate`]??0,opacity:e[`piece.${i}.opacity`]??1};return n}function Yc(t){const e={};for(const[n,s]of Object.entries({...Ss,...t.rig.controls})){const{bind:i,...o}=s;e[n]=o}return e}function dm(t){const{prop:e}=t,n=t.scale??60,s=e.rig.length*n*1.4,i=e.rig.height*n*1.6,o=Yc(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),ql(l,xs(e,u,n),{...a,time:h,loose:jc(c,u)})}}}function xs(t,e,n){const s=rm(It(t.rig,e,"turn"),It(t.rig,e,"tilt"),n);return qc(t.rig,e,s,n)}function $r(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=xs(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 W3(t,e,n,s,i={}){const o=$r(e,n,s);return t.save(),t.translate(o.origin.x,o.origin.y),ql(t,o.solved,{...e.propDraw,time:n.time,loose:jc(e,o.values),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 Ts={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…); it can come loose as a piece","control:NAME":"where the parts a control moves or lights are (control:door is the doors, control:lights the lamps; a control of the whole prop, like lift, is its box)"},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",move:"a part; { at, to: an anchor name or { x, y }, duration? }: carry the part there, loose",fling:"a part; { at, velocity?, spin?, gravity?, duration? }: knock the part off on a spinning arc"}},D3=400,B3=.2;function z3(t,e={}){const{prop:n}=t,s=Yc(n),i=Object.keys(s),o=Object.keys(n.rig.anchors??{}),r=n.rig.parts.map(P=>P.id),a=ms(),l=vi(a),c=e.tracks?.length?new Ht({id:`${n.kind}-surface`,tracks:e.tracks}):void 0,h=Math.max(0,...(e.tracks??[]).flatMap(P=>P.keyframes.map(M=>M.time))),u=new Map,d=new Map;t.loose=d;const f=t.props,p=P=>{const M={...t.props};let T=0,S=0;if(c){const E=c.getStateAtTime(Math.min(P,h));for(const $ of E.values.values())for(const[A,I]of $)typeof I=="number"&&(A==="x"?T=I:A==="y"?S=I:A in M&&(M[A]=I))}for(const E of i)a.keys(E)?.length&&(M[E]=a.valueAt(E,P));return{values:M,origin:{x:t.x+t.width/2+T,y:t.y+t.height+S}}},g=P=>{const{kind:M,rest:T}=In(P),S=E=>tn(n.kind,P,Ts,E);if(M==="box"){if(T)throw S("box takes no arguments");return{kind:M}}if(M==="anchor"){if(!o.includes(T))throw S(ft(`${n.kind} anchor`,T,o));return{kind:M,name:T}}if(M==="part"){if(!r.includes(T))throw S(ft(`${n.kind} part`,T,r));return{kind:M,name:T}}if(M==="control"){if(!i.includes(T))throw S(ft(`${n.kind} control`,T,i));return{kind:M,name:T}}throw S()},m=P=>{const M=(n.rig.controls[P]?.bind??[]).flatMap(S=>S.parts),T=n.rig.parts.filter(S=>S.glow?.control===P).map(S=>S.id);return new Set([...M,...T])},w=new Map,v=P=>{let M=w.get(P);if(!M){const T=p(P);w.set(P,M={...T,solved:xs(n,T.values,t.propScale)})}return M},k=(P,M)=>{const T=g(P),{values:S,origin:E,solved:$}=v(M);if(T.kind==="box")return Mt(E.x-t.width/2,E.y-t.height,t.width,t.height);if(T.kind==="anchor"){const C=$.anchors[T.name].point,D=B3*t.propScale;return Mt(E.x+C.x-D/2,E.y+C.y-D/2,D,D)}if(T.kind==="part")return I(new Set([T.name]),`part "${T.name}" is`);const A=m(T.name);if(A.size===0)return Mt(E.x-t.width/2,E.y-t.height,t.width,t.height);return I(A,`the parts control "${T.name}" moves are`);function I(C,D){const j=[...$.under,...$.over].filter(H=>C.has(H.part.id)).flatMap(H=>H.faces.flatMap(W=>W.points));if(j.length===0){const H=Number.isFinite(M)?`at ${M} ms`:"after its edits";throw new Error(`${n.kind}: ${D} turned away from the viewer ${H}; aim at an anchor (${o.map(W=>`anchor:${W}`).join(", ")||"none"}) or box`)}const V=j.map(H=>H.x),et=j.map(H=>H.y),G=Math.min(...V),F=Math.min(...et);return Mt(E.x+G,E.y+F,Math.max(...V)-G,Math.max(...et)-F)}},y=(P,M)=>{try{return k(P,M)}catch{return}},x={kind:"prop",prop:t,about:Ts,target:t,box:Mt(t.x,t.y,t.width,t.height),anchor(P,M=1/0){return k(P,M)},piece(P){const M=g(P);if(M.kind!=="part")throw new Error(`${n.kind}: a piece is a part, part:ID (${r.slice(0,6).map($=>`part:${$}`).join(", ")}…), not "${P}"`);const T=u.get(M.name);if(T)return T;const S=[M.name];for(let $=0;$<S.length;$++)for(const A of n.rig.parts)A.parent===S[$]&&!S.includes(A.id)&&S.push(A.id);const E={id:u.size+1,part:M.name,home:k(P,0)};u.set(M.name,E);for(const $ of S)d.set($,E.id);for(const $ of["x","y","rotate"])f[`piece.${E.id}.${$}`]=0;return f[`piece.${E.id}.opacity`]=1,E},edit(P,M,T){if(!(P in Ts.edits))throw Mi(n.kind,P,Ts);const S=Array.isArray(M)?M:[M];if(S.length===0)throw new Error(`${n.kind}.edit: ${P} takes at least one anchor`);if(w.clear(),P==="move"||P==="fling"){if(S.length>1)throw new Error(`${n.kind}.edit: ${P} takes one part anchor`);const E=x.piece(S[0]);if(P==="fling")return x.fling(E,T);const $=T.to;if(!$)throw new Error(`${n.kind}.edit: move needs \`to\`, an anchor name or { x, y }`);const A=typeof $=="string"?k($,T.at):void 0;return x.move(E,{...T,to:A?{x:A.left+A.width/2,y:A.top+A.height/2}:$})}for(const E of S){const $=g(E);if($.kind!=="control")throw new Error(`${n.kind}.edit: ${P} takes control anchors (control:${i.join(", control:")}), not "${E}"`);const A=s[$.name];let I;if(P==="set"){if(typeof T.value!="number"||!Number.isFinite(T.value))throw new Error(`${n.kind}.edit: set needs \`value\`, a number (${$.name}: ${A.description})`);I=T.value}else I=T.on===!1?A.default??A.min??0:A.max??1;a.tween($.name,p(T.at).values[$.name],I,T,D3)}return x},follow(P,M){return w.clear(),l.follow(P,M),x},fling(P,M){return w.clear(),l.fling(P,M),x},move(P,M){return w.clear(),l.move(P,M),x},ride(P,M,T){const S=[...i.flatMap($=>ys(a.keys($))),...(e.tracks??[]).flatMap($=>ys($.keyframes.filter(A=>typeof A.value=="number")))];if(S.length===0)return P;const E=[...o.map($=>`anchor:${$}`),...r.map($=>`part:${$}`)].flatMap($=>{const A=y($,0);return A?[{top:A.top,offset:I=>(y($,I)?.top??A.top)-A.top,windows:S}]:[]});return dr(P,M,{ground:T.ground,every:T.every??Qe,floors:E})},tracks:a.tracks};return x}const q3={body:"#e8574a",trim:"#3b3b44",glass:"#bfe3f2",tyre:"#2c2c33",hub:"#c9ccd3",light:"#fff4b8",tail:"#ff5a4f",inside:"#3b3640",seat:"#6d5d55"};function Le(t){const e={...q3,...t.colors},n=[],{forwardMost:s,backMost:i,top:o}=fm(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,p]of(t.cabin.pillars??[]).entries())n.push({id:`pillar-${f}`,shape:{type:"box",size:[h+.02,d-u,.1]},at:[0,(u+d)/2,p],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 p of d){const g=`wheel-${u}-${p>0?"left":p<0?"right":"middle"}`;if(a.push({parts:[g],rotate:{axis:"x",degrees:r/h.radius}}),n.push({id:g,shape:{type:"cylinder",radius:h.radius,length:f,axis:"x",segments:20,spokes:h.style==="spoked"?8:0},at:[p*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 p===0?[1,-1]:[p])n.push({id:`${g}-hub${p===0?m>0?"-left":"-right":""}`,parent:g,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,p=[[h,d],[u,d],[u,f],[h,f]];for(const g of[1,-1]){const m=g>0?"left":"right";n.push({id:`doorway-${m}`,shape:{type:"panel",points:p,facing:g>0?"left":"right"},at:[g*(t.width/2+.004),0,0],fill:e.inside,outline:.5,seeThrough:!0});const w=h+(u-h)*.15,v=h+(u-h)*.55;n.push({id:`seat-back-${m}`,shape:{type:"panel",points:[[w,d+.05],[v,d+.05],[v-.08,f-.06],[w+.06,f-.04]],facing:g>0?"left":"right"},at:[g*(t.width/2+.006),0,0],fill:e.seat,outline:.4}),n.push({id:`door-${m}`,shape:{type:"panel",points:p.map(([k,y])=>[k-u,y]),facing:g>0?"left":"right"},at:[g*(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:p}=t.lights,g=(t.lights.size??.32)/2,m=[[-g,u],[g,u],[g,d],[-g,d]];for(const w of[1,-1])n.push({id:`headlight-${w}`,shape:{type:"panel",points:m,facing:"front"},at:[w*h,0,f],fill:e.light,outline:.6,glow:{control:"lights",color:"#ffffff"}}),n.push({id:`taillight-${w}`,shape:{type:"panel",points:m,facing:"back"},at:[w*h,0,p],fill:rr(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:j3(t),acting:gm,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 fm(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 gm={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 Pr(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 pm=.4;function j3(t){const e=t.wheels[0]?.radius??.4,{forwardMost:n,backMost:s}=fm(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"}),Pr(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),p=l.for??Math.max(500,f/(l.speed??pm));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,p-160),{pitch:0,lean:.08*d,squash:1.02},{act:!1}),Pr(a,u,u+p,l.to,"ease-in-out",e),r(a,u+p,!1),{end:u+p+380,contact:u,release:u+p}}},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,p=Math.abs(l.to-f),g=l.for??Math.max(600,p/(l.speed??pm*1.2)),m=u+g*.55,w=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"}),Pr(a,u,m,w,"ease-in",e),a.key(m+80,{pitch:-7*d,lean:-.12*d,squash:.94},{act:!1,easing:"ease-out"}),Pr(a,m,u+g,l.to,"ease-out",e,!0),a.effect({kind:"skid",time:m,x:w,toX:l.to,y:a.floor,length:g*.45+1500}),a.effect({kind:"dust",time:u+g,x:l.to+h*i*a.scale,y:a.floor,length:600,direction:h}),r(a,u+g,!0),{end:u+g+380,contact:m,release:u+g}}},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 mm(t={}){return Le({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 ym(t={}){return Le({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 bm(t={}){return Le({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 wm(t={}){return Le({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 km(t={}){const e=t.colors?.body??"#a8743f";return Le({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 vm(t={}){return Le({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 Mm(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 Le({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 Sm(t={}){return Le({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 xm(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=je(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),p=[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:p,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:Y3(),acting:Tm,colors:{body:o.leaves}}}const Tm={depth:{sway:1,canopySway:2,size:0,squash:1},limits:{sway:2,canopySway:3,squash:.08},eyes:[],headTurns:{},drift:[]};function Y3(){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 Em(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((g,m)=>{d.push({id:`window-${m}`,shape:{type:"panel",points:[[-g.width/2,g.low],[g.width/2,g.low],[g.width/2,g.low+g.height],[-g.width/2,g.low+g.height]],facing:"front"},at:[g.at,0,a+.01],fill:r.glass,outline:.8,glow:{control:"lights",color:r.lit}})});for(const g of[1,-1])d.push({id:`side-window-${g>0?"left":"right"}`,shape:{type:"panel",points:[[-.4,1],[.4,1],[.4,1.8],[-.4,1.8]],facing:g>0?"left":"right"},at:[g*(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 g=s+i*(1-Math.abs(f.back)/(n/2+o)),m=s+i+.45;d.push({id:"chimney",shape:{type:"box",size:[.42,m-g+.3,.42]},at:[f.at,(m+g-.3)/2,f.back],fill:r.chimney,layer:1})}const p={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:p,actions:K3(!!f),acting:Am,colors:{body:r.walls}}}const Am={depth:{door:1,lights:0,roll:1,squash:1,size:0},limits:{door:.1,roll:1.5,squash:.05},eyes:[],headTurns:{},drift:[]};function K3(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 $m(t={}){const e=t.width??.46,n=t.depth??.46,s=t.seatHeight??.46,i=t.backHeight??.95,o={wood:"#8a5a3b",seat:"#c48a4a",...t.colors},r=.05,a=.025,l=[{id:"seat",shape:{type:"box",size:[e,r,n]},at:[0,s-r/2,0],fill:o.seat},{id:"back",shape:{type:"box",size:[e,i-s,r]},at:[0,(i+s)/2,-n/2+r/2],fill:o.wood}];for(const[h,u,d]of[[-1,1,"front-left"],[1,1,"front-right"],[-1,-1,"back-left"],[1,-1,"back-right"]])l.push({id:`leg-${d}`,shape:{type:"tube",points:[[0,0,0],[0,s-r,0]],radius:a,segments:6},at:[h*(e/2-a*1.5),0,u*(n/2-a*1.5)],fill:o.wood});const c={parts:l,controls:{tip:{description:"Tipped back on its rear legs (+), degrees",unit:"degrees",min:0,max:60,bind:[{parts:l.map(h=>h.id),rotate:{axis:"x",degrees:1,pivot:[0,0,-n/2+a*1.5]}}]}},length:n,height:i,footprint:[e,n],anchors:{seat:{at:[0,s,0]},back:{at:[0,i,-n/2]},front:{at:[0,0,n/2+.3]}}};return{kind:t.kind??"chair",family:"furniture",summary:t.summary??"A chair: a seat to sit on (`seat`), tips back on its rear legs and settles, or falls over.",rig:c,actions:X3(),acting:Pm,colors:{body:o.seat}}}const Pm={depth:{tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.05},eyes:[],headTurns:{},drift:[]};function X3(){return{tip:{summary:"Tips back on its rear legs for `for` ms (default 1200), rocking a little, then settles down.",uses:["for"],run(t,e,n){const s=18*t.exaggeration,i=e.for??1200;return t.key(n+350,{tip:s},{easing:"ease-out"}),t.key(n+350+i*.4,{tip:s*.85},{act:!1,easing:"ease-in-out"}),t.key(n+350+i*.7,{tip:s},{act:!1,easing:"ease-in-out"}),t.key(n+350+i,{tip:0},{easing:"ease-in"}),{end:n+350+i,contact:n+350}}},fall:{summary:"Falls over backwards onto its back and bounces, with dust.",uses:["for"],run(t,e,n){const s=e.for??700;return t.key(n+s*.6,{tip:90},{act:!1,easing:"ease-in"}),t.key(n+s*.75,{tip:82},{act:!1,easing:"ease-out"}),t.key(n+s,{tip:90},{act:!1,easing:"ease-in"}),t.effect({kind:"dust",time:n+s*.6,x:t.x,y:t.floor,length:600}),{end:n+s,contact:n+s*.6}}}}}function Im(t={}){const e=t.width??1.4,n=t.depth??.7,s=t.height??.75,i={wood:"#8a5a3b",top:"#a9754a",knob:"#2b2b2b",...t.colors},o=.04,r=.03,a=.14,l=e*.4,c=[{id:"top",shape:{type:"box",size:[e,o,n]},at:[0,s-o/2,0],fill:i.top},{id:"drawer",shape:{type:"box",size:[l,a,n*.8]},at:[-e/2+l/2+.05,s-o-a/2,0],fill:i.wood},{id:"knob",parent:"drawer",shape:{type:"ellipsoid",radii:[.02,.02,.015],segments:8},at:[0,0,n*.4+.012],fill:i.knob,outline:.6}];for(const[u,d,f]of[[-1,1,"front-left"],[1,1,"front-right"],[-1,-1,"back-left"],[1,-1,"back-right"]])c.push({id:`leg-${f}`,shape:{type:"tube",points:[[0,0,0],[0,s-o,0]],radius:r,segments:6},at:[u*(e/2-r*2),0,d*(n/2-r*2)],fill:i.wood});const h={parts:c,controls:{drawer:{description:"The drawer out: 0 shut, 1 open",unit:"0..1",min:0,max:1,bind:[{parts:["drawer"],translate:[0,0,n*.5]}]}},length:n,height:s,footprint:[e,n],anchors:{top:{at:[0,s,0]},edge:{at:[0,s,n/2]},drawer:{part:"drawer",at:[0,0,n*.4]},chair:{at:[0,0,n/2+.35]}}};return{kind:t.kind??"desk",family:"furniture",summary:t.summary??"A desk: a top to work at (`top`, `edge`), a drawer that opens (`drawer`), a place for a chair in front (`chair`).",rig:h,actions:{drawer:{summary:"Opens the drawer (`open: true`) or shuts it (`open: false`).",needs:["open"],run(u,d,f){return u.key(f+400,{drawer:d.open?1:0},{easing:d.open?"ease-out":"ease-in"}),{end:f+500,contact:f+400}}}},acting:Om,colors:{body:i.top}}}const Om={depth:{drawer:1,roll:1,squash:1,size:0},limits:{drawer:.08,roll:1,squash:.04},eyes:[],headTurns:{},drift:[]};function _m(t={}){const e=t.length??2,n=t.width??1,s=t.height??.55,i=t.headboard??.95,o={wood:"#8a5a3b",mattress:"#f1ece2",blanket:"#5b7fb0",pillow:"#fbf8f2",...t.colors},r=.3,a=s-r,c={parts:[{id:"frame",shape:{type:"box",size:[n,r,e]},at:[0,r/2,0],fill:o.wood},{id:"headboard",shape:{type:"box",size:[n+.06,i-r,.06]},at:[0,(i+r)/2,-e/2-.03],fill:o.wood},{id:"mattress",shape:{type:"box",size:[n-.04,a,e-.04]},at:[0,r+a/2,0],fill:o.mattress},{id:"blanket",parent:"mattress",shape:{type:"box",size:[n-.02,.04,e*.62]},at:[0,a/2+.02,e*.19],fill:o.blanket,outline:.7},{id:"pillow",parent:"mattress",shape:{type:"ellipsoid",radii:[n*.32,.07,.22],segments:12},at:[0,a/2+.06,-e/2+.32],fill:o.pillow,outline:.7}],controls:{give:{description:"The mattress pressed down: 1 as made, below squashed (someone landed on it)",unit:"factor",default:1,min:.5,max:1.2,bind:[{parts:["mattress"],scale:[1,1,1]}]}},length:e,height:i,footprint:[n,e],anchors:{mattress:{part:"mattress",at:[0,a/2,0]},pillow:{part:"mattress",at:[0,a/2+.1,-e/2+.32]},foot:{at:[0,s,e/2]},side:{at:[n/2+.25,0,0]}}};return{kind:t.kind??"bed",family:"furniture",summary:t.summary??"A bed: a mattress to lie on (`mattress`, `pillow`) that gives and springs back when someone lands on it (`bounce`), a side to sit on (`side`).",rig:c,actions:{bounce:{summary:"The mattress gives (someone landed on it) and springs back over `for` ms (default 700).",uses:["for"],run(h,u,d){const f=u.for??700,p=h.exaggeration;return h.key(d+90,{give:1-.18*p},{act:!1,easing:"ease-out"}),h.key(d+f*.45,{give:1+.05*p},{act:!1,easing:"ease-in-out"}),h.key(d+f*.7,{give:1-.04*p},{act:!1,easing:"ease-in-out"}),h.key(d+f,{give:1}),{end:d+f,contact:d+90}}}},acting:Cm,colors:{body:o.blanket}}}const Cm={depth:{give:1,roll:1,squash:1,size:0},limits:{give:.03,roll:.5,squash:.03},eyes:[],headTurns:{},drift:[]};function Hm(t={}){const e=t.width??.9,n=t.height??2.05,s=t.hinge??"left",i={frame:"#d9d2c3",door:"#7a4b2a",handle:"#c9a227",beyond:"#2a2f3a",...t.colors},o=.1,r=s==="left"?1:-1,a=r>0?[[0,0],[-e,0],[-e,n],[0,n]]:[[0,0],[e,0],[e,n],[0,n]],c={parts:[{id:"post-left",shape:{type:"box",size:[o,n+o,o]},at:[e/2+o/2,(n+o)/2,0],fill:i.frame},{id:"post-right",shape:{type:"box",size:[o,n+o,o]},at:[-e/2-o/2,(n+o)/2,0],fill:i.frame},{id:"lintel",shape:{type:"box",size:[e+o*2,o,o]},at:[0,n+o/2,0],fill:i.frame},{id:"beyond",shape:{type:"panel",points:[[-e/2,0],[e/2,0],[e/2,n],[-e/2,n]],facing:"front"},at:[0,0,-.03],fill:i.beyond,outline:.4,seeThrough:!0},{id:"door",shape:{type:"panel",points:a,facing:"front"},at:[r*e/2,0,.005],fill:i.door,outline:.9,overRider:!0},{id:"handle",parent:"door",shape:{type:"ellipsoid",radii:[.03,.03,.03],segments:8},at:[-r*(e-.1),n*.47,.03],fill:i.handle,outline:.5}],controls:{open:{description:"How far the door is open: 0 shut, 1 open wide",unit:"0..1",min:0,max:1,bind:[{parts:["door"],rotate:{axis:"y",degrees:r*-95}}]}},length:.3,height:n+o,footprint:[e+o*2,.3],anchors:{handle:{part:"door",at:[-r*(e-.1),n*.47,.03]},doorway:{at:[0,0,0]},front:{at:[0,0,.5]},beyond:{at:[0,0,-.5]}}};return{kind:t.kind??"door",family:"furniture",summary:t.summary??"A door in its frame: opens and shuts on its hinge (`open`), slams, rattles when knocked; a figure goes through the `doorway` from `front` to `beyond`.",rig:c,actions:G3(),acting:Rm,colors:{body:i.door}}}const Rm={depth:{open:1,roll:1,squash:1,size:0},limits:{open:.08,roll:.6,squash:.03},eyes:[],headTurns:{},drift:[]};function G3(){return{open:{summary:"Opens the door (`open: true`, default) or shuts it (`open: false`), over `for` ms (default 600).",uses:["open","for"],run(t,e,n){const s=e.for??600;return t.key(n+s,{open:e.open===!1?0:1},{easing:"ease-in-out"}),{end:n+s+80,contact:n+s}}},slam:{summary:"Slams shut: a fast swing, a shudder in the frame, dust.",run(t,e,n){const s=t.exaggeration;t.key(n+180,{open:0},{act:!1,easing:"ease-in"});for(let i=1;i<=4;i++)t.key(n+180+i*70,{roll:(i%2===0?1:-1)*1.2*s*(1-i/5)},{act:!1});return t.key(n+180+350,{roll:0}),t.effect({kind:"dust",time:n+180,x:t.x,y:t.floor,length:500}),{end:n+180+350,contact:n+180}}},knock:{summary:"Someone knocks three times: the door rattles over `for` ms (default 700).",uses:["for"],run(t,e,n){const i=e.for??700,o=t.exaggeration;for(let r=0;r<3;r++){const a=n+i*(r+.5)/3;t.key(a,{open:.03*o},{act:!1,easing:"ease-out"}),t.key(a+60,{open:0},{act:!1,easing:"ease-in"})}return{end:n+i,contact:n+i/6}}}}}const Lm=1.4;function Fm(t={}){const e=t.width??.5,n=t.seatHeight??.5,s=t.wheelRadius??.3,i=.08,o={frame:"#2b2f36",seat:"#3c6ea5",tyre:"#1f2328",...t.colors},r=.04,a=.018,l=.44,c=n+.5,h=-.08,u=e/2+.06,d=[{id:"seat",shape:{type:"box",size:[e,r,l]},at:[0,n-r/2,0],fill:o.seat},{id:"back",shape:{type:"box",size:[e,c-n-.02,r]},at:[0,(c+n)/2,-l/2+r/2],fill:o.seat},{id:"footrest",shape:{type:"box",size:[e*.8,.02,.14]},at:[0,.12,l/2+.22],fill:o.frame}];for(const[g,m]of[[-1,"left"],[1,"right"]]){const w=g*u,v=(k,y,x=a)=>{d.push({id:k,shape:{type:"tube",points:y,radius:x,segments:6},fill:o.frame,outline:.7})};v(`post-${m}`,[[w,n-.1,-l/2],[w,c+.04,-l/2],[w,c+.04,-l/2-.14]]),v(`rail-${m}`,[[w,n-.03,-l/2],[w,n-.03,l/2]]),v(`leg-${m}`,[[w,n-.03,l/2],[w*.85,i,l/2+.06]]),v(`strut-${m}`,[[w*.85,i+.08,l/2+.04],[w*.8,.13,l/2+.22]]),v(`armrest-${m}`,[[w,n+.22,-l/2+.02],[w,n+.22,l/2-.08]],a*1.3),d.push({id:`wheel-${m}`,shape:{type:"cylinder",radius:s,length:.04,axis:"x",segments:20,spokes:8},at:[w+g*.03,s,h],ink:o.tyre,outline:1.3}),d.push({id:`rim-${m}`,shape:{type:"cylinder",radius:s*.9,length:.012,axis:"x",segments:20},at:[g*.045,0,0],parent:`wheel-${m}`,ink:o.frame,outline:.8}),d.push({id:`castor-${m}`,shape:{type:"cylinder",radius:i,length:.03,axis:"x",segments:12,spokes:3},at:[w*.85,i,l/2+.06],fill:o.tyre})}const f=d.map(g=>g.id).filter(g=>!g.startsWith("rim-")),p={parts:d,controls:{wheelSpin:{description:"How far the big wheels have turned, degrees (keyed with the distance rolled, so they never skate); the castors turn faster",unit:"degrees",bind:[{parts:["wheel-left","wheel-right"],rotate:{axis:"x",degrees:1}},{parts:["castor-left","castor-right"],rotate:{axis:"x",degrees:s/i}}]},tip:{description:"Tipped back on its big wheels (+), degrees: a wheelie, or a helper tipping it up a kerb",unit:"degrees",min:0,max:45,bind:[{parts:f,rotate:{axis:"x",degrees:1,pivot:[0,s,h]}}]}},length:l+.4,height:c+.04,footprint:[u*2+.1,l+.4],anchors:{seat:{at:[0,n,.02]},handles:{at:[0,0,-l/2-.5]},front:{at:[0,0,l/2+.6]},footrest:{at:[0,.13,l/2+.22]}}};return{kind:t.kind??"wheelchair",family:"furniture",summary:t.summary??"A wheelchair: rolls to `to` with its wheels turning the distance (roll), brakes, tips back on its big wheels (wheelie); its `seat` is ridden in the `wheeling` pose and a pusher stands at `handles`.",rig:p,actions:U3(s),acting:Nm,colors:{body:o.seat,ink:o.frame},wheelRadius:s,moves:{roll:{speed:Lm,perMetre:{wheelSpin:180/(Math.PI*s)}}}}}const Nm={depth:{wheelSpin:0,tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.03},eyes:[],headTurns:{},drift:[]};function Wm(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)}function U3(t){return{roll:{summary:"Rolls to `to` at `speed` px/ms (or over `for` ms): a small push-off, the wheels turning exactly the distance, and a gentle stop.",needs:["to"],uses:["speed","for"],run(e,n,s){const i=Math.sign(n.to-e.x);if(i===0)return{end:s};let o=s;e.facing()!==i&&(o=e.turnTo(o,i>0?"right":"left"));const r=Math.abs(n.to-e.x),a=n.for??Math.max(300,r/(n.speed??Lm*e.scale/1e3));return e.key(o+150,{tip:1.5*e.exaggeration},{act:!1,easing:"ease-out"}),Wm(e,o,o+a,n.to,"ease-in-out",t),e.key(o+a,{tip:0},{easing:"ease-out"}),{end:o+a}}},brake:{summary:"Stops short at `to`: the wheels lock and it skids the last bit, tipping forward a touch.",needs:["to"],uses:["for"],run(e,n,s){if(Math.sign(n.to-e.x)===0)return{end:s};const o=n.for??500;return Wm(e,s,s+o,n.to,"ease-out",t,!0),e.key(s+o,{tip:0},{easing:"ease-out"}),e.effect({kind:"dust",time:s+o*.5,x:n.to,y:e.floor,length:500}),{end:s+o,contact:s+o}}},wheelie:{summary:"Tips back onto its big wheels, balances there for `for` ms (default 1200), and drops down.",uses:["for"],run(e,n,s){const i=24*e.exaggeration,o=n.for??1200;return e.key(s+300,{tip:i},{easing:"ease-out"}),e.key(s+300+o*.5,{tip:i*.9},{act:!1,easing:"ease-in-out"}),e.key(s+300+o,{tip:i},{act:!1,easing:"ease-in-out"}),e.key(s+300+o+250,{tip:0},{easing:"ease-in"}),e.effect({kind:"dust",time:s+300+o+250,x:e.x,y:e.floor,length:400}),{end:s+300+o+250,contact:s+300+o+250}}}}}function Dm(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:V3(),acting:Kc,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:15,flies:!0,hold:{blur:1},perSecond:{rotor:nn*1e3}}}}}const Kc={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:[]},nn=2.6;function V3(){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,nn,"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,nn),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,nn),{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,nn),{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,nn),t(n,r,r+1600,nn,"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 Bm(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:Z3(),acting:Kc,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:30,flies:!0,hold:{blur:1},perSecond:{rotor:nn*1e3}}}}}const J3=3.2;function Z3(){const t=(n,s,i,o)=>{const r=n.values.rotor??0;n.set("rotor",s,r),n.set("rotor",i,r+J3*(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,p=i+o*d/l;n.key(p,{lift:h+r*(1-Math.cos(f)),pitch:u+360*d/l},{act:!1}),n.move(i+o*(d-1)/l,p,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 Es=["walk","trot","canter","gallop"],Q3=Es,zm=["fl","fr","hl","hr"],Ir={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}},sn=Math.PI/180;function Or(t,e){return 4*t*Math.sin(Ir[e].swing*sn)}function on(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},...e4(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((p,g)=>g===2?u*p:p):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=>`${Es.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:be,rotate:{axis:"x",degrees:1/be.length}}]},wag:{description:"Tail swung side to side, curling",unit:"degrees",bind:[{parts:be,rotate:{axis:"y",degrees:1/be.length}}]},ears:{description:"Ears pricked forward (+) or laid back (−), on a spring behind the motion",unit:"degrees",bind:[{parts:["ear-left","ear-right"],rotate:{axis:"x",degrees:1,pivot:[0,-t.ears.radii[1],0]}}]}};for(const u of zm){const d=u[0]==="f",f=u[1]==="l"?1:-1,p=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:[p,p*.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 g=`${d?"Front":"Hind"} ${f>0?"left":"right"} leg`;a[`${u}.swing`]={description:`${g}: forward (+) or back (−) from the hip`,unit:"degrees",bind:[{parts:[`${u}-upper`],rotate:{axis:"x",degrees:-1}}]},a[`${u}.knee`]={description:`${g}: knee (hock) folded`,unit:"degrees",bind:[{parts:[`${u}-lower`],rotate:{axis:"x",degrees:d?1:-1}}]},a[`${u}.ankle`]={description:`${g}: 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=>n4(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:{...i4(t,h),...t.actions?.(h)},acting:Gc,colors:{body:n.coat,ink:"#26262b"},follow:[{control:"tail",of:"x",per:.6,stiffness:90,damping:6,limit:40},{control:"ears",of:"x",per:1.4,stiffness:150,damping:8,limit:45}],moves:t4(t,s)}}function t4(t,e){const n=i=>{const o=Or(e,i);return{speed:o/(Ir[i].cycle*(t.cycleScale??1)/1e3),set:{gait:Es.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 be=Array.from({length:7},(t,e)=>e===0?"tail":`tail-${e}`);function e4(t,e,n){const s=Ql(t.tail.points,be.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/be.length),h=be.map((f,p)=>{const g=s[p],m=s[p+1],w=[m[0]-g[0],m[1]-g[1],m[2]-g[2]],v=p===0?void 0:s[p-1];return{id:f,...p>0?{parent:be[p-1]}:{},shape:{type:"tube",points:[[0,0,0],w],radius:[c(p),c(p+1)],segments:8,joined:!0},at:p===0?l:[g[0]-v[0],g[1]-v[1],g[2]-v[2]],fill:e.dark,outline:.8}}),u=s[s.length-1],d=s[s.length-2];return h.push({id:"tail-tip",parent:be[be.length-1],shape:{type:"ellipsoid",radii:Array(3).fill(c(be.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 n4(t,e,n){const s=Math.max(0,Math.min(1,t.walking??0));if(s===0)return{};const i=Es[Math.max(0,Math.min(3,Math.round(t.gait??0)))],o=Ir[e.gaits.includes(i)?i:e.gaits[0]],r=t.walk??0,a={};for(const c of zm){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 Xc(t){const n=Math.sin(32*sn),s=t.legLength-(t.front-t.hind)*n,i=72,r=(s-t.upper*Math.cos(i*sn)-t.foot)/t.lower,a=r>=1?0:r<=-1?180:Math.acos(r)/sn,l={pitch:32,lift:t.legLength*(1-Math.cos(32*sn))-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 Gc={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:[]},s4=Gc;function qm(t){const e=(t.upper+t.lower)*.32,n=Math.asin(Math.min(1,e/(t.upper+t.lower+t.foot)))/sn,s={pitch:0,lift:e-t.legLength,neck:-14,tail:t.tailHangs?60:-60,"fl.swing":90-n,"fr.swing":90-n,"fl.knee":0,"fr.knee":0,"fl.ankle":n,"fr.ankle":n};for(const i of["hl","hr"])s[`${i}.swing`]=70,s[`${i}.knee`]=-155,s[`${i}.ankle`]=85;return s}function i4(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 p=Math.abs(l.to-a.x)/a.scale/Or(e.legLength,r),g=l.for??Math.max(500,p*Ir[r].cycle*n),m=a.values.walk??0;return a.set("gait",u,a.values.gait??0),a.set("gait",u+1,Es.indexOf(r)),a.set("walking",u,0),a.set("walking",u+240,1,"ease-out"),a.set("walking",u+g-240,1),a.set("walking",u+g,0,"ease-in"),a.set("walk",u,m),a.move(u,u+g,l.to,{easing:"ease-in-out"}),a.set("walk",u+g,m+p,"ease-in-out"),a.key(u+g+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+g,x:l.to+h*e.legLength*.6*a.scale,y:a.floor,length:600,direction:h})),{end:u+g+300,contact:u,release:u+g}}}),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=Xc(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}}},lie:{summary:"Lies down for `for` ms (default 2000), head up and front paws forward (sinking back onto its haunches first), then gets up.",uses:["for"],run(r,a,l){const c=qm(e),h={...Xc(e)},u=l+400,d=u+450;r.key(u,h,{act:!1,easing:"ease-in-out"}),r.key(d,c,{act:!1,easing:"ease-in-out"}),r.key(d+(a.for??2e3),c,{act:!1});const f=d+(a.for??2e3)+600,p={};for(const g of new Set([...Object.keys(c),...Object.keys(h)]))p[g]=0;return r.key(f,p),{end:f,contact:d,release:f-600}}},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 p=Math.sign(a.to-r.x);p!==0&&r.facing()!==p&&r.turnTo(l,p>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 jm(t={}){return on({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*sn),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*sn);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 Ym(t={}){return on({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 Km(t={}){return on({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 Xm(t={}){return on({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 o4(t){return Or(1,t)}function Gm(t={}){return on({kind:t.kind??"goat",summary:t.summary??"A goat: walks, trots and gallops, bleats, grazes, sits, lies, jumps, and swishes its stubby tail.",legs:{upper:.22,lower:.2,foot:.05,footSize:[.07,.09],front:.26,hind:-.26,across:.1,thickness:[.045,.05],lowerThickness:.03},body:{radii:[.15,.17,.38],rise:.1},neck:{at:[0,.62,.3],points:[[0,0,0],[0,.16,.1]],radius:.07},head:{at:[0,.16,.1],radii:[.09,.1,.15],rotate:[-20,0,0]},muzzle:{at:[0,-.05,.13],radii:[.055,.05,.07]},ears:{at:[.1,.03,-.02],radii:[.06,.025,.03],rotate:[0,0,-20]},eyes:{at:[.065,.05,.09],size:.022},tail:{at:[0,.64,-.37],points:[[0,0,0],[0,.06,-.05]],radius:.025},extras:e=>[{id:"horn-left",parent:"head",shape:{type:"tube",points:[[0,0,0],[.01,.07,-.03],[.015,.12,-.08]],radius:.014,segments:6},at:[.045,.08,-.02],fill:e.dark},{id:"horn-right",parent:"head",shape:{type:"tube",points:[[0,0,0],[-.01,.07,-.03],[-.015,.12,-.08]],radius:.014,segments:6},at:[-.045,.08,-.02],fill:e.dark},{id:"beard",parent:"head",shape:{type:"ellipsoid",radii:[.025,.05,.02],segments:8},at:[0,-.12,.06],fill:e.accent,outline:.5}],colors:{coat:"#e9e2d3",dark:"#8c7b66",foot:"#4f4339",muzzle:"#d8cdb8",accent:"#cfc4b0",...t.colors},gaits:["walk","trot","gallop"],cycleScale:.8,call:"bleat",grazes:!0})}function Um(t={}){return on({kind:t.kind??"rabbit",summary:t.summary??"A rabbit: walks and hops (gallop), squeaks, nibbles the ground (graze), sits, lies and jumps; long ears and a puff of a tail.",legs:{upper:.07,lower:.07,foot:.03,footSize:[.04,.07],front:.11,hind:-.12,across:.06,thickness:[.028,.04],lowerThickness:.02},body:{radii:[.1,.11,.19],rise:.05},neck:{at:[0,.22,.14],points:[[0,0,0],[0,.06,.04]],radius:.05},head:{at:[0,.07,.04],radii:[.08,.075,.09]},muzzle:{at:[0,-.02,.07],radii:[.035,.028,.03]},ears:{at:[.035,.08,-.02],radii:[.022,.1,.03],rotate:[-15,0,-8]},eyes:{at:[.045,.015,.06],size:.02},tail:{at:[0,.2,-.18],points:[[0,0,0],[0,.03,-.02]],radius:.03},extras:()=>[{id:"nose",parent:"muzzle",shape:{type:"ellipsoid",radii:[.012,.009,.009],segments:8},at:[0,.012,.03],fill:"#e48a9a",outline:.4}],colors:{coat:"#c9b8a6",dark:"#9a8574",foot:"#b5a493",muzzle:"#eadfd2",accent:"#f4ece2",...t.colors},gaits:["walk","gallop"],cycleScale:.4,call:"squeak",grazes:!0})}function Vm(t={}){return on({kind:t.kind??"squirrel",summary:t.summary??"A squirrel: scampers (gallop) and walks, chatters, sits up, nibbles (graze), with a bushy tail curled over its back.",legs:{upper:.05,lower:.05,foot:.02,footSize:[.025,.04],front:.08,hind:-.08,across:.04,thickness:[.02,.025],lowerThickness:.014},body:{radii:[.065,.07,.14],rise:.03},neck:{at:[0,.16,.1],points:[[0,0,0],[0,.04,.03]],radius:.035},head:{at:[0,.05,.03],radii:[.055,.05,.06]},muzzle:{at:[0,-.015,.05],radii:[.025,.02,.02]},ears:{at:[.03,.05,-.01],radii:[.015,.03,.012],rotate:[0,0,-5]},eyes:{at:[.035,.012,.04],size:.015},tail:{at:[0,.14,-.13],points:[[0,0,0],[0,.08,-.06],[0,.2,-.04],[0,.26,.04]],radius:.045},colors:{coat:"#a9663a",dark:"#7a4523",foot:"#7a4523",muzzle:"#e9c9a8",accent:"#f0dcc4",...t.colors},gaits:["walk","gallop"],cycleScale:.3,call:"chatter",grazes:!0})}const rn=.6,Jm=75,Uc=80;function an(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*rn/2,t.wing.chord*.1,t.wing.chord/2],segments:12},at:[h*t.wing.span*rn/2,0,-t.wing.chord*.1],rotate:[-Uc,0,0],fill:e.wing,outline:.8}),a.push({id:`wing-${u}-tip`,parent:`wing-${u}-blade`,shape:{type:"ellipsoid",radii:[t.wing.span*rn/2.4,t.wing.chord*.06,t.wing.chord*.3],segments:10},at:[h*t.wing.span*rn/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-rn)/2,0,0],rotate:{axis:"x",degrees:Uc},scale:[1/rn,1,1]},{parts:["wing-right-blade"],translate:[-t.wing.span*(1-rn)/2,0,0],rotate:{axis:"x",degrees:Uc},scale:[1/rn,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)/Jm,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}}]},grip:{description:"The toes curled down round a perch: 0 flat on the ground, 1 gripping",unit:"0..1",min:0,max:1,bind:[{parts:["toes-left","toes-right"],rotate:{axis:"x",degrees:55}}]}},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 p=Math.sin(Math.PI*2*(h.step??0));u["leg.left"]=(h["leg.left"]??0)+f*28*p,u["leg.right"]=(h["leg.right"]??0)-f*28*p,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:a4(t),acting:Zm,colors:{body:e.body,ink:"#26262b"},moves:r4(t)}}function r4(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 Zm={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 a4(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 p=0;p<d;p++){const g=c+p*f;r.key(g+60,{squash:.85},{act:!1,easing:"ease-out"}),r.key(g+150,{squash:1.1,lift:t.legs.length*1.4,spread:.15},{act:!1,easing:"ease-out"}),r.key(g+f,{squash:.9,lift:0,spread:0},{act:!1,easing:"ease-in"}),r.move(g+60,g+f,h+(a.to-h)*(p+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),p=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,p),r.move(c,c+f,a.to,{easing:"ease-in-out"}),r.set("step",c+f,p+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:Jm},{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;r.key(l+60,{grip:0},{act:!1});const 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,p=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:p,x:r.x,y:r.floor,length:400})),r.key(p+100,{spread:1,squash:1.08,pitch:10},{act:!1,easing:"ease-out"}),r.set("flapping",p,r.values.flapping??0),r.set("flapping",p+100,1,"ease-out"),r.set("flapping",p+d,.6),n(r,p,p+d),r.key(p+d*.4,{lift:u,pitch:-5,squash:1},{act:!1,easing:"ease-out"}),r.key(p+d,{lift:u,pitch:0},{act:!1,easing:"ease-in-out"}),r.move(p,p+d,a.to,{easing:"ease-in-out"}),{end:p+d,contact:p,release:p+d}}},o.glide={summary:"Glides to `to` on still, spread wings, sinking gently to `height` metres (default: a third lower than it is); from the ground it takes off first, flying the first stretch.",needs:["to"],uses:["height","for"],run(r,a,l){let c=l;if(r.values.lift<=t.legs.length){const f=r.x+(a.to-r.x)/3;c=o.fly.run(r,{do:"fly",to:f,height:(a.height??1.5)*1.3},l).end}c=s(r,c,a.to);const h=r.values.lift,u=a.height??h*.67,d=a.for??Math.max(900,Math.abs(a.to-r.x)/.3);return r.set("flapping",c,r.values.flapping??1),r.set("flapping",c+250,0,"ease-out"),n(r,c,c+250),r.key(c+300,{spread:1,flap:10,pitch:-6},{act:!1,easing:"ease-out"}),r.key(c+d,{lift:u,pitch:-3,flap:10},{act:!1,easing:"ease-in-out"}),r.move(c,c+d,a.to,{easing:"ease-in-out"}),{end:c+d,contact:c,release:c+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,grip:h>0?1:0},{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,flap: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 Qm(t={}){return an({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 t1(t={}){return an({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 e1(t={}){return an({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})}function n1(t={}){return an({kind:"pigeon",summary:"A pigeon: walks with a bobbing head, pecks at crumbs, coos, flaps, flies and lands (on the ground, a ledge or a branch).",body:{radii:[.08,.075,.14],height:.14},head:{at:[0,.24,.12],radius:.045},beak:{length:.035,thickness:.014},wing:{shoulder:[.065,.17,.05],span:.24,chord:.11},tail:{at:[0,.13,-.13],length:.12,width:.08,raised:8},legs:{length:.06,across:.03},colors:{body:"#8d93a3",wing:"#6f7586",beak:"#5a5a66",legs:"#d9627a",belly:"#b9bdc8",...t.colors},call:"coo",beatsPerSecond:6,stoop:16})}function s1(t={}){return an({kind:"duck",summary:"A duck: waddles, dabbles with its bill (peck), quacks, flaps, flies and lands (on the ground or the water’s edge).",body:{radii:[.11,.1,.2],height:.16},head:{at:[0,.33,.15],radius:.055},beak:{length:.075,thickness:.028},wing:{shoulder:[.09,.22,.06],span:.28,chord:.13},tail:{at:[0,.17,-.19],length:.1,width:.09,raised:30},legs:{length:.07,across:.045},colors:{body:"#c9b48b",wing:"#8f7a55",beak:"#f2a71b",legs:"#f2a71b",belly:"#e8dcc0",...t.colors},call:"quack",beatsPerSecond:7,stoop:22,neckReach:.04})}function i1(t={}){return an({kind:"owl",summary:"An owl: a big round head, slow silent wingbeats; hoots, turns its head, flies and lands on a branch.",body:{radii:[.1,.12,.13],height:.19},head:{at:[0,.37,.07],radius:.085},beak:{length:.025,thickness:.02},wing:{shoulder:[.085,.27,.03],span:.34,chord:.18},tail:{at:[0,.14,-.12],length:.1,width:.1,raised:-10},legs:{length:.07,across:.04},colors:{body:"#9c7a55",wing:"#6e5538",beak:"#3d3028",legs:"#c9a76a",belly:"#e3cda8",...t.colors},call:"hoot",beatsPerSecond:3,stoop:6})}function o1(t={}){return an({kind:"parrot",summary:"A parrot: bright, with a big hooked beak and a long tail; squawks, bobs, flies and lands on a perch, gripping it.",body:{radii:[.07,.08,.13],height:.15},head:{at:[0,.29,.1],radius:.055},beak:{length:.045,thickness:.03},wing:{shoulder:[.06,.2,.05],span:.26,chord:.11},tail:{at:[0,.12,-.12],length:.22,width:.06,raised:-20},legs:{length:.06,across:.03},colors:{body:"#4caf50",wing:"#2e7d32",beak:"#5a5a66",legs:"#8d8d8d",belly:"#a5d66f",comb:"#d9372e",...t.colors},call:"squawk",beatsPerSecond:6,stoop:10})}const As={car:mm,truck:ym,bus:bm,tractor:wm,cart:km,trainCar:vm,bike:Mm,motorbike:Sm,tree:xm,house:Em,chair:$m,desk:Im,bed:_m,door:Hm,wheelchair:Fm,helicopter:Dm,airplane:Bm,horse:jm,dog:Ym,cat:Km,cow:Xm,goat:Gm,rabbit:Um,squirrel:Vm,songbird:Qm,crow:t1,chicken:e1,pigeon:n1,duck:s1,owl:i1,parrot:o1};function Vc(t,e={}){const n=As[t];if(!n)throw new Error(ft("prop preset",t,Object.keys(As)));return n(e)}const _r=["do","at","for","to","toward","speed","open","on","height","wind"],Jc={viewer:0,right:1,away:2,left:3},l4=420,Zc={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 Cr(t){return{...Zc,...t.actions}}const Qc=t=>typeof t=="number"&&Number.isFinite(t);function r1(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=Cr(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))_r.includes(c)||a(ft("beat field",c,_r,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&&!(Qc(l[c])&&l[c]>=0)&&a(`\`${c}\` must be a number ≥ 0 (got ${JSON.stringify(l[c])}).`);if(l.to!==void 0&&!Qc(l.to)&&a(`\`to\` is a scene x in px (got ${JSON.stringify(l.to)}).`),l.toward!==void 0&&!Qc(l.toward)&&!(typeof l.toward=="string"&&l.toward in Jc)){const c=typeof l.toward=="string"?qs(l.toward,Object.keys(Jc)):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 a1(t,e,n,s={}){const i=r1(n,e).filter(S=>S.level==="error");if(i.length>0)throw new Error(`propScript (${e.kind}): ${i.length} problem(s) in the beats:
60
+ `)}`);const o=n.map(d=>Yp(d,e)),r=Tr(t,o,s),a=d3(o,r.beats,s),l=s.ground??0,c=d=>s.ride===!1?d:Object.values(e).reduce((f,p)=>p.ride(f,t,{ground:l}),d);n.forEach((d,f)=>{for(const p of h3(d)){const g=y=>new Error(`surfaceScript: beat ${f} (${d.do}), ${p.edit} on ${p.surface}: ${y}`),m=(y,x)=>{const P=typeof y=="object"?y.beat:f,M=(typeof y=="object"?y.at:y)??x??"start",T=a[P][M];if(T===void 0){const S=vs.filter(E=>a[P][E]!==void 0).join(", ");throw g(`beat ${P} (${n[P].do}) has no ${M} (it has ${S})`)}return T},w=e[p.surface],v=m(p.at??(a[f].contact!==void 0?"contact":"start")),k=p.until===void 0?void 0:m(p.until,"end");if(k!==void 0&&k<v)throw g(`it ends (${k} ms) before it starts (${v} ms)`);try{if(p.edit==="carry"){const x=w.piece(p.anchor),P=Fc(t,c(r.tracks),{x:s.from??0,y:l,style:s.figureStyle??(s.height?{height:s.height}:void 0),cast:s,start:v,end:k});w.follow(x,P);continue}const y=Object.fromEntries(Object.entries(p).filter(([x])=>!l3.includes(x)));w.edit(p.edit,p.anchor,{...y,at:v,...k!==void 0?{duration:k-v}:{}})}catch(y){throw g(y.message)}}});const h=c(r.tracks),u=Object.entries(e).flatMap(([d,f])=>f.tracks(d));return{...r,tracks:[...h,...u],figureTracks:h}}function jp(t,e,n={}){if(!Array.isArray(t))return _i(t,n);const s=[],i=Object.keys(e),o=(c,h,u)=>{const d=typeof h=="string"?e[h]:void 0;return d||s.push({level:"error",beat:c,message:`${u}: ${ft("surface",h,i)}`}),d},r=(c,h,u,d)=>{if(typeof u!="string"){s.push({level:"error",beat:c,message:`${d}: \`anchor\` is a place name such as ${Object.keys(h.about.anchors).join(", ")} (got ${JSON.stringify(u)}).`});return}try{h.anchor(u,0)}catch(f){s.push({level:"error",beat:c,message:`${d}: ${f.message}`})}},a=(c,h,u)=>{const d=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:`${u}: \`beat\` is the index of this beat or a later one, ${c} to ${t.length-1} (got ${JSON.stringify(f)}).`}),d===void 0)return}typeof d=="number"?s.push({level:"error",beat:c,message:`${u}: a cue starts at a moment of its beat (${vs.join(", ")}), not at ms; set the beat's own \`at\` to move it.`}):(typeof d!="string"||!vs.includes(d))&&s.push({level:"error",beat:c,message:`${u}: ${ft("moment",d,vs)}`})};t.forEach((c,h)=>{if(!c||typeof c!="object"||Array.isArray(c))return;const u=c;for(const f of["target","to","onto"]){if(!Er(u[f]))continue;const p=u[f],g=o(h,p.surface,`\`${f}\``);g&&r(h,g,p.anchor,`\`${f}\``)}if(u.then===void 0)return;(Array.isArray(u.then)?u.then:[u.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 p=f,g=o(h,p.surface,"`then`");if(!g)return;const m=`\`then\` (${String(p.edit)} on ${String(p.surface)})`,w=[...Object.keys(g.about.edits),...c3];if(typeof p.edit!="string"||!w.includes(p.edit)){s.push({level:"error",beat:h,message:`\`then\`: ${ft("edit",p.edit,w)}`});return}for(const v of Array.isArray(p.anchor)?p.anchor:[p.anchor])r(h,g,v,m);p.edit==="carry"&&typeof p.anchor!="string"&&s.push({level:"error",beat:h,message:`${m}: \`carry\` takes one anchor, the piece it carries.`}),p.edit==="carry"&&p.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' }).`}),p.at!==void 0&&a(h,p.at,`${m} \`at\``),p.until!==void 0&&a(h,p.until,`${m} \`until\``),p.until!==void 0&&p.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)?Yp(c,e,!0):c);return[..._i(l,n),...s]}function Yp(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 Er(t.target)&&(r.target=o(t.target)),Er(t.to)&&(r.to=o(t.to).x),Er(t.onto)&&(r.onto=o(t.onto).top),r}function d3(t,e,n){let s=0;return t.map(i=>{const o=Sr([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 f3(t){const e={actions:t.actions,gaits:t.gaits},n=Ec(e);if(n.length>0)throw new Error(`persona "${t.name}": ${n.join(" ")}`);const s=[...Object.keys(Yt),...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 vt))throw new Error(`persona "${t.name}": ${ft("mood",t.mood,Object.keys(vt))}`);const o=t.acting??"snappy";if(typeof o=="string"&&!(o in Cn))throw new Error(`persona "${t.name}": ${ft("acting style",o,Object.keys(Cn))}`);if(typeof t.stance=="string"&&!(t.stance in ae))throw new Error(`persona "${t.name}": ${ft("stance",t.stance,Object.keys(ae))}`);const r=t.height??120,a=typeof t.stance=="string"?ae[t.stance]:Dt(t.stance??{}),l=t.mood?Xe(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=>Qa({x:u.x,y:u.y,pose:l,style:{...c,...u.facing?{facing:u.facing}:{}},cast:e}),script:(u,d,f={})=>Tr(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=>_i(u,e),handPath:(u,d,f)=>Fc(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:Ac(e),own:{actions:Object.keys(t.actions??{}),gaits:Object.keys(t.gaits??{})}})}}const g3=new Set(["x","y","walking","gait"]),Kp=.215+.205;function Xp(t,e,n=1){const{points:s}=fe(t,lt),i=s["hip.left"],o=s["knee.left"],r=s["ankle.left"],a=i&&o&&r?Math.hypot(o.x-i.x,o.y-i.y)+Math.hypot(r.x-o.x,r.y-o.y):Kp*t.height;return Uo(e,a/Kp,n)}function p3(t,e,n,s={}){const i=Tr(t,n,{...s,height:e.height,reach:s.reach??Gp(e)}),o=i.tracks.find(w=>w.property==="facing")?.keyframes??[],r=w=>{let v=s.facing??1;for(const k of o)k.time<=w&&(v=k.value);return v},a=To(i.keys),l=i.keys.map((w,v)=>{const k=fg(a[v]);return{time:w.time,pose:r(w.time)<0?Ld(k):k,...w.easing?{easing:w.easing}:{},...w.act===!1?{act:!1}:{}}}),{rest:c,start:h,...u}=s;b3(l,a,n,i,e,r,s);const d=Sp(t,l,u),f=hr(t,d,i.lines,{energy:s.energy}),p=i.tracks.filter(w=>g3.has(w.property)),g=i.tracks.find(w=>w.property==="walk");return{tracks:g?[...f,...p,x3(t,g,i.tracks,e,s)]:[...f,...p],duration:i.duration,lines:i.lines,keys:l,beats:i.beats,effects:i.effects}}function Gp(t){const e=kt({"arm.left.spread":90,"arm.left.elbow":0,"arm.left.bend":0,"leg.left.knee":0}),n=fe(t,e).points,s=Math.hypot(n["hand.left"].x-n["shoulder.left"].x,n["hand.left"].y-n["shoulder.left"].y),i=Math.hypot(n["toe.left"].x-n["hip.left"].x,n["toe.left"].y-n["hip.left"].y),o=me({...ut,rightShoulder:90,rightElbow:0,rightWrist:0},{height:t.height,facing:1}),r=me({...ut,rightHip:90,rightKnee:0},{height:t.height,facing:1}),a={x:(o.hands.right.x+o.fingertips.right.x)/2,y:(o.hands.right.y+o.fingertips.right.y)/2},l=Math.hypot(a.x-o.shoulders.right.x,a.y-o.shoulders.right.y),c=Math.hypot(r.feet.right.x-r.hip.x,r.feet.right.y-r.hip.y);return{arm:l>0?s/l:1,leg:c>0?i/c:1}}const m3={point:"arm",grab:"arm",put:"arm",write:"arm",swipe:"arm",push:"arm",kick:"leg"},y3=new Set(["point","grab","put","kick"]);function b3(t,e,n,s,i,o,r){const a=s.beats;if(n.length!==a.length)return;const l=new Ht({id:"placed",tracks:s.tracks.filter(h=>h.property==="x"||h.property==="y")}),c=h=>{const u=l.getStateAtTime(h).values.get(s.tracks[0]?.target??"");return{x:(r.from??0)+Number(u?.get("x")??0),y:(r.ground??0)+Number(u?.get("y")??0)}};n.forEach((h,u)=>{const d=m3[h.do],f=a[u];if(!d||f.contact===void 0||h.do!=="swipe"&&!h.target)return;const p=f.contact,g=f.release??f.contact;t.forEach((m,w)=>{if(m.time<p-1||m.time>g+1)return;const v=o(m.time),k=me(e[w],{height:i.height,facing:v<0?-1:1}),y=c(m.time),x=y3.has(h.do)&&h.target?{x:h.target.x-y.x,y:h.target.y-y.y}:void 0,P={x:(k.hands.right.x+k.fingertips.right.x)/2,y:(k.hands.right.y+k.fingertips.right.y)/2},M=x??(d==="arm"?P:k.toes.right),T=v<0?"right":"left",S=`${d}.${T}`;let E=m.pose;if(h.do==="point")E=Ce(i,E,S,M);else if(d==="arm")E=Ce(i,S3(i,E,T,M),S,M);else for(let $=0;$<3;$++){const A=fe(i,E).points,I=A[`ankle.${T}`],C=A[`toe.${T}`];E=Ce(i,E,S,{x:M.x-(C.x-I.x),y:M.y-(C.y-I.y)})}t[w]={...m,pose:E}})})}function w3(t,e){const n=kt({[`arm.${e}.spread`]:90,[`arm.${e}.elbow`]:0,[`arm.${e}.bend`]:0}),s=fe(t,n).points;return Math.hypot(s[`hand.${e}`].x-s[`shoulder.${e}`].x,s[`hand.${e}`].y-s[`shoulder.${e}`].y)}const k3=5,v3=4,M3=8;function S3(t,e,n,s){const i=w3(t,n)*.9,o=a=>{const l=fe(t,a).points[`shoulder.${n}`];return Math.hypot(s.x-l.x,s.y-l.y)<=i};if(o(e))return e;let r=e;for(let a=1;a<=M3;a++)if(r={...e,lean:(e.lean??0)+k3*a,bend:(e.bend??0)+v3*a},o(r))return r;return r}function x3(t,e,n,s,i){const o=n.find(u=>u.property==="gait"),r=o?new Ht({id:`${t}-gait-of`,tracks:[o]}):void 0,a=u=>{const d=r?.getStateAtTime(u).values.get(t)?.get("gait");if(typeof d=="string")return Yt[d]??i.gaits?.[d]??d},l=e.keyframes,c=[];let h=l[0]?.value??0;return l.forEach((u,d)=>{if(d>0){const f=l[d-1],p=a((f.time+u.time)/2),g=Mo(p,s.height),m=Xp(s,p);h+=(u.value-f.value)*(m>0?g/m:1)}else h=u.value;c.push({...u,value:h})}),{...e,keyframes:c}}const mt=["rect","circle","text","line","path","image","custom"],Ar={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:mt},y:{description:"Moves it down by this much from where it was placed (an offset)",unit:"px",types:mt},opacity:{description:"How opaque it is",unit:"0..1",min:0,max:1,types:mt},rotate:{description:"Turns it clockwise about its origin",unit:"degrees",types:mt},rotateX:{description:"Tips it about the horizontal axis (3D; shows with perspective)",unit:"degrees",types:mt},rotateY:{description:"Turns it about the vertical axis (3D; shows with perspective)",unit:"degrees",types:mt},z:{description:"Depth toward the viewer (shows with perspective)",unit:"px",types:mt},perspective:{description:"Distance from the viewer: nearer parts grow, further ones shrink",unit:"px",min:1,types:mt},scale:{description:"Size, both ways",unit:"factor",types:mt},scaleX:{description:"Width factor",unit:"factor",types:mt},scaleY:{description:"Height factor",unit:"factor",types:mt},skewX:{description:"Slants it sideways",unit:"degrees",types:mt},skewY:{description:"Slants it up and down",unit:"degrees",types:mt},originX:{description:"Transform pivot across its box",unit:"% (0 left, 50 centre, 100 right)",min:0,max:100,types:mt},originY:{description:"Transform pivot down its box",unit:"% (0 top, 50 centre, 100 bottom)",min:0,max:100,types:mt},fill:{description:"Fill colour (also written fillStyle)",kind:"color",types:mt},stroke:{description:"Outline colour (also written strokeStyle)",kind:"color",types:mt},strokeWidth:{description:"Outline width (also written lineWidth)",unit:"px",min:0,types:mt},clipTop:{description:"Hides this much from the top edge, for reveals",unit:"% of its height",min:0,max:100,types:mt},clipRight:{description:"Hides this much from the right edge",unit:"% of its width",min:0,max:100,types:mt},clipBottom:{description:"Hides this much from the bottom edge",unit:"% of its height",min:0,max:100,types:mt},clipLeft:{description:"Hides this much from the left edge",unit:"% of its width",min:0,max:100,types:mt},blur:{description:"Gaussian blur",unit:"px",min:0,types:mt},brightness:{description:"Brightness factor (1 unchanged)",unit:"factor",min:0,types:mt},glow:{description:"Soft glow around it, in glowColor",unit:"px",min:0,types:mt},glowColor:{description:"Colour of the glow",kind:"color",types:mt},shadowX:{description:"Drop shadow offset right",unit:"px",types:mt},shadowY:{description:"Drop shadow offset down",unit:"px",types:mt},shadowBlur:{description:"Drop shadow softness",unit:"px",min:0,types:mt},shadowColor:{description:"Drop shadow colour",kind:"color",types:mt},shine:{description:"A highlight sweeping across the fill",unit:"0..1 (progress)",min:0,max:1,types:mt},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:mt},quaternion:{description:'A rotation as [x, y, z, w] (a track with interpolation: "slerp")',kind:"list",types:mt}},Nc={fillStyle:"fill",strokeStyle:"stroke",lineWidth:"strokeWidth",rotateZ:"rotate",motionPathX:"x",motionPathY:"y",motionPathRotate:"rotate"},T3={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 Up(t){const e=t,n=Object.entries(Ar).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 Vp(t){const e=Up(t).properties.map(n=>n.name);return[...e,...Object.keys(Nc).filter(n=>e.includes(Nc[n]))]}function E3(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=Vp(r),l=r.type==="custom"&&r.acceptsProp?.(i.property);if(!a.includes(i.property)&&!l){o(`${i.target}: ${ft("property",i.property,a,T3[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=Ar[Nc[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 Ms=(t,e)=>t[2]<=-e;function Wc(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 Jp(t,e){if(t.every(s=>Ms(s,e)))return t;const n=[];return t.forEach((s,i)=>{const o=t[(i+t.length-1)%t.length],r=Ms(s,e),a=Ms(o,e);r!==a&&n.push(Wc(o,s,e)),r&&n.push(s)}),n.length>=3?n:[]}function A3(t,e){if(t.every(i=>Ms(i,e)))return[t];const n=[];let s=[];return t.forEach((i,o)=>{const r=Ms(i,e);if(o>0){const a=t[o-1],l=Ms(a,e);l&&!r?(s.push(Wc(a,i,e)),n.push(s),s=[]):!l&&r&&s.push(Wc(a,i,e))}r&&s.push(i)}),s.length>0&&n.push(s),n.filter(i=>i.length>=2)}function Zp(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 $3(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 P3(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=>ie(e,s)),faces:t.faces.map(s=>({corners:s.corners,normal:n(s.normal)}))}}function $r(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 I3(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=p=>{const g=p.map(w=>Math.round(w*1e6)).join(",");let m=c.get(g);return m===void 0&&(m=l.length,l.push(p),c.set(g,m)),m},u=[],d=p=>p===0,f=(p,g)=>p+2===g.length;for(const p of s){let g=p.points;d(r)||(g=$r(g,0,e[r],1)),g.length&&!f(r,e)&&(g=$r(g,0,e[r+1],-1)),g.length&&!d(a)&&(g=$r(g,2,n[a],1)),g.length&&!f(a,n)&&(g=$r(g,2,n[a+1],-1)),g.length>=3&&u.push({corners:g.map(h),normal:p.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 O3=new WeakMap,_3=new WeakMap,C3=48,Qp=t=>t.map(e=>Math.round(e*1e5)).join(",");function tm(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>=C3&&i.clear(),i.set(n,o=s())),o}function Dc(t,e){const n=Qp(e);return tm(O3,t,n,()=>{const s=P3(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 H3(t,e){const n=t.map(h=>({...h,...Dc(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=Zp(s[0],i[0],e),r=Zp(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:$3(o,r,d)}]}return tm(_3,h.inSpace,a,()=>I3(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 em=.004,Bc=.05,nm=new WeakMap;function R3(t){let e=nm.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)}),nm.set(t,e)),e}const sm=new WeakMap;function im(t){return t.filter(({mesh:e})=>R3(e)).map(({part:e,key:n,inSpace:s,low:i,high:o})=>{let r=sm.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]}}),sm.set(s,r)),{part:e,key:n,planes:r,low:i,high:o}})}function L3(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]-Bc||i[a]>o.high[a]+Bc))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)<=em))return l<-.9;const h=Math.abs(l)<.5?Bc:em;return c.every(u=>u<=h)}))return!0}return!1}const om=new WeakMap;function rm(t,e,n,s,i){const o=`${s}|${i.map(l=>l.key).join(";")}`;let r=om.get(e);r||om.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=>ie(n,h));a=e.faces.map(h=>L3(t,h.corners.map(u=>c[u]),l(h.normal),i)),r.set(o,a)}return a}const Ss={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}},zc=Math.PI/180;function am(t,e,n){return{toView:s=>ll(Qt(s,t*90*zc),-e*zc),toScreen:s=>({x:s[0]*n,y:-s[1]*n})}}const lm=new WeakMap,Hi=t=>Pr(t),Pr=t=>{let e=lm.get(t);return e||lm.set(t,e=Dg(t)),e};function It(t,e,n){return e[n]??t.controls[n]?.default??Ss[n]?.default??0}function Ri(t,e){const n=Math.max(.05,It(t,e,"squash")),s=1/Math.sqrt(n),o=[1,0,0,0,0,1,It(t,e,"lean"),0,0,0,1,0,0,0,0,1];return[pn([0,It(t,e,"lift"),0]),pe(Vt([1,0,0],-It(t,e,"pitch"))),pe(Vt([0,0,1],It(t,e,"roll"))),o,mn([s,n,s]),mn(Array(3).fill(Math.max(0,It(t,e,"size"))))].reduce((r,a)=>Rt(r,a))}function qc(t,e){const n=Ri(t,e),s=new Map,i=Object.entries(t.controls).flatMap(([r,a])=>(a.bind??[]).map(l=>({value:It(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=Rt(l?o(l):n,pn(r.at??[0,0,0]));if(r.rotate){const[h,u,d]=r.rotate;h&&(c=Rt(c,pe(Vt([1,0,0],h)))),u&&(c=Rt(c,pe(Vt([0,1,0],u)))),d&&(c=Rt(c,pe(Vt([0,0,1],d))))}for(const{value:h,bind:u}of i)if(!(!u.parts.includes(r.id)||h===0)){if(u.translate&&(c=Rt(c,pn([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,pn(d),pe(Vt(f,u.rotate.degrees*h)),pn([-d[0],-d[1],-d[2]])].reduce((p,g)=>Rt(p,g))}u.scale&&(c=Rt(c,mn([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 jc=(()=>{const t=[-.45,.75,.5],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),F3=Math.cos(35*zc);function Yc(t,e,n,s,i={}){const o=t.derive?{...e,...t.derive(e)}:e,r=qc(t,o),a=n.toView([0,0,0]),l=C=>D=>[C[0]*D[0]+C[4]*D[1]+C[8]*D[2],C[1]*D[0]+C[5]*D[1]+C[9]*D[2],C[2]*D[0]+C[6]*D[1]+C[10]*D[2]],c=Ri(t,o),h=i.slice===void 0?null:Ma(c),u=h?t.parts.map(C=>({part:C,mesh:Pr(C.shape),local:Rt(h,r.get(C.id)),whole:C.shape.type==="tube"})):void 0,d=u?H3(u,i.slice):void 0,f=u?im(u.map(C=>({part:C.part.id,mesh:C.mesh,...Dc(C.mesh,C.local)}))):void 0,p=(C,D,j,V)=>{const et=Z=>n.toView(ie(j,Z)),G=D.vertices.map(et),F=G.map(Z=>n.toScreen(Z)),H=i.perspective?i.near:void 0,W=Z=>Z.map(rt=>n.toScreen(rt)),_=Z=>H===void 0?Z:Jp(Z,H),B=Z=>H===void 0?[Z]:A3(Z,H),Q=l(j),O=D.faces.map(Z=>{const rt=n.toView(Q(Z.normal)),ht=[rt[0]-a[0],rt[1]-a[1],rt[2]-a[2]],dt=Math.hypot(...ht)||1;return[ht[0]/dt,ht[1]/dt,ht[2]/dt]}),R=f&&V?rm(C.id,D,V,Qp(V),f):void 0,z=Z=>R?.[Z]??!1,K=O.map((Z,rt)=>{if(z(rt))return!1;if(!i.perspective)return Z[2]>1e-6;const dt=D.faces[rt].corners.reduce((bt,wt)=>[bt[0]+G[wt][0],bt[1]+G[wt][1],bt[2]+G[wt][2]],[0,0,0]);return-(Z[0]*dt[0]+Z[1]*dt[1]+Z[2]*dt[2])>1e-9}),N=Z=>D.faces[Z].corners.reduce((rt,ht)=>rt+G[ht][2],0)/D.faces[Z].corners.length,q=D.faces.map((Z,rt)=>({face:Z,i:rt})).filter(({i:Z})=>K[Z]).map(({face:Z,i:rt})=>({i:rt,solved:{points:H===void 0?Z.corners.map(ht=>F[ht]):W(_(Z.corners.map(ht=>G[ht]))),depth:N(rt),tone:.72+.33*Math.max(0,O[rt][0]*jc[0]+O[rt][1]*jc[1]+O[rt][2]*jc[2])}})).filter(Z=>Z.solved.points.length>=3).sort((Z,rt)=>Z.solved.depth-rt.solved.depth);if(i.light){const Z=l(j);for(const{i:rt,solved:ht}of q){const dt=D.faces[rt].corners,bt=dt.reduce((ph,Nx)=>{const mh=ie(j,D.vertices[Nx]);return[ph[0]+mh[0]/dt.length,ph[1]+mh[1]/dt.length,ph[2]+mh[2]/dt.length]},[0,0,0]),wt=Z(D.faces[rt].normal),ge=Math.hypot(...wt)||1,zi=i.light(bt,[wt[0]/ge,wt[1]/ge,wt[2]/ge]);ht.light=zi.light,ht.fog=zi.fog}}const Y=q.map(Z=>Z.solved),J=N3(D),X=[],tt=[];for(const[Z,rt]of J){const ht=rt.filter(bt=>K[bt]).length;if(ht===0)continue;const dt=rt.length===2&&ht===2&&D.creases!==!1&&O[rt[0]][0]*O[rt[1]][0]+O[rt[0]][1]*O[rt[1]][1]+O[rt[0]][2]*O[rt[1]][2]<F3;rt.length===1&&(D.joined||W3(D,Z))||(rt.length===1||ht===1||dt)&&(X.push(Z.split("-").map(Number)),tt.push(rt.filter(bt=>K[bt]).reduce((bt,wt)=>N(wt)>N(bt)?wt:bt)))}const nt=Z=>D.faces.findIndex(rt=>rt.corners.length>4&&Math.sign(B3(D.vertices[Z],rt.normal))>0),L=(D.marks??[]).filter(([Z])=>nt(Z)<0||K[nt(Z)]),U=([Z,rt])=>H===void 0?[[F[Z],F[rt]]]:B([G[Z],G[rt]]).map(W),ot=L.flatMap(U),at=Z=>H===void 0?[Z.map(rt=>F[rt])]:B(Z.map(rt=>G[rt])).map(W);if(i.slice!==void 0){const Z=new Map;X.forEach((rt,ht)=>Z.set(tt[ht],[...Z.get(tt[ht])??[],rt]));for(const{i:rt,solved:ht}of q){ht.edges=dm(Z.get(rt)??[]).flatMap(at);const dt=D.faces[rt].corners;ht.center=dt.reduce((wt,ge)=>[wt[0]+G[ge][0]/dt.length,wt[1]+G[ge][1]/dt.length,wt[2]+G[ge][2]/dt.length],[0,0,0]),ht.normal=O[rt];const bt=q[q.length-1].i;ht.marks=L.filter(([wt])=>(nt(wt)>=0?nt(wt):bt)===rt).flatMap(U)}}const it=C.glow?Math.max(0,Math.min(1,It(t,o,C.glow.control))):0,ct=C.fade?Math.max(0,Math.min(1,It(t,o,C.fade.control))):0,st=C.fade?Math.max(0,Math.min(1,C.fade.from+(C.fade.to-C.fade.from)*ct)):1;return{part:C,depth:G.reduce((Z,rt)=>Z+rt[2],0)/Math.max(1,G.length),faces:Y,edges:dm(X).flatMap(at),marks:ot,glow:it,opacity:st,...C.shape.type==="tube"?{spine:D3(B(C.shape.points.map(et)).map(W))}:{},...D.walls?{cut:!0}:{}}},g=new Map(u?.map(C=>[C.part.id,C.local])),w=(d?d.pieces.map(C=>({part:C.part,mesh:C.mesh,m:C.cut?c:r.get(C.part.id),local:C.cut?oo():g.get(C.part.id),cell:C.cell})):t.parts.map(C=>({part:C,mesh:Pr(C.shape),m:r.get(C.id),local:void 0,cell:void 0}))).map(C=>({cell:C.cell,solved:p(C.part,C.mesh,C.m,C.local)})),v=w.map(C=>C.solved),k=C=>C.filter(D=>D.faces.length>0&&D.opacity>.01).sort((D,j)=>D.depth-j.depth);let y;if(d){const C=new Map(t.parts.map(j=>{const V=r.get(j.id),et=Pr(j.shape).vertices;return[j.id,et.reduce((G,F)=>G+n.toView(ie(V,F))[2],0)/Math.max(1,et.length)]})),D=new Map;for(const j of w){const V=j.cell.join(",");D.has(V)||D.set(V,{cell:j.cell,parts:[]}),D.get(V).parts.push(j.solved),j.solved.depth=C.get(j.solved.part.id)}y=[...D.values()].map(({cell:j,parts:V})=>({depth:n.toView(ie(c,d.middle(j)))[2],parts:k(V)})).filter(j=>j.parts.length>0)}const x={};for(const[C,D]of Object.entries(t.anchors??{})){const j=D.part?r.get(D.part):Ri(t,o);if(!j)throw new Error(`prop rig: anchor "${C}" is on "${D.part}", which is not a part`);const V=n.toView(ie(j,D.at));x[C]={point:n.toScreen(V),depth:V[2]}}const[P,M]=t.footprint??[t.length*.45,t.length],T=Math.max(0,It(t,o,"lift")),S=Math.max(0,It(t,o,"size"))/(1+T*.8),E=Array.from({length:24},(C,D)=>{const j=Math.PI*2*D/24;return n.toView([Math.cos(j)*P*.55*S,0,Math.sin(j)*M*.55*S])}),$=i.perspective?i.near:void 0,A={points:($===void 0?E:Jp(E,$)).map(C=>n.toScreen(C)),opacity:.16*S},I=v.filter(C=>C.part.seeThrough&&C.opacity>.01).flatMap(C=>C.faces.map(D=>D.points));return{under:k(v.filter(C=>!C.part.overRider)),over:k(v.filter(C=>C.part.overRider)),...y?{cells:y}:{},anchors:x,openings:I,shadow:A,pxPerUnit:s,sizePx:t.height*s}}const cm=new WeakMap;function N3(t){let e=cm.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])}}cm.set(t,e)}return e}function hm(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=qc(t,n),i=Ma(Ri(t,n))??oo(),o=r=>Math.max(0,Math.min(1,r));return t.parts.map(r=>{const a=r.fade?o(It(t,n,r.fade.control)):0;return{part:r,matrix:s.get(r.id),local:Rt(i,s.get(r.id)),glow:r.glow?o(It(t,n,r.glow.control)):0,opacity:r.fade?o(r.fade.from+(r.fade.to-r.fade.from)*a):1}})}function um(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=qc(t,n),i=Ri(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]=ie(l,a.at)}return o}function W3(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 D3(t){return t.reduce((e,n)=>!e||n.length>e.length?n:e,void 0)}const B3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2];function dm(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 Kc(t,e){if(!t.loose?.size)return;const n={};for(const[s,i]of t.loose)n[s]={x:e[`piece.${i}.x`]??0,y:e[`piece.${i}.y`]??0,rotate:e[`piece.${i}.rotate`]??0,opacity:e[`piece.${i}.opacity`]??1};return n}function Xc(t){const e={};for(const[n,s]of Object.entries({...Ss,...t.rig.controls})){const{bind:i,...o}=s;e[n]=o}return e}function fm(t){const{prop:e}=t,n=t.scale??60,s=e.rig.length*n*1.4,i=e.rig.height*n*1.6,o=Xc(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),Yl(l,xs(e,u,n),{...a,time:h,loose:Kc(c,u)})}}}function xs(t,e,n){const s=am(It(t.rig,e,"turn"),It(t.rig,e,"tilt"),n);return Yc(t.rig,e,s,n)}function Ir(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=xs(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 z3(t,e,n,s,i={}){const o=Ir(e,n,s);return t.save(),t.translate(o.origin.x,o.origin.y),Yl(t,o.solved,{...e.propDraw,time:n.time,loose:Kc(e,o.values),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 Ts={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…); it can come loose as a piece","control:NAME":"where the parts a control moves or lights are (control:door is the doors, control:lights the lamps; a control of the whole prop, like lift, is its box)"},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",move:"a part; { at, to: an anchor name or { x, y }, duration? }: carry the part there, loose",fling:"a part; { at, velocity?, spin?, gravity?, duration? }: knock the part off on a spinning arc"}},q3=400,j3=.2;function Y3(t,e={}){const{prop:n}=t,s=Xc(n),i=Object.keys(s),o=Object.keys(n.rig.anchors??{}),r=n.rig.parts.map(P=>P.id),a=ms(),l=Si(a),c=e.tracks?.length?new Ht({id:`${n.kind}-surface`,tracks:e.tracks}):void 0,h=Math.max(0,...(e.tracks??[]).flatMap(P=>P.keyframes.map(M=>M.time))),u=new Map,d=new Map;t.loose=d;const f=t.props,p=P=>{const M={...t.props};let T=0,S=0;if(c){const E=c.getStateAtTime(Math.min(P,h));for(const $ of E.values.values())for(const[A,I]of $)typeof I=="number"&&(A==="x"?T=I:A==="y"?S=I:A in M&&(M[A]=I))}for(const E of i)a.keys(E)?.length&&(M[E]=a.valueAt(E,P));return{values:M,origin:{x:t.x+t.width/2+T,y:t.y+t.height+S}}},g=P=>{const{kind:M,rest:T}=In(P),S=E=>tn(n.kind,P,Ts,E);if(M==="box"){if(T)throw S("box takes no arguments");return{kind:M}}if(M==="anchor"){if(!o.includes(T))throw S(ft(`${n.kind} anchor`,T,o));return{kind:M,name:T}}if(M==="part"){if(!r.includes(T))throw S(ft(`${n.kind} part`,T,r));return{kind:M,name:T}}if(M==="control"){if(!i.includes(T))throw S(ft(`${n.kind} control`,T,i));return{kind:M,name:T}}throw S()},m=P=>{const M=(n.rig.controls[P]?.bind??[]).flatMap(S=>S.parts),T=n.rig.parts.filter(S=>S.glow?.control===P).map(S=>S.id);return new Set([...M,...T])},w=new Map,v=P=>{let M=w.get(P);if(!M){const T=p(P);w.set(P,M={...T,solved:xs(n,T.values,t.propScale)})}return M},k=(P,M)=>{const T=g(P),{values:S,origin:E,solved:$}=v(M);if(T.kind==="box")return Mt(E.x-t.width/2,E.y-t.height,t.width,t.height);if(T.kind==="anchor"){const C=$.anchors[T.name].point,D=j3*t.propScale;return Mt(E.x+C.x-D/2,E.y+C.y-D/2,D,D)}if(T.kind==="part")return I(new Set([T.name]),`part "${T.name}" is`);const A=m(T.name);if(A.size===0)return Mt(E.x-t.width/2,E.y-t.height,t.width,t.height);return I(A,`the parts control "${T.name}" moves are`);function I(C,D){const j=[...$.under,...$.over].filter(H=>C.has(H.part.id)).flatMap(H=>H.faces.flatMap(W=>W.points));if(j.length===0){const H=Number.isFinite(M)?`at ${M} ms`:"after its edits";throw new Error(`${n.kind}: ${D} turned away from the viewer ${H}; aim at an anchor (${o.map(W=>`anchor:${W}`).join(", ")||"none"}) or box`)}const V=j.map(H=>H.x),et=j.map(H=>H.y),G=Math.min(...V),F=Math.min(...et);return Mt(E.x+G,E.y+F,Math.max(...V)-G,Math.max(...et)-F)}},y=(P,M)=>{try{return k(P,M)}catch{return}},x={kind:"prop",prop:t,about:Ts,target:t,box:Mt(t.x,t.y,t.width,t.height),anchor(P,M=1/0){return k(P,M)},piece(P){const M=g(P);if(M.kind!=="part")throw new Error(`${n.kind}: a piece is a part, part:ID (${r.slice(0,6).map($=>`part:${$}`).join(", ")}…), not "${P}"`);const T=u.get(M.name);if(T)return T;const S=[M.name];for(let $=0;$<S.length;$++)for(const A of n.rig.parts)A.parent===S[$]&&!S.includes(A.id)&&S.push(A.id);const E={id:u.size+1,part:M.name,home:k(P,0)};u.set(M.name,E);for(const $ of S)d.set($,E.id);for(const $ of["x","y","rotate"])f[`piece.${E.id}.${$}`]=0;return f[`piece.${E.id}.opacity`]=1,E},edit(P,M,T){if(!(P in Ts.edits))throw xi(n.kind,P,Ts);const S=Array.isArray(M)?M:[M];if(S.length===0)throw new Error(`${n.kind}.edit: ${P} takes at least one anchor`);if(w.clear(),P==="move"||P==="fling"){if(S.length>1)throw new Error(`${n.kind}.edit: ${P} takes one part anchor`);const E=x.piece(S[0]);if(P==="fling")return x.fling(E,T);const $=T.to;if(!$)throw new Error(`${n.kind}.edit: move needs \`to\`, an anchor name or { x, y }`);const A=typeof $=="string"?k($,T.at):void 0;return x.move(E,{...T,to:A?{x:A.left+A.width/2,y:A.top+A.height/2}:$})}for(const E of S){const $=g(E);if($.kind!=="control")throw new Error(`${n.kind}.edit: ${P} takes control anchors (control:${i.join(", control:")}), not "${E}"`);const A=s[$.name];let I;if(P==="set"){if(typeof T.value!="number"||!Number.isFinite(T.value))throw new Error(`${n.kind}.edit: set needs \`value\`, a number (${$.name}: ${A.description})`);I=T.value}else I=T.on===!1?A.default??A.min??0:A.max??1;a.tween($.name,p(T.at).values[$.name],I,T,q3)}return x},follow(P,M){return w.clear(),l.follow(P,M),x},fling(P,M){return w.clear(),l.fling(P,M),x},move(P,M){return w.clear(),l.move(P,M),x},ride(P,M,T){const S=[...i.flatMap($=>ys(a.keys($))),...(e.tracks??[]).flatMap($=>ys($.keyframes.filter(A=>typeof A.value=="number")))];if(S.length===0)return P;const E=[...o.map($=>`anchor:${$}`),...r.map($=>`part:${$}`)].flatMap($=>{const A=y($,0);return A?[{top:A.top,offset:I=>(y($,I)?.top??A.top)-A.top,windows:S}]:[]});return gr(P,M,{ground:T.ground,every:T.every??Qe,floors:E})},tracks:a.tracks};return x}const K3={body:"#e8574a",trim:"#3b3b44",glass:"#bfe3f2",tyre:"#2c2c33",hub:"#c9ccd3",light:"#fff4b8",tail:"#ff5a4f",inside:"#3b3640",seat:"#6d5d55"};function Fe(t){const e={...K3,...t.colors},n=[],{forwardMost:s,backMost:i,top:o}=gm(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,p]of(t.cabin.pillars??[]).entries())n.push({id:`pillar-${f}`,shape:{type:"box",size:[h+.02,d-u,.1]},at:[0,(u+d)/2,p],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 p of d){const g=`wheel-${u}-${p>0?"left":p<0?"right":"middle"}`;if(a.push({parts:[g],rotate:{axis:"x",degrees:r/h.radius}}),n.push({id:g,shape:{type:"cylinder",radius:h.radius,length:f,axis:"x",segments:20,spokes:h.style==="spoked"?8:0},at:[p*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 p===0?[1,-1]:[p])n.push({id:`${g}-hub${p===0?m>0?"-left":"-right":""}`,parent:g,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,p=[[h,d],[u,d],[u,f],[h,f]];for(const g of[1,-1]){const m=g>0?"left":"right";n.push({id:`doorway-${m}`,shape:{type:"panel",points:p,facing:g>0?"left":"right"},at:[g*(t.width/2+.004),0,0],fill:e.inside,outline:.5,seeThrough:!0});const w=h+(u-h)*.15,v=h+(u-h)*.55;n.push({id:`seat-back-${m}`,shape:{type:"panel",points:[[w,d+.05],[v,d+.05],[v-.08,f-.06],[w+.06,f-.04]],facing:g>0?"left":"right"},at:[g*(t.width/2+.006),0,0],fill:e.seat,outline:.4}),n.push({id:`door-${m}`,shape:{type:"panel",points:p.map(([k,y])=>[k-u,y]),facing:g>0?"left":"right"},at:[g*(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:p}=t.lights,g=(t.lights.size??.32)/2,m=[[-g,u],[g,u],[g,d],[-g,d]];for(const w of[1,-1])n.push({id:`headlight-${w}`,shape:{type:"panel",points:m,facing:"front"},at:[w*h,0,f],fill:e.light,outline:.6,glow:{control:"lights",color:"#ffffff"}}),n.push({id:`taillight-${w}`,shape:{type:"panel",points:m,facing:"back"},at:[w*h,0,p],fill:lr(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:X3(t),acting:pm,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 gm(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 pm={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 Or(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 mm=.4;function X3(t){const e=t.wheels[0]?.radius??.4,{forwardMost:n,backMost:s}=gm(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"}),Or(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),p=l.for??Math.max(500,f/(l.speed??mm));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,p-160),{pitch:0,lean:.08*d,squash:1.02},{act:!1}),Or(a,u,u+p,l.to,"ease-in-out",e),r(a,u+p,!1),{end:u+p+380,contact:u,release:u+p}}},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,p=Math.abs(l.to-f),g=l.for??Math.max(600,p/(l.speed??mm*1.2)),m=u+g*.55,w=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"}),Or(a,u,m,w,"ease-in",e),a.key(m+80,{pitch:-7*d,lean:-.12*d,squash:.94},{act:!1,easing:"ease-out"}),Or(a,m,u+g,l.to,"ease-out",e,!0),a.effect({kind:"skid",time:m,x:w,toX:l.to,y:a.floor,length:g*.45+1500}),a.effect({kind:"dust",time:u+g,x:l.to+h*i*a.scale,y:a.floor,length:600,direction:h}),r(a,u+g,!0),{end:u+g+380,contact:m,release:u+g}}},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 ym(t={}){return Fe({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 bm(t={}){return Fe({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 wm(t={}){return Fe({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 km(t={}){return Fe({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 vm(t={}){const e=t.colors?.body??"#a8743f";return Fe({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 Mm(t={}){return Fe({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 Sm(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 Fe({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 xm(t={}){return Fe({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 Tm(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=je(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),p=[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:p,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:G3(),acting:Em,colors:{body:o.leaves}}}const Em={depth:{sway:1,canopySway:2,size:0,squash:1},limits:{sway:2,canopySway:3,squash:.08},eyes:[],headTurns:{},drift:[]};function G3(){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 Am(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((g,m)=>{d.push({id:`window-${m}`,shape:{type:"panel",points:[[-g.width/2,g.low],[g.width/2,g.low],[g.width/2,g.low+g.height],[-g.width/2,g.low+g.height]],facing:"front"},at:[g.at,0,a+.01],fill:r.glass,outline:.8,glow:{control:"lights",color:r.lit}})});for(const g of[1,-1])d.push({id:`side-window-${g>0?"left":"right"}`,shape:{type:"panel",points:[[-.4,1],[.4,1],[.4,1.8],[-.4,1.8]],facing:g>0?"left":"right"},at:[g*(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 g=s+i*(1-Math.abs(f.back)/(n/2+o)),m=s+i+.45;d.push({id:"chimney",shape:{type:"box",size:[.42,m-g+.3,.42]},at:[f.at,(m+g-.3)/2,f.back],fill:r.chimney,layer:1})}const p={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:p,actions:U3(!!f),acting:$m,colors:{body:r.walls}}}const $m={depth:{door:1,lights:0,roll:1,squash:1,size:0},limits:{door:.1,roll:1.5,squash:.05},eyes:[],headTurns:{},drift:[]};function U3(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 Pm(t={}){const e=t.width??.46,n=t.depth??.46,s=t.seatHeight??.46,i=t.backHeight??.95,o={wood:"#8a5a3b",seat:"#c48a4a",...t.colors},r=.05,a=.025,l=[{id:"seat",shape:{type:"box",size:[e,r,n]},at:[0,s-r/2,0],fill:o.seat},{id:"back",shape:{type:"box",size:[e,i-s,r]},at:[0,(i+s)/2,-n/2+r/2],fill:o.wood}];for(const[h,u,d]of[[-1,1,"front-left"],[1,1,"front-right"],[-1,-1,"back-left"],[1,-1,"back-right"]])l.push({id:`leg-${d}`,shape:{type:"tube",points:[[0,0,0],[0,s-r,0]],radius:a,segments:6},at:[h*(e/2-a*1.5),0,u*(n/2-a*1.5)],fill:o.wood});const c={parts:l,controls:{tip:{description:"Tipped back on its rear legs (+), degrees",unit:"degrees",min:0,max:60,bind:[{parts:l.map(h=>h.id),rotate:{axis:"x",degrees:1,pivot:[0,0,-n/2+a*1.5]}}]}},length:n,height:i,footprint:[e,n],anchors:{seat:{at:[0,s,0]},back:{at:[0,i,-n/2]},front:{at:[0,0,n/2+.3]}}};return{kind:t.kind??"chair",family:"furniture",summary:t.summary??"A chair: a seat to sit on (`seat`), tips back on its rear legs and settles, or falls over.",rig:c,actions:V3(),acting:Im,colors:{body:o.seat}}}const Im={depth:{tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.05},eyes:[],headTurns:{},drift:[]};function V3(){return{tip:{summary:"Tips back on its rear legs for `for` ms (default 1200), rocking a little, then settles down.",uses:["for"],run(t,e,n){const s=18*t.exaggeration,i=e.for??1200;return t.key(n+350,{tip:s},{easing:"ease-out"}),t.key(n+350+i*.4,{tip:s*.85},{act:!1,easing:"ease-in-out"}),t.key(n+350+i*.7,{tip:s},{act:!1,easing:"ease-in-out"}),t.key(n+350+i,{tip:0},{easing:"ease-in"}),{end:n+350+i,contact:n+350}}},fall:{summary:"Falls over backwards onto its back and bounces, with dust.",uses:["for"],run(t,e,n){const s=e.for??700;return t.key(n+s*.6,{tip:90},{act:!1,easing:"ease-in"}),t.key(n+s*.75,{tip:82},{act:!1,easing:"ease-out"}),t.key(n+s,{tip:90},{act:!1,easing:"ease-in"}),t.effect({kind:"dust",time:n+s*.6,x:t.x,y:t.floor,length:600}),{end:n+s,contact:n+s*.6}}}}}function Om(t={}){const e=t.width??1.4,n=t.depth??.7,s=t.height??.75,i={wood:"#8a5a3b",top:"#a9754a",knob:"#2b2b2b",...t.colors},o=.04,r=.03,a=.14,l=e*.4,c=[{id:"top",shape:{type:"box",size:[e,o,n]},at:[0,s-o/2,0],fill:i.top},{id:"drawer",shape:{type:"box",size:[l,a,n*.8]},at:[-e/2+l/2+.05,s-o-a/2,0],fill:i.wood},{id:"knob",parent:"drawer",shape:{type:"ellipsoid",radii:[.02,.02,.015],segments:8},at:[0,0,n*.4+.012],fill:i.knob,outline:.6}];for(const[u,d,f]of[[-1,1,"front-left"],[1,1,"front-right"],[-1,-1,"back-left"],[1,-1,"back-right"]])c.push({id:`leg-${f}`,shape:{type:"tube",points:[[0,0,0],[0,s-o,0]],radius:r,segments:6},at:[u*(e/2-r*2),0,d*(n/2-r*2)],fill:i.wood});const h={parts:c,controls:{drawer:{description:"The drawer out: 0 shut, 1 open",unit:"0..1",min:0,max:1,bind:[{parts:["drawer"],translate:[0,0,n*.5]}]}},length:n,height:s,footprint:[e,n],anchors:{top:{at:[0,s,0]},edge:{at:[0,s,n/2]},drawer:{part:"drawer",at:[0,0,n*.4]},chair:{at:[0,0,n/2+.35]}}};return{kind:t.kind??"desk",family:"furniture",summary:t.summary??"A desk: a top to work at (`top`, `edge`), a drawer that opens (`drawer`), a place for a chair in front (`chair`).",rig:h,actions:{drawer:{summary:"Opens the drawer (`open: true`) or shuts it (`open: false`).",needs:["open"],run(u,d,f){return u.key(f+400,{drawer:d.open?1:0},{easing:d.open?"ease-out":"ease-in"}),{end:f+500,contact:f+400}}}},acting:_m,colors:{body:i.top}}}const _m={depth:{drawer:1,roll:1,squash:1,size:0},limits:{drawer:.08,roll:1,squash:.04},eyes:[],headTurns:{},drift:[]};function Cm(t={}){const e=t.length??2,n=t.width??1,s=t.height??.55,i=t.headboard??.95,o={wood:"#8a5a3b",mattress:"#f1ece2",blanket:"#5b7fb0",pillow:"#fbf8f2",...t.colors},r=.3,a=s-r,c={parts:[{id:"frame",shape:{type:"box",size:[n,r,e]},at:[0,r/2,0],fill:o.wood},{id:"headboard",shape:{type:"box",size:[n+.06,i-r,.06]},at:[0,(i+r)/2,-e/2-.03],fill:o.wood},{id:"mattress",shape:{type:"box",size:[n-.04,a,e-.04]},at:[0,r+a/2,0],fill:o.mattress},{id:"blanket",parent:"mattress",shape:{type:"box",size:[n-.02,.04,e*.62]},at:[0,a/2+.02,e*.19],fill:o.blanket,outline:.7},{id:"pillow",parent:"mattress",shape:{type:"ellipsoid",radii:[n*.32,.07,.22],segments:12},at:[0,a/2+.06,-e/2+.32],fill:o.pillow,outline:.7}],controls:{give:{description:"The mattress pressed down: 1 as made, below squashed (someone landed on it)",unit:"factor",default:1,min:.5,max:1.2,bind:[{parts:["mattress"],scale:[1,1,1]}]}},length:e,height:i,footprint:[n,e],anchors:{mattress:{part:"mattress",at:[0,a/2,0]},pillow:{part:"mattress",at:[0,a/2+.1,-e/2+.32]},foot:{at:[0,s,e/2]},side:{at:[n/2+.25,0,0]}}};return{kind:t.kind??"bed",family:"furniture",summary:t.summary??"A bed: a mattress to lie on (`mattress`, `pillow`) that gives and springs back when someone lands on it (`bounce`), a side to sit on (`side`).",rig:c,actions:{bounce:{summary:"The mattress gives (someone landed on it) and springs back over `for` ms (default 700).",uses:["for"],run(h,u,d){const f=u.for??700,p=h.exaggeration;return h.key(d+90,{give:1-.18*p},{act:!1,easing:"ease-out"}),h.key(d+f*.45,{give:1+.05*p},{act:!1,easing:"ease-in-out"}),h.key(d+f*.7,{give:1-.04*p},{act:!1,easing:"ease-in-out"}),h.key(d+f,{give:1}),{end:d+f,contact:d+90}}}},acting:Hm,colors:{body:o.blanket}}}const Hm={depth:{give:1,roll:1,squash:1,size:0},limits:{give:.03,roll:.5,squash:.03},eyes:[],headTurns:{},drift:[]};function Rm(t={}){const e=t.width??.9,n=t.height??2.05,s=t.hinge??"left",i={frame:"#d9d2c3",door:"#7a4b2a",handle:"#c9a227",beyond:"#2a2f3a",...t.colors},o=.1,r=s==="left"?1:-1,a=r>0?[[0,0],[-e,0],[-e,n],[0,n]]:[[0,0],[e,0],[e,n],[0,n]],c={parts:[{id:"post-left",shape:{type:"box",size:[o,n+o,o]},at:[e/2+o/2,(n+o)/2,0],fill:i.frame},{id:"post-right",shape:{type:"box",size:[o,n+o,o]},at:[-e/2-o/2,(n+o)/2,0],fill:i.frame},{id:"lintel",shape:{type:"box",size:[e+o*2,o,o]},at:[0,n+o/2,0],fill:i.frame},{id:"beyond",shape:{type:"panel",points:[[-e/2,0],[e/2,0],[e/2,n],[-e/2,n]],facing:"front"},at:[0,0,-.03],fill:i.beyond,outline:.4,seeThrough:!0},{id:"door",shape:{type:"panel",points:a,facing:"front"},at:[r*e/2,0,.005],fill:i.door,outline:.9,overRider:!0},{id:"handle",parent:"door",shape:{type:"ellipsoid",radii:[.03,.03,.03],segments:8},at:[-r*(e-.1),n*.47,.03],fill:i.handle,outline:.5}],controls:{open:{description:"How far the door is open: 0 shut, 1 open wide",unit:"0..1",min:0,max:1,bind:[{parts:["door"],rotate:{axis:"y",degrees:r*-95}}]}},length:.3,height:n+o,footprint:[e+o*2,.3],anchors:{handle:{part:"door",at:[-r*(e-.1),n*.47,.03]},doorway:{at:[0,0,0]},front:{at:[0,0,.5]},beyond:{at:[0,0,-.5]}}};return{kind:t.kind??"door",family:"furniture",summary:t.summary??"A door in its frame: opens and shuts on its hinge (`open`), slams, rattles when knocked; a figure goes through the `doorway` from `front` to `beyond`.",rig:c,actions:J3(),acting:Lm,colors:{body:i.door}}}const Lm={depth:{open:1,roll:1,squash:1,size:0},limits:{open:.08,roll:.6,squash:.03},eyes:[],headTurns:{},drift:[]};function J3(){return{open:{summary:"Opens the door (`open: true`, default) or shuts it (`open: false`), over `for` ms (default 600).",uses:["open","for"],run(t,e,n){const s=e.for??600;return t.key(n+s,{open:e.open===!1?0:1},{easing:"ease-in-out"}),{end:n+s+80,contact:n+s}}},slam:{summary:"Slams shut: a fast swing, a shudder in the frame, dust.",run(t,e,n){const s=t.exaggeration;t.key(n+180,{open:0},{act:!1,easing:"ease-in"});for(let i=1;i<=4;i++)t.key(n+180+i*70,{roll:(i%2===0?1:-1)*1.2*s*(1-i/5)},{act:!1});return t.key(n+180+350,{roll:0}),t.effect({kind:"dust",time:n+180,x:t.x,y:t.floor,length:500}),{end:n+180+350,contact:n+180}}},knock:{summary:"Someone knocks three times: the door rattles over `for` ms (default 700).",uses:["for"],run(t,e,n){const i=e.for??700,o=t.exaggeration;for(let r=0;r<3;r++){const a=n+i*(r+.5)/3;t.key(a,{open:.03*o},{act:!1,easing:"ease-out"}),t.key(a+60,{open:0},{act:!1,easing:"ease-in"})}return{end:n+i,contact:n+i/6}}}}}const Fm=1.4;function Nm(t={}){const e=t.width??.5,n=t.seatHeight??.5,s=t.wheelRadius??.3,i=.08,o={frame:"#2b2f36",seat:"#3c6ea5",tyre:"#1f2328",...t.colors},r=.04,a=.018,l=.44,c=n+.5,h=-.08,u=e/2+.06,d=[{id:"seat",shape:{type:"box",size:[e,r,l]},at:[0,n-r/2,0],fill:o.seat},{id:"back",shape:{type:"box",size:[e,c-n-.02,r]},at:[0,(c+n)/2,-l/2+r/2],fill:o.seat},{id:"footrest",shape:{type:"box",size:[e*.8,.02,.14]},at:[0,.12,l/2+.22],fill:o.frame}];for(const[g,m]of[[-1,"left"],[1,"right"]]){const w=g*u,v=(k,y,x=a)=>{d.push({id:k,shape:{type:"tube",points:y,radius:x,segments:6},fill:o.frame,outline:.7})};v(`post-${m}`,[[w,n-.1,-l/2],[w,c+.04,-l/2],[w,c+.04,-l/2-.14]]),v(`rail-${m}`,[[w,n-.03,-l/2],[w,n-.03,l/2]]),v(`leg-${m}`,[[w,n-.03,l/2],[w*.85,i,l/2+.06]]),v(`strut-${m}`,[[w*.85,i+.08,l/2+.04],[w*.8,.13,l/2+.22]]),v(`armrest-${m}`,[[w,n+.22,-l/2+.02],[w,n+.22,l/2-.08]],a*1.3),d.push({id:`wheel-${m}`,shape:{type:"cylinder",radius:s,length:.04,axis:"x",segments:20,spokes:8},at:[w+g*.03,s,h],ink:o.tyre,outline:1.3}),d.push({id:`rim-${m}`,shape:{type:"cylinder",radius:s*.9,length:.012,axis:"x",segments:20},at:[g*.045,0,0],parent:`wheel-${m}`,ink:o.frame,outline:.8}),d.push({id:`castor-${m}`,shape:{type:"cylinder",radius:i,length:.03,axis:"x",segments:12,spokes:3},at:[w*.85,i,l/2+.06],fill:o.tyre})}const f=d.map(g=>g.id).filter(g=>!g.startsWith("rim-")),p={parts:d,controls:{wheelSpin:{description:"How far the big wheels have turned, degrees (keyed with the distance rolled, so they never skate); the castors turn faster",unit:"degrees",bind:[{parts:["wheel-left","wheel-right"],rotate:{axis:"x",degrees:1}},{parts:["castor-left","castor-right"],rotate:{axis:"x",degrees:s/i}}]},tip:{description:"Tipped back on its big wheels (+), degrees: a wheelie, or a helper tipping it up a kerb",unit:"degrees",min:0,max:45,bind:[{parts:f,rotate:{axis:"x",degrees:1,pivot:[0,s,h]}}]}},length:l+.4,height:c+.04,footprint:[u*2+.1,l+.4],anchors:{seat:{at:[0,n,.02]},handles:{at:[0,0,-l/2-.5]},front:{at:[0,0,l/2+.6]},footrest:{at:[0,.13,l/2+.22]}}};return{kind:t.kind??"wheelchair",family:"furniture",summary:t.summary??"A wheelchair: rolls to `to` with its wheels turning the distance (roll), brakes, tips back on its big wheels (wheelie); its `seat` is ridden in the `wheeling` pose and a pusher stands at `handles`.",rig:p,actions:Z3(s),acting:Wm,colors:{body:o.seat,ink:o.frame},wheelRadius:s,moves:{roll:{speed:Fm,perMetre:{wheelSpin:180/(Math.PI*s)}}}}}const Wm={depth:{wheelSpin:0,tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.03},eyes:[],headTurns:{},drift:[]};function Dm(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)}function Z3(t){return{roll:{summary:"Rolls to `to` at `speed` px/ms (or over `for` ms): a small push-off, the wheels turning exactly the distance, and a gentle stop.",needs:["to"],uses:["speed","for"],run(e,n,s){const i=Math.sign(n.to-e.x);if(i===0)return{end:s};let o=s;e.facing()!==i&&(o=e.turnTo(o,i>0?"right":"left"));const r=Math.abs(n.to-e.x),a=n.for??Math.max(300,r/(n.speed??Fm*e.scale/1e3));return e.key(o+150,{tip:1.5*e.exaggeration},{act:!1,easing:"ease-out"}),Dm(e,o,o+a,n.to,"ease-in-out",t),e.key(o+a,{tip:0},{easing:"ease-out"}),{end:o+a}}},brake:{summary:"Stops short at `to`: the wheels lock and it skids the last bit, tipping forward a touch.",needs:["to"],uses:["for"],run(e,n,s){if(Math.sign(n.to-e.x)===0)return{end:s};const o=n.for??500;return Dm(e,s,s+o,n.to,"ease-out",t,!0),e.key(s+o,{tip:0},{easing:"ease-out"}),e.effect({kind:"dust",time:s+o*.5,x:n.to,y:e.floor,length:500}),{end:s+o,contact:s+o}}},wheelie:{summary:"Tips back onto its big wheels, balances there for `for` ms (default 1200), and drops down.",uses:["for"],run(e,n,s){const i=24*e.exaggeration,o=n.for??1200;return e.key(s+300,{tip:i},{easing:"ease-out"}),e.key(s+300+o*.5,{tip:i*.9},{act:!1,easing:"ease-in-out"}),e.key(s+300+o,{tip:i},{act:!1,easing:"ease-in-out"}),e.key(s+300+o+250,{tip:0},{easing:"ease-in"}),e.effect({kind:"dust",time:s+300+o+250,x:e.x,y:e.floor,length:400}),{end:s+300+o+250,contact:s+300+o+250}}}}}function Bm(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:Q3(),acting:Gc,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:15,flies:!0,hold:{blur:1},perSecond:{rotor:nn*1e3}}}}}const Gc={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:[]},nn=2.6;function Q3(){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,nn,"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,nn),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,nn),{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,nn),{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,nn),t(n,r,r+1600,nn,"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 zm(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:e4(),acting:Gc,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:30,flies:!0,hold:{blur:1},perSecond:{rotor:nn*1e3}}}}}const t4=3.2;function e4(){const t=(n,s,i,o)=>{const r=n.values.rotor??0;n.set("rotor",s,r),n.set("rotor",i,r+t4*(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,p=i+o*d/l;n.key(p,{lift:h+r*(1-Math.cos(f)),pitch:u+360*d/l},{act:!1}),n.move(i+o*(d-1)/l,p,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 Es=["walk","trot","canter","gallop"],n4=Es,qm=["fl","fr","hl","hr"],_r={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}},sn=Math.PI/180;function Cr(t,e){return 4*t*Math.sin(_r[e].swing*sn)}function on(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},...i4(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((p,g)=>g===2?u*p:p):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=>`${Es.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:be,rotate:{axis:"x",degrees:1/be.length}}]},wag:{description:"Tail swung side to side, curling",unit:"degrees",bind:[{parts:be,rotate:{axis:"y",degrees:1/be.length}}]},ears:{description:"Ears pricked forward (+) or laid back (−), on a spring behind the motion",unit:"degrees",bind:[{parts:["ear-left","ear-right"],rotate:{axis:"x",degrees:1,pivot:[0,-t.ears.radii[1],0]}}]}};for(const u of qm){const d=u[0]==="f",f=u[1]==="l"?1:-1,p=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:[p,p*.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 g=`${d?"Front":"Hind"} ${f>0?"left":"right"} leg`;a[`${u}.swing`]={description:`${g}: forward (+) or back (−) from the hip`,unit:"degrees",bind:[{parts:[`${u}-upper`],rotate:{axis:"x",degrees:-1}}]},a[`${u}.knee`]={description:`${g}: knee (hock) folded`,unit:"degrees",bind:[{parts:[`${u}-lower`],rotate:{axis:"x",degrees:d?1:-1}}]},a[`${u}.ankle`]={description:`${g}: 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=>o4(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:{...a4(t,h),...t.actions?.(h)},acting:Vc,colors:{body:n.coat,ink:"#26262b"},follow:[{control:"tail",of:"x",per:.6,stiffness:90,damping:6,limit:40},{control:"ears",of:"x",per:1.4,stiffness:150,damping:8,limit:45}],moves:s4(t,s)}}function s4(t,e){const n=i=>{const o=Cr(e,i);return{speed:o/(_r[i].cycle*(t.cycleScale??1)/1e3),set:{gait:Es.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 be=Array.from({length:7},(t,e)=>e===0?"tail":`tail-${e}`);function i4(t,e,n){const s=ec(t.tail.points,be.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/be.length),h=be.map((f,p)=>{const g=s[p],m=s[p+1],w=[m[0]-g[0],m[1]-g[1],m[2]-g[2]],v=p===0?void 0:s[p-1];return{id:f,...p>0?{parent:be[p-1]}:{},shape:{type:"tube",points:[[0,0,0],w],radius:[c(p),c(p+1)],segments:8,joined:!0},at:p===0?l:[g[0]-v[0],g[1]-v[1],g[2]-v[2]],fill:e.dark,outline:.8}}),u=s[s.length-1],d=s[s.length-2];return h.push({id:"tail-tip",parent:be[be.length-1],shape:{type:"ellipsoid",radii:Array(3).fill(c(be.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 o4(t,e,n){const s=Math.max(0,Math.min(1,t.walking??0));if(s===0)return{};const i=Es[Math.max(0,Math.min(3,Math.round(t.gait??0)))],o=_r[e.gaits.includes(i)?i:e.gaits[0]],r=t.walk??0,a={};for(const c of qm){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 Uc(t){const n=Math.sin(32*sn),s=t.legLength-(t.front-t.hind)*n,i=72,r=(s-t.upper*Math.cos(i*sn)-t.foot)/t.lower,a=r>=1?0:r<=-1?180:Math.acos(r)/sn,l={pitch:32,lift:t.legLength*(1-Math.cos(32*sn))-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 Vc={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:[]},r4=Vc;function jm(t){const e=(t.upper+t.lower)*.32,n=Math.asin(Math.min(1,e/(t.upper+t.lower+t.foot)))/sn,s={pitch:0,lift:e-t.legLength,neck:-14,tail:t.tailHangs?60:-60,"fl.swing":90-n,"fr.swing":90-n,"fl.knee":0,"fr.knee":0,"fl.ankle":n,"fr.ankle":n};for(const i of["hl","hr"])s[`${i}.swing`]=70,s[`${i}.knee`]=-155,s[`${i}.ankle`]=85;return s}function a4(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 p=Math.abs(l.to-a.x)/a.scale/Cr(e.legLength,r),g=l.for??Math.max(500,p*_r[r].cycle*n),m=a.values.walk??0;return a.set("gait",u,a.values.gait??0),a.set("gait",u+1,Es.indexOf(r)),a.set("walking",u,0),a.set("walking",u+240,1,"ease-out"),a.set("walking",u+g-240,1),a.set("walking",u+g,0,"ease-in"),a.set("walk",u,m),a.move(u,u+g,l.to,{easing:"ease-in-out"}),a.set("walk",u+g,m+p,"ease-in-out"),a.key(u+g+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+g,x:l.to+h*e.legLength*.6*a.scale,y:a.floor,length:600,direction:h})),{end:u+g+300,contact:u,release:u+g}}}),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=Uc(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}}},lie:{summary:"Lies down for `for` ms (default 2000), head up and front paws forward (sinking back onto its haunches first), then gets up.",uses:["for"],run(r,a,l){const c=jm(e),h={...Uc(e)},u=l+400,d=u+450;r.key(u,h,{act:!1,easing:"ease-in-out"}),r.key(d,c,{act:!1,easing:"ease-in-out"}),r.key(d+(a.for??2e3),c,{act:!1});const f=d+(a.for??2e3)+600,p={};for(const g of new Set([...Object.keys(c),...Object.keys(h)]))p[g]=0;return r.key(f,p),{end:f,contact:d,release:f-600}}},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 p=Math.sign(a.to-r.x);p!==0&&r.facing()!==p&&r.turnTo(l,p>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 Ym(t={}){return on({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*sn),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*sn);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 Km(t={}){return on({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 Xm(t={}){return on({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 Gm(t={}){return on({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 l4(t){return Cr(1,t)}function Um(t={}){return on({kind:t.kind??"goat",summary:t.summary??"A goat: walks, trots and gallops, bleats, grazes, sits, lies, jumps, and swishes its stubby tail.",legs:{upper:.22,lower:.2,foot:.05,footSize:[.07,.09],front:.26,hind:-.26,across:.1,thickness:[.045,.05],lowerThickness:.03},body:{radii:[.15,.17,.38],rise:.1},neck:{at:[0,.62,.3],points:[[0,0,0],[0,.16,.1]],radius:.07},head:{at:[0,.16,.1],radii:[.09,.1,.15],rotate:[-20,0,0]},muzzle:{at:[0,-.05,.13],radii:[.055,.05,.07]},ears:{at:[.1,.03,-.02],radii:[.06,.025,.03],rotate:[0,0,-20]},eyes:{at:[.065,.05,.09],size:.022},tail:{at:[0,.64,-.37],points:[[0,0,0],[0,.06,-.05]],radius:.025},extras:e=>[{id:"horn-left",parent:"head",shape:{type:"tube",points:[[0,0,0],[.01,.07,-.03],[.015,.12,-.08]],radius:.014,segments:6},at:[.045,.08,-.02],fill:e.dark},{id:"horn-right",parent:"head",shape:{type:"tube",points:[[0,0,0],[-.01,.07,-.03],[-.015,.12,-.08]],radius:.014,segments:6},at:[-.045,.08,-.02],fill:e.dark},{id:"beard",parent:"head",shape:{type:"ellipsoid",radii:[.025,.05,.02],segments:8},at:[0,-.12,.06],fill:e.accent,outline:.5}],colors:{coat:"#e9e2d3",dark:"#8c7b66",foot:"#4f4339",muzzle:"#d8cdb8",accent:"#cfc4b0",...t.colors},gaits:["walk","trot","gallop"],cycleScale:.8,call:"bleat",grazes:!0})}function Vm(t={}){return on({kind:t.kind??"rabbit",summary:t.summary??"A rabbit: walks and hops (gallop), squeaks, nibbles the ground (graze), sits, lies and jumps; long ears and a puff of a tail.",legs:{upper:.07,lower:.07,foot:.03,footSize:[.04,.07],front:.11,hind:-.12,across:.06,thickness:[.028,.04],lowerThickness:.02},body:{radii:[.1,.11,.19],rise:.05},neck:{at:[0,.22,.14],points:[[0,0,0],[0,.06,.04]],radius:.05},head:{at:[0,.07,.04],radii:[.08,.075,.09]},muzzle:{at:[0,-.02,.07],radii:[.035,.028,.03]},ears:{at:[.035,.08,-.02],radii:[.022,.1,.03],rotate:[-15,0,-8]},eyes:{at:[.045,.015,.06],size:.02},tail:{at:[0,.2,-.18],points:[[0,0,0],[0,.03,-.02]],radius:.03},extras:()=>[{id:"nose",parent:"muzzle",shape:{type:"ellipsoid",radii:[.012,.009,.009],segments:8},at:[0,.012,.03],fill:"#e48a9a",outline:.4}],colors:{coat:"#c9b8a6",dark:"#9a8574",foot:"#b5a493",muzzle:"#eadfd2",accent:"#f4ece2",...t.colors},gaits:["walk","gallop"],cycleScale:.4,call:"squeak",grazes:!0})}function Jm(t={}){return on({kind:t.kind??"squirrel",summary:t.summary??"A squirrel: scampers (gallop) and walks, chatters, sits up, nibbles (graze), with a bushy tail curled over its back.",legs:{upper:.05,lower:.05,foot:.02,footSize:[.025,.04],front:.08,hind:-.08,across:.04,thickness:[.02,.025],lowerThickness:.014},body:{radii:[.065,.07,.14],rise:.03},neck:{at:[0,.16,.1],points:[[0,0,0],[0,.04,.03]],radius:.035},head:{at:[0,.05,.03],radii:[.055,.05,.06]},muzzle:{at:[0,-.015,.05],radii:[.025,.02,.02]},ears:{at:[.03,.05,-.01],radii:[.015,.03,.012],rotate:[0,0,-5]},eyes:{at:[.035,.012,.04],size:.015},tail:{at:[0,.14,-.13],points:[[0,0,0],[0,.08,-.06],[0,.2,-.04],[0,.26,.04]],radius:.045},colors:{coat:"#a9663a",dark:"#7a4523",foot:"#7a4523",muzzle:"#e9c9a8",accent:"#f0dcc4",...t.colors},gaits:["walk","gallop"],cycleScale:.3,call:"chatter",grazes:!0})}const rn=.6,Zm=75,Jc=80;function an(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*rn/2,t.wing.chord*.1,t.wing.chord/2],segments:12},at:[h*t.wing.span*rn/2,0,-t.wing.chord*.1],rotate:[-Jc,0,0],fill:e.wing,outline:.8}),a.push({id:`wing-${u}-tip`,parent:`wing-${u}-blade`,shape:{type:"ellipsoid",radii:[t.wing.span*rn/2.4,t.wing.chord*.06,t.wing.chord*.3],segments:10},at:[h*t.wing.span*rn/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-rn)/2,0,0],rotate:{axis:"x",degrees:Jc},scale:[1/rn,1,1]},{parts:["wing-right-blade"],translate:[-t.wing.span*(1-rn)/2,0,0],rotate:{axis:"x",degrees:Jc},scale:[1/rn,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)/Zm,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}}]},grip:{description:"The toes curled down round a perch: 0 flat on the ground, 1 gripping",unit:"0..1",min:0,max:1,bind:[{parts:["toes-left","toes-right"],rotate:{axis:"x",degrees:55}}]}},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 p=Math.sin(Math.PI*2*(h.step??0));u["leg.left"]=(h["leg.left"]??0)+f*28*p,u["leg.right"]=(h["leg.right"]??0)-f*28*p,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:h4(t),acting:Qm,colors:{body:e.body,ink:"#26262b"},moves:c4(t)}}function c4(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 Qm={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 h4(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 p=0;p<d;p++){const g=c+p*f;r.key(g+60,{squash:.85},{act:!1,easing:"ease-out"}),r.key(g+150,{squash:1.1,lift:t.legs.length*1.4,spread:.15},{act:!1,easing:"ease-out"}),r.key(g+f,{squash:.9,lift:0,spread:0},{act:!1,easing:"ease-in"}),r.move(g+60,g+f,h+(a.to-h)*(p+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),p=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,p),r.move(c,c+f,a.to,{easing:"ease-in-out"}),r.set("step",c+f,p+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:Zm},{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;r.key(l+60,{grip:0},{act:!1});const 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,p=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:p,x:r.x,y:r.floor,length:400})),r.key(p+100,{spread:1,squash:1.08,pitch:10},{act:!1,easing:"ease-out"}),r.set("flapping",p,r.values.flapping??0),r.set("flapping",p+100,1,"ease-out"),r.set("flapping",p+d,.6),n(r,p,p+d),r.key(p+d*.4,{lift:u,pitch:-5,squash:1},{act:!1,easing:"ease-out"}),r.key(p+d,{lift:u,pitch:0},{act:!1,easing:"ease-in-out"}),r.move(p,p+d,a.to,{easing:"ease-in-out"}),{end:p+d,contact:p,release:p+d}}},o.glide={summary:"Glides to `to` on still, spread wings, sinking gently to `height` metres (default: a third lower than it is); from the ground it takes off first, flying the first stretch.",needs:["to"],uses:["height","for"],run(r,a,l){let c=l;if(r.values.lift<=t.legs.length){const f=r.x+(a.to-r.x)/3;c=o.fly.run(r,{do:"fly",to:f,height:(a.height??1.5)*1.3},l).end}c=s(r,c,a.to);const h=r.values.lift,u=a.height??h*.67,d=a.for??Math.max(900,Math.abs(a.to-r.x)/.3);return r.set("flapping",c,r.values.flapping??1),r.set("flapping",c+250,0,"ease-out"),n(r,c,c+250),r.key(c+300,{spread:1,flap:10,pitch:-6},{act:!1,easing:"ease-out"}),r.key(c+d,{lift:u,pitch:-3,flap:10},{act:!1,easing:"ease-in-out"}),r.move(c,c+d,a.to,{easing:"ease-in-out"}),{end:c+d,contact:c,release:c+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,grip:h>0?1:0},{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,flap: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 t1(t={}){return an({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 e1(t={}){return an({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 n1(t={}){return an({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})}function s1(t={}){return an({kind:"pigeon",summary:"A pigeon: walks with a bobbing head, pecks at crumbs, coos, flaps, flies and lands (on the ground, a ledge or a branch).",body:{radii:[.08,.075,.14],height:.14},head:{at:[0,.24,.12],radius:.045},beak:{length:.035,thickness:.014},wing:{shoulder:[.065,.17,.05],span:.24,chord:.11},tail:{at:[0,.13,-.13],length:.12,width:.08,raised:8},legs:{length:.06,across:.03},colors:{body:"#8d93a3",wing:"#6f7586",beak:"#5a5a66",legs:"#d9627a",belly:"#b9bdc8",...t.colors},call:"coo",beatsPerSecond:6,stoop:16})}function i1(t={}){return an({kind:"duck",summary:"A duck: waddles, dabbles with its bill (peck), quacks, flaps, flies and lands (on the ground or the water’s edge).",body:{radii:[.11,.1,.2],height:.16},head:{at:[0,.33,.15],radius:.055},beak:{length:.075,thickness:.028},wing:{shoulder:[.09,.22,.06],span:.28,chord:.13},tail:{at:[0,.17,-.19],length:.1,width:.09,raised:30},legs:{length:.07,across:.045},colors:{body:"#c9b48b",wing:"#8f7a55",beak:"#f2a71b",legs:"#f2a71b",belly:"#e8dcc0",...t.colors},call:"quack",beatsPerSecond:7,stoop:22,neckReach:.04})}function o1(t={}){return an({kind:"owl",summary:"An owl: a big round head, slow silent wingbeats; hoots, turns its head, flies and lands on a branch.",body:{radii:[.1,.12,.13],height:.19},head:{at:[0,.37,.07],radius:.085},beak:{length:.025,thickness:.02},wing:{shoulder:[.085,.27,.03],span:.34,chord:.18},tail:{at:[0,.14,-.12],length:.1,width:.1,raised:-10},legs:{length:.07,across:.04},colors:{body:"#9c7a55",wing:"#6e5538",beak:"#3d3028",legs:"#c9a76a",belly:"#e3cda8",...t.colors},call:"hoot",beatsPerSecond:3,stoop:6})}function r1(t={}){return an({kind:"parrot",summary:"A parrot: bright, with a big hooked beak and a long tail; squawks, bobs, flies and lands on a perch, gripping it.",body:{radii:[.07,.08,.13],height:.15},head:{at:[0,.29,.1],radius:.055},beak:{length:.045,thickness:.03},wing:{shoulder:[.06,.2,.05],span:.26,chord:.11},tail:{at:[0,.12,-.12],length:.22,width:.06,raised:-20},legs:{length:.06,across:.03},colors:{body:"#4caf50",wing:"#2e7d32",beak:"#5a5a66",legs:"#8d8d8d",belly:"#a5d66f",comb:"#d9372e",...t.colors},call:"squawk",beatsPerSecond:6,stoop:10})}const As={car:ym,truck:bm,bus:wm,tractor:km,cart:vm,trainCar:Mm,bike:Sm,motorbike:xm,tree:Tm,house:Am,chair:Pm,desk:Om,bed:Cm,door:Rm,wheelchair:Nm,helicopter:Bm,airplane:zm,horse:Ym,dog:Km,cat:Xm,cow:Gm,goat:Um,rabbit:Vm,squirrel:Jm,songbird:t1,crow:e1,chicken:n1,pigeon:s1,duck:i1,owl:o1,parrot:r1};function Zc(t,e={}){const n=As[t];if(!n)throw new Error(ft("prop preset",t,Object.keys(As)));return n(e)}const Hr=["do","at","for","to","toward","speed","open","on","height","wind"],Qc={viewer:0,right:1,away:2,left:3},u4=420,th={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 Rr(t){return{...th,...t.actions}}const eh=t=>typeof t=="number"&&Number.isFinite(t);function a1(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=Rr(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))Hr.includes(c)||a(ft("beat field",c,Hr,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&&!(eh(l[c])&&l[c]>=0)&&a(`\`${c}\` must be a number ≥ 0 (got ${JSON.stringify(l[c])}).`);if(l.to!==void 0&&!eh(l.to)&&a(`\`to\` is a scene x in px (got ${JSON.stringify(l.to)}).`),l.toward!==void 0&&!eh(l.toward)&&!(typeof l.toward=="string"&&l.toward in Qc)){const c=typeof l.toward=="string"?Ys(l.toward,Object.keys(Qc)):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 l1(t,e,n,s={}){const i=a1(n,e).filter(S=>S.level==="error");if(i.length>0)throw new Error(`propScript (${e.kind}): ${i.length} problem(s) in the beats:
61
61
  ${i.map(S=>` beat ${S.beat}: ${S.message}`).join(`
62
- `)}`);const o=s.from??0,r=s.ground??0,a=s.scale??60,l=s.exaggeration??1,c=Cr(e),h={};for(const S of[...Object.keys(Ss),...Object.keys(e.rig.controls)])h[S]=s.start?.[S]??It(e.rig,{},S);const u=[{time:0,pose:{...h}}],d=new Map,f=[];let p=o,g=r;const m=(S,E,$,A)=>{const I=d.get(S)??[{time:0,value:S==="x"||S==="y"?0:h[S]}];I.push({time:E,value:$,...A?{easing:A}:{}}),d.set(S,I),S!=="x"&&S!=="y"&&(h[S]=$)},w=(S,E)=>{const $=S==="x"?p-o:S==="y"?g-r:h[S],A=d.get(S);(!A||A[A.length-1].time<E)&&m(S,E,$)},v={prop:e,scale:a,exaggeration:l,get x(){return p},get floor(){return g},values:h,facing(){const S=Math.sin(h.turn*Math.PI/2);return Math.abs(S)<.5?0:S>0?1:-1},key(S,E,$={}){Object.assign(h,E),u.push({time:S,pose:{...h},...$.act===!1?{act:!1}:{},...$.easing?{easing:$.easing}:{}})},move(S,E,$,A={}){w("x",S),m("x",E,$-o,A.easing),p=$,A.floor!==void 0&&(w("y",S),m("y",E,A.floor-r,A.easing),g=A.floor)},set(S,E,$,A){m(S,E,$,A)},turnTo(S,E){const $=typeof E=="number"?E:Jc[E],A=h.turn,C=[$-4,$,$+4].map(j=>({t:j,d:Math.abs(j-A)})).sort((j,V)=>j.d-V.d||Math.abs(j.t)-Math.abs(V.t))[0];if(C.d<.001)return S;const D=S+l4*Math.max(1,C.d);return v.key(D,{turn:C.t}),D},effect(S){f.push(S)},anchor(S){const $=xs(e,h,a).anchors[S];if(!$)throw new Error(`${e.kind}: no anchor "${S}"`);return{x:p+$.point.x,y:g+$.point.y}}},k=[];let y=0;for(const S of n){const E=Math.max(S.at??y,u[u.length-1].time),$=c[S.do].run(v,S,E);$.end>u[u.length-1].time&&u.push({time:$.end,pose:{...h}}),k.push({start:E,end:$.end,...$.contact!==void 0?{contact:$.contact}:{},...$.release!==void 0?{release:$.release}:{}}),y=$.end}const x=bc(s.style??"snappy"),P={...x,anticipation:x.anticipation*l,overshoot:x.overshoot*l},M=br(d4(u),e.acting,{style:P}),T=[...Object.entries(M).filter(([S])=>!d.has(S)).map(([S,E])=>({id:`${t}-${S}`,target:t,property:S,keyframes:E})),...[...d].map(([S,E])=>({id:`${t}-${S}`,target:t,property:S,keyframes:f4(E)}))];for(const S of h4(t,e,T,y,u[0].pose)){const E=T.findIndex(I=>I.property===S.property);if(E<0){T.push(S);continue}const $=new Ht({id:`${t}-own`,tracks:[T[E]]}),A=I=>Number($.getStateAtTime(I).values.get(t)?.get(S.property)??0);T[E]={...S,keyframes:S.keyframes.map(I=>({time:I.time,value:Number(I.value)+A(I.time)}))}}return{tracks:T,duration:y,beats:k,effects:f}}const c4=1500;function h4(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+c4,c=js(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 p=Math.sin(r(d,"turn")*Math.PI/2),g=(f-r(d,a.of))*p;return{time:d,value:Math.max(-h,Math.min(h,g*a.per))}});return{id:`${t}-${a.control}`,target:t,property:a.control,keyframes:u}})}const u4=20;function d4(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<u4?n[n.length-1]={...s,time:i.time}:n.push(s)}return n}function f4(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 $s=Object.freeze({test:Object.freeze({name:"Test",inningsPerSide:2,oversPerInnings:null,ballsPerOver:6,freeHitAfterNoBall:!1,summary:"Multi-day cricket. Each side can have two innings; there is no innings over limit."}),odi:Object.freeze({name:"ODI",inningsPerSide:1,oversPerInnings:50,ballsPerOver:6,freeHitAfterNoBall:!0,summary:"One innings per side, up to 50 overs. A no-ball gives a free hit on the next legitimate delivery."}),t20:Object.freeze({name:"T20",inningsPerSide:1,oversPerInnings:20,ballsPerOver:6,freeHitAfterNoBall:!0,summary:"One innings per side, up to 20 overs. A no-ball gives a free hit on the next legitimate delivery."})}),th=Object.freeze({adults:"Adults",men:"Men",children:"Children",mixed:"Mixed cast"}),Hr=Object.freeze({bowler:"Bowler",keeper:"Wicketkeeper",fielder:"Extra cover",slip:"Slip",point:"Point",cover:"Cover","mid-off":"Mid-off","mid-on":"Mid-on","square-leg":"Square leg","fine-leg":"Fine leg","third-man":"Third man"}),Ps=Object.freeze(Object.fromEntries(Object.entries({bowling:{name:"Pace bowling",summary:"Run up, deliver with a straight arm, bounce and follow through."},spin:{name:"Spin bowling",summary:"A shorter approach and a curved illustrative flight before the bounce."},batting:{name:"Drive",summary:"Two hands on the bat, a backlift, contact and a follow-through."},defend:{name:"Defensive block",summary:"Meet the ball with a controlled bat and keep it close."},running:{name:"Running between wickets",summary:"Both batters make the opposite ground to complete one run."},four:{name:"Boundary four",summary:"A struck ball reaches the boundary after touching the ground."},six:{name:"Boundary six",summary:"A struck ball clears the boundary before touching the ground."},catch:{name:"Catch",summary:"A fielder controls the struck ball before it touches the ground."},fielding:{name:"Ground field",summary:"A fielder moves to the ball, bends and gathers it."},throw:{name:"Field and throw",summary:"Gather, wind up, release and return the ball to the keeper."},bowled:{name:"Bowled",summary:"A legal delivery hits the wicket and removes a bail."},lbw:{name:"LBW illustration",summary:"Pad contact and a projected path to the stumps illustrate an authored LBW decision."},stumping:{name:"Stumping",summary:"The keeper holds the ball and breaks the wicket while the striker is out of ground, not attempting a run."},"run-out":{name:"Run-out",summary:"A direct throw breaks the wicket before the running batter makes that ground."},"no-ball":{name:"Front-foot no-ball",summary:"The landing front foot oversteps the popping crease at release; one extra, no legal ball."},wide:{name:"Wide ball",summary:"An untouched delivery passes beyond reach for a normal stroke; one extra, no legal ball."}}).map(([t,e])=>[t,Object.freeze(e)])));function Fe(t,e,n){if(!Object.prototype.hasOwnProperty.call(t,e))throw new Error(`${n}: unknown choice '${e}'`);return e}function eh(t,e,n,s){const i=e*Math.PI/180,o=n*Math.PI/180;return[t[0]+s*Math.cos(o)*Math.sin(i),t[1]+s*Math.sin(o),t[2]+s*Math.cos(o)*Math.cos(i)]}const nh=(t,e,n)=>[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n,t[2]+(e[2]-t[2])*n];function g4(t,e,n){const s={target:[0,0,0],yaw:0,pitch:15,distance:8,...t},i={...s,...e},o=nh(s.target,i.target,n),r=s.position||i.position?nh(s.position??eh(s.target,s.yaw,s.pitch,s.distance),i.position??eh(i.target,i.yaw,i.pitch,i.distance),n):eh(o,s.yaw+(i.yaw-s.yaw)*n,s.pitch+(i.pitch-s.pitch)*n,s.distance+(i.distance-s.distance)*n),a=nh(s.lookAt??s.target,i.lookAt??i.target,n),l=s.fov!==void 0||i.fov!==void 0?(s.fov??i.fov)+((i.fov??s.fov)-(s.fov??i.fov))*n:void 0;return{position:r,lookAt:a,fov:l}}function p4(t){const e=Math.max(1,t.every??33),n=Wt(t.easing??"ease-in-out"),s=`${t.scene}/${t.camera}`,i=[],o=[],r=[];for(let l=t.start;;l=Math.min(t.end,l+e)){const c=t.end>t.start?n((l-t.start)/(t.end-t.start)):1,h=g4(t.from,t.to,c);if(i.push({time:l,value:h.position}),o.push({time:l,value:h.lookAt}),h.fov!==void 0&&r.push({time:l,value:h.fov}),l>=t.end)break}const a=[{id:`${s}-move-position`,target:s,property:"position",keyframes:i},{id:`${s}-move-lookAt`,target:s,property:"lookAt",keyframes:o}];return r.length>0&&a.push({id:`${s}-move-fov`,target:s,property:"fov",keyframes:r}),a}function m4(t){const e=Math.max(1,t.every??33),n=t.offset??[0,2,6],s=t.lag??0,i=`${t.scene}/${t.camera}`,o=[],r=[];for(let a=t.start;;a=Math.min(t.end,a+e)){const l=t.subjectAt(a),c=t.subjectAt(Math.max(t.start,a-s));if(o.push({time:a,value:[c[0]+n[0],c[1]+n[1],c[2]+n[2]]}),r.push({time:a,value:l}),a>=t.end)break}return[{id:`${i}-follow-position`,target:i,property:"position",keyframes:o},{id:`${i}-follow-lookAt`,target:i,property:"lookAt",keyframes:r}]}const sh=Object.freeze({pitch:"Whole pitch",batter:"Batter close-up",bowler:"Bowler close-up",keeper:"Keeper close-up",field:"Whole ground",overhead:"Overhead ground",orbit:"360° ground orbit","follow-ball":"Follow the ball"}),l1=Object.freeze({pitch:75,batter:145,bowler:35,keeper:145,field:75,overhead:75,orbit:75,"follow-ball":75});function y4(t,e={}){const n=Fe(sh,e.view??"pitch","cricketCamera.view"),s=e.yaw??l1[n];if(!Number.isFinite(s))throw new Error("cricketCamera: yaw must be finite");const i=(s%360+360)%360,o=e.zoom??1;if(!Number.isFinite(o)||o<.25||o>4)throw new Error("cricketCamera: zoom must be between 0.25 and 4");const r=d=>o===1?d:Math.atan(Math.tan(d*Math.PI/360)/o)*360/Math.PI,a=e.every??40;if(!Number.isFinite(a)||a<16||a>1e3)throw new Error("cricketCamera: every must be between 16 and 1000 ms");if(n==="follow-ball"){const d=["x","y","z"].map(m=>{const w=t.timeline.tracks.find(x=>x.target===`${t.scene.id}/ball`&&x.property===m);if(!w||!("keyframes"in w)||!w.keyframes.length)throw new Error(`cricketCamera: missing ball ${m} keyframes`);const v=w.keyframes;let k=0,y=new un({...w,keyframes:v.slice(0,2)});return x=>{const P=k;for(;k<v.length-2&&x-(w.delay??0)>v[k+1].time;)k++;return k!==P&&(y=new un({...w,keyframes:v.slice(k,k+2)})),y.getValueAtTime(x)}}),f=m4({scene:t.scene.id,camera:"camera",start:0,end:t.duration,every:a,offset:[5,3,6],subjectAt:m=>d.map(w=>w(m))}),p=t.scene.objects.find(m=>m.id==="camera"&&m.kind==="camera"),g=r(p?.kind==="camera"&&p.projection==="perspective"?p.fov:48);return[...f,{id:`${t.scene.id}/camera-zoom-fov`,target:`${t.scene.id}/camera`,property:"fov",keyframes:[{time:0,value:g},{time:t.duration,value:g}]}]}const l=n==="field"||n==="overhead"||n==="orbit",c=n==="batter"?[.1,.85,9.3]:n==="bowler"?[.68,1,-9.55]:n==="keeper"?[0,.7,10.1]:[0,.65,0],h=l?t.boundaryRadius*2.8:n==="pitch"?29:4.3,u=n==="overhead"?89:l?52:n==="pitch"?16:12;return p4({scene:t.scene.id,camera:"camera",start:0,end:t.duration,every:a,easing:"linear",from:{target:c,yaw:i,pitch:u,distance:h,fov:r(l?48:n==="pitch"?50:46)},to:{yaw:n==="orbit"?i+360:i}})}const b4={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 c1(t,e={}){const n={};for(const s of Object.keys(Yt))n[s]={summary:`Walks to \`to\` in the ${s} gait.`,needs:["to"]};for(const s of Object.keys(ae))n[s]={summary:`Moves into the ${s} pose and holds it (\`for\` ms).`};for(const s of Object.keys(en))n[s]={summary:`The ${s} gag (${$i(s)} ms).`};for(const[s,i]of Object.entries(Pi))n[s]={...i};return{sports:{cricket:{actions:{...Ps},formats:{...$s},casts:{...th},fieldingPositions:{...Hr},cameras:{...sh}}},...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(b4),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:Tr,stickFigure:{poseFields:Fu,props:Nu,handFields:Wu,poses:Object.keys(ae),expressions:Object.keys(vt),gags:Object.fromEntries(Object.keys(en).map(s=>[s,$i(s)])),gaits:Object.keys(Yt),actingStyles:Object.keys(Cn),beatFields:wr,actions:n,dances:Object.fromEntries(Object.entries(Ge).map(([s,i])=>[s,Object.keys(i.moves)])),flips:Object.fromEntries(Object.entries(yi).map(([s,i])=>[s,i.label])),handShapes:Object.keys(St),mudras:Object.keys(xo)},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 world metres: gaits, face (shortest turn), spin (signed turns and duration), dance (native style, bpm, beats), 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 / .driving / .cycling / .wheeling (a wheelchair)","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:_r,commonControls:Object.fromEntries(Object.entries(Ss).map(([s,i])=>[s,`${i.description}${i.unit?` (${i.unit})`:""}`])),commonActions:Object.fromEntries(Object.entries(Zc).map(([s,i])=>[s,i.summary])),presets:Object.fromEntries(Object.entries(As).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:{figureStyles:["fluid","stick","organic"],body:{"body.torso · body.arm · body.leg · body.neck":"Organic half-width profiles: [{ at: 0..1, width: fractionOfHeight }], increasing from 0 to 1; independent of ink width.","body.fill · body.outline · body.shading":"Shared skin fill, outline { color, width }, cel material { mode: cel | none, light: [x,y], shadow, opacity, highlight }.","softCartoonCharacter(name, options?)":"Original youngMan / youngWoman / childBoy / childGirl story presets. Children have larger head proportions, shorter limbs and rounded torsos; every face, hair, build, hand, clothing and material option can be overridden.","face.projection":"Organic default volume follows the head axes, keeps both eyes in three-quarter views and projects a small nose above the mouth; opaque hair covers features. cartoon keeps the classic face slide.","outfitPreset(category, overrides?)":"Fresh JSON Everyday / Formal / Casual wardrobe defaults for every actor; top: tshirt | shirt | blouse | dress, trouserStyle: plain | jeans | cargo, colours, sleeves, bottoms, collar and tie are editable.",leafOutfit:"Organic-only JSON garment { top?, color?, accent?, length? }; curved leaves follow torso/thighs at native part depths. Everyday basicOutfit also follows organic contours."},poses:Object.keys(ye),dances:Object.keys(Sn),expressions:Object.keys(ol),faceStyles:["simple","anime"],faceShapes:["round","angular"],gags:Object.keys(Go),builds:Object.keys(Io),hair:Object.keys(kl),hairColors:{...xe},facialHair:Object.keys(Tl),glasses:Object.keys(Al),hats:Object.keys(Yo),feet:[...Ld],cast:Object.keys(pc),heldItems:Object.fromEntries(Object.entries(Ol).map(([s,i])=>[s,i.hands])),handMeetings:Object.keys(Ai)},codePanel:{languages:pr,removeStyles:fr,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:cc},surfaces:{code:Si,board:Ce,chart:On,prop:Ts},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: ${vs.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 yt=t=>t.map(e=>`\`${e}\``).join(", "),h1=t=>Object.entries(t).map(([e,n])=>`| \`${e}\` | ${n.unit??n.kind??""} | ${n.description} |`).join(`
63
- `);function w4(t,e={}){const n=c1(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: ${yt(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`).","","Style proportions: `headSize` is a fraction of height; `armLength` multiplies both upper arm and forearm lengths (default 1, positive finite). Hands, shoulders, torso and legs retain their sizes.","","### Pose fields","","| Field | Unit | What it does |","|---|---|---|",h1(s.poseFields),"","### Other props","","| Prop | Unit | What it does |","|---|---|---|",h1(s.props),"",`With \`style.hands\`, each hand has \`hand.left.<field>\` / \`hand.right.<field>\` props: ${yt(Object.keys(s.handFields))}.`,"",`**Poses** (a beat's \`do\`, or a pose key): ${yt(s.poses)}.`,"",`**Expressions** (a beat's \`mood\`): ${yt(s.expressions)}.`,"",`**Gags** (ms): ${Object.entries(s.gags).map(([o,r])=>`\`${o}\` (${r})`).join(", ")}.`,"",`**Gaits**: ${yt(s.gaits)}. **Acting styles** (\`style\`): ${yt(s.actingStyles)}.`,"","### Beat scripts","",`\`scriptTracks(target, beats, { from, ground, height, facing, style })\`. A beat has these fields only: ${yt(s.beatFields)}. Times are ms; \`to\` and \`target\` are scene px; \`onto\` is a floor's scene y.`,"","`characterScript(target, who, beats, options)` compiles the same beats for a v2 `character()` on a `characterTarget` (every option but `height`; the same result, its key poses on the human body; the walk phase keyed to that character's stride, and `walk` / `walking` / `gait` tracks that step the gait as the target draws). Add `hairFollowTracks(target, tracks, who)` after it so hanging hair swings.","","| `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**: ${yt(s.handShapes)}. **Mudras**: ${yt(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: ${yt(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(", ")}.`,"","Scenery: `scenery({ x, y, width, height, kind: sky | room, hour, clouds, wind, rain, snow, horizon: hills | city | flat })` is a canvas target whose values `hour` (0–24), `clouds`, `rain`, `snow` (0–1) and `wind` (−1..1) are tracks (`set(prop, { at, value, duration })`, `tracks(id)`; `anchor('sun' | 'moon' | 'horizon' | 'ground', time)`); the same `wind` streams hair (`hairFollowTracks(…, { wind })`). `scenePreset('park' | 'street' | 'office' | 'home', { width, height })` lays out scenery and props as data; `buildScene` builds them into targets.","","| 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: ${yt(n.character.poses)}. Expressions: ${yt(n.character.expressions)}. Gags: ${yt(n.character.gags)}.`,`Native dances: ${yt(n.character.dances)}; \`humanDanceFrame(style, beat, base)\` keeps body heading independent; \`humanDanceTracks(target, options)\` bakes JSON pose tracks. \`danceCircleAt(beat, { radius, count, beatsPerTurn, facing, spins })\` gives a formation with planted toes; \`danceCircleTracks(targets, options)\` bakes scene tracks. \`plantDanceFoot(partner, side, worldPoint)\` returns pose AND position; \`meetDandiya(a, b)\` solves both stick tips to one shared world point and reports unreachable contacts.`,"","Appearance options of `character({ … })`, all plain data that turns with the head (see docs/character-appearance.md):","",`- \`build\`: ${yt(n.character.builds)}`,`- \`figure\`: ${yt(n.character.figureStyles)}`,...Object.entries(n.character.body).map(([o,r])=>`- \`${o}\`: ${r}`),`- \`hair\`: ${yt(n.character.hair)} (colours: ${yt(Object.keys(n.character.hairColors))} in \`HAIR_COLORS\`)`,"- Flowing hair: `softSweep`, `flowingBob`, `cascadingWaves`; editable `locks: [{ path, width, follow? }]` with cubic `{ around, up, lift? }` points (around in degrees, dimensions in head radii), `fall: { taper, wave }` and `shine` (0–1). Roots stay attached; `hairFollowTracks` also drives flexible short locks.",`- \`facialHair\`: ${yt(n.character.facialHair)}`,`- \`glasses\`: ${yt(n.character.glasses)}; \`hat\`: ${yt(n.character.hats)}; \`ears: true\`; \`face: { teeth, tongue }\` (shown when the mouth opens); \`feet\`: ${yt(n.character.feet)}`,"- `outfit`: `{ top: tshirt | shirt | blouse | dress, trouserStyle: plain | jeans | cargo, shirt: top colour, trousers: bottom colour, sleeves: short | long | none, bottom: trousers | shorts | skirt, collar, tie: colour, over: apron | labCoat | hoodie | cardigan | overalls | sari, overColor, shoes: boots, shoeColor }`",`- \`castMember(name, height)\`: ${yt(n.character.cast)}`,"- Face marks (pose fields, 0–1): `blush`, `tears`, `sweat`; close-up fields `pupil` (size, 1 usual), `lid` (upper lids lowered, 0–1), `bulge` (eyes out of the head, 0–1); `face: { nose: true, inPupil(ctx, pupil) }`; `drawCharacterHead(ctx, who, pose, { x, y, radius })` draws just the head big",`- Face styles: ${yt(n.character.faceStyles)}; \`face: { style: 'anime', iris: '#4b7fce', lashes: true, ageLines: 0.8 }\` uses coloured eyes and the same expressions, blinks and gaze. \`ANIME_CAST\` contains eight age presets, also available through \`castMember\`.`,`- Face shapes: ${yt(n.character.faceShapes)}; \`face: { shape: 'angular', jawWidth: 0.74, chinWidth: 0.14, eyeScale: 0.8, eyeAspect: 0.65 }\` sets a tapered 3D jaw and narrower anime eyes; \`jawRoundness: 1\` softens the cheek/chin corners (default 0 keeps sharp jaws). \`MANGA_CAST\` contains four original young adult presets; hair styles \`mangaSpikes\` and \`mangaSweep\` remain editable.`,"- Hair in motion (pose fields): `hair.swing` (degrees round the head, + toward its left), `hair.trail` (head radii back), `hair.lift` (head radii up); key them with `hairFollowTracks(target, tracks, who)` after the character's tracks, or `hairFollow` + `hairMotionAt` when posing per frame",`- \`holding\`: ${Object.entries(n.character.heldItems).map(([o,r])=>`\`${o}\` (${r==="both"?"both":r==="either"?"one hand or both":"left or right"})`).join(", ")}; pose fields \`held.left\`, \`held.right\`, \`held.both\` (below 0.5 lets go); \`handGrip(joints, side)\``,`- \`meetHands(kind, a, b)\` (stand them \`meetingSpacing(kind, a, b)\` apart): ${yt(n.character.handMeetings)}; \`embrace(a, b)\` (a hug, \`embraceSpacing\` apart); \`helpUp(helper, sitter, progress)\` (0 on the floor, hand taken; 1 standing; \`helpUpSpacing\` apart)`,"- Everyday cycles like a gait: `humanCyclePose('sweeping' | 'brushing', phase, base)` (0 → 1 is one stroke and back; sweeping with `holding: { right: 'broom' }`)","","## Code panel","",`\`codePanel({ code, language, x, y, fontSize?, lineHeight?, width? })\`: a code listing as a scene object. Languages: ${yt(n.codePanel.languages)}. Remove styles: ${yt(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}`),""]),"## Cricket stories (`@algorisys/tinyfly/sports`)","","`cricketClip({ format, action, cast })` returns an organic-player scene, JSON tracks, timed events/captions and a declared result. `cricketField`, `cricketPlayer` and `cricketAction` compose separately; `cricketCameraTracks` adds camera tracks. These are authored tutorial plays, not physics or automatic umpiring. See docs/cricket.md.","",...Object.entries(n.sports.cricket.actions).map(([o,r])=>`- \`${o}\`: ${r.summary}`),"",`Formats: ${yt(Object.keys(n.sports.cricket.formats))}. Casts: ${yt(Object.keys(n.sports.cricket.casts))}. Cameras: ${yt(Object.keys(n.sports.cricket.cameras))}. Orbit turns 360° around the whole ground. \`cricketCameraTracks(clip, { view, zoom })\` supports 0.25–4× optical magnification (default 1) in every view.`,"",`Stock fielding labels (\`CRICKET_FIELDING_POSITIONS\`): ${Object.entries(n.sports.cricket.fieldingPositions).map(([o,r])=>`\`${o}\`: ${r}`).join(", ")}. Eleven fielders, two on-field batters and two umpires; nine batting teammates wait off-field. Mid-on is closer to the pitch; long-on is its deeper boundary alternative, not an extra stock fielder. For the right-handed striker, +x is off side and -x is on/leg side.`,"","## 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 k4(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=ne(`${r.kind}:${r.time}:${r.x}`);r.kind==="dust"?Tp(t,{x:r.x,y:r.y},a,{size:o,color:i,seed:l}):r.kind==="exhaust"?S4(t,r,a,o,i,l):r.kind==="skid"?x4(t,r,a,n,i):r.kind==="honk"?T4(t,r,a,o,i):r.kind==="smoke"?v4(t,r,n,o,i):r.kind==="leaves"&&M4(t,r,a,o,s.leafColor??"#5cae5a",i,l)}}function v4(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 M4(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=ne(`${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,p=u*u*.4+u*.6,g=d+a*u*s*(.6+h)+Math.sin(u*9+h*6)*s*.18,m=Math.min(l-2,f+(l-f)*p);t.globalAlpha=n>.85?(1-n)/.15:1,t.save(),t.translate(g,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 S4(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=(ne(`${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 x4(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 T4(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 E4(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 u=$r(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:A4(r)}),c}function A4(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 $4(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 P4(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,u;for(let f=t.start;;f=Math.min(t.end,f+n)){const p=$r(t.leader,{state:e.getStateAtTime(f)},t.leaderId),g=p.anchor(t.hitch),m=p.values.turn,w=xs(s.prop,{...o,turn:m},s.propScale).anchors[t.anchor];if(!w)throw new Error(`propTow: ${s.prop.kind} has no anchor "${t.anchor}"`);const v=g.x-w.point.x;if(u!==void 0&&r){const k=Math.sin(m*Math.PI/2);h+=(v-u)*(k||1)/s.propScale/r*(180/Math.PI)}if(u=v,a.push({time:f,value:v-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 u1=new WeakMap;function I4(t,e){const n=e?.some(Boolean)?e.map(d=>d?1:0).join(""):"";let s=u1.get(t);s||u1.set(t,s=new Map);const i=s.get(n);if(i)return i;const o=_i(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 g of d.corners)for(const m of[0,1,2])l[g][m]+=d.normal[m];const[f,...p]=d.corners;for(let g=0;g+1<p.length;g++){const[m,w,v]=[f,p[g],p[g+1]],[k,y,x]=[r.vertices[m],r.vertices[w],r.vertices[v]],P=[y[0]-k[0],y[1]-k[1],y[2]-k[2]],M=[x[0]-k[0],x[1]-k[1],x[2]-k[2]],T=[P[1]*M[2]-P[2]*M[1],P[2]*M[0]-P[0]*M[2],P[0]*M[1]-P[1]*M[0]],S=T[0]*d.normal[0]+T[1]*d.normal[1]+T[2]*d.normal[2];c.push(...S>=0?[m,w,v]:[m,v,w])}});const h=l.flatMap(d=>{const f=Math.hypot(...d)||1;return[d[0]/f,d[1]/f,d[2]/f]}),u=ir({positions:a,normals:h,indices:c});return s.size>=16&&s.clear(),s.set(n,u),u}function O4(t,e,n={}){const s=t.ink??n.ink??"#26262b",i=(n.outline??2)*(t.outline??1),o=t.glow&&e.glow>0?_4(t.glow.color,e.glow):void 0;return{color:t.fill??s,creases:_i(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 _4(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 C4=ir(pg(1,.002,28));function H4(t,e,n){const s=t.rig,[i,o]=s.footprint??[s.length*.45,s.length],r=Math.max(0,It(s,e,"lift")),a=Math.max(0,It(s,e,"size"))/(1+r*.8);return{mesh:C4,world:Rt(n,wa([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 R4=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),L4=1,F4={kind:"prop",validate(t){const e=t,n=typeof e.prop=="string"&&e.prop in As?[]:[ft("prop preset",e.prop,Object.keys(As))];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 Vc(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[M,T]of n)typeof T=="number"&&!R4.has(M)&&(h[M]=T);h.turn=0,h.tilt=0;const u=Rt(i.view,s),d={toView:M=>ie(u,M),toScreen:M=>a(M)},f=d.toView([0,c.rig.height/2,0]);if(-f[2]<=i.near)return null;if(l.look==="mesh"){const M=cm(c.rig,h),T=M.map(({part:$,local:A})=>({part:$.id,mesh:_i($.shape),...Nc(_i($.shape),A)})),S=sm(T),E=M.map(($,A)=>({...$,hidden:om($.part.id,T[A].mesh,$.local,T[A].key,S)})).filter(({opacity:$})=>$>.01).map(({part:$,matrix:A,glow:I,opacity:C,hidden:D})=>({mesh:I4($.shape,D),world:Rt(s,A),material:O4($,{glow:I,opacity:C},{shading:l.shading,ink:l.ink,outline:l.outline})}));return{meshes:l.shadow===!1?E:[H4(c,h,s),...E]}}const p=a(f),g=a(d.toView([0,c.rig.height/2+1,0])),m=Math.hypot(g.x-p.x,g.y-p.y),w=o.length===0?void 0:(M,T)=>{const S=ie(s,M),E=[s[0]*T[0]+s[4]*T[1]+s[8]*T[2],s[1]*T[0]+s[5]*T[1]+s[9]*T[2],s[2]*T[0]+s[6]*T[1]+s[10]*T[2]],$=Math.hypot(...E)||1;return{light:mg(S,[E[0]/$,E[1]/$,E[2]/$],o),fog:yg(r,Math.hypot(S[0]-i.position[0],S[1]-i.position[1],S[2]-i.position[2]))}},v=qc(c.rig,h,d,m,{perspective:!0,near:i.near,slice:L4,light:w}),k={look:l.look,style:l.style,ink:l.ink,paper:l.paper,fog:r?.color},y=jl(v),x=v.cells??[],P=Math.max(...x.map(M=>-M.depth),-f[2]);return{drawables:[...l.shadow===!1?[]:[{depth:P+c.rig.length,draw:M=>Yl(M,v,k)}],...x.map(M=>({depth:-M.depth,draw(T,S){T.lineCap="round",T.lineJoin="round",wg(T,M.parts,y,{...k,time:S.time})}}))]}}},ih=["do","at","for","to","through","toward","speed","height","open","on","wind"],N4=.25,W4=800/180,D4=220,B4=300,z4=["turn"];function q4(t){const e=Cr(t),n=Object.keys(t.moves??{});return Object.keys(e).filter(s=>!n.includes(s)&&!z4.includes(s)&&!(e[s].needs??[]).includes("to"))}function d1(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=q4(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))ih.includes(u)||l(ft("beat field",u,ih,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&&!Pn(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(Pn))&&l("`through` is a list of points on the ground, each [x, z] metres.")),c.do==="face"&&!(Pn(c.toward)||typeof c.toward=="number")&&l("`face` needs `toward`: a point [x, z] or a heading in degrees.")}),o}function j4(t,e,n,s){const i=d1(n,e);if(i.length>0)throw new Error(`propScript3D (${e.kind}): ${i.length} problem(s) in the beats:
62
+ `)}`);const o=s.from??0,r=s.ground??0,a=s.scale??60,l=s.exaggeration??1,c=Rr(e),h={};for(const S of[...Object.keys(Ss),...Object.keys(e.rig.controls)])h[S]=s.start?.[S]??It(e.rig,{},S);const u=[{time:0,pose:{...h}}],d=new Map,f=[];let p=o,g=r;const m=(S,E,$,A)=>{const I=d.get(S)??[{time:0,value:S==="x"||S==="y"?0:h[S]}];I.push({time:E,value:$,...A?{easing:A}:{}}),d.set(S,I),S!=="x"&&S!=="y"&&(h[S]=$)},w=(S,E)=>{const $=S==="x"?p-o:S==="y"?g-r:h[S],A=d.get(S);(!A||A[A.length-1].time<E)&&m(S,E,$)},v={prop:e,scale:a,exaggeration:l,get x(){return p},get floor(){return g},values:h,facing(){const S=Math.sin(h.turn*Math.PI/2);return Math.abs(S)<.5?0:S>0?1:-1},key(S,E,$={}){Object.assign(h,E),u.push({time:S,pose:{...h},...$.act===!1?{act:!1}:{},...$.easing?{easing:$.easing}:{}})},move(S,E,$,A={}){w("x",S),m("x",E,$-o,A.easing),p=$,A.floor!==void 0&&(w("y",S),m("y",E,A.floor-r,A.easing),g=A.floor)},set(S,E,$,A){m(S,E,$,A)},turnTo(S,E){const $=typeof E=="number"?E:Qc[E],A=h.turn,C=[$-4,$,$+4].map(j=>({t:j,d:Math.abs(j-A)})).sort((j,V)=>j.d-V.d||Math.abs(j.t)-Math.abs(V.t))[0];if(C.d<.001)return S;const D=S+u4*Math.max(1,C.d);return v.key(D,{turn:C.t}),D},effect(S){f.push(S)},anchor(S){const $=xs(e,h,a).anchors[S];if(!$)throw new Error(`${e.kind}: no anchor "${S}"`);return{x:p+$.point.x,y:g+$.point.y}}},k=[];let y=0;for(const S of n){const E=Math.max(S.at??y,u[u.length-1].time),$=c[S.do].run(v,S,E);$.end>u[u.length-1].time&&u.push({time:$.end,pose:{...h}}),k.push({start:E,end:$.end,...$.contact!==void 0?{contact:$.contact}:{},...$.release!==void 0?{release:$.release}:{}}),y=$.end}const x=kc(s.style??"snappy"),P={...x,anticipation:x.anticipation*l,overshoot:x.overshoot*l},M=kr(p4(u),e.acting,{style:P}),T=[...Object.entries(M).filter(([S])=>!d.has(S)).map(([S,E])=>({id:`${t}-${S}`,target:t,property:S,keyframes:E})),...[...d].map(([S,E])=>({id:`${t}-${S}`,target:t,property:S,keyframes:m4(E)}))];for(const S of f4(t,e,T,y,u[0].pose)){const E=T.findIndex(I=>I.property===S.property);if(E<0){T.push(S);continue}const $=new Ht({id:`${t}-own`,tracks:[T[E]]}),A=I=>Number($.getStateAtTime(I).values.get(t)?.get(S.property)??0);T[E]={...S,keyframes:S.keyframes.map(I=>({time:I.time,value:Number(I.value)+A(I.time)}))}}return{tracks:T,duration:y,beats:k,effects:f}}const d4=1500;function f4(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+d4,c=Ks(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 p=Math.sin(r(d,"turn")*Math.PI/2),g=(f-r(d,a.of))*p;return{time:d,value:Math.max(-h,Math.min(h,g*a.per))}});return{id:`${t}-${a.control}`,target:t,property:a.control,keyframes:u}})}const g4=20;function p4(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<g4?n[n.length-1]={...s,time:i.time}:n.push(s)}return n}function m4(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 $s=Object.freeze({test:Object.freeze({name:"Test",inningsPerSide:2,oversPerInnings:null,ballsPerOver:6,freeHitAfterNoBall:!1,summary:"Multi-day cricket. Each side can have two innings; there is no innings over limit."}),odi:Object.freeze({name:"ODI",inningsPerSide:1,oversPerInnings:50,ballsPerOver:6,freeHitAfterNoBall:!0,summary:"One innings per side, up to 50 overs. A no-ball gives a free hit on the next legitimate delivery."}),t20:Object.freeze({name:"T20",inningsPerSide:1,oversPerInnings:20,ballsPerOver:6,freeHitAfterNoBall:!0,summary:"One innings per side, up to 20 overs. A no-ball gives a free hit on the next legitimate delivery."})}),nh=Object.freeze({adults:"Adults",men:"Men",children:"Children",mixed:"Mixed cast"}),Ps=Object.freeze({bowler:"Bowler",keeper:"Wicketkeeper",fielder:"Extra cover",slip:"Slip",point:"Point",cover:"Cover","mid-off":"Mid-off","mid-on":"Mid-on","square-leg":"Square leg","fine-leg":"Fine leg","third-man":"Third man"}),Is=Object.freeze(Object.fromEntries(Object.entries({bowling:{name:"Pace bowling",summary:"Run up, deliver with a straight arm, bounce and follow through."},spin:{name:"Spin bowling",summary:"A shorter approach and a curved illustrative flight before the bounce."},batting:{name:"Drive",summary:"Two hands on the bat, a backlift, contact and a follow-through."},defend:{name:"Defensive block",summary:"Meet the ball with a controlled bat and keep it close."},running:{name:"Running between wickets",summary:"Both batters make the opposite ground to complete one run."},four:{name:"Boundary four",summary:"A struck ball reaches the boundary after touching the ground."},six:{name:"Boundary six",summary:"A struck ball clears the boundary before touching the ground."},catch:{name:"Catch",summary:"A fielder controls the struck ball before it touches the ground."},fielding:{name:"Ground field",summary:"A fielder moves to the ball, bends and gathers it."},throw:{name:"Field and throw",summary:"Gather, wind up, release and return the ball to the keeper."},bowled:{name:"Bowled",summary:"A legal delivery hits the wicket and removes a bail."},lbw:{name:"LBW illustration",summary:"Pad contact and a projected path to the stumps illustrate an authored LBW decision."},stumping:{name:"Stumping",summary:"The keeper holds the ball and breaks the wicket while the striker is out of ground, not attempting a run."},"run-out":{name:"Run-out",summary:"A direct throw breaks the wicket before the running batter makes that ground."},"no-ball":{name:"Front-foot no-ball",summary:"The landing front foot oversteps the popping crease at release; one extra, no legal ball."},wide:{name:"Wide ball",summary:"An untouched delivery passes beyond reach for a normal stroke; one extra, no legal ball."}}).map(([t,e])=>[t,Object.freeze(e)])));function Ae(t,e,n){if(!Object.prototype.hasOwnProperty.call(t,e))throw new Error(`${n}: unknown choice '${e}'`);return e}function sh(t,e,n,s){const i=e*Math.PI/180,o=n*Math.PI/180;return[t[0]+s*Math.cos(o)*Math.sin(i),t[1]+s*Math.sin(o),t[2]+s*Math.cos(o)*Math.cos(i)]}const ih=(t,e,n)=>[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n,t[2]+(e[2]-t[2])*n];function y4(t,e,n){const s={target:[0,0,0],yaw:0,pitch:15,distance:8,...t},i={...s,...e},o=ih(s.target,i.target,n),r=s.position||i.position?ih(s.position??sh(s.target,s.yaw,s.pitch,s.distance),i.position??sh(i.target,i.yaw,i.pitch,i.distance),n):sh(o,s.yaw+(i.yaw-s.yaw)*n,s.pitch+(i.pitch-s.pitch)*n,s.distance+(i.distance-s.distance)*n),a=ih(s.lookAt??s.target,i.lookAt??i.target,n),l=s.fov!==void 0||i.fov!==void 0?(s.fov??i.fov)+((i.fov??s.fov)-(s.fov??i.fov))*n:void 0;return{position:r,lookAt:a,fov:l}}function b4(t){const e=Math.max(1,t.every??33),n=Wt(t.easing??"ease-in-out"),s=`${t.scene}/${t.camera}`,i=[],o=[],r=[];for(let l=t.start;;l=Math.min(t.end,l+e)){const c=t.end>t.start?n((l-t.start)/(t.end-t.start)):1,h=y4(t.from,t.to,c);if(i.push({time:l,value:h.position}),o.push({time:l,value:h.lookAt}),h.fov!==void 0&&r.push({time:l,value:h.fov}),l>=t.end)break}const a=[{id:`${s}-move-position`,target:s,property:"position",keyframes:i},{id:`${s}-move-lookAt`,target:s,property:"lookAt",keyframes:o}];return r.length>0&&a.push({id:`${s}-move-fov`,target:s,property:"fov",keyframes:r}),a}function w4(t){const e=Math.max(1,t.every??33),n=t.offset??[0,2,6],s=t.lag??0,i=`${t.scene}/${t.camera}`,o=[],r=[];for(let a=t.start;;a=Math.min(t.end,a+e)){const l=t.subjectAt(a),c=t.subjectAt(Math.max(t.start,a-s));if(o.push({time:a,value:[c[0]+n[0],c[1]+n[1],c[2]+n[2]]}),r.push({time:a,value:l}),a>=t.end)break}return[{id:`${i}-follow-position`,target:i,property:"position",keyframes:o},{id:`${i}-follow-lookAt`,target:i,property:"lookAt",keyframes:r}]}const oh=Object.freeze({pitch:"Whole pitch",batter:"Batter close-up",bowler:"Bowler close-up",keeper:"Keeper close-up",field:"Whole ground",overhead:"Overhead ground",orbit:"360° ground orbit","follow-ball":"Follow the ball"}),c1=Object.freeze({pitch:75,batter:145,bowler:35,keeper:145,field:75,overhead:75,orbit:75,"follow-ball":75});function k4(t,e={}){const n=Ae(oh,e.view??"pitch","cricketCamera.view"),s=e.yaw??c1[n];if(!Number.isFinite(s))throw new Error("cricketCamera: yaw must be finite");const i=(s%360+360)%360,o=e.zoom??1;if(!Number.isFinite(o)||o<.25||o>4)throw new Error("cricketCamera: zoom must be between 0.25 and 4");const r=d=>o===1?d:Math.atan(Math.tan(d*Math.PI/360)/o)*360/Math.PI,a=e.every??40;if(!Number.isFinite(a)||a<16||a>1e3)throw new Error("cricketCamera: every must be between 16 and 1000 ms");if(n==="follow-ball"){const d=["x","y","z"].map(m=>{const w=t.timeline.tracks.find(x=>x.target===`${t.scene.id}/ball`&&x.property===m);if(!w||!("keyframes"in w)||!w.keyframes.length)throw new Error(`cricketCamera: missing ball ${m} keyframes`);const v=w.keyframes;let k=0,y=new un({...w,keyframes:v.slice(0,2)});return x=>{const P=k;for(;k<v.length-2&&x-(w.delay??0)>v[k+1].time;)k++;return k!==P&&(y=new un({...w,keyframes:v.slice(k,k+2)})),y.getValueAtTime(x)}}),f=w4({scene:t.scene.id,camera:"camera",start:0,end:t.duration,every:a,offset:[5,3,6],subjectAt:m=>d.map(w=>w(m))}),p=t.scene.objects.find(m=>m.id==="camera"&&m.kind==="camera"),g=r(p?.kind==="camera"&&p.projection==="perspective"?p.fov:48);return[...f,{id:`${t.scene.id}/camera-zoom-fov`,target:`${t.scene.id}/camera`,property:"fov",keyframes:[{time:0,value:g},{time:t.duration,value:g}]}]}const l=n==="field"||n==="overhead"||n==="orbit",c=n==="batter"?[.1,.85,9.3]:n==="bowler"?[.68,1,-9.55]:n==="keeper"?[0,.7,10.1]:[0,.65,0],h=l?t.boundaryRadius*2.8:n==="pitch"?29:4.3,u=n==="overhead"?89:l?52:n==="pitch"?16:12;return b4({scene:t.scene.id,camera:"camera",start:0,end:t.duration,every:a,easing:"linear",from:{target:c,yaw:i,pitch:u,distance:h,fov:r(l?48:n==="pitch"?50:46)},to:{yaw:n==="orbit"?i+360:i}})}function Os(t,e){if(!Array.isArray(t)||t.length!==3||!t.every(Number.isFinite))throw new Error(`${e}: expected three finite coordinates`)}function h1(t,e,n=40,s=[]){if(!Number.isFinite(t)||!Number.isFinite(e)||t<0||e<t)throw new Error("sampleTimes: expected finite ordered nonnegative times");if(!Number.isFinite(n)||n<16||n>1e3)throw new Error("sampleTimes: every must be between 16 and 1000 ms");if((e-t)/n>2e4)throw new Error("sampleTimes: too many samples");const i=new Set([t,e,...s.filter(o=>o>=t&&o<=e&&Number.isFinite(o))]);for(let o=t+n;o<e;o+=n)i.add(o);return[...i].sort((o,r)=>o-r)}function rh(t,e){if(u1(t),!Number.isFinite(e))throw new Error("ballFlightPoint: time must be finite");const n=Math.max(0,Math.min(1,(e-t.start)/(t.end-t.start))),s=4*n*(1-n),i=t.to[0]-t.from[0],o=t.to[2]-t.from[2],r=Math.hypot(i,o)||1;return[t.from[0]+i*n-o/r*(t.curve??0)*s,t.from[1]+(t.to[1]-t.from[1])*n+(t.arc??0)*s,t.from[2]+o*n+i/r*(t.curve??0)*s]}function u1(t){if(!t.target?.trim())throw new Error("ballFlight: target is required");if(Os(t.from,"ballFlight.from"),Os(t.to,"ballFlight.to"),!Number.isFinite(t.start)||!Number.isFinite(t.end)||t.start<0||t.end<=t.start)throw new Error("ballFlight: end must be greater than start, both finite and nonnegative");if(!Number.isFinite(t.arc??0)||(t.arc??0)<0||!Number.isFinite(t.curve??0))throw new Error("ballFlight: arc must be finite and nonnegative; curve must be finite")}function v4(t){u1(t);const e=h1(t.start,t.end,t.every),n=e.map(s=>rh(t,s));return["x","y","z"].map((s,i)=>({id:`${t.id??"flight"}-${s}`,target:t.target,property:s,keyframes:e.map((o,r)=>({time:o,value:n[r][i]}))}))}const Lr=Object.freeze({mcc:Object.freeze({name:"MCC",poppingCreaseHalfWidth:1.83,fieldingRadius:null,summary:"MCC minimum crease markings. The base Laws do not prescribe a limited-over restriction area."}),"icc-men":Object.freeze({name:"ICC men",poppingCreaseHalfWidth:7.5,fieldingRadius:27.43,summary:"ICC men: extended crease markings; ODI/T20 restriction-area arcs have a 27.43 m radius."}),"icc-women":Object.freeze({name:"ICC women",poppingCreaseHalfWidth:7.5,fieldingRadius:23,summary:"ICC women: extended crease markings; ODI/T20 restriction-area arcs have a 23 m radius."})});function M4(t){const[e,n]=t.centres,s=Math.hypot(n[0]-e[0],n[2]-e[2]),i=(n[0]-e[0])/s,o=(n[2]-e[2])/s,r=[];for(let a=0;a<2;a++){const l=a===0?n:e;for(let c=0;c<=64;c++){const h=(a+c/64)*Math.PI,u=Math.cos(h)*t.radius,d=Math.sin(h)*t.radius;r.push([l[0]+o*u+i*d,.018,l[2]-i*u+o*d])}}return r}function d1(t,e){Os(e,"cricketFieldingAreaContains.point");const n=t.fieldingArea;if(n==null)return null;if(!Number.isFinite(n.radius)||n.radius<=0)throw new Error("cricketFieldingAreaContains: radius must be positive and finite");if(!Array.isArray(n.centres)||n.centres.length!==2)throw new Error("cricketFieldingAreaContains: two centres are required");const[s,i]=n.centres;Os(s,"cricketFieldingAreaContains.centre"),Os(i,"cricketFieldingAreaContains.centre");const o=i[0]-s[0],r=i[2]-s[2],a=o*o+r*r,l=a?Math.max(0,Math.min(1,((e[0]-s[0])*o+(e[2]-s[2])*r)/a)):0;return Math.hypot(e[0]-s[0]-l*o,e[2]-s[2]-l*r)<=n.radius+1e-9}function f1(t){return Object.keys(Ps).flatMap(e=>{const n=t.scene.objects.find(i=>i.id===e&&i.kind==="character");if(!n)return[];if(n.parent)throw new Error(`cricketFieldingPositions: '${e}' must be unparented for setup markers`);const s=[...n.position??[0,0,0]];return[{id:e,name:n.name??Ps[e],position:s,inside:d1(t,s)}]})}function S4(t){return t.fieldingArea?f1(t).map(e=>({id:`fielding-review-${e.id}`,name:`${e.name}: ${e.inside?"inside":"outside"} restriction area`,kind:"line",closed:!0,width:.12,color:e.inside?"#d8eb8a":"#ee9670",points:Array.from({length:32},(n,s)=>[e.position[0]+Math.cos(s*Math.PI/16)*.7,.06,e.position[2]+Math.sin(s*Math.PI/16)*.7])})):[]}const x4={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 g1(t,e={}){const n={};for(const s of Object.keys(Yt))n[s]={summary:`Walks to \`to\` in the ${s} gait.`,needs:["to"]};for(const s of Object.keys(ae))n[s]={summary:`Moves into the ${s} pose and holds it (\`for\` ms).`};for(const s of Object.keys(en))n[s]={summary:`The ${s} gag (${Ii(s)} ms).`};for(const[s,i]of Object.entries(Oi))n[s]={...i};return{sports:{cricket:{actions:{...Is},formats:{...$s},casts:{...nh},fieldingPositions:{...Ps},markingProfiles:{...Lr},cameras:{...oh}}},...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(x4),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:Ar,stickFigure:{poseFields:Nu,props:Wu,handFields:Du,poses:Object.keys(ae),expressions:Object.keys(vt),gags:Object.fromEntries(Object.keys(en).map(s=>[s,Ii(s)])),gaits:Object.keys(Yt),actingStyles:Object.keys(Cn),beatFields:vr,actions:n,dances:Object.fromEntries(Object.entries(Ge).map(([s,i])=>[s,Object.keys(i.moves)])),flips:Object.fromEntries(Object.entries(wi).map(([s,i])=>[s,i.label])),handShapes:Object.keys(St),mudras:Object.keys(Eo)},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 world metres: gaits, face (shortest turn), spin (signed turns and duration), dance (native style, bpm, beats), 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 / .driving / .cycling / .wheeling (a wheelchair)","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:Hr,commonControls:Object.fromEntries(Object.entries(Ss).map(([s,i])=>[s,`${i.description}${i.unit?` (${i.unit})`:""}`])),commonActions:Object.fromEntries(Object.entries(th).map(([s,i])=>[s,i.summary])),presets:Object.fromEntries(Object.entries(As).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:{figureStyles:["fluid","stick","organic"],body:{"body.torso · body.arm · body.leg · body.neck":"Organic half-width profiles: [{ at: 0..1, width: fractionOfHeight }], increasing from 0 to 1; independent of ink width.","body.fill · body.outline · body.shading":"Shared skin fill, outline { color, width }, cel material { mode: cel | none, light: [x,y], shadow, opacity, highlight }.","softCartoonCharacter(name, options?)":"Original youngMan / youngWoman / childBoy / childGirl story presets. Children have larger head proportions, shorter limbs and rounded torsos; every face, hair, build, hand, clothing and material option can be overridden.","face.projection":"Organic default volume follows the head axes, keeps both eyes in three-quarter views and projects a small nose above the mouth; opaque hair covers features. cartoon keeps the classic face slide.","outfitPreset(category, overrides?)":"Fresh JSON Everyday / Formal / Casual wardrobe defaults for every actor; top: tshirt | shirt | blouse | dress, trouserStyle: plain | jeans | cargo, colours, sleeves, bottoms, collar and tie are editable.",leafOutfit:"Organic-only JSON garment { top?, color?, accent?, length? }; curved leaves follow torso/thighs at native part depths. Everyday basicOutfit also follows organic contours."},poses:Object.keys(ye),dances:Object.keys(Sn),expressions:Object.keys(al),faceStyles:["simple","anime"],faceShapes:["round","angular"],gags:Object.keys(Vo),builds:Object.keys(_o),hair:Object.keys(Ml),hairColors:{...xe},facialHair:Object.keys(Al),glasses:Object.keys(Pl),hats:Object.keys(Xo),feet:[...Fd],cast:Object.keys(yc),heldItems:Object.fromEntries(Object.entries(Cl).map(([s,i])=>[s,i.hands])),handMeetings:Object.keys(Pi)},codePanel:{languages:yr,removeStyles:pr,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:uc},surfaces:{code:Ti,board:He,chart:On,prop:Ts},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: ${vs.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 yt=t=>t.map(e=>`\`${e}\``).join(", "),p1=t=>Object.entries(t).map(([e,n])=>`| \`${e}\` | ${n.unit??n.kind??""} | ${n.description} |`).join(`
63
+ `);function T4(t,e={}){const n=g1(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: ${yt(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`).","","Style proportions: `headSize` is a fraction of height; `armLength` multiplies both upper arm and forearm lengths (default 1, positive finite). Hands, shoulders, torso and legs retain their sizes.","","### Pose fields","","| Field | Unit | What it does |","|---|---|---|",p1(s.poseFields),"","### Other props","","| Prop | Unit | What it does |","|---|---|---|",p1(s.props),"",`With \`style.hands\`, each hand has \`hand.left.<field>\` / \`hand.right.<field>\` props: ${yt(Object.keys(s.handFields))}.`,"",`**Poses** (a beat's \`do\`, or a pose key): ${yt(s.poses)}.`,"",`**Expressions** (a beat's \`mood\`): ${yt(s.expressions)}.`,"",`**Gags** (ms): ${Object.entries(s.gags).map(([o,r])=>`\`${o}\` (${r})`).join(", ")}.`,"",`**Gaits**: ${yt(s.gaits)}. **Acting styles** (\`style\`): ${yt(s.actingStyles)}.`,"","### Beat scripts","",`\`scriptTracks(target, beats, { from, ground, height, facing, style })\`. A beat has these fields only: ${yt(s.beatFields)}. Times are ms; \`to\` and \`target\` are scene px; \`onto\` is a floor's scene y.`,"","`characterScript(target, who, beats, options)` compiles the same beats for a v2 `character()` on a `characterTarget` (every option but `height`; the same result, its key poses on the human body; the walk phase keyed to that character's stride, and `walk` / `walking` / `gait` tracks that step the gait as the target draws). Add `hairFollowTracks(target, tracks, who)` after it so hanging hair swings.","","| `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**: ${yt(s.handShapes)}. **Mudras**: ${yt(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: ${yt(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(", ")}.`,"","Scenery: `scenery({ x, y, width, height, kind: sky | room, hour, clouds, wind, rain, snow, horizon: hills | city | flat })` is a canvas target whose values `hour` (0–24), `clouds`, `rain`, `snow` (0–1) and `wind` (−1..1) are tracks (`set(prop, { at, value, duration })`, `tracks(id)`; `anchor('sun' | 'moon' | 'horizon' | 'ground', time)`); the same `wind` streams hair (`hairFollowTracks(…, { wind })`). `scenePreset('park' | 'street' | 'office' | 'home', { width, height })` lays out scenery and props as data; `buildScene` builds them into targets.","","| 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: ${yt(n.character.poses)}. Expressions: ${yt(n.character.expressions)}. Gags: ${yt(n.character.gags)}.`,`Native dances: ${yt(n.character.dances)}; \`humanDanceFrame(style, beat, base)\` keeps body heading independent; \`humanDanceTracks(target, options)\` bakes JSON pose tracks. \`danceCircleAt(beat, { radius, count, beatsPerTurn, facing, spins })\` gives a formation with planted toes; \`danceCircleTracks(targets, options)\` bakes scene tracks. \`plantDanceFoot(partner, side, worldPoint)\` returns pose AND position; \`meetDandiya(a, b)\` solves both stick tips to one shared world point and reports unreachable contacts.`,"","Appearance options of `character({ … })`, all plain data that turns with the head (see docs/character-appearance.md):","",`- \`build\`: ${yt(n.character.builds)}`,`- \`figure\`: ${yt(n.character.figureStyles)}`,...Object.entries(n.character.body).map(([o,r])=>`- \`${o}\`: ${r}`),`- \`hair\`: ${yt(n.character.hair)} (colours: ${yt(Object.keys(n.character.hairColors))} in \`HAIR_COLORS\`)`,"- Flowing hair: `softSweep`, `flowingBob`, `cascadingWaves`; editable `locks: [{ path, width, follow? }]` with cubic `{ around, up, lift? }` points (around in degrees, dimensions in head radii), `fall: { taper, wave }` and `shine` (0–1). Roots stay attached; `hairFollowTracks` also drives flexible short locks.",`- \`facialHair\`: ${yt(n.character.facialHair)}`,`- \`glasses\`: ${yt(n.character.glasses)}; \`hat\`: ${yt(n.character.hats)}; \`ears: true\`; \`face: { teeth, tongue }\` (shown when the mouth opens); \`feet\`: ${yt(n.character.feet)}`,"- `outfit`: `{ top: tshirt | shirt | blouse | dress, trouserStyle: plain | jeans | cargo, shirt: top colour, trousers: bottom colour, sleeves: short | long | none, bottom: trousers | shorts | skirt, collar, tie: colour, over: apron | labCoat | hoodie | cardigan | overalls | sari, overColor, shoes: boots, shoeColor }`",`- \`castMember(name, height)\`: ${yt(n.character.cast)}`,"- Face marks (pose fields, 0–1): `blush`, `tears`, `sweat`; close-up fields `pupil` (size, 1 usual), `lid` (upper lids lowered, 0–1), `bulge` (eyes out of the head, 0–1); `face: { nose: true, inPupil(ctx, pupil) }`; `drawCharacterHead(ctx, who, pose, { x, y, radius })` draws just the head big",`- Face styles: ${yt(n.character.faceStyles)}; \`face: { style: 'anime', iris: '#4b7fce', lashes: true, ageLines: 0.8 }\` uses coloured eyes and the same expressions, blinks and gaze. \`ANIME_CAST\` contains eight age presets, also available through \`castMember\`.`,`- Face shapes: ${yt(n.character.faceShapes)}; \`face: { shape: 'angular', jawWidth: 0.74, chinWidth: 0.14, eyeScale: 0.8, eyeAspect: 0.65 }\` sets a tapered 3D jaw and narrower anime eyes; \`jawRoundness: 1\` softens the cheek/chin corners (default 0 keeps sharp jaws). \`MANGA_CAST\` contains four original young adult presets; hair styles \`mangaSpikes\` and \`mangaSweep\` remain editable.`,"- Hair in motion (pose fields): `hair.swing` (degrees round the head, + toward its left), `hair.trail` (head radii back), `hair.lift` (head radii up); key them with `hairFollowTracks(target, tracks, who)` after the character's tracks, or `hairFollow` + `hairMotionAt` when posing per frame",`- \`holding\`: ${Object.entries(n.character.heldItems).map(([o,r])=>`\`${o}\` (${r==="both"?"both":r==="either"?"one hand or both":"left or right"})`).join(", ")}; pose fields \`held.left\`, \`held.right\`, \`held.both\` (below 0.5 lets go); \`handGrip(joints, side)\``,`- \`meetHands(kind, a, b)\` (stand them \`meetingSpacing(kind, a, b)\` apart): ${yt(n.character.handMeetings)}; \`embrace(a, b)\` (a hug, \`embraceSpacing\` apart); \`helpUp(helper, sitter, progress)\` (0 on the floor, hand taken; 1 standing; \`helpUpSpacing\` apart)`,"- Everyday cycles like a gait: `humanCyclePose('sweeping' | 'brushing', phase, base)` (0 → 1 is one stroke and back; sweeping with `holding: { right: 'broom' }`)","","## Code panel","",`\`codePanel({ code, language, x, y, fontSize?, lineHeight?, width? })\`: a code listing as a scene object. Languages: ${yt(n.codePanel.languages)}. Remove styles: ${yt(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}`),""]),"## Cricket stories (`@algorisys/tinyfly/sports`)","","`cricketClip({ format, action, cast })` returns an organic-player scene, JSON tracks, timed events/captions and a declared result. `cricketField`, `cricketPlayer` and `cricketAction` compose separately; `cricketCameraTracks` adds camera tracks. These are authored tutorial plays, not physics or automatic umpiring. See docs/cricket.md.","",`Marking profiles: ${yt(Object.keys(n.sports.cricket.markingProfiles))}; default ICC men, independently of cast. Limited-over ICC profiles draw a wicket-centred capsule; Test/MCC have no restriction-area line. \`cricketFieldingAreaContains(field, point)\` returns true/false/null; \`cricketFieldingPositions\` and \`cricketFieldingOverlay\` provide owned setup markers, not umpiring decisions.`,"",...Object.entries(n.sports.cricket.actions).map(([o,r])=>`- \`${o}\`: ${r.summary}`),"",`Formats: ${yt(Object.keys(n.sports.cricket.formats))}. Casts: ${yt(Object.keys(n.sports.cricket.casts))}. Cameras: ${yt(Object.keys(n.sports.cricket.cameras))}. Orbit turns 360° around the whole ground. \`cricketCameraTracks(clip, { view, zoom })\` supports 0.25–4× optical magnification (default 1) in every view.`,"",`Stock fielding labels (\`CRICKET_FIELDING_POSITIONS\`): ${Object.entries(n.sports.cricket.fieldingPositions).map(([o,r])=>`\`${o}\`: ${r}`).join(", ")}. Eleven fielders, two on-field batters and two umpires; nine batting teammates wait off-field. Mid-on is closer to the pitch; long-on is its deeper boundary alternative, not an extra stock fielder. For the right-handed striker, +x is off side and -x is on/leg side.`,"","## 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 E4(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=ne(`${r.kind}:${r.time}:${r.x}`);r.kind==="dust"?Ep(t,{x:r.x,y:r.y},a,{size:o,color:i,seed:l}):r.kind==="exhaust"?P4(t,r,a,o,i,l):r.kind==="skid"?I4(t,r,a,n,i):r.kind==="honk"?O4(t,r,a,o,i):r.kind==="smoke"?A4(t,r,n,o,i):r.kind==="leaves"&&$4(t,r,a,o,s.leafColor??"#5cae5a",i,l)}}function A4(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 $4(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=ne(`${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,p=u*u*.4+u*.6,g=d+a*u*s*(.6+h)+Math.sin(u*9+h*6)*s*.18,m=Math.min(l-2,f+(l-f)*p);t.globalAlpha=n>.85?(1-n)/.15:1,t.save(),t.translate(g,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 P4(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=(ne(`${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 I4(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 O4(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 _4(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 u=Ir(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:C4(r)}),c}function C4(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 H4(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 R4(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,u;for(let f=t.start;;f=Math.min(t.end,f+n)){const p=Ir(t.leader,{state:e.getStateAtTime(f)},t.leaderId),g=p.anchor(t.hitch),m=p.values.turn,w=xs(s.prop,{...o,turn:m},s.propScale).anchors[t.anchor];if(!w)throw new Error(`propTow: ${s.prop.kind} has no anchor "${t.anchor}"`);const v=g.x-w.point.x;if(u!==void 0&&r){const k=Math.sin(m*Math.PI/2);h+=(v-u)*(k||1)/s.propScale/r*(180/Math.PI)}if(u=v,a.push({time:f,value:v-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 m1=new WeakMap;function L4(t,e){const n=e?.some(Boolean)?e.map(d=>d?1:0).join(""):"";let s=m1.get(t);s||m1.set(t,s=new Map);const i=s.get(n);if(i)return i;const o=Hi(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 g of d.corners)for(const m of[0,1,2])l[g][m]+=d.normal[m];const[f,...p]=d.corners;for(let g=0;g+1<p.length;g++){const[m,w,v]=[f,p[g],p[g+1]],[k,y,x]=[r.vertices[m],r.vertices[w],r.vertices[v]],P=[y[0]-k[0],y[1]-k[1],y[2]-k[2]],M=[x[0]-k[0],x[1]-k[1],x[2]-k[2]],T=[P[1]*M[2]-P[2]*M[1],P[2]*M[0]-P[0]*M[2],P[0]*M[1]-P[1]*M[0]],S=T[0]*d.normal[0]+T[1]*d.normal[1]+T[2]*d.normal[2];c.push(...S>=0?[m,w,v]:[m,v,w])}});const h=l.flatMap(d=>{const f=Math.hypot(...d)||1;return[d[0]/f,d[1]/f,d[2]/f]}),u=rr({positions:a,normals:h,indices:c});return s.size>=16&&s.clear(),s.set(n,u),u}function F4(t,e,n={}){const s=t.ink??n.ink??"#26262b",i=(n.outline??2)*(t.outline??1),o=t.glow&&e.glow>0?N4(t.glow.color,e.glow):void 0;return{color:t.fill??s,creases:Hi(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 N4(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 W4=rr(mg(1,.002,28));function D4(t,e,n){const s=t.rig,[i,o]=s.footprint??[s.length*.45,s.length],r=Math.max(0,It(s,e,"lift")),a=Math.max(0,It(s,e,"size"))/(1+r*.8);return{mesh:W4,world:Rt(n,va([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 B4=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),z4=1,q4={kind:"prop",validate(t){const e=t,n=typeof e.prop=="string"&&e.prop in As?[]:[ft("prop preset",e.prop,Object.keys(As))];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 Zc(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[M,T]of n)typeof T=="number"&&!B4.has(M)&&(h[M]=T);h.turn=0,h.tilt=0;const u=Rt(i.view,s),d={toView:M=>ie(u,M),toScreen:M=>a(M)},f=d.toView([0,c.rig.height/2,0]);if(-f[2]<=i.near)return null;if(l.look==="mesh"){const M=hm(c.rig,h),T=M.map(({part:$,local:A})=>({part:$.id,mesh:Hi($.shape),...Dc(Hi($.shape),A)})),S=im(T),E=M.map(($,A)=>({...$,hidden:rm($.part.id,T[A].mesh,$.local,T[A].key,S)})).filter(({opacity:$})=>$>.01).map(({part:$,matrix:A,glow:I,opacity:C,hidden:D})=>({mesh:L4($.shape,D),world:Rt(s,A),material:F4($,{glow:I,opacity:C},{shading:l.shading,ink:l.ink,outline:l.outline})}));return{meshes:l.shadow===!1?E:[D4(c,h,s),...E]}}const p=a(f),g=a(d.toView([0,c.rig.height/2+1,0])),m=Math.hypot(g.x-p.x,g.y-p.y),w=o.length===0?void 0:(M,T)=>{const S=ie(s,M),E=[s[0]*T[0]+s[4]*T[1]+s[8]*T[2],s[1]*T[0]+s[5]*T[1]+s[9]*T[2],s[2]*T[0]+s[6]*T[1]+s[10]*T[2]],$=Math.hypot(...E)||1;return{light:yg(S,[E[0]/$,E[1]/$,E[2]/$],o),fog:bg(r,Math.hypot(S[0]-i.position[0],S[1]-i.position[1],S[2]-i.position[2]))}},v=Yc(c.rig,h,d,m,{perspective:!0,near:i.near,slice:z4,light:w}),k={look:l.look,style:l.style,ink:l.ink,paper:l.paper,fog:r?.color},y=Kl(v),x=v.cells??[],P=Math.max(...x.map(M=>-M.depth),-f[2]);return{drawables:[...l.shadow===!1?[]:[{depth:P+c.rig.length,draw:M=>Xl(M,v,k)}],...x.map(M=>({depth:-M.depth,draw(T,S){T.lineCap="round",T.lineJoin="round",kg(T,M.parts,y,{...k,time:S.time})}}))]}}},ah=["do","at","for","to","through","toward","speed","height","open","on","wind"],j4=.25,Y4=800/180,K4=220,X4=300,G4=["turn"];function U4(t){const e=Rr(t),n=Object.keys(t.moves??{});return Object.keys(e).filter(s=>!n.includes(s)&&!G4.includes(s)&&!(e[s].needs??[]).includes("to"))}function y1(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=U4(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))ah.includes(u)||l(ft("beat field",u,ah,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&&!Pn(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(Pn))&&l("`through` is a list of points on the ground, each [x, z] metres.")),c.do==="face"&&!(Pn(c.toward)||typeof c.toward=="number")&&l("`face` needs `toward`: a point [x, z] or a heading in degrees.")}),o}function V4(t,e,n,s){const i=y1(n,e);if(i.length>0)throw new Error(`propScript3D (${e.kind}): ${i.length} problem(s) in the beats:
65
65
  ${i.map(k=>` beat ${k.beat}: ${k.message}`).join(`
66
- `)}`);const o={};for(const k of[...Object.keys(Ss),...Object.keys(e.rig.controls)])o[k]=s.values?.[k]??It(e.rig,{},k);let[r,a]=s.position??[0,0],l=s.heading??0;const c=new Map,h=(k,y,x,P="linear")=>{const M=c.get(k)??[];M.push({time:y,value:x,easing:P}),c.set(k,M)},u=(k,y,x)=>h(k,y,x);h("x",0,r),h("z",0,a),h("rotateY",0,l);const d=(k,y)=>{const x=cr(l,y);if(Math.abs(x)<1)return k;const P=Math.max(D4,Math.abs(x)*W4);return u("rotateY",k,l),l+=x,h("rotateY",k+P,l,"ease-in-out"),k+P},f=(k,y,x)=>{const P=Bg([[r,a],...y.through??[y.to]]);if(P.length<2)return x;const M=d(x,ps(P[0].point,P[1].point)),T=P[P.length-1].at,S=y.for??T/(y.speed??k.speed)*1e3,E=Wt("ease-in-out"),$=Math.min(B4,S/4);for(const[V,et]of Object.entries(k.set??{}))u(V,M,o[V]),h(V,M+1,et),o[V]=et;const A=k.flies?y.height??(o.lift>.05?o.lift:2):void 0,I=A!==void 0&&A>.05;for(const[V,et]of Object.entries(k.hold??{}))u(V,M,o[V]),h(V,M+$,et,"ease-out"),I||(h(V,M+S-$,et),h(V,M+S,0,"ease-in")),o[V]=I?et:0;A!==void 0&&(u("lift",M,o.lift),h("lift",M+Math.min(S*.35,1400),A,"ease-out"),h("lift",M+S,A),o.lift=A);const C={...o};let D=l;for(let V=0;;V=Math.min(T,V+N4)){const et=M+qg(E,V/T)*S,{point:G,direction:F}=zg(P,V);D+=cr(D,ps([0,0],F)),h("x",et,G[0]),h("z",et,G[1]),h("rotateY",et,D);for(const[H,W]of Object.entries(k.perMetre??{}))h(H,et,C[H]+V*W);for(const[H,W]of Object.entries(k.perSecond??{}))h(H,et,C[H]+(et-M)/1e3*W);if(V>=T)break}for(const[V,et]of Object.entries(k.perMetre??{}))o[V]=C[V]+T*et;for(const[V,et]of Object.entries(k.perSecond??{}))o[V]=C[V]+S/1e3*et;return[r,a]=P[P.length-1].point,l=D,M+S},p=(k,y)=>{const x=Object.fromEntries(Object.entries(k).filter(([M])=>!["at","to","through","toward"].includes(M))),P=a1(t,e,[x],{start:{...o,turn:1},scale:100,style:s.style,exaggeration:s.exaggeration});for(const M of P.tracks){if(Y4.includes(M.property))continue;const T=M.keyframes??[],S=o[M.property];if(!T.every(E=>E.value===S)){u(M.property,y,S);for(const E of T)E.time>0&&c.get(M.property).push({...E,time:y+E.time});o[M.property]=T[T.length-1].value}}return y+P.duration},g=[];let m=0;for(const k of n){const y=k.at??m;let x=y;const P=e.moves?.[k.do];P?x=f(P,k,y):k.do==="face"?x=d(y,typeof k.toward=="number"?k.toward:ps([r,a],k.toward)):k.do==="hold"?x=y+(k.for??1e3):x=p(k,y),g.push({do:k.do,start:y,end:x}),m=x}const w=`${s.scene}/${t}`;return{tracks:[...c].map(([k,y])=>({id:`${t}-${k}`,target:w,property:k,keyframes:Dg(y)})),duration:m,beats:g,end:{position:[r,a],heading:l,values:{...o}}}}const Y4=["x","y","turn","facing","tilt"],K4=.35,oh={seated:ye.sit,astride:{...ye.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},driving:{...ye.sit,"arm.left.swing":52,"arm.right.swing":52,"arm.left.spread":8,"arm.right.spread":8,"arm.left.elbow":38,"arm.right.elbow":38,lean:4},wheeling:{...ye.sit,"arm.left.swing":-6,"arm.right.swing":-6,"arm.left.spread":16,"arm.right.spread":16,"arm.left.elbow":28,"arm.right.elbow":28,"leg.left.knee":80,"leg.right.knee":80},cycling:{...ye.sit,lean:22,bend:10,"head.nod":-14,"arm.left.swing":58,"arm.right.swing":58,"arm.left.spread":10,"arm.right.spread":10,"arm.left.elbow":22,"arm.right.elbow":22,"leg.left.spread":6,"leg.right.spread":6}},X4=22,f1=38;function rh(t,e=oh.cycling){const n=t*Math.PI*2,s=r=>({swing:(e["leg.left.swing"]??40)+X4*Math.cos(n+r),knee:(e["leg.left.knee"]??70)+f1*(.5+.5*Math.cos(n+r))-f1*.5,ankle:12*Math.sin(n+r)}),i=s(0),o=s(Math.PI);return{...e,"leg.left.swing":i.swing,"leg.left.knee":i.knee,"leg.left.ankle":i.ankle,"leg.right.swing":o.swing,"leg.right.knee":o.knee,"leg.right.ankle":o.ankle}}function G4(t){const e=t.cadence??1.2,n=Math.max(2,t.samplesPerTurn??8),s=1e3/e/n,i=[];for(let o=t.start,r=0;o<t.end;o+=s,r++)i.push({time:Math.round(o),pose:rh((o-t.start)/1e3*e,t.base),...r>0?{act:!1}:{}});return i.push({time:t.end,pose:rh((t.end-t.start)/1e3*e,t.base),act:!1}),i}const g1=(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 U4(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=us({...t.character,height:1}),c={...lt,...t.pose??oh.seated},h=Ue(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 w=n.getStateAtTime(m).values.get(e)??new Map,v=(C,D)=>{const j=w.get(C);return typeof j=="number"?j:D},k={...s.values};for(const C of Object.keys(a.controls))k[C]=v(C,s.values?.[C]??It(a,{},C));for(const C of["pitch","roll","squash","lift","lean","size"])k[C]=v(C,s.values?.[C]??It(a,{},C));const y=hm(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 x=v("rotateY",s.heading??0),P=g1(y,x),M=[v("x",i)+P[0],v("y",o)+P[1],v("z",r)+P[2]],T=x+u,S=g1(h,T);let E=[M[0]-S[0],M[1]-S[1],M[2]-S[2]];const $=(C,D)=>{const j=D*D*(3-2*D);return[C[0]+(E[0]-C[0])*j,E[1]*j+K4*Math.sin(Math.PI*D),C[1]+(E[2]-C[1])*j]},A=t.mount?Math.max(1,t.mount.for??450):0,I=t.dismount?Math.max(1,t.dismount.for??450):0;if(t.mount&&m<t.start+A?E=$(t.mount.from,(m-t.start)/A):t.dismount&&m>t.end-I&&(E=$(t.dismount.to,(t.end-m)/I)),f.x.push({time:m,value:E[0]}),f.y.push({time:m,value:E[1]}),f.z.push({time:m,value:E[2]}),f.rotateY.push({time:m,value:T}),m>=t.end)break}const p=t.riderId,g=`${t.scene}/${p}`;return Object.keys(f).map(m=>({id:`${p}-${m}`,target:g,property:m,keyframes:f[m]}))}const p1={ground:"#7fb56a",hills:"#5f9a58",city:"#4b5468",cloud:"#ffffff",sun:"#ffd45c",moon:"#f3f0e0",rain:"#9fc4e8",snow:"#ffffff",wall:"#e9e1cf",floor:"#b08a5e",skirting:"#8a6a44",frame:"#f7f3ea"},Hi=[[0,"#0b1530","#1b2a4a"],[4.5,"#141a3e","#2a2f5a"],[6,"#4a3f7a","#f0a070"],[7.5,"#86c2ee","#d8ecf8"],[12,"#5aaef2","#c0e2f8"],[16.5,"#69b0e6","#f5d79a"],[18.5,"#4c3f78","#f08a5a"],[20.5,"#17203f","#2d3660"],[24,"#0b1530","#1b2a4a"]],Ri=(t,e,n)=>{const s=r=>[1,3,5].map(a=>parseInt(r.slice(a,a+2),16)),[i,o]=[s(t),s(e)];return`#${i.map((r,a)=>Math.round(r+(o[a]-r)*n).toString(16).padStart(2,"0")).join("")}`},V4=t=>{const e=(t%24+24)%24;return e<5||e>20?0:e<7?(e-5)/2:e>18?(20-e)/2:1};function m1(t){const e=(t%24+24)%24;for(let n=1;n<Hi.length;n++){const[s,i,o]=Hi[n-1],[r,a,l]=Hi[n];if(e<=r){const c=(e-s)/(r-s);return{top:Ri(i,a,c),bottom:Ri(o,l,c)}}}return{top:Hi[0][1],bottom:Hi[0][2]}}const J4=(t,e)=>{const n=((t-e)%24+24)%24;return n<=12?n/12:-1},Z4=9,Q4=55,tx=28;function y1(t){const{x:e,y:n,width:s,height:i}=t,o=t.kind??"sky",r=t.ground??n+i*.85,a={...p1,...t.colors},l=t.horizon??"hills",c=t.window!==!1,h=je(t.seed??1),u=s*i/1e5,d=Array.from({length:Math.ceil(Z4*u)+2},()=>({u:h.next(),v:h.next(),size:.6+h.next()*.8,puffs:2+Math.floor(h.next()*3)})),f=Array.from({length:Math.ceil(Q4*u)+4},()=>({u:h.next(),v:h.next(),speed:.8+h.next()*.5})),p=Array.from({length:Math.ceil(tx*u)+4},()=>({u:h.next(),v:h.next(),speed:.7+h.next()*.6,sway:h.next()*Math.PI*2,size:1.5+h.next()*2})),g=Array.from({length:Math.ceil(30*u)+10},()=>({u:h.next(),v:h.next()*.6,size:.6+h.next()*1.2})),m=Array.from({length:6},()=>({phase:h.next()*Math.PI*2,amp:.5+h.next()})),w=Array.from({length:24},()=>({h:.35+h.next()*.65,w:.6+h.next()*.8,windows:h.next()>.3})),v={hour:t.hour??12,clouds:t.clouds??.3,wind:t.wind??0,rain:t.rain??0,snow:t.snow??0},k=ms(),y=(E,$)=>k.keys(E)?.length?k.valueAt(E,$):v[E],x=(E,$)=>{const A=J4(E,$),I=A<0?.5:A,C=r-n;return{x:.1*s+.8*s*I,y:A<0?C+i*.2:C-Math.sin(I*Math.PI)*C*.8,up:A>=0}},P=(E,$,A,I,C)=>{const D=$("hour"),{top:j,bottom:V}=m1(D),et=E.createLinearGradient(0,I.y,0,I.ground);et.addColorStop(0,j),et.addColorStop(1,V),E.fillStyle=et,E.fillRect(I.x,I.y,I.w,I.ground-I.y);const G=V4(D);if(G<.6){E.fillStyle="#ffffff",E.globalAlpha=(.6-G)/.6*.9;for(const R of g)E.beginPath(),E.arc(I.x+R.u*I.w,I.y+R.v*(I.ground-I.y),R.size,0,Math.PI*2),E.fill();E.globalAlpha=1}const F=x(D,6),H=x(D,18),W=Math.min(I.w,I.h)*.06;if(F.up&&(E.fillStyle=a.sun,E.beginPath(),E.arc(I.x+F.x/s*I.w,I.y+F.y/i*I.h,W,0,Math.PI*2),E.fill()),H.up){const R=I.x+H.x/s*I.w,z=I.y+H.y/i*I.h;E.fillStyle=a.moon,E.beginPath(),E.arc(R,z,W*.8,0,Math.PI*2),E.fill(),E.fillStyle=j,E.beginPath(),E.arc(R-W*.35,z-W*.15,W*.7,0,Math.PI*2),E.fill()}const _=Math.max(0,Math.min(1,$("clouds"))),B=Math.max(-1,Math.min(1,$("wind"))),Q=Math.round(_*d.length);E.fillStyle=Ri("#ffffff",a.cloud==="#ffffff"?"#ffffff":a.cloud,1),E.globalAlpha=.55+.4*G;for(let R=0;R<Q;R++){const z=d[R],K=((z.u*I.w+B*A*.012*(.6+z.size*.5))%(I.w*1.4)+I.w*1.4)%(I.w*1.4)-I.w*.2,N=I.x+K,q=I.y+(.08+z.v*.42)*(I.ground-I.y),Y=Math.min(I.w,I.h)*.07*z.size;for(let J=0;J<z.puffs;J++)E.beginPath(),E.ellipse(N+(J-(z.puffs-1)/2)*Y*.9,q+J%2*Y*.25,Y*(J%2?.8:1),Y*.62,0,0,Math.PI*2),E.fill()}E.globalAlpha=1;const O=R=>Ri(Ri(R,"#0b1530",.65),R,G);if(l==="hills"){E.fillStyle=O(a.hills),E.beginPath(),E.moveTo(I.x,I.ground);const R=40;for(let z=0;z<=R;z++){const K=z/R;let N=0;m.forEach((q,Y)=>N+=Math.sin(K*Math.PI*(1.5+Y*.7)+q.phase)*q.amp),E.lineTo(I.x+K*I.w,I.ground-Math.max(0,N)*I.h*.045-I.h*.03)}E.lineTo(I.x+I.w,I.ground),E.closePath(),E.fill()}else if(l==="city"){E.fillStyle=O(a.city);let R=I.x;const z=I.w/18;for(const K of w){if(R>I.x+I.w)break;const N=z*K.w,q=I.h*.22*K.h;if(E.fillRect(R,I.ground-q,N,q),K.windows&&G<.5){E.fillStyle="#ffd66b",E.globalAlpha=.5-G;for(let Y=I.ground-q+6;Y<I.ground-8;Y+=9)for(let J=R+4;J<R+N-4;J+=8)E.fillRect(J,Y,3,4);E.globalAlpha=1,E.fillStyle=O(a.city)}R+=N+z*.15}}E.fillStyle=O(a.ground),E.fillRect(I.x,I.ground,I.w,I.y+I.h-I.ground)},M=(E,$,A,I)=>{const C=Math.max(-1,Math.min(1,$("wind"))),D=Math.max(0,Math.min(1,$("rain"))),j=Math.max(0,Math.min(1,$("snow")));if(D>0){E.strokeStyle=a.rain,E.globalAlpha=.35+.45*D,E.lineWidth=1.2,E.lineCap="round";const V=I.h*.05,et=C*.45,G=Math.round(D*f.length);E.beginPath();for(let F=0;F<G;F++){const H=f[F],W=((H.v*I.h+A*H.speed*.9)%I.h+I.h)%I.h,_=((H.u*I.w+W*et)%I.w+I.w)%I.w;E.moveTo(I.x+_,I.y+W),E.lineTo(I.x+_+et*V,I.y+W+V)}E.stroke(),E.globalAlpha=1}if(j>0){E.fillStyle=a.snow,E.globalAlpha=.85;const V=Math.round(j*p.length);for(let et=0;et<V;et++){const G=p[et],F=((G.v*I.h+A*G.speed*.08)%I.h+I.h)%I.h,H=Math.sin(A*.002+G.sway)*I.w*.02,W=((G.u*I.w+H+C*F*.3)%I.w+I.w)%I.w;E.beginPath(),E.arc(I.x+W,I.y+F,G.size,0,Math.PI*2),E.fill()}E.globalAlpha=1}},S={kind:"scenery",target:{type:"custom",x:e,y:n,width:s,height:i,props:v,about:{kind:o==="room"?"room":"sky",summary:o==="room"?"A room: a wall, a floor and a window on the sky. Its values are tracks: hour, clouds, wind, rain, snow (seen through the window).":`A sky over ${l==="flat"?"the ground":l}: the sun and moon on their arcs, stars, clouds on the wind, rain and snow. Its values are tracks: hour (0–24), clouds, wind (−1..1), rain, snow (0..1).`,props:Object.fromEntries(Object.keys(v).map(E=>[E,ex(E)]))},draw(E,$,A){const I=$.props??{},C=j=>Number(I[j]??v[j]??0);E.save();const D={x:0,y:0,w:s,h:i,ground:r-n};if(o==="sky")P(E,C,A,D),M(E,C,A,D);else if(E.fillStyle=a.wall,E.fillRect(0,0,s,D.ground),E.fillStyle=a.floor,E.fillRect(0,D.ground,s,i-D.ground),E.fillStyle=a.skirting,E.fillRect(0,D.ground-i*.012,s,i*.012),c){const j=s*.26,V=D.ground*.5,et=s*.62,G=D.ground*.14;E.fillStyle=a.frame,E.fillRect(et-6,G-6,j+12,V+12),E.save(),E.beginPath(),E.rect(et,G,j,V),E.clip(),P(E,C,A,{x:et,y:G,w:j,h:V,ground:G+V*.8}),M(E,C,A,{x:et,y:G,w:j,h:V}),E.restore(),E.strokeStyle=a.frame,E.lineWidth=4,E.beginPath(),E.moveTo(et+j/2,G),E.lineTo(et+j/2,G+V),E.moveTo(et,G+V/2),E.lineTo(et+j,G+V/2),E.stroke()}E.restore()}},ground:r,anchor(E,$=1/0){const A=y("hour",$);if(E==="sun"||E==="moon"){const I=x(A,E==="sun"?6:18);return{x:e+I.x,y:n+I.y}}if(E==="horizon")return{x:e+s/2,y:r-i*.03};if(E==="ground")return{x:e+s/2,y:r};throw new Error(`scenery: ${ft("place",E,["sun","moon","horizon","ground"])}`)},set(E,$){if(!(E in v))throw new Error(`scenery: ${ft("value",E,Object.keys(v))}`);if(typeof $.value!="number"||!Number.isFinite($.value))throw new Error("scenery.set needs `value`, a number");return k.tween(E,y(E,$.at),$.value,$,1e3),S},tracks:k.tracks};return S}function ex(t){switch(t){case"hour":return{description:"The time of day, 0–24: the sky’s colours, the sun and the moon on their arcs, stars at night",unit:"hours",min:0,max:24};case"clouds":return{description:"Cloud cover",unit:"0..1",min:0,max:1};case"wind":return{description:"The wind, blowing left (−) or right (+): clouds drift, rain slants, snow drifts",unit:"-1..1",min:-1,max:1};case"rain":return{description:"How hard it rains",unit:"0..1",min:0,max:1};default:return{description:"How hard it snows",unit:"0..1",min:0,max:1}}}function b1(t,e){const{width:n,height:s}=e,i=e.ground??s*.85,o=e.scale??s/4.5,r={x:0,y:0,width:n,height:s,ground:i},a=(l,c,h={})=>({preset:l,x:n*c,scale:o,...h});switch(t){case"park":return{scenery:{...r,hour:10.5,clouds:.35,horizon:"hills",...e.scenery},props:[a("tree",.14,{scale:o*1.1}),a("chair",.5,{turn:0}),a("tree",.86,{scale:o*.9})]};case"street":return{scenery:{...r,hour:16,clouds:.25,horizon:"city",colors:{ground:"#8a8f99"},...e.scenery},props:[a("house",.2,{scale:o*.75,turn:.1}),a("car",.5,{turn:1,scale:o*.9}),a("house",.78,{scale:o*.7,turn:.1}),a("tree",.95,{scale:o*.8})]};case"office":return{scenery:{...r,kind:"room",hour:11,clouds:.3,colors:{wall:"#dfe5ec",floor:"#9aa3ad",skirting:"#6c757d"},...e.scenery},props:[a("door",.1,{turn:.15}),a("chair",.46,{turn:0}),a("desk",.58,{turn:0})]};case"home":return{scenery:{...r,kind:"room",hour:20,clouds:.2,...e.scenery},props:[a("door",.08,{turn:.15}),a("chair",.35,{turn:.3}),a("bed",.72,{turn:.25})]};default:throw new Error(ft("scene preset",t,["park","street","office","home"]))}}function nx(t,e){const n=b1(t,e),s=y1(n.scenery),i=n.props.map(o=>dm({x:o.x,y:s.ground,prop:Vc(o.preset),scale:o.scale,values:{turn:o.turn??0,...o.values}}));return{scenery:s,props:i,ground:s.ground}}function ah(t,e){if(!Array.isArray(t)||t.length!==3||!t.every(Number.isFinite))throw new Error(`${e}: expected three finite coordinates`)}function w1(t,e,n=40,s=[]){if(!Number.isFinite(t)||!Number.isFinite(e)||t<0||e<t)throw new Error("sampleTimes: expected finite ordered nonnegative times");if(!Number.isFinite(n)||n<16||n>1e3)throw new Error("sampleTimes: every must be between 16 and 1000 ms");if((e-t)/n>2e4)throw new Error("sampleTimes: too many samples");const i=new Set([t,e,...s.filter(o=>o>=t&&o<=e&&Number.isFinite(o))]);for(let o=t+n;o<e;o+=n)i.add(o);return[...i].sort((o,r)=>o-r)}function lh(t,e){if(k1(t),!Number.isFinite(e))throw new Error("ballFlightPoint: time must be finite");const n=Math.max(0,Math.min(1,(e-t.start)/(t.end-t.start))),s=4*n*(1-n),i=t.to[0]-t.from[0],o=t.to[2]-t.from[2],r=Math.hypot(i,o)||1;return[t.from[0]+i*n-o/r*(t.curve??0)*s,t.from[1]+(t.to[1]-t.from[1])*n+(t.arc??0)*s,t.from[2]+o*n+i/r*(t.curve??0)*s]}function k1(t){if(!t.target?.trim())throw new Error("ballFlight: target is required");if(ah(t.from,"ballFlight.from"),ah(t.to,"ballFlight.to"),!Number.isFinite(t.start)||!Number.isFinite(t.end)||t.start<0||t.end<=t.start)throw new Error("ballFlight: end must be greater than start, both finite and nonnegative");if(!Number.isFinite(t.arc??0)||(t.arc??0)<0||!Number.isFinite(t.curve??0))throw new Error("ballFlight: arc must be finite and nonnegative; curve must be finite")}function sx(t){k1(t);const e=w1(t.start,t.end,t.every),n=e.map(s=>lh(t,s));return["x","y","z"].map((s,i)=>({id:`${t.id??"flight"}-${s}`,target:t.target,property:s,keyframes:e.map((o,r)=>({time:o,value:n[r][i]}))}))}const Ct=(t,e,n)=>Math.max(0,Math.min(1,(t-e)/(n-e))),Ft=t=>t*t*(3-2*t),Tt=(t,e)=>Ys(t,e),ch=(t,e)=>fn(t,e);function hh(t,e){const n=e+((t-e+2)%4+4)%4-2;return n===0?0:n}function Is(t,e,n=0){return Math.hypot(e[0]-t[0],e[2]-t[2])<.001?n:hh(Math.atan2(e[0]-t[0],e[2]-t[2])*2/Math.PI,n)}function v1(){return{turn:1,"head.turn":90,"leg.left.spread":12,"leg.right.spread":12,"leg.left.swing":6,"leg.right.swing":6,"leg.left.knee":12,"leg.right.knee":12}}function M1(t,e){const n=t.objects.find(s=>s.id===e);if(!n||n.kind!=="character")throw new Error(`cricketAction: required character '${e}' is missing`);if(n.parent||n.rotation?.some(s=>s!==0)||n.quaternion||n.scale!==void 0)throw new Error(`cricketAction: '${e}' must use position and pose.turn, without a transformed parent, scale or object rotation`);return{object:n,who:us({...n.character,height:n.height??1.78})}}function ix(t){return{position:[...t.object.position??[0,0,0]],pose:{...lt,...t.object.pose}}}function Li(t,e,n,s){const i=Ue(t.who.plan,e.pose,{height:t.who.height,contact:t.who.contact});return Tt(e.position,i.chains[n][s])}function Fi(t,e,n){const s=Li(t,e,`arm.${n}`,2),i=Li(t,e,`arm.${n}`,1);return Tt(s,ch(Jt(se(s,i)),t.who.lineWidth*.5))}function ox(t,e,n){const s={...e.pose,"head.turn":0,"head.nod":0,"head.tilt":0},i=Ue(t.who.plan,s,{height:t.who.height,contact:t.who.contact}).head,o=se(n,Tt(e.position,i.center)),r=i.axes.map(c=>Ae(o,c)),a=Math.atan2(r[0],r[2])*180/Math.PI,l=Math.atan2(-r[1],Math.hypot(r[0],r[2]))*180/Math.PI;return{...e,pose:{...e.pose,"head.turn":Math.max(-90,Math.min(90,a)),"head.nod":Math.max(-25,Math.min(30,l)),"head.tilt":0}}}function ln(t,e,n,s,i="hold"){let o={...e.pose};for(let r=0;r<10;r++){const a={...e,pose:o},l=Ue(t.who.plan,o,{height:t.who.height,contact:t.who.contact}),c=ts(t.who.plan,o,t.who.height),h=se(Fi(t,a,n),Li(t,a,`arm.${n}`,2)),u=se(se(se(s,h),e.position),l.hip),d=Qn(u,(o.roll??0)*Math.PI/180),f=Tt(c.root,Qt(d,-(o.turn??0)*Math.PI/2));o=ci(t.who.plan,o,`arm.${n}`,f,{height:t.who.height})}for(const[r,a]of Object.entries(St[i]))o[`hand.${n}.${r}`]=a;return{...e,pose:o}}function rx(t,e,n,s){const i=Jt(s),o=t.who.height/1.78;let r=ln(t,e,"left",n);return r=ln(t,r,"right",Tt(Fi(t,r,"left"),ch(i,.105*o))),{...r,bat:{grip:Fi(t,r,"left"),axis:i,scale:o}}}function ax(t){return Tt(t.grip,ch(t.axis,.51*t.scale))}function S1(t){const e=Jt(t),n=Math.max(-1,Math.min(1,e[1]));return n>.999999?[0,0,0,1]:n<-.999999?Vt([1,0,0],180):Vt(Jt(Ks([0,1,0],e)),Math.acos(n)*180/Math.PI).map(s=>s===0?0:s)}function Rr(t,e,n){const s={};for(const i of Object.keys({...t,...e})){const o=t[i]??lt[i]??0;s[i]=o+((e[i]??lt[i]??0)-o)*n}return s}function x1(t,e){if(t<=e[0][0])return{...lt,...e[0][1]};for(let n=1;n<e.length;n++)if(t<=e[n][0])return Rr({...lt,...e[n-1][1]},{...lt,...e[n][1]},Ft(Ct(t,e[n-1][0],e[n][0])));return{...lt,...e.at(-1)[1]}}const jt=Object.freeze({length:20.12,width:3.05,poppingCrease:1.22,returnCrease:1.32,stumpHeight:.711,wicketWidth:.2286});function T1(t){if(!t.id?.trim())throw new Error("cricketPlayer: id is required");Fe({batter:1,bowler:1,keeper:1,fielder:1,umpire:1},t.role,"cricketPlayer.role");const e=Fe(Ei,t.preset??"youngMan","cricketPlayer.preset"),n=Fe($s,t.format??"t20","cricketPlayer.format"),s=Fe({none:1,cap:1,"sun-hat":1},t.headwear??"none","cricketPlayer.headwear"),i=e==="childBoy"||e==="childGirl",o=t.height??(i?1.24:1.78);if(!Number.isFinite(o)||o<.5||o>3)throw new Error("cricketPlayer: height must be between .5 and 3 metres");ah(t.position??[0,0,0],"cricketPlayer.position");const r=t.role==="umpire"?"#f5ebd5":n==="test"?"#f5f0df":t.color??"#3577b5",a=JSON.parse(JSON.stringify({...Ei[e],...t.appearance,outfit:pp("casual",{top:"shirt",shirt:r,trousers:t.role==="umpire"?"#405058":r,bottom:"trousers",trouserStyle:"plain",sleeves:"short",collar:!0,tie:null,shoes:"boots",shoeColor:"#f3ead7"}),hat:s==="none"?null:{style:s==="sun-hat"?"sunHat":"cap",color:r}}));return{id:t.id,name:t.role,kind:"character",look:"pen",height:o,position:[...t.position??[0,0,0]],character:a,pose:t.role==="batter"?v1():{turn:t.role==="keeper"?2:0}}}function Lr(t,e,n,s,i=0){return{id:t,kind:"mesh",position:e,geometry:{type:"box",size:n},material:s,layer:i}}function lx(t,e){const n=jt.stumpHeight,s=(jt.wicketWidth-.036)/2;return[...[-1,0,1].map((i,o)=>({id:`${t}-stump-${o}`,kind:"mesh",position:[i*s,n/2,e],geometry:{type:"cylinder",radius:.018,height:n,segments:10},material:"wicket"})),...[-1,1].map((i,o)=>Lr(`${t}-bail-${o}`,[i*s/2,n+.015,e],[.105,.025,.035],"bail"))]}function E1(t,e){return[{id:t,kind:"group",scale:e,visible:!1},Lr(`${t}-grip`,[0,.1,0],[.036,.28,.036],"bat-grip"),Lr(`${t}-blade`,[0,.51,0],[.108,.54,.055],"bat-blade"),Lr(`${t}-label`,[0,.41,.029],[.07,.16,.004],"bat-label")].map((s,i)=>i===0?s:{...s,parent:t})}function A1(t={}){const e=Fe($s,t.format??"t20","cricketField.format"),n=Fe(th,t.cast??"adults","cricketField.cast"),s=t.boundaryRadius??64;if(!Number.isFinite(s)||s<24||s>250)throw new Error("cricketField: boundaryRadius must be between 24 and 250 metres");const i=t.id??"cricket";if(!i.trim())throw new Error("cricketField: id is required");const o=jt.length/2,r={"striker-wicket":[0,0,o],"bowler-wicket":[0,0,-o],"striker-crease":[0,0,o-jt.poppingCrease],"bowler-crease":[0,0,-o+jt.poppingCrease]},a=[{id:"camera",kind:"camera",projection:"perspective",position:[25,9,6],lookAt:[0,.65,0],fov:48,near:.02,far:Math.max(600,s*4)},{id:"sun",kind:"light",light:"directional",position:[4,8,5],intensity:.8,color:"#fff2dd"},{id:"ambient",kind:"light",light:"ambient",intensity:.85,color:"#eaf6f4"},{id:"outfield",kind:"mesh",layer:-4,position:[0,-.04,0],geometry:{type:"cylinder",radius:s+1,height:.06,segments:80},material:"grass"},{id:"square",kind:"mesh",layer:-3,geometry:{type:"plane",size:[8,25]},position:[0,.003,0],material:"square"},{id:"pitch",kind:"mesh",layer:-2,geometry:{type:"plane",size:[jt.width,jt.length]},position:[0,.008,0],material:"pitch"},{id:"boundary",kind:"line",layer:-1,closed:!0,width:.15,color:"#f8f2db",points:Array.from({length:96},(u,d)=>[Math.cos(d*Math.PI/48)*s,.022,Math.sin(d*Math.PI/48)*s])}];e!=="test"&&a.push({id:"fielding-circle",kind:"line",layer:-1,closed:!0,width:.06,color:"#d6e4c8",points:Array.from({length:80},(u,d)=>[Math.cos(d*Math.PI/40)*27.43,.018,Math.sin(d*Math.PI/40)*27.43])});for(const u of[-1,1]){const d=u>0?"striker":"bowler",f=u*o,p=f-u*jt.poppingCrease;a.push(...lx(d,f));const g=(m,w)=>a.push({id:`${d}-${m}`,kind:"line",layer:-1,color:"#fffdf0",width:.045,points:w});g("popping-line",[[-1.83,.02,p],[1.83,.02,p]]),g("bowling-line",[[-1.32,.02,f],[1.32,.02,f]]);for(const m of[-1,1])g(`return-line-${m<0?"left":"right"}`,[[m*1.32,.02,p],[m*1.32,.02,f+u*2.5]])}const l=[["batter","batter",[-.38,0,9.3]],["non-striker","batter",[-.85,0,-9.3]],["bowler","bowler",[.68,0,-17]],["keeper","keeper",[0,0,11.25]],["fielder","fielder",[12,0,-3]],["slip","fielder",[3.5,0,12]],["point","fielder",[20,0,6]],["cover","fielder",[22,0,-16]],["mid-off","fielder",[9,0,-25]],["mid-on","fielder",[-9,0,-25]],["square-leg","fielder",[-20,0,7]],["fine-leg","fielder",[-20,0,35]],["third-man","fielder",[23,0,35]],["umpire","umpire",[0,0,-12.4]],["square-umpire","umpire",[-15,0,8.84]]];l.forEach(([u,d,f],p)=>{const g=n==="children"||n==="mixed"&&p%3===0,m=n==="men"?"youngMan":g?p%2?"childGirl":"childBoy":p%2?"youngWoman":"youngMan",w=Math.hypot(f[0],f[2]),v=w>s*.88?[f[0]*s*.88/w,0,f[2]*s*.88/w]:[...f];r[u]=[...v];const k=T1({id:u,role:d,preset:m,format:e,position:v,color:d==="batter"?t.battingColor??"#397cb9":t.fieldingColor??"#bf604e"});if(Object.hasOwn(Hr,u)&&(k.name=Hr[u]),u!=="batter"){const y=u==="non-striker"||u==="bowler"?l[0][2]:l.find(([x])=>x==="bowler")[2];k.pose={turn:Is(v,y)}}a.push(k)});const c=u=>a.find(d=>d.id===u).height/1.78;a.push(...E1("bat",c("batter")),...E1("non-striker-bat",c("non-striker"))),a.push({id:"ball",kind:"mesh",position:[0,.075,0],geometry:{type:"sphere",radius:.075,segments:12},material:"ball"}),a.push({id:"lbw-guide",kind:"group",visible:!1},{id:"lbw-projection",kind:"line",parent:"lbw-guide",points:[[0,0,0],[0,1,0]],width:.04,color:"#e9ae38"});const h=u=>({color:u,shading:"toon",outline:{color:"#69513a",width:.8}});return{format:e,boundaryRadius:s,landmarks:r,scene:{id:i,formatVersion:1,camera:"camera",background:{top:"#c8e5ef",bottom:"#e9efcc"},ground:0,objects:a,materials:{grass:{color:"#81a95c",shading:"unlit"},square:{color:"#a6b76a",shading:"unlit",doubleSided:!0},pitch:{color:"#ddbd85",shading:"unlit",doubleSided:!0},wicket:h("#edd99e"),bail:h("#bd8c4d"),"bat-grip":h("#385b5c"),"bat-blade":h("#e8c58d"),"bat-label":h("#c34d4c"),ball:{color:e==="test"?"#b32d36":"#fff9e7",shading:"toon",outline:{color:"#9b3840",width:1}}}}}}const Ut=1900,Ni=2450,Et=2900,Wi=4100,cn=4200,Os=4600,Fr=5300,uh=5500;function Nr(t,e,n,s,i,o,r=t.object.pose?.turn??0){const a=Ct(e,n,s),l=Xs(i,o),c=Is(i,o,r),h=r+(c-r)*Ft(Ct(e,n,n+200)),u={...lt,...t.object.pose,turn:h},d=Xo("run",t.who.height,1,t.object.character?.legLength??1),f=Ko("run",l*a/d,u),p=Math.min(a*12,(1-a)*12,1);return{position:gn(i,o,a),pose:Rr(u,f,Math.max(0,p))}}function dh(t,e,n){const s=(t.pose.turn??0)*Math.PI/2;return Tt(t.position,[Math.sin(s)*e,n,Math.cos(s)*e])}function cx(t,e,n,s,i){const o=`${e}/${n.object.id}`,r={...lt,...n.object.pose},a=new Set(i.flatMap(l=>Object.keys(l.pose)));for(const l of a){const c=r[l]??0;i.some(h=>h.pose[l]!==c)&&t.push({id:`${n.object.id}-${l}`,target:o,property:l,keyframes:s.map((h,u)=>({time:h,value:i[u].pose[l]??c}))})}for(const[l,c]of["x","y","z"].entries())i.some(h=>h.position[l]!==(n.object.position?.[l]??0))&&t.push({id:`${n.object.id}-${c}`,target:o,property:c,keyframes:s.map((h,u)=>({time:h,value:i[u].position[l]}))});if(i[0].bat){const l=n.object.id==="batter"?"bat":"non-striker-bat",c=`${e}/${l}`;t.push({id:`${l}-visible`,target:c,property:"visible",keyframes:[{time:0,value:1}]}),t.push({id:`${l}-position`,target:c,property:"position",keyframes:s.map((h,u)=>({time:h,value:[...i[u].bat.grip]}))}),t.push({id:`${l}-rotation`,target:c,property:"quaternion",interpolation:"slerp",keyframes:s.map((h,u)=>({time:h,value:S1(i[u].bat.axis)}))})}}function hx(t,e){const n={runs:0,extras:0,wickets:0,legalBall:!0,freeHitNext:!1};t==="running"&&(n.runs=1),t==="four"&&(n.runs=4),t==="six"&&(n.runs=6),(t==="wide"||t==="no-ball")&&(n.extras=1,n.legalBall=!1),t==="no-ball"&&(n.freeHitNext=$s[e].freeHitAfterNoBall);const i={catch:"caught",bowled:"bowled",lbw:"lbw",stumping:"stumped","run-out":"run-out"}[t];return i&&(n.wickets=1,n.dismissal=i),n}function $1(t,e={}){const n=Fe(Ps,e.action??"bowling","cricketAction.action");Fe($s,t.format,"cricketAction.format");const s=e.duration??6e3;if(!Number.isFinite(s)||s<4e3||s>6e4)throw new Error("cricketAction: duration must be between 4000 and 60000 ms");const i=t.scene.id;for(const H of["ball","bat","non-striker-bat","lbw-guide","striker-bail-0","striker-bail-1","bowler-bail-0","bowler-bail-1"])if(!t.scene.objects.some(W=>W.id===H))throw new Error(`cricketAction: required equipment '${H}' is missing`);const o=Object.fromEntries(["batter","non-striker","bowler","keeper","fielder","umpire"].map(H=>[H,M1(t.scene,H)]));for(const H of["slip","point","cover","mid-off","mid-on","square-leg","fine-leg","third-man","square-umpire"])t.scene.objects.some(W=>W.id===H&&W.kind==="character")&&(o[H]=M1(t.scene,H));const r=H=>o[H].who.height,a=H=>ix(o[H]),l=H=>Math.round(H*6e3/s*1e9)/1e9,c=H=>H*s/6e3,h=["batting","defend","running","four","six","catch","fielding","throw","run-out"].includes(n),u=["bowling","spin","no-ball","stumping"].includes(n),d=["catch","fielding","throw","run-out","batting","running"].includes(n),f=n==="running"||n==="run-out",p=new Map,g=[a("bowler").position[0],0,n==="no-ball"?-8.25:-9.55],m=n==="fielding"?[10.5,0,2]:[9,0,-1],w=a("fielder").position,v=(H,W)=>{let _=p.get(H);_||(_=new Map,p.set(H,_));const B=_.get(W);if(B)return B;const Q=o[H];let O=a(H);if(H==="bowler"){const R=O.position;if(W<1400){const z=Tt(g,[0,0,-.65]);O=Nr(Q,W,0,1400,R,z),O.pose["arm.right.swing"]=45,O.pose["arm.right.elbow"]=80}else O.position=W<=Ut?gn(Tt(g,[0,0,-.65]),g,Ft(Ct(W,1400,Ut))):Tt(g,[0,0,.8*Ft(Ct(W,Ut,2600))]),O.pose=x1(W,[[1400,{turn:0,"arm.right.swing":285,"arm.right.elbow":8,"arm.left.swing":115,"leg.right.swing":15,"leg.left.knee":45}],[1800,{turn:0,"arm.right.swing":180,"arm.right.elbow":0,"arm.left.swing":80,"leg.right.swing":25,"leg.right.knee":0,"leg.left.swing":-25,"leg.left.knee":60}],[Ut,{turn:0,lean:8,"arm.right.swing":155,"arm.right.elbow":0,"arm.left.swing":45,"leg.right.swing":25,"leg.right.knee":0,"leg.left.swing":-25,"leg.left.knee":60}],[2250,{turn:0,lean:26,bend:12,"arm.right.swing":40,"arm.right.elbow":0,"arm.left.swing":-35,"leg.left.swing":-35,"leg.left.knee":55}],[3e3,{turn:0,"head.turn":10}],[6e3,{turn:0,"head.turn":10}]]);n==="spin"&&(O.pose={...O.pose,"arm.right.spread":18,"head.tilt":-5});for(const[z,K]of Object.entries(W<Ut?St.hold:St.open))O.pose[`hand.right.${z}`]=K}else if(H==="batter"||H==="non-striker"){const R=r(H);if(n==="lbw"&&H==="batter"&&(O.position[0]=0),n==="stumping"&&H==="batter"&&(O.position[2]-=1.1*Ft(Ct(W,2150,2800))),f&&W>3050){const z=v(H,3050),K=H==="batter"?[1,0,-9.5]:[-1,0,9.5];O=Nr(Q,W,3050,n==="run-out"?6e3:uh,z.position,K,z.pose.turn);const q=Fi(Q,O,"right");O.bat={grip:q,axis:Jt([.7,-.35,.5]),scale:R/1.78}}else{O.pose={...O.pose,...H==="batter"?v1():{turn:.15,"leg.left.knee":8,"leg.right.knee":8}};let K=[0,-1,H==="batter"?.05:.12],N=Tt(O.position,[R*.15,R*.44,R*.04]);if(H==="non-striker"&&(N=Tt(O.position,[R*.08,R*.44,R*.17])),H==="batter"){const q=Ft(Ct(W,2100,2600))*(1-Ft(Ct(W,2600,Et))),Y=Ft(Ct(W,2600,Et))*(1-Ft(Ct(W,Et,3800))),J=Ft(Ct(W,Et,3250))*(1-Ft(Ct(W,3250,4e3)));if(h){N=Tt(O.position,[R*(.15+.03*q-.02*Y-.03*J),R*(.44+.14*q+.07*Y+.23*J),R*(.04+.16*q-.12*Y-.06*J)]),K=Jt([.15*q+.25*J,-1+1.85*q+1.6*J,.05+.55*q-.4*Y-.8*J]),O.pose.turn=1+.12*Y+.3*J,O.pose.lean=3+4*Y;const X=12+4*Y;O.pose["leg.left.spread"]=X,O.pose["leg.right.spread"]=X,n==="defend"&&(K=[0,-1,-.08],N=Tt(O.position,[R*.1,R*.5,-R*.12]))}else if(["stumping","bowled","lbw"].includes(n)){const X=Ft(Ct(W,2100,2700))*(1-Ft(Ct(W,4e3,4500)));K=Jt([.15*X,-1+1.85*X,.05+.55*X]),N=Tt(O.position,[R*(.15+.03*X),R*(.44+.14*X),R*(.04+.16*X)])}}O=rx(Q,O,N,K)}}else if(H==="keeper"){O.pose={...O.pose,turn:Is(O.position,a("bowler").position,2),lean:20,"leg.left.swing":22,"leg.right.swing":22,"leg.left.knee":50,"leg.right.knee":50},n==="wide"&&(O.position[0]=2.15*Ft(Ct(W,2900,3500))),n==="stumping"&&(O.position[2]-=.85*Ft(Ct(W,3400,3900)));const R=dh(O,r(H)*.27,r(H)*.44);if(n==="stumping"&&W>=3500){const z=dh({...O,position:a(H).position},r(H)*.27,r(H)*.44),K=[0,jt.stumpHeight,jt.length/2],N=gn(z,K,Ft(Ct(W,3500,3900)));O=ln(Q,O,"right",N),O=ln(Q,O,"left",Tt(N,[.045,0,0]))}else O=ln(Q,O,"right",R),O=ln(Q,O,"left",Tt(R,[.045,0,0]))}else if(H==="fielder"&&d){if(O=Nr(Q,W,3050,n==="catch"?3800:3950,w,m),W>=3800){const R={...lt,turn:Is(m,a("batter").position,O.pose.turn),lean:n==="catch"?5:42,bend:n==="catch"?0:18,"leg.left.swing":n==="catch"?0:45,"leg.right.swing":n==="catch"?0:45,"leg.left.knee":n==="catch"?0:85,"leg.right.knee":n==="catch"?0:85,smile:.7};O.pose=Rr(O.pose,R,Ft(Ct(W,3800,cn)));const z=dh(O,r(H)*.22,r(H)*(n==="catch"?.73:.2));if(O=ln(Q,O,"right",z),O=ln(Q,O,"left",Tt(z,[.035,0,0])),(n==="throw"||n==="run-out")&&W>cn){const K={...lt,turn:Is(m,n==="throw"?a("keeper").position:t.landmarks["bowler-wicket"],O.pose.turn),"arm.right.swing":225,"arm.right.elbow":60,"arm.left.spread":70,"leg.left.swing":15},N={...K,"arm.right.swing":110,"arm.right.elbow":0,lean:15};O.pose=x1(W,[[cn,O.pose],[4450,K],[Os,N],[4900,{...lt,turn:K.turn,"arm.right.swing":25,lean:22}],[6e3,{...lt,turn:K.turn}]])}}}else if(H==="umpire"){let R={...lt};const z=n==="stumping"?4150:n==="run-out"?5150:n==="bowled"||n==="lbw"?3500:n==="catch"?4350:5100;if(n==="no-ball")R={...R,"arm.right.spread":90,"arm.right.elbow":0};else if(n==="wide")R={...R,"arm.right.spread":90,"arm.left.spread":90,"arm.right.elbow":0,"arm.left.elbow":0};else if(n==="six")R={...R,"arm.right.spread":180,"arm.left.spread":180,"arm.right.elbow":0,"arm.left.elbow":0};else if(n==="four")R={...R,"arm.right.spread":90-70*(.5+Math.sin((W-5100)/180)*.5),"arm.right.elbow":12};else if(["catch","bowled","lbw","stumping","run-out"].includes(n)){R={...R,"arm.right.swing":165,"arm.right.elbow":0};for(const[K,N]of Object.entries(St.point))R[`hand.right.${K}`]=N}O.pose=Rr(O.pose,R,Ft(Ct(W,n==="no-ball"?Ut:n==="wide"?3100:z,(n==="no-ball"?Ut:n==="wide"?3100:z)+350)))}return _.set(W,O),O},k=(H,W)=>Fi(o[H],v(H,W),"right"),y=h?ax(v("batter",Et).bat):n==="lbw"?gn(Li(o.batter,v("batter",Et),"leg.right",1),Li(o.batter,v("batter",Et),"leg.right",2),.6):[u?jt.wicketWidth/2+.075+.15:0,.45,9.25],x=k("bowler",Ut),P=[n==="wide"?.85:n==="spin"?-.35:n==="lbw"?y[0]*.6:0,.075,3.9],M=k("keeper",n==="stumping"?3400:3500),T=k("fielder",Wi),S=k("fielder",cn),E=n==="run-out"?"bowler":"striker",$=n==="run-out"?5e3:n==="stumping"?3900:3200,A=[t.boundaryRadius*.8,n==="six"?2.1:.075,-t.boundaryRadius*.6],I=(H,W,_,B,Q,O=0,R=0)=>lh({target:`${i}/ball`,start:W,end:_,from:B,to:Q,arc:O,curve:R},H),C=H=>{if(H<=Ut)return k("bowler",H);if(H<=Ni)return I(H,Ut,Ni,x,P,.15,n==="spin"?.35:0);const W=n==="wide"?Tt(M,[0,0,-.6]):y;if(H<=Et)return I(H,Ni,Et,P,W,.08);if(n==="bowled"){const B=[0,.36,jt.length/2];return H<=$?I(H,Et,$,y,B):I(H,$,4100,B,[0,.075,12.5],.2)}if(n==="lbw")return[...y];if(["bowling","spin","no-ball","wide","stumping"].includes(n)){const B=n==="stumping"?3400:3500;if(u&&H<=B){const Q=[W[0],M[1],jt.length/2+.2];return H<=3200?I(H,Et,3200,W,Q,.04):I(H,3200,B,Q,M,.04)}return H<=B?I(H,Et,B,W,M,.04):k("keeper",H)}if(n==="defend")return I(H,Et,3400,y,Tt(y,[-.5,-y[1]+.075,-.7]),.12);if(n==="four"||n==="six"){if(n==="six")return H<=5e3?I(H,Et,5e3,y,A,12):I(H,5e3,5700,A,Tt(A,[2,-2.025,-1.5]));const B=[5,.075,5];return H<=3300?I(H,Et,3300,y,B,.5):I(H,3300,5e3,B,A)}if(n==="catch")return H<=Wi?I(H,Et,Wi,y,T,5):k("fielder",H);const _=[4,.075,5];if(H<=3300)return I(H,Et,3300,y,_,.8);if(H<=cn)return I(H,3300,cn,_,S);if(n==="throw"||n==="run-out"){if(H<=Os)return k("fielder",H);const B=k("fielder",Os),Q=n==="run-out"?[0,.42,-jt.length/2]:k("keeper",Fr),O=n==="run-out"?$:Fr;return H<=O?I(H,Os,O,B,Q,1.2):n==="run-out"?I(H,O,5700,Q,[0,.075,-12],.18):k("keeper",H)}return[...S]},D=[],j=(H,W,_,B,Q)=>D.push({id:H,time:c(W),kind:_,label:B,caption:Q});j("setup",0,"setup",Ps[n].name,Ps[n].summary),j("release",Ut,"release","Ball released",n==="no-ball"?"The front foot has landed beyond the popping crease. No-ball.":"The bowler releases the ball; the front foot is behind the popping crease."),j("bounce",Ni,"bounce","Pitch bounce",n==="spin"?"The curved flight is illustrative. Spin can change the ball’s path after it bounces.":"The delivery bounces on the pitch on its way to the striker."),h?j("contact",Et,"contact","Bat contact","The ball meets the blade. The bat is keyed from the same two hand grips."):n==="lbw"?j("pad-contact",Et,"contact","Pad contact","The highlighted path illustrates a ball that would hit the stumps. This is an authored LBW example."):j("miss",Et,"contact",n==="wide"?"Beyond normal reach":"The batter misses",n==="wide"?"The untouched ball is too far away for a normal stroke. The umpire calls Wide.":"The untouched delivery passes the striker."),n==="catch"&&j("catch",Wi,"collect","Catch controlled","The fielder controls the ball before it touches the ground: caught."),["fielding","throw","run-out","batting","running"].includes(n)&&j("gather",cn,"collect","Ground ball gathered","The ball has touched the ground. Gathering it is fielding, not a catch dismissal."),["bowling","spin","wide","no-ball","stumping"].includes(n)&&j("keeper",n==="stumping"?3400:3500,"collect","Keeper gathers","The keeper controls the ball behind the striker’s wicket."),(n==="throw"||n==="run-out")&&j("throw",Os,"throw","Throw released","The fielder releases the gathered ball toward the wicket."),n==="throw"&&j("return",Fr,"collect","Return received","The keeper receives and controls the return throw."),n==="stumping"&&j("wicket",$,"wicket","Stumped","Holding the ball, the keeper removes a bail. The striker is out of ground and is not attempting a run."),n==="run-out"&&j("wicket",$,"wicket","Run out","The direct throw removes a bail before the running batter makes this ground."),n==="bowled"&&j("wicket",$,"wicket","Bowled","The legal delivery hits the wicket and removes a bail."),(n==="four"||n==="six")&&j("boundary",5e3,"boundary",n==="four"?"Four runs":"Six runs",n==="four"?"The struck ball reaches the boundary after touching the ground: four.":"The struck ball clears the boundary without touching the ground: six."),n==="running"&&j("run",uh,"result","One run completed","Both batters have reached the opposite ground. One run is completed.");const V=hx(n,t.format);j("result",5700,"result","Illustrated result",n==="no-ball"?`One no-ball extra; it does not count in the over.${V.freeHitNext?" The next legitimate delivery is a free hit.":" Test cricket has no automatic free hit."}`:n==="wide"?"One wide extra; the delivery does not count in the over.":n==="lbw"?"LBW is declared for this illustrated legal delivery. A full decision also checks pitching, impact and any bat contact.":`${V.runs} bat runs · ${V.extras} extras · ${V.wickets} wicket${V.wickets===1?"":"s"}.`),D.sort((H,W)=>H.time-W.time);const et=w1(0,s,e.every,[1400,1800,Ut,2100,2150,2250,Ni,2600,2800,Et,3050,3100,3200,3250,3300,3400,3500,3800,3900,3950,4e3,Wi,cn,4350,4450,Os,4900,5e3,5100,5150,Fr,uh,5700].map(c)),G=et.map(H=>C(l(H))),F=[];for(const[H,W]of Object.entries(o)){let _=W.object.pose?.turn??0,B=_;const Q=et.map((O,R)=>{const z=l(O);let K=H==="fielder"&&d&&z>3050&&z<3250?Nr(W,z,3050,n==="catch"?3800:3950,w,m,B):v(H,z),N=G[R];const q=!["batter","non-striker","bowler","keeper"].includes(H);if(q){const J=v("bowler",Math.min(z,Ut)),X=Tt(J.position,[0,r("bowler")*.8,0]);N=z<=Ut?X:z<2100?gn(X,N,Ft(Ct(z,Ut,2100))):N}if(f&&(H==="batter"||H==="non-striker")&&z>3050&&(N=H==="batter"?[1,r(H)*.8,-10.5]:[-1,r(H)*.8,10.5]),H==="bowler"&&z<=Et&&(N=Tt(v("batter",z).position,[0,r("batter")*.65,0])),q&&(H!=="fielder"||!d||z<=3050)||H==="bowler"&&z>=3e3){const J=Is(K.position,N,_);_=H==="bowler"&&z<3500?(K.pose.turn??0)+(hh(J,K.pose.turn??0)-(K.pose.turn??0))*Ft(Ct(z,3e3,3500)):J,K={...K,pose:{...K.pose,turn:_}}}return H==="fielder"&&d&&(z===3050?B=_:z>3050&&(_=hh(K.pose.turn??0,_),K={...K,pose:{...K.pose,turn:_}})),ox(W,K,N)});cx(F,i,W,et,Q)}for(const[H,W]of["x","y","z"].entries())F.push({id:`ball-${W}`,target:`${i}/ball`,property:W,keyframes:et.map((_,B)=>({time:_,value:G[B][H]}))});if(["bowled","stumping","run-out"].includes(n))for(let H=0;H<2;H++){const W=`${E}-bail-${H}`,B=t.scene.objects.find(Q=>Q.id===W).position;F.push({id:`${W}-fall`,target:`${i}/${W}`,property:"position",keyframes:[{time:0,value:[...B]},{time:c($),value:[...B]},{time:c($+180),value:Tt(B,[H?.25:-.25,.22,E==="striker"?.22:-.22]),easing:"ease-out"},{time:c($+650),value:[B[0]+(H?.4:-.4),.035,B[2]+(E==="striker"?.45:-.45)],easing:"ease-in"}]}),F.push({id:`${W}-spin`,target:`${i}/${W}`,property:"rotateZ",keyframes:[{time:0,value:0},{time:c($),value:0},{time:c($+650),value:H?145:-145}]})}if(n==="lbw"){const H=[y[0]*.8,y[1],jt.length/2],W=se(H,y);F.push({id:"lbw-position",target:`${i}/lbw-guide`,property:"position",keyframes:[{time:0,value:[...y]}]},{id:"lbw-rotation",target:`${i}/lbw-guide`,property:"quaternion",interpolation:"slerp",keyframes:[{time:0,value:S1(W)}]},{id:"lbw-length",target:`${i}/lbw-guide`,property:"scaleY",keyframes:[{time:0,value:Xs(y,H)}]},{id:"lbw-visible",target:`${i}/lbw-guide`,property:"visible",keyframes:[{time:0,value:0},{time:c(Et)-.001,value:0},{time:c(Et),value:1}]})}return{action:n,duration:s,events:D,result:V,timeline:{id:`${i}-${n}`,formatVersion:2,name:Ps[n].name,config:{duration:s,markers:D.map(H=>({id:H.id,time:H.time,label:H.label}))},captions:{en:Object.fromEntries(D.map(H=>[H.id,H.caption]))},tracks:F}}}function ux(t={}){const e=A1(t);return{...e,...$1(e,t)}}function dx(t,e){if(!Number.isFinite(e))throw new Error("cricketEventAt: time must be finite");let n;for(const s of t){if(s.time>e)break;n=s}return n}function fx(t){const{timeline:e}=t,n=new bn;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 gx={timeline:tw,to(t,e,n){const s=new yn(n);return s.to(t,e),s},from(t,e,n){const s=new yn(n);return s.from(t,e),s},fromTo(t,e,n,s){const i=new yn(s);return i.fromTo(t,e,n),i},set(t,e,n){const s=new yn(n);return s.set(t,e),s}};function P1(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 px(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 I1(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 p=t[l(h,Math.max(0,f-s))+u],g=t[l(h,Math.min(a-1,f+s+1))+u];d+=g-p}}return o}function O1(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=I1(o,e,n,i,!0),o=I1(o,e,n,i,!1);return o}function mx(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=P1(t,r,a),c=l?.getContext("2d");if(!l||!c)return;c.imageSmoothingEnabled=!0,c.drawImage(t.canvas,0,0,r,a);const h=px(c.getImageData(0,0,r,a).data,e.threshold??.55),u=(e.radius??Math.max(s,i)*.02)/o,d=O1(h,r,a,u),f=O1(h,r,a,u*3),p=e.halo??.6,g=c.createImageData(r,a);for(let m=0;m<r*a;m++){for(let w=0;w<3;w++)g.data[m*4+w]=Math.round(Math.min(1,d[m*3+w]+f[m*3+w]*p)*255);g.data[m*4+3]=255}c.putImageData(g,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 yx(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=wx(e,s,i,o,r);a?(t.globalCompositeOperation="lighter",fh(t,c,n.color)):kx(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,bx(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 bx(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 wx(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=E0(o),a=A0(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 fh(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 kx(t,e,n){const s=typeof t.getTransform=="function"?t.getTransform():null,i=g=>s?{x:s.a*g.x+s.c*g.y+s.e,y:s.b*g.x+s.d*g.y+s.f}:g,o=s?Math.sqrt(Math.abs(s.a*s.d-s.b*s.c)):1,r=e.map(g=>({...g,corners:g.corners.map(i),...g.cap&&{cap:{...g.cap,...i(g.cap),radius:g.cap.radius*o,start:g.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 g of r){const m=g.cap?[{x:g.cap.x-g.cap.radius,y:g.cap.y-g.cap.radius},{x:g.cap.x+g.cap.radius,y:g.cap.y+g.cap.radius}]:[];for(const w of[...g.corners,...m])a=Math.min(a,w.x),l=Math.min(l,w.y),c=Math.max(c,w.x),h=Math.max(h,w.y)}if(!(c>a&&h>l))return;const u=Math.floor(a)-1,d=Math.floor(l)-1,f=s?P1(t,Math.ceil(c)+1-u,Math.ceil(h)+1-d):null,p=f?.getContext("2d");if(!f||!p){fh(t,e,n);return}p.translate(-u,-d),p.globalCompositeOperation="lighter",fh(p,r,n),t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=1,t.drawImage(f,u,d),t.restore()}const vx=oe.to,Mx=oe.from,Sx=oe.fromTo,xx=oe.set,Tx=oe.timeline,Ex=oe.ticker,Ax=oe.splitText,$x=oe.context,Px=oe.matchMedia,Ix=oe.quickTo,Ox=oe.imageSequence,_x=oe.pageTransition;A2(),b.ACTING_STYLES=Cn,b.AIRCRAFT_ACTING=Kc,b.ANIMAL_GAITS=Es,b.ANIME_CAST=dp,b.BEAT_FIELDS=wr,b.BEAT_MOMENTS=vs,b.BED_ACTING=Cm,b.BIRD_ACTING=Zm,b.BOARD_MARKS=uc,b.BOARD_THEMES=xi,b.CANVAS_PROPERTIES=Tr,b.CHAIR_ACTING=Pm,b.CHARACTER_BEAT_3D_FIELDS=tc,b.CHARACTER_CAST=pc,b.CHARACTER_GAIT_SPEEDS=Xg,b.CHART_KINDS=fc,b.CHART_SURFACE=On,b.CHART_THEMES=Ti,b.CODE_LANGUAGES=pr,b.CODE_PANEL_EDITS=cc,b.CODE_SURFACE=Si,b.CODE_THEME=tp,b.CRICKET_ACTIONS=Ps,b.CRICKET_CAMERA_ANGLES=l1,b.CRICKET_CASTS=th,b.CRICKET_FIELDING_POSITIONS=Hr,b.CRICKET_FORMATS=$s,b.CRICKET_PITCH=jt,b.CRICKET_VIEWS=sh,b.Clock=H1,b.CompatTimeline=yn,b.CustomBounce=bu,b.CustomEase=yu,b.CustomWiggle=wu,b.DANCE_STYLES=Ge,b.DEFAULT_BAKE_INTERVAL_MS=sa,b.DEFAULT_INERTIA_FRICTION=Yr,b.DEFAULT_LABELS=$u,b.DEFAULT_SPRING=ce,b.DEFAULT_TRANSITION=P2,b.DESK_ACTING=Om,b.DOOR_ACTING=Rm,b.Draggable=$a,b.EMBRACE=mr,b.EXPRESSIONS=vt,b.FACIAL_HAIR_STYLES=Tl,b.FINGERS=Yu,b.FLIPS=yi,b.FOOT_SHAPES=Ld,b.FORMAT_VERSION=Wr,b.FRAME_ASPECTS=x0,b.GAGS=en,b.GAITS=Yt,b.GAIT_CYCLE_MS=Ac,b.GLASSES_STYLES=Al,b.HAIR_COLORS=xe,b.HAIR_STILL=rs,b.HAIR_STYLES=kl,b.HAND_MEETINGS=Ai,b.HAND_REST=Ot,b.HAND_SHAPES=St,b.HAT_STYLES=Yo,b.HELD_ITEMS=Ol,b.HELP_UP=_n,b.HORSE_ACTING=s4,b.HORSE_GAITS=Q3,b.HOUSE_ACTING=Am,b.HUMAN_ACTING_RIG=wp,b.HUMAN_BUILDS=Io,b.HUMAN_CYCLES=$l,b.HUMAN_DANCES=Sn,b.HUMAN_EXPRESSIONS=ol,b.HUMAN_GAGS=Go,b.HUMAN_POSES=ye,b.HUMAN_REST=lt,b.IDENTITY_CAMERA=Ug,b.IDENTITY_SIMILARITY=ub,b.INERTIA_MAX_DURATION_MS=wh,b.InertiaTrackPlayer=o0,b.LiveTimeline=Me,b.MANGA_CAST=fp,b.MORPH_SAMPLES=ny,b.MUDRAS=xo,b.ManualClock=C1,b.MediaSync=za,b.OUTFIT_PRESETS=mc,b.Observer=G0,b.POSES=ae,b.PROP_BEAT_3D_FIELDS=ih,b.PROP_BEAT_FIELDS=_r,b.PROP_COMMON_ACTIONS=Zc,b.PROP_COMMON_CONTROLS=Ss,b.PROP_PRESETS=As,b.PROP_SURFACE=Ts,b.QUADRUPED_ACTING=Gc,b.REMOVE_STYLES=fr,b.REST_POSE=ut,b.RIDING_POSES=oh,b.SAMPLE_STEP=Qe,b.SCENERY_COLORS=p1,b.SCRIPT_ACTIONS=Pi,b.SOFT_CARTOON_CAST=Ei,b.SPRING_MAX_DURATION_MS=jr,b.SPRING_PRESETS=Yi,b.SPRING_STEP_MS=Fn,b.STICK_ACTING_RIG=bp,b.ScrollAnimator=hu,b.ScrollDriver=Js,b.ScrollMarkers=uu,b.ScrollPin=ru,b.SmoothScroll=Wa,b.SpringSampler=Hs,b.SpringTrackPlayer=i0,b.Stage=z0,b.TREE_ACTING=Tm,b.Timeline=Ht,b.TinyflyPlayer=co,b.TinyflySequencer=Lu,b.TrackPlayer=un,b.VEHICLE_ACTING=gm,b.VISEMES=Ze,b.ValueResolver=Iy,b.VisibilityDriver=ou,b.WHEELCHAIR_ACTING=Nm,b.WHITEBOARD_SURFACE=Ce,b.actCharacterTracks=Mp,b.actKeyframes=br,b.actTracks=vp,b.actionNames=Sc,b.airplane=Bm,b.anchorError=tn,b.animalStrideLength=Or,b.animatableProperties=Up,b.applyBloom=mx,b.applyCamera=gM,b.applyGroove=$d,b.applySimilarity=pa,b.aspectOf=ga,b.assertBeats=Ec,b.audioEnvelope=sb,b.backOut=Ph,b.bakeDanceTracks=Yk,b.bakeEasing=ra,b.bakeInertiaTrack=oa,b.bakeSpringTrack=ia,b.ballFlightPoint=lh,b.ballFlightTracks=sx,b.basicOutfit=Xf,b.beatAt=zk,b.beatAtTime=zs,b.beatLength=Bs,b.beatPeriod=tb,b.beatPulse=nb,b.beatTime=Zi,b.beatsBetween=zy,b.bed=_m,b.bike=Mm,b.bindChoiceHotspots=_u,b.bird=an,b.blendPose=Zn,b.bodyProfileWidth=Bd,b.boilFrame=ja,b.bounceOut=$h,b.boxMesh=_g,b.brushingPose=Nf,b.bubblePath=Mb,b.bubblePop=Sb,b.buildScene=nx,b.bus=bm,b.cameraFromValues=fM,b.cameraPoint=pM,b.cameraTracks=Ky,b.capabilities=c1,b.capabilitiesMarkdown=w4,b.car=mm,b.cart=km,b.castMember=ZM,b.cat=Km,b.chair=$m,b.changingWindows=ys,b.character=us,b.characterAt=Sv,b.characterHandPose=Qf,b.characterJoints=fe,b.characterJointsInView=wv,b.characterLookAtTracks=uM,b.characterObjects=Qv,b.characterPartsInView=ng,b.characterPoseOf=Zo,b.characterPoseTracks=xv,b.characterScript=d3,b.characterScript3D=hM,b.characterStrideLength=Kp,b.characterTarget=Mv,b.charactersFor=r0,b.chart=XM,b.checkBeats=Ii,b.checkCast=xc,b.checkCharacterBeats3D=Gg,b.checkPropBeats=r1,b.checkPropBeats3D=d1,b.checkSurfaceBeats=qp,b.checkTracks=S3,b.chicken=e1,b.circlePath=wM,b.clamp01=Ra,b.clearMorphCache=uy,b.clearPathCache=J1,b.clipErased=lc,b.closestName=qs,b.codePanel=IM,b.codeTokens=np,b.composeSimilarity=fb,b.containerProgressAt=La,b.context=$x,b.controlValue=It,b.cow=Xm,b.create=d2,b.createControls=Iu,b.createCubicBezier=Eh,b.createLive=Mu,b.createPen=ti,b.createRandom=je,b.createTrack=Ji,b.cricketAction=$1,b.cricketCameraTracks=y4,b.cricketClip=ux,b.cricketEventAt=dx,b.cricketField=A1,b.cricketPlayer=T1,b.criticalDamping=F1,b.crow=t1,b.curve=Qy,b.customBounce=y0,b.customEase=m0,b.customWiggle=b0,b.cylinderMesh=Cg,b.danceCircleAt=cg,b.danceCircleTracks=Ev,b.danceFrame=Ao,b.danceJoint=$n,b.dancePose=Fk,b.danceStance=Eo,b.danceTaps=Wk,b.danceTracks=jk,b.danceTravel=Po,b.danceTravelTrack=Cd,b.dancer=qk,b.defineAction=OS,b.defineGait=_S,b.describeTarget=Gp,b.deserializeTimeline=jn,b.deserializeTrack=h0,b.desk=Im,b.detectTempo=qy,b.dog=Ym,b.door=Hm,b.draggable=Tw,b.drawCartoonHand=wo,b.drawCharacter=eg,b.drawCharacterHead=vv,b.drawCharacterInView=kv,b.drawDustPuff=Tp,b.drawEraser=rc,b.drawHand=ac,b.drawHeldItem=_l,b.drawImpactStars=$S,b.drawPencil=Vg,b.drawProp=W3,b.drawPropEffects=k4,b.drawPropShadow=Yl,b.drawSolvedFaces=wg,b.drawSolvedPart=qv,b.drawSolvedProp=ql,b.drawSpeedLines=xp,b.drawStickFigure=Sd,b.drawStickSmear=AS,b.drawTrail=yx,b.drawnPathTarget=kM,b.dripPath=vb,b.duck=s1,b.easeIn=Sh,b.easeInCubic=Kr,b.easeInOut=Th,b.easeInOutCubic=Ls,b.easeInOutQuad=Mh,b.easeInQuad=kh,b.easeOut=xh,b.easeOutCubic=Xr,b.easeOutQuad=vh,b.editDistance=v0,b.editError=Mi,b.editLog=ms,b.elasticOut=Ah,b.ellipsePoints=po,b.ellipsoidMesh=Hg,b.embrace=nS,b.embraceSpacing=eS,b.envelopeAt=ib,b.erasable=xM,b.expandBeats=vr,b.expandParametricEasings=n0,b.extrudeMesh=Rg,b.flipPose=hg,b.flipTracks=Ov,b.flipTravel=ug,b.formatVersionFor=Dr,b.frameRect=ob,b.frameSize=rb,b.from=Mx,b.fromJSON=Ay,b.fromTo=Sx,b.gag=vc,b.gagDuration=$i,b.gaitPose=Vu,b.gaitStrideLength=ko,b.getEasingFunction=Wt,b.getInterpolator=Ds,b.getMotionPathPoint=aa,b.getPathLength=Z1,b.getPointAtProgress=Hh,b.goat=Gm,b.gridLinesFor=J0,b.hairFollow=mp,b.hairFollowTracks=mS,b.hairHangs=lf,b.hairMotionAt=gS,b.hairMotionOf=fi,b.hairlineAt=gi,b.handAt=bM,b.handGrip=Uo,b.handJoints=bo,b.handJointsAt=Gu,b.handPath=Rc,b.handPose=Nt,b.handProp=ai,b.hasKeyframes=mh,b.hashSeed=ne,b.headPoint=Ak,b.heldTime=yh,b.helicopter=Dm,b.helpUp=iS,b.helpUpSpacing=sS,b.holdingLayers=Vf,b.horse=jm,b.horseStrideLength=o4,b.house=Em,b.humanCyclePose=hv,b.humanDanceFrame=hi,b.humanDanceTracks=m5,b.humanFieldLabel=d5,b.humanGag=Lf,b.humanGaitPose=Ko,b.humanGaitStrideLength=Xo,b.humanPlan=il,b.humanPose=kt,b.imageSequence=Ox,b.inertiaDuration=Wn,b.inertiaRest=Nn,b.inertiaValueAt=Xi,b.inertiaVelocityAt=B1,b.interpolateArray=Zh,b.interpolateColor=Jh,b.interpolateMotionPath=My,b.interpolateNumber=we,b.interpolatePathString=t0,b.interpolateQuaternion=Qh,b.interpolateString=na,b.invertSimilarity=gb,b.isCubicBezierEasing=Ln,b.isHeld=Cl,b.isInertiaTrack=Ne,b.isMotionPathPoint=_1,b.isMotionPathTrack=Br,b.isParametricEasing=_s,b.isPathData=Bn,b.isSpringTrack=We,b.isTextTrack=Bi,b.isUnderdamped=L1,b.isUnresolved=Py,b.isoDepth=ma,b.isometricBoxFaces=ya,b.isometricFaces=ba,b.jointsInScene=ig,b.jointsToScene=Md,b.leafOutfit=qf,b.leafOutfitContours=Pl,b.linear=Gi,b.lipSyncKeyframes=Zl,b.lipSyncOver=lr,b.lipSyncTracks=iM,b.lit=Vl,b.live=oe,b.lookFields=ec,b.loopBeats=eb,b.loopEase=Gy,b.loopNoise=Uy,b.loosePartsOf=jc,b.lyingPose=qm,b.mapEase=Gs,b.mat4=_b,b.matchMedia=Px,b.maxStaggerDistance=qr,b.meetDandiya=Tv,b.meetHands=tS,b.meetingSpacing=QM,b.metaballContours=wb,b.metaballField=I0,b.mirrorHumanPose=Rd,b.mirrorPose=Ad,b.mixColors=Jl,b.mixHandPoses=Jn,b.mixPoses=Fl,b.morphPath=Bh,b.motorbike=Sm,b.mount=Cu,b.mountAll=Ru,b.narrationMarkers=Ny,b.narrationSceneAt=Wy,b.naturalRest=Rs,b.nearestBeat=Dy,b.nextBeat=By,b.niceCeiling=cp,b.objectPositionAt=oc,b.organicBodyContours=qd,b.organicCenterLine=ui,b.outfitPreset=pp,b.owl=i1,b.pageTransition=_x,b.panelMesh=Lg,b.parametricEasing=Oh,b.parrot=o1,b.parseAnchor=In,b.parseEdge=Ca,b.parsePath=hn,b.parseTrigger=Ha,b.partialPath=Vn,b.pathLength=Bu,b.pedallingKeys=G4,b.pedallingPose=rh,b.penroseStairs=bb,b.penroseTriangle=yb,b.persona=h3,b.phaseOf=dn,b.pieceMotion=vi,b.pigeon=n1,b.pingPong=fa,b.planNarration=Fy,b.plantDanceFoot=ag,b.play=u2,b.playSequence=$2,b.playWhenVisible=Nw,b.playheadCrossings=ca,b.pointAlong=uo,b.pointAtDistance=Ur,b.pointOnHead=mv,b.pointsToPath=T0,b.pose=Dt,b.poseTracks=Ok,b.powSimilarity=pb,b.projectIsometric=eo,b.propActions=Cr,b.propAnchors3D=hm,b.propAt=$r,b.propControls=Yc,b.propLineWidth=jl,b.propObjects=F4,b.propPartsInSpace=cm,b.propPreset=Vc,b.propRide=E4,b.propRide3D=U4,b.propScript=a1,b.propScript3D=j4,b.propShapeMesh=_i,b.propSurface=z3,b.propTarget=dm,b.propTow=P4,b.propView=rm,b.quadruped=on,b.quat=yy,b.quickPlay=fx,b.quickTo=Ix,b.rabbit=Um,b.randomBetween=ua,b.randomChoice=$y,b.randomSnapped=d0,b.reachCharacter=_e,b.reachOf=Xp,b.resolveActingStyle=bc,b.resolveCharacterPoseKeys=Nl,b.resolveFacialHair=Sf,b.resolveGait=ii,b.resolveGlasses=Tf,b.resolveHair=uf,b.resolveHat=Af,b.resolveHeadLook=Pf,b.resolveHolding=Gf,b.resolveOrganicBody=Dd,b.resolvePoseKeys=So,b.resolveSequence=p0,b.resolveStickFrame=Va,b.resolveStickPose=xd,b.resolveValue=da,b.ribbon=E0,b.ribbonHeadCap=A0,b.rideFloors=dr,b.rotateAbout=Ke,b.routineBeats=$o,b.rubberLimb=wn,b.safeAreas=ab,b.scalePoints=Tb,b.scenePreset=b1,b.scenery=y1,b.scriptActionSummaries=Tc,b.scriptTracks=Sr,b.scrollProgress=Fw,b.scrubOnScroll=zw,b.scrubPath=MM,b.seatHeight=vk,b.serializeTimeline=u0,b.serializeTrack=l0,b.set=xx,b.shade=rr,b.shapeMesh=Wg,b.shapeToPathData=Qi,b.similarity=db,b.similarityAbout=$0,b.similarityFixedPoint=P0,b.similarityMatrix=mb,b.simplifyKeyframes=s0,b.sittingPose=Xc,b.skeletonInView=Ro,b.sketchPen=fo,b.skyColors=m1,b.smoothPath=Ql,b.smoothToward=iu,b.snapAxis=V0,b.snapConfig=au,b.snapDuration=cu,b.snapProgress=lu,b.softCartoonCharacter=JM,b.solveAt=xs,b.solvePlanSpace=ts,b.solveProp=qc,b.songbird=Qm,b.soundsOf=Og,b.speechDuration=zp,b.speechLength=jg,b.spliceTracks=$4,b.splitText=Ax,b.springDuration=bh,b.springFollow=js,b.springValueAt=R1,b.squashStretch=xb,b.squirrel=Vm,b.stagePlanSpace=Ue,b.stageSpots=dM,b.staggerDistance=zr,b.staggerOffset=zi,b.staggerOffsets=qi,b.staggerSpan=Cs,b.stepsDuration=Ap,b.stepsEasing=Ih,b.stepsToKeys=Mc,b.stickFigureAt=Za,b.stickFigureJoints=me,b.stickFigureTarget=Ja,b.stickToHuman=dg,b.strideLength=nd,b.surfaceBox=Mt,b.surfaceScript=l3,b.sweepingPose=Ff,b.syncMediaElement=Au,b.talkingMouth=sd,b.taperedLine=go,b.taperedOutline=zt,b.textAt=a0,b.tf=gx,b.ticker=Ex,b.timeline=Tx,b.to=vx,b.toJSON=Ey,b.toKeyframedTrack=ky,b.toKeyframedTracks=vy,b.torusNoise=Vy,b.trackTargets=qe,b.tractor=wm,b.trailSamples=cb,b.trainCar=vm,b.tree=xm,b.triggerDistance=Kn,b.truck=ym,b.tubeMesh=Fg,b.unknownName=ft,b.unmount=T2,b.valueAt=ur,b.vec3=Eb,b.vehicle=Le,b.walkPose=ed,b.wheelchair=Fm,b.whiteboard=RM,b.withErased=SM,b.withExpression=Xe,b.wobble=Xy,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
66
+ `)}`);const o={};for(const k of[...Object.keys(Ss),...Object.keys(e.rig.controls)])o[k]=s.values?.[k]??It(e.rig,{},k);let[r,a]=s.position??[0,0],l=s.heading??0;const c=new Map,h=(k,y,x,P="linear")=>{const M=c.get(k)??[];M.push({time:y,value:x,easing:P}),c.set(k,M)},u=(k,y,x)=>h(k,y,x);h("x",0,r),h("z",0,a),h("rotateY",0,l);const d=(k,y)=>{const x=ur(l,y);if(Math.abs(x)<1)return k;const P=Math.max(K4,Math.abs(x)*Y4);return u("rotateY",k,l),l+=x,h("rotateY",k+P,l,"ease-in-out"),k+P},f=(k,y,x)=>{const P=zg([[r,a],...y.through??[y.to]]);if(P.length<2)return x;const M=d(x,ps(P[0].point,P[1].point)),T=P[P.length-1].at,S=y.for??T/(y.speed??k.speed)*1e3,E=Wt("ease-in-out"),$=Math.min(X4,S/4);for(const[V,et]of Object.entries(k.set??{}))u(V,M,o[V]),h(V,M+1,et),o[V]=et;const A=k.flies?y.height??(o.lift>.05?o.lift:2):void 0,I=A!==void 0&&A>.05;for(const[V,et]of Object.entries(k.hold??{}))u(V,M,o[V]),h(V,M+$,et,"ease-out"),I||(h(V,M+S-$,et),h(V,M+S,0,"ease-in")),o[V]=I?et:0;A!==void 0&&(u("lift",M,o.lift),h("lift",M+Math.min(S*.35,1400),A,"ease-out"),h("lift",M+S,A),o.lift=A);const C={...o};let D=l;for(let V=0;;V=Math.min(T,V+j4)){const et=M+jg(E,V/T)*S,{point:G,direction:F}=qg(P,V);D+=ur(D,ps([0,0],F)),h("x",et,G[0]),h("z",et,G[1]),h("rotateY",et,D);for(const[H,W]of Object.entries(k.perMetre??{}))h(H,et,C[H]+V*W);for(const[H,W]of Object.entries(k.perSecond??{}))h(H,et,C[H]+(et-M)/1e3*W);if(V>=T)break}for(const[V,et]of Object.entries(k.perMetre??{}))o[V]=C[V]+T*et;for(const[V,et]of Object.entries(k.perSecond??{}))o[V]=C[V]+S/1e3*et;return[r,a]=P[P.length-1].point,l=D,M+S},p=(k,y)=>{const x=Object.fromEntries(Object.entries(k).filter(([M])=>!["at","to","through","toward"].includes(M))),P=l1(t,e,[x],{start:{...o,turn:1},scale:100,style:s.style,exaggeration:s.exaggeration});for(const M of P.tracks){if(J4.includes(M.property))continue;const T=M.keyframes??[],S=o[M.property];if(!T.every(E=>E.value===S)){u(M.property,y,S);for(const E of T)E.time>0&&c.get(M.property).push({...E,time:y+E.time});o[M.property]=T[T.length-1].value}}return y+P.duration},g=[];let m=0;for(const k of n){const y=k.at??m;let x=y;const P=e.moves?.[k.do];P?x=f(P,k,y):k.do==="face"?x=d(y,typeof k.toward=="number"?k.toward:ps([r,a],k.toward)):k.do==="hold"?x=y+(k.for??1e3):x=p(k,y),g.push({do:k.do,start:y,end:x}),m=x}const w=`${s.scene}/${t}`;return{tracks:[...c].map(([k,y])=>({id:`${t}-${k}`,target:w,property:k,keyframes:Bg(y)})),duration:m,beats:g,end:{position:[r,a],heading:l,values:{...o}}}}const J4=["x","y","turn","facing","tilt"],Z4=.35,lh={seated:ye.sit,astride:{...ye.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},driving:{...ye.sit,"arm.left.swing":52,"arm.right.swing":52,"arm.left.spread":8,"arm.right.spread":8,"arm.left.elbow":38,"arm.right.elbow":38,lean:4},wheeling:{...ye.sit,"arm.left.swing":-6,"arm.right.swing":-6,"arm.left.spread":16,"arm.right.spread":16,"arm.left.elbow":28,"arm.right.elbow":28,"leg.left.knee":80,"leg.right.knee":80},cycling:{...ye.sit,lean:22,bend:10,"head.nod":-14,"arm.left.swing":58,"arm.right.swing":58,"arm.left.spread":10,"arm.right.spread":10,"arm.left.elbow":22,"arm.right.elbow":22,"leg.left.spread":6,"leg.right.spread":6}},Q4=22,b1=38;function ch(t,e=lh.cycling){const n=t*Math.PI*2,s=r=>({swing:(e["leg.left.swing"]??40)+Q4*Math.cos(n+r),knee:(e["leg.left.knee"]??70)+b1*(.5+.5*Math.cos(n+r))-b1*.5,ankle:12*Math.sin(n+r)}),i=s(0),o=s(Math.PI);return{...e,"leg.left.swing":i.swing,"leg.left.knee":i.knee,"leg.left.ankle":i.ankle,"leg.right.swing":o.swing,"leg.right.knee":o.knee,"leg.right.ankle":o.ankle}}function tx(t){const e=t.cadence??1.2,n=Math.max(2,t.samplesPerTurn??8),s=1e3/e/n,i=[];for(let o=t.start,r=0;o<t.end;o+=s,r++)i.push({time:Math.round(o),pose:ch((o-t.start)/1e3*e,t.base),...r>0?{act:!1}:{}});return i.push({time:t.end,pose:ch((t.end-t.start)/1e3*e,t.base),act:!1}),i}const w1=(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 ex(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=us({...t.character,height:1}),c={...lt,...t.pose??lh.seated},h=Ue(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 w=n.getStateAtTime(m).values.get(e)??new Map,v=(C,D)=>{const j=w.get(C);return typeof j=="number"?j:D},k={...s.values};for(const C of Object.keys(a.controls))k[C]=v(C,s.values?.[C]??It(a,{},C));for(const C of["pitch","roll","squash","lift","lean","size"])k[C]=v(C,s.values?.[C]??It(a,{},C));const y=um(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 x=v("rotateY",s.heading??0),P=w1(y,x),M=[v("x",i)+P[0],v("y",o)+P[1],v("z",r)+P[2]],T=x+u,S=w1(h,T);let E=[M[0]-S[0],M[1]-S[1],M[2]-S[2]];const $=(C,D)=>{const j=D*D*(3-2*D);return[C[0]+(E[0]-C[0])*j,E[1]*j+Z4*Math.sin(Math.PI*D),C[1]+(E[2]-C[1])*j]},A=t.mount?Math.max(1,t.mount.for??450):0,I=t.dismount?Math.max(1,t.dismount.for??450):0;if(t.mount&&m<t.start+A?E=$(t.mount.from,(m-t.start)/A):t.dismount&&m>t.end-I&&(E=$(t.dismount.to,(t.end-m)/I)),f.x.push({time:m,value:E[0]}),f.y.push({time:m,value:E[1]}),f.z.push({time:m,value:E[2]}),f.rotateY.push({time:m,value:T}),m>=t.end)break}const p=t.riderId,g=`${t.scene}/${p}`;return Object.keys(f).map(m=>({id:`${p}-${m}`,target:g,property:m,keyframes:f[m]}))}const k1={ground:"#7fb56a",hills:"#5f9a58",city:"#4b5468",cloud:"#ffffff",sun:"#ffd45c",moon:"#f3f0e0",rain:"#9fc4e8",snow:"#ffffff",wall:"#e9e1cf",floor:"#b08a5e",skirting:"#8a6a44",frame:"#f7f3ea"},Li=[[0,"#0b1530","#1b2a4a"],[4.5,"#141a3e","#2a2f5a"],[6,"#4a3f7a","#f0a070"],[7.5,"#86c2ee","#d8ecf8"],[12,"#5aaef2","#c0e2f8"],[16.5,"#69b0e6","#f5d79a"],[18.5,"#4c3f78","#f08a5a"],[20.5,"#17203f","#2d3660"],[24,"#0b1530","#1b2a4a"]],Fi=(t,e,n)=>{const s=r=>[1,3,5].map(a=>parseInt(r.slice(a,a+2),16)),[i,o]=[s(t),s(e)];return`#${i.map((r,a)=>Math.round(r+(o[a]-r)*n).toString(16).padStart(2,"0")).join("")}`},nx=t=>{const e=(t%24+24)%24;return e<5||e>20?0:e<7?(e-5)/2:e>18?(20-e)/2:1};function v1(t){const e=(t%24+24)%24;for(let n=1;n<Li.length;n++){const[s,i,o]=Li[n-1],[r,a,l]=Li[n];if(e<=r){const c=(e-s)/(r-s);return{top:Fi(i,a,c),bottom:Fi(o,l,c)}}}return{top:Li[0][1],bottom:Li[0][2]}}const sx=(t,e)=>{const n=((t-e)%24+24)%24;return n<=12?n/12:-1},ix=9,ox=55,rx=28;function M1(t){const{x:e,y:n,width:s,height:i}=t,o=t.kind??"sky",r=t.ground??n+i*.85,a={...k1,...t.colors},l=t.horizon??"hills",c=t.window!==!1,h=je(t.seed??1),u=s*i/1e5,d=Array.from({length:Math.ceil(ix*u)+2},()=>({u:h.next(),v:h.next(),size:.6+h.next()*.8,puffs:2+Math.floor(h.next()*3)})),f=Array.from({length:Math.ceil(ox*u)+4},()=>({u:h.next(),v:h.next(),speed:.8+h.next()*.5})),p=Array.from({length:Math.ceil(rx*u)+4},()=>({u:h.next(),v:h.next(),speed:.7+h.next()*.6,sway:h.next()*Math.PI*2,size:1.5+h.next()*2})),g=Array.from({length:Math.ceil(30*u)+10},()=>({u:h.next(),v:h.next()*.6,size:.6+h.next()*1.2})),m=Array.from({length:6},()=>({phase:h.next()*Math.PI*2,amp:.5+h.next()})),w=Array.from({length:24},()=>({h:.35+h.next()*.65,w:.6+h.next()*.8,windows:h.next()>.3})),v={hour:t.hour??12,clouds:t.clouds??.3,wind:t.wind??0,rain:t.rain??0,snow:t.snow??0},k=ms(),y=(E,$)=>k.keys(E)?.length?k.valueAt(E,$):v[E],x=(E,$)=>{const A=sx(E,$),I=A<0?.5:A,C=r-n;return{x:.1*s+.8*s*I,y:A<0?C+i*.2:C-Math.sin(I*Math.PI)*C*.8,up:A>=0}},P=(E,$,A,I,C)=>{const D=$("hour"),{top:j,bottom:V}=v1(D),et=E.createLinearGradient(0,I.y,0,I.ground);et.addColorStop(0,j),et.addColorStop(1,V),E.fillStyle=et,E.fillRect(I.x,I.y,I.w,I.ground-I.y);const G=nx(D);if(G<.6){E.fillStyle="#ffffff",E.globalAlpha=(.6-G)/.6*.9;for(const R of g)E.beginPath(),E.arc(I.x+R.u*I.w,I.y+R.v*(I.ground-I.y),R.size,0,Math.PI*2),E.fill();E.globalAlpha=1}const F=x(D,6),H=x(D,18),W=Math.min(I.w,I.h)*.06;if(F.up&&(E.fillStyle=a.sun,E.beginPath(),E.arc(I.x+F.x/s*I.w,I.y+F.y/i*I.h,W,0,Math.PI*2),E.fill()),H.up){const R=I.x+H.x/s*I.w,z=I.y+H.y/i*I.h;E.fillStyle=a.moon,E.beginPath(),E.arc(R,z,W*.8,0,Math.PI*2),E.fill(),E.fillStyle=j,E.beginPath(),E.arc(R-W*.35,z-W*.15,W*.7,0,Math.PI*2),E.fill()}const _=Math.max(0,Math.min(1,$("clouds"))),B=Math.max(-1,Math.min(1,$("wind"))),Q=Math.round(_*d.length);E.fillStyle=Fi("#ffffff",a.cloud==="#ffffff"?"#ffffff":a.cloud,1),E.globalAlpha=.55+.4*G;for(let R=0;R<Q;R++){const z=d[R],K=((z.u*I.w+B*A*.012*(.6+z.size*.5))%(I.w*1.4)+I.w*1.4)%(I.w*1.4)-I.w*.2,N=I.x+K,q=I.y+(.08+z.v*.42)*(I.ground-I.y),Y=Math.min(I.w,I.h)*.07*z.size;for(let J=0;J<z.puffs;J++)E.beginPath(),E.ellipse(N+(J-(z.puffs-1)/2)*Y*.9,q+J%2*Y*.25,Y*(J%2?.8:1),Y*.62,0,0,Math.PI*2),E.fill()}E.globalAlpha=1;const O=R=>Fi(Fi(R,"#0b1530",.65),R,G);if(l==="hills"){E.fillStyle=O(a.hills),E.beginPath(),E.moveTo(I.x,I.ground);const R=40;for(let z=0;z<=R;z++){const K=z/R;let N=0;m.forEach((q,Y)=>N+=Math.sin(K*Math.PI*(1.5+Y*.7)+q.phase)*q.amp),E.lineTo(I.x+K*I.w,I.ground-Math.max(0,N)*I.h*.045-I.h*.03)}E.lineTo(I.x+I.w,I.ground),E.closePath(),E.fill()}else if(l==="city"){E.fillStyle=O(a.city);let R=I.x;const z=I.w/18;for(const K of w){if(R>I.x+I.w)break;const N=z*K.w,q=I.h*.22*K.h;if(E.fillRect(R,I.ground-q,N,q),K.windows&&G<.5){E.fillStyle="#ffd66b",E.globalAlpha=.5-G;for(let Y=I.ground-q+6;Y<I.ground-8;Y+=9)for(let J=R+4;J<R+N-4;J+=8)E.fillRect(J,Y,3,4);E.globalAlpha=1,E.fillStyle=O(a.city)}R+=N+z*.15}}E.fillStyle=O(a.ground),E.fillRect(I.x,I.ground,I.w,I.y+I.h-I.ground)},M=(E,$,A,I)=>{const C=Math.max(-1,Math.min(1,$("wind"))),D=Math.max(0,Math.min(1,$("rain"))),j=Math.max(0,Math.min(1,$("snow")));if(D>0){E.strokeStyle=a.rain,E.globalAlpha=.35+.45*D,E.lineWidth=1.2,E.lineCap="round";const V=I.h*.05,et=C*.45,G=Math.round(D*f.length);E.beginPath();for(let F=0;F<G;F++){const H=f[F],W=((H.v*I.h+A*H.speed*.9)%I.h+I.h)%I.h,_=((H.u*I.w+W*et)%I.w+I.w)%I.w;E.moveTo(I.x+_,I.y+W),E.lineTo(I.x+_+et*V,I.y+W+V)}E.stroke(),E.globalAlpha=1}if(j>0){E.fillStyle=a.snow,E.globalAlpha=.85;const V=Math.round(j*p.length);for(let et=0;et<V;et++){const G=p[et],F=((G.v*I.h+A*G.speed*.08)%I.h+I.h)%I.h,H=Math.sin(A*.002+G.sway)*I.w*.02,W=((G.u*I.w+H+C*F*.3)%I.w+I.w)%I.w;E.beginPath(),E.arc(I.x+W,I.y+F,G.size,0,Math.PI*2),E.fill()}E.globalAlpha=1}},S={kind:"scenery",target:{type:"custom",x:e,y:n,width:s,height:i,props:v,about:{kind:o==="room"?"room":"sky",summary:o==="room"?"A room: a wall, a floor and a window on the sky. Its values are tracks: hour, clouds, wind, rain, snow (seen through the window).":`A sky over ${l==="flat"?"the ground":l}: the sun and moon on their arcs, stars, clouds on the wind, rain and snow. Its values are tracks: hour (0–24), clouds, wind (−1..1), rain, snow (0..1).`,props:Object.fromEntries(Object.keys(v).map(E=>[E,ax(E)]))},draw(E,$,A){const I=$.props??{},C=j=>Number(I[j]??v[j]??0);E.save();const D={x:0,y:0,w:s,h:i,ground:r-n};if(o==="sky")P(E,C,A,D),M(E,C,A,D);else if(E.fillStyle=a.wall,E.fillRect(0,0,s,D.ground),E.fillStyle=a.floor,E.fillRect(0,D.ground,s,i-D.ground),E.fillStyle=a.skirting,E.fillRect(0,D.ground-i*.012,s,i*.012),c){const j=s*.26,V=D.ground*.5,et=s*.62,G=D.ground*.14;E.fillStyle=a.frame,E.fillRect(et-6,G-6,j+12,V+12),E.save(),E.beginPath(),E.rect(et,G,j,V),E.clip(),P(E,C,A,{x:et,y:G,w:j,h:V,ground:G+V*.8}),M(E,C,A,{x:et,y:G,w:j,h:V}),E.restore(),E.strokeStyle=a.frame,E.lineWidth=4,E.beginPath(),E.moveTo(et+j/2,G),E.lineTo(et+j/2,G+V),E.moveTo(et,G+V/2),E.lineTo(et+j,G+V/2),E.stroke()}E.restore()}},ground:r,anchor(E,$=1/0){const A=y("hour",$);if(E==="sun"||E==="moon"){const I=x(A,E==="sun"?6:18);return{x:e+I.x,y:n+I.y}}if(E==="horizon")return{x:e+s/2,y:r-i*.03};if(E==="ground")return{x:e+s/2,y:r};throw new Error(`scenery: ${ft("place",E,["sun","moon","horizon","ground"])}`)},set(E,$){if(!(E in v))throw new Error(`scenery: ${ft("value",E,Object.keys(v))}`);if(typeof $.value!="number"||!Number.isFinite($.value))throw new Error("scenery.set needs `value`, a number");return k.tween(E,y(E,$.at),$.value,$,1e3),S},tracks:k.tracks};return S}function ax(t){switch(t){case"hour":return{description:"The time of day, 0–24: the sky’s colours, the sun and the moon on their arcs, stars at night",unit:"hours",min:0,max:24};case"clouds":return{description:"Cloud cover",unit:"0..1",min:0,max:1};case"wind":return{description:"The wind, blowing left (−) or right (+): clouds drift, rain slants, snow drifts",unit:"-1..1",min:-1,max:1};case"rain":return{description:"How hard it rains",unit:"0..1",min:0,max:1};default:return{description:"How hard it snows",unit:"0..1",min:0,max:1}}}function S1(t,e){const{width:n,height:s}=e,i=e.ground??s*.85,o=e.scale??s/4.5,r={x:0,y:0,width:n,height:s,ground:i},a=(l,c,h={})=>({preset:l,x:n*c,scale:o,...h});switch(t){case"park":return{scenery:{...r,hour:10.5,clouds:.35,horizon:"hills",...e.scenery},props:[a("tree",.14,{scale:o*1.1}),a("chair",.5,{turn:0}),a("tree",.86,{scale:o*.9})]};case"street":return{scenery:{...r,hour:16,clouds:.25,horizon:"city",colors:{ground:"#8a8f99"},...e.scenery},props:[a("house",.2,{scale:o*.75,turn:.1}),a("car",.5,{turn:1,scale:o*.9}),a("house",.78,{scale:o*.7,turn:.1}),a("tree",.95,{scale:o*.8})]};case"office":return{scenery:{...r,kind:"room",hour:11,clouds:.3,colors:{wall:"#dfe5ec",floor:"#9aa3ad",skirting:"#6c757d"},...e.scenery},props:[a("door",.1,{turn:.15}),a("chair",.46,{turn:0}),a("desk",.58,{turn:0})]};case"home":return{scenery:{...r,kind:"room",hour:20,clouds:.2,...e.scenery},props:[a("door",.08,{turn:.15}),a("chair",.35,{turn:.3}),a("bed",.72,{turn:.25})]};default:throw new Error(ft("scene preset",t,["park","street","office","home"]))}}function lx(t,e){const n=S1(t,e),s=M1(n.scenery),i=n.props.map(o=>fm({x:o.x,y:s.ground,prop:Zc(o.preset),scale:o.scale,values:{turn:o.turn??0,...o.values}}));return{scenery:s,props:i,ground:s.ground}}const Ct=(t,e,n)=>Math.max(0,Math.min(1,(t-e)/(n-e))),Ft=t=>t*t*(3-2*t),Tt=(t,e)=>Xs(t,e),hh=(t,e)=>fn(t,e);function uh(t,e){const n=e+((t-e+2)%4+4)%4-2;return n===0?0:n}function _s(t,e,n=0){return Math.hypot(e[0]-t[0],e[2]-t[2])<.001?n:uh(Math.atan2(e[0]-t[0],e[2]-t[2])*2/Math.PI,n)}function x1(){return{turn:1,"head.turn":90,"leg.left.spread":12,"leg.right.spread":12,"leg.left.swing":6,"leg.right.swing":6,"leg.left.knee":12,"leg.right.knee":12}}function T1(t,e){const n=t.objects.find(s=>s.id===e);if(!n||n.kind!=="character")throw new Error(`cricketAction: required character '${e}' is missing`);if(n.parent||n.rotation?.some(s=>s!==0)||n.quaternion||n.scale!==void 0)throw new Error(`cricketAction: '${e}' must use position and pose.turn, without a transformed parent, scale or object rotation`);return{object:n,who:us({...n.character,height:n.height??1.78})}}function cx(t){return{position:[...t.object.position??[0,0,0]],pose:{...lt,...t.object.pose}}}function Ni(t,e,n,s){const i=Ue(t.who.plan,e.pose,{height:t.who.height,contact:t.who.contact});return Tt(e.position,i.chains[n][s])}function Wi(t,e,n){const s=Ni(t,e,`arm.${n}`,2),i=Ni(t,e,`arm.${n}`,1);return Tt(s,hh(Jt(se(s,i)),t.who.lineWidth*.5))}function hx(t,e,n){const s={...e.pose,"head.turn":0,"head.nod":0,"head.tilt":0},i=Ue(t.who.plan,s,{height:t.who.height,contact:t.who.contact}).head,o=se(n,Tt(e.position,i.center)),r=i.axes.map(c=>$e(o,c)),a=Math.atan2(r[0],r[2])*180/Math.PI,l=Math.atan2(-r[1],Math.hypot(r[0],r[2]))*180/Math.PI;return{...e,pose:{...e.pose,"head.turn":Math.max(-90,Math.min(90,a)),"head.nod":Math.max(-25,Math.min(30,l)),"head.tilt":0}}}function ln(t,e,n,s,i="hold"){let o={...e.pose};for(let r=0;r<10;r++){const a={...e,pose:o},l=Ue(t.who.plan,o,{height:t.who.height,contact:t.who.contact}),c=ts(t.who.plan,o,t.who.height),h=se(Wi(t,a,n),Ni(t,a,`arm.${n}`,2)),u=se(se(se(s,h),e.position),l.hip),d=Qn(u,(o.roll??0)*Math.PI/180),f=Tt(c.root,Qt(d,-(o.turn??0)*Math.PI/2));o=ui(t.who.plan,o,`arm.${n}`,f,{height:t.who.height})}for(const[r,a]of Object.entries(St[i]))o[`hand.${n}.${r}`]=a;return{...e,pose:o}}function ux(t,e,n,s){const i=Jt(s),o=t.who.height/1.78;let r=ln(t,e,"left",n);return r=ln(t,r,"right",Tt(Wi(t,r,"left"),hh(i,.105*o))),{...r,bat:{grip:Wi(t,r,"left"),axis:i,scale:o}}}function dx(t){return Tt(t.grip,hh(t.axis,.51*t.scale))}function E1(t){const e=Jt(t),n=Math.max(-1,Math.min(1,e[1]));return n>.999999?[0,0,0,1]:n<-.999999?Vt([1,0,0],180):Vt(Jt(Gs([0,1,0],e)),Math.acos(n)*180/Math.PI).map(s=>s===0?0:s)}function Fr(t,e,n){const s={};for(const i of Object.keys({...t,...e})){const o=t[i]??lt[i]??0;s[i]=o+((e[i]??lt[i]??0)-o)*n}return s}function A1(t,e){if(t<=e[0][0])return{...lt,...e[0][1]};for(let n=1;n<e.length;n++)if(t<=e[n][0])return Fr({...lt,...e[n-1][1]},{...lt,...e[n][1]},Ft(Ct(t,e[n-1][0],e[n][0])));return{...lt,...e.at(-1)[1]}}const jt=Object.freeze({length:20.12,width:3.05,poppingCrease:1.22,returnCrease:1.32,stumpHeight:.711,wicketWidth:.2286});function $1(t){if(!t.id?.trim())throw new Error("cricketPlayer: id is required");Ae({batter:1,bowler:1,keeper:1,fielder:1,umpire:1},t.role,"cricketPlayer.role");const e=Ae($i,t.preset??"youngMan","cricketPlayer.preset"),n=Ae($s,t.format??"t20","cricketPlayer.format"),s=Ae({none:1,cap:1,"sun-hat":1},t.headwear??"none","cricketPlayer.headwear"),i=e==="childBoy"||e==="childGirl",o=t.height??(i?1.24:1.78);if(!Number.isFinite(o)||o<.5||o>3)throw new Error("cricketPlayer: height must be between .5 and 3 metres");Os(t.position??[0,0,0],"cricketPlayer.position");const r=t.role==="umpire"?"#f5ebd5":n==="test"?"#f5f0df":t.color??"#3577b5",a=JSON.parse(JSON.stringify({...$i[e],...t.appearance,outfit:mp("casual",{top:"shirt",shirt:r,trousers:t.role==="umpire"?"#405058":r,bottom:"trousers",trouserStyle:"plain",sleeves:"short",collar:!0,tie:null,shoes:"boots",shoeColor:"#f3ead7"}),hat:s==="none"?null:{style:s==="sun-hat"?"sunHat":"cap",color:r}}));return{id:t.id,name:t.role,kind:"character",look:"pen",height:o,position:[...t.position??[0,0,0]],character:a,pose:t.role==="batter"?x1():{turn:t.role==="keeper"?2:0}}}function Nr(t,e,n,s,i=0){return{id:t,kind:"mesh",position:e,geometry:{type:"box",size:n},material:s,layer:i}}function fx(t,e){const n=jt.stumpHeight,s=(jt.wicketWidth-.036)/2;return[...[-1,0,1].map((i,o)=>({id:`${t}-stump-${o}`,kind:"mesh",position:[i*s,n/2,e],geometry:{type:"cylinder",radius:.018,height:n,segments:10},material:"wicket"})),...[-1,1].map((i,o)=>Nr(`${t}-bail-${o}`,[i*s/2,n+.015,e],[.105,.025,.035],"bail"))]}function P1(t,e){return[{id:t,kind:"group",scale:e,visible:!1},Nr(`${t}-grip`,[0,.1,0],[.036,.28,.036],"bat-grip"),Nr(`${t}-blade`,[0,.51,0],[.108,.54,.055],"bat-blade"),Nr(`${t}-label`,[0,.41,.029],[.07,.16,.004],"bat-label")].map((s,i)=>i===0?s:{...s,parent:t})}function I1(t={}){const e=Ae($s,t.format??"t20","cricketField.format"),n=Ae(nh,t.cast??"adults","cricketField.cast"),s=Ae(Lr,t.markingProfile??"icc-men","cricketField.markingProfile"),i=Lr[s],o=t.boundaryRadius??64;if(!Number.isFinite(o)||o<24||o>250)throw new Error("cricketField: boundaryRadius must be between 24 and 250 metres");const r=t.id??"cricket";if(!r.trim())throw new Error("cricketField: id is required");const a=jt.length/2,l=e!=="test"&&i.fieldingRadius!==null?{radius:i.fieldingRadius,centres:[[0,0,-a],[0,0,a]]}:null,c={"striker-wicket":[0,0,a],"bowler-wicket":[0,0,-a],"striker-crease":[0,0,a-jt.poppingCrease],"bowler-crease":[0,0,-a+jt.poppingCrease]},h=[{id:"camera",kind:"camera",projection:"perspective",position:[25,9,6],lookAt:[0,.65,0],fov:48,near:.02,far:Math.max(600,o*4)},{id:"sun",kind:"light",light:"directional",position:[4,8,5],intensity:.8,color:"#fff2dd"},{id:"ambient",kind:"light",light:"ambient",intensity:.85,color:"#eaf6f4"},{id:"outfield",kind:"mesh",layer:-4,position:[0,-.04,0],geometry:{type:"cylinder",radius:o+1,height:.06,segments:80},material:"grass"},{id:"square",kind:"mesh",layer:-3,geometry:{type:"plane",size:[8,25]},position:[0,.003,0],material:"square"},{id:"pitch",kind:"mesh",layer:-2,geometry:{type:"plane",size:[jt.width,jt.length]},position:[0,.008,0],material:"pitch"},{id:"boundary",kind:"line",layer:-1,closed:!0,width:.15,color:"#f8f2db",points:Array.from({length:96},(p,g)=>[Math.cos(g*Math.PI/48)*o,.022,Math.sin(g*Math.PI/48)*o])}];l&&h.push({id:"fielding-circle",kind:"line",layer:-1,closed:!0,width:.06,color:"#d6e4c8",points:M4(l)});for(const p of[-1,1]){const g=p>0?"striker":"bowler",m=p*a,w=m-p*jt.poppingCrease;h.push(...fx(g,m));const v=(k,y)=>h.push({id:`${g}-${k}`,kind:"line",layer:-1,color:"#fffdf0",width:.045,points:y});v("popping-line",[[-i.poppingCreaseHalfWidth,.02,w],[i.poppingCreaseHalfWidth,.02,w]]),v("bowling-line",[[-1.32,.02,m],[1.32,.02,m]]);for(const k of[-1,1])v(`return-line-${k<0?"left":"right"}`,[[k*1.32,.02,w],[k*1.32,.02,m+p*2.5]])}const u=[["batter","batter",[-.38,0,9.3]],["non-striker","batter",[-.85,0,-9.3]],["bowler","bowler",[.68,0,-17]],["keeper","keeper",[0,0,11.25]],["fielder","fielder",[12,0,-3]],["slip","fielder",[3.5,0,12]],["point","fielder",[20,0,6]],["cover","fielder",[22,0,-16]],["mid-off","fielder",[9,0,-25]],["mid-on","fielder",[-9,0,-25]],["square-leg","fielder",[-20,0,7]],["fine-leg","fielder",[-20,0,35]],["third-man","fielder",[23,0,35]],["umpire","umpire",[0,0,-12.4]],["square-umpire","umpire",[-15,0,8.84]]];u.forEach(([p,g,m],w)=>{const v=n==="children"||n==="mixed"&&w%3===0,k=n==="men"?"youngMan":v?w%2?"childGirl":"childBoy":w%2?"youngWoman":"youngMan",y=Math.hypot(m[0],m[2]),x=y>o*.88?[m[0]*o*.88/y,0,m[2]*o*.88/y]:[...m];c[p]=[...x];const P=$1({id:p,role:g,preset:k,format:e,position:x,color:g==="batter"?t.battingColor??"#397cb9":t.fieldingColor??"#bf604e"});if(Object.hasOwn(Ps,p)&&(P.name=Ps[p]),p!=="batter"){const M=p==="non-striker"||p==="bowler"?u[0][2]:u.find(([T])=>T==="bowler")[2];P.pose={turn:_s(x,M)}}h.push(P)});const d=p=>h.find(g=>g.id===p).height/1.78;h.push(...P1("bat",d("batter")),...P1("non-striker-bat",d("non-striker"))),h.push({id:"ball",kind:"mesh",position:[0,.075,0],geometry:{type:"sphere",radius:.075,segments:12},material:"ball"}),h.push({id:"lbw-guide",kind:"group",visible:!1},{id:"lbw-projection",kind:"line",parent:"lbw-guide",points:[[0,0,0],[0,1,0]],width:.04,color:"#e9ae38"});const f=p=>({color:p,shading:"toon",outline:{color:"#69513a",width:.8}});return{format:e,boundaryRadius:o,landmarks:c,markingProfile:s,fieldingArea:l,scene:{id:r,formatVersion:1,camera:"camera",background:{top:"#c8e5ef",bottom:"#e9efcc"},ground:0,objects:h,materials:{grass:{color:"#81a95c",shading:"unlit"},square:{color:"#a6b76a",shading:"unlit",doubleSided:!0},pitch:{color:"#ddbd85",shading:"unlit",doubleSided:!0},wicket:f("#edd99e"),bail:f("#bd8c4d"),"bat-grip":f("#385b5c"),"bat-blade":f("#e8c58d"),"bat-label":f("#c34d4c"),ball:{color:e==="test"?"#b32d36":"#fff9e7",shading:"toon",outline:{color:"#9b3840",width:1}}}}}}const Ut=1900,Di=2450,Et=2900,Bi=4100,cn=4200,Cs=4600,Wr=5300,dh=5500;function Dr(t,e,n,s,i,o,r=t.object.pose?.turn??0){const a=Ct(e,n,s),l=Us(i,o),c=_s(i,o,r),h=r+(c-r)*Ft(Ct(e,n,n+200)),u={...lt,...t.object.pose,turn:h},d=Uo("run",t.who.height,1,t.object.character?.legLength??1),f=Go("run",l*a/d,u),p=Math.min(a*12,(1-a)*12,1);return{position:gn(i,o,a),pose:Fr(u,f,Math.max(0,p))}}function fh(t,e,n){const s=(t.pose.turn??0)*Math.PI/2;return Tt(t.position,[Math.sin(s)*e,n,Math.cos(s)*e])}function gx(t,e,n,s,i){const o=`${e}/${n.object.id}`,r={...lt,...n.object.pose},a=new Set(i.flatMap(l=>Object.keys(l.pose)));for(const l of a){const c=r[l]??0;i.some(h=>h.pose[l]!==c)&&t.push({id:`${n.object.id}-${l}`,target:o,property:l,keyframes:s.map((h,u)=>({time:h,value:i[u].pose[l]??c}))})}for(const[l,c]of["x","y","z"].entries())i.some(h=>h.position[l]!==(n.object.position?.[l]??0))&&t.push({id:`${n.object.id}-${c}`,target:o,property:c,keyframes:s.map((h,u)=>({time:h,value:i[u].position[l]}))});if(i[0].bat){const l=n.object.id==="batter"?"bat":"non-striker-bat",c=`${e}/${l}`;t.push({id:`${l}-visible`,target:c,property:"visible",keyframes:[{time:0,value:1}]}),t.push({id:`${l}-position`,target:c,property:"position",keyframes:s.map((h,u)=>({time:h,value:[...i[u].bat.grip]}))}),t.push({id:`${l}-rotation`,target:c,property:"quaternion",interpolation:"slerp",keyframes:s.map((h,u)=>({time:h,value:E1(i[u].bat.axis)}))})}}function px(t,e){const n={runs:0,extras:0,wickets:0,legalBall:!0,freeHitNext:!1};t==="running"&&(n.runs=1),t==="four"&&(n.runs=4),t==="six"&&(n.runs=6),(t==="wide"||t==="no-ball")&&(n.extras=1,n.legalBall=!1),t==="no-ball"&&(n.freeHitNext=$s[e].freeHitAfterNoBall);const i={catch:"caught",bowled:"bowled",lbw:"lbw",stumping:"stumped","run-out":"run-out"}[t];return i&&(n.wickets=1,n.dismissal=i),n}function O1(t,e={}){const n=Ae(Is,e.action??"bowling","cricketAction.action");Ae($s,t.format,"cricketAction.format");const s=e.duration??6e3;if(!Number.isFinite(s)||s<4e3||s>6e4)throw new Error("cricketAction: duration must be between 4000 and 60000 ms");const i=t.scene.id;for(const H of["ball","bat","non-striker-bat","lbw-guide","striker-bail-0","striker-bail-1","bowler-bail-0","bowler-bail-1"])if(!t.scene.objects.some(W=>W.id===H))throw new Error(`cricketAction: required equipment '${H}' is missing`);const o=Object.fromEntries(["batter","non-striker","bowler","keeper","fielder","umpire"].map(H=>[H,T1(t.scene,H)]));for(const H of["slip","point","cover","mid-off","mid-on","square-leg","fine-leg","third-man","square-umpire"])t.scene.objects.some(W=>W.id===H&&W.kind==="character")&&(o[H]=T1(t.scene,H));const r=H=>o[H].who.height,a=H=>cx(o[H]),l=H=>Math.round(H*6e3/s*1e9)/1e9,c=H=>H*s/6e3,h=["batting","defend","running","four","six","catch","fielding","throw","run-out"].includes(n),u=["bowling","spin","no-ball","stumping"].includes(n),d=["catch","fielding","throw","run-out","batting","running"].includes(n),f=n==="running"||n==="run-out",p=new Map,g=[a("bowler").position[0],0,n==="no-ball"?-8.25:-9.55],m=n==="fielding"?[10.5,0,2]:[9,0,-1],w=a("fielder").position,v=(H,W)=>{let _=p.get(H);_||(_=new Map,p.set(H,_));const B=_.get(W);if(B)return B;const Q=o[H];let O=a(H);if(H==="bowler"){const R=O.position;if(W<1400){const z=Tt(g,[0,0,-.65]);O=Dr(Q,W,0,1400,R,z),O.pose["arm.right.swing"]=45,O.pose["arm.right.elbow"]=80}else O.position=W<=Ut?gn(Tt(g,[0,0,-.65]),g,Ft(Ct(W,1400,Ut))):Tt(g,[0,0,.8*Ft(Ct(W,Ut,2600))]),O.pose=A1(W,[[1400,{turn:0,"arm.right.swing":285,"arm.right.elbow":8,"arm.left.swing":115,"leg.right.swing":15,"leg.left.knee":45}],[1800,{turn:0,"arm.right.swing":180,"arm.right.elbow":0,"arm.left.swing":80,"leg.right.swing":25,"leg.right.knee":0,"leg.left.swing":-25,"leg.left.knee":60}],[Ut,{turn:0,lean:8,"arm.right.swing":155,"arm.right.elbow":0,"arm.left.swing":45,"leg.right.swing":25,"leg.right.knee":0,"leg.left.swing":-25,"leg.left.knee":60}],[2250,{turn:0,lean:26,bend:12,"arm.right.swing":40,"arm.right.elbow":0,"arm.left.swing":-35,"leg.left.swing":-35,"leg.left.knee":55}],[3e3,{turn:0,"head.turn":10}],[6e3,{turn:0,"head.turn":10}]]);n==="spin"&&(O.pose={...O.pose,"arm.right.spread":18,"head.tilt":-5});for(const[z,K]of Object.entries(W<Ut?St.hold:St.open))O.pose[`hand.right.${z}`]=K}else if(H==="batter"||H==="non-striker"){const R=r(H);if(n==="lbw"&&H==="batter"&&(O.position[0]=0),n==="stumping"&&H==="batter"&&(O.position[2]-=1.1*Ft(Ct(W,2150,2800))),f&&W>3050){const z=v(H,3050),K=H==="batter"?[1,0,-9.5]:[-1,0,9.5];O=Dr(Q,W,3050,n==="run-out"?6e3:dh,z.position,K,z.pose.turn);const q=Wi(Q,O,"right");O.bat={grip:q,axis:Jt([.7,-.35,.5]),scale:R/1.78}}else{O.pose={...O.pose,...H==="batter"?x1():{turn:.15,"leg.left.knee":8,"leg.right.knee":8}};let K=[0,-1,H==="batter"?.05:.12],N=Tt(O.position,[R*.15,R*.44,R*.04]);if(H==="non-striker"&&(N=Tt(O.position,[R*.08,R*.44,R*.17])),H==="batter"){const q=Ft(Ct(W,2100,2600))*(1-Ft(Ct(W,2600,Et))),Y=Ft(Ct(W,2600,Et))*(1-Ft(Ct(W,Et,3800))),J=Ft(Ct(W,Et,3250))*(1-Ft(Ct(W,3250,4e3)));if(h){N=Tt(O.position,[R*(.15+.03*q-.02*Y-.03*J),R*(.44+.14*q+.07*Y+.23*J),R*(.04+.16*q-.12*Y-.06*J)]),K=Jt([.15*q+.25*J,-1+1.85*q+1.6*J,.05+.55*q-.4*Y-.8*J]),O.pose.turn=1+.12*Y+.3*J,O.pose.lean=3+4*Y;const X=12+4*Y;O.pose["leg.left.spread"]=X,O.pose["leg.right.spread"]=X,n==="defend"&&(K=[0,-1,-.08],N=Tt(O.position,[R*.1,R*.5,-R*.12]))}else if(["stumping","bowled","lbw"].includes(n)){const X=Ft(Ct(W,2100,2700))*(1-Ft(Ct(W,4e3,4500)));K=Jt([.15*X,-1+1.85*X,.05+.55*X]),N=Tt(O.position,[R*(.15+.03*X),R*(.44+.14*X),R*(.04+.16*X)])}}O=ux(Q,O,N,K)}}else if(H==="keeper"){O.pose={...O.pose,turn:_s(O.position,a("bowler").position,2),lean:20,"leg.left.swing":22,"leg.right.swing":22,"leg.left.knee":50,"leg.right.knee":50},n==="wide"&&(O.position[0]=2.15*Ft(Ct(W,2900,3500))),n==="stumping"&&(O.position[2]-=.85*Ft(Ct(W,3400,3900)));const R=fh(O,r(H)*.27,r(H)*.44);if(n==="stumping"&&W>=3500){const z=fh({...O,position:a(H).position},r(H)*.27,r(H)*.44),K=[0,jt.stumpHeight,jt.length/2],N=gn(z,K,Ft(Ct(W,3500,3900)));O=ln(Q,O,"right",N),O=ln(Q,O,"left",Tt(N,[.045,0,0]))}else O=ln(Q,O,"right",R),O=ln(Q,O,"left",Tt(R,[.045,0,0]))}else if(H==="fielder"&&d){if(O=Dr(Q,W,3050,n==="catch"?3800:3950,w,m),W>=3800){const R={...lt,turn:_s(m,a("batter").position,O.pose.turn),lean:n==="catch"?5:42,bend:n==="catch"?0:18,"leg.left.swing":n==="catch"?0:45,"leg.right.swing":n==="catch"?0:45,"leg.left.knee":n==="catch"?0:85,"leg.right.knee":n==="catch"?0:85,smile:.7};O.pose=Fr(O.pose,R,Ft(Ct(W,3800,cn)));const z=fh(O,r(H)*.22,r(H)*(n==="catch"?.73:.2));if(O=ln(Q,O,"right",z),O=ln(Q,O,"left",Tt(z,[.035,0,0])),(n==="throw"||n==="run-out")&&W>cn){const K={...lt,turn:_s(m,n==="throw"?a("keeper").position:t.landmarks["bowler-wicket"],O.pose.turn),"arm.right.swing":225,"arm.right.elbow":60,"arm.left.spread":70,"leg.left.swing":15},N={...K,"arm.right.swing":110,"arm.right.elbow":0,lean:15};O.pose=A1(W,[[cn,O.pose],[4450,K],[Cs,N],[4900,{...lt,turn:K.turn,"arm.right.swing":25,lean:22}],[6e3,{...lt,turn:K.turn}]])}}}else if(H==="umpire"){let R={...lt};const z=n==="stumping"?4150:n==="run-out"?5150:n==="bowled"||n==="lbw"?3500:n==="catch"?4350:5100;if(n==="no-ball")R={...R,"arm.right.spread":90,"arm.right.elbow":0};else if(n==="wide")R={...R,"arm.right.spread":90,"arm.left.spread":90,"arm.right.elbow":0,"arm.left.elbow":0};else if(n==="six")R={...R,"arm.right.spread":180,"arm.left.spread":180,"arm.right.elbow":0,"arm.left.elbow":0};else if(n==="four")R={...R,"arm.right.spread":90-70*(.5+Math.sin((W-5100)/180)*.5),"arm.right.elbow":12};else if(["catch","bowled","lbw","stumping","run-out"].includes(n)){R={...R,"arm.right.swing":165,"arm.right.elbow":0};for(const[K,N]of Object.entries(St.point))R[`hand.right.${K}`]=N}O.pose=Fr(O.pose,R,Ft(Ct(W,n==="no-ball"?Ut:n==="wide"?3100:z,(n==="no-ball"?Ut:n==="wide"?3100:z)+350)))}return _.set(W,O),O},k=(H,W)=>Wi(o[H],v(H,W),"right"),y=h?dx(v("batter",Et).bat):n==="lbw"?gn(Ni(o.batter,v("batter",Et),"leg.right",1),Ni(o.batter,v("batter",Et),"leg.right",2),.6):[u?jt.wicketWidth/2+.075+.15:0,.45,9.25],x=k("bowler",Ut),P=[n==="wide"?.85:n==="spin"?-.35:n==="lbw"?y[0]*.6:0,.075,3.9],M=k("keeper",n==="stumping"?3400:3500),T=k("fielder",Bi),S=k("fielder",cn),E=n==="run-out"?"bowler":"striker",$=n==="run-out"?5e3:n==="stumping"?3900:3200,A=[t.boundaryRadius*.8,n==="six"?2.1:.075,-t.boundaryRadius*.6],I=(H,W,_,B,Q,O=0,R=0)=>rh({target:`${i}/ball`,start:W,end:_,from:B,to:Q,arc:O,curve:R},H),C=H=>{if(H<=Ut)return k("bowler",H);if(H<=Di)return I(H,Ut,Di,x,P,.15,n==="spin"?.35:0);const W=n==="wide"?Tt(M,[0,0,-.6]):y;if(H<=Et)return I(H,Di,Et,P,W,.08);if(n==="bowled"){const B=[0,.36,jt.length/2];return H<=$?I(H,Et,$,y,B):I(H,$,4100,B,[0,.075,12.5],.2)}if(n==="lbw")return[...y];if(["bowling","spin","no-ball","wide","stumping"].includes(n)){const B=n==="stumping"?3400:3500;if(u&&H<=B){const Q=[W[0],M[1],jt.length/2+.2];return H<=3200?I(H,Et,3200,W,Q,.04):I(H,3200,B,Q,M,.04)}return H<=B?I(H,Et,B,W,M,.04):k("keeper",H)}if(n==="defend")return I(H,Et,3400,y,Tt(y,[-.5,-y[1]+.075,-.7]),.12);if(n==="four"||n==="six"){if(n==="six")return H<=5e3?I(H,Et,5e3,y,A,12):I(H,5e3,5700,A,Tt(A,[2,-2.025,-1.5]));const B=[5,.075,5];return H<=3300?I(H,Et,3300,y,B,.5):I(H,3300,5e3,B,A)}if(n==="catch")return H<=Bi?I(H,Et,Bi,y,T,5):k("fielder",H);const _=[4,.075,5];if(H<=3300)return I(H,Et,3300,y,_,.8);if(H<=cn)return I(H,3300,cn,_,S);if(n==="throw"||n==="run-out"){if(H<=Cs)return k("fielder",H);const B=k("fielder",Cs),Q=n==="run-out"?[0,.42,-jt.length/2]:k("keeper",Wr),O=n==="run-out"?$:Wr;return H<=O?I(H,Cs,O,B,Q,1.2):n==="run-out"?I(H,O,5700,Q,[0,.075,-12],.18):k("keeper",H)}return[...S]},D=[],j=(H,W,_,B,Q)=>D.push({id:H,time:c(W),kind:_,label:B,caption:Q});j("setup",0,"setup",Is[n].name,Is[n].summary),j("release",Ut,"release","Ball released",n==="no-ball"?"The front foot has landed beyond the popping crease. No-ball.":"The bowler releases the ball; the front foot is behind the popping crease."),j("bounce",Di,"bounce","Pitch bounce",n==="spin"?"The curved flight is illustrative. Spin can change the ball’s path after it bounces.":"The delivery bounces on the pitch on its way to the striker."),h?j("contact",Et,"contact","Bat contact","The ball meets the blade. The bat is keyed from the same two hand grips."):n==="lbw"?j("pad-contact",Et,"contact","Pad contact","The highlighted path illustrates a ball that would hit the stumps. This is an authored LBW example."):j("miss",Et,"contact",n==="wide"?"Beyond normal reach":"The batter misses",n==="wide"?"The untouched ball is too far away for a normal stroke. The umpire calls Wide.":"The untouched delivery passes the striker."),n==="catch"&&j("catch",Bi,"collect","Catch controlled","The fielder controls the ball before it touches the ground: caught."),["fielding","throw","run-out","batting","running"].includes(n)&&j("gather",cn,"collect","Ground ball gathered","The ball has touched the ground. Gathering it is fielding, not a catch dismissal."),["bowling","spin","wide","no-ball","stumping"].includes(n)&&j("keeper",n==="stumping"?3400:3500,"collect","Keeper gathers","The keeper controls the ball behind the striker’s wicket."),(n==="throw"||n==="run-out")&&j("throw",Cs,"throw","Throw released","The fielder releases the gathered ball toward the wicket."),n==="throw"&&j("return",Wr,"collect","Return received","The keeper receives and controls the return throw."),n==="stumping"&&j("wicket",$,"wicket","Stumped","Holding the ball, the keeper removes a bail. The striker is out of ground and is not attempting a run."),n==="run-out"&&j("wicket",$,"wicket","Run out","The direct throw removes a bail before the running batter makes this ground."),n==="bowled"&&j("wicket",$,"wicket","Bowled","The legal delivery hits the wicket and removes a bail."),(n==="four"||n==="six")&&j("boundary",5e3,"boundary",n==="four"?"Four runs":"Six runs",n==="four"?"The struck ball reaches the boundary after touching the ground: four.":"The struck ball clears the boundary without touching the ground: six."),n==="running"&&j("run",dh,"result","One run completed","Both batters have reached the opposite ground. One run is completed.");const V=px(n,t.format);j("result",5700,"result","Illustrated result",n==="no-ball"?`One no-ball extra; it does not count in the over.${V.freeHitNext?" The next legitimate delivery is a free hit.":" Test cricket has no automatic free hit."}`:n==="wide"?"One wide extra; the delivery does not count in the over.":n==="lbw"?"LBW is declared for this illustrated legal delivery. A full decision also checks pitching, impact and any bat contact.":`${V.runs} bat runs · ${V.extras} extras · ${V.wickets} wicket${V.wickets===1?"":"s"}.`),D.sort((H,W)=>H.time-W.time);const et=h1(0,s,e.every,[1400,1800,Ut,2100,2150,2250,Di,2600,2800,Et,3050,3100,3200,3250,3300,3400,3500,3800,3900,3950,4e3,Bi,cn,4350,4450,Cs,4900,5e3,5100,5150,Wr,dh,5700].map(c)),G=et.map(H=>C(l(H))),F=[];for(const[H,W]of Object.entries(o)){let _=W.object.pose?.turn??0,B=_;const Q=et.map((O,R)=>{const z=l(O);let K=H==="fielder"&&d&&z>3050&&z<3250?Dr(W,z,3050,n==="catch"?3800:3950,w,m,B):v(H,z),N=G[R];const q=!["batter","non-striker","bowler","keeper"].includes(H);if(q){const J=v("bowler",Math.min(z,Ut)),X=Tt(J.position,[0,r("bowler")*.8,0]);N=z<=Ut?X:z<2100?gn(X,N,Ft(Ct(z,Ut,2100))):N}if(f&&(H==="batter"||H==="non-striker")&&z>3050&&(N=H==="batter"?[1,r(H)*.8,-10.5]:[-1,r(H)*.8,10.5]),H==="bowler"&&z<=Et&&(N=Tt(v("batter",z).position,[0,r("batter")*.65,0])),q&&(H!=="fielder"||!d||z<=3050)||H==="bowler"&&z>=3e3){const J=_s(K.position,N,_);_=H==="bowler"&&z<3500?(K.pose.turn??0)+(uh(J,K.pose.turn??0)-(K.pose.turn??0))*Ft(Ct(z,3e3,3500)):J,K={...K,pose:{...K.pose,turn:_}}}return H==="fielder"&&d&&(z===3050?B=_:z>3050&&(_=uh(K.pose.turn??0,_),K={...K,pose:{...K.pose,turn:_}})),hx(W,K,N)});gx(F,i,W,et,Q)}for(const[H,W]of["x","y","z"].entries())F.push({id:`ball-${W}`,target:`${i}/ball`,property:W,keyframes:et.map((_,B)=>({time:_,value:G[B][H]}))});if(["bowled","stumping","run-out"].includes(n))for(let H=0;H<2;H++){const W=`${E}-bail-${H}`,B=t.scene.objects.find(Q=>Q.id===W).position;F.push({id:`${W}-fall`,target:`${i}/${W}`,property:"position",keyframes:[{time:0,value:[...B]},{time:c($),value:[...B]},{time:c($+180),value:Tt(B,[H?.25:-.25,.22,E==="striker"?.22:-.22]),easing:"ease-out"},{time:c($+650),value:[B[0]+(H?.4:-.4),.035,B[2]+(E==="striker"?.45:-.45)],easing:"ease-in"}]}),F.push({id:`${W}-spin`,target:`${i}/${W}`,property:"rotateZ",keyframes:[{time:0,value:0},{time:c($),value:0},{time:c($+650),value:H?145:-145}]})}if(n==="lbw"){const H=[y[0]*.8,y[1],jt.length/2],W=se(H,y);F.push({id:"lbw-position",target:`${i}/lbw-guide`,property:"position",keyframes:[{time:0,value:[...y]}]},{id:"lbw-rotation",target:`${i}/lbw-guide`,property:"quaternion",interpolation:"slerp",keyframes:[{time:0,value:E1(W)}]},{id:"lbw-length",target:`${i}/lbw-guide`,property:"scaleY",keyframes:[{time:0,value:Us(y,H)}]},{id:"lbw-visible",target:`${i}/lbw-guide`,property:"visible",keyframes:[{time:0,value:0},{time:c(Et)-.001,value:0},{time:c(Et),value:1}]})}return{action:n,duration:s,events:D,result:V,timeline:{id:`${i}-${n}`,formatVersion:2,name:Is[n].name,config:{duration:s,markers:D.map(H=>({id:H.id,time:H.time,label:H.label}))},captions:{en:Object.fromEntries(D.map(H=>[H.id,H.caption]))},tracks:F}}}function mx(t={}){const e=I1(t);return{...e,...O1(e,t)}}function yx(t,e){if(!Number.isFinite(e))throw new Error("cricketEventAt: time must be finite");let n;for(const s of t){if(s.time>e)break;n=s}return n}function bx(t){const{timeline:e}=t,n=new bn;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 wx={timeline:sw,to(t,e,n){const s=new yn(n);return s.to(t,e),s},from(t,e,n){const s=new yn(n);return s.from(t,e),s},fromTo(t,e,n,s){const i=new yn(s);return i.fromTo(t,e,n),i},set(t,e,n){const s=new yn(n);return s.set(t,e),s}};function _1(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 kx(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 C1(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 p=t[l(h,Math.max(0,f-s))+u],g=t[l(h,Math.min(a-1,f+s+1))+u];d+=g-p}}return o}function H1(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=C1(o,e,n,i,!0),o=C1(o,e,n,i,!1);return o}function vx(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=_1(t,r,a),c=l?.getContext("2d");if(!l||!c)return;c.imageSmoothingEnabled=!0,c.drawImage(t.canvas,0,0,r,a);const h=kx(c.getImageData(0,0,r,a).data,e.threshold??.55),u=(e.radius??Math.max(s,i)*.02)/o,d=H1(h,r,a,u),f=H1(h,r,a,u*3),p=e.halo??.6,g=c.createImageData(r,a);for(let m=0;m<r*a;m++){for(let w=0;w<3;w++)g.data[m*4+w]=Math.round(Math.min(1,d[m*3+w]+f[m*3+w]*p)*255);g.data[m*4+3]=255}c.putImageData(g,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 Mx(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=xx(e,s,i,o,r);a?(t.globalCompositeOperation="lighter",gh(t,c,n.color)):Tx(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,Sx(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 Sx(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 xx(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=A0(o),a=$0(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 gh(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 Tx(t,e,n){const s=typeof t.getTransform=="function"?t.getTransform():null,i=g=>s?{x:s.a*g.x+s.c*g.y+s.e,y:s.b*g.x+s.d*g.y+s.f}:g,o=s?Math.sqrt(Math.abs(s.a*s.d-s.b*s.c)):1,r=e.map(g=>({...g,corners:g.corners.map(i),...g.cap&&{cap:{...g.cap,...i(g.cap),radius:g.cap.radius*o,start:g.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 g of r){const m=g.cap?[{x:g.cap.x-g.cap.radius,y:g.cap.y-g.cap.radius},{x:g.cap.x+g.cap.radius,y:g.cap.y+g.cap.radius}]:[];for(const w of[...g.corners,...m])a=Math.min(a,w.x),l=Math.min(l,w.y),c=Math.max(c,w.x),h=Math.max(h,w.y)}if(!(c>a&&h>l))return;const u=Math.floor(a)-1,d=Math.floor(l)-1,f=s?_1(t,Math.ceil(c)+1-u,Math.ceil(h)+1-d):null,p=f?.getContext("2d");if(!f||!p){gh(t,e,n);return}p.translate(-u,-d),p.globalCompositeOperation="lighter",gh(p,r,n),t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=1,t.drawImage(f,u,d),t.restore()}const Ex=oe.to,Ax=oe.from,$x=oe.fromTo,Px=oe.set,Ix=oe.timeline,Ox=oe.ticker,_x=oe.splitText,Cx=oe.context,Hx=oe.matchMedia,Rx=oe.quickTo,Lx=oe.imageSequence,Fx=oe.pageTransition;I2(),b.ACTING_STYLES=Cn,b.AIRCRAFT_ACTING=Gc,b.ANIMAL_GAITS=Es,b.ANIME_CAST=fp,b.BEAT_FIELDS=vr,b.BEAT_MOMENTS=vs,b.BED_ACTING=Hm,b.BIRD_ACTING=Qm,b.BOARD_MARKS=fc,b.BOARD_THEMES=Ei,b.CANVAS_PROPERTIES=Ar,b.CHAIR_ACTING=Im,b.CHARACTER_BEAT_3D_FIELDS=nc,b.CHARACTER_CAST=yc,b.CHARACTER_GAIT_SPEEDS=Gg,b.CHART_KINDS=pc,b.CHART_SURFACE=On,b.CHART_THEMES=Ai,b.CODE_LANGUAGES=yr,b.CODE_PANEL_EDITS=uc,b.CODE_SURFACE=Ti,b.CODE_THEME=ep,b.CRICKET_ACTIONS=Is,b.CRICKET_CAMERA_ANGLES=c1,b.CRICKET_CASTS=nh,b.CRICKET_FIELDING_POSITIONS=Ps,b.CRICKET_FORMATS=$s,b.CRICKET_MARKING_PROFILES=Lr,b.CRICKET_PITCH=jt,b.CRICKET_VIEWS=oh,b.Clock=F1,b.CompatTimeline=yn,b.CustomBounce=wu,b.CustomEase=bu,b.CustomWiggle=ku,b.DANCE_STYLES=Ge,b.DEFAULT_BAKE_INTERVAL_MS=oa,b.DEFAULT_INERTIA_FRICTION=Xr,b.DEFAULT_LABELS=Pu,b.DEFAULT_SPRING=ce,b.DEFAULT_TRANSITION=_2,b.DESK_ACTING=_m,b.DOOR_ACTING=Lm,b.Draggable=Ia,b.EMBRACE=br,b.EXPRESSIONS=vt,b.FACIAL_HAIR_STYLES=Al,b.FINGERS=Ku,b.FLIPS=wi,b.FOOT_SHAPES=Fd,b.FORMAT_VERSION=Br,b.FRAME_ASPECTS=T0,b.GAGS=en,b.GAITS=Yt,b.GAIT_CYCLE_MS=Pc,b.GLASSES_STYLES=Pl,b.HAIR_COLORS=xe,b.HAIR_STILL=rs,b.HAIR_STYLES=Ml,b.HAND_MEETINGS=Pi,b.HAND_REST=Ot,b.HAND_SHAPES=St,b.HAT_STYLES=Xo,b.HELD_ITEMS=Cl,b.HELP_UP=_n,b.HORSE_ACTING=r4,b.HORSE_GAITS=n4,b.HOUSE_ACTING=$m,b.HUMAN_ACTING_RIG=kp,b.HUMAN_BUILDS=_o,b.HUMAN_CYCLES=Il,b.HUMAN_DANCES=Sn,b.HUMAN_EXPRESSIONS=al,b.HUMAN_GAGS=Vo,b.HUMAN_POSES=ye,b.HUMAN_REST=lt,b.IDENTITY_CAMERA=Vg,b.IDENTITY_SIMILARITY=gb,b.INERTIA_MAX_DURATION_MS=kh,b.InertiaTrackPlayer=r0,b.LiveTimeline=Me,b.MANGA_CAST=gp,b.MORPH_SAMPLES=oy,b.MUDRAS=Eo,b.ManualClock=L1,b.MediaSync=ja,b.OUTFIT_PRESETS=bc,b.Observer=U0,b.POSES=ae,b.PROP_BEAT_3D_FIELDS=ah,b.PROP_BEAT_FIELDS=Hr,b.PROP_COMMON_ACTIONS=th,b.PROP_COMMON_CONTROLS=Ss,b.PROP_PRESETS=As,b.PROP_SURFACE=Ts,b.QUADRUPED_ACTING=Vc,b.REMOVE_STYLES=pr,b.REST_POSE=ut,b.RIDING_POSES=lh,b.SAMPLE_STEP=Qe,b.SCENERY_COLORS=k1,b.SCRIPT_ACTIONS=Oi,b.SOFT_CARTOON_CAST=$i,b.SPRING_MAX_DURATION_MS=Kr,b.SPRING_PRESETS=Xi,b.SPRING_STEP_MS=Fn,b.STICK_ACTING_RIG=wp,b.ScrollAnimator=uu,b.ScrollDriver=Qs,b.ScrollMarkers=du,b.ScrollPin=au,b.SmoothScroll=Ba,b.SpringSampler=Ls,b.SpringTrackPlayer=o0,b.Stage=q0,b.TREE_ACTING=Em,b.Timeline=Ht,b.TinyflyPlayer=uo,b.TinyflySequencer=Fu,b.TrackPlayer=un,b.VEHICLE_ACTING=pm,b.VISEMES=Ze,b.ValueResolver=Cy,b.VisibilityDriver=ru,b.WHEELCHAIR_ACTING=Wm,b.WHITEBOARD_SURFACE=He,b.actCharacterTracks=Sp,b.actKeyframes=kr,b.actTracks=Mp,b.actionNames=Tc,b.airplane=zm,b.anchorError=tn,b.animalStrideLength=Cr,b.animatableProperties=Vp,b.applyBloom=vx,b.applyCamera=yM,b.applyGroove=Pd,b.applySimilarity=ya,b.aspectOf=ma,b.assertBeats=$c,b.audioEnvelope=rb,b.backOut=Ih,b.bakeDanceTracks=Gk,b.bakeEasing=la,b.bakeInertiaTrack=aa,b.bakeSpringTrack=ra,b.ballFlightPoint=rh,b.ballFlightTracks=v4,b.basicOutfit=Gf,b.beatAt=Yk,b.beatAtTime=js,b.beatLength=qs,b.beatPeriod=sb,b.beatPulse=ob,b.beatTime=to,b.beatsBetween=Yy,b.bed=Cm,b.bike=Sm,b.bindChoiceHotspots=Cu,b.bird=an,b.blendPose=Zn,b.bodyProfileWidth=zd,b.boilFrame=Ka,b.bounceOut=Ph,b.boxMesh=Cg,b.brushingPose=Wf,b.bubblePath=Tb,b.bubblePop=Eb,b.buildScene=lx,b.bus=wm,b.cameraFromValues=mM,b.cameraPoint=bM,b.cameraTracks=Uy,b.capabilities=g1,b.capabilitiesMarkdown=T4,b.car=ym,b.cart=vm,b.castMember=eS,b.cat=Xm,b.chair=Pm,b.changingWindows=ys,b.character=us,b.characterAt=Ev,b.characterHandPose=tg,b.characterJoints=fe,b.characterJointsInView=Mv,b.characterLookAtTracks=gM,b.characterObjects=nM,b.characterPartsInView=sg,b.characterPoseOf=tr,b.characterPoseTracks=Av,b.characterScript=p3,b.characterScript3D=fM,b.characterStrideLength=Xp,b.characterTarget=Tv,b.charactersFor=a0,b.chart=VM,b.checkBeats=_i,b.checkCast=Ec,b.checkCharacterBeats3D=Ug,b.checkPropBeats=a1,b.checkPropBeats3D=y1,b.checkSurfaceBeats=jp,b.checkTracks=E3,b.chicken=n1,b.circlePath=MM,b.clamp01=Fa,b.clearMorphCache=gy,b.clearPathCache=ty,b.clipErased=hc,b.closestName=Ys,b.codePanel=CM,b.codeTokens=sp,b.composeSimilarity=mb,b.containerProgressAt=Na,b.context=Cx,b.controlValue=It,b.cow=Gm,b.create=p2,b.createControls=Ou,b.createCubicBezier=Ah,b.createLive=Su,b.createPen=ni,b.createRandom=je,b.createTrack=Qi,b.cricketAction=O1,b.cricketCameraTracks=k4,b.cricketClip=mx,b.cricketEventAt=yx,b.cricketField=I1,b.cricketFieldingAreaContains=d1,b.cricketFieldingOverlay=S4,b.cricketFieldingPositions=f1,b.cricketPlayer=$1,b.criticalDamping=D1,b.crow=e1,b.curve=nb,b.customBounce=b0,b.customEase=y0,b.customWiggle=w0,b.cylinderMesh=Hg,b.danceCircleAt=hg,b.danceCircleTracks=Pv,b.danceFrame=Po,b.danceJoint=$n,b.dancePose=Dk,b.danceStance=$o,b.danceTaps=zk,b.danceTracks=Xk,b.danceTravel=Oo,b.danceTravelTrack=Hd,b.dancer=Kk,b.defineAction=HS,b.defineGait=RS,b.describeTarget=Up,b.deserializeTimeline=jn,b.deserializeTrack=u0,b.desk=Om,b.detectTempo=Ky,b.dog=Km,b.door=Rm,b.draggable=$w,b.drawCartoonHand=vo,b.drawCharacter=ng,b.drawCharacterHead=xv,b.drawCharacterInView=Sv,b.drawDustPuff=Ep,b.drawEraser=lc,b.drawHand=cc,b.drawHeldItem=Hl,b.drawImpactStars=OS,b.drawPencil=Jg,b.drawProp=z3,b.drawPropEffects=E4,b.drawPropShadow=Xl,b.drawSolvedFaces=kg,b.drawSolvedPart=Kv,b.drawSolvedProp=Yl,b.drawSpeedLines=Tp,b.drawStickFigure=xd,b.drawStickSmear=IS,b.drawTrail=Mx,b.drawnPathTarget=SM,b.dripPath=xb,b.duck=i1,b.easeIn=xh,b.easeInCubic=Gr,b.easeInOut=Eh,b.easeInOutCubic=Ns,b.easeInOutQuad=Sh,b.easeInQuad=vh,b.easeOut=Th,b.easeOutCubic=Ur,b.easeOutQuad=Mh,b.editDistance=M0,b.editError=xi,b.editLog=ms,b.elasticOut=$h,b.ellipsePoints=yo,b.ellipsoidMesh=Rg,b.embrace=oS,b.embraceSpacing=iS,b.envelopeAt=ab,b.erasable=AM,b.expandBeats=Sr,b.expandParametricEasings=s0,b.extrudeMesh=Lg,b.flipPose=ug,b.flipTracks=Hv,b.flipTravel=dg,b.formatVersionFor=zr,b.frameRect=lb,b.frameSize=cb,b.from=Ax,b.fromJSON=Iy,b.fromTo=$x,b.gag=Sc,b.gagDuration=Ii,b.gaitPose=Ju,b.gaitStrideLength=Mo,b.getEasingFunction=Wt,b.getInterpolator=zs,b.getMotionPathPoint=ca,b.getPathLength=ey,b.getPointAtProgress=Rh,b.goat=Um,b.gridLinesFor=Z0,b.hairFollow=yp,b.hairFollowTracks=wS,b.hairHangs=cf,b.hairMotionAt=yS,b.hairMotionOf=pi,b.hairlineAt=mi,b.handAt=vM,b.handGrip=Jo,b.handJoints=ko,b.handJointsAt=Uu,b.handPath=Fc,b.handPose=Nt,b.handProp=ci,b.hasKeyframes=yh,b.hashSeed=ne,b.headPoint=Ik,b.heldTime=bh,b.helicopter=Bm,b.helpUp=aS,b.helpUpSpacing=rS,b.holdingLayers=Jf,b.horse=Ym,b.horseStrideLength=l4,b.house=Am,b.humanCyclePose=fv,b.humanDanceFrame=di,b.humanDanceTracks=w5,b.humanFieldLabel=p5,b.humanGag=Ff,b.humanGaitPose=Go,b.humanGaitStrideLength=Uo,b.humanPlan=rl,b.humanPose=kt,b.imageSequence=Lx,b.inertiaDuration=Wn,b.inertiaRest=Nn,b.inertiaValueAt=Ui,b.inertiaVelocityAt=j1,b.interpolateArray=Qh,b.interpolateColor=Zh,b.interpolateMotionPath=Ty,b.interpolateNumber=we,b.interpolatePathString=e0,b.interpolateQuaternion=t0,b.interpolateString=ia,b.invertSimilarity=yb,b.isCubicBezierEasing=Ln,b.isHeld=Rl,b.isInertiaTrack=Ne,b.isMotionPathPoint=R1,b.isMotionPathTrack=qr,b.isParametricEasing=Hs,b.isPathData=Bn,b.isSpringTrack=We,b.isTextTrack=qi,b.isUnderdamped=W1,b.isUnresolved=_y,b.isoDepth=ba,b.isometricBoxFaces=wa,b.isometricFaces=ka,b.jointsInScene=og,b.jointsToScene=Sd,b.leafOutfit=jf,b.leafOutfitContours=Ol,b.linear=Vi,b.lipSyncKeyframes=tc,b.lipSyncOver=hr,b.lipSyncTracks=aM,b.lit=Zl,b.live=oe,b.lookFields=sc,b.loopBeats=ib,b.loopEase=Jy,b.loopNoise=Zy,b.loosePartsOf=Kc,b.lyingPose=jm,b.mapEase=Vs,b.mat4=Rb,b.matchMedia=Hx,b.maxStaggerDistance=Yr,b.meetDandiya=$v,b.meetHands=sS,b.meetingSpacing=nS,b.metaballContours=Mb,b.metaballField=O0,b.mirrorHumanPose=Ld,b.mirrorPose=$d,b.mixColors=Ql,b.mixHandPoses=Jn,b.mixPoses=Wl,b.morphPath=zh,b.motorbike=xm,b.mount=Hu,b.mountAll=Lu,b.narrationMarkers=By,b.narrationSceneAt=zy,b.naturalRest=Fs,b.nearestBeat=qy,b.nextBeat=jy,b.niceCeiling=hp,b.objectPositionAt=ac,b.organicBodyContours=jd,b.organicCenterLine=fi,b.outfitPreset=mp,b.owl=o1,b.pageTransition=Fx,b.panelMesh=Fg,b.parametricEasing=_h,b.parrot=r1,b.parseAnchor=In,b.parseEdge=Ra,b.parsePath=hn,b.parseTrigger=La,b.partialPath=Vn,b.pathLength=zu,b.pedallingKeys=tx,b.pedallingPose=ch,b.penroseStairs=vb,b.penroseTriangle=kb,b.persona=f3,b.phaseOf=dn,b.pieceMotion=Si,b.pigeon=s1,b.pingPong=pa,b.planNarration=Dy,b.plantDanceFoot=lg,b.play=g2,b.playSequence=O2,b.playWhenVisible=Bw,b.playheadCrossings=ua,b.pointAlong=go,b.pointAtDistance=Jr,b.pointOnHead=wv,b.pointsToPath=E0,b.pose=Dt,b.poseTracks=Hk,b.powSimilarity=bb,b.projectIsometric=so,b.propActions=Rr,b.propAnchors3D=um,b.propAt=Ir,b.propControls=Xc,b.propLineWidth=Kl,b.propObjects=q4,b.propPartsInSpace=hm,b.propPreset=Zc,b.propRide=_4,b.propRide3D=ex,b.propScript=l1,b.propScript3D=V4,b.propShapeMesh=Hi,b.propSurface=Y3,b.propTarget=fm,b.propTow=R4,b.propView=am,b.quadruped=on,b.quat=ky,b.quickPlay=bx,b.quickTo=Rx,b.rabbit=Vm,b.randomBetween=fa,b.randomChoice=Oy,b.randomSnapped=f0,b.reachCharacter=Ce,b.reachOf=Gp,b.resolveActingStyle=kc,b.resolveCharacterPoseKeys=Dl,b.resolveFacialHair=xf,b.resolveGait=ri,b.resolveGlasses=Ef,b.resolveHair=df,b.resolveHat=$f,b.resolveHeadLook=If,b.resolveHolding=Uf,b.resolveOrganicBody=Bd,b.resolvePoseKeys=To,b.resolveSequence=m0,b.resolveStickFrame=Za,b.resolveStickPose=Td,b.resolveValue=ga,b.ribbon=A0,b.ribbonHeadCap=$0,b.rideFloors=gr,b.rotateAbout=Ke,b.routineBeats=Io,b.rubberLimb=wn,b.safeAreas=hb,b.scalePoints=$b,b.scenePreset=S1,b.scenery=M1,b.scriptActionSummaries=Ac,b.scriptTracks=Tr,b.scrollProgress=Dw,b.scrubOnScroll=Yw,b.scrubPath=TM,b.seatHeight=xk,b.serializeTimeline=d0,b.serializeTrack=c0,b.set=Px,b.shade=lr,b.shapeMesh=Dg,b.shapeToPathData=eo,b.similarity=pb,b.similarityAbout=P0,b.similarityFixedPoint=I0,b.similarityMatrix=wb,b.simplifyKeyframes=i0,b.sittingPose=Uc,b.skeletonInView=Fo,b.sketchPen=po,b.skyColors=v1,b.smoothPath=ec,b.smoothToward=ou,b.snapAxis=J0,b.snapConfig=lu,b.snapDuration=hu,b.snapProgress=cu,b.softCartoonCharacter=tS,b.solveAt=xs,b.solvePlanSpace=ts,b.solveProp=Yc,b.songbird=t1,b.soundsOf=_g,b.speechDuration=qp,b.speechLength=Yg,b.spliceTracks=H4,b.splitText=_x,b.springDuration=wh,b.springFollow=Ks,b.springValueAt=N1,b.squashStretch=Ab,b.squirrel=Jm,b.stagePlanSpace=Ue,b.stageSpots=pM,b.staggerDistance=jr,b.staggerOffset=ji,b.staggerOffsets=Yi,b.staggerSpan=Rs,b.stepsDuration=$p,b.stepsEasing=Oh,b.stepsToKeys=xc,b.stickFigureAt=tl,b.stickFigureJoints=me,b.stickFigureTarget=Qa,b.stickToHuman=fg,b.strideLength=sd,b.surfaceBox=Mt,b.surfaceScript=u3,b.sweepingPose=Nf,b.syncMediaElement=$u,b.talkingMouth=id,b.taperedLine=mo,b.taperedOutline=zt,b.textAt=l0,b.tf=wx,b.ticker=Ox,b.timeline=Ix,b.to=Ex,b.toJSON=Py,b.toKeyframedTrack=Sy,b.toKeyframedTracks=xy,b.torusNoise=Qy,b.trackTargets=qe,b.tractor=km,b.trailSamples=db,b.trainCar=Mm,b.tree=Tm,b.triggerDistance=Kn,b.truck=bm,b.tubeMesh=Ng,b.unknownName=ft,b.unmount=$2,b.valueAt=fr,b.vec3=Pb,b.vehicle=Fe,b.walkPose=nd,b.wheelchair=Nm,b.whiteboard=NM,b.withErased=EM,b.withExpression=Xe,b.wobble=Vy,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));