@algorisys/tinyfly 0.125.0 → 0.126.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/docs/editor-guide.md +1 -1
- package/docs/examples.md +1 -1
- package/docs/getting-started.md +1 -1
- package/docs/gsap-compat.md +1 -1
- package/docs/llm-guide.md +4 -0
- package/docs/maps.md +2 -2
- package/docs/math.md +1 -1
- package/docs/props.md +5 -1
- package/docs/teaching.md +1 -1
- package/lib/addons/characters.js +798 -796
- package/lib/browser/tinyfly.iife.js +14 -14
- package/lib/browser/tinyfly.js +652 -650
- package/lib/browser/tinyfly.umd.js +14 -14
- package/lib/types/characters/props/families/environment.d.ts +7 -1
- package/llms-full.txt +19 -11
- package/llms.txt +32 -32
- package/package.json +1 -1
- package/skills/tinyfly/SKILL.md +3 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
(function(y,Qn){typeof exports=="object"&&typeof module<"u"?Qn(exports):typeof define=="function"&&define.amd?define(["exports"],Qn):(y=typeof globalThis<"u"?globalThis:y||self,Qn(y.tinyfly=y.tinyfly||{}))})(this,(function(y){"use strict";function Qn(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function Vs(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const xa=2;function Pa(t){return t.some(e=>e.interpolation!==void 0)?2:1}function mr(t){return t.property==="text"&&"textConfig"in t}function Ve(t){return t.kind==="inertia"&&"inertia"in t}function Je(t){return t.kind==="spring"&&"spring"in t}function $a(t){return t.property==="motionPath"&&"motionPathConfig"in t}function Db(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"angle"in t}function O0(t){return"keyframes"in t}class Bb{_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 zb{_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 C0(t,e){if(!(e>0))return t;const n=1e3/e;return Math.floor(t/n+1e-9)*n}function Ia(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 Oa(t,e="start"){if(t<=1)return 0;let n=0;for(let s=0;s<t;s++)n=Math.max(n,Ia(s,t,e));return n}function pr(t,e,n){if(n.offsets)return n.offsets[t]??0;const s=n.from??"start",i=Ia(t,e,s);if(n.amount!==void 0){const r=Oa(e,s);return r===0?0:n.amount*i/r}return n.each!==void 0?n.each*i:0}function yr(t,e){return Array.from({length:t},(n,s)=>pr(s,t,e))}function Js(t,e){return t<=1?0:Math.max(...yr(t,e))}const ts=1,Ca=6e4,br=Ca/ts,ge={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1},wr={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 Zs{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??ge.stiffness,this.damping=e.damping??ge.damping,this.mass=e.mass??ge.mass,this.restDelta=e.restDelta??ge.restDelta,this.restSpeed=e.restSpeed??ge.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=e.velocity??ge.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/ts);if(this.simulateTo(n+1),this.settledStep!==null&&n>=this.settledStep)return this.to;const s=this.samples[Math.min(n,this.samples.length-1)],i=this.samples[Math.min(n+1,this.samples.length-1)],r=e/ts-n;return s+(i-s)*r}settleTime(){return this.simulateTo(br+1),this.settledStep!==null?this.settledStep*ts:Ca}simulateTo(e){if(this.settledStep!==null)return;const n=Math.min(e,br+1),s=ts/1e3;for(;this.samples.length<n;){const i=this.samples[this.samples.length-1],r=i-this.to,o=-this.stiffness*r,a=-this.damping*this.velocity,l=(o+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>br&&(this.settledStep=br)}}function qb(t,e){return new Zs(t).valueAt(e)}function _0(t){return new Zs(t).settleTime()}function jb(t){const e=t.stiffness??ge.stiffness,n=t.damping??ge.damping,s=t.mass??ge.mass;return n<2*Math.sqrt(e*s)}function Kb(t){const e=t.stiffness??ge.stiffness,n=t.mass??ge.mass;return 2*Math.sqrt(e*n)}const _a=4,Yb=.002,Xb=1e-4,R0=6e4;function kr(t){const e=t.friction??_a;return e>0?e:_a}function Qs(t){return t.from+t.velocity/kr(t)}function Gb(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 es(t){let e=Gb(Qs(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 ns(t){const e=Math.abs(es(t)-t.from);if(e===0)return 0;const n=t.restDelta??Math.max(Xb,e*Yb);if(n>=e)return 0;const s=Math.log(e/n)/kr(t);return Math.min(R0,s*1e3)}function vr(t,e){if(e<=0)return t.from;const n=es(t);if(e>=ns(t))return n;const s=kr(t);return t.from+(n-t.from)*(1-Math.exp(-s*e/1e3))}function Ub(t,e){const n=kr(t),s=es(t);return e>=ns(t)?0:(s-t.from)*n*Math.exp(-n*Math.max(0,e)/1e3)}const Mr=t=>t,H0=t=>t*t,F0=t=>1-(1-t)*(1-t),L0=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,Ra=t=>t*t*t,Ha=t=>1-Math.pow(1-t,3),ti=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,N0=Ra,W0=Ha,D0=ti,Vb={linear:Mr,"ease-in":N0,"ease-out":W0,"ease-in-out":D0,"ease-in-quad":H0,"ease-out-quad":F0,"ease-in-out-quad":L0,"ease-in-cubic":Ra,"ease-out-cubic":Ha,"ease-in-out-cubic":ti};function B0(t){const[e,n,s,i]=t,r=3*e,o=3*(s-e)-r,a=1-r-o,l=3*n,c=3*(i-n)-l,h=1-l-c,u=g=>((a*g+o)*g+r)*g,d=g=>((h*g+c)*g+l)*g,f=g=>(3*a*g+2*o)*g+r,m=g=>{let p=g;for(let k=0;k<8;k++){const w=u(p)-g;if(Math.abs(w)<1e-7)return p;const S=f(p);if(Math.abs(S)<1e-7)break;p-=w/S}let b=0,v=1;for(p=g;b<v;){const k=u(p);if(Math.abs(k-g)<1e-7)return p;g>k?b=p:v=p,p=(b+v)/2}return p};return g=>{if(g<=0)return 0;if(g>=1)return 1;const p=m(g);return d(p)}}function Fa(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 z0(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 q0=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 j0(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 K0(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 Y0(t){switch(t.type){case"steps":return K0(t.count,t.position);case"elastic":return Fa(z0(t.amplitude,t.period),t.mode);case"bounce":return Fa(q0,t.mode);case"back":return Fa(j0(t.overshoot),t.mode)}}function Dt(t){return t===void 0?Mr:Qn(t)?B0(t.points):Vs(t)?Y0(t):Vb[t]??Mr}const X0=32,Jb=256,ss=new Map,Zb=/[MmLlHhVvCcSsQqTtAaZz]/,Qb=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,tw={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function ew(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 r=t[n];if(Zb.test(r)){s={type:r,args:[]},e.push(s),n++;continue}if(!s)break;const o=s.type==="A"||s.type==="a",a=s.args.length%7;if(o&&(a===3||a===4)){if(r!=="0"&&r!=="1")break;s.args.push(r==="1"?1:0),n++;continue}const l=Qb.exec(t.slice(n));if(!l)break;s.args.push(parseFloat(l[0])),n+=l[0].length}return e}function nw(t,e,n,s,i,r,o,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),m=(t-a)/2,g=(e-l)/2,p=d*m+f*g,b=-f*m+d*g,v=p*p/(c*c)+b*b/(h*h);if(v>1){const F=Math.sqrt(v);c*=F,h*=F}const k=r===o?-1:1,w=c*c*h*h-c*c*b*b-h*h*p*p,S=c*c*b*b+h*h*p*p,x=k*Math.sqrt(Math.max(0,w/S)),M=x*c*b/h,E=-x*h*p/c,T=d*M-f*E+(t+a)/2,A=f*M+d*E+(e+l)/2,P=(F,B,Y,R)=>{const K=F*Y+B*R,st=Math.sqrt((F*F+B*B)*(Y*Y+R*R)),$=Math.acos(Math.max(-1,Math.min(1,K/st)));return F*R-B*Y<0?-$:$},I=P(1,0,(p-M)/c,(b-E)/h);let O=P((p-M)/c,(b-E)/h,(-p-M)/c,(-b-E)/h);!o&&O>0&&(O-=2*Math.PI),o&&O<0&&(O+=2*Math.PI);const _=Math.max(1,Math.ceil(Math.abs(O)/(Math.PI/2))),L=O/_,j=4/3*Math.tan(L/4),V=F=>{const B=c*Math.cos(F),Y=h*Math.sin(F);return[d*B-f*Y+T,f*B+d*Y+A]},tt=F=>{const B=-c*Math.sin(F),Y=h*Math.cos(F);return[d*B-f*Y,f*B+d*Y]},J=[];for(let F=0;F<_;F++){const B=I+F*L,Y=B+L,[R,K]=V(B),[st,$]=F===_-1?[a,l]:V(Y),[C,z]=tt(B),[X,W]=tt(Y);J.push([R+j*C,K+j*z,st-j*X,$-j*W,st,$])}return J}function Ze(t,e,n,s,i){const r=1-i;return r*r*r*t+3*r*r*i*e+3*r*i*i*n+i*i*i*s}function G0(t,e,n,s,i){const r=1-i;return 3*r*r*(e-t)+6*r*i*(n-e)+3*i*i*(s-n)}function ei(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 Sr(t,e,n){const[s,i,r,o,a,l]=n,c=[0];let h=t,u=e,d=0;for(let f=1;f<=X0;f++){const m=f/X0,g=Ze(t,s,r,a,m),p=Ze(e,i,o,l,m);d+=Math.hypot(g-h,p-u),c.push(d),h=g,u=p}return{subpath:0,type:"C",points:[s,i,r,o,a,l],startX:t,startY:e,endX:a,endY:l,length:d,lengths:c}}function An(t){const e=ss.get(t);if(e)return e;const n=[];let s=0,i=0,r=0,o=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:p}of ew(t)){const b=g.toUpperCase(),v=g!==b,k=tw[b];if(b==="Z"){(s!==r||i!==o)&&u(ei(s,i,r,o)),c>=0&&h.add(c),s=r,i=o,a=l=null;continue}for(let w=0;w+k<=p.length;w+=k){const S=p.slice(w,w+k),x=v?s:0,M=v?i:0;let E=null,T=null;switch(b){case"M":w===0?(s=S[0]+x,i=S[1]+M,r=s,o=i,(c<0||n[n.length-1]?.subpath===c)&&c++):(u(ei(s,i,S[0]+x,S[1]+M)),s=S[0]+x,i=S[1]+M);break;case"L":u(ei(s,i,S[0]+x,S[1]+M)),s=S[0]+x,i=S[1]+M;break;case"H":u(ei(s,i,S[0]+x,i)),s=S[0]+x;break;case"V":u(ei(s,i,s,S[0]+M)),i=S[0]+M;break;case"C":{const A=[S[0]+x,S[1]+M,S[2]+x,S[3]+M,S[4]+x,S[5]+M];u(Sr(s,i,A)),E=[A[2],A[3]],s=A[4],i=A[5];break}case"S":{const[A,P]=a?[2*s-a[0],2*i-a[1]]:[s,i],I=[A,P,S[0]+x,S[1]+M,S[2]+x,S[3]+M];u(Sr(s,i,I)),E=[I[2],I[3]],s=I[4],i=I[5];break}case"Q":case"T":{let A=s,P=i;b==="Q"?(A=S[0]+x,P=S[1]+M):l&&(A=2*s-l[0],P=2*i-l[1]);const I=b==="Q"?S[2]+x:S[0]+x,O=b==="Q"?S[3]+M:S[1]+M;u(Sr(s,i,[s+2/3*(A-s),i+2/3*(P-i),I+2/3*(A-I),O+2/3*(P-O),I,O])),T=[A,P],s=I,i=O;break}case"A":{const A=S[5]+x,P=S[6]+M;let I=s,O=i;for(const _ of nw(s,i,S[0],S[1],S[2],S[3],S[4],A,P))u(Sr(I,O,_)),I=_[4],O=_[5];s=A,i=P;break}}a=E,l=T}}const d=n.reduce((g,p)=>g+p.length,0),f=[];for(let g=0;g<n.length;){const p=n[g].subpath;let b=g,v=0;for(;b<n.length&&n[b].subpath===p;)v+=n[b++].length;const k=n[g],w=n[b-1],S=h.has(p)||Math.abs(w.endX-k.startX)<1e-9&&Math.abs(w.endY-k.startY)<1e-9;f.push({start:g,end:b,length:v,closed:S}),g=b}const m={segments:n,totalLength:d,subpaths:f};return ss.size>=Jb&&ss.delete(ss.keys().next().value),ss.set(t,m),m}function sw(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 r=n[i]-n[s],o=r>0?(e-n[s])/r:0;return(s+o)/(n.length-1)}function iw(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,r,o,a]=t.points,l=sw(t,e);let c=G0(t.startX,n,i,o,l),h=G0(t.startY,s,r,a,l);if(Math.hypot(c,h)<1e-9){const u=l<.5?Math.min(1,l+.001):Math.max(0,l-.001),d=Ze(t.startX,n,i,o,u),f=Ze(t.startY,s,r,a,u),m=Ze(t.startX,n,i,o,l),g=Ze(t.startY,s,r,a,l);c=l<.5?d-m:m-d,h=l<.5?f-g:g-f}return{x:Ze(t.startX,n,i,o,l),y:Ze(t.startY,s,r,a,l),angle:Math.atan2(h,c)*180/Math.PI}}function La(t,e,n=0,s=t.length){if(s<=n)return{x:0,y:0,angle:0};let i=0;for(let r=n;r<s;r++){const o=t[r];if(i+o.length>=e||r===s-1)return iw(o,e-i);i+=o.length}return{x:0,y:0,angle:0}}function U0(t,e){const{segments:n,totalLength:s}=An(t);return La(n,Math.max(0,Math.min(1,e))*s)}function rw(){ss.clear()}function ow(t){return An(t).totalLength}const aw=24,lw=320,cw=2.5,ni=72,hw=64,uw=.2,dw=128,si=new Map;let Tr=0,Qe;const V0=t=>Math.round(t*100)/100;function J0(t,e){const{segments:n,subpaths:s,totalLength:i}=An(t);if(n.length===0)return[];if(e){const r=s.every(o=>o.closed);return[{segments:n,start:0,end:n.length,length:i,closed:r}]}return s.filter(r=>r.length>0).map(r=>({segments:n,start:r.start,end:r.end,length:r.length,closed:r.closed}))}function Na(t,e){const n=t.closed?(e%1+1)%1:Math.max(0,Math.min(1,e)),s=La(t.segments,n*t.length,t.start,t.end);return[s.x,s.y]}function Z0(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 Q0(t,e){const n=[];for(let s=0;s<e;s++)n.push(Na(t,t.closed?s/e:s/(e-1)));return n}function tu(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 fw(t,e,n){const s=t.closed&&e.closed;if(n!==void 0)return{offset:s?Math.abs(n)%ni/ni:0,reversed:n<0};const i=tu(Q0(t,ni)),r=tu(Q0(e,ni)),o=ni;let a={offset:0,reversed:!1},l=1/0;for(const c of[!1,!0]){const h=s?o:1;for(let u=0;u<h;u++){let d=0;for(let f=0;f<o&&d<l;f++){const m=s?c?(u-f+o)%o:(f+u)%o:c?o-1-f:f,g=i[f][0]-r[m][0],p=i[f][1]-r[m][1];d+=g*g+p*p}d<l&&(l=d,a={offset:s?u/o:0,reversed:c})}}return a}function gw(t,e,n){return n?((e.reversed?e.offset-t:t+e.offset)%1+1)%1:e.reversed?1-t:t}function mw(t,e,n){return n?((e.reversed?e.offset-t:t-e.offset)%1+1)%1:e.reversed?1-t:t}function pw(t,e,n){const s=t.closed&&e.closed,i=fw(t,e,n.shapeIndex),r=Math.max(aw,Math.min(lw,Math.ceil(Math.max(t.length,e.length)/cw))),o=new Set,a=u=>o.add(Math.round(u*1e7)/1e7);for(let u=0;u<=r;u++)a(u/r);for(const u of Z0(t))a(u);for(const u of Z0(e))a(mw(u,i,s));let l=[...o].sort((u,d)=>u-d);s&&(l=l.filter(u=>u<1));const c=[],h=[];for(const u of l)c.push(...Na(t,u)),h.push(...Na(e,gw(u,i,s)));return yw({from:c,to:h,closed:s})}function yw(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[o,a]=s.pop();let l=-1,c=uw;for(let h=o+1;h<a;h++){const u=Math.max(eu(t.from,o,a,h),eu(t.to,o,a,h));u>c&&(c=u,l=h)}l!==-1&&(n[l]=1,s.push([o,l],[l,a]))}const i=[],r=[];for(let o=0;o<e;o++)n[o]&&(i.push(t.from[o*2],t.from[o*2+1]),r.push(t.to[o*2],t.to[o*2+1]));return{from:i,to:r,closed:t.closed}}function eu(t,e,n,s){const i=t[e*2],r=t[e*2+1],o=t[n*2]-i,a=t[n*2+1]-r,l=t[s*2]-i,c=t[s*2+1]-r,h=o*o+a*a,u=h===0?0:Math.max(0,Math.min(1,(l*o+c*a)/h));return Math.hypot(l-u*o,c-u*a)}function bw(t,e,n){const s=n.shapeIndex;if(Qe&&Qe.from===t&&Qe.to===e&&Qe.shapeIndex===s)return Qe.plan;const r=si.get(String(s??"auto"))?.get(t)?.get(e);if(r)return Qe={from:t,to:e,shapeIndex:s,plan:r},r;const o=An(t).subpaths.filter(f=>f.length>0).length===An(e).subpaths.filter(f=>f.length>0).length,a=J0(t,!o),l=J0(e,!o),c={pairs:a.map((f,m)=>pw(f,l[m],n))};Tr>=dw&&(si.clear(),Tr=0);const h=String(s??"auto"),u=si.get(h)??new Map;si.set(h,u);const d=u.get(t)??new Map;return u.set(t,d),d.set(e,c),Tr++,Qe={from:t,to:e,shapeIndex:s,plan:c},c}function nu(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 r=bw(t,e,s);if(r.pairs.length===0)return i<.5?t:e;let o="";for(const a of r.pairs){for(let l=0;l<a.from.length;l+=2){const c=V0(a.from[l]+(a.to[l]-a.from[l])*i),h=V0(a.from[l+1]+(a.to[l+1]-a.from[l+1])*i);o+=`${l===0?o?" M":"M":" L"}${c} ${h}`}a.closed&&(o+=" Z")}return o}function ww(){si.clear(),Tr=0,Qe=void 0}function is(t){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(t)}const rs=Math.PI/180,kw=.9995;function Wa(){return[0,0,0,1]}function Zt(t,e){const n=Math.hypot(t[0],t[1],t[2]);if(n===0)return Wa();const s=e*rs/2,i=Math.sin(s)/n;return[t[0]*i,t[1]*i,t[2]*i,Math.cos(s)]}function vw(t,e,n){return Da(Da(Zt([0,1,0],e),Zt([1,0,0],t)),Zt([0,0,1],n))}function Mw(t){const[e,n,s,i]=tn(t),r=2*(e*s+n*i),o=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/rs,Math.atan2(r,u)/rs,Math.atan2(o,a)/rs]:[d/rs,Math.atan2(-h,c)/rs,0]}function Da(t,e){const[n,s,i,r]=t,[o,a,l,c]=e;return[r*o+n*c+s*l-i*a,r*a-n*l+s*c+i*o,r*l+n*a-s*o+i*c,r*c-n*o-s*a-i*l]}function su(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function iu(t){return Math.hypot(t[0],t[1],t[2],t[3])}function tn(t){const e=iu(t);return e===0?Wa():[t[0]/e,t[1]/e,t[2]/e,t[3]/e]}function Sw(t){return[-t[0],-t[1],-t[2],t[3]]}function ru(t,e,n){const s=tn(t);let i=tn(e),r=su(s,i);if(r<0&&(i=[-i[0],-i[1],-i[2],-i[3]],r=-r),r>kw)return tn([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 o=Math.acos(r),a=Math.sin(o),l=Math.sin((1-n)*o)/a,c=Math.sin(n*o)/a;return tn([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 Tw(t,e){const[n,s,i,r]=tn(t),o=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]+r*o+(s*l-i*a),e[1]+r*a+(i*o-n*l),e[2]+r*l+(n*a-s*o)]}const Ew=Object.freeze(Object.defineProperty({__proto__:null,conjugate:Sw,dot:su,fromAxisAngle:Zt,fromEuler:vw,identity:Wa,length:iu,multiply:Da,normalize:tn,rotateVec3:Tw,slerp:ru,toEuler:Mw},Symbol.toStringTag,{value:"Module"})),Ie=(t,e,n)=>t+(e-t)*n,ou=512,Ba=new Map,za=new Map;function au(t){const e=Ba.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 Ba.size<ou&&Ba.set(t,s),s}const lu=t=>t.charCodeAt(0)===35,cu=t=>t.startsWith("rgb"),hu=t=>t.startsWith("rgba"),Aw=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,qa=t=>Math.round(t).toString(16).padStart(2,"0");function xw(t,e,n){return`#${qa(t)}${qa(e)}${qa(n)}`}function uu(t){const e=za.get(t);if(e)return e;const n=t.match(Aw);if(!n)throw new Error(`Invalid rgb color: ${t}`);const s=parseInt(n[1],10),i=parseInt(n[2],10),r=parseInt(n[3],10),o=n[4]!==void 0?[s,i,r,parseFloat(n[4])]:[s,i,r];return za.size<ou&&za.set(t,o),o}const du=(t,e,n)=>{if(lu(t)&&lu(e)){const[s,i,r]=au(t),[o,a,l]=au(e),c=Ie(s,o,n),h=Ie(i,a,n),u=Ie(r,l,n);return xw(c,h,u)}if((cu(t)||hu(t))&&(cu(e)||hu(e))){const s=uu(t),i=uu(e),r=Math.round(Ie(s[0],i[0],n)),o=Math.round(Ie(s[1],i[1],n)),a=Math.round(Ie(s[2],i[2],n));if(s.length===4||i.length===4){const l=s[3]??1,c=i[3]??1,h=Ie(l,c,n);return`rgba(${r}, ${o}, ${a}, ${h})`}return`rgb(${r}, ${o}, ${a})`}return n<1?t:e},fu=(t,e,n)=>{const s=Math.min(t.length,e.length),i=[];for(let r=0;r<s;r++)i.push(Ie(t[r],e[r],n));return i},gu=(t,e,n)=>ru(t,e,n),ja=(t,e,n)=>n<1?t:e,mu=(t,e,n)=>nu(t,e,n);function ii(t,e){return e==="slerp"?gu:typeof t=="number"?Ie:Array.isArray(t)?fu:typeof t=="string"?t.startsWith("#")||t.startsWith("rgb")?du:is(t)?mu:ja:ja}const Ka=1e3/60;function Ya(t,e={}){if(!Je(t))throw new Error(`bakeSpringTrack: track "${t.id}" is not a spring track`);const n=new Zs(t.spring);return pu(t,s=>n.valueAt(s),n.settleTime(),t.spring.from,t.spring.to,e)}function Xa(t,e={}){if(!Ve(t))throw new Error(`bakeInertiaTrack: track "${t.id}" is not an inertia track`);const n=t.inertia;return pu(t,s=>vr(n,s),ns(n),n.from,es(n),e)}function pu(t,e,n,s,i,r){const o=r.intervalMs??Ka,a=r.tolerance??.01,l=t.delay??0,c=[];for(let u=0;u<=n;u+=o)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?bu(c,a):c,...t.targets&&{targets:[...t.targets]},...t.stagger&&{stagger:{...t.stagger}}}}function Ga(t,e,n,s={}){const i=s.intervalMs??Ka,r=typeof n=="function"?n:Dt(n),o=ii(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:o(t.value,e.value,r(u)),easing:"linear"})}const c=r(1);return l.push({...e,...c!==1&&{value:o(t.value,e.value,c)},easing:"linear"}),l}function Pw(t,e){return Je(t)?Ya(t,e):Ve(t)?Xa(t,e):t}function yu(t,e={}){const n=t.keyframes;if(!n.some(r=>Vs(r.easing)))return t;const s=n.length>0?[n[0]]:[],i={...e,interpolation:t.interpolation??e.interpolation};for(let r=1;r<n.length;r++){const o=n[r];Vs(o.easing)?s.push(...Ga(n[r-1],o,o.easing,i)):s.push(o)}return{...t,keyframes:s}}function $w(t,e){return t.filter(O0).map(n=>yu(n,e)).concat(t.filter(Je).map(n=>Ya(n,e)),t.filter(Ve).map(n=>Xa(n,e)))}function bu(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],r=t[s],o=t[s+1],a=o.time-i.time;if(a<=0)continue;const l=(r.time-i.time)/a,c=i.value+(o.value-i.value)*l;Math.abs(r.value-c)>e&&n.push(r)}return n.push(t[t.length-1]),n}function Er(t){const e=[...t.keyframes].sort((n,s)=>n.time-s.time);return{...t,keyframes:e}}function en(t){return t.targets&&t.targets.length>0?t.targets:[t.target]}function os(t,e,n,s){const i=n??0;return!s||e<=1?i:i+pr(t,e,s)}class nn{track;targets;constructor(e){this.track=e,this.targets=en(e)}getValueAtTime(e){return this.valueForOffset(e-os(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 r=os(i,n,this.track.delay,this.track.stagger),o=this.valueForOffset(e-r);o!==void 0&&s.push({target:this.targets[i],value:o,start:r+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?Js(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 r=i.time-s.time,o=(e-s.time)/r,l=Dt(i.easing)(o);return ii(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 wu{track;targets;sampler;constructor(e){this.track=e,this.targets=en(e),this.sampler=new Zs(e.spring)}getValueAtTime(e){return this.sampler.valueAt(e-os(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 r=os(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:this.sampler.valueAt(e-r),start:r})}return s}getDuration(){const e=this.track.stagger?Js(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+e}getTrack(){return this.track}}class ku{track;targets;duration;constructor(e){this.track=e,this.targets=en(e),this.duration=ns(e.inertia)}getValueAtTime(e){return vr(this.track.inertia,e-os(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 r=os(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:vr(this.track.inertia,e-r),start:r})}return s}getDuration(){const e=this.track.stagger?Js(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+e}getTrack(){return this.track}}function Ua(t,e){const n={...U0(t.pathData,e)};if(t.matrix){const[s,i,r,o,a,l]=t.matrix,{x:c,y:h}=n;n.x=s*c+r*h+a,n.y=i*c+o*h+l;const u=n.angle*Math.PI/180,d=Math.cos(u),f=Math.sin(u);n.angle=Math.atan2(i*d+o*f,s*d+r*f)*180/Math.PI}return t.autoRotate&&t.rotateOffset&&(n.angle+=t.rotateOffset),n}function Iw(t,e,n,s){const i=e+(n-e)*s;return Ua(t,i)}const Va={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},Ow=20;function vu(t){const e=Va[t??"upperCase"]??t??Va.upperCase,n=Array.from(e);return n.length>0?n:Array.from(Va.upperCase)}function Cw(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 Mu(t,e,n=0){const s=t.from??"",i=t.to,r=Math.max(0,Math.min(1,e));if(r<=0)return s;if(r>=1)return i;const o=Array.from(s),a=Array.from(i),l=t.rightToLeft??!1;if(t.mode==="type"){const v=Math.round(r*Math.max(o.length,a.length));return l?o.slice(0,Math.max(0,o.length-v)).join("")+a.slice(Math.max(0,a.length-v)).join(""):a.slice(0,v).join("")+o.slice(v).join("")}const c=Math.max(0,Math.min(.999,t.revealDelay??0)),h=Math.max(0,(r-c)/(1-c)),u=Math.floor(h*a.length),d=t.tweenLength===!1?a.length:Math.round(o.length+(a.length-o.length)*r),f=vu(t.chars),m=t.refreshRate??Ow,g=m>0?Math.floor(n*m/1e3):0,p=t.seed??1;let b="";for(let v=0;v<d;v++){const k=l?v>=d-u:v<u,w=l?a[a.length-(d-v)]:a[v];k&&w!==void 0||w===" "||w===`
|
|
2
|
-
`?b+=w:b+=f[Cw(p,v,g)%f.length]}return b}class Ht{id;name;_captions;_tracks=[];_trackPlayers=new Map;_motionPathTracks=new Map;_springTracks=new Map;_textTracks=new Map;_config;_currentTime=0;_playbackState="idle";_direction="forward";_loopIteration=0;_explicitDuration;_repeatDelayRemaining=0;_wrapAfterDelay=!1;onUpdate=null;onComplete=null;constructor(e){if(this.id=e.id,this.name=e.name,this._captions=e.captions,this._config=e.config??{},this._explicitDuration=e.config?.duration,e.tracks)for(const n of e.tracks)this.addTrack(n)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(e){if(this._explicitDuration=e,e!==void 0)this._config={...this._config,duration:e};else if(this._config.duration!==void 0){const n={...this._config};delete n.duration,this._config=n}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(e){this._config.speed=e}get drawingRate(){return this._config.drawingRate??0}set drawingRate(e){const n={...this._config};e>0?n.drawingRate=e:delete n.drawingRate,this._config=n}play(){const e=this.duration;this._direction==="forward"&&this._currentTime>=e&&e>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&e>0&&(this._currentTime=e,this._loopIteration=0),this._playbackState="playing"}pause(){this._playbackState="paused"}stop(){this._playbackState="idle",this._repeatDelayRemaining=0,this._wrapAfterDelay=!1,this._currentTime=0,this._loopIteration=0,this._direction="forward"}seek(e){const n=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(e,n)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(e){if(this._playbackState!=="playing")return;const n=this.duration;if(n<=0)return;let i=e*this.speed;if(this._repeatDelayRemaining>0){const a=Math.min(this._repeatDelayRemaining,i);if(this._repeatDelayRemaining-=a,i-=a,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const r=1e3;for(let a=0;a<r&&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 o=this.getStateAtTime(this._currentTime);this.onUpdate?.(o)}getStateAtTime(e){const n=new Map;if(e=C0(e,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(e,n);else for(const[s,i]of this._trackPlayers){const r=i.getTrack().property;for(const{target:o,value:a,start:l}of i.getTargetValues(e))this._write(n,s,o,r,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,r]of this._trackPlayers){const o=r.getTrack().property;for(const{target:a,value:l,start:c}of r.getTargetValues(e)){const h=`${a}\0${o}`,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:o,value:l,start:c,started:u})}}for(const{trackId:i,target:r,property:o,value:a,start:l}of s.values())this._write(n,i,r,o,a,e-l)}_write(e,n,s,i,r,o){if(r===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 r=="number"){a.set("text",Mu(l.textConfig,r,Math.max(0,o)));return}const c=this._motionPathTracks.get(n);if(c&&typeof r=="number"){const h=Ua(c.motionPathConfig,r);a.set("motionPathX",h.x),a.set("motionPathY",h.y),c.motionPathConfig.autoRotate&&a.set("motionPathRotate",h.angle)}else a.set(i,r)}_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 en(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,Ve(e)){this._trackPlayers.set(e.id,new ku(e));return}if(Je(e)){this._trackPlayers.set(e.id,new wu(e)),this._springTracks.set(e.id,e);return}if(mr(e))this._trackPlayers.set(e.id,new nn(e)),this._textTracks.set(e.id,e);else if($a(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 nn(n)),this._motionPathTracks.set(e.id,e)}else this._trackPlayers.set(e.id,new nn(e))}replaceTrack(e,n){const s=this._tracks.findIndex(r=>r.id===e);if(s<0)return;const i=this._tracks.slice(s+1);this.removeTrack(e);for(const r of i)this.removeTrack(r.id);this.addTrack(n);for(const r of i)this.addTrack(r)}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(Je(s)||Ve(s))return{from:i,to:n.getDuration()};const r=s.keyframes;if(!(!r||r.length===0))return{from:r[0].time+i,to:n.getDuration()}}findConflicts(){const e=[];for(let n=0;n<this._tracks.length;n++){const s=this._tracks[n],i=this.getTrackSpan(s.id);if(i)for(let r=0;r<n;r++){const o=this._tracks[r];if(o.property!==s.property)continue;const a=en(o).filter(u=>en(s).includes(u));if(a.length===0)continue;const l=this.getTrackSpan(o.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?o.id:s.id,winningTrackId:h?s.id:o.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&&!en(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:Pa(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,r)=>i.time-r.time).map(i=>({...i})):void 0,s={...this._config};n?s.markers=n:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(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 _w=100;function Ja(t,e,n,s){const i=[],r=[],{duration:o,alternate:a}=s,l=(f,m,g,p)=>{r.push([f,m]);const b=[];t.forEach((v,k)=>{(g==="forward"?(p?v>=f:v>f)&&v<=m:(p?v<=f:v<f)&&v>=m)&&b.push(k)}),b.sort((v,k)=>(g==="forward"?t[v]-t[k]:t[k]-t[v])||v-k);for(const v of b)i.push({kind:"event",index:v,direction:g})};let c=e.time,h=e.direction,u=e.fresh===!0;const d=Math.min(_w,Math.max(0,n.iteration-e.iteration));for(let f=0;f<d;f++){const m=h==="forward"?o:0;l(c,m,h,u),i.push({kind:"repeat"}),a?(h=h==="forward"?"reverse":"forward",c=m,u=!1):(c=h==="forward"?0:o,u=!0)}return d>0&&s.holding&&!a?{crossings:i,passes:r}:(l(c,n.time,h,u),{crossings:i,passes:r})}function Su(t){return Ve(t)?{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:Tu(t.inertia),...Oe(t)}:Je(t)?{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...Oe(t)}:mr(t)?{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:t.keyframes.map(Za),...Oe(t)}:$a(t)?{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:t.keyframes.map(Za),...Oe(t)}:{id:t.id,target:t.target,property:t.property,keyframes:t.keyframes.map(Za),...t.interpolation!==void 0&&{interpolation:t.interpolation},...Oe(t)}}function Tu(t){return{...t,...Array.isArray(t.end)&&{end:[...t.end]}}}function Za(t){return{time:t.time,value:t.value,...t.easing&&{easing:t.easing}}}function Oe(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 Eu(t){if(Ve(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"inertia",inertia:Tu(e.inertia),...Oe(e)}}if(Je(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"spring",spring:{...e.spring},...Oe(e)}}if(mr(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),...Oe(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,...Oe(e)}}return Er({id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,...t.interpolation!==void 0&&{interpolation:t.interpolation},...Oe(t)})}function Au(t){const e=t._config.markers;return{formatVersion:Pa(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(Su),...t.captions&&{captions:JSON.parse(JSON.stringify(t.captions))}}}function as(t){const e=t.formatVersion??1;if(e>xa)throw new Error(`tinyfly: this animation uses format version ${e}, but this tinyfly reads up to version ${xa}. Update tinyfly to play it.`);return new Ht({id:t.id,name:t.name,config:t.config,tracks:t.tracks.map(Eu),captions:t.captions})}function Rw(t){return JSON.stringify(Au(t))}function Hw(t){const e=JSON.parse(t);return as(e)}function re(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 Se(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 Qa(t,e,n){return e+t.next()*(n-e)}function xu(t,e,n,s){if(s<=0)return Qa(t,e,n);const i=Math.floor((n-e)/s),r=Math.round(t.next()*i);return e+r*s}function Fw(t,e){if(e.length!==0)return e[Math.floor(t.next()*e.length)]}function Lw(t,e=0,n=1){const s=1-t.next(),i=t.next();return e+n*Math.sqrt(-2*Math.log(s))*Math.cos(2*Math.PI*i)}function Nw(t,e){const n=[...e];for(let s=n.length-1;s>0;s--){const i=Math.floor(t.next()*(s+1));[n[s],n[i]]=[n[i],n[s]]}return n}const Pu=/^([+\-*/])=\s*(-?[\d.]+)$/,$u=/^random\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*(?:,\s*(-?[\d.]+)\s*)?\)$/i;function Ww(t){return typeof t!="string"?!1:Pu.test(t.trim())||$u.test(t.trim())}function tl(t,e={}){if(typeof t!="string")return t;const n=t.trim(),s=Pu.exec(n);if(s){const[,r,o]=s,a=e.base??0,l=Number.parseFloat(o);switch(r){case"+":return a+l;case"-":return a-l;case"*":return a*l;case"/":return l===0?a:a/l}}const i=$u.exec(n);if(i){if(!e.random)throw new Error(`resolveValue: "${n}" needs a random source — pass one via context.random`);const r=Number.parseFloat(i[1]),o=Number.parseFloat(i[2]),a=i[3]!==void 0?Number.parseFloat(i[3]):void 0;return a!==void 0?xu(e.random,r,o,a):Qa(e.random,r,o)}return t}function Iu(t,e=0,n){const s=[];let i=e;for(const r of t){const o=tl(r,{base:i,random:n});s.push(o),typeof o=="number"&&(i=o)}return s}class Dw{random;constructor(e){this.random=Se(e)}get seed(){return this.random.seed}resolve(e,n=0){return tl(e,{base:n,random:this.random})}resolveSequence(e,n=0){return Iu(e,n,this.random)}}const Bw=600;function Ou(t){if(Array.isArray(t)){const[d,f,m,g]=t;return{fn:Ru(d,f,m,g),bezier:[d,f,m,g]}}const{segments:e}=An(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],r=i.endX-n,o=i.endY-s;if(r===0||o===0)throw new Error(`customEase: "${t}" must move along both axes`);const a=d=>(d-n)/r,l=d=>(d-s)/o;if(e.length===1&&i.type==="C"){const[d,f,m,g]=i.points,p=[a(d),l(f),a(m),l(g)];return{fn:Ru(...p),bezier:p}}const c=[],h=[],u=Math.max(8,Math.ceil(Bw/e.length));for(const d of e)for(let f=c.length===0?0:1;f<=u;f++){const[m,g]=zw(d,f/u);c.push(a(m)),h.push(l(g))}return{fn:qw(c,h)}}function Cu(t={}){const n=.1+Math.max(0,Math.min(1,t.strength??.7))*.7,s=[1];for(let r=n;r>.002;r*=n)s.push(2*Math.sqrt(r));const i=s.reduce((r,o)=>r+o,0);return r=>{if(r<=0)return 0;if(r>=1)return 1;let o=r*i;for(let a=0;a<s.length;a++){if(o<=s[a]){if(a===0)return(o/s[0])**2;const l=s[a]/2,c=l*l,h=o-l;return 1-(c-h*h)}o-=s[a]}return 1}}function _u(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 zw(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,r,o,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*o,l*l*l*t.startY+3*l*l*e*s+3*l*e*e*r+e*e*e*a]}function qw(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 o=s+i>>1;t[o]<=n?s=o:i=o}const r=t[i]-t[s];return r===0?e[i]:e[s]+(n-t[s])/r*(e[i]-e[s])}}function Ru(t,e,n,s){const i=(o,a,l)=>3*(1-o)*(1-o)*o*a+3*(1-o)*o*o*l+o*o*o,r=(o,a,l)=>3*(1-o)*(1-o)*a+6*(1-o)*o*(l-a)+3*o*o*(1-l);return o=>{if(o<=0)return 0;if(o>=1)return 1;let a=o;for(let h=0;h<8;h++){const u=i(a,t,n)-o,d=r(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=o;for(let h=0;h<40;h++)i(a,t,n)<o?l=a:c=a,a=(l+c)/2;return i(a,e,s)}}const jw=350,Kw=300,Yw=550;function Xw(t,e={}){const n=e.lead??jw,s=e.gap??Kw,i=e.tail??Yw,r=[];let o=0;return t.forEach((a,l)=>{const c=[];let h=o+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);r.push({id:a.id??`s${l}`,start:o,duration:u-o,cues:c}),o=u}),{duration:o,scenes:r,cues:r.flatMap(a=>a.cues)}}function Gw(t){return t.cues.map(e=>({id:e.id,time:e.start,label:e.text}))}function Uw(t,e){let n=t.scenes[0];for(const s of t.scenes)if(e>=s.start)n=s;else break;return n}const ri=t=>6e4/t.bpm;function Ar(t,e){return t.offset+e*ri(t)}function oi(t,e){return(e-t.offset)/ri(t)}function Vw(t,e){return Ar(t,Math.round(oi(t,e)))}function Jw(t,e){return Ar(t,Math.ceil(oi(t,e)-1e-9))}function Zw(t,e,n){const s=Math.max(1,Math.round(t.beatsPerBar??4)),i=[];if(!(t.bpm>0)||n<e)return i;for(let r=Math.ceil(oi(t,e)-1e-9);;r++){const o=Ar(t,r);if(o>n+1e-9)break;i.push({time:o,bar:(r%s+s)%s===0,n:r})}return i}const ls=100;function Qw(t,e,n={}){const s=n.minBpm??70,i=n.maxBpm??180,r=Math.max(1,Math.round(e/ls)),o=Math.min(t.length,Math.round((n.maxSeconds??60)*e)),a=Math.floor(o/r);if(a<4)return{bpm:120,offset:0,confidence:0};const l=new Float64Array(a);for(let T=0;T<a;T++){let A=0;for(let P=T*r;P<(T+1)*r;P++)A+=t[P]*t[P];l[T]=Math.log(1e-6+A/r)}const c=new Float64Array(a);for(let T=1;T<a;T++)c[T]=Math.max(0,l[T]-l[T-1]);const h=c.reduce((T,A)=>T+A,0)/a;for(let T=0;T<a;T++)c[T]=Math.max(0,c[T]-h);const u=Math.max(1,Math.floor(60*ls/i)),d=Math.min(a-1,Math.ceil(60*ls/s)),f=T=>{let A=0;for(let P=T;P<a;P++)A+=c[P]*c[P-T];return A/(a-T)};let m=0;for(let T=0;T<a;T++)m+=c[T]*c[T];m/=a;let g=u,p=-1/0;for(let T=u;T<=d;T++){const A=60*ls/T,P=Math.exp(-.5*(Math.log2(A/120)/.9)**2),I=f(T)*P;I>p&&(p=I,g=T)}const b=T=>{const A=Math.floor(T);return A<0||A+1>=a?0:c[A]+(c[A+1]-c[A])*(T-A)},v=(T,A)=>{let P=0;for(let I=A;I<a;I+=T)P+=b(I);return P};let k=g,w=0,S=-1/0;for(let T=g-.6;T<=g+.6+1e-9;T+=.02){if(T<1)continue;const A=Math.max(1,Math.round(T*4));for(let P=0;P<A;P++){const I=P/A*T,O=v(T,I);O>S&&(S=O,w=I,k=T)}}const x=60*ls/k,M=m>0?Math.max(0,Math.min(1,f(g)/m)):0,E=(w+.5)*1e3/ls;return{bpm:Math.round(x*100)/100,offset:Math.round(E%(6e4/x)),confidence:M}}const t2=600,e2=250,Hu=1;function n2(t,e){const n=e.target??"Camera",s={x:e.stage.width/2,y:e.stage.height/2},i={},r=(u,d,f,m)=>{const g=i[u]??=[];for(;g.length>0&&g[g.length-1].time>=d;)g.pop();g.push({time:d,value:f,...m?{easing:m}:{}})},o=u=>{const d=u.rotate*Math.PI/180,f=(u.focusX-s.x)*u.scale,m=(u.focusY-s.y)*u.scale;return{x:-(f*Math.cos(d)-m*Math.sin(d)),y:-(f*Math.sin(d)+m*Math.cos(d)),scale:u.scale,rotate:u.rotate}},a=(u,d,f)=>{const m=o(d);for(const g of["x","y","scale","rotate"])r(g,u,m[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(Hu,u.duration??t2);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>Hu?"ease-in-out":void 0))}else{const{follow:d}=u,f=d.lag??e2,m=new Ht({id:"follow",tracks:[{id:"x",target:"s",property:"x",keyframes:d.x}]}),g=v=>m.getStateAtTime(v).values.get("s")?.get("x")??l.focusX,p=[u.at,...d.x.map(v=>v.time).filter(v=>v>u.at&&v<u.until),u.until];a(u.at,l);const b=v=>({focusX:g(v)+(d.lead??0),focusY:d.y??l.focusY,scale:d.scale??l.scale,rotate:l.rotate});for(const v of p){const k=d.x.find(w=>w.time===v)?.easing;a(v+f,b(v),v===u.at?"ease-in-out":k)}l=b(u.until)}for(const u of c.filter(d=>"shake"in d)){const d=u.shake.strength??12,f=u.shake.roll??1.5,m=1e3/(u.shake.frequency??24),g=Se(u.shake.seed??Math.round(u.at)+1),p=()=>g.next()*2-1;for(const b of["shakeX","shakeY","shakeRotate"])r(b,u.at,0);for(let b=u.at+m;b<u.at+u.duration;b+=m){const v=1-(b-u.at)/u.duration;r("shakeX",b,p()*d*v),r("shakeY",b,p()*d*v),r("shakeRotate",b,p()*f*v)}for(const b of["shakeX","shakeY","shakeRotate"])r(b,u.at+u.duration,0,"ease-out")}return Object.entries(i).map(([u,d])=>({id:`${n}-${u}`,target:n,property:u,keyframes:d}))}function Fu(t,e){const n=t.toLowerCase(),s=e.toLowerCase();let i=Array.from({length:s.length+1},(r,o)=>o);for(let r=1;r<=n.length;r++){const o=[r];for(let a=1;a<=s.length;a++)o[a]=Math.min(i[a]+1,o[a-1]+1,i[a-1]+(n[r-1]===s[a-1]?0:1));i=o}return i[s.length]}function ai(t,e){const n=t.toLowerCase(),s=e.find(o=>o.toLowerCase().includes(n)||n.includes(o.toLowerCase()));if(s&&Math.min(t.length,s.length)>=3)return s;let i,r=1/0;for(const o of e){const a=Fu(t,o);a<r&&(r=a,i=o)}return i!==void 0&&r<=Math.max(2,Math.floor(t.length/3))?i:void 0}function dt(t,e,n,s){const i=typeof e=="string"?s??ai(e,n):void 0;return`Unknown ${t} ${JSON.stringify(e)}${i?`: did you mean "${i}"?`:"."} Known: ${n.join(", ")}`}function li(t,e){const n=e.step??33,s=e.stiffness??120,i=e.damping??9,r=e.mass??1;let o=t(e.start),a=0;const l=[{time:e.start,value:o}];let c=e.start+n;for(let h=e.start+1;h<=e.end;h++){const d=s*(t(h)-o)-i*a;a+=d/r*.001,o+=a*.001,(h>=c||h===e.end)&&(l.push({time:h,value:o}),c+=n)}return l}function xn(t,e,n=1){if(!(e>0))return 0;const s=t*n/e;return s-Math.floor(s)}function el(t){const e=t-Math.floor(t);return 1-Math.abs(e*2-1)}function s2(t,e){const n=Math.max(1,Math.round(e.cycles??1)),s=e.amplitude??1,i=xn(t,e.period,n)+(e.phase??0),r=i-Math.floor(i);switch(e.shape??"sine"){case"triangle":return s*(el(r+.25)*2-1);case"square":return r<.5?s:-s;default:return s*Math.sin(r*Math.PI*2)}}function i2(t,e){const n=Math.max(1,Math.round(e.cycles??1)),s=typeof e.easing=="function"?e.easing:Dt(e.easing??"ease-in-out"),i=xn(t,e.period,n)+(e.phase??0);return s(el(i))}function r2(t,e){const n=Lu(e.seed),s=Math.max(1,Math.round(e.cycles??1)),i=(xn(t,e.period,1)+(e.phase??0))*Math.PI*2,r=s/Math.PI;return Nu([Math.cos(i)*r+7.31,Math.sin(i)*r+3.17],n,e.octaves??1)}function o2(t,e,n){const s=Lu(n.seed),i=Math.max(1,Math.round(n.cycles??1)),r=Math.max(1,Math.round(n.cyclesAlong??1)),o=xn(t,n.period,1)*Math.PI*2,a=xn(e,n.periodAlong,1)*Math.PI*2,l=i/Math.PI,c=r/Math.PI;return Nu([Math.cos(o)*l+5.13,Math.sin(o)*l+9.47,Math.cos(a)*c+2.71,Math.sin(a)*c+6.29],s,n.octaves??1)}const Lu=t=>typeof t=="string"?re(t):(t??0)>>>0;function Nu(t,e,n){const s=Math.max(1,Math.min(6,Math.round(n)));let i=0,r=1,o=0;for(let a=0;a<s;a++){const l=2**a;i+=r*a2(t.map(c=>c*l),e+a*1013),o+=r,r*=.5}return i/o}function a2(t,e){const n=t.length,s=t.map(Math.floor),r=t.map((a,l)=>a-s[l]).map(a=>a*a*(3-2*a));let o=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?r[h]:1-r[h],c.push(s[h]+u)}l!==0&&(o+=l*l2(c,e))}return o}function l2(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 c2(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(r=>({time:r.at,value:r.value,easing:r.easing})).sort((r,o)=>r.time-o.time),interpolation:e.interpolation},i=new nn(s);return r=>i.getValueAtTime(r)}function h2(t,e){return e*ri({bpm:t.bpm})}function u2(t,e){const n=Math.max(1,Math.round(t/ri(e)));return{beats:n,grid:{...e,bpm:n*6e4/t}}}function d2(t,e,n={}){const s=Math.max(1e-6,n.attack??.05),i=Math.max(1e-6,n.decay??.4),r=oi(e,t),o=r-Math.floor(r),a=o<s?o/s:Math.max(0,1-(o-s)/i),l=n.barAccent??0;if(l<=0)return a;const c=Math.max(1,Math.round(e.beatsPerBar??4)),u=(Math.floor(r)%c+c)%c===0;return a*(u?1+l:1)/(1+l)}function f2(t,e,n={}){const s=n.fps??30,i=Math.max(1,Math.round(e/s)),r=Math.max(1,Math.ceil(t.length/i)),o=new Float32Array(r),a=Math.min(.99,Math.max(0,n.smoothing??.5));let l=0,c=0;for(let h=0;h<r;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 m=f>d?Math.sqrt(u/(f-d)):0;l=m>l?m:l*a+m*(1-a),o[h]=l,c=Math.max(c,l)}if(n.normalize!==!1&&c>0)for(let h=0;h<r;h++)o[h]/=c;return o}function g2(t,e,n=30,s){if(t.length===0)return 0;const r=(s?xn(e,s)*s:e)*n/1e3,o=Math.floor(r),a=t[Math.min(t.length-1,Math.max(0,o))],l=t[Math.min(t.length-1,Math.max(0,o+1))];return a+(l-a)*(r-o)}const Wu={"16:9":16/9,"2.39:1":2.39,"4:3":4/3,"1:1":1,"9:16":9/16,"4:5":4/5},nl=t=>typeof t=="number"?t:Wu[t];function m2(t,e){const n=nl(e),s=t.width/t.height;if(n>=s){const r=t.width/n;return{x:0,y:(t.height-r)/2,width:t.width,height:r}}const i=t.height*n;return{x:(t.width-i)/2,y:0,width:i,height:t.height}}function p2(t,e){const n=nl(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 y2(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 Ce=t=>Math.round(t*1e3)/1e3;function Du(t,e={}){if(t.length===0)return"";const n=e.curviness??1,s=e.closed??!1,i=t.length;let r=`M${Ce(t[0].x)} ${Ce(t[0].y)}`;if(i===1)return r;const o=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=o(l-1),h=o(l),u=o(l+1),d=o(l+2);if(n===0){r+=` L${Ce(u.x)} ${Ce(u.y)}`;continue}const f=n/6,m=h.x+(u.x-c.x)*f,g=h.y+(u.y-c.y)*f,p=u.x-(d.x-h.x)*f,b=u.y-(d.y-h.y)*f;r+=` C${Ce(m)} ${Ce(g)} ${Ce(p)} ${Ce(b)} ${Ce(u.x)} ${Ce(u.y)}`}return s?`${r} Z`:r}const zt=(t,e=0)=>{const n=parseFloat(t??"");return Number.isFinite(n)?n:e};function b2(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 xr(t){const e=t.attributes;switch(t.tag.toLowerCase()){case"path":return e.d??null;case"circle":case"ellipse":{const n=zt(e.cx),s=zt(e.cy),i=t.tag.toLowerCase()==="circle"?zt(e.r):zt(e.rx),r=t.tag.toLowerCase()==="circle"?zt(e.r):zt(e.ry);return`M${n+i} ${s} A${i} ${r} 0 1 1 ${n-i} ${s} A${i} ${r} 0 1 1 ${n+i} ${s} Z`}case"rect":{const n=zt(e.x),s=zt(e.y),i=zt(e.width),r=zt(e.height);let o=e.rx!=null?zt(e.rx):e.ry!=null?zt(e.ry):0,a=e.ry!=null?zt(e.ry):o;return o=Math.min(o,i/2),a=Math.min(a,r/2),o===0||a===0?`M${n} ${s} H${n+i} V${s+r} H${n} Z`:`M${n+o} ${s} H${n+i-o} A${o} ${a} 0 0 1 ${n+i} ${s+a} V${s+r-a} A${o} ${a} 0 0 1 ${n+i-o} ${s+r} H${n+o} A${o} ${a} 0 0 1 ${n} ${s+r-a} V${s+a} A${o} ${a} 0 0 1 ${n+o} ${s} Z`}case"line":return`M${zt(e.x1)} ${zt(e.y1)} L${zt(e.x2)} ${zt(e.y2)}`;case"polyline":case"polygon":{const n=b2(e.points);if(n.length===0)return null;const s=n.map((i,r)=>`${r===0?"M":"L"}${i.x} ${i.y}`).join(" ");return t.tag.toLowerCase()==="polygon"?`${s} Z`:s}default:return null}}function w2(t,e,n){const s=Math.max(2,Math.round(n.samples??32)),i=Math.max(0,n.length),r=n.since!==void 0?Math.max(e-i,n.since):e-i;if(r>=e)return[];const o=n.period,a=[];for(let l=0;l<s;l++){const c=r+(e-r)*l/(s-1),h=o&&o>0&&l<s-1?(c%o+o)%o:c;a.push({at:t(h),time:c,age:i>0?(e-c)/i:0})}return a}const k2=2.5;function Bu(t){const e=[],n=[],s=t.length,i=(r,o)=>{for(let a=r+o;a>=0&&a<s;a+=o){const l=(t[a].x-t[r].x)*o,c=(t[a].y-t[r].y)*o,h=Math.hypot(l,c);if(h>1e-9)return[l/h,c/h]}return null};for(let r=0;r<s;r++){const o=t[r],a=i(r,-1),l=i(r,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 m=u*c[0]+d*c[1],g=Math.min(k2,1/Math.max(m,1e-6)),p=o.width/2*g;e.push({x:o.x-d*p,y:o.y+u*p}),n.push({x:o.x+d*p,y:o.y-u*p})}return{left:e,right:n}}function zu(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,r=n.y-t[s].y,o=Math.hypot(i,r);if(o>1e-9)return{x:n.x,y:n.y,radius:n.width/2,start:Math.atan2(i/o,-r/o)}}return null}const v2={scale:1,turn:0,x:0,y:0};function M2(t={}){return{scale:t.scale??1,turn:t.turn??0,x:t.x??0,y:t.y??0}}function qu(t,e,n){const{ax:s,ay:i}=Pr(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 sl(t,e){const{ax:n,ay:s}=Pr(t.scale,t.turn);return{x:n*e.x-s*e.y+t.x,y:s*e.x+n*e.y+t.y}}function S2(t,e){const n=sl(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 T2(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=sl(e,{x:t.x,y:t.y});return{...e,x:-n.x,y:-n.y}}function ju(t){const{ax:e,ay:n}=Pr(t.scale,t.turn),s=1-e,i=-n,r=s*s+i*i;return r<1e-18?null:{x:(t.x*s+t.y*i)/r,y:(t.y*s-t.x*i)/r}}function E2(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=ju(t);return i?qu(n,s,i):{scale:n,turn:s,x:t.x*e,y:t.y*e}}function A2(t){const{ax:e,ay:n}=Pr(t.scale,t.turn);return[e,n,-n,e,t.x,t.y]}const Pr=(t,e)=>{const n=e*Math.PI/180;return{ax:t*Math.cos(n),ay:t*Math.sin(n)}};function $r([t,e,n],s={}){const i=s.scale??1,r=s.centre??{x:0,y:0},o=Math.sqrt(3)/2;return{x:r.x+(t-e)*o*i,y:r.y+((t+e)*.5-n)*i}}const il=([t,e,n])=>t+e+n;function rl(t,e={}){const[n,s,i]=t.min,[r,o,a]=t.max,l=d=>$r(d,e),c=[(n+r)/2,(s+o)/2,(i+a)/2],h=il(c),u=[{side:"top",depth:h,tag:t.tag,points:[l([n,s,a]),l([r,s,a]),l([r,o,a]),l([n,o,a])]},{side:"left",depth:h,tag:t.tag,points:[l([n,o,i]),l([r,o,i]),l([r,o,a]),l([n,o,a])]},{side:"right",depth:h,tag:t.tag,points:[l([r,s,i]),l([r,o,i]),l([r,o,a]),l([r,s,a])]}];return t.hide?u.filter(d=>!t.hide.includes(d.side)):u}function ol(t,e={}){return t.map(n=>({box:n,depth:il([(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})=>rl(n,e))}function x2(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]}],r=t.centre??{x:0,y:0},o=$r([2*e/3,e/3,e/3],{scale:t.scale}),a={centre:{x:r.x-o.x,y:r.y-o.y},scale:t.scale};return{boxes:i,faces:[...ol(i,a),...rl({...i[0],hide:["right"]},a)]}}function P2(t={}){const e=Math.max(2,Math.round(t.steps??8)),n=t.tread??1.5,s=t.rise??.25,i=t.width??3,r=t.base??1.5,o=Math.max(1,Math.round(e*(n-2*s)/(n+2*s))),a=2*(e+o),l=n*(e-o)/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:o},{dir:[0,-1,0],across:[1,0,0],count:o}],h=[];let u=[0,0,0],d=0;for(const b of c){for(let v=0;v<b.count;v++){const k=d*l,w=[u[0]+b.dir[0]*v*n,u[1]+b.dir[1]*v*n,0],S=[w[0]+b.dir[0]*n+b.across[0]*i,w[1]+b.dir[1]*n+b.across[1]*i,0];h.push({tag:d,min:[Math.min(w[0],S[0]),Math.min(w[1],S[1]),0],max:[Math.max(w[0],S[0]),Math.max(w[1],S[1]),k+r]}),d++}u=[u[0]+b.dir[0]*b.count*n,u[1]+b.dir[1]*b.count*n,0]}const f=a*l,m=t.centre??{x:0,y:0},g=$r([e*n/2,e*n/2,f/2+r],{scale:t.scale}),p={centre:{x:m.x-g.x,y:m.y-g.y},scale:t.scale};return{boxes:h,faces:ol(h,p),rise:l}}function Ku(t,e,n){let s=0;for(const i of t){const r=(e-i.x)**2+(n-i.y)**2;s+=r>1e-9?i.r*i.r/r:1e9}return s}function $2(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,r=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))},o=Math.max(2,Math.ceil(r.width/s)+1),a=Math.max(2,Math.ceil(r.height/s)+1),l=new Float64Array(o*a);for(let f=0;f<a;f++)for(let m=0;m<o;m++)l[f*o+m]=Ku(t,r.x+m*s,r.y+f*s)-n;const c=(f,m)=>l[m*o+f],h=(f,m,g,p,b,v)=>{const k=g===v?.5:g/(g-v);return{x:f+(p-f)*k,y:m+(b-m)*k}},u=[];for(let f=0;f+1<a;f++)for(let m=0;m+1<o;m++){const g=r.x+m*s,p=r.y+f*s,b=g+s,v=p+s,k=[c(m,f),c(m+1,f),c(m+1,f+1),c(m,f+1)],w=(k[0]>0?1:0)|(k[1]>0?2:0)|(k[2]>0?4:0)|(k[3]>0?8:0);if(w===0||w===15)continue;const S=()=>h(g,p,k[0],b,p,k[1]),x=()=>h(b,p,k[1],b,v,k[2]),M=()=>h(g,v,k[3],b,v,k[2]),E=()=>h(g,p,k[0],g,v,k[3]),T=(k[0]+k[1]+k[2]+k[3])/4>0;switch(w){case 1:case 14:u.push([E(),S()]);break;case 2:case 13:u.push([S(),x()]);break;case 3:case 12:u.push([E(),x()]);break;case 4:case 11:u.push([x(),M()]);break;case 6:case 9:u.push([S(),M()]);break;case 7:case 8:u.push([E(),M()]);break;case 5:T?u.push([E(),M()],[S(),x()]):u.push([E(),S()],[x(),M()]);break;case 10:T?u.push([E(),S()],[x(),M()]):u.push([E(),M()],[S(),x()]);break}}const d=I2(u);return e.smooth===!1?d:d.map(f=>Yu(Yu(f)))}function I2(t){const e=r=>`${Math.round(r.x*1e3)},${Math.round(r.y*1e3)}`,n=new Map;t.forEach(([r,o],a)=>{for(const l of[r,o]){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 r=0;r<t.length;r++){if(s[r])continue;s[r]=!0;const o=[t[r][0],t[r][1]];let a=t[r][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(o[0]))break;o.push(a)}o.length>=3&&i.push(o)}return i}function Yu(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 O2(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),r=t.x,o=t.y+i-s,a=Math.max(.1,n*(.35-.3*e)),l=o-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,w=a+(n-a)*Math.pow(1-k,1.6+1.4*e);u.push({x:r-w,y:t.y+c*k}),d.push({x:r+w,y:t.y+c*k})}const f=Math.max(8,Math.round(t.segments??12)),m=Math.acos(Math.min(1,a/s)),g=-m,p=Math.PI+m,b=[];for(let v=1;v<f;v++){const k=g+(p-g)*v/f;b.push({x:r+Math.cos(k)*s,y:o+Math.sin(k)*s})}return[...d,...b,...u.reverse()]}function C2(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)),r=t.wobble??.05,o=t.time??0,a=t.period?o/t.period:o/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+r*(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 _2(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),r=Math.PI*2/n*.6*(1-e);for(let o=0;o<n;o++){const a=o/n*Math.PI*2+.3,l=[];for(let c=0;c<=4;c++){const h=a-r/2+r*c/4;l.push({x:t.x+Math.cos(h)*i,y:t.y+Math.sin(h)*i})}s.push(l)}return s}function R2(t,e={}){const n=Math.max(.05,1+t);return{sx:e.keep==="volume"?1/Math.sqrt(n):1/n,sy:n}}function H2(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 ci(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function oe(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function Pn(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function We(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function hi(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 Ir(t){return Math.hypot(t[0],t[1],t[2])}function ui(t,e){return Ir(oe(t,e))}function Qt(t){const e=Ir(t);return e===0?[0,0,0]:Pn(t,1/e)}function $n(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 F2=Object.freeze(Object.defineProperty({__proto__:null,add:ci,cross:hi,distance:ui,dot:We,length:Ir,lerp:$n,normalize:Qt,scale:Pn,subtract:oe},Symbol.toStringTag,{value:"Module"})),L2=Math.PI/180;function Or(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function Ft(t,e){const n=new Array(16);for(let s=0;s<4;s++)for(let i=0;i<4;i++){let r=0;for(let o=0;o<4;o++)r+=t[o*4+i]*e[s*4+o];n[s*4+i]=r}return n}function In(t){return[1,0,0,0,0,1,0,0,0,0,1,0,t[0],t[1],t[2],1]}function On(t){return[t[0],0,0,0,0,t[1],0,0,0,0,t[2],0,0,0,0,1]}function Te(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 al(t,e,n){const s=Te(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 N2(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 ll(t){const[e,n,s,i,r,o,a,l,c,h,u,d,f,m,g,p]=t,b=e*o-n*r,v=e*a-s*r,k=e*l-i*r,w=n*a-s*o,S=n*l-i*o,x=s*l-i*a,M=c*m-h*f,E=c*g-u*f,T=c*p-d*f,A=h*g-u*m,P=h*p-d*m,I=u*p-d*g,O=b*I-v*P+k*A+w*T-S*E+x*M;if(Math.abs(O)<1e-12)return null;const _=1/O;return[(o*I-a*P+l*A)*_,(s*P-n*I-i*A)*_,(m*x-g*S+p*w)*_,(u*S-h*x-d*w)*_,(a*T-r*I-l*E)*_,(e*I-s*T+i*E)*_,(g*k-f*x-p*v)*_,(c*x-u*k+d*v)*_,(r*P-o*T+l*M)*_,(n*T-e*P-i*M)*_,(f*S-m*k+p*b)*_,(h*k-c*S-d*b)*_,(o*E-r*A-a*M)*_,(e*A-n*E+s*M)*_,(m*v-f*w-g*b)*_,(c*w-h*v+u*b)*_]}function W2(t,e,n,s){const i=1/Math.tan(t*L2/2),r=1/(n-s);return[i/e,0,0,0,0,i,0,0,0,0,(s+n)*r,-1,0,0,2*s*n*r,0]}function D2(t,e,n,s,i,r){const o=1/(e-t),a=1/(s-n),l=1/(r-i);return[2*o,0,0,0,0,2*a,0,0,0,0,-2*l,0,-(e+t)*o,-(s+n)*a,-(r+i)*l,1]}function B2(t,e,n=[0,1,0]){const s=Qt(oe(t,e)),i=Qt(hi(n,s)),r=hi(s,i);return[i[0],r[0],s[0],0,i[1],r[1],s[1],0,i[2],r[2],s[2],0,-We(i,t),-We(r,t),-We(s,t),1]}function ae(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],r=t[3]*e[0]+t[7]*e[1]+t[11]*e[2]+t[15];return r===1||r===0?[n,s,i]:[n/r,s/r,i/r]}const z2=Object.freeze(Object.defineProperty({__proto__:null,compose:al,fromQuat:Te,identity:Or,invert:ll,lookAt:B2,multiply:Ft,orthographic:D2,perspective:W2,scaling:On,transformPoint:ae,translation:In,transpose:N2},Symbol.toStringTag,{value:"Module"})),Cr={"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]},Xu={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 q2(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}Dt({type:"bounce",mode:"in"}),Dt({type:"bounce",mode:"in-out"});function di(t){const e=Gu.get(t.trim().toLowerCase());if(e)return e;const n=q2(t),s=/^steps\(\s*(\d+)\s*\)$/.exec(n);if(s){const o={type:"steps",count:Math.max(1,Number.parseInt(s[1],10))+1,position:"none"};return{easing:o,fn:Dt(o)}}const i=/^(elastic|bounce|back)\.(in|out|inout)(?:\(([^)]*)\))?$/.exec(n);if(i){const[,r,o,a]=i,l=(a??"").split(",").map(u=>Number.parseFloat(u)).filter(u=>Number.isFinite(u)),c=o==="inout"?"in-out":o;if(r==="back"&&l.length===0&&n in Cr)return{easing:{type:"cubic-bezier",points:Cr[n]}};const h=r==="elastic"?{type:"elastic",mode:c,...l[0]!==void 0&&{amplitude:l[0]},...l[1]!==void 0&&{period:l[1]}}:r==="bounce"?{type:"bounce",mode:c}:{type:"back",mode:c,...l[0]!==void 0&&{overshoot:l[0]}};return{easing:h,fn:Dt(h)}}return n in Xu?{easing:Xu[n]}:n in Cr?{easing:{type:"cubic-bezier",points:Cr[n]}}:{easing:"ease-out"}}const Gu=new Map;function cl(t,e){return Gu.set(t.trim().toLowerCase(),e.bezier?{easing:{type:"cubic-bezier",points:e.bezier},fn:e.fn}:{fn:e.fn,requiresBaking:"custom"}),t}function hl(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 Uu=/^\s*random\(\s*(\[.*\]|[^)]*)\s*\)\s*$/;function Vu(t){return typeof t=="string"&&Uu.test(t)}function j2(t=1){let e=hl(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),r=(l,c)=>{if(typeof l=="number")return l===0?c:Math.round(c/l)*l;if(Array.isArray(l))return Ju(l,c,1/0);if("values"in l)return Ju(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},o=(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]=ii(l[d])(l[d],c[d],h);return u}return ii(l)(l,c,h)}),wrap:((l,c,h)=>{if(Array.isArray(l)){const g=l,p=b=>g[(Math.round(b)%g.length+g.length)%g.length];return c===void 0?p:p(c)}const u=l,f=c-u,m=g=>f===0?u:((g-u)%f+f)%f+u;return h===void 0?m:m(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,r),random:((l,c,h,u)=>{if(Array.isArray(l)){const f=()=>l[Math.floor(e()*l.length)];return c===!0?f:f()}const d=()=>o(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,m,g)=>{const p=g.length,v=pr(f,p,{...c!==void 0?{amount:c}:{each:h??1},from:u}),k=c!==void 0?c:(h??1)*Oa(p,u),w=d&&k>0?d(v/k)*k:v;return l+w},pipe:(...l)=>c=>l.reduce((h,u)=>u(h),c),splitColor:l=>K2(l),getUnit:l=>typeof l=="number"?"":/^-?[\d.]+(?:e[-+]?\d+)?([a-z%]*)$/i.exec(l.trim())?.[1]??"",seed:l=>{e=hl(l)},resolveRandomString:l=>{const c=Uu.exec(l)?.[1]??"";if(c.startsWith("[")){const m=c.slice(1,-1).split(",").map(g=>g.trim()).filter(Boolean).map(g=>Number.isFinite(Number(g))?Number(g):g.replace(/^['"]|['"]$/g,""));return m[Math.floor(e()*m.length)]}const[h,u,d]=c.split(",").map(f=>Number.parseFloat(f));return o(h,u,Number.isFinite(d)?d:void 0)}}}function Ju(t,e,n){let s=e,i=1/0;for(const r of t){const o=Math.abs(r-e);o<i&&(i=o,s=r)}return i<=n?s:e}function K2(t){const e=t.trim(),n=/^#([0-9a-f]{3,8})$/i.exec(e)?.[1];if(n){const r=(n.length<=4?[...n].map(o=>o+o).join(""):n).match(/../g).map(o=>Number.parseInt(o,16));return r.length>=4?[r[0],r[1],r[2],Math.round(r[3]/255*1e3)/1e3]:[r[0],r[1],r[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 Y2=/^([+-])=\s*(-?[\d.]+)$/,X2=/^([<>])\s*(?:([+-])?=?\s*(-?[\d.]+))?$/;function fi(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 r=Y2.exec(i);if(r){const c=s(r[2]);return e.cursor+(r[1]==="-"?-c:c)}const o=X2.exec(i);if(o){const c=o[1]==="<"?e.previousStart:e.previousEnd;if(o[3]===void 0)return c;const h=s(o[3]);return c+(o[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 G2(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 U2(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),r=m=>({x:m%s,y:Math.floor(m/s)}),o=e.from??"start",a=Array.isArray(o)?{x:o[0]*(s-1),y:o[1]*(i-1)}:typeof o=="number"?r(Math.max(0,Math.min(t-1,o))):o==="end"?r(t-1):o==="center"||o==="edges"?{x:(s-1)/2,y:(i-1)/2}:{x:0,y:0},l=m=>{const{x:g,y:p}=r(m),b=Math.abs(g-a.x),v=Math.abs(p-a.y);return e.axis==="x"?b:e.axis==="y"?v:Math.hypot(b,v)};let c=Array.from({length:t},(m,g)=>l(g));const h=Math.max(...c);if(o==="edges"&&(c=c.map(m=>h-m)),o==="random"){const m=n.random??Math.random;c=c.map(()=>m()*h)}const u=e.amount!==void 0?e.amount:(e.each??0)*h,d=e.ease?di(e.ease):void 0,f=d?d.fn??Dt(d.easing):void 0;return c.map(m=>{const g=h===0?0:m/h;return(f?f(g):g)*u})}const ul=new Set(["duration","delay","ease","repeat","repeatDelay","yoyo","stagger","onComplete","onUpdate","onStart","onRepeat","onReverseComplete","repeatRefresh","keyframes","easeEach","scrollTo","id","immediateRender","overwrite","paused","scrollTrigger","spring"]),V2={rotation:"rotate",rotationZ:"rotate",rotationX:"rotateX",rotationY:"rotateY",transformPerspective:"perspective",perspective:"childPerspective"};function _r(t){const e={},n={};for(const[s,i]of Object.entries(t))ul.has(s)?e[s]=i:n[V2[s]??s]=i;return{config:e,properties:n}}function Rr(t,e){return t===void 0?e:t*1e3}function dl(t,e){if(t!==void 0)return typeof t=="number"?{each:t*1e3}:G2(t)?{offsets:U2(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 J2={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 Zu(t){return J2[t]}function Z2(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=Du(e.path,{curviness:e.curviness});else if(is(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 Q2(t){const e=typeof t=="string"||Array.isArray(t)?{path:t}:{...t};return{...e,start:e.end??1,end:e.start??0}}function Qu(t){return typeof t=="object"&&t!==null&&"shape"in t?t.shape:t}function tk(t){if(t.morphSVG===void 0)return t;const{morphSVG:e,...n}=t,s=Qu(e);if(typeof s!="string"||!is(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 ek(t,e){if(t===!0)return[0,e];if(t===!1)return[0,0];if(typeof t=="number")return[0,td(t,e)];const n=t.trim().split(/[\s,]+/).filter(Boolean),s=o=>{const a=Number.parseFloat(o);if(Number.isNaN(a))throw new Error(`gsap-compat: drawSVG "${t}" is not a length or percentage`);return td(o.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]),r=s(n[1]);return i<=r?[i,r]:[r,i]}function nk(t,e){const[n,s]=ek(t,e);return{strokeDasharray:[s-n,e],strokeDashoffset:-n}}function sk(t,e){if(t.drawSVG===void 0)return t;const{drawSVG:n,...s}=t;return{...s,...nk(n,e)}}function ik(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 td(t,e){return Math.max(0,Math.min(e,t))}function rk(t){let e=2166136261;for(let n=0;n<t.length;n++)e=Math.imul(e^t.charCodeAt(n),16777619);return e>>>0}function ok(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 r=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},...r!==void 0&&{revealDelay:Math.min(r,.999)},...i.tweenLength!==void 0&&{tweenLength:i.tweenLength},...i.rightToLeft!==void 0&&{rightToLeft:i.rightToLeft},seed:i.seed??rk(`${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 fl(t){return Math.max(.1,t/25)}function ak(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?fl(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(Qs(i))]:n.end!==void 0&&(i.end=Array.isArray(n.end)?[...n.end]:n.end),i}function lk(t){const e=t===!0?{}:typeof t=="string"?{preset:t}:t;if(e.preset!==void 0&&!(e.preset in wr))throw new Error(`gsap-compat: unknown spring preset "${e.preset}" — use one of ${Object.keys(wr).join(", ")}`);return{...e.preset?wr[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 ck(t,e){if(t===!0||typeof t=="string")return;const n=t.velocity;return typeof n=="number"?n:n?.[e]}class Cn{timeline;options;cursor=0;fallbackRandom=hl(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,gi(n),s)}from(e,n,s){const{config:i,properties:r}=_r(gi(n)),{motionPath:o,text:a,scrambleText:l,...c}=r,h=this.targetsOf(e)[0],u={...i};for(const m of Object.keys(c))u[m]=this.resolveStart(h,m);o!==void 0&&(u.motionPath=Q2(o));const d={},f=String(this.resolveStart(h,"text"));return a!==void 0&&(d.text=gl(a),u.text=typeof a=="object"?{...a,value:f}:f),l!==void 0&&(d.text=gl(l),u.scrambleText=typeof l=="object"?{...l,text:f}:f),this.build(e,{...c,...d},u,s)}fromTo(e,n,s,i){const{properties:r}=_r(gi(n));return this.build(e,r,gi(s),i)}set(e,n,s){return this.build(e,void 0,{...gi(n),duration:0},s)}get lastStart(){return this.previousStart}get lastEnd(){return this.previousEnd}addEvent(e){const n=Math.max(0,fi(e,this.context()));return this.previousStart=n,this.previousEnd=n,this.cursor=Math.max(this.cursor,n),n}timeOf(e){return fi(e,this.context())}addLabel(e,n){return this.labels.set(e,fi(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=fi(n,this.context());for(const r of e.timeline.tracks){if(!("keyframes"in r))continue;const o=Er({...r,id:this.nextTrackId(`nested-${r.id}`),keyframes:r.keyframes.map(a=>({...a,time:a.time+s}))});this.timeline.addTrack(o)}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:r,properties:o}=_r(s),{motionPath:a,text:l,scrambleText:c,inertia:h,...u}=o,d=this.targetsOf(e),f=fi(i,this.context()),m=Rr(r.delay,0),g=Rr(r.duration,500),p=dl(r.stagger,{count:d.length,columnsFromLayout:this.options.layoutColumns?()=>this.options.layoutColumns(d):void 0,random:this.options.random??this.fallbackRandom}),b=this.easingFor(r.ease),v=[],k=r.spring;let w=0,S=!1;for(const[P,I]of Object.entries(u)){const O=I;let _=n?.[P]!==void 0?n[P]:this.resolveStart(d[0],P);if(typeof _!=typeof O&&(this.warn(`no usable start value for "${P}" on "${d[0]}" — it will snap to ${String(O)}. Use fromTo() to animate it.`),_=O),k!==void 0&&(typeof _!="number"||typeof O!="number")&&this.warn(`spring works on numbers, so "${P}" on "${d[0]}" eases instead`),k!==void 0&&typeof _=="number"&&typeof O=="number"){const V={...lk(k),from:_,to:O,velocity:ck(k,P)??this.options.startVelocity?.(d[0],P)??0},tt=this.nextTrackId(`${d[0]}-${P}-spring`),J={id:tt,target:d[0],...d.length>1&&{targets:d},...p&&d.length>1&&{stagger:p},property:P,kind:"spring",spring:V,delay:f+m};this.timeline.addTrack(J),v.push(tt),w=Math.max(w,_0(V));for(const F of d)this.lastValues.set(`${F}|${P}`,O);continue}S=!0;const L=this.keyframesFor(_,O,g,b,r.ease),j=this.nextTrackId(`${d[0]}-${P}`);this.timeline.addTrack(Er({id:j,target:d[0],...d.length>1&&{targets:d},...p&&d.length>1&&{stagger:p},property:P,delay:f+m,keyframes:L,...P==="quaternion"&&{interpolation:"slerp"}})),v.push(j);for(const V of d)this.lastValues.set(`${V}|${P}`,O)}const x=ok({text:l,scrambleText:c},d[0],g);if(x){const P=n?.text??n?.scrambleText,I=P!==void 0?gl(P):this.resolveStart(d[0],"text"),O=this.nextTrackId(`${d[0]}-text`),_={id:O,target:d[0],...d.length>1&&{targets:d},...p&&d.length>1&&{stagger:p},property:"text",textConfig:{from:typeof I=="string"?I:String(I??""),...x},delay:f+m,keyframes:this.keyframesFor(0,1,g,b,r.ease)};this.timeline.addTrack(_),v.push(O);for(const L of d)this.lastValues.set(`${L}|text`,x.to)}if(a!==void 0){const{config:P,start:I,end:O}=Z2(a),_=this.nextTrackId(`${d[0]}-motionPath`),L={id:_,target:d[0],...d.length>1&&{targets:d},...p&&d.length>1&&{stagger:p},property:"motionPath",motionPathConfig:P,delay:f+m,keyframes:this.keyframesFor(I,O,g,b,r.ease)};this.timeline.addTrack(L),v.push(_)}if(h!==void 0)for(const[P,I]of Object.entries(h)){const O=this.resolveStart(d[0],P);if(typeof O!="number"){this.warn(`inertia on "${P}" needs a numeric start value; skipped`);continue}const _=ak(O,I),L=this.nextTrackId(`${d[0]}-${P}-inertia`),j={id:L,target:d[0],...d.length>1&&{targets:d},...p&&d.length>1&&{stagger:p},property:P,kind:"inertia",inertia:_,delay:f+m};this.timeline.addTrack(j),v.push(L),w=Math.max(w,ns(_));for(const V of d)this.lastValues.set(`${V}|${P}`,es(_))}const T=((h!==void 0||k!==void 0)&&!S&&!x&&a===void 0?w:Math.max(g,w))+(p&&d.length>1?Js(d.length,p):0),A=f+m+T;return this.previousStart=f+m,this.previousEnd=A,this.cursor=Math.max(this.cursor,A),{trackIds:v,start:f+m,end:A,kill:()=>{for(const P of v)this.timeline.removeTrack(P)}}}keyframesFor(e,n,s,i,r){const o={time:0,value:e};if(s<=0)return[{time:0,value:n}];const a=typeof r=="string"?di(r):void 0;if(a?.requiresBaking==="custom"||this.options.bakeEases&&Vs(i)){const c=a?.fn??Dt(i);return[o,...Ga(o,{time:s,value:n},c,{intervalMs:this.options.bakeIntervalMs})]}return[o,{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 r=this.options.defaults?.[n];if(r!==void 0)return r;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 o=Zu(n);return o!==void 0?(this.warn(`no start value for "${n}" on "${e}" — using the static default ${o}. GSAP would read the live DOM here; tinyfly cannot, so pass an explicit fromTo() or a defaults map.`),o):(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 di(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 gl(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 hk(t){return new Cn(t)}function gi(t){return ik(tk(t))}function uk(t){return!Array.isArray(t)||t.length!==4?null:`matrix3d(${Te(tn(t)).map(n=>Math.round(n*1e6)/1e6+0).join(", ")})`}const dk=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),fk="#ffffff",gk="rgba(0, 0, 0, 0.5)";function mk(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??fk})`),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??gk})`)}return e.length>0?e.join(" "):null}function pk(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 yk(t){if(!("ownerSVGElement"in t))return;const e=t.style;!e||e.transformBox||(e.transformBox="fill-box",e.transformOrigin||(e.transformOrigin="50% 50%"))}const ed=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"]),bk=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),wk=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],kk=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),vk=new Set(["originX","originY"]),Mk=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Sk=new Set(["drawOn"]),Tk={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},nd={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},Ek="http://www.w3.org/2000/svg";class _n{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,r=null,o=null,a=null;const l=n.has("motionPathX"),c=n.has("motionPathY"),h=n.has("motionPathRotate");for(const[m,g]of n)if(!(m==="x"&&l)&&!(m==="y"&&c)&&!((m==="rotate"||m==="rotateZ")&&h)&&!Sk.has(m)){if(bk.has(m))(s??={})[m]=g;else if(kk.has(m))typeof g=="number"&&((i??={})[m]=g);else if(vk.has(m))typeof g=="number"&&((r??={})[m]=g);else if(Mk.has(m))typeof g=="number"&&((o??={})[m]=g);else if(dk.has(m))(a??={})[m]=g;else if(m!=="perspective"){if(m!=="shine")if(m==="text"&&typeof g=="string")pk(e,g);else if(m==="d"&&typeof g=="string"){const p=e;(p.tagName?.toLowerCase()==="path"?p:p.querySelector?.("path"))?.setAttribute?.("d",g)}else this.applyStyleProperty(e,m,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 m of wk){const g=s[m];if(g===void 0)continue;const p=this.buildTransformPart(m,g);p&&d.push(p)}if(d.length>0&&(e.style.transform=d.join(" "),yk(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}%`)),r){const m=r.originX??50,g=r.originY??50;e.style.transformOrigin=`${m}% ${g}%`}if(o){const m=o.clipTop??0,g=o.clipRight??0,p=o.clipBottom??0,b=o.clipLeft??0;e.style.clipPath=`inset(${m}% ${g}% ${p}% ${b}%)`}if(a){const m=mk(a);m&&(e.style.filter=m)}}buildTransformPart(e,n){if(e==="quaternion")return uk(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,r=e.style;r.color="transparent",r.backgroundImage=`linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${s}, ${s})`,r.backgroundSize="250% 100%, 100% 100%",r.backgroundPosition=`${i}% 0, 0 0`,r.backgroundRepeat="no-repeat",r.webkitBackgroundClip="text",r.backgroundClip="text"}applyStyleProperty(e,n,s){let i;if(e.namespaceURI===Ek&&n in nd){const a=Array.isArray(s)?s.join(", "):String(s);e.style[nd[n]]=a;return}else n==="fill"&&e.dataset?.elementType==="text"?i="color":i=Tk[n]??n;let o;typeof s=="number"?ed.has(n)||ed.has(i)?o=`${s}px`:o=String(s):Array.isArray(s)?o=s.join(", "):o=s,e.style[i]=o}}const Ak={request:t=>requestAnimationFrame(t),cancel:t=>cancelAnimationFrame(t)};class sd{adapter=new _n;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=j2();active=new Map;applied=new Map;dirty=new Set;frameId=null;lastTimestamp=null;destroyed=!1;constructor(e={}){this.scheduler=e.scheduler??Ak,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);ml(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 r=i.currentTime;if(r<4)return 0;const o=i.getStateAtTime(r).values.get(e)?.get(n),a=i.getStateAtTime(r-4).values.get(e)?.get(n);if(typeof o!="number"||typeof a!="number")return;const l=(o-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[r,o]of s)i.set(r,o);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[r,o]of s)i[r]=o;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(ml(e))return[e];if(!xk(e))return[e];const n=[];for(const s of Array.from(e))n.push(...this.targetsOf(s));return n}nameFor(e){return ml(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 ml(t){return typeof t=="object"&&t!==null&&t.nodeType===1}function xk(t){if(Array.isArray(t))return!0;const e=t;return typeof e.length=="number"&&typeof e.item=="function"}function Hr(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 id=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function Pk(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function $k(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 Ik(t,e){const n=typeof t=="string"||Array.isArray(t)||id(t)?{path:t}:t,{align:s,alignOrigin:i,path:r,...o}=n,a=x=>{const M=id(x)?x:e.query(x);return M||e.warn(`gsap-compat: motionPath could not find "${String(x)}"`),M};let l=null,c="";if(Array.isArray(r)||typeof r=="string"&&is(r))c=r;else{l=a(r);const x=l&&xr({tag:l.localName,attributes:Pk(l)});l&&!x&&e.warn(`gsap-compat: motionPath element <${l.localName}> has no path geometry`),c=x??""}const h={...o,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,m,g,p,b,v]=$k(u),k=Hr(d),[w,S]=i??[.5,.5];for(const x of e.targets.slice(1)){const M=Hr(x);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,m,g,p,b-k.left-w*k.width,v-k.top-S*k.height],h}const rd=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function od(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function ad(t){if(!t)return null;const e=xr({tag:t.localName,attributes:od(t)});return e||(t.querySelector("path")?.getAttribute("d")??null)}function Ok(t,e,n){const s=Qu(t);if(typeof s=="string"&&is(s))return s;const i=rd(s)?s:typeof s=="string"?e(s):null,r=ad(i);return r||(n(`gsap-compat: morphSVG could not find a shape for "${String(s)}"`),"")}const Ck=new Set(["cx","cy","r","rx","ry","x","y","width","height","x1","y1","x2","y2","points"]);function _k(t,e=document){return(typeof t=="string"?Array.from(e.querySelectorAll(t)):rd(t)?[t]:Array.from(t)).map(s=>{if(s.localName==="path")return s;const i=xr({tag:s.localName,attributes:od(s)});if(!i||!s.parentNode)return s;const r=s.ownerDocument.createElementNS("http://www.w3.org/2000/svg","path");for(const o of Array.from(s.attributes))Ck.has(o.name)||r.setAttribute(o.name,o.value);return r.setAttribute("d",i),s.parentNode.replaceChild(r,s),r})}const ld=.3;class cd{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=hd(),this.options.onPress?.(this.stateFrom(0,0,s))}move(e,n,s){if(!this.dragging)return;const i=e-this.lastX,r=n-this.lastY;this.lastX=e,this.lastY=n;const o=e-this.startX,a=n-this.startY,l=this.options.tolerance??3;if(!this.passedTolerance){if(Math.hypot(o,a)<l)return;this.passedTolerance=!0}this.updateVelocity(i,r),this.options.preventDefault!==!1&&s.cancelable&&s.preventDefault(),this.options.onMove?.(this.stateFrom(i,r,s))}end(e){this.dragging&&(this.dragging=!1,this.options.onRelease?.(this.stateFrom(0,0,e)))}updateVelocity(e,n){const s=hd(),i=Math.max(1,s-this.lastTime);this.lastTime=s;const r=e/i*1e3,o=n/i*1e3;this.velocityX+=(r-this.velocityX)*ld,this.velocityY+=(o-this.velocityY)*ld}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 hd(){return typeof performance<"u"?performance.now():Date.now()}function ud(t,e,n){let s={delta:0,line:null},i=n;for(const r of t)for(const o of e){const a=Math.abs(o-r);a<=i&&(i=a,s={delta:o-r,line:o})}return s}function dd(t,e){return e<=0?[]:t.map(n=>Math.round(n/e)*e)}class pl{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 cd({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,r=Rk(i/s);e.pause(),e.seek(r*n)}applyConstraints(e,n){let s=e;const i=[...dd([s],this.options.snap??0),...(n==="x"?this.options.snapLinesX:this.options.snapLinesY)??[]],r=ud([s],i,this.snapThreshold());s+=r.delta,n==="x"?this.snappedX=r.line:this.snappedY=r.line;const o=this.options.bounds;if(o){const a=n==="x"?o.minX:o.minY,l=n==="x"?o.maxX:o.maxY;a!==void 0&&(s=Math.max(a,s)),l!==void 0&&(s=Math.min(l,s))}return s}}function Rk(t){return t<0?0:t>1?1:t}function Hk(t){const e=new pl(t);return e.start(),e}const Fk={x:"x",y:"y","x,y":"both"},yl=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function fd(t,e){const n=Hr(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 gd(t){return Array.isArray(t)?[...t]:t}function Lk(t,e,n,s={}){const[i]=e.resolveTargets(n),r=i?e.elementFor(i):void 0;if(!i||!r)throw new Error(`gsap-compat: live.draggable could not find ${String(n)}`);if(s.type==="rotation")return Nk(t,e,i,r,s);const o=Fk[s.type??"x,y"],a=()=>{const g=e.appliedValue(i,"x"),p=e.appliedValue(i,"y");return{x:typeof g=="number"?g:0,y:typeof p=="number"?p:0}},l=typeof s.bounds=="string"?e.query(s.bounds):yl(s.bounds)?s.bounds:null,h={bounds:(!l&&s.bounds&&!yl(s.bounds)?s.bounds:void 0)??(l?fd(r,l):void 0)};let u=null;const d=()=>{u?.kill(),u=null},f=g=>{const p=s.inertia===!0?{}:s.inertia,b=p.friction??(p.resistance!==void 0?fl(p.resistance):4),v=a(),k=h.bounds??{};let w,S;const x=p.end;if(Array.isArray(x)){const E=Qs({from:v.x,velocity:o==="y"?0:g.x,friction:b}),T=Qs({from:v.y,velocity:o==="x"?0:g.y,friction:b});let A=x[0];for(const P of x)Math.hypot(P.x-E,P.y-T)<Math.hypot(A.x-E,A.y-T)&&(A=P);A&&(w=[A.x],S=[A.y])}else typeof x=="number"?(w=x,S=x):x&&(w=gd(x.x),S=gd(x.y));const M={};o!=="y"&&(M.x={velocity:g.x,friction:b,min:k.minX,max:k.maxX,end:w}),o!=="x"&&(M.y={velocity:g.y,friction:b,min:k.minY,max:k.maxY,end:S}),u=t.to(r,{inertia:M,onComplete:()=>s.onThrowComplete?.()})},m=new pl({target:r,axis:o,snap:s.snap,get bounds(){return h.bounds},getPosition:a,onPress:()=>{d(),l&&(h.bounds=fd(r,l)),s.onPress?.()},onDrag:g=>{e.apply(i,o==="x"?{x:g.x}:o==="y"?{y:g.y}:{x:g.x,y:g.y}),s.onDrag?.(g)},onRelease:()=>{const g=m.velocity;s.onRelease?.(g),s.inertia&&f(g)}});return m.start(),{draggable:m,get position(){return a()},get rotation(){const g=e.appliedValue(i,"rotate");return typeof g=="number"?g:0},destroy(){d(),m.destroy()}}}function Nk(t,e,n,s,i){const r=typeof i.bounds=="object"&&i.bounds!==null&&!yl(i.bounds)?i.bounds:{},o=()=>{const k=e.appliedValue(n,"rotate");return typeof k=="number"?k:0},a=k=>Math.min(r.maxRotation??1/0,Math.max(r.minRotation??-1/0,k));let l=null,c=!1,h,u={x:0,y:0},d=0,f=0,m=[];const g=k=>Math.atan2(k.clientY-u.y,k.clientX-u.x)*180/Math.PI,p=k=>{if(c)return;l?.kill(),l=null,c=!0,h=k.pointerId,s.setPointerCapture?.(k.pointerId);const w=s.getBoundingClientRect();u={x:w.left+w.width/2,y:w.top+w.height/2},d=g(k),f=o(),m=[{time:performance.now(),rotation:f}],i.onPress?.()},b=k=>{if(!c||k.pointerId!==h)return;const w=g(k);let S=w-d;S>180&&(S-=360),S<-180&&(S+=360),d=w,f+=S;let x=a(f);i.snap&&(x=a(Math.round(x/i.snap)*i.snap)),e.apply(n,{rotate:x});const M=performance.now();for(m.push({time:M,rotation:x});m.length>2&&M-m[0].time>100;)m.shift();const E={x:0,y:0};i.onDrag?.(E)},v=k=>{if(!c||k.pointerId!==h)return;c=!1;const w=m[0],S=m[m.length-1],x=w&&S?(S.time-w.time)/1e3:0,M=x>0?(S.rotation-w.rotation)/x:0;if(i.onRelease?.({x:M,y:0}),!i.inertia)return;const E=i.inertia===!0?{}:i.inertia,T=E.friction??(E.resistance!==void 0?fl(E.resistance):4),A=typeof E.end=="number"||Array.isArray(E.end)?E.end:void 0;l=t.to(s,{inertia:{rotate:{velocity:M,friction:T,min:r.minRotation,max:r.maxRotation,end:Array.isArray(A)?A.filter(P=>typeof P=="number"):A}},onComplete:()=>i.onThrowComplete?.()})};return s.addEventListener("pointerdown",p),s.addEventListener("pointermove",b),s.addEventListener("pointerup",v),s.addEventListener("pointercancel",v),s.style.touchAction="none",{draggable:void 0,position:{x:0,y:0},get rotation(){return o()},destroy(){l?.kill(),s.removeEventListener("pointerdown",p),s.removeEventListener("pointermove",b),s.removeEventListener("pointerup",v),s.removeEventListener("pointercancel",v)}}}const Wk={opacity:0,scale:.6};function Dk(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 md(t){const e=Hr(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 bl(t,e){const s=t.resolveTargets(e).map(o=>t.elementFor(o)).filter(o=>!!o),i=new Map,r=new Map;for(const o of s){const a=Dk(o);i.set(o,a);const l=pd(o);a&&l!==void 0&&!r.has(l)&&r.set(l,{element:o,box:a})}return{elements:s,boxes:i,ids:r}}const wl=new WeakMap;function kl(t,e,n,s={}){const i=s.duration??.6,r=s.ease??"power2.inOut",o=s.stagger??0,a=s.scale!==!1,l=s.enter===void 0?Wk:s.enter,c=new Set(n.elements);if(s.targets!==void 0)for(const f of t.resolveTargets(s.targets)){const m=t.elementFor(f);m&&c.add(m)}const h=[...c].sort((f,m)=>f===m?0:f.compareDocumentPosition(m)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1),u=e({onComplete:s.onComplete});let d=0;for(const f of h){const m=md(f);if(!m)continue;let g=n.boxes.get(f)??null,p;const b=pd(f),v=!g&&b!==void 0?n.ids.get(b):void 0;v&&v.element!==f&&(g=v.box,p=v.element);const[k]=t.resolveTargets(f);wl.get(f)?.timeline.removeTracks({target:k});const w=d*o;if(!g){if(l===!1)continue;u.fromTo(f,{x:0,y:0,scaleX:1,scaleY:1,...l},{...yd(l),x:0,y:0,scaleX:1,scaleY:1,duration:i,ease:r,delay:w},0),wl.set(f,u),d++;continue}const S=g.cx-m.cx,x=g.cy-m.cy,M=a?g.width/m.width:1,E=a?g.height/m.height:1;if(!(Math.abs(S)>.5||Math.abs(x)>.5||Math.abs(M-1)>.001||Math.abs(E-1)>.001)){const P=(I,O)=>{const _=t.appliedValue(k,I);return typeof _=="number"&&Math.abs(_-O)>1e-6};(P("x",0)||P("y",0)||P("scaleX",1)||P("scaleY",1))&&u.set(f,{x:0,y:0,scaleX:1,scaleY:1},0);continue}const A=s.fade===!0&&p!==void 0;u.fromTo(f,{x:S,y:x,scaleX:M,scaleY:E,...A&&{opacity:0}},{x:0,y:0,scaleX:1,scaleY:1,...A&&{opacity:1},duration:i,ease:r,delay:w},0),A&&p&&md(p)&&u.fromTo(p,{opacity:1},{opacity:0,duration:i,ease:r,delay:w},0),wl.set(f,u),d++}return u}function pd(t){return t.dataset?.flipId}function yd(t){const e={};for(const n of Object.keys(t))e[n]=n==="opacity"||n.startsWith("scale")?1:0;return e}function Bk(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,r=t.map(g=>({element:g,html:g.innerHTML,ariaLabel:g.getAttribute("aria-label")}));let o={chars:[],words:[],lines:[],masks:[]},a,l,c=!1;const h=()=>{for(const{element:g,html:p,ariaLabel:b}of r)g.innerHTML=p,b===null?g.removeAttribute("aria-label"):g.setAttribute("aria-label",b)},u=()=>{a&&(a.revert?a.revert():a.kill?.(),a=void 0)},d=()=>{const g={chars:[],words:[],lines:[],masks:[]};for(const{element:p}of r){const b=(p.textContent??"").replace(/\s+/g," ").trim(),v=zk(p,s.words),k=n.has("chars")?v.flatMap(x=>qk(x,s.chars)):[],w=n.has("lines")?Kk(p,v,s.lines):[];if(i){!p.hasAttribute("aria-label")&&b&&p.setAttribute("aria-label",b);for(const x of v)x.setAttribute("aria-hidden","true")}if(n.has("words"))g.words.push(...v);else for(const x of v)x.removeAttribute("class");g.chars.push(...k),g.lines.push(...w);const S=e.mask==="lines"?w:e.mask==="words"?v:e.mask==="chars"?k:[];for(const x of S)g.masks.push(Yk(x,`${s[e.mask]}-mask`))}o=g},f={elements:t,get chars(){return o.chars},get words(){return o.words},get lines(){return o.lines},get masks(){return o.masks},split(){c||(u(),h(),d(),a=e.onSplit?.(f))},revert(){c=!0,l?.disconnect(),u(),h()}};d(),a=e.onSplit?.(f),e.autoSplit&&m();function m(){const g=new Map;let p=!1;const b=()=>{if(p)return;p=!0;const k=()=>{p=!1,f.split()};typeof requestAnimationFrame=="function"?requestAnimationFrame(k):setTimeout(k,0)};if(typeof ResizeObserver=="function"){l=new ResizeObserver(k=>{let w=!1;for(const S of k){const x=Math.round(S.contentRect.width),M=g.get(S.target);g.set(S.target,x),M!==void 0&&M!==x&&(w=!0)}w&&b()});for(const k of t)l.observe(k)}const v=t[0]?.ownerDocument?.fonts;v&&v.status!=="loaded"&&v.ready.then(()=>b())}return f}function zk(t,e){const n=t.ownerDocument,s=[],i=n.createTreeWalker(t,4),r=[];for(let o=i.nextNode();o;o=i.nextNode())r.push(o);for(const o of r){const a=o.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)}o.replaceWith(l)}return s}function qk(t,e){const n=t.ownerDocument,s=jk(t.textContent??"").map(i=>{const r=n.createElement("span");return r.className=e,r.style.display="inline-block",r.textContent=i,r});return t.replaceChildren(...s),s}function jk(t){const e=Intl.Segmenter;return e?Array.from(new e(void 0,{granularity:"grapheme"}).segment(t),n=>n.segment):Array.from(t)}function Kk(t,e,n){const s=t.ownerDocument,i=new Map(e.map(m=>[m,m.getBoundingClientRect()])),r=[],o=m=>{for(const g of Array.from(m.childNodes))g.nodeType===3||i.has(g)||g.tagName==="BR"?r.push(g):o(g)};o(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 m of r){if(m.tagName==="BR"){u=!0;continue}const g=i.get(m);if(g&&(!l||u||g.top>c+h)&&(f(),c=g.top,h=g.height/2,u=!1),!l)continue;const p=[];for(let k=m.parentNode;k&&k!==t;k=k.parentNode)p.unshift(k);let b=0;for(;b<d.length&&b<p.length&&d[b].original===p[b];)b++;d.length=b;let v=b===0?l:d[b-1].clone;for(const k of p.slice(b)){const w=k.cloneNode(!1);v.appendChild(w),d.push({original:k,clone:w}),v=w}v.appendChild(m)}return t.replaceChildren(...a),a}function Yk(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 bd={top:0,left:0,start:0,center:.5,centre:.5,middle:.5,bottom:1,right:1,end:1};function vl(t){const e=t.trim().toLowerCase();if(e in bd)return bd[e];if(e.endsWith("%")){const n=Number.parseFloat(e.slice(0,-1));return Number.isNaN(n)?void 0:n/100}}function Ml(t){if(typeof t=="number")return{elementFraction:0,viewportFraction:0,offsetPx:0,absolutePx:t};let e=0;const s=t.replace(/([+-])=\s*(-?[\d.]+)/g,(o,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?vl(s[0]):void 0,r=s[1]!==void 0?vl(s[1]):void 0;return{elementFraction:i??0,viewportFraction:r??0,offsetPx:e}}function cs(t,e,n){const s=Ml(n),i=s.absolutePx!==void 0?t.top+s.absolutePx:t.top+t.height*s.elementFraction,r=e*s.viewportFraction;return i-r+s.offsetPx}function Xk(t,e,n,s){const i=cs(t,e,n),o=cs(t,e,s)-i;return o<=0?i<=0?1:0:Sl(-i/o)}function Sl(t){return t<0?0:t>1?1:t===0?0:t}function wd(t,e,n,s){if(n<=0)return e;const i=1-Math.exp(-(s/1e3)/n);return t+(e-t)*i}function Tl(t,e,n,s,i){const r=h=>cs({top:t+i(h),bottom:t+i(h)+e,height:e},n,s),o=r(0),a=r(1);if(Math.sign(o)===Math.sign(a)||o===0||a===0)return o===0?0:a===0?1:Math.abs(o)<Math.abs(a)?0:1;let l=0,c=1;for(let h=0;h<40;h++){const u=(l+c)/2;Math.sign(r(u))===Math.sign(o)?l=u:c=u}return(l+c)/2}class kd{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 Gk(t){const e=new kd(t);return e.start(),e}class vd{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 Uk=.15;function Md(t){return typeof t=="object"&&!Array.isArray(t)?t:{snapTo:t}}function Sd(t,e,n){const s=Fr(t+e*Uk);if(typeof n=="function")return Fr(n(s));if(typeof n=="number")return n<=0?t:Fr(Math.round(s/n)*n);if(n.length===0)return t;let i=n[0];for(const r of n)Math.abs(r-s)<Math.abs(i-s)&&(i=r);return Fr(i)}function Td(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 Ed{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=ti,r){if(this.cancel(),typeof requestAnimationFrame>"u"||s<=0){this.write(n),r?.();return}for(const l of this.cancelEvents)this.eventTarget?.addEventListener(l,this.onInterrupt,{passive:!0});let o=null;const a=l=>{o??=l;const c=Math.min(1,(l-o)/(s*1e3));this.write(e+(n-e)*i(c)),c<1?this.rafId=requestAnimationFrame(a):(this.rafId=null,this.detach(),r?.())};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 Fr(t){return Math.max(0,Math.min(1,t))}class Ad{options;scroller;nodes=[];scrollerStart;scrollerEnd;start;end;constructor(e,n,s){this.options=s===!0?{}:s,this.scroller=n;const{startColor:i="#3ecf7a",endColor:r="#ff5a5a",id:o}=this.options,a=o?`${o} `:"",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",r,!n),this.start=l("start",i,!1),this.end=l("end",r,!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 Vk=120,hs=[],us=new Set;let El=!1;const Jk=()=>{El||us.size===0||(El=!0,queueMicrotask(()=>{El=!1;for(const t of us)t.afterRefresh()}))},xd=()=>{for(const t of us)t.beforeRefresh();for(const t of hs)t.refresh();for(const t of us)t.afterRefresh()};let ds={width:0,height:0};const Pd=()=>{const t=window.innerWidth,e=window.innerHeight,n=t===ds.width&&e!==ds.height,s=Math.abs(e-ds.height)<ds.height*.25,i=typeof navigator<"u"&&(navigator.maxTouchPoints??0)>0;n&&s&&i||(ds={width:t,height:e},xd())};class mi{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 Ed(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 vd(e,{axis:this.options.horizontal?"x":"y",spacing:this.options.pinSpacing!==!1})),this.options.markers&&!this.options.horizontal&&typeof document<"u"&&(this.markers=new Ad(document,this.options.scroller??null,this.options.markers)),this.scrollTarget()?.addEventListener("scroll",this.onScroll,{passive:!0}),hs.length===0&&typeof window<"u"&&(ds={width:window.innerWidth,height:window.innerHeight},window.addEventListener("resize",Pd,{passive:!0})),hs.push(this),this.refresh()}stop(){this.running&&(this.running=!1,this.scrollTarget()?.removeEventListener("scroll",this.onScroll),hs.splice(hs.indexOf(this),1),hs.length===0&&typeof window<"u"&&window.removeEventListener("resize",Pd),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(){xd()}static onRefresh(e){return us.add(e),()=>us.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+cs(n,s,pi(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,Jk()}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?Sl((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=pi(this.options.end)??"bottom top",r=typeof i=="string"?i.trim().match(/^\+=\s*(-?[\d.]+)\s*(%|px)?$/):null;if(r){const o=Number.parseFloat(r[1]);return this.startPx+(r[2]==="%"?n*o/100:o)}return s+cs(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()},Vk))}fireBoundaryCallbacks(e,n){if(e===n)return;const{onEnter:s,onLeave:i,onEnterBack:r,onLeaveBack:o}=this.options;e==="before"?(s?.(),n==="after"&&i?.()):e==="after"?(r?.(),n==="before"&&o?.()):n==="after"?i?.():o?.()}scheduleSnap(){const e=this.options.snap;if(e===void 0||this.snapper.active)return;const n=Md(e),s=()=>{this.snapTimer=null;const i=this.endPx-this.startPx,r=this.scrollPosition();if(!this.running||i<=0||r<=this.startPx||r>=this.endPx)return;const o=(r-this.startPx)/i,a=this.startPx+Sd(o,this.releaseVelocity/i,n.snapTo)*i;Math.abs(a-r)<1||this.snapper.animate(r,a,Td(n,a-r,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,r=this.options.scroller?this.options.scroller.clientWidth:typeof window<"u"?window.innerWidth:0,o=s.left-i-e.shiftAt(e.progress()),{start:a,end:l}=e.range(),c=f=>a+f*(l-a),h=Tl(o,s.width,r,pi(this.options.start)??"left right",e.shiftAt);this.startPx=c(h);const u=pi(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(Tl(o,s.width,r,u,e.shiftAt)),this.markerGeometry=null}markersFor(e){const n=(r,o)=>{const a=pi(r)??o;if(typeof a=="number")return 0;if(/^\s*\+=/.test(a))return;const l=Ml(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=wd(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,r=n?e.width??0:e.height,o=this.options.scroller;if(o&&typeof o.getBoundingClientRect=="function"){const a=o.getBoundingClientRect(),l=n?a.left:a.top;return{top:s-l,bottom:i-l,height:r}}return{top:s,bottom:i,height:r}}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 pi(t){return typeof t=="function"?t():t}function Zk(t){const e=new mi(t);return e.start(),e}const Al=new Set,Qk=16,$d=.5,t5=2;class xl{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),Al.add(this),this.stopListening=mi.onRefresh({beforeRefresh:()=>this.rest(),afterRefresh:()=>this.refresh()}),this.refresh(),this}static refreshAll(){for(const e of Al)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),Al.delete(this),this.stopListening?.(),this.stopListening=null,this.cancelFrame(),this.journey=null,this}destroy(){this.stop();for(const e of this.effects)Pl(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),r=this.reduced?0:n.duration??Math.min(1.2,Math.max(.4,i/2500));if(r<=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:r*1e3,ease:n.ease??ti,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(),r=this.options.scroller?.getBoundingClientRect().top??0;for(const o of n.querySelectorAll(e)){const a=Number.parseFloat(o.dataset.speed??""),l=Number.parseFloat(o.dataset.lag??""),c=o.getBoundingClientRect(),h=c.top-r+s;this.effects.push({element:o,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:o.style.getPropertyValue("translate")})}}this.current=this.target=this.clamp(this.position()),this.applyEffects(0)}rest(){for(const e of this.effects)Pl(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?Qk: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)<=t5||(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 r=this.journey;r.elapsed+=n;const o=Math.min(1,r.elapsed/r.ms);this.current=r.from+(r.to-r.from)*r.ease(o),o>=1&&(this.journey=null)}else if(this.current!==this.target){const r=(this.options.smooth??.8)*1e3/3;this.current+=(this.target-this.current)*(1-Math.exp(-n/r)),Math.abs(this.target-this.current)<$d&&(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 r=0;if(i.speed!==void 0&&(r+=(s-i.centre)*(1-i.speed)),i.lag!==void 0){const o=i.lag*1e3/3;i.lagged=e===0?s:i.lagged+(s-i.lagged)*(1-Math.exp(-e/o)),Math.abs(s-i.lagged)<$d?i.lagged=s:n=!0,r+=s-i.lagged}Pl(i.element,r===0?i.saved:`0 ${e5(r)}px`),i.shift=r}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,r=this.effects.find(o=>o.element===s)?.shift??0;return s.getBoundingClientRect().top-i+this.position()-r}}function Pl(t,e){e?t.style.setProperty("translate",e):t.style.removeProperty("translate")}function e5(t){return Math.round(t*100)/100}function n5(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 $l(t,e,n,s,i=()=>{}){const r=f=>typeof f=="string"?t.query(f)??void 0:f,o=r(e.trigger)??s;if(!o){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,m)=>()=>{m?.(),n&&!a&&n5(n,l[f]??"none"),e.once&&f===0&&queueMicrotask(()=>h.destroy())},d=e.containerAnimation?r5(t,e.containerAnimation,o,i):void 0;return h=new mi({trigger:o,start:e.start,end:e.end,scrub:a===!1?void 0:a,pin:e.pin===!0?!0:r(e.pin),scroller:r(e.scroller),horizontal:e.horizontal,pinSpacing:e.pinSpacing,onRefresh:e.invalidateOnRefresh&&n?.invalidate?()=>n.invalidate():void 0,snap:e.snap===void 0?void 0:s5(e.snap,n),markers:e.markers,container:d,onUpdate:(f,m)=>{if(n&&a!==!1&&n.progress(f),e.onUpdate){const g=f<c||m<0?-1:1;e.onUpdate({progress:f,velocity:m,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 s5(t,e){const n=i=>i==="labels"?r=>i5(r,e?.labelProgresses?.()??[]):i;if(typeof t!="object"||Array.isArray(t))return n(t);const s=t.ease?di(t.ease):void 0;return{snapTo:n(t.snapTo),duration:t.duration,delay:t.delay,ease:s?s.fn??Dt(s.easing):void 0}}function i5(t,e){return e.reduce((n,s)=>Math.abs(s-t)<Math.abs(n-t)?s:n,e[0]??t)}function r5(t,e,n,s){const i=()=>e.timeline.getTracks({property:"x"}).map(r=>r.target).filter(r=>{const o=t.elementFor(r);return!!o&&o!==n&&o.contains(n)});return i().length===0&&s("gsap-compat: containerAnimation does not move an ancestor of the trigger along x"),{range:()=>{const r=e.scrollTrigger;return r||s("gsap-compat: containerAnimation needs its own scrollTrigger (created before this one)"),{start:r?.startOffset??0,end:r?.endOffset??0}},progress:()=>e.progress(),shiftAt:r=>{const o=e.timeline.getStateAtTime(r*e.timeline.duration);let a=0;for(const l of i()){const c=o.values.get(l)?.get("x");typeof c=="number"&&(a+=c)}return a}}}class Id{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 o5{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[r,o]of Object.entries(i)){const a=window.matchMedia(o);s.queries.set(r,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[o,a]of e.queries)n[o]=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 r=new Id(this.host,this.scope);r.conditions=n,r.add(()=>e.setup(r)),e.context=r}}class a5{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:r}=this.canvas,o=(this.options.fit??"cover")==="cover"?Math.max(i/s.naturalWidth,r/s.naturalHeight):Math.min(i/s.naturalWidth,r/s.naturalHeight),a=s.naturalWidth*o,l=s.naturalHeight*o;this.context.clearRect(0,0,i,r),this.context.drawImage(s,(i-a)/2,(r-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 r=Math.round(this.current);(Math.abs(e-r)<Math.abs(this.drawn-r)||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 l5={opacity:0,y:-16},c5={opacity:0,y:16};async function h5(t,e,n,s){const i=e.collector?.scope??e.root,r=i.ownerDocument??i,o=()=>s.shared?[...i.querySelectorAll(s.shared)]:[];if(s.native&&typeof r.startViewTransition=="function")return u5(r,s,o);const a=s.duration??.35,l=s.ease??"power2.inOut",c=p=>new Promise(b=>{p(b)||b()}),h=o(),u=h.length?bl(e,h):void 0,d=s.from!==void 0?Od(e,s.from,s.shared):[];if(d.length&&s.leave!==!1){const p=s.leave??l5;await c(b=>t.to(d,{...p,duration:a,ease:l,onComplete:b}))}await s.update();const f=[],m=typeof s.to=="function"?s.to():s.to,g=m!==void 0?Od(e,m,s.shared):[];if(g.length&&s.enter!==!1){const p=s.enter??c5;f.push(c(b=>t.fromTo(g,p,{...yd(p),duration:a,ease:l,onComplete:b})))}if(u){const p=o().filter(b=>!h.includes(b));p.length&&f.push(c(b=>kl(e,n,u,{targets:p,duration:a*1.4,ease:l,enter:!1,onComplete:b})))}await Promise.all(f)}function Od(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(r=>!r.matches(n)&&!r.querySelector(n))):s}async function u5(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 r=[];await t.startViewTransition(async()=>{i.forEach(a=>s(a,!1)),await e.update(),r=n(),r.forEach(a=>s(a,!0))}).finished,r.forEach(a=>s(a,!1))}const Cd={create:(t,e)=>cl(t,Ou(e))},_d={create:(t,e)=>cl(t,{fn:Cu(e)})},Rd={create:(t,e)=>cl(t,{fn:_u(e)})},d5=new Set(["keyframes","duration","delay","ease","easeEach","stagger","repeat","repeatDelay","yoyo","repeatRefresh","paused","id","onStart","onUpdate","onComplete","onRepeat","onReverseComplete","scrollTrigger"]),Hd=.5,f5="power1.inOut";function g5(t){return t.keyframes!==void 0&&t.keyframes!==null}function m5(t){const e=t.keyframes,n={};for(const[c,h]of Object.entries(t))d5.has(c)||(n[c]=h);if(Array.isArray(e))return e.map(c=>({...n,...c,duration:c.duration??t.duration??Hd}));const s=Object.entries(e),i=t.duration??Hd,r=e.easeEach??t.easeEach??f5;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 m=Math.max(0,d-u);h.push({...n,ease:r,...f,duration:m*i}),u=d}return h}const o=s.filter(([c,h])=>c!=="easeEach"&&Array.isArray(h)),a=Math.max(0,...o.map(([,c])=>c.length)),l=[];for(let c=0;c<a;c++){const h={...n,ease:r,duration:i/a};for(const[u,d]of o)c<d.length&&(h[u]=d[c]);l.push(h)}return l}function Fd(t,e,n,s={}){const i=e.collector?.scope??e.root,r=typeof s.scroller=="string"?i.querySelector(s.scroller):s.scroller??null,o={x:r?r.scrollLeft:window.scrollX,y:r?r.scrollTop:window.scrollY},a={x:r?r.scrollWidth-r.clientWidth:document.documentElement.scrollWidth-window.innerWidth,y:r?r.scrollHeight-r.clientHeight:document.documentElement.scrollHeight-window.innerHeight},l=(v,k)=>{if(k===void 0)return o[v];if(typeof k=="number")return k;if(k==="max")return a[v];const w=typeof k=="string"?i.querySelector(k):k;if(!w)return o[v];const S=w.getBoundingClientRect(),x=r?.getBoundingClientRect(),M=(v==="x"?s.offsetX:s.offsetY)??s.offset??0;return v==="x"?S.left-(x?.left??0)+o.x-M:S.top-(x?.top??0)+o.y-M},c=typeof n=="object"&&n!==null&&!("nodeType"in n)?{x:l("x",n.x),y:l("y",n.y)}:{x:o.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={...o},d=()=>{r?(r.scrollLeft=u.x,r.scrollTop=u.y):window.scrollTo({left:u.x,top:u.y,behavior:"instant"})},f=["wheel","touchstart","keydown"],m=r??window,g=()=>{b.kill(),p()},p=()=>{for(const v of f)m.removeEventListener(v,g)},b=t.to(u,{x:h.x,y:h.y,duration:s.duration??1,ease:s.ease??"power2.inOut",onStart:s.onStart,onUpdate:()=>{d(),s.onUpdate?.()},onComplete:()=>{p(),s.onComplete?.()}});if(s.autoKill!==!1)for(const v of f)m.addEventListener(v,g,{passive:!0});return b}function p5(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:r=.1,batchMax:o,onEnter:a,onLeave:l,onEnterBack:c,onLeaveBack:h,...u}=n,d={onEnter:a,onLeave:l,onEnterBack:c,onLeaveBack:h},f={onEnter:[],onLeave:[],onEnterBack:[],onLeaveBack:[]},m={},g=b=>{m[b]!==void 0&&clearTimeout(m[b]),m[b]=void 0;const v=f[b].splice(0);v.length>0&&d[b]?.(v)},p=(b,v)=>{if(d[b]){if(f[b].push(v),o!==void 0&&f[b].length>=o)return g(b);m[b]===void 0&&(m[b]=setTimeout(()=>g(b),r*1e3))}};return i.map(b=>$l(t,{...u,trigger:b,onEnter:()=>p("onEnter",b),onLeave:()=>p("onLeave",b),onEnterBack:()=>p("onEnterBack",b),onLeaveBack:()=>p("onLeaveBack",b)})).filter(b=>b!==void 0)}class _e{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 Cn({...s,startValue:(i,r)=>{const o=e.objectFor(i);if(o)return w5(o[r]);const a=e.appliedValue(i,r);if(a!==void 0)return a;if(r==="d")return ad(e.elementFor(i))??void 0;if(r==="text")return e.elementFor(i)?.textContent??void 0;if(r==="strokeDasharray"||r==="strokeDashoffset"){const l=Bd(e.elementFor(i));if(l!==void 0)return r==="strokeDasharray"?[l,l]:0}},startVelocity:(i,r)=>e.velocityOf(i,r),layoutColumns:i=>Dd(i.map(r=>e.elementFor(r))),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=$l(e,i,this,this.firstElement,r=>s.onWarning?.(r)))})}this.autoplayPending&&queueMicrotask(()=>{this.autoplayPending&&this.play()})}get timeline(){return this.compat.timeline}get scrollTrigger(){return this.scrollDriver}to(e,n,s){return g5(n)?this.record(()=>this.keyframed(e,n,s)):this.record(()=>this.tween(e,[n],s,([i],r,o)=>this.compat.to(r,i,o)))}from(e,n,s){return this.record(()=>this.tween(e,[n],s,([i],r,o)=>this.compat.from(r,i,o)))}fromTo(e,n,s,i){return this.record(()=>this.tween(e,[n,s],i,([r,o],a,l)=>this.compat.fromTo(a,r,o,l)))}set(e,n,s){return this.record(()=>this.tween(e,[n],s,([i],r,o)=>this.compat.set(r,i,o)))}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,r=Math.max(0,Math.min(this.timeline.duration,this.compat.timeOf(n))),o={time:i},a=s.duration??Math.abs(r-i)/1e3/(this.timeScale()||1),l=new _e(this.stage,{onStart:s.onStart,onComplete:s.onComplete});return l.to(o,{time:r,duration:a,ease:s.ease??"none",onUpdate:()=>{this.moveTo(o.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 r=this.options.yoyo===!0;n&&!r&&i.iteration>s.iteration&&(this.playhead={time:0,iteration:i.iteration,direction:"forward",fresh:!0},this.waitingToWrap=!0);const o=this.runCrossings(s,i,n);if(this.options.onUpdate?.(),this.finishedThisFrame&&!o){this.finishedThisFrame=!1;const a=e.currentTime===0&&e.direction==="reverse";!this.scrollDriver&&!r&&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:r,passes:o}=Ja(i.map(a=>a.time),e,n,{duration:this.timeline.duration,alternate:this.options.yoyo===!0,holding:s});for(const a of r){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)o.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 r=this.resolve(e);if(!r)return;const{onStart:o,onUpdate:a,onComplete:l}=n[n.length-1];if(o||a||l){let c=1/0,h=-1/0;const u=(d,f,m)=>{i(d,f,m),c=Math.min(c,this.compat.lastStart),h=Math.max(h,this.compat.lastEnd)};if(this.buildTween(r,n,s,u),c===1/0)return;o&&this.events.push({time:c,direction:"forward",run:o}),a&&this.ranges.push({start:c,end:h,run:a}),l&&this.events.push({time:h,direction:"forward",run:l});return}this.buildTween(r,n,s,i)}keyframed(e,n,s){const i=this.resolve(e);if(!i)return;const r=m5(n);if(r.length===0)return;const o=i.length>1?dl(n.stagger,this.staggerContext(i)):void 0,a=i.map(p=>this.targetFor(p)).filter(p=>p!==void 0),l=o?a.map(p=>[p]):[a],c=o?yr(i.length,o).map(p=>p/1e3):[0],h=this.compat.timeOf(s)/1e3+Rr(n.delay,0)/1e3;let u=1/0,d=-1/0;if(l.forEach((p,b)=>{r.forEach((v,k)=>{const w=k===0?h+c[b]:">";this.tween(p,[v],w,([S],x,M)=>this.compat.to(x,S,M)),u=Math.min(u,this.compat.lastStart),d=Math.max(d,this.compat.lastEnd)})}),u===1/0)return;const{onStart:f,onUpdate:m,onComplete:g}=n;f&&this.events.push({time:u,direction:"forward",run:f}),m&&this.ranges.push({start:u,end:d,run:m}),g&&this.events.push({time:d,direction:"forward",run:g})}staggerContext(e){return{count:e.length,columnsFromLayout:()=>Dd(e.map(n=>this.stage.elementFor(n))),random:()=>this.stage.utils.random(0,1)}}buildTween(e,n,s,i){const r=e.map(d=>this.targetFor(d));if(!(e.length>1&&(n.some(b5)||e.some(d=>this.stage.objectFor(d)!==void 0)))){const d=this.targetFor(e[0]);i(n.map(f=>this.prepare(Wd(f,0,d,this.stage.utils,r),e)),e,s);return}const a=n.length-1,{stagger:l,...c}=n[a],h=dl(l,this.staggerContext(e)),u=h?yr(e.length,h).map(d=>d/1e3):e.map(()=>0);e.forEach((d,f)=>{const m=f===0?Rr(c.delay,0)/1e3+u[0]:0,g=f===0?0:u[f]-u[f-1],p=f===0?s:`<${g<0?"-":"+"}${Math.abs(g).toFixed(6)}`,v=n.map((k,w)=>w===a?{...c,delay:m}:k).map(k=>this.prepare(Wd(k,f,this.targetFor(d),this.stage.utils,r),[d]));i(v,[d],p)})}targetFor(e){return this.stage.elementFor(e)??this.stage.objectFor(e)}prepare(e,n){const s=o=>this.options.onWarning?.(o),i=o=>this.stage.query(o);let r=e;if(e.motionPath!==void 0){const o=Ik(e.motionPath,{query:i,targets:n.map(a=>this.stage.elementFor(a)).filter(a=>!!a),warn:s});r={...r,motionPath:o}}if(e.morphSVG!==void 0){const o=Ok(e.morphSVG,i,s),{morphSVG:a,...l}=r;r=o?{...r,morphSVG:o}:l}if(e.drawSVG!==void 0){const o=Bd(this.stage.elementFor(n[0]));if(o===void 0){s("gsap-compat: drawSVG needs an SVG shape with a stroke (path, line, circle…)");const{drawSVG:a,...l}=r;r=l}else r=sk(r,o)}return r}resolve(e){const n=this.stage.resolveTargets(e);if(n.length===0){this.options.onWarning?.(`gsap-compat: no elements found for target ${k5(e)}`);return}return this.firstElement??=n.map(s=>this.stage.elementFor(s)).find(s=>s!==void 0),n}}function Ld(t=new sd){const e=r=>{const{config:o}=_r(r);return new _e(t,{repeat:o.repeat,yoyo:o.yoyo,repeatDelay:o.repeatDelay,paused:o.paused,onStart:o.onStart,onUpdate:o.onUpdate,onComplete:o.onComplete,onRepeat:o.onRepeat,onReverseComplete:o.onReverseComplete,repeatRefresh:o.repeatRefresh,scrollTrigger:o.scrollTrigger})},n=r=>{const{onStart:o,onUpdate:a,onComplete:l,onRepeat:c,onReverseComplete:h,repeatRefresh:u,...d}=r;return d},s=r=>(r&&t.collector?.track(r),r),i={stage:t,ticker:t.ticker,utils:t.utils,getProperty:(r,o)=>{const[a]=t.resolveTargets(r);if(a===void 0)return;const l=t.objectFor(a);return l?l[o]:t.appliedValue(a,o)??Zu(o)},scrollTrigger:r=>s($l(t,r)),scrollBatch:(r,o)=>p5(t,r,o).map(a=>s(a)),scrollTo:(r,o)=>Fd(i,t,r,o),refreshScroll:()=>{mi.refreshAll(),xl.refreshAll()},smoothScroll:(r={})=>{const o=typeof r.scroller=="string"?(t.collector?.scope??t.root).querySelector(r.scroller):r.scroller;return s(new xl({...r,scroller:o}).start())},context:(r,o)=>{const a=new Id(t,o);return r&&a.add(()=>r(a)),a},matchMedia:r=>new o5(t,r),customEase:Cd.create,customBounce:_d.create,customWiggle:Rd.create,pageTransition:r=>h5(i,t,o=>new _e(t,o),r),imageSequence:(r,o)=>{const a=typeof r=="string"?(t.collector?.scope??t.root).querySelector(r):r;if(!(a instanceof HTMLCanvasElement))throw new Error(`gsap-compat: imageSequence needs a <canvas>, got ${String(r)}`);return s(new a5(a,o))},quickTo:(r,o,a={})=>{const l=new _e(t,{paused:!0}),[c]=t.resolveTargets(r);return Object.assign(u=>{if(!c)return;const d=a.spring!==void 0?t.velocityOf(c,o)??0:0;l.compat.reset(),l.compat.to(c,{[o]:u,duration:a.duration??.4,ease:a.ease??"power3.out",...a.spring!==void 0&&{spring:y5(a.spring,o,d)}}),l.timeline.stop(),l.timeline.play(),t.activate(l.timeline)},{tween:l,kill:()=>l.kill()})},timeline:r=>new _e(t,r),to:(r,o)=>{if(o.scrollTo!==void 0){const{scrollTo:a,...l}=o,c=typeof a=="object"&&a!==null&&!("nodeType"in a)?a:{},h=typeof r!="string"&&r!==window&&r.nodeType===1;return Fd(i,t,a,{...l,offsetX:c.offsetX,offsetY:c.offsetY,scroller:h?r:void 0})}return e(o).to(r,n(o))},from:(r,o)=>e(o).from(r,n(o)),fromTo:(r,o,a)=>e(a).fromTo(r,o,n(a)),set:(r,o)=>e(o).set(r,n(o)),delayedCall:(r,o,a)=>new _e(t).call(o,a,r),killTweensOf:(r,o)=>{const a=t.resolveTargets(r),l=typeof o=="string"?o.split(",").map(c=>c.trim()).filter(Boolean):o;for(const c of[...t.liveTimelines])c.killTweensOf(a,l)},convertToPath:r=>_k(r,t.root),splitText:(r,o)=>{const a=t.collector?.scope??t.root,l=typeof r=="string"?Array.from(a.querySelectorAll(r)):"nodeType"in r?[r]:Array.from(r);return s(Bk(l,o))},draggable:(r,o)=>s(Lk(i,t,r,o)),getFlipState:r=>bl(t,r),flipFrom:(r,o)=>kl(t,a=>new _e(t,a),r,o),flip:(r,o,a)=>{const l=bl(t,r);return o(),kl(t,c=>new _e(t,c),l,{targets:r,...a})}};return i}const le=Ld();function y5(t,e,n){return t===!0?{velocity:{[e]:n}}:typeof t=="string"?{preset:t,velocity:{[e]:n}}:{...t,velocity:{[e]:n}}}function b5(t){return t.morphSVG!==void 0||t.drawSVG!==void 0||t.text!==void 0||t.scrambleText!==void 0||Nd(t)}function Nd(t){return Object.entries(t).some(([e,n])=>(typeof n=="function"||Vu(n))&&!ul.has(e))}function Wd(t,e,n,s,i){if(!Nd(t))return t;const r={};for(const[o,a]of Object.entries(t))ul.has(o)?r[o]=a:typeof a=="function"?r[o]=a(e,n,i):Vu(a)?r[o]=s.resolveRandomString(a):r[o]=a;return r}function Dd(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 Bd(t){const e=t;if(typeof e?.getTotalLength=="function")return e.getTotalLength()}function w5(t){if(typeof t=="number"||typeof t=="string"||Array.isArray(t)&&t.every(e=>typeof e=="number"))return t}function k5(t){return typeof t=="string"?`"${t}"`:String(t)}class Il{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 zd(t,e,n,s,i){const r=n-i;if(r<0){e.paused||e.pause(),e.currentTime=0;return}t.update(r,s)}class Lr{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 _n}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=as({...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 r of e){if(s.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);s.add(r.id)}const i=n.initial===void 0?e[0]:e.find(r=>r.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,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=e,this.useDefinition(n.timeline),this.lastMarkerId=null;let o=0;return this.reducedMotion||i?o=this.duration:r!==void 0&&(o=this.markers.find(a=>a.id===r)?.time??0),this.seek(o),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(o=>o.id===e):this.currentMarker;if(!s)return;const i=n??this.language(),r=o=>o?.[i]?.[s.id]??o?.[i.split("-")[0]]?.[s.id];return r(this.options.captions)??r(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,r=s.getAttribute("data-volume");r!==null&&(s.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:s,startTime:i,sync:new Il(s)})})}syncAllMedia(e,n){for(const s of this.mediaTargets)zd(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 r=n.get(i);if(!r||!r.timeline.tracks?.length)return;const o=new _n;s.querySelectorAll("[data-tinyfly]").forEach(a=>{const l=a.getAttribute("data-tinyfly");l&&o.registerTarget(l,a)}),this.symbolInstances.push({adapter:o,timeline:as(r.timeline)})})}attachMedia(e,n){this.mediaSync=new Il(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 state(){return this.timeline?.getStateAtTime(this.timeline.currentTime)}get duration(){return this.timeline?.duration??0}get isPlaying(){return this.timeline?.playbackState==="playing"}destroy(){this.isDestroyed=!0,this.stopAnimationLoop(),this.reducedQuery?.removeEventListener?.("change",this.onReducedChange),this.visibilityObserver?.disconnect(),typeof document<"u"&&document.removeEventListener("visibilitychange",this.onDocumentVisibility),this.mediaSync?.dispose(),this.mediaSync=void 0;for(const 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 r=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,r),this.syncAllMedia(this.timeline.currentTime,r),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(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:r}=Ja(i.map(o=>o.time),e,s,{duration:n.duration,alternate:n.config.alternate===!0,holding:n.repeatDelayRemaining>0});for(const o of r){if(o.kind!=="event")continue;const a=i[o.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 v5(t,e,n={}){const s=new Lr(t,{...n,autoplay:!0});return await s.load(e),s}function M5(t,e={}){return new Lr(t,e)}const qd={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"},jd="tinyfly-controls-style",S5=`
|
|
1
|
+
(function(b,Qn){typeof exports=="object"&&typeof module<"u"?Qn(exports):typeof define=="function"&&define.amd?define(["exports"],Qn):(b=typeof globalThis<"u"?globalThis:b||self,Qn(b.tinyfly=b.tinyfly||{}))})(this,(function(b){"use strict";function Qn(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function Vs(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const xa=2;function Pa(t){return t.some(e=>e.interpolation!==void 0)?2:1}function mr(t){return t.property==="text"&&"textConfig"in t}function Ve(t){return t.kind==="inertia"&&"inertia"in t}function Je(t){return t.kind==="spring"&&"spring"in t}function $a(t){return t.property==="motionPath"&&"motionPathConfig"in t}function Db(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"angle"in t}function O0(t){return"keyframes"in t}class Bb{_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 zb{_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 C0(t,e){if(!(e>0))return t;const n=1e3/e;return Math.floor(t/n+1e-9)*n}function Ia(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 Oa(t,e="start"){if(t<=1)return 0;let n=0;for(let s=0;s<t;s++)n=Math.max(n,Ia(s,t,e));return n}function pr(t,e,n){if(n.offsets)return n.offsets[t]??0;const s=n.from??"start",i=Ia(t,e,s);if(n.amount!==void 0){const r=Oa(e,s);return r===0?0:n.amount*i/r}return n.each!==void 0?n.each*i:0}function yr(t,e){return Array.from({length:t},(n,s)=>pr(s,t,e))}function Js(t,e){return t<=1?0:Math.max(...yr(t,e))}const ts=1,Ca=6e4,br=Ca/ts,ge={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1},wr={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 Zs{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??ge.stiffness,this.damping=e.damping??ge.damping,this.mass=e.mass??ge.mass,this.restDelta=e.restDelta??ge.restDelta,this.restSpeed=e.restSpeed??ge.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=e.velocity??ge.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/ts);if(this.simulateTo(n+1),this.settledStep!==null&&n>=this.settledStep)return this.to;const s=this.samples[Math.min(n,this.samples.length-1)],i=this.samples[Math.min(n+1,this.samples.length-1)],r=e/ts-n;return s+(i-s)*r}settleTime(){return this.simulateTo(br+1),this.settledStep!==null?this.settledStep*ts:Ca}simulateTo(e){if(this.settledStep!==null)return;const n=Math.min(e,br+1),s=ts/1e3;for(;this.samples.length<n;){const i=this.samples[this.samples.length-1],r=i-this.to,o=-this.stiffness*r,a=-this.damping*this.velocity,l=(o+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>br&&(this.settledStep=br)}}function qb(t,e){return new Zs(t).valueAt(e)}function _0(t){return new Zs(t).settleTime()}function jb(t){const e=t.stiffness??ge.stiffness,n=t.damping??ge.damping,s=t.mass??ge.mass;return n<2*Math.sqrt(e*s)}function Kb(t){const e=t.stiffness??ge.stiffness,n=t.mass??ge.mass;return 2*Math.sqrt(e*n)}const _a=4,Yb=.002,Xb=1e-4,R0=6e4;function kr(t){const e=t.friction??_a;return e>0?e:_a}function Qs(t){return t.from+t.velocity/kr(t)}function Gb(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 es(t){let e=Gb(Qs(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 ns(t){const e=Math.abs(es(t)-t.from);if(e===0)return 0;const n=t.restDelta??Math.max(Xb,e*Yb);if(n>=e)return 0;const s=Math.log(e/n)/kr(t);return Math.min(R0,s*1e3)}function vr(t,e){if(e<=0)return t.from;const n=es(t);if(e>=ns(t))return n;const s=kr(t);return t.from+(n-t.from)*(1-Math.exp(-s*e/1e3))}function Ub(t,e){const n=kr(t),s=es(t);return e>=ns(t)?0:(s-t.from)*n*Math.exp(-n*Math.max(0,e)/1e3)}const Mr=t=>t,H0=t=>t*t,F0=t=>1-(1-t)*(1-t),L0=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,Ra=t=>t*t*t,Ha=t=>1-Math.pow(1-t,3),ti=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,N0=Ra,W0=Ha,D0=ti,Vb={linear:Mr,"ease-in":N0,"ease-out":W0,"ease-in-out":D0,"ease-in-quad":H0,"ease-out-quad":F0,"ease-in-out-quad":L0,"ease-in-cubic":Ra,"ease-out-cubic":Ha,"ease-in-out-cubic":ti};function B0(t){const[e,n,s,i]=t,r=3*e,o=3*(s-e)-r,a=1-r-o,l=3*n,c=3*(i-n)-l,h=1-l-c,u=g=>((a*g+o)*g+r)*g,d=g=>((h*g+c)*g+l)*g,f=g=>(3*a*g+2*o)*g+r,m=g=>{let p=g;for(let w=0;w<8;w++){const k=u(p)-g;if(Math.abs(k)<1e-7)return p;const S=f(p);if(Math.abs(S)<1e-7)break;p-=k/S}let y=0,v=1;for(p=g;y<v;){const w=u(p);if(Math.abs(w-g)<1e-7)return p;g>w?y=p:v=p,p=(y+v)/2}return p};return g=>{if(g<=0)return 0;if(g>=1)return 1;const p=m(g);return d(p)}}function Fa(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 z0(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 q0=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 j0(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 K0(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 Y0(t){switch(t.type){case"steps":return K0(t.count,t.position);case"elastic":return Fa(z0(t.amplitude,t.period),t.mode);case"bounce":return Fa(q0,t.mode);case"back":return Fa(j0(t.overshoot),t.mode)}}function Dt(t){return t===void 0?Mr:Qn(t)?B0(t.points):Vs(t)?Y0(t):Vb[t]??Mr}const X0=32,Jb=256,ss=new Map,Zb=/[MmLlHhVvCcSsQqTtAaZz]/,Qb=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,tw={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function ew(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 r=t[n];if(Zb.test(r)){s={type:r,args:[]},e.push(s),n++;continue}if(!s)break;const o=s.type==="A"||s.type==="a",a=s.args.length%7;if(o&&(a===3||a===4)){if(r!=="0"&&r!=="1")break;s.args.push(r==="1"?1:0),n++;continue}const l=Qb.exec(t.slice(n));if(!l)break;s.args.push(parseFloat(l[0])),n+=l[0].length}return e}function nw(t,e,n,s,i,r,o,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),m=(t-a)/2,g=(e-l)/2,p=d*m+f*g,y=-f*m+d*g,v=p*p/(c*c)+y*y/(h*h);if(v>1){const F=Math.sqrt(v);c*=F,h*=F}const w=r===o?-1:1,k=c*c*h*h-c*c*y*y-h*h*p*p,S=c*c*y*y+h*h*p*p,x=w*Math.sqrt(Math.max(0,k/S)),M=x*c*y/h,E=-x*h*p/c,T=d*M-f*E+(t+a)/2,A=f*M+d*E+(e+l)/2,P=(F,B,Y,R)=>{const K=F*Y+B*R,st=Math.sqrt((F*F+B*B)*(Y*Y+R*R)),$=Math.acos(Math.max(-1,Math.min(1,K/st)));return F*R-B*Y<0?-$:$},I=P(1,0,(p-M)/c,(y-E)/h);let O=P((p-M)/c,(y-E)/h,(-p-M)/c,(-y-E)/h);!o&&O>0&&(O-=2*Math.PI),o&&O<0&&(O+=2*Math.PI);const _=Math.max(1,Math.ceil(Math.abs(O)/(Math.PI/2))),L=O/_,j=4/3*Math.tan(L/4),V=F=>{const B=c*Math.cos(F),Y=h*Math.sin(F);return[d*B-f*Y+T,f*B+d*Y+A]},tt=F=>{const B=-c*Math.sin(F),Y=h*Math.cos(F);return[d*B-f*Y,f*B+d*Y]},J=[];for(let F=0;F<_;F++){const B=I+F*L,Y=B+L,[R,K]=V(B),[st,$]=F===_-1?[a,l]:V(Y),[C,z]=tt(B),[X,W]=tt(Y);J.push([R+j*C,K+j*z,st-j*X,$-j*W,st,$])}return J}function Ze(t,e,n,s,i){const r=1-i;return r*r*r*t+3*r*r*i*e+3*r*i*i*n+i*i*i*s}function G0(t,e,n,s,i){const r=1-i;return 3*r*r*(e-t)+6*r*i*(n-e)+3*i*i*(s-n)}function ei(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 Sr(t,e,n){const[s,i,r,o,a,l]=n,c=[0];let h=t,u=e,d=0;for(let f=1;f<=X0;f++){const m=f/X0,g=Ze(t,s,r,a,m),p=Ze(e,i,o,l,m);d+=Math.hypot(g-h,p-u),c.push(d),h=g,u=p}return{subpath:0,type:"C",points:[s,i,r,o,a,l],startX:t,startY:e,endX:a,endY:l,length:d,lengths:c}}function An(t){const e=ss.get(t);if(e)return e;const n=[];let s=0,i=0,r=0,o=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:p}of ew(t)){const y=g.toUpperCase(),v=g!==y,w=tw[y];if(y==="Z"){(s!==r||i!==o)&&u(ei(s,i,r,o)),c>=0&&h.add(c),s=r,i=o,a=l=null;continue}for(let k=0;k+w<=p.length;k+=w){const S=p.slice(k,k+w),x=v?s:0,M=v?i:0;let E=null,T=null;switch(y){case"M":k===0?(s=S[0]+x,i=S[1]+M,r=s,o=i,(c<0||n[n.length-1]?.subpath===c)&&c++):(u(ei(s,i,S[0]+x,S[1]+M)),s=S[0]+x,i=S[1]+M);break;case"L":u(ei(s,i,S[0]+x,S[1]+M)),s=S[0]+x,i=S[1]+M;break;case"H":u(ei(s,i,S[0]+x,i)),s=S[0]+x;break;case"V":u(ei(s,i,s,S[0]+M)),i=S[0]+M;break;case"C":{const A=[S[0]+x,S[1]+M,S[2]+x,S[3]+M,S[4]+x,S[5]+M];u(Sr(s,i,A)),E=[A[2],A[3]],s=A[4],i=A[5];break}case"S":{const[A,P]=a?[2*s-a[0],2*i-a[1]]:[s,i],I=[A,P,S[0]+x,S[1]+M,S[2]+x,S[3]+M];u(Sr(s,i,I)),E=[I[2],I[3]],s=I[4],i=I[5];break}case"Q":case"T":{let A=s,P=i;y==="Q"?(A=S[0]+x,P=S[1]+M):l&&(A=2*s-l[0],P=2*i-l[1]);const I=y==="Q"?S[2]+x:S[0]+x,O=y==="Q"?S[3]+M:S[1]+M;u(Sr(s,i,[s+2/3*(A-s),i+2/3*(P-i),I+2/3*(A-I),O+2/3*(P-O),I,O])),T=[A,P],s=I,i=O;break}case"A":{const A=S[5]+x,P=S[6]+M;let I=s,O=i;for(const _ of nw(s,i,S[0],S[1],S[2],S[3],S[4],A,P))u(Sr(I,O,_)),I=_[4],O=_[5];s=A,i=P;break}}a=E,l=T}}const d=n.reduce((g,p)=>g+p.length,0),f=[];for(let g=0;g<n.length;){const p=n[g].subpath;let y=g,v=0;for(;y<n.length&&n[y].subpath===p;)v+=n[y++].length;const w=n[g],k=n[y-1],S=h.has(p)||Math.abs(k.endX-w.startX)<1e-9&&Math.abs(k.endY-w.startY)<1e-9;f.push({start:g,end:y,length:v,closed:S}),g=y}const m={segments:n,totalLength:d,subpaths:f};return ss.size>=Jb&&ss.delete(ss.keys().next().value),ss.set(t,m),m}function sw(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 r=n[i]-n[s],o=r>0?(e-n[s])/r:0;return(s+o)/(n.length-1)}function iw(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,r,o,a]=t.points,l=sw(t,e);let c=G0(t.startX,n,i,o,l),h=G0(t.startY,s,r,a,l);if(Math.hypot(c,h)<1e-9){const u=l<.5?Math.min(1,l+.001):Math.max(0,l-.001),d=Ze(t.startX,n,i,o,u),f=Ze(t.startY,s,r,a,u),m=Ze(t.startX,n,i,o,l),g=Ze(t.startY,s,r,a,l);c=l<.5?d-m:m-d,h=l<.5?f-g:g-f}return{x:Ze(t.startX,n,i,o,l),y:Ze(t.startY,s,r,a,l),angle:Math.atan2(h,c)*180/Math.PI}}function La(t,e,n=0,s=t.length){if(s<=n)return{x:0,y:0,angle:0};let i=0;for(let r=n;r<s;r++){const o=t[r];if(i+o.length>=e||r===s-1)return iw(o,e-i);i+=o.length}return{x:0,y:0,angle:0}}function U0(t,e){const{segments:n,totalLength:s}=An(t);return La(n,Math.max(0,Math.min(1,e))*s)}function rw(){ss.clear()}function ow(t){return An(t).totalLength}const aw=24,lw=320,cw=2.5,ni=72,hw=64,uw=.2,dw=128,si=new Map;let Tr=0,Qe;const V0=t=>Math.round(t*100)/100;function J0(t,e){const{segments:n,subpaths:s,totalLength:i}=An(t);if(n.length===0)return[];if(e){const r=s.every(o=>o.closed);return[{segments:n,start:0,end:n.length,length:i,closed:r}]}return s.filter(r=>r.length>0).map(r=>({segments:n,start:r.start,end:r.end,length:r.length,closed:r.closed}))}function Na(t,e){const n=t.closed?(e%1+1)%1:Math.max(0,Math.min(1,e)),s=La(t.segments,n*t.length,t.start,t.end);return[s.x,s.y]}function Z0(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 Q0(t,e){const n=[];for(let s=0;s<e;s++)n.push(Na(t,t.closed?s/e:s/(e-1)));return n}function tu(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 fw(t,e,n){const s=t.closed&&e.closed;if(n!==void 0)return{offset:s?Math.abs(n)%ni/ni:0,reversed:n<0};const i=tu(Q0(t,ni)),r=tu(Q0(e,ni)),o=ni;let a={offset:0,reversed:!1},l=1/0;for(const c of[!1,!0]){const h=s?o:1;for(let u=0;u<h;u++){let d=0;for(let f=0;f<o&&d<l;f++){const m=s?c?(u-f+o)%o:(f+u)%o:c?o-1-f:f,g=i[f][0]-r[m][0],p=i[f][1]-r[m][1];d+=g*g+p*p}d<l&&(l=d,a={offset:s?u/o:0,reversed:c})}}return a}function gw(t,e,n){return n?((e.reversed?e.offset-t:t+e.offset)%1+1)%1:e.reversed?1-t:t}function mw(t,e,n){return n?((e.reversed?e.offset-t:t-e.offset)%1+1)%1:e.reversed?1-t:t}function pw(t,e,n){const s=t.closed&&e.closed,i=fw(t,e,n.shapeIndex),r=Math.max(aw,Math.min(lw,Math.ceil(Math.max(t.length,e.length)/cw))),o=new Set,a=u=>o.add(Math.round(u*1e7)/1e7);for(let u=0;u<=r;u++)a(u/r);for(const u of Z0(t))a(u);for(const u of Z0(e))a(mw(u,i,s));let l=[...o].sort((u,d)=>u-d);s&&(l=l.filter(u=>u<1));const c=[],h=[];for(const u of l)c.push(...Na(t,u)),h.push(...Na(e,gw(u,i,s)));return yw({from:c,to:h,closed:s})}function yw(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[o,a]=s.pop();let l=-1,c=uw;for(let h=o+1;h<a;h++){const u=Math.max(eu(t.from,o,a,h),eu(t.to,o,a,h));u>c&&(c=u,l=h)}l!==-1&&(n[l]=1,s.push([o,l],[l,a]))}const i=[],r=[];for(let o=0;o<e;o++)n[o]&&(i.push(t.from[o*2],t.from[o*2+1]),r.push(t.to[o*2],t.to[o*2+1]));return{from:i,to:r,closed:t.closed}}function eu(t,e,n,s){const i=t[e*2],r=t[e*2+1],o=t[n*2]-i,a=t[n*2+1]-r,l=t[s*2]-i,c=t[s*2+1]-r,h=o*o+a*a,u=h===0?0:Math.max(0,Math.min(1,(l*o+c*a)/h));return Math.hypot(l-u*o,c-u*a)}function bw(t,e,n){const s=n.shapeIndex;if(Qe&&Qe.from===t&&Qe.to===e&&Qe.shapeIndex===s)return Qe.plan;const r=si.get(String(s??"auto"))?.get(t)?.get(e);if(r)return Qe={from:t,to:e,shapeIndex:s,plan:r},r;const o=An(t).subpaths.filter(f=>f.length>0).length===An(e).subpaths.filter(f=>f.length>0).length,a=J0(t,!o),l=J0(e,!o),c={pairs:a.map((f,m)=>pw(f,l[m],n))};Tr>=dw&&(si.clear(),Tr=0);const h=String(s??"auto"),u=si.get(h)??new Map;si.set(h,u);const d=u.get(t)??new Map;return u.set(t,d),d.set(e,c),Tr++,Qe={from:t,to:e,shapeIndex:s,plan:c},c}function nu(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 r=bw(t,e,s);if(r.pairs.length===0)return i<.5?t:e;let o="";for(const a of r.pairs){for(let l=0;l<a.from.length;l+=2){const c=V0(a.from[l]+(a.to[l]-a.from[l])*i),h=V0(a.from[l+1]+(a.to[l+1]-a.from[l+1])*i);o+=`${l===0?o?" M":"M":" L"}${c} ${h}`}a.closed&&(o+=" Z")}return o}function ww(){si.clear(),Tr=0,Qe=void 0}function is(t){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(t)}const rs=Math.PI/180,kw=.9995;function Wa(){return[0,0,0,1]}function Zt(t,e){const n=Math.hypot(t[0],t[1],t[2]);if(n===0)return Wa();const s=e*rs/2,i=Math.sin(s)/n;return[t[0]*i,t[1]*i,t[2]*i,Math.cos(s)]}function vw(t,e,n){return Da(Da(Zt([0,1,0],e),Zt([1,0,0],t)),Zt([0,0,1],n))}function Mw(t){const[e,n,s,i]=tn(t),r=2*(e*s+n*i),o=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/rs,Math.atan2(r,u)/rs,Math.atan2(o,a)/rs]:[d/rs,Math.atan2(-h,c)/rs,0]}function Da(t,e){const[n,s,i,r]=t,[o,a,l,c]=e;return[r*o+n*c+s*l-i*a,r*a-n*l+s*c+i*o,r*l+n*a-s*o+i*c,r*c-n*o-s*a-i*l]}function su(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function iu(t){return Math.hypot(t[0],t[1],t[2],t[3])}function tn(t){const e=iu(t);return e===0?Wa():[t[0]/e,t[1]/e,t[2]/e,t[3]/e]}function Sw(t){return[-t[0],-t[1],-t[2],t[3]]}function ru(t,e,n){const s=tn(t);let i=tn(e),r=su(s,i);if(r<0&&(i=[-i[0],-i[1],-i[2],-i[3]],r=-r),r>kw)return tn([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 o=Math.acos(r),a=Math.sin(o),l=Math.sin((1-n)*o)/a,c=Math.sin(n*o)/a;return tn([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 Tw(t,e){const[n,s,i,r]=tn(t),o=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]+r*o+(s*l-i*a),e[1]+r*a+(i*o-n*l),e[2]+r*l+(n*a-s*o)]}const Ew=Object.freeze(Object.defineProperty({__proto__:null,conjugate:Sw,dot:su,fromAxisAngle:Zt,fromEuler:vw,identity:Wa,length:iu,multiply:Da,normalize:tn,rotateVec3:Tw,slerp:ru,toEuler:Mw},Symbol.toStringTag,{value:"Module"})),Ie=(t,e,n)=>t+(e-t)*n,ou=512,Ba=new Map,za=new Map;function au(t){const e=Ba.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 Ba.size<ou&&Ba.set(t,s),s}const lu=t=>t.charCodeAt(0)===35,cu=t=>t.startsWith("rgb"),hu=t=>t.startsWith("rgba"),Aw=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,qa=t=>Math.round(t).toString(16).padStart(2,"0");function xw(t,e,n){return`#${qa(t)}${qa(e)}${qa(n)}`}function uu(t){const e=za.get(t);if(e)return e;const n=t.match(Aw);if(!n)throw new Error(`Invalid rgb color: ${t}`);const s=parseInt(n[1],10),i=parseInt(n[2],10),r=parseInt(n[3],10),o=n[4]!==void 0?[s,i,r,parseFloat(n[4])]:[s,i,r];return za.size<ou&&za.set(t,o),o}const du=(t,e,n)=>{if(lu(t)&&lu(e)){const[s,i,r]=au(t),[o,a,l]=au(e),c=Ie(s,o,n),h=Ie(i,a,n),u=Ie(r,l,n);return xw(c,h,u)}if((cu(t)||hu(t))&&(cu(e)||hu(e))){const s=uu(t),i=uu(e),r=Math.round(Ie(s[0],i[0],n)),o=Math.round(Ie(s[1],i[1],n)),a=Math.round(Ie(s[2],i[2],n));if(s.length===4||i.length===4){const l=s[3]??1,c=i[3]??1,h=Ie(l,c,n);return`rgba(${r}, ${o}, ${a}, ${h})`}return`rgb(${r}, ${o}, ${a})`}return n<1?t:e},fu=(t,e,n)=>{const s=Math.min(t.length,e.length),i=[];for(let r=0;r<s;r++)i.push(Ie(t[r],e[r],n));return i},gu=(t,e,n)=>ru(t,e,n),ja=(t,e,n)=>n<1?t:e,mu=(t,e,n)=>nu(t,e,n);function ii(t,e){return e==="slerp"?gu:typeof t=="number"?Ie:Array.isArray(t)?fu:typeof t=="string"?t.startsWith("#")||t.startsWith("rgb")?du:is(t)?mu:ja:ja}const Ka=1e3/60;function Ya(t,e={}){if(!Je(t))throw new Error(`bakeSpringTrack: track "${t.id}" is not a spring track`);const n=new Zs(t.spring);return pu(t,s=>n.valueAt(s),n.settleTime(),t.spring.from,t.spring.to,e)}function Xa(t,e={}){if(!Ve(t))throw new Error(`bakeInertiaTrack: track "${t.id}" is not an inertia track`);const n=t.inertia;return pu(t,s=>vr(n,s),ns(n),n.from,es(n),e)}function pu(t,e,n,s,i,r){const o=r.intervalMs??Ka,a=r.tolerance??.01,l=t.delay??0,c=[];for(let u=0;u<=n;u+=o)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?bu(c,a):c,...t.targets&&{targets:[...t.targets]},...t.stagger&&{stagger:{...t.stagger}}}}function Ga(t,e,n,s={}){const i=s.intervalMs??Ka,r=typeof n=="function"?n:Dt(n),o=ii(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:o(t.value,e.value,r(u)),easing:"linear"})}const c=r(1);return l.push({...e,...c!==1&&{value:o(t.value,e.value,c)},easing:"linear"}),l}function Pw(t,e){return Je(t)?Ya(t,e):Ve(t)?Xa(t,e):t}function yu(t,e={}){const n=t.keyframes;if(!n.some(r=>Vs(r.easing)))return t;const s=n.length>0?[n[0]]:[],i={...e,interpolation:t.interpolation??e.interpolation};for(let r=1;r<n.length;r++){const o=n[r];Vs(o.easing)?s.push(...Ga(n[r-1],o,o.easing,i)):s.push(o)}return{...t,keyframes:s}}function $w(t,e){return t.filter(O0).map(n=>yu(n,e)).concat(t.filter(Je).map(n=>Ya(n,e)),t.filter(Ve).map(n=>Xa(n,e)))}function bu(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],r=t[s],o=t[s+1],a=o.time-i.time;if(a<=0)continue;const l=(r.time-i.time)/a,c=i.value+(o.value-i.value)*l;Math.abs(r.value-c)>e&&n.push(r)}return n.push(t[t.length-1]),n}function Er(t){const e=[...t.keyframes].sort((n,s)=>n.time-s.time);return{...t,keyframes:e}}function en(t){return t.targets&&t.targets.length>0?t.targets:[t.target]}function os(t,e,n,s){const i=n??0;return!s||e<=1?i:i+pr(t,e,s)}class nn{track;targets;constructor(e){this.track=e,this.targets=en(e)}getValueAtTime(e){return this.valueForOffset(e-os(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 r=os(i,n,this.track.delay,this.track.stagger),o=this.valueForOffset(e-r);o!==void 0&&s.push({target:this.targets[i],value:o,start:r+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?Js(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 r=i.time-s.time,o=(e-s.time)/r,l=Dt(i.easing)(o);return ii(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 wu{track;targets;sampler;constructor(e){this.track=e,this.targets=en(e),this.sampler=new Zs(e.spring)}getValueAtTime(e){return this.sampler.valueAt(e-os(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 r=os(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:this.sampler.valueAt(e-r),start:r})}return s}getDuration(){const e=this.track.stagger?Js(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+e}getTrack(){return this.track}}class ku{track;targets;duration;constructor(e){this.track=e,this.targets=en(e),this.duration=ns(e.inertia)}getValueAtTime(e){return vr(this.track.inertia,e-os(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 r=os(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:vr(this.track.inertia,e-r),start:r})}return s}getDuration(){const e=this.track.stagger?Js(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+e}getTrack(){return this.track}}function Ua(t,e){const n={...U0(t.pathData,e)};if(t.matrix){const[s,i,r,o,a,l]=t.matrix,{x:c,y:h}=n;n.x=s*c+r*h+a,n.y=i*c+o*h+l;const u=n.angle*Math.PI/180,d=Math.cos(u),f=Math.sin(u);n.angle=Math.atan2(i*d+o*f,s*d+r*f)*180/Math.PI}return t.autoRotate&&t.rotateOffset&&(n.angle+=t.rotateOffset),n}function Iw(t,e,n,s){const i=e+(n-e)*s;return Ua(t,i)}const Va={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},Ow=20;function vu(t){const e=Va[t??"upperCase"]??t??Va.upperCase,n=Array.from(e);return n.length>0?n:Array.from(Va.upperCase)}function Cw(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 Mu(t,e,n=0){const s=t.from??"",i=t.to,r=Math.max(0,Math.min(1,e));if(r<=0)return s;if(r>=1)return i;const o=Array.from(s),a=Array.from(i),l=t.rightToLeft??!1;if(t.mode==="type"){const v=Math.round(r*Math.max(o.length,a.length));return l?o.slice(0,Math.max(0,o.length-v)).join("")+a.slice(Math.max(0,a.length-v)).join(""):a.slice(0,v).join("")+o.slice(v).join("")}const c=Math.max(0,Math.min(.999,t.revealDelay??0)),h=Math.max(0,(r-c)/(1-c)),u=Math.floor(h*a.length),d=t.tweenLength===!1?a.length:Math.round(o.length+(a.length-o.length)*r),f=vu(t.chars),m=t.refreshRate??Ow,g=m>0?Math.floor(n*m/1e3):0,p=t.seed??1;let y="";for(let v=0;v<d;v++){const w=l?v>=d-u:v<u,k=l?a[a.length-(d-v)]:a[v];w&&k!==void 0||k===" "||k===`
|
|
2
|
+
`?y+=k:y+=f[Cw(p,v,g)%f.length]}return y}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 r=1e3;for(let a=0;a<r&&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 o=this.getStateAtTime(this._currentTime);this.onUpdate?.(o)}getStateAtTime(e){const n=new Map;if(e=C0(e,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(e,n);else for(const[s,i]of this._trackPlayers){const r=i.getTrack().property;for(const{target:o,value:a,start:l}of i.getTargetValues(e))this._write(n,s,o,r,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,r]of this._trackPlayers){const o=r.getTrack().property;for(const{target:a,value:l,start:c}of r.getTargetValues(e)){const h=`${a}\0${o}`,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:o,value:l,start:c,started:u})}}for(const{trackId:i,target:r,property:o,value:a,start:l}of s.values())this._write(n,i,r,o,a,e-l)}_write(e,n,s,i,r,o){if(r===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 r=="number"){a.set("text",Mu(l.textConfig,r,Math.max(0,o)));return}const c=this._motionPathTracks.get(n);if(c&&typeof r=="number"){const h=Ua(c.motionPathConfig,r);a.set("motionPathX",h.x),a.set("motionPathY",h.y),c.motionPathConfig.autoRotate&&a.set("motionPathRotate",h.angle)}else a.set(i,r)}_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 en(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,Ve(e)){this._trackPlayers.set(e.id,new ku(e));return}if(Je(e)){this._trackPlayers.set(e.id,new wu(e)),this._springTracks.set(e.id,e);return}if(mr(e))this._trackPlayers.set(e.id,new nn(e)),this._textTracks.set(e.id,e);else if($a(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 nn(n)),this._motionPathTracks.set(e.id,e)}else this._trackPlayers.set(e.id,new nn(e))}replaceTrack(e,n){const s=this._tracks.findIndex(r=>r.id===e);if(s<0)return;const i=this._tracks.slice(s+1);this.removeTrack(e);for(const r of i)this.removeTrack(r.id);this.addTrack(n);for(const r of i)this.addTrack(r)}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(Je(s)||Ve(s))return{from:i,to:n.getDuration()};const r=s.keyframes;if(!(!r||r.length===0))return{from:r[0].time+i,to:n.getDuration()}}findConflicts(){const e=[];for(let n=0;n<this._tracks.length;n++){const s=this._tracks[n],i=this.getTrackSpan(s.id);if(i)for(let r=0;r<n;r++){const o=this._tracks[r];if(o.property!==s.property)continue;const a=en(o).filter(u=>en(s).includes(u));if(a.length===0)continue;const l=this.getTrackSpan(o.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?o.id:s.id,winningTrackId:h?s.id:o.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&&!en(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:Pa(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,r)=>i.time-r.time).map(i=>({...i})):void 0,s={...this._config};n?s.markers=n:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(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 _w=100;function Ja(t,e,n,s){const i=[],r=[],{duration:o,alternate:a}=s,l=(f,m,g,p)=>{r.push([f,m]);const y=[];t.forEach((v,w)=>{(g==="forward"?(p?v>=f:v>f)&&v<=m:(p?v<=f:v<f)&&v>=m)&&y.push(w)}),y.sort((v,w)=>(g==="forward"?t[v]-t[w]:t[w]-t[v])||v-w);for(const v of y)i.push({kind:"event",index:v,direction:g})};let c=e.time,h=e.direction,u=e.fresh===!0;const d=Math.min(_w,Math.max(0,n.iteration-e.iteration));for(let f=0;f<d;f++){const m=h==="forward"?o:0;l(c,m,h,u),i.push({kind:"repeat"}),a?(h=h==="forward"?"reverse":"forward",c=m,u=!1):(c=h==="forward"?0:o,u=!0)}return d>0&&s.holding&&!a?{crossings:i,passes:r}:(l(c,n.time,h,u),{crossings:i,passes:r})}function Su(t){return Ve(t)?{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:Tu(t.inertia),...Oe(t)}:Je(t)?{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...Oe(t)}:mr(t)?{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:t.keyframes.map(Za),...Oe(t)}:$a(t)?{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:t.keyframes.map(Za),...Oe(t)}:{id:t.id,target:t.target,property:t.property,keyframes:t.keyframes.map(Za),...t.interpolation!==void 0&&{interpolation:t.interpolation},...Oe(t)}}function Tu(t){return{...t,...Array.isArray(t.end)&&{end:[...t.end]}}}function Za(t){return{time:t.time,value:t.value,...t.easing&&{easing:t.easing}}}function Oe(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 Eu(t){if(Ve(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"inertia",inertia:Tu(e.inertia),...Oe(e)}}if(Je(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"spring",spring:{...e.spring},...Oe(e)}}if(mr(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),...Oe(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,...Oe(e)}}return Er({id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,...t.interpolation!==void 0&&{interpolation:t.interpolation},...Oe(t)})}function Au(t){const e=t._config.markers;return{formatVersion:Pa(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(Su),...t.captions&&{captions:JSON.parse(JSON.stringify(t.captions))}}}function as(t){const e=t.formatVersion??1;if(e>xa)throw new Error(`tinyfly: this animation uses format version ${e}, but this tinyfly reads up to version ${xa}. Update tinyfly to play it.`);return new Ht({id:t.id,name:t.name,config:t.config,tracks:t.tracks.map(Eu),captions:t.captions})}function Rw(t){return JSON.stringify(Au(t))}function Hw(t){const e=JSON.parse(t);return as(e)}function re(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 Se(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 Qa(t,e,n){return e+t.next()*(n-e)}function xu(t,e,n,s){if(s<=0)return Qa(t,e,n);const i=Math.floor((n-e)/s),r=Math.round(t.next()*i);return e+r*s}function Fw(t,e){if(e.length!==0)return e[Math.floor(t.next()*e.length)]}function Lw(t,e=0,n=1){const s=1-t.next(),i=t.next();return e+n*Math.sqrt(-2*Math.log(s))*Math.cos(2*Math.PI*i)}function Nw(t,e){const n=[...e];for(let s=n.length-1;s>0;s--){const i=Math.floor(t.next()*(s+1));[n[s],n[i]]=[n[i],n[s]]}return n}const Pu=/^([+\-*/])=\s*(-?[\d.]+)$/,$u=/^random\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*(?:,\s*(-?[\d.]+)\s*)?\)$/i;function Ww(t){return typeof t!="string"?!1:Pu.test(t.trim())||$u.test(t.trim())}function tl(t,e={}){if(typeof t!="string")return t;const n=t.trim(),s=Pu.exec(n);if(s){const[,r,o]=s,a=e.base??0,l=Number.parseFloat(o);switch(r){case"+":return a+l;case"-":return a-l;case"*":return a*l;case"/":return l===0?a:a/l}}const i=$u.exec(n);if(i){if(!e.random)throw new Error(`resolveValue: "${n}" needs a random source — pass one via context.random`);const r=Number.parseFloat(i[1]),o=Number.parseFloat(i[2]),a=i[3]!==void 0?Number.parseFloat(i[3]):void 0;return a!==void 0?xu(e.random,r,o,a):Qa(e.random,r,o)}return t}function Iu(t,e=0,n){const s=[];let i=e;for(const r of t){const o=tl(r,{base:i,random:n});s.push(o),typeof o=="number"&&(i=o)}return s}class Dw{random;constructor(e){this.random=Se(e)}get seed(){return this.random.seed}resolve(e,n=0){return tl(e,{base:n,random:this.random})}resolveSequence(e,n=0){return Iu(e,n,this.random)}}const Bw=600;function Ou(t){if(Array.isArray(t)){const[d,f,m,g]=t;return{fn:Ru(d,f,m,g),bezier:[d,f,m,g]}}const{segments:e}=An(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],r=i.endX-n,o=i.endY-s;if(r===0||o===0)throw new Error(`customEase: "${t}" must move along both axes`);const a=d=>(d-n)/r,l=d=>(d-s)/o;if(e.length===1&&i.type==="C"){const[d,f,m,g]=i.points,p=[a(d),l(f),a(m),l(g)];return{fn:Ru(...p),bezier:p}}const c=[],h=[],u=Math.max(8,Math.ceil(Bw/e.length));for(const d of e)for(let f=c.length===0?0:1;f<=u;f++){const[m,g]=zw(d,f/u);c.push(a(m)),h.push(l(g))}return{fn:qw(c,h)}}function Cu(t={}){const n=.1+Math.max(0,Math.min(1,t.strength??.7))*.7,s=[1];for(let r=n;r>.002;r*=n)s.push(2*Math.sqrt(r));const i=s.reduce((r,o)=>r+o,0);return r=>{if(r<=0)return 0;if(r>=1)return 1;let o=r*i;for(let a=0;a<s.length;a++){if(o<=s[a]){if(a===0)return(o/s[0])**2;const l=s[a]/2,c=l*l,h=o-l;return 1-(c-h*h)}o-=s[a]}return 1}}function _u(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 zw(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,r,o,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*o,l*l*l*t.startY+3*l*l*e*s+3*l*e*e*r+e*e*e*a]}function qw(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 o=s+i>>1;t[o]<=n?s=o:i=o}const r=t[i]-t[s];return r===0?e[i]:e[s]+(n-t[s])/r*(e[i]-e[s])}}function Ru(t,e,n,s){const i=(o,a,l)=>3*(1-o)*(1-o)*o*a+3*(1-o)*o*o*l+o*o*o,r=(o,a,l)=>3*(1-o)*(1-o)*a+6*(1-o)*o*(l-a)+3*o*o*(1-l);return o=>{if(o<=0)return 0;if(o>=1)return 1;let a=o;for(let h=0;h<8;h++){const u=i(a,t,n)-o,d=r(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=o;for(let h=0;h<40;h++)i(a,t,n)<o?l=a:c=a,a=(l+c)/2;return i(a,e,s)}}const jw=350,Kw=300,Yw=550;function Xw(t,e={}){const n=e.lead??jw,s=e.gap??Kw,i=e.tail??Yw,r=[];let o=0;return t.forEach((a,l)=>{const c=[];let h=o+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);r.push({id:a.id??`s${l}`,start:o,duration:u-o,cues:c}),o=u}),{duration:o,scenes:r,cues:r.flatMap(a=>a.cues)}}function Gw(t){return t.cues.map(e=>({id:e.id,time:e.start,label:e.text}))}function Uw(t,e){let n=t.scenes[0];for(const s of t.scenes)if(e>=s.start)n=s;else break;return n}const ri=t=>6e4/t.bpm;function Ar(t,e){return t.offset+e*ri(t)}function oi(t,e){return(e-t.offset)/ri(t)}function Vw(t,e){return Ar(t,Math.round(oi(t,e)))}function Jw(t,e){return Ar(t,Math.ceil(oi(t,e)-1e-9))}function Zw(t,e,n){const s=Math.max(1,Math.round(t.beatsPerBar??4)),i=[];if(!(t.bpm>0)||n<e)return i;for(let r=Math.ceil(oi(t,e)-1e-9);;r++){const o=Ar(t,r);if(o>n+1e-9)break;i.push({time:o,bar:(r%s+s)%s===0,n:r})}return i}const ls=100;function Qw(t,e,n={}){const s=n.minBpm??70,i=n.maxBpm??180,r=Math.max(1,Math.round(e/ls)),o=Math.min(t.length,Math.round((n.maxSeconds??60)*e)),a=Math.floor(o/r);if(a<4)return{bpm:120,offset:0,confidence:0};const l=new Float64Array(a);for(let T=0;T<a;T++){let A=0;for(let P=T*r;P<(T+1)*r;P++)A+=t[P]*t[P];l[T]=Math.log(1e-6+A/r)}const c=new Float64Array(a);for(let T=1;T<a;T++)c[T]=Math.max(0,l[T]-l[T-1]);const h=c.reduce((T,A)=>T+A,0)/a;for(let T=0;T<a;T++)c[T]=Math.max(0,c[T]-h);const u=Math.max(1,Math.floor(60*ls/i)),d=Math.min(a-1,Math.ceil(60*ls/s)),f=T=>{let A=0;for(let P=T;P<a;P++)A+=c[P]*c[P-T];return A/(a-T)};let m=0;for(let T=0;T<a;T++)m+=c[T]*c[T];m/=a;let g=u,p=-1/0;for(let T=u;T<=d;T++){const A=60*ls/T,P=Math.exp(-.5*(Math.log2(A/120)/.9)**2),I=f(T)*P;I>p&&(p=I,g=T)}const y=T=>{const A=Math.floor(T);return A<0||A+1>=a?0:c[A]+(c[A+1]-c[A])*(T-A)},v=(T,A)=>{let P=0;for(let I=A;I<a;I+=T)P+=y(I);return P};let w=g,k=0,S=-1/0;for(let T=g-.6;T<=g+.6+1e-9;T+=.02){if(T<1)continue;const A=Math.max(1,Math.round(T*4));for(let P=0;P<A;P++){const I=P/A*T,O=v(T,I);O>S&&(S=O,k=I,w=T)}}const x=60*ls/w,M=m>0?Math.max(0,Math.min(1,f(g)/m)):0,E=(k+.5)*1e3/ls;return{bpm:Math.round(x*100)/100,offset:Math.round(E%(6e4/x)),confidence:M}}const t2=600,e2=250,Hu=1;function n2(t,e){const n=e.target??"Camera",s={x:e.stage.width/2,y:e.stage.height/2},i={},r=(u,d,f,m)=>{const g=i[u]??=[];for(;g.length>0&&g[g.length-1].time>=d;)g.pop();g.push({time:d,value:f,...m?{easing:m}:{}})},o=u=>{const d=u.rotate*Math.PI/180,f=(u.focusX-s.x)*u.scale,m=(u.focusY-s.y)*u.scale;return{x:-(f*Math.cos(d)-m*Math.sin(d)),y:-(f*Math.sin(d)+m*Math.cos(d)),scale:u.scale,rotate:u.rotate}},a=(u,d,f)=>{const m=o(d);for(const g of["x","y","scale","rotate"])r(g,u,m[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(Hu,u.duration??t2);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>Hu?"ease-in-out":void 0))}else{const{follow:d}=u,f=d.lag??e2,m=new Ht({id:"follow",tracks:[{id:"x",target:"s",property:"x",keyframes:d.x}]}),g=v=>m.getStateAtTime(v).values.get("s")?.get("x")??l.focusX,p=[u.at,...d.x.map(v=>v.time).filter(v=>v>u.at&&v<u.until),u.until];a(u.at,l);const y=v=>({focusX:g(v)+(d.lead??0),focusY:d.y??l.focusY,scale:d.scale??l.scale,rotate:l.rotate});for(const v of p){const w=d.x.find(k=>k.time===v)?.easing;a(v+f,y(v),v===u.at?"ease-in-out":w)}l=y(u.until)}for(const u of c.filter(d=>"shake"in d)){const d=u.shake.strength??12,f=u.shake.roll??1.5,m=1e3/(u.shake.frequency??24),g=Se(u.shake.seed??Math.round(u.at)+1),p=()=>g.next()*2-1;for(const y of["shakeX","shakeY","shakeRotate"])r(y,u.at,0);for(let y=u.at+m;y<u.at+u.duration;y+=m){const v=1-(y-u.at)/u.duration;r("shakeX",y,p()*d*v),r("shakeY",y,p()*d*v),r("shakeRotate",y,p()*f*v)}for(const y of["shakeX","shakeY","shakeRotate"])r(y,u.at+u.duration,0,"ease-out")}return Object.entries(i).map(([u,d])=>({id:`${n}-${u}`,target:n,property:u,keyframes:d}))}function Fu(t,e){const n=t.toLowerCase(),s=e.toLowerCase();let i=Array.from({length:s.length+1},(r,o)=>o);for(let r=1;r<=n.length;r++){const o=[r];for(let a=1;a<=s.length;a++)o[a]=Math.min(i[a]+1,o[a-1]+1,i[a-1]+(n[r-1]===s[a-1]?0:1));i=o}return i[s.length]}function ai(t,e){const n=t.toLowerCase(),s=e.find(o=>o.toLowerCase().includes(n)||n.includes(o.toLowerCase()));if(s&&Math.min(t.length,s.length)>=3)return s;let i,r=1/0;for(const o of e){const a=Fu(t,o);a<r&&(r=a,i=o)}return i!==void 0&&r<=Math.max(2,Math.floor(t.length/3))?i:void 0}function dt(t,e,n,s){const i=typeof e=="string"?s??ai(e,n):void 0;return`Unknown ${t} ${JSON.stringify(e)}${i?`: did you mean "${i}"?`:"."} Known: ${n.join(", ")}`}function li(t,e){const n=e.step??33,s=e.stiffness??120,i=e.damping??9,r=e.mass??1;let o=t(e.start),a=0;const l=[{time:e.start,value:o}];let c=e.start+n;for(let h=e.start+1;h<=e.end;h++){const d=s*(t(h)-o)-i*a;a+=d/r*.001,o+=a*.001,(h>=c||h===e.end)&&(l.push({time:h,value:o}),c+=n)}return l}function xn(t,e,n=1){if(!(e>0))return 0;const s=t*n/e;return s-Math.floor(s)}function el(t){const e=t-Math.floor(t);return 1-Math.abs(e*2-1)}function s2(t,e){const n=Math.max(1,Math.round(e.cycles??1)),s=e.amplitude??1,i=xn(t,e.period,n)+(e.phase??0),r=i-Math.floor(i);switch(e.shape??"sine"){case"triangle":return s*(el(r+.25)*2-1);case"square":return r<.5?s:-s;default:return s*Math.sin(r*Math.PI*2)}}function i2(t,e){const n=Math.max(1,Math.round(e.cycles??1)),s=typeof e.easing=="function"?e.easing:Dt(e.easing??"ease-in-out"),i=xn(t,e.period,n)+(e.phase??0);return s(el(i))}function r2(t,e){const n=Lu(e.seed),s=Math.max(1,Math.round(e.cycles??1)),i=(xn(t,e.period,1)+(e.phase??0))*Math.PI*2,r=s/Math.PI;return Nu([Math.cos(i)*r+7.31,Math.sin(i)*r+3.17],n,e.octaves??1)}function o2(t,e,n){const s=Lu(n.seed),i=Math.max(1,Math.round(n.cycles??1)),r=Math.max(1,Math.round(n.cyclesAlong??1)),o=xn(t,n.period,1)*Math.PI*2,a=xn(e,n.periodAlong,1)*Math.PI*2,l=i/Math.PI,c=r/Math.PI;return Nu([Math.cos(o)*l+5.13,Math.sin(o)*l+9.47,Math.cos(a)*c+2.71,Math.sin(a)*c+6.29],s,n.octaves??1)}const Lu=t=>typeof t=="string"?re(t):(t??0)>>>0;function Nu(t,e,n){const s=Math.max(1,Math.min(6,Math.round(n)));let i=0,r=1,o=0;for(let a=0;a<s;a++){const l=2**a;i+=r*a2(t.map(c=>c*l),e+a*1013),o+=r,r*=.5}return i/o}function a2(t,e){const n=t.length,s=t.map(Math.floor),r=t.map((a,l)=>a-s[l]).map(a=>a*a*(3-2*a));let o=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?r[h]:1-r[h],c.push(s[h]+u)}l!==0&&(o+=l*l2(c,e))}return o}function l2(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 c2(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(r=>({time:r.at,value:r.value,easing:r.easing})).sort((r,o)=>r.time-o.time),interpolation:e.interpolation},i=new nn(s);return r=>i.getValueAtTime(r)}function h2(t,e){return e*ri({bpm:t.bpm})}function u2(t,e){const n=Math.max(1,Math.round(t/ri(e)));return{beats:n,grid:{...e,bpm:n*6e4/t}}}function d2(t,e,n={}){const s=Math.max(1e-6,n.attack??.05),i=Math.max(1e-6,n.decay??.4),r=oi(e,t),o=r-Math.floor(r),a=o<s?o/s:Math.max(0,1-(o-s)/i),l=n.barAccent??0;if(l<=0)return a;const c=Math.max(1,Math.round(e.beatsPerBar??4)),u=(Math.floor(r)%c+c)%c===0;return a*(u?1+l:1)/(1+l)}function f2(t,e,n={}){const s=n.fps??30,i=Math.max(1,Math.round(e/s)),r=Math.max(1,Math.ceil(t.length/i)),o=new Float32Array(r),a=Math.min(.99,Math.max(0,n.smoothing??.5));let l=0,c=0;for(let h=0;h<r;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 m=f>d?Math.sqrt(u/(f-d)):0;l=m>l?m:l*a+m*(1-a),o[h]=l,c=Math.max(c,l)}if(n.normalize!==!1&&c>0)for(let h=0;h<r;h++)o[h]/=c;return o}function g2(t,e,n=30,s){if(t.length===0)return 0;const r=(s?xn(e,s)*s:e)*n/1e3,o=Math.floor(r),a=t[Math.min(t.length-1,Math.max(0,o))],l=t[Math.min(t.length-1,Math.max(0,o+1))];return a+(l-a)*(r-o)}const Wu={"16:9":16/9,"2.39:1":2.39,"4:3":4/3,"1:1":1,"9:16":9/16,"4:5":4/5},nl=t=>typeof t=="number"?t:Wu[t];function m2(t,e){const n=nl(e),s=t.width/t.height;if(n>=s){const r=t.width/n;return{x:0,y:(t.height-r)/2,width:t.width,height:r}}const i=t.height*n;return{x:(t.width-i)/2,y:0,width:i,height:t.height}}function p2(t,e){const n=nl(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 y2(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 Ce=t=>Math.round(t*1e3)/1e3;function Du(t,e={}){if(t.length===0)return"";const n=e.curviness??1,s=e.closed??!1,i=t.length;let r=`M${Ce(t[0].x)} ${Ce(t[0].y)}`;if(i===1)return r;const o=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=o(l-1),h=o(l),u=o(l+1),d=o(l+2);if(n===0){r+=` L${Ce(u.x)} ${Ce(u.y)}`;continue}const f=n/6,m=h.x+(u.x-c.x)*f,g=h.y+(u.y-c.y)*f,p=u.x-(d.x-h.x)*f,y=u.y-(d.y-h.y)*f;r+=` C${Ce(m)} ${Ce(g)} ${Ce(p)} ${Ce(y)} ${Ce(u.x)} ${Ce(u.y)}`}return s?`${r} Z`:r}const zt=(t,e=0)=>{const n=parseFloat(t??"");return Number.isFinite(n)?n:e};function b2(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 xr(t){const e=t.attributes;switch(t.tag.toLowerCase()){case"path":return e.d??null;case"circle":case"ellipse":{const n=zt(e.cx),s=zt(e.cy),i=t.tag.toLowerCase()==="circle"?zt(e.r):zt(e.rx),r=t.tag.toLowerCase()==="circle"?zt(e.r):zt(e.ry);return`M${n+i} ${s} A${i} ${r} 0 1 1 ${n-i} ${s} A${i} ${r} 0 1 1 ${n+i} ${s} Z`}case"rect":{const n=zt(e.x),s=zt(e.y),i=zt(e.width),r=zt(e.height);let o=e.rx!=null?zt(e.rx):e.ry!=null?zt(e.ry):0,a=e.ry!=null?zt(e.ry):o;return o=Math.min(o,i/2),a=Math.min(a,r/2),o===0||a===0?`M${n} ${s} H${n+i} V${s+r} H${n} Z`:`M${n+o} ${s} H${n+i-o} A${o} ${a} 0 0 1 ${n+i} ${s+a} V${s+r-a} A${o} ${a} 0 0 1 ${n+i-o} ${s+r} H${n+o} A${o} ${a} 0 0 1 ${n} ${s+r-a} V${s+a} A${o} ${a} 0 0 1 ${n+o} ${s} Z`}case"line":return`M${zt(e.x1)} ${zt(e.y1)} L${zt(e.x2)} ${zt(e.y2)}`;case"polyline":case"polygon":{const n=b2(e.points);if(n.length===0)return null;const s=n.map((i,r)=>`${r===0?"M":"L"}${i.x} ${i.y}`).join(" ");return t.tag.toLowerCase()==="polygon"?`${s} Z`:s}default:return null}}function w2(t,e,n){const s=Math.max(2,Math.round(n.samples??32)),i=Math.max(0,n.length),r=n.since!==void 0?Math.max(e-i,n.since):e-i;if(r>=e)return[];const o=n.period,a=[];for(let l=0;l<s;l++){const c=r+(e-r)*l/(s-1),h=o&&o>0&&l<s-1?(c%o+o)%o:c;a.push({at:t(h),time:c,age:i>0?(e-c)/i:0})}return a}const k2=2.5;function Bu(t){const e=[],n=[],s=t.length,i=(r,o)=>{for(let a=r+o;a>=0&&a<s;a+=o){const l=(t[a].x-t[r].x)*o,c=(t[a].y-t[r].y)*o,h=Math.hypot(l,c);if(h>1e-9)return[l/h,c/h]}return null};for(let r=0;r<s;r++){const o=t[r],a=i(r,-1),l=i(r,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 m=u*c[0]+d*c[1],g=Math.min(k2,1/Math.max(m,1e-6)),p=o.width/2*g;e.push({x:o.x-d*p,y:o.y+u*p}),n.push({x:o.x+d*p,y:o.y-u*p})}return{left:e,right:n}}function zu(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,r=n.y-t[s].y,o=Math.hypot(i,r);if(o>1e-9)return{x:n.x,y:n.y,radius:n.width/2,start:Math.atan2(i/o,-r/o)}}return null}const v2={scale:1,turn:0,x:0,y:0};function M2(t={}){return{scale:t.scale??1,turn:t.turn??0,x:t.x??0,y:t.y??0}}function qu(t,e,n){const{ax:s,ay:i}=Pr(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 sl(t,e){const{ax:n,ay:s}=Pr(t.scale,t.turn);return{x:n*e.x-s*e.y+t.x,y:s*e.x+n*e.y+t.y}}function S2(t,e){const n=sl(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 T2(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=sl(e,{x:t.x,y:t.y});return{...e,x:-n.x,y:-n.y}}function ju(t){const{ax:e,ay:n}=Pr(t.scale,t.turn),s=1-e,i=-n,r=s*s+i*i;return r<1e-18?null:{x:(t.x*s+t.y*i)/r,y:(t.y*s-t.x*i)/r}}function E2(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=ju(t);return i?qu(n,s,i):{scale:n,turn:s,x:t.x*e,y:t.y*e}}function A2(t){const{ax:e,ay:n}=Pr(t.scale,t.turn);return[e,n,-n,e,t.x,t.y]}const Pr=(t,e)=>{const n=e*Math.PI/180;return{ax:t*Math.cos(n),ay:t*Math.sin(n)}};function $r([t,e,n],s={}){const i=s.scale??1,r=s.centre??{x:0,y:0},o=Math.sqrt(3)/2;return{x:r.x+(t-e)*o*i,y:r.y+((t+e)*.5-n)*i}}const il=([t,e,n])=>t+e+n;function rl(t,e={}){const[n,s,i]=t.min,[r,o,a]=t.max,l=d=>$r(d,e),c=[(n+r)/2,(s+o)/2,(i+a)/2],h=il(c),u=[{side:"top",depth:h,tag:t.tag,points:[l([n,s,a]),l([r,s,a]),l([r,o,a]),l([n,o,a])]},{side:"left",depth:h,tag:t.tag,points:[l([n,o,i]),l([r,o,i]),l([r,o,a]),l([n,o,a])]},{side:"right",depth:h,tag:t.tag,points:[l([r,s,i]),l([r,o,i]),l([r,o,a]),l([r,s,a])]}];return t.hide?u.filter(d=>!t.hide.includes(d.side)):u}function ol(t,e={}){return t.map(n=>({box:n,depth:il([(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})=>rl(n,e))}function x2(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]}],r=t.centre??{x:0,y:0},o=$r([2*e/3,e/3,e/3],{scale:t.scale}),a={centre:{x:r.x-o.x,y:r.y-o.y},scale:t.scale};return{boxes:i,faces:[...ol(i,a),...rl({...i[0],hide:["right"]},a)]}}function P2(t={}){const e=Math.max(2,Math.round(t.steps??8)),n=t.tread??1.5,s=t.rise??.25,i=t.width??3,r=t.base??1.5,o=Math.max(1,Math.round(e*(n-2*s)/(n+2*s))),a=2*(e+o),l=n*(e-o)/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:o},{dir:[0,-1,0],across:[1,0,0],count:o}],h=[];let u=[0,0,0],d=0;for(const y of c){for(let v=0;v<y.count;v++){const w=d*l,k=[u[0]+y.dir[0]*v*n,u[1]+y.dir[1]*v*n,0],S=[k[0]+y.dir[0]*n+y.across[0]*i,k[1]+y.dir[1]*n+y.across[1]*i,0];h.push({tag:d,min:[Math.min(k[0],S[0]),Math.min(k[1],S[1]),0],max:[Math.max(k[0],S[0]),Math.max(k[1],S[1]),w+r]}),d++}u=[u[0]+y.dir[0]*y.count*n,u[1]+y.dir[1]*y.count*n,0]}const f=a*l,m=t.centre??{x:0,y:0},g=$r([e*n/2,e*n/2,f/2+r],{scale:t.scale}),p={centre:{x:m.x-g.x,y:m.y-g.y},scale:t.scale};return{boxes:h,faces:ol(h,p),rise:l}}function Ku(t,e,n){let s=0;for(const i of t){const r=(e-i.x)**2+(n-i.y)**2;s+=r>1e-9?i.r*i.r/r:1e9}return s}function $2(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,r=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))},o=Math.max(2,Math.ceil(r.width/s)+1),a=Math.max(2,Math.ceil(r.height/s)+1),l=new Float64Array(o*a);for(let f=0;f<a;f++)for(let m=0;m<o;m++)l[f*o+m]=Ku(t,r.x+m*s,r.y+f*s)-n;const c=(f,m)=>l[m*o+f],h=(f,m,g,p,y,v)=>{const w=g===v?.5:g/(g-v);return{x:f+(p-f)*w,y:m+(y-m)*w}},u=[];for(let f=0;f+1<a;f++)for(let m=0;m+1<o;m++){const g=r.x+m*s,p=r.y+f*s,y=g+s,v=p+s,w=[c(m,f),c(m+1,f),c(m+1,f+1),c(m,f+1)],k=(w[0]>0?1:0)|(w[1]>0?2:0)|(w[2]>0?4:0)|(w[3]>0?8:0);if(k===0||k===15)continue;const S=()=>h(g,p,w[0],y,p,w[1]),x=()=>h(y,p,w[1],y,v,w[2]),M=()=>h(g,v,w[3],y,v,w[2]),E=()=>h(g,p,w[0],g,v,w[3]),T=(w[0]+w[1]+w[2]+w[3])/4>0;switch(k){case 1:case 14:u.push([E(),S()]);break;case 2:case 13:u.push([S(),x()]);break;case 3:case 12:u.push([E(),x()]);break;case 4:case 11:u.push([x(),M()]);break;case 6:case 9:u.push([S(),M()]);break;case 7:case 8:u.push([E(),M()]);break;case 5:T?u.push([E(),M()],[S(),x()]):u.push([E(),S()],[x(),M()]);break;case 10:T?u.push([E(),S()],[x(),M()]):u.push([E(),M()],[S(),x()]);break}}const d=I2(u);return e.smooth===!1?d:d.map(f=>Yu(Yu(f)))}function I2(t){const e=r=>`${Math.round(r.x*1e3)},${Math.round(r.y*1e3)}`,n=new Map;t.forEach(([r,o],a)=>{for(const l of[r,o]){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 r=0;r<t.length;r++){if(s[r])continue;s[r]=!0;const o=[t[r][0],t[r][1]];let a=t[r][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(o[0]))break;o.push(a)}o.length>=3&&i.push(o)}return i}function Yu(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 O2(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),r=t.x,o=t.y+i-s,a=Math.max(.1,n*(.35-.3*e)),l=o-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 w=v/h,k=a+(n-a)*Math.pow(1-w,1.6+1.4*e);u.push({x:r-k,y:t.y+c*w}),d.push({x:r+k,y:t.y+c*w})}const f=Math.max(8,Math.round(t.segments??12)),m=Math.acos(Math.min(1,a/s)),g=-m,p=Math.PI+m,y=[];for(let v=1;v<f;v++){const w=g+(p-g)*v/f;y.push({x:r+Math.cos(w)*s,y:o+Math.sin(w)*s})}return[...d,...y,...u.reverse()]}function C2(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)),r=t.wobble??.05,o=t.time??0,a=t.period?o/t.period:o/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+r*(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 _2(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),r=Math.PI*2/n*.6*(1-e);for(let o=0;o<n;o++){const a=o/n*Math.PI*2+.3,l=[];for(let c=0;c<=4;c++){const h=a-r/2+r*c/4;l.push({x:t.x+Math.cos(h)*i,y:t.y+Math.sin(h)*i})}s.push(l)}return s}function R2(t,e={}){const n=Math.max(.05,1+t);return{sx:e.keep==="volume"?1/Math.sqrt(n):1/n,sy:n}}function H2(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 ci(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function oe(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function Pn(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function We(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function hi(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 Ir(t){return Math.hypot(t[0],t[1],t[2])}function ui(t,e){return Ir(oe(t,e))}function Qt(t){const e=Ir(t);return e===0?[0,0,0]:Pn(t,1/e)}function $n(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 F2=Object.freeze(Object.defineProperty({__proto__:null,add:ci,cross:hi,distance:ui,dot:We,length:Ir,lerp:$n,normalize:Qt,scale:Pn,subtract:oe},Symbol.toStringTag,{value:"Module"})),L2=Math.PI/180;function Or(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function Ft(t,e){const n=new Array(16);for(let s=0;s<4;s++)for(let i=0;i<4;i++){let r=0;for(let o=0;o<4;o++)r+=t[o*4+i]*e[s*4+o];n[s*4+i]=r}return n}function In(t){return[1,0,0,0,0,1,0,0,0,0,1,0,t[0],t[1],t[2],1]}function On(t){return[t[0],0,0,0,0,t[1],0,0,0,0,t[2],0,0,0,0,1]}function Te(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 al(t,e,n){const s=Te(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 N2(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 ll(t){const[e,n,s,i,r,o,a,l,c,h,u,d,f,m,g,p]=t,y=e*o-n*r,v=e*a-s*r,w=e*l-i*r,k=n*a-s*o,S=n*l-i*o,x=s*l-i*a,M=c*m-h*f,E=c*g-u*f,T=c*p-d*f,A=h*g-u*m,P=h*p-d*m,I=u*p-d*g,O=y*I-v*P+w*A+k*T-S*E+x*M;if(Math.abs(O)<1e-12)return null;const _=1/O;return[(o*I-a*P+l*A)*_,(s*P-n*I-i*A)*_,(m*x-g*S+p*k)*_,(u*S-h*x-d*k)*_,(a*T-r*I-l*E)*_,(e*I-s*T+i*E)*_,(g*w-f*x-p*v)*_,(c*x-u*w+d*v)*_,(r*P-o*T+l*M)*_,(n*T-e*P-i*M)*_,(f*S-m*w+p*y)*_,(h*w-c*S-d*y)*_,(o*E-r*A-a*M)*_,(e*A-n*E+s*M)*_,(m*v-f*k-g*y)*_,(c*k-h*v+u*y)*_]}function W2(t,e,n,s){const i=1/Math.tan(t*L2/2),r=1/(n-s);return[i/e,0,0,0,0,i,0,0,0,0,(s+n)*r,-1,0,0,2*s*n*r,0]}function D2(t,e,n,s,i,r){const o=1/(e-t),a=1/(s-n),l=1/(r-i);return[2*o,0,0,0,0,2*a,0,0,0,0,-2*l,0,-(e+t)*o,-(s+n)*a,-(r+i)*l,1]}function B2(t,e,n=[0,1,0]){const s=Qt(oe(t,e)),i=Qt(hi(n,s)),r=hi(s,i);return[i[0],r[0],s[0],0,i[1],r[1],s[1],0,i[2],r[2],s[2],0,-We(i,t),-We(r,t),-We(s,t),1]}function ae(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],r=t[3]*e[0]+t[7]*e[1]+t[11]*e[2]+t[15];return r===1||r===0?[n,s,i]:[n/r,s/r,i/r]}const z2=Object.freeze(Object.defineProperty({__proto__:null,compose:al,fromQuat:Te,identity:Or,invert:ll,lookAt:B2,multiply:Ft,orthographic:D2,perspective:W2,scaling:On,transformPoint:ae,translation:In,transpose:N2},Symbol.toStringTag,{value:"Module"})),Cr={"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]},Xu={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 q2(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}Dt({type:"bounce",mode:"in"}),Dt({type:"bounce",mode:"in-out"});function di(t){const e=Gu.get(t.trim().toLowerCase());if(e)return e;const n=q2(t),s=/^steps\(\s*(\d+)\s*\)$/.exec(n);if(s){const o={type:"steps",count:Math.max(1,Number.parseInt(s[1],10))+1,position:"none"};return{easing:o,fn:Dt(o)}}const i=/^(elastic|bounce|back)\.(in|out|inout)(?:\(([^)]*)\))?$/.exec(n);if(i){const[,r,o,a]=i,l=(a??"").split(",").map(u=>Number.parseFloat(u)).filter(u=>Number.isFinite(u)),c=o==="inout"?"in-out":o;if(r==="back"&&l.length===0&&n in Cr)return{easing:{type:"cubic-bezier",points:Cr[n]}};const h=r==="elastic"?{type:"elastic",mode:c,...l[0]!==void 0&&{amplitude:l[0]},...l[1]!==void 0&&{period:l[1]}}:r==="bounce"?{type:"bounce",mode:c}:{type:"back",mode:c,...l[0]!==void 0&&{overshoot:l[0]}};return{easing:h,fn:Dt(h)}}return n in Xu?{easing:Xu[n]}:n in Cr?{easing:{type:"cubic-bezier",points:Cr[n]}}:{easing:"ease-out"}}const Gu=new Map;function cl(t,e){return Gu.set(t.trim().toLowerCase(),e.bezier?{easing:{type:"cubic-bezier",points:e.bezier},fn:e.fn}:{fn:e.fn,requiresBaking:"custom"}),t}function hl(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 Uu=/^\s*random\(\s*(\[.*\]|[^)]*)\s*\)\s*$/;function Vu(t){return typeof t=="string"&&Uu.test(t)}function j2(t=1){let e=hl(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),r=(l,c)=>{if(typeof l=="number")return l===0?c:Math.round(c/l)*l;if(Array.isArray(l))return Ju(l,c,1/0);if("values"in l)return Ju(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},o=(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]=ii(l[d])(l[d],c[d],h);return u}return ii(l)(l,c,h)}),wrap:((l,c,h)=>{if(Array.isArray(l)){const g=l,p=y=>g[(Math.round(y)%g.length+g.length)%g.length];return c===void 0?p:p(c)}const u=l,f=c-u,m=g=>f===0?u:((g-u)%f+f)%f+u;return h===void 0?m:m(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,r),random:((l,c,h,u)=>{if(Array.isArray(l)){const f=()=>l[Math.floor(e()*l.length)];return c===!0?f:f()}const d=()=>o(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,m,g)=>{const p=g.length,v=pr(f,p,{...c!==void 0?{amount:c}:{each:h??1},from:u}),w=c!==void 0?c:(h??1)*Oa(p,u),k=d&&w>0?d(v/w)*w:v;return l+k},pipe:(...l)=>c=>l.reduce((h,u)=>u(h),c),splitColor:l=>K2(l),getUnit:l=>typeof l=="number"?"":/^-?[\d.]+(?:e[-+]?\d+)?([a-z%]*)$/i.exec(l.trim())?.[1]??"",seed:l=>{e=hl(l)},resolveRandomString:l=>{const c=Uu.exec(l)?.[1]??"";if(c.startsWith("[")){const m=c.slice(1,-1).split(",").map(g=>g.trim()).filter(Boolean).map(g=>Number.isFinite(Number(g))?Number(g):g.replace(/^['"]|['"]$/g,""));return m[Math.floor(e()*m.length)]}const[h,u,d]=c.split(",").map(f=>Number.parseFloat(f));return o(h,u,Number.isFinite(d)?d:void 0)}}}function Ju(t,e,n){let s=e,i=1/0;for(const r of t){const o=Math.abs(r-e);o<i&&(i=o,s=r)}return i<=n?s:e}function K2(t){const e=t.trim(),n=/^#([0-9a-f]{3,8})$/i.exec(e)?.[1];if(n){const r=(n.length<=4?[...n].map(o=>o+o).join(""):n).match(/../g).map(o=>Number.parseInt(o,16));return r.length>=4?[r[0],r[1],r[2],Math.round(r[3]/255*1e3)/1e3]:[r[0],r[1],r[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 Y2=/^([+-])=\s*(-?[\d.]+)$/,X2=/^([<>])\s*(?:([+-])?=?\s*(-?[\d.]+))?$/;function fi(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 r=Y2.exec(i);if(r){const c=s(r[2]);return e.cursor+(r[1]==="-"?-c:c)}const o=X2.exec(i);if(o){const c=o[1]==="<"?e.previousStart:e.previousEnd;if(o[3]===void 0)return c;const h=s(o[3]);return c+(o[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 G2(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 U2(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),r=m=>({x:m%s,y:Math.floor(m/s)}),o=e.from??"start",a=Array.isArray(o)?{x:o[0]*(s-1),y:o[1]*(i-1)}:typeof o=="number"?r(Math.max(0,Math.min(t-1,o))):o==="end"?r(t-1):o==="center"||o==="edges"?{x:(s-1)/2,y:(i-1)/2}:{x:0,y:0},l=m=>{const{x:g,y:p}=r(m),y=Math.abs(g-a.x),v=Math.abs(p-a.y);return e.axis==="x"?y:e.axis==="y"?v:Math.hypot(y,v)};let c=Array.from({length:t},(m,g)=>l(g));const h=Math.max(...c);if(o==="edges"&&(c=c.map(m=>h-m)),o==="random"){const m=n.random??Math.random;c=c.map(()=>m()*h)}const u=e.amount!==void 0?e.amount:(e.each??0)*h,d=e.ease?di(e.ease):void 0,f=d?d.fn??Dt(d.easing):void 0;return c.map(m=>{const g=h===0?0:m/h;return(f?f(g):g)*u})}const ul=new Set(["duration","delay","ease","repeat","repeatDelay","yoyo","stagger","onComplete","onUpdate","onStart","onRepeat","onReverseComplete","repeatRefresh","keyframes","easeEach","scrollTo","id","immediateRender","overwrite","paused","scrollTrigger","spring"]),V2={rotation:"rotate",rotationZ:"rotate",rotationX:"rotateX",rotationY:"rotateY",transformPerspective:"perspective",perspective:"childPerspective"};function _r(t){const e={},n={};for(const[s,i]of Object.entries(t))ul.has(s)?e[s]=i:n[V2[s]??s]=i;return{config:e,properties:n}}function Rr(t,e){return t===void 0?e:t*1e3}function dl(t,e){if(t!==void 0)return typeof t=="number"?{each:t*1e3}:G2(t)?{offsets:U2(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 J2={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 Zu(t){return J2[t]}function Z2(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=Du(e.path,{curviness:e.curviness});else if(is(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 Q2(t){const e=typeof t=="string"||Array.isArray(t)?{path:t}:{...t};return{...e,start:e.end??1,end:e.start??0}}function Qu(t){return typeof t=="object"&&t!==null&&"shape"in t?t.shape:t}function tk(t){if(t.morphSVG===void 0)return t;const{morphSVG:e,...n}=t,s=Qu(e);if(typeof s!="string"||!is(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 ek(t,e){if(t===!0)return[0,e];if(t===!1)return[0,0];if(typeof t=="number")return[0,td(t,e)];const n=t.trim().split(/[\s,]+/).filter(Boolean),s=o=>{const a=Number.parseFloat(o);if(Number.isNaN(a))throw new Error(`gsap-compat: drawSVG "${t}" is not a length or percentage`);return td(o.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]),r=s(n[1]);return i<=r?[i,r]:[r,i]}function nk(t,e){const[n,s]=ek(t,e);return{strokeDasharray:[s-n,e],strokeDashoffset:-n}}function sk(t,e){if(t.drawSVG===void 0)return t;const{drawSVG:n,...s}=t;return{...s,...nk(n,e)}}function ik(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 td(t,e){return Math.max(0,Math.min(e,t))}function rk(t){let e=2166136261;for(let n=0;n<t.length;n++)e=Math.imul(e^t.charCodeAt(n),16777619);return e>>>0}function ok(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 r=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},...r!==void 0&&{revealDelay:Math.min(r,.999)},...i.tweenLength!==void 0&&{tweenLength:i.tweenLength},...i.rightToLeft!==void 0&&{rightToLeft:i.rightToLeft},seed:i.seed??rk(`${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 fl(t){return Math.max(.1,t/25)}function ak(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?fl(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(Qs(i))]:n.end!==void 0&&(i.end=Array.isArray(n.end)?[...n.end]:n.end),i}function lk(t){const e=t===!0?{}:typeof t=="string"?{preset:t}:t;if(e.preset!==void 0&&!(e.preset in wr))throw new Error(`gsap-compat: unknown spring preset "${e.preset}" — use one of ${Object.keys(wr).join(", ")}`);return{...e.preset?wr[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 ck(t,e){if(t===!0||typeof t=="string")return;const n=t.velocity;return typeof n=="number"?n:n?.[e]}class Cn{timeline;options;cursor=0;fallbackRandom=hl(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,gi(n),s)}from(e,n,s){const{config:i,properties:r}=_r(gi(n)),{motionPath:o,text:a,scrambleText:l,...c}=r,h=this.targetsOf(e)[0],u={...i};for(const m of Object.keys(c))u[m]=this.resolveStart(h,m);o!==void 0&&(u.motionPath=Q2(o));const d={},f=String(this.resolveStart(h,"text"));return a!==void 0&&(d.text=gl(a),u.text=typeof a=="object"?{...a,value:f}:f),l!==void 0&&(d.text=gl(l),u.scrambleText=typeof l=="object"?{...l,text:f}:f),this.build(e,{...c,...d},u,s)}fromTo(e,n,s,i){const{properties:r}=_r(gi(n));return this.build(e,r,gi(s),i)}set(e,n,s){return this.build(e,void 0,{...gi(n),duration:0},s)}get lastStart(){return this.previousStart}get lastEnd(){return this.previousEnd}addEvent(e){const n=Math.max(0,fi(e,this.context()));return this.previousStart=n,this.previousEnd=n,this.cursor=Math.max(this.cursor,n),n}timeOf(e){return fi(e,this.context())}addLabel(e,n){return this.labels.set(e,fi(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=fi(n,this.context());for(const r of e.timeline.tracks){if(!("keyframes"in r))continue;const o=Er({...r,id:this.nextTrackId(`nested-${r.id}`),keyframes:r.keyframes.map(a=>({...a,time:a.time+s}))});this.timeline.addTrack(o)}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:r,properties:o}=_r(s),{motionPath:a,text:l,scrambleText:c,inertia:h,...u}=o,d=this.targetsOf(e),f=fi(i,this.context()),m=Rr(r.delay,0),g=Rr(r.duration,500),p=dl(r.stagger,{count:d.length,columnsFromLayout:this.options.layoutColumns?()=>this.options.layoutColumns(d):void 0,random:this.options.random??this.fallbackRandom}),y=this.easingFor(r.ease),v=[],w=r.spring;let k=0,S=!1;for(const[P,I]of Object.entries(u)){const O=I;let _=n?.[P]!==void 0?n[P]:this.resolveStart(d[0],P);if(typeof _!=typeof O&&(this.warn(`no usable start value for "${P}" on "${d[0]}" — it will snap to ${String(O)}. Use fromTo() to animate it.`),_=O),w!==void 0&&(typeof _!="number"||typeof O!="number")&&this.warn(`spring works on numbers, so "${P}" on "${d[0]}" eases instead`),w!==void 0&&typeof _=="number"&&typeof O=="number"){const V={...lk(w),from:_,to:O,velocity:ck(w,P)??this.options.startVelocity?.(d[0],P)??0},tt=this.nextTrackId(`${d[0]}-${P}-spring`),J={id:tt,target:d[0],...d.length>1&&{targets:d},...p&&d.length>1&&{stagger:p},property:P,kind:"spring",spring:V,delay:f+m};this.timeline.addTrack(J),v.push(tt),k=Math.max(k,_0(V));for(const F of d)this.lastValues.set(`${F}|${P}`,O);continue}S=!0;const L=this.keyframesFor(_,O,g,y,r.ease),j=this.nextTrackId(`${d[0]}-${P}`);this.timeline.addTrack(Er({id:j,target:d[0],...d.length>1&&{targets:d},...p&&d.length>1&&{stagger:p},property:P,delay:f+m,keyframes:L,...P==="quaternion"&&{interpolation:"slerp"}})),v.push(j);for(const V of d)this.lastValues.set(`${V}|${P}`,O)}const x=ok({text:l,scrambleText:c},d[0],g);if(x){const P=n?.text??n?.scrambleText,I=P!==void 0?gl(P):this.resolveStart(d[0],"text"),O=this.nextTrackId(`${d[0]}-text`),_={id:O,target:d[0],...d.length>1&&{targets:d},...p&&d.length>1&&{stagger:p},property:"text",textConfig:{from:typeof I=="string"?I:String(I??""),...x},delay:f+m,keyframes:this.keyframesFor(0,1,g,y,r.ease)};this.timeline.addTrack(_),v.push(O);for(const L of d)this.lastValues.set(`${L}|text`,x.to)}if(a!==void 0){const{config:P,start:I,end:O}=Z2(a),_=this.nextTrackId(`${d[0]}-motionPath`),L={id:_,target:d[0],...d.length>1&&{targets:d},...p&&d.length>1&&{stagger:p},property:"motionPath",motionPathConfig:P,delay:f+m,keyframes:this.keyframesFor(I,O,g,y,r.ease)};this.timeline.addTrack(L),v.push(_)}if(h!==void 0)for(const[P,I]of Object.entries(h)){const O=this.resolveStart(d[0],P);if(typeof O!="number"){this.warn(`inertia on "${P}" needs a numeric start value; skipped`);continue}const _=ak(O,I),L=this.nextTrackId(`${d[0]}-${P}-inertia`),j={id:L,target:d[0],...d.length>1&&{targets:d},...p&&d.length>1&&{stagger:p},property:P,kind:"inertia",inertia:_,delay:f+m};this.timeline.addTrack(j),v.push(L),k=Math.max(k,ns(_));for(const V of d)this.lastValues.set(`${V}|${P}`,es(_))}const T=((h!==void 0||w!==void 0)&&!S&&!x&&a===void 0?k:Math.max(g,k))+(p&&d.length>1?Js(d.length,p):0),A=f+m+T;return this.previousStart=f+m,this.previousEnd=A,this.cursor=Math.max(this.cursor,A),{trackIds:v,start:f+m,end:A,kill:()=>{for(const P of v)this.timeline.removeTrack(P)}}}keyframesFor(e,n,s,i,r){const o={time:0,value:e};if(s<=0)return[{time:0,value:n}];const a=typeof r=="string"?di(r):void 0;if(a?.requiresBaking==="custom"||this.options.bakeEases&&Vs(i)){const c=a?.fn??Dt(i);return[o,...Ga(o,{time:s,value:n},c,{intervalMs:this.options.bakeIntervalMs})]}return[o,{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 r=this.options.defaults?.[n];if(r!==void 0)return r;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 o=Zu(n);return o!==void 0?(this.warn(`no start value for "${n}" on "${e}" — using the static default ${o}. GSAP would read the live DOM here; tinyfly cannot, so pass an explicit fromTo() or a defaults map.`),o):(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 di(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 gl(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 hk(t){return new Cn(t)}function gi(t){return ik(tk(t))}function uk(t){return!Array.isArray(t)||t.length!==4?null:`matrix3d(${Te(tn(t)).map(n=>Math.round(n*1e6)/1e6+0).join(", ")})`}const dk=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),fk="#ffffff",gk="rgba(0, 0, 0, 0.5)";function mk(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??fk})`),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??gk})`)}return e.length>0?e.join(" "):null}function pk(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 yk(t){if(!("ownerSVGElement"in t))return;const e=t.style;!e||e.transformBox||(e.transformBox="fill-box",e.transformOrigin||(e.transformOrigin="50% 50%"))}const ed=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"]),bk=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),wk=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],kk=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),vk=new Set(["originX","originY"]),Mk=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Sk=new Set(["drawOn"]),Tk={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},nd={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},Ek="http://www.w3.org/2000/svg";class _n{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,r=null,o=null,a=null;const l=n.has("motionPathX"),c=n.has("motionPathY"),h=n.has("motionPathRotate");for(const[m,g]of n)if(!(m==="x"&&l)&&!(m==="y"&&c)&&!((m==="rotate"||m==="rotateZ")&&h)&&!Sk.has(m)){if(bk.has(m))(s??={})[m]=g;else if(kk.has(m))typeof g=="number"&&((i??={})[m]=g);else if(vk.has(m))typeof g=="number"&&((r??={})[m]=g);else if(Mk.has(m))typeof g=="number"&&((o??={})[m]=g);else if(dk.has(m))(a??={})[m]=g;else if(m!=="perspective"){if(m!=="shine")if(m==="text"&&typeof g=="string")pk(e,g);else if(m==="d"&&typeof g=="string"){const p=e;(p.tagName?.toLowerCase()==="path"?p:p.querySelector?.("path"))?.setAttribute?.("d",g)}else this.applyStyleProperty(e,m,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 m of wk){const g=s[m];if(g===void 0)continue;const p=this.buildTransformPart(m,g);p&&d.push(p)}if(d.length>0&&(e.style.transform=d.join(" "),yk(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}%`)),r){const m=r.originX??50,g=r.originY??50;e.style.transformOrigin=`${m}% ${g}%`}if(o){const m=o.clipTop??0,g=o.clipRight??0,p=o.clipBottom??0,y=o.clipLeft??0;e.style.clipPath=`inset(${m}% ${g}% ${p}% ${y}%)`}if(a){const m=mk(a);m&&(e.style.filter=m)}}buildTransformPart(e,n){if(e==="quaternion")return uk(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,r=e.style;r.color="transparent",r.backgroundImage=`linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${s}, ${s})`,r.backgroundSize="250% 100%, 100% 100%",r.backgroundPosition=`${i}% 0, 0 0`,r.backgroundRepeat="no-repeat",r.webkitBackgroundClip="text",r.backgroundClip="text"}applyStyleProperty(e,n,s){let i;if(e.namespaceURI===Ek&&n in nd){const a=Array.isArray(s)?s.join(", "):String(s);e.style[nd[n]]=a;return}else n==="fill"&&e.dataset?.elementType==="text"?i="color":i=Tk[n]??n;let o;typeof s=="number"?ed.has(n)||ed.has(i)?o=`${s}px`:o=String(s):Array.isArray(s)?o=s.join(", "):o=s,e.style[i]=o}}const Ak={request:t=>requestAnimationFrame(t),cancel:t=>cancelAnimationFrame(t)};class sd{adapter=new _n;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=j2();active=new Map;applied=new Map;dirty=new Set;frameId=null;lastTimestamp=null;destroyed=!1;constructor(e={}){this.scheduler=e.scheduler??Ak,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);ml(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 r=i.currentTime;if(r<4)return 0;const o=i.getStateAtTime(r).values.get(e)?.get(n),a=i.getStateAtTime(r-4).values.get(e)?.get(n);if(typeof o!="number"||typeof a!="number")return;const l=(o-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[r,o]of s)i.set(r,o);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[r,o]of s)i[r]=o;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(ml(e))return[e];if(!xk(e))return[e];const n=[];for(const s of Array.from(e))n.push(...this.targetsOf(s));return n}nameFor(e){return ml(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 ml(t){return typeof t=="object"&&t!==null&&t.nodeType===1}function xk(t){if(Array.isArray(t))return!0;const e=t;return typeof e.length=="number"&&typeof e.item=="function"}function Hr(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 id=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function Pk(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function $k(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 Ik(t,e){const n=typeof t=="string"||Array.isArray(t)||id(t)?{path:t}:t,{align:s,alignOrigin:i,path:r,...o}=n,a=x=>{const M=id(x)?x:e.query(x);return M||e.warn(`gsap-compat: motionPath could not find "${String(x)}"`),M};let l=null,c="";if(Array.isArray(r)||typeof r=="string"&&is(r))c=r;else{l=a(r);const x=l&&xr({tag:l.localName,attributes:Pk(l)});l&&!x&&e.warn(`gsap-compat: motionPath element <${l.localName}> has no path geometry`),c=x??""}const h={...o,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,m,g,p,y,v]=$k(u),w=Hr(d),[k,S]=i??[.5,.5];for(const x of e.targets.slice(1)){const M=Hr(x);if(Math.abs(M.left-w.left)>.5||Math.abs(M.top-w.top)>.5){e.warn("gsap-compat: motionPath align measures the first target; the others are laid out elsewhere");break}}return h.matrix=[f,m,g,p,y-w.left-k*w.width,v-w.top-S*w.height],h}const rd=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function od(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function ad(t){if(!t)return null;const e=xr({tag:t.localName,attributes:od(t)});return e||(t.querySelector("path")?.getAttribute("d")??null)}function Ok(t,e,n){const s=Qu(t);if(typeof s=="string"&&is(s))return s;const i=rd(s)?s:typeof s=="string"?e(s):null,r=ad(i);return r||(n(`gsap-compat: morphSVG could not find a shape for "${String(s)}"`),"")}const Ck=new Set(["cx","cy","r","rx","ry","x","y","width","height","x1","y1","x2","y2","points"]);function _k(t,e=document){return(typeof t=="string"?Array.from(e.querySelectorAll(t)):rd(t)?[t]:Array.from(t)).map(s=>{if(s.localName==="path")return s;const i=xr({tag:s.localName,attributes:od(s)});if(!i||!s.parentNode)return s;const r=s.ownerDocument.createElementNS("http://www.w3.org/2000/svg","path");for(const o of Array.from(s.attributes))Ck.has(o.name)||r.setAttribute(o.name,o.value);return r.setAttribute("d",i),s.parentNode.replaceChild(r,s),r})}const ld=.3;class cd{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=hd(),this.options.onPress?.(this.stateFrom(0,0,s))}move(e,n,s){if(!this.dragging)return;const i=e-this.lastX,r=n-this.lastY;this.lastX=e,this.lastY=n;const o=e-this.startX,a=n-this.startY,l=this.options.tolerance??3;if(!this.passedTolerance){if(Math.hypot(o,a)<l)return;this.passedTolerance=!0}this.updateVelocity(i,r),this.options.preventDefault!==!1&&s.cancelable&&s.preventDefault(),this.options.onMove?.(this.stateFrom(i,r,s))}end(e){this.dragging&&(this.dragging=!1,this.options.onRelease?.(this.stateFrom(0,0,e)))}updateVelocity(e,n){const s=hd(),i=Math.max(1,s-this.lastTime);this.lastTime=s;const r=e/i*1e3,o=n/i*1e3;this.velocityX+=(r-this.velocityX)*ld,this.velocityY+=(o-this.velocityY)*ld}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 hd(){return typeof performance<"u"?performance.now():Date.now()}function ud(t,e,n){let s={delta:0,line:null},i=n;for(const r of t)for(const o of e){const a=Math.abs(o-r);a<=i&&(i=a,s={delta:o-r,line:o})}return s}function dd(t,e){return e<=0?[]:t.map(n=>Math.round(n/e)*e)}class pl{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 cd({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,r=Rk(i/s);e.pause(),e.seek(r*n)}applyConstraints(e,n){let s=e;const i=[...dd([s],this.options.snap??0),...(n==="x"?this.options.snapLinesX:this.options.snapLinesY)??[]],r=ud([s],i,this.snapThreshold());s+=r.delta,n==="x"?this.snappedX=r.line:this.snappedY=r.line;const o=this.options.bounds;if(o){const a=n==="x"?o.minX:o.minY,l=n==="x"?o.maxX:o.maxY;a!==void 0&&(s=Math.max(a,s)),l!==void 0&&(s=Math.min(l,s))}return s}}function Rk(t){return t<0?0:t>1?1:t}function Hk(t){const e=new pl(t);return e.start(),e}const Fk={x:"x",y:"y","x,y":"both"},yl=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function fd(t,e){const n=Hr(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 gd(t){return Array.isArray(t)?[...t]:t}function Lk(t,e,n,s={}){const[i]=e.resolveTargets(n),r=i?e.elementFor(i):void 0;if(!i||!r)throw new Error(`gsap-compat: live.draggable could not find ${String(n)}`);if(s.type==="rotation")return Nk(t,e,i,r,s);const o=Fk[s.type??"x,y"],a=()=>{const g=e.appliedValue(i,"x"),p=e.appliedValue(i,"y");return{x:typeof g=="number"?g:0,y:typeof p=="number"?p:0}},l=typeof s.bounds=="string"?e.query(s.bounds):yl(s.bounds)?s.bounds:null,h={bounds:(!l&&s.bounds&&!yl(s.bounds)?s.bounds:void 0)??(l?fd(r,l):void 0)};let u=null;const d=()=>{u?.kill(),u=null},f=g=>{const p=s.inertia===!0?{}:s.inertia,y=p.friction??(p.resistance!==void 0?fl(p.resistance):4),v=a(),w=h.bounds??{};let k,S;const x=p.end;if(Array.isArray(x)){const E=Qs({from:v.x,velocity:o==="y"?0:g.x,friction:y}),T=Qs({from:v.y,velocity:o==="x"?0:g.y,friction:y});let A=x[0];for(const P of x)Math.hypot(P.x-E,P.y-T)<Math.hypot(A.x-E,A.y-T)&&(A=P);A&&(k=[A.x],S=[A.y])}else typeof x=="number"?(k=x,S=x):x&&(k=gd(x.x),S=gd(x.y));const M={};o!=="y"&&(M.x={velocity:g.x,friction:y,min:w.minX,max:w.maxX,end:k}),o!=="x"&&(M.y={velocity:g.y,friction:y,min:w.minY,max:w.maxY,end:S}),u=t.to(r,{inertia:M,onComplete:()=>s.onThrowComplete?.()})},m=new pl({target:r,axis:o,snap:s.snap,get bounds(){return h.bounds},getPosition:a,onPress:()=>{d(),l&&(h.bounds=fd(r,l)),s.onPress?.()},onDrag:g=>{e.apply(i,o==="x"?{x:g.x}:o==="y"?{y:g.y}:{x:g.x,y:g.y}),s.onDrag?.(g)},onRelease:()=>{const g=m.velocity;s.onRelease?.(g),s.inertia&&f(g)}});return m.start(),{draggable:m,get position(){return a()},get rotation(){const g=e.appliedValue(i,"rotate");return typeof g=="number"?g:0},destroy(){d(),m.destroy()}}}function Nk(t,e,n,s,i){const r=typeof i.bounds=="object"&&i.bounds!==null&&!yl(i.bounds)?i.bounds:{},o=()=>{const w=e.appliedValue(n,"rotate");return typeof w=="number"?w:0},a=w=>Math.min(r.maxRotation??1/0,Math.max(r.minRotation??-1/0,w));let l=null,c=!1,h,u={x:0,y:0},d=0,f=0,m=[];const g=w=>Math.atan2(w.clientY-u.y,w.clientX-u.x)*180/Math.PI,p=w=>{if(c)return;l?.kill(),l=null,c=!0,h=w.pointerId,s.setPointerCapture?.(w.pointerId);const k=s.getBoundingClientRect();u={x:k.left+k.width/2,y:k.top+k.height/2},d=g(w),f=o(),m=[{time:performance.now(),rotation:f}],i.onPress?.()},y=w=>{if(!c||w.pointerId!==h)return;const k=g(w);let S=k-d;S>180&&(S-=360),S<-180&&(S+=360),d=k,f+=S;let x=a(f);i.snap&&(x=a(Math.round(x/i.snap)*i.snap)),e.apply(n,{rotate:x});const M=performance.now();for(m.push({time:M,rotation:x});m.length>2&&M-m[0].time>100;)m.shift();const E={x:0,y:0};i.onDrag?.(E)},v=w=>{if(!c||w.pointerId!==h)return;c=!1;const k=m[0],S=m[m.length-1],x=k&&S?(S.time-k.time)/1e3:0,M=x>0?(S.rotation-k.rotation)/x:0;if(i.onRelease?.({x:M,y:0}),!i.inertia)return;const E=i.inertia===!0?{}:i.inertia,T=E.friction??(E.resistance!==void 0?fl(E.resistance):4),A=typeof E.end=="number"||Array.isArray(E.end)?E.end:void 0;l=t.to(s,{inertia:{rotate:{velocity:M,friction:T,min:r.minRotation,max:r.maxRotation,end:Array.isArray(A)?A.filter(P=>typeof P=="number"):A}},onComplete:()=>i.onThrowComplete?.()})};return s.addEventListener("pointerdown",p),s.addEventListener("pointermove",y),s.addEventListener("pointerup",v),s.addEventListener("pointercancel",v),s.style.touchAction="none",{draggable:void 0,position:{x:0,y:0},get rotation(){return o()},destroy(){l?.kill(),s.removeEventListener("pointerdown",p),s.removeEventListener("pointermove",y),s.removeEventListener("pointerup",v),s.removeEventListener("pointercancel",v)}}}const Wk={opacity:0,scale:.6};function Dk(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 md(t){const e=Hr(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 bl(t,e){const s=t.resolveTargets(e).map(o=>t.elementFor(o)).filter(o=>!!o),i=new Map,r=new Map;for(const o of s){const a=Dk(o);i.set(o,a);const l=pd(o);a&&l!==void 0&&!r.has(l)&&r.set(l,{element:o,box:a})}return{elements:s,boxes:i,ids:r}}const wl=new WeakMap;function kl(t,e,n,s={}){const i=s.duration??.6,r=s.ease??"power2.inOut",o=s.stagger??0,a=s.scale!==!1,l=s.enter===void 0?Wk:s.enter,c=new Set(n.elements);if(s.targets!==void 0)for(const f of t.resolveTargets(s.targets)){const m=t.elementFor(f);m&&c.add(m)}const h=[...c].sort((f,m)=>f===m?0:f.compareDocumentPosition(m)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1),u=e({onComplete:s.onComplete});let d=0;for(const f of h){const m=md(f);if(!m)continue;let g=n.boxes.get(f)??null,p;const y=pd(f),v=!g&&y!==void 0?n.ids.get(y):void 0;v&&v.element!==f&&(g=v.box,p=v.element);const[w]=t.resolveTargets(f);wl.get(f)?.timeline.removeTracks({target:w});const k=d*o;if(!g){if(l===!1)continue;u.fromTo(f,{x:0,y:0,scaleX:1,scaleY:1,...l},{...yd(l),x:0,y:0,scaleX:1,scaleY:1,duration:i,ease:r,delay:k},0),wl.set(f,u),d++;continue}const S=g.cx-m.cx,x=g.cy-m.cy,M=a?g.width/m.width:1,E=a?g.height/m.height:1;if(!(Math.abs(S)>.5||Math.abs(x)>.5||Math.abs(M-1)>.001||Math.abs(E-1)>.001)){const P=(I,O)=>{const _=t.appliedValue(w,I);return typeof _=="number"&&Math.abs(_-O)>1e-6};(P("x",0)||P("y",0)||P("scaleX",1)||P("scaleY",1))&&u.set(f,{x:0,y:0,scaleX:1,scaleY:1},0);continue}const A=s.fade===!0&&p!==void 0;u.fromTo(f,{x:S,y:x,scaleX:M,scaleY:E,...A&&{opacity:0}},{x:0,y:0,scaleX:1,scaleY:1,...A&&{opacity:1},duration:i,ease:r,delay:k},0),A&&p&&md(p)&&u.fromTo(p,{opacity:1},{opacity:0,duration:i,ease:r,delay:k},0),wl.set(f,u),d++}return u}function pd(t){return t.dataset?.flipId}function yd(t){const e={};for(const n of Object.keys(t))e[n]=n==="opacity"||n.startsWith("scale")?1:0;return e}function Bk(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,r=t.map(g=>({element:g,html:g.innerHTML,ariaLabel:g.getAttribute("aria-label")}));let o={chars:[],words:[],lines:[],masks:[]},a,l,c=!1;const h=()=>{for(const{element:g,html:p,ariaLabel:y}of r)g.innerHTML=p,y===null?g.removeAttribute("aria-label"):g.setAttribute("aria-label",y)},u=()=>{a&&(a.revert?a.revert():a.kill?.(),a=void 0)},d=()=>{const g={chars:[],words:[],lines:[],masks:[]};for(const{element:p}of r){const y=(p.textContent??"").replace(/\s+/g," ").trim(),v=zk(p,s.words),w=n.has("chars")?v.flatMap(x=>qk(x,s.chars)):[],k=n.has("lines")?Kk(p,v,s.lines):[];if(i){!p.hasAttribute("aria-label")&&y&&p.setAttribute("aria-label",y);for(const x of v)x.setAttribute("aria-hidden","true")}if(n.has("words"))g.words.push(...v);else for(const x of v)x.removeAttribute("class");g.chars.push(...w),g.lines.push(...k);const S=e.mask==="lines"?k:e.mask==="words"?v:e.mask==="chars"?w:[];for(const x of S)g.masks.push(Yk(x,`${s[e.mask]}-mask`))}o=g},f={elements:t,get chars(){return o.chars},get words(){return o.words},get lines(){return o.lines},get masks(){return o.masks},split(){c||(u(),h(),d(),a=e.onSplit?.(f))},revert(){c=!0,l?.disconnect(),u(),h()}};d(),a=e.onSplit?.(f),e.autoSplit&&m();function m(){const g=new Map;let p=!1;const y=()=>{if(p)return;p=!0;const w=()=>{p=!1,f.split()};typeof requestAnimationFrame=="function"?requestAnimationFrame(w):setTimeout(w,0)};if(typeof ResizeObserver=="function"){l=new ResizeObserver(w=>{let k=!1;for(const S of w){const x=Math.round(S.contentRect.width),M=g.get(S.target);g.set(S.target,x),M!==void 0&&M!==x&&(k=!0)}k&&y()});for(const w of t)l.observe(w)}const v=t[0]?.ownerDocument?.fonts;v&&v.status!=="loaded"&&v.ready.then(()=>y())}return f}function zk(t,e){const n=t.ownerDocument,s=[],i=n.createTreeWalker(t,4),r=[];for(let o=i.nextNode();o;o=i.nextNode())r.push(o);for(const o of r){const a=o.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)}o.replaceWith(l)}return s}function qk(t,e){const n=t.ownerDocument,s=jk(t.textContent??"").map(i=>{const r=n.createElement("span");return r.className=e,r.style.display="inline-block",r.textContent=i,r});return t.replaceChildren(...s),s}function jk(t){const e=Intl.Segmenter;return e?Array.from(new e(void 0,{granularity:"grapheme"}).segment(t),n=>n.segment):Array.from(t)}function Kk(t,e,n){const s=t.ownerDocument,i=new Map(e.map(m=>[m,m.getBoundingClientRect()])),r=[],o=m=>{for(const g of Array.from(m.childNodes))g.nodeType===3||i.has(g)||g.tagName==="BR"?r.push(g):o(g)};o(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 m of r){if(m.tagName==="BR"){u=!0;continue}const g=i.get(m);if(g&&(!l||u||g.top>c+h)&&(f(),c=g.top,h=g.height/2,u=!1),!l)continue;const p=[];for(let w=m.parentNode;w&&w!==t;w=w.parentNode)p.unshift(w);let y=0;for(;y<d.length&&y<p.length&&d[y].original===p[y];)y++;d.length=y;let v=y===0?l:d[y-1].clone;for(const w of p.slice(y)){const k=w.cloneNode(!1);v.appendChild(k),d.push({original:w,clone:k}),v=k}v.appendChild(m)}return t.replaceChildren(...a),a}function Yk(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 bd={top:0,left:0,start:0,center:.5,centre:.5,middle:.5,bottom:1,right:1,end:1};function vl(t){const e=t.trim().toLowerCase();if(e in bd)return bd[e];if(e.endsWith("%")){const n=Number.parseFloat(e.slice(0,-1));return Number.isNaN(n)?void 0:n/100}}function Ml(t){if(typeof t=="number")return{elementFraction:0,viewportFraction:0,offsetPx:0,absolutePx:t};let e=0;const s=t.replace(/([+-])=\s*(-?[\d.]+)/g,(o,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?vl(s[0]):void 0,r=s[1]!==void 0?vl(s[1]):void 0;return{elementFraction:i??0,viewportFraction:r??0,offsetPx:e}}function cs(t,e,n){const s=Ml(n),i=s.absolutePx!==void 0?t.top+s.absolutePx:t.top+t.height*s.elementFraction,r=e*s.viewportFraction;return i-r+s.offsetPx}function Xk(t,e,n,s){const i=cs(t,e,n),o=cs(t,e,s)-i;return o<=0?i<=0?1:0:Sl(-i/o)}function Sl(t){return t<0?0:t>1?1:t===0?0:t}function wd(t,e,n,s){if(n<=0)return e;const i=1-Math.exp(-(s/1e3)/n);return t+(e-t)*i}function Tl(t,e,n,s,i){const r=h=>cs({top:t+i(h),bottom:t+i(h)+e,height:e},n,s),o=r(0),a=r(1);if(Math.sign(o)===Math.sign(a)||o===0||a===0)return o===0?0:a===0?1:Math.abs(o)<Math.abs(a)?0:1;let l=0,c=1;for(let h=0;h<40;h++){const u=(l+c)/2;Math.sign(r(u))===Math.sign(o)?l=u:c=u}return(l+c)/2}class kd{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 Gk(t){const e=new kd(t);return e.start(),e}class vd{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 Uk=.15;function Md(t){return typeof t=="object"&&!Array.isArray(t)?t:{snapTo:t}}function Sd(t,e,n){const s=Fr(t+e*Uk);if(typeof n=="function")return Fr(n(s));if(typeof n=="number")return n<=0?t:Fr(Math.round(s/n)*n);if(n.length===0)return t;let i=n[0];for(const r of n)Math.abs(r-s)<Math.abs(i-s)&&(i=r);return Fr(i)}function Td(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 Ed{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=ti,r){if(this.cancel(),typeof requestAnimationFrame>"u"||s<=0){this.write(n),r?.();return}for(const l of this.cancelEvents)this.eventTarget?.addEventListener(l,this.onInterrupt,{passive:!0});let o=null;const a=l=>{o??=l;const c=Math.min(1,(l-o)/(s*1e3));this.write(e+(n-e)*i(c)),c<1?this.rafId=requestAnimationFrame(a):(this.rafId=null,this.detach(),r?.())};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 Fr(t){return Math.max(0,Math.min(1,t))}class Ad{options;scroller;nodes=[];scrollerStart;scrollerEnd;start;end;constructor(e,n,s){this.options=s===!0?{}:s,this.scroller=n;const{startColor:i="#3ecf7a",endColor:r="#ff5a5a",id:o}=this.options,a=o?`${o} `:"",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",r,!n),this.start=l("start",i,!1),this.end=l("end",r,!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 Vk=120,hs=[],us=new Set;let El=!1;const Jk=()=>{El||us.size===0||(El=!0,queueMicrotask(()=>{El=!1;for(const t of us)t.afterRefresh()}))},xd=()=>{for(const t of us)t.beforeRefresh();for(const t of hs)t.refresh();for(const t of us)t.afterRefresh()};let ds={width:0,height:0};const Pd=()=>{const t=window.innerWidth,e=window.innerHeight,n=t===ds.width&&e!==ds.height,s=Math.abs(e-ds.height)<ds.height*.25,i=typeof navigator<"u"&&(navigator.maxTouchPoints??0)>0;n&&s&&i||(ds={width:t,height:e},xd())};class mi{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 Ed(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 vd(e,{axis:this.options.horizontal?"x":"y",spacing:this.options.pinSpacing!==!1})),this.options.markers&&!this.options.horizontal&&typeof document<"u"&&(this.markers=new Ad(document,this.options.scroller??null,this.options.markers)),this.scrollTarget()?.addEventListener("scroll",this.onScroll,{passive:!0}),hs.length===0&&typeof window<"u"&&(ds={width:window.innerWidth,height:window.innerHeight},window.addEventListener("resize",Pd,{passive:!0})),hs.push(this),this.refresh()}stop(){this.running&&(this.running=!1,this.scrollTarget()?.removeEventListener("scroll",this.onScroll),hs.splice(hs.indexOf(this),1),hs.length===0&&typeof window<"u"&&window.removeEventListener("resize",Pd),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(){xd()}static onRefresh(e){return us.add(e),()=>us.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+cs(n,s,pi(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,Jk()}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?Sl((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=pi(this.options.end)??"bottom top",r=typeof i=="string"?i.trim().match(/^\+=\s*(-?[\d.]+)\s*(%|px)?$/):null;if(r){const o=Number.parseFloat(r[1]);return this.startPx+(r[2]==="%"?n*o/100:o)}return s+cs(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()},Vk))}fireBoundaryCallbacks(e,n){if(e===n)return;const{onEnter:s,onLeave:i,onEnterBack:r,onLeaveBack:o}=this.options;e==="before"?(s?.(),n==="after"&&i?.()):e==="after"?(r?.(),n==="before"&&o?.()):n==="after"?i?.():o?.()}scheduleSnap(){const e=this.options.snap;if(e===void 0||this.snapper.active)return;const n=Md(e),s=()=>{this.snapTimer=null;const i=this.endPx-this.startPx,r=this.scrollPosition();if(!this.running||i<=0||r<=this.startPx||r>=this.endPx)return;const o=(r-this.startPx)/i,a=this.startPx+Sd(o,this.releaseVelocity/i,n.snapTo)*i;Math.abs(a-r)<1||this.snapper.animate(r,a,Td(n,a-r,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,r=this.options.scroller?this.options.scroller.clientWidth:typeof window<"u"?window.innerWidth:0,o=s.left-i-e.shiftAt(e.progress()),{start:a,end:l}=e.range(),c=f=>a+f*(l-a),h=Tl(o,s.width,r,pi(this.options.start)??"left right",e.shiftAt);this.startPx=c(h);const u=pi(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(Tl(o,s.width,r,u,e.shiftAt)),this.markerGeometry=null}markersFor(e){const n=(r,o)=>{const a=pi(r)??o;if(typeof a=="number")return 0;if(/^\s*\+=/.test(a))return;const l=Ml(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=wd(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,r=n?e.width??0:e.height,o=this.options.scroller;if(o&&typeof o.getBoundingClientRect=="function"){const a=o.getBoundingClientRect(),l=n?a.left:a.top;return{top:s-l,bottom:i-l,height:r}}return{top:s,bottom:i,height:r}}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 pi(t){return typeof t=="function"?t():t}function Zk(t){const e=new mi(t);return e.start(),e}const Al=new Set,Qk=16,$d=.5,t5=2;class xl{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),Al.add(this),this.stopListening=mi.onRefresh({beforeRefresh:()=>this.rest(),afterRefresh:()=>this.refresh()}),this.refresh(),this}static refreshAll(){for(const e of Al)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),Al.delete(this),this.stopListening?.(),this.stopListening=null,this.cancelFrame(),this.journey=null,this}destroy(){this.stop();for(const e of this.effects)Pl(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),r=this.reduced?0:n.duration??Math.min(1.2,Math.max(.4,i/2500));if(r<=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:r*1e3,ease:n.ease??ti,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(),r=this.options.scroller?.getBoundingClientRect().top??0;for(const o of n.querySelectorAll(e)){const a=Number.parseFloat(o.dataset.speed??""),l=Number.parseFloat(o.dataset.lag??""),c=o.getBoundingClientRect(),h=c.top-r+s;this.effects.push({element:o,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:o.style.getPropertyValue("translate")})}}this.current=this.target=this.clamp(this.position()),this.applyEffects(0)}rest(){for(const e of this.effects)Pl(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?Qk: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)<=t5||(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 r=this.journey;r.elapsed+=n;const o=Math.min(1,r.elapsed/r.ms);this.current=r.from+(r.to-r.from)*r.ease(o),o>=1&&(this.journey=null)}else if(this.current!==this.target){const r=(this.options.smooth??.8)*1e3/3;this.current+=(this.target-this.current)*(1-Math.exp(-n/r)),Math.abs(this.target-this.current)<$d&&(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 r=0;if(i.speed!==void 0&&(r+=(s-i.centre)*(1-i.speed)),i.lag!==void 0){const o=i.lag*1e3/3;i.lagged=e===0?s:i.lagged+(s-i.lagged)*(1-Math.exp(-e/o)),Math.abs(s-i.lagged)<$d?i.lagged=s:n=!0,r+=s-i.lagged}Pl(i.element,r===0?i.saved:`0 ${e5(r)}px`),i.shift=r}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,r=this.effects.find(o=>o.element===s)?.shift??0;return s.getBoundingClientRect().top-i+this.position()-r}}function Pl(t,e){e?t.style.setProperty("translate",e):t.style.removeProperty("translate")}function e5(t){return Math.round(t*100)/100}function n5(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 $l(t,e,n,s,i=()=>{}){const r=f=>typeof f=="string"?t.query(f)??void 0:f,o=r(e.trigger)??s;if(!o){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,m)=>()=>{m?.(),n&&!a&&n5(n,l[f]??"none"),e.once&&f===0&&queueMicrotask(()=>h.destroy())},d=e.containerAnimation?r5(t,e.containerAnimation,o,i):void 0;return h=new mi({trigger:o,start:e.start,end:e.end,scrub:a===!1?void 0:a,pin:e.pin===!0?!0:r(e.pin),scroller:r(e.scroller),horizontal:e.horizontal,pinSpacing:e.pinSpacing,onRefresh:e.invalidateOnRefresh&&n?.invalidate?()=>n.invalidate():void 0,snap:e.snap===void 0?void 0:s5(e.snap,n),markers:e.markers,container:d,onUpdate:(f,m)=>{if(n&&a!==!1&&n.progress(f),e.onUpdate){const g=f<c||m<0?-1:1;e.onUpdate({progress:f,velocity:m,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 s5(t,e){const n=i=>i==="labels"?r=>i5(r,e?.labelProgresses?.()??[]):i;if(typeof t!="object"||Array.isArray(t))return n(t);const s=t.ease?di(t.ease):void 0;return{snapTo:n(t.snapTo),duration:t.duration,delay:t.delay,ease:s?s.fn??Dt(s.easing):void 0}}function i5(t,e){return e.reduce((n,s)=>Math.abs(s-t)<Math.abs(n-t)?s:n,e[0]??t)}function r5(t,e,n,s){const i=()=>e.timeline.getTracks({property:"x"}).map(r=>r.target).filter(r=>{const o=t.elementFor(r);return!!o&&o!==n&&o.contains(n)});return i().length===0&&s("gsap-compat: containerAnimation does not move an ancestor of the trigger along x"),{range:()=>{const r=e.scrollTrigger;return r||s("gsap-compat: containerAnimation needs its own scrollTrigger (created before this one)"),{start:r?.startOffset??0,end:r?.endOffset??0}},progress:()=>e.progress(),shiftAt:r=>{const o=e.timeline.getStateAtTime(r*e.timeline.duration);let a=0;for(const l of i()){const c=o.values.get(l)?.get("x");typeof c=="number"&&(a+=c)}return a}}}class Id{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 o5{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[r,o]of Object.entries(i)){const a=window.matchMedia(o);s.queries.set(r,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[o,a]of e.queries)n[o]=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 r=new Id(this.host,this.scope);r.conditions=n,r.add(()=>e.setup(r)),e.context=r}}class a5{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:r}=this.canvas,o=(this.options.fit??"cover")==="cover"?Math.max(i/s.naturalWidth,r/s.naturalHeight):Math.min(i/s.naturalWidth,r/s.naturalHeight),a=s.naturalWidth*o,l=s.naturalHeight*o;this.context.clearRect(0,0,i,r),this.context.drawImage(s,(i-a)/2,(r-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 r=Math.round(this.current);(Math.abs(e-r)<Math.abs(this.drawn-r)||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 l5={opacity:0,y:-16},c5={opacity:0,y:16};async function h5(t,e,n,s){const i=e.collector?.scope??e.root,r=i.ownerDocument??i,o=()=>s.shared?[...i.querySelectorAll(s.shared)]:[];if(s.native&&typeof r.startViewTransition=="function")return u5(r,s,o);const a=s.duration??.35,l=s.ease??"power2.inOut",c=p=>new Promise(y=>{p(y)||y()}),h=o(),u=h.length?bl(e,h):void 0,d=s.from!==void 0?Od(e,s.from,s.shared):[];if(d.length&&s.leave!==!1){const p=s.leave??l5;await c(y=>t.to(d,{...p,duration:a,ease:l,onComplete:y}))}await s.update();const f=[],m=typeof s.to=="function"?s.to():s.to,g=m!==void 0?Od(e,m,s.shared):[];if(g.length&&s.enter!==!1){const p=s.enter??c5;f.push(c(y=>t.fromTo(g,p,{...yd(p),duration:a,ease:l,onComplete:y})))}if(u){const p=o().filter(y=>!h.includes(y));p.length&&f.push(c(y=>kl(e,n,u,{targets:p,duration:a*1.4,ease:l,enter:!1,onComplete:y})))}await Promise.all(f)}function Od(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(r=>!r.matches(n)&&!r.querySelector(n))):s}async function u5(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 r=[];await t.startViewTransition(async()=>{i.forEach(a=>s(a,!1)),await e.update(),r=n(),r.forEach(a=>s(a,!0))}).finished,r.forEach(a=>s(a,!1))}const Cd={create:(t,e)=>cl(t,Ou(e))},_d={create:(t,e)=>cl(t,{fn:Cu(e)})},Rd={create:(t,e)=>cl(t,{fn:_u(e)})},d5=new Set(["keyframes","duration","delay","ease","easeEach","stagger","repeat","repeatDelay","yoyo","repeatRefresh","paused","id","onStart","onUpdate","onComplete","onRepeat","onReverseComplete","scrollTrigger"]),Hd=.5,f5="power1.inOut";function g5(t){return t.keyframes!==void 0&&t.keyframes!==null}function m5(t){const e=t.keyframes,n={};for(const[c,h]of Object.entries(t))d5.has(c)||(n[c]=h);if(Array.isArray(e))return e.map(c=>({...n,...c,duration:c.duration??t.duration??Hd}));const s=Object.entries(e),i=t.duration??Hd,r=e.easeEach??t.easeEach??f5;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 m=Math.max(0,d-u);h.push({...n,ease:r,...f,duration:m*i}),u=d}return h}const o=s.filter(([c,h])=>c!=="easeEach"&&Array.isArray(h)),a=Math.max(0,...o.map(([,c])=>c.length)),l=[];for(let c=0;c<a;c++){const h={...n,ease:r,duration:i/a};for(const[u,d]of o)c<d.length&&(h[u]=d[c]);l.push(h)}return l}function Fd(t,e,n,s={}){const i=e.collector?.scope??e.root,r=typeof s.scroller=="string"?i.querySelector(s.scroller):s.scroller??null,o={x:r?r.scrollLeft:window.scrollX,y:r?r.scrollTop:window.scrollY},a={x:r?r.scrollWidth-r.clientWidth:document.documentElement.scrollWidth-window.innerWidth,y:r?r.scrollHeight-r.clientHeight:document.documentElement.scrollHeight-window.innerHeight},l=(v,w)=>{if(w===void 0)return o[v];if(typeof w=="number")return w;if(w==="max")return a[v];const k=typeof w=="string"?i.querySelector(w):w;if(!k)return o[v];const S=k.getBoundingClientRect(),x=r?.getBoundingClientRect(),M=(v==="x"?s.offsetX:s.offsetY)??s.offset??0;return v==="x"?S.left-(x?.left??0)+o.x-M:S.top-(x?.top??0)+o.y-M},c=typeof n=="object"&&n!==null&&!("nodeType"in n)?{x:l("x",n.x),y:l("y",n.y)}:{x:o.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={...o},d=()=>{r?(r.scrollLeft=u.x,r.scrollTop=u.y):window.scrollTo({left:u.x,top:u.y,behavior:"instant"})},f=["wheel","touchstart","keydown"],m=r??window,g=()=>{y.kill(),p()},p=()=>{for(const v of f)m.removeEventListener(v,g)},y=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:()=>{p(),s.onComplete?.()}});if(s.autoKill!==!1)for(const v of f)m.addEventListener(v,g,{passive:!0});return y}function p5(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:r=.1,batchMax:o,onEnter:a,onLeave:l,onEnterBack:c,onLeaveBack:h,...u}=n,d={onEnter:a,onLeave:l,onEnterBack:c,onLeaveBack:h},f={onEnter:[],onLeave:[],onEnterBack:[],onLeaveBack:[]},m={},g=y=>{m[y]!==void 0&&clearTimeout(m[y]),m[y]=void 0;const v=f[y].splice(0);v.length>0&&d[y]?.(v)},p=(y,v)=>{if(d[y]){if(f[y].push(v),o!==void 0&&f[y].length>=o)return g(y);m[y]===void 0&&(m[y]=setTimeout(()=>g(y),r*1e3))}};return i.map(y=>$l(t,{...u,trigger:y,onEnter:()=>p("onEnter",y),onLeave:()=>p("onLeave",y),onEnterBack:()=>p("onEnterBack",y),onLeaveBack:()=>p("onLeaveBack",y)})).filter(y=>y!==void 0)}class _e{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 Cn({...s,startValue:(i,r)=>{const o=e.objectFor(i);if(o)return w5(o[r]);const a=e.appliedValue(i,r);if(a!==void 0)return a;if(r==="d")return ad(e.elementFor(i))??void 0;if(r==="text")return e.elementFor(i)?.textContent??void 0;if(r==="strokeDasharray"||r==="strokeDashoffset"){const l=Bd(e.elementFor(i));if(l!==void 0)return r==="strokeDasharray"?[l,l]:0}},startVelocity:(i,r)=>e.velocityOf(i,r),layoutColumns:i=>Dd(i.map(r=>e.elementFor(r))),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=$l(e,i,this,this.firstElement,r=>s.onWarning?.(r)))})}this.autoplayPending&&queueMicrotask(()=>{this.autoplayPending&&this.play()})}get timeline(){return this.compat.timeline}get scrollTrigger(){return this.scrollDriver}to(e,n,s){return g5(n)?this.record(()=>this.keyframed(e,n,s)):this.record(()=>this.tween(e,[n],s,([i],r,o)=>this.compat.to(r,i,o)))}from(e,n,s){return this.record(()=>this.tween(e,[n],s,([i],r,o)=>this.compat.from(r,i,o)))}fromTo(e,n,s,i){return this.record(()=>this.tween(e,[n,s],i,([r,o],a,l)=>this.compat.fromTo(a,r,o,l)))}set(e,n,s){return this.record(()=>this.tween(e,[n],s,([i],r,o)=>this.compat.set(r,i,o)))}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,r=Math.max(0,Math.min(this.timeline.duration,this.compat.timeOf(n))),o={time:i},a=s.duration??Math.abs(r-i)/1e3/(this.timeScale()||1),l=new _e(this.stage,{onStart:s.onStart,onComplete:s.onComplete});return l.to(o,{time:r,duration:a,ease:s.ease??"none",onUpdate:()=>{this.moveTo(o.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 r=this.options.yoyo===!0;n&&!r&&i.iteration>s.iteration&&(this.playhead={time:0,iteration:i.iteration,direction:"forward",fresh:!0},this.waitingToWrap=!0);const o=this.runCrossings(s,i,n);if(this.options.onUpdate?.(),this.finishedThisFrame&&!o){this.finishedThisFrame=!1;const a=e.currentTime===0&&e.direction==="reverse";!this.scrollDriver&&!r&&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:r,passes:o}=Ja(i.map(a=>a.time),e,n,{duration:this.timeline.duration,alternate:this.options.yoyo===!0,holding:s});for(const a of r){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)o.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 r=this.resolve(e);if(!r)return;const{onStart:o,onUpdate:a,onComplete:l}=n[n.length-1];if(o||a||l){let c=1/0,h=-1/0;const u=(d,f,m)=>{i(d,f,m),c=Math.min(c,this.compat.lastStart),h=Math.max(h,this.compat.lastEnd)};if(this.buildTween(r,n,s,u),c===1/0)return;o&&this.events.push({time:c,direction:"forward",run:o}),a&&this.ranges.push({start:c,end:h,run:a}),l&&this.events.push({time:h,direction:"forward",run:l});return}this.buildTween(r,n,s,i)}keyframed(e,n,s){const i=this.resolve(e);if(!i)return;const r=m5(n);if(r.length===0)return;const o=i.length>1?dl(n.stagger,this.staggerContext(i)):void 0,a=i.map(p=>this.targetFor(p)).filter(p=>p!==void 0),l=o?a.map(p=>[p]):[a],c=o?yr(i.length,o).map(p=>p/1e3):[0],h=this.compat.timeOf(s)/1e3+Rr(n.delay,0)/1e3;let u=1/0,d=-1/0;if(l.forEach((p,y)=>{r.forEach((v,w)=>{const k=w===0?h+c[y]:">";this.tween(p,[v],k,([S],x,M)=>this.compat.to(x,S,M)),u=Math.min(u,this.compat.lastStart),d=Math.max(d,this.compat.lastEnd)})}),u===1/0)return;const{onStart:f,onUpdate:m,onComplete:g}=n;f&&this.events.push({time:u,direction:"forward",run:f}),m&&this.ranges.push({start:u,end:d,run:m}),g&&this.events.push({time:d,direction:"forward",run:g})}staggerContext(e){return{count:e.length,columnsFromLayout:()=>Dd(e.map(n=>this.stage.elementFor(n))),random:()=>this.stage.utils.random(0,1)}}buildTween(e,n,s,i){const r=e.map(d=>this.targetFor(d));if(!(e.length>1&&(n.some(b5)||e.some(d=>this.stage.objectFor(d)!==void 0)))){const d=this.targetFor(e[0]);i(n.map(f=>this.prepare(Wd(f,0,d,this.stage.utils,r),e)),e,s);return}const a=n.length-1,{stagger:l,...c}=n[a],h=dl(l,this.staggerContext(e)),u=h?yr(e.length,h).map(d=>d/1e3):e.map(()=>0);e.forEach((d,f)=>{const m=f===0?Rr(c.delay,0)/1e3+u[0]:0,g=f===0?0:u[f]-u[f-1],p=f===0?s:`<${g<0?"-":"+"}${Math.abs(g).toFixed(6)}`,v=n.map((w,k)=>k===a?{...c,delay:m}:w).map(w=>this.prepare(Wd(w,f,this.targetFor(d),this.stage.utils,r),[d]));i(v,[d],p)})}targetFor(e){return this.stage.elementFor(e)??this.stage.objectFor(e)}prepare(e,n){const s=o=>this.options.onWarning?.(o),i=o=>this.stage.query(o);let r=e;if(e.motionPath!==void 0){const o=Ik(e.motionPath,{query:i,targets:n.map(a=>this.stage.elementFor(a)).filter(a=>!!a),warn:s});r={...r,motionPath:o}}if(e.morphSVG!==void 0){const o=Ok(e.morphSVG,i,s),{morphSVG:a,...l}=r;r=o?{...r,morphSVG:o}:l}if(e.drawSVG!==void 0){const o=Bd(this.stage.elementFor(n[0]));if(o===void 0){s("gsap-compat: drawSVG needs an SVG shape with a stroke (path, line, circle…)");const{drawSVG:a,...l}=r;r=l}else r=sk(r,o)}return r}resolve(e){const n=this.stage.resolveTargets(e);if(n.length===0){this.options.onWarning?.(`gsap-compat: no elements found for target ${k5(e)}`);return}return this.firstElement??=n.map(s=>this.stage.elementFor(s)).find(s=>s!==void 0),n}}function Ld(t=new sd){const e=r=>{const{config:o}=_r(r);return new _e(t,{repeat:o.repeat,yoyo:o.yoyo,repeatDelay:o.repeatDelay,paused:o.paused,onStart:o.onStart,onUpdate:o.onUpdate,onComplete:o.onComplete,onRepeat:o.onRepeat,onReverseComplete:o.onReverseComplete,repeatRefresh:o.repeatRefresh,scrollTrigger:o.scrollTrigger})},n=r=>{const{onStart:o,onUpdate:a,onComplete:l,onRepeat:c,onReverseComplete:h,repeatRefresh:u,...d}=r;return d},s=r=>(r&&t.collector?.track(r),r),i={stage:t,ticker:t.ticker,utils:t.utils,getProperty:(r,o)=>{const[a]=t.resolveTargets(r);if(a===void 0)return;const l=t.objectFor(a);return l?l[o]:t.appliedValue(a,o)??Zu(o)},scrollTrigger:r=>s($l(t,r)),scrollBatch:(r,o)=>p5(t,r,o).map(a=>s(a)),scrollTo:(r,o)=>Fd(i,t,r,o),refreshScroll:()=>{mi.refreshAll(),xl.refreshAll()},smoothScroll:(r={})=>{const o=typeof r.scroller=="string"?(t.collector?.scope??t.root).querySelector(r.scroller):r.scroller;return s(new xl({...r,scroller:o}).start())},context:(r,o)=>{const a=new Id(t,o);return r&&a.add(()=>r(a)),a},matchMedia:r=>new o5(t,r),customEase:Cd.create,customBounce:_d.create,customWiggle:Rd.create,pageTransition:r=>h5(i,t,o=>new _e(t,o),r),imageSequence:(r,o)=>{const a=typeof r=="string"?(t.collector?.scope??t.root).querySelector(r):r;if(!(a instanceof HTMLCanvasElement))throw new Error(`gsap-compat: imageSequence needs a <canvas>, got ${String(r)}`);return s(new a5(a,o))},quickTo:(r,o,a={})=>{const l=new _e(t,{paused:!0}),[c]=t.resolveTargets(r);return Object.assign(u=>{if(!c)return;const d=a.spring!==void 0?t.velocityOf(c,o)??0:0;l.compat.reset(),l.compat.to(c,{[o]:u,duration:a.duration??.4,ease:a.ease??"power3.out",...a.spring!==void 0&&{spring:y5(a.spring,o,d)}}),l.timeline.stop(),l.timeline.play(),t.activate(l.timeline)},{tween:l,kill:()=>l.kill()})},timeline:r=>new _e(t,r),to:(r,o)=>{if(o.scrollTo!==void 0){const{scrollTo:a,...l}=o,c=typeof a=="object"&&a!==null&&!("nodeType"in a)?a:{},h=typeof r!="string"&&r!==window&&r.nodeType===1;return Fd(i,t,a,{...l,offsetX:c.offsetX,offsetY:c.offsetY,scroller:h?r:void 0})}return e(o).to(r,n(o))},from:(r,o)=>e(o).from(r,n(o)),fromTo:(r,o,a)=>e(a).fromTo(r,o,n(a)),set:(r,o)=>e(o).set(r,n(o)),delayedCall:(r,o,a)=>new _e(t).call(o,a,r),killTweensOf:(r,o)=>{const a=t.resolveTargets(r),l=typeof o=="string"?o.split(",").map(c=>c.trim()).filter(Boolean):o;for(const c of[...t.liveTimelines])c.killTweensOf(a,l)},convertToPath:r=>_k(r,t.root),splitText:(r,o)=>{const a=t.collector?.scope??t.root,l=typeof r=="string"?Array.from(a.querySelectorAll(r)):"nodeType"in r?[r]:Array.from(r);return s(Bk(l,o))},draggable:(r,o)=>s(Lk(i,t,r,o)),getFlipState:r=>bl(t,r),flipFrom:(r,o)=>kl(t,a=>new _e(t,a),r,o),flip:(r,o,a)=>{const l=bl(t,r);return o(),kl(t,c=>new _e(t,c),l,{targets:r,...a})}};return i}const le=Ld();function y5(t,e,n){return t===!0?{velocity:{[e]:n}}:typeof t=="string"?{preset:t,velocity:{[e]:n}}:{...t,velocity:{[e]:n}}}function b5(t){return t.morphSVG!==void 0||t.drawSVG!==void 0||t.text!==void 0||t.scrambleText!==void 0||Nd(t)}function Nd(t){return Object.entries(t).some(([e,n])=>(typeof n=="function"||Vu(n))&&!ul.has(e))}function Wd(t,e,n,s,i){if(!Nd(t))return t;const r={};for(const[o,a]of Object.entries(t))ul.has(o)?r[o]=a:typeof a=="function"?r[o]=a(e,n,i):Vu(a)?r[o]=s.resolveRandomString(a):r[o]=a;return r}function Dd(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 Bd(t){const e=t;if(typeof e?.getTotalLength=="function")return e.getTotalLength()}function w5(t){if(typeof t=="number"||typeof t=="string"||Array.isArray(t)&&t.every(e=>typeof e=="number"))return t}function k5(t){return typeof t=="string"?`"${t}"`:String(t)}class Il{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 zd(t,e,n,s,i){const r=n-i;if(r<0){e.paused||e.pause(),e.currentTime=0;return}t.update(r,s)}class Lr{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 _n}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=as({...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 r of e){if(s.has(r.id))throw new Error(`tinyfly: scenario id "${r.id}" is used more than once`);s.add(r.id)}const i=n.initial===void 0?e[0]:e.find(r=>r.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,r=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=e,this.useDefinition(n.timeline),this.lastMarkerId=null;let o=0;return this.reducedMotion||i?o=this.duration:r!==void 0&&(o=this.markers.find(a=>a.id===r)?.time??0),this.seek(o),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(o=>o.id===e):this.currentMarker;if(!s)return;const i=n??this.language(),r=o=>o?.[i]?.[s.id]??o?.[i.split("-")[0]]?.[s.id];return r(this.options.captions)??r(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,r=s.getAttribute("data-volume");r!==null&&(s.volume=Math.max(0,Math.min(1,Number(r)||0))),this.mediaTargets.push({el:s,startTime:i,sync:new Il(s)})})}syncAllMedia(e,n){for(const s of this.mediaTargets)zd(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 r=n.get(i);if(!r||!r.timeline.tracks?.length)return;const o=new _n;s.querySelectorAll("[data-tinyfly]").forEach(a=>{const l=a.getAttribute("data-tinyfly");l&&o.registerTarget(l,a)}),this.symbolInstances.push({adapter:o,timeline:as(r.timeline)})})}attachMedia(e,n){this.mediaSync=new Il(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 state(){return this.timeline?.getStateAtTime(this.timeline.currentTime)}get duration(){return this.timeline?.duration??0}get isPlaying(){return this.timeline?.playbackState==="playing"}destroy(){this.isDestroyed=!0,this.stopAnimationLoop(),this.reducedQuery?.removeEventListener?.("change",this.onReducedChange),this.visibilityObserver?.disconnect(),typeof document<"u"&&document.removeEventListener("visibilitychange",this.onDocumentVisibility),this.mediaSync?.dispose(),this.mediaSync=void 0;for(const 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 r=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,r),this.syncAllMedia(this.timeline.currentTime,r),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(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:r}=Ja(i.map(o=>o.time),e,s,{duration:n.duration,alternate:n.config.alternate===!0,holding:n.repeatDelayRemaining>0});for(const o of r){if(o.kind!=="event")continue;const a=i[o.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 v5(t,e,n={}){const s=new Lr(t,{...n,autoplay:!0});return await s.load(e),s}function M5(t,e={}){return new Lr(t,e)}const qd={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"},jd="tinyfly-controls-style",S5=`
|
|
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,22 +47,22 @@
|
|
|
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 T5=0;function E5(t){if(t.getElementById(jd))return;const e=t.createElement("style");e.id=jd,e.textContent=S5,t.head.appendChild(e)}function Kd(t,e,n={}){const s=e.ownerDocument;E5(s);const i={...qd,...n.labels},r=n.speeds??[.5,1,2],o=()=>t.markers.length>0,a=()=>t.markers.some(L=>L.label!==void 0||t.caption(L.id)!==void 0),l=s.createElement("div");l.className="tf-ctl";const c=s.createElement("div");c.className="tf-ctl-bar",c.setAttribute("role","group");const h=(L,j,V,tt="")=>{const J=s.createElement("button");return J.type="button",J.className=`tf-ctl-btn ${tt}`.trim(),J.setAttribute("aria-label",L),J.title=L,J.textContent=j,J.addEventListener("click",V),J},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"),m=h(i.next,"▶|",()=>t.next()),g=()=>{t.currentTime>=t.duration-.5&&t.seek(0),t.play()},p=s.createElement("input");p.type="range",p.className="tf-ctl-scrub",p.min="0",p.max="1000",p.step="1",p.setAttribute("aria-label",i.scrub),p.addEventListener("input",()=>{t.pause(),t.seek(Number(p.value)/1e3*t.duration)});const
|
|
50
|
+
`;let T5=0;function E5(t){if(t.getElementById(jd))return;const e=t.createElement("style");e.id=jd,e.textContent=S5,t.head.appendChild(e)}function Kd(t,e,n={}){const s=e.ownerDocument;E5(s);const i={...qd,...n.labels},r=n.speeds??[.5,1,2],o=()=>t.markers.length>0,a=()=>t.markers.some(L=>L.label!==void 0||t.caption(L.id)!==void 0),l=s.createElement("div");l.className="tf-ctl";const c=s.createElement("div");c.className="tf-ctl-bar",c.setAttribute("role","group");const h=(L,j,V,tt="")=>{const J=s.createElement("button");return J.type="button",J.className=`tf-ctl-btn ${tt}`.trim(),J.setAttribute("aria-label",L),J.title=L,J.textContent=j,J.addEventListener("click",V),J},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"),m=h(i.next,"▶|",()=>t.next()),g=()=>{t.currentTime>=t.duration-.5&&t.seek(0),t.play()},p=s.createElement("input");p.type="range",p.className="tf-ctl-scrub",p.min="0",p.max="1000",p.step="1",p.setAttribute("aria-label",i.scrub),p.addEventListener("input",()=>{t.pause(),t.seek(Number(p.value)/1e3*t.duration)});const y=s.createElement("span");y.className="tf-ctl-step";const v=s.createElement("select");v.className="tf-ctl-speed",v.setAttribute("aria-label",i.speed);for(const L of r){const j=s.createElement("option");j.value=String(L),j.textContent=`${L}×`,L===1&&(j.selected=!0),v.appendChild(j)}v.addEventListener("change",()=>t.setSpeed(Number(v.value))),c.append(u,d,f,m,p,y),r.length>0&&c.append(v),l.append(c);const w=n.fullscreen?$5(e,s,i):void 0;w&&c.append(w.button);const k=s.createElement("p");k.className="tf-ctl-caption",k.setAttribute("aria-live","polite"),n.captions!==!1&&l.append(k);const S=s.createElement("div");S.className="tf-ctl-question",S.hidden=!0;const x=s.createElement("span"),M=h(i.reveal,i.reveal,()=>t.play(),"tf-ctl-primary");S.append(x,M),l.append(S);const E=A5(t,s,i.scenario,n.scenarioControl??"buttons");E&&l.append(E.element);const T=n.mount;T?T.appendChild(l):e.insertAdjacentElement("afterend",l);const A=()=>{const L=t.isPlaying;f.textContent=L?"❚❚":"▶",f.setAttribute("aria-label",L?i.pause:i.play),f.title=L?i.pause:i.play;const j=t.duration;s.activeElement!==p&&(p.value=String(j>0?Math.round(t.currentTime/j*1e3):0));const V=t.markers;if(d.hidden=m.hidden=y.hidden=V.length===0,V.length>0){const tt=t.currentMarker,J=tt?V.indexOf(tt)+1:0;y.textContent=i.stepFormat.replace("{index}",String(J)).replace("{total}",String(V.length)),y.setAttribute("aria-label",`${i.step} ${J} ${i.of} ${V.length}`),d.disabled=t.currentTime<=.5,m.disabled=t.currentTime>=j-.5;const F=t.caption()??"";k.textContent!==F&&(k.textContent=F),k.hidden=!a();const B=!L&&tt?.question!==void 0&&Math.abs(t.currentTime-tt.time)<1;S.hidden=!B,B&&x.textContent!==tt.question&&(x.textContent=tt.question)}else S.hidden=!0,k.hidden=!0;E?.update()},P=t.subscribe(A);A();const I=n.keyboardScope??e;!I.hasAttribute("tabindex")&&I.tabIndex<0&&(I.tabIndex=0);const O=new WeakSet,_=L=>{if(O.has(L)||(O.add(L),L.defaultPrevented||L.altKey||L.ctrlKey||L.metaKey))return;const j=L.target;if(!(j.tagName==="INPUT"||j.tagName==="SELECT")&&!(L.key===" "&&j.tagName==="BUTTON"))switch(L.key){case" ":L.preventDefault(),t.isPlaying?t.pause():g();break;case"ArrowRight":if(!o())return;L.preventDefault(),t.next();break;case"ArrowLeft":if(!o())return;L.preventDefault(),t.prev();break;case"Home":L.preventDefault(),t.pause(),t.seek(0);break;case"f":case"F":if(!w)return;L.preventDefault(),w.active?w.exit():w.enter();break}};return I.addEventListener("keydown",_),l.addEventListener("keydown",_),{element:l,fullscreen:w&&{get active(){return w.active},enter:w.enter,exit:w.exit},destroy(){w?.destroy(),P(),I.removeEventListener("keydown",_),l.removeEventListener("keydown",_),l.remove()}}}function A5(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(y=>y.id===t.scenario));e.activeElement!==d&&(d.value=String(g));const p=i[g].label;f.textContent!==p&&(f.textContent=p),d.setAttribute("aria-valuetext",p)}}}const r=e.createElement("fieldset");r.className="tf-ctl-choices";const o=e.createElement("legend");o.textContent=n,r.append(o);const a=`tf-ctl-scenario-${++T5}`,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),r.append(u),d});return{element:r,update:()=>{for(const h of l){const u=h.value===t.scenario;h.checked!==u&&(h.checked=u)}}}}const x5='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',P5='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';function $5(t,e,n){const s=e,i=t,r=e.createElement("button");r.type="button",r.className="tf-ctl-btn tf-ctl-fullscreen";let o,a="";const l=()=>{const g=o!==void 0;r.innerHTML=g?P5:x5;const p=g?n.exitFullscreen:n.fullscreen;r.setAttribute("aria-label",p),r.title=p,r.setAttribute("aria-pressed",String(g)),t.classList.toggle("tf-fullscreen",g),t.classList.toggle("tf-fullscreen-overlay",o==="overlay")},c=()=>s.fullscreenElement??s.webkitFullscreenElement??null,h=()=>{c()===t?o="native":o==="native"&&(o=void 0),l()},u=g=>{g.key==="Escape"&&m()},d=()=>{o="overlay",a=e.documentElement.style.overflow,e.documentElement.style.overflow="hidden",e.addEventListener("keydown",u),l()};async function f(){if(o)return;const g=i.requestFullscreen?.bind(i)??i.webkitRequestFullscreen?.bind(i),p=s.fullscreenEnabled??s.webkitFullscreenEnabled??!1;if(g&&p)try{if(await g(),c()===t){o="native",l();return}}catch{}d()}async function m(){if(o==="overlay")e.removeEventListener("keydown",u),e.documentElement.style.overflow=a,o=void 0,l();else if(o==="native"){o=void 0,l();const g=s.exitFullscreen?.bind(s)??s.webkitExitFullscreen?.bind(s);c()===t&&g&&await g()}}return r.addEventListener("click",()=>{o?m():f()}),e.addEventListener("fullscreenchange",h),e.addEventListener("webkitfullscreenchange",h),l(),{button:r,get active(){return o!==void 0},enter:f,exit:m,destroy(){m(),e.removeEventListener("fullscreenchange",h),e.removeEventListener("webkitfullscreenchange",h),r.remove()}}}const Yd="tinyfly-choices-style",I5=`
|
|
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 O5(t){if(t.getElementById(Yd))return;const e=t.createElement("style");e.id=Yd,e.textContent=I5,t.head.appendChild(e)}function Xd(t,e){const n=Array.from(e.querySelectorAll("[data-tinyfly-choose]"));if(n.length===0)return()=>{};O5(e.ownerDocument);const s=[],i=[];for(const a of n){const l=a.getAttribute("data-tinyfly-choose")??"",c=[],h=(m,g)=>{a.hasAttribute(m)||(a.setAttribute(m,g),c.push(m))};h("role","button"),h("tabindex","0");const u=t.scenarios.find(m=>m.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=m=>{const g=m.key;g!=="Enter"&&g!==" "||(m.preventDefault(),d())};a.addEventListener("click",d),a.addEventListener("keydown",f),i.push(()=>{a.removeEventListener("click",d),a.removeEventListener("keydown",f)})}const r=()=>{for(const{element:a}of s)a.setAttribute("aria-pressed",String(a.getAttribute("data-tinyfly-choose")===t.scenario))},o=t.subscribe(r);return r(),()=>{o();for(const a of i)a();for(const{element:a,attributes:l}of s)for(const c of l)a.removeAttribute(c)}}const Nr=new WeakMap,Ol=new WeakMap;let C5=0;function yi(t,e,n){if(t)try{return JSON.parse(t)}catch(s){console.warn(`tinyfly: invalid ${e} JSON on`,n,s);return}}async function Gd(t,e={}){const n=Nr.get(t);if(n)return n;const s=Array.from(t.querySelectorAll("script[data-tinyfly-timeline]")),i=s[0],r=t.getAttribute("data-src"),o=R5(t.getAttribute("data-markers")),a=s.length>1||i?.hasAttribute("data-scenario")?_5(s,o,t):void 0;if(a&&a.length===0)return;let l=i&&!a?yi(i.textContent,"timeline",t):void 0;if(!l&&r&&o){const f=await fetch(r);f.ok&&(l=await f.json())}if(l&&o&&(l=Ud(l,o)),!l&&!r&&!a){console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)',t);return}const c=yi(t.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",t),h={playWhenVisible:!0,...e.player,...c&&{captions:c},...yi(t.getAttribute("data-options"),"data-options",t)};F5(t);const u=new Lr(t,h),d={element:t,player:u};if(Nr.set(t,d),t.setAttribute("data-tinyfly-mounted",""),a){const f=t.getAttribute("data-scenario")??void 0;await u.loadScenarios(a,{initial:a.some(m=>m.id===f)?f:void 0}),Ol.set(t,Xd(u,t))}else await u.load(l??r);if(t.getAttribute("data-controls")!=="false"){const f=yi(t.getAttribute("data-labels"),"data-labels",t),m=t.querySelector("figcaption"),g=t.getAttribute("data-scenario-legend"),p=t.getAttribute("data-scenario-control");d.controls=Kd(u,t,{...e.controls,...t.getAttribute("data-fullscreen")==="true"?{fullscreen:!0}:{},...p==="slider"||p==="buttons"?{scenarioControl:p}:{},labels:{...e.controls?.labels,...f,...g?{scenario:g}:{}},mount:void 0}),m?t.insertBefore(d.controls.element,m):t.appendChild(d.controls.element)}return d}function _5(t,e,n){const s=[];return t.forEach((i,r)=>{const o=yi(i.textContent,"timeline",n);if(!o)return;const a=i.getAttribute("data-scenario")||`scenario-${r+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?Ud(o,e):o})}),s}function Ud(t,e){return t.config.markers?.length?t:{...t,config:{...t.config,markers:e.map((n,s)=>({id:`step-${s+1}`,time:n}))}}}function R5(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 Vd(t=document,e={}){const n=Array.from(t.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(n.map(i=>Gd(i,e)))).filter(i=>i!==void 0)}function H5(t){const e=Nr.get(t);e&&(Ol.get(t)?.(),Ol.delete(t),e.controls?.destroy(),e.player.destroy(),Nr.delete(t),t.removeAttribute("data-tinyfly-mounted"))}function F5(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-${++C5}`,e.setAttribute("aria-labelledby",s.id))}function L5(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const e=()=>{Vd()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}class Jd{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 _n,this.adapterB=new _n}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 r of e.elements){if(!r.html)continue;const o=document.createElement("div");o.innerHTML=r.html.trim();const a=o.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 r=i.getAttribute("data-tinyfly-symbol");if(!r)return;const o=this.symbolDefs.get(r);if(!o)return;const a=new _n;i.querySelectorAll("[data-tinyfly]").forEach(l=>{const c=l.getAttribute("data-tinyfly");c&&a.registerTarget(c,l)}),s.push({adapter:a,timeline:as(o)})}),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 r=i.timeline.duration;i.adapter.applyState(i.timeline.getStateAtTime(r>0?n%r:n))}}clearContainer(e){e.innerHTML=""}createTimeline(e){return e.timeline?as(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 N5(t,e,n={}){const s=new Jd(t,{...n,autoplay:!0});return await s.load(e),s}const W5={type:"none",duration:0},Lt=t=>({description:t,unit:"degrees"}),Pt=(t,e=0,n=1)=>({description:t,unit:`${e}..${n}`,min:e,max:n}),Zd={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:Pt("Left foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),rightFootOut:Pt("Right foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),mouth:Pt("Mouth open: 0 closed, 1 wide open"),smile:Pt("−1 frown, 0 flat, 1 smile",-1,1),mouthWidth:{description:"Mouth width: 1 normal, 0.5 pursed, 1.5 wide",unit:"factor",min:.3,max:2},blink:Pt("Eyes closed by a blink: 0 open, 1 shut"),leftEye:{description:"Left eye openness: 0 shut, 1 normal, 1.6 wide",unit:"factor",min:0,max:2},rightEye:{description:"Right eye openness: 0 shut, 1 normal, 1.6 wide",unit:"factor",min:0,max:2},leftBrow:Pt("Left eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),rightBrow:Pt("Right eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),browTilt:Pt("Eyebrow slant: −1 angry, 1 worried",-1,1),lookX:Pt("Eyes look across: + the way it faces",-1,1),lookY:Pt("Eyes look down (+) or up (−)",-1,1),stretch:{description:"Squash and stretch: 1 normal, above taller (a jump), below squashed (a landing)",unit:"factor",min:.3,max:3},turn:Pt("0 front-on, 1 in profile, turned the way it faces"),sit:Pt("0 standing, 1 seated"),spin: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"}},Qd={walk:{description:"Walk-cycle phase, in strides: animate 0 → n for n strides",unit:"strides"},walking:Pt("How much of the walk cycle is applied (0 standing)"),gait:{description:"How it walks: a gait name (walk, bouncy, doubleBounce, sneak, strut, tired, run, shove); a string track switches it",kind:"string"},talk:Pt("How much the mouth chatters"),rubber:Pt("Limbs from jointed (0) to rubber hose (1)"),facing:{description:"Which way it faces: 1 right, −1 left (key the flip while turn is near 0)",unit:"±1",min:-1,max:1},beat:{description:"Beats into its dance (with a dance)",unit:"beats"},dancing:Pt("How much of the dance is applied")},tf={"thumb.curl":Pt("Thumb curled in"),"thumb.across":Pt("Thumb across the palm"),"index.curl":Pt("Index finger curled"),"middle.curl":Pt("Middle finger curled"),"ring.curl":Pt("Ring finger curled"),"pinky.curl":Pt("Little finger curled"),spread:Pt("Fingers spread apart"),turn: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 ef;function D5(t){ef=t}function B5(t){return ef?.(t)??{}}function Cl(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 sn(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=Cl(t)*n;const i=[t[0]];for(let r=1;r<t.length;r++){const o=t[r-1],a=t[r],l=Math.hypot(a.x-o.x,a.y-o.y);if(l>=s){const c=l===0?0:s/l;return i.push({x:o.x+(a.x-o.x)*c,y:o.y+(a.y-o.y)*c}),i}i.push(a),s-=l}return i}function Wr(t,e){const n=sn(t,e);return n[n.length-1]}function _l(t,e){return e>0?Math.floor(Math.max(0,t)*e/1e3):0}function Dr(t,e,n){const s=e.roughness??2,i=Math.max(1,Math.round(e.passes??2)),r=_l(n,e.boil??8);let o=0;const a=()=>{const d=o++;return f=>Se(re(`${e.seed??1}:${r}:${d}:${f}`))},l=(d,f)=>(d.next()*2-1)*f,c=d=>{const f=a(),m=t.lineWidth,g=t.globalAlpha;for(let p=0;p<i;p++)t.lineWidth=p===0?m:m*.55,t.globalAlpha=p===0?g:g*.6,d(f(p));t.lineWidth=m,t.globalAlpha=g},h=(d,f=1)=>{if(d.length<2)return;const m=d.slice(1).map((p,b)=>Math.hypot(p.x-d[b].x,p.y-d[b].y)),g=m.reduce((p,b)=>p+b,0)*Math.min(1,Math.max(0,f));c(p=>{const b=[],v=[];if(d.forEach((w,S)=>{b.push({x:w.x+l(p,s*.5),y:w.y+l(p,s*.5)}),S>0&&v.push([p.next()*2-1,p.next()*2-1])}),g<=0)return;t.beginPath(),t.moveTo(b[0].x,b[0].y);let k=0;for(let w=1;w<b.length;w++){const S=z5(b[w-1],b[w],s,v[w-1]),x=m[w-1];if(k+x<=g){t.bezierCurveTo(S[1].x,S[1].y,S[2].x,S[2].y,S[3].x,S[3].y),k+=x;continue}const M=q5(S,x===0?1:(g-k)/x);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,m,g,p=1)=>{c(b=>{const k=b.next()*Math.PI*2,w=Math.PI*2+.15+b.next()*.3,S=[];for(let M=0;M<=14;M++){const E=k+w*M/14,T=l(b,s*.6);S.push({x:d+Math.cos(E)*(m+T),y:f+Math.sin(E)*(g+T)})}const x=sn(S,p);x.length<2||(nf(t,x),t.stroke())})};return{line:h,curve(d,f=1){if(d.length<2)return;const m=d[0],g=d[d.length-1],p=Math.hypot(g.x-m.x,g.y-m.y)||1,b=-(g.y-m.y)/p,v=(g.x-m.x)/p;c(k=>{const w={x:l(k,s*.5),y:l(k,s*.5)},S={x:l(k,s*.5),y:l(k,s*.5)},x=l(k,s*Math.min(1.5,Math.max(.3,p/80))),M=d.map((T,A)=>{const P=A/(d.length-1),I=Math.sin(Math.PI*P)*x;return{x:T.x+w.x+(S.x-w.x)*P+b*I,y:T.y+w.y+(S.y-w.y)*P+v*I}}),E=sn(M,f);E.length<2||(nf(t,E),t.stroke())})},circle(d,f,m,g=1){u(d,f,m,m,g)},ellipse:u,nudge(d=.5){const f=a()(0);return{x:l(f,s*d),y:l(f,s*d)}}}}function z5(t,e,n,s){const i=e.x-t.x,r=e.y-t.y,o=Math.hypot(i,r)||1,a=n*Math.min(1.5,Math.max(.3,o/80)),l=-r/o,c=i/o;return[t,{x:t.x+i/3+l*s[0]*a,y:t.y+r/3+c*s[0]*a},{x:t.x+2*i/3+l*s[1]*a,y:t.y+2*r/3+c*s[1]*a},e]}function q5([t,e,n,s],i){const r=(u,d)=>({x:u.x+(d.x-u.x)*i,y:u.y+(d.y-u.y)*i}),o=r(t,e),a=r(e,n),l=r(n,s),c=r(o,a),h=r(a,l);return[t,o,c,r(c,h)]}function nf(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 qt(t,e,n){const s=t.length;if(s<2)return[];const i=[],r=[],o=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=o(l)/2,f=-(h.y-c.y)/u*d,m=(h.x-c.x)/u*d;i.push({x:a.x+f,y:a.y+m}),r.push({x:a.x-f,y:a.y-m})}),[...i,...r.reverse()]}function bi(t,e,n,s){const i=e.length;if(i<2)return;const r=qt(e,n,s),o=a=>n+(s-n)*a/(i-1);t.beginPath(),t.moveTo(r[0].x,r[0].y);for(const a of r.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,o(l)/2,0,Math.PI*2),t.fill())})}function Rn(t,e,n,s,i=16){const r={x:2*e.x-(t.x+n.x)/2,y:2*e.y-(t.y+n.y)/2},o=[];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*r.x+l*l*n.x,y:h*h*t.y+2*h*l*r.y+l*l*n.y};o.push({x:c.x+(u.x-c.x)*s,y:c.y+(u.y-c.y)*s})}return o}const Rl=new Map;function sf(t){const e=Rl.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(r=>r+r).join(""):s;n=[0,2,4].map(r=>Number.parseInt(i.slice(r,r+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 Rl.size<512&&Rl.set(t,n),n}Qt([-3,-5,-4]);const j5=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)};function rf(t,e,n){const s=[0,0,0];for(const i of n){const r=sf(i.color);let o;if(i.light==="ambient")o=i.intensity;else if(i.light==="directional")o=i.intensity*Math.max(0,-We(e,i.direction));else{const a=oe(i.position,t),l=Ir(a),c=l>0?Pn(a,1/l):e,h=i.range?Math.max(0,1-l/i.range)**2:1;if(o=i.intensity*Math.max(0,We(e,c))*h,i.light==="spot"){const u=Math.cos(i.angle*Math.PI/180),d=Math.cos(i.angle*.8*Math.PI/180);o*=j5(u,d,-We(c,i.direction))}}s[0]+=r[0]*o,s[1]+=r[1]*o,s[2]+=r[2]*o}return s}function of(t,e){return t?Math.min(1,Math.max(0,(e-t.near)/(t.far-t.near))):0}function K5([t,e,n]){const s=Math.max(t,e,n),i=Math.min(t,e,n),r=(s+i)/2;if(s===i)return[0,0,r];const o=s-i,a=r>.5?o/(2-s-i):o/(s+i);return[(s===t?(e-n)/o+(e<n?6:0):s===e?(n-t)/o+2:(t-e)/o+4)*60,a,r]}function Hl([t,e,n]){const s=(t%360+360)%360,i=r=>Math.min(1,Math.max(0,r));return`hsl(${s.toFixed(1)}, ${(i(e)*100).toFixed(1)}%, ${(i(n)*100).toFixed(1)}%)`}function Fl(t,e,n){const s=(e-t+540)%360-180;return t+Math.sign(s)*Math.min(Math.abs(s),n)}const af=335,Y5=50,Ll=new Map;function Nl(t){const e=Ll.get(t);if(e)return e;const n=t.trim();if(!/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(n)&&!n.startsWith("rgb("))return;const[s,i,r]=K5(sf(n)),o=i<.08,a={shadow:Hl(o?[230,.1,r*.82]:[Fl(s,af,8),i*.82+.02,r*.8]),core:Hl(o?[235,.14,r*.66]:[Fl(s,af,14),i*.85+.04,r*.64]),highlight:Hl(o?[s,i,r+(1-r)*.5]:[Fl(s,Y5,8),i*.9,r+(1-r)*.4])};return Ll.size<512&&Ll.set(t,a),a}const Br=(t,e)=>{if(!Number.isFinite(t)||t<0||t>1)throw new Error(`illustrated: ${e} must be 0..1`);return t};function lf(t={},e=[-.8,-.6]){const n=t.light??e;if(n.length!==2||!n.every(Number.isFinite)||Math.hypot(...n)===0)throw new Error("illustrated: light must be a finite nonzero 2D vector");const s=Math.hypot(...n);return{light:[n[0]/s,n[1]/s],weight:Br(t.weight??.6,"weight"),taper:Br(t.taper??.7,"taper"),shadow:Br(t.shadow??1,"shadow"),highlight:Br(t.highlight??.6,"highlight")}}const Wl=6,Dl=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)};function Bl(t,e,n){const s=[],i=t.length,r=n?i:i-1;for(let o=0;o<r;o++){const a=t[o],l=t[(o+1)%i],c=Math.min(24,Math.max(1,Math.ceil(Math.hypot(l.x-a.x,l.y-a.y)/e)));for(let h=0;h<c;h++)s.push({x:a.x+(l.x-a.x)*h/c,y:a.y+(l.y-a.y)*h/c})}return n||s.push(t[i-1]),s}function zl(t,e){const n=t.length,s=i=>t[e?(i%n+n)%n:Math.min(n-1,Math.max(0,i))];return t.map((i,r)=>{const o=s(r-2),a=s(r+2),l=a.x-o.x,c=a.y-o.y,h=Math.hypot(l,c)||1;return{x:-c/h,y:l/h}})}function cf(t,e){const n=t.reduce((r,o)=>r+o.x,0)/t.length,s=t.reduce((r,o)=>r+o.y,0)/t.length;return t.reduce((r,o,a)=>r+e[a].x*(o.x-n)+e[a].y*(o.y-s),0)>=0?1:-1}function X5(t){let e=0,n=0;return t.forEach((s,i)=>{const r=t[(i+1)%t.length];e+=s.x*r.y-r.x*s.y,n+=Math.hypot(r.x-s.x,r.y-s.y)}),n>0?Math.abs(e)/n:0}function zr(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 G5(t,e,n,s){const[i,r]=s.light,o=u=>{const d=u.x*i+u.y*r;return 1-s.weight*d*(d>0?.55:1)},a=(u,d,f,m)=>{const g=u.map((b,v)=>({x:b.x+d[v].x*f[v]/2,y:b.y+d[v].y*f[v]/2})),p=u.map((b,v)=>({x:b.x-d[v].x*f[v]/2,y:b.y-d[v].y*f[v]/2}));if(t.fillStyle=e,m){t.beginPath(),g.forEach((b,v)=>v?t.lineTo(b.x,b.y):t.moveTo(b.x,b.y)),t.closePath(),p.forEach((b,v)=>v?t.lineTo(b.x,b.y):t.moveTo(b.x,b.y)),t.closePath(),t.fill("evenodd");return}zr(t,[...g,...p.reverse()]),t.fill();for(const b of[0,u.length-1])t.beginPath(),t.arc(u[b].x,u[b].y,f[b]/2,0,Math.PI*2),t.fill()},l=(u,d)=>{const f=Nl(d),m=X5(u);if(!f||m<n*1.5)return;const g=Bl(u,Math.max(2,m*.25),!0),p=zl(g,!0),b=cf(g,p),v=p.map(M=>({x:M.x*b,y:M.y*b})),k=v.map(M=>M.x*i+M.y*r),w=t.globalAlpha,S=(M,E,T,A)=>{if(A<=0)return;const P=g.map((O,_)=>({x:O.x-v[_].x*M(k[_]),y:O.y-v[_].y*M(k[_])})),I=g.map((O,_)=>({x:O.x-v[_].x*E(k[_]),y:O.y-v[_].y*E(k[_])}));zr(t,[...P,...I.reverse()]),t.globalAlpha=w*A,t.fillStyle=T,t.fill()};t.save(),zr(t,u),t.clip();const x=(M,E,T,A=()=>-n)=>{for(let P=1;P<=Wl;P++){const I=P/Wl;S(A,O=>A()+(M(O)-A())*I,E,T/Wl)}};x(M=>m*.5*Dl(-.15,.7,-M),f.shadow,s.shadow*.85),x(M=>m*.18*Dl(.3,.95,-M),f.core,s.shadow*.6),x(M=>m*(.07+.2*Dl(.35,.95,M)),f.highlight,s.highlight*.7,()=>m*.07),t.restore()},c=(u,d)=>{const f=Bl(u,Math.max(1.5,d*1.5),!0),m=zl(f,!0),g=cf(f,m);a(f,m,m.map(p=>d*o({x:p.x*g,y:p.y*g})),!0)},h={look:"illustrated",ink:e,limb(u,d,f){t.fillStyle=e,bi(t,u,d,f)},line(u,d,f){if(u.length<2||d<=0)return;const m=Bl(u,Math.max(1.5,d*1.5),!1),g=zl(m,!1),p=m.length,b=m.map((v,k)=>{const w=k/(p-1),S=1-s.taper*.6*(1-Math.sqrt(Math.sin(Math.PI*w))),x=f?o({x:g[k].x*f,y:g[k].y*f}):1;return d*S*x});a(m,g,b,!1)},shape(u,d,f,m){u.length<3||(zr(t,u),d!==null&&(t.fillStyle=d,t.fill(),m||l(u,d)),f>0&&c(u,f))},ellipse(u,d,f,m,g,p,b){h.shape(wi(u,d,f,m,g,0,1,48).slice(0,-1),p,b)},dot(u,d,f){t.fillStyle=e,t.beginPath(),t.arc(u,d,f,0,Math.PI*2),t.fill()},guide(){},guideEllipse(){}};return h}function wi(t,e,n,s,i,r=0,o=1,a=40){const l=Math.cos(i),c=Math.sin(i);return Array.from({length:a+1},(h,u)=>{const d=r+Math.PI*2*o*u/a,f=Math.cos(d)*n,m=Math.sin(d)*s;return{x:t+f*l-m*c,y:e+f*c+m*l}})}function ki(t,e){if(e.look==="pencil")return J5(t,e);if(e.look==="illustrated"){if(!e.illustrated)throw new Error("createPen: the illustrated look needs its resolved style");return G5(t,e.ink,e.lineWidth,e.illustrated)}return hf(t,e.ink,e.look)}function qr(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 vi(t,e){return e.look==="silhouette"?hf(t,e.ink,"silhouette",!1):e}function hf(t,e,n,s=!0){const i=n==="silhouette",r=i?1.25:1;return{look:n,ink:e,limb(o,a,l){t.fillStyle=e,bi(t,o,a*r,l*r)},line(o,a){o.length<2||(t.strokeStyle=e,t.lineWidth=a*r,t.lineCap="round",t.lineJoin="round",qr(t,o),t.stroke())},shape(o,a,l){qr(t,o,!0),(a!==null||i&&s)&&(t.fillStyle=i?e:a,t.fill()),!(l<=0)&&(t.strokeStyle=e,t.lineWidth=l*r,t.lineJoin="round",t.stroke())},ellipse(o,a,l,c,h,u,d){t.beginPath(),t.ellipse(o,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*r,t.stroke())},dot(o,a,l){t.fillStyle=e,t.beginPath(),t.arc(o,a,l*r,0,Math.PI*2),t.fill()},guide(){},guideEllipse(){}}}function U5(t,e){const n=[t[0]];let s=0;for(let o=1;o<t.length;o++){const a=t[o-1],l=t[o],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],r=n[n.length-1];return Math.hypot(i.x-r.x,i.y-r.y)>e*.25?n.push(i):n[n.length-1]=i,n}function V5(t,e){const n=t.length;return t.map((s,i)=>{const r=t[Math.max(0,i-1)],o=t[Math.min(n-1,i+1)],a=Math.hypot(o.x-r.x,o.y-r.y)||1,l=e(n===1?0:i/(n-1));return{x:s.x-(o.y-r.y)/a*l,y:s.y+(o.x-r.x)/a*l}})}function uf(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,r)=>i+r.amount*Math.sin(Math.PI*2*r.frequency*s+r.phase),0)/n}function J5(t,e){const n=e.pencil??{},s=e.ink,i=n.roughness??Math.max(1,e.lineWidth*.12),r=Math.max(1,Math.round(n.passes??2)),o=Math.min(1,Math.max(0,n.pressure??.25)),a=Math.min(1,Math.max(0,n.rubbedOut??.15)),l=_l(e.time,n.boil??8);let c=0;const h=(m,g,p=!1)=>Se(re(`${e.seed}:${p?"paper":l}:${m}:${g}`)),u=(m,g,p,b,v,k=0)=>{if(m.length<2)return;const w=m.slice(1).reduce((P,I,O)=>P+Math.hypot(I.x-m[O].x,I.y-m[O].y),0);let S=U5(m,Math.max(1.5,Math.min(e.lineWidth*.8,w/24)));if(k>0&&S.length>=2){const[P,I]=[S[S.length-2],S[S.length-1]],O=Math.hypot(I.x-P.x,I.y-P.y)||1;S=[...S,{x:I.x+(I.x-P.x)/O*k,y:I.y+(I.y-P.y)/O*k}]}const x=uf(p),M=uf(p),E=S.length,T=[],A=[];S.forEach((P,I)=>{const O=E===1?0:I/(E-1),_=S[Math.max(0,I-1)],L=S[Math.min(E-1,I+1)],j=Math.hypot(L.x-_.x,L.y-_.y)||1,V=-(L.y-_.y)/j,tt=(L.x-_.x)/j,J=x(O)*v,F=Math.min(1,O/.08,(1-O)/.08),B=(.55+.45*Math.sqrt(Math.max(0,F)))*(1+o*M(O)),Y=Math.max(.3,g(O)*B/2),R=P.x+V*J,K=P.y+tt*J;T.push({x:R+V*Y,y:K+tt*Y}),A.push({x:R-V*Y,y:K-tt*Y})}),t.save(),t.globalAlpha*=b,t.fillStyle=s,qr(t,[...T,...A.reverse()],!0),t.fill(),t.restore()},d=(m,g)=>{const p=c++,b=h(p,99,!0);if(b.next()<a){const S=(b.next()*2-1)*e.lineWidth*1.4,x=(b.next()*2-1)*e.lineWidth*1.4,M=m.map(E=>({x:E.x+S,y:E.y+x}));u(M,E=>g(E)*1.8,h(p,98,!0),.035,i),u(M,E=>g(E)*.45,h(p,97,!0),.12,i*1.5)}const v=m.slice(1).reduce((S,x,M)=>S+Math.hypot(x.x-m[M].x,x.y-m[M].y),0),k=g(.5)>4&&v>g(.5)*6,w=k?[-.3,.3,0]:[0];for(let S=0;S<r;S++){const x=S===0;w.forEach((M,E)=>{const T=h(p,S*10+E),A=M===0?m:V5(m,I=>g(I)*M*Math.sqrt(Math.sin(Math.PI*I))),P=!x&&M===0?e.lineWidth*(.3+T.next()*.8):0;u(A,I=>g(I)*(k?.5:1)*(x?1:.6),T,x?.85:.45,i*(x?.6:1),P)})}},f=(m,g,p,b,v,k)=>{const S=h(c,50).next()*Math.PI*2;d(wi(m,g,p,b,v,S,1.08,48),()=>k)};return{look:"pencil",ink:s,limb(m,g,p){d(m,b=>g+(p-g)*b)},line(m,g){d(m,()=>g)},shape(m,g,p){g!==null&&(t.save(),t.globalAlpha*=.88,t.fillStyle=g,qr(t,m,!0),t.fill(),t.restore()),p>0&&d([...m,m[0]],()=>p)},ellipse(m,g,p,b,v,k,w){k!==null&&(t.save(),t.globalAlpha*=.9,t.fillStyle=k,t.beginPath(),t.ellipse(m,g,p,b,v,0,Math.PI*2),t.fill(),t.restore()),f(m,g,p,b,v,w)},dot(m,g,p){t.save(),t.globalAlpha*=.9,t.fillStyle=s,t.beginPath(),t.arc(m,g,p,0,Math.PI*2),t.fill(),t.restore()},guide(m){if(n.construction===!1||m.length<2)return;const g=c++;u(m,()=>Math.max(.6,e.lineWidth*.18),h(g,0),.28,i*1.2,e.lineWidth)},guideEllipse(m,g,p,b,v){if(n.construction===!1)return;const k=c++,w=h(k,0),S=wi(m,g,p,b,v,w.next()*Math.PI*2,1.12,48);u(S,()=>Math.max(.6,e.lineWidth*.18),w,.28,i*1.5)}}}const df=["thumb","index","middle","ring","pinky"],Ct={"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 Wt(t={}){return{...Ct,...t}}const ce=(t,e,n,s,i)=>({"thumb.curl":t,"index.curl":e,"middle.curl":n,"ring.curl":s,"pinky.curl":i}),Tt={relaxed:Ct,open:Wt({...ce(0,0,0,0,0),"thumb.across":0,spread:.55}),spread:Wt({...ce(0,0,0,0,0),"thumb.across":0,spread:1}),flat:Wt({...ce(0,0,0,0,0),"thumb.across":.35,spread:0}),fist:Wt({...ce(.7,1,1,1,1),"thumb.across":.9,spread:0}),point:Wt({...ce(.75,0,1,1,1),"thumb.across":.9,spread:0}),thumbsUp:Wt({...ce(0,1,1,1,1),"thumb.across":0,spread:0,roll:70}),peace:Wt({...ce(.75,0,0,1,1),"thumb.across":.9,spread:1}),ok:Wt({...ce(.12,.6,.1,.15,.2),"thumb.across":.55,spread:.6}),pinch:Wt({...ce(.1,.65,.75,.85,.9),"thumb.across":.55,spread:0}),cupped:Wt({...ce(.25,.4,.4,.4,.4),"thumb.across":.4,spread:.05,turn:2}),wave:Wt({...ce(0,.05,.05,.1,.12),"thumb.across":0,spread:.7,turn:2}),pencilGrip:Wt({...ce(.1,.6,.72,.88,.95),"thumb.across":.5,spread:0,turn:.8,bend:10}),hold:Wt({...ce(.5,.7,.72,.74,.76),"thumb.across":.75,spread:0,turn:1})};function fs(t,e,n){const s={...t};for(const[i,r]of Object.entries(e)){const o=t[i]??r;s[i]=o+(r-o)*n}return s}const Z5={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}},Q5={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}},De={base:[-.11,.1,-.05],bones:[.2,.15,.12],widths:[.2,.145,.135],out:[-.7,.68,-.22],across:[.35,.5,-.8]},tv=[82,100,62],ev=[48,72],nv=3,sv=13,iv=.035,rv=-.075,ov=[[-.17,0],[-.215,.12],[-.235,.26],[-.225,.4],[-.185,.49],[-.075,.525],[.05,.51],[.16,.465],[.215,.4],[.225,.26],[.2,.1],[.16,0]],rn=t=>t*Math.PI/180,ql=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],jr=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],jl=(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]],Mi=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function on(t,e,n){const s=Math.cos(n),i=Math.sin(n),r=jl(e,t),o=e[0]*t[0]+e[1]*t[1]+e[2]*t[2];return[t[0]*s+r[0]*i+e[0]*o*(1-s),t[1]*s+r[1]*i+e[1]*o*(1-s),t[2]*s+r[2]*i+e[2]*o*(1-s)]}const ff=[1,0,0],gf=[0,1,0],Si=[0,0,1];function av(t,e,n){const s=rn(t.fan*(nv+sv*n)),i=[Math.sin(s),Math.cos(s),0],r=[Math.cos(s),-Math.sin(s),0],o=[t.knuckle];let a=0;t.bones.forEach((h,u)=>{a+=rn(tv[u]*e),o.push(ql(o[u],jr(on(i,r,-a),h)))});const l=on(Si,r,-a),c=o.map((h,u)=>t.width*(1-.14*(u/(o.length-1))));return{joints:o,back:l,widths:c}}function lv(t,e,n=1,s=1){const i=Math.min(1,Math.max(0,e)),r=Mi(ql(jr(Mi(De.out),1-i),jr(Mi(De.across),i))),o=Mi(jl(Si,r)),a=Mi(jl(r,o)),l=[[De.base[0]*s,De.base[1],De.base[2]]];let c=0;De.bones.forEach((d,f)=>{f>0&&(c+=rn(ev[f-1]*t)),l.push(ql(l[f],jr(on(r,o,c),d)))});const h=on(a,o,c),u=[...De.widths,De.widths[De.widths.length-1]*.92].map(d=>d*n);return{joints:l,back:h,widths:u}}function Kr(t,e={}){const n={...Ct,...t},s=e.size??100,i=e.side??"right",r=i==="left"?-1:1,o=rn(e.angle??0),a=e.fingers===4,l=Math.max(.5,e.plump??1),c=1+(l-1)*.7,h=I=>({...I,knuckle:[I.knuckle[0]*c,I.knuckle[1],I.knuckle[2]],width:I.width*l}),u=rn(n.bend??0),d=rn(n.tilt??0),f=rn(90*(n.turn??0)),m=I=>on(on(on(I,ff,-u),Si,-d),gf,f),g=Math.cos(o),p=Math.sin(o),b=rn(n.roll??0),v=Math.cos(b),k=Math.sin(b),w=I=>{const O=I[0]*s,_=-I[1]*s,L=(O*v-_*k)*r,j=O*k+_*v;return{x:L*g-j*p,y:L*p+j*g}},S=I=>{const O=w(I),_=Math.hypot(O.x,O.y);return _>1e-6*s?{x:O.x/_,y:O.y/_}:{x:0,y:0}},x={thumb:lv(n["thumb.curl"]??0,n["thumb.across"]??0,l,c)},M=a?Q5:Z5;for(const I of df){const O=M[I];O&&(x[I]=av(h(O),n[`${I}.curl`]??0,n.spread??0))}const E={};for(const[I,O]of Object.entries(x)){const _=O.joints.map(m),L=m(O.back);E[I]={points:_.map(w),depths:_.map(j=>j[2]*s),widths:O.widths.map(j=>j*s),nail:L[2],back:S(L)}}const T=ov.flatMap(([I,O])=>[m([I*c,O,iv]),m([I*c,O,rv])]),A=cv(T.map(w)),P=T.reduce((I,O)=>I+O[2],0)/T.length*s;return{size:s,side:i,wrist:{x:0,y:0},palm:A,palmDepth:P,palmFacing:-m(Si)[2],fingers:E,axes:{up:S(m(gf)),across:S(m(ff)),out:S(m(Si))},curls:Object.fromEntries(Object.keys(E).map(I=>[I,n[`${I}.curl`]??0]))}}function mf(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,r]of Object.entries(t.fingers))s[i]={...r,points:r.points.map(n)};return{...t,wrist:n(t.wrist),palm:t.palm.map(n),fingers:s}}function cv(t){const e=[...t].sort((r,o)=>r.x-o.x||r.y-o.y);if(e.length<3)return e;const n=(r,o,a)=>(o.x-r.x)*(a.y-r.y)-(o.y-r.y)*(a.x-r.x),s=[];for(const r of e){for(;s.length>=2&&n(s[s.length-2],s[s.length-1],r)<=0;)s.pop();s.push(r)}const i=[];for(const r of[...e].reverse()){for(;i.length>=2&&n(i[i.length-2],i[i.length-1],r)<=0;)i.pop();i.push(r)}return[...s.slice(0,-1),...i.slice(0,-1)]}function pf(t,e,n,s){if(s.mode!=="cel"||e.length<3)return;const i=Math.hypot(...s.light),r=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}}),o=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(),o(e),t.clip(),o([...e,...r.reverse()]),t.globalAlpha*=s.opacity,t.fillStyle=s.shadow,t.fill(),t.restore()}const hv="#f1c9a5",uv="#2f2f33";function Yr(t,e,n,s={},i=0){const r=mf(Kr(n,s),e),o=s.ink??uv,a=s.lineWidth??r.size*.035;let l=s.pen??ki(t,{look:s.look??"clean",ink:o,lineWidth:a,seed:s.seed??1,time:i,pencil:{construction:!1,...s.pencil}});const c=s.skin??hv;c==="none"&&(l=vi(t,l));const h=s.nails??!0,u=[{depth:r.palmDepth,draw:()=>dv(t,l,r,c,a,s)}];for(const d of Object.values(r.fingers)){const f=d.depths.reduce((m,g)=>m+g,0)/d.depths.length;u.push({depth:f,draw:()=>fv(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,m)=>f.depth-m.depth))d.draw();return t.restore(),r}function dv(t,e,n,s,i,r){if(e.shape(n.palm,s==="none"?null:s,r.connected?0:i),s!=="none"&&r.shading&&e.look==="clean"){const o=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});pf(t,n.palm,o,r.shading)}if(r.connected&&i>0&&(e.look!=="silhouette"||s==="none")){const{up:o}=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)*o.x+((c.y+h.y)/2-n.wrist.y)*o.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:o}=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-o.x*u*.2,y:h.y-o.y*u*.2},f=Math.atan2(o.y,o.x),m=Array.from({length:7},(g,p)=>{const b=f-Math.PI/2+Math.PI*p/6;return{x:d.x+Math.cos(b)*u,y:d.y+Math.sin(b)*u}});e.line(m,i*.6)}}if(n.palmFacing>.45&&e.look!=="silhouette"){const{up:o,across:a}=n.axes,l=n.size,c=n.wrist,h=(d,f)=>({x:c.x+(a.x*d+o.x*f)*l,y:c.y+(a.y*d+o.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 fv(t,e,n,s,i,r){const{widths:o}=n,a=gv(n.points,2),l=n.points[0],c=a[a.length-1],h=o[0],u=o[o.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=qt(a,h,u),p=a[a.length-2],b=Math.atan2(c.y-p.y,c.x-p.x),v=Array.from({length:13},(k,w)=>{const S=b+Math.PI/2-w*Math.PI/12;return{x:c.x+Math.cos(S)*u/2,y:c.y+Math.sin(S)*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,bi(t,a,h,u)),s==="none"||e.look==="silhouette"||!r||n.nail<.25)return;const d=a[a.length-2],f=mv({x:c.x-d.x,y:c.y-d.y})??{x:0,y:-1},m={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(m.x,m.y,u*.24*Math.max(.35,n.nail),u*.19,Math.atan2(f.y,f.x),"#f8e3d3",i*.45)}function gv(t,e){let n=t;for(let s=0;s<e;s++){if(n.length<3)return n;const i=[n[0]];for(let r=0;r<n.length-1;r++){const o=n[r],a=n[r+1];r>0&&i.push({x:o.x*.75+a.x*.25,y:o.y*.75+a.y*.25}),r<n.length-2&&i.push({x:o.x*.25+a.x*.75,y:o.y*.25+a.y*.75})}i.push(n[n.length-1]),n=i}return n}const mv=t=>{const e=Math.hypot(t.x,t.y);return e>1e-6?{x:t.x/e,y:t.y/e}:null},Gt={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,give:12},doubleBounce:{swing:22,knee:40,arm:26,elbow:24,lean:3,bounce:.02,bounces:2,squash:.04,give:10},sneak:{swing:28,knee:70,arm:6,elbow:0,forearm:110,shoulder:25,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,flight:!0,give:30},shove:{swing:18,knee:28,arm:0,elbow:0,lean:0}},pv=40;function Kl(t,e){const n=Math.cos(e*2*(t.bounces??1));return t.flight?(1-n)/2:(1+n)/2}function Yl(t,e){const n=t.give??0;return{left:n*(.4+.6*Math.max(0,-e)),right:n*(.4+.6*Math.max(0,e))}}function Ti(t){return t===void 0?Gt.walk:typeof t=="string"?Gt[t]??Gt.walk:t}function yf(t,e,n=ut,s=1){const i=Ti(t);if(i===Gt.walk)return vf(e,n,s);const r=e*Math.PI*2,o=Math.sin(r)*s,a=Math.cos(r)*s,l=w=>Math.abs(w)<=pv,c=n.lean+i.lean*s,h=(n.bend??0)+(i.bend??0),u=c+h,d=(i.shoulder??0)+u,f=(w,S)=>l(w)?S*d+i.arm*o:w,m=i.forearm??0,g=l(n.leftShoulder)?n.leftElbow-m-i.elbow*Math.max(0,-o):n.leftElbow,p=l(n.rightShoulder)?n.rightElbow+m+i.elbow*Math.max(0,o):n.rightElbow,b=Kl(i,r),v=i.crouch??0,k=Yl(i,a);return{...n,lean:c+(i.sway??0)*Math.sin(r)*(1-(n.turn??0)),bend:h,headTilt:n.headTilt-i.lean*.5*s+(i.headTilt??0),leftElbow:g,rightElbow:p,leftHip:-i.swing*o-v*.5-k.left*.5,rightHip:-i.swing*o+v*.5+k.right*.5,leftKnee:-i.knee*Math.max(0,a)-v-k.left,rightKnee:i.knee*Math.max(0,-a)+v+k.right,leftAnkle:(n.leftAnkle??0)+(i.tiptoe??0),rightAnkle:(n.rightAnkle??0)+(i.tiptoe??0),leftShoulder:f(n.leftShoulder,-1),rightShoulder:f(n.rightShoulder,1),rise:(n.rise??0)+(i.bounce??0)*s*b,stretch:n.stretch*(1+(i.squash??0)*(b-.5))}}function Xr(t,e,n=1){const s=Ti(t),i=Gt.walk.swing,r=o=>Math.sin(o*Math.PI/180);return Mf(e,n)*r(s.swing*n)/r(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 Bt(t){return{...ut,...t}}const bf={mouth:0,smile:0,mouthWidth:1,leftEye:1,rightEye:1,leftBrow:0,rightBrow:0,browTilt:0,lookX:0,lookY:0},jt=t=>({...bf,...t}),Mt={neutral:bf,happy:jt({smile:.9,leftBrow:.2,rightBrow:.2}),joyful:jt({mouth:.6,smile:1,mouthWidth:1.2,leftEye:0,rightEye:0,leftBrow:.4,rightBrow:.4}),sad:jt({smile:-.8,leftEye:.8,rightEye:.8,browTilt:.9,leftBrow:-.1,rightBrow:-.1,lookY:.6}),crying:jt({mouth:.45,smile:-1,leftEye:0,rightEye:0,browTilt:1,lookY:.4}),surprised:jt({mouth:.7,mouthWidth:.7,leftEye:1.5,rightEye:1.5,leftBrow:1,rightBrow:1}),shocked:jt({mouth:1,mouthWidth:.8,leftEye:1.6,rightEye:1.6,leftBrow:1,rightBrow:1,browTilt:.4}),angry:jt({smile:-.6,mouthWidth:.9,leftEye:.8,rightEye:.8,leftBrow:-.6,rightBrow:-.6,browTilt:-1}),furious:jt({mouth:.5,smile:-1,mouthWidth:1.3,leftEye:.9,rightEye:.9,leftBrow:-.9,rightBrow:-.9,browTilt:-1}),worried:jt({smile:-.3,mouthWidth:.8,leftEye:1.1,rightEye:1.1,leftBrow:.3,rightBrow:.3,browTilt:.8,lookX:-.5}),scared:jt({mouth:.35,smile:-.5,mouthWidth:.8,leftEye:1.45,rightEye:1.45,leftBrow:.8,rightBrow:.8,browTilt:.9}),confused:jt({smile:-.2,mouthWidth:.8,leftEye:.9,rightEye:1.15,leftBrow:-.3,rightBrow:.8,lookX:.5,lookY:-.4}),skeptical:jt({smile:-.1,leftEye:.6,rightEye:1,leftBrow:-.4,rightBrow:.7,lookX:.4}),thinking:jt({smile:0,mouthWidth:.7,leftBrow:.3,rightBrow:.5,lookX:.6,lookY:-.8}),sleepy:jt({smile:.1,leftEye:.25,rightEye:.25,leftBrow:-.3,rightBrow:-.3,lookY:.5}),disgusted:jt({smile:-.7,mouthWidth:.9,leftEye:.6,rightEye:.75,leftBrow:-.5,rightBrow:-.2,browTilt:-.4,lookX:-.6}),smug:jt({smile:.6,mouthWidth:.9,leftEye:.6,rightEye:.6,leftBrow:.1,rightBrow:.5,lookX:.5}),wink:jt({smile:.9,leftEye:0,rightEye:1,leftBrow:-.2,rightBrow:.3})};function an(t,e){return{...t,...typeof e=="string"?Mt[e]:e}}const he={rest:ut,wave:Bt({rightShoulder:135,rightElbow:30,headTilt:6,...Mt.happy}),cheer:Bt({leftShoulder:125,leftElbow:20,rightShoulder:125,rightElbow:20,...Mt.joyful}),shrug:Bt({leftShoulder:30,leftElbow:85,rightShoulder:30,rightElbow:85,headTilt:-10,...Mt.confused,lookX:0,lookY:0}),point:Bt({rightShoulder:90,rightElbow:0,lean:4,smile:.4}),think:Bt({rightShoulder:60,rightElbow:150,headTilt:10,...Mt.thinking}),handsOnHips:Bt({leftShoulder:45,leftElbow:-100,rightShoulder:45,rightElbow:-100,leftHip:14,rightHip:14,smile:.8}),sad:Bt({leftShoulder:14,rightShoulder:14,leftElbow:-4,rightElbow:-4,headTilt:-14,lean:-3,...Mt.sad}),surprised:Bt({leftShoulder:70,leftElbow:60,rightShoulder:70,rightElbow:60,...Mt.surprised}),crouch:Bt({stretch:.72,leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50,leftHip:22,rightHip:22,headTilt:-4}),sit:Bt({sit:1,turn:.5,leftShoulder:-25,rightShoulder:25,leftElbow:-55,rightElbow:55}),jump:Bt({stretch:1.22,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4,...Mt.joyful}),duck:Bt({stretch:.62,bend:28,headTilt:-8,leftShoulder:150,rightShoulder:150,leftElbow:130,rightElbow:130,leftHip:25,rightHip:25,...Mt.scared}),lie:Bt({spin:-90,rise:-.42,leftShoulder:165,rightShoulder:165,leftElbow:150,rightElbow:150,...Mt.sleepy}),sideSplit:Bt({leftHip:90,rightHip:90,leftAnkle:-45,rightAnkle:-45,leftShoulder:120,rightShoulder:120,leftElbow:10,rightElbow:10,...Mt.happy}),frontSplit:Bt({turn:1,leftHip:-90,rightHip:-90,leftAnkle:-45,rightAnkle:-45,leftShoulder:-150,rightShoulder:150,leftElbow:10,rightElbow:-10,...Mt.happy})},wf=Object.keys(ut);function gs(t,e,n){const s={...t};for(const i of wf)s[i]=t[i]+(e[i]-t[i])*n;return s}const Xl=24,Gl=4,kf=28,yv=40;function vf(t,e=ut,n=1){const s=Math.sin(t*Math.PI*2)*n,i=Math.cos(t*Math.PI*2)*n,r=h=>Math.abs(h)<=yv,o=e.lean+Gl*n+(e.bend??0),a=(h,u)=>r(h)?u*o+22*s:h,l=r(e.leftShoulder)?e.leftElbow-kf*Math.max(0,-s):e.leftElbow,c=r(e.rightShoulder)?e.rightElbow+kf*Math.max(0,s):e.rightElbow;return{...e,lean:e.lean+Gl*n,headTilt:e.headTilt-Gl*.5*n,leftElbow:l,rightElbow:c,leftHip:-Xl*s,rightHip:-Xl*s,leftKnee:-30*Math.max(0,i),rightKnee:30*Math.max(0,-i),leftShoulder:a(e.leftShoulder,-1),rightShoulder:a(e.rightShoulder,1)}}function Mf(t,e=1){return 4*((Ul+Gr)*t)*Math.sin(Xl*e*Math.PI/180)}function Sf(t){const e=Math.abs(Math.sin(t/65)),n=.55+.45*Math.sin(t/310);return e*n}const Tf=.12,Ef=.46,bv=1-2*Tf,wv=.1,kv=.21,vv=.19,Ul=.24,Gr=.22,Af=.12,Mv=.14,xf=.33,Pf=.7,$f=.3,Sv=.35,Tv=[1.7,1.05],Ev=[1.3,.75],If=[1.45,.85],Av=[1.15,.75],Of=.06,xv=.7,Pv=.65,Cf=.075,$v=.3,Iv=.02,Ov=.012,Cv=12,_v=.25,Ur=90,Rv=.25,Hv=.04,_f=.01,Hn=t=>Math.min(1,Math.max(0,t??0));function Fv(t,e=1){return Gr*t*e}const Vl=-.12,Rf=.4,me=t=>t*Math.PI/180,Lv=(t,e)=>({x:e*Math.sin(me(t)),y:Math.cos(me(t))}),Hf=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),Ff=(t,e,n,s)=>t-.3*e-n*.14*e-Math.max(0,s-1)*.12*e;function Nv(t,e,n,s,i,r){const o=Math.max(1,Math.min(r*.6,Mv*n)),a=Hn(e.turn),l=(Af+xf*a)*n,c=s+Vl*n,h=l+e.lookX*.08*n,u=e.lookY*.07*n,d=[{x:-.34*n*(1-Pf*a),squeeze:1-Pf*a,open:e.leftEye,brow:e.leftBrow,side:-1},{x:.34*n*(1-$f*a),squeeze:1-$f*a,open:e.rightEye,brow:e.rightBrow,side:1}];t.fillStyle=i,t.strokeStyle=i,t.lineWidth=o;for(const b of d){const v=Hf(b.open,e.blink);if(v<.2){const x=e.smile>.5?-.12*n:.06*n;t.beginPath(),t.moveTo(b.x+l-.12*n,c),t.quadraticCurveTo(b.x+l,c+x,b.x+l+.12*n,c),t.stroke()}else{if(v>1.2){const M=.13*n*v;t.beginPath(),t.ellipse(b.x+l,c,M*.85,M,0,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.stroke(),t.fillStyle=i}const x=v>1.2?.075*n:.1*n;t.beginPath(),t.ellipse(b.x+h,c+u,x,x*1.1*Math.min(v,1),0,0,Math.PI*2),t.fill()}const k=Ff(c,n,b.brow,v),w=b.x+l-b.side*.13*n*b.squeeze,S=b.x+l+b.side*.13*n*b.squeeze;t.beginPath(),t.moveTo(S,k),t.lineTo(w,k-e.browTilt*.1*n),t.stroke()}const f=s+Rf*n,m=.25*n*Math.max(.3,e.mouthWidth)*(1-Sv*a),g=Math.min(1,Math.max(0,e.mouth));if(t.beginPath(),g<=.05){t.moveTo(l-m,f),t.quadraticCurveTo(l,f+e.smile*.25*n,l+m,f),t.stroke();return}const p=.3*n*g;e.smile>.3?(t.moveTo(l-m,f-.05*n),t.lineTo(l+m,f-.05*n),t.quadraticCurveTo(l,f+p*2,l-m,f-.05*n)):e.smile<-.3?(t.moveTo(l-m,f+p*.6),t.lineTo(l+m,f+p*.6),t.quadraticCurveTo(l,f-p*1.4,l-m,f+p*.6)):t.ellipse(l,f,m*.8,p,0,0,Math.PI*2),t.fill()}function Lf(t,e){const n=e.height??300,s=Math.min(3,Math.max(.3,t.stretch??1)),i=Math.sqrt(s),r=e.armLength??1;if(!Number.isFinite(r)||r<=0)throw new Error("stick figure: armLength must be a positive finite multiplier");const o=(e.headSize??2*Tf)/2,a=e.headSize===void 0?bv:1-2*o,l=o*n,c=Hn(t.sit),h=t.leftHip+(-Ur-t.leftHip)*c,u=t.leftKnee+(-Ur-t.leftKnee)*c,d=t.rightHip+(Ur-t.rightHip)*c,f=t.rightKnee+(Ur-t.rightKnee)*c,m=e.classic===!0,g=Hn(t.turn),p=(J,F,B,Y,R)=>{const K=Math.max(-Math.PI/2,Math.min(Math.PI/2,Math.abs(me(F-B)/2)+me(Y))),st=Math.max(-1,Math.min(1,xv+R)),$=g+(1-g)*J*st;return m?{x:0,y:0}:{x:Math.cos(K)*Of*$,y:Math.sin(K)*Of}},b={left:t.leftAnkle??0,right:t.rightAnkle??0},v={left:t.leftFootOut??0,right:t.rightFootOut??0};let k=0;if(c>0||!m){const J=(R,K,st,$,C)=>Ul*Math.cos(me(K))+Gr*Math.cos(me(K-st))+Math.max(0,p(R,K,st,$,C).y),F=Math.max(J(-1,h,u,b.left,v.left),J(1,d,f,b.right,v.right)),B=1-Hn((t.rise??0)/Hv),Y=(m?Math.min(1,c/Rv):1)*B;k=(Ef-F)*Y*n*s}const w=-Ef*n*s+k,S=-a*n*s+k,x=m?0:(Iv*Hn(t.turn)+Ov*c)*n*s,M=me(t.bend??0),E={end:Wf(w,S,M,1),bend:M};let T;if(M!==0){T=[];for(let J=0;J<=Nf;J++){const F=J/Nf,B=Wf(w,S,M,F);T.push({x:B.x-x*Math.sin(Math.PI*F),y:B.y})}}else T=x===0?[{x:0,y:w},{x:0,y:S}]:Rn({x:0,y:w},{x:-x,y:(w+S)/2},{x:0,y:S},1,8);const A=S+wv*n*s,P=(e.shoulderWidth??0)*n*Math.cos(g*Math.PI/2),I=(J,F,B,Y,R)=>{const K=Lv(B,Y);return{x:J+K.x*R*n,y:F+K.y*R*n}},O=(J,F,B)=>{const Y=I(0,w,F,J,Ul*s);return{root:{x:0,y:w},joint:Y,end:I(Y.x,Y.y,F-B,J,Gr*s)}},_=(J,F,B)=>{const Y={x:J*P,y:A},R=I(Y.x,Y.y,F,J,kv*i*r);return{root:Y,joint:R,end:I(R.x,R.y,F+B,J,vv*i*r)}},L={left:O(-1,h,u),right:O(1,d,f)},j=(J,F,B,Y,R,K)=>{const st=p(J,B,Y,R,K);return{x:F.end.x+st.x*n*s,y:F.end.y+st.y*n*s}},V=(J,F,B,Y,R)=>I(F.end.x,F.end.y,B+Y+R,J,Cf*i),tt={left:_(-1,t.leftShoulder,t.leftElbow),right:_(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(m?0:$v,e.rubber??0)),r:l,headRx:l/Math.sqrt(s),headRy:l*Math.sqrt(s),hipY:w,neckY:S,drop:k,lean:m?t.lean:t.lean+Cv*Math.sin(Math.PI*c),classic:m,legs:L,toes:{left:j(-1,L.left,h,u,b.left,v.left),right:j(1,L.right,d,f,b.right,v.right)},spine:T,chest:E,arms:tt,handTips:{left:V(-1,tt.left,t.leftShoulder,t.leftElbow,t.leftWrist??0),right:V(1,tt.right,t.rightShoulder,t.rightElbow,t.rightWrist??0)}}}const Nf=10;function Wf(t,e,n,s){const i=t-e,r=n*s;if(Math.abs(n)<1e-9)return{x:0,y:t-i*s};const o=i/n;return{x:o*(1-Math.cos(r)),y:t-o*Math.sin(r)}}function Wv(t,e){if(t.chest.bend===0)return e;const n=Ai(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 Ei=(t,e)=>e===0?[t.root,t.joint,t.end]:Rn(t.root,t.joint,t.end,e);function Ai(t,e,n){const s=Math.cos(n),i=Math.sin(n),r=t.x-e.x,o=t.y-e.y;return{x:e.x+r*s-o*i,y:e.y+r*i+o*s}}function Df(t,e,n=!0){const s=Bv(t,e),i=e.spin??0,r=e.rise??0;return n&&(i!==0||r!==0)?Dv(s,t,i,r):s}function Bf(t,e,n){return{pivot:{x:0,y:t.hipY},angle:t.facing*me(e),lift:n*t.height}}function Dv(t,e,n,s){const{pivot:i,angle:r,lift:o}=Bf(e,n,s),a=d=>{const f=Ai(d,i,r);return{x:f.x,y:f.y-o}},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=_f*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+r,right:t.handAngle.right+r},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+r}}}function Bv(t,e){const n=me(t.lean),s=me(e.headTilt),i={x:0,y:t.hipY},r=w=>({x:t.facing*w.x,y:w.y}),o=w=>r(Ai(w,i,n)),a=w=>o(Wv(t,w)),l=w=>a(Ai({x:w.x,y:w.y+t.neckY},{x:0,y:t.neckY},s)),c=Ei(t.arms.left,t.rubber).map(a),h=Ei(t.arms.right,t.rubber).map(a),u=(w,S)=>Math.atan2(S.y-w.y,S.x-w.x),d={left:a(t.handTips.left),right:a(t.handTips.right)},f=(w,S)=>{const[x,M]=w.slice(-2),E=t.arms[S],T=u(a(E.end),d[S])-u(a(E.joint),a(E.end));return u(x,M)+T};let m=1/0;for(const[w,S]of[[e.leftBrow,e.leftEye],[e.rightBrow,e.rightEye]]){const x=Ff(Vl,1,w,Hf(S,e.blink));m=Math.min(m,x,x-e.browTilt*.1)}const g={left:r(t.legs.left.end),right:r(t.legs.right.end)},p={left:r(t.toes.left),right:r(t.toes.right)},b={left:Math.max(g.left.y,p.left.y),right:Math.max(g.right.y,p.right.y)},v=Math.max(b.left,b.right),k=_f*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:r(t.legs.left.joint),right:r(t.legs.right.joint)},feet:g,toes:p,feetY:v,grounded:{left:b.left>=v-k,right:b.right>=v-k},fingertips:d,handAngle:{left:f(c,"left"),right:f(h,"right")},limbs:{leftArm:c,rightArm:h,leftLeg:Ei(t.legs.left,t.rubber).map(r),rightLeg:Ei(t.legs.right,t.rubber).map(r),spine:t.spine.map(o)},head:{center:l({x:0,y:-t.headRy}),rx:t.headRx,ry:t.headRy,angle:t.facing*(n+t.chest.bend+s),eyeY:Vl,browTopY:m,mouthY:Rf,faceX:t.facing*(Af+xf*Hn(e.turn))}}}function Ee(t,e={}){return Df(Lf(t,e),t)}function zv(t,e,n){return Ai({x:t.center.x+e*t.rx,y:t.center.y+n*t.ry},t.center,t.angle)}function zf(t,e,n){const s=r=>({x:r.x+e,y:r.y+n}),i=r=>({left:s(r.left),right:s(r.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 qf(t,e,n={},s=0){const i=Lf(e,n),r=n.color??"#1e293b",o=n.layers??{},a=n.layers?Df(i,e,!1):void 0,l=n.sketch?Dr(t,n.sketch,s):void 0,c=n.sketch&&n.layers?Dr(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(me(i.lean)),t.translate(0,-i.hipY)},m=()=>{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,E,T)=>{if(l)return E?l.curve(M):l.line(M);if(i.classic){t.beginPath(),t.moveTo(M[0].x,M[0].y);for(const A of M.slice(1))t.lineTo(A.x,A.y);t.stroke();return}bi(t,M,T[0]*i.lineWidth,T[1]*i.lineWidth)},p=(M,E)=>g(Ei(M,i.rubber),i.rubber>0,E),b=M=>{i.classic||g([i.legs[M].end,i.toes[M]],!1,Av)},v=M=>{if(n.hands&&!i.classic)return w(M);if(i.classic||l)return;const E=i.arms[M].end;t.beginPath(),t.arc(E.x,E.y,Pv*i.lineWidth,0,Math.PI*2),t.fill()};t.save(),t.strokeStyle=r,t.fillStyle=r,t.lineWidth=i.lineWidth,t.lineCap="round",t.lineJoin="round";const k=Bf(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 w(M){const E=n.hands??{},T=i.arms[M].end,A=i.handTips[M],P=n.headFill??"#ffffff";Yr(t,T,E[M]??Ct,{side:M,angle:Math.atan2(A.x-T.x,T.y-A.y)*180/Math.PI,size:(E.size??Cf)*i.height*Math.sqrt(i.stretch),skin:E.skin??(P==="none"?void 0:P),ink:r,lineWidth:i.lineWidth*.45,fingers:E.fingers,plump:E.plump,look:n.sketch?"pencil":"clean",seed:n.sketch?.seed},s)}const S=M=>{h(()=>{m(),p(i.arms[M],Ev),v(M)});const E=o.sleeve;E&&a&&h(()=>E(t,a,M,s,c))},x=Hn(e.turn)>_v;u(o.behind),h(()=>{d(),p(i.legs.left,If),b("left"),p(i.legs.right,If),b("right")}),x&&S("left"),h(()=>{f(),g(i.spine,i.spine.length>2,Tv)}),h(()=>{m();const{left:M,right:E}={left:i.arms.left.root,right:i.arms.right.root};if(M.x!==E.x)if(i.classic)g([M,E],!1,[1,1]);else{const T={x:(M.x+E.x)/2,y:M.y-.3*Math.abs(E.x-M.x)};g(Rn(M,T,E,1,8),!0,[1.1,1.1])}}),u(o.body),x||S("left"),S("right"),u(o.behindHead),h(()=>{m(),t.translate(0,i.neckY),t.rotate(me(e.headTilt));const M=-i.headRy;t.beginPath(),t.ellipse(0,M,i.headRx,i.headRy,0,0,Math.PI*2);const E=n.headFill??"#ffffff";if(E!=="none"&&(t.fillStyle=E,t.fill()),l){l.ellipse(0,M,i.headRx,i.headRy);const T=l.nudge();t.translate(T.x,T.y)}else t.stroke();t.translate(0,M),t.scale(i.headRx/i.r,i.headRy/i.r),Nv(t,e,i.r,0,r,i.lineWidth)}),u(o.overHead),u(o.front),t.restore(),n.label&&(t.save(),t.fillStyle=r,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 Jl(t,e,n,s){const i={...t},r=t.gait&&s?.[t.gait]||t.gait;let o=t.walking>0?gs(i,yf(r,t.walk,i),t.walking):i,a=qv(t);const l=t.dancing??0;if(n&&l>0){const c=n(t.beat??0);if(o=gs(o,c.pose,l),c.hands){const h=(u,d)=>d?fs(u??Ct,d,l):u;a={left:h(a?.left,c.hands.left),right:h(a?.right,c.hands.right)}}}return t.talk>0&&(o={...o,mouth:Math.max(o.mouth,t.talk*Sf(e))}),{pose:o,hands:a}}function jf(t,e,n,s){return Jl(t,e,n,s).pose}const Kf=(t,e)=>(t.facing??e.facing??1)<0?-1:1,xi=(t,e)=>`hand.${t}.${e}`;function qv(t){const e=i=>{if(typeof t[xi(i,"spread")]=="number")return Object.fromEntries(Object.keys(Ct).map(r=>[r,t[xi(i,r)]]))},n=e("left"),s=e("right");return n||s?{left:n,right:s}:void 0}function jv(t,e){return!e||!t.hands?t:{...t,hands:{...t.hands,left:e.left??t.hands.left,right:e.right??t.hands.right}}}function Zl(t){const e=t.style??{},n=e.height??300,s=n*.8,i={...Bt(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},r={};if(e.hands)for(const o of["left","right"]){const a=e.hands[o]??Ct;for(const l of Object.keys(Ct))r[xi(o,l)]=a[l]??Ct[l]}return{type:"custom",x:t.x-s/2,y:t.y-n,width:s,height:n,props:{...i,...r},about:Kv(Object.keys(r),t.cast),figureStyle:e,figureDance:t.dance,figureGaits:t.cast?.gaits,draw(o,a,l){const c=a.props,h=Jl(c,l,t.dance,t.cast?.gaits);o.translate(s/2,n),qf(o,h.pose,jv({...e,rubber:c.rubber,facing:Kf(c,e)},h.hands),l)}}}function Kv(t,e){const n={...Zd,...Qd};for(const s of t){const[,i,...r]=s.split("."),o=tf[r.join(".")];o&&(n[s]={...o,description:`${i==="left"?"Left":"Right"} hand: ${o.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 B5(e)}}}function Ql(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 r=0,o=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"?r=h:c==="y"||c==="motionPathY"?o=h:c in i&&(i[c]=h));const a=jf(i,e.time,t.figureDance,t.figureGaits),l=Ee(a,{...s,rubber:i.rubber,facing:Kf(i,s)});return{pose:a,joints:zf(l,t.x+r+t.width/2,t.y+o+t.height)}}function Vr(t){const e=[];return t.forEach((n,s)=>{const i=s===0?ut:e[s-1],r=typeof n.pose=="string"?he[n.pose]:{...i,...n.pose};e.push(n.expression?an(r,n.expression):r)}),e}function Yv(t,e){const n=Vr(e);return wf.filter(s=>n.some(i=>i[s]!==ut[s])).map(s=>({id:`${t}-${s}`,target:t,property:s,keyframes:e.map((i,r)=>({time:i.time,value:n[r][s],...i.easing?{easing:i.easing}:{}}))}))}const tc=.5,Jr={pataka:Wt({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:0,turn:2}),tripataka:Wt({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":1,"pinky.curl":0,spread:0,turn:2}),alapadma:Wt({"thumb.curl":.1,"thumb.across":0,"index.curl":.05,"middle.curl":.15,"ring.curl":.25,"pinky.curl":.35,spread:1,turn:2}),mushti:Tt.fist,shikhara:Tt.thumbsUp,hamsasya:Wt({"thumb.curl":.15,"thumb.across":.6,"index.curl":.6,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:.7,turn:2}),katakamukha:Wt({"thumb.curl":.2,"thumb.across":.6,"index.curl":.65,"middle.curl":.7,"ring.curl":0,"pinky.curl":0,spread:.4,turn:2})};function Zr(t){return typeof t!="string"?t:t in Jr?Jr[t]:Tt[t]}function Yf(t,e,n){const s=[];for(const i of t.keys){const r=s[s.length-1],o=!r||i.reset?{pose:e,...n}:r;s.push({beat:i.beat,pose:{...o.pose,...i.pose},left:i.hands?.left?Zr(i.hands.left):o.left,right:i.hands?.right?Zr(i.hands.right):o.right,easing:i.easing??t.easing})}return s}const ec=(t,e)=>(t%e+e)%e;function Xv(t,e,n,s){const i=Yf(t,n,s);if(i.length===0)return{pose:n,hands:s};const r=ec(e,t.beats);let o=i.length-1;for(let f=0;f<i.length;f++)i[f].beat<=r&&(o=f);const a=i[o],l=i[(o+1)%i.length],c=a.beat<=r?a.beat:a.beat-t.beats,h=l.beat>c?l.beat:l.beat+t.beats,u=h>c?(r-c)/(h-c):0,d=Dt(l.easing??"ease-in-out")(Math.min(1,Math.max(0,u)));return{pose:gs(a.pose,l.pose,d),hands:{left:fs(a.left,l.left,d),right:fs(a.right,l.right,d)}}}const Gv=[["leftShoulder","rightShoulder"],["leftElbow","rightElbow"],["leftWrist","rightWrist"],["leftHip","rightHip"],["leftKnee","rightKnee"],["leftAnkle","rightAnkle"],["leftFootOut","rightFootOut"],["leftEye","rightEye"],["leftBrow","rightBrow"]],Uv=["lean","headTilt","lookX","spin"],Vv=new Set(["leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee"]);function Xf(t){const e={...t},n=(t.turn??0)>=.5;for(const[s,i]of Gv){const r=n&&Vv.has(s)?-1:1;e[s]=r*t[i],e[i]=r*t[s]}if(!n)for(const s of Uv)e[s]=-t[s];return e}const Jv=t=>Math.min(1,Math.max(-1,(.5-t)*4));function Gf(t,e,n){const s=ec(n,1),i=(1+Math.cos(2*Math.PI*s))/2,r=e.bounce*(e.accent==="up"?1-i:i),o=Math.min(1,Math.max(0,t.turn??0)),a=Jv(o);return{...t,leftHip:t.leftHip+a*r/2,rightHip:t.rightHip+r/2,leftKnee:t.leftKnee+a*r,rightKnee:t.rightKnee+r,lean:t.lean+(e.sway??0)*(1-o)*Math.sin(Math.PI*n)}}function Qr(t){const e={...ut,...t.stance};return t.expression?an(e,t.expression):e}function Uf(t){return{left:t.hands?.left?Zr(t.hands.left):Ct,right:t.hands?.right?Zr(t.hands.right):Ct}}function nc(t,e,n){const s=t.moves[e.move];if(!s)throw new Error(`dance: "${t.label}" has no move "${e.move}"`);const i=Xv(s,n,Qr(t),Uf(t));return e.mirror?{pose:Xf(i.pose),hands:{left:i.hands?.right,right:i.hands?.left}}:i}function to(t,e,n={}){const s=typeof t=="string"?ln[t]:t;let i;if(n.move)i=nc(s,{move:n.move,mirror:n.mirror},e);else{const r=s.routine,o=r.reduce((u,d)=>u+d.beats,0),a=ec(e,o);let l=0,c=0;for(;c<r.length-1&&a>=l+r[c].beats;)l+=r[c++].beats;const h=a-l;if(i=nc(s,r[c],h),h<tc&&r.length>1&&e>=tc){const u=r[(c-1+r.length)%r.length],d=nc(s,u,u.beats+h),f=Dt("ease-in-out")(h/tc);i={pose:gs(d.pose,i.pose,f),hands:{left:fs(d.hands.left,i.hands.left,f),right:fs(d.hands.right,i.hands.right,f)}}}}return{...i,pose:Gf(i.pose,s.groove,e)}}function Zv(t,e,n={}){return to(t,e,n).pose}function eo(t){return(typeof t=="string"?ln[t]:t).routine.reduce((n,s)=>n+s.beats,0)}const Qv={leftToe:"rightToe",rightToe:"leftToe",leftHeel:"rightHeel",rightHeel:"leftHeel"};function Vf(t,e,n,s,i,r,o){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<r||h>=o))for(const u of l.taps??[])i.push({beat:h,tap:s?Qv[u]:u})}}function tM(t,e,n,s={}){const i=typeof t=="string"?ln[t]:t,r=[];if(n<=e)return r;if(s.move){const o=i.moves[s.move],a=Math.floor(e/o.beats)*o.beats;Vf(o,a,Math.ceil((n-a)/o.beats)*o.beats,s.mirror,r,e,n)}else{const o=eo(i);for(let a=Math.floor(e/o)*o;a<n;a+=o){let l=a;for(const c of i.routine)Vf(i.moves[c.move],l,c.beats,c.mirror,r,e,n),l+=c.beats}}return r.sort((o,a)=>o.beat-a.beat)}function Jf(t,e){const n=t.moves[e.move];if(!n?.travel)return 0;const s=n.travel/n.beats;return e.mirror?(Yf(n,Qr(t),Uf(t))[0]?.pose.turn??Qr(t).turn??0)>=.5?s:-s:s}function Zf(t,e){return e.move?[{move:e.move,beats:t.moves[e.move].beats,mirror:e.mirror}]:t.routine}function no(t,e,n={}){const s=typeof t=="string"?ln[t]:t,i=Zf(s,n),r=i.reduce((h,u)=>h+u.beats,0),o=i.reduce((h,u)=>h+Jf(s,u)*u.beats,0),a=Math.floor(e/r);let l=a*o,c=e-a*r;for(const h of i){const u=Math.min(h.beats,c);if(l+=Jf(s,h)*u,c-=u,c<=0)break}return l}function eM(t,e,n){const s=Zf(t,n),i=[0];let r=0;for(let o=0;r<e;o=(o+1)%s.length)r+=s[o].beats,i.push(Math.min(r,e));return i}const nM=8;function Qf(t,e,n){const s=typeof e=="string"?ln[e]:e,i=n.bpm??s.bpm,r=n.beats??(n.move?s.moves[n.move].beats:eo(s)),o=eM(s,r,n);if(o.every(b=>no(s,b,n)===0))return;const a=Math.min(n.fade??1,r/2),l=Dt("ease-in-out"),c=b=>a<=0?1:Math.min(l(Math.min(1,b/a)),l(Math.min(1,(r-b)/a))),h=Math.ceil(a*nM),u=a<=0?[]:Array.from({length:h+1},(b,v)=>[v/h*a,r-v/h*a]).flat(),d=[...new Set([...o,...u])].sort((b,v)=>b-v);let f=0;const m=d.map((b,v)=>{if(v>0){const k=d[v-1],w=Math.max(1,Math.ceil((b-k)*16));for(let S=0;S<w;S++){const x=k+(b-k)*S/w,M=k+(b-k)*(S+1)/w;f+=(no(s,M,n)-no(s,x,n))*c((x+M)/2)}}return{beat:b,travel:f}}),g=n.start??0,p=n.x??0;return{id:`${t}-x`,target:t,property:"x",keyframes:m.map(b=>({time:g+b.beat*6e4/i,value:p+n.height*b.travel,easing:"linear"}))}}function sM(t,e,n=0){return(t-n)*e/6e4}function iM(t,e={}){return n=>to(t,n,e)}function rM(t,e){const n=e.start??0,s=6e4/e.bpm,i=n+e.beats*s,r=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+r,value:1,easing:"ease-in-out"},{time:i-r,value:1},{time:i,value:0,easing:"ease-in-out"}]}]}function oM(t,e,n={}){const s=typeof e=="string"?ln[e]:e,i=n.bpm??s.bpm,r=n.beats??(n.move?s.moves[n.move].beats:eo(s)),o=n.samplesPerBeat??4,a=n.start??0,l=Math.round(r*o),c=Array.from({length:l+1},(g,p)=>{const b=p/o;return{time:a+b*6e4/i,frame:to(s,b,n)}}),h=(g,p)=>({id:`${t}-${g}`,target:t,property:g,keyframes:c.map(b=>({time:b.time,value:p(b.frame)}))}),d=Object.keys(ut).filter(g=>c.some(p=>p.frame.pose[g]!==c[0].frame.pose[g])||c[0].frame.pose[g]!==ut[g]).map(g=>h(g,p=>p.pose[g])),f=n.height===void 0?void 0:Qf(t,s,{...n,bpm:i,beats:r,start:a,height:n.height,fade:0});if(f&&d.push(f),n.hands===!1)return d;const m=[];for(const g of["left","right"])for(const p of Object.keys(Ct)){const b=v=>v.hands?.[g]?.[p]??Ct[p];c.some(v=>b(v.frame)!==Ct[p])&&m.push(h(xi(g,p),b))}return[...d,...m]}const Pi={type:"back",mode:"out",overshoot:1.1},te="ease-out-cubic",aM={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:te,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:te},{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:te},{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}]},lM={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}]},cM={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:te},{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:te},{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:te},{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:Pi},{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}]},hM={label:"Jazz",bpm:130,stance:{leftHip:10,rightHip:10},expression:{mouth:.55,smile:1,mouthWidth:1.2,leftBrow:.6,rightBrow:.6},hands:{left:"spread",right:"spread"},groove:{bounce:6,accent:"up"},moves:{jazzHands:{label:"Jazz hands",beats:2,easing:"linear",keys:[0,.25,.5,.75,1,1.25,1.5,1.75].map((t,e)=>({beat:t,pose:{leftShoulder:128,rightShoulder:128,leftElbow:8,rightElbow:8,leftWrist:e%2?4:26,rightWrist:e%2?26:4,leftHip:16,rightHip:16,leftKnee:t<1?26:8,rightKnee:t<1?26:8},hands:e===0?{left:{...Tt.spread,turn:2},right:{...Tt.spread,turn:2}}:void 0}))},kickBallChange:{label:"Kick ball change",beats:2,keys:[{beat:0,reset:!0,pose:{rightHip:88,rightKnee:0,rightAnkle:55,leftHip:4,lean:-12,leftShoulder:112,rightShoulder:112,leftWrist:15,rightWrist:15},hands:{left:"flat",right:"flat"},easing:te},{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}]},uM={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:Pi,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:Pi},{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:Pi},{beat:3,pose:{headTilt:4}}]},isolations:{label:"Isolations",beats:2,easing:te,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}]},dM={label:"Bollywood",bpm:120,stance:{leftHip:10,rightHip:10},expression:{smile:1,mouth:.3,leftBrow:.4,rightBrow:.4},groove:{bounce:8,accent:"down",sway:3},moves:{lightBulb:{label:"Screw the bulb, pat the dog",beats:2,keys:[{beat:0,reset:!0,pose:{rightShoulder:160,rightElbow:12,rightWrist:-15,leftShoulder:40,leftElbow:-12,leftWrist:-45,lean:-4,rightHip:16,lookX:.5,lookY:-.6},hands:{right:{...Tt.cupped,roll:-30},left:{...Tt.flat,turn:0}}},{beat:.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{...Tt.cupped,roll:30}}},{beat:1,pose:{rightWrist:-15,rightElbow:12,leftWrist:-45,lean:-4,rightHip:16,leftHip:6},hands:{right:{...Tt.cupped,roll:-30}}},{beat:1.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{...Tt.cupped,roll:30}}}]},thumka:{label:"Thumka",beats:2,keys:[{beat:0,reset:!0,pose:{lean:-11,rightHip:22,leftHip:2,leftKnee:14,rightShoulder:45,rightElbow:-105,leftShoulder:128,leftElbow:18,leftWrist:35,headTilt:10,lookX:-.5},hands:{right:"fist",left:{...Tt.open,turn:2}},easing:te},{beat:.5,pose:{lean:-4,rightHip:12,headTilt:6}},{beat:1,pose:{lean:-11,rightHip:22,headTilt:10},easing:te},{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:te},{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:te}]}},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}]},fM={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}]},gM={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}]},mM={label:"Charleston",bpm:150,stance:{leftHip:10,rightHip:10,leftKnee:10,rightKnee:10,leftShoulder:30,rightShoulder:30,leftElbow:20,rightElbow:20},expression:{mouth:.4,smile:1,leftBrow:.5,rightBrow:.5},hands:{left:{...Tt.spread,turn:2},right:{...Tt.spread,turn:2}},groove:{bounce:8,accent:"down"},moves:{basic:{label:"Kick forward, kick back",beats:4,keys:[{beat:0,reset:!0,pose:{rightHip:48,rightKnee:8,rightAnkle:45,leftShoulder:75,rightShoulder:15,leftElbow:30,rightElbow:-10,lean:-7,headTilt:-5},easing:te},{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:te},{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}]},pM={label:"Tap",bpm:120,stance:{turn:.8,leftHip:-3,rightHip:3,leftKnee:-10,rightKnee:10,leftShoulder:12,rightShoulder:12,leftElbow:-40,rightElbow:40,leftWrist:-15,rightWrist:15,lean:4},expression:{smile:.9,mouth:.2,leftBrow:.3,rightBrow:.3,lookY:.3},hands:{left:"relaxed",right:"relaxed"},groove:{bounce:6,accent:"down"},moves:{shuffleBallChange:{label:"Shuffle ball change",beats:2,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:34,rightKnee:8,rightAnkle:30,leftShoulder:30,rightShoulder:-10},taps:["rightToe"]},{beat:.25,pose:{rightHip:24,rightKnee:62,rightAnkle:40},taps:["rightToe"]},{beat:.5,pose:{rightHip:-8,rightKnee:14,rightAnkle:50,leftAnkle:15,leftShoulder:12,rightShoulder:12},taps:["rightToe"]},{beat:.75,pose:{rightHip:3,rightKnee:10,rightAnkle:0,leftAnkle:0},taps:["leftHeel"]},{beat:1,reset:!0,pose:{leftHip:-34,leftKnee:-8,leftAnkle:30,rightShoulder:-30,leftShoulder:10},taps:["leftToe"]},{beat:1.25,pose:{leftHip:-24,leftKnee:-62,leftAnkle:40},taps:["leftToe"]},{beat:1.5,pose:{leftHip:8,leftKnee:-14,leftAnkle:50,rightAnkle:15,leftShoulder:12,rightShoulder:12},taps:["leftToe"]},{beat:1.75,pose:{leftHip:-3,leftKnee:-10,leftAnkle:0,rightAnkle:0},taps:["rightHeel"]}]},timeStep:{label:"Single time step",beats:4,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:8,rightKnee:4,rightAnkle:0,leftShoulder:25,rightShoulder:-20},taps:["rightToe","rightHeel"]},{beat:.5,pose:{rightHip:34,rightKnee:8,rightAnkle:30},taps:["rightToe"]},{beat:.75,pose:{rightHip:22,rightKnee:62,rightAnkle:40},taps:["rightToe"]},{beat:1,pose:{rise:.05,leftAnkle:45,leftKnee:-4,leftHip:-2,rightHip:26,rightKnee:70,stretch:1.03}},{beat:1.25,pose:{rise:0,leftAnkle:0,leftKnee:-14,stretch:1},taps:["leftToe"]},{beat:1.5,pose:{rightHip:4,rightKnee:12,rightAnkle:0,rightShoulder:25,leftShoulder:-20},taps:["rightToe"]},{beat:2,pose:{leftHip:-30,leftKnee:-6,leftAnkle:35},taps:["leftToe"]},{beat:2.25,pose:{leftHip:-4,leftKnee:-12,leftAnkle:0},taps:["leftToe"]},{beat:3,pose:{rightHip:10,rightAnkle:35,rightKnee:18,leftShoulder:12,rightShoulder:12},taps:["rightToe"]},{beat:3.5,pose:{rightHip:3,rightKnee:10,rightAnkle:0}}]},heelToe:{label:"Heel toe",beats:2,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:26,rightKnee:0,rightAnkle:-35,leftShoulder:30,rightShoulder:-20},taps:["rightHeel"]},{beat:.5,pose:{rightHip:-16,rightKnee:24,rightAnkle:55,leftShoulder:-15,rightShoulder:25},taps:["rightToe"]},{beat:1,reset:!0,pose:{leftHip:-26,leftKnee:0,leftAnkle:-35,rightShoulder:-30,leftShoulder:20},taps:["leftHeel"]},{beat:1.5,pose:{leftHip:16,leftKnee:-24,leftAnkle:55,rightShoulder:15,leftShoulder:-25},taps:["leftToe"]}]},crampRoll:{label:"Cramp roll",beats:2,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:12,rightKnee:26,leftHip:-12,leftKnee:-26}},{beat:.5,pose:{rightAnkle:40,rise:.02},taps:["rightToe"]},{beat:.625,pose:{leftAnkle:40},taps:["leftToe"]},{beat:.75,pose:{rightAnkle:0,rise:0},taps:["rightHeel"]},{beat:.875,pose:{leftAnkle:0},taps:["leftHeel"]},{beat:1,pose:{rightShoulder:135,leftShoulder:125,leftElbow:0,rightElbow:0,leftWrist:0,rightWrist:30,rightKnee:8,leftKnee:-8,rightHip:4,leftHip:-4},hands:{left:{...Tt.spread,turn:2},right:{...Tt.spread,turn:2}}},{beat:1.75,reset:!0}]}},routine:[{move:"shuffleBallChange",beats:8},{move:"timeStep",beats:4},{move:"timeStep",beats:4,mirror:!0},{move:"heelToe",beats:8},{move:"crampRoll",beats:4}]},ln={disco:aM,hipHop:lM,breaking:cM,jazz:hM,kpop:uM,bollywood:dM,bhangra:fM,bharatanatyam:gM,charleston:mM,tap:pM,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:Pi},{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}]}},so={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}},sc=.215,ic=.205,yM=.065,tg=.035,bM=.165,wM=.155,kM=12,vM=.3,MM=.7,SM=.35,TM=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 vt(t={}){return{...lt,...t}}const EM=new Set(["turn","side","head.turn","head.tilt","roll","lookX","hair.swing"]);function eg(t){const e={};for(const[n,s]of Object.entries(t)){const i=n.replace(/(^|\.)(left|right)(\.|$)/,(r,o,a,l)=>`${o}${a==="left"?"right":"left"}${l}`);e[i]=EM.has(n)?-s:s}return e}function $t(t,e){const n={};for(const s of["left","right"])for(const[i,r]of Object.entries(e))n[`${t}.${s}.${i}`]=r;return n}const Ae={rest:lt,wave:vt({"arm.right.spread":115,"arm.right.bend":55,"arm.right.elbow":0,"head.tilt":-6,smile:.9}),cheer:vt({...$t("arm",{spread:140,bend:20,elbow:0}),mouth:.6,smile:1,"eye.left":0,"eye.right":0}),point:vt({"arm.right.spread":88,"arm.right.elbow":0,"arm.right.bend":0,"head.turn":-20,smile:.4}),handsOnHips:vt({...$t("arm",{spread:50,bend:-105,elbow:0}),...$t("leg",{spread:9}),smile:.8}),think:vt({"arm.right.spread":22,"arm.right.bend":-150,"arm.right.elbow":0,"head.tilt":10,lookX:-.5,lookY:-.8,smile:0}),shrug:vt({...$t("arm",{spread:35,bend:75,elbow:0}),"head.tilt":-10,smile:-.2}),sit:vt({...$t("leg",{swing:90,knee:90,spread:4}),...$t("arm",{swing:25,elbow:45,spread:8})}),kneel:vt({"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:vt({...$t("leg",{swing:75,knee:140,spread:6}),lean:25,...$t("arm",{swing:50,elbow:40}),"head.nod":-15}),crawl:vt({lean:82,"head.nod":-35,...$t("arm",{swing:80,elbow:0,spread:4}),...$t("leg",{knee:92,ankle:-88})}),lieDown:vt({roll:90,...$t("arm",{spread:8}),"head.nod":0}),sleep:vt({roll:90,...$t("arm",{spread:8,swing:20,elbow:40}),"leg.left.knee":20,"leg.left.swing":15,blink:1,smile:.2}),stretch:vt({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:vt({...$t("leg",{swing:80,spread:22,rotate:75,knee:145}),...$t("arm",{swing:25,spread:18,elbow:30}),lean:5,smile:.5}),carry:vt({...$t("arm",{spread:16,elbow:4}),lean:-3,smile:.4}),cane:vt({"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:vt({...$t("arm",{swing:28,spread:24,elbow:85,bend:-45}),...$t("leg",{swing:12,knee:22,spread:6}),lean:-4,smile:.2}),push:vt({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:vt({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:vt({"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:vt({"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:vt({...$t("arm",{swing:32,spread:10,elbow:82,bend:-28}),"head.nod":22,lookY:.8,smile:.2}),type:vt({...$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})},ng=["round","flat","pointed","big"],AM={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 rc(t={}){const e=t.headSize??.3,n=t.shoulderWidth??.06,s=t.hipWidth??.022,i=t.legLength??1,r=t.armLength??1,o=AM[t.feet??"round"],a=Math.max(.12,1-e-tg-(sc+ic)*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:bM*r,width:[1.25,.9]},{length:wM*r,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:sc*i,width:[1.45,1.05]},{length:ic*i,width:[1.05,.85]},{length:yM*Math.sqrt(i)*o.length,width:o.width}]}),h=(u,d)=>u[d]??lt[d]??0;return{id:"human",hipHeight:(sc+ic)*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:tg,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,w=-h(u,"bend");return[{swing:v+w*vM,spread:k},{swing:v+w*MM,spread:k}]}if(d.id==="neck")return[{swing:-h(u,"bend")*SM,spread:0}];const[f,m]=d.id.split("."),g=v=>h(u,`${f}.${m}.${v}`);if(f==="arm")return[{swing:g("swing"),spread:g("spread")},{swing:g("elbow"),spread:g("bend")}];const p=(d.side??1)*g("rotate"),b=1-Math.cos(TM(g("rotate")));return[{swing:g("swing"),spread:g("spread"),yaw:p},{swing:-g("knee"),spread:0,yaw:p},{swing:90+g("ankle")-b*(g("swing")-g("knee")),spread:0,yaw:(kM+g("toeOut"))*(d.side??1)}]},withAngles(u,d,f){const[m,g]=d.id.split("."),p=b=>`${m}.${g}.${b}`;return m==="arm"?{...u,[p("swing")]:f[0].swing,[p("spread")]:f[0].spread,[p("elbow")]:f[1].swing,[p("bend")]:f[1].spread}:m==="leg"?{...u,[p("swing")]:f[0].swing,[p("spread")]:f[0].spread,[p("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 xM(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"},r=e.slice(2).join(".");return`${s} · ${i[r]??r.replace(".curl"," curl").replace(".across"," across")}`}if(e.length===3){const[s,i,r]=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"}[r]??r}`}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 PM={leftEye:"eye.left",rightEye:"eye.right",leftBrow:"brow.left",rightBrow:"brow.right"},$M={blush:0,tears:0,sweat:0,pupil:1,lid:0,bulge:0},Fn=Object.fromEntries(Object.entries(Mt).map(([t,e])=>[t,{...Object.fromEntries(Object.entries(e).map(([n,s])=>[PM[n]??n,s])),...$M}]));Fn.crying.tears=1,Fn.scared.sweat=.8,Fn.scared.bulge=.4,Fn.sleepy.lid=.5,Fn.worried.sweat=.6;const pe=t=>({...Fn.neutral,...t}),oc={...Fn,laughing:pe({mouth:.75,smile:1,mouthWidth:1.25,"eye.left":0,"eye.right":0,"brow.left":.5,"brow.right":.5}),afraid:pe({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:pe({smile:-.05,mouthWidth:.6,"eye.left":.45,"eye.right":.45,"brow.left":-.4,"brow.right":-.4,lookX:.5}),tired:pe({mouth:.2,smile:-.3,mouthWidth:.7,"eye.left":.3,"eye.right":.3,"brow.left":-.1,"brow.right":-.1,browTilt:.6,lookY:.6}),embarrassed:pe({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:pe({smile:.75,mouthWidth:1,"eye.left":.75,"eye.right":.75,"brow.left":.5,"brow.right":.5,lookY:-.2}),determined:pe({smile:.35,mouthWidth:.8,"eye.left":.85,"eye.right":.85,"brow.left":-.5,"brow.right":-.5,browTilt:-.9}),affectionate:pe({smile:.85,"eye.left":0,"eye.right":0,"brow.left":.3,"brow.right":.3,blush:.8}),hurt:pe({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:pe({smile:-.25,mouthWidth:.7,"eye.left":.5,"eye.right":.85,"brow.left":-.6,"brow.right":.4,browTilt:-.3,lookX:.8,lid:.3}),relieved:pe({smile:.7,"eye.left":0,"eye.right":0,"brow.left":.4,"brow.right":.4,browTilt:.4}),excited:pe({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})},ye=t=>t*Math.PI/180;function sg([t,e,n],s){const i=Math.cos(s),r=Math.sin(s);return[t,e*i+n*r,-e*r+n*i]}function $i([t,e,n],s){const i=Math.cos(s),r=Math.sin(s);return[t*i-e*r,t*r+e*i,n]}function ee([t,e,n],s){const i=Math.cos(s),r=Math.sin(s);return[t*i+n*r,e,-t*r+n*i]}const Be=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],io=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],ro=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],ac=[[1,0,0],[0,1,0],[0,0,1]],Ii=([t,e,n],s)=>[t*s[0][0]+e*s[1][0]+n*s[2][0],t*s[0][1]+e*s[1][1]+n*s[2][1],t*s[0][2]+e*s[1][2]+n*s[2][2]],ig=(t,e)=>[io(t,e[0]),io(t,e[1]),io(t,e[2])];function IM(t,e,n){const s=Math.hypot(e,n);if(s<1e-12)return t;const i=[-e/s,0,n/s],r=Math.cos(s),o=Math.sin(s),a=[i[1]*t[2]-i[2]*t[1],i[2]*t[0]-i[0]*t[2],i[0]*t[1]-i[1]*t[0]],l=io(i,t)*(1-r);return[t[0]*r+a[0]*o+i[0]*l,t[1]*r+a[1]*o+i[1]*l,t[2]*r+a[2]*o+i[2]*l]}const rg=(t,e,n)=>ac.map(s=>Ii(IM(s,e,n),t));function og(t,e={swing:0,spread:0}){const n=Math.hypot(t[0],t[2]);if(n<1e-12)return t[1]<=0?{swing:0,spread:0}:{swing:Math.PI,spread:0};const s=Math.atan2(n,-t[1]),i={swing:s*t[2]/n,spread:s*t[0]/n},r=s-2*Math.PI,o={swing:r*t[2]/n,spread:r*t[0]/n},a=l=>Math.hypot(l.swing-e.swing,l.spread-e.spread);return a(o)<a(i)-1e-9?o:i}function oo(t,e){const n=ee(t,e);return{point:{x:n[0],y:-n[1]},depth:n[2]}}function ms(t,e,n){const s=n,r=[0,t.hipHeight*s*(t.boneScale?.(e,null)??1),0],o={};for(const g of t.chains){const p=g.parent?o[g.parent]:void 0;if(g.parent&&!p)throw new Error(`body plan ${t.id}: chain ${g.id} comes before its parent ${g.parent}`);const b=g.at??(p?p.joints3.length-1:0),v=p?p.joints3[b]:r,k=p?p.frames[Math.max(0,b-1)]:ac,w=g.offset?Be(v,Ii(ro(g.offset,s),k)):v,S=g.side??1,x=t.boneScale?.(e,g)??1,M=t.angles(e,g),E=[w],T=[];let A=k;g.bones.forEach((P,I)=>{const O=M[I]??{swing:0,spread:0};A=rg(A,ye(O.swing),ye(O.spread)*S),T.push(A);const _=ee(Ii(g.rest,A),ye(O.yaw??0));E.push(Be(E[I],ro(_,P.length*s*x)))}),o[g.id]={joints3:E,frames:T}}const a=o[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=>Ii(ee(sg($i(g,-ye(l.tilt)),-ye(l.nod)),ye(l.yaw)),c),m=Be(a.joints3[a.joints3.length-1],f([0,d,0]));return{height:s,root:r,chains:o,head:{center:m,rx:u,ry:d,toBody:f}}}function lc(t,e,n){const s=n.height,i=ye(90*(e.turn??0)),r=ms(t,e,s),{root:o}=r,a=r.chains,{rx:l,ry:c}=r.head,h=r.head.toBody,u=r.head.center,d={};for(const T of t.chains){const{joints3:A,frames:P}=a[T.id],I=A.map(O=>oo(O,i));d[T.id]={id:T.id,joints3:A,frames:P,points:I.map(O=>O.point),depths:I.map(O=>O.depth)}}const f=oo(u,i),m=[[1,0,0],[0,1,0],[0,0,1]].map(T=>ee(h(T),i)),g=oo(o,i).point,p=ye(e.roll??0),b=T=>{const A=T.x-g.x,P=T.y-g.y;return{x:g.x+A*Math.cos(p)-P*Math.sin(p),y:g.y+A*Math.sin(p)+P*Math.cos(p)}},v=([T,A,P])=>[T*Math.cos(p)+A*Math.sin(p),-T*Math.sin(p)+A*Math.cos(p),P];for(const T of Object.values(d))T.points=T.points.map(b);const k={center:b(f.point),depth:f.depth,rx:l,ry:c,angle:0,axes:m.map(v)},w=k.axes[1];k.angle=Math.atan2(w[0],w[1]);const S=T=>{if("head"in T)return{x:k.center.x+w[0]*c,y:k.center.y-w[1]*c};const A=d[T.chain];return A.points[Math.min(T.joint,A.points.length-1)]};let x=0;(n.contact??"ground")==="ground"&&(x=-Math.max(...t.contacts.map(T=>S(T).y))),x-=(e.lift??0)*s;const M=T=>({x:T.x,y:T.y+x});for(const T of Object.values(d))T.points=T.points.map(M);k.center=M(k.center);const E=t.contacts.map(T=>({spec:T,point:S(T)}));return{height:s,view:i,chains:d,head:k,hip:M(b(g)),hipDepth:oo(o,i).depth,contacts:E,groundY:Math.max(...E.map(T=>T.point.y))}}const ao=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],cc=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function cn(t,e,n){const s=n.height,i=ye(90*(e.turn??0)),r=ye(e.roll??0),o=ms(t,e,s),a=ee(o.root,i),l=p=>Be($i(ao(ee(p,i),a),-r),a),c={};for(const p of t.chains)c[p.id]=o.chains[p.id].joints3.map(l);const h=l(o.head.center),u=p=>cc(ao(l(Be(o.head.center,o.head.toBody(p))),h)),d=[u([1,0,0]),u([0,1,0]),u([0,0,1])],f=p=>{if("head"in p)return Be(h,ro(d[1],o.head.ry));const b=c[p.chain];return b[Math.min(p.joint,b.length-1)]};let m=0;(n.contact??"ground")==="ground"&&(m=-Math.min(...t.contacts.map(p=>f(p)[1]))),m+=(e.lift??0)*s;const g=p=>[p[0],p[1]+m,p[2]];return{height:s,hip:g(a),chains:Object.fromEntries(Object.entries(c).map(([p,b])=>[p,b.map(g)])),head:{center:g(h),rx:o.head.rx,ry:o.head.ry,axes:d}}}function lo(t,e,n,s){const i=n.height,r=ye(90*(e.turn??0)),o=ms(t,e,i),a=cn(t,e,n),l=a.hip,c=a.chains,h=a.head.center,u=P=>{if("head"in P)return Be(h,ro(a.head.axes[1],a.head.ry));const I=c[P.chain];return I[Math.min(P.joint,I.length-1)]},d=s.toView(l),f=$i(ee([0,0,1],r),-ye(e.roll??0)),m=cc(ao(s.toView(Be(l,f)),d)),g=s.toScreen(d),p=s.toScreen([d[0]+1,d[1],d[2]]),b=Math.hypot(p.x-g.x,p.y-g.y),v=P=>{const I=s.toView(P);return{point:s.toScreen(I),depth:I[2]*b}},k={};for(const P of t.chains){const I=c[P.id].map(v);k[P.id]={id:P.id,joints3:o.chains[P.id].joints3,frames:o.chains[P.id].frames,points:I.map(O=>O.point),depths:I.map(O=>O.depth)}}const w=s.toView(h),S=s.toScreen(w),x=s.toScreen([w[0]+1,w[1],w[2]]),M=Math.hypot(x.x-S.x,x.y-S.y),E=a.head.axes.map(P=>cc(ao(s.toView(Be(h,P)),w))),T={center:S,depth:w[2]*b,rx:o.head.rx*M,ry:o.head.ry*M,angle:Math.atan2(E[1][0],E[1][1]),axes:E},A=t.contacts.map(P=>({spec:P,point:v(u(P)).point}));return{height:i*b,view:r,bodyForward:m,chains:k,head:T,hip:g,hipDepth:d[2]*b,contacts:A,groundY:Math.max(...A.map(P=>P.point.y))}}function hn(t,[e,n,s]){const[i,r,o]=t.axes,a=[i[0]*e*t.rx+r[0]*n*t.ry+o[0]*s*t.rx,i[1]*e*t.rx+r[1]*n*t.ry+o[1]*s*t.rx,i[2]*e*t.rx+r[2]*n*t.ry+o[2]*s*t.rx],l=Math.hypot(e,n,s)||1,c=(i[2]*e+r[2]*n+o[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 co=t=>t*180/Math.PI,ag=t=>t*Math.PI/180,Ln=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],hc=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],OM=(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]],ps=t=>Math.hypot(t[0],t[1],t[2]),lg=t=>{const e=ps(t)||1;return[t[0]/e,t[1]/e,t[2]/e]};function Oi(t,e,n,s,i){const r=t.chains.find(L=>L.id===n);if(!r)throw new Error(`reach: no chain ${n} in ${t.id}`);if(r.bones.length<2||r.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 o=lc(t,{...e,turn:0,roll:0,lift:0},{height:i.height,contact:"none"}),a=o.chains[n];if(ps(Ln(s,a.joints3[2]))<i.height*1e-12)return e;const l=a.joints3[0],c=ps(Ln(a.joints3[1],a.joints3[0])),h=ps(Ln(a.joints3[2],a.joints3[1])),u=r.parent?o.chains[r.parent].frames[Math.max(0,(r.at??o.chains[r.parent].joints3.length-1)-1)]:ac,d=Ln(s,l),f=t.angles(e,r),m=L=>(f[L]?.yaw??0)*Math.PI/180,g=Math.min(c+h-1e-6,Math.max(Math.abs(c-h)+1e-6,ps(d))),p=lg(d),b=r.parent!==null,v=ee(Ii(r.pole??(b?[0,-.35,-1]:[0,0,1]),u),m(0));let k=Ln(v,[p[0]*hc(v,p),p[1]*hc(v,p),p[2]*hc(v,p)]);ps(k)<1e-6&&(k=ee([1,0,0],m(0))),k=lg(k);const w=(c*c+g*g-h*h)/(2*c*g),S=Math.sqrt(Math.max(0,1-w*w)),x=[l[0]+p[0]*g,l[1]+p[1]*g,l[2]+p[2]*g],M=r.side??1,E=L=>({swing:ag(f[L]?.swing??0),spread:ag(f[L]?.spread??0)*M}),T=L=>{const j=OM(p,k),V=[k[0]*Math.cos(L)+j[0]*Math.sin(L),k[1]*Math.cos(L)+j[1]*Math.sin(L),k[2]*Math.cos(L)+j[2]*Math.sin(L)],tt=[l[0]+c*(w*p[0]+S*V[0]),l[1]+c*(w*p[1]+S*V[1]),l[2]+c*(w*p[2]+S*V[2])],J=og(ig(ee(Ln(tt,l),-m(0)),u),E(0)),F=rg(u,J.swing,J.spread),B=og(ig(ee(Ln(x,tt),-m(1)),F),E(1));return{upper:J,lower:B}};let A=0,P=T(A);if(!b){let L={swivel:.05,miss:T(.05).lower.spread};for(let j=0;j<40&&Math.abs(P.lower.spread)>1e-14;j++){const V=(P.lower.spread-L.miss)/(A-L.swivel);if(!Number.isFinite(V)||Math.abs(V)<1e-15)break;L={swivel:A,miss:P.lower.spread},A-=P.lower.spread/V,P=T(A)}}const{upper:I,lower:O}=P,_=[{swing:co(I.swing),spread:co(I.spread)*M},{swing:co(O.swing),spread:co(O.spread)*M}];return t.withAngles(e,r,_)}const ys=(t,e)=>(t%e+e)%e,cg=t=>t*t*(3-2*t),CM=t=>Object.fromEntries(["left","right"].flatMap(e=>Object.entries(Tt[t]).map(([n,s])=>[`hand.${e}.${n}`,s])));function uc(t,e=!1){const n=rc(),s=Oi(n,lt,"arm.left",[.015,.68,.2],{height:1}),i=Oi(n,s,"arm.right",[-.015,.68,.2],{height:1});return Array.from({length:32},(r,o)=>{const a=o/4,l=Math.floor(a),c=a-l,h=l%2===0,u=Math.sin(Math.PI*c),d=Math.max(0,...t.map(m=>1-Math.min(ys(a-m,8),ys(m-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,...CM(e?"hold":"spread")};if(!e)for(const m of Object.keys(i))m.startsWith("arm.")&&(f[m]+=(i[m]-f[m])*d);return{beat:a,pose:f}})}const Nn={garba:{label:"Garba · two clap",bpm:120,beats:8,strikes:[2,3,6,7],keys:uc([2,3,6,7])},garbaThreeClap:{label:"Garba · three clap",bpm:120,beats:8,strikes:[1,2,3,5,6,7],keys:uc([1,2,3,5,6,7])},dandiya:{label:"Dandiya · partner strikes",bpm:120,beats:8,strikes:[1,3,5,7],keys:uc([1,3,5,7],!0)}};function hg(t){const e=typeof t=="string"&&Object.hasOwn(Nn,t)?Nn[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 Ci(t,e,n=lt){const s=hg(t);if(!Number.isFinite(e))throw new Error("humanDanceFrame: beat must be finite");const i=ys(e,s.beats);let r=s.keys.length-1;for(let p=0;p<s.keys.length;p++)s.keys[p].beat<=i&&(r=p);const o=s.keys[r],a=s.keys[(r+1)%s.keys.length],l=o.beat>i?o.beat-s.beats:o.beat,c=a.beat<=o.beat?a.beat+s.beats:a.beat,h=cg((i-l)/(c-o.beat)),u={...lt,...n};for(const p of new Set(s.keys.flatMap(b=>Object.keys(b.pose)))){if(p==="turn"||p==="roll")continue;const b=p.match(/^hand\.(?:left|right)\.(.+)$/)?.[1],v=n[p]??lt[p]??(b?Ct[b]:void 0)??0,k=o.pose[p]??v;u[p]=k+((a.pose[p]??v)-k)*h}const d=Math.floor(e),f=e-d,m=f<=.6?1:1-cg((f-.6)/.4),g=Math.max(0,...s.strikes.map(p=>1-Math.min(ys(i-p,s.beats),ys(p-i,s.beats))/.25));return{pose:u,contact:{side:ys(d,2)===0?"left":"right",start:d,weight:m},strike:g}}function _M(t,e){const n=hg(e.style),s=e.bpm??n.bpm,i=e.beats??n.beats,r=e.samplesPerBeat??16;if(![s,i,r].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 o=Math.max(1,Math.ceil(i*r)),a=Array.from({length:o+1},(l,c)=>({time:(e.start??0)+i*c/o*6e4/s,pose:Ci(n,i*c/o,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"}))}))}const ho={hourglass:{height:165,bust:94,underbust:76,waist:70,hip:98},pear:{height:165,bust:86,underbust:74,waist:72,hip:102},rectangle:{height:165,bust:86,underbust:76,waist:76,hip:89},invertedTriangle:{height:165,bust:98,underbust:86,waist:78,hip:90},round:{height:165,bust:104,underbust:92,waist:98,hip:104}},ug=.72,dg=.72,dc=.68,RM=.33,fc=.2,fg=1.04,gc=.024,gg=.54,_i=.66,mg=.86,uo=.18,HM=.6,FM=.02;function pg(t,e,n){const s=Math.round((e-t)/FM);return Array.from({length:s+1},(i,r)=>{const o=t+(e-t)*r/s;return{at:o,width:n(o)}})}function LM(t){if(t<=_i){const e=(_i-t)/(_i-gg);return Math.sqrt(Math.max(0,1-e*e))}return(1-(t-_i)/(mg-_i))**1.6}function NM(t,e,n,s){if(t<=uo)return e+(n-e)*Math.sin(t/uo*Math.PI/2);const i=(t-uo)/(.4-uo);return n+(s-n)*(1-Math.cos(i*Math.PI))/2}function fo(t,e){return t/(Math.PI*Math.sqrt(2*(1+e*e)))}function mc(t){if(typeof t=="string"){if(!Object.prototype.hasOwnProperty.call(ho,t))throw new Error(`body shape: unknown shape '${t}'`);t=ho[t]}const{height:e,bust:n,waist:s,hip:i}=t,r=t.underbust??n*.86;for(const[o,a]of Object.entries({height:e,bust:n,underbust:r,waist:s,hip:i}))if(!Number.isFinite(a)||a<=0)throw new Error(`body shape: ${o} must be a positive number`);if(r>n)throw new Error("body shape: underbust cannot be larger than bust");for(const[o,a]of Object.entries({bust:n,waist:s,hip:i}))if(a/e<.25||a/e>1)throw new Error(`body shape: ${o} must be 0.25..1 of the height`);return{height:e,bust:n,underbust:r,waist:s,hip:i}}function yg(t,e){const n=mc(t),s=d=>d/n.height,i=fo(s(n.hip),dc),r=fo(s(n.waist),dg),o=fo(s(n.underbust),ug),a=i*dc,l=r*dg,c=o*ug,h=s(n.bust-n.underbust)*RM,u=Math.min(.25,Math.max(0,n.waist/n.hip-.8));return{torso:[{at:0,width:i},{at:.2,width:i*.97},{at:.42,width:r},{at:.6,width:o},{at:.72,width:Math.min(e,o*fg)},{at:.86,width:Math.max(e,o*fg)},{at:1,width:gc}],torsoFront:[{at:0,width:a*(1-fc)*.8},{at:.14,width:a*(1-fc)},{at:.42,width:l*(1.05+u)},...pg(gg,mg,d=>c+h*LM(d)),{at:.92,width:c*.9},{at:1,width:gc}],torsoBack:[...pg(0,.4,d=>NM(d,a*HM,a*(1+fc),l*.95)),{at:.6,width:c},{at:.8,width:c*1.02},{at:.9,width:c*.9},{at:1,width:gc}],hipHalfWidth:i}}function bg(t){return t*.4}function wg(t){const e=mc(t),n=fo(e.hip/e.height,dc);return Math.max(.02,n-Math.max(.042,bg(n)))}function bs(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 ws(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(bs(n.at,`${e}.at`,0,1),bs(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 kg(t,e){const n=Math.max(.095,e.shoulderWidth+.025),s=Math.max(.085,e.hipWidth+.032),i=t.shading??{},r=i.light??[-.8,-.6];if(r.length!==2||!r.every(Number.isFinite)||Math.hypot(...r)===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");const o=t.measurements!==void 0?yg(t.measurements,n):void 0,a=ws(t.torso??o?.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"),l=bs(t.depth??.55,"depth",.2,1),c=u=>u.map(d=>({at:d.at,width:Math.max(.001,d.width*l)})),h=o?Math.max(1,bg(o.hipHalfWidth)/.042):1;return{torso:a,torsoFront:ws(t.torsoFront??o?.torsoFront??c(a),"torsoFront"),torsoBack:ws(t.torsoBack??o?.torsoBack??c(a),"torsoBack"),arm:ws(t.arm??[{at:0,width:.028},{at:.22,width:.027},{at:.5,width:.019},{at:.68,width:.023},{at:1,width:.012}],"arm"),leg:ws(t.leg??[{at:0,width:.04*h},{at:.24,width:.042*h},{at:.5,width:.027},{at:.68,width:.032},{at:1,width:.016}],"leg"),neck:ws(t.neck??[{at:0,width:.024},{at:1,width:.023}],"neck"),depth:l,fill:t.fill??e.skin,outline:{color:t.outline?.color??e.ink,width:bs(t.outline?.width??e.lineWidth,"outline.width",0,100)},shading:{mode:i.mode??"cel",light:[...r],shadow:i.shadow??"#633923",opacity:bs(i.opacity??.17,"shading.opacity",0,1),highlight:bs(i.highlight??.12,"shading.highlight",0,1)}}}function Ri(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],r=t[s],o=(n-i.at)/(r.at-i.at);return i.width+(r.width-i.width)*o*o*(3-2*o)}const vg=8,WM=(t,e,n)=>({x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n}),Wn=(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}},Hi=(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,r)=>{const o=Wn(t[Math.max(0,r-1)],i),a=Wn(i,t[Math.min(t.length-1,r+1)]),l=Math.hypot(o.x+a.x,o.y+a.y);return l>1e-6?{x:(o.x+a.x)/l,y:(o.y+a.y)/l}:a}),s=[];for(let i=0;i<t.length-1;i++){const r=t[i],o=t[i+1],a=Math.hypot(o.x-r.x,o.y-r.y)*.28,l=Hi(r,n[i],a),c=Hi(o,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*r.x+3*d*d*u*l.x+3*d*u*u*c.x+u**3*o.x,y:d**3*r.y+3*d*d*u*l.y+3*d*u*u*c.y+u**3*o.y})}}return s}const pc=(t,e)=>n=>{const s=Ri(t,n)*e;return{left:s,right:s}};function go(t,e,n=1){const s=t.map((l,c)=>{const h=t[Math.max(0,c-1)],u=t[Math.min(t.length-1,c+1)];let d=Wn(h,u);Math.hypot(d.x,d.y)<1e-6&&(d={x:0,y:1});const f={x:-d.y,y:d.x},m=c/Math.max(1,t.length-1),{left:g,right:p}=e(m),b=Wn(h,l),v=Wn(l,u),k=b.x*v.y-b.y*v.x,w=Math.acos(Math.min(1,Math.max(-1,b.x*v.x+b.y*v.y))),S=(Math.hypot(l.x-h.x,l.y-h.y)+Math.hypot(u.x-l.x,u.y-l.y))/(2*Math.max(1e-6,w)),x=M=>Math.min(M,Math.max(M*.2,S*.8));return{center:l,width:(g+p)/2,at:m,left:Hi(l,f,k>0?x(g):g),right:Hi(l,f,k<0?-x(p):-p)}}),i=[],r=[],o=(l,c)=>{i.push(l),r.push(c)};for(const l of s)o(l.left,l.at);const a=(l,c,h)=>{const u={x:-c.y,y:c.x},{left:d,right:f}=e(l.at),m=Hi(l.center,u,(d-f)/2),g=(d+f)/2;for(let p=1;p<vg;p++){const b=p*Math.PI/vg,v=(h?1:-1)*Math.cos(b),k=(h?1:-n)*Math.sin(b);o({x:m.x+g*(u.x*v+c.x*k),y:m.y+g*(u.y*v+c.y*k)},l.at)}};a(s.at(-1),Wn(t[Math.max(0,t.length-2)],t.at(-1)),!0);for(const l of[...s].reverse())o(l.right,l.at);return a(s[0],Wn(t[0],t[Math.min(1,t.length-1)]),!1),{outline:i,samples:s,positions:r}}function DM(t,e,n,s){const i=Math.sqrt(Math.max(0,1-n*n));return r=>{const o=Ri(t.torso,r)*e*n,a=Math.hypot(o,Ri(t.torsoFront,r)*e*i),l=Math.hypot(o,Ri(t.torsoBack,r)*e*i);return s?{left:a,right:l}:{left:l,right:a}}}function Mg(t,e,n){const s={},i=e.height,r=e.chains.spine;if(r?.length>=2){const o=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=o&&a?Math.min(1,Math.hypot(o.x-a.x,o.y-a.y)/c):Math.abs(Math.cos(e.turn*Math.PI/2)),u=Math.sin(e.turn*Math.PI/2)>=0,d=[WM(r[0],r[1],-.16),...r.slice(1)];s.spine=go(Fi(d),DM(t,i,h,u),.25)}e.chains.neck?.length>=2&&(s.neck=go(Fi(e.chains.neck),pc(t.neck,i)));for(const o of["left","right"])for(const a of["arm","leg"]){const l=e.chains[`${a}.${o}`];!l||l.length<3||(s[`${a}.${o}`]=go(Fi(l.slice(0,3)),pc(t[a],i)),a==="leg"&&l.length>3&&(s[`foot.${o}`]=go(Fi(l.slice(2)),pc([{at:0,width:.019},{at:1,width:.014}],i))))}return s}function Sg(t,e){let n=!1;for(let s=0,i=e.length-1;s<e.length;i=s++){const r=e[s],o=e[i];r.y>t.y!=o.y>t.y&&t.x<(o.x-r.x)*(t.y-r.y)/(o.y-r.y)+r.x&&(n=!n)}return n}function yc(t,e,n,s=0){const i=t.samples.filter(a=>a.at>=e&&a.at<=n),r=(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}},o=[...i.map(a=>r(a,"left")),...[...i].reverse().map(a=>r(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;o.push({x:l.x+(l.x-a.x)*s/c,y:l.y+(l.y-a.y)*s/c})}}return o}function Tg(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 BM(t,e,n){const s=n.shading;if(s.mode==="none"||n.fill==="none")return;const i=Math.hypot(...s.light),r={x:s.light[0]/i,y:s.light[1]/i},o=t.globalAlpha;t.save(),Tg(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,m=u.y-d.y,g=(f*r.x+m*r.y)/(Math.hypot(f,m)||1),p=Math.max(0,-g)*.44;return{x:u.x+(d.x-u.x)*p,y:u.y+(d.y-u.y)*p}});if(Tg(t,[...l,...c.reverse()]),t.fillStyle=s.shadow,t.globalAlpha=o*s.opacity,t.fill(),s.highlight>0){const h=e.samples.map(f=>{const m=f[a],g=f.center;return{x:m.x+(g.x-m.x)*.2,y:m.y+(g.y-m.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)*r.x+(u.y-d.y)*r.y>0){t.globalAlpha=o*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 zM(t,e,n,s){const i=s.bodyContours,r=o=>i[o]&&Sg(t,i[o].outline);if(n.startsWith("arm."))return e<.2&&r("spine");if(n.startsWith("leg."))return e<.2&&r("spine")||e>.85&&r(n.replace("leg.","foot."));if(n.startsWith("foot."))return e<.25&&r(n.replace("foot.","leg."));if(n==="neck")return e<.6&&r("spine");if(n==="spine"){if(e>.85&&r("neck"))return!0;for(const o of["left","right"]){if(e>.6&&r(`arm.${o}`)){const a=s.chains[`arm.${o}`]?.[0];if(a&&Math.hypot(a.x-t.x,a.y-t.y)<s.height*.07)return!0}if(e<.25&&r(`leg.${o}`))return!0}}return!1}function qM(t){let e=0;return t.forEach((n,s)=>{const i=t[(s+1)%t.length];e+=n.x*i.y-i.x*n.y}),e>0?-1:1}function Eg(t,e,n,s,i){const r=s.bodyContours?.[i];if(!r)return!1;if(n.fill==="none"&&(e=vi(t,e)),e.shape(r.outline,n.fill==="none"?null:n.fill,0),e.look==="clean"&&BM(t,r,n),(e.look!=="silhouette"||n.fill==="none")&&s.lineWidth>0){const o=qM(r.outline);let a=[];for(let l=0;l<=r.outline.length;l++){const c=l%r.outline.length,h=r.outline[c],u=r.outline[(c+1)%r.outline.length],d={x:(h.x+u.x)/2,y:(h.y+u.y)/2};i.startsWith("arm.")&&r.positions[c]===1||zM(d,r.positions[c],i,s)?(a.length>=2&&e.line(a,s.lineWidth,o),a=[]):(a.length===0&&a.push(h),a.push(u))}a.length>=2&&e.line(a,s.lineWidth,o)}return!0}function Ag(t){return[[.01,-.12,.8],[0,-.25,.98],[-.04,-.31,.8]].map(e=>hn(t,e).point)}function xg(t,e){const n=e.shape==="angular"?jM(t,e):e.projection==="volume"?KM(t):wi(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),r=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}),o=r(Ag(t)[1]),a=Math.sign(o.x),l=o.y,c=n.flatMap((u,d)=>{const f=r(u),m=r(n[(d+1)%n.length]);if(f.y>l==m.y>l)return[];const g=(l-f.y)/(m.y-f.y);return[(f.x+(m.x-f.x)*g)*a]}),h=Math.max(0,o.x*a-Math.max(...c));return!Number.isFinite(h)||h===0?n:n.flatMap((u,d)=>{const f=n[(d+1)%n.length],m=r(u),g=r(f),p=Math.max(1,Math.ceil(Math.hypot(g.x-m.x,g.y-m.y)/.025));return Array.from({length:p},(b,v)=>{const k=v/p,w={x:u.x+(f.x-u.x)*k,y:u.y+(f.y-u.y)*k},S=r(w),x=(S.y-l+.115)/.23;if(S.x*a<.5||x<=0||x>=1)return w;const M=Math.sin(x*Math.PI)**2*h*t.rx*a;return{x:w.x+M*s,y:w.y+M*i}})})}function jM(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 r=0;r<=12;r++){const o=r*Math.PI/24;i.push([Math.sin(o),Math.cos(o)])}return Pg(t,i,e.jawRoundness??0,e.projection==="volume")}function KM(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 Pg(t,e,0,!0)}function Pg(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(hn(t,[l*Math.cos(h),a,s?Math.min(u,.82):u]).point)}let r=bc(i);if(n=Math.min(1,Math.max(0,n)),n===0)return r;const o=n*.25;for(let a=0;a<3;a++)r=r.flatMap((l,c)=>{const h=r[(c+1)%r.length];return[{x:l.x+(h.x-l.x)*o,y:l.y+(h.y-l.y)*o},{x:h.x+(l.x-h.x)*o,y:h.y+(l.y-h.y)*o}]});return r}function bc(t){const e=t.sort((i,r)=>i.x-r.x||i.y-r.y),n=(i,r,o)=>(r.x-i.x)*(o.y-i.y)-(r.y-i.y)*(o.x-i.x),s=i=>{const r=[];for(const o of i){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],o)<=0;)r.pop();r.push(o)}return r.slice(0,-1)};return[...s(e),...s([...e].reverse())]}const $g=.34,Ut=.12,Kt=-.4,Et=(t,e,n)=>t[e]??n,Ig=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),YM=.45,XM=.35,GM=.7,Og=.78;function kt(t,e,n,s="cartoon"){const i=f=>Math.sqrt(Math.max(0,1-f.x*f.x-f.y*f.y));let r=hn(t,[n.x,n.y,i(n)]).facing;const o=t.axes[2];s==="volume"&&n.x*o[0]>0&&(r=Math.max(r,o[2]));const a=Math.atan2(o[0],o[2]),l=Math.cos(a),c=Math.max(XM,l),h=Math.max(GM,l),u=Math.cos(t.angle),d=Math.sin(t.angle);if(s==="volume"){const f=hn(t,[n.x,n.y,i(n)*Og]).point,m=Math.abs(n.x)>.1?Math.min(1,Math.max(0,r)/.25):1,g=Math.max(n.x*o[0]>0?.2:.5,l);return{facing:r,points:e.map(p=>{const b=(p.x-n.x)*g*t.rx*m,v=(p.y-n.y+o[1]*(i(p)-i(n))*Og)*t.ry*m;return{x:f.x+b*u+v*d,y:f.y+b*d-v*u}})}}return{facing:r,points:e.map(f=>{const m=YM*Math.sin(a)+n.x*c+(f.x-n.x)*h,g=f.y+o[1]*i(f),p=m*t.rx,b=g*t.ry;return{x:t.center.x+p*u+b*d,y:t.center.y+p*d-b*u}})}}const ue=(t,e,n,s=12)=>Array.from({length:s+1},(i,r)=>{const o=r/s,a=1-o;return{x:a*a*t.x+2*a*o*e.x+o*o*n.x,y:a*a*t.y+2*a*o*e.y+o*o*n.y}}),Li=(t,e,n,s)=>{const i=Math.min(1,Math.max(0,(s-t.x)/(n.x-t.x))),r=1-i;return r*r*t.y+2*r*i*e.y+i*i*n.y},de=(t,e,n,s,i=16)=>Array.from({length:i},(r,o)=>{const a=Math.PI*2*o/i;return{x:t+Math.cos(a)*n,y:e+Math.sin(a)*s}}),Re=.05,UM=.3,VM="#e06b7d";function JM(t,e,n,s,i={},r){const o=Math.max(1,Math.min(s*.6,.14*e.rx)),a=(O,_)=>kt(e,O,_,i.projection).points,l=(O,_)=>kt(e,[],{x:O,y:_},i.projection).facing,c=Et(n,"smile",0),h=Et(n,"blink",0),u=Et(n,"lookX",0),d=Et(n,"lookY",0),f=Et(n,"browTilt",0),m=Math.max(.2,Et(n,"pupil",1)),g=Math.min(1,Math.max(0,Et(n,"lid",0))),p=Math.min(1,Math.max(0,Et(n,"bulge",0))),b=t.look==="illustrated";b&&r&&sS(r,e,i.projection);for(const O of[1,-1]){const _=O===1?"left":"right";if(i.style==="oval"){l(be.x*O,be.y)>=Re&&eS(t,e,O,n,i);continue}const L=$g*O;if(l(L,Ut)<Re)continue;const j={x:L,y:Ut},V=Ig(Et(n,`eye.${_}`,1),h);if(V<.2||i.style==="anime"&&g>=.98){const Y=c>.5?.12:-.06;t.line(a(ue({x:L-.12,y:Ut},{x:L,y:Ut+Y},{x:L+.12,y:Ut}),j),o)}else if(i.style==="anime")ZM(t,e,j,O,V,g,p,m,u,d,o,i,r);else{const Y=V>1.2||p>.02,R=.13*Math.max(V,1)*(1+p*.7);Y&&t.shape(a(de(L,Ut,R*.85,R),j),"#ffffff",o,!0);const K=(V>1.2?.075:.1)*m*(1+p*.3),st=L+u*.08,$=Ut-d*.07,C=de(st,$,K,K*1.1*Math.min(V,1));if(t.shape(a(C,j),t.ink,0,!0),i.inPupil&&r){const[z]=a([{x:st,y:$}],j),X=a(C,j),W=Math.min(...X.map(N=>Math.hypot(N.x-z.x,N.y-z.y)));W>.5&&(r.save(),r.beginPath(),r.arc(z.x,z.y,W,0,Math.PI*2),r.clip(),i.inPupil(r,{x:z.x,y:z.y,r:W,side:_}),r.restore())}if(g>.02){const z=Y?R*1.15:K*1.4,X=Ut+z,W=X-z*2*g,N=z*1.1;t.shape(a([{x:L-N,y:X+.02},{x:L+N,y:X+.02},{x:L+N,y:W},{x:L-N,y:W}],j),i.skin??"#ffffff",0,!0),t.line(a([{x:L-N,y:W},{x:L+N,y:W}],j),o)}}const tt=Ut+(i.style==="anime"?.38:.3)+Et(n,`brow.${_}`,0)*.14+Math.max(0,V-1)*.12,J={x:L+O*.13,y:tt},F={x:L-O*.13,y:tt+f*.1},B=b?.035:0;t.line(a([J,{x:(J.x+F.x)/2,y:(J.y+F.y)/2+B},F],{x:L,y:tt}),o*(b?2.2:1))}i.style==="oval"&&i.shades&&tS(t,e,i),rS(t,e,n,o,i.projection),iS(t,e,i.ageLines??0,o,i.projection);const v={x:0,y:Kt};if(l(0,Kt)<-Re)return;i.nose&&l(0,Ut-.15)>=Re&&(i.projection==="volume"?t.line(Ag(e),o):t.line(a([{x:.01,y:Ut-.1},{x:.03,y:Kt+.2},{x:-.05,y:Kt+.17}],{x:0,y:Kt+.22}),o));const k=.25*Math.max(.3,Et(n,"mouthWidth",1)),w=Math.min(1,Math.max(0,Et(n,"mouth",0)));if(w<=.05){b&&nS(t,k,c,a),t.line(a(ue({x:-k,y:Kt},{x:0,y:Kt-c*.25},{x:k,y:Kt}),v),o);return}const S=.3*w;let x,M,E,T;if(c>.3){const O=Kt+.05,_={x:0,y:Kt-S*2};x=[...ue({x:k,y:O},_,{x:-k,y:O})],M=()=>O,E=L=>Li({x:k,y:O},_,{x:-k,y:O},L),T=.85}else if(c<-.3){const O=Kt-S*.6,_={x:0,y:Kt+S*1.4};x=[...ue({x:k,y:O},_,{x:-k,y:O})],M=L=>Li({x:k,y:O},_,{x:-k,y:O},L),E=()=>O,T=.5}else{const O=k*.8;x=de(0,Kt,O,S);const _=L=>S*Math.sqrt(Math.max(0,1-(L/O)**2));M=L=>Kt+_(L),E=L=>Kt-_(L),T=.5}if(t.shape(a(x,v),t.ink,0,!0),w<UM)return;const A=M(0)-E(0),P=k*T,I=(O,_,L=8)=>Array.from({length:L+1},(j,V)=>O+(_-O)*V/L);if(i.tongue){const O=P*.55,_=I(O,-O).map(j=>({x:j,y:E(j)})),L=ue({x:-O,y:E(-O)},{x:0,y:E(0)+A*.8},{x:O,y:E(O)},8);t.shape(a([..._,...L.slice(1,-1)],v),VM,0,!0)}if(i.teeth){const O=Math.min(.06,A*.4),_=I(-P,P).map(j=>({x:j,y:M(j)})),L=_.map(({x:j,y:V})=>({x:j*.92,y:V-O})).reverse();t.shape(a([..._,...L],v),"#ffffff",0,!0);for(const j of[-.5,0,.5]){const V=P*j;t.line(a([{x:V,y:M(V)},{x:V*.92,y:M(V)-O}],v),o*.6)}}}function ZM(t,e,n,s,i,r,o,a,l,c,h,u,d){const{x:f,y:m}=n,g=Math.min(1.2,Math.max(.5,u.eyeScale??1)),p=Math.min(1.2,Math.max(.45,u.eyeAspect??1)),b=.21*g*(1+o*.15),v=.25*g*p*Math.min(i,1.6)*(1-r)*(1+o*.3),k={x:f-b,y:m},w={x:f+b,y:m},S={x:f,y:m+v*1.9},x={x:f,y:m-v*1.35},M=ue(k,S,w),E=ue(w,x,k),T=J=>kt(e,J,n,u.projection).points,A=J=>J.map(F=>{const B=Math.min(w.x,Math.max(k.x,F.x));return{x:B,y:Math.min(Li(k,S,w,B),Math.max(Li(w,x,k,B),F.y))}});t.shape(T([...M,...E.slice(1,-1)]),"#ffffff",h*.5,!0);const P=f+Math.max(-1,Math.min(1,l))*.07*g,I=m-Math.max(-1,Math.min(1,c))*.055*g,O=.115*g,_=.185*g;t.shape(T(A(de(P,I,O,_,24))),u.iris??"#4b7fce",h*.4,!0),t.shape(T(A(de(P,I-.075*g,O*.7,_*.35))),"rgba(255,255,255,0.25)",0,!0);const L=t.look==="illustrated",j=L?Nl(u.iris??"#4b7fce")?.highlight:void 0;j&&t.shape(T(A(de(P,I-_*.5,O*.7,_*.32))),j,0,!0);const V=Math.min(.085,.042*a)*g,tt=A(de(P,I,V,V*1.35));if(t.shape(T(tt),t.ink,0,!0),u.inPupil&&d){const[J]=T([{x:P,y:I}]),F=Math.min(...T(tt).map(B=>Math.hypot(B.x-J.x,B.y-J.y)));F>.5&&(d.save(),d.beginPath(),d.arc(J.x,J.y,F,0,Math.PI*2),d.clip(),u.inPupil(d,{...J,r:F,side:s===1?"left":"right"}),d.restore())}if(t.shape(T(A(de(P-.038*g,I+.075*g,.035*g,.045*g))),"#ffffff",0,!0),t.shape(T(A(de(P+.04*g,I-.04*g,.014*g,.02*g))),"#ffffff",0,!0),L){const J=ue(k,{x:f,y:m+v*1.2},w);t.shape(T([...M,...J.slice(1,-1).reverse()]),"rgba(70, 35, 30, 0.22)",0,!0);const F=ue({x:f-b*.7,y:m+v*.55+.03},{x:f,y:m+v*1.4+.09},{x:f+b*.85,y:m+v*.5+.03});t.line(T(F),h*.45);const B=E.filter(Y=>s*(Y.x-f)>b*.25);B.length>=2&&t.line(T(B),h*.55)}if(t.line(T(M),h*(L?1.9:1.1)),u.lashes!==!1)for(const J of[0,.035]){const F=f+s*(b-J),B=Li(k,S,w,F);t.line(T([{x:F,y:B},{x:F+s*.055,y:B+.07}]),h*.75)}}const be={x:.31,y:.12,rx:.29,ry:.44},wc={rx:.37,ry:.33},Cg=(t,e,n,s,i=10)=>Array.from({length:i},(r,o)=>{const a=(o+1)/i,l=1-a;return{x:l*l*l*t.x+3*l*l*a*e.x+3*l*a*a*n.x+a*a*a*s.x,y:l*l*l*t.y+3*l*l*a*e.y+3*l*a*a*n.y+a*a*a*s.y}});function QM(t,e,n,s,i,r){const{rx:o,ry:a}=wc,l=(d,f)=>({x:n+i*d,y:s-f}),c=l(-o,-a*.55),h=[c,...ue(c,l(0,-a*.8),l(o,-a*.6),8).slice(1),...Cg(l(o,-a*.6),l(o*1.08,a*.2),l(o*.75,a*1.05),l(0,a)),...Cg(l(0,a),l(-o*.8,a*.95),l(-o*1.1,a*.1),c)];t.shape(e(h),"#161c27",r*1.3,!0),t.shape(e(h.filter(d=>d.y<=s-a*.15)),"rgba(80, 96, 122, 0.45)",0,!0);const u=.035;t.shape(e([l(-o*.55-u,a*.5),l(-o*.55+u,a*.5),l(o*.05+u,-a*.45),l(o*.05-u,-a*.45)]),"rgba(255, 255, 255, 0.55)",0,!0)}function tS(t,e,n){const s=Math.max(1,.06*e.rx),i=be.y+.12,r=o=>kt(e,[],{x:o,y:i},n.projection).facing>=Re;r(-.1)&&r(.1)&&t.line(kt(e,ue({x:-.1,y:i},{x:0,y:i+.06},{x:.1,y:i}),{x:0,y:i},n.projection).points,s);for(const o of[1,-1]){const a={x:o*(be.x+wc.rx*.95),y:i};if(hn(e,[o,0,0]).facing<=.15||!r(a.x))continue;const[l]=kt(e,[a],a,n.projection).points;t.line([l,hn(e,[o*.98,i,-.1]).point],s*.9)}}function eS(t,e,n,s,i){const r=n===1?"left":"right",{x:o,y:a}={x:be.x*n,y:be.y},l={x:o,y:a},c=E=>kt(e,E,l,i.projection).points,h=Math.max(1,.055*e.rx),u=Math.max(1.5,.095*e.rx),d=Math.min(1,Math.max(0,Et(s,"blink",0))),f=Math.max(0,Et(s,`eye.${r}`,1)),m=Ig(f,d),g=Math.min(1,Math.max(0,Et(s,"bulge",0))),p=1+.12*Math.min(1,Math.max(0,f-1))+.25*g,b=be.rx*p,v=be.ry*p,k=Et(s,"smile",0);if(i.shades)QM(t,c,o,a,n,h);else if(m<.2){const E=k>.5?.14:-.08;t.line(c(ue({x:o-b*.85,y:a},{x:o,y:a+E},{x:o+b*.85,y:a})),h*1.4)}else{const E=de(o,a,b,v,32);t.shape(c(E),"#ffffff",h,!0);const T=Math.min(1,Math.max(Math.max(0,Et(s,"lid",0)),1-Math.min(1,m))),A=a+v-2*v*T*.95,P=Math.max(-1,Math.min(1,Et(s,"lookX",0))),I=Math.max(-1,Math.min(1,Et(s,"lookY",0))),O=.085*Math.max(.3,Et(s,"pupil",1))*(1+g*.2),_=o+P*b*.45,L=a-I*v*.45-v*.05,j=de(_,L,O,O,20).map(V=>({x:V.x,y:Math.min(V.y,A)}));if(L-O<A&&t.shape(c(j),t.ink,0,!0),T>.02){const V=Math.asin(Math.max(-1,Math.min(1,(A-a)/v))),tt=Array.from({length:25},(J,F)=>{const B=V+(Math.PI-2*V)*F/24;return{x:o+b*Math.cos(B),y:a+v*Math.sin(B)}});t.shape(c(tt),i.skin??"#ffffff",0,!0),t.line(c([tt[0],tt[tt.length-1]]),h),t.shape(c(E),null,h,!0)}}const w=a+(i.shades?wc.ry+.1:v+.12)+.08*Et(s,`brow.${r}`,0),S=Et(s,"browTilt",0)*.06,x={x:o+n*b*1,y:w},M={x:o-n*b*.8,y:w+S};t.line(kt(e,[M,x],{x:o,y:w},i.projection).points,u)}function nS(t,e,n,s){const i=Kt-n*.125,r=e*.5,o=.045,a=de(0,i-o*.9,r,o,24);t.shape(s(a,{x:0,y:Kt-.08}),"rgba(165, 55, 70, 0.2)",0,!0)}function sS(t,e,n){for(const s of[1,-1]){const i={x:.48*s,y:-.2},r=kt(e,[i],i,n);if(r.facing<Re)continue;const[o]=r.points,a=e.rx*.26,l=t.createRadialGradient(o.x,o.y,0,o.x,o.y,a);l.addColorStop(0,"rgba(225, 95, 95, 0.2)"),l.addColorStop(1,"rgba(225, 95, 95, 0)"),t.fillStyle=l,t.beginPath(),t.arc(o.x,o.y,a,0,Math.PI*2),t.fill()}}function iS(t,e,n,s,i){const r=Math.min(1,Math.max(0,n));if(!(r<=0))for(const o of[-1,1]){const a={x:o*.59,y:Ut};if(kt(e,[],a,i).facing<Re)continue;for(const h of[-.06,.035]){const u=[{x:a.x,y:a.y},{x:a.x+o*.1,y:a.y+h}];t.line(kt(e,u,a,i).points,s*.45*r)}const l={x:o*.3,y:-.38},c=ue({x:l.x,y:-.31},{x:l.x+o*.07,y:-.4},{x:l.x+o*.035,y:-.49});t.line(kt(e,c,l,i).points,s*.35*r)}}const _g="#8fd0f5",Rg=(t,e,n)=>Array.from({length:18},(s,i)=>{const r=Math.PI*2*i/18,o=Math.sin(r/2);return{x:t+Math.sin(r)*n*o,y:e-n*.9+Math.cos(r)*n*1.6*(.55+.45*o)-n*.4}});function rS(t,e,n,s,i){const r=Math.min(1,Math.max(0,Et(n,"blush",0))),o=Math.min(1,Math.max(0,Et(n,"tears",0))),a=Math.min(1,Math.max(0,Et(n,"sweat",0)));if(!(r+o+a<=.01)){for(const l of[1,-1]){const c={x:.5*l,y:-.16},h=kt(e,[],c,i).facing>=Re;if(r>.01&&h){const{points:d}=kt(e,de(c.x,c.y,.17,.1),c,i);if(t.shape(d,`rgba(240, 120, 140, ${(.75*r).toFixed(3)})`,0,!0),r>.5)for(const f of[-.07,0,.07]){const m=[{x:c.x+f-.018,y:c.y-.03},{x:c.x+f+.018,y:c.y+.03}];t.line(kt(e,m,c,i).points,s*.3)}}const u={x:$g*l,y:Ut};if(o>.01&&kt(e,[],u,i).facing>=Re){const d=.05+.04*o,f={x:u.x+.06*l,y:Ut-.2-.12*o};if(t.shape(kt(e,Rg(f.x,f.y,d),f,i).points,_g,s*.35),o>.6){const m=[{x:u.x+.05*l,y:Ut-.1},{x:f.x,y:f.y+d*.8}];t.line(kt(e,m,f,i).points,s*.3)}}}if(a>.01){const l={x:.64,y:.42};kt(e,[],l,i).facing>=Re&&t.shape(kt(e,Rg(l.x,l.y,.05+.05*a),l,i).points,_g,s*.35)}}}const oS=15;function He(t,e){const n=Math.sqrt(Math.max(0,1-e*e));return[n*Math.sin(t),e,n*Math.cos(t)]}const aS=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function ne(t,[e,n,s]){const[i,r,o]=t.axes;return i[2]*e+r[2]*n+o[2]*s}function _t(t,e){return hn(t,e).point}function mo(t,e){const n=Math.abs(t-e)%(Math.PI*2);return n>Math.PI?Math.PI*2-n:n}function po(t,e,n=64){const s=e.top??1,i=e.bottom??-1,r=Math.max(8,Math.ceil((s-i)*oS)),o=m=>Math.min(s,Math.max(i,s-(s-i)*(m-1)/r)),a=m=>-Math.PI+Math.PI*2*m/n,l=(m,g)=>e.normal?e.normal(m,g):aS(e.position(m,g)),c=r+3,h=new Float64Array(n*c),u=new Float64Array(n*c);for(let m=0;m<c;m++){const g=m===0||m===c-1,p=o(m);for(let b=0;b<n;b++){const v=m*n+b;if(g){h[v]=-1;continue}const k=a(b);h[v]=e.inside(k,p),u[v]=h[v]>-.35?ne(t,l(k,p)):0}}const d=m=>(m%n+n)%n,f=m=>{const g=n+1,p=new Float64Array(g*c);for(let I=0;I<c;I++)for(let O=0;O<=n;O++){const _=I*n+(O===n?0:O);p[I*g+O]=Math.min(h[_],m*u[_])}const b=(I,O)=>p[O*g+I],v=(I,O,_,L)=>{const j=b(I,O),V=b(_,L),tt=j===V?.5:Math.min(1,Math.max(0,j/(j-V)));return _t(t,e.position(a(I+(_-I)*tt),o(O+(L-O)*tt)))},k=n*c*2,w=new Int32Array(k).fill(-1),S=new Int32Array(k).fill(-1),x=new Map,M=(I,O,_)=>{const L=(_*n+d(O))*2+(I?1:0);return x.has(L)||x.set(L,I?v(d(O),_,d(O),_+1):v(O,_,O+1,_)),L},E=(I,O)=>{w[I]===-1?w[I]=O:S[I]=O},T=(I,O)=>{E(I,O),E(O,I)};for(let I=0;I<c-1;I++)for(let O=0;O<n;O++){const _=I*g+O,L=(p[_]>0?8:0)|(p[_+1]>0?4:0)|(p[_+g+1]>0?2:0)|(p[_+g]>0?1:0);if(L===0||L===15)continue;const j=()=>M(!1,O,I),V=()=>M(!1,O,I+1),tt=()=>M(!0,O,I),J=()=>M(!0,O+1,I);switch(L){case 1:case 14:T(tt(),V());break;case 2:case 13:T(V(),J());break;case 3:case 12:T(tt(),J());break;case 4:case 11:T(j(),J());break;case 6:case 9:T(j(),V());break;case 7:case 8:T(tt(),j());break;case 5:case 10:{const F=(b(O,I)+b(O+1,I)+b(O+1,I+1)+b(O,I+1))/4>0;L===5===F?(T(tt(),j()),T(V(),J())):(T(tt(),V()),T(j(),J()));break}}}const A=[],P=new Uint8Array(k);for(const I of x.keys()){if(P[I])continue;const O=[];let _=-1,L=I;for(;L!==-1&&!P[L];){P[L]=1,O.push(x.get(L));const j=w[L],V=S[L],tt=j!==-1&&j!==_&&!P[j]?j:V!==-1&&V!==_&&!P[V]?V:-1;_=L,L=tt}O.length>=3&&A.push(O)}return A};return{near:f(1),far:f(-1)}}const Hg=new WeakMap;function kc(t,e,n){let s=Hg.get(t);s||Hg.set(t,s=new Map);let i=s.get(e);return i||s.set(e,i=n()),i}function vc(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 Fg(t,e,n,s=.04){const i=[];let r=[];return e.forEach((o,a)=>{ne(t,n[a])>s?r.push(_t(t,o)):(r.length>=2&&i.push(r),r=[])}),r.length>=2&&i.push(r),i}const Lg=t=>t*Math.PI/180,Mc=t=>{const e=Math.hypot(...t)||1;return t.map(n=>n/e)},lS=(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 Ng(t,e,n){return t>=e+n?t:t<=e-n?e:e+(t-e+n)**2/(4*n)}function Sc(t,e,n){const s=Mc(n),i=t.reduce((c,h,u)=>c+h*s[u],0),o=t.map((c,h)=>c-i*s[h]).reduce((c,h)=>c+h*h,0),a=Math.sqrt(Ng(1-o,e*e,e*e)),l=Ng(i,a,e)-i;return l===0?t:t.map((c,h)=>c+s[h]*l)}function cS(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 hS(t,e,n,s){const i=(t.path.length-1)/3,r=i*20,o=[],a=[],l=s.trail!==0||s.lift!==0,c=Math.max(0,e+n);for(let h=0;h<=r;h++){const u=h/r,d=Math.min(i-1,Math.floor(u*i)),f=u*i-d,m=1-f,g=[m**3,3*m*m*f,3*m*f*f,f**3],p=t.path.slice(d*3,d*3+4),b=Lg(p.reduce((_,L,j)=>_+L.around*g[j],0)),v=p.reduce((_,L,j)=>_+L.up*g[j],0),k=p.reduce((_,L,j)=>_+(L.lift??0)*g[j],0),w=1+e+n+k,S=v>=0?Math.sqrt(Math.max(0,1-v*v)):1,x=u*u*(t.follow??1),M=Lg(s.swing)*x,E=b-M,T=[Math.sin(E)*S*w,v*(v>=0?w:1),Math.cos(E)*S*w],A=[T[0],T[1]+s.lift*x,T[2]-s.trail*x],P=[Math.sin(E)*S,Math.max(0,v),Math.cos(E)*S],I=Mc(T),O=l&&x>0?Sc(A,c,I):A;a.push(I),o.push({center:O,normal:P,left:O,right:O,t:u})}return o.forEach((h,u)=>{const d=o[Math.max(0,u-1)].center,m=o[Math.min(r,u+1)].center.map((b,v)=>b-d[v]),g=Mc(lS(h.normal,m)),p=t.width*Math.sin(Math.PI*h.t)**.6*.5;h.left=h.center.map((b,v)=>b+g[v]*p),h.right=h.center.map((b,v)=>b-g[v]*p),l&&h.t>0&&(t.follow??1)>0&&(h.left=Sc(h.left,c,a[u]),h.right=Sc(h.right,c,a[u]))}),o}const ks=(t,e,n)=>t.map((s,i)=>s+(e[i]-s)*n);function uS(t,e,n){const s=n?1:-1,i=[];let r=[];for(let o=0;o<e.length;o++){const a=e[o],l=s*ne(t,a.normal)>=0;if(o>0){const c=e[o-1],h=s*ne(t,c.normal),u=s*ne(t,a.normal);if(h>=0!==l){const d=h/(h-u),f={center:ks(c.center,a.center,d),left:ks(c.left,a.left,d),right:ks(c.right,a.right,d),normal:ks(c.normal,a.normal,d),t:c.t+(a.t-c.t)*d};l?r=[f]:(r.push(f),r.length>=2&&i.push(r),r=[])}}l&&r.push(a)}return r.length>=2&&i.push(r),i}function Wg(t,e,n,s,i,r,o){const a=(n.locks??[]).map(h=>hS(h,n.volume,s,i)),l=h=>h.reduce((u,d)=>u+ne(e,d.center),0)/h.length;a.sort((h,u)=>l(h)-l(u));const c=Math.max(.7,r*.35);for(const h of a)for(const u of uS(e,h,o)){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"||t.look==="illustrated")&&(n.shine??0)>0){const g=u.filter(p=>p.t>=.2&&p.t<=.75);if(g.length>=3){const p=g.map((v,k)=>{const w=.16*Math.sin(Math.PI*k/(g.length-1));return _t(e,ks(v.center,v.left,.16+w))}),b=g.map(v=>_t(e,ks(v.center,v.left,.16)));t.shape([...p,...b.reverse()],`rgba(255,255,255,${n.shine})`,0)}}const m=u.filter(g=>g.t>.3);m.length>=2&&t.line(m.map(g=>_t(e,g.left)),c)}}const It=(t,e,n=0)=>({around:t,up:e,lift:n}),Tc=()=>[{width:.66,follow:.22,path:[It(-38,.88),It(-12,.94,.08),It(58,.76,.09),It(94,.16,.03)]},{width:.58,follow:.3,path:[It(-42,.8),It(-24,.7,.12),It(18,.57,.09),It(64,.3)]},{width:.36,follow:.18,path:[It(-58,.76),It(-76,.56,.07),It(-90,.12,.06),It(-102,-.36)]}];function Dg(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?[It(e,.7),It(e+s*9,.2,.12),It(e-s*13,-.5,.2),It(e-s*8,-.95,.16),It(e-s*3,-1.4,.12),It(e+s*18,i+.35,.22),It(e+s*12,i,.03)]:[It(e,.7),It(e+s*7,.15,.2),It(e-s*8,-.75,.25),It(e+s*5,i)]}})}const dS={softSweep:{volume:.12,shine:.16,part:-38,strands:"part",sweep:-.08,hairline:{front:.64,side:.12,back:-.8},locks:Tc()},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:[...Dg(!1),...Tc()]},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:[...Dg(!0),...Tc()]}},vs={swing:0,trail:0,lift:0};function Ni(t){if(!t)return vs;const e=t["hair.swing"]??0,n=t["hair.trail"]??0,s=t["hair.lift"]??0;return e===0&&n===0&&s===0?vs:{swing:e,trail:n,lift:s}}const Bg=t=>t.swing===0&&t.trail===0&&t.lift===0;function zg(t){return t.length>0||t.ties.some(e=>e.kind!=="bun")||(t.locks??[]).some(e=>(e.follow??1)>0)}function Ec([t,e,n],s){if(s===0)return[t,e,n];const i=Math.cos(s),r=Math.sin(s);return[t*i-n*r,e,n*i+t*r]}const qg={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},jg=1.75,Ac={...dS,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:jg,opening:84,part:0,strands:"part",hairline:{front:.5,side:.05,back:-.85},coversEars:!0},shoulderWaves:{volume:.22,length:jg,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}},Fe={black:"#22201f",brown:"#6b4630",chestnut:"#7b4a2b",auburn:"#9a4426",blond:"#d9b55a",ginger:"#c8662f",gray:"#a7a29c",white:"#ecebe7"};function Kg(t){const e=typeof t=="string"?{style:t}:t,n=e.style?Ac[e.style]:{};if(e.style&&!n)throw new Error(`hair: unknown style '${e.style}'`);const{style:s,hairline:i,...r}=e,o={...qg,...n,...r,hairline:{...qg.hairline,...n.hairline,...i},ties:(r.ties??n.ties??[]).map(a=>({...a})),...r.spikes??n.spikes?{spikes:(r.spikes??n.spikes).map(a=>({...a}))}:{},...r.locks??n.locks?{locks:(r.locks??n.locks).map(cS)}:{},...r.fall??n.fall?{fall:{...r.fall??n.fall}}:{}};if(o.shine!==void 0&&(!Number.isFinite(o.shine)||o.shine<0||o.shine>1))throw new Error("hair: shine must be between 0 and 1");if(o.fall&&(!Number.isFinite(o.fall.taper)||o.fall.taper<0||o.fall.taper>1||!Number.isFinite(o.fall.wave)||o.fall.wave<0))throw new Error("hair: fall needs taper between 0 and 1 and nonnegative wave");return o}const Dn=t=>t*Math.PI/180,Ms=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},xc=t=>1-Math.abs(2*(t-Math.floor(t))-1);function Wi(t,e){const{front:n,side:s,back:i}=t.hairline,r=(n-i)/2,o=(n+i)/2,a=(o+s)/2,l=(o-s)/2,c=Math.max(0,Math.cos(e));let h=a+r*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*xc(e*11/(Math.PI*2))*c),h}function Yg(t,e,n){const s=t.textureAmount;switch(t.texture){case"spiky":return s*(xc(e*11/(Math.PI*2))*xc(n*2.6+.5))**1.2*Ms(-.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 Xg(t,e,n=vs){const s=t.length>0,i=new Map,r=h=>{let u=i.get(h);return u===void 0&&i.set(h,u=Wi(t,h)),u},o=Dn(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,m=Math.sqrt(1-.45*.45)*d*(1-f**5),g=.45+(1+t.flat-.45)*Math.min(1,f*1.8);return[m*Math.sin(h),g*(1+e),m*Math.cos(h)]},c={top:1,bottom:s?-(t.length+.25+Math.abs(t.fall?.wave??0)):-1,inside(h,u){const d=u-r(h);if(!s)return d;const f=Math.min(u+a(h),mo(h,0)-o);return Math.max(d,f)},position(h,u){if(s&&u<0){const k=t.length<1.5?.14*Ms(-t.length+.45,-t.length-.1,u):0,w=(t.fall?.taper??0)*Ms(0,-Math.max(.1,a(h)),u),S=1+e+t.volume*(1-k*2.5)+Yg(t,h,u)-k-w;return[S*Math.sin(h),u,S*Math.cos(h)]}const d=.4+.6*Ms(0,.3,u-Wi(t,h)),f=1+e+(t.volume+Yg(t,h,u))*d,m=l(h,u,f);if(m)return m;const[g,p,b]=He(h,u),v=[g*f,p*f,b*f];if(t.quiff>0){const k=t.quiff*Math.exp(-((h/.7)**2))*Ms(.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)]:He(h,u)}};return s&&!Bg(n)?fS(c,t,n):c}function fS(t,e,n){const s=r=>r<0?Ms(-.15,-Math.max(.7,e.length),r):0,i=r=>Dn(n.swing)*s(r);return{top:t.top,bottom:t.bottom,inside:(r,o)=>t.inside(r+i(o),o),position(r,o){const a=s(o);if(a===0)return t.position(r,o);const l=i(o),[c,h,u]=Ec(t.position(r+l,o),l);return[c,h+n.lift*a,u-n.trail*a]},normal:(r,o)=>Ec(t.normal(r+i(o),o),i(o))}}const gS=t=>t.texture==="spiky"||t.texture==="curly"||t.texture==="locs"?104:t.texture==="wavy"?80:64;function Gg(t,e,n,s){return kc(t,pS(e,s),()=>po(t,n,gS(e)))}const Ug=new WeakMap;let mS=1;function pS(t,e){if(Bg(e))return t;let n=Ug.get(t);return n||Ug.set(t,n=mS++),`${n}:${e.swing}:${e.trail}:${e.lift}`}function Vg(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 Pc(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 yS(t,e,n,s=16){return Array.from({length:s+1},(i,r)=>{const o=r/s,a=1-o;return{x:a*a*t.x+2*a*o*e.x+o*o*n.x,y:a*a*t.y+2*a*o*e.y+o*o*n.y}})}function bS(t,e,n,s,i){const r=t.ry,o=(e.length??1.8)*r,a=Pc(t,Ec(s,Dn(i.swing))),l=Pc(t,[0,i.lift,-i.trail]),c=Math.hypot(a.x,a.y)||1,h=e.at==="high"||e.at==="low"||e.at==="top"?Pc(t,[.95,0,0]):{x:0},u=e.kind==="braid"?.15:.5,d={x:n.x+a.x/c*r*u+h.x*.9+l.x*.5,y:n.y+a.y/c*r*u*.6+l.y*.5},f={x:n.x+a.x/c*r*u*.6+h.x*1.3+l.x,y:n.y+o+l.y};return yS(n,d,f)}const yo=t=>Math.max(1,t*.5),Jg=(t,e)=>Math.max(.8,Math.min(t*.4,.1*e.rx));function Zg(t,e,n,s,i,r){const{point:o,out:a}=Vg(s.at),l=1+n.volume,c=_t(e,[o[0]*l,o[1]*l,o[2]*l]),h=yo(i),u=Jg(i,e);if(s.kind==="bun"){const g=s.size??.32,p=_t(e,[o[0]*l+a[0]*g,o[1]*l+a[1]*g,o[2]*l+a[2]*g]);t.ellipse(p.x,p.y,g*e.rx,g*e.ry,e.angle,n.color,h);const b=g*e.rx*.55;t.line(Array.from({length:9},(v,k)=>{const w=-.4+k/8*Math.PI*1.3;return{x:p.x+Math.cos(w)*b,y:p.y+Math.sin(w)*b*.8}}),u);return}const d=bS(e,s,c,a,r),f=(s.size??(s.kind==="braid"?.2:.34))*e.rx*2;if(s.kind==="ponytail")t.shape(qt(d,f,f*.15),n.color,h),t.line(d.slice(3,d.length-3),u);else{const p=d.slice(0,d.length-3);for(let k=0;k<7;k++){const w=p[Math.floor(k/7*(p.length-1))],S=p[Math.floor((k+1)/7*(p.length-1))],x=Math.atan2(S.y-w.y,S.x-w.x),M=Math.hypot(S.x-w.x,S.y-w.y),E=f*(1-k/(7*2.2)),T=(k%2===0?1:-1)*.35,A={x:(w.x+S.x)/2,y:(w.y+S.y)/2};t.ellipse(A.x,A.y,M*.62,E*.5,x+T,n.color,h*.8)}const b=p[p.length-1],v=d[d.length-1];t.shape(qt([b,v],f*.7,f*.2),n.color,h*.8)}const m=d[s.kind==="braid"?d.length-4:2];t.ellipse(m.x,m.y,f*.32,f*.22,e.angle,n.color,h)}function Qg(t,e){return ne(t,Vg(e.at).out)<-.2}function wS(t){const e=(i,r,o=0,a=14)=>Array.from({length:a+1},(l,c)=>{const h=c/a;return[i[0]+(r[0]-i[0])*h+o*Math.sin(Math.PI*h),i[1]+(r[1]-i[1])*h]}),n=Dn(t.part??0),s=i=>Wi(t,i)+.04;switch(t.strands){case"part":return[e([n,s(n)],[n,.97])];case"sweep":{const i=Math.sign(t.sweep||-1),r=[.9,.72,.55].map((o,a)=>{const l=n+i*(.6+a*.35);return e([n,o],[l,Math.max(s(l)+.05,o-.35)],.05*i)});return[e([n,s(n)],[n,.97]),...r]}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,r=[-2.6,-2,-1.4,1.4,2,2.6,3.05].map(o=>e([o,Wi(t,o)<.9?.6:.9],[o,i],0));return t.part!==null&&r.push(e([n,s(n)],[n,.97])),r}default:return[]}}function kS(t,e,n,s,i){if(s.fill==="stipple"||s.hairline.front>1.5)return;const r=i.motion??vs,o=i.lineWidth*.45/n.rx,{far:a}=Gg(n,s,Xg(s,o,r),r);vc(e,n,()=>{for(const l of s.ties)Qg(n,l)&&Zg(t,n,s,l,i.lineWidth,r);tm(t,n,s,i.lineWidth,o,!1);for(const l of a)t.shape(l,s.color,yo(i.lineWidth));Wg(t,n,s,o,r,i.lineWidth,!1)},i.headOutline)}function $c(t,e,n,s){if(n.hairline.front>1.5)return;const i=s.motion??vs,r=s.lineWidth*.45/e.rx,o=Xg(n,r,i),a=Jg(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(o.inside(u+d,h)<.02)continue;const f=He(u+d,h);if(ne(e,f)<.12)continue;const m=_t(e,f);t.dot(m.x,m.y,a*.4)}return}const{near:l}=Gg(e,n,o,i),c=yo(s.lineWidth);tm(t,e,n,s.lineWidth,r,!0);for(const h of l)t.shape(h,n.color,c);Wg(t,e,n,r,i,s.lineWidth,!0);for(const h of wS(n)){const u=h.map(([f,m])=>{const[g,p,b]=o.position(f,m);return[g*.985,p*.985,b*.985]}),d=h.map(([f,m])=>o.normal(f,m));for(const f of Fg(e,u,d,.12))t.line(f,a)}for(const h of n.ties)Qg(e,h)||Zg(t,e,n,h,s.lineWidth,i)}function tm(t,e,n,s,i,r){for(const o of n.spikes??[]){const a=He(Dn(o.around),Math.max(-1,Math.min(1,o.up)));if(ne(e,a)>=0!==r)continue;const l=[Math.cos(Dn(o.around)),0,-Math.sin(Dn(o.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,o.width),d=Math.max(0,o.length),f=[_t(e,a.map(m=>m*(h+d)))];for(let m=0;m<8;m++){const g=m*Math.PI/4,p=a.map((b,v)=>b*h+u*(l[v]*Math.cos(g)+c[v]*Math.sin(g)));f.push(_t(e,p))}t.shape(bc(f),n.color,yo(s))}}const em=.35,Ic=t=>({centre:[t*.98,-.02,-.08],out:[t,0,-.12]});function nm(t,e,n,s,i){const{centre:r,out:o}=Ic(n),a=ne(e,o),l=Math.max(1,s.lineWidth*.55),c=s.skin==="none"?null:s.skin,h=e.ry*.27;if(!i){const p=_t(e,[r[0]*1.06,r[1],r[2]]);t.ellipse(p.x,p.y,e.rx*.17,h,e.angle,c,l);return}const u=_t(e,r),d=e.rx*(.12+.08*a);t.ellipse(u.x,u.y,d,h,e.angle,c,l);const f=Math.cos(e.angle),m=Math.sin(e.angle),g=Array.from({length:9},(p,b)=>{const v=-Math.PI*.55+b/8*Math.PI*1.1,k=Math.cos(v)*d*.45*-n,w=Math.sin(v)*h*.55;return{x:u.x+k*f-w*m,y:u.y+k*m+w*f}});t.line(g,Math.max(.8,l*.7))}function vS(t,e,n,s){vc(e,n,()=>{for(const i of[1,-1])ne(n,Ic(i).out)<em&&nm(t,n,i,s,!1)},s.headOutline)}function MS(t,e,n){for(const s of[1,-1])ne(e,Ic(s).out)>=em&&nm(t,e,s,n,!0)}const Oc={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 sm(t,e){const n=typeof t=="string"?{style:t}:t,s=n.style?Oc[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 un=t=>t*Math.PI/180,bo=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},im={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}},SS=(t,e)=>{const n=bo(un(48),un(100),mo(e,0));return t.top[0]+(t.top[1]-t.top[0])*n},TS=t=>t==="sideburns"||t==="muttonChops";function Cc(t,e){const n=im[t];if(!n)return null;const s=un(n.reach),i=r=>{const o=mo(r,0);return n.shape==="point"?Math.exp(-((o/.42)**2)):n.shape==="square"?1-bo(un(45),un(85),o):Math.cos(Math.min(o,Math.PI/2))**.7};return{top:Math.max(n.top[0],n.top[1])+.05,bottom:-1,inside(r,o){const a=mo(r,0),l=SS(n,r);let c=Math.min(l-o,s-a);if(n.band>0&&(c=Math.min(c,o-(l-n.band))),TS(t)){const h=t==="muttonChops"?un(70)-un(22)*bo(.08,-.6,o):un(72);c=Math.min(c,a-h)}return c},position(r,o){const[a,l,c]=He(r,o),h=1+e+n.volume,u=n.length*i(r)*bo(-.45,-1,o);return[a*h,l*h-u,c*h+u*.25]},normal:(r,o)=>He(r,o)}}function ES(t){const n=s=>s.map(([i,r])=>({x:i,y:-.24+r}));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 Di=t=>Math.max(1,t*.45);function AS(t,e,n,s){for(let i=.1;i>-1;i-=.13)for(let r=-Math.PI/1.7;r<Math.PI/1.7;r+=.2){const o=Math.round(i*100)%2*.1;if(n.inside(r+o,i)<.02)continue;const a=He(r+o,i);if(ne(e,a)<.15)continue;const l=_t(e,a);t.dot(l.x,l.y,s)}}function xS(t,e,n,s,i){const r=s.beard==="stubble"?null:Cc(s.beard,i.lineWidth*.45/n.rx);if(!r)return;const{far:o}=kc(n,s,()=>po(n,r));vc(e,n,()=>{for(const a of o)t.shape(a,s.color,Di(i.lineWidth))},i.headOutline)}function PS(t,e,n,s,i){if(n.beard==="none")return;const r=s.lineWidth*.45/e.rx;if(n.beard==="stubble"){AS(t,e,Cc("full",r),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}=kt(e,l,{x:0,y:-.6},s.face?.projection);h>-.05&&t.shape(c,n.color,Di(s.lineWidth)*.7);return}const o=Cc(n.beard,r);if(!o)return;const{near:a}=kc(e,n,()=>po(e,o));for(const l of a)t.shape(l,n.color,Di(s.lineWidth));if(im[n.beard]?.aroundMouth){const l=.27*Math.max(.3,i),c=Array.from({length:20},(d,f)=>{const m=Math.PI*2*f/20;return{x:Math.cos(m)*l,y:-.42+Math.sin(m)*.13}}),{points:h,facing:u}=kt(e,c,{x:0,y:-.42},s.face?.projection);u>-.05&&t.shape(h,s.skin==="none"?"#ffffff":s.skin,0)}}function $S(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}=kt(e,l,i,s.face?.projection);h>-.05&&t.line(c,Math.max(1,s.lineWidth*.32));return}const r=ES(n.moustache);if(!r)return;const{points:o,facing:a}=kt(e,r,i,s.face?.projection);if(!(a<=-.05)&&(t.shape(o,n.color,Di(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(kt(e,c,i,s.face?.projection).points,Di(s.lineWidth)*.8)}}const _c={round:!0,square:!0,sunglasses:!0};function rm(t){const n=(typeof t=="string"?{style:t}:t).style??"round";if(!(n in _c))throw new Error(`glasses: unknown style '${n}'`);return{style:n}}const IS=.05,wo={x:.34,y:.12,rx:1,ry:1},OS={x:be.x,y:be.y,rx:(be.rx+.03)/.2,ry:(be.ry+.06)/.19};function CS(t,e,n=wo){return Array.from({length:28},(i,r)=>{const o=Math.PI*2*r/28;if(t==="round")return{x:e+Math.cos(o)*.2*n.rx,y:n.y+Math.sin(o)*.19*n.ry};const a=Math.cos(o),l=Math.sin(o),c=(t==="sunglasses"?.22:.21)*n.rx*(n===wo?1:.93),h=(t==="sunglasses"?.17:.16)*n.ry*(n===wo?1:1.12);return{x:e+Math.sign(a)*Math.abs(a)**.45*c,y:n.y-.01+Math.sign(l)*Math.abs(l)**.45*h}})}function _S(t,e,n,s){const i=Math.max(1,Math.min(s.lineWidth*.5,.11*e.rx)),r=s.face?.style==="oval"?OS:wo,o=.2*r.rx,a=[];for(const l of[1,-1]){const c=r.x*l,{points:h,facing:u}=kt(e,CS(n.style,c,r),{x:c,y:r.y},s.face?.projection);if(u<IS)continue;a.push(l),t.shape(h,n.style==="sunglasses"?"#1f2328":null,i);const d=[l*.97,r.y+.02,-.1];if(ne(e,[l,0,0])>.15){const f=kt(e,[{x:c+l*(o+.01),y:r.y+.02}],{x:c,y:r.y},s.face?.projection).points[0];t.line([f,_t(e,d)],i*.9)}}if(a.length===2&&r.x-o>.02){const l=[{x:r.x-o,y:r.y+.02},{x:0,y:r.y+.07},{x:-(r.x-o),y:r.y+.02}];t.line(kt(e,l,{x:0,y:r.y},s.face?.projection).points,i)}}const ko={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 om(t){const e=typeof t=="string"?{style:t}:t,n=e.style??"cap",s=ko[n];if(!s)throw new Error(`hat: unknown style '${n}'`);return{style:n,color:e.color??s.color}}const Bn=(t,e)=>t.brim[1]+(t.brim[0]-t.brim[1])*(1+Math.cos(e))/2;function RS(t,e){return{top:1,bottom:Math.min(...t.brim)-.05,inside:(n,s)=>s-Bn(t,n),position(n,s){const[i,r,o]=He(n,s),a=Bn(t,n),l=s>a?(r-a)*(t.height-1):0;return[i*e,r*e+l,o*e]},normal:(n,s)=>He(n,s)}}function HS(t,e,n){const i=(r,o,a)=>{const l=Bn(e,r)*n-a;return[Math.sin(r)*o,l,Math.cos(r)*o]};if(e.peak){const r=[],o=[];for(let a=0;a<=24;a++){const l=(-80+160*a/24)*(Math.PI/180),c=e.peak*Math.cos(l)**.6;r.push(_t(t,[Math.sin(l)*(n+c*.25),Bn(e,l)*n-.07*Math.cos(l),Math.cos(l)*(n+c)])),o.push(_t(t,i(l,n,0)))}return[...r,...o.reverse()]}return e.ring?Array.from({length:48},(r,o)=>_t(t,i(Math.PI*2*o/48,n+e.ring,.07))):null}function FS(t){const e=s=>Array.from({length:13},(i,r)=>[s,Bn(t,s)+(.97-Bn(t,s))*r/12]),n=s=>Array.from({length:49},(i,r)=>{const o=-Math.PI+Math.PI*2*r/48;return[o,Bn(t,o)+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 am(t,e,n,s){const i=ko[n.style],o=1+s.lineWidth*.45/e.rx+Math.max(.05,Math.min(.3,s.hairVolume)+.04),a=Math.max(1,s.lineWidth*.5),l=HS(e,i,o);l&&t.shape(l,n.color,a);const c=RS(i,o),{near:h,far:u}=po(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 FS(i)){const m=f.map(([p,b])=>{const[v,k,w]=c.position(p,b);return[v*.99,k*.99,w*.99]}),g=f.map(([p,b])=>He(p,b));for(const p of Fg(e,m,g,.1))t.line(p,d)}if(i.detail==="seams"){const f=_t(e,[0,o*1.01,0]);t.dot(f.x,f.y,a*.9)}}function lm(t){const e=t.hair?Kg(t.hair):null;return{hair:e,facialHair:t.facialHair?sm(t.facialHair,e?.color):null,glasses:t.glasses?rm(t.glasses):null,hat:t.hat?om(t.hat):null,ears:t.ears??!1}}const cm=t=>!t.hair&&!t.facialHair&&!t.glasses&&!t.hat&&!t.ears,hm=t=>t.axes[2][2]<-.3,um=t=>t.ears&&!t.hair?.coversEars;function dm(t,e,n,s,i,r){if(cm(n))return;const o={...r,headOutline:r.face&&(r.face.shape==="angular"||r.face.projection==="volume")?xg(s,r.face):void 0};n.hair&&kS(e,t,s,n.hair,{...o,motion:Ni(i)}),n.facialHair&&xS(e,t,s,n.facialHair,o),um(n)&&vS(e,t,s,o)}function LS(t,e,n,s,i,r,o){if(cm(n)){o();return}const a=hm(s);um(n)&&MS(e,s,r),n.hair&&!a&&!r.faceUnderHair&&$c(e,s,n.hair,{...r,motion:Ni(i)}),n.facialHair&&PS(e,s,n.facialHair,r,i.mouthWidth??1),o(),n.hair&&!a&&r.faceUnderHair&&$c(e,s,n.hair,{...r,motion:Ni(i)}),n.facialHair&&$S(e,s,n.facialHair,r),n.glasses&&_S(e,s,n.glasses,r),n.hat&&!a&&am(e,s,n.hat,{lineWidth:r.lineWidth,hairVolume:n.hair?.volume??0})}function fm(t,e,n,s,i,r){hm(s)&&(n.hair&&$c(e,s,n.hair,{...r,motion:Ni(i)}),n.hat&&am(e,s,n.hat,{lineWidth:r.lineWidth,hairVolume:n.hair?.volume??0}))}const gm=40,NS=.215+.205,fe=(t,e)=>{const n={};for(const s of["left","right"])for(const[i,r]of Object.entries(e))n[`${t}.${s}.${i}`]=r;return n},gt=(t,e)=>t[e]??lt[e]??0;function vo(t,e,n=lt,s=1){const i=Ti(t),r=e*Math.PI*2,o=Math.sin(r)*s,a=Math.cos(r)*s,l=Kl(i,r),c=i.crouch??0,h=i.forearm??0,u={...lt,...n};u.lean=gt(n,"lean")+i.lean*s,u.bend=gt(n,"bend")+(i.bend??0);const d=(i.shoulder??0)+u.lean+u.bend,f=Yl(i,a);u["leg.left.swing"]=i.swing*o+c*.6+f.left*.5,u["leg.right.swing"]=-i.swing*o+c*.6+f.right*.5,u["leg.left.knee"]=i.knee*Math.max(0,a)+c*1.2+f.left,u["leg.right.knee"]=i.knee*Math.max(0,-a)+c*1.2+f.right,u["leg.left.ankle"]=gt(n,"leg.left.ankle")-(i.tiptoe??0),u["leg.right.ankle"]=gt(n,"leg.right.ankle")-(i.tiptoe??0);for(const[m,g]of[["left",-1],["right",1]])gt(n,`arm.${m}.spread`)>gm||gt(n,`arm.${m}.swing`)>gm||(u[`arm.${m}.swing`]=d+g*i.arm*o,u[`arm.${m}.elbow`]=gt(n,`arm.${m}.elbow`)+h+i.elbow*Math.max(0,g*o));return u["head.nod"]=gt(n,"head.nod")-i.lean*.5*s+(i.headTilt??0),u.side=gt(n,"side")+(i.sway??0)*Math.sin(r),u.lift=gt(n,"lift")+(i.bounce??0)*s*l,u.stretch=gt(n,"stretch")*(1+(i.squash??0)*(l-.5)),u}function Mo(t,e,n=1,s=1){const i=Ti(t);return 4*NS*s*e*Math.sin(i.swing*n*Math.PI/180)}const Ss=t=>oc[t],So={take:t=>[{after:140,pose:{stretch:.8,bend:10,lean:gt(t,"lean")-4,...fe("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,...fe("arm",{spread:150,bend:35,swing:0,elbow:0}),...fe("leg",{swing:25,knee:60}),...Ss("shocked")},easing:"ease-out-cubic"},{after:720,pose:{lift:.25,stretch:1.25,bend:-10,...fe("arm",{spread:140})},easing:"ease-in-out"},{after:900,pose:{lift:0,stretch:.74,bend:12,...fe("arm",{spread:70,bend:0}),...fe("leg",{swing:30,knee:60})},easing:"ease-in-quad"},{after:1060,pose:{stretch:1.06,bend:-3,...fe("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"),...Ss("surprised"),...fe("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,...Ss("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,...Ss("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,...fe("arm",{spread:75}),...fe("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"),...fe("leg",{swing:0,knee:0})},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...Ss("scared"),...fe("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:{...Ss("sad"),bend:18,stretch:.92,lean:gt(t,"lean")+5,"head.nod":14,...fe("arm",{spread:6,swing:0,elbow:4,bend:0})},easing:"ease-in-out"}]};function mm(t,e){const n=vt(e.from??{}),s=e.speed??1;let i=n;return[{time:e.at,pose:n},...So[t](n).map(r=>(i={...i,...r.pose},{time:e.at+r.after*s,pose:i,act:!1,...r.easing?{easing:r.easing}:{}}))]}function pm(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 ym(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 Rc={sweeping:pm,brushing:ym};function WS(t,e,n=lt){const s=Rc[t];if(!s)throw new Error(`humanCyclePose: ${dt("cycle",t,Object.keys(Rc))}`);return s(e,n)}function bm(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 wm(t,e){const n=t.flatMap(i=>Array.from({length:8},(r,o)=>({x:i.x+Math.cos(o*Math.PI/4)*e,y:i.y+Math.sin(o*Math.PI/4)*e})));let s=bc(n);for(let i=0;i<2;i++)s=s.flatMap((r,o)=>{const a=s[(o+1)%s.length];return[{x:r.x*.75+a.x*.25,y:r.y*.75+a.y*.25},{x:r.x*.25+a.x*.75,y:r.y*.25+a.y*.75}]});return s}const km=t=>t.flatMap(e=>[e.left,e.right]);function Hc(t,e={}){const{top:n,length:s}=bm(e),i=t.bodyContours;if(!i?.spine)throw new Error("leafOutfit requires organic body contours");const r=i.spine.samples.filter(a=>a.at<=.3),o=["left","right"].flatMap(a=>i[`leg.${a}`]?.samples.filter(l=>l.at<=s)??[]);return{...n?{top:wm(km(i.spine.samples.filter(a=>a.at>=.52&&a.at<=.91)),t.height*.01)}:{},skirt:wm(km([...r,...o]),t.height*.012)}}function DS(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 BS(t,e,n){const s=e.x-t.x,i=e.y-t.y,r=Math.hypot(s,i)||1,o=-i/r,a=s/r,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+o*f,y:t.y+i*u+a*f})}return l}function vm(t,e,n,s,i,r){const o=e.lineWidth*.7;if(n.shape(s,i,o),n.look==="silhouette")return;t.save(),DS(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 m=0;m<5;m++){const g={x:a+u*(m/4+(f?.07:-.04)),y:c+d*(f?.38:-.1)},p={x:g.x+u*.09,y:g.y+d*.78};n.shape(BS(g,p,u*.13),(m+f)%2?i:r,o*.6),n.line([g,{x:g.x*.45+p.x*.55,y:g.y*.45+p.y*.55},p],o*.45);for(const b of[.32,.52,.7]){const v={x:g.x+(p.x-g.x)*b,y:g.y+(p.y-g.y)*b};n.line([{x:v.x-u*.045,y:v.y-d*.065},v,{x:v.x+u*.045,y:v.y-d*.05}],o*.3)}}t.restore()}function Mm(t={}){const e=bm(t),{color:n,accent:s}=e,i=r=>(o,a,l)=>{const c=Hc(a,e);r==="spine"&&c.top&&vm(o,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);r===h&&vm(o,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 zS={apron:"#d8b48a",labCoat:"#f4f6f8",hoodie:"#6b7280",cardigan:"#6b8e4e",overalls:"",sari:"#16a34a"},Fc=(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 qS(t){return t.parts["leg.left"].order>t.parts["leg.right"].order?"left":"right"}const Sm=t=>Math.max(t.parts["leg.left"].order,t.parts["leg.right"].order)>t.parts.spine.order,se=t=>t.bodyForward?.[2]??Math.cos(t.turn*Math.PI/2),ze=t=>t.bodyForward?.[0]??Math.sin(t.turn*Math.PI/2);function Tm(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 Em(t,e,n=0){const s=e*(t.length-1),i=Math.min(t.length-2,Math.floor(s)),r=t[i],o=t[i+1],a=pt(r,o,s-i),l=Math.hypot(o.x-r.x,o.y-r.y)||1;return{x:a.x+(o.y-r.y)/l*n,y:a.y-(o.x-r.x)/l*n}}function Am(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",r=e==="dress"?i:t.trousers??"#24476b",o=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"?zS[t.over]:r),m=t.shoes==="boots",g=t.shoeColor??"#3b2a1e",p=$=>$.lineWidth*.45,b=($,C,z,X)=>{const W=C.parts[`leg.${X}`].points;if(a==="skirt"&&!u)return;const N=a==="shorts"&&!u,D=C.bodyContours?.[`leg.${X}`],G=D?yc(D,0,N?.5:1,C.height*.006):qt(N?Fc(W,0,.5):W,C.height*(N?.085:.08),C.height*(N?.07:.05));z.shape(G,r,p(C)),!(n==="plain"||se(C)<.15)&&Tm($,G,()=>{const q=(Z,et=0)=>Em(W,Z,et*C.height);if(n==="jeans")z.line([q(.07,-.018),q(.17,-.02),q(.23,0),q(.17,.02),q(.07,.018)],p(C)*.65),z.line([q(.27,.013),...[.4,.55,.7,.85,.96].filter(Z=>!N||Z<.5).map(Z=>q(Z,.013))],p(C)*.5);else{const Z=[q(.25,-.024),q(.25,.024),q(.43,.024),q(.43,-.024)];z.shape(Z,r,p(C)*.65),z.line([q(.28,-.024),q(.32,0),q(.28,.024)],p(C)*.65);const et=q(.32);z.dot(et.x,et.y,p(C)*.8)}})},v=($,C,z)=>{const X=$.parts[`leg.${z}`].points,W=Fc(X,.7,1);if(W.length<2)return;C.shape(qt(W,$.height*.075,$.height*.07),g,p($));const N=W[0],D=W[1],G=D.x-N.x,q=D.y-N.y,Z=Math.hypot(G,q)||1,et=$.height*.04;C.line([{x:N.x-q/Z*et,y:N.y+G/Z*et},{x:N.x+q/Z*et,y:N.y-G/Z*et}],p($)*.9)},k=$=>{const C=$.chains.spine,z=C[0],X=C[C.length-1],W={x:z.x-(X.x-z.x)*.25,y:z.y-(X.y-z.y)*.25};return{hip:z,top:X,below:W,line:[W,...$.parts.spine.points]}},w=$=>{if($.bodyContours?.spine)return yc($.bodyContours.spine,0,.97,$.height*(c?.014:.006));const C=c?1.14:1,z=Math.hypot($.points["hip.left"].x-$.points["hip.right"].x,$.points["hip.left"].y-$.points["hip.right"].y),X=Math.max($.height*.15*C,z+Math.max($.height*.08,$.lineWidth*1.45)+p($));return qt(k($).line,X,$.height*.14*C)},S=($,C)=>{const z=[w(C)],{top:X,hip:W}=k(C);h&&z.push(qt([X,pt(X,W,.5),pt(X,W,1.08)],C.height*.155,C.height*.15)),l&&z.push(qt([X,pt(X,W,.5),W],C.height*.14,C.height*.15));const N=Object.values(C.points),D=Math.min(...N.map(et=>et.x))-C.height,G=Math.min(...N.map(et=>et.y))-C.height,q=Math.max(...N.map(et=>et.x))+C.height,Z=Math.max(...N.map(et=>et.y))+C.height;for(const et of z){$.beginPath(),$.rect(D,G,q-D,Z-G),$.moveTo(et[0].x,et[0].y);for(const H of et.slice(1))$.lineTo(H.x,H.y);$.closePath(),$.clip("evenodd")}},x=($,C)=>{const z=c?f:i;C.shape(w($),z,p($))},M=($,C,z)=>{const X=se(C);if(!e||X<.2||c)return;const{top:W,hip:N}=k(C),D=ze(C)*C.height*.025,G=[W,N],q=(Z,et=0)=>Em(G,Z,D+et*C.height*X);Tm($,w(C),()=>{if(e==="shirt"){z.line([q(.12),q(.92)],p(C)*.65);for(const Z of[.24,.4,.56,.72,.88]){const et=q(Z,.008);z.dot(et.x,et.y,p(C)*.9)}}else if(e==="blouse"){z.line([q(.025,-.04),q(.24),q(.025,.04)],p(C)*.75);const Z=q(.31);z.dot(Z.x,Z.y,p(C))}else e==="dress"?z.line([q(.04,-.035),q(.17,-.028),q(.17,.028),q(.04,.035)],p(C)*.75):z.line([q(.025,-.035),q(.1,-.02),q(.12),q(.1,.02),q(.025,.035)],p(C)*.65)})},E=($,C)=>{const z=se($),{top:X,hip:W}=k($),N=$.height*.07,D={x:(X.x-W.x)*.16,y:(X.y-W.y)*.16};if(z>=0){C.shape([{x:X.x-N,y:X.y+D.y*.25},{x:X.x-N*.8+D.x,y:X.y+D.y},{x:X.x+D.x*1.2,y:X.y+D.y*1.35},{x:X.x+N*.8+D.x,y:X.y+D.y},{x:X.x+N,y:X.y+D.y*.25}],f,p($));return}const G=pt(X,W,.42);C.shape([{x:X.x-N*.9,y:X.y},{x:X.x+N*.9,y:X.y},{x:G.x+N*.7,y:G.y},{x:G.x,y:G.y+$.height*.02},{x:G.x-N*.7,y:G.y}],f,p($))},T=($,C)=>{const z=se($);if(z<.2)return;const{top:X,hip:W}=k($),N=ze($)*$.height*.03,D=$.height*.06*z,G=pt(X,W,.62),q=pt(X,W,.9);C.line([{x:G.x+N-D,y:G.y},{x:q.x+N-D*1.1,y:q.y}],p($)*.7),C.line([{x:G.x+N+D,y:G.y},{x:q.x+N+D*1.1,y:q.y}],p($)*.7);const Z=pt(X,W,.1);for(const et of[-1,1])C.line([{x:Z.x+N+et*D*.2,y:Z.y},{x:Z.x+N+et*D*.35,y:Z.y+$.height*.07}],p($)*.6)},A=($,C)=>{const{top:z,hip:X}=k($),W=se($);if(C.shape(qt([z,pt(z,X,.5),pt(z,X,1.08)],$.height*.155,$.height*.15),f,p($)),W<.2)return;const N=ze($)*$.height*.03,D=$.height*.02*W,G=pt(z,X,.12),q=pt(z,X,1.05);C.shape([{x:G.x+N-D,y:G.y},{x:G.x+N+D,y:G.y},{x:q.x+N+D*1.3,y:q.y},{x:q.x+N-D*1.3,y:q.y}],i,p($)*.7);for(const Z of[.35,.55,.75]){const et=pt(z,X,Z);C.dot(et.x+N+D*1.6,et.y,p($)*1.2)}},P=($,C)=>{const z=se($),{top:X,hip:W}=k($),N=ze($)*$.height*.04,D=pt(W,X,.12),G=pt(W,X,.74);if(z<.15){if(z<-.3){const H=$.points["shoulder.left"],U=$.points["shoulder.right"];C.line([H,{x:D.x+$.height*.03,y:D.y}],p($)*.8),C.line([U,{x:D.x-$.height*.03,y:D.y}],p($)*.8)}return}const q=$.height*.07*z;C.shape([{x:G.x+N-q*.75,y:G.y},{x:G.x+N+q*.75,y:G.y},{x:D.x+N+q*1.1,y:D.y},{x:D.x+N-q*1.1,y:D.y}],r,p($));for(const H of["left","right"]){const U=$.points[`shoulder.${H}`],nt={x:G.x+N+(U.x>G.x+N?1:-1)*q*.55,y:G.y};C.line([nt,{x:U.x+(nt.x-U.x)*.15,y:U.y+(nt.y-U.y)*.15}],p($)*1.6)}const Z=pt(G,D,.3),et=q*.4;C.line([{x:Z.x+N-et,y:Z.y},{x:Z.x+N-et,y:Z.y+et*1.4},{x:Z.x+N+et,y:Z.y+et*1.4},{x:Z.x+N+et,y:Z.y}],p($)*.6)},I=($,C)=>{const{hip:z,top:X}=k($),W=pt(z,X,.2),N=[$.points["ankle.left"],$.points["ankle.right"]],D=pt(z,{x:(N[0].x+N[1].x)/2,y:(N[0].y+N[1].y)/2},.98),G=$.height*.075,q=Math.max($.height*.12,Math.abs(N[0].x-N[1].x)/2+$.height*.07),Z=D.x-W.x,et=D.y-W.y,H=Math.hypot(Z,et)||1,U={x:-et/H,y:Z/H};if(C.shape([{x:W.x+U.x*G,y:W.y+U.y*G},{x:D.x+U.x*q,y:D.y+U.y*q},{x:D.x-U.x*q,y:D.y-U.y*q},{x:W.x-U.x*G,y:W.y-U.y*G}],f,p($)),se($)>.2){const at=ze($)*$.height*.03;for(const rt of[-.35,0,.35]){const ct=G*.5*rt,it=q*.45*rt;C.line([{x:W.x+at+U.x*ct,y:W.y+U.y*ct+$.height*.02},{x:D.x+at+U.x*it,y:D.y+U.y*it}],p($)*.5)}}},O=($,C)=>{const z=se($),{top:X,hip:W}=k($),N=ze($),D=N>=0?"left":"right",G=D==="left"?"right":"left",q=$.points[`shoulder.${D}`],Z=$.height*.035;if(z<.15){const U=pt(X,W,.9);C.shape(qt([q,{x:U.x+(q.x-X.x)*.5,y:U.y}],Z*2.2,Z*2.6),f,p($));return}const et={x:W.x+($.points[`hip.${G}`].x-W.x)*1.2,y:pt(W,X,.08).y};C.shape(qt([et,pt(et,q,.5),q],Z*2.4,Z*2),f,p($));const H={x:q.x-(W.x-q.x)*.05-N*$.height*.03,y:q.y+$.height*.16};C.shape(qt([q,H],Z*2,Z*1.6),f,p($))},_=($,C)=>{if($.bodyContours){C.shape(Hc($,{top:!1,length:.45}).skirt,r,p($));return}const{hip:z,top:X}=k($),W=pt(z,X,.18),N=[$.points["knee.left"],$.points["knee.right"]],D=pt(z,{x:(N[0].x+N[1].x)/2,y:(N[0].y+N[1].y)/2},1.05),G=$.height*.075,q=Math.max($.height*.13,Math.abs(N[0].x-N[1].x)/2+$.height*.08),Z=D.x-W.x,et=D.y-W.y,H=Math.hypot(Z,et)||1,U={x:-et/H,y:Z/H};C.shape([{x:W.x+U.x*G,y:W.y+U.y*G},{x:D.x+U.x*q,y:D.y+U.y*q},{x:D.x-U.x*q,y:D.y-U.y*q},{x:W.x-U.x*G,y:W.y-U.y*G}],r,p($))},L=($,C)=>{const z=se($);if(z<.2)return;const{top:X,hip:W}=k($),N={x:(W.x-X.x)*.12,y:(W.y-X.y)*.12},D=$.height*.045*z;for(const G of[-1,1])C.shape([{x:X.x+G*D*.2,y:X.y+N.y*.1},{x:X.x+G*D*1.3,y:X.y-N.y*.1},{x:X.x+G*D*.6+N.x,y:X.y+N.y}],i,p($)*.8)},j=($,C,z)=>{const X=se($);if(X<.25)return;const{top:W,hip:N}=k($),D=ze($)*$.height*.03,G=H=>({x:pt(W,N,H).x+D,y:pt(W,N,H).y}),q=$.height*.022*X,Z=G(.08),et=G(.62);C.shape([{x:Z.x-q,y:Z.y-q},{x:Z.x+q,y:Z.y-q},{x:Z.x+q*.6,y:Z.y+q},{x:Z.x-q*.6,y:Z.y+q}],z,p($)*.7),C.shape([{x:Z.x-q*.6,y:Z.y+q},{x:Z.x+q*.6,y:Z.y+q},{x:et.x+q*1.4,y:et.y-q*2},et,{x:et.x-q*1.4,y:et.y-q*2}],z,p($)*.7)},V=($,C)=>{const z=se($),{top:X,hip:W}=k($),N=pt(W,X,.72),D=[$.points["knee.left"],$.points["knee.right"]],G=pt(W,{x:(D[0].x+D[1].x)/2,y:(D[0].y+D[1].y)/2},.9),q=ze($)*$.height*.04;if(z<.15){const H=pt(W,X,.2);z<-.3&&C.line([{x:H.x-$.height*.05,y:H.y},{x:H.x+$.height*.05,y:H.y}],p($));return}const Z=$.height*.075*z,et=pt(W,X,.2);C.shape([{x:N.x+q-Z*.7,y:N.y},{x:N.x+q+Z*.7,y:N.y},{x:et.x+q+Z,y:et.y},{x:G.x+q+Z*1.15,y:G.y},{x:G.x+q-Z*1.15,y:G.y},{x:et.x+q-Z,y:et.y}],f,p($)),C.line([{x:N.x+q-Z*.6,y:N.y},{x:X.x-Z*.2,y:X.y},{x:N.x+q+Z*.6,y:N.y}],p($)*.8)},tt=($,C,z)=>{const{top:X,hip:W}=k($),N=[$.points["knee.left"],$.points["knee.right"]],D=pt(W,{x:(N[0].x+N[1].x)/2,y:(N[0].y+N[1].y)/2},.95);z?C.shape(qt([pt(X,W,.8),W,D],$.height*.145,$.height*.17),f,p($)):C.shape(qt([X,pt(X,W,.5),W],$.height*.14,$.height*.15),f,p($));const G=se($);if(G>.2){const q=ze($)*$.height*.03,[Z,et]=z?[W,D]:[X,W];if(C.line([{x:Z.x+q,y:Z.y},{x:et.x+q,y:et.y}],p($)*.8),!z){const H=pt(X,W,.35),U=$.height*.025*G;C.shape([{x:H.x+q-U*2.4,y:H.y},{x:H.x+q-U*.6,y:H.y},{x:H.x+q-U*.6,y:H.y+U*1.6},{x:H.x+q-U*2.4,y:H.y+U*1.6}],f,p($)*.6)}}},J=($,C,z,X,W)=>{const N=$.bodyContours?.[`arm.${z}`];if(N){const Q=yc(N,0,W,$.height*.006);C.shape(Q,X,0);const ot=w($);for(let ht=0;ht<Q.length;ht++){const ft=Q[ht],bt=Q[(ht+1)%Q.length];Sg({x:(ft.x+bt.x)/2,y:(ft.y+bt.y)/2},ot)||C.line([ft,bt],p($))}return}const D=$.parts[`arm.${z}`].points,G=D[0],q=$.chains.spine[$.chains.spine.length-1],et=[{x:G.x+(q.x-G.x)*.45,y:G.y+(q.y-G.y)*.45},...Fc(D,0,W)],H=qt(et,$.height*.085,$.height*(W>.6?.045:.06)),U=et.length,nt=H.slice(0,U),at=H.slice(U).reverse();C.shape(H,X,0);const rt=Q=>Math.hypot(Q[1].x-q.x,Q[1].y-q.y),[ct,it]=rt(nt)>rt(at)?[nt,at]:[at,nt];C.line(ct.slice(1),p($)),C.line(it.slice(Math.ceil(U*.45)),p($)),C.line([nt[U-1],at[U-1]],p($))},F=l||c||h,B=F?f:i,Y=F||o==="long"?.95:.45,R=F||o!=="none",K=($,C)=>{a==="skirt"&&!u&&!d&&_($,C),d&&I($,C),l&&tt($,C,!0),t.over==="apron"&&V($,C)},st=$=>(C,z,X)=>{C.save(),S(C,z),b(C,z,X,$),m&&v(z,X,$),C.restore(),qS(z)===$&&Sm(z)&&K(z,X)};return{parts:{"leg.left":{clip:S,over:st("left")},"leg.right":{clip:S,over:st("right")},spine:{over:($,C,z)=>{c&&se(C)>=0&&E(C,z),x(C,z),M($,C,z),s&&!c&&L(C,z),t.tie&&!c&&j(C,z,t.tie),l&&tt(C,z,!1),h&&A(C,z),c&&(se(C)<0&&E(C,z),T(C,z)),u&&P(C,z),d&&O(C,z),Sm(C)||K(C,z)}},"arm.left":{over:R?($,C,z)=>J(C,z,"left",B,Y):void 0},"arm.right":{over:R?($,C,z)=>J(C,z,"right",B,Y):void 0}}}}const Lc={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 xm(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,r=Lc[i];if(!r)throw new Error(`holding: unknown item '${i}'`);if(n==="both"&&r.hands==="one")throw new Error(`holding: a ${i} is held in one hand ('left' or 'right'), not 'both'`);if(n!=="both"&&r.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)??r.color}}return e}function To(t,e){const n=t.chains[`arm.${e}`],s=n[n.length-1],i=n[n.length-2],r=Math.hypot(s.x-i.x,s.y-i.y)||1,o={x:(s.x-i.x)/r,y:(s.y-i.y)/r},a=t.lineWidth*.5;return{point:{x:s.x+o.x*a,y:s.y+o.y*a},along:o,depth:t.parts[`arm.${e}`]?.depth??0}}function Ts(t,e,n,s=0){const i=Math.cos(s),r=Math.sin(s);return[[-e/2,-n/2],[e/2,-n/2],[e/2,n/2],[-e/2,n/2]].map(([o,a])=>({x:t.x+o*i-a*r,y:t.y+o*r+a*i}))}const Es=(t,e,n,s,i=12)=>Array.from({length:i+1},(r,o)=>{const a=n+(s-n)*o/i;return{x:t.x+Math.cos(a)*e,y:t.y+Math.sin(a)*e}});function Nc(t,e,n,s,i,r=1,o){const{point:a,along:l}=n,c=s/300;switch(e.item){case"mug":{const h=Ts({x:a.x,y:a.y-4*c},20*c,24*c);t.line(Es({x:a.x+10*c*Math.sign(r||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(r||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(Ts(a,13*c,24*c,h),e.color,i),t.shape(Ts(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 m=a.y-u/2+u*f;t.line([{x:a.x+d*5*c,y:m},{x:a.x+d*(h-5*c),y:m-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(Es({x:a.x,y:a.y+6*c},7*c,Math.PI,Math.PI*2),i),t.shape(Ts({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=(o??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(Es({x:a.x+5*c,y:a.y+10*c},5*c,Math.PI,0,8),i);const f=[...Es({x:d.x,y:d.y+h*.55},h,Math.PI,Math.PI*2,24)],m=[];for(let g=4;g>=0;g--){const p=d.x-h+2*h*g/5;m.push(...Es({x:p+h/5,y:d.y+h*.55},h/5,0,-Math.PI,6).reverse())}t.shape([...f,...m],e.color,i);return}case"broom":{const h={x:l.x*.4+.25*Math.sign(r||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},m={x:a.x+d.x*120*c,y:a.y+d.y*120*c};t.line([f,m],i*1.1);const g={x:-d.y,y:d.x},p=[{x:m.x+g.x*6*c,y:m.y+g.y*6*c},{x:m.x-g.x*6*c,y:m.y-g.y*6*c},{x:m.x-g.x*16*c+d.x*34*c,y:m.y-g.y*16*c+d.y*34*c},{x:m.x+g.x*16*c+d.x*34*c,y:m.y+g.y*16*c+d.y*34*c}];t.shape(p,e.color,i);return}case"cane":{const h=Math.min(.56*s,Math.max(.3*s,-a.y)),u=.12*Math.sign(r||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},m=Es({x:a.x+7*c*Math.sign(r||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(r||1),y:g.y}));t.line([...m,{x:a.x,y:a.y+2*c},f],i*1.2),t.shape(Ts({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(Ts(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 Wc=(t,e)=>(t[`held.${e}`]??1)>=.5,Pm=t=>Math.sin(t*Math.PI/2);function $m(t){const e=r=>Math.max(1,r.lineWidth*.45),n=r=>(o,a,l,c,h)=>{const u=t[r];u&&Wc(h??{},r)&&Nc(l,u,To(a,r),a.height,e(a),Pm(a.turn),a.head.center.y-a.head.ry)},s=(r,o,a,l,c)=>{const h=t.both;if(!h||!Wc(c??{},"both"))return;const u=To(o,"left"),d=To(o,"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};Nc(a,h,f,o.height,e(o),Pm(o.turn),o.head.center.y-o.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 r=o=>(a,l,c,h,u)=>{const d=o==="left"?"right":"left";(o==="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 o of["left","right"])i.parts[`arm.${o}`]={...i.parts[`arm.${o}`],over:jS(i.parts[`arm.${o}`]?.over,r(o))}}return i}function jS(t,e){return t?(n,s,i,r,o)=>{t(n,s,i,r,o),e(n,s,i,r,o)}:e}const As=(t,e,n)=>Math.min(n,Math.max(e,t)),Bi=(t,e)=>typeof t=="number"&&Number.isFinite(t)?t:e;function Im(t={}){const e=t.limbs??"tube";if(e!=="tube"&&e!=="line")throw new Error(`bean: unknown limbs '${String(e)}' (tube | line)`);const n=t.sleeves??"short";if(!["short","long","none"].includes(n))throw new Error(`bean: unknown sleeves '${String(n)}' (short | long | none)`);const s=t.fill??"#ffffff";return{limbs:e,torso:As(Bi(t.torso,1),.4,2.5),limbWidth:As(Bi(t.limbWidth,.024),.004,.12),lineWidth:As(Bi(t.lineWidth,.017),.003,.08),outlineWidth:As(Bi(t.outlineWidth,.0105),.001,.05),fill:s,shirt:t.shirt??null,sleeves:n,trousers:t.trousers??null,shoes:t.shoes??s,halo:t.halo??null,coat:t.coat??null,fedora:t.fedora??null,skirt:KS(t.skirt),drape:t.drape??null,bangles:t.bangles??null}}function KS(t){if(t==null)return null;if(typeof t=="string")return{color:t,length:1};if(typeof t!="object"||typeof t.color!="string")throw new Error("bean: skirt is a colour or { color, length }");return{color:t.color,length:As(Bi(t.length,1),.1,1)}}const we=(t,e,n=.5)=>({x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n});function Om(t,e){const{points:n}=e,s=we(n["shoulder.left"],n["shoulder.right"]),i=n.hip,r=Math.hypot(s.x-i.x,s.y-i.y);return{cx:(s.x+i.x)/2,cy:(s.y+i.y)/2,length:Math.max(r,e.height*.04),width:e.height*.068*t.torso,angle:r>1e-6?Math.atan2(s.y-i.y,s.x-i.x):-Math.PI/2}}function Cm(t){const e=t.length,n=e*.58,s=-e*.62,i=t.width*.82,r=t.width*.74,o=t.width,a=u=>[[{x:n,y:u*i},{x:n-e*.16,y:u*i}],[{x:e*.05,y:u*r*.98},{x:-e*.05,y:u*r}],[{x:-e*.3,y:u*o*1.04},{x:s+e*.14,y:u*o}],[{x:s,y:u*o*.95},{x:s,y:0}]],l=a(1),c=[{x:n,y:0},...l.map(([,u])=>u)],h=l.map(([u],d)=>[u,c[d]]).reverse();return{start:{x:n,y:0},segments:[...a(-1),...h]}}function xs(t,e){const n=Math.cos(t.angle),s=Math.sin(t.angle);return{x:t.cx+e.x*n-e.y*s,y:t.cy+e.x*s+e.y*n}}function YS(t,e=8){const{start:n,segments:s}=Cm(t),i=[xs(t,n)];let r=n;for(const[o,a]of s){for(let l=1;l<=e;l++){const c=l/e,h=1-c;i.push(xs(t,{x:h*h*r.x+2*h*c*o.x+c*c*a.x,y:h*h*r.y+2*h*c*o.y+c*c*a.y}))}r=a}return i}function _m(t,e,n={}){const s=h=>e.parts[h]?.depth??0,i=h=>(n[h]??0)>e.height*(h.startsWith("leg.")?Hm:Rm),r=s("arm.left")>=s("arm.right")?["arm.right","arm.left"]:["arm.left","arm.right"],o=s("leg.left")>=s("leg.right")?["leg.right","leg.left"]:["leg.left","leg.right"],a=h=>i(h)||h===r[1],l=h=>i(h)||t.limbs==="tube"&&!t.trousers&&!t.coat&&!t.skirt,c=t.limbs==="tube"&&!t.shirt&&!t.coat;return[...r.filter(h=>!a(h)),...o.filter(h=>!l(h)),...c?[]:["neck"],"spine",...c?["neck"]:[],...o.filter(l),...r.filter(a),"head"]}const Rm=.08,Hm=.12;function zi(t,e){return(t.parts[e]?.order??0)>(t.parts.spine?.order??0)}function XS(t,e){if(t.beginPath(),t.moveTo(e[0].x,e[0].y),e.length===2){t.lineTo(e[1].x,e[1].y);return}for(let n=1;n<e.length-1;n++){const s=n===e.length-2?e[n+1]:we(e[n],e[n+1]);t.quadraticCurveTo(e[n].x,e[n].y,s.x,s.y)}}function qi(t,e,n,s=12){const r={x:2*e.x-(t.x+n.x)/2,y:2*e.y-(t.y+n.y)/2};return Array.from({length:s+1},(o,a)=>{const l=a/s,c=1-l,h={x:c*c*t.x+2*c*l*r.x+l*l*n.x,y:c*c*t.y+2*c*l*r.y+l*l*n.y},u=l<.5?we(t,e,2*l):we(e,n,2*l-1);return we(u,h,.55)})}function Dc(t,e,n,s,i){i&&Vt(t,e,n*1.9,i),Vt(t,e,n,s)}function Vt(t,e,n,s){e.length<2||(t.lineCap="round",t.lineJoin="round",XS(t,e),t.strokeStyle=s,t.lineWidth=n,t.stroke())}function Eo(t,e){const{start:n,segments:s}=Cm(e),i=xs(e,n);t.moveTo(i.x,i.y);for(const[r,o]of s){const a=xs(e,r),l=xs(e,o);t.quadraticCurveTo(a.x,a.y,l.x,l.y)}t.closePath()}function Ao(t,e,n,s,i){for(const o of[()=>Eo(t,e),()=>t.arc(n.x,n.y,s,0,Math.PI*2)])t.save(),t.beginPath(),t.rect(-1e6,-1e6,2*1e6,2*1e6),o(),t.clip("evenodd"),i(),t.restore()}function GS(t,e,n){return{x:t.x-Math.cos(e.angle)*n,y:t.y-Math.sin(e.angle)*n}}function Fm(t,e,n,s,i,r,o,a,l){t.beginPath(),t.ellipse(e,n,s,i,r,0,Math.PI*2),t.fillStyle=o,t.fill(),t.lineWidth=l,t.strokeStyle=a,t.stroke()}function Bc(t,e,n){const s=Math.atan2(e.y-t.y,e.x-t.x),i=n*.012;return{x:e.x+Math.cos(s)*i,y:e.y+Math.sin(s)*i,rx:n*.031,ry:n*.025,angle:s}}function Lm(t,e,n,s){const i=e.x-t.x,r=e.y-t.y,o=Math.abs(i)>n*.004?Math.sign(i):s,a=Math.max(Math.abs(i),n*.03),l=Math.max(0,Math.abs(r)-n*.02),c=Math.atan2(Math.sign(r)*l,a);return{x:t.x,ankle:t.y,ground:e.y,dir:o,length:a+n*.035,tip:c}}const Nm="#d6d3d1",Wm="#3f3f46";function Dm(t){const e=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim())?.[1];if(!e)return!1;const n=e.length===3?[...e].map(o=>o+o).join(""):e,[s,i,r]=[0,2,4].map(o=>parseInt(n.slice(o,o+2),16));return .299*s+.587*i+.114*r<110}function US(t,e,n,s,i,r,o){const a=e.length,l=e.width,c=a*.58,u=-a*.62-s*.62,d=l,f=l*.9,m=l*1.45;t.save(),t.translate(e.cx,e.cy),t.rotate(e.angle),t.lineJoin="round",t.lineCap="round",t.strokeStyle=i,t.lineWidth=r,t.beginPath(),t.moveTo(c+a*.02,0),t.quadraticCurveTo(c+a*.02,-d,c-a*.14,-d),t.quadraticCurveTo(a*.05,-f,-a*.08,-f),t.quadraticCurveTo(-a*.5,-f*1.1,u,-m),t.lineTo(u,m),t.quadraticCurveTo(-a*.5,f*1.1,-a*.08,f),t.quadraticCurveTo(a*.05,f,c-a*.14,d),t.quadraticCurveTo(c+a*.02,d,c+a*.02,0),t.closePath(),t.fillStyle=n,t.fill(),t.stroke(),t.clip(),t.lineWidth=r*.8,t.beginPath(),t.moveTo(c,-l*.5),t.lineTo(-a*.02,l*.05),t.moveTo(c,l*.5),t.lineTo(-a*.02,-l*.05),t.moveTo(c-a*.2,-l*.62),t.lineTo(c-a*.12,-l*.38),t.moveTo(c-a*.2,l*.62),t.lineTo(c-a*.12,l*.38),t.stroke(),t.beginPath(),t.moveTo(-a*.02,l*.05),t.lineTo(u,l*.12),t.stroke(),t.fillStyle="rgba(0,0,0,0.28)",t.fillRect(-a*.16,-f*1.2,a*.11,f*2.4),t.beginPath(),t.rect(-a*.17,-l*.18,a*.13,l*.36),t.fillStyle="#c9a227",t.fill(),t.stroke(),t.fillStyle=i;for(const[g,p]of[[a*.22,-l*.3],[a*.22,l*.4],[-a*.32,-l*.3],[-a*.32,l*.45]])t.beginPath(),t.arc(g,p,o*.006,0,Math.PI*2),t.fill();t.restore()}function Bm(t,e,n,s,i,r=0){const o=e.rx,a=Math.max(-90,Math.min(90,r))/60*o*.25;t.save(),t.translate(e.center.x,e.center.y),t.rotate(e.angle),t.lineJoin="round",t.lineWidth=i,t.strokeStyle=s,t.beginPath(),t.ellipse(a*.5,-o*.62,o*1.38,o*.22,0,0,Math.PI*2),t.fillStyle=n,t.fill(),t.stroke(),t.beginPath(),t.moveTo(a-o*.78,-o*.64),t.bezierCurveTo(a-o*.82,-o*1.05,a-o*.6,-o*1.32,a-o*.22,-o*1.24),t.quadraticCurveTo(a,-o*1.12,a+o*.22,-o*1.24),t.bezierCurveTo(a+o*.6,-o*1.32,a+o*.82,-o*1.05,a+o*.78,-o*.64),t.quadraticCurveTo(a,-o*.54,a-o*.78,-o*.64),t.closePath(),t.fillStyle=n,t.fill(),t.stroke(),t.clip(),t.fillStyle=s,t.fillRect(a-o,-o*.84,2*o,o*.17),t.restore()}function VS(t,e,n,s,i,r){const o=e.length*1.3,a=n*.034,l=n*.066,c=n*.012;t.save(),t.translate(e.x,e.ankle),t.scale(e.dir,1),e.tip&&t.rotate(e.tip),t.translate(0,e.ground-e.ankle),t.lineJoin="round",t.lineWidth=r,t.strokeStyle=i,t.beginPath(),t.moveTo(-a,-c),t.lineTo(o*.82,-c),t.quadraticCurveTo(o+n*.012,-c,o+n*.01,-l*.42),t.quadraticCurveTo(o*.98,-l*.85,o*.62,-l*.82),t.quadraticCurveTo(o*.3,-l*.8,n*.012,-l),t.lineTo(-n*.012,-l),t.quadraticCurveTo(-a*1.15,-l*.85,-a,-c),t.closePath(),t.fillStyle=s,t.fill(),t.stroke(),Dm(s)&&(t.save(),t.clip(),t.strokeStyle="rgba(255,255,255,0.35)",t.lineWidth=n*.006,t.lineCap="round",t.beginPath(),t.moveTo(o*.45,-l*.68),t.quadraticCurveTo(o*.85,-l*.72,o*.95,-l*.45),t.stroke(),t.restore()),t.beginPath(),t.moveTo(-a,-c),t.lineTo(o*.82,-c),t.quadraticCurveTo(o+n*.012,-c,o+n*.011,-c*1.8),t.lineTo(o+n*.012,0),t.lineTo(-a,0),t.closePath(),t.fillStyle=Dm(s)?Wm:Nm,t.fill(),t.stroke(),t.restore()}function zc(t,e,n){const s=t.points[`hip.${e}`],i=t.points[`knee.${e}`],r=t.points[`ankle.${e}`],o=Math.hypot(i.x-s.x,i.y-s.y),a=Math.hypot(r.x-i.x,r.y-i.y),l=As(n,0,1)*(o+a);return l<=o?we(s,i,o>0?l/o:0):we(i,r,a>0?Math.min(1,(l-o)/a):1)}function zm(t){const e=t.points,n=Math.hypot(e["knee.left"].x-e["hip.left"].x,e["knee.left"].y-e["hip.left"].y);return(e["knee.left"].y+e["knee.right"].y)/2-e.hip.y>.6*n}function JS(t,e,n,s,i,r){const o=e.height,a=s*3.1,l=zm(e),c=e.points,h=Math.hypot(c["knee.left"].x-c["hip.left"].x,c["knee.left"].y-c["hip.left"].y)+Math.hypot(c["ankle.left"].x-c["knee.left"].x,c["ankle.left"].y-c["knee.left"].y),u=Math.min(.93,n.length,l?1:1-(a/2+i)/Math.max(h,1)),d=[0,.25,.5,.75,1].map(v=>v*u),f=d.map(v=>zc(e,"left",v)),m=d.map(v=>zc(e,"right",v));if(t.save(),t.lineCap="round",t.lineJoin="round",l){const v=o*.035*u,k=d.map((S,x)=>{const M=x/(d.length-1);return{a:Math.min(f[x].x,m[x].x)-a/2-v*M,b:Math.max(f[x].x,m[x].x)+a/2+v*M,y:(f[x].y+m[x].y)/2}}),w=k[k.length-1];t.beginPath(),t.moveTo(k[0].a+a*.2,k[0].y-o*.02);for(const S of k.slice(1))t.lineTo(S.a,S.y);t.quadraticCurveTo((w.a+w.b)/2,w.y+o*.012,w.b,w.y);for(const S of[...k].reverse().slice(1))t.lineTo(S.b,S.y);t.lineTo(k[0].b-a*.2,k[0].y-o*.02),t.closePath(),t.fillStyle=n.color,t.fill(),t.lineWidth=i,t.strokeStyle=r,t.stroke(),t.strokeStyle="rgba(0,0,0,0.2)",t.lineWidth=i*.6;for(const S of[.38,.62])t.beginPath(),t.moveTo(k[1].a+(k[1].b-k[1].a)*S,k[1].y),t.lineTo(w.a+(w.b-w.a)*(S*1.2-.1),w.y),t.stroke();t.restore();return}for(const v of[f,m])Vt(t,v,a+2*i,r),Vt(t,v,a,n.color);t.beginPath(),t.moveTo(f[0].x,f[0].y);for(const v of f.slice(1))t.lineTo(v.x,v.y);for(const v of[...m].reverse())t.lineTo(v.x,v.y);t.closePath(),t.fillStyle=n.color,t.fill();const g=f[f.length-1],p=m[m.length-1],b=Math.sign(p.x-g.x)||1;t.beginPath(),t.moveTo(g.x-b*a/2,g.y+a*.1),t.lineTo(p.x+b*a/2,p.y+a*.1),t.lineWidth=i,t.strokeStyle=r,t.stroke(),t.restore()}function ZS(t,e,n,s,i){const r=e.length,o=r*.58,a=-r*.62,l=e.width*.82,c=e.width,h=[{x:o+r*.1,y:-l*1.2},{x:o+r*.1,y:-l*.2},{x:a+r*.45,y:c*1.3},{x:a,y:c*1.3}].map(u=>xs(e,u));t.save(),t.beginPath(),Eo(t,e),t.clip(),t.beginPath(),h.forEach((u,d)=>d?t.lineTo(u.x,u.y):t.moveTo(u.x,u.y)),t.closePath(),t.fillStyle=n,t.fill(),t.lineWidth=i,t.lineJoin="round",t.strokeStyle=s,t.stroke(),t.restore(),t.beginPath(),Eo(t,e),t.lineWidth=i,t.strokeStyle=s,t.stroke()}const qm=[.7,.78,.86];function QS(t,e,n,s,i,r,o){const a=Math.atan2(n.y-e.y,n.x-e.x);for(const l of qm){const c=we(e,n,l);Fm(t,c.x,c.y,s*.006,s*.019,a,i,r,o*.55)}}function t3(t,e,n,s,i){const r=n.height,o=n.points,a=i.ink,l=e.outlineWidth*r,c=e.limbWidth*r,h=e.lineWidth*r,u=e.limbs==="line",d=Om(e,n);if(t.save(),s==="spine"){if(t.beginPath(),Eo(t,d),t.fillStyle=e.shirt??e.fill,t.fill(),t.lineWidth=l,t.strokeStyle=a,t.stroke(),e.drape&&ZS(t,d,e.drape,a,l),e.coat){const f=m=>Math.hypot(o[`knee.${m}`].x-o[`hip.${m}`].x,o[`knee.${m}`].y-o[`hip.${m}`].y);US(t,d,e.coat,(f("left")+f("right"))/2,a,l,r)}}else if(s==="neck"){const f=we(o["shoulder.left"],o["shoulder.right"]),m=[f,n.head.center];if(u)Dc(t,m,h,a,e.halo);else{const g=()=>Vt(t,m,c*.9+2*l,a);zi(n,s)?Ao(t,d,f,d.length*.25,g):g(),Vt(t,m,c*.9,e.fill)}}else if(s.startsWith("arm.")){const f=s.slice(4),m=o[`elbow.${f}`],g=GS(o[`shoulder.${f}`],d,(u?h:c)/2+l),p=o[`hand.${f}`],b=qi(g,m,p),v=!u&&zi(n,s),k=e.coat?qi(g,m,we(m,p,.8)):null,w=c*1.7,S=e.shirt,x=!!S&&e.sleeves==="long",M=S&&e.sleeves==="short"?qi(g,we(g,m,.25),we(g,m,.5),4):null,E=c*1.55,T=(k?w:M?E:c)/2+l*2,A=()=>{u||Vt(t,b,c+2*l,a),M&&Vt(t,M,E+2*l,a)};if(u&&!x&&Dc(t,b,h,a,e.halo),u&&x&&Vt(t,b,c+2*l,a),v?Ao(t,d,g,T,A):A(),(!u||x)&&Vt(t,b,c,x?S:e.fill),M&&Vt(t,M,E,S),k){const P=()=>Vt(t,k,w+2*l,a);zi(n,s)?Ao(t,d,g,T,P):P(),Vt(t,k,w,e.coat)}if(e.bangles&&QS(t,m,p,r,e.bangles,a,l),i.hands==="mitten"){const P=Bc(m,p,r);Fm(t,P.x,P.y,P.rx,P.ry,P.angle,e.fill,a,l)}else i.hands==="dot"&&u&&(t.beginPath(),t.arc(p.x,p.y,h*.9,0,Math.PI*2),t.fillStyle=a,t.fill())}else if(s.startsWith("leg.")){const f=s.slice(4),m=o[`hip.${f}`],g=o[`ankle.${f}`],p=e.trousers?c*1.35:u?h:c,b=o[`knee.${f}`],v=Math.hypot(b.x-g.x,b.y-g.y)||1,k=Math.min(v*.4,p/2+l+r*.012),w={x:g.x+(b.x-g.x)/v*k,y:g.y+(b.y-g.y)/v*k},S=qi(m,b,w),x=zi(n,s);if(u&&!e.trousers)Dc(t,S,h,a,e.halo);else{const A=()=>Vt(t,S,p+2*l,a);x?Ao(t,d,m,p/2+l*2,A):A(),Vt(t,S,p,e.trousers??e.fill)}const E=(n.turn%4+4)%4>2?-1:1;VS(t,Lm(o[`ankle.${f}`],o[`toe.${f}`],r,E),r,e.shoes,a,l);const T=`leg.${f==="left"?"right":"left"}`;e.skirt&&(n.parts[s]?.order??0)>=(n.parts[T]?.order??0)&&JS(t,n,e.skirt,c,l,a)}t.restore()}function qc(t,e){const n=(i,r)=>i&&r?(o,a,l,c,h)=>{i(o,a,l,c,h),r(o,a,l,c,h)}:i??r,s={};for(const i of new Set([...Object.keys(t.parts??{}),...Object.keys(e.parts??{})])){const r=t.parts?.[i],o=e.parts?.[i];s[i]={under:n(r?.under,o?.under),clip:n(r?.clip,o?.clip),over:n(r?.over,o?.over)}}return{behind:n(t.behind,e.behind),parts:s,front:n(t.front,e.front)}}function Ps(t={}){if(t.build&&!(t.build in so))throw new Error(`character: unknown build '${t.build}'`);const e=t.build?so[t.build]:{},n=(t.proportions??"bold")==="bold",s=t.figure??"fluid";if(!["fluid","stick","organic","bean"].includes(s))throw new Error(`character: unknown figure '${s}'`);const i=t.height??300,r=s==="stick",o=s==="organic",a=s==="bean",l=a?"clean":t.look??"clean",c=a?Im({...t.outfit?{shirt:t.outfit.shirt,trousers:t.outfit.trousers,...t.outfit.sleeves?{sleeves:t.outfit.sleeves}:{}}:{},...t.lineWidth!==void 0?{outlineWidth:t.lineWidth/i}:{},...t.bean}):void 0,h=t.shoulderWidth??e.shoulderWidth??(o?.07:a?.04:.06),u=o&&t.body?.measurements!==void 0?wg(t.body.measurements):void 0,d=t.hipWidth??u??e.hipWidth??(o?.045:a?.02:.022),f=c?c.outlineWidth*i:t.lineWidth??i*(o?.005:n?.045:.022),m=t.ink??(o?"#53362d":a?"#111111":l==="pencil"?"#2f2f33":"#1e293b"),g=t.skin??(o?"#f1bf98":l==="pencil"?"none":"#ffffff"),p=o?kg(t.body??{},{skin:g,ink:m,lineWidth:f,shoulderWidth:h,hipWidth:d}):void 0;if(t.leafOutfit&&!o)throw new Error("character: leafOutfit requires figure: 'organic'");const b=t.outfit&&!a?Am(t.outfit):null,v=t.holding?xm(t.holding):{};let k=b?qc(b,t.layers??{}):t.layers??{};return t.leafOutfit&&(k=qc(Mm(t.leafOutfit),k)),Object.keys(v).length>0&&(k=qc(k,$m(v))),{plan:t.plan??rc({headSize:t.headSize??e.headSize??(o?.27:n?.3:.24),shoulderWidth:r?0:h,hipWidth:r?0:d,legLength:t.legLength??e.legLength??1,armLength:t.armLength??e.armLength??1,feet:t.feet??e.feet}),figure:s,...p?{body:p}:{},...c?{bean:c}:{},look:l,illustrated:lf(t.illustrated,p?.shading.light),height:i,lineWidth:p?.outline.width??f,ink:p?.outline.color??m,skin:p?.fill??g,seed:t.seed??1,pencil:o?{construction:!1,...t.pencil}:t.pencil??{},layers:k,holding:v,contact:t.contact??"ground",hands:t.hands??(o?"cartoon":a?"mitten":"dot"),handStyle:t.handStyle??(o?"natural":"glove"),handSize:t.handSize??(o?.073:t.handStyle==="natural"?.14:.17),head:lm(t),face:{...o?{style:"anime",projection:"volume",iris:"#66422e",nose:!0}:{},...a?{style:"oval",projection:"volume",...t.bean?.shades?{shades:!0}:{}}:{},...t.face,teeth:t.face?.teeth??a,tongue:t.face?.tongue??a}}}function e3(t,e,n,s){const{point:i,facing:r}=hn(t,[e,n,s]);return{point:i,facing:r}}const jc=t=>t.rest[1]<-.5,n3=.3;function s3(t,e,n){return t.figure==="stick"?jc(e)?n.slice(0,3):n:jc(e)&&n.length>=3?Rn(n[0],n[1],n[2],n3):n.length===3?Rn(n[0],n[1],n[2],1):n}function ji(t,e){const n=t.plan.id==="human"?{...lt,...e}:e;return xo(t,n,lc(t.plan,n,{height:t.height,contact:t.contact}))}function xo(t,e,n){const s={},i={},r={},o=.01*t.height;t.plan.chains.forEach(f=>{const m=n.chains[f.id];s[f.id]=m.points;const g=m.depths.reduce((k,w)=>k+w,0)/m.depths.length,p=f.parent?n.chains[f.parent]:void 0,b=p?p.depths[f.at??p.depths.length-1]:n.hipDepth,v=g-b;r[f.id]=Math.abs(v)<o?0:v,i[f.id]={points:s3(t,f,m.points),depth:g,order:0}}),i.head={points:[n.head.center],depth:n.head.depth,order:0},r.head=0;const a=[...t.plan.chains.map(f=>f.id),"head"],l=f=>t.body&&f.startsWith("arm.")&&r[f]>=0?1:0;let c=[...a].sort((f,m)=>l(f)-l(m)||r[f]-r[m]||a.indexOf(f)-a.indexOf(m));const h={hip:n.hip};for(const[f,[m,g]]of Object.entries(t.plan.landmarks??{})){const p=n.chains[m]?.points;p&&(h[f]=p[Math.min(g,p.length-1)])}const u={};for(const[f,m]of Object.entries(h))u[f]=m.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};if(t.body&&(d.bodyContours=Mg(t.body,d,t.plan)),t.bean&&t.plan.id==="human"){const f={};for(const m of["arm.left","arm.right","leg.left","leg.right"]){const g=n.chains[m]?.depths??[0];f[m]=Math.max(...g.slice(1,3))-g[0]}c=_m(t.bean,d,f)}return c.forEach((f,m)=>{i[f].order=m}),{skeleton:n,joints:d,order:c}}function ke(t,e){return ji(t,e).joints}function jm(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})),r=Array.from({length:13},(l,c)=>({x:-.95+1.9*c/12,y:.12})),o=kt(s,i,{x:0,y:0});o.facing>0&&t.guide(o.points),t.guide(kt(s,r,{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 Km(t,e,n,s,i,r){const o=n.lineWidth;if(n.body&&n.skin==="none"&&(e=vi(t,e)),i==="head"){const{head:f}=s;let m;const g=()=>m??=xg(f,n.face),p=n.skin==="none"?null:n.skin;n.face.projection==="volume"||n.face.shape==="angular"?e.shape(g(),p,o):e.ellipse(f.center.x,f.center.y,f.rx,f.ry,f.angle,p,o),n.body&&n.skin!=="none"&&e.look==="clean"&&pf(t,g(),f.center,n.body.shading),LS(t,e,n.head,f,r,{lineWidth:o,skin:n.skin,face:n.face,faceUnderHair:!!n.body},()=>{e.look!=="silhouette"&&(t.save(),n.body&&(t.beginPath(),g().forEach((b,v)=>v?t.lineTo(b.x,b.y):t.moveTo(b.x,b.y)),t.closePath(),t.clip()),JM(e,f,r,o,{...n.face,skin:n.skin==="none"?"#ffffff":n.skin},t),t.restore())}),n.bean?.fedora&&Bm(t,f,n.bean.fedora,n.ink,o,r["head.turn"]??0);return}const a=n.plan.chains.find(f=>f.id===i),l=s.chains[i],c=s.parts[i].points;if(n.bean&&n.plan.id==="human"){t3(t,n.bean,s,i,{ink:n.ink,hands:n.hands}),n.hands==="cartoon"&&i.startsWith("arm.")&&Kc(t,e,n,l,i.endsWith(".left")?"left":"right",r);return}if(n.body&&Eg(t,e,n.body,s,i)){if(i.startsWith("leg.")&&Eg(t,e,n.body,s,i.replace("leg.","foot.")),i.startsWith("arm."))if(n.hands==="cartoon")Kc(t,e,n,l,i.endsWith(".left")?"left":"right",r);else if(n.hands==="mitten")Xm(e,n,l);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,o)}return}if(n.figure==="stick"){if(i==="neck")return;const f=i==="spine"?[...l,...s.chains.neck?.slice(1)??[]]:c;e.line(f,o);return}const h=(f,m)=>[a.bones[f].width[0]*o,a.bones[m].width[1]*o];if(jc(a)){const[f,m]=h(0,1);if(e.limb(c,f,m),a.bones.length>=3)e.limb([l[2],l[3]],a.bones[2].width[0]*o,a.bones[2].width[1]*o);else if(n.hands==="cartoon"&&i.startsWith("arm."))Kc(t,e,n,l,i.endsWith(".left")?"left":"right",r);else if(n.hands==="mitten"&&i.startsWith("arm."))Xm(e,n,l);else{const g=l[l.length-1];e.dot(g.x,g.y,o*.62)}return}if(i==="spine"){const f=s.points["hip.left"],m=s.points["hip.right"];f&&m&&Math.hypot(f.x-m.x,f.y-m.y)>.5&&e.limb([f,m],o*1.3,o*1.3);const[g,p]=h(0,a.bones.length-1);e.limb(c,g,p);const b=s.points["shoulder.left"],v=s.points["shoulder.right"];b&&v&&Math.hypot(b.x-v.x,b.y-v.y)>.5&&e.limb(Rn(b,l[l.length-1],v,1,10),o*1.15,o*1.15);return}const[u,d]=h(0,a.bones.length-1);e.limb(c,u,d)}function Ym(t,e){const n=`hand.${e}.`,s={};for(const[o,a]of Object.entries(t))o.startsWith(n)&&(s[o.slice(n.length)]=a);const i=t.turn??0,r=e==="right"?1-i:1+i;return{...Ct,...s,turn:r+(s.turn??0)}}function Xm(t,e,n){const s=Bc(n[n.length-2],n[n.length-1],e.height);t.ellipse(s.x,s.y,s.rx,s.ry,s.angle,e.skin==="none"?"#ffffff":e.skin,e.lineWidth*(e.body?1:.45))}function Kc(t,e,n,s,i,r){const o=s[s.length-1],a=s[s.length-2],l=Math.atan2(o.x-a.x,-(o.y-a.y))*180/Math.PI;Yr(t,o,Ym(r,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 Gm(t,e,n,s=0){const i=e.plan.id==="human"?{...lt,...n}:n;Yc(t,e,i,ji(e,i),s)}function Po(t,e){const n=e/t.height;return{...t,height:e,lineWidth:t.lineWidth*n}}function i3(t,e,n,s){const i=t.plan.id==="human"?{...lt,...e}:e,r=lo(t.plan,i,{height:s.height,contact:t.contact},n);return xo(Po(t,r.height),i,r).joints}function r3(t,e,n,s,i){const r=e.plan.id==="human"?{...lt,...n}:n,o=lo(e.plan,r,{height:i.height,contact:e.contact},s),a=Po(e,o.height);Yc(t,a,r,xo(a,r,o),i.time??0)}function Um(t,e,n,s){const i=t.plan.id==="human"?{...lt,...e}:e,r=lo(t.plan,i,{height:s.height,contact:t.contact},n),o=Po(t,r.height),{joints:a,order:l}=xo(o,i,r),c=r.height/s.height,h=l.map(m=>(a.parts[m]?.depth??0)/c),u=l.filter(m=>m==="spine"||m.startsWith("leg.")),d=Math.max(...u.map(m=>a.parts[m].depth/c)),f=Math.max(...u.map(m=>a.parts[m].order));return l.map((m,g)=>({part:m,depth:h[g],...o.body?{sortDepth:m.startsWith("arm.")&&g>f?Math.max(h[g],d):h[g]}:{},draw(p,b=0){const v=ki(p,{look:o.look,ink:o.ink,lineWidth:o.lineWidth,seed:re(`${o.seed}:${m}`),time:b,pencil:o.pencil,illustrated:o.illustrated}),k=S=>{S&&(p.save(),S(p,a,v,b,i),p.restore())};p.save(),p.lineCap="round",p.lineJoin="round",g===0&&(o.look==="pencil"&&o.pencil.construction!==!1&&jm(v,o,a),k(o.layers.behind),dm(p,o.body&&o.skin==="none"?vi(p,v):v,o.head,a.head,i,{lineWidth:o.lineWidth,skin:o.skin,face:o.face}));const w=o.layers.parts?.[m];k(w?.under),p.save(),w?.clip?.(p,a,v,b,i),Km(p,v,o,a,m,i),p.restore(),k(w?.over),m==="head"&&fm(p,v,o.head,a.head,i,{lineWidth:o.lineWidth,skin:o.skin,face:o.face}),g===l.length-1&&k(o.layers.front),p.restore()}}))}function Yc(t,e,n,s,i,r){const{joints:o}=s,a=r?s.order.filter(h=>r.has(h)):s.order,l=ki(t,{look:e.look,ink:e.ink,lineWidth:e.lineWidth,seed:e.seed,time:i,pencil:e.pencil,illustrated:e.illustrated}),c=h=>{h&&(t.save(),h(t,o,l,i,n),t.restore())};t.save(),t.lineCap="round",t.lineJoin="round",!r&&e.look==="pencil"&&e.pencil.construction!==!1&&jm(l,e,o),r||c(e.layers.behind),dm(t,e.body&&e.skin==="none"?vi(t,l):l,e.head,o.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,o,l,i,n),Km(t,l,e,o,h,n),t.restore(),c(u?.over)}fm(t,l,e.head,o.head,n,{lineWidth:e.lineWidth,skin:e.skin}),r||c(e.layers.front),t.restore()}function o3(t,e,n,s){const i=e.plan.id==="human"?{...lt,...n}:n,r=ji(e,i).joints.head.rx,o=Po(e,e.height*s.radius/Math.max(1e-6,r)),a=ji(o,i);t.save(),t.translate(s.x-a.joints.head.center.x,s.y-a.joints.head.center.y),Yc(t,o,i,a,s.time??0,new Set(["head"])),t.restore()}function Xc(t,e,n){const s={...t};for(const[i,r]of Object.entries(e)){const o=t[i]??r;s[i]=o+(r-o)*n}return s}function qe(t,e,n,s){const i=t.plan.id==="human"?{...lt,...e}:e;let r;if(Array.isArray(s))r=s;else{const{skeleton:o}=ji(t,i),a=lc(t.plan,{...i,roll:0},{height:t.height,contact:"none"}),l=(i.roll??0)*Math.PI/180,c=s.x-o.hip.x,h=s.y-o.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),m=s.depth??o.chains[n].depths[o.chains[n].depths.length-1],g=Math.cos(f),p=Math.sin(f);r=[u*g-m*p,-d,u*p+m*g]}return Oi(t.plan,i,n,r,{height:t.height})}const Vm=new Set(["walk","walking","gait"]);function $o(t,e=lt,n){let s={...e};for(const[r,o]of Object.entries(t))typeof o=="number"&&!Vm.has(r)&&(s[r]=o);const i=Math.max(0,Math.min(1,typeof t.walking=="number"?t.walking:0));if(i>0){const r=typeof t.gait=="string"?t.gait:void 0,o=r?n?.[r]??r:void 0,a=vo(o,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 a3(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(r,o,a){r.translate(n/2,s),Gm(r,e,$o(o.props??{},i,t.gaits),a)}}}function Jm(t,e,n){const s=r=>({x:r.x+e,y:r.y+n}),i=r=>Object.fromEntries(Object.entries(r).map(([o,a])=>[o,a.map(s)]));return{...t,...t.bodyContours?{bodyContours:Object.fromEntries(Object.entries(t.bodyContours).map(([r,o])=>[r,{...o,outline:o.outline.map(s),samples:o.samples.map(a=>({...a,center:s(a.center),left:s(a.left),right:s(a.right)}))}]))}:{},points:Object.fromEntries(Object.entries(t.points).map(([r,o])=>[r,s(o)])),chains:i(t.chains),parts:Object.fromEntries(Object.entries(t.parts).map(([r,o])=>[r,{...o,points:o.points.map(s)}])),head:{...t.head,center:s(t.head.center)},groundY:t.groundY+n}}function l3(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 r=0,o=0;for(const[c,h]of e.state?.values.get(n)??[])c==="x"||c==="motionPathX"?r=typeof h=="number"?h:r:c==="y"||c==="motionPathY"?o=typeof h=="number"?h:o:(typeof h=="number"||Vm.has(c))&&(i[c]=h);const a=$o(i,s.plan.id==="human"?lt:{},t.gaits),l=ke(s,a);return{pose:a,joints:Jm(l,t.x+r+t.width/2,t.y+o+t.height)}}function Gc(t,e=lt){const n=[];return t.forEach((s,i)=>{const r=i===0?e:n[i-1],o=typeof s.pose=="string"?Ae[s.pose]:void 0;n.push(o?{...o,turn:r.turn??0}:{...r,...s.pose})}),n}function c3(t,e,n=lt){const s=Gc(e,n);return Object.keys(n).filter(r=>s.some(o=>(o[r]??n[r])!==n[r])).map(r=>({id:`${t}-${r}`,target:t,property:r,keyframes:e.map((o,a)=>({time:o.time,value:s[a][r]??n[r],...o.easing?{easing:o.easing}:{}}))}))}const Io=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Le=(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],Uc=t=>Math.hypot(...t),Zm=t=>Oo(t,1/(Uc(t)||1)),Co=t=>({...lt,...t}),Vc=t=>cn(t.character.plan,Co(t.pose),{height:t.character.height,contact:t.character.contact});function zn(t,e,n){return Io(t.position,Vc(t).chains[e][n])}function Qm(t,e,n){const s=Co(t.pose),i=Vc(t).hip,r=ms(t.character.plan,s,t.character.height),o=Le(Le(n,t.position),i),a=$i(o,(s.roll??0)*Math.PI/180),l=Io(r.root,ee(a,-(s.turn??0)*Math.PI/2));return Oi(t.character.plan,s,e,l,{height:t.character.height})}function tp(t,e,n,s="toe"){const i=`leg.${e}`,r=s==="toe"?3:2;let o={...t,pose:Co(t.pose),position:[...t.position]};for(let l=0;l<6;l++){const c=Vc(o).chains[i],h=Le(c[r],c[2]);o={...o,pose:Qm(o,i,Le(n,h))};const u=zn(o,i,r);o.position[1]+=n[1]-u[1]}const a=Uc(Le(zn(o,i,r),n));return{...o,reached:a<t.character.height*.002}}function ep(t,e){const n=zn(t,`arm.${e}`,2),s=zn(t,`arm.${e}`,1);return Io(n,Oo(Zm(Le(n,s)),t.character.lineWidth*.5))}function h3(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 r=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],o=(c,h)=>{const u=Zm([r[0]-c.position[0],s*.2,r[2]-c.position[2]]),d=Le(r,Oo(u,i));let f=Co(c.pose);for(let g=0;g<6;g++){const p={...c,pose:f},b=zn(p,`arm.${h}`,2);f=Qm(p,`arm.${h}`,Le(d,Le(ep(p,h),b)))}for(const[g,p]of Object.entries(Tt.hold))f[`hand.${h}.${g}`]=p;const m=ep({...c,pose:f},h);return{pose:f,stick:{grip:m,tip:Io(m,Oo(u,i))}}},a=o(t,n.sideA??"right"),l=o(e,n.sideB??"right");return{a:a.pose,b:l.pose,sticks:[a.stick,l.stick],point:r,reached:[a.stick,l.stick].every(c=>Uc(Le(c.tip,r))<s*.002)}}function np(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],r=e.direction??1;if(i.length!==2||!i.every(Number.isFinite)||!Number.isFinite(e.angle??0)||!Number.isFinite(e.spins??0)||![1,-1].includes(r)||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 o=e.character??Ps({height:1.7}),a=e.style??"garba",l=(h,u)=>{const d=(e.angle??0)+360*u/n+r*360*h/s,f=d*Math.PI/180,m=e.facing??"inward",g=(typeof m=="number"?m:d+(m==="inward"?180:m==="tangent"?r*90:0))+(e.spins??0)*360*h/s,p=Ci(a,h,{...e.pose,turn:g/90});return{character:o,position:[i[0]+e.radius*Math.sin(f),0,i[1]+e.radius*Math.cos(f)],pose:p.pose,heading:g,strike:p.strike}},c=Ci(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),m=zn(f,`leg.${c.side}`,3),g=tp(d,c.side,m);return{...d,pose:Xc(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 u3(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)),r=Array.from({length:i+1},(l,c)=>({time:(e.start??0)+e.beats*c/i*6e4/n,members:np(e.beats*c/i,{...e,count:t.length})})),o=r.some(l=>l.members.some(c=>c.pose.roll!==0)),a=new Set(["x","y","z","rotateY",...o?["turn","roll"]:[]]);return t.flatMap((l,c)=>{const h=r.map(u=>{const d=u.members[c],{turn:f,...m}=d.pose;return{time:u.time,pose:{...o?d.pose:m,x:d.position[0],y:d.position[1],z:d.position[2],rotateY:o?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 _o=t=>Math.min(1,Math.max(0,t));function d3(t){const e={...ut,turn:t.view},n=[];for(const s of t.keys){const i=n[n.length-1],r=!i||s.reset?e:i.pose;n.push({at:s.at,pose:{...r,...s.pose},easing:s.easing})}return n}function f3(t){return t-g3*Math.sin(2*Math.PI*t)/(2*Math.PI)}const g3=.5;function m3(t,e){if(!(e<=t.takeoff||e>=t.landing))return(e-t.takeoff)/(t.landing-t.takeoff)}function sp(t,e){const n=typeof t=="string"?Ki[t]:t,s=d3(n),i=_o(e);let r=0;for(let u=0;u<s.length;u++)s[u].at<=i&&(r=u);const o=s[r],a=s[Math.min(r+1,s.length-1)],l=a.at>o.at?(i-o.at)/(a.at-o.at):0,c=gs(o.pose,a.pose,Dt(a.easing??"ease-in-out")(_o(l))),h=m3(n,i);return h===void 0?{...c,spin:0,rise:0}:{...c,spin:n.spin*f3(h),rise:4*n.height*h*(1-h)}}function ip(t,e,n){const s=typeof t=="string"?Ki[t]:t,i=_o(e),r=_o((i-s.takeoff)/(s.landing-s.takeoff));return s.travel*n*r}function p3(t,e,n={}){const s=typeof e=="string"?Ki[e]:e,i=n.start??0,r=n.duration??s.duration,o=n.samples??48,a=Array.from({length:o+1},(h,u)=>{const d=u/o;return{time:i+d*r,progress:d,pose:sp(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*ip(s,u.progress,n.height)}))})}return c}const y3={leftHip:-55,leftKnee:-95,rightHip:55,rightKnee:95,leftShoulder:45,rightShoulder:-45,leftElbow:10,rightElbow:-10,lean:22,stretch:.94,headTilt:6},b3={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},Ro={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},w3={leftHip:-22,leftKnee:-30,rightHip:22,rightKnee:30,leftAnkle:10,rightAnkle:10,leftShoulder:-125,rightShoulder:125,leftElbow:0,rightElbow:0,lean:8,headTilt:0},k3={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 $s(t,e,n,s,i,r=1300){return{label:t,view:1,spin:e,height:n,travel:s,takeoff:.27,landing:.8,duration:r,keys:[{at:0,reset:!0},{at:.16,pose:y3},{at:.27,pose:b3,easing:"ease-out-quad"},...i,{at:.76,pose:w3},{at:.86,pose:k3,easing:"ease-out-quad"},{at:1,reset:!0}]}}const Ki={frontFlip:$s("Front flip (tuck)",360,.56,.35,[{at:.38,pose:Ro,easing:"ease-out-cubic"},{at:.64,pose:Ro}]),backFlip:$s("Back flip (tuck)",-360,.58,-.15,[{at:.36,pose:{...Ro,lean:18},easing:"ease-out-cubic"},{at:.64,pose:{...Ro,lean:18}}]),layout:$s("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:$s("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:$s("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:$s("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 rp(t,e){const n=Math.min(1,Math.max(0,t.turn??0)),s=1-n,i={...lt,turn:n},r=[{stick:"right",human:"left",s:1},{stick:"left",human:"right",s:-1}];for(const{stick:a,human:l,s:c}of r){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`],m=s+c*n;i[`leg.${l}.rotate`]=90*s,i[`leg.${l}.spread`]=0,i[`leg.${l}.swing`]=d*m,i[`leg.${l}.knee`]=f*m,i[`leg.${l}.ankle`]=-(t[`${a}Ankle`]??0),i[`leg.${l}.toeOut`]=(t[`${a}FootOut`]??0)*v3,i[`eye.${l}`]=t[`${a}Eye`],i[`brow.${l}`]=t[`${a}Brow`],e&&Object.assign(i,M3(l,e[a]??Ct,t[`${a}Wrist`]??0,n))}const o=t.bend??0;i.lean=t.lean*n,i.bend=o*n,i.side=(t.lean+o*.5)*s,i["head.tilt"]=(t.headTilt+o*.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 v3=70;function M3(t,e,n,s){const i=t==="right"?1-s:1+s,r={};for(const o of Object.keys(Ct))r[`hand.${t}.${o}`]=e[o]??Ct[o];return r[`hand.${t}.turn`]=(e.turn??0)-i,r[`hand.${t}.roll`]=(e.roll??0)+n,r}class op{positions=[];normals=[];indices=[];vertex(e,n,s,i,r,o){const a=Math.hypot(i,r,o)||1;return this.positions.push(e,n,s),this.normals.push(i/a,r/a,o/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 S3(t){const e=new Map,n=[];for(let i=0;i<t.positions.length/3;i++){const r=[0,1,2].map(o=>Math.round(t.positions[i*3+o]*1e6)).join(",");e.has(r)||e.set(r,i),n.push(e.get(r))}const s=new Map;for(let i=0;i<t.indices.length/3;i++)for(let r=0;r<3;r++){const o=n[t.indices[i*3+r]],a=n[t.indices[i*3+(r+1)%3]];if(o===a)continue;const l=o<a?`${o}-${a}`:`${a}-${o}`,c=s.get(l);c?c.faces.push(i):s.set(l,{a:Math.min(o,a),b:Math.max(o,a),faces:[i]})}return[...s.values()]}const Jc=Math.PI*2;function T3(t,e=16){const n=new op,s=Math.max(6,Math.round(e)),i=Math.max(3,Math.round(s/2)),r=[];for(let o=0;o<=i;o++){const a=o/i*Math.PI,l=[];for(let c=0;c<=s;c++){const h=c/s*Jc,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))}r.push(l)}for(let o=0;o<i;o++)for(let a=0;a<s;a++){const l=r[o][a],c=r[o+1][a],h=r[o+1][a+1],u=r[o][a+1];o>0&&n.triangle(l,c,u),o<i-1&&n.triangle(c,h,u)}return n.build()}function ap(t,e,n,s,i){const r=t.vertex(0,n,0,0,s,0),o=Array.from({length:i},(a,l)=>{const c=l/i*Jc;return t.vertex(Math.sin(c)*e,n,Math.cos(c)*e,0,s,0)});for(let a=0;a<i;a++){const l=o[a],c=o[(a+1)%i];s===1?t.triangle(r,l,c):t.triangle(r,c,l)}}function lp(t,e,n=24){const s=new op,i=Math.max(6,Math.round(n)),r=e/2,o=-e/2,a=h=>Array.from({length:i+1},(u,d)=>{const f=d/i*Jc;return s.vertex(Math.sin(f)*t,h,Math.cos(f)*t,Math.sin(f),0,Math.cos(f))}),l=a(o),c=a(r);for(let h=0;h<i;h++)s.quad(l[h],l[h+1],c[h+1],c[h]);return ap(s,t,r,1,i),ap(s,t,o,-1,i),s.build()}function Ho(t){const e=Array.from({length:t.indices.length/3},()=>[]);for(const n of S3(t))for(const s of n.faces){const i=n.faces.find(r=>r!==s)??-1;e[s].push({a:n.a,b:n.b,across:i})}return{...t,faceEdges:e}}function Zc(t,e,n={}){t.save(),E3(t,e,n),t.restore()}function E3(t,e,n){const s=Qc(e,n);n.shadow!==!1&&th(t,e,n);for(const i of e.under)cp(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 r of i.slice(1))t.lineTo(r.x,r.y);t.closePath()}t.clip("nonzero")}n.rider(t),t.restore()}for(const i of e.over)cp(t,i,s,n)}function cp(t,e,n,s){const i=s.loose?.[e.part.id];if(!i){sh(t,e,n,s);return}if(i.opacity<=0)return;const r=e.faces.flatMap(c=>c.points);if(r.length===0)return;const o=r.map(c=>c.x),a=r.map(c=>c.y),l={x:(Math.min(...o)+Math.max(...o))/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),sh(t,e,n,s),t.restore()}function Qc(t,e={}){return e.lineWidth??Math.max(1.3,t.sizePx*.022)}function th(t,e,n={}){e.shadow.opacity<=0||e.shadow.points.length<3||(t.save(),t.globalAlpha=e.shadow.opacity,Fo(t,e.shadow.points,n.ink??"#26262b",!1),t.restore())}function A3(t,e,n,s={}){t.save(),sh(t,e,n,s),t.restore()}function hp(t,e,n,s={}){const i=s.style==="stick",r=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}))}),o=new Map;for(const h of r){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);o.set(f,[...o.get(f)??[],h])}for(const h of o.values())for(const u of h){const{center:d,normal:f}=u.face;for(const m of h){if(m.part.part.id===u.part.part.id)continue;const g=m.face;if(g.normal[0]*f[0]+g.normal[1]*f[1]+g.normal[2]*f[2]<=.8)continue;const b=g.normal[0]*(d[0]-g.center[0])+g.normal[1]*(d[1]-g.center[1])+g.normal[2]*(d[2]-g.center[2]);b>-up/5&&b<up&&(u.layer=Math.max(u.layer,m.layer),u.depth=Math.max(u.depth,m.depth+1e-6))}}r.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=eh(t,h,n,s)),u};t.save();const c=t.globalAlpha;for(const{part:h,face:u}of r){t.globalAlpha=c*h.opacity;const d=l(h);if(!u)d.line(h.spine,n*1.15);else{const f=i?dp(h,s):u.light?x3(h,u,s):nh(h);f&&(!i&&s.look==="silhouette"?d.shape(u.points,f,0):Fo(t,u.points,i||u.light?f:Lo(f,u.tone),!0,h.cut?1.6:.8));const m=(h.part.outline??1)*n;if(m>0)for(const g of u.edges??[])g.length>1&&d.line(g,m);for(const g of u.marks??[])d.line(g,n*.7)}}t.restore()}const up=.05;function eh(t,e,n,s){return ki(t,{look:s.look??"clean",ink:e.part.ink??s.ink??"#26262b",lineWidth:n,seed:re(`${s.seed??0}:${e.part.id}`),time:s.time??0,pencil:{construction:!1,rubbedOut:0,...s.pencil}})}function nh(t){const{part:e}=t;return e.glow&&t.glow>0&&e.fill?oh(e.fill,e.glow.color,t.glow):e.fill}function x3(t,e,n){const{part:s}=t;if(!s.fill)return;const i=rh(s.fill,e.light,e.fog??0,n.fog);return s.glow&&t.glow>0?oh(i,s.glow.color,t.glow):i}function dp(t,e){const n=nh(t);return n&&($3(n)||t.glow>0)?n:e.paper??"#fbf8ef"}function sh(t,e,n,s){e.opacity<1?(t.save(),t.globalAlpha*=e.opacity,fp(t,e,n,s),t.restore()):fp(t,e,n,s)}function fp(t,e,n,s){if(s.style==="stick")return P3(t,e,n,s);const{part:i}=e,r=eh(t,e,n,s),o=nh(e),a=s.look==="silhouette";for(const c of e.faces)o&&(a?r.shape(c.points,o,0):Fo(t,c.points,Lo(o,c.tone)));const l=(i.outline??1)*n;if(l>0)for(const c of e.edges)c.length>1&&r.line(c,l);for(const c of e.marks)r.line(c,n*.7)}function P3(t,e,n,s){const{part:i}=e;if(i.solidOnly)return;const r=eh(t,e,n,s);if(e.spine){r.line(e.spine,n*1.15);return}const o=dp(e,s);for(const l of e.faces)Fo(t,l.points,o);const a=(i.outline??1)*n;if(a>0)for(const l of e.edges)l.length>1&&r.line(l,a);for(const l of e.marks)r.line(l,n*.7)}function $3(t){const e=Is(t);return e?(.299*e[0]+.587*e[1]+.114*e[2])/255<.3:!1}function Fo(t,e,n,s=!0,i=.8){t.fillStyle=n,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let r=1;r<e.length;r++)t.lineTo(e[r].x,e[r].y);t.closePath(),t.fill(),s&&(t.strokeStyle=n,t.lineWidth=i,t.lineJoin="round",t.stroke())}function Is(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 ih=t=>`#${t.map(e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0")).join("")}`;function Lo(t,e){const n=Is(t);return n?ih(e>=1?n.map(s=>s+(255-s)*(e-1)*2):n.map(s=>s*e)):t}function rh(t,e,n,s){const i=Is(t);if(!i)return t;let r=i.map((a,l)=>a*e[l]);const o=s?Is(s):void 0;return o&&n>0&&(r=r.map((a,l)=>a+(o[l]-a)*n)),ih(r)}function oh(t,e,n){const s=Is(t),i=Is(e);return!s||!i?n<.5?t:e:ih(s.map((r,o)=>r+(i[o]-r)*n))}const I3=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),O3=new Set(["walk","walking","gait"]),gp=t=>typeof t=="number"?t:void 0,C3=1.7;function _3(t,e,n){const s=Array.from({length:24},(i,r)=>{const o=r/24*Math.PI*2,a=e.toView([Math.cos(o)*n,0,Math.sin(o)*n*.8]);return a[2]<-.001?e.toScreen(a):null});s.some(i=>i===null)||(t.beginPath(),s.forEach((i,r)=>r===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 R3(t){const e=We([0,1,0],t);if(e>.999999)return Or();if(e<-.999999)return Te(Zt([1,0,0],180));const n=hi([0,1,0],t);return Te(Zt(n,Math.acos(e)*180/Math.PI))}function H3(t,e,n,s,i){const r=t.solid??{},o=r.outline===!1?void 0:r.outline??{width:2,color:"#0f172a"},a={color:r.color??"#475569",shading:r.shading??"toon",outline:o},l={color:r.skin??"#f2c49b",shading:r.shading??"toon",outline:o},c={color:"#0f172a",shading:"unlit"},h=s.height*.034,u=[],d=(k,w,S)=>u.push({mesh:k,world:Ft(i,w),material:S}),f=(k,w,S)=>d(e.sphere,al(k,[0,0,0,1],[w,w,w]),S);for(const k of n.chains){const w=s.chains[k.id],S=k.id==="spine"?1.9:1;k.bones.forEach((x,M)=>{const E=w[M],T=w[M+1],A=ui(E,T),[P,I]=x.width??[1,1],O=h*S*(P+I)/2;if(A>1e-6){const _=$n(E,T,.5),L=R3(Qt(oe(T,E)));d(e.cylinder,Ft(In(_),Ft(L,On([O,A,O]))),a)}f(E,h*S*P,a),f(T,h*S*I,a)}),k.id.startsWith("arm.")&&f(w[w.length-1],h*1.5,l)}const{center:m,rx:g,ry:p,axes:b}=s.head,v=[...b[0],0,...b[1],0,...b[2],0,...m,1];d(e.sphere,Ft(v,On([g,p,g])),l);for(const k of[-1,1]){const w=Qt([k*.36,.15,.92]),S=ci(m,ci(ci(Pn(b[0],w[0]*g*1.04),Pn(b[1],w[1]*p*1.04)),Pn(b[2],w[2]*g*1.04))),x=[...b[0],0,...b[1],0,...b[2],0,...S,1];d(e.sphere,Ft(x,On([g*.11,p*.14,g*.03])),c)}return u}const F3={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:Ps({...t.character,height:1}),cylinder:Ho(lp(1,1,16)),sphere:Ho(T3(1,20))}},resolve({object:t,prepared:e,values:n,world:s,camera:i,lights:r=[],fog:o,toScreen:a}){const l=t,c=e,h=c.who;let u={...lt,...l.pose};for(const[E,T]of n)typeof T=="number"&&!I3.has(E)&&!O3.has(E)&&(u[E]=T);const d=Math.max(0,Math.min(1,gp(n.get("walking"))??l.walking??0));if(d>0){const E=typeof n.get("gait")=="string"?n.get("gait"):l.gait,T=vo(E,gp(n.get("walk"))??0,u);u=Object.fromEntries(Object.keys({...u,...T}).map(A=>[A,(u[A]??0)+((T[A]??0)-(u[A]??0))*d]))}const f=l.height??C3,m=Ft(i.view,s),g={toView:E=>ae(m,E),toScreen:E=>a(E)},b=-g.toView([0,f/2,0])[2];if(b<=i.near)return null;const v=l.shadow===!1?[]:[{depth:b+f,draw:E=>_3(E,g,f*.18)}];if(l.look==="solid"){const E=cn(h.plan,u,{height:f,contact:h.contact});return{meshes:H3(l,c,h.plan,E,s),drawables:v}}const k=ae(s,[0,f*.6,0]),w=Qt(oe(i.position,k)),S=rf(k,w,r).map(E=>Math.min(1,E));let x=h;if(r.length>0&&h.skin!=="none"){const E=rh(h.skin,S,of(o,ui(k,i.position)),o?.color);x={...h,skin:E,...h.body?{body:{...h.body,fill:E}}:{}}}const M=Um(x,u,g,{height:f});return{drawables:[...v,...M.map((E,T)=>({depth:-(E.sortDepth??E.depth)-T*1e-6,draw:(A,P)=>E.draw(A,P.time)}))]}}},dn={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}},Yi=1,No=.55,mp=.35,L3=1.6,pp={a:"a",e:"e",i:"i",y:"i",o:"o",u:"u"},yp={m:"m",b:"m",p:"m",f:"f",v:"f",w:"u",q:"u",l:"l",n:"l",d:"l",t:"l"},bp={अ:"a",आ:"a",इ:"i",ई:"i",उ:"u",ऊ:"u",ऋ:"i",ए:"e",ऐ:"e",ओ:"o",औ:"o",ऍ:"e",ऑ:"o"},wp={"ा":"a","ि":"i","ी":"i","ु":"u","ू":"u","ृ":"i","े":"e","ै":"e","ो":"o","ौ":"o","ॅ":"e","ॉ":"o"},N3={प:"m",फ:"m",ब:"m",भ:"m",म:"m",व:"u"},W3="्",kp="़",D3=t=>t>="क"&&t<="ह",vp=new Set([".",",","!","?",";",":","…","।","॥","—","-"]);function Mp(t){const e=[],n=Array.from(t.toLowerCase()),s=(i,r)=>{const o=e[e.length-1];o&&o.viseme===i?o.weight+=r*.5:e.push({viseme:i,weight:r})};for(let i=0;i<n.length;i++){const r=n[i],o=n[i+1];if(vp.has(r))s("rest",L3);else if(/\s/.test(r)){const a=e[e.length-1];a&&a.viseme!=="rest"&&e.push({viseme:"c",weight:mp})}else if((r==="o"||r==="e")&&o===r)s(r==="o"?"u":"i",Yi),i++;else if(r in pp)s(pp[r],Yi);else if(r in yp)s(yp[r],No);else{if(r==="h")continue;if(/[a-z]/.test(r))s("c",No);else if(r in bp)s(bp[r],Yi);else if(D3(r)){const a=o===kp?r==="फ"?"f":void 0:N3[r];s(a??"c",No);let l=i+1;n[l]===kp&&l++;const c=n[l];c===W3?i=l:c&&c in wp?(s(wp[c],Yi),i=l):(!c||/\s/.test(c)||vp.has(c)||s("a",Yi*.6),i=l-1)}else(r==="ं"||r==="ँ")&&s("l",No*.6)}}for(;e.length>0&&(e[e.length-1].viseme==="rest"||e[e.length-1].weight===mp);)e.pop();return e}function ah(t,e={}){const n=e.fields?.mouth??"mouth",s=e.fields?.mouthWidth??"mouthWidth",i=e.energy??1,r=Mp(t.text),o=[{time:t.start,value:dn.rest.mouth}],a=[{time:t.start,value:dn.rest.mouthWidth}],l=r.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 r){const d=c*u.weight/l,f=h+Math.min(d*.4,60);if(f>o[o.length-1].time){const m=dn[u.viseme];o.push({time:f,value:m.mouth*i,easing:"ease-out"}),a.push({time:f,value:1+(m.mouthWidth-1)*Math.min(1.3,i),easing:"ease-out"})}h+=d}}return t.end>o[o.length-1].time&&(o.push({time:t.end,value:dn.rest.mouth,easing:"ease-in-out"}),a.push({time:t.end,value:dn.rest.mouthWidth,easing:"ease-in-out"})),{[n]:o,[s]:a}}function B3(t,e,n={}){const s={};for(const i of[...e].sort((r,o)=>r.start-o.start))for(const[r,o]of Object.entries(ah(i,n))){const a=s[r]??=[],l=a.length>0?a[a.length-1].time:-1/0;a.push(...o.filter(c=>c.time>l))}return Object.entries(s).map(([i,r])=>({id:`${t}-${i}`,target:t,property:i,keyframes:r}))}function Wo(t,e,n,s={}){if(n.length===0)return e;const i=s.fields?.mouth??"mouth",r=s.fields?.mouthWidth??"mouthWidth",o={[i]:dn.rest.mouth,[r]:dn.rest.mouthWidth,...s.rest},a=new Ht({id:"before-speech",tracks:e}),l=(u,d)=>a.getStateAtTime(d).values.get(t)?.get(u)??o[u],c=[i,r],h=e.filter(u=>u.target!==t||!c.includes(u.property));for(const u of c){const d=e.find(m=>m.target===t&&m.property===u);let f=d?[...d.keyframes]:[{time:0,value:l(u,0)}];for(const m of n){const g=ah(m,s)[u];g[0]={...g[0],value:l(u,m.start)},g[g.length-1]={...g[g.length-1],value:l(u,m.end)},f=[...f.filter(p=>p.time<m.start||p.time>m.end),...g],f.sort((p,b)=>p.time-b.time)}h.push({id:d?.id??`${t}-${u}`,target:t,property:u,keyframes:f})}return h}const Xi=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function Sp([t,e,n]){const[s,i,r]=[t/2,e/2,n/2];return{vertices:[[-s,-i,-r],[s,-i,-r],[s,i,-r],[-s,i,-r],[-s,-i,r],[s,-i,r],[s,i,r],[-s,i,r]],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 Os=(t,[e,n,s])=>t==="z"?[e,n,s]:t==="x"?[s,n,e]:[e,s,n];function Tp(t,e,n="x",s=20,i=0){const r=[],o=e/2;for(const c of[-o,o])for(let h=0;h<s;h++){const u=Math.PI*2*h/s;r.push(Os(n,[Math.cos(u)*t,Math.sin(u)*t,c]))}const a=[{corners:Array.from({length:s},(c,h)=>s-1-h),normal:Os(n,[0,0,-1])},{corners:Array.from({length:s},(c,h)=>s+h),normal:Os(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:Os(n,[Math.cos(u),Math.sin(u),0])})}const l=[];if(i>0)for(const c of[-o,o]){const h=r.push(Os(n,[0,0,c*1.01]))-1;for(let u=0;u<i;u++){const d=Math.PI*2*u/i,f=r.push(Os(n,[Math.cos(d)*t*.82,Math.sin(d)*t*.82,c*1.01]))-1;l.push([h,f])}}return{vertices:r,faces:a,marks:l,creases:!0}}function Ep([t,e,n],s=16){const i=Math.max(4,Math.round(s/2)),r=[[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;r.push([Math.sin(u)*Math.cos(f)*t,Math.cos(u)*e,Math.sin(u)*Math.sin(f)*n])}}const o=r.push([0,-e,0])-1,a=(h,u)=>1+(h-1)*s+u%s,l=h=>{const u=h.reduce((d,f)=>[d[0]+r[f][0],d[1]+r[f][1],d[2]+r[f][2]],[0,0,0]);return Xi([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 m=[a(f,h),a(f,h+1),a(f+1,h+1),a(f+1,h)];c.push({corners:m,normal:l(m)})}const d=[a(i-1,h),a(i-1,h+1),o];c.push({corners:d,normal:l(d)})}return{vertices:r,faces:c,creases:!1}}const z3=t=>t.reduce((e,[n,s],i)=>{const[r,o]=t[(i+1)%t.length];return e+n*o-r*s},0)/2;function Ap(t,e){const n=z3(t)<0?[...t].reverse():t,s=n.length,i=e/2,r=[...n.map(([a,l])=>[i,l,a]),...n.map(([a,l])=>[-i,l,a])],o=[{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]];o.push({corners:[a,l,s+l,s+a],normal:Xi([0,-c,h])})}return{vertices:r,faces:o,creases:!0}}function xp(t,e){const n={left:([i,r])=>[0,r,i],right:([i,r])=>[0,r,i],front:([i,r])=>[i,r,0],back:([i,r])=>[i,r,0],up:([i,r])=>[i,0,r]},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,r)=>r),normal:s[e]}]}}function Pp(t,e,n=8){const s=o=>Array.isArray(e)?e[Math.min(o,e.length-1)]:e,i=[],r=[];t.forEach((o,a)=>{const l=t[Math.min(a+1,t.length-1)],c=t[Math.max(a-1,0)],h=Xi([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=Xi($p(h,u)),f=$p(d,h);for(let m=0;m<n;m++){const g=Math.PI*2*m/n,p=Math.cos(g)*s(a),b=Math.sin(g)*s(a);i.push([o[0]+d[0]*p+f[0]*b,o[1]+d[1]*p+f[1]*b,o[2]+d[2]*p+f[2]*b])}});for(let o=0;o<t.length-1;o++)for(let a=0;a<n;a++){const l=(a+1)%n,c=[o*n+a,o*n+l,(o+1)*n+l,(o+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[o][0]+t[o+1][0])/2,(t[o][1]+t[o+1][1])/2,(t[o][2]+t[o+1][2])/2];r.push({corners:c,normal:Xi([h[0]-u[0],h[1]-u[1],h[2]-u[2]])})}return{vertices:i,faces:r,creases:!1}}function $p(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 Ip(t){switch(t.type){case"box":return Sp(t.size);case"cylinder":return Tp(t.radius,t.length,t.axis,t.segments,t.spokes);case"ellipsoid":return Ep(t.radii,t.segments);case"extrude":return Ap(t.profile,t.width);case"panel":return xp(t.points,t.facing);case"tube":return{...Pp(t.points,t.radius,t.segments),joined:t.joined}}}function lh(t,e){if(t.length<2)return t;const n=i=>t[Math.max(0,Math.min(t.length-1,i))],s=i=>{const r=i*(t.length-1),o=Math.min(t.length-2,Math.floor(r)),a=r-o,[l,c,h,u]=[n(o-1),n(o),n(o+1),n(o+2)];return[0,1,2].map(d=>{const f=l[d],m=c[d],g=h[d],p=u[d];return .5*(2*m+(-f+g)*a+(2*f-5*m+4*g-p)*a*a+(-f+3*m-3*g+p)*a*a*a)})};return Array.from({length:e},(i,r)=>s(r/(e-1)))}const qn=t=>Array.isArray(t)&&t.length===2&&t.every(e=>typeof e=="number"&&Number.isFinite(e));function Do(t,e){return((e-t)%360+540)%360-180}function Op(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 Cs(t,e){return Math.atan2(e[0]-t[0],e[1]-t[1])*180/Math.PI}function Cp(t){const e=t.filter((i,r)=>r===0||Math.hypot(i[0]-t[r-1][0],i[1]-t[r-1][1])>1e-6);if(e.length<2)return[];const n=e.length===2?e:lh(e.map(([i,r])=>[i,0,r]),(e.length-1)*12).map(([i,,r])=>[i,r]);let s=0;return n.map((i,r)=>(r>0&&(s+=Math.hypot(i[0]-n[r-1][0],i[1]-n[r-1][1])),{point:i,at:s}))}function _p(t,e){let n=1;for(;n<t.length-1&&t[n].at<e;)n++;const s=t[n-1],i=t[n],r=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])*r,s.point[1]+(i.point[1]-s.point[1])*r],direction:[i.point[0]-s.point[0],i.point[1]-s.point[1]]}}function Rp(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 r=(n+s)/2;t(r)<e?n=r:s=r}return(n+s)/2}const Gi=520,ch=["do","at","for","to","through","toward","speed","pose","gag","say","look","turns","dance","bpm","beats"],Hp=t=>Math.max(700,Array.from(t).length*65),Fp=70,Lp=35;function hh(t,e){const n=e[0]-t.x,s=e[1]-t.eyeHeight,i=e[2]-t.z,r=t.heading*Math.PI/180,o=n*Math.cos(r)-i*Math.sin(r),a=n*Math.sin(r)+i*Math.cos(r),l=Math.atan2(o,a)*180/Math.PI,c=Math.hypot(o,a),h=-Math.atan2(s,c)*180/Math.PI,u=Math.max(-Fp,Math.min(Fp,l*.75)),d=Math.max(-Lp,Math.min(Lp,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 Np={walk:1.3,bouncy:1.4,doubleBounce:1.2,sneak:.6,strut:1.2,tired:.8,run:3.6,shove:.7},uh=Object.keys(Gt),dh=Object.keys(Ae),fh=Object.keys(So),q3=.25,j3=700/180,K3=200,Y3=300;function Wp(t){if(!Array.isArray(t))return[{beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const e=[...uh,"face","spin","dance","hold","pose","gag","place","say","look"],n=[];return t.forEach((s,i)=>{const r=c=>n.push({beat:i,message:c});if(!s||typeof s!="object"||Array.isArray(s))return r("Each beat must be an object like { do: 'walk', to: [x, z] }.");const o=s,a={duration:"for",path:"through",position:"to",heading:"toward",direction:"toward"};for(const c of Object.keys(o))ch.includes(c)||r(dt("beat field",c,ch,a[c]));const l=typeof o.do=="string"?dh.includes(o.do)?"pose":fh.includes(o.do)?"gag":o.do==="turn"?"face":void 0:void 0;if(typeof o.do!="string"||!e.includes(o.do))return r(dt("character 3D beat",o.do,e,l));for(const c of["at","for","turns","bpm","beats"]){const h=o[c];h!==void 0&&(typeof h!="number"||!Number.isFinite(h)||(c==="at"?h<0:c!=="turns"&&h<=0))&&r(`\`${c}\` must be finite${c==="turns"?"":c==="at"?" and non-negative":" and positive"}.`)}if(o.do==="dance"&&!(typeof o.dance=="string"&&Object.hasOwn(Nn,o.dance))&&r(dt("native dance",o.dance,Object.keys(Nn))),uh.includes(o.do)&&(o.to===void 0&&o.through===void 0&&r(`\`${o.do}\` needs \`to\` ([x, z] metres) or \`through\` (a list of them).`),o.to!==void 0&&!qn(o.to)&&r(`\`to\` is a point on the ground, [x, z] metres (got ${JSON.stringify(o.to)}).`),o.through!==void 0&&!(Array.isArray(o.through)&&o.through.length>0&&o.through.every(qn))&&r("`through` is a list of points on the ground, each [x, z] metres.")),o.do==="place"&&!qn(o.to)&&r("`place` needs `to`: a point on the ground, [x, z] metres."),o.do==="face"&&!(qn(o.toward)||typeof o.toward=="number"&&Number.isFinite(o.toward))&&r("`face` needs `toward`: a point [x, z] or a finite heading in degrees."),o.do==="say"&&!(typeof o.say=="string"&&o.say.trim().length>0)&&r("`say` needs `say`: the line spoken."),o.do==="look"){const c=o.look??o.toward;Array.isArray(c)&&(c.length===2||c.length===3)&&c.every(u=>typeof u=="number"&&Number.isFinite(u))||c==="camera"||r("`look` needs `look`: a point [x, z] or [x, y, z] to look at, or `camera`.")}o.do==="pose"&&!(typeof o.pose=="object"&&o.pose!==null)&&!dh.includes(o.pose)&&r(dt("pose",o.pose,dh)),o.do==="gag"&&!fh.includes(o.gag)&&r(dt("gag",o.gag,fh))}),n}function X3(t,e,n){const s=Wp(e);if(s.length>0)throw new Error(`characterScript3D: ${s.length} problem(s) in the beats:
|
|
53
|
+
`;function O5(t){if(t.getElementById(Yd))return;const e=t.createElement("style");e.id=Yd,e.textContent=I5,t.head.appendChild(e)}function Xd(t,e){const n=Array.from(e.querySelectorAll("[data-tinyfly-choose]"));if(n.length===0)return()=>{};O5(e.ownerDocument);const s=[],i=[];for(const a of n){const l=a.getAttribute("data-tinyfly-choose")??"",c=[],h=(m,g)=>{a.hasAttribute(m)||(a.setAttribute(m,g),c.push(m))};h("role","button"),h("tabindex","0");const u=t.scenarios.find(m=>m.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=m=>{const g=m.key;g!=="Enter"&&g!==" "||(m.preventDefault(),d())};a.addEventListener("click",d),a.addEventListener("keydown",f),i.push(()=>{a.removeEventListener("click",d),a.removeEventListener("keydown",f)})}const r=()=>{for(const{element:a}of s)a.setAttribute("aria-pressed",String(a.getAttribute("data-tinyfly-choose")===t.scenario))},o=t.subscribe(r);return r(),()=>{o();for(const a of i)a();for(const{element:a,attributes:l}of s)for(const c of l)a.removeAttribute(c)}}const Nr=new WeakMap,Ol=new WeakMap;let C5=0;function yi(t,e,n){if(t)try{return JSON.parse(t)}catch(s){console.warn(`tinyfly: invalid ${e} JSON on`,n,s);return}}async function Gd(t,e={}){const n=Nr.get(t);if(n)return n;const s=Array.from(t.querySelectorAll("script[data-tinyfly-timeline]")),i=s[0],r=t.getAttribute("data-src"),o=R5(t.getAttribute("data-markers")),a=s.length>1||i?.hasAttribute("data-scenario")?_5(s,o,t):void 0;if(a&&a.length===0)return;let l=i&&!a?yi(i.textContent,"timeline",t):void 0;if(!l&&r&&o){const f=await fetch(r);f.ok&&(l=await f.json())}if(l&&o&&(l=Ud(l,o)),!l&&!r&&!a){console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)',t);return}const c=yi(t.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",t),h={playWhenVisible:!0,...e.player,...c&&{captions:c},...yi(t.getAttribute("data-options"),"data-options",t)};F5(t);const u=new Lr(t,h),d={element:t,player:u};if(Nr.set(t,d),t.setAttribute("data-tinyfly-mounted",""),a){const f=t.getAttribute("data-scenario")??void 0;await u.loadScenarios(a,{initial:a.some(m=>m.id===f)?f:void 0}),Ol.set(t,Xd(u,t))}else await u.load(l??r);if(t.getAttribute("data-controls")!=="false"){const f=yi(t.getAttribute("data-labels"),"data-labels",t),m=t.querySelector("figcaption"),g=t.getAttribute("data-scenario-legend"),p=t.getAttribute("data-scenario-control");d.controls=Kd(u,t,{...e.controls,...t.getAttribute("data-fullscreen")==="true"?{fullscreen:!0}:{},...p==="slider"||p==="buttons"?{scenarioControl:p}:{},labels:{...e.controls?.labels,...f,...g?{scenario:g}:{}},mount:void 0}),m?t.insertBefore(d.controls.element,m):t.appendChild(d.controls.element)}return d}function _5(t,e,n){const s=[];return t.forEach((i,r)=>{const o=yi(i.textContent,"timeline",n);if(!o)return;const a=i.getAttribute("data-scenario")||`scenario-${r+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?Ud(o,e):o})}),s}function Ud(t,e){return t.config.markers?.length?t:{...t,config:{...t.config,markers:e.map((n,s)=>({id:`step-${s+1}`,time:n}))}}}function R5(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 Vd(t=document,e={}){const n=Array.from(t.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(n.map(i=>Gd(i,e)))).filter(i=>i!==void 0)}function H5(t){const e=Nr.get(t);e&&(Ol.get(t)?.(),Ol.delete(t),e.controls?.destroy(),e.player.destroy(),Nr.delete(t),t.removeAttribute("data-tinyfly-mounted"))}function F5(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-${++C5}`,e.setAttribute("aria-labelledby",s.id))}function L5(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const e=()=>{Vd()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}class Jd{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 _n,this.adapterB=new _n}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 r of e.elements){if(!r.html)continue;const o=document.createElement("div");o.innerHTML=r.html.trim();const a=o.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 r=i.getAttribute("data-tinyfly-symbol");if(!r)return;const o=this.symbolDefs.get(r);if(!o)return;const a=new _n;i.querySelectorAll("[data-tinyfly]").forEach(l=>{const c=l.getAttribute("data-tinyfly");c&&a.registerTarget(c,l)}),s.push({adapter:a,timeline:as(o)})}),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 r=i.timeline.duration;i.adapter.applyState(i.timeline.getStateAtTime(r>0?n%r:n))}}clearContainer(e){e.innerHTML=""}createTimeline(e){return e.timeline?as(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 N5(t,e,n={}){const s=new Jd(t,{...n,autoplay:!0});return await s.load(e),s}const W5={type:"none",duration:0},Lt=t=>({description:t,unit:"degrees"}),Pt=(t,e=0,n=1)=>({description:t,unit:`${e}..${n}`,min:e,max:n}),Zd={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:Pt("Left foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),rightFootOut:Pt("Right foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),mouth:Pt("Mouth open: 0 closed, 1 wide open"),smile:Pt("−1 frown, 0 flat, 1 smile",-1,1),mouthWidth:{description:"Mouth width: 1 normal, 0.5 pursed, 1.5 wide",unit:"factor",min:.3,max:2},blink:Pt("Eyes closed by a blink: 0 open, 1 shut"),leftEye:{description:"Left eye openness: 0 shut, 1 normal, 1.6 wide",unit:"factor",min:0,max:2},rightEye:{description:"Right eye openness: 0 shut, 1 normal, 1.6 wide",unit:"factor",min:0,max:2},leftBrow:Pt("Left eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),rightBrow:Pt("Right eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),browTilt:Pt("Eyebrow slant: −1 angry, 1 worried",-1,1),lookX:Pt("Eyes look across: + the way it faces",-1,1),lookY:Pt("Eyes look down (+) or up (−)",-1,1),stretch:{description:"Squash and stretch: 1 normal, above taller (a jump), below squashed (a landing)",unit:"factor",min:.3,max:3},turn:Pt("0 front-on, 1 in profile, turned the way it faces"),sit:Pt("0 standing, 1 seated"),spin: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"}},Qd={walk:{description:"Walk-cycle phase, in strides: animate 0 → n for n strides",unit:"strides"},walking:Pt("How much of the walk cycle is applied (0 standing)"),gait:{description:"How it walks: a gait name (walk, bouncy, doubleBounce, sneak, strut, tired, run, shove); a string track switches it",kind:"string"},talk:Pt("How much the mouth chatters"),rubber:Pt("Limbs from jointed (0) to rubber hose (1)"),facing:{description:"Which way it faces: 1 right, −1 left (key the flip while turn is near 0)",unit:"±1",min:-1,max:1},beat:{description:"Beats into its dance (with a dance)",unit:"beats"},dancing:Pt("How much of the dance is applied")},tf={"thumb.curl":Pt("Thumb curled in"),"thumb.across":Pt("Thumb across the palm"),"index.curl":Pt("Index finger curled"),"middle.curl":Pt("Middle finger curled"),"ring.curl":Pt("Ring finger curled"),"pinky.curl":Pt("Little finger curled"),spread:Pt("Fingers spread apart"),turn: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 ef;function D5(t){ef=t}function B5(t){return ef?.(t)??{}}function Cl(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 sn(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=Cl(t)*n;const i=[t[0]];for(let r=1;r<t.length;r++){const o=t[r-1],a=t[r],l=Math.hypot(a.x-o.x,a.y-o.y);if(l>=s){const c=l===0?0:s/l;return i.push({x:o.x+(a.x-o.x)*c,y:o.y+(a.y-o.y)*c}),i}i.push(a),s-=l}return i}function Wr(t,e){const n=sn(t,e);return n[n.length-1]}function _l(t,e){return e>0?Math.floor(Math.max(0,t)*e/1e3):0}function Dr(t,e,n){const s=e.roughness??2,i=Math.max(1,Math.round(e.passes??2)),r=_l(n,e.boil??8);let o=0;const a=()=>{const d=o++;return f=>Se(re(`${e.seed??1}:${r}:${d}:${f}`))},l=(d,f)=>(d.next()*2-1)*f,c=d=>{const f=a(),m=t.lineWidth,g=t.globalAlpha;for(let p=0;p<i;p++)t.lineWidth=p===0?m:m*.55,t.globalAlpha=p===0?g:g*.6,d(f(p));t.lineWidth=m,t.globalAlpha=g},h=(d,f=1)=>{if(d.length<2)return;const m=d.slice(1).map((p,y)=>Math.hypot(p.x-d[y].x,p.y-d[y].y)),g=m.reduce((p,y)=>p+y,0)*Math.min(1,Math.max(0,f));c(p=>{const y=[],v=[];if(d.forEach((k,S)=>{y.push({x:k.x+l(p,s*.5),y:k.y+l(p,s*.5)}),S>0&&v.push([p.next()*2-1,p.next()*2-1])}),g<=0)return;t.beginPath(),t.moveTo(y[0].x,y[0].y);let w=0;for(let k=1;k<y.length;k++){const S=z5(y[k-1],y[k],s,v[k-1]),x=m[k-1];if(w+x<=g){t.bezierCurveTo(S[1].x,S[1].y,S[2].x,S[2].y,S[3].x,S[3].y),w+=x;continue}const M=q5(S,x===0?1:(g-w)/x);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,m,g,p=1)=>{c(y=>{const w=y.next()*Math.PI*2,k=Math.PI*2+.15+y.next()*.3,S=[];for(let M=0;M<=14;M++){const E=w+k*M/14,T=l(y,s*.6);S.push({x:d+Math.cos(E)*(m+T),y:f+Math.sin(E)*(g+T)})}const x=sn(S,p);x.length<2||(nf(t,x),t.stroke())})};return{line:h,curve(d,f=1){if(d.length<2)return;const m=d[0],g=d[d.length-1],p=Math.hypot(g.x-m.x,g.y-m.y)||1,y=-(g.y-m.y)/p,v=(g.x-m.x)/p;c(w=>{const k={x:l(w,s*.5),y:l(w,s*.5)},S={x:l(w,s*.5),y:l(w,s*.5)},x=l(w,s*Math.min(1.5,Math.max(.3,p/80))),M=d.map((T,A)=>{const P=A/(d.length-1),I=Math.sin(Math.PI*P)*x;return{x:T.x+k.x+(S.x-k.x)*P+y*I,y:T.y+k.y+(S.y-k.y)*P+v*I}}),E=sn(M,f);E.length<2||(nf(t,E),t.stroke())})},circle(d,f,m,g=1){u(d,f,m,m,g)},ellipse:u,nudge(d=.5){const f=a()(0);return{x:l(f,s*d),y:l(f,s*d)}}}}function z5(t,e,n,s){const i=e.x-t.x,r=e.y-t.y,o=Math.hypot(i,r)||1,a=n*Math.min(1.5,Math.max(.3,o/80)),l=-r/o,c=i/o;return[t,{x:t.x+i/3+l*s[0]*a,y:t.y+r/3+c*s[0]*a},{x:t.x+2*i/3+l*s[1]*a,y:t.y+2*r/3+c*s[1]*a},e]}function q5([t,e,n,s],i){const r=(u,d)=>({x:u.x+(d.x-u.x)*i,y:u.y+(d.y-u.y)*i}),o=r(t,e),a=r(e,n),l=r(n,s),c=r(o,a),h=r(a,l);return[t,o,c,r(c,h)]}function nf(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 qt(t,e,n){const s=t.length;if(s<2)return[];const i=[],r=[],o=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=o(l)/2,f=-(h.y-c.y)/u*d,m=(h.x-c.x)/u*d;i.push({x:a.x+f,y:a.y+m}),r.push({x:a.x-f,y:a.y-m})}),[...i,...r.reverse()]}function bi(t,e,n,s){const i=e.length;if(i<2)return;const r=qt(e,n,s),o=a=>n+(s-n)*a/(i-1);t.beginPath(),t.moveTo(r[0].x,r[0].y);for(const a of r.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,o(l)/2,0,Math.PI*2),t.fill())})}function Rn(t,e,n,s,i=16){const r={x:2*e.x-(t.x+n.x)/2,y:2*e.y-(t.y+n.y)/2},o=[];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*r.x+l*l*n.x,y:h*h*t.y+2*h*l*r.y+l*l*n.y};o.push({x:c.x+(u.x-c.x)*s,y:c.y+(u.y-c.y)*s})}return o}const Rl=new Map;function sf(t){const e=Rl.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(r=>r+r).join(""):s;n=[0,2,4].map(r=>Number.parseInt(i.slice(r,r+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 Rl.size<512&&Rl.set(t,n),n}Qt([-3,-5,-4]);const j5=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)};function rf(t,e,n){const s=[0,0,0];for(const i of n){const r=sf(i.color);let o;if(i.light==="ambient")o=i.intensity;else if(i.light==="directional")o=i.intensity*Math.max(0,-We(e,i.direction));else{const a=oe(i.position,t),l=Ir(a),c=l>0?Pn(a,1/l):e,h=i.range?Math.max(0,1-l/i.range)**2:1;if(o=i.intensity*Math.max(0,We(e,c))*h,i.light==="spot"){const u=Math.cos(i.angle*Math.PI/180),d=Math.cos(i.angle*.8*Math.PI/180);o*=j5(u,d,-We(c,i.direction))}}s[0]+=r[0]*o,s[1]+=r[1]*o,s[2]+=r[2]*o}return s}function of(t,e){return t?Math.min(1,Math.max(0,(e-t.near)/(t.far-t.near))):0}function K5([t,e,n]){const s=Math.max(t,e,n),i=Math.min(t,e,n),r=(s+i)/2;if(s===i)return[0,0,r];const o=s-i,a=r>.5?o/(2-s-i):o/(s+i);return[(s===t?(e-n)/o+(e<n?6:0):s===e?(n-t)/o+2:(t-e)/o+4)*60,a,r]}function Hl([t,e,n]){const s=(t%360+360)%360,i=r=>Math.min(1,Math.max(0,r));return`hsl(${s.toFixed(1)}, ${(i(e)*100).toFixed(1)}%, ${(i(n)*100).toFixed(1)}%)`}function Fl(t,e,n){const s=(e-t+540)%360-180;return t+Math.sign(s)*Math.min(Math.abs(s),n)}const af=335,Y5=50,Ll=new Map;function Nl(t){const e=Ll.get(t);if(e)return e;const n=t.trim();if(!/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(n)&&!n.startsWith("rgb("))return;const[s,i,r]=K5(sf(n)),o=i<.08,a={shadow:Hl(o?[230,.1,r*.82]:[Fl(s,af,8),i*.82+.02,r*.8]),core:Hl(o?[235,.14,r*.66]:[Fl(s,af,14),i*.85+.04,r*.64]),highlight:Hl(o?[s,i,r+(1-r)*.5]:[Fl(s,Y5,8),i*.9,r+(1-r)*.4])};return Ll.size<512&&Ll.set(t,a),a}const Br=(t,e)=>{if(!Number.isFinite(t)||t<0||t>1)throw new Error(`illustrated: ${e} must be 0..1`);return t};function lf(t={},e=[-.8,-.6]){const n=t.light??e;if(n.length!==2||!n.every(Number.isFinite)||Math.hypot(...n)===0)throw new Error("illustrated: light must be a finite nonzero 2D vector");const s=Math.hypot(...n);return{light:[n[0]/s,n[1]/s],weight:Br(t.weight??.6,"weight"),taper:Br(t.taper??.7,"taper"),shadow:Br(t.shadow??1,"shadow"),highlight:Br(t.highlight??.6,"highlight")}}const Wl=6,Dl=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)};function Bl(t,e,n){const s=[],i=t.length,r=n?i:i-1;for(let o=0;o<r;o++){const a=t[o],l=t[(o+1)%i],c=Math.min(24,Math.max(1,Math.ceil(Math.hypot(l.x-a.x,l.y-a.y)/e)));for(let h=0;h<c;h++)s.push({x:a.x+(l.x-a.x)*h/c,y:a.y+(l.y-a.y)*h/c})}return n||s.push(t[i-1]),s}function zl(t,e){const n=t.length,s=i=>t[e?(i%n+n)%n:Math.min(n-1,Math.max(0,i))];return t.map((i,r)=>{const o=s(r-2),a=s(r+2),l=a.x-o.x,c=a.y-o.y,h=Math.hypot(l,c)||1;return{x:-c/h,y:l/h}})}function cf(t,e){const n=t.reduce((r,o)=>r+o.x,0)/t.length,s=t.reduce((r,o)=>r+o.y,0)/t.length;return t.reduce((r,o,a)=>r+e[a].x*(o.x-n)+e[a].y*(o.y-s),0)>=0?1:-1}function X5(t){let e=0,n=0;return t.forEach((s,i)=>{const r=t[(i+1)%t.length];e+=s.x*r.y-r.x*s.y,n+=Math.hypot(r.x-s.x,r.y-s.y)}),n>0?Math.abs(e)/n:0}function zr(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 G5(t,e,n,s){const[i,r]=s.light,o=u=>{const d=u.x*i+u.y*r;return 1-s.weight*d*(d>0?.55:1)},a=(u,d,f,m)=>{const g=u.map((y,v)=>({x:y.x+d[v].x*f[v]/2,y:y.y+d[v].y*f[v]/2})),p=u.map((y,v)=>({x:y.x-d[v].x*f[v]/2,y:y.y-d[v].y*f[v]/2}));if(t.fillStyle=e,m){t.beginPath(),g.forEach((y,v)=>v?t.lineTo(y.x,y.y):t.moveTo(y.x,y.y)),t.closePath(),p.forEach((y,v)=>v?t.lineTo(y.x,y.y):t.moveTo(y.x,y.y)),t.closePath(),t.fill("evenodd");return}zr(t,[...g,...p.reverse()]),t.fill();for(const y of[0,u.length-1])t.beginPath(),t.arc(u[y].x,u[y].y,f[y]/2,0,Math.PI*2),t.fill()},l=(u,d)=>{const f=Nl(d),m=X5(u);if(!f||m<n*1.5)return;const g=Bl(u,Math.max(2,m*.25),!0),p=zl(g,!0),y=cf(g,p),v=p.map(M=>({x:M.x*y,y:M.y*y})),w=v.map(M=>M.x*i+M.y*r),k=t.globalAlpha,S=(M,E,T,A)=>{if(A<=0)return;const P=g.map((O,_)=>({x:O.x-v[_].x*M(w[_]),y:O.y-v[_].y*M(w[_])})),I=g.map((O,_)=>({x:O.x-v[_].x*E(w[_]),y:O.y-v[_].y*E(w[_])}));zr(t,[...P,...I.reverse()]),t.globalAlpha=k*A,t.fillStyle=T,t.fill()};t.save(),zr(t,u),t.clip();const x=(M,E,T,A=()=>-n)=>{for(let P=1;P<=Wl;P++){const I=P/Wl;S(A,O=>A()+(M(O)-A())*I,E,T/Wl)}};x(M=>m*.5*Dl(-.15,.7,-M),f.shadow,s.shadow*.85),x(M=>m*.18*Dl(.3,.95,-M),f.core,s.shadow*.6),x(M=>m*(.07+.2*Dl(.35,.95,M)),f.highlight,s.highlight*.7,()=>m*.07),t.restore()},c=(u,d)=>{const f=Bl(u,Math.max(1.5,d*1.5),!0),m=zl(f,!0),g=cf(f,m);a(f,m,m.map(p=>d*o({x:p.x*g,y:p.y*g})),!0)},h={look:"illustrated",ink:e,limb(u,d,f){t.fillStyle=e,bi(t,u,d,f)},line(u,d,f){if(u.length<2||d<=0)return;const m=Bl(u,Math.max(1.5,d*1.5),!1),g=zl(m,!1),p=m.length,y=m.map((v,w)=>{const k=w/(p-1),S=1-s.taper*.6*(1-Math.sqrt(Math.sin(Math.PI*k))),x=f?o({x:g[w].x*f,y:g[w].y*f}):1;return d*S*x});a(m,g,y,!1)},shape(u,d,f,m){u.length<3||(zr(t,u),d!==null&&(t.fillStyle=d,t.fill(),m||l(u,d)),f>0&&c(u,f))},ellipse(u,d,f,m,g,p,y){h.shape(wi(u,d,f,m,g,0,1,48).slice(0,-1),p,y)},dot(u,d,f){t.fillStyle=e,t.beginPath(),t.arc(u,d,f,0,Math.PI*2),t.fill()},guide(){},guideEllipse(){}};return h}function wi(t,e,n,s,i,r=0,o=1,a=40){const l=Math.cos(i),c=Math.sin(i);return Array.from({length:a+1},(h,u)=>{const d=r+Math.PI*2*o*u/a,f=Math.cos(d)*n,m=Math.sin(d)*s;return{x:t+f*l-m*c,y:e+f*c+m*l}})}function ki(t,e){if(e.look==="pencil")return J5(t,e);if(e.look==="illustrated"){if(!e.illustrated)throw new Error("createPen: the illustrated look needs its resolved style");return G5(t,e.ink,e.lineWidth,e.illustrated)}return hf(t,e.ink,e.look)}function qr(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 vi(t,e){return e.look==="silhouette"?hf(t,e.ink,"silhouette",!1):e}function hf(t,e,n,s=!0){const i=n==="silhouette",r=i?1.25:1;return{look:n,ink:e,limb(o,a,l){t.fillStyle=e,bi(t,o,a*r,l*r)},line(o,a){o.length<2||(t.strokeStyle=e,t.lineWidth=a*r,t.lineCap="round",t.lineJoin="round",qr(t,o),t.stroke())},shape(o,a,l){qr(t,o,!0),(a!==null||i&&s)&&(t.fillStyle=i?e:a,t.fill()),!(l<=0)&&(t.strokeStyle=e,t.lineWidth=l*r,t.lineJoin="round",t.stroke())},ellipse(o,a,l,c,h,u,d){t.beginPath(),t.ellipse(o,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*r,t.stroke())},dot(o,a,l){t.fillStyle=e,t.beginPath(),t.arc(o,a,l*r,0,Math.PI*2),t.fill()},guide(){},guideEllipse(){}}}function U5(t,e){const n=[t[0]];let s=0;for(let o=1;o<t.length;o++){const a=t[o-1],l=t[o],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],r=n[n.length-1];return Math.hypot(i.x-r.x,i.y-r.y)>e*.25?n.push(i):n[n.length-1]=i,n}function V5(t,e){const n=t.length;return t.map((s,i)=>{const r=t[Math.max(0,i-1)],o=t[Math.min(n-1,i+1)],a=Math.hypot(o.x-r.x,o.y-r.y)||1,l=e(n===1?0:i/(n-1));return{x:s.x-(o.y-r.y)/a*l,y:s.y+(o.x-r.x)/a*l}})}function uf(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,r)=>i+r.amount*Math.sin(Math.PI*2*r.frequency*s+r.phase),0)/n}function J5(t,e){const n=e.pencil??{},s=e.ink,i=n.roughness??Math.max(1,e.lineWidth*.12),r=Math.max(1,Math.round(n.passes??2)),o=Math.min(1,Math.max(0,n.pressure??.25)),a=Math.min(1,Math.max(0,n.rubbedOut??.15)),l=_l(e.time,n.boil??8);let c=0;const h=(m,g,p=!1)=>Se(re(`${e.seed}:${p?"paper":l}:${m}:${g}`)),u=(m,g,p,y,v,w=0)=>{if(m.length<2)return;const k=m.slice(1).reduce((P,I,O)=>P+Math.hypot(I.x-m[O].x,I.y-m[O].y),0);let S=U5(m,Math.max(1.5,Math.min(e.lineWidth*.8,k/24)));if(w>0&&S.length>=2){const[P,I]=[S[S.length-2],S[S.length-1]],O=Math.hypot(I.x-P.x,I.y-P.y)||1;S=[...S,{x:I.x+(I.x-P.x)/O*w,y:I.y+(I.y-P.y)/O*w}]}const x=uf(p),M=uf(p),E=S.length,T=[],A=[];S.forEach((P,I)=>{const O=E===1?0:I/(E-1),_=S[Math.max(0,I-1)],L=S[Math.min(E-1,I+1)],j=Math.hypot(L.x-_.x,L.y-_.y)||1,V=-(L.y-_.y)/j,tt=(L.x-_.x)/j,J=x(O)*v,F=Math.min(1,O/.08,(1-O)/.08),B=(.55+.45*Math.sqrt(Math.max(0,F)))*(1+o*M(O)),Y=Math.max(.3,g(O)*B/2),R=P.x+V*J,K=P.y+tt*J;T.push({x:R+V*Y,y:K+tt*Y}),A.push({x:R-V*Y,y:K-tt*Y})}),t.save(),t.globalAlpha*=y,t.fillStyle=s,qr(t,[...T,...A.reverse()],!0),t.fill(),t.restore()},d=(m,g)=>{const p=c++,y=h(p,99,!0);if(y.next()<a){const S=(y.next()*2-1)*e.lineWidth*1.4,x=(y.next()*2-1)*e.lineWidth*1.4,M=m.map(E=>({x:E.x+S,y:E.y+x}));u(M,E=>g(E)*1.8,h(p,98,!0),.035,i),u(M,E=>g(E)*.45,h(p,97,!0),.12,i*1.5)}const v=m.slice(1).reduce((S,x,M)=>S+Math.hypot(x.x-m[M].x,x.y-m[M].y),0),w=g(.5)>4&&v>g(.5)*6,k=w?[-.3,.3,0]:[0];for(let S=0;S<r;S++){const x=S===0;k.forEach((M,E)=>{const T=h(p,S*10+E),A=M===0?m:V5(m,I=>g(I)*M*Math.sqrt(Math.sin(Math.PI*I))),P=!x&&M===0?e.lineWidth*(.3+T.next()*.8):0;u(A,I=>g(I)*(w?.5:1)*(x?1:.6),T,x?.85:.45,i*(x?.6:1),P)})}},f=(m,g,p,y,v,w)=>{const S=h(c,50).next()*Math.PI*2;d(wi(m,g,p,y,v,S,1.08,48),()=>w)};return{look:"pencil",ink:s,limb(m,g,p){d(m,y=>g+(p-g)*y)},line(m,g){d(m,()=>g)},shape(m,g,p){g!==null&&(t.save(),t.globalAlpha*=.88,t.fillStyle=g,qr(t,m,!0),t.fill(),t.restore()),p>0&&d([...m,m[0]],()=>p)},ellipse(m,g,p,y,v,w,k){w!==null&&(t.save(),t.globalAlpha*=.9,t.fillStyle=w,t.beginPath(),t.ellipse(m,g,p,y,v,0,Math.PI*2),t.fill(),t.restore()),f(m,g,p,y,v,k)},dot(m,g,p){t.save(),t.globalAlpha*=.9,t.fillStyle=s,t.beginPath(),t.arc(m,g,p,0,Math.PI*2),t.fill(),t.restore()},guide(m){if(n.construction===!1||m.length<2)return;const g=c++;u(m,()=>Math.max(.6,e.lineWidth*.18),h(g,0),.28,i*1.2,e.lineWidth)},guideEllipse(m,g,p,y,v){if(n.construction===!1)return;const w=c++,k=h(w,0),S=wi(m,g,p,y,v,k.next()*Math.PI*2,1.12,48);u(S,()=>Math.max(.6,e.lineWidth*.18),k,.28,i*1.5)}}}const df=["thumb","index","middle","ring","pinky"],Ct={"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 Wt(t={}){return{...Ct,...t}}const ce=(t,e,n,s,i)=>({"thumb.curl":t,"index.curl":e,"middle.curl":n,"ring.curl":s,"pinky.curl":i}),Tt={relaxed:Ct,open:Wt({...ce(0,0,0,0,0),"thumb.across":0,spread:.55}),spread:Wt({...ce(0,0,0,0,0),"thumb.across":0,spread:1}),flat:Wt({...ce(0,0,0,0,0),"thumb.across":.35,spread:0}),fist:Wt({...ce(.7,1,1,1,1),"thumb.across":.9,spread:0}),point:Wt({...ce(.75,0,1,1,1),"thumb.across":.9,spread:0}),thumbsUp:Wt({...ce(0,1,1,1,1),"thumb.across":0,spread:0,roll:70}),peace:Wt({...ce(.75,0,0,1,1),"thumb.across":.9,spread:1}),ok:Wt({...ce(.12,.6,.1,.15,.2),"thumb.across":.55,spread:.6}),pinch:Wt({...ce(.1,.65,.75,.85,.9),"thumb.across":.55,spread:0}),cupped:Wt({...ce(.25,.4,.4,.4,.4),"thumb.across":.4,spread:.05,turn:2}),wave:Wt({...ce(0,.05,.05,.1,.12),"thumb.across":0,spread:.7,turn:2}),pencilGrip:Wt({...ce(.1,.6,.72,.88,.95),"thumb.across":.5,spread:0,turn:.8,bend:10}),hold:Wt({...ce(.5,.7,.72,.74,.76),"thumb.across":.75,spread:0,turn:1})};function fs(t,e,n){const s={...t};for(const[i,r]of Object.entries(e)){const o=t[i]??r;s[i]=o+(r-o)*n}return s}const Z5={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}},Q5={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}},De={base:[-.11,.1,-.05],bones:[.2,.15,.12],widths:[.2,.145,.135],out:[-.7,.68,-.22],across:[.35,.5,-.8]},tv=[82,100,62],ev=[48,72],nv=3,sv=13,iv=.035,rv=-.075,ov=[[-.17,0],[-.215,.12],[-.235,.26],[-.225,.4],[-.185,.49],[-.075,.525],[.05,.51],[.16,.465],[.215,.4],[.225,.26],[.2,.1],[.16,0]],rn=t=>t*Math.PI/180,ql=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],jr=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],jl=(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]],Mi=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function on(t,e,n){const s=Math.cos(n),i=Math.sin(n),r=jl(e,t),o=e[0]*t[0]+e[1]*t[1]+e[2]*t[2];return[t[0]*s+r[0]*i+e[0]*o*(1-s),t[1]*s+r[1]*i+e[1]*o*(1-s),t[2]*s+r[2]*i+e[2]*o*(1-s)]}const ff=[1,0,0],gf=[0,1,0],Si=[0,0,1];function av(t,e,n){const s=rn(t.fan*(nv+sv*n)),i=[Math.sin(s),Math.cos(s),0],r=[Math.cos(s),-Math.sin(s),0],o=[t.knuckle];let a=0;t.bones.forEach((h,u)=>{a+=rn(tv[u]*e),o.push(ql(o[u],jr(on(i,r,-a),h)))});const l=on(Si,r,-a),c=o.map((h,u)=>t.width*(1-.14*(u/(o.length-1))));return{joints:o,back:l,widths:c}}function lv(t,e,n=1,s=1){const i=Math.min(1,Math.max(0,e)),r=Mi(ql(jr(Mi(De.out),1-i),jr(Mi(De.across),i))),o=Mi(jl(Si,r)),a=Mi(jl(r,o)),l=[[De.base[0]*s,De.base[1],De.base[2]]];let c=0;De.bones.forEach((d,f)=>{f>0&&(c+=rn(ev[f-1]*t)),l.push(ql(l[f],jr(on(r,o,c),d)))});const h=on(a,o,c),u=[...De.widths,De.widths[De.widths.length-1]*.92].map(d=>d*n);return{joints:l,back:h,widths:u}}function Kr(t,e={}){const n={...Ct,...t},s=e.size??100,i=e.side??"right",r=i==="left"?-1:1,o=rn(e.angle??0),a=e.fingers===4,l=Math.max(.5,e.plump??1),c=1+(l-1)*.7,h=I=>({...I,knuckle:[I.knuckle[0]*c,I.knuckle[1],I.knuckle[2]],width:I.width*l}),u=rn(n.bend??0),d=rn(n.tilt??0),f=rn(90*(n.turn??0)),m=I=>on(on(on(I,ff,-u),Si,-d),gf,f),g=Math.cos(o),p=Math.sin(o),y=rn(n.roll??0),v=Math.cos(y),w=Math.sin(y),k=I=>{const O=I[0]*s,_=-I[1]*s,L=(O*v-_*w)*r,j=O*w+_*v;return{x:L*g-j*p,y:L*p+j*g}},S=I=>{const O=k(I),_=Math.hypot(O.x,O.y);return _>1e-6*s?{x:O.x/_,y:O.y/_}:{x:0,y:0}},x={thumb:lv(n["thumb.curl"]??0,n["thumb.across"]??0,l,c)},M=a?Q5:Z5;for(const I of df){const O=M[I];O&&(x[I]=av(h(O),n[`${I}.curl`]??0,n.spread??0))}const E={};for(const[I,O]of Object.entries(x)){const _=O.joints.map(m),L=m(O.back);E[I]={points:_.map(k),depths:_.map(j=>j[2]*s),widths:O.widths.map(j=>j*s),nail:L[2],back:S(L)}}const T=ov.flatMap(([I,O])=>[m([I*c,O,iv]),m([I*c,O,rv])]),A=cv(T.map(k)),P=T.reduce((I,O)=>I+O[2],0)/T.length*s;return{size:s,side:i,wrist:{x:0,y:0},palm:A,palmDepth:P,palmFacing:-m(Si)[2],fingers:E,axes:{up:S(m(gf)),across:S(m(ff)),out:S(m(Si))},curls:Object.fromEntries(Object.keys(E).map(I=>[I,n[`${I}.curl`]??0]))}}function mf(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,r]of Object.entries(t.fingers))s[i]={...r,points:r.points.map(n)};return{...t,wrist:n(t.wrist),palm:t.palm.map(n),fingers:s}}function cv(t){const e=[...t].sort((r,o)=>r.x-o.x||r.y-o.y);if(e.length<3)return e;const n=(r,o,a)=>(o.x-r.x)*(a.y-r.y)-(o.y-r.y)*(a.x-r.x),s=[];for(const r of e){for(;s.length>=2&&n(s[s.length-2],s[s.length-1],r)<=0;)s.pop();s.push(r)}const i=[];for(const r of[...e].reverse()){for(;i.length>=2&&n(i[i.length-2],i[i.length-1],r)<=0;)i.pop();i.push(r)}return[...s.slice(0,-1),...i.slice(0,-1)]}function pf(t,e,n,s){if(s.mode!=="cel"||e.length<3)return;const i=Math.hypot(...s.light),r=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}}),o=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(),o(e),t.clip(),o([...e,...r.reverse()]),t.globalAlpha*=s.opacity,t.fillStyle=s.shadow,t.fill(),t.restore()}const hv="#f1c9a5",uv="#2f2f33";function Yr(t,e,n,s={},i=0){const r=mf(Kr(n,s),e),o=s.ink??uv,a=s.lineWidth??r.size*.035;let l=s.pen??ki(t,{look:s.look??"clean",ink:o,lineWidth:a,seed:s.seed??1,time:i,pencil:{construction:!1,...s.pencil}});const c=s.skin??hv;c==="none"&&(l=vi(t,l));const h=s.nails??!0,u=[{depth:r.palmDepth,draw:()=>dv(t,l,r,c,a,s)}];for(const d of Object.values(r.fingers)){const f=d.depths.reduce((m,g)=>m+g,0)/d.depths.length;u.push({depth:f,draw:()=>fv(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,m)=>f.depth-m.depth))d.draw();return t.restore(),r}function dv(t,e,n,s,i,r){if(e.shape(n.palm,s==="none"?null:s,r.connected?0:i),s!=="none"&&r.shading&&e.look==="clean"){const o=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});pf(t,n.palm,o,r.shading)}if(r.connected&&i>0&&(e.look!=="silhouette"||s==="none")){const{up:o}=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)*o.x+((c.y+h.y)/2-n.wrist.y)*o.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:o}=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-o.x*u*.2,y:h.y-o.y*u*.2},f=Math.atan2(o.y,o.x),m=Array.from({length:7},(g,p)=>{const y=f-Math.PI/2+Math.PI*p/6;return{x:d.x+Math.cos(y)*u,y:d.y+Math.sin(y)*u}});e.line(m,i*.6)}}if(n.palmFacing>.45&&e.look!=="silhouette"){const{up:o,across:a}=n.axes,l=n.size,c=n.wrist,h=(d,f)=>({x:c.x+(a.x*d+o.x*f)*l,y:c.y+(a.y*d+o.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 fv(t,e,n,s,i,r){const{widths:o}=n,a=gv(n.points,2),l=n.points[0],c=a[a.length-1],h=o[0],u=o[o.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=qt(a,h,u),p=a[a.length-2],y=Math.atan2(c.y-p.y,c.x-p.x),v=Array.from({length:13},(w,k)=>{const S=y+Math.PI/2-k*Math.PI/12;return{x:c.x+Math.cos(S)*u/2,y:c.y+Math.sin(S)*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,bi(t,a,h,u)),s==="none"||e.look==="silhouette"||!r||n.nail<.25)return;const d=a[a.length-2],f=mv({x:c.x-d.x,y:c.y-d.y})??{x:0,y:-1},m={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(m.x,m.y,u*.24*Math.max(.35,n.nail),u*.19,Math.atan2(f.y,f.x),"#f8e3d3",i*.45)}function gv(t,e){let n=t;for(let s=0;s<e;s++){if(n.length<3)return n;const i=[n[0]];for(let r=0;r<n.length-1;r++){const o=n[r],a=n[r+1];r>0&&i.push({x:o.x*.75+a.x*.25,y:o.y*.75+a.y*.25}),r<n.length-2&&i.push({x:o.x*.25+a.x*.75,y:o.y*.25+a.y*.75})}i.push(n[n.length-1]),n=i}return n}const mv=t=>{const e=Math.hypot(t.x,t.y);return e>1e-6?{x:t.x/e,y:t.y/e}:null},Gt={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,give:12},doubleBounce:{swing:22,knee:40,arm:26,elbow:24,lean:3,bounce:.02,bounces:2,squash:.04,give:10},sneak:{swing:28,knee:70,arm:6,elbow:0,forearm:110,shoulder:25,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,flight:!0,give:30},shove:{swing:18,knee:28,arm:0,elbow:0,lean:0}},pv=40;function Kl(t,e){const n=Math.cos(e*2*(t.bounces??1));return t.flight?(1-n)/2:(1+n)/2}function Yl(t,e){const n=t.give??0;return{left:n*(.4+.6*Math.max(0,-e)),right:n*(.4+.6*Math.max(0,e))}}function Ti(t){return t===void 0?Gt.walk:typeof t=="string"?Gt[t]??Gt.walk:t}function yf(t,e,n=ut,s=1){const i=Ti(t);if(i===Gt.walk)return vf(e,n,s);const r=e*Math.PI*2,o=Math.sin(r)*s,a=Math.cos(r)*s,l=k=>Math.abs(k)<=pv,c=n.lean+i.lean*s,h=(n.bend??0)+(i.bend??0),u=c+h,d=(i.shoulder??0)+u,f=(k,S)=>l(k)?S*d+i.arm*o:k,m=i.forearm??0,g=l(n.leftShoulder)?n.leftElbow-m-i.elbow*Math.max(0,-o):n.leftElbow,p=l(n.rightShoulder)?n.rightElbow+m+i.elbow*Math.max(0,o):n.rightElbow,y=Kl(i,r),v=i.crouch??0,w=Yl(i,a);return{...n,lean:c+(i.sway??0)*Math.sin(r)*(1-(n.turn??0)),bend:h,headTilt:n.headTilt-i.lean*.5*s+(i.headTilt??0),leftElbow:g,rightElbow:p,leftHip:-i.swing*o-v*.5-w.left*.5,rightHip:-i.swing*o+v*.5+w.right*.5,leftKnee:-i.knee*Math.max(0,a)-v-w.left,rightKnee:i.knee*Math.max(0,-a)+v+w.right,leftAnkle:(n.leftAnkle??0)+(i.tiptoe??0),rightAnkle:(n.rightAnkle??0)+(i.tiptoe??0),leftShoulder:f(n.leftShoulder,-1),rightShoulder:f(n.rightShoulder,1),rise:(n.rise??0)+(i.bounce??0)*s*y,stretch:n.stretch*(1+(i.squash??0)*(y-.5))}}function Xr(t,e,n=1){const s=Ti(t),i=Gt.walk.swing,r=o=>Math.sin(o*Math.PI/180);return Mf(e,n)*r(s.swing*n)/r(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 Bt(t){return{...ut,...t}}const bf={mouth:0,smile:0,mouthWidth:1,leftEye:1,rightEye:1,leftBrow:0,rightBrow:0,browTilt:0,lookX:0,lookY:0},jt=t=>({...bf,...t}),Mt={neutral:bf,happy:jt({smile:.9,leftBrow:.2,rightBrow:.2}),joyful:jt({mouth:.6,smile:1,mouthWidth:1.2,leftEye:0,rightEye:0,leftBrow:.4,rightBrow:.4}),sad:jt({smile:-.8,leftEye:.8,rightEye:.8,browTilt:.9,leftBrow:-.1,rightBrow:-.1,lookY:.6}),crying:jt({mouth:.45,smile:-1,leftEye:0,rightEye:0,browTilt:1,lookY:.4}),surprised:jt({mouth:.7,mouthWidth:.7,leftEye:1.5,rightEye:1.5,leftBrow:1,rightBrow:1}),shocked:jt({mouth:1,mouthWidth:.8,leftEye:1.6,rightEye:1.6,leftBrow:1,rightBrow:1,browTilt:.4}),angry:jt({smile:-.6,mouthWidth:.9,leftEye:.8,rightEye:.8,leftBrow:-.6,rightBrow:-.6,browTilt:-1}),furious:jt({mouth:.5,smile:-1,mouthWidth:1.3,leftEye:.9,rightEye:.9,leftBrow:-.9,rightBrow:-.9,browTilt:-1}),worried:jt({smile:-.3,mouthWidth:.8,leftEye:1.1,rightEye:1.1,leftBrow:.3,rightBrow:.3,browTilt:.8,lookX:-.5}),scared:jt({mouth:.35,smile:-.5,mouthWidth:.8,leftEye:1.45,rightEye:1.45,leftBrow:.8,rightBrow:.8,browTilt:.9}),confused:jt({smile:-.2,mouthWidth:.8,leftEye:.9,rightEye:1.15,leftBrow:-.3,rightBrow:.8,lookX:.5,lookY:-.4}),skeptical:jt({smile:-.1,leftEye:.6,rightEye:1,leftBrow:-.4,rightBrow:.7,lookX:.4}),thinking:jt({smile:0,mouthWidth:.7,leftBrow:.3,rightBrow:.5,lookX:.6,lookY:-.8}),sleepy:jt({smile:.1,leftEye:.25,rightEye:.25,leftBrow:-.3,rightBrow:-.3,lookY:.5}),disgusted:jt({smile:-.7,mouthWidth:.9,leftEye:.6,rightEye:.75,leftBrow:-.5,rightBrow:-.2,browTilt:-.4,lookX:-.6}),smug:jt({smile:.6,mouthWidth:.9,leftEye:.6,rightEye:.6,leftBrow:.1,rightBrow:.5,lookX:.5}),wink:jt({smile:.9,leftEye:0,rightEye:1,leftBrow:-.2,rightBrow:.3})};function an(t,e){return{...t,...typeof e=="string"?Mt[e]:e}}const he={rest:ut,wave:Bt({rightShoulder:135,rightElbow:30,headTilt:6,...Mt.happy}),cheer:Bt({leftShoulder:125,leftElbow:20,rightShoulder:125,rightElbow:20,...Mt.joyful}),shrug:Bt({leftShoulder:30,leftElbow:85,rightShoulder:30,rightElbow:85,headTilt:-10,...Mt.confused,lookX:0,lookY:0}),point:Bt({rightShoulder:90,rightElbow:0,lean:4,smile:.4}),think:Bt({rightShoulder:60,rightElbow:150,headTilt:10,...Mt.thinking}),handsOnHips:Bt({leftShoulder:45,leftElbow:-100,rightShoulder:45,rightElbow:-100,leftHip:14,rightHip:14,smile:.8}),sad:Bt({leftShoulder:14,rightShoulder:14,leftElbow:-4,rightElbow:-4,headTilt:-14,lean:-3,...Mt.sad}),surprised:Bt({leftShoulder:70,leftElbow:60,rightShoulder:70,rightElbow:60,...Mt.surprised}),crouch:Bt({stretch:.72,leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50,leftHip:22,rightHip:22,headTilt:-4}),sit:Bt({sit:1,turn:.5,leftShoulder:-25,rightShoulder:25,leftElbow:-55,rightElbow:55}),jump:Bt({stretch:1.22,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4,...Mt.joyful}),duck:Bt({stretch:.62,bend:28,headTilt:-8,leftShoulder:150,rightShoulder:150,leftElbow:130,rightElbow:130,leftHip:25,rightHip:25,...Mt.scared}),lie:Bt({spin:-90,rise:-.42,leftShoulder:165,rightShoulder:165,leftElbow:150,rightElbow:150,...Mt.sleepy}),sideSplit:Bt({leftHip:90,rightHip:90,leftAnkle:-45,rightAnkle:-45,leftShoulder:120,rightShoulder:120,leftElbow:10,rightElbow:10,...Mt.happy}),frontSplit:Bt({turn:1,leftHip:-90,rightHip:-90,leftAnkle:-45,rightAnkle:-45,leftShoulder:-150,rightShoulder:150,leftElbow:10,rightElbow:-10,...Mt.happy})},wf=Object.keys(ut);function gs(t,e,n){const s={...t};for(const i of wf)s[i]=t[i]+(e[i]-t[i])*n;return s}const Xl=24,Gl=4,kf=28,yv=40;function vf(t,e=ut,n=1){const s=Math.sin(t*Math.PI*2)*n,i=Math.cos(t*Math.PI*2)*n,r=h=>Math.abs(h)<=yv,o=e.lean+Gl*n+(e.bend??0),a=(h,u)=>r(h)?u*o+22*s:h,l=r(e.leftShoulder)?e.leftElbow-kf*Math.max(0,-s):e.leftElbow,c=r(e.rightShoulder)?e.rightElbow+kf*Math.max(0,s):e.rightElbow;return{...e,lean:e.lean+Gl*n,headTilt:e.headTilt-Gl*.5*n,leftElbow:l,rightElbow:c,leftHip:-Xl*s,rightHip:-Xl*s,leftKnee:-30*Math.max(0,i),rightKnee:30*Math.max(0,-i),leftShoulder:a(e.leftShoulder,-1),rightShoulder:a(e.rightShoulder,1)}}function Mf(t,e=1){return 4*((Ul+Gr)*t)*Math.sin(Xl*e*Math.PI/180)}function Sf(t){const e=Math.abs(Math.sin(t/65)),n=.55+.45*Math.sin(t/310);return e*n}const Tf=.12,Ef=.46,bv=1-2*Tf,wv=.1,kv=.21,vv=.19,Ul=.24,Gr=.22,Af=.12,Mv=.14,xf=.33,Pf=.7,$f=.3,Sv=.35,Tv=[1.7,1.05],Ev=[1.3,.75],If=[1.45,.85],Av=[1.15,.75],Of=.06,xv=.7,Pv=.65,Cf=.075,$v=.3,Iv=.02,Ov=.012,Cv=12,_v=.25,Ur=90,Rv=.25,Hv=.04,_f=.01,Hn=t=>Math.min(1,Math.max(0,t??0));function Fv(t,e=1){return Gr*t*e}const Vl=-.12,Rf=.4,me=t=>t*Math.PI/180,Lv=(t,e)=>({x:e*Math.sin(me(t)),y:Math.cos(me(t))}),Hf=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),Ff=(t,e,n,s)=>t-.3*e-n*.14*e-Math.max(0,s-1)*.12*e;function Nv(t,e,n,s,i,r){const o=Math.max(1,Math.min(r*.6,Mv*n)),a=Hn(e.turn),l=(Af+xf*a)*n,c=s+Vl*n,h=l+e.lookX*.08*n,u=e.lookY*.07*n,d=[{x:-.34*n*(1-Pf*a),squeeze:1-Pf*a,open:e.leftEye,brow:e.leftBrow,side:-1},{x:.34*n*(1-$f*a),squeeze:1-$f*a,open:e.rightEye,brow:e.rightBrow,side:1}];t.fillStyle=i,t.strokeStyle=i,t.lineWidth=o;for(const y of d){const v=Hf(y.open,e.blink);if(v<.2){const x=e.smile>.5?-.12*n:.06*n;t.beginPath(),t.moveTo(y.x+l-.12*n,c),t.quadraticCurveTo(y.x+l,c+x,y.x+l+.12*n,c),t.stroke()}else{if(v>1.2){const M=.13*n*v;t.beginPath(),t.ellipse(y.x+l,c,M*.85,M,0,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.stroke(),t.fillStyle=i}const x=v>1.2?.075*n:.1*n;t.beginPath(),t.ellipse(y.x+h,c+u,x,x*1.1*Math.min(v,1),0,0,Math.PI*2),t.fill()}const w=Ff(c,n,y.brow,v),k=y.x+l-y.side*.13*n*y.squeeze,S=y.x+l+y.side*.13*n*y.squeeze;t.beginPath(),t.moveTo(S,w),t.lineTo(k,w-e.browTilt*.1*n),t.stroke()}const f=s+Rf*n,m=.25*n*Math.max(.3,e.mouthWidth)*(1-Sv*a),g=Math.min(1,Math.max(0,e.mouth));if(t.beginPath(),g<=.05){t.moveTo(l-m,f),t.quadraticCurveTo(l,f+e.smile*.25*n,l+m,f),t.stroke();return}const p=.3*n*g;e.smile>.3?(t.moveTo(l-m,f-.05*n),t.lineTo(l+m,f-.05*n),t.quadraticCurveTo(l,f+p*2,l-m,f-.05*n)):e.smile<-.3?(t.moveTo(l-m,f+p*.6),t.lineTo(l+m,f+p*.6),t.quadraticCurveTo(l,f-p*1.4,l-m,f+p*.6)):t.ellipse(l,f,m*.8,p,0,0,Math.PI*2),t.fill()}function Lf(t,e){const n=e.height??300,s=Math.min(3,Math.max(.3,t.stretch??1)),i=Math.sqrt(s),r=e.armLength??1;if(!Number.isFinite(r)||r<=0)throw new Error("stick figure: armLength must be a positive finite multiplier");const o=(e.headSize??2*Tf)/2,a=e.headSize===void 0?bv:1-2*o,l=o*n,c=Hn(t.sit),h=t.leftHip+(-Ur-t.leftHip)*c,u=t.leftKnee+(-Ur-t.leftKnee)*c,d=t.rightHip+(Ur-t.rightHip)*c,f=t.rightKnee+(Ur-t.rightKnee)*c,m=e.classic===!0,g=Hn(t.turn),p=(J,F,B,Y,R)=>{const K=Math.max(-Math.PI/2,Math.min(Math.PI/2,Math.abs(me(F-B)/2)+me(Y))),st=Math.max(-1,Math.min(1,xv+R)),$=g+(1-g)*J*st;return m?{x:0,y:0}:{x:Math.cos(K)*Of*$,y:Math.sin(K)*Of}},y={left:t.leftAnkle??0,right:t.rightAnkle??0},v={left:t.leftFootOut??0,right:t.rightFootOut??0};let w=0;if(c>0||!m){const J=(R,K,st,$,C)=>Ul*Math.cos(me(K))+Gr*Math.cos(me(K-st))+Math.max(0,p(R,K,st,$,C).y),F=Math.max(J(-1,h,u,y.left,v.left),J(1,d,f,y.right,v.right)),B=1-Hn((t.rise??0)/Hv),Y=(m?Math.min(1,c/Rv):1)*B;w=(Ef-F)*Y*n*s}const k=-Ef*n*s+w,S=-a*n*s+w,x=m?0:(Iv*Hn(t.turn)+Ov*c)*n*s,M=me(t.bend??0),E={end:Wf(k,S,M,1),bend:M};let T;if(M!==0){T=[];for(let J=0;J<=Nf;J++){const F=J/Nf,B=Wf(k,S,M,F);T.push({x:B.x-x*Math.sin(Math.PI*F),y:B.y})}}else T=x===0?[{x:0,y:k},{x:0,y:S}]:Rn({x:0,y:k},{x:-x,y:(k+S)/2},{x:0,y:S},1,8);const A=S+wv*n*s,P=(e.shoulderWidth??0)*n*Math.cos(g*Math.PI/2),I=(J,F,B,Y,R)=>{const K=Lv(B,Y);return{x:J+K.x*R*n,y:F+K.y*R*n}},O=(J,F,B)=>{const Y=I(0,k,F,J,Ul*s);return{root:{x:0,y:k},joint:Y,end:I(Y.x,Y.y,F-B,J,Gr*s)}},_=(J,F,B)=>{const Y={x:J*P,y:A},R=I(Y.x,Y.y,F,J,kv*i*r);return{root:Y,joint:R,end:I(R.x,R.y,F+B,J,vv*i*r)}},L={left:O(-1,h,u),right:O(1,d,f)},j=(J,F,B,Y,R,K)=>{const st=p(J,B,Y,R,K);return{x:F.end.x+st.x*n*s,y:F.end.y+st.y*n*s}},V=(J,F,B,Y,R)=>I(F.end.x,F.end.y,B+Y+R,J,Cf*i),tt={left:_(-1,t.leftShoulder,t.leftElbow),right:_(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(m?0:$v,e.rubber??0)),r:l,headRx:l/Math.sqrt(s),headRy:l*Math.sqrt(s),hipY:k,neckY:S,drop:w,lean:m?t.lean:t.lean+Cv*Math.sin(Math.PI*c),classic:m,legs:L,toes:{left:j(-1,L.left,h,u,y.left,v.left),right:j(1,L.right,d,f,y.right,v.right)},spine:T,chest:E,arms:tt,handTips:{left:V(-1,tt.left,t.leftShoulder,t.leftElbow,t.leftWrist??0),right:V(1,tt.right,t.rightShoulder,t.rightElbow,t.rightWrist??0)}}}const Nf=10;function Wf(t,e,n,s){const i=t-e,r=n*s;if(Math.abs(n)<1e-9)return{x:0,y:t-i*s};const o=i/n;return{x:o*(1-Math.cos(r)),y:t-o*Math.sin(r)}}function Wv(t,e){if(t.chest.bend===0)return e;const n=Ai(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 Ei=(t,e)=>e===0?[t.root,t.joint,t.end]:Rn(t.root,t.joint,t.end,e);function Ai(t,e,n){const s=Math.cos(n),i=Math.sin(n),r=t.x-e.x,o=t.y-e.y;return{x:e.x+r*s-o*i,y:e.y+r*i+o*s}}function Df(t,e,n=!0){const s=Bv(t,e),i=e.spin??0,r=e.rise??0;return n&&(i!==0||r!==0)?Dv(s,t,i,r):s}function Bf(t,e,n){return{pivot:{x:0,y:t.hipY},angle:t.facing*me(e),lift:n*t.height}}function Dv(t,e,n,s){const{pivot:i,angle:r,lift:o}=Bf(e,n,s),a=d=>{const f=Ai(d,i,r);return{x:f.x,y:f.y-o}},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=_f*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+r,right:t.handAngle.right+r},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+r}}}function Bv(t,e){const n=me(t.lean),s=me(e.headTilt),i={x:0,y:t.hipY},r=k=>({x:t.facing*k.x,y:k.y}),o=k=>r(Ai(k,i,n)),a=k=>o(Wv(t,k)),l=k=>a(Ai({x:k.x,y:k.y+t.neckY},{x:0,y:t.neckY},s)),c=Ei(t.arms.left,t.rubber).map(a),h=Ei(t.arms.right,t.rubber).map(a),u=(k,S)=>Math.atan2(S.y-k.y,S.x-k.x),d={left:a(t.handTips.left),right:a(t.handTips.right)},f=(k,S)=>{const[x,M]=k.slice(-2),E=t.arms[S],T=u(a(E.end),d[S])-u(a(E.joint),a(E.end));return u(x,M)+T};let m=1/0;for(const[k,S]of[[e.leftBrow,e.leftEye],[e.rightBrow,e.rightEye]]){const x=Ff(Vl,1,k,Hf(S,e.blink));m=Math.min(m,x,x-e.browTilt*.1)}const g={left:r(t.legs.left.end),right:r(t.legs.right.end)},p={left:r(t.toes.left),right:r(t.toes.right)},y={left:Math.max(g.left.y,p.left.y),right:Math.max(g.right.y,p.right.y)},v=Math.max(y.left,y.right),w=_f*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:r(t.legs.left.joint),right:r(t.legs.right.joint)},feet:g,toes:p,feetY:v,grounded:{left:y.left>=v-w,right:y.right>=v-w},fingertips:d,handAngle:{left:f(c,"left"),right:f(h,"right")},limbs:{leftArm:c,rightArm:h,leftLeg:Ei(t.legs.left,t.rubber).map(r),rightLeg:Ei(t.legs.right,t.rubber).map(r),spine:t.spine.map(o)},head:{center:l({x:0,y:-t.headRy}),rx:t.headRx,ry:t.headRy,angle:t.facing*(n+t.chest.bend+s),eyeY:Vl,browTopY:m,mouthY:Rf,faceX:t.facing*(Af+xf*Hn(e.turn))}}}function Ee(t,e={}){return Df(Lf(t,e),t)}function zv(t,e,n){return Ai({x:t.center.x+e*t.rx,y:t.center.y+n*t.ry},t.center,t.angle)}function zf(t,e,n){const s=r=>({x:r.x+e,y:r.y+n}),i=r=>({left:s(r.left),right:s(r.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 qf(t,e,n={},s=0){const i=Lf(e,n),r=n.color??"#1e293b",o=n.layers??{},a=n.layers?Df(i,e,!1):void 0,l=n.sketch?Dr(t,n.sketch,s):void 0,c=n.sketch&&n.layers?Dr(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(me(i.lean)),t.translate(0,-i.hipY)},m=()=>{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,E,T)=>{if(l)return E?l.curve(M):l.line(M);if(i.classic){t.beginPath(),t.moveTo(M[0].x,M[0].y);for(const A of M.slice(1))t.lineTo(A.x,A.y);t.stroke();return}bi(t,M,T[0]*i.lineWidth,T[1]*i.lineWidth)},p=(M,E)=>g(Ei(M,i.rubber),i.rubber>0,E),y=M=>{i.classic||g([i.legs[M].end,i.toes[M]],!1,Av)},v=M=>{if(n.hands&&!i.classic)return k(M);if(i.classic||l)return;const E=i.arms[M].end;t.beginPath(),t.arc(E.x,E.y,Pv*i.lineWidth,0,Math.PI*2),t.fill()};t.save(),t.strokeStyle=r,t.fillStyle=r,t.lineWidth=i.lineWidth,t.lineCap="round",t.lineJoin="round";const w=Bf(i,e.spin??0,e.rise??0);(w.angle!==0||w.lift!==0)&&(t.translate(0,-w.lift),t.translate(w.pivot.x,w.pivot.y),t.rotate(w.angle),t.translate(-w.pivot.x,-w.pivot.y));function k(M){const E=n.hands??{},T=i.arms[M].end,A=i.handTips[M],P=n.headFill??"#ffffff";Yr(t,T,E[M]??Ct,{side:M,angle:Math.atan2(A.x-T.x,T.y-A.y)*180/Math.PI,size:(E.size??Cf)*i.height*Math.sqrt(i.stretch),skin:E.skin??(P==="none"?void 0:P),ink:r,lineWidth:i.lineWidth*.45,fingers:E.fingers,plump:E.plump,look:n.sketch?"pencil":"clean",seed:n.sketch?.seed},s)}const S=M=>{h(()=>{m(),p(i.arms[M],Ev),v(M)});const E=o.sleeve;E&&a&&h(()=>E(t,a,M,s,c))},x=Hn(e.turn)>_v;u(o.behind),h(()=>{d(),p(i.legs.left,If),y("left"),p(i.legs.right,If),y("right")}),x&&S("left"),h(()=>{f(),g(i.spine,i.spine.length>2,Tv)}),h(()=>{m();const{left:M,right:E}={left:i.arms.left.root,right:i.arms.right.root};if(M.x!==E.x)if(i.classic)g([M,E],!1,[1,1]);else{const T={x:(M.x+E.x)/2,y:M.y-.3*Math.abs(E.x-M.x)};g(Rn(M,T,E,1,8),!0,[1.1,1.1])}}),u(o.body),x||S("left"),S("right"),u(o.behindHead),h(()=>{m(),t.translate(0,i.neckY),t.rotate(me(e.headTilt));const M=-i.headRy;t.beginPath(),t.ellipse(0,M,i.headRx,i.headRy,0,0,Math.PI*2);const E=n.headFill??"#ffffff";if(E!=="none"&&(t.fillStyle=E,t.fill()),l){l.ellipse(0,M,i.headRx,i.headRy);const T=l.nudge();t.translate(T.x,T.y)}else t.stroke();t.translate(0,M),t.scale(i.headRx/i.r,i.headRy/i.r),Nv(t,e,i.r,0,r,i.lineWidth)}),u(o.overHead),u(o.front),t.restore(),n.label&&(t.save(),t.fillStyle=r,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 Jl(t,e,n,s){const i={...t},r=t.gait&&s?.[t.gait]||t.gait;let o=t.walking>0?gs(i,yf(r,t.walk,i),t.walking):i,a=qv(t);const l=t.dancing??0;if(n&&l>0){const c=n(t.beat??0);if(o=gs(o,c.pose,l),c.hands){const h=(u,d)=>d?fs(u??Ct,d,l):u;a={left:h(a?.left,c.hands.left),right:h(a?.right,c.hands.right)}}}return t.talk>0&&(o={...o,mouth:Math.max(o.mouth,t.talk*Sf(e))}),{pose:o,hands:a}}function jf(t,e,n,s){return Jl(t,e,n,s).pose}const Kf=(t,e)=>(t.facing??e.facing??1)<0?-1:1,xi=(t,e)=>`hand.${t}.${e}`;function qv(t){const e=i=>{if(typeof t[xi(i,"spread")]=="number")return Object.fromEntries(Object.keys(Ct).map(r=>[r,t[xi(i,r)]]))},n=e("left"),s=e("right");return n||s?{left:n,right:s}:void 0}function jv(t,e){return!e||!t.hands?t:{...t,hands:{...t.hands,left:e.left??t.hands.left,right:e.right??t.hands.right}}}function Zl(t){const e=t.style??{},n=e.height??300,s=n*.8,i={...Bt(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},r={};if(e.hands)for(const o of["left","right"]){const a=e.hands[o]??Ct;for(const l of Object.keys(Ct))r[xi(o,l)]=a[l]??Ct[l]}return{type:"custom",x:t.x-s/2,y:t.y-n,width:s,height:n,props:{...i,...r},about:Kv(Object.keys(r),t.cast),figureStyle:e,figureDance:t.dance,figureGaits:t.cast?.gaits,draw(o,a,l){const c=a.props,h=Jl(c,l,t.dance,t.cast?.gaits);o.translate(s/2,n),qf(o,h.pose,jv({...e,rubber:c.rubber,facing:Kf(c,e)},h.hands),l)}}}function Kv(t,e){const n={...Zd,...Qd};for(const s of t){const[,i,...r]=s.split("."),o=tf[r.join(".")];o&&(n[s]={...o,description:`${i==="left"?"Left":"Right"} hand: ${o.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 B5(e)}}}function Ql(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 r=0,o=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"?r=h:c==="y"||c==="motionPathY"?o=h:c in i&&(i[c]=h));const a=jf(i,e.time,t.figureDance,t.figureGaits),l=Ee(a,{...s,rubber:i.rubber,facing:Kf(i,s)});return{pose:a,joints:zf(l,t.x+r+t.width/2,t.y+o+t.height)}}function Vr(t){const e=[];return t.forEach((n,s)=>{const i=s===0?ut:e[s-1],r=typeof n.pose=="string"?he[n.pose]:{...i,...n.pose};e.push(n.expression?an(r,n.expression):r)}),e}function Yv(t,e){const n=Vr(e);return wf.filter(s=>n.some(i=>i[s]!==ut[s])).map(s=>({id:`${t}-${s}`,target:t,property:s,keyframes:e.map((i,r)=>({time:i.time,value:n[r][s],...i.easing?{easing:i.easing}:{}}))}))}const tc=.5,Jr={pataka:Wt({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:0,turn:2}),tripataka:Wt({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":1,"pinky.curl":0,spread:0,turn:2}),alapadma:Wt({"thumb.curl":.1,"thumb.across":0,"index.curl":.05,"middle.curl":.15,"ring.curl":.25,"pinky.curl":.35,spread:1,turn:2}),mushti:Tt.fist,shikhara:Tt.thumbsUp,hamsasya:Wt({"thumb.curl":.15,"thumb.across":.6,"index.curl":.6,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:.7,turn:2}),katakamukha:Wt({"thumb.curl":.2,"thumb.across":.6,"index.curl":.65,"middle.curl":.7,"ring.curl":0,"pinky.curl":0,spread:.4,turn:2})};function Zr(t){return typeof t!="string"?t:t in Jr?Jr[t]:Tt[t]}function Yf(t,e,n){const s=[];for(const i of t.keys){const r=s[s.length-1],o=!r||i.reset?{pose:e,...n}:r;s.push({beat:i.beat,pose:{...o.pose,...i.pose},left:i.hands?.left?Zr(i.hands.left):o.left,right:i.hands?.right?Zr(i.hands.right):o.right,easing:i.easing??t.easing})}return s}const ec=(t,e)=>(t%e+e)%e;function Xv(t,e,n,s){const i=Yf(t,n,s);if(i.length===0)return{pose:n,hands:s};const r=ec(e,t.beats);let o=i.length-1;for(let f=0;f<i.length;f++)i[f].beat<=r&&(o=f);const a=i[o],l=i[(o+1)%i.length],c=a.beat<=r?a.beat:a.beat-t.beats,h=l.beat>c?l.beat:l.beat+t.beats,u=h>c?(r-c)/(h-c):0,d=Dt(l.easing??"ease-in-out")(Math.min(1,Math.max(0,u)));return{pose:gs(a.pose,l.pose,d),hands:{left:fs(a.left,l.left,d),right:fs(a.right,l.right,d)}}}const Gv=[["leftShoulder","rightShoulder"],["leftElbow","rightElbow"],["leftWrist","rightWrist"],["leftHip","rightHip"],["leftKnee","rightKnee"],["leftAnkle","rightAnkle"],["leftFootOut","rightFootOut"],["leftEye","rightEye"],["leftBrow","rightBrow"]],Uv=["lean","headTilt","lookX","spin"],Vv=new Set(["leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee"]);function Xf(t){const e={...t},n=(t.turn??0)>=.5;for(const[s,i]of Gv){const r=n&&Vv.has(s)?-1:1;e[s]=r*t[i],e[i]=r*t[s]}if(!n)for(const s of Uv)e[s]=-t[s];return e}const Jv=t=>Math.min(1,Math.max(-1,(.5-t)*4));function Gf(t,e,n){const s=ec(n,1),i=(1+Math.cos(2*Math.PI*s))/2,r=e.bounce*(e.accent==="up"?1-i:i),o=Math.min(1,Math.max(0,t.turn??0)),a=Jv(o);return{...t,leftHip:t.leftHip+a*r/2,rightHip:t.rightHip+r/2,leftKnee:t.leftKnee+a*r,rightKnee:t.rightKnee+r,lean:t.lean+(e.sway??0)*(1-o)*Math.sin(Math.PI*n)}}function Qr(t){const e={...ut,...t.stance};return t.expression?an(e,t.expression):e}function Uf(t){return{left:t.hands?.left?Zr(t.hands.left):Ct,right:t.hands?.right?Zr(t.hands.right):Ct}}function nc(t,e,n){const s=t.moves[e.move];if(!s)throw new Error(`dance: "${t.label}" has no move "${e.move}"`);const i=Xv(s,n,Qr(t),Uf(t));return e.mirror?{pose:Xf(i.pose),hands:{left:i.hands?.right,right:i.hands?.left}}:i}function to(t,e,n={}){const s=typeof t=="string"?ln[t]:t;let i;if(n.move)i=nc(s,{move:n.move,mirror:n.mirror},e);else{const r=s.routine,o=r.reduce((u,d)=>u+d.beats,0),a=ec(e,o);let l=0,c=0;for(;c<r.length-1&&a>=l+r[c].beats;)l+=r[c++].beats;const h=a-l;if(i=nc(s,r[c],h),h<tc&&r.length>1&&e>=tc){const u=r[(c-1+r.length)%r.length],d=nc(s,u,u.beats+h),f=Dt("ease-in-out")(h/tc);i={pose:gs(d.pose,i.pose,f),hands:{left:fs(d.hands.left,i.hands.left,f),right:fs(d.hands.right,i.hands.right,f)}}}}return{...i,pose:Gf(i.pose,s.groove,e)}}function Zv(t,e,n={}){return to(t,e,n).pose}function eo(t){return(typeof t=="string"?ln[t]:t).routine.reduce((n,s)=>n+s.beats,0)}const Qv={leftToe:"rightToe",rightToe:"leftToe",leftHeel:"rightHeel",rightHeel:"leftHeel"};function Vf(t,e,n,s,i,r,o){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<r||h>=o))for(const u of l.taps??[])i.push({beat:h,tap:s?Qv[u]:u})}}function tM(t,e,n,s={}){const i=typeof t=="string"?ln[t]:t,r=[];if(n<=e)return r;if(s.move){const o=i.moves[s.move],a=Math.floor(e/o.beats)*o.beats;Vf(o,a,Math.ceil((n-a)/o.beats)*o.beats,s.mirror,r,e,n)}else{const o=eo(i);for(let a=Math.floor(e/o)*o;a<n;a+=o){let l=a;for(const c of i.routine)Vf(i.moves[c.move],l,c.beats,c.mirror,r,e,n),l+=c.beats}}return r.sort((o,a)=>o.beat-a.beat)}function Jf(t,e){const n=t.moves[e.move];if(!n?.travel)return 0;const s=n.travel/n.beats;return e.mirror?(Yf(n,Qr(t),Uf(t))[0]?.pose.turn??Qr(t).turn??0)>=.5?s:-s:s}function Zf(t,e){return e.move?[{move:e.move,beats:t.moves[e.move].beats,mirror:e.mirror}]:t.routine}function no(t,e,n={}){const s=typeof t=="string"?ln[t]:t,i=Zf(s,n),r=i.reduce((h,u)=>h+u.beats,0),o=i.reduce((h,u)=>h+Jf(s,u)*u.beats,0),a=Math.floor(e/r);let l=a*o,c=e-a*r;for(const h of i){const u=Math.min(h.beats,c);if(l+=Jf(s,h)*u,c-=u,c<=0)break}return l}function eM(t,e,n){const s=Zf(t,n),i=[0];let r=0;for(let o=0;r<e;o=(o+1)%s.length)r+=s[o].beats,i.push(Math.min(r,e));return i}const nM=8;function Qf(t,e,n){const s=typeof e=="string"?ln[e]:e,i=n.bpm??s.bpm,r=n.beats??(n.move?s.moves[n.move].beats:eo(s)),o=eM(s,r,n);if(o.every(y=>no(s,y,n)===0))return;const a=Math.min(n.fade??1,r/2),l=Dt("ease-in-out"),c=y=>a<=0?1:Math.min(l(Math.min(1,y/a)),l(Math.min(1,(r-y)/a))),h=Math.ceil(a*nM),u=a<=0?[]:Array.from({length:h+1},(y,v)=>[v/h*a,r-v/h*a]).flat(),d=[...new Set([...o,...u])].sort((y,v)=>y-v);let f=0;const m=d.map((y,v)=>{if(v>0){const w=d[v-1],k=Math.max(1,Math.ceil((y-w)*16));for(let S=0;S<k;S++){const x=w+(y-w)*S/k,M=w+(y-w)*(S+1)/k;f+=(no(s,M,n)-no(s,x,n))*c((x+M)/2)}}return{beat:y,travel:f}}),g=n.start??0,p=n.x??0;return{id:`${t}-x`,target:t,property:"x",keyframes:m.map(y=>({time:g+y.beat*6e4/i,value:p+n.height*y.travel,easing:"linear"}))}}function sM(t,e,n=0){return(t-n)*e/6e4}function iM(t,e={}){return n=>to(t,n,e)}function rM(t,e){const n=e.start??0,s=6e4/e.bpm,i=n+e.beats*s,r=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+r,value:1,easing:"ease-in-out"},{time:i-r,value:1},{time:i,value:0,easing:"ease-in-out"}]}]}function oM(t,e,n={}){const s=typeof e=="string"?ln[e]:e,i=n.bpm??s.bpm,r=n.beats??(n.move?s.moves[n.move].beats:eo(s)),o=n.samplesPerBeat??4,a=n.start??0,l=Math.round(r*o),c=Array.from({length:l+1},(g,p)=>{const y=p/o;return{time:a+y*6e4/i,frame:to(s,y,n)}}),h=(g,p)=>({id:`${t}-${g}`,target:t,property:g,keyframes:c.map(y=>({time:y.time,value:p(y.frame)}))}),d=Object.keys(ut).filter(g=>c.some(p=>p.frame.pose[g]!==c[0].frame.pose[g])||c[0].frame.pose[g]!==ut[g]).map(g=>h(g,p=>p.pose[g])),f=n.height===void 0?void 0:Qf(t,s,{...n,bpm:i,beats:r,start:a,height:n.height,fade:0});if(f&&d.push(f),n.hands===!1)return d;const m=[];for(const g of["left","right"])for(const p of Object.keys(Ct)){const y=v=>v.hands?.[g]?.[p]??Ct[p];c.some(v=>y(v.frame)!==Ct[p])&&m.push(h(xi(g,p),y))}return[...d,...m]}const Pi={type:"back",mode:"out",overshoot:1.1},te="ease-out-cubic",aM={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:te,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:te},{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:te},{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}]},lM={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}]},cM={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:te},{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:te},{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:te},{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:Pi},{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}]},hM={label:"Jazz",bpm:130,stance:{leftHip:10,rightHip:10},expression:{mouth:.55,smile:1,mouthWidth:1.2,leftBrow:.6,rightBrow:.6},hands:{left:"spread",right:"spread"},groove:{bounce:6,accent:"up"},moves:{jazzHands:{label:"Jazz hands",beats:2,easing:"linear",keys:[0,.25,.5,.75,1,1.25,1.5,1.75].map((t,e)=>({beat:t,pose:{leftShoulder:128,rightShoulder:128,leftElbow:8,rightElbow:8,leftWrist:e%2?4:26,rightWrist:e%2?26:4,leftHip:16,rightHip:16,leftKnee:t<1?26:8,rightKnee:t<1?26:8},hands:e===0?{left:{...Tt.spread,turn:2},right:{...Tt.spread,turn:2}}:void 0}))},kickBallChange:{label:"Kick ball change",beats:2,keys:[{beat:0,reset:!0,pose:{rightHip:88,rightKnee:0,rightAnkle:55,leftHip:4,lean:-12,leftShoulder:112,rightShoulder:112,leftWrist:15,rightWrist:15},hands:{left:"flat",right:"flat"},easing:te},{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}]},uM={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:Pi,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:Pi},{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:Pi},{beat:3,pose:{headTilt:4}}]},isolations:{label:"Isolations",beats:2,easing:te,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}]},dM={label:"Bollywood",bpm:120,stance:{leftHip:10,rightHip:10},expression:{smile:1,mouth:.3,leftBrow:.4,rightBrow:.4},groove:{bounce:8,accent:"down",sway:3},moves:{lightBulb:{label:"Screw the bulb, pat the dog",beats:2,keys:[{beat:0,reset:!0,pose:{rightShoulder:160,rightElbow:12,rightWrist:-15,leftShoulder:40,leftElbow:-12,leftWrist:-45,lean:-4,rightHip:16,lookX:.5,lookY:-.6},hands:{right:{...Tt.cupped,roll:-30},left:{...Tt.flat,turn:0}}},{beat:.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{...Tt.cupped,roll:30}}},{beat:1,pose:{rightWrist:-15,rightElbow:12,leftWrist:-45,lean:-4,rightHip:16,leftHip:6},hands:{right:{...Tt.cupped,roll:-30}}},{beat:1.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{...Tt.cupped,roll:30}}}]},thumka:{label:"Thumka",beats:2,keys:[{beat:0,reset:!0,pose:{lean:-11,rightHip:22,leftHip:2,leftKnee:14,rightShoulder:45,rightElbow:-105,leftShoulder:128,leftElbow:18,leftWrist:35,headTilt:10,lookX:-.5},hands:{right:"fist",left:{...Tt.open,turn:2}},easing:te},{beat:.5,pose:{lean:-4,rightHip:12,headTilt:6}},{beat:1,pose:{lean:-11,rightHip:22,headTilt:10},easing:te},{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:te},{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:te}]}},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}]},fM={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}]},gM={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}]},mM={label:"Charleston",bpm:150,stance:{leftHip:10,rightHip:10,leftKnee:10,rightKnee:10,leftShoulder:30,rightShoulder:30,leftElbow:20,rightElbow:20},expression:{mouth:.4,smile:1,leftBrow:.5,rightBrow:.5},hands:{left:{...Tt.spread,turn:2},right:{...Tt.spread,turn:2}},groove:{bounce:8,accent:"down"},moves:{basic:{label:"Kick forward, kick back",beats:4,keys:[{beat:0,reset:!0,pose:{rightHip:48,rightKnee:8,rightAnkle:45,leftShoulder:75,rightShoulder:15,leftElbow:30,rightElbow:-10,lean:-7,headTilt:-5},easing:te},{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:te},{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}]},pM={label:"Tap",bpm:120,stance:{turn:.8,leftHip:-3,rightHip:3,leftKnee:-10,rightKnee:10,leftShoulder:12,rightShoulder:12,leftElbow:-40,rightElbow:40,leftWrist:-15,rightWrist:15,lean:4},expression:{smile:.9,mouth:.2,leftBrow:.3,rightBrow:.3,lookY:.3},hands:{left:"relaxed",right:"relaxed"},groove:{bounce:6,accent:"down"},moves:{shuffleBallChange:{label:"Shuffle ball change",beats:2,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:34,rightKnee:8,rightAnkle:30,leftShoulder:30,rightShoulder:-10},taps:["rightToe"]},{beat:.25,pose:{rightHip:24,rightKnee:62,rightAnkle:40},taps:["rightToe"]},{beat:.5,pose:{rightHip:-8,rightKnee:14,rightAnkle:50,leftAnkle:15,leftShoulder:12,rightShoulder:12},taps:["rightToe"]},{beat:.75,pose:{rightHip:3,rightKnee:10,rightAnkle:0,leftAnkle:0},taps:["leftHeel"]},{beat:1,reset:!0,pose:{leftHip:-34,leftKnee:-8,leftAnkle:30,rightShoulder:-30,leftShoulder:10},taps:["leftToe"]},{beat:1.25,pose:{leftHip:-24,leftKnee:-62,leftAnkle:40},taps:["leftToe"]},{beat:1.5,pose:{leftHip:8,leftKnee:-14,leftAnkle:50,rightAnkle:15,leftShoulder:12,rightShoulder:12},taps:["leftToe"]},{beat:1.75,pose:{leftHip:-3,leftKnee:-10,leftAnkle:0,rightAnkle:0},taps:["rightHeel"]}]},timeStep:{label:"Single time step",beats:4,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:8,rightKnee:4,rightAnkle:0,leftShoulder:25,rightShoulder:-20},taps:["rightToe","rightHeel"]},{beat:.5,pose:{rightHip:34,rightKnee:8,rightAnkle:30},taps:["rightToe"]},{beat:.75,pose:{rightHip:22,rightKnee:62,rightAnkle:40},taps:["rightToe"]},{beat:1,pose:{rise:.05,leftAnkle:45,leftKnee:-4,leftHip:-2,rightHip:26,rightKnee:70,stretch:1.03}},{beat:1.25,pose:{rise:0,leftAnkle:0,leftKnee:-14,stretch:1},taps:["leftToe"]},{beat:1.5,pose:{rightHip:4,rightKnee:12,rightAnkle:0,rightShoulder:25,leftShoulder:-20},taps:["rightToe"]},{beat:2,pose:{leftHip:-30,leftKnee:-6,leftAnkle:35},taps:["leftToe"]},{beat:2.25,pose:{leftHip:-4,leftKnee:-12,leftAnkle:0},taps:["leftToe"]},{beat:3,pose:{rightHip:10,rightAnkle:35,rightKnee:18,leftShoulder:12,rightShoulder:12},taps:["rightToe"]},{beat:3.5,pose:{rightHip:3,rightKnee:10,rightAnkle:0}}]},heelToe:{label:"Heel toe",beats:2,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:26,rightKnee:0,rightAnkle:-35,leftShoulder:30,rightShoulder:-20},taps:["rightHeel"]},{beat:.5,pose:{rightHip:-16,rightKnee:24,rightAnkle:55,leftShoulder:-15,rightShoulder:25},taps:["rightToe"]},{beat:1,reset:!0,pose:{leftHip:-26,leftKnee:0,leftAnkle:-35,rightShoulder:-30,leftShoulder:20},taps:["leftHeel"]},{beat:1.5,pose:{leftHip:16,leftKnee:-24,leftAnkle:55,rightShoulder:15,leftShoulder:-25},taps:["leftToe"]}]},crampRoll:{label:"Cramp roll",beats:2,easing:"ease-out-quad",keys:[{beat:0,reset:!0,pose:{rightHip:12,rightKnee:26,leftHip:-12,leftKnee:-26}},{beat:.5,pose:{rightAnkle:40,rise:.02},taps:["rightToe"]},{beat:.625,pose:{leftAnkle:40},taps:["leftToe"]},{beat:.75,pose:{rightAnkle:0,rise:0},taps:["rightHeel"]},{beat:.875,pose:{leftAnkle:0},taps:["leftHeel"]},{beat:1,pose:{rightShoulder:135,leftShoulder:125,leftElbow:0,rightElbow:0,leftWrist:0,rightWrist:30,rightKnee:8,leftKnee:-8,rightHip:4,leftHip:-4},hands:{left:{...Tt.spread,turn:2},right:{...Tt.spread,turn:2}}},{beat:1.75,reset:!0}]}},routine:[{move:"shuffleBallChange",beats:8},{move:"timeStep",beats:4},{move:"timeStep",beats:4,mirror:!0},{move:"heelToe",beats:8},{move:"crampRoll",beats:4}]},ln={disco:aM,hipHop:lM,breaking:cM,jazz:hM,kpop:uM,bollywood:dM,bhangra:fM,bharatanatyam:gM,charleston:mM,tap:pM,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:Pi},{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}]}},so={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}},sc=.215,ic=.205,yM=.065,tg=.035,bM=.165,wM=.155,kM=12,vM=.3,MM=.7,SM=.35,TM=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 vt(t={}){return{...lt,...t}}const EM=new Set(["turn","side","head.turn","head.tilt","roll","lookX","hair.swing"]);function eg(t){const e={};for(const[n,s]of Object.entries(t)){const i=n.replace(/(^|\.)(left|right)(\.|$)/,(r,o,a,l)=>`${o}${a==="left"?"right":"left"}${l}`);e[i]=EM.has(n)?-s:s}return e}function $t(t,e){const n={};for(const s of["left","right"])for(const[i,r]of Object.entries(e))n[`${t}.${s}.${i}`]=r;return n}const Ae={rest:lt,wave:vt({"arm.right.spread":115,"arm.right.bend":55,"arm.right.elbow":0,"head.tilt":-6,smile:.9}),cheer:vt({...$t("arm",{spread:140,bend:20,elbow:0}),mouth:.6,smile:1,"eye.left":0,"eye.right":0}),point:vt({"arm.right.spread":88,"arm.right.elbow":0,"arm.right.bend":0,"head.turn":-20,smile:.4}),handsOnHips:vt({...$t("arm",{spread:50,bend:-105,elbow:0}),...$t("leg",{spread:9}),smile:.8}),think:vt({"arm.right.spread":22,"arm.right.bend":-150,"arm.right.elbow":0,"head.tilt":10,lookX:-.5,lookY:-.8,smile:0}),shrug:vt({...$t("arm",{spread:35,bend:75,elbow:0}),"head.tilt":-10,smile:-.2}),sit:vt({...$t("leg",{swing:90,knee:90,spread:4}),...$t("arm",{swing:25,elbow:45,spread:8})}),kneel:vt({"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:vt({...$t("leg",{swing:75,knee:140,spread:6}),lean:25,...$t("arm",{swing:50,elbow:40}),"head.nod":-15}),crawl:vt({lean:82,"head.nod":-35,...$t("arm",{swing:80,elbow:0,spread:4}),...$t("leg",{knee:92,ankle:-88})}),lieDown:vt({roll:90,...$t("arm",{spread:8}),"head.nod":0}),sleep:vt({roll:90,...$t("arm",{spread:8,swing:20,elbow:40}),"leg.left.knee":20,"leg.left.swing":15,blink:1,smile:.2}),stretch:vt({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:vt({...$t("leg",{swing:80,spread:22,rotate:75,knee:145}),...$t("arm",{swing:25,spread:18,elbow:30}),lean:5,smile:.5}),carry:vt({...$t("arm",{spread:16,elbow:4}),lean:-3,smile:.4}),cane:vt({"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:vt({...$t("arm",{swing:28,spread:24,elbow:85,bend:-45}),...$t("leg",{swing:12,knee:22,spread:6}),lean:-4,smile:.2}),push:vt({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:vt({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:vt({"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:vt({"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:vt({...$t("arm",{swing:32,spread:10,elbow:82,bend:-28}),"head.nod":22,lookY:.8,smile:.2}),type:vt({...$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})},ng=["round","flat","pointed","big"],AM={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 rc(t={}){const e=t.headSize??.3,n=t.shoulderWidth??.06,s=t.hipWidth??.022,i=t.legLength??1,r=t.armLength??1,o=AM[t.feet??"round"],a=Math.max(.12,1-e-tg-(sc+ic)*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:bM*r,width:[1.25,.9]},{length:wM*r,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:sc*i,width:[1.45,1.05]},{length:ic*i,width:[1.05,.85]},{length:yM*Math.sqrt(i)*o.length,width:o.width}]}),h=(u,d)=>u[d]??lt[d]??0;return{id:"human",hipHeight:(sc+ic)*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:tg,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,w=h(u,"side")/2,k=-h(u,"bend");return[{swing:v+k*vM,spread:w},{swing:v+k*MM,spread:w}]}if(d.id==="neck")return[{swing:-h(u,"bend")*SM,spread:0}];const[f,m]=d.id.split("."),g=v=>h(u,`${f}.${m}.${v}`);if(f==="arm")return[{swing:g("swing"),spread:g("spread")},{swing:g("elbow"),spread:g("bend")}];const p=(d.side??1)*g("rotate"),y=1-Math.cos(TM(g("rotate")));return[{swing:g("swing"),spread:g("spread"),yaw:p},{swing:-g("knee"),spread:0,yaw:p},{swing:90+g("ankle")-y*(g("swing")-g("knee")),spread:0,yaw:(kM+g("toeOut"))*(d.side??1)}]},withAngles(u,d,f){const[m,g]=d.id.split("."),p=y=>`${m}.${g}.${y}`;return m==="arm"?{...u,[p("swing")]:f[0].swing,[p("spread")]:f[0].spread,[p("elbow")]:f[1].swing,[p("bend")]:f[1].spread}:m==="leg"?{...u,[p("swing")]:f[0].swing,[p("spread")]:f[0].spread,[p("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 xM(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"},r=e.slice(2).join(".");return`${s} · ${i[r]??r.replace(".curl"," curl").replace(".across"," across")}`}if(e.length===3){const[s,i,r]=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"}[r]??r}`}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 PM={leftEye:"eye.left",rightEye:"eye.right",leftBrow:"brow.left",rightBrow:"brow.right"},$M={blush:0,tears:0,sweat:0,pupil:1,lid:0,bulge:0},Fn=Object.fromEntries(Object.entries(Mt).map(([t,e])=>[t,{...Object.fromEntries(Object.entries(e).map(([n,s])=>[PM[n]??n,s])),...$M}]));Fn.crying.tears=1,Fn.scared.sweat=.8,Fn.scared.bulge=.4,Fn.sleepy.lid=.5,Fn.worried.sweat=.6;const pe=t=>({...Fn.neutral,...t}),oc={...Fn,laughing:pe({mouth:.75,smile:1,mouthWidth:1.25,"eye.left":0,"eye.right":0,"brow.left":.5,"brow.right":.5}),afraid:pe({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:pe({smile:-.05,mouthWidth:.6,"eye.left":.45,"eye.right":.45,"brow.left":-.4,"brow.right":-.4,lookX:.5}),tired:pe({mouth:.2,smile:-.3,mouthWidth:.7,"eye.left":.3,"eye.right":.3,"brow.left":-.1,"brow.right":-.1,browTilt:.6,lookY:.6}),embarrassed:pe({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:pe({smile:.75,mouthWidth:1,"eye.left":.75,"eye.right":.75,"brow.left":.5,"brow.right":.5,lookY:-.2}),determined:pe({smile:.35,mouthWidth:.8,"eye.left":.85,"eye.right":.85,"brow.left":-.5,"brow.right":-.5,browTilt:-.9}),affectionate:pe({smile:.85,"eye.left":0,"eye.right":0,"brow.left":.3,"brow.right":.3,blush:.8}),hurt:pe({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:pe({smile:-.25,mouthWidth:.7,"eye.left":.5,"eye.right":.85,"brow.left":-.6,"brow.right":.4,browTilt:-.3,lookX:.8,lid:.3}),relieved:pe({smile:.7,"eye.left":0,"eye.right":0,"brow.left":.4,"brow.right":.4,browTilt:.4}),excited:pe({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})},ye=t=>t*Math.PI/180;function sg([t,e,n],s){const i=Math.cos(s),r=Math.sin(s);return[t,e*i+n*r,-e*r+n*i]}function $i([t,e,n],s){const i=Math.cos(s),r=Math.sin(s);return[t*i-e*r,t*r+e*i,n]}function ee([t,e,n],s){const i=Math.cos(s),r=Math.sin(s);return[t*i+n*r,e,-t*r+n*i]}const Be=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],io=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],ro=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],ac=[[1,0,0],[0,1,0],[0,0,1]],Ii=([t,e,n],s)=>[t*s[0][0]+e*s[1][0]+n*s[2][0],t*s[0][1]+e*s[1][1]+n*s[2][1],t*s[0][2]+e*s[1][2]+n*s[2][2]],ig=(t,e)=>[io(t,e[0]),io(t,e[1]),io(t,e[2])];function IM(t,e,n){const s=Math.hypot(e,n);if(s<1e-12)return t;const i=[-e/s,0,n/s],r=Math.cos(s),o=Math.sin(s),a=[i[1]*t[2]-i[2]*t[1],i[2]*t[0]-i[0]*t[2],i[0]*t[1]-i[1]*t[0]],l=io(i,t)*(1-r);return[t[0]*r+a[0]*o+i[0]*l,t[1]*r+a[1]*o+i[1]*l,t[2]*r+a[2]*o+i[2]*l]}const rg=(t,e,n)=>ac.map(s=>Ii(IM(s,e,n),t));function og(t,e={swing:0,spread:0}){const n=Math.hypot(t[0],t[2]);if(n<1e-12)return t[1]<=0?{swing:0,spread:0}:{swing:Math.PI,spread:0};const s=Math.atan2(n,-t[1]),i={swing:s*t[2]/n,spread:s*t[0]/n},r=s-2*Math.PI,o={swing:r*t[2]/n,spread:r*t[0]/n},a=l=>Math.hypot(l.swing-e.swing,l.spread-e.spread);return a(o)<a(i)-1e-9?o:i}function oo(t,e){const n=ee(t,e);return{point:{x:n[0],y:-n[1]},depth:n[2]}}function ms(t,e,n){const s=n,r=[0,t.hipHeight*s*(t.boneScale?.(e,null)??1),0],o={};for(const g of t.chains){const p=g.parent?o[g.parent]:void 0;if(g.parent&&!p)throw new Error(`body plan ${t.id}: chain ${g.id} comes before its parent ${g.parent}`);const y=g.at??(p?p.joints3.length-1:0),v=p?p.joints3[y]:r,w=p?p.frames[Math.max(0,y-1)]:ac,k=g.offset?Be(v,Ii(ro(g.offset,s),w)):v,S=g.side??1,x=t.boneScale?.(e,g)??1,M=t.angles(e,g),E=[k],T=[];let A=w;g.bones.forEach((P,I)=>{const O=M[I]??{swing:0,spread:0};A=rg(A,ye(O.swing),ye(O.spread)*S),T.push(A);const _=ee(Ii(g.rest,A),ye(O.yaw??0));E.push(Be(E[I],ro(_,P.length*s*x)))}),o[g.id]={joints3:E,frames:T}}const a=o[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=>Ii(ee(sg($i(g,-ye(l.tilt)),-ye(l.nod)),ye(l.yaw)),c),m=Be(a.joints3[a.joints3.length-1],f([0,d,0]));return{height:s,root:r,chains:o,head:{center:m,rx:u,ry:d,toBody:f}}}function lc(t,e,n){const s=n.height,i=ye(90*(e.turn??0)),r=ms(t,e,s),{root:o}=r,a=r.chains,{rx:l,ry:c}=r.head,h=r.head.toBody,u=r.head.center,d={};for(const T of t.chains){const{joints3:A,frames:P}=a[T.id],I=A.map(O=>oo(O,i));d[T.id]={id:T.id,joints3:A,frames:P,points:I.map(O=>O.point),depths:I.map(O=>O.depth)}}const f=oo(u,i),m=[[1,0,0],[0,1,0],[0,0,1]].map(T=>ee(h(T),i)),g=oo(o,i).point,p=ye(e.roll??0),y=T=>{const A=T.x-g.x,P=T.y-g.y;return{x:g.x+A*Math.cos(p)-P*Math.sin(p),y:g.y+A*Math.sin(p)+P*Math.cos(p)}},v=([T,A,P])=>[T*Math.cos(p)+A*Math.sin(p),-T*Math.sin(p)+A*Math.cos(p),P];for(const T of Object.values(d))T.points=T.points.map(y);const w={center:y(f.point),depth:f.depth,rx:l,ry:c,angle:0,axes:m.map(v)},k=w.axes[1];w.angle=Math.atan2(k[0],k[1]);const S=T=>{if("head"in T)return{x:w.center.x+k[0]*c,y:w.center.y-k[1]*c};const A=d[T.chain];return A.points[Math.min(T.joint,A.points.length-1)]};let x=0;(n.contact??"ground")==="ground"&&(x=-Math.max(...t.contacts.map(T=>S(T).y))),x-=(e.lift??0)*s;const M=T=>({x:T.x,y:T.y+x});for(const T of Object.values(d))T.points=T.points.map(M);w.center=M(w.center);const E=t.contacts.map(T=>({spec:T,point:S(T)}));return{height:s,view:i,chains:d,head:w,hip:M(y(g)),hipDepth:oo(o,i).depth,contacts:E,groundY:Math.max(...E.map(T=>T.point.y))}}const ao=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],cc=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function cn(t,e,n){const s=n.height,i=ye(90*(e.turn??0)),r=ye(e.roll??0),o=ms(t,e,s),a=ee(o.root,i),l=p=>Be($i(ao(ee(p,i),a),-r),a),c={};for(const p of t.chains)c[p.id]=o.chains[p.id].joints3.map(l);const h=l(o.head.center),u=p=>cc(ao(l(Be(o.head.center,o.head.toBody(p))),h)),d=[u([1,0,0]),u([0,1,0]),u([0,0,1])],f=p=>{if("head"in p)return Be(h,ro(d[1],o.head.ry));const y=c[p.chain];return y[Math.min(p.joint,y.length-1)]};let m=0;(n.contact??"ground")==="ground"&&(m=-Math.min(...t.contacts.map(p=>f(p)[1]))),m+=(e.lift??0)*s;const g=p=>[p[0],p[1]+m,p[2]];return{height:s,hip:g(a),chains:Object.fromEntries(Object.entries(c).map(([p,y])=>[p,y.map(g)])),head:{center:g(h),rx:o.head.rx,ry:o.head.ry,axes:d}}}function lo(t,e,n,s){const i=n.height,r=ye(90*(e.turn??0)),o=ms(t,e,i),a=cn(t,e,n),l=a.hip,c=a.chains,h=a.head.center,u=P=>{if("head"in P)return Be(h,ro(a.head.axes[1],a.head.ry));const I=c[P.chain];return I[Math.min(P.joint,I.length-1)]},d=s.toView(l),f=$i(ee([0,0,1],r),-ye(e.roll??0)),m=cc(ao(s.toView(Be(l,f)),d)),g=s.toScreen(d),p=s.toScreen([d[0]+1,d[1],d[2]]),y=Math.hypot(p.x-g.x,p.y-g.y),v=P=>{const I=s.toView(P);return{point:s.toScreen(I),depth:I[2]*y}},w={};for(const P of t.chains){const I=c[P.id].map(v);w[P.id]={id:P.id,joints3:o.chains[P.id].joints3,frames:o.chains[P.id].frames,points:I.map(O=>O.point),depths:I.map(O=>O.depth)}}const k=s.toView(h),S=s.toScreen(k),x=s.toScreen([k[0]+1,k[1],k[2]]),M=Math.hypot(x.x-S.x,x.y-S.y),E=a.head.axes.map(P=>cc(ao(s.toView(Be(h,P)),k))),T={center:S,depth:k[2]*y,rx:o.head.rx*M,ry:o.head.ry*M,angle:Math.atan2(E[1][0],E[1][1]),axes:E},A=t.contacts.map(P=>({spec:P,point:v(u(P)).point}));return{height:i*y,view:r,bodyForward:m,chains:w,head:T,hip:g,hipDepth:d[2]*y,contacts:A,groundY:Math.max(...A.map(P=>P.point.y))}}function hn(t,[e,n,s]){const[i,r,o]=t.axes,a=[i[0]*e*t.rx+r[0]*n*t.ry+o[0]*s*t.rx,i[1]*e*t.rx+r[1]*n*t.ry+o[1]*s*t.rx,i[2]*e*t.rx+r[2]*n*t.ry+o[2]*s*t.rx],l=Math.hypot(e,n,s)||1,c=(i[2]*e+r[2]*n+o[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 co=t=>t*180/Math.PI,ag=t=>t*Math.PI/180,Ln=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],hc=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],OM=(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]],ps=t=>Math.hypot(t[0],t[1],t[2]),lg=t=>{const e=ps(t)||1;return[t[0]/e,t[1]/e,t[2]/e]};function Oi(t,e,n,s,i){const r=t.chains.find(L=>L.id===n);if(!r)throw new Error(`reach: no chain ${n} in ${t.id}`);if(r.bones.length<2||r.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 o=lc(t,{...e,turn:0,roll:0,lift:0},{height:i.height,contact:"none"}),a=o.chains[n];if(ps(Ln(s,a.joints3[2]))<i.height*1e-12)return e;const l=a.joints3[0],c=ps(Ln(a.joints3[1],a.joints3[0])),h=ps(Ln(a.joints3[2],a.joints3[1])),u=r.parent?o.chains[r.parent].frames[Math.max(0,(r.at??o.chains[r.parent].joints3.length-1)-1)]:ac,d=Ln(s,l),f=t.angles(e,r),m=L=>(f[L]?.yaw??0)*Math.PI/180,g=Math.min(c+h-1e-6,Math.max(Math.abs(c-h)+1e-6,ps(d))),p=lg(d),y=r.parent!==null,v=ee(Ii(r.pole??(y?[0,-.35,-1]:[0,0,1]),u),m(0));let w=Ln(v,[p[0]*hc(v,p),p[1]*hc(v,p),p[2]*hc(v,p)]);ps(w)<1e-6&&(w=ee([1,0,0],m(0))),w=lg(w);const k=(c*c+g*g-h*h)/(2*c*g),S=Math.sqrt(Math.max(0,1-k*k)),x=[l[0]+p[0]*g,l[1]+p[1]*g,l[2]+p[2]*g],M=r.side??1,E=L=>({swing:ag(f[L]?.swing??0),spread:ag(f[L]?.spread??0)*M}),T=L=>{const j=OM(p,w),V=[w[0]*Math.cos(L)+j[0]*Math.sin(L),w[1]*Math.cos(L)+j[1]*Math.sin(L),w[2]*Math.cos(L)+j[2]*Math.sin(L)],tt=[l[0]+c*(k*p[0]+S*V[0]),l[1]+c*(k*p[1]+S*V[1]),l[2]+c*(k*p[2]+S*V[2])],J=og(ig(ee(Ln(tt,l),-m(0)),u),E(0)),F=rg(u,J.swing,J.spread),B=og(ig(ee(Ln(x,tt),-m(1)),F),E(1));return{upper:J,lower:B}};let A=0,P=T(A);if(!y){let L={swivel:.05,miss:T(.05).lower.spread};for(let j=0;j<40&&Math.abs(P.lower.spread)>1e-14;j++){const V=(P.lower.spread-L.miss)/(A-L.swivel);if(!Number.isFinite(V)||Math.abs(V)<1e-15)break;L={swivel:A,miss:P.lower.spread},A-=P.lower.spread/V,P=T(A)}}const{upper:I,lower:O}=P,_=[{swing:co(I.swing),spread:co(I.spread)*M},{swing:co(O.swing),spread:co(O.spread)*M}];return t.withAngles(e,r,_)}const ys=(t,e)=>(t%e+e)%e,cg=t=>t*t*(3-2*t),CM=t=>Object.fromEntries(["left","right"].flatMap(e=>Object.entries(Tt[t]).map(([n,s])=>[`hand.${e}.${n}`,s])));function uc(t,e=!1){const n=rc(),s=Oi(n,lt,"arm.left",[.015,.68,.2],{height:1}),i=Oi(n,s,"arm.right",[-.015,.68,.2],{height:1});return Array.from({length:32},(r,o)=>{const a=o/4,l=Math.floor(a),c=a-l,h=l%2===0,u=Math.sin(Math.PI*c),d=Math.max(0,...t.map(m=>1-Math.min(ys(a-m,8),ys(m-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,...CM(e?"hold":"spread")};if(!e)for(const m of Object.keys(i))m.startsWith("arm.")&&(f[m]+=(i[m]-f[m])*d);return{beat:a,pose:f}})}const Nn={garba:{label:"Garba · two clap",bpm:120,beats:8,strikes:[2,3,6,7],keys:uc([2,3,6,7])},garbaThreeClap:{label:"Garba · three clap",bpm:120,beats:8,strikes:[1,2,3,5,6,7],keys:uc([1,2,3,5,6,7])},dandiya:{label:"Dandiya · partner strikes",bpm:120,beats:8,strikes:[1,3,5,7],keys:uc([1,3,5,7],!0)}};function hg(t){const e=typeof t=="string"&&Object.hasOwn(Nn,t)?Nn[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 Ci(t,e,n=lt){const s=hg(t);if(!Number.isFinite(e))throw new Error("humanDanceFrame: beat must be finite");const i=ys(e,s.beats);let r=s.keys.length-1;for(let p=0;p<s.keys.length;p++)s.keys[p].beat<=i&&(r=p);const o=s.keys[r],a=s.keys[(r+1)%s.keys.length],l=o.beat>i?o.beat-s.beats:o.beat,c=a.beat<=o.beat?a.beat+s.beats:a.beat,h=cg((i-l)/(c-o.beat)),u={...lt,...n};for(const p of new Set(s.keys.flatMap(y=>Object.keys(y.pose)))){if(p==="turn"||p==="roll")continue;const y=p.match(/^hand\.(?:left|right)\.(.+)$/)?.[1],v=n[p]??lt[p]??(y?Ct[y]:void 0)??0,w=o.pose[p]??v;u[p]=w+((a.pose[p]??v)-w)*h}const d=Math.floor(e),f=e-d,m=f<=.6?1:1-cg((f-.6)/.4),g=Math.max(0,...s.strikes.map(p=>1-Math.min(ys(i-p,s.beats),ys(p-i,s.beats))/.25));return{pose:u,contact:{side:ys(d,2)===0?"left":"right",start:d,weight:m},strike:g}}function _M(t,e){const n=hg(e.style),s=e.bpm??n.bpm,i=e.beats??n.beats,r=e.samplesPerBeat??16;if(![s,i,r].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 o=Math.max(1,Math.ceil(i*r)),a=Array.from({length:o+1},(l,c)=>({time:(e.start??0)+i*c/o*6e4/s,pose:Ci(n,i*c/o,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"}))}))}const ho={hourglass:{height:165,bust:94,underbust:76,waist:70,hip:98},pear:{height:165,bust:86,underbust:74,waist:72,hip:102},rectangle:{height:165,bust:86,underbust:76,waist:76,hip:89},invertedTriangle:{height:165,bust:98,underbust:86,waist:78,hip:90},round:{height:165,bust:104,underbust:92,waist:98,hip:104}},ug=.72,dg=.72,dc=.68,RM=.33,fc=.2,fg=1.04,gc=.024,gg=.54,_i=.66,mg=.86,uo=.18,HM=.6,FM=.02;function pg(t,e,n){const s=Math.round((e-t)/FM);return Array.from({length:s+1},(i,r)=>{const o=t+(e-t)*r/s;return{at:o,width:n(o)}})}function LM(t){if(t<=_i){const e=(_i-t)/(_i-gg);return Math.sqrt(Math.max(0,1-e*e))}return(1-(t-_i)/(mg-_i))**1.6}function NM(t,e,n,s){if(t<=uo)return e+(n-e)*Math.sin(t/uo*Math.PI/2);const i=(t-uo)/(.4-uo);return n+(s-n)*(1-Math.cos(i*Math.PI))/2}function fo(t,e){return t/(Math.PI*Math.sqrt(2*(1+e*e)))}function mc(t){if(typeof t=="string"){if(!Object.prototype.hasOwnProperty.call(ho,t))throw new Error(`body shape: unknown shape '${t}'`);t=ho[t]}const{height:e,bust:n,waist:s,hip:i}=t,r=t.underbust??n*.86;for(const[o,a]of Object.entries({height:e,bust:n,underbust:r,waist:s,hip:i}))if(!Number.isFinite(a)||a<=0)throw new Error(`body shape: ${o} must be a positive number`);if(r>n)throw new Error("body shape: underbust cannot be larger than bust");for(const[o,a]of Object.entries({bust:n,waist:s,hip:i}))if(a/e<.25||a/e>1)throw new Error(`body shape: ${o} must be 0.25..1 of the height`);return{height:e,bust:n,underbust:r,waist:s,hip:i}}function yg(t,e){const n=mc(t),s=d=>d/n.height,i=fo(s(n.hip),dc),r=fo(s(n.waist),dg),o=fo(s(n.underbust),ug),a=i*dc,l=r*dg,c=o*ug,h=s(n.bust-n.underbust)*RM,u=Math.min(.25,Math.max(0,n.waist/n.hip-.8));return{torso:[{at:0,width:i},{at:.2,width:i*.97},{at:.42,width:r},{at:.6,width:o},{at:.72,width:Math.min(e,o*fg)},{at:.86,width:Math.max(e,o*fg)},{at:1,width:gc}],torsoFront:[{at:0,width:a*(1-fc)*.8},{at:.14,width:a*(1-fc)},{at:.42,width:l*(1.05+u)},...pg(gg,mg,d=>c+h*LM(d)),{at:.92,width:c*.9},{at:1,width:gc}],torsoBack:[...pg(0,.4,d=>NM(d,a*HM,a*(1+fc),l*.95)),{at:.6,width:c},{at:.8,width:c*1.02},{at:.9,width:c*.9},{at:1,width:gc}],hipHalfWidth:i}}function bg(t){return t*.4}function wg(t){const e=mc(t),n=fo(e.hip/e.height,dc);return Math.max(.02,n-Math.max(.042,bg(n)))}function bs(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 ws(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(bs(n.at,`${e}.at`,0,1),bs(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 kg(t,e){const n=Math.max(.095,e.shoulderWidth+.025),s=Math.max(.085,e.hipWidth+.032),i=t.shading??{},r=i.light??[-.8,-.6];if(r.length!==2||!r.every(Number.isFinite)||Math.hypot(...r)===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");const o=t.measurements!==void 0?yg(t.measurements,n):void 0,a=ws(t.torso??o?.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"),l=bs(t.depth??.55,"depth",.2,1),c=u=>u.map(d=>({at:d.at,width:Math.max(.001,d.width*l)})),h=o?Math.max(1,bg(o.hipHalfWidth)/.042):1;return{torso:a,torsoFront:ws(t.torsoFront??o?.torsoFront??c(a),"torsoFront"),torsoBack:ws(t.torsoBack??o?.torsoBack??c(a),"torsoBack"),arm:ws(t.arm??[{at:0,width:.028},{at:.22,width:.027},{at:.5,width:.019},{at:.68,width:.023},{at:1,width:.012}],"arm"),leg:ws(t.leg??[{at:0,width:.04*h},{at:.24,width:.042*h},{at:.5,width:.027},{at:.68,width:.032},{at:1,width:.016}],"leg"),neck:ws(t.neck??[{at:0,width:.024},{at:1,width:.023}],"neck"),depth:l,fill:t.fill??e.skin,outline:{color:t.outline?.color??e.ink,width:bs(t.outline?.width??e.lineWidth,"outline.width",0,100)},shading:{mode:i.mode??"cel",light:[...r],shadow:i.shadow??"#633923",opacity:bs(i.opacity??.17,"shading.opacity",0,1),highlight:bs(i.highlight??.12,"shading.highlight",0,1)}}}function Ri(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],r=t[s],o=(n-i.at)/(r.at-i.at);return i.width+(r.width-i.width)*o*o*(3-2*o)}const vg=8,WM=(t,e,n)=>({x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n}),Wn=(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}},Hi=(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,r)=>{const o=Wn(t[Math.max(0,r-1)],i),a=Wn(i,t[Math.min(t.length-1,r+1)]),l=Math.hypot(o.x+a.x,o.y+a.y);return l>1e-6?{x:(o.x+a.x)/l,y:(o.y+a.y)/l}:a}),s=[];for(let i=0;i<t.length-1;i++){const r=t[i],o=t[i+1],a=Math.hypot(o.x-r.x,o.y-r.y)*.28,l=Hi(r,n[i],a),c=Hi(o,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*r.x+3*d*d*u*l.x+3*d*u*u*c.x+u**3*o.x,y:d**3*r.y+3*d*d*u*l.y+3*d*u*u*c.y+u**3*o.y})}}return s}const pc=(t,e)=>n=>{const s=Ri(t,n)*e;return{left:s,right:s}};function go(t,e,n=1){const s=t.map((l,c)=>{const h=t[Math.max(0,c-1)],u=t[Math.min(t.length-1,c+1)];let d=Wn(h,u);Math.hypot(d.x,d.y)<1e-6&&(d={x:0,y:1});const f={x:-d.y,y:d.x},m=c/Math.max(1,t.length-1),{left:g,right:p}=e(m),y=Wn(h,l),v=Wn(l,u),w=y.x*v.y-y.y*v.x,k=Math.acos(Math.min(1,Math.max(-1,y.x*v.x+y.y*v.y))),S=(Math.hypot(l.x-h.x,l.y-h.y)+Math.hypot(u.x-l.x,u.y-l.y))/(2*Math.max(1e-6,k)),x=M=>Math.min(M,Math.max(M*.2,S*.8));return{center:l,width:(g+p)/2,at:m,left:Hi(l,f,w>0?x(g):g),right:Hi(l,f,w<0?-x(p):-p)}}),i=[],r=[],o=(l,c)=>{i.push(l),r.push(c)};for(const l of s)o(l.left,l.at);const a=(l,c,h)=>{const u={x:-c.y,y:c.x},{left:d,right:f}=e(l.at),m=Hi(l.center,u,(d-f)/2),g=(d+f)/2;for(let p=1;p<vg;p++){const y=p*Math.PI/vg,v=(h?1:-1)*Math.cos(y),w=(h?1:-n)*Math.sin(y);o({x:m.x+g*(u.x*v+c.x*w),y:m.y+g*(u.y*v+c.y*w)},l.at)}};a(s.at(-1),Wn(t[Math.max(0,t.length-2)],t.at(-1)),!0);for(const l of[...s].reverse())o(l.right,l.at);return a(s[0],Wn(t[0],t[Math.min(1,t.length-1)]),!1),{outline:i,samples:s,positions:r}}function DM(t,e,n,s){const i=Math.sqrt(Math.max(0,1-n*n));return r=>{const o=Ri(t.torso,r)*e*n,a=Math.hypot(o,Ri(t.torsoFront,r)*e*i),l=Math.hypot(o,Ri(t.torsoBack,r)*e*i);return s?{left:a,right:l}:{left:l,right:a}}}function Mg(t,e,n){const s={},i=e.height,r=e.chains.spine;if(r?.length>=2){const o=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=o&&a?Math.min(1,Math.hypot(o.x-a.x,o.y-a.y)/c):Math.abs(Math.cos(e.turn*Math.PI/2)),u=Math.sin(e.turn*Math.PI/2)>=0,d=[WM(r[0],r[1],-.16),...r.slice(1)];s.spine=go(Fi(d),DM(t,i,h,u),.25)}e.chains.neck?.length>=2&&(s.neck=go(Fi(e.chains.neck),pc(t.neck,i)));for(const o of["left","right"])for(const a of["arm","leg"]){const l=e.chains[`${a}.${o}`];!l||l.length<3||(s[`${a}.${o}`]=go(Fi(l.slice(0,3)),pc(t[a],i)),a==="leg"&&l.length>3&&(s[`foot.${o}`]=go(Fi(l.slice(2)),pc([{at:0,width:.019},{at:1,width:.014}],i))))}return s}function Sg(t,e){let n=!1;for(let s=0,i=e.length-1;s<e.length;i=s++){const r=e[s],o=e[i];r.y>t.y!=o.y>t.y&&t.x<(o.x-r.x)*(t.y-r.y)/(o.y-r.y)+r.x&&(n=!n)}return n}function yc(t,e,n,s=0){const i=t.samples.filter(a=>a.at>=e&&a.at<=n),r=(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}},o=[...i.map(a=>r(a,"left")),...[...i].reverse().map(a=>r(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;o.push({x:l.x+(l.x-a.x)*s/c,y:l.y+(l.y-a.y)*s/c})}}return o}function Tg(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 BM(t,e,n){const s=n.shading;if(s.mode==="none"||n.fill==="none")return;const i=Math.hypot(...s.light),r={x:s.light[0]/i,y:s.light[1]/i},o=t.globalAlpha;t.save(),Tg(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,m=u.y-d.y,g=(f*r.x+m*r.y)/(Math.hypot(f,m)||1),p=Math.max(0,-g)*.44;return{x:u.x+(d.x-u.x)*p,y:u.y+(d.y-u.y)*p}});if(Tg(t,[...l,...c.reverse()]),t.fillStyle=s.shadow,t.globalAlpha=o*s.opacity,t.fill(),s.highlight>0){const h=e.samples.map(f=>{const m=f[a],g=f.center;return{x:m.x+(g.x-m.x)*.2,y:m.y+(g.y-m.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)*r.x+(u.y-d.y)*r.y>0){t.globalAlpha=o*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 zM(t,e,n,s){const i=s.bodyContours,r=o=>i[o]&&Sg(t,i[o].outline);if(n.startsWith("arm."))return e<.2&&r("spine");if(n.startsWith("leg."))return e<.2&&r("spine")||e>.85&&r(n.replace("leg.","foot."));if(n.startsWith("foot."))return e<.25&&r(n.replace("foot.","leg."));if(n==="neck")return e<.6&&r("spine");if(n==="spine"){if(e>.85&&r("neck"))return!0;for(const o of["left","right"]){if(e>.6&&r(`arm.${o}`)){const a=s.chains[`arm.${o}`]?.[0];if(a&&Math.hypot(a.x-t.x,a.y-t.y)<s.height*.07)return!0}if(e<.25&&r(`leg.${o}`))return!0}}return!1}function qM(t){let e=0;return t.forEach((n,s)=>{const i=t[(s+1)%t.length];e+=n.x*i.y-i.x*n.y}),e>0?-1:1}function Eg(t,e,n,s,i){const r=s.bodyContours?.[i];if(!r)return!1;if(n.fill==="none"&&(e=vi(t,e)),e.shape(r.outline,n.fill==="none"?null:n.fill,0),e.look==="clean"&&BM(t,r,n),(e.look!=="silhouette"||n.fill==="none")&&s.lineWidth>0){const o=qM(r.outline);let a=[];for(let l=0;l<=r.outline.length;l++){const c=l%r.outline.length,h=r.outline[c],u=r.outline[(c+1)%r.outline.length],d={x:(h.x+u.x)/2,y:(h.y+u.y)/2};i.startsWith("arm.")&&r.positions[c]===1||zM(d,r.positions[c],i,s)?(a.length>=2&&e.line(a,s.lineWidth,o),a=[]):(a.length===0&&a.push(h),a.push(u))}a.length>=2&&e.line(a,s.lineWidth,o)}return!0}function Ag(t){return[[.01,-.12,.8],[0,-.25,.98],[-.04,-.31,.8]].map(e=>hn(t,e).point)}function xg(t,e){const n=e.shape==="angular"?jM(t,e):e.projection==="volume"?KM(t):wi(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),r=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}),o=r(Ag(t)[1]),a=Math.sign(o.x),l=o.y,c=n.flatMap((u,d)=>{const f=r(u),m=r(n[(d+1)%n.length]);if(f.y>l==m.y>l)return[];const g=(l-f.y)/(m.y-f.y);return[(f.x+(m.x-f.x)*g)*a]}),h=Math.max(0,o.x*a-Math.max(...c));return!Number.isFinite(h)||h===0?n:n.flatMap((u,d)=>{const f=n[(d+1)%n.length],m=r(u),g=r(f),p=Math.max(1,Math.ceil(Math.hypot(g.x-m.x,g.y-m.y)/.025));return Array.from({length:p},(y,v)=>{const w=v/p,k={x:u.x+(f.x-u.x)*w,y:u.y+(f.y-u.y)*w},S=r(k),x=(S.y-l+.115)/.23;if(S.x*a<.5||x<=0||x>=1)return k;const M=Math.sin(x*Math.PI)**2*h*t.rx*a;return{x:k.x+M*s,y:k.y+M*i}})})}function jM(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 r=0;r<=12;r++){const o=r*Math.PI/24;i.push([Math.sin(o),Math.cos(o)])}return Pg(t,i,e.jawRoundness??0,e.projection==="volume")}function KM(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 Pg(t,e,0,!0)}function Pg(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(hn(t,[l*Math.cos(h),a,s?Math.min(u,.82):u]).point)}let r=bc(i);if(n=Math.min(1,Math.max(0,n)),n===0)return r;const o=n*.25;for(let a=0;a<3;a++)r=r.flatMap((l,c)=>{const h=r[(c+1)%r.length];return[{x:l.x+(h.x-l.x)*o,y:l.y+(h.y-l.y)*o},{x:h.x+(l.x-h.x)*o,y:h.y+(l.y-h.y)*o}]});return r}function bc(t){const e=t.sort((i,r)=>i.x-r.x||i.y-r.y),n=(i,r,o)=>(r.x-i.x)*(o.y-i.y)-(r.y-i.y)*(o.x-i.x),s=i=>{const r=[];for(const o of i){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],o)<=0;)r.pop();r.push(o)}return r.slice(0,-1)};return[...s(e),...s([...e].reverse())]}const $g=.34,Ut=.12,Kt=-.4,Et=(t,e,n)=>t[e]??n,Ig=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),YM=.45,XM=.35,GM=.7,Og=.78;function kt(t,e,n,s="cartoon"){const i=f=>Math.sqrt(Math.max(0,1-f.x*f.x-f.y*f.y));let r=hn(t,[n.x,n.y,i(n)]).facing;const o=t.axes[2];s==="volume"&&n.x*o[0]>0&&(r=Math.max(r,o[2]));const a=Math.atan2(o[0],o[2]),l=Math.cos(a),c=Math.max(XM,l),h=Math.max(GM,l),u=Math.cos(t.angle),d=Math.sin(t.angle);if(s==="volume"){const f=hn(t,[n.x,n.y,i(n)*Og]).point,m=Math.abs(n.x)>.1?Math.min(1,Math.max(0,r)/.25):1,g=Math.max(n.x*o[0]>0?.2:.5,l);return{facing:r,points:e.map(p=>{const y=(p.x-n.x)*g*t.rx*m,v=(p.y-n.y+o[1]*(i(p)-i(n))*Og)*t.ry*m;return{x:f.x+y*u+v*d,y:f.y+y*d-v*u}})}}return{facing:r,points:e.map(f=>{const m=YM*Math.sin(a)+n.x*c+(f.x-n.x)*h,g=f.y+o[1]*i(f),p=m*t.rx,y=g*t.ry;return{x:t.center.x+p*u+y*d,y:t.center.y+p*d-y*u}})}}const ue=(t,e,n,s=12)=>Array.from({length:s+1},(i,r)=>{const o=r/s,a=1-o;return{x:a*a*t.x+2*a*o*e.x+o*o*n.x,y:a*a*t.y+2*a*o*e.y+o*o*n.y}}),Li=(t,e,n,s)=>{const i=Math.min(1,Math.max(0,(s-t.x)/(n.x-t.x))),r=1-i;return r*r*t.y+2*r*i*e.y+i*i*n.y},de=(t,e,n,s,i=16)=>Array.from({length:i},(r,o)=>{const a=Math.PI*2*o/i;return{x:t+Math.cos(a)*n,y:e+Math.sin(a)*s}}),Re=.05,UM=.3,VM="#e06b7d";function JM(t,e,n,s,i={},r){const o=Math.max(1,Math.min(s*.6,.14*e.rx)),a=(O,_)=>kt(e,O,_,i.projection).points,l=(O,_)=>kt(e,[],{x:O,y:_},i.projection).facing,c=Et(n,"smile",0),h=Et(n,"blink",0),u=Et(n,"lookX",0),d=Et(n,"lookY",0),f=Et(n,"browTilt",0),m=Math.max(.2,Et(n,"pupil",1)),g=Math.min(1,Math.max(0,Et(n,"lid",0))),p=Math.min(1,Math.max(0,Et(n,"bulge",0))),y=t.look==="illustrated";y&&r&&sS(r,e,i.projection);for(const O of[1,-1]){const _=O===1?"left":"right";if(i.style==="oval"){l(be.x*O,be.y)>=Re&&eS(t,e,O,n,i);continue}const L=$g*O;if(l(L,Ut)<Re)continue;const j={x:L,y:Ut},V=Ig(Et(n,`eye.${_}`,1),h);if(V<.2||i.style==="anime"&&g>=.98){const Y=c>.5?.12:-.06;t.line(a(ue({x:L-.12,y:Ut},{x:L,y:Ut+Y},{x:L+.12,y:Ut}),j),o)}else if(i.style==="anime")ZM(t,e,j,O,V,g,p,m,u,d,o,i,r);else{const Y=V>1.2||p>.02,R=.13*Math.max(V,1)*(1+p*.7);Y&&t.shape(a(de(L,Ut,R*.85,R),j),"#ffffff",o,!0);const K=(V>1.2?.075:.1)*m*(1+p*.3),st=L+u*.08,$=Ut-d*.07,C=de(st,$,K,K*1.1*Math.min(V,1));if(t.shape(a(C,j),t.ink,0,!0),i.inPupil&&r){const[z]=a([{x:st,y:$}],j),X=a(C,j),W=Math.min(...X.map(N=>Math.hypot(N.x-z.x,N.y-z.y)));W>.5&&(r.save(),r.beginPath(),r.arc(z.x,z.y,W,0,Math.PI*2),r.clip(),i.inPupil(r,{x:z.x,y:z.y,r:W,side:_}),r.restore())}if(g>.02){const z=Y?R*1.15:K*1.4,X=Ut+z,W=X-z*2*g,N=z*1.1;t.shape(a([{x:L-N,y:X+.02},{x:L+N,y:X+.02},{x:L+N,y:W},{x:L-N,y:W}],j),i.skin??"#ffffff",0,!0),t.line(a([{x:L-N,y:W},{x:L+N,y:W}],j),o)}}const tt=Ut+(i.style==="anime"?.38:.3)+Et(n,`brow.${_}`,0)*.14+Math.max(0,V-1)*.12,J={x:L+O*.13,y:tt},F={x:L-O*.13,y:tt+f*.1},B=y?.035:0;t.line(a([J,{x:(J.x+F.x)/2,y:(J.y+F.y)/2+B},F],{x:L,y:tt}),o*(y?2.2:1))}i.style==="oval"&&i.shades&&tS(t,e,i),rS(t,e,n,o,i.projection),iS(t,e,i.ageLines??0,o,i.projection);const v={x:0,y:Kt};if(l(0,Kt)<-Re)return;i.nose&&l(0,Ut-.15)>=Re&&(i.projection==="volume"?t.line(Ag(e),o):t.line(a([{x:.01,y:Ut-.1},{x:.03,y:Kt+.2},{x:-.05,y:Kt+.17}],{x:0,y:Kt+.22}),o));const w=.25*Math.max(.3,Et(n,"mouthWidth",1)),k=Math.min(1,Math.max(0,Et(n,"mouth",0)));if(k<=.05){y&&nS(t,w,c,a),t.line(a(ue({x:-w,y:Kt},{x:0,y:Kt-c*.25},{x:w,y:Kt}),v),o);return}const S=.3*k;let x,M,E,T;if(c>.3){const O=Kt+.05,_={x:0,y:Kt-S*2};x=[...ue({x:w,y:O},_,{x:-w,y:O})],M=()=>O,E=L=>Li({x:w,y:O},_,{x:-w,y:O},L),T=.85}else if(c<-.3){const O=Kt-S*.6,_={x:0,y:Kt+S*1.4};x=[...ue({x:w,y:O},_,{x:-w,y:O})],M=L=>Li({x:w,y:O},_,{x:-w,y:O},L),E=()=>O,T=.5}else{const O=w*.8;x=de(0,Kt,O,S);const _=L=>S*Math.sqrt(Math.max(0,1-(L/O)**2));M=L=>Kt+_(L),E=L=>Kt-_(L),T=.5}if(t.shape(a(x,v),t.ink,0,!0),k<UM)return;const A=M(0)-E(0),P=w*T,I=(O,_,L=8)=>Array.from({length:L+1},(j,V)=>O+(_-O)*V/L);if(i.tongue){const O=P*.55,_=I(O,-O).map(j=>({x:j,y:E(j)})),L=ue({x:-O,y:E(-O)},{x:0,y:E(0)+A*.8},{x:O,y:E(O)},8);t.shape(a([..._,...L.slice(1,-1)],v),VM,0,!0)}if(i.teeth){const O=Math.min(.06,A*.4),_=I(-P,P).map(j=>({x:j,y:M(j)})),L=_.map(({x:j,y:V})=>({x:j*.92,y:V-O})).reverse();t.shape(a([..._,...L],v),"#ffffff",0,!0);for(const j of[-.5,0,.5]){const V=P*j;t.line(a([{x:V,y:M(V)},{x:V*.92,y:M(V)-O}],v),o*.6)}}}function ZM(t,e,n,s,i,r,o,a,l,c,h,u,d){const{x:f,y:m}=n,g=Math.min(1.2,Math.max(.5,u.eyeScale??1)),p=Math.min(1.2,Math.max(.45,u.eyeAspect??1)),y=.21*g*(1+o*.15),v=.25*g*p*Math.min(i,1.6)*(1-r)*(1+o*.3),w={x:f-y,y:m},k={x:f+y,y:m},S={x:f,y:m+v*1.9},x={x:f,y:m-v*1.35},M=ue(w,S,k),E=ue(k,x,w),T=J=>kt(e,J,n,u.projection).points,A=J=>J.map(F=>{const B=Math.min(k.x,Math.max(w.x,F.x));return{x:B,y:Math.min(Li(w,S,k,B),Math.max(Li(k,x,w,B),F.y))}});t.shape(T([...M,...E.slice(1,-1)]),"#ffffff",h*.5,!0);const P=f+Math.max(-1,Math.min(1,l))*.07*g,I=m-Math.max(-1,Math.min(1,c))*.055*g,O=.115*g,_=.185*g;t.shape(T(A(de(P,I,O,_,24))),u.iris??"#4b7fce",h*.4,!0),t.shape(T(A(de(P,I-.075*g,O*.7,_*.35))),"rgba(255,255,255,0.25)",0,!0);const L=t.look==="illustrated",j=L?Nl(u.iris??"#4b7fce")?.highlight:void 0;j&&t.shape(T(A(de(P,I-_*.5,O*.7,_*.32))),j,0,!0);const V=Math.min(.085,.042*a)*g,tt=A(de(P,I,V,V*1.35));if(t.shape(T(tt),t.ink,0,!0),u.inPupil&&d){const[J]=T([{x:P,y:I}]),F=Math.min(...T(tt).map(B=>Math.hypot(B.x-J.x,B.y-J.y)));F>.5&&(d.save(),d.beginPath(),d.arc(J.x,J.y,F,0,Math.PI*2),d.clip(),u.inPupil(d,{...J,r:F,side:s===1?"left":"right"}),d.restore())}if(t.shape(T(A(de(P-.038*g,I+.075*g,.035*g,.045*g))),"#ffffff",0,!0),t.shape(T(A(de(P+.04*g,I-.04*g,.014*g,.02*g))),"#ffffff",0,!0),L){const J=ue(w,{x:f,y:m+v*1.2},k);t.shape(T([...M,...J.slice(1,-1).reverse()]),"rgba(70, 35, 30, 0.22)",0,!0);const F=ue({x:f-y*.7,y:m+v*.55+.03},{x:f,y:m+v*1.4+.09},{x:f+y*.85,y:m+v*.5+.03});t.line(T(F),h*.45);const B=E.filter(Y=>s*(Y.x-f)>y*.25);B.length>=2&&t.line(T(B),h*.55)}if(t.line(T(M),h*(L?1.9:1.1)),u.lashes!==!1)for(const J of[0,.035]){const F=f+s*(y-J),B=Li(w,S,k,F);t.line(T([{x:F,y:B},{x:F+s*.055,y:B+.07}]),h*.75)}}const be={x:.31,y:.12,rx:.29,ry:.44},wc={rx:.37,ry:.33},Cg=(t,e,n,s,i=10)=>Array.from({length:i},(r,o)=>{const a=(o+1)/i,l=1-a;return{x:l*l*l*t.x+3*l*l*a*e.x+3*l*a*a*n.x+a*a*a*s.x,y:l*l*l*t.y+3*l*l*a*e.y+3*l*a*a*n.y+a*a*a*s.y}});function QM(t,e,n,s,i,r){const{rx:o,ry:a}=wc,l=(d,f)=>({x:n+i*d,y:s-f}),c=l(-o,-a*.55),h=[c,...ue(c,l(0,-a*.8),l(o,-a*.6),8).slice(1),...Cg(l(o,-a*.6),l(o*1.08,a*.2),l(o*.75,a*1.05),l(0,a)),...Cg(l(0,a),l(-o*.8,a*.95),l(-o*1.1,a*.1),c)];t.shape(e(h),"#161c27",r*1.3,!0),t.shape(e(h.filter(d=>d.y<=s-a*.15)),"rgba(80, 96, 122, 0.45)",0,!0);const u=.035;t.shape(e([l(-o*.55-u,a*.5),l(-o*.55+u,a*.5),l(o*.05+u,-a*.45),l(o*.05-u,-a*.45)]),"rgba(255, 255, 255, 0.55)",0,!0)}function tS(t,e,n){const s=Math.max(1,.06*e.rx),i=be.y+.12,r=o=>kt(e,[],{x:o,y:i},n.projection).facing>=Re;r(-.1)&&r(.1)&&t.line(kt(e,ue({x:-.1,y:i},{x:0,y:i+.06},{x:.1,y:i}),{x:0,y:i},n.projection).points,s);for(const o of[1,-1]){const a={x:o*(be.x+wc.rx*.95),y:i};if(hn(e,[o,0,0]).facing<=.15||!r(a.x))continue;const[l]=kt(e,[a],a,n.projection).points;t.line([l,hn(e,[o*.98,i,-.1]).point],s*.9)}}function eS(t,e,n,s,i){const r=n===1?"left":"right",{x:o,y:a}={x:be.x*n,y:be.y},l={x:o,y:a},c=E=>kt(e,E,l,i.projection).points,h=Math.max(1,.055*e.rx),u=Math.max(1.5,.095*e.rx),d=Math.min(1,Math.max(0,Et(s,"blink",0))),f=Math.max(0,Et(s,`eye.${r}`,1)),m=Ig(f,d),g=Math.min(1,Math.max(0,Et(s,"bulge",0))),p=1+.12*Math.min(1,Math.max(0,f-1))+.25*g,y=be.rx*p,v=be.ry*p,w=Et(s,"smile",0);if(i.shades)QM(t,c,o,a,n,h);else if(m<.2){const E=w>.5?.14:-.08;t.line(c(ue({x:o-y*.85,y:a},{x:o,y:a+E},{x:o+y*.85,y:a})),h*1.4)}else{const E=de(o,a,y,v,32);t.shape(c(E),"#ffffff",h,!0);const T=Math.min(1,Math.max(Math.max(0,Et(s,"lid",0)),1-Math.min(1,m))),A=a+v-2*v*T*.95,P=Math.max(-1,Math.min(1,Et(s,"lookX",0))),I=Math.max(-1,Math.min(1,Et(s,"lookY",0))),O=.085*Math.max(.3,Et(s,"pupil",1))*(1+g*.2),_=o+P*y*.45,L=a-I*v*.45-v*.05,j=de(_,L,O,O,20).map(V=>({x:V.x,y:Math.min(V.y,A)}));if(L-O<A&&t.shape(c(j),t.ink,0,!0),T>.02){const V=Math.asin(Math.max(-1,Math.min(1,(A-a)/v))),tt=Array.from({length:25},(J,F)=>{const B=V+(Math.PI-2*V)*F/24;return{x:o+y*Math.cos(B),y:a+v*Math.sin(B)}});t.shape(c(tt),i.skin??"#ffffff",0,!0),t.line(c([tt[0],tt[tt.length-1]]),h),t.shape(c(E),null,h,!0)}}const k=a+(i.shades?wc.ry+.1:v+.12)+.08*Et(s,`brow.${r}`,0),S=Et(s,"browTilt",0)*.06,x={x:o+n*y*1,y:k},M={x:o-n*y*.8,y:k+S};t.line(kt(e,[M,x],{x:o,y:k},i.projection).points,u)}function nS(t,e,n,s){const i=Kt-n*.125,r=e*.5,o=.045,a=de(0,i-o*.9,r,o,24);t.shape(s(a,{x:0,y:Kt-.08}),"rgba(165, 55, 70, 0.2)",0,!0)}function sS(t,e,n){for(const s of[1,-1]){const i={x:.48*s,y:-.2},r=kt(e,[i],i,n);if(r.facing<Re)continue;const[o]=r.points,a=e.rx*.26,l=t.createRadialGradient(o.x,o.y,0,o.x,o.y,a);l.addColorStop(0,"rgba(225, 95, 95, 0.2)"),l.addColorStop(1,"rgba(225, 95, 95, 0)"),t.fillStyle=l,t.beginPath(),t.arc(o.x,o.y,a,0,Math.PI*2),t.fill()}}function iS(t,e,n,s,i){const r=Math.min(1,Math.max(0,n));if(!(r<=0))for(const o of[-1,1]){const a={x:o*.59,y:Ut};if(kt(e,[],a,i).facing<Re)continue;for(const h of[-.06,.035]){const u=[{x:a.x,y:a.y},{x:a.x+o*.1,y:a.y+h}];t.line(kt(e,u,a,i).points,s*.45*r)}const l={x:o*.3,y:-.38},c=ue({x:l.x,y:-.31},{x:l.x+o*.07,y:-.4},{x:l.x+o*.035,y:-.49});t.line(kt(e,c,l,i).points,s*.35*r)}}const _g="#8fd0f5",Rg=(t,e,n)=>Array.from({length:18},(s,i)=>{const r=Math.PI*2*i/18,o=Math.sin(r/2);return{x:t+Math.sin(r)*n*o,y:e-n*.9+Math.cos(r)*n*1.6*(.55+.45*o)-n*.4}});function rS(t,e,n,s,i){const r=Math.min(1,Math.max(0,Et(n,"blush",0))),o=Math.min(1,Math.max(0,Et(n,"tears",0))),a=Math.min(1,Math.max(0,Et(n,"sweat",0)));if(!(r+o+a<=.01)){for(const l of[1,-1]){const c={x:.5*l,y:-.16},h=kt(e,[],c,i).facing>=Re;if(r>.01&&h){const{points:d}=kt(e,de(c.x,c.y,.17,.1),c,i);if(t.shape(d,`rgba(240, 120, 140, ${(.75*r).toFixed(3)})`,0,!0),r>.5)for(const f of[-.07,0,.07]){const m=[{x:c.x+f-.018,y:c.y-.03},{x:c.x+f+.018,y:c.y+.03}];t.line(kt(e,m,c,i).points,s*.3)}}const u={x:$g*l,y:Ut};if(o>.01&&kt(e,[],u,i).facing>=Re){const d=.05+.04*o,f={x:u.x+.06*l,y:Ut-.2-.12*o};if(t.shape(kt(e,Rg(f.x,f.y,d),f,i).points,_g,s*.35),o>.6){const m=[{x:u.x+.05*l,y:Ut-.1},{x:f.x,y:f.y+d*.8}];t.line(kt(e,m,f,i).points,s*.3)}}}if(a>.01){const l={x:.64,y:.42};kt(e,[],l,i).facing>=Re&&t.shape(kt(e,Rg(l.x,l.y,.05+.05*a),l,i).points,_g,s*.35)}}}const oS=15;function He(t,e){const n=Math.sqrt(Math.max(0,1-e*e));return[n*Math.sin(t),e,n*Math.cos(t)]}const aS=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function ne(t,[e,n,s]){const[i,r,o]=t.axes;return i[2]*e+r[2]*n+o[2]*s}function _t(t,e){return hn(t,e).point}function mo(t,e){const n=Math.abs(t-e)%(Math.PI*2);return n>Math.PI?Math.PI*2-n:n}function po(t,e,n=64){const s=e.top??1,i=e.bottom??-1,r=Math.max(8,Math.ceil((s-i)*oS)),o=m=>Math.min(s,Math.max(i,s-(s-i)*(m-1)/r)),a=m=>-Math.PI+Math.PI*2*m/n,l=(m,g)=>e.normal?e.normal(m,g):aS(e.position(m,g)),c=r+3,h=new Float64Array(n*c),u=new Float64Array(n*c);for(let m=0;m<c;m++){const g=m===0||m===c-1,p=o(m);for(let y=0;y<n;y++){const v=m*n+y;if(g){h[v]=-1;continue}const w=a(y);h[v]=e.inside(w,p),u[v]=h[v]>-.35?ne(t,l(w,p)):0}}const d=m=>(m%n+n)%n,f=m=>{const g=n+1,p=new Float64Array(g*c);for(let I=0;I<c;I++)for(let O=0;O<=n;O++){const _=I*n+(O===n?0:O);p[I*g+O]=Math.min(h[_],m*u[_])}const y=(I,O)=>p[O*g+I],v=(I,O,_,L)=>{const j=y(I,O),V=y(_,L),tt=j===V?.5:Math.min(1,Math.max(0,j/(j-V)));return _t(t,e.position(a(I+(_-I)*tt),o(O+(L-O)*tt)))},w=n*c*2,k=new Int32Array(w).fill(-1),S=new Int32Array(w).fill(-1),x=new Map,M=(I,O,_)=>{const L=(_*n+d(O))*2+(I?1:0);return x.has(L)||x.set(L,I?v(d(O),_,d(O),_+1):v(O,_,O+1,_)),L},E=(I,O)=>{k[I]===-1?k[I]=O:S[I]=O},T=(I,O)=>{E(I,O),E(O,I)};for(let I=0;I<c-1;I++)for(let O=0;O<n;O++){const _=I*g+O,L=(p[_]>0?8:0)|(p[_+1]>0?4:0)|(p[_+g+1]>0?2:0)|(p[_+g]>0?1:0);if(L===0||L===15)continue;const j=()=>M(!1,O,I),V=()=>M(!1,O,I+1),tt=()=>M(!0,O,I),J=()=>M(!0,O+1,I);switch(L){case 1:case 14:T(tt(),V());break;case 2:case 13:T(V(),J());break;case 3:case 12:T(tt(),J());break;case 4:case 11:T(j(),J());break;case 6:case 9:T(j(),V());break;case 7:case 8:T(tt(),j());break;case 5:case 10:{const F=(y(O,I)+y(O+1,I)+y(O+1,I+1)+y(O,I+1))/4>0;L===5===F?(T(tt(),j()),T(V(),J())):(T(tt(),V()),T(j(),J()));break}}}const A=[],P=new Uint8Array(w);for(const I of x.keys()){if(P[I])continue;const O=[];let _=-1,L=I;for(;L!==-1&&!P[L];){P[L]=1,O.push(x.get(L));const j=k[L],V=S[L],tt=j!==-1&&j!==_&&!P[j]?j:V!==-1&&V!==_&&!P[V]?V:-1;_=L,L=tt}O.length>=3&&A.push(O)}return A};return{near:f(1),far:f(-1)}}const Hg=new WeakMap;function kc(t,e,n){let s=Hg.get(t);s||Hg.set(t,s=new Map);let i=s.get(e);return i||s.set(e,i=n()),i}function vc(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 Fg(t,e,n,s=.04){const i=[];let r=[];return e.forEach((o,a)=>{ne(t,n[a])>s?r.push(_t(t,o)):(r.length>=2&&i.push(r),r=[])}),r.length>=2&&i.push(r),i}const Lg=t=>t*Math.PI/180,Mc=t=>{const e=Math.hypot(...t)||1;return t.map(n=>n/e)},lS=(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 Ng(t,e,n){return t>=e+n?t:t<=e-n?e:e+(t-e+n)**2/(4*n)}function Sc(t,e,n){const s=Mc(n),i=t.reduce((c,h,u)=>c+h*s[u],0),o=t.map((c,h)=>c-i*s[h]).reduce((c,h)=>c+h*h,0),a=Math.sqrt(Ng(1-o,e*e,e*e)),l=Ng(i,a,e)-i;return l===0?t:t.map((c,h)=>c+s[h]*l)}function cS(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 hS(t,e,n,s){const i=(t.path.length-1)/3,r=i*20,o=[],a=[],l=s.trail!==0||s.lift!==0,c=Math.max(0,e+n);for(let h=0;h<=r;h++){const u=h/r,d=Math.min(i-1,Math.floor(u*i)),f=u*i-d,m=1-f,g=[m**3,3*m*m*f,3*m*f*f,f**3],p=t.path.slice(d*3,d*3+4),y=Lg(p.reduce((_,L,j)=>_+L.around*g[j],0)),v=p.reduce((_,L,j)=>_+L.up*g[j],0),w=p.reduce((_,L,j)=>_+(L.lift??0)*g[j],0),k=1+e+n+w,S=v>=0?Math.sqrt(Math.max(0,1-v*v)):1,x=u*u*(t.follow??1),M=Lg(s.swing)*x,E=y-M,T=[Math.sin(E)*S*k,v*(v>=0?k:1),Math.cos(E)*S*k],A=[T[0],T[1]+s.lift*x,T[2]-s.trail*x],P=[Math.sin(E)*S,Math.max(0,v),Math.cos(E)*S],I=Mc(T),O=l&&x>0?Sc(A,c,I):A;a.push(I),o.push({center:O,normal:P,left:O,right:O,t:u})}return o.forEach((h,u)=>{const d=o[Math.max(0,u-1)].center,m=o[Math.min(r,u+1)].center.map((y,v)=>y-d[v]),g=Mc(lS(h.normal,m)),p=t.width*Math.sin(Math.PI*h.t)**.6*.5;h.left=h.center.map((y,v)=>y+g[v]*p),h.right=h.center.map((y,v)=>y-g[v]*p),l&&h.t>0&&(t.follow??1)>0&&(h.left=Sc(h.left,c,a[u]),h.right=Sc(h.right,c,a[u]))}),o}const ks=(t,e,n)=>t.map((s,i)=>s+(e[i]-s)*n);function uS(t,e,n){const s=n?1:-1,i=[];let r=[];for(let o=0;o<e.length;o++){const a=e[o],l=s*ne(t,a.normal)>=0;if(o>0){const c=e[o-1],h=s*ne(t,c.normal),u=s*ne(t,a.normal);if(h>=0!==l){const d=h/(h-u),f={center:ks(c.center,a.center,d),left:ks(c.left,a.left,d),right:ks(c.right,a.right,d),normal:ks(c.normal,a.normal,d),t:c.t+(a.t-c.t)*d};l?r=[f]:(r.push(f),r.length>=2&&i.push(r),r=[])}}l&&r.push(a)}return r.length>=2&&i.push(r),i}function Wg(t,e,n,s,i,r,o){const a=(n.locks??[]).map(h=>hS(h,n.volume,s,i)),l=h=>h.reduce((u,d)=>u+ne(e,d.center),0)/h.length;a.sort((h,u)=>l(h)-l(u));const c=Math.max(.7,r*.35);for(const h of a)for(const u of uS(e,h,o)){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"||t.look==="illustrated")&&(n.shine??0)>0){const g=u.filter(p=>p.t>=.2&&p.t<=.75);if(g.length>=3){const p=g.map((v,w)=>{const k=.16*Math.sin(Math.PI*w/(g.length-1));return _t(e,ks(v.center,v.left,.16+k))}),y=g.map(v=>_t(e,ks(v.center,v.left,.16)));t.shape([...p,...y.reverse()],`rgba(255,255,255,${n.shine})`,0)}}const m=u.filter(g=>g.t>.3);m.length>=2&&t.line(m.map(g=>_t(e,g.left)),c)}}const It=(t,e,n=0)=>({around:t,up:e,lift:n}),Tc=()=>[{width:.66,follow:.22,path:[It(-38,.88),It(-12,.94,.08),It(58,.76,.09),It(94,.16,.03)]},{width:.58,follow:.3,path:[It(-42,.8),It(-24,.7,.12),It(18,.57,.09),It(64,.3)]},{width:.36,follow:.18,path:[It(-58,.76),It(-76,.56,.07),It(-90,.12,.06),It(-102,-.36)]}];function Dg(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?[It(e,.7),It(e+s*9,.2,.12),It(e-s*13,-.5,.2),It(e-s*8,-.95,.16),It(e-s*3,-1.4,.12),It(e+s*18,i+.35,.22),It(e+s*12,i,.03)]:[It(e,.7),It(e+s*7,.15,.2),It(e-s*8,-.75,.25),It(e+s*5,i)]}})}const dS={softSweep:{volume:.12,shine:.16,part:-38,strands:"part",sweep:-.08,hairline:{front:.64,side:.12,back:-.8},locks:Tc()},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:[...Dg(!1),...Tc()]},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:[...Dg(!0),...Tc()]}},vs={swing:0,trail:0,lift:0};function Ni(t){if(!t)return vs;const e=t["hair.swing"]??0,n=t["hair.trail"]??0,s=t["hair.lift"]??0;return e===0&&n===0&&s===0?vs:{swing:e,trail:n,lift:s}}const Bg=t=>t.swing===0&&t.trail===0&&t.lift===0;function zg(t){return t.length>0||t.ties.some(e=>e.kind!=="bun")||(t.locks??[]).some(e=>(e.follow??1)>0)}function Ec([t,e,n],s){if(s===0)return[t,e,n];const i=Math.cos(s),r=Math.sin(s);return[t*i-n*r,e,n*i+t*r]}const qg={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},jg=1.75,Ac={...dS,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:jg,opening:84,part:0,strands:"part",hairline:{front:.5,side:.05,back:-.85},coversEars:!0},shoulderWaves:{volume:.22,length:jg,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}},Fe={black:"#22201f",brown:"#6b4630",chestnut:"#7b4a2b",auburn:"#9a4426",blond:"#d9b55a",ginger:"#c8662f",gray:"#a7a29c",white:"#ecebe7"};function Kg(t){const e=typeof t=="string"?{style:t}:t,n=e.style?Ac[e.style]:{};if(e.style&&!n)throw new Error(`hair: unknown style '${e.style}'`);const{style:s,hairline:i,...r}=e,o={...qg,...n,...r,hairline:{...qg.hairline,...n.hairline,...i},ties:(r.ties??n.ties??[]).map(a=>({...a})),...r.spikes??n.spikes?{spikes:(r.spikes??n.spikes).map(a=>({...a}))}:{},...r.locks??n.locks?{locks:(r.locks??n.locks).map(cS)}:{},...r.fall??n.fall?{fall:{...r.fall??n.fall}}:{}};if(o.shine!==void 0&&(!Number.isFinite(o.shine)||o.shine<0||o.shine>1))throw new Error("hair: shine must be between 0 and 1");if(o.fall&&(!Number.isFinite(o.fall.taper)||o.fall.taper<0||o.fall.taper>1||!Number.isFinite(o.fall.wave)||o.fall.wave<0))throw new Error("hair: fall needs taper between 0 and 1 and nonnegative wave");return o}const Dn=t=>t*Math.PI/180,Ms=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},xc=t=>1-Math.abs(2*(t-Math.floor(t))-1);function Wi(t,e){const{front:n,side:s,back:i}=t.hairline,r=(n-i)/2,o=(n+i)/2,a=(o+s)/2,l=(o-s)/2,c=Math.max(0,Math.cos(e));let h=a+r*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*xc(e*11/(Math.PI*2))*c),h}function Yg(t,e,n){const s=t.textureAmount;switch(t.texture){case"spiky":return s*(xc(e*11/(Math.PI*2))*xc(n*2.6+.5))**1.2*Ms(-.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 Xg(t,e,n=vs){const s=t.length>0,i=new Map,r=h=>{let u=i.get(h);return u===void 0&&i.set(h,u=Wi(t,h)),u},o=Dn(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,m=Math.sqrt(1-.45*.45)*d*(1-f**5),g=.45+(1+t.flat-.45)*Math.min(1,f*1.8);return[m*Math.sin(h),g*(1+e),m*Math.cos(h)]},c={top:1,bottom:s?-(t.length+.25+Math.abs(t.fall?.wave??0)):-1,inside(h,u){const d=u-r(h);if(!s)return d;const f=Math.min(u+a(h),mo(h,0)-o);return Math.max(d,f)},position(h,u){if(s&&u<0){const w=t.length<1.5?.14*Ms(-t.length+.45,-t.length-.1,u):0,k=(t.fall?.taper??0)*Ms(0,-Math.max(.1,a(h)),u),S=1+e+t.volume*(1-w*2.5)+Yg(t,h,u)-w-k;return[S*Math.sin(h),u,S*Math.cos(h)]}const d=.4+.6*Ms(0,.3,u-Wi(t,h)),f=1+e+(t.volume+Yg(t,h,u))*d,m=l(h,u,f);if(m)return m;const[g,p,y]=He(h,u),v=[g*f,p*f,y*f];if(t.quiff>0){const w=t.quiff*Math.exp(-((h/.7)**2))*Ms(.15,.85,u);v[1]+=w*.7,v[2]+=w*.45}return v},normal(h,u){return s&&u<0?[Math.sin(h),0,Math.cos(h)]:He(h,u)}};return s&&!Bg(n)?fS(c,t,n):c}function fS(t,e,n){const s=r=>r<0?Ms(-.15,-Math.max(.7,e.length),r):0,i=r=>Dn(n.swing)*s(r);return{top:t.top,bottom:t.bottom,inside:(r,o)=>t.inside(r+i(o),o),position(r,o){const a=s(o);if(a===0)return t.position(r,o);const l=i(o),[c,h,u]=Ec(t.position(r+l,o),l);return[c,h+n.lift*a,u-n.trail*a]},normal:(r,o)=>Ec(t.normal(r+i(o),o),i(o))}}const gS=t=>t.texture==="spiky"||t.texture==="curly"||t.texture==="locs"?104:t.texture==="wavy"?80:64;function Gg(t,e,n,s){return kc(t,pS(e,s),()=>po(t,n,gS(e)))}const Ug=new WeakMap;let mS=1;function pS(t,e){if(Bg(e))return t;let n=Ug.get(t);return n||Ug.set(t,n=mS++),`${n}:${e.swing}:${e.trail}:${e.lift}`}function Vg(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 Pc(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 yS(t,e,n,s=16){return Array.from({length:s+1},(i,r)=>{const o=r/s,a=1-o;return{x:a*a*t.x+2*a*o*e.x+o*o*n.x,y:a*a*t.y+2*a*o*e.y+o*o*n.y}})}function bS(t,e,n,s,i){const r=t.ry,o=(e.length??1.8)*r,a=Pc(t,Ec(s,Dn(i.swing))),l=Pc(t,[0,i.lift,-i.trail]),c=Math.hypot(a.x,a.y)||1,h=e.at==="high"||e.at==="low"||e.at==="top"?Pc(t,[.95,0,0]):{x:0},u=e.kind==="braid"?.15:.5,d={x:n.x+a.x/c*r*u+h.x*.9+l.x*.5,y:n.y+a.y/c*r*u*.6+l.y*.5},f={x:n.x+a.x/c*r*u*.6+h.x*1.3+l.x,y:n.y+o+l.y};return yS(n,d,f)}const yo=t=>Math.max(1,t*.5),Jg=(t,e)=>Math.max(.8,Math.min(t*.4,.1*e.rx));function Zg(t,e,n,s,i,r){const{point:o,out:a}=Vg(s.at),l=1+n.volume,c=_t(e,[o[0]*l,o[1]*l,o[2]*l]),h=yo(i),u=Jg(i,e);if(s.kind==="bun"){const g=s.size??.32,p=_t(e,[o[0]*l+a[0]*g,o[1]*l+a[1]*g,o[2]*l+a[2]*g]);t.ellipse(p.x,p.y,g*e.rx,g*e.ry,e.angle,n.color,h);const y=g*e.rx*.55;t.line(Array.from({length:9},(v,w)=>{const k=-.4+w/8*Math.PI*1.3;return{x:p.x+Math.cos(k)*y,y:p.y+Math.sin(k)*y*.8}}),u);return}const d=bS(e,s,c,a,r),f=(s.size??(s.kind==="braid"?.2:.34))*e.rx*2;if(s.kind==="ponytail")t.shape(qt(d,f,f*.15),n.color,h),t.line(d.slice(3,d.length-3),u);else{const p=d.slice(0,d.length-3);for(let w=0;w<7;w++){const k=p[Math.floor(w/7*(p.length-1))],S=p[Math.floor((w+1)/7*(p.length-1))],x=Math.atan2(S.y-k.y,S.x-k.x),M=Math.hypot(S.x-k.x,S.y-k.y),E=f*(1-w/(7*2.2)),T=(w%2===0?1:-1)*.35,A={x:(k.x+S.x)/2,y:(k.y+S.y)/2};t.ellipse(A.x,A.y,M*.62,E*.5,x+T,n.color,h*.8)}const y=p[p.length-1],v=d[d.length-1];t.shape(qt([y,v],f*.7,f*.2),n.color,h*.8)}const m=d[s.kind==="braid"?d.length-4:2];t.ellipse(m.x,m.y,f*.32,f*.22,e.angle,n.color,h)}function Qg(t,e){return ne(t,Vg(e.at).out)<-.2}function wS(t){const e=(i,r,o=0,a=14)=>Array.from({length:a+1},(l,c)=>{const h=c/a;return[i[0]+(r[0]-i[0])*h+o*Math.sin(Math.PI*h),i[1]+(r[1]-i[1])*h]}),n=Dn(t.part??0),s=i=>Wi(t,i)+.04;switch(t.strands){case"part":return[e([n,s(n)],[n,.97])];case"sweep":{const i=Math.sign(t.sweep||-1),r=[.9,.72,.55].map((o,a)=>{const l=n+i*(.6+a*.35);return e([n,o],[l,Math.max(s(l)+.05,o-.35)],.05*i)});return[e([n,s(n)],[n,.97]),...r]}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,r=[-2.6,-2,-1.4,1.4,2,2.6,3.05].map(o=>e([o,Wi(t,o)<.9?.6:.9],[o,i],0));return t.part!==null&&r.push(e([n,s(n)],[n,.97])),r}default:return[]}}function kS(t,e,n,s,i){if(s.fill==="stipple"||s.hairline.front>1.5)return;const r=i.motion??vs,o=i.lineWidth*.45/n.rx,{far:a}=Gg(n,s,Xg(s,o,r),r);vc(e,n,()=>{for(const l of s.ties)Qg(n,l)&&Zg(t,n,s,l,i.lineWidth,r);tm(t,n,s,i.lineWidth,o,!1);for(const l of a)t.shape(l,s.color,yo(i.lineWidth));Wg(t,n,s,o,r,i.lineWidth,!1)},i.headOutline)}function $c(t,e,n,s){if(n.hairline.front>1.5)return;const i=s.motion??vs,r=s.lineWidth*.45/e.rx,o=Xg(n,r,i),a=Jg(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(o.inside(u+d,h)<.02)continue;const f=He(u+d,h);if(ne(e,f)<.12)continue;const m=_t(e,f);t.dot(m.x,m.y,a*.4)}return}const{near:l}=Gg(e,n,o,i),c=yo(s.lineWidth);tm(t,e,n,s.lineWidth,r,!0);for(const h of l)t.shape(h,n.color,c);Wg(t,e,n,r,i,s.lineWidth,!0);for(const h of wS(n)){const u=h.map(([f,m])=>{const[g,p,y]=o.position(f,m);return[g*.985,p*.985,y*.985]}),d=h.map(([f,m])=>o.normal(f,m));for(const f of Fg(e,u,d,.12))t.line(f,a)}for(const h of n.ties)Qg(e,h)||Zg(t,e,n,h,s.lineWidth,i)}function tm(t,e,n,s,i,r){for(const o of n.spikes??[]){const a=He(Dn(o.around),Math.max(-1,Math.min(1,o.up)));if(ne(e,a)>=0!==r)continue;const l=[Math.cos(Dn(o.around)),0,-Math.sin(Dn(o.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,o.width),d=Math.max(0,o.length),f=[_t(e,a.map(m=>m*(h+d)))];for(let m=0;m<8;m++){const g=m*Math.PI/4,p=a.map((y,v)=>y*h+u*(l[v]*Math.cos(g)+c[v]*Math.sin(g)));f.push(_t(e,p))}t.shape(bc(f),n.color,yo(s))}}const em=.35,Ic=t=>({centre:[t*.98,-.02,-.08],out:[t,0,-.12]});function nm(t,e,n,s,i){const{centre:r,out:o}=Ic(n),a=ne(e,o),l=Math.max(1,s.lineWidth*.55),c=s.skin==="none"?null:s.skin,h=e.ry*.27;if(!i){const p=_t(e,[r[0]*1.06,r[1],r[2]]);t.ellipse(p.x,p.y,e.rx*.17,h,e.angle,c,l);return}const u=_t(e,r),d=e.rx*(.12+.08*a);t.ellipse(u.x,u.y,d,h,e.angle,c,l);const f=Math.cos(e.angle),m=Math.sin(e.angle),g=Array.from({length:9},(p,y)=>{const v=-Math.PI*.55+y/8*Math.PI*1.1,w=Math.cos(v)*d*.45*-n,k=Math.sin(v)*h*.55;return{x:u.x+w*f-k*m,y:u.y+w*m+k*f}});t.line(g,Math.max(.8,l*.7))}function vS(t,e,n,s){vc(e,n,()=>{for(const i of[1,-1])ne(n,Ic(i).out)<em&&nm(t,n,i,s,!1)},s.headOutline)}function MS(t,e,n){for(const s of[1,-1])ne(e,Ic(s).out)>=em&&nm(t,e,s,n,!0)}const Oc={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 sm(t,e){const n=typeof t=="string"?{style:t}:t,s=n.style?Oc[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 un=t=>t*Math.PI/180,bo=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},im={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}},SS=(t,e)=>{const n=bo(un(48),un(100),mo(e,0));return t.top[0]+(t.top[1]-t.top[0])*n},TS=t=>t==="sideburns"||t==="muttonChops";function Cc(t,e){const n=im[t];if(!n)return null;const s=un(n.reach),i=r=>{const o=mo(r,0);return n.shape==="point"?Math.exp(-((o/.42)**2)):n.shape==="square"?1-bo(un(45),un(85),o):Math.cos(Math.min(o,Math.PI/2))**.7};return{top:Math.max(n.top[0],n.top[1])+.05,bottom:-1,inside(r,o){const a=mo(r,0),l=SS(n,r);let c=Math.min(l-o,s-a);if(n.band>0&&(c=Math.min(c,o-(l-n.band))),TS(t)){const h=t==="muttonChops"?un(70)-un(22)*bo(.08,-.6,o):un(72);c=Math.min(c,a-h)}return c},position(r,o){const[a,l,c]=He(r,o),h=1+e+n.volume,u=n.length*i(r)*bo(-.45,-1,o);return[a*h,l*h-u,c*h+u*.25]},normal:(r,o)=>He(r,o)}}function ES(t){const n=s=>s.map(([i,r])=>({x:i,y:-.24+r}));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 Di=t=>Math.max(1,t*.45);function AS(t,e,n,s){for(let i=.1;i>-1;i-=.13)for(let r=-Math.PI/1.7;r<Math.PI/1.7;r+=.2){const o=Math.round(i*100)%2*.1;if(n.inside(r+o,i)<.02)continue;const a=He(r+o,i);if(ne(e,a)<.15)continue;const l=_t(e,a);t.dot(l.x,l.y,s)}}function xS(t,e,n,s,i){const r=s.beard==="stubble"?null:Cc(s.beard,i.lineWidth*.45/n.rx);if(!r)return;const{far:o}=kc(n,s,()=>po(n,r));vc(e,n,()=>{for(const a of o)t.shape(a,s.color,Di(i.lineWidth))},i.headOutline)}function PS(t,e,n,s,i){if(n.beard==="none")return;const r=s.lineWidth*.45/e.rx;if(n.beard==="stubble"){AS(t,e,Cc("full",r),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}=kt(e,l,{x:0,y:-.6},s.face?.projection);h>-.05&&t.shape(c,n.color,Di(s.lineWidth)*.7);return}const o=Cc(n.beard,r);if(!o)return;const{near:a}=kc(e,n,()=>po(e,o));for(const l of a)t.shape(l,n.color,Di(s.lineWidth));if(im[n.beard]?.aroundMouth){const l=.27*Math.max(.3,i),c=Array.from({length:20},(d,f)=>{const m=Math.PI*2*f/20;return{x:Math.cos(m)*l,y:-.42+Math.sin(m)*.13}}),{points:h,facing:u}=kt(e,c,{x:0,y:-.42},s.face?.projection);u>-.05&&t.shape(h,s.skin==="none"?"#ffffff":s.skin,0)}}function $S(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}=kt(e,l,i,s.face?.projection);h>-.05&&t.line(c,Math.max(1,s.lineWidth*.32));return}const r=ES(n.moustache);if(!r)return;const{points:o,facing:a}=kt(e,r,i,s.face?.projection);if(!(a<=-.05)&&(t.shape(o,n.color,Di(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(kt(e,c,i,s.face?.projection).points,Di(s.lineWidth)*.8)}}const _c={round:!0,square:!0,sunglasses:!0};function rm(t){const n=(typeof t=="string"?{style:t}:t).style??"round";if(!(n in _c))throw new Error(`glasses: unknown style '${n}'`);return{style:n}}const IS=.05,wo={x:.34,y:.12,rx:1,ry:1},OS={x:be.x,y:be.y,rx:(be.rx+.03)/.2,ry:(be.ry+.06)/.19};function CS(t,e,n=wo){return Array.from({length:28},(i,r)=>{const o=Math.PI*2*r/28;if(t==="round")return{x:e+Math.cos(o)*.2*n.rx,y:n.y+Math.sin(o)*.19*n.ry};const a=Math.cos(o),l=Math.sin(o),c=(t==="sunglasses"?.22:.21)*n.rx*(n===wo?1:.93),h=(t==="sunglasses"?.17:.16)*n.ry*(n===wo?1:1.12);return{x:e+Math.sign(a)*Math.abs(a)**.45*c,y:n.y-.01+Math.sign(l)*Math.abs(l)**.45*h}})}function _S(t,e,n,s){const i=Math.max(1,Math.min(s.lineWidth*.5,.11*e.rx)),r=s.face?.style==="oval"?OS:wo,o=.2*r.rx,a=[];for(const l of[1,-1]){const c=r.x*l,{points:h,facing:u}=kt(e,CS(n.style,c,r),{x:c,y:r.y},s.face?.projection);if(u<IS)continue;a.push(l),t.shape(h,n.style==="sunglasses"?"#1f2328":null,i);const d=[l*.97,r.y+.02,-.1];if(ne(e,[l,0,0])>.15){const f=kt(e,[{x:c+l*(o+.01),y:r.y+.02}],{x:c,y:r.y},s.face?.projection).points[0];t.line([f,_t(e,d)],i*.9)}}if(a.length===2&&r.x-o>.02){const l=[{x:r.x-o,y:r.y+.02},{x:0,y:r.y+.07},{x:-(r.x-o),y:r.y+.02}];t.line(kt(e,l,{x:0,y:r.y},s.face?.projection).points,i)}}const ko={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 om(t){const e=typeof t=="string"?{style:t}:t,n=e.style??"cap",s=ko[n];if(!s)throw new Error(`hat: unknown style '${n}'`);return{style:n,color:e.color??s.color}}const Bn=(t,e)=>t.brim[1]+(t.brim[0]-t.brim[1])*(1+Math.cos(e))/2;function RS(t,e){return{top:1,bottom:Math.min(...t.brim)-.05,inside:(n,s)=>s-Bn(t,n),position(n,s){const[i,r,o]=He(n,s),a=Bn(t,n),l=s>a?(r-a)*(t.height-1):0;return[i*e,r*e+l,o*e]},normal:(n,s)=>He(n,s)}}function HS(t,e,n){const i=(r,o,a)=>{const l=Bn(e,r)*n-a;return[Math.sin(r)*o,l,Math.cos(r)*o]};if(e.peak){const r=[],o=[];for(let a=0;a<=24;a++){const l=(-80+160*a/24)*(Math.PI/180),c=e.peak*Math.cos(l)**.6;r.push(_t(t,[Math.sin(l)*(n+c*.25),Bn(e,l)*n-.07*Math.cos(l),Math.cos(l)*(n+c)])),o.push(_t(t,i(l,n,0)))}return[...r,...o.reverse()]}return e.ring?Array.from({length:48},(r,o)=>_t(t,i(Math.PI*2*o/48,n+e.ring,.07))):null}function FS(t){const e=s=>Array.from({length:13},(i,r)=>[s,Bn(t,s)+(.97-Bn(t,s))*r/12]),n=s=>Array.from({length:49},(i,r)=>{const o=-Math.PI+Math.PI*2*r/48;return[o,Bn(t,o)+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 am(t,e,n,s){const i=ko[n.style],o=1+s.lineWidth*.45/e.rx+Math.max(.05,Math.min(.3,s.hairVolume)+.04),a=Math.max(1,s.lineWidth*.5),l=HS(e,i,o);l&&t.shape(l,n.color,a);const c=RS(i,o),{near:h,far:u}=po(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 FS(i)){const m=f.map(([p,y])=>{const[v,w,k]=c.position(p,y);return[v*.99,w*.99,k*.99]}),g=f.map(([p,y])=>He(p,y));for(const p of Fg(e,m,g,.1))t.line(p,d)}if(i.detail==="seams"){const f=_t(e,[0,o*1.01,0]);t.dot(f.x,f.y,a*.9)}}function lm(t){const e=t.hair?Kg(t.hair):null;return{hair:e,facialHair:t.facialHair?sm(t.facialHair,e?.color):null,glasses:t.glasses?rm(t.glasses):null,hat:t.hat?om(t.hat):null,ears:t.ears??!1}}const cm=t=>!t.hair&&!t.facialHair&&!t.glasses&&!t.hat&&!t.ears,hm=t=>t.axes[2][2]<-.3,um=t=>t.ears&&!t.hair?.coversEars;function dm(t,e,n,s,i,r){if(cm(n))return;const o={...r,headOutline:r.face&&(r.face.shape==="angular"||r.face.projection==="volume")?xg(s,r.face):void 0};n.hair&&kS(e,t,s,n.hair,{...o,motion:Ni(i)}),n.facialHair&&xS(e,t,s,n.facialHair,o),um(n)&&vS(e,t,s,o)}function LS(t,e,n,s,i,r,o){if(cm(n)){o();return}const a=hm(s);um(n)&&MS(e,s,r),n.hair&&!a&&!r.faceUnderHair&&$c(e,s,n.hair,{...r,motion:Ni(i)}),n.facialHair&&PS(e,s,n.facialHair,r,i.mouthWidth??1),o(),n.hair&&!a&&r.faceUnderHair&&$c(e,s,n.hair,{...r,motion:Ni(i)}),n.facialHair&&$S(e,s,n.facialHair,r),n.glasses&&_S(e,s,n.glasses,r),n.hat&&!a&&am(e,s,n.hat,{lineWidth:r.lineWidth,hairVolume:n.hair?.volume??0})}function fm(t,e,n,s,i,r){hm(s)&&(n.hair&&$c(e,s,n.hair,{...r,motion:Ni(i)}),n.hat&&am(e,s,n.hat,{lineWidth:r.lineWidth,hairVolume:n.hair?.volume??0}))}const gm=40,NS=.215+.205,fe=(t,e)=>{const n={};for(const s of["left","right"])for(const[i,r]of Object.entries(e))n[`${t}.${s}.${i}`]=r;return n},gt=(t,e)=>t[e]??lt[e]??0;function vo(t,e,n=lt,s=1){const i=Ti(t),r=e*Math.PI*2,o=Math.sin(r)*s,a=Math.cos(r)*s,l=Kl(i,r),c=i.crouch??0,h=i.forearm??0,u={...lt,...n};u.lean=gt(n,"lean")+i.lean*s,u.bend=gt(n,"bend")+(i.bend??0);const d=(i.shoulder??0)+u.lean+u.bend,f=Yl(i,a);u["leg.left.swing"]=i.swing*o+c*.6+f.left*.5,u["leg.right.swing"]=-i.swing*o+c*.6+f.right*.5,u["leg.left.knee"]=i.knee*Math.max(0,a)+c*1.2+f.left,u["leg.right.knee"]=i.knee*Math.max(0,-a)+c*1.2+f.right,u["leg.left.ankle"]=gt(n,"leg.left.ankle")-(i.tiptoe??0),u["leg.right.ankle"]=gt(n,"leg.right.ankle")-(i.tiptoe??0);for(const[m,g]of[["left",-1],["right",1]])gt(n,`arm.${m}.spread`)>gm||gt(n,`arm.${m}.swing`)>gm||(u[`arm.${m}.swing`]=d+g*i.arm*o,u[`arm.${m}.elbow`]=gt(n,`arm.${m}.elbow`)+h+i.elbow*Math.max(0,g*o));return u["head.nod"]=gt(n,"head.nod")-i.lean*.5*s+(i.headTilt??0),u.side=gt(n,"side")+(i.sway??0)*Math.sin(r),u.lift=gt(n,"lift")+(i.bounce??0)*s*l,u.stretch=gt(n,"stretch")*(1+(i.squash??0)*(l-.5)),u}function Mo(t,e,n=1,s=1){const i=Ti(t);return 4*NS*s*e*Math.sin(i.swing*n*Math.PI/180)}const Ss=t=>oc[t],So={take:t=>[{after:140,pose:{stretch:.8,bend:10,lean:gt(t,"lean")-4,...fe("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,...fe("arm",{spread:150,bend:35,swing:0,elbow:0}),...fe("leg",{swing:25,knee:60}),...Ss("shocked")},easing:"ease-out-cubic"},{after:720,pose:{lift:.25,stretch:1.25,bend:-10,...fe("arm",{spread:140})},easing:"ease-in-out"},{after:900,pose:{lift:0,stretch:.74,bend:12,...fe("arm",{spread:70,bend:0}),...fe("leg",{swing:30,knee:60})},easing:"ease-in-quad"},{after:1060,pose:{stretch:1.06,bend:-3,...fe("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"),...Ss("surprised"),...fe("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,...Ss("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,...Ss("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,...fe("arm",{spread:75}),...fe("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"),...fe("leg",{swing:0,knee:0})},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...Ss("scared"),...fe("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:{...Ss("sad"),bend:18,stretch:.92,lean:gt(t,"lean")+5,"head.nod":14,...fe("arm",{spread:6,swing:0,elbow:4,bend:0})},easing:"ease-in-out"}]};function mm(t,e){const n=vt(e.from??{}),s=e.speed??1;let i=n;return[{time:e.at,pose:n},...So[t](n).map(r=>(i={...i,...r.pose},{time:e.at+r.after*s,pose:i,act:!1,...r.easing?{easing:r.easing}:{}}))]}function pm(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 ym(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 Rc={sweeping:pm,brushing:ym};function WS(t,e,n=lt){const s=Rc[t];if(!s)throw new Error(`humanCyclePose: ${dt("cycle",t,Object.keys(Rc))}`);return s(e,n)}function bm(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 wm(t,e){const n=t.flatMap(i=>Array.from({length:8},(r,o)=>({x:i.x+Math.cos(o*Math.PI/4)*e,y:i.y+Math.sin(o*Math.PI/4)*e})));let s=bc(n);for(let i=0;i<2;i++)s=s.flatMap((r,o)=>{const a=s[(o+1)%s.length];return[{x:r.x*.75+a.x*.25,y:r.y*.75+a.y*.25},{x:r.x*.25+a.x*.75,y:r.y*.25+a.y*.75}]});return s}const km=t=>t.flatMap(e=>[e.left,e.right]);function Hc(t,e={}){const{top:n,length:s}=bm(e),i=t.bodyContours;if(!i?.spine)throw new Error("leafOutfit requires organic body contours");const r=i.spine.samples.filter(a=>a.at<=.3),o=["left","right"].flatMap(a=>i[`leg.${a}`]?.samples.filter(l=>l.at<=s)??[]);return{...n?{top:wm(km(i.spine.samples.filter(a=>a.at>=.52&&a.at<=.91)),t.height*.01)}:{},skirt:wm(km([...r,...o]),t.height*.012)}}function DS(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 BS(t,e,n){const s=e.x-t.x,i=e.y-t.y,r=Math.hypot(s,i)||1,o=-i/r,a=s/r,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+o*f,y:t.y+i*u+a*f})}return l}function vm(t,e,n,s,i,r){const o=e.lineWidth*.7;if(n.shape(s,i,o),n.look==="silhouette")return;t.save(),DS(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 m=0;m<5;m++){const g={x:a+u*(m/4+(f?.07:-.04)),y:c+d*(f?.38:-.1)},p={x:g.x+u*.09,y:g.y+d*.78};n.shape(BS(g,p,u*.13),(m+f)%2?i:r,o*.6),n.line([g,{x:g.x*.45+p.x*.55,y:g.y*.45+p.y*.55},p],o*.45);for(const y of[.32,.52,.7]){const v={x:g.x+(p.x-g.x)*y,y:g.y+(p.y-g.y)*y};n.line([{x:v.x-u*.045,y:v.y-d*.065},v,{x:v.x+u*.045,y:v.y-d*.05}],o*.3)}}t.restore()}function Mm(t={}){const e=bm(t),{color:n,accent:s}=e,i=r=>(o,a,l)=>{const c=Hc(a,e);r==="spine"&&c.top&&vm(o,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);r===h&&vm(o,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 zS={apron:"#d8b48a",labCoat:"#f4f6f8",hoodie:"#6b7280",cardigan:"#6b8e4e",overalls:"",sari:"#16a34a"},Fc=(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 qS(t){return t.parts["leg.left"].order>t.parts["leg.right"].order?"left":"right"}const Sm=t=>Math.max(t.parts["leg.left"].order,t.parts["leg.right"].order)>t.parts.spine.order,se=t=>t.bodyForward?.[2]??Math.cos(t.turn*Math.PI/2),ze=t=>t.bodyForward?.[0]??Math.sin(t.turn*Math.PI/2);function Tm(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 Em(t,e,n=0){const s=e*(t.length-1),i=Math.min(t.length-2,Math.floor(s)),r=t[i],o=t[i+1],a=pt(r,o,s-i),l=Math.hypot(o.x-r.x,o.y-r.y)||1;return{x:a.x+(o.y-r.y)/l*n,y:a.y-(o.x-r.x)/l*n}}function Am(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",r=e==="dress"?i:t.trousers??"#24476b",o=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"?zS[t.over]:r),m=t.shoes==="boots",g=t.shoeColor??"#3b2a1e",p=$=>$.lineWidth*.45,y=($,C,z,X)=>{const W=C.parts[`leg.${X}`].points;if(a==="skirt"&&!u)return;const N=a==="shorts"&&!u,D=C.bodyContours?.[`leg.${X}`],G=D?yc(D,0,N?.5:1,C.height*.006):qt(N?Fc(W,0,.5):W,C.height*(N?.085:.08),C.height*(N?.07:.05));z.shape(G,r,p(C)),!(n==="plain"||se(C)<.15)&&Tm($,G,()=>{const q=(Z,et=0)=>Em(W,Z,et*C.height);if(n==="jeans")z.line([q(.07,-.018),q(.17,-.02),q(.23,0),q(.17,.02),q(.07,.018)],p(C)*.65),z.line([q(.27,.013),...[.4,.55,.7,.85,.96].filter(Z=>!N||Z<.5).map(Z=>q(Z,.013))],p(C)*.5);else{const Z=[q(.25,-.024),q(.25,.024),q(.43,.024),q(.43,-.024)];z.shape(Z,r,p(C)*.65),z.line([q(.28,-.024),q(.32,0),q(.28,.024)],p(C)*.65);const et=q(.32);z.dot(et.x,et.y,p(C)*.8)}})},v=($,C,z)=>{const X=$.parts[`leg.${z}`].points,W=Fc(X,.7,1);if(W.length<2)return;C.shape(qt(W,$.height*.075,$.height*.07),g,p($));const N=W[0],D=W[1],G=D.x-N.x,q=D.y-N.y,Z=Math.hypot(G,q)||1,et=$.height*.04;C.line([{x:N.x-q/Z*et,y:N.y+G/Z*et},{x:N.x+q/Z*et,y:N.y-G/Z*et}],p($)*.9)},w=$=>{const C=$.chains.spine,z=C[0],X=C[C.length-1],W={x:z.x-(X.x-z.x)*.25,y:z.y-(X.y-z.y)*.25};return{hip:z,top:X,below:W,line:[W,...$.parts.spine.points]}},k=$=>{if($.bodyContours?.spine)return yc($.bodyContours.spine,0,.97,$.height*(c?.014:.006));const C=c?1.14:1,z=Math.hypot($.points["hip.left"].x-$.points["hip.right"].x,$.points["hip.left"].y-$.points["hip.right"].y),X=Math.max($.height*.15*C,z+Math.max($.height*.08,$.lineWidth*1.45)+p($));return qt(w($).line,X,$.height*.14*C)},S=($,C)=>{const z=[k(C)],{top:X,hip:W}=w(C);h&&z.push(qt([X,pt(X,W,.5),pt(X,W,1.08)],C.height*.155,C.height*.15)),l&&z.push(qt([X,pt(X,W,.5),W],C.height*.14,C.height*.15));const N=Object.values(C.points),D=Math.min(...N.map(et=>et.x))-C.height,G=Math.min(...N.map(et=>et.y))-C.height,q=Math.max(...N.map(et=>et.x))+C.height,Z=Math.max(...N.map(et=>et.y))+C.height;for(const et of z){$.beginPath(),$.rect(D,G,q-D,Z-G),$.moveTo(et[0].x,et[0].y);for(const H of et.slice(1))$.lineTo(H.x,H.y);$.closePath(),$.clip("evenodd")}},x=($,C)=>{const z=c?f:i;C.shape(k($),z,p($))},M=($,C,z)=>{const X=se(C);if(!e||X<.2||c)return;const{top:W,hip:N}=w(C),D=ze(C)*C.height*.025,G=[W,N],q=(Z,et=0)=>Em(G,Z,D+et*C.height*X);Tm($,k(C),()=>{if(e==="shirt"){z.line([q(.12),q(.92)],p(C)*.65);for(const Z of[.24,.4,.56,.72,.88]){const et=q(Z,.008);z.dot(et.x,et.y,p(C)*.9)}}else if(e==="blouse"){z.line([q(.025,-.04),q(.24),q(.025,.04)],p(C)*.75);const Z=q(.31);z.dot(Z.x,Z.y,p(C))}else e==="dress"?z.line([q(.04,-.035),q(.17,-.028),q(.17,.028),q(.04,.035)],p(C)*.75):z.line([q(.025,-.035),q(.1,-.02),q(.12),q(.1,.02),q(.025,.035)],p(C)*.65)})},E=($,C)=>{const z=se($),{top:X,hip:W}=w($),N=$.height*.07,D={x:(X.x-W.x)*.16,y:(X.y-W.y)*.16};if(z>=0){C.shape([{x:X.x-N,y:X.y+D.y*.25},{x:X.x-N*.8+D.x,y:X.y+D.y},{x:X.x+D.x*1.2,y:X.y+D.y*1.35},{x:X.x+N*.8+D.x,y:X.y+D.y},{x:X.x+N,y:X.y+D.y*.25}],f,p($));return}const G=pt(X,W,.42);C.shape([{x:X.x-N*.9,y:X.y},{x:X.x+N*.9,y:X.y},{x:G.x+N*.7,y:G.y},{x:G.x,y:G.y+$.height*.02},{x:G.x-N*.7,y:G.y}],f,p($))},T=($,C)=>{const z=se($);if(z<.2)return;const{top:X,hip:W}=w($),N=ze($)*$.height*.03,D=$.height*.06*z,G=pt(X,W,.62),q=pt(X,W,.9);C.line([{x:G.x+N-D,y:G.y},{x:q.x+N-D*1.1,y:q.y}],p($)*.7),C.line([{x:G.x+N+D,y:G.y},{x:q.x+N+D*1.1,y:q.y}],p($)*.7);const Z=pt(X,W,.1);for(const et of[-1,1])C.line([{x:Z.x+N+et*D*.2,y:Z.y},{x:Z.x+N+et*D*.35,y:Z.y+$.height*.07}],p($)*.6)},A=($,C)=>{const{top:z,hip:X}=w($),W=se($);if(C.shape(qt([z,pt(z,X,.5),pt(z,X,1.08)],$.height*.155,$.height*.15),f,p($)),W<.2)return;const N=ze($)*$.height*.03,D=$.height*.02*W,G=pt(z,X,.12),q=pt(z,X,1.05);C.shape([{x:G.x+N-D,y:G.y},{x:G.x+N+D,y:G.y},{x:q.x+N+D*1.3,y:q.y},{x:q.x+N-D*1.3,y:q.y}],i,p($)*.7);for(const Z of[.35,.55,.75]){const et=pt(z,X,Z);C.dot(et.x+N+D*1.6,et.y,p($)*1.2)}},P=($,C)=>{const z=se($),{top:X,hip:W}=w($),N=ze($)*$.height*.04,D=pt(W,X,.12),G=pt(W,X,.74);if(z<.15){if(z<-.3){const H=$.points["shoulder.left"],U=$.points["shoulder.right"];C.line([H,{x:D.x+$.height*.03,y:D.y}],p($)*.8),C.line([U,{x:D.x-$.height*.03,y:D.y}],p($)*.8)}return}const q=$.height*.07*z;C.shape([{x:G.x+N-q*.75,y:G.y},{x:G.x+N+q*.75,y:G.y},{x:D.x+N+q*1.1,y:D.y},{x:D.x+N-q*1.1,y:D.y}],r,p($));for(const H of["left","right"]){const U=$.points[`shoulder.${H}`],nt={x:G.x+N+(U.x>G.x+N?1:-1)*q*.55,y:G.y};C.line([nt,{x:U.x+(nt.x-U.x)*.15,y:U.y+(nt.y-U.y)*.15}],p($)*1.6)}const Z=pt(G,D,.3),et=q*.4;C.line([{x:Z.x+N-et,y:Z.y},{x:Z.x+N-et,y:Z.y+et*1.4},{x:Z.x+N+et,y:Z.y+et*1.4},{x:Z.x+N+et,y:Z.y}],p($)*.6)},I=($,C)=>{const{hip:z,top:X}=w($),W=pt(z,X,.2),N=[$.points["ankle.left"],$.points["ankle.right"]],D=pt(z,{x:(N[0].x+N[1].x)/2,y:(N[0].y+N[1].y)/2},.98),G=$.height*.075,q=Math.max($.height*.12,Math.abs(N[0].x-N[1].x)/2+$.height*.07),Z=D.x-W.x,et=D.y-W.y,H=Math.hypot(Z,et)||1,U={x:-et/H,y:Z/H};if(C.shape([{x:W.x+U.x*G,y:W.y+U.y*G},{x:D.x+U.x*q,y:D.y+U.y*q},{x:D.x-U.x*q,y:D.y-U.y*q},{x:W.x-U.x*G,y:W.y-U.y*G}],f,p($)),se($)>.2){const at=ze($)*$.height*.03;for(const rt of[-.35,0,.35]){const ct=G*.5*rt,it=q*.45*rt;C.line([{x:W.x+at+U.x*ct,y:W.y+U.y*ct+$.height*.02},{x:D.x+at+U.x*it,y:D.y+U.y*it}],p($)*.5)}}},O=($,C)=>{const z=se($),{top:X,hip:W}=w($),N=ze($),D=N>=0?"left":"right",G=D==="left"?"right":"left",q=$.points[`shoulder.${D}`],Z=$.height*.035;if(z<.15){const U=pt(X,W,.9);C.shape(qt([q,{x:U.x+(q.x-X.x)*.5,y:U.y}],Z*2.2,Z*2.6),f,p($));return}const et={x:W.x+($.points[`hip.${G}`].x-W.x)*1.2,y:pt(W,X,.08).y};C.shape(qt([et,pt(et,q,.5),q],Z*2.4,Z*2),f,p($));const H={x:q.x-(W.x-q.x)*.05-N*$.height*.03,y:q.y+$.height*.16};C.shape(qt([q,H],Z*2,Z*1.6),f,p($))},_=($,C)=>{if($.bodyContours){C.shape(Hc($,{top:!1,length:.45}).skirt,r,p($));return}const{hip:z,top:X}=w($),W=pt(z,X,.18),N=[$.points["knee.left"],$.points["knee.right"]],D=pt(z,{x:(N[0].x+N[1].x)/2,y:(N[0].y+N[1].y)/2},1.05),G=$.height*.075,q=Math.max($.height*.13,Math.abs(N[0].x-N[1].x)/2+$.height*.08),Z=D.x-W.x,et=D.y-W.y,H=Math.hypot(Z,et)||1,U={x:-et/H,y:Z/H};C.shape([{x:W.x+U.x*G,y:W.y+U.y*G},{x:D.x+U.x*q,y:D.y+U.y*q},{x:D.x-U.x*q,y:D.y-U.y*q},{x:W.x-U.x*G,y:W.y-U.y*G}],r,p($))},L=($,C)=>{const z=se($);if(z<.2)return;const{top:X,hip:W}=w($),N={x:(W.x-X.x)*.12,y:(W.y-X.y)*.12},D=$.height*.045*z;for(const G of[-1,1])C.shape([{x:X.x+G*D*.2,y:X.y+N.y*.1},{x:X.x+G*D*1.3,y:X.y-N.y*.1},{x:X.x+G*D*.6+N.x,y:X.y+N.y}],i,p($)*.8)},j=($,C,z)=>{const X=se($);if(X<.25)return;const{top:W,hip:N}=w($),D=ze($)*$.height*.03,G=H=>({x:pt(W,N,H).x+D,y:pt(W,N,H).y}),q=$.height*.022*X,Z=G(.08),et=G(.62);C.shape([{x:Z.x-q,y:Z.y-q},{x:Z.x+q,y:Z.y-q},{x:Z.x+q*.6,y:Z.y+q},{x:Z.x-q*.6,y:Z.y+q}],z,p($)*.7),C.shape([{x:Z.x-q*.6,y:Z.y+q},{x:Z.x+q*.6,y:Z.y+q},{x:et.x+q*1.4,y:et.y-q*2},et,{x:et.x-q*1.4,y:et.y-q*2}],z,p($)*.7)},V=($,C)=>{const z=se($),{top:X,hip:W}=w($),N=pt(W,X,.72),D=[$.points["knee.left"],$.points["knee.right"]],G=pt(W,{x:(D[0].x+D[1].x)/2,y:(D[0].y+D[1].y)/2},.9),q=ze($)*$.height*.04;if(z<.15){const H=pt(W,X,.2);z<-.3&&C.line([{x:H.x-$.height*.05,y:H.y},{x:H.x+$.height*.05,y:H.y}],p($));return}const Z=$.height*.075*z,et=pt(W,X,.2);C.shape([{x:N.x+q-Z*.7,y:N.y},{x:N.x+q+Z*.7,y:N.y},{x:et.x+q+Z,y:et.y},{x:G.x+q+Z*1.15,y:G.y},{x:G.x+q-Z*1.15,y:G.y},{x:et.x+q-Z,y:et.y}],f,p($)),C.line([{x:N.x+q-Z*.6,y:N.y},{x:X.x-Z*.2,y:X.y},{x:N.x+q+Z*.6,y:N.y}],p($)*.8)},tt=($,C,z)=>{const{top:X,hip:W}=w($),N=[$.points["knee.left"],$.points["knee.right"]],D=pt(W,{x:(N[0].x+N[1].x)/2,y:(N[0].y+N[1].y)/2},.95);z?C.shape(qt([pt(X,W,.8),W,D],$.height*.145,$.height*.17),f,p($)):C.shape(qt([X,pt(X,W,.5),W],$.height*.14,$.height*.15),f,p($));const G=se($);if(G>.2){const q=ze($)*$.height*.03,[Z,et]=z?[W,D]:[X,W];if(C.line([{x:Z.x+q,y:Z.y},{x:et.x+q,y:et.y}],p($)*.8),!z){const H=pt(X,W,.35),U=$.height*.025*G;C.shape([{x:H.x+q-U*2.4,y:H.y},{x:H.x+q-U*.6,y:H.y},{x:H.x+q-U*.6,y:H.y+U*1.6},{x:H.x+q-U*2.4,y:H.y+U*1.6}],f,p($)*.6)}}},J=($,C,z,X,W)=>{const N=$.bodyContours?.[`arm.${z}`];if(N){const Q=yc(N,0,W,$.height*.006);C.shape(Q,X,0);const ot=k($);for(let ht=0;ht<Q.length;ht++){const ft=Q[ht],bt=Q[(ht+1)%Q.length];Sg({x:(ft.x+bt.x)/2,y:(ft.y+bt.y)/2},ot)||C.line([ft,bt],p($))}return}const D=$.parts[`arm.${z}`].points,G=D[0],q=$.chains.spine[$.chains.spine.length-1],et=[{x:G.x+(q.x-G.x)*.45,y:G.y+(q.y-G.y)*.45},...Fc(D,0,W)],H=qt(et,$.height*.085,$.height*(W>.6?.045:.06)),U=et.length,nt=H.slice(0,U),at=H.slice(U).reverse();C.shape(H,X,0);const rt=Q=>Math.hypot(Q[1].x-q.x,Q[1].y-q.y),[ct,it]=rt(nt)>rt(at)?[nt,at]:[at,nt];C.line(ct.slice(1),p($)),C.line(it.slice(Math.ceil(U*.45)),p($)),C.line([nt[U-1],at[U-1]],p($))},F=l||c||h,B=F?f:i,Y=F||o==="long"?.95:.45,R=F||o!=="none",K=($,C)=>{a==="skirt"&&!u&&!d&&_($,C),d&&I($,C),l&&tt($,C,!0),t.over==="apron"&&V($,C)},st=$=>(C,z,X)=>{C.save(),S(C,z),y(C,z,X,$),m&&v(z,X,$),C.restore(),qS(z)===$&&Sm(z)&&K(z,X)};return{parts:{"leg.left":{clip:S,over:st("left")},"leg.right":{clip:S,over:st("right")},spine:{over:($,C,z)=>{c&&se(C)>=0&&E(C,z),x(C,z),M($,C,z),s&&!c&&L(C,z),t.tie&&!c&&j(C,z,t.tie),l&&tt(C,z,!1),h&&A(C,z),c&&(se(C)<0&&E(C,z),T(C,z)),u&&P(C,z),d&&O(C,z),Sm(C)||K(C,z)}},"arm.left":{over:R?($,C,z)=>J(C,z,"left",B,Y):void 0},"arm.right":{over:R?($,C,z)=>J(C,z,"right",B,Y):void 0}}}}const Lc={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 xm(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,r=Lc[i];if(!r)throw new Error(`holding: unknown item '${i}'`);if(n==="both"&&r.hands==="one")throw new Error(`holding: a ${i} is held in one hand ('left' or 'right'), not 'both'`);if(n!=="both"&&r.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)??r.color}}return e}function To(t,e){const n=t.chains[`arm.${e}`],s=n[n.length-1],i=n[n.length-2],r=Math.hypot(s.x-i.x,s.y-i.y)||1,o={x:(s.x-i.x)/r,y:(s.y-i.y)/r},a=t.lineWidth*.5;return{point:{x:s.x+o.x*a,y:s.y+o.y*a},along:o,depth:t.parts[`arm.${e}`]?.depth??0}}function Ts(t,e,n,s=0){const i=Math.cos(s),r=Math.sin(s);return[[-e/2,-n/2],[e/2,-n/2],[e/2,n/2],[-e/2,n/2]].map(([o,a])=>({x:t.x+o*i-a*r,y:t.y+o*r+a*i}))}const Es=(t,e,n,s,i=12)=>Array.from({length:i+1},(r,o)=>{const a=n+(s-n)*o/i;return{x:t.x+Math.cos(a)*e,y:t.y+Math.sin(a)*e}});function Nc(t,e,n,s,i,r=1,o){const{point:a,along:l}=n,c=s/300;switch(e.item){case"mug":{const h=Ts({x:a.x,y:a.y-4*c},20*c,24*c);t.line(Es({x:a.x+10*c*Math.sign(r||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(r||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(Ts(a,13*c,24*c,h),e.color,i),t.shape(Ts(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 m=a.y-u/2+u*f;t.line([{x:a.x+d*5*c,y:m},{x:a.x+d*(h-5*c),y:m-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(Es({x:a.x,y:a.y+6*c},7*c,Math.PI,Math.PI*2),i),t.shape(Ts({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=(o??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(Es({x:a.x+5*c,y:a.y+10*c},5*c,Math.PI,0,8),i);const f=[...Es({x:d.x,y:d.y+h*.55},h,Math.PI,Math.PI*2,24)],m=[];for(let g=4;g>=0;g--){const p=d.x-h+2*h*g/5;m.push(...Es({x:p+h/5,y:d.y+h*.55},h/5,0,-Math.PI,6).reverse())}t.shape([...f,...m],e.color,i);return}case"broom":{const h={x:l.x*.4+.25*Math.sign(r||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},m={x:a.x+d.x*120*c,y:a.y+d.y*120*c};t.line([f,m],i*1.1);const g={x:-d.y,y:d.x},p=[{x:m.x+g.x*6*c,y:m.y+g.y*6*c},{x:m.x-g.x*6*c,y:m.y-g.y*6*c},{x:m.x-g.x*16*c+d.x*34*c,y:m.y-g.y*16*c+d.y*34*c},{x:m.x+g.x*16*c+d.x*34*c,y:m.y+g.y*16*c+d.y*34*c}];t.shape(p,e.color,i);return}case"cane":{const h=Math.min(.56*s,Math.max(.3*s,-a.y)),u=.12*Math.sign(r||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},m=Es({x:a.x+7*c*Math.sign(r||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(r||1),y:g.y}));t.line([...m,{x:a.x,y:a.y+2*c},f],i*1.2),t.shape(Ts({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(Ts(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 Wc=(t,e)=>(t[`held.${e}`]??1)>=.5,Pm=t=>Math.sin(t*Math.PI/2);function $m(t){const e=r=>Math.max(1,r.lineWidth*.45),n=r=>(o,a,l,c,h)=>{const u=t[r];u&&Wc(h??{},r)&&Nc(l,u,To(a,r),a.height,e(a),Pm(a.turn),a.head.center.y-a.head.ry)},s=(r,o,a,l,c)=>{const h=t.both;if(!h||!Wc(c??{},"both"))return;const u=To(o,"left"),d=To(o,"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};Nc(a,h,f,o.height,e(o),Pm(o.turn),o.head.center.y-o.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 r=o=>(a,l,c,h,u)=>{const d=o==="left"?"right":"left";(o==="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 o of["left","right"])i.parts[`arm.${o}`]={...i.parts[`arm.${o}`],over:jS(i.parts[`arm.${o}`]?.over,r(o))}}return i}function jS(t,e){return t?(n,s,i,r,o)=>{t(n,s,i,r,o),e(n,s,i,r,o)}:e}const As=(t,e,n)=>Math.min(n,Math.max(e,t)),Bi=(t,e)=>typeof t=="number"&&Number.isFinite(t)?t:e;function Im(t={}){const e=t.limbs??"tube";if(e!=="tube"&&e!=="line")throw new Error(`bean: unknown limbs '${String(e)}' (tube | line)`);const n=t.sleeves??"short";if(!["short","long","none"].includes(n))throw new Error(`bean: unknown sleeves '${String(n)}' (short | long | none)`);const s=t.fill??"#ffffff";return{limbs:e,torso:As(Bi(t.torso,1),.4,2.5),limbWidth:As(Bi(t.limbWidth,.024),.004,.12),lineWidth:As(Bi(t.lineWidth,.017),.003,.08),outlineWidth:As(Bi(t.outlineWidth,.0105),.001,.05),fill:s,shirt:t.shirt??null,sleeves:n,trousers:t.trousers??null,shoes:t.shoes??s,halo:t.halo??null,coat:t.coat??null,fedora:t.fedora??null,skirt:KS(t.skirt),drape:t.drape??null,bangles:t.bangles??null}}function KS(t){if(t==null)return null;if(typeof t=="string")return{color:t,length:1};if(typeof t!="object"||typeof t.color!="string")throw new Error("bean: skirt is a colour or { color, length }");return{color:t.color,length:As(Bi(t.length,1),.1,1)}}const we=(t,e,n=.5)=>({x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n});function Om(t,e){const{points:n}=e,s=we(n["shoulder.left"],n["shoulder.right"]),i=n.hip,r=Math.hypot(s.x-i.x,s.y-i.y);return{cx:(s.x+i.x)/2,cy:(s.y+i.y)/2,length:Math.max(r,e.height*.04),width:e.height*.068*t.torso,angle:r>1e-6?Math.atan2(s.y-i.y,s.x-i.x):-Math.PI/2}}function Cm(t){const e=t.length,n=e*.58,s=-e*.62,i=t.width*.82,r=t.width*.74,o=t.width,a=u=>[[{x:n,y:u*i},{x:n-e*.16,y:u*i}],[{x:e*.05,y:u*r*.98},{x:-e*.05,y:u*r}],[{x:-e*.3,y:u*o*1.04},{x:s+e*.14,y:u*o}],[{x:s,y:u*o*.95},{x:s,y:0}]],l=a(1),c=[{x:n,y:0},...l.map(([,u])=>u)],h=l.map(([u],d)=>[u,c[d]]).reverse();return{start:{x:n,y:0},segments:[...a(-1),...h]}}function xs(t,e){const n=Math.cos(t.angle),s=Math.sin(t.angle);return{x:t.cx+e.x*n-e.y*s,y:t.cy+e.x*s+e.y*n}}function YS(t,e=8){const{start:n,segments:s}=Cm(t),i=[xs(t,n)];let r=n;for(const[o,a]of s){for(let l=1;l<=e;l++){const c=l/e,h=1-c;i.push(xs(t,{x:h*h*r.x+2*h*c*o.x+c*c*a.x,y:h*h*r.y+2*h*c*o.y+c*c*a.y}))}r=a}return i}function _m(t,e,n={}){const s=h=>e.parts[h]?.depth??0,i=h=>(n[h]??0)>e.height*(h.startsWith("leg.")?Hm:Rm),r=s("arm.left")>=s("arm.right")?["arm.right","arm.left"]:["arm.left","arm.right"],o=s("leg.left")>=s("leg.right")?["leg.right","leg.left"]:["leg.left","leg.right"],a=h=>i(h)||h===r[1],l=h=>i(h)||t.limbs==="tube"&&!t.trousers&&!t.coat&&!t.skirt,c=t.limbs==="tube"&&!t.shirt&&!t.coat;return[...r.filter(h=>!a(h)),...o.filter(h=>!l(h)),...c?[]:["neck"],"spine",...c?["neck"]:[],...o.filter(l),...r.filter(a),"head"]}const Rm=.08,Hm=.12;function zi(t,e){return(t.parts[e]?.order??0)>(t.parts.spine?.order??0)}function XS(t,e){if(t.beginPath(),t.moveTo(e[0].x,e[0].y),e.length===2){t.lineTo(e[1].x,e[1].y);return}for(let n=1;n<e.length-1;n++){const s=n===e.length-2?e[n+1]:we(e[n],e[n+1]);t.quadraticCurveTo(e[n].x,e[n].y,s.x,s.y)}}function qi(t,e,n,s=12){const r={x:2*e.x-(t.x+n.x)/2,y:2*e.y-(t.y+n.y)/2};return Array.from({length:s+1},(o,a)=>{const l=a/s,c=1-l,h={x:c*c*t.x+2*c*l*r.x+l*l*n.x,y:c*c*t.y+2*c*l*r.y+l*l*n.y},u=l<.5?we(t,e,2*l):we(e,n,2*l-1);return we(u,h,.55)})}function Dc(t,e,n,s,i){i&&Vt(t,e,n*1.9,i),Vt(t,e,n,s)}function Vt(t,e,n,s){e.length<2||(t.lineCap="round",t.lineJoin="round",XS(t,e),t.strokeStyle=s,t.lineWidth=n,t.stroke())}function Eo(t,e){const{start:n,segments:s}=Cm(e),i=xs(e,n);t.moveTo(i.x,i.y);for(const[r,o]of s){const a=xs(e,r),l=xs(e,o);t.quadraticCurveTo(a.x,a.y,l.x,l.y)}t.closePath()}function Ao(t,e,n,s,i){for(const o of[()=>Eo(t,e),()=>t.arc(n.x,n.y,s,0,Math.PI*2)])t.save(),t.beginPath(),t.rect(-1e6,-1e6,2*1e6,2*1e6),o(),t.clip("evenodd"),i(),t.restore()}function GS(t,e,n){return{x:t.x-Math.cos(e.angle)*n,y:t.y-Math.sin(e.angle)*n}}function Fm(t,e,n,s,i,r,o,a,l){t.beginPath(),t.ellipse(e,n,s,i,r,0,Math.PI*2),t.fillStyle=o,t.fill(),t.lineWidth=l,t.strokeStyle=a,t.stroke()}function Bc(t,e,n){const s=Math.atan2(e.y-t.y,e.x-t.x),i=n*.012;return{x:e.x+Math.cos(s)*i,y:e.y+Math.sin(s)*i,rx:n*.031,ry:n*.025,angle:s}}function Lm(t,e,n,s){const i=e.x-t.x,r=e.y-t.y,o=Math.abs(i)>n*.004?Math.sign(i):s,a=Math.max(Math.abs(i),n*.03),l=Math.max(0,Math.abs(r)-n*.02),c=Math.atan2(Math.sign(r)*l,a);return{x:t.x,ankle:t.y,ground:e.y,dir:o,length:a+n*.035,tip:c}}const Nm="#d6d3d1",Wm="#3f3f46";function Dm(t){const e=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim())?.[1];if(!e)return!1;const n=e.length===3?[...e].map(o=>o+o).join(""):e,[s,i,r]=[0,2,4].map(o=>parseInt(n.slice(o,o+2),16));return .299*s+.587*i+.114*r<110}function US(t,e,n,s,i,r,o){const a=e.length,l=e.width,c=a*.58,u=-a*.62-s*.62,d=l,f=l*.9,m=l*1.45;t.save(),t.translate(e.cx,e.cy),t.rotate(e.angle),t.lineJoin="round",t.lineCap="round",t.strokeStyle=i,t.lineWidth=r,t.beginPath(),t.moveTo(c+a*.02,0),t.quadraticCurveTo(c+a*.02,-d,c-a*.14,-d),t.quadraticCurveTo(a*.05,-f,-a*.08,-f),t.quadraticCurveTo(-a*.5,-f*1.1,u,-m),t.lineTo(u,m),t.quadraticCurveTo(-a*.5,f*1.1,-a*.08,f),t.quadraticCurveTo(a*.05,f,c-a*.14,d),t.quadraticCurveTo(c+a*.02,d,c+a*.02,0),t.closePath(),t.fillStyle=n,t.fill(),t.stroke(),t.clip(),t.lineWidth=r*.8,t.beginPath(),t.moveTo(c,-l*.5),t.lineTo(-a*.02,l*.05),t.moveTo(c,l*.5),t.lineTo(-a*.02,-l*.05),t.moveTo(c-a*.2,-l*.62),t.lineTo(c-a*.12,-l*.38),t.moveTo(c-a*.2,l*.62),t.lineTo(c-a*.12,l*.38),t.stroke(),t.beginPath(),t.moveTo(-a*.02,l*.05),t.lineTo(u,l*.12),t.stroke(),t.fillStyle="rgba(0,0,0,0.28)",t.fillRect(-a*.16,-f*1.2,a*.11,f*2.4),t.beginPath(),t.rect(-a*.17,-l*.18,a*.13,l*.36),t.fillStyle="#c9a227",t.fill(),t.stroke(),t.fillStyle=i;for(const[g,p]of[[a*.22,-l*.3],[a*.22,l*.4],[-a*.32,-l*.3],[-a*.32,l*.45]])t.beginPath(),t.arc(g,p,o*.006,0,Math.PI*2),t.fill();t.restore()}function Bm(t,e,n,s,i,r=0){const o=e.rx,a=Math.max(-90,Math.min(90,r))/60*o*.25;t.save(),t.translate(e.center.x,e.center.y),t.rotate(e.angle),t.lineJoin="round",t.lineWidth=i,t.strokeStyle=s,t.beginPath(),t.ellipse(a*.5,-o*.62,o*1.38,o*.22,0,0,Math.PI*2),t.fillStyle=n,t.fill(),t.stroke(),t.beginPath(),t.moveTo(a-o*.78,-o*.64),t.bezierCurveTo(a-o*.82,-o*1.05,a-o*.6,-o*1.32,a-o*.22,-o*1.24),t.quadraticCurveTo(a,-o*1.12,a+o*.22,-o*1.24),t.bezierCurveTo(a+o*.6,-o*1.32,a+o*.82,-o*1.05,a+o*.78,-o*.64),t.quadraticCurveTo(a,-o*.54,a-o*.78,-o*.64),t.closePath(),t.fillStyle=n,t.fill(),t.stroke(),t.clip(),t.fillStyle=s,t.fillRect(a-o,-o*.84,2*o,o*.17),t.restore()}function VS(t,e,n,s,i,r){const o=e.length*1.3,a=n*.034,l=n*.066,c=n*.012;t.save(),t.translate(e.x,e.ankle),t.scale(e.dir,1),e.tip&&t.rotate(e.tip),t.translate(0,e.ground-e.ankle),t.lineJoin="round",t.lineWidth=r,t.strokeStyle=i,t.beginPath(),t.moveTo(-a,-c),t.lineTo(o*.82,-c),t.quadraticCurveTo(o+n*.012,-c,o+n*.01,-l*.42),t.quadraticCurveTo(o*.98,-l*.85,o*.62,-l*.82),t.quadraticCurveTo(o*.3,-l*.8,n*.012,-l),t.lineTo(-n*.012,-l),t.quadraticCurveTo(-a*1.15,-l*.85,-a,-c),t.closePath(),t.fillStyle=s,t.fill(),t.stroke(),Dm(s)&&(t.save(),t.clip(),t.strokeStyle="rgba(255,255,255,0.35)",t.lineWidth=n*.006,t.lineCap="round",t.beginPath(),t.moveTo(o*.45,-l*.68),t.quadraticCurveTo(o*.85,-l*.72,o*.95,-l*.45),t.stroke(),t.restore()),t.beginPath(),t.moveTo(-a,-c),t.lineTo(o*.82,-c),t.quadraticCurveTo(o+n*.012,-c,o+n*.011,-c*1.8),t.lineTo(o+n*.012,0),t.lineTo(-a,0),t.closePath(),t.fillStyle=Dm(s)?Wm:Nm,t.fill(),t.stroke(),t.restore()}function zc(t,e,n){const s=t.points[`hip.${e}`],i=t.points[`knee.${e}`],r=t.points[`ankle.${e}`],o=Math.hypot(i.x-s.x,i.y-s.y),a=Math.hypot(r.x-i.x,r.y-i.y),l=As(n,0,1)*(o+a);return l<=o?we(s,i,o>0?l/o:0):we(i,r,a>0?Math.min(1,(l-o)/a):1)}function zm(t){const e=t.points,n=Math.hypot(e["knee.left"].x-e["hip.left"].x,e["knee.left"].y-e["hip.left"].y);return(e["knee.left"].y+e["knee.right"].y)/2-e.hip.y>.6*n}function JS(t,e,n,s,i,r){const o=e.height,a=s*3.1,l=zm(e),c=e.points,h=Math.hypot(c["knee.left"].x-c["hip.left"].x,c["knee.left"].y-c["hip.left"].y)+Math.hypot(c["ankle.left"].x-c["knee.left"].x,c["ankle.left"].y-c["knee.left"].y),u=Math.min(.93,n.length,l?1:1-(a/2+i)/Math.max(h,1)),d=[0,.25,.5,.75,1].map(v=>v*u),f=d.map(v=>zc(e,"left",v)),m=d.map(v=>zc(e,"right",v));if(t.save(),t.lineCap="round",t.lineJoin="round",l){const v=o*.035*u,w=d.map((S,x)=>{const M=x/(d.length-1);return{a:Math.min(f[x].x,m[x].x)-a/2-v*M,b:Math.max(f[x].x,m[x].x)+a/2+v*M,y:(f[x].y+m[x].y)/2}}),k=w[w.length-1];t.beginPath(),t.moveTo(w[0].a+a*.2,w[0].y-o*.02);for(const S of w.slice(1))t.lineTo(S.a,S.y);t.quadraticCurveTo((k.a+k.b)/2,k.y+o*.012,k.b,k.y);for(const S of[...w].reverse().slice(1))t.lineTo(S.b,S.y);t.lineTo(w[0].b-a*.2,w[0].y-o*.02),t.closePath(),t.fillStyle=n.color,t.fill(),t.lineWidth=i,t.strokeStyle=r,t.stroke(),t.strokeStyle="rgba(0,0,0,0.2)",t.lineWidth=i*.6;for(const S of[.38,.62])t.beginPath(),t.moveTo(w[1].a+(w[1].b-w[1].a)*S,w[1].y),t.lineTo(k.a+(k.b-k.a)*(S*1.2-.1),k.y),t.stroke();t.restore();return}for(const v of[f,m])Vt(t,v,a+2*i,r),Vt(t,v,a,n.color);t.beginPath(),t.moveTo(f[0].x,f[0].y);for(const v of f.slice(1))t.lineTo(v.x,v.y);for(const v of[...m].reverse())t.lineTo(v.x,v.y);t.closePath(),t.fillStyle=n.color,t.fill();const g=f[f.length-1],p=m[m.length-1],y=Math.sign(p.x-g.x)||1;t.beginPath(),t.moveTo(g.x-y*a/2,g.y+a*.1),t.lineTo(p.x+y*a/2,p.y+a*.1),t.lineWidth=i,t.strokeStyle=r,t.stroke(),t.restore()}function ZS(t,e,n,s,i){const r=e.length,o=r*.58,a=-r*.62,l=e.width*.82,c=e.width,h=[{x:o+r*.1,y:-l*1.2},{x:o+r*.1,y:-l*.2},{x:a+r*.45,y:c*1.3},{x:a,y:c*1.3}].map(u=>xs(e,u));t.save(),t.beginPath(),Eo(t,e),t.clip(),t.beginPath(),h.forEach((u,d)=>d?t.lineTo(u.x,u.y):t.moveTo(u.x,u.y)),t.closePath(),t.fillStyle=n,t.fill(),t.lineWidth=i,t.lineJoin="round",t.strokeStyle=s,t.stroke(),t.restore(),t.beginPath(),Eo(t,e),t.lineWidth=i,t.strokeStyle=s,t.stroke()}const qm=[.7,.78,.86];function QS(t,e,n,s,i,r,o){const a=Math.atan2(n.y-e.y,n.x-e.x);for(const l of qm){const c=we(e,n,l);Fm(t,c.x,c.y,s*.006,s*.019,a,i,r,o*.55)}}function t3(t,e,n,s,i){const r=n.height,o=n.points,a=i.ink,l=e.outlineWidth*r,c=e.limbWidth*r,h=e.lineWidth*r,u=e.limbs==="line",d=Om(e,n);if(t.save(),s==="spine"){if(t.beginPath(),Eo(t,d),t.fillStyle=e.shirt??e.fill,t.fill(),t.lineWidth=l,t.strokeStyle=a,t.stroke(),e.drape&&ZS(t,d,e.drape,a,l),e.coat){const f=m=>Math.hypot(o[`knee.${m}`].x-o[`hip.${m}`].x,o[`knee.${m}`].y-o[`hip.${m}`].y);US(t,d,e.coat,(f("left")+f("right"))/2,a,l,r)}}else if(s==="neck"){const f=we(o["shoulder.left"],o["shoulder.right"]),m=[f,n.head.center];if(u)Dc(t,m,h,a,e.halo);else{const g=()=>Vt(t,m,c*.9+2*l,a);zi(n,s)?Ao(t,d,f,d.length*.25,g):g(),Vt(t,m,c*.9,e.fill)}}else if(s.startsWith("arm.")){const f=s.slice(4),m=o[`elbow.${f}`],g=GS(o[`shoulder.${f}`],d,(u?h:c)/2+l),p=o[`hand.${f}`],y=qi(g,m,p),v=!u&&zi(n,s),w=e.coat?qi(g,m,we(m,p,.8)):null,k=c*1.7,S=e.shirt,x=!!S&&e.sleeves==="long",M=S&&e.sleeves==="short"?qi(g,we(g,m,.25),we(g,m,.5),4):null,E=c*1.55,T=(w?k:M?E:c)/2+l*2,A=()=>{u||Vt(t,y,c+2*l,a),M&&Vt(t,M,E+2*l,a)};if(u&&!x&&Dc(t,y,h,a,e.halo),u&&x&&Vt(t,y,c+2*l,a),v?Ao(t,d,g,T,A):A(),(!u||x)&&Vt(t,y,c,x?S:e.fill),M&&Vt(t,M,E,S),w){const P=()=>Vt(t,w,k+2*l,a);zi(n,s)?Ao(t,d,g,T,P):P(),Vt(t,w,k,e.coat)}if(e.bangles&&QS(t,m,p,r,e.bangles,a,l),i.hands==="mitten"){const P=Bc(m,p,r);Fm(t,P.x,P.y,P.rx,P.ry,P.angle,e.fill,a,l)}else i.hands==="dot"&&u&&(t.beginPath(),t.arc(p.x,p.y,h*.9,0,Math.PI*2),t.fillStyle=a,t.fill())}else if(s.startsWith("leg.")){const f=s.slice(4),m=o[`hip.${f}`],g=o[`ankle.${f}`],p=e.trousers?c*1.35:u?h:c,y=o[`knee.${f}`],v=Math.hypot(y.x-g.x,y.y-g.y)||1,w=Math.min(v*.4,p/2+l+r*.012),k={x:g.x+(y.x-g.x)/v*w,y:g.y+(y.y-g.y)/v*w},S=qi(m,y,k),x=zi(n,s);if(u&&!e.trousers)Dc(t,S,h,a,e.halo);else{const A=()=>Vt(t,S,p+2*l,a);x?Ao(t,d,m,p/2+l*2,A):A(),Vt(t,S,p,e.trousers??e.fill)}const E=(n.turn%4+4)%4>2?-1:1;VS(t,Lm(o[`ankle.${f}`],o[`toe.${f}`],r,E),r,e.shoes,a,l);const T=`leg.${f==="left"?"right":"left"}`;e.skirt&&(n.parts[s]?.order??0)>=(n.parts[T]?.order??0)&&JS(t,n,e.skirt,c,l,a)}t.restore()}function qc(t,e){const n=(i,r)=>i&&r?(o,a,l,c,h)=>{i(o,a,l,c,h),r(o,a,l,c,h)}:i??r,s={};for(const i of new Set([...Object.keys(t.parts??{}),...Object.keys(e.parts??{})])){const r=t.parts?.[i],o=e.parts?.[i];s[i]={under:n(r?.under,o?.under),clip:n(r?.clip,o?.clip),over:n(r?.over,o?.over)}}return{behind:n(t.behind,e.behind),parts:s,front:n(t.front,e.front)}}function Ps(t={}){if(t.build&&!(t.build in so))throw new Error(`character: unknown build '${t.build}'`);const e=t.build?so[t.build]:{},n=(t.proportions??"bold")==="bold",s=t.figure??"fluid";if(!["fluid","stick","organic","bean"].includes(s))throw new Error(`character: unknown figure '${s}'`);const i=t.height??300,r=s==="stick",o=s==="organic",a=s==="bean",l=a?"clean":t.look??"clean",c=a?Im({...t.outfit?{shirt:t.outfit.shirt,trousers:t.outfit.trousers,...t.outfit.sleeves?{sleeves:t.outfit.sleeves}:{}}:{},...t.lineWidth!==void 0?{outlineWidth:t.lineWidth/i}:{},...t.bean}):void 0,h=t.shoulderWidth??e.shoulderWidth??(o?.07:a?.04:.06),u=o&&t.body?.measurements!==void 0?wg(t.body.measurements):void 0,d=t.hipWidth??u??e.hipWidth??(o?.045:a?.02:.022),f=c?c.outlineWidth*i:t.lineWidth??i*(o?.005:n?.045:.022),m=t.ink??(o?"#53362d":a?"#111111":l==="pencil"?"#2f2f33":"#1e293b"),g=t.skin??(o?"#f1bf98":l==="pencil"?"none":"#ffffff"),p=o?kg(t.body??{},{skin:g,ink:m,lineWidth:f,shoulderWidth:h,hipWidth:d}):void 0;if(t.leafOutfit&&!o)throw new Error("character: leafOutfit requires figure: 'organic'");const y=t.outfit&&!a?Am(t.outfit):null,v=t.holding?xm(t.holding):{};let w=y?qc(y,t.layers??{}):t.layers??{};return t.leafOutfit&&(w=qc(Mm(t.leafOutfit),w)),Object.keys(v).length>0&&(w=qc(w,$m(v))),{plan:t.plan??rc({headSize:t.headSize??e.headSize??(o?.27:n?.3:.24),shoulderWidth:r?0:h,hipWidth:r?0:d,legLength:t.legLength??e.legLength??1,armLength:t.armLength??e.armLength??1,feet:t.feet??e.feet}),figure:s,...p?{body:p}:{},...c?{bean:c}:{},look:l,illustrated:lf(t.illustrated,p?.shading.light),height:i,lineWidth:p?.outline.width??f,ink:p?.outline.color??m,skin:p?.fill??g,seed:t.seed??1,pencil:o?{construction:!1,...t.pencil}:t.pencil??{},layers:w,holding:v,contact:t.contact??"ground",hands:t.hands??(o?"cartoon":a?"mitten":"dot"),handStyle:t.handStyle??(o?"natural":"glove"),handSize:t.handSize??(o?.073:t.handStyle==="natural"?.14:.17),head:lm(t),face:{...o?{style:"anime",projection:"volume",iris:"#66422e",nose:!0}:{},...a?{style:"oval",projection:"volume",...t.bean?.shades?{shades:!0}:{}}:{},...t.face,teeth:t.face?.teeth??a,tongue:t.face?.tongue??a}}}function e3(t,e,n,s){const{point:i,facing:r}=hn(t,[e,n,s]);return{point:i,facing:r}}const jc=t=>t.rest[1]<-.5,n3=.3;function s3(t,e,n){return t.figure==="stick"?jc(e)?n.slice(0,3):n:jc(e)&&n.length>=3?Rn(n[0],n[1],n[2],n3):n.length===3?Rn(n[0],n[1],n[2],1):n}function ji(t,e){const n=t.plan.id==="human"?{...lt,...e}:e;return xo(t,n,lc(t.plan,n,{height:t.height,contact:t.contact}))}function xo(t,e,n){const s={},i={},r={},o=.01*t.height;t.plan.chains.forEach(f=>{const m=n.chains[f.id];s[f.id]=m.points;const g=m.depths.reduce((w,k)=>w+k,0)/m.depths.length,p=f.parent?n.chains[f.parent]:void 0,y=p?p.depths[f.at??p.depths.length-1]:n.hipDepth,v=g-y;r[f.id]=Math.abs(v)<o?0:v,i[f.id]={points:s3(t,f,m.points),depth:g,order:0}}),i.head={points:[n.head.center],depth:n.head.depth,order:0},r.head=0;const a=[...t.plan.chains.map(f=>f.id),"head"],l=f=>t.body&&f.startsWith("arm.")&&r[f]>=0?1:0;let c=[...a].sort((f,m)=>l(f)-l(m)||r[f]-r[m]||a.indexOf(f)-a.indexOf(m));const h={hip:n.hip};for(const[f,[m,g]]of Object.entries(t.plan.landmarks??{})){const p=n.chains[m]?.points;p&&(h[f]=p[Math.min(g,p.length-1)])}const u={};for(const[f,m]of Object.entries(h))u[f]=m.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};if(t.body&&(d.bodyContours=Mg(t.body,d,t.plan)),t.bean&&t.plan.id==="human"){const f={};for(const m of["arm.left","arm.right","leg.left","leg.right"]){const g=n.chains[m]?.depths??[0];f[m]=Math.max(...g.slice(1,3))-g[0]}c=_m(t.bean,d,f)}return c.forEach((f,m)=>{i[f].order=m}),{skeleton:n,joints:d,order:c}}function ke(t,e){return ji(t,e).joints}function jm(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})),r=Array.from({length:13},(l,c)=>({x:-.95+1.9*c/12,y:.12})),o=kt(s,i,{x:0,y:0});o.facing>0&&t.guide(o.points),t.guide(kt(s,r,{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 Km(t,e,n,s,i,r){const o=n.lineWidth;if(n.body&&n.skin==="none"&&(e=vi(t,e)),i==="head"){const{head:f}=s;let m;const g=()=>m??=xg(f,n.face),p=n.skin==="none"?null:n.skin;n.face.projection==="volume"||n.face.shape==="angular"?e.shape(g(),p,o):e.ellipse(f.center.x,f.center.y,f.rx,f.ry,f.angle,p,o),n.body&&n.skin!=="none"&&e.look==="clean"&&pf(t,g(),f.center,n.body.shading),LS(t,e,n.head,f,r,{lineWidth:o,skin:n.skin,face:n.face,faceUnderHair:!!n.body},()=>{e.look!=="silhouette"&&(t.save(),n.body&&(t.beginPath(),g().forEach((y,v)=>v?t.lineTo(y.x,y.y):t.moveTo(y.x,y.y)),t.closePath(),t.clip()),JM(e,f,r,o,{...n.face,skin:n.skin==="none"?"#ffffff":n.skin},t),t.restore())}),n.bean?.fedora&&Bm(t,f,n.bean.fedora,n.ink,o,r["head.turn"]??0);return}const a=n.plan.chains.find(f=>f.id===i),l=s.chains[i],c=s.parts[i].points;if(n.bean&&n.plan.id==="human"){t3(t,n.bean,s,i,{ink:n.ink,hands:n.hands}),n.hands==="cartoon"&&i.startsWith("arm.")&&Kc(t,e,n,l,i.endsWith(".left")?"left":"right",r);return}if(n.body&&Eg(t,e,n.body,s,i)){if(i.startsWith("leg.")&&Eg(t,e,n.body,s,i.replace("leg.","foot.")),i.startsWith("arm."))if(n.hands==="cartoon")Kc(t,e,n,l,i.endsWith(".left")?"left":"right",r);else if(n.hands==="mitten")Xm(e,n,l);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,o)}return}if(n.figure==="stick"){if(i==="neck")return;const f=i==="spine"?[...l,...s.chains.neck?.slice(1)??[]]:c;e.line(f,o);return}const h=(f,m)=>[a.bones[f].width[0]*o,a.bones[m].width[1]*o];if(jc(a)){const[f,m]=h(0,1);if(e.limb(c,f,m),a.bones.length>=3)e.limb([l[2],l[3]],a.bones[2].width[0]*o,a.bones[2].width[1]*o);else if(n.hands==="cartoon"&&i.startsWith("arm."))Kc(t,e,n,l,i.endsWith(".left")?"left":"right",r);else if(n.hands==="mitten"&&i.startsWith("arm."))Xm(e,n,l);else{const g=l[l.length-1];e.dot(g.x,g.y,o*.62)}return}if(i==="spine"){const f=s.points["hip.left"],m=s.points["hip.right"];f&&m&&Math.hypot(f.x-m.x,f.y-m.y)>.5&&e.limb([f,m],o*1.3,o*1.3);const[g,p]=h(0,a.bones.length-1);e.limb(c,g,p);const y=s.points["shoulder.left"],v=s.points["shoulder.right"];y&&v&&Math.hypot(y.x-v.x,y.y-v.y)>.5&&e.limb(Rn(y,l[l.length-1],v,1,10),o*1.15,o*1.15);return}const[u,d]=h(0,a.bones.length-1);e.limb(c,u,d)}function Ym(t,e){const n=`hand.${e}.`,s={};for(const[o,a]of Object.entries(t))o.startsWith(n)&&(s[o.slice(n.length)]=a);const i=t.turn??0,r=e==="right"?1-i:1+i;return{...Ct,...s,turn:r+(s.turn??0)}}function Xm(t,e,n){const s=Bc(n[n.length-2],n[n.length-1],e.height);t.ellipse(s.x,s.y,s.rx,s.ry,s.angle,e.skin==="none"?"#ffffff":e.skin,e.lineWidth*(e.body?1:.45))}function Kc(t,e,n,s,i,r){const o=s[s.length-1],a=s[s.length-2],l=Math.atan2(o.x-a.x,-(o.y-a.y))*180/Math.PI;Yr(t,o,Ym(r,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 Gm(t,e,n,s=0){const i=e.plan.id==="human"?{...lt,...n}:n;Yc(t,e,i,ji(e,i),s)}function Po(t,e){const n=e/t.height;return{...t,height:e,lineWidth:t.lineWidth*n}}function i3(t,e,n,s){const i=t.plan.id==="human"?{...lt,...e}:e,r=lo(t.plan,i,{height:s.height,contact:t.contact},n);return xo(Po(t,r.height),i,r).joints}function r3(t,e,n,s,i){const r=e.plan.id==="human"?{...lt,...n}:n,o=lo(e.plan,r,{height:i.height,contact:e.contact},s),a=Po(e,o.height);Yc(t,a,r,xo(a,r,o),i.time??0)}function Um(t,e,n,s){const i=t.plan.id==="human"?{...lt,...e}:e,r=lo(t.plan,i,{height:s.height,contact:t.contact},n),o=Po(t,r.height),{joints:a,order:l}=xo(o,i,r),c=r.height/s.height,h=l.map(m=>(a.parts[m]?.depth??0)/c),u=l.filter(m=>m==="spine"||m.startsWith("leg.")),d=Math.max(...u.map(m=>a.parts[m].depth/c)),f=Math.max(...u.map(m=>a.parts[m].order));return l.map((m,g)=>({part:m,depth:h[g],...o.body?{sortDepth:m.startsWith("arm.")&&g>f?Math.max(h[g],d):h[g]}:{},draw(p,y=0){const v=ki(p,{look:o.look,ink:o.ink,lineWidth:o.lineWidth,seed:re(`${o.seed}:${m}`),time:y,pencil:o.pencil,illustrated:o.illustrated}),w=S=>{S&&(p.save(),S(p,a,v,y,i),p.restore())};p.save(),p.lineCap="round",p.lineJoin="round",g===0&&(o.look==="pencil"&&o.pencil.construction!==!1&&jm(v,o,a),w(o.layers.behind),dm(p,o.body&&o.skin==="none"?vi(p,v):v,o.head,a.head,i,{lineWidth:o.lineWidth,skin:o.skin,face:o.face}));const k=o.layers.parts?.[m];w(k?.under),p.save(),k?.clip?.(p,a,v,y,i),Km(p,v,o,a,m,i),p.restore(),w(k?.over),m==="head"&&fm(p,v,o.head,a.head,i,{lineWidth:o.lineWidth,skin:o.skin,face:o.face}),g===l.length-1&&w(o.layers.front),p.restore()}}))}function Yc(t,e,n,s,i,r){const{joints:o}=s,a=r?s.order.filter(h=>r.has(h)):s.order,l=ki(t,{look:e.look,ink:e.ink,lineWidth:e.lineWidth,seed:e.seed,time:i,pencil:e.pencil,illustrated:e.illustrated}),c=h=>{h&&(t.save(),h(t,o,l,i,n),t.restore())};t.save(),t.lineCap="round",t.lineJoin="round",!r&&e.look==="pencil"&&e.pencil.construction!==!1&&jm(l,e,o),r||c(e.layers.behind),dm(t,e.body&&e.skin==="none"?vi(t,l):l,e.head,o.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,o,l,i,n),Km(t,l,e,o,h,n),t.restore(),c(u?.over)}fm(t,l,e.head,o.head,n,{lineWidth:e.lineWidth,skin:e.skin}),r||c(e.layers.front),t.restore()}function o3(t,e,n,s){const i=e.plan.id==="human"?{...lt,...n}:n,r=ji(e,i).joints.head.rx,o=Po(e,e.height*s.radius/Math.max(1e-6,r)),a=ji(o,i);t.save(),t.translate(s.x-a.joints.head.center.x,s.y-a.joints.head.center.y),Yc(t,o,i,a,s.time??0,new Set(["head"])),t.restore()}function Xc(t,e,n){const s={...t};for(const[i,r]of Object.entries(e)){const o=t[i]??r;s[i]=o+(r-o)*n}return s}function qe(t,e,n,s){const i=t.plan.id==="human"?{...lt,...e}:e;let r;if(Array.isArray(s))r=s;else{const{skeleton:o}=ji(t,i),a=lc(t.plan,{...i,roll:0},{height:t.height,contact:"none"}),l=(i.roll??0)*Math.PI/180,c=s.x-o.hip.x,h=s.y-o.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),m=s.depth??o.chains[n].depths[o.chains[n].depths.length-1],g=Math.cos(f),p=Math.sin(f);r=[u*g-m*p,-d,u*p+m*g]}return Oi(t.plan,i,n,r,{height:t.height})}const Vm=new Set(["walk","walking","gait"]);function $o(t,e=lt,n){let s={...e};for(const[r,o]of Object.entries(t))typeof o=="number"&&!Vm.has(r)&&(s[r]=o);const i=Math.max(0,Math.min(1,typeof t.walking=="number"?t.walking:0));if(i>0){const r=typeof t.gait=="string"?t.gait:void 0,o=r?n?.[r]??r:void 0,a=vo(o,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 a3(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(r,o,a){r.translate(n/2,s),Gm(r,e,$o(o.props??{},i,t.gaits),a)}}}function Jm(t,e,n){const s=r=>({x:r.x+e,y:r.y+n}),i=r=>Object.fromEntries(Object.entries(r).map(([o,a])=>[o,a.map(s)]));return{...t,...t.bodyContours?{bodyContours:Object.fromEntries(Object.entries(t.bodyContours).map(([r,o])=>[r,{...o,outline:o.outline.map(s),samples:o.samples.map(a=>({...a,center:s(a.center),left:s(a.left),right:s(a.right)}))}]))}:{},points:Object.fromEntries(Object.entries(t.points).map(([r,o])=>[r,s(o)])),chains:i(t.chains),parts:Object.fromEntries(Object.entries(t.parts).map(([r,o])=>[r,{...o,points:o.points.map(s)}])),head:{...t.head,center:s(t.head.center)},groundY:t.groundY+n}}function l3(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 r=0,o=0;for(const[c,h]of e.state?.values.get(n)??[])c==="x"||c==="motionPathX"?r=typeof h=="number"?h:r:c==="y"||c==="motionPathY"?o=typeof h=="number"?h:o:(typeof h=="number"||Vm.has(c))&&(i[c]=h);const a=$o(i,s.plan.id==="human"?lt:{},t.gaits),l=ke(s,a);return{pose:a,joints:Jm(l,t.x+r+t.width/2,t.y+o+t.height)}}function Gc(t,e=lt){const n=[];return t.forEach((s,i)=>{const r=i===0?e:n[i-1],o=typeof s.pose=="string"?Ae[s.pose]:void 0;n.push(o?{...o,turn:r.turn??0}:{...r,...s.pose})}),n}function c3(t,e,n=lt){const s=Gc(e,n);return Object.keys(n).filter(r=>s.some(o=>(o[r]??n[r])!==n[r])).map(r=>({id:`${t}-${r}`,target:t,property:r,keyframes:e.map((o,a)=>({time:o.time,value:s[a][r]??n[r],...o.easing?{easing:o.easing}:{}}))}))}const Io=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Le=(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],Uc=t=>Math.hypot(...t),Zm=t=>Oo(t,1/(Uc(t)||1)),Co=t=>({...lt,...t}),Vc=t=>cn(t.character.plan,Co(t.pose),{height:t.character.height,contact:t.character.contact});function zn(t,e,n){return Io(t.position,Vc(t).chains[e][n])}function Qm(t,e,n){const s=Co(t.pose),i=Vc(t).hip,r=ms(t.character.plan,s,t.character.height),o=Le(Le(n,t.position),i),a=$i(o,(s.roll??0)*Math.PI/180),l=Io(r.root,ee(a,-(s.turn??0)*Math.PI/2));return Oi(t.character.plan,s,e,l,{height:t.character.height})}function tp(t,e,n,s="toe"){const i=`leg.${e}`,r=s==="toe"?3:2;let o={...t,pose:Co(t.pose),position:[...t.position]};for(let l=0;l<6;l++){const c=Vc(o).chains[i],h=Le(c[r],c[2]);o={...o,pose:Qm(o,i,Le(n,h))};const u=zn(o,i,r);o.position[1]+=n[1]-u[1]}const a=Uc(Le(zn(o,i,r),n));return{...o,reached:a<t.character.height*.002}}function ep(t,e){const n=zn(t,`arm.${e}`,2),s=zn(t,`arm.${e}`,1);return Io(n,Oo(Zm(Le(n,s)),t.character.lineWidth*.5))}function h3(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 r=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],o=(c,h)=>{const u=Zm([r[0]-c.position[0],s*.2,r[2]-c.position[2]]),d=Le(r,Oo(u,i));let f=Co(c.pose);for(let g=0;g<6;g++){const p={...c,pose:f},y=zn(p,`arm.${h}`,2);f=Qm(p,`arm.${h}`,Le(d,Le(ep(p,h),y)))}for(const[g,p]of Object.entries(Tt.hold))f[`hand.${h}.${g}`]=p;const m=ep({...c,pose:f},h);return{pose:f,stick:{grip:m,tip:Io(m,Oo(u,i))}}},a=o(t,n.sideA??"right"),l=o(e,n.sideB??"right");return{a:a.pose,b:l.pose,sticks:[a.stick,l.stick],point:r,reached:[a.stick,l.stick].every(c=>Uc(Le(c.tip,r))<s*.002)}}function np(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],r=e.direction??1;if(i.length!==2||!i.every(Number.isFinite)||!Number.isFinite(e.angle??0)||!Number.isFinite(e.spins??0)||![1,-1].includes(r)||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 o=e.character??Ps({height:1.7}),a=e.style??"garba",l=(h,u)=>{const d=(e.angle??0)+360*u/n+r*360*h/s,f=d*Math.PI/180,m=e.facing??"inward",g=(typeof m=="number"?m:d+(m==="inward"?180:m==="tangent"?r*90:0))+(e.spins??0)*360*h/s,p=Ci(a,h,{...e.pose,turn:g/90});return{character:o,position:[i[0]+e.radius*Math.sin(f),0,i[1]+e.radius*Math.cos(f)],pose:p.pose,heading:g,strike:p.strike}},c=Ci(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),m=zn(f,`leg.${c.side}`,3),g=tp(d,c.side,m);return{...d,pose:Xc(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 u3(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)),r=Array.from({length:i+1},(l,c)=>({time:(e.start??0)+e.beats*c/i*6e4/n,members:np(e.beats*c/i,{...e,count:t.length})})),o=r.some(l=>l.members.some(c=>c.pose.roll!==0)),a=new Set(["x","y","z","rotateY",...o?["turn","roll"]:[]]);return t.flatMap((l,c)=>{const h=r.map(u=>{const d=u.members[c],{turn:f,...m}=d.pose;return{time:u.time,pose:{...o?d.pose:m,x:d.position[0],y:d.position[1],z:d.position[2],rotateY:o?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 _o=t=>Math.min(1,Math.max(0,t));function d3(t){const e={...ut,turn:t.view},n=[];for(const s of t.keys){const i=n[n.length-1],r=!i||s.reset?e:i.pose;n.push({at:s.at,pose:{...r,...s.pose},easing:s.easing})}return n}function f3(t){return t-g3*Math.sin(2*Math.PI*t)/(2*Math.PI)}const g3=.5;function m3(t,e){if(!(e<=t.takeoff||e>=t.landing))return(e-t.takeoff)/(t.landing-t.takeoff)}function sp(t,e){const n=typeof t=="string"?Ki[t]:t,s=d3(n),i=_o(e);let r=0;for(let u=0;u<s.length;u++)s[u].at<=i&&(r=u);const o=s[r],a=s[Math.min(r+1,s.length-1)],l=a.at>o.at?(i-o.at)/(a.at-o.at):0,c=gs(o.pose,a.pose,Dt(a.easing??"ease-in-out")(_o(l))),h=m3(n,i);return h===void 0?{...c,spin:0,rise:0}:{...c,spin:n.spin*f3(h),rise:4*n.height*h*(1-h)}}function ip(t,e,n){const s=typeof t=="string"?Ki[t]:t,i=_o(e),r=_o((i-s.takeoff)/(s.landing-s.takeoff));return s.travel*n*r}function p3(t,e,n={}){const s=typeof e=="string"?Ki[e]:e,i=n.start??0,r=n.duration??s.duration,o=n.samples??48,a=Array.from({length:o+1},(h,u)=>{const d=u/o;return{time:i+d*r,progress:d,pose:sp(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*ip(s,u.progress,n.height)}))})}return c}const y3={leftHip:-55,leftKnee:-95,rightHip:55,rightKnee:95,leftShoulder:45,rightShoulder:-45,leftElbow:10,rightElbow:-10,lean:22,stretch:.94,headTilt:6},b3={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},Ro={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},w3={leftHip:-22,leftKnee:-30,rightHip:22,rightKnee:30,leftAnkle:10,rightAnkle:10,leftShoulder:-125,rightShoulder:125,leftElbow:0,rightElbow:0,lean:8,headTilt:0},k3={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 $s(t,e,n,s,i,r=1300){return{label:t,view:1,spin:e,height:n,travel:s,takeoff:.27,landing:.8,duration:r,keys:[{at:0,reset:!0},{at:.16,pose:y3},{at:.27,pose:b3,easing:"ease-out-quad"},...i,{at:.76,pose:w3},{at:.86,pose:k3,easing:"ease-out-quad"},{at:1,reset:!0}]}}const Ki={frontFlip:$s("Front flip (tuck)",360,.56,.35,[{at:.38,pose:Ro,easing:"ease-out-cubic"},{at:.64,pose:Ro}]),backFlip:$s("Back flip (tuck)",-360,.58,-.15,[{at:.36,pose:{...Ro,lean:18},easing:"ease-out-cubic"},{at:.64,pose:{...Ro,lean:18}}]),layout:$s("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:$s("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:$s("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:$s("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 rp(t,e){const n=Math.min(1,Math.max(0,t.turn??0)),s=1-n,i={...lt,turn:n},r=[{stick:"right",human:"left",s:1},{stick:"left",human:"right",s:-1}];for(const{stick:a,human:l,s:c}of r){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`],m=s+c*n;i[`leg.${l}.rotate`]=90*s,i[`leg.${l}.spread`]=0,i[`leg.${l}.swing`]=d*m,i[`leg.${l}.knee`]=f*m,i[`leg.${l}.ankle`]=-(t[`${a}Ankle`]??0),i[`leg.${l}.toeOut`]=(t[`${a}FootOut`]??0)*v3,i[`eye.${l}`]=t[`${a}Eye`],i[`brow.${l}`]=t[`${a}Brow`],e&&Object.assign(i,M3(l,e[a]??Ct,t[`${a}Wrist`]??0,n))}const o=t.bend??0;i.lean=t.lean*n,i.bend=o*n,i.side=(t.lean+o*.5)*s,i["head.tilt"]=(t.headTilt+o*.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 v3=70;function M3(t,e,n,s){const i=t==="right"?1-s:1+s,r={};for(const o of Object.keys(Ct))r[`hand.${t}.${o}`]=e[o]??Ct[o];return r[`hand.${t}.turn`]=(e.turn??0)-i,r[`hand.${t}.roll`]=(e.roll??0)+n,r}class op{positions=[];normals=[];indices=[];vertex(e,n,s,i,r,o){const a=Math.hypot(i,r,o)||1;return this.positions.push(e,n,s),this.normals.push(i/a,r/a,o/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 S3(t){const e=new Map,n=[];for(let i=0;i<t.positions.length/3;i++){const r=[0,1,2].map(o=>Math.round(t.positions[i*3+o]*1e6)).join(",");e.has(r)||e.set(r,i),n.push(e.get(r))}const s=new Map;for(let i=0;i<t.indices.length/3;i++)for(let r=0;r<3;r++){const o=n[t.indices[i*3+r]],a=n[t.indices[i*3+(r+1)%3]];if(o===a)continue;const l=o<a?`${o}-${a}`:`${a}-${o}`,c=s.get(l);c?c.faces.push(i):s.set(l,{a:Math.min(o,a),b:Math.max(o,a),faces:[i]})}return[...s.values()]}const Jc=Math.PI*2;function T3(t,e=16){const n=new op,s=Math.max(6,Math.round(e)),i=Math.max(3,Math.round(s/2)),r=[];for(let o=0;o<=i;o++){const a=o/i*Math.PI,l=[];for(let c=0;c<=s;c++){const h=c/s*Jc,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))}r.push(l)}for(let o=0;o<i;o++)for(let a=0;a<s;a++){const l=r[o][a],c=r[o+1][a],h=r[o+1][a+1],u=r[o][a+1];o>0&&n.triangle(l,c,u),o<i-1&&n.triangle(c,h,u)}return n.build()}function ap(t,e,n,s,i){const r=t.vertex(0,n,0,0,s,0),o=Array.from({length:i},(a,l)=>{const c=l/i*Jc;return t.vertex(Math.sin(c)*e,n,Math.cos(c)*e,0,s,0)});for(let a=0;a<i;a++){const l=o[a],c=o[(a+1)%i];s===1?t.triangle(r,l,c):t.triangle(r,c,l)}}function lp(t,e,n=24){const s=new op,i=Math.max(6,Math.round(n)),r=e/2,o=-e/2,a=h=>Array.from({length:i+1},(u,d)=>{const f=d/i*Jc;return s.vertex(Math.sin(f)*t,h,Math.cos(f)*t,Math.sin(f),0,Math.cos(f))}),l=a(o),c=a(r);for(let h=0;h<i;h++)s.quad(l[h],l[h+1],c[h+1],c[h]);return ap(s,t,r,1,i),ap(s,t,o,-1,i),s.build()}function Ho(t){const e=Array.from({length:t.indices.length/3},()=>[]);for(const n of S3(t))for(const s of n.faces){const i=n.faces.find(r=>r!==s)??-1;e[s].push({a:n.a,b:n.b,across:i})}return{...t,faceEdges:e}}function Zc(t,e,n={}){t.save(),E3(t,e,n),t.restore()}function E3(t,e,n){const s=Qc(e,n);n.shadow!==!1&&th(t,e,n);for(const i of e.under)cp(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 r of i.slice(1))t.lineTo(r.x,r.y);t.closePath()}t.clip("nonzero")}n.rider(t),t.restore()}for(const i of e.over)cp(t,i,s,n)}function cp(t,e,n,s){const i=s.loose?.[e.part.id];if(!i){sh(t,e,n,s);return}if(i.opacity<=0)return;const r=e.faces.flatMap(c=>c.points);if(r.length===0)return;const o=r.map(c=>c.x),a=r.map(c=>c.y),l={x:(Math.min(...o)+Math.max(...o))/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),sh(t,e,n,s),t.restore()}function Qc(t,e={}){return e.lineWidth??Math.max(1.3,t.sizePx*.022)}function th(t,e,n={}){e.shadow.opacity<=0||e.shadow.points.length<3||(t.save(),t.globalAlpha=e.shadow.opacity,Fo(t,e.shadow.points,n.ink??"#26262b",!1),t.restore())}function A3(t,e,n,s={}){t.save(),sh(t,e,n,s),t.restore()}function hp(t,e,n,s={}){const i=s.style==="stick",r=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}))}),o=new Map;for(const h of r){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);o.set(f,[...o.get(f)??[],h])}for(const h of o.values())for(const u of h){const{center:d,normal:f}=u.face;for(const m of h){if(m.part.part.id===u.part.part.id)continue;const g=m.face;if(g.normal[0]*f[0]+g.normal[1]*f[1]+g.normal[2]*f[2]<=.8)continue;const y=g.normal[0]*(d[0]-g.center[0])+g.normal[1]*(d[1]-g.center[1])+g.normal[2]*(d[2]-g.center[2]);y>-up/5&&y<up&&(u.layer=Math.max(u.layer,m.layer),u.depth=Math.max(u.depth,m.depth+1e-6))}}r.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=eh(t,h,n,s)),u};t.save();const c=t.globalAlpha;for(const{part:h,face:u}of r){t.globalAlpha=c*h.opacity;const d=l(h);if(!u)d.line(h.spine,n*1.15);else{const f=i?dp(h,s):u.light?x3(h,u,s):nh(h);f&&(!i&&s.look==="silhouette"?d.shape(u.points,f,0):Fo(t,u.points,i||u.light?f:Lo(f,u.tone),!0,h.cut?1.6:.8));const m=(h.part.outline??1)*n;if(m>0)for(const g of u.edges??[])g.length>1&&d.line(g,m);for(const g of u.marks??[])d.line(g,n*.7)}}t.restore()}const up=.05;function eh(t,e,n,s){return ki(t,{look:s.look??"clean",ink:e.part.ink??s.ink??"#26262b",lineWidth:n,seed:re(`${s.seed??0}:${e.part.id}`),time:s.time??0,pencil:{construction:!1,rubbedOut:0,...s.pencil}})}function nh(t){const{part:e}=t;return e.glow&&t.glow>0&&e.fill?oh(e.fill,e.glow.color,t.glow):e.fill}function x3(t,e,n){const{part:s}=t;if(!s.fill)return;const i=rh(s.fill,e.light,e.fog??0,n.fog);return s.glow&&t.glow>0?oh(i,s.glow.color,t.glow):i}function dp(t,e){const n=nh(t);return n&&($3(n)||t.glow>0)?n:e.paper??"#fbf8ef"}function sh(t,e,n,s){e.opacity<1?(t.save(),t.globalAlpha*=e.opacity,fp(t,e,n,s),t.restore()):fp(t,e,n,s)}function fp(t,e,n,s){if(s.style==="stick")return P3(t,e,n,s);const{part:i}=e,r=eh(t,e,n,s),o=nh(e),a=s.look==="silhouette";for(const c of e.faces)o&&(a?r.shape(c.points,o,0):Fo(t,c.points,Lo(o,c.tone)));const l=(i.outline??1)*n;if(l>0)for(const c of e.edges)c.length>1&&r.line(c,l);for(const c of e.marks)r.line(c,n*.7)}function P3(t,e,n,s){const{part:i}=e;if(i.solidOnly)return;const r=eh(t,e,n,s);if(e.spine){r.line(e.spine,n*1.15);return}const o=dp(e,s);for(const l of e.faces)Fo(t,l.points,o);const a=(i.outline??1)*n;if(a>0)for(const l of e.edges)l.length>1&&r.line(l,a);for(const l of e.marks)r.line(l,n*.7)}function $3(t){const e=Is(t);return e?(.299*e[0]+.587*e[1]+.114*e[2])/255<.3:!1}function Fo(t,e,n,s=!0,i=.8){t.fillStyle=n,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let r=1;r<e.length;r++)t.lineTo(e[r].x,e[r].y);t.closePath(),t.fill(),s&&(t.strokeStyle=n,t.lineWidth=i,t.lineJoin="round",t.stroke())}function Is(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 ih=t=>`#${t.map(e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0")).join("")}`;function Lo(t,e){const n=Is(t);return n?ih(e>=1?n.map(s=>s+(255-s)*(e-1)*2):n.map(s=>s*e)):t}function rh(t,e,n,s){const i=Is(t);if(!i)return t;let r=i.map((a,l)=>a*e[l]);const o=s?Is(s):void 0;return o&&n>0&&(r=r.map((a,l)=>a+(o[l]-a)*n)),ih(r)}function oh(t,e,n){const s=Is(t),i=Is(e);return!s||!i?n<.5?t:e:ih(s.map((r,o)=>r+(i[o]-r)*n))}const I3=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),O3=new Set(["walk","walking","gait"]),gp=t=>typeof t=="number"?t:void 0,C3=1.7;function _3(t,e,n){const s=Array.from({length:24},(i,r)=>{const o=r/24*Math.PI*2,a=e.toView([Math.cos(o)*n,0,Math.sin(o)*n*.8]);return a[2]<-.001?e.toScreen(a):null});s.some(i=>i===null)||(t.beginPath(),s.forEach((i,r)=>r===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 R3(t){const e=We([0,1,0],t);if(e>.999999)return Or();if(e<-.999999)return Te(Zt([1,0,0],180));const n=hi([0,1,0],t);return Te(Zt(n,Math.acos(e)*180/Math.PI))}function H3(t,e,n,s,i){const r=t.solid??{},o=r.outline===!1?void 0:r.outline??{width:2,color:"#0f172a"},a={color:r.color??"#475569",shading:r.shading??"toon",outline:o},l={color:r.skin??"#f2c49b",shading:r.shading??"toon",outline:o},c={color:"#0f172a",shading:"unlit"},h=s.height*.034,u=[],d=(w,k,S)=>u.push({mesh:w,world:Ft(i,k),material:S}),f=(w,k,S)=>d(e.sphere,al(w,[0,0,0,1],[k,k,k]),S);for(const w of n.chains){const k=s.chains[w.id],S=w.id==="spine"?1.9:1;w.bones.forEach((x,M)=>{const E=k[M],T=k[M+1],A=ui(E,T),[P,I]=x.width??[1,1],O=h*S*(P+I)/2;if(A>1e-6){const _=$n(E,T,.5),L=R3(Qt(oe(T,E)));d(e.cylinder,Ft(In(_),Ft(L,On([O,A,O]))),a)}f(E,h*S*P,a),f(T,h*S*I,a)}),w.id.startsWith("arm.")&&f(k[k.length-1],h*1.5,l)}const{center:m,rx:g,ry:p,axes:y}=s.head,v=[...y[0],0,...y[1],0,...y[2],0,...m,1];d(e.sphere,Ft(v,On([g,p,g])),l);for(const w of[-1,1]){const k=Qt([w*.36,.15,.92]),S=ci(m,ci(ci(Pn(y[0],k[0]*g*1.04),Pn(y[1],k[1]*p*1.04)),Pn(y[2],k[2]*g*1.04))),x=[...y[0],0,...y[1],0,...y[2],0,...S,1];d(e.sphere,Ft(x,On([g*.11,p*.14,g*.03])),c)}return u}const F3={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:Ps({...t.character,height:1}),cylinder:Ho(lp(1,1,16)),sphere:Ho(T3(1,20))}},resolve({object:t,prepared:e,values:n,world:s,camera:i,lights:r=[],fog:o,toScreen:a}){const l=t,c=e,h=c.who;let u={...lt,...l.pose};for(const[E,T]of n)typeof T=="number"&&!I3.has(E)&&!O3.has(E)&&(u[E]=T);const d=Math.max(0,Math.min(1,gp(n.get("walking"))??l.walking??0));if(d>0){const E=typeof n.get("gait")=="string"?n.get("gait"):l.gait,T=vo(E,gp(n.get("walk"))??0,u);u=Object.fromEntries(Object.keys({...u,...T}).map(A=>[A,(u[A]??0)+((T[A]??0)-(u[A]??0))*d]))}const f=l.height??C3,m=Ft(i.view,s),g={toView:E=>ae(m,E),toScreen:E=>a(E)},y=-g.toView([0,f/2,0])[2];if(y<=i.near)return null;const v=l.shadow===!1?[]:[{depth:y+f,draw:E=>_3(E,g,f*.18)}];if(l.look==="solid"){const E=cn(h.plan,u,{height:f,contact:h.contact});return{meshes:H3(l,c,h.plan,E,s),drawables:v}}const w=ae(s,[0,f*.6,0]),k=Qt(oe(i.position,w)),S=rf(w,k,r).map(E=>Math.min(1,E));let x=h;if(r.length>0&&h.skin!=="none"){const E=rh(h.skin,S,of(o,ui(w,i.position)),o?.color);x={...h,skin:E,...h.body?{body:{...h.body,fill:E}}:{}}}const M=Um(x,u,g,{height:f});return{drawables:[...v,...M.map((E,T)=>({depth:-(E.sortDepth??E.depth)-T*1e-6,draw:(A,P)=>E.draw(A,P.time)}))]}}},dn={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}},Yi=1,No=.55,mp=.35,L3=1.6,pp={a:"a",e:"e",i:"i",y:"i",o:"o",u:"u"},yp={m:"m",b:"m",p:"m",f:"f",v:"f",w:"u",q:"u",l:"l",n:"l",d:"l",t:"l"},bp={अ:"a",आ:"a",इ:"i",ई:"i",उ:"u",ऊ:"u",ऋ:"i",ए:"e",ऐ:"e",ओ:"o",औ:"o",ऍ:"e",ऑ:"o"},wp={"ा":"a","ि":"i","ी":"i","ु":"u","ू":"u","ृ":"i","े":"e","ै":"e","ो":"o","ौ":"o","ॅ":"e","ॉ":"o"},N3={प:"m",फ:"m",ब:"m",भ:"m",म:"m",व:"u"},W3="्",kp="़",D3=t=>t>="क"&&t<="ह",vp=new Set([".",",","!","?",";",":","…","।","॥","—","-"]);function Mp(t){const e=[],n=Array.from(t.toLowerCase()),s=(i,r)=>{const o=e[e.length-1];o&&o.viseme===i?o.weight+=r*.5:e.push({viseme:i,weight:r})};for(let i=0;i<n.length;i++){const r=n[i],o=n[i+1];if(vp.has(r))s("rest",L3);else if(/\s/.test(r)){const a=e[e.length-1];a&&a.viseme!=="rest"&&e.push({viseme:"c",weight:mp})}else if((r==="o"||r==="e")&&o===r)s(r==="o"?"u":"i",Yi),i++;else if(r in pp)s(pp[r],Yi);else if(r in yp)s(yp[r],No);else{if(r==="h")continue;if(/[a-z]/.test(r))s("c",No);else if(r in bp)s(bp[r],Yi);else if(D3(r)){const a=o===kp?r==="फ"?"f":void 0:N3[r];s(a??"c",No);let l=i+1;n[l]===kp&&l++;const c=n[l];c===W3?i=l:c&&c in wp?(s(wp[c],Yi),i=l):(!c||/\s/.test(c)||vp.has(c)||s("a",Yi*.6),i=l-1)}else(r==="ं"||r==="ँ")&&s("l",No*.6)}}for(;e.length>0&&(e[e.length-1].viseme==="rest"||e[e.length-1].weight===mp);)e.pop();return e}function ah(t,e={}){const n=e.fields?.mouth??"mouth",s=e.fields?.mouthWidth??"mouthWidth",i=e.energy??1,r=Mp(t.text),o=[{time:t.start,value:dn.rest.mouth}],a=[{time:t.start,value:dn.rest.mouthWidth}],l=r.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 r){const d=c*u.weight/l,f=h+Math.min(d*.4,60);if(f>o[o.length-1].time){const m=dn[u.viseme];o.push({time:f,value:m.mouth*i,easing:"ease-out"}),a.push({time:f,value:1+(m.mouthWidth-1)*Math.min(1.3,i),easing:"ease-out"})}h+=d}}return t.end>o[o.length-1].time&&(o.push({time:t.end,value:dn.rest.mouth,easing:"ease-in-out"}),a.push({time:t.end,value:dn.rest.mouthWidth,easing:"ease-in-out"})),{[n]:o,[s]:a}}function B3(t,e,n={}){const s={};for(const i of[...e].sort((r,o)=>r.start-o.start))for(const[r,o]of Object.entries(ah(i,n))){const a=s[r]??=[],l=a.length>0?a[a.length-1].time:-1/0;a.push(...o.filter(c=>c.time>l))}return Object.entries(s).map(([i,r])=>({id:`${t}-${i}`,target:t,property:i,keyframes:r}))}function Wo(t,e,n,s={}){if(n.length===0)return e;const i=s.fields?.mouth??"mouth",r=s.fields?.mouthWidth??"mouthWidth",o={[i]:dn.rest.mouth,[r]:dn.rest.mouthWidth,...s.rest},a=new Ht({id:"before-speech",tracks:e}),l=(u,d)=>a.getStateAtTime(d).values.get(t)?.get(u)??o[u],c=[i,r],h=e.filter(u=>u.target!==t||!c.includes(u.property));for(const u of c){const d=e.find(m=>m.target===t&&m.property===u);let f=d?[...d.keyframes]:[{time:0,value:l(u,0)}];for(const m of n){const g=ah(m,s)[u];g[0]={...g[0],value:l(u,m.start)},g[g.length-1]={...g[g.length-1],value:l(u,m.end)},f=[...f.filter(p=>p.time<m.start||p.time>m.end),...g],f.sort((p,y)=>p.time-y.time)}h.push({id:d?.id??`${t}-${u}`,target:t,property:u,keyframes:f})}return h}const Xi=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function Sp([t,e,n]){const[s,i,r]=[t/2,e/2,n/2];return{vertices:[[-s,-i,-r],[s,-i,-r],[s,i,-r],[-s,i,-r],[-s,-i,r],[s,-i,r],[s,i,r],[-s,i,r]],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 Os=(t,[e,n,s])=>t==="z"?[e,n,s]:t==="x"?[s,n,e]:[e,s,n];function Tp(t,e,n="x",s=20,i=0){const r=[],o=e/2;for(const c of[-o,o])for(let h=0;h<s;h++){const u=Math.PI*2*h/s;r.push(Os(n,[Math.cos(u)*t,Math.sin(u)*t,c]))}const a=[{corners:Array.from({length:s},(c,h)=>s-1-h),normal:Os(n,[0,0,-1])},{corners:Array.from({length:s},(c,h)=>s+h),normal:Os(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:Os(n,[Math.cos(u),Math.sin(u),0])})}const l=[];if(i>0)for(const c of[-o,o]){const h=r.push(Os(n,[0,0,c*1.01]))-1;for(let u=0;u<i;u++){const d=Math.PI*2*u/i,f=r.push(Os(n,[Math.cos(d)*t*.82,Math.sin(d)*t*.82,c*1.01]))-1;l.push([h,f])}}return{vertices:r,faces:a,marks:l,creases:!0}}function Ep([t,e,n],s=16){const i=Math.max(4,Math.round(s/2)),r=[[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;r.push([Math.sin(u)*Math.cos(f)*t,Math.cos(u)*e,Math.sin(u)*Math.sin(f)*n])}}const o=r.push([0,-e,0])-1,a=(h,u)=>1+(h-1)*s+u%s,l=h=>{const u=h.reduce((d,f)=>[d[0]+r[f][0],d[1]+r[f][1],d[2]+r[f][2]],[0,0,0]);return Xi([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 m=[a(f,h),a(f,h+1),a(f+1,h+1),a(f+1,h)];c.push({corners:m,normal:l(m)})}const d=[a(i-1,h),a(i-1,h+1),o];c.push({corners:d,normal:l(d)})}return{vertices:r,faces:c,creases:!1}}const z3=t=>t.reduce((e,[n,s],i)=>{const[r,o]=t[(i+1)%t.length];return e+n*o-r*s},0)/2;function Ap(t,e){const n=z3(t)<0?[...t].reverse():t,s=n.length,i=e/2,r=[...n.map(([a,l])=>[i,l,a]),...n.map(([a,l])=>[-i,l,a])],o=[{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]];o.push({corners:[a,l,s+l,s+a],normal:Xi([0,-c,h])})}return{vertices:r,faces:o,creases:!0}}function xp(t,e){const n={left:([i,r])=>[0,r,i],right:([i,r])=>[0,r,i],front:([i,r])=>[i,r,0],back:([i,r])=>[i,r,0],up:([i,r])=>[i,0,r]},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,r)=>r),normal:s[e]}]}}function Pp(t,e,n=8){const s=o=>Array.isArray(e)?e[Math.min(o,e.length-1)]:e,i=[],r=[];t.forEach((o,a)=>{const l=t[Math.min(a+1,t.length-1)],c=t[Math.max(a-1,0)],h=Xi([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=Xi($p(h,u)),f=$p(d,h);for(let m=0;m<n;m++){const g=Math.PI*2*m/n,p=Math.cos(g)*s(a),y=Math.sin(g)*s(a);i.push([o[0]+d[0]*p+f[0]*y,o[1]+d[1]*p+f[1]*y,o[2]+d[2]*p+f[2]*y])}});for(let o=0;o<t.length-1;o++)for(let a=0;a<n;a++){const l=(a+1)%n,c=[o*n+a,o*n+l,(o+1)*n+l,(o+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[o][0]+t[o+1][0])/2,(t[o][1]+t[o+1][1])/2,(t[o][2]+t[o+1][2])/2];r.push({corners:c,normal:Xi([h[0]-u[0],h[1]-u[1],h[2]-u[2]])})}return{vertices:i,faces:r,creases:!1}}function $p(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 Ip(t){switch(t.type){case"box":return Sp(t.size);case"cylinder":return Tp(t.radius,t.length,t.axis,t.segments,t.spokes);case"ellipsoid":return Ep(t.radii,t.segments);case"extrude":return Ap(t.profile,t.width);case"panel":return xp(t.points,t.facing);case"tube":return{...Pp(t.points,t.radius,t.segments),joined:t.joined}}}function lh(t,e){if(t.length<2)return t;const n=i=>t[Math.max(0,Math.min(t.length-1,i))],s=i=>{const r=i*(t.length-1),o=Math.min(t.length-2,Math.floor(r)),a=r-o,[l,c,h,u]=[n(o-1),n(o),n(o+1),n(o+2)];return[0,1,2].map(d=>{const f=l[d],m=c[d],g=h[d],p=u[d];return .5*(2*m+(-f+g)*a+(2*f-5*m+4*g-p)*a*a+(-f+3*m-3*g+p)*a*a*a)})};return Array.from({length:e},(i,r)=>s(r/(e-1)))}const qn=t=>Array.isArray(t)&&t.length===2&&t.every(e=>typeof e=="number"&&Number.isFinite(e));function Do(t,e){return((e-t)%360+540)%360-180}function Op(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 Cs(t,e){return Math.atan2(e[0]-t[0],e[1]-t[1])*180/Math.PI}function Cp(t){const e=t.filter((i,r)=>r===0||Math.hypot(i[0]-t[r-1][0],i[1]-t[r-1][1])>1e-6);if(e.length<2)return[];const n=e.length===2?e:lh(e.map(([i,r])=>[i,0,r]),(e.length-1)*12).map(([i,,r])=>[i,r]);let s=0;return n.map((i,r)=>(r>0&&(s+=Math.hypot(i[0]-n[r-1][0],i[1]-n[r-1][1])),{point:i,at:s}))}function _p(t,e){let n=1;for(;n<t.length-1&&t[n].at<e;)n++;const s=t[n-1],i=t[n],r=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])*r,s.point[1]+(i.point[1]-s.point[1])*r],direction:[i.point[0]-s.point[0],i.point[1]-s.point[1]]}}function Rp(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 r=(n+s)/2;t(r)<e?n=r:s=r}return(n+s)/2}const Gi=520,ch=["do","at","for","to","through","toward","speed","pose","gag","say","look","turns","dance","bpm","beats"],Hp=t=>Math.max(700,Array.from(t).length*65),Fp=70,Lp=35;function hh(t,e){const n=e[0]-t.x,s=e[1]-t.eyeHeight,i=e[2]-t.z,r=t.heading*Math.PI/180,o=n*Math.cos(r)-i*Math.sin(r),a=n*Math.sin(r)+i*Math.cos(r),l=Math.atan2(o,a)*180/Math.PI,c=Math.hypot(o,a),h=-Math.atan2(s,c)*180/Math.PI,u=Math.max(-Fp,Math.min(Fp,l*.75)),d=Math.max(-Lp,Math.min(Lp,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 Np={walk:1.3,bouncy:1.4,doubleBounce:1.2,sneak:.6,strut:1.2,tired:.8,run:3.6,shove:.7},uh=Object.keys(Gt),dh=Object.keys(Ae),fh=Object.keys(So),q3=.25,j3=700/180,K3=200,Y3=300;function Wp(t){if(!Array.isArray(t))return[{beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const e=[...uh,"face","spin","dance","hold","pose","gag","place","say","look"],n=[];return t.forEach((s,i)=>{const r=c=>n.push({beat:i,message:c});if(!s||typeof s!="object"||Array.isArray(s))return r("Each beat must be an object like { do: 'walk', to: [x, z] }.");const o=s,a={duration:"for",path:"through",position:"to",heading:"toward",direction:"toward"};for(const c of Object.keys(o))ch.includes(c)||r(dt("beat field",c,ch,a[c]));const l=typeof o.do=="string"?dh.includes(o.do)?"pose":fh.includes(o.do)?"gag":o.do==="turn"?"face":void 0:void 0;if(typeof o.do!="string"||!e.includes(o.do))return r(dt("character 3D beat",o.do,e,l));for(const c of["at","for","turns","bpm","beats"]){const h=o[c];h!==void 0&&(typeof h!="number"||!Number.isFinite(h)||(c==="at"?h<0:c!=="turns"&&h<=0))&&r(`\`${c}\` must be finite${c==="turns"?"":c==="at"?" and non-negative":" and positive"}.`)}if(o.do==="dance"&&!(typeof o.dance=="string"&&Object.hasOwn(Nn,o.dance))&&r(dt("native dance",o.dance,Object.keys(Nn))),uh.includes(o.do)&&(o.to===void 0&&o.through===void 0&&r(`\`${o.do}\` needs \`to\` ([x, z] metres) or \`through\` (a list of them).`),o.to!==void 0&&!qn(o.to)&&r(`\`to\` is a point on the ground, [x, z] metres (got ${JSON.stringify(o.to)}).`),o.through!==void 0&&!(Array.isArray(o.through)&&o.through.length>0&&o.through.every(qn))&&r("`through` is a list of points on the ground, each [x, z] metres.")),o.do==="place"&&!qn(o.to)&&r("`place` needs `to`: a point on the ground, [x, z] metres."),o.do==="face"&&!(qn(o.toward)||typeof o.toward=="number"&&Number.isFinite(o.toward))&&r("`face` needs `toward`: a point [x, z] or a finite heading in degrees."),o.do==="say"&&!(typeof o.say=="string"&&o.say.trim().length>0)&&r("`say` needs `say`: the line spoken."),o.do==="look"){const c=o.look??o.toward;Array.isArray(c)&&(c.length===2||c.length===3)&&c.every(u=>typeof u=="number"&&Number.isFinite(u))||c==="camera"||r("`look` needs `look`: a point [x, z] or [x, y, z] to look at, or `camera`.")}o.do==="pose"&&!(typeof o.pose=="object"&&o.pose!==null)&&!dh.includes(o.pose)&&r(dt("pose",o.pose,dh)),o.do==="gag"&&!fh.includes(o.gag)&&r(dt("gag",o.gag,fh))}),n}function X3(t,e,n){const s=Wp(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,r={...lt,...n.pose},o=(M,E=r)=>{const T=M.match(/^hand\.(?:left|right)\.(.+)$/)?.[1];return E[M]??lt[M]??(T?Ct[T]:void 0)??0};let[a,l]=n.position??[0,0],c=n.heading??0,h=0;const u=new Map,d=[],f=(M,E,T,A="linear")=>{const P=u.get(M)??[];P.push({time:E,value:T,easing:A}),u.set(M,P)},m=(M,E,T)=>{const A=u.get(M)??[];for(let P=A.length-1;P>=0;P--)if(A[P].time===E){if(A[P].value===T)return;break}f(M,E,T)};f("x",0,a),f("z",0,l),f("rotateY",0,c);const g=(M,E,T)=>{const A=Do(c,E);if(Math.abs(A)<1)return T!==void 0&&(m("rotateY",M,c),f("rotateY",M+T,c)),M+(T??0);const P=T??Math.max(K3,Math.abs(A)*j3);return m("rotateY",M,c),c+=A,f("rotateY",M+P,c,"ease-in-out"),M+P},p=(M,E,T,A="ease-in-out")=>{for(const[P,I]of Object.entries(T))o(P)!==I&&(m(P,M,o(P)),f(P,E,I,A),r[P]=I)},b=(M,E,T)=>{const A=Cp([[a,l],...E.through??[E.to]]);if(A.length<2)return T;const P=g(T,Cs(A[0].point,A[1].point)),I=A[A.length-1].at,O=E.speed??Np[M]*Math.sqrt(i/1.7),_=E.for??I/O*1e3,L=Mo(M,i),j=Dt("ease-in-out"),V=Math.min(Y3,_/4);d.push({time:P,value:M}),m("walking",P,0),f("walking",P+V,1,"ease-out"),f("walking",P+_-V,1),f("walking",P+_,0,"ease-in");const tt=h;let J=c;for(let F=0;;F=Math.min(I,F+q3)){const B=P+Rp(j,F/I)*_,{point:Y,direction:R}=_p(A,F);J+=Do(J,Cs([0,0],R));const K=F===0?m:f;if(K("x",B,Y[0]),K("z",B,Y[1]),K("rotateY",B,J),K("walk",B,tt+F/L),F>=I)break}return h=tt+I/L,[a,l]=A[A.length-1].point,c=J,P+_},v=[],k=[];let w=0;for(const M of e){const E=M.at??w;let T=E;if(uh.includes(M.do))T=b(M.do,M,E);else if(M.do==="face")T=g(E,typeof M.toward=="number"?M.toward:Cs([a,l],M.toward),M.for);else if(M.do==="spin")T=E+(M.for??1e3),m("rotateY",E,c),c+=(M.turns??1)*360,f("rotateY",T,c,"linear");else if(M.do==="dance"){const A=Nn[M.dance],P=M.bpm??A.bpm,I=M.beats??(M.for!==void 0?M.for*P/6e4:A.beats);T=E+(M.for??I*6e4/P);const O={...r},_=Math.max(1,Math.ceil(I*16)),L=Array.from({length:_+1},(V,tt)=>Ci(M.dance,I*tt/_,O).pose),j=Math.min(150,(T-E)/4);for(const V of Object.keys(L[0])){const tt=o(V,O);V==="turn"||V==="roll"||L.every(J=>J[V]===tt)||(m(V,E,tt),L.slice(1).forEach((J,F)=>{const B=E+(T-E)*(F+1)/_,Y=Math.min(1,(B-E)/j),R=Y*Y*(3-2*Y);f(V,B,tt+(J[V]-tt)*R)}),r[V]=L[_][V])}}else if(M.do==="hold")T=E+(M.for??1e3);else if(M.do==="place")m("x",E,a),m("z",E,l),[a,l]=M.to,f("x",E+1,a),f("z",E+1,l),typeof M.toward=="number"&&(m("rotateY",E,c),c=M.toward,f("rotateY",E+1,c)),T=E+1;else if(M.do==="pose"){T=E+(M.for??500);const A=typeof M.pose=="string"?Ae[M.pose]:M.pose;p(E,T,A)}else if(M.do==="gag"){const A=mm(M.gag,{at:E,from:{...r}});let P=A[0];for(const I of A.slice(1))p(P.time,I.time,Object.fromEntries(Object.entries(I.pose).filter(([O,_])=>r[O]!==_)),I.easing??"ease-in-out"),P=I;T=P.time}else if(M.do==="say"){T=E+(M.for??Hp(M.say)),k.push({text:M.say,start:E,end:T});const A={tilt:r["head.tilt"]??0,left:r["brow.left"]??0,right:r["brow.right"]??0};let P=0;for(let I=E+Gi;I<T-Gi/2;I+=Gi,P++){const O=P%2===0;p(I-Gi/2,I,{"head.tilt":A.tilt+(O?3:-2),"brow.left":A.left+(O?.25:0),"brow.right":A.right+(O?.25:0)})}P>0&&p(T-Gi/2,T,{"head.tilt":A.tilt,"brow.left":A.left,"brow.right":A.right})}else if(M.do==="look"){const A=M.look??M.toward,P=i*.9,I=A==="camera"?n.camera??[0,1.6,8]:A.length===3?A:[A[0],P,A[1]];T=E+(M.for??500),p(E,T,hh({x:a,z:l,heading:c,eyeHeight:P},I),"ease-out")}v.push({do:M.do,start:E,end:T}),w=T}const S=`${n.scene}/${t}`;let x=[...u].map(([M,E])=>({id:`${t}-${M}`,target:S,property:M,keyframes:Op(E)}));return d.length>0&&x.push({id:`${t}-gait`,target:S,property:"gait",keyframes:d}),k.length>0&&(x=Wo(S,x,k,{rest:{mouth:n.pose?.mouth??lt.mouth??0,mouthWidth:n.pose?.mouthWidth??lt.mouthWidth??1}})),{tracks:x,duration:w,beats:v,end:{position:[a,l],heading:c,pose:{...r}}}}function gh(t,e,n=[0,0,0]){const s=t.filter(r=>r.target===e),i=new Ht({id:`${e}-position`,tracks:s});return r=>{const o=i.getStateAtTime(r).values.get(e),a=o?.get("position");if(Array.isArray(a)&&a.length===3)return[a[0],a[1],a[2]];const l=(c,h)=>{const u=o?.get(c);return typeof u=="number"?u:h};return[l("x",n[0]),l("y",n[1]),l("z",n[2])]}}function G3(t,e){const n=`${e.scene}/${e.character}`,s=e.height??1.7,i=Math.max(1,e.every??66),r=e.objects?.[e.character]??[0,0,0],o=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?gh(t,`${e.scene}/${a.camera}`,e.objects?.[a.camera]??[0,1.6,8]):(()=>{const u=gh(t,`${e.scene}/${a.object}`,e.objects?.[a.object]??[0,0,0]),d=a.eyeHeight??s*.9;return f=>{const m=u(f);return[m[0],m[1]+d,m[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=o.getStateAtTime(u).values.get(n),f=(g,p)=>{const b=d?.get(g);return typeof b=="number"?b:p},m=hh({x:f("x",r[0]),z:f("z",r[2]),heading:f("rotateY",0),eyeHeight:f("y",r[1])+s*.9},l(u));for(const g of c)h[g].push({time:u,value:m[g]??0});if(u>=e.end)break}return c.map(u=>({id:`${n}-lookAt-${u}`,target:n,property:u,keyframes:h[u]}))}function U3(t){const e=Math.max(1,Math.round(t.count)),[n,s]=t.centre??[0,0],i=t.spacing??1.2,r=t.shape??"line",o=[];if(r==="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,m=s+Math.cos(d)*h;o.push({position:[f,m],heading:(Math.atan2(n-f,s-m)*180/Math.PI+360)%360})}return o}if(r==="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 m=[n,s],g=-1/0;for(let p=0;p<24;p++){const b=Math.sqrt(u())*i*Math.max(1,Math.sqrt(e)*.9),v=u()*Math.PI*2,k=[n+Math.cos(v)*b,s+Math.sin(v)*b],w=d.length===0?1/0:Math.min(...d.map(S=>Math.hypot(S[0]-k[0],S[1]-k[1])));if(w>g&&(g=w,m=k),w>=i)break}d.push(m),o.push({position:m,heading:0})}return o}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,m=s+Math.cos(a)*d,g=((t.heading??90)-90+360)%360;if(r==="arc"){const p=(1-Math.cos(u*c))*l*.5;f-=Math.cos(a)*p,m+=Math.sin(a)*p,g=(g-u*(t.bend??60)+360)%360}o.push({position:[f,m],heading:g})}return o}const Dp={x:0,y:0,scale:1,rotate:0,shakeX:0,shakeY:0,shakeRotate:0};function V3(t){const e=n=>{const s=t?.get(n);return typeof s=="number"?s:Dp[n]};return{x:e("x"),y:e("y"),scale:e("scale"),rotate:e("rotate"),shakeX:e("shakeX"),shakeY:e("shakeY"),shakeRotate:e("shakeRotate")}}function J3(t,e,n){const s=n.width/2,i=n.height/2,o=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*o,e.scale*o),t.translate(-s,-i)}function Z3(t,e,n){const s=e.width/2,i=e.height/2,r=(t.rotate+t.shakeRotate)*Math.PI/180,o=(n.x-s)*t.scale,a=(n.y-i)*t.scale;return{x:s+t.x+t.shakeX+o*Math.cos(r)-a*Math.sin(r),y:i+t.y+t.shakeY+o*Math.sin(r)+a*Math.cos(r)}}function Bp(t,e,n={},s){const i=n.length??240,r=9,o=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(o,-r,a-o,2*r),t.fillStyle="#e8b4a0",t.fillRect(a,-r,i-a,2*r),t.fillStyle="#f1dcbf",t.beginPath(),t.moveTo(0,0),t.lineTo(o,-r),t.lineTo(o,r),t.closePath(),t.fill(),t.fillStyle=n.outline??"#2f2f33",t.beginPath(),t.moveTo(0,0),t.lineTo(o*.35,-r*.35),t.lineTo(o*.35,r*.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:o,y:-r},{x:i,y:-r},{x:i,y:r},{x:o,y:r},{x:0,y:0}],[{x:o,y:-r},{x:o,y:r}],[{x:a,y:-r},{x:a,y:r}]];for(const c of l)jp(t,c,s);t.restore()}function mh(t,e,n={},s){const i=n.length??90,r=n.thickness??34;t.save(),t.translate(e.x,e.y),t.rotate((n.angle??-35)*Math.PI/180);const o=-r/2;t.fillStyle=n.color??"#f4a7b9",t.fillRect(0,o,i,r),t.fillStyle="#e9edf2",t.fillRect(i*.45,o,i*.55,r),t.strokeStyle=n.outline??"#2f2f33",t.lineWidth=3,t.lineJoin="round";const a=[{x:0,y:o},{x:i,y:o},{x:i,y:-o},{x:0,y:-o},{x:0,y:o}],l=[{x:i*.45,y:o},{x:i*.45,y:-o}];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 zp=150,Q3={pencil:44,eraser:30};function ph(t,e,n={},s){const i=n.tool??"pencil",r=n.skin??"#f1c9a5",o=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=zp*a*(1+.05*l);l>0&&(t.save(),t.fillStyle=o,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=Tt.pencilGrip,m=M=>{const E=M.fingers.thumb,T=M.fingers.index,A=M.fingers.middle,P=qp([E.points[3],T.points[3],A.points[3]]),I=qp([E.points[1],T.points[0]]),O=(E.depths[3]+T.depths[3]+A.depths[3])/3;return{pinch:P,direction:Math.atan2(I.y-P.y,I.x-P.x),depth:O}},g=Kr(f,{size:u}),p=c-m(g).direction,b=Kr(f,{size:u,angle:p*180/Math.PI}),v=m(b),k=Q3[i]*a,w={x:v.pinch.x-Math.cos(c)*k,y:v.pinch.y-Math.sin(c)*k},S={x:d.x-w.x,y:d.y-w.y},x=b.axes.up;tT(t,S,{x:-x.x,y:-x.y},u,n.arm??300*a,r,n.sleeve??"#5b7db1",o),Yr(t,S,f,{size:u,angle:p*180/Math.PI,skin:r,ink:o,lineWidth:3*a,prop:{depth:v.depth,draw:()=>{t.save(),t.translate(d.x,d.y),t.scale(a,a),i==="eraser"?mh(t,{x:0,y:0},{angle:c*180/Math.PI,outline:o},s):Bp(t,{x:0,y:0},{angle:c*180/Math.PI,length:190,outline:o},s),t.restore()}}})}const qp=t=>({x:t.reduce((e,n)=>e+n.x,0)/t.length,y:t.reduce((e,n)=>e+n.y,0)/t.length});function tT(t,e,n,s,i,r,o,a){const l={x:-n.y,y:n.x},c=s*.15,h=(g,p,b)=>({x:e.x+n.x*g+l.x*p*b,y:e.y+n.y*g+l.y*p*b}),u=h(i,0,0),d=g=>{const p=t.createLinearGradient(e.x,e.y,u.x,u.y);return p.addColorStop(0,g),p.addColorStop(.6,g),p.addColorStop(1,iT(g)),p},f=Math.min(s*.55,i*.35);t.save(),t.lineJoin="round",t.lineCap="round",t.lineWidth=3*(s/zp),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=r,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 m=[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(),m.forEach((g,p)=>p?t.lineTo(g.x,g.y):t.moveTo(g.x,g.y)),t.closePath(),t.fillStyle=d(o),t.fill(),t.strokeStyle=d(a),t.beginPath(),t.moveTo(m[1].x,m[1].y),t.lineTo(m[0].x,m[0].y),t.lineTo(m[3].x,m[3].y),t.lineTo(m[2].x,m[2].y),t.stroke(),t.restore()}function eT(t,e,n={}){const s=n.offstage??{x:2e3,y:1400},i=n.enter??450,r=n.exit??450,o=n.linger??1500,a=[...t].filter(g=>g.path.length>0).sort((g,p)=>g.start-p.start),l=g=>g.tool??"pencil",c=g=>{const p=Math.min(1,Math.max(0,g));return p*p*(3-2*p)},h=(g,p,b)=>({x:g.x+(p.x-g.x)*b,y:g.y+(p.y-g.y)*b}),u=a.find(g=>e>=g.start&&e<=g.end);if(u){const g=u.end-u.start,p=g>0?(e-u.start)/g:1;return{at:Wr(u.path,p),tool:l(u),lift:0,drawing:!0}}const d=[...a].reverse().find(g=>g.end<e),f=a.find(g=>g.start>e),m=g=>g.path[g.path.length-1];if(d&&f&&f.start-d.end<=o){const g=(e-d.end)/(f.start-d.end),p=g<.5?l(d):l(f);return{at:h(m(d),f.path[0],c(g)),tool:p,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<=r){const g=(e-d.end)/r;return{at:h(m(d),s,c(g)),tool:l(d),lift:c(g),drawing:!1}}return null}function nT(t,e,n,s=.08,i=32){const r=Math.PI*2*(1+s),o=[];for(let a=0;a<=i;a++){const l=-Math.PI/2+r*a/i;o.push({x:t+Math.cos(l)*n,y:e+Math.sin(l)*n})}return o}function sT(t){const{path:e}=t,n=e.map(a=>a.x),s=e.map(a=>a.y),i=Math.min(...n),r=Math.min(...s),o=t.hand===!1?void 0:t.hand===!0||t.hand===void 0?{}:t.hand;return{type:"custom",x:i,y:r,width:Math.max(1,Math.max(...n)-i),height:Math.max(1,Math.max(...s)-r),props:{draw:0},draw(a,l,c){const h=Math.min(1,Math.max(0,Number(l.props?.draw??0)));a.translate(-i,-r),a.strokeStyle=t.color??"#2f2f33",a.lineWidth=t.lineWidth??5,a.lineCap="round",a.lineJoin="round";const u=t.sketch?Dr(a,t.sketch,c):void 0;h>0&&(u?t.smooth?u.curve(e,h):u.line(e,h):jp(a,sn(e,h))),o&&h>0&&h<1&&ph(a,Wr(e,h),o,u)}}}function iT(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(o=>o+o).join(""):e[1],[s,i,r]=[0,2,4].map(o=>parseInt(n.slice(o,o+2),16));return`rgba(${s}, ${i}, ${r}, 0)`}function jp(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 Bo=1e5;function rT(t,e,n,s,i=6){const r=[],o=Math.max(1,Math.round(i));for(let a=0;a<=o;a++)r.push({x:a%2===0?t:t+n,y:e+s*a/o});return r}function yh(t,e,n,s){if(s<=0||e.length===0)return;const i=sn(e,s),r=n/2,o=a=>{t.beginPath(),t.rect(-Bo,-Bo,2*Bo,2*Bo),a(),t.clip("evenodd")};for(const a of i)o(()=>{t.moveTo(a.x+r,a.y),t.arc(a.x,a.y,r,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*r,d=(c.x-l.x)/h*r;o(()=>{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 oT(t,e,n,s,i){t.save(),yh(t,e,n,s),i(),t.restore()}function aT(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(r,o,a){const l=Number(o.props?.erase??0);if(r.save(),yh(r,e.path,n,l),t.draw(r,o,a),r.restore(),!i||l<=0||l>=1)return;const c=Wr(e.path,l);s?ph(r,c,{...s,tool:"eraser"}):mh(r,c,i)}}}function _s(){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,r,o=300){e(n,{time:r.at,value:s},{time:r.at+(r.duration??o),value:i,...r.easing?{easing:r.easing}:{}})},last(n,s){const i=t.get(n);return i?[...i].sort((r,o)=>r.time-o.time)[i.length-1].value:s},valueAt:(n,s)=>zo(t.get(n),s),cutAfter(n,s){for(const i of n)t.set(i,(t.get(i)??[]).filter(r=>r.time<=s))},tracks(n){return[...t].filter(([,s])=>s.length>0).map(([s,i])=>({id:`${n}-${s}`,target:n,property:s,keyframes:lT(i)}))}}}function zo(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],r=n[s];return r.time===i.time?r.value:i.value+(r.value-i.value)*(e-i.time)/(r.time-i.time)}return n[n.length-1].value}function Rs(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 lT(t){return[...t].sort((n,s)=>n.time-s.time).map(n=>({time:n.time,value:n.value,...n.easing?{easing:n.easing}:{}}))}const cT=.0016,hT=.6,fn=33;function Ui(t){const e=(r,o)=>`piece.${r.id}.${o}`,n=(r,o)=>({x:r.home.x+t.valueAt(e(r,"x"),o),y:r.home.y+t.valueAt(e(r,"y"),o)}),s=(r,o)=>{const a=t.keys(e(r,"x"));if(!a||a.length<2)return;const l=n(r,o-fn),c=n(r,o);return{x:(c.x-l.x)/fn,y:(c.y-l.y)/fn}},i=(r,o)=>t.cutAfter(["x","y","rotate"].map(a=>e(r,a)),o);return{at:n,cutAfter:i,follow(r,o){for(const a of o)t.push(e(r,"x"),{time:a.time,value:a.x-r.home.x}),t.push(e(r,"y"),{time:a.time,value:a.y-r.home.y})},fling(r,o){const a=n(r,o.at),l=o.velocity??s(r,o.at)??{x:.5,y:-.6},c=o.gravity??cT,h=o.duration??900,u=(o.spin??hT)*(l.x<0?-1:1),d=t.valueAt(e(r,"rotate"),o.at);i(r,o.at);for(let f=0;f<=h;f+=fn){const m=a.x+l.x*f,g=a.y+l.y*f+.5*c*f*f;t.push(e(r,"x"),{time:o.at+f,value:m-r.home.x}),t.push(e(r,"y"),{time:o.at+f,value:g-r.home.y}),t.push(e(r,"rotate"),{time:o.at+f,value:d+u*f})}t.tween(e(r,"opacity"),1,0,{at:o.at+h*.6,duration:h*.4})},move(r,o){const a=n(r,o.at);t.tween(e(r,"x"),a.x-r.home.x,o.to.x-r.home.x,o,400),t.tween(e(r,"y"),a.y-r.home.y,o.to.y-r.home.y,o,400)}}}function qo(t,e,{ground:n,every:s,floors:i}){if(i.every(k=>k.windows.length===0))return t;const r=t.find(k=>k.target===e&&k.property==="y"),o=new Ht({id:`${e}-ride`,tracks:r?[r]:[]}),a=k=>r?Number(o.getStateAtTime(k).values.get(e)?.get("y")??0):0,l=k=>{const w=n+a(k);return i.findIndex(S=>Math.abs(S.top-w)<.5)},c=(r?.keyframes??[]).map(k=>k.time),h=k=>{const w=T=>T<0?0:i[T].offset(k),S=l(k);if(S>=0)return w(S);if(Math.abs(a(k))<.5)return 0;const x=T=>l(T)>=0||Math.abs(a(T))<.5,M=[...c].reverse().find(T=>T<=k&&x(T)),E=c.find(T=>T>=k&&x(T));return M===void 0&&E===void 0?0:M===void 0?w(l(E)):E===void 0||E===M?w(l(M)):w(l(M))+(w(l(E))-w(l(M)))*(k-M)/(E-M)},u=i.flatMap(k=>k.windows),d=(k,w)=>u.some(S=>S.start<w&&S.end>k)||h(k)!==h(w),f=r?[...r.keyframes]:[{time:0,value:0}],m=[{...f[0],value:f[0].value+h(f[0].time)}],g=(k,w)=>{const S=new Set([w]);for(let x=k+s;x<w;x+=s)S.add(x);for(const x of u)for(const M of[x.start,x.end])M>k&&M<w&&S.add(M);for(const x of[...S].sort((M,E)=>M-E))m.push({time:x,value:a(x)+h(x)})};for(let k=1;k<f.length;k++){const w=f[k-1].time,S=f[k].time;d(w,S)?g(w,S):m.push({...f[k],value:f[k].value+h(S)})}const p=f[f.length-1].time,b=Math.max(p,...u.map(k=>k.end));b>p&&g(p,b);const v={id:r?.id??`${e}-y`,target:e,property:"y",keyframes:m};return r?t.map(k=>k===r?v:k):[...t,v]}function jn(t){const e=t.indexOf(":");return e<0?{kind:t,rest:""}:{kind:t.slice(0,e),rest:t.slice(e+1)}}function gn(t,e,n,s){const i=Object.keys(n.anchors).map(o=>jn(o).kind),{kind:r}=jn(e);return i.includes(r)?new Error(`${t}: no anchor "${e}"${s?`: ${s}`:""} (anchors: ${Object.keys(n.anchors).join(", ")})`):new Error(`${t}: ${dt("anchor",r,i)} (anchors: ${Object.keys(n.anchors).join(", ")})`)}function Vi(t,e,n){return new Error(`${t}.edit: ${dt("edit",e,Object.keys(n.edits))}`)}function St(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 Kp={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"},jo=["wipe","fly","blur"],Ji={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"}},uT=.9,dT=8;function fT(t){const e={...Kp,...t.theme},n=t.code.replace(/\t/g," ").replace(/\n$/,"").split(`
|
|
56
|
-
`),s=t.fontSize??16,i=(t.lineHeight??1.6)*s,r=(t.charWidth??.6)*s,o=t.padding??12,a=t.lineNumbers===!1?0:(String(n.length).length+2)*r,l=Math.max(1,...n.map(F=>F.length)),c=t.width??o*2+a+l*r,h=o*2+n.length*i,u=t.x+o+a,d=new Set(t.hidden??[]),f=t.language??"plain";if(!Yo.includes(f))throw new Error(`codePanel: ${dt("language",f,Yo)}`);const m=n.map(F=>Xp(F,f).flatMap(B=>Array.from(B.text,()=>e[B.kind]))),g=_s(),p=Ui(g),b=[],v=new Map,k=[],w=[],S=F=>{if(!Number.isInteger(F)||F<1||F>n.length)throw new Error(`codePanel: no line ${F} (it has ${n.length})`)},x=g.tween,M=g.last,E=(F,B,Y,R,K,st=300)=>{S(F),x(`line.${F}.${B}`,Y,R,K,st)},T=(F,B)=>b.filter(Y=>Y.line<F&&Y.closed<=B).length,A=St,P=F=>t.y+o+(F-1)*i,I=F=>Array.isArray(F)?F:[F],O=(F,B,Y)=>{let R=-1;for(let K=0;K<Y;K++)if(R=n[F-1].indexOf(B,R+1),R<0)throw new Error(`codePanel: line ${F} has no ${Y>1?`${Y}th `:""}"${B}"`);return R},_={};n.forEach((F,B)=>{const Y=B+1;_[`line.${Y}.highlight`]=0,_[`line.${Y}.strike`]=0,_[`line.${Y}.wipe`]=0,_[`line.${Y}.reveal`]=d.has(Y)?0:1,_[`line.${Y}.shift`]=0});const L={type:"custom",x:t.x,y:t.y,width:c,height:h,props:_,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 mT(Object.keys(_))},actions:bh},draw(F,B){const Y=B.props??{},R=C=>Number(Y[C]??_[C]),K=o+a,st=C=>o+(C-1)*i-R(`line.${C}.shift`)*i;F.fillStyle=e.background,Yp(F,0,0,c,h,8),F.fill(),F.font=`${s}px ${e.font}`,F.textBaseline="middle",F.textAlign="left";const $=(C,z,X,W,N)=>{const D=n[C-1];for(let G=z;G<X;G++)D[G]!==" "&&(F.fillStyle=m[C-1][G],F.fillText(D[G],W+(G-z)*r,N))};F.save(),Yp(F,0,0,c,h,8),F.clip(),n.forEach((C,z)=>{const X=z+1,W=R(`line.${X}.wipe`);if(W>=1)return;const N=st(X),D=N+i/2,G=Math.max(1,C.length)*r,q=Math.round(R(`line.${X}.reveal`)*C.length),Z=v.get(X)??{style:"wipe",from:"left"};F.save(),W>0&&gT(F,Z,W,{left:K-a,top:N,width:a+G+r,height:i},c);const et=R(`line.${X}.highlight`);et>0&&(F.globalAlpha*=Math.min(1,et),F.fillStyle=e.highlight,F.fillRect(K-r/2,N,G+r,i),F.globalAlpha/=Math.min(1,et)),a>0&&q>0&&(F.fillStyle=e.gutter,F.textAlign="right",F.fillText(String(X),K-r,D),F.textAlign="left");const H=[...k.filter(rt=>rt.line===X).map(rt=>({column:rt.column,length:rt.text.length,piece:rt,insert:void 0})),...w.filter(rt=>rt.line===X).map(rt=>({column:rt.column,length:0,piece:void 0,insert:rt}))].sort((rt,ct)=>rt.column-ct.column||rt.length-ct.length);let U=0,nt=K;for(const rt of H){$(X,U,Math.min(rt.column,q),nt,D),nt+=(rt.column-U)*r;let ct=rt.length,it="";if(rt.piece){const Q=rt.piece.written??"",ot=R(`piece.${rt.piece.id}.write`);Q&&ot>0?(it=Q.slice(0,Math.round(ot*Q.length)),ct=rt.length+(Q.length-rt.length)*Math.min(1,ot*2)):ct=rt.length*(1-R(`piece.${rt.piece.id}.away`))}else rt.insert&&(ct=rt.insert.chars*R(`insert.${rt.insert.id}.open`),rt.insert.text&&(it=rt.insert.text.slice(0,Math.round(R(`insert.${rt.insert.id}.type`)*rt.insert.text.length))));F.fillStyle=e.text;for(let Q=0;Q<it.length;Q++)it[Q]!==" "&&F.fillText(it[Q],nt+Q*r,D);nt+=ct*r,U=rt.column+rt.length}$(X,U,Math.max(U,q),nt,D);const at=R(`line.${X}.strike`);at>0&&(F.strokeStyle=e.strike,F.lineWidth=Math.max(1.5,s/10),F.beginPath(),F.moveTo(K,D),F.lineTo(K+G*Math.min(1,at),D),F.stroke()),F.restore()});for(const C of k){const z=R(`piece.${C.id}.opacity`);if(z<=0||R(`line.${C.line}.wipe`)>=1)continue;const X=K+(C.column+C.text.length/2)*r+R(`piece.${C.id}.x`),W=st(C.line)+i/2+R(`piece.${C.id}.y`);F.save(),F.globalAlpha=Math.min(1,z),F.translate(X,W),F.rotate(R(`piece.${C.id}.rotate`)*Math.PI/180),$(C.line,C.column,C.column+C.text.length,-C.text.length*r/2,0),F.restore()}F.restore()}},j=F=>{const{kind:B,rest:Y}=jn(F),R=K=>gn("codePanel",F,Ji,K);if(B==="box"){if(Y)throw R("box takes no arguments");return{kind:B}}if(B==="line"){if(!/^\d+$/.test(Y))throw R("write it line:N");return{kind:B,n:Number(Y)}}if(B==="token"){const K=/^(\d+)(?:#(\d+))?:(.+)$/.exec(Y);if(!K)throw R("write it token:N:TEXT, or token:N#K:TEXT for the Kth");return{kind:B,n:Number(K[1]),occurrence:K[2]?Number(K[2]):1,text:K[3]}}if(B==="spot"){const K=/^(\d+):(\d+)(?::(\d+))?$/.exec(Y);if(!K)throw R("write it spot:N:C, or spot:N:C:W for W characters");return{kind:B,n:Number(K[1]),column:Number(K[2]),width:K[3]?Number(K[3]):1}}throw R()},V=(F,B,Y,R=!1)=>{const K=Array.isArray(B)?B:[B];if(K.length===0||R&&K.length>1)throw new Error(`codePanel.edit: ${F} takes ${R?"one":"at least one"} ${Y} anchor`);return K.map(st=>{const $=j(st);if($.kind!==Y)throw new Error(`codePanel.edit: ${F} takes ${Y} anchors (${Y}:…), not "${st}"`);return $})},tt=(F,B)=>{if(typeof B.text!="string")throw new Error(`codePanel.edit: ${F} needs \`text\` (the text to write)`);return B.text},J={kind:"code",about:Ji,target:L,lines:n,box:A(t.x,t.y,c,h),line(F,B=1/0){return S(F),A(u,P(F)-T(F,B)*i,Math.max(1,n[F-1].length)*r,i)},token(F,B,Y=1,R=1/0){S(F);const K=O(F,B,Y);return A(u+K*r,P(F)-T(F,R)*i,B.length*r,i)},highlight(F,B){for(const Y of I(F)){const R=M(`line.${Y}.highlight`,0);E(Y,"highlight",R,B.on===!1?0:1,B,200)}return J},strike(F,B){for(const Y of I(F))E(Y,"strike",M(`line.${Y}.strike`,0),1,B);return J},remove(F,B){const Y=I(F),R=B.style??"wipe";if(!jo.includes(R))throw new Error(`codePanel.remove: ${dt("style",R,jo)}`);const K=R==="wipe"?300:450,st=B.at+(B.duration??K),$=B.close??250;for(const C of Y)E(C,"wipe",0,1,{...B,easing:B.easing??(R==="fly"?"ease-in":void 0)},K),v.set(C,{style:R,from:B.from??"left"}),b.push({line:C,closed:st+$});for(let C=1;C<=n.length;C++){if(Y.includes(C))continue;const z=Y.filter(W=>W<C).length;if(z===0)continue;const X=M(`line.${C}.shift`,0);E(C,"shift",X,X+z,{at:st,duration:$,easing:"ease-in-out"})}return J},type(F,B){return E(F,"reveal",0,1,{duration:n[F-1].length*45,...B}),J},piece(F,B,Y=1){if(typeof F=="string"){const C=j(F);if(C.kind!=="token")throw new Error(`codePanel.piece: a piece is a word, token:N:TEXT, not "${F}"`);return J.piece(C.n,C.text,C.occurrence)}const R=F;if(B===void 0)throw new Error('codePanel.piece: which word? piece(n, text) or piece("token:N:TEXT")');S(R);const K=O(R,B,Y),st=k.find(C=>C.line===R&&C.column===K&&C.text===B);if(st)return st;if(k.some(C=>C.line===R&&K<C.column+C.text.length&&C.column<K+B.length))throw new Error(`codePanel: "${B}" on line ${R} overlaps another piece`);const $={id:k.length+1,line:R,column:K,text:B,home:J.token(R,B,Y,0)};k.push($);for(const C of["x","y","rotate","write","away"])_[`piece.${$.id}.${C}`]=0;return _[`piece.${$.id}.opacity`]=1,$},follow(F,B){return p.follow(F,B),J},fling(F,B){return p.fling(F,B),J},move(F,B){return p.move(F,B),J},write(F,B,Y){return F.written=B,x(`piece.${F.id}.write`,0,1,{duration:Math.max(1,B.length)*70,...Y}),J},spot(F,B,Y=1,R=1/0){S(F);const K=w.filter(st=>st.line===F&&st.column<=B&&st.at<=R).reduce((st,$)=>st+$.chars,0);return A(u+(B+K)*r,P(F)-T(F,R)*i,Y*r,i)},insert(F,B,Y,R){S(F);const K={id:w.length+1,line:F,column:B,chars:Y.length,text:Y,at:R.at};w.push(K),_[`insert.${K.id}.open`]=0,_[`insert.${K.id}.type`]=0;const st=R.duration??Y.length*70;return x(`insert.${K.id}.open`,0,1,{at:R.at,duration:st*.6,easing:"ease-out"}),x(`insert.${K.id}.type`,0,1,{at:R.at,duration:st}),J},drop(F,B,Y,R){S(B);const K=R.duration??250,st=B===F.line,$=R.easing??(st?"linear":"ease-out"),C=J.landing(F,B,Y,R.at),z={id:w.length+1,line:B,column:Y,chars:F.text.length,at:R.at};return w.push(z),_[`insert.${z.id}.open`]=0,x(`insert.${z.id}.open`,0,1,{at:R.at,duration:K,easing:st?$:"ease-out"}),x(`piece.${F.id}.away`,M(`piece.${F.id}.away`,0),1,{at:R.at,duration:K,easing:st?$:"ease-in-out"}),p.cutAfter(F,R.at),J.move(F,{at:R.at,duration:K,easing:$,to:{x:C.x,y:C.y}}),x(`piece.${F.id}.rotate`,g.valueAt(`piece.${F.id}.rotate`,R.at),0,{at:R.at,duration:K}),J},landing(F,B,Y,R=1/0){const K=J.spot(B,Y,F.text.length,R),st=B===F.line&&Y>F.column?F.text.length*r:0;return A(K.left-st,K.top,K.width,K.height)},ride(F,B,Y){const R=n.map((K,st)=>{const $=g.keys(`line.${st+1}.shift`)??[];return{top:P(st+1),offset:C=>-zo($,C)*i,windows:Rs($)}});return qo(F,B,{ground:Y.ground,every:Y.every??fn,floors:R})},tracks:g.tracks,anchor(F,B=1/0){const Y=j(F);return Y.kind==="box"?J.box:Y.kind==="line"?J.line(Y.n,B):Y.kind==="token"?J.token(Y.n,Y.text,Y.occurrence,B):J.spot(Y.n,Y.column,Y.width,B)},edit(F,B,Y){const R=()=>V(F,B,"line").map(K=>K.n);if(F==="highlight")return J.highlight(R(),Y);if(F==="strike")return J.strike(R(),Y);if(F==="remove")return J.remove(R(),Y);if(F==="type"){for(const K of R())J.type(K,Y);return J}if(F==="insert"){const[K]=V(F,B,"spot",!0);return J.insert(K.n,K.column,tt(F,Y),Y)}if(F==="write"||F==="drop"||F==="move"||F==="fling"){const[K]=V(F,B,"token",!0),st=J.piece(K.n,K.text,K.occurrence);if(F==="write")return J.write(st,tt(F,Y),Y);if(F==="fling")return J.fling(st,Y);if(F==="drop"){const C=typeof Y.into=="string"?j(Y.into):void 0;if(C?.kind!=="spot")throw new Error("codePanel.edit: drop needs `into`, a spot anchor (spot:N:C)");return J.drop(st,C.n,C.column,Y)}const $=typeof Y.to=="string"?J.anchor(Y.to,Y.at):Y.to;if(!$||typeof $.x!="number"||typeof $.y!="number")throw new Error("codePanel.edit: move needs `to`, an anchor name or { x, y }");return J.move(st,{...Y,to:$})}throw Vi("codePanel",F,Ji)}};return J}function gT(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 r=dT*n;if(r>.2&&"filter"in t&&(t.filter=`blur(${r.toFixed(1)}px)`),t.globalAlpha*=1-n,e.style==="fly"){const o=e.from==="right"?-1:1;t.translate(o*n*uT*i,0),t.rotate(o*n*.08)}else{const o=1+.08*n,a=s.left+s.width/2,l=s.top+s.height/2;t.translate(a,l),t.scale(o,o),t.translate(-a,-l)}}const bh={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 mT(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(([r])=>r.test(s));i&&(n[s]=i[1])}return n}function Yp(t,e,n,s,i,r){t.beginPath(),t.moveTo(e+r,n),t.arcTo(e+s,n,e+s,n+i,r),t.arcTo(e+s,n+i,e,n+i,r),t.arcTo(e,n+i,e,n,r),t.arcTo(e,n,e+s,n,r),t.closePath()}const Ko={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:[]};Ko.typescript=[...Ko.javascript,"enum","interface","type","implements","private","public","readonly","keyof","as","declare","namespace"];const Yo=Object.keys(Ko),pT={go:"//",rust:"//",csharp:"//",javascript:"//",typescript:"//",python:"#",plain:null};function Xp(t,e){const n=new Set(Ko[e]),s=pT[e],i=[],r=(a,l)=>{const c=i[i.length-1];c&&c.kind===l?c.text+=a:i.push({text:a,kind:l})};let o=0;for(;o<t.length;){const a=t[o];if(e!=="plain"&&s&&t.startsWith(s,o)){r(t.slice(o),"comment");break}if(e!=="plain"&&(a==='"'||a==="'"||a==="`")){let h=o+1;for(;h<t.length&&t[h]!==a;)h+=t[h]==="\\"?2:1;r(t.slice(o,h+1),"string"),o=h+1;continue}const l=/^[A-Za-z_][A-Za-z0-9_]*/.exec(t.slice(o));if(l){r(l[0],n.has(l[0])?"keyword":"text"),o+=l[0].length;continue}const c=/^\d[\d_.]*/.exec(t.slice(o));if(c&&e!=="plain"){r(c[0],"number"),o+=c[0].length;continue}r(a,"text"),o++}return i}const wh='"Patrick Hand", "Segoe Print", "Bradley Hand", "Comic Sans MS", "Chalkboard SE", cursive',Zi={whiteboard:{background:"#f7f7f2",frame:"#b8bcc4",ink:"#1f2a44",colors:{ink:"#1f2a44",red:"#d03b3b",blue:"#2f6fd0",green:"#2e9a52",orange:"#e07b1a"},font:wh,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:wh,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:wh,stroke:.08,opacity:1,rule:{color:"#c9d6ec",spacing:1.55,margin:"#f0a3a3"}}},kh=["circle","box","underline","arrow"],je={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"}},Gp=90,Up=300,yT=.3;function bT(t){const e=typeof t.theme=="string"?t.theme:"whiteboard";if(!(e in Zi))throw new Error(`whiteboard: ${dt("theme",e,Object.keys(Zi))}`);const n=typeof t.theme=="object"?{...Zi.whiteboard,...t.theme}:Zi[e],s=t.fontSize??28,i=t.charWidth??.55,r=w=>w===void 0?n.ink:n.colors[w]??w,o=w=>St(t.x+w.left,t.y+w.top,w.width,w.height),a=_s(),l=Ui(a),c={},h=new Map,u=[],d=[],f=(w,S,x,M)=>{const E=h.get(w);if(!E||E.kind!=="text")throw gn("whiteboard",M,je,`there is no text "${w}" (texts: ${m().join(", ")||"none"})`);let T=-1;for(let P=0;P<x;P++)if(T=E.item.text.indexOf(S,T+1),T<0)throw gn("whiteboard",M,je,`text "${w}" has no ${x>1?`${x}th `:""}"${S}"`);const A=E.size*i;return{column:T,box:St(E.box.left+T*A,E.box.top,S.length*A,E.box.height)}},m=()=>[...h.values()].filter(w=>w.kind==="text").map(w=>w.item.id),g=w=>{const{kind:S,rest:x}=jn(w),M=E=>gn("whiteboard",w,je,E);if(S==="box"){if(x)throw M("box takes no arguments");return{kind:S}}if(S==="text"||S==="mark"){if(!x)throw M(`write it ${S}:ID`);return{kind:S,id:x}}if(S==="term"){const E=/^([^:#]+)(?:#(\d+))?:(.+)$/.exec(x);if(!E)throw M("write it term:ID:TEXT, or term:ID#K:TEXT for the Kth");return{kind:S,id:E[1],occurrence:E[2]?Number(E[2]):1,text:E[3]}}throw M()},p=w=>{const S=g(w);if(S.kind==="box")return St(0,0,t.width,t.height);if(S.kind==="term")return f(S.id,S.text,S.occurrence,w).box;const x=h.get(S.id);if(!x||x.kind!==S.kind){const M=[...h.values()].filter(E=>E.kind===S.kind).map(E=>E.item.id);throw gn("whiteboard",w,je,`there is no ${S.kind} "${S.id}" (${S.kind}s: ${M.join(", ")||"none"})`)}return x.box};for(const w of t.items??[]){if(!w||typeof w.id!="string"||!w.id||/[:#]/.test(w.id))throw new Error(`whiteboard: every item needs an \`id\` without ":" or "#" (got ${JSON.stringify(w?.id)})`);if(h.has(w.id))throw new Error(`whiteboard: two items are called "${w.id}"`);if("text"in w){if(!Array.isArray(w.at)||w.at.length!==2||!w.at.every(P=>typeof P=="number"))throw new Error(`whiteboard: text "${w.id}" needs \`at\`, [x, y] from the board's top-left`);const T=w.size??s,A=St(w.at[0],w.at[1],Math.max(1,w.text.length)*T*i,T*1.3);h.set(w.id,{kind:"text",item:w,size:T,color:r(w.color),box:A}),c[`text.${w.id}.write`]=w.hidden?0:1,c[`text.${w.id}.erase`]=0;continue}if(!kh.includes(w.mark))throw new Error(`whiteboard: mark "${w.id}": ${dt("mark",w.mark,kh)}`);const S=w.mark==="arrow"?["from","to"]:["around"];for(const T of S)if(typeof w[T]!="string")throw new Error(`whiteboard: ${w.mark} "${w.id}" needs \`${T}\`, a place on the board (an item before it)`);const x=new Set([w.from,w.to].filter(T=>typeof T=="string").map(T=>T.split(":")[1])),M=w.mark==="arrow"?[...h.values()].filter(T=>T.kind==="text"&&!x.has(T.item.id)).map(T=>T.box):[],E=wT(w,p,s,M);h.set(w.id,{kind:"mark",item:w,color:r(w.color),points:E,box:MT(E)}),c[`mark.${w.id}.draw`]=w.hidden?0:1,c[`mark.${w.id}.erase`]=0}const b=w=>u.filter(S=>S.item===w),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 ST(Object.keys(c))},actions:je.edits},draw(w,S){const x=S.props??{},M=E=>Number(x[E]??c[E]??0);if(w.save(),w.fillStyle=n.background,Zp(w,0,0,t.width,t.height,10),w.fill(),w.lineWidth=Math.max(4,t.width*.012),w.strokeStyle=n.frame,w.stroke(),n.rule){w.save(),w.beginPath(),Zp(w,0,0,t.width,t.height,10),w.clip(),w.lineWidth=1,w.strokeStyle=n.rule.color;const E=s*(n.rule.spacing??1.55);for(let T=E;T<t.height;T+=E)w.beginPath(),w.moveTo(0,T),w.lineTo(t.width,T),w.stroke();n.rule.margin&&(w.strokeStyle=n.rule.margin,w.beginPath(),w.moveTo(s*2.2,0),w.lineTo(s*2.2,t.height),w.stroke()),w.restore()}w.textAlign="center",w.textBaseline="middle",w.lineCap="round",w.lineJoin="round",w.globalAlpha=n.opacity;for(const E of h.values()){if(w.save(),vh(w,E.box,M(`${E.kind}.${E.item.id}.erase`)),E.kind==="text"){const T=b(E.item.id),A=M(`text.${E.item.id}.write`)*E.item.text.length;w.font=`${E.size}px ${n.font}`,w.fillStyle=E.color;for(let P=0;P<Math.ceil(A);P++)E.item.text[P]===" "||T.some(I=>P>=I.column&&P<I.column+I.text.length)||(w.globalAlpha=n.opacity*Math.min(1,A-P),w.fillText(E.item.text[P],E.box.left+(P+.5)*E.size*i,E.box.y))}else Jp(w,E.points,M(`mark.${E.item.id}.draw`),E.color,s*n.stroke,E.item.mark==="arrow");w.restore()}for(const E of d){const T=M(`strike.${E.id}.draw`);if(T<=0)continue;const{box:A}=E,P=A.height*.15;Jp(w,[{x:A.left-3,y:A.y+P},{x:A.right+3,y:A.y-P}],T,n.colors.red??n.ink,s*n.stroke*.8,!1)}for(const E of u){const T=h.get(E.item),A=T.size*i;w.font=`${T.size}px ${n.font}`,w.fillStyle=T.color;const P=E.written;if(P){const L=M(`piece.${E.id}.write`)*P.length,j=E.home.x-t.x-P.length*A/2;for(let V=0;V<Math.ceil(L);V++)P[V]!==" "&&(w.globalAlpha=n.opacity*Math.min(1,L-V),w.fillText(P[V],j+(V+.5)*A,E.home.y-t.y))}const I=M(`piece.${E.id}.opacity`)*Math.min(1,M(`text.${E.item}.write`)*T.item.text.length-E.column);if(I<=0)continue;w.save();const O={x:E.home.x-t.x,y:E.home.y-t.y},_={x:M(`piece.${E.id}.x`),y:M(`piece.${E.id}.y`)};vh(w,St(O.x+_.x-E.home.width/2,O.y+_.y-E.home.height/2,E.home.width,E.home.height),M(`piece.${E.id}.erase`)),Math.hypot(_.x,_.y)<1&&vh(w,T.box,M(`text.${E.item}.erase`)),w.globalAlpha=n.opacity*Math.min(1,I),w.translate(O.x+_.x,O.y+_.y),w.rotate(M(`piece.${E.id}.rotate`)*Math.PI/180);for(let L=0;L<E.text.length;L++)E.text[L]!==" "&&w.fillText(E.text[L],(L+.5-E.text.length/2)*A,0);w.restore()}w.restore()}},k={kind:"board",about:je,target:v,box:St(t.x,t.y,t.width,t.height),anchor(w){return o(p(w))},piece(w){const S=g(w);if(S.kind!=="term")throw new Error(`whiteboard.piece: a piece is a term, term:ID:TEXT, not "${w}"`);const{column:x,box:M}=f(S.id,S.text,S.occurrence,w),E=u.find(A=>A.item===S.id&&A.column===x&&A.text===S.text);if(E)return E;if(u.some(A=>A.item===S.id&&x<A.column+A.text.length&&A.column<x+S.text.length))throw new Error(`whiteboard: "${S.text}" in "${S.id}" overlaps another piece`);const T={id:u.length+1,item:S.id,column:x,text:S.text,home:o(M)};u.push(T);for(const A of["x","y","rotate","erase","write"])c[`piece.${T.id}.${A}`]=0;return c[`piece.${T.id}.opacity`]=1,T},edit(w,S,x){const M=Array.isArray(S)?S:[S];if(M.length===0)throw new Error(`whiteboard.edit: ${w} takes at least one anchor`);const E=M.map(P=>({name:P,anchor:g(P)}));for(const{name:P}of E)p(P);const T=(P,I=!1)=>{const O=E.find(_=>!P.includes(_.anchor.kind));if(O)throw new Error(`whiteboard.edit: ${w} takes ${P.join(" or ")} anchors, not "${O.name}"`);if(I&&E.length>1)throw new Error(`whiteboard.edit: ${w} takes one ${P.join(" or ")} anchor`)},A=()=>k.piece(E[0].name);if(w==="write"){if(E.some(P=>P.anchor.kind==="term")){if(T(["term"],!0),typeof x.text!="string")throw new Error("whiteboard.edit: write into a term needs `text` (the new text)");const P=A();return P.written=x.text,a.tween(`piece.${P.id}.write`,0,1,{duration:Math.max(Up,x.text.length*Gp),...x}),k}T(["text"]);for(const{anchor:P}of E){const I=P.id,O=h.get(I).item.text;a.tween(`text.${I}.write`,0,1,{duration:Math.max(Up,O.length*Gp),...x})}return k}if(w==="draw"){T(["mark"]);for(const{anchor:P}of E)a.tween(`mark.${P.id}.draw`,0,1,{duration:500,...x});return k}if(w==="erase"){T(["text","term","mark"]);for(const P of E){const I=P.anchor.kind==="term"?`piece.${k.piece(P.name).id}.erase`:`${P.anchor.kind}.${P.anchor.id}.erase`;a.tween(I,0,1,{duration:400,...x})}return k}if(w==="strike"){T(["text","term"]);for(const P of E){const I={id:d.length+1,box:p(P.name)};d.push(I),c[`strike.${I.id}.draw`]=0,a.tween(`strike.${I.id}.draw`,0,1,{duration:250,...x})}return k}if(w==="move"){T(["term"],!0);const P=typeof x.to=="string"?k.anchor(x.to):x.to;if(!P||typeof P.x!="number"||typeof P.y!="number")throw new Error("whiteboard.edit: move needs `to`, an anchor name or { x, y }");return k.move(A(),{...x,to:P})}if(w==="fling")return T(["term"],!0),k.fling(A(),x);throw Vi("whiteboard",w,je)},follow(w,S){return l.follow(w,S),k},fling(w,S){return l.fling(w,S),k},move(w,S){return l.move(w,S),k},ride(w){return w},tracks:a.tracks};return k}function wT(t,e,n,s=[]){const i=Se(re(t.id)),r=g=>(i.next()*2-1)*g,o=n*yT;if(t.mark==="arrow"){const g=e(t.from),p=e(t.to),b=Vp(g,p,o*.6),v=Vp(p,g,o*.6),k=Math.hypot(v.x-b.x,v.y-b.y),w=vT(b,v);let S=k*(.06+r(.04));if(t.bend!==void 0)S=k*t.bend;else{const E=kT(b,v,w,s,o);E!==0&&(S=E)}const x={x:(b.x+v.x)/2+w.x*S,y:(b.y+v.y)/2+w.y*S},M=[];for(let E=0;E<=24;E++){const T=E/24;M.push({x:(1-T)**2*b.x+2*(1-T)*T*x.x+T*T*v.x,y:(1-T)**2*b.y+2*(1-T)*T*x.y+T*T*v.y})}return M}const a=e(t.around);if(t.mark==="underline"){const g=a.bottom+o*.4;return[{x:a.left-o*.3,y:g+r(2)},{x:a.x,y:g+2+r(2)},{x:a.right+o*.5,y:g-1+r(3)}]}if(t.mark==="box"){const g=a.left-o,p=a.right+o,b=a.top-o*.6,v=a.bottom+o*.6,k=(S,x)=>({x:S+r(o*.2),y:x+r(o*.2)}),w=k(g,b);return[w,k(p,b),k(p,v),k(g,v),w,{x:w.x+o*.8,y:w.y+r(2)}]}const l=a.width/2+o,c=a.height/2+o*.6,h=-2.2+r(.3),u=i.next()*Math.PI*2,d=1.12,f=64,m=[];for(let g=0;g<=f*d;g++){const p=g/f,b=h+p*Math.PI*2,v=1+.035*Math.sin(p*Math.PI*4+u)+.06*p;m.push({x:a.x+Math.cos(b)*l*v,y:a.y+Math.sin(b)*c*v})}return m}function kT(t,e,n,s,i){const r=Math.hypot(e.x-t.x,e.y-t.y);if(r<1e-6)return 0;const o={x:(e.x-t.x)/r,y:(e.y-t.y)/r};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(m=>({t:(m.x-t.x)*o.x+(m.y-t.y)*o.y,n:(m.x-t.x)*n.x+(m.y-t.y)*n.y})),d=u.some(m=>m.t>0&&m.t<r),f=u.some(m=>m.n>0)&&u.some(m=>m.n<0);!d||!f||(a=Math.max(a,...u.map(m=>m.n)),l=Math.min(l,...u.map(m=>m.n)))}return a===0&&l===0?0:a<=-l?2*(a+i):2*(l-i)}function Vp(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 r=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*r,y:t.y+i*r}}function vT(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 MT(t){const e=t.map(r=>r.x),n=t.map(r=>r.y),s=Math.min(...e),i=Math.min(...n);return St(s,i,Math.max(...e)-s,Math.max(...n)-i)}function Jp(t,e,n,s,i,r){if(n<=0||e.length<2)return;const o=[0];for(let m=1;m<e.length;m++)o.push(o[m-1]+Math.hypot(e[m].x-e[m-1].x,e[m].y-e[m-1].y));const l=o[o.length-1]*Math.min(1,n/(r?.85:1));t.strokeStyle=s,t.lineWidth=i,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let m=1;m<e.length;m++){if(o[m]<=l){t.lineTo(e[m].x,e[m].y);continue}const g=(l-o[m-1])/(o[m]-o[m-1]||1);t.lineTo(e[m-1].x+(e[m].x-e[m-1].x)*g,e[m-1].y+(e[m].y-e[m-1].y)*g);break}if(t.stroke(),!r||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 m of[-1,1])t.moveTo(h.x,h.y),t.lineTo(h.x-Math.cos(d+m*.45)*f,h.y-Math.sin(d+m*.45)*f);t.stroke()}function vh(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 Zp(t,e,n,s,i,r){t.beginPath(),t.moveTo(e+r,n),t.arcTo(e+s,n,e+s,n+i,r),t.arcTo(e+s,n+i,e,n+i,r),t.arcTo(e,n+i,e,n,r),t.arcTo(e,n,e+s,n,r),t.closePath()}function ST(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(([r])=>r.test(s));i&&(n[s]=i[1])}return n}const Mh=["bar","line","pie","donut"],Qp='system-ui, -apple-system, "Segoe UI", sans-serif',Qi={light:{background:"#ffffff",text:"#3b4252",grid:"#d8dee9",color:"#4c7bd9",highlight:"#e8833a",palette:["#4c7bd9","#3fa66b","#b05cc9","#d9c04c","#4cb8c4","#d95c6f","#8a7a5a","#6b7a99"],font:Qp},dark:{background:"#1e2230",text:"#cdd6f4",grid:"#3a4055",color:"#89b4fa",highlight:"#fab387",palette:["#89b4fa","#a6e3a1","#cba6f7","#f9e2af","#94e2d5","#f38ba8","#b4a58a","#9399b2"],font:Qp}},Kn={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)"}},TT=600,ET=500,AT=200,xT=400,PT=.14,$T=Math.PI*2;function IT(t){if(!Mh.includes(t.kind))throw new Error(`chart: ${dt("kind",t.kind,Mh)}`);const e=typeof t.theme=="string"?t.theme:"light";if(!(e in Qi))throw new Error(`chart: ${dt("theme",e,Object.keys(Qi))}`);const n=typeof t.theme=="object"?{...Qi.light,...t.theme}:Qi[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",r=Array.isArray(t.series)&&t.series.length>1,o=Array.isArray(t.series)&&t.series.length>0?t.series:[{id:"value"}];if(i&&r)throw new Error(`chart: a ${s} shows one series (got ${o.length}); make a chart per series`);const a=new Set;for(const H of o){if(typeof H?.id!="string"||!H.id||/[:.]/.test(H.id))throw new Error(`chart: every series needs an \`id\` without ":" or "." (got ${JSON.stringify(H?.id)})`);if(a.has(H.id))throw new Error(`chart: two series are called "${H.id}"`);a.add(H.id)}const l=new Map(o.map((H,U)=>[H.id,U])),c=H=>o[l.get(H)].color??(l.get(H)===0?n.color:n.palette[l.get(H)%n.palette.length]),h=new Set,u=(H,U)=>{const nt=H.values?.[U.id]??(t.series?void 0:H.value)??H.value;if(typeof nt!="number"||!Number.isFinite(nt))throw new Error(r?`chart: "${H.id}" needs a value for series "${U.id}" (\`values: { ${U.id}: … }\`)`:`chart: "${H.id}" needs a \`value\`, a number`);return nt};for(const H of t.data){if(typeof H?.id!="string"||!H.id||/[:.]/.test(H.id))throw new Error(`chart: every datum needs an \`id\` without ":" or "." (got ${JSON.stringify(H?.id)})`);if(h.has(H.id))throw new Error(`chart: two data are called "${H.id}"`);for(const U of o)u(H,U);h.add(H.id)}const d=s==="bar"?"bar":s==="line"?"point":"slice",f=Math.max(...t.data.flatMap(H=>o.map(U=>u(H,U)))),m=i?t.data.reduce((H,U)=>H+u(U,o[0]),0):t.max??ty(f*1.1);if(!i&&!(m>0))throw new Error(`chart: \`max\` must be above 0 (got ${m})`);const g=Math.max(10,Math.min(16,t.height/20)),p=r&&t.legend!==!1,b=i?void 0:t.axis?.x,v=i?void 0:t.axis?.y,k=t.title?g*2.3:g*.5,w={left:g*3.6+(v?g*1.5:0),right:t.width-g,top:(t.title?g*3:g*1.6)+(p?g*1.6:0),bottom:t.height-g*2.4-(b?g*1.4:0)},S=w.bottom-w.top,x=(w.right-w.left)/t.data.length,M=r?x*.72/o.length:x*.6,E=r?M*.86:M,T=Math.max(4,g*.35),A=S/m,P=new Map(t.data.map((H,U)=>[H.id,U])),I=H=>w.left+x*(P.get(H)+.5),O=(H,U)=>r?I(H)-x*.36+M*l.get(U)+(M-E)/2:I(H)-E/2,_=(H,U)=>O(H,U)+E/2,L=t.height-g*1.2,j={cx:t.width/2,cy:(w.top+L)/2,r:Math.max(10,Math.min(t.width/2,(L-w.top)/2)-g*2.6)},V=s==="donut"?j.r*.55:0,tt=s==="donut"?(V+j.r)/2:j.r*.62,J=new Map;if(p){let H=w.right;for(const U of[...o].reverse()){const nt=U.label??U.id,at=g*.62*nt.length+g*1.9;J.set(U.id,St(H-at,k,at,g*1.4)),H-=at+g*.6}}const F=_s(),B=Ui(F),Y={},R=(H,U,nt)=>r?`${d}.${H}.${U}.${nt}`:`${d}.${H}.${nt}`;for(const H of t.data)for(const U of o)Y[R(H.id,U.id,"value")]=u(H,U),Y[R(H.id,U.id,"show")]=H.hidden?0:1,Y[R(H.id,U.id,"highlight")]=0,i&&(Y[R(H.id,U.id,"pull")]=0);const K=(H,U)=>F.keys(H)?.length?zo(F.keys(H),U):Y[H],st=(H,U,nt)=>K(R(H,U,"value"),nt)*(s==="bar"?K(R(H,U,"show"),nt):1)*A,$=H=>{const U=o[0].id,nt=t.data.map(it=>Math.max(0,H(R(it.id,U,"value")))*Math.max(0,Math.min(1,H(R(it.id,U,"show"))))),at=nt.reduce((it,Q)=>it+Q,0),rt=new Map;let ct=-Math.PI/2;return t.data.forEach((it,Q)=>{const ot=at>0?$T*nt[Q]/at:0,ht=ct+ot/2,ft=Math.max(0,Math.min(1,H(R(it.id,U,"pull"))))*j.r*PT;rt.set(it.id,{start:ct,sweep:ot,mid:ht,out:ft,centre:{x:j.cx+Math.cos(ht)*(tt+ft),y:j.cy+Math.sin(ht)*(tt+ft)}}),ct+=ot}),rt},C=H=>$(U=>K(U,H)),z=H=>{const{kind:U,rest:nt}=jn(H),at=rt=>gn("chart",H,Kn,rt);if(U==="box"){if(nt)throw at("box takes no arguments");return{kind:"box"}}if(U==="legend"){if(!J.has(nt))throw at(p?`there is no series "${nt}" (series: ${o.map(rt=>rt.id).join(", ")})`:"only a chart with several series has a legend");return{kind:"legend",series:nt}}if(U==="bar"||U==="point"||U==="slice"||U==="label"||U==="value"){if(!nt)throw at(`write it ${U}:ID`);const rt=nt.indexOf(":"),ct=rt<0?nt:nt.slice(0,rt),it=rt<0?o[0].id:nt.slice(rt+1);if(!P.has(ct))throw at(`there is no "${ct}" (data: ${[...P.keys()].join(", ")})`);if(!a.has(it))throw at(`there is no series "${it}" (series: ${o.map(Q=>Q.id).join(", ")})`);if(U==="label"&&rt>=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:it}}throw at()},X=(H,U)=>{if(H.kind==="box")return St(0,0,t.width,t.height);if(H.kind==="legend")return J.get(H.series);if(i){const it=C(U).get(H.id),Q=Math.max(g*1.5,j.r*.42);if(H.kind==="slice")return St(it.centre.x-Q/2,it.centre.y-Q/2,Q,Q);const ot=W(it);return H.kind==="label"?ot:it.sweep>=.3?St(it.centre.x-g*1.6,it.centre.y-g*.65,g*3.2,g*1.3):St(ot.left,ot.bottom,ot.width,g*1.3)}const nt=H.kind==="label"?I(H.id):_(H.id,H.series),at=w.bottom-st(H.id,H.series,U);if(H.kind==="bar")return St(nt-E/2,at,E,w.bottom-at);if(H.kind==="point")return St(I(H.id)-T,at-T,T*2,T*2);if(H.kind==="label")return St(nt-x/2,w.bottom+g*.4,x,g*1.4);const rt=at-(s==="line"?T:0)-g*.3,ct=r&&s==="bar"?M:x;return St((s==="line"?I(H.id):nt)-ct/2,rt-g*1.3,ct,g*1.3)},W=H=>{const U=j.r+H.out+g*.9,nt={x:j.cx+Math.cos(H.mid)*U,y:j.cy+Math.sin(H.mid)*U},at=g*4.2,rt=Math.cos(H.mid),ct=rt>.2?nt.x:rt<-.2?nt.x-at:nt.x-at/2;return St(ct,nt.y-g*.7,at,g*1.4)},N=H=>St(t.x+H.left,t.y+H.top,H.width,H.height),D=H=>`${t.prefix??""}${H.toFixed(t.decimals??0)}${t.suffix??""}`,G=new Map,q={type:"custom",x:t.x,y:t.y,width:t.width,height:t.height,props:Y,about:{kind:`${s} chart`,summary:`A ${s} chart of ${t.data.length} values (${t.data.map(H=>H.id).join(", ")})${r?` in ${o.length} series (${o.map(H=>H.id).join(", ")})`:""}${i?"":`, scaled to ${m}`}. Its ${d}s and labels are places in the scene (anchor()); its edits record tracks (edit(), tracks()).`,props:Object.fromEntries(Object.keys(Y).map(H=>[H,_T(H)])),actions:Kn.edits},draw(H,U){const nt=U.props??{},at=it=>Number(nt[it]??Y[it]??0);if(H.save(),H.fillStyle=n.background,ey(H,0,0,t.width,t.height,8),H.fill(),H.font=`${g}px ${n.font}`,H.textBaseline="middle",t.title&&(H.fillStyle=n.text,H.textAlign="left",H.font=`600 ${g*1.2}px ${n.font}`,H.fillText(t.title,i?g:w.left,g*1.5),H.font=`${g}px ${n.font}`),p){H.textAlign="left";for(const it of o){const Q=J.get(it.id);H.fillStyle=c(it.id),ey(H,Q.left,Q.top+g*.25,g*.9,g*.9,2),H.fill(),H.fillStyle=n.text,H.fillText(it.label??it.id,Q.left+g*1.3,Q.top+Q.height/2)}}if(i){Z(H,at),H.restore();return}H.lineWidth=1,H.textAlign="right";for(let it=0;it<=4;it++){const Q=w.bottom-S*it/4;H.strokeStyle=n.grid,H.beginPath(),H.moveTo(w.left,Q),H.lineTo(w.right,Q),H.stroke(),H.fillStyle=n.text,H.globalAlpha=.7,H.fillText(OT(m*it/4),w.left-g*.5,Q),H.globalAlpha=1}(v||b)&&(H.fillStyle=n.text,H.textAlign="center",H.globalAlpha=.85,v&&(H.save(),H.translate(g*.9,(w.top+w.bottom)/2),H.rotate(-Math.PI/2),H.fillText(v,0,0),H.restore()),b&&H.fillText(b,(w.left+w.right)/2,w.bottom+g*2.3),H.globalAlpha=1);const rt=(it,Q)=>at(R(it,Q,"value"))*(s==="bar"?at(R(it,Q,"show")):1)*A,ct=(it,Q)=>Sh(c(Q),n.highlight,at(R(it,Q,"highlight")));if(s==="line"){H.lineWidth=Math.max(2,g*.2),H.lineJoin="round",H.lineCap="round";for(const it of o)H.strokeStyle=c(it.id),H.beginPath(),t.data.forEach((Q,ot)=>{const ht={x:I(Q.id),y:w.bottom-rt(Q.id,it.id)},ft=at(R(Q.id,it.id,"show"));if(ot===0){ft>0&&H.moveTo(ht.x,ht.y);return}const bt=t.data[ot-1];if(at(R(bt.id,it.id,"show"))<1||ft<=0)return;const wt={x:I(bt.id),y:w.bottom-rt(bt.id,it.id)};H.lineTo(wt.x+(ht.x-wt.x)*ft,wt.y+(ht.y-wt.y)*ft)}),H.stroke()}H.textAlign="center";for(const it of t.data){for(const Q of o){const ot=s==="bar"?_(it.id,Q.id):I(it.id),ht=rt(it.id,Q.id),ft=at(R(it.id,Q.id,"show"));if(H.fillStyle=ct(it.id,Q.id),s==="bar"?ht>.5&&(CT(H,ot-E/2,w.bottom-ht,E,ht,Math.min(6,E/4)),H.fill()):ft>0&&(H.beginPath(),H.arc(ot,w.bottom-ht,T*Math.min(1,ft*1.5)*(1+.3*at(R(it.id,Q.id,"highlight"))),0,Math.PI*2),H.fill()),t.values!==!1&&ft>0){H.globalAlpha=Math.min(1,ft*2),H.font=`600 ${r?g*.85:g}px ${n.font}`,H.fillStyle=Sh(n.text,n.highlight,at(R(it.id,Q.id,"highlight")));const bt=w.bottom-ht-(s==="line"?T:0)-g*.95;H.fillText(D(at(R(it.id,Q.id,"value"))),ot,bt),H.font=`${g}px ${n.font}`,H.globalAlpha=1}}H.fillStyle=n.text,H.fillText(it.label??it.id,I(it.id),w.bottom+g*1.1)}H.strokeStyle=n.text,H.lineWidth=1.5,H.beginPath(),H.moveTo(w.left,w.bottom),H.lineTo(w.right,w.bottom),H.stroke(),H.restore()}};function Z(H,U){const nt=o[0].id,at=$(U);t.data.forEach((rt,ct)=>{const it=at.get(rt.id);if(it.sweep<=1e-4)return;const Q=G.get(rt.id),ot=Q?{x:U(`piece.${Q.id}.x`),y:U(`piece.${Q.id}.y`)}:{x:0,y:0},ht=Q?U(`piece.${Q.id}.rotate`)*Math.PI/180:0,ft=Q?U(`piece.${Q.id}.opacity`):1;if(ft<=0)return;H.save(),H.globalAlpha=ft;const bt={x:j.cx+Math.cos(it.mid)*it.out,y:j.cy+Math.sin(it.mid)*it.out};H.translate(it.centre.x+ot.x,it.centre.y+ot.y),H.rotate(ht),H.translate(-it.centre.x,-it.centre.y),H.beginPath(),H.arc(bt.x,bt.y,j.r,it.start,it.start+it.sweep),V>0?H.arc(bt.x,bt.y,V,it.start+it.sweep,it.start,!0):H.lineTo(bt.x,bt.y),H.closePath(),H.fillStyle=Sh(n.palette[ct%n.palette.length],n.highlight,U(R(rt.id,nt,"highlight"))),H.fill(),H.strokeStyle=n.background,H.lineWidth=Math.max(1.5,g*.15),H.stroke(),t.values!==!1&&it.sweep>=.3&&(H.fillStyle=n.background,H.font=`600 ${g}px ${n.font}`,H.textAlign="center",H.fillText(D(U(R(rt.id,nt,"value"))),it.centre.x,it.centre.y),H.font=`${g}px ${n.font}`),H.restore();const wt=W(it),Me=Math.cos(it.mid);H.globalAlpha=ft,H.fillStyle=n.text,H.textAlign=Me>.2?"left":Me<-.2?"right":"center";const gr=Me>.2?wt.left:Me<-.2?wt.right:wt.left+wt.width/2;H.fillText(rt.label??rt.id,gr,wt.top+wt.height/2),t.values!==!1&&it.sweep<.3&&(H.globalAlpha=ft*.8,H.fillText(D(U(R(rt.id,nt,"value"))),gr,wt.bottom+g*.65)),H.globalAlpha=1})}const et={kind:"chart",chartKind:s,about:Kn,target:q,max:m,box:St(t.x,t.y,t.width,t.height),anchor(H,U=1/0){return N(X(z(H),U))},piece(H){const U=z(H);if(U.kind!=="slice")throw new Error(i?`chart: a piece is a slice, slice:ID, not "${H}"`:`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 nt=G.get(U.id);if(nt)return nt;const at={id:G.size+1,datum:U.id,home:N(X(U,0))};G.set(U.id,at);for(const rt of["x","y","rotate"])Y[`piece.${at.id}.${rt}`]=0;return Y[`piece.${at.id}.opacity`]=1,at},edit(H,U,nt){const at=Array.isArray(U)?U:[U];if(at.length===0)throw new Error(`chart.edit: ${H} takes at least one anchor`);if(!(H in Kn.edits))throw Vi("chart",H,Kn);if(H==="pull"&&!i)throw new Error(`chart.edit: pull takes slice anchors of a pie or donut; a ${s} chart has ${d}s`);const rt=at.map(ct=>{const it=z(ct);if(it.kind!==d)throw new Error(`chart.edit: ${H} takes ${d} anchors (${d}:ID), not "${ct}"`);return it});for(const{id:ct,series:it}of rt){const Q=ot=>R(ct,it,ot);if(H==="set"){if(typeof nt.value!="number"||!Number.isFinite(nt.value))throw new Error("chart.edit: set needs `value`, a number");F.tween(Q("value"),K(Q("value"),nt.at),nt.value,nt,TT)}else H==="show"?F.tween(Q("show"),K(Q("show"),nt.at),nt.on===!1?0:1,nt,ET):H==="pull"?F.tween(Q("pull"),K(Q("pull"),nt.at),nt.on===!1?0:1,nt,xT):F.tween(Q("highlight"),K(Q("highlight"),nt.at),nt.on===!1?0:1,nt,AT)}return et},follow(H,U){return B.follow(H,U),et},fling(H,U){return B.fling(H,U),et},move(H,U){return B.move(H,U),et},ride(H,U,nt){if(s!=="bar")return H;const at=t.data.flatMap(rt=>o.map(ct=>{const it=st(rt.id,ct.id,0),Q=[...Rs(F.keys(R(rt.id,ct.id,"value"))),...Rs(F.keys(R(rt.id,ct.id,"show")))];return{top:t.y+w.bottom-it,offset:ot=>it-st(rt.id,ct.id,ot),windows:Q}}));return qo(H,U,{ground:nt.ground,every:nt.every??fn,floors:at})},tracks:F.tracks};return et}function ty(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 OT(t){return Number.isInteger(t)?String(t):String(Number(t.toFixed(2)))}function Sh(t,e,n){if(n<=0)return t;if(n>=1)return e;const s=o=>[1,3,5].map(a=>parseInt(o.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,r]=[s(t),s(e)];return`#${i.map((o,a)=>Math.round(o+(r[a]-o)*n).toString(16).padStart(2,"0")).join("")}`}function ey(t,e,n,s,i,r){t.beginPath(),t.moveTo(e+r,n),t.arcTo(e+s,n,e+s,n+i,r),t.arcTo(e+s,n+i,e,n+i,r),t.arcTo(e,n+i,e,n,r),t.arcTo(e,n,e+s,n,r),t.closePath()}function CT(t,e,n,s,i,r){const o=Math.min(r,i);t.beginPath(),t.moveTo(e,n+i),t.lineTo(e,n+o),t.arcTo(e,n,e+o,n,o),t.lineTo(e+s-o,n),t.arcTo(e+s,n,e+s,n+o,o),t.lineTo(e+s,n+i),t.closePath()}function _T(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 ny(){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 tr={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}],measurements:{height:165,bust:86,underbust:72,waist:58,hip:88}},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:ny(),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:ny(),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 RT(t,e={}){if(!Object.prototype.hasOwnProperty.call(tr,t))throw new Error(`softCartoonCharacter: unknown actor '${t}'`);const n=tr[t],s={...n.body};return e.body?.measurements!==void 0&&delete s.torso,Ps({...n,...e,body:{...s,...e.body},face:{...n.face,...e.face}})}const sy={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"}}}},iy={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"}}}},ry={beanMan:{label:"Bean man",group:"bean",scale:1,options:{figure:"bean",hair:{style:"short",color:"#1f1f1f"}}},beanWoman:{label:"Bean woman",group:"bean",scale:.96,options:{figure:"bean",hair:{style:"bob",color:"#1f1f1f"},bean:{torso:.95}}},beanKid:{label:"Bean kid",group:"bean",scale:.72,options:{figure:"bean",headSize:.36,legLength:.9,armLength:.92,hair:{style:"spiky",color:"#1f1f1f"},bean:{shirt:"#f2b134",trousers:"#3d5a80",torso:.9}}},beanBoss:{label:"Bean boss",group:"bean",scale:1,options:{figure:"bean",hair:{style:"slickBack",color:"#4a4a4a"},facialHair:"shortMoustache",glasses:"square",bean:{shirt:"#5b7aa6",trousers:"#2b2f3a",sleeves:"long",torso:1.25}}},beanDetective:{label:"Bean detective",group:"bean",scale:1,options:{figure:"bean",hair:{style:"short",color:"#2a2a2a"},bean:{coat:"#b08a5a",fedora:"#5b4636",shades:!0,trousers:"#2b2f3a",shoes:"#1a1a1a"}}},beanStick:{label:"Bean stick figure",group:"bean",scale:1,options:{figure:"bean",bean:{limbs:"line"}}},beanSari:{label:"Bean woman in a sari",group:"bean",scale:.96,options:{figure:"bean",hair:{style:"lowBun",color:"#1f1f1f"},bean:{torso:1.05,shirt:"#7c2d12",sleeves:"short",skirt:"#c2410c",drape:"#ea580c",bangles:"#d4a017",shoes:"#7c2d12"}}}},Th={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:Fe.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:Fe.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:Fe.black},ears:!0,outfit:{shirt:"#9b5fc0",trousers:"#2f2f3a",sleeves:"long"}}},grandpa:{label:"Grandpa",group:"family",scale:.96,options:{build:"stocky",hair:{style:"receding",color:Fe.gray},facialHair:{style:"shortBoxed",color:Fe.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:Fe.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:Fe.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:Fe.blond},hat:"sunHat",ears:!0,outfit:{shirt:"#d64535",trousers:"#4f6b3a",sleeves:"long"}}},...sy,...iy,...ry};function HT(t,e=300,n={}){const s=Th[t];if(!s)throw new Error(`castMember: unknown cast member '${t}'`);return{...s.options,height:Math.round(e*s.scale),...n}}const er={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 FT(t,e,n){return er[t].spacing*Math.min(e.height,n.height)}const oy=.075;function LT(t,e,n,s={}){const i=er[t];if(!i)throw new Error(`meetHands: unknown meeting '${t}' (one of ${Object.keys(er).join(", ")})`);const[r,o]=e.x<=n.x?[e,n]:[n,e],a=s.view==="side",l=Math.min(r.character.height,o.character.height),c={x:(r.x+o.x)/2,y:-(s.height??i.height)*l},h=(p,b)=>{const v=b?a?1:.62:a?3:3.38;let k={...lt,...p.pose,turn:v,lean:(p.pose?.lean??0)+i.lean};const w=b?1:-1,S=(x,M,E)=>{k=qe(p.character,k,x,{x:c.x+M-p.x,y:c.y,depth:E})};if(t==="handOver"){const x=oy*l;S("arm.left",-w*x*.9,x),S("arm.right",-w*x*.9,-x)}else S("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(r,!0),d=h(o,!1),f=.03*l,m=(p,b)=>{const v=ke(p.character,b),k=t==="handOver"?["hand.left","hand.right"]:["hand.right"],w=t==="handOver"?oy*l+f:f;return k.every(S=>Math.abs(v.points[S].y-c.y)<f&&Math.abs(v.points[S].x+p.x-c.x)<w)},g=m(r,u)&&m(o,d);return e.x<=n.x?{a:u,b:d,point:c,reached:g}:{a:d,b:u,point:c,reached:g}}const Xo={spacing:.3,lean:10,tilt:8};function NT(t,e){return Xo.spacing*Math.min(t.height,e.height)}function WT(t,e,n={}){const[s,i]=t.x<=e.x?[t,e]:[e,t],r=n.view==="side",o=Math.min(s.character.height,i.character.height),a=(m,g,p)=>({over:{x:g.x-p*.02*o-m.x,y:-.72*o,depth:-.08*o},round:{x:g.x-p*.04*o-m.x,y:-.5*o,depth:.06*o}}),l=(m,g,p)=>{const b=p?r?1:.62:r?3:3.38,v=p?1:-1;let k={...lt,...m.pose,turn:b,lean:(m.pose?.lean??0)+Xo.lean,"head.tilt":(m.pose?.["head.tilt"]??0)+v*Xo.tilt};const{over:w,round:S}=a(m,g,v);return k=qe(m.character,k,"arm.right",w),k=qe(m.character,k,"arm.left",S),k},c=l(s,i,!0),h=l(i,s,!1),u=.05*o,d=(m,g,p,b)=>{const v=ke(m.character,b).points,{over:k,round:w}=a(m,g,p);return Math.hypot(v["hand.right"].x-k.x,v["hand.right"].y-k.y)<u&&Math.hypot(v["hand.left"].x-w.x,v["hand.left"].y-w.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 Yn={spacing:.32,low:.3,high:.5,helperLean:40,helperBend:16};function DT(t,e){return Yn.spacing*Math.min(t.height,e.height)}function BT(t,e,n,s={}){const i=Math.max(0,Math.min(1,n)),r=s.view==="side",o=t.x<=e.x,a=Math.min(t.character.height,e.character.height),l={x:(t.x+e.x)/2,y:-(Yn.low+(Yn.high-Yn.low)*i)*a},c=p=>p?r?1:.62:r?3:3.38;let h={...lt,...t.pose,turn:c(o),lean:(t.pose?.lean??0)+Yn.helperLean*(1-i)+4,bend:(t.pose?.bend??0)+Yn.helperBend*(1-i),"head.nod":18*(1-i)};h=qe(t.character,h,"arm.right",{x:l.x-t.x,y:l.y});const u={...Ae.sitFloor,...e.pose,turn:c(!o)},d={...lt,...e.pose,turn:c(!o)};let f=Xc(u,d,i);f=qe(e.character,f,"arm.right",{x:l.x-e.x,y:l.y});const m=.04*a,g=(p,b)=>{const v=ke(p.character,b).points["hand.right"];return Math.hypot(v.x+p.x-l.x,v.y-l.y)<m};return{helper:h,sitter:f,point:l,reached:g(t,h)&&g(e,f)}}const Eh=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 ay(t,e={}){if(!Object.prototype.hasOwnProperty.call(Eh,t))throw new Error(`outfitPreset: unknown category '${t}'`);const n={...Eh[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 zT=.7,qT=50,jT=1.2,KT=.8,YT=3,XT=30,GT=.8,UT=.6,Ah=(t,e)=>Math.max(-e,Math.min(e,t)),VT=["hair.swing","hair.trail","hair.lift"];function ly(t,e){const n=e.start??0,s=e.amount??1,i=Math.max(1e-6,e.headRadius);let r=NaN,o={x:0,y:0,turn:0};const a=f=>(f!==r&&(o=t(f),r=f),o),l=f=>{const m=a(f);return m.turn*90+(m.headTurn??0)},c={start:n,end:e.end,step:e.step,stiffness:e.stiffness??70,damping:e.damping??6},h=li(l,c),u=li(f=>a(f).x,c),d=li(f=>a(f).y,c);return h.map((f,m)=>{const g=a(f.time),p=f.value-l(f.time),b=u[m].value-g.x-(e.wind??0)*zT*i,v=d[m].value-g.y,k=Math.sin(g.turn*Math.PI/2),w=Math.cos(g.turn*Math.PI/2),S=p*YT+b*w/i*XT,x=-b*k/i*GT,M=-v/i*UT;return{time:f.time,swing:Ah(S*s,qT),trail:Ah(x*s,jT),lift:Ah(M*s,KT)}})}function JT(t,e){if(t.length===0)return{"hair.swing":0,"hair.trail":0,"hair.lift":0};if(e<=t[0].time)return cy(t[0]);if(e>=t[t.length-1].time)return cy(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],r=t[s],o=r.time===i.time?0:(e-i.time)/(r.time-i.time);return{"hair.swing":i.swing+(r.swing-i.swing)*o,"hair.trail":i.trail+(r.trail-i.trail)*o,"hair.lift":i.lift+(r.lift-i.lift)*o}}const cy=t=>({"hair.swing":t.swing,"hair.trail":t.trail,"hair.lift":t.lift}),Hs=16,ZT=1500;function QT(t,e,n,s={}){const i=n.head.hair;if(!i||!zg(i))return[];const r=e.filter(v=>v.target===t),o=r.reduce((v,k)=>k.keyframes.reduce((w,S)=>Math.max(w,S.time),v),0),a=lt,l=new Set(["x","y","turn","head.turn"]),c=new Ht({id:`${t}-hair-follow`,tracks:r.filter(v=>l.has(v.property))}),h=(v,k,w)=>{const S=c.getStateAtTime(v).values.get(t)?.get(k);return typeof S=="number"?S:w},u=new Ht({id:`${t}-hair-pose`,tracks:r}),d=v=>u.getStateAtTime(v).values.get(t),f=new Map,m=v=>{const k=Math.round(v/Hs);let w=f.get(k);if(!w){const S={};for(const[M,E]of d(k*Hs)??[])S[M]=E;const x=ke(n,$o(S,a,s.gaits)).head.center;f.set(k,w={x:x.x,y:x.y})}return w},g=v=>{const k=Math.floor(v/Hs),w=v/Hs-k,S=m(k*Hs),x=m((k+1)*Hs);return{x:S.x+(x.x-S.x)*w,y:S.y+(x.y-S.y)*w}},p=ly(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:o+(s.settle??ZT),headRadius:ke(n,lt).head.rx,step:s.step,stiffness:s.stiffness,damping:s.damping,amount:s.amount,wind:s.wind}),b=[];for(const v of VT){const k=v.slice(5);let w=p.map(x=>({time:x.time,value:x[k]}));if(w.every(x=>Math.abs(x.value)<.001))continue;const S=r.find(x=>x.property===v);if(S){const x=new Ht({id:`${t}-${v}-own`,tracks:[S]}),M=E=>Number(x.getStateAtTime(E).values.get(t)?.get(v)??0);w=w.map(E=>({time:E.time,value:E.value+M(E.time)}))}b.push({id:`${t}-${v}`,target:t,property:v,keyframes:w})}return b}const Xn={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 xh(t){if(t===void 0)return Xn.full;if(typeof t=="string")return Xn[t];const{base:e,...n}=t;return{...Xn[e??"full"],...n}}const Ph=160,t4=120,e4=700,$h=60,n4=90,Go=3200,Fs=1,Gn=1e-6;function Uo(t,e,n={}){const s=xh(n.style),i=n.seed??1,r={};if(t.length===0)return r;const o=Object.keys(t[0].pose).filter(u=>t.some(d=>Math.abs(d.pose[u]-t[0].pose[u])>Gn));for(const u of o)r[u]=s4(u,t,e,s,i);const a=e.blink,l=a!==void 0&&o.includes(a);if(s.blinks&&a!==void 0&&!l&&a in t[0].pose){const u=i4(t,e,s,i,t[0].pose[a]);u.length>0&&(r[a]=u)}const{lift:c,stretch:h}=e;if(s.jumpSquash>0&&c&&h&&o.includes(c)&&!o.includes(h)&&h in t[0].pose){const u=r4(t,c,t[0].pose[h],s.jumpSquash);u.length>0&&(r[h]=u)}return r}function s4(t,e,n,s,i){const r=n.eyes.includes(t),o=n.limits[t],a=o!==void 0,l=r?-s.eyeLead:(n.depth[t]??1)*s.overlap,c=f=>{const m=(e[f].time-e[f-1].time)/2;return Math.max(-m,Math.min(m,l))},h=[{time:e[0].time,value:e[0].pose[t]}],u=(f,m,g)=>{const p=h[h.length-1];if(f<=p.time+Fs){h[h.length-1]={...p,value:m,...g?{easing:g}:{}};return}h.push({time:f,value:m,...g?{easing:g}:{}})};let d=e[0].pose[t];for(let f=1;f<e.length;f++){const m=e[f],g=e[f-1].pose[t],p=m.pose[t],b=p-g,v=h[h.length-1].time,k=m.act!==!1;if(Math.abs(b)<=Gn){const P=m.time+(k?c(f):0);if(f===e.length-1)Math.abs(d-p)>Gn&&u(Math.max(P,v+Ph),p,"ease-in-out"),d=p;else if(k&&a&&s.drift>0&&n.drift.includes(t)&&P-v>=e4){const I=re(`${i}:${t}:${f}`)%2===0?1:-1;d=p+I*s.drift*o,u(P,d,"ease-in-out")}continue}if(!k){u(e[f-1].time,d),u(m.time,p,m.easing),d=p;continue}const w=c(f),S=Math.max(e[f-1].time+w,v);let x=m.time+w;r&&s.eyeDart>0&&(x=Math.min(x,S+s.eyeDart));const M=x-S;if(M<=Fs){u(m.time,p,m.easing),d=p;continue}u(S,d);const E=Math.sign(b);if(a&&s.anticipation>0&&o>0&&M>=Ph){const P=d-E*Math.min(Math.abs(b)*s.anticipation,o),I=S+M*s.anticipationTime;u(I,P,"ease-in-out"),s.hold>0&&u(I+M*s.hold,P)}const T=f+1<e.length?e[f+1].time-m.time:1/0,A=Math.min(s.settle,T/2);if(a&&s.overshoot>0&&o>0&&M>=t4&&A>Fs){const P=Math.min(Math.abs(b)*s.overshoot,o);u(x,p+E*P,m.easing??s.actionEase),u(x+A,p,s.settleEase)}else u(x,p,m.easing??s.actionEase);d=p}return h}function i4(t,e,n,s,i){const r=[],o=$h+n4;for(let f=1;f<t.length;f++){const m=t[f-1].pose,g=t[f].pose;Object.entries(e.headTurns).some(([b,v])=>Math.abs((g[b]??0)-(m[b]??0))>v)&&t[f].act!==!1&&r.push(Math.max(t[0].time,t[f-1].time-n.eyeLead))}const a=t[0].time,l=t[t.length-1].time,c=[...r];let h=a+Go*.6,u=0;for(;h<l;){c.some(g=>Math.abs(g-h)<Go/2)||r.push(h);const m=(re(`${s}:blink:${u++}`)%1e3/1e3-.5)*(Go*.66);h+=Go+m}r.sort((f,m)=>f-m);const d=[{time:a,value:i}];for(const f of r){const m=d[d.length-1].time;f+$h<=m+Fs||(f>m+Fs&&d.push({time:f,value:i}),d.push({time:f+$h,value:1,easing:"ease-in"}),d.push({time:f+o,value:i,easing:"ease-out"}))}return d.length>1?d:[]}function r4(t,e,n,s){const i=n*(1-.18*s),r=n*(1+.14*s),o=[{time:t[0].time,value:n}],a=(l,c,h)=>{const u=o[o.length-1];l<=u.time+Fs||o.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<Ph||t[l].act===!1)){if(c<=Gn&&h>Gn)a(u,n),a(u+f*.2,i,"ease-out"),a(u+f*.45,r,"ease-out"),a(d,n,"ease-in-out");else if(c>Gn&&h<=Gn){const m=l+1<t.length?t[l+1].time-d:400;a(u+f*.5,n),a(d-Math.min(60,f*.15),r,"ease-in"),a(d,i,"ease-out"),a(d+Math.min(260,m/2),n,{type:"back",mode:"out",overshoot:1.4})}}}return o.length>1?o:[]}const hy={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 o4(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 a4(){const t={},e={};for(const n of Object.keys(lt)){const s=o4(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 uy=a4();function dy(t,e){return Object.entries(e).map(([n,s])=>({id:`${t}-${n}`,target:t,property:n,keyframes:s}))}function fy(t,e,n={}){const s=Vr(e),i=e.map((r,o)=>({time:r.time,pose:{...s[o]},easing:r.easing,act:r.act}));return dy(t,Uo(i,n.rig??hy,n))}function gy(t,e,n={}){const s=n.rest??lt,i=Gc(e,s),r=e.map((o,a)=>({time:o.time,pose:{...s,...i[a]},easing:o.easing,act:o.act}));return dy(t,Uo(r,n.rig??uy,n))}const my=Mt.shocked,l4=Mt.scared,mn={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,...my,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,...Mt.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,...my,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,...Mt.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:{...l4,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:{...he.sad,bend:18,stretch:.92,lean:t.lean+5,turn:t.turn,sit:t.sit},easing:"ease-in-out"}]};function Ih(t,e){const n=typeof e.from=="string"?he[e.from]:e.from??ut;return Oh(mn[t](n),{...e,from:n})}function Oh(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 nr(t,e=1){const n=mn[t](ut);return n[n.length-1].after*e}function py(t,e,n={}){if(e.length<2)return;const s=Math.max(1,Math.round(n.lines??3)),i=n.spacing??5,r=n.lineWidth??2,o=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,m=d.y-u.y,g=Math.hypot(f,m)||1,p=-m/g,b=f/g,v=1-h/(e.length-1);t.globalAlpha=o*(1-v),t.lineWidth=r*(1-v*.7),t.beginPath(),t.moveTo(u.x+p*l,u.y+b*l),t.lineTo(d.x+p*l,d.y+b*l),t.stroke()}}t.restore()}const c4={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 h4(t,e,n,s,i={}){const r=n.stateAt;if(!r)return;const o=i.length??120,a=Math.max(2,Math.round(i.samples??8)),l=Math.max(0,n.time-o);if(n.time-l<1)return;const c=[];for(let f=0;f<a;f++){const m=l+(n.time-l)*f/(a-1);c.push(Ql(e,{time:m,state:r(m)},s).joints)}const h=c[c.length-1].height,u=(i.threshold??1.2)*h,d=(i.parts??["hands","toes","head"]).flatMap(f=>c4[f]);for(const f of d){const m=c.map(f.at);let g=0;for(let v=1;v<m.length;v++)g+=Math.hypot(m[v].x-m[v-1].x,m[v].y-m[v-1].y);const p=g/((n.time-l)/1e3);if(p<=u)continue;const b=Math.min(1,(p-u)/(u*.5));py(t,m,{...i,opacity:(i.opacity??.7)*b,spacing:i.spacing??h*.02})}}function yy(t,e,n,s={}){if(n<=0||n>=1)return;const i=s.size??40,r=s.seed??1,o=.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=re(`${r}:puff:${a}`)%1e3/1e3,c=a-2,h=e.x+c*i*.3*o,u=e.y-i*(.06+.12*l)*o+Math.abs(c)*i*.03,d=i*(.11+.07*l)*o;t.beginPath(),t.arc(h,u,d,Math.PI*.95,Math.PI*2.05),t.stroke()}t.restore()}function u4(t,e,n,s={}){if(n<=0||n>=1)return;const i=s.size??40,r=5,o=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<r;a++){const l=-Math.PI/2+(a-(r-1)/2)*Math.PI/(r+1),c=i*(.3+.7*o),h=e.x+Math.cos(l)*c,u=e.y+Math.sin(l)*c;d4(t,h,u,i*.14,n*Math.PI+a),t.stroke()}t.restore()}function d4(t,e,n,s,i){t.beginPath();for(let r=0;r<10;r++){const o=r%2===0?s:s*.45,a=i+r*Math.PI/5-Math.PI/2,l=e+Math.cos(a)*o,c=n+Math.sin(a)*o;r===0?t.moveTo(l,c):t.lineTo(l,c)}t.closePath()}const sr={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 Ch(t={}){return[...Object.keys(Gt),...Object.keys(he),...Object.keys(mn),...Object.keys(sr),...Object.keys(t.gaits??{}),...Object.keys(t.actions??{})]}function _h(t={}){const e=new Set(Ch()),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 Rh(t={}){const e={};for(const n of Object.keys(Gt))e[n]=`Walks to \`to\` in the ${n} gait, feet planted, turning round first if needed.`;for(const n of Object.keys(he))e[n]=`Moves into the ${n} pose and holds it.`;for(const n of Object.keys(mn))e[n]=`The ${n} gag, built on the current pose.`;for(const[n,s]of Object.entries(sr))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 Vo=["do","at","for","to","toward","mood","say","pose","target","onto"],f4={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"},Jo=["viewer","ahead","back"],Un=t=>typeof t=="number"&&Number.isFinite(t);function ir(t,e={}){const n=_h(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=Ch(e),i=l=>l in Gt||l in(e.gaits??{}),r=Object.keys(Mt),o=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))Vo.includes(g)||h(dt("beat field",g,Vo,f4[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(dt("action",f,s));return}const m=sr[f]??e.actions?.[f];for(const g of m?.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"||!r.includes(d.mood))&&h(dt("mood",d.mood,r)),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,p]of Object.entries(d.pose))o.includes(g)?Un(p)||h(`Pose joint \`${g}\` must be a number (got ${JSON.stringify(p)}).`):h(dt("pose joint",g,o));for(const g of["at","for"]){const p=d[g];p!==void 0&&!(Un(p)&&p>=0)&&h(`\`${g}\` is milliseconds, a number ≥ 0 (got ${JSON.stringify(p)}).`)}Un(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 p=d[g];p!==void 0&&!Un(p)&&h(`\`${g}\` is a scene ${g==="to"?"x":"y"} in px, a number (got ${JSON.stringify(p)}).`)}if(d.toward!==void 0&&!Un(d.toward)&&!Jo.includes(d.toward)&&h(`\`toward\` is a scene x or one of ${Jo.join(", ")}${typeof d.toward=="string"&&ai(d.toward,Jo)?` (did you mean "${ai(d.toward,Jo)}"?)`:""} (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"||!Un(g.x)||!Un(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 Hh(t,e={},n="scriptTracks"){const s=ir(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,r={...lt,...n.pose},o=(M,E=r)=>{const T=M.match(/^hand\.(?:left|right)\.(.+)$/)?.[1];return E[M]??lt[M]??(T?Ct[T]:void 0)??0};let[a,l]=n.position??[0,0],c=n.heading??0,h=0;const u=new Map,d=[],f=(M,E,T,A="linear")=>{const P=u.get(M)??[];P.push({time:E,value:T,easing:A}),u.set(M,P)},m=(M,E,T)=>{const A=u.get(M)??[];for(let P=A.length-1;P>=0;P--)if(A[P].time===E){if(A[P].value===T)return;break}f(M,E,T)};f("x",0,a),f("z",0,l),f("rotateY",0,c);const g=(M,E,T)=>{const A=Do(c,E);if(Math.abs(A)<1)return T!==void 0&&(m("rotateY",M,c),f("rotateY",M+T,c)),M+(T??0);const P=T??Math.max(K3,Math.abs(A)*j3);return m("rotateY",M,c),c+=A,f("rotateY",M+P,c,"ease-in-out"),M+P},p=(M,E,T,A="ease-in-out")=>{for(const[P,I]of Object.entries(T))o(P)!==I&&(m(P,M,o(P)),f(P,E,I,A),r[P]=I)},y=(M,E,T)=>{const A=Cp([[a,l],...E.through??[E.to]]);if(A.length<2)return T;const P=g(T,Cs(A[0].point,A[1].point)),I=A[A.length-1].at,O=E.speed??Np[M]*Math.sqrt(i/1.7),_=E.for??I/O*1e3,L=Mo(M,i),j=Dt("ease-in-out"),V=Math.min(Y3,_/4);d.push({time:P,value:M}),m("walking",P,0),f("walking",P+V,1,"ease-out"),f("walking",P+_-V,1),f("walking",P+_,0,"ease-in");const tt=h;let J=c;for(let F=0;;F=Math.min(I,F+q3)){const B=P+Rp(j,F/I)*_,{point:Y,direction:R}=_p(A,F);J+=Do(J,Cs([0,0],R));const K=F===0?m:f;if(K("x",B,Y[0]),K("z",B,Y[1]),K("rotateY",B,J),K("walk",B,tt+F/L),F>=I)break}return h=tt+I/L,[a,l]=A[A.length-1].point,c=J,P+_},v=[],w=[];let k=0;for(const M of e){const E=M.at??k;let T=E;if(uh.includes(M.do))T=y(M.do,M,E);else if(M.do==="face")T=g(E,typeof M.toward=="number"?M.toward:Cs([a,l],M.toward),M.for);else if(M.do==="spin")T=E+(M.for??1e3),m("rotateY",E,c),c+=(M.turns??1)*360,f("rotateY",T,c,"linear");else if(M.do==="dance"){const A=Nn[M.dance],P=M.bpm??A.bpm,I=M.beats??(M.for!==void 0?M.for*P/6e4:A.beats);T=E+(M.for??I*6e4/P);const O={...r},_=Math.max(1,Math.ceil(I*16)),L=Array.from({length:_+1},(V,tt)=>Ci(M.dance,I*tt/_,O).pose),j=Math.min(150,(T-E)/4);for(const V of Object.keys(L[0])){const tt=o(V,O);V==="turn"||V==="roll"||L.every(J=>J[V]===tt)||(m(V,E,tt),L.slice(1).forEach((J,F)=>{const B=E+(T-E)*(F+1)/_,Y=Math.min(1,(B-E)/j),R=Y*Y*(3-2*Y);f(V,B,tt+(J[V]-tt)*R)}),r[V]=L[_][V])}}else if(M.do==="hold")T=E+(M.for??1e3);else if(M.do==="place")m("x",E,a),m("z",E,l),[a,l]=M.to,f("x",E+1,a),f("z",E+1,l),typeof M.toward=="number"&&(m("rotateY",E,c),c=M.toward,f("rotateY",E+1,c)),T=E+1;else if(M.do==="pose"){T=E+(M.for??500);const A=typeof M.pose=="string"?Ae[M.pose]:M.pose;p(E,T,A)}else if(M.do==="gag"){const A=mm(M.gag,{at:E,from:{...r}});let P=A[0];for(const I of A.slice(1))p(P.time,I.time,Object.fromEntries(Object.entries(I.pose).filter(([O,_])=>r[O]!==_)),I.easing??"ease-in-out"),P=I;T=P.time}else if(M.do==="say"){T=E+(M.for??Hp(M.say)),w.push({text:M.say,start:E,end:T});const A={tilt:r["head.tilt"]??0,left:r["brow.left"]??0,right:r["brow.right"]??0};let P=0;for(let I=E+Gi;I<T-Gi/2;I+=Gi,P++){const O=P%2===0;p(I-Gi/2,I,{"head.tilt":A.tilt+(O?3:-2),"brow.left":A.left+(O?.25:0),"brow.right":A.right+(O?.25:0)})}P>0&&p(T-Gi/2,T,{"head.tilt":A.tilt,"brow.left":A.left,"brow.right":A.right})}else if(M.do==="look"){const A=M.look??M.toward,P=i*.9,I=A==="camera"?n.camera??[0,1.6,8]:A.length===3?A:[A[0],P,A[1]];T=E+(M.for??500),p(E,T,hh({x:a,z:l,heading:c,eyeHeight:P},I),"ease-out")}v.push({do:M.do,start:E,end:T}),k=T}const S=`${n.scene}/${t}`;let x=[...u].map(([M,E])=>({id:`${t}-${M}`,target:S,property:M,keyframes:Op(E)}));return d.length>0&&x.push({id:`${t}-gait`,target:S,property:"gait",keyframes:d}),w.length>0&&(x=Wo(S,x,w,{rest:{mouth:n.pose?.mouth??lt.mouth??0,mouthWidth:n.pose?.mouthWidth??lt.mouthWidth??1}})),{tracks:x,duration:k,beats:v,end:{position:[a,l],heading:c,pose:{...r}}}}function gh(t,e,n=[0,0,0]){const s=t.filter(r=>r.target===e),i=new Ht({id:`${e}-position`,tracks:s});return r=>{const o=i.getStateAtTime(r).values.get(e),a=o?.get("position");if(Array.isArray(a)&&a.length===3)return[a[0],a[1],a[2]];const l=(c,h)=>{const u=o?.get(c);return typeof u=="number"?u:h};return[l("x",n[0]),l("y",n[1]),l("z",n[2])]}}function G3(t,e){const n=`${e.scene}/${e.character}`,s=e.height??1.7,i=Math.max(1,e.every??66),r=e.objects?.[e.character]??[0,0,0],o=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?gh(t,`${e.scene}/${a.camera}`,e.objects?.[a.camera]??[0,1.6,8]):(()=>{const u=gh(t,`${e.scene}/${a.object}`,e.objects?.[a.object]??[0,0,0]),d=a.eyeHeight??s*.9;return f=>{const m=u(f);return[m[0],m[1]+d,m[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=o.getStateAtTime(u).values.get(n),f=(g,p)=>{const y=d?.get(g);return typeof y=="number"?y:p},m=hh({x:f("x",r[0]),z:f("z",r[2]),heading:f("rotateY",0),eyeHeight:f("y",r[1])+s*.9},l(u));for(const g of c)h[g].push({time:u,value:m[g]??0});if(u>=e.end)break}return c.map(u=>({id:`${n}-lookAt-${u}`,target:n,property:u,keyframes:h[u]}))}function U3(t){const e=Math.max(1,Math.round(t.count)),[n,s]=t.centre??[0,0],i=t.spacing??1.2,r=t.shape??"line",o=[];if(r==="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,m=s+Math.cos(d)*h;o.push({position:[f,m],heading:(Math.atan2(n-f,s-m)*180/Math.PI+360)%360})}return o}if(r==="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 m=[n,s],g=-1/0;for(let p=0;p<24;p++){const y=Math.sqrt(u())*i*Math.max(1,Math.sqrt(e)*.9),v=u()*Math.PI*2,w=[n+Math.cos(v)*y,s+Math.sin(v)*y],k=d.length===0?1/0:Math.min(...d.map(S=>Math.hypot(S[0]-w[0],S[1]-w[1])));if(k>g&&(g=k,m=w),k>=i)break}d.push(m),o.push({position:m,heading:0})}return o}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,m=s+Math.cos(a)*d,g=((t.heading??90)-90+360)%360;if(r==="arc"){const p=(1-Math.cos(u*c))*l*.5;f-=Math.cos(a)*p,m+=Math.sin(a)*p,g=(g-u*(t.bend??60)+360)%360}o.push({position:[f,m],heading:g})}return o}const Dp={x:0,y:0,scale:1,rotate:0,shakeX:0,shakeY:0,shakeRotate:0};function V3(t){const e=n=>{const s=t?.get(n);return typeof s=="number"?s:Dp[n]};return{x:e("x"),y:e("y"),scale:e("scale"),rotate:e("rotate"),shakeX:e("shakeX"),shakeY:e("shakeY"),shakeRotate:e("shakeRotate")}}function J3(t,e,n){const s=n.width/2,i=n.height/2,o=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*o,e.scale*o),t.translate(-s,-i)}function Z3(t,e,n){const s=e.width/2,i=e.height/2,r=(t.rotate+t.shakeRotate)*Math.PI/180,o=(n.x-s)*t.scale,a=(n.y-i)*t.scale;return{x:s+t.x+t.shakeX+o*Math.cos(r)-a*Math.sin(r),y:i+t.y+t.shakeY+o*Math.sin(r)+a*Math.cos(r)}}function Bp(t,e,n={},s){const i=n.length??240,r=9,o=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(o,-r,a-o,2*r),t.fillStyle="#e8b4a0",t.fillRect(a,-r,i-a,2*r),t.fillStyle="#f1dcbf",t.beginPath(),t.moveTo(0,0),t.lineTo(o,-r),t.lineTo(o,r),t.closePath(),t.fill(),t.fillStyle=n.outline??"#2f2f33",t.beginPath(),t.moveTo(0,0),t.lineTo(o*.35,-r*.35),t.lineTo(o*.35,r*.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:o,y:-r},{x:i,y:-r},{x:i,y:r},{x:o,y:r},{x:0,y:0}],[{x:o,y:-r},{x:o,y:r}],[{x:a,y:-r},{x:a,y:r}]];for(const c of l)jp(t,c,s);t.restore()}function mh(t,e,n={},s){const i=n.length??90,r=n.thickness??34;t.save(),t.translate(e.x,e.y),t.rotate((n.angle??-35)*Math.PI/180);const o=-r/2;t.fillStyle=n.color??"#f4a7b9",t.fillRect(0,o,i,r),t.fillStyle="#e9edf2",t.fillRect(i*.45,o,i*.55,r),t.strokeStyle=n.outline??"#2f2f33",t.lineWidth=3,t.lineJoin="round";const a=[{x:0,y:o},{x:i,y:o},{x:i,y:-o},{x:0,y:-o},{x:0,y:o}],l=[{x:i*.45,y:o},{x:i*.45,y:-o}];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 zp=150,Q3={pencil:44,eraser:30};function ph(t,e,n={},s){const i=n.tool??"pencil",r=n.skin??"#f1c9a5",o=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=zp*a*(1+.05*l);l>0&&(t.save(),t.fillStyle=o,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=Tt.pencilGrip,m=M=>{const E=M.fingers.thumb,T=M.fingers.index,A=M.fingers.middle,P=qp([E.points[3],T.points[3],A.points[3]]),I=qp([E.points[1],T.points[0]]),O=(E.depths[3]+T.depths[3]+A.depths[3])/3;return{pinch:P,direction:Math.atan2(I.y-P.y,I.x-P.x),depth:O}},g=Kr(f,{size:u}),p=c-m(g).direction,y=Kr(f,{size:u,angle:p*180/Math.PI}),v=m(y),w=Q3[i]*a,k={x:v.pinch.x-Math.cos(c)*w,y:v.pinch.y-Math.sin(c)*w},S={x:d.x-k.x,y:d.y-k.y},x=y.axes.up;tT(t,S,{x:-x.x,y:-x.y},u,n.arm??300*a,r,n.sleeve??"#5b7db1",o),Yr(t,S,f,{size:u,angle:p*180/Math.PI,skin:r,ink:o,lineWidth:3*a,prop:{depth:v.depth,draw:()=>{t.save(),t.translate(d.x,d.y),t.scale(a,a),i==="eraser"?mh(t,{x:0,y:0},{angle:c*180/Math.PI,outline:o},s):Bp(t,{x:0,y:0},{angle:c*180/Math.PI,length:190,outline:o},s),t.restore()}}})}const qp=t=>({x:t.reduce((e,n)=>e+n.x,0)/t.length,y:t.reduce((e,n)=>e+n.y,0)/t.length});function tT(t,e,n,s,i,r,o,a){const l={x:-n.y,y:n.x},c=s*.15,h=(g,p,y)=>({x:e.x+n.x*g+l.x*p*y,y:e.y+n.y*g+l.y*p*y}),u=h(i,0,0),d=g=>{const p=t.createLinearGradient(e.x,e.y,u.x,u.y);return p.addColorStop(0,g),p.addColorStop(.6,g),p.addColorStop(1,iT(g)),p},f=Math.min(s*.55,i*.35);t.save(),t.lineJoin="round",t.lineCap="round",t.lineWidth=3*(s/zp),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=r,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 m=[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(),m.forEach((g,p)=>p?t.lineTo(g.x,g.y):t.moveTo(g.x,g.y)),t.closePath(),t.fillStyle=d(o),t.fill(),t.strokeStyle=d(a),t.beginPath(),t.moveTo(m[1].x,m[1].y),t.lineTo(m[0].x,m[0].y),t.lineTo(m[3].x,m[3].y),t.lineTo(m[2].x,m[2].y),t.stroke(),t.restore()}function eT(t,e,n={}){const s=n.offstage??{x:2e3,y:1400},i=n.enter??450,r=n.exit??450,o=n.linger??1500,a=[...t].filter(g=>g.path.length>0).sort((g,p)=>g.start-p.start),l=g=>g.tool??"pencil",c=g=>{const p=Math.min(1,Math.max(0,g));return p*p*(3-2*p)},h=(g,p,y)=>({x:g.x+(p.x-g.x)*y,y:g.y+(p.y-g.y)*y}),u=a.find(g=>e>=g.start&&e<=g.end);if(u){const g=u.end-u.start,p=g>0?(e-u.start)/g:1;return{at:Wr(u.path,p),tool:l(u),lift:0,drawing:!0}}const d=[...a].reverse().find(g=>g.end<e),f=a.find(g=>g.start>e),m=g=>g.path[g.path.length-1];if(d&&f&&f.start-d.end<=o){const g=(e-d.end)/(f.start-d.end),p=g<.5?l(d):l(f);return{at:h(m(d),f.path[0],c(g)),tool:p,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<=r){const g=(e-d.end)/r;return{at:h(m(d),s,c(g)),tool:l(d),lift:c(g),drawing:!1}}return null}function nT(t,e,n,s=.08,i=32){const r=Math.PI*2*(1+s),o=[];for(let a=0;a<=i;a++){const l=-Math.PI/2+r*a/i;o.push({x:t+Math.cos(l)*n,y:e+Math.sin(l)*n})}return o}function sT(t){const{path:e}=t,n=e.map(a=>a.x),s=e.map(a=>a.y),i=Math.min(...n),r=Math.min(...s),o=t.hand===!1?void 0:t.hand===!0||t.hand===void 0?{}:t.hand;return{type:"custom",x:i,y:r,width:Math.max(1,Math.max(...n)-i),height:Math.max(1,Math.max(...s)-r),props:{draw:0},draw(a,l,c){const h=Math.min(1,Math.max(0,Number(l.props?.draw??0)));a.translate(-i,-r),a.strokeStyle=t.color??"#2f2f33",a.lineWidth=t.lineWidth??5,a.lineCap="round",a.lineJoin="round";const u=t.sketch?Dr(a,t.sketch,c):void 0;h>0&&(u?t.smooth?u.curve(e,h):u.line(e,h):jp(a,sn(e,h))),o&&h>0&&h<1&&ph(a,Wr(e,h),o,u)}}}function iT(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(o=>o+o).join(""):e[1],[s,i,r]=[0,2,4].map(o=>parseInt(n.slice(o,o+2),16));return`rgba(${s}, ${i}, ${r}, 0)`}function jp(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 Bo=1e5;function rT(t,e,n,s,i=6){const r=[],o=Math.max(1,Math.round(i));for(let a=0;a<=o;a++)r.push({x:a%2===0?t:t+n,y:e+s*a/o});return r}function yh(t,e,n,s){if(s<=0||e.length===0)return;const i=sn(e,s),r=n/2,o=a=>{t.beginPath(),t.rect(-Bo,-Bo,2*Bo,2*Bo),a(),t.clip("evenodd")};for(const a of i)o(()=>{t.moveTo(a.x+r,a.y),t.arc(a.x,a.y,r,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*r,d=(c.x-l.x)/h*r;o(()=>{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 oT(t,e,n,s,i){t.save(),yh(t,e,n,s),i(),t.restore()}function aT(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(r,o,a){const l=Number(o.props?.erase??0);if(r.save(),yh(r,e.path,n,l),t.draw(r,o,a),r.restore(),!i||l<=0||l>=1)return;const c=Wr(e.path,l);s?ph(r,c,{...s,tool:"eraser"}):mh(r,c,i)}}}function _s(){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,r,o=300){e(n,{time:r.at,value:s},{time:r.at+(r.duration??o),value:i,...r.easing?{easing:r.easing}:{}})},last(n,s){const i=t.get(n);return i?[...i].sort((r,o)=>r.time-o.time)[i.length-1].value:s},valueAt:(n,s)=>zo(t.get(n),s),cutAfter(n,s){for(const i of n)t.set(i,(t.get(i)??[]).filter(r=>r.time<=s))},tracks(n){return[...t].filter(([,s])=>s.length>0).map(([s,i])=>({id:`${n}-${s}`,target:n,property:s,keyframes:lT(i)}))}}}function zo(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],r=n[s];return r.time===i.time?r.value:i.value+(r.value-i.value)*(e-i.time)/(r.time-i.time)}return n[n.length-1].value}function Rs(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 lT(t){return[...t].sort((n,s)=>n.time-s.time).map(n=>({time:n.time,value:n.value,...n.easing?{easing:n.easing}:{}}))}const cT=.0016,hT=.6,fn=33;function Ui(t){const e=(r,o)=>`piece.${r.id}.${o}`,n=(r,o)=>({x:r.home.x+t.valueAt(e(r,"x"),o),y:r.home.y+t.valueAt(e(r,"y"),o)}),s=(r,o)=>{const a=t.keys(e(r,"x"));if(!a||a.length<2)return;const l=n(r,o-fn),c=n(r,o);return{x:(c.x-l.x)/fn,y:(c.y-l.y)/fn}},i=(r,o)=>t.cutAfter(["x","y","rotate"].map(a=>e(r,a)),o);return{at:n,cutAfter:i,follow(r,o){for(const a of o)t.push(e(r,"x"),{time:a.time,value:a.x-r.home.x}),t.push(e(r,"y"),{time:a.time,value:a.y-r.home.y})},fling(r,o){const a=n(r,o.at),l=o.velocity??s(r,o.at)??{x:.5,y:-.6},c=o.gravity??cT,h=o.duration??900,u=(o.spin??hT)*(l.x<0?-1:1),d=t.valueAt(e(r,"rotate"),o.at);i(r,o.at);for(let f=0;f<=h;f+=fn){const m=a.x+l.x*f,g=a.y+l.y*f+.5*c*f*f;t.push(e(r,"x"),{time:o.at+f,value:m-r.home.x}),t.push(e(r,"y"),{time:o.at+f,value:g-r.home.y}),t.push(e(r,"rotate"),{time:o.at+f,value:d+u*f})}t.tween(e(r,"opacity"),1,0,{at:o.at+h*.6,duration:h*.4})},move(r,o){const a=n(r,o.at);t.tween(e(r,"x"),a.x-r.home.x,o.to.x-r.home.x,o,400),t.tween(e(r,"y"),a.y-r.home.y,o.to.y-r.home.y,o,400)}}}function qo(t,e,{ground:n,every:s,floors:i}){if(i.every(w=>w.windows.length===0))return t;const r=t.find(w=>w.target===e&&w.property==="y"),o=new Ht({id:`${e}-ride`,tracks:r?[r]:[]}),a=w=>r?Number(o.getStateAtTime(w).values.get(e)?.get("y")??0):0,l=w=>{const k=n+a(w);return i.findIndex(S=>Math.abs(S.top-k)<.5)},c=(r?.keyframes??[]).map(w=>w.time),h=w=>{const k=T=>T<0?0:i[T].offset(w),S=l(w);if(S>=0)return k(S);if(Math.abs(a(w))<.5)return 0;const x=T=>l(T)>=0||Math.abs(a(T))<.5,M=[...c].reverse().find(T=>T<=w&&x(T)),E=c.find(T=>T>=w&&x(T));return M===void 0&&E===void 0?0:M===void 0?k(l(E)):E===void 0||E===M?k(l(M)):k(l(M))+(k(l(E))-k(l(M)))*(w-M)/(E-M)},u=i.flatMap(w=>w.windows),d=(w,k)=>u.some(S=>S.start<k&&S.end>w)||h(w)!==h(k),f=r?[...r.keyframes]:[{time:0,value:0}],m=[{...f[0],value:f[0].value+h(f[0].time)}],g=(w,k)=>{const S=new Set([k]);for(let x=w+s;x<k;x+=s)S.add(x);for(const x of u)for(const M of[x.start,x.end])M>w&&M<k&&S.add(M);for(const x of[...S].sort((M,E)=>M-E))m.push({time:x,value:a(x)+h(x)})};for(let w=1;w<f.length;w++){const k=f[w-1].time,S=f[w].time;d(k,S)?g(k,S):m.push({...f[w],value:f[w].value+h(S)})}const p=f[f.length-1].time,y=Math.max(p,...u.map(w=>w.end));y>p&&g(p,y);const v={id:r?.id??`${e}-y`,target:e,property:"y",keyframes:m};return r?t.map(w=>w===r?v:w):[...t,v]}function jn(t){const e=t.indexOf(":");return e<0?{kind:t,rest:""}:{kind:t.slice(0,e),rest:t.slice(e+1)}}function gn(t,e,n,s){const i=Object.keys(n.anchors).map(o=>jn(o).kind),{kind:r}=jn(e);return i.includes(r)?new Error(`${t}: no anchor "${e}"${s?`: ${s}`:""} (anchors: ${Object.keys(n.anchors).join(", ")})`):new Error(`${t}: ${dt("anchor",r,i)} (anchors: ${Object.keys(n.anchors).join(", ")})`)}function Vi(t,e,n){return new Error(`${t}.edit: ${dt("edit",e,Object.keys(n.edits))}`)}function St(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 Kp={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"},jo=["wipe","fly","blur"],Ji={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"}},uT=.9,dT=8;function fT(t){const e={...Kp,...t.theme},n=t.code.replace(/\t/g," ").replace(/\n$/,"").split(`
|
|
56
|
+
`),s=t.fontSize??16,i=(t.lineHeight??1.6)*s,r=(t.charWidth??.6)*s,o=t.padding??12,a=t.lineNumbers===!1?0:(String(n.length).length+2)*r,l=Math.max(1,...n.map(F=>F.length)),c=t.width??o*2+a+l*r,h=o*2+n.length*i,u=t.x+o+a,d=new Set(t.hidden??[]),f=t.language??"plain";if(!Yo.includes(f))throw new Error(`codePanel: ${dt("language",f,Yo)}`);const m=n.map(F=>Xp(F,f).flatMap(B=>Array.from(B.text,()=>e[B.kind]))),g=_s(),p=Ui(g),y=[],v=new Map,w=[],k=[],S=F=>{if(!Number.isInteger(F)||F<1||F>n.length)throw new Error(`codePanel: no line ${F} (it has ${n.length})`)},x=g.tween,M=g.last,E=(F,B,Y,R,K,st=300)=>{S(F),x(`line.${F}.${B}`,Y,R,K,st)},T=(F,B)=>y.filter(Y=>Y.line<F&&Y.closed<=B).length,A=St,P=F=>t.y+o+(F-1)*i,I=F=>Array.isArray(F)?F:[F],O=(F,B,Y)=>{let R=-1;for(let K=0;K<Y;K++)if(R=n[F-1].indexOf(B,R+1),R<0)throw new Error(`codePanel: line ${F} has no ${Y>1?`${Y}th `:""}"${B}"`);return R},_={};n.forEach((F,B)=>{const Y=B+1;_[`line.${Y}.highlight`]=0,_[`line.${Y}.strike`]=0,_[`line.${Y}.wipe`]=0,_[`line.${Y}.reveal`]=d.has(Y)?0:1,_[`line.${Y}.shift`]=0});const L={type:"custom",x:t.x,y:t.y,width:c,height:h,props:_,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 mT(Object.keys(_))},actions:bh},draw(F,B){const Y=B.props??{},R=C=>Number(Y[C]??_[C]),K=o+a,st=C=>o+(C-1)*i-R(`line.${C}.shift`)*i;F.fillStyle=e.background,Yp(F,0,0,c,h,8),F.fill(),F.font=`${s}px ${e.font}`,F.textBaseline="middle",F.textAlign="left";const $=(C,z,X,W,N)=>{const D=n[C-1];for(let G=z;G<X;G++)D[G]!==" "&&(F.fillStyle=m[C-1][G],F.fillText(D[G],W+(G-z)*r,N))};F.save(),Yp(F,0,0,c,h,8),F.clip(),n.forEach((C,z)=>{const X=z+1,W=R(`line.${X}.wipe`);if(W>=1)return;const N=st(X),D=N+i/2,G=Math.max(1,C.length)*r,q=Math.round(R(`line.${X}.reveal`)*C.length),Z=v.get(X)??{style:"wipe",from:"left"};F.save(),W>0&&gT(F,Z,W,{left:K-a,top:N,width:a+G+r,height:i},c);const et=R(`line.${X}.highlight`);et>0&&(F.globalAlpha*=Math.min(1,et),F.fillStyle=e.highlight,F.fillRect(K-r/2,N,G+r,i),F.globalAlpha/=Math.min(1,et)),a>0&&q>0&&(F.fillStyle=e.gutter,F.textAlign="right",F.fillText(String(X),K-r,D),F.textAlign="left");const H=[...w.filter(rt=>rt.line===X).map(rt=>({column:rt.column,length:rt.text.length,piece:rt,insert:void 0})),...k.filter(rt=>rt.line===X).map(rt=>({column:rt.column,length:0,piece:void 0,insert:rt}))].sort((rt,ct)=>rt.column-ct.column||rt.length-ct.length);let U=0,nt=K;for(const rt of H){$(X,U,Math.min(rt.column,q),nt,D),nt+=(rt.column-U)*r;let ct=rt.length,it="";if(rt.piece){const Q=rt.piece.written??"",ot=R(`piece.${rt.piece.id}.write`);Q&&ot>0?(it=Q.slice(0,Math.round(ot*Q.length)),ct=rt.length+(Q.length-rt.length)*Math.min(1,ot*2)):ct=rt.length*(1-R(`piece.${rt.piece.id}.away`))}else rt.insert&&(ct=rt.insert.chars*R(`insert.${rt.insert.id}.open`),rt.insert.text&&(it=rt.insert.text.slice(0,Math.round(R(`insert.${rt.insert.id}.type`)*rt.insert.text.length))));F.fillStyle=e.text;for(let Q=0;Q<it.length;Q++)it[Q]!==" "&&F.fillText(it[Q],nt+Q*r,D);nt+=ct*r,U=rt.column+rt.length}$(X,U,Math.max(U,q),nt,D);const at=R(`line.${X}.strike`);at>0&&(F.strokeStyle=e.strike,F.lineWidth=Math.max(1.5,s/10),F.beginPath(),F.moveTo(K,D),F.lineTo(K+G*Math.min(1,at),D),F.stroke()),F.restore()});for(const C of w){const z=R(`piece.${C.id}.opacity`);if(z<=0||R(`line.${C.line}.wipe`)>=1)continue;const X=K+(C.column+C.text.length/2)*r+R(`piece.${C.id}.x`),W=st(C.line)+i/2+R(`piece.${C.id}.y`);F.save(),F.globalAlpha=Math.min(1,z),F.translate(X,W),F.rotate(R(`piece.${C.id}.rotate`)*Math.PI/180),$(C.line,C.column,C.column+C.text.length,-C.text.length*r/2,0),F.restore()}F.restore()}},j=F=>{const{kind:B,rest:Y}=jn(F),R=K=>gn("codePanel",F,Ji,K);if(B==="box"){if(Y)throw R("box takes no arguments");return{kind:B}}if(B==="line"){if(!/^\d+$/.test(Y))throw R("write it line:N");return{kind:B,n:Number(Y)}}if(B==="token"){const K=/^(\d+)(?:#(\d+))?:(.+)$/.exec(Y);if(!K)throw R("write it token:N:TEXT, or token:N#K:TEXT for the Kth");return{kind:B,n:Number(K[1]),occurrence:K[2]?Number(K[2]):1,text:K[3]}}if(B==="spot"){const K=/^(\d+):(\d+)(?::(\d+))?$/.exec(Y);if(!K)throw R("write it spot:N:C, or spot:N:C:W for W characters");return{kind:B,n:Number(K[1]),column:Number(K[2]),width:K[3]?Number(K[3]):1}}throw R()},V=(F,B,Y,R=!1)=>{const K=Array.isArray(B)?B:[B];if(K.length===0||R&&K.length>1)throw new Error(`codePanel.edit: ${F} takes ${R?"one":"at least one"} ${Y} anchor`);return K.map(st=>{const $=j(st);if($.kind!==Y)throw new Error(`codePanel.edit: ${F} takes ${Y} anchors (${Y}:…), not "${st}"`);return $})},tt=(F,B)=>{if(typeof B.text!="string")throw new Error(`codePanel.edit: ${F} needs \`text\` (the text to write)`);return B.text},J={kind:"code",about:Ji,target:L,lines:n,box:A(t.x,t.y,c,h),line(F,B=1/0){return S(F),A(u,P(F)-T(F,B)*i,Math.max(1,n[F-1].length)*r,i)},token(F,B,Y=1,R=1/0){S(F);const K=O(F,B,Y);return A(u+K*r,P(F)-T(F,R)*i,B.length*r,i)},highlight(F,B){for(const Y of I(F)){const R=M(`line.${Y}.highlight`,0);E(Y,"highlight",R,B.on===!1?0:1,B,200)}return J},strike(F,B){for(const Y of I(F))E(Y,"strike",M(`line.${Y}.strike`,0),1,B);return J},remove(F,B){const Y=I(F),R=B.style??"wipe";if(!jo.includes(R))throw new Error(`codePanel.remove: ${dt("style",R,jo)}`);const K=R==="wipe"?300:450,st=B.at+(B.duration??K),$=B.close??250;for(const C of Y)E(C,"wipe",0,1,{...B,easing:B.easing??(R==="fly"?"ease-in":void 0)},K),v.set(C,{style:R,from:B.from??"left"}),y.push({line:C,closed:st+$});for(let C=1;C<=n.length;C++){if(Y.includes(C))continue;const z=Y.filter(W=>W<C).length;if(z===0)continue;const X=M(`line.${C}.shift`,0);E(C,"shift",X,X+z,{at:st,duration:$,easing:"ease-in-out"})}return J},type(F,B){return E(F,"reveal",0,1,{duration:n[F-1].length*45,...B}),J},piece(F,B,Y=1){if(typeof F=="string"){const C=j(F);if(C.kind!=="token")throw new Error(`codePanel.piece: a piece is a word, token:N:TEXT, not "${F}"`);return J.piece(C.n,C.text,C.occurrence)}const R=F;if(B===void 0)throw new Error('codePanel.piece: which word? piece(n, text) or piece("token:N:TEXT")');S(R);const K=O(R,B,Y),st=w.find(C=>C.line===R&&C.column===K&&C.text===B);if(st)return st;if(w.some(C=>C.line===R&&K<C.column+C.text.length&&C.column<K+B.length))throw new Error(`codePanel: "${B}" on line ${R} overlaps another piece`);const $={id:w.length+1,line:R,column:K,text:B,home:J.token(R,B,Y,0)};w.push($);for(const C of["x","y","rotate","write","away"])_[`piece.${$.id}.${C}`]=0;return _[`piece.${$.id}.opacity`]=1,$},follow(F,B){return p.follow(F,B),J},fling(F,B){return p.fling(F,B),J},move(F,B){return p.move(F,B),J},write(F,B,Y){return F.written=B,x(`piece.${F.id}.write`,0,1,{duration:Math.max(1,B.length)*70,...Y}),J},spot(F,B,Y=1,R=1/0){S(F);const K=k.filter(st=>st.line===F&&st.column<=B&&st.at<=R).reduce((st,$)=>st+$.chars,0);return A(u+(B+K)*r,P(F)-T(F,R)*i,Y*r,i)},insert(F,B,Y,R){S(F);const K={id:k.length+1,line:F,column:B,chars:Y.length,text:Y,at:R.at};k.push(K),_[`insert.${K.id}.open`]=0,_[`insert.${K.id}.type`]=0;const st=R.duration??Y.length*70;return x(`insert.${K.id}.open`,0,1,{at:R.at,duration:st*.6,easing:"ease-out"}),x(`insert.${K.id}.type`,0,1,{at:R.at,duration:st}),J},drop(F,B,Y,R){S(B);const K=R.duration??250,st=B===F.line,$=R.easing??(st?"linear":"ease-out"),C=J.landing(F,B,Y,R.at),z={id:k.length+1,line:B,column:Y,chars:F.text.length,at:R.at};return k.push(z),_[`insert.${z.id}.open`]=0,x(`insert.${z.id}.open`,0,1,{at:R.at,duration:K,easing:st?$:"ease-out"}),x(`piece.${F.id}.away`,M(`piece.${F.id}.away`,0),1,{at:R.at,duration:K,easing:st?$:"ease-in-out"}),p.cutAfter(F,R.at),J.move(F,{at:R.at,duration:K,easing:$,to:{x:C.x,y:C.y}}),x(`piece.${F.id}.rotate`,g.valueAt(`piece.${F.id}.rotate`,R.at),0,{at:R.at,duration:K}),J},landing(F,B,Y,R=1/0){const K=J.spot(B,Y,F.text.length,R),st=B===F.line&&Y>F.column?F.text.length*r:0;return A(K.left-st,K.top,K.width,K.height)},ride(F,B,Y){const R=n.map((K,st)=>{const $=g.keys(`line.${st+1}.shift`)??[];return{top:P(st+1),offset:C=>-zo($,C)*i,windows:Rs($)}});return qo(F,B,{ground:Y.ground,every:Y.every??fn,floors:R})},tracks:g.tracks,anchor(F,B=1/0){const Y=j(F);return Y.kind==="box"?J.box:Y.kind==="line"?J.line(Y.n,B):Y.kind==="token"?J.token(Y.n,Y.text,Y.occurrence,B):J.spot(Y.n,Y.column,Y.width,B)},edit(F,B,Y){const R=()=>V(F,B,"line").map(K=>K.n);if(F==="highlight")return J.highlight(R(),Y);if(F==="strike")return J.strike(R(),Y);if(F==="remove")return J.remove(R(),Y);if(F==="type"){for(const K of R())J.type(K,Y);return J}if(F==="insert"){const[K]=V(F,B,"spot",!0);return J.insert(K.n,K.column,tt(F,Y),Y)}if(F==="write"||F==="drop"||F==="move"||F==="fling"){const[K]=V(F,B,"token",!0),st=J.piece(K.n,K.text,K.occurrence);if(F==="write")return J.write(st,tt(F,Y),Y);if(F==="fling")return J.fling(st,Y);if(F==="drop"){const C=typeof Y.into=="string"?j(Y.into):void 0;if(C?.kind!=="spot")throw new Error("codePanel.edit: drop needs `into`, a spot anchor (spot:N:C)");return J.drop(st,C.n,C.column,Y)}const $=typeof Y.to=="string"?J.anchor(Y.to,Y.at):Y.to;if(!$||typeof $.x!="number"||typeof $.y!="number")throw new Error("codePanel.edit: move needs `to`, an anchor name or { x, y }");return J.move(st,{...Y,to:$})}throw Vi("codePanel",F,Ji)}};return J}function gT(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 r=dT*n;if(r>.2&&"filter"in t&&(t.filter=`blur(${r.toFixed(1)}px)`),t.globalAlpha*=1-n,e.style==="fly"){const o=e.from==="right"?-1:1;t.translate(o*n*uT*i,0),t.rotate(o*n*.08)}else{const o=1+.08*n,a=s.left+s.width/2,l=s.top+s.height/2;t.translate(a,l),t.scale(o,o),t.translate(-a,-l)}}const bh={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 mT(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(([r])=>r.test(s));i&&(n[s]=i[1])}return n}function Yp(t,e,n,s,i,r){t.beginPath(),t.moveTo(e+r,n),t.arcTo(e+s,n,e+s,n+i,r),t.arcTo(e+s,n+i,e,n+i,r),t.arcTo(e,n+i,e,n,r),t.arcTo(e,n,e+s,n,r),t.closePath()}const Ko={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:[]};Ko.typescript=[...Ko.javascript,"enum","interface","type","implements","private","public","readonly","keyof","as","declare","namespace"];const Yo=Object.keys(Ko),pT={go:"//",rust:"//",csharp:"//",javascript:"//",typescript:"//",python:"#",plain:null};function Xp(t,e){const n=new Set(Ko[e]),s=pT[e],i=[],r=(a,l)=>{const c=i[i.length-1];c&&c.kind===l?c.text+=a:i.push({text:a,kind:l})};let o=0;for(;o<t.length;){const a=t[o];if(e!=="plain"&&s&&t.startsWith(s,o)){r(t.slice(o),"comment");break}if(e!=="plain"&&(a==='"'||a==="'"||a==="`")){let h=o+1;for(;h<t.length&&t[h]!==a;)h+=t[h]==="\\"?2:1;r(t.slice(o,h+1),"string"),o=h+1;continue}const l=/^[A-Za-z_][A-Za-z0-9_]*/.exec(t.slice(o));if(l){r(l[0],n.has(l[0])?"keyword":"text"),o+=l[0].length;continue}const c=/^\d[\d_.]*/.exec(t.slice(o));if(c&&e!=="plain"){r(c[0],"number"),o+=c[0].length;continue}r(a,"text"),o++}return i}const wh='"Patrick Hand", "Segoe Print", "Bradley Hand", "Comic Sans MS", "Chalkboard SE", cursive',Zi={whiteboard:{background:"#f7f7f2",frame:"#b8bcc4",ink:"#1f2a44",colors:{ink:"#1f2a44",red:"#d03b3b",blue:"#2f6fd0",green:"#2e9a52",orange:"#e07b1a"},font:wh,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:wh,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:wh,stroke:.08,opacity:1,rule:{color:"#c9d6ec",spacing:1.55,margin:"#f0a3a3"}}},kh=["circle","box","underline","arrow"],je={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"}},Gp=90,Up=300,yT=.3;function bT(t){const e=typeof t.theme=="string"?t.theme:"whiteboard";if(!(e in Zi))throw new Error(`whiteboard: ${dt("theme",e,Object.keys(Zi))}`);const n=typeof t.theme=="object"?{...Zi.whiteboard,...t.theme}:Zi[e],s=t.fontSize??28,i=t.charWidth??.55,r=k=>k===void 0?n.ink:n.colors[k]??k,o=k=>St(t.x+k.left,t.y+k.top,k.width,k.height),a=_s(),l=Ui(a),c={},h=new Map,u=[],d=[],f=(k,S,x,M)=>{const E=h.get(k);if(!E||E.kind!=="text")throw gn("whiteboard",M,je,`there is no text "${k}" (texts: ${m().join(", ")||"none"})`);let T=-1;for(let P=0;P<x;P++)if(T=E.item.text.indexOf(S,T+1),T<0)throw gn("whiteboard",M,je,`text "${k}" has no ${x>1?`${x}th `:""}"${S}"`);const A=E.size*i;return{column:T,box:St(E.box.left+T*A,E.box.top,S.length*A,E.box.height)}},m=()=>[...h.values()].filter(k=>k.kind==="text").map(k=>k.item.id),g=k=>{const{kind:S,rest:x}=jn(k),M=E=>gn("whiteboard",k,je,E);if(S==="box"){if(x)throw M("box takes no arguments");return{kind:S}}if(S==="text"||S==="mark"){if(!x)throw M(`write it ${S}:ID`);return{kind:S,id:x}}if(S==="term"){const E=/^([^:#]+)(?:#(\d+))?:(.+)$/.exec(x);if(!E)throw M("write it term:ID:TEXT, or term:ID#K:TEXT for the Kth");return{kind:S,id:E[1],occurrence:E[2]?Number(E[2]):1,text:E[3]}}throw M()},p=k=>{const S=g(k);if(S.kind==="box")return St(0,0,t.width,t.height);if(S.kind==="term")return f(S.id,S.text,S.occurrence,k).box;const x=h.get(S.id);if(!x||x.kind!==S.kind){const M=[...h.values()].filter(E=>E.kind===S.kind).map(E=>E.item.id);throw gn("whiteboard",k,je,`there is no ${S.kind} "${S.id}" (${S.kind}s: ${M.join(", ")||"none"})`)}return x.box};for(const k of t.items??[]){if(!k||typeof k.id!="string"||!k.id||/[:#]/.test(k.id))throw new Error(`whiteboard: every item needs an \`id\` without ":" or "#" (got ${JSON.stringify(k?.id)})`);if(h.has(k.id))throw new Error(`whiteboard: two items are called "${k.id}"`);if("text"in k){if(!Array.isArray(k.at)||k.at.length!==2||!k.at.every(P=>typeof P=="number"))throw new Error(`whiteboard: text "${k.id}" needs \`at\`, [x, y] from the board's top-left`);const T=k.size??s,A=St(k.at[0],k.at[1],Math.max(1,k.text.length)*T*i,T*1.3);h.set(k.id,{kind:"text",item:k,size:T,color:r(k.color),box:A}),c[`text.${k.id}.write`]=k.hidden?0:1,c[`text.${k.id}.erase`]=0;continue}if(!kh.includes(k.mark))throw new Error(`whiteboard: mark "${k.id}": ${dt("mark",k.mark,kh)}`);const S=k.mark==="arrow"?["from","to"]:["around"];for(const T of S)if(typeof k[T]!="string")throw new Error(`whiteboard: ${k.mark} "${k.id}" needs \`${T}\`, a place on the board (an item before it)`);const x=new Set([k.from,k.to].filter(T=>typeof T=="string").map(T=>T.split(":")[1])),M=k.mark==="arrow"?[...h.values()].filter(T=>T.kind==="text"&&!x.has(T.item.id)).map(T=>T.box):[],E=wT(k,p,s,M);h.set(k.id,{kind:"mark",item:k,color:r(k.color),points:E,box:MT(E)}),c[`mark.${k.id}.draw`]=k.hidden?0:1,c[`mark.${k.id}.erase`]=0}const y=k=>u.filter(S=>S.item===k),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 ST(Object.keys(c))},actions:je.edits},draw(k,S){const x=S.props??{},M=E=>Number(x[E]??c[E]??0);if(k.save(),k.fillStyle=n.background,Zp(k,0,0,t.width,t.height,10),k.fill(),k.lineWidth=Math.max(4,t.width*.012),k.strokeStyle=n.frame,k.stroke(),n.rule){k.save(),k.beginPath(),Zp(k,0,0,t.width,t.height,10),k.clip(),k.lineWidth=1,k.strokeStyle=n.rule.color;const E=s*(n.rule.spacing??1.55);for(let T=E;T<t.height;T+=E)k.beginPath(),k.moveTo(0,T),k.lineTo(t.width,T),k.stroke();n.rule.margin&&(k.strokeStyle=n.rule.margin,k.beginPath(),k.moveTo(s*2.2,0),k.lineTo(s*2.2,t.height),k.stroke()),k.restore()}k.textAlign="center",k.textBaseline="middle",k.lineCap="round",k.lineJoin="round",k.globalAlpha=n.opacity;for(const E of h.values()){if(k.save(),vh(k,E.box,M(`${E.kind}.${E.item.id}.erase`)),E.kind==="text"){const T=y(E.item.id),A=M(`text.${E.item.id}.write`)*E.item.text.length;k.font=`${E.size}px ${n.font}`,k.fillStyle=E.color;for(let P=0;P<Math.ceil(A);P++)E.item.text[P]===" "||T.some(I=>P>=I.column&&P<I.column+I.text.length)||(k.globalAlpha=n.opacity*Math.min(1,A-P),k.fillText(E.item.text[P],E.box.left+(P+.5)*E.size*i,E.box.y))}else Jp(k,E.points,M(`mark.${E.item.id}.draw`),E.color,s*n.stroke,E.item.mark==="arrow");k.restore()}for(const E of d){const T=M(`strike.${E.id}.draw`);if(T<=0)continue;const{box:A}=E,P=A.height*.15;Jp(k,[{x:A.left-3,y:A.y+P},{x:A.right+3,y:A.y-P}],T,n.colors.red??n.ink,s*n.stroke*.8,!1)}for(const E of u){const T=h.get(E.item),A=T.size*i;k.font=`${T.size}px ${n.font}`,k.fillStyle=T.color;const P=E.written;if(P){const L=M(`piece.${E.id}.write`)*P.length,j=E.home.x-t.x-P.length*A/2;for(let V=0;V<Math.ceil(L);V++)P[V]!==" "&&(k.globalAlpha=n.opacity*Math.min(1,L-V),k.fillText(P[V],j+(V+.5)*A,E.home.y-t.y))}const I=M(`piece.${E.id}.opacity`)*Math.min(1,M(`text.${E.item}.write`)*T.item.text.length-E.column);if(I<=0)continue;k.save();const O={x:E.home.x-t.x,y:E.home.y-t.y},_={x:M(`piece.${E.id}.x`),y:M(`piece.${E.id}.y`)};vh(k,St(O.x+_.x-E.home.width/2,O.y+_.y-E.home.height/2,E.home.width,E.home.height),M(`piece.${E.id}.erase`)),Math.hypot(_.x,_.y)<1&&vh(k,T.box,M(`text.${E.item}.erase`)),k.globalAlpha=n.opacity*Math.min(1,I),k.translate(O.x+_.x,O.y+_.y),k.rotate(M(`piece.${E.id}.rotate`)*Math.PI/180);for(let L=0;L<E.text.length;L++)E.text[L]!==" "&&k.fillText(E.text[L],(L+.5-E.text.length/2)*A,0);k.restore()}k.restore()}},w={kind:"board",about:je,target:v,box:St(t.x,t.y,t.width,t.height),anchor(k){return o(p(k))},piece(k){const S=g(k);if(S.kind!=="term")throw new Error(`whiteboard.piece: a piece is a term, term:ID:TEXT, not "${k}"`);const{column:x,box:M}=f(S.id,S.text,S.occurrence,k),E=u.find(A=>A.item===S.id&&A.column===x&&A.text===S.text);if(E)return E;if(u.some(A=>A.item===S.id&&x<A.column+A.text.length&&A.column<x+S.text.length))throw new Error(`whiteboard: "${S.text}" in "${S.id}" overlaps another piece`);const T={id:u.length+1,item:S.id,column:x,text:S.text,home:o(M)};u.push(T);for(const A of["x","y","rotate","erase","write"])c[`piece.${T.id}.${A}`]=0;return c[`piece.${T.id}.opacity`]=1,T},edit(k,S,x){const M=Array.isArray(S)?S:[S];if(M.length===0)throw new Error(`whiteboard.edit: ${k} takes at least one anchor`);const E=M.map(P=>({name:P,anchor:g(P)}));for(const{name:P}of E)p(P);const T=(P,I=!1)=>{const O=E.find(_=>!P.includes(_.anchor.kind));if(O)throw new Error(`whiteboard.edit: ${k} takes ${P.join(" or ")} anchors, not "${O.name}"`);if(I&&E.length>1)throw new Error(`whiteboard.edit: ${k} takes one ${P.join(" or ")} anchor`)},A=()=>w.piece(E[0].name);if(k==="write"){if(E.some(P=>P.anchor.kind==="term")){if(T(["term"],!0),typeof x.text!="string")throw new Error("whiteboard.edit: write into a term needs `text` (the new text)");const P=A();return P.written=x.text,a.tween(`piece.${P.id}.write`,0,1,{duration:Math.max(Up,x.text.length*Gp),...x}),w}T(["text"]);for(const{anchor:P}of E){const I=P.id,O=h.get(I).item.text;a.tween(`text.${I}.write`,0,1,{duration:Math.max(Up,O.length*Gp),...x})}return w}if(k==="draw"){T(["mark"]);for(const{anchor:P}of E)a.tween(`mark.${P.id}.draw`,0,1,{duration:500,...x});return w}if(k==="erase"){T(["text","term","mark"]);for(const P of E){const I=P.anchor.kind==="term"?`piece.${w.piece(P.name).id}.erase`:`${P.anchor.kind}.${P.anchor.id}.erase`;a.tween(I,0,1,{duration:400,...x})}return w}if(k==="strike"){T(["text","term"]);for(const P of E){const I={id:d.length+1,box:p(P.name)};d.push(I),c[`strike.${I.id}.draw`]=0,a.tween(`strike.${I.id}.draw`,0,1,{duration:250,...x})}return w}if(k==="move"){T(["term"],!0);const P=typeof x.to=="string"?w.anchor(x.to):x.to;if(!P||typeof P.x!="number"||typeof P.y!="number")throw new Error("whiteboard.edit: move needs `to`, an anchor name or { x, y }");return w.move(A(),{...x,to:P})}if(k==="fling")return T(["term"],!0),w.fling(A(),x);throw Vi("whiteboard",k,je)},follow(k,S){return l.follow(k,S),w},fling(k,S){return l.fling(k,S),w},move(k,S){return l.move(k,S),w},ride(k){return k},tracks:a.tracks};return w}function wT(t,e,n,s=[]){const i=Se(re(t.id)),r=g=>(i.next()*2-1)*g,o=n*yT;if(t.mark==="arrow"){const g=e(t.from),p=e(t.to),y=Vp(g,p,o*.6),v=Vp(p,g,o*.6),w=Math.hypot(v.x-y.x,v.y-y.y),k=vT(y,v);let S=w*(.06+r(.04));if(t.bend!==void 0)S=w*t.bend;else{const E=kT(y,v,k,s,o);E!==0&&(S=E)}const x={x:(y.x+v.x)/2+k.x*S,y:(y.y+v.y)/2+k.y*S},M=[];for(let E=0;E<=24;E++){const T=E/24;M.push({x:(1-T)**2*y.x+2*(1-T)*T*x.x+T*T*v.x,y:(1-T)**2*y.y+2*(1-T)*T*x.y+T*T*v.y})}return M}const a=e(t.around);if(t.mark==="underline"){const g=a.bottom+o*.4;return[{x:a.left-o*.3,y:g+r(2)},{x:a.x,y:g+2+r(2)},{x:a.right+o*.5,y:g-1+r(3)}]}if(t.mark==="box"){const g=a.left-o,p=a.right+o,y=a.top-o*.6,v=a.bottom+o*.6,w=(S,x)=>({x:S+r(o*.2),y:x+r(o*.2)}),k=w(g,y);return[k,w(p,y),w(p,v),w(g,v),k,{x:k.x+o*.8,y:k.y+r(2)}]}const l=a.width/2+o,c=a.height/2+o*.6,h=-2.2+r(.3),u=i.next()*Math.PI*2,d=1.12,f=64,m=[];for(let g=0;g<=f*d;g++){const p=g/f,y=h+p*Math.PI*2,v=1+.035*Math.sin(p*Math.PI*4+u)+.06*p;m.push({x:a.x+Math.cos(y)*l*v,y:a.y+Math.sin(y)*c*v})}return m}function kT(t,e,n,s,i){const r=Math.hypot(e.x-t.x,e.y-t.y);if(r<1e-6)return 0;const o={x:(e.x-t.x)/r,y:(e.y-t.y)/r};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(m=>({t:(m.x-t.x)*o.x+(m.y-t.y)*o.y,n:(m.x-t.x)*n.x+(m.y-t.y)*n.y})),d=u.some(m=>m.t>0&&m.t<r),f=u.some(m=>m.n>0)&&u.some(m=>m.n<0);!d||!f||(a=Math.max(a,...u.map(m=>m.n)),l=Math.min(l,...u.map(m=>m.n)))}return a===0&&l===0?0:a<=-l?2*(a+i):2*(l-i)}function Vp(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 r=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*r,y:t.y+i*r}}function vT(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 MT(t){const e=t.map(r=>r.x),n=t.map(r=>r.y),s=Math.min(...e),i=Math.min(...n);return St(s,i,Math.max(...e)-s,Math.max(...n)-i)}function Jp(t,e,n,s,i,r){if(n<=0||e.length<2)return;const o=[0];for(let m=1;m<e.length;m++)o.push(o[m-1]+Math.hypot(e[m].x-e[m-1].x,e[m].y-e[m-1].y));const l=o[o.length-1]*Math.min(1,n/(r?.85:1));t.strokeStyle=s,t.lineWidth=i,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let m=1;m<e.length;m++){if(o[m]<=l){t.lineTo(e[m].x,e[m].y);continue}const g=(l-o[m-1])/(o[m]-o[m-1]||1);t.lineTo(e[m-1].x+(e[m].x-e[m-1].x)*g,e[m-1].y+(e[m].y-e[m-1].y)*g);break}if(t.stroke(),!r||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 m of[-1,1])t.moveTo(h.x,h.y),t.lineTo(h.x-Math.cos(d+m*.45)*f,h.y-Math.sin(d+m*.45)*f);t.stroke()}function vh(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 Zp(t,e,n,s,i,r){t.beginPath(),t.moveTo(e+r,n),t.arcTo(e+s,n,e+s,n+i,r),t.arcTo(e+s,n+i,e,n+i,r),t.arcTo(e,n+i,e,n,r),t.arcTo(e,n,e+s,n,r),t.closePath()}function ST(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(([r])=>r.test(s));i&&(n[s]=i[1])}return n}const Mh=["bar","line","pie","donut"],Qp='system-ui, -apple-system, "Segoe UI", sans-serif',Qi={light:{background:"#ffffff",text:"#3b4252",grid:"#d8dee9",color:"#4c7bd9",highlight:"#e8833a",palette:["#4c7bd9","#3fa66b","#b05cc9","#d9c04c","#4cb8c4","#d95c6f","#8a7a5a","#6b7a99"],font:Qp},dark:{background:"#1e2230",text:"#cdd6f4",grid:"#3a4055",color:"#89b4fa",highlight:"#fab387",palette:["#89b4fa","#a6e3a1","#cba6f7","#f9e2af","#94e2d5","#f38ba8","#b4a58a","#9399b2"],font:Qp}},Kn={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)"}},TT=600,ET=500,AT=200,xT=400,PT=.14,$T=Math.PI*2;function IT(t){if(!Mh.includes(t.kind))throw new Error(`chart: ${dt("kind",t.kind,Mh)}`);const e=typeof t.theme=="string"?t.theme:"light";if(!(e in Qi))throw new Error(`chart: ${dt("theme",e,Object.keys(Qi))}`);const n=typeof t.theme=="object"?{...Qi.light,...t.theme}:Qi[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",r=Array.isArray(t.series)&&t.series.length>1,o=Array.isArray(t.series)&&t.series.length>0?t.series:[{id:"value"}];if(i&&r)throw new Error(`chart: a ${s} shows one series (got ${o.length}); make a chart per series`);const a=new Set;for(const H of o){if(typeof H?.id!="string"||!H.id||/[:.]/.test(H.id))throw new Error(`chart: every series needs an \`id\` without ":" or "." (got ${JSON.stringify(H?.id)})`);if(a.has(H.id))throw new Error(`chart: two series are called "${H.id}"`);a.add(H.id)}const l=new Map(o.map((H,U)=>[H.id,U])),c=H=>o[l.get(H)].color??(l.get(H)===0?n.color:n.palette[l.get(H)%n.palette.length]),h=new Set,u=(H,U)=>{const nt=H.values?.[U.id]??(t.series?void 0:H.value)??H.value;if(typeof nt!="number"||!Number.isFinite(nt))throw new Error(r?`chart: "${H.id}" needs a value for series "${U.id}" (\`values: { ${U.id}: … }\`)`:`chart: "${H.id}" needs a \`value\`, a number`);return nt};for(const H of t.data){if(typeof H?.id!="string"||!H.id||/[:.]/.test(H.id))throw new Error(`chart: every datum needs an \`id\` without ":" or "." (got ${JSON.stringify(H?.id)})`);if(h.has(H.id))throw new Error(`chart: two data are called "${H.id}"`);for(const U of o)u(H,U);h.add(H.id)}const d=s==="bar"?"bar":s==="line"?"point":"slice",f=Math.max(...t.data.flatMap(H=>o.map(U=>u(H,U)))),m=i?t.data.reduce((H,U)=>H+u(U,o[0]),0):t.max??ty(f*1.1);if(!i&&!(m>0))throw new Error(`chart: \`max\` must be above 0 (got ${m})`);const g=Math.max(10,Math.min(16,t.height/20)),p=r&&t.legend!==!1,y=i?void 0:t.axis?.x,v=i?void 0:t.axis?.y,w=t.title?g*2.3:g*.5,k={left:g*3.6+(v?g*1.5:0),right:t.width-g,top:(t.title?g*3:g*1.6)+(p?g*1.6:0),bottom:t.height-g*2.4-(y?g*1.4:0)},S=k.bottom-k.top,x=(k.right-k.left)/t.data.length,M=r?x*.72/o.length:x*.6,E=r?M*.86:M,T=Math.max(4,g*.35),A=S/m,P=new Map(t.data.map((H,U)=>[H.id,U])),I=H=>k.left+x*(P.get(H)+.5),O=(H,U)=>r?I(H)-x*.36+M*l.get(U)+(M-E)/2:I(H)-E/2,_=(H,U)=>O(H,U)+E/2,L=t.height-g*1.2,j={cx:t.width/2,cy:(k.top+L)/2,r:Math.max(10,Math.min(t.width/2,(L-k.top)/2)-g*2.6)},V=s==="donut"?j.r*.55:0,tt=s==="donut"?(V+j.r)/2:j.r*.62,J=new Map;if(p){let H=k.right;for(const U of[...o].reverse()){const nt=U.label??U.id,at=g*.62*nt.length+g*1.9;J.set(U.id,St(H-at,w,at,g*1.4)),H-=at+g*.6}}const F=_s(),B=Ui(F),Y={},R=(H,U,nt)=>r?`${d}.${H}.${U}.${nt}`:`${d}.${H}.${nt}`;for(const H of t.data)for(const U of o)Y[R(H.id,U.id,"value")]=u(H,U),Y[R(H.id,U.id,"show")]=H.hidden?0:1,Y[R(H.id,U.id,"highlight")]=0,i&&(Y[R(H.id,U.id,"pull")]=0);const K=(H,U)=>F.keys(H)?.length?zo(F.keys(H),U):Y[H],st=(H,U,nt)=>K(R(H,U,"value"),nt)*(s==="bar"?K(R(H,U,"show"),nt):1)*A,$=H=>{const U=o[0].id,nt=t.data.map(it=>Math.max(0,H(R(it.id,U,"value")))*Math.max(0,Math.min(1,H(R(it.id,U,"show"))))),at=nt.reduce((it,Q)=>it+Q,0),rt=new Map;let ct=-Math.PI/2;return t.data.forEach((it,Q)=>{const ot=at>0?$T*nt[Q]/at:0,ht=ct+ot/2,ft=Math.max(0,Math.min(1,H(R(it.id,U,"pull"))))*j.r*PT;rt.set(it.id,{start:ct,sweep:ot,mid:ht,out:ft,centre:{x:j.cx+Math.cos(ht)*(tt+ft),y:j.cy+Math.sin(ht)*(tt+ft)}}),ct+=ot}),rt},C=H=>$(U=>K(U,H)),z=H=>{const{kind:U,rest:nt}=jn(H),at=rt=>gn("chart",H,Kn,rt);if(U==="box"){if(nt)throw at("box takes no arguments");return{kind:"box"}}if(U==="legend"){if(!J.has(nt))throw at(p?`there is no series "${nt}" (series: ${o.map(rt=>rt.id).join(", ")})`:"only a chart with several series has a legend");return{kind:"legend",series:nt}}if(U==="bar"||U==="point"||U==="slice"||U==="label"||U==="value"){if(!nt)throw at(`write it ${U}:ID`);const rt=nt.indexOf(":"),ct=rt<0?nt:nt.slice(0,rt),it=rt<0?o[0].id:nt.slice(rt+1);if(!P.has(ct))throw at(`there is no "${ct}" (data: ${[...P.keys()].join(", ")})`);if(!a.has(it))throw at(`there is no series "${it}" (series: ${o.map(Q=>Q.id).join(", ")})`);if(U==="label"&&rt>=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:it}}throw at()},X=(H,U)=>{if(H.kind==="box")return St(0,0,t.width,t.height);if(H.kind==="legend")return J.get(H.series);if(i){const it=C(U).get(H.id),Q=Math.max(g*1.5,j.r*.42);if(H.kind==="slice")return St(it.centre.x-Q/2,it.centre.y-Q/2,Q,Q);const ot=W(it);return H.kind==="label"?ot:it.sweep>=.3?St(it.centre.x-g*1.6,it.centre.y-g*.65,g*3.2,g*1.3):St(ot.left,ot.bottom,ot.width,g*1.3)}const nt=H.kind==="label"?I(H.id):_(H.id,H.series),at=k.bottom-st(H.id,H.series,U);if(H.kind==="bar")return St(nt-E/2,at,E,k.bottom-at);if(H.kind==="point")return St(I(H.id)-T,at-T,T*2,T*2);if(H.kind==="label")return St(nt-x/2,k.bottom+g*.4,x,g*1.4);const rt=at-(s==="line"?T:0)-g*.3,ct=r&&s==="bar"?M:x;return St((s==="line"?I(H.id):nt)-ct/2,rt-g*1.3,ct,g*1.3)},W=H=>{const U=j.r+H.out+g*.9,nt={x:j.cx+Math.cos(H.mid)*U,y:j.cy+Math.sin(H.mid)*U},at=g*4.2,rt=Math.cos(H.mid),ct=rt>.2?nt.x:rt<-.2?nt.x-at:nt.x-at/2;return St(ct,nt.y-g*.7,at,g*1.4)},N=H=>St(t.x+H.left,t.y+H.top,H.width,H.height),D=H=>`${t.prefix??""}${H.toFixed(t.decimals??0)}${t.suffix??""}`,G=new Map,q={type:"custom",x:t.x,y:t.y,width:t.width,height:t.height,props:Y,about:{kind:`${s} chart`,summary:`A ${s} chart of ${t.data.length} values (${t.data.map(H=>H.id).join(", ")})${r?` in ${o.length} series (${o.map(H=>H.id).join(", ")})`:""}${i?"":`, scaled to ${m}`}. Its ${d}s and labels are places in the scene (anchor()); its edits record tracks (edit(), tracks()).`,props:Object.fromEntries(Object.keys(Y).map(H=>[H,_T(H)])),actions:Kn.edits},draw(H,U){const nt=U.props??{},at=it=>Number(nt[it]??Y[it]??0);if(H.save(),H.fillStyle=n.background,ey(H,0,0,t.width,t.height,8),H.fill(),H.font=`${g}px ${n.font}`,H.textBaseline="middle",t.title&&(H.fillStyle=n.text,H.textAlign="left",H.font=`600 ${g*1.2}px ${n.font}`,H.fillText(t.title,i?g:k.left,g*1.5),H.font=`${g}px ${n.font}`),p){H.textAlign="left";for(const it of o){const Q=J.get(it.id);H.fillStyle=c(it.id),ey(H,Q.left,Q.top+g*.25,g*.9,g*.9,2),H.fill(),H.fillStyle=n.text,H.fillText(it.label??it.id,Q.left+g*1.3,Q.top+Q.height/2)}}if(i){Z(H,at),H.restore();return}H.lineWidth=1,H.textAlign="right";for(let it=0;it<=4;it++){const Q=k.bottom-S*it/4;H.strokeStyle=n.grid,H.beginPath(),H.moveTo(k.left,Q),H.lineTo(k.right,Q),H.stroke(),H.fillStyle=n.text,H.globalAlpha=.7,H.fillText(OT(m*it/4),k.left-g*.5,Q),H.globalAlpha=1}(v||y)&&(H.fillStyle=n.text,H.textAlign="center",H.globalAlpha=.85,v&&(H.save(),H.translate(g*.9,(k.top+k.bottom)/2),H.rotate(-Math.PI/2),H.fillText(v,0,0),H.restore()),y&&H.fillText(y,(k.left+k.right)/2,k.bottom+g*2.3),H.globalAlpha=1);const rt=(it,Q)=>at(R(it,Q,"value"))*(s==="bar"?at(R(it,Q,"show")):1)*A,ct=(it,Q)=>Sh(c(Q),n.highlight,at(R(it,Q,"highlight")));if(s==="line"){H.lineWidth=Math.max(2,g*.2),H.lineJoin="round",H.lineCap="round";for(const it of o)H.strokeStyle=c(it.id),H.beginPath(),t.data.forEach((Q,ot)=>{const ht={x:I(Q.id),y:k.bottom-rt(Q.id,it.id)},ft=at(R(Q.id,it.id,"show"));if(ot===0){ft>0&&H.moveTo(ht.x,ht.y);return}const bt=t.data[ot-1];if(at(R(bt.id,it.id,"show"))<1||ft<=0)return;const wt={x:I(bt.id),y:k.bottom-rt(bt.id,it.id)};H.lineTo(wt.x+(ht.x-wt.x)*ft,wt.y+(ht.y-wt.y)*ft)}),H.stroke()}H.textAlign="center";for(const it of t.data){for(const Q of o){const ot=s==="bar"?_(it.id,Q.id):I(it.id),ht=rt(it.id,Q.id),ft=at(R(it.id,Q.id,"show"));if(H.fillStyle=ct(it.id,Q.id),s==="bar"?ht>.5&&(CT(H,ot-E/2,k.bottom-ht,E,ht,Math.min(6,E/4)),H.fill()):ft>0&&(H.beginPath(),H.arc(ot,k.bottom-ht,T*Math.min(1,ft*1.5)*(1+.3*at(R(it.id,Q.id,"highlight"))),0,Math.PI*2),H.fill()),t.values!==!1&&ft>0){H.globalAlpha=Math.min(1,ft*2),H.font=`600 ${r?g*.85:g}px ${n.font}`,H.fillStyle=Sh(n.text,n.highlight,at(R(it.id,Q.id,"highlight")));const bt=k.bottom-ht-(s==="line"?T:0)-g*.95;H.fillText(D(at(R(it.id,Q.id,"value"))),ot,bt),H.font=`${g}px ${n.font}`,H.globalAlpha=1}}H.fillStyle=n.text,H.fillText(it.label??it.id,I(it.id),k.bottom+g*1.1)}H.strokeStyle=n.text,H.lineWidth=1.5,H.beginPath(),H.moveTo(k.left,k.bottom),H.lineTo(k.right,k.bottom),H.stroke(),H.restore()}};function Z(H,U){const nt=o[0].id,at=$(U);t.data.forEach((rt,ct)=>{const it=at.get(rt.id);if(it.sweep<=1e-4)return;const Q=G.get(rt.id),ot=Q?{x:U(`piece.${Q.id}.x`),y:U(`piece.${Q.id}.y`)}:{x:0,y:0},ht=Q?U(`piece.${Q.id}.rotate`)*Math.PI/180:0,ft=Q?U(`piece.${Q.id}.opacity`):1;if(ft<=0)return;H.save(),H.globalAlpha=ft;const bt={x:j.cx+Math.cos(it.mid)*it.out,y:j.cy+Math.sin(it.mid)*it.out};H.translate(it.centre.x+ot.x,it.centre.y+ot.y),H.rotate(ht),H.translate(-it.centre.x,-it.centre.y),H.beginPath(),H.arc(bt.x,bt.y,j.r,it.start,it.start+it.sweep),V>0?H.arc(bt.x,bt.y,V,it.start+it.sweep,it.start,!0):H.lineTo(bt.x,bt.y),H.closePath(),H.fillStyle=Sh(n.palette[ct%n.palette.length],n.highlight,U(R(rt.id,nt,"highlight"))),H.fill(),H.strokeStyle=n.background,H.lineWidth=Math.max(1.5,g*.15),H.stroke(),t.values!==!1&&it.sweep>=.3&&(H.fillStyle=n.background,H.font=`600 ${g}px ${n.font}`,H.textAlign="center",H.fillText(D(U(R(rt.id,nt,"value"))),it.centre.x,it.centre.y),H.font=`${g}px ${n.font}`),H.restore();const wt=W(it),Me=Math.cos(it.mid);H.globalAlpha=ft,H.fillStyle=n.text,H.textAlign=Me>.2?"left":Me<-.2?"right":"center";const gr=Me>.2?wt.left:Me<-.2?wt.right:wt.left+wt.width/2;H.fillText(rt.label??rt.id,gr,wt.top+wt.height/2),t.values!==!1&&it.sweep<.3&&(H.globalAlpha=ft*.8,H.fillText(D(U(R(rt.id,nt,"value"))),gr,wt.bottom+g*.65)),H.globalAlpha=1})}const et={kind:"chart",chartKind:s,about:Kn,target:q,max:m,box:St(t.x,t.y,t.width,t.height),anchor(H,U=1/0){return N(X(z(H),U))},piece(H){const U=z(H);if(U.kind!=="slice")throw new Error(i?`chart: a piece is a slice, slice:ID, not "${H}"`:`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 nt=G.get(U.id);if(nt)return nt;const at={id:G.size+1,datum:U.id,home:N(X(U,0))};G.set(U.id,at);for(const rt of["x","y","rotate"])Y[`piece.${at.id}.${rt}`]=0;return Y[`piece.${at.id}.opacity`]=1,at},edit(H,U,nt){const at=Array.isArray(U)?U:[U];if(at.length===0)throw new Error(`chart.edit: ${H} takes at least one anchor`);if(!(H in Kn.edits))throw Vi("chart",H,Kn);if(H==="pull"&&!i)throw new Error(`chart.edit: pull takes slice anchors of a pie or donut; a ${s} chart has ${d}s`);const rt=at.map(ct=>{const it=z(ct);if(it.kind!==d)throw new Error(`chart.edit: ${H} takes ${d} anchors (${d}:ID), not "${ct}"`);return it});for(const{id:ct,series:it}of rt){const Q=ot=>R(ct,it,ot);if(H==="set"){if(typeof nt.value!="number"||!Number.isFinite(nt.value))throw new Error("chart.edit: set needs `value`, a number");F.tween(Q("value"),K(Q("value"),nt.at),nt.value,nt,TT)}else H==="show"?F.tween(Q("show"),K(Q("show"),nt.at),nt.on===!1?0:1,nt,ET):H==="pull"?F.tween(Q("pull"),K(Q("pull"),nt.at),nt.on===!1?0:1,nt,xT):F.tween(Q("highlight"),K(Q("highlight"),nt.at),nt.on===!1?0:1,nt,AT)}return et},follow(H,U){return B.follow(H,U),et},fling(H,U){return B.fling(H,U),et},move(H,U){return B.move(H,U),et},ride(H,U,nt){if(s!=="bar")return H;const at=t.data.flatMap(rt=>o.map(ct=>{const it=st(rt.id,ct.id,0),Q=[...Rs(F.keys(R(rt.id,ct.id,"value"))),...Rs(F.keys(R(rt.id,ct.id,"show")))];return{top:t.y+k.bottom-it,offset:ot=>it-st(rt.id,ct.id,ot),windows:Q}}));return qo(H,U,{ground:nt.ground,every:nt.every??fn,floors:at})},tracks:F.tracks};return et}function ty(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 OT(t){return Number.isInteger(t)?String(t):String(Number(t.toFixed(2)))}function Sh(t,e,n){if(n<=0)return t;if(n>=1)return e;const s=o=>[1,3,5].map(a=>parseInt(o.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,r]=[s(t),s(e)];return`#${i.map((o,a)=>Math.round(o+(r[a]-o)*n).toString(16).padStart(2,"0")).join("")}`}function ey(t,e,n,s,i,r){t.beginPath(),t.moveTo(e+r,n),t.arcTo(e+s,n,e+s,n+i,r),t.arcTo(e+s,n+i,e,n+i,r),t.arcTo(e,n+i,e,n,r),t.arcTo(e,n,e+s,n,r),t.closePath()}function CT(t,e,n,s,i,r){const o=Math.min(r,i);t.beginPath(),t.moveTo(e,n+i),t.lineTo(e,n+o),t.arcTo(e,n,e+o,n,o),t.lineTo(e+s-o,n),t.arcTo(e+s,n,e+s,n+o,o),t.lineTo(e+s,n+i),t.closePath()}function _T(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 ny(){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 tr={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}],measurements:{height:165,bust:86,underbust:72,waist:58,hip:88}},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:ny(),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:ny(),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 RT(t,e={}){if(!Object.prototype.hasOwnProperty.call(tr,t))throw new Error(`softCartoonCharacter: unknown actor '${t}'`);const n=tr[t],s={...n.body};return e.body?.measurements!==void 0&&delete s.torso,Ps({...n,...e,body:{...s,...e.body},face:{...n.face,...e.face}})}const sy={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"}}}},iy={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"}}}},ry={beanMan:{label:"Bean man",group:"bean",scale:1,options:{figure:"bean",hair:{style:"short",color:"#1f1f1f"}}},beanWoman:{label:"Bean woman",group:"bean",scale:.96,options:{figure:"bean",hair:{style:"bob",color:"#1f1f1f"},bean:{torso:.95}}},beanKid:{label:"Bean kid",group:"bean",scale:.72,options:{figure:"bean",headSize:.36,legLength:.9,armLength:.92,hair:{style:"spiky",color:"#1f1f1f"},bean:{shirt:"#f2b134",trousers:"#3d5a80",torso:.9}}},beanBoss:{label:"Bean boss",group:"bean",scale:1,options:{figure:"bean",hair:{style:"slickBack",color:"#4a4a4a"},facialHair:"shortMoustache",glasses:"square",bean:{shirt:"#5b7aa6",trousers:"#2b2f3a",sleeves:"long",torso:1.25}}},beanDetective:{label:"Bean detective",group:"bean",scale:1,options:{figure:"bean",hair:{style:"short",color:"#2a2a2a"},bean:{coat:"#b08a5a",fedora:"#5b4636",shades:!0,trousers:"#2b2f3a",shoes:"#1a1a1a"}}},beanStick:{label:"Bean stick figure",group:"bean",scale:1,options:{figure:"bean",bean:{limbs:"line"}}},beanSari:{label:"Bean woman in a sari",group:"bean",scale:.96,options:{figure:"bean",hair:{style:"lowBun",color:"#1f1f1f"},bean:{torso:1.05,shirt:"#7c2d12",sleeves:"short",skirt:"#c2410c",drape:"#ea580c",bangles:"#d4a017",shoes:"#7c2d12"}}}},Th={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:Fe.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:Fe.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:Fe.black},ears:!0,outfit:{shirt:"#9b5fc0",trousers:"#2f2f3a",sleeves:"long"}}},grandpa:{label:"Grandpa",group:"family",scale:.96,options:{build:"stocky",hair:{style:"receding",color:Fe.gray},facialHair:{style:"shortBoxed",color:Fe.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:Fe.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:Fe.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:Fe.blond},hat:"sunHat",ears:!0,outfit:{shirt:"#d64535",trousers:"#4f6b3a",sleeves:"long"}}},...sy,...iy,...ry};function HT(t,e=300,n={}){const s=Th[t];if(!s)throw new Error(`castMember: unknown cast member '${t}'`);return{...s.options,height:Math.round(e*s.scale),...n}}const er={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 FT(t,e,n){return er[t].spacing*Math.min(e.height,n.height)}const oy=.075;function LT(t,e,n,s={}){const i=er[t];if(!i)throw new Error(`meetHands: unknown meeting '${t}' (one of ${Object.keys(er).join(", ")})`);const[r,o]=e.x<=n.x?[e,n]:[n,e],a=s.view==="side",l=Math.min(r.character.height,o.character.height),c={x:(r.x+o.x)/2,y:-(s.height??i.height)*l},h=(p,y)=>{const v=y?a?1:.62:a?3:3.38;let w={...lt,...p.pose,turn:v,lean:(p.pose?.lean??0)+i.lean};const k=y?1:-1,S=(x,M,E)=>{w=qe(p.character,w,x,{x:c.x+M-p.x,y:c.y,depth:E})};if(t==="handOver"){const x=oy*l;S("arm.left",-k*x*.9,x),S("arm.right",-k*x*.9,-x)}else S("arm.right",0,0);return t==="fistBump"&&(w={...w,"hand.right.index.curl":1,"hand.right.middle.curl":1,"hand.right.ring.curl":1,"hand.right.pinky.curl":1}),w},u=h(r,!0),d=h(o,!1),f=.03*l,m=(p,y)=>{const v=ke(p.character,y),w=t==="handOver"?["hand.left","hand.right"]:["hand.right"],k=t==="handOver"?oy*l+f:f;return w.every(S=>Math.abs(v.points[S].y-c.y)<f&&Math.abs(v.points[S].x+p.x-c.x)<k)},g=m(r,u)&&m(o,d);return e.x<=n.x?{a:u,b:d,point:c,reached:g}:{a:d,b:u,point:c,reached:g}}const Xo={spacing:.3,lean:10,tilt:8};function NT(t,e){return Xo.spacing*Math.min(t.height,e.height)}function WT(t,e,n={}){const[s,i]=t.x<=e.x?[t,e]:[e,t],r=n.view==="side",o=Math.min(s.character.height,i.character.height),a=(m,g,p)=>({over:{x:g.x-p*.02*o-m.x,y:-.72*o,depth:-.08*o},round:{x:g.x-p*.04*o-m.x,y:-.5*o,depth:.06*o}}),l=(m,g,p)=>{const y=p?r?1:.62:r?3:3.38,v=p?1:-1;let w={...lt,...m.pose,turn:y,lean:(m.pose?.lean??0)+Xo.lean,"head.tilt":(m.pose?.["head.tilt"]??0)+v*Xo.tilt};const{over:k,round:S}=a(m,g,v);return w=qe(m.character,w,"arm.right",k),w=qe(m.character,w,"arm.left",S),w},c=l(s,i,!0),h=l(i,s,!1),u=.05*o,d=(m,g,p,y)=>{const v=ke(m.character,y).points,{over:w,round:k}=a(m,g,p);return Math.hypot(v["hand.right"].x-w.x,v["hand.right"].y-w.y)<u&&Math.hypot(v["hand.left"].x-k.x,v["hand.left"].y-k.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 Yn={spacing:.32,low:.3,high:.5,helperLean:40,helperBend:16};function DT(t,e){return Yn.spacing*Math.min(t.height,e.height)}function BT(t,e,n,s={}){const i=Math.max(0,Math.min(1,n)),r=s.view==="side",o=t.x<=e.x,a=Math.min(t.character.height,e.character.height),l={x:(t.x+e.x)/2,y:-(Yn.low+(Yn.high-Yn.low)*i)*a},c=p=>p?r?1:.62:r?3:3.38;let h={...lt,...t.pose,turn:c(o),lean:(t.pose?.lean??0)+Yn.helperLean*(1-i)+4,bend:(t.pose?.bend??0)+Yn.helperBend*(1-i),"head.nod":18*(1-i)};h=qe(t.character,h,"arm.right",{x:l.x-t.x,y:l.y});const u={...Ae.sitFloor,...e.pose,turn:c(!o)},d={...lt,...e.pose,turn:c(!o)};let f=Xc(u,d,i);f=qe(e.character,f,"arm.right",{x:l.x-e.x,y:l.y});const m=.04*a,g=(p,y)=>{const v=ke(p.character,y).points["hand.right"];return Math.hypot(v.x+p.x-l.x,v.y-l.y)<m};return{helper:h,sitter:f,point:l,reached:g(t,h)&&g(e,f)}}const Eh=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 ay(t,e={}){if(!Object.prototype.hasOwnProperty.call(Eh,t))throw new Error(`outfitPreset: unknown category '${t}'`);const n={...Eh[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 zT=.7,qT=50,jT=1.2,KT=.8,YT=3,XT=30,GT=.8,UT=.6,Ah=(t,e)=>Math.max(-e,Math.min(e,t)),VT=["hair.swing","hair.trail","hair.lift"];function ly(t,e){const n=e.start??0,s=e.amount??1,i=Math.max(1e-6,e.headRadius);let r=NaN,o={x:0,y:0,turn:0};const a=f=>(f!==r&&(o=t(f),r=f),o),l=f=>{const m=a(f);return m.turn*90+(m.headTurn??0)},c={start:n,end:e.end,step:e.step,stiffness:e.stiffness??70,damping:e.damping??6},h=li(l,c),u=li(f=>a(f).x,c),d=li(f=>a(f).y,c);return h.map((f,m)=>{const g=a(f.time),p=f.value-l(f.time),y=u[m].value-g.x-(e.wind??0)*zT*i,v=d[m].value-g.y,w=Math.sin(g.turn*Math.PI/2),k=Math.cos(g.turn*Math.PI/2),S=p*YT+y*k/i*XT,x=-y*w/i*GT,M=-v/i*UT;return{time:f.time,swing:Ah(S*s,qT),trail:Ah(x*s,jT),lift:Ah(M*s,KT)}})}function JT(t,e){if(t.length===0)return{"hair.swing":0,"hair.trail":0,"hair.lift":0};if(e<=t[0].time)return cy(t[0]);if(e>=t[t.length-1].time)return cy(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],r=t[s],o=r.time===i.time?0:(e-i.time)/(r.time-i.time);return{"hair.swing":i.swing+(r.swing-i.swing)*o,"hair.trail":i.trail+(r.trail-i.trail)*o,"hair.lift":i.lift+(r.lift-i.lift)*o}}const cy=t=>({"hair.swing":t.swing,"hair.trail":t.trail,"hair.lift":t.lift}),Hs=16,ZT=1500;function QT(t,e,n,s={}){const i=n.head.hair;if(!i||!zg(i))return[];const r=e.filter(v=>v.target===t),o=r.reduce((v,w)=>w.keyframes.reduce((k,S)=>Math.max(k,S.time),v),0),a=lt,l=new Set(["x","y","turn","head.turn"]),c=new Ht({id:`${t}-hair-follow`,tracks:r.filter(v=>l.has(v.property))}),h=(v,w,k)=>{const S=c.getStateAtTime(v).values.get(t)?.get(w);return typeof S=="number"?S:k},u=new Ht({id:`${t}-hair-pose`,tracks:r}),d=v=>u.getStateAtTime(v).values.get(t),f=new Map,m=v=>{const w=Math.round(v/Hs);let k=f.get(w);if(!k){const S={};for(const[M,E]of d(w*Hs)??[])S[M]=E;const x=ke(n,$o(S,a,s.gaits)).head.center;f.set(w,k={x:x.x,y:x.y})}return k},g=v=>{const w=Math.floor(v/Hs),k=v/Hs-w,S=m(w*Hs),x=m((w+1)*Hs);return{x:S.x+(x.x-S.x)*k,y:S.y+(x.y-S.y)*k}},p=ly(v=>{const w=g(v);return{x:h(v,"x",0)+w.x,y:h(v,"y",0)+w.y,turn:h(v,"turn",a.turn??0),headTurn:h(v,"head.turn",a["head.turn"]??0)}},{start:0,end:o+(s.settle??ZT),headRadius:ke(n,lt).head.rx,step:s.step,stiffness:s.stiffness,damping:s.damping,amount:s.amount,wind:s.wind}),y=[];for(const v of VT){const w=v.slice(5);let k=p.map(x=>({time:x.time,value:x[w]}));if(k.every(x=>Math.abs(x.value)<.001))continue;const S=r.find(x=>x.property===v);if(S){const x=new Ht({id:`${t}-${v}-own`,tracks:[S]}),M=E=>Number(x.getStateAtTime(E).values.get(t)?.get(v)??0);k=k.map(E=>({time:E.time,value:E.value+M(E.time)}))}y.push({id:`${t}-${v}`,target:t,property:v,keyframes:k})}return y}const Xn={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 xh(t){if(t===void 0)return Xn.full;if(typeof t=="string")return Xn[t];const{base:e,...n}=t;return{...Xn[e??"full"],...n}}const Ph=160,t4=120,e4=700,$h=60,n4=90,Go=3200,Fs=1,Gn=1e-6;function Uo(t,e,n={}){const s=xh(n.style),i=n.seed??1,r={};if(t.length===0)return r;const o=Object.keys(t[0].pose).filter(u=>t.some(d=>Math.abs(d.pose[u]-t[0].pose[u])>Gn));for(const u of o)r[u]=s4(u,t,e,s,i);const a=e.blink,l=a!==void 0&&o.includes(a);if(s.blinks&&a!==void 0&&!l&&a in t[0].pose){const u=i4(t,e,s,i,t[0].pose[a]);u.length>0&&(r[a]=u)}const{lift:c,stretch:h}=e;if(s.jumpSquash>0&&c&&h&&o.includes(c)&&!o.includes(h)&&h in t[0].pose){const u=r4(t,c,t[0].pose[h],s.jumpSquash);u.length>0&&(r[h]=u)}return r}function s4(t,e,n,s,i){const r=n.eyes.includes(t),o=n.limits[t],a=o!==void 0,l=r?-s.eyeLead:(n.depth[t]??1)*s.overlap,c=f=>{const m=(e[f].time-e[f-1].time)/2;return Math.max(-m,Math.min(m,l))},h=[{time:e[0].time,value:e[0].pose[t]}],u=(f,m,g)=>{const p=h[h.length-1];if(f<=p.time+Fs){h[h.length-1]={...p,value:m,...g?{easing:g}:{}};return}h.push({time:f,value:m,...g?{easing:g}:{}})};let d=e[0].pose[t];for(let f=1;f<e.length;f++){const m=e[f],g=e[f-1].pose[t],p=m.pose[t],y=p-g,v=h[h.length-1].time,w=m.act!==!1;if(Math.abs(y)<=Gn){const P=m.time+(w?c(f):0);if(f===e.length-1)Math.abs(d-p)>Gn&&u(Math.max(P,v+Ph),p,"ease-in-out"),d=p;else if(w&&a&&s.drift>0&&n.drift.includes(t)&&P-v>=e4){const I=re(`${i}:${t}:${f}`)%2===0?1:-1;d=p+I*s.drift*o,u(P,d,"ease-in-out")}continue}if(!w){u(e[f-1].time,d),u(m.time,p,m.easing),d=p;continue}const k=c(f),S=Math.max(e[f-1].time+k,v);let x=m.time+k;r&&s.eyeDart>0&&(x=Math.min(x,S+s.eyeDart));const M=x-S;if(M<=Fs){u(m.time,p,m.easing),d=p;continue}u(S,d);const E=Math.sign(y);if(a&&s.anticipation>0&&o>0&&M>=Ph){const P=d-E*Math.min(Math.abs(y)*s.anticipation,o),I=S+M*s.anticipationTime;u(I,P,"ease-in-out"),s.hold>0&&u(I+M*s.hold,P)}const T=f+1<e.length?e[f+1].time-m.time:1/0,A=Math.min(s.settle,T/2);if(a&&s.overshoot>0&&o>0&&M>=t4&&A>Fs){const P=Math.min(Math.abs(y)*s.overshoot,o);u(x,p+E*P,m.easing??s.actionEase),u(x+A,p,s.settleEase)}else u(x,p,m.easing??s.actionEase);d=p}return h}function i4(t,e,n,s,i){const r=[],o=$h+n4;for(let f=1;f<t.length;f++){const m=t[f-1].pose,g=t[f].pose;Object.entries(e.headTurns).some(([y,v])=>Math.abs((g[y]??0)-(m[y]??0))>v)&&t[f].act!==!1&&r.push(Math.max(t[0].time,t[f-1].time-n.eyeLead))}const a=t[0].time,l=t[t.length-1].time,c=[...r];let h=a+Go*.6,u=0;for(;h<l;){c.some(g=>Math.abs(g-h)<Go/2)||r.push(h);const m=(re(`${s}:blink:${u++}`)%1e3/1e3-.5)*(Go*.66);h+=Go+m}r.sort((f,m)=>f-m);const d=[{time:a,value:i}];for(const f of r){const m=d[d.length-1].time;f+$h<=m+Fs||(f>m+Fs&&d.push({time:f,value:i}),d.push({time:f+$h,value:1,easing:"ease-in"}),d.push({time:f+o,value:i,easing:"ease-out"}))}return d.length>1?d:[]}function r4(t,e,n,s){const i=n*(1-.18*s),r=n*(1+.14*s),o=[{time:t[0].time,value:n}],a=(l,c,h)=>{const u=o[o.length-1];l<=u.time+Fs||o.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<Ph||t[l].act===!1)){if(c<=Gn&&h>Gn)a(u,n),a(u+f*.2,i,"ease-out"),a(u+f*.45,r,"ease-out"),a(d,n,"ease-in-out");else if(c>Gn&&h<=Gn){const m=l+1<t.length?t[l+1].time-d:400;a(u+f*.5,n),a(d-Math.min(60,f*.15),r,"ease-in"),a(d,i,"ease-out"),a(d+Math.min(260,m/2),n,{type:"back",mode:"out",overshoot:1.4})}}}return o.length>1?o:[]}const hy={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 o4(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 a4(){const t={},e={};for(const n of Object.keys(lt)){const s=o4(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 uy=a4();function dy(t,e){return Object.entries(e).map(([n,s])=>({id:`${t}-${n}`,target:t,property:n,keyframes:s}))}function fy(t,e,n={}){const s=Vr(e),i=e.map((r,o)=>({time:r.time,pose:{...s[o]},easing:r.easing,act:r.act}));return dy(t,Uo(i,n.rig??hy,n))}function gy(t,e,n={}){const s=n.rest??lt,i=Gc(e,s),r=e.map((o,a)=>({time:o.time,pose:{...s,...i[a]},easing:o.easing,act:o.act}));return dy(t,Uo(r,n.rig??uy,n))}const my=Mt.shocked,l4=Mt.scared,mn={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,...my,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,...Mt.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,...my,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,...Mt.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:{...l4,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:{...he.sad,bend:18,stretch:.92,lean:t.lean+5,turn:t.turn,sit:t.sit},easing:"ease-in-out"}]};function Ih(t,e){const n=typeof e.from=="string"?he[e.from]:e.from??ut;return Oh(mn[t](n),{...e,from:n})}function Oh(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 nr(t,e=1){const n=mn[t](ut);return n[n.length-1].after*e}function py(t,e,n={}){if(e.length<2)return;const s=Math.max(1,Math.round(n.lines??3)),i=n.spacing??5,r=n.lineWidth??2,o=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,m=d.y-u.y,g=Math.hypot(f,m)||1,p=-m/g,y=f/g,v=1-h/(e.length-1);t.globalAlpha=o*(1-v),t.lineWidth=r*(1-v*.7),t.beginPath(),t.moveTo(u.x+p*l,u.y+y*l),t.lineTo(d.x+p*l,d.y+y*l),t.stroke()}}t.restore()}const c4={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 h4(t,e,n,s,i={}){const r=n.stateAt;if(!r)return;const o=i.length??120,a=Math.max(2,Math.round(i.samples??8)),l=Math.max(0,n.time-o);if(n.time-l<1)return;const c=[];for(let f=0;f<a;f++){const m=l+(n.time-l)*f/(a-1);c.push(Ql(e,{time:m,state:r(m)},s).joints)}const h=c[c.length-1].height,u=(i.threshold??1.2)*h,d=(i.parts??["hands","toes","head"]).flatMap(f=>c4[f]);for(const f of d){const m=c.map(f.at);let g=0;for(let v=1;v<m.length;v++)g+=Math.hypot(m[v].x-m[v-1].x,m[v].y-m[v-1].y);const p=g/((n.time-l)/1e3);if(p<=u)continue;const y=Math.min(1,(p-u)/(u*.5));py(t,m,{...i,opacity:(i.opacity??.7)*y,spacing:i.spacing??h*.02})}}function yy(t,e,n,s={}){if(n<=0||n>=1)return;const i=s.size??40,r=s.seed??1,o=.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=re(`${r}:puff:${a}`)%1e3/1e3,c=a-2,h=e.x+c*i*.3*o,u=e.y-i*(.06+.12*l)*o+Math.abs(c)*i*.03,d=i*(.11+.07*l)*o;t.beginPath(),t.arc(h,u,d,Math.PI*.95,Math.PI*2.05),t.stroke()}t.restore()}function u4(t,e,n,s={}){if(n<=0||n>=1)return;const i=s.size??40,r=5,o=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<r;a++){const l=-Math.PI/2+(a-(r-1)/2)*Math.PI/(r+1),c=i*(.3+.7*o),h=e.x+Math.cos(l)*c,u=e.y+Math.sin(l)*c;d4(t,h,u,i*.14,n*Math.PI+a),t.stroke()}t.restore()}function d4(t,e,n,s,i){t.beginPath();for(let r=0;r<10;r++){const o=r%2===0?s:s*.45,a=i+r*Math.PI/5-Math.PI/2,l=e+Math.cos(a)*o,c=n+Math.sin(a)*o;r===0?t.moveTo(l,c):t.lineTo(l,c)}t.closePath()}const sr={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 Ch(t={}){return[...Object.keys(Gt),...Object.keys(he),...Object.keys(mn),...Object.keys(sr),...Object.keys(t.gaits??{}),...Object.keys(t.actions??{})]}function _h(t={}){const e=new Set(Ch()),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 Rh(t={}){const e={};for(const n of Object.keys(Gt))e[n]=`Walks to \`to\` in the ${n} gait, feet planted, turning round first if needed.`;for(const n of Object.keys(he))e[n]=`Moves into the ${n} pose and holds it.`;for(const n of Object.keys(mn))e[n]=`The ${n} gag, built on the current pose.`;for(const[n,s]of Object.entries(sr))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 Vo=["do","at","for","to","toward","mood","say","pose","target","onto"],f4={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"},Jo=["viewer","ahead","back"],Un=t=>typeof t=="number"&&Number.isFinite(t);function ir(t,e={}){const n=_h(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=Ch(e),i=l=>l in Gt||l in(e.gaits??{}),r=Object.keys(Mt),o=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))Vo.includes(g)||h(dt("beat field",g,Vo,f4[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(dt("action",f,s));return}const m=sr[f]??e.actions?.[f];for(const g of m?.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"||!r.includes(d.mood))&&h(dt("mood",d.mood,r)),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,p]of Object.entries(d.pose))o.includes(g)?Un(p)||h(`Pose joint \`${g}\` must be a number (got ${JSON.stringify(p)}).`):h(dt("pose joint",g,o));for(const g of["at","for"]){const p=d[g];p!==void 0&&!(Un(p)&&p>=0)&&h(`\`${g}\` is milliseconds, a number ≥ 0 (got ${JSON.stringify(p)}).`)}Un(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 p=d[g];p!==void 0&&!Un(p)&&h(`\`${g}\` is a scene ${g==="to"?"x":"y"} in px, a number (got ${JSON.stringify(p)}).`)}if(d.toward!==void 0&&!Un(d.toward)&&!Jo.includes(d.toward)&&h(`\`toward\` is a scene x or one of ${Jo.join(", ")}${typeof d.toward=="string"&&ai(d.toward,Jo)?` (did you mean "${ai(d.toward,Jo)}"?)`:""} (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"||!Un(g.x)||!Un(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 Hh(t,e={},n="scriptTracks"){const s=ir(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
|
-
`)}`)}D5(Rh);function g4(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 m4(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 by=8;function Zo(t,e={},n=0){if(n>by)throw new Error(`scriptTracks: custom actions nest more than ${by} deep (does one build itself?)`);return t.flatMap(s=>{const i=e[s.do];if(!i||!("beats"in i))return[s];const r=i.beats(s).map((o,a)=>a===0?{...o,...s.at!==void 0&&o.at===void 0?{at:s.at}:{},...s.mood&&!o.mood?{mood:s.mood}:{},...s.say&&!o.say?{say:s.say}:{}}:o);return Zo(r,e,n+1)})}function wy(t){return t.length===0?0:Math.max(...t.map(e=>e.after))}const Fh={walk:1e3,bouncy:900,doubleBounce:1100,sneak:1600,strut:1100,tired:1500,shove:1300,run:560},p4=450,y4=2.4,b4=160,ky=2.5,w4=200,k4=340,v4=1.1,vy=[380,900],M4=.35,Qo=300,Lh=150,S4=260,T4=1.2,Nh=160,My=400,rr=300,E4=450,Sy=500,Wh=350,Ty=150,A4=120,Dh=180,Ey=420,x4=300,Ay=300,P4=140,Bh=150,xy=450,$4=450,zh=150,Py=350,$y=400,I4=12,O4=600,Iy=90,Oy=400,C4=200,_4=.09,Cy=350,Ke=450,qh=1200,R4=700,Ls=320,Ye=220,H4=65,F4=700,_y=t=>t in mn,L4=t=>t in he;function Ry(t){return Math.max(F4,Array.from(t).length*H4)}function ta(t,e,n={}){const s={actions:n.actions,gaits:n.gaits};Hh(e,s);const i=n.gait??"walk",r=Zo(e,n.actions).map(R=>R.do==="go"?{...R,do:i}:R);Hh(r,s,"scriptTracks (after expanding custom actions)");const o=R=>Gt[R]??n.gaits?.[R],a=R=>Fh[R]??n.gaits?.[R]?.cycle??1e3,l=R=>{const K=n.actions?.[R];return K&&"steps"in K?K:void 0},c=n.from??0,h=n.ground??0,u=n.height??300;let d=c,f=h,m=n.facing??1,g=n.start??ut,p=0,b=0;const v=[{time:0,pose:g}],k=[{time:0,value:0}],w=[{time:0,value:0}],S=[{time:0,value:0}],x=[{time:0,value:0}],M=[{time:0,value:"walk"}],E=[{time:0,value:m}],T=[],A=[],P=[],I=(R,K,st,$)=>{g={...g,...K},st&&(g=an(g,st)),v.push({time:R,pose:g,...$===!1?{act:$}:{}})},O=(R,K,st)=>(I(R+Ls/2,{turn:0},st),E.push({time:R+Ls/2,value:m},{time:R+Ls/2+1,value:K}),m=K,I(R+Ls,{turn:1}),R+Ls),_=R=>R<d?-1:1,L=(R,K,st)=>_(K)!==m?O(R,_(K),st):R,j=(R,K,st,$="arm")=>{const C=$==="arm",z=Ee({...R,...C?{rightShoulder:0,rightElbow:0}:{rightHip:0,rightKnee:0}},{height:u,facing:m}),X=C?z.shoulders.right:z.hip,W=C?z.elbows.right:z.knees.right,N=(q,Z)=>Math.atan2(m*q,Z)*180/Math.PI,G=((N(K-(d+X.x),st-(f+X.y))-N(W.x-X.x,W.y-X.y))%360+360)%360;return G>270?G-360:G},V=(R,K,st,$)=>{const C=$==="arm",z=Ee({...R,...C?{rightShoulder:90,rightElbow:0,rightWrist:0}:{rightHip:90,rightKnee:0}},{height:u,facing:m}),X=C?z.shoulders.right:z.hip,W=C?{x:(z.hands.right.x+z.fingertips.right.x)/2,y:(z.hands.right.y+z.fingertips.right.y)/2}:z.feet.right,N=Math.hypot(W.x-X.x,W.y-X.y)*((C?n.reach?.arm:n.reach?.leg)??1),D=st-(f+X.y),G=Math.abs(D)<N?Math.sqrt(N*N-D*D):N*.1;return K-X.x-m*G},tt=R=>{const K=Ee(R,{height:u,facing:m});return{x:d+(K.hands.right.x+K.fingertips.right.x)/2,y:f+(K.hands.right.y+K.fingertips.right.y)/2}},J=(R,K,st)=>{const $={...R,rightWrist:0,rightElbow:0,rightShoulder:j(R,K,st)},C=Ee($,{height:u,facing:m}),z={x:d+C.shoulders.right.x,y:f+C.shoulders.right.y},X={x:d+C.elbows.right.x,y:f+C.elbows.right.y},W=tt($),N=Math.hypot(X.x-z.x,X.y-z.y),D=Math.hypot(W.x-X.x,W.y-X.y),G=Math.min(N+D-.01,Math.max(Math.abs(N-D)+.01,Math.hypot(K-z.x,st-z.y))),q=nt=>nt*180/Math.PI,Z=q(Math.acos((N*N+G*G-D*D)/(2*N*G))),et=180-q(Math.acos((N*N+D*D-G*G)/(2*N*D)));let H={rightShoulder:$.rightShoulder,rightElbow:0},U=1/0;for(const nt of[1,-1])for(const at of[1,-1]){const rt={rightShoulder:$.rightShoulder+nt*Z,rightElbow:at*et},ct={...R,rightWrist:0,...rt},it=tt(ct),ot=Math.hypot(it.x-K,it.y-st)-Ee(ct,{height:u,facing:m}).elbows.right.y*.001;ot<U&&(U=ot,H=rt)}return H},F=(R,K,st)=>Math.abs(K-d)<2?R:(k.push({time:R,value:d-c},{time:R+st,value:K-c,easing:"ease-in-out"}),d=K,R+st);for(const R of r){const K=Math.max(R.at??b,b===0?0:v[v.length-1].time);let st=K,$,C;const z=R.pose??{},X=l(R.do);if(o(R.do)){const W=R.to??d,N=W===d?m:_(W);let D=K;N!==m?D=O(K,N,R.mood):g.turn<1?(D=K+Ye,I(D,{turn:1,...z},R.mood)):(R.mood||R.pose)&&I(K+Ye,z,R.mood);const q=Math.abs(W-d)/Xr(o(R.do),u),Z=R.for??Math.max(Ye*2,q*a(R.do)),et=D+Z;M.push({time:D,value:R.do}),x.push({time:D,value:0},{time:D+Ye,value:1,easing:"ease-out"}),x.push({time:et-Ye,value:1},{time:et,value:0,easing:"ease-in"}),S.push({time:D,value:p},{time:et,value:p+q}),k.push({time:D,value:d-c},{time:et,value:W-c}),p+=q,d=W,I(et,{}),st=et}else if(R.do==="zip"){const W=R.to??d,N=W===d?m:_(W);let D=K;N!==m?D=O(K,N,R.mood):g.turn<1&&(D=K+Ye,I(D,{turn:1},R.mood));const G=Ih("windUp",{at:D,from:R.mood?an(g,R.mood):g});v.push(...G),g=G[G.length-1].pose;const q=D+nr("windUp"),Z=q+p4,et=Z+Math.max(b4,Math.abs(W-d)/y4);M.push({time:q,value:"run"}),x.push({time:q,value:0},{time:q+80,value:1,easing:"ease-out"},{time:et,value:1},{time:et+120,value:0}),S.push({time:q,value:p},{time:Z,value:p+ky,easing:"ease-in"}),p+=ky+(et-Z)/Fh.run*1.5,S.push({time:et,value:p}),k.push({time:Z,value:d-c},{time:et,value:W-c,easing:"ease-in"}),P.push({kind:"dust",time:Z,x:d,y:f,length:900}),d=W,I(et,{}),st=et}else if(R.do==="leap"){const W=R.to??d,N=R.onto??f;let D=W===d?K:L(K,W,R.mood);g.turn<1&&(D+=Ye,I(D,{turn:1},R.mood));const G={leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50};I(D+w4,{stretch:.75,bend:12,leftHip:22,rightHip:22,...G},R.mood,!1);const q=D+k4;I(q-40,{stretch:.72},void 0,!1),I(q,{stretch:1.2,bend:-6,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4},void 0,!1);const Z=Math.hypot(W-d,N-f),et=R.for??Math.min(vy[1],Math.max(vy[0],300+Z*v4)),H=Math.min(f,N)-M4*u,U=Math.sqrt(f-H),nt=Math.sqrt(N-H),at=q+et*U/(U+nt),rt=q+et;I(at,{stretch:1,bend:4,leftHip:-55,leftKnee:-80,rightHip:55,rightKnee:80,leftShoulder:110,rightShoulder:110},void 0,!1),I(rt,{stretch:.72,bend:12,leftShoulder:75,rightShoulder:75,leftElbow:0,rightElbow:0,leftHip:18,rightHip:18,leftKnee:0,rightKnee:0},void 0,!1),I(rt+180,{stretch:1.05,bend:-3},void 0,!1),I(rt+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:q,value:d-c},{time:rt,value:W-c}),w.push({time:q,value:f-h},{time:at,value:H-h,easing:"ease-out-quad"},{time:rt,value:N-h,easing:"ease-in-quad"}),d=W,f=N,P.push({kind:"dust",time:rt,x:d,y:f,length:500}),st=rt+340,$=rt}else if(R.do==="point"&&R.target){const W=R.target,N=L(K,W.x,R.mood),D={...g,...R.mood?Mt[R.mood]:{},turn:Math.max(g.turn,.6),rightElbow:0,rightWrist:0,...z},G=Ee(D,{height:u,facing:m}).head.center,q=Math.abs(W.x-(d+G.x)),Z=W.y-(f+G.y),et=N+Ke;I(et,{...D,rightShoulder:j(D,W.x,W.y),lookX:1,lookY:N4(Z/Math.max(1,Math.hypot(q,Z)))*.8}),st=et+(R.for??qh),$=et,C=st}else if(R.do==="swipe"){const W=R.target??{x:d+m*u*.5,y:f-u*.6},N=_(W.x),D=L(K,W.x,R.mood),G=N===1?W.left??W.x:W.right??W.x,q=N===1?W.right??W.x:W.left??W.x,Z={...g,turn:1,lean:-10,bend:-8,rightElbow:40,lookX:1,...z};I(D+Qo,{...Z,rightShoulder:j(Z,d-m*u*.3,f-u*1.1)},R.mood,!1);const et={...g,lean:6,bend:4,rightElbow:0,rightWrist:0},H={...g,lean:14,bend:12,rightElbow:0,rightWrist:0};F(D,V(et,G,W.y,"arm"),Qo+Lh),I(D+Qo+Lh,{lean:-12},void 0,!1);const U=D+Qo+Lh+80;I(U,{...et,rightShoulder:j(et,G,W.y)},void 0,!1);const nt=U+(R.for??Math.max(S4,Math.abs(q-G)/T4));k.push({time:U,value:d-c}),d=V(H,q,W.y,"arm"),k.push({time:nt,value:d-c}),I(nt,{...H,rightShoulder:j(H,q,W.y)},void 0,!1),I(nt+Nh,{lean:16,bend:14,rightShoulder:j(g,q+N*u*.4,W.y+u*.25)},void 0,!1),I(nt+Nh+My,{lean:0,bend:0,rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow}),st=nt+Nh+My,$=U,C=nt}else if(R.do==="grab"&&R.target){const W=R.target,N=L(K,W.x,R.mood),D=W.y>f-u*.5,G={...g,turn:1,rightElbow:0,bend:D?35:0,lean:D?12:0,stretch:D?.75:1,lookX:1,lookY:D?.8:0,...z},Z=F(N,V(G,W.x,W.y,"arm"),rr)+E4;I(Z,{...G,rightShoulder:j(G,W.x,W.y)},R.mood,!1),I(Z+120,{},void 0,!1),I(Z+Sy,{bend:0,lean:-3,stretch:1,rightShoulder:165,rightElbow:20,lookY:-.6}),st=Z+Sy+150,$=Z}else if(R.do==="throw"){const W=R.target?.x??R.to??d+m*u,N=L(K,W,R.mood),D={...g,turn:1,lean:-12,bend:-10,rightElbow:60,stretch:.95,lookX:1,lookY:-.3,...z};I(N+Wh,{...D,rightShoulder:j(D,d-m*u*.4,f-u*1.05)},R.mood,!1),I(N+Wh+Ty,{lean:-14},void 0,!1);const G=N+Wh+Ty+A4,q={...g,lean:14,bend:12,rightElbow:0,stretch:1.04};v.push({time:G,pose:g={...q,rightShoulder:j(q,d+m*u,f-u*1.1)},easing:"ease-in",act:!1}),I(G+Dh,{lean:18,bend:14,rightShoulder:55,stretch:1},void 0,!1),I(G+Dh+Ey,{lean:0,bend:0,rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow,lookY:0}),st=G+Dh+Ey,$=G,C=G}else if(R.do==="kick"&&R.target){const W=R.target,N=L(K,W.x,R.mood),D={...g,turn:1,lean:-12,bend:-6,rightKnee:0,leftShoulder:100,rightShoulder:70},G=F(N,V(D,W.x,W.y,"leg"),x4),q={leftShoulder:70,rightShoulder:50,leftElbow:-20,rightElbow:20};I(G+Ay,{turn:1,lean:8,bend:6,rightHip:-40,rightKnee:80,lookX:1,lookY:.7,...q,...z},R.mood,!1);const Z=G+Ay+P4,et=j(D,W.x,W.y,"leg");v.push({time:Z,pose:g={...g,...D,rightHip:et},easing:"ease-in",act:!1}),I(Z+Bh,{lean:-15,rightHip:et+20},void 0,!1),I(Z+Bh+xy,{lean:0,bend:0,rightHip:ut.rightHip,rightKnee:0,leftShoulder:ut.leftShoulder,rightShoulder:ut.rightShoulder,leftElbow:ut.leftElbow,rightElbow:ut.rightElbow,lookY:0}),st=Z+Bh+xy,$=Z}else if(R.do==="put"&&R.target){const W=R.target,N=L(K,W.x,R.mood),D=W.y>f-u*.5,G={...g,turn:1,rightElbow:0,rightWrist:0,bend:D?35:0,lean:D?12:0,stretch:D?.75:1,lookX:1,lookY:D?.8:0,...z},Z=F(N,V(G,W.x,W.y,"arm"),rr)+$4;I(Z,{...G,rightShoulder:j(G,W.x,W.y)},R.mood,!1),I(Z+zh,{},void 0,!1),I(Z+zh+Py,{bend:0,lean:0,stretch:1,rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow,lookY:0}),st=Z+zh+Py,$=Z}else if(R.do==="write"&&R.target){const W=R.target,N=W.left??W.x,D=W.right??W.x,G=L(K,(N+D)/2,R.mood),q={...g,turn:1,rightElbow:0,rightWrist:0,...Mt.thinking,lookX:1,lookY:0,...z},Z=it=>V(q,it,W.y,"arm")+m*u*.08,et=it=>{const Q=tt({...q,...J(q,it,W.y),rightWrist:0});return Math.hypot(Q.x-it,Q.y-W.y)<2},H=m===1?N:D,U=F(G,Z((N+D)/2),rr),nt=!et(N)||!et(D),at=nt?F(U,Z(N),rr)+$y:U+$y;I(at,{...q,...J(q,nt?N:H,W.y)},R.mood,!1);const rt=R.for??Math.max(O4,Math.abs(D-N)*I4);nt&&k.push({time:at,value:d-c});for(let it=Iy,Q=0;it<=rt;it+=Iy,Q++){const ot=N+(D-N)*Math.min(it,rt)/rt;nt&&(d=Z(ot),k.push({time:at+it,value:d-c}));const ht=(Q%2===0?-1:1)*u*.02;I(at+it,J(q,ot,W.y+ht),void 0,!1)}const ct=at+rt;I(ct,J(q,D,W.y),void 0,!1),I(ct+Oy,{rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow,...Mt.happy}),st=ct+Oy,$=at,C=ct}else if(R.do==="push"&&R.target){const W=R.target,N=R.to??W.x,D=L(K,d+(N>=W.x?1:-1),R.mood),G=m===1?W.left??W.x:W.right??W.x,q={...g,turn:1,lean:16,bend:8,rightWrist:0,leftWrist:0,lookX:1,...z},Z=V(q,G,W.y,"arm"),et=F(D,Z+m*u*.06,rr),H=J(q,G,W.y),U={...q,...H,leftShoulder:-H.rightShoulder,leftElbow:-H.rightElbow},nt=et+C4;I(nt,U,R.mood,!1);const at=Math.abs(N-W.x),rt=nt+(R.for??Math.max(600,at/_4)),ct=at/Xr("shove",u);M.push({time:nt,value:"shove"}),x.push({time:nt,value:0},{time:nt+Ye,value:1,easing:"ease-out"},{time:rt-Ye,value:1},{time:rt,value:0,easing:"ease-in"}),S.push({time:nt,value:p},{time:rt,value:p+ct}),p+=ct,k.push({time:nt,value:d-c},{time:rt,value:d+(N-W.x)-c}),d+=N-W.x,I(rt,{},void 0,!1),I(rt+Cy,{lean:0,bend:0,rightShoulder:ut.rightShoulder,leftShoulder:ut.leftShoulder,rightElbow:ut.rightElbow,leftElbow:ut.leftElbow}),st=rt+Cy,$=nt,C=rt}else if(X){const W=R.mood?an(g,R.mood):g,N=X.steps(W,R),D=Oh(N,{at:K,from:W});v.push(...D),g=D[D.length-1].pose,st=K+Math.max(wy(N),R.for??0)}else if(_y(R.do)){const W=Ih(R.do,{at:K,from:R.mood?an(g,R.mood):g});v.push(...W),g=W[W.length-1].pose,st=K+nr(R.do),R.do==="take"&&P.push({kind:"dust",time:K+900,x:d,y:f,length:500}),R.do==="land"&&P.push({kind:"dust",time:K+120,x:d,y:f,length:500})}else if(R.do==="look"||R.do==="face"){const W=R.toward??"viewer",N=R.for??R4;if(W==="viewer")I(K+Ke,{turn:0,lookX:0,lookY:0,...z},R.mood);else if(W==="ahead")I(K+Ke,{turn:R.do==="face"?1:.6,lookX:1,...z},R.mood);else if(W==="back")I(K+Ke,{turn:.2,lookX:-1,...z},R.mood);else{const D=_(W);D!==m&&R.do==="face"?(O(K,D,R.mood),I(K+Ls+1,{lookX:1,...z})):D!==m?I(K+Ke,{turn:.25,lookX:-1,...z},R.mood):I(K+Ke,{turn:R.do==="face"?1:.6,lookX:1,...z},R.mood)}st=K+Math.max(N,Ke)}else if(L4(R.do)||R.do==="stand"){const W=R.do==="stand"?n.rest??ut:he[R.do],N=W.turn!==ut.turn?W.turn:g.turn,D=R.mood?Mt[R.mood]:{lookX:g.lookX,lookY:g.lookY};I(K+Ke,{...W,turn:N,...D,...z}),st=K+(R.for??qh)}else{const W=R.for??(R.say?Ry(R.say):qh);(R.mood||R.pose)&&I(K+Math.min(Ke,W/2),z,R.mood),st=K+W}if(R.say){const W=o(R.do)||_y(R.do)||X?K:K+Math.min(150,(st-K)/4),N=o(R.do)?st:Math.max(W+200,st-100);T.push({text:R.say,start:W,end:N}),R.do==="say"&&B4(v,g,W,N)}R.onto!==void 0&&R.do!=="leap"&&R.onto!==f&&(w.push({time:K,value:f-h},{time:st,value:R.onto-h,easing:"ease-in-out"}),f=R.onto),st>v[v.length-1].time&&v.push({time:st,pose:g}),A.push({start:K,end:st,...$!==void 0?{contact:$}:{},...C!==void 0?{release:C}:{}}),b=st}const B=fy(t,D4(v),n),Y=[{id:`${t}-x`,target:t,property:"x",keyframes:k},{id:`${t}-y`,target:t,property:"y",keyframes:w},{id:`${t}-walk`,target:t,property:"walk",keyframes:S},{id:`${t}-walking`,target:t,property:"walking",keyframes:x},{id:`${t}-gait`,target:t,property:"gait",keyframes:M},{id:`${t}-facing`,target:t,property:"facing",keyframes:E}].filter(R=>R.keyframes.length>1||R.property==="x"||R.property==="facing"&&R.keyframes[0].value===-1);return{tracks:[...Wo(t,B,T,{energy:n.energy}),...Y],duration:b,lines:T,keys:v,beats:A,effects:P}}const N4=t=>Math.max(-1,Math.min(1,t)),W4=30;function D4(t){const e=[];for(const n of t){const s=e[e.length-1];s&&n.time-s.time<W4?e[e.length-1]={...n,time:s.time}:e.push(n)}return e}function B4(t,e,n,s){const r=t.filter(l=>l.time>n),o=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(...o,...a.filter(l=>!r.some(c=>Math.abs(c.time-l.time)<60)),...r),t.sort((l,c)=>l.time-c.time)}function jh(t,e,n){const s=new Ht({id:`${t}-hand`,tracks:e.filter(l=>l.target===t)}),i=Zl({x:n.x,y:n.y,style:n.style,cast:n.cast}),r=n.side??"right",o=n.every??33,a=[];for(let l=n.start;;l=Math.min(n.end,l+o)){const{joints:c}=Ql(i,{time:l,state:s.getStateAtTime(l)},t),h=c.hands[r],u=c.fingertips[r];if(a.push({time:l,x:(h.x+u.x)/2,y:(h.y+u.y)/2}),l>=n.end)break}return a}const Ns=["start","contact","release","end"],z4=["surface","edit","anchor","at","until"],q4=["carry"],ea=t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&"surface"in t&&"anchor"in t,j4=t=>t.then===void 0?[]:Array.isArray(t.then)?t.then:[t.then];function K4(t,e,n,s={}){const i=Hy(n,e,s).filter(d=>d.level==="error");if(i.length>0)throw new Error(`surfaceScript: ${i.length} problem(s) in the beats:
|
|
58
|
+
`)}`)}D5(Rh);function g4(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 m4(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 by=8;function Zo(t,e={},n=0){if(n>by)throw new Error(`scriptTracks: custom actions nest more than ${by} deep (does one build itself?)`);return t.flatMap(s=>{const i=e[s.do];if(!i||!("beats"in i))return[s];const r=i.beats(s).map((o,a)=>a===0?{...o,...s.at!==void 0&&o.at===void 0?{at:s.at}:{},...s.mood&&!o.mood?{mood:s.mood}:{},...s.say&&!o.say?{say:s.say}:{}}:o);return Zo(r,e,n+1)})}function wy(t){return t.length===0?0:Math.max(...t.map(e=>e.after))}const Fh={walk:1e3,bouncy:900,doubleBounce:1100,sneak:1600,strut:1100,tired:1500,shove:1300,run:560},p4=450,y4=2.4,b4=160,ky=2.5,w4=200,k4=340,v4=1.1,vy=[380,900],M4=.35,Qo=300,Lh=150,S4=260,T4=1.2,Nh=160,My=400,rr=300,E4=450,Sy=500,Wh=350,Ty=150,A4=120,Dh=180,Ey=420,x4=300,Ay=300,P4=140,Bh=150,xy=450,$4=450,zh=150,Py=350,$y=400,I4=12,O4=600,Iy=90,Oy=400,C4=200,_4=.09,Cy=350,Ke=450,qh=1200,R4=700,Ls=320,Ye=220,H4=65,F4=700,_y=t=>t in mn,L4=t=>t in he;function Ry(t){return Math.max(F4,Array.from(t).length*H4)}function ta(t,e,n={}){const s={actions:n.actions,gaits:n.gaits};Hh(e,s);const i=n.gait??"walk",r=Zo(e,n.actions).map(R=>R.do==="go"?{...R,do:i}:R);Hh(r,s,"scriptTracks (after expanding custom actions)");const o=R=>Gt[R]??n.gaits?.[R],a=R=>Fh[R]??n.gaits?.[R]?.cycle??1e3,l=R=>{const K=n.actions?.[R];return K&&"steps"in K?K:void 0},c=n.from??0,h=n.ground??0,u=n.height??300;let d=c,f=h,m=n.facing??1,g=n.start??ut,p=0,y=0;const v=[{time:0,pose:g}],w=[{time:0,value:0}],k=[{time:0,value:0}],S=[{time:0,value:0}],x=[{time:0,value:0}],M=[{time:0,value:"walk"}],E=[{time:0,value:m}],T=[],A=[],P=[],I=(R,K,st,$)=>{g={...g,...K},st&&(g=an(g,st)),v.push({time:R,pose:g,...$===!1?{act:$}:{}})},O=(R,K,st)=>(I(R+Ls/2,{turn:0},st),E.push({time:R+Ls/2,value:m},{time:R+Ls/2+1,value:K}),m=K,I(R+Ls,{turn:1}),R+Ls),_=R=>R<d?-1:1,L=(R,K,st)=>_(K)!==m?O(R,_(K),st):R,j=(R,K,st,$="arm")=>{const C=$==="arm",z=Ee({...R,...C?{rightShoulder:0,rightElbow:0}:{rightHip:0,rightKnee:0}},{height:u,facing:m}),X=C?z.shoulders.right:z.hip,W=C?z.elbows.right:z.knees.right,N=(q,Z)=>Math.atan2(m*q,Z)*180/Math.PI,G=((N(K-(d+X.x),st-(f+X.y))-N(W.x-X.x,W.y-X.y))%360+360)%360;return G>270?G-360:G},V=(R,K,st,$)=>{const C=$==="arm",z=Ee({...R,...C?{rightShoulder:90,rightElbow:0,rightWrist:0}:{rightHip:90,rightKnee:0}},{height:u,facing:m}),X=C?z.shoulders.right:z.hip,W=C?{x:(z.hands.right.x+z.fingertips.right.x)/2,y:(z.hands.right.y+z.fingertips.right.y)/2}:z.feet.right,N=Math.hypot(W.x-X.x,W.y-X.y)*((C?n.reach?.arm:n.reach?.leg)??1),D=st-(f+X.y),G=Math.abs(D)<N?Math.sqrt(N*N-D*D):N*.1;return K-X.x-m*G},tt=R=>{const K=Ee(R,{height:u,facing:m});return{x:d+(K.hands.right.x+K.fingertips.right.x)/2,y:f+(K.hands.right.y+K.fingertips.right.y)/2}},J=(R,K,st)=>{const $={...R,rightWrist:0,rightElbow:0,rightShoulder:j(R,K,st)},C=Ee($,{height:u,facing:m}),z={x:d+C.shoulders.right.x,y:f+C.shoulders.right.y},X={x:d+C.elbows.right.x,y:f+C.elbows.right.y},W=tt($),N=Math.hypot(X.x-z.x,X.y-z.y),D=Math.hypot(W.x-X.x,W.y-X.y),G=Math.min(N+D-.01,Math.max(Math.abs(N-D)+.01,Math.hypot(K-z.x,st-z.y))),q=nt=>nt*180/Math.PI,Z=q(Math.acos((N*N+G*G-D*D)/(2*N*G))),et=180-q(Math.acos((N*N+D*D-G*G)/(2*N*D)));let H={rightShoulder:$.rightShoulder,rightElbow:0},U=1/0;for(const nt of[1,-1])for(const at of[1,-1]){const rt={rightShoulder:$.rightShoulder+nt*Z,rightElbow:at*et},ct={...R,rightWrist:0,...rt},it=tt(ct),ot=Math.hypot(it.x-K,it.y-st)-Ee(ct,{height:u,facing:m}).elbows.right.y*.001;ot<U&&(U=ot,H=rt)}return H},F=(R,K,st)=>Math.abs(K-d)<2?R:(w.push({time:R,value:d-c},{time:R+st,value:K-c,easing:"ease-in-out"}),d=K,R+st);for(const R of r){const K=Math.max(R.at??y,y===0?0:v[v.length-1].time);let st=K,$,C;const z=R.pose??{},X=l(R.do);if(o(R.do)){const W=R.to??d,N=W===d?m:_(W);let D=K;N!==m?D=O(K,N,R.mood):g.turn<1?(D=K+Ye,I(D,{turn:1,...z},R.mood)):(R.mood||R.pose)&&I(K+Ye,z,R.mood);const q=Math.abs(W-d)/Xr(o(R.do),u),Z=R.for??Math.max(Ye*2,q*a(R.do)),et=D+Z;M.push({time:D,value:R.do}),x.push({time:D,value:0},{time:D+Ye,value:1,easing:"ease-out"}),x.push({time:et-Ye,value:1},{time:et,value:0,easing:"ease-in"}),S.push({time:D,value:p},{time:et,value:p+q}),w.push({time:D,value:d-c},{time:et,value:W-c}),p+=q,d=W,I(et,{}),st=et}else if(R.do==="zip"){const W=R.to??d,N=W===d?m:_(W);let D=K;N!==m?D=O(K,N,R.mood):g.turn<1&&(D=K+Ye,I(D,{turn:1},R.mood));const G=Ih("windUp",{at:D,from:R.mood?an(g,R.mood):g});v.push(...G),g=G[G.length-1].pose;const q=D+nr("windUp"),Z=q+p4,et=Z+Math.max(b4,Math.abs(W-d)/y4);M.push({time:q,value:"run"}),x.push({time:q,value:0},{time:q+80,value:1,easing:"ease-out"},{time:et,value:1},{time:et+120,value:0}),S.push({time:q,value:p},{time:Z,value:p+ky,easing:"ease-in"}),p+=ky+(et-Z)/Fh.run*1.5,S.push({time:et,value:p}),w.push({time:Z,value:d-c},{time:et,value:W-c,easing:"ease-in"}),P.push({kind:"dust",time:Z,x:d,y:f,length:900}),d=W,I(et,{}),st=et}else if(R.do==="leap"){const W=R.to??d,N=R.onto??f;let D=W===d?K:L(K,W,R.mood);g.turn<1&&(D+=Ye,I(D,{turn:1},R.mood));const G={leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50};I(D+w4,{stretch:.75,bend:12,leftHip:22,rightHip:22,...G},R.mood,!1);const q=D+k4;I(q-40,{stretch:.72},void 0,!1),I(q,{stretch:1.2,bend:-6,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4},void 0,!1);const Z=Math.hypot(W-d,N-f),et=R.for??Math.min(vy[1],Math.max(vy[0],300+Z*v4)),H=Math.min(f,N)-M4*u,U=Math.sqrt(f-H),nt=Math.sqrt(N-H),at=q+et*U/(U+nt),rt=q+et;I(at,{stretch:1,bend:4,leftHip:-55,leftKnee:-80,rightHip:55,rightKnee:80,leftShoulder:110,rightShoulder:110},void 0,!1),I(rt,{stretch:.72,bend:12,leftShoulder:75,rightShoulder:75,leftElbow:0,rightElbow:0,leftHip:18,rightHip:18,leftKnee:0,rightKnee:0},void 0,!1),I(rt+180,{stretch:1.05,bend:-3},void 0,!1),I(rt+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),w.push({time:q,value:d-c},{time:rt,value:W-c}),k.push({time:q,value:f-h},{time:at,value:H-h,easing:"ease-out-quad"},{time:rt,value:N-h,easing:"ease-in-quad"}),d=W,f=N,P.push({kind:"dust",time:rt,x:d,y:f,length:500}),st=rt+340,$=rt}else if(R.do==="point"&&R.target){const W=R.target,N=L(K,W.x,R.mood),D={...g,...R.mood?Mt[R.mood]:{},turn:Math.max(g.turn,.6),rightElbow:0,rightWrist:0,...z},G=Ee(D,{height:u,facing:m}).head.center,q=Math.abs(W.x-(d+G.x)),Z=W.y-(f+G.y),et=N+Ke;I(et,{...D,rightShoulder:j(D,W.x,W.y),lookX:1,lookY:N4(Z/Math.max(1,Math.hypot(q,Z)))*.8}),st=et+(R.for??qh),$=et,C=st}else if(R.do==="swipe"){const W=R.target??{x:d+m*u*.5,y:f-u*.6},N=_(W.x),D=L(K,W.x,R.mood),G=N===1?W.left??W.x:W.right??W.x,q=N===1?W.right??W.x:W.left??W.x,Z={...g,turn:1,lean:-10,bend:-8,rightElbow:40,lookX:1,...z};I(D+Qo,{...Z,rightShoulder:j(Z,d-m*u*.3,f-u*1.1)},R.mood,!1);const et={...g,lean:6,bend:4,rightElbow:0,rightWrist:0},H={...g,lean:14,bend:12,rightElbow:0,rightWrist:0};F(D,V(et,G,W.y,"arm"),Qo+Lh),I(D+Qo+Lh,{lean:-12},void 0,!1);const U=D+Qo+Lh+80;I(U,{...et,rightShoulder:j(et,G,W.y)},void 0,!1);const nt=U+(R.for??Math.max(S4,Math.abs(q-G)/T4));w.push({time:U,value:d-c}),d=V(H,q,W.y,"arm"),w.push({time:nt,value:d-c}),I(nt,{...H,rightShoulder:j(H,q,W.y)},void 0,!1),I(nt+Nh,{lean:16,bend:14,rightShoulder:j(g,q+N*u*.4,W.y+u*.25)},void 0,!1),I(nt+Nh+My,{lean:0,bend:0,rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow}),st=nt+Nh+My,$=U,C=nt}else if(R.do==="grab"&&R.target){const W=R.target,N=L(K,W.x,R.mood),D=W.y>f-u*.5,G={...g,turn:1,rightElbow:0,bend:D?35:0,lean:D?12:0,stretch:D?.75:1,lookX:1,lookY:D?.8:0,...z},Z=F(N,V(G,W.x,W.y,"arm"),rr)+E4;I(Z,{...G,rightShoulder:j(G,W.x,W.y)},R.mood,!1),I(Z+120,{},void 0,!1),I(Z+Sy,{bend:0,lean:-3,stretch:1,rightShoulder:165,rightElbow:20,lookY:-.6}),st=Z+Sy+150,$=Z}else if(R.do==="throw"){const W=R.target?.x??R.to??d+m*u,N=L(K,W,R.mood),D={...g,turn:1,lean:-12,bend:-10,rightElbow:60,stretch:.95,lookX:1,lookY:-.3,...z};I(N+Wh,{...D,rightShoulder:j(D,d-m*u*.4,f-u*1.05)},R.mood,!1),I(N+Wh+Ty,{lean:-14},void 0,!1);const G=N+Wh+Ty+A4,q={...g,lean:14,bend:12,rightElbow:0,stretch:1.04};v.push({time:G,pose:g={...q,rightShoulder:j(q,d+m*u,f-u*1.1)},easing:"ease-in",act:!1}),I(G+Dh,{lean:18,bend:14,rightShoulder:55,stretch:1},void 0,!1),I(G+Dh+Ey,{lean:0,bend:0,rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow,lookY:0}),st=G+Dh+Ey,$=G,C=G}else if(R.do==="kick"&&R.target){const W=R.target,N=L(K,W.x,R.mood),D={...g,turn:1,lean:-12,bend:-6,rightKnee:0,leftShoulder:100,rightShoulder:70},G=F(N,V(D,W.x,W.y,"leg"),x4),q={leftShoulder:70,rightShoulder:50,leftElbow:-20,rightElbow:20};I(G+Ay,{turn:1,lean:8,bend:6,rightHip:-40,rightKnee:80,lookX:1,lookY:.7,...q,...z},R.mood,!1);const Z=G+Ay+P4,et=j(D,W.x,W.y,"leg");v.push({time:Z,pose:g={...g,...D,rightHip:et},easing:"ease-in",act:!1}),I(Z+Bh,{lean:-15,rightHip:et+20},void 0,!1),I(Z+Bh+xy,{lean:0,bend:0,rightHip:ut.rightHip,rightKnee:0,leftShoulder:ut.leftShoulder,rightShoulder:ut.rightShoulder,leftElbow:ut.leftElbow,rightElbow:ut.rightElbow,lookY:0}),st=Z+Bh+xy,$=Z}else if(R.do==="put"&&R.target){const W=R.target,N=L(K,W.x,R.mood),D=W.y>f-u*.5,G={...g,turn:1,rightElbow:0,rightWrist:0,bend:D?35:0,lean:D?12:0,stretch:D?.75:1,lookX:1,lookY:D?.8:0,...z},Z=F(N,V(G,W.x,W.y,"arm"),rr)+$4;I(Z,{...G,rightShoulder:j(G,W.x,W.y)},R.mood,!1),I(Z+zh,{},void 0,!1),I(Z+zh+Py,{bend:0,lean:0,stretch:1,rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow,lookY:0}),st=Z+zh+Py,$=Z}else if(R.do==="write"&&R.target){const W=R.target,N=W.left??W.x,D=W.right??W.x,G=L(K,(N+D)/2,R.mood),q={...g,turn:1,rightElbow:0,rightWrist:0,...Mt.thinking,lookX:1,lookY:0,...z},Z=it=>V(q,it,W.y,"arm")+m*u*.08,et=it=>{const Q=tt({...q,...J(q,it,W.y),rightWrist:0});return Math.hypot(Q.x-it,Q.y-W.y)<2},H=m===1?N:D,U=F(G,Z((N+D)/2),rr),nt=!et(N)||!et(D),at=nt?F(U,Z(N),rr)+$y:U+$y;I(at,{...q,...J(q,nt?N:H,W.y)},R.mood,!1);const rt=R.for??Math.max(O4,Math.abs(D-N)*I4);nt&&w.push({time:at,value:d-c});for(let it=Iy,Q=0;it<=rt;it+=Iy,Q++){const ot=N+(D-N)*Math.min(it,rt)/rt;nt&&(d=Z(ot),w.push({time:at+it,value:d-c}));const ht=(Q%2===0?-1:1)*u*.02;I(at+it,J(q,ot,W.y+ht),void 0,!1)}const ct=at+rt;I(ct,J(q,D,W.y),void 0,!1),I(ct+Oy,{rightShoulder:ut.rightShoulder,rightElbow:ut.rightElbow,...Mt.happy}),st=ct+Oy,$=at,C=ct}else if(R.do==="push"&&R.target){const W=R.target,N=R.to??W.x,D=L(K,d+(N>=W.x?1:-1),R.mood),G=m===1?W.left??W.x:W.right??W.x,q={...g,turn:1,lean:16,bend:8,rightWrist:0,leftWrist:0,lookX:1,...z},Z=V(q,G,W.y,"arm"),et=F(D,Z+m*u*.06,rr),H=J(q,G,W.y),U={...q,...H,leftShoulder:-H.rightShoulder,leftElbow:-H.rightElbow},nt=et+C4;I(nt,U,R.mood,!1);const at=Math.abs(N-W.x),rt=nt+(R.for??Math.max(600,at/_4)),ct=at/Xr("shove",u);M.push({time:nt,value:"shove"}),x.push({time:nt,value:0},{time:nt+Ye,value:1,easing:"ease-out"},{time:rt-Ye,value:1},{time:rt,value:0,easing:"ease-in"}),S.push({time:nt,value:p},{time:rt,value:p+ct}),p+=ct,w.push({time:nt,value:d-c},{time:rt,value:d+(N-W.x)-c}),d+=N-W.x,I(rt,{},void 0,!1),I(rt+Cy,{lean:0,bend:0,rightShoulder:ut.rightShoulder,leftShoulder:ut.leftShoulder,rightElbow:ut.rightElbow,leftElbow:ut.leftElbow}),st=rt+Cy,$=nt,C=rt}else if(X){const W=R.mood?an(g,R.mood):g,N=X.steps(W,R),D=Oh(N,{at:K,from:W});v.push(...D),g=D[D.length-1].pose,st=K+Math.max(wy(N),R.for??0)}else if(_y(R.do)){const W=Ih(R.do,{at:K,from:R.mood?an(g,R.mood):g});v.push(...W),g=W[W.length-1].pose,st=K+nr(R.do),R.do==="take"&&P.push({kind:"dust",time:K+900,x:d,y:f,length:500}),R.do==="land"&&P.push({kind:"dust",time:K+120,x:d,y:f,length:500})}else if(R.do==="look"||R.do==="face"){const W=R.toward??"viewer",N=R.for??R4;if(W==="viewer")I(K+Ke,{turn:0,lookX:0,lookY:0,...z},R.mood);else if(W==="ahead")I(K+Ke,{turn:R.do==="face"?1:.6,lookX:1,...z},R.mood);else if(W==="back")I(K+Ke,{turn:.2,lookX:-1,...z},R.mood);else{const D=_(W);D!==m&&R.do==="face"?(O(K,D,R.mood),I(K+Ls+1,{lookX:1,...z})):D!==m?I(K+Ke,{turn:.25,lookX:-1,...z},R.mood):I(K+Ke,{turn:R.do==="face"?1:.6,lookX:1,...z},R.mood)}st=K+Math.max(N,Ke)}else if(L4(R.do)||R.do==="stand"){const W=R.do==="stand"?n.rest??ut:he[R.do],N=W.turn!==ut.turn?W.turn:g.turn,D=R.mood?Mt[R.mood]:{lookX:g.lookX,lookY:g.lookY};I(K+Ke,{...W,turn:N,...D,...z}),st=K+(R.for??qh)}else{const W=R.for??(R.say?Ry(R.say):qh);(R.mood||R.pose)&&I(K+Math.min(Ke,W/2),z,R.mood),st=K+W}if(R.say){const W=o(R.do)||_y(R.do)||X?K:K+Math.min(150,(st-K)/4),N=o(R.do)?st:Math.max(W+200,st-100);T.push({text:R.say,start:W,end:N}),R.do==="say"&&B4(v,g,W,N)}R.onto!==void 0&&R.do!=="leap"&&R.onto!==f&&(k.push({time:K,value:f-h},{time:st,value:R.onto-h,easing:"ease-in-out"}),f=R.onto),st>v[v.length-1].time&&v.push({time:st,pose:g}),A.push({start:K,end:st,...$!==void 0?{contact:$}:{},...C!==void 0?{release:C}:{}}),y=st}const B=fy(t,D4(v),n),Y=[{id:`${t}-x`,target:t,property:"x",keyframes:w},{id:`${t}-y`,target:t,property:"y",keyframes:k},{id:`${t}-walk`,target:t,property:"walk",keyframes:S},{id:`${t}-walking`,target:t,property:"walking",keyframes:x},{id:`${t}-gait`,target:t,property:"gait",keyframes:M},{id:`${t}-facing`,target:t,property:"facing",keyframes:E}].filter(R=>R.keyframes.length>1||R.property==="x"||R.property==="facing"&&R.keyframes[0].value===-1);return{tracks:[...Wo(t,B,T,{energy:n.energy}),...Y],duration:y,lines:T,keys:v,beats:A,effects:P}}const N4=t=>Math.max(-1,Math.min(1,t)),W4=30;function D4(t){const e=[];for(const n of t){const s=e[e.length-1];s&&n.time-s.time<W4?e[e.length-1]={...n,time:s.time}:e.push(n)}return e}function B4(t,e,n,s){const r=t.filter(l=>l.time>n),o=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(...o,...a.filter(l=>!r.some(c=>Math.abs(c.time-l.time)<60)),...r),t.sort((l,c)=>l.time-c.time)}function jh(t,e,n){const s=new Ht({id:`${t}-hand`,tracks:e.filter(l=>l.target===t)}),i=Zl({x:n.x,y:n.y,style:n.style,cast:n.cast}),r=n.side??"right",o=n.every??33,a=[];for(let l=n.start;;l=Math.min(n.end,l+o)){const{joints:c}=Ql(i,{time:l,state:s.getStateAtTime(l)},t),h=c.hands[r],u=c.fingertips[r];if(a.push({time:l,x:(h.x+u.x)/2,y:(h.y+u.y)/2}),l>=n.end)break}return a}const Ns=["start","contact","release","end"],z4=["surface","edit","anchor","at","until"],q4=["carry"],ea=t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&"surface"in t&&"anchor"in t,j4=t=>t.then===void 0?[]:Array.isArray(t.then)?t.then:[t.then];function K4(t,e,n,s={}){const i=Hy(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 r=n.map(d=>Fy(d,e)),o=ta(t,r,s),a=Y4(r,o.beats,s),l=s.ground??0,c=d=>s.ride===!1?d:Object.values(e).reduce((f,m)=>m.ride(f,t,{ground:l}),d);n.forEach((d,f)=>{for(const m of j4(d)){const g=w=>new Error(`surfaceScript: beat ${f} (${d.do}), ${m.edit} on ${m.surface}: ${w}`),p=(w,S)=>{const x=typeof w=="object"?w.beat:f,M=(typeof w=="object"?w.at:w)??S??"start",E=a[x][M];if(E===void 0){const T=Ns.filter(A=>a[x][A]!==void 0).join(", ");throw g(`beat ${x} (${n[x].do}) has no ${M} (it has ${T})`)}return E},b=e[m.surface],v=p(m.at??(a[f].contact!==void 0?"contact":"start")),k=m.until===void 0?void 0:p(m.until,"end");if(k!==void 0&&k<v)throw g(`it ends (${k} ms) before it starts (${v} ms)`);try{if(m.edit==="carry"){const S=b.piece(m.anchor),x=jh(t,c(o.tracks),{x:s.from??0,y:l,style:s.figureStyle??(s.height?{height:s.height}:void 0),cast:s,start:v,end:k});b.follow(S,x);continue}const w=Object.fromEntries(Object.entries(m).filter(([S])=>!z4.includes(S)));b.edit(m.edit,m.anchor,{...w,at:v,...k!==void 0?{duration:k-v}:{}})}catch(w){throw g(w.message)}}});const h=c(o.tracks),u=Object.entries(e).flatMap(([d,f])=>f.tracks(d));return{...o,tracks:[...h,...u],figureTracks:h}}function Hy(t,e,n={}){if(!Array.isArray(t))return ir(t,n);const s=[],i=Object.keys(e),r=(c,h,u)=>{const d=typeof h=="string"?e[h]:void 0;return d||s.push({level:"error",beat:c,message:`${u}: ${dt("surface",h,i)}`}),d},o=(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 (${Ns.join(", ")}), not at ms; set the beat's own \`at\` to move it.`}):(typeof d!="string"||!Ns.includes(d))&&s.push({level:"error",beat:c,message:`${u}: ${dt("moment",d,Ns)}`})};t.forEach((c,h)=>{if(!c||typeof c!="object"||Array.isArray(c))return;const u=c;for(const f of["target","to","onto"]){if(!ea(u[f]))continue;const m=u[f],g=r(h,m.surface,`\`${f}\``);g&&o(h,g,m.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 m=f,g=r(h,m.surface,"`then`");if(!g)return;const p=`\`then\` (${String(m.edit)} on ${String(m.surface)})`,b=[...Object.keys(g.about.edits),...q4];if(typeof m.edit!="string"||!b.includes(m.edit)){s.push({level:"error",beat:h,message:`\`then\`: ${dt("edit",m.edit,b)}`});return}for(const v of Array.isArray(m.anchor)?m.anchor:[m.anchor])o(h,g,v,p);m.edit==="carry"&&typeof m.anchor!="string"&&s.push({level:"error",beat:h,message:`${p}: \`carry\` takes one anchor, the piece it carries.`}),m.edit==="carry"&&m.until===void 0&&s.push({level:"error",beat:h,message:`${p}: \`carry\` needs \`until\` (when it lets go, such as { beat: ${h+1}, at: 'release' }).`}),m.at!==void 0&&a(h,m.at,`${p} \`at\``),m.until!==void 0&&a(h,m.until,`${p} \`until\``),m.until!==void 0&&m.duration!==void 0&&s.push({level:"error",beat:h,message:`${p}: give \`until\` or \`duration\`, not both.`})})});const l=t.map(c=>c&&typeof c=="object"&&!Array.isArray(c)?Fy(c,e,!0):c);return[...ir(l,n),...s]}function Fy(t,e,n=!1){const{then:s,...i}=t,r=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}},o={...i};return ea(t.target)&&(o.target=r(t.target)),ea(t.to)&&(o.to=r(t.to).x),ea(t.onto)&&(o.onto=r(t.onto).top),o}function Y4(t,e,n){let s=0;return t.map(i=>{const r=Zo([i],n.actions).length,o=e.slice(s,s+r);s+=r;const a=o.find(c=>c.contact!==void 0)?.contact,l=[...o].reverse().find(c=>c.release!==void 0)?.release;return{start:o[0]?.start,end:o[o.length-1]?.end,...a!==void 0?{contact:a}:{},...l!==void 0?{release:l}:{}}})}function X4(t){const e={actions:t.actions,gaits:t.gaits},n=_h(e);if(n.length>0)throw new Error(`persona "${t.name}": ${n.join(" ")}`);const s=[...Object.keys(Gt),...Object.keys(t.gaits??{})],i=t.gait??"walk";if(!s.includes(i))throw new Error(`persona "${t.name}": ${dt("gait",i,s)}`);if(t.mood&&!(t.mood in Mt))throw new Error(`persona "${t.name}": ${dt("mood",t.mood,Object.keys(Mt))}`);const r=t.acting??"snappy";if(typeof r=="string"&&!(r in Xn))throw new Error(`persona "${t.name}": ${dt("acting style",r,Object.keys(Xn))}`);if(typeof t.stance=="string"&&!(t.stance in he))throw new Error(`persona "${t.name}": ${dt("stance",t.stance,Object.keys(he))}`);const o=t.height??120,a=typeof t.stance=="string"?he[t.stance]:Bt(t.stance??{}),l=t.mood?an(a,t.mood):a,c={...t.look,height:o},h=t.summary??`${t.name}, a stick figure`;return{name:t.name,summary:h,cast:e,rest:l,height:o,figure:u=>Zl({x:u.x,y:u.y,pose:l,style:{...c,...u.facing?{facing:u.facing}:{}},cast:e}),script:(u,d,f={})=>ta(u,d,{...e,from:f.from,ground:f.ground,facing:f.facing,height:o,style:r,gait:i,start:l,rest:l,energy:t.energy}),check:u=>ir(u,e),handPath:(u,d,f)=>jh(u,d,{...f,style:c,cast:e}),describe:()=>({name:t.name,summary:h,habits:{height:o,acting:typeof r=="string"?r:"custom",gait:i,...t.mood?{mood:t.mood}:{},stance:typeof t.stance=="string"?t.stance:t.stance?"custom":"rest"},actions:Rh(e),own:{actions:Object.keys(t.actions??{}),gaits:Object.keys(t.gaits??{})}})}}const G4=new Set(["x","y","walking","gait"]),Ly=.215+.205;function Ny(t,e,n=1){const{points:s}=ke(t,lt),i=s["hip.left"],r=s["knee.left"],o=s["ankle.left"],a=i&&r&&o?Math.hypot(r.x-i.x,r.y-i.y)+Math.hypot(o.x-r.x,o.y-r.y):Ly*t.height;return Mo(e,a/Ly,n)}function U4(t,e,n,s={}){const i=ta(t,n,{...s,height:e.height,reach:s.reach??Wy(e)}),r=i.tracks.find(b=>b.property==="facing")?.keyframes??[],o=b=>{let v=s.facing??1;for(const k of r)k.time<=b&&(v=k.value);return v},a=Vr(i.keys),l=i.keys.map((b,v)=>{const k=rp(a[v]);return{time:b.time,pose:o(b.time)<0?eg(k):k,...b.easing?{easing:b.easing}:{},...b.act===!1?{act:!1}:{}}}),{rest:c,start:h,...u}=s;Z4(l,a,n,i,e,o,s);const d=gy(t,l,u),f=Wo(t,d,i.lines,{energy:s.energy}),m=i.tracks.filter(b=>G4.has(b.property)),g=i.tracks.find(b=>b.property==="walk");return{tracks:g?[...f,...m,iE(t,g,i.tracks,e,s)]:[...f,...m],duration:i.duration,lines:i.lines,keys:l,beats:i.beats,effects:i.effects}}function Wy(t){const e=vt({"arm.left.spread":90,"arm.left.elbow":0,"arm.left.bend":0,"leg.left.knee":0}),n=ke(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),r=Ee({...ut,rightShoulder:90,rightElbow:0,rightWrist:0},{height:t.height,facing:1}),o=Ee({...ut,rightHip:90,rightKnee:0},{height:t.height,facing:1}),a={x:(r.hands.right.x+r.fingertips.right.x)/2,y:(r.hands.right.y+r.fingertips.right.y)/2},l=Math.hypot(a.x-r.shoulders.right.x,a.y-r.shoulders.right.y),c=Math.hypot(o.feet.right.x-o.hip.x,o.feet.right.y-o.hip.y);return{arm:l>0?s/l:1,leg:c>0?i/c:1}}const V4={point:"arm",grab:"arm",put:"arm",write:"arm",swipe:"arm",push:"arm",kick:"leg"},J4=new Set(["point","grab","put","kick"]);function Z4(t,e,n,s,i,r,o){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:(o.from??0)+Number(u?.get("x")??0),y:(o.ground??0)+Number(u?.get("y")??0)}};n.forEach((h,u)=>{const d=V4[h.do],f=a[u];if(!d||f.contact===void 0||h.do!=="swipe"&&!h.target)return;const m=f.contact,g=f.release??f.contact;t.forEach((p,b)=>{if(p.time<m-1||p.time>g+1)return;const v=r(p.time),k=Ee(e[b],{height:i.height,facing:v<0?-1:1}),w=c(p.time),S=J4.has(h.do)&&h.target?{x:h.target.x-w.x,y:h.target.y-w.y}:void 0,x={x:(k.hands.right.x+k.fingertips.right.x)/2,y:(k.hands.right.y+k.fingertips.right.y)/2},M=S??(d==="arm"?x:k.toes.right),E=v<0?"right":"left",T=`${d}.${E}`;let A=p.pose;if(h.do==="point")A=qe(i,A,T,M);else if(d==="arm")A=qe(i,sE(i,A,E,M),T,M);else for(let P=0;P<3;P++){const I=ke(i,A).points,O=I[`ankle.${E}`],_=I[`toe.${E}`];A=qe(i,A,T,{x:M.x-(_.x-O.x),y:M.y-(_.y-O.y)})}t[b]={...p,pose:A}})})}function Q4(t,e){const n=vt({[`arm.${e}.spread`]:90,[`arm.${e}.elbow`]:0,[`arm.${e}.bend`]:0}),s=ke(t,n).points;return Math.hypot(s[`hand.${e}`].x-s[`shoulder.${e}`].x,s[`hand.${e}`].y-s[`shoulder.${e}`].y)}const tE=5,eE=4,nE=8;function sE(t,e,n,s){const i=Q4(t,n)*.9,r=a=>{const l=ke(t,a).points[`shoulder.${n}`];return Math.hypot(s.x-l.x,s.y-l.y)<=i};if(r(e))return e;let o=e;for(let a=1;a<=nE;a++)if(o={...e,lean:(e.lean??0)+tE*a,bend:(e.bend??0)+eE*a},r(o))return o;return o}function iE(t,e,n,s,i){const r=n.find(u=>u.property==="gait"),o=r?new Ht({id:`${t}-gait-of`,tracks:[r]}):void 0,a=u=>{const d=o?.getStateAtTime(u).values.get(t)?.get("gait");if(typeof d=="string")return Gt[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],m=a((f.time+u.time)/2),g=Xr(m,s.height),p=Ny(s,m);h+=(u.value-f.value)*(p>0?g/p:1)}else h=u.value;c.push({...u,value:h})}),{...e,keyframes:c}}const pn=t=>Math.min(1,Math.max(0,Number.isFinite(t)?t:0)),Ne=t=>{const e=pn(t);return e*e*(3-2*e)},ie=(t,e,n)=>n<=0?t>=e?1:0:pn((t-e)/n);function na(t){const e=pn(t);if(e===0||e===1)return e;const n=1.70158,s=e-1;return 1+(n+1)*s*s*s+n*s*s}function Dy(t,e,n,s=300,i=300){return t>=e&&t<=e+n?Ne(ie(t,e,s))*(1-Ne(ie(t,e+n-i,i))):0}function xe(t,e){const n=pn(e),s=t.trim(),i=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(s)?.[1];if(i){const o=i.length===3?[...i].map(h=>h+h).join(""):i,[a,l,c]=[0,2,4].map(h=>parseInt(o.slice(h,h+2),16));return`rgba(${a},${l},${c},${By(n)})`}const r=/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+)\s*)?\)$/i.exec(s);return r?`rgba(${r[1]},${r[2]},${r[3]},${By(n*(r[4]===void 0?1:Number(r[4])))})`:s}const By=t=>Math.round(t*1e3)/1e3;function sa(t,e,n){const s=[];for(const i of e.split(`
|
|
61
|
-
`)){let r="";for(const o of i.split(/\s+/).filter(Boolean)){const a=r?`${r} ${o}`:o;r&&t.measureText(a).width>n?(s.push(r),r=o):r=a}s.push(r)}return s}function Pe(t,e,n,s,i,r){const o=Math.max(0,Math.min(r,Math.abs(s)/2,Math.abs(i)/2));t.beginPath(),t.moveTo(e+o,n),t.lineTo(e+s-o,n),t.quadraticCurveTo(e+s,n,e+s,n+o),t.lineTo(e+s,n+i-o),t.quadraticCurveTo(e+s,n+i,e+s-o,n+i),t.lineTo(e+o,n+i),t.quadraticCurveTo(e,n+i,e,n+i-o),t.lineTo(e,n+o),t.quadraticCurveTo(e,n,e+o,n),t.closePath()}const Jt=(t,e,n)=>`${e} ${Math.round(t)}px ${n}`,Vn="system-ui, sans-serif";function rE(t,e,n){const{x:s,y:i,width:r,height:o}=n,a=Math.max(0,Math.round(n.drops??70));if(a===0||r<=0||o<=0)return;const l=n.speed??900,c=n.length??34,h=n.slant??-8,u=Se(n.seed??1),d=o+c*2;t.save(),t.beginPath(),t.rect(s,i,r,o),t.clip(),t.strokeStyle=xe(n.color??"rgb(190,210,235)",n.opacity??.35),t.lineWidth=n.lineWidth??2,t.lineCap="round",t.beginPath();for(let f=0;f<a;f++){const m=s+u.next()*r,g=l*(1+u.next()*.6),p=u.next()*d,b=e/1e3*g+p,v=i-c+(b%d+d)%d;t.moveTo(m,v),t.lineTo(m+h,v+c)}t.stroke(),t.restore()}function oE(t,e){const{x:n,y:s,width:i,height:r}=e,o=e.slope??.35,a=Math.max(4,e.spacing??52),l=e.band??24,c=i*o,h=Math.floor((-Math.max(0,c)-l)/a)-1,u=Math.ceil((r-Math.min(0,c))/a)+1;t.save(),t.beginPath(),t.rect(n,s,i,r),t.clip(),t.fillStyle=xe(e.color??"rgb(255,240,210)",e.opacity??.12),t.beginPath();for(let d=h;d<=u;d++){const f=s+d*a;t.moveTo(n,f),t.lineTo(n+i,f+c),t.lineTo(n+i,f+c+l),t.lineTo(n,f+l),t.closePath()}t.fill(),t.restore()}function zy(t){const e=t.angle*Math.PI/180,n=Math.cos(e),s=Math.sin(e),i={x:t.x+n*t.length,y:t.y+s*t.length};return[{x:t.x,y:t.y},{x:i.x-s*t.width,y:i.y+n*t.width},{x:i.x+s*t.width,y:i.y-n*t.width}]}function aE(t,e){const n=pn(e.amount);if(n<=0)return;const s=e.bounds??{x:-1e5,y:-1e5,width:2e5,height:2e5},i=e.color??"rgb(4,6,10)",r=(e.cones??[]).map(zy),o=a=>{t.moveTo(a[0].x,a[0].y),t.lineTo(a[1].x,a[1].y),t.lineTo(a[2].x,a[2].y),t.closePath()};t.save(),t.beginPath(),t.rect(s.x,s.y,s.width,s.height);for(const a of r)o(a);for(const a of e.holes??[])t.moveTo(a.x+a.radius,a.y),t.arc(a.x,a.y,a.radius,0,Math.PI*2,!0);t.fillStyle=xe(i,(e.opacity??.9)*n),t.fill("evenodd");for(const a of r)t.beginPath(),o(a),t.fillStyle=xe(i,.35*n),t.fill(),e.beam!==null&&(t.fillStyle=xe(e.beam??"rgb(255,236,190)",(e.beamOpacity??.08)*n),t.fill());t.restore()}function lE(t,e){const{x:n,y:s,radius:i}=e;if(!(i>0))return;const r=e.color??"rgb(245,185,66)",o=t.createRadialGradient(n,s,0,n,s,i);o.addColorStop(0,xe(r,e.opacity??.5)),o.addColorStop(1,xe(r,0)),t.save(),t.fillStyle=o,t.fillRect(n-i,s-i,2*i,2*i),t.restore()}function cE(t,e){const n=e.x??0,s=e.y??0,i=n+e.width/2,r=s+e.height/2,o=Math.hypot(e.width,e.height)/2,a=e.color??"rgb(0,0,0)",l=t.createRadialGradient(i,r,o*(e.inner??.38),i,r,o*(e.outer??1.05));l.addColorStop(0,xe(a,0)),l.addColorStop(1,xe(a,e.opacity??.55)),t.save(),t.fillStyle=l,t.fillRect(n,s,e.width,e.height),t.restore()}function hE(t,e,n=170){let s=0;for(const i of e)s=Math.max(s,1-Math.abs(t-i)/Math.max(1,n));return pn(s)}function uE(t,e=.18){const n=t/1e3;return Math.sin(n*40)*Math.sin(n*13)>.3?e:0}const Jn="#d7263d",Kh="#f5b942",ia="#efe6d2",yn="#111111";function qy(t,e){const n=e.duration??3e3;return t>=e.at&&t<=e.at+n?{opacity:pn(na(ie(t,e.at,300)))*(1-Ne(ie(t,e.at+n-400,400))),scale:1+.08*Math.sin((t-e.at)/1e3*7)}:{opacity:0,scale:1}}function dE(t,e,n){const{opacity:s,scale:i}=qy(e,n);if(s<=0)return 0;const r=n.radius??46,o=n.lineWidth??6,{x:a,y:l}=n;return t.save(),t.globalAlpha*=Math.min(1,s),t.strokeStyle=n.color??Jn,t.lineWidth=o,t.beginPath(),t.arc(a,l,r*i,0,Math.PI*2),t.stroke(),t.lineWidth=o*10/6,t.lineCap="round",t.beginPath(),t.moveTo(a+r*.72*i,l+r*.72*i),t.lineTo(a+r*1.35,l+r*1.35),t.stroke(),t.restore(),s}function fE(t,e){const n=e.ink??yn,s=e.color??"#b91c1c";t.save(),t.translate(e.x,e.y),t.rotate((e.angle??0)*Math.PI/180);const i=e.scale??1;t.scale(i,i),t.lineJoin="round",t.strokeStyle=n,t.lineWidth=3,t.fillStyle=s,Pe(t,-34,-30,26,10,3),t.fill(),t.stroke(),Pe(t,-34,-24,68,48,4),t.fill(),t.stroke(),t.strokeStyle="#fca5a5",t.lineCap="round",t.beginPath(),t.moveTo(-22,-6),t.lineTo(22,-6),t.stroke(),e.label&&(t.fillStyle=e.labelColor??ia,t.font=Jt(13,800,e.font??Vn),t.textAlign="center",t.textBaseline="middle",t.fillText(e.label,0,9,60)),t.restore()}function gE(t,e){const n=e.radius??52,s=e.ink??yn,{x:i,y:r}=e;t.save(),t.lineCap="round",t.beginPath(),t.arc(i,r,n,0,Math.PI*2),t.fillStyle=e.face??"#f5f0e1",t.fill(),t.strokeStyle=s,t.lineWidth=n*.115,t.stroke(),t.lineWidth=n*.058,t.beginPath();for(let c=0;c<12;c++){const h=c/12*Math.PI*2;t.moveTo(i+Math.sin(h)*n*.77,r-Math.cos(h)*n*.77),t.lineTo(i+Math.sin(h)*n*.88,r-Math.cos(h)*n*.88)}t.stroke();const o=(c,h,u)=>{t.lineWidth=u,t.beginPath(),t.moveTo(i,r),t.lineTo(i+Math.sin(c)*h,r-Math.cos(c)*h),t.stroke()},{hour:a,minute:l}=jy(e.hours,e.minutes);o(a,n*.5,n*.115),o(l,n*.77,n*.077),t.restore()}function jy(t,e){const n=(e%60+60)%60;return{hour:((t%12+12)%12+n/60)/12*Math.PI*2,minute:n/60*Math.PI*2}}function mE(t,e,n){const s=n.size??30,i=n.color??Kh;t.save(),t.font=Jt(s,800,n.font??Vn);const r=t.measureText(n.text).width+s*1.66,o=s*1.87;return t.globalAlpha*=Ne(ie(e,n.at??100,400)),Pe(t,n.x,n.y,r,o,6),t.fillStyle=n.background??"#000000",t.fill(),t.strokeStyle=i,t.lineWidth=3,t.stroke(),t.fillStyle=i,t.textAlign="center",t.textBaseline="middle",t.fillText(n.text,n.x+r/2,n.y+o/2+s*.04),t.restore(),r}function pE(t,e,n){const s=Dy(e,n.at,n.duration??2600,250,300);if(s<=0)return 0;const i=n.frame??{width:1920,height:1080},r=n.nameSize??64,o=n.roleSize??30,a=n.font??Vn,l=n.side==="left"||n.side==="right"?n.side:n.anchor.x<i.width*.57?"right":"left";t.save();const c=n.dim??.35;c>0&&(t.fillStyle=`rgba(0,0,0,${c*s})`,t.fillRect(0,0,i.width,i.height));const h=r*2.2;t.translate(n.anchor.x+(l==="right"?h:-h),n.anchor.y+r*.6),t.rotate((n.tilt??-3.4)*Math.PI/180),t.globalAlpha*=s,t.font=Jt(r,800,a);const u=t.measureText(n.name).width;t.font=Jt(o,700,a);const d=n.role?t.measureText(n.role).width:0,f=r*.47,m=Math.max(u,d)+f*2+10,g=-r*1.1,p=n.role?r+o+r*.95:r*1.6,b=l==="right"?0:-m;Pe(t,b,g,m,p,4),t.fillStyle=n.color??Jn,t.fill(),t.strokeStyle=n.ink??yn,t.lineWidth=5,t.stroke(),t.textAlign="left",t.textBaseline="alphabetic",t.fillStyle="#ffffff",t.font=Jt(r,800,a);const v=n.role?g+r*1.1+r*.22:g+p/2+r*.35;return t.fillText(n.name,b+f,v),n.role&&(t.font=Jt(o,700,a),t.fillStyle=ia,t.fillText(n.role,b+f,v+o*1.45)),t.restore(),s}function Ky(t,e,n,s){const i=Ne(ie(t,e-50,300))*(1-Ne(ie(t,n,250))),r=s??Math.min(1600,Math.max(0,n-e)*.5);return{opacity:t<e-50||t>n+250?0:i,reveal:ie(t,e,r)}}function yE(t,e){const n=t.reduce((i,r)=>i+r.split(" ").filter(Boolean).length,0);let s=Math.round(pn(e)*n);return t.map(i=>{const r=i.split(" ").filter(Boolean),o=r.slice(0,Math.max(0,Math.min(r.length,s)));return s-=r.length,o.join(" ")})}function bE(t,e,n){const{opacity:s,reveal:i}=Ky(e,n.start,n.end,n.typeDuration);if(s<=0||!n.text)return 0;const r=n.x??150,o=n.width??1620,a=n.bottom??1040,l=n.size??42,c=n.font??Vn,h=n.ink??yn,u=l*1.29;t.save(),t.font=Jt(l,700,c);const d=sa(t,n.text,o-l*1.4),f=a-d.length*u-l*.72;if(t.globalAlpha*=s,Pe(t,r,f,o,a-f,6),t.fillStyle=n.background??xe("rgb(239,230,210)",.96),t.fill(),t.strokeStyle=h,t.lineWidth=5,t.stroke(),n.speaker){t.font=Jt(l*.57,800,c);const g=t.measureText(n.speaker).width+l*1.4;Pe(t,r,f-l*.72,g,l*.86,4),t.fillStyle=n.tagColor??Jn,t.fill(),t.lineWidth=3,t.stroke(),t.fillStyle="#ffffff",t.textAlign="center",t.textBaseline="middle",t.fillText(n.speaker,r+g/2,f-l*.29)}t.font=Jt(l,700,c),t.fillStyle=h,t.textBaseline="alphabetic";const m=yE(d,i);return d.forEach((g,p)=>{const b=t.measureText(g).width;t.textAlign="left",t.fillText(m[p],r+o/2-b/2,f+l*1.38+p*u)}),t.restore(),s}function wE(t,e,n){const s=n.start-50,i=n.end+300,r=na(ie(e,s,280))*(1-Ne(ie(e,i,220)));if(!(e>=s&&e<=i+220)||r<=.01)return 0;const o=n.size??40,a=n.font??Vn,l=n.ink??yn,c=n.fill??"#ffffff",h=n.bounds??{x:40,y:40,width:1840},u=n.tail;t.save(),t.font=Jt(o,700,a);const d=sa(t,n.text,n.maxWidth??640),f=o*1.3,m=Math.max(...d.map(S=>t.measureText(S).width))+o*1.75,g=d.length*f+o*1.25,p=n.speaker?o*.5:0,b=Math.min(h.x+h.width-m/2,Math.max(h.x+m/2,u.x));let v=Math.min(u.y-(n.gap??70)-g/2,n.maxCenterY??1/0);v=Math.max(h.y+p+g/2,v);const k={x:u.x+(b-u.x)*.2,y:Math.max(v+g/2+16,u.y-14)};t.translate(k.x,k.y),t.scale(r,r),t.translate(-k.x,-k.y),t.fillStyle=c,t.strokeStyle=l,t.lineWidth=5,t.lineJoin="round";const w=Math.min(Math.max(k.x,b-m/2+50),b+m/2-50);if(t.beginPath(),t.moveTo(w-22,v+g/2-4),t.lineTo(k.x,k.y),t.lineTo(w+22,v+g/2-4),t.closePath(),t.fill(),t.stroke(),Pe(t,b-m/2,v-g/2,m,g,26),t.fill(),t.stroke(),t.fillRect(w-19,v+g/2-8,38,6),n.speaker){const S=o*.68;t.font=Jt(S,800,a);const x=t.measureText(n.speaker).width+S*1.1;Pe(t,b-m/2+18,v-g/2-S*.74,x,S*1.4,6),t.fillStyle=n.tagColor??l,t.fill(),t.fillStyle=n.tagText??ia,t.textAlign="left",t.textBaseline="middle",t.fillText(n.speaker,b-m/2+18+S*.55,v-g/2-S*.04)}return t.font=Jt(o,700,a),t.fillStyle=l,t.textAlign="center",t.textBaseline="alphabetic",d.forEach((S,x)=>t.fillText(S,b,v-g/2+o*1.65+x*f)),t.restore(),r}const ra=["photo","note"],oa={cross:"two diagonals across the card, one after the other (ruled out)",strike:"one diagonal, bottom-left to top-right (half ruled out)",scribble:"a zigzag back and forth across the card (scribbled out)",circle:"a loose ring round the card (this one)"};function kE(t){const e=t.seed??1,n=Se(e),s=new Set,i=t.cards.map(c=>{if(!c.id)throw new Error("caseBoard: every card needs an id");if(s.has(c.id))throw new Error(`caseBoard: two cards have the id "${c.id}"`);s.add(c.id);const h=c.kind??"photo";if(!ra.includes(h))throw new Error(`caseBoard: ${dt("card kind",h,ra)}`);const u=(n.next()-.5)*6;return{id:c.id,x:c.x,y:c.y,kind:h,title:c.title,note:c.note,width:c.width??220,height:c.height??(h==="photo"?260:124),angle:c.angle??u,color:c.color??(h==="photo"?"#f5f1e8":"#fef08a"),at:c.at??0,highlight:c.highlight}}),r=[...s],o=(c,h)=>{if(!s.has(c))throw new Error(`caseBoard: ${h}: ${dt("card",c,r)}`)},a=(t.strings??[]).map((c,h)=>(o(c.from,`strings[${h}].from`),o(c.to,`strings[${h}].to`),{from:c.from,to:c.to,at:c.at??0,duration:c.duration??600,color:c.color??"#b91c1c"})),l=(t.marks??[]).map((c,h)=>{if(o(c.on,`marks[${h}].on`),!(c.kind in oa))throw new Error(`caseBoard: marks[${h}]: ${dt("mark",c.kind,Object.keys(oa))}`);return{on:c.on,kind:c.kind,at:c.at,duration:c.duration??1400,color:c.color??Jn,width:c.width??(c.kind==="scribble"?18:16)}});return{x:t.x,y:t.y,width:t.width,height:t.height,cards:i,strings:a,marks:l,cork:t.cork??"#9a6b43",frame:t.frame??"#4a2f1e",ink:t.ink??yn,font:t.font??Vn,handFont:t.handFont??t.font??Vn,seed:e}}const Yh=(t,e)=>{const n=t.cards.find(s=>s.id===e);if(!n)throw new Error(dt("card",e,t.cards.map(s=>s.id)));return n};function aa(t,e,n){const s=e.angle*Math.PI/180;return{x:t.x+e.x+n.x*Math.cos(s)-n.y*Math.sin(s),y:t.y+e.y+n.x*Math.sin(s)+n.y*Math.cos(s)}}function la(t,e){const n=Yh(t,e),s=n.width/2,i=n.height;return{pin:aa(t,n,{x:0,y:0}),center:aa(t,n,{x:0,y:i/2}),corners:[{x:-s,y:0},{x:s,y:0},{x:s,y:i},{x:-s,y:i}].map(r=>aa(t,n,r)),width:n.width,height:n.height}}function Xh(t,e){const n=Yh(t,e.on),s=n.width/2-10,i=8,r=n.height-8,o=(a,l)=>aa(t,n,{x:a,y:l});if(e.kind==="cross")return[[o(-s,i),o(s,r)],[o(s,i),o(-s,r)]];if(e.kind==="strike")return[[o(-s,r),o(s,i)]];if(e.kind==="scribble"){const a=n.height/2,l=n.height*.33;return[Array.from({length:15},(c,h)=>o(-s+h*2*s/14,h%2?a-l:a+l))]}return[Array.from({length:41},(a,l)=>{const c=-2.4+l/40*Math.PI*2.15,h=1+.04*Math.sin(l*1.7);return o(Math.cos(c)*(s+30)*h,n.height/2+Math.sin(c)*(n.height/2+26)*h)})]}function Yy(t,e){const n=t.map(Cl),s=n.reduce((r,o)=>r+o,0)||1;let i=e*s;return n.map(r=>{const o=r>0?Math.min(1,Math.max(0,i/r)):1;return i-=r,o})}function Xy(t,e){let n=null;for(const s of t.marks){if(e<=s.at||e>=s.at+s.duration)continue;const i=Xh(t,s),r=Yy(i,Ne(ie(e,s.at,s.duration))),o=Math.max(0,r.findIndex(l=>l<1)),a=sn(i[o],r[o]);n=a[a.length-1]}return n}function Gy(t,e,n,s={}){const i=s.radius??11;t.save(),t.beginPath(),t.arc(e,n,i,0,Math.PI*2),t.fillStyle=s.color??Jn,t.fill(),t.lineWidth=3,t.strokeStyle=s.ink??yn,t.stroke(),t.beginPath(),t.arc(e-i*.27,n-i*.27,i*.27,0,Math.PI*2),t.fillStyle="#fca5a5",t.fill(),t.restore()}function Uy(t,e,n,s={}){if(n<=0||e.length<2)return null;const i=sn(e,n);t.save(),t.strokeStyle=s.color??Jn,t.lineWidth=s.width??16,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(i[0].x,i[0].y);for(const r of i.slice(1))t.lineTo(r.x,r.y);return t.stroke(),t.restore(),i[i.length-1]}function vE(t,e,n,s={}){const{x:i,y:r,width:o,height:a,ink:l}=e;t.save(),Pe(t,i,r,o,a,10),t.fillStyle=e.cork,t.fill(),t.save(),t.clip();const c=Se(e.seed+7);t.fillStyle="rgba(60,35,15,0.25)";const h=Math.round(o*a/3e3);for(let d=0;d<h;d++)t.beginPath(),t.arc(i+c.next()*o,r+c.next()*a,2+c.next()*2,0,Math.PI*2),t.fill();t.restore(),Pe(t,i,r,o,a,10),t.lineWidth=22,t.strokeStyle=e.frame,t.stroke();const u=d=>n>=d.at?na(ie(n,d.at,350)):0;for(const d of e.strings){const f=Ne(ie(n,d.at,d.duration));if(f<=0||u(Yh(e,d.from))<=0)continue;const m=la(e,d.from).pin,g=la(e,d.to).pin;t.strokeStyle=d.color,t.lineWidth=4,t.lineCap="round",t.beginPath(),t.moveTo(m.x,m.y),t.lineTo(m.x+(g.x-m.x)*f,m.y+(g.y-m.y)*f),t.stroke()}for(const d of e.cards){const f=u(d);if(f<=0)continue;const m=d.width,g=d.height;t.save(),t.translate(i+d.x,r+d.y-40*(1-Math.min(1,f))),t.rotate(d.angle*Math.PI/180),t.scale(f,f),Pe(t,-m/2,0,m,g,3),t.fillStyle=d.color,t.fill(),t.lineWidth=3,t.strokeStyle=l,t.stroke();const p=d.kind==="photo",b=p?{x:-m/2+18,y:18,width:m-36,height:g*.62}:{x:-m/2+12,y:14,width:m-24,height:g*.45};p&&(t.fillStyle="#1e2530",t.fillRect(b.x,b.y,b.width,b.height)),s.drawCard&&(t.save(),t.beginPath(),t.rect(b.x,b.y,b.width,b.height),t.clip(),s.drawCard(t,d,b,n),t.restore()),t.textAlign="center",t.textBaseline="alphabetic";const v=b.y+b.height;if(p)d.title&&(t.font=Jt(28,800,e.font),t.fillStyle=l,t.fillText(d.title,0,v+(g-v)*.45,m-16)),d.note&&(t.font=Jt(19,600,e.font),t.fillStyle="#7f1d1d",t.fillText(d.note,0,v+(g-v)*.8,m-16));else{const w=[d.title,d.note].filter(Boolean).join(`
|
|
62
|
-
`);t.font=Jt(26,700,e.handFont),t.fillStyle=l;const S=sa(t,w,m-20),x=s.drawCard?v+8:(g-S.length*30)/2;S.forEach((M,E)=>t.fillText(M,0,x+24+E*30,m-12))}d.highlight&&n>=d.highlight.at&&n<=d.highlight.at+d.highlight.duration&&(t.strokeStyle=Kh,t.lineWidth=8,t.globalAlpha*=.6+.4*Math.sin((n-d.highlight.at)/1e3*6),t.strokeRect(-m/2-8,-8,m+16,g+16)),t.restore();const k=la(e,d.id).pin;Gy(t,k.x,k.y-40*(1-Math.min(1,f)),{ink:l})}for(const d of e.marks){if(n<=d.at)continue;const f=Xh(e,d),m=Yy(f,Ne(ie(n,d.at,d.duration)));f.forEach((g,p)=>Uy(t,g,m[p],{color:d.color,width:d.width}))}return t.restore(),Xy(e,n)}const Vy={atmosphere:{"drawRain(ctx, time, { x, y, width, height, drops?, opacity?, color?, speed?, length?, slant?, lineWidth?, seed? })":"rain streaks falling in a box (a window, the frame), clipped to it; seeded, a pure function of time","drawBlinds(ctx, { x, y, width, height, opacity?, slope?, spacing?, band?, color? })":"key light through venetian blinds: slanted bright bands","drawDarkness(ctx, { amount, cones?: [{ x, y, angle (deg), length, width }], holes?: [{ x, y, radius }], bounds?, color?, opacity?, beam?, beamOpacity? })":"a dark room with torch beams and round holes of light cut out (coneCorners(cone) gives a beam’s corners)","drawGlow(ctx, { x, y, radius, color?, opacity? })":"a soft pool of light","drawVignette(ctx, { width, height, x?, y?, inner?, outer?, opacity?, color? })":"the frame’s edges fall into dark","lightningFlash(time, strikes, decay?)":"flash brightness 0..1 from strike times (ms)","lightFlicker(time, strength?)":"a failing bulb: how much darker the room is (0 or strength)"},overlays:{"drawClueMarker(ctx, time, { x, y, radius?, at, duration?, color?, lineWidth? })":"the red magnifier over a clue: pops on, pulses, fades (clueMarkerAt gives its opacity and scale)","drawEvidenceFolder(ctx, { x, y, scale?, angle?, color?, ink?, label?, font? })":"a tabbed evidence folder","drawClockFace(ctx, { x, y, radius?, hours, minutes, face?, ink? })":"a wall clock showing a time (clockHandAngles gives the hands)","drawTimeChip(ctx, time, { x, y, text, size?, font?, color?, background?, at? })":"a time/place chip in a corner; returns its width","drawNameCard(ctx, time, { name, role?, at, duration?, anchor, side?, frame?, dim?, color?, font?, tilt? })":"a freeze-frame suspect card: the frame dims, a slanted red band beside the head","drawNarrationBox(ctx, time, { text, start, end, speaker?, x?, width?, bottom?, size?, font?, typeDuration? })":"a first-person narration box along the bottom, words typed on (lineReveal gives opacity and reveal)","drawSpeechBubble(ctx, time, { text, start, end, tail, speaker?, maxWidth?, size?, font?, bounds?, maxCenterY?, gap? })":"a comic speech bubble above the speaker, tail to the head, popping on"},caseBoard:{"caseBoard({ x, y, width, height, cards, strings?, marks?, cork?, frame?, font?, handFont?, seed? })":"checks and resolves a case board (did-you-mean on unknown card ids and kinds)","drawCaseBoard(ctx, board, time, { drawCard? })":"the board at a time: cork, red strings stretching, cards popping up on pins, marker strokes; returns the nib point while a mark is drawn","caseBoardMarkerTip(board, time)":"where the marker’s nib is (for a hand), or null","caseCardBox(board, id)":"a card’s pin, centre and corners, scene px","caseMarkPath(board, { on, kind })":"a mark’s stroke points","drawPushPin(ctx, x, y, { color?, radius? })":"a red push pin","drawMarkerStroke(ctx, points, progress, { color?, width? })":"the first part of a marker stroke; returns the nib"},cardKinds:ra,markKinds:oa,card:"{ id, x, y (its pin, relative to the board), kind?, title?, note?, width?, height?, angle?, color?, at?, highlight?: { at, duration } }",string:"{ from, to, at?, duration?, color? }",mark:"{ on, kind, at, duration?, color?, width? }"},yt=["rect","circle","text","line","path","image","custom"],ca={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:yt},y:{description:"Moves it down by this much from where it was placed (an offset)",unit:"px",types:yt},opacity:{description:"How opaque it is",unit:"0..1",min:0,max:1,types:yt},rotate:{description:"Turns it clockwise about its origin",unit:"degrees",types:yt},rotateX:{description:"Tips it about the horizontal axis (3D; shows with perspective)",unit:"degrees",types:yt},rotateY:{description:"Turns it about the vertical axis (3D; shows with perspective)",unit:"degrees",types:yt},z:{description:"Depth toward the viewer (shows with perspective)",unit:"px",types:yt},perspective:{description:"Distance from the viewer: nearer parts grow, further ones shrink",unit:"px",min:1,types:yt},scale:{description:"Size, both ways",unit:"factor",types:yt},scaleX:{description:"Width factor",unit:"factor",types:yt},scaleY:{description:"Height factor",unit:"factor",types:yt},skewX:{description:"Slants it sideways",unit:"degrees",types:yt},skewY:{description:"Slants it up and down",unit:"degrees",types:yt},originX:{description:"Transform pivot across its box",unit:"% (0 left, 50 centre, 100 right)",min:0,max:100,types:yt},originY:{description:"Transform pivot down its box",unit:"% (0 top, 50 centre, 100 bottom)",min:0,max:100,types:yt},fill:{description:"Fill colour (also written fillStyle)",kind:"color",types:yt},stroke:{description:"Outline colour (also written strokeStyle)",kind:"color",types:yt},strokeWidth:{description:"Outline width (also written lineWidth)",unit:"px",min:0,types:yt},clipTop:{description:"Hides this much from the top edge, for reveals",unit:"% of its height",min:0,max:100,types:yt},clipRight:{description:"Hides this much from the right edge",unit:"% of its width",min:0,max:100,types:yt},clipBottom:{description:"Hides this much from the bottom edge",unit:"% of its height",min:0,max:100,types:yt},clipLeft:{description:"Hides this much from the left edge",unit:"% of its width",min:0,max:100,types:yt},blur:{description:"Gaussian blur",unit:"px",min:0,types:yt},brightness:{description:"Brightness factor (1 unchanged)",unit:"factor",min:0,types:yt},glow:{description:"Soft glow around it, in glowColor",unit:"px",min:0,types:yt},glowColor:{description:"Colour of the glow",kind:"color",types:yt},shadowX:{description:"Drop shadow offset right",unit:"px",types:yt},shadowY:{description:"Drop shadow offset down",unit:"px",types:yt},shadowBlur:{description:"Drop shadow softness",unit:"px",min:0,types:yt},shadowColor:{description:"Drop shadow colour",kind:"color",types:yt},shine:{description:"A highlight sweeping across the fill",unit:"0..1 (progress)",min:0,max:1,types:yt},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:yt},quaternion:{description:'A rotation as [x, y, z, w] (a track with interpolation: "slerp")',kind:"list",types:yt}},Gh={fillStyle:"fill",strokeStyle:"stroke",lineWidth:"strokeWidth",rotateZ:"rotate",motionPathX:"x",motionPathY:"y",motionPathRotate:"rotate"},ME={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 Jy(t){const e=t,n=Object.entries(ca).filter(([,i])=>i.types.includes(t.type)).map(([i,{types:r,...o}])=>({name:i,...o,...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,r]of Object.entries(t.props??{}))n.push({name:i,description:s?.props?.[i]?.description??"",...s?.props?.[i],value:r});return{type:"custom",...s?{kind:s.kind,summary:s.summary}:{},properties:n,...s?.actions?{actions:s.actions}:{}}}function Zy(t){const e=Jy(t).properties.map(n=>n.name);return[...e,...Object.keys(Gh).filter(n=>e.includes(Gh[n]))]}function SE(t,e){const n=[],s=Object.keys(e);for(const i of t){const r=d=>n.push({level:"error",track:i.id,message:d}),o=e[i.target];if(!o){r(dt("target",i.target,s));continue}const a=Zy(o),l=o.type==="custom"&&o.acceptsProp?.(i.property);if(!a.includes(i.property)&&!l){r(`${i.target}: ${dt("property",i.property,a,ME[i.property])}`);continue}const c=i.keyframes??[];for(let d=1;d<c.length;d++)c[d].time<c[d-1].time&&r(`${i.target}.${i.property}: keyframes out of time order (${c[d-1].time} ms, then ${c[d].time} ms).`);const h=ca[Gh[i.property]??i.property]??o.about?.props?.[i.property],u=h&&(h.kind??"number")==="number";for(const d of c){if(u&&typeof d.value!="number"){r(`${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 Ws=(t,e)=>t[2]<=-e;function Uh(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 Qy(t,e){if(t.every(s=>Ws(s,e)))return t;const n=[];return t.forEach((s,i)=>{const r=t[(i+t.length-1)%t.length],o=Ws(s,e),a=Ws(r,e);o!==a&&n.push(Uh(r,s,e)),o&&n.push(s)}),n.length>=3?n:[]}function TE(t,e){if(t.every(i=>Ws(i,e)))return[t];const n=[];let s=[];return t.forEach((i,r)=>{const o=Ws(i,e);if(r>0){const a=t[r-1],l=Ws(a,e);l&&!o?(s.push(Uh(a,i,e)),n.push(s),s=[]):!l&&o&&s.push(Uh(a,i,e))}o&&s.push(i)}),s.length>0&&n.push(s),n.filter(i=>i.length>=2)}function t1(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},(r,o)=>t+s*o/i)}function EE(t,e,n){const s=(i,r)=>Math.max(0,Math.min(i.length-2,i.findIndex((o,a)=>a>0&&r<=o)-1));return[s(t,n[0]),s(e,n[2])]}function AE(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]],r=Math.hypot(...i)||1;return[i[0]/r,i[1]/r,i[2]/r]};return{...t,vertices:t.vertices.map(s=>ae(e,s)),faces:t.faces.map(s=>({corners:s.corners,normal:n(s.normal)}))}}function ha(t,e,n,s){const i=o=>(o[e]-n)*s>=0;if(t.every(i))return t;const r=[];return t.forEach((o,a)=>{const l=t[(a+t.length-1)%t.length];if(i(o)!==i(l)){const c=(n-l[e])/(o[e]-l[e]);r.push([0,1,2].map(h=>h===e?n:l[h]+(o[h]-l[h])*c))}i(o)&&r.push(o)}),r.length>=3?r:[]}function xE(t,e,n){const s=t.faces.map(o=>({points:o.corners.map(a=>t.vertices[a]),normal:o.normal})),i=[],r={x:e.slice(1,-1),z:n.slice(1,-1)};for(let o=0;o+1<e.length;o++)for(let a=0;a+1<n.length;a++){const l=[],c=new Map,h=m=>{const g=m.map(b=>Math.round(b*1e6)).join(",");let p=c.get(g);return p===void 0&&(p=l.length,l.push(m),c.set(g,p)),p},u=[],d=m=>m===0,f=(m,g)=>m+2===g.length;for(const m of s){let g=m.points;d(o)||(g=ha(g,0,e[o],1)),g.length&&!f(o,e)&&(g=ha(g,0,e[o+1],-1)),g.length&&!d(a)&&(g=ha(g,2,n[a],1)),g.length&&!f(a,n)&&(g=ha(g,2,n[a+1],-1)),g.length>=3&&u.push({corners:g.map(h),normal:m.normal})}u.length>0&&i.push({cell:[o,a],mesh:{vertices:l,faces:u,creases:t.creases,joined:t.joined,walls:r}})}return i}const PE=new WeakMap,$E=new WeakMap,IE=48,e1=t=>t.map(e=>Math.round(e*1e5)).join(",");function n1(t,e,n,s){let i=t.get(e);i||t.set(e,i=new Map);let r=i.get(n);return r===void 0&&(i.size>=IE&&i.clear(),i.set(n,r=s())),r}function Vh(t,e){const n=e1(e);return n1(PE,t,n,()=>{const s=AE(t,e),i=[1/0,1/0,1/0],r=[-1/0,-1/0,-1/0];for(const o of s.vertices)for(const a of[0,1,2])i[a]=Math.min(i[a],o[a]),r[a]=Math.max(r[a],o[a]);return{key:n,inSpace:s,low:i,high:r}})}function OE(t,e){const n=t.map(h=>({...h,...Vh(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 r=t1(s[0],i[0],e),o=t1(s[2],i[2],e),a=`${r.join(",")}|${o.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:EE(r,o,d)}]}return n1($E,h.inSpace,a,()=>xE(h.inSpace,r,o)).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])=>[(r[h]+r[h+1])/2,c,(o[u]+o[u+1])/2]}}const s1=.004,Jh=.05,i1=new WeakMap;function CE(t){let e=i1.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)}),i1.set(t,e)),e}const r1=new WeakMap;function o1(t){return t.filter(({mesh:e})=>CE(e)).map(({part:e,key:n,inSpace:s,low:i,high:r})=>{let o=r1.get(s);return o||(o=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]}}),r1.set(s,o)),{part:e,key:n,planes:o,low:i,high:r}})}function _E(t,e,n,s){const i=e.reduce((r,o)=>[r[0]+o[0]/e.length,r[1]+o[1]/e.length,r[2]+o[2]/e.length],[0,0,0]);for(const r of s){if(r.part===t||[0,1,2].some(a=>i[a]<r.low[a]-Jh||i[a]>r.high[a]+Jh))continue;if(r.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)<=s1))return l<-.9;const h=Math.abs(l)<.5?Jh:s1;return c.every(u=>u<=h)}))return!0}return!1}const a1=new WeakMap;function l1(t,e,n,s,i){const r=`${s}|${i.map(l=>l.key).join(";")}`;let o=a1.get(e);o||a1.set(e,o=new Map);let a=o.get(r);if(!a){o.size>=48&&o.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=>ae(n,h));a=e.faces.map(h=>_E(t,h.corners.map(u=>c[u]),l(h.normal),i)),o.set(r,a)}return a}const Ds={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}},Zh=Math.PI/180;function c1(t,e,n){return{toView:s=>sg(ee(s,t*90*Zh),-e*Zh),toScreen:s=>({x:s[0]*n,y:-s[1]*n})}}const h1=new WeakMap,or=t=>ua(t),ua=t=>{let e=h1.get(t);return e||h1.set(t,e=Ip(t)),e};function Ot(t,e,n){return e[n]??t.controls[n]?.default??Ds[n]?.default??0}function ar(t,e){const n=Math.max(.05,Ot(t,e,"squash")),s=1/Math.sqrt(n),r=[1,0,0,0,0,1,Ot(t,e,"lean"),0,0,0,1,0,0,0,0,1];return[In([0,Ot(t,e,"lift"),0]),Te(Zt([1,0,0],-Ot(t,e,"pitch"))),Te(Zt([0,0,1],Ot(t,e,"roll"))),r,On([s,n,s]),On(Array(3).fill(Math.max(0,Ot(t,e,"size"))))].reduce((o,a)=>Ft(o,a))}function Qh(t,e){const n=ar(t,e),s=new Map,i=Object.entries(t.controls).flatMap(([o,a])=>(a.bind??[]).map(l=>({value:Ot(t,e,o),bind:l}))),r=o=>{const a=s.get(o.id);if(a)return a;const l=o.parent?t.parts.find(h=>h.id===o.parent):void 0;if(o.parent&&!l)throw new Error(`prop rig: part "${o.id}" hangs from "${o.parent}", which is not a part`);let c=Ft(l?r(l):n,In(o.at??[0,0,0]));if(o.rotate){const[h,u,d]=o.rotate;h&&(c=Ft(c,Te(Zt([1,0,0],h)))),u&&(c=Ft(c,Te(Zt([0,1,0],u)))),d&&(c=Ft(c,Te(Zt([0,0,1],d))))}for(const{value:h,bind:u}of i)if(!(!u.parts.includes(o.id)||h===0)){if(u.translate&&(c=Ft(c,In([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,In(d),Te(Zt(f,u.rotate.degrees*h)),In([-d[0],-d[1],-d[2]])].reduce((m,g)=>Ft(m,g))}u.scale&&(c=Ft(c,On([1+(u.scale[0]-1)*h,1+(u.scale[1]-1)*h,1+(u.scale[2]-1)*h])))}return s.set(o.id,c),c};for(const o of t.parts)r(o);return s}const t0=(()=>{const t=[-.45,.75,.5],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),RE=Math.cos(35*Zh);function e0(t,e,n,s,i={}){const r=t.derive?{...e,...t.derive(e)}:e,o=Qh(t,r),a=n.toView([0,0,0]),l=_=>L=>[_[0]*L[0]+_[4]*L[1]+_[8]*L[2],_[1]*L[0]+_[5]*L[1]+_[9]*L[2],_[2]*L[0]+_[6]*L[1]+_[10]*L[2]],c=ar(t,r),h=i.slice===void 0?null:ll(c),u=h?t.parts.map(_=>({part:_,mesh:ua(_.shape),local:Ft(h,o.get(_.id)),whole:_.shape.type==="tube"})):void 0,d=u?OE(u,i.slice):void 0,f=u?o1(u.map(_=>({part:_.part.id,mesh:_.mesh,...Vh(_.mesh,_.local)}))):void 0,m=(_,L,j,V)=>{const tt=Q=>n.toView(ae(j,Q)),J=L.vertices.map(tt),F=J.map(Q=>n.toScreen(Q)),B=i.perspective?i.near:void 0,Y=Q=>Q.map(ot=>n.toScreen(ot)),R=Q=>B===void 0?Q:Qy(Q,B),K=Q=>B===void 0?[Q]:TE(Q,B),st=l(j),$=L.faces.map(Q=>{const ot=n.toView(st(Q.normal)),ht=[ot[0]-a[0],ot[1]-a[1],ot[2]-a[2]],ft=Math.hypot(...ht)||1;return[ht[0]/ft,ht[1]/ft,ht[2]/ft]}),C=f&&V?l1(_.id,L,V,e1(V),f):void 0,z=Q=>C?.[Q]??!1,X=$.map((Q,ot)=>{if(z(ot))return!1;if(!i.perspective)return Q[2]>1e-6;const ft=L.faces[ot].corners.reduce((bt,wt)=>[bt[0]+J[wt][0],bt[1]+J[wt][1],bt[2]+J[wt][2]],[0,0,0]);return-(Q[0]*ft[0]+Q[1]*ft[1]+Q[2]*ft[2])>1e-9}),W=Q=>L.faces[Q].corners.reduce((ot,ht)=>ot+J[ht][2],0)/L.faces[Q].corners.length,N=L.faces.map((Q,ot)=>({face:Q,i:ot})).filter(({i:Q})=>X[Q]).map(({face:Q,i:ot})=>({i:ot,solved:{points:B===void 0?Q.corners.map(ht=>F[ht]):Y(R(Q.corners.map(ht=>J[ht]))),depth:W(ot),tone:.72+.33*Math.max(0,$[ot][0]*t0[0]+$[ot][1]*t0[1]+$[ot][2]*t0[2])}})).filter(Q=>Q.solved.points.length>=3).sort((Q,ot)=>Q.solved.depth-ot.solved.depth);if(i.light){const Q=l(j);for(const{i:ot,solved:ht}of N){const ft=L.faces[ot].corners,bt=ft.reduce(($0,Wx)=>{const I0=ae(j,L.vertices[Wx]);return[$0[0]+I0[0]/ft.length,$0[1]+I0[1]/ft.length,$0[2]+I0[2]/ft.length]},[0,0,0]),wt=Q(L.faces[ot].normal),Me=Math.hypot(...wt)||1,gr=i.light(bt,[wt[0]/Me,wt[1]/Me,wt[2]/Me]);ht.light=gr.light,ht.fog=gr.fog}}const D=N.map(Q=>Q.solved),G=HE(L),q=[],Z=[];for(const[Q,ot]of G){const ht=ot.filter(bt=>X[bt]).length;if(ht===0)continue;const ft=ot.length===2&&ht===2&&L.creases!==!1&&$[ot[0]][0]*$[ot[1]][0]+$[ot[0]][1]*$[ot[1]][1]+$[ot[0]][2]*$[ot[1]][2]<RE;ot.length===1&&(L.joined||FE(L,Q))||(ot.length===1||ht===1||ft)&&(q.push(Q.split("-").map(Number)),Z.push(ot.filter(bt=>X[bt]).reduce((bt,wt)=>W(wt)>W(bt)?wt:bt)))}const et=Q=>L.faces.findIndex(ot=>ot.corners.length>4&&Math.sign(NE(L.vertices[Q],ot.normal))>0),H=(L.marks??[]).filter(([Q])=>et(Q)<0||X[et(Q)]),U=([Q,ot])=>B===void 0?[[F[Q],F[ot]]]:K([J[Q],J[ot]]).map(Y),nt=H.flatMap(U),at=Q=>B===void 0?[Q.map(ot=>F[ot])]:K(Q.map(ot=>J[ot])).map(Y);if(i.slice!==void 0){const Q=new Map;q.forEach((ot,ht)=>Q.set(Z[ht],[...Q.get(Z[ht])??[],ot]));for(const{i:ot,solved:ht}of N){ht.edges=g1(Q.get(ot)??[]).flatMap(at);const ft=L.faces[ot].corners;ht.center=ft.reduce((wt,Me)=>[wt[0]+J[Me][0]/ft.length,wt[1]+J[Me][1]/ft.length,wt[2]+J[Me][2]/ft.length],[0,0,0]),ht.normal=$[ot];const bt=N[N.length-1].i;ht.marks=H.filter(([wt])=>(et(wt)>=0?et(wt):bt)===ot).flatMap(U)}}const rt=_.glow?Math.max(0,Math.min(1,Ot(t,r,_.glow.control))):0,ct=_.fade?Math.max(0,Math.min(1,Ot(t,r,_.fade.control))):0,it=_.fade?Math.max(0,Math.min(1,_.fade.from+(_.fade.to-_.fade.from)*ct)):1;return{part:_,depth:J.reduce((Q,ot)=>Q+ot[2],0)/Math.max(1,J.length),faces:D,edges:g1(q).flatMap(at),marks:nt,glow:rt,opacity:it,..._.shape.type==="tube"?{spine:LE(K(_.shape.points.map(tt)).map(Y))}:{},...L.walls?{cut:!0}:{}}},g=new Map(u?.map(_=>[_.part.id,_.local])),b=(d?d.pieces.map(_=>({part:_.part,mesh:_.mesh,m:_.cut?c:o.get(_.part.id),local:_.cut?Or():g.get(_.part.id),cell:_.cell})):t.parts.map(_=>({part:_,mesh:ua(_.shape),m:o.get(_.id),local:void 0,cell:void 0}))).map(_=>({cell:_.cell,solved:m(_.part,_.mesh,_.m,_.local)})),v=b.map(_=>_.solved),k=_=>_.filter(L=>L.faces.length>0&&L.opacity>.01).sort((L,j)=>L.depth-j.depth);let w;if(d){const _=new Map(t.parts.map(j=>{const V=o.get(j.id),tt=ua(j.shape).vertices;return[j.id,tt.reduce((J,F)=>J+n.toView(ae(V,F))[2],0)/Math.max(1,tt.length)]})),L=new Map;for(const j of b){const V=j.cell.join(",");L.has(V)||L.set(V,{cell:j.cell,parts:[]}),L.get(V).parts.push(j.solved),j.solved.depth=_.get(j.solved.part.id)}w=[...L.values()].map(({cell:j,parts:V})=>({depth:n.toView(ae(c,d.middle(j)))[2],parts:k(V)})).filter(j=>j.parts.length>0)}const S={};for(const[_,L]of Object.entries(t.anchors??{})){const j=L.part?o.get(L.part):ar(t,r);if(!j)throw new Error(`prop rig: anchor "${_}" is on "${L.part}", which is not a part`);const V=n.toView(ae(j,L.at));S[_]={point:n.toScreen(V),depth:V[2]}}const[x,M]=t.footprint??[t.length*.45,t.length],E=Math.max(0,Ot(t,r,"lift")),T=Math.max(0,Ot(t,r,"size"))/(1+E*.8),A=Array.from({length:24},(_,L)=>{const j=Math.PI*2*L/24;return n.toView([Math.cos(j)*x*.55*T,0,Math.sin(j)*M*.55*T])}),P=i.perspective?i.near:void 0,I={points:(P===void 0?A:Qy(A,P)).map(_=>n.toScreen(_)),opacity:.16*T},O=v.filter(_=>_.part.seeThrough&&_.opacity>.01).flatMap(_=>_.faces.map(L=>L.points));return{under:k(v.filter(_=>!_.part.overRider)),over:k(v.filter(_=>_.part.overRider)),...w?{cells:w}:{},anchors:S,openings:O,shadow:I,pxPerUnit:s,sizePx:t.height*s}}const u1=new WeakMap;function HE(t){let e=u1.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 r=s[i],o=s[(i+1)%s.length],a=r<o?`${r}-${o}`:`${o}-${r}`,l=e.get(a);l?l.push(n):e.set(a,[n])}}u1.set(t,e)}return e}function d1(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=Qh(t,n),i=ll(ar(t,n))??Or(),r=o=>Math.max(0,Math.min(1,o));return t.parts.map(o=>{const a=o.fade?r(Ot(t,n,o.fade.control)):0;return{part:o,matrix:s.get(o.id),local:Ft(i,s.get(o.id)),glow:o.glow?r(Ot(t,n,o.glow.control)):0,opacity:o.fade?r(o.fade.from+(o.fade.to-o.fade.from)*a):1}})}function f1(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=Qh(t,n),i=ar(t,n),r={};for(const[o,a]of Object.entries(t.anchors??{})){const l=a.part?s.get(a.part):i;if(!l)throw new Error(`prop rig: anchor "${o}" is on "${a.part}", which is not a part`);r[o]=ae(l,a.at)}return r}function FE(t,e){if(!t.walls)return!1;const[n,s]=e.split("-").map(r=>t.vertices[Number(r)]),i=(r,o)=>o.some(a=>Math.abs(n[r]-a)<1e-6&&Math.abs(s[r]-a)<1e-6);return i(0,t.walls.x)||i(2,t.walls.z)}function LE(t){return t.reduce((e,n)=>!e||n.length>e.length?n:e,void 0)}const NE=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2];function g1(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 r=0;r<e.length;r++){const[o,a]=e[r],l=s[s.length-1],c=s[0];if(o===l)s.push(a);else if(a===l)s.push(o);else if(a===c)s.unshift(o);else if(o===c)s.unshift(a);else continue;e.splice(r,1),i=!0;break}}n.push(s)}return n}function n0(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 s0(t){const e={};for(const[n,s]of Object.entries({...Ds,...t.rig.controls})){const{bind:i,...r}=s;e[n]=r}return e}function m1(t){const{prop:e}=t,n=t.scale??60,s=e.rig.length*n*1.4,i=e.rig.height*n*1.6,r=s0(e),o={};for(const[l,c]of Object.entries(r))o[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:o,prop:e,propScale:n,propDraw:a,about:{kind:e.kind,summary:e.summary,props:r,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),Zc(l,Bs(e,u,n),{...a,time:h,loose:n0(c,u)})}}}function Bs(t,e,n){const s=c1(Ot(t.rig,e,"turn"),Ot(t.rig,e,"tilt"),n);return e0(t.rig,e,s,n)}function da(t,e,n){const s={...t.props};let i=0,r=0;for(const[l,c]of e.state?.values.get(n)??[])typeof c=="number"&&(l==="x"?i=c:l==="y"?r=c:l in s&&(s[l]=c));const o={x:t.x+t.width/2+i,y:t.y+t.height+r},a=Bs(t.prop,s,t.propScale);return{values:s,origin:o,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:o.x+c.point.x,y:o.y+c.point.y,depth:c.depth}}}}function WE(t,e,n,s,i={}){const r=da(e,n,s);return t.save(),t.translate(r.origin.x,r.origin.y),Zc(t,r.solved,{...e.propDraw,time:n.time,loose:n0(e,r.values),rider:i.rider?o=>{o.save(),o.translate(-r.origin.x,-r.origin.y),i.rider(o),o.restore()}:void 0}),t.restore(),r}const zs={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"}},DE=400,BE=.2;function zE(t,e={}){const{prop:n}=t,s=s0(n),i=Object.keys(s),r=Object.keys(n.rig.anchors??{}),o=n.rig.parts.map(x=>x.id),a=_s(),l=Ui(a),c=e.tracks?.length?new Ht({id:`${n.kind}-surface`,tracks:e.tracks}):void 0,h=Math.max(0,...(e.tracks??[]).flatMap(x=>x.keyframes.map(M=>M.time))),u=new Map,d=new Map;t.loose=d;const f=t.props,m=x=>{const M={...t.props};let E=0,T=0;if(c){const A=c.getStateAtTime(Math.min(x,h));for(const P of A.values.values())for(const[I,O]of P)typeof O=="number"&&(I==="x"?E=O:I==="y"?T=O:I in M&&(M[I]=O))}for(const A of i)a.keys(A)?.length&&(M[A]=a.valueAt(A,x));return{values:M,origin:{x:t.x+t.width/2+E,y:t.y+t.height+T}}},g=x=>{const{kind:M,rest:E}=jn(x),T=A=>gn(n.kind,x,zs,A);if(M==="box"){if(E)throw T("box takes no arguments");return{kind:M}}if(M==="anchor"){if(!r.includes(E))throw T(dt(`${n.kind} anchor`,E,r));return{kind:M,name:E}}if(M==="part"){if(!o.includes(E))throw T(dt(`${n.kind} part`,E,o));return{kind:M,name:E}}if(M==="control"){if(!i.includes(E))throw T(dt(`${n.kind} control`,E,i));return{kind:M,name:E}}throw T()},p=x=>{const M=(n.rig.controls[x]?.bind??[]).flatMap(T=>T.parts),E=n.rig.parts.filter(T=>T.glow?.control===x).map(T=>T.id);return new Set([...M,...E])},b=new Map,v=x=>{let M=b.get(x);if(!M){const E=m(x);b.set(x,M={...E,solved:Bs(n,E.values,t.propScale)})}return M},k=(x,M)=>{const E=g(x),{values:T,origin:A,solved:P}=v(M);if(E.kind==="box")return St(A.x-t.width/2,A.y-t.height,t.width,t.height);if(E.kind==="anchor"){const _=P.anchors[E.name].point,L=BE*t.propScale;return St(A.x+_.x-L/2,A.y+_.y-L/2,L,L)}if(E.kind==="part")return O(new Set([E.name]),`part "${E.name}" is`);const I=p(E.name);if(I.size===0)return St(A.x-t.width/2,A.y-t.height,t.width,t.height);return O(I,`the parts control "${E.name}" moves are`);function O(_,L){const j=[...P.under,...P.over].filter(B=>_.has(B.part.id)).flatMap(B=>B.faces.flatMap(Y=>Y.points));if(j.length===0){const B=Number.isFinite(M)?`at ${M} ms`:"after its edits";throw new Error(`${n.kind}: ${L} turned away from the viewer ${B}; aim at an anchor (${r.map(Y=>`anchor:${Y}`).join(", ")||"none"}) or box`)}const V=j.map(B=>B.x),tt=j.map(B=>B.y),J=Math.min(...V),F=Math.min(...tt);return St(A.x+J,A.y+F,Math.max(...V)-J,Math.max(...tt)-F)}},w=(x,M)=>{try{return k(x,M)}catch{return}},S={kind:"prop",prop:t,about:zs,target:t,box:St(t.x,t.y,t.width,t.height),anchor(x,M=1/0){return k(x,M)},piece(x){const M=g(x);if(M.kind!=="part")throw new Error(`${n.kind}: a piece is a part, part:ID (${o.slice(0,6).map(P=>`part:${P}`).join(", ")}…), not "${x}"`);const E=u.get(M.name);if(E)return E;const T=[M.name];for(let P=0;P<T.length;P++)for(const I of n.rig.parts)I.parent===T[P]&&!T.includes(I.id)&&T.push(I.id);const A={id:u.size+1,part:M.name,home:k(x,0)};u.set(M.name,A);for(const P of T)d.set(P,A.id);for(const P of["x","y","rotate"])f[`piece.${A.id}.${P}`]=0;return f[`piece.${A.id}.opacity`]=1,A},edit(x,M,E){if(!(x in zs.edits))throw Vi(n.kind,x,zs);const T=Array.isArray(M)?M:[M];if(T.length===0)throw new Error(`${n.kind}.edit: ${x} takes at least one anchor`);if(b.clear(),x==="move"||x==="fling"){if(T.length>1)throw new Error(`${n.kind}.edit: ${x} takes one part anchor`);const A=S.piece(T[0]);if(x==="fling")return S.fling(A,E);const P=E.to;if(!P)throw new Error(`${n.kind}.edit: move needs \`to\`, an anchor name or { x, y }`);const I=typeof P=="string"?k(P,E.at):void 0;return S.move(A,{...E,to:I?{x:I.left+I.width/2,y:I.top+I.height/2}:P})}for(const A of T){const P=g(A);if(P.kind!=="control")throw new Error(`${n.kind}.edit: ${x} takes control anchors (control:${i.join(", control:")}), not "${A}"`);const I=s[P.name];let O;if(x==="set"){if(typeof E.value!="number"||!Number.isFinite(E.value))throw new Error(`${n.kind}.edit: set needs \`value\`, a number (${P.name}: ${I.description})`);O=E.value}else O=E.on===!1?I.default??I.min??0:I.max??1;a.tween(P.name,m(E.at).values[P.name],O,E,DE)}return S},follow(x,M){return b.clear(),l.follow(x,M),S},fling(x,M){return b.clear(),l.fling(x,M),S},move(x,M){return b.clear(),l.move(x,M),S},ride(x,M,E){const T=[...i.flatMap(P=>Rs(a.keys(P))),...(e.tracks??[]).flatMap(P=>Rs(P.keyframes.filter(I=>typeof I.value=="number")))];if(T.length===0)return x;const A=[...r.map(P=>`anchor:${P}`),...o.map(P=>`part:${P}`)].flatMap(P=>{const I=w(P,0);return I?[{top:I.top,offset:O=>(w(P,O)?.top??I.top)-I.top,windows:T}]:[]});return qo(x,M,{ground:E.ground,every:E.every??fn,floors:A})},tracks:a.tracks};return S}const qE={body:"#e8574a",trim:"#3b3b44",glass:"#bfe3f2",tyre:"#2c2c33",hub:"#c9ccd3",light:"#fff4b8",tail:"#ff5a4f",inside:"#3b3640",seat:"#6d5d55"};function Xe(t){const e={...qE,...t.colors},n=[],{forwardMost:s,backMost:i,top:r}=p1(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,m]of(t.cabin.pillars??[]).entries())n.push({id:`pillar-${f}`,shape:{type:"box",size:[h+.02,d-u,.1]},at:[0,(u+d)/2,m],fill:e.body,outline:.8,layer:1})}const o=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 m of d){const g=`wheel-${u}-${m>0?"left":m<0?"right":"middle"}`;if(a.push({parts:[g],rotate:{axis:"x",degrees:o/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:[m*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 p of m===0?[1,-1]:[m])n.push({id:`${g}-hub${m===0?p>0?"-left":"-right":""}`,parent:g,shape:{type:"cylinder",radius:h.radius*.55,length:.02,axis:"x",segments:14,spokes:5},at:[p*(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,m=[[h,d],[u,d],[u,f],[h,f]];for(const g of[1,-1]){const p=g>0?"left":"right";n.push({id:`doorway-${p}`,shape:{type:"panel",points:m,facing:g>0?"left":"right"},at:[g*(t.width/2+.004),0,0],fill:e.inside,outline:.5,seeThrough:!0});const b=h+(u-h)*.15,v=h+(u-h)*.55;n.push({id:`seat-back-${p}`,shape:{type:"panel",points:[[b,d+.05],[v,d+.05],[v-.08,f-.06],[b+.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-${p}`,shape:{type:"panel",points:m.map(([k,w])=>[k-u,w]),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:m}=t.lights,g=(t.lights.size??.32)/2,p=[[-g,u],[g,u],[g,d],[-g,d]];for(const b of[1,-1])n.push({id:`headlight-${b}`,shape:{type:"panel",points:p,facing:"front"},at:[b*h,0,f],fill:e.light,outline:.6,glow:{control:"lights",color:"#ffffff"}}),n.push({id:`taillight-${b}`,shape:{type:"panel",points:p,facing:"back"},at:[b*h,0,m],fill:Lo(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:r,footprint:[t.width,s-i],anchors:{...t.seat?{seat:{at:t.seat}}:{},front:{at:[0,r*.45,s]},back:{at:[0,r*.45,i]},roof:{at:[0,r,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:jE(t),acting:y1,colors:{body:e.body,ink:"#26262b"},follow:t.antenna?[{control:"antenna",of:"x",per:.9,stiffness:140,damping:7,limit:35}]:void 0,wheelRadius:o,...t.wheels.length>0?{moves:{drive:{speed:t.speed??6,perMetre:{wheelSpin:180/(Math.PI*o)}}}}:{}}}function p1(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 y1={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 fa(t,e,n,s,i,r,o=!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,o?l:l+c/r*(180/Math.PI),i)}const b1=.4;function jE(t){const e=t.wheels[0]?.radius??.4,{forwardMost:n,backMost:s}=p1(t),i=(n-s)/2,r=(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"}),fa(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},o=(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=r(a,c,h),d=a.exaggeration,f=Math.abs(l.to-a.x),m=l.for??Math.max(500,f/(l.speed??b1));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,m-160),{pitch:0,lean:.08*d,squash:1.02},{act:!1}),fa(a,u,u+m,l.to,"ease-in-out",e),o(a,u+m,!1),{end:u+m+380,contact:u,release:u+m}}},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=r(a,c,h),d=a.exaggeration,f=a.x,m=Math.abs(l.to-f),g=l.for??Math.max(600,m/(l.speed??b1*1.2)),p=u+g*.55,b=f+(l.to-f)*.65;return a.key(u+140,{pitch:-1.5*d,squash:1+.06*d,lean:.14*d},{act:!1,easing:"ease-out"}),fa(a,u,p,b,"ease-in",e),a.key(p+80,{pitch:-7*d,lean:-.12*d,squash:.94},{act:!1,easing:"ease-out"}),fa(a,p,u+g,l.to,"ease-out",e,!0),a.effect({kind:"skid",time:p,x:b,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}),o(a,u+g,!0),{end:u+g+380,contact:p,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 w1(t={}){return Xe({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 k1(t={}){return Xe({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 v1(t={}){return Xe({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 M1(t={}){return Xe({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 S1(t={}){const e=t.colors?.body??"#a8743f";return Xe({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 T1(t={}){return Xe({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 E1(t={}){const e=t.colors?.body??"#e0473b",n=[0,.32,-.05],s=[0,.86,-.22],i=[0,.9,.42],r=[0,.34,.56],o=[0,.34,-.56];return Xe({kind:"bike",summary:"A bicycle: rides (drive) with its wire wheels turning, brakes, bumps, rings its bell (honk).",width:.5,frame:[{points:[o,n]},{points:[n,s]},{points:[s,o]},{points:[s,i]},{points:[n,i]},{points:[i,r]},{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 A1(t={}){return Xe({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 x1(t={}){const e=t.height??2.4,n=t.trunkRadius??.16,s=t.canopy?.radius??1.1,i=t.canopy?.shape==="tall",r={trunk:"#8a5a3b",leaves:"#5cae5a",...t.colors},o=Se(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:r.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:r.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:r.leaves}],l=t.canopy?.lobes??7;for(let h=0;h<l;h++){const u=Math.PI*2*h/l+o.next()*.6,d=(o.next()-.25)*s*(i?1.1:.7),f=s*(.48+o.next()*.22),m=[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:m,fill:r.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:KE(),acting:P1,colors:{body:r.leaves}}}const P1={depth:{sway:1,canopySway:2,size:0,squash:1},limits:{sway:2,canopySway:3,squash:.08},eyes:[],headTurns:{},drift:[]};function KE(){const t=(e,n,s,i)=>{const r=e.anchor("canopy");e.effect({kind:"leaves",time:n,x:r.x,y:r.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,r=n.for??3e3,o=e.exaggeration,a=260;let l=0;for(let c=a;c<r;c+=a){const h=.55+.45*Math.sin(c/r*Math.PI*2.3),u=Math.sin(c/170)*.35,d=-i*9*o*(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+r,{sway:0,canopySway:0}),i>.45)for(let c=0;c<r;c+=700)t(e,s+c,2200,1);return{end:s+r}}},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,r=e.exaggeration,o=6;for(let a=1;a<=o;a++){const l=1-a/(o+1),c=a%2===0?1:-1;e.key(s+i*a/(o+1),{sway:c*5*r*l,canopySway:-c*6*r*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 r=0;r<i;r+=500)t(e,s+r,2e3,r%1e3===0?1:-1);return{end:s+i}}}}}function $1(t={}){const e=t.width??4,n=t.depth??3.2,s=t.wallHeight??2.5,i=t.roofHeight??1.5,r=t.overhang??.25,o={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:o.walls},{id:"roof",shape:{type:"extrude",profile:[[-n/2-r,s],[n/2+r,s],[0,s+i]],width:e+r*2},fill:o.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:o.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:o.door,outline:.8,overRider:!0}];u.forEach((g,p)=>{d.push({id:`window-${p}`,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:o.glass,outline:.8,glow:{control:"lights",color:o.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:o.glass,outline:.8,glow:{control:"lights",color:o.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+r)),p=s+i+.45;d.push({id:"chimney",shape:{type:"box",size:[.42,p-g+.3,.42]},at:[f.at,(p+g-.3)/2,f.back],fill:o.chimney,layer:1})}const m={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+r*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:m,actions:YE(!!f),acting:I1,colors:{body:o.walls}}}const I1={depth:{door:1,lights:0,roll:1,squash:1,size:0},limits:{door:.1,roll:1.5,squash:.05},eyes:[],headTurns:{},drift:[]};function YE(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,r=e.exaggeration;e.key(s+80,{squash:1-.06*r},{act:!1,easing:"ease-out"});for(let o=1;o<=5;o++){const a=1-o/6;e.key(s+80+i*o/6,{roll:(o%2===0?1:-1)*2.2*r*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,r=e.anchor("chimney");return e.effect({kind:"smoke",time:s,x:r.x,y:r.y,length:i+1500,direction:(n.wind??.4)>=0?1:-1}),{end:s+50,release:s+i}}}}:{}}}function O1(t={}){const e=t.width??.46,n=t.depth??.46,s=t.seatHeight??.46,i=t.backHeight??.95,r={wood:"#8a5a3b",seat:"#c48a4a",...t.colors},o=.05,a=.025,l=[{id:"seat",shape:{type:"box",size:[e,o,n]},at:[0,s-o/2,0],fill:r.seat},{id:"back",shape:{type:"box",size:[e,i-s,o]},at:[0,(i+s)/2,-n/2+o/2],fill:r.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-o,0]],radius:a,segments:6},at:[h*(e/2-a*1.5),0,u*(n/2-a*1.5)],fill:r.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:XE(),acting:C1,colors:{body:r.seat}}}const C1={depth:{tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.05},eyes:[],headTurns:{},drift:[]};function XE(){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 _1(t={}){const e=t.width??1.4,n=t.depth??.7,s=t.height??.75,i={wood:"#8a5a3b",top:"#a9754a",knob:"#2b2b2b",...t.colors},r=.04,o=.03,a=.14,l=e*.4,c=[{id:"top",shape:{type:"box",size:[e,r,n]},at:[0,s-r/2,0],fill:i.top},{id:"drawer",shape:{type:"box",size:[l,a,n*.8]},at:[-e/2+l/2+.05,s-r-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-r,0]],radius:o,segments:6},at:[u*(e/2-o*2),0,d*(n/2-o*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:R1,colors:{body:i.top}}}const R1={depth:{drawer:1,roll:1,squash:1,size:0},limits:{drawer:.08,roll:1,squash:.04},eyes:[],headTurns:{},drift:[]};function H1(t={}){const e=t.length??2,n=t.width??1,s=t.height??.55,i=t.headboard??.95,r={wood:"#8a5a3b",mattress:"#f1ece2",blanket:"#5b7fb0",pillow:"#fbf8f2",...t.colors},o=.3,a=s-o,c={parts:[{id:"frame",shape:{type:"box",size:[n,o,e]},at:[0,o/2,0],fill:r.wood},{id:"headboard",shape:{type:"box",size:[n+.06,i-o,.06]},at:[0,(i+o)/2,-e/2-.03],fill:r.wood},{id:"mattress",shape:{type:"box",size:[n-.04,a,e-.04]},at:[0,o+a/2,0],fill:r.mattress},{id:"blanket",parent:"mattress",shape:{type:"box",size:[n-.02,.04,e*.62]},at:[0,a/2+.02,e*.19],fill:r.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:r.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,m=h.exaggeration;return h.key(d+90,{give:1-.18*m},{act:!1,easing:"ease-out"}),h.key(d+f*.45,{give:1+.05*m},{act:!1,easing:"ease-in-out"}),h.key(d+f*.7,{give:1-.04*m},{act:!1,easing:"ease-in-out"}),h.key(d+f,{give:1}),{end:d+f,contact:d+90}}}},acting:F1,colors:{body:r.blanket}}}const F1={depth:{give:1,roll:1,squash:1,size:0},limits:{give:.03,roll:.5,squash:.03},eyes:[],headTurns:{},drift:[]};function L1(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},r=.1,o=s==="left"?1:-1,a=o>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:[r,n+r,r]},at:[e/2+r/2,(n+r)/2,0],fill:i.frame},{id:"post-right",shape:{type:"box",size:[r,n+r,r]},at:[-e/2-r/2,(n+r)/2,0],fill:i.frame},{id:"lintel",shape:{type:"box",size:[e+r*2,r,r]},at:[0,n+r/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:[o*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:[-o*(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:o*-95}}]}},length:.3,height:n+r,footprint:[e+r*2,.3],anchors:{handle:{part:"door",at:[-o*(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:GE(),acting:N1,colors:{body:i.door}}}const N1={depth:{open:1,roll:1,squash:1,size:0},limits:{open:.08,roll:.6,squash:.03},eyes:[],headTurns:{},drift:[]};function GE(){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,r=t.exaggeration;for(let o=0;o<3;o++){const a=n+i*(o+.5)/3;t.key(a,{open:.03*r},{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 W1=1.4;function D1(t={}){const e=t.width??.5,n=t.seatHeight??.5,s=t.wheelRadius??.3,i=.08,r={frame:"#2b2f36",seat:"#3c6ea5",tyre:"#1f2328",...t.colors},o=.04,a=.018,l=.44,c=n+.5,h=-.08,u=e/2+.06,d=[{id:"seat",shape:{type:"box",size:[e,o,l]},at:[0,n-o/2,0],fill:r.seat},{id:"back",shape:{type:"box",size:[e,c-n-.02,o]},at:[0,(c+n)/2,-l/2+o/2],fill:r.seat},{id:"footrest",shape:{type:"box",size:[e*.8,.02,.14]},at:[0,.12,l/2+.22],fill:r.frame}];for(const[g,p]of[[-1,"left"],[1,"right"]]){const b=g*u,v=(k,w,S=a)=>{d.push({id:k,shape:{type:"tube",points:w,radius:S,segments:6},fill:r.frame,outline:.7})};v(`post-${p}`,[[b,n-.1,-l/2],[b,c+.04,-l/2],[b,c+.04,-l/2-.14]]),v(`rail-${p}`,[[b,n-.03,-l/2],[b,n-.03,l/2]]),v(`leg-${p}`,[[b,n-.03,l/2],[b*.85,i,l/2+.06]]),v(`strut-${p}`,[[b*.85,i+.08,l/2+.04],[b*.8,.13,l/2+.22]]),v(`armrest-${p}`,[[b,n+.22,-l/2+.02],[b,n+.22,l/2-.08]],a*1.3),d.push({id:`wheel-${p}`,shape:{type:"cylinder",radius:s,length:.04,axis:"x",segments:20,spokes:8},at:[b+g*.03,s,h],ink:r.tyre,outline:1.3}),d.push({id:`rim-${p}`,shape:{type:"cylinder",radius:s*.9,length:.012,axis:"x",segments:20},at:[g*.045,0,0],parent:`wheel-${p}`,ink:r.frame,outline:.8}),d.push({id:`castor-${p}`,shape:{type:"cylinder",radius:i,length:.03,axis:"x",segments:12,spokes:3},at:[b*.85,i,l/2+.06],fill:r.tyre})}const f=d.map(g=>g.id).filter(g=>!g.startsWith("rim-")),m={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:m,actions:UE(s),acting:B1,colors:{body:r.seat,ink:r.frame},wheelRadius:s,moves:{roll:{speed:W1,perMetre:{wheelSpin:180/(Math.PI*s)}}}}}const B1={depth:{wheelSpin:0,tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.03},eyes:[],headTurns:{},drift:[]};function z1(t,e,n,s,i,r,o=!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,o?l:l+c/r*(180/Math.PI),i)}function UE(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 r=s;e.facing()!==i&&(r=e.turnTo(r,i>0?"right":"left"));const o=Math.abs(n.to-e.x),a=n.for??Math.max(300,o/(n.speed??W1*e.scale/1e3));return e.key(r+150,{tip:1.5*e.exaggeration},{act:!1,easing:"ease-out"}),z1(e,r,r+a,n.to,"ease-in-out",t),e.key(r+a,{tip:0},{easing:"ease-out"}),{end:r+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 r=n.for??500;return z1(e,s,s+r,n.to,"ease-out",t,!0),e.key(s+r,{tip:0},{easing:"ease-out"}),e.effect({kind:"dust",time:s+r*.5,x:n.to,y:e.floor,length:500}),{end:s+r,contact:s+r}}},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,r=n.for??1200;return e.key(s+300,{tip:i},{easing:"ease-out"}),e.key(s+300+r*.5,{tip:i*.9},{act:!1,easing:"ease-in-out"}),e.key(s+300+r,{tip:i},{act:!1,easing:"ease-in-out"}),e.key(s+300+r+250,{tip:0},{easing:"ease-in"}),e.effect({kind:"dust",time:s+300+r+250,x:e.x,y:e.floor,length:400}),{end:s+300+r+250,contact:s+300+r+250}}}}}function q1(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:VE(),acting:i0,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:15,flies:!0,hold:{blur:1},perSecond:{rotor:bn*1e3}}}}}const i0={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:[]},bn=2.6;function VE(){const t=(n,s,i,r,o)=>{const a=n.values.rotor??0;n.set("rotor",s,a);const l=o?r*(i-s)*.5:r*(i-s);n.set("rotor",i,a+l,o)},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 r=n.exaggeration,o=s.height??3;t(n,i,i+900,bn,"ease-in"),n.key(i+900,{blur:1},{act:!1,easing:"ease-in"}),n.key(i+700,{squash:1-.08*r},{act:!1,easing:"ease-in"});const a=i+1e3;return n.key(a+150,{squash:1+.06*r,lift:.3},{act:!1,easing:"ease-out"}),n.key(a+1300,{squash:1,lift:o,pitch:-4*r},{act:!1,easing:"ease-in-out"}),n.key(a+1700,{pitch:0}),t(n,i+900,a+1700,bn),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 r=n.exaggeration,o=Math.sign(s.to-n.x);let a=i;o!==0&&n.facing()!==o&&(a=n.turnTo(a,o>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*r,roll:6*r},{act:!1,easing:"ease-out"}),n.key(a+c-250,{pitch:-4*r,roll:3*r,lift:h},{act:!1}),n.key(a+c,{pitch:7*r,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,bn),{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 r=s.for??2e3,o=n.values.lift,a=n.exaggeration;for(let l=350,c=0;l<r;l+=350,c++)n.key(i+l,{lift:o+(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+r,{lift:o,roll:0},{act:!1,easing:"ease-in-out"}),(e(n)||o>0)&&t(n,i,i+r,bn),{end:i+r}}},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 r=n.exaggeration,o=i+Math.max(900,n.values.lift*450);return n.key(i+400,{pitch:3*r},{act:!1,easing:"ease-out"}),n.key(o,{lift:0,pitch:0,squash:1-.14*r},{act:!1,easing:"ease-in"}),n.key(o+280,{squash:1}),t(n,i,o,bn),t(n,o,o+1600,bn,"ease-out"),n.key(o+1600,{blur:0},{act:!1,easing:"ease-out"}),n.effect({kind:"dust",time:o,x:n.x,y:n.floor,length:800}),{end:o+1600,contact:o}}}}}function j1(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:ZE(),acting:i0,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:30,flies:!0,hold:{blur:1},perSecond:{rotor:bn*1e3}}}}}const JE=3.2;function ZE(){const t=(n,s,i,r)=>{const o=n.values.rotor??0;n.set("rotor",s,o),n.set("rotor",i,o+JE*(i-s)*(r?.5:1),r)},e=(n,s,i)=>{const r=Math.sign(i-n.x);return r!==0&&n.facing()!==r?n.turnTo(s,r>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 r=n.exaggeration,o=e(n,i,s.to);t(n,o,o+700,"ease-in"),n.key(o+700,{blur:1},{act:!1,easing:"ease-in"});const a=s.for??2600,l=n.x,c=o+700+a*.55,h=l+(s.to-l)*.45;return n.move(o+700,c,h,{easing:"ease-in"}),n.key(c,{pitch:8*r,squash:1+.04*r},{act:!1,easing:"ease-out"}),n.key(o+700+a,{lift:s.height??4,pitch:10*r,squash:1},{act:!1,easing:"ease-in-out"}),n.move(c,o+700+a,s.to),n.key(o+700+a+500,{pitch:0}),t(n,o+700,o+700+a+500),n.effect({kind:"dust",time:c,x:h,y:n.floor,length:700}),{end:o+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 r=n.exaggeration,o=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(o+350,{roll:10*r,pitch:l>n.values.lift?6*r:-3*r},{act:!1,easing:"ease-out"}),n.key(o+a-300,{roll:4*r,lift:l},{act:!1}),n.key(o+a,{roll:0,pitch:0}),n.move(o,o+a,s.to,{easing:"ease-in-out"}),t(n,i,o+a),{end:o+a,contact:o,release:o+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 r=s.for??2400,o=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,m=i+r*d/l;n.key(m,{lift:h+o*(1-Math.cos(f)),pitch:u+360*d/l},{act:!1}),n.move(i+r*(d-1)/l,m,c+a*(o*Math.sin(f)+d/l*o*1.2)*n.scale)}return n.key(i+r+1,{pitch:u},{act:!1}),t(n,i,i+r),{end:i+r+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 r=n.exaggeration,o=e(n,i,s.to),a=n.x,l=s.for??2200,c=o+l,h=a+(s.to-a)*.7;return n.key(o+l*.4,{pitch:-4*r},{act:!1,easing:"ease-out"}),n.key(c-250,{pitch:6*r,lift:.15},{act:!1,easing:"ease-in-out"}),n.key(c,{lift:0,pitch:0,squash:1-.12*r},{act:!1,easing:"ease-in"}),n.key(c+260,{squash:1}),n.move(o,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 qs=["walk","trot","canter","gallop"],QE=qs,K1=["fl","fr","hl","hr"],ga={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}},wn=Math.PI/180;function ma(t,e){return 4*t*Math.sin(ga[e].swing*wn)}function kn(t){const{legs:e,colors:n}=t,s=e.upper+e.lower+e.foot,i=s+t.body.rise,r=(u,d)=>[d*u[0],u[1],u[2]],o=[{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},...eA(t,n,i)];t.mane&&o.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&&o.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?r(t.ears.rotate,1).map((m,g)=>g===2?u*m:m):void 0;o.push({id:`ear-${d}`,parent:"head",shape:{type:"ellipsoid",radii:t.ears.radii,segments:8},at:r(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:r(t.eyes.at,u),fill:"#1d1d22",outline:.4})}o.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=>`${qs.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:$e,rotate:{axis:"x",degrees:1/$e.length}}]},wag:{description:"Tail swung side to side, curling",unit:"degrees",bind:[{parts:$e,rotate:{axis:"y",degrees:1/$e.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 K1){const d=u[0]==="f",f=u[1]==="l"?1:-1,m=d?e.thickness[0]:e.thickness[1];o.push({id:`${u}-upper`,shape:{type:"tube",points:[[0,e.upper*.2,0],[0,-e.upper*.5,0],[0,-e.upper,0]],radius:[m,m*.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:o,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=>nA(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:{...iA(t,h),...t.actions?.(h)},acting:o0,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:tA(t,s)}}function tA(t,e){const n=i=>{const r=ma(e,i);return{speed:r/(ga[i].cycle*(t.cycleScale??1)/1e3),set:{gait:qs.indexOf(i)},hold:{walking:1},perMetre:{walk:1/r}}},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 $e=Array.from({length:7},(t,e)=>e===0?"tail":`tail-${e}`);function eA(t,e,n){const s=lh(t.tail.points,$e.length+1),[,i,r]=t.body.radii,o=(t.tail.at[1]-n)/i,a=Math.abs(o)<1?-r*Math.sqrt(1-o*o):t.tail.at[2],l=[t.tail.at[0],t.tail.at[1],a+Math.min(.04,r*.08)],c=f=>t.tail.radius*(1-.5*f/$e.length),h=$e.map((f,m)=>{const g=s[m],p=s[m+1],b=[p[0]-g[0],p[1]-g[1],p[2]-g[2]],v=m===0?void 0:s[m-1];return{id:f,...m>0?{parent:$e[m-1]}:{},shape:{type:"tube",points:[[0,0,0],b],radius:[c(m),c(m+1)],segments:8,joined:!0},at:m===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:$e[$e.length-1],shape:{type:"ellipsoid",radii:Array(3).fill(c($e.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 nA(t,e,n){const s=Math.max(0,Math.min(1,t.walking??0));if(s===0)return{};const i=qs[Math.max(0,Math.min(3,Math.round(t.gait??0)))],r=ga[e.gaits.includes(i)?i:e.gaits[0]],o=t.walk??0,a={};for(const c of K1){const h=Math.PI*2*(o+r.offsets[c]);a[`${c}.swing`]=(t[`${c}.swing`]??0)+s*r.swing*Math.sin(h),a[`${c}.knee`]=(t[`${c}.knee`]??0)+s*r.lift*Math.max(0,Math.cos(h))}const l=Math.PI*2*o;return a.lift=(t.lift??0)+s*r.bob*n*Math.abs(Math.sin(l*2)),a.pitch=(t.pitch??0)+s*r.rock*Math.sin(l),a.neck=(t.neck??0)+s*(r.rock>0?-r.rock*1.4:5)*Math.sin(l*2),a}function r0(t){const n=Math.sin(32*wn),s=t.legLength-(t.front-t.hind)*n,i=72,o=(s-t.upper*Math.cos(i*wn)-t.foot)/t.lower,a=o>=1?0:o<=-1?180:Math.acos(o)/wn,l={pitch:32,lift:t.legLength*(1-Math.cos(32*wn))-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 o0={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:[]},sA=o0;function Y1(t){const e=(t.upper+t.lower)*.32,n=Math.asin(Math.min(1,e/(t.upper+t.lower+t.foot)))/wn,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 iA(t,e){const n=t.cycleScale??1,s=o=>({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."}[o],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 m=Math.abs(l.to-a.x)/a.scale/ma(e.legLength,o),g=l.for??Math.max(500,m*ga[o].cycle*n),p=a.values.walk??0;return a.set("gait",u,a.values.gait??0),a.set("gait",u+1,qs.indexOf(o)),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,p),a.move(u,u+g,l.to,{easing:"ease-in-out"}),a.set("walk",u+g,p+m,"ease-in-out"),a.key(u+g+300,{neck:0}),(o==="gallop"||o==="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(o=>[o==="gallop"&&!t.gaits.includes("canter")?"run":o,s(o)]));t.gaits.includes("gallop")&&!i.gallop&&(i.gallop=s("gallop"));const r={...i,[t.call]:{summary:`Throws its head up and ${t.call}s.`,run(o,a,l){const c=o.exaggeration;return o.key(l+150,{neck:10*c},{act:!1,easing:"ease-out"}),o.key(l+380,{neck:-28*c,squash:1.05},{act:!1,easing:"ease-out"}),o.key(l+680,{neck:-20*c},{act:!1}),o.key(l+980,{neck:0,squash:1}),e.call(o,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(o,a,l){const c=r0(e),h=l+450;o.key(h,c,{act:!1,easing:"ease-in-out"}),o.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 o.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(o,a,l){const c=Y1(e),h={...r0(e)},u=l+400,d=u+450;o.key(u,h,{act:!1,easing:"ease-in-out"}),o.key(d,c,{act:!1,easing:"ease-in-out"}),o.key(d+(a.for??2e3),c,{act:!1});const f=d+(a.for??2e3)+600,m={};for(const g of new Set([...Object.keys(c),...Object.keys(h)]))m[g]=0;return o.key(f,m),{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(o,a,l){const c=o.exaggeration,h=e.legLength*.8*c,u=l+260,d=u+90,f=d+520;if(o.key(u,{squash:.86,"hl.knee":40,"hr.knee":40,"fl.knee":25,"fr.knee":25,neck:8},{act:!1,easing:"ease-out"}),o.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"}),o.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"}),o.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"}),o.key(f+280,{squash:1,pitch:0,neck:0}),a.to!==void 0){const m=Math.sign(a.to-o.x);m!==0&&o.facing()!==m&&o.turnTo(l,m>0?"right":"left"),o.move(d,f,a.to)}return o.effect({kind:"dust",time:f,x:o.x,y:o.floor,length:550}),{end:f+280,contact:f}}},nod:{summary:"Nods its head twice.",run(o,a,l){return o.key(l+200,{neck:20},{act:!1,easing:"ease-out"}),o.key(l+400,{neck:-5},{act:!1,easing:"ease-in-out"}),o.key(l+600,{neck:18},{act:!1,easing:"ease-in-out"}),o.key(l+900,{neck:0}),{end:l+900}}},swish:{summary:"Swishes its tail a few times.",uses:["for"],run(o,a,l){const c=a.for??900;for(let h=1;h<=4;h++)o.key(l+c*h/5,{tail:h%2===0?10:35},{act:!1,easing:"ease-in-out"});return o.key(l+c,{tail:0}),{end:l+c}}}};return t.grazes&&(r.graze={summary:"Lowers its head to graze for `for` ms (default 1800), nibbling, then looks up.",uses:["for"],run(o,a,l){const c=a.for??1800;o.key(l+600,{neck:75},{act:!1,easing:"ease-in-out"});for(let h=900;h<600+c;h+=400)o.key(l+h,{neck:h%800===100?70:78},{act:!1,easing:"ease-in-out"});return o.key(l+600+c+500,{neck:0}),{end:l+600+c+500}}}),r}function X1(t={}){return kn({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 r=n.exaggeration,o=Math.min(55,32*r),a=-e.hind*Math.sin(o*wn),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:o,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 r=n.exaggeration,o=Math.min(35,18*r),a=e.front*Math.sin(o*wn);return n.key(i+220,{pitch:3,squash:.95},{act:!1,easing:"ease-out"}),n.key(i+480,{pitch:-o,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 G1(t={}){return kn({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 r=80,o=0;r<i;r+=80,o++)e.key(s+r,{wag:o%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 r=500,o=0;r<i;r+=140,o++)e.key(s+r,{neck:o%2===0?74:66},{act:!1});return e.key(s+i+300,{neck:0,pitch:0}),{end:s+i+300}}}})})}function U1(t={}){return kn({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 r=n.exaggeration,o=s.for??1200,a={squash:1+.25*r,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+o,a,{act:!1}),n.key(i+o+520,{squash:1,neck:0,tail:0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0}),{end:i+o+520,contact:i+180}}},pounce:{summary:"Crouches low, wiggles, and pounces to `to`, landing with a squash.",needs:["to"],run(n,s,i){const r=n.exaggeration,o=Math.sign(s.to-n.x);let a=i;o!==0&&n.facing()!==o&&(a=n.turnTo(a,o>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*r,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 V1(t={}){return kn({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 rA(t){return ma(1,t)}function J1(t={}){return kn({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 Z1(t={}){return kn({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 Q1(t={}){return kn({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 vn=.6,tb=75,a0=80;function Mn(t){const{colors:e}=t,[n,s,i]=t.body.radii,r=(t.tail.raised??15)*Math.PI/180,o=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]+o*Math.sin(r),t.tail.at[2]-o*Math.cos(r)],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*vn/2,t.wing.chord*.1,t.wing.chord/2],segments:12},at:[h*t.wing.span*vn/2,0,-t.wing.chord*.1],rotate:[-a0,0,0],fill:e.wing,outline:.8}),a.push({id:`wing-${u}-tip`,parent:`wing-${u}-blade`,shape:{type:"ellipsoid",radii:[t.wing.span*vn/2.4,t.wing.chord*.06,t.wing.chord*.3],segments:10},at:[h*t.wing.span*vn/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-vn)/2,0,0],rotate:{axis:"x",degrees:a0},scale:[1/vn,1,1]},{parts:["wing-right-blade"],translate:[-t.wing.span*(1-vn)/2,0,0],rotate:{axis:"x",degrees:a0},scale:[1/vn,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)/tb,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 m=Math.sin(Math.PI*2*(h.step??0));u["leg.left"]=(h["leg.left"]??0)+f*28*m,u["leg.right"]=(h["leg.right"]??0)-f*28*m,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:aA(t),acting:eb,colors:{body:e.body,ink:"#26262b"},moves:oA(t)}}function oA(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 eb={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 aA(t){const e=(t.beatsPerSecond??4)/1e3,n=(o,a,l)=>{const c=o.values.wingbeat??0;o.set("wingbeat",a,c),o.set("wingbeat",l,c+(l-a)*e)},s=(o,a,l)=>{const c=Math.sign(l-o.x);return c!==0&&o.facing()!==c?o.turnTo(a,c>0?"right":"left"):a},i=(o,a)=>{const l=o.anchor("beak");o.effect({kind:"honk",time:a,x:l.x,y:l.y,length:600,direction:o.facing()||1})},r={hop:{summary:"Hops to `to` in little bounces, wings twitching.",needs:["to"],run(o,a,l){const c=s(o,l,a.to),h=o.x,u=Math.abs(a.to-h),d=Math.max(1,Math.round(u/(t.body.radii[2]*3*o.scale))),f=260;for(let m=0;m<d;m++){const g=c+m*f;o.key(g+60,{squash:.85},{act:!1,easing:"ease-out"}),o.key(g+150,{squash:1.1,lift:t.legs.length*1.4,spread:.15},{act:!1,easing:"ease-out"}),o.key(g+f,{squash:.9,lift:0,spread:0},{act:!1,easing:"ease-in"}),o.move(g+60,g+f,h+(a.to-h)*(m+1)/d,{easing:"ease-in-out"})}return o.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(o,a,l){const c=s(o,l,a.to),h=Math.abs(a.to-o.x)/o.scale,u=t.legs.length*1.2,d=h/u,f=a.for??Math.max(400,d*420),m=o.values.step??0;return o.set("stepping",c,0),o.set("stepping",c+150,1,"ease-out"),o.set("stepping",c+f-150,1),o.set("stepping",c+f,0,"ease-in"),o.set("step",c,m),o.move(c,c+f,a.to,{easing:"ease-in-out"}),o.set("step",c+f,m+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(o,a,l){const c=a.for??900,h=Math.max(1,Math.round(c/300));o.key(l+120,{pitch:-(t.stoop??12)},{act:!1,easing:"ease-out"});for(let u=0;u<h;u++)o.key(l+120+u*300+90,{peck:tb},{act:!1,easing:"ease-in"}),o.key(l+120+u*300+260,{peck:20},{act:!1,easing:"ease-out"});return o.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(o,a,l){const c=a.for??900;return o.key(l+120,{spread:1},{act:!1,easing:"ease-out"}),o.set("flapping",l,0),o.set("flapping",l+150,1,"ease-out"),o.set("flapping",l+c-150,1),o.set("flapping",l+c,0,"ease-in"),n(o,l,l+c),o.key(l+c*.5,{lift:t.legs.length*.6},{act:!1,easing:"ease-out"}),o.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(o,a,l){return o.key(l+120,{peck:-25,squash:1.06},{act:!1,easing:"ease-out"}),o.key(l+500,{peck:-20},{act:!1}),o.key(l+760,{peck:0,squash:1}),i(o,l+150),{end:l+760,contact:l+150}}}};return t.flies!==!1?(r.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(o,a,l){const c=o.exaggeration;o.key(l+60,{grip:0},{act:!1});const h=s(o,l,a.to),u=a.height??2,d=a.for??Math.max(700,Math.abs(a.to-o.x)/.35),f=o.values.lift>t.legs.length,m=f?h:h+200;return f||(o.key(h+160,{squash:1-.18*c,spread:.6},{act:!1,easing:"ease-out"}),o.effect({kind:"dust",time:m,x:o.x,y:o.floor,length:400})),o.key(m+100,{spread:1,squash:1.08,pitch:10},{act:!1,easing:"ease-out"}),o.set("flapping",m,o.values.flapping??0),o.set("flapping",m+100,1,"ease-out"),o.set("flapping",m+d,.6),n(o,m,m+d),o.key(m+d*.4,{lift:u,pitch:-5,squash:1},{act:!1,easing:"ease-out"}),o.key(m+d,{lift:u,pitch:0},{act:!1,easing:"ease-in-out"}),o.move(m,m+d,a.to,{easing:"ease-in-out"}),{end:m+d,contact:m,release:m+d}}},r.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(o,a,l){let c=l;if(o.values.lift<=t.legs.length){const f=o.x+(a.to-o.x)/3;c=r.fly.run(o,{do:"fly",to:f,height:(a.height??1.5)*1.3},l).end}c=s(o,c,a.to);const h=o.values.lift,u=a.height??h*.67,d=a.for??Math.max(900,Math.abs(a.to-o.x)/.3);return o.set("flapping",c,o.values.flapping??1),o.set("flapping",c+250,0,"ease-out"),n(o,c,c+250),o.key(c+300,{spread:1,flap:10,pitch:-6},{act:!1,easing:"ease-out"}),o.key(c+d,{lift:u,pitch:-3,flap:10},{act:!1,easing:"ease-in-out"}),o.move(c,c+d,a.to,{easing:"ease-in-out"}),{end:c+d,contact:c,release:c+d}}},r.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(o,a,l){const h=a.height??0;return o.set("flapping",l,o.values.flapping??1),o.set("flapping",l+700-120,1),o.set("flapping",l+700,0,"ease-in"),n(o,l,l+700),o.key(l+700*.6,{pitch:14},{act:!1,easing:"ease-out"}),o.key(l+700,{lift:h,pitch:0,squash:.85,grip:h>0?1:0},{act:!1,easing:"ease-in"}),a.to!==void 0&&o.move(l,l+700,a.to,{easing:"ease-out"}),o.key(l+700+160,{squash:1,spread:0,flap:0}),{end:l+700+200,contact:l+700}}}):r.flutter={summary:"Flutters up a little way and back down, wings beating hard (a chicken’s flight).",run(o,a,l){return o.key(l+100,{spread:1,squash:.9},{act:!1,easing:"ease-out"}),o.set("flapping",l+80,0),o.set("flapping",l+160,1,"ease-out"),o.set("flapping",l+900-100,1),o.set("flapping",l+900,0,"ease-in"),n(o,l+80,l+900),o.key(l+900*.5,{lift:t.legs.length*2.5,squash:1.08},{act:!1,easing:"ease-out"}),o.key(l+900,{lift:0,squash:.85,spread:0},{act:!1,easing:"ease-in"}),o.key(l+900+160,{squash:1}),{end:l+900+160,contact:l+900}}},r}function nb(t={}){return Mn({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 sb(t={}){return Mn({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 ib(t={}){return Mn({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 rb(t={}){return Mn({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 ob(t={}){return Mn({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 ab(t={}){return Mn({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 lb(t={}){return Mn({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 js={car:w1,truck:k1,bus:v1,tractor:M1,cart:S1,trainCar:T1,bike:E1,motorbike:A1,tree:x1,house:$1,chair:O1,desk:_1,bed:H1,door:L1,wheelchair:D1,helicopter:q1,airplane:j1,horse:X1,dog:G1,cat:U1,cow:V1,goat:J1,rabbit:Z1,squirrel:Q1,songbird:nb,crow:sb,chicken:ib,pigeon:rb,duck:ob,owl:ab,parrot:lb};function l0(t,e={}){const n=js[t];if(!n)throw new Error(dt("prop preset",t,Object.keys(js)));return n(e)}const pa=["do","at","for","to","toward","speed","open","on","height","wind"],c0={viewer:0,right:1,away:2,left:3},lA=420,h0={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 ya(t){return{...h0,...t.actions}}const u0=t=>typeof t=="number"&&Number.isFinite(t);function cb(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=ya(e),s=Object.keys(n),i=[];return t.forEach((r,o)=>{const a=c=>i.push({level:"error",beat:o,message:c});if(!r||typeof r!="object"||Array.isArray(r))return a(`Each beat must be an object like { do: '${s[s.length-1]}' }.`);const l=r;for(const c of Object.keys(l))pa.includes(c)||a(dt("beat field",c,pa,c==="duration"?"for":c==="direction"?"toward":void 0));if(typeof l.do!="string"||!s.includes(l.do))return a(dt(`${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&&!(u0(l[c])&&l[c]>=0)&&a(`\`${c}\` must be a number ≥ 0 (got ${JSON.stringify(l[c])}).`);if(l.to!==void 0&&!u0(l.to)&&a(`\`to\` is a scene x in px (got ${JSON.stringify(l.to)}).`),l.toward!==void 0&&!u0(l.toward)&&!(typeof l.toward=="string"&&l.toward in c0)){const c=typeof l.toward=="string"?ai(l.toward,Object.keys(c0)):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 hb(t,e,n,s={}){const i=cb(n,e).filter(T=>T.level==="error");if(i.length>0)throw new Error(`propScript (${e.kind}): ${i.length} problem(s) in the beats:
|
|
60
|
+
`)}`);const r=n.map(d=>Fy(d,e)),o=ta(t,r,s),a=Y4(r,o.beats,s),l=s.ground??0,c=d=>s.ride===!1?d:Object.values(e).reduce((f,m)=>m.ride(f,t,{ground:l}),d);n.forEach((d,f)=>{for(const m of j4(d)){const g=k=>new Error(`surfaceScript: beat ${f} (${d.do}), ${m.edit} on ${m.surface}: ${k}`),p=(k,S)=>{const x=typeof k=="object"?k.beat:f,M=(typeof k=="object"?k.at:k)??S??"start",E=a[x][M];if(E===void 0){const T=Ns.filter(A=>a[x][A]!==void 0).join(", ");throw g(`beat ${x} (${n[x].do}) has no ${M} (it has ${T})`)}return E},y=e[m.surface],v=p(m.at??(a[f].contact!==void 0?"contact":"start")),w=m.until===void 0?void 0:p(m.until,"end");if(w!==void 0&&w<v)throw g(`it ends (${w} ms) before it starts (${v} ms)`);try{if(m.edit==="carry"){const S=y.piece(m.anchor),x=jh(t,c(o.tracks),{x:s.from??0,y:l,style:s.figureStyle??(s.height?{height:s.height}:void 0),cast:s,start:v,end:w});y.follow(S,x);continue}const k=Object.fromEntries(Object.entries(m).filter(([S])=>!z4.includes(S)));y.edit(m.edit,m.anchor,{...k,at:v,...w!==void 0?{duration:w-v}:{}})}catch(k){throw g(k.message)}}});const h=c(o.tracks),u=Object.entries(e).flatMap(([d,f])=>f.tracks(d));return{...o,tracks:[...h,...u],figureTracks:h}}function Hy(t,e,n={}){if(!Array.isArray(t))return ir(t,n);const s=[],i=Object.keys(e),r=(c,h,u)=>{const d=typeof h=="string"?e[h]:void 0;return d||s.push({level:"error",beat:c,message:`${u}: ${dt("surface",h,i)}`}),d},o=(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 (${Ns.join(", ")}), not at ms; set the beat's own \`at\` to move it.`}):(typeof d!="string"||!Ns.includes(d))&&s.push({level:"error",beat:c,message:`${u}: ${dt("moment",d,Ns)}`})};t.forEach((c,h)=>{if(!c||typeof c!="object"||Array.isArray(c))return;const u=c;for(const f of["target","to","onto"]){if(!ea(u[f]))continue;const m=u[f],g=r(h,m.surface,`\`${f}\``);g&&o(h,g,m.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 m=f,g=r(h,m.surface,"`then`");if(!g)return;const p=`\`then\` (${String(m.edit)} on ${String(m.surface)})`,y=[...Object.keys(g.about.edits),...q4];if(typeof m.edit!="string"||!y.includes(m.edit)){s.push({level:"error",beat:h,message:`\`then\`: ${dt("edit",m.edit,y)}`});return}for(const v of Array.isArray(m.anchor)?m.anchor:[m.anchor])o(h,g,v,p);m.edit==="carry"&&typeof m.anchor!="string"&&s.push({level:"error",beat:h,message:`${p}: \`carry\` takes one anchor, the piece it carries.`}),m.edit==="carry"&&m.until===void 0&&s.push({level:"error",beat:h,message:`${p}: \`carry\` needs \`until\` (when it lets go, such as { beat: ${h+1}, at: 'release' }).`}),m.at!==void 0&&a(h,m.at,`${p} \`at\``),m.until!==void 0&&a(h,m.until,`${p} \`until\``),m.until!==void 0&&m.duration!==void 0&&s.push({level:"error",beat:h,message:`${p}: give \`until\` or \`duration\`, not both.`})})});const l=t.map(c=>c&&typeof c=="object"&&!Array.isArray(c)?Fy(c,e,!0):c);return[...ir(l,n),...s]}function Fy(t,e,n=!1){const{then:s,...i}=t,r=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}},o={...i};return ea(t.target)&&(o.target=r(t.target)),ea(t.to)&&(o.to=r(t.to).x),ea(t.onto)&&(o.onto=r(t.onto).top),o}function Y4(t,e,n){let s=0;return t.map(i=>{const r=Zo([i],n.actions).length,o=e.slice(s,s+r);s+=r;const a=o.find(c=>c.contact!==void 0)?.contact,l=[...o].reverse().find(c=>c.release!==void 0)?.release;return{start:o[0]?.start,end:o[o.length-1]?.end,...a!==void 0?{contact:a}:{},...l!==void 0?{release:l}:{}}})}function X4(t){const e={actions:t.actions,gaits:t.gaits},n=_h(e);if(n.length>0)throw new Error(`persona "${t.name}": ${n.join(" ")}`);const s=[...Object.keys(Gt),...Object.keys(t.gaits??{})],i=t.gait??"walk";if(!s.includes(i))throw new Error(`persona "${t.name}": ${dt("gait",i,s)}`);if(t.mood&&!(t.mood in Mt))throw new Error(`persona "${t.name}": ${dt("mood",t.mood,Object.keys(Mt))}`);const r=t.acting??"snappy";if(typeof r=="string"&&!(r in Xn))throw new Error(`persona "${t.name}": ${dt("acting style",r,Object.keys(Xn))}`);if(typeof t.stance=="string"&&!(t.stance in he))throw new Error(`persona "${t.name}": ${dt("stance",t.stance,Object.keys(he))}`);const o=t.height??120,a=typeof t.stance=="string"?he[t.stance]:Bt(t.stance??{}),l=t.mood?an(a,t.mood):a,c={...t.look,height:o},h=t.summary??`${t.name}, a stick figure`;return{name:t.name,summary:h,cast:e,rest:l,height:o,figure:u=>Zl({x:u.x,y:u.y,pose:l,style:{...c,...u.facing?{facing:u.facing}:{}},cast:e}),script:(u,d,f={})=>ta(u,d,{...e,from:f.from,ground:f.ground,facing:f.facing,height:o,style:r,gait:i,start:l,rest:l,energy:t.energy}),check:u=>ir(u,e),handPath:(u,d,f)=>jh(u,d,{...f,style:c,cast:e}),describe:()=>({name:t.name,summary:h,habits:{height:o,acting:typeof r=="string"?r:"custom",gait:i,...t.mood?{mood:t.mood}:{},stance:typeof t.stance=="string"?t.stance:t.stance?"custom":"rest"},actions:Rh(e),own:{actions:Object.keys(t.actions??{}),gaits:Object.keys(t.gaits??{})}})}}const G4=new Set(["x","y","walking","gait"]),Ly=.215+.205;function Ny(t,e,n=1){const{points:s}=ke(t,lt),i=s["hip.left"],r=s["knee.left"],o=s["ankle.left"],a=i&&r&&o?Math.hypot(r.x-i.x,r.y-i.y)+Math.hypot(o.x-r.x,o.y-r.y):Ly*t.height;return Mo(e,a/Ly,n)}function U4(t,e,n,s={}){const i=ta(t,n,{...s,height:e.height,reach:s.reach??Wy(e)}),r=i.tracks.find(y=>y.property==="facing")?.keyframes??[],o=y=>{let v=s.facing??1;for(const w of r)w.time<=y&&(v=w.value);return v},a=Vr(i.keys),l=i.keys.map((y,v)=>{const w=rp(a[v]);return{time:y.time,pose:o(y.time)<0?eg(w):w,...y.easing?{easing:y.easing}:{},...y.act===!1?{act:!1}:{}}}),{rest:c,start:h,...u}=s;Z4(l,a,n,i,e,o,s);const d=gy(t,l,u),f=Wo(t,d,i.lines,{energy:s.energy}),m=i.tracks.filter(y=>G4.has(y.property)),g=i.tracks.find(y=>y.property==="walk");return{tracks:g?[...f,...m,iE(t,g,i.tracks,e,s)]:[...f,...m],duration:i.duration,lines:i.lines,keys:l,beats:i.beats,effects:i.effects}}function Wy(t){const e=vt({"arm.left.spread":90,"arm.left.elbow":0,"arm.left.bend":0,"leg.left.knee":0}),n=ke(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),r=Ee({...ut,rightShoulder:90,rightElbow:0,rightWrist:0},{height:t.height,facing:1}),o=Ee({...ut,rightHip:90,rightKnee:0},{height:t.height,facing:1}),a={x:(r.hands.right.x+r.fingertips.right.x)/2,y:(r.hands.right.y+r.fingertips.right.y)/2},l=Math.hypot(a.x-r.shoulders.right.x,a.y-r.shoulders.right.y),c=Math.hypot(o.feet.right.x-o.hip.x,o.feet.right.y-o.hip.y);return{arm:l>0?s/l:1,leg:c>0?i/c:1}}const V4={point:"arm",grab:"arm",put:"arm",write:"arm",swipe:"arm",push:"arm",kick:"leg"},J4=new Set(["point","grab","put","kick"]);function Z4(t,e,n,s,i,r,o){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:(o.from??0)+Number(u?.get("x")??0),y:(o.ground??0)+Number(u?.get("y")??0)}};n.forEach((h,u)=>{const d=V4[h.do],f=a[u];if(!d||f.contact===void 0||h.do!=="swipe"&&!h.target)return;const m=f.contact,g=f.release??f.contact;t.forEach((p,y)=>{if(p.time<m-1||p.time>g+1)return;const v=r(p.time),w=Ee(e[y],{height:i.height,facing:v<0?-1:1}),k=c(p.time),S=J4.has(h.do)&&h.target?{x:h.target.x-k.x,y:h.target.y-k.y}:void 0,x={x:(w.hands.right.x+w.fingertips.right.x)/2,y:(w.hands.right.y+w.fingertips.right.y)/2},M=S??(d==="arm"?x:w.toes.right),E=v<0?"right":"left",T=`${d}.${E}`;let A=p.pose;if(h.do==="point")A=qe(i,A,T,M);else if(d==="arm")A=qe(i,sE(i,A,E,M),T,M);else for(let P=0;P<3;P++){const I=ke(i,A).points,O=I[`ankle.${E}`],_=I[`toe.${E}`];A=qe(i,A,T,{x:M.x-(_.x-O.x),y:M.y-(_.y-O.y)})}t[y]={...p,pose:A}})})}function Q4(t,e){const n=vt({[`arm.${e}.spread`]:90,[`arm.${e}.elbow`]:0,[`arm.${e}.bend`]:0}),s=ke(t,n).points;return Math.hypot(s[`hand.${e}`].x-s[`shoulder.${e}`].x,s[`hand.${e}`].y-s[`shoulder.${e}`].y)}const tE=5,eE=4,nE=8;function sE(t,e,n,s){const i=Q4(t,n)*.9,r=a=>{const l=ke(t,a).points[`shoulder.${n}`];return Math.hypot(s.x-l.x,s.y-l.y)<=i};if(r(e))return e;let o=e;for(let a=1;a<=nE;a++)if(o={...e,lean:(e.lean??0)+tE*a,bend:(e.bend??0)+eE*a},r(o))return o;return o}function iE(t,e,n,s,i){const r=n.find(u=>u.property==="gait"),o=r?new Ht({id:`${t}-gait-of`,tracks:[r]}):void 0,a=u=>{const d=o?.getStateAtTime(u).values.get(t)?.get("gait");if(typeof d=="string")return Gt[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],m=a((f.time+u.time)/2),g=Xr(m,s.height),p=Ny(s,m);h+=(u.value-f.value)*(p>0?g/p:1)}else h=u.value;c.push({...u,value:h})}),{...e,keyframes:c}}const pn=t=>Math.min(1,Math.max(0,Number.isFinite(t)?t:0)),Ne=t=>{const e=pn(t);return e*e*(3-2*e)},ie=(t,e,n)=>n<=0?t>=e?1:0:pn((t-e)/n);function na(t){const e=pn(t);if(e===0||e===1)return e;const n=1.70158,s=e-1;return 1+(n+1)*s*s*s+n*s*s}function Dy(t,e,n,s=300,i=300){return t>=e&&t<=e+n?Ne(ie(t,e,s))*(1-Ne(ie(t,e+n-i,i))):0}function xe(t,e){const n=pn(e),s=t.trim(),i=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(s)?.[1];if(i){const o=i.length===3?[...i].map(h=>h+h).join(""):i,[a,l,c]=[0,2,4].map(h=>parseInt(o.slice(h,h+2),16));return`rgba(${a},${l},${c},${By(n)})`}const r=/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+)\s*)?\)$/i.exec(s);return r?`rgba(${r[1]},${r[2]},${r[3]},${By(n*(r[4]===void 0?1:Number(r[4])))})`:s}const By=t=>Math.round(t*1e3)/1e3;function sa(t,e,n){const s=[];for(const i of e.split(`
|
|
61
|
+
`)){let r="";for(const o of i.split(/\s+/).filter(Boolean)){const a=r?`${r} ${o}`:o;r&&t.measureText(a).width>n?(s.push(r),r=o):r=a}s.push(r)}return s}function Pe(t,e,n,s,i,r){const o=Math.max(0,Math.min(r,Math.abs(s)/2,Math.abs(i)/2));t.beginPath(),t.moveTo(e+o,n),t.lineTo(e+s-o,n),t.quadraticCurveTo(e+s,n,e+s,n+o),t.lineTo(e+s,n+i-o),t.quadraticCurveTo(e+s,n+i,e+s-o,n+i),t.lineTo(e+o,n+i),t.quadraticCurveTo(e,n+i,e,n+i-o),t.lineTo(e,n+o),t.quadraticCurveTo(e,n,e+o,n),t.closePath()}const Jt=(t,e,n)=>`${e} ${Math.round(t)}px ${n}`,Vn="system-ui, sans-serif";function rE(t,e,n){const{x:s,y:i,width:r,height:o}=n,a=Math.max(0,Math.round(n.drops??70));if(a===0||r<=0||o<=0)return;const l=n.speed??900,c=n.length??34,h=n.slant??-8,u=Se(n.seed??1),d=o+c*2;t.save(),t.beginPath(),t.rect(s,i,r,o),t.clip(),t.strokeStyle=xe(n.color??"rgb(190,210,235)",n.opacity??.35),t.lineWidth=n.lineWidth??2,t.lineCap="round",t.beginPath();for(let f=0;f<a;f++){const m=s+u.next()*r,g=l*(1+u.next()*.6),p=u.next()*d,y=e/1e3*g+p,v=i-c+(y%d+d)%d;t.moveTo(m,v),t.lineTo(m+h,v+c)}t.stroke(),t.restore()}function oE(t,e){const{x:n,y:s,width:i,height:r}=e,o=e.slope??.35,a=Math.max(4,e.spacing??52),l=e.band??24,c=i*o,h=Math.floor((-Math.max(0,c)-l)/a)-1,u=Math.ceil((r-Math.min(0,c))/a)+1;t.save(),t.beginPath(),t.rect(n,s,i,r),t.clip(),t.fillStyle=xe(e.color??"rgb(255,240,210)",e.opacity??.12),t.beginPath();for(let d=h;d<=u;d++){const f=s+d*a;t.moveTo(n,f),t.lineTo(n+i,f+c),t.lineTo(n+i,f+c+l),t.lineTo(n,f+l),t.closePath()}t.fill(),t.restore()}function zy(t){const e=t.angle*Math.PI/180,n=Math.cos(e),s=Math.sin(e),i={x:t.x+n*t.length,y:t.y+s*t.length};return[{x:t.x,y:t.y},{x:i.x-s*t.width,y:i.y+n*t.width},{x:i.x+s*t.width,y:i.y-n*t.width}]}function aE(t,e){const n=pn(e.amount);if(n<=0)return;const s=e.bounds??{x:-1e5,y:-1e5,width:2e5,height:2e5},i=e.color??"rgb(4,6,10)",r=(e.cones??[]).map(zy),o=a=>{t.moveTo(a[0].x,a[0].y),t.lineTo(a[1].x,a[1].y),t.lineTo(a[2].x,a[2].y),t.closePath()};t.save(),t.beginPath(),t.rect(s.x,s.y,s.width,s.height);for(const a of r)o(a);for(const a of e.holes??[])t.moveTo(a.x+a.radius,a.y),t.arc(a.x,a.y,a.radius,0,Math.PI*2,!0);t.fillStyle=xe(i,(e.opacity??.9)*n),t.fill("evenodd");for(const a of r)t.beginPath(),o(a),t.fillStyle=xe(i,.35*n),t.fill(),e.beam!==null&&(t.fillStyle=xe(e.beam??"rgb(255,236,190)",(e.beamOpacity??.08)*n),t.fill());t.restore()}function lE(t,e){const{x:n,y:s,radius:i}=e;if(!(i>0))return;const r=e.color??"rgb(245,185,66)",o=t.createRadialGradient(n,s,0,n,s,i);o.addColorStop(0,xe(r,e.opacity??.5)),o.addColorStop(1,xe(r,0)),t.save(),t.fillStyle=o,t.fillRect(n-i,s-i,2*i,2*i),t.restore()}function cE(t,e){const n=e.x??0,s=e.y??0,i=n+e.width/2,r=s+e.height/2,o=Math.hypot(e.width,e.height)/2,a=e.color??"rgb(0,0,0)",l=t.createRadialGradient(i,r,o*(e.inner??.38),i,r,o*(e.outer??1.05));l.addColorStop(0,xe(a,0)),l.addColorStop(1,xe(a,e.opacity??.55)),t.save(),t.fillStyle=l,t.fillRect(n,s,e.width,e.height),t.restore()}function hE(t,e,n=170){let s=0;for(const i of e)s=Math.max(s,1-Math.abs(t-i)/Math.max(1,n));return pn(s)}function uE(t,e=.18){const n=t/1e3;return Math.sin(n*40)*Math.sin(n*13)>.3?e:0}const Jn="#d7263d",Kh="#f5b942",ia="#efe6d2",yn="#111111";function qy(t,e){const n=e.duration??3e3;return t>=e.at&&t<=e.at+n?{opacity:pn(na(ie(t,e.at,300)))*(1-Ne(ie(t,e.at+n-400,400))),scale:1+.08*Math.sin((t-e.at)/1e3*7)}:{opacity:0,scale:1}}function dE(t,e,n){const{opacity:s,scale:i}=qy(e,n);if(s<=0)return 0;const r=n.radius??46,o=n.lineWidth??6,{x:a,y:l}=n;return t.save(),t.globalAlpha*=Math.min(1,s),t.strokeStyle=n.color??Jn,t.lineWidth=o,t.beginPath(),t.arc(a,l,r*i,0,Math.PI*2),t.stroke(),t.lineWidth=o*10/6,t.lineCap="round",t.beginPath(),t.moveTo(a+r*.72*i,l+r*.72*i),t.lineTo(a+r*1.35,l+r*1.35),t.stroke(),t.restore(),s}function fE(t,e){const n=e.ink??yn,s=e.color??"#b91c1c";t.save(),t.translate(e.x,e.y),t.rotate((e.angle??0)*Math.PI/180);const i=e.scale??1;t.scale(i,i),t.lineJoin="round",t.strokeStyle=n,t.lineWidth=3,t.fillStyle=s,Pe(t,-34,-30,26,10,3),t.fill(),t.stroke(),Pe(t,-34,-24,68,48,4),t.fill(),t.stroke(),t.strokeStyle="#fca5a5",t.lineCap="round",t.beginPath(),t.moveTo(-22,-6),t.lineTo(22,-6),t.stroke(),e.label&&(t.fillStyle=e.labelColor??ia,t.font=Jt(13,800,e.font??Vn),t.textAlign="center",t.textBaseline="middle",t.fillText(e.label,0,9,60)),t.restore()}function gE(t,e){const n=e.radius??52,s=e.ink??yn,{x:i,y:r}=e;t.save(),t.lineCap="round",t.beginPath(),t.arc(i,r,n,0,Math.PI*2),t.fillStyle=e.face??"#f5f0e1",t.fill(),t.strokeStyle=s,t.lineWidth=n*.115,t.stroke(),t.lineWidth=n*.058,t.beginPath();for(let c=0;c<12;c++){const h=c/12*Math.PI*2;t.moveTo(i+Math.sin(h)*n*.77,r-Math.cos(h)*n*.77),t.lineTo(i+Math.sin(h)*n*.88,r-Math.cos(h)*n*.88)}t.stroke();const o=(c,h,u)=>{t.lineWidth=u,t.beginPath(),t.moveTo(i,r),t.lineTo(i+Math.sin(c)*h,r-Math.cos(c)*h),t.stroke()},{hour:a,minute:l}=jy(e.hours,e.minutes);o(a,n*.5,n*.115),o(l,n*.77,n*.077),t.restore()}function jy(t,e){const n=(e%60+60)%60;return{hour:((t%12+12)%12+n/60)/12*Math.PI*2,minute:n/60*Math.PI*2}}function mE(t,e,n){const s=n.size??30,i=n.color??Kh;t.save(),t.font=Jt(s,800,n.font??Vn);const r=t.measureText(n.text).width+s*1.66,o=s*1.87;return t.globalAlpha*=Ne(ie(e,n.at??100,400)),Pe(t,n.x,n.y,r,o,6),t.fillStyle=n.background??"#000000",t.fill(),t.strokeStyle=i,t.lineWidth=3,t.stroke(),t.fillStyle=i,t.textAlign="center",t.textBaseline="middle",t.fillText(n.text,n.x+r/2,n.y+o/2+s*.04),t.restore(),r}function pE(t,e,n){const s=Dy(e,n.at,n.duration??2600,250,300);if(s<=0)return 0;const i=n.frame??{width:1920,height:1080},r=n.nameSize??64,o=n.roleSize??30,a=n.font??Vn,l=n.side==="left"||n.side==="right"?n.side:n.anchor.x<i.width*.57?"right":"left";t.save();const c=n.dim??.35;c>0&&(t.fillStyle=`rgba(0,0,0,${c*s})`,t.fillRect(0,0,i.width,i.height));const h=r*2.2;t.translate(n.anchor.x+(l==="right"?h:-h),n.anchor.y+r*.6),t.rotate((n.tilt??-3.4)*Math.PI/180),t.globalAlpha*=s,t.font=Jt(r,800,a);const u=t.measureText(n.name).width;t.font=Jt(o,700,a);const d=n.role?t.measureText(n.role).width:0,f=r*.47,m=Math.max(u,d)+f*2+10,g=-r*1.1,p=n.role?r+o+r*.95:r*1.6,y=l==="right"?0:-m;Pe(t,y,g,m,p,4),t.fillStyle=n.color??Jn,t.fill(),t.strokeStyle=n.ink??yn,t.lineWidth=5,t.stroke(),t.textAlign="left",t.textBaseline="alphabetic",t.fillStyle="#ffffff",t.font=Jt(r,800,a);const v=n.role?g+r*1.1+r*.22:g+p/2+r*.35;return t.fillText(n.name,y+f,v),n.role&&(t.font=Jt(o,700,a),t.fillStyle=ia,t.fillText(n.role,y+f,v+o*1.45)),t.restore(),s}function Ky(t,e,n,s){const i=Ne(ie(t,e-50,300))*(1-Ne(ie(t,n,250))),r=s??Math.min(1600,Math.max(0,n-e)*.5);return{opacity:t<e-50||t>n+250?0:i,reveal:ie(t,e,r)}}function yE(t,e){const n=t.reduce((i,r)=>i+r.split(" ").filter(Boolean).length,0);let s=Math.round(pn(e)*n);return t.map(i=>{const r=i.split(" ").filter(Boolean),o=r.slice(0,Math.max(0,Math.min(r.length,s)));return s-=r.length,o.join(" ")})}function bE(t,e,n){const{opacity:s,reveal:i}=Ky(e,n.start,n.end,n.typeDuration);if(s<=0||!n.text)return 0;const r=n.x??150,o=n.width??1620,a=n.bottom??1040,l=n.size??42,c=n.font??Vn,h=n.ink??yn,u=l*1.29;t.save(),t.font=Jt(l,700,c);const d=sa(t,n.text,o-l*1.4),f=a-d.length*u-l*.72;if(t.globalAlpha*=s,Pe(t,r,f,o,a-f,6),t.fillStyle=n.background??xe("rgb(239,230,210)",.96),t.fill(),t.strokeStyle=h,t.lineWidth=5,t.stroke(),n.speaker){t.font=Jt(l*.57,800,c);const g=t.measureText(n.speaker).width+l*1.4;Pe(t,r,f-l*.72,g,l*.86,4),t.fillStyle=n.tagColor??Jn,t.fill(),t.lineWidth=3,t.stroke(),t.fillStyle="#ffffff",t.textAlign="center",t.textBaseline="middle",t.fillText(n.speaker,r+g/2,f-l*.29)}t.font=Jt(l,700,c),t.fillStyle=h,t.textBaseline="alphabetic";const m=yE(d,i);return d.forEach((g,p)=>{const y=t.measureText(g).width;t.textAlign="left",t.fillText(m[p],r+o/2-y/2,f+l*1.38+p*u)}),t.restore(),s}function wE(t,e,n){const s=n.start-50,i=n.end+300,r=na(ie(e,s,280))*(1-Ne(ie(e,i,220)));if(!(e>=s&&e<=i+220)||r<=.01)return 0;const o=n.size??40,a=n.font??Vn,l=n.ink??yn,c=n.fill??"#ffffff",h=n.bounds??{x:40,y:40,width:1840},u=n.tail;t.save(),t.font=Jt(o,700,a);const d=sa(t,n.text,n.maxWidth??640),f=o*1.3,m=Math.max(...d.map(S=>t.measureText(S).width))+o*1.75,g=d.length*f+o*1.25,p=n.speaker?o*.5:0,y=Math.min(h.x+h.width-m/2,Math.max(h.x+m/2,u.x));let v=Math.min(u.y-(n.gap??70)-g/2,n.maxCenterY??1/0);v=Math.max(h.y+p+g/2,v);const w={x:u.x+(y-u.x)*.2,y:Math.max(v+g/2+16,u.y-14)};t.translate(w.x,w.y),t.scale(r,r),t.translate(-w.x,-w.y),t.fillStyle=c,t.strokeStyle=l,t.lineWidth=5,t.lineJoin="round";const k=Math.min(Math.max(w.x,y-m/2+50),y+m/2-50);if(t.beginPath(),t.moveTo(k-22,v+g/2-4),t.lineTo(w.x,w.y),t.lineTo(k+22,v+g/2-4),t.closePath(),t.fill(),t.stroke(),Pe(t,y-m/2,v-g/2,m,g,26),t.fill(),t.stroke(),t.fillRect(k-19,v+g/2-8,38,6),n.speaker){const S=o*.68;t.font=Jt(S,800,a);const x=t.measureText(n.speaker).width+S*1.1;Pe(t,y-m/2+18,v-g/2-S*.74,x,S*1.4,6),t.fillStyle=n.tagColor??l,t.fill(),t.fillStyle=n.tagText??ia,t.textAlign="left",t.textBaseline="middle",t.fillText(n.speaker,y-m/2+18+S*.55,v-g/2-S*.04)}return t.font=Jt(o,700,a),t.fillStyle=l,t.textAlign="center",t.textBaseline="alphabetic",d.forEach((S,x)=>t.fillText(S,y,v-g/2+o*1.65+x*f)),t.restore(),r}const ra=["photo","note"],oa={cross:"two diagonals across the card, one after the other (ruled out)",strike:"one diagonal, bottom-left to top-right (half ruled out)",scribble:"a zigzag back and forth across the card (scribbled out)",circle:"a loose ring round the card (this one)"};function kE(t){const e=t.seed??1,n=Se(e),s=new Set,i=t.cards.map(c=>{if(!c.id)throw new Error("caseBoard: every card needs an id");if(s.has(c.id))throw new Error(`caseBoard: two cards have the id "${c.id}"`);s.add(c.id);const h=c.kind??"photo";if(!ra.includes(h))throw new Error(`caseBoard: ${dt("card kind",h,ra)}`);const u=(n.next()-.5)*6;return{id:c.id,x:c.x,y:c.y,kind:h,title:c.title,note:c.note,width:c.width??220,height:c.height??(h==="photo"?260:124),angle:c.angle??u,color:c.color??(h==="photo"?"#f5f1e8":"#fef08a"),at:c.at??0,highlight:c.highlight}}),r=[...s],o=(c,h)=>{if(!s.has(c))throw new Error(`caseBoard: ${h}: ${dt("card",c,r)}`)},a=(t.strings??[]).map((c,h)=>(o(c.from,`strings[${h}].from`),o(c.to,`strings[${h}].to`),{from:c.from,to:c.to,at:c.at??0,duration:c.duration??600,color:c.color??"#b91c1c"})),l=(t.marks??[]).map((c,h)=>{if(o(c.on,`marks[${h}].on`),!(c.kind in oa))throw new Error(`caseBoard: marks[${h}]: ${dt("mark",c.kind,Object.keys(oa))}`);return{on:c.on,kind:c.kind,at:c.at,duration:c.duration??1400,color:c.color??Jn,width:c.width??(c.kind==="scribble"?18:16)}});return{x:t.x,y:t.y,width:t.width,height:t.height,cards:i,strings:a,marks:l,cork:t.cork??"#9a6b43",frame:t.frame??"#4a2f1e",ink:t.ink??yn,font:t.font??Vn,handFont:t.handFont??t.font??Vn,seed:e}}const Yh=(t,e)=>{const n=t.cards.find(s=>s.id===e);if(!n)throw new Error(dt("card",e,t.cards.map(s=>s.id)));return n};function aa(t,e,n){const s=e.angle*Math.PI/180;return{x:t.x+e.x+n.x*Math.cos(s)-n.y*Math.sin(s),y:t.y+e.y+n.x*Math.sin(s)+n.y*Math.cos(s)}}function la(t,e){const n=Yh(t,e),s=n.width/2,i=n.height;return{pin:aa(t,n,{x:0,y:0}),center:aa(t,n,{x:0,y:i/2}),corners:[{x:-s,y:0},{x:s,y:0},{x:s,y:i},{x:-s,y:i}].map(r=>aa(t,n,r)),width:n.width,height:n.height}}function Xh(t,e){const n=Yh(t,e.on),s=n.width/2-10,i=8,r=n.height-8,o=(a,l)=>aa(t,n,{x:a,y:l});if(e.kind==="cross")return[[o(-s,i),o(s,r)],[o(s,i),o(-s,r)]];if(e.kind==="strike")return[[o(-s,r),o(s,i)]];if(e.kind==="scribble"){const a=n.height/2,l=n.height*.33;return[Array.from({length:15},(c,h)=>o(-s+h*2*s/14,h%2?a-l:a+l))]}return[Array.from({length:41},(a,l)=>{const c=-2.4+l/40*Math.PI*2.15,h=1+.04*Math.sin(l*1.7);return o(Math.cos(c)*(s+30)*h,n.height/2+Math.sin(c)*(n.height/2+26)*h)})]}function Yy(t,e){const n=t.map(Cl),s=n.reduce((r,o)=>r+o,0)||1;let i=e*s;return n.map(r=>{const o=r>0?Math.min(1,Math.max(0,i/r)):1;return i-=r,o})}function Xy(t,e){let n=null;for(const s of t.marks){if(e<=s.at||e>=s.at+s.duration)continue;const i=Xh(t,s),r=Yy(i,Ne(ie(e,s.at,s.duration))),o=Math.max(0,r.findIndex(l=>l<1)),a=sn(i[o],r[o]);n=a[a.length-1]}return n}function Gy(t,e,n,s={}){const i=s.radius??11;t.save(),t.beginPath(),t.arc(e,n,i,0,Math.PI*2),t.fillStyle=s.color??Jn,t.fill(),t.lineWidth=3,t.strokeStyle=s.ink??yn,t.stroke(),t.beginPath(),t.arc(e-i*.27,n-i*.27,i*.27,0,Math.PI*2),t.fillStyle="#fca5a5",t.fill(),t.restore()}function Uy(t,e,n,s={}){if(n<=0||e.length<2)return null;const i=sn(e,n);t.save(),t.strokeStyle=s.color??Jn,t.lineWidth=s.width??16,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(i[0].x,i[0].y);for(const r of i.slice(1))t.lineTo(r.x,r.y);return t.stroke(),t.restore(),i[i.length-1]}function vE(t,e,n,s={}){const{x:i,y:r,width:o,height:a,ink:l}=e;t.save(),Pe(t,i,r,o,a,10),t.fillStyle=e.cork,t.fill(),t.save(),t.clip();const c=Se(e.seed+7);t.fillStyle="rgba(60,35,15,0.25)";const h=Math.round(o*a/3e3);for(let d=0;d<h;d++)t.beginPath(),t.arc(i+c.next()*o,r+c.next()*a,2+c.next()*2,0,Math.PI*2),t.fill();t.restore(),Pe(t,i,r,o,a,10),t.lineWidth=22,t.strokeStyle=e.frame,t.stroke();const u=d=>n>=d.at?na(ie(n,d.at,350)):0;for(const d of e.strings){const f=Ne(ie(n,d.at,d.duration));if(f<=0||u(Yh(e,d.from))<=0)continue;const m=la(e,d.from).pin,g=la(e,d.to).pin;t.strokeStyle=d.color,t.lineWidth=4,t.lineCap="round",t.beginPath(),t.moveTo(m.x,m.y),t.lineTo(m.x+(g.x-m.x)*f,m.y+(g.y-m.y)*f),t.stroke()}for(const d of e.cards){const f=u(d);if(f<=0)continue;const m=d.width,g=d.height;t.save(),t.translate(i+d.x,r+d.y-40*(1-Math.min(1,f))),t.rotate(d.angle*Math.PI/180),t.scale(f,f),Pe(t,-m/2,0,m,g,3),t.fillStyle=d.color,t.fill(),t.lineWidth=3,t.strokeStyle=l,t.stroke();const p=d.kind==="photo",y=p?{x:-m/2+18,y:18,width:m-36,height:g*.62}:{x:-m/2+12,y:14,width:m-24,height:g*.45};p&&(t.fillStyle="#1e2530",t.fillRect(y.x,y.y,y.width,y.height)),s.drawCard&&(t.save(),t.beginPath(),t.rect(y.x,y.y,y.width,y.height),t.clip(),s.drawCard(t,d,y,n),t.restore()),t.textAlign="center",t.textBaseline="alphabetic";const v=y.y+y.height;if(p)d.title&&(t.font=Jt(28,800,e.font),t.fillStyle=l,t.fillText(d.title,0,v+(g-v)*.45,m-16)),d.note&&(t.font=Jt(19,600,e.font),t.fillStyle="#7f1d1d",t.fillText(d.note,0,v+(g-v)*.8,m-16));else{const k=[d.title,d.note].filter(Boolean).join(`
|
|
62
|
+
`);t.font=Jt(26,700,e.handFont),t.fillStyle=l;const S=sa(t,k,m-20),x=s.drawCard?v+8:(g-S.length*30)/2;S.forEach((M,E)=>t.fillText(M,0,x+24+E*30,m-12))}d.highlight&&n>=d.highlight.at&&n<=d.highlight.at+d.highlight.duration&&(t.strokeStyle=Kh,t.lineWidth=8,t.globalAlpha*=.6+.4*Math.sin((n-d.highlight.at)/1e3*6),t.strokeRect(-m/2-8,-8,m+16,g+16)),t.restore();const w=la(e,d.id).pin;Gy(t,w.x,w.y-40*(1-Math.min(1,f)),{ink:l})}for(const d of e.marks){if(n<=d.at)continue;const f=Xh(e,d),m=Yy(f,Ne(ie(n,d.at,d.duration)));f.forEach((g,p)=>Uy(t,g,m[p],{color:d.color,width:d.width}))}return t.restore(),Xy(e,n)}const Vy={atmosphere:{"drawRain(ctx, time, { x, y, width, height, drops?, opacity?, color?, speed?, length?, slant?, lineWidth?, seed? })":"rain streaks falling in a box (a window, the frame), clipped to it; seeded, a pure function of time","drawBlinds(ctx, { x, y, width, height, opacity?, slope?, spacing?, band?, color? })":"key light through venetian blinds: slanted bright bands","drawDarkness(ctx, { amount, cones?: [{ x, y, angle (deg), length, width }], holes?: [{ x, y, radius }], bounds?, color?, opacity?, beam?, beamOpacity? })":"a dark room with torch beams and round holes of light cut out (coneCorners(cone) gives a beam’s corners)","drawGlow(ctx, { x, y, radius, color?, opacity? })":"a soft pool of light","drawVignette(ctx, { width, height, x?, y?, inner?, outer?, opacity?, color? })":"the frame’s edges fall into dark","lightningFlash(time, strikes, decay?)":"flash brightness 0..1 from strike times (ms)","lightFlicker(time, strength?)":"a failing bulb: how much darker the room is (0 or strength)"},overlays:{"drawClueMarker(ctx, time, { x, y, radius?, at, duration?, color?, lineWidth? })":"the red magnifier over a clue: pops on, pulses, fades (clueMarkerAt gives its opacity and scale)","drawEvidenceFolder(ctx, { x, y, scale?, angle?, color?, ink?, label?, font? })":"a tabbed evidence folder","drawClockFace(ctx, { x, y, radius?, hours, minutes, face?, ink? })":"a wall clock showing a time (clockHandAngles gives the hands)","drawTimeChip(ctx, time, { x, y, text, size?, font?, color?, background?, at? })":"a time/place chip in a corner; returns its width","drawNameCard(ctx, time, { name, role?, at, duration?, anchor, side?, frame?, dim?, color?, font?, tilt? })":"a freeze-frame suspect card: the frame dims, a slanted red band beside the head","drawNarrationBox(ctx, time, { text, start, end, speaker?, x?, width?, bottom?, size?, font?, typeDuration? })":"a first-person narration box along the bottom, words typed on (lineReveal gives opacity and reveal)","drawSpeechBubble(ctx, time, { text, start, end, tail, speaker?, maxWidth?, size?, font?, bounds?, maxCenterY?, gap? })":"a comic speech bubble above the speaker, tail to the head, popping on"},caseBoard:{"caseBoard({ x, y, width, height, cards, strings?, marks?, cork?, frame?, font?, handFont?, seed? })":"checks and resolves a case board (did-you-mean on unknown card ids and kinds)","drawCaseBoard(ctx, board, time, { drawCard? })":"the board at a time: cork, red strings stretching, cards popping up on pins, marker strokes; returns the nib point while a mark is drawn","caseBoardMarkerTip(board, time)":"where the marker’s nib is (for a hand), or null","caseCardBox(board, id)":"a card’s pin, centre and corners, scene px","caseMarkPath(board, { on, kind })":"a mark’s stroke points","drawPushPin(ctx, x, y, { color?, radius? })":"a red push pin","drawMarkerStroke(ctx, points, progress, { color?, width? })":"the first part of a marker stroke; returns the nib"},cardKinds:ra,markKinds:oa,card:"{ id, x, y (its pin, relative to the board), kind?, title?, note?, width?, height?, angle?, color?, at?, highlight?: { at, duration } }",string:"{ from, to, at?, duration?, color? }",mark:"{ on, kind, at, duration?, color?, width? }"},yt=["rect","circle","text","line","path","image","custom"],ca={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:yt},y:{description:"Moves it down by this much from where it was placed (an offset)",unit:"px",types:yt},opacity:{description:"How opaque it is",unit:"0..1",min:0,max:1,types:yt},rotate:{description:"Turns it clockwise about its origin",unit:"degrees",types:yt},rotateX:{description:"Tips it about the horizontal axis (3D; shows with perspective)",unit:"degrees",types:yt},rotateY:{description:"Turns it about the vertical axis (3D; shows with perspective)",unit:"degrees",types:yt},z:{description:"Depth toward the viewer (shows with perspective)",unit:"px",types:yt},perspective:{description:"Distance from the viewer: nearer parts grow, further ones shrink",unit:"px",min:1,types:yt},scale:{description:"Size, both ways",unit:"factor",types:yt},scaleX:{description:"Width factor",unit:"factor",types:yt},scaleY:{description:"Height factor",unit:"factor",types:yt},skewX:{description:"Slants it sideways",unit:"degrees",types:yt},skewY:{description:"Slants it up and down",unit:"degrees",types:yt},originX:{description:"Transform pivot across its box",unit:"% (0 left, 50 centre, 100 right)",min:0,max:100,types:yt},originY:{description:"Transform pivot down its box",unit:"% (0 top, 50 centre, 100 bottom)",min:0,max:100,types:yt},fill:{description:"Fill colour (also written fillStyle)",kind:"color",types:yt},stroke:{description:"Outline colour (also written strokeStyle)",kind:"color",types:yt},strokeWidth:{description:"Outline width (also written lineWidth)",unit:"px",min:0,types:yt},clipTop:{description:"Hides this much from the top edge, for reveals",unit:"% of its height",min:0,max:100,types:yt},clipRight:{description:"Hides this much from the right edge",unit:"% of its width",min:0,max:100,types:yt},clipBottom:{description:"Hides this much from the bottom edge",unit:"% of its height",min:0,max:100,types:yt},clipLeft:{description:"Hides this much from the left edge",unit:"% of its width",min:0,max:100,types:yt},blur:{description:"Gaussian blur",unit:"px",min:0,types:yt},brightness:{description:"Brightness factor (1 unchanged)",unit:"factor",min:0,types:yt},glow:{description:"Soft glow around it, in glowColor",unit:"px",min:0,types:yt},glowColor:{description:"Colour of the glow",kind:"color",types:yt},shadowX:{description:"Drop shadow offset right",unit:"px",types:yt},shadowY:{description:"Drop shadow offset down",unit:"px",types:yt},shadowBlur:{description:"Drop shadow softness",unit:"px",min:0,types:yt},shadowColor:{description:"Drop shadow colour",kind:"color",types:yt},shine:{description:"A highlight sweeping across the fill",unit:"0..1 (progress)",min:0,max:1,types:yt},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:yt},quaternion:{description:'A rotation as [x, y, z, w] (a track with interpolation: "slerp")',kind:"list",types:yt}},Gh={fillStyle:"fill",strokeStyle:"stroke",lineWidth:"strokeWidth",rotateZ:"rotate",motionPathX:"x",motionPathY:"y",motionPathRotate:"rotate"},ME={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 Jy(t){const e=t,n=Object.entries(ca).filter(([,i])=>i.types.includes(t.type)).map(([i,{types:r,...o}])=>({name:i,...o,...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,r]of Object.entries(t.props??{}))n.push({name:i,description:s?.props?.[i]?.description??"",...s?.props?.[i],value:r});return{type:"custom",...s?{kind:s.kind,summary:s.summary}:{},properties:n,...s?.actions?{actions:s.actions}:{}}}function Zy(t){const e=Jy(t).properties.map(n=>n.name);return[...e,...Object.keys(Gh).filter(n=>e.includes(Gh[n]))]}function SE(t,e){const n=[],s=Object.keys(e);for(const i of t){const r=d=>n.push({level:"error",track:i.id,message:d}),o=e[i.target];if(!o){r(dt("target",i.target,s));continue}const a=Zy(o),l=o.type==="custom"&&o.acceptsProp?.(i.property);if(!a.includes(i.property)&&!l){r(`${i.target}: ${dt("property",i.property,a,ME[i.property])}`);continue}const c=i.keyframes??[];for(let d=1;d<c.length;d++)c[d].time<c[d-1].time&&r(`${i.target}.${i.property}: keyframes out of time order (${c[d-1].time} ms, then ${c[d].time} ms).`);const h=ca[Gh[i.property]??i.property]??o.about?.props?.[i.property],u=h&&(h.kind??"number")==="number";for(const d of c){if(u&&typeof d.value!="number"){r(`${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 Ws=(t,e)=>t[2]<=-e;function Uh(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 Qy(t,e){if(t.every(s=>Ws(s,e)))return t;const n=[];return t.forEach((s,i)=>{const r=t[(i+t.length-1)%t.length],o=Ws(s,e),a=Ws(r,e);o!==a&&n.push(Uh(r,s,e)),o&&n.push(s)}),n.length>=3?n:[]}function TE(t,e){if(t.every(i=>Ws(i,e)))return[t];const n=[];let s=[];return t.forEach((i,r)=>{const o=Ws(i,e);if(r>0){const a=t[r-1],l=Ws(a,e);l&&!o?(s.push(Uh(a,i,e)),n.push(s),s=[]):!l&&o&&s.push(Uh(a,i,e))}o&&s.push(i)}),s.length>0&&n.push(s),n.filter(i=>i.length>=2)}function t1(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},(r,o)=>t+s*o/i)}function EE(t,e,n){const s=(i,r)=>Math.max(0,Math.min(i.length-2,i.findIndex((o,a)=>a>0&&r<=o)-1));return[s(t,n[0]),s(e,n[2])]}function AE(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]],r=Math.hypot(...i)||1;return[i[0]/r,i[1]/r,i[2]/r]};return{...t,vertices:t.vertices.map(s=>ae(e,s)),faces:t.faces.map(s=>({corners:s.corners,normal:n(s.normal)}))}}function ha(t,e,n,s){const i=o=>(o[e]-n)*s>=0;if(t.every(i))return t;const r=[];return t.forEach((o,a)=>{const l=t[(a+t.length-1)%t.length];if(i(o)!==i(l)){const c=(n-l[e])/(o[e]-l[e]);r.push([0,1,2].map(h=>h===e?n:l[h]+(o[h]-l[h])*c))}i(o)&&r.push(o)}),r.length>=3?r:[]}function xE(t,e,n){const s=t.faces.map(o=>({points:o.corners.map(a=>t.vertices[a]),normal:o.normal})),i=[],r={x:e.slice(1,-1),z:n.slice(1,-1)};for(let o=0;o+1<e.length;o++)for(let a=0;a+1<n.length;a++){const l=[],c=new Map,h=m=>{const g=m.map(y=>Math.round(y*1e6)).join(",");let p=c.get(g);return p===void 0&&(p=l.length,l.push(m),c.set(g,p)),p},u=[],d=m=>m===0,f=(m,g)=>m+2===g.length;for(const m of s){let g=m.points;d(o)||(g=ha(g,0,e[o],1)),g.length&&!f(o,e)&&(g=ha(g,0,e[o+1],-1)),g.length&&!d(a)&&(g=ha(g,2,n[a],1)),g.length&&!f(a,n)&&(g=ha(g,2,n[a+1],-1)),g.length>=3&&u.push({corners:g.map(h),normal:m.normal})}u.length>0&&i.push({cell:[o,a],mesh:{vertices:l,faces:u,creases:t.creases,joined:t.joined,walls:r}})}return i}const PE=new WeakMap,$E=new WeakMap,IE=48,e1=t=>t.map(e=>Math.round(e*1e5)).join(",");function n1(t,e,n,s){let i=t.get(e);i||t.set(e,i=new Map);let r=i.get(n);return r===void 0&&(i.size>=IE&&i.clear(),i.set(n,r=s())),r}function Vh(t,e){const n=e1(e);return n1(PE,t,n,()=>{const s=AE(t,e),i=[1/0,1/0,1/0],r=[-1/0,-1/0,-1/0];for(const o of s.vertices)for(const a of[0,1,2])i[a]=Math.min(i[a],o[a]),r[a]=Math.max(r[a],o[a]);return{key:n,inSpace:s,low:i,high:r}})}function OE(t,e){const n=t.map(h=>({...h,...Vh(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 r=t1(s[0],i[0],e),o=t1(s[2],i[2],e),a=`${r.join(",")}|${o.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:EE(r,o,d)}]}return n1($E,h.inSpace,a,()=>xE(h.inSpace,r,o)).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])=>[(r[h]+r[h+1])/2,c,(o[u]+o[u+1])/2]}}const s1=.004,Jh=.05,i1=new WeakMap;function CE(t){let e=i1.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)}),i1.set(t,e)),e}const r1=new WeakMap;function o1(t){return t.filter(({mesh:e})=>CE(e)).map(({part:e,key:n,inSpace:s,low:i,high:r})=>{let o=r1.get(s);return o||(o=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]}}),r1.set(s,o)),{part:e,key:n,planes:o,low:i,high:r}})}function _E(t,e,n,s){const i=e.reduce((r,o)=>[r[0]+o[0]/e.length,r[1]+o[1]/e.length,r[2]+o[2]/e.length],[0,0,0]);for(const r of s){if(r.part===t||[0,1,2].some(a=>i[a]<r.low[a]-Jh||i[a]>r.high[a]+Jh))continue;if(r.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)<=s1))return l<-.9;const h=Math.abs(l)<.5?Jh:s1;return c.every(u=>u<=h)}))return!0}return!1}const a1=new WeakMap;function l1(t,e,n,s,i){const r=`${s}|${i.map(l=>l.key).join(";")}`;let o=a1.get(e);o||a1.set(e,o=new Map);let a=o.get(r);if(!a){o.size>=48&&o.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=>ae(n,h));a=e.faces.map(h=>_E(t,h.corners.map(u=>c[u]),l(h.normal),i)),o.set(r,a)}return a}const Ds={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}},Zh=Math.PI/180;function c1(t,e,n){return{toView:s=>sg(ee(s,t*90*Zh),-e*Zh),toScreen:s=>({x:s[0]*n,y:-s[1]*n})}}const h1=new WeakMap,or=t=>ua(t),ua=t=>{let e=h1.get(t);return e||h1.set(t,e=Ip(t)),e};function Ot(t,e,n){return e[n]??t.controls[n]?.default??Ds[n]?.default??0}function ar(t,e){const n=Math.max(.05,Ot(t,e,"squash")),s=1/Math.sqrt(n),r=[1,0,0,0,0,1,Ot(t,e,"lean"),0,0,0,1,0,0,0,0,1];return[In([0,Ot(t,e,"lift"),0]),Te(Zt([1,0,0],-Ot(t,e,"pitch"))),Te(Zt([0,0,1],Ot(t,e,"roll"))),r,On([s,n,s]),On(Array(3).fill(Math.max(0,Ot(t,e,"size"))))].reduce((o,a)=>Ft(o,a))}function Qh(t,e){const n=ar(t,e),s=new Map,i=Object.entries(t.controls).flatMap(([o,a])=>(a.bind??[]).map(l=>({value:Ot(t,e,o),bind:l}))),r=o=>{const a=s.get(o.id);if(a)return a;const l=o.parent?t.parts.find(h=>h.id===o.parent):void 0;if(o.parent&&!l)throw new Error(`prop rig: part "${o.id}" hangs from "${o.parent}", which is not a part`);let c=Ft(l?r(l):n,In(o.at??[0,0,0]));if(o.rotate){const[h,u,d]=o.rotate;h&&(c=Ft(c,Te(Zt([1,0,0],h)))),u&&(c=Ft(c,Te(Zt([0,1,0],u)))),d&&(c=Ft(c,Te(Zt([0,0,1],d))))}for(const{value:h,bind:u}of i)if(!(!u.parts.includes(o.id)||h===0)){if(u.translate&&(c=Ft(c,In([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,In(d),Te(Zt(f,u.rotate.degrees*h)),In([-d[0],-d[1],-d[2]])].reduce((m,g)=>Ft(m,g))}u.scale&&(c=Ft(c,On([1+(u.scale[0]-1)*h,1+(u.scale[1]-1)*h,1+(u.scale[2]-1)*h])))}return s.set(o.id,c),c};for(const o of t.parts)r(o);return s}const t0=(()=>{const t=[-.45,.75,.5],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),RE=Math.cos(35*Zh);function e0(t,e,n,s,i={}){const r=t.derive?{...e,...t.derive(e)}:e,o=Qh(t,r),a=n.toView([0,0,0]),l=_=>L=>[_[0]*L[0]+_[4]*L[1]+_[8]*L[2],_[1]*L[0]+_[5]*L[1]+_[9]*L[2],_[2]*L[0]+_[6]*L[1]+_[10]*L[2]],c=ar(t,r),h=i.slice===void 0?null:ll(c),u=h?t.parts.map(_=>({part:_,mesh:ua(_.shape),local:Ft(h,o.get(_.id)),whole:_.shape.type==="tube"})):void 0,d=u?OE(u,i.slice):void 0,f=u?o1(u.map(_=>({part:_.part.id,mesh:_.mesh,...Vh(_.mesh,_.local)}))):void 0,m=(_,L,j,V)=>{const tt=Q=>n.toView(ae(j,Q)),J=L.vertices.map(tt),F=J.map(Q=>n.toScreen(Q)),B=i.perspective?i.near:void 0,Y=Q=>Q.map(ot=>n.toScreen(ot)),R=Q=>B===void 0?Q:Qy(Q,B),K=Q=>B===void 0?[Q]:TE(Q,B),st=l(j),$=L.faces.map(Q=>{const ot=n.toView(st(Q.normal)),ht=[ot[0]-a[0],ot[1]-a[1],ot[2]-a[2]],ft=Math.hypot(...ht)||1;return[ht[0]/ft,ht[1]/ft,ht[2]/ft]}),C=f&&V?l1(_.id,L,V,e1(V),f):void 0,z=Q=>C?.[Q]??!1,X=$.map((Q,ot)=>{if(z(ot))return!1;if(!i.perspective)return Q[2]>1e-6;const ft=L.faces[ot].corners.reduce((bt,wt)=>[bt[0]+J[wt][0],bt[1]+J[wt][1],bt[2]+J[wt][2]],[0,0,0]);return-(Q[0]*ft[0]+Q[1]*ft[1]+Q[2]*ft[2])>1e-9}),W=Q=>L.faces[Q].corners.reduce((ot,ht)=>ot+J[ht][2],0)/L.faces[Q].corners.length,N=L.faces.map((Q,ot)=>({face:Q,i:ot})).filter(({i:Q})=>X[Q]).map(({face:Q,i:ot})=>({i:ot,solved:{points:B===void 0?Q.corners.map(ht=>F[ht]):Y(R(Q.corners.map(ht=>J[ht]))),depth:W(ot),tone:.72+.33*Math.max(0,$[ot][0]*t0[0]+$[ot][1]*t0[1]+$[ot][2]*t0[2])}})).filter(Q=>Q.solved.points.length>=3).sort((Q,ot)=>Q.solved.depth-ot.solved.depth);if(i.light){const Q=l(j);for(const{i:ot,solved:ht}of N){const ft=L.faces[ot].corners,bt=ft.reduce(($0,Wx)=>{const I0=ae(j,L.vertices[Wx]);return[$0[0]+I0[0]/ft.length,$0[1]+I0[1]/ft.length,$0[2]+I0[2]/ft.length]},[0,0,0]),wt=Q(L.faces[ot].normal),Me=Math.hypot(...wt)||1,gr=i.light(bt,[wt[0]/Me,wt[1]/Me,wt[2]/Me]);ht.light=gr.light,ht.fog=gr.fog}}const D=N.map(Q=>Q.solved),G=HE(L),q=[],Z=[];for(const[Q,ot]of G){const ht=ot.filter(bt=>X[bt]).length;if(ht===0)continue;const ft=ot.length===2&&ht===2&&L.creases!==!1&&$[ot[0]][0]*$[ot[1]][0]+$[ot[0]][1]*$[ot[1]][1]+$[ot[0]][2]*$[ot[1]][2]<RE;ot.length===1&&(L.joined||FE(L,Q))||(ot.length===1||ht===1||ft)&&(q.push(Q.split("-").map(Number)),Z.push(ot.filter(bt=>X[bt]).reduce((bt,wt)=>W(wt)>W(bt)?wt:bt)))}const et=Q=>L.faces.findIndex(ot=>ot.corners.length>4&&Math.sign(NE(L.vertices[Q],ot.normal))>0),H=(L.marks??[]).filter(([Q])=>et(Q)<0||X[et(Q)]),U=([Q,ot])=>B===void 0?[[F[Q],F[ot]]]:K([J[Q],J[ot]]).map(Y),nt=H.flatMap(U),at=Q=>B===void 0?[Q.map(ot=>F[ot])]:K(Q.map(ot=>J[ot])).map(Y);if(i.slice!==void 0){const Q=new Map;q.forEach((ot,ht)=>Q.set(Z[ht],[...Q.get(Z[ht])??[],ot]));for(const{i:ot,solved:ht}of N){ht.edges=g1(Q.get(ot)??[]).flatMap(at);const ft=L.faces[ot].corners;ht.center=ft.reduce((wt,Me)=>[wt[0]+J[Me][0]/ft.length,wt[1]+J[Me][1]/ft.length,wt[2]+J[Me][2]/ft.length],[0,0,0]),ht.normal=$[ot];const bt=N[N.length-1].i;ht.marks=H.filter(([wt])=>(et(wt)>=0?et(wt):bt)===ot).flatMap(U)}}const rt=_.glow?Math.max(0,Math.min(1,Ot(t,r,_.glow.control))):0,ct=_.fade?Math.max(0,Math.min(1,Ot(t,r,_.fade.control))):0,it=_.fade?Math.max(0,Math.min(1,_.fade.from+(_.fade.to-_.fade.from)*ct)):1;return{part:_,depth:J.reduce((Q,ot)=>Q+ot[2],0)/Math.max(1,J.length),faces:D,edges:g1(q).flatMap(at),marks:nt,glow:rt,opacity:it,..._.shape.type==="tube"?{spine:LE(K(_.shape.points.map(tt)).map(Y))}:{},...L.walls?{cut:!0}:{}}},g=new Map(u?.map(_=>[_.part.id,_.local])),y=(d?d.pieces.map(_=>({part:_.part,mesh:_.mesh,m:_.cut?c:o.get(_.part.id),local:_.cut?Or():g.get(_.part.id),cell:_.cell})):t.parts.map(_=>({part:_,mesh:ua(_.shape),m:o.get(_.id),local:void 0,cell:void 0}))).map(_=>({cell:_.cell,solved:m(_.part,_.mesh,_.m,_.local)})),v=y.map(_=>_.solved),w=_=>_.filter(L=>L.faces.length>0&&L.opacity>.01).sort((L,j)=>L.depth-j.depth);let k;if(d){const _=new Map(t.parts.map(j=>{const V=o.get(j.id),tt=ua(j.shape).vertices;return[j.id,tt.reduce((J,F)=>J+n.toView(ae(V,F))[2],0)/Math.max(1,tt.length)]})),L=new Map;for(const j of y){const V=j.cell.join(",");L.has(V)||L.set(V,{cell:j.cell,parts:[]}),L.get(V).parts.push(j.solved),j.solved.depth=_.get(j.solved.part.id)}k=[...L.values()].map(({cell:j,parts:V})=>({depth:n.toView(ae(c,d.middle(j)))[2],parts:w(V)})).filter(j=>j.parts.length>0)}const S={};for(const[_,L]of Object.entries(t.anchors??{})){const j=L.part?o.get(L.part):ar(t,r);if(!j)throw new Error(`prop rig: anchor "${_}" is on "${L.part}", which is not a part`);const V=n.toView(ae(j,L.at));S[_]={point:n.toScreen(V),depth:V[2]}}const[x,M]=t.footprint??[t.length*.45,t.length],E=Math.max(0,Ot(t,r,"lift")),T=Math.max(0,Ot(t,r,"size"))/(1+E*.8),A=Array.from({length:24},(_,L)=>{const j=Math.PI*2*L/24;return n.toView([Math.cos(j)*x*.55*T,0,Math.sin(j)*M*.55*T])}),P=i.perspective?i.near:void 0,I={points:(P===void 0?A:Qy(A,P)).map(_=>n.toScreen(_)),opacity:.16*T},O=v.filter(_=>_.part.seeThrough&&_.opacity>.01).flatMap(_=>_.faces.map(L=>L.points));return{under:w(v.filter(_=>!_.part.overRider)),over:w(v.filter(_=>_.part.overRider)),...k?{cells:k}:{},anchors:S,openings:O,shadow:I,pxPerUnit:s,sizePx:t.height*s}}const u1=new WeakMap;function HE(t){let e=u1.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 r=s[i],o=s[(i+1)%s.length],a=r<o?`${r}-${o}`:`${o}-${r}`,l=e.get(a);l?l.push(n):e.set(a,[n])}}u1.set(t,e)}return e}function d1(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=Qh(t,n),i=ll(ar(t,n))??Or(),r=o=>Math.max(0,Math.min(1,o));return t.parts.map(o=>{const a=o.fade?r(Ot(t,n,o.fade.control)):0;return{part:o,matrix:s.get(o.id),local:Ft(i,s.get(o.id)),glow:o.glow?r(Ot(t,n,o.glow.control)):0,opacity:o.fade?r(o.fade.from+(o.fade.to-o.fade.from)*a):1}})}function f1(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=Qh(t,n),i=ar(t,n),r={};for(const[o,a]of Object.entries(t.anchors??{})){const l=a.part?s.get(a.part):i;if(!l)throw new Error(`prop rig: anchor "${o}" is on "${a.part}", which is not a part`);r[o]=ae(l,a.at)}return r}function FE(t,e){if(!t.walls)return!1;const[n,s]=e.split("-").map(r=>t.vertices[Number(r)]),i=(r,o)=>o.some(a=>Math.abs(n[r]-a)<1e-6&&Math.abs(s[r]-a)<1e-6);return i(0,t.walls.x)||i(2,t.walls.z)}function LE(t){return t.reduce((e,n)=>!e||n.length>e.length?n:e,void 0)}const NE=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2];function g1(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 r=0;r<e.length;r++){const[o,a]=e[r],l=s[s.length-1],c=s[0];if(o===l)s.push(a);else if(a===l)s.push(o);else if(a===c)s.unshift(o);else if(o===c)s.unshift(a);else continue;e.splice(r,1),i=!0;break}}n.push(s)}return n}function n0(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 s0(t){const e={};for(const[n,s]of Object.entries({...Ds,...t.rig.controls})){const{bind:i,...r}=s;e[n]=r}return e}function m1(t){const{prop:e}=t,n=t.scale??60,s=e.rig.length*n*1.4,i=e.rig.height*n*1.6,r=s0(e),o={};for(const[l,c]of Object.entries(r))o[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:o,prop:e,propScale:n,propDraw:a,about:{kind:e.kind,summary:e.summary,props:r,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),Zc(l,Bs(e,u,n),{...a,time:h,loose:n0(c,u)})}}}function Bs(t,e,n){const s=c1(Ot(t.rig,e,"turn"),Ot(t.rig,e,"tilt"),n);return e0(t.rig,e,s,n)}function da(t,e,n){const s={...t.props};let i=0,r=0;for(const[l,c]of e.state?.values.get(n)??[])typeof c=="number"&&(l==="x"?i=c:l==="y"?r=c:l in s&&(s[l]=c));const o={x:t.x+t.width/2+i,y:t.y+t.height+r},a=Bs(t.prop,s,t.propScale);return{values:s,origin:o,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:o.x+c.point.x,y:o.y+c.point.y,depth:c.depth}}}}function WE(t,e,n,s,i={}){const r=da(e,n,s);return t.save(),t.translate(r.origin.x,r.origin.y),Zc(t,r.solved,{...e.propDraw,time:n.time,loose:n0(e,r.values),rider:i.rider?o=>{o.save(),o.translate(-r.origin.x,-r.origin.y),i.rider(o),o.restore()}:void 0}),t.restore(),r}const zs={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"}},DE=400,BE=.2;function zE(t,e={}){const{prop:n}=t,s=s0(n),i=Object.keys(s),r=Object.keys(n.rig.anchors??{}),o=n.rig.parts.map(x=>x.id),a=_s(),l=Ui(a),c=e.tracks?.length?new Ht({id:`${n.kind}-surface`,tracks:e.tracks}):void 0,h=Math.max(0,...(e.tracks??[]).flatMap(x=>x.keyframes.map(M=>M.time))),u=new Map,d=new Map;t.loose=d;const f=t.props,m=x=>{const M={...t.props};let E=0,T=0;if(c){const A=c.getStateAtTime(Math.min(x,h));for(const P of A.values.values())for(const[I,O]of P)typeof O=="number"&&(I==="x"?E=O:I==="y"?T=O:I in M&&(M[I]=O))}for(const A of i)a.keys(A)?.length&&(M[A]=a.valueAt(A,x));return{values:M,origin:{x:t.x+t.width/2+E,y:t.y+t.height+T}}},g=x=>{const{kind:M,rest:E}=jn(x),T=A=>gn(n.kind,x,zs,A);if(M==="box"){if(E)throw T("box takes no arguments");return{kind:M}}if(M==="anchor"){if(!r.includes(E))throw T(dt(`${n.kind} anchor`,E,r));return{kind:M,name:E}}if(M==="part"){if(!o.includes(E))throw T(dt(`${n.kind} part`,E,o));return{kind:M,name:E}}if(M==="control"){if(!i.includes(E))throw T(dt(`${n.kind} control`,E,i));return{kind:M,name:E}}throw T()},p=x=>{const M=(n.rig.controls[x]?.bind??[]).flatMap(T=>T.parts),E=n.rig.parts.filter(T=>T.glow?.control===x).map(T=>T.id);return new Set([...M,...E])},y=new Map,v=x=>{let M=y.get(x);if(!M){const E=m(x);y.set(x,M={...E,solved:Bs(n,E.values,t.propScale)})}return M},w=(x,M)=>{const E=g(x),{values:T,origin:A,solved:P}=v(M);if(E.kind==="box")return St(A.x-t.width/2,A.y-t.height,t.width,t.height);if(E.kind==="anchor"){const _=P.anchors[E.name].point,L=BE*t.propScale;return St(A.x+_.x-L/2,A.y+_.y-L/2,L,L)}if(E.kind==="part")return O(new Set([E.name]),`part "${E.name}" is`);const I=p(E.name);if(I.size===0)return St(A.x-t.width/2,A.y-t.height,t.width,t.height);return O(I,`the parts control "${E.name}" moves are`);function O(_,L){const j=[...P.under,...P.over].filter(B=>_.has(B.part.id)).flatMap(B=>B.faces.flatMap(Y=>Y.points));if(j.length===0){const B=Number.isFinite(M)?`at ${M} ms`:"after its edits";throw new Error(`${n.kind}: ${L} turned away from the viewer ${B}; aim at an anchor (${r.map(Y=>`anchor:${Y}`).join(", ")||"none"}) or box`)}const V=j.map(B=>B.x),tt=j.map(B=>B.y),J=Math.min(...V),F=Math.min(...tt);return St(A.x+J,A.y+F,Math.max(...V)-J,Math.max(...tt)-F)}},k=(x,M)=>{try{return w(x,M)}catch{return}},S={kind:"prop",prop:t,about:zs,target:t,box:St(t.x,t.y,t.width,t.height),anchor(x,M=1/0){return w(x,M)},piece(x){const M=g(x);if(M.kind!=="part")throw new Error(`${n.kind}: a piece is a part, part:ID (${o.slice(0,6).map(P=>`part:${P}`).join(", ")}…), not "${x}"`);const E=u.get(M.name);if(E)return E;const T=[M.name];for(let P=0;P<T.length;P++)for(const I of n.rig.parts)I.parent===T[P]&&!T.includes(I.id)&&T.push(I.id);const A={id:u.size+1,part:M.name,home:w(x,0)};u.set(M.name,A);for(const P of T)d.set(P,A.id);for(const P of["x","y","rotate"])f[`piece.${A.id}.${P}`]=0;return f[`piece.${A.id}.opacity`]=1,A},edit(x,M,E){if(!(x in zs.edits))throw Vi(n.kind,x,zs);const T=Array.isArray(M)?M:[M];if(T.length===0)throw new Error(`${n.kind}.edit: ${x} takes at least one anchor`);if(y.clear(),x==="move"||x==="fling"){if(T.length>1)throw new Error(`${n.kind}.edit: ${x} takes one part anchor`);const A=S.piece(T[0]);if(x==="fling")return S.fling(A,E);const P=E.to;if(!P)throw new Error(`${n.kind}.edit: move needs \`to\`, an anchor name or { x, y }`);const I=typeof P=="string"?w(P,E.at):void 0;return S.move(A,{...E,to:I?{x:I.left+I.width/2,y:I.top+I.height/2}:P})}for(const A of T){const P=g(A);if(P.kind!=="control")throw new Error(`${n.kind}.edit: ${x} takes control anchors (control:${i.join(", control:")}), not "${A}"`);const I=s[P.name];let O;if(x==="set"){if(typeof E.value!="number"||!Number.isFinite(E.value))throw new Error(`${n.kind}.edit: set needs \`value\`, a number (${P.name}: ${I.description})`);O=E.value}else O=E.on===!1?I.default??I.min??0:I.max??1;a.tween(P.name,m(E.at).values[P.name],O,E,DE)}return S},follow(x,M){return y.clear(),l.follow(x,M),S},fling(x,M){return y.clear(),l.fling(x,M),S},move(x,M){return y.clear(),l.move(x,M),S},ride(x,M,E){const T=[...i.flatMap(P=>Rs(a.keys(P))),...(e.tracks??[]).flatMap(P=>Rs(P.keyframes.filter(I=>typeof I.value=="number")))];if(T.length===0)return x;const A=[...r.map(P=>`anchor:${P}`),...o.map(P=>`part:${P}`)].flatMap(P=>{const I=k(P,0);return I?[{top:I.top,offset:O=>(k(P,O)?.top??I.top)-I.top,windows:T}]:[]});return qo(x,M,{ground:E.ground,every:E.every??fn,floors:A})},tracks:a.tracks};return S}const qE={body:"#e8574a",trim:"#3b3b44",glass:"#bfe3f2",tyre:"#2c2c33",hub:"#c9ccd3",light:"#fff4b8",tail:"#ff5a4f",inside:"#3b3640",seat:"#6d5d55"};function Xe(t){const e={...qE,...t.colors},n=[],{forwardMost:s,backMost:i,top:r}=p1(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,m]of(t.cabin.pillars??[]).entries())n.push({id:`pillar-${f}`,shape:{type:"box",size:[h+.02,d-u,.1]},at:[0,(u+d)/2,m],fill:e.body,outline:.8,layer:1})}const o=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 m of d){const g=`wheel-${u}-${m>0?"left":m<0?"right":"middle"}`;if(a.push({parts:[g],rotate:{axis:"x",degrees:o/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:[m*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 p of m===0?[1,-1]:[m])n.push({id:`${g}-hub${m===0?p>0?"-left":"-right":""}`,parent:g,shape:{type:"cylinder",radius:h.radius*.55,length:.02,axis:"x",segments:14,spokes:5},at:[p*(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,m=[[h,d],[u,d],[u,f],[h,f]];for(const g of[1,-1]){const p=g>0?"left":"right";n.push({id:`doorway-${p}`,shape:{type:"panel",points:m,facing:g>0?"left":"right"},at:[g*(t.width/2+.004),0,0],fill:e.inside,outline:.5,seeThrough:!0});const y=h+(u-h)*.15,v=h+(u-h)*.55;n.push({id:`seat-back-${p}`,shape:{type:"panel",points:[[y,d+.05],[v,d+.05],[v-.08,f-.06],[y+.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-${p}`,shape:{type:"panel",points:m.map(([w,k])=>[w-u,k]),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:m}=t.lights,g=(t.lights.size??.32)/2,p=[[-g,u],[g,u],[g,d],[-g,d]];for(const y of[1,-1])n.push({id:`headlight-${y}`,shape:{type:"panel",points:p,facing:"front"},at:[y*h,0,f],fill:e.light,outline:.6,glow:{control:"lights",color:"#ffffff"}}),n.push({id:`taillight-${y}`,shape:{type:"panel",points:p,facing:"back"},at:[y*h,0,m],fill:Lo(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:r,footprint:[t.width,s-i],anchors:{...t.seat?{seat:{at:t.seat}}:{},front:{at:[0,r*.45,s]},back:{at:[0,r*.45,i]},roof:{at:[0,r,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:jE(t),acting:y1,colors:{body:e.body,ink:"#26262b"},follow:t.antenna?[{control:"antenna",of:"x",per:.9,stiffness:140,damping:7,limit:35}]:void 0,wheelRadius:o,...t.wheels.length>0?{moves:{drive:{speed:t.speed??6,perMetre:{wheelSpin:180/(Math.PI*o)}}}}:{}}}function p1(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 y1={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 fa(t,e,n,s,i,r,o=!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,o?l:l+c/r*(180/Math.PI),i)}const b1=.4;function jE(t){const e=t.wheels[0]?.radius??.4,{forwardMost:n,backMost:s}=p1(t),i=(n-s)/2,r=(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"}),fa(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},o=(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=r(a,c,h),d=a.exaggeration,f=Math.abs(l.to-a.x),m=l.for??Math.max(500,f/(l.speed??b1));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,m-160),{pitch:0,lean:.08*d,squash:1.02},{act:!1}),fa(a,u,u+m,l.to,"ease-in-out",e),o(a,u+m,!1),{end:u+m+380,contact:u,release:u+m}}},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=r(a,c,h),d=a.exaggeration,f=a.x,m=Math.abs(l.to-f),g=l.for??Math.max(600,m/(l.speed??b1*1.2)),p=u+g*.55,y=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"}),fa(a,u,p,y,"ease-in",e),a.key(p+80,{pitch:-7*d,lean:-.12*d,squash:.94},{act:!1,easing:"ease-out"}),fa(a,p,u+g,l.to,"ease-out",e,!0),a.effect({kind:"skid",time:p,x:y,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}),o(a,u+g,!0),{end:u+g+380,contact:p,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 w1(t={}){return Xe({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 k1(t={}){return Xe({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 v1(t={}){return Xe({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 M1(t={}){return Xe({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 S1(t={}){const e=t.colors?.body??"#a8743f";return Xe({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 T1(t={}){return Xe({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 E1(t={}){const e=t.colors?.body??"#e0473b",n=[0,.32,-.05],s=[0,.86,-.22],i=[0,.9,.42],r=[0,.34,.56],o=[0,.34,-.56];return Xe({kind:"bike",summary:"A bicycle: rides (drive) with its wire wheels turning, brakes, bumps, rings its bell (honk).",width:.5,frame:[{points:[o,n]},{points:[n,s]},{points:[s,o]},{points:[s,i]},{points:[n,i]},{points:[i,r]},{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 A1(t={}){return Xe({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 x1(t={}){const e=t.height??2.4,n=t.trunkRadius??.16,s=t.canopy?.radius??1.1,i=t.canopy?.shape==="tall",r={trunk:"#8a5a3b",leaves:"#5cae5a",...t.colors},o=Se(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:r.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:r.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:r.leaves}],l=t.canopy?.lobes??7;for(let h=0;h<l;h++){const u=Math.PI*2*h/l+o.next()*.6,d=(o.next()-.25)*s*(i?1.1:.7),f=s*(.48+o.next()*.22),m=[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:m,fill:r.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:KE(),acting:P1,colors:{body:r.leaves}}}const P1={depth:{sway:1,canopySway:2,size:0,squash:1},limits:{sway:2,canopySway:3,squash:.08},eyes:[],headTurns:{},drift:[]};function KE(){const t=(e,n,s,i)=>{const r=e.anchor("canopy");e.effect({kind:"leaves",time:n,x:r.x,y:r.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,r=n.for??3e3,o=e.exaggeration,a=260;let l=0;for(let c=a;c<r;c+=a){const h=.55+.45*Math.sin(c/r*Math.PI*2.3),u=Math.sin(c/170)*.35,d=-i*9*o*(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+r,{sway:0,canopySway:0}),i>.45)for(let c=0;c<r;c+=700)t(e,s+c,2200,1);return{end:s+r}}},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,r=e.exaggeration,o=6;for(let a=1;a<=o;a++){const l=1-a/(o+1),c=a%2===0?1:-1;e.key(s+i*a/(o+1),{sway:c*5*r*l,canopySway:-c*6*r*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 r=0;r<i;r+=500)t(e,s+r,2e3,r%1e3===0?1:-1);return{end:s+i}}}}}function $1(t={}){const e=t.width??4,n=t.depth??3.2,s=t.wallHeight??2.5,i=t.roofHeight??1.5,r=t.overhang??.25,o={walls:"#f1d9a8",roof:"#b8433a",door:"#7a4b2a",doorway:"#3a2a22",glass:"#bfe3f2",lit:"#ffd66b",chimney:"#9b5a45",...t.colors},a=n/2+.01,l=t.door?.width??.9,c=t.door?.height??1.9,h=t.door?.at??0,d=(t.door?.hinge??"left")==="left"?1:-1,f=h-d*l/2,m=-80*d*((t.door?.opens??"out")==="out"?1:-1),g=t.windows??[{at:-1.25,low:1,width:.8,height:.8},{at:1.25,low:1,width:.8,height:.8}],p=[{id:"walls",shape:{type:"box",size:[e,s,n]},at:[0,s/2,0],fill:o.walls},{id:"roof",shape:{type:"extrude",profile:[[-n/2-r,s],[n/2+r,s],[0,s+i]],width:e+r*2},fill:o.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:o.doorway,outline:.6,seeThrough:!0},{id:"door",shape:{type:"panel",points:[[0,0],[d*l,0],[d*l,c],[0,c]],facing:"front"},at:[f,0,a+.005],fill:o.door,outline:.8,overRider:!0}];g.forEach((w,k)=>{p.push({id:`window-${k}`,shape:{type:"panel",points:[[-w.width/2,w.low],[w.width/2,w.low],[w.width/2,w.low+w.height],[-w.width/2,w.low+w.height]],facing:"front"},at:[w.at,0,a+.01],fill:o.glass,outline:.8,glow:{control:"lights",color:o.lit}})});for(const w of[1,-1])p.push({id:`side-window-${w>0?"left":"right"}`,shape:{type:"panel",points:[[-.4,1],[.4,1],[.4,1.8],[-.4,1.8]],facing:w>0?"left":"right"},at:[w*(e/2+.01),0,0],fill:o.glass,outline:.8,glow:{control:"lights",color:o.lit}});const y=t.chimney===!1?void 0:{at:t.chimney?.at??e*.28,back:t.chimney?.back??-n*.18};if(y){const w=s+i*(1-Math.abs(y.back)/(n/2+r)),k=s+i+.45;p.push({id:"chimney",shape:{type:"box",size:[.42,k-w+.3,.42]},at:[y.at,(k+w-.3)/2,y.back],fill:o.chimney,layer:1})}const v={parts:p,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:m}}]},lights:{description:"The windows lit: 0 dark, 1 lit",unit:"0..1",min:0,max:1}},length:n+r*2,height:s+i+.6,footprint:[e+.6,n+.6],anchors:{door:{at:[h,c/2,a]},handle:{at:[f+d*(l-.12),c*.5,a+.02]},doorstep:{at:[h,0,a+.4]},ridge:{at:[0,s+i,0]},...y?{chimney:{at:[y.at,s+i+.5,y.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:v,actions:YE(!!y),acting:I1,colors:{body:o.walls}}}const I1={depth:{door:1,lights:0,roll:1,squash:1,size:0},limits:{door:.1,roll:1.5,squash:.05},eyes:[],headTurns:{},drift:[]};function YE(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,r=e.exaggeration;e.key(s+80,{squash:1-.06*r},{act:!1,easing:"ease-out"});for(let o=1;o<=5;o++){const a=1-o/6;e.key(s+80+i*o/6,{roll:(o%2===0?1:-1)*2.2*r*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,r=e.anchor("chimney");return e.effect({kind:"smoke",time:s,x:r.x,y:r.y,length:i+1500,direction:(n.wind??.4)>=0?1:-1}),{end:s+50,release:s+i}}}}:{}}}function O1(t={}){const e=t.width??.46,n=t.depth??.46,s=t.seatHeight??.46,i=t.backHeight??.95,r={wood:"#8a5a3b",seat:"#c48a4a",...t.colors},o=.05,a=.025,l=[{id:"seat",shape:{type:"box",size:[e,o,n]},at:[0,s-o/2,0],fill:r.seat},{id:"back",shape:{type:"box",size:[e,i-s,o]},at:[0,(i+s)/2,-n/2+o/2],fill:r.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-o,0]],radius:a,segments:6},at:[h*(e/2-a*1.5),0,u*(n/2-a*1.5)],fill:r.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:XE(),acting:C1,colors:{body:r.seat}}}const C1={depth:{tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.05},eyes:[],headTurns:{},drift:[]};function XE(){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 _1(t={}){const e=t.width??1.4,n=t.depth??.7,s=t.height??.75,i={wood:"#8a5a3b",top:"#a9754a",knob:"#2b2b2b",...t.colors},r=.04,o=.03,a=.14,l=e*.4,c=[{id:"top",shape:{type:"box",size:[e,r,n]},at:[0,s-r/2,0],fill:i.top},{id:"drawer",shape:{type:"box",size:[l,a,n*.8]},at:[-e/2+l/2+.05,s-r-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-r,0]],radius:o,segments:6},at:[u*(e/2-o*2),0,d*(n/2-o*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:R1,colors:{body:i.top}}}const R1={depth:{drawer:1,roll:1,squash:1,size:0},limits:{drawer:.08,roll:1,squash:.04},eyes:[],headTurns:{},drift:[]};function H1(t={}){const e=t.length??2,n=t.width??1,s=t.height??.55,i=t.headboard??.95,r={wood:"#8a5a3b",mattress:"#f1ece2",blanket:"#5b7fb0",pillow:"#fbf8f2",...t.colors},o=.3,a=s-o,c={parts:[{id:"frame",shape:{type:"box",size:[n,o,e]},at:[0,o/2,0],fill:r.wood},{id:"headboard",shape:{type:"box",size:[n+.06,i-o,.06]},at:[0,(i+o)/2,-e/2-.03],fill:r.wood},{id:"mattress",shape:{type:"box",size:[n-.04,a,e-.04]},at:[0,o+a/2,0],fill:r.mattress},{id:"blanket",parent:"mattress",shape:{type:"box",size:[n-.02,.04,e*.62]},at:[0,a/2+.02,e*.19],fill:r.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:r.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,m=h.exaggeration;return h.key(d+90,{give:1-.18*m},{act:!1,easing:"ease-out"}),h.key(d+f*.45,{give:1+.05*m},{act:!1,easing:"ease-in-out"}),h.key(d+f*.7,{give:1-.04*m},{act:!1,easing:"ease-in-out"}),h.key(d+f,{give:1}),{end:d+f,contact:d+90}}}},acting:F1,colors:{body:r.blanket}}}const F1={depth:{give:1,roll:1,squash:1,size:0},limits:{give:.03,roll:.5,squash:.03},eyes:[],headTurns:{},drift:[]};function L1(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},r=.1,o=s==="left"?1:-1,a=o>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:[r,n+r,r]},at:[e/2+r/2,(n+r)/2,0],fill:i.frame},{id:"post-right",shape:{type:"box",size:[r,n+r,r]},at:[-e/2-r/2,(n+r)/2,0],fill:i.frame},{id:"lintel",shape:{type:"box",size:[e+r*2,r,r]},at:[0,n+r/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:[o*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:[-o*(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:o*-95}}]}},length:.3,height:n+r,footprint:[e+r*2,.3],anchors:{handle:{part:"door",at:[-o*(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:GE(),acting:N1,colors:{body:i.door}}}const N1={depth:{open:1,roll:1,squash:1,size:0},limits:{open:.08,roll:.6,squash:.03},eyes:[],headTurns:{},drift:[]};function GE(){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,r=t.exaggeration;for(let o=0;o<3;o++){const a=n+i*(o+.5)/3;t.key(a,{open:.03*r},{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 W1=1.4;function D1(t={}){const e=t.width??.5,n=t.seatHeight??.5,s=t.wheelRadius??.3,i=.08,r={frame:"#2b2f36",seat:"#3c6ea5",tyre:"#1f2328",...t.colors},o=.04,a=.018,l=.44,c=n+.5,h=-.08,u=e/2+.06,d=[{id:"seat",shape:{type:"box",size:[e,o,l]},at:[0,n-o/2,0],fill:r.seat},{id:"back",shape:{type:"box",size:[e,c-n-.02,o]},at:[0,(c+n)/2,-l/2+o/2],fill:r.seat},{id:"footrest",shape:{type:"box",size:[e*.8,.02,.14]},at:[0,.12,l/2+.22],fill:r.frame}];for(const[g,p]of[[-1,"left"],[1,"right"]]){const y=g*u,v=(w,k,S=a)=>{d.push({id:w,shape:{type:"tube",points:k,radius:S,segments:6},fill:r.frame,outline:.7})};v(`post-${p}`,[[y,n-.1,-l/2],[y,c+.04,-l/2],[y,c+.04,-l/2-.14]]),v(`rail-${p}`,[[y,n-.03,-l/2],[y,n-.03,l/2]]),v(`leg-${p}`,[[y,n-.03,l/2],[y*.85,i,l/2+.06]]),v(`strut-${p}`,[[y*.85,i+.08,l/2+.04],[y*.8,.13,l/2+.22]]),v(`armrest-${p}`,[[y,n+.22,-l/2+.02],[y,n+.22,l/2-.08]],a*1.3),d.push({id:`wheel-${p}`,shape:{type:"cylinder",radius:s,length:.04,axis:"x",segments:20,spokes:8},at:[y+g*.03,s,h],ink:r.tyre,outline:1.3}),d.push({id:`rim-${p}`,shape:{type:"cylinder",radius:s*.9,length:.012,axis:"x",segments:20},at:[g*.045,0,0],parent:`wheel-${p}`,ink:r.frame,outline:.8}),d.push({id:`castor-${p}`,shape:{type:"cylinder",radius:i,length:.03,axis:"x",segments:12,spokes:3},at:[y*.85,i,l/2+.06],fill:r.tyre})}const f=d.map(g=>g.id).filter(g=>!g.startsWith("rim-")),m={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:m,actions:UE(s),acting:B1,colors:{body:r.seat,ink:r.frame},wheelRadius:s,moves:{roll:{speed:W1,perMetre:{wheelSpin:180/(Math.PI*s)}}}}}const B1={depth:{wheelSpin:0,tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.03},eyes:[],headTurns:{},drift:[]};function z1(t,e,n,s,i,r,o=!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,o?l:l+c/r*(180/Math.PI),i)}function UE(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 r=s;e.facing()!==i&&(r=e.turnTo(r,i>0?"right":"left"));const o=Math.abs(n.to-e.x),a=n.for??Math.max(300,o/(n.speed??W1*e.scale/1e3));return e.key(r+150,{tip:1.5*e.exaggeration},{act:!1,easing:"ease-out"}),z1(e,r,r+a,n.to,"ease-in-out",t),e.key(r+a,{tip:0},{easing:"ease-out"}),{end:r+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 r=n.for??500;return z1(e,s,s+r,n.to,"ease-out",t,!0),e.key(s+r,{tip:0},{easing:"ease-out"}),e.effect({kind:"dust",time:s+r*.5,x:n.to,y:e.floor,length:500}),{end:s+r,contact:s+r}}},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,r=n.for??1200;return e.key(s+300,{tip:i},{easing:"ease-out"}),e.key(s+300+r*.5,{tip:i*.9},{act:!1,easing:"ease-in-out"}),e.key(s+300+r,{tip:i},{act:!1,easing:"ease-in-out"}),e.key(s+300+r+250,{tip:0},{easing:"ease-in"}),e.effect({kind:"dust",time:s+300+r+250,x:e.x,y:e.floor,length:400}),{end:s+300+r+250,contact:s+300+r+250}}}}}function q1(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:VE(),acting:i0,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:15,flies:!0,hold:{blur:1},perSecond:{rotor:bn*1e3}}}}}const i0={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:[]},bn=2.6;function VE(){const t=(n,s,i,r,o)=>{const a=n.values.rotor??0;n.set("rotor",s,a);const l=o?r*(i-s)*.5:r*(i-s);n.set("rotor",i,a+l,o)},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 r=n.exaggeration,o=s.height??3;t(n,i,i+900,bn,"ease-in"),n.key(i+900,{blur:1},{act:!1,easing:"ease-in"}),n.key(i+700,{squash:1-.08*r},{act:!1,easing:"ease-in"});const a=i+1e3;return n.key(a+150,{squash:1+.06*r,lift:.3},{act:!1,easing:"ease-out"}),n.key(a+1300,{squash:1,lift:o,pitch:-4*r},{act:!1,easing:"ease-in-out"}),n.key(a+1700,{pitch:0}),t(n,i+900,a+1700,bn),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 r=n.exaggeration,o=Math.sign(s.to-n.x);let a=i;o!==0&&n.facing()!==o&&(a=n.turnTo(a,o>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*r,roll:6*r},{act:!1,easing:"ease-out"}),n.key(a+c-250,{pitch:-4*r,roll:3*r,lift:h},{act:!1}),n.key(a+c,{pitch:7*r,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,bn),{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 r=s.for??2e3,o=n.values.lift,a=n.exaggeration;for(let l=350,c=0;l<r;l+=350,c++)n.key(i+l,{lift:o+(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+r,{lift:o,roll:0},{act:!1,easing:"ease-in-out"}),(e(n)||o>0)&&t(n,i,i+r,bn),{end:i+r}}},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 r=n.exaggeration,o=i+Math.max(900,n.values.lift*450);return n.key(i+400,{pitch:3*r},{act:!1,easing:"ease-out"}),n.key(o,{lift:0,pitch:0,squash:1-.14*r},{act:!1,easing:"ease-in"}),n.key(o+280,{squash:1}),t(n,i,o,bn),t(n,o,o+1600,bn,"ease-out"),n.key(o+1600,{blur:0},{act:!1,easing:"ease-out"}),n.effect({kind:"dust",time:o,x:n.x,y:n.floor,length:800}),{end:o+1600,contact:o}}}}}function j1(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:ZE(),acting:i0,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:30,flies:!0,hold:{blur:1},perSecond:{rotor:bn*1e3}}}}}const JE=3.2;function ZE(){const t=(n,s,i,r)=>{const o=n.values.rotor??0;n.set("rotor",s,o),n.set("rotor",i,o+JE*(i-s)*(r?.5:1),r)},e=(n,s,i)=>{const r=Math.sign(i-n.x);return r!==0&&n.facing()!==r?n.turnTo(s,r>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 r=n.exaggeration,o=e(n,i,s.to);t(n,o,o+700,"ease-in"),n.key(o+700,{blur:1},{act:!1,easing:"ease-in"});const a=s.for??2600,l=n.x,c=o+700+a*.55,h=l+(s.to-l)*.45;return n.move(o+700,c,h,{easing:"ease-in"}),n.key(c,{pitch:8*r,squash:1+.04*r},{act:!1,easing:"ease-out"}),n.key(o+700+a,{lift:s.height??4,pitch:10*r,squash:1},{act:!1,easing:"ease-in-out"}),n.move(c,o+700+a,s.to),n.key(o+700+a+500,{pitch:0}),t(n,o+700,o+700+a+500),n.effect({kind:"dust",time:c,x:h,y:n.floor,length:700}),{end:o+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 r=n.exaggeration,o=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(o+350,{roll:10*r,pitch:l>n.values.lift?6*r:-3*r},{act:!1,easing:"ease-out"}),n.key(o+a-300,{roll:4*r,lift:l},{act:!1}),n.key(o+a,{roll:0,pitch:0}),n.move(o,o+a,s.to,{easing:"ease-in-out"}),t(n,i,o+a),{end:o+a,contact:o,release:o+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 r=s.for??2400,o=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,m=i+r*d/l;n.key(m,{lift:h+o*(1-Math.cos(f)),pitch:u+360*d/l},{act:!1}),n.move(i+r*(d-1)/l,m,c+a*(o*Math.sin(f)+d/l*o*1.2)*n.scale)}return n.key(i+r+1,{pitch:u},{act:!1}),t(n,i,i+r),{end:i+r+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 r=n.exaggeration,o=e(n,i,s.to),a=n.x,l=s.for??2200,c=o+l,h=a+(s.to-a)*.7;return n.key(o+l*.4,{pitch:-4*r},{act:!1,easing:"ease-out"}),n.key(c-250,{pitch:6*r,lift:.15},{act:!1,easing:"ease-in-out"}),n.key(c,{lift:0,pitch:0,squash:1-.12*r},{act:!1,easing:"ease-in"}),n.key(c+260,{squash:1}),n.move(o,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 qs=["walk","trot","canter","gallop"],QE=qs,K1=["fl","fr","hl","hr"],ga={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}},wn=Math.PI/180;function ma(t,e){return 4*t*Math.sin(ga[e].swing*wn)}function kn(t){const{legs:e,colors:n}=t,s=e.upper+e.lower+e.foot,i=s+t.body.rise,r=(u,d)=>[d*u[0],u[1],u[2]],o=[{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},...eA(t,n,i)];t.mane&&o.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&&o.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?r(t.ears.rotate,1).map((m,g)=>g===2?u*m:m):void 0;o.push({id:`ear-${d}`,parent:"head",shape:{type:"ellipsoid",radii:t.ears.radii,segments:8},at:r(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:r(t.eyes.at,u),fill:"#1d1d22",outline:.4})}o.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=>`${qs.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:$e,rotate:{axis:"x",degrees:1/$e.length}}]},wag:{description:"Tail swung side to side, curling",unit:"degrees",bind:[{parts:$e,rotate:{axis:"y",degrees:1/$e.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 K1){const d=u[0]==="f",f=u[1]==="l"?1:-1,m=d?e.thickness[0]:e.thickness[1];o.push({id:`${u}-upper`,shape:{type:"tube",points:[[0,e.upper*.2,0],[0,-e.upper*.5,0],[0,-e.upper,0]],radius:[m,m*.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:o,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=>nA(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:{...iA(t,h),...t.actions?.(h)},acting:o0,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:tA(t,s)}}function tA(t,e){const n=i=>{const r=ma(e,i);return{speed:r/(ga[i].cycle*(t.cycleScale??1)/1e3),set:{gait:qs.indexOf(i)},hold:{walking:1},perMetre:{walk:1/r}}},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 $e=Array.from({length:7},(t,e)=>e===0?"tail":`tail-${e}`);function eA(t,e,n){const s=lh(t.tail.points,$e.length+1),[,i,r]=t.body.radii,o=(t.tail.at[1]-n)/i,a=Math.abs(o)<1?-r*Math.sqrt(1-o*o):t.tail.at[2],l=[t.tail.at[0],t.tail.at[1],a+Math.min(.04,r*.08)],c=f=>t.tail.radius*(1-.5*f/$e.length),h=$e.map((f,m)=>{const g=s[m],p=s[m+1],y=[p[0]-g[0],p[1]-g[1],p[2]-g[2]],v=m===0?void 0:s[m-1];return{id:f,...m>0?{parent:$e[m-1]}:{},shape:{type:"tube",points:[[0,0,0],y],radius:[c(m),c(m+1)],segments:8,joined:!0},at:m===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:$e[$e.length-1],shape:{type:"ellipsoid",radii:Array(3).fill(c($e.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 nA(t,e,n){const s=Math.max(0,Math.min(1,t.walking??0));if(s===0)return{};const i=qs[Math.max(0,Math.min(3,Math.round(t.gait??0)))],r=ga[e.gaits.includes(i)?i:e.gaits[0]],o=t.walk??0,a={};for(const c of K1){const h=Math.PI*2*(o+r.offsets[c]);a[`${c}.swing`]=(t[`${c}.swing`]??0)+s*r.swing*Math.sin(h),a[`${c}.knee`]=(t[`${c}.knee`]??0)+s*r.lift*Math.max(0,Math.cos(h))}const l=Math.PI*2*o;return a.lift=(t.lift??0)+s*r.bob*n*Math.abs(Math.sin(l*2)),a.pitch=(t.pitch??0)+s*r.rock*Math.sin(l),a.neck=(t.neck??0)+s*(r.rock>0?-r.rock*1.4:5)*Math.sin(l*2),a}function r0(t){const n=Math.sin(32*wn),s=t.legLength-(t.front-t.hind)*n,i=72,o=(s-t.upper*Math.cos(i*wn)-t.foot)/t.lower,a=o>=1?0:o<=-1?180:Math.acos(o)/wn,l={pitch:32,lift:t.legLength*(1-Math.cos(32*wn))-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 o0={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:[]},sA=o0;function Y1(t){const e=(t.upper+t.lower)*.32,n=Math.asin(Math.min(1,e/(t.upper+t.lower+t.foot)))/wn,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 iA(t,e){const n=t.cycleScale??1,s=o=>({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."}[o],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 m=Math.abs(l.to-a.x)/a.scale/ma(e.legLength,o),g=l.for??Math.max(500,m*ga[o].cycle*n),p=a.values.walk??0;return a.set("gait",u,a.values.gait??0),a.set("gait",u+1,qs.indexOf(o)),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,p),a.move(u,u+g,l.to,{easing:"ease-in-out"}),a.set("walk",u+g,p+m,"ease-in-out"),a.key(u+g+300,{neck:0}),(o==="gallop"||o==="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(o=>[o==="gallop"&&!t.gaits.includes("canter")?"run":o,s(o)]));t.gaits.includes("gallop")&&!i.gallop&&(i.gallop=s("gallop"));const r={...i,[t.call]:{summary:`Throws its head up and ${t.call}s.`,run(o,a,l){const c=o.exaggeration;return o.key(l+150,{neck:10*c},{act:!1,easing:"ease-out"}),o.key(l+380,{neck:-28*c,squash:1.05},{act:!1,easing:"ease-out"}),o.key(l+680,{neck:-20*c},{act:!1}),o.key(l+980,{neck:0,squash:1}),e.call(o,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(o,a,l){const c=r0(e),h=l+450;o.key(h,c,{act:!1,easing:"ease-in-out"}),o.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 o.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(o,a,l){const c=Y1(e),h={...r0(e)},u=l+400,d=u+450;o.key(u,h,{act:!1,easing:"ease-in-out"}),o.key(d,c,{act:!1,easing:"ease-in-out"}),o.key(d+(a.for??2e3),c,{act:!1});const f=d+(a.for??2e3)+600,m={};for(const g of new Set([...Object.keys(c),...Object.keys(h)]))m[g]=0;return o.key(f,m),{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(o,a,l){const c=o.exaggeration,h=e.legLength*.8*c,u=l+260,d=u+90,f=d+520;if(o.key(u,{squash:.86,"hl.knee":40,"hr.knee":40,"fl.knee":25,"fr.knee":25,neck:8},{act:!1,easing:"ease-out"}),o.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"}),o.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"}),o.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"}),o.key(f+280,{squash:1,pitch:0,neck:0}),a.to!==void 0){const m=Math.sign(a.to-o.x);m!==0&&o.facing()!==m&&o.turnTo(l,m>0?"right":"left"),o.move(d,f,a.to)}return o.effect({kind:"dust",time:f,x:o.x,y:o.floor,length:550}),{end:f+280,contact:f}}},nod:{summary:"Nods its head twice.",run(o,a,l){return o.key(l+200,{neck:20},{act:!1,easing:"ease-out"}),o.key(l+400,{neck:-5},{act:!1,easing:"ease-in-out"}),o.key(l+600,{neck:18},{act:!1,easing:"ease-in-out"}),o.key(l+900,{neck:0}),{end:l+900}}},swish:{summary:"Swishes its tail a few times.",uses:["for"],run(o,a,l){const c=a.for??900;for(let h=1;h<=4;h++)o.key(l+c*h/5,{tail:h%2===0?10:35},{act:!1,easing:"ease-in-out"});return o.key(l+c,{tail:0}),{end:l+c}}}};return t.grazes&&(r.graze={summary:"Lowers its head to graze for `for` ms (default 1800), nibbling, then looks up.",uses:["for"],run(o,a,l){const c=a.for??1800;o.key(l+600,{neck:75},{act:!1,easing:"ease-in-out"});for(let h=900;h<600+c;h+=400)o.key(l+h,{neck:h%800===100?70:78},{act:!1,easing:"ease-in-out"});return o.key(l+600+c+500,{neck:0}),{end:l+600+c+500}}}),r}function X1(t={}){return kn({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 r=n.exaggeration,o=Math.min(55,32*r),a=-e.hind*Math.sin(o*wn),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:o,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 r=n.exaggeration,o=Math.min(35,18*r),a=e.front*Math.sin(o*wn);return n.key(i+220,{pitch:3,squash:.95},{act:!1,easing:"ease-out"}),n.key(i+480,{pitch:-o,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 G1(t={}){return kn({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 r=80,o=0;r<i;r+=80,o++)e.key(s+r,{wag:o%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 r=500,o=0;r<i;r+=140,o++)e.key(s+r,{neck:o%2===0?74:66},{act:!1});return e.key(s+i+300,{neck:0,pitch:0}),{end:s+i+300}}}})})}function U1(t={}){return kn({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 r=n.exaggeration,o=s.for??1200,a={squash:1+.25*r,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+o,a,{act:!1}),n.key(i+o+520,{squash:1,neck:0,tail:0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0}),{end:i+o+520,contact:i+180}}},pounce:{summary:"Crouches low, wiggles, and pounces to `to`, landing with a squash.",needs:["to"],run(n,s,i){const r=n.exaggeration,o=Math.sign(s.to-n.x);let a=i;o!==0&&n.facing()!==o&&(a=n.turnTo(a,o>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*r,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 V1(t={}){return kn({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 rA(t){return ma(1,t)}function J1(t={}){return kn({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 Z1(t={}){return kn({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 Q1(t={}){return kn({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 vn=.6,tb=75,a0=80;function Mn(t){const{colors:e}=t,[n,s,i]=t.body.radii,r=(t.tail.raised??15)*Math.PI/180,o=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]+o*Math.sin(r),t.tail.at[2]-o*Math.cos(r)],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*vn/2,t.wing.chord*.1,t.wing.chord/2],segments:12},at:[h*t.wing.span*vn/2,0,-t.wing.chord*.1],rotate:[-a0,0,0],fill:e.wing,outline:.8}),a.push({id:`wing-${u}-tip`,parent:`wing-${u}-blade`,shape:{type:"ellipsoid",radii:[t.wing.span*vn/2.4,t.wing.chord*.06,t.wing.chord*.3],segments:10},at:[h*t.wing.span*vn/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-vn)/2,0,0],rotate:{axis:"x",degrees:a0},scale:[1/vn,1,1]},{parts:["wing-right-blade"],translate:[-t.wing.span*(1-vn)/2,0,0],rotate:{axis:"x",degrees:a0},scale:[1/vn,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)/tb,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 m=Math.sin(Math.PI*2*(h.step??0));u["leg.left"]=(h["leg.left"]??0)+f*28*m,u["leg.right"]=(h["leg.right"]??0)-f*28*m,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:aA(t),acting:eb,colors:{body:e.body,ink:"#26262b"},moves:oA(t)}}function oA(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 eb={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 aA(t){const e=(t.beatsPerSecond??4)/1e3,n=(o,a,l)=>{const c=o.values.wingbeat??0;o.set("wingbeat",a,c),o.set("wingbeat",l,c+(l-a)*e)},s=(o,a,l)=>{const c=Math.sign(l-o.x);return c!==0&&o.facing()!==c?o.turnTo(a,c>0?"right":"left"):a},i=(o,a)=>{const l=o.anchor("beak");o.effect({kind:"honk",time:a,x:l.x,y:l.y,length:600,direction:o.facing()||1})},r={hop:{summary:"Hops to `to` in little bounces, wings twitching.",needs:["to"],run(o,a,l){const c=s(o,l,a.to),h=o.x,u=Math.abs(a.to-h),d=Math.max(1,Math.round(u/(t.body.radii[2]*3*o.scale))),f=260;for(let m=0;m<d;m++){const g=c+m*f;o.key(g+60,{squash:.85},{act:!1,easing:"ease-out"}),o.key(g+150,{squash:1.1,lift:t.legs.length*1.4,spread:.15},{act:!1,easing:"ease-out"}),o.key(g+f,{squash:.9,lift:0,spread:0},{act:!1,easing:"ease-in"}),o.move(g+60,g+f,h+(a.to-h)*(m+1)/d,{easing:"ease-in-out"})}return o.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(o,a,l){const c=s(o,l,a.to),h=Math.abs(a.to-o.x)/o.scale,u=t.legs.length*1.2,d=h/u,f=a.for??Math.max(400,d*420),m=o.values.step??0;return o.set("stepping",c,0),o.set("stepping",c+150,1,"ease-out"),o.set("stepping",c+f-150,1),o.set("stepping",c+f,0,"ease-in"),o.set("step",c,m),o.move(c,c+f,a.to,{easing:"ease-in-out"}),o.set("step",c+f,m+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(o,a,l){const c=a.for??900,h=Math.max(1,Math.round(c/300));o.key(l+120,{pitch:-(t.stoop??12)},{act:!1,easing:"ease-out"});for(let u=0;u<h;u++)o.key(l+120+u*300+90,{peck:tb},{act:!1,easing:"ease-in"}),o.key(l+120+u*300+260,{peck:20},{act:!1,easing:"ease-out"});return o.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(o,a,l){const c=a.for??900;return o.key(l+120,{spread:1},{act:!1,easing:"ease-out"}),o.set("flapping",l,0),o.set("flapping",l+150,1,"ease-out"),o.set("flapping",l+c-150,1),o.set("flapping",l+c,0,"ease-in"),n(o,l,l+c),o.key(l+c*.5,{lift:t.legs.length*.6},{act:!1,easing:"ease-out"}),o.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(o,a,l){return o.key(l+120,{peck:-25,squash:1.06},{act:!1,easing:"ease-out"}),o.key(l+500,{peck:-20},{act:!1}),o.key(l+760,{peck:0,squash:1}),i(o,l+150),{end:l+760,contact:l+150}}}};return t.flies!==!1?(r.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(o,a,l){const c=o.exaggeration;o.key(l+60,{grip:0},{act:!1});const h=s(o,l,a.to),u=a.height??2,d=a.for??Math.max(700,Math.abs(a.to-o.x)/.35),f=o.values.lift>t.legs.length,m=f?h:h+200;return f||(o.key(h+160,{squash:1-.18*c,spread:.6},{act:!1,easing:"ease-out"}),o.effect({kind:"dust",time:m,x:o.x,y:o.floor,length:400})),o.key(m+100,{spread:1,squash:1.08,pitch:10},{act:!1,easing:"ease-out"}),o.set("flapping",m,o.values.flapping??0),o.set("flapping",m+100,1,"ease-out"),o.set("flapping",m+d,.6),n(o,m,m+d),o.key(m+d*.4,{lift:u,pitch:-5,squash:1},{act:!1,easing:"ease-out"}),o.key(m+d,{lift:u,pitch:0},{act:!1,easing:"ease-in-out"}),o.move(m,m+d,a.to,{easing:"ease-in-out"}),{end:m+d,contact:m,release:m+d}}},r.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(o,a,l){let c=l;if(o.values.lift<=t.legs.length){const f=o.x+(a.to-o.x)/3;c=r.fly.run(o,{do:"fly",to:f,height:(a.height??1.5)*1.3},l).end}c=s(o,c,a.to);const h=o.values.lift,u=a.height??h*.67,d=a.for??Math.max(900,Math.abs(a.to-o.x)/.3);return o.set("flapping",c,o.values.flapping??1),o.set("flapping",c+250,0,"ease-out"),n(o,c,c+250),o.key(c+300,{spread:1,flap:10,pitch:-6},{act:!1,easing:"ease-out"}),o.key(c+d,{lift:u,pitch:-3,flap:10},{act:!1,easing:"ease-in-out"}),o.move(c,c+d,a.to,{easing:"ease-in-out"}),{end:c+d,contact:c,release:c+d}}},r.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(o,a,l){const h=a.height??0;return o.set("flapping",l,o.values.flapping??1),o.set("flapping",l+700-120,1),o.set("flapping",l+700,0,"ease-in"),n(o,l,l+700),o.key(l+700*.6,{pitch:14},{act:!1,easing:"ease-out"}),o.key(l+700,{lift:h,pitch:0,squash:.85,grip:h>0?1:0},{act:!1,easing:"ease-in"}),a.to!==void 0&&o.move(l,l+700,a.to,{easing:"ease-out"}),o.key(l+700+160,{squash:1,spread:0,flap:0}),{end:l+700+200,contact:l+700}}}):r.flutter={summary:"Flutters up a little way and back down, wings beating hard (a chicken’s flight).",run(o,a,l){return o.key(l+100,{spread:1,squash:.9},{act:!1,easing:"ease-out"}),o.set("flapping",l+80,0),o.set("flapping",l+160,1,"ease-out"),o.set("flapping",l+900-100,1),o.set("flapping",l+900,0,"ease-in"),n(o,l+80,l+900),o.key(l+900*.5,{lift:t.legs.length*2.5,squash:1.08},{act:!1,easing:"ease-out"}),o.key(l+900,{lift:0,squash:.85,spread:0},{act:!1,easing:"ease-in"}),o.key(l+900+160,{squash:1}),{end:l+900+160,contact:l+900}}},r}function nb(t={}){return Mn({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 sb(t={}){return Mn({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 ib(t={}){return Mn({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 rb(t={}){return Mn({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 ob(t={}){return Mn({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 ab(t={}){return Mn({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 lb(t={}){return Mn({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 js={car:w1,truck:k1,bus:v1,tractor:M1,cart:S1,trainCar:T1,bike:E1,motorbike:A1,tree:x1,house:$1,chair:O1,desk:_1,bed:H1,door:L1,wheelchair:D1,helicopter:q1,airplane:j1,horse:X1,dog:G1,cat:U1,cow:V1,goat:J1,rabbit:Z1,squirrel:Q1,songbird:nb,crow:sb,chicken:ib,pigeon:rb,duck:ob,owl:ab,parrot:lb};function l0(t,e={}){const n=js[t];if(!n)throw new Error(dt("prop preset",t,Object.keys(js)));return n(e)}const pa=["do","at","for","to","toward","speed","open","on","height","wind"],c0={viewer:0,right:1,away:2,left:3},lA=420,h0={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 ya(t){return{...h0,...t.actions}}const u0=t=>typeof t=="number"&&Number.isFinite(t);function cb(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=ya(e),s=Object.keys(n),i=[];return t.forEach((r,o)=>{const a=c=>i.push({level:"error",beat:o,message:c});if(!r||typeof r!="object"||Array.isArray(r))return a(`Each beat must be an object like { do: '${s[s.length-1]}' }.`);const l=r;for(const c of Object.keys(l))pa.includes(c)||a(dt("beat field",c,pa,c==="duration"?"for":c==="direction"?"toward":void 0));if(typeof l.do!="string"||!s.includes(l.do))return a(dt(`${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&&!(u0(l[c])&&l[c]>=0)&&a(`\`${c}\` must be a number ≥ 0 (got ${JSON.stringify(l[c])}).`);if(l.to!==void 0&&!u0(l.to)&&a(`\`to\` is a scene x in px (got ${JSON.stringify(l.to)}).`),l.toward!==void 0&&!u0(l.toward)&&!(typeof l.toward=="string"&&l.toward in c0)){const c=typeof l.toward=="string"?ai(l.toward,Object.keys(c0)):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 hb(t,e,n,s={}){const i=cb(n,e).filter(T=>T.level==="error");if(i.length>0)throw new Error(`propScript (${e.kind}): ${i.length} problem(s) in the beats:
|
|
63
63
|
${i.map(T=>` beat ${T.beat}: ${T.message}`).join(`
|
|
64
|
-
`)}`);const r=s.from??0,o=s.ground??0,a=s.scale??60,l=s.exaggeration??1,c=ya(e),h={};for(const T of[...Object.keys(Ds),...Object.keys(e.rig.controls)])h[T]=s.start?.[T]??Ot(e.rig,{},T);const u=[{time:0,pose:{...h}}],d=new Map,f=[];let m=r,g=o;const p=(T,A,P,I)=>{const O=d.get(T)??[{time:0,value:T==="x"||T==="y"?0:h[T]}];O.push({time:A,value:P,...I?{easing:I}:{}}),d.set(T,O),T!=="x"&&T!=="y"&&(h[T]=P)},b=(T,A)=>{const P=T==="x"?m-r:T==="y"?g-o:h[T],I=d.get(T);(!I||I[I.length-1].time<A)&&p(T,A,P)},v={prop:e,scale:a,exaggeration:l,get x(){return m},get floor(){return g},values:h,facing(){const T=Math.sin(h.turn*Math.PI/2);return Math.abs(T)<.5?0:T>0?1:-1},key(T,A,P={}){Object.assign(h,A),u.push({time:T,pose:{...h},...P.act===!1?{act:!1}:{},...P.easing?{easing:P.easing}:{}})},move(T,A,P,I={}){b("x",T),p("x",A,P-r,I.easing),m=P,I.floor!==void 0&&(b("y",T),p("y",A,I.floor-o,I.easing),g=I.floor)},set(T,A,P,I){p(T,A,P,I)},turnTo(T,A){const P=typeof A=="number"?A:c0[A],I=h.turn,_=[P-4,P,P+4].map(j=>({t:j,d:Math.abs(j-I)})).sort((j,V)=>j.d-V.d||Math.abs(j.t)-Math.abs(V.t))[0];if(_.d<.001)return T;const L=T+lA*Math.max(1,_.d);return v.key(L,{turn:_.t}),L},effect(T){f.push(T)},anchor(T){const P=Bs(e,h,a).anchors[T];if(!P)throw new Error(`${e.kind}: no anchor "${T}"`);return{x:m+P.point.x,y:g+P.point.y}}},k=[];let w=0;for(const T of n){const A=Math.max(T.at??w,u[u.length-1].time),P=c[T.do].run(v,T,A);P.end>u[u.length-1].time&&u.push({time:P.end,pose:{...h}}),k.push({start:A,end:P.end,...P.contact!==void 0?{contact:P.contact}:{},...P.release!==void 0?{release:P.release}:{}}),w=P.end}const S=xh(s.style??"snappy"),x={...S,anticipation:S.anticipation*l,overshoot:S.overshoot*l},M=Uo(dA(u),e.acting,{style:x}),E=[...Object.entries(M).filter(([T])=>!d.has(T)).map(([T,A])=>({id:`${t}-${T}`,target:t,property:T,keyframes:A})),...[...d].map(([T,A])=>({id:`${t}-${T}`,target:t,property:T,keyframes:fA(A)}))];for(const T of hA(t,e,E,w,u[0].pose)){const A=E.findIndex(O=>O.property===T.property);if(A<0){E.push(T);continue}const P=new Ht({id:`${t}-own`,tracks:[E[A]]}),I=O=>Number(P.getStateAtTime(O).values.get(t)?.get(T.property)??0);E[A]={...T,keyframes:T.keyframes.map(O=>({time:O.time,value:Number(O.value)+I(O.time)}))}}return{tracks:E,duration:w,beats:k,effects:f}}const cA=1500;function hA(t,e,n,s,i){if(!e.follow?.length)return[];const r=new Ht({id:`${t}-follow`,tracks:n.filter(a=>a.property==="turn"||e.follow.some(l=>l.of===a.property))}),o=(a,l)=>{const c=r.getStateAtTime(a).values.get(t)?.get(l);return typeof c=="number"?c:i[l]??0};return e.follow.map(a=>{const l=s+cA,c=li(d=>o(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 m=Math.sin(o(d,"turn")*Math.PI/2),g=(f-o(d,a.of))*m;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 uA=20;function dA(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<uA?n[n.length-1]={...s,time:i.time}:n.push(s)}return n}function fA(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 Ge=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."})}),d0=Object.freeze({adults:"Adults",men:"Men",children:"Children",mixed:"Mixed cast"}),Ks=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"}),Zn=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 ve(t,e,n){if(!Object.prototype.hasOwnProperty.call(t,e))throw new Error(`${n}: unknown choice '${e}'`);return e}const Rt=(t,e,n)=>Math.max(0,Math.min(1,(t-e)/(n-e))),Nt=t=>t*t*(3-2*t),At=(t,e)=>ci(t,e),f0=(t,e)=>Pn(t,e);function g0(t,e){const n=e+((t-e+2)%4+4)%4-2;return n===0?0:n}function Ys(t,e,n=0){return Math.hypot(e[0]-t[0],e[2]-t[2])<.001?n:g0(Math.atan2(e[0]-t[0],e[2]-t[2])*2/Math.PI,n)}function ub(){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 m0(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:Ps({...n.character,height:n.height??1.78})}}function db(t){return{position:[...t.object.position??[0,0,0]],pose:{...lt,...t.object.pose}}}function Xs(t,e,n,s){const i=cn(t.who.plan,e.pose,{height:t.who.height,contact:t.who.contact});return At(e.position,i.chains[n][s])}function lr(t,e,n){const s=Xs(t,e,`arm.${n}`,2),i=Xs(t,e,`arm.${n}`,1);return At(s,f0(Qt(oe(s,i)),t.who.lineWidth*.5))}function gA(t,e,n){const s={...e.pose,"head.turn":0,"head.nod":0,"head.tilt":0},i=cn(t.who.plan,s,{height:t.who.height,contact:t.who.contact}).head,r=oe(n,At(e.position,i.center)),o=i.axes.map(c=>We(r,c)),a=Math.atan2(o[0],o[2])*180/Math.PI,l=Math.atan2(-o[1],Math.hypot(o[0],o[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 Sn(t,e,n,s,i="hold"){let r={...e.pose};for(let o=0;o<10;o++){const a={...e,pose:r},l=cn(t.who.plan,r,{height:t.who.height,contact:t.who.contact}),c=ms(t.who.plan,r,t.who.height),h=oe(lr(t,a,n),Xs(t,a,`arm.${n}`,2)),u=oe(oe(oe(s,h),e.position),l.hip),d=$i(u,(r.roll??0)*Math.PI/180),f=At(c.root,ee(d,-(r.turn??0)*Math.PI/2));r=Oi(t.who.plan,r,`arm.${n}`,f,{height:t.who.height})}for(const[o,a]of Object.entries(Tt[i]))r[`hand.${n}.${o}`]=a;return{...e,pose:r}}function mA(t,e,n,s){const i=Qt(s),r=t.who.height/1.78;let o=Sn(t,e,"left",n);return o=Sn(t,o,"right",At(lr(t,o,"left"),f0(i,.105*r))),{...o,bat:{grip:lr(t,o,"left"),axis:i,scale:r}}}function pA(t){return At(t.grip,f0(t.axis,.51*t.scale))}function fb(t){const e=Qt(t),n=Math.max(-1,Math.min(1,e[1]));return n>.999999?[0,0,0,1]:n<-.999999?Zt([1,0,0],180):Zt(Qt(hi([0,1,0],e)),Math.acos(n)*180/Math.PI).map(s=>s===0?0:s)}function ba(t,e,n){const s={};for(const i of Object.keys({...t,...e})){const r=t[i]??lt[i]??0;s[i]=r+((e[i]??lt[i]??0)-r)*n}return s}function p0(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 ba({...lt,...e[n-1][1]},{...lt,...e[n][1]},Nt(Rt(t,e[n-1][0],e[n][0])));return{...lt,...e.at(-1)[1]}}function Ue(t,e){if(!Array.isArray(t)||t.length!==3||!t.every(Number.isFinite))throw new Error(`${e}: expected three finite coordinates`)}function gb(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(r=>r>=t&&r<=e&&Number.isFinite(r))]);for(let r=t+n;r<e;r+=n)i.add(r);return[...i].sort((r,o)=>r-o)}function y0(t,e){if(mb(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],r=t.to[2]-t.from[2],o=Math.hypot(i,r)||1;return[t.from[0]+i*n-r/o*(t.curve??0)*s,t.from[1]+(t.to[1]-t.from[1])*n+(t.arc??0)*s,t.from[2]+r*n+i/o*(t.curve??0)*s]}function mb(t){if(!t.target?.trim())throw new Error("ballFlight: target is required");if(Ue(t.from,"ballFlight.from"),Ue(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 yA(t){mb(t);const e=gb(t.start,t.end,t.every),n=e.map(s=>y0(t,s));return["x","y","z"].map((s,i)=>({id:`${t.id??"flight"}-${s}`,target:t.target,property:s,keyframes:e.map((r,o)=>({time:r,value:n[o][i]}))}))}const cr=Object.freeze({"front-foot":Object.freeze({name:"Front-foot review",summary:"A fixed side view of the landing front foot and bowler’s popping crease at release."}),"striker-crease":Object.freeze({name:"Striker crease",summary:"A fixed side view of the striker’s popping crease, wicket and keeper arrival."}),"bowler-crease":Object.freeze({name:"Bowler crease",summary:"A fixed side view of the other crease and wicket for a running batter and return throw."})});function b0(t){return Object.prototype.hasOwnProperty.call(cr,t)}function wa(t,e){if(!b0(e))return;const n=i=>t.events.find(r=>r.id===i),s=e==="front-foot"?n("release"):e==="bowler-crease"?t.action==="run-out"?n("wicket"):n("run")??n("release"):(t.action!=="run-out"?n("wicket"):void 0)??n("run")??n("keeper")??n("return")??t.events.find(i=>i.kind==="contact");if(s){if(!Number.isFinite(s.time)||s.time<0||s.time>t.duration)throw new Error("cricketCameraReview: event time must be within the clip");return{...s}}}function ka(t,e,n){const s=m0(t.scene,e),i=db(s);for(const r of t.timeline.tracks){if(r.target!==t.scene.id+"/"+e)continue;if(!("keyframes"in r))throw new Error("cricketCamera: review requires baked actor tracks");const o=new nn(r).getValueAtTime(n);if(typeof o!="number"||!Number.isFinite(o))continue;const a=["x","y","z"].indexOf(r.property);a>=0?i.position[a]=o:i.pose[r.property]=o}return{actor:s,sample:i}}function pb(t){const e=wa(t,"front-foot");if(!e)throw new Error("cricketCamera: front-foot view requires a release event");const{actor:n,sample:s}=ka(t,"bowler",e.time);return{point:Xs(n,s,"leg.right",2),height:n.who.height}}function yb(t,e){const n=e==="striker-crease"?"striker":"bowler",s=t.landmarks[n+"-crease"];return Ue(s,"cricketCamera.crease"),[...s]}function bA(t,e){if(!b0(e))return[];const n=yb(t,e),s=e==="front-foot"?pb(t).point[0]:0;return[{id:"decision-review-"+e,name:cr[e].name+": crease reference",kind:"line",color:"#f4b83f",width:.035,points:[[s-1.1,.045,n[2]],[s+1.1,.045,n[2]]]}]}function w0(t,e,n,s){const i=e*Math.PI/180,r=n*Math.PI/180;return[t[0]+s*Math.cos(r)*Math.sin(i),t[1]+s*Math.sin(r),t[2]+s*Math.cos(r)*Math.cos(i)]}const k0=(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 wA(t,e,n){const s={target:[0,0,0],yaw:0,pitch:15,distance:8,...t},i={...s,...e},r=k0(s.target,i.target,n),o=s.position||i.position?k0(s.position??w0(s.target,s.yaw,s.pitch,s.distance),i.position??w0(i.target,i.yaw,i.pitch,i.distance),n):w0(r,s.yaw+(i.yaw-s.yaw)*n,s.pitch+(i.pitch-s.pitch)*n,s.distance+(i.distance-s.distance)*n),a=k0(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:o,lookAt:a,fov:l}}function kA(t){const e=Math.max(1,t.every??33),n=Dt(t.easing??"ease-in-out"),s=`${t.scene}/${t.camera}`,i=[],r=[],o=[];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=wA(t.from,t.to,c);if(i.push({time:l,value:h.position}),r.push({time:l,value:h.lookAt}),h.fov!==void 0&&o.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:r}];return o.length>0&&a.push({id:`${s}-move-fov`,target:s,property:"fov",keyframes:o}),a}function vA(t){const e=Math.max(1,t.every??33),n=t.offset??[0,2,6],s=t.lag??0,i=`${t.scene}/${t.camera}`,r=[],o=[];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(r.push({time:a,value:[c[0]+n[0],c[1]+n[1],c[2]+n[2]]}),o.push({time:a,value:l}),a>=t.end)break}return[{id:`${i}-follow-position`,target:i,property:"position",keyframes:r},{id:`${i}-follow-lookAt`,target:i,property:"lookAt",keyframes:o}]}const va=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",...Object.fromEntries(Object.entries(cr).map(([t,e])=>[t,e.name]))}),Ma=Object.freeze({pitch:75,batter:145,bowler:35,keeper:145,field:75,overhead:75,orbit:75,"follow-ball":75,"front-foot":90,"striker-crease":90,"bowler-crease":90});function bb(t,e="pitch"){const n=ve(va,e,"cricketCamera.view");if(b0(n)){const i=yb(t,n);if(n==="front-foot"){const c=pb(t);return{target:[c.point[0],.12,(c.point[2]+i[2])/2],pitch:25,distance:Math.max(2.2,2.6*c.height/1.78),fov:40}}const r=t.landmarks[n==="striker-crease"?"striker-wicket":"bowler-wicket"];Ue(r,"cricketCamera.wicket");let o=(i[2]+r[2])/2,a=4;if(t.action==="run-out"&&n==="bowler-crease"||t.action==="running"){const c=wa(t,n);if(c){const u=ka(t,n==="bowler-crease"?"batter":"non-striker",c.time).sample.position;o=(Math.min(i[2],r[2],u[2])+Math.max(i[2],r[2],u[2]))/2,a=Math.max(4,Math.abs(r[2]-u[2])*1.8)}}let l=0;if(n==="striker-crease"&&t.action==="wide"){const c=wa(t,n);if(c){const h=ka(t,"keeper",c.time).sample.position,u=ka(t,"batter",c.time).sample.position,d=Math.min(i[0],r[0],h[0],u[0]),f=Math.max(i[0],r[0],h[0],u[0]),m=Math.min(i[2],r[2],h[2],u[2]),g=Math.max(i[2],r[2],h[2],u[2]);l=(d+f)/2,o=(m+g)/2,a=Math.max(4,Math.hypot(f-d,g-m)*1.8)}}return{target:[l,.42,o],pitch:12,distance:a,fov:44}}if(n==="follow-ball"){const i=t.scene.objects.find(r=>r.id==="camera"&&r.kind==="camera");return{pitch:Math.atan2(3,Math.hypot(5,6))*180/Math.PI,distance:Math.sqrt(70),fov:i?.kind==="camera"&&i.projection==="perspective"?i.fov:48}}const s=n==="field"||n==="overhead"||n==="orbit";return{target:n==="batter"?[.1,.85,9.3]:n==="bowler"?[.68,1,-9.55]:n==="keeper"?[0,.7,10.1]:[0,.65,0],distance:s?t.boundaryRadius*2.8:n==="pitch"?29:4.3,pitch:n==="overhead"?89:s?52:n==="pitch"?16:12,fov:s?48:n==="pitch"?50:46}}function v0(t,e,n,s){if(t!==void 0&&(!Number.isFinite(t)||t<e||t>n))throw new Error("cricketCamera: "+s+" must be between "+e+" and "+n)}function MA(t,e={}){const n=ve(va,e.view??"pitch","cricketCamera.view"),s=e.yaw??Ma[n];if(!Number.isFinite(s))throw new Error("cricketCamera: yaw must be finite");const i=(s%360+360)%360,r=e.zoom??1;if(!Number.isFinite(r)||r<.25||r>4)throw new Error("cricketCamera: zoom must be between 0.25 and 4");const o=g=>r===1?g:Math.atan(Math.tan(g*Math.PI/360)/r)*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(v0(e.pitch,0,89,"pitch"),v0(e.distance,.5,2e3,"distance"),v0(e.fov,10,100,"fov"),e.target!==void 0&&(Ue(e.target,"cricketCamera.target"),n==="follow-ball"))throw new Error("cricketCamera: target override is not supported by follow-ball");const l=bb(t,n),c=e.pitch??l.pitch,h=e.distance??l.distance,u=o(e.fov??l.fov),d=e.target?[...e.target]:l.target??[0,0,0],f=t.scene.id+"/camera",m=g=>{if(e.distance===void 0&&e.target===void 0)return g;const p=g.find(k=>k.property==="position");if(!p||!("keyframes"in p))return g;const b=t.scene.objects.find(k=>k.id==="camera"&&k.kind==="camera");let v=b?.kind==="camera"?Math.max(600,b.far):600;for(const k of p.keyframes)v=Math.max(v,Math.hypot(...k.value)+t.boundaryRadius+10);if(!Number.isFinite(v))throw new Error("cricketCamera: framing exceeds finite camera range");return[...g,{id:f+"-framing-far",target:f,property:"far",keyframes:[{time:0,value:v},{time:t.duration,value:v}]}]};if(n==="follow-ball"){const g=["x","y","z"].map(w=>{const S=t.timeline.tracks.find(T=>T.target===t.scene.id+"/ball"&&T.property===w);if(!S||!("keyframes"in S)||!S.keyframes.length)throw new Error("cricketCamera: missing ball "+w+" keyframes");const x=S.keyframes;let M=0,E=new nn({...S,keyframes:x.slice(0,2)});return T=>{const A=M;for(;M<x.length-2&&T-(S.delay??0)>x[M+1].time;)M++;return M!==A&&(E=new nn({...S,keyframes:x.slice(M,M+2)})),E.getValueAtTime(T)}}),p=(Math.atan2(5,6)*180/Math.PI+i-Ma["follow-ball"])*Math.PI/180,b=c*Math.PI/180,v=i===Ma["follow-ball"]&&(e.pitch===void 0||e.pitch===l.pitch)&&(e.distance===void 0||e.distance===l.distance)?[5,3,6]:[Math.sin(p)*Math.cos(b)*h,Math.sin(b)*h,Math.cos(p)*Math.cos(b)*h],k=vA({scene:t.scene.id,camera:"camera",start:0,end:t.duration,every:a,offset:v,subjectAt:w=>g.map(S=>S(w))});return m([...k,{id:f+"-zoom-fov",target:f,property:"fov",keyframes:[{time:0,value:u},{time:t.duration,value:u}]}])}return m(kA({scene:t.scene.id,camera:"camera",start:0,end:t.duration,every:a,easing:"linear",from:{target:d,yaw:i,pitch:c,distance:h,fov:u},to:{yaw:n==="orbit"?i+360:i}}))}const Sa=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 SA(t){const[e,n]=t.centres,s=Math.hypot(n[0]-e[0],n[2]-e[2]),i=(n[0]-e[0])/s,r=(n[2]-e[2])/s,o=[];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;o.push([l[0]+r*u+i*d,.018,l[2]-i*u+r*d])}}return o}function wb(t,e){Ue(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;Ue(s,"cricketFieldingAreaContains.centre"),Ue(i,"cricketFieldingAreaContains.centre");const r=i[0]-s[0],o=i[2]-s[2],a=r*r+o*o,l=a?Math.max(0,Math.min(1,((e[0]-s[0])*r+(e[2]-s[2])*o)/a)):0;return Math.hypot(e[0]-s[0]-l*r,e[2]-s[2]-l*o)<=n.radius+1e-9}function kb(t){return Object.keys(Ks).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??Ks[e],position:s,inside:wb(t,s)}]})}function TA(t){return t.fieldingArea?kb(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 Yt=Object.freeze({length:20.12,width:3.05,poppingCrease:1.22,returnCrease:1.32,stumpHeight:.711,wicketWidth:.2286});function vb(t){if(!t.id?.trim())throw new Error("cricketPlayer: id is required");ve({batter:1,bowler:1,keeper:1,fielder:1,umpire:1},t.role,"cricketPlayer.role");const e=ve(tr,t.preset??"youngMan","cricketPlayer.preset"),n=ve(Ge,t.format??"t20","cricketPlayer.format"),s=ve({none:1,cap:1,"sun-hat":1},t.headwear??"none","cricketPlayer.headwear"),i=e==="childBoy"||e==="childGirl",r=t.height??(i?1.24:1.78);if(!Number.isFinite(r)||r<.5||r>3)throw new Error("cricketPlayer: height must be between .5 and 3 metres");Ue(t.position??[0,0,0],"cricketPlayer.position");const o=t.role==="umpire"?"#f5ebd5":n==="test"?"#f5f0df":t.color??"#3577b5",a=JSON.parse(JSON.stringify({...tr[e],...t.appearance,outfit:ay("casual",{top:"shirt",shirt:o,trousers:t.role==="umpire"?"#405058":o,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:o}}));return{id:t.id,name:t.role,kind:"character",look:"pen",height:r,position:[...t.position??[0,0,0]],character:a,pose:t.role==="batter"?ub():{turn:t.role==="keeper"?2:0}}}function Ta(t,e,n,s,i=0){return{id:t,kind:"mesh",position:e,geometry:{type:"box",size:n},material:s,layer:i}}function EA(t,e){const n=Yt.stumpHeight,s=(Yt.wicketWidth-.036)/2;return[...[-1,0,1].map((i,r)=>({id:`${t}-stump-${r}`,kind:"mesh",position:[i*s,n/2,e],geometry:{type:"cylinder",radius:.018,height:n,segments:10},material:"wicket"})),...[-1,1].map((i,r)=>Ta(`${t}-bail-${r}`,[i*s/2,n+.015,e],[.105,.025,.035],"bail"))]}function Mb(t,e){return[{id:t,kind:"group",scale:e,visible:!1},Ta(`${t}-grip`,[0,.1,0],[.036,.28,.036],"bat-grip"),Ta(`${t}-blade`,[0,.51,0],[.108,.54,.055],"bat-blade"),Ta(`${t}-label`,[0,.41,.029],[.07,.16,.004],"bat-label")].map((s,i)=>i===0?s:{...s,parent:t})}function M0(t={}){const e=ve(Ge,t.format??"t20","cricketField.format"),n=ve(d0,t.cast??"adults","cricketField.cast"),s=ve(Sa,t.markingProfile??"icc-men","cricketField.markingProfile"),i=Sa[s],r=t.boundaryRadius??64;if(!Number.isFinite(r)||r<24||r>250)throw new Error("cricketField: boundaryRadius must be between 24 and 250 metres");const o=t.id??"cricket";if(!o.trim())throw new Error("cricketField: id is required");const a=Yt.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-Yt.poppingCrease],"bowler-crease":[0,0,-a+Yt.poppingCrease]},h=[{id:"camera",kind:"camera",projection:"perspective",position:[25,9,6],lookAt:[0,.65,0],fov:48,near:.02,far:Math.max(600,r*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:r+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:[Yt.width,Yt.length]},position:[0,.008,0],material:"pitch"},{id:"boundary",kind:"line",layer:-1,closed:!0,width:.15,color:"#f8f2db",points:Array.from({length:96},(m,g)=>[Math.cos(g*Math.PI/48)*r,.022,Math.sin(g*Math.PI/48)*r])}];l&&h.push({id:"fielding-circle",kind:"line",layer:-1,closed:!0,width:.06,color:"#d6e4c8",points:SA(l)});for(const m of[-1,1]){const g=m>0?"striker":"bowler",p=m*a,b=p-m*Yt.poppingCrease;h.push(...EA(g,p));const v=(k,w)=>h.push({id:`${g}-${k}`,kind:"line",layer:-1,color:"#fffdf0",width:.045,points:w});v("popping-line",[[-i.poppingCreaseHalfWidth,.02,b],[i.poppingCreaseHalfWidth,.02,b]]),v("bowling-line",[[-1.32,.02,p],[1.32,.02,p]]);for(const k of[-1,1])v(`return-line-${k<0?"left":"right"}`,[[k*1.32,.02,b],[k*1.32,.02,p+m*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(([m,g,p],b)=>{const v=n==="children"||n==="mixed"&&b%3===0,k=n==="men"?"youngMan":v?b%2?"childGirl":"childBoy":b%2?"youngWoman":"youngMan",w=Math.hypot(p[0],p[2]),S=w>r*.88?[p[0]*r*.88/w,0,p[2]*r*.88/w]:[...p];c[m]=[...S];const x=vb({id:m,role:g,preset:k,format:e,position:S,color:g==="batter"?t.battingColor??"#397cb9":t.fieldingColor??"#bf604e"});if(Object.hasOwn(Ks,m)&&(x.name=Ks[m]),m!=="batter"){const M=m==="non-striker"||m==="bowler"?u[0][2]:u.find(([E])=>E==="bowler")[2];x.pose={turn:Ys(S,M)}}h.push(x)});const d=m=>h.find(g=>g.id===m).height/1.78;h.push(...Mb("bat",d("batter")),...Mb("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=m=>({color:m,shading:"toon",outline:{color:"#69513a",width:.8}});return{format:e,boundaryRadius:r,landmarks:c,markingProfile:s,fieldingArea:l,scene:{id:o,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 Xt=1900,hr=2450,xt=2900,ur=4100,Tn=4200,Gs=4600,Ea=5300,S0=5500;function Aa(t,e,n,s,i,r,o=t.object.pose?.turn??0){const a=Rt(e,n,s),l=ui(i,r),c=Ys(i,r,o),h=o+(c-o)*Nt(Rt(e,n,n+200)),u={...lt,...t.object.pose,turn:h},d=Mo("run",t.who.height,1,t.object.character?.legLength??1),f=vo("run",l*a/d,u),m=Math.min(a*12,(1-a)*12,1);return{position:$n(i,r,a),pose:ba(u,f,Math.max(0,m))}}function T0(t,e,n){const s=(t.pose.turn??0)*Math.PI/2;return At(t.position,[Math.sin(s)*e,n,Math.cos(s)*e])}function AA(t,e,n,s,i){const r=`${e}/${n.object.id}`,o={...lt,...n.object.pose},a=new Set(i.flatMap(l=>Object.keys(l.pose)));for(const l of a){const c=o[l]??0;i.some(h=>h.pose[l]!==c)&&t.push({id:`${n.object.id}-${l}`,target:r,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:r,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:fb(i[u].bat.axis)}))})}}function xA(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=Ge[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 Sb(t,e={}){return Tb(t,e)}function Tb(t,e,n){const s=ve(Zn,e.action??"bowling","cricketAction.action"),i=n?n.delivery.legality==="no-ball":s==="no-ball",r=n?n.delivery.legality==="wide":s==="wide",o=n?n.delivery.style==="spin":s==="spin";ve(Ge,t.format,"cricketAction.format");const a=n?.result??xA(s,t.format),l=e.duration??6e3;if(!Number.isFinite(l)||l<4e3||l>6e4)throw new Error("cricketAction: duration must be between 4000 and 60000 ms");const c=t.scene.id;for(const $ 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(C=>C.id===$))throw new Error(`cricketAction: required equipment '${$}' is missing`);const h=Object.fromEntries(["batter","non-striker","bowler","keeper","fielder","umpire"].map($=>[$,m0(t.scene,$)]));for(const $ of["slip","point","cover","mid-off","mid-on","square-leg","fine-leg","third-man","square-umpire"])t.scene.objects.some(C=>C.id===$&&C.kind==="character")&&(h[$]=m0(t.scene,$));const u=$=>h[$].who.height,d=$=>db(h[$]),f=$=>Math.round($*6e3/l*1e9)/1e9,m=$=>$*l/6e3,g=["batting","defend","running","four","six","catch","fielding","throw","run-out"].includes(s),p=["bowling","spin","no-ball","stumping"].includes(s),b=["catch","fielding","throw","run-out","batting","running"].includes(s),v=s==="running"||s==="run-out",k=new Map,w=[d("bowler").position[0],0,i?-8.25:-9.55],S=s==="fielding"?[10.5,0,2]:[9,0,-1],x=d("fielder").position,M=($,C)=>{let z=k.get($);z||(z=new Map,k.set($,z));const X=z.get(C);if(X)return X;const W=h[$];let N=d($);if($==="bowler"){const D=N.position;if(C<1400){const G=At(w,[0,0,-.65]);N=Aa(W,C,0,1400,D,G),N.pose["arm.right.swing"]=45,N.pose["arm.right.elbow"]=80}else N.position=C<=Xt?$n(At(w,[0,0,-.65]),w,Nt(Rt(C,1400,Xt))):At(w,[0,0,.8*Nt(Rt(C,Xt,2600))]),N.pose=p0(C,[[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}],[Xt,{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}]]);o&&(N.pose={...N.pose,"arm.right.spread":18,"head.tilt":-5});for(const[G,q]of Object.entries(C<Xt?Tt.hold:Tt.open))N.pose[`hand.right.${G}`]=q}else if($==="batter"||$==="non-striker"){const D=u($);if(s==="lbw"&&$==="batter"&&(N.position[0]=0),s==="stumping"&&$==="batter"&&(N.position[2]-=1.1*Nt(Rt(C,2150,2800))),v&&C>3050){const G=M($,3050),q=$==="batter"?[1,0,-9.5]:[-1,0,9.5];N=Aa(W,C,3050,s==="run-out"?6e3:S0,G.position,q,G.pose.turn);const et=lr(W,N,"right");N.bat={grip:et,axis:Qt([.7,-.35,.5]),scale:D/1.78}}else{N.pose={...N.pose,...$==="batter"?ub():{turn:.15,"leg.left.knee":8,"leg.right.knee":8}};let q=[0,-1,$==="batter"?.05:.12],Z=At(N.position,[D*.15,D*.44,D*.04]);if($==="non-striker"&&(Z=At(N.position,[D*.08,D*.44,D*.17])),$==="batter"){const et=Nt(Rt(C,2100,2600))*(1-Nt(Rt(C,2600,xt))),H=Nt(Rt(C,2600,xt))*(1-Nt(Rt(C,xt,3800))),U=Nt(Rt(C,xt,3250))*(1-Nt(Rt(C,3250,4e3)));if(g){Z=At(N.position,[D*(.15+.03*et-.02*H-.03*U),D*(.44+.14*et+.07*H+.23*U),D*(.04+.16*et-.12*H-.06*U)]),q=Qt([.15*et+.25*U,-1+1.85*et+1.6*U,.05+.55*et-.4*H-.8*U]),N.pose.turn=1+.12*H+.3*U,N.pose.lean=3+4*H;const nt=12+4*H;N.pose["leg.left.spread"]=nt,N.pose["leg.right.spread"]=nt,s==="defend"&&(q=[0,-1,-.08],Z=At(N.position,[D*.1,D*.5,-D*.12]))}else if(["stumping","bowled","lbw"].includes(s)){const nt=Nt(Rt(C,2100,2700))*(1-Nt(Rt(C,4e3,4500)));q=Qt([.15*nt,-1+1.85*nt,.05+.55*nt]),Z=At(N.position,[D*(.15+.03*nt),D*(.44+.14*nt),D*(.04+.16*nt)])}}N=mA(W,N,Z,q)}}else if($==="keeper"){N.pose={...N.pose,turn:Ys(N.position,d("bowler").position,2),lean:20,"leg.left.swing":22,"leg.right.swing":22,"leg.left.knee":50,"leg.right.knee":50},r&&(N.position[0]=2.15*Nt(Rt(C,2900,3500))),s==="stumping"&&(N.position[2]-=.85*Nt(Rt(C,3400,3900)));const D=T0(N,u($)*.27,u($)*.44);if(s==="stumping"&&C>=3500){const G=T0({...N,position:d($).position},u($)*.27,u($)*.44),q=[0,Yt.stumpHeight,Yt.length/2],Z=$n(G,q,Nt(Rt(C,3500,3900)));N=Sn(W,N,"right",Z),N=Sn(W,N,"left",At(Z,[.045,0,0]))}else N=Sn(W,N,"right",D),N=Sn(W,N,"left",At(D,[.045,0,0]))}else if($==="fielder"&&b){if(N=Aa(W,C,3050,s==="catch"?3800:3950,x,S),C>=3800){const D={...lt,turn:Ys(S,d("batter").position,N.pose.turn),lean:s==="catch"?5:42,bend:s==="catch"?0:18,"leg.left.swing":s==="catch"?0:45,"leg.right.swing":s==="catch"?0:45,"leg.left.knee":s==="catch"?0:85,"leg.right.knee":s==="catch"?0:85,smile:.7};N.pose=ba(N.pose,D,Nt(Rt(C,3800,Tn)));const G=T0(N,u($)*.22,u($)*(s==="catch"?.73:.2));if(N=Sn(W,N,"right",G),N=Sn(W,N,"left",At(G,[.035,0,0])),(s==="throw"||s==="run-out")&&C>Tn){const q={...lt,turn:Ys(S,s==="throw"?d("keeper").position:t.landmarks["bowler-wicket"],N.pose.turn),"arm.right.swing":225,"arm.right.elbow":60,"arm.left.spread":70,"leg.left.swing":15},Z={...q,"arm.right.swing":110,"arm.right.elbow":0,lean:15};N.pose=p0(C,[[Tn,N.pose],[4450,q],[Gs,Z],[4900,{...lt,turn:q.turn,"arm.right.swing":25,lean:22}],[6e3,{...lt,turn:q.turn}]])}}}else if($==="umpire"){let D={...lt};const G=s==="stumping"?4150:s==="run-out"?5150:s==="bowled"||s==="lbw"?3500:s==="catch"?4350:5100;if(s==="no-ball")D={...D,"arm.right.spread":90,"arm.right.elbow":0};else if(s==="wide")D={...D,"arm.right.spread":90,"arm.left.spread":90,"arm.right.elbow":0,"arm.left.elbow":0};else if(s==="six")D={...D,"arm.right.spread":180,"arm.left.spread":180,"arm.right.elbow":0,"arm.left.elbow":0};else if(s==="four")D={...D,"arm.right.spread":90-70*(.5+Math.sin((C-5100)/180)*.5),"arm.right.elbow":12};else if(["catch","bowled","lbw","stumping","run-out"].includes(s)){D={...D,"arm.right.swing":165,"arm.right.elbow":0};for(const[q,Z]of Object.entries(Tt.point))D[`hand.right.${q}`]=Z}if(n){const q={...lt},Z=[[0,q]];let et=q;if(i||r){const H=i?Xt:3100;et=i?{...q,"arm.right.spread":90,"arm.right.elbow":0}:{...q,"arm.right.spread":90,"arm.left.spread":90,"arm.right.elbow":0,"arm.left.elbow":0},Z.push([H,q],[H+350,et])}if(a.wickets||s==="four"||s==="six"){const H=a.wickets?G:5100;let U=D;if(a.wickets){U={...q,"arm.right.swing":165,"arm.right.elbow":0};for(const[nt,at]of Object.entries(Tt.point))U[`hand.right.${nt}`]=at}Z.push([H,et],[H+350,U])}N.pose=p0(C,Z)}else N.pose=ba(N.pose,D,Nt(Rt(C,s==="no-ball"?Xt:s==="wide"?3100:G,(s==="no-ball"?Xt:s==="wide"?3100:G)+350)))}return z.set(C,N),N},E=($,C)=>lr(h[$],M($,C),"right"),T=g?pA(M("batter",xt).bat):s==="lbw"?$n(Xs(h.batter,M("batter",xt),"leg.right",1),Xs(h.batter,M("batter",xt),"leg.right",2),.6):[p?Yt.wicketWidth/2+.075+.15:0,.45,9.25],A=E("bowler",Xt),P=[r?.85:o?-.35:s==="lbw"?T[0]*.6:0,.075,3.9],I=E("keeper",s==="stumping"?3400:3500),O=E("fielder",ur),_=E("fielder",Tn),L=s==="run-out"?"bowler":"striker",j=s==="run-out"?5e3:s==="stumping"?3900:3200,V=[t.boundaryRadius*.8,s==="six"?2.1:.075,-t.boundaryRadius*.6],tt=($,C,z,X,W,N=0,D=0)=>y0({target:`${c}/ball`,start:C,end:z,from:X,to:W,arc:N,curve:D},$),J=$=>{if($<=Xt)return E("bowler",$);if($<=hr)return tt($,Xt,hr,A,P,.15,o?.35:0);const C=r?At(I,[0,0,-.6]):T;if($<=xt)return tt($,hr,xt,P,C,.08);if(s==="bowled"){const X=[0,.36,Yt.length/2];return $<=j?tt($,xt,j,T,X):tt($,j,4100,X,[0,.075,12.5],.2)}if(s==="lbw")return[...T];if(["bowling","spin","no-ball","wide","stumping"].includes(s)){const X=s==="stumping"?3400:3500;if(p&&$<=X){const W=[C[0],I[1],Yt.length/2+.2];return $<=3200?tt($,xt,3200,C,W,.04):tt($,3200,X,W,I,.04)}return $<=X?tt($,xt,X,C,I,.04):E("keeper",$)}if(s==="defend")return tt($,xt,3400,T,At(T,[-.5,-T[1]+.075,-.7]),.12);if(s==="four"||s==="six"){if(s==="six")return $<=5e3?tt($,xt,5e3,T,V,12):tt($,5e3,5700,V,At(V,[2,-2.025,-1.5]));const X=[5,.075,5];return $<=3300?tt($,xt,3300,T,X,.5):tt($,3300,5e3,X,V)}if(s==="catch")return $<=ur?tt($,xt,ur,T,O,5):E("fielder",$);const z=[4,.075,5];if($<=3300)return tt($,xt,3300,T,z,.8);if($<=Tn)return tt($,3300,Tn,z,_);if(s==="throw"||s==="run-out"){if($<=Gs)return E("fielder",$);const X=E("fielder",Gs),W=s==="run-out"?[0,.42,-Yt.length/2]:E("keeper",Ea),N=s==="run-out"?j:Ea;return $<=N?tt($,Gs,N,X,W,1.2):s==="run-out"?tt($,N,5700,W,[0,.075,-12],.18):E("keeper",$)}return[..._]},F=[],B=($,C,z,X,W)=>F.push({id:$,time:m(C),kind:z,label:X,caption:W}),Y=n?{bowled:"Delivery hits stumps",lbw:"Pad contact",stumping:"Keeper breaks wicket","run-out":"Throw breaks wicket"}[s]??Zn[s].name:Zn[s].name;if(B("setup",0,"setup",Y,n?`${n.delivery.style} delivery · ${n.delivery.legality}${n.freeHit?" · free hit":""}. ${Zn[s].summary.replace("A legal delivery","A delivery")}`:Zn[s].summary),B("release",Xt,"release","Ball released",i?"The front foot has landed beyond the popping crease. No-ball.":"The bowler releases the ball; the front foot is behind the popping crease."),B("bounce",hr,"bounce","Pitch bounce",o?"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."),g?B("contact",xt,"contact","Bat contact","The ball meets the blade. The bat is keyed from the same two hand grips."):s==="lbw"?B("pad-contact",xt,"contact","Pad contact",n?"The ball contacts the pad. The highlighted path is illustrative; the authored decision is resolved separately.":"The highlighted path illustrates a ball that would hit the stumps. This is an authored LBW example."):B("miss",xt,"contact",s==="wide"?"Beyond normal reach":"The batter misses",s==="wide"?"The untouched ball is too far away for a normal stroke. The umpire calls Wide.":"The untouched delivery passes the striker."),s==="catch"&&B("catch",ur,"collect","Catch controlled",n?"The fielder controls the ball before it touches the ground. The authored decision is resolved separately.":"The fielder controls the ball before it touches the ground: caught."),["fielding","throw","run-out","batting","running"].includes(s)&&B("gather",Tn,"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(s)&&B("keeper",s==="stumping"?3400:3500,"collect","Keeper gathers","The keeper controls the ball behind the striker’s wicket."),(s==="throw"||s==="run-out")&&B("throw",Gs,"throw","Throw released","The fielder releases the gathered ball toward the wicket."),s==="throw"&&B("return",Ea,"collect","Return received","The keeper receives and controls the return throw."),s==="stumping"&&B("wicket",j,"wicket",n?"Wicket broken":"Stumped","Holding the ball, the keeper removes a bail. The striker is out of ground and is not attempting a run."),s==="run-out"&&B("wicket",j,"wicket",n?"Wicket broken":"Run out","The direct throw removes a bail before the running batter makes this ground."),s==="bowled"&&B("wicket",j,"wicket",n?"Stumps hit":"Bowled",n?"The delivery hits the wicket and removes a bail. A broken wicket does not by itself decide a dismissal.":"The legal delivery hits the wicket and removes a bail."),(s==="four"||s==="six")&&B("boundary",5e3,"boundary",s==="four"?"Four runs":"Six runs",s==="four"?"The struck ball reaches the boundary after touching the ground: four.":"The struck ball clears the boundary without touching the ground: six."),s==="running"&&B("run",S0,"result","One run completed","Both batters have reached the opposite ground. One run is completed."),B("result",5700,"result","Illustrated result",s==="no-ball"?`One no-ball extra; it does not count in the over.${a.freeHitNext?" The next legitimate delivery is a free hit.":" Test cricket has no automatic free hit."}`:s==="wide"?"One wide extra; the delivery does not count in the over.":s==="lbw"?"LBW is declared for this illustrated legal delivery. A full decision also checks pitching, impact and any bat contact.":`${a.runs} bat runs · ${a.extras} extras · ${a.wickets} wicket${a.wickets===1?"":"s"}.`),n){const $={"no-dismissal":"No dismissal was authored for this play.",dismissal:`The authored ${n.ruling.dismissal} decision is allowed in this delivery context.`,"no-ball":`Not out: ${s==="catch"?"a catch":"this dismissal"} cannot dismiss the striker on a no-ball.`,"free-hit":`Not out: ${s==="catch"?"a catch":"this dismissal"} cannot dismiss the striker on a free hit.`,wide:"Not out: this dismissal is not available from a Wide."},C=F.find(z=>z.id==="result");C.label=a.wickets?"Out":"Not out",C.caption=`${$[n.ruling.reason]} ${a.runs} bat runs · ${a.extras} extras · ${a.wickets} wickets. ${a.legalBall?"Counts as a legal ball.":"Does not count in the over."}${a.freeHitNext?" The next delivery is a free hit; an illegal delivery carries it forward.":n.freeHit?" This legal delivery consumes the free hit.":""}`}F.sort(($,C)=>$.time-C.time);const R=gb(0,l,e.every,[1400,1800,Xt,2100,2150,2250,hr,2600,2800,xt,3050,3100,3200,3250,3300,3400,3500,3800,3900,3950,4e3,ur,Tn,4350,4450,Gs,4900,5e3,5100,5150,Ea,S0,5700].map(m)),K=R.map($=>J(f($))),st=[];for(const[$,C]of Object.entries(h)){let z=C.object.pose?.turn??0,X=z;const W=R.map((N,D)=>{const G=f(N);let q=$==="fielder"&&b&&G>3050&&G<3250?Aa(C,G,3050,s==="catch"?3800:3950,x,S,X):M($,G),Z=K[D];const et=!["batter","non-striker","bowler","keeper"].includes($);if(et){const U=M("bowler",Math.min(G,Xt)),nt=At(U.position,[0,u("bowler")*.8,0]);Z=G<=Xt?nt:G<2100?$n(nt,Z,Nt(Rt(G,Xt,2100))):Z}if(v&&($==="batter"||$==="non-striker")&&G>3050&&(Z=$==="batter"?[1,u($)*.8,-10.5]:[-1,u($)*.8,10.5]),$==="bowler"&&G<=xt&&(Z=At(M("batter",G).position,[0,u("batter")*.65,0])),et&&($!=="fielder"||!b||G<=3050)||$==="bowler"&&G>=3e3){const U=Ys(q.position,Z,z);z=$==="bowler"&&G<3500?(q.pose.turn??0)+(g0(U,q.pose.turn??0)-(q.pose.turn??0))*Nt(Rt(G,3e3,3500)):U,q={...q,pose:{...q.pose,turn:z}}}return $==="fielder"&&b&&(G===3050?X=z:G>3050&&(z=g0(q.pose.turn??0,z),q={...q,pose:{...q.pose,turn:z}})),gA(C,q,Z)});AA(st,c,C,R,W)}for(const[$,C]of["x","y","z"].entries())st.push({id:`ball-${C}`,target:`${c}/ball`,property:C,keyframes:R.map((z,X)=>({time:z,value:K[X][$]}))});if(["bowled","stumping","run-out"].includes(s))for(let $=0;$<2;$++){const C=`${L}-bail-${$}`,X=t.scene.objects.find(W=>W.id===C).position;st.push({id:`${C}-fall`,target:`${c}/${C}`,property:"position",keyframes:[{time:0,value:[...X]},{time:m(j),value:[...X]},{time:m(j+180),value:At(X,[$?.25:-.25,.22,L==="striker"?.22:-.22]),easing:"ease-out"},{time:m(j+650),value:[X[0]+($?.4:-.4),.035,X[2]+(L==="striker"?.45:-.45)],easing:"ease-in"}]}),st.push({id:`${C}-spin`,target:`${c}/${C}`,property:"rotateZ",keyframes:[{time:0,value:0},{time:m(j),value:0},{time:m(j+650),value:$?145:-145}]})}if(s==="lbw"){const $=[T[0]*.8,T[1],Yt.length/2],C=oe($,T);st.push({id:"lbw-position",target:`${c}/lbw-guide`,property:"position",keyframes:[{time:0,value:[...T]}]},{id:"lbw-rotation",target:`${c}/lbw-guide`,property:"quaternion",interpolation:"slerp",keyframes:[{time:0,value:fb(C)}]},{id:"lbw-length",target:`${c}/lbw-guide`,property:"scaleY",keyframes:[{time:0,value:ui(T,$)}]},{id:"lbw-visible",target:`${c}/lbw-guide`,property:"visible",keyframes:[{time:0,value:0},{time:m(xt)-.001,value:0},{time:m(xt),value:1}]})}return{action:s,duration:l,events:F,result:a,timeline:{id:`${c}-${s}`,formatVersion:2,name:Y,config:{duration:l,markers:F.map($=>({id:$.id,time:$.time,label:$.label}))},captions:{en:Object.fromEntries(F.map($=>[$.id,$.caption]))},tracks:st}}}function PA(t={}){const e=M0(t);return{...e,...Sb(e,t)}}function $A(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}const En=Object.freeze({deliveryStyles:Object.freeze(["pace","spin"]),deliveryLegalities:Object.freeze(["legal","no-ball","wide"]),shots:Object.freeze(["miss","drive","defend"]),finishes:Object.freeze(["none","single","four","six","stumps","pad"]),fielding:Object.freeze(["none","keeper","catch","gather","throw","stumping","run-out"]),dismissals:Object.freeze(["caught","bowled","lbw","stumped","run-out"])});function Us(t,e,n){if(!t.includes(e))throw new Error(`cricketPlay.${n}: unknown choice '${e}'`);return e}function IA(t){const{shot:e,finish:n,fielding:s}=t;if(t.delivery.legality==="wide"){if(e!=="miss"||n!=="none"||s!=="keeper")throw new Error("cricketPlay: Wide currently supports only an untouched delivery gathered by the keeper");return"wide"}if(e==="miss"){if(s==="none"&&n==="stumps")return"bowled";if(s==="none"&&n==="pad")return"lbw";if(n==="none"&&s==="stumping")return"stumping";if(n==="none"&&s==="keeper")return t.delivery.style==="spin"?"spin":"bowling"}if(e==="defend"&&n==="none"&&s==="none")return"defend";if(e==="drive"){if(s==="none"&&(n==="four"||n==="six"))return n;if(s==="gather"&&n==="single")return"running";if(n==="none"){if(s==="catch")return"catch";if(s==="gather")return"fielding";if(s==="throw")return"throw";if(s==="run-out")return"run-out"}}throw new Error(`cricketPlay: unsupported motion combination (${e}, ${n}, ${s})`)}function OA(t){const e=Us(En.shots,t.shot??"miss","shot"),n=Us(En.finishes,t.finish??"none","finish");let s=e==="miss"?"keeper":"gather";(e==="defend"||n!=="none")&&(s=n==="single"?"gather":"none");const i=Us(En.fielding,t.fielding??s,"fielding"),r=t.context?.freeHit??!1;if(typeof r!="boolean")throw new Error("cricketPlay.context.freeHit must be boolean");const o=t.decision?.dismissal??null;return o!==null&&Us(En.dismissals,o,"decision.dismissal"),{delivery:{style:Us(En.deliveryStyles,t.delivery?.style??"pace","delivery.style"),legality:Us(En.deliveryLegalities,t.delivery?.legality??"legal","delivery.legality")},shot:e,finish:n,fielding:i,context:{freeHit:r},decision:{dismissal:o}}}function CA(t,e){const n=t.decision.dismissal;if(!n)return{dismissal:null,reason:"no-dismissal"};if({catch:"caught",bowled:"bowled",lbw:"lbw",stumping:"stumped","run-out":"run-out"}[e]!==n)throw new Error(`cricketPlay: '${n}' decision does not match '${e}' motion`);if(n!=="run-out"){if(t.context.freeHit)return{dismissal:null,reason:"free-hit"};if(t.delivery.legality==="no-ball")return{dismissal:null,reason:"no-ball"};if(t.delivery.legality==="wide"&&n!=="stumped")return{dismissal:null,reason:"wide"}}return{dismissal:n,reason:"dismissal"}}function Eb(t,e={}){const n=ve(Ge,t.format,"cricketPlay.format"),s=OA(e);if(s.context.freeHit&&!Ge[n].freeHitAfterNoBall)throw new Error("cricketPlay: Test format does not support free-hit context");const i=IA(s),r=CA(s,i),o=s.delivery.legality==="legal",a={runs:s.finish==="single"?1:s.finish==="four"?4:s.finish==="six"?6:0,extras:o?0:1,wickets:r.dismissal?1:0,legalBall:o,freeHitNext:Ge[n].freeHitAfterNoBall&&(s.delivery.legality==="no-ball"||s.context.freeHit&&!o),...r.dismissal?{dismissal:r.dismissal}:{}};return{...Tb(t,{action:i,duration:e.duration,every:e.every},{delivery:s.delivery,result:a,ruling:r,freeHit:s.context.freeHit}),play:s,ruling:r}}function _A(t={}){const e=M0(t);return{...e,...Eb(e,t)}}const Ab=Object.freeze({"no-ball-stumps":Object.freeze({name:"No-ball + stumps hit",options:Object.freeze({delivery:Object.freeze({legality:"no-ball"}),finish:"stumps",decision:Object.freeze({dismissal:"bowled"})})}),"free-hit-catch":Object.freeze({name:"Free hit + catch",options:Object.freeze({context:Object.freeze({freeHit:!0}),shot:"drive",fielding:"catch",decision:Object.freeze({dismissal:"caught"})})}),"no-ball-four":Object.freeze({name:"No-ball + four",options:Object.freeze({delivery:Object.freeze({legality:"no-ball"}),shot:"drive",finish:"four"})}),"free-hit-run-out":Object.freeze({name:"Free hit + run-out",options:Object.freeze({context:Object.freeze({freeHit:!0}),shot:"drive",fielding:"run-out",decision:Object.freeze({dismissal:"run-out"})})}),"free-hit-wide":Object.freeze({name:"Free hit + Wide",options:Object.freeze({context:Object.freeze({freeHit:!0}),delivery:Object.freeze({legality:"wide"})})})}),RA={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 xb(t,e={}){const n={};for(const s of Object.keys(Gt))n[s]={summary:`Walks to \`to\` in the ${s} gait.`,needs:["to"]};for(const s of Object.keys(he))n[s]={summary:`Moves into the ${s} pose and holds it (\`for\` ms).`};for(const s of Object.keys(mn))n[s]={summary:`The ${s} gag (${nr(s)} ms).`};for(const[s,i]of Object.entries(sr))n[s]={...i};return{sports:{cricket:{actions:{...Zn},formats:{...Ge},casts:{...d0},fieldingPositions:{...Ks},markingProfiles:{...Sa},cameras:{...va},decisionCameras:cr,playComponents:En,playExamples:Ab}},...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(RA),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:ca,stickFigure:{poseFields:Zd,props:Qd,handFields:tf,poses:Object.keys(he),expressions:Object.keys(Mt),gags:Object.fromEntries(Object.keys(mn).map(s=>[s,nr(s)])),gaits:Object.keys(Gt),actingStyles:Object.keys(Xn),beatFields:Vo,actions:n,dances:Object.fromEntries(Object.entries(ln).map(([s,i])=>[s,Object.keys(i.moves)])),flips:Object.fromEntries(Object.entries(Ki).map(([s,i])=>[s,i.label])),handShapes:Object.keys(Tt),mudras:Object.keys(Jr)},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:pa,commonControls:Object.fromEntries(Object.entries(Ds).map(([s,i])=>[s,`${i.description}${i.unit?` (${i.unit})`:""}`])),commonActions:Object.fromEntries(Object.entries(h0).map(([s,i])=>[s,i.summary])),presets:Object.fromEntries(Object.entries(js).map(([s,i])=>{const r=i();return[s,{family:r.family,summary:r.summary,actions:Object.fromEntries(Object.entries(r.actions).map(([o,a])=>[o,{summary:a.summary,...a.needs?{needs:a.needs}:{}}])),controls:Object.keys(r.rig.controls),anchors:Object.keys(r.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","bean"],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.measurements":`Organic torso from tape-measure girths { height, bust, underbust?, waist, hip } in any one unit, or a named shape (${Object.keys(ho).join(" | ")}). Sets the front width, the side depth (bust forward, seat back, belly) and the hip and thigh spacing; reads correctly at every turn. An explicit torso / torsoFront / torsoBack / hipWidth still wins.`,"body.torsoFront · body.torsoBack":"Organic side-view depth from the spine line toward the chest/belly and toward the back/seat, same profile format; default torso × depth.","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.","figure: 'bean'":"The white outlined stick figure: one smooth stroked outline per limb (no seams at elbows, knees or the front arm's shoulder), a shaped body (rounded shoulders, slight waist, fuller hips), big oval eyes, mittens and cartoon shoes; every pose, gait, dance and turn works. Always drawn clean; the near arm is in front of the body in both limb modes. `bean: { limbs: tube | line, halo (a pale edge on line limbs), torso, limbWidth, lineWidth, outlineWidth, fill, shirt, sleeves: short | long | none, trousers, shoes (a dark shoe gets a shine), coat (a trench coat: lapels, belt and buckle, buttons, knee hem, sleeves to the wrist), fedora, shades (aviators in place of the eyes; brows still show) }`; an `outfit`'s shirt, trousers and sleeves colour it. `castMember('beanMan' | 'beanWoman' | 'beanKid' | 'beanBoss' | 'beanDetective' | 'beanStick', h)`.",hands:"`dot` | `cartoon` (with `handStyle: glove | natural`) | `mitten` (a plain oval mitten; the bean figure's default)",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(Ae),dances:Object.keys(Nn),expressions:Object.keys(oc),faceStyles:["simple","anime","oval"],faceShapes:["round","angular"],gags:Object.keys(So),builds:Object.keys(so),hair:Object.keys(Ac),hairColors:{...Fe},facialHair:Object.keys(Oc),glasses:Object.keys(_c),hats:Object.keys(ko),feet:[...ng],cast:Object.keys(Th),heldItems:Object.fromEntries(Object.entries(Lc).map(([s,i])=>[s,i.hands])),handMeetings:Object.keys(er)},noir:Vy,codePanel:{languages:Yo,removeStyles:jo,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:bh},surfaces:{code:Ji,board:je,chart:Kn,prop:zs},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: ${Ns.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"},math:{api:{"mathFigure(spec)":"checks a figure (JSON: width, height, x?, y?, theme?: dark | light | chalk, values, items) and says how to fix it","layoutFigure(spec, props)":"the figure at some values as shapes; drawDisplayList(ctx, list) or displayListToSvg(list) draws them","mathTarget(spec, { x, y })":"a canvas target for videos and canvas pages; tracks animate its values and item props","mathSteps(lesson, target, spec, { hidden })":"lesson steps: toValue, applyMatrix, drawOn, fadeIn, fadeOut, showStep (equations)","mountMath(element) / mountAllMath()":"lesson-page embeds: <figure data-tinyfly-math> with data-tinyfly-figure and data-tinyfly-timeline JSON scripts, stepped like any embed","lossSurface3D({ expr, start, rate, momentum?, steps?, orbit? })":"a loss surface as scene-3d JSON with a ball rolling down the descent path: { scene, tracks, duration, path, losses }","mathSurface(figure, { x, y })":"a figure as a surface for surfaceScript: anchors box, item:ID, tip:ID, point:ID, node:GRAPH:NODE, term:ID:TEXT, value:NAME; edits drawOn, erase, show, hide, step, set","mathExplorable(element, spec, { sliders, drag })":"reader-driven figures: sliders on number values, drag vector tips or matrix columns","mathFigureToSvg(spec, props)":"a standalone SVG of a figure at some values","linearMapFigure, determinantFigure, eigenFigure, vectorSumFigure, spanFigure":"ready linear algebra figures; the matrix is the value M","tangentFigure, secantFigure, riemannFigure, areaFigure, taylorFigure, limitFigure":"ready calculus figures; their moving parts are number values (a, h, n, b, order, p)","differentiate / compileDerivative / integrate":"exact symbolic derivatives of expressions; Simpson integration","normalFigure, binomialFigure, cltFigure, galtonFigure, monteCarloPiFigure, regressionFigure, bayesFigure":"ready probability and statistics figures","graphSearchFigure, shortestPathFigure, recursionTreeFigure, vennFigure, clockFigure":"ready discrete maths figures; searches move with the value step","searchEvents / parseSetExpression / regionCells":"graph searches as data; set expressions and their Venn cells","neuralNetworkFigure, gradientDescentFigure, attentionFigure, decisionBoundaryFigure, kmeansFigure, activationFigure":"ready AI/ML figures",distributions:"{ kind: normal | uniform | exponential | binomial | poisson | dice | mean, …numbers or value names }; density, meanOf, sdOf, samples (seeded)","layoutTex(tex) / morphEquation(a, b, t)":"the built-in TeX subset, and term-by-term transitions","vec2, mat2":"2D vectors and 2×2 matrices (apply, multiply, determinant, inverse, eigen)"},items:{grid:"{ step?, transform?: matrix value, ghost? }: lines of the plane, warped by a matrix",axes:"{ ticks?, labels? }",vector:"{ to, from?, transform?, label? (TeX), labelAt?: tip | middle }",basis:"{ transform? }: î and ĵ",point:"{ at, transform?, label?, hollow? } or { on: expr, x } (a point riding a curve)",function:'{ expr: "sin(k x)", domain?, derivative?, dashed? }: y = f(x); number values are its parameters',parametric:"{ x, y (expressions in t), t?, transform? }",polygon:"{ points? (default the unit square), transform?, label? }: \\val{M.det} shows the determinant",line:"{ along } or { eigen: matrix value }: a span, or eigenlines",label:"{ tex, at, screen?, size?, align?, backdrop? }",equation:"{ steps: [TeX…], at, screen? }: ITEM.step moves between steps, terms gliding",tangent:"{ expr, at, h? (secant), label? }: \\val{ID.slope} is the exact slope",riemann:"{ expr, from, to, n, rule?: left | right | midpoint | trapezoid }: \\val{ID.sum}, \\val{ID.exact}",area:"{ expr, from, to, lower? }: signed, coloured by sign; \\val{ID.value}",taylor:"{ expr, at, order }: exact Taylor polynomials; a fractional order grows the next term in",histogram:"{ distribution, count, bins?, scale?, curve?, seed? }: seeded samples, binned; fills as count grows",distribution:"{ distribution, shade?: [a, b] }: a density curve (bars when discrete); \\val{ID.p}",galton:"{ rows?, balls, spacing?, top?, seed? }: a Galton board; fractional balls = the next one falling",scatter:"{ points: uniform | linear, count, inside?, fit?, seed? }: Monte Carlo and regression; \\val{ID.ratio}, \\val{ID.r}",bayes:"{ prior, truePositive, falsePositive }: Bayes as areas; \\val{ID.posterior}",graph:"{ nodes, edges, directed?, tree?, search?: { kind: bfs | dfs | dijkstra, start }, step?, frontier? }: searches step by step",venn:"{ sets (2 or 3), highlight?: set expression like (A | B)' }: shaded by clipping",clock:"{ modulus, value }: clock arithmetic; \\val{ID.hour}",network:"{ layers, activation?, inputs?, flow?, seed?, labels? }: a forward pass, layer by layer",heatmap:"{ cells (softmax? per row) or expr in x, y; colormap?, rowLabels?, colLabels?, values? }: attention maps, loss fields",contours:"{ expr in x, y, levels? }: level curves (marching squares)",descent:"{ expr in x, y, start, rate, steps, momentum? }: gradient descent with an exact gradient",classifier:"{ epochs, centres?, rate?, start? }: logistic regression training; \\val{ID.accuracy}",kmeans:"{ centres, iteration, k? }: Lloyd iterations; \\val{ID.inertia}"},props:{NAME:"a value: a number, [x, y] vector or [a, b, c, d] matrix (row by row; columns are where î and ĵ land)","ITEM.draw":"0..1, draws an item on","ITEM.opacity":"0..1","ITEM.step":"an equation's step; fractional values are part way"},functions:["sin","cos","tan","asin","acos","atan","atan2","sinh","cosh","tanh","exp","ln","log","log2","sqrt","abs","floor","ceil","round","sign","min","max","sigmoid","relu"],tex:"^ _ \\frac \\sqrt \\vec \\hat \\bar, \\sum \\prod \\int with limits, \\sin \\lim … , Greek, \\cdot \\times \\le \\to \\infty …, pmatrix / bmatrix / vmatrix, \\text, \\color{c}{…}, \\id{name}{…} (names a term for transitions), \\val{name:digits} (a live value)"},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 mt=t=>t.map(e=>`\`${e}\``).join(", "),Pb=t=>Object.entries(t).map(([e,n])=>`| \`${e}\` | ${n.unit??n.kind??""} | ${n.description} |`).join(`
|
|
64
|
+
`)}`);const r=s.from??0,o=s.ground??0,a=s.scale??60,l=s.exaggeration??1,c=ya(e),h={};for(const T of[...Object.keys(Ds),...Object.keys(e.rig.controls)])h[T]=s.start?.[T]??Ot(e.rig,{},T);const u=[{time:0,pose:{...h}}],d=new Map,f=[];let m=r,g=o;const p=(T,A,P,I)=>{const O=d.get(T)??[{time:0,value:T==="x"||T==="y"?0:h[T]}];O.push({time:A,value:P,...I?{easing:I}:{}}),d.set(T,O),T!=="x"&&T!=="y"&&(h[T]=P)},y=(T,A)=>{const P=T==="x"?m-r:T==="y"?g-o:h[T],I=d.get(T);(!I||I[I.length-1].time<A)&&p(T,A,P)},v={prop:e,scale:a,exaggeration:l,get x(){return m},get floor(){return g},values:h,facing(){const T=Math.sin(h.turn*Math.PI/2);return Math.abs(T)<.5?0:T>0?1:-1},key(T,A,P={}){Object.assign(h,A),u.push({time:T,pose:{...h},...P.act===!1?{act:!1}:{},...P.easing?{easing:P.easing}:{}})},move(T,A,P,I={}){y("x",T),p("x",A,P-r,I.easing),m=P,I.floor!==void 0&&(y("y",T),p("y",A,I.floor-o,I.easing),g=I.floor)},set(T,A,P,I){p(T,A,P,I)},turnTo(T,A){const P=typeof A=="number"?A:c0[A],I=h.turn,_=[P-4,P,P+4].map(j=>({t:j,d:Math.abs(j-I)})).sort((j,V)=>j.d-V.d||Math.abs(j.t)-Math.abs(V.t))[0];if(_.d<.001)return T;const L=T+lA*Math.max(1,_.d);return v.key(L,{turn:_.t}),L},effect(T){f.push(T)},anchor(T){const P=Bs(e,h,a).anchors[T];if(!P)throw new Error(`${e.kind}: no anchor "${T}"`);return{x:m+P.point.x,y:g+P.point.y}}},w=[];let k=0;for(const T of n){const A=Math.max(T.at??k,u[u.length-1].time),P=c[T.do].run(v,T,A);P.end>u[u.length-1].time&&u.push({time:P.end,pose:{...h}}),w.push({start:A,end:P.end,...P.contact!==void 0?{contact:P.contact}:{},...P.release!==void 0?{release:P.release}:{}}),k=P.end}const S=xh(s.style??"snappy"),x={...S,anticipation:S.anticipation*l,overshoot:S.overshoot*l},M=Uo(dA(u),e.acting,{style:x}),E=[...Object.entries(M).filter(([T])=>!d.has(T)).map(([T,A])=>({id:`${t}-${T}`,target:t,property:T,keyframes:A})),...[...d].map(([T,A])=>({id:`${t}-${T}`,target:t,property:T,keyframes:fA(A)}))];for(const T of hA(t,e,E,k,u[0].pose)){const A=E.findIndex(O=>O.property===T.property);if(A<0){E.push(T);continue}const P=new Ht({id:`${t}-own`,tracks:[E[A]]}),I=O=>Number(P.getStateAtTime(O).values.get(t)?.get(T.property)??0);E[A]={...T,keyframes:T.keyframes.map(O=>({time:O.time,value:Number(O.value)+I(O.time)}))}}return{tracks:E,duration:k,beats:w,effects:f}}const cA=1500;function hA(t,e,n,s,i){if(!e.follow?.length)return[];const r=new Ht({id:`${t}-follow`,tracks:n.filter(a=>a.property==="turn"||e.follow.some(l=>l.of===a.property))}),o=(a,l)=>{const c=r.getStateAtTime(a).values.get(t)?.get(l);return typeof c=="number"?c:i[l]??0};return e.follow.map(a=>{const l=s+cA,c=li(d=>o(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 m=Math.sin(o(d,"turn")*Math.PI/2),g=(f-o(d,a.of))*m;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 uA=20;function dA(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<uA?n[n.length-1]={...s,time:i.time}:n.push(s)}return n}function fA(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 Ge=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."})}),d0=Object.freeze({adults:"Adults",men:"Men",children:"Children",mixed:"Mixed cast"}),Ks=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"}),Zn=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 ve(t,e,n){if(!Object.prototype.hasOwnProperty.call(t,e))throw new Error(`${n}: unknown choice '${e}'`);return e}const Rt=(t,e,n)=>Math.max(0,Math.min(1,(t-e)/(n-e))),Nt=t=>t*t*(3-2*t),At=(t,e)=>ci(t,e),f0=(t,e)=>Pn(t,e);function g0(t,e){const n=e+((t-e+2)%4+4)%4-2;return n===0?0:n}function Ys(t,e,n=0){return Math.hypot(e[0]-t[0],e[2]-t[2])<.001?n:g0(Math.atan2(e[0]-t[0],e[2]-t[2])*2/Math.PI,n)}function ub(){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 m0(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:Ps({...n.character,height:n.height??1.78})}}function db(t){return{position:[...t.object.position??[0,0,0]],pose:{...lt,...t.object.pose}}}function Xs(t,e,n,s){const i=cn(t.who.plan,e.pose,{height:t.who.height,contact:t.who.contact});return At(e.position,i.chains[n][s])}function lr(t,e,n){const s=Xs(t,e,`arm.${n}`,2),i=Xs(t,e,`arm.${n}`,1);return At(s,f0(Qt(oe(s,i)),t.who.lineWidth*.5))}function gA(t,e,n){const s={...e.pose,"head.turn":0,"head.nod":0,"head.tilt":0},i=cn(t.who.plan,s,{height:t.who.height,contact:t.who.contact}).head,r=oe(n,At(e.position,i.center)),o=i.axes.map(c=>We(r,c)),a=Math.atan2(o[0],o[2])*180/Math.PI,l=Math.atan2(-o[1],Math.hypot(o[0],o[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 Sn(t,e,n,s,i="hold"){let r={...e.pose};for(let o=0;o<10;o++){const a={...e,pose:r},l=cn(t.who.plan,r,{height:t.who.height,contact:t.who.contact}),c=ms(t.who.plan,r,t.who.height),h=oe(lr(t,a,n),Xs(t,a,`arm.${n}`,2)),u=oe(oe(oe(s,h),e.position),l.hip),d=$i(u,(r.roll??0)*Math.PI/180),f=At(c.root,ee(d,-(r.turn??0)*Math.PI/2));r=Oi(t.who.plan,r,`arm.${n}`,f,{height:t.who.height})}for(const[o,a]of Object.entries(Tt[i]))r[`hand.${n}.${o}`]=a;return{...e,pose:r}}function mA(t,e,n,s){const i=Qt(s),r=t.who.height/1.78;let o=Sn(t,e,"left",n);return o=Sn(t,o,"right",At(lr(t,o,"left"),f0(i,.105*r))),{...o,bat:{grip:lr(t,o,"left"),axis:i,scale:r}}}function pA(t){return At(t.grip,f0(t.axis,.51*t.scale))}function fb(t){const e=Qt(t),n=Math.max(-1,Math.min(1,e[1]));return n>.999999?[0,0,0,1]:n<-.999999?Zt([1,0,0],180):Zt(Qt(hi([0,1,0],e)),Math.acos(n)*180/Math.PI).map(s=>s===0?0:s)}function ba(t,e,n){const s={};for(const i of Object.keys({...t,...e})){const r=t[i]??lt[i]??0;s[i]=r+((e[i]??lt[i]??0)-r)*n}return s}function p0(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 ba({...lt,...e[n-1][1]},{...lt,...e[n][1]},Nt(Rt(t,e[n-1][0],e[n][0])));return{...lt,...e.at(-1)[1]}}function Ue(t,e){if(!Array.isArray(t)||t.length!==3||!t.every(Number.isFinite))throw new Error(`${e}: expected three finite coordinates`)}function gb(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(r=>r>=t&&r<=e&&Number.isFinite(r))]);for(let r=t+n;r<e;r+=n)i.add(r);return[...i].sort((r,o)=>r-o)}function y0(t,e){if(mb(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],r=t.to[2]-t.from[2],o=Math.hypot(i,r)||1;return[t.from[0]+i*n-r/o*(t.curve??0)*s,t.from[1]+(t.to[1]-t.from[1])*n+(t.arc??0)*s,t.from[2]+r*n+i/o*(t.curve??0)*s]}function mb(t){if(!t.target?.trim())throw new Error("ballFlight: target is required");if(Ue(t.from,"ballFlight.from"),Ue(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 yA(t){mb(t);const e=gb(t.start,t.end,t.every),n=e.map(s=>y0(t,s));return["x","y","z"].map((s,i)=>({id:`${t.id??"flight"}-${s}`,target:t.target,property:s,keyframes:e.map((r,o)=>({time:r,value:n[o][i]}))}))}const cr=Object.freeze({"front-foot":Object.freeze({name:"Front-foot review",summary:"A fixed side view of the landing front foot and bowler’s popping crease at release."}),"striker-crease":Object.freeze({name:"Striker crease",summary:"A fixed side view of the striker’s popping crease, wicket and keeper arrival."}),"bowler-crease":Object.freeze({name:"Bowler crease",summary:"A fixed side view of the other crease and wicket for a running batter and return throw."})});function b0(t){return Object.prototype.hasOwnProperty.call(cr,t)}function wa(t,e){if(!b0(e))return;const n=i=>t.events.find(r=>r.id===i),s=e==="front-foot"?n("release"):e==="bowler-crease"?t.action==="run-out"?n("wicket"):n("run")??n("release"):(t.action!=="run-out"?n("wicket"):void 0)??n("run")??n("keeper")??n("return")??t.events.find(i=>i.kind==="contact");if(s){if(!Number.isFinite(s.time)||s.time<0||s.time>t.duration)throw new Error("cricketCameraReview: event time must be within the clip");return{...s}}}function ka(t,e,n){const s=m0(t.scene,e),i=db(s);for(const r of t.timeline.tracks){if(r.target!==t.scene.id+"/"+e)continue;if(!("keyframes"in r))throw new Error("cricketCamera: review requires baked actor tracks");const o=new nn(r).getValueAtTime(n);if(typeof o!="number"||!Number.isFinite(o))continue;const a=["x","y","z"].indexOf(r.property);a>=0?i.position[a]=o:i.pose[r.property]=o}return{actor:s,sample:i}}function pb(t){const e=wa(t,"front-foot");if(!e)throw new Error("cricketCamera: front-foot view requires a release event");const{actor:n,sample:s}=ka(t,"bowler",e.time);return{point:Xs(n,s,"leg.right",2),height:n.who.height}}function yb(t,e){const n=e==="striker-crease"?"striker":"bowler",s=t.landmarks[n+"-crease"];return Ue(s,"cricketCamera.crease"),[...s]}function bA(t,e){if(!b0(e))return[];const n=yb(t,e),s=e==="front-foot"?pb(t).point[0]:0;return[{id:"decision-review-"+e,name:cr[e].name+": crease reference",kind:"line",color:"#f4b83f",width:.035,points:[[s-1.1,.045,n[2]],[s+1.1,.045,n[2]]]}]}function w0(t,e,n,s){const i=e*Math.PI/180,r=n*Math.PI/180;return[t[0]+s*Math.cos(r)*Math.sin(i),t[1]+s*Math.sin(r),t[2]+s*Math.cos(r)*Math.cos(i)]}const k0=(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 wA(t,e,n){const s={target:[0,0,0],yaw:0,pitch:15,distance:8,...t},i={...s,...e},r=k0(s.target,i.target,n),o=s.position||i.position?k0(s.position??w0(s.target,s.yaw,s.pitch,s.distance),i.position??w0(i.target,i.yaw,i.pitch,i.distance),n):w0(r,s.yaw+(i.yaw-s.yaw)*n,s.pitch+(i.pitch-s.pitch)*n,s.distance+(i.distance-s.distance)*n),a=k0(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:o,lookAt:a,fov:l}}function kA(t){const e=Math.max(1,t.every??33),n=Dt(t.easing??"ease-in-out"),s=`${t.scene}/${t.camera}`,i=[],r=[],o=[];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=wA(t.from,t.to,c);if(i.push({time:l,value:h.position}),r.push({time:l,value:h.lookAt}),h.fov!==void 0&&o.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:r}];return o.length>0&&a.push({id:`${s}-move-fov`,target:s,property:"fov",keyframes:o}),a}function vA(t){const e=Math.max(1,t.every??33),n=t.offset??[0,2,6],s=t.lag??0,i=`${t.scene}/${t.camera}`,r=[],o=[];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(r.push({time:a,value:[c[0]+n[0],c[1]+n[1],c[2]+n[2]]}),o.push({time:a,value:l}),a>=t.end)break}return[{id:`${i}-follow-position`,target:i,property:"position",keyframes:r},{id:`${i}-follow-lookAt`,target:i,property:"lookAt",keyframes:o}]}const va=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",...Object.fromEntries(Object.entries(cr).map(([t,e])=>[t,e.name]))}),Ma=Object.freeze({pitch:75,batter:145,bowler:35,keeper:145,field:75,overhead:75,orbit:75,"follow-ball":75,"front-foot":90,"striker-crease":90,"bowler-crease":90});function bb(t,e="pitch"){const n=ve(va,e,"cricketCamera.view");if(b0(n)){const i=yb(t,n);if(n==="front-foot"){const c=pb(t);return{target:[c.point[0],.12,(c.point[2]+i[2])/2],pitch:25,distance:Math.max(2.2,2.6*c.height/1.78),fov:40}}const r=t.landmarks[n==="striker-crease"?"striker-wicket":"bowler-wicket"];Ue(r,"cricketCamera.wicket");let o=(i[2]+r[2])/2,a=4;if(t.action==="run-out"&&n==="bowler-crease"||t.action==="running"){const c=wa(t,n);if(c){const u=ka(t,n==="bowler-crease"?"batter":"non-striker",c.time).sample.position;o=(Math.min(i[2],r[2],u[2])+Math.max(i[2],r[2],u[2]))/2,a=Math.max(4,Math.abs(r[2]-u[2])*1.8)}}let l=0;if(n==="striker-crease"&&t.action==="wide"){const c=wa(t,n);if(c){const h=ka(t,"keeper",c.time).sample.position,u=ka(t,"batter",c.time).sample.position,d=Math.min(i[0],r[0],h[0],u[0]),f=Math.max(i[0],r[0],h[0],u[0]),m=Math.min(i[2],r[2],h[2],u[2]),g=Math.max(i[2],r[2],h[2],u[2]);l=(d+f)/2,o=(m+g)/2,a=Math.max(4,Math.hypot(f-d,g-m)*1.8)}}return{target:[l,.42,o],pitch:12,distance:a,fov:44}}if(n==="follow-ball"){const i=t.scene.objects.find(r=>r.id==="camera"&&r.kind==="camera");return{pitch:Math.atan2(3,Math.hypot(5,6))*180/Math.PI,distance:Math.sqrt(70),fov:i?.kind==="camera"&&i.projection==="perspective"?i.fov:48}}const s=n==="field"||n==="overhead"||n==="orbit";return{target:n==="batter"?[.1,.85,9.3]:n==="bowler"?[.68,1,-9.55]:n==="keeper"?[0,.7,10.1]:[0,.65,0],distance:s?t.boundaryRadius*2.8:n==="pitch"?29:4.3,pitch:n==="overhead"?89:s?52:n==="pitch"?16:12,fov:s?48:n==="pitch"?50:46}}function v0(t,e,n,s){if(t!==void 0&&(!Number.isFinite(t)||t<e||t>n))throw new Error("cricketCamera: "+s+" must be between "+e+" and "+n)}function MA(t,e={}){const n=ve(va,e.view??"pitch","cricketCamera.view"),s=e.yaw??Ma[n];if(!Number.isFinite(s))throw new Error("cricketCamera: yaw must be finite");const i=(s%360+360)%360,r=e.zoom??1;if(!Number.isFinite(r)||r<.25||r>4)throw new Error("cricketCamera: zoom must be between 0.25 and 4");const o=g=>r===1?g:Math.atan(Math.tan(g*Math.PI/360)/r)*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(v0(e.pitch,0,89,"pitch"),v0(e.distance,.5,2e3,"distance"),v0(e.fov,10,100,"fov"),e.target!==void 0&&(Ue(e.target,"cricketCamera.target"),n==="follow-ball"))throw new Error("cricketCamera: target override is not supported by follow-ball");const l=bb(t,n),c=e.pitch??l.pitch,h=e.distance??l.distance,u=o(e.fov??l.fov),d=e.target?[...e.target]:l.target??[0,0,0],f=t.scene.id+"/camera",m=g=>{if(e.distance===void 0&&e.target===void 0)return g;const p=g.find(w=>w.property==="position");if(!p||!("keyframes"in p))return g;const y=t.scene.objects.find(w=>w.id==="camera"&&w.kind==="camera");let v=y?.kind==="camera"?Math.max(600,y.far):600;for(const w of p.keyframes)v=Math.max(v,Math.hypot(...w.value)+t.boundaryRadius+10);if(!Number.isFinite(v))throw new Error("cricketCamera: framing exceeds finite camera range");return[...g,{id:f+"-framing-far",target:f,property:"far",keyframes:[{time:0,value:v},{time:t.duration,value:v}]}]};if(n==="follow-ball"){const g=["x","y","z"].map(k=>{const S=t.timeline.tracks.find(T=>T.target===t.scene.id+"/ball"&&T.property===k);if(!S||!("keyframes"in S)||!S.keyframes.length)throw new Error("cricketCamera: missing ball "+k+" keyframes");const x=S.keyframes;let M=0,E=new nn({...S,keyframes:x.slice(0,2)});return T=>{const A=M;for(;M<x.length-2&&T-(S.delay??0)>x[M+1].time;)M++;return M!==A&&(E=new nn({...S,keyframes:x.slice(M,M+2)})),E.getValueAtTime(T)}}),p=(Math.atan2(5,6)*180/Math.PI+i-Ma["follow-ball"])*Math.PI/180,y=c*Math.PI/180,v=i===Ma["follow-ball"]&&(e.pitch===void 0||e.pitch===l.pitch)&&(e.distance===void 0||e.distance===l.distance)?[5,3,6]:[Math.sin(p)*Math.cos(y)*h,Math.sin(y)*h,Math.cos(p)*Math.cos(y)*h],w=vA({scene:t.scene.id,camera:"camera",start:0,end:t.duration,every:a,offset:v,subjectAt:k=>g.map(S=>S(k))});return m([...w,{id:f+"-zoom-fov",target:f,property:"fov",keyframes:[{time:0,value:u},{time:t.duration,value:u}]}])}return m(kA({scene:t.scene.id,camera:"camera",start:0,end:t.duration,every:a,easing:"linear",from:{target:d,yaw:i,pitch:c,distance:h,fov:u},to:{yaw:n==="orbit"?i+360:i}}))}const Sa=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 SA(t){const[e,n]=t.centres,s=Math.hypot(n[0]-e[0],n[2]-e[2]),i=(n[0]-e[0])/s,r=(n[2]-e[2])/s,o=[];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;o.push([l[0]+r*u+i*d,.018,l[2]-i*u+r*d])}}return o}function wb(t,e){Ue(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;Ue(s,"cricketFieldingAreaContains.centre"),Ue(i,"cricketFieldingAreaContains.centre");const r=i[0]-s[0],o=i[2]-s[2],a=r*r+o*o,l=a?Math.max(0,Math.min(1,((e[0]-s[0])*r+(e[2]-s[2])*o)/a)):0;return Math.hypot(e[0]-s[0]-l*r,e[2]-s[2]-l*o)<=n.radius+1e-9}function kb(t){return Object.keys(Ks).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??Ks[e],position:s,inside:wb(t,s)}]})}function TA(t){return t.fieldingArea?kb(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 Yt=Object.freeze({length:20.12,width:3.05,poppingCrease:1.22,returnCrease:1.32,stumpHeight:.711,wicketWidth:.2286});function vb(t){if(!t.id?.trim())throw new Error("cricketPlayer: id is required");ve({batter:1,bowler:1,keeper:1,fielder:1,umpire:1},t.role,"cricketPlayer.role");const e=ve(tr,t.preset??"youngMan","cricketPlayer.preset"),n=ve(Ge,t.format??"t20","cricketPlayer.format"),s=ve({none:1,cap:1,"sun-hat":1},t.headwear??"none","cricketPlayer.headwear"),i=e==="childBoy"||e==="childGirl",r=t.height??(i?1.24:1.78);if(!Number.isFinite(r)||r<.5||r>3)throw new Error("cricketPlayer: height must be between .5 and 3 metres");Ue(t.position??[0,0,0],"cricketPlayer.position");const o=t.role==="umpire"?"#f5ebd5":n==="test"?"#f5f0df":t.color??"#3577b5",a=JSON.parse(JSON.stringify({...tr[e],...t.appearance,outfit:ay("casual",{top:"shirt",shirt:o,trousers:t.role==="umpire"?"#405058":o,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:o}}));return{id:t.id,name:t.role,kind:"character",look:"pen",height:r,position:[...t.position??[0,0,0]],character:a,pose:t.role==="batter"?ub():{turn:t.role==="keeper"?2:0}}}function Ta(t,e,n,s,i=0){return{id:t,kind:"mesh",position:e,geometry:{type:"box",size:n},material:s,layer:i}}function EA(t,e){const n=Yt.stumpHeight,s=(Yt.wicketWidth-.036)/2;return[...[-1,0,1].map((i,r)=>({id:`${t}-stump-${r}`,kind:"mesh",position:[i*s,n/2,e],geometry:{type:"cylinder",radius:.018,height:n,segments:10},material:"wicket"})),...[-1,1].map((i,r)=>Ta(`${t}-bail-${r}`,[i*s/2,n+.015,e],[.105,.025,.035],"bail"))]}function Mb(t,e){return[{id:t,kind:"group",scale:e,visible:!1},Ta(`${t}-grip`,[0,.1,0],[.036,.28,.036],"bat-grip"),Ta(`${t}-blade`,[0,.51,0],[.108,.54,.055],"bat-blade"),Ta(`${t}-label`,[0,.41,.029],[.07,.16,.004],"bat-label")].map((s,i)=>i===0?s:{...s,parent:t})}function M0(t={}){const e=ve(Ge,t.format??"t20","cricketField.format"),n=ve(d0,t.cast??"adults","cricketField.cast"),s=ve(Sa,t.markingProfile??"icc-men","cricketField.markingProfile"),i=Sa[s],r=t.boundaryRadius??64;if(!Number.isFinite(r)||r<24||r>250)throw new Error("cricketField: boundaryRadius must be between 24 and 250 metres");const o=t.id??"cricket";if(!o.trim())throw new Error("cricketField: id is required");const a=Yt.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-Yt.poppingCrease],"bowler-crease":[0,0,-a+Yt.poppingCrease]},h=[{id:"camera",kind:"camera",projection:"perspective",position:[25,9,6],lookAt:[0,.65,0],fov:48,near:.02,far:Math.max(600,r*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:r+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:[Yt.width,Yt.length]},position:[0,.008,0],material:"pitch"},{id:"boundary",kind:"line",layer:-1,closed:!0,width:.15,color:"#f8f2db",points:Array.from({length:96},(m,g)=>[Math.cos(g*Math.PI/48)*r,.022,Math.sin(g*Math.PI/48)*r])}];l&&h.push({id:"fielding-circle",kind:"line",layer:-1,closed:!0,width:.06,color:"#d6e4c8",points:SA(l)});for(const m of[-1,1]){const g=m>0?"striker":"bowler",p=m*a,y=p-m*Yt.poppingCrease;h.push(...EA(g,p));const v=(w,k)=>h.push({id:`${g}-${w}`,kind:"line",layer:-1,color:"#fffdf0",width:.045,points:k});v("popping-line",[[-i.poppingCreaseHalfWidth,.02,y],[i.poppingCreaseHalfWidth,.02,y]]),v("bowling-line",[[-1.32,.02,p],[1.32,.02,p]]);for(const w of[-1,1])v(`return-line-${w<0?"left":"right"}`,[[w*1.32,.02,y],[w*1.32,.02,p+m*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(([m,g,p],y)=>{const v=n==="children"||n==="mixed"&&y%3===0,w=n==="men"?"youngMan":v?y%2?"childGirl":"childBoy":y%2?"youngWoman":"youngMan",k=Math.hypot(p[0],p[2]),S=k>r*.88?[p[0]*r*.88/k,0,p[2]*r*.88/k]:[...p];c[m]=[...S];const x=vb({id:m,role:g,preset:w,format:e,position:S,color:g==="batter"?t.battingColor??"#397cb9":t.fieldingColor??"#bf604e"});if(Object.hasOwn(Ks,m)&&(x.name=Ks[m]),m!=="batter"){const M=m==="non-striker"||m==="bowler"?u[0][2]:u.find(([E])=>E==="bowler")[2];x.pose={turn:Ys(S,M)}}h.push(x)});const d=m=>h.find(g=>g.id===m).height/1.78;h.push(...Mb("bat",d("batter")),...Mb("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=m=>({color:m,shading:"toon",outline:{color:"#69513a",width:.8}});return{format:e,boundaryRadius:r,landmarks:c,markingProfile:s,fieldingArea:l,scene:{id:o,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 Xt=1900,hr=2450,xt=2900,ur=4100,Tn=4200,Gs=4600,Ea=5300,S0=5500;function Aa(t,e,n,s,i,r,o=t.object.pose?.turn??0){const a=Rt(e,n,s),l=ui(i,r),c=Ys(i,r,o),h=o+(c-o)*Nt(Rt(e,n,n+200)),u={...lt,...t.object.pose,turn:h},d=Mo("run",t.who.height,1,t.object.character?.legLength??1),f=vo("run",l*a/d,u),m=Math.min(a*12,(1-a)*12,1);return{position:$n(i,r,a),pose:ba(u,f,Math.max(0,m))}}function T0(t,e,n){const s=(t.pose.turn??0)*Math.PI/2;return At(t.position,[Math.sin(s)*e,n,Math.cos(s)*e])}function AA(t,e,n,s,i){const r=`${e}/${n.object.id}`,o={...lt,...n.object.pose},a=new Set(i.flatMap(l=>Object.keys(l.pose)));for(const l of a){const c=o[l]??0;i.some(h=>h.pose[l]!==c)&&t.push({id:`${n.object.id}-${l}`,target:r,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:r,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:fb(i[u].bat.axis)}))})}}function xA(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=Ge[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 Sb(t,e={}){return Tb(t,e)}function Tb(t,e,n){const s=ve(Zn,e.action??"bowling","cricketAction.action"),i=n?n.delivery.legality==="no-ball":s==="no-ball",r=n?n.delivery.legality==="wide":s==="wide",o=n?n.delivery.style==="spin":s==="spin";ve(Ge,t.format,"cricketAction.format");const a=n?.result??xA(s,t.format),l=e.duration??6e3;if(!Number.isFinite(l)||l<4e3||l>6e4)throw new Error("cricketAction: duration must be between 4000 and 60000 ms");const c=t.scene.id;for(const $ 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(C=>C.id===$))throw new Error(`cricketAction: required equipment '${$}' is missing`);const h=Object.fromEntries(["batter","non-striker","bowler","keeper","fielder","umpire"].map($=>[$,m0(t.scene,$)]));for(const $ of["slip","point","cover","mid-off","mid-on","square-leg","fine-leg","third-man","square-umpire"])t.scene.objects.some(C=>C.id===$&&C.kind==="character")&&(h[$]=m0(t.scene,$));const u=$=>h[$].who.height,d=$=>db(h[$]),f=$=>Math.round($*6e3/l*1e9)/1e9,m=$=>$*l/6e3,g=["batting","defend","running","four","six","catch","fielding","throw","run-out"].includes(s),p=["bowling","spin","no-ball","stumping"].includes(s),y=["catch","fielding","throw","run-out","batting","running"].includes(s),v=s==="running"||s==="run-out",w=new Map,k=[d("bowler").position[0],0,i?-8.25:-9.55],S=s==="fielding"?[10.5,0,2]:[9,0,-1],x=d("fielder").position,M=($,C)=>{let z=w.get($);z||(z=new Map,w.set($,z));const X=z.get(C);if(X)return X;const W=h[$];let N=d($);if($==="bowler"){const D=N.position;if(C<1400){const G=At(k,[0,0,-.65]);N=Aa(W,C,0,1400,D,G),N.pose["arm.right.swing"]=45,N.pose["arm.right.elbow"]=80}else N.position=C<=Xt?$n(At(k,[0,0,-.65]),k,Nt(Rt(C,1400,Xt))):At(k,[0,0,.8*Nt(Rt(C,Xt,2600))]),N.pose=p0(C,[[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}],[Xt,{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}]]);o&&(N.pose={...N.pose,"arm.right.spread":18,"head.tilt":-5});for(const[G,q]of Object.entries(C<Xt?Tt.hold:Tt.open))N.pose[`hand.right.${G}`]=q}else if($==="batter"||$==="non-striker"){const D=u($);if(s==="lbw"&&$==="batter"&&(N.position[0]=0),s==="stumping"&&$==="batter"&&(N.position[2]-=1.1*Nt(Rt(C,2150,2800))),v&&C>3050){const G=M($,3050),q=$==="batter"?[1,0,-9.5]:[-1,0,9.5];N=Aa(W,C,3050,s==="run-out"?6e3:S0,G.position,q,G.pose.turn);const et=lr(W,N,"right");N.bat={grip:et,axis:Qt([.7,-.35,.5]),scale:D/1.78}}else{N.pose={...N.pose,...$==="batter"?ub():{turn:.15,"leg.left.knee":8,"leg.right.knee":8}};let q=[0,-1,$==="batter"?.05:.12],Z=At(N.position,[D*.15,D*.44,D*.04]);if($==="non-striker"&&(Z=At(N.position,[D*.08,D*.44,D*.17])),$==="batter"){const et=Nt(Rt(C,2100,2600))*(1-Nt(Rt(C,2600,xt))),H=Nt(Rt(C,2600,xt))*(1-Nt(Rt(C,xt,3800))),U=Nt(Rt(C,xt,3250))*(1-Nt(Rt(C,3250,4e3)));if(g){Z=At(N.position,[D*(.15+.03*et-.02*H-.03*U),D*(.44+.14*et+.07*H+.23*U),D*(.04+.16*et-.12*H-.06*U)]),q=Qt([.15*et+.25*U,-1+1.85*et+1.6*U,.05+.55*et-.4*H-.8*U]),N.pose.turn=1+.12*H+.3*U,N.pose.lean=3+4*H;const nt=12+4*H;N.pose["leg.left.spread"]=nt,N.pose["leg.right.spread"]=nt,s==="defend"&&(q=[0,-1,-.08],Z=At(N.position,[D*.1,D*.5,-D*.12]))}else if(["stumping","bowled","lbw"].includes(s)){const nt=Nt(Rt(C,2100,2700))*(1-Nt(Rt(C,4e3,4500)));q=Qt([.15*nt,-1+1.85*nt,.05+.55*nt]),Z=At(N.position,[D*(.15+.03*nt),D*(.44+.14*nt),D*(.04+.16*nt)])}}N=mA(W,N,Z,q)}}else if($==="keeper"){N.pose={...N.pose,turn:Ys(N.position,d("bowler").position,2),lean:20,"leg.left.swing":22,"leg.right.swing":22,"leg.left.knee":50,"leg.right.knee":50},r&&(N.position[0]=2.15*Nt(Rt(C,2900,3500))),s==="stumping"&&(N.position[2]-=.85*Nt(Rt(C,3400,3900)));const D=T0(N,u($)*.27,u($)*.44);if(s==="stumping"&&C>=3500){const G=T0({...N,position:d($).position},u($)*.27,u($)*.44),q=[0,Yt.stumpHeight,Yt.length/2],Z=$n(G,q,Nt(Rt(C,3500,3900)));N=Sn(W,N,"right",Z),N=Sn(W,N,"left",At(Z,[.045,0,0]))}else N=Sn(W,N,"right",D),N=Sn(W,N,"left",At(D,[.045,0,0]))}else if($==="fielder"&&y){if(N=Aa(W,C,3050,s==="catch"?3800:3950,x,S),C>=3800){const D={...lt,turn:Ys(S,d("batter").position,N.pose.turn),lean:s==="catch"?5:42,bend:s==="catch"?0:18,"leg.left.swing":s==="catch"?0:45,"leg.right.swing":s==="catch"?0:45,"leg.left.knee":s==="catch"?0:85,"leg.right.knee":s==="catch"?0:85,smile:.7};N.pose=ba(N.pose,D,Nt(Rt(C,3800,Tn)));const G=T0(N,u($)*.22,u($)*(s==="catch"?.73:.2));if(N=Sn(W,N,"right",G),N=Sn(W,N,"left",At(G,[.035,0,0])),(s==="throw"||s==="run-out")&&C>Tn){const q={...lt,turn:Ys(S,s==="throw"?d("keeper").position:t.landmarks["bowler-wicket"],N.pose.turn),"arm.right.swing":225,"arm.right.elbow":60,"arm.left.spread":70,"leg.left.swing":15},Z={...q,"arm.right.swing":110,"arm.right.elbow":0,lean:15};N.pose=p0(C,[[Tn,N.pose],[4450,q],[Gs,Z],[4900,{...lt,turn:q.turn,"arm.right.swing":25,lean:22}],[6e3,{...lt,turn:q.turn}]])}}}else if($==="umpire"){let D={...lt};const G=s==="stumping"?4150:s==="run-out"?5150:s==="bowled"||s==="lbw"?3500:s==="catch"?4350:5100;if(s==="no-ball")D={...D,"arm.right.spread":90,"arm.right.elbow":0};else if(s==="wide")D={...D,"arm.right.spread":90,"arm.left.spread":90,"arm.right.elbow":0,"arm.left.elbow":0};else if(s==="six")D={...D,"arm.right.spread":180,"arm.left.spread":180,"arm.right.elbow":0,"arm.left.elbow":0};else if(s==="four")D={...D,"arm.right.spread":90-70*(.5+Math.sin((C-5100)/180)*.5),"arm.right.elbow":12};else if(["catch","bowled","lbw","stumping","run-out"].includes(s)){D={...D,"arm.right.swing":165,"arm.right.elbow":0};for(const[q,Z]of Object.entries(Tt.point))D[`hand.right.${q}`]=Z}if(n){const q={...lt},Z=[[0,q]];let et=q;if(i||r){const H=i?Xt:3100;et=i?{...q,"arm.right.spread":90,"arm.right.elbow":0}:{...q,"arm.right.spread":90,"arm.left.spread":90,"arm.right.elbow":0,"arm.left.elbow":0},Z.push([H,q],[H+350,et])}if(a.wickets||s==="four"||s==="six"){const H=a.wickets?G:5100;let U=D;if(a.wickets){U={...q,"arm.right.swing":165,"arm.right.elbow":0};for(const[nt,at]of Object.entries(Tt.point))U[`hand.right.${nt}`]=at}Z.push([H,et],[H+350,U])}N.pose=p0(C,Z)}else N.pose=ba(N.pose,D,Nt(Rt(C,s==="no-ball"?Xt:s==="wide"?3100:G,(s==="no-ball"?Xt:s==="wide"?3100:G)+350)))}return z.set(C,N),N},E=($,C)=>lr(h[$],M($,C),"right"),T=g?pA(M("batter",xt).bat):s==="lbw"?$n(Xs(h.batter,M("batter",xt),"leg.right",1),Xs(h.batter,M("batter",xt),"leg.right",2),.6):[p?Yt.wicketWidth/2+.075+.15:0,.45,9.25],A=E("bowler",Xt),P=[r?.85:o?-.35:s==="lbw"?T[0]*.6:0,.075,3.9],I=E("keeper",s==="stumping"?3400:3500),O=E("fielder",ur),_=E("fielder",Tn),L=s==="run-out"?"bowler":"striker",j=s==="run-out"?5e3:s==="stumping"?3900:3200,V=[t.boundaryRadius*.8,s==="six"?2.1:.075,-t.boundaryRadius*.6],tt=($,C,z,X,W,N=0,D=0)=>y0({target:`${c}/ball`,start:C,end:z,from:X,to:W,arc:N,curve:D},$),J=$=>{if($<=Xt)return E("bowler",$);if($<=hr)return tt($,Xt,hr,A,P,.15,o?.35:0);const C=r?At(I,[0,0,-.6]):T;if($<=xt)return tt($,hr,xt,P,C,.08);if(s==="bowled"){const X=[0,.36,Yt.length/2];return $<=j?tt($,xt,j,T,X):tt($,j,4100,X,[0,.075,12.5],.2)}if(s==="lbw")return[...T];if(["bowling","spin","no-ball","wide","stumping"].includes(s)){const X=s==="stumping"?3400:3500;if(p&&$<=X){const W=[C[0],I[1],Yt.length/2+.2];return $<=3200?tt($,xt,3200,C,W,.04):tt($,3200,X,W,I,.04)}return $<=X?tt($,xt,X,C,I,.04):E("keeper",$)}if(s==="defend")return tt($,xt,3400,T,At(T,[-.5,-T[1]+.075,-.7]),.12);if(s==="four"||s==="six"){if(s==="six")return $<=5e3?tt($,xt,5e3,T,V,12):tt($,5e3,5700,V,At(V,[2,-2.025,-1.5]));const X=[5,.075,5];return $<=3300?tt($,xt,3300,T,X,.5):tt($,3300,5e3,X,V)}if(s==="catch")return $<=ur?tt($,xt,ur,T,O,5):E("fielder",$);const z=[4,.075,5];if($<=3300)return tt($,xt,3300,T,z,.8);if($<=Tn)return tt($,3300,Tn,z,_);if(s==="throw"||s==="run-out"){if($<=Gs)return E("fielder",$);const X=E("fielder",Gs),W=s==="run-out"?[0,.42,-Yt.length/2]:E("keeper",Ea),N=s==="run-out"?j:Ea;return $<=N?tt($,Gs,N,X,W,1.2):s==="run-out"?tt($,N,5700,W,[0,.075,-12],.18):E("keeper",$)}return[..._]},F=[],B=($,C,z,X,W)=>F.push({id:$,time:m(C),kind:z,label:X,caption:W}),Y=n?{bowled:"Delivery hits stumps",lbw:"Pad contact",stumping:"Keeper breaks wicket","run-out":"Throw breaks wicket"}[s]??Zn[s].name:Zn[s].name;if(B("setup",0,"setup",Y,n?`${n.delivery.style} delivery · ${n.delivery.legality}${n.freeHit?" · free hit":""}. ${Zn[s].summary.replace("A legal delivery","A delivery")}`:Zn[s].summary),B("release",Xt,"release","Ball released",i?"The front foot has landed beyond the popping crease. No-ball.":"The bowler releases the ball; the front foot is behind the popping crease."),B("bounce",hr,"bounce","Pitch bounce",o?"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."),g?B("contact",xt,"contact","Bat contact","The ball meets the blade. The bat is keyed from the same two hand grips."):s==="lbw"?B("pad-contact",xt,"contact","Pad contact",n?"The ball contacts the pad. The highlighted path is illustrative; the authored decision is resolved separately.":"The highlighted path illustrates a ball that would hit the stumps. This is an authored LBW example."):B("miss",xt,"contact",s==="wide"?"Beyond normal reach":"The batter misses",s==="wide"?"The untouched ball is too far away for a normal stroke. The umpire calls Wide.":"The untouched delivery passes the striker."),s==="catch"&&B("catch",ur,"collect","Catch controlled",n?"The fielder controls the ball before it touches the ground. The authored decision is resolved separately.":"The fielder controls the ball before it touches the ground: caught."),["fielding","throw","run-out","batting","running"].includes(s)&&B("gather",Tn,"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(s)&&B("keeper",s==="stumping"?3400:3500,"collect","Keeper gathers","The keeper controls the ball behind the striker’s wicket."),(s==="throw"||s==="run-out")&&B("throw",Gs,"throw","Throw released","The fielder releases the gathered ball toward the wicket."),s==="throw"&&B("return",Ea,"collect","Return received","The keeper receives and controls the return throw."),s==="stumping"&&B("wicket",j,"wicket",n?"Wicket broken":"Stumped","Holding the ball, the keeper removes a bail. The striker is out of ground and is not attempting a run."),s==="run-out"&&B("wicket",j,"wicket",n?"Wicket broken":"Run out","The direct throw removes a bail before the running batter makes this ground."),s==="bowled"&&B("wicket",j,"wicket",n?"Stumps hit":"Bowled",n?"The delivery hits the wicket and removes a bail. A broken wicket does not by itself decide a dismissal.":"The legal delivery hits the wicket and removes a bail."),(s==="four"||s==="six")&&B("boundary",5e3,"boundary",s==="four"?"Four runs":"Six runs",s==="four"?"The struck ball reaches the boundary after touching the ground: four.":"The struck ball clears the boundary without touching the ground: six."),s==="running"&&B("run",S0,"result","One run completed","Both batters have reached the opposite ground. One run is completed."),B("result",5700,"result","Illustrated result",s==="no-ball"?`One no-ball extra; it does not count in the over.${a.freeHitNext?" The next legitimate delivery is a free hit.":" Test cricket has no automatic free hit."}`:s==="wide"?"One wide extra; the delivery does not count in the over.":s==="lbw"?"LBW is declared for this illustrated legal delivery. A full decision also checks pitching, impact and any bat contact.":`${a.runs} bat runs · ${a.extras} extras · ${a.wickets} wicket${a.wickets===1?"":"s"}.`),n){const $={"no-dismissal":"No dismissal was authored for this play.",dismissal:`The authored ${n.ruling.dismissal} decision is allowed in this delivery context.`,"no-ball":`Not out: ${s==="catch"?"a catch":"this dismissal"} cannot dismiss the striker on a no-ball.`,"free-hit":`Not out: ${s==="catch"?"a catch":"this dismissal"} cannot dismiss the striker on a free hit.`,wide:"Not out: this dismissal is not available from a Wide."},C=F.find(z=>z.id==="result");C.label=a.wickets?"Out":"Not out",C.caption=`${$[n.ruling.reason]} ${a.runs} bat runs · ${a.extras} extras · ${a.wickets} wickets. ${a.legalBall?"Counts as a legal ball.":"Does not count in the over."}${a.freeHitNext?" The next delivery is a free hit; an illegal delivery carries it forward.":n.freeHit?" This legal delivery consumes the free hit.":""}`}F.sort(($,C)=>$.time-C.time);const R=gb(0,l,e.every,[1400,1800,Xt,2100,2150,2250,hr,2600,2800,xt,3050,3100,3200,3250,3300,3400,3500,3800,3900,3950,4e3,ur,Tn,4350,4450,Gs,4900,5e3,5100,5150,Ea,S0,5700].map(m)),K=R.map($=>J(f($))),st=[];for(const[$,C]of Object.entries(h)){let z=C.object.pose?.turn??0,X=z;const W=R.map((N,D)=>{const G=f(N);let q=$==="fielder"&&y&&G>3050&&G<3250?Aa(C,G,3050,s==="catch"?3800:3950,x,S,X):M($,G),Z=K[D];const et=!["batter","non-striker","bowler","keeper"].includes($);if(et){const U=M("bowler",Math.min(G,Xt)),nt=At(U.position,[0,u("bowler")*.8,0]);Z=G<=Xt?nt:G<2100?$n(nt,Z,Nt(Rt(G,Xt,2100))):Z}if(v&&($==="batter"||$==="non-striker")&&G>3050&&(Z=$==="batter"?[1,u($)*.8,-10.5]:[-1,u($)*.8,10.5]),$==="bowler"&&G<=xt&&(Z=At(M("batter",G).position,[0,u("batter")*.65,0])),et&&($!=="fielder"||!y||G<=3050)||$==="bowler"&&G>=3e3){const U=Ys(q.position,Z,z);z=$==="bowler"&&G<3500?(q.pose.turn??0)+(g0(U,q.pose.turn??0)-(q.pose.turn??0))*Nt(Rt(G,3e3,3500)):U,q={...q,pose:{...q.pose,turn:z}}}return $==="fielder"&&y&&(G===3050?X=z:G>3050&&(z=g0(q.pose.turn??0,z),q={...q,pose:{...q.pose,turn:z}})),gA(C,q,Z)});AA(st,c,C,R,W)}for(const[$,C]of["x","y","z"].entries())st.push({id:`ball-${C}`,target:`${c}/ball`,property:C,keyframes:R.map((z,X)=>({time:z,value:K[X][$]}))});if(["bowled","stumping","run-out"].includes(s))for(let $=0;$<2;$++){const C=`${L}-bail-${$}`,X=t.scene.objects.find(W=>W.id===C).position;st.push({id:`${C}-fall`,target:`${c}/${C}`,property:"position",keyframes:[{time:0,value:[...X]},{time:m(j),value:[...X]},{time:m(j+180),value:At(X,[$?.25:-.25,.22,L==="striker"?.22:-.22]),easing:"ease-out"},{time:m(j+650),value:[X[0]+($?.4:-.4),.035,X[2]+(L==="striker"?.45:-.45)],easing:"ease-in"}]}),st.push({id:`${C}-spin`,target:`${c}/${C}`,property:"rotateZ",keyframes:[{time:0,value:0},{time:m(j),value:0},{time:m(j+650),value:$?145:-145}]})}if(s==="lbw"){const $=[T[0]*.8,T[1],Yt.length/2],C=oe($,T);st.push({id:"lbw-position",target:`${c}/lbw-guide`,property:"position",keyframes:[{time:0,value:[...T]}]},{id:"lbw-rotation",target:`${c}/lbw-guide`,property:"quaternion",interpolation:"slerp",keyframes:[{time:0,value:fb(C)}]},{id:"lbw-length",target:`${c}/lbw-guide`,property:"scaleY",keyframes:[{time:0,value:ui(T,$)}]},{id:"lbw-visible",target:`${c}/lbw-guide`,property:"visible",keyframes:[{time:0,value:0},{time:m(xt)-.001,value:0},{time:m(xt),value:1}]})}return{action:s,duration:l,events:F,result:a,timeline:{id:`${c}-${s}`,formatVersion:2,name:Y,config:{duration:l,markers:F.map($=>({id:$.id,time:$.time,label:$.label}))},captions:{en:Object.fromEntries(F.map($=>[$.id,$.caption]))},tracks:st}}}function PA(t={}){const e=M0(t);return{...e,...Sb(e,t)}}function $A(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}const En=Object.freeze({deliveryStyles:Object.freeze(["pace","spin"]),deliveryLegalities:Object.freeze(["legal","no-ball","wide"]),shots:Object.freeze(["miss","drive","defend"]),finishes:Object.freeze(["none","single","four","six","stumps","pad"]),fielding:Object.freeze(["none","keeper","catch","gather","throw","stumping","run-out"]),dismissals:Object.freeze(["caught","bowled","lbw","stumped","run-out"])});function Us(t,e,n){if(!t.includes(e))throw new Error(`cricketPlay.${n}: unknown choice '${e}'`);return e}function IA(t){const{shot:e,finish:n,fielding:s}=t;if(t.delivery.legality==="wide"){if(e!=="miss"||n!=="none"||s!=="keeper")throw new Error("cricketPlay: Wide currently supports only an untouched delivery gathered by the keeper");return"wide"}if(e==="miss"){if(s==="none"&&n==="stumps")return"bowled";if(s==="none"&&n==="pad")return"lbw";if(n==="none"&&s==="stumping")return"stumping";if(n==="none"&&s==="keeper")return t.delivery.style==="spin"?"spin":"bowling"}if(e==="defend"&&n==="none"&&s==="none")return"defend";if(e==="drive"){if(s==="none"&&(n==="four"||n==="six"))return n;if(s==="gather"&&n==="single")return"running";if(n==="none"){if(s==="catch")return"catch";if(s==="gather")return"fielding";if(s==="throw")return"throw";if(s==="run-out")return"run-out"}}throw new Error(`cricketPlay: unsupported motion combination (${e}, ${n}, ${s})`)}function OA(t){const e=Us(En.shots,t.shot??"miss","shot"),n=Us(En.finishes,t.finish??"none","finish");let s=e==="miss"?"keeper":"gather";(e==="defend"||n!=="none")&&(s=n==="single"?"gather":"none");const i=Us(En.fielding,t.fielding??s,"fielding"),r=t.context?.freeHit??!1;if(typeof r!="boolean")throw new Error("cricketPlay.context.freeHit must be boolean");const o=t.decision?.dismissal??null;return o!==null&&Us(En.dismissals,o,"decision.dismissal"),{delivery:{style:Us(En.deliveryStyles,t.delivery?.style??"pace","delivery.style"),legality:Us(En.deliveryLegalities,t.delivery?.legality??"legal","delivery.legality")},shot:e,finish:n,fielding:i,context:{freeHit:r},decision:{dismissal:o}}}function CA(t,e){const n=t.decision.dismissal;if(!n)return{dismissal:null,reason:"no-dismissal"};if({catch:"caught",bowled:"bowled",lbw:"lbw",stumping:"stumped","run-out":"run-out"}[e]!==n)throw new Error(`cricketPlay: '${n}' decision does not match '${e}' motion`);if(n!=="run-out"){if(t.context.freeHit)return{dismissal:null,reason:"free-hit"};if(t.delivery.legality==="no-ball")return{dismissal:null,reason:"no-ball"};if(t.delivery.legality==="wide"&&n!=="stumped")return{dismissal:null,reason:"wide"}}return{dismissal:n,reason:"dismissal"}}function Eb(t,e={}){const n=ve(Ge,t.format,"cricketPlay.format"),s=OA(e);if(s.context.freeHit&&!Ge[n].freeHitAfterNoBall)throw new Error("cricketPlay: Test format does not support free-hit context");const i=IA(s),r=CA(s,i),o=s.delivery.legality==="legal",a={runs:s.finish==="single"?1:s.finish==="four"?4:s.finish==="six"?6:0,extras:o?0:1,wickets:r.dismissal?1:0,legalBall:o,freeHitNext:Ge[n].freeHitAfterNoBall&&(s.delivery.legality==="no-ball"||s.context.freeHit&&!o),...r.dismissal?{dismissal:r.dismissal}:{}};return{...Tb(t,{action:i,duration:e.duration,every:e.every},{delivery:s.delivery,result:a,ruling:r,freeHit:s.context.freeHit}),play:s,ruling:r}}function _A(t={}){const e=M0(t);return{...e,...Eb(e,t)}}const Ab=Object.freeze({"no-ball-stumps":Object.freeze({name:"No-ball + stumps hit",options:Object.freeze({delivery:Object.freeze({legality:"no-ball"}),finish:"stumps",decision:Object.freeze({dismissal:"bowled"})})}),"free-hit-catch":Object.freeze({name:"Free hit + catch",options:Object.freeze({context:Object.freeze({freeHit:!0}),shot:"drive",fielding:"catch",decision:Object.freeze({dismissal:"caught"})})}),"no-ball-four":Object.freeze({name:"No-ball + four",options:Object.freeze({delivery:Object.freeze({legality:"no-ball"}),shot:"drive",finish:"four"})}),"free-hit-run-out":Object.freeze({name:"Free hit + run-out",options:Object.freeze({context:Object.freeze({freeHit:!0}),shot:"drive",fielding:"run-out",decision:Object.freeze({dismissal:"run-out"})})}),"free-hit-wide":Object.freeze({name:"Free hit + Wide",options:Object.freeze({context:Object.freeze({freeHit:!0}),delivery:Object.freeze({legality:"wide"})})})}),RA={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 xb(t,e={}){const n={};for(const s of Object.keys(Gt))n[s]={summary:`Walks to \`to\` in the ${s} gait.`,needs:["to"]};for(const s of Object.keys(he))n[s]={summary:`Moves into the ${s} pose and holds it (\`for\` ms).`};for(const s of Object.keys(mn))n[s]={summary:`The ${s} gag (${nr(s)} ms).`};for(const[s,i]of Object.entries(sr))n[s]={...i};return{sports:{cricket:{actions:{...Zn},formats:{...Ge},casts:{...d0},fieldingPositions:{...Ks},markingProfiles:{...Sa},cameras:{...va},decisionCameras:cr,playComponents:En,playExamples:Ab}},...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(RA),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:ca,stickFigure:{poseFields:Zd,props:Qd,handFields:tf,poses:Object.keys(he),expressions:Object.keys(Mt),gags:Object.fromEntries(Object.keys(mn).map(s=>[s,nr(s)])),gaits:Object.keys(Gt),actingStyles:Object.keys(Xn),beatFields:Vo,actions:n,dances:Object.fromEntries(Object.entries(ln).map(([s,i])=>[s,Object.keys(i.moves)])),flips:Object.fromEntries(Object.entries(Ki).map(([s,i])=>[s,i.label])),handShapes:Object.keys(Tt),mudras:Object.keys(Jr)},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:pa,commonControls:Object.fromEntries(Object.entries(Ds).map(([s,i])=>[s,`${i.description}${i.unit?` (${i.unit})`:""}`])),commonActions:Object.fromEntries(Object.entries(h0).map(([s,i])=>[s,i.summary])),presets:Object.fromEntries(Object.entries(js).map(([s,i])=>{const r=i();return[s,{family:r.family,summary:r.summary,actions:Object.fromEntries(Object.entries(r.actions).map(([o,a])=>[o,{summary:a.summary,...a.needs?{needs:a.needs}:{}}])),controls:Object.keys(r.rig.controls),anchors:Object.keys(r.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","bean"],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.measurements":`Organic torso from tape-measure girths { height, bust, underbust?, waist, hip } in any one unit, or a named shape (${Object.keys(ho).join(" | ")}). Sets the front width, the side depth (bust forward, seat back, belly) and the hip and thigh spacing; reads correctly at every turn. An explicit torso / torsoFront / torsoBack / hipWidth still wins.`,"body.torsoFront · body.torsoBack":"Organic side-view depth from the spine line toward the chest/belly and toward the back/seat, same profile format; default torso × depth.","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.","figure: 'bean'":"The white outlined stick figure: one smooth stroked outline per limb (no seams at elbows, knees or the front arm's shoulder), a shaped body (rounded shoulders, slight waist, fuller hips), big oval eyes, mittens and cartoon shoes; every pose, gait, dance and turn works. Always drawn clean; the near arm is in front of the body in both limb modes. `bean: { limbs: tube | line, halo (a pale edge on line limbs), torso, limbWidth, lineWidth, outlineWidth, fill, shirt, sleeves: short | long | none, trousers, shoes (a dark shoe gets a shine), coat (a trench coat: lapels, belt and buckle, buttons, knee hem, sleeves to the wrist), fedora, shades (aviators in place of the eyes; brows still show) }`; an `outfit`'s shirt, trousers and sleeves colour it. `castMember('beanMan' | 'beanWoman' | 'beanKid' | 'beanBoss' | 'beanDetective' | 'beanStick', h)`.",hands:"`dot` | `cartoon` (with `handStyle: glove | natural`) | `mitten` (a plain oval mitten; the bean figure's default)",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(Ae),dances:Object.keys(Nn),expressions:Object.keys(oc),faceStyles:["simple","anime","oval"],faceShapes:["round","angular"],gags:Object.keys(So),builds:Object.keys(so),hair:Object.keys(Ac),hairColors:{...Fe},facialHair:Object.keys(Oc),glasses:Object.keys(_c),hats:Object.keys(ko),feet:[...ng],cast:Object.keys(Th),heldItems:Object.fromEntries(Object.entries(Lc).map(([s,i])=>[s,i.hands])),handMeetings:Object.keys(er)},noir:Vy,codePanel:{languages:Yo,removeStyles:jo,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:bh},surfaces:{code:Ji,board:je,chart:Kn,prop:zs},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: ${Ns.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"},math:{api:{"mathFigure(spec)":"checks a figure (JSON: width, height, x?, y?, theme?: dark | light | chalk, values, items) and says how to fix it","layoutFigure(spec, props)":"the figure at some values as shapes; drawDisplayList(ctx, list) or displayListToSvg(list) draws them","mathTarget(spec, { x, y })":"a canvas target for videos and canvas pages; tracks animate its values and item props","mathSteps(lesson, target, spec, { hidden })":"lesson steps: toValue, applyMatrix, drawOn, fadeIn, fadeOut, showStep (equations)","mountMath(element) / mountAllMath()":"lesson-page embeds: <figure data-tinyfly-math> with data-tinyfly-figure and data-tinyfly-timeline JSON scripts, stepped like any embed","lossSurface3D({ expr, start, rate, momentum?, steps?, orbit? })":"a loss surface as scene-3d JSON with a ball rolling down the descent path: { scene, tracks, duration, path, losses }","mathSurface(figure, { x, y })":"a figure as a surface for surfaceScript: anchors box, item:ID, tip:ID, point:ID, node:GRAPH:NODE, term:ID:TEXT, value:NAME; edits drawOn, erase, show, hide, step, set","mathExplorable(element, spec, { sliders, drag })":"reader-driven figures: sliders on number values, drag vector tips or matrix columns","mathFigureToSvg(spec, props)":"a standalone SVG of a figure at some values","linearMapFigure, determinantFigure, eigenFigure, vectorSumFigure, spanFigure":"ready linear algebra figures; the matrix is the value M","tangentFigure, secantFigure, riemannFigure, areaFigure, taylorFigure, limitFigure":"ready calculus figures; their moving parts are number values (a, h, n, b, order, p)","differentiate / compileDerivative / integrate":"exact symbolic derivatives of expressions; Simpson integration","normalFigure, binomialFigure, cltFigure, galtonFigure, monteCarloPiFigure, regressionFigure, bayesFigure":"ready probability and statistics figures","graphSearchFigure, shortestPathFigure, recursionTreeFigure, vennFigure, clockFigure":"ready discrete maths figures; searches move with the value step","searchEvents / parseSetExpression / regionCells":"graph searches as data; set expressions and their Venn cells","neuralNetworkFigure, gradientDescentFigure, attentionFigure, decisionBoundaryFigure, kmeansFigure, activationFigure":"ready AI/ML figures",distributions:"{ kind: normal | uniform | exponential | binomial | poisson | dice | mean, …numbers or value names }; density, meanOf, sdOf, samples (seeded)","layoutTex(tex) / morphEquation(a, b, t)":"the built-in TeX subset, and term-by-term transitions","vec2, mat2":"2D vectors and 2×2 matrices (apply, multiply, determinant, inverse, eigen)"},items:{grid:"{ step?, transform?: matrix value, ghost? }: lines of the plane, warped by a matrix",axes:"{ ticks?, labels? }",vector:"{ to, from?, transform?, label? (TeX), labelAt?: tip | middle }",basis:"{ transform? }: î and ĵ",point:"{ at, transform?, label?, hollow? } or { on: expr, x } (a point riding a curve)",function:'{ expr: "sin(k x)", domain?, derivative?, dashed? }: y = f(x); number values are its parameters',parametric:"{ x, y (expressions in t), t?, transform? }",polygon:"{ points? (default the unit square), transform?, label? }: \\val{M.det} shows the determinant",line:"{ along } or { eigen: matrix value }: a span, or eigenlines",label:"{ tex, at, screen?, size?, align?, backdrop? }",equation:"{ steps: [TeX…], at, screen? }: ITEM.step moves between steps, terms gliding",tangent:"{ expr, at, h? (secant), label? }: \\val{ID.slope} is the exact slope",riemann:"{ expr, from, to, n, rule?: left | right | midpoint | trapezoid }: \\val{ID.sum}, \\val{ID.exact}",area:"{ expr, from, to, lower? }: signed, coloured by sign; \\val{ID.value}",taylor:"{ expr, at, order }: exact Taylor polynomials; a fractional order grows the next term in",histogram:"{ distribution, count, bins?, scale?, curve?, seed? }: seeded samples, binned; fills as count grows",distribution:"{ distribution, shade?: [a, b] }: a density curve (bars when discrete); \\val{ID.p}",galton:"{ rows?, balls, spacing?, top?, seed? }: a Galton board; fractional balls = the next one falling",scatter:"{ points: uniform | linear, count, inside?, fit?, seed? }: Monte Carlo and regression; \\val{ID.ratio}, \\val{ID.r}",bayes:"{ prior, truePositive, falsePositive }: Bayes as areas; \\val{ID.posterior}",graph:"{ nodes, edges, directed?, tree?, search?: { kind: bfs | dfs | dijkstra, start }, step?, frontier? }: searches step by step",venn:"{ sets (2 or 3), highlight?: set expression like (A | B)' }: shaded by clipping",clock:"{ modulus, value }: clock arithmetic; \\val{ID.hour}",network:"{ layers, activation?, inputs?, flow?, seed?, labels? }: a forward pass, layer by layer",heatmap:"{ cells (softmax? per row) or expr in x, y; colormap?, rowLabels?, colLabels?, values? }: attention maps, loss fields",contours:"{ expr in x, y, levels? }: level curves (marching squares)",descent:"{ expr in x, y, start, rate, steps, momentum? }: gradient descent with an exact gradient",classifier:"{ epochs, centres?, rate?, start? }: logistic regression training; \\val{ID.accuracy}",kmeans:"{ centres, iteration, k? }: Lloyd iterations; \\val{ID.inertia}"},props:{NAME:"a value: a number, [x, y] vector or [a, b, c, d] matrix (row by row; columns are where î and ĵ land)","ITEM.draw":"0..1, draws an item on","ITEM.opacity":"0..1","ITEM.step":"an equation's step; fractional values are part way"},functions:["sin","cos","tan","asin","acos","atan","atan2","sinh","cosh","tanh","exp","ln","log","log2","sqrt","abs","floor","ceil","round","sign","min","max","sigmoid","relu"],tex:"^ _ \\frac \\sqrt \\vec \\hat \\bar, \\sum \\prod \\int with limits, \\sin \\lim … , Greek, \\cdot \\times \\le \\to \\infty …, pmatrix / bmatrix / vmatrix, \\text, \\color{c}{…}, \\id{name}{…} (names a term for transitions), \\val{name:digits} (a live value)"},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 mt=t=>t.map(e=>`\`${e}\``).join(", "),Pb=t=>Object.entries(t).map(([e,n])=>`| \`${e}\` | ${n.unit??n.kind??""} | ${n.description} |`).join(`
|
|
65
65
|
`);function HA(t,e={}){const n=xb(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: ${mt(n.easings.named)}.`,"",...Object.entries(n.easings.parametric).map(([r,o])=>`- ${r}: \`${o}\``),"","## Track kinds","",...Object.entries(n.trackKinds).map(([r,o])=>`- **${r}**: ${o}`),"","## 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(([r,o])=>`| \`${r}\` | ${o.unit??o.kind??""} | ${o.description} | ${o.types.length===7?"all":o.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 |","|---|---|---|",Pb(s.poseFields),"","### Other props","","| Prop | Unit | What it does |","|---|---|---|",Pb(s.props),"",`With \`style.hands\`, each hand has \`hand.left.<field>\` / \`hand.right.<field>\` props: ${mt(Object.keys(s.handFields))}.`,"",`**Poses** (a beat's \`do\`, or a pose key): ${mt(s.poses)}.`,"",`**Expressions** (a beat's \`mood\`): ${mt(s.expressions)}.`,"",`**Gags** (ms): ${Object.entries(s.gags).map(([r,o])=>`\`${r}\` (${o})`).join(", ")}.`,"",`**Gaits**: ${mt(s.gaits)}. **Acting styles** (\`style\`): ${mt(s.actingStyles)}.`,"","### Beat scripts","",`\`scriptTracks(target, beats, { from, ground, height, facing, style })\`. A beat has these fields only: ${mt(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(([r,o])=>`| \`${r}\` | ${(o.needs??[]).map(a=>`\`${a}\``).join(", ")} | ${o.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(([r,o])=>`\`${r}\` (${o.join(", ")})`).join("; ")}.`,"",`**Flips**: ${Object.entries(s.flips).map(([r,o])=>`\`${r}\` (${o})`).join(", ")}.`,"",`**Hand shapes**: ${mt(s.handShapes)}. **Mudras**: ${mt(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(([r,o])=>`- \`${r}\`: ${o}`),"",...Object.keys(n.custom.actions).length||Object.keys(n.custom.gaits).length?["**This cast’s own:**","",...Object.entries(n.custom.actions).map(([r,o])=>`- \`${r}\`${o.needs?.length?` (needs ${o.needs.map(a=>`\`${a}\``).join(", ")})`:""}: ${o.summary}`),...Object.entries(n.custom.gaits).map(([r,o])=>`- \`${r}\` (gait): ${o}`),""]:[],"## 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(([r,o])=>`- \`${r}\`: ${o}`),"",`Prop beat fields: ${mt(n.props.beatFields)}. Every prop has the controls ${Object.keys(n.props.commonControls).map(r=>`\`${r}\``).join(", ")} and the actions ${Object.keys(n.props.commonActions).map(r=>`\`${r}\``).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(([r,o])=>`| \`${r}()\` | ${o.family} | ${Object.entries(o.actions).map(([a,l])=>`\`${a}\`${l.needs?.length?` (${l.needs.join(", ")})`:""}`).join(", ")} | ${o.controls.map(a=>`\`${a}\``).join(", ")} | ${o.anchors.join(", ")} |`),"","## Character (v2 human)","",`Poses: ${mt(n.character.poses)}. Expressions: ${mt(n.character.expressions)}. Gags: ${mt(n.character.gags)}.`,`Native dances: ${mt(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\`: ${mt(n.character.builds)}`,`- \`figure\`: ${mt(n.character.figureStyles)}`,"- `look`: `clean` (default), `pencil`, `silhouette`, `illustrated` (inked and painted: line weight follows the light, brush-tapered strokes, shadow/core/highlight tones from each fill; `illustrated: { light: [x, y], weight, taper, shadow, highlight }`, each 0–1)",...Object.entries(n.character.body).map(([r,o])=>`- \`${r}\`: ${o}`),`- \`hair\`: ${mt(n.character.hair)} (colours: ${mt(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\`: ${mt(n.character.facialHair)}`,`- \`glasses\`: ${mt(n.character.glasses)}; \`hat\`: ${mt(n.character.hats)}; \`ears: true\`; \`face: { teeth, tongue }\` (shown when the mouth opens); \`feet\`: ${mt(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)\`: ${mt(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: ${mt(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: { style: 'oval' }\` (the bean figure's default) draws big white oval eyes with small pupils that follow \`lookX\`/\`lookY\`, lids for \`lid\`, \`blink\` and half-open eyes, and heavy brows for \`brow.*\`/\`browTilt\`; glasses grow to fit round them.`,`- Face shapes: ${mt(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(([r,o])=>`\`${r}\` (${o==="both"?"both":o==="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): ${mt(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' }`)","","## Noir / detective kit","","Canvas drawing functions for detective and noir scenes (see docs/noir-detective.md). Times are ms; every one is a pure function of its options and the time (rain is seeded), so frames draw the same in any order. Text and fonts are the caller’s.","",...["atmosphere","overlays","caseBoard"].flatMap(r=>Object.entries(n.noir[r]).map(([o,a])=>`- \`${o}\`: ${a}`)),"",`Case board cards: ${n.noir.card}, kinds ${mt(n.noir.cardKinds)}. Strings: ${n.noir.string}. Marks: ${n.noir.mark}, kinds ${Object.entries(n.noir.markKinds).map(([r,o])=>`\`${r}\` (${o})`).join(", ")}.`,"","## Code panel","",`\`codePanel({ code, language, x, y, fontSize?, lineHeight?, width? })\`: a code listing as a scene object. Languages: ${mt(n.codePanel.languages)}. Remove styles: ${mt(n.codePanel.removeStyles)}.`,"",...Object.entries(n.codePanel.anchors).map(([r,o])=>`- \`${r}\`: ${o}`),"",...Object.values(n.codePanel.edits).map(r=>`- \`${r.split(":")[0]}\`:${r.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(([r,o])=>`- \`${r}\`: ${o}`),"",...Object.entries(n.surfaces).flatMap(([r,o])=>[`### ${r}`,"",...o.create?[`\`${o.create}\``,""]:[],"Anchors:",...Object.entries(o.anchors).map(([a,l])=>`- \`${a}\`: ${l}`),"","Edits:",...Object.entries(o.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: ${mt(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.`,"","`cricketPlay(field, options)` / `cricketPlayClip(options)` independently author delivery style/legality, shot, finish, fielding, current free-hit context and candidate dismissal. Omitted dismissal means no dismissal. Unsupported motion combinations throw; no-ball/free-hit protection changes result/signals without removing physical catches or wicket breaks. Run-out remains available. Illegal free hits carry forward; legal ones consume context. Test rejects free-hit context. Keep innings/score/strike in the consuming app.","",...Object.entries(n.sports.cricket.playComponents).map(([r,o])=>`Play ${r}: ${mt(o)}`),...Object.entries(n.sports.cricket.playExamples).map(([r,o])=>`- Composed example \`${r}\`: ${o.name}`),"",...Object.entries(n.sports.cricket.actions).map(([r,o])=>`- \`${r}\`: ${o.summary}`),"",`Formats: ${mt(Object.keys(n.sports.cricket.formats))}. Casts: ${mt(Object.keys(n.sports.cricket.casts))}. Cameras: ${mt(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(([r,o])=>`\`${r}\`: ${o}`).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.`,"","Decision review cameras: front-foot, striker-crease, bowler-crease. cricketCameraFraming returns owned defaults; cricketCameraReview returns a physical event without seeking. Optional cricketDecisionOverlay marks the crease reference. pitch 0–89, distance 0.5–2000, fov 10–100 before zoom, and fixed-view target customize framing. Ball-follow yaw rotates its default offset relative to 75 degrees; pitch/distance apply too. Export all camera tracks, including far for distant framing. These APIs never alter motion or rulings.","","## Camera shots (`cameraTracks(shots, { stage })`)","",...Object.entries(n.cameraShots).map(([r,o])=>`- **${r}**: \`${o}\``),"","## Teaching (`@algorisys/tinyfly/teach`)","",...Object.entries(n.teach).map(([r,o])=>`- \`${r}\`: ${o}`),"","## Maths (`@algorisys/tinyfly/math`)","","A figure is JSON: a plane and items. Tracks on its target animate values by name and item props. One layout feeds a canvas (videos) and SVG (lesson embeds), so they match.","",...Object.entries(n.math.api).map(([r,o])=>`- \`${r}\`: ${o}`),"","Items (each has `id`, `kind`, and optional `color`, `draw`, `opacity`):","",...Object.entries(n.math.items).map(([r,o])=>`- \`${r}\` ${o}`),"","Props a timeline animates:","",...Object.entries(n.math.props).map(([r,o])=>`- \`${r}\`: ${o}`),"",`Expression functions: ${n.math.functions.map(r=>`\`${r}\``).join(", ")}; constants \`pi\`, \`e\`, \`tau\`.`,"",`TeX subset: ${n.math.tex}`,"","## Command line","",...Object.entries(n.cli).map(([r,o])=>`- \`${r}\`: ${o}`),""].join(`
|
|
66
|
-
`)}function FA(t,e,n,s={}){const i=s.color??"#555",r=s.size??60;for(const o of e){const a=(n-o.time)/o.length;if(a<=0||a>=1)continue;const l=re(`${o.kind}:${o.time}:${o.x}`);o.kind==="dust"?yy(t,{x:o.x,y:o.y},a,{size:r,color:i,seed:l}):o.kind==="exhaust"?WA(t,o,a,r,i,l):o.kind==="skid"?DA(t,o,a,n,i):o.kind==="honk"?BA(t,o,a,r,i):o.kind==="smoke"?LA(t,o,n,r,i):o.kind==="leaves"&&NA(t,o,a,r,s.leafColor??"#5cae5a",i,l)}}function LA(t,e,n,s,i,r){const o=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+o*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 NA(t,e,n,s,i,r,o){const a=e.direction??1,l=e.toY??e.y+s*3;t.save(),t.lineWidth=Math.max(1,s*.02),t.strokeStyle=r,t.fillStyle=i;for(let c=0;c<4;c++){const h=re(`${o}:${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,m=u*u*.4+u*.6,g=d+a*u*s*(.6+h)+Math.sin(u*9+h*6)*s*.18,p=Math.min(l-2,f+(l-f)*m);t.globalAlpha=n>.85?(1-n)/.15:1,t.save(),t.translate(g,p),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 WA(t,e,n,s,i,r){const o=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=(re(`${r}:${a}`)%100/100-.5)*s*.1,h=e.x+o*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 DA(t,e,n,s,i){const r=e.toX??e.x,o=Math.min(1,(s-e.time)/e.length*3),a=e.x+(r-e.x)*o;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 BA(t,e,n,s,i){const r=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 o=s*(.15+.5*(1-(1-n)**2));for(let a=-1;a<=1;a++){const l=a*Math.PI/7,c=e.x+r*Math.cos(l)*o,h=e.y+Math.sin(l)*o;t.beginPath(),t.arc(c,h,s*.12,r>0?-Math.PI/3:Math.PI*2/3,r>0?Math.PI/3:Math.PI*4/3),t.stroke()}t.restore()}function zA(t){const e=new Ht({id:`${t.propId}-ride`,tracks:t.propTracks.filter(h=>h.target===t.propId)}),n=t.every??33,s=[],i=[],r=[],o=[];let a=1;for(let h=t.start;;h=Math.min(t.end,h+n)){const u=da(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),r.push({time:h,value:Math.abs(f)}),o.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:r},{id:`${l}-facing`,target:l,property:"facing",keyframes:qA(o)}),c}function qA(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 jA(t,e,n){const s=o=>`${o.target}\0${o.property}`,i=new Map(e.map(o=>[s(o),o]));return[...t.map(o=>{const a=i.get(s(o));if(!a)return o;i.delete(s(o));const c=[...(o.keyframes??[]).filter(h=>h.time<n.from||h.time>n.to),...a.keyframes??[]].sort((h,u)=>h.time-u.time);return{...o,keyframes:c}}),...i.values()]}function KA(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,r=s.props,o=s.prop.wheelRadius,a=[],l=[],c=[];let h=r.wheelSpin??0,u;for(let f=t.start;;f=Math.min(t.end,f+n)){const m=da(t.leader,{state:e.getStateAtTime(f)},t.leaderId),g=m.anchor(t.hitch),p=m.values.turn,b=Bs(s.prop,{...r,turn:p},s.propScale).anchors[t.anchor];if(!b)throw new Error(`propTow: ${s.prop.kind} has no anchor "${t.anchor}"`);const v=g.x-b.point.x;if(u!==void 0&&o){const k=Math.sin(p*Math.PI/2);h+=(v-u)*(k||1)/s.propScale/o*(180/Math.PI)}if(u=v,a.push({time:f,value:v-i}),l.push({time:f,value:p}),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},...o?[{id:`${d}-wheelSpin`,target:d,property:"wheelSpin",keyframes:c}]:[]]}const $b=new WeakMap;function YA(t,e){const n=e?.some(Boolean)?e.map(d=>d?1:0).join(""):"";let s=$b.get(t);s||$b.set(t,s=new Map);const i=s.get(n);if(i)return i;const r=or(t),o={vertices:r.vertices,faces:r.faces.filter((d,f)=>!e?.[f])},a=o.vertices.flatMap(d=>[d[0],d[1],d[2]]),l=o.vertices.map(()=>[0,0,0]),c=[];o.faces.forEach(d=>{for(const g of d.corners)for(const p of[0,1,2])l[g][p]+=d.normal[p];const[f,...m]=d.corners;for(let g=0;g+1<m.length;g++){const[p,b,v]=[f,m[g],m[g+1]],[k,w,S]=[o.vertices[p],o.vertices[b],o.vertices[v]],x=[w[0]-k[0],w[1]-k[1],w[2]-k[2]],M=[S[0]-k[0],S[1]-k[1],S[2]-k[2]],E=[x[1]*M[2]-x[2]*M[1],x[2]*M[0]-x[0]*M[2],x[0]*M[1]-x[1]*M[0]],T=E[0]*d.normal[0]+E[1]*d.normal[1]+E[2]*d.normal[2];c.push(...T>=0?[p,b,v]:[p,v,b])}});const h=l.flatMap(d=>{const f=Math.hypot(...d)||1;return[d[0]/f,d[1]/f,d[2]/f]}),u=Ho({positions:a,normals:h,indices:c});return s.size>=16&&s.clear(),s.set(n,u),u}function XA(t,e,n={}){const s=t.ink??n.ink??"#26262b",i=(n.outline??2)*(t.outline??1),r=t.glow&&e.glow>0?GA(t.glow.color,e.glow):void 0;return{color:t.fill??s,creases:or(t.shape).creases!==!1,shading:n.shading??"toon",...i>0?{outline:{width:i,color:s}}:{},...r?{emissive:r}:{},...t.seeThrough?{opacity:.45*e.opacity}:e.opacity<1?{opacity:e.opacity}:{}}}function GA(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 UA=Ho(lp(1,.002,28));function VA(t,e,n){const s=t.rig,[i,r]=s.footprint??[s.length*.45,s.length],o=Math.max(0,Ot(s,e,"lift")),a=Math.max(0,Ot(s,e,"size"))/(1+o*.8);return{mesh:UA,world:Ft(n,al([0,.004,0],[0,0,0,1],[i*.55*a||1e-4,1,r*.55*a||1e-4])),material:{color:"#000000",shading:"unlit",opacity:.16*a}}}const JA=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),ZA=1,QA={kind:"prop",validate(t){const e=t,n=typeof e.prop=="string"&&e.prop in js?[]:[dt("prop preset",e.prop,Object.keys(js))];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(r=>r===s?e[i]:0).join(", ")}]`);return n},prepare(t){const e=t;return l0(e.prop,e.options)},resolve({object:t,prepared:e,values:n,world:s,camera:i,lights:r=[],fog:o,toScreen:a}){const l=t,c=e,h={...l.values};for(const[M,E]of n)typeof E=="number"&&!JA.has(M)&&(h[M]=E);h.turn=0,h.tilt=0;const u=Ft(i.view,s),d={toView:M=>ae(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=d1(c.rig,h),E=M.map(({part:P,local:I})=>({part:P.id,mesh:or(P.shape),...Vh(or(P.shape),I)})),T=o1(E),A=M.map((P,I)=>({...P,hidden:l1(P.part.id,E[I].mesh,P.local,E[I].key,T)})).filter(({opacity:P})=>P>.01).map(({part:P,matrix:I,glow:O,opacity:_,hidden:L})=>({mesh:YA(P.shape,L),world:Ft(s,I),material:XA(P,{glow:O,opacity:_},{shading:l.shading,ink:l.ink,outline:l.outline})}));return{meshes:l.shadow===!1?A:[VA(c,h,s),...A]}}const m=a(f),g=a(d.toView([0,c.rig.height/2+1,0])),p=Math.hypot(g.x-m.x,g.y-m.y),b=r.length===0?void 0:(M,E)=>{const T=ae(s,M),A=[s[0]*E[0]+s[4]*E[1]+s[8]*E[2],s[1]*E[0]+s[5]*E[1]+s[9]*E[2],s[2]*E[0]+s[6]*E[1]+s[10]*E[2]],P=Math.hypot(...A)||1;return{light:rf(T,[A[0]/P,A[1]/P,A[2]/P],r),fog:of(o,Math.hypot(T[0]-i.position[0],T[1]-i.position[1],T[2]-i.position[2]))}},v=e0(c.rig,h,d,p,{perspective:!0,near:i.near,slice:ZA,light:b}),k={look:l.look,style:l.style,ink:l.ink,paper:l.paper,fog:o?.color},w=Qc(v),S=v.cells??[],x=Math.max(...S.map(M=>-M.depth),-f[2]);return{drawables:[...l.shadow===!1?[]:[{depth:x+c.rig.length,draw:M=>th(M,v,k)}],...S.map(M=>({depth:-M.depth,draw(E,T){E.lineCap="round",E.lineJoin="round",hp(E,M.parts,w,{...k,time:T.time})}}))]}}},E0=["do","at","for","to","through","toward","speed","height","open","on","wind"],tx=.25,ex=800/180,nx=220,sx=300,ix=["turn"];function rx(t){const e=ya(t),n=Object.keys(t.moves??{});return Object.keys(e).filter(s=>!n.includes(s)&&!ix.includes(s)&&!(e[s].needs??[]).includes("to"))}function Ib(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=rx(e),i=[...n,"face","hold",...s.filter(o=>o!=="hold")],r=[];return t.forEach((o,a)=>{const l=u=>r.push({beat:a,message:u});if(!o||typeof o!="object"||Array.isArray(o))return l(`Each beat must be an object like { do: '${i[0]??"hold"}' }.`);const c=o,h={duration:"for",path:"through",points:"through",position:"to",heading:"toward",direction:"toward"};for(const u of Object.keys(c))E0.includes(u)||l(dt("beat field",u,E0,h[u]));if(typeof c.do!="string"||!i.includes(c.do)){const u=c.do==="turn"?"face":void 0;return l(dt(`${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&&!qn(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(qn))&&l("`through` is a list of points on the ground, each [x, z] metres.")),c.do==="face"&&!(qn(c.toward)||typeof c.toward=="number")&&l("`face` needs `toward`: a point [x, z] or a heading in degrees.")}),r}function ox(t,e,n,s){const i=Ib(n,e);if(i.length>0)throw new Error(`propScript3D (${e.kind}): ${i.length} problem(s) in the beats:
|
|
67
|
-
${i.map(
|
|
68
|
-
`)}`);const r={};for(const k of[...Object.keys(Ds),...Object.keys(e.rig.controls)])r[k]=s.values?.[k]??Ot(e.rig,{},k);let[o,a]=s.position??[0,0],l=s.heading??0;const c=new Map,h=(k,w,S,x="linear")=>{const M=c.get(k)??[];M.push({time:w,value:S,easing:x}),c.set(k,M)},u=(k,w,S)=>h(k,w,S);h("x",0,o),h("z",0,a),h("rotateY",0,l);const d=(k,w)=>{const S=Do(l,w);if(Math.abs(S)<1)return k;const x=Math.max(nx,Math.abs(S)*ex);return u("rotateY",k,l),l+=S,h("rotateY",k+x,l,"ease-in-out"),k+x},f=(k,w,S)=>{const x=Cp([[o,a],...w.through??[w.to]]);if(x.length<2)return S;const M=d(S,Cs(x[0].point,x[1].point)),E=x[x.length-1].at,T=w.for??E/(w.speed??k.speed)*1e3,A=Dt("ease-in-out"),P=Math.min(sx,T/4);for(const[V,tt]of Object.entries(k.set??{}))u(V,M,r[V]),h(V,M+1,tt),r[V]=tt;const I=k.flies?w.height??(r.lift>.05?r.lift:2):void 0,O=I!==void 0&&I>.05;for(const[V,tt]of Object.entries(k.hold??{}))u(V,M,r[V]),h(V,M+P,tt,"ease-out"),O||(h(V,M+T-P,tt),h(V,M+T,0,"ease-in")),r[V]=O?tt:0;I!==void 0&&(u("lift",M,r.lift),h("lift",M+Math.min(T*.35,1400),I,"ease-out"),h("lift",M+T,I),r.lift=I);const _={...r};let L=l;for(let V=0;;V=Math.min(E,V+tx)){const tt=M+Rp(A,V/E)*T,{point:J,direction:F}=_p(x,V);L+=Do(L,Cs([0,0],F)),h("x",tt,J[0]),h("z",tt,J[1]),h("rotateY",tt,L);for(const[B,Y]of Object.entries(k.perMetre??{}))h(B,tt,_[B]+V*Y);for(const[B,Y]of Object.entries(k.perSecond??{}))h(B,tt,_[B]+(tt-M)/1e3*Y);if(V>=E)break}for(const[V,tt]of Object.entries(k.perMetre??{}))r[V]=_[V]+E*tt;for(const[V,tt]of Object.entries(k.perSecond??{}))r[V]=_[V]+T/1e3*tt;return[o,a]=x[x.length-1].point,l=L,M+T},m=(k,w)=>{const S=Object.fromEntries(Object.entries(k).filter(([M])=>!["at","to","through","toward"].includes(M))),x=hb(t,e,[S],{start:{...r,turn:1},scale:100,style:s.style,exaggeration:s.exaggeration});for(const M of x.tracks){if(ax.includes(M.property))continue;const E=M.keyframes??[],T=r[M.property];if(!E.every(A=>A.value===T)){u(M.property,w,T);for(const A of E)A.time>0&&c.get(M.property).push({...A,time:w+A.time});r[M.property]=E[E.length-1].value}}return w+x.duration},g=[];let p=0;for(const k of n){const w=k.at??p;let S=w;const x=e.moves?.[k.do];x?S=f(x,k,w):k.do==="face"?S=d(w,typeof k.toward=="number"?k.toward:Cs([o,a],k.toward)):k.do==="hold"?S=w+(k.for??1e3):S=m(k,w),g.push({do:k.do,start:w,end:S}),p=S}const b=`${s.scene}/${t}`;return{tracks:[...c].map(([k,w])=>({id:`${t}-${k}`,target:b,property:k,keyframes:Op(w)})),duration:p,beats:g,end:{position:[o,a],heading:l,values:{...r}}}}const ax=["x","y","turn","facing","tilt"],lx=.35,A0={seated:Ae.sit,astride:{...Ae.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:{...Ae.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:{...Ae.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:{...Ae.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}},cx=22,Ob=38;function x0(t,e=A0.cycling){const n=t*Math.PI*2,s=o=>({swing:(e["leg.left.swing"]??40)+cx*Math.cos(n+o),knee:(e["leg.left.knee"]??70)+Ob*(.5+.5*Math.cos(n+o))-Ob*.5,ankle:12*Math.sin(n+o)}),i=s(0),r=s(Math.PI);return{...e,"leg.left.swing":i.swing,"leg.left.knee":i.knee,"leg.left.ankle":i.ankle,"leg.right.swing":r.swing,"leg.right.knee":r.knee,"leg.right.ankle":r.ankle}}function hx(t){const e=t.cadence??1.2,n=Math.max(2,t.samplesPerTurn??8),s=1e3/e/n,i=[];for(let r=t.start,o=0;r<t.end;r+=s,o++)i.push({time:Math.round(r),pose:x0((r-t.start)/1e3*e,t.base),...o>0?{act:!1}:{}});return i.push({time:t.end,pose:x0((t.end-t.start)/1e3*e,t.base),act:!1}),i}const Cb=(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 ux(t){const e=`${t.scene}/${t.propId}`,n=new Ht({id:`${t.propId}-ride-3d`,tracks:t.propTracks.filter(p=>p.target===e)}),s=t.placement??{},[i,r,o]=s.position??[0,0,0],a=t.prop.rig,l=Ps({...t.character,height:1}),c={...lt,...t.pose??A0.seated},h=cn(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 p=t.start;;p=Math.min(t.end,p+d)){const b=n.getStateAtTime(p).values.get(e)??new Map,v=(_,L)=>{const j=b.get(_);return typeof j=="number"?j:L},k={...s.values};for(const _ of Object.keys(a.controls))k[_]=v(_,s.values?.[_]??Ot(a,{},_));for(const _ of["pitch","roll","squash","lift","lean","size"])k[_]=v(_,s.values?.[_]??Ot(a,{},_));const w=f1(a,k)[t.anchor];if(!w)throw new Error(`propRide3D: ${t.prop.kind} has no anchor "${t.anchor}" (it has ${Object.keys(a.anchors??{}).join(", ")||"none"})`);const S=v("rotateY",s.heading??0),x=Cb(w,S),M=[v("x",i)+x[0],v("y",r)+x[1],v("z",o)+x[2]],E=S+u,T=Cb(h,E);let A=[M[0]-T[0],M[1]-T[1],M[2]-T[2]];const P=(_,L)=>{const j=L*L*(3-2*L);return[_[0]+(A[0]-_[0])*j,A[1]*j+lx*Math.sin(Math.PI*L),_[1]+(A[2]-_[1])*j]},I=t.mount?Math.max(1,t.mount.for??450):0,O=t.dismount?Math.max(1,t.dismount.for??450):0;if(t.mount&&p<t.start+I?A=P(t.mount.from,(p-t.start)/I):t.dismount&&p>t.end-O&&(A=P(t.dismount.to,(t.end-p)/O)),f.x.push({time:p,value:A[0]}),f.y.push({time:p,value:A[1]}),f.z.push({time:p,value:A[2]}),f.rotateY.push({time:p,value:E}),p>=t.end)break}const m=t.riderId,g=`${t.scene}/${m}`;return Object.keys(f).map(p=>({id:`${m}-${p}`,target:g,property:p,keyframes:f[p]}))}const _b={ground:"#7fb56a",hills:"#5f9a58",city:"#4b5468",cloud:"#ffffff",sun:"#ffd45c",moon:"#f3f0e0",rain:"#9fc4e8",snow:"#ffffff",wall:"#e9e1cf",floor:"#b08a5e",skirting:"#8a6a44",frame:"#f7f3ea"},dr=[[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"]],fr=(t,e,n)=>{const s=o=>[1,3,5].map(a=>parseInt(o.slice(a,a+2),16)),[i,r]=[s(t),s(e)];return`#${i.map((o,a)=>Math.round(o+(r[a]-o)*n).toString(16).padStart(2,"0")).join("")}`},dx=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 Rb(t){const e=(t%24+24)%24;for(let n=1;n<dr.length;n++){const[s,i,r]=dr[n-1],[o,a,l]=dr[n];if(e<=o){const c=(e-s)/(o-s);return{top:fr(i,a,c),bottom:fr(r,l,c)}}}return{top:dr[0][1],bottom:dr[0][2]}}const fx=(t,e)=>{const n=((t-e)%24+24)%24;return n<=12?n/12:-1},gx=9,mx=55,px=28;function Hb(t){const{x:e,y:n,width:s,height:i}=t,r=t.kind??"sky",o=t.ground??n+i*.85,a={..._b,...t.colors},l=t.horizon??"hills",c=t.window!==!1,h=Se(t.seed??1),u=s*i/1e5,d=Array.from({length:Math.ceil(gx*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(mx*u)+4},()=>({u:h.next(),v:h.next(),speed:.8+h.next()*.5})),m=Array.from({length:Math.ceil(px*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})),p=Array.from({length:6},()=>({phase:h.next()*Math.PI*2,amp:.5+h.next()})),b=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=_s(),w=(A,P)=>k.keys(A)?.length?k.valueAt(A,P):v[A],S=(A,P)=>{const I=fx(A,P),O=I<0?.5:I,_=o-n;return{x:.1*s+.8*s*O,y:I<0?_+i*.2:_-Math.sin(O*Math.PI)*_*.8,up:I>=0}},x=(A,P,I,O,_)=>{const L=P("hour"),{top:j,bottom:V}=Rb(L),tt=A.createLinearGradient(0,O.y,0,O.ground);tt.addColorStop(0,j),tt.addColorStop(1,V),A.fillStyle=tt,A.fillRect(O.x,O.y,O.w,O.ground-O.y);const J=dx(L);if(J<.6){A.fillStyle="#ffffff",A.globalAlpha=(.6-J)/.6*.9;for(const C of g)A.beginPath(),A.arc(O.x+C.u*O.w,O.y+C.v*(O.ground-O.y),C.size,0,Math.PI*2),A.fill();A.globalAlpha=1}const F=S(L,6),B=S(L,18),Y=Math.min(O.w,O.h)*.06;if(F.up&&(A.fillStyle=a.sun,A.beginPath(),A.arc(O.x+F.x/s*O.w,O.y+F.y/i*O.h,Y,0,Math.PI*2),A.fill()),B.up){const C=O.x+B.x/s*O.w,z=O.y+B.y/i*O.h;A.fillStyle=a.moon,A.beginPath(),A.arc(C,z,Y*.8,0,Math.PI*2),A.fill(),A.fillStyle=j,A.beginPath(),A.arc(C-Y*.35,z-Y*.15,Y*.7,0,Math.PI*2),A.fill()}const R=Math.max(0,Math.min(1,P("clouds"))),K=Math.max(-1,Math.min(1,P("wind"))),st=Math.round(R*d.length);A.fillStyle=fr("#ffffff",a.cloud==="#ffffff"?"#ffffff":a.cloud,1),A.globalAlpha=.55+.4*J;for(let C=0;C<st;C++){const z=d[C],X=((z.u*O.w+K*I*.012*(.6+z.size*.5))%(O.w*1.4)+O.w*1.4)%(O.w*1.4)-O.w*.2,W=O.x+X,N=O.y+(.08+z.v*.42)*(O.ground-O.y),D=Math.min(O.w,O.h)*.07*z.size;for(let G=0;G<z.puffs;G++)A.beginPath(),A.ellipse(W+(G-(z.puffs-1)/2)*D*.9,N+G%2*D*.25,D*(G%2?.8:1),D*.62,0,0,Math.PI*2),A.fill()}A.globalAlpha=1;const $=C=>fr(fr(C,"#0b1530",.65),C,J);if(l==="hills"){A.fillStyle=$(a.hills),A.beginPath(),A.moveTo(O.x,O.ground);const C=40;for(let z=0;z<=C;z++){const X=z/C;let W=0;p.forEach((N,D)=>W+=Math.sin(X*Math.PI*(1.5+D*.7)+N.phase)*N.amp),A.lineTo(O.x+X*O.w,O.ground-Math.max(0,W)*O.h*.045-O.h*.03)}A.lineTo(O.x+O.w,O.ground),A.closePath(),A.fill()}else if(l==="city"){A.fillStyle=$(a.city);let C=O.x;const z=O.w/18;for(const X of b){if(C>O.x+O.w)break;const W=z*X.w,N=O.h*.22*X.h;if(A.fillRect(C,O.ground-N,W,N),X.windows&&J<.5){A.fillStyle="#ffd66b",A.globalAlpha=.5-J;for(let D=O.ground-N+6;D<O.ground-8;D+=9)for(let G=C+4;G<C+W-4;G+=8)A.fillRect(G,D,3,4);A.globalAlpha=1,A.fillStyle=$(a.city)}C+=W+z*.15}}A.fillStyle=$(a.ground),A.fillRect(O.x,O.ground,O.w,O.y+O.h-O.ground)},M=(A,P,I,O)=>{const _=Math.max(-1,Math.min(1,P("wind"))),L=Math.max(0,Math.min(1,P("rain"))),j=Math.max(0,Math.min(1,P("snow")));if(L>0){A.strokeStyle=a.rain,A.globalAlpha=.35+.45*L,A.lineWidth=1.2,A.lineCap="round";const V=O.h*.05,tt=_*.45,J=Math.round(L*f.length);A.beginPath();for(let F=0;F<J;F++){const B=f[F],Y=((B.v*O.h+I*B.speed*.9)%O.h+O.h)%O.h,R=((B.u*O.w+Y*tt)%O.w+O.w)%O.w;A.moveTo(O.x+R,O.y+Y),A.lineTo(O.x+R+tt*V,O.y+Y+V)}A.stroke(),A.globalAlpha=1}if(j>0){A.fillStyle=a.snow,A.globalAlpha=.85;const V=Math.round(j*m.length);for(let tt=0;tt<V;tt++){const J=m[tt],F=((J.v*O.h+I*J.speed*.08)%O.h+O.h)%O.h,B=Math.sin(I*.002+J.sway)*O.w*.02,Y=((J.u*O.w+B+_*F*.3)%O.w+O.w)%O.w;A.beginPath(),A.arc(O.x+Y,O.y+F,J.size,0,Math.PI*2),A.fill()}A.globalAlpha=1}},T={kind:"scenery",target:{type:"custom",x:e,y:n,width:s,height:i,props:v,about:{kind:r==="room"?"room":"sky",summary:r==="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(A=>[A,yx(A)]))},draw(A,P,I){const O=P.props??{},_=j=>Number(O[j]??v[j]??0);A.save();const L={x:0,y:0,w:s,h:i,ground:o-n};if(r==="sky")x(A,_,I,L),M(A,_,I,L);else if(A.fillStyle=a.wall,A.fillRect(0,0,s,L.ground),A.fillStyle=a.floor,A.fillRect(0,L.ground,s,i-L.ground),A.fillStyle=a.skirting,A.fillRect(0,L.ground-i*.012,s,i*.012),c){const j=s*.26,V=L.ground*.5,tt=s*.62,J=L.ground*.14;A.fillStyle=a.frame,A.fillRect(tt-6,J-6,j+12,V+12),A.save(),A.beginPath(),A.rect(tt,J,j,V),A.clip(),x(A,_,I,{x:tt,y:J,w:j,h:V,ground:J+V*.8}),M(A,_,I,{x:tt,y:J,w:j,h:V}),A.restore(),A.strokeStyle=a.frame,A.lineWidth=4,A.beginPath(),A.moveTo(tt+j/2,J),A.lineTo(tt+j/2,J+V),A.moveTo(tt,J+V/2),A.lineTo(tt+j,J+V/2),A.stroke()}A.restore()}},ground:o,anchor(A,P=1/0){const I=w("hour",P);if(A==="sun"||A==="moon"){const O=S(I,A==="sun"?6:18);return{x:e+O.x,y:n+O.y}}if(A==="horizon")return{x:e+s/2,y:o-i*.03};if(A==="ground")return{x:e+s/2,y:o};throw new Error(`scenery: ${dt("place",A,["sun","moon","horizon","ground"])}`)},set(A,P){if(!(A in v))throw new Error(`scenery: ${dt("value",A,Object.keys(v))}`);if(typeof P.value!="number"||!Number.isFinite(P.value))throw new Error("scenery.set needs `value`, a number");return k.tween(A,w(A,P.at),P.value,P,1e3),T},tracks:k.tracks};return T}function yx(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 Fb(t,e){const{width:n,height:s}=e,i=e.ground??s*.85,r=e.scale??s/4.5,o={x:0,y:0,width:n,height:s,ground:i},a=(l,c,h={})=>({preset:l,x:n*c,scale:r,...h});switch(t){case"park":return{scenery:{...o,hour:10.5,clouds:.35,horizon:"hills",...e.scenery},props:[a("tree",.14,{scale:r*1.1}),a("chair",.5,{turn:0}),a("tree",.86,{scale:r*.9})]};case"street":return{scenery:{...o,hour:16,clouds:.25,horizon:"city",colors:{ground:"#8a8f99"},...e.scenery},props:[a("house",.2,{scale:r*.75,turn:.1}),a("car",.5,{turn:1,scale:r*.9}),a("house",.78,{scale:r*.7,turn:.1}),a("tree",.95,{scale:r*.8})]};case"office":return{scenery:{...o,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:{...o,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(dt("scene preset",t,["park","street","office","home"]))}}function bx(t,e){const n=Fb(t,e),s=Hb(n.scenery),i=n.props.map(r=>m1({x:r.x,y:s.ground,prop:l0(r.preset),scale:r.scale,values:{turn:r.turn??0,...r.values}}));return{scenery:s,props:i,ground:s.ground}}function wx(t){const{timeline:e}=t,n=new _n;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,r=!1;const o=c=>{if(r)return;const h=i===null?0:c-i;i=c,h>0&&e.tick(h),s=requestAnimationFrame(o)},a=()=>{s!==null||r||(i=null,s=requestAnimationFrame(o))},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(){r=!0,l(),e.stop(),n.clearTargets()}}}const kx={timeline:hk,to(t,e,n){const s=new Cn(n);return s.to(t,e),s},from(t,e,n){const s=new Cn(n);return s.from(t,e),s},fromTo(t,e,n,s){const i=new Cn(s);return i.fromTo(t,e,n),i},set(t,e,n){const s=new Cn(n);return s.set(t,e),s}};function Lb(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 vx(t,e){const n=t.length/4,s=new Float32Array(n*3),i=Math.min(.999,Math.max(0,e));for(let r=0;r<n;r++){const o=t[r*4]/255,a=t[r*4+1]/255,l=t[r*4+2]/255,c=t[r*4+3]/255,h=Math.max(o,a,l);if(h<=i)continue;const u=(h-i)/(1-i)*c/h;s[r*3]=o*u,s[r*3+1]=a*u,s[r*3+2]=l*u}return s}function Nb(t,e,n,s,i){const r=new Float32Array(t.length),o=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<o;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++){r[l(h,f)+u]=d/c;const m=t[l(h,Math.max(0,f-s))+u],g=t[l(h,Math.min(a-1,f+s+1))+u];d+=g-m}}return r}function Wb(t,e,n,s){const i=Math.max(1,Math.round(s/Math.sqrt(3)));let r=t;for(let o=0;o<3;o++)r=Nb(r,e,n,i,!0),r=Nb(r,e,n,i,!1);return r}function Mx(t,e={}){const n=t.canvas,s=n.width,i=n.height;if(!(s>0&&i>0))return;const r=Math.max(1,Math.round(e.downsample??4)),o=Math.max(1,Math.ceil(s/r)),a=Math.max(1,Math.ceil(i/r)),l=Lb(t,o,a),c=l?.getContext("2d");if(!l||!c)return;c.imageSmoothingEnabled=!0,c.drawImage(t.canvas,0,0,o,a);const h=vx(c.getImageData(0,0,o,a).data,e.threshold??.55),u=(e.radius??Math.max(s,i)*.02)/r,d=Wb(h,o,a,u),f=Wb(h,o,a,u*3),m=e.halo??.6,g=c.createImageData(o,a);for(let p=0;p<o*a;p++){for(let b=0;b<3;b++)g.data[p*4+b]=Math.round(Math.min(1,d[p*3+b]+f[p*3+b]*m)*255);g.data[p*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 Sx(t,e,n){const s=n.width??6,i=n.taper??1,r=n.fade??1,o=n.opacity??1,a=n.blend==="add";if(t.save(),e.length>=2){const c=Ex(e,s,i,r,o);a?(t.globalCompositeOperation="lighter",P0(t,c,n.color)):Ax(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,Tx(t,c)),t.globalAlpha=o,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 Tx(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 Ex(t,e,n,s,i){const r=t.map(c=>({x:c.at.x,y:c.at.y,width:e*(1-n*c.age)})),o=Bu(r),a=zu(r)??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:[o.left[c],o.left[c+1],o.right[c+1],o.right[c]],alpha:u,...d&&a&&{cap:a}})}return l}function P0(t,e,n){t.fillStyle=n;for(const s of e){const[i,r,o,a]=s.corners;t.globalAlpha=Math.min(1,s.alpha),t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(r.x,r.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(o.x,o.y),t.lineTo(a.x,a.y),t.closePath(),t.fill()}}function Ax(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,r=s?Math.sqrt(Math.abs(s.a*s.d-s.b*s.c)):1,o=e.map(g=>({...g,corners:g.corners.map(i),...g.cap&&{cap:{...g.cap,...i(g.cap),radius:g.cap.radius*r,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 o){const p=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 b of[...g.corners,...p])a=Math.min(a,b.x),l=Math.min(l,b.y),c=Math.max(c,b.x),h=Math.max(h,b.y)}if(!(c>a&&h>l))return;const u=Math.floor(a)-1,d=Math.floor(l)-1,f=s?Lb(t,Math.ceil(c)+1-u,Math.ceil(h)+1-d):null,m=f?.getContext("2d");if(!f||!m){P0(t,e,n);return}m.translate(-u,-d),m.globalCompositeOperation="lighter",P0(m,o,n),t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=1,t.drawImage(f,u,d),t.restore()}const xx=le.to,Px=le.from,$x=le.fromTo,Ix=le.set,Ox=le.timeline,Cx=le.ticker,_x=le.splitText,Rx=le.context,Hx=le.matchMedia,Fx=le.quickTo,Lx=le.imageSequence,Nx=le.pageTransition;L5(),y.ACTING_STYLES=Xn,y.AIRCRAFT_ACTING=i0,y.ANIMAL_GAITS=qs,y.ANIME_CAST=sy,y.BEAN_ARM_REACH=Rm,y.BEAN_BANGLE_STOPS=qm,y.BEAN_CAST=ry,y.BEAN_DARK_SOLE=Wm,y.BEAN_LEG_REACH=Hm,y.BEAN_SOLE=Nm,y.BEAT_FIELDS=Vo,y.BEAT_MOMENTS=Ns,y.BED_ACTING=F1,y.BIRD_ACTING=eb,y.BOARD_MARKS=kh,y.BOARD_THEMES=Zi,y.BODY_SHAPES=ho,y.CANVAS_PROPERTIES=ca,y.CASE_CARD_KINDS=ra,y.CASE_MARK_KINDS=oa,y.CHAIR_ACTING=C1,y.CHARACTER_BEAT_3D_FIELDS=ch,y.CHARACTER_CAST=Th,y.CHARACTER_GAIT_SPEEDS=Np,y.CHART_KINDS=Mh,y.CHART_SURFACE=Kn,y.CHART_THEMES=Qi,y.CODE_LANGUAGES=Yo,y.CODE_PANEL_EDITS=bh,y.CODE_SURFACE=Ji,y.CODE_THEME=Kp,y.CRICKET_ACTIONS=Zn,y.CRICKET_CAMERA_ANGLES=Ma,y.CRICKET_CASTS=d0,y.CRICKET_DECISION_VIEWS=cr,y.CRICKET_FIELDING_POSITIONS=Ks,y.CRICKET_FORMATS=Ge,y.CRICKET_MARKING_PROFILES=Sa,y.CRICKET_PITCH=Yt,y.CRICKET_PLAY_COMPONENTS=En,y.CRICKET_PLAY_EXAMPLES=Ab,y.CRICKET_VIEWS=va,y.Clock=zb,y.CompatTimeline=Cn,y.CustomBounce=_d,y.CustomEase=Cd,y.CustomWiggle=Rd,y.DANCE_STYLES=ln,y.DEFAULT_BAKE_INTERVAL_MS=Ka,y.DEFAULT_INERTIA_FRICTION=_a,y.DEFAULT_LABELS=qd,y.DEFAULT_SPRING=ge,y.DEFAULT_TRANSITION=W5,y.DESK_ACTING=R1,y.DOOR_ACTING=N1,y.Draggable=pl,y.EMBRACE=Xo,y.EXPRESSIONS=Mt,y.FACIAL_HAIR_STYLES=Oc,y.FINGERS=df,y.FLIPS=Ki,y.FOOT_SHAPES=ng,y.FORMAT_VERSION=xa,y.FRAME_ASPECTS=Wu,y.GAGS=mn,y.GAITS=Gt,y.GAIT_CYCLE_MS=Fh,y.GLASSES_STYLES=_c,y.HAIR_COLORS=Fe,y.HAIR_STILL=vs,y.HAIR_STYLES=Ac,y.HAND_MEETINGS=er,y.HAND_REST=Ct,y.HAND_SHAPES=Tt,y.HAT_STYLES=ko,y.HELD_ITEMS=Lc,y.HELP_UP=Yn,y.HORSE_ACTING=sA,y.HORSE_GAITS=QE,y.HOUSE_ACTING=I1,y.HUMAN_ACTING_RIG=uy,y.HUMAN_BUILDS=so,y.HUMAN_CYCLES=Rc,y.HUMAN_DANCES=Nn,y.HUMAN_EXPRESSIONS=oc,y.HUMAN_GAGS=So,y.HUMAN_POSES=Ae,y.HUMAN_REST=lt,y.IDENTITY_CAMERA=Dp,y.IDENTITY_SIMILARITY=v2,y.INERTIA_MAX_DURATION_MS=R0,y.InertiaTrackPlayer=ku,y.LiveTimeline=_e,y.MANGA_CAST=iy,y.MORPH_SAMPLES=hw,y.MUDRAS=Jr,y.ManualClock=Bb,y.MediaSync=Il,y.NOIR_AMBER=Kh,y.NOIR_CREAM=ia,y.NOIR_INK=yn,y.NOIR_KIT=Vy,y.NOIR_RED=Jn,y.OUTFIT_PRESETS=Eh,y.Observer=cd,y.POSES=he,y.PROP_BEAT_3D_FIELDS=E0,y.PROP_BEAT_FIELDS=pa,y.PROP_COMMON_ACTIONS=h0,y.PROP_COMMON_CONTROLS=Ds,y.PROP_PRESETS=js,y.PROP_SURFACE=zs,y.QUADRUPED_ACTING=o0,y.REMOVE_STYLES=jo,y.REST_POSE=ut,y.RIDING_POSES=A0,y.SAMPLE_STEP=fn,y.SCENERY_COLORS=_b,y.SCRIPT_ACTIONS=sr,y.SOFT_CARTOON_CAST=tr,y.SPRING_MAX_DURATION_MS=Ca,y.SPRING_PRESETS=wr,y.SPRING_STEP_MS=ts,y.STICK_ACTING_RIG=hy,y.ScrollAnimator=Ed,y.ScrollDriver=mi,y.ScrollMarkers=Ad,y.ScrollPin=vd,y.SmoothScroll=xl,y.SpringSampler=Zs,y.SpringTrackPlayer=wu,y.Stage=sd,y.TREE_ACTING=P1,y.Timeline=Ht,y.TinyflyPlayer=Lr,y.TinyflySequencer=Jd,y.TrackPlayer=nn,y.VEHICLE_ACTING=y1,y.VISEMES=dn,y.ValueResolver=Dw,y.VisibilityDriver=kd,y.WHEELCHAIR_ACTING=B1,y.WHITEBOARD_SURFACE=je,y.actCharacterTracks=gy,y.actKeyframes=Uo,y.actTracks=fy,y.actionNames=Ch,y.airplane=j1,y.anchorError=gn,y.animalStrideLength=ma,y.animatableProperties=Zy,y.applyBloom=Mx,y.applyCamera=J3,y.applyGroove=Gf,y.applySimilarity=sl,y.aspectOf=nl,y.assertBeats=Hh,y.audioEnvelope=f2,y.backOut=j0,y.bakeDanceTracks=oM,y.bakeEasing=Ga,y.bakeInertiaTrack=Xa,y.bakeSpringTrack=Ya,y.ballFlightPoint=y0,y.ballFlightTracks=yA,y.basicOutfit=Am,y.beanAlongLeg=zc,y.beanLimbLine=qi,y.beanOrder=_m,y.beanOverBody=zi,y.beanShoeAt=Lm,y.beanStanding=zm,y.beanTorso=Om,y.beanTorsoOutline=YS,y.beatAt=sM,y.beatAtTime=oi,y.beatLength=ri,y.beatPeriod=h2,y.beatPulse=d2,y.beatTime=Ar,y.beatsBetween=Zw,y.bed=H1,y.bike=E1,y.bindChoiceHotspots=Xd,y.bird=Mn,y.blendPose=gs,y.bodyProfileWidth=Ri,y.bodyShapeProfiles=yg,y.boilFrame=_l,y.bounceOut=q0,y.boxMesh=Sp,y.brushingPose=ym,y.bubblePath=C2,y.bubblePop=_2,y.buildScene=bx,y.bus=v1,y.cameraFromValues=V3,y.cameraPoint=Z3,y.cameraTracks=n2,y.capabilities=xb,y.capabilitiesMarkdown=HA,y.car=w1,y.cart=S1,y.caseBoard=kE,y.caseBoardMarkerTip=Xy,y.caseCardBox=la,y.caseMarkPath=Xh,y.castMember=HT,y.cat=U1,y.chair=O1,y.changingWindows=Rs,y.character=Ps,y.characterAt=l3,y.characterHandPose=Ym,y.characterJoints=ke,y.characterJointsInView=i3,y.characterLookAtTracks=G3,y.characterObjects=F3,y.characterPartsInView=Um,y.characterPoseOf=$o,y.characterPoseTracks=c3,y.characterScript=U4,y.characterScript3D=X3,y.characterStrideLength=Ny,y.characterTarget=a3,y.charactersFor=vu,y.chart=IT,y.checkBeats=ir,y.checkCast=_h,y.checkCharacterBeats3D=Wp,y.checkPropBeats=cb,y.checkPropBeats3D=Ib,y.checkSurfaceBeats=Hy,y.checkTracks=SE,y.chicken=ib,y.circlePath=nT,y.clamp01=Sl,y.clearMorphCache=ww,y.clearPathCache=rw,y.clipErased=yh,y.clockHandAngles=jy,y.closestName=ai,y.clueMarkerAt=qy,y.codePanel=fT,y.codeTokens=Xp,y.composeSimilarity=S2,y.coneCorners=zy,y.containerProgressAt=Tl,y.context=Rx,y.controlValue=Ot,y.cow=V1,y.create=M5,y.createControls=Kd,y.createCubicBezier=B0,y.createLive=Ld,y.createPen=ki,y.createRandom=Se,y.createTrack=Er,y.cricketAction=Sb,y.cricketCameraFraming=bb,y.cricketCameraReview=wa,y.cricketCameraTracks=MA,y.cricketClip=PA,y.cricketDecisionOverlay=bA,y.cricketEventAt=$A,y.cricketField=M0,y.cricketFieldingAreaContains=wb,y.cricketFieldingOverlay=TA,y.cricketFieldingPositions=kb,y.cricketPlay=Eb,y.cricketPlayClip=_A,y.cricketPlayer=vb,y.criticalDamping=Kb,y.crow=sb,y.curve=c2,y.customBounce=Cu,y.customEase=Ou,y.customWiggle=_u,y.cylinderMesh=Tp,y.danceCircleAt=np,y.danceCircleTracks=u3,y.danceFrame=to,y.danceJoint=zn,y.dancePose=Zv,y.danceStance=Qr,y.danceTaps=tM,y.danceTracks=rM,y.danceTravel=no,y.danceTravelTrack=Qf,y.dancer=iM,y.defineAction=g4,y.defineGait=m4,y.describeTarget=Jy,y.deserializeTimeline=as,y.deserializeTrack=Eu,y.desk=_1,y.detectTempo=Qw,y.dog=G1,y.door=L1,y.draggable=Hk,y.drawBeanFedora=Bm,y.drawBlinds=oE,y.drawCartoonHand=Yr,y.drawCaseBoard=vE,y.drawCharacter=Gm,y.drawCharacterHead=o3,y.drawCharacterInView=r3,y.drawClockFace=gE,y.drawClueMarker=dE,y.drawDarkness=aE,y.drawDustPuff=yy,y.drawEraser=mh,y.drawEvidenceFolder=fE,y.drawGlow=lE,y.drawHand=ph,y.drawHeldItem=Nc,y.drawImpactStars=u4,y.drawMarkerStroke=Uy,y.drawNameCard=pE,y.drawNarrationBox=bE,y.drawPencil=Bp,y.drawProp=WE,y.drawPropEffects=FA,y.drawPropShadow=th,y.drawPushPin=Gy,y.drawRain=rE,y.drawSolvedFaces=hp,y.drawSolvedPart=A3,y.drawSolvedProp=Zc,y.drawSpeechBubble=wE,y.drawSpeedLines=py,y.drawStickFigure=qf,y.drawStickSmear=h4,y.drawTimeChip=mE,y.drawTrail=Sx,y.drawVignette=cE,y.drawnPathTarget=sT,y.dripPath=O2,y.duck=ob,y.easeIn=N0,y.easeInCubic=Ra,y.easeInOut=D0,y.easeInOutCubic=ti,y.easeInOutQuad=L0,y.easeInQuad=H0,y.easeOut=W0,y.easeOutCubic=Ha,y.easeOutQuad=F0,y.editDistance=Fu,y.editError=Vi,y.editLog=_s,y.elasticOut=z0,y.ellipsePoints=wi,y.ellipsoidMesh=Ep,y.embrace=WT,y.embraceSpacing=NT,y.envelopeAt=g2,y.erasable=aT,y.expandBeats=Zo,y.expandParametricEasings=yu,y.extrudeMesh=Ap,y.fadeWindow=Dy,y.flipPose=sp,y.flipTracks=p3,y.flipTravel=ip,y.formatVersionFor=Pa,y.frameRect=m2,y.frameSize=p2,y.from=Px,y.fromJSON=Hw,y.fromTo=$x,y.gag=Ih,y.gagDuration=nr,y.gaitBob=Kl,y.gaitGive=Yl,y.gaitPose=yf,y.gaitStrideLength=Xr,y.getEasingFunction=Dt,y.getInterpolator=ii,y.getMotionPathPoint=Ua,y.getPathLength=ow,y.getPointAtProgress=U0,y.goat=J1,y.gridLinesFor=dd,y.hairFollow=ly,y.hairFollowTracks=QT,y.hairHangs=zg,y.hairMotionAt=JT,y.hairMotionOf=Ni,y.hairlineAt=Wi,y.handAt=eT,y.handGrip=To,y.handJoints=Kr,y.handJointsAt=mf,y.handPath=jh,y.handPose=Wt,y.handProp=xi,y.hasKeyframes=O0,y.hashSeed=re,y.headPoint=zv,y.heldTime=C0,y.helicopter=q1,y.helpUp=BT,y.helpUpSpacing=DT,y.holdingLayers=$m,y.horse=X1,y.horseStrideLength=rA,y.house=$1,y.humanCyclePose=WS,y.humanDanceFrame=Ci,y.humanDanceTracks=_M,y.humanFieldLabel=xM,y.humanGag=mm,y.humanGaitPose=vo,y.humanGaitStrideLength=Mo,y.humanPlan=rc,y.humanPose=vt,y.illustrationTones=Nl,y.imageSequence=Lx,y.inertiaDuration=ns,y.inertiaRest=es,y.inertiaValueAt=vr,y.inertiaVelocityAt=Ub,y.interpolateArray=fu,y.interpolateColor=du,y.interpolateMotionPath=Iw,y.interpolateNumber=Ie,y.interpolatePathString=mu,y.interpolateQuaternion=gu,y.interpolateString=ja,y.invertSimilarity=T2,y.isCubicBezierEasing=Qn,y.isHeld=Wc,y.isInertiaTrack=Ve,y.isMotionPathPoint=Db,y.isMotionPathTrack=$a,y.isParametricEasing=Vs,y.isPathData=is,y.isSpringTrack=Je,y.isTextTrack=mr,y.isUnderdamped=jb,y.isUnresolved=Ww,y.isoDepth=il,y.isometricBoxFaces=rl,y.isometricFaces=ol,y.jointsInScene=Jm,y.jointsToScene=zf,y.leafOutfit=Mm,y.leafOutfitContours=Hc,y.lightFlicker=uE,y.lightningFlash=hE,y.lineReveal=Ky,y.linear=Mr,y.lipSyncKeyframes=ah,y.lipSyncOver=Wo,y.lipSyncTracks=B3,y.lit=rh,y.live=le,y.lookFields=hh,y.loopBeats=u2,y.loopEase=i2,y.loopNoise=r2,y.loosePartsOf=n0,y.lyingPose=Y1,y.mapEase=di,y.mat4=z2,y.matchMedia=Hx,y.maxStaggerDistance=Oa,y.measuredHipWidth=wg,y.meetDandiya=h3,y.meetHands=LT,y.meetingSpacing=FT,y.metaballContours=$2,y.metaballField=Ku,y.mirrorHumanPose=eg,y.mirrorPose=Xf,y.mittenAt=Bc,y.mixColors=oh,y.mixHandPoses=fs,y.mixPoses=Xc,y.morphPath=nu,y.motorbike=A1,y.mount=Gd,y.mountAll=Vd,y.narrationMarkers=Gw,y.narrationSceneAt=Uw,y.naturalRest=Qs,y.nearestBeat=Vw,y.nextBeat=Jw,y.niceCeiling=ty,y.objectPositionAt=gh,y.organicBodyContours=Mg,y.organicCenterLine=Fi,y.outfitPreset=ay,y.owl=ab,y.pageTransition=Nx,y.panelMesh=xp,y.parametricEasing=Y0,y.parrot=lb,y.parseAnchor=jn,y.parseEdge=vl,y.parsePath=An,y.parseTrigger=Ml,y.partialPath=sn,y.pathLength=Cl,y.pedallingKeys=hx,y.pedallingPose=x0,y.penroseStairs=P2,y.penroseTriangle=x2,y.persona=X4,y.phaseOf=xn,y.pieceMotion=Ui,y.pigeon=rb,y.pingPong=el,y.planNarration=Xw,y.plantDanceFoot=tp,y.play=v5,y.playSequence=N5,y.playWhenVisible=Gk,y.playheadCrossings=Ja,y.pointAlong=Wr,y.pointAtDistance=La,y.pointOnHead=e3,y.pointsToPath=Du,y.popIn=na,y.pose=Bt,y.poseTracks=Yv,y.powSimilarity=E2,y.projectIsometric=$r,y.propActions=ya,y.propAnchors3D=f1,y.propAt=da,y.propControls=s0,y.propLineWidth=Qc,y.propObjects=QA,y.propPartsInSpace=d1,y.propPreset=l0,y.propRide=zA,y.propRide3D=ux,y.propScript=hb,y.propScript3D=ox,y.propShapeMesh=or,y.propSurface=zE,y.propTarget=m1,y.propTow=KA,y.propView=c1,y.quadruped=kn,y.quat=Ew,y.quickPlay=wx,y.quickTo=Fx,y.rabbit=Z1,y.randomBetween=Qa,y.randomChoice=Fw,y.randomNormal=Lw,y.randomSnapped=xu,y.reachCharacter=qe,y.reachOf=Wy,y.resolveActingStyle=xh,y.resolveBean=Im,y.resolveCharacterPoseKeys=Gc,y.resolveFacialHair=sm,y.resolveGait=Ti,y.resolveGlasses=rm,y.resolveHair=Kg,y.resolveHat=om,y.resolveHeadLook=lm,y.resolveHolding=xm,y.resolveIllustration=lf,y.resolveMeasurements=mc,y.resolveOrganicBody=kg,y.resolvePoseKeys=Vr,y.resolveSequence=Iu,y.resolveStickFrame=Jl,y.resolveStickPose=jf,y.resolveValue=tl,y.ribbon=Bu,y.ribbonHeadCap=zu,y.rideFloors=qo,y.rotateAbout=on,y.routineBeats=eo,y.rubberLimb=Rn,y.safeAreas=y2,y.scalePoints=H2,y.scenePreset=Fb,y.scenery=Hb,y.scriptActionSummaries=Rh,y.scriptTracks=ta,y.scrollProgress=Xk,y.scrubOnScroll=Zk,y.scrubPath=rT,y.seatHeight=Fv,y.serializeTimeline=Au,y.serializeTrack=Su,y.set=Ix,y.shade=Lo,y.shapeMesh=Ip,y.shapeToPathData=xr,y.shuffled=Nw,y.similarity=M2,y.similarityAbout=qu,y.similarityFixedPoint=ju,y.similarityMatrix=A2,y.simplifyKeyframes=bu,y.sittingPose=r0,y.skeletonInView=lo,y.sketchPen=Dr,y.skyColors=Rb,y.smoothPath=lh,y.smoothToward=wd,y.snapAxis=ud,y.snapConfig=Md,y.snapDuration=Td,y.snapProgress=Sd,y.softCartoonCharacter=RT,y.solveAt=Bs,y.solvePlanSpace=ms,y.solveProp=e0,y.songbird=nb,y.soundsOf=Mp,y.speechDuration=Ry,y.speechLength=Hp,y.spliceTracks=jA,y.splitText=_x,y.springDuration=_0,y.springFollow=li,y.springValueAt=qb,y.squashStretch=R2,y.squirrel=Q1,y.stagePlanSpace=cn,y.stageSpots=U3,y.staggerDistance=Ia,y.staggerOffset=pr,y.staggerOffsets=yr,y.staggerSpan=Js,y.stepsDuration=wy,y.stepsEasing=K0,y.stepsToKeys=Oh,y.stickFigureAt=Ql,y.stickFigureJoints=Ee,y.stickFigureTarget=Zl,y.stickToHuman=rp,y.strideLength=Mf,y.surfaceBox=St,y.surfaceScript=K4,y.sweepingPose=pm,y.syncMediaElement=zd,y.talkingMouth=Sf,y.taperedLine=bi,y.taperedOutline=qt,y.textAt=Mu,y.tf=kx,y.ticker=Cx,y.timeline=Ox,y.to=xx,y.toJSON=Rw,y.toKeyframedTrack=Pw,y.toKeyframedTracks=$w,y.torusNoise=o2,y.trackTargets=en,y.tractor=M1,y.trailSamples=w2,y.trainCar=T1,y.tree=x1,y.triggerDistance=cs,y.truck=k1,y.tubeMesh=Pp,y.unknownName=dt,y.unmount=H5,y.valueAt=zo,y.vec3=F2,y.vehicle=Xe,y.walkPose=vf,y.wheelchair=D1,y.whiteboard=bT,y.withAlpha=xe,y.withErased=oT,y.withExpression=an,y.wobble=s2,y.wrapText=sa,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));
|
|
66
|
+
`)}function FA(t,e,n,s={}){const i=s.color??"#555",r=s.size??60;for(const o of e){const a=(n-o.time)/o.length;if(a<=0||a>=1)continue;const l=re(`${o.kind}:${o.time}:${o.x}`);o.kind==="dust"?yy(t,{x:o.x,y:o.y},a,{size:r,color:i,seed:l}):o.kind==="exhaust"?WA(t,o,a,r,i,l):o.kind==="skid"?DA(t,o,a,n,i):o.kind==="honk"?BA(t,o,a,r,i):o.kind==="smoke"?LA(t,o,n,r,i):o.kind==="leaves"&&NA(t,o,a,r,s.leafColor??"#5cae5a",i,l)}}function LA(t,e,n,s,i,r){const o=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+o*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 NA(t,e,n,s,i,r,o){const a=e.direction??1,l=e.toY??e.y+s*3;t.save(),t.lineWidth=Math.max(1,s*.02),t.strokeStyle=r,t.fillStyle=i;for(let c=0;c<4;c++){const h=re(`${o}:${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,m=u*u*.4+u*.6,g=d+a*u*s*(.6+h)+Math.sin(u*9+h*6)*s*.18,p=Math.min(l-2,f+(l-f)*m);t.globalAlpha=n>.85?(1-n)/.15:1,t.save(),t.translate(g,p),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 WA(t,e,n,s,i,r){const o=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=(re(`${r}:${a}`)%100/100-.5)*s*.1,h=e.x+o*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 DA(t,e,n,s,i){const r=e.toX??e.x,o=Math.min(1,(s-e.time)/e.length*3),a=e.x+(r-e.x)*o;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 BA(t,e,n,s,i){const r=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 o=s*(.15+.5*(1-(1-n)**2));for(let a=-1;a<=1;a++){const l=a*Math.PI/7,c=e.x+r*Math.cos(l)*o,h=e.y+Math.sin(l)*o;t.beginPath(),t.arc(c,h,s*.12,r>0?-Math.PI/3:Math.PI*2/3,r>0?Math.PI/3:Math.PI*4/3),t.stroke()}t.restore()}function zA(t){const e=new Ht({id:`${t.propId}-ride`,tracks:t.propTracks.filter(h=>h.target===t.propId)}),n=t.every??33,s=[],i=[],r=[],o=[];let a=1;for(let h=t.start;;h=Math.min(t.end,h+n)){const u=da(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),r.push({time:h,value:Math.abs(f)}),o.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:r},{id:`${l}-facing`,target:l,property:"facing",keyframes:qA(o)}),c}function qA(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 jA(t,e,n){const s=o=>`${o.target}\0${o.property}`,i=new Map(e.map(o=>[s(o),o]));return[...t.map(o=>{const a=i.get(s(o));if(!a)return o;i.delete(s(o));const c=[...(o.keyframes??[]).filter(h=>h.time<n.from||h.time>n.to),...a.keyframes??[]].sort((h,u)=>h.time-u.time);return{...o,keyframes:c}}),...i.values()]}function KA(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,r=s.props,o=s.prop.wheelRadius,a=[],l=[],c=[];let h=r.wheelSpin??0,u;for(let f=t.start;;f=Math.min(t.end,f+n)){const m=da(t.leader,{state:e.getStateAtTime(f)},t.leaderId),g=m.anchor(t.hitch),p=m.values.turn,y=Bs(s.prop,{...r,turn:p},s.propScale).anchors[t.anchor];if(!y)throw new Error(`propTow: ${s.prop.kind} has no anchor "${t.anchor}"`);const v=g.x-y.point.x;if(u!==void 0&&o){const w=Math.sin(p*Math.PI/2);h+=(v-u)*(w||1)/s.propScale/o*(180/Math.PI)}if(u=v,a.push({time:f,value:v-i}),l.push({time:f,value:p}),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},...o?[{id:`${d}-wheelSpin`,target:d,property:"wheelSpin",keyframes:c}]:[]]}const $b=new WeakMap;function YA(t,e){const n=e?.some(Boolean)?e.map(d=>d?1:0).join(""):"";let s=$b.get(t);s||$b.set(t,s=new Map);const i=s.get(n);if(i)return i;const r=or(t),o={vertices:r.vertices,faces:r.faces.filter((d,f)=>!e?.[f])},a=o.vertices.flatMap(d=>[d[0],d[1],d[2]]),l=o.vertices.map(()=>[0,0,0]),c=[];o.faces.forEach(d=>{for(const g of d.corners)for(const p of[0,1,2])l[g][p]+=d.normal[p];const[f,...m]=d.corners;for(let g=0;g+1<m.length;g++){const[p,y,v]=[f,m[g],m[g+1]],[w,k,S]=[o.vertices[p],o.vertices[y],o.vertices[v]],x=[k[0]-w[0],k[1]-w[1],k[2]-w[2]],M=[S[0]-w[0],S[1]-w[1],S[2]-w[2]],E=[x[1]*M[2]-x[2]*M[1],x[2]*M[0]-x[0]*M[2],x[0]*M[1]-x[1]*M[0]],T=E[0]*d.normal[0]+E[1]*d.normal[1]+E[2]*d.normal[2];c.push(...T>=0?[p,y,v]:[p,v,y])}});const h=l.flatMap(d=>{const f=Math.hypot(...d)||1;return[d[0]/f,d[1]/f,d[2]/f]}),u=Ho({positions:a,normals:h,indices:c});return s.size>=16&&s.clear(),s.set(n,u),u}function XA(t,e,n={}){const s=t.ink??n.ink??"#26262b",i=(n.outline??2)*(t.outline??1),r=t.glow&&e.glow>0?GA(t.glow.color,e.glow):void 0;return{color:t.fill??s,creases:or(t.shape).creases!==!1,shading:n.shading??"toon",...i>0?{outline:{width:i,color:s}}:{},...r?{emissive:r}:{},...t.seeThrough?{opacity:.45*e.opacity}:e.opacity<1?{opacity:e.opacity}:{}}}function GA(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 UA=Ho(lp(1,.002,28));function VA(t,e,n){const s=t.rig,[i,r]=s.footprint??[s.length*.45,s.length],o=Math.max(0,Ot(s,e,"lift")),a=Math.max(0,Ot(s,e,"size"))/(1+o*.8);return{mesh:UA,world:Ft(n,al([0,.004,0],[0,0,0,1],[i*.55*a||1e-4,1,r*.55*a||1e-4])),material:{color:"#000000",shading:"unlit",opacity:.16*a}}}const JA=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),ZA=1,QA={kind:"prop",validate(t){const e=t,n=typeof e.prop=="string"&&e.prop in js?[]:[dt("prop preset",e.prop,Object.keys(js))];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(r=>r===s?e[i]:0).join(", ")}]`);return n},prepare(t){const e=t;return l0(e.prop,e.options)},resolve({object:t,prepared:e,values:n,world:s,camera:i,lights:r=[],fog:o,toScreen:a}){const l=t,c=e,h={...l.values};for(const[M,E]of n)typeof E=="number"&&!JA.has(M)&&(h[M]=E);h.turn=0,h.tilt=0;const u=Ft(i.view,s),d={toView:M=>ae(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=d1(c.rig,h),E=M.map(({part:P,local:I})=>({part:P.id,mesh:or(P.shape),...Vh(or(P.shape),I)})),T=o1(E),A=M.map((P,I)=>({...P,hidden:l1(P.part.id,E[I].mesh,P.local,E[I].key,T)})).filter(({opacity:P})=>P>.01).map(({part:P,matrix:I,glow:O,opacity:_,hidden:L})=>({mesh:YA(P.shape,L),world:Ft(s,I),material:XA(P,{glow:O,opacity:_},{shading:l.shading,ink:l.ink,outline:l.outline})}));return{meshes:l.shadow===!1?A:[VA(c,h,s),...A]}}const m=a(f),g=a(d.toView([0,c.rig.height/2+1,0])),p=Math.hypot(g.x-m.x,g.y-m.y),y=r.length===0?void 0:(M,E)=>{const T=ae(s,M),A=[s[0]*E[0]+s[4]*E[1]+s[8]*E[2],s[1]*E[0]+s[5]*E[1]+s[9]*E[2],s[2]*E[0]+s[6]*E[1]+s[10]*E[2]],P=Math.hypot(...A)||1;return{light:rf(T,[A[0]/P,A[1]/P,A[2]/P],r),fog:of(o,Math.hypot(T[0]-i.position[0],T[1]-i.position[1],T[2]-i.position[2]))}},v=e0(c.rig,h,d,p,{perspective:!0,near:i.near,slice:ZA,light:y}),w={look:l.look,style:l.style,ink:l.ink,paper:l.paper,fog:o?.color},k=Qc(v),S=v.cells??[],x=Math.max(...S.map(M=>-M.depth),-f[2]);return{drawables:[...l.shadow===!1?[]:[{depth:x+c.rig.length,draw:M=>th(M,v,w)}],...S.map(M=>({depth:-M.depth,draw(E,T){E.lineCap="round",E.lineJoin="round",hp(E,M.parts,k,{...w,time:T.time})}}))]}}},E0=["do","at","for","to","through","toward","speed","height","open","on","wind"],tx=.25,ex=800/180,nx=220,sx=300,ix=["turn"];function rx(t){const e=ya(t),n=Object.keys(t.moves??{});return Object.keys(e).filter(s=>!n.includes(s)&&!ix.includes(s)&&!(e[s].needs??[]).includes("to"))}function Ib(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=rx(e),i=[...n,"face","hold",...s.filter(o=>o!=="hold")],r=[];return t.forEach((o,a)=>{const l=u=>r.push({beat:a,message:u});if(!o||typeof o!="object"||Array.isArray(o))return l(`Each beat must be an object like { do: '${i[0]??"hold"}' }.`);const c=o,h={duration:"for",path:"through",points:"through",position:"to",heading:"toward",direction:"toward"};for(const u of Object.keys(c))E0.includes(u)||l(dt("beat field",u,E0,h[u]));if(typeof c.do!="string"||!i.includes(c.do)){const u=c.do==="turn"?"face":void 0;return l(dt(`${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&&!qn(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(qn))&&l("`through` is a list of points on the ground, each [x, z] metres.")),c.do==="face"&&!(qn(c.toward)||typeof c.toward=="number")&&l("`face` needs `toward`: a point [x, z] or a heading in degrees.")}),r}function ox(t,e,n,s){const i=Ib(n,e);if(i.length>0)throw new Error(`propScript3D (${e.kind}): ${i.length} problem(s) in the beats:
|
|
67
|
+
${i.map(w=>` beat ${w.beat}: ${w.message}`).join(`
|
|
68
|
+
`)}`);const r={};for(const w of[...Object.keys(Ds),...Object.keys(e.rig.controls)])r[w]=s.values?.[w]??Ot(e.rig,{},w);let[o,a]=s.position??[0,0],l=s.heading??0;const c=new Map,h=(w,k,S,x="linear")=>{const M=c.get(w)??[];M.push({time:k,value:S,easing:x}),c.set(w,M)},u=(w,k,S)=>h(w,k,S);h("x",0,o),h("z",0,a),h("rotateY",0,l);const d=(w,k)=>{const S=Do(l,k);if(Math.abs(S)<1)return w;const x=Math.max(nx,Math.abs(S)*ex);return u("rotateY",w,l),l+=S,h("rotateY",w+x,l,"ease-in-out"),w+x},f=(w,k,S)=>{const x=Cp([[o,a],...k.through??[k.to]]);if(x.length<2)return S;const M=d(S,Cs(x[0].point,x[1].point)),E=x[x.length-1].at,T=k.for??E/(k.speed??w.speed)*1e3,A=Dt("ease-in-out"),P=Math.min(sx,T/4);for(const[V,tt]of Object.entries(w.set??{}))u(V,M,r[V]),h(V,M+1,tt),r[V]=tt;const I=w.flies?k.height??(r.lift>.05?r.lift:2):void 0,O=I!==void 0&&I>.05;for(const[V,tt]of Object.entries(w.hold??{}))u(V,M,r[V]),h(V,M+P,tt,"ease-out"),O||(h(V,M+T-P,tt),h(V,M+T,0,"ease-in")),r[V]=O?tt:0;I!==void 0&&(u("lift",M,r.lift),h("lift",M+Math.min(T*.35,1400),I,"ease-out"),h("lift",M+T,I),r.lift=I);const _={...r};let L=l;for(let V=0;;V=Math.min(E,V+tx)){const tt=M+Rp(A,V/E)*T,{point:J,direction:F}=_p(x,V);L+=Do(L,Cs([0,0],F)),h("x",tt,J[0]),h("z",tt,J[1]),h("rotateY",tt,L);for(const[B,Y]of Object.entries(w.perMetre??{}))h(B,tt,_[B]+V*Y);for(const[B,Y]of Object.entries(w.perSecond??{}))h(B,tt,_[B]+(tt-M)/1e3*Y);if(V>=E)break}for(const[V,tt]of Object.entries(w.perMetre??{}))r[V]=_[V]+E*tt;for(const[V,tt]of Object.entries(w.perSecond??{}))r[V]=_[V]+T/1e3*tt;return[o,a]=x[x.length-1].point,l=L,M+T},m=(w,k)=>{const S=Object.fromEntries(Object.entries(w).filter(([M])=>!["at","to","through","toward"].includes(M))),x=hb(t,e,[S],{start:{...r,turn:1},scale:100,style:s.style,exaggeration:s.exaggeration});for(const M of x.tracks){if(ax.includes(M.property))continue;const E=M.keyframes??[],T=r[M.property];if(!E.every(A=>A.value===T)){u(M.property,k,T);for(const A of E)A.time>0&&c.get(M.property).push({...A,time:k+A.time});r[M.property]=E[E.length-1].value}}return k+x.duration},g=[];let p=0;for(const w of n){const k=w.at??p;let S=k;const x=e.moves?.[w.do];x?S=f(x,w,k):w.do==="face"?S=d(k,typeof w.toward=="number"?w.toward:Cs([o,a],w.toward)):w.do==="hold"?S=k+(w.for??1e3):S=m(w,k),g.push({do:w.do,start:k,end:S}),p=S}const y=`${s.scene}/${t}`;return{tracks:[...c].map(([w,k])=>({id:`${t}-${w}`,target:y,property:w,keyframes:Op(k)})),duration:p,beats:g,end:{position:[o,a],heading:l,values:{...r}}}}const ax=["x","y","turn","facing","tilt"],lx=.35,A0={seated:Ae.sit,astride:{...Ae.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:{...Ae.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:{...Ae.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:{...Ae.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}},cx=22,Ob=38;function x0(t,e=A0.cycling){const n=t*Math.PI*2,s=o=>({swing:(e["leg.left.swing"]??40)+cx*Math.cos(n+o),knee:(e["leg.left.knee"]??70)+Ob*(.5+.5*Math.cos(n+o))-Ob*.5,ankle:12*Math.sin(n+o)}),i=s(0),r=s(Math.PI);return{...e,"leg.left.swing":i.swing,"leg.left.knee":i.knee,"leg.left.ankle":i.ankle,"leg.right.swing":r.swing,"leg.right.knee":r.knee,"leg.right.ankle":r.ankle}}function hx(t){const e=t.cadence??1.2,n=Math.max(2,t.samplesPerTurn??8),s=1e3/e/n,i=[];for(let r=t.start,o=0;r<t.end;r+=s,o++)i.push({time:Math.round(r),pose:x0((r-t.start)/1e3*e,t.base),...o>0?{act:!1}:{}});return i.push({time:t.end,pose:x0((t.end-t.start)/1e3*e,t.base),act:!1}),i}const Cb=(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 ux(t){const e=`${t.scene}/${t.propId}`,n=new Ht({id:`${t.propId}-ride-3d`,tracks:t.propTracks.filter(p=>p.target===e)}),s=t.placement??{},[i,r,o]=s.position??[0,0,0],a=t.prop.rig,l=Ps({...t.character,height:1}),c={...lt,...t.pose??A0.seated},h=cn(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 p=t.start;;p=Math.min(t.end,p+d)){const y=n.getStateAtTime(p).values.get(e)??new Map,v=(_,L)=>{const j=y.get(_);return typeof j=="number"?j:L},w={...s.values};for(const _ of Object.keys(a.controls))w[_]=v(_,s.values?.[_]??Ot(a,{},_));for(const _ of["pitch","roll","squash","lift","lean","size"])w[_]=v(_,s.values?.[_]??Ot(a,{},_));const k=f1(a,w)[t.anchor];if(!k)throw new Error(`propRide3D: ${t.prop.kind} has no anchor "${t.anchor}" (it has ${Object.keys(a.anchors??{}).join(", ")||"none"})`);const S=v("rotateY",s.heading??0),x=Cb(k,S),M=[v("x",i)+x[0],v("y",r)+x[1],v("z",o)+x[2]],E=S+u,T=Cb(h,E);let A=[M[0]-T[0],M[1]-T[1],M[2]-T[2]];const P=(_,L)=>{const j=L*L*(3-2*L);return[_[0]+(A[0]-_[0])*j,A[1]*j+lx*Math.sin(Math.PI*L),_[1]+(A[2]-_[1])*j]},I=t.mount?Math.max(1,t.mount.for??450):0,O=t.dismount?Math.max(1,t.dismount.for??450):0;if(t.mount&&p<t.start+I?A=P(t.mount.from,(p-t.start)/I):t.dismount&&p>t.end-O&&(A=P(t.dismount.to,(t.end-p)/O)),f.x.push({time:p,value:A[0]}),f.y.push({time:p,value:A[1]}),f.z.push({time:p,value:A[2]}),f.rotateY.push({time:p,value:E}),p>=t.end)break}const m=t.riderId,g=`${t.scene}/${m}`;return Object.keys(f).map(p=>({id:`${m}-${p}`,target:g,property:p,keyframes:f[p]}))}const _b={ground:"#7fb56a",hills:"#5f9a58",city:"#4b5468",cloud:"#ffffff",sun:"#ffd45c",moon:"#f3f0e0",rain:"#9fc4e8",snow:"#ffffff",wall:"#e9e1cf",floor:"#b08a5e",skirting:"#8a6a44",frame:"#f7f3ea"},dr=[[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"]],fr=(t,e,n)=>{const s=o=>[1,3,5].map(a=>parseInt(o.slice(a,a+2),16)),[i,r]=[s(t),s(e)];return`#${i.map((o,a)=>Math.round(o+(r[a]-o)*n).toString(16).padStart(2,"0")).join("")}`},dx=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 Rb(t){const e=(t%24+24)%24;for(let n=1;n<dr.length;n++){const[s,i,r]=dr[n-1],[o,a,l]=dr[n];if(e<=o){const c=(e-s)/(o-s);return{top:fr(i,a,c),bottom:fr(r,l,c)}}}return{top:dr[0][1],bottom:dr[0][2]}}const fx=(t,e)=>{const n=((t-e)%24+24)%24;return n<=12?n/12:-1},gx=9,mx=55,px=28;function Hb(t){const{x:e,y:n,width:s,height:i}=t,r=t.kind??"sky",o=t.ground??n+i*.85,a={..._b,...t.colors},l=t.horizon??"hills",c=t.window!==!1,h=Se(t.seed??1),u=s*i/1e5,d=Array.from({length:Math.ceil(gx*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(mx*u)+4},()=>({u:h.next(),v:h.next(),speed:.8+h.next()*.5})),m=Array.from({length:Math.ceil(px*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})),p=Array.from({length:6},()=>({phase:h.next()*Math.PI*2,amp:.5+h.next()})),y=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},w=_s(),k=(A,P)=>w.keys(A)?.length?w.valueAt(A,P):v[A],S=(A,P)=>{const I=fx(A,P),O=I<0?.5:I,_=o-n;return{x:.1*s+.8*s*O,y:I<0?_+i*.2:_-Math.sin(O*Math.PI)*_*.8,up:I>=0}},x=(A,P,I,O,_)=>{const L=P("hour"),{top:j,bottom:V}=Rb(L),tt=A.createLinearGradient(0,O.y,0,O.ground);tt.addColorStop(0,j),tt.addColorStop(1,V),A.fillStyle=tt,A.fillRect(O.x,O.y,O.w,O.ground-O.y);const J=dx(L);if(J<.6){A.fillStyle="#ffffff",A.globalAlpha=(.6-J)/.6*.9;for(const C of g)A.beginPath(),A.arc(O.x+C.u*O.w,O.y+C.v*(O.ground-O.y),C.size,0,Math.PI*2),A.fill();A.globalAlpha=1}const F=S(L,6),B=S(L,18),Y=Math.min(O.w,O.h)*.06;if(F.up&&(A.fillStyle=a.sun,A.beginPath(),A.arc(O.x+F.x/s*O.w,O.y+F.y/i*O.h,Y,0,Math.PI*2),A.fill()),B.up){const C=O.x+B.x/s*O.w,z=O.y+B.y/i*O.h;A.fillStyle=a.moon,A.beginPath(),A.arc(C,z,Y*.8,0,Math.PI*2),A.fill(),A.fillStyle=j,A.beginPath(),A.arc(C-Y*.35,z-Y*.15,Y*.7,0,Math.PI*2),A.fill()}const R=Math.max(0,Math.min(1,P("clouds"))),K=Math.max(-1,Math.min(1,P("wind"))),st=Math.round(R*d.length);A.fillStyle=fr("#ffffff",a.cloud==="#ffffff"?"#ffffff":a.cloud,1),A.globalAlpha=.55+.4*J;for(let C=0;C<st;C++){const z=d[C],X=((z.u*O.w+K*I*.012*(.6+z.size*.5))%(O.w*1.4)+O.w*1.4)%(O.w*1.4)-O.w*.2,W=O.x+X,N=O.y+(.08+z.v*.42)*(O.ground-O.y),D=Math.min(O.w,O.h)*.07*z.size;for(let G=0;G<z.puffs;G++)A.beginPath(),A.ellipse(W+(G-(z.puffs-1)/2)*D*.9,N+G%2*D*.25,D*(G%2?.8:1),D*.62,0,0,Math.PI*2),A.fill()}A.globalAlpha=1;const $=C=>fr(fr(C,"#0b1530",.65),C,J);if(l==="hills"){A.fillStyle=$(a.hills),A.beginPath(),A.moveTo(O.x,O.ground);const C=40;for(let z=0;z<=C;z++){const X=z/C;let W=0;p.forEach((N,D)=>W+=Math.sin(X*Math.PI*(1.5+D*.7)+N.phase)*N.amp),A.lineTo(O.x+X*O.w,O.ground-Math.max(0,W)*O.h*.045-O.h*.03)}A.lineTo(O.x+O.w,O.ground),A.closePath(),A.fill()}else if(l==="city"){A.fillStyle=$(a.city);let C=O.x;const z=O.w/18;for(const X of y){if(C>O.x+O.w)break;const W=z*X.w,N=O.h*.22*X.h;if(A.fillRect(C,O.ground-N,W,N),X.windows&&J<.5){A.fillStyle="#ffd66b",A.globalAlpha=.5-J;for(let D=O.ground-N+6;D<O.ground-8;D+=9)for(let G=C+4;G<C+W-4;G+=8)A.fillRect(G,D,3,4);A.globalAlpha=1,A.fillStyle=$(a.city)}C+=W+z*.15}}A.fillStyle=$(a.ground),A.fillRect(O.x,O.ground,O.w,O.y+O.h-O.ground)},M=(A,P,I,O)=>{const _=Math.max(-1,Math.min(1,P("wind"))),L=Math.max(0,Math.min(1,P("rain"))),j=Math.max(0,Math.min(1,P("snow")));if(L>0){A.strokeStyle=a.rain,A.globalAlpha=.35+.45*L,A.lineWidth=1.2,A.lineCap="round";const V=O.h*.05,tt=_*.45,J=Math.round(L*f.length);A.beginPath();for(let F=0;F<J;F++){const B=f[F],Y=((B.v*O.h+I*B.speed*.9)%O.h+O.h)%O.h,R=((B.u*O.w+Y*tt)%O.w+O.w)%O.w;A.moveTo(O.x+R,O.y+Y),A.lineTo(O.x+R+tt*V,O.y+Y+V)}A.stroke(),A.globalAlpha=1}if(j>0){A.fillStyle=a.snow,A.globalAlpha=.85;const V=Math.round(j*m.length);for(let tt=0;tt<V;tt++){const J=m[tt],F=((J.v*O.h+I*J.speed*.08)%O.h+O.h)%O.h,B=Math.sin(I*.002+J.sway)*O.w*.02,Y=((J.u*O.w+B+_*F*.3)%O.w+O.w)%O.w;A.beginPath(),A.arc(O.x+Y,O.y+F,J.size,0,Math.PI*2),A.fill()}A.globalAlpha=1}},T={kind:"scenery",target:{type:"custom",x:e,y:n,width:s,height:i,props:v,about:{kind:r==="room"?"room":"sky",summary:r==="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(A=>[A,yx(A)]))},draw(A,P,I){const O=P.props??{},_=j=>Number(O[j]??v[j]??0);A.save();const L={x:0,y:0,w:s,h:i,ground:o-n};if(r==="sky")x(A,_,I,L),M(A,_,I,L);else if(A.fillStyle=a.wall,A.fillRect(0,0,s,L.ground),A.fillStyle=a.floor,A.fillRect(0,L.ground,s,i-L.ground),A.fillStyle=a.skirting,A.fillRect(0,L.ground-i*.012,s,i*.012),c){const j=s*.26,V=L.ground*.5,tt=s*.62,J=L.ground*.14;A.fillStyle=a.frame,A.fillRect(tt-6,J-6,j+12,V+12),A.save(),A.beginPath(),A.rect(tt,J,j,V),A.clip(),x(A,_,I,{x:tt,y:J,w:j,h:V,ground:J+V*.8}),M(A,_,I,{x:tt,y:J,w:j,h:V}),A.restore(),A.strokeStyle=a.frame,A.lineWidth=4,A.beginPath(),A.moveTo(tt+j/2,J),A.lineTo(tt+j/2,J+V),A.moveTo(tt,J+V/2),A.lineTo(tt+j,J+V/2),A.stroke()}A.restore()}},ground:o,anchor(A,P=1/0){const I=k("hour",P);if(A==="sun"||A==="moon"){const O=S(I,A==="sun"?6:18);return{x:e+O.x,y:n+O.y}}if(A==="horizon")return{x:e+s/2,y:o-i*.03};if(A==="ground")return{x:e+s/2,y:o};throw new Error(`scenery: ${dt("place",A,["sun","moon","horizon","ground"])}`)},set(A,P){if(!(A in v))throw new Error(`scenery: ${dt("value",A,Object.keys(v))}`);if(typeof P.value!="number"||!Number.isFinite(P.value))throw new Error("scenery.set needs `value`, a number");return w.tween(A,k(A,P.at),P.value,P,1e3),T},tracks:w.tracks};return T}function yx(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 Fb(t,e){const{width:n,height:s}=e,i=e.ground??s*.85,r=e.scale??s/4.5,o={x:0,y:0,width:n,height:s,ground:i},a=(l,c,h={})=>({preset:l,x:n*c,scale:r,...h});switch(t){case"park":return{scenery:{...o,hour:10.5,clouds:.35,horizon:"hills",...e.scenery},props:[a("tree",.14,{scale:r*1.1}),a("chair",.5,{turn:0}),a("tree",.86,{scale:r*.9})]};case"street":return{scenery:{...o,hour:16,clouds:.25,horizon:"city",colors:{ground:"#8a8f99"},...e.scenery},props:[a("house",.2,{scale:r*.75,turn:.1}),a("car",.5,{turn:1,scale:r*.9}),a("house",.78,{scale:r*.7,turn:.1}),a("tree",.95,{scale:r*.8})]};case"office":return{scenery:{...o,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:{...o,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(dt("scene preset",t,["park","street","office","home"]))}}function bx(t,e){const n=Fb(t,e),s=Hb(n.scenery),i=n.props.map(r=>m1({x:r.x,y:s.ground,prop:l0(r.preset),scale:r.scale,values:{turn:r.turn??0,...r.values}}));return{scenery:s,props:i,ground:s.ground}}function wx(t){const{timeline:e}=t,n=new _n;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,r=!1;const o=c=>{if(r)return;const h=i===null?0:c-i;i=c,h>0&&e.tick(h),s=requestAnimationFrame(o)},a=()=>{s!==null||r||(i=null,s=requestAnimationFrame(o))},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(){r=!0,l(),e.stop(),n.clearTargets()}}}const kx={timeline:hk,to(t,e,n){const s=new Cn(n);return s.to(t,e),s},from(t,e,n){const s=new Cn(n);return s.from(t,e),s},fromTo(t,e,n,s){const i=new Cn(s);return i.fromTo(t,e,n),i},set(t,e,n){const s=new Cn(n);return s.set(t,e),s}};function Lb(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 vx(t,e){const n=t.length/4,s=new Float32Array(n*3),i=Math.min(.999,Math.max(0,e));for(let r=0;r<n;r++){const o=t[r*4]/255,a=t[r*4+1]/255,l=t[r*4+2]/255,c=t[r*4+3]/255,h=Math.max(o,a,l);if(h<=i)continue;const u=(h-i)/(1-i)*c/h;s[r*3]=o*u,s[r*3+1]=a*u,s[r*3+2]=l*u}return s}function Nb(t,e,n,s,i){const r=new Float32Array(t.length),o=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<o;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++){r[l(h,f)+u]=d/c;const m=t[l(h,Math.max(0,f-s))+u],g=t[l(h,Math.min(a-1,f+s+1))+u];d+=g-m}}return r}function Wb(t,e,n,s){const i=Math.max(1,Math.round(s/Math.sqrt(3)));let r=t;for(let o=0;o<3;o++)r=Nb(r,e,n,i,!0),r=Nb(r,e,n,i,!1);return r}function Mx(t,e={}){const n=t.canvas,s=n.width,i=n.height;if(!(s>0&&i>0))return;const r=Math.max(1,Math.round(e.downsample??4)),o=Math.max(1,Math.ceil(s/r)),a=Math.max(1,Math.ceil(i/r)),l=Lb(t,o,a),c=l?.getContext("2d");if(!l||!c)return;c.imageSmoothingEnabled=!0,c.drawImage(t.canvas,0,0,o,a);const h=vx(c.getImageData(0,0,o,a).data,e.threshold??.55),u=(e.radius??Math.max(s,i)*.02)/r,d=Wb(h,o,a,u),f=Wb(h,o,a,u*3),m=e.halo??.6,g=c.createImageData(o,a);for(let p=0;p<o*a;p++){for(let y=0;y<3;y++)g.data[p*4+y]=Math.round(Math.min(1,d[p*3+y]+f[p*3+y]*m)*255);g.data[p*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 Sx(t,e,n){const s=n.width??6,i=n.taper??1,r=n.fade??1,o=n.opacity??1,a=n.blend==="add";if(t.save(),e.length>=2){const c=Ex(e,s,i,r,o);a?(t.globalCompositeOperation="lighter",P0(t,c,n.color)):Ax(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,Tx(t,c)),t.globalAlpha=o,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 Tx(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 Ex(t,e,n,s,i){const r=t.map(c=>({x:c.at.x,y:c.at.y,width:e*(1-n*c.age)})),o=Bu(r),a=zu(r)??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:[o.left[c],o.left[c+1],o.right[c+1],o.right[c]],alpha:u,...d&&a&&{cap:a}})}return l}function P0(t,e,n){t.fillStyle=n;for(const s of e){const[i,r,o,a]=s.corners;t.globalAlpha=Math.min(1,s.alpha),t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(r.x,r.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(o.x,o.y),t.lineTo(a.x,a.y),t.closePath(),t.fill()}}function Ax(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,r=s?Math.sqrt(Math.abs(s.a*s.d-s.b*s.c)):1,o=e.map(g=>({...g,corners:g.corners.map(i),...g.cap&&{cap:{...g.cap,...i(g.cap),radius:g.cap.radius*r,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 o){const p=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 y of[...g.corners,...p])a=Math.min(a,y.x),l=Math.min(l,y.y),c=Math.max(c,y.x),h=Math.max(h,y.y)}if(!(c>a&&h>l))return;const u=Math.floor(a)-1,d=Math.floor(l)-1,f=s?Lb(t,Math.ceil(c)+1-u,Math.ceil(h)+1-d):null,m=f?.getContext("2d");if(!f||!m){P0(t,e,n);return}m.translate(-u,-d),m.globalCompositeOperation="lighter",P0(m,o,n),t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=1,t.drawImage(f,u,d),t.restore()}const xx=le.to,Px=le.from,$x=le.fromTo,Ix=le.set,Ox=le.timeline,Cx=le.ticker,_x=le.splitText,Rx=le.context,Hx=le.matchMedia,Fx=le.quickTo,Lx=le.imageSequence,Nx=le.pageTransition;L5(),b.ACTING_STYLES=Xn,b.AIRCRAFT_ACTING=i0,b.ANIMAL_GAITS=qs,b.ANIME_CAST=sy,b.BEAN_ARM_REACH=Rm,b.BEAN_BANGLE_STOPS=qm,b.BEAN_CAST=ry,b.BEAN_DARK_SOLE=Wm,b.BEAN_LEG_REACH=Hm,b.BEAN_SOLE=Nm,b.BEAT_FIELDS=Vo,b.BEAT_MOMENTS=Ns,b.BED_ACTING=F1,b.BIRD_ACTING=eb,b.BOARD_MARKS=kh,b.BOARD_THEMES=Zi,b.BODY_SHAPES=ho,b.CANVAS_PROPERTIES=ca,b.CASE_CARD_KINDS=ra,b.CASE_MARK_KINDS=oa,b.CHAIR_ACTING=C1,b.CHARACTER_BEAT_3D_FIELDS=ch,b.CHARACTER_CAST=Th,b.CHARACTER_GAIT_SPEEDS=Np,b.CHART_KINDS=Mh,b.CHART_SURFACE=Kn,b.CHART_THEMES=Qi,b.CODE_LANGUAGES=Yo,b.CODE_PANEL_EDITS=bh,b.CODE_SURFACE=Ji,b.CODE_THEME=Kp,b.CRICKET_ACTIONS=Zn,b.CRICKET_CAMERA_ANGLES=Ma,b.CRICKET_CASTS=d0,b.CRICKET_DECISION_VIEWS=cr,b.CRICKET_FIELDING_POSITIONS=Ks,b.CRICKET_FORMATS=Ge,b.CRICKET_MARKING_PROFILES=Sa,b.CRICKET_PITCH=Yt,b.CRICKET_PLAY_COMPONENTS=En,b.CRICKET_PLAY_EXAMPLES=Ab,b.CRICKET_VIEWS=va,b.Clock=zb,b.CompatTimeline=Cn,b.CustomBounce=_d,b.CustomEase=Cd,b.CustomWiggle=Rd,b.DANCE_STYLES=ln,b.DEFAULT_BAKE_INTERVAL_MS=Ka,b.DEFAULT_INERTIA_FRICTION=_a,b.DEFAULT_LABELS=qd,b.DEFAULT_SPRING=ge,b.DEFAULT_TRANSITION=W5,b.DESK_ACTING=R1,b.DOOR_ACTING=N1,b.Draggable=pl,b.EMBRACE=Xo,b.EXPRESSIONS=Mt,b.FACIAL_HAIR_STYLES=Oc,b.FINGERS=df,b.FLIPS=Ki,b.FOOT_SHAPES=ng,b.FORMAT_VERSION=xa,b.FRAME_ASPECTS=Wu,b.GAGS=mn,b.GAITS=Gt,b.GAIT_CYCLE_MS=Fh,b.GLASSES_STYLES=_c,b.HAIR_COLORS=Fe,b.HAIR_STILL=vs,b.HAIR_STYLES=Ac,b.HAND_MEETINGS=er,b.HAND_REST=Ct,b.HAND_SHAPES=Tt,b.HAT_STYLES=ko,b.HELD_ITEMS=Lc,b.HELP_UP=Yn,b.HORSE_ACTING=sA,b.HORSE_GAITS=QE,b.HOUSE_ACTING=I1,b.HUMAN_ACTING_RIG=uy,b.HUMAN_BUILDS=so,b.HUMAN_CYCLES=Rc,b.HUMAN_DANCES=Nn,b.HUMAN_EXPRESSIONS=oc,b.HUMAN_GAGS=So,b.HUMAN_POSES=Ae,b.HUMAN_REST=lt,b.IDENTITY_CAMERA=Dp,b.IDENTITY_SIMILARITY=v2,b.INERTIA_MAX_DURATION_MS=R0,b.InertiaTrackPlayer=ku,b.LiveTimeline=_e,b.MANGA_CAST=iy,b.MORPH_SAMPLES=hw,b.MUDRAS=Jr,b.ManualClock=Bb,b.MediaSync=Il,b.NOIR_AMBER=Kh,b.NOIR_CREAM=ia,b.NOIR_INK=yn,b.NOIR_KIT=Vy,b.NOIR_RED=Jn,b.OUTFIT_PRESETS=Eh,b.Observer=cd,b.POSES=he,b.PROP_BEAT_3D_FIELDS=E0,b.PROP_BEAT_FIELDS=pa,b.PROP_COMMON_ACTIONS=h0,b.PROP_COMMON_CONTROLS=Ds,b.PROP_PRESETS=js,b.PROP_SURFACE=zs,b.QUADRUPED_ACTING=o0,b.REMOVE_STYLES=jo,b.REST_POSE=ut,b.RIDING_POSES=A0,b.SAMPLE_STEP=fn,b.SCENERY_COLORS=_b,b.SCRIPT_ACTIONS=sr,b.SOFT_CARTOON_CAST=tr,b.SPRING_MAX_DURATION_MS=Ca,b.SPRING_PRESETS=wr,b.SPRING_STEP_MS=ts,b.STICK_ACTING_RIG=hy,b.ScrollAnimator=Ed,b.ScrollDriver=mi,b.ScrollMarkers=Ad,b.ScrollPin=vd,b.SmoothScroll=xl,b.SpringSampler=Zs,b.SpringTrackPlayer=wu,b.Stage=sd,b.TREE_ACTING=P1,b.Timeline=Ht,b.TinyflyPlayer=Lr,b.TinyflySequencer=Jd,b.TrackPlayer=nn,b.VEHICLE_ACTING=y1,b.VISEMES=dn,b.ValueResolver=Dw,b.VisibilityDriver=kd,b.WHEELCHAIR_ACTING=B1,b.WHITEBOARD_SURFACE=je,b.actCharacterTracks=gy,b.actKeyframes=Uo,b.actTracks=fy,b.actionNames=Ch,b.airplane=j1,b.anchorError=gn,b.animalStrideLength=ma,b.animatableProperties=Zy,b.applyBloom=Mx,b.applyCamera=J3,b.applyGroove=Gf,b.applySimilarity=sl,b.aspectOf=nl,b.assertBeats=Hh,b.audioEnvelope=f2,b.backOut=j0,b.bakeDanceTracks=oM,b.bakeEasing=Ga,b.bakeInertiaTrack=Xa,b.bakeSpringTrack=Ya,b.ballFlightPoint=y0,b.ballFlightTracks=yA,b.basicOutfit=Am,b.beanAlongLeg=zc,b.beanLimbLine=qi,b.beanOrder=_m,b.beanOverBody=zi,b.beanShoeAt=Lm,b.beanStanding=zm,b.beanTorso=Om,b.beanTorsoOutline=YS,b.beatAt=sM,b.beatAtTime=oi,b.beatLength=ri,b.beatPeriod=h2,b.beatPulse=d2,b.beatTime=Ar,b.beatsBetween=Zw,b.bed=H1,b.bike=E1,b.bindChoiceHotspots=Xd,b.bird=Mn,b.blendPose=gs,b.bodyProfileWidth=Ri,b.bodyShapeProfiles=yg,b.boilFrame=_l,b.bounceOut=q0,b.boxMesh=Sp,b.brushingPose=ym,b.bubblePath=C2,b.bubblePop=_2,b.buildScene=bx,b.bus=v1,b.cameraFromValues=V3,b.cameraPoint=Z3,b.cameraTracks=n2,b.capabilities=xb,b.capabilitiesMarkdown=HA,b.car=w1,b.cart=S1,b.caseBoard=kE,b.caseBoardMarkerTip=Xy,b.caseCardBox=la,b.caseMarkPath=Xh,b.castMember=HT,b.cat=U1,b.chair=O1,b.changingWindows=Rs,b.character=Ps,b.characterAt=l3,b.characterHandPose=Ym,b.characterJoints=ke,b.characterJointsInView=i3,b.characterLookAtTracks=G3,b.characterObjects=F3,b.characterPartsInView=Um,b.characterPoseOf=$o,b.characterPoseTracks=c3,b.characterScript=U4,b.characterScript3D=X3,b.characterStrideLength=Ny,b.characterTarget=a3,b.charactersFor=vu,b.chart=IT,b.checkBeats=ir,b.checkCast=_h,b.checkCharacterBeats3D=Wp,b.checkPropBeats=cb,b.checkPropBeats3D=Ib,b.checkSurfaceBeats=Hy,b.checkTracks=SE,b.chicken=ib,b.circlePath=nT,b.clamp01=Sl,b.clearMorphCache=ww,b.clearPathCache=rw,b.clipErased=yh,b.clockHandAngles=jy,b.closestName=ai,b.clueMarkerAt=qy,b.codePanel=fT,b.codeTokens=Xp,b.composeSimilarity=S2,b.coneCorners=zy,b.containerProgressAt=Tl,b.context=Rx,b.controlValue=Ot,b.cow=V1,b.create=M5,b.createControls=Kd,b.createCubicBezier=B0,b.createLive=Ld,b.createPen=ki,b.createRandom=Se,b.createTrack=Er,b.cricketAction=Sb,b.cricketCameraFraming=bb,b.cricketCameraReview=wa,b.cricketCameraTracks=MA,b.cricketClip=PA,b.cricketDecisionOverlay=bA,b.cricketEventAt=$A,b.cricketField=M0,b.cricketFieldingAreaContains=wb,b.cricketFieldingOverlay=TA,b.cricketFieldingPositions=kb,b.cricketPlay=Eb,b.cricketPlayClip=_A,b.cricketPlayer=vb,b.criticalDamping=Kb,b.crow=sb,b.curve=c2,b.customBounce=Cu,b.customEase=Ou,b.customWiggle=_u,b.cylinderMesh=Tp,b.danceCircleAt=np,b.danceCircleTracks=u3,b.danceFrame=to,b.danceJoint=zn,b.dancePose=Zv,b.danceStance=Qr,b.danceTaps=tM,b.danceTracks=rM,b.danceTravel=no,b.danceTravelTrack=Qf,b.dancer=iM,b.defineAction=g4,b.defineGait=m4,b.describeTarget=Jy,b.deserializeTimeline=as,b.deserializeTrack=Eu,b.desk=_1,b.detectTempo=Qw,b.dog=G1,b.door=L1,b.draggable=Hk,b.drawBeanFedora=Bm,b.drawBlinds=oE,b.drawCartoonHand=Yr,b.drawCaseBoard=vE,b.drawCharacter=Gm,b.drawCharacterHead=o3,b.drawCharacterInView=r3,b.drawClockFace=gE,b.drawClueMarker=dE,b.drawDarkness=aE,b.drawDustPuff=yy,b.drawEraser=mh,b.drawEvidenceFolder=fE,b.drawGlow=lE,b.drawHand=ph,b.drawHeldItem=Nc,b.drawImpactStars=u4,b.drawMarkerStroke=Uy,b.drawNameCard=pE,b.drawNarrationBox=bE,b.drawPencil=Bp,b.drawProp=WE,b.drawPropEffects=FA,b.drawPropShadow=th,b.drawPushPin=Gy,b.drawRain=rE,b.drawSolvedFaces=hp,b.drawSolvedPart=A3,b.drawSolvedProp=Zc,b.drawSpeechBubble=wE,b.drawSpeedLines=py,b.drawStickFigure=qf,b.drawStickSmear=h4,b.drawTimeChip=mE,b.drawTrail=Sx,b.drawVignette=cE,b.drawnPathTarget=sT,b.dripPath=O2,b.duck=ob,b.easeIn=N0,b.easeInCubic=Ra,b.easeInOut=D0,b.easeInOutCubic=ti,b.easeInOutQuad=L0,b.easeInQuad=H0,b.easeOut=W0,b.easeOutCubic=Ha,b.easeOutQuad=F0,b.editDistance=Fu,b.editError=Vi,b.editLog=_s,b.elasticOut=z0,b.ellipsePoints=wi,b.ellipsoidMesh=Ep,b.embrace=WT,b.embraceSpacing=NT,b.envelopeAt=g2,b.erasable=aT,b.expandBeats=Zo,b.expandParametricEasings=yu,b.extrudeMesh=Ap,b.fadeWindow=Dy,b.flipPose=sp,b.flipTracks=p3,b.flipTravel=ip,b.formatVersionFor=Pa,b.frameRect=m2,b.frameSize=p2,b.from=Px,b.fromJSON=Hw,b.fromTo=$x,b.gag=Ih,b.gagDuration=nr,b.gaitBob=Kl,b.gaitGive=Yl,b.gaitPose=yf,b.gaitStrideLength=Xr,b.getEasingFunction=Dt,b.getInterpolator=ii,b.getMotionPathPoint=Ua,b.getPathLength=ow,b.getPointAtProgress=U0,b.goat=J1,b.gridLinesFor=dd,b.hairFollow=ly,b.hairFollowTracks=QT,b.hairHangs=zg,b.hairMotionAt=JT,b.hairMotionOf=Ni,b.hairlineAt=Wi,b.handAt=eT,b.handGrip=To,b.handJoints=Kr,b.handJointsAt=mf,b.handPath=jh,b.handPose=Wt,b.handProp=xi,b.hasKeyframes=O0,b.hashSeed=re,b.headPoint=zv,b.heldTime=C0,b.helicopter=q1,b.helpUp=BT,b.helpUpSpacing=DT,b.holdingLayers=$m,b.horse=X1,b.horseStrideLength=rA,b.house=$1,b.humanCyclePose=WS,b.humanDanceFrame=Ci,b.humanDanceTracks=_M,b.humanFieldLabel=xM,b.humanGag=mm,b.humanGaitPose=vo,b.humanGaitStrideLength=Mo,b.humanPlan=rc,b.humanPose=vt,b.illustrationTones=Nl,b.imageSequence=Lx,b.inertiaDuration=ns,b.inertiaRest=es,b.inertiaValueAt=vr,b.inertiaVelocityAt=Ub,b.interpolateArray=fu,b.interpolateColor=du,b.interpolateMotionPath=Iw,b.interpolateNumber=Ie,b.interpolatePathString=mu,b.interpolateQuaternion=gu,b.interpolateString=ja,b.invertSimilarity=T2,b.isCubicBezierEasing=Qn,b.isHeld=Wc,b.isInertiaTrack=Ve,b.isMotionPathPoint=Db,b.isMotionPathTrack=$a,b.isParametricEasing=Vs,b.isPathData=is,b.isSpringTrack=Je,b.isTextTrack=mr,b.isUnderdamped=jb,b.isUnresolved=Ww,b.isoDepth=il,b.isometricBoxFaces=rl,b.isometricFaces=ol,b.jointsInScene=Jm,b.jointsToScene=zf,b.leafOutfit=Mm,b.leafOutfitContours=Hc,b.lightFlicker=uE,b.lightningFlash=hE,b.lineReveal=Ky,b.linear=Mr,b.lipSyncKeyframes=ah,b.lipSyncOver=Wo,b.lipSyncTracks=B3,b.lit=rh,b.live=le,b.lookFields=hh,b.loopBeats=u2,b.loopEase=i2,b.loopNoise=r2,b.loosePartsOf=n0,b.lyingPose=Y1,b.mapEase=di,b.mat4=z2,b.matchMedia=Hx,b.maxStaggerDistance=Oa,b.measuredHipWidth=wg,b.meetDandiya=h3,b.meetHands=LT,b.meetingSpacing=FT,b.metaballContours=$2,b.metaballField=Ku,b.mirrorHumanPose=eg,b.mirrorPose=Xf,b.mittenAt=Bc,b.mixColors=oh,b.mixHandPoses=fs,b.mixPoses=Xc,b.morphPath=nu,b.motorbike=A1,b.mount=Gd,b.mountAll=Vd,b.narrationMarkers=Gw,b.narrationSceneAt=Uw,b.naturalRest=Qs,b.nearestBeat=Vw,b.nextBeat=Jw,b.niceCeiling=ty,b.objectPositionAt=gh,b.organicBodyContours=Mg,b.organicCenterLine=Fi,b.outfitPreset=ay,b.owl=ab,b.pageTransition=Nx,b.panelMesh=xp,b.parametricEasing=Y0,b.parrot=lb,b.parseAnchor=jn,b.parseEdge=vl,b.parsePath=An,b.parseTrigger=Ml,b.partialPath=sn,b.pathLength=Cl,b.pedallingKeys=hx,b.pedallingPose=x0,b.penroseStairs=P2,b.penroseTriangle=x2,b.persona=X4,b.phaseOf=xn,b.pieceMotion=Ui,b.pigeon=rb,b.pingPong=el,b.planNarration=Xw,b.plantDanceFoot=tp,b.play=v5,b.playSequence=N5,b.playWhenVisible=Gk,b.playheadCrossings=Ja,b.pointAlong=Wr,b.pointAtDistance=La,b.pointOnHead=e3,b.pointsToPath=Du,b.popIn=na,b.pose=Bt,b.poseTracks=Yv,b.powSimilarity=E2,b.projectIsometric=$r,b.propActions=ya,b.propAnchors3D=f1,b.propAt=da,b.propControls=s0,b.propLineWidth=Qc,b.propObjects=QA,b.propPartsInSpace=d1,b.propPreset=l0,b.propRide=zA,b.propRide3D=ux,b.propScript=hb,b.propScript3D=ox,b.propShapeMesh=or,b.propSurface=zE,b.propTarget=m1,b.propTow=KA,b.propView=c1,b.quadruped=kn,b.quat=Ew,b.quickPlay=wx,b.quickTo=Fx,b.rabbit=Z1,b.randomBetween=Qa,b.randomChoice=Fw,b.randomNormal=Lw,b.randomSnapped=xu,b.reachCharacter=qe,b.reachOf=Wy,b.resolveActingStyle=xh,b.resolveBean=Im,b.resolveCharacterPoseKeys=Gc,b.resolveFacialHair=sm,b.resolveGait=Ti,b.resolveGlasses=rm,b.resolveHair=Kg,b.resolveHat=om,b.resolveHeadLook=lm,b.resolveHolding=xm,b.resolveIllustration=lf,b.resolveMeasurements=mc,b.resolveOrganicBody=kg,b.resolvePoseKeys=Vr,b.resolveSequence=Iu,b.resolveStickFrame=Jl,b.resolveStickPose=jf,b.resolveValue=tl,b.ribbon=Bu,b.ribbonHeadCap=zu,b.rideFloors=qo,b.rotateAbout=on,b.routineBeats=eo,b.rubberLimb=Rn,b.safeAreas=y2,b.scalePoints=H2,b.scenePreset=Fb,b.scenery=Hb,b.scriptActionSummaries=Rh,b.scriptTracks=ta,b.scrollProgress=Xk,b.scrubOnScroll=Zk,b.scrubPath=rT,b.seatHeight=Fv,b.serializeTimeline=Au,b.serializeTrack=Su,b.set=Ix,b.shade=Lo,b.shapeMesh=Ip,b.shapeToPathData=xr,b.shuffled=Nw,b.similarity=M2,b.similarityAbout=qu,b.similarityFixedPoint=ju,b.similarityMatrix=A2,b.simplifyKeyframes=bu,b.sittingPose=r0,b.skeletonInView=lo,b.sketchPen=Dr,b.skyColors=Rb,b.smoothPath=lh,b.smoothToward=wd,b.snapAxis=ud,b.snapConfig=Md,b.snapDuration=Td,b.snapProgress=Sd,b.softCartoonCharacter=RT,b.solveAt=Bs,b.solvePlanSpace=ms,b.solveProp=e0,b.songbird=nb,b.soundsOf=Mp,b.speechDuration=Ry,b.speechLength=Hp,b.spliceTracks=jA,b.splitText=_x,b.springDuration=_0,b.springFollow=li,b.springValueAt=qb,b.squashStretch=R2,b.squirrel=Q1,b.stagePlanSpace=cn,b.stageSpots=U3,b.staggerDistance=Ia,b.staggerOffset=pr,b.staggerOffsets=yr,b.staggerSpan=Js,b.stepsDuration=wy,b.stepsEasing=K0,b.stepsToKeys=Oh,b.stickFigureAt=Ql,b.stickFigureJoints=Ee,b.stickFigureTarget=Zl,b.stickToHuman=rp,b.strideLength=Mf,b.surfaceBox=St,b.surfaceScript=K4,b.sweepingPose=pm,b.syncMediaElement=zd,b.talkingMouth=Sf,b.taperedLine=bi,b.taperedOutline=qt,b.textAt=Mu,b.tf=kx,b.ticker=Cx,b.timeline=Ox,b.to=xx,b.toJSON=Rw,b.toKeyframedTrack=Pw,b.toKeyframedTracks=$w,b.torusNoise=o2,b.trackTargets=en,b.tractor=M1,b.trailSamples=w2,b.trainCar=T1,b.tree=x1,b.triggerDistance=cs,b.truck=k1,b.tubeMesh=Pp,b.unknownName=dt,b.unmount=H5,b.valueAt=zo,b.vec3=F2,b.vehicle=Xe,b.walkPose=vf,b.wheelchair=D1,b.whiteboard=bT,b.withAlpha=xe,b.withErased=oT,b.withExpression=an,b.wobble=s2,b.wrapText=sa,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|