@algorisys/tinyfly 0.107.1 → 0.108.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 +17 -12
- package/docs/character-appearance.md +148 -0
- 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 +35 -0
- package/docs/maps.md +2 -2
- package/docs/teaching.md +1 -1
- package/lib/addons/characters.js +5469 -4932
- package/lib/browser/tinyfly.iife.js +14 -14
- package/lib/browser/tinyfly.js +6742 -6205
- package/lib/browser/tinyfly.umd.js +14 -14
- package/lib/types/characters/body/organic-body.d.ts +56 -0
- package/lib/types/characters/body/organic-draw.d.ts +5 -0
- package/lib/types/characters/body/organic-geometry.d.ts +25 -0
- package/lib/types/characters/capabilities.d.ts +2 -0
- package/lib/types/characters/character.d.ts +15 -2
- package/lib/types/characters/hands/draw-cartoon-hand.d.ts +4 -0
- package/lib/types/characters/head/face.d.ts +6 -4
- package/lib/types/characters/head/facial-hair.d.ts +2 -0
- package/lib/types/characters/head/glasses.d.ts +2 -0
- package/lib/types/characters/head/head-look.d.ts +4 -2
- package/lib/types/characters/head/head-shape.d.ts +4 -0
- package/lib/types/characters/index.d.ts +5 -0
- package/lib/types/characters/look/pen.d.ts +1 -0
- package/lib/types/characters/look/skin-shading.d.ts +4 -0
- package/lib/types/characters/rig/skeleton.d.ts +2 -0
- package/lib/types/characters/soft-cartoon-cast.d.ts +166 -0
- package/lib/types/characters/wardrobe/basic-outfit.d.ts +5 -1
- package/lib/types/characters/wardrobe/leaf-outfit.d.ts +18 -0
- package/lib/types/characters/wardrobe/outfit-preset.d.ts +6 -0
- package/llms-full.txt +199 -9
- package/llms.txt +29 -29
- package/package.json +1 -1
- package/skills/tinyfly/SKILL.md +30 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
(function(y){"use strict";function kc(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function ls(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const er=2;function nr(t){return t.some(e=>e.interpolation!==void 0)?2:1}function li(t){return t.property==="text"&&"textConfig"in t}function Ee(t){return t.kind==="inertia"&&"inertia"in t}function Ae(t){return t.kind==="spring"&&"spring"in t}function sr(t){return t.property==="motionPath"&&"motionPathConfig"in t}function cm(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"angle"in t}function vc(t){return"keyframes"in t}class hm{_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 um{_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 Mc(t,e){if(!(e>0))return t;const n=1e3/e;return Math.floor(t/n+1e-9)*n}function ir(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 or(t,e="start"){if(t<=1)return 0;let n=0;for(let s=0;s<t;s++)n=Math.max(n,ir(s,t,e));return n}function ci(t,e,n){if(n.offsets)return n.offsets[t]??0;const s=n.from??"start",i=ir(t,e,s);if(n.amount!==void 0){const o=or(e,s);return o===0?0:n.amount*i/o}return n.each!==void 0?n.each*i:0}function hi(t,e){return Array.from({length:t},(n,s)=>ci(s,t,e))}function cs(t,e){return t<=1?0:Math.max(...hi(t,e))}const kn=1,rr=6e4,ui=rr/kn,Zt={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1},di={gentle:{stiffness:120,damping:18,mass:1},default:{stiffness:180,damping:12,mass:1},snappy:{stiffness:280,damping:20,mass:1},bouncy:{stiffness:220,damping:8,mass:1},wobbly:{stiffness:180,damping:5,mass:1},stiff:{stiffness:400,damping:30,mass:1}};class hs{from;to;stiffness;damping;mass;restDelta;restSpeed;distance;samples;velocity;settledStep=null;constructor(e){this.from=e.from,this.to=e.to,this.stiffness=e.stiffness??Zt.stiffness,this.damping=e.damping??Zt.damping,this.mass=e.mass??Zt.mass,this.restDelta=e.restDelta??Zt.restDelta,this.restSpeed=e.restSpeed??Zt.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=e.velocity??Zt.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/kn);if(this.simulateTo(n+1),this.settledStep!==null&&n>=this.settledStep)return this.to;const s=this.samples[Math.min(n,this.samples.length-1)],i=this.samples[Math.min(n+1,this.samples.length-1)],o=e/kn-n;return s+(i-s)*o}settleTime(){return this.simulateTo(ui+1),this.settledStep!==null?this.settledStep*kn:rr}simulateTo(e){if(this.settledStep!==null)return;const n=Math.min(e,ui+1),s=kn/1e3;for(;this.samples.length<n;){const i=this.samples[this.samples.length-1],o=i-this.to,r=-this.stiffness*o,a=-this.damping*this.velocity,l=(r+a)/this.mass;this.velocity+=l*s;const c=i+this.velocity*s;if(this.samples.push(c),this.isAtRest(c)){this.settledStep=this.samples.length-1;return}}this.samples.length>ui&&(this.settledStep=ui)}}function dm(t,e){return new hs(t).valueAt(e)}function Sc(t){return new hs(t).settleTime()}function fm(t){const e=t.stiffness??Zt.stiffness,n=t.damping??Zt.damping,s=t.mass??Zt.mass;return n<2*Math.sqrt(e*s)}function gm(t){const e=t.stiffness??Zt.stiffness,n=t.mass??Zt.mass;return 2*Math.sqrt(e*n)}const ar=4,pm=.002,mm=1e-4,Tc=6e4;function fi(t){const e=t.friction??ar;return e>0?e:ar}function us(t){return t.from+t.velocity/fi(t)}function ym(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 vn(t){let e=ym(us(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 Mn(t){const e=Math.abs(vn(t)-t.from);if(e===0)return 0;const n=t.restDelta??Math.max(mm,e*pm);if(n>=e)return 0;const s=Math.log(e/n)/fi(t);return Math.min(Tc,s*1e3)}function gi(t,e){if(e<=0)return t.from;const n=vn(t);if(e>=Mn(t))return n;const s=fi(t);return t.from+(n-t.from)*(1-Math.exp(-s*e/1e3))}function bm(t,e){const n=fi(t),s=vn(t);return e>=Mn(t)?0:(s-t.from)*n*Math.exp(-n*Math.max(0,e)/1e3)}const pi=t=>t,xc=t=>t*t,Ec=t=>1-(1-t)*(1-t),Ac=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,lr=t=>t*t*t,cr=t=>1-Math.pow(1-t,3),ds=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,Pc=lr,$c=cr,Ic=ds,wm={linear:pi,"ease-in":Pc,"ease-out":$c,"ease-in-out":Ic,"ease-in-quad":xc,"ease-out-quad":Ec,"ease-in-out-quad":Ac,"ease-in-cubic":lr,"ease-out-cubic":cr,"ease-in-out-cubic":ds};function Oc(t){const[e,n,s,i]=t,o=3*e,r=3*(s-e)-o,a=1-o-r,l=3*n,c=3*(i-n)-l,h=1-l-c,u=g=>((a*g+r)*g+o)*g,d=g=>((h*g+c)*g+l)*g,f=g=>(3*a*g+2*r)*g+o,p=g=>{let m=g;for(let k=0;k<8;k++){const b=u(m)-g;if(Math.abs(b)<1e-7)return m;const E=f(m);if(Math.abs(E)<1e-7)break;m-=b/E}let w=0,v=1;for(m=g;w<v;){const k=u(m);if(Math.abs(k-g)<1e-7)return m;g>k?w=m:v=m,m=(w+v)/2}return m};return g=>{if(g<=0)return 0;if(g>=1)return 1;const m=p(g);return d(m)}}function hr(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 _c(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 Cc=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 Hc(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 Rc(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 Lc(t){switch(t.type){case"steps":return Rc(t.count,t.position);case"elastic":return hr(_c(t.amplitude,t.period),t.mode);case"bounce":return hr(Cc,t.mode);case"back":return hr(Hc(t.overshoot),t.mode)}}function Lt(t){return t===void 0?pi:kc(t)?Oc(t.points):ls(t)?Lc(t):wm[t]??pi}const Nc=32,km=256,Sn=new Map,vm=/[MmLlHhVvCcSsQqTtAaZz]/,Mm=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,Sm={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function Tm(t){const e=[];let n=0,s=null;const i=()=>{for(;n<t.length&&/[\s,]/.test(t[n]);)n++};for(;n<t.length&&(i(),!(n>=t.length));){const o=t[n];if(vm.test(o)){s={type:o,args:[]},e.push(s),n++;continue}if(!s)break;const r=s.type==="A"||s.type==="a",a=s.args.length%7;if(r&&(a===3||a===4)){if(o!=="0"&&o!=="1")break;s.args.push(o==="1"?1:0),n++;continue}const l=Mm.exec(t.slice(n));if(!l)break;s.args.push(parseFloat(l[0])),n+=l[0].length}return e}function xm(t,e,n,s,i,o,r,a,l){if(t===a&&e===l)return[];let c=Math.abs(n),h=Math.abs(s);if(c===0||h===0)return[[t,e,a,l,a,l]];const u=i*Math.PI/180,d=Math.cos(u),f=Math.sin(u),p=(t-a)/2,g=(e-l)/2,m=d*p+f*g,w=-f*p+d*g,v=m*m/(c*c)+w*w/(h*h);if(v>1){const L=Math.sqrt(v);c*=L,h*=L}const k=o===r?-1:1,b=c*c*h*h-c*c*w*w-h*h*m*m,E=c*c*w*w+h*h*m*m,$=k*Math.sqrt(Math.max(0,b/E)),S=$*c*w/h,x=-$*h*m/c,M=d*S-f*x+(t+a)/2,T=f*S+d*x+(e+l)/2,I=(L,z,O,P)=>{const H=L*O+z*P,W=Math.sqrt((L*L+z*z)*(O*O+P*P)),q=Math.acos(Math.max(-1,Math.min(1,H/W)));return L*P-z*O<0?-q:q},A=I(1,0,(m-S)/c,(w-x)/h);let _=I((m-S)/c,(w-x)/h,(-m-S)/c,(-w-x)/h);!r&&_>0&&(_-=2*Math.PI),r&&_<0&&(_+=2*Math.PI);const C=Math.max(1,Math.ceil(Math.abs(_)/(Math.PI/2))),N=_/C,B=4/3*Math.tan(N/4),G=L=>{const z=c*Math.cos(L),O=h*Math.sin(L);return[d*z-f*O+M,f*z+d*O+T]},Z=L=>{const z=-c*Math.sin(L),O=h*Math.cos(L);return[d*z-f*O,f*z+d*O]},Y=[];for(let L=0;L<C;L++){const z=A+L*N,O=z+N,[P,H]=G(z),[W,q]=L===C-1?[a,l]:G(O),[D,K]=Z(z),[V,F]=Z(O);Y.push([P+B*D,H+B*K,W-B*V,q-B*F,W,q])}return Y}function Pe(t,e,n,s,i){const o=1-i;return o*o*o*t+3*o*o*i*e+3*o*i*i*n+i*i*i*s}function Fc(t,e,n,s,i){const o=1-i;return 3*o*o*(e-t)+6*o*i*(n-e)+3*i*i*(s-n)}function fs(t,e,n,s){return{subpath:0,type:"L",points:[n,s],startX:t,startY:e,endX:n,endY:s,length:Math.hypot(n-t,s-e)}}function mi(t,e,n){const[s,i,o,r,a,l]=n,c=[0];let h=t,u=e,d=0;for(let f=1;f<=Nc;f++){const p=f/Nc,g=Pe(t,s,o,a,p),m=Pe(e,i,r,l,p);d+=Math.hypot(g-h,m-u),c.push(d),h=g,u=m}return{subpath:0,type:"C",points:[s,i,o,r,a,l],startX:t,startY:e,endX:a,endY:l,length:d,lengths:c}}function Ve(t){const e=Sn.get(t);if(e)return e;const n=[];let s=0,i=0,o=0,r=0,a=null,l=null,c=-1;const h=new Set,u=g=>{c<0&&(c=0),g.subpath=c,n.push(g)};for(const{type:g,args:m}of Tm(t)){const w=g.toUpperCase(),v=g!==w,k=Sm[w];if(w==="Z"){(s!==o||i!==r)&&u(fs(s,i,o,r)),c>=0&&h.add(c),s=o,i=r,a=l=null;continue}for(let b=0;b+k<=m.length;b+=k){const E=m.slice(b,b+k),$=v?s:0,S=v?i:0;let x=null,M=null;switch(w){case"M":b===0?(s=E[0]+$,i=E[1]+S,o=s,r=i,(c<0||n[n.length-1]?.subpath===c)&&c++):(u(fs(s,i,E[0]+$,E[1]+S)),s=E[0]+$,i=E[1]+S);break;case"L":u(fs(s,i,E[0]+$,E[1]+S)),s=E[0]+$,i=E[1]+S;break;case"H":u(fs(s,i,E[0]+$,i)),s=E[0]+$;break;case"V":u(fs(s,i,s,E[0]+S)),i=E[0]+S;break;case"C":{const T=[E[0]+$,E[1]+S,E[2]+$,E[3]+S,E[4]+$,E[5]+S];u(mi(s,i,T)),x=[T[2],T[3]],s=T[4],i=T[5];break}case"S":{const[T,I]=a?[2*s-a[0],2*i-a[1]]:[s,i],A=[T,I,E[0]+$,E[1]+S,E[2]+$,E[3]+S];u(mi(s,i,A)),x=[A[2],A[3]],s=A[4],i=A[5];break}case"Q":case"T":{let T=s,I=i;w==="Q"?(T=E[0]+$,I=E[1]+S):l&&(T=2*s-l[0],I=2*i-l[1]);const A=w==="Q"?E[2]+$:E[0]+$,_=w==="Q"?E[3]+S:E[1]+S;u(mi(s,i,[s+2/3*(T-s),i+2/3*(I-i),A+2/3*(T-A),_+2/3*(I-_),A,_])),M=[T,I],s=A,i=_;break}case"A":{const T=E[5]+$,I=E[6]+S;let A=s,_=i;for(const C of xm(s,i,E[0],E[1],E[2],E[3],E[4],T,I))u(mi(A,_,C)),A=C[4],_=C[5];s=T,i=I;break}}a=x,l=M}}const d=n.reduce((g,m)=>g+m.length,0),f=[];for(let g=0;g<n.length;){const m=n[g].subpath;let w=g,v=0;for(;w<n.length&&n[w].subpath===m;)v+=n[w++].length;const k=n[g],b=n[w-1],E=h.has(m)||Math.abs(b.endX-k.startX)<1e-9&&Math.abs(b.endY-k.startY)<1e-9;f.push({start:g,end:w,length:v,closed:E}),g=w}const p={segments:n,totalLength:d,subpaths:f};return Sn.size>=km&&Sn.delete(Sn.keys().next().value),Sn.set(t,p),p}function Em(t,e){const n=t.lengths;if(e<=0)return 0;if(e>=t.length)return 1;let s=0,i=n.length-1;for(;s<i-1;){const a=s+i>>1;n[a]<e?s=a:i=a}const o=n[i]-n[s],r=o>0?(e-n[s])/o:0;return(s+r)/(n.length-1)}function Am(t,e){if(t.type==="L"){const u=t.length>0?Math.max(0,Math.min(1,e/t.length)):0;return{x:t.startX+(t.endX-t.startX)*u,y:t.startY+(t.endY-t.startY)*u,angle:Math.atan2(t.endY-t.startY,t.endX-t.startX)*180/Math.PI}}const[n,s,i,o,r,a]=t.points,l=Em(t,e);let c=Fc(t.startX,n,i,r,l),h=Fc(t.startY,s,o,a,l);if(Math.hypot(c,h)<1e-9){const u=l<.5?Math.min(1,l+.001):Math.max(0,l-.001),d=Pe(t.startX,n,i,r,u),f=Pe(t.startY,s,o,a,u),p=Pe(t.startX,n,i,r,l),g=Pe(t.startY,s,o,a,l);c=l<.5?d-p:p-d,h=l<.5?f-g:g-f}return{x:Pe(t.startX,n,i,r,l),y:Pe(t.startY,s,o,a,l),angle:Math.atan2(h,c)*180/Math.PI}}function ur(t,e,n=0,s=t.length){if(s<=n)return{x:0,y:0,angle:0};let i=0;for(let o=n;o<s;o++){const r=t[o];if(i+r.length>=e||o===s-1)return Am(r,e-i);i+=r.length}return{x:0,y:0,angle:0}}function Dc(t,e){const{segments:n,totalLength:s}=Ve(t);return ur(n,Math.max(0,Math.min(1,e))*s)}function Pm(){Sn.clear()}function $m(t){return Ve(t).totalLength}const Im=24,Om=320,_m=2.5,gs=72,Cm=64,Hm=.2,Rm=128,ps=new Map;let yi=0,$e;const Wc=t=>Math.round(t*100)/100;function Bc(t,e){const{segments:n,subpaths:s,totalLength:i}=Ve(t);if(n.length===0)return[];if(e){const o=s.every(r=>r.closed);return[{segments:n,start:0,end:n.length,length:i,closed:o}]}return s.filter(o=>o.length>0).map(o=>({segments:n,start:o.start,end:o.end,length:o.length,closed:o.closed}))}function dr(t,e){const n=t.closed?(e%1+1)%1:Math.max(0,Math.min(1,e)),s=ur(t.segments,n*t.length,t.start,t.end);return[s.x,s.y]}function zc(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 qc(t,e){const n=[];for(let s=0;s<e;s++)n.push(dr(t,t.closed?s/e:s/(e-1)));return n}function Yc(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 Lm(t,e,n){const s=t.closed&&e.closed;if(n!==void 0)return{offset:s?Math.abs(n)%gs/gs:0,reversed:n<0};const i=Yc(qc(t,gs)),o=Yc(qc(e,gs)),r=gs;let a={offset:0,reversed:!1},l=1/0;for(const c of[!1,!0]){const h=s?r:1;for(let u=0;u<h;u++){let d=0;for(let f=0;f<r&&d<l;f++){const p=s?c?(u-f+r)%r:(f+u)%r:c?r-1-f:f,g=i[f][0]-o[p][0],m=i[f][1]-o[p][1];d+=g*g+m*m}d<l&&(l=d,a={offset:s?u/r:0,reversed:c})}}return a}function Nm(t,e,n){return n?((e.reversed?e.offset-t:t+e.offset)%1+1)%1:e.reversed?1-t:t}function Fm(t,e,n){return n?((e.reversed?e.offset-t:t-e.offset)%1+1)%1:e.reversed?1-t:t}function Dm(t,e,n){const s=t.closed&&e.closed,i=Lm(t,e,n.shapeIndex),o=Math.max(Im,Math.min(Om,Math.ceil(Math.max(t.length,e.length)/_m))),r=new Set,a=u=>r.add(Math.round(u*1e7)/1e7);for(let u=0;u<=o;u++)a(u/o);for(const u of zc(t))a(u);for(const u of zc(e))a(Fm(u,i,s));let l=[...r].sort((u,d)=>u-d);s&&(l=l.filter(u=>u<1));const c=[],h=[];for(const u of l)c.push(...dr(t,u)),h.push(...dr(e,Nm(u,i,s)));return Wm({from:c,to:h,closed:s})}function Wm(t){const e=t.from.length/2;if(e<=3)return t;const n=new Uint8Array(e);n[0]=1,n[e-1]=1;const s=[[0,e-1]];for(;s.length>0;){const[r,a]=s.pop();let l=-1,c=Hm;for(let h=r+1;h<a;h++){const u=Math.max(jc(t.from,r,a,h),jc(t.to,r,a,h));u>c&&(c=u,l=h)}l!==-1&&(n[l]=1,s.push([r,l],[l,a]))}const i=[],o=[];for(let r=0;r<e;r++)n[r]&&(i.push(t.from[r*2],t.from[r*2+1]),o.push(t.to[r*2],t.to[r*2+1]));return{from:i,to:o,closed:t.closed}}function jc(t,e,n,s){const i=t[e*2],o=t[e*2+1],r=t[n*2]-i,a=t[n*2+1]-o,l=t[s*2]-i,c=t[s*2+1]-o,h=r*r+a*a,u=h===0?0:Math.max(0,Math.min(1,(l*r+c*a)/h));return Math.hypot(l-u*r,c-u*a)}function Bm(t,e,n){const s=n.shapeIndex;if($e&&$e.from===t&&$e.to===e&&$e.shapeIndex===s)return $e.plan;const o=ps.get(String(s??"auto"))?.get(t)?.get(e);if(o)return $e={from:t,to:e,shapeIndex:s,plan:o},o;const r=Ve(t).subpaths.filter(f=>f.length>0).length===Ve(e).subpaths.filter(f=>f.length>0).length,a=Bc(t,!r),l=Bc(e,!r),c={pairs:a.map((f,p)=>Dm(f,l[p],n))};yi>=Rm&&(ps.clear(),yi=0);const h=String(s??"auto"),u=ps.get(h)??new Map;ps.set(h,u);const d=u.get(t)??new Map;return u.set(t,d),d.set(e,c),yi++,$e={from:t,to:e,shapeIndex:s,plan:c},c}function Kc(t,e,n,s={}){if(!t)return e;if(!e)return t;const i=Math.max(0,Math.min(1,n));if(i===0)return t;if(i===1)return e;const o=Bm(t,e,s);if(o.pairs.length===0)return i<.5?t:e;let r="";for(const a of o.pairs){for(let l=0;l<a.from.length;l+=2){const c=Wc(a.from[l]+(a.to[l]-a.from[l])*i),h=Wc(a.from[l+1]+(a.to[l+1]-a.from[l+1])*i);r+=`${l===0?r?" M":"M":" L"}${c} ${h}`}a.closed&&(r+=" Z")}return r}function zm(){ps.clear(),yi=0,$e=void 0}function Tn(t){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(t)}const xn=Math.PI/180,qm=.9995;function fr(){return[0,0,0,1]}function Qt(t,e){const n=Math.hypot(t[0],t[1],t[2]);if(n===0)return fr();const s=e*xn/2,i=Math.sin(s)/n;return[t[0]*i,t[1]*i,t[2]*i,Math.cos(s)]}function Ym(t,e,n){return gr(gr(Qt([0,1,0],e),Qt([1,0,0],t)),Qt([0,0,1],n))}function jm(t){const[e,n,s,i]=Ie(t),o=2*(e*s+n*i),r=2*(e*n+s*i),a=1-2*(e*e+s*s),l=2*(n*s-e*i),c=1-2*(n*n+s*s),h=2*(e*s-n*i),u=1-2*(e*e+n*n),d=Math.asin(Math.max(-1,Math.min(1,-l)));return Math.abs(l)<.9999999?[d/xn,Math.atan2(o,u)/xn,Math.atan2(r,a)/xn]:[d/xn,Math.atan2(-h,c)/xn,0]}function gr(t,e){const[n,s,i,o]=t,[r,a,l,c]=e;return[o*r+n*c+s*l-i*a,o*a-n*l+s*c+i*r,o*l+n*a-s*r+i*c,o*c-n*r-s*a-i*l]}function Xc(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function Gc(t){return Math.hypot(t[0],t[1],t[2],t[3])}function Ie(t){const e=Gc(t);return e===0?fr():[t[0]/e,t[1]/e,t[2]/e,t[3]/e]}function Km(t){return[-t[0],-t[1],-t[2],t[3]]}function Uc(t,e,n){const s=Ie(t);let i=Ie(e),o=Xc(s,i);if(o<0&&(i=[-i[0],-i[1],-i[2],-i[3]],o=-o),o>qm)return Ie([s[0]+(i[0]-s[0])*n,s[1]+(i[1]-s[1])*n,s[2]+(i[2]-s[2])*n,s[3]+(i[3]-s[3])*n]);const r=Math.acos(o),a=Math.sin(r),l=Math.sin((1-n)*r)/a,c=Math.sin(n*r)/a;return Ie([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 Xm(t,e){const[n,s,i,o]=Ie(t),r=2*(s*e[2]-i*e[1]),a=2*(i*e[0]-n*e[2]),l=2*(n*e[1]-s*e[0]);return[e[0]+o*r+(s*l-i*a),e[1]+o*a+(i*r-n*l),e[2]+o*l+(n*a-s*r)]}const Gm=Object.freeze(Object.defineProperty({__proto__:null,conjugate:Km,dot:Xc,fromAxisAngle:Qt,fromEuler:Ym,identity:fr,length:Gc,multiply:gr,normalize:Ie,rotateVec3:Xm,slerp:Uc,toEuler:jm},Symbol.toStringTag,{value:"Module"})),ue=(t,e,n)=>t+(e-t)*n,Vc=512,pr=new Map,mr=new Map;function Jc(t){const e=pr.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 pr.size<Vc&&pr.set(t,s),s}const Zc=t=>t.charCodeAt(0)===35,Qc=t=>t.startsWith("rgb"),th=t=>t.startsWith("rgba"),Um=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,yr=t=>Math.round(t).toString(16).padStart(2,"0");function Vm(t,e,n){return`#${yr(t)}${yr(e)}${yr(n)}`}function eh(t){const e=mr.get(t);if(e)return e;const n=t.match(Um);if(!n)throw new Error(`Invalid rgb color: ${t}`);const s=parseInt(n[1],10),i=parseInt(n[2],10),o=parseInt(n[3],10),r=n[4]!==void 0?[s,i,o,parseFloat(n[4])]:[s,i,o];return mr.size<Vc&&mr.set(t,r),r}const nh=(t,e,n)=>{if(Zc(t)&&Zc(e)){const[s,i,o]=Jc(t),[r,a,l]=Jc(e),c=ue(s,r,n),h=ue(i,a,n),u=ue(o,l,n);return Vm(c,h,u)}if((Qc(t)||th(t))&&(Qc(e)||th(e))){const s=eh(t),i=eh(e),o=Math.round(ue(s[0],i[0],n)),r=Math.round(ue(s[1],i[1],n)),a=Math.round(ue(s[2],i[2],n));if(s.length===4||i.length===4){const l=s[3]??1,c=i[3]??1,h=ue(l,c,n);return`rgba(${o}, ${r}, ${a}, ${h})`}return`rgb(${o}, ${r}, ${a})`}return n<1?t:e},sh=(t,e,n)=>{const s=Math.min(t.length,e.length),i=[];for(let o=0;o<s;o++)i.push(ue(t[o],e[o],n));return i},ih=(t,e,n)=>Uc(t,e,n),br=(t,e,n)=>n<1?t:e,oh=(t,e,n)=>Kc(t,e,n);function ms(t,e){return e==="slerp"?ih:typeof t=="number"?ue:Array.isArray(t)?sh:typeof t=="string"?t.startsWith("#")||t.startsWith("rgb")?nh:Tn(t)?oh:br:br}const wr=1e3/60;function kr(t,e={}){if(!Ae(t))throw new Error(`bakeSpringTrack: track "${t.id}" is not a spring track`);const n=new hs(t.spring);return rh(t,s=>n.valueAt(s),n.settleTime(),t.spring.from,t.spring.to,e)}function vr(t,e={}){if(!Ee(t))throw new Error(`bakeInertiaTrack: track "${t.id}" is not an inertia track`);const n=t.inertia;return rh(t,s=>gi(n,s),Mn(n),n.from,vn(n),e)}function rh(t,e,n,s,i,o){const r=o.intervalMs??wr,a=o.tolerance??.01,l=t.delay??0,c=[];for(let u=0;u<=n;u+=r)c.push({time:u+l,value:e(u),easing:"linear"});const h=c[c.length-1];return!h||h.time<n+l?c.push({time:n+l,value:i,easing:"linear"}):h.value=i,l>0&&c.unshift({time:0,value:s,easing:"linear"}),{id:t.id,target:t.target,property:t.property,keyframes:a>0?lh(c,a):c,...t.targets&&{targets:[...t.targets]},...t.stagger&&{stagger:{...t.stagger}}}}function Mr(t,e,n,s={}){const i=s.intervalMs??wr,o=typeof n=="function"?n:Lt(n),r=ms(t.value,s.interpolation),a=e.time-t.time;if(a<=0)return[e];const l=[];for(let h=i;h<a;h+=i){const u=h/a;l.push({time:t.time+h,value:r(t.value,e.value,o(u)),easing:"linear"})}const c=o(1);return l.push({...e,...c!==1&&{value:r(t.value,e.value,c)},easing:"linear"}),l}function Jm(t,e){return Ae(t)?kr(t,e):Ee(t)?vr(t,e):t}function ah(t,e={}){const n=t.keyframes;if(!n.some(o=>ls(o.easing)))return t;const s=n.length>0?[n[0]]:[],i={...e,interpolation:t.interpolation??e.interpolation};for(let o=1;o<n.length;o++){const r=n[o];ls(r.easing)?s.push(...Mr(n[o-1],r,r.easing,i)):s.push(r)}return{...t,keyframes:s}}function Zm(t,e){return t.filter(vc).map(n=>ah(n,e)).concat(t.filter(Ae).map(n=>kr(n,e)),t.filter(Ee).map(n=>vr(n,e)))}function lh(t,e){if(t.length<=2)return t;const n=[t[0]];for(let s=1;s<t.length-1;s++){const i=n[n.length-1],o=t[s],r=t[s+1],a=r.time-i.time;if(a<=0)continue;const l=(o.time-i.time)/a,c=i.value+(r.value-i.value)*l;Math.abs(o.value-c)>e&&n.push(o)}return n.push(t[t.length-1]),n}function bi(t){const e=[...t.keyframes].sort((n,s)=>n.time-s.time);return{...t,keyframes:e}}function Oe(t){return t.targets&&t.targets.length>0?t.targets:[t.target]}function En(t,e,n,s){const i=n??0;return!s||e<=1?i:i+ci(t,e,s)}class ys{track;targets;constructor(e){this.track=e,this.targets=Oe(e)}getValueAtTime(e){return this.valueForOffset(e-En(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const o=En(i,n,this.track.delay,this.track.stagger),r=this.valueForOffset(e-o);r!==void 0&&s.push({target:this.targets[i],value:r,start:o+this.track.keyframes[0].time})}return s}getDuration(){const{keyframes:e}=this.track;if(e.length===0)return 0;const n=e[e.length-1].time,s=this.track.stagger?cs(this.targets.length,this.track.stagger):0;return n+(this.track.delay??0)+s+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(e){const{keyframes:n}=this.track;if(n.length===0)return;if(n.length===1||e<=n[0].time)return n[0].value;if(e>=n[n.length-1].time)return n[n.length-1].value;const{from:s,to:i}=this.findSurroundingKeyframes(e);if(!s||!i)return;if(s.time===e)return s.value;const o=i.time-s.time,r=(e-s.time)/o,l=Lt(i.easing)(r);return ms(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 ch{track;targets;sampler;constructor(e){this.track=e,this.targets=Oe(e),this.sampler=new hs(e.spring)}getValueAtTime(e){return this.sampler.valueAt(e-En(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const o=En(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:this.sampler.valueAt(e-o),start:o})}return s}getDuration(){const e=this.track.stagger?cs(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+e}getTrack(){return this.track}}class hh{track;targets;duration;constructor(e){this.track=e,this.targets=Oe(e),this.duration=Mn(e.inertia)}getValueAtTime(e){return gi(this.track.inertia,e-En(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const o=En(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:gi(this.track.inertia,e-o),start:o})}return s}getDuration(){const e=this.track.stagger?cs(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+e}getTrack(){return this.track}}function Sr(t,e){const n={...Dc(t.pathData,e)};if(t.matrix){const[s,i,o,r,a,l]=t.matrix,{x:c,y:h}=n;n.x=s*c+o*h+a,n.y=i*c+r*h+l;const u=n.angle*Math.PI/180,d=Math.cos(u),f=Math.sin(u);n.angle=Math.atan2(i*d+r*f,s*d+o*f)*180/Math.PI}return t.autoRotate&&t.rotateOffset&&(n.angle+=t.rotateOffset),n}function Qm(t,e,n,s){const i=e+(n-e)*s;return Sr(t,i)}const Tr={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},t1=20;function uh(t){const e=Tr[t??"upperCase"]??t??Tr.upperCase,n=Array.from(e);return n.length>0?n:Array.from(Tr.upperCase)}function e1(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 dh(t,e,n=0){const s=t.from??"",i=t.to,o=Math.max(0,Math.min(1,e));if(o<=0)return s;if(o>=1)return i;const r=Array.from(s),a=Array.from(i),l=t.rightToLeft??!1;if(t.mode==="type"){const v=Math.round(o*Math.max(r.length,a.length));return l?r.slice(0,Math.max(0,r.length-v)).join("")+a.slice(Math.max(0,a.length-v)).join(""):a.slice(0,v).join("")+r.slice(v).join("")}const c=Math.max(0,Math.min(.999,t.revealDelay??0)),h=Math.max(0,(o-c)/(1-c)),u=Math.floor(h*a.length),d=t.tweenLength===!1?a.length:Math.round(r.length+(a.length-r.length)*o),f=uh(t.chars),p=t.refreshRate??t1,g=p>0?Math.floor(n*p/1e3):0,m=t.seed??1;let w="";for(let v=0;v<d;v++){const k=l?v>=d-u:v<u,b=l?a[a.length-(d-v)]:a[v];k&&b!==void 0||b===" "||b===`
|
|
2
|
-
`?w+=b:w+=f[e1(m,v,g)%f.length]}return w}class It{id;name;_captions;_tracks=[];_trackPlayers=new Map;_motionPathTracks=new Map;_springTracks=new Map;_textTracks=new Map;_config;_currentTime=0;_playbackState="idle";_direction="forward";_loopIteration=0;_explicitDuration;_repeatDelayRemaining=0;_wrapAfterDelay=!1;onUpdate=null;onComplete=null;constructor(e){if(this.id=e.id,this.name=e.name,this._captions=e.captions,this._config=e.config??{},this._explicitDuration=e.config?.duration,e.tracks)for(const n of e.tracks)this.addTrack(n)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(e){if(this._explicitDuration=e,e!==void 0)this._config={...this._config,duration:e};else if(this._config.duration!==void 0){const n={...this._config};delete n.duration,this._config=n}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(e){this._config.speed=e}get drawingRate(){return this._config.drawingRate??0}set drawingRate(e){const n={...this._config};e>0?n.drawingRate=e:delete n.drawingRate,this._config=n}play(){const e=this.duration;this._direction==="forward"&&this._currentTime>=e&&e>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&e>0&&(this._currentTime=e,this._loopIteration=0),this._playbackState="playing"}pause(){this._playbackState="paused"}stop(){this._playbackState="idle",this._repeatDelayRemaining=0,this._wrapAfterDelay=!1,this._currentTime=0,this._loopIteration=0,this._direction="forward"}seek(e){const n=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(e,n)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(e){if(this._playbackState!=="playing")return;const n=this.duration;if(n<=0)return;let i=e*this.speed;if(this._repeatDelayRemaining>0){const a=Math.min(this._repeatDelayRemaining,i);if(this._repeatDelayRemaining-=a,i-=a,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const o=1e3;for(let a=0;a<o&&i>0&&this._playbackState==="playing";a++)if(this._direction==="forward"){const l=n-this._currentTime;if(i>=l){if(i-=l,this._currentTime=n,!this._handleEndReached())break}else this._currentTime+=i,i=0}else{const l=this._currentTime;if(i>=l){if(i-=l,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=i,i=0}const r=this.getStateAtTime(this._currentTime);this.onUpdate?.(r)}getStateAtTime(e){const n=new Map;if(e=Mc(e,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(e,n);else for(const[s,i]of this._trackPlayers){const o=i.getTrack().property;for(const{target:r,value:a,start:l}of i.getTargetValues(e))this._write(n,s,r,o,a,e-l)}return{values:n,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(e,n){const s=new Map;for(const[i,o]of this._trackPlayers){const r=o.getTrack().property;for(const{target:a,value:l,start:c}of o.getTargetValues(e)){const h=`${a}\0${r}`,u=c<=e,d=s.get(h);(!d||(u!==d.started?u:u?c>=d.start:c<=d.start))&&s.set(h,{trackId:i,target:a,property:r,value:l,start:c,started:u})}}for(const{trackId:i,target:o,property:r,value:a,start:l}of s.values())this._write(n,i,o,r,a,e-l)}_write(e,n,s,i,o,r){if(o===void 0)return;let a=e.get(s);a||(a=new Map,e.set(s,a));const l=this._textTracks.get(n);if(l&&typeof o=="number"){a.set("text",dh(l.textConfig,o,Math.max(0,r)));return}const c=this._motionPathTracks.get(n);if(c&&typeof o=="number"){const h=Sr(c.motionPathConfig,o);a.set("motionPathX",h.x),a.set("motionPathY",h.y),c.motionPathConfig.autoRotate&&a.set("motionPathRotate",h.angle)}else a.set(i,o)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const e=new Set;this._sharedWrites=!1;t:for(const n of this._tracks)for(const s of Oe(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,Ee(e)){this._trackPlayers.set(e.id,new hh(e));return}if(Ae(e)){this._trackPlayers.set(e.id,new ch(e)),this._springTracks.set(e.id,e);return}if(li(e))this._trackPlayers.set(e.id,new ys(e)),this._textTracks.set(e.id,e);else if(sr(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 ys(n)),this._motionPathTracks.set(e.id,e)}else this._trackPlayers.set(e.id,new ys(e))}replaceTrack(e,n){const s=this._tracks.findIndex(o=>o.id===e);if(s<0)return;const i=this._tracks.slice(s+1);this.removeTrack(e);for(const o of i)this.removeTrack(o.id);this.addTrack(n);for(const o of i)this.addTrack(o)}removeTrack(e){this._tracks=this._tracks.filter(n=>n.id!==e),this._sharedWrites=null,this._trackPlayers.delete(e),this._motionPathTracks.delete(e),this._springTracks.delete(e),this._textTracks.delete(e)}getTracks(e={}){return this._tracks.filter(n=>this._matches(n,e))}removeTracks(e={}){const n=this.getTracks(e).map(s=>s.id);for(const s of n)this.removeTrack(s);return n}getTrackSpan(e){const n=this._trackPlayers.get(e);if(!n)return;const s=n.getTrack(),i=s.delay??0;if(Ae(s)||Ee(s))return{from:i,to:n.getDuration()};const o=s.keyframes;if(!(!o||o.length===0))return{from:o[0].time+i,to:n.getDuration()}}findConflicts(){const e=[];for(let n=0;n<this._tracks.length;n++){const s=this._tracks[n],i=this.getTrackSpan(s.id);if(i)for(let o=0;o<n;o++){const r=this._tracks[o];if(r.property!==s.property)continue;const a=Oe(r).filter(u=>Oe(s).includes(u));if(a.length===0)continue;const l=this.getTrackSpan(r.id);if(!l||!(l.from<=i.to&&i.from<=l.to))continue;const h=i.from>=l.from;for(const u of a)e.push({target:u,property:s.property,losingTrackId:h?r.id:s.id,winningTrackId:h?s.id:r.id})}}return e}_matches(e,n){if(n.id!==void 0&&e.id!==n.id||n.property!==void 0&&e.property!==n.property||n.target!==void 0&&!Oe(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:nr(this._tracks),id:this.id,name:this.name,config:{...this._config},tracks:[...this._tracks],...this.captions&&{captions:this.captions}}}get config(){return this._config}get markers(){return[...this._config.markers??[]].sort((e,n)=>e.time-n.time)}setMarkers(e){const n=e&&e.length>0?[...e].sort((i,o)=>i.time-o.time).map(i=>({...i})):void 0,s={...this._config};n?s.markers=n:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(e){const n={};for(const[s,i]of Object.entries(e??{}))n[s]={...i};this._captions=Object.keys(n).length>0?n:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let e=0;for(const[,n]of this._trackPlayers)e=Math.max(e,n.getDuration());return e}_handleEndReached(){const e=this._config.loop??0;return e===-1||this._loopIteration<e?(this._loopIteration++,this._armRepeatDelay(),this._config.alternate?this._direction="reverse":this._repeatDelayRemaining>0?this._wrapAfterDelay=!0:this._currentTime=0,this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}_handleStartReached(){const e=this._config.loop??0;return this._config.alternate&&(e===-1||this._loopIteration<e)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const n1=100;function xr(t,e,n,s){const i=[],o=[],{duration:r,alternate:a}=s,l=(f,p,g,m)=>{o.push([f,p]);const w=[];t.forEach((v,k)=>{(g==="forward"?(m?v>=f:v>f)&&v<=p:(m?v<=f:v<f)&&v>=p)&&w.push(k)}),w.sort((v,k)=>(g==="forward"?t[v]-t[k]:t[k]-t[v])||v-k);for(const v of w)i.push({kind:"event",index:v,direction:g})};let c=e.time,h=e.direction,u=e.fresh===!0;const d=Math.min(n1,Math.max(0,n.iteration-e.iteration));for(let f=0;f<d;f++){const p=h==="forward"?r:0;l(c,p,h,u),i.push({kind:"repeat"}),a?(h=h==="forward"?"reverse":"forward",c=p,u=!1):(c=h==="forward"?0:r,u=!0)}return d>0&&s.holding&&!a?{crossings:i,passes:o}:(l(c,n.time,h,u),{crossings:i,passes:o})}function fh(t){return Ee(t)?{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:gh(t.inertia),...de(t)}:Ae(t)?{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...de(t)}:li(t)?{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:t.keyframes.map(Er),...de(t)}:sr(t)?{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:t.keyframes.map(Er),...de(t)}:{id:t.id,target:t.target,property:t.property,keyframes:t.keyframes.map(Er),...t.interpolation!==void 0&&{interpolation:t.interpolation},...de(t)}}function gh(t){return{...t,...Array.isArray(t.end)&&{end:[...t.end]}}}function Er(t){return{time:t.time,value:t.value,...t.easing&&{easing:t.easing}}}function de(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 ph(t){if(Ee(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"inertia",inertia:gh(e.inertia),...de(e)}}if(Ae(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"spring",spring:{...e.spring},...de(e)}}if(li(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),...de(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,...de(e)}}return bi({id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,...t.interpolation!==void 0&&{interpolation:t.interpolation},...de(t)})}function mh(t){const e=t._config.markers;return{formatVersion:nr(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(fh),...t.captions&&{captions:JSON.parse(JSON.stringify(t.captions))}}}function An(t){const e=t.formatVersion??1;if(e>er)throw new Error(`tinyfly: this animation uses format version ${e}, but this tinyfly reads up to version ${er}. Update tinyfly to play it.`);return new It({id:t.id,name:t.name,config:t.config,tracks:t.tracks.map(ph),captions:t.captions})}function s1(t){return JSON.stringify(mh(t))}function i1(t){const e=JSON.parse(t);return An(e)}function Kt(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e>>>0}function _e(t){let e=t>>>0||2654435769;return{seed:t>>>0,next(){return e^=e<<13,e>>>=0,e^=e>>17,e^=e<<5,e>>>=0,e/4294967296}}}function Ar(t,e,n){return e+t.next()*(n-e)}function yh(t,e,n,s){if(s<=0)return Ar(t,e,n);const i=Math.floor((n-e)/s),o=Math.round(t.next()*i);return e+o*s}function o1(t,e){if(e.length!==0)return e[Math.floor(t.next()*e.length)]}const bh=/^([+\-*/])=\s*(-?[\d.]+)$/,wh=/^random\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*(?:,\s*(-?[\d.]+)\s*)?\)$/i;function r1(t){return typeof t!="string"?!1:bh.test(t.trim())||wh.test(t.trim())}function Pr(t,e={}){if(typeof t!="string")return t;const n=t.trim(),s=bh.exec(n);if(s){const[,o,r]=s,a=e.base??0,l=Number.parseFloat(r);switch(o){case"+":return a+l;case"-":return a-l;case"*":return a*l;case"/":return l===0?a:a/l}}const i=wh.exec(n);if(i){if(!e.random)throw new Error(`resolveValue: "${n}" needs a random source — pass one via context.random`);const o=Number.parseFloat(i[1]),r=Number.parseFloat(i[2]),a=i[3]!==void 0?Number.parseFloat(i[3]):void 0;return a!==void 0?yh(e.random,o,r,a):Ar(e.random,o,r)}return t}function kh(t,e=0,n){const s=[];let i=e;for(const o of t){const r=Pr(o,{base:i,random:n});s.push(r),typeof r=="number"&&(i=r)}return s}class a1{random;constructor(e){this.random=_e(e)}get seed(){return this.random.seed}resolve(e,n=0){return Pr(e,{base:n,random:this.random})}resolveSequence(e,n=0){return kh(e,n,this.random)}}const l1=600;function vh(t){if(Array.isArray(t)){const[d,f,p,g]=t;return{fn:Th(d,f,p,g),bezier:[d,f,p,g]}}const{segments:e}=Ve(t);if(e.length===0)throw new Error(`customEase: no curve in "${t}"`);const n=e[0].startX,s=e[0].startY,i=e[e.length-1],o=i.endX-n,r=i.endY-s;if(o===0||r===0)throw new Error(`customEase: "${t}" must move along both axes`);const a=d=>(d-n)/o,l=d=>(d-s)/r;if(e.length===1&&i.type==="C"){const[d,f,p,g]=i.points,m=[a(d),l(f),a(p),l(g)];return{fn:Th(...m),bezier:m}}const c=[],h=[],u=Math.max(8,Math.ceil(l1/e.length));for(const d of e)for(let f=c.length===0?0:1;f<=u;f++){const[p,g]=c1(d,f/u);c.push(a(p)),h.push(l(g))}return{fn:h1(c,h)}}function Mh(t={}){const n=.1+Math.max(0,Math.min(1,t.strength??.7))*.7,s=[1];for(let o=n;o>.002;o*=n)s.push(2*Math.sqrt(o));const i=s.reduce((o,r)=>o+r,0);return o=>{if(o<=0)return 0;if(o>=1)return 1;let r=o*i;for(let a=0;a<s.length;a++){if(r<=s[a]){if(a===0)return(r/s[0])**2;const l=s[a]/2,c=l*l,h=r-l;return 1-(c-h*h)}r-=s[a]}return 1}}function Sh(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 c1(t,e){if(t.type==="L"){const[c,h]=t.points;return[t.startX+(c-t.startX)*e,t.startY+(h-t.startY)*e]}const[n,s,i,o,r,a]=t.points,l=1-e;return[l*l*l*t.startX+3*l*l*e*n+3*l*e*e*i+e*e*e*r,l*l*l*t.startY+3*l*l*e*s+3*l*e*e*o+e*e*e*a]}function h1(t,e){return n=>{if(n<=t[0])return e[0];if(n>=t[t.length-1])return e[e.length-1];let s=0,i=t.length-1;for(;i-s>1;){const r=s+i>>1;t[r]<=n?s=r:i=r}const o=t[i]-t[s];return o===0?e[i]:e[s]+(n-t[s])/o*(e[i]-e[s])}}function Th(t,e,n,s){const i=(r,a,l)=>3*(1-r)*(1-r)*r*a+3*(1-r)*r*r*l+r*r*r,o=(r,a,l)=>3*(1-r)*(1-r)*a+6*(1-r)*r*(l-a)+3*r*r*(1-l);return r=>{if(r<=0)return 0;if(r>=1)return 1;let a=r;for(let h=0;h<8;h++){const u=i(a,t,n)-r,d=o(a,t,n);if(Math.abs(u)<1e-6)return i(a,e,s);if(Math.abs(d)<1e-6)break;a-=u/d}let l=0,c=1;a=r;for(let h=0;h<40;h++)i(a,t,n)<r?l=a:c=a,a=(l+c)/2;return i(a,e,s)}}const u1=350,d1=300,f1=550;function g1(t,e={}){const n=e.lead??u1,s=e.gap??d1,i=e.tail??f1,o=[];let r=0;return t.forEach((a,l)=>{const c=[];let h=r+n;a.lines.forEach((d,f)=>{if(!(d.duration>=0))throw new Error(`narration: scene ${l} line ${f} has an invalid duration (${d.duration})`);f>0&&(h+=s),c.push({id:d.id??`s${l}-l${f}`,scene:l,line:f,start:h,end:h+d.duration,text:d.text}),h+=d.duration});const u=h+i+(a.tail??0);o.push({id:a.id??`s${l}`,start:r,duration:u-r,cues:c}),r=u}),{duration:r,scenes:o,cues:o.flatMap(a=>a.cues)}}function p1(t){return t.cues.map(e=>({id:e.id,time:e.start,label:e.text}))}function m1(t,e){let n=t.scenes[0];for(const s of t.scenes)if(e>=s.start)n=s;else break;return n}const bs=t=>6e4/t.bpm;function wi(t,e){return t.offset+e*bs(t)}function ws(t,e){return(e-t.offset)/bs(t)}function y1(t,e){return wi(t,Math.round(ws(t,e)))}function b1(t,e){return wi(t,Math.ceil(ws(t,e)-1e-9))}function w1(t,e,n){const s=Math.max(1,Math.round(t.beatsPerBar??4)),i=[];if(!(t.bpm>0)||n<e)return i;for(let o=Math.ceil(ws(t,e)-1e-9);;o++){const r=wi(t,o);if(r>n+1e-9)break;i.push({time:r,bar:(o%s+s)%s===0,n:o})}return i}const Pn=100;function k1(t,e,n={}){const s=n.minBpm??70,i=n.maxBpm??180,o=Math.max(1,Math.round(e/Pn)),r=Math.min(t.length,Math.round((n.maxSeconds??60)*e)),a=Math.floor(r/o);if(a<4)return{bpm:120,offset:0,confidence:0};const l=new Float64Array(a);for(let M=0;M<a;M++){let T=0;for(let I=M*o;I<(M+1)*o;I++)T+=t[I]*t[I];l[M]=Math.log(1e-6+T/o)}const c=new Float64Array(a);for(let M=1;M<a;M++)c[M]=Math.max(0,l[M]-l[M-1]);const h=c.reduce((M,T)=>M+T,0)/a;for(let M=0;M<a;M++)c[M]=Math.max(0,c[M]-h);const u=Math.max(1,Math.floor(60*Pn/i)),d=Math.min(a-1,Math.ceil(60*Pn/s)),f=M=>{let T=0;for(let I=M;I<a;I++)T+=c[I]*c[I-M];return T/(a-M)};let p=0;for(let M=0;M<a;M++)p+=c[M]*c[M];p/=a;let g=u,m=-1/0;for(let M=u;M<=d;M++){const T=60*Pn/M,I=Math.exp(-.5*(Math.log2(T/120)/.9)**2),A=f(M)*I;A>m&&(m=A,g=M)}const w=M=>{const T=Math.floor(M);return T<0||T+1>=a?0:c[T]+(c[T+1]-c[T])*(M-T)},v=(M,T)=>{let I=0;for(let A=T;A<a;A+=M)I+=w(A);return I};let k=g,b=0,E=-1/0;for(let M=g-.6;M<=g+.6+1e-9;M+=.02){if(M<1)continue;const T=Math.max(1,Math.round(M*4));for(let I=0;I<T;I++){const A=I/T*M,_=v(M,A);_>E&&(E=_,b=A,k=M)}}const $=60*Pn/k,S=p>0?Math.max(0,Math.min(1,f(g)/p)):0,x=(b+.5)*1e3/Pn;return{bpm:Math.round($*100)/100,offset:Math.round(x%(6e4/$)),confidence:S}}const v1=600,M1=250,xh=1;function S1(t,e){const n=e.target??"Camera",s={x:e.stage.width/2,y:e.stage.height/2},i={},o=(u,d,f,p)=>{const g=i[u]??=[];for(;g.length>0&&g[g.length-1].time>=d;)g.pop();g.push({time:d,value:f,...p?{easing:p}:{}})},r=u=>{const d=u.rotate*Math.PI/180,f=(u.focusX-s.x)*u.scale,p=(u.focusY-s.y)*u.scale;return{x:-(f*Math.cos(d)-p*Math.sin(d)),y:-(f*Math.sin(d)+p*Math.cos(d)),scale:u.scale,rotate:u.rotate}},a=(u,d,f)=>{const p=r(d);for(const g of["x","y","scale","rotate"])o(g,u,p[g],f)};let l={focusX:s.x,focusY:s.y,scale:1,rotate:0};const c=[...t].sort((u,d)=>u.at-d.at),h=c.filter(u=>!("shake"in u));h.length>0&&a(0,l);for(const u of h)if("frame"in u){const d=Math.max(xh,u.duration??v1);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>xh?"ease-in-out":void 0))}else{const{follow:d}=u,f=d.lag??M1,p=new It({id:"follow",tracks:[{id:"x",target:"s",property:"x",keyframes:d.x}]}),g=v=>p.getStateAtTime(v).values.get("s")?.get("x")??l.focusX,m=[u.at,...d.x.map(v=>v.time).filter(v=>v>u.at&&v<u.until),u.until];a(u.at,l);const w=v=>({focusX:g(v)+(d.lead??0),focusY:d.y??l.focusY,scale:d.scale??l.scale,rotate:l.rotate});for(const v of m){const k=d.x.find(b=>b.time===v)?.easing;a(v+f,w(v),v===u.at?"ease-in-out":k)}l=w(u.until)}for(const u of c.filter(d=>"shake"in d)){const d=u.shake.strength??12,f=u.shake.roll??1.5,p=1e3/(u.shake.frequency??24),g=_e(u.shake.seed??Math.round(u.at)+1),m=()=>g.next()*2-1;for(const w of["shakeX","shakeY","shakeRotate"])o(w,u.at,0);for(let w=u.at+p;w<u.at+u.duration;w+=p){const v=1-(w-u.at)/u.duration;o("shakeX",w,m()*d*v),o("shakeY",w,m()*d*v),o("shakeRotate",w,m()*f*v)}for(const w of["shakeX","shakeY","shakeRotate"])o(w,u.at+u.duration,0,"ease-out")}return Object.entries(i).map(([u,d])=>({id:`${n}-${u}`,target:n,property:u,keyframes:d}))}function Eh(t,e){const n=t.toLowerCase(),s=e.toLowerCase();let i=Array.from({length:s.length+1},(o,r)=>r);for(let o=1;o<=n.length;o++){const r=[o];for(let a=1;a<=s.length;a++)r[a]=Math.min(i[a]+1,r[a-1]+1,i[a-1]+(n[o-1]===s[a-1]?0:1));i=r}return i[s.length]}function ks(t,e){const n=t.toLowerCase(),s=e.find(r=>r.toLowerCase().includes(n)||n.includes(r.toLowerCase()));if(s&&Math.min(t.length,s.length)>=3)return s;let i,o=1/0;for(const r of e){const a=Eh(t,r);a<o&&(o=a,i=r)}return i!==void 0&&o<=Math.max(2,Math.floor(t.length/3))?i:void 0}function dt(t,e,n,s){const i=typeof e=="string"?s??ks(e,n):void 0;return`Unknown ${t} ${JSON.stringify(e)}${i?`: did you mean "${i}"?`:"."} Known: ${n.join(", ")}`}function vs(t,e){const n=e.step??33,s=e.stiffness??120,i=e.damping??9,o=e.mass??1;let r=t(e.start),a=0;const l=[{time:e.start,value:r}];let c=e.start+n;for(let h=e.start+1;h<=e.end;h++){const d=s*(t(h)-r)-i*a;a+=d/o*.001,r+=a*.001,(h>=c||h===e.end)&&(l.push({time:h,value:r}),c+=n)}return l}function Je(t,e,n=1){if(!(e>0))return 0;const s=t*n/e;return s-Math.floor(s)}function $r(t){const e=t-Math.floor(t);return 1-Math.abs(e*2-1)}function T1(t,e){const n=Math.max(1,Math.round(e.cycles??1)),s=e.amplitude??1,i=Je(t,e.period,n)+(e.phase??0),o=i-Math.floor(i);switch(e.shape??"sine"){case"triangle":return s*($r(o+.25)*2-1);case"square":return o<.5?s:-s;default:return s*Math.sin(o*Math.PI*2)}}function x1(t,e){const n=Math.max(1,Math.round(e.cycles??1)),s=typeof e.easing=="function"?e.easing:Lt(e.easing??"ease-in-out"),i=Je(t,e.period,n)+(e.phase??0);return s($r(i))}function E1(t,e){const n=Ah(e.seed),s=Math.max(1,Math.round(e.cycles??1)),i=(Je(t,e.period,1)+(e.phase??0))*Math.PI*2,o=s/Math.PI;return Ph([Math.cos(i)*o+7.31,Math.sin(i)*o+3.17],n,e.octaves??1)}function A1(t,e,n){const s=Ah(n.seed),i=Math.max(1,Math.round(n.cycles??1)),o=Math.max(1,Math.round(n.cyclesAlong??1)),r=Je(t,n.period,1)*Math.PI*2,a=Je(e,n.periodAlong,1)*Math.PI*2,l=i/Math.PI,c=o/Math.PI;return Ph([Math.cos(r)*l+5.13,Math.sin(r)*l+9.47,Math.cos(a)*c+2.71,Math.sin(a)*c+6.29],s,n.octaves??1)}const Ah=t=>typeof t=="string"?Kt(t):(t??0)>>>0;function Ph(t,e,n){const s=Math.max(1,Math.min(6,Math.round(n)));let i=0,o=1,r=0;for(let a=0;a<s;a++){const l=2**a;i+=o*P1(t.map(c=>c*l),e+a*1013),r+=o,o*=.5}return i/r}function P1(t,e){const n=t.length,s=t.map(Math.floor),o=t.map((a,l)=>a-s[l]).map(a=>a*a*(3-2*a));let r=0;for(let a=0;a<1<<n;a++){let l=1;const c=[];for(let h=0;h<n;h++){const u=a>>h&1;l*=u?o[h]:1-o[h],c.push(s[h]+u)}l!==0&&(r+=l*$1(c,e))}return r}function $1(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 I1(t,e={}){if(t.length===0)throw new Error("curve: needs at least one key");const s={id:"curve",target:"curve",property:"value",keyframes:t.map(o=>({time:o.at,value:o.value,easing:o.easing})).sort((o,r)=>o.time-r.time),interpolation:e.interpolation},i=new ys(s);return o=>i.getValueAtTime(o)}function O1(t,e){return e*bs({bpm:t.bpm})}function _1(t,e){const n=Math.max(1,Math.round(t/bs(e)));return{beats:n,grid:{...e,bpm:n*6e4/t}}}function C1(t,e,n={}){const s=Math.max(1e-6,n.attack??.05),i=Math.max(1e-6,n.decay??.4),o=ws(e,t),r=o-Math.floor(o),a=r<s?r/s:Math.max(0,1-(r-s)/i),l=n.barAccent??0;if(l<=0)return a;const c=Math.max(1,Math.round(e.beatsPerBar??4)),u=(Math.floor(o)%c+c)%c===0;return a*(u?1+l:1)/(1+l)}function H1(t,e,n={}){const s=n.fps??30,i=Math.max(1,Math.round(e/s)),o=Math.max(1,Math.ceil(t.length/i)),r=new Float32Array(o),a=Math.min(.99,Math.max(0,n.smoothing??.5));let l=0,c=0;for(let h=0;h<o;h++){let u=0;const d=h*i,f=Math.min(t.length,d+i);for(let g=d;g<f;g++)u+=t[g]*t[g];const p=f>d?Math.sqrt(u/(f-d)):0;l=p>l?p:l*a+p*(1-a),r[h]=l,c=Math.max(c,l)}if(n.normalize!==!1&&c>0)for(let h=0;h<o;h++)r[h]/=c;return r}function R1(t,e,n=30,s){if(t.length===0)return 0;const o=(s?Je(e,s)*s:e)*n/1e3,r=Math.floor(o),a=t[Math.min(t.length-1,Math.max(0,r))],l=t[Math.min(t.length-1,Math.max(0,r+1))];return a+(l-a)*(o-r)}const $h={"16:9":16/9,"2.39:1":2.39,"4:3":4/3,"1:1":1,"9:16":9/16,"4:5":4/5},Ir=t=>typeof t=="number"?t:$h[t];function L1(t,e){const n=Ir(e),s=t.width/t.height;if(n>=s){const o=t.width/n;return{x:0,y:(t.height-o)/2,width:t.width,height:o}}const i=t.height*n;return{x:(t.width-i)/2,y:0,width:i,height:t.height}}function N1(t,e){const n=Ir(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 F1(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 fe=t=>Math.round(t*1e3)/1e3;function Ih(t,e={}){if(t.length===0)return"";const n=e.curviness??1,s=e.closed??!1,i=t.length;let o=`M${fe(t[0].x)} ${fe(t[0].y)}`;if(i===1)return o;const r=l=>s?t[(l%i+i)%i]:t[Math.max(0,Math.min(i-1,l))],a=s?i:i-1;for(let l=0;l<a;l++){const c=r(l-1),h=r(l),u=r(l+1),d=r(l+2);if(n===0){o+=` L${fe(u.x)} ${fe(u.y)}`;continue}const f=n/6,p=h.x+(u.x-c.x)*f,g=h.y+(u.y-c.y)*f,m=u.x-(d.x-h.x)*f,w=u.y-(d.y-h.y)*f;o+=` C${fe(p)} ${fe(g)} ${fe(m)} ${fe(w)} ${fe(u.x)} ${fe(u.y)}`}return s?`${o} Z`:o}const Nt=(t,e=0)=>{const n=parseFloat(t??"");return Number.isFinite(n)?n:e};function D1(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 ki(t){const e=t.attributes;switch(t.tag.toLowerCase()){case"path":return e.d??null;case"circle":case"ellipse":{const n=Nt(e.cx),s=Nt(e.cy),i=t.tag.toLowerCase()==="circle"?Nt(e.r):Nt(e.rx),o=t.tag.toLowerCase()==="circle"?Nt(e.r):Nt(e.ry);return`M${n+i} ${s} A${i} ${o} 0 1 1 ${n-i} ${s} A${i} ${o} 0 1 1 ${n+i} ${s} Z`}case"rect":{const n=Nt(e.x),s=Nt(e.y),i=Nt(e.width),o=Nt(e.height);let r=e.rx!=null?Nt(e.rx):e.ry!=null?Nt(e.ry):0,a=e.ry!=null?Nt(e.ry):r;return r=Math.min(r,i/2),a=Math.min(a,o/2),r===0||a===0?`M${n} ${s} H${n+i} V${s+o} H${n} Z`:`M${n+r} ${s} H${n+i-r} A${r} ${a} 0 0 1 ${n+i} ${s+a} V${s+o-a} A${r} ${a} 0 0 1 ${n+i-r} ${s+o} H${n+r} A${r} ${a} 0 0 1 ${n} ${s+o-a} V${s+a} A${r} ${a} 0 0 1 ${n+r} ${s} Z`}case"line":return`M${Nt(e.x1)} ${Nt(e.y1)} L${Nt(e.x2)} ${Nt(e.y2)}`;case"polyline":case"polygon":{const n=D1(e.points);if(n.length===0)return null;const s=n.map((i,o)=>`${o===0?"M":"L"}${i.x} ${i.y}`).join(" ");return t.tag.toLowerCase()==="polygon"?`${s} Z`:s}default:return null}}function W1(t,e,n){const s=Math.max(2,Math.round(n.samples??32)),i=Math.max(0,n.length),o=n.since!==void 0?Math.max(e-i,n.since):e-i;if(o>=e)return[];const r=n.period,a=[];for(let l=0;l<s;l++){const c=o+(e-o)*l/(s-1),h=r&&r>0&&l<s-1?(c%r+r)%r:c;a.push({at:t(h),time:c,age:i>0?(e-c)/i:0})}return a}const B1=2.5;function Oh(t){const e=[],n=[],s=t.length,i=(o,r)=>{for(let a=o+r;a>=0&&a<s;a+=r){const l=(t[a].x-t[o].x)*r,c=(t[a].y-t[o].y)*r,h=Math.hypot(l,c);if(h>1e-9)return[l/h,c/h]}return null};for(let o=0;o<s;o++){const r=t[o],a=i(o,-1),l=i(o,1),c=a??l??[1,0],h=l??a??[1,0];let u=c[0]+h[0],d=c[1]+h[1];const f=Math.hypot(u,d);f<1e-9?(u=c[0],d=c[1]):(u/=f,d/=f);const p=u*c[0]+d*c[1],g=Math.min(B1,1/Math.max(p,1e-6)),m=r.width/2*g;e.push({x:r.x-d*m,y:r.y+u*m}),n.push({x:r.x+d*m,y:r.y-u*m})}return{left:e,right:n}}function _h(t){const e=t.length;if(e<2)return null;const n=t[e-1];for(let s=e-2;s>=0;s--){const i=n.x-t[s].x,o=n.y-t[s].y,r=Math.hypot(i,o);if(r>1e-9)return{x:n.x,y:n.y,radius:n.width/2,start:Math.atan2(i/r,-o/r)}}return null}const z1={scale:1,turn:0,x:0,y:0};function q1(t={}){return{scale:t.scale??1,turn:t.turn??0,x:t.x??0,y:t.y??0}}function Ch(t,e,n){const{ax:s,ay:i}=vi(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 Or(t,e){const{ax:n,ay:s}=vi(t.scale,t.turn);return{x:n*e.x-s*e.y+t.x,y:s*e.x+n*e.y+t.y}}function Y1(t,e){const n=Or(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 j1(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=Or(e,{x:t.x,y:t.y});return{...e,x:-n.x,y:-n.y}}function Hh(t){const{ax:e,ay:n}=vi(t.scale,t.turn),s=1-e,i=-n,o=s*s+i*i;return o<1e-18?null:{x:(t.x*s+t.y*i)/o,y:(t.y*s-t.x*i)/o}}function K1(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=Hh(t);return i?Ch(n,s,i):{scale:n,turn:s,x:t.x*e,y:t.y*e}}function X1(t){const{ax:e,ay:n}=vi(t.scale,t.turn);return[e,n,-n,e,t.x,t.y]}const vi=(t,e)=>{const n=e*Math.PI/180;return{ax:t*Math.cos(n),ay:t*Math.sin(n)}};function Mi([t,e,n],s={}){const i=s.scale??1,o=s.centre??{x:0,y:0},r=Math.sqrt(3)/2;return{x:o.x+(t-e)*r*i,y:o.y+((t+e)*.5-n)*i}}const _r=([t,e,n])=>t+e+n;function Cr(t,e={}){const[n,s,i]=t.min,[o,r,a]=t.max,l=d=>Mi(d,e),c=[(n+o)/2,(s+r)/2,(i+a)/2],h=_r(c),u=[{side:"top",depth:h,tag:t.tag,points:[l([n,s,a]),l([o,s,a]),l([o,r,a]),l([n,r,a])]},{side:"left",depth:h,tag:t.tag,points:[l([n,r,i]),l([o,r,i]),l([o,r,a]),l([n,r,a])]},{side:"right",depth:h,tag:t.tag,points:[l([o,s,i]),l([o,r,i]),l([o,r,a]),l([o,s,a])]}];return t.hide?u.filter(d=>!t.hide.includes(d.side)):u}function Hr(t,e={}){return t.map(n=>({box:n,depth:_r([(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})=>Cr(n,e))}function G1(t={}){const e=t.size??10,s=(t.thickness??2)/2,i=[{tag:0,min:[-s,-s,-s],max:[e-s,s,s]},{tag:1,min:[e-s,-s,-s],max:[e+s,e-s,s]},{tag:2,min:[e-s,e-s,-s],max:[e+s,e+s,e]}],o=t.centre??{x:0,y:0},r=Mi([2*e/3,e/3,e/3],{scale:t.scale}),a={centre:{x:o.x-r.x,y:o.y-r.y},scale:t.scale};return{boxes:i,faces:[...Hr(i,a),...Cr({...i[0],hide:["right"]},a)]}}function U1(t={}){const e=Math.max(2,Math.round(t.steps??8)),n=t.tread??1.5,s=t.rise??.25,i=t.width??3,o=t.base??1.5,r=Math.max(1,Math.round(e*(n-2*s)/(n+2*s))),a=2*(e+r),l=n*(e-r)/a,c=[{dir:[1,0,0],across:[0,1,0],count:e},{dir:[0,1,0],across:[-1,0,0],count:e},{dir:[-1,0,0],across:[0,-1,0],count:r},{dir:[0,-1,0],across:[1,0,0],count:r}],h=[];let u=[0,0,0],d=0;for(const w of c){for(let v=0;v<w.count;v++){const k=d*l,b=[u[0]+w.dir[0]*v*n,u[1]+w.dir[1]*v*n,0],E=[b[0]+w.dir[0]*n+w.across[0]*i,b[1]+w.dir[1]*n+w.across[1]*i,0];h.push({tag:d,min:[Math.min(b[0],E[0]),Math.min(b[1],E[1]),0],max:[Math.max(b[0],E[0]),Math.max(b[1],E[1]),k+o]}),d++}u=[u[0]+w.dir[0]*w.count*n,u[1]+w.dir[1]*w.count*n,0]}const f=a*l,p=t.centre??{x:0,y:0},g=Mi([e*n/2,e*n/2,f/2+o],{scale:t.scale}),m={centre:{x:p.x-g.x,y:p.y-g.y},scale:t.scale};return{boxes:h,faces:Hr(h,m),rise:l}}function Rh(t,e,n){let s=0;for(const i of t){const o=(e-i.x)**2+(n-i.y)**2;s+=o>1e-9?i.r*i.r/o:1e9}return s}function V1(t,e={}){if(t.length===0)return[];const n=e.threshold??1,s=Math.max(.5,e.cell??4),i=Math.sqrt(1/n)*1.6,o=e.bounds??{x:Math.min(...t.map(f=>f.x-f.r*i)),y:Math.min(...t.map(f=>f.y-f.r*i)),width:Math.max(...t.map(f=>f.x+f.r*i))-Math.min(...t.map(f=>f.x-f.r*i)),height:Math.max(...t.map(f=>f.y+f.r*i))-Math.min(...t.map(f=>f.y-f.r*i))},r=Math.max(2,Math.ceil(o.width/s)+1),a=Math.max(2,Math.ceil(o.height/s)+1),l=new Float64Array(r*a);for(let f=0;f<a;f++)for(let p=0;p<r;p++)l[f*r+p]=Rh(t,o.x+p*s,o.y+f*s)-n;const c=(f,p)=>l[p*r+f],h=(f,p,g,m,w,v)=>{const k=g===v?.5:g/(g-v);return{x:f+(m-f)*k,y:p+(w-p)*k}},u=[];for(let f=0;f+1<a;f++)for(let p=0;p+1<r;p++){const g=o.x+p*s,m=o.y+f*s,w=g+s,v=m+s,k=[c(p,f),c(p+1,f),c(p+1,f+1),c(p,f+1)],b=(k[0]>0?1:0)|(k[1]>0?2:0)|(k[2]>0?4:0)|(k[3]>0?8:0);if(b===0||b===15)continue;const E=()=>h(g,m,k[0],w,m,k[1]),$=()=>h(w,m,k[1],w,v,k[2]),S=()=>h(g,v,k[3],w,v,k[2]),x=()=>h(g,m,k[0],g,v,k[3]),M=(k[0]+k[1]+k[2]+k[3])/4>0;switch(b){case 1:case 14:u.push([x(),E()]);break;case 2:case 13:u.push([E(),$()]);break;case 3:case 12:u.push([x(),$()]);break;case 4:case 11:u.push([$(),S()]);break;case 6:case 9:u.push([E(),S()]);break;case 7:case 8:u.push([x(),S()]);break;case 5:M?u.push([x(),S()],[E(),$()]):u.push([x(),E()],[$(),S()]);break;case 10:M?u.push([x(),E()],[$(),S()]):u.push([x(),S()],[E(),$()]);break}}const d=J1(u);return e.smooth===!1?d:d.map(f=>Lh(Lh(f)))}function J1(t){const e=o=>`${Math.round(o.x*1e3)},${Math.round(o.y*1e3)}`,n=new Map;t.forEach(([o,r],a)=>{for(const l of[o,r]){const c=e(l);n.has(c)||n.set(c,[]),n.get(c).push(a)}});const s=new Array(t.length).fill(!1),i=[];for(let o=0;o<t.length;o++){if(s[o])continue;s[o]=!0;const r=[t[o][0],t[o][1]];let a=t[o][1];for(;;){const l=(n.get(e(a))??[]).find(u=>!s[u]);if(l===void 0)break;s[l]=!0;const[c,h]=t[l];if(a=e(c)===e(a)?h:c,e(a)===e(r[0]))break;r.push(a)}r.length>=3&&i.push(r)}return i}function Lh(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 Z1(t){const e=Math.min(1,Math.max(0,t.progress));if(e<=0)return[];const n=t.width/2,s=n*(.55+.75*e),i=Math.max(t.length*e,s*1.2),o=t.x,r=t.y+i-s,a=Math.max(.1,n*(.35-.3*e)),l=r-Math.sqrt(Math.max(0,s*s-a*a)),c=Math.max(0,l-t.y),h=8,u=[],d=[];for(let v=0;v<=h;v++){const k=v/h,b=a+(n-a)*Math.pow(1-k,1.6+1.4*e);u.push({x:o-b,y:t.y+c*k}),d.push({x:o+b,y:t.y+c*k})}const f=Math.max(8,Math.round(t.segments??12)),p=Math.acos(Math.min(1,a/s)),g=-p,m=Math.PI+p,w=[];for(let v=1;v<f;v++){const k=g+(m-g)*v/f;w.push({x:o+Math.cos(k)*s,y:r+Math.sin(k)*s})}return[...d,...w,...u.reverse()]}function Q1(t){const e=Math.min(1,Math.max(0,t.grow??1)),n=e>=1?1:1-Math.pow(1-e,3)+.08*Math.sin(e*Math.PI)*e,s=t.r*Math.max(0,n);if(s<=0)return[];const i=Math.max(12,Math.round(t.segments??48)),o=t.wobble??.05,r=t.time??0,a=t.period?r/t.period:r/2500,l=(a-Math.floor(a))*Math.PI*2,c=t.seed??0,h=[];for(let u=0;u<i;u++){const d=u/i*Math.PI*2,f=1+o*(Math.sin(2*d+l+c)*.6+Math.sin(3*d-2*l+c*1.7)*.4);h.push({x:t.x+Math.cos(d)*s*f,y:t.y+Math.sin(d)*s*f})}return h}function ty(t){const e=t.progress;if(e<=0||e>=1)return[];const n=Math.max(3,Math.round(t.pieces??8)),s=[],i=t.r*(1+1.2*e),o=Math.PI*2/n*.6*(1-e);for(let r=0;r<n;r++){const a=r/n*Math.PI*2+.3,l=[];for(let c=0;c<=4;c++){const h=a-o/2+o*c/4;l.push({x:t.x+Math.cos(h)*i,y:t.y+Math.sin(h)*i})}s.push(l)}return s}function ey(t,e={}){const n=Math.max(.05,1+t);return{sx:e.keep==="volume"?1/Math.sqrt(n):1/n,sy:n}}function ny(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 Si(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function $n(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function In(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function Ce(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Ti(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 xi(t){return Math.hypot(t[0],t[1],t[2])}function Rr(t,e){return xi($n(t,e))}function Ze(t){const e=xi(t);return e===0?[0,0,0]:In(t,1/e)}function Nh(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 sy=Object.freeze(Object.defineProperty({__proto__:null,add:Si,cross:Ti,distance:Rr,dot:Ce,length:xi,lerp:Nh,normalize:Ze,scale:In,subtract:$n},Symbol.toStringTag,{value:"Module"})),iy=Math.PI/180;function Ei(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function Ot(t,e){const n=new Array(16);for(let s=0;s<4;s++)for(let i=0;i<4;i++){let o=0;for(let r=0;r<4;r++)o+=t[r*4+i]*e[s*4+r];n[s*4+i]=o}return n}function Qe(t){return[1,0,0,0,0,1,0,0,0,0,1,0,t[0],t[1],t[2],1]}function tn(t){return[t[0],0,0,0,0,t[1],0,0,0,0,t[2],0,0,0,0,1]}function re(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 Lr(t,e,n){const s=re(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 oy(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 Nr(t){const[e,n,s,i,o,r,a,l,c,h,u,d,f,p,g,m]=t,w=e*r-n*o,v=e*a-s*o,k=e*l-i*o,b=n*a-s*r,E=n*l-i*r,$=s*l-i*a,S=c*p-h*f,x=c*g-u*f,M=c*m-d*f,T=h*g-u*p,I=h*m-d*p,A=u*m-d*g,_=w*A-v*I+k*T+b*M-E*x+$*S;if(Math.abs(_)<1e-12)return null;const C=1/_;return[(r*A-a*I+l*T)*C,(s*I-n*A-i*T)*C,(p*$-g*E+m*b)*C,(u*E-h*$-d*b)*C,(a*M-o*A-l*x)*C,(e*A-s*M+i*x)*C,(g*k-f*$-m*v)*C,(c*$-u*k+d*v)*C,(o*I-r*M+l*S)*C,(n*M-e*I-i*S)*C,(f*E-p*k+m*w)*C,(h*k-c*E-d*w)*C,(r*x-o*T-a*S)*C,(e*T-n*x+s*S)*C,(p*v-f*b-g*w)*C,(c*b-h*v+u*w)*C]}function ry(t,e,n,s){const i=1/Math.tan(t*iy/2),o=1/(n-s);return[i/e,0,0,0,0,i,0,0,0,0,(s+n)*o,-1,0,0,2*s*n*o,0]}function ay(t,e,n,s,i,o){const r=1/(e-t),a=1/(s-n),l=1/(o-i);return[2*r,0,0,0,0,2*a,0,0,0,0,-2*l,0,-(e+t)*r,-(s+n)*a,-(o+i)*l,1]}function ly(t,e,n=[0,1,0]){const s=Ze($n(t,e)),i=Ze(Ti(n,s)),o=Ti(s,i);return[i[0],o[0],s[0],0,i[1],o[1],s[1],0,i[2],o[2],s[2],0,-Ce(i,t),-Ce(o,t),-Ce(s,t),1]}function Xt(t,e){const n=t[0]*e[0]+t[4]*e[1]+t[8]*e[2]+t[12],s=t[1]*e[0]+t[5]*e[1]+t[9]*e[2]+t[13],i=t[2]*e[0]+t[6]*e[1]+t[10]*e[2]+t[14],o=t[3]*e[0]+t[7]*e[1]+t[11]*e[2]+t[15];return o===1||o===0?[n,s,i]:[n/o,s/o,i/o]}const cy=Object.freeze(Object.defineProperty({__proto__:null,compose:Lr,fromQuat:re,identity:Ei,invert:Nr,lookAt:ly,multiply:Ot,orthographic:ay,perspective:ry,scaling:tn,transformPoint:Xt,translation:Qe,transpose:oy},Symbol.toStringTag,{value:"Module"})),Ai={"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]},Fh={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 hy(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}Lt({type:"bounce",mode:"in"}),Lt({type:"bounce",mode:"in-out"});function Ms(t){const e=Dh.get(t.trim().toLowerCase());if(e)return e;const n=hy(t),s=/^steps\(\s*(\d+)\s*\)$/.exec(n);if(s){const r={type:"steps",count:Math.max(1,Number.parseInt(s[1],10))+1,position:"none"};return{easing:r,fn:Lt(r)}}const i=/^(elastic|bounce|back)\.(in|out|inout)(?:\(([^)]*)\))?$/.exec(n);if(i){const[,o,r,a]=i,l=(a??"").split(",").map(u=>Number.parseFloat(u)).filter(u=>Number.isFinite(u)),c=r==="inout"?"in-out":r;if(o==="back"&&l.length===0&&n in Ai)return{easing:{type:"cubic-bezier",points:Ai[n]}};const h=o==="elastic"?{type:"elastic",mode:c,...l[0]!==void 0&&{amplitude:l[0]},...l[1]!==void 0&&{period:l[1]}}:o==="bounce"?{type:"bounce",mode:c}:{type:"back",mode:c,...l[0]!==void 0&&{overshoot:l[0]}};return{easing:h,fn:Lt(h)}}return n in Fh?{easing:Fh[n]}:n in Ai?{easing:{type:"cubic-bezier",points:Ai[n]}}:{easing:"ease-out"}}const Dh=new Map;function Fr(t,e){return Dh.set(t.trim().toLowerCase(),e.bezier?{easing:{type:"cubic-bezier",points:e.bezier},fn:e.fn}:{fn:e.fn,requiresBaking:"custom"}),t}function Dr(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 Wh=/^\s*random\(\s*(\[.*\]|[^)]*)\s*\)\s*$/;function Bh(t){return typeof t=="string"&&Wh.test(t)}function uy(t=1){let e=Dr(t);const n=(l,c)=>((...h)=>h.length>=l?c(...h):u=>c(...h,u)),s=(l,c,h)=>Math.min(Math.max(h,Math.min(l,c)),Math.max(l,c)),i=(l,c,h,u,d)=>c===l?h:h+(d-l)/(c-l)*(u-h),o=(l,c)=>{if(typeof l=="number")return l===0?c:Math.round(c/l)*l;if(Array.isArray(l))return zh(l,c,1/0);if("values"in l)return zh(l.values,c,l.radius??1/0);const h=Math.round(c/l.increment)*l.increment;return Math.abs(h-c)<=(l.radius??1/0)?h:c},r=(l,c,h)=>{const u=l+e()*(c-l);return h?Math.round(u/h)*h:u};return{clamp:n(3,s),mapRange:n(5,i),normalize:n(3,(l,c,h)=>i(l,c,0,1,h)),interpolate:n(3,(l,c,h)=>{if(typeof l=="object"&&!Array.isArray(l)){const u={};for(const d of Object.keys(l))u[d]=ms(l[d])(l[d],c[d],h);return u}return ms(l)(l,c,h)}),wrap:((l,c,h)=>{if(Array.isArray(l)){const g=l,m=w=>g[(Math.round(w)%g.length+g.length)%g.length];return c===void 0?m:m(c)}const u=l,f=c-u,p=g=>f===0?u:((g-u)%f+f)%f+u;return h===void 0?p:p(h)}),wrapYoyo:n(3,(l,c,h)=>{const u=c-l;if(u===0)return l;const d=((h-l)%(u*2)+u*2)%(u*2);return l+(d>u?u*2-d:d)}),snap:n(2,o),random:((l,c,h,u)=>{if(Array.isArray(l)){const f=()=>l[Math.floor(e()*l.length)];return c===!0?f:f()}const d=()=>r(l,c,h);return u?d:d()}),shuffle:l=>{for(let c=l.length-1;c>0;c--){const h=Math.floor(e()*(c+1));[l[c],l[h]]=[l[h],l[c]]}return l},distribute:({base:l=0,amount:c,each:h,from:u="start",ease:d})=>(f,p,g)=>{const m=g.length,v=ci(f,m,{...c!==void 0?{amount:c}:{each:h??1},from:u}),k=c!==void 0?c:(h??1)*or(m,u),b=d&&k>0?d(v/k)*k:v;return l+b},pipe:(...l)=>c=>l.reduce((h,u)=>u(h),c),splitColor:l=>dy(l),getUnit:l=>typeof l=="number"?"":/^-?[\d.]+(?:e[-+]?\d+)?([a-z%]*)$/i.exec(l.trim())?.[1]??"",seed:l=>{e=Dr(l)},resolveRandomString:l=>{const c=Wh.exec(l)?.[1]??"";if(c.startsWith("[")){const p=c.slice(1,-1).split(",").map(g=>g.trim()).filter(Boolean).map(g=>Number.isFinite(Number(g))?Number(g):g.replace(/^['"]|['"]$/g,""));return p[Math.floor(e()*p.length)]}const[h,u,d]=c.split(",").map(f=>Number.parseFloat(f));return r(h,u,Number.isFinite(d)?d:void 0)}}}function zh(t,e,n){let s=e,i=1/0;for(const o of t){const r=Math.abs(o-e);r<i&&(i=r,s=o)}return i<=n?s:e}function dy(t){const e=t.trim(),n=/^#([0-9a-f]{3,8})$/i.exec(e)?.[1];if(n){const o=(n.length<=4?[...n].map(r=>r+r).join(""):n).match(/../g).map(r=>Number.parseInt(r,16));return o.length>=4?[o[0],o[1],o[2],Math.round(o[3]/255*1e3)/1e3]:[o[0],o[1],o[2]]}const s=(/rgba?\(([^)]+)\)/i.exec(e)?.[1]??"0,0,0").split(/[\s,/]+/).filter(Boolean).map(i=>Number.parseFloat(i));return s.length>=4?[s[0],s[1],s[2],s[3]]:[s[0]??0,s[1]??0,s[2]??0]}const fy=/^([+-])=\s*(-?[\d.]+)$/,gy=/^([<>])\s*(?:([+-])?=?\s*(-?[\d.]+))?$/;function Ss(t,e){const n=e.scale??1,s=c=>Number.parseFloat(c)*n;if(t===void 0)return e.cursor;if(typeof t=="number")return t*n;const i=t.trim();if(i==="")return e.cursor;const o=fy.exec(i);if(o){const c=s(o[2]);return e.cursor+(o[1]==="-"?-c:c)}const r=gy.exec(i);if(r){const c=r[1]==="<"?e.previousStart:e.previousEnd;if(r[3]===void 0)return c;const h=s(r[3]);return c+(r[2]==="-"?-h:h)}const a=/^(.+?)([+-])=\s*(-?[\d.]+)$/.exec(i);if(a){const c=e.labels.get(a[1].trim());if(c!==void 0){const h=s(a[3]);return c+(a[2]==="-"?-h:h)}}const l=e.labels.get(i);return l!==void 0?l:/^-?[\d.]+$/.test(i)?s(i):e.cursor}function py(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 my(t,e,n={}){if(t===0)return[];const s=e.grid==="auto"?Math.max(1,Math.min(t,n.columnsFromLayout?.()??t)):Array.isArray(e.grid)?Math.max(1,e.grid[1]):t,i=Array.isArray(e.grid)?Math.max(1,e.grid[0]):Math.ceil(t/s),o=p=>({x:p%s,y:Math.floor(p/s)}),r=e.from??"start",a=Array.isArray(r)?{x:r[0]*(s-1),y:r[1]*(i-1)}:typeof r=="number"?o(Math.max(0,Math.min(t-1,r))):r==="end"?o(t-1):r==="center"||r==="edges"?{x:(s-1)/2,y:(i-1)/2}:{x:0,y:0},l=p=>{const{x:g,y:m}=o(p),w=Math.abs(g-a.x),v=Math.abs(m-a.y);return e.axis==="x"?w:e.axis==="y"?v:Math.hypot(w,v)};let c=Array.from({length:t},(p,g)=>l(g));const h=Math.max(...c);if(r==="edges"&&(c=c.map(p=>h-p)),r==="random"){const p=n.random??Math.random;c=c.map(()=>p()*h)}const u=e.amount!==void 0?e.amount:(e.each??0)*h,d=e.ease?Ms(e.ease):void 0,f=d?d.fn??Lt(d.easing):void 0;return c.map(p=>{const g=h===0?0:p/h;return(f?f(g):g)*u})}const Wr=new Set(["duration","delay","ease","repeat","repeatDelay","yoyo","stagger","onComplete","onUpdate","onStart","onRepeat","onReverseComplete","repeatRefresh","keyframes","easeEach","scrollTo","id","immediateRender","overwrite","paused","scrollTrigger","spring"]),yy={rotation:"rotate",rotationZ:"rotate",rotationX:"rotateX",rotationY:"rotateY",transformPerspective:"perspective",perspective:"childPerspective"};function Pi(t){const e={},n={};for(const[s,i]of Object.entries(t))Wr.has(s)?e[s]=i:n[yy[s]??s]=i;return{config:e,properties:n}}function $i(t,e){return t===void 0?e:t*1e3}function Br(t,e){if(t!==void 0)return typeof t=="number"?{each:t*1e3}:py(t)?{offsets:my(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 by={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 qh(t){return by[t]}function wy(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=Ih(e.path,{curviness:e.curviness});else if(Tn(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 ky(t){const e=typeof t=="string"||Array.isArray(t)?{path:t}:{...t};return{...e,start:e.end??1,end:e.start??0}}function Yh(t){return typeof t=="object"&&t!==null&&"shape"in t?t.shape:t}function vy(t){if(t.morphSVG===void 0)return t;const{morphSVG:e,...n}=t,s=Yh(e);if(typeof s!="string"||!Tn(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 My(t,e){if(t===!0)return[0,e];if(t===!1)return[0,0];if(typeof t=="number")return[0,jh(t,e)];const n=t.trim().split(/[\s,]+/).filter(Boolean),s=r=>{const a=Number.parseFloat(r);if(Number.isNaN(a))throw new Error(`gsap-compat: drawSVG "${t}" is not a length or percentage`);return jh(r.endsWith("%")?e*a/100:a,e)};if(n.length===0)return[0,e];if(n.length===1)return[0,s(n[0])];const i=s(n[0]),o=s(n[1]);return i<=o?[i,o]:[o,i]}function Sy(t,e){const[n,s]=My(t,e);return{strokeDasharray:[s-n,e],strokeDashoffset:-n}}function Ty(t,e){if(t.drawSVG===void 0)return t;const{drawSVG:n,...s}=t;return{...s,...Sy(n,e)}}function xy(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 jh(t,e){return Math.max(0,Math.min(e,t))}function Ey(t){let e=2166136261;for(let n=0;n<t.length;n++)e=Math.imul(e^t.charCodeAt(n),16777619);return e>>>0}function Ay(t,e,n){if(t.scrambleText!==void 0){const s=t.scrambleText,i=typeof s=="string"?{text:s}:s;if(typeof i?.text!="string")throw new Error("gsap-compat: scrambleText needs the text to end on — a string, or { text }.");const o=i.revealDelay&&n>0?i.revealDelay*1e3/n:void 0;return{to:i.text,mode:"scramble",...i.chars!==void 0&&{chars:i.chars},...i.speed!==void 0&&{refreshRate:20*i.speed},...o!==void 0&&{revealDelay:Math.min(o,.999)},...i.tweenLength!==void 0&&{tweenLength:i.tweenLength},...i.rightToLeft!==void 0&&{rightToLeft:i.rightToLeft},seed:i.seed??Ey(`${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 zr(t){return Math.max(.1,t/25)}function Py(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?zr(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(us(i))]:n.end!==void 0&&(i.end=Array.isArray(n.end)?[...n.end]:n.end),i}function $y(t){const e=t===!0?{}:typeof t=="string"?{preset:t}:t;if(e.preset!==void 0&&!(e.preset in di))throw new Error(`gsap-compat: unknown spring preset "${e.preset}" — use one of ${Object.keys(di).join(", ")}`);return{...e.preset?di[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 Iy(t,e){if(t===!0||typeof t=="string")return;const n=t.velocity;return typeof n=="number"?n:n?.[e]}class en{timeline;options;cursor=0;fallbackRandom=Dr(1);previousStart=0;previousEnd=0;labels=new Map;trackCounter=0;lastValues=new Map;constructor(e={}){this.options=e,this.timeline=new It({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,Ts(n),s)}from(e,n,s){const{config:i,properties:o}=Pi(Ts(n)),{motionPath:r,text:a,scrambleText:l,...c}=o,h=this.targetsOf(e)[0],u={...i};for(const p of Object.keys(c))u[p]=this.resolveStart(h,p);r!==void 0&&(u.motionPath=ky(r));const d={},f=String(this.resolveStart(h,"text"));return a!==void 0&&(d.text=qr(a),u.text=typeof a=="object"?{...a,value:f}:f),l!==void 0&&(d.text=qr(l),u.scrambleText=typeof l=="object"?{...l,text:f}:f),this.build(e,{...c,...d},u,s)}fromTo(e,n,s,i){const{properties:o}=Pi(Ts(n));return this.build(e,o,Ts(s),i)}set(e,n,s){return this.build(e,void 0,{...Ts(n),duration:0},s)}get lastStart(){return this.previousStart}get lastEnd(){return this.previousEnd}addEvent(e){const n=Math.max(0,Ss(e,this.context()));return this.previousStart=n,this.previousEnd=n,this.cursor=Math.max(this.cursor,n),n}timeOf(e){return Ss(e,this.context())}addLabel(e,n){return this.labels.set(e,Ss(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=Ss(n,this.context());for(const o of e.timeline.tracks){if(!("keyframes"in o))continue;const r=bi({...o,id:this.nextTrackId(`nested-${o.id}`),keyframes:o.keyframes.map(a=>({...a,time:a.time+s}))});this.timeline.addTrack(r)}const i=s+e.timeline.duration;return this.previousStart=s,this.previousEnd=i,this.cursor=Math.max(this.cursor,i),this}play(){return this.timeline.play(),this}pause(){return this.timeline.pause(),this}restart(){return this.timeline.stop(),this.timeline.play(),this}reverse(){return this.timeline.reverse(),this}kill(){return this.timeline.removeTracks(),this}reset(){return this.timeline.removeTracks(),this.cursor=0,this.previousStart=0,this.previousEnd=0,this.labels.clear(),this.lastValues.clear(),this.trackCounter=0,this}seek(e){if(typeof e=="string"){const n=this.labels.get(e);return n!==void 0&&this.timeline.seek(n),this}return this.timeline.seek(e*1e3),this}progress(e){const n=this.timeline.duration;return e!==void 0&&n>0&&this.timeline.seek(e*n),n>0?this.timeline.currentTime/n:0}timeScale(e){return e!==void 0&&(this.timeline.speed=e),this.timeline.speed}duration(){return this.timeline.duration/1e3}tick(e){return this.timeline.tick(e),this}toDefinition(){return this.timeline.toDefinition()}build(e,n,s,i){const{config:o,properties:r}=Pi(s),{motionPath:a,text:l,scrambleText:c,inertia:h,...u}=r,d=this.targetsOf(e),f=Ss(i,this.context()),p=$i(o.delay,0),g=$i(o.duration,500),m=Br(o.stagger,{count:d.length,columnsFromLayout:this.options.layoutColumns?()=>this.options.layoutColumns(d):void 0,random:this.options.random??this.fallbackRandom}),w=this.easingFor(o.ease),v=[],k=o.spring;let b=0,E=!1;for(const[I,A]of Object.entries(u)){const _=A;let C=n?.[I]!==void 0?n[I]:this.resolveStart(d[0],I);if(typeof C!=typeof _&&(this.warn(`no usable start value for "${I}" on "${d[0]}" — it will snap to ${String(_)}. Use fromTo() to animate it.`),C=_),k!==void 0&&(typeof C!="number"||typeof _!="number")&&this.warn(`spring works on numbers, so "${I}" on "${d[0]}" eases instead`),k!==void 0&&typeof C=="number"&&typeof _=="number"){const G={...$y(k),from:C,to:_,velocity:Iy(k,I)??this.options.startVelocity?.(d[0],I)??0},Z=this.nextTrackId(`${d[0]}-${I}-spring`),Y={id:Z,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:I,kind:"spring",spring:G,delay:f+p};this.timeline.addTrack(Y),v.push(Z),b=Math.max(b,Sc(G));for(const L of d)this.lastValues.set(`${L}|${I}`,_);continue}E=!0;const N=this.keyframesFor(C,_,g,w,o.ease),B=this.nextTrackId(`${d[0]}-${I}`);this.timeline.addTrack(bi({id:B,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:I,delay:f+p,keyframes:N,...I==="quaternion"&&{interpolation:"slerp"}})),v.push(B);for(const G of d)this.lastValues.set(`${G}|${I}`,_)}const $=Ay({text:l,scrambleText:c},d[0],g);if($){const I=n?.text??n?.scrambleText,A=I!==void 0?qr(I):this.resolveStart(d[0],"text"),_=this.nextTrackId(`${d[0]}-text`),C={id:_,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:"text",textConfig:{from:typeof A=="string"?A:String(A??""),...$},delay:f+p,keyframes:this.keyframesFor(0,1,g,w,o.ease)};this.timeline.addTrack(C),v.push(_);for(const N of d)this.lastValues.set(`${N}|text`,$.to)}if(a!==void 0){const{config:I,start:A,end:_}=wy(a),C=this.nextTrackId(`${d[0]}-motionPath`),N={id:C,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:"motionPath",motionPathConfig:I,delay:f+p,keyframes:this.keyframesFor(A,_,g,w,o.ease)};this.timeline.addTrack(N),v.push(C)}if(h!==void 0)for(const[I,A]of Object.entries(h)){const _=this.resolveStart(d[0],I);if(typeof _!="number"){this.warn(`inertia on "${I}" needs a numeric start value; skipped`);continue}const C=Py(_,A),N=this.nextTrackId(`${d[0]}-${I}-inertia`),B={id:N,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:I,kind:"inertia",inertia:C,delay:f+p};this.timeline.addTrack(B),v.push(N),b=Math.max(b,Mn(C));for(const G of d)this.lastValues.set(`${G}|${I}`,vn(C))}const M=((h!==void 0||k!==void 0)&&!E&&!$&&a===void 0?b:Math.max(g,b))+(m&&d.length>1?cs(d.length,m):0),T=f+p+M;return this.previousStart=f+p,this.previousEnd=T,this.cursor=Math.max(this.cursor,T),{trackIds:v,start:f+p,end:T,kill:()=>{for(const I of v)this.timeline.removeTrack(I)}}}keyframesFor(e,n,s,i,o){const r={time:0,value:e};if(s<=0)return[{time:0,value:n}];const a=typeof o=="string"?Ms(o):void 0;if(a?.requiresBaking==="custom"||this.options.bakeEases&&ls(i)){const c=a?.fn??Lt(i);return[r,...Mr(r,{time:s,value:n},c,{intervalMs:this.options.bakeIntervalMs})]}return[r,{time:s,value:n,...i&&{easing:i}}]}resolveStart(e,n){const s=this.lastValues.get(`${e}|${n}`);if(s!==void 0)return s;const i=this.options.startValue?.(e,n);if(i!==void 0)return i;const o=this.options.defaults?.[n];if(o!==void 0)return o;if(n==="text")return"";if(n==="quaternion")return[0,0,0,1];if(n==="d")throw new Error(`gsap-compat: no starting shape for "${e}". Use fromTo({ d: … }, { morphSVG: … }), or live.to(), which reads the element's current shape.`);const r=qh(n);return r!==void 0?(this.warn(`no start value for "${n}" on "${e}" — using the static default ${r}. GSAP would read the live DOM here; tinyfly cannot, so pass an explicit fromTo() or a defaults map.`),r):(this.warn(`no start value or default for "${n}" on "${e}" — using 0`),0)}easingFor(e){if(e!==void 0){if(typeof e=="string")return Ms(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 qr(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 Oy(t){return new en(t)}function Ts(t){return xy(vy(t))}function _y(t){return!Array.isArray(t)||t.length!==4?null:`matrix3d(${re(Ie(t)).map(n=>Math.round(n*1e6)/1e6+0).join(", ")})`}const Cy=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),Hy="#ffffff",Ry="rgba(0, 0, 0, 0.5)";function Ly(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??Hy})`),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??Ry})`)}return e.length>0?e.join(" "):null}function Ny(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 Fy(t){if(!("ownerSVGElement"in t))return;const e=t.style;!e||e.transformBox||(e.transformBox="fill-box",e.transformOrigin||(e.transformOrigin="50% 50%"))}const Kh=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"]),Dy=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),Wy=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],By=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),zy=new Set(["originX","originY"]),qy=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Yy=new Set(["drawOn"]),jy={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},Xh={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},Ky="http://www.w3.org/2000/svg";class nn{targets=new Map;registerTarget(e,n){this.targets.set(e,n)}unregisterTarget(e){this.targets.delete(e)}getTarget(e){return this.targets.get(e)}clearTargets(){this.targets.clear()}applyState(e){for(const[n,s]of e.values){const i=this.targets.get(n);i&&this.applyProperties(i,s)}}applyProperties(e,n){let s=null,i=null,o=null,r=null,a=null;const l=n.has("motionPathX"),c=n.has("motionPathY"),h=n.has("motionPathRotate");for(const[p,g]of n)if(!(p==="x"&&l)&&!(p==="y"&&c)&&!((p==="rotate"||p==="rotateZ")&&h)&&!Yy.has(p)){if(Dy.has(p))(s??={})[p]=g;else if(By.has(p))typeof g=="number"&&((i??={})[p]=g);else if(zy.has(p))typeof g=="number"&&((o??={})[p]=g);else if(qy.has(p))typeof g=="number"&&((r??={})[p]=g);else if(Cy.has(p))(a??={})[p]=g;else if(p!=="perspective"){if(p!=="shine")if(p==="text"&&typeof g=="string")Ny(e,g);else if(p==="d"&&typeof g=="string"){const m=e;(m.tagName?.toLowerCase()==="path"?m:m.querySelector?.("path"))?.setAttribute?.("d",g)}else this.applyStyleProperty(e,p,g)}}const u=n.get("shine");typeof u=="number"&&this.applyShine(e,u);const d=[],f=n.get("perspective");if(typeof f=="number"&&f>0&&d.push(`perspective(${f}px)`),s)for(const p of Wy){const g=s[p];if(g===void 0)continue;const m=this.buildTransformPart(p,g);m&&d.push(m)}if(d.length>0&&(e.style.transform=d.join(" "),Fy(e)),i&&(i.childPerspective!==void 0&&(e.style.perspective=`${i.childPerspective}px`),(i.perspectiveOriginX!==void 0||i.perspectiveOriginY!==void 0)&&(e.style.perspectiveOrigin=`${i.perspectiveOriginX??50}% ${i.perspectiveOriginY??50}%`)),o){const p=o.originX??50,g=o.originY??50;e.style.transformOrigin=`${p}% ${g}%`}if(r){const p=r.clipTop??0,g=r.clipRight??0,m=r.clipBottom??0,w=r.clipLeft??0;e.style.clipPath=`inset(${p}% ${g}% ${m}% ${w}%)`}if(a){const p=Ly(a);p&&(e.style.filter=p)}}buildTransformPart(e,n){if(e==="quaternion")return _y(n);if(typeof n!="number")return null;switch(e){case"x":case"motionPathX":return`translateX(${n}px)`;case"y":case"motionPathY":return`translateY(${n}px)`;case"z":return`translateZ(${n}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${n}deg)`;case"rotateX":return`rotateX(${n}deg)`;case"rotateY":return`rotateY(${n}deg)`;case"scale":return`scale(${n})`;case"scaleX":return`scaleX(${n})`;case"scaleY":return`scaleY(${n})`;case"scaleZ":return`scaleZ(${n})`;case"skewX":return`skewX(${n}deg)`;case"skewY":return`skewY(${n}deg)`;default:return null}}applyShine(e,n){e.dataset.shineBase||(e.dataset.shineBase=e.style.color||"currentColor");const s=e.dataset.shineBase,i=-20+n*140,o=e.style;o.color="transparent",o.backgroundImage=`linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${s}, ${s})`,o.backgroundSize="250% 100%, 100% 100%",o.backgroundPosition=`${i}% 0, 0 0`,o.backgroundRepeat="no-repeat",o.webkitBackgroundClip="text",o.backgroundClip="text"}applyStyleProperty(e,n,s){let i;if(e.namespaceURI===Ky&&n in Xh){const a=Array.isArray(s)?s.join(", "):String(s);e.style[Xh[n]]=a;return}else n==="fill"&&e.dataset?.elementType==="text"?i="color":i=jy[n]??n;let r;typeof s=="number"?Kh.has(n)||Kh.has(i)?r=`${s}px`:r=String(s):Array.isArray(s)?r=s.join(", "):r=s,e.style[i]=r}}const Xy={request:t=>requestAnimationFrame(t),cancel:t=>cancelAnimationFrame(t)};class Gh{adapter=new nn;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=uy();active=new Map;applied=new Map;dirty=new Set;frameId=null;lastTimestamp=null;destroyed=!1;constructor(e={}){this.scheduler=e.scheduler??Xy,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);Yr(s)&&this.currentCollector?.touch(s,i),n.push(i)}return n}query(e){return this.selectorRoot.querySelector(e)}get collector(){return this.currentCollector}setCollector(e){this.currentCollector=e}forget(e){this.applied.delete(e),this.dirty.delete(e)}get selectorRoot(){return this.currentCollector?.scope??this.root}elementFor(e){return this.elements.get(e)}objectFor(e){return this.objects.get(e)}appliedValue(e,n){return this.applied.get(e)?.get(n)}velocityOf(e,n){for(const i of[...this.active.keys()].reverse()){if(i.getTracks({target:e,property:n}).length===0)continue;const o=i.currentTime;if(o<4)return 0;const r=i.getStateAtTime(o).values.get(e)?.get(n),a=i.getStateAtTime(o-4).values.get(e)?.get(n);if(typeof r!="number"||typeof a!="number")return;const l=(r-a)/4;return(i.direction==="reverse"?-l:l)*1e3}}ticker={add:e=>{this.destroyed||(this.tickerCallbacks.size===0&&(this.tickerTime=0,this.tickerFrame=0),this.tickerCallbacks.add(e),this.currentCollector?.track({revert:()=>this.ticker.remove(e)}),this.startLoop())},remove:e=>{this.tickerCallbacks.delete(e),this.running||this.stopLoop()}};activate(e,n={}){this.destroyed||(e.onUpdate=s=>this.write(s),this.active.delete(e),this.active.set(e,n),this.startLoop())}deactivate(e){this.active.delete(e),this.running||this.stopLoop()}own(e){return this.destroyed?e.destroy():this.owned.add(e),e}destroy(){this.destroyed=!0;for(const e of this.owned)e.destroy();this.owned.clear();for(const e of this.active.keys())e.stop();this.active.clear(),this.stopLoop(),this.adapter.clearTargets(),this.elements.clear(),this.names=new WeakMap,this.objects.clear(),this.objectNames=new WeakMap,this.tickerCallbacks.clear(),this.liveTimelines.clear(),this.applied.clear(),this.dirty.clear()}apply(e,n){if(this.destroyed)return;const s=new Map(Object.entries(n));this.write({values:new Map([[e,s]]),currentTime:0,playbackState:"idle",direction:"forward",loopIteration:0}),this.flush()}render(e){this.destroyed||(this.write(e.getStateAtTime(e.currentTime)),this.flush())}tick(e){const n=[...this.active];for(const[s]of n)s.duration<=0?(this.write(s.getStateAtTime(0)),s.stop()):s.tick(e);this.flush();for(const[s,i]of n)i.onUpdate?.(),s.playbackState!=="playing"&&this.active.get(s)===i&&this.active.delete(s);this.flush(),this.runTicker(e),this.running||this.stopLoop()}get running(){return this.active.size>0||this.tickerCallbacks.size>0}runTicker(e){if(this.tickerCallbacks.size!==0){this.tickerTime+=e,this.tickerFrame+=1;for(const n of[...this.tickerCallbacks])n(this.tickerTime/1e3,e,this.tickerFrame)}}write(e){for(const[n,s]of e.values){let i=this.applied.get(n);i||(i=new Map,this.applied.set(n,i));for(const[o,r]of s)i.set(o,r);this.dirty.add(n)}}flush(){if(this.dirty.size===0)return;const e=new Map;for(const n of this.dirty){const s=this.applied.get(n),i=this.objects.get(n);if(i)for(const[o,r]of s)i[o]=r;else e.set(n,s)}this.dirty.clear(),e.size!==0&&this.adapter.applyState({values:e,currentTime:0,playbackState:"playing",direction:"forward",loopIteration:0})}frame=e=>{this.frameId=null;const n=this.lastTimestamp===null?0:e-this.lastTimestamp;this.lastTimestamp=e,n>0&&this.tick(n),this.running&&this.frameId===null&&(this.frameId=this.scheduler.request(this.frame))};startLoop(){this.frameId===null&&(this.lastTimestamp=null,this.frameId=this.scheduler.request(this.frame))}stopLoop(){this.frameId!==null&&this.scheduler.cancel(this.frameId),this.frameId=null,this.lastTimestamp=null}targetsOf(e){if(typeof e=="string")return Array.from(this.selectorRoot.querySelectorAll(e));if(Yr(e))return[e];if(!Gy(e))return[e];const n=[];for(const s of Array.from(e))n.push(...this.targetsOf(s));return n}nameFor(e){return Yr(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 Yr(t){return typeof t=="object"&&t!==null&&t.nodeType===1}function Gy(t){if(Array.isArray(t))return!0;const e=t;return typeof e.length=="number"&&typeof e.item=="function"}function Ii(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 Uh=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function Uy(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function Vy(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 Jy(t,e){const n=typeof t=="string"||Array.isArray(t)||Uh(t)?{path:t}:t,{align:s,alignOrigin:i,path:o,...r}=n,a=$=>{const S=Uh($)?$:e.query($);return S||e.warn(`gsap-compat: motionPath could not find "${String($)}"`),S};let l=null,c="";if(Array.isArray(o)||typeof o=="string"&&Tn(o))c=o;else{l=a(o);const $=l&&ki({tag:l.localName,attributes:Uy(l)});l&&!$&&e.warn(`gsap-compat: motionPath element <${l.localName}> has no path geometry`),c=$??""}const h={...r,path:c};if(s===void 0||s===!1)return h;const u=s===!0?l:a(s);if(!u)return s===!0&&e.warn("gsap-compat: motionPath align: true needs the path to be an element"),h;const d=e.targets[0];if(!d)return h;const[f,p,g,m,w,v]=Vy(u),k=Ii(d),[b,E]=i??[.5,.5];for(const $ of e.targets.slice(1)){const S=Ii($);if(Math.abs(S.left-k.left)>.5||Math.abs(S.top-k.top)>.5){e.warn("gsap-compat: motionPath align measures the first target; the others are laid out elsewhere");break}}return h.matrix=[f,p,g,m,w-k.left-b*k.width,v-k.top-E*k.height],h}const Vh=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function Jh(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function Zh(t){if(!t)return null;const e=ki({tag:t.localName,attributes:Jh(t)});return e||(t.querySelector("path")?.getAttribute("d")??null)}function Zy(t,e,n){const s=Yh(t);if(typeof s=="string"&&Tn(s))return s;const i=Vh(s)?s:typeof s=="string"?e(s):null,o=Zh(i);return o||(n(`gsap-compat: morphSVG could not find a shape for "${String(s)}"`),"")}const Qy=new Set(["cx","cy","r","rx","ry","x","y","width","height","x1","y1","x2","y2","points"]);function tb(t,e=document){return(typeof t=="string"?Array.from(e.querySelectorAll(t)):Vh(t)?[t]:Array.from(t)).map(s=>{if(s.localName==="path")return s;const i=ki({tag:s.localName,attributes:Jh(s)});if(!i||!s.parentNode)return s;const o=s.ownerDocument.createElementNS("http://www.w3.org/2000/svg","path");for(const r of Array.from(s.attributes))Qy.has(r.name)||o.setAttribute(r.name,r.value);return o.setAttribute("d",i),s.parentNode.replaceChild(o,s),o})}const Qh=.3;class t0{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=e0(),this.options.onPress?.(this.stateFrom(0,0,s))}move(e,n,s){if(!this.dragging)return;const i=e-this.lastX,o=n-this.lastY;this.lastX=e,this.lastY=n;const r=e-this.startX,a=n-this.startY,l=this.options.tolerance??3;if(!this.passedTolerance){if(Math.hypot(r,a)<l)return;this.passedTolerance=!0}this.updateVelocity(i,o),this.options.preventDefault!==!1&&s.cancelable&&s.preventDefault(),this.options.onMove?.(this.stateFrom(i,o,s))}end(e){this.dragging&&(this.dragging=!1,this.options.onRelease?.(this.stateFrom(0,0,e)))}updateVelocity(e,n){const s=e0(),i=Math.max(1,s-this.lastTime);this.lastTime=s;const o=e/i*1e3,r=n/i*1e3;this.velocityX+=(o-this.velocityX)*Qh,this.velocityY+=(r-this.velocityY)*Qh}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 e0(){return typeof performance<"u"?performance.now():Date.now()}function n0(t,e,n){let s={delta:0,line:null},i=n;for(const o of t)for(const r of e){const a=Math.abs(r-o);a<=i&&(i=a,s={delta:r-o,line:r})}return s}function s0(t,e){return e<=0?[]:t.map(n=>Math.round(n/e)*e)}class jr{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 t0({target:e.target,onPress:n=>{const s=e.getPosition?.();s&&(this.x=s.x,this.y=s.y),this.originX=this.x,this.originY=this.y,e.onPress?.(n)},onMove:n=>this.handleMove(n),onRelease:n=>e.onRelease?.(n)})}start(){this.observer.start()}stop(){this.observer.stop()}destroy(){this.observer.destroy()}get position(){return{x:this.x,y:this.y}}get velocity(){return this.observer.velocity}setPosition(e,n){const s=this.options.axis??"both";this.x=s==="y"?this.x:this.applyConstraints(e,"x"),this.y=s==="x"?this.y:this.applyConstraints(n,"y")}get snapLines(){return{x:this.snappedX,y:this.snappedY}}snapThreshold(){if(this.options.snapThreshold!==void 0)return this.options.snapThreshold;const e=this.options.snap??0;return e>0?e/2:8}handleMove(e){this.setPosition(this.originX+e.totalX,this.originY+e.totalY),this.options.mode==="scrub"&&this.scrub(),this.options.onDrag?.(this.position,e),this.options.onSnap?.(this.snapLines)}scrub(){const e=this.options.timeline;if(!e)return;const n=e.duration;if(n<=0)return;const s=this.options.scrubDistance??500;if(s===0)return;const i=(this.options.axis??"both")==="y"?this.y:this.x,o=eb(i/s);e.pause(),e.seek(o*n)}applyConstraints(e,n){let s=e;const i=[...s0([s],this.options.snap??0),...(n==="x"?this.options.snapLinesX:this.options.snapLinesY)??[]],o=n0([s],i,this.snapThreshold());s+=o.delta,n==="x"?this.snappedX=o.line:this.snappedY=o.line;const r=this.options.bounds;if(r){const a=n==="x"?r.minX:r.minY,l=n==="x"?r.maxX:r.maxY;a!==void 0&&(s=Math.max(a,s)),l!==void 0&&(s=Math.min(l,s))}return s}}function eb(t){return t<0?0:t>1?1:t}function nb(t){const e=new jr(t);return e.start(),e}const sb={x:"x",y:"y","x,y":"both"},Kr=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function i0(t,e){const n=Ii(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 o0(t){return Array.isArray(t)?[...t]:t}function ib(t,e,n,s={}){const[i]=e.resolveTargets(n),o=i?e.elementFor(i):void 0;if(!i||!o)throw new Error(`gsap-compat: live.draggable could not find ${String(n)}`);if(s.type==="rotation")return ob(t,e,i,o,s);const r=sb[s.type??"x,y"],a=()=>{const g=e.appliedValue(i,"x"),m=e.appliedValue(i,"y");return{x:typeof g=="number"?g:0,y:typeof m=="number"?m:0}},l=typeof s.bounds=="string"?e.query(s.bounds):Kr(s.bounds)?s.bounds:null,h={bounds:(!l&&s.bounds&&!Kr(s.bounds)?s.bounds:void 0)??(l?i0(o,l):void 0)};let u=null;const d=()=>{u?.kill(),u=null},f=g=>{const m=s.inertia===!0?{}:s.inertia,w=m.friction??(m.resistance!==void 0?zr(m.resistance):4),v=a(),k=h.bounds??{};let b,E;const $=m.end;if(Array.isArray($)){const x=us({from:v.x,velocity:r==="y"?0:g.x,friction:w}),M=us({from:v.y,velocity:r==="x"?0:g.y,friction:w});let T=$[0];for(const I of $)Math.hypot(I.x-x,I.y-M)<Math.hypot(T.x-x,T.y-M)&&(T=I);T&&(b=[T.x],E=[T.y])}else typeof $=="number"?(b=$,E=$):$&&(b=o0($.x),E=o0($.y));const S={};r!=="y"&&(S.x={velocity:g.x,friction:w,min:k.minX,max:k.maxX,end:b}),r!=="x"&&(S.y={velocity:g.y,friction:w,min:k.minY,max:k.maxY,end:E}),u=t.to(o,{inertia:S,onComplete:()=>s.onThrowComplete?.()})},p=new jr({target:o,axis:r,snap:s.snap,get bounds(){return h.bounds},getPosition:a,onPress:()=>{d(),l&&(h.bounds=i0(o,l)),s.onPress?.()},onDrag:g=>{e.apply(i,r==="x"?{x:g.x}:r==="y"?{y:g.y}:{x:g.x,y:g.y}),s.onDrag?.(g)},onRelease:()=>{const g=p.velocity;s.onRelease?.(g),s.inertia&&f(g)}});return p.start(),{draggable:p,get position(){return a()},get rotation(){const g=e.appliedValue(i,"rotate");return typeof g=="number"?g:0},destroy(){d(),p.destroy()}}}function ob(t,e,n,s,i){const o=typeof i.bounds=="object"&&i.bounds!==null&&!Kr(i.bounds)?i.bounds:{},r=()=>{const k=e.appliedValue(n,"rotate");return typeof k=="number"?k:0},a=k=>Math.min(o.maxRotation??1/0,Math.max(o.minRotation??-1/0,k));let l=null,c=!1,h,u={x:0,y:0},d=0,f=0,p=[];const g=k=>Math.atan2(k.clientY-u.y,k.clientX-u.x)*180/Math.PI,m=k=>{if(c)return;l?.kill(),l=null,c=!0,h=k.pointerId,s.setPointerCapture?.(k.pointerId);const b=s.getBoundingClientRect();u={x:b.left+b.width/2,y:b.top+b.height/2},d=g(k),f=r(),p=[{time:performance.now(),rotation:f}],i.onPress?.()},w=k=>{if(!c||k.pointerId!==h)return;const b=g(k);let E=b-d;E>180&&(E-=360),E<-180&&(E+=360),d=b,f+=E;let $=a(f);i.snap&&($=a(Math.round($/i.snap)*i.snap)),e.apply(n,{rotate:$});const S=performance.now();for(p.push({time:S,rotation:$});p.length>2&&S-p[0].time>100;)p.shift();const x={x:0,y:0};i.onDrag?.(x)},v=k=>{if(!c||k.pointerId!==h)return;c=!1;const b=p[0],E=p[p.length-1],$=b&&E?(E.time-b.time)/1e3:0,S=$>0?(E.rotation-b.rotation)/$:0;if(i.onRelease?.({x:S,y:0}),!i.inertia)return;const x=i.inertia===!0?{}:i.inertia,M=x.friction??(x.resistance!==void 0?zr(x.resistance):4),T=typeof x.end=="number"||Array.isArray(x.end)?x.end:void 0;l=t.to(s,{inertia:{rotate:{velocity:S,friction:M,min:o.minRotation,max:o.maxRotation,end:Array.isArray(T)?T.filter(I=>typeof I=="number"):T}},onComplete:()=>i.onThrowComplete?.()})};return s.addEventListener("pointerdown",m),s.addEventListener("pointermove",w),s.addEventListener("pointerup",v),s.addEventListener("pointercancel",v),s.style.touchAction="none",{draggable:void 0,position:{x:0,y:0},get rotation(){return r()},destroy(){l?.kill(),s.removeEventListener("pointerdown",m),s.removeEventListener("pointermove",w),s.removeEventListener("pointerup",v),s.removeEventListener("pointercancel",v)}}}const rb={opacity:0,scale:.6};function ab(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 r0(t){const e=Ii(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 Xr(t,e){const s=t.resolveTargets(e).map(r=>t.elementFor(r)).filter(r=>!!r),i=new Map,o=new Map;for(const r of s){const a=ab(r);i.set(r,a);const l=a0(r);a&&l!==void 0&&!o.has(l)&&o.set(l,{element:r,box:a})}return{elements:s,boxes:i,ids:o}}const Gr=new WeakMap;function Ur(t,e,n,s={}){const i=s.duration??.6,o=s.ease??"power2.inOut",r=s.stagger??0,a=s.scale!==!1,l=s.enter===void 0?rb:s.enter,c=new Set(n.elements);if(s.targets!==void 0)for(const f of t.resolveTargets(s.targets)){const p=t.elementFor(f);p&&c.add(p)}const h=[...c].sort((f,p)=>f===p?0:f.compareDocumentPosition(p)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1),u=e({onComplete:s.onComplete});let d=0;for(const f of h){const p=r0(f);if(!p)continue;let g=n.boxes.get(f)??null,m;const w=a0(f),v=!g&&w!==void 0?n.ids.get(w):void 0;v&&v.element!==f&&(g=v.box,m=v.element);const[k]=t.resolveTargets(f);Gr.get(f)?.timeline.removeTracks({target:k});const b=d*r;if(!g){if(l===!1)continue;u.fromTo(f,{x:0,y:0,scaleX:1,scaleY:1,...l},{...l0(l),x:0,y:0,scaleX:1,scaleY:1,duration:i,ease:o,delay:b},0),Gr.set(f,u),d++;continue}const E=g.cx-p.cx,$=g.cy-p.cy,S=a?g.width/p.width:1,x=a?g.height/p.height:1;if(!(Math.abs(E)>.5||Math.abs($)>.5||Math.abs(S-1)>.001||Math.abs(x-1)>.001)){const I=(A,_)=>{const C=t.appliedValue(k,A);return typeof C=="number"&&Math.abs(C-_)>1e-6};(I("x",0)||I("y",0)||I("scaleX",1)||I("scaleY",1))&&u.set(f,{x:0,y:0,scaleX:1,scaleY:1},0);continue}const T=s.fade===!0&&m!==void 0;u.fromTo(f,{x:E,y:$,scaleX:S,scaleY:x,...T&&{opacity:0}},{x:0,y:0,scaleX:1,scaleY:1,...T&&{opacity:1},duration:i,ease:o,delay:b},0),T&&m&&r0(m)&&u.fromTo(m,{opacity:1},{opacity:0,duration:i,ease:o,delay:b},0),Gr.set(f,u),d++}return u}function a0(t){return t.dataset?.flipId}function l0(t){const e={};for(const n of Object.keys(t))e[n]=n==="opacity"||n.startsWith("scale")?1:0;return e}function lb(t,e={}){const n=new Set((e.type??"chars,words,lines").split(",").map(g=>g.trim())),s={chars:e.charsClass??"char",words:e.wordsClass??"word",lines:e.linesClass??"line"},i=e.aria!==!1,o=t.map(g=>({element:g,html:g.innerHTML,ariaLabel:g.getAttribute("aria-label")}));let r={chars:[],words:[],lines:[],masks:[]},a,l,c=!1;const h=()=>{for(const{element:g,html:m,ariaLabel:w}of o)g.innerHTML=m,w===null?g.removeAttribute("aria-label"):g.setAttribute("aria-label",w)},u=()=>{a&&(a.revert?a.revert():a.kill?.(),a=void 0)},d=()=>{const g={chars:[],words:[],lines:[],masks:[]};for(const{element:m}of o){const w=(m.textContent??"").replace(/\s+/g," ").trim(),v=cb(m,s.words),k=n.has("chars")?v.flatMap($=>hb($,s.chars)):[],b=n.has("lines")?db(m,v,s.lines):[];if(i){!m.hasAttribute("aria-label")&&w&&m.setAttribute("aria-label",w);for(const $ of v)$.setAttribute("aria-hidden","true")}if(n.has("words"))g.words.push(...v);else for(const $ of v)$.removeAttribute("class");g.chars.push(...k),g.lines.push(...b);const E=e.mask==="lines"?b:e.mask==="words"?v:e.mask==="chars"?k:[];for(const $ of E)g.masks.push(fb($,`${s[e.mask]}-mask`))}r=g},f={elements:t,get chars(){return r.chars},get words(){return r.words},get lines(){return r.lines},get masks(){return r.masks},split(){c||(u(),h(),d(),a=e.onSplit?.(f))},revert(){c=!0,l?.disconnect(),u(),h()}};d(),a=e.onSplit?.(f),e.autoSplit&&p();function p(){const g=new Map;let m=!1;const w=()=>{if(m)return;m=!0;const k=()=>{m=!1,f.split()};typeof requestAnimationFrame=="function"?requestAnimationFrame(k):setTimeout(k,0)};if(typeof ResizeObserver=="function"){l=new ResizeObserver(k=>{let b=!1;for(const E of k){const $=Math.round(E.contentRect.width),S=g.get(E.target);g.set(E.target,$),S!==void 0&&S!==$&&(b=!0)}b&&w()});for(const k of t)l.observe(k)}const v=t[0]?.ownerDocument?.fonts;v&&v.status!=="loaded"&&v.ready.then(()=>w())}return f}function cb(t,e){const n=t.ownerDocument,s=[],i=n.createTreeWalker(t,4),o=[];for(let r=i.nextNode();r;r=i.nextNode())o.push(r);for(const r of o){const a=r.data.match(/\s+|\S+/g)??[];if(a.length===0)continue;const l=n.createDocumentFragment();for(const c of a){if(/^\s/.test(c)){l.appendChild(n.createTextNode(c));continue}const h=n.createElement("span");h.className=e,h.style.display="inline-block",h.textContent=c,l.appendChild(h),s.push(h)}r.replaceWith(l)}return s}function hb(t,e){const n=t.ownerDocument,s=ub(t.textContent??"").map(i=>{const o=n.createElement("span");return o.className=e,o.style.display="inline-block",o.textContent=i,o});return t.replaceChildren(...s),s}function ub(t){const e=Intl.Segmenter;return e?Array.from(new e(void 0,{granularity:"grapheme"}).segment(t),n=>n.segment):Array.from(t)}function db(t,e,n){const s=t.ownerDocument,i=new Map(e.map(p=>[p,p.getBoundingClientRect()])),o=[],r=p=>{for(const g of Array.from(p.childNodes))g.nodeType===3||i.has(g)||g.tagName==="BR"?o.push(g):r(g)};r(t);const a=[];let l=null,c=0,h=0,u=!1,d=[];const f=()=>{l=s.createElement("span"),l.className=n,l.style.display="block",a.push(l),d=[]};for(const p of o){if(p.tagName==="BR"){u=!0;continue}const g=i.get(p);if(g&&(!l||u||g.top>c+h)&&(f(),c=g.top,h=g.height/2,u=!1),!l)continue;const m=[];for(let k=p.parentNode;k&&k!==t;k=k.parentNode)m.unshift(k);let w=0;for(;w<d.length&&w<m.length&&d[w].original===m[w];)w++;d.length=w;let v=w===0?l:d[w-1].clone;for(const k of m.slice(w)){const b=k.cloneNode(!1);v.appendChild(b),d.push({original:k,clone:b}),v=b}v.appendChild(p)}return t.replaceChildren(...a),a}function fb(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 c0={top:0,left:0,start:0,center:.5,centre:.5,middle:.5,bottom:1,right:1,end:1};function Vr(t){const e=t.trim().toLowerCase();if(e in c0)return c0[e];if(e.endsWith("%")){const n=Number.parseFloat(e.slice(0,-1));return Number.isNaN(n)?void 0:n/100}}function Jr(t){if(typeof t=="number")return{elementFraction:0,viewportFraction:0,offsetPx:0,absolutePx:t};let e=0;const s=t.replace(/([+-])=\s*(-?[\d.]+)/g,(r,a,l)=>(e+=(a==="-"?-1:1)*Number.parseFloat(l),"")).trim().split(/\s+/).filter(Boolean);if(s.length===1&&/^-?[\d.]+$/.test(s[0]))return{elementFraction:0,viewportFraction:0,offsetPx:0,absolutePx:Number.parseFloat(s[0])+e};const i=s[0]!==void 0?Vr(s[0]):void 0,o=s[1]!==void 0?Vr(s[1]):void 0;return{elementFraction:i??0,viewportFraction:o??0,offsetPx:e}}function On(t,e,n){const s=Jr(n),i=s.absolutePx!==void 0?t.top+s.absolutePx:t.top+t.height*s.elementFraction,o=e*s.viewportFraction;return i-o+s.offsetPx}function gb(t,e,n,s){const i=On(t,e,n),r=On(t,e,s)-i;return r<=0?i<=0?1:0:Zr(-i/r)}function Zr(t){return t<0?0:t>1?1:t===0?0:t}function h0(t,e,n,s){if(n<=0)return e;const i=1-Math.exp(-(s/1e3)/n);return t+(e-t)*i}function Qr(t,e,n,s,i){const o=h=>On({top:t+i(h),bottom:t+i(h)+e,height:e},n,s),r=o(0),a=o(1);if(Math.sign(r)===Math.sign(a)||r===0||a===0)return r===0?0:a===0?1:Math.abs(r)<Math.abs(a)?0:1;let l=0,c=1;for(let h=0;h<40;h++){const u=(l+c)/2;Math.sign(o(u))===Math.sign(r)?l=u:c=u}return(l+c)/2}class u0{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 pb(t){const e=new u0(t);return e.start(),e}class d0{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 mb=.15;function f0(t){return typeof t=="object"&&!Array.isArray(t)?t:{snapTo:t}}function g0(t,e,n){const s=Oi(t+e*mb);if(typeof n=="function")return Oi(n(s));if(typeof n=="number")return n<=0?t:Oi(Math.round(s/n)*n);if(n.length===0)return t;let i=n[0];for(const o of n)Math.abs(o-s)<Math.abs(i-s)&&(i=o);return Oi(i)}function p0(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 m0{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=ds,o){if(this.cancel(),typeof requestAnimationFrame>"u"||s<=0){this.write(n),o?.();return}for(const l of this.cancelEvents)this.eventTarget?.addEventListener(l,this.onInterrupt,{passive:!0});let r=null;const a=l=>{r??=l;const c=Math.min(1,(l-r)/(s*1e3));this.write(e+(n-e)*i(c)),c<1?this.rafId=requestAnimationFrame(a):(this.rafId=null,this.detach(),o?.())};this.rafId=requestAnimationFrame(a)}cancel(){this.rafId!==null&&typeof cancelAnimationFrame<"u"&&cancelAnimationFrame(this.rafId),this.rafId=null,this.detach()}detach(){for(const e of this.cancelEvents)this.eventTarget?.removeEventListener(e,this.onInterrupt)}}function Oi(t){return Math.max(0,Math.min(1,t))}class y0{options;scroller;nodes=[];scrollerStart;scrollerEnd;start;end;constructor(e,n,s){this.options=s===!0?{}:s,this.scroller=n;const{startColor:i="#3ecf7a",endColor:o="#ff5a5a",id:r}=this.options,a=r?`${r} `:"",l=(c,h,u)=>{const d=e.createElement("div");return d.textContent=`${a}${c}`,d.setAttribute("aria-hidden","true"),d.className="scroll-marker",Object.assign(d.style,{position:u?"fixed":"absolute",right:`${this.options.indent??0}px`,zIndex:"2147483646",pointerEvents:"none",borderTop:`1px solid ${h}`,color:h,font:`${this.options.fontSize??"11px"} ui-monospace, monospace`,padding:"2px 6px",whiteSpace:"nowrap",background:"rgba(0, 0, 0, 0.35)"}),(n??e.body).appendChild(d),this.nodes.push(d),d};this.scrollerStart=l("scroller-start",i,!n),this.scrollerEnd=l("scroller-end",o,!n),this.start=l("start",i,!1),this.end=l("end",o,!1),n&&getComputedStyle(n).position==="static"&&(n.style.position="relative")}place(e,n){this.start.style.top=`${e.startPage}px`,this.end.style.top=`${e.endPage}px`;const s=this.scroller?n:0;this.scrollerStart.style.top=`${s+e.startViewport}px`,this.scrollerEnd.style.top=`${s+e.endViewport}px`}follow(e,n){this.scroller&&this.place(e,n)}destroy(){for(const e of this.nodes.splice(0))e.remove()}}const yb=120,_n=[],Cn=new Set;let ta=!1;const bb=()=>{ta||Cn.size===0||(ta=!0,queueMicrotask(()=>{ta=!1;for(const t of Cn)t.afterRefresh()}))},b0=()=>{for(const t of Cn)t.beforeRefresh();for(const t of _n)t.refresh();for(const t of Cn)t.afterRefresh()};let Hn={width:0,height:0};const w0=()=>{const t=window.innerWidth,e=window.innerHeight,n=t===Hn.width&&e!==Hn.height,s=Math.abs(e-Hn.height)<Hn.height*.25,i=typeof navigator<"u"&&(navigator.maxTouchPoints??0)>0;n&&s&&i||(Hn={width:t,height:e},b0())};class xs{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 m0(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 d0(e,{axis:this.options.horizontal?"x":"y",spacing:this.options.pinSpacing!==!1})),this.options.markers&&!this.options.horizontal&&typeof document<"u"&&(this.markers=new y0(document,this.options.scroller??null,this.options.markers)),this.scrollTarget()?.addEventListener("scroll",this.onScroll,{passive:!0}),_n.length===0&&typeof window<"u"&&(Hn={width:window.innerWidth,height:window.innerHeight},window.addEventListener("resize",w0,{passive:!0})),_n.push(this),this.refresh()}stop(){this.running&&(this.running=!1,this.scrollTarget()?.removeEventListener("scroll",this.onScroll),_n.splice(_n.indexOf(this),1),_n.length===0&&typeof window<"u"&&window.removeEventListener("resize",w0),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(){b0()}static onRefresh(e){return Cn.add(e),()=>Cn.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+On(n,s,Es(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,bb()}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?Zr((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=Es(this.options.end)??"bottom top",o=typeof i=="string"?i.trim().match(/^\+=\s*(-?[\d.]+)\s*(%|px)?$/):null;if(o){const r=Number.parseFloat(o[1]);return this.startPx+(o[2]==="%"?n*r/100:r)}return s+On(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()},yb))}fireBoundaryCallbacks(e,n){if(e===n)return;const{onEnter:s,onLeave:i,onEnterBack:o,onLeaveBack:r}=this.options;e==="before"?(s?.(),n==="after"&&i?.()):e==="after"?(o?.(),n==="before"&&r?.()):n==="after"?i?.():r?.()}scheduleSnap(){const e=this.options.snap;if(e===void 0||this.snapper.active)return;const n=f0(e),s=()=>{this.snapTimer=null;const i=this.endPx-this.startPx,o=this.scrollPosition();if(!this.running||i<=0||o<=this.startPx||o>=this.endPx)return;const r=(o-this.startPx)/i,a=this.startPx+g0(r,this.releaseVelocity/i,n.snapTo)*i;Math.abs(a-o)<1||this.snapper.animate(o,a,p0(n,a-o,this.viewportHeight()),n.ease)};n.delay?this.snapTimer=setTimeout(s,n.delay*1e3):s()}scrollTo(e){const n=this.options.scroller,s=this.options.horizontal?{left:e}:{top:e};n?typeof n.scrollTo=="function"?n.scrollTo({...s,behavior:"instant"}):this.options.horizontal?n.scrollLeft=e:n.scrollTop=e:typeof window<"u"&&window.scrollTo({...s,behavior:"instant"})}measureInContainer(e){const n=this.options.trigger;if(typeof n?.getBoundingClientRect!="function")return;const s=n.getBoundingClientRect(),i=this.options.scroller?.getBoundingClientRect?.().left??0,o=this.options.scroller?this.options.scroller.clientWidth:typeof window<"u"?window.innerWidth:0,r=s.left-i-e.shiftAt(e.progress()),{start:a,end:l}=e.range(),c=f=>a+f*(l-a),h=Qr(r,s.width,o,Es(this.options.start)??"left right",e.shiftAt);this.startPx=c(h);const u=Es(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(Qr(r,s.width,o,u,e.shiftAt)),this.markerGeometry=null}markersFor(e){const n=(o,r)=>{const a=Es(o)??r;if(typeof a=="number")return 0;if(/^\s*\+=/.test(a))return;const l=Jr(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=h0(this.displayProgress,this.targetProgress,this.smoothing(),s);const i=Math.abs(this.targetProgress-this.displayProgress)<1e-4;i&&(this.displayProgress=this.targetProgress),this.applyProgress(),i?this.lastFrameTime=null:this.rafId=requestAnimationFrame(e)};this.rafId=requestAnimationFrame(e)}stopSmoothing(){this.rafId!==null&&typeof cancelAnimationFrame<"u"&&cancelAnimationFrame(this.rafId),this.rafId=null,this.lastFrameTime=null}scrollTarget(){return this.options.scroller??(typeof window<"u"?window:null)}scrollPosition(){const e=this.options.scroller,n=this.options.horizontal;return e?(n?e.scrollLeft:e.scrollTop)??0:typeof window<"u"?(n?window.scrollX:window.scrollY)??0:0}triggerRect(){const e=this.options.trigger;return typeof e?.getBoundingClientRect!="function"?null:this.relativeRect(e.getBoundingClientRect())}relativeRect(e){const n=this.options.horizontal,s=n?e.left??0:e.top,i=n?e.right??0:e.bottom,o=n?e.width??0:e.height,r=this.options.scroller;if(r&&typeof r.getBoundingClientRect=="function"){const a=r.getBoundingClientRect(),l=n?a.left:a.top;return{top:s-l,bottom:i-l,height:o}}return{top:s,bottom:i,height:o}}viewportHeight(){const e=this.options.scroller,n=this.options.horizontal;return e?n?e.clientWidth:e.clientHeight:typeof window<"u"?n?window.innerWidth:window.innerHeight:0}}function Es(t){return typeof t=="function"?t():t}function wb(t){const e=new xs(t);return e.start(),e}const ea=new Set,kb=16,k0=.5,vb=2;class na{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),ea.add(this),this.stopListening=xs.onRefresh({beforeRefresh:()=>this.rest(),afterRefresh:()=>this.refresh()}),this.refresh(),this}static refreshAll(){for(const e of ea)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),ea.delete(this),this.stopListening?.(),this.stopListening=null,this.cancelFrame(),this.journey=null,this}destroy(){this.stop();for(const e of this.effects)sa(e.element,e.saved);this.effects=[]}kill(){this.destroy()}get state(){const e=this.limit();return{scroll:this.current,target:this.target,progress:e>0?this.current/e:0,velocity:this.velocityPxPerSecond}}paused(e){return e!==void 0&&(this.pausedState=e,e&&(this.target=this.current,this.journey=null)),this.pausedState}scrollTo(e,n={}){if(!this.running)return;const s=this.clamp(this.resolve(e)+(n.offset??0)),i=Math.abs(s-this.current),o=this.reduced?0:n.duration??Math.min(1.2,Math.max(.4,i/2500));if(o<=0){this.journey=null,this.current=this.target=s,this.write(s),this.applyEffects(0);return}this.target=s,this.journey={from:this.current,to:s,ms:o*1e3,ease:n.ease??ds,elapsed:0},this.requestFrame()}refresh(){if(!this.running)return;this.rest(),this.effects=[];const e=this.options.effects===!0?"[data-speed], [data-lag]":this.options.effects||"";if(e&&!this.reduced){const n=this.options.scroller??document,s=this.position(),i=this.viewportHeight(),o=this.options.scroller?.getBoundingClientRect().top??0;for(const r of n.querySelectorAll(e)){const a=Number.parseFloat(r.dataset.speed??""),l=Number.parseFloat(r.dataset.lag??""),c=r.getBoundingClientRect(),h=c.top-o+s;this.effects.push({element:r,speed:Number.isFinite(a)?a:void 0,lag:Number.isFinite(l)&&l>0?l:void 0,centre:h+c.height/2-i/2,lagged:s,shift:0,saved:r.style.getPropertyValue("translate")})}}this.current=this.target=this.clamp(this.position()),this.applyEffects(0)}rest(){for(const e of this.effects)sa(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?kb: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)<=vb||(this.written=null,this.journey=null,this.cancelFrame(),this.current=this.target=e,this.requestFrame())}nestedScrollerTakes(e){const n=this.options.scroller??document.documentElement;for(let s=e.target;s&&s!==n&&s!==document.body;s=s.parentElement){if(s.hasAttribute?.("data-smooth-ignore"))return!0;const i=getComputedStyle(s);if(!/(auto|scroll)/.test(i.overflowY)||s.scrollHeight<=s.clientHeight)continue;if(e.deltaY<0?s.scrollTop>0:s.scrollTop+s.clientHeight<s.scrollHeight-1)return!0}return!1}requestFrame(){this.frameId!==null||!this.running||(this.frameId=this.frames.request(e=>this.frame(e)))}cancelFrame(){this.frameId!==null&&this.frames.cancel(this.frameId),this.frameId=null,this.lastTime=null}frame(e){this.frameId=null;const n=this.lastTime===null?1e3/60:Math.min(100,e-this.lastTime);this.lastTime=e;const s=this.current;if(this.journey){const o=this.journey;o.elapsed+=n;const r=Math.min(1,o.elapsed/o.ms);this.current=o.from+(o.to-o.from)*o.ease(r),r>=1&&(this.journey=null)}else if(this.current!==this.target){const o=(this.options.smooth??.8)*1e3/3;this.current+=(this.target-this.current)*(1-Math.exp(-n/o)),Math.abs(this.target-this.current)<k0&&(this.current=this.target)}this.current!==s&&this.write(this.current),this.velocityPxPerSecond=n>0?(this.current-s)*1e3/n:0;const i=this.applyEffects(n);this.current!==s&&this.options.onUpdate?.(this.state),this.journey||this.current!==this.target||i?this.requestFrame():(this.lastTime=null,this.velocityPxPerSecond=0)}applyEffects(e){let n=!1;const s=this.current;for(const i of this.effects){let o=0;if(i.speed!==void 0&&(o+=(s-i.centre)*(1-i.speed)),i.lag!==void 0){const r=i.lag*1e3/3;i.lagged=e===0?s:i.lagged+(s-i.lagged)*(1-Math.exp(-e/r)),Math.abs(s-i.lagged)<k0?i.lagged=s:n=!0,o+=s-i.lagged}sa(i.element,o===0?i.saved:`0 ${Mb(o)}px`),i.shift=o}return n}write(e){const n=Math.round(e);this.written=n;const s=this.options.scroller;s?s.scrollTop=n:window.scrollTo({top:n,behavior:"instant"})}position(){const e=this.options.scroller;return e?e.scrollTop:window.scrollY}viewportHeight(){const e=this.options.scroller;return e?e.clientHeight:window.innerHeight}limit(){const e=this.options.scroller??document.documentElement;return Math.max(0,e.scrollHeight-this.viewportHeight())}clamp(e){return Math.max(0,Math.min(this.limit(),e))}resolve(e){if(typeof e=="number")return e;const n=this.options.scroller??document,s=typeof e=="string"?n.querySelector(e):e;if(!s)return this.current;const i=this.options.scroller?.getBoundingClientRect().top??0,o=this.effects.find(r=>r.element===s)?.shift??0;return s.getBoundingClientRect().top-i+this.position()-o}}function sa(t,e){e?t.style.setProperty("translate",e):t.style.removeProperty("translate")}function Mb(t){return Math.round(t*100)/100}function Sb(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 ia(t,e,n,s,i=()=>{}){const o=f=>typeof f=="string"?t.query(f)??void 0:f,r=o(e.trigger)??s;if(!r){i(`gsap-compat: scrollTrigger has no trigger element${typeof e.trigger=="string"?` for "${e.trigger}"`:""}`);return}const a=e.scrub===void 0||e.scrub===!1?!1:e.scrub,l=(e.toggleActions??"play none none none").trim().split(/\s+/);let c=0,h;const u=(f,p)=>()=>{p?.(),n&&!a&&Sb(n,l[f]??"none"),e.once&&f===0&&queueMicrotask(()=>h.destroy())},d=e.containerAnimation?Eb(t,e.containerAnimation,r,i):void 0;return h=new xs({trigger:r,start:e.start,end:e.end,scrub:a===!1?void 0:a,pin:e.pin===!0?!0:o(e.pin),scroller:o(e.scroller),horizontal:e.horizontal,pinSpacing:e.pinSpacing,onRefresh:e.invalidateOnRefresh&&n?.invalidate?()=>n.invalidate():void 0,snap:e.snap===void 0?void 0:Tb(e.snap,n),markers:e.markers,container:d,onUpdate:(f,p)=>{if(n&&a!==!1&&n.progress(f),e.onUpdate){const g=f<c||p<0?-1:1;e.onUpdate({progress:f,velocity:p,direction:g})}c=f},onEnter:u(0,e.onEnter),onLeave:u(1,e.onLeave),onEnterBack:u(2,e.onEnterBack),onLeaveBack:u(3,e.onLeaveBack)}),n&&a===!1&&n.progress(0),h.start(),t.own(h)}function Tb(t,e){const n=i=>i==="labels"?o=>xb(o,e?.labelProgresses?.()??[]):i;if(typeof t!="object"||Array.isArray(t))return n(t);const s=t.ease?Ms(t.ease):void 0;return{snapTo:n(t.snapTo),duration:t.duration,delay:t.delay,ease:s?s.fn??Lt(s.easing):void 0}}function xb(t,e){return e.reduce((n,s)=>Math.abs(s-t)<Math.abs(n-t)?s:n,e[0]??t)}function Eb(t,e,n,s){const i=()=>e.timeline.getTracks({property:"x"}).map(o=>o.target).filter(o=>{const r=t.elementFor(o);return!!r&&r!==n&&r.contains(n)});return i().length===0&&s("gsap-compat: containerAnimation does not move an ancestor of the trigger along x"),{range:()=>{const o=e.scrollTrigger;return o||s("gsap-compat: containerAnimation needs its own scrollTrigger (created before this one)"),{start:o?.startOffset??0,end:o?.endOffset??0}},progress:()=>e.progress(),shiftAt:o=>{const r=e.timeline.getStateAtTime(o*e.timeline.duration);let a=0;for(const l of i()){const c=r.values.get(l)?.get("x");typeof c=="number"&&(a+=c)}return a}}}class v0{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 Ab{host;scope;entries=[];listeners=[];scheduled=!1;constructor(e,n){this.host=e,this.scope=n}add(e,n){const s={conditions:e,setup:n,queries:new Map},i=typeof e=="string"?{matches:e}:e;if(typeof window<"u"&&typeof window.matchMedia=="function")for(const[o,r]of Object.entries(i)){const a=window.matchMedia(r);s.queries.set(o,a);const l=()=>this.scheduleUpdate();a.addEventListener("change",l),this.listeners.push(()=>a.removeEventListener("change",l))}return this.entries.push(s),this.update(s),this}revert(){for(const e of this.listeners.splice(0))e();for(const e of this.entries.splice(0))e.context?.revert()}kill(){this.revert()}scheduleUpdate(){this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1;for(const e of this.entries)this.update(e)}))}update(e){const n={};for(const[r,a]of e.queries)n[r]=a.matches;const s=Object.values(n).some(Boolean),i=s?JSON.stringify(n):void 0;if(i===e.key||(e.context?.revert(),e.context=void 0,e.key=i,!s))return;const o=new v0(this.host,this.scope);o.conditions=n,o.add(()=>e.setup(o)),e.context=o}}class Pb{frames;canvas;context;options;images;ready;current=0;drawn=-1;loadedCount=0;inFlight=0;destroyed=!1;onResize=()=>this.resize();constructor(e,n){this.canvas=e,this.context=e.getContext("2d"),this.options=n,this.frames=Math.max(1,Math.floor(n.frames)),this.images=new Array(this.frames),this.ready=new Array(this.frames).fill(!1),typeof window<"u"&&window.addEventListener("resize",this.onResize,{passive:!0}),this.resize(),this.pump()}get frame(){return this.current}set frame(e){this.current=Math.max(0,Math.min(this.frames-1,e)),this.draw()}get loaded(){return this.loadedCount}destroy(){this.destroyed=!0,typeof window<"u"&&window.removeEventListener("resize",this.onResize);for(const e of this.images)e&&(e.src="")}resize(){const e=typeof window<"u"?Math.min(window.devicePixelRatio||1,2):1,n=Math.round(this.canvas.clientWidth*e),s=Math.round(this.canvas.clientHeight*e);n>0&&s>0&&(this.canvas.width!==n||this.canvas.height!==s)&&(this.canvas.width=n,this.canvas.height=s),this.drawn=-1,this.draw()}draw(){const e=Math.round(this.current),n=this.nearestReady(e);if(n===-1||n===this.drawn||!this.context)return;const s=this.images[n],{width:i,height:o}=this.canvas,r=(this.options.fit??"cover")==="cover"?Math.max(i/s.naturalWidth,o/s.naturalHeight):Math.min(i/s.naturalWidth,o/s.naturalHeight),a=s.naturalWidth*r,l=s.naturalHeight*r;this.context.clearRect(0,0,i,o),this.context.drawImage(s,(i-a)/2,(o-l)/2,a,l),this.drawn=n,this.pump()}nearestReady(e){for(let n=0;n<this.frames;n++){if(e-n>=0&&this.ready[e-n])return e-n;if(e+n<this.frames&&this.ready[e+n])return e+n}return-1}pump(){const e=this.options.concurrency??6,n=Math.round(this.current);for(let s=0;s<this.frames&&this.inFlight<e;s++)for(const i of s===0?[n]:[n+s,n-s])i<0||i>=this.frames||this.images[i]||this.inFlight>=e||this.load(i)}load(e){const n=new Image;n.decoding="async",this.images[e]=n,this.inFlight++;const s=i=>{if(!this.destroyed){if(this.inFlight--,i){this.ready[e]=!0,this.loadedCount++,this.options.onProgress?.(this.loadedCount,this.frames);const o=Math.round(this.current);(Math.abs(e-o)<Math.abs(this.drawn-o)||this.drawn===-1)&&(this.drawn=-1,this.draw())}this.pump()}};n.onload=()=>s(!0),n.onerror=()=>s(!1),n.src=this.options.url(e)}}const $b={opacity:0,y:-16},Ib={opacity:0,y:16};async function Ob(t,e,n,s){const i=e.collector?.scope??e.root,o=i.ownerDocument??i,r=()=>s.shared?[...i.querySelectorAll(s.shared)]:[];if(s.native&&typeof o.startViewTransition=="function")return _b(o,s,r);const a=s.duration??.35,l=s.ease??"power2.inOut",c=m=>new Promise(w=>{m(w)||w()}),h=r(),u=h.length?Xr(e,h):void 0,d=s.from!==void 0?M0(e,s.from,s.shared):[];if(d.length&&s.leave!==!1){const m=s.leave??$b;await c(w=>t.to(d,{...m,duration:a,ease:l,onComplete:w}))}await s.update();const f=[],p=typeof s.to=="function"?s.to():s.to,g=p!==void 0?M0(e,p,s.shared):[];if(g.length&&s.enter!==!1){const m=s.enter??Ib;f.push(c(w=>t.fromTo(g,m,{...l0(m),duration:a,ease:l,onComplete:w})))}if(u){const m=r().filter(w=>!h.includes(w));m.length&&f.push(c(w=>Ur(e,n,u,{targets:m,duration:a*1.4,ease:l,enter:!1,onComplete:w})))}await Promise.all(f)}function M0(t,e,n){const s=t.resolveTargets(e).map(i=>t.elementFor(i)).filter(i=>!!i);return n?s.flatMap(i=>!i.querySelector(n)&&!i.matches(n)?[i]:[...i.children].filter(o=>!o.matches(n)&&!o.querySelector(n))):s}async function _b(t,e,n){const s=(a,l)=>{const c=a.dataset?.flipId;c&&a.style.setProperty("view-transition-name",l?`tf-${c.replace(/[^\w-]/g,"-")}`:"")},i=n();i.forEach(a=>s(a,!0));let o=[];await t.startViewTransition(async()=>{i.forEach(a=>s(a,!1)),await e.update(),o=n(),o.forEach(a=>s(a,!0))}).finished,o.forEach(a=>s(a,!1))}const S0={create:(t,e)=>Fr(t,vh(e))},T0={create:(t,e)=>Fr(t,{fn:Mh(e)})},x0={create:(t,e)=>Fr(t,{fn:Sh(e)})},Cb=new Set(["keyframes","duration","delay","ease","easeEach","stagger","repeat","repeatDelay","yoyo","repeatRefresh","paused","id","onStart","onUpdate","onComplete","onRepeat","onReverseComplete","scrollTrigger"]),E0=.5,Hb="power1.inOut";function Rb(t){return t.keyframes!==void 0&&t.keyframes!==null}function Lb(t){const e=t.keyframes,n={};for(const[c,h]of Object.entries(t))Cb.has(c)||(n[c]=h);if(Array.isArray(e))return e.map(c=>({...n,...c,duration:c.duration??t.duration??E0}));const s=Object.entries(e),i=t.duration??E0,o=e.easeEach??t.easeEach??Hb;if(s.length>0&&s.every(([c])=>/^\s*-?\d+(\.\d+)?\s*%\s*$/.test(c)||c==="easeEach")){const c=s.filter(([d])=>d!=="easeEach").map(([d,f])=>({at:Number.parseFloat(d)/100,step:f})).sort((d,f)=>d.at-f.at),h=[];let u=0;for(const{at:d,step:f}of c){const p=Math.max(0,d-u);h.push({...n,ease:o,...f,duration:p*i}),u=d}return h}const r=s.filter(([c,h])=>c!=="easeEach"&&Array.isArray(h)),a=Math.max(0,...r.map(([,c])=>c.length)),l=[];for(let c=0;c<a;c++){const h={...n,ease:o,duration:i/a};for(const[u,d]of r)c<d.length&&(h[u]=d[c]);l.push(h)}return l}function A0(t,e,n,s={}){const i=e.collector?.scope??e.root,o=typeof s.scroller=="string"?i.querySelector(s.scroller):s.scroller??null,r={x:o?o.scrollLeft:window.scrollX,y:o?o.scrollTop:window.scrollY},a={x:o?o.scrollWidth-o.clientWidth:document.documentElement.scrollWidth-window.innerWidth,y:o?o.scrollHeight-o.clientHeight:document.documentElement.scrollHeight-window.innerHeight},l=(v,k)=>{if(k===void 0)return r[v];if(typeof k=="number")return k;if(k==="max")return a[v];const b=typeof k=="string"?i.querySelector(k):k;if(!b)return r[v];const E=b.getBoundingClientRect(),$=o?.getBoundingClientRect(),S=(v==="x"?s.offsetX:s.offsetY)??s.offset??0;return v==="x"?E.left-($?.left??0)+r.x-S:E.top-($?.top??0)+r.y-S},c=typeof n=="object"&&n!==null&&!("nodeType"in n)?{x:l("x",n.x),y:l("y",n.y)}:{x:r.x,y:l("y",n)},h={x:Math.max(0,Math.min(a.x,c.x)),y:Math.max(0,Math.min(a.y,c.y))},u={...r},d=()=>{o?(o.scrollLeft=u.x,o.scrollTop=u.y):window.scrollTo({left:u.x,top:u.y,behavior:"instant"})},f=["wheel","touchstart","keydown"],p=o??window,g=()=>{w.kill(),m()},m=()=>{for(const v of f)p.removeEventListener(v,g)},w=t.to(u,{x:h.x,y:h.y,duration:s.duration??1,ease:s.ease??"power2.inOut",onStart:s.onStart,onUpdate:()=>{d(),s.onUpdate?.()},onComplete:()=>{m(),s.onComplete?.()}});if(s.autoKill!==!1)for(const v of f)p.addEventListener(v,g,{passive:!0});return w}function Nb(t,e,n){const s=t.collector?.scope??t.root,i=typeof e=="string"?[...s.querySelectorAll(e)]:"nodeType"in e?[e]:Array.from(e),{interval:o=.1,batchMax:r,onEnter:a,onLeave:l,onEnterBack:c,onLeaveBack:h,...u}=n,d={onEnter:a,onLeave:l,onEnterBack:c,onLeaveBack:h},f={onEnter:[],onLeave:[],onEnterBack:[],onLeaveBack:[]},p={},g=w=>{p[w]!==void 0&&clearTimeout(p[w]),p[w]=void 0;const v=f[w].splice(0);v.length>0&&d[w]?.(v)},m=(w,v)=>{if(d[w]){if(f[w].push(v),r!==void 0&&f[w].length>=r)return g(w);p[w]===void 0&&(p[w]=setTimeout(()=>g(w),o*1e3))}};return i.map(w=>ia(t,{...u,trigger:w,onEnter:()=>m("onEnter",w),onLeave:()=>m("onLeave",w),onEnterBack:()=>m("onEnterBack",w),onLeaveBack:()=>m("onLeaveBack",w)})).filter(w=>w!==void 0)}class ge{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 en({...s,startValue:(i,o)=>{const r=e.objectFor(i);if(r)return Wb(r[o]);const a=e.appliedValue(i,o);if(a!==void 0)return a;if(o==="d")return Zh(e.elementFor(i))??void 0;if(o==="text")return e.elementFor(i)?.textContent??void 0;if(o==="strokeDasharray"||o==="strokeDashoffset"){const l=_0(e.elementFor(i));if(l!==void 0)return o==="strokeDasharray"?[l,l]:0}},startVelocity:(i,o)=>e.velocityOf(i,o),layoutColumns:i=>O0(i.map(o=>e.elementFor(o))),random:()=>e.utils.random(0,1)}),this.compat.timeline.onComplete=()=>{this.finishedThisFrame=!0},e.collector?.track(this),e.liveTimelines.add(this),this.autoplayPending=!s.paused&&!s.scrollTrigger,s.scrollTrigger){const i=s.scrollTrigger;queueMicrotask(()=>{this.killed||(this.scrollDriver=ia(e,i,this,this.firstElement,o=>s.onWarning?.(o)))})}this.autoplayPending&&queueMicrotask(()=>{this.autoplayPending&&this.play()})}get timeline(){return this.compat.timeline}get scrollTrigger(){return this.scrollDriver}to(e,n,s){return Rb(n)?this.record(()=>this.keyframed(e,n,s)):this.record(()=>this.tween(e,[n],s,([i],o,r)=>this.compat.to(o,i,r)))}from(e,n,s){return this.record(()=>this.tween(e,[n],s,([i],o,r)=>this.compat.from(o,i,r)))}fromTo(e,n,s,i){return this.record(()=>this.tween(e,[n,s],i,([o,r],a,l)=>this.compat.fromTo(a,o,r,l)))}set(e,n,s){return this.record(()=>this.tween(e,[n],s,([i],o,r)=>this.compat.set(o,i,r)))}addLabel(e,n){return this.record(()=>this.compat.addLabel(e,n))}add(e,n){return this.record(()=>{e.autoplayPending=!1,e.timeline.stop(),e.stage.deactivate(e.timeline),this.compat.add(e.compat,n)})}invalidate(){const e=this.compat.progress();this.compat.progress(0),this.stage.render(this.timeline),this.compat.reset(),this.events=[],this.ranges=[];for(const n of this.recipe)n();return this.syncDuration(),this.compat.progress(e),this.stage.render(this.timeline),this}call(e,n=[],s){return this.record(()=>{const i=this.compat.addEvent(s);this.events.push({time:i,run:()=>e(...n)})})}addPause(e,n,s=[]){return this.record(()=>{const i=this.compat.addEvent(e);this.events.push({time:i,pause:!0,run:()=>n?.(...s)})})}tweenTo(e,n={}){return this.tweenFromTo(this.timeline.currentTime/1e3,e,n)}tweenFromTo(e,n,s={}){this.pause(),this.seek(e);const i=this.timeline.currentTime,o=Math.max(0,Math.min(this.timeline.duration,this.compat.timeOf(n))),r={time:i},a=s.duration??Math.abs(o-i)/1e3/(this.timeScale()||1),l=new ge(this.stage,{onStart:s.onStart,onComplete:s.onComplete});return l.to(r,{time:o,duration:a,ease:s.ease??"none",onUpdate:()=>{this.moveTo(r.time),s.onUpdate?.()}}),l}play(){this.autoplayPending=!1,this.started||(this.started=!0,this.options.onStart?.());const e=this.timeline.playbackState==="playing",n=this.timeline.playbackState==="paused";if(this.timeline.play(),!e){const s=this.timeline,i=s.direction==="forward"?s.currentTime===0:s.currentTime===s.duration;this.playhead={...this.readPlayhead(),fresh:i&&!n},this.waitingToWrap=!1}return this.stage.liveTimelines.add(this),this.stage.render(this.timeline),this.stage.activate(this.timeline,{onUpdate:()=>this.afterFrame()}),this}pause(){return this.autoplayPending=!1,this.timeline.pause(),this.stage.deactivate(this.timeline),this}resume(){return this.play()}restart(){return this.timeline.stop(),this.backwards=!1,this.play()}reverse(){this.backwards=!this.backwards;const e=this.timeline.playbackState==="idle"&&this.timeline.direction==="forward";return this.timeline.reverse(),e&&this.timeline.currentTime===0&&this.timeline.seek(this.timeline.duration),this.play()}labelProgresses(){const e=this.timeline.duration;return e>0?this.compat.labelTimes().map(n=>n/e):[]}reversed(){return this.timeline.direction==="reverse"}seek(e){return this.autoplayPending=!1,this.compat.seek(e),this.stage.render(this.timeline),this.playhead=this.readPlayhead(),this.waitingToWrap=!1,this.options.onUpdate?.(),this}progress(e){return e===void 0?this.compat.progress():(this.autoplayPending=!1,this.moveTo(Math.max(0,Math.min(1,e))*this.timeline.duration),this.compat.progress())}timeScale(e){return this.compat.timeScale(e)}duration(){return this.compat.duration()}isActive(){return this.timeline.playbackState==="playing"}kill(){return this.killed=!0,this.stage.liveTimelines.delete(this),this.scrollDriver?.destroy(),this.scrollDriver=void 0,this.autoplayPending=!1,this.timeline.stop(),this.stage.deactivate(this.timeline),this.compat.kill(),this}toDefinition(){return this.compat.toDefinition()}killTweensOf(e,n){for(const s of e)for(const i of n??[void 0])this.timeline.removeTracks({target:s,...i!==void 0&&{property:i}});this.timeline.tracks.length===0&&this.events.length===0&&this.kill()}record(e){return this.recipe.push(e),e(),this.syncDuration(),this}syncDuration(){if(this.events.length===0)return;this.timeline.setDuration(void 0);const e=Math.max(...this.events.map(n=>n.time));e>this.timeline.duration&&this.timeline.setDuration(e)}readPlayhead(){const e=this.timeline;return{time:e.currentTime,iteration:e.loopIteration,direction:e.direction}}moveTo(e){const n=this.playhead;this.timeline.seek(e),this.stage.render(this.timeline);const s={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:e>=n.time?"forward":"reverse"},i={...n,iteration:s.iteration,direction:s.direction};this.playhead={...this.readPlayhead()},this.waitingToWrap=!1,this.runCrossings(i,s,!1),this.options.onUpdate?.()}refreshForRepeat(){const e=this.timeline.currentTime;this.compat.reset(),this.events=[],this.ranges=[];for(const n of this.recipe)n();this.syncDuration(),this.timeline.seek(Math.min(e,this.timeline.duration))}afterFrame(){const e=this.timeline,n=e.repeatDelayRemaining>0;if(this.waitingToWrap&&n){this.options.onUpdate?.();return}this.waitingToWrap=!1;const s=this.playhead,i=this.readPlayhead();this.playhead=i;const o=this.options.yoyo===!0;n&&!o&&i.iteration>s.iteration&&(this.playhead={time:0,iteration:i.iteration,direction:"forward",fresh:!0},this.waitingToWrap=!0);const r=this.runCrossings(s,i,n);if(this.options.onUpdate?.(),this.finishedThisFrame&&!r){this.finishedThisFrame=!1;const a=e.currentTime===0&&e.direction==="reverse";!this.scrollDriver&&!o&&this.stage.liveTimelines.delete(this),a&&this.backwards?this.options.onReverseComplete?.():this.options.onComplete?.()}this.finishedThisFrame=!1}runCrossings(e,n,s){if(this.events.length===0&&this.ranges.length===0&&!this.options.onRepeat&&!this.options.repeatRefresh)return!1;const i=this.events,{crossings:o,passes:r}=xr(i.map(a=>a.time),e,n,{duration:this.timeline.duration,alternate:this.options.yoyo===!0,holding:s});for(const a of o){if(this.killed)return!0;if(a.kind==="repeat"){this.options.repeatRefresh&&this.refreshForRepeat(),this.options.onRepeat?.();continue}const l=i[a.index];if(!(l.direction&&l.direction!==a.direction)){if(l.pause)return this.timeline.seek(l.time),this.stage.render(this.timeline),this.pause(),this.playhead=this.readPlayhead(),this.waitingToWrap=!1,l.run(),!0;l.run()}}for(const a of this.ranges)r.some(([c,h])=>c!==h&&Math.max(c,h)>=a.start&&Math.min(c,h)<=a.end)&&a.run();return!1}tween(e,n,s,i){const o=this.resolve(e);if(!o)return;const{onStart:r,onUpdate:a,onComplete:l}=n[n.length-1];if(r||a||l){let c=1/0,h=-1/0;const u=(d,f,p)=>{i(d,f,p),c=Math.min(c,this.compat.lastStart),h=Math.max(h,this.compat.lastEnd)};if(this.buildTween(o,n,s,u),c===1/0)return;r&&this.events.push({time:c,direction:"forward",run:r}),a&&this.ranges.push({start:c,end:h,run:a}),l&&this.events.push({time:h,direction:"forward",run:l});return}this.buildTween(o,n,s,i)}keyframed(e,n,s){const i=this.resolve(e);if(!i)return;const o=Lb(n);if(o.length===0)return;const r=i.length>1?Br(n.stagger,this.staggerContext(i)):void 0,a=i.map(m=>this.targetFor(m)).filter(m=>m!==void 0),l=r?a.map(m=>[m]):[a],c=r?hi(i.length,r).map(m=>m/1e3):[0],h=this.compat.timeOf(s)/1e3+$i(n.delay,0)/1e3;let u=1/0,d=-1/0;if(l.forEach((m,w)=>{o.forEach((v,k)=>{const b=k===0?h+c[w]:">";this.tween(m,[v],b,([E],$,S)=>this.compat.to($,E,S)),u=Math.min(u,this.compat.lastStart),d=Math.max(d,this.compat.lastEnd)})}),u===1/0)return;const{onStart:f,onUpdate:p,onComplete:g}=n;f&&this.events.push({time:u,direction:"forward",run:f}),p&&this.ranges.push({start:u,end:d,run:p}),g&&this.events.push({time:d,direction:"forward",run:g})}staggerContext(e){return{count:e.length,columnsFromLayout:()=>O0(e.map(n=>this.stage.elementFor(n))),random:()=>this.stage.utils.random(0,1)}}buildTween(e,n,s,i){const o=e.map(d=>this.targetFor(d));if(!(e.length>1&&(n.some(Db)||e.some(d=>this.stage.objectFor(d)!==void 0)))){const d=this.targetFor(e[0]);i(n.map(f=>this.prepare(I0(f,0,d,this.stage.utils,o),e)),e,s);return}const a=n.length-1,{stagger:l,...c}=n[a],h=Br(l,this.staggerContext(e)),u=h?hi(e.length,h).map(d=>d/1e3):e.map(()=>0);e.forEach((d,f)=>{const p=f===0?$i(c.delay,0)/1e3+u[0]:0,g=f===0?0:u[f]-u[f-1],m=f===0?s:`<${g<0?"-":"+"}${Math.abs(g).toFixed(6)}`,v=n.map((k,b)=>b===a?{...c,delay:p}:k).map(k=>this.prepare(I0(k,f,this.targetFor(d),this.stage.utils,o),[d]));i(v,[d],m)})}targetFor(e){return this.stage.elementFor(e)??this.stage.objectFor(e)}prepare(e,n){const s=r=>this.options.onWarning?.(r),i=r=>this.stage.query(r);let o=e;if(e.motionPath!==void 0){const r=Jy(e.motionPath,{query:i,targets:n.map(a=>this.stage.elementFor(a)).filter(a=>!!a),warn:s});o={...o,motionPath:r}}if(e.morphSVG!==void 0){const r=Zy(e.morphSVG,i,s),{morphSVG:a,...l}=o;o=r?{...o,morphSVG:r}:l}if(e.drawSVG!==void 0){const r=_0(this.stage.elementFor(n[0]));if(r===void 0){s("gsap-compat: drawSVG needs an SVG shape with a stroke (path, line, circle…)");const{drawSVG:a,...l}=o;o=l}else o=Ty(o,r)}return o}resolve(e){const n=this.stage.resolveTargets(e);if(n.length===0){this.options.onWarning?.(`gsap-compat: no elements found for target ${Bb(e)}`);return}return this.firstElement??=n.map(s=>this.stage.elementFor(s)).find(s=>s!==void 0),n}}function P0(t=new Gh){const e=o=>{const{config:r}=Pi(o);return new ge(t,{repeat:r.repeat,yoyo:r.yoyo,repeatDelay:r.repeatDelay,paused:r.paused,onStart:r.onStart,onUpdate:r.onUpdate,onComplete:r.onComplete,onRepeat:r.onRepeat,onReverseComplete:r.onReverseComplete,repeatRefresh:r.repeatRefresh,scrollTrigger:r.scrollTrigger})},n=o=>{const{onStart:r,onUpdate:a,onComplete:l,onRepeat:c,onReverseComplete:h,repeatRefresh:u,...d}=o;return d},s=o=>(o&&t.collector?.track(o),o),i={stage:t,ticker:t.ticker,utils:t.utils,getProperty:(o,r)=>{const[a]=t.resolveTargets(o);if(a===void 0)return;const l=t.objectFor(a);return l?l[r]:t.appliedValue(a,r)??qh(r)},scrollTrigger:o=>s(ia(t,o)),scrollBatch:(o,r)=>Nb(t,o,r).map(a=>s(a)),scrollTo:(o,r)=>A0(i,t,o,r),refreshScroll:()=>{xs.refreshAll(),na.refreshAll()},smoothScroll:(o={})=>{const r=typeof o.scroller=="string"?(t.collector?.scope??t.root).querySelector(o.scroller):o.scroller;return s(new na({...o,scroller:r}).start())},context:(o,r)=>{const a=new v0(t,r);return o&&a.add(()=>o(a)),a},matchMedia:o=>new Ab(t,o),customEase:S0.create,customBounce:T0.create,customWiggle:x0.create,pageTransition:o=>Ob(i,t,r=>new ge(t,r),o),imageSequence:(o,r)=>{const a=typeof o=="string"?(t.collector?.scope??t.root).querySelector(o):o;if(!(a instanceof HTMLCanvasElement))throw new Error(`gsap-compat: imageSequence needs a <canvas>, got ${String(o)}`);return s(new Pb(a,r))},quickTo:(o,r,a={})=>{const l=new ge(t,{paused:!0}),[c]=t.resolveTargets(o);return Object.assign(u=>{if(!c)return;const d=a.spring!==void 0?t.velocityOf(c,r)??0:0;l.compat.reset(),l.compat.to(c,{[r]:u,duration:a.duration??.4,ease:a.ease??"power3.out",...a.spring!==void 0&&{spring:Fb(a.spring,r,d)}}),l.timeline.stop(),l.timeline.play(),t.activate(l.timeline)},{tween:l,kill:()=>l.kill()})},timeline:o=>new ge(t,o),to:(o,r)=>{if(r.scrollTo!==void 0){const{scrollTo:a,...l}=r,c=typeof a=="object"&&a!==null&&!("nodeType"in a)?a:{},h=typeof o!="string"&&o!==window&&o.nodeType===1;return A0(i,t,a,{...l,offsetX:c.offsetX,offsetY:c.offsetY,scroller:h?o:void 0})}return e(r).to(o,n(r))},from:(o,r)=>e(r).from(o,n(r)),fromTo:(o,r,a)=>e(a).fromTo(o,r,n(a)),set:(o,r)=>e(r).set(o,n(r)),delayedCall:(o,r,a)=>new ge(t).call(r,a,o),killTweensOf:(o,r)=>{const a=t.resolveTargets(o),l=typeof r=="string"?r.split(",").map(c=>c.trim()).filter(Boolean):r;for(const c of[...t.liveTimelines])c.killTweensOf(a,l)},convertToPath:o=>tb(o,t.root),splitText:(o,r)=>{const a=t.collector?.scope??t.root,l=typeof o=="string"?Array.from(a.querySelectorAll(o)):"nodeType"in o?[o]:Array.from(o);return s(lb(l,r))},draggable:(o,r)=>s(ib(i,t,o,r)),getFlipState:o=>Xr(t,o),flipFrom:(o,r)=>Ur(t,a=>new ge(t,a),o,r),flip:(o,r,a)=>{const l=Xr(t,o);return r(),Ur(t,c=>new ge(t,c),l,{targets:o,...a})}};return i}const Gt=P0();function Fb(t,e,n){return t===!0?{velocity:{[e]:n}}:typeof t=="string"?{preset:t,velocity:{[e]:n}}:{...t,velocity:{[e]:n}}}function Db(t){return t.morphSVG!==void 0||t.drawSVG!==void 0||t.text!==void 0||t.scrambleText!==void 0||$0(t)}function $0(t){return Object.entries(t).some(([e,n])=>(typeof n=="function"||Bh(n))&&!Wr.has(e))}function I0(t,e,n,s,i){if(!$0(t))return t;const o={};for(const[r,a]of Object.entries(t))Wr.has(r)?o[r]=a:typeof a=="function"?o[r]=a(e,n,i):Bh(a)?o[r]=s.resolveRandomString(a):o[r]=a;return o}function O0(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 _0(t){const e=t;if(typeof e?.getTotalLength=="function")return e.getTotalLength()}function Wb(t){if(typeof t=="number"||typeof t=="string"||Array.isArray(t)&&t.every(e=>typeof e=="number"))return t}function Bb(t){return typeof t=="string"?`"${t}"`:String(t)}class oa{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 C0(t,e,n,s,i){const o=n-i;if(o<0){e.paused||e.pause(),e.currentTime=0;return}t.update(o,s)}class _i{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 nn}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=An({...e,config:n}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(e,n={}){if(e.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const s=new Set;for(const o of e){if(s.has(o.id))throw new Error(`tinyfly: scenario id "${o.id}" is used more than once`);s.add(o.id)}const i=n.initial===void 0?e[0]:e.find(o=>o.id===n.initial);if(!i)throw new Error(`tinyfly: there is no scenario "${n.initial}"`);this.scenarioList=[...e],this.scenarioId=i.id,await this.loadSource(i.timeline)}get scenarios(){return this.scenarioList.map(e=>({id:e.id,label:e.label??e.id}))}get scenario(){return this.scenarioId}setScenario(e){const n=this.scenarioList.find(a=>a.id===e);if(!n||!this.timeline)return!1;if(e===this.scenarioId)return!0;const s=this.isPlaying,i=this.currentTime>=this.duration-.5,o=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=e,this.useDefinition(n.timeline),this.lastMarkerId=null;let r=0;return this.reducedMotion||i?r=this.duration:o!==void 0&&(r=this.markers.find(a=>a.id===o)?.time??0),this.seek(r),s&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(e){if(this.authored.has(e))return;const n={style:e.getAttribute("style")};e.children.length===0&&(n.text=e.textContent??"");const s=e.tagName.toLowerCase()==="path"?e:e.querySelector("path");s&&(n.path={element:s,d:s.getAttribute("d")}),this.authored.set(e,n)}restoreAuthored(){for(const[e,n]of this.authored){n.style===null?e.removeAttribute("style"):e.setAttribute("style",n.style),n.text!==void 0&&e.textContent!==n.text&&(e.textContent=n.text),n.path&&(n.path.d===null?n.path.element.removeAttribute("d"):n.path.element.setAttribute("d",n.path.d));const s=e.dataset;s&&delete s.shineBase}}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){for(const e of this.listeners)e()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const e=this.currentTime;let n;for(const s of this.markers)if(s.time<=e+.5)n=s;else break;return n}caption(e,n){const s=e?this.markers.find(r=>r.id===e):this.currentMarker;if(!s)return;const i=n??this.language(),o=r=>r?.[i]?.[s.id]??r?.[i.split("-")[0]]?.[s.id];return o(this.options.captions)??o(this.timeline?.captions)??s.label}next(){if(!this.timeline)return;const e=this.currentTime,n=this.markers.find(s=>s.time>e+.5);if(this.reducedMotion){this.seek(n?n.time:this.duration);return}e>=this.duration-.5||(this.stepping=n!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const e=this.currentTime,n=[...this.markers].reverse().find(s=>s.time<e-.5);this.pause(),this.seek(n?n.time:0)}goToMarker(e){const n=this.markers.find(s=>s.id===e);n&&(this.pause(),this.seek(n.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const e=this.options.initialFrame??"start";if(e==="none")return;const n=e==="end"?this.timeline.duration:e==="start"?0:e;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,n))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(n=>{for(const s of n)this.onScreen=s.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const e=this.container.getBoundingClientRect?.();e&&(e.width>0||e.height>0)&&(this.onScreen=e.bottom>0&&e.top<window.innerHeight&&e.right>0&&e.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const e=this.onScreen&&document.visibilityState!=="hidden";!e&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):e&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const e=this.currentMarker,n=e?.id;n!==this.lastMarkerId&&(this.lastMarkerId=n,this.options.onMarker(e))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(n=>{const s=n,i=Number(s.getAttribute("data-tinyfly-start")??"0")||0,o=s.getAttribute("data-volume");o!==null&&(s.volume=Math.max(0,Math.min(1,Number(o)||0))),this.mediaTargets.push({el:s,startTime:i,sync:new oa(s)})})}syncAllMedia(e,n){for(const s of this.mediaTargets)C0(s.sync,s.el,e,n,s.startTime)}loadFromString(e){const n=JSON.parse(e);this.load(n)}registerTarget(e,n){if(typeof n=="string"){const s=this.container.querySelector(n);s&&(this.rememberAuthored(s),this.targets[e]=s,this.adapter.registerTarget(e,s))}else this.rememberAuthored(n),this.targets[e]=n,this.adapter.registerTarget(e,n)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(n=>{const s=n.closest("[data-tinyfly-symbol]");if(s&&s!==n)return;const i=n.getAttribute("data-tinyfly");i&&this.registerTarget(i,n)}),this.timeline&&new Set(this.timeline.tracks.map(s=>s.target)).forEach(s=>{if(!this.targets[s]){const i=this.container.querySelector(`[data-tinyfly="${s}"]`)||this.container.querySelector(`.${s}`)||this.container.querySelector(`#${s}`);i&&this.registerTarget(s,i)}})}setupSymbolInstances(){this.symbolInstances=[];const e=this.options.symbols;if(!e||e.length===0)return;const n=new Map(e.map(s=>[s.id,s]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const i=s.getAttribute("data-tinyfly-symbol");if(!i)return;const o=n.get(i);if(!o||!o.timeline.tracks?.length)return;const r=new nn;s.querySelectorAll("[data-tinyfly]").forEach(a=>{const l=a.getAttribute("data-tinyfly");l&&r.registerTarget(l,a)}),this.symbolInstances.push({adapter:r,timeline:An(o.timeline)})})}attachMedia(e,n){this.mediaSync=new oa(e,n),this.timeline&&(this.mediaSync.setRate(this.timeline.speed),this.mediaSync.update(this.timeline.currentTime,this.isPlaying))}detachMedia(){this.mediaSync?.dispose(),this.mediaSync=void 0}play(){!this.timeline||this.isDestroyed||(this.autoplayWhenSeen=!1,this.stepping=this.options.stepMode===!0,this.startPlaying())}startPlaying(){if(!this.timeline||this.isDestroyed)return;const e=this.timeline.playbackState==="idle";this.timeline.play(),e&&this.timeline.currentTime===0&&this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.update(this.timeline.currentTime,!0),this.syncAllMedia(this.timeline.currentTime,!0),this.startAnimationLoop(),this.notify()}pause(){this.timeline&&(this.stepping=!1,this.timeline.pause(),this.notify(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1),this.stopAnimationLoop())}stop(){this.timeline&&(this.timeline.stop(),this.stopAnimationLoop(),this.applyState(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1))}seek(e){this.timeline&&(this.timeline.seek(e),this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.seek(this.timeline.currentTime),this.syncAllMedia(this.timeline.currentTime,this.isPlaying))}setSpeed(e){this.timeline&&(this.timeline.speed=e,this.mediaSync?.setRate(e))}reverse(){this.timeline&&this.timeline.reverse()}get currentTime(){return this.timeline?.currentTime??0}get duration(){return this.timeline?.duration??0}get isPlaying(){return this.timeline?.playbackState==="playing"}destroy(){this.isDestroyed=!0,this.stopAnimationLoop(),this.reducedQuery?.removeEventListener?.("change",this.onReducedChange),this.visibilityObserver?.disconnect(),typeof document<"u"&&document.removeEventListener("visibilitychange",this.onDocumentVisibility),this.mediaSync?.dispose(),this.mediaSync=void 0;for(const e of this.mediaTargets)e.el.paused||e.el.pause();this.mediaTargets=[],this.adapter.clearTargets();for(const e of this.symbolInstances)e.adapter.clearTargets();this.symbolInstances=[],this.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const e=n=>{if(this.isDestroyed||!this.timeline)return;const s=n-(this.lastTime??n);this.lastTime=n;const i=this.playhead;this.timeline.tick(s),this.stopAtMarker(i),this.applyState();const o=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,o),this.syncAllMedia(this.timeline.currentTime,o),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(e):(this.animationFrameId=void 0,this.notify())};this.animationFrameId=requestAnimationFrame(e)}stopAtMarker(e){const n=this.timeline,s={time:n.currentTime,iteration:n.loopIteration,direction:n.direction};this.playhead=s;const i=this.markers;if(i.length===0)return;const{crossings:o}=xr(i.map(r=>r.time),e,s,{duration:n.duration,alternate:n.config.alternate===!0,holding:n.repeatDelayRemaining>0});for(const r of o){if(r.kind!=="event")continue;const a=i[r.index];if(this.stepping||a.pause){this.stepping=!1,n.pause(),n.seek(a.time),this.playhead={time:a.time,iteration:n.loopIteration,direction:n.direction};return}}}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}applyState(){if(!this.timeline)return;const e=this.timeline.currentTime;this.adapter.applyState(this.timeline.getStateAtTime(e)),this.announceMarker(),this.notify();for(const n of this.symbolInstances){const s=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(s>0?e%s:e))}}}async function zb(t,e,n={}){const s=new _i(t,{...n,autoplay:!0});return await s.load(e),s}function qb(t,e={}){return new _i(t,e)}const H0={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"},R0="tinyfly-controls-style",Yb=`
|
|
1
|
+
(function(b){"use strict";function Lc(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function ds(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const ur=2;function dr(t){return t.some(e=>e.interpolation!==void 0)?2:1}function yi(t){return t.property==="text"&&"textConfig"in t}function Pe(t){return t.kind==="inertia"&&"inertia"in t}function $e(t){return t.kind==="spring"&&"spring"in t}function fr(t){return t.property==="motionPath"&&"motionPathConfig"in t}function zm(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"angle"in t}function Nc(t){return"keyframes"in t}class qm{_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 Ym{_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 Fc(t,e){if(!(e>0))return t;const n=1e3/e;return Math.floor(t/n+1e-9)*n}function gr(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 pr(t,e="start"){if(t<=1)return 0;let n=0;for(let s=0;s<t;s++)n=Math.max(n,gr(s,t,e));return n}function bi(t,e,n){if(n.offsets)return n.offsets[t]??0;const s=n.from??"start",i=gr(t,e,s);if(n.amount!==void 0){const o=pr(e,s);return o===0?0:n.amount*i/o}return n.each!==void 0?n.each*i:0}function wi(t,e){return Array.from({length:t},(n,s)=>bi(s,t,e))}function fs(t,e){return t<=1?0:Math.max(...wi(t,e))}const Mn=1,mr=6e4,ki=mr/Mn,te={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1},vi={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 gs{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??te.stiffness,this.damping=e.damping??te.damping,this.mass=e.mass??te.mass,this.restDelta=e.restDelta??te.restDelta,this.restSpeed=e.restSpeed??te.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=e.velocity??te.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/Mn);if(this.simulateTo(n+1),this.settledStep!==null&&n>=this.settledStep)return this.to;const s=this.samples[Math.min(n,this.samples.length-1)],i=this.samples[Math.min(n+1,this.samples.length-1)],o=e/Mn-n;return s+(i-s)*o}settleTime(){return this.simulateTo(ki+1),this.settledStep!==null?this.settledStep*Mn:mr}simulateTo(e){if(this.settledStep!==null)return;const n=Math.min(e,ki+1),s=Mn/1e3;for(;this.samples.length<n;){const i=this.samples[this.samples.length-1],o=i-this.to,r=-this.stiffness*o,a=-this.damping*this.velocity,l=(r+a)/this.mass;this.velocity+=l*s;const c=i+this.velocity*s;if(this.samples.push(c),this.isAtRest(c)){this.settledStep=this.samples.length-1;return}}this.samples.length>ki&&(this.settledStep=ki)}}function Km(t,e){return new gs(t).valueAt(e)}function Wc(t){return new gs(t).settleTime()}function jm(t){const e=t.stiffness??te.stiffness,n=t.damping??te.damping,s=t.mass??te.mass;return n<2*Math.sqrt(e*s)}function Xm(t){const e=t.stiffness??te.stiffness,n=t.mass??te.mass;return 2*Math.sqrt(e*n)}const yr=4,Gm=.002,Um=1e-4,Dc=6e4;function Mi(t){const e=t.friction??yr;return e>0?e:yr}function ps(t){return t.from+t.velocity/Mi(t)}function Vm(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 Sn(t){let e=Vm(ps(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 xn(t){const e=Math.abs(Sn(t)-t.from);if(e===0)return 0;const n=t.restDelta??Math.max(Um,e*Gm);if(n>=e)return 0;const s=Math.log(e/n)/Mi(t);return Math.min(Dc,s*1e3)}function Si(t,e){if(e<=0)return t.from;const n=Sn(t);if(e>=xn(t))return n;const s=Mi(t);return t.from+(n-t.from)*(1-Math.exp(-s*e/1e3))}function Jm(t,e){const n=Mi(t),s=Sn(t);return e>=xn(t)?0:(s-t.from)*n*Math.exp(-n*Math.max(0,e)/1e3)}const xi=t=>t,Bc=t=>t*t,zc=t=>1-(1-t)*(1-t),qc=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,br=t=>t*t*t,wr=t=>1-Math.pow(1-t,3),ms=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,Yc=br,Kc=wr,jc=ms,Zm={linear:xi,"ease-in":Yc,"ease-out":Kc,"ease-in-out":jc,"ease-in-quad":Bc,"ease-out-quad":zc,"ease-in-out-quad":qc,"ease-in-cubic":br,"ease-out-cubic":wr,"ease-in-out-cubic":ms};function Xc(t){const[e,n,s,i]=t,o=3*e,r=3*(s-e)-o,a=1-o-r,l=3*n,c=3*(i-n)-l,h=1-l-c,u=g=>((a*g+r)*g+o)*g,d=g=>((h*g+c)*g+l)*g,f=g=>(3*a*g+2*r)*g+o,p=g=>{let m=g;for(let k=0;k<8;k++){const y=u(m)-g;if(Math.abs(y)<1e-7)return m;const T=f(m);if(Math.abs(T)<1e-7)break;m-=y/T}let w=0,v=1;for(m=g;w<v;){const k=u(m);if(Math.abs(k-g)<1e-7)return m;g>k?w=m:v=m,m=(w+v)/2}return m};return g=>{if(g<=0)return 0;if(g>=1)return 1;const m=p(g);return d(m)}}function kr(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 Gc(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 Uc=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 Vc(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 Jc(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 Zc(t){switch(t.type){case"steps":return Jc(t.count,t.position);case"elastic":return kr(Gc(t.amplitude,t.period),t.mode);case"bounce":return kr(Uc,t.mode);case"back":return kr(Vc(t.overshoot),t.mode)}}function Lt(t){return t===void 0?xi:Lc(t)?Xc(t.points):ds(t)?Zc(t):Zm[t]??xi}const Qc=32,Qm=256,Tn=new Map,ty=/[MmLlHhVvCcSsQqTtAaZz]/,ey=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,ny={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function sy(t){const e=[];let n=0,s=null;const i=()=>{for(;n<t.length&&/[\s,]/.test(t[n]);)n++};for(;n<t.length&&(i(),!(n>=t.length));){const o=t[n];if(ty.test(o)){s={type:o,args:[]},e.push(s),n++;continue}if(!s)break;const r=s.type==="A"||s.type==="a",a=s.args.length%7;if(r&&(a===3||a===4)){if(o!=="0"&&o!=="1")break;s.args.push(o==="1"?1:0),n++;continue}const l=ey.exec(t.slice(n));if(!l)break;s.args.push(parseFloat(l[0])),n+=l[0].length}return e}function iy(t,e,n,s,i,o,r,a,l){if(t===a&&e===l)return[];let c=Math.abs(n),h=Math.abs(s);if(c===0||h===0)return[[t,e,a,l,a,l]];const u=i*Math.PI/180,d=Math.cos(u),f=Math.sin(u),p=(t-a)/2,g=(e-l)/2,m=d*p+f*g,w=-f*p+d*g,v=m*m/(c*c)+w*w/(h*h);if(v>1){const R=Math.sqrt(v);c*=R,h*=R}const k=o===r?-1:1,y=c*c*h*h-c*c*w*w-h*h*m*m,T=c*c*w*w+h*h*m*m,$=k*Math.sqrt(Math.max(0,y/T)),M=$*c*w/h,x=-$*h*m/c,S=d*M-f*x+(t+a)/2,E=f*M+d*x+(e+l)/2,P=(R,z,K,O)=>{const D=R*K+z*O,st=Math.sqrt((R*R+z*z)*(K*K+O*O)),H=Math.acos(Math.max(-1,Math.min(1,D/st)));return R*O-z*K<0?-H:H},A=P(1,0,(m-M)/c,(w-x)/h);let I=P((m-M)/c,(w-x)/h,(-m-M)/c,(-w-x)/h);!r&&I>0&&(I-=2*Math.PI),r&&I<0&&(I+=2*Math.PI);const _=Math.max(1,Math.ceil(Math.abs(I)/(Math.PI/2))),N=I/_,Y=4/3*Math.tan(N/4),V=R=>{const z=c*Math.cos(R),K=h*Math.sin(R);return[d*z-f*K+S,f*z+d*K+E]},tt=R=>{const z=-c*Math.sin(R),K=h*Math.cos(R);return[d*z-f*K,f*z+d*K]},X=[];for(let R=0;R<_;R++){const z=A+R*N,K=z+N,[O,D]=V(z),[st,H]=R===_-1?[a,l]:V(K),[L,q]=tt(z),[U,F]=tt(K);X.push([O+Y*L,D+Y*q,st-Y*U,H-Y*F,st,H])}return X}function Ie(t,e,n,s,i){const o=1-i;return o*o*o*t+3*o*o*i*e+3*o*i*i*n+i*i*i*s}function th(t,e,n,s,i){const o=1-i;return 3*o*o*(e-t)+6*o*i*(n-e)+3*i*i*(s-n)}function ys(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 Ti(t,e,n){const[s,i,o,r,a,l]=n,c=[0];let h=t,u=e,d=0;for(let f=1;f<=Qc;f++){const p=f/Qc,g=Ie(t,s,o,a,p),m=Ie(e,i,r,l,p);d+=Math.hypot(g-h,m-u),c.push(d),h=g,u=m}return{subpath:0,type:"C",points:[s,i,o,r,a,l],startX:t,startY:e,endX:a,endY:l,length:d,lengths:c}}function Je(t){const e=Tn.get(t);if(e)return e;const n=[];let s=0,i=0,o=0,r=0,a=null,l=null,c=-1;const h=new Set,u=g=>{c<0&&(c=0),g.subpath=c,n.push(g)};for(const{type:g,args:m}of sy(t)){const w=g.toUpperCase(),v=g!==w,k=ny[w];if(w==="Z"){(s!==o||i!==r)&&u(ys(s,i,o,r)),c>=0&&h.add(c),s=o,i=r,a=l=null;continue}for(let y=0;y+k<=m.length;y+=k){const T=m.slice(y,y+k),$=v?s:0,M=v?i:0;let x=null,S=null;switch(w){case"M":y===0?(s=T[0]+$,i=T[1]+M,o=s,r=i,(c<0||n[n.length-1]?.subpath===c)&&c++):(u(ys(s,i,T[0]+$,T[1]+M)),s=T[0]+$,i=T[1]+M);break;case"L":u(ys(s,i,T[0]+$,T[1]+M)),s=T[0]+$,i=T[1]+M;break;case"H":u(ys(s,i,T[0]+$,i)),s=T[0]+$;break;case"V":u(ys(s,i,s,T[0]+M)),i=T[0]+M;break;case"C":{const E=[T[0]+$,T[1]+M,T[2]+$,T[3]+M,T[4]+$,T[5]+M];u(Ti(s,i,E)),x=[E[2],E[3]],s=E[4],i=E[5];break}case"S":{const[E,P]=a?[2*s-a[0],2*i-a[1]]:[s,i],A=[E,P,T[0]+$,T[1]+M,T[2]+$,T[3]+M];u(Ti(s,i,A)),x=[A[2],A[3]],s=A[4],i=A[5];break}case"Q":case"T":{let E=s,P=i;w==="Q"?(E=T[0]+$,P=T[1]+M):l&&(E=2*s-l[0],P=2*i-l[1]);const A=w==="Q"?T[2]+$:T[0]+$,I=w==="Q"?T[3]+M:T[1]+M;u(Ti(s,i,[s+2/3*(E-s),i+2/3*(P-i),A+2/3*(E-A),I+2/3*(P-I),A,I])),S=[E,P],s=A,i=I;break}case"A":{const E=T[5]+$,P=T[6]+M;let A=s,I=i;for(const _ of iy(s,i,T[0],T[1],T[2],T[3],T[4],E,P))u(Ti(A,I,_)),A=_[4],I=_[5];s=E,i=P;break}}a=x,l=S}}const d=n.reduce((g,m)=>g+m.length,0),f=[];for(let g=0;g<n.length;){const m=n[g].subpath;let w=g,v=0;for(;w<n.length&&n[w].subpath===m;)v+=n[w++].length;const k=n[g],y=n[w-1],T=h.has(m)||Math.abs(y.endX-k.startX)<1e-9&&Math.abs(y.endY-k.startY)<1e-9;f.push({start:g,end:w,length:v,closed:T}),g=w}const p={segments:n,totalLength:d,subpaths:f};return Tn.size>=Qm&&Tn.delete(Tn.keys().next().value),Tn.set(t,p),p}function oy(t,e){const n=t.lengths;if(e<=0)return 0;if(e>=t.length)return 1;let s=0,i=n.length-1;for(;s<i-1;){const a=s+i>>1;n[a]<e?s=a:i=a}const o=n[i]-n[s],r=o>0?(e-n[s])/o:0;return(s+r)/(n.length-1)}function ry(t,e){if(t.type==="L"){const u=t.length>0?Math.max(0,Math.min(1,e/t.length)):0;return{x:t.startX+(t.endX-t.startX)*u,y:t.startY+(t.endY-t.startY)*u,angle:Math.atan2(t.endY-t.startY,t.endX-t.startX)*180/Math.PI}}const[n,s,i,o,r,a]=t.points,l=oy(t,e);let c=th(t.startX,n,i,r,l),h=th(t.startY,s,o,a,l);if(Math.hypot(c,h)<1e-9){const u=l<.5?Math.min(1,l+.001):Math.max(0,l-.001),d=Ie(t.startX,n,i,r,u),f=Ie(t.startY,s,o,a,u),p=Ie(t.startX,n,i,r,l),g=Ie(t.startY,s,o,a,l);c=l<.5?d-p:p-d,h=l<.5?f-g:g-f}return{x:Ie(t.startX,n,i,r,l),y:Ie(t.startY,s,o,a,l),angle:Math.atan2(h,c)*180/Math.PI}}function vr(t,e,n=0,s=t.length){if(s<=n)return{x:0,y:0,angle:0};let i=0;for(let o=n;o<s;o++){const r=t[o];if(i+r.length>=e||o===s-1)return ry(r,e-i);i+=r.length}return{x:0,y:0,angle:0}}function eh(t,e){const{segments:n,totalLength:s}=Je(t);return vr(n,Math.max(0,Math.min(1,e))*s)}function ay(){Tn.clear()}function ly(t){return Je(t).totalLength}const cy=24,hy=320,uy=2.5,bs=72,dy=64,fy=.2,gy=128,ws=new Map;let Ei=0,Oe;const nh=t=>Math.round(t*100)/100;function sh(t,e){const{segments:n,subpaths:s,totalLength:i}=Je(t);if(n.length===0)return[];if(e){const o=s.every(r=>r.closed);return[{segments:n,start:0,end:n.length,length:i,closed:o}]}return s.filter(o=>o.length>0).map(o=>({segments:n,start:o.start,end:o.end,length:o.length,closed:o.closed}))}function Mr(t,e){const n=t.closed?(e%1+1)%1:Math.max(0,Math.min(1,e)),s=vr(t.segments,n*t.length,t.start,t.end);return[s.x,s.y]}function ih(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 oh(t,e){const n=[];for(let s=0;s<e;s++)n.push(Mr(t,t.closed?s/e:s/(e-1)));return n}function rh(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 py(t,e,n){const s=t.closed&&e.closed;if(n!==void 0)return{offset:s?Math.abs(n)%bs/bs:0,reversed:n<0};const i=rh(oh(t,bs)),o=rh(oh(e,bs)),r=bs;let a={offset:0,reversed:!1},l=1/0;for(const c of[!1,!0]){const h=s?r:1;for(let u=0;u<h;u++){let d=0;for(let f=0;f<r&&d<l;f++){const p=s?c?(u-f+r)%r:(f+u)%r:c?r-1-f:f,g=i[f][0]-o[p][0],m=i[f][1]-o[p][1];d+=g*g+m*m}d<l&&(l=d,a={offset:s?u/r:0,reversed:c})}}return a}function my(t,e,n){return n?((e.reversed?e.offset-t:t+e.offset)%1+1)%1:e.reversed?1-t:t}function yy(t,e,n){return n?((e.reversed?e.offset-t:t-e.offset)%1+1)%1:e.reversed?1-t:t}function by(t,e,n){const s=t.closed&&e.closed,i=py(t,e,n.shapeIndex),o=Math.max(cy,Math.min(hy,Math.ceil(Math.max(t.length,e.length)/uy))),r=new Set,a=u=>r.add(Math.round(u*1e7)/1e7);for(let u=0;u<=o;u++)a(u/o);for(const u of ih(t))a(u);for(const u of ih(e))a(yy(u,i,s));let l=[...r].sort((u,d)=>u-d);s&&(l=l.filter(u=>u<1));const c=[],h=[];for(const u of l)c.push(...Mr(t,u)),h.push(...Mr(e,my(u,i,s)));return wy({from:c,to:h,closed:s})}function wy(t){const e=t.from.length/2;if(e<=3)return t;const n=new Uint8Array(e);n[0]=1,n[e-1]=1;const s=[[0,e-1]];for(;s.length>0;){const[r,a]=s.pop();let l=-1,c=fy;for(let h=r+1;h<a;h++){const u=Math.max(ah(t.from,r,a,h),ah(t.to,r,a,h));u>c&&(c=u,l=h)}l!==-1&&(n[l]=1,s.push([r,l],[l,a]))}const i=[],o=[];for(let r=0;r<e;r++)n[r]&&(i.push(t.from[r*2],t.from[r*2+1]),o.push(t.to[r*2],t.to[r*2+1]));return{from:i,to:o,closed:t.closed}}function ah(t,e,n,s){const i=t[e*2],o=t[e*2+1],r=t[n*2]-i,a=t[n*2+1]-o,l=t[s*2]-i,c=t[s*2+1]-o,h=r*r+a*a,u=h===0?0:Math.max(0,Math.min(1,(l*r+c*a)/h));return Math.hypot(l-u*r,c-u*a)}function ky(t,e,n){const s=n.shapeIndex;if(Oe&&Oe.from===t&&Oe.to===e&&Oe.shapeIndex===s)return Oe.plan;const o=ws.get(String(s??"auto"))?.get(t)?.get(e);if(o)return Oe={from:t,to:e,shapeIndex:s,plan:o},o;const r=Je(t).subpaths.filter(f=>f.length>0).length===Je(e).subpaths.filter(f=>f.length>0).length,a=sh(t,!r),l=sh(e,!r),c={pairs:a.map((f,p)=>by(f,l[p],n))};Ei>=gy&&(ws.clear(),Ei=0);const h=String(s??"auto"),u=ws.get(h)??new Map;ws.set(h,u);const d=u.get(t)??new Map;return u.set(t,d),d.set(e,c),Ei++,Oe={from:t,to:e,shapeIndex:s,plan:c},c}function lh(t,e,n,s={}){if(!t)return e;if(!e)return t;const i=Math.max(0,Math.min(1,n));if(i===0)return t;if(i===1)return e;const o=ky(t,e,s);if(o.pairs.length===0)return i<.5?t:e;let r="";for(const a of o.pairs){for(let l=0;l<a.from.length;l+=2){const c=nh(a.from[l]+(a.to[l]-a.from[l])*i),h=nh(a.from[l+1]+(a.to[l+1]-a.from[l+1])*i);r+=`${l===0?r?" M":"M":" L"}${c} ${h}`}a.closed&&(r+=" Z")}return r}function vy(){ws.clear(),Ei=0,Oe=void 0}function En(t){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(t)}const An=Math.PI/180,My=.9995;function Sr(){return[0,0,0,1]}function ee(t,e){const n=Math.hypot(t[0],t[1],t[2]);if(n===0)return Sr();const s=e*An/2,i=Math.sin(s)/n;return[t[0]*i,t[1]*i,t[2]*i,Math.cos(s)]}function Sy(t,e,n){return xr(xr(ee([0,1,0],e),ee([1,0,0],t)),ee([0,0,1],n))}function xy(t){const[e,n,s,i]=_e(t),o=2*(e*s+n*i),r=2*(e*n+s*i),a=1-2*(e*e+s*s),l=2*(n*s-e*i),c=1-2*(n*n+s*s),h=2*(e*s-n*i),u=1-2*(e*e+n*n),d=Math.asin(Math.max(-1,Math.min(1,-l)));return Math.abs(l)<.9999999?[d/An,Math.atan2(o,u)/An,Math.atan2(r,a)/An]:[d/An,Math.atan2(-h,c)/An,0]}function xr(t,e){const[n,s,i,o]=t,[r,a,l,c]=e;return[o*r+n*c+s*l-i*a,o*a-n*l+s*c+i*r,o*l+n*a-s*r+i*c,o*c-n*r-s*a-i*l]}function ch(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function hh(t){return Math.hypot(t[0],t[1],t[2],t[3])}function _e(t){const e=hh(t);return e===0?Sr():[t[0]/e,t[1]/e,t[2]/e,t[3]/e]}function Ty(t){return[-t[0],-t[1],-t[2],t[3]]}function uh(t,e,n){const s=_e(t);let i=_e(e),o=ch(s,i);if(o<0&&(i=[-i[0],-i[1],-i[2],-i[3]],o=-o),o>My)return _e([s[0]+(i[0]-s[0])*n,s[1]+(i[1]-s[1])*n,s[2]+(i[2]-s[2])*n,s[3]+(i[3]-s[3])*n]);const r=Math.acos(o),a=Math.sin(r),l=Math.sin((1-n)*r)/a,c=Math.sin(n*r)/a;return _e([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 Ey(t,e){const[n,s,i,o]=_e(t),r=2*(s*e[2]-i*e[1]),a=2*(i*e[0]-n*e[2]),l=2*(n*e[1]-s*e[0]);return[e[0]+o*r+(s*l-i*a),e[1]+o*a+(i*r-n*l),e[2]+o*l+(n*a-s*r)]}const Ay=Object.freeze(Object.defineProperty({__proto__:null,conjugate:Ty,dot:ch,fromAxisAngle:ee,fromEuler:Sy,identity:Sr,length:hh,multiply:xr,normalize:_e,rotateVec3:Ey,slerp:uh,toEuler:xy},Symbol.toStringTag,{value:"Module"})),ue=(t,e,n)=>t+(e-t)*n,dh=512,Tr=new Map,Er=new Map;function fh(t){const e=Tr.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 Tr.size<dh&&Tr.set(t,s),s}const gh=t=>t.charCodeAt(0)===35,ph=t=>t.startsWith("rgb"),mh=t=>t.startsWith("rgba"),Py=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,Ar=t=>Math.round(t).toString(16).padStart(2,"0");function $y(t,e,n){return`#${Ar(t)}${Ar(e)}${Ar(n)}`}function yh(t){const e=Er.get(t);if(e)return e;const n=t.match(Py);if(!n)throw new Error(`Invalid rgb color: ${t}`);const s=parseInt(n[1],10),i=parseInt(n[2],10),o=parseInt(n[3],10),r=n[4]!==void 0?[s,i,o,parseFloat(n[4])]:[s,i,o];return Er.size<dh&&Er.set(t,r),r}const bh=(t,e,n)=>{if(gh(t)&&gh(e)){const[s,i,o]=fh(t),[r,a,l]=fh(e),c=ue(s,r,n),h=ue(i,a,n),u=ue(o,l,n);return $y(c,h,u)}if((ph(t)||mh(t))&&(ph(e)||mh(e))){const s=yh(t),i=yh(e),o=Math.round(ue(s[0],i[0],n)),r=Math.round(ue(s[1],i[1],n)),a=Math.round(ue(s[2],i[2],n));if(s.length===4||i.length===4){const l=s[3]??1,c=i[3]??1,h=ue(l,c,n);return`rgba(${o}, ${r}, ${a}, ${h})`}return`rgb(${o}, ${r}, ${a})`}return n<1?t:e},wh=(t,e,n)=>{const s=Math.min(t.length,e.length),i=[];for(let o=0;o<s;o++)i.push(ue(t[o],e[o],n));return i},kh=(t,e,n)=>uh(t,e,n),Pr=(t,e,n)=>n<1?t:e,vh=(t,e,n)=>lh(t,e,n);function ks(t,e){return e==="slerp"?kh:typeof t=="number"?ue:Array.isArray(t)?wh:typeof t=="string"?t.startsWith("#")||t.startsWith("rgb")?bh:En(t)?vh:Pr:Pr}const $r=1e3/60;function Ir(t,e={}){if(!$e(t))throw new Error(`bakeSpringTrack: track "${t.id}" is not a spring track`);const n=new gs(t.spring);return Mh(t,s=>n.valueAt(s),n.settleTime(),t.spring.from,t.spring.to,e)}function Or(t,e={}){if(!Pe(t))throw new Error(`bakeInertiaTrack: track "${t.id}" is not an inertia track`);const n=t.inertia;return Mh(t,s=>Si(n,s),xn(n),n.from,Sn(n),e)}function Mh(t,e,n,s,i,o){const r=o.intervalMs??$r,a=o.tolerance??.01,l=t.delay??0,c=[];for(let u=0;u<=n;u+=r)c.push({time:u+l,value:e(u),easing:"linear"});const h=c[c.length-1];return!h||h.time<n+l?c.push({time:n+l,value:i,easing:"linear"}):h.value=i,l>0&&c.unshift({time:0,value:s,easing:"linear"}),{id:t.id,target:t.target,property:t.property,keyframes:a>0?xh(c,a):c,...t.targets&&{targets:[...t.targets]},...t.stagger&&{stagger:{...t.stagger}}}}function _r(t,e,n,s={}){const i=s.intervalMs??$r,o=typeof n=="function"?n:Lt(n),r=ks(t.value,s.interpolation),a=e.time-t.time;if(a<=0)return[e];const l=[];for(let h=i;h<a;h+=i){const u=h/a;l.push({time:t.time+h,value:r(t.value,e.value,o(u)),easing:"linear"})}const c=o(1);return l.push({...e,...c!==1&&{value:r(t.value,e.value,c)},easing:"linear"}),l}function Iy(t,e){return $e(t)?Ir(t,e):Pe(t)?Or(t,e):t}function Sh(t,e={}){const n=t.keyframes;if(!n.some(o=>ds(o.easing)))return t;const s=n.length>0?[n[0]]:[],i={...e,interpolation:t.interpolation??e.interpolation};for(let o=1;o<n.length;o++){const r=n[o];ds(r.easing)?s.push(..._r(n[o-1],r,r.easing,i)):s.push(r)}return{...t,keyframes:s}}function Oy(t,e){return t.filter(Nc).map(n=>Sh(n,e)).concat(t.filter($e).map(n=>Ir(n,e)),t.filter(Pe).map(n=>Or(n,e)))}function xh(t,e){if(t.length<=2)return t;const n=[t[0]];for(let s=1;s<t.length-1;s++){const i=n[n.length-1],o=t[s],r=t[s+1],a=r.time-i.time;if(a<=0)continue;const l=(o.time-i.time)/a,c=i.value+(r.value-i.value)*l;Math.abs(o.value-c)>e&&n.push(o)}return n.push(t[t.length-1]),n}function Ai(t){const e=[...t.keyframes].sort((n,s)=>n.time-s.time);return{...t,keyframes:e}}function Ce(t){return t.targets&&t.targets.length>0?t.targets:[t.target]}function Pn(t,e,n,s){const i=n??0;return!s||e<=1?i:i+bi(t,e,s)}class vs{track;targets;constructor(e){this.track=e,this.targets=Ce(e)}getValueAtTime(e){return this.valueForOffset(e-Pn(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const o=Pn(i,n,this.track.delay,this.track.stagger),r=this.valueForOffset(e-o);r!==void 0&&s.push({target:this.targets[i],value:r,start:o+this.track.keyframes[0].time})}return s}getDuration(){const{keyframes:e}=this.track;if(e.length===0)return 0;const n=e[e.length-1].time,s=this.track.stagger?fs(this.targets.length,this.track.stagger):0;return n+(this.track.delay??0)+s+(this.track.endDelay??0)}getTrack(){return this.track}valueForOffset(e){const{keyframes:n}=this.track;if(n.length===0)return;if(n.length===1||e<=n[0].time)return n[0].value;if(e>=n[n.length-1].time)return n[n.length-1].value;const{from:s,to:i}=this.findSurroundingKeyframes(e);if(!s||!i)return;if(s.time===e)return s.value;const o=i.time-s.time,r=(e-s.time)/o,l=Lt(i.easing)(r);return ks(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 Th{track;targets;sampler;constructor(e){this.track=e,this.targets=Ce(e),this.sampler=new gs(e.spring)}getValueAtTime(e){return this.sampler.valueAt(e-Pn(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const o=Pn(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:this.sampler.valueAt(e-o),start:o})}return s}getDuration(){const e=this.track.stagger?fs(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+e}getTrack(){return this.track}}class Eh{track;targets;duration;constructor(e){this.track=e,this.targets=Ce(e),this.duration=xn(e.inertia)}getValueAtTime(e){return Si(this.track.inertia,e-Pn(0,this.targets.length,this.track.delay,this.track.stagger))}getTargetValues(e){const n=this.targets.length,s=[];for(let i=0;i<n;i++){const o=Pn(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:Si(this.track.inertia,e-o),start:o})}return s}getDuration(){const e=this.track.stagger?fs(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+e}getTrack(){return this.track}}function Cr(t,e){const n={...eh(t.pathData,e)};if(t.matrix){const[s,i,o,r,a,l]=t.matrix,{x:c,y:h}=n;n.x=s*c+o*h+a,n.y=i*c+r*h+l;const u=n.angle*Math.PI/180,d=Math.cos(u),f=Math.sin(u);n.angle=Math.atan2(i*d+r*f,s*d+o*f)*180/Math.PI}return t.autoRotate&&t.rotateOffset&&(n.angle+=t.rotateOffset),n}function _y(t,e,n,s){const i=e+(n-e)*s;return Cr(t,i)}const Hr={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},Cy=20;function Ah(t){const e=Hr[t??"upperCase"]??t??Hr.upperCase,n=Array.from(e);return n.length>0?n:Array.from(Hr.upperCase)}function Hy(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 Ph(t,e,n=0){const s=t.from??"",i=t.to,o=Math.max(0,Math.min(1,e));if(o<=0)return s;if(o>=1)return i;const r=Array.from(s),a=Array.from(i),l=t.rightToLeft??!1;if(t.mode==="type"){const v=Math.round(o*Math.max(r.length,a.length));return l?r.slice(0,Math.max(0,r.length-v)).join("")+a.slice(Math.max(0,a.length-v)).join(""):a.slice(0,v).join("")+r.slice(v).join("")}const c=Math.max(0,Math.min(.999,t.revealDelay??0)),h=Math.max(0,(o-c)/(1-c)),u=Math.floor(h*a.length),d=t.tweenLength===!1?a.length:Math.round(r.length+(a.length-r.length)*o),f=Ah(t.chars),p=t.refreshRate??Cy,g=p>0?Math.floor(n*p/1e3):0,m=t.seed??1;let w="";for(let v=0;v<d;v++){const k=l?v>=d-u:v<u,y=l?a[a.length-(d-v)]:a[v];k&&y!==void 0||y===" "||y===`
|
|
2
|
+
`?w+=y:w+=f[Hy(m,v,g)%f.length]}return w}class It{id;name;_captions;_tracks=[];_trackPlayers=new Map;_motionPathTracks=new Map;_springTracks=new Map;_textTracks=new Map;_config;_currentTime=0;_playbackState="idle";_direction="forward";_loopIteration=0;_explicitDuration;_repeatDelayRemaining=0;_wrapAfterDelay=!1;onUpdate=null;onComplete=null;constructor(e){if(this.id=e.id,this.name=e.name,this._captions=e.captions,this._config=e.config??{},this._explicitDuration=e.config?.duration,e.tracks)for(const n of e.tracks)this.addTrack(n)}get tracks(){return[...this._tracks]}get duration(){return this._explicitDuration!==void 0?this._explicitDuration:this._calculateDuration()}setDuration(e){if(this._explicitDuration=e,e!==void 0)this._config={...this._config,duration:e};else if(this._config.duration!==void 0){const n={...this._config};delete n.duration,this._config=n}}get currentTime(){return this._currentTime}get playbackState(){return this._playbackState}get direction(){return this._direction}get loopIteration(){return this._loopIteration}get repeatDelayRemaining(){return this._repeatDelayRemaining}get speed(){return this._config.speed??1}set speed(e){this._config.speed=e}get drawingRate(){return this._config.drawingRate??0}set drawingRate(e){const n={...this._config};e>0?n.drawingRate=e:delete n.drawingRate,this._config=n}play(){const e=this.duration;this._direction==="forward"&&this._currentTime>=e&&e>0?(this._currentTime=0,this._loopIteration=0):this._direction==="reverse"&&this._currentTime<=0&&e>0&&(this._currentTime=e,this._loopIteration=0),this._playbackState="playing"}pause(){this._playbackState="paused"}stop(){this._playbackState="idle",this._repeatDelayRemaining=0,this._wrapAfterDelay=!1,this._currentTime=0,this._loopIteration=0,this._direction="forward"}seek(e){const n=this.duration>0?this.duration:1/0;this._currentTime=Math.max(0,Math.min(e,n)),this._repeatDelayRemaining=0,this._wrapAfterDelay=!1}reverse(){this._direction=this._direction==="forward"?"reverse":"forward"}tick(e){if(this._playbackState!=="playing")return;const n=this.duration;if(n<=0)return;let i=e*this.speed;if(this._repeatDelayRemaining>0){const a=Math.min(this._repeatDelayRemaining,i);if(this._repeatDelayRemaining-=a,i-=a,this._repeatDelayRemaining>0){this.onUpdate?.(this.getStateAtTime(this._currentTime));return}this._wrapAfterDelay&&(this._wrapAfterDelay=!1,this._currentTime=0)}const o=1e3;for(let a=0;a<o&&i>0&&this._playbackState==="playing";a++)if(this._direction==="forward"){const l=n-this._currentTime;if(i>=l){if(i-=l,this._currentTime=n,!this._handleEndReached())break}else this._currentTime+=i,i=0}else{const l=this._currentTime;if(i>=l){if(i-=l,this._currentTime=0,!this._handleStartReached())break}else this._currentTime-=i,i=0}const r=this.getStateAtTime(this._currentTime);this.onUpdate?.(r)}getStateAtTime(e){const n=new Map;if(e=Fc(e,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(e,n);else for(const[s,i]of this._trackPlayers){const o=i.getTrack().property;for(const{target:r,value:a,start:l}of i.getTargetValues(e))this._write(n,s,r,o,a,e-l)}return{values:n,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(e,n){const s=new Map;for(const[i,o]of this._trackPlayers){const r=o.getTrack().property;for(const{target:a,value:l,start:c}of o.getTargetValues(e)){const h=`${a}\0${r}`,u=c<=e,d=s.get(h);(!d||(u!==d.started?u:u?c>=d.start:c<=d.start))&&s.set(h,{trackId:i,target:a,property:r,value:l,start:c,started:u})}}for(const{trackId:i,target:o,property:r,value:a,start:l}of s.values())this._write(n,i,o,r,a,e-l)}_write(e,n,s,i,o,r){if(o===void 0)return;let a=e.get(s);a||(a=new Map,e.set(s,a));const l=this._textTracks.get(n);if(l&&typeof o=="number"){a.set("text",Ph(l.textConfig,o,Math.max(0,r)));return}const c=this._motionPathTracks.get(n);if(c&&typeof o=="number"){const h=Cr(c.motionPathConfig,o);a.set("motionPathX",h.x),a.set("motionPathY",h.y),c.motionPathConfig.autoRotate&&a.set("motionPathRotate",h.angle)}else a.set(i,o)}_sharedWrites=null;_hasSharedWrites(){if(this._sharedWrites===null){const e=new Set;this._sharedWrites=!1;t:for(const n of this._tracks)for(const s of Ce(n)){const i=`${s}\0${n.property}`;if(e.has(i)){this._sharedWrites=!0;break t}e.add(i)}}return this._sharedWrites}addTrack(e){if(this._tracks.push(e),this._sharedWrites=null,Pe(e)){this._trackPlayers.set(e.id,new Eh(e));return}if($e(e)){this._trackPlayers.set(e.id,new Th(e)),this._springTracks.set(e.id,e);return}if(yi(e))this._trackPlayers.set(e.id,new vs(e)),this._textTracks.set(e.id,e);else if(fr(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 vs(n)),this._motionPathTracks.set(e.id,e)}else this._trackPlayers.set(e.id,new vs(e))}replaceTrack(e,n){const s=this._tracks.findIndex(o=>o.id===e);if(s<0)return;const i=this._tracks.slice(s+1);this.removeTrack(e);for(const o of i)this.removeTrack(o.id);this.addTrack(n);for(const o of i)this.addTrack(o)}removeTrack(e){this._tracks=this._tracks.filter(n=>n.id!==e),this._sharedWrites=null,this._trackPlayers.delete(e),this._motionPathTracks.delete(e),this._springTracks.delete(e),this._textTracks.delete(e)}getTracks(e={}){return this._tracks.filter(n=>this._matches(n,e))}removeTracks(e={}){const n=this.getTracks(e).map(s=>s.id);for(const s of n)this.removeTrack(s);return n}getTrackSpan(e){const n=this._trackPlayers.get(e);if(!n)return;const s=n.getTrack(),i=s.delay??0;if($e(s)||Pe(s))return{from:i,to:n.getDuration()};const o=s.keyframes;if(!(!o||o.length===0))return{from:o[0].time+i,to:n.getDuration()}}findConflicts(){const e=[];for(let n=0;n<this._tracks.length;n++){const s=this._tracks[n],i=this.getTrackSpan(s.id);if(i)for(let o=0;o<n;o++){const r=this._tracks[o];if(r.property!==s.property)continue;const a=Ce(r).filter(u=>Ce(s).includes(u));if(a.length===0)continue;const l=this.getTrackSpan(r.id);if(!l||!(l.from<=i.to&&i.from<=l.to))continue;const h=i.from>=l.from;for(const u of a)e.push({target:u,property:s.property,losingTrackId:h?r.id:s.id,winningTrackId:h?s.id:r.id})}}return e}_matches(e,n){if(n.id!==void 0&&e.id!==n.id||n.property!==void 0&&e.property!==n.property||n.target!==void 0&&!Ce(e).includes(n.target))return!1;if(n.timeRange){const s=this.getTrackSpan(e.id);if(!s||s.to<n.timeRange.from||s.from>n.timeRange.to)return!1}return!0}toDefinition(){return{formatVersion:dr(this._tracks),id:this.id,name:this.name,config:{...this._config},tracks:[...this._tracks],...this.captions&&{captions:this.captions}}}get config(){return this._config}get markers(){return[...this._config.markers??[]].sort((e,n)=>e.time-n.time)}setMarkers(e){const n=e&&e.length>0?[...e].sort((i,o)=>i.time-o.time).map(i=>({...i})):void 0,s={...this._config};n?s.markers=n:delete s.markers,this._config=s}get captions(){return this._captions}setCaptions(e){const n={};for(const[s,i]of Object.entries(e??{}))n[s]={...i};this._captions=Object.keys(n).length>0?n:void 0}_armRepeatDelay(){this._repeatDelayRemaining=this._config.repeatDelay??0}_calculateDuration(){let e=0;for(const[,n]of this._trackPlayers)e=Math.max(e,n.getDuration());return e}_handleEndReached(){const e=this._config.loop??0;return e===-1||this._loopIteration<e?(this._loopIteration++,this._armRepeatDelay(),this._config.alternate?this._direction="reverse":this._repeatDelayRemaining>0?this._wrapAfterDelay=!0:this._currentTime=0,this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}_handleStartReached(){const e=this._config.loop??0;return this._config.alternate&&(e===-1||this._loopIteration<e)?(this._loopIteration++,this._armRepeatDelay(),this._direction="forward",this._repeatDelayRemaining===0):(this._playbackState="idle",this.onComplete?.(),!1)}}const Ry=100;function Rr(t,e,n,s){const i=[],o=[],{duration:r,alternate:a}=s,l=(f,p,g,m)=>{o.push([f,p]);const w=[];t.forEach((v,k)=>{(g==="forward"?(m?v>=f:v>f)&&v<=p:(m?v<=f:v<f)&&v>=p)&&w.push(k)}),w.sort((v,k)=>(g==="forward"?t[v]-t[k]:t[k]-t[v])||v-k);for(const v of w)i.push({kind:"event",index:v,direction:g})};let c=e.time,h=e.direction,u=e.fresh===!0;const d=Math.min(Ry,Math.max(0,n.iteration-e.iteration));for(let f=0;f<d;f++){const p=h==="forward"?r:0;l(c,p,h,u),i.push({kind:"repeat"}),a?(h=h==="forward"?"reverse":"forward",c=p,u=!1):(c=h==="forward"?0:r,u=!0)}return d>0&&s.holding&&!a?{crossings:i,passes:o}:(l(c,n.time,h,u),{crossings:i,passes:o})}function $h(t){return Pe(t)?{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:Ih(t.inertia),...de(t)}:$e(t)?{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...de(t)}:yi(t)?{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:t.keyframes.map(Lr),...de(t)}:fr(t)?{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:t.keyframes.map(Lr),...de(t)}:{id:t.id,target:t.target,property:t.property,keyframes:t.keyframes.map(Lr),...t.interpolation!==void 0&&{interpolation:t.interpolation},...de(t)}}function Ih(t){return{...t,...Array.isArray(t.end)&&{end:[...t.end]}}}function Lr(t){return{time:t.time,value:t.value,...t.easing&&{easing:t.easing}}}function de(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 Oh(t){if(Pe(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"inertia",inertia:Ih(e.inertia),...de(e)}}if($e(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"spring",spring:{...e.spring},...de(e)}}if(yi(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),...de(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,...de(e)}}return Ai({id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,...t.interpolation!==void 0&&{interpolation:t.interpolation},...de(t)})}function _h(t){const e=t._config.markers;return{formatVersion:dr(t.tracks),id:t.id,name:t.name,config:{duration:t.duration>0?t.duration:void 0,loop:t._config.loop,speed:t._config.speed,alternate:t._config.alternate,repeatDelay:t._config.repeatDelay,...t._config.drawingRate?{drawingRate:t._config.drawingRate}:{},...e&&{markers:e.map(n=>({...n}))}},tracks:t.tracks.map($h),...t.captions&&{captions:JSON.parse(JSON.stringify(t.captions))}}}function $n(t){const e=t.formatVersion??1;if(e>ur)throw new Error(`tinyfly: this animation uses format version ${e}, but this tinyfly reads up to version ${ur}. Update tinyfly to play it.`);return new It({id:t.id,name:t.name,config:t.config,tracks:t.tracks.map(Oh),captions:t.captions})}function Ly(t){return JSON.stringify(_h(t))}function Ny(t){const e=JSON.parse(t);return $n(e)}function Xt(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 He(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 Nr(t,e,n){return e+t.next()*(n-e)}function Ch(t,e,n,s){if(s<=0)return Nr(t,e,n);const i=Math.floor((n-e)/s),o=Math.round(t.next()*i);return e+o*s}function Fy(t,e){if(e.length!==0)return e[Math.floor(t.next()*e.length)]}const Hh=/^([+\-*/])=\s*(-?[\d.]+)$/,Rh=/^random\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*(?:,\s*(-?[\d.]+)\s*)?\)$/i;function Wy(t){return typeof t!="string"?!1:Hh.test(t.trim())||Rh.test(t.trim())}function Fr(t,e={}){if(typeof t!="string")return t;const n=t.trim(),s=Hh.exec(n);if(s){const[,o,r]=s,a=e.base??0,l=Number.parseFloat(r);switch(o){case"+":return a+l;case"-":return a-l;case"*":return a*l;case"/":return l===0?a:a/l}}const i=Rh.exec(n);if(i){if(!e.random)throw new Error(`resolveValue: "${n}" needs a random source — pass one via context.random`);const o=Number.parseFloat(i[1]),r=Number.parseFloat(i[2]),a=i[3]!==void 0?Number.parseFloat(i[3]):void 0;return a!==void 0?Ch(e.random,o,r,a):Nr(e.random,o,r)}return t}function Lh(t,e=0,n){const s=[];let i=e;for(const o of t){const r=Fr(o,{base:i,random:n});s.push(r),typeof r=="number"&&(i=r)}return s}class Dy{random;constructor(e){this.random=He(e)}get seed(){return this.random.seed}resolve(e,n=0){return Fr(e,{base:n,random:this.random})}resolveSequence(e,n=0){return Lh(e,n,this.random)}}const By=600;function Nh(t){if(Array.isArray(t)){const[d,f,p,g]=t;return{fn:Dh(d,f,p,g),bezier:[d,f,p,g]}}const{segments:e}=Je(t);if(e.length===0)throw new Error(`customEase: no curve in "${t}"`);const n=e[0].startX,s=e[0].startY,i=e[e.length-1],o=i.endX-n,r=i.endY-s;if(o===0||r===0)throw new Error(`customEase: "${t}" must move along both axes`);const a=d=>(d-n)/o,l=d=>(d-s)/r;if(e.length===1&&i.type==="C"){const[d,f,p,g]=i.points,m=[a(d),l(f),a(p),l(g)];return{fn:Dh(...m),bezier:m}}const c=[],h=[],u=Math.max(8,Math.ceil(By/e.length));for(const d of e)for(let f=c.length===0?0:1;f<=u;f++){const[p,g]=zy(d,f/u);c.push(a(p)),h.push(l(g))}return{fn:qy(c,h)}}function Fh(t={}){const n=.1+Math.max(0,Math.min(1,t.strength??.7))*.7,s=[1];for(let o=n;o>.002;o*=n)s.push(2*Math.sqrt(o));const i=s.reduce((o,r)=>o+r,0);return o=>{if(o<=0)return 0;if(o>=1)return 1;let r=o*i;for(let a=0;a<s.length;a++){if(r<=s[a]){if(a===0)return(r/s[0])**2;const l=s[a]/2,c=l*l,h=r-l;return 1-(c-h*h)}r-=s[a]}return 1}}function Wh(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 zy(t,e){if(t.type==="L"){const[c,h]=t.points;return[t.startX+(c-t.startX)*e,t.startY+(h-t.startY)*e]}const[n,s,i,o,r,a]=t.points,l=1-e;return[l*l*l*t.startX+3*l*l*e*n+3*l*e*e*i+e*e*e*r,l*l*l*t.startY+3*l*l*e*s+3*l*e*e*o+e*e*e*a]}function qy(t,e){return n=>{if(n<=t[0])return e[0];if(n>=t[t.length-1])return e[e.length-1];let s=0,i=t.length-1;for(;i-s>1;){const r=s+i>>1;t[r]<=n?s=r:i=r}const o=t[i]-t[s];return o===0?e[i]:e[s]+(n-t[s])/o*(e[i]-e[s])}}function Dh(t,e,n,s){const i=(r,a,l)=>3*(1-r)*(1-r)*r*a+3*(1-r)*r*r*l+r*r*r,o=(r,a,l)=>3*(1-r)*(1-r)*a+6*(1-r)*r*(l-a)+3*r*r*(1-l);return r=>{if(r<=0)return 0;if(r>=1)return 1;let a=r;for(let h=0;h<8;h++){const u=i(a,t,n)-r,d=o(a,t,n);if(Math.abs(u)<1e-6)return i(a,e,s);if(Math.abs(d)<1e-6)break;a-=u/d}let l=0,c=1;a=r;for(let h=0;h<40;h++)i(a,t,n)<r?l=a:c=a,a=(l+c)/2;return i(a,e,s)}}const Yy=350,Ky=300,jy=550;function Xy(t,e={}){const n=e.lead??Yy,s=e.gap??Ky,i=e.tail??jy,o=[];let r=0;return t.forEach((a,l)=>{const c=[];let h=r+n;a.lines.forEach((d,f)=>{if(!(d.duration>=0))throw new Error(`narration: scene ${l} line ${f} has an invalid duration (${d.duration})`);f>0&&(h+=s),c.push({id:d.id??`s${l}-l${f}`,scene:l,line:f,start:h,end:h+d.duration,text:d.text}),h+=d.duration});const u=h+i+(a.tail??0);o.push({id:a.id??`s${l}`,start:r,duration:u-r,cues:c}),r=u}),{duration:r,scenes:o,cues:o.flatMap(a=>a.cues)}}function Gy(t){return t.cues.map(e=>({id:e.id,time:e.start,label:e.text}))}function Uy(t,e){let n=t.scenes[0];for(const s of t.scenes)if(e>=s.start)n=s;else break;return n}const Ms=t=>6e4/t.bpm;function Pi(t,e){return t.offset+e*Ms(t)}function Ss(t,e){return(e-t.offset)/Ms(t)}function Vy(t,e){return Pi(t,Math.round(Ss(t,e)))}function Jy(t,e){return Pi(t,Math.ceil(Ss(t,e)-1e-9))}function Zy(t,e,n){const s=Math.max(1,Math.round(t.beatsPerBar??4)),i=[];if(!(t.bpm>0)||n<e)return i;for(let o=Math.ceil(Ss(t,e)-1e-9);;o++){const r=Pi(t,o);if(r>n+1e-9)break;i.push({time:r,bar:(o%s+s)%s===0,n:o})}return i}const In=100;function Qy(t,e,n={}){const s=n.minBpm??70,i=n.maxBpm??180,o=Math.max(1,Math.round(e/In)),r=Math.min(t.length,Math.round((n.maxSeconds??60)*e)),a=Math.floor(r/o);if(a<4)return{bpm:120,offset:0,confidence:0};const l=new Float64Array(a);for(let S=0;S<a;S++){let E=0;for(let P=S*o;P<(S+1)*o;P++)E+=t[P]*t[P];l[S]=Math.log(1e-6+E/o)}const c=new Float64Array(a);for(let S=1;S<a;S++)c[S]=Math.max(0,l[S]-l[S-1]);const h=c.reduce((S,E)=>S+E,0)/a;for(let S=0;S<a;S++)c[S]=Math.max(0,c[S]-h);const u=Math.max(1,Math.floor(60*In/i)),d=Math.min(a-1,Math.ceil(60*In/s)),f=S=>{let E=0;for(let P=S;P<a;P++)E+=c[P]*c[P-S];return E/(a-S)};let p=0;for(let S=0;S<a;S++)p+=c[S]*c[S];p/=a;let g=u,m=-1/0;for(let S=u;S<=d;S++){const E=60*In/S,P=Math.exp(-.5*(Math.log2(E/120)/.9)**2),A=f(S)*P;A>m&&(m=A,g=S)}const w=S=>{const E=Math.floor(S);return E<0||E+1>=a?0:c[E]+(c[E+1]-c[E])*(S-E)},v=(S,E)=>{let P=0;for(let A=E;A<a;A+=S)P+=w(A);return P};let k=g,y=0,T=-1/0;for(let S=g-.6;S<=g+.6+1e-9;S+=.02){if(S<1)continue;const E=Math.max(1,Math.round(S*4));for(let P=0;P<E;P++){const A=P/E*S,I=v(S,A);I>T&&(T=I,y=A,k=S)}}const $=60*In/k,M=p>0?Math.max(0,Math.min(1,f(g)/p)):0,x=(y+.5)*1e3/In;return{bpm:Math.round($*100)/100,offset:Math.round(x%(6e4/$)),confidence:M}}const t1=600,e1=250,Bh=1;function n1(t,e){const n=e.target??"Camera",s={x:e.stage.width/2,y:e.stage.height/2},i={},o=(u,d,f,p)=>{const g=i[u]??=[];for(;g.length>0&&g[g.length-1].time>=d;)g.pop();g.push({time:d,value:f,...p?{easing:p}:{}})},r=u=>{const d=u.rotate*Math.PI/180,f=(u.focusX-s.x)*u.scale,p=(u.focusY-s.y)*u.scale;return{x:-(f*Math.cos(d)-p*Math.sin(d)),y:-(f*Math.sin(d)+p*Math.cos(d)),scale:u.scale,rotate:u.rotate}},a=(u,d,f)=>{const p=r(d);for(const g of["x","y","scale","rotate"])o(g,u,p[g],f)};let l={focusX:s.x,focusY:s.y,scale:1,rotate:0};const c=[...t].sort((u,d)=>u.at-d.at),h=c.filter(u=>!("shake"in u));h.length>0&&a(0,l);for(const u of h)if("frame"in u){const d=Math.max(Bh,u.duration??t1);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>Bh?"ease-in-out":void 0))}else{const{follow:d}=u,f=d.lag??e1,p=new It({id:"follow",tracks:[{id:"x",target:"s",property:"x",keyframes:d.x}]}),g=v=>p.getStateAtTime(v).values.get("s")?.get("x")??l.focusX,m=[u.at,...d.x.map(v=>v.time).filter(v=>v>u.at&&v<u.until),u.until];a(u.at,l);const w=v=>({focusX:g(v)+(d.lead??0),focusY:d.y??l.focusY,scale:d.scale??l.scale,rotate:l.rotate});for(const v of m){const k=d.x.find(y=>y.time===v)?.easing;a(v+f,w(v),v===u.at?"ease-in-out":k)}l=w(u.until)}for(const u of c.filter(d=>"shake"in d)){const d=u.shake.strength??12,f=u.shake.roll??1.5,p=1e3/(u.shake.frequency??24),g=He(u.shake.seed??Math.round(u.at)+1),m=()=>g.next()*2-1;for(const w of["shakeX","shakeY","shakeRotate"])o(w,u.at,0);for(let w=u.at+p;w<u.at+u.duration;w+=p){const v=1-(w-u.at)/u.duration;o("shakeX",w,m()*d*v),o("shakeY",w,m()*d*v),o("shakeRotate",w,m()*f*v)}for(const w of["shakeX","shakeY","shakeRotate"])o(w,u.at+u.duration,0,"ease-out")}return Object.entries(i).map(([u,d])=>({id:`${n}-${u}`,target:n,property:u,keyframes:d}))}function zh(t,e){const n=t.toLowerCase(),s=e.toLowerCase();let i=Array.from({length:s.length+1},(o,r)=>r);for(let o=1;o<=n.length;o++){const r=[o];for(let a=1;a<=s.length;a++)r[a]=Math.min(i[a]+1,r[a-1]+1,i[a-1]+(n[o-1]===s[a-1]?0:1));i=r}return i[s.length]}function xs(t,e){const n=t.toLowerCase(),s=e.find(r=>r.toLowerCase().includes(n)||n.includes(r.toLowerCase()));if(s&&Math.min(t.length,s.length)>=3)return s;let i,o=1/0;for(const r of e){const a=zh(t,r);a<o&&(o=a,i=r)}return i!==void 0&&o<=Math.max(2,Math.floor(t.length/3))?i:void 0}function ft(t,e,n,s){const i=typeof e=="string"?s??xs(e,n):void 0;return`Unknown ${t} ${JSON.stringify(e)}${i?`: did you mean "${i}"?`:"."} Known: ${n.join(", ")}`}function Ts(t,e){const n=e.step??33,s=e.stiffness??120,i=e.damping??9,o=e.mass??1;let r=t(e.start),a=0;const l=[{time:e.start,value:r}];let c=e.start+n;for(let h=e.start+1;h<=e.end;h++){const d=s*(t(h)-r)-i*a;a+=d/o*.001,r+=a*.001,(h>=c||h===e.end)&&(l.push({time:h,value:r}),c+=n)}return l}function Ze(t,e,n=1){if(!(e>0))return 0;const s=t*n/e;return s-Math.floor(s)}function Wr(t){const e=t-Math.floor(t);return 1-Math.abs(e*2-1)}function s1(t,e){const n=Math.max(1,Math.round(e.cycles??1)),s=e.amplitude??1,i=Ze(t,e.period,n)+(e.phase??0),o=i-Math.floor(i);switch(e.shape??"sine"){case"triangle":return s*(Wr(o+.25)*2-1);case"square":return o<.5?s:-s;default:return s*Math.sin(o*Math.PI*2)}}function i1(t,e){const n=Math.max(1,Math.round(e.cycles??1)),s=typeof e.easing=="function"?e.easing:Lt(e.easing??"ease-in-out"),i=Ze(t,e.period,n)+(e.phase??0);return s(Wr(i))}function o1(t,e){const n=qh(e.seed),s=Math.max(1,Math.round(e.cycles??1)),i=(Ze(t,e.period,1)+(e.phase??0))*Math.PI*2,o=s/Math.PI;return Yh([Math.cos(i)*o+7.31,Math.sin(i)*o+3.17],n,e.octaves??1)}function r1(t,e,n){const s=qh(n.seed),i=Math.max(1,Math.round(n.cycles??1)),o=Math.max(1,Math.round(n.cyclesAlong??1)),r=Ze(t,n.period,1)*Math.PI*2,a=Ze(e,n.periodAlong,1)*Math.PI*2,l=i/Math.PI,c=o/Math.PI;return Yh([Math.cos(r)*l+5.13,Math.sin(r)*l+9.47,Math.cos(a)*c+2.71,Math.sin(a)*c+6.29],s,n.octaves??1)}const qh=t=>typeof t=="string"?Xt(t):(t??0)>>>0;function Yh(t,e,n){const s=Math.max(1,Math.min(6,Math.round(n)));let i=0,o=1,r=0;for(let a=0;a<s;a++){const l=2**a;i+=o*a1(t.map(c=>c*l),e+a*1013),r+=o,o*=.5}return i/r}function a1(t,e){const n=t.length,s=t.map(Math.floor),o=t.map((a,l)=>a-s[l]).map(a=>a*a*(3-2*a));let r=0;for(let a=0;a<1<<n;a++){let l=1;const c=[];for(let h=0;h<n;h++){const u=a>>h&1;l*=u?o[h]:1-o[h],c.push(s[h]+u)}l!==0&&(r+=l*l1(c,e))}return r}function l1(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 c1(t,e={}){if(t.length===0)throw new Error("curve: needs at least one key");const s={id:"curve",target:"curve",property:"value",keyframes:t.map(o=>({time:o.at,value:o.value,easing:o.easing})).sort((o,r)=>o.time-r.time),interpolation:e.interpolation},i=new vs(s);return o=>i.getValueAtTime(o)}function h1(t,e){return e*Ms({bpm:t.bpm})}function u1(t,e){const n=Math.max(1,Math.round(t/Ms(e)));return{beats:n,grid:{...e,bpm:n*6e4/t}}}function d1(t,e,n={}){const s=Math.max(1e-6,n.attack??.05),i=Math.max(1e-6,n.decay??.4),o=Ss(e,t),r=o-Math.floor(o),a=r<s?r/s:Math.max(0,1-(r-s)/i),l=n.barAccent??0;if(l<=0)return a;const c=Math.max(1,Math.round(e.beatsPerBar??4)),u=(Math.floor(o)%c+c)%c===0;return a*(u?1+l:1)/(1+l)}function f1(t,e,n={}){const s=n.fps??30,i=Math.max(1,Math.round(e/s)),o=Math.max(1,Math.ceil(t.length/i)),r=new Float32Array(o),a=Math.min(.99,Math.max(0,n.smoothing??.5));let l=0,c=0;for(let h=0;h<o;h++){let u=0;const d=h*i,f=Math.min(t.length,d+i);for(let g=d;g<f;g++)u+=t[g]*t[g];const p=f>d?Math.sqrt(u/(f-d)):0;l=p>l?p:l*a+p*(1-a),r[h]=l,c=Math.max(c,l)}if(n.normalize!==!1&&c>0)for(let h=0;h<o;h++)r[h]/=c;return r}function g1(t,e,n=30,s){if(t.length===0)return 0;const o=(s?Ze(e,s)*s:e)*n/1e3,r=Math.floor(o),a=t[Math.min(t.length-1,Math.max(0,r))],l=t[Math.min(t.length-1,Math.max(0,r+1))];return a+(l-a)*(o-r)}const Kh={"16:9":16/9,"2.39:1":2.39,"4:3":4/3,"1:1":1,"9:16":9/16,"4:5":4/5},Dr=t=>typeof t=="number"?t:Kh[t];function p1(t,e){const n=Dr(e),s=t.width/t.height;if(n>=s){const o=t.width/n;return{x:0,y:(t.height-o)/2,width:t.width,height:o}}const i=t.height*n;return{x:(t.width-i)/2,y:0,width:i,height:t.height}}function m1(t,e){const n=Dr(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 y1(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 fe=t=>Math.round(t*1e3)/1e3;function jh(t,e={}){if(t.length===0)return"";const n=e.curviness??1,s=e.closed??!1,i=t.length;let o=`M${fe(t[0].x)} ${fe(t[0].y)}`;if(i===1)return o;const r=l=>s?t[(l%i+i)%i]:t[Math.max(0,Math.min(i-1,l))],a=s?i:i-1;for(let l=0;l<a;l++){const c=r(l-1),h=r(l),u=r(l+1),d=r(l+2);if(n===0){o+=` L${fe(u.x)} ${fe(u.y)}`;continue}const f=n/6,p=h.x+(u.x-c.x)*f,g=h.y+(u.y-c.y)*f,m=u.x-(d.x-h.x)*f,w=u.y-(d.y-h.y)*f;o+=` C${fe(p)} ${fe(g)} ${fe(m)} ${fe(w)} ${fe(u.x)} ${fe(u.y)}`}return s?`${o} Z`:o}const Nt=(t,e=0)=>{const n=parseFloat(t??"");return Number.isFinite(n)?n:e};function b1(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 $i(t){const e=t.attributes;switch(t.tag.toLowerCase()){case"path":return e.d??null;case"circle":case"ellipse":{const n=Nt(e.cx),s=Nt(e.cy),i=t.tag.toLowerCase()==="circle"?Nt(e.r):Nt(e.rx),o=t.tag.toLowerCase()==="circle"?Nt(e.r):Nt(e.ry);return`M${n+i} ${s} A${i} ${o} 0 1 1 ${n-i} ${s} A${i} ${o} 0 1 1 ${n+i} ${s} Z`}case"rect":{const n=Nt(e.x),s=Nt(e.y),i=Nt(e.width),o=Nt(e.height);let r=e.rx!=null?Nt(e.rx):e.ry!=null?Nt(e.ry):0,a=e.ry!=null?Nt(e.ry):r;return r=Math.min(r,i/2),a=Math.min(a,o/2),r===0||a===0?`M${n} ${s} H${n+i} V${s+o} H${n} Z`:`M${n+r} ${s} H${n+i-r} A${r} ${a} 0 0 1 ${n+i} ${s+a} V${s+o-a} A${r} ${a} 0 0 1 ${n+i-r} ${s+o} H${n+r} A${r} ${a} 0 0 1 ${n} ${s+o-a} V${s+a} A${r} ${a} 0 0 1 ${n+r} ${s} Z`}case"line":return`M${Nt(e.x1)} ${Nt(e.y1)} L${Nt(e.x2)} ${Nt(e.y2)}`;case"polyline":case"polygon":{const n=b1(e.points);if(n.length===0)return null;const s=n.map((i,o)=>`${o===0?"M":"L"}${i.x} ${i.y}`).join(" ");return t.tag.toLowerCase()==="polygon"?`${s} Z`:s}default:return null}}function w1(t,e,n){const s=Math.max(2,Math.round(n.samples??32)),i=Math.max(0,n.length),o=n.since!==void 0?Math.max(e-i,n.since):e-i;if(o>=e)return[];const r=n.period,a=[];for(let l=0;l<s;l++){const c=o+(e-o)*l/(s-1),h=r&&r>0&&l<s-1?(c%r+r)%r:c;a.push({at:t(h),time:c,age:i>0?(e-c)/i:0})}return a}const k1=2.5;function Xh(t){const e=[],n=[],s=t.length,i=(o,r)=>{for(let a=o+r;a>=0&&a<s;a+=r){const l=(t[a].x-t[o].x)*r,c=(t[a].y-t[o].y)*r,h=Math.hypot(l,c);if(h>1e-9)return[l/h,c/h]}return null};for(let o=0;o<s;o++){const r=t[o],a=i(o,-1),l=i(o,1),c=a??l??[1,0],h=l??a??[1,0];let u=c[0]+h[0],d=c[1]+h[1];const f=Math.hypot(u,d);f<1e-9?(u=c[0],d=c[1]):(u/=f,d/=f);const p=u*c[0]+d*c[1],g=Math.min(k1,1/Math.max(p,1e-6)),m=r.width/2*g;e.push({x:r.x-d*m,y:r.y+u*m}),n.push({x:r.x+d*m,y:r.y-u*m})}return{left:e,right:n}}function Gh(t){const e=t.length;if(e<2)return null;const n=t[e-1];for(let s=e-2;s>=0;s--){const i=n.x-t[s].x,o=n.y-t[s].y,r=Math.hypot(i,o);if(r>1e-9)return{x:n.x,y:n.y,radius:n.width/2,start:Math.atan2(i/r,-o/r)}}return null}const v1={scale:1,turn:0,x:0,y:0};function M1(t={}){return{scale:t.scale??1,turn:t.turn??0,x:t.x??0,y:t.y??0}}function Uh(t,e,n){const{ax:s,ay:i}=Ii(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 Br(t,e){const{ax:n,ay:s}=Ii(t.scale,t.turn);return{x:n*e.x-s*e.y+t.x,y:s*e.x+n*e.y+t.y}}function S1(t,e){const n=Br(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 x1(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=Br(e,{x:t.x,y:t.y});return{...e,x:-n.x,y:-n.y}}function Vh(t){const{ax:e,ay:n}=Ii(t.scale,t.turn),s=1-e,i=-n,o=s*s+i*i;return o<1e-18?null:{x:(t.x*s+t.y*i)/o,y:(t.y*s-t.x*i)/o}}function T1(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=Vh(t);return i?Uh(n,s,i):{scale:n,turn:s,x:t.x*e,y:t.y*e}}function E1(t){const{ax:e,ay:n}=Ii(t.scale,t.turn);return[e,n,-n,e,t.x,t.y]}const Ii=(t,e)=>{const n=e*Math.PI/180;return{ax:t*Math.cos(n),ay:t*Math.sin(n)}};function Oi([t,e,n],s={}){const i=s.scale??1,o=s.centre??{x:0,y:0},r=Math.sqrt(3)/2;return{x:o.x+(t-e)*r*i,y:o.y+((t+e)*.5-n)*i}}const zr=([t,e,n])=>t+e+n;function qr(t,e={}){const[n,s,i]=t.min,[o,r,a]=t.max,l=d=>Oi(d,e),c=[(n+o)/2,(s+r)/2,(i+a)/2],h=zr(c),u=[{side:"top",depth:h,tag:t.tag,points:[l([n,s,a]),l([o,s,a]),l([o,r,a]),l([n,r,a])]},{side:"left",depth:h,tag:t.tag,points:[l([n,r,i]),l([o,r,i]),l([o,r,a]),l([n,r,a])]},{side:"right",depth:h,tag:t.tag,points:[l([o,s,i]),l([o,r,i]),l([o,r,a]),l([o,s,a])]}];return t.hide?u.filter(d=>!t.hide.includes(d.side)):u}function Yr(t,e={}){return t.map(n=>({box:n,depth:zr([(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})=>qr(n,e))}function A1(t={}){const e=t.size??10,s=(t.thickness??2)/2,i=[{tag:0,min:[-s,-s,-s],max:[e-s,s,s]},{tag:1,min:[e-s,-s,-s],max:[e+s,e-s,s]},{tag:2,min:[e-s,e-s,-s],max:[e+s,e+s,e]}],o=t.centre??{x:0,y:0},r=Oi([2*e/3,e/3,e/3],{scale:t.scale}),a={centre:{x:o.x-r.x,y:o.y-r.y},scale:t.scale};return{boxes:i,faces:[...Yr(i,a),...qr({...i[0],hide:["right"]},a)]}}function P1(t={}){const e=Math.max(2,Math.round(t.steps??8)),n=t.tread??1.5,s=t.rise??.25,i=t.width??3,o=t.base??1.5,r=Math.max(1,Math.round(e*(n-2*s)/(n+2*s))),a=2*(e+r),l=n*(e-r)/a,c=[{dir:[1,0,0],across:[0,1,0],count:e},{dir:[0,1,0],across:[-1,0,0],count:e},{dir:[-1,0,0],across:[0,-1,0],count:r},{dir:[0,-1,0],across:[1,0,0],count:r}],h=[];let u=[0,0,0],d=0;for(const w of c){for(let v=0;v<w.count;v++){const k=d*l,y=[u[0]+w.dir[0]*v*n,u[1]+w.dir[1]*v*n,0],T=[y[0]+w.dir[0]*n+w.across[0]*i,y[1]+w.dir[1]*n+w.across[1]*i,0];h.push({tag:d,min:[Math.min(y[0],T[0]),Math.min(y[1],T[1]),0],max:[Math.max(y[0],T[0]),Math.max(y[1],T[1]),k+o]}),d++}u=[u[0]+w.dir[0]*w.count*n,u[1]+w.dir[1]*w.count*n,0]}const f=a*l,p=t.centre??{x:0,y:0},g=Oi([e*n/2,e*n/2,f/2+o],{scale:t.scale}),m={centre:{x:p.x-g.x,y:p.y-g.y},scale:t.scale};return{boxes:h,faces:Yr(h,m),rise:l}}function Jh(t,e,n){let s=0;for(const i of t){const o=(e-i.x)**2+(n-i.y)**2;s+=o>1e-9?i.r*i.r/o:1e9}return s}function $1(t,e={}){if(t.length===0)return[];const n=e.threshold??1,s=Math.max(.5,e.cell??4),i=Math.sqrt(1/n)*1.6,o=e.bounds??{x:Math.min(...t.map(f=>f.x-f.r*i)),y:Math.min(...t.map(f=>f.y-f.r*i)),width:Math.max(...t.map(f=>f.x+f.r*i))-Math.min(...t.map(f=>f.x-f.r*i)),height:Math.max(...t.map(f=>f.y+f.r*i))-Math.min(...t.map(f=>f.y-f.r*i))},r=Math.max(2,Math.ceil(o.width/s)+1),a=Math.max(2,Math.ceil(o.height/s)+1),l=new Float64Array(r*a);for(let f=0;f<a;f++)for(let p=0;p<r;p++)l[f*r+p]=Jh(t,o.x+p*s,o.y+f*s)-n;const c=(f,p)=>l[p*r+f],h=(f,p,g,m,w,v)=>{const k=g===v?.5:g/(g-v);return{x:f+(m-f)*k,y:p+(w-p)*k}},u=[];for(let f=0;f+1<a;f++)for(let p=0;p+1<r;p++){const g=o.x+p*s,m=o.y+f*s,w=g+s,v=m+s,k=[c(p,f),c(p+1,f),c(p+1,f+1),c(p,f+1)],y=(k[0]>0?1:0)|(k[1]>0?2:0)|(k[2]>0?4:0)|(k[3]>0?8:0);if(y===0||y===15)continue;const T=()=>h(g,m,k[0],w,m,k[1]),$=()=>h(w,m,k[1],w,v,k[2]),M=()=>h(g,v,k[3],w,v,k[2]),x=()=>h(g,m,k[0],g,v,k[3]),S=(k[0]+k[1]+k[2]+k[3])/4>0;switch(y){case 1:case 14:u.push([x(),T()]);break;case 2:case 13:u.push([T(),$()]);break;case 3:case 12:u.push([x(),$()]);break;case 4:case 11:u.push([$(),M()]);break;case 6:case 9:u.push([T(),M()]);break;case 7:case 8:u.push([x(),M()]);break;case 5:S?u.push([x(),M()],[T(),$()]):u.push([x(),T()],[$(),M()]);break;case 10:S?u.push([x(),T()],[$(),M()]):u.push([x(),M()],[T(),$()]);break}}const d=I1(u);return e.smooth===!1?d:d.map(f=>Zh(Zh(f)))}function I1(t){const e=o=>`${Math.round(o.x*1e3)},${Math.round(o.y*1e3)}`,n=new Map;t.forEach(([o,r],a)=>{for(const l of[o,r]){const c=e(l);n.has(c)||n.set(c,[]),n.get(c).push(a)}});const s=new Array(t.length).fill(!1),i=[];for(let o=0;o<t.length;o++){if(s[o])continue;s[o]=!0;const r=[t[o][0],t[o][1]];let a=t[o][1];for(;;){const l=(n.get(e(a))??[]).find(u=>!s[u]);if(l===void 0)break;s[l]=!0;const[c,h]=t[l];if(a=e(c)===e(a)?h:c,e(a)===e(r[0]))break;r.push(a)}r.length>=3&&i.push(r)}return i}function Zh(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 O1(t){const e=Math.min(1,Math.max(0,t.progress));if(e<=0)return[];const n=t.width/2,s=n*(.55+.75*e),i=Math.max(t.length*e,s*1.2),o=t.x,r=t.y+i-s,a=Math.max(.1,n*(.35-.3*e)),l=r-Math.sqrt(Math.max(0,s*s-a*a)),c=Math.max(0,l-t.y),h=8,u=[],d=[];for(let v=0;v<=h;v++){const k=v/h,y=a+(n-a)*Math.pow(1-k,1.6+1.4*e);u.push({x:o-y,y:t.y+c*k}),d.push({x:o+y,y:t.y+c*k})}const f=Math.max(8,Math.round(t.segments??12)),p=Math.acos(Math.min(1,a/s)),g=-p,m=Math.PI+p,w=[];for(let v=1;v<f;v++){const k=g+(m-g)*v/f;w.push({x:o+Math.cos(k)*s,y:r+Math.sin(k)*s})}return[...d,...w,...u.reverse()]}function _1(t){const e=Math.min(1,Math.max(0,t.grow??1)),n=e>=1?1:1-Math.pow(1-e,3)+.08*Math.sin(e*Math.PI)*e,s=t.r*Math.max(0,n);if(s<=0)return[];const i=Math.max(12,Math.round(t.segments??48)),o=t.wobble??.05,r=t.time??0,a=t.period?r/t.period:r/2500,l=(a-Math.floor(a))*Math.PI*2,c=t.seed??0,h=[];for(let u=0;u<i;u++){const d=u/i*Math.PI*2,f=1+o*(Math.sin(2*d+l+c)*.6+Math.sin(3*d-2*l+c*1.7)*.4);h.push({x:t.x+Math.cos(d)*s*f,y:t.y+Math.sin(d)*s*f})}return h}function C1(t){const e=t.progress;if(e<=0||e>=1)return[];const n=Math.max(3,Math.round(t.pieces??8)),s=[],i=t.r*(1+1.2*e),o=Math.PI*2/n*.6*(1-e);for(let r=0;r<n;r++){const a=r/n*Math.PI*2+.3,l=[];for(let c=0;c<=4;c++){const h=a-o/2+o*c/4;l.push({x:t.x+Math.cos(h)*i,y:t.y+Math.sin(h)*i})}s.push(l)}return s}function H1(t,e={}){const n=Math.max(.05,1+t);return{sx:e.keep==="volume"?1/Math.sqrt(n):1/n,sy:n}}function R1(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 _i(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function On(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function _n(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function Re(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Ci(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 Hi(t){return Math.hypot(t[0],t[1],t[2])}function Kr(t,e){return Hi(On(t,e))}function Qe(t){const e=Hi(t);return e===0?[0,0,0]:_n(t,1/e)}function Qh(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 L1=Object.freeze(Object.defineProperty({__proto__:null,add:_i,cross:Ci,distance:Kr,dot:Re,length:Hi,lerp:Qh,normalize:Qe,scale:_n,subtract:On},Symbol.toStringTag,{value:"Module"})),N1=Math.PI/180;function Ri(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function Ot(t,e){const n=new Array(16);for(let s=0;s<4;s++)for(let i=0;i<4;i++){let o=0;for(let r=0;r<4;r++)o+=t[r*4+i]*e[s*4+r];n[s*4+i]=o}return n}function tn(t){return[1,0,0,0,0,1,0,0,0,0,1,0,t[0],t[1],t[2],1]}function en(t){return[t[0],0,0,0,0,t[1],0,0,0,0,t[2],0,0,0,0,1]}function ae(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 jr(t,e,n){const s=ae(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 F1(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 Xr(t){const[e,n,s,i,o,r,a,l,c,h,u,d,f,p,g,m]=t,w=e*r-n*o,v=e*a-s*o,k=e*l-i*o,y=n*a-s*r,T=n*l-i*r,$=s*l-i*a,M=c*p-h*f,x=c*g-u*f,S=c*m-d*f,E=h*g-u*p,P=h*m-d*p,A=u*m-d*g,I=w*A-v*P+k*E+y*S-T*x+$*M;if(Math.abs(I)<1e-12)return null;const _=1/I;return[(r*A-a*P+l*E)*_,(s*P-n*A-i*E)*_,(p*$-g*T+m*y)*_,(u*T-h*$-d*y)*_,(a*S-o*A-l*x)*_,(e*A-s*S+i*x)*_,(g*k-f*$-m*v)*_,(c*$-u*k+d*v)*_,(o*P-r*S+l*M)*_,(n*S-e*P-i*M)*_,(f*T-p*k+m*w)*_,(h*k-c*T-d*w)*_,(r*x-o*E-a*M)*_,(e*E-n*x+s*M)*_,(p*v-f*y-g*w)*_,(c*y-h*v+u*w)*_]}function W1(t,e,n,s){const i=1/Math.tan(t*N1/2),o=1/(n-s);return[i/e,0,0,0,0,i,0,0,0,0,(s+n)*o,-1,0,0,2*s*n*o,0]}function D1(t,e,n,s,i,o){const r=1/(e-t),a=1/(s-n),l=1/(o-i);return[2*r,0,0,0,0,2*a,0,0,0,0,-2*l,0,-(e+t)*r,-(s+n)*a,-(o+i)*l,1]}function B1(t,e,n=[0,1,0]){const s=Qe(On(t,e)),i=Qe(Ci(n,s)),o=Ci(s,i);return[i[0],o[0],s[0],0,i[1],o[1],s[1],0,i[2],o[2],s[2],0,-Re(i,t),-Re(o,t),-Re(s,t),1]}function Gt(t,e){const n=t[0]*e[0]+t[4]*e[1]+t[8]*e[2]+t[12],s=t[1]*e[0]+t[5]*e[1]+t[9]*e[2]+t[13],i=t[2]*e[0]+t[6]*e[1]+t[10]*e[2]+t[14],o=t[3]*e[0]+t[7]*e[1]+t[11]*e[2]+t[15];return o===1||o===0?[n,s,i]:[n/o,s/o,i/o]}const z1=Object.freeze(Object.defineProperty({__proto__:null,compose:jr,fromQuat:ae,identity:Ri,invert:Xr,lookAt:B1,multiply:Ot,orthographic:D1,perspective:W1,scaling:en,transformPoint:Gt,translation:tn,transpose:F1},Symbol.toStringTag,{value:"Module"})),Li={"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]},t0={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 q1(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}Lt({type:"bounce",mode:"in"}),Lt({type:"bounce",mode:"in-out"});function Es(t){const e=e0.get(t.trim().toLowerCase());if(e)return e;const n=q1(t),s=/^steps\(\s*(\d+)\s*\)$/.exec(n);if(s){const r={type:"steps",count:Math.max(1,Number.parseInt(s[1],10))+1,position:"none"};return{easing:r,fn:Lt(r)}}const i=/^(elastic|bounce|back)\.(in|out|inout)(?:\(([^)]*)\))?$/.exec(n);if(i){const[,o,r,a]=i,l=(a??"").split(",").map(u=>Number.parseFloat(u)).filter(u=>Number.isFinite(u)),c=r==="inout"?"in-out":r;if(o==="back"&&l.length===0&&n in Li)return{easing:{type:"cubic-bezier",points:Li[n]}};const h=o==="elastic"?{type:"elastic",mode:c,...l[0]!==void 0&&{amplitude:l[0]},...l[1]!==void 0&&{period:l[1]}}:o==="bounce"?{type:"bounce",mode:c}:{type:"back",mode:c,...l[0]!==void 0&&{overshoot:l[0]}};return{easing:h,fn:Lt(h)}}return n in t0?{easing:t0[n]}:n in Li?{easing:{type:"cubic-bezier",points:Li[n]}}:{easing:"ease-out"}}const e0=new Map;function Gr(t,e){return e0.set(t.trim().toLowerCase(),e.bezier?{easing:{type:"cubic-bezier",points:e.bezier},fn:e.fn}:{fn:e.fn,requiresBaking:"custom"}),t}function Ur(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 n0=/^\s*random\(\s*(\[.*\]|[^)]*)\s*\)\s*$/;function s0(t){return typeof t=="string"&&n0.test(t)}function Y1(t=1){let e=Ur(t);const n=(l,c)=>((...h)=>h.length>=l?c(...h):u=>c(...h,u)),s=(l,c,h)=>Math.min(Math.max(h,Math.min(l,c)),Math.max(l,c)),i=(l,c,h,u,d)=>c===l?h:h+(d-l)/(c-l)*(u-h),o=(l,c)=>{if(typeof l=="number")return l===0?c:Math.round(c/l)*l;if(Array.isArray(l))return i0(l,c,1/0);if("values"in l)return i0(l.values,c,l.radius??1/0);const h=Math.round(c/l.increment)*l.increment;return Math.abs(h-c)<=(l.radius??1/0)?h:c},r=(l,c,h)=>{const u=l+e()*(c-l);return h?Math.round(u/h)*h:u};return{clamp:n(3,s),mapRange:n(5,i),normalize:n(3,(l,c,h)=>i(l,c,0,1,h)),interpolate:n(3,(l,c,h)=>{if(typeof l=="object"&&!Array.isArray(l)){const u={};for(const d of Object.keys(l))u[d]=ks(l[d])(l[d],c[d],h);return u}return ks(l)(l,c,h)}),wrap:((l,c,h)=>{if(Array.isArray(l)){const g=l,m=w=>g[(Math.round(w)%g.length+g.length)%g.length];return c===void 0?m:m(c)}const u=l,f=c-u,p=g=>f===0?u:((g-u)%f+f)%f+u;return h===void 0?p:p(h)}),wrapYoyo:n(3,(l,c,h)=>{const u=c-l;if(u===0)return l;const d=((h-l)%(u*2)+u*2)%(u*2);return l+(d>u?u*2-d:d)}),snap:n(2,o),random:((l,c,h,u)=>{if(Array.isArray(l)){const f=()=>l[Math.floor(e()*l.length)];return c===!0?f:f()}const d=()=>r(l,c,h);return u?d:d()}),shuffle:l=>{for(let c=l.length-1;c>0;c--){const h=Math.floor(e()*(c+1));[l[c],l[h]]=[l[h],l[c]]}return l},distribute:({base:l=0,amount:c,each:h,from:u="start",ease:d})=>(f,p,g)=>{const m=g.length,v=bi(f,m,{...c!==void 0?{amount:c}:{each:h??1},from:u}),k=c!==void 0?c:(h??1)*pr(m,u),y=d&&k>0?d(v/k)*k:v;return l+y},pipe:(...l)=>c=>l.reduce((h,u)=>u(h),c),splitColor:l=>K1(l),getUnit:l=>typeof l=="number"?"":/^-?[\d.]+(?:e[-+]?\d+)?([a-z%]*)$/i.exec(l.trim())?.[1]??"",seed:l=>{e=Ur(l)},resolveRandomString:l=>{const c=n0.exec(l)?.[1]??"";if(c.startsWith("[")){const p=c.slice(1,-1).split(",").map(g=>g.trim()).filter(Boolean).map(g=>Number.isFinite(Number(g))?Number(g):g.replace(/^['"]|['"]$/g,""));return p[Math.floor(e()*p.length)]}const[h,u,d]=c.split(",").map(f=>Number.parseFloat(f));return r(h,u,Number.isFinite(d)?d:void 0)}}}function i0(t,e,n){let s=e,i=1/0;for(const o of t){const r=Math.abs(o-e);r<i&&(i=r,s=o)}return i<=n?s:e}function K1(t){const e=t.trim(),n=/^#([0-9a-f]{3,8})$/i.exec(e)?.[1];if(n){const o=(n.length<=4?[...n].map(r=>r+r).join(""):n).match(/../g).map(r=>Number.parseInt(r,16));return o.length>=4?[o[0],o[1],o[2],Math.round(o[3]/255*1e3)/1e3]:[o[0],o[1],o[2]]}const s=(/rgba?\(([^)]+)\)/i.exec(e)?.[1]??"0,0,0").split(/[\s,/]+/).filter(Boolean).map(i=>Number.parseFloat(i));return s.length>=4?[s[0],s[1],s[2],s[3]]:[s[0]??0,s[1]??0,s[2]??0]}const j1=/^([+-])=\s*(-?[\d.]+)$/,X1=/^([<>])\s*(?:([+-])?=?\s*(-?[\d.]+))?$/;function As(t,e){const n=e.scale??1,s=c=>Number.parseFloat(c)*n;if(t===void 0)return e.cursor;if(typeof t=="number")return t*n;const i=t.trim();if(i==="")return e.cursor;const o=j1.exec(i);if(o){const c=s(o[2]);return e.cursor+(o[1]==="-"?-c:c)}const r=X1.exec(i);if(r){const c=r[1]==="<"?e.previousStart:e.previousEnd;if(r[3]===void 0)return c;const h=s(r[3]);return c+(r[2]==="-"?-h:h)}const a=/^(.+?)([+-])=\s*(-?[\d.]+)$/.exec(i);if(a){const c=e.labels.get(a[1].trim());if(c!==void 0){const h=s(a[3]);return c+(a[2]==="-"?-h:h)}}const l=e.labels.get(i);return l!==void 0?l:/^-?[\d.]+$/.test(i)?s(i):e.cursor}function G1(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 U1(t,e,n={}){if(t===0)return[];const s=e.grid==="auto"?Math.max(1,Math.min(t,n.columnsFromLayout?.()??t)):Array.isArray(e.grid)?Math.max(1,e.grid[1]):t,i=Array.isArray(e.grid)?Math.max(1,e.grid[0]):Math.ceil(t/s),o=p=>({x:p%s,y:Math.floor(p/s)}),r=e.from??"start",a=Array.isArray(r)?{x:r[0]*(s-1),y:r[1]*(i-1)}:typeof r=="number"?o(Math.max(0,Math.min(t-1,r))):r==="end"?o(t-1):r==="center"||r==="edges"?{x:(s-1)/2,y:(i-1)/2}:{x:0,y:0},l=p=>{const{x:g,y:m}=o(p),w=Math.abs(g-a.x),v=Math.abs(m-a.y);return e.axis==="x"?w:e.axis==="y"?v:Math.hypot(w,v)};let c=Array.from({length:t},(p,g)=>l(g));const h=Math.max(...c);if(r==="edges"&&(c=c.map(p=>h-p)),r==="random"){const p=n.random??Math.random;c=c.map(()=>p()*h)}const u=e.amount!==void 0?e.amount:(e.each??0)*h,d=e.ease?Es(e.ease):void 0,f=d?d.fn??Lt(d.easing):void 0;return c.map(p=>{const g=h===0?0:p/h;return(f?f(g):g)*u})}const Vr=new Set(["duration","delay","ease","repeat","repeatDelay","yoyo","stagger","onComplete","onUpdate","onStart","onRepeat","onReverseComplete","repeatRefresh","keyframes","easeEach","scrollTo","id","immediateRender","overwrite","paused","scrollTrigger","spring"]),V1={rotation:"rotate",rotationZ:"rotate",rotationX:"rotateX",rotationY:"rotateY",transformPerspective:"perspective",perspective:"childPerspective"};function Ni(t){const e={},n={};for(const[s,i]of Object.entries(t))Vr.has(s)?e[s]=i:n[V1[s]??s]=i;return{config:e,properties:n}}function Fi(t,e){return t===void 0?e:t*1e3}function Jr(t,e){if(t!==void 0)return typeof t=="number"?{each:t*1e3}:G1(t)?{offsets:U1(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 J1={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 o0(t){return J1[t]}function Z1(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=jh(e.path,{curviness:e.curviness});else if(En(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 Q1(t){const e=typeof t=="string"||Array.isArray(t)?{path:t}:{...t};return{...e,start:e.end??1,end:e.start??0}}function r0(t){return typeof t=="object"&&t!==null&&"shape"in t?t.shape:t}function tb(t){if(t.morphSVG===void 0)return t;const{morphSVG:e,...n}=t,s=r0(e);if(typeof s!="string"||!En(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 eb(t,e){if(t===!0)return[0,e];if(t===!1)return[0,0];if(typeof t=="number")return[0,a0(t,e)];const n=t.trim().split(/[\s,]+/).filter(Boolean),s=r=>{const a=Number.parseFloat(r);if(Number.isNaN(a))throw new Error(`gsap-compat: drawSVG "${t}" is not a length or percentage`);return a0(r.endsWith("%")?e*a/100:a,e)};if(n.length===0)return[0,e];if(n.length===1)return[0,s(n[0])];const i=s(n[0]),o=s(n[1]);return i<=o?[i,o]:[o,i]}function nb(t,e){const[n,s]=eb(t,e);return{strokeDasharray:[s-n,e],strokeDashoffset:-n}}function sb(t,e){if(t.drawSVG===void 0)return t;const{drawSVG:n,...s}=t;return{...s,...nb(n,e)}}function ib(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 a0(t,e){return Math.max(0,Math.min(e,t))}function ob(t){let e=2166136261;for(let n=0;n<t.length;n++)e=Math.imul(e^t.charCodeAt(n),16777619);return e>>>0}function rb(t,e,n){if(t.scrambleText!==void 0){const s=t.scrambleText,i=typeof s=="string"?{text:s}:s;if(typeof i?.text!="string")throw new Error("gsap-compat: scrambleText needs the text to end on — a string, or { text }.");const o=i.revealDelay&&n>0?i.revealDelay*1e3/n:void 0;return{to:i.text,mode:"scramble",...i.chars!==void 0&&{chars:i.chars},...i.speed!==void 0&&{refreshRate:20*i.speed},...o!==void 0&&{revealDelay:Math.min(o,.999)},...i.tweenLength!==void 0&&{tweenLength:i.tweenLength},...i.rightToLeft!==void 0&&{rightToLeft:i.rightToLeft},seed:i.seed??ob(`${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 Zr(t){return Math.max(.1,t/25)}function ab(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?Zr(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(ps(i))]:n.end!==void 0&&(i.end=Array.isArray(n.end)?[...n.end]:n.end),i}function lb(t){const e=t===!0?{}:typeof t=="string"?{preset:t}:t;if(e.preset!==void 0&&!(e.preset in vi))throw new Error(`gsap-compat: unknown spring preset "${e.preset}" — use one of ${Object.keys(vi).join(", ")}`);return{...e.preset?vi[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 cb(t,e){if(t===!0||typeof t=="string")return;const n=t.velocity;return typeof n=="number"?n:n?.[e]}class nn{timeline;options;cursor=0;fallbackRandom=Ur(1);previousStart=0;previousEnd=0;labels=new Map;trackCounter=0;lastValues=new Map;constructor(e={}){this.options=e,this.timeline=new It({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,Ps(n),s)}from(e,n,s){const{config:i,properties:o}=Ni(Ps(n)),{motionPath:r,text:a,scrambleText:l,...c}=o,h=this.targetsOf(e)[0],u={...i};for(const p of Object.keys(c))u[p]=this.resolveStart(h,p);r!==void 0&&(u.motionPath=Q1(r));const d={},f=String(this.resolveStart(h,"text"));return a!==void 0&&(d.text=Qr(a),u.text=typeof a=="object"?{...a,value:f}:f),l!==void 0&&(d.text=Qr(l),u.scrambleText=typeof l=="object"?{...l,text:f}:f),this.build(e,{...c,...d},u,s)}fromTo(e,n,s,i){const{properties:o}=Ni(Ps(n));return this.build(e,o,Ps(s),i)}set(e,n,s){return this.build(e,void 0,{...Ps(n),duration:0},s)}get lastStart(){return this.previousStart}get lastEnd(){return this.previousEnd}addEvent(e){const n=Math.max(0,As(e,this.context()));return this.previousStart=n,this.previousEnd=n,this.cursor=Math.max(this.cursor,n),n}timeOf(e){return As(e,this.context())}addLabel(e,n){return this.labels.set(e,As(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=As(n,this.context());for(const o of e.timeline.tracks){if(!("keyframes"in o))continue;const r=Ai({...o,id:this.nextTrackId(`nested-${o.id}`),keyframes:o.keyframes.map(a=>({...a,time:a.time+s}))});this.timeline.addTrack(r)}const i=s+e.timeline.duration;return this.previousStart=s,this.previousEnd=i,this.cursor=Math.max(this.cursor,i),this}play(){return this.timeline.play(),this}pause(){return this.timeline.pause(),this}restart(){return this.timeline.stop(),this.timeline.play(),this}reverse(){return this.timeline.reverse(),this}kill(){return this.timeline.removeTracks(),this}reset(){return this.timeline.removeTracks(),this.cursor=0,this.previousStart=0,this.previousEnd=0,this.labels.clear(),this.lastValues.clear(),this.trackCounter=0,this}seek(e){if(typeof e=="string"){const n=this.labels.get(e);return n!==void 0&&this.timeline.seek(n),this}return this.timeline.seek(e*1e3),this}progress(e){const n=this.timeline.duration;return e!==void 0&&n>0&&this.timeline.seek(e*n),n>0?this.timeline.currentTime/n:0}timeScale(e){return e!==void 0&&(this.timeline.speed=e),this.timeline.speed}duration(){return this.timeline.duration/1e3}tick(e){return this.timeline.tick(e),this}toDefinition(){return this.timeline.toDefinition()}build(e,n,s,i){const{config:o,properties:r}=Ni(s),{motionPath:a,text:l,scrambleText:c,inertia:h,...u}=r,d=this.targetsOf(e),f=As(i,this.context()),p=Fi(o.delay,0),g=Fi(o.duration,500),m=Jr(o.stagger,{count:d.length,columnsFromLayout:this.options.layoutColumns?()=>this.options.layoutColumns(d):void 0,random:this.options.random??this.fallbackRandom}),w=this.easingFor(o.ease),v=[],k=o.spring;let y=0,T=!1;for(const[P,A]of Object.entries(u)){const I=A;let _=n?.[P]!==void 0?n[P]:this.resolveStart(d[0],P);if(typeof _!=typeof I&&(this.warn(`no usable start value for "${P}" on "${d[0]}" — it will snap to ${String(I)}. Use fromTo() to animate it.`),_=I),k!==void 0&&(typeof _!="number"||typeof I!="number")&&this.warn(`spring works on numbers, so "${P}" on "${d[0]}" eases instead`),k!==void 0&&typeof _=="number"&&typeof I=="number"){const V={...lb(k),from:_,to:I,velocity:cb(k,P)??this.options.startVelocity?.(d[0],P)??0},tt=this.nextTrackId(`${d[0]}-${P}-spring`),X={id:tt,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:P,kind:"spring",spring:V,delay:f+p};this.timeline.addTrack(X),v.push(tt),y=Math.max(y,Wc(V));for(const R of d)this.lastValues.set(`${R}|${P}`,I);continue}T=!0;const N=this.keyframesFor(_,I,g,w,o.ease),Y=this.nextTrackId(`${d[0]}-${P}`);this.timeline.addTrack(Ai({id:Y,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:P,delay:f+p,keyframes:N,...P==="quaternion"&&{interpolation:"slerp"}})),v.push(Y);for(const V of d)this.lastValues.set(`${V}|${P}`,I)}const $=rb({text:l,scrambleText:c},d[0],g);if($){const P=n?.text??n?.scrambleText,A=P!==void 0?Qr(P):this.resolveStart(d[0],"text"),I=this.nextTrackId(`${d[0]}-text`),_={id:I,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:"text",textConfig:{from:typeof A=="string"?A:String(A??""),...$},delay:f+p,keyframes:this.keyframesFor(0,1,g,w,o.ease)};this.timeline.addTrack(_),v.push(I);for(const N of d)this.lastValues.set(`${N}|text`,$.to)}if(a!==void 0){const{config:P,start:A,end:I}=Z1(a),_=this.nextTrackId(`${d[0]}-motionPath`),N={id:_,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:"motionPath",motionPathConfig:P,delay:f+p,keyframes:this.keyframesFor(A,I,g,w,o.ease)};this.timeline.addTrack(N),v.push(_)}if(h!==void 0)for(const[P,A]of Object.entries(h)){const I=this.resolveStart(d[0],P);if(typeof I!="number"){this.warn(`inertia on "${P}" needs a numeric start value; skipped`);continue}const _=ab(I,A),N=this.nextTrackId(`${d[0]}-${P}-inertia`),Y={id:N,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:P,kind:"inertia",inertia:_,delay:f+p};this.timeline.addTrack(Y),v.push(N),y=Math.max(y,xn(_));for(const V of d)this.lastValues.set(`${V}|${P}`,Sn(_))}const S=((h!==void 0||k!==void 0)&&!T&&!$&&a===void 0?y:Math.max(g,y))+(m&&d.length>1?fs(d.length,m):0),E=f+p+S;return this.previousStart=f+p,this.previousEnd=E,this.cursor=Math.max(this.cursor,E),{trackIds:v,start:f+p,end:E,kill:()=>{for(const P of v)this.timeline.removeTrack(P)}}}keyframesFor(e,n,s,i,o){const r={time:0,value:e};if(s<=0)return[{time:0,value:n}];const a=typeof o=="string"?Es(o):void 0;if(a?.requiresBaking==="custom"||this.options.bakeEases&&ds(i)){const c=a?.fn??Lt(i);return[r,..._r(r,{time:s,value:n},c,{intervalMs:this.options.bakeIntervalMs})]}return[r,{time:s,value:n,...i&&{easing:i}}]}resolveStart(e,n){const s=this.lastValues.get(`${e}|${n}`);if(s!==void 0)return s;const i=this.options.startValue?.(e,n);if(i!==void 0)return i;const o=this.options.defaults?.[n];if(o!==void 0)return o;if(n==="text")return"";if(n==="quaternion")return[0,0,0,1];if(n==="d")throw new Error(`gsap-compat: no starting shape for "${e}". Use fromTo({ d: … }, { morphSVG: … }), or live.to(), which reads the element's current shape.`);const r=o0(n);return r!==void 0?(this.warn(`no start value for "${n}" on "${e}" — using the static default ${r}. GSAP would read the live DOM here; tinyfly cannot, so pass an explicit fromTo() or a defaults map.`),r):(this.warn(`no start value or default for "${n}" on "${e}" — using 0`),0)}easingFor(e){if(e!==void 0){if(typeof e=="string")return Es(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 Qr(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 hb(t){return new nn(t)}function Ps(t){return ib(tb(t))}function ub(t){return!Array.isArray(t)||t.length!==4?null:`matrix3d(${ae(_e(t)).map(n=>Math.round(n*1e6)/1e6+0).join(", ")})`}const db=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),fb="#ffffff",gb="rgba(0, 0, 0, 0.5)";function pb(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??fb})`),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??gb})`)}return e.length>0?e.join(" "):null}function mb(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 yb(t){if(!("ownerSVGElement"in t))return;const e=t.style;!e||e.transformBox||(e.transformBox="fill-box",e.transformOrigin||(e.transformOrigin="50% 50%"))}const l0=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"]),bb=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),wb=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],kb=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),vb=new Set(["originX","originY"]),Mb=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),Sb=new Set(["drawOn"]),xb={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},c0={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},Tb="http://www.w3.org/2000/svg";class sn{targets=new Map;registerTarget(e,n){this.targets.set(e,n)}unregisterTarget(e){this.targets.delete(e)}getTarget(e){return this.targets.get(e)}clearTargets(){this.targets.clear()}applyState(e){for(const[n,s]of e.values){const i=this.targets.get(n);i&&this.applyProperties(i,s)}}applyProperties(e,n){let s=null,i=null,o=null,r=null,a=null;const l=n.has("motionPathX"),c=n.has("motionPathY"),h=n.has("motionPathRotate");for(const[p,g]of n)if(!(p==="x"&&l)&&!(p==="y"&&c)&&!((p==="rotate"||p==="rotateZ")&&h)&&!Sb.has(p)){if(bb.has(p))(s??={})[p]=g;else if(kb.has(p))typeof g=="number"&&((i??={})[p]=g);else if(vb.has(p))typeof g=="number"&&((o??={})[p]=g);else if(Mb.has(p))typeof g=="number"&&((r??={})[p]=g);else if(db.has(p))(a??={})[p]=g;else if(p!=="perspective"){if(p!=="shine")if(p==="text"&&typeof g=="string")mb(e,g);else if(p==="d"&&typeof g=="string"){const m=e;(m.tagName?.toLowerCase()==="path"?m:m.querySelector?.("path"))?.setAttribute?.("d",g)}else this.applyStyleProperty(e,p,g)}}const u=n.get("shine");typeof u=="number"&&this.applyShine(e,u);const d=[],f=n.get("perspective");if(typeof f=="number"&&f>0&&d.push(`perspective(${f}px)`),s)for(const p of wb){const g=s[p];if(g===void 0)continue;const m=this.buildTransformPart(p,g);m&&d.push(m)}if(d.length>0&&(e.style.transform=d.join(" "),yb(e)),i&&(i.childPerspective!==void 0&&(e.style.perspective=`${i.childPerspective}px`),(i.perspectiveOriginX!==void 0||i.perspectiveOriginY!==void 0)&&(e.style.perspectiveOrigin=`${i.perspectiveOriginX??50}% ${i.perspectiveOriginY??50}%`)),o){const p=o.originX??50,g=o.originY??50;e.style.transformOrigin=`${p}% ${g}%`}if(r){const p=r.clipTop??0,g=r.clipRight??0,m=r.clipBottom??0,w=r.clipLeft??0;e.style.clipPath=`inset(${p}% ${g}% ${m}% ${w}%)`}if(a){const p=pb(a);p&&(e.style.filter=p)}}buildTransformPart(e,n){if(e==="quaternion")return ub(n);if(typeof n!="number")return null;switch(e){case"x":case"motionPathX":return`translateX(${n}px)`;case"y":case"motionPathY":return`translateY(${n}px)`;case"z":return`translateZ(${n}px)`;case"rotate":case"rotateZ":case"motionPathRotate":return`rotate(${n}deg)`;case"rotateX":return`rotateX(${n}deg)`;case"rotateY":return`rotateY(${n}deg)`;case"scale":return`scale(${n})`;case"scaleX":return`scaleX(${n})`;case"scaleY":return`scaleY(${n})`;case"scaleZ":return`scaleZ(${n})`;case"skewX":return`skewX(${n}deg)`;case"skewY":return`skewY(${n}deg)`;default:return null}}applyShine(e,n){e.dataset.shineBase||(e.dataset.shineBase=e.style.color||"currentColor");const s=e.dataset.shineBase,i=-20+n*140,o=e.style;o.color="transparent",o.backgroundImage=`linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${s}, ${s})`,o.backgroundSize="250% 100%, 100% 100%",o.backgroundPosition=`${i}% 0, 0 0`,o.backgroundRepeat="no-repeat",o.webkitBackgroundClip="text",o.backgroundClip="text"}applyStyleProperty(e,n,s){let i;if(e.namespaceURI===Tb&&n in c0){const a=Array.isArray(s)?s.join(", "):String(s);e.style[c0[n]]=a;return}else n==="fill"&&e.dataset?.elementType==="text"?i="color":i=xb[n]??n;let r;typeof s=="number"?l0.has(n)||l0.has(i)?r=`${s}px`:r=String(s):Array.isArray(s)?r=s.join(", "):r=s,e.style[i]=r}}const Eb={request:t=>requestAnimationFrame(t),cancel:t=>cancelAnimationFrame(t)};class h0{adapter=new sn;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=Y1();active=new Map;applied=new Map;dirty=new Set;frameId=null;lastTimestamp=null;destroyed=!1;constructor(e={}){this.scheduler=e.scheduler??Eb,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);ta(s)&&this.currentCollector?.touch(s,i),n.push(i)}return n}query(e){return this.selectorRoot.querySelector(e)}get collector(){return this.currentCollector}setCollector(e){this.currentCollector=e}forget(e){this.applied.delete(e),this.dirty.delete(e)}get selectorRoot(){return this.currentCollector?.scope??this.root}elementFor(e){return this.elements.get(e)}objectFor(e){return this.objects.get(e)}appliedValue(e,n){return this.applied.get(e)?.get(n)}velocityOf(e,n){for(const i of[...this.active.keys()].reverse()){if(i.getTracks({target:e,property:n}).length===0)continue;const o=i.currentTime;if(o<4)return 0;const r=i.getStateAtTime(o).values.get(e)?.get(n),a=i.getStateAtTime(o-4).values.get(e)?.get(n);if(typeof r!="number"||typeof a!="number")return;const l=(r-a)/4;return(i.direction==="reverse"?-l:l)*1e3}}ticker={add:e=>{this.destroyed||(this.tickerCallbacks.size===0&&(this.tickerTime=0,this.tickerFrame=0),this.tickerCallbacks.add(e),this.currentCollector?.track({revert:()=>this.ticker.remove(e)}),this.startLoop())},remove:e=>{this.tickerCallbacks.delete(e),this.running||this.stopLoop()}};activate(e,n={}){this.destroyed||(e.onUpdate=s=>this.write(s),this.active.delete(e),this.active.set(e,n),this.startLoop())}deactivate(e){this.active.delete(e),this.running||this.stopLoop()}own(e){return this.destroyed?e.destroy():this.owned.add(e),e}destroy(){this.destroyed=!0;for(const e of this.owned)e.destroy();this.owned.clear();for(const e of this.active.keys())e.stop();this.active.clear(),this.stopLoop(),this.adapter.clearTargets(),this.elements.clear(),this.names=new WeakMap,this.objects.clear(),this.objectNames=new WeakMap,this.tickerCallbacks.clear(),this.liveTimelines.clear(),this.applied.clear(),this.dirty.clear()}apply(e,n){if(this.destroyed)return;const s=new Map(Object.entries(n));this.write({values:new Map([[e,s]]),currentTime:0,playbackState:"idle",direction:"forward",loopIteration:0}),this.flush()}render(e){this.destroyed||(this.write(e.getStateAtTime(e.currentTime)),this.flush())}tick(e){const n=[...this.active];for(const[s]of n)s.duration<=0?(this.write(s.getStateAtTime(0)),s.stop()):s.tick(e);this.flush();for(const[s,i]of n)i.onUpdate?.(),s.playbackState!=="playing"&&this.active.get(s)===i&&this.active.delete(s);this.flush(),this.runTicker(e),this.running||this.stopLoop()}get running(){return this.active.size>0||this.tickerCallbacks.size>0}runTicker(e){if(this.tickerCallbacks.size!==0){this.tickerTime+=e,this.tickerFrame+=1;for(const n of[...this.tickerCallbacks])n(this.tickerTime/1e3,e,this.tickerFrame)}}write(e){for(const[n,s]of e.values){let i=this.applied.get(n);i||(i=new Map,this.applied.set(n,i));for(const[o,r]of s)i.set(o,r);this.dirty.add(n)}}flush(){if(this.dirty.size===0)return;const e=new Map;for(const n of this.dirty){const s=this.applied.get(n),i=this.objects.get(n);if(i)for(const[o,r]of s)i[o]=r;else e.set(n,s)}this.dirty.clear(),e.size!==0&&this.adapter.applyState({values:e,currentTime:0,playbackState:"playing",direction:"forward",loopIteration:0})}frame=e=>{this.frameId=null;const n=this.lastTimestamp===null?0:e-this.lastTimestamp;this.lastTimestamp=e,n>0&&this.tick(n),this.running&&this.frameId===null&&(this.frameId=this.scheduler.request(this.frame))};startLoop(){this.frameId===null&&(this.lastTimestamp=null,this.frameId=this.scheduler.request(this.frame))}stopLoop(){this.frameId!==null&&this.scheduler.cancel(this.frameId),this.frameId=null,this.lastTimestamp=null}targetsOf(e){if(typeof e=="string")return Array.from(this.selectorRoot.querySelectorAll(e));if(ta(e))return[e];if(!Ab(e))return[e];const n=[];for(const s of Array.from(e))n.push(...this.targetsOf(s));return n}nameFor(e){return ta(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 ta(t){return typeof t=="object"&&t!==null&&t.nodeType===1}function Ab(t){if(Array.isArray(t))return!0;const e=t;return typeof e.length=="number"&&typeof e.item=="function"}function Wi(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 u0=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function Pb(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function $b(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 Ib(t,e){const n=typeof t=="string"||Array.isArray(t)||u0(t)?{path:t}:t,{align:s,alignOrigin:i,path:o,...r}=n,a=$=>{const M=u0($)?$:e.query($);return M||e.warn(`gsap-compat: motionPath could not find "${String($)}"`),M};let l=null,c="";if(Array.isArray(o)||typeof o=="string"&&En(o))c=o;else{l=a(o);const $=l&&$i({tag:l.localName,attributes:Pb(l)});l&&!$&&e.warn(`gsap-compat: motionPath element <${l.localName}> has no path geometry`),c=$??""}const h={...r,path:c};if(s===void 0||s===!1)return h;const u=s===!0?l:a(s);if(!u)return s===!0&&e.warn("gsap-compat: motionPath align: true needs the path to be an element"),h;const d=e.targets[0];if(!d)return h;const[f,p,g,m,w,v]=$b(u),k=Wi(d),[y,T]=i??[.5,.5];for(const $ of e.targets.slice(1)){const M=Wi($);if(Math.abs(M.left-k.left)>.5||Math.abs(M.top-k.top)>.5){e.warn("gsap-compat: motionPath align measures the first target; the others are laid out elsewhere");break}}return h.matrix=[f,p,g,m,w-k.left-y*k.width,v-k.top-T*k.height],h}const d0=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function f0(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function g0(t){if(!t)return null;const e=$i({tag:t.localName,attributes:f0(t)});return e||(t.querySelector("path")?.getAttribute("d")??null)}function Ob(t,e,n){const s=r0(t);if(typeof s=="string"&&En(s))return s;const i=d0(s)?s:typeof s=="string"?e(s):null,o=g0(i);return o||(n(`gsap-compat: morphSVG could not find a shape for "${String(s)}"`),"")}const _b=new Set(["cx","cy","r","rx","ry","x","y","width","height","x1","y1","x2","y2","points"]);function Cb(t,e=document){return(typeof t=="string"?Array.from(e.querySelectorAll(t)):d0(t)?[t]:Array.from(t)).map(s=>{if(s.localName==="path")return s;const i=$i({tag:s.localName,attributes:f0(s)});if(!i||!s.parentNode)return s;const o=s.ownerDocument.createElementNS("http://www.w3.org/2000/svg","path");for(const r of Array.from(s.attributes))_b.has(r.name)||o.setAttribute(r.name,r.value);return o.setAttribute("d",i),s.parentNode.replaceChild(o,s),o})}const p0=.3;class m0{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=y0(),this.options.onPress?.(this.stateFrom(0,0,s))}move(e,n,s){if(!this.dragging)return;const i=e-this.lastX,o=n-this.lastY;this.lastX=e,this.lastY=n;const r=e-this.startX,a=n-this.startY,l=this.options.tolerance??3;if(!this.passedTolerance){if(Math.hypot(r,a)<l)return;this.passedTolerance=!0}this.updateVelocity(i,o),this.options.preventDefault!==!1&&s.cancelable&&s.preventDefault(),this.options.onMove?.(this.stateFrom(i,o,s))}end(e){this.dragging&&(this.dragging=!1,this.options.onRelease?.(this.stateFrom(0,0,e)))}updateVelocity(e,n){const s=y0(),i=Math.max(1,s-this.lastTime);this.lastTime=s;const o=e/i*1e3,r=n/i*1e3;this.velocityX+=(o-this.velocityX)*p0,this.velocityY+=(r-this.velocityY)*p0}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 y0(){return typeof performance<"u"?performance.now():Date.now()}function b0(t,e,n){let s={delta:0,line:null},i=n;for(const o of t)for(const r of e){const a=Math.abs(r-o);a<=i&&(i=a,s={delta:r-o,line:r})}return s}function w0(t,e){return e<=0?[]:t.map(n=>Math.round(n/e)*e)}class ea{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 m0({target:e.target,onPress:n=>{const s=e.getPosition?.();s&&(this.x=s.x,this.y=s.y),this.originX=this.x,this.originY=this.y,e.onPress?.(n)},onMove:n=>this.handleMove(n),onRelease:n=>e.onRelease?.(n)})}start(){this.observer.start()}stop(){this.observer.stop()}destroy(){this.observer.destroy()}get position(){return{x:this.x,y:this.y}}get velocity(){return this.observer.velocity}setPosition(e,n){const s=this.options.axis??"both";this.x=s==="y"?this.x:this.applyConstraints(e,"x"),this.y=s==="x"?this.y:this.applyConstraints(n,"y")}get snapLines(){return{x:this.snappedX,y:this.snappedY}}snapThreshold(){if(this.options.snapThreshold!==void 0)return this.options.snapThreshold;const e=this.options.snap??0;return e>0?e/2:8}handleMove(e){this.setPosition(this.originX+e.totalX,this.originY+e.totalY),this.options.mode==="scrub"&&this.scrub(),this.options.onDrag?.(this.position,e),this.options.onSnap?.(this.snapLines)}scrub(){const e=this.options.timeline;if(!e)return;const n=e.duration;if(n<=0)return;const s=this.options.scrubDistance??500;if(s===0)return;const i=(this.options.axis??"both")==="y"?this.y:this.x,o=Hb(i/s);e.pause(),e.seek(o*n)}applyConstraints(e,n){let s=e;const i=[...w0([s],this.options.snap??0),...(n==="x"?this.options.snapLinesX:this.options.snapLinesY)??[]],o=b0([s],i,this.snapThreshold());s+=o.delta,n==="x"?this.snappedX=o.line:this.snappedY=o.line;const r=this.options.bounds;if(r){const a=n==="x"?r.minX:r.minY,l=n==="x"?r.maxX:r.maxY;a!==void 0&&(s=Math.max(a,s)),l!==void 0&&(s=Math.min(l,s))}return s}}function Hb(t){return t<0?0:t>1?1:t}function Rb(t){const e=new ea(t);return e.start(),e}const Lb={x:"x",y:"y","x,y":"both"},na=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function k0(t,e){const n=Wi(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 v0(t){return Array.isArray(t)?[...t]:t}function Nb(t,e,n,s={}){const[i]=e.resolveTargets(n),o=i?e.elementFor(i):void 0;if(!i||!o)throw new Error(`gsap-compat: live.draggable could not find ${String(n)}`);if(s.type==="rotation")return Fb(t,e,i,o,s);const r=Lb[s.type??"x,y"],a=()=>{const g=e.appliedValue(i,"x"),m=e.appliedValue(i,"y");return{x:typeof g=="number"?g:0,y:typeof m=="number"?m:0}},l=typeof s.bounds=="string"?e.query(s.bounds):na(s.bounds)?s.bounds:null,h={bounds:(!l&&s.bounds&&!na(s.bounds)?s.bounds:void 0)??(l?k0(o,l):void 0)};let u=null;const d=()=>{u?.kill(),u=null},f=g=>{const m=s.inertia===!0?{}:s.inertia,w=m.friction??(m.resistance!==void 0?Zr(m.resistance):4),v=a(),k=h.bounds??{};let y,T;const $=m.end;if(Array.isArray($)){const x=ps({from:v.x,velocity:r==="y"?0:g.x,friction:w}),S=ps({from:v.y,velocity:r==="x"?0:g.y,friction:w});let E=$[0];for(const P of $)Math.hypot(P.x-x,P.y-S)<Math.hypot(E.x-x,E.y-S)&&(E=P);E&&(y=[E.x],T=[E.y])}else typeof $=="number"?(y=$,T=$):$&&(y=v0($.x),T=v0($.y));const M={};r!=="y"&&(M.x={velocity:g.x,friction:w,min:k.minX,max:k.maxX,end:y}),r!=="x"&&(M.y={velocity:g.y,friction:w,min:k.minY,max:k.maxY,end:T}),u=t.to(o,{inertia:M,onComplete:()=>s.onThrowComplete?.()})},p=new ea({target:o,axis:r,snap:s.snap,get bounds(){return h.bounds},getPosition:a,onPress:()=>{d(),l&&(h.bounds=k0(o,l)),s.onPress?.()},onDrag:g=>{e.apply(i,r==="x"?{x:g.x}:r==="y"?{y:g.y}:{x:g.x,y:g.y}),s.onDrag?.(g)},onRelease:()=>{const g=p.velocity;s.onRelease?.(g),s.inertia&&f(g)}});return p.start(),{draggable:p,get position(){return a()},get rotation(){const g=e.appliedValue(i,"rotate");return typeof g=="number"?g:0},destroy(){d(),p.destroy()}}}function Fb(t,e,n,s,i){const o=typeof i.bounds=="object"&&i.bounds!==null&&!na(i.bounds)?i.bounds:{},r=()=>{const k=e.appliedValue(n,"rotate");return typeof k=="number"?k:0},a=k=>Math.min(o.maxRotation??1/0,Math.max(o.minRotation??-1/0,k));let l=null,c=!1,h,u={x:0,y:0},d=0,f=0,p=[];const g=k=>Math.atan2(k.clientY-u.y,k.clientX-u.x)*180/Math.PI,m=k=>{if(c)return;l?.kill(),l=null,c=!0,h=k.pointerId,s.setPointerCapture?.(k.pointerId);const y=s.getBoundingClientRect();u={x:y.left+y.width/2,y:y.top+y.height/2},d=g(k),f=r(),p=[{time:performance.now(),rotation:f}],i.onPress?.()},w=k=>{if(!c||k.pointerId!==h)return;const y=g(k);let T=y-d;T>180&&(T-=360),T<-180&&(T+=360),d=y,f+=T;let $=a(f);i.snap&&($=a(Math.round($/i.snap)*i.snap)),e.apply(n,{rotate:$});const M=performance.now();for(p.push({time:M,rotation:$});p.length>2&&M-p[0].time>100;)p.shift();const x={x:0,y:0};i.onDrag?.(x)},v=k=>{if(!c||k.pointerId!==h)return;c=!1;const y=p[0],T=p[p.length-1],$=y&&T?(T.time-y.time)/1e3:0,M=$>0?(T.rotation-y.rotation)/$:0;if(i.onRelease?.({x:M,y:0}),!i.inertia)return;const x=i.inertia===!0?{}:i.inertia,S=x.friction??(x.resistance!==void 0?Zr(x.resistance):4),E=typeof x.end=="number"||Array.isArray(x.end)?x.end:void 0;l=t.to(s,{inertia:{rotate:{velocity:M,friction:S,min:o.minRotation,max:o.maxRotation,end:Array.isArray(E)?E.filter(P=>typeof P=="number"):E}},onComplete:()=>i.onThrowComplete?.()})};return s.addEventListener("pointerdown",m),s.addEventListener("pointermove",w),s.addEventListener("pointerup",v),s.addEventListener("pointercancel",v),s.style.touchAction="none",{draggable:void 0,position:{x:0,y:0},get rotation(){return r()},destroy(){l?.kill(),s.removeEventListener("pointerdown",m),s.removeEventListener("pointermove",w),s.removeEventListener("pointerup",v),s.removeEventListener("pointercancel",v)}}}const Wb={opacity:0,scale:.6};function Db(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 M0(t){const e=Wi(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 sa(t,e){const s=t.resolveTargets(e).map(r=>t.elementFor(r)).filter(r=>!!r),i=new Map,o=new Map;for(const r of s){const a=Db(r);i.set(r,a);const l=S0(r);a&&l!==void 0&&!o.has(l)&&o.set(l,{element:r,box:a})}return{elements:s,boxes:i,ids:o}}const ia=new WeakMap;function oa(t,e,n,s={}){const i=s.duration??.6,o=s.ease??"power2.inOut",r=s.stagger??0,a=s.scale!==!1,l=s.enter===void 0?Wb:s.enter,c=new Set(n.elements);if(s.targets!==void 0)for(const f of t.resolveTargets(s.targets)){const p=t.elementFor(f);p&&c.add(p)}const h=[...c].sort((f,p)=>f===p?0:f.compareDocumentPosition(p)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1),u=e({onComplete:s.onComplete});let d=0;for(const f of h){const p=M0(f);if(!p)continue;let g=n.boxes.get(f)??null,m;const w=S0(f),v=!g&&w!==void 0?n.ids.get(w):void 0;v&&v.element!==f&&(g=v.box,m=v.element);const[k]=t.resolveTargets(f);ia.get(f)?.timeline.removeTracks({target:k});const y=d*r;if(!g){if(l===!1)continue;u.fromTo(f,{x:0,y:0,scaleX:1,scaleY:1,...l},{...x0(l),x:0,y:0,scaleX:1,scaleY:1,duration:i,ease:o,delay:y},0),ia.set(f,u),d++;continue}const T=g.cx-p.cx,$=g.cy-p.cy,M=a?g.width/p.width:1,x=a?g.height/p.height:1;if(!(Math.abs(T)>.5||Math.abs($)>.5||Math.abs(M-1)>.001||Math.abs(x-1)>.001)){const P=(A,I)=>{const _=t.appliedValue(k,A);return typeof _=="number"&&Math.abs(_-I)>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 E=s.fade===!0&&m!==void 0;u.fromTo(f,{x:T,y:$,scaleX:M,scaleY:x,...E&&{opacity:0}},{x:0,y:0,scaleX:1,scaleY:1,...E&&{opacity:1},duration:i,ease:o,delay:y},0),E&&m&&M0(m)&&u.fromTo(m,{opacity:1},{opacity:0,duration:i,ease:o,delay:y},0),ia.set(f,u),d++}return u}function S0(t){return t.dataset?.flipId}function x0(t){const e={};for(const n of Object.keys(t))e[n]=n==="opacity"||n.startsWith("scale")?1:0;return e}function Bb(t,e={}){const n=new Set((e.type??"chars,words,lines").split(",").map(g=>g.trim())),s={chars:e.charsClass??"char",words:e.wordsClass??"word",lines:e.linesClass??"line"},i=e.aria!==!1,o=t.map(g=>({element:g,html:g.innerHTML,ariaLabel:g.getAttribute("aria-label")}));let r={chars:[],words:[],lines:[],masks:[]},a,l,c=!1;const h=()=>{for(const{element:g,html:m,ariaLabel:w}of o)g.innerHTML=m,w===null?g.removeAttribute("aria-label"):g.setAttribute("aria-label",w)},u=()=>{a&&(a.revert?a.revert():a.kill?.(),a=void 0)},d=()=>{const g={chars:[],words:[],lines:[],masks:[]};for(const{element:m}of o){const w=(m.textContent??"").replace(/\s+/g," ").trim(),v=zb(m,s.words),k=n.has("chars")?v.flatMap($=>qb($,s.chars)):[],y=n.has("lines")?Kb(m,v,s.lines):[];if(i){!m.hasAttribute("aria-label")&&w&&m.setAttribute("aria-label",w);for(const $ of v)$.setAttribute("aria-hidden","true")}if(n.has("words"))g.words.push(...v);else for(const $ of v)$.removeAttribute("class");g.chars.push(...k),g.lines.push(...y);const T=e.mask==="lines"?y:e.mask==="words"?v:e.mask==="chars"?k:[];for(const $ of T)g.masks.push(jb($,`${s[e.mask]}-mask`))}r=g},f={elements:t,get chars(){return r.chars},get words(){return r.words},get lines(){return r.lines},get masks(){return r.masks},split(){c||(u(),h(),d(),a=e.onSplit?.(f))},revert(){c=!0,l?.disconnect(),u(),h()}};d(),a=e.onSplit?.(f),e.autoSplit&&p();function p(){const g=new Map;let m=!1;const w=()=>{if(m)return;m=!0;const k=()=>{m=!1,f.split()};typeof requestAnimationFrame=="function"?requestAnimationFrame(k):setTimeout(k,0)};if(typeof ResizeObserver=="function"){l=new ResizeObserver(k=>{let y=!1;for(const T of k){const $=Math.round(T.contentRect.width),M=g.get(T.target);g.set(T.target,$),M!==void 0&&M!==$&&(y=!0)}y&&w()});for(const k of t)l.observe(k)}const v=t[0]?.ownerDocument?.fonts;v&&v.status!=="loaded"&&v.ready.then(()=>w())}return f}function zb(t,e){const n=t.ownerDocument,s=[],i=n.createTreeWalker(t,4),o=[];for(let r=i.nextNode();r;r=i.nextNode())o.push(r);for(const r of o){const a=r.data.match(/\s+|\S+/g)??[];if(a.length===0)continue;const l=n.createDocumentFragment();for(const c of a){if(/^\s/.test(c)){l.appendChild(n.createTextNode(c));continue}const h=n.createElement("span");h.className=e,h.style.display="inline-block",h.textContent=c,l.appendChild(h),s.push(h)}r.replaceWith(l)}return s}function qb(t,e){const n=t.ownerDocument,s=Yb(t.textContent??"").map(i=>{const o=n.createElement("span");return o.className=e,o.style.display="inline-block",o.textContent=i,o});return t.replaceChildren(...s),s}function Yb(t){const e=Intl.Segmenter;return e?Array.from(new e(void 0,{granularity:"grapheme"}).segment(t),n=>n.segment):Array.from(t)}function Kb(t,e,n){const s=t.ownerDocument,i=new Map(e.map(p=>[p,p.getBoundingClientRect()])),o=[],r=p=>{for(const g of Array.from(p.childNodes))g.nodeType===3||i.has(g)||g.tagName==="BR"?o.push(g):r(g)};r(t);const a=[];let l=null,c=0,h=0,u=!1,d=[];const f=()=>{l=s.createElement("span"),l.className=n,l.style.display="block",a.push(l),d=[]};for(const p of o){if(p.tagName==="BR"){u=!0;continue}const g=i.get(p);if(g&&(!l||u||g.top>c+h)&&(f(),c=g.top,h=g.height/2,u=!1),!l)continue;const m=[];for(let k=p.parentNode;k&&k!==t;k=k.parentNode)m.unshift(k);let w=0;for(;w<d.length&&w<m.length&&d[w].original===m[w];)w++;d.length=w;let v=w===0?l:d[w-1].clone;for(const k of m.slice(w)){const y=k.cloneNode(!1);v.appendChild(y),d.push({original:k,clone:y}),v=y}v.appendChild(p)}return t.replaceChildren(...a),a}function jb(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 T0={top:0,left:0,start:0,center:.5,centre:.5,middle:.5,bottom:1,right:1,end:1};function ra(t){const e=t.trim().toLowerCase();if(e in T0)return T0[e];if(e.endsWith("%")){const n=Number.parseFloat(e.slice(0,-1));return Number.isNaN(n)?void 0:n/100}}function aa(t){if(typeof t=="number")return{elementFraction:0,viewportFraction:0,offsetPx:0,absolutePx:t};let e=0;const s=t.replace(/([+-])=\s*(-?[\d.]+)/g,(r,a,l)=>(e+=(a==="-"?-1:1)*Number.parseFloat(l),"")).trim().split(/\s+/).filter(Boolean);if(s.length===1&&/^-?[\d.]+$/.test(s[0]))return{elementFraction:0,viewportFraction:0,offsetPx:0,absolutePx:Number.parseFloat(s[0])+e};const i=s[0]!==void 0?ra(s[0]):void 0,o=s[1]!==void 0?ra(s[1]):void 0;return{elementFraction:i??0,viewportFraction:o??0,offsetPx:e}}function Cn(t,e,n){const s=aa(n),i=s.absolutePx!==void 0?t.top+s.absolutePx:t.top+t.height*s.elementFraction,o=e*s.viewportFraction;return i-o+s.offsetPx}function Xb(t,e,n,s){const i=Cn(t,e,n),r=Cn(t,e,s)-i;return r<=0?i<=0?1:0:la(-i/r)}function la(t){return t<0?0:t>1?1:t===0?0:t}function E0(t,e,n,s){if(n<=0)return e;const i=1-Math.exp(-(s/1e3)/n);return t+(e-t)*i}function ca(t,e,n,s,i){const o=h=>Cn({top:t+i(h),bottom:t+i(h)+e,height:e},n,s),r=o(0),a=o(1);if(Math.sign(r)===Math.sign(a)||r===0||a===0)return r===0?0:a===0?1:Math.abs(r)<Math.abs(a)?0:1;let l=0,c=1;for(let h=0;h<40;h++){const u=(l+c)/2;Math.sign(o(u))===Math.sign(r)?l=u:c=u}return(l+c)/2}class A0{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 Gb(t){const e=new A0(t);return e.start(),e}class P0{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 Ub=.15;function $0(t){return typeof t=="object"&&!Array.isArray(t)?t:{snapTo:t}}function I0(t,e,n){const s=Di(t+e*Ub);if(typeof n=="function")return Di(n(s));if(typeof n=="number")return n<=0?t:Di(Math.round(s/n)*n);if(n.length===0)return t;let i=n[0];for(const o of n)Math.abs(o-s)<Math.abs(i-s)&&(i=o);return Di(i)}function O0(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 _0{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=ms,o){if(this.cancel(),typeof requestAnimationFrame>"u"||s<=0){this.write(n),o?.();return}for(const l of this.cancelEvents)this.eventTarget?.addEventListener(l,this.onInterrupt,{passive:!0});let r=null;const a=l=>{r??=l;const c=Math.min(1,(l-r)/(s*1e3));this.write(e+(n-e)*i(c)),c<1?this.rafId=requestAnimationFrame(a):(this.rafId=null,this.detach(),o?.())};this.rafId=requestAnimationFrame(a)}cancel(){this.rafId!==null&&typeof cancelAnimationFrame<"u"&&cancelAnimationFrame(this.rafId),this.rafId=null,this.detach()}detach(){for(const e of this.cancelEvents)this.eventTarget?.removeEventListener(e,this.onInterrupt)}}function Di(t){return Math.max(0,Math.min(1,t))}class C0{options;scroller;nodes=[];scrollerStart;scrollerEnd;start;end;constructor(e,n,s){this.options=s===!0?{}:s,this.scroller=n;const{startColor:i="#3ecf7a",endColor:o="#ff5a5a",id:r}=this.options,a=r?`${r} `:"",l=(c,h,u)=>{const d=e.createElement("div");return d.textContent=`${a}${c}`,d.setAttribute("aria-hidden","true"),d.className="scroll-marker",Object.assign(d.style,{position:u?"fixed":"absolute",right:`${this.options.indent??0}px`,zIndex:"2147483646",pointerEvents:"none",borderTop:`1px solid ${h}`,color:h,font:`${this.options.fontSize??"11px"} ui-monospace, monospace`,padding:"2px 6px",whiteSpace:"nowrap",background:"rgba(0, 0, 0, 0.35)"}),(n??e.body).appendChild(d),this.nodes.push(d),d};this.scrollerStart=l("scroller-start",i,!n),this.scrollerEnd=l("scroller-end",o,!n),this.start=l("start",i,!1),this.end=l("end",o,!1),n&&getComputedStyle(n).position==="static"&&(n.style.position="relative")}place(e,n){this.start.style.top=`${e.startPage}px`,this.end.style.top=`${e.endPage}px`;const s=this.scroller?n:0;this.scrollerStart.style.top=`${s+e.startViewport}px`,this.scrollerEnd.style.top=`${s+e.endViewport}px`}follow(e,n){this.scroller&&this.place(e,n)}destroy(){for(const e of this.nodes.splice(0))e.remove()}}const Vb=120,Hn=[],Rn=new Set;let ha=!1;const Jb=()=>{ha||Rn.size===0||(ha=!0,queueMicrotask(()=>{ha=!1;for(const t of Rn)t.afterRefresh()}))},H0=()=>{for(const t of Rn)t.beforeRefresh();for(const t of Hn)t.refresh();for(const t of Rn)t.afterRefresh()};let Ln={width:0,height:0};const R0=()=>{const t=window.innerWidth,e=window.innerHeight,n=t===Ln.width&&e!==Ln.height,s=Math.abs(e-Ln.height)<Ln.height*.25,i=typeof navigator<"u"&&(navigator.maxTouchPoints??0)>0;n&&s&&i||(Ln={width:t,height:e},H0())};class $s{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 _0(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 P0(e,{axis:this.options.horizontal?"x":"y",spacing:this.options.pinSpacing!==!1})),this.options.markers&&!this.options.horizontal&&typeof document<"u"&&(this.markers=new C0(document,this.options.scroller??null,this.options.markers)),this.scrollTarget()?.addEventListener("scroll",this.onScroll,{passive:!0}),Hn.length===0&&typeof window<"u"&&(Ln={width:window.innerWidth,height:window.innerHeight},window.addEventListener("resize",R0,{passive:!0})),Hn.push(this),this.refresh()}stop(){this.running&&(this.running=!1,this.scrollTarget()?.removeEventListener("scroll",this.onScroll),Hn.splice(Hn.indexOf(this),1),Hn.length===0&&typeof window<"u"&&window.removeEventListener("resize",R0),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(){H0()}static onRefresh(e){return Rn.add(e),()=>Rn.delete(e)}get progress(){return this.targetProgress}get velocity(){return this.velocityPxPerSecond}refresh(){if(!this.running)return;this.measured&&this.options.onRefresh?.();const e=this.scrollPosition();this.pin?.release();const n=this.triggerRect();if(n&&this.options.container)this.measureInContainer(this.options.container);else if(n){const s=this.viewportHeight();if(this.startPx=e+Cn(n,s,Is(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,Jb()}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?la((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=Is(this.options.end)??"bottom top",o=typeof i=="string"?i.trim().match(/^\+=\s*(-?[\d.]+)\s*(%|px)?$/):null;if(o){const r=Number.parseFloat(o[1]);return this.startPx+(o[2]==="%"?n*r/100:r)}return s+Cn(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()},Vb))}fireBoundaryCallbacks(e,n){if(e===n)return;const{onEnter:s,onLeave:i,onEnterBack:o,onLeaveBack:r}=this.options;e==="before"?(s?.(),n==="after"&&i?.()):e==="after"?(o?.(),n==="before"&&r?.()):n==="after"?i?.():r?.()}scheduleSnap(){const e=this.options.snap;if(e===void 0||this.snapper.active)return;const n=$0(e),s=()=>{this.snapTimer=null;const i=this.endPx-this.startPx,o=this.scrollPosition();if(!this.running||i<=0||o<=this.startPx||o>=this.endPx)return;const r=(o-this.startPx)/i,a=this.startPx+I0(r,this.releaseVelocity/i,n.snapTo)*i;Math.abs(a-o)<1||this.snapper.animate(o,a,O0(n,a-o,this.viewportHeight()),n.ease)};n.delay?this.snapTimer=setTimeout(s,n.delay*1e3):s()}scrollTo(e){const n=this.options.scroller,s=this.options.horizontal?{left:e}:{top:e};n?typeof n.scrollTo=="function"?n.scrollTo({...s,behavior:"instant"}):this.options.horizontal?n.scrollLeft=e:n.scrollTop=e:typeof window<"u"&&window.scrollTo({...s,behavior:"instant"})}measureInContainer(e){const n=this.options.trigger;if(typeof n?.getBoundingClientRect!="function")return;const s=n.getBoundingClientRect(),i=this.options.scroller?.getBoundingClientRect?.().left??0,o=this.options.scroller?this.options.scroller.clientWidth:typeof window<"u"?window.innerWidth:0,r=s.left-i-e.shiftAt(e.progress()),{start:a,end:l}=e.range(),c=f=>a+f*(l-a),h=ca(r,s.width,o,Is(this.options.start)??"left right",e.shiftAt);this.startPx=c(h);const u=Is(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(ca(r,s.width,o,u,e.shiftAt)),this.markerGeometry=null}markersFor(e){const n=(o,r)=>{const a=Is(o)??r;if(typeof a=="number")return 0;if(/^\s*\+=/.test(a))return;const l=aa(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=E0(this.displayProgress,this.targetProgress,this.smoothing(),s);const i=Math.abs(this.targetProgress-this.displayProgress)<1e-4;i&&(this.displayProgress=this.targetProgress),this.applyProgress(),i?this.lastFrameTime=null:this.rafId=requestAnimationFrame(e)};this.rafId=requestAnimationFrame(e)}stopSmoothing(){this.rafId!==null&&typeof cancelAnimationFrame<"u"&&cancelAnimationFrame(this.rafId),this.rafId=null,this.lastFrameTime=null}scrollTarget(){return this.options.scroller??(typeof window<"u"?window:null)}scrollPosition(){const e=this.options.scroller,n=this.options.horizontal;return e?(n?e.scrollLeft:e.scrollTop)??0:typeof window<"u"?(n?window.scrollX:window.scrollY)??0:0}triggerRect(){const e=this.options.trigger;return typeof e?.getBoundingClientRect!="function"?null:this.relativeRect(e.getBoundingClientRect())}relativeRect(e){const n=this.options.horizontal,s=n?e.left??0:e.top,i=n?e.right??0:e.bottom,o=n?e.width??0:e.height,r=this.options.scroller;if(r&&typeof r.getBoundingClientRect=="function"){const a=r.getBoundingClientRect(),l=n?a.left:a.top;return{top:s-l,bottom:i-l,height:o}}return{top:s,bottom:i,height:o}}viewportHeight(){const e=this.options.scroller,n=this.options.horizontal;return e?n?e.clientWidth:e.clientHeight:typeof window<"u"?n?window.innerWidth:window.innerHeight:0}}function Is(t){return typeof t=="function"?t():t}function Zb(t){const e=new $s(t);return e.start(),e}const ua=new Set,Qb=16,L0=.5,tw=2;class da{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),ua.add(this),this.stopListening=$s.onRefresh({beforeRefresh:()=>this.rest(),afterRefresh:()=>this.refresh()}),this.refresh(),this}static refreshAll(){for(const e of ua)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),ua.delete(this),this.stopListening?.(),this.stopListening=null,this.cancelFrame(),this.journey=null,this}destroy(){this.stop();for(const e of this.effects)fa(e.element,e.saved);this.effects=[]}kill(){this.destroy()}get state(){const e=this.limit();return{scroll:this.current,target:this.target,progress:e>0?this.current/e:0,velocity:this.velocityPxPerSecond}}paused(e){return e!==void 0&&(this.pausedState=e,e&&(this.target=this.current,this.journey=null)),this.pausedState}scrollTo(e,n={}){if(!this.running)return;const s=this.clamp(this.resolve(e)+(n.offset??0)),i=Math.abs(s-this.current),o=this.reduced?0:n.duration??Math.min(1.2,Math.max(.4,i/2500));if(o<=0){this.journey=null,this.current=this.target=s,this.write(s),this.applyEffects(0);return}this.target=s,this.journey={from:this.current,to:s,ms:o*1e3,ease:n.ease??ms,elapsed:0},this.requestFrame()}refresh(){if(!this.running)return;this.rest(),this.effects=[];const e=this.options.effects===!0?"[data-speed], [data-lag]":this.options.effects||"";if(e&&!this.reduced){const n=this.options.scroller??document,s=this.position(),i=this.viewportHeight(),o=this.options.scroller?.getBoundingClientRect().top??0;for(const r of n.querySelectorAll(e)){const a=Number.parseFloat(r.dataset.speed??""),l=Number.parseFloat(r.dataset.lag??""),c=r.getBoundingClientRect(),h=c.top-o+s;this.effects.push({element:r,speed:Number.isFinite(a)?a:void 0,lag:Number.isFinite(l)&&l>0?l:void 0,centre:h+c.height/2-i/2,lagged:s,shift:0,saved:r.style.getPropertyValue("translate")})}}this.current=this.target=this.clamp(this.position()),this.applyEffects(0)}rest(){for(const e of this.effects)fa(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?Qb: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)<=tw||(this.written=null,this.journey=null,this.cancelFrame(),this.current=this.target=e,this.requestFrame())}nestedScrollerTakes(e){const n=this.options.scroller??document.documentElement;for(let s=e.target;s&&s!==n&&s!==document.body;s=s.parentElement){if(s.hasAttribute?.("data-smooth-ignore"))return!0;const i=getComputedStyle(s);if(!/(auto|scroll)/.test(i.overflowY)||s.scrollHeight<=s.clientHeight)continue;if(e.deltaY<0?s.scrollTop>0:s.scrollTop+s.clientHeight<s.scrollHeight-1)return!0}return!1}requestFrame(){this.frameId!==null||!this.running||(this.frameId=this.frames.request(e=>this.frame(e)))}cancelFrame(){this.frameId!==null&&this.frames.cancel(this.frameId),this.frameId=null,this.lastTime=null}frame(e){this.frameId=null;const n=this.lastTime===null?1e3/60:Math.min(100,e-this.lastTime);this.lastTime=e;const s=this.current;if(this.journey){const o=this.journey;o.elapsed+=n;const r=Math.min(1,o.elapsed/o.ms);this.current=o.from+(o.to-o.from)*o.ease(r),r>=1&&(this.journey=null)}else if(this.current!==this.target){const o=(this.options.smooth??.8)*1e3/3;this.current+=(this.target-this.current)*(1-Math.exp(-n/o)),Math.abs(this.target-this.current)<L0&&(this.current=this.target)}this.current!==s&&this.write(this.current),this.velocityPxPerSecond=n>0?(this.current-s)*1e3/n:0;const i=this.applyEffects(n);this.current!==s&&this.options.onUpdate?.(this.state),this.journey||this.current!==this.target||i?this.requestFrame():(this.lastTime=null,this.velocityPxPerSecond=0)}applyEffects(e){let n=!1;const s=this.current;for(const i of this.effects){let o=0;if(i.speed!==void 0&&(o+=(s-i.centre)*(1-i.speed)),i.lag!==void 0){const r=i.lag*1e3/3;i.lagged=e===0?s:i.lagged+(s-i.lagged)*(1-Math.exp(-e/r)),Math.abs(s-i.lagged)<L0?i.lagged=s:n=!0,o+=s-i.lagged}fa(i.element,o===0?i.saved:`0 ${ew(o)}px`),i.shift=o}return n}write(e){const n=Math.round(e);this.written=n;const s=this.options.scroller;s?s.scrollTop=n:window.scrollTo({top:n,behavior:"instant"})}position(){const e=this.options.scroller;return e?e.scrollTop:window.scrollY}viewportHeight(){const e=this.options.scroller;return e?e.clientHeight:window.innerHeight}limit(){const e=this.options.scroller??document.documentElement;return Math.max(0,e.scrollHeight-this.viewportHeight())}clamp(e){return Math.max(0,Math.min(this.limit(),e))}resolve(e){if(typeof e=="number")return e;const n=this.options.scroller??document,s=typeof e=="string"?n.querySelector(e):e;if(!s)return this.current;const i=this.options.scroller?.getBoundingClientRect().top??0,o=this.effects.find(r=>r.element===s)?.shift??0;return s.getBoundingClientRect().top-i+this.position()-o}}function fa(t,e){e?t.style.setProperty("translate",e):t.style.removeProperty("translate")}function ew(t){return Math.round(t*100)/100}function nw(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 ga(t,e,n,s,i=()=>{}){const o=f=>typeof f=="string"?t.query(f)??void 0:f,r=o(e.trigger)??s;if(!r){i(`gsap-compat: scrollTrigger has no trigger element${typeof e.trigger=="string"?` for "${e.trigger}"`:""}`);return}const a=e.scrub===void 0||e.scrub===!1?!1:e.scrub,l=(e.toggleActions??"play none none none").trim().split(/\s+/);let c=0,h;const u=(f,p)=>()=>{p?.(),n&&!a&&nw(n,l[f]??"none"),e.once&&f===0&&queueMicrotask(()=>h.destroy())},d=e.containerAnimation?ow(t,e.containerAnimation,r,i):void 0;return h=new $s({trigger:r,start:e.start,end:e.end,scrub:a===!1?void 0:a,pin:e.pin===!0?!0:o(e.pin),scroller:o(e.scroller),horizontal:e.horizontal,pinSpacing:e.pinSpacing,onRefresh:e.invalidateOnRefresh&&n?.invalidate?()=>n.invalidate():void 0,snap:e.snap===void 0?void 0:sw(e.snap,n),markers:e.markers,container:d,onUpdate:(f,p)=>{if(n&&a!==!1&&n.progress(f),e.onUpdate){const g=f<c||p<0?-1:1;e.onUpdate({progress:f,velocity:p,direction:g})}c=f},onEnter:u(0,e.onEnter),onLeave:u(1,e.onLeave),onEnterBack:u(2,e.onEnterBack),onLeaveBack:u(3,e.onLeaveBack)}),n&&a===!1&&n.progress(0),h.start(),t.own(h)}function sw(t,e){const n=i=>i==="labels"?o=>iw(o,e?.labelProgresses?.()??[]):i;if(typeof t!="object"||Array.isArray(t))return n(t);const s=t.ease?Es(t.ease):void 0;return{snapTo:n(t.snapTo),duration:t.duration,delay:t.delay,ease:s?s.fn??Lt(s.easing):void 0}}function iw(t,e){return e.reduce((n,s)=>Math.abs(s-t)<Math.abs(n-t)?s:n,e[0]??t)}function ow(t,e,n,s){const i=()=>e.timeline.getTracks({property:"x"}).map(o=>o.target).filter(o=>{const r=t.elementFor(o);return!!r&&r!==n&&r.contains(n)});return i().length===0&&s("gsap-compat: containerAnimation does not move an ancestor of the trigger along x"),{range:()=>{const o=e.scrollTrigger;return o||s("gsap-compat: containerAnimation needs its own scrollTrigger (created before this one)"),{start:o?.startOffset??0,end:o?.endOffset??0}},progress:()=>e.progress(),shiftAt:o=>{const r=e.timeline.getStateAtTime(o*e.timeline.duration);let a=0;for(const l of i()){const c=r.values.get(l)?.get("x");typeof c=="number"&&(a+=c)}return a}}}class N0{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 rw{host;scope;entries=[];listeners=[];scheduled=!1;constructor(e,n){this.host=e,this.scope=n}add(e,n){const s={conditions:e,setup:n,queries:new Map},i=typeof e=="string"?{matches:e}:e;if(typeof window<"u"&&typeof window.matchMedia=="function")for(const[o,r]of Object.entries(i)){const a=window.matchMedia(r);s.queries.set(o,a);const l=()=>this.scheduleUpdate();a.addEventListener("change",l),this.listeners.push(()=>a.removeEventListener("change",l))}return this.entries.push(s),this.update(s),this}revert(){for(const e of this.listeners.splice(0))e();for(const e of this.entries.splice(0))e.context?.revert()}kill(){this.revert()}scheduleUpdate(){this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1;for(const e of this.entries)this.update(e)}))}update(e){const n={};for(const[r,a]of e.queries)n[r]=a.matches;const s=Object.values(n).some(Boolean),i=s?JSON.stringify(n):void 0;if(i===e.key||(e.context?.revert(),e.context=void 0,e.key=i,!s))return;const o=new N0(this.host,this.scope);o.conditions=n,o.add(()=>e.setup(o)),e.context=o}}class aw{frames;canvas;context;options;images;ready;current=0;drawn=-1;loadedCount=0;inFlight=0;destroyed=!1;onResize=()=>this.resize();constructor(e,n){this.canvas=e,this.context=e.getContext("2d"),this.options=n,this.frames=Math.max(1,Math.floor(n.frames)),this.images=new Array(this.frames),this.ready=new Array(this.frames).fill(!1),typeof window<"u"&&window.addEventListener("resize",this.onResize,{passive:!0}),this.resize(),this.pump()}get frame(){return this.current}set frame(e){this.current=Math.max(0,Math.min(this.frames-1,e)),this.draw()}get loaded(){return this.loadedCount}destroy(){this.destroyed=!0,typeof window<"u"&&window.removeEventListener("resize",this.onResize);for(const e of this.images)e&&(e.src="")}resize(){const e=typeof window<"u"?Math.min(window.devicePixelRatio||1,2):1,n=Math.round(this.canvas.clientWidth*e),s=Math.round(this.canvas.clientHeight*e);n>0&&s>0&&(this.canvas.width!==n||this.canvas.height!==s)&&(this.canvas.width=n,this.canvas.height=s),this.drawn=-1,this.draw()}draw(){const e=Math.round(this.current),n=this.nearestReady(e);if(n===-1||n===this.drawn||!this.context)return;const s=this.images[n],{width:i,height:o}=this.canvas,r=(this.options.fit??"cover")==="cover"?Math.max(i/s.naturalWidth,o/s.naturalHeight):Math.min(i/s.naturalWidth,o/s.naturalHeight),a=s.naturalWidth*r,l=s.naturalHeight*r;this.context.clearRect(0,0,i,o),this.context.drawImage(s,(i-a)/2,(o-l)/2,a,l),this.drawn=n,this.pump()}nearestReady(e){for(let n=0;n<this.frames;n++){if(e-n>=0&&this.ready[e-n])return e-n;if(e+n<this.frames&&this.ready[e+n])return e+n}return-1}pump(){const e=this.options.concurrency??6,n=Math.round(this.current);for(let s=0;s<this.frames&&this.inFlight<e;s++)for(const i of s===0?[n]:[n+s,n-s])i<0||i>=this.frames||this.images[i]||this.inFlight>=e||this.load(i)}load(e){const n=new Image;n.decoding="async",this.images[e]=n,this.inFlight++;const s=i=>{if(!this.destroyed){if(this.inFlight--,i){this.ready[e]=!0,this.loadedCount++,this.options.onProgress?.(this.loadedCount,this.frames);const o=Math.round(this.current);(Math.abs(e-o)<Math.abs(this.drawn-o)||this.drawn===-1)&&(this.drawn=-1,this.draw())}this.pump()}};n.onload=()=>s(!0),n.onerror=()=>s(!1),n.src=this.options.url(e)}}const lw={opacity:0,y:-16},cw={opacity:0,y:16};async function hw(t,e,n,s){const i=e.collector?.scope??e.root,o=i.ownerDocument??i,r=()=>s.shared?[...i.querySelectorAll(s.shared)]:[];if(s.native&&typeof o.startViewTransition=="function")return uw(o,s,r);const a=s.duration??.35,l=s.ease??"power2.inOut",c=m=>new Promise(w=>{m(w)||w()}),h=r(),u=h.length?sa(e,h):void 0,d=s.from!==void 0?F0(e,s.from,s.shared):[];if(d.length&&s.leave!==!1){const m=s.leave??lw;await c(w=>t.to(d,{...m,duration:a,ease:l,onComplete:w}))}await s.update();const f=[],p=typeof s.to=="function"?s.to():s.to,g=p!==void 0?F0(e,p,s.shared):[];if(g.length&&s.enter!==!1){const m=s.enter??cw;f.push(c(w=>t.fromTo(g,m,{...x0(m),duration:a,ease:l,onComplete:w})))}if(u){const m=r().filter(w=>!h.includes(w));m.length&&f.push(c(w=>oa(e,n,u,{targets:m,duration:a*1.4,ease:l,enter:!1,onComplete:w})))}await Promise.all(f)}function F0(t,e,n){const s=t.resolveTargets(e).map(i=>t.elementFor(i)).filter(i=>!!i);return n?s.flatMap(i=>!i.querySelector(n)&&!i.matches(n)?[i]:[...i.children].filter(o=>!o.matches(n)&&!o.querySelector(n))):s}async function uw(t,e,n){const s=(a,l)=>{const c=a.dataset?.flipId;c&&a.style.setProperty("view-transition-name",l?`tf-${c.replace(/[^\w-]/g,"-")}`:"")},i=n();i.forEach(a=>s(a,!0));let o=[];await t.startViewTransition(async()=>{i.forEach(a=>s(a,!1)),await e.update(),o=n(),o.forEach(a=>s(a,!0))}).finished,o.forEach(a=>s(a,!1))}const W0={create:(t,e)=>Gr(t,Nh(e))},D0={create:(t,e)=>Gr(t,{fn:Fh(e)})},B0={create:(t,e)=>Gr(t,{fn:Wh(e)})},dw=new Set(["keyframes","duration","delay","ease","easeEach","stagger","repeat","repeatDelay","yoyo","repeatRefresh","paused","id","onStart","onUpdate","onComplete","onRepeat","onReverseComplete","scrollTrigger"]),z0=.5,fw="power1.inOut";function gw(t){return t.keyframes!==void 0&&t.keyframes!==null}function pw(t){const e=t.keyframes,n={};for(const[c,h]of Object.entries(t))dw.has(c)||(n[c]=h);if(Array.isArray(e))return e.map(c=>({...n,...c,duration:c.duration??t.duration??z0}));const s=Object.entries(e),i=t.duration??z0,o=e.easeEach??t.easeEach??fw;if(s.length>0&&s.every(([c])=>/^\s*-?\d+(\.\d+)?\s*%\s*$/.test(c)||c==="easeEach")){const c=s.filter(([d])=>d!=="easeEach").map(([d,f])=>({at:Number.parseFloat(d)/100,step:f})).sort((d,f)=>d.at-f.at),h=[];let u=0;for(const{at:d,step:f}of c){const p=Math.max(0,d-u);h.push({...n,ease:o,...f,duration:p*i}),u=d}return h}const r=s.filter(([c,h])=>c!=="easeEach"&&Array.isArray(h)),a=Math.max(0,...r.map(([,c])=>c.length)),l=[];for(let c=0;c<a;c++){const h={...n,ease:o,duration:i/a};for(const[u,d]of r)c<d.length&&(h[u]=d[c]);l.push(h)}return l}function q0(t,e,n,s={}){const i=e.collector?.scope??e.root,o=typeof s.scroller=="string"?i.querySelector(s.scroller):s.scroller??null,r={x:o?o.scrollLeft:window.scrollX,y:o?o.scrollTop:window.scrollY},a={x:o?o.scrollWidth-o.clientWidth:document.documentElement.scrollWidth-window.innerWidth,y:o?o.scrollHeight-o.clientHeight:document.documentElement.scrollHeight-window.innerHeight},l=(v,k)=>{if(k===void 0)return r[v];if(typeof k=="number")return k;if(k==="max")return a[v];const y=typeof k=="string"?i.querySelector(k):k;if(!y)return r[v];const T=y.getBoundingClientRect(),$=o?.getBoundingClientRect(),M=(v==="x"?s.offsetX:s.offsetY)??s.offset??0;return v==="x"?T.left-($?.left??0)+r.x-M:T.top-($?.top??0)+r.y-M},c=typeof n=="object"&&n!==null&&!("nodeType"in n)?{x:l("x",n.x),y:l("y",n.y)}:{x:r.x,y:l("y",n)},h={x:Math.max(0,Math.min(a.x,c.x)),y:Math.max(0,Math.min(a.y,c.y))},u={...r},d=()=>{o?(o.scrollLeft=u.x,o.scrollTop=u.y):window.scrollTo({left:u.x,top:u.y,behavior:"instant"})},f=["wheel","touchstart","keydown"],p=o??window,g=()=>{w.kill(),m()},m=()=>{for(const v of f)p.removeEventListener(v,g)},w=t.to(u,{x:h.x,y:h.y,duration:s.duration??1,ease:s.ease??"power2.inOut",onStart:s.onStart,onUpdate:()=>{d(),s.onUpdate?.()},onComplete:()=>{m(),s.onComplete?.()}});if(s.autoKill!==!1)for(const v of f)p.addEventListener(v,g,{passive:!0});return w}function mw(t,e,n){const s=t.collector?.scope??t.root,i=typeof e=="string"?[...s.querySelectorAll(e)]:"nodeType"in e?[e]:Array.from(e),{interval:o=.1,batchMax:r,onEnter:a,onLeave:l,onEnterBack:c,onLeaveBack:h,...u}=n,d={onEnter:a,onLeave:l,onEnterBack:c,onLeaveBack:h},f={onEnter:[],onLeave:[],onEnterBack:[],onLeaveBack:[]},p={},g=w=>{p[w]!==void 0&&clearTimeout(p[w]),p[w]=void 0;const v=f[w].splice(0);v.length>0&&d[w]?.(v)},m=(w,v)=>{if(d[w]){if(f[w].push(v),r!==void 0&&f[w].length>=r)return g(w);p[w]===void 0&&(p[w]=setTimeout(()=>g(w),o*1e3))}};return i.map(w=>ga(t,{...u,trigger:w,onEnter:()=>m("onEnter",w),onLeave:()=>m("onLeave",w),onEnterBack:()=>m("onEnterBack",w),onLeaveBack:()=>m("onLeaveBack",w)})).filter(w=>w!==void 0)}class ge{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 nn({...s,startValue:(i,o)=>{const r=e.objectFor(i);if(r)return ww(r[o]);const a=e.appliedValue(i,o);if(a!==void 0)return a;if(o==="d")return g0(e.elementFor(i))??void 0;if(o==="text")return e.elementFor(i)?.textContent??void 0;if(o==="strokeDasharray"||o==="strokeDashoffset"){const l=G0(e.elementFor(i));if(l!==void 0)return o==="strokeDasharray"?[l,l]:0}},startVelocity:(i,o)=>e.velocityOf(i,o),layoutColumns:i=>X0(i.map(o=>e.elementFor(o))),random:()=>e.utils.random(0,1)}),this.compat.timeline.onComplete=()=>{this.finishedThisFrame=!0},e.collector?.track(this),e.liveTimelines.add(this),this.autoplayPending=!s.paused&&!s.scrollTrigger,s.scrollTrigger){const i=s.scrollTrigger;queueMicrotask(()=>{this.killed||(this.scrollDriver=ga(e,i,this,this.firstElement,o=>s.onWarning?.(o)))})}this.autoplayPending&&queueMicrotask(()=>{this.autoplayPending&&this.play()})}get timeline(){return this.compat.timeline}get scrollTrigger(){return this.scrollDriver}to(e,n,s){return gw(n)?this.record(()=>this.keyframed(e,n,s)):this.record(()=>this.tween(e,[n],s,([i],o,r)=>this.compat.to(o,i,r)))}from(e,n,s){return this.record(()=>this.tween(e,[n],s,([i],o,r)=>this.compat.from(o,i,r)))}fromTo(e,n,s,i){return this.record(()=>this.tween(e,[n,s],i,([o,r],a,l)=>this.compat.fromTo(a,o,r,l)))}set(e,n,s){return this.record(()=>this.tween(e,[n],s,([i],o,r)=>this.compat.set(o,i,r)))}addLabel(e,n){return this.record(()=>this.compat.addLabel(e,n))}add(e,n){return this.record(()=>{e.autoplayPending=!1,e.timeline.stop(),e.stage.deactivate(e.timeline),this.compat.add(e.compat,n)})}invalidate(){const e=this.compat.progress();this.compat.progress(0),this.stage.render(this.timeline),this.compat.reset(),this.events=[],this.ranges=[];for(const n of this.recipe)n();return this.syncDuration(),this.compat.progress(e),this.stage.render(this.timeline),this}call(e,n=[],s){return this.record(()=>{const i=this.compat.addEvent(s);this.events.push({time:i,run:()=>e(...n)})})}addPause(e,n,s=[]){return this.record(()=>{const i=this.compat.addEvent(e);this.events.push({time:i,pause:!0,run:()=>n?.(...s)})})}tweenTo(e,n={}){return this.tweenFromTo(this.timeline.currentTime/1e3,e,n)}tweenFromTo(e,n,s={}){this.pause(),this.seek(e);const i=this.timeline.currentTime,o=Math.max(0,Math.min(this.timeline.duration,this.compat.timeOf(n))),r={time:i},a=s.duration??Math.abs(o-i)/1e3/(this.timeScale()||1),l=new ge(this.stage,{onStart:s.onStart,onComplete:s.onComplete});return l.to(r,{time:o,duration:a,ease:s.ease??"none",onUpdate:()=>{this.moveTo(r.time),s.onUpdate?.()}}),l}play(){this.autoplayPending=!1,this.started||(this.started=!0,this.options.onStart?.());const e=this.timeline.playbackState==="playing",n=this.timeline.playbackState==="paused";if(this.timeline.play(),!e){const s=this.timeline,i=s.direction==="forward"?s.currentTime===0:s.currentTime===s.duration;this.playhead={...this.readPlayhead(),fresh:i&&!n},this.waitingToWrap=!1}return this.stage.liveTimelines.add(this),this.stage.render(this.timeline),this.stage.activate(this.timeline,{onUpdate:()=>this.afterFrame()}),this}pause(){return this.autoplayPending=!1,this.timeline.pause(),this.stage.deactivate(this.timeline),this}resume(){return this.play()}restart(){return this.timeline.stop(),this.backwards=!1,this.play()}reverse(){this.backwards=!this.backwards;const e=this.timeline.playbackState==="idle"&&this.timeline.direction==="forward";return this.timeline.reverse(),e&&this.timeline.currentTime===0&&this.timeline.seek(this.timeline.duration),this.play()}labelProgresses(){const e=this.timeline.duration;return e>0?this.compat.labelTimes().map(n=>n/e):[]}reversed(){return this.timeline.direction==="reverse"}seek(e){return this.autoplayPending=!1,this.compat.seek(e),this.stage.render(this.timeline),this.playhead=this.readPlayhead(),this.waitingToWrap=!1,this.options.onUpdate?.(),this}progress(e){return e===void 0?this.compat.progress():(this.autoplayPending=!1,this.moveTo(Math.max(0,Math.min(1,e))*this.timeline.duration),this.compat.progress())}timeScale(e){return this.compat.timeScale(e)}duration(){return this.compat.duration()}isActive(){return this.timeline.playbackState==="playing"}kill(){return this.killed=!0,this.stage.liveTimelines.delete(this),this.scrollDriver?.destroy(),this.scrollDriver=void 0,this.autoplayPending=!1,this.timeline.stop(),this.stage.deactivate(this.timeline),this.compat.kill(),this}toDefinition(){return this.compat.toDefinition()}killTweensOf(e,n){for(const s of e)for(const i of n??[void 0])this.timeline.removeTracks({target:s,...i!==void 0&&{property:i}});this.timeline.tracks.length===0&&this.events.length===0&&this.kill()}record(e){return this.recipe.push(e),e(),this.syncDuration(),this}syncDuration(){if(this.events.length===0)return;this.timeline.setDuration(void 0);const e=Math.max(...this.events.map(n=>n.time));e>this.timeline.duration&&this.timeline.setDuration(e)}readPlayhead(){const e=this.timeline;return{time:e.currentTime,iteration:e.loopIteration,direction:e.direction}}moveTo(e){const n=this.playhead;this.timeline.seek(e),this.stage.render(this.timeline);const s={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:e>=n.time?"forward":"reverse"},i={...n,iteration:s.iteration,direction:s.direction};this.playhead={...this.readPlayhead()},this.waitingToWrap=!1,this.runCrossings(i,s,!1),this.options.onUpdate?.()}refreshForRepeat(){const e=this.timeline.currentTime;this.compat.reset(),this.events=[],this.ranges=[];for(const n of this.recipe)n();this.syncDuration(),this.timeline.seek(Math.min(e,this.timeline.duration))}afterFrame(){const e=this.timeline,n=e.repeatDelayRemaining>0;if(this.waitingToWrap&&n){this.options.onUpdate?.();return}this.waitingToWrap=!1;const s=this.playhead,i=this.readPlayhead();this.playhead=i;const o=this.options.yoyo===!0;n&&!o&&i.iteration>s.iteration&&(this.playhead={time:0,iteration:i.iteration,direction:"forward",fresh:!0},this.waitingToWrap=!0);const r=this.runCrossings(s,i,n);if(this.options.onUpdate?.(),this.finishedThisFrame&&!r){this.finishedThisFrame=!1;const a=e.currentTime===0&&e.direction==="reverse";!this.scrollDriver&&!o&&this.stage.liveTimelines.delete(this),a&&this.backwards?this.options.onReverseComplete?.():this.options.onComplete?.()}this.finishedThisFrame=!1}runCrossings(e,n,s){if(this.events.length===0&&this.ranges.length===0&&!this.options.onRepeat&&!this.options.repeatRefresh)return!1;const i=this.events,{crossings:o,passes:r}=Rr(i.map(a=>a.time),e,n,{duration:this.timeline.duration,alternate:this.options.yoyo===!0,holding:s});for(const a of o){if(this.killed)return!0;if(a.kind==="repeat"){this.options.repeatRefresh&&this.refreshForRepeat(),this.options.onRepeat?.();continue}const l=i[a.index];if(!(l.direction&&l.direction!==a.direction)){if(l.pause)return this.timeline.seek(l.time),this.stage.render(this.timeline),this.pause(),this.playhead=this.readPlayhead(),this.waitingToWrap=!1,l.run(),!0;l.run()}}for(const a of this.ranges)r.some(([c,h])=>c!==h&&Math.max(c,h)>=a.start&&Math.min(c,h)<=a.end)&&a.run();return!1}tween(e,n,s,i){const o=this.resolve(e);if(!o)return;const{onStart:r,onUpdate:a,onComplete:l}=n[n.length-1];if(r||a||l){let c=1/0,h=-1/0;const u=(d,f,p)=>{i(d,f,p),c=Math.min(c,this.compat.lastStart),h=Math.max(h,this.compat.lastEnd)};if(this.buildTween(o,n,s,u),c===1/0)return;r&&this.events.push({time:c,direction:"forward",run:r}),a&&this.ranges.push({start:c,end:h,run:a}),l&&this.events.push({time:h,direction:"forward",run:l});return}this.buildTween(o,n,s,i)}keyframed(e,n,s){const i=this.resolve(e);if(!i)return;const o=pw(n);if(o.length===0)return;const r=i.length>1?Jr(n.stagger,this.staggerContext(i)):void 0,a=i.map(m=>this.targetFor(m)).filter(m=>m!==void 0),l=r?a.map(m=>[m]):[a],c=r?wi(i.length,r).map(m=>m/1e3):[0],h=this.compat.timeOf(s)/1e3+Fi(n.delay,0)/1e3;let u=1/0,d=-1/0;if(l.forEach((m,w)=>{o.forEach((v,k)=>{const y=k===0?h+c[w]:">";this.tween(m,[v],y,([T],$,M)=>this.compat.to($,T,M)),u=Math.min(u,this.compat.lastStart),d=Math.max(d,this.compat.lastEnd)})}),u===1/0)return;const{onStart:f,onUpdate:p,onComplete:g}=n;f&&this.events.push({time:u,direction:"forward",run:f}),p&&this.ranges.push({start:u,end:d,run:p}),g&&this.events.push({time:d,direction:"forward",run:g})}staggerContext(e){return{count:e.length,columnsFromLayout:()=>X0(e.map(n=>this.stage.elementFor(n))),random:()=>this.stage.utils.random(0,1)}}buildTween(e,n,s,i){const o=e.map(d=>this.targetFor(d));if(!(e.length>1&&(n.some(bw)||e.some(d=>this.stage.objectFor(d)!==void 0)))){const d=this.targetFor(e[0]);i(n.map(f=>this.prepare(j0(f,0,d,this.stage.utils,o),e)),e,s);return}const a=n.length-1,{stagger:l,...c}=n[a],h=Jr(l,this.staggerContext(e)),u=h?wi(e.length,h).map(d=>d/1e3):e.map(()=>0);e.forEach((d,f)=>{const p=f===0?Fi(c.delay,0)/1e3+u[0]:0,g=f===0?0:u[f]-u[f-1],m=f===0?s:`<${g<0?"-":"+"}${Math.abs(g).toFixed(6)}`,v=n.map((k,y)=>y===a?{...c,delay:p}:k).map(k=>this.prepare(j0(k,f,this.targetFor(d),this.stage.utils,o),[d]));i(v,[d],m)})}targetFor(e){return this.stage.elementFor(e)??this.stage.objectFor(e)}prepare(e,n){const s=r=>this.options.onWarning?.(r),i=r=>this.stage.query(r);let o=e;if(e.motionPath!==void 0){const r=Ib(e.motionPath,{query:i,targets:n.map(a=>this.stage.elementFor(a)).filter(a=>!!a),warn:s});o={...o,motionPath:r}}if(e.morphSVG!==void 0){const r=Ob(e.morphSVG,i,s),{morphSVG:a,...l}=o;o=r?{...o,morphSVG:r}:l}if(e.drawSVG!==void 0){const r=G0(this.stage.elementFor(n[0]));if(r===void 0){s("gsap-compat: drawSVG needs an SVG shape with a stroke (path, line, circle…)");const{drawSVG:a,...l}=o;o=l}else o=sb(o,r)}return o}resolve(e){const n=this.stage.resolveTargets(e);if(n.length===0){this.options.onWarning?.(`gsap-compat: no elements found for target ${kw(e)}`);return}return this.firstElement??=n.map(s=>this.stage.elementFor(s)).find(s=>s!==void 0),n}}function Y0(t=new h0){const e=o=>{const{config:r}=Ni(o);return new ge(t,{repeat:r.repeat,yoyo:r.yoyo,repeatDelay:r.repeatDelay,paused:r.paused,onStart:r.onStart,onUpdate:r.onUpdate,onComplete:r.onComplete,onRepeat:r.onRepeat,onReverseComplete:r.onReverseComplete,repeatRefresh:r.repeatRefresh,scrollTrigger:r.scrollTrigger})},n=o=>{const{onStart:r,onUpdate:a,onComplete:l,onRepeat:c,onReverseComplete:h,repeatRefresh:u,...d}=o;return d},s=o=>(o&&t.collector?.track(o),o),i={stage:t,ticker:t.ticker,utils:t.utils,getProperty:(o,r)=>{const[a]=t.resolveTargets(o);if(a===void 0)return;const l=t.objectFor(a);return l?l[r]:t.appliedValue(a,r)??o0(r)},scrollTrigger:o=>s(ga(t,o)),scrollBatch:(o,r)=>mw(t,o,r).map(a=>s(a)),scrollTo:(o,r)=>q0(i,t,o,r),refreshScroll:()=>{$s.refreshAll(),da.refreshAll()},smoothScroll:(o={})=>{const r=typeof o.scroller=="string"?(t.collector?.scope??t.root).querySelector(o.scroller):o.scroller;return s(new da({...o,scroller:r}).start())},context:(o,r)=>{const a=new N0(t,r);return o&&a.add(()=>o(a)),a},matchMedia:o=>new rw(t,o),customEase:W0.create,customBounce:D0.create,customWiggle:B0.create,pageTransition:o=>hw(i,t,r=>new ge(t,r),o),imageSequence:(o,r)=>{const a=typeof o=="string"?(t.collector?.scope??t.root).querySelector(o):o;if(!(a instanceof HTMLCanvasElement))throw new Error(`gsap-compat: imageSequence needs a <canvas>, got ${String(o)}`);return s(new aw(a,r))},quickTo:(o,r,a={})=>{const l=new ge(t,{paused:!0}),[c]=t.resolveTargets(o);return Object.assign(u=>{if(!c)return;const d=a.spring!==void 0?t.velocityOf(c,r)??0:0;l.compat.reset(),l.compat.to(c,{[r]:u,duration:a.duration??.4,ease:a.ease??"power3.out",...a.spring!==void 0&&{spring:yw(a.spring,r,d)}}),l.timeline.stop(),l.timeline.play(),t.activate(l.timeline)},{tween:l,kill:()=>l.kill()})},timeline:o=>new ge(t,o),to:(o,r)=>{if(r.scrollTo!==void 0){const{scrollTo:a,...l}=r,c=typeof a=="object"&&a!==null&&!("nodeType"in a)?a:{},h=typeof o!="string"&&o!==window&&o.nodeType===1;return q0(i,t,a,{...l,offsetX:c.offsetX,offsetY:c.offsetY,scroller:h?o:void 0})}return e(r).to(o,n(r))},from:(o,r)=>e(r).from(o,n(r)),fromTo:(o,r,a)=>e(a).fromTo(o,r,n(a)),set:(o,r)=>e(r).set(o,n(r)),delayedCall:(o,r,a)=>new ge(t).call(r,a,o),killTweensOf:(o,r)=>{const a=t.resolveTargets(o),l=typeof r=="string"?r.split(",").map(c=>c.trim()).filter(Boolean):r;for(const c of[...t.liveTimelines])c.killTweensOf(a,l)},convertToPath:o=>Cb(o,t.root),splitText:(o,r)=>{const a=t.collector?.scope??t.root,l=typeof o=="string"?Array.from(a.querySelectorAll(o)):"nodeType"in o?[o]:Array.from(o);return s(Bb(l,r))},draggable:(o,r)=>s(Nb(i,t,o,r)),getFlipState:o=>sa(t,o),flipFrom:(o,r)=>oa(t,a=>new ge(t,a),o,r),flip:(o,r,a)=>{const l=sa(t,o);return r(),oa(t,c=>new ge(t,c),l,{targets:o,...a})}};return i}const Ut=Y0();function yw(t,e,n){return t===!0?{velocity:{[e]:n}}:typeof t=="string"?{preset:t,velocity:{[e]:n}}:{...t,velocity:{[e]:n}}}function bw(t){return t.morphSVG!==void 0||t.drawSVG!==void 0||t.text!==void 0||t.scrambleText!==void 0||K0(t)}function K0(t){return Object.entries(t).some(([e,n])=>(typeof n=="function"||s0(n))&&!Vr.has(e))}function j0(t,e,n,s,i){if(!K0(t))return t;const o={};for(const[r,a]of Object.entries(t))Vr.has(r)?o[r]=a:typeof a=="function"?o[r]=a(e,n,i):s0(a)?o[r]=s.resolveRandomString(a):o[r]=a;return o}function X0(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 G0(t){const e=t;if(typeof e?.getTotalLength=="function")return e.getTotalLength()}function ww(t){if(typeof t=="number"||typeof t=="string"||Array.isArray(t)&&t.every(e=>typeof e=="number"))return t}function kw(t){return typeof t=="string"?`"${t}"`:String(t)}class pa{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 U0(t,e,n,s,i){const o=n-i;if(o<0){e.paused||e.pause(),e.currentTime=0;return}t.update(o,s)}class Bi{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 sn}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=$n({...e,config:n}),this.markerList=this.timeline.markers,this.lastMarkerId=null,this.options.onComplete&&(this.timeline.onComplete=this.options.onComplete),this.options.onUpdate&&(this.timeline.onUpdate=this.options.onUpdate),this.autoRegisterTargets(),this.setupSymbolInstances(),this.scanMedia()}async loadScenarios(e,n={}){if(e.length===0)throw new Error("tinyfly: loadScenarios needs at least one scenario");const s=new Set;for(const o of e){if(s.has(o.id))throw new Error(`tinyfly: scenario id "${o.id}" is used more than once`);s.add(o.id)}const i=n.initial===void 0?e[0]:e.find(o=>o.id===n.initial);if(!i)throw new Error(`tinyfly: there is no scenario "${n.initial}"`);this.scenarioList=[...e],this.scenarioId=i.id,await this.loadSource(i.timeline)}get scenarios(){return this.scenarioList.map(e=>({id:e.id,label:e.label??e.id}))}get scenario(){return this.scenarioId}setScenario(e){const n=this.scenarioList.find(a=>a.id===e);if(!n||!this.timeline)return!1;if(e===this.scenarioId)return!0;const s=this.isPlaying,i=this.currentTime>=this.duration-.5,o=this.currentMarker?.id;this.stopAnimationLoop(),this.stepping=!1,this.pausedByVisibility=!1,this.restoreAuthored(),this.scenarioId=e,this.useDefinition(n.timeline),this.lastMarkerId=null;let r=0;return this.reducedMotion||i?r=this.duration:o!==void 0&&(r=this.markers.find(a=>a.id===o)?.time??0),this.seek(r),s&&!this.reducedMotion?(this.stepping=this.options.stepMode===!0,this.startPlaying()):this.notify(),!0}rememberAuthored(e){if(this.authored.has(e))return;const n={style:e.getAttribute("style")};e.children.length===0&&(n.text=e.textContent??"");const s=e.tagName.toLowerCase()==="path"?e:e.querySelector("path");s&&(n.path={element:s,d:s.getAttribute("d")}),this.authored.set(e,n)}restoreAuthored(){for(const[e,n]of this.authored){n.style===null?e.removeAttribute("style"):e.setAttribute("style",n.style),n.text!==void 0&&e.textContent!==n.text&&(e.textContent=n.text),n.path&&(n.path.d===null?n.path.element.removeAttribute("d"):n.path.element.setAttribute("d",n.path.d));const s=e.dataset;s&&delete s.shineBase}}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){for(const e of this.listeners)e()}get reducedMotion(){return this.reducedQuery?.matches===!0}get markers(){return this.markerList}get currentMarker(){const e=this.currentTime;let n;for(const s of this.markers)if(s.time<=e+.5)n=s;else break;return n}caption(e,n){const s=e?this.markers.find(r=>r.id===e):this.currentMarker;if(!s)return;const i=n??this.language(),o=r=>r?.[i]?.[s.id]??r?.[i.split("-")[0]]?.[s.id];return o(this.options.captions)??o(this.timeline?.captions)??s.label}next(){if(!this.timeline)return;const e=this.currentTime,n=this.markers.find(s=>s.time>e+.5);if(this.reducedMotion){this.seek(n?n.time:this.duration);return}e>=this.duration-.5||(this.stepping=n!==void 0,this.startPlaying())}prev(){if(!this.timeline)return;const e=this.currentTime,n=[...this.markers].reverse().find(s=>s.time<e-.5);this.pause(),this.seek(n?n.time:0)}goToMarker(e){const n=this.markers.find(s=>s.id===e);n&&(this.pause(),this.seek(n.time))}language(){return this.container.closest("[lang]")?.getAttribute("lang")||(typeof document<"u"?document.documentElement.lang:"")||"en"}showInitialFrame(){if(!this.timeline)return;const e=this.options.initialFrame??"start";if(e==="none")return;const n=e==="end"?this.timeline.duration:e==="start"?0:e;this.timeline.seek(Math.max(0,Math.min(this.timeline.duration,n))),this.applyState()}watchReducedMotion(){this.options.respectReducedMotion===!1||typeof window>"u"||typeof window.matchMedia!="function"||(this.reducedQuery??=window.matchMedia("(prefers-reduced-motion: reduce)"),this.reducedQuery.addEventListener?.("change",this.onReducedChange),this.reducedQuery.matches&&this.applyReducedMotion())}applyReducedMotion(){!this.reducedMotion||!this.timeline||(this.autoplayWhenSeen=!1,this.pause(),this.seek(this.timeline.duration))}watchVisibility(){if(!(!this.options.playWhenVisible||typeof window>"u")){if(typeof IntersectionObserver=="function"){this.visibilityObserver?.disconnect(),this.visibilityObserver=new IntersectionObserver(n=>{for(const s of n)this.onScreen=s.isIntersecting;this.updateVisibility()}),this.visibilityObserver.observe(this.container);const e=this.container.getBoundingClientRect?.();e&&(e.width>0||e.height>0)&&(this.onScreen=e.bottom>0&&e.top<window.innerHeight&&e.right>0&&e.left<window.innerWidth)}document.addEventListener("visibilitychange",this.onDocumentVisibility)}}updateVisibility(){const e=this.onScreen&&document.visibilityState!=="hidden";!e&&this.isPlaying?(this.pausedByVisibility=!0,this.pause()):e&&(this.pausedByVisibility||this.autoplayWhenSeen)&&!this.reducedMotion&&(this.pausedByVisibility=!1,this.autoplayWhenSeen=!1,this.startPlaying())}announceMarker(){if(!this.options.onMarker)return;const e=this.currentMarker,n=e?.id;n!==this.lastMarkerId&&(this.lastMarkerId=n,this.options.onMarker(e))}scanMedia(){this.mediaTargets=[],this.container.querySelectorAll("[data-tinyfly-media]").forEach(n=>{const s=n,i=Number(s.getAttribute("data-tinyfly-start")??"0")||0,o=s.getAttribute("data-volume");o!==null&&(s.volume=Math.max(0,Math.min(1,Number(o)||0))),this.mediaTargets.push({el:s,startTime:i,sync:new pa(s)})})}syncAllMedia(e,n){for(const s of this.mediaTargets)U0(s.sync,s.el,e,n,s.startTime)}loadFromString(e){const n=JSON.parse(e);this.load(n)}registerTarget(e,n){if(typeof n=="string"){const s=this.container.querySelector(n);s&&(this.rememberAuthored(s),this.targets[e]=s,this.adapter.registerTarget(e,s))}else this.rememberAuthored(n),this.targets[e]=n,this.adapter.registerTarget(e,n)}autoRegisterTargets(){this.container.querySelectorAll("[data-tinyfly]").forEach(n=>{const s=n.closest("[data-tinyfly-symbol]");if(s&&s!==n)return;const i=n.getAttribute("data-tinyfly");i&&this.registerTarget(i,n)}),this.timeline&&new Set(this.timeline.tracks.map(s=>s.target)).forEach(s=>{if(!this.targets[s]){const i=this.container.querySelector(`[data-tinyfly="${s}"]`)||this.container.querySelector(`.${s}`)||this.container.querySelector(`#${s}`);i&&this.registerTarget(s,i)}})}setupSymbolInstances(){this.symbolInstances=[];const e=this.options.symbols;if(!e||e.length===0)return;const n=new Map(e.map(s=>[s.id,s]));this.container.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const i=s.getAttribute("data-tinyfly-symbol");if(!i)return;const o=n.get(i);if(!o||!o.timeline.tracks?.length)return;const r=new sn;s.querySelectorAll("[data-tinyfly]").forEach(a=>{const l=a.getAttribute("data-tinyfly");l&&r.registerTarget(l,a)}),this.symbolInstances.push({adapter:r,timeline:$n(o.timeline)})})}attachMedia(e,n){this.mediaSync=new pa(e,n),this.timeline&&(this.mediaSync.setRate(this.timeline.speed),this.mediaSync.update(this.timeline.currentTime,this.isPlaying))}detachMedia(){this.mediaSync?.dispose(),this.mediaSync=void 0}play(){!this.timeline||this.isDestroyed||(this.autoplayWhenSeen=!1,this.stepping=this.options.stepMode===!0,this.startPlaying())}startPlaying(){if(!this.timeline||this.isDestroyed)return;const e=this.timeline.playbackState==="idle";this.timeline.play(),e&&this.timeline.currentTime===0&&this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.update(this.timeline.currentTime,!0),this.syncAllMedia(this.timeline.currentTime,!0),this.startAnimationLoop(),this.notify()}pause(){this.timeline&&(this.stepping=!1,this.timeline.pause(),this.notify(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1),this.stopAnimationLoop())}stop(){this.timeline&&(this.timeline.stop(),this.stopAnimationLoop(),this.applyState(),this.mediaSync?.update(this.timeline.currentTime,!1),this.syncAllMedia(this.timeline.currentTime,!1))}seek(e){this.timeline&&(this.timeline.seek(e),this.applyState(),this.playhead={time:this.timeline.currentTime,iteration:this.timeline.loopIteration,direction:this.timeline.direction},this.mediaSync?.seek(this.timeline.currentTime),this.syncAllMedia(this.timeline.currentTime,this.isPlaying))}setSpeed(e){this.timeline&&(this.timeline.speed=e,this.mediaSync?.setRate(e))}reverse(){this.timeline&&this.timeline.reverse()}get currentTime(){return this.timeline?.currentTime??0}get duration(){return this.timeline?.duration??0}get isPlaying(){return this.timeline?.playbackState==="playing"}destroy(){this.isDestroyed=!0,this.stopAnimationLoop(),this.reducedQuery?.removeEventListener?.("change",this.onReducedChange),this.visibilityObserver?.disconnect(),typeof document<"u"&&document.removeEventListener("visibilitychange",this.onDocumentVisibility),this.mediaSync?.dispose(),this.mediaSync=void 0;for(const e of this.mediaTargets)e.el.paused||e.el.pause();this.mediaTargets=[],this.adapter.clearTargets();for(const e of this.symbolInstances)e.adapter.clearTargets();this.symbolInstances=[],this.authored.clear(),this.timeline=null}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const e=n=>{if(this.isDestroyed||!this.timeline)return;const s=n-(this.lastTime??n);this.lastTime=n;const i=this.playhead;this.timeline.tick(s),this.stopAtMarker(i),this.applyState();const o=this.timeline.playbackState==="playing";this.mediaSync?.update(this.timeline.currentTime,o),this.syncAllMedia(this.timeline.currentTime,o),this.timeline.playbackState==="playing"?this.animationFrameId=requestAnimationFrame(e):(this.animationFrameId=void 0,this.notify())};this.animationFrameId=requestAnimationFrame(e)}stopAtMarker(e){const n=this.timeline,s={time:n.currentTime,iteration:n.loopIteration,direction:n.direction};this.playhead=s;const i=this.markers;if(i.length===0)return;const{crossings:o}=Rr(i.map(r=>r.time),e,s,{duration:n.duration,alternate:n.config.alternate===!0,holding:n.repeatDelayRemaining>0});for(const r of o){if(r.kind!=="event")continue;const a=i[r.index];if(this.stepping||a.pause){this.stepping=!1,n.pause(),n.seek(a.time),this.playhead={time:a.time,iteration:n.loopIteration,direction:n.direction};return}}}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}applyState(){if(!this.timeline)return;const e=this.timeline.currentTime;this.adapter.applyState(this.timeline.getStateAtTime(e)),this.announceMarker(),this.notify();for(const n of this.symbolInstances){const s=n.timeline.duration;n.adapter.applyState(n.timeline.getStateAtTime(s>0?e%s:e))}}}async function vw(t,e,n={}){const s=new Bi(t,{...n,autoplay:!0});return await s.load(e),s}function Mw(t,e={}){return new Bi(t,e)}const V0={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"},J0="tinyfly-controls-style",Sw=`
|
|
3
3
|
.tf-ctl { --tf-ctl-fg: #1d1d1f; --tf-ctl-bg: #f4f2ee; --tf-ctl-accent: #c2410c; --tf-ctl-radius: 8px;
|
|
4
4
|
font: 14px/1.4 var(--tf-ctl-font, system-ui, sans-serif); color: var(--tf-ctl-fg); margin-top: 8px; }
|
|
5
5
|
.tf-ctl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px; border-radius: var(--tf-ctl-radius); background: var(--tf-ctl-bg); }
|
|
@@ -47,20 +47,20 @@
|
|
|
47
47
|
.tf-fullscreen > svg, .tf-fullscreen > canvas { grid-column: 1; grid-row: 1 / span 12; height: calc(100vh - 24px) !important; height: calc(100dvh - 24px) !important; }
|
|
48
48
|
.tf-fullscreen > :not(svg):not(canvas) { grid-column: 2; }
|
|
49
49
|
}
|
|
50
|
-
`;let
|
|
50
|
+
`;let xw=0;function Tw(t){if(t.getElementById(J0))return;const e=t.createElement("style");e.id=J0,e.textContent=Sw,t.head.appendChild(e)}function Z0(t,e,n={}){const s=e.ownerDocument;Tw(s);const i={...V0,...n.labels},o=n.speeds??[.5,1,2],r=()=>t.markers.length>0,a=()=>t.markers.some(N=>N.label!==void 0||t.caption(N.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=(N,Y,V,tt="")=>{const X=s.createElement("button");return X.type="button",X.className=`tf-ctl-btn ${tt}`.trim(),X.setAttribute("aria-label",N),X.title=N,X.textContent=Y,X.addEventListener("click",V),X},u=h(i.restart,"⟲",()=>{t.pause(),t.seek(0)}),d=h(i.prev,"|◀",()=>t.prev()),f=h(i.play,"▶",()=>t.isPlaying?t.pause():g(),"tf-ctl-primary"),p=h(i.next,"▶|",()=>t.next()),g=()=>{t.currentTime>=t.duration-.5&&t.seek(0),t.play()},m=s.createElement("input");m.type="range",m.className="tf-ctl-scrub",m.min="0",m.max="1000",m.step="1",m.setAttribute("aria-label",i.scrub),m.addEventListener("input",()=>{t.pause(),t.seek(Number(m.value)/1e3*t.duration)});const w=s.createElement("span");w.className="tf-ctl-step";const v=s.createElement("select");v.className="tf-ctl-speed",v.setAttribute("aria-label",i.speed);for(const N of o){const Y=s.createElement("option");Y.value=String(N),Y.textContent=`${N}×`,N===1&&(Y.selected=!0),v.appendChild(Y)}v.addEventListener("change",()=>t.setSpeed(Number(v.value))),c.append(u,d,f,p,m,w),o.length>0&&c.append(v),l.append(c);const k=n.fullscreen?$w(e,s,i):void 0;k&&c.append(k.button);const y=s.createElement("p");y.className="tf-ctl-caption",y.setAttribute("aria-live","polite"),n.captions!==!1&&l.append(y);const T=s.createElement("div");T.className="tf-ctl-question",T.hidden=!0;const $=s.createElement("span"),M=h(i.reveal,i.reveal,()=>t.play(),"tf-ctl-primary");T.append($,M),l.append(T);const x=Ew(t,s,i.scenario,n.scenarioControl??"buttons");x&&l.append(x.element);const S=n.mount;S?S.appendChild(l):e.insertAdjacentElement("afterend",l);const E=()=>{const N=t.isPlaying;f.textContent=N?"❚❚":"▶",f.setAttribute("aria-label",N?i.pause:i.play),f.title=N?i.pause:i.play;const Y=t.duration;s.activeElement!==m&&(m.value=String(Y>0?Math.round(t.currentTime/Y*1e3):0));const V=t.markers;if(d.hidden=p.hidden=w.hidden=V.length===0,V.length>0){const tt=t.currentMarker,X=tt?V.indexOf(tt)+1:0;w.textContent=i.stepFormat.replace("{index}",String(X)).replace("{total}",String(V.length)),w.setAttribute("aria-label",`${i.step} ${X} ${i.of} ${V.length}`),d.disabled=t.currentTime<=.5,p.disabled=t.currentTime>=Y-.5;const R=t.caption()??"";y.textContent!==R&&(y.textContent=R),y.hidden=!a();const z=!N&&tt?.question!==void 0&&Math.abs(t.currentTime-tt.time)<1;T.hidden=!z,z&&$.textContent!==tt.question&&($.textContent=tt.question)}else T.hidden=!0,y.hidden=!0;x?.update()},P=t.subscribe(E);E();const A=n.keyboardScope??e;!A.hasAttribute("tabindex")&&A.tabIndex<0&&(A.tabIndex=0);const I=new WeakSet,_=N=>{if(I.has(N)||(I.add(N),N.defaultPrevented||N.altKey||N.ctrlKey||N.metaKey))return;const Y=N.target;if(!(Y.tagName==="INPUT"||Y.tagName==="SELECT")&&!(N.key===" "&&Y.tagName==="BUTTON"))switch(N.key){case" ":N.preventDefault(),t.isPlaying?t.pause():g();break;case"ArrowRight":if(!r())return;N.preventDefault(),t.next();break;case"ArrowLeft":if(!r())return;N.preventDefault(),t.prev();break;case"Home":N.preventDefault(),t.pause(),t.seek(0);break;case"f":case"F":if(!k)return;N.preventDefault(),k.active?k.exit():k.enter();break}};return A.addEventListener("keydown",_),l.addEventListener("keydown",_),{element:l,fullscreen:k&&{get active(){return k.active},enter:k.enter,exit:k.exit},destroy(){k?.destroy(),P(),A.removeEventListener("keydown",_),l.removeEventListener("keydown",_),l.remove()}}}function Ew(t,e,n,s){const i=t.scenarios;if(i.length<2)return;if(s==="slider"){const h=e.createElement("div");h.className="tf-ctl-choice-slider";const u=e.createElement("span");u.textContent=n,u.setAttribute("aria-hidden","true");const d=e.createElement("input");d.type="range",d.min="0",d.max=String(i.length-1),d.step="1",d.setAttribute("aria-label",n);const f=e.createElement("output");return f.setAttribute("aria-hidden","true"),d.addEventListener("input",()=>{const g=i[Number(d.value)];g&&t.setScenario(g.id)}),h.append(u,d,f),{element:h,update:()=>{const g=Math.max(0,i.findIndex(w=>w.id===t.scenario));e.activeElement!==d&&(d.value=String(g));const m=i[g].label;f.textContent!==m&&(f.textContent=m),d.setAttribute("aria-valuetext",m)}}}const o=e.createElement("fieldset");o.className="tf-ctl-choices";const r=e.createElement("legend");r.textContent=n,o.append(r);const a=`tf-ctl-scenario-${++xw}`,l=i.map(h=>{const u=e.createElement("label");u.className="tf-ctl-choice";const d=e.createElement("input");d.type="radio",d.name=a,d.value=h.id,d.addEventListener("change",()=>{d.checked&&t.setScenario(h.id)});const f=e.createElement("span");return f.textContent=h.label,u.append(d,f),o.append(u),d});return{element:o,update:()=>{for(const h of l){const u=h.value===t.scenario;h.checked!==u&&(h.checked=u)}}}}const Aw='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',Pw='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';function $w(t,e,n){const s=e,i=t,o=e.createElement("button");o.type="button",o.className="tf-ctl-btn tf-ctl-fullscreen";let r,a="";const l=()=>{const g=r!==void 0;o.innerHTML=g?Pw:Aw;const m=g?n.exitFullscreen:n.fullscreen;o.setAttribute("aria-label",m),o.title=m,o.setAttribute("aria-pressed",String(g)),t.classList.toggle("tf-fullscreen",g),t.classList.toggle("tf-fullscreen-overlay",r==="overlay")},c=()=>s.fullscreenElement??s.webkitFullscreenElement??null,h=()=>{c()===t?r="native":r==="native"&&(r=void 0),l()},u=g=>{g.key==="Escape"&&p()},d=()=>{r="overlay",a=e.documentElement.style.overflow,e.documentElement.style.overflow="hidden",e.addEventListener("keydown",u),l()};async function f(){if(r)return;const g=i.requestFullscreen?.bind(i)??i.webkitRequestFullscreen?.bind(i),m=s.fullscreenEnabled??s.webkitFullscreenEnabled??!1;if(g&&m)try{if(await g(),c()===t){r="native",l();return}}catch{}d()}async function p(){if(r==="overlay")e.removeEventListener("keydown",u),e.documentElement.style.overflow=a,r=void 0,l();else if(r==="native"){r=void 0,l();const g=s.exitFullscreen?.bind(s)??s.webkitExitFullscreen?.bind(s);c()===t&&g&&await g()}}return o.addEventListener("click",()=>{r?p():f()}),e.addEventListener("fullscreenchange",h),e.addEventListener("webkitfullscreenchange",h),l(),{button:o,get active(){return r!==void 0},enter:f,exit:p,destroy(){p(),e.removeEventListener("fullscreenchange",h),e.removeEventListener("webkitfullscreenchange",h),o.remove()}}}const Q0="tinyfly-choices-style",Iw=`
|
|
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 Zb(t){if(t.getElementById(N0))return;const e=t.createElement("style");e.id=N0,e.textContent=Jb,t.head.appendChild(e)}function F0(t,e){const n=Array.from(e.querySelectorAll("[data-tinyfly-choose]"));if(n.length===0)return()=>{};Zb(e.ownerDocument);const s=[],i=[];for(const a of n){const l=a.getAttribute("data-tinyfly-choose")??"",c=[],h=(p,g)=>{a.hasAttribute(p)||(a.setAttribute(p,g),c.push(p))};h("role","button"),h("tabindex","0");const u=t.scenarios.find(p=>p.id===l)?.label;u!==void 0&&h("aria-label",u),a.setAttribute("aria-pressed","false"),c.push("aria-pressed"),s.push({element:a,attributes:c});const d=()=>t.setScenario(l),f=p=>{const g=p.key;g!=="Enter"&&g!==" "||(p.preventDefault(),d())};a.addEventListener("click",d),a.addEventListener("keydown",f),i.push(()=>{a.removeEventListener("click",d),a.removeEventListener("keydown",f)})}const o=()=>{for(const{element:a}of s)a.setAttribute("aria-pressed",String(a.getAttribute("data-tinyfly-choose")===t.scenario))},r=t.subscribe(o);return o(),()=>{r();for(const a of i)a();for(const{element:a,attributes:l}of s)for(const c of l)a.removeAttribute(c)}}const Ci=new WeakMap,ra=new WeakMap;let Qb=0;function As(t,e,n){if(t)try{return JSON.parse(t)}catch(s){console.warn(`tinyfly: invalid ${e} JSON on`,n,s);return}}async function D0(t,e={}){const n=Ci.get(t);if(n)return n;const s=Array.from(t.querySelectorAll("script[data-tinyfly-timeline]")),i=s[0],o=t.getAttribute("data-src"),r=ew(t.getAttribute("data-markers")),a=s.length>1||i?.hasAttribute("data-scenario")?tw(s,r,t):void 0;if(a&&a.length===0)return;let l=i&&!a?As(i.textContent,"timeline",t):void 0;if(!l&&o&&r){const f=await fetch(o);f.ok&&(l=await f.json())}if(l&&r&&(l=W0(l,r)),!l&&!o&&!a){console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)',t);return}const c=As(t.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",t),h={playWhenVisible:!0,...e.player,...c&&{captions:c},...As(t.getAttribute("data-options"),"data-options",t)};sw(t);const u=new _i(t,h),d={element:t,player:u};if(Ci.set(t,d),t.setAttribute("data-tinyfly-mounted",""),a){const f=t.getAttribute("data-scenario")??void 0;await u.loadScenarios(a,{initial:a.some(p=>p.id===f)?f:void 0}),ra.set(t,F0(u,t))}else await u.load(l??o);if(t.getAttribute("data-controls")!=="false"){const f=As(t.getAttribute("data-labels"),"data-labels",t),p=t.querySelector("figcaption"),g=t.getAttribute("data-scenario-legend"),m=t.getAttribute("data-scenario-control");d.controls=L0(u,t,{...e.controls,...t.getAttribute("data-fullscreen")==="true"?{fullscreen:!0}:{},...m==="slider"||m==="buttons"?{scenarioControl:m}:{},labels:{...e.controls?.labels,...f,...g?{scenario:g}:{}},mount:void 0}),p?t.insertBefore(d.controls.element,p):t.appendChild(d.controls.element)}return d}function tw(t,e,n){const s=[];return t.forEach((i,o)=>{const r=As(i.textContent,"timeline",n);if(!r)return;const a=i.getAttribute("data-scenario")||`scenario-${o+1}`;if(s.some(c=>c.id===a)){console.warn(`tinyfly: scenario id "${a}" is used more than once; the later one is skipped`,n);return}const l=i.getAttribute("data-scenario-label")??void 0;s.push({id:a,label:l,timeline:e?W0(r,e):r})}),s}function W0(t,e){return t.config.markers?.length?t:{...t,config:{...t.config,markers:e.map((n,s)=>({id:`step-${s+1}`,time:n}))}}}function ew(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 B0(t=document,e={}){const n=Array.from(t.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(n.map(i=>D0(i,e)))).filter(i=>i!==void 0)}function nw(t){const e=Ci.get(t);e&&(ra.get(t)?.(),ra.delete(t),e.controls?.destroy(),e.player.destroy(),Ci.delete(t),t.removeAttribute("data-tinyfly-mounted"))}function sw(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-${++Qb}`,e.setAttribute("aria-labelledby",s.id))}function iw(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const e=()=>{B0()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}class z0{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 nn,this.adapterB=new nn}async load(e){let n;if(typeof e=="string"){const s=await fetch(e);if(!s.ok)throw new Error(`Failed to load sequence: ${s.statusText}`);n=await s.json()}else n=e;this.sequence=n,this.symbolDefs.clear();for(const s of n.symbols??[])s.timeline?.tracks?.length&&this.symbolDefs.set(s.id,s.timeline);this.container.style.width=`${n.canvas.width}px`,this.container.style.height=`${n.canvas.height}px`,n.scenes.length>0&&(this.renderScene(n.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(n.scenes[0])),this.options.autoplay&&this.play()}play(){if(!(!this.sequence||this._isDestroyed)&&this.sequence.scenes.length!==0){if(this._isPlaying=!0,this._state==="idle"){if(this._state="playing-scene",this._currentSceneIndex=0,this.timelineA)this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play();else{this.onSceneComplete();return}this.options.onSceneChange?.(0)}else this._state==="playing-scene"&&this.timelineA&&this.timelineA.play();this.startAnimationLoop()}}pause(){this._isPlaying&&(this._isPlaying=!1,this.timelineA&&this.timelineA.pause(),this.timelineB&&this.timelineB.pause(),this.stopAnimationLoop())}stop(){if(this._isPlaying=!1,this._state="idle",this._currentSceneIndex=0,this.loopIteration=0,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.stopAnimationLoop(),this.sequence&&this.sequence.scenes.length>0&&(this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this.renderScene(this.sequence.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(this.sequence.scenes[0]),this.timelineA)){const e=this.timelineA.getStateAtTime(0);this.adapterA.applyState(e),this.applyNested(this.adapterA,0)}}goToScene(e){if(!this.sequence||e<0||e>=this.sequence.scenes.length)return;const n=this._isPlaying;this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this._currentSceneIndex=e,this._state=n?"playing-scene":"idle",this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB);const s=this.sequence.scenes[e];if(this.renderScene(s,this.containerA,this.adapterA),this.timelineA=this.createTimeline(s),this.options.onSceneChange?.(e),n)this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play(),this.startAnimationLoop()):this.onSceneComplete();else if(this.timelineA){const i=this.timelineA.getStateAtTime(0);this.adapterA.applyState(i),this.applyNested(this.adapterA,0)}}destroy(){this._isDestroyed=!0,this._isPlaying=!1,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.adapterA.clearTargets(),this.adapterB.clearTargets();for(const e of this.nestedByAdapter.values())for(const n of e)n.adapter.clearTargets();this.nestedByAdapter.clear(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.timelineA=null,this.timelineB=null,this.containerA.parentNode&&this.containerA.remove(),this.containerB.parentNode&&this.containerB.remove(),this.sequence=null}get currentSceneIndex(){return this._currentSceneIndex}get sceneCount(){return this.sequence?.scenes.length??0}get isPlaying(){return this._isPlaying}get state(){return this._state}createSceneContainer(){const e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.width="100%",e.style.height="100%",e}renderScene(e,n,s){n.innerHTML="",s.clearTargets();const i=document.createElement("div");i.style.cssText="position:absolute;inset:0;transform-origin:center center",i.setAttribute("data-tinyfly","Camera"),n.appendChild(i),s.registerTarget("Camera",i);for(const o of e.elements){if(!o.html)continue;const r=document.createElement("div");r.innerHTML=o.html.trim();const a=r.firstElementChild;if(a){i.appendChild(a);const l=a.getAttribute("data-tinyfly");l&&s.registerTarget(l,a)}}this.setupNested(i,s)}setupNested(e,n){const s=[];e.querySelectorAll("[data-tinyfly-symbol]").forEach(i=>{const o=i.getAttribute("data-tinyfly-symbol");if(!o)return;const r=this.symbolDefs.get(o);if(!r)return;const a=new nn;i.querySelectorAll("[data-tinyfly]").forEach(l=>{const c=l.getAttribute("data-tinyfly");c&&a.registerTarget(c,l)}),s.push({adapter:a,timeline:An(r)})}),s.length?this.nestedByAdapter.set(n,s):this.nestedByAdapter.delete(n)}applyNested(e,n){const s=this.nestedByAdapter.get(e);if(s)for(const i of s){const o=i.timeline.duration;i.adapter.applyState(i.timeline.getStateAtTime(o>0?n%o:n))}}clearContainer(e){e.innerHTML=""}createTimeline(e){return e.timeline?An(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 ow(t,e,n={}){const s=new z0(t,{...n,autoplay:!0});return await s.load(e),s}const rw={type:"none",duration:0},_t=t=>({description:t,unit:"degrees"}),Tt=(t,e=0,n=1)=>({description:t,unit:`${e}..${n}`,min:e,max:n}),q0={lean:_t("Upper body tipped about the hips (+ toward the way it faces)"),bend:_t("Line of action: the spine curved (+ curls forward, − arches back)"),headTilt:_t("Head tilt"),leftShoulder:_t("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:_t("Right upper arm: 0 hangs down, 90 straight out (forward, in profile), 180 straight up"),leftElbow:_t("Left elbow bend, added to the upper arm"),rightElbow:_t("Right elbow bend, added to the upper arm"),leftHip:_t("Left thigh: 0 straight down; in profile negative is forward"),rightHip:_t("Right thigh: 0 straight down; in profile positive is forward"),leftKnee:_t("Left knee bend (negative folds the shin back)"),rightKnee:_t("Right knee bend (positive folds the shin back)"),leftWrist:_t("Left wrist bend, added to the forearm"),rightWrist:_t("Right wrist bend, added to the forearm"),leftAnkle:_t("Left ankle: + points the toe down (tiptoe), − onto the heel"),rightAnkle:_t("Right ankle: + points the toe down (tiptoe), − onto the heel"),leftFootOut:Tt("Left foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),rightFootOut:Tt("Right foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),mouth:Tt("Mouth open: 0 closed, 1 wide open"),smile:Tt("−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:Tt("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:Tt("Left eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),rightBrow:Tt("Right eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),browTilt:Tt("Eyebrow slant: −1 angry, 1 worried",-1,1),lookX:Tt("Eyes look across: + the way it faces",-1,1),lookY:Tt("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:Tt("0 front-on, 1 in profile, turned the way it faces"),sit:Tt("0 standing, 1 seated"),spin:_t("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"}},Y0={walk:{description:"Walk-cycle phase, in strides: animate 0 → n for n strides",unit:"strides"},walking:Tt("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:Tt("How much the mouth chatters"),rubber:Tt("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:Tt("How much of the dance is applied")},j0={"thumb.curl":Tt("Thumb curled in"),"thumb.across":Tt("Thumb across the palm"),"index.curl":Tt("Index finger curled"),"middle.curl":Tt("Middle finger curled"),"ring.curl":Tt("Ring finger curled"),"pinky.curl":Tt("Little finger curled"),spread:Tt("Fingers spread apart"),turn:_t("Hand turned about the forearm"),bend:_t("Hand bent at the wrist, palm-ward"),tilt:_t("Hand tilted sideways"),roll:_t("Hand rolled to show the back or the palm")};let K0;function aw(t){K0=t}function lw(t){return K0?.(t)??{}}function X0(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 Rn(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=X0(t)*n;const i=[t[0]];for(let o=1;o<t.length;o++){const r=t[o-1],a=t[o],l=Math.hypot(a.x-r.x,a.y-r.y);if(l>=s){const c=l===0?0:s/l;return i.push({x:r.x+(a.x-r.x)*c,y:r.y+(a.y-r.y)*c}),i}i.push(a),s-=l}return i}function Hi(t,e){const n=Rn(t,e);return n[n.length-1]}function aa(t,e){return e>0?Math.floor(Math.max(0,t)*e/1e3):0}function Ri(t,e,n){const s=e.roughness??2,i=Math.max(1,Math.round(e.passes??2)),o=aa(n,e.boil??8);let r=0;const a=()=>{const d=r++;return f=>_e(Kt(`${e.seed??1}:${o}:${d}:${f}`))},l=(d,f)=>(d.next()*2-1)*f,c=d=>{const f=a(),p=t.lineWidth,g=t.globalAlpha;for(let m=0;m<i;m++)t.lineWidth=m===0?p:p*.55,t.globalAlpha=m===0?g:g*.6,d(f(m));t.lineWidth=p,t.globalAlpha=g},h=(d,f=1)=>{if(d.length<2)return;const p=d.slice(1).map((m,w)=>Math.hypot(m.x-d[w].x,m.y-d[w].y)),g=p.reduce((m,w)=>m+w,0)*Math.min(1,Math.max(0,f));c(m=>{const w=[],v=[];if(d.forEach((b,E)=>{w.push({x:b.x+l(m,s*.5),y:b.y+l(m,s*.5)}),E>0&&v.push([m.next()*2-1,m.next()*2-1])}),g<=0)return;t.beginPath(),t.moveTo(w[0].x,w[0].y);let k=0;for(let b=1;b<w.length;b++){const E=cw(w[b-1],w[b],s,v[b-1]),$=p[b-1];if(k+$<=g){t.bezierCurveTo(E[1].x,E[1].y,E[2].x,E[2].y,E[3].x,E[3].y),k+=$;continue}const S=hw(E,$===0?1:(g-k)/$);t.bezierCurveTo(S[1].x,S[1].y,S[2].x,S[2].y,S[3].x,S[3].y);break}t.stroke()})},u=(d,f,p,g,m=1)=>{c(w=>{const k=w.next()*Math.PI*2,b=Math.PI*2+.15+w.next()*.3,E=[];for(let S=0;S<=14;S++){const x=k+b*S/14,M=l(w,s*.6);E.push({x:d+Math.cos(x)*(p+M),y:f+Math.sin(x)*(g+M)})}const $=Rn(E,m);$.length<2||(G0(t,$),t.stroke())})};return{line:h,curve(d,f=1){if(d.length<2)return;const p=d[0],g=d[d.length-1],m=Math.hypot(g.x-p.x,g.y-p.y)||1,w=-(g.y-p.y)/m,v=(g.x-p.x)/m;c(k=>{const b={x:l(k,s*.5),y:l(k,s*.5)},E={x:l(k,s*.5),y:l(k,s*.5)},$=l(k,s*Math.min(1.5,Math.max(.3,m/80))),S=d.map((M,T)=>{const I=T/(d.length-1),A=Math.sin(Math.PI*I)*$;return{x:M.x+b.x+(E.x-b.x)*I+w*A,y:M.y+b.y+(E.y-b.y)*I+v*A}}),x=Rn(S,f);x.length<2||(G0(t,x),t.stroke())})},circle(d,f,p,g=1){u(d,f,p,p,g)},ellipse:u,nudge(d=.5){const f=a()(0);return{x:l(f,s*d),y:l(f,s*d)}}}}function cw(t,e,n,s){const i=e.x-t.x,o=e.y-t.y,r=Math.hypot(i,o)||1,a=n*Math.min(1.5,Math.max(.3,r/80)),l=-o/r,c=i/r;return[t,{x:t.x+i/3+l*s[0]*a,y:t.y+o/3+c*s[0]*a},{x:t.x+2*i/3+l*s[1]*a,y:t.y+2*o/3+c*s[1]*a},e]}function hw([t,e,n,s],i){const o=(u,d)=>({x:u.x+(d.x-u.x)*i,y:u.y+(d.y-u.y)*i}),r=o(t,e),a=o(e,n),l=o(n,s),c=o(r,a),h=o(a,l);return[t,r,c,o(c,h)]}function G0(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 Ft(t,e,n){const s=t.length;if(s<2)return[];const i=[],o=[],r=a=>e+(n-e)*a/(s-1);return t.forEach((a,l)=>{const c=t[Math.max(0,l-1)],h=t[Math.min(s-1,l+1)],u=Math.hypot(h.x-c.x,h.y-c.y)||1,d=r(l)/2,f=-(h.y-c.y)/u*d,p=(h.x-c.x)/u*d;i.push({x:a.x+f,y:a.y+p}),o.push({x:a.x-f,y:a.y-p})}),[...i,...o.reverse()]}function Li(t,e,n,s){const i=e.length;if(i<2)return;const o=Ft(e,n,s),r=a=>n+(s-n)*a/(i-1);t.beginPath(),t.moveTo(o[0].x,o[0].y);for(const a of o.slice(1))t.lineTo(a.x,a.y);t.closePath(),t.fill(),e.forEach((a,l)=>{l!==0&&l!==i-1&&i>3||(t.beginPath(),t.arc(a.x,a.y,r(l)/2,0,Math.PI*2),t.fill())})}function sn(t,e,n,s,i=16){const o={x:2*e.x-(t.x+n.x)/2,y:2*e.y-(t.y+n.y)/2},r=[];for(let a=0;a<=i;a++){const l=a/i,c=l<.5?{x:t.x+(e.x-t.x)*2*l,y:t.y+(e.y-t.y)*2*l}:{x:e.x+(n.x-e.x)*(2*l-1),y:e.y+(n.y-e.y)*(2*l-1)},h=1-l,u={x:h*h*t.x+2*h*l*o.x+l*l*n.x,y:h*h*t.y+2*h*l*o.y+l*l*n.y};r.push({x:c.x+(u.x-c.x)*s,y:c.y+(u.y-c.y)*s})}return r}function la(t,e,n,s,i,o=0,r=1,a=40){const l=Math.cos(i),c=Math.sin(i);return Array.from({length:a+1},(h,u)=>{const d=o+Math.PI*2*r*u/a,f=Math.cos(d)*n,p=Math.sin(d)*s;return{x:t+f*l-p*c,y:e+f*c+p*l}})}function Ps(t,e){return e.look==="pencil"?gw(t,e):uw(t,e.ink,e.look)}function Ni(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 uw(t,e,n){const s=n==="silhouette",i=s?1.25:1;return{look:n,ink:e,limb(o,r,a){t.fillStyle=e,Li(t,o,r*i,a*i)},line(o,r){o.length<2||(t.strokeStyle=e,t.lineWidth=r*i,t.lineCap="round",t.lineJoin="round",Ni(t,o),t.stroke())},shape(o,r,a){Ni(t,o,!0),(r!==null||s)&&(t.fillStyle=s?e:r,t.fill()),!(a<=0)&&(t.strokeStyle=e,t.lineWidth=a*i,t.lineJoin="round",t.stroke())},ellipse(o,r,a,l,c,h,u){t.beginPath(),t.ellipse(o,r,a,l,c,0,Math.PI*2),(h!==null||s)&&(t.fillStyle=s?e:h,t.fill()),!(u<=0)&&(t.strokeStyle=e,t.lineWidth=u*i,t.stroke())},dot(o,r,a){t.fillStyle=e,t.beginPath(),t.arc(o,r,a*i,0,Math.PI*2),t.fill()},guide(){},guideEllipse(){}}}function dw(t,e){const n=[t[0]];let s=0;for(let r=1;r<t.length;r++){const a=t[r-1],l=t[r],c=Math.hypot(l.x-a.x,l.y-a.y);let h=e-s;for(;h<c;){const u=h/c;n.push({x:a.x+(l.x-a.x)*u,y:a.y+(l.y-a.y)*u}),h+=e}s=c-(h-e)}const i=t[t.length-1],o=n[n.length-1];return Math.hypot(i.x-o.x,i.y-o.y)>e*.25?n.push(i):n[n.length-1]=i,n}function fw(t,e){const n=t.length;return t.map((s,i)=>{const o=t[Math.max(0,i-1)],r=t[Math.min(n-1,i+1)],a=Math.hypot(r.x-o.x,r.y-o.y)||1,l=e(n===1?0:i/(n-1));return{x:s.x-(r.y-o.y)/a*l,y:s.y+(r.x-o.x)/a*l}})}function U0(t){const e=[.6,1.4,2.9].map(s=>({frequency:s*(.8+t.next()*.4),phase:t.next()*Math.PI*2,amount:.5+t.next()*.5})),n=e.reduce((s,i)=>s+i.amount,0);return s=>e.reduce((i,o)=>i+o.amount*Math.sin(Math.PI*2*o.frequency*s+o.phase),0)/n}function gw(t,e){const n=e.pencil??{},s=e.ink,i=n.roughness??Math.max(1,e.lineWidth*.12),o=Math.max(1,Math.round(n.passes??2)),r=Math.min(1,Math.max(0,n.pressure??.25)),a=Math.min(1,Math.max(0,n.rubbedOut??.15)),l=aa(e.time,n.boil??8);let c=0;const h=(p,g,m=!1)=>_e(Kt(`${e.seed}:${m?"paper":l}:${p}:${g}`)),u=(p,g,m,w,v,k=0)=>{if(p.length<2)return;const b=p.slice(1).reduce((I,A,_)=>I+Math.hypot(A.x-p[_].x,A.y-p[_].y),0);let E=dw(p,Math.max(1.5,Math.min(e.lineWidth*.8,b/24)));if(k>0&&E.length>=2){const[I,A]=[E[E.length-2],E[E.length-1]],_=Math.hypot(A.x-I.x,A.y-I.y)||1;E=[...E,{x:A.x+(A.x-I.x)/_*k,y:A.y+(A.y-I.y)/_*k}]}const $=U0(m),S=U0(m),x=E.length,M=[],T=[];E.forEach((I,A)=>{const _=x===1?0:A/(x-1),C=E[Math.max(0,A-1)],N=E[Math.min(x-1,A+1)],B=Math.hypot(N.x-C.x,N.y-C.y)||1,G=-(N.y-C.y)/B,Z=(N.x-C.x)/B,Y=$(_)*v,L=Math.min(1,_/.08,(1-_)/.08),z=(.55+.45*Math.sqrt(Math.max(0,L)))*(1+r*S(_)),O=Math.max(.3,g(_)*z/2),P=I.x+G*Y,H=I.y+Z*Y;M.push({x:P+G*O,y:H+Z*O}),T.push({x:P-G*O,y:H-Z*O})}),t.save(),t.globalAlpha*=w,t.fillStyle=s,Ni(t,[...M,...T.reverse()],!0),t.fill(),t.restore()},d=(p,g)=>{const m=c++,w=h(m,99,!0);if(w.next()<a){const E=(w.next()*2-1)*e.lineWidth*1.4,$=(w.next()*2-1)*e.lineWidth*1.4,S=p.map(x=>({x:x.x+E,y:x.y+$}));u(S,x=>g(x)*1.8,h(m,98,!0),.035,i),u(S,x=>g(x)*.45,h(m,97,!0),.12,i*1.5)}const v=p.slice(1).reduce((E,$,S)=>E+Math.hypot($.x-p[S].x,$.y-p[S].y),0),k=g(.5)>4&&v>g(.5)*6,b=k?[-.3,.3,0]:[0];for(let E=0;E<o;E++){const $=E===0;b.forEach((S,x)=>{const M=h(m,E*10+x),T=S===0?p:fw(p,A=>g(A)*S*Math.sqrt(Math.sin(Math.PI*A))),I=!$&&S===0?e.lineWidth*(.3+M.next()*.8):0;u(T,A=>g(A)*(k?.5:1)*($?1:.6),M,$?.85:.45,i*($?.6:1),I)})}},f=(p,g,m,w,v,k)=>{const E=h(c,50).next()*Math.PI*2;d(la(p,g,m,w,v,E,1.08,48),()=>k)};return{look:"pencil",ink:s,limb(p,g,m){d(p,w=>g+(m-g)*w)},line(p,g){d(p,()=>g)},shape(p,g,m){g!==null&&(t.save(),t.globalAlpha*=.88,t.fillStyle=g,Ni(t,p,!0),t.fill(),t.restore()),m>0&&d([...p,p[0]],()=>m)},ellipse(p,g,m,w,v,k,b){k!==null&&(t.save(),t.globalAlpha*=.9,t.fillStyle=k,t.beginPath(),t.ellipse(p,g,m,w,v,0,Math.PI*2),t.fill(),t.restore()),f(p,g,m,w,v,b)},dot(p,g,m){t.save(),t.globalAlpha*=.9,t.fillStyle=s,t.beginPath(),t.arc(p,g,m,0,Math.PI*2),t.fill(),t.restore()},guide(p){if(n.construction===!1||p.length<2)return;const g=c++;u(p,()=>Math.max(.6,e.lineWidth*.18),h(g,0),.28,i*1.2,e.lineWidth)},guideEllipse(p,g,m,w,v){if(n.construction===!1)return;const k=c++,b=h(k,0),E=la(p,g,m,w,v,b.next()*Math.PI*2,1.12,48);u(E,()=>Math.max(.6,e.lineWidth*.18),b,.28,i*1.5)}}}const V0=["thumb","index","middle","ring","pinky"],Pt={"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 Ht(t={}){return{...Pt,...t}}const Ut=(t,e,n,s,i)=>({"thumb.curl":t,"index.curl":e,"middle.curl":n,"ring.curl":s,"pinky.curl":i}),Ct={relaxed:Pt,open:Ht({...Ut(0,0,0,0,0),"thumb.across":0,spread:.55}),spread:Ht({...Ut(0,0,0,0,0),"thumb.across":0,spread:1}),flat:Ht({...Ut(0,0,0,0,0),"thumb.across":.35,spread:0}),fist:Ht({...Ut(.7,1,1,1,1),"thumb.across":.9,spread:0}),point:Ht({...Ut(.75,0,1,1,1),"thumb.across":.9,spread:0}),thumbsUp:Ht({...Ut(0,1,1,1,1),"thumb.across":0,spread:0,roll:70}),peace:Ht({...Ut(.75,0,0,1,1),"thumb.across":.9,spread:1}),ok:Ht({...Ut(.12,.6,.1,.15,.2),"thumb.across":.55,spread:.6}),pinch:Ht({...Ut(.1,.65,.75,.85,.9),"thumb.across":.55,spread:0}),cupped:Ht({...Ut(.25,.4,.4,.4,.4),"thumb.across":.4,spread:.05,turn:2}),wave:Ht({...Ut(0,.05,.05,.1,.12),"thumb.across":0,spread:.7,turn:2}),pencilGrip:Ht({...Ut(.1,.6,.72,.88,.95),"thumb.across":.5,spread:0,turn:.8,bend:10}),hold:Ht({...Ut(.5,.7,.72,.74,.76),"thumb.across":.75,spread:0,turn:1})};function Ln(t,e,n){const s={...t};for(const[i,o]of Object.entries(e)){const r=t[i]??o;s[i]=r+(o-r)*n}return s}const pw={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}},mw={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}},we={base:[-.11,.1,-.05],bones:[.2,.15,.12],widths:[.2,.145,.135],out:[-.7,.68,-.22],across:[.35,.5,-.8]},yw=[82,100,62],bw=[48,72],ww=3,kw=13,vw=.035,Mw=-.075,Sw=[[-.17,0],[-.215,.12],[-.235,.26],[-.225,.4],[-.185,.49],[-.075,.525],[.05,.51],[.16,.465],[.215,.4],[.225,.26],[.2,.1],[.16,0]],He=t=>t*Math.PI/180,ca=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Fi=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],ha=(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]],$s=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function Re(t,e,n){const s=Math.cos(n),i=Math.sin(n),o=ha(e,t),r=e[0]*t[0]+e[1]*t[1]+e[2]*t[2];return[t[0]*s+o[0]*i+e[0]*r*(1-s),t[1]*s+o[1]*i+e[1]*r*(1-s),t[2]*s+o[2]*i+e[2]*r*(1-s)]}const J0=[1,0,0],Z0=[0,1,0],Is=[0,0,1];function Tw(t,e,n){const s=He(t.fan*(ww+kw*n)),i=[Math.sin(s),Math.cos(s),0],o=[Math.cos(s),-Math.sin(s),0],r=[t.knuckle];let a=0;t.bones.forEach((h,u)=>{a+=He(yw[u]*e),r.push(ca(r[u],Fi(Re(i,o,-a),h)))});const l=Re(Is,o,-a),c=r.map((h,u)=>t.width*(1-.14*(u/(r.length-1))));return{joints:r,back:l,widths:c}}function xw(t,e,n=1,s=1){const i=Math.min(1,Math.max(0,e)),o=$s(ca(Fi($s(we.out),1-i),Fi($s(we.across),i))),r=$s(ha(Is,o)),a=$s(ha(o,r)),l=[[we.base[0]*s,we.base[1],we.base[2]]];let c=0;we.bones.forEach((d,f)=>{f>0&&(c+=He(bw[f-1]*t)),l.push(ca(l[f],Fi(Re(o,r,c),d)))});const h=Re(a,r,c),u=[...we.widths,we.widths[we.widths.length-1]*.92].map(d=>d*n);return{joints:l,back:h,widths:u}}function Di(t,e={}){const n={...Pt,...t},s=e.size??100,i=e.side??"right",o=i==="left"?-1:1,r=He(e.angle??0),a=e.fingers===4,l=Math.max(.5,e.plump??1),c=1+(l-1)*.7,h=A=>({...A,knuckle:[A.knuckle[0]*c,A.knuckle[1],A.knuckle[2]],width:A.width*l}),u=He(n.bend??0),d=He(n.tilt??0),f=He(90*(n.turn??0)),p=A=>Re(Re(Re(A,J0,-u),Is,-d),Z0,f),g=Math.cos(r),m=Math.sin(r),w=He(n.roll??0),v=Math.cos(w),k=Math.sin(w),b=A=>{const _=A[0]*s,C=-A[1]*s,N=(_*v-C*k)*o,B=_*k+C*v;return{x:N*g-B*m,y:N*m+B*g}},E=A=>{const _=b(A),C=Math.hypot(_.x,_.y);return C>1e-6*s?{x:_.x/C,y:_.y/C}:{x:0,y:0}},$={thumb:xw(n["thumb.curl"]??0,n["thumb.across"]??0,l,c)},S=a?mw:pw;for(const A of V0){const _=S[A];_&&($[A]=Tw(h(_),n[`${A}.curl`]??0,n.spread??0))}const x={};for(const[A,_]of Object.entries($)){const C=_.joints.map(p),N=p(_.back);x[A]={points:C.map(b),depths:C.map(B=>B[2]*s),widths:_.widths.map(B=>B*s),nail:N[2],back:E(N)}}const M=Sw.flatMap(([A,_])=>[p([A*c,_,vw]),p([A*c,_,Mw])]),T=Ew(M.map(b)),I=M.reduce((A,_)=>A+_[2],0)/M.length*s;return{size:s,side:i,wrist:{x:0,y:0},palm:T,palmDepth:I,palmFacing:-p(Is)[2],fingers:x,axes:{up:E(p(Z0)),across:E(p(J0)),out:E(p(Is))},curls:Object.fromEntries(Object.keys(x).map(A=>[A,n[`${A}.curl`]??0]))}}function Q0(t,e){const n=i=>({x:i.x+e.x-t.wrist.x,y:i.y+e.y-t.wrist.y}),s={};for(const[i,o]of Object.entries(t.fingers))s[i]={...o,points:o.points.map(n)};return{...t,wrist:n(t.wrist),palm:t.palm.map(n),fingers:s}}function Ew(t){const e=[...t].sort((o,r)=>o.x-r.x||o.y-r.y);if(e.length<3)return e;const n=(o,r,a)=>(r.x-o.x)*(a.y-o.y)-(r.y-o.y)*(a.x-o.x),s=[];for(const o of e){for(;s.length>=2&&n(s[s.length-2],s[s.length-1],o)<=0;)s.pop();s.push(o)}const i=[];for(const o of[...e].reverse()){for(;i.length>=2&&n(i[i.length-2],i[i.length-1],o)<=0;)i.pop();i.push(o)}return[...s.slice(0,-1),...i.slice(0,-1)]}const Aw="#f1c9a5",Pw="#2f2f33";function Wi(t,e,n,s={},i=0){const o=Q0(Di(n,s),e),r=s.ink??Pw,a=s.lineWidth??o.size*.035,l=s.pen??Ps(t,{look:s.look??"clean",ink:r,lineWidth:a,seed:s.seed??1,time:i,pencil:{construction:!1,...s.pencil}}),c=s.skin??Aw,h=s.nails??!0,u=[{depth:o.palmDepth,draw:()=>$w(l,o,c,a)}];for(const d of Object.values(o.fingers)){const f=d.depths.reduce((p,g)=>p+g,0)/d.depths.length;u.push({depth:f,draw:()=>Iw(t,l,d,c,a,h)})}if(s.prop){const d=s.prop;u.push({depth:d.depth,draw:()=>d.draw(l)})}t.save(),t.lineCap="round",t.lineJoin="round";for(const d of[...u].sort((f,p)=>f.depth-p.depth))d.draw();return t.restore(),o}function $w(t,e,n,s){if(t.shape(e.palm,n,s),e.palmFacing<-.3&&t.look!=="silhouette"){const{up:i}=e.axes;for(const[o,r]of Object.entries(e.fingers)){const a=e.curls[o]??0;if(o==="thumb"||a<.5)continue;const l=r.points[0],c=r.widths[0]*.42,h={x:l.x-i.x*c*.2,y:l.y-i.y*c*.2},u=Math.atan2(i.y,i.x),d=Array.from({length:7},(f,p)=>{const g=u-Math.PI/2+Math.PI*p/6;return{x:h.x+Math.cos(g)*c,y:h.y+Math.sin(g)*c}});t.line(d,s*.6)}}if(e.palmFacing>.45&&t.look!=="silhouette"){const{up:i,across:o}=e.axes,r=e.size,a=e.wrist,l=(h,u)=>({x:a.x+(o.x*h+i.x*u)*r,y:a.y+(o.y*h+i.y*u)*r}),c=e.side==="left"?-1:1;t.line([l(-.15*c,.36),l(-.04*c,.3),l(.1*c,.33)],s*.5)}}function Iw(t,e,n,s,i,o){const{widths:r}=n,a=Ow(n.points,2),l=n.points[0],c=a[a.length-1],h=r[0],u=r[r.length-1];if(t.save(),e.look!=="silhouette"){t.beginPath(),t.rect(l.x-1e5,l.y-1e5,2e5,2e5);const 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(e.limb(a,h+2*i,u+2*i),t.restore(),e.look!=="silhouette"&&(t.fillStyle=s,Li(t,a,h,u)),e.look==="silhouette"||!o||n.nail<.25)return;const d=a[a.length-2],f=_w({x:c.x-d.x,y:c.y-d.y})??{x:0,y:-1},p={x:c.x-f.x*u*.22+n.back.x*u*.1,y:c.y-f.y*u*.22+n.back.y*u*.1};e.ellipse(p.x,p.y,u*.24*Math.max(.35,n.nail),u*.19,Math.atan2(f.y,f.x),"#f8e3d3",i*.45)}function Ow(t,e){let n=t;for(let s=0;s<e;s++){if(n.length<3)return n;const i=[n[0]];for(let o=0;o<n.length-1;o++){const r=n[o],a=n[o+1];o>0&&i.push({x:r.x*.75+a.x*.25,y:r.y*.75+a.y*.25}),o<n.length-2&&i.push({x:r.x*.25+a.x*.75,y:r.y*.25+a.y*.75})}i.push(n[n.length-1]),n=i}return n}const _w=t=>{const e=Math.hypot(t.x,t.y);return e>1e-6?{x:t.x/e,y:t.y/e}:null},Wt={walk:{swing:24,knee:30,arm:22,elbow:28,lean:4},bouncy:{swing:26,knee:45,arm:34,elbow:30,lean:2,bend:-4,bounce:.035,squash:.06},doubleBounce:{swing:22,knee:40,arm:26,elbow:24,lean:3,bounce:.02,bounces:2,squash:.04},sneak:{swing:28,knee:70,arm:6,elbow:0,forearm:110,shoulder:55,lean:16,bend:14,headTilt:-8,crouch:50,tiptoe:25},strut:{swing:26,knee:30,arm:30,elbow:20,lean:-4,bend:-10,headTilt:-6,sway:4,bounce:.01},tired:{swing:14,knee:14,arm:6,elbow:6,lean:10,bend:16,headTilt:12},run:{swing:40,knee:95,arm:45,elbow:0,forearm:90,lean:16,bend:6,bounce:.05,squash:.06},shove:{swing:18,knee:28,arm:0,elbow:0,lean:0}},Cw=40;function Os(t){return t===void 0?Wt.walk:typeof t=="string"?Wt[t]??Wt.walk:t}function tu(t,e,n=ct,s=1){const i=Os(t);if(i===Wt.walk)return ou(e,n,s);const o=e*Math.PI*2,r=Math.sin(o)*s,a=Math.cos(o)*s,l=w=>Math.abs(w)<=Cw,c=i.shoulder??0,h=(w,v)=>l(w)?v*c+i.arm*r:w,u=i.forearm??0,d=l(n.leftShoulder)?n.leftElbow-u-i.elbow*Math.max(0,-r):n.leftElbow,f=l(n.rightShoulder)?n.rightElbow+u+i.elbow*Math.max(0,r):n.rightElbow,p=i.bounces??1,g=(1+Math.cos(o*2*p))/2,m=i.crouch??0;return{...n,lean:n.lean+i.lean*s+(i.sway??0)*Math.sin(o)*(1-(n.turn??0)),bend:(n.bend??0)+(i.bend??0),headTilt:n.headTilt-i.lean*.5*s+(i.headTilt??0),leftElbow:d,rightElbow:f,leftHip:-i.swing*r-m*.5,rightHip:-i.swing*r+m*.5,leftKnee:-i.knee*Math.max(0,a)-m,rightKnee:i.knee*Math.max(0,-a)+m,leftAnkle:(n.leftAnkle??0)+(i.tiptoe??0),rightAnkle:(n.rightAnkle??0)+(i.tiptoe??0),leftShoulder:h(n.leftShoulder,-1),rightShoulder:h(n.rightShoulder,1),rise:(n.rise??0)+(i.bounce??0)*s*g,stretch:n.stretch*(1+(i.squash??0)*(g-.5))}}function Bi(t,e,n=1){const s=Os(t),i=Wt.walk.swing,o=r=>Math.sin(r*Math.PI/180);return ru(e,n)*o(s.swing*n)/o(i*n)}const ct={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 Rt(t){return{...ct,...t}}const eu={mouth:0,smile:0,mouthWidth:1,leftEye:1,rightEye:1,leftBrow:0,rightBrow:0,browTilt:0,lookX:0,lookY:0},Dt=t=>({...eu,...t}),vt={neutral:eu,happy:Dt({smile:.9,leftBrow:.2,rightBrow:.2}),joyful:Dt({mouth:.6,smile:1,mouthWidth:1.2,leftEye:0,rightEye:0,leftBrow:.4,rightBrow:.4}),sad:Dt({smile:-.8,leftEye:.8,rightEye:.8,browTilt:.9,leftBrow:-.1,rightBrow:-.1,lookY:.6}),crying:Dt({mouth:.45,smile:-1,leftEye:0,rightEye:0,browTilt:1,lookY:.4}),surprised:Dt({mouth:.7,mouthWidth:.7,leftEye:1.5,rightEye:1.5,leftBrow:1,rightBrow:1}),shocked:Dt({mouth:1,mouthWidth:.8,leftEye:1.6,rightEye:1.6,leftBrow:1,rightBrow:1,browTilt:.4}),angry:Dt({smile:-.6,mouthWidth:.9,leftEye:.8,rightEye:.8,leftBrow:-.6,rightBrow:-.6,browTilt:-1}),furious:Dt({mouth:.5,smile:-1,mouthWidth:1.3,leftEye:.9,rightEye:.9,leftBrow:-.9,rightBrow:-.9,browTilt:-1}),worried:Dt({smile:-.3,mouthWidth:.8,leftEye:1.1,rightEye:1.1,leftBrow:.3,rightBrow:.3,browTilt:.8,lookX:-.5}),scared:Dt({mouth:.35,smile:-.5,mouthWidth:.8,leftEye:1.45,rightEye:1.45,leftBrow:.8,rightBrow:.8,browTilt:.9}),confused:Dt({smile:-.2,mouthWidth:.8,leftEye:.9,rightEye:1.15,leftBrow:-.3,rightBrow:.8,lookX:.5,lookY:-.4}),skeptical:Dt({smile:-.1,leftEye:.6,rightEye:1,leftBrow:-.4,rightBrow:.7,lookX:.4}),thinking:Dt({smile:0,mouthWidth:.7,leftBrow:.3,rightBrow:.5,lookX:.6,lookY:-.8}),sleepy:Dt({smile:.1,leftEye:.25,rightEye:.25,leftBrow:-.3,rightBrow:-.3,lookY:.5}),disgusted:Dt({smile:-.7,mouthWidth:.9,leftEye:.6,rightEye:.75,leftBrow:-.5,rightBrow:-.2,browTilt:-.4,lookX:-.6}),smug:Dt({smile:.6,mouthWidth:.9,leftEye:.6,rightEye:.6,leftBrow:.1,rightBrow:.5,lookX:.5}),wink:Dt({smile:.9,leftEye:0,rightEye:1,leftBrow:-.2,rightBrow:.3})};function Le(t,e){return{...t,...typeof e=="string"?vt[e]:e}}const Vt={rest:ct,wave:Rt({rightShoulder:135,rightElbow:30,headTilt:6,...vt.happy}),cheer:Rt({leftShoulder:125,leftElbow:20,rightShoulder:125,rightElbow:20,...vt.joyful}),shrug:Rt({leftShoulder:30,leftElbow:85,rightShoulder:30,rightElbow:85,headTilt:-10,...vt.confused,lookX:0,lookY:0}),point:Rt({rightShoulder:90,rightElbow:0,lean:4,smile:.4}),think:Rt({rightShoulder:60,rightElbow:150,headTilt:10,...vt.thinking}),handsOnHips:Rt({leftShoulder:45,leftElbow:-100,rightShoulder:45,rightElbow:-100,leftHip:14,rightHip:14,smile:.8}),sad:Rt({leftShoulder:14,rightShoulder:14,leftElbow:-4,rightElbow:-4,headTilt:-14,lean:-3,...vt.sad}),surprised:Rt({leftShoulder:70,leftElbow:60,rightShoulder:70,rightElbow:60,...vt.surprised}),crouch:Rt({stretch:.72,leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50,leftHip:22,rightHip:22,headTilt:-4}),sit:Rt({sit:1,turn:.5,leftShoulder:-25,rightShoulder:25,leftElbow:-55,rightElbow:55}),jump:Rt({stretch:1.22,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4,...vt.joyful}),duck:Rt({stretch:.62,bend:28,headTilt:-8,leftShoulder:150,rightShoulder:150,leftElbow:130,rightElbow:130,leftHip:25,rightHip:25,...vt.scared}),lie:Rt({spin:-90,rise:-.42,leftShoulder:165,rightShoulder:165,leftElbow:150,rightElbow:150,...vt.sleepy}),sideSplit:Rt({leftHip:90,rightHip:90,leftAnkle:-45,rightAnkle:-45,leftShoulder:120,rightShoulder:120,leftElbow:10,rightElbow:10,...vt.happy}),frontSplit:Rt({turn:1,leftHip:-90,rightHip:-90,leftAnkle:-45,rightAnkle:-45,leftShoulder:-150,rightShoulder:150,leftElbow:10,rightElbow:-10,...vt.happy})},nu=Object.keys(ct);function Nn(t,e,n){const s={...t};for(const i of nu)s[i]=t[i]+(e[i]-t[i])*n;return s}const ua=24,su=4,iu=28,Hw=40;function ou(t,e=ct,n=1){const s=Math.sin(t*Math.PI*2)*n,i=Math.cos(t*Math.PI*2)*n,o=c=>Math.abs(c)<=Hw,r=c=>o(c)?22*s:c,a=o(e.leftShoulder)?e.leftElbow-iu*Math.max(0,-s):e.leftElbow,l=o(e.rightShoulder)?e.rightElbow+iu*Math.max(0,s):e.rightElbow;return{...e,lean:e.lean+su*n,headTilt:e.headTilt-su*.5*n,leftElbow:a,rightElbow:l,leftHip:-ua*s,rightHip:-ua*s,leftKnee:-30*Math.max(0,i),rightKnee:30*Math.max(0,-i),leftShoulder:r(e.leftShoulder),rightShoulder:r(e.rightShoulder)}}function ru(t,e=1){return 4*((da+zi)*t)*Math.sin(ua*e*Math.PI/180)}function au(t){const e=Math.abs(Math.sin(t/65)),n=.55+.45*Math.sin(t/310);return e*n}const lu=.12,cu=.46,Rw=1-2*lu,Lw=.1,Nw=.21,Fw=.19,da=.24,zi=.22,hu=.12,Dw=.14,uu=.33,du=.7,fu=.3,Ww=.35,Bw=[1.7,1.05],zw=[1.3,.75],gu=[1.45,.85],qw=[1.15,.75],pu=.06,Yw=.7,jw=.65,mu=.075,Kw=.3,Xw=.02,Gw=.012,Uw=12,Vw=.25,qi=90,Jw=.25,Zw=.04,yu=.01,on=t=>Math.min(1,Math.max(0,t??0));function Qw(t,e=1){return zi*t*e}const fa=-.12,bu=.4,te=t=>t*Math.PI/180,t2=(t,e)=>({x:e*Math.sin(te(t)),y:Math.cos(te(t))}),wu=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),ku=(t,e,n,s)=>t-.3*e-n*.14*e-Math.max(0,s-1)*.12*e;function e2(t,e,n,s,i,o){const r=Math.max(1,Math.min(o*.6,Dw*n)),a=on(e.turn),l=(hu+uu*a)*n,c=s+fa*n,h=l+e.lookX*.08*n,u=e.lookY*.07*n,d=[{x:-.34*n*(1-du*a),squeeze:1-du*a,open:e.leftEye,brow:e.leftBrow,side:-1},{x:.34*n*(1-fu*a),squeeze:1-fu*a,open:e.rightEye,brow:e.rightBrow,side:1}];t.fillStyle=i,t.strokeStyle=i,t.lineWidth=r;for(const w of d){const v=wu(w.open,e.blink);if(v<.2){const $=e.smile>.5?-.12*n:.06*n;t.beginPath(),t.moveTo(w.x+l-.12*n,c),t.quadraticCurveTo(w.x+l,c+$,w.x+l+.12*n,c),t.stroke()}else{if(v>1.2){const S=.13*n*v;t.beginPath(),t.ellipse(w.x+l,c,S*.85,S,0,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.stroke(),t.fillStyle=i}const $=v>1.2?.075*n:.1*n;t.beginPath(),t.ellipse(w.x+h,c+u,$,$*1.1*Math.min(v,1),0,0,Math.PI*2),t.fill()}const k=ku(c,n,w.brow,v),b=w.x+l-w.side*.13*n*w.squeeze,E=w.x+l+w.side*.13*n*w.squeeze;t.beginPath(),t.moveTo(E,k),t.lineTo(b,k-e.browTilt*.1*n),t.stroke()}const f=s+bu*n,p=.25*n*Math.max(.3,e.mouthWidth)*(1-Ww*a),g=Math.min(1,Math.max(0,e.mouth));if(t.beginPath(),g<=.05){t.moveTo(l-p,f),t.quadraticCurveTo(l,f+e.smile*.25*n,l+p,f),t.stroke();return}const m=.3*n*g;e.smile>.3?(t.moveTo(l-p,f-.05*n),t.lineTo(l+p,f-.05*n),t.quadraticCurveTo(l,f+m*2,l-p,f-.05*n)):e.smile<-.3?(t.moveTo(l-p,f+m*.6),t.lineTo(l+p,f+m*.6),t.quadraticCurveTo(l,f-m*1.4,l-p,f+m*.6)):t.ellipse(l,f,p*.8,m,0,0,Math.PI*2),t.fill()}function vu(t,e){const n=e.height??300,s=Math.min(3,Math.max(.3,t.stretch??1)),i=Math.sqrt(s),o=e.armLength??1;if(!Number.isFinite(o)||o<=0)throw new Error("stick figure: armLength must be a positive finite multiplier");const r=(e.headSize??2*lu)/2,a=e.headSize===void 0?Rw:1-2*r,l=r*n,c=on(t.sit),h=t.leftHip+(-qi-t.leftHip)*c,u=t.leftKnee+(-qi-t.leftKnee)*c,d=t.rightHip+(qi-t.rightHip)*c,f=t.rightKnee+(qi-t.rightKnee)*c,p=e.classic===!0,g=on(t.turn),m=(Y,L,z,O,P)=>{const H=Math.max(-Math.PI/2,Math.min(Math.PI/2,Math.abs(te(L-z)/2)+te(O))),W=Math.max(-1,Math.min(1,Yw+P)),q=g+(1-g)*Y*W;return p?{x:0,y:0}:{x:Math.cos(H)*pu*q,y:Math.sin(H)*pu}},w={left:t.leftAnkle??0,right:t.rightAnkle??0},v={left:t.leftFootOut??0,right:t.rightFootOut??0};let k=0;if(c>0||!p){const Y=(P,H,W,q,D)=>da*Math.cos(te(H))+zi*Math.cos(te(H-W))+Math.max(0,m(P,H,W,q,D).y),L=Math.max(Y(-1,h,u,w.left,v.left),Y(1,d,f,w.right,v.right)),z=1-on((t.rise??0)/Zw),O=(p?Math.min(1,c/Jw):1)*z;k=(cu-L)*O*n*s}const b=-cu*n*s+k,E=-a*n*s+k,$=p?0:(Xw*on(t.turn)+Gw*c)*n*s,S=te(t.bend??0),x={end:Su(b,E,S,1),bend:S};let M;if(S!==0){M=[];for(let Y=0;Y<=Mu;Y++){const L=Y/Mu,z=Su(b,E,S,L);M.push({x:z.x-$*Math.sin(Math.PI*L),y:z.y})}}else M=$===0?[{x:0,y:b},{x:0,y:E}]:sn({x:0,y:b},{x:-$,y:(b+E)/2},{x:0,y:E},1,8);const T=E+Lw*n*s,I=(e.shoulderWidth??0)*n*Math.cos(g*Math.PI/2),A=(Y,L,z,O,P)=>{const H=t2(z,O);return{x:Y+H.x*P*n,y:L+H.y*P*n}},_=(Y,L,z)=>{const O=A(0,b,L,Y,da*s);return{root:{x:0,y:b},joint:O,end:A(O.x,O.y,L-z,Y,zi*s)}},C=(Y,L,z)=>{const O={x:Y*I,y:T},P=A(O.x,O.y,L,Y,Nw*i*o);return{root:O,joint:P,end:A(P.x,P.y,L+z,Y,Fw*i*o)}},N={left:_(-1,h,u),right:_(1,d,f)},B=(Y,L,z,O,P,H)=>{const W=m(Y,z,O,P,H);return{x:L.end.x+W.x*n*s,y:L.end.y+W.y*n*s}},G=(Y,L,z,O,P)=>A(L.end.x,L.end.y,z+O+P,Y,mu*i),Z={left:C(-1,t.leftShoulder,t.leftElbow),right:C(1,t.rightShoulder,t.rightElbow)};return{height:n,facing:(e.facing??1)<0?-1:1,stretch:s,lineWidth:e.lineWidth??n*.025,rubber:Math.min(1,Math.max(p?0:Kw,e.rubber??0)),r:l,headRx:l/Math.sqrt(s),headRy:l*Math.sqrt(s),hipY:b,neckY:E,drop:k,lean:p?t.lean:t.lean+Uw*Math.sin(Math.PI*c),classic:p,legs:N,toes:{left:B(-1,N.left,h,u,w.left,v.left),right:B(1,N.right,d,f,w.right,v.right)},spine:M,chest:x,arms:Z,handTips:{left:G(-1,Z.left,t.leftShoulder,t.leftElbow,t.leftWrist??0),right:G(1,Z.right,t.rightShoulder,t.rightElbow,t.rightWrist??0)}}}const Mu=10;function Su(t,e,n,s){const i=t-e,o=n*s;if(Math.abs(n)<1e-9)return{x:0,y:t-i*s};const r=i/n;return{x:r*(1-Math.cos(o)),y:t-r*Math.sin(o)}}function n2(t,e){if(t.chest.bend===0)return e;const n=Cs(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 _s=(t,e)=>e===0?[t.root,t.joint,t.end]:sn(t.root,t.joint,t.end,e);function Cs(t,e,n){const s=Math.cos(n),i=Math.sin(n),o=t.x-e.x,r=t.y-e.y;return{x:e.x+o*s-r*i,y:e.y+o*i+r*s}}function Tu(t,e,n=!0){const s=i2(t,e),i=e.spin??0,o=e.rise??0;return n&&(i!==0||o!==0)?s2(s,t,i,o):s}function xu(t,e,n){return{pivot:{x:0,y:t.hipY},angle:t.facing*te(e),lift:n*t.height}}function s2(t,e,n,s){const{pivot:i,angle:o,lift:r}=xu(e,n,s),a=d=>{const f=Cs(d,i,o);return{x:f.x,y:f.y-r}},l=d=>({left:a(d.left),right:a(d.right)}),c={left:Math.max(a(t.feet.left).y,a(t.toes.left).y),right:Math.max(a(t.feet.right).y,a(t.toes.right).y)},h=Math.max(c.left,c.right),u=yu*e.height;return{...t,hip:a(t.hip),neck:a(t.neck),shoulders:l(t.shoulders),elbows:l(t.elbows),hands:l(t.hands),fingertips:l(t.fingertips),knees:l(t.knees),feet:l(t.feet),toes:l(t.toes),feetY:h,grounded:{left:c.left>=h-u,right:c.right>=h-u},handAngle:{left:t.handAngle.left+o,right:t.handAngle.right+o},limbs:{leftArm:t.limbs.leftArm.map(a),rightArm:t.limbs.rightArm.map(a),leftLeg:t.limbs.leftLeg.map(a),rightLeg:t.limbs.rightLeg.map(a),spine:t.limbs.spine.map(a)},head:{...t.head,center:a(t.head.center),angle:t.head.angle+o}}}function i2(t,e){const n=te(t.lean),s=te(e.headTilt),i={x:0,y:t.hipY},o=b=>({x:t.facing*b.x,y:b.y}),r=b=>o(Cs(b,i,n)),a=b=>r(n2(t,b)),l=b=>a(Cs({x:b.x,y:b.y+t.neckY},{x:0,y:t.neckY},s)),c=_s(t.arms.left,t.rubber).map(a),h=_s(t.arms.right,t.rubber).map(a),u=(b,E)=>Math.atan2(E.y-b.y,E.x-b.x),d={left:a(t.handTips.left),right:a(t.handTips.right)},f=(b,E)=>{const[$,S]=b.slice(-2),x=t.arms[E],M=u(a(x.end),d[E])-u(a(x.joint),a(x.end));return u($,S)+M};let p=1/0;for(const[b,E]of[[e.leftBrow,e.leftEye],[e.rightBrow,e.rightEye]]){const $=ku(fa,1,b,wu(E,e.blink));p=Math.min(p,$,$-e.browTilt*.1)}const g={left:o(t.legs.left.end),right:o(t.legs.right.end)},m={left:o(t.toes.left),right:o(t.toes.right)},w={left:Math.max(g.left.y,m.left.y),right:Math.max(g.right.y,m.right.y)},v=Math.max(w.left,w.right),k=yu*t.height;return{facing:t.facing,height:t.height,stretch:t.stretch,lineWidth:t.lineWidth,hip:i,neck:a({x:0,y:t.neckY}),shoulders:{left:a(t.arms.left.root),right:a(t.arms.right.root)},elbows:{left:a(t.arms.left.joint),right:a(t.arms.right.joint)},hands:{left:a(t.arms.left.end),right:a(t.arms.right.end)},knees:{left:o(t.legs.left.joint),right:o(t.legs.right.joint)},feet:g,toes:m,feetY:v,grounded:{left:w.left>=v-k,right:w.right>=v-k},fingertips:d,handAngle:{left:f(c,"left"),right:f(h,"right")},limbs:{leftArm:c,rightArm:h,leftLeg:_s(t.legs.left,t.rubber).map(o),rightLeg:_s(t.legs.right,t.rubber).map(o),spine:t.spine.map(r)},head:{center:l({x:0,y:-t.headRy}),rx:t.headRx,ry:t.headRy,angle:t.facing*(n+t.chest.bend+s),eyeY:fa,browTopY:p,mouthY:bu,faceX:t.facing*(hu+uu*on(e.turn))}}}function ae(t,e={}){return Tu(vu(t,e),t)}function o2(t,e,n){return Cs({x:t.center.x+e*t.rx,y:t.center.y+n*t.ry},t.center,t.angle)}function Eu(t,e,n){const s=o=>({x:o.x+e,y:o.y+n}),i=o=>({left:s(o.left),right:s(o.right)});return{...t,hip:s(t.hip),neck:s(t.neck),shoulders:i(t.shoulders),elbows:i(t.elbows),hands:i(t.hands),fingertips:i(t.fingertips),knees:i(t.knees),feet:i(t.feet),toes:i(t.toes),feetY:t.feetY+n,grounded:{...t.grounded},handAngle:{...t.handAngle},limbs:{leftArm:t.limbs.leftArm.map(s),rightArm:t.limbs.rightArm.map(s),leftLeg:t.limbs.leftLeg.map(s),rightLeg:t.limbs.rightLeg.map(s),spine:t.limbs.spine.map(s)},head:{...t.head,center:s(t.head.center)}}}function Au(t,e,n={},s=0){const i=vu(e,n),o=n.color??"#1e293b",r=n.layers??{},a=n.layers?Tu(i,e,!1):void 0,l=n.sketch?Ri(t,n.sketch,s):void 0,c=n.sketch&&n.layers?Ri(t,n.sketch,s):void 0,h=S=>{t.save(),S(),t.restore()},u=S=>{S&&a&&h(()=>S(t,a,s,c))},d=()=>t.scale(i.facing,1),f=()=>{d(),t.translate(0,i.hipY),t.rotate(te(i.lean)),t.translate(0,-i.hipY)},p=()=>{f(),i.chest.bend!==0&&(t.translate(i.chest.end.x,i.chest.end.y),t.rotate(i.chest.bend),t.translate(0,-i.neckY))},g=(S,x,M)=>{if(l)return x?l.curve(S):l.line(S);if(i.classic){t.beginPath(),t.moveTo(S[0].x,S[0].y);for(const T of S.slice(1))t.lineTo(T.x,T.y);t.stroke();return}Li(t,S,M[0]*i.lineWidth,M[1]*i.lineWidth)},m=(S,x)=>g(_s(S,i.rubber),i.rubber>0,x),w=S=>{i.classic||g([i.legs[S].end,i.toes[S]],!1,qw)},v=S=>{if(n.hands&&!i.classic)return b(S);if(i.classic||l)return;const x=i.arms[S].end;t.beginPath(),t.arc(x.x,x.y,jw*i.lineWidth,0,Math.PI*2),t.fill()};t.save(),t.strokeStyle=o,t.fillStyle=o,t.lineWidth=i.lineWidth,t.lineCap="round",t.lineJoin="round";const k=xu(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 b(S){const x=n.hands??{},M=i.arms[S].end,T=i.handTips[S],I=n.headFill??"#ffffff";Wi(t,M,x[S]??Pt,{side:S,angle:Math.atan2(T.x-M.x,M.y-T.y)*180/Math.PI,size:(x.size??mu)*i.height*Math.sqrt(i.stretch),skin:x.skin??(I==="none"?void 0:I),ink:o,lineWidth:i.lineWidth*.45,fingers:x.fingers,plump:x.plump,look:n.sketch?"pencil":"clean",seed:n.sketch?.seed},s)}const E=S=>{h(()=>{p(),m(i.arms[S],zw),v(S)});const x=r.sleeve;x&&a&&h(()=>x(t,a,S,s,c))},$=on(e.turn)>Vw;u(r.behind),h(()=>{d(),m(i.legs.left,gu),w("left"),m(i.legs.right,gu),w("right")}),$&&E("left"),h(()=>{f(),g(i.spine,i.spine.length>2,Bw)}),h(()=>{p();const{left:S,right:x}={left:i.arms.left.root,right:i.arms.right.root};if(S.x!==x.x)if(i.classic)g([S,x],!1,[1,1]);else{const M={x:(S.x+x.x)/2,y:S.y-.3*Math.abs(x.x-S.x)};g(sn(S,M,x,1,8),!0,[1.1,1.1])}}),u(r.body),$||E("left"),E("right"),u(r.behindHead),h(()=>{p(),t.translate(0,i.neckY),t.rotate(te(e.headTilt));const S=-i.headRy;t.beginPath(),t.ellipse(0,S,i.headRx,i.headRy,0,0,Math.PI*2);const x=n.headFill??"#ffffff";if(x!=="none"&&(t.fillStyle=x,t.fill()),l){l.ellipse(0,S,i.headRx,i.headRy);const M=l.nudge();t.translate(M.x,M.y)}else t.stroke();t.translate(0,S),t.scale(i.headRx/i.r,i.headRy/i.r),e2(t,e,i.r,0,o,i.lineWidth)}),u(r.overHead),u(r.front),t.restore(),n.label&&(t.save(),t.fillStyle=o,t.font=n.labelFont??`700 ${Math.round(i.height*.11)}px sans-serif`,t.textAlign="center",t.textBaseline="bottom",t.fillText(n.label,0,-i.height*i.stretch-.04*i.height+i.drop),t.restore())}function ga(t,e,n,s){const i={...t},o=t.gait&&s?.[t.gait]||t.gait;let r=t.walking>0?Nn(i,tu(o,t.walk,i),t.walking):i,a=r2(t);const l=t.dancing??0;if(n&&l>0){const c=n(t.beat??0);if(r=Nn(r,c.pose,l),c.hands){const h=(u,d)=>d?Ln(u??Pt,d,l):u;a={left:h(a?.left,c.hands.left),right:h(a?.right,c.hands.right)}}}return t.talk>0&&(r={...r,mouth:Math.max(r.mouth,t.talk*au(e))}),{pose:r,hands:a}}function Pu(t,e,n,s){return ga(t,e,n,s).pose}const $u=(t,e)=>(t.facing??e.facing??1)<0?-1:1,Hs=(t,e)=>`hand.${t}.${e}`;function r2(t){const e=i=>{if(typeof t[Hs(i,"spread")]=="number")return Object.fromEntries(Object.keys(Pt).map(o=>[o,t[Hs(i,o)]]))},n=e("left"),s=e("right");return n||s?{left:n,right:s}:void 0}function a2(t,e){return!e||!t.hands?t:{...t,hands:{...t.hands,left:e.left??t.hands.left,right:e.right??t.hands.right}}}function pa(t){const e=t.style??{},n=e.height??300,s=n*.8,i={...Rt(t.pose??{}),walk:0,walking:0,gait:"walk",facing:(e.facing??1)<0?-1:1,talk:0,rubber:e.rubber??0,beat:0,dancing:0},o={};if(e.hands)for(const r of["left","right"]){const a=e.hands[r]??Pt;for(const l of Object.keys(Pt))o[Hs(r,l)]=a[l]??Pt[l]}return{type:"custom",x:t.x-s/2,y:t.y-n,width:s,height:n,props:{...i,...o},about:l2(Object.keys(o),t.cast),figureStyle:e,figureDance:t.dance,figureGaits:t.cast?.gaits,draw(r,a,l){const c=a.props,h=ga(c,l,t.dance,t.cast?.gaits);r.translate(s/2,n),Au(r,h.pose,a2({...e,rubber:c.rubber,facing:$u(c,e)},h.hands),l)}}}function l2(t,e){const n={...q0,...Y0};for(const s of t){const[,i,...o]=s.split("."),r=j0[o.join(".")];r&&(n[s]={...r,description:`${i==="left"?"Left":"Right"} hand: ${r.description.toLowerCase()}`})}return{kind:"stick figure",summary:"A poseable stick figure: pose it with joint tracks, or give it beats (`scriptTracks`) that compile into acted tracks.",props:n,get actions(){return lw(e)}}}function ma(t,e,n){const s=t.figureStyle;if(!s)throw new Error("stickFigureAt: the target was not made by stickFigureTarget");const i={...t.props};let o=0,r=0;for(const[c,h]of e.state?.values.get(n)??[])c==="gait"&&typeof h=="string"&&(i.gait=h),typeof h=="number"&&(c==="x"||c==="motionPathX"?o=h:c==="y"||c==="motionPathY"?r=h:c in i&&(i[c]=h));const a=Pu(i,e.time,t.figureDance,t.figureGaits),l=ae(a,{...s,rubber:i.rubber,facing:$u(i,s)});return{pose:a,joints:Eu(l,t.x+o+t.width/2,t.y+r+t.height)}}function Yi(t){const e=[];return t.forEach((n,s)=>{const i=s===0?ct:e[s-1],o=typeof n.pose=="string"?Vt[n.pose]:{...i,...n.pose};e.push(n.expression?Le(o,n.expression):o)}),e}function c2(t,e){const n=Yi(e);return nu.filter(s=>n.some(i=>i[s]!==ct[s])).map(s=>({id:`${t}-${s}`,target:t,property:s,keyframes:e.map((i,o)=>({time:i.time,value:n[o][s],...i.easing?{easing:i.easing}:{}}))}))}const ya=.5,ji={pataka:Ht({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:0,turn:2}),tripataka:Ht({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":1,"pinky.curl":0,spread:0,turn:2}),alapadma:Ht({"thumb.curl":.1,"thumb.across":0,"index.curl":.05,"middle.curl":.15,"ring.curl":.25,"pinky.curl":.35,spread:1,turn:2}),mushti:Ct.fist,shikhara:Ct.thumbsUp,hamsasya:Ht({"thumb.curl":.15,"thumb.across":.6,"index.curl":.6,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:.7,turn:2}),katakamukha:Ht({"thumb.curl":.2,"thumb.across":.6,"index.curl":.65,"middle.curl":.7,"ring.curl":0,"pinky.curl":0,spread:.4,turn:2})};function Ki(t){return typeof t!="string"?t:t in ji?ji[t]:Ct[t]}function Iu(t,e,n){const s=[];for(const i of t.keys){const o=s[s.length-1],r=!o||i.reset?{pose:e,...n}:o;s.push({beat:i.beat,pose:{...r.pose,...i.pose},left:i.hands?.left?Ki(i.hands.left):r.left,right:i.hands?.right?Ki(i.hands.right):r.right,easing:i.easing??t.easing})}return s}const ba=(t,e)=>(t%e+e)%e;function h2(t,e,n,s){const i=Iu(t,n,s);if(i.length===0)return{pose:n,hands:s};const o=ba(e,t.beats);let r=i.length-1;for(let f=0;f<i.length;f++)i[f].beat<=o&&(r=f);const a=i[r],l=i[(r+1)%i.length],c=a.beat<=o?a.beat:a.beat-t.beats,h=l.beat>c?l.beat:l.beat+t.beats,u=h>c?(o-c)/(h-c):0,d=Lt(l.easing??"ease-in-out")(Math.min(1,Math.max(0,u)));return{pose:Nn(a.pose,l.pose,d),hands:{left:Ln(a.left,l.left,d),right:Ln(a.right,l.right,d)}}}const u2=[["leftShoulder","rightShoulder"],["leftElbow","rightElbow"],["leftWrist","rightWrist"],["leftHip","rightHip"],["leftKnee","rightKnee"],["leftAnkle","rightAnkle"],["leftFootOut","rightFootOut"],["leftEye","rightEye"],["leftBrow","rightBrow"]],d2=["lean","headTilt","lookX","spin"],f2=new Set(["leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee"]);function Ou(t){const e={...t},n=(t.turn??0)>=.5;for(const[s,i]of u2){const o=n&&f2.has(s)?-1:1;e[s]=o*t[i],e[i]=o*t[s]}if(!n)for(const s of d2)e[s]=-t[s];return e}const g2=t=>Math.min(1,Math.max(-1,(.5-t)*4));function _u(t,e,n){const s=ba(n,1),i=(1+Math.cos(2*Math.PI*s))/2,o=e.bounce*(e.accent==="up"?1-i:i),r=Math.min(1,Math.max(0,t.turn??0)),a=g2(r);return{...t,leftHip:t.leftHip+a*o/2,rightHip:t.rightHip+o/2,leftKnee:t.leftKnee+a*o,rightKnee:t.rightKnee+o,lean:t.lean+(e.sway??0)*(1-r)*Math.sin(Math.PI*n)}}function Xi(t){const e={...ct,...t.stance};return t.expression?Le(e,t.expression):e}function Cu(t){return{left:t.hands?.left?Ki(t.hands.left):Pt,right:t.hands?.right?Ki(t.hands.right):Pt}}function wa(t,e,n){const s=t.moves[e.move];if(!s)throw new Error(`dance: "${t.label}" has no move "${e.move}"`);const i=h2(s,n,Xi(t),Cu(t));return e.mirror?{pose:Ou(i.pose),hands:{left:i.hands?.right,right:i.hands?.left}}:i}function Gi(t,e,n={}){const s=typeof t=="string"?Ne[t]:t;let i;if(n.move)i=wa(s,{move:n.move,mirror:n.mirror},e);else{const o=s.routine,r=o.reduce((u,d)=>u+d.beats,0),a=ba(e,r);let l=0,c=0;for(;c<o.length-1&&a>=l+o[c].beats;)l+=o[c++].beats;const h=a-l;if(i=wa(s,o[c],h),h<ya&&o.length>1&&e>=ya){const u=o[(c-1+o.length)%o.length],d=wa(s,u,u.beats+h),f=Lt("ease-in-out")(h/ya);i={pose:Nn(d.pose,i.pose,f),hands:{left:Ln(d.hands.left,i.hands.left,f),right:Ln(d.hands.right,i.hands.right,f)}}}}return{...i,pose:_u(i.pose,s.groove,e)}}function p2(t,e,n={}){return Gi(t,e,n).pose}function Ui(t){return(typeof t=="string"?Ne[t]:t).routine.reduce((n,s)=>n+s.beats,0)}const m2={leftToe:"rightToe",rightToe:"leftToe",leftHeel:"rightHeel",rightHeel:"leftHeel"};function Hu(t,e,n,s,i,o,r){for(let a=0;a*t.beats<n;a++)for(const l of t.keys){const c=a*t.beats+l.beat,h=e+c;if(!(c>=n||h<o||h>=r))for(const u of l.taps??[])i.push({beat:h,tap:s?m2[u]:u})}}function y2(t,e,n,s={}){const i=typeof t=="string"?Ne[t]:t,o=[];if(n<=e)return o;if(s.move){const r=i.moves[s.move],a=Math.floor(e/r.beats)*r.beats;Hu(r,a,Math.ceil((n-a)/r.beats)*r.beats,s.mirror,o,e,n)}else{const r=Ui(i);for(let a=Math.floor(e/r)*r;a<n;a+=r){let l=a;for(const c of i.routine)Hu(i.moves[c.move],l,c.beats,c.mirror,o,e,n),l+=c.beats}}return o.sort((r,a)=>r.beat-a.beat)}function Ru(t,e){const n=t.moves[e.move];if(!n?.travel)return 0;const s=n.travel/n.beats;return e.mirror?(Iu(n,Xi(t),Cu(t))[0]?.pose.turn??Xi(t).turn??0)>=.5?s:-s:s}function Lu(t,e){return e.move?[{move:e.move,beats:t.moves[e.move].beats,mirror:e.mirror}]:t.routine}function Vi(t,e,n={}){const s=typeof t=="string"?Ne[t]:t,i=Lu(s,n),o=i.reduce((h,u)=>h+u.beats,0),r=i.reduce((h,u)=>h+Ru(s,u)*u.beats,0),a=Math.floor(e/o);let l=a*r,c=e-a*o;for(const h of i){const u=Math.min(h.beats,c);if(l+=Ru(s,h)*u,c-=u,c<=0)break}return l}function b2(t,e,n){const s=Lu(t,n),i=[0];let o=0;for(let r=0;o<e;r=(r+1)%s.length)o+=s[r].beats,i.push(Math.min(o,e));return i}const w2=8;function Nu(t,e,n){const s=typeof e=="string"?Ne[e]:e,i=n.bpm??s.bpm,o=n.beats??(n.move?s.moves[n.move].beats:Ui(s)),r=b2(s,o,n);if(r.every(w=>Vi(s,w,n)===0))return;const a=Math.min(n.fade??1,o/2),l=Lt("ease-in-out"),c=w=>a<=0?1:Math.min(l(Math.min(1,w/a)),l(Math.min(1,(o-w)/a))),h=Math.ceil(a*w2),u=a<=0?[]:Array.from({length:h+1},(w,v)=>[v/h*a,o-v/h*a]).flat(),d=[...new Set([...r,...u])].sort((w,v)=>w-v);let f=0;const p=d.map((w,v)=>{if(v>0){const k=d[v-1],b=Math.max(1,Math.ceil((w-k)*16));for(let E=0;E<b;E++){const $=k+(w-k)*E/b,S=k+(w-k)*(E+1)/b;f+=(Vi(s,S,n)-Vi(s,$,n))*c(($+S)/2)}}return{beat:w,travel:f}}),g=n.start??0,m=n.x??0;return{id:`${t}-x`,target:t,property:"x",keyframes:p.map(w=>({time:g+w.beat*6e4/i,value:m+n.height*w.travel,easing:"linear"}))}}function k2(t,e,n=0){return(t-n)*e/6e4}function v2(t,e={}){return n=>Gi(t,n,e)}function M2(t,e){const n=e.start??0,s=6e4/e.bpm,i=n+e.beats*s,o=Math.min((e.fade??1)*s,(i-n)/2);return[{id:`${t}-beat`,target:t,property:"beat",keyframes:[{time:n,value:0},{time:i,value:e.beats,easing:"linear"}]},{id:`${t}-dancing`,target:t,property:"dancing",keyframes:[{time:n,value:0},{time:n+o,value:1,easing:"ease-in-out"},{time:i-o,value:1},{time:i,value:0,easing:"ease-in-out"}]}]}function S2(t,e,n={}){const s=typeof e=="string"?Ne[e]:e,i=n.bpm??s.bpm,o=n.beats??(n.move?s.moves[n.move].beats:Ui(s)),r=n.samplesPerBeat??4,a=n.start??0,l=Math.round(o*r),c=Array.from({length:l+1},(g,m)=>{const w=m/r;return{time:a+w*6e4/i,frame:Gi(s,w,n)}}),h=(g,m)=>({id:`${t}-${g}`,target:t,property:g,keyframes:c.map(w=>({time:w.time,value:m(w.frame)}))}),d=Object.keys(ct).filter(g=>c.some(m=>m.frame.pose[g]!==c[0].frame.pose[g])||c[0].frame.pose[g]!==ct[g]).map(g=>h(g,m=>m.pose[g])),f=n.height===void 0?void 0:Nu(t,s,{...n,bpm:i,beats:o,start:a,height:n.height,fade:0});if(f&&d.push(f),n.hands===!1)return d;const p=[];for(const g of["left","right"])for(const m of Object.keys(Pt)){const w=v=>v.hands?.[g]?.[m]??Pt[m];c.some(v=>w(v.frame)!==Pt[m])&&p.push(h(Hs(g,m),w))}return[...d,...p]}const Rs={type:"back",mode:"out",overshoot:1.1},Yt="ease-out-cubic",T2={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:Yt,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:Yt},{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:Yt},{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}]},x2={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}]},E2={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:Yt},{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:Yt},{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:Yt},{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:Rs},{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}]},A2={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:{...Ct.spread,turn:2},right:{...Ct.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:Yt},{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}]},P2={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:Rs,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:Rs},{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:Rs},{beat:3,pose:{headTilt:4}}]},isolations:{label:"Isolations",beats:2,easing:Yt,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}]},$2={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:{...Ct.cupped,roll:-30},left:{...Ct.flat,turn:0}}},{beat:.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{...Ct.cupped,roll:30}}},{beat:1,pose:{rightWrist:-15,rightElbow:12,leftWrist:-45,lean:-4,rightHip:16,leftHip:6},hands:{right:{...Ct.cupped,roll:-30}}},{beat:1.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{...Ct.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:{...Ct.open,turn:2}},easing:Yt},{beat:.5,pose:{lean:-4,rightHip:12,headTilt:6}},{beat:1,pose:{lean:-11,rightHip:22,headTilt:10},easing:Yt},{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:Yt},{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:Yt}]}},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}]},I2={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}]},O2={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}]},_2={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:{...Ct.spread,turn:2},right:{...Ct.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:Yt},{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:Yt},{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}]},C2={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:{...Ct.spread,turn:2},right:{...Ct.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}]},Ne={disco:T2,hipHop:x2,breaking:E2,jazz:A2,kpop:P2,bollywood:$2,bhangra:I2,bharatanatyam:O2,charleston:_2,tap:C2,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:Rs},{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}]}},Ji={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}},ka=.215,va=.205,H2=.065,Fu=.035,R2=.165,L2=.155,N2=12,F2=.3,D2=.7,W2=.35,B2=t=>t*Math.PI/180,ht={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 bt(t={}){return{...ht,...t}}const z2=new Set(["turn","side","head.turn","head.tilt","roll","lookX","hair.swing"]);function Du(t){const e={};for(const[n,s]of Object.entries(t)){const i=n.replace(/(^|\.)(left|right)(\.|$)/,(o,r,a,l)=>`${r}${a==="left"?"right":"left"}${l}`);e[i]=z2.has(n)?-s:s}return e}function xt(t,e){const n={};for(const s of["left","right"])for(const[i,o]of Object.entries(e))n[`${t}.${s}.${i}`]=o;return n}const le={rest:ht,wave:bt({"arm.right.spread":115,"arm.right.bend":55,"arm.right.elbow":0,"head.tilt":-6,smile:.9}),cheer:bt({...xt("arm",{spread:140,bend:20,elbow:0}),mouth:.6,smile:1,"eye.left":0,"eye.right":0}),point:bt({"arm.right.spread":88,"arm.right.elbow":0,"arm.right.bend":0,"head.turn":-20,smile:.4}),handsOnHips:bt({...xt("arm",{spread:50,bend:-105,elbow:0}),...xt("leg",{spread:9}),smile:.8}),think:bt({"arm.right.spread":22,"arm.right.bend":-150,"arm.right.elbow":0,"head.tilt":10,lookX:-.5,lookY:-.8,smile:0}),shrug:bt({...xt("arm",{spread:35,bend:75,elbow:0}),"head.tilt":-10,smile:-.2}),sit:bt({...xt("leg",{swing:90,knee:90,spread:4}),...xt("arm",{swing:25,elbow:45,spread:8})}),kneel:bt({"leg.left.swing":90,"leg.left.knee":90,"leg.right.swing":-18,"leg.right.knee":108,"leg.right.ankle":16,...xt("arm",{swing:20,elbow:30})}),crouch:bt({...xt("leg",{swing:75,knee:140,spread:6}),lean:25,...xt("arm",{swing:50,elbow:40}),"head.nod":-15}),crawl:bt({lean:82,"head.nod":-35,...xt("arm",{swing:80,elbow:0,spread:4}),...xt("leg",{knee:92,ankle:-88})}),lieDown:bt({roll:90,...xt("arm",{spread:8}),"head.nod":0}),sleep:bt({roll:90,...xt("arm",{spread:8,swing:20,elbow:40}),"leg.left.knee":20,"leg.left.swing":15,blink:1,smile:.2}),stretch:bt({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:bt({...xt("leg",{swing:80,spread:22,rotate:75,knee:145}),...xt("arm",{swing:25,spread:18,elbow:30}),lean:5,smile:.5}),carry:bt({...xt("arm",{spread:16,elbow:4}),lean:-3,smile:.4}),cane:bt({"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:bt({...xt("arm",{swing:28,spread:24,elbow:85,bend:-45}),...xt("leg",{swing:12,knee:22,spread:6}),lean:-4,smile:.2}),push:bt({lean:28,...xt("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:bt({lean:-22,...xt("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:bt({"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:bt({"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:bt({...xt("arm",{swing:32,spread:10,elbow:82,bend:-28}),"head.nod":22,lookY:.8,smile:.2}),type:bt({...xt("leg",{swing:90,knee:90,spread:4}),...xt("arm",{swing:40,spread:10,elbow:55,bend:-20}),lean:8,"head.nod":10,lookY:.5,smile:0})},Wu=["round","flat","pointed","big"],q2={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 Ma(t={}){const e=t.headSize??.3,n=t.shoulderWidth??.06,s=t.hipWidth??.022,i=t.legLength??1,o=t.armLength??1,r=q2[t.feet??"round"],a=Math.max(.12,1-e-Fu-(ka+va)*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:R2*o,width:[1.25,.9]},{length:L2*o,width:[.9,.75]}]}),c=u=>({id:`leg.${u}`,parent:null,offset:[(u==="left"?1:-1)*s,0,0],rest:[0,-1,0],side:u==="left"?1:-1,bones:[{length:ka*i,width:[1.45,1.05]},{length:va*i,width:[1.05,.85]},{length:H2*Math.sqrt(i)*r.length,width:r.width}]}),h=(u,d)=>u[d]??ht[d]??0;return{id:"human",hipHeight:(ka+va)*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:Fu,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,b=-h(u,"bend");return[{swing:v+b*F2,spread:k},{swing:v+b*D2,spread:k}]}if(d.id==="neck")return[{swing:-h(u,"bend")*W2,spread:0}];const[f,p]=d.id.split("."),g=v=>h(u,`${f}.${p}.${v}`);if(f==="arm")return[{swing:g("swing"),spread:g("spread")},{swing:g("elbow"),spread:g("bend")}];const m=(d.side??1)*g("rotate"),w=1-Math.cos(B2(g("rotate")));return[{swing:g("swing"),spread:g("spread"),yaw:m},{swing:-g("knee"),spread:0,yaw:m},{swing:90+g("ankle")-w*(g("swing")-g("knee")),spread:0,yaw:(N2+g("toeOut"))*(d.side??1)}]},withAngles(u,d,f){const[p,g]=d.id.split("."),m=w=>`${p}.${g}.${w}`;return p==="arm"?{...u,[m("swing")]:f[0].swing,[m("spread")]:f[0].spread,[m("elbow")]:f[1].swing,[m("bend")]:f[1].spread}:p==="leg"?{...u,[m("swing")]:f[0].swing,[m("spread")]:f[0].spread,[m("knee")]:-f[1].swing}:u},boneScale(u,d){const f=Math.min(3,Math.max(.3,h(u,"stretch")));return d?.id.startsWith("arm.")?Math.sqrt(f):f},headPose(u){const d=Math.min(3,Math.max(.3,h(u,"stretch")));return{yaw:h(u,"head.turn"),nod:h(u,"head.nod"),tilt:h(u,"head.tilt"),sx:1/Math.sqrt(d),sy:Math.sqrt(d)}},landmarks:{neck:["neck",0],"shoulder.left":["arm.left",0],"elbow.left":["arm.left",1],"hand.left":["arm.left",2],"shoulder.right":["arm.right",0],"elbow.right":["arm.right",1],"hand.right":["arm.right",2],"hip.left":["leg.left",0],"knee.left":["leg.left",1],"ankle.left":["leg.left",2],"toe.left":["leg.left",3],"hip.right":["leg.right",0],"knee.right":["leg.right",1],"ankle.right":["leg.right",2],"toe.right":["leg.right",3]}}}function Y2(t){const e=t.split(".");if(e[0]==="hand"&&e.length>=3){const s=`${e[1]==="left"?"Left":"Right"} hand`,i={spread:"finger spread",turn:"wrist turn",bend:"wrist bend",tilt:"wrist tilt",roll:"roll"},o=e.slice(2).join(".");return`${s} · ${i[o]??o.replace(".curl"," curl").replace(".across"," across")}`}if(e.length===3){const[s,i,o]=e;return`${`${i==="left"?"Left":"Right"} ${s}`} · ${{swing:"forward / back",spread:"out / in",elbow:"elbow bend",bend:"forearm out / in",knee:"knee bend",ankle:"foot tilt",toeOut:"toes out / in",rotate:"turn out at the hip"}[o]??o}`}return{turn:"View (front → side → back)",lean:"Lean forward / back",bend:"Back curve (line of action)",side:"Lean sideways","head.turn":"Head · turn","head.nod":"Head · nod","head.tilt":"Head · tilt",stretch:"Squash / stretch",lift:"Lift off the ground",roll:"Roll (whole figure)",mouth:"Mouth open",smile:"Smile",mouthWidth:"Mouth width",blink:"Blink","eye.left":"Left eye open","eye.right":"Right eye open",pupil:"Pupil size",lid:"Eyelids lowered",bulge:"Eyes bulging","brow.left":"Left brow","brow.right":"Right brow",browTilt:"Brow slant",lookX:"Look left / right",lookY:"Look up / down",blush:"Blush",tears:"Tears",sweat:"Sweat","hair.swing":"Hair · swing","hair.trail":"Hair · trail","hair.lift":"Hair · lift","held.left":"Left hand · holding","held.right":"Right hand · holding","held.both":"Both hands · holding"}[t]??t}const j2={leftEye:"eye.left",rightEye:"eye.right",leftBrow:"brow.left",rightBrow:"brow.right"},K2={blush:0,tears:0,sweat:0,pupil:1,lid:0,bulge:0},rn=Object.fromEntries(Object.entries(vt).map(([t,e])=>[t,{...Object.fromEntries(Object.entries(e).map(([n,s])=>[j2[n]??n,s])),...K2}]));rn.crying.tears=1,rn.scared.sweat=.8,rn.scared.bulge=.4,rn.sleepy.lid=.5,rn.worried.sweat=.6;const ee=t=>({...rn.neutral,...t}),Sa={...rn,laughing:ee({mouth:.75,smile:1,mouthWidth:1.25,"eye.left":0,"eye.right":0,"brow.left":.5,"brow.right":.5}),afraid:ee({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:ee({smile:-.05,mouthWidth:.6,"eye.left":.45,"eye.right":.45,"brow.left":-.4,"brow.right":-.4,lookX:.5}),tired:ee({mouth:.2,smile:-.3,mouthWidth:.7,"eye.left":.3,"eye.right":.3,"brow.left":-.1,"brow.right":-.1,browTilt:.6,lookY:.6}),embarrassed:ee({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:ee({smile:.75,mouthWidth:1,"eye.left":.75,"eye.right":.75,"brow.left":.5,"brow.right":.5,lookY:-.2}),determined:ee({smile:.35,mouthWidth:.8,"eye.left":.85,"eye.right":.85,"brow.left":-.5,"brow.right":-.5,browTilt:-.9}),affectionate:ee({smile:.85,"eye.left":0,"eye.right":0,"brow.left":.3,"brow.right":.3,blush:.8}),hurt:ee({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:ee({smile:-.25,mouthWidth:.7,"eye.left":.5,"eye.right":.85,"brow.left":-.6,"brow.right":.4,browTilt:-.3,lookX:.8,lid:.3}),relieved:ee({smile:.7,"eye.left":0,"eye.right":0,"brow.left":.4,"brow.right":.4,browTilt:.4}),excited:ee({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})},ce=t=>t*Math.PI/180;function Ta([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t,e*i+n*o,-e*o+n*i]}function Zi([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i-e*o,t*o+e*i,n]}function ne([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i+n*o,e,-t*o+n*i]}const Fe=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Qi=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],to=(t,e)=>Zi(Ta(t,e.swing),e.spread);function eo(t,e){const n=ne(t,e);return{point:{x:n[0],y:-n[1]},depth:n[2]}}function Ls(t,e,n){const s=n,o=[0,t.hipHeight*s*(t.boneScale?.(e,null)??1),0],r={};for(const g of t.chains){const m=g.parent?r[g.parent]:void 0;if(g.parent&&!m)throw new Error(`body plan ${t.id}: chain ${g.id} comes before its parent ${g.parent}`);const w=g.at??(m?m.joints3.length-1:0),v=m?m.joints3[w]:o,k=m?m.frames[Math.max(0,w-1)]:{swing:0,spread:0},b=g.offset?Fe(v,to(Qi(g.offset,s),k)):v,E=g.side??1,$=t.boneScale?.(e,g)??1,S=t.angles(e,g),x=[b],M=[];let T=k.swing,I=k.spread;g.bones.forEach((A,_)=>{const C=S[_]??{swing:0,spread:0};T+=ce(C.swing),I+=ce(C.spread)*E,M.push({swing:T,spread:I});const N=ne(to(g.rest,{swing:T,spread:I}),ce(C.yaw??0));x.push(Fe(x[_],Qi(N,A.length*s*$)))}),r[g.id]={joints3:x,frames:M}}const a=r[t.head.on],l=t.headPose?.(e)??{yaw:0,nod:0,tilt:0,sx:1,sy:1},c=a.frames[a.frames.length-1],h=t.head.size/2*s,u=h*l.sx,d=h*l.sy,f=g=>to(ne(Ta(Zi(g,-ce(l.tilt)),-ce(l.nod)),ce(l.yaw)),c),p=Fe(a.joints3[a.joints3.length-1],f([0,d,0]));return{height:s,root:o,chains:r,head:{center:p,rx:u,ry:d,toBody:f}}}function xa(t,e,n){const s=n.height,i=ce(90*(e.turn??0)),o=Ls(t,e,s),{root:r}=o,a=o.chains,{rx:l,ry:c}=o.head,h=o.head.toBody,u=o.head.center,d={};for(const M of t.chains){const{joints3:T,frames:I}=a[M.id],A=T.map(_=>eo(_,i));d[M.id]={id:M.id,joints3:T,frames:I,points:A.map(_=>_.point),depths:A.map(_=>_.depth)}}const f=eo(u,i),p=[[1,0,0],[0,1,0],[0,0,1]].map(M=>ne(h(M),i)),g=eo(r,i).point,m=ce(e.roll??0),w=M=>{const T=M.x-g.x,I=M.y-g.y;return{x:g.x+T*Math.cos(m)-I*Math.sin(m),y:g.y+T*Math.sin(m)+I*Math.cos(m)}},v=([M,T,I])=>[M*Math.cos(m)+T*Math.sin(m),-M*Math.sin(m)+T*Math.cos(m),I];for(const M of Object.values(d))M.points=M.points.map(w);const k={center:w(f.point),depth:f.depth,rx:l,ry:c,angle:0,axes:p.map(v)},b=k.axes[1];k.angle=Math.atan2(b[0],b[1]);const E=M=>{if("head"in M)return{x:k.center.x+b[0]*c,y:k.center.y-b[1]*c};const T=d[M.chain];return T.points[Math.min(M.joint,T.points.length-1)]};let $=0;(n.contact??"ground")==="ground"&&($=-Math.max(...t.contacts.map(M=>E(M).y))),$-=(e.lift??0)*s;const S=M=>({x:M.x,y:M.y+$});for(const M of Object.values(d))M.points=M.points.map(S);k.center=S(k.center);const x=t.contacts.map(M=>({spec:M,point:E(M)}));return{height:s,view:i,chains:d,head:k,hip:S(w(g)),hipDepth:eo(r,i).depth,contacts:x,groundY:Math.max(...x.map(M=>M.point.y))}}const Ea=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Bu=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function Ns(t,e,n){const s=n.height,i=ce(90*(e.turn??0)),o=ce(e.roll??0),r=Ls(t,e,s),a=ne(r.root,i),l=m=>Fe(Zi(Ea(ne(m,i),a),-o),a),c={};for(const m of t.chains)c[m.id]=r.chains[m.id].joints3.map(l);const h=l(r.head.center),u=m=>Bu(Ea(l(Fe(r.head.center,r.head.toBody(m))),h)),d=[u([1,0,0]),u([0,1,0]),u([0,0,1])],f=m=>{if("head"in m)return Fe(h,Qi(d[1],r.head.ry));const w=c[m.chain];return w[Math.min(m.joint,w.length-1)]};let p=0;(n.contact??"ground")==="ground"&&(p=-Math.min(...t.contacts.map(m=>f(m)[1]))),p+=(e.lift??0)*s;const g=m=>[m[0],m[1]+p,m[2]];return{height:s,hip:g(a),chains:Object.fromEntries(Object.entries(c).map(([m,w])=>[m,w.map(g)])),head:{center:g(h),rx:r.head.rx,ry:r.head.ry,axes:d}}}function no(t,e,n,s){const i=n.height,o=ce(90*(e.turn??0)),r=Ls(t,e,i),a=Ns(t,e,n),l=a.hip,c=a.chains,h=a.head.center,u=M=>{if("head"in M)return Fe(h,Qi(a.head.axes[1],a.head.ry));const T=c[M.chain];return T[Math.min(M.joint,T.length-1)]},d=s.toView(l),f=s.toScreen(d),p=s.toScreen([d[0]+1,d[1],d[2]]),g=Math.hypot(p.x-f.x,p.y-f.y),m=M=>{const T=s.toView(M);return{point:s.toScreen(T),depth:T[2]*g}},w={};for(const M of t.chains){const T=c[M.id].map(m);w[M.id]={id:M.id,joints3:r.chains[M.id].joints3,frames:r.chains[M.id].frames,points:T.map(I=>I.point),depths:T.map(I=>I.depth)}}const v=s.toView(h),k=s.toScreen(v),b=s.toScreen([v[0]+1,v[1],v[2]]),E=Math.hypot(b.x-k.x,b.y-k.y),$=a.head.axes.map(M=>Bu(Ea(s.toView(Fe(h,M)),v))),S={center:k,depth:v[2]*g,rx:r.head.rx*E,ry:r.head.ry*E,angle:Math.atan2($[1][0],$[1][1]),axes:$},x=t.contacts.map(M=>({spec:M,point:m(u(M)).point}));return{height:i*g,view:o,chains:w,head:S,hip:f,hipDepth:d[2]*g,contacts:x,groundY:Math.max(...x.map(M=>M.point.y))}}function so(t,[e,n,s]){const[i,o,r]=t.axes,a=[i[0]*e*t.rx+o[0]*n*t.ry+r[0]*s*t.rx,i[1]*e*t.rx+o[1]*n*t.ry+r[1]*s*t.rx,i[2]*e*t.rx+o[2]*n*t.ry+r[2]*s*t.rx],l=Math.hypot(e,n,s)||1,c=(i[2]*e+o[2]*n+r[2]*s)/l;return{point:{x:t.center.x+a[0],y:t.center.y-a[1]},depth:t.depth+a[2],facing:c}}const io=t=>t*180/Math.PI,an=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Aa=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Fn=t=>Math.hypot(t[0],t[1],t[2]),Pa=t=>{const e=Fn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},oo=t=>Math.atan2(Math.sin(t),Math.cos(t));function zu(t){const[e,n,s]=Pa(t);return{swing:Math.asin(Math.max(-1,Math.min(1,s))),spread:Math.atan2(e,-n)}}function ro(t,e,n,s,i){const o=t.chains.find(A=>A.id===n);if(!o)throw new Error(`reach: no chain ${n} in ${t.id}`);if(o.bones.length<2||o.rest[1]>-.99)throw new Error(`reach: ${n} is not a hanging limb of two bones or more`);if(!t.withAngles)throw new Error(`reach: the ${t.id} plan cannot set angles`);const r=xa(t,{...e,turn:0,roll:0,lift:0},{height:i.height,contact:"none"}),a=r.chains[n];if(Fn(an(s,a.joints3[2]))<i.height*1e-12)return e;const l=a.joints3[0],c=Fn(an(a.joints3[1],a.joints3[0])),h=Fn(an(a.joints3[2],a.joints3[1])),u=o.parent?r.chains[o.parent].frames[Math.max(0,(o.at??r.chains[o.parent].joints3.length-1)-1)]:{swing:0,spread:0},d=an(s,l),f=t.angles(e,o),p=A=>(f[A]?.yaw??0)*Math.PI/180,g=Math.min(c+h-1e-6,Math.max(Math.abs(c-h)+1e-6,Fn(d))),m=Pa(d),w=o.parent!==null,v=ne(to(o.pole??(w?[0,-.35,-1]:[0,0,1]),u),p(0));let k=an(v,[m[0]*Aa(v,m),m[1]*Aa(v,m),m[2]*Aa(v,m)]);Fn(k)<1e-6&&(k=ne([1,0,0],p(0))),k=Pa(k);const b=(c*c+g*g-h*h)/(2*c*g),E=Math.sqrt(Math.max(0,1-b*b)),$=[l[0]+c*(b*m[0]+E*k[0]),l[1]+c*(b*m[1]+E*k[1]),l[2]+c*(b*m[2]+E*k[2])],S=[l[0]+m[0]*g,l[1]+m[1]*g,l[2]+m[2]*g],x=o.side??1,M=zu(ne(an($,l),-p(0))),T=zu(ne(an(S,$),-p(1))),I=[{swing:io(oo(M.swing-u.swing)),spread:io(oo(M.spread-u.spread))*x},{swing:io(oo(T.swing-M.swing)),spread:io(oo(T.spread-M.spread))*x}];return t.withAngles(e,o,I)}const Dn=(t,e)=>(t%e+e)%e,qu=t=>t*t*(3-2*t),X2=t=>Object.fromEntries(["left","right"].flatMap(e=>Object.entries(Ct[t]).map(([n,s])=>[`hand.${e}.${n}`,s])));function $a(t,e=!1){const n=Ma(),s=ro(n,ht,"arm.left",[.015,.68,.2],{height:1}),i=ro(n,s,"arm.right",[-.015,.68,.2],{height:1});return Array.from({length:32},(o,r)=>{const a=r/4,l=Math.floor(a),c=a-l,h=l%2===0,u=Math.sin(Math.PI*c),d=Math.max(0,...t.map(p=>1-Math.min(Dn(a-p,8),Dn(p-a,8))/.5)),f={side:(h?1:-1)*5*Math.sin(Math.PI*c),bend:2+3*u,"head.tilt":(h?-1:1)*3*u,"head.nod":-2*u,"leg.left.swing":h?-4*u:17*u,"leg.right.swing":h?17*u:-4*u,"leg.left.knee":h?5*u:36*u,"leg.right.knee":h?36*u:5*u,"leg.left.spread":4,"leg.right.spread":4,"arm.left.swing":22+d*(e?45:42),"arm.right.swing":22+d*(e?45:42),"arm.left.spread":28-22*d,"arm.right.spread":28-22*d,"arm.left.elbow":48+22*d,"arm.right.elbow":48+22*d,"arm.left.bend":-35*d,"arm.right.bend":-35*d,smile:.9,...X2(e?"hold":"spread")};if(!e)for(const p of Object.keys(i))p.startsWith("arm.")&&(f[p]+=(i[p]-f[p])*d);return{beat:a,pose:f}})}const ln={garba:{label:"Garba · two clap",bpm:120,beats:8,strikes:[2,3,6,7],keys:$a([2,3,6,7])},garbaThreeClap:{label:"Garba · three clap",bpm:120,beats:8,strikes:[1,2,3,5,6,7],keys:$a([1,2,3,5,6,7])},dandiya:{label:"Dandiya · partner strikes",bpm:120,beats:8,strikes:[1,3,5,7],keys:$a([1,3,5,7],!0)}};function Yu(t){const e=typeof t=="string"&&Object.hasOwn(ln,t)?ln[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 Fs(t,e,n=ht){const s=Yu(t);if(!Number.isFinite(e))throw new Error("humanDanceFrame: beat must be finite");const i=Dn(e,s.beats);let o=s.keys.length-1;for(let m=0;m<s.keys.length;m++)s.keys[m].beat<=i&&(o=m);const r=s.keys[o],a=s.keys[(o+1)%s.keys.length],l=r.beat>i?r.beat-s.beats:r.beat,c=a.beat<=r.beat?a.beat+s.beats:a.beat,h=qu((i-l)/(c-r.beat)),u={...ht,...n};for(const m of new Set(s.keys.flatMap(w=>Object.keys(w.pose)))){if(m==="turn"||m==="roll")continue;const w=m.match(/^hand\.(?:left|right)\.(.+)$/)?.[1],v=n[m]??ht[m]??(w?Pt[w]:void 0)??0,k=r.pose[m]??v;u[m]=k+((a.pose[m]??v)-k)*h}const d=Math.floor(e),f=e-d,p=f<=.6?1:1-qu((f-.6)/.4),g=Math.max(0,...s.strikes.map(m=>1-Math.min(Dn(i-m,s.beats),Dn(m-i,s.beats))/.25));return{pose:u,contact:{side:Dn(d,2)===0?"left":"right",start:d,weight:p},strike:g}}function G2(t,e){const n=Yu(e.style),s=e.bpm??n.bpm,i=e.beats??n.beats,o=e.samplesPerBeat??16;if(![s,i,o].every(l=>Number.isFinite(l)&&l>0))throw new Error("humanDanceTracks: bpm, beats and samplesPerBeat must be positive and finite");if(!Number.isFinite(e.start??0))throw new Error("humanDanceTracks: start must be finite");const r=Math.max(1,Math.ceil(i*o)),a=Array.from({length:r+1},(l,c)=>({time:(e.start??0)+i*c/r*6e4/s,pose:Fs(n,i*c/r,e.pose).pose}));return Object.keys(a[0].pose).filter(l=>l!=="turn"&&l!=="roll"&&a.some(c=>c.pose[l]!==(e.pose?.[l]??ht[l]))).map(l=>({id:`${t}-dance-${l}`,target:t,property:l,keyframes:a.map(c=>({time:c.time,value:c.pose[l],easing:"linear"}))}))}function ju(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 c=0;c<=12;c++){const h=c*Math.PI/24;i.push([Math.sin(h),Math.cos(h)])}const o=[];for(const[c,h]of i)for(let u=0;u<40;u++){const d=u*Math.PI/20;o.push(so(t,[h*Math.cos(d),c,h*Math.sin(d)]).point)}let r=Ku(o);const a=Math.min(1,Math.max(0,e.jawRoundness??0));if(a===0)return r;const l=a*.25;for(let c=0;c<3;c++)r=r.flatMap((h,u)=>{const d=r[(u+1)%r.length];return[{x:h.x+(d.x-h.x)*l,y:h.y+(d.y-h.y)*l},{x:d.x+(h.x-d.x)*l,y:d.y+(h.y-d.y)*l}]});return r}function Ku(t){const e=t.sort((i,o)=>i.x-o.x||i.y-o.y),n=(i,o,r)=>(o.x-i.x)*(r.y-i.y)-(o.y-i.y)*(r.x-i.x),s=i=>{const o=[];for(const r of i){for(;o.length>=2&&n(o[o.length-2],o[o.length-1],r)<=0;)o.pop();o.push(r)}return o.slice(0,-1)};return[...s(e),...s([...e].reverse())]}const Xu=.34,Bt=.12,zt=-.4,qt=(t,e,n)=>t[e]??n,U2=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),V2=.45,J2=.35,Z2=.7;function St(t,e,n){const s=f=>Math.sqrt(Math.max(0,1-f.x*f.x-f.y*f.y)),i=so(t,[n.x,n.y,s(n)]).facing,o=t.axes[2],r=Math.atan2(o[0],o[2]),a=Math.cos(r),l=a>=0?1:-1,c=l*Math.max(J2,Math.abs(a)),h=l*Math.max(Z2,Math.abs(a)),u=Math.cos(t.angle),d=Math.sin(t.angle);return{facing:i,points:e.map(f=>{const p=V2*Math.sin(r)+n.x*c+(f.x-n.x)*h,g=f.y+o[1]*s(f),m=p*t.rx,w=g*t.ry;return{x:t.center.x+m*u+w*d,y:t.center.y+m*d-w*u}})}}const De=(t,e,n,s=12)=>Array.from({length:s+1},(i,o)=>{const r=o/s,a=1-r;return{x:a*a*t.x+2*a*r*e.x+r*r*n.x,y:a*a*t.y+2*a*r*e.y+r*r*n.y}}),Ds=(t,e,n,s)=>{const i=Math.min(1,Math.max(0,(s-t.x)/(n.x-t.x))),o=1-i;return o*o*t.y+2*o*i*e.y+i*i*n.y},ke=(t,e,n,s,i=16)=>Array.from({length:i},(o,r)=>{const a=Math.PI*2*r/i;return{x:t+Math.cos(a)*n,y:e+Math.sin(a)*s}}),cn=.05,Q2=.3,tk="#e06b7d";function ek(t,e,n,s,i={},o){const r=Math.max(1,Math.min(s*.6,.14*e.rx)),a=(A,_)=>St(e,A,_).points,l=(A,_)=>St(e,[],{x:A,y:_}).facing,c=qt(n,"smile",0),h=qt(n,"blink",0),u=qt(n,"lookX",0),d=qt(n,"lookY",0),f=qt(n,"browTilt",0),p=Math.max(.2,qt(n,"pupil",1)),g=Math.min(1,Math.max(0,qt(n,"lid",0))),m=Math.min(1,Math.max(0,qt(n,"bulge",0)));for(const A of[1,-1]){const _=A===1?"left":"right",C=Xu*A;if(l(C,Bt)<cn)continue;const N={x:C,y:Bt},B=U2(qt(n,`eye.${_}`,1),h);if(B<.2||i.style==="anime"&&g>=.98){const L=c>.5?.12:-.06;t.line(a(De({x:C-.12,y:Bt},{x:C,y:Bt+L},{x:C+.12,y:Bt}),N),r)}else if(i.style==="anime")nk(t,e,N,A,B,g,m,p,u,d,r,i,o);else{const L=B>1.2||m>.02,z=.13*Math.max(B,1)*(1+m*.7);L&&t.shape(a(ke(C,Bt,z*.85,z),N),"#ffffff",r);const O=(B>1.2?.075:.1)*p*(1+m*.3),P=C+u*.08,H=Bt-d*.07,W=ke(P,H,O,O*1.1*Math.min(B,1));if(t.shape(a(W,N),t.ink,0),i.inPupil&&o){const[q]=a([{x:P,y:H}],N),D=a(W,N),K=Math.min(...D.map(V=>Math.hypot(V.x-q.x,V.y-q.y)));K>.5&&(o.save(),o.beginPath(),o.arc(q.x,q.y,K,0,Math.PI*2),o.clip(),i.inPupil(o,{x:q.x,y:q.y,r:K,side:_}),o.restore())}if(g>.02){const q=L?z*1.15:O*1.4,D=Bt+q,K=D-q*2*g,V=q*1.1;t.shape(a([{x:C-V,y:D+.02},{x:C+V,y:D+.02},{x:C+V,y:K},{x:C-V,y:K}],N),i.skin??"#ffffff",0),t.line(a([{x:C-V,y:K},{x:C+V,y:K}],N),r)}}const G=Bt+(i.style==="anime"?.38:.3)+qt(n,`brow.${_}`,0)*.14+Math.max(0,B-1)*.12,Z={x:C+A*.13,y:G},Y={x:C-A*.13,y:G+f*.1};t.line(a([Z,{x:(Z.x+Y.x)/2,y:(Z.y+Y.y)/2},Y],{x:C,y:G}),r)}ik(t,e,n,r),sk(t,e,i.ageLines??0,r);const w={x:0,y:zt};if(l(0,zt)<-cn)return;i.nose&&l(0,Bt-.15)>=cn&&t.line(a([{x:.01,y:Bt-.1},{x:.03,y:zt+.2},{x:-.05,y:zt+.17}],{x:0,y:zt+.22}),r);const v=.25*Math.max(.3,qt(n,"mouthWidth",1)),k=Math.min(1,Math.max(0,qt(n,"mouth",0)));if(k<=.05){t.line(a(De({x:-v,y:zt},{x:0,y:zt-c*.25},{x:v,y:zt}),w),r);return}const b=.3*k;let E,$,S,x;if(c>.3){const A=zt+.05,_={x:0,y:zt-b*2};E=[...De({x:v,y:A},_,{x:-v,y:A})],$=()=>A,S=C=>Ds({x:v,y:A},_,{x:-v,y:A},C),x=.85}else if(c<-.3){const A=zt-b*.6,_={x:0,y:zt+b*1.4};E=[...De({x:v,y:A},_,{x:-v,y:A})],$=C=>Ds({x:v,y:A},_,{x:-v,y:A},C),S=()=>A,x=.5}else{const A=v*.8;E=ke(0,zt,A,b);const _=C=>b*Math.sqrt(Math.max(0,1-(C/A)**2));$=C=>zt+_(C),S=C=>zt-_(C),x=.5}if(t.shape(a(E,w),t.ink,0),k<Q2)return;const M=$(0)-S(0),T=v*x,I=(A,_,C=8)=>Array.from({length:C+1},(N,B)=>A+(_-A)*B/C);if(i.tongue){const A=T*.55,_=I(A,-A).map(N=>({x:N,y:S(N)})),C=De({x:-A,y:S(-A)},{x:0,y:S(0)+M*.8},{x:A,y:S(A)},8);t.shape(a([..._,...C.slice(1,-1)],w),tk,0)}if(i.teeth){const A=Math.min(.06,M*.4),_=I(-T,T).map(N=>({x:N,y:$(N)})),C=_.map(({x:N,y:B})=>({x:N*.92,y:B-A})).reverse();t.shape(a([..._,...C],w),"#ffffff",0);for(const N of[-.5,0,.5]){const B=T*N;t.line(a([{x:B,y:$(B)},{x:B*.92,y:$(B)-A}],w),r*.6)}}}function nk(t,e,n,s,i,o,r,a,l,c,h,u,d){const{x:f,y:p}=n,g=Math.min(1.2,Math.max(.5,u.eyeScale??1)),m=Math.min(1.2,Math.max(.45,u.eyeAspect??1)),w=.21*g*(1+r*.15),v=.25*g*m*Math.min(i,1.6)*(1-o)*(1+r*.3),k={x:f-w,y:p},b={x:f+w,y:p},E={x:f,y:p+v*1.9},$={x:f,y:p-v*1.35},S=De(k,E,b),x=De(b,$,k),M=G=>St(e,G,n).points,T=G=>G.map(Z=>{const Y=Math.min(b.x,Math.max(k.x,Z.x));return{x:Y,y:Math.min(Ds(k,E,b,Y),Math.max(Ds(b,$,k,Y),Z.y))}});t.shape(M([...S,...x.slice(1,-1)]),"#ffffff",h*.5);const I=f+Math.max(-1,Math.min(1,l))*.07*g,A=p-Math.max(-1,Math.min(1,c))*.055*g,_=.115*g,C=.185*g;t.shape(M(T(ke(I,A,_,C,24))),u.iris??"#4b7fce",h*.4),t.shape(M(T(ke(I,A-.075*g,_*.7,C*.35))),"rgba(255,255,255,0.25)",0);const N=Math.min(.085,.042*a)*g,B=T(ke(I,A,N,N*1.35));if(t.shape(M(B),t.ink,0),u.inPupil&&d){const[G]=M([{x:I,y:A}]),Z=Math.min(...M(B).map(Y=>Math.hypot(Y.x-G.x,Y.y-G.y)));Z>.5&&(d.save(),d.beginPath(),d.arc(G.x,G.y,Z,0,Math.PI*2),d.clip(),u.inPupil(d,{...G,r:Z,side:s===1?"left":"right"}),d.restore())}if(t.shape(M(T(ke(I-.038*g,A+.075*g,.035*g,.045*g))),"#ffffff",0),t.shape(M(T(ke(I+.04*g,A-.04*g,.014*g,.02*g))),"#ffffff",0),t.line(M(S),h*1.1),u.lashes!==!1)for(const G of[0,.035]){const Z=f+s*(w-G),Y=Ds(k,E,b,Z);t.line(M([{x:Z,y:Y},{x:Z+s*.055,y:Y+.07}]),h*.75)}}function sk(t,e,n,s){const i=Math.min(1,Math.max(0,n));if(!(i<=0))for(const o of[-1,1]){const r={x:o*.59,y:Bt};if(St(e,[],r).facing<cn)continue;for(const c of[-.06,.035]){const h=[{x:r.x,y:r.y},{x:r.x+o*.1,y:r.y+c}];t.line(St(e,h,r).points,s*.45*i)}const a={x:o*.3,y:-.38},l=De({x:a.x,y:-.31},{x:a.x+o*.07,y:-.4},{x:a.x+o*.035,y:-.49});t.line(St(e,l,a).points,s*.35*i)}}const Gu="#8fd0f5",Uu=(t,e,n)=>Array.from({length:18},(s,i)=>{const o=Math.PI*2*i/18,r=Math.sin(o/2);return{x:t+Math.sin(o)*n*r,y:e-n*.9+Math.cos(o)*n*1.6*(.55+.45*r)-n*.4}});function ik(t,e,n,s){const i=Math.min(1,Math.max(0,qt(n,"blush",0))),o=Math.min(1,Math.max(0,qt(n,"tears",0))),r=Math.min(1,Math.max(0,qt(n,"sweat",0)));if(!(i+o+r<=.01)){for(const a of[1,-1]){const l={x:.5*a,y:-.16},c=St(e,[],l).facing>=cn;if(i>.01&&c){const{points:u}=St(e,ke(l.x,l.y,.17,.1),l);if(t.shape(u,`rgba(240, 120, 140, ${(.75*i).toFixed(3)})`,0),i>.5)for(const d of[-.07,0,.07]){const f=[{x:l.x+d-.018,y:l.y-.03},{x:l.x+d+.018,y:l.y+.03}];t.line(St(e,f,l).points,s*.3)}}const h={x:Xu*a,y:Bt};if(o>.01&&St(e,[],h).facing>=cn){const u=.05+.04*o,d={x:h.x+.06*a,y:Bt-.2-.12*o};if(t.shape(St(e,Uu(d.x,d.y,u),d).points,Gu,s*.35),o>.6){const f=[{x:h.x+.05*a,y:Bt-.1},{x:d.x,y:d.y+u*.8}];t.line(St(e,f,d).points,s*.3)}}}if(r>.01){const a={x:.64,y:.42};St(e,[],a).facing>=cn&&t.shape(St(e,Uu(a.x,a.y,.05+.05*r),a).points,Gu,s*.35)}}}const ok=15;function pe(t,e){const n=Math.sqrt(Math.max(0,1-e*e));return[n*Math.sin(t),e,n*Math.cos(t)]}const rk=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function jt(t,[e,n,s]){const[i,o,r]=t.axes;return i[2]*e+o[2]*n+r[2]*s}function $t(t,e){return so(t,e).point}function ao(t,e){const n=Math.abs(t-e)%(Math.PI*2);return n>Math.PI?Math.PI*2-n:n}function lo(t,e,n=64){const s=e.top??1,i=e.bottom??-1,o=Math.max(8,Math.ceil((s-i)*ok)),r=p=>Math.min(s,Math.max(i,s-(s-i)*(p-1)/o)),a=p=>-Math.PI+Math.PI*2*p/n,l=(p,g)=>e.normal?e.normal(p,g):rk(e.position(p,g)),c=o+3,h=new Float64Array(n*c),u=new Float64Array(n*c);for(let p=0;p<c;p++){const g=p===0||p===c-1,m=r(p);for(let w=0;w<n;w++){const v=p*n+w;if(g){h[v]=-1;continue}const k=a(w);h[v]=e.inside(k,m),u[v]=h[v]>-.35?jt(t,l(k,m)):0}}const d=p=>(p%n+n)%n,f=p=>{const g=n+1,m=new Float64Array(g*c);for(let A=0;A<c;A++)for(let _=0;_<=n;_++){const C=A*n+(_===n?0:_);m[A*g+_]=Math.min(h[C],p*u[C])}const w=(A,_)=>m[_*g+A],v=(A,_,C,N)=>{const B=w(A,_),G=w(C,N),Z=B===G?.5:Math.min(1,Math.max(0,B/(B-G)));return $t(t,e.position(a(A+(C-A)*Z),r(_+(N-_)*Z)))},k=n*c*2,b=new Int32Array(k).fill(-1),E=new Int32Array(k).fill(-1),$=new Map,S=(A,_,C)=>{const N=(C*n+d(_))*2+(A?1:0);return $.has(N)||$.set(N,A?v(d(_),C,d(_),C+1):v(_,C,_+1,C)),N},x=(A,_)=>{b[A]===-1?b[A]=_:E[A]=_},M=(A,_)=>{x(A,_),x(_,A)};for(let A=0;A<c-1;A++)for(let _=0;_<n;_++){const C=A*g+_,N=(m[C]>0?8:0)|(m[C+1]>0?4:0)|(m[C+g+1]>0?2:0)|(m[C+g]>0?1:0);if(N===0||N===15)continue;const B=()=>S(!1,_,A),G=()=>S(!1,_,A+1),Z=()=>S(!0,_,A),Y=()=>S(!0,_+1,A);switch(N){case 1:case 14:M(Z(),G());break;case 2:case 13:M(G(),Y());break;case 3:case 12:M(Z(),Y());break;case 4:case 11:M(B(),Y());break;case 6:case 9:M(B(),G());break;case 7:case 8:M(Z(),B());break;case 5:case 10:{const L=(w(_,A)+w(_+1,A)+w(_+1,A+1)+w(_,A+1))/4>0;N===5===L?(M(Z(),B()),M(G(),Y())):(M(Z(),G()),M(B(),Y()));break}}}const T=[],I=new Uint8Array(k);for(const A of $.keys()){if(I[A])continue;const _=[];let C=-1,N=A;for(;N!==-1&&!I[N];){I[N]=1,_.push($.get(N));const B=b[N],G=E[N],Z=B!==-1&&B!==C&&!I[B]?B:G!==-1&&G!==C&&!I[G]?G:-1;C=N,N=Z}_.length>=3&&T.push(_)}return T};return{near:f(1),far:f(-1)}}const Vu=new WeakMap;function Ia(t,e,n){let s=Vu.get(t);s||Vu.set(t,s=new Map);let i=s.get(e);return i||s.set(e,i=n()),i}function Oa(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 Ju(t,e,n,s=.04){const i=[];let o=[];return e.forEach((r,a)=>{jt(t,n[a])>s?o.push($t(t,r)):(o.length>=2&&i.push(o),o=[])}),o.length>=2&&i.push(o),i}const Zu=t=>t*Math.PI/180,_a=t=>{const e=Math.hypot(...t)||1;return t.map(n=>n/e)},ak=(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 Qu(t,e,n){return t>=e+n?t:t<=e-n?e:e+(t-e+n)**2/(4*n)}function Ca(t,e,n){const s=_a(n),i=t.reduce((c,h,u)=>c+h*s[u],0),r=t.map((c,h)=>c-i*s[h]).reduce((c,h)=>c+h*h,0),a=Math.sqrt(Qu(1-r,e*e,e*e)),l=Qu(i,a,e)-i;return l===0?t:t.map((c,h)=>c+s[h]*l)}function lk(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 ck(t,e,n,s){const i=(t.path.length-1)/3,o=i*20,r=[],a=[],l=s.trail!==0||s.lift!==0,c=Math.max(0,e+n);for(let h=0;h<=o;h++){const u=h/o,d=Math.min(i-1,Math.floor(u*i)),f=u*i-d,p=1-f,g=[p**3,3*p*p*f,3*p*f*f,f**3],m=t.path.slice(d*3,d*3+4),w=Zu(m.reduce((C,N,B)=>C+N.around*g[B],0)),v=m.reduce((C,N,B)=>C+N.up*g[B],0),k=m.reduce((C,N,B)=>C+(N.lift??0)*g[B],0),b=1+e+n+k,E=v>=0?Math.sqrt(Math.max(0,1-v*v)):1,$=u*u*(t.follow??1),S=Zu(s.swing)*$,x=w-S,M=[Math.sin(x)*E*b,v*(v>=0?b:1),Math.cos(x)*E*b],T=[M[0],M[1]+s.lift*$,M[2]-s.trail*$],I=[Math.sin(x)*E,Math.max(0,v),Math.cos(x)*E],A=_a(M),_=l&&$>0?Ca(T,c,A):T;a.push(A),r.push({center:_,normal:I,left:_,right:_,t:u})}return r.forEach((h,u)=>{const d=r[Math.max(0,u-1)].center,p=r[Math.min(o,u+1)].center.map((w,v)=>w-d[v]),g=_a(ak(h.normal,p)),m=t.width*Math.sin(Math.PI*h.t)**.6*.5;h.left=h.center.map((w,v)=>w+g[v]*m),h.right=h.center.map((w,v)=>w-g[v]*m),l&&h.t>0&&(t.follow??1)>0&&(h.left=Ca(h.left,c,a[u]),h.right=Ca(h.right,c,a[u]))}),r}const Wn=(t,e,n)=>t.map((s,i)=>s+(e[i]-s)*n);function hk(t,e,n){const s=n?1:-1,i=[];let o=[];for(let r=0;r<e.length;r++){const a=e[r],l=s*jt(t,a.normal)>=0;if(r>0){const c=e[r-1],h=s*jt(t,c.normal),u=s*jt(t,a.normal);if(h>=0!==l){const d=h/(h-u),f={center:Wn(c.center,a.center,d),left:Wn(c.left,a.left,d),right:Wn(c.right,a.right,d),normal:Wn(c.normal,a.normal,d),t:c.t+(a.t-c.t)*d};l?o=[f]:(o.push(f),o.length>=2&&i.push(o),o=[])}}l&&o.push(a)}return o.length>=2&&i.push(o),i}function td(t,e,n,s,i,o,r){const a=(n.locks??[]).map(h=>ck(h,n.volume,s,i)),l=h=>h.reduce((u,d)=>u+jt(e,d.center),0)/h.length;a.sort((h,u)=>l(h)-l(u));const c=Math.max(.7,o*.35);for(const h of a)for(const u of hk(e,h,r)){const d=u.map(g=>$t(e,g.left)),f=u.map(g=>$t(e,g.right));if(t.shape([...d,...f.slice().reverse()],n.color,0),t.look==="clean"&&(n.shine??0)>0){const g=u.filter(m=>m.t>=.2&&m.t<=.75);if(g.length>=3){const m=g.map((v,k)=>{const b=.16*Math.sin(Math.PI*k/(g.length-1));return $t(e,Wn(v.center,v.left,.16+b))}),w=g.map(v=>$t(e,Wn(v.center,v.left,.16)));t.shape([...m,...w.reverse()],`rgba(255,255,255,${n.shine})`,0)}}const p=u.filter(g=>g.t>.3);p.length>=2&&t.line(p.map(g=>$t(e,g.left)),c)}}const Et=(t,e,n=0)=>({around:t,up:e,lift:n}),Ha=()=>[{width:.66,follow:.22,path:[Et(-38,.88),Et(-12,.94,.08),Et(58,.76,.09),Et(94,.16,.03)]},{width:.58,follow:.3,path:[Et(-42,.8),Et(-24,.7,.12),Et(18,.57,.09),Et(64,.3)]},{width:.36,follow:.18,path:[Et(-58,.76),Et(-76,.56,.07),Et(-90,.12,.06),Et(-102,-.36)]}];function ed(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?[Et(e,.7),Et(e+s*9,.2,.12),Et(e-s*13,-.5,.2),Et(e-s*8,-.95,.16),Et(e-s*3,-1.4,.12),Et(e+s*18,i+.35,.22),Et(e+s*12,i,.03)]:[Et(e,.7),Et(e+s*7,.15,.2),Et(e-s*8,-.75,.25),Et(e+s*5,i)]}})}const uk={softSweep:{volume:.12,shine:.16,part:-38,strands:"part",sweep:-.08,hairline:{front:.64,side:.12,back:-.8},locks:Ha()},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:[...ed(!1),...Ha()]},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:[...ed(!0),...Ha()]}},Bn={swing:0,trail:0,lift:0};function co(t){if(!t)return Bn;const e=t["hair.swing"]??0,n=t["hair.trail"]??0,s=t["hair.lift"]??0;return e===0&&n===0&&s===0?Bn:{swing:e,trail:n,lift:s}}const nd=t=>t.swing===0&&t.trail===0&&t.lift===0;function sd(t){return t.length>0||t.ties.some(e=>e.kind!=="bun")||(t.locks??[]).some(e=>(e.follow??1)>0)}function Ra([t,e,n],s){if(s===0)return[t,e,n];const i=Math.cos(s),o=Math.sin(s);return[t*i-n*o,e,n*i+t*o]}const id={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},od=1.75,La={...uk,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:od,opening:84,part:0,strands:"part",hairline:{front:.5,side:.05,back:-.85},coversEars:!0},shoulderWaves:{volume:.22,length:od,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}},me={black:"#22201f",brown:"#6b4630",chestnut:"#7b4a2b",auburn:"#9a4426",blond:"#d9b55a",ginger:"#c8662f",gray:"#a7a29c",white:"#ecebe7"};function rd(t){const e=typeof t=="string"?{style:t}:t,n=e.style?La[e.style]:{};if(e.style&&!n)throw new Error(`hair: unknown style '${e.style}'`);const{style:s,hairline:i,...o}=e,r={...id,...n,...o,hairline:{...id.hairline,...n.hairline,...i},ties:(o.ties??n.ties??[]).map(a=>({...a})),...o.spikes??n.spikes?{spikes:(o.spikes??n.spikes).map(a=>({...a}))}:{},...o.locks??n.locks?{locks:(o.locks??n.locks).map(lk)}:{},...o.fall??n.fall?{fall:{...o.fall??n.fall}}:{}};if(r.shine!==void 0&&(!Number.isFinite(r.shine)||r.shine<0||r.shine>1))throw new Error("hair: shine must be between 0 and 1");if(r.fall&&(!Number.isFinite(r.fall.taper)||r.fall.taper<0||r.fall.taper>1||!Number.isFinite(r.fall.wave)||r.fall.wave<0))throw new Error("hair: fall needs taper between 0 and 1 and nonnegative wave");return r}const hn=t=>t*Math.PI/180,zn=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},Na=t=>1-Math.abs(2*(t-Math.floor(t))-1);function Ws(t,e){const{front:n,side:s,back:i}=t.hairline,o=(n-i)/2,r=(n+i)/2,a=(r+s)/2,l=(r-s)/2,c=Math.max(0,Math.cos(e));let h=a+o*Math.cos(e)+l*Math.cos(2*e);return h-=t.sweep*Math.sin(e)*c,h+=t.recede*Math.exp(-(((Math.abs(e)-.75)/.32)**2)),(t.texture==="spiky"||t.texture==="curly")&&(h-=t.textureAmount*.6*Na(e*11/(Math.PI*2))*c),h}function ad(t,e,n){const s=t.textureAmount;switch(t.texture){case"spiky":return s*(Na(e*11/(Math.PI*2))*Na(n*2.6+.5))**1.2*zn(-.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 ld(t,e,n=Bn){const s=t.length>0,i=new Map,o=h=>{let u=i.get(h);return u===void 0&&i.set(h,u=Ws(t,h)),u},r=hn(t.opening),a=h=>t.length+(t.texture==="wavy"||t.texture==="curly"||t.texture==="locs"?.12*Math.sin(h*9):0)+(t.fall?.wave??0)*Math.cos(h*3+.6),l=(h,u,d)=>{if(t.flat<=0||u<.45)return null;const f=(u-.45)/.55,p=Math.sqrt(1-.45*.45)*d*(1-f**5),g=.45+(1+t.flat-.45)*Math.min(1,f*1.8);return[p*Math.sin(h),g*(1+e),p*Math.cos(h)]},c={top:1,bottom:s?-(t.length+.25+Math.abs(t.fall?.wave??0)):-1,inside(h,u){const d=u-o(h);if(!s)return d;const f=Math.min(u+a(h),ao(h,0)-r);return Math.max(d,f)},position(h,u){if(s&&u<0){const k=t.length<1.5?.14*zn(-t.length+.45,-t.length-.1,u):0,b=(t.fall?.taper??0)*zn(0,-Math.max(.1,a(h)),u),E=1+e+t.volume*(1-k*2.5)+ad(t,h,u)-k-b;return[E*Math.sin(h),u,E*Math.cos(h)]}const d=.4+.6*zn(0,.3,u-Ws(t,h)),f=1+e+(t.volume+ad(t,h,u))*d,p=l(h,u,f);if(p)return p;const[g,m,w]=pe(h,u),v=[g*f,m*f,w*f];if(t.quiff>0){const k=t.quiff*Math.exp(-((h/.7)**2))*zn(.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)]:pe(h,u)}};return s&&!nd(n)?dk(c,t,n):c}function dk(t,e,n){const s=o=>o<0?zn(-.15,-Math.max(.7,e.length),o):0,i=o=>hn(n.swing)*s(o);return{top:t.top,bottom:t.bottom,inside:(o,r)=>t.inside(o+i(r),r),position(o,r){const a=s(r);if(a===0)return t.position(o,r);const l=i(r),[c,h,u]=Ra(t.position(o+l,r),l);return[c,h+n.lift*a,u-n.trail*a]},normal:(o,r)=>Ra(t.normal(o+i(r),r),i(r))}}const fk=t=>t.texture==="spiky"||t.texture==="curly"||t.texture==="locs"?104:t.texture==="wavy"?80:64;function cd(t,e,n,s){return Ia(t,pk(e,s),()=>lo(t,n,fk(e)))}const hd=new WeakMap;let gk=1;function pk(t,e){if(nd(e))return t;let n=hd.get(t);return n||hd.set(t,n=gk++),`${n}:${e.swing}:${e.trail}:${e.lift}`}function ud(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 Fa(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 mk(t,e,n,s=16){return Array.from({length:s+1},(i,o)=>{const r=o/s,a=1-r;return{x:a*a*t.x+2*a*r*e.x+r*r*n.x,y:a*a*t.y+2*a*r*e.y+r*r*n.y}})}function yk(t,e,n,s,i){const o=t.ry,r=(e.length??1.8)*o,a=Fa(t,Ra(s,hn(i.swing))),l=Fa(t,[0,i.lift,-i.trail]),c=Math.hypot(a.x,a.y)||1,h=e.at==="high"||e.at==="low"||e.at==="top"?Fa(t,[.95,0,0]):{x:0},u=e.kind==="braid"?.15:.5,d={x:n.x+a.x/c*o*u+h.x*.9+l.x*.5,y:n.y+a.y/c*o*u*.6+l.y*.5},f={x:n.x+a.x/c*o*u*.6+h.x*1.3+l.x,y:n.y+r+l.y};return mk(n,d,f)}const ho=t=>Math.max(1,t*.5),dd=(t,e)=>Math.max(.8,Math.min(t*.4,.1*e.rx));function fd(t,e,n,s,i,o){const{point:r,out:a}=ud(s.at),l=1+n.volume,c=$t(e,[r[0]*l,r[1]*l,r[2]*l]),h=ho(i),u=dd(i,e);if(s.kind==="bun"){const g=s.size??.32,m=$t(e,[r[0]*l+a[0]*g,r[1]*l+a[1]*g,r[2]*l+a[2]*g]);t.ellipse(m.x,m.y,g*e.rx,g*e.ry,e.angle,n.color,h);const w=g*e.rx*.55;t.line(Array.from({length:9},(v,k)=>{const b=-.4+k/8*Math.PI*1.3;return{x:m.x+Math.cos(b)*w,y:m.y+Math.sin(b)*w*.8}}),u);return}const d=yk(e,s,c,a,o),f=(s.size??(s.kind==="braid"?.2:.34))*e.rx*2;if(s.kind==="ponytail")t.shape(Ft(d,f,f*.15),n.color,h),t.line(d.slice(3,d.length-3),u);else{const m=d.slice(0,d.length-3);for(let k=0;k<7;k++){const b=m[Math.floor(k/7*(m.length-1))],E=m[Math.floor((k+1)/7*(m.length-1))],$=Math.atan2(E.y-b.y,E.x-b.x),S=Math.hypot(E.x-b.x,E.y-b.y),x=f*(1-k/(7*2.2)),M=(k%2===0?1:-1)*.35,T={x:(b.x+E.x)/2,y:(b.y+E.y)/2};t.ellipse(T.x,T.y,S*.62,x*.5,$+M,n.color,h*.8)}const w=m[m.length-1],v=d[d.length-1];t.shape(Ft([w,v],f*.7,f*.2),n.color,h*.8)}const p=d[s.kind==="braid"?d.length-4:2];t.ellipse(p.x,p.y,f*.32,f*.22,e.angle,n.color,h)}function gd(t,e){return jt(t,ud(e.at).out)<-.2}function bk(t){const e=(i,o,r=0,a=14)=>Array.from({length:a+1},(l,c)=>{const h=c/a;return[i[0]+(o[0]-i[0])*h+r*Math.sin(Math.PI*h),i[1]+(o[1]-i[1])*h]}),n=hn(t.part??0),s=i=>Ws(t,i)+.04;switch(t.strands){case"part":return[e([n,s(n)],[n,.97])];case"sweep":{const i=Math.sign(t.sweep||-1),o=[.9,.72,.55].map((r,a)=>{const l=n+i*(.6+a*.35);return e([n,r],[l,Math.max(s(l)+.05,r-.35)],.05*i)});return[e([n,s(n)],[n,.97]),...o]}case"combed":return[-.75,-.35,.35,.75].map(i=>e([i,s(i)+.02],[i*.3,.86]));case"thin":return[-.5,.05,.6].map(i=>e([i,s(i)+.02],[i*.5,.95],.12));case"hanging":{const i=t.length>0?-t.length+.25:-.4,o=[-2.6,-2,-1.4,1.4,2,2.6,3.05].map(r=>e([r,Ws(t,r)<.9?.6:.9],[r,i],0));return t.part!==null&&o.push(e([n,s(n)],[n,.97])),o}default:return[]}}function wk(t,e,n,s,i){if(s.fill==="stipple"||s.hairline.front>1.5)return;const o=i.motion??Bn,r=i.lineWidth*.45/n.rx,{far:a}=cd(n,s,ld(s,r,o),o);Oa(e,n,()=>{for(const l of s.ties)gd(n,l)&&fd(t,n,s,l,i.lineWidth,o);md(t,n,s,i.lineWidth,r,!1);for(const l of a)t.shape(l,s.color,ho(i.lineWidth));td(t,n,s,r,o,i.lineWidth,!1)},i.headOutline)}function pd(t,e,n,s){if(n.hairline.front>1.5)return;const i=s.motion??Bn,o=s.lineWidth*.45/e.rx,r=ld(n,o,i),a=dd(s.lineWidth,e);if(n.fill==="stipple"){for(let h=.97;h>-1;h-=.17)for(let u=-Math.PI;u<Math.PI;u+=.27){const d=Math.round(h*100)%2*.13;if(r.inside(u+d,h)<.02)continue;const f=pe(u+d,h);if(jt(e,f)<.12)continue;const p=$t(e,f);t.dot(p.x,p.y,a*.4)}return}const{near:l}=cd(e,n,r,i),c=ho(s.lineWidth);md(t,e,n,s.lineWidth,o,!0);for(const h of l)t.shape(h,n.color,c);td(t,e,n,o,i,s.lineWidth,!0);for(const h of bk(n)){const u=h.map(([f,p])=>{const[g,m,w]=r.position(f,p);return[g*.985,m*.985,w*.985]}),d=h.map(([f,p])=>r.normal(f,p));for(const f of Ju(e,u,d,.12))t.line(f,a)}for(const h of n.ties)gd(e,h)||fd(t,e,n,h,s.lineWidth,i)}function md(t,e,n,s,i,o){for(const r of n.spikes??[]){const a=pe(hn(r.around),Math.max(-1,Math.min(1,r.up)));if(jt(e,a)>=0!==o)continue;const l=[Math.cos(hn(r.around)),0,-Math.sin(hn(r.around))],c=[a[1]*l[2],a[2]*l[0]-a[0]*l[2],-a[1]*l[0]],h=1+n.volume+i,u=Math.max(0,r.width),d=Math.max(0,r.length),f=[$t(e,a.map(p=>p*(h+d)))];for(let p=0;p<8;p++){const g=p*Math.PI/4,m=a.map((w,v)=>w*h+u*(l[v]*Math.cos(g)+c[v]*Math.sin(g)));f.push($t(e,m))}t.shape(Ku(f),n.color,ho(s))}}const yd=.35,Da=t=>({centre:[t*.98,-.02,-.08],out:[t,0,-.12]});function bd(t,e,n,s,i){const{centre:o,out:r}=Da(n),a=jt(e,r),l=Math.max(1,s.lineWidth*.55),c=s.skin==="none"?null:s.skin,h=e.ry*.27;if(!i){const m=$t(e,[o[0]*1.06,o[1],o[2]]);t.ellipse(m.x,m.y,e.rx*.17,h,e.angle,c,l);return}const u=$t(e,o),d=e.rx*(.12+.08*a);t.ellipse(u.x,u.y,d,h,e.angle,c,l);const f=Math.cos(e.angle),p=Math.sin(e.angle),g=Array.from({length:9},(m,w)=>{const v=-Math.PI*.55+w/8*Math.PI*1.1,k=Math.cos(v)*d*.45*-n,b=Math.sin(v)*h*.55;return{x:u.x+k*f-b*p,y:u.y+k*p+b*f}});t.line(g,Math.max(.8,l*.7))}function kk(t,e,n,s){Oa(e,n,()=>{for(const i of[1,-1])jt(n,Da(i).out)<yd&&bd(t,n,i,s,!1)},s.headOutline)}function vk(t,e,n){for(const s of[1,-1])jt(e,Da(s).out)>=yd&&bd(t,e,s,n,!0)}const Wa={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 wd(t,e){const n=typeof t=="string"?{style:t}:t,s=n.style?Wa[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 We=t=>t*Math.PI/180,uo=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},kd={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}},Mk=(t,e)=>{const n=uo(We(48),We(100),ao(e,0));return t.top[0]+(t.top[1]-t.top[0])*n},Sk=t=>t==="sideburns"||t==="muttonChops";function Ba(t,e){const n=kd[t];if(!n)return null;const s=We(n.reach),i=o=>{const r=ao(o,0);return n.shape==="point"?Math.exp(-((r/.42)**2)):n.shape==="square"?1-uo(We(45),We(85),r):Math.cos(Math.min(r,Math.PI/2))**.7};return{top:Math.max(n.top[0],n.top[1])+.05,bottom:-1,inside(o,r){const a=ao(o,0),l=Mk(n,o);let c=Math.min(l-r,s-a);if(n.band>0&&(c=Math.min(c,r-(l-n.band))),Sk(t)){const h=t==="muttonChops"?We(70)-We(22)*uo(.08,-.6,r):We(72);c=Math.min(c,a-h)}return c},position(o,r){const[a,l,c]=pe(o,r),h=1+e+n.volume,u=n.length*i(o)*uo(-.45,-1,r);return[a*h,l*h-u,c*h+u*.25]},normal:(o,r)=>pe(o,r)}}function Tk(t){const n=s=>s.map(([i,o])=>({x:i,y:-.24+o}));switch(t){case"short":return n([[-.17,-.02],[-.1,.04],[0,.03],[.1,.04],[.17,-.02],[.08,-.05],[0,-.03],[-.08,-.05]]);case"chevron":return n([[-.28,-.1],[-.16,.05],[0,.07],[.16,.05],[.28,-.1],[.12,-.08],[0,-.06],[-.12,-.08]]);case"walrus":return n([[-.38,-.2],[-.3,.02],[-.12,.09],[0,.07],[.12,.09],[.3,.02],[.38,-.2],[.2,-.13],[0,-.11],[-.2,-.13]]);case"handlebar":return n([[-.24,-.03],[-.12,.04],[0,.03],[.12,.04],[.24,-.03],[.1,-.05],[0,-.03],[-.1,-.05]]);default:return null}}const Bs=t=>Math.max(1,t*.45);function xk(t,e,n,s){for(let i=.1;i>-1;i-=.13)for(let o=-Math.PI/1.7;o<Math.PI/1.7;o+=.2){const r=Math.round(i*100)%2*.1;if(n.inside(o+r,i)<.02)continue;const a=pe(o+r,i);if(jt(e,a)<.15)continue;const l=$t(e,a);t.dot(l.x,l.y,s)}}function Ek(t,e,n,s,i){const o=s.beard==="stubble"?null:Ba(s.beard,i.lineWidth*.45/n.rx);if(!o)return;const{far:r}=Ia(n,s,()=>lo(n,o));Oa(e,n,()=>{for(const a of r)t.shape(a,s.color,Bs(i.lineWidth))},i.headOutline)}function Ak(t,e,n,s,i){if(n.beard==="none")return;const o=s.lineWidth*.45/e.rx;if(n.beard==="stubble"){xk(t,e,Ba("full",o),Math.max(.5,s.lineWidth*.09));return}if(n.beard==="soulPatch"){const l=[{x:-.05,y:-.55},{x:.05,y:-.55},{x:0,y:-.68}],{points:c,facing:h}=St(e,l,{x:0,y:-.6});h>-.05&&t.shape(c,n.color,Bs(s.lineWidth)*.7);return}const r=Ba(n.beard,o);if(!r)return;const{near:a}=Ia(e,n,()=>lo(e,r));for(const l of a)t.shape(l,n.color,Bs(s.lineWidth));if(kd[n.beard]?.aroundMouth){const l=.27*Math.max(.3,i),c=Array.from({length:20},(d,f)=>{const p=Math.PI*2*f/20;return{x:Math.cos(p)*l,y:-.42+Math.sin(p)*.13}}),{points:h,facing:u}=St(e,c,{x:0,y:-.42});u>-.05&&t.shape(h,s.skin==="none"?"#ffffff":s.skin,0)}}function Pk(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}=St(e,l,i);h>-.05&&t.line(c,Math.max(1,s.lineWidth*.32));return}const o=Tk(n.moustache);if(!o)return;const{points:r,facing:a}=St(e,o,i);if(!(a<=-.05)&&(t.shape(r,n.color,Bs(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(St(e,c,i).points,Bs(s.lineWidth)*.8)}}const za={round:!0,square:!0,sunglasses:!0};function vd(t){const n=(typeof t=="string"?{style:t}:t).style??"round";if(!(n in za))throw new Error(`glasses: unknown style '${n}'`);return{style:n}}const Md=.34,ye=.12,$k=.05;function Ik(t,e){return Array.from({length:28},(s,i)=>{const o=Math.PI*2*i/28;if(t==="round")return{x:e+Math.cos(o)*.2,y:ye+Math.sin(o)*.19};const r=Math.cos(o),a=Math.sin(o),l=t==="sunglasses"?.22:.21,c=t==="sunglasses"?.17:.16;return{x:e+Math.sign(r)*Math.abs(r)**.45*l,y:ye-.01+Math.sign(a)*Math.abs(a)**.45*c}})}function Ok(t,e,n,s){const i=Math.max(1,Math.min(s.lineWidth*.5,.11*e.rx)),o=[];for(const r of[1,-1]){const a=Md*r,{points:l,facing:c}=St(e,Ik(n.style,a),{x:a,y:ye});if(c<$k)continue;o.push(r),t.shape(l,n.style==="sunglasses"?"#1f2328":null,i);const h=[r*.97,ye+.02,-.1];if(jt(e,[r,0,0])>.15){const u=St(e,[{x:a+r*.21,y:ye+.02}],{x:a,y:ye}).points[0];t.line([u,$t(e,h)],i*.9)}}if(o.length===2){const r=[{x:Md-.2,y:ye+.02},{x:0,y:ye+.07},{x:-.14,y:ye+.02}];t.line(St(e,r,{x:0,y:ye}).points,i)}}const fo={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 Sd(t){const e=typeof t=="string"?{style:t}:t,n=e.style??"cap",s=fo[n];if(!s)throw new Error(`hat: unknown style '${n}'`);return{style:n,color:e.color??s.color}}const un=(t,e)=>t.brim[1]+(t.brim[0]-t.brim[1])*(1+Math.cos(e))/2;function _k(t,e){return{top:1,bottom:Math.min(...t.brim)-.05,inside:(n,s)=>s-un(t,n),position(n,s){const[i,o,r]=pe(n,s),a=un(t,n),l=s>a?(o-a)*(t.height-1):0;return[i*e,o*e+l,r*e]},normal:(n,s)=>pe(n,s)}}function Ck(t,e,n){const i=(o,r,a)=>{const l=un(e,o)*n-a;return[Math.sin(o)*r,l,Math.cos(o)*r]};if(e.peak){const o=[],r=[];for(let a=0;a<=24;a++){const l=(-80+160*a/24)*(Math.PI/180),c=e.peak*Math.cos(l)**.6;o.push($t(t,[Math.sin(l)*(n+c*.25),un(e,l)*n-.07*Math.cos(l),Math.cos(l)*(n+c)])),r.push($t(t,i(l,n,0)))}return[...o,...r.reverse()]}return e.ring?Array.from({length:48},(o,r)=>$t(t,i(Math.PI*2*r/48,n+e.ring,.07))):null}function Hk(t){const e=s=>Array.from({length:13},(i,o)=>[s,un(t,s)+(.97-un(t,s))*o/12]),n=s=>Array.from({length:49},(i,o)=>{const r=-Math.PI+Math.PI*2*o/48;return[r,un(t,r)+s]});switch(t.detail){case"seams":return[e(.55),e(-.55)];case"fold":return[n(.2)];case"ridge":return[e(0),e(Math.PI)];case"band":return[n(.12)]}}function Td(t,e,n,s){const i=fo[n.style],r=1+s.lineWidth*.45/e.rx+Math.max(.05,Math.min(.3,s.hairVolume)+.04),a=Math.max(1,s.lineWidth*.5),l=Ck(e,i,r);l&&t.shape(l,n.color,a);const c=_k(i,r),{near:h,far:u}=lo(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 Hk(i)){const p=f.map(([m,w])=>{const[v,k,b]=c.position(m,w);return[v*.99,k*.99,b*.99]}),g=f.map(([m,w])=>pe(m,w));for(const m of Ju(e,p,g,.1))t.line(m,d)}if(i.detail==="seams"){const f=$t(e,[0,r*1.01,0]);t.dot(f.x,f.y,a*.9)}}function xd(t){const e=t.hair?rd(t.hair):null;return{hair:e,facialHair:t.facialHair?wd(t.facialHair,e?.color):null,glasses:t.glasses?vd(t.glasses):null,hat:t.hat?Sd(t.hat):null,ears:t.ears??!1}}const Ed=t=>!t.hair&&!t.facialHair&&!t.glasses&&!t.hat&&!t.ears,Ad=t=>t.axes[2][2]<-.3,Pd=t=>t.ears&&!t.hair?.coversEars;function $d(t,e,n,s,i,o){if(Ed(n))return;const r={...o,headOutline:o.face?.shape==="angular"?ju(s,o.face):void 0};n.hair&&wk(e,t,s,n.hair,{...r,motion:co(i)}),n.facialHair&&Ek(e,t,s,n.facialHair,r),Pd(n)&&kk(e,t,s,r)}function Rk(t,e,n,s,i,o,r){if(Ed(n)){r();return}const a=Ad(s);Pd(n)&&vk(e,s,o),n.hair&&!a&&pd(e,s,n.hair,{...o,motion:co(i)}),n.facialHair&&Ak(e,s,n.facialHair,o,i.mouthWidth??1),r(),n.facialHair&&Pk(e,s,n.facialHair,o),n.glasses&&Ok(e,s,n.glasses,o),n.hat&&!a&&Td(e,s,n.hat,{lineWidth:o.lineWidth,hairVolume:n.hair?.volume??0})}function Id(t,e,n,s,i,o){Ad(s)&&(n.hair&&pd(e,s,n.hair,{...o,motion:co(i)}),n.hat&&Td(e,s,n.hat,{lineWidth:o.lineWidth,hairVolume:n.hair?.volume??0}))}const Od=40,Lk=.215+.205,Jt=(t,e)=>{const n={};for(const s of["left","right"])for(const[i,o]of Object.entries(e))n[`${t}.${s}.${i}`]=o;return n},ft=(t,e)=>t[e]??ht[e]??0;function qa(t,e,n=ht,s=1){const i=Os(t),o=e*Math.PI*2,r=Math.sin(o)*s,a=Math.cos(o)*s,l=(1+Math.cos(o*2*(i.bounces??1)))/2,c=i.crouch??0,h=i.shoulder??0,u=i.forearm??0,d={...ht,...n};d["leg.left.swing"]=i.swing*r+c*.6,d["leg.right.swing"]=-i.swing*r+c*.6,d["leg.left.knee"]=i.knee*Math.max(0,a)+c*1.2,d["leg.right.knee"]=i.knee*Math.max(0,-a)+c*1.2,d["leg.left.ankle"]=ft(n,"leg.left.ankle")-(i.tiptoe??0),d["leg.right.ankle"]=ft(n,"leg.right.ankle")-(i.tiptoe??0);for(const[f,p]of[["left",-1],["right",1]])ft(n,`arm.${f}.spread`)>Od||ft(n,`arm.${f}.swing`)>Od||(d[`arm.${f}.swing`]=h+p*i.arm*r,d[`arm.${f}.elbow`]=ft(n,`arm.${f}.elbow`)+u+i.elbow*Math.max(0,p*r));return d.lean=ft(n,"lean")+i.lean*s,d.bend=ft(n,"bend")+(i.bend??0),d["head.nod"]=ft(n,"head.nod")-i.lean*.5*s+(i.headTilt??0),d.side=ft(n,"side")+(i.sway??0)*Math.sin(o),d.lift=ft(n,"lift")+(i.bounce??0)*s*l,d.stretch=ft(n,"stretch")*(1+(i.squash??0)*(l-.5)),d}function Ya(t,e,n=1,s=1){const i=Os(t);return 4*Lk*s*e*Math.sin(i.swing*n*Math.PI/180)}const qn=t=>Sa[t],go={take:t=>[{after:140,pose:{stretch:.8,bend:10,lean:ft(t,"lean")-4,...Jt("arm",{spread:6,swing:0,elbow:10}),"eye.left":.35,"eye.right":.35,"brow.left":-.6,"brow.right":-.6,mouth:0},easing:"ease-in-out"},{after:260,pose:{stretch:.78}},{after:360,pose:{lift:.22,stretch:1.35,bend:-14,...Jt("arm",{spread:150,bend:35,swing:0,elbow:0}),...Jt("leg",{swing:25,knee:60}),...qn("shocked")},easing:"ease-out-cubic"},{after:720,pose:{lift:.25,stretch:1.25,bend:-10,...Jt("arm",{spread:140})},easing:"ease-in-out"},{after:900,pose:{lift:0,stretch:.74,bend:12,...Jt("arm",{spread:70,bend:0}),...Jt("leg",{swing:30,knee:60})},easing:"ease-in-quad"},{after:1060,pose:{stretch:1.06,bend:-3,...Jt("arm",{spread:60}),"leg.left.swing":ft(t,"leg.left.swing"),"leg.right.swing":ft(t,"leg.right.swing"),"leg.left.knee":ft(t,"leg.left.knee"),"leg.right.knee":ft(t,"leg.right.knee")},easing:"ease-out"},{after:1260,pose:{stretch:ft(t,"stretch"),bend:ft(t,"bend"),...qn("surprised"),...Jt("arm",{spread:55,bend:60})},easing:"ease-in-out"}],doubleTake:t=>[{after:160,pose:{lookX:1,lookY:0,"head.turn":0},easing:"ease-out"},{after:520,pose:{lookX:-.6,"head.turn":30,"head.nod":ft(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":ft(t,"head.nod")-10,bend:ft(t,"bend")-10,lift:.05,stretch:1.18,...qn("shocked"),lookX:1,lookY:0},easing:"ease-out-cubic"},{after:1360,pose:{lift:0,stretch:.88,"head.nod":ft(t,"head.nod")-4,bend:ft(t,"bend")+4},easing:"ease-in-quad"},{after:1560,pose:{stretch:ft(t,"stretch"),"head.nod":ft(t,"head.nod"),bend:ft(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,...qn("angry"),lookX:1},easing:"ease-out"},{after:620,pose:{lean:-20,bend:-18,stretch:.9}},{after:700,pose:{lean:28,bend:14,"head.nod":6,"arm.left.swing":-30,"arm.right.swing":60,"leg.left.swing":-20,"leg.left.knee":30,"leg.right.swing":20,stretch:1.12},easing:"ease-out-cubic"}],land:t=>[{after:120,pose:{lift:0,stretch:.7,bend:14,...Jt("arm",{spread:75}),...Jt("leg",{swing:25,knee:50})},easing:"ease-in-quad"},{after:300,pose:{stretch:1.05,bend:-4,"arm.left.spread":ft(t,"arm.left.spread"),"arm.right.spread":ft(t,"arm.right.spread")},easing:"ease-out"},{after:460,pose:{lift:0,stretch:ft(t,"stretch"),bend:ft(t,"bend"),...Jt("leg",{swing:0,knee:0})},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...qn("scared"),...Jt("arm",{swing:40,elbow:110,spread:14}),stretch:.94,bend:ft(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:ft(t,"side")+2.5*s,"head.tilt":ft(t,"head.tilt")-2*s}})}return e.push({after:755,pose:{side:ft(t,"side"),"head.tilt":ft(t,"head.tilt"),bend:ft(t,"bend")}}),e},deflate:t=>[{after:260,pose:{stretch:1.04,"head.nod":ft(t,"head.nod")-4,"brow.left":.3,"brow.right":.3},easing:"ease-in-out"},{after:900,pose:{...qn("sad"),bend:18,stretch:.92,lean:ft(t,"lean")+5,"head.nod":14,...Jt("arm",{spread:6,swing:0,elbow:4,bend:0})},easing:"ease-in-out"}]};function _d(t,e){const n=bt(e.from??{}),s=e.speed??1;let i=n;return[{time:e.at,pose:n},...go[t](n).map(o=>(i={...i,...o.pose},{time:e.at+o.after*s,pose:i,act:!1,...o.easing?{easing:o.easing}:{}}))]}function Cd(t,e=ht){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 Hd(t,e=ht){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 ja={sweeping:Cd,brushing:Hd};function Nk(t,e,n=ht){const s=ja[t];if(!s)throw new Error(`humanCyclePose: ${dt("cycle",t,Object.keys(ja))}`);return s(e,n)}const Fk={apron:"#d8b48a",labCoat:"#f4f6f8",hoodie:"#6b7280",cardigan:"#6b8e4e",overalls:"",sari:"#16a34a"},Ka=(t,e,n)=>t.slice(Math.floor((t.length-1)*e),Math.ceil((t.length-1)*n)+1),mt=(t,e,n)=>({x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n});function Dk(t){return t.parts["leg.left"].order>t.parts["leg.right"].order?"left":"right"}const Rd=t=>Math.max(t.parts["leg.left"].order,t.parts["leg.right"].order)>t.parts.spine.order,se=t=>Math.cos(t.turn*Math.PI/2);function Ld(t={}){const e=t.shirt??"#e2493b",n=t.trousers??"#24476b",s=t.sleeves??"short",i=t.bottom??"trousers",o=t.over==="labCoat",r=t.over==="hoodie",a=t.over==="cardigan",l=t.over==="overalls",c=t.over==="sari",h=t.overColor??(t.over&&t.over!=="overalls"?Fk[t.over]:n),u=t.shoes==="boots",d=t.shoeColor??"#3b2a1e",f=O=>O.lineWidth*.45,p=(O,P,H)=>{const W=O.parts[`leg.${H}`].points;if(!(i==="skirt"&&!l)){if(i==="shorts"&&!l){const q=Ka(W,0,.5);P.shape(Ft(q,O.height*.085,O.height*.07),n,f(O));return}P.shape(Ft(W,O.height*.08,O.height*.05),n,f(O))}},g=(O,P,H)=>{const W=O.parts[`leg.${H}`].points,q=Ka(W,.7,1);if(q.length<2)return;P.shape(Ft(q,O.height*.075,O.height*.07),d,f(O));const D=q[0],K=q[1],V=K.x-D.x,F=K.y-D.y,X=Math.hypot(V,F)||1,j=O.height*.04;P.line([{x:D.x-F/X*j,y:D.y+V/X*j},{x:D.x+F/X*j,y:D.y-V/X*j}],f(O)*.9)},m=O=>{const P=O.chains.spine,H=P[0],W=P[P.length-1],q={x:H.x-(W.x-H.x)*.25,y:H.y-(W.y-H.y)*.25};return{hip:H,top:W,below:q,line:[q,...O.parts.spine.points]}},w=O=>{const P=r?1.14:1,H=Math.hypot(O.points["hip.left"].x-O.points["hip.right"].x,O.points["hip.left"].y-O.points["hip.right"].y),W=Math.max(O.height*.15*P,H+Math.max(O.height*.08,O.lineWidth*1.45)+f(O));return Ft(m(O).line,W,O.height*.14*P)},v=(O,P)=>{const H=[w(P)],{top:W,hip:q}=m(P);a&&H.push(Ft([W,mt(W,q,.5),mt(W,q,1.08)],P.height*.155,P.height*.15)),o&&H.push(Ft([W,mt(W,q,.5),q],P.height*.14,P.height*.15));const D=Object.values(P.points),K=Math.min(...D.map(j=>j.x))-P.height,V=Math.min(...D.map(j=>j.y))-P.height,F=Math.max(...D.map(j=>j.x))+P.height,X=Math.max(...D.map(j=>j.y))+P.height;for(const j of H){O.beginPath(),O.rect(K,V,F-K,X-V),O.moveTo(j[0].x,j[0].y);for(const Q of j.slice(1))O.lineTo(Q.x,Q.y);O.closePath(),O.clip("evenodd")}},k=(O,P)=>{const H=r?h:e;P.shape(w(O),H,f(O))},b=(O,P)=>{const H=se(O),{top:W,hip:q}=m(O),D=O.height*.07,K={x:(W.x-q.x)*.16,y:(W.y-q.y)*.16};if(H>=0){P.shape([{x:W.x-D,y:W.y+K.y*.25},{x:W.x-D*.8+K.x,y:W.y+K.y},{x:W.x+K.x*1.2,y:W.y+K.y*1.35},{x:W.x+D*.8+K.x,y:W.y+K.y},{x:W.x+D,y:W.y+K.y*.25}],h,f(O));return}const V=mt(W,q,.42);P.shape([{x:W.x-D*.9,y:W.y},{x:W.x+D*.9,y:W.y},{x:V.x+D*.7,y:V.y},{x:V.x,y:V.y+O.height*.02},{x:V.x-D*.7,y:V.y}],h,f(O))},E=(O,P)=>{const H=se(O);if(H<.2)return;const{top:W,hip:q}=m(O),D=Math.sin(O.turn*Math.PI/2)*O.height*.03,K=O.height*.06*H,V=mt(W,q,.62),F=mt(W,q,.9);P.line([{x:V.x+D-K,y:V.y},{x:F.x+D-K*1.1,y:F.y}],f(O)*.7),P.line([{x:V.x+D+K,y:V.y},{x:F.x+D+K*1.1,y:F.y}],f(O)*.7);const X=mt(W,q,.1);for(const j of[-1,1])P.line([{x:X.x+D+j*K*.2,y:X.y},{x:X.x+D+j*K*.35,y:X.y+O.height*.07}],f(O)*.6)},$=(O,P)=>{const{top:H,hip:W}=m(O),q=se(O);if(P.shape(Ft([H,mt(H,W,.5),mt(H,W,1.08)],O.height*.155,O.height*.15),h,f(O)),q<.2)return;const D=Math.sin(O.turn*Math.PI/2)*O.height*.03,K=O.height*.02*q,V=mt(H,W,.12),F=mt(H,W,1.05);P.shape([{x:V.x+D-K,y:V.y},{x:V.x+D+K,y:V.y},{x:F.x+D+K*1.3,y:F.y},{x:F.x+D-K*1.3,y:F.y}],e,f(O)*.7);for(const X of[.35,.55,.75]){const j=mt(H,W,X);P.dot(j.x+D+K*1.6,j.y,f(O)*1.2)}},S=(O,P)=>{const H=se(O),{top:W,hip:q}=m(O),D=Math.sin(O.turn*Math.PI/2)*O.height*.04,K=mt(q,W,.12),V=mt(q,W,.74);if(H<.15){if(H<-.3){const Q=O.points["shoulder.left"],et=O.points["shoulder.right"];P.line([Q,{x:K.x+O.height*.03,y:K.y}],f(O)*.8),P.line([et,{x:K.x-O.height*.03,y:K.y}],f(O)*.8)}return}const F=O.height*.07*H;P.shape([{x:V.x+D-F*.75,y:V.y},{x:V.x+D+F*.75,y:V.y},{x:K.x+D+F*1.1,y:K.y},{x:K.x+D-F*1.1,y:K.y}],n,f(O));for(const Q of["left","right"]){const et=O.points[`shoulder.${Q}`],rt={x:V.x+D+(et.x>V.x+D?1:-1)*F*.55,y:V.y};P.line([rt,{x:et.x+(rt.x-et.x)*.15,y:et.y+(rt.y-et.y)*.15}],f(O)*1.6)}const X=mt(V,K,.3),j=F*.4;P.line([{x:X.x+D-j,y:X.y},{x:X.x+D-j,y:X.y+j*1.4},{x:X.x+D+j,y:X.y+j*1.4},{x:X.x+D+j,y:X.y}],f(O)*.6)},x=(O,P)=>{const{hip:H,top:W}=m(O),q=mt(H,W,.2),D=[O.points["ankle.left"],O.points["ankle.right"]],K=mt(H,{x:(D[0].x+D[1].x)/2,y:(D[0].y+D[1].y)/2},.98),V=O.height*.075,F=Math.max(O.height*.12,Math.abs(D[0].x-D[1].x)/2+O.height*.07),X=K.x-q.x,j=K.y-q.y,Q=Math.hypot(X,j)||1,et={x:-j/Q,y:X/Q};if(P.shape([{x:q.x+et.x*V,y:q.y+et.y*V},{x:K.x+et.x*F,y:K.y+et.y*F},{x:K.x-et.x*F,y:K.y-et.y*F},{x:q.x-et.x*V,y:q.y-et.y*V}],h,f(O)),se(O)>.2){const at=Math.sin(O.turn*Math.PI/2)*O.height*.03;for(const R of[-.35,0,.35]){const J=V*.5*R,nt=F*.45*R;P.line([{x:q.x+at+et.x*J,y:q.y+et.y*J+O.height*.02},{x:K.x+at+et.x*nt,y:K.y+et.y*nt}],f(O)*.5)}}},M=(O,P)=>{const H=se(O),{top:W,hip:q}=m(O),D=Math.sin(O.turn*Math.PI/2),K=D>=0?"left":"right",V=K==="left"?"right":"left",F=O.points[`shoulder.${K}`],X=O.height*.035;if(H<.15){const et=mt(W,q,.9);P.shape(Ft([F,{x:et.x+(F.x-W.x)*.5,y:et.y}],X*2.2,X*2.6),h,f(O));return}const j={x:q.x+(O.points[`hip.${V}`].x-q.x)*1.2,y:mt(q,W,.08).y};P.shape(Ft([j,mt(j,F,.5),F],X*2.4,X*2),h,f(O));const Q={x:F.x-(q.x-F.x)*.05-D*O.height*.03,y:F.y+O.height*.16};P.shape(Ft([F,Q],X*2,X*1.6),h,f(O))},T=(O,P)=>{const{hip:H,top:W}=m(O),q=mt(H,W,.18),D=[O.points["knee.left"],O.points["knee.right"]],K=mt(H,{x:(D[0].x+D[1].x)/2,y:(D[0].y+D[1].y)/2},1.05),V=O.height*.075,F=Math.max(O.height*.13,Math.abs(D[0].x-D[1].x)/2+O.height*.08),X=K.x-q.x,j=K.y-q.y,Q=Math.hypot(X,j)||1,et={x:-j/Q,y:X/Q};P.shape([{x:q.x+et.x*V,y:q.y+et.y*V},{x:K.x+et.x*F,y:K.y+et.y*F},{x:K.x-et.x*F,y:K.y-et.y*F},{x:q.x-et.x*V,y:q.y-et.y*V}],n,f(O))},I=(O,P)=>{const H=se(O);if(H<.2)return;const{top:W,hip:q}=m(O),D={x:(q.x-W.x)*.12,y:(q.y-W.y)*.12},K=O.height*.045*H;for(const V of[-1,1])P.shape([{x:W.x+V*K*.2,y:W.y+D.y*.1},{x:W.x+V*K*1.3,y:W.y-D.y*.1},{x:W.x+V*K*.6+D.x,y:W.y+D.y}],e,f(O)*.8)},A=(O,P,H)=>{const W=se(O);if(W<.25)return;const{top:q,hip:D}=m(O),K=Math.sin(O.turn*Math.PI/2)*O.height*.03,V=Q=>({x:mt(q,D,Q).x+K,y:mt(q,D,Q).y}),F=O.height*.022*W,X=V(.08),j=V(.62);P.shape([{x:X.x-F,y:X.y-F},{x:X.x+F,y:X.y-F},{x:X.x+F*.6,y:X.y+F},{x:X.x-F*.6,y:X.y+F}],H,f(O)*.7),P.shape([{x:X.x-F*.6,y:X.y+F},{x:X.x+F*.6,y:X.y+F},{x:j.x+F*1.4,y:j.y-F*2},j,{x:j.x-F*1.4,y:j.y-F*2}],H,f(O)*.7)},_=(O,P)=>{const H=se(O),{top:W,hip:q}=m(O),D=mt(q,W,.72),K=[O.points["knee.left"],O.points["knee.right"]],V=mt(q,{x:(K[0].x+K[1].x)/2,y:(K[0].y+K[1].y)/2},.9),F=Math.sin(O.turn*Math.PI/2)*O.height*.04;if(H<.15){const Q=mt(q,W,.2);H<-.3&&P.line([{x:Q.x-O.height*.05,y:Q.y},{x:Q.x+O.height*.05,y:Q.y}],f(O));return}const X=O.height*.075*H,j=mt(q,W,.2);P.shape([{x:D.x+F-X*.7,y:D.y},{x:D.x+F+X*.7,y:D.y},{x:j.x+F+X,y:j.y},{x:V.x+F+X*1.15,y:V.y},{x:V.x+F-X*1.15,y:V.y},{x:j.x+F-X,y:j.y}],h,f(O)),P.line([{x:D.x+F-X*.6,y:D.y},{x:W.x-X*.2,y:W.y},{x:D.x+F+X*.6,y:D.y}],f(O)*.8)},C=(O,P,H)=>{const{top:W,hip:q}=m(O),D=[O.points["knee.left"],O.points["knee.right"]],K=mt(q,{x:(D[0].x+D[1].x)/2,y:(D[0].y+D[1].y)/2},.95);H?P.shape(Ft([mt(W,q,.8),q,K],O.height*.145,O.height*.17),h,f(O)):P.shape(Ft([W,mt(W,q,.5),q],O.height*.14,O.height*.15),h,f(O));const V=se(O);if(V>.2){const F=Math.sin(O.turn*Math.PI/2)*O.height*.03,[X,j]=H?[q,K]:[W,q];if(P.line([{x:X.x+F,y:X.y},{x:j.x+F,y:j.y}],f(O)*.8),!H){const Q=mt(W,q,.35),et=O.height*.025*V;P.shape([{x:Q.x+F-et*2.4,y:Q.y},{x:Q.x+F-et*.6,y:Q.y},{x:Q.x+F-et*.6,y:Q.y+et*1.6},{x:Q.x+F-et*2.4,y:Q.y+et*1.6}],h,f(O)*.6)}}},N=(O,P,H,W,q)=>{const D=O.parts[`arm.${H}`].points,K=D[0],V=O.chains.spine[O.chains.spine.length-1],X=[{x:K.x+(V.x-K.x)*.45,y:K.y+(V.y-K.y)*.45},...Ka(D,0,q)],j=Ft(X,O.height*.085,O.height*(q>.6?.045:.06)),Q=X.length,et=j.slice(0,Q),rt=j.slice(Q).reverse();P.shape(j,W,0);const at=nt=>Math.hypot(nt[1].x-V.x,nt[1].y-V.y),[R,J]=at(et)>at(rt)?[et,rt]:[rt,et];P.line(R.slice(1),f(O)),P.line(J.slice(Math.ceil(Q*.45)),f(O)),P.line([et[Q-1],rt[Q-1]],f(O))},B=o||r||a,G=B?h:e,Z=B||s==="long"?.95:.45,Y=B||s!=="none",L=(O,P)=>{i==="skirt"&&!l&&!c&&T(O,P),c&&x(O,P),o&&C(O,P,!0),t.over==="apron"&&_(O,P)},z=O=>(P,H,W)=>{P.save(),v(P,H),p(H,W,O),u&&g(H,W,O),P.restore(),Dk(H)===O&&Rd(H)&&L(H,W)};return{parts:{"leg.left":{clip:v,over:z("left")},"leg.right":{clip:v,over:z("right")},spine:{over:(O,P,H)=>{r&&se(P)>=0&&b(P,H),k(P,H),t.collar&&!r&&I(P,H),t.tie&&!r&&A(P,H,t.tie),o&&C(P,H,!1),a&&$(P,H),r&&(se(P)<0&&b(P,H),E(P,H)),l&&S(P,H),c&&M(P,H),Rd(P)||L(P,H)}},"arm.left":{over:Y?(O,P,H)=>N(P,H,"left",G,Z):void 0},"arm.right":{over:Y?(O,P,H)=>N(P,H,"right",G,Z):void 0}}}}const Xa={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 Nd(t){const e={};for(const n of["left","right","both"]){const s=t[n];if(!s)continue;const i=typeof s=="string"?s:s.item,o=Xa[i];if(!o)throw new Error(`holding: unknown item '${i}'`);if(n==="both"&&o.hands==="one")throw new Error(`holding: a ${i} is held in one hand ('left' or 'right'), not 'both'`);if(n!=="both"&&o.hands==="both")throw new Error(`holding: a ${i} is held in both hands ('both')`);e[n]={item:i,color:(typeof s=="object"?s.color:void 0)??o.color}}return e}function po(t,e){const n=t.chains[`arm.${e}`],s=n[n.length-1],i=n[n.length-2],o=Math.hypot(s.x-i.x,s.y-i.y)||1,r={x:(s.x-i.x)/o,y:(s.y-i.y)/o},a=t.lineWidth*.5;return{point:{x:s.x+r.x*a,y:s.y+r.y*a},along:r,depth:t.parts[`arm.${e}`]?.depth??0}}function Yn(t,e,n,s=0){const i=Math.cos(s),o=Math.sin(s);return[[-e/2,-n/2],[e/2,-n/2],[e/2,n/2],[-e/2,n/2]].map(([r,a])=>({x:t.x+r*i-a*o,y:t.y+r*o+a*i}))}const jn=(t,e,n,s,i=12)=>Array.from({length:i+1},(o,r)=>{const a=n+(s-n)*r/i;return{x:t.x+Math.cos(a)*e,y:t.y+Math.sin(a)*e}});function Ga(t,e,n,s,i,o=1,r){const{point:a,along:l}=n,c=s/300;switch(e.item){case"mug":{const h=Yn({x:a.x,y:a.y-4*c},20*c,24*c);t.line(jn({x:a.x+10*c*Math.sign(o||1),y:a.y-4*c},7*c,-Math.PI/2,Math.PI/2).map(u=>({x:a.x+(u.x-a.x)*Math.sign(o||1),y:u.y})),i),t.shape(h,e.color,i);return}case"phone":{const h=Math.atan2(l.y,l.x)-Math.PI/2;t.shape(Yn(a,13*c,24*c,h),e.color,i),t.shape(Yn(a,9*c,17*c,h),"#8fd0f5",0);return}case"book":{const h=26*c,u=34*c;t.shape([{x:a.x,y:a.y-u/2},{x:a.x-h,y:a.y-u/2-3*c},{x:a.x-h,y:a.y+u/2-3*c},{x:a.x,y:a.y+u/2}],e.color,i),t.shape([{x:a.x,y:a.y-u/2},{x:a.x+h,y:a.y-u/2-3*c},{x:a.x+h,y:a.y+u/2-3*c},{x:a.x,y:a.y+u/2}],e.color,i);for(const d of[-1,1])for(const f of[.3,.5,.7]){const p=a.y-u/2+u*f;t.line([{x:a.x+d*5*c,y:p},{x:a.x+d*(h-5*c),y:p-2*c}],Math.max(.8,i*.5))}return}case"bag":{const h=a.y+10*c;t.line([{x:a.x-9*c,y:h},{x:a.x-5*c,y:a.y-2*c},{x:a.x+5*c,y:a.y-2*c},{x:a.x+9*c,y:h}],i),t.shape([{x:a.x-17*c,y:h},{x:a.x+17*c,y:h},{x:a.x+20*c,y:h+40*c},{x:a.x-20*c,y:h+40*c}],e.color,i);return}case"briefcase":{t.line(jn({x:a.x,y:a.y+6*c},7*c,Math.PI,Math.PI*2),i),t.shape(Yn({x:a.x,y:a.y+22*c},46*c,32*c),e.color,i),t.line([{x:a.x-23*c,y:a.y+14*c},{x:a.x+23*c,y:a.y+14*c}],Math.max(.8,i*.6));return}case"umbrella":{const h=78*c,u=(r??a.y-120*c)-14*c,d={x:a.x,y:Math.min(a.y-60*c,u-h*.55)};t.line([{x:a.x,y:a.y+10*c},d],i),t.line(jn({x:a.x+5*c,y:a.y+10*c},5*c,Math.PI,0,8),i);const f=[...jn({x:d.x,y:d.y+h*.55},h,Math.PI,Math.PI*2,24)],p=[];for(let g=4;g>=0;g--){const m=d.x-h+2*h*g/5;p.push(...jn({x:m+h/5,y:d.y+h*.55},h/5,0,-Math.PI,6).reverse())}t.shape([...f,...p],e.color,i);return}case"broom":{const h={x:l.x*.4+.25*Math.sign(o||1),y:Math.max(.6,l.y)},u=Math.hypot(h.x,h.y),d={x:h.x/u,y:h.y/u},f={x:a.x-d.x*40*c,y:a.y-d.y*40*c},p={x:a.x+d.x*120*c,y:a.y+d.y*120*c};t.line([f,p],i*1.1);const g={x:-d.y,y:d.x},m=[{x:p.x+g.x*6*c,y:p.y+g.y*6*c},{x:p.x-g.x*6*c,y:p.y-g.y*6*c},{x:p.x-g.x*16*c+d.x*34*c,y:p.y-g.y*16*c+d.y*34*c},{x:p.x+g.x*16*c+d.x*34*c,y:p.y+g.y*16*c+d.y*34*c}];t.shape(m,e.color,i);return}case"cane":{const h=Math.min(.56*s,Math.max(.3*s,-a.y)),u=.12*Math.sign(o||1),d={x:u/Math.hypot(u,1),y:1/Math.hypot(u,1)},f={x:a.x+d.x*h,y:a.y+d.y*h},p=jn({x:a.x+7*c*Math.sign(o||1),y:a.y-2*c},7*c,Math.PI,Math.PI*2,8).map(g=>({x:a.x+(g.x-a.x)*Math.sign(o||1),y:g.y}));t.line([...p,{x:a.x,y:a.y+2*c},f],i*1.2),t.shape(Yn({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(Yn(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 Ua=(t,e)=>(t[`held.${e}`]??1)>=.5,Fd=t=>Math.sin(t*Math.PI/2);function Dd(t){const e=o=>Math.max(1,o.lineWidth*.45),n=o=>(r,a,l,c,h)=>{const u=t[o];u&&Ua(h??{},o)&&Ga(l,u,po(a,o),a.height,e(a),Fd(a.turn),a.head.center.y-a.head.ry)},s=(o,r,a,l,c)=>{const h=t.both;if(!h||!Ua(c??{},"both"))return;const u=po(r,"left"),d=po(r,"right"),f={point:{x:(u.point.x+d.point.x)/2,y:(u.point.y+d.point.y)/2},along:{x:(u.along.x+d.along.x)/2,y:(u.along.y+d.along.y)/2},depth:(u.depth+d.depth)/2};Ga(a,h,f,r.height,e(r),Fd(r.turn),r.head.center.y-r.head.ry)},i={parts:{}};if(t.left&&(i.parts["arm.left"]={over:n("left")}),t.right&&(i.parts["arm.right"]={over:n("right")}),t.both){const o=r=>(a,l,c,h,u)=>{const d=r==="left"?"right":"left";(r==="left"?l.parts["arm.left"].depth>=l.parts["arm.right"].depth:l.parts["arm.right"].depth>l.parts[`arm.${d}`].depth)&&s(a,l,c,h,u)};for(const r of["left","right"])i.parts[`arm.${r}`]={...i.parts[`arm.${r}`],over:Wk(i.parts[`arm.${r}`]?.over,o(r))}}return i}function Wk(t,e){return t?(n,s,i,o,r)=>{t(n,s,i,o,r),e(n,s,i,o,r)}:e}function Wd(t,e){const n=(i,o)=>i&&o?(r,a,l,c,h)=>{i(r,a,l,c,h),o(r,a,l,c,h)}:i??o,s={};for(const i of new Set([...Object.keys(t.parts??{}),...Object.keys(e.parts??{})])){const o=t.parts?.[i],r=e.parts?.[i];s[i]={under:n(o?.under,r?.under),clip:n(o?.clip,r?.clip),over:n(o?.over,r?.over)}}return{behind:n(t.behind,e.behind),parts:s,front:n(t.front,e.front)}}function mo(t={}){if(t.build&&!(t.build in Ji))throw new Error(`character: unknown build '${t.build}'`);const e=t.build?Ji[t.build]:{},n=(t.proportions??"bold")==="bold",s=t.figure??"fluid",i=t.look??"clean",o=t.height??300,r=s==="stick",a=t.outfit?Ld(t.outfit):null,l=t.holding?Nd(t.holding):{};let c=a?Wd(a,t.layers??{}):t.layers??{};return Object.keys(l).length>0&&(c=Wd(c,Dd(l))),{plan:t.plan??Ma({headSize:t.headSize??e.headSize??(n?.3:.24),shoulderWidth:r?0:t.shoulderWidth??e.shoulderWidth??.06,hipWidth:r?0:t.hipWidth??e.hipWidth??.022,legLength:t.legLength??e.legLength??1,armLength:t.armLength??e.armLength??1,feet:t.feet??e.feet}),figure:s,look:i,height:o,lineWidth:t.lineWidth??o*(n?.045:.022),ink:t.ink??(i==="pencil"?"#2f2f33":"#1e293b"),skin:t.skin??(i==="pencil"?"none":"#ffffff"),seed:t.seed??1,pencil:t.pencil??{},layers:c,holding:l,contact:t.contact??"ground",hands:t.hands??"dot",handStyle:t.handStyle??"glove",handSize:t.handSize??(t.handStyle==="natural"?.14:.17),head:xd(t),face:{...t.face,teeth:t.face?.teeth??!1,tongue:t.face?.tongue??!1}}}function Bk(t,e,n,s){const{point:i,facing:o}=so(t,[e,n,s]);return{point:i,facing:o}}const Va=t=>t.rest[1]<-.5,zk=.3;function qk(t,e,n){return t.figure==="stick"?Va(e)?n.slice(0,3):n:Va(e)&&n.length>=3?sn(n[0],n[1],n[2],zk):n.length===3?sn(n[0],n[1],n[2],1):n}function zs(t,e){const n=t.plan.id==="human"?{...ht,...e}:e;return yo(t,n,xa(t.plan,n,{height:t.height,contact:t.contact}))}function yo(t,e,n){const s={},i={},o={},r=.01*t.height;t.plan.chains.forEach(d=>{const f=n.chains[d.id];s[d.id]=f.points;const p=f.depths.reduce((v,k)=>v+k,0)/f.depths.length,g=d.parent?n.chains[d.parent]:void 0,m=g?g.depths[d.at??g.depths.length-1]:n.hipDepth,w=p-m;o[d.id]=Math.abs(w)<r?0:w,i[d.id]={points:qk(t,d,f.points),depth:p,order:0}}),i.head={points:[n.head.center],depth:n.head.depth,order:0},o.head=0;const a=[...t.plan.chains.map(d=>d.id),"head"],l=[...a].sort((d,f)=>o[d]-o[f]||a.indexOf(d)-a.indexOf(f));l.forEach((d,f)=>{i[d].order=f});const c={hip:n.hip};for(const[d,[f,p]]of Object.entries(t.plan.landmarks??{})){const g=n.chains[f]?.points;g&&(c[d]=g[Math.min(p,g.length-1)])}const h={};for(const[d,f]of Object.entries(c))h[d]=f.y>=n.groundY-.01*t.height;const u={height:t.height,lineWidth:t.lineWidth,turn:e.turn??0,points:c,chains:s,parts:i,head:n.head,groundY:n.groundY,grounded:h};return{skeleton:n,joints:u,order:l}}function ie(t,e){return zs(t,e).joints}function Bd(t,e,n){const{head:s}=n;t.guideEllipse(s.center.x,s.center.y,s.rx*1.03,s.ry*1.03,s.angle);const i=Array.from({length:13},(l,c)=>({x:0,y:-.95+1.9*c/12})),o=Array.from({length:13},(l,c)=>({x:-.95+1.9*c/12,y:.12})),r=St(s,i,{x:0,y:0});r.facing>0&&t.guide(r.points),t.guide(St(s,o,{x:0,y:.12}).points),t.guide(n.chains.spine??[]);const a=e.lineWidth*.9;for(const l of["shoulder.left","shoulder.right","elbow.left","elbow.right","hip.left","hip.right","knee.left","knee.right"]){const c=n.points[l];c&&t.guideEllipse(c.x,c.y,a,a,0)}}function zd(t,e,n,s,i,o){const r=n.lineWidth;if(i==="head"){const{head:f}=s,p=n.skin==="none"?null:n.skin;n.face.shape==="angular"?e.shape(ju(f,n.face),p,r):e.ellipse(f.center.x,f.center.y,f.rx,f.ry,f.angle,p,r),Rk(t,e,n.head,f,o,{lineWidth:r,skin:n.skin},()=>{e.look!=="silhouette"&&ek(e,f,o,r,{...n.face,skin:n.skin==="none"?"#ffffff":n.skin},t)});return}const a=n.plan.chains.find(f=>f.id===i),l=s.chains[i],c=s.parts[i].points;if(n.figure==="stick"){if(i==="neck")return;const f=i==="spine"?[...l,...s.chains.neck?.slice(1)??[]]:c;e.line(f,r);return}const h=(f,p)=>[a.bones[f].width[0]*r,a.bones[p].width[1]*r];if(Va(a)){const[f,p]=h(0,1);if(e.limb(c,f,p),a.bones.length>=3)e.limb([l[2],l[3]],a.bones[2].width[0]*r,a.bones[2].width[1]*r);else if(n.hands==="cartoon"&&i.startsWith("arm."))Yk(t,e,n,l,i.endsWith(".left")?"left":"right",o);else{const g=l[l.length-1];e.dot(g.x,g.y,r*.62)}return}if(i==="spine"){const f=s.points["hip.left"],p=s.points["hip.right"];f&&p&&Math.hypot(f.x-p.x,f.y-p.y)>.5&&e.limb([f,p],r*1.3,r*1.3);const[g,m]=h(0,a.bones.length-1);e.limb(c,g,m);const w=s.points["shoulder.left"],v=s.points["shoulder.right"];w&&v&&Math.hypot(w.x-v.x,w.y-v.y)>.5&&e.limb(sn(w,l[l.length-1],v,1,10),r*1.15,r*1.15);return}const[u,d]=h(0,a.bones.length-1);e.limb(c,u,d)}function qd(t,e){const n=`hand.${e}.`,s={};for(const[r,a]of Object.entries(t))r.startsWith(n)&&(s[r.slice(n.length)]=a);const i=t.turn??0,o=e==="right"?1-i:1+i;return{...Pt,...s,turn:o+(s.turn??0)}}function Yk(t,e,n,s,i,o){const r=s[s.length-1],a=s[s.length-2],l=Math.atan2(r.x-a.x,-(r.y-a.y))*180/Math.PI;Wi(t,r,qd(o,i),{size:n.handSize*n.height,side:i,angle:l,pen:e,skin:n.skin==="none"?"#ffffff":n.skin,fingers:n.handStyle==="natural"?5:4,plump:n.handStyle==="natural"?1.15:1.6,lineWidth:n.lineWidth*.3})}function Yd(t,e,n,s=0){const i=e.plan.id==="human"?{...ht,...n}:n;Ja(t,e,i,zs(e,i),s)}function bo(t,e){const n=e/t.height;return{...t,height:e,lineWidth:t.lineWidth*n}}function jk(t,e,n,s){const i=t.plan.id==="human"?{...ht,...e}:e,o=no(t.plan,i,{height:s.height,contact:t.contact},n);return yo(bo(t,o.height),i,o).joints}function Kk(t,e,n,s,i){const o=e.plan.id==="human"?{...ht,...n}:n,r=no(e.plan,o,{height:i.height,contact:e.contact},s),a=bo(e,r.height);Ja(t,a,o,yo(a,o,r),i.time??0)}function jd(t,e,n,s){const i=t.plan.id==="human"?{...ht,...e}:e,o=no(t.plan,i,{height:s.height,contact:t.contact},n),r=bo(t,o.height),{joints:a,order:l}=yo(r,i,o),c=o.height/s.height;return l.map((h,u)=>({part:h,depth:(a.parts[h]?.depth??0)/c,draw(d,f=0){const p=Ps(d,{look:r.look,ink:r.ink,lineWidth:r.lineWidth,seed:Kt(`${r.seed}:${h}`),time:f,pencil:r.pencil}),g=w=>{w&&(d.save(),w(d,a,p,f,i),d.restore())};d.save(),d.lineCap="round",d.lineJoin="round",u===0&&(r.look==="pencil"&&r.pencil.construction!==!1&&Bd(p,r,a),g(r.layers.behind),$d(d,p,r.head,a.head,i,{lineWidth:r.lineWidth,skin:r.skin,face:r.face}));const m=r.layers.parts?.[h];g(m?.under),d.save(),m?.clip?.(d,a,p,f,i),zd(d,p,r,a,h,i),d.restore(),g(m?.over),u===l.length-1&&(Id(d,p,r.head,a.head,i,{lineWidth:r.lineWidth,skin:r.skin}),g(r.layers.front)),d.restore()}}))}function Ja(t,e,n,s,i,o){const{joints:r}=s,a=o?s.order.filter(h=>o.has(h)):s.order,l=Ps(t,{look:e.look,ink:e.ink,lineWidth:e.lineWidth,seed:e.seed,time:i,pencil:e.pencil}),c=h=>{h&&(t.save(),h(t,r,l,i,n),t.restore())};t.save(),t.lineCap="round",t.lineJoin="round",!o&&e.look==="pencil"&&e.pencil.construction!==!1&&Bd(l,e,r),o||c(e.layers.behind),$d(t,l,e.head,r.head,n,{lineWidth:e.lineWidth,skin:e.skin,face:e.face});for(const h of a){const u=e.layers.parts?.[h];c(u?.under),t.save(),u?.clip?.(t,r,l,i,n),zd(t,l,e,r,h,n),t.restore(),c(u?.over)}Id(t,l,e.head,r.head,n,{lineWidth:e.lineWidth,skin:e.skin}),o||c(e.layers.front),t.restore()}function Xk(t,e,n,s){const i=e.plan.id==="human"?{...ht,...n}:n,o=zs(e,i).joints.head.rx,r=bo(e,e.height*s.radius/Math.max(1e-6,o)),a=zs(r,i);t.save(),t.translate(s.x-a.joints.head.center.x,s.y-a.joints.head.center.y),Ja(t,r,i,a,s.time??0,new Set(["head"])),t.restore()}function Za(t,e,n){const s={...t};for(const[i,o]of Object.entries(e)){const r=t[i]??o;s[i]=r+(o-r)*n}return s}function ve(t,e,n,s){const i=t.plan.id==="human"?{...ht,...e}:e;let o;if(Array.isArray(s))o=s;else{const{skeleton:r}=zs(t,i),a=xa(t.plan,{...i,roll:0},{height:t.height,contact:"none"}),l=(i.roll??0)*Math.PI/180,c=s.x-r.hip.x,h=s.y-r.hip.y,u=a.hip.x+c*Math.cos(-l)-h*Math.sin(-l),d=a.hip.y+c*Math.sin(-l)+h*Math.cos(-l),f=Math.PI/2*(i.turn??0),p=s.depth??r.chains[n].depths[r.chains[n].depths.length-1],g=Math.cos(f),m=Math.sin(f);o=[u*g-p*m,-d,u*m+p*g]}return ro(t.plan,i,n,o,{height:t.height})}const Kd=new Set(["walk","walking","gait"]);function wo(t,e=ht,n){let s={...e};for(const[o,r]of Object.entries(t))typeof r=="number"&&!Kd.has(o)&&(s[o]=r);const i=Math.max(0,Math.min(1,typeof t.walking=="number"?t.walking:0));if(i>0){const o=typeof t.gait=="string"?t.gait:void 0,r=o?n?.[o]??o:void 0,a=qa(r,typeof t.walk=="number"?t.walk:0,s);s=Object.fromEntries(Object.keys({...s,...a}).map(l=>[l,(s[l]??0)+((a[l]??0)-(s[l]??0))*i]))}return s}function Gk(t){const{character:e}=t,n=e.height*.8,s=e.height,i=e.plan.id==="human"?ht:{};return{type:"custom",x:t.x-n/2,y:t.y-s,width:n,height:s,props:{...i,...t.pose},character:e,...t.gaits?{gaits:t.gaits}:{},draw(o,r,a){o.translate(n/2,s),Yd(o,e,wo(r.props??{},i,t.gaits),a)}}}function Xd(t,e,n){const s=o=>({x:o.x+e,y:o.y+n}),i=o=>Object.fromEntries(Object.entries(o).map(([r,a])=>[r,a.map(s)]));return{...t,points:Object.fromEntries(Object.entries(t.points).map(([o,r])=>[o,s(r)])),chains:i(t.chains),parts:Object.fromEntries(Object.entries(t.parts).map(([o,r])=>[o,{...r,points:r.points.map(s)}])),head:{...t.head,center:s(t.head.center)},groundY:t.groundY+n}}function Uk(t,e,n){const s=t.character;if(!s)throw new Error("characterAt: the target was not made by characterTarget");const i={...t.props};let o=0,r=0;for(const[c,h]of e.state?.values.get(n)??[])c==="x"||c==="motionPathX"?o=typeof h=="number"?h:o:c==="y"||c==="motionPathY"?r=typeof h=="number"?h:r:(typeof h=="number"||Kd.has(c))&&(i[c]=h);const a=wo(i,s.plan.id==="human"?ht:{},t.gaits),l=ie(s,a);return{pose:a,joints:Xd(l,t.x+o+t.width/2,t.y+r+t.height)}}function Qa(t,e=ht){const n=[];return t.forEach((s,i)=>{const o=i===0?e:n[i-1],r=typeof s.pose=="string"?le[s.pose]:void 0;n.push(r?{...r,turn:o.turn??0}:{...o,...s.pose})}),n}function Vk(t,e,n=ht){const s=Qa(e,n);return Object.keys(n).filter(o=>s.some(r=>(r[o]??n[o])!==n[o])).map(o=>({id:`${t}-${o}`,target:t,property:o,keyframes:e.map((r,a)=>({time:r.time,value:s[a][o]??n[o],...r.easing?{easing:r.easing}:{}}))}))}const ko=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],be=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],vo=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],tl=t=>Math.hypot(...t),Gd=t=>vo(t,1/(tl(t)||1)),Mo=t=>({...ht,...t}),el=t=>Ns(t.character.plan,Mo(t.pose),{height:t.character.height,contact:t.character.contact});function dn(t,e,n){return ko(t.position,el(t).chains[e][n])}function Ud(t,e,n){const s=Mo(t.pose),i=el(t).hip,o=Ls(t.character.plan,s,t.character.height),r=be(be(n,t.position),i),a=Zi(r,(s.roll??0)*Math.PI/180),l=ko(o.root,ne(a,-(s.turn??0)*Math.PI/2));return ro(t.character.plan,s,e,l,{height:t.character.height})}function Vd(t,e,n,s="toe"){const i=`leg.${e}`,o=s==="toe"?3:2;let r={...t,pose:Mo(t.pose),position:[...t.position]};for(let l=0;l<6;l++){const c=el(r).chains[i],h=be(c[o],c[2]);r={...r,pose:Ud(r,i,be(n,h))};const u=dn(r,i,o);r.position[1]+=n[1]-u[1]}const a=tl(be(dn(r,i,o),n));return{...r,reached:a<t.character.height*.002}}function Jd(t,e){const n=dn(t,`arm.${e}`,2),s=dn(t,`arm.${e}`,1);return ko(n,vo(Gd(be(n,s)),t.character.lineWidth*.5))}function Jk(t,e,n={}){const s=Math.min(t.character.height,e.character.height),i=n.length??s*.22;if(!(i>0)||!Number.isFinite(i))throw new Error("meetDandiya: stick length must be positive and finite");const o=n.point??[(t.position[0]+e.position[0])/2,Math.max(t.position[1],e.position[1])+s*.62,(t.position[2]+e.position[2])/2],r=(c,h)=>{const u=Gd([o[0]-c.position[0],s*.2,o[2]-c.position[2]]),d=be(o,vo(u,i));let f=Mo(c.pose);for(let g=0;g<6;g++){const m={...c,pose:f},w=dn(m,`arm.${h}`,2);f=Ud(m,`arm.${h}`,be(d,be(Jd(m,h),w)))}for(const[g,m]of Object.entries(Ct.hold))f[`hand.${h}.${g}`]=m;const p=Jd({...c,pose:f},h);return{pose:f,stick:{grip:p,tip:ko(p,vo(u,i))}}},a=r(t,n.sideA??"right"),l=r(e,n.sideB??"right");return{a:a.pose,b:l.pose,sticks:[a.stick,l.stick],point:o,reached:[a.stick,l.stick].every(c=>tl(be(c.tip,o))<s*.002)}}function Zd(t,e){const n=e.count??8,s=e.beatsPerTurn??32;if(!Number.isFinite(t)||!Number.isFinite(e.radius)||e.radius<=0||!Number.isInteger(n)||n<1||!Number.isFinite(s)||s<=0)throw new Error("danceCircleAt: finite beat, positive radius/beatsPerTurn and a positive integer count are required");const i=e.center??[0,0],o=e.direction??1;if(i.length!==2||!i.every(Number.isFinite)||!Number.isFinite(e.angle??0)||!Number.isFinite(e.spins??0)||![1,-1].includes(o)||e.facing!==void 0&&!(typeof e.facing=="number"?Number.isFinite(e.facing):["inward","outward","tangent"].includes(e.facing)))throw new Error("danceCircleAt: center, angle, spins and facing must be finite; direction is 1 or -1");const r=e.character??mo({height:1.7}),a=e.style??"garba",l=(h,u)=>{const d=(e.angle??0)+360*u/n+o*360*h/s,f=d*Math.PI/180,p=e.facing??"inward",g=(typeof p=="number"?p:d+(p==="inward"?180:p==="tangent"?o*90:0))+(e.spins??0)*360*h/s,m=Fs(a,h,{...e.pose,turn:g/90});return{character:r,position:[i[0]+e.radius*Math.sin(f),0,i[1]+e.radius*Math.cos(f)],pose:m.pose,heading:g,strike:m.strike}},c=Fs(a,t).contact;return Array.from({length:n},(h,u)=>{const d=l(t,u);if(e.plantFeet===!1)return{...d,planted:!1};const f=l(c.start,u),p=dn(f,`leg.${c.side}`,3),g=Vd(d,c.side,p);return{...d,pose:Za(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 Zk(t,e){if(e.count!==void 0&&e.count!==t.length)throw new Error("danceCircleTracks: count must match targets.length");const n=e.bpm??120,s=e.samplesPerBeat??16;if(!t.length||![n,e.beats,s].every(l=>Number.isFinite(l)&&l>0))throw new Error("danceCircleTracks: targets and positive finite bpm, beats and samplesPerBeat are required");if(!Number.isFinite(e.start??0))throw new Error("danceCircleTracks: start must be finite");const i=Math.max(1,Math.ceil(e.beats*s)),o=Array.from({length:i+1},(l,c)=>({time:(e.start??0)+e.beats*c/i*6e4/n,members:Zd(e.beats*c/i,{...e,count:t.length})})),r=o.some(l=>l.members.some(c=>c.pose.roll!==0)),a=new Set(["x","y","z","rotateY",...r?["turn","roll"]:[]]);return t.flatMap((l,c)=>{const h=o.map(u=>{const d=u.members[c],{turn:f,...p}=d.pose;return{time:u.time,pose:{...r?d.pose:p,x:d.position[0],y:d.position[1],z:d.position[2],rotateY:r?0:d.heading}}});return Object.keys(h[0].pose).filter(u=>a.has(u)||h.some(d=>d.pose[u]!==(e.pose?.[u]??ht[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 So=t=>Math.min(1,Math.max(0,t));function Qk(t){const e={...ct,turn:t.view},n=[];for(const s of t.keys){const i=n[n.length-1],o=!i||s.reset?e:i.pose;n.push({at:s.at,pose:{...o,...s.pose},easing:s.easing})}return n}function t5(t){return t-e5*Math.sin(2*Math.PI*t)/(2*Math.PI)}const e5=.5;function n5(t,e){if(!(e<=t.takeoff||e>=t.landing))return(e-t.takeoff)/(t.landing-t.takeoff)}function Qd(t,e){const n=typeof t=="string"?qs[t]:t,s=Qk(n),i=So(e);let o=0;for(let u=0;u<s.length;u++)s[u].at<=i&&(o=u);const r=s[o],a=s[Math.min(o+1,s.length-1)],l=a.at>r.at?(i-r.at)/(a.at-r.at):0,c=Nn(r.pose,a.pose,Lt(a.easing??"ease-in-out")(So(l))),h=n5(n,i);return h===void 0?{...c,spin:0,rise:0}:{...c,spin:n.spin*t5(h),rise:4*n.height*h*(1-h)}}function tf(t,e,n){const s=typeof t=="string"?qs[t]:t,i=So(e),o=So((i-s.takeoff)/(s.landing-s.takeoff));return s.travel*n*o}function s5(t,e,n={}){const s=typeof e=="string"?qs[e]:e,i=n.start??0,o=n.duration??s.duration,r=n.samples??48,a=Array.from({length:r+1},(h,u)=>{const d=u/r;return{time:i+d*o,progress:d,pose:Qd(s,d)}}),c=Object.keys(ct).filter(h=>a.some(u=>u.pose[h]!==ct[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*tf(s,u.progress,n.height)}))})}return c}const i5={leftHip:-55,leftKnee:-95,rightHip:55,rightKnee:95,leftShoulder:45,rightShoulder:-45,leftElbow:10,rightElbow:-10,lean:22,stretch:.94,headTilt:6},o5={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},To={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},r5={leftHip:-22,leftKnee:-30,rightHip:22,rightKnee:30,leftAnkle:10,rightAnkle:10,leftShoulder:-125,rightShoulder:125,leftElbow:0,rightElbow:0,lean:8,headTilt:0},a5={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 Kn(t,e,n,s,i,o=1300){return{label:t,view:1,spin:e,height:n,travel:s,takeoff:.27,landing:.8,duration:o,keys:[{at:0,reset:!0},{at:.16,pose:i5},{at:.27,pose:o5,easing:"ease-out-quad"},...i,{at:.76,pose:r5},{at:.86,pose:a5,easing:"ease-out-quad"},{at:1,reset:!0}]}}const qs={frontFlip:Kn("Front flip (tuck)",360,.56,.35,[{at:.38,pose:To,easing:"ease-out-cubic"},{at:.64,pose:To}]),backFlip:Kn("Back flip (tuck)",-360,.58,-.15,[{at:.36,pose:{...To,lean:18},easing:"ease-out-cubic"},{at:.64,pose:{...To,lean:18}}]),layout:Kn("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:Kn("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:Kn("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:Kn("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 ef(t,e){const n=Math.min(1,Math.max(0,t.turn??0)),s=1-n,i={...ht,turn:n},o=[{stick:"right",human:"left",s:1},{stick:"left",human:"right",s:-1}];for(const{stick:a,human:l,s:c}of o){const h=t[`${a}Shoulder`],u=t[`${a}Elbow`];i[`arm.${l}.spread`]=h*s,i[`arm.${l}.swing`]=c*h*n,i[`arm.${l}.bend`]=u*s,i[`arm.${l}.elbow`]=c*u*n;const d=t[`${a}Hip`],f=t[`${a}Knee`],p=s+c*n;i[`leg.${l}.rotate`]=90*s,i[`leg.${l}.spread`]=0,i[`leg.${l}.swing`]=d*p,i[`leg.${l}.knee`]=f*p,i[`leg.${l}.ankle`]=-(t[`${a}Ankle`]??0),i[`leg.${l}.toeOut`]=(t[`${a}FootOut`]??0)*l5,i[`eye.${l}`]=t[`${a}Eye`],i[`brow.${l}`]=t[`${a}Brow`],e&&Object.assign(i,c5(l,e[a]??Pt,t[`${a}Wrist`]??0,n))}const r=t.bend??0;i.lean=t.lean*n,i.bend=r*n,i.side=(t.lean+r*.5)*s,i["head.tilt"]=(t.headTilt+r*.5)*s,i["head.nod"]=t.headTilt*n;for(const a of["mouth","smile","mouthWidth","blink","browTilt","lookX","lookY","stretch"])i[a]=t[a];return i.lift=t.rise??0,i.roll=t.spin??0,i}const l5=70;function c5(t,e,n,s){const i=t==="right"?1-s:1+s,o={};for(const r of Object.keys(Pt))o[`hand.${t}.${r}`]=e[r]??Pt[r];return o[`hand.${t}.turn`]=(e.turn??0)-i,o[`hand.${t}.roll`]=(e.roll??0)+n,o}class nf{positions=[];normals=[];indices=[];vertex(e,n,s,i,o,r){const a=Math.hypot(i,o,r)||1;return this.positions.push(e,n,s),this.normals.push(i/a,o/a,r/a),this.positions.length/3-1}triangle(e,n,s){this.indices.push(e,n,s)}quad(e,n,s,i){this.indices.push(e,n,s,e,s,i)}build(){return{positions:this.positions,normals:this.normals,indices:this.indices}}}function h5(t){const e=new Map,n=[];for(let i=0;i<t.positions.length/3;i++){const o=[0,1,2].map(r=>Math.round(t.positions[i*3+r]*1e6)).join(",");e.has(o)||e.set(o,i),n.push(e.get(o))}const s=new Map;for(let i=0;i<t.indices.length/3;i++)for(let o=0;o<3;o++){const r=n[t.indices[i*3+o]],a=n[t.indices[i*3+(o+1)%3]];if(r===a)continue;const l=r<a?`${r}-${a}`:`${a}-${r}`,c=s.get(l);c?c.faces.push(i):s.set(l,{a:Math.min(r,a),b:Math.max(r,a),faces:[i]})}return[...s.values()]}const nl=Math.PI*2;function u5(t,e=16){const n=new nf,s=Math.max(6,Math.round(e)),i=Math.max(3,Math.round(s/2)),o=[];for(let r=0;r<=i;r++){const a=r/i*Math.PI,l=[];for(let c=0;c<=s;c++){const h=c/s*nl,u=Math.sin(a)*Math.sin(h),d=Math.cos(a),f=Math.sin(a)*Math.cos(h);l.push(n.vertex(u*t,d*t,f*t,u,d,f))}o.push(l)}for(let r=0;r<i;r++)for(let a=0;a<s;a++){const l=o[r][a],c=o[r+1][a],h=o[r+1][a+1],u=o[r][a+1];r>0&&n.triangle(l,c,u),r<i-1&&n.triangle(c,h,u)}return n.build()}function sf(t,e,n,s,i){const o=t.vertex(0,n,0,0,s,0),r=Array.from({length:i},(a,l)=>{const c=l/i*nl;return t.vertex(Math.sin(c)*e,n,Math.cos(c)*e,0,s,0)});for(let a=0;a<i;a++){const l=r[a],c=r[(a+1)%i];s===1?t.triangle(o,l,c):t.triangle(o,c,l)}}function of(t,e,n=24){const s=new nf,i=Math.max(6,Math.round(n)),o=e/2,r=-e/2,a=h=>Array.from({length:i+1},(u,d)=>{const f=d/i*nl;return s.vertex(Math.sin(f)*t,h,Math.cos(f)*t,Math.sin(f),0,Math.cos(f))}),l=a(r),c=a(o);for(let h=0;h<i;h++)s.quad(l[h],l[h+1],c[h+1],c[h]);return sf(s,t,o,1,i),sf(s,t,r,-1,i),s.build()}function xo(t){const e=Array.from({length:t.indices.length/3},()=>[]);for(const n of h5(t))for(const s of n.faces){const i=n.faces.find(o=>o!==s)??-1;e[s].push({a:n.a,b:n.b,across:i})}return{...t,faceEdges:e}}const sl=new Map;function d5(t){const e=sl.get(t);if(e)return e;let n=[1,1,1];const s=t.trim().replace("#","");if(t.trim().startsWith("#")&&(s.length===3||s.length===6)){const i=s.length===3?s.split("").map(o=>o+o).join(""):s;n=[0,2,4].map(o=>Number.parseInt(i.slice(o,o+2),16)/255)}else{const i=t.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/);i&&(n=[Number(i[1])/255,Number(i[2])/255,Number(i[3])/255])}return sl.size<512&&sl.set(t,n),n}Ze([-3,-5,-4]);const f5=(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 o=d5(i.color);let r;if(i.light==="ambient")r=i.intensity;else if(i.light==="directional")r=i.intensity*Math.max(0,-Ce(e,i.direction));else{const a=$n(i.position,t),l=xi(a),c=l>0?In(a,1/l):e,h=i.range?Math.max(0,1-l/i.range)**2:1;if(r=i.intensity*Math.max(0,Ce(e,c))*h,i.light==="spot"){const u=Math.cos(i.angle*Math.PI/180),d=Math.cos(i.angle*.8*Math.PI/180);r*=f5(u,d,-Ce(c,i.direction))}}s[0]+=o[0]*r,s[1]+=o[1]*r,s[2]+=o[2]*r}return s}function af(t,e){return t?Math.min(1,Math.max(0,(e-t.near)/(t.far-t.near))):0}function il(t,e,n={}){t.save(),g5(t,e,n),t.restore()}function g5(t,e,n){const s=ol(e,n);n.shadow!==!1&&rl(t,e,n);for(const i of e.under)lf(t,i,s,n);if(n.rider){if(t.save(),e.openings.length>0){t.beginPath();for(const i of e.openings){t.moveTo(i[0].x,i[0].y);for(const o of i.slice(1))t.lineTo(o.x,o.y);t.closePath()}t.clip("nonzero")}n.rider(t),t.restore()}for(const i of e.over)lf(t,i,s,n)}function lf(t,e,n,s){const i=s.loose?.[e.part.id];if(!i){cl(t,e,n,s);return}if(i.opacity<=0)return;const o=e.faces.flatMap(c=>c.points);if(o.length===0)return;const r=o.map(c=>c.x),a=o.map(c=>c.y),l={x:(Math.min(...r)+Math.max(...r))/2,y:(Math.min(...a)+Math.max(...a))/2};t.save(),t.globalAlpha*=Math.min(1,i.opacity),t.translate(l.x+i.x,l.y+i.y),t.rotate(i.rotate*Math.PI/180),t.translate(-l.x,-l.y),cl(t,e,n,s),t.restore()}function ol(t,e={}){return e.lineWidth??Math.max(1.3,t.sizePx*.022)}function rl(t,e,n={}){e.shadow.opacity<=0||e.shadow.points.length<3||(t.save(),t.globalAlpha=e.shadow.opacity,Eo(t,e.shadow.points,n.ink??"#26262b",!1),t.restore())}function p5(t,e,n,s={}){t.save(),cl(t,e,n,s),t.restore()}function cf(t,e,n,s={}){const i=s.style==="stick",o=e.flatMap(h=>{if(i&&h.part.solidOnly)return[];const u=h.part.layer??0;return i&&h.spine?[{depth:h.depth,layer:u,part:h}]:h.faces.map(d=>({depth:d.depth,layer:u,part:h,face:d}))}),r=new Map;for(const h of o){const u=h.face?.normal;if(!h.face?.center||!u)continue;const d=Math.abs(u[0])>=Math.abs(u[1])&&Math.abs(u[0])>=Math.abs(u[2])?0:Math.abs(u[1])>=Math.abs(u[2])?1:2,f=d*2+(u[d]<0?1:0);r.set(f,[...r.get(f)??[],h])}for(const h of r.values())for(const u of h){const{center:d,normal:f}=u.face;for(const p of h){if(p.part.part.id===u.part.part.id)continue;const g=p.face;if(g.normal[0]*f[0]+g.normal[1]*f[1]+g.normal[2]*f[2]<=.8)continue;const w=g.normal[0]*(d[0]-g.center[0])+g.normal[1]*(d[1]-g.center[1])+g.normal[2]*(d[2]-g.center[2]);w>-hf/5&&w<hf&&(u.layer=Math.max(u.layer,p.layer),u.depth=Math.max(u.depth,p.depth+1e-6))}}o.sort((h,u)=>h.layer-u.layer||h.depth-u.depth);const a=new Map,l=h=>{let u=a.get(h.part.id);return u||a.set(h.part.id,u=al(t,h,n,s)),u};t.save();const c=t.globalAlpha;for(const{part:h,face:u}of o){t.globalAlpha=c*h.opacity;const d=l(h);if(!u)d.line(h.spine,n*1.15);else{const f=i?uf(h,s):u.light?m5(h,u,s):ll(h);f&&(!i&&s.look==="silhouette"?d.shape(u.points,f,0):Eo(t,u.points,i||u.light?f:Ao(f,u.tone),!0,h.cut?1.6:.8));const p=(h.part.outline??1)*n;if(p>0)for(const g of u.edges??[])g.length>1&&d.line(g,p);for(const g of u.marks??[])d.line(g,n*.7)}}t.restore()}const hf=.05;function al(t,e,n,s){return Ps(t,{look:s.look??"clean",ink:e.part.ink??s.ink??"#26262b",lineWidth:n,seed:Kt(`${s.seed??0}:${e.part.id}`),time:s.time??0,pencil:{construction:!1,rubbedOut:0,...s.pencil}})}function ll(t){const{part:e}=t;return e.glow&&t.glow>0&&e.fill?dl(e.fill,e.glow.color,t.glow):e.fill}function m5(t,e,n){const{part:s}=t;if(!s.fill)return;const i=ul(s.fill,e.light,e.fog??0,n.fog);return s.glow&&t.glow>0?dl(i,s.glow.color,t.glow):i}function uf(t,e){const n=ll(t);return n&&(b5(n)||t.glow>0)?n:e.paper??"#fbf8ef"}function cl(t,e,n,s){e.opacity<1?(t.save(),t.globalAlpha*=e.opacity,df(t,e,n,s),t.restore()):df(t,e,n,s)}function df(t,e,n,s){if(s.style==="stick")return y5(t,e,n,s);const{part:i}=e,o=al(t,e,n,s),r=ll(e),a=s.look==="silhouette";for(const c of e.faces)r&&(a?o.shape(c.points,r,0):Eo(t,c.points,Ao(r,c.tone)));const l=(i.outline??1)*n;if(l>0)for(const c of e.edges)c.length>1&&o.line(c,l);for(const c of e.marks)o.line(c,n*.7)}function y5(t,e,n,s){const{part:i}=e;if(i.solidOnly)return;const o=al(t,e,n,s);if(e.spine){o.line(e.spine,n*1.15);return}const r=uf(e,s);for(const l of e.faces)Eo(t,l.points,r);const a=(i.outline??1)*n;if(a>0)for(const l of e.edges)l.length>1&&o.line(l,a);for(const l of e.marks)o.line(l,n*.7)}function b5(t){const e=Xn(t);return e?(.299*e[0]+.587*e[1]+.114*e[2])/255<.3:!1}function Eo(t,e,n,s=!0,i=.8){t.fillStyle=n,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let o=1;o<e.length;o++)t.lineTo(e[o].x,e[o].y);t.closePath(),t.fill(),s&&(t.strokeStyle=n,t.lineWidth=i,t.lineJoin="round",t.stroke())}function Xn(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 hl=t=>`#${t.map(e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0")).join("")}`;function Ao(t,e){const n=Xn(t);return n?hl(e>=1?n.map(s=>s+(255-s)*(e-1)*2):n.map(s=>s*e)):t}function ul(t,e,n,s){const i=Xn(t);if(!i)return t;let o=i.map((a,l)=>a*e[l]);const r=s?Xn(s):void 0;return r&&n>0&&(o=o.map((a,l)=>a+(r[l]-a)*n)),hl(o)}function dl(t,e,n){const s=Xn(t),i=Xn(e);return!s||!i?n<.5?t:e:hl(s.map((o,r)=>o+(i[r]-o)*n))}const w5=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),k5=new Set(["walk","walking","gait"]),ff=t=>typeof t=="number"?t:void 0,v5=1.7;function M5(t,e,n){const s=Array.from({length:24},(i,o)=>{const r=o/24*Math.PI*2,a=e.toView([Math.cos(r)*n,0,Math.sin(r)*n*.8]);return a[2]<-.001?e.toScreen(a):null});s.some(i=>i===null)||(t.beginPath(),s.forEach((i,o)=>o===0?t.moveTo(i.x,i.y):t.lineTo(i.x,i.y)),t.closePath(),t.fillStyle="rgba(0, 0, 0, 0.22)",t.fill())}function S5(t){const e=Ce([0,1,0],t);if(e>.999999)return Ei();if(e<-.999999)return re(Qt([1,0,0],180));const n=Ti([0,1,0],t);return re(Qt(n,Math.acos(e)*180/Math.PI))}function T5(t,e,n,s,i){const o=t.solid??{},r=o.outline===!1?void 0:o.outline??{width:2,color:"#0f172a"},a={color:o.color??"#475569",shading:o.shading??"toon",outline:r},l={color:o.skin??"#f2c49b",shading:o.shading??"toon",outline:r},c={color:"#0f172a",shading:"unlit"},h=s.height*.034,u=[],d=(k,b,E)=>u.push({mesh:k,world:Ot(i,b),material:E}),f=(k,b,E)=>d(e.sphere,Lr(k,[0,0,0,1],[b,b,b]),E);for(const k of n.chains){const b=s.chains[k.id],E=k.id==="spine"?1.9:1;k.bones.forEach(($,S)=>{const x=b[S],M=b[S+1],T=Rr(x,M),[I,A]=$.width??[1,1],_=h*E*(I+A)/2;if(T>1e-6){const C=Nh(x,M,.5),N=S5(Ze($n(M,x)));d(e.cylinder,Ot(Qe(C),Ot(N,tn([_,T,_]))),a)}f(x,h*E*I,a),f(M,h*E*A,a)}),k.id.startsWith("arm.")&&f(b[b.length-1],h*1.5,l)}const{center:p,rx:g,ry:m,axes:w}=s.head,v=[...w[0],0,...w[1],0,...w[2],0,...p,1];d(e.sphere,Ot(v,tn([g,m,g])),l);for(const k of[-1,1]){const b=Ze([k*.36,.15,.92]),E=Si(p,Si(Si(In(w[0],b[0]*g*1.04),In(w[1],b[1]*m*1.04)),In(w[2],b[2]*g*1.04))),$=[...w[0],0,...w[1],0,...w[2],0,...E,1];d(e.sphere,Ot($,tn([g*.11,m*.14,g*.03])),c)}return u}const x5={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:mo({...t.character,height:1}),cylinder:xo(of(1,1,16)),sphere:xo(u5(1,20))}},resolve({object:t,prepared:e,values:n,world:s,camera:i,lights:o=[],fog:r,toScreen:a}){const l=t,c=e,h=c.who;let u={...ht,...l.pose};for(const[x,M]of n)typeof M=="number"&&!w5.has(x)&&!k5.has(x)&&(u[x]=M);const d=Math.max(0,Math.min(1,ff(n.get("walking"))??l.walking??0));if(d>0){const x=typeof n.get("gait")=="string"?n.get("gait"):l.gait,M=qa(x,ff(n.get("walk"))??0,u);u=Object.fromEntries(Object.keys({...u,...M}).map(T=>[T,(u[T]??0)+((M[T]??0)-(u[T]??0))*d]))}const f=l.height??v5,p=Ot(i.view,s),g={toView:x=>Xt(p,x),toScreen:x=>a(x)},w=-g.toView([0,f/2,0])[2];if(w<=i.near)return null;const v=l.shadow===!1?[]:[{depth:w+f,draw:x=>M5(x,g,f*.18)}];if(l.look==="solid"){const x=Ns(h.plan,u,{height:f,contact:h.contact});return{meshes:T5(l,c,h.plan,x,s),drawables:v}}const k=Xt(s,[0,f*.6,0]),b=Ze($n(i.position,k)),E=rf(k,b,o).map(x=>Math.min(1,x)),$=o.length>0&&h.skin!=="none"?{...h,skin:ul(h.skin,E,af(r,Rr(k,i.position)),r?.color)}:h,S=jd($,u,g,{height:f});return{drawables:[...v,...S.map((x,M)=>({depth:-x.depth-M*1e-6,draw:(T,I)=>x.draw(T,I.time)}))]}}},Be={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}},Ys=1,Po=.55,gf=.35,E5=1.6,pf={a:"a",e:"e",i:"i",y:"i",o:"o",u:"u"},mf={m:"m",b:"m",p:"m",f:"f",v:"f",w:"u",q:"u",l:"l",n:"l",d:"l",t:"l"},yf={अ:"a",आ:"a",इ:"i",ई:"i",उ:"u",ऊ:"u",ऋ:"i",ए:"e",ऐ:"e",ओ:"o",औ:"o",ऍ:"e",ऑ:"o"},bf={"ा":"a","ि":"i","ी":"i","ु":"u","ू":"u","ृ":"i","े":"e","ै":"e","ो":"o","ौ":"o","ॅ":"e","ॉ":"o"},A5={प:"m",फ:"m",ब:"m",भ:"m",म:"m",व:"u"},P5="्",wf="़",$5=t=>t>="क"&&t<="ह",kf=new Set([".",",","!","?",";",":","…","।","॥","—","-"]);function vf(t){const e=[],n=Array.from(t.toLowerCase()),s=(i,o)=>{const r=e[e.length-1];r&&r.viseme===i?r.weight+=o*.5:e.push({viseme:i,weight:o})};for(let i=0;i<n.length;i++){const o=n[i],r=n[i+1];if(kf.has(o))s("rest",E5);else if(/\s/.test(o)){const a=e[e.length-1];a&&a.viseme!=="rest"&&e.push({viseme:"c",weight:gf})}else if((o==="o"||o==="e")&&r===o)s(o==="o"?"u":"i",Ys),i++;else if(o in pf)s(pf[o],Ys);else if(o in mf)s(mf[o],Po);else{if(o==="h")continue;if(/[a-z]/.test(o))s("c",Po);else if(o in yf)s(yf[o],Ys);else if($5(o)){const a=r===wf?o==="फ"?"f":void 0:A5[o];s(a??"c",Po);let l=i+1;n[l]===wf&&l++;const c=n[l];c===P5?i=l:c&&c in bf?(s(bf[c],Ys),i=l):(!c||/\s/.test(c)||kf.has(c)||s("a",Ys*.6),i=l-1)}else(o==="ं"||o==="ँ")&&s("l",Po*.6)}}for(;e.length>0&&(e[e.length-1].viseme==="rest"||e[e.length-1].weight===gf);)e.pop();return e}function fl(t,e={}){const n=e.fields?.mouth??"mouth",s=e.fields?.mouthWidth??"mouthWidth",i=e.energy??1,o=vf(t.text),r=[{time:t.start,value:Be.rest.mouth}],a=[{time:t.start,value:Be.rest.mouthWidth}],l=o.reduce((h,u)=>h+u.weight,0),c=t.end-t.start;if(l>0&&c>0){let h=t.start;for(const u of o){const d=c*u.weight/l,f=h+Math.min(d*.4,60);if(f>r[r.length-1].time){const p=Be[u.viseme];r.push({time:f,value:p.mouth*i,easing:"ease-out"}),a.push({time:f,value:1+(p.mouthWidth-1)*Math.min(1.3,i),easing:"ease-out"})}h+=d}}return t.end>r[r.length-1].time&&(r.push({time:t.end,value:Be.rest.mouth,easing:"ease-in-out"}),a.push({time:t.end,value:Be.rest.mouthWidth,easing:"ease-in-out"})),{[n]:r,[s]:a}}function I5(t,e,n={}){const s={};for(const i of[...e].sort((o,r)=>o.start-r.start))for(const[o,r]of Object.entries(fl(i,n))){const a=s[o]??=[],l=a.length>0?a[a.length-1].time:-1/0;a.push(...r.filter(c=>c.time>l))}return Object.entries(s).map(([i,o])=>({id:`${t}-${i}`,target:t,property:i,keyframes:o}))}function $o(t,e,n,s={}){if(n.length===0)return e;const i=s.fields?.mouth??"mouth",o=s.fields?.mouthWidth??"mouthWidth",r={[i]:Be.rest.mouth,[o]:Be.rest.mouthWidth,...s.rest},a=new It({id:"before-speech",tracks:e}),l=(u,d)=>a.getStateAtTime(d).values.get(t)?.get(u)??r[u],c=[i,o],h=e.filter(u=>u.target!==t||!c.includes(u.property));for(const u of c){const d=e.find(p=>p.target===t&&p.property===u);let f=d?[...d.keyframes]:[{time:0,value:l(u,0)}];for(const p of n){const g=fl(p,s)[u];g[0]={...g[0],value:l(u,p.start)},g[g.length-1]={...g[g.length-1],value:l(u,p.end)},f=[...f.filter(m=>m.time<p.start||m.time>p.end),...g],f.sort((m,w)=>m.time-w.time)}h.push({id:d?.id??`${t}-${u}`,target:t,property:u,keyframes:f})}return h}const js=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function Mf([t,e,n]){const[s,i,o]=[t/2,e/2,n/2];return{vertices:[[-s,-i,-o],[s,-i,-o],[s,i,-o],[-s,i,-o],[-s,-i,o],[s,-i,o],[s,i,o],[-s,i,o]],faces:[{corners:[4,5,6,7],normal:[0,0,1]},{corners:[1,0,3,2],normal:[0,0,-1]},{corners:[5,1,2,6],normal:[1,0,0]},{corners:[0,4,7,3],normal:[-1,0,0]},{corners:[7,6,2,3],normal:[0,1,0]},{corners:[0,1,5,4],normal:[0,-1,0]}]}}const Gn=(t,[e,n,s])=>t==="z"?[e,n,s]:t==="x"?[s,n,e]:[e,s,n];function Sf(t,e,n="x",s=20,i=0){const o=[],r=e/2;for(const c of[-r,r])for(let h=0;h<s;h++){const u=Math.PI*2*h/s;o.push(Gn(n,[Math.cos(u)*t,Math.sin(u)*t,c]))}const a=[{corners:Array.from({length:s},(c,h)=>s-1-h),normal:Gn(n,[0,0,-1])},{corners:Array.from({length:s},(c,h)=>s+h),normal:Gn(n,[0,0,1])}];for(let c=0;c<s;c++){const h=(c+1)%s,u=Math.PI*2*(c+.5)/s;a.push({corners:[c,h,s+h,s+c],normal:Gn(n,[Math.cos(u),Math.sin(u),0])})}const l=[];if(i>0)for(const c of[-r,r]){const h=o.push(Gn(n,[0,0,c*1.01]))-1;for(let u=0;u<i;u++){const d=Math.PI*2*u/i,f=o.push(Gn(n,[Math.cos(d)*t*.82,Math.sin(d)*t*.82,c*1.01]))-1;l.push([h,f])}}return{vertices:o,faces:a,marks:l,creases:!0}}function Tf([t,e,n],s=16){const i=Math.max(4,Math.round(s/2)),o=[[0,e,0]];for(let h=1;h<i;h++){const u=Math.PI*h/i;for(let d=0;d<s;d++){const f=Math.PI*2*d/s;o.push([Math.sin(u)*Math.cos(f)*t,Math.cos(u)*e,Math.sin(u)*Math.sin(f)*n])}}const r=o.push([0,-e,0])-1,a=(h,u)=>1+(h-1)*s+u%s,l=h=>{const u=h.reduce((d,f)=>[d[0]+o[f][0],d[1]+o[f][1],d[2]+o[f][2]],[0,0,0]);return js([u[0]/(t*t),u[1]/(e*e),u[2]/(n*n)])},c=[];for(let h=0;h<s;h++){const u=[0,a(1,h+1),a(1,h)];c.push({corners:u,normal:l(u)});for(let f=1;f<i-1;f++){const p=[a(f,h),a(f,h+1),a(f+1,h+1),a(f+1,h)];c.push({corners:p,normal:l(p)})}const d=[a(i-1,h),a(i-1,h+1),r];c.push({corners:d,normal:l(d)})}return{vertices:o,faces:c,creases:!1}}const O5=t=>t.reduce((e,[n,s],i)=>{const[o,r]=t[(i+1)%t.length];return e+n*r-o*s},0)/2;function xf(t,e){const n=O5(t)<0?[...t].reverse():t,s=n.length,i=e/2,o=[...n.map(([a,l])=>[i,l,a]),...n.map(([a,l])=>[-i,l,a])],r=[{corners:Array.from({length:s},(a,l)=>s-1-l),normal:[1,0,0]},{corners:Array.from({length:s},(a,l)=>s+l),normal:[-1,0,0]}];for(let a=0;a<s;a++){const l=(a+1)%s,[c,h]=[n[l][0]-n[a][0],n[l][1]-n[a][1]];r.push({corners:[a,l,s+l,s+a],normal:js([0,-c,h])})}return{vertices:o,faces:r,creases:!0}}function Ef(t,e){const n={left:([i,o])=>[0,o,i],right:([i,o])=>[0,o,i],front:([i,o])=>[i,o,0],back:([i,o])=>[i,o,0],up:([i,o])=>[i,0,o]},s={left:[1,0,0],right:[-1,0,0],front:[0,0,1],back:[0,0,-1],up:[0,1,0]};return{vertices:t.map(n[e]),faces:[{corners:t.map((i,o)=>o),normal:s[e]}]}}function Af(t,e,n=8){const s=r=>Array.isArray(e)?e[Math.min(r,e.length-1)]:e,i=[],o=[];t.forEach((r,a)=>{const l=t[Math.min(a+1,t.length-1)],c=t[Math.max(a-1,0)],h=js([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=js(Pf(h,u)),f=Pf(d,h);for(let p=0;p<n;p++){const g=Math.PI*2*p/n,m=Math.cos(g)*s(a),w=Math.sin(g)*s(a);i.push([r[0]+d[0]*m+f[0]*w,r[1]+d[1]*m+f[1]*w,r[2]+d[2]*m+f[2]*w])}});for(let r=0;r<t.length-1;r++)for(let a=0;a<n;a++){const l=(a+1)%n,c=[r*n+a,r*n+l,(r+1)*n+l,(r+1)*n+a],h=c.reduce((d,f)=>[d[0]+i[f][0]/4,d[1]+i[f][1]/4,d[2]+i[f][2]/4],[0,0,0]),u=[(t[r][0]+t[r+1][0])/2,(t[r][1]+t[r+1][1])/2,(t[r][2]+t[r+1][2])/2];o.push({corners:c,normal:js([h[0]-u[0],h[1]-u[1],h[2]-u[2]])})}return{vertices:i,faces:o,creases:!1}}function Pf(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 $f(t){switch(t.type){case"box":return Mf(t.size);case"cylinder":return Sf(t.radius,t.length,t.axis,t.segments,t.spokes);case"ellipsoid":return Tf(t.radii,t.segments);case"extrude":return xf(t.profile,t.width);case"panel":return Ef(t.points,t.facing);case"tube":return{...Af(t.points,t.radius,t.segments),joined:t.joined}}}function gl(t,e){if(t.length<2)return t;const n=i=>t[Math.max(0,Math.min(t.length-1,i))],s=i=>{const o=i*(t.length-1),r=Math.min(t.length-2,Math.floor(o)),a=o-r,[l,c,h,u]=[n(r-1),n(r),n(r+1),n(r+2)];return[0,1,2].map(d=>{const f=l[d],p=c[d],g=h[d],m=u[d];return .5*(2*p+(-f+g)*a+(2*f-5*p+4*g-m)*a*a+(-f+3*p-3*g+m)*a*a*a)})};return Array.from({length:e},(i,o)=>s(o/(e-1)))}const fn=t=>Array.isArray(t)&&t.length===2&&t.every(e=>typeof e=="number"&&Number.isFinite(e));function Io(t,e){return((e-t)%360+540)%360-180}function If(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 Un(t,e){return Math.atan2(e[0]-t[0],e[1]-t[1])*180/Math.PI}function Of(t){const e=t.filter((i,o)=>o===0||Math.hypot(i[0]-t[o-1][0],i[1]-t[o-1][1])>1e-6);if(e.length<2)return[];const n=e.length===2?e:gl(e.map(([i,o])=>[i,0,o]),(e.length-1)*12).map(([i,,o])=>[i,o]);let s=0;return n.map((i,o)=>(o>0&&(s+=Math.hypot(i[0]-n[o-1][0],i[1]-n[o-1][1])),{point:i,at:s}))}function _f(t,e){let n=1;for(;n<t.length-1&&t[n].at<e;)n++;const s=t[n-1],i=t[n],o=i.at>s.at?Math.max(0,Math.min(1,(e-s.at)/(i.at-s.at))):0;return{point:[s.point[0]+(i.point[0]-s.point[0])*o,s.point[1]+(i.point[1]-s.point[1])*o],direction:[i.point[0]-s.point[0],i.point[1]-s.point[1]]}}function Cf(t,e){if(e<=0)return 0;if(e>=1)return 1;let n=0,s=1;for(let i=0;i<40;i++){const o=(n+s)/2;t(o)<e?n=o:s=o}return(n+s)/2}const Ks=520,pl=["do","at","for","to","through","toward","speed","pose","gag","say","look","turns","dance","bpm","beats"],Hf=t=>Math.max(700,Array.from(t).length*65),Rf=70,Lf=35;function ml(t,e){const n=e[0]-t.x,s=e[1]-t.eyeHeight,i=e[2]-t.z,o=t.heading*Math.PI/180,r=n*Math.cos(o)-i*Math.sin(o),a=n*Math.sin(o)+i*Math.cos(o),l=Math.atan2(r,a)*180/Math.PI,c=Math.hypot(r,a),h=-Math.atan2(s,c)*180/Math.PI,u=Math.max(-Rf,Math.min(Rf,l*.75)),d=Math.max(-Lf,Math.min(Lf,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 Nf={walk:1.3,bouncy:1.4,doubleBounce:1.2,sneak:.6,strut:1.2,tired:.8,run:3.6,shove:.7},yl=Object.keys(Wt),bl=Object.keys(le),wl=Object.keys(go),_5=.25,C5=700/180,H5=200,R5=300;function Ff(t){if(!Array.isArray(t))return[{beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const e=[...yl,"face","spin","dance","hold","pose","gag","place","say","look"],n=[];return t.forEach((s,i)=>{const o=c=>n.push({beat:i,message:c});if(!s||typeof s!="object"||Array.isArray(s))return o("Each beat must be an object like { do: 'walk', to: [x, z] }.");const r=s,a={duration:"for",path:"through",position:"to",heading:"toward",direction:"toward"};for(const c of Object.keys(r))pl.includes(c)||o(dt("beat field",c,pl,a[c]));const l=typeof r.do=="string"?bl.includes(r.do)?"pose":wl.includes(r.do)?"gag":r.do==="turn"?"face":void 0:void 0;if(typeof r.do!="string"||!e.includes(r.do))return o(dt("character 3D beat",r.do,e,l));for(const c of["at","for","turns","bpm","beats"]){const h=r[c];h!==void 0&&(typeof h!="number"||!Number.isFinite(h)||(c==="at"?h<0:c!=="turns"&&h<=0))&&o(`\`${c}\` must be finite${c==="turns"?"":c==="at"?" and non-negative":" and positive"}.`)}if(r.do==="dance"&&!(typeof r.dance=="string"&&Object.hasOwn(ln,r.dance))&&o(dt("native dance",r.dance,Object.keys(ln))),yl.includes(r.do)&&(r.to===void 0&&r.through===void 0&&o(`\`${r.do}\` needs \`to\` ([x, z] metres) or \`through\` (a list of them).`),r.to!==void 0&&!fn(r.to)&&o(`\`to\` is a point on the ground, [x, z] metres (got ${JSON.stringify(r.to)}).`),r.through!==void 0&&!(Array.isArray(r.through)&&r.through.length>0&&r.through.every(fn))&&o("`through` is a list of points on the ground, each [x, z] metres.")),r.do==="place"&&!fn(r.to)&&o("`place` needs `to`: a point on the ground, [x, z] metres."),r.do==="face"&&!(fn(r.toward)||typeof r.toward=="number"&&Number.isFinite(r.toward))&&o("`face` needs `toward`: a point [x, z] or a finite heading in degrees."),r.do==="say"&&!(typeof r.say=="string"&&r.say.trim().length>0)&&o("`say` needs `say`: the line spoken."),r.do==="look"){const c=r.look??r.toward;Array.isArray(c)&&(c.length===2||c.length===3)&&c.every(u=>typeof u=="number"&&Number.isFinite(u))||c==="camera"||o("`look` needs `look`: a point [x, z] or [x, y, z] to look at, or `camera`.")}r.do==="pose"&&!(typeof r.pose=="object"&&r.pose!==null)&&!bl.includes(r.pose)&&o(dt("pose",r.pose,bl)),r.do==="gag"&&!wl.includes(r.gag)&&o(dt("gag",r.gag,wl))}),n}function L5(t,e,n){const s=Ff(e);if(s.length>0)throw new Error(`characterScript3D: ${s.length} problem(s) in the beats:
|
|
54
|
-
${s.map(
|
|
55
|
-
`)}`);const i=n.height??1.7,o={...ht,...n.pose},r=(S,x=o)=>{const M=S.match(/^hand\.(?:left|right)\.(.+)$/)?.[1];return x[S]??ht[S]??(M?Pt[M]:void 0)??0};let[a,l]=n.position??[0,0],c=n.heading??0,h=0;const u=new Map,d=[],f=(S,x,M,T="linear")=>{const I=u.get(S)??[];I.push({time:x,value:M,easing:T}),u.set(S,I)},p=(S,x,M)=>{const T=u.get(S)??[];for(let I=T.length-1;I>=0;I--)if(T[I].time===x){if(T[I].value===M)return;break}f(S,x,M)};f("x",0,a),f("z",0,l),f("rotateY",0,c);const g=(S,x,M)=>{const T=Io(c,x);if(Math.abs(T)<1)return M!==void 0&&(p("rotateY",S,c),f("rotateY",S+M,c)),S+(M??0);const I=M??Math.max(H5,Math.abs(T)*C5);return p("rotateY",S,c),c+=T,f("rotateY",S+I,c,"ease-in-out"),S+I},m=(S,x,M,T="ease-in-out")=>{for(const[I,A]of Object.entries(M))r(I)!==A&&(p(I,S,r(I)),f(I,x,A,T),o[I]=A)},w=(S,x,M)=>{const T=Of([[a,l],...x.through??[x.to]]);if(T.length<2)return M;const I=g(M,Un(T[0].point,T[1].point)),A=T[T.length-1].at,_=x.speed??Nf[S]*Math.sqrt(i/1.7),C=x.for??A/_*1e3,N=Ya(S,i),B=Lt("ease-in-out"),G=Math.min(R5,C/4);d.push({time:I,value:S}),p("walking",I,0),f("walking",I+G,1,"ease-out"),f("walking",I+C-G,1),f("walking",I+C,0,"ease-in");const Z=h;let Y=c;for(let L=0;;L=Math.min(A,L+_5)){const z=I+Cf(B,L/A)*C,{point:O,direction:P}=_f(T,L);Y+=Io(Y,Un([0,0],P));const H=L===0?p:f;if(H("x",z,O[0]),H("z",z,O[1]),H("rotateY",z,Y),H("walk",z,Z+L/N),L>=A)break}return h=Z+A/N,[a,l]=T[T.length-1].point,c=Y,I+C},v=[],k=[];let b=0;for(const S of e){const x=S.at??b;let M=x;if(yl.includes(S.do))M=w(S.do,S,x);else if(S.do==="face")M=g(x,typeof S.toward=="number"?S.toward:Un([a,l],S.toward),S.for);else if(S.do==="spin")M=x+(S.for??1e3),p("rotateY",x,c),c+=(S.turns??1)*360,f("rotateY",M,c,"linear");else if(S.do==="dance"){const T=ln[S.dance],I=S.bpm??T.bpm,A=S.beats??(S.for!==void 0?S.for*I/6e4:T.beats);M=x+(S.for??A*6e4/I);const _={...o},C=Math.max(1,Math.ceil(A*16)),N=Array.from({length:C+1},(G,Z)=>Fs(S.dance,A*Z/C,_).pose),B=Math.min(150,(M-x)/4);for(const G of Object.keys(N[0])){const Z=r(G,_);G==="turn"||G==="roll"||N.every(Y=>Y[G]===Z)||(p(G,x,Z),N.slice(1).forEach((Y,L)=>{const z=x+(M-x)*(L+1)/C,O=Math.min(1,(z-x)/B),P=O*O*(3-2*O);f(G,z,Z+(Y[G]-Z)*P)}),o[G]=N[C][G])}}else if(S.do==="hold")M=x+(S.for??1e3);else if(S.do==="place")p("x",x,a),p("z",x,l),[a,l]=S.to,f("x",x+1,a),f("z",x+1,l),typeof S.toward=="number"&&(p("rotateY",x,c),c=S.toward,f("rotateY",x+1,c)),M=x+1;else if(S.do==="pose"){M=x+(S.for??500);const T=typeof S.pose=="string"?le[S.pose]:S.pose;m(x,M,T)}else if(S.do==="gag"){const T=_d(S.gag,{at:x,from:{...o}});let I=T[0];for(const A of T.slice(1))m(I.time,A.time,Object.fromEntries(Object.entries(A.pose).filter(([_,C])=>o[_]!==C)),A.easing??"ease-in-out"),I=A;M=I.time}else if(S.do==="say"){M=x+(S.for??Hf(S.say)),k.push({text:S.say,start:x,end:M});const T={tilt:o["head.tilt"]??0,left:o["brow.left"]??0,right:o["brow.right"]??0};let I=0;for(let A=x+Ks;A<M-Ks/2;A+=Ks,I++){const _=I%2===0;m(A-Ks/2,A,{"head.tilt":T.tilt+(_?3:-2),"brow.left":T.left+(_?.25:0),"brow.right":T.right+(_?.25:0)})}I>0&&m(M-Ks/2,M,{"head.tilt":T.tilt,"brow.left":T.left,"brow.right":T.right})}else if(S.do==="look"){const T=S.look??S.toward,I=i*.9,A=T==="camera"?n.camera??[0,1.6,8]:T.length===3?T:[T[0],I,T[1]];M=x+(S.for??500),m(x,M,ml({x:a,z:l,heading:c,eyeHeight:I},A),"ease-out")}v.push({do:S.do,start:x,end:M}),b=M}const E=`${n.scene}/${t}`;let $=[...u].map(([S,x])=>({id:`${t}-${S}`,target:E,property:S,keyframes:If(x)}));return d.length>0&&$.push({id:`${t}-gait`,target:E,property:"gait",keyframes:d}),k.length>0&&($=$o(E,$,k,{rest:{mouth:n.pose?.mouth??ht.mouth??0,mouthWidth:n.pose?.mouthWidth??ht.mouthWidth??1}})),{tracks:$,duration:b,beats:v,end:{position:[a,l],heading:c,pose:{...o}}}}function kl(t,e,n=[0,0,0]){const s=t.filter(o=>o.target===e),i=new It({id:`${e}-position`,tracks:s});return o=>{const r=i.getStateAtTime(o).values.get(e),a=r?.get("position");if(Array.isArray(a)&&a.length===3)return[a[0],a[1],a[2]];const l=(c,h)=>{const u=r?.get(c);return typeof u=="number"?u:h};return[l("x",n[0]),l("y",n[1]),l("z",n[2])]}}function N5(t,e){const n=`${e.scene}/${e.character}`,s=e.height??1.7,i=Math.max(1,e.every??66),o=e.objects?.[e.character]??[0,0,0],r=new It({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?kl(t,`${e.scene}/${a.camera}`,e.objects?.[a.camera]??[0,1.6,8]):(()=>{const u=kl(t,`${e.scene}/${a.object}`,e.objects?.[a.object]??[0,0,0]),d=a.eyeHeight??s*.9;return f=>{const p=u(f);return[p[0],p[1]+d,p[2]]}})(),c=["head.turn","head.nod","lookX","lookY"],h={"head.turn":[],"head.nod":[],lookX:[],lookY:[]};for(let u=e.start;;u=Math.min(e.end,u+i)){const d=r.getStateAtTime(u).values.get(n),f=(g,m)=>{const w=d?.get(g);return typeof w=="number"?w:m},p=ml({x:f("x",o[0]),z:f("z",o[2]),heading:f("rotateY",0),eyeHeight:f("y",o[1])+s*.9},l(u));for(const g of c)h[g].push({time:u,value:p[g]??0});if(u>=e.end)break}return c.map(u=>({id:`${n}-lookAt-${u}`,target:n,property:u,keyframes:h[u]}))}function F5(t){const e=Math.max(1,Math.round(t.count)),[n,s]=t.centre??[0,0],i=t.spacing??1.2,o=t.shape??"line",r=[];if(o==="circle"){const h=e<2?0:Math.max(i,i*e/(Math.PI*2));for(let u=0;u<e;u++){const d=u/e*Math.PI*2,f=n+Math.sin(d)*h,p=s+Math.cos(d)*h;r.push({position:[f,p],heading:(Math.atan2(n-f,s-p)*180/Math.PI+360)%360})}return r}if(o==="cluster"){let h=(t.seed??1)>>>0||7;const u=()=>(h^=h<<13,h>>>=0,h^=h>>17,h^=h<<5,h>>>=0,h/4294967296),d=[];for(let f=0;f<e;f++){let p=[n,s],g=-1/0;for(let m=0;m<24;m++){const w=Math.sqrt(u())*i*Math.max(1,Math.sqrt(e)*.9),v=u()*Math.PI*2,k=[n+Math.cos(v)*w,s+Math.sin(v)*w],b=d.length===0?1/0:Math.min(...d.map(E=>Math.hypot(E[0]-k[0],E[1]-k[1])));if(b>g&&(g=b,p=k),b>=i)break}d.push(p),r.push({position:p,heading:0})}return r}const a=(t.heading??90)*Math.PI/180,l=i*(e-1),c=(t.bend??60)*Math.PI/180;for(let h=0;h<e;h++){const u=e===1?0:h/(e-1)-.5,d=u*l;let f=n+Math.sin(a)*d,p=s+Math.cos(a)*d,g=((t.heading??90)-90+360)%360;if(o==="arc"){const m=(1-Math.cos(u*c))*l*.5;f-=Math.cos(a)*m,p+=Math.sin(a)*m,g=(g-u*(t.bend??60)+360)%360}r.push({position:[f,p],heading:g})}return r}const Df={x:0,y:0,scale:1,rotate:0,shakeX:0,shakeY:0,shakeRotate:0};function D5(t){const e=n=>{const s=t?.get(n);return typeof s=="number"?s:Df[n]};return{x:e("x"),y:e("y"),scale:e("scale"),rotate:e("rotate"),shakeX:e("shakeX"),shakeY:e("shakeY"),shakeRotate:e("shakeRotate")}}function W5(t,e,n){const s=n.width/2,i=n.height/2,r=1+2*Math.max(Math.abs(e.shakeX),Math.abs(e.shakeY))/Math.max(1,Math.min(n.width,n.height));t.translate(s+e.x+e.shakeX,i+e.y+e.shakeY),t.rotate((e.rotate+e.shakeRotate)*Math.PI/180),t.scale(e.scale*r,e.scale*r),t.translate(-s,-i)}function B5(t,e,n){const s=e.width/2,i=e.height/2,o=(t.rotate+t.shakeRotate)*Math.PI/180,r=(n.x-s)*t.scale,a=(n.y-i)*t.scale;return{x:s+t.x+t.shakeX+r*Math.cos(o)-a*Math.sin(o),y:i+t.y+t.shakeY+r*Math.sin(o)+a*Math.cos(o)}}function Wf(t,e,n={},s){const i=n.length??240,o=9,r=28,a=i-22;t.save(),t.translate(e.x,e.y),t.rotate((n.angle??-30)*Math.PI/180),t.fillStyle=n.color??"#f4c542",t.fillRect(r,-o,a-r,2*o),t.fillStyle="#e8b4a0",t.fillRect(a,-o,i-a,2*o),t.fillStyle="#f1dcbf",t.beginPath(),t.moveTo(0,0),t.lineTo(r,-o),t.lineTo(r,o),t.closePath(),t.fill(),t.fillStyle=n.outline??"#2f2f33",t.beginPath(),t.moveTo(0,0),t.lineTo(r*.35,-o*.35),t.lineTo(r*.35,o*.35),t.closePath(),t.fill(),t.strokeStyle=n.outline??"#2f2f33",t.lineWidth=3,t.lineJoin="round",t.lineCap="round";const l=[[{x:0,y:0},{x:r,y:-o},{x:i,y:-o},{x:i,y:o},{x:r,y:o},{x:0,y:0}],[{x:r,y:-o},{x:r,y:o}],[{x:a,y:-o},{x:a,y:o}]];for(const c of l)qf(t,c,s);t.restore()}function vl(t,e,n={},s){const i=n.length??90,o=n.thickness??34;t.save(),t.translate(e.x,e.y),t.rotate((n.angle??-35)*Math.PI/180);const r=-o/2;t.fillStyle=n.color??"#f4a7b9",t.fillRect(0,r,i,o),t.fillStyle="#e9edf2",t.fillRect(i*.45,r,i*.55,o),t.strokeStyle=n.outline??"#2f2f33",t.lineWidth=3,t.lineJoin="round";const a=[{x:0,y:r},{x:i,y:r},{x:i,y:-r},{x:0,y:-r},{x:0,y:r}],l=[{x:i*.45,y:r},{x:i*.45,y:-r}];if(s)s.line(a),s.line(l);else for(const c of[a,l]){t.beginPath(),t.moveTo(c[0].x,c[0].y);for(const h of c.slice(1))t.lineTo(h.x,h.y);t.stroke()}t.restore()}const Bf=150,z5={pencil:44,eraser:30};function Ml(t,e,n={},s){const i=n.tool??"pencil",o=n.skin??"#f1c9a5",r=n.outline??"#2f2f33",a=n.scale??1,l=Math.min(1,Math.max(0,n.lift??0)),c=(n.angle??-30)*Math.PI/180,h=s?s.nudge(.6):{x:0,y:0},u=Bf*a*(1+.05*l);l>0&&(t.save(),t.fillStyle=r,t.globalAlpha=.15*l,t.beginPath(),t.ellipse(e.x,e.y,9*a,4*a,0,0,Math.PI*2),t.fill(),t.restore());const d={x:e.x+h.x+6*l*a,y:e.y+h.y-18*l*a},f=Ct.pencilGrip,p=S=>{const x=S.fingers.thumb,M=S.fingers.index,T=S.fingers.middle,I=zf([x.points[3],M.points[3],T.points[3]]),A=zf([x.points[1],M.points[0]]),_=(x.depths[3]+M.depths[3]+T.depths[3])/3;return{pinch:I,direction:Math.atan2(A.y-I.y,A.x-I.x),depth:_}},g=Di(f,{size:u}),m=c-p(g).direction,w=Di(f,{size:u,angle:m*180/Math.PI}),v=p(w),k=z5[i]*a,b={x:v.pinch.x-Math.cos(c)*k,y:v.pinch.y-Math.sin(c)*k},E={x:d.x-b.x,y:d.y-b.y},$=w.axes.up;q5(t,E,{x:-$.x,y:-$.y},u,n.arm??300*a,o,n.sleeve??"#5b7db1",r),Wi(t,E,f,{size:u,angle:m*180/Math.PI,skin:o,ink:r,lineWidth:3*a,prop:{depth:v.depth,draw:()=>{t.save(),t.translate(d.x,d.y),t.scale(a,a),i==="eraser"?vl(t,{x:0,y:0},{angle:c*180/Math.PI,outline:r},s):Wf(t,{x:0,y:0},{angle:c*180/Math.PI,length:190,outline:r},s),t.restore()}}})}const zf=t=>({x:t.reduce((e,n)=>e+n.x,0)/t.length,y:t.reduce((e,n)=>e+n.y,0)/t.length});function q5(t,e,n,s,i,o,r,a){const l={x:-n.y,y:n.x},c=s*.15,h=(g,m,w)=>({x:e.x+n.x*g+l.x*m*w,y:e.y+n.y*g+l.y*m*w}),u=h(i,0,0),d=g=>{const m=t.createLinearGradient(e.x,e.y,u.x,u.y);return m.addColorStop(0,g),m.addColorStop(.6,g),m.addColorStop(1,X5(g)),m},f=Math.min(s*.55,i*.35);t.save(),t.lineJoin="round",t.lineCap="round",t.lineWidth=3*(s/Bf),t.beginPath(),t.moveTo(h(-s*.1,-1,c).x,h(-s*.1,-1,c).y),t.lineTo(h(f+4,-1,c*1.1).x,h(f+4,-1,c*1.1).y),t.lineTo(h(f+4,1,c*1.1).x,h(f+4,1,c*1.1).y),t.lineTo(h(-s*.1,1,c).x,h(-s*.1,1,c).y),t.closePath(),t.fillStyle=o,t.fill(),t.strokeStyle=a,t.beginPath(),t.moveTo(h(0,-1,c).x,h(0,-1,c).y),t.lineTo(h(f,-1,c*1.1).x,h(f,-1,c*1.1).y),t.moveTo(h(0,1,c).x,h(0,1,c).y),t.lineTo(h(f,1,c*1.1).x,h(f,1,c*1.1).y),t.stroke();const p=[h(f,-1,c*1.3),h(i,-1,c*1.5),h(i,1,c*1.5),h(f,1,c*1.3)];t.beginPath(),p.forEach((g,m)=>m?t.lineTo(g.x,g.y):t.moveTo(g.x,g.y)),t.closePath(),t.fillStyle=d(r),t.fill(),t.strokeStyle=d(a),t.beginPath(),t.moveTo(p[1].x,p[1].y),t.lineTo(p[0].x,p[0].y),t.lineTo(p[3].x,p[3].y),t.lineTo(p[2].x,p[2].y),t.stroke(),t.restore()}function Y5(t,e,n={}){const s=n.offstage??{x:2e3,y:1400},i=n.enter??450,o=n.exit??450,r=n.linger??1500,a=[...t].filter(g=>g.path.length>0).sort((g,m)=>g.start-m.start),l=g=>g.tool??"pencil",c=g=>{const m=Math.min(1,Math.max(0,g));return m*m*(3-2*m)},h=(g,m,w)=>({x:g.x+(m.x-g.x)*w,y:g.y+(m.y-g.y)*w}),u=a.find(g=>e>=g.start&&e<=g.end);if(u){const g=u.end-u.start,m=g>0?(e-u.start)/g:1;return{at:Hi(u.path,m),tool:l(u),lift:0,drawing:!0}}const d=[...a].reverse().find(g=>g.end<e),f=a.find(g=>g.start>e),p=g=>g.path[g.path.length-1];if(d&&f&&f.start-d.end<=r){const g=(e-d.end)/(f.start-d.end),m=g<.5?l(d):l(f);return{at:h(p(d),f.path[0],c(g)),tool:m,lift:Math.sin(Math.PI*g),drawing:!1}}if(f&&f.start-e<=i){const g=1-(f.start-e)/i;return{at:h(s,f.path[0],c(g)),tool:l(f),lift:1-c(g),drawing:!1}}if(d&&e-d.end<=o){const g=(e-d.end)/o;return{at:h(p(d),s,c(g)),tool:l(d),lift:c(g),drawing:!1}}return null}function j5(t,e,n,s=.08,i=32){const o=Math.PI*2*(1+s),r=[];for(let a=0;a<=i;a++){const l=-Math.PI/2+o*a/i;r.push({x:t+Math.cos(l)*n,y:e+Math.sin(l)*n})}return r}function K5(t){const{path:e}=t,n=e.map(a=>a.x),s=e.map(a=>a.y),i=Math.min(...n),o=Math.min(...s),r=t.hand===!1?void 0:t.hand===!0||t.hand===void 0?{}:t.hand;return{type:"custom",x:i,y:o,width:Math.max(1,Math.max(...n)-i),height:Math.max(1,Math.max(...s)-o),props:{draw:0},draw(a,l,c){const h=Math.min(1,Math.max(0,Number(l.props?.draw??0)));a.translate(-i,-o),a.strokeStyle=t.color??"#2f2f33",a.lineWidth=t.lineWidth??5,a.lineCap="round",a.lineJoin="round";const u=t.sketch?Ri(a,t.sketch,c):void 0;h>0&&(u?t.smooth?u.curve(e,h):u.line(e,h):qf(a,Rn(e,h))),r&&h>0&&h<1&&Ml(a,Hi(e,h),r,u)}}}function X5(t){const e=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim());if(!e)return"rgba(0, 0, 0, 0)";const n=e[1].length===3?[...e[1]].map(r=>r+r).join(""):e[1],[s,i,o]=[0,2,4].map(r=>parseInt(n.slice(r,r+2),16));return`rgba(${s}, ${i}, ${o}, 0)`}function qf(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 Oo=1e5;function G5(t,e,n,s,i=6){const o=[],r=Math.max(1,Math.round(i));for(let a=0;a<=r;a++)o.push({x:a%2===0?t:t+n,y:e+s*a/r});return o}function Sl(t,e,n,s){if(s<=0||e.length===0)return;const i=Rn(e,s),o=n/2,r=a=>{t.beginPath(),t.rect(-Oo,-Oo,2*Oo,2*Oo),a(),t.clip("evenodd")};for(const a of i)r(()=>{t.moveTo(a.x+o,a.y),t.arc(a.x,a.y,o,0,Math.PI*2)});for(let a=1;a<i.length;a++){const l=i[a-1],c=i[a],h=Math.hypot(c.x-l.x,c.y-l.y);if(h===0)continue;const u=-(c.y-l.y)/h*o,d=(c.x-l.x)/h*o;r(()=>{t.moveTo(l.x+u,l.y+d),t.lineTo(c.x+u,c.y+d),t.lineTo(c.x-u,c.y-d),t.lineTo(l.x-u,l.y-d),t.closePath()})}}function U5(t,e,n,s,i){t.save(),Sl(t,e,n,s),i(),t.restore()}function V5(t,e){const n=e.width??40,s=e.hand===!0?{}:e.hand||void 0,i=e.eraser===!1?void 0:e.eraser===!0||e.eraser===void 0?{}:e.eraser;return{...t,props:{...t.props,erase:0},draw(o,r,a){const l=Number(r.props?.erase??0);if(o.save(),Sl(o,e.path,n,l),t.draw(o,r,a),o.restore(),!i||l<=0||l>=1)return;const c=Hi(e.path,l);s?Ml(o,c,{...s,tool:"eraser"}):vl(o,c,i)}}}function Vn(){const t=new Map,e=(n,...s)=>t.set(n,[...t.get(n)??[],...s]);return{keys:n=>t.get(n),push:e,tween(n,s,i,o,r=300){e(n,{time:o.at,value:s},{time:o.at+(o.duration??r),value:i,...o.easing?{easing:o.easing}:{}})},last(n,s){const i=t.get(n);return i?[...i].sort((o,r)=>o.time-r.time)[i.length-1].value:s},valueAt:(n,s)=>_o(t.get(n),s),cutAfter(n,s){for(const i of n)t.set(i,(t.get(i)??[]).filter(o=>o.time<=s))},tracks(n){return[...t].filter(([,s])=>s.length>0).map(([s,i])=>({id:`${n}-${s}`,target:n,property:s,keyframes:J5(i)}))}}}function _o(t,e){if(!t||t.length===0)return 0;const n=[...t].sort((s,i)=>s.time-i.time);if(e<=n[0].time)return n[0].value;for(let s=1;s<n.length;s++)if(e<=n[s].time){const i=n[s-1],o=n[s];return o.time===i.time?o.value:i.value+(o.value-i.value)*(e-i.time)/(o.time-i.time)}return n[n.length-1].value}function Jn(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 J5(t){return[...t].sort((n,s)=>n.time-s.time).map(n=>({time:n.time,value:n.value,...n.easing?{easing:n.easing}:{}}))}const Z5=.0016,Q5=.6,ze=33;function Xs(t){const e=(o,r)=>`piece.${o.id}.${r}`,n=(o,r)=>({x:o.home.x+t.valueAt(e(o,"x"),r),y:o.home.y+t.valueAt(e(o,"y"),r)}),s=(o,r)=>{const a=t.keys(e(o,"x"));if(!a||a.length<2)return;const l=n(o,r-ze),c=n(o,r);return{x:(c.x-l.x)/ze,y:(c.y-l.y)/ze}},i=(o,r)=>t.cutAfter(["x","y","rotate"].map(a=>e(o,a)),r);return{at:n,cutAfter:i,follow(o,r){for(const a of r)t.push(e(o,"x"),{time:a.time,value:a.x-o.home.x}),t.push(e(o,"y"),{time:a.time,value:a.y-o.home.y})},fling(o,r){const a=n(o,r.at),l=r.velocity??s(o,r.at)??{x:.5,y:-.6},c=r.gravity??Z5,h=r.duration??900,u=(r.spin??Q5)*(l.x<0?-1:1),d=t.valueAt(e(o,"rotate"),r.at);i(o,r.at);for(let f=0;f<=h;f+=ze){const p=a.x+l.x*f,g=a.y+l.y*f+.5*c*f*f;t.push(e(o,"x"),{time:r.at+f,value:p-o.home.x}),t.push(e(o,"y"),{time:r.at+f,value:g-o.home.y}),t.push(e(o,"rotate"),{time:r.at+f,value:d+u*f})}t.tween(e(o,"opacity"),1,0,{at:r.at+h*.6,duration:h*.4})},move(o,r){const a=n(o,r.at);t.tween(e(o,"x"),a.x-o.home.x,r.to.x-o.home.x,r,400),t.tween(e(o,"y"),a.y-o.home.y,r.to.y-o.home.y,r,400)}}}function Co(t,e,{ground:n,every:s,floors:i}){if(i.every(k=>k.windows.length===0))return t;const o=t.find(k=>k.target===e&&k.property==="y"),r=new It({id:`${e}-ride`,tracks:o?[o]:[]}),a=k=>o?Number(r.getStateAtTime(k).values.get(e)?.get("y")??0):0,l=k=>{const b=n+a(k);return i.findIndex(E=>Math.abs(E.top-b)<.5)},c=(o?.keyframes??[]).map(k=>k.time),h=k=>{const b=M=>M<0?0:i[M].offset(k),E=l(k);if(E>=0)return b(E);if(Math.abs(a(k))<.5)return 0;const $=M=>l(M)>=0||Math.abs(a(M))<.5,S=[...c].reverse().find(M=>M<=k&&$(M)),x=c.find(M=>M>=k&&$(M));return S===void 0&&x===void 0?0:S===void 0?b(l(x)):x===void 0||x===S?b(l(S)):b(l(S))+(b(l(x))-b(l(S)))*(k-S)/(x-S)},u=i.flatMap(k=>k.windows),d=(k,b)=>u.some(E=>E.start<b&&E.end>k)||h(k)!==h(b),f=o?[...o.keyframes]:[{time:0,value:0}],p=[{...f[0],value:f[0].value+h(f[0].time)}],g=(k,b)=>{const E=new Set([b]);for(let $=k+s;$<b;$+=s)E.add($);for(const $ of u)for(const S of[$.start,$.end])S>k&&S<b&&E.add(S);for(const $ of[...E].sort((S,x)=>S-x))p.push({time:$,value:a($)+h($)})};for(let k=1;k<f.length;k++){const b=f[k-1].time,E=f[k].time;d(b,E)?g(b,E):p.push({...f[k],value:f[k].value+h(E)})}const m=f[f.length-1].time,w=Math.max(m,...u.map(k=>k.end));w>m&&g(m,w);const v={id:o?.id??`${e}-y`,target:e,property:"y",keyframes:p};return o?t.map(k=>k===o?v:k):[...t,v]}function gn(t){const e=t.indexOf(":");return e<0?{kind:t,rest:""}:{kind:t.slice(0,e),rest:t.slice(e+1)}}function qe(t,e,n,s){const i=Object.keys(n.anchors).map(r=>gn(r).kind),{kind:o}=gn(e);return i.includes(o)?new Error(`${t}: no anchor "${e}"${s?`: ${s}`:""} (anchors: ${Object.keys(n.anchors).join(", ")})`):new Error(`${t}: ${dt("anchor",o,i)} (anchors: ${Object.keys(n.anchors).join(", ")})`)}function Gs(t,e,n){return new Error(`${t}.edit: ${dt("edit",e,Object.keys(n.edits))}`)}function Mt(t,e,n,s){return{x:t+n/2,y:e+s/2,left:t,right:t+n,top:e,bottom:e+s,width:n,height:s}}const Yf={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"},Ho=["wipe","fly","blur"],Us={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"}},tv=.9,ev=8;function nv(t){const e={...Yf,...t.theme},n=t.code.replace(/\t/g," ").replace(/\n$/,"").split(`
|
|
56
|
-
`),s=t.fontSize??16,i=(t.lineHeight??1.6)*s,o=(t.charWidth??.6)*s,r=t.padding??12,a=t.lineNumbers===!1?0:(String(n.length).length+2)*o,l=Math.max(1,...n.map(L=>L.length)),c=t.width??r*2+a+l*o,h=r*2+n.length*i,u=t.x+r+a,d=new Set(t.hidden??[]),f=t.language??"plain";if(!Lo.includes(f))throw new Error(`codePanel: ${dt("language",f,Lo)}`);const p=n.map(L=>Kf(L,f).flatMap(z=>Array.from(z.text,()=>e[z.kind]))),g=Vn(),m=Xs(g),w=[],v=new Map,k=[],b=[],E=L=>{if(!Number.isInteger(L)||L<1||L>n.length)throw new Error(`codePanel: no line ${L} (it has ${n.length})`)},$=g.tween,S=g.last,x=(L,z,O,P,H,W=300)=>{E(L),$(`line.${L}.${z}`,O,P,H,W)},M=(L,z)=>w.filter(O=>O.line<L&&O.closed<=z).length,T=Mt,I=L=>t.y+r+(L-1)*i,A=L=>Array.isArray(L)?L:[L],_=(L,z,O)=>{let P=-1;for(let H=0;H<O;H++)if(P=n[L-1].indexOf(z,P+1),P<0)throw new Error(`codePanel: line ${L} has no ${O>1?`${O}th `:""}"${z}"`);return P},C={};n.forEach((L,z)=>{const O=z+1;C[`line.${O}.highlight`]=0,C[`line.${O}.strike`]=0,C[`line.${O}.wipe`]=0,C[`line.${O}.reveal`]=d.has(O)?0:1,C[`line.${O}.shift`]=0});const N={type:"custom",x:t.x,y:t.y,width:c,height:h,props:C,about:{kind:"code panel",summary:`${n.length} lines of ${f} code. Its lines and words are places in the scene (line(), token(), spot()); its edits are methods that record tracks (tracks()).`,get props(){return iv(Object.keys(C))},actions:Tl},draw(L,z){const O=z.props??{},P=D=>Number(O[D]??C[D]),H=r+a,W=D=>r+(D-1)*i-P(`line.${D}.shift`)*i;L.fillStyle=e.background,jf(L,0,0,c,h,8),L.fill(),L.font=`${s}px ${e.font}`,L.textBaseline="middle",L.textAlign="left";const q=(D,K,V,F,X)=>{const j=n[D-1];for(let Q=K;Q<V;Q++)j[Q]!==" "&&(L.fillStyle=p[D-1][Q],L.fillText(j[Q],F+(Q-K)*o,X))};L.save(),jf(L,0,0,c,h,8),L.clip(),n.forEach((D,K)=>{const V=K+1,F=P(`line.${V}.wipe`);if(F>=1)return;const X=W(V),j=X+i/2,Q=Math.max(1,D.length)*o,et=Math.round(P(`line.${V}.reveal`)*D.length),rt=v.get(V)??{style:"wipe",from:"left"};L.save(),F>0&&sv(L,rt,F,{left:H-a,top:X,width:a+Q+o,height:i},c);const at=P(`line.${V}.highlight`);at>0&&(L.globalAlpha*=Math.min(1,at),L.fillStyle=e.highlight,L.fillRect(H-o/2,X,Q+o,i),L.globalAlpha/=Math.min(1,at)),a>0&&et>0&&(L.fillStyle=e.gutter,L.textAlign="right",L.fillText(String(V),H-o,j),L.textAlign="left");const R=[...k.filter(st=>st.line===V).map(st=>({column:st.column,length:st.text.length,piece:st,insert:void 0})),...b.filter(st=>st.line===V).map(st=>({column:st.column,length:0,piece:void 0,insert:st}))].sort((st,lt)=>st.column-lt.column||st.length-lt.length);let J=0,nt=H;for(const st of R){q(V,J,Math.min(st.column,et),nt,j),nt+=(st.column-J)*o;let lt=st.length,tt="";if(st.piece){const U=st.piece.written??"",it=P(`piece.${st.piece.id}.write`);U&&it>0?(tt=U.slice(0,Math.round(it*U.length)),lt=st.length+(U.length-st.length)*Math.min(1,it*2)):lt=st.length*(1-P(`piece.${st.piece.id}.away`))}else st.insert&&(lt=st.insert.chars*P(`insert.${st.insert.id}.open`),st.insert.text&&(tt=st.insert.text.slice(0,Math.round(P(`insert.${st.insert.id}.type`)*st.insert.text.length))));L.fillStyle=e.text;for(let U=0;U<tt.length;U++)tt[U]!==" "&&L.fillText(tt[U],nt+U*o,j);nt+=lt*o,J=st.column+st.length}q(V,J,Math.max(J,et),nt,j);const ot=P(`line.${V}.strike`);ot>0&&(L.strokeStyle=e.strike,L.lineWidth=Math.max(1.5,s/10),L.beginPath(),L.moveTo(H,j),L.lineTo(H+Q*Math.min(1,ot),j),L.stroke()),L.restore()});for(const D of k){const K=P(`piece.${D.id}.opacity`);if(K<=0||P(`line.${D.line}.wipe`)>=1)continue;const V=H+(D.column+D.text.length/2)*o+P(`piece.${D.id}.x`),F=W(D.line)+i/2+P(`piece.${D.id}.y`);L.save(),L.globalAlpha=Math.min(1,K),L.translate(V,F),L.rotate(P(`piece.${D.id}.rotate`)*Math.PI/180),q(D.line,D.column,D.column+D.text.length,-D.text.length*o/2,0),L.restore()}L.restore()}},B=L=>{const{kind:z,rest:O}=gn(L),P=H=>qe("codePanel",L,Us,H);if(z==="box"){if(O)throw P("box takes no arguments");return{kind:z}}if(z==="line"){if(!/^\d+$/.test(O))throw P("write it line:N");return{kind:z,n:Number(O)}}if(z==="token"){const H=/^(\d+)(?:#(\d+))?:(.+)$/.exec(O);if(!H)throw P("write it token:N:TEXT, or token:N#K:TEXT for the Kth");return{kind:z,n:Number(H[1]),occurrence:H[2]?Number(H[2]):1,text:H[3]}}if(z==="spot"){const H=/^(\d+):(\d+)(?::(\d+))?$/.exec(O);if(!H)throw P("write it spot:N:C, or spot:N:C:W for W characters");return{kind:z,n:Number(H[1]),column:Number(H[2]),width:H[3]?Number(H[3]):1}}throw P()},G=(L,z,O,P=!1)=>{const H=Array.isArray(z)?z:[z];if(H.length===0||P&&H.length>1)throw new Error(`codePanel.edit: ${L} takes ${P?"one":"at least one"} ${O} anchor`);return H.map(W=>{const q=B(W);if(q.kind!==O)throw new Error(`codePanel.edit: ${L} takes ${O} anchors (${O}:…), not "${W}"`);return q})},Z=(L,z)=>{if(typeof z.text!="string")throw new Error(`codePanel.edit: ${L} needs \`text\` (the text to write)`);return z.text},Y={kind:"code",about:Us,target:N,lines:n,box:T(t.x,t.y,c,h),line(L,z=1/0){return E(L),T(u,I(L)-M(L,z)*i,Math.max(1,n[L-1].length)*o,i)},token(L,z,O=1,P=1/0){E(L);const H=_(L,z,O);return T(u+H*o,I(L)-M(L,P)*i,z.length*o,i)},highlight(L,z){for(const O of A(L)){const P=S(`line.${O}.highlight`,0);x(O,"highlight",P,z.on===!1?0:1,z,200)}return Y},strike(L,z){for(const O of A(L))x(O,"strike",S(`line.${O}.strike`,0),1,z);return Y},remove(L,z){const O=A(L),P=z.style??"wipe";if(!Ho.includes(P))throw new Error(`codePanel.remove: ${dt("style",P,Ho)}`);const H=P==="wipe"?300:450,W=z.at+(z.duration??H),q=z.close??250;for(const D of O)x(D,"wipe",0,1,{...z,easing:z.easing??(P==="fly"?"ease-in":void 0)},H),v.set(D,{style:P,from:z.from??"left"}),w.push({line:D,closed:W+q});for(let D=1;D<=n.length;D++){if(O.includes(D))continue;const K=O.filter(F=>F<D).length;if(K===0)continue;const V=S(`line.${D}.shift`,0);x(D,"shift",V,V+K,{at:W,duration:q,easing:"ease-in-out"})}return Y},type(L,z){return x(L,"reveal",0,1,{duration:n[L-1].length*45,...z}),Y},piece(L,z,O=1){if(typeof L=="string"){const D=B(L);if(D.kind!=="token")throw new Error(`codePanel.piece: a piece is a word, token:N:TEXT, not "${L}"`);return Y.piece(D.n,D.text,D.occurrence)}const P=L;if(z===void 0)throw new Error('codePanel.piece: which word? piece(n, text) or piece("token:N:TEXT")');E(P);const H=_(P,z,O),W=k.find(D=>D.line===P&&D.column===H&&D.text===z);if(W)return W;if(k.some(D=>D.line===P&&H<D.column+D.text.length&&D.column<H+z.length))throw new Error(`codePanel: "${z}" on line ${P} overlaps another piece`);const q={id:k.length+1,line:P,column:H,text:z,home:Y.token(P,z,O,0)};k.push(q);for(const D of["x","y","rotate","write","away"])C[`piece.${q.id}.${D}`]=0;return C[`piece.${q.id}.opacity`]=1,q},follow(L,z){return m.follow(L,z),Y},fling(L,z){return m.fling(L,z),Y},move(L,z){return m.move(L,z),Y},write(L,z,O){return L.written=z,$(`piece.${L.id}.write`,0,1,{duration:Math.max(1,z.length)*70,...O}),Y},spot(L,z,O=1,P=1/0){E(L);const H=b.filter(W=>W.line===L&&W.column<=z&&W.at<=P).reduce((W,q)=>W+q.chars,0);return T(u+(z+H)*o,I(L)-M(L,P)*i,O*o,i)},insert(L,z,O,P){E(L);const H={id:b.length+1,line:L,column:z,chars:O.length,text:O,at:P.at};b.push(H),C[`insert.${H.id}.open`]=0,C[`insert.${H.id}.type`]=0;const W=P.duration??O.length*70;return $(`insert.${H.id}.open`,0,1,{at:P.at,duration:W*.6,easing:"ease-out"}),$(`insert.${H.id}.type`,0,1,{at:P.at,duration:W}),Y},drop(L,z,O,P){E(z);const H=P.duration??250,W=z===L.line,q=P.easing??(W?"linear":"ease-out"),D=Y.landing(L,z,O,P.at),K={id:b.length+1,line:z,column:O,chars:L.text.length,at:P.at};return b.push(K),C[`insert.${K.id}.open`]=0,$(`insert.${K.id}.open`,0,1,{at:P.at,duration:H,easing:W?q:"ease-out"}),$(`piece.${L.id}.away`,S(`piece.${L.id}.away`,0),1,{at:P.at,duration:H,easing:W?q:"ease-in-out"}),m.cutAfter(L,P.at),Y.move(L,{at:P.at,duration:H,easing:q,to:{x:D.x,y:D.y}}),$(`piece.${L.id}.rotate`,g.valueAt(`piece.${L.id}.rotate`,P.at),0,{at:P.at,duration:H}),Y},landing(L,z,O,P=1/0){const H=Y.spot(z,O,L.text.length,P),W=z===L.line&&O>L.column?L.text.length*o:0;return T(H.left-W,H.top,H.width,H.height)},ride(L,z,O){const P=n.map((H,W)=>{const q=g.keys(`line.${W+1}.shift`)??[];return{top:I(W+1),offset:D=>-_o(q,D)*i,windows:Jn(q)}});return Co(L,z,{ground:O.ground,every:O.every??ze,floors:P})},tracks:g.tracks,anchor(L,z=1/0){const O=B(L);return O.kind==="box"?Y.box:O.kind==="line"?Y.line(O.n,z):O.kind==="token"?Y.token(O.n,O.text,O.occurrence,z):Y.spot(O.n,O.column,O.width,z)},edit(L,z,O){const P=()=>G(L,z,"line").map(H=>H.n);if(L==="highlight")return Y.highlight(P(),O);if(L==="strike")return Y.strike(P(),O);if(L==="remove")return Y.remove(P(),O);if(L==="type"){for(const H of P())Y.type(H,O);return Y}if(L==="insert"){const[H]=G(L,z,"spot",!0);return Y.insert(H.n,H.column,Z(L,O),O)}if(L==="write"||L==="drop"||L==="move"||L==="fling"){const[H]=G(L,z,"token",!0),W=Y.piece(H.n,H.text,H.occurrence);if(L==="write")return Y.write(W,Z(L,O),O);if(L==="fling")return Y.fling(W,O);if(L==="drop"){const D=typeof O.into=="string"?B(O.into):void 0;if(D?.kind!=="spot")throw new Error("codePanel.edit: drop needs `into`, a spot anchor (spot:N:C)");return Y.drop(W,D.n,D.column,O)}const q=typeof O.to=="string"?Y.anchor(O.to,O.at):O.to;if(!q||typeof q.x!="number"||typeof q.y!="number")throw new Error("codePanel.edit: move needs `to`, an anchor name or { x, y }");return Y.move(W,{...O,to:q})}throw Gs("codePanel",L,Us)}};return Y}function sv(t,e,n,s,i){if(e.style==="wipe"){t.beginPath(),e.from==="right"?t.rect(s.left,s.top,s.width*(1-n),s.height):t.rect(s.left+n*s.width,s.top,s.width*(1-n),s.height),t.clip();return}const o=ev*n;if(o>.2&&"filter"in t&&(t.filter=`blur(${o.toFixed(1)}px)`),t.globalAlpha*=1-n,e.style==="fly"){const r=e.from==="right"?-1:1;t.translate(r*n*tv*i,0),t.rotate(r*n*.08)}else{const r=1+.08*n,a=s.left+s.width/2,l=s.top+s.height/2;t.translate(a,l),t.scale(r,r),t.translate(-a,-l)}}const Tl={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 iv(t){const e=[[/^line\.\d+\.highlight$/,{description:"How much the line is tinted",unit:"0..1",min:0,max:1}],[/^line\.\d+\.strike$/,{description:"How far the strike-through has drawn",unit:"0..1",min:0,max:1}],[/^line\.\d+\.wipe$/,{description:"How far the line has gone (wiped, flown off or blurred)",unit:"0..1",min:0,max:1}],[/^line\.\d+\.reveal$/,{description:"How much of the line is typed in",unit:"0..1",min:0,max:1}],[/^line\.\d+\.shift$/,{description:"How many rows the line has moved up",unit:"rows"}],[/^piece\.\d+\.(x|y)$/,{description:"The piece moved from its home",unit:"px"}],[/^piece\.\d+\.rotate$/,{description:"The piece turned",unit:"degrees"}],[/^piece\.\d+\.opacity$/,{description:"How opaque the piece is",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.write$/,{description:"How much of the text written into its place is typed",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.away$/,{description:"How far its old place has closed",unit:"0..1",min:0,max:1}],[/^insert\.\d+\.open$/,{description:"How much room the insert has opened",unit:"0..1",min:0,max:1}],[/^insert\.\d+\.type$/,{description:"How much of the inserted text is typed",unit:"0..1",min:0,max:1}]],n={};for(const s of t){const i=e.find(([o])=>o.test(s));i&&(n[s]=i[1])}return n}function jf(t,e,n,s,i,o){t.beginPath(),t.moveTo(e+o,n),t.arcTo(e+s,n,e+s,n+i,o),t.arcTo(e+s,n+i,e,n+i,o),t.arcTo(e,n+i,e,n,o),t.arcTo(e,n,e+s,n,o),t.closePath()}const Ro={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:[]};Ro.typescript=[...Ro.javascript,"enum","interface","type","implements","private","public","readonly","keyof","as","declare","namespace"];const Lo=Object.keys(Ro),ov={go:"//",rust:"//",csharp:"//",javascript:"//",typescript:"//",python:"#",plain:null};function Kf(t,e){const n=new Set(Ro[e]),s=ov[e],i=[],o=(a,l)=>{const c=i[i.length-1];c&&c.kind===l?c.text+=a:i.push({text:a,kind:l})};let r=0;for(;r<t.length;){const a=t[r];if(e!=="plain"&&s&&t.startsWith(s,r)){o(t.slice(r),"comment");break}if(e!=="plain"&&(a==='"'||a==="'"||a==="`")){let h=r+1;for(;h<t.length&&t[h]!==a;)h+=t[h]==="\\"?2:1;o(t.slice(r,h+1),"string"),r=h+1;continue}const l=/^[A-Za-z_][A-Za-z0-9_]*/.exec(t.slice(r));if(l){o(l[0],n.has(l[0])?"keyword":"text"),r+=l[0].length;continue}const c=/^\d[\d_.]*/.exec(t.slice(r));if(c&&e!=="plain"){o(c[0],"number"),r+=c[0].length;continue}o(a,"text"),r++}return i}const xl='"Patrick Hand", "Segoe Print", "Bradley Hand", "Comic Sans MS", "Chalkboard SE", cursive',Vs={whiteboard:{background:"#f7f7f2",frame:"#b8bcc4",ink:"#1f2a44",colors:{ink:"#1f2a44",red:"#d03b3b",blue:"#2f6fd0",green:"#2e9a52",orange:"#e07b1a"},font:xl,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:xl,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:xl,stroke:.08,opacity:1,rule:{color:"#c9d6ec",spacing:1.55,margin:"#f0a3a3"}}},El=["circle","box","underline","arrow"],Me={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"}},Xf=90,Gf=300,rv=.3;function av(t){const e=typeof t.theme=="string"?t.theme:"whiteboard";if(!(e in Vs))throw new Error(`whiteboard: ${dt("theme",e,Object.keys(Vs))}`);const n=typeof t.theme=="object"?{...Vs.whiteboard,...t.theme}:Vs[e],s=t.fontSize??28,i=t.charWidth??.55,o=b=>b===void 0?n.ink:n.colors[b]??b,r=b=>Mt(t.x+b.left,t.y+b.top,b.width,b.height),a=Vn(),l=Xs(a),c={},h=new Map,u=[],d=[],f=(b,E,$,S)=>{const x=h.get(b);if(!x||x.kind!=="text")throw qe("whiteboard",S,Me,`there is no text "${b}" (texts: ${p().join(", ")||"none"})`);let M=-1;for(let I=0;I<$;I++)if(M=x.item.text.indexOf(E,M+1),M<0)throw qe("whiteboard",S,Me,`text "${b}" has no ${$>1?`${$}th `:""}"${E}"`);const T=x.size*i;return{column:M,box:Mt(x.box.left+M*T,x.box.top,E.length*T,x.box.height)}},p=()=>[...h.values()].filter(b=>b.kind==="text").map(b=>b.item.id),g=b=>{const{kind:E,rest:$}=gn(b),S=x=>qe("whiteboard",b,Me,x);if(E==="box"){if($)throw S("box takes no arguments");return{kind:E}}if(E==="text"||E==="mark"){if(!$)throw S(`write it ${E}:ID`);return{kind:E,id:$}}if(E==="term"){const x=/^([^:#]+)(?:#(\d+))?:(.+)$/.exec($);if(!x)throw S("write it term:ID:TEXT, or term:ID#K:TEXT for the Kth");return{kind:E,id:x[1],occurrence:x[2]?Number(x[2]):1,text:x[3]}}throw S()},m=b=>{const E=g(b);if(E.kind==="box")return Mt(0,0,t.width,t.height);if(E.kind==="term")return f(E.id,E.text,E.occurrence,b).box;const $=h.get(E.id);if(!$||$.kind!==E.kind){const S=[...h.values()].filter(x=>x.kind===E.kind).map(x=>x.item.id);throw qe("whiteboard",b,Me,`there is no ${E.kind} "${E.id}" (${E.kind}s: ${S.join(", ")||"none"})`)}return $.box};for(const b of t.items??[]){if(!b||typeof b.id!="string"||!b.id||/[:#]/.test(b.id))throw new Error(`whiteboard: every item needs an \`id\` without ":" or "#" (got ${JSON.stringify(b?.id)})`);if(h.has(b.id))throw new Error(`whiteboard: two items are called "${b.id}"`);if("text"in b){if(!Array.isArray(b.at)||b.at.length!==2||!b.at.every(I=>typeof I=="number"))throw new Error(`whiteboard: text "${b.id}" needs \`at\`, [x, y] from the board's top-left`);const M=b.size??s,T=Mt(b.at[0],b.at[1],Math.max(1,b.text.length)*M*i,M*1.3);h.set(b.id,{kind:"text",item:b,size:M,color:o(b.color),box:T}),c[`text.${b.id}.write`]=b.hidden?0:1,c[`text.${b.id}.erase`]=0;continue}if(!El.includes(b.mark))throw new Error(`whiteboard: mark "${b.id}": ${dt("mark",b.mark,El)}`);const E=b.mark==="arrow"?["from","to"]:["around"];for(const M of E)if(typeof b[M]!="string")throw new Error(`whiteboard: ${b.mark} "${b.id}" needs \`${M}\`, a place on the board (an item before it)`);const $=new Set([b.from,b.to].filter(M=>typeof M=="string").map(M=>M.split(":")[1])),S=b.mark==="arrow"?[...h.values()].filter(M=>M.kind==="text"&&!$.has(M.item.id)).map(M=>M.box):[],x=lv(b,m,s,S);h.set(b.id,{kind:"mark",item:b,color:o(b.color),points:x,box:uv(x)}),c[`mark.${b.id}.draw`]=b.hidden?0:1,c[`mark.${b.id}.erase`]=0}const w=b=>u.filter(E=>E.item===b),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 dv(Object.keys(c))},actions:Me.edits},draw(b,E){const $=E.props??{},S=x=>Number($[x]??c[x]??0);if(b.save(),b.fillStyle=n.background,Jf(b,0,0,t.width,t.height,10),b.fill(),b.lineWidth=Math.max(4,t.width*.012),b.strokeStyle=n.frame,b.stroke(),n.rule){b.save(),b.beginPath(),Jf(b,0,0,t.width,t.height,10),b.clip(),b.lineWidth=1,b.strokeStyle=n.rule.color;const x=s*(n.rule.spacing??1.55);for(let M=x;M<t.height;M+=x)b.beginPath(),b.moveTo(0,M),b.lineTo(t.width,M),b.stroke();n.rule.margin&&(b.strokeStyle=n.rule.margin,b.beginPath(),b.moveTo(s*2.2,0),b.lineTo(s*2.2,t.height),b.stroke()),b.restore()}b.textAlign="center",b.textBaseline="middle",b.lineCap="round",b.lineJoin="round",b.globalAlpha=n.opacity;for(const x of h.values()){if(b.save(),Al(b,x.box,S(`${x.kind}.${x.item.id}.erase`)),x.kind==="text"){const M=w(x.item.id),T=S(`text.${x.item.id}.write`)*x.item.text.length;b.font=`${x.size}px ${n.font}`,b.fillStyle=x.color;for(let I=0;I<Math.ceil(T);I++)x.item.text[I]===" "||M.some(A=>I>=A.column&&I<A.column+A.text.length)||(b.globalAlpha=n.opacity*Math.min(1,T-I),b.fillText(x.item.text[I],x.box.left+(I+.5)*x.size*i,x.box.y))}else Vf(b,x.points,S(`mark.${x.item.id}.draw`),x.color,s*n.stroke,x.item.mark==="arrow");b.restore()}for(const x of d){const M=S(`strike.${x.id}.draw`);if(M<=0)continue;const{box:T}=x,I=T.height*.15;Vf(b,[{x:T.left-3,y:T.y+I},{x:T.right+3,y:T.y-I}],M,n.colors.red??n.ink,s*n.stroke*.8,!1)}for(const x of u){const M=h.get(x.item),T=M.size*i;b.font=`${M.size}px ${n.font}`,b.fillStyle=M.color;const I=x.written;if(I){const N=S(`piece.${x.id}.write`)*I.length,B=x.home.x-t.x-I.length*T/2;for(let G=0;G<Math.ceil(N);G++)I[G]!==" "&&(b.globalAlpha=n.opacity*Math.min(1,N-G),b.fillText(I[G],B+(G+.5)*T,x.home.y-t.y))}const A=S(`piece.${x.id}.opacity`)*Math.min(1,S(`text.${x.item}.write`)*M.item.text.length-x.column);if(A<=0)continue;b.save();const _={x:x.home.x-t.x,y:x.home.y-t.y},C={x:S(`piece.${x.id}.x`),y:S(`piece.${x.id}.y`)};Al(b,Mt(_.x+C.x-x.home.width/2,_.y+C.y-x.home.height/2,x.home.width,x.home.height),S(`piece.${x.id}.erase`)),Math.hypot(C.x,C.y)<1&&Al(b,M.box,S(`text.${x.item}.erase`)),b.globalAlpha=n.opacity*Math.min(1,A),b.translate(_.x+C.x,_.y+C.y),b.rotate(S(`piece.${x.id}.rotate`)*Math.PI/180);for(let N=0;N<x.text.length;N++)x.text[N]!==" "&&b.fillText(x.text[N],(N+.5-x.text.length/2)*T,0);b.restore()}b.restore()}},k={kind:"board",about:Me,target:v,box:Mt(t.x,t.y,t.width,t.height),anchor(b){return r(m(b))},piece(b){const E=g(b);if(E.kind!=="term")throw new Error(`whiteboard.piece: a piece is a term, term:ID:TEXT, not "${b}"`);const{column:$,box:S}=f(E.id,E.text,E.occurrence,b),x=u.find(T=>T.item===E.id&&T.column===$&&T.text===E.text);if(x)return x;if(u.some(T=>T.item===E.id&&$<T.column+T.text.length&&T.column<$+E.text.length))throw new Error(`whiteboard: "${E.text}" in "${E.id}" overlaps another piece`);const M={id:u.length+1,item:E.id,column:$,text:E.text,home:r(S)};u.push(M);for(const T of["x","y","rotate","erase","write"])c[`piece.${M.id}.${T}`]=0;return c[`piece.${M.id}.opacity`]=1,M},edit(b,E,$){const S=Array.isArray(E)?E:[E];if(S.length===0)throw new Error(`whiteboard.edit: ${b} takes at least one anchor`);const x=S.map(I=>({name:I,anchor:g(I)}));for(const{name:I}of x)m(I);const M=(I,A=!1)=>{const _=x.find(C=>!I.includes(C.anchor.kind));if(_)throw new Error(`whiteboard.edit: ${b} takes ${I.join(" or ")} anchors, not "${_.name}"`);if(A&&x.length>1)throw new Error(`whiteboard.edit: ${b} takes one ${I.join(" or ")} anchor`)},T=()=>k.piece(x[0].name);if(b==="write"){if(x.some(I=>I.anchor.kind==="term")){if(M(["term"],!0),typeof $.text!="string")throw new Error("whiteboard.edit: write into a term needs `text` (the new text)");const I=T();return I.written=$.text,a.tween(`piece.${I.id}.write`,0,1,{duration:Math.max(Gf,$.text.length*Xf),...$}),k}M(["text"]);for(const{anchor:I}of x){const A=I.id,_=h.get(A).item.text;a.tween(`text.${A}.write`,0,1,{duration:Math.max(Gf,_.length*Xf),...$})}return k}if(b==="draw"){M(["mark"]);for(const{anchor:I}of x)a.tween(`mark.${I.id}.draw`,0,1,{duration:500,...$});return k}if(b==="erase"){M(["text","term","mark"]);for(const I of x){const A=I.anchor.kind==="term"?`piece.${k.piece(I.name).id}.erase`:`${I.anchor.kind}.${I.anchor.id}.erase`;a.tween(A,0,1,{duration:400,...$})}return k}if(b==="strike"){M(["text","term"]);for(const I of x){const A={id:d.length+1,box:m(I.name)};d.push(A),c[`strike.${A.id}.draw`]=0,a.tween(`strike.${A.id}.draw`,0,1,{duration:250,...$})}return k}if(b==="move"){M(["term"],!0);const I=typeof $.to=="string"?k.anchor($.to):$.to;if(!I||typeof I.x!="number"||typeof I.y!="number")throw new Error("whiteboard.edit: move needs `to`, an anchor name or { x, y }");return k.move(T(),{...$,to:I})}if(b==="fling")return M(["term"],!0),k.fling(T(),$);throw Gs("whiteboard",b,Me)},follow(b,E){return l.follow(b,E),k},fling(b,E){return l.fling(b,E),k},move(b,E){return l.move(b,E),k},ride(b){return b},tracks:a.tracks};return k}function lv(t,e,n,s=[]){const i=_e(Kt(t.id)),o=g=>(i.next()*2-1)*g,r=n*rv;if(t.mark==="arrow"){const g=e(t.from),m=e(t.to),w=Uf(g,m,r*.6),v=Uf(m,g,r*.6),k=Math.hypot(v.x-w.x,v.y-w.y),b=hv(w,v);let E=k*(.06+o(.04));if(t.bend!==void 0)E=k*t.bend;else{const x=cv(w,v,b,s,r);x!==0&&(E=x)}const $={x:(w.x+v.x)/2+b.x*E,y:(w.y+v.y)/2+b.y*E},S=[];for(let x=0;x<=24;x++){const M=x/24;S.push({x:(1-M)**2*w.x+2*(1-M)*M*$.x+M*M*v.x,y:(1-M)**2*w.y+2*(1-M)*M*$.y+M*M*v.y})}return S}const a=e(t.around);if(t.mark==="underline"){const g=a.bottom+r*.4;return[{x:a.left-r*.3,y:g+o(2)},{x:a.x,y:g+2+o(2)},{x:a.right+r*.5,y:g-1+o(3)}]}if(t.mark==="box"){const g=a.left-r,m=a.right+r,w=a.top-r*.6,v=a.bottom+r*.6,k=(E,$)=>({x:E+o(r*.2),y:$+o(r*.2)}),b=k(g,w);return[b,k(m,w),k(m,v),k(g,v),b,{x:b.x+r*.8,y:b.y+o(2)}]}const l=a.width/2+r,c=a.height/2+r*.6,h=-2.2+o(.3),u=i.next()*Math.PI*2,d=1.12,f=64,p=[];for(let g=0;g<=f*d;g++){const m=g/f,w=h+m*Math.PI*2,v=1+.035*Math.sin(m*Math.PI*4+u)+.06*m;p.push({x:a.x+Math.cos(w)*l*v,y:a.y+Math.sin(w)*c*v})}return p}function cv(t,e,n,s,i){const o=Math.hypot(e.x-t.x,e.y-t.y);if(o<1e-6)return 0;const r={x:(e.x-t.x)/o,y:(e.y-t.y)/o};let a=0,l=0;for(const c of s){const u=[{x:c.left,y:c.top},{x:c.right,y:c.top},{x:c.right,y:c.bottom},{x:c.left,y:c.bottom}].map(p=>({t:(p.x-t.x)*r.x+(p.y-t.y)*r.y,n:(p.x-t.x)*n.x+(p.y-t.y)*n.y})),d=u.some(p=>p.t>0&&p.t<o),f=u.some(p=>p.n>0)&&u.some(p=>p.n<0);!d||!f||(a=Math.max(a,...u.map(p=>p.n)),l=Math.min(l,...u.map(p=>p.n)))}return a===0&&l===0?0:a<=-l?2*(a+i):2*(l-i)}function Uf(t,e,n){const s=e.x-t.x,i=e.y-t.y;if(s===0&&i===0)return{x:t.x,y:t.y};const o=Math.min(s===0?1/0:(t.width/2+n)/Math.abs(s),i===0?1/0:(t.height/2+n)/Math.abs(i));return{x:t.x+s*o,y:t.y+i*o}}function hv(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 uv(t){const e=t.map(o=>o.x),n=t.map(o=>o.y),s=Math.min(...e),i=Math.min(...n);return Mt(s,i,Math.max(...e)-s,Math.max(...n)-i)}function Vf(t,e,n,s,i,o){if(n<=0||e.length<2)return;const r=[0];for(let p=1;p<e.length;p++)r.push(r[p-1]+Math.hypot(e[p].x-e[p-1].x,e[p].y-e[p-1].y));const l=r[r.length-1]*Math.min(1,n/(o?.85:1));t.strokeStyle=s,t.lineWidth=i,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let p=1;p<e.length;p++){if(r[p]<=l){t.lineTo(e[p].x,e[p].y);continue}const g=(l-r[p-1])/(r[p]-r[p-1]||1);t.lineTo(e[p-1].x+(e[p].x-e[p-1].x)*g,e[p-1].y+(e[p].y-e[p-1].y)*g);break}if(t.stroke(),!o||n<=.85)return;const c=(n-.85)/.15,h=e[e.length-1],u=e[e.length-3]??e[0],d=Math.atan2(h.y-u.y,h.x-u.x),f=i*4.5*c;t.beginPath();for(const p of[-1,1])t.moveTo(h.x,h.y),t.lineTo(h.x-Math.cos(d+p*.45)*f,h.y-Math.sin(d+p*.45)*f);t.stroke()}function Al(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 Jf(t,e,n,s,i,o){t.beginPath(),t.moveTo(e+o,n),t.arcTo(e+s,n,e+s,n+i,o),t.arcTo(e+s,n+i,e,n+i,o),t.arcTo(e,n+i,e,n,o),t.arcTo(e,n,e+s,n,o),t.closePath()}function dv(t){const e=[[/^text\..+\.write$/,{description:"How much of the text is written",unit:"0..1",min:0,max:1}],[/^(text|mark)\..+\.erase$/,{description:"How far it has been wiped off, left to right",unit:"0..1",min:0,max:1}],[/^mark\..+\.draw$/,{description:"How much of the mark is drawn",unit:"0..1",min:0,max:1}],[/^strike\.\d+\.draw$/,{description:"How far the strike-through has drawn",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.(x|y)$/,{description:"The term moved from its home",unit:"px"}],[/^piece\.\d+\.rotate$/,{description:"The term turned",unit:"degrees"}],[/^piece\.\d+\.opacity$/,{description:"How opaque the term is",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.erase$/,{description:"How far the term has been wiped off",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.write$/,{description:"How much of the text written into its place is written",unit:"0..1",min:0,max:1}]],n={};for(const s of t){const i=e.find(([o])=>o.test(s));i&&(n[s]=i[1])}return n}const Pl=["bar","line","pie","donut"],Zf='system-ui, -apple-system, "Segoe UI", sans-serif',Js={light:{background:"#ffffff",text:"#3b4252",grid:"#d8dee9",color:"#4c7bd9",highlight:"#e8833a",palette:["#4c7bd9","#3fa66b","#b05cc9","#d9c04c","#4cb8c4","#d95c6f","#8a7a5a","#6b7a99"],font:Zf},dark:{background:"#1e2230",text:"#cdd6f4",grid:"#3a4055",color:"#89b4fa",highlight:"#fab387",palette:["#89b4fa","#a6e3a1","#cba6f7","#f9e2af","#94e2d5","#f38ba8","#b4a58a","#9399b2"],font:Zf}},pn={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)"}},fv=600,gv=500,pv=200,mv=400,yv=.14,bv=Math.PI*2;function wv(t){if(!Pl.includes(t.kind))throw new Error(`chart: ${dt("kind",t.kind,Pl)}`);const e=typeof t.theme=="string"?t.theme:"light";if(!(e in Js))throw new Error(`chart: ${dt("theme",e,Object.keys(Js))}`);const n=typeof t.theme=="object"?{...Js.light,...t.theme}:Js[e];if(!Array.isArray(t.data)||t.data.length===0)throw new Error("chart: `data` needs at least one { id, value }");const s=t.kind,i=s==="pie"||s==="donut",o=Array.isArray(t.series)&&t.series.length>1,r=Array.isArray(t.series)&&t.series.length>0?t.series:[{id:"value"}];if(i&&o)throw new Error(`chart: a ${s} shows one series (got ${r.length}); make a chart per series`);const a=new Set;for(const R of r){if(typeof R?.id!="string"||!R.id||/[:.]/.test(R.id))throw new Error(`chart: every series needs an \`id\` without ":" or "." (got ${JSON.stringify(R?.id)})`);if(a.has(R.id))throw new Error(`chart: two series are called "${R.id}"`);a.add(R.id)}const l=new Map(r.map((R,J)=>[R.id,J])),c=R=>r[l.get(R)].color??(l.get(R)===0?n.color:n.palette[l.get(R)%n.palette.length]),h=new Set,u=(R,J)=>{const nt=R.values?.[J.id]??(t.series?void 0:R.value)??R.value;if(typeof nt!="number"||!Number.isFinite(nt))throw new Error(o?`chart: "${R.id}" needs a value for series "${J.id}" (\`values: { ${J.id}: … }\`)`:`chart: "${R.id}" needs a \`value\`, a number`);return nt};for(const R of t.data){if(typeof R?.id!="string"||!R.id||/[:.]/.test(R.id))throw new Error(`chart: every datum needs an \`id\` without ":" or "." (got ${JSON.stringify(R?.id)})`);if(h.has(R.id))throw new Error(`chart: two data are called "${R.id}"`);for(const J of r)u(R,J);h.add(R.id)}const d=s==="bar"?"bar":s==="line"?"point":"slice",f=Math.max(...t.data.flatMap(R=>r.map(J=>u(R,J)))),p=i?t.data.reduce((R,J)=>R+u(J,r[0]),0):t.max??Qf(f*1.1);if(!i&&!(p>0))throw new Error(`chart: \`max\` must be above 0 (got ${p})`);const g=Math.max(10,Math.min(16,t.height/20)),m=o&&t.legend!==!1,w=i?void 0:t.axis?.x,v=i?void 0:t.axis?.y,k=t.title?g*2.3:g*.5,b={left:g*3.6+(v?g*1.5:0),right:t.width-g,top:(t.title?g*3:g*1.6)+(m?g*1.6:0),bottom:t.height-g*2.4-(w?g*1.4:0)},E=b.bottom-b.top,$=(b.right-b.left)/t.data.length,S=o?$*.72/r.length:$*.6,x=o?S*.86:S,M=Math.max(4,g*.35),T=E/p,I=new Map(t.data.map((R,J)=>[R.id,J])),A=R=>b.left+$*(I.get(R)+.5),_=(R,J)=>o?A(R)-$*.36+S*l.get(J)+(S-x)/2:A(R)-x/2,C=(R,J)=>_(R,J)+x/2,N=t.height-g*1.2,B={cx:t.width/2,cy:(b.top+N)/2,r:Math.max(10,Math.min(t.width/2,(N-b.top)/2)-g*2.6)},G=s==="donut"?B.r*.55:0,Z=s==="donut"?(G+B.r)/2:B.r*.62,Y=new Map;if(m){let R=b.right;for(const J of[...r].reverse()){const nt=J.label??J.id,ot=g*.62*nt.length+g*1.9;Y.set(J.id,Mt(R-ot,k,ot,g*1.4)),R-=ot+g*.6}}const L=Vn(),z=Xs(L),O={},P=(R,J,nt)=>o?`${d}.${R}.${J}.${nt}`:`${d}.${R}.${nt}`;for(const R of t.data)for(const J of r)O[P(R.id,J.id,"value")]=u(R,J),O[P(R.id,J.id,"show")]=R.hidden?0:1,O[P(R.id,J.id,"highlight")]=0,i&&(O[P(R.id,J.id,"pull")]=0);const H=(R,J)=>L.keys(R)?.length?_o(L.keys(R),J):O[R],W=(R,J,nt)=>H(P(R,J,"value"),nt)*(s==="bar"?H(P(R,J,"show"),nt):1)*T,q=R=>{const J=r[0].id,nt=t.data.map(tt=>Math.max(0,R(P(tt.id,J,"value")))*Math.max(0,Math.min(1,R(P(tt.id,J,"show"))))),ot=nt.reduce((tt,U)=>tt+U,0),st=new Map;let lt=-Math.PI/2;return t.data.forEach((tt,U)=>{const it=ot>0?bv*nt[U]/ot:0,ut=lt+it/2,gt=Math.max(0,Math.min(1,R(P(tt.id,J,"pull"))))*B.r*yv;st.set(tt.id,{start:lt,sweep:it,mid:ut,out:gt,centre:{x:B.cx+Math.cos(ut)*(Z+gt),y:B.cy+Math.sin(ut)*(Z+gt)}}),lt+=it}),st},D=R=>q(J=>H(J,R)),K=R=>{const{kind:J,rest:nt}=gn(R),ot=st=>qe("chart",R,pn,st);if(J==="box"){if(nt)throw ot("box takes no arguments");return{kind:"box"}}if(J==="legend"){if(!Y.has(nt))throw ot(m?`there is no series "${nt}" (series: ${r.map(st=>st.id).join(", ")})`:"only a chart with several series has a legend");return{kind:"legend",series:nt}}if(J==="bar"||J==="point"||J==="slice"||J==="label"||J==="value"){if(!nt)throw ot(`write it ${J}:ID`);const st=nt.indexOf(":"),lt=st<0?nt:nt.slice(0,st),tt=st<0?r[0].id:nt.slice(st+1);if(!I.has(lt))throw ot(`there is no "${lt}" (data: ${[...I.keys()].join(", ")})`);if(!a.has(tt))throw ot(`there is no series "${tt}" (series: ${r.map(U=>U.id).join(", ")})`);if(J==="label"&&st>=0)throw ot("a label is one per datum: label:ID");if((J==="bar"||J==="point"||J==="slice")&&J!==d)throw ot(`a ${s} chart has ${d}s, not ${J}s: ${d}:${lt}`);return{kind:J,id:lt,series:tt}}throw ot()},V=(R,J)=>{if(R.kind==="box")return Mt(0,0,t.width,t.height);if(R.kind==="legend")return Y.get(R.series);if(i){const tt=D(J).get(R.id),U=Math.max(g*1.5,B.r*.42);if(R.kind==="slice")return Mt(tt.centre.x-U/2,tt.centre.y-U/2,U,U);const it=F(tt);return R.kind==="label"?it:tt.sweep>=.3?Mt(tt.centre.x-g*1.6,tt.centre.y-g*.65,g*3.2,g*1.3):Mt(it.left,it.bottom,it.width,g*1.3)}const nt=R.kind==="label"?A(R.id):C(R.id,R.series),ot=b.bottom-W(R.id,R.series,J);if(R.kind==="bar")return Mt(nt-x/2,ot,x,b.bottom-ot);if(R.kind==="point")return Mt(A(R.id)-M,ot-M,M*2,M*2);if(R.kind==="label")return Mt(nt-$/2,b.bottom+g*.4,$,g*1.4);const st=ot-(s==="line"?M:0)-g*.3,lt=o&&s==="bar"?S:$;return Mt((s==="line"?A(R.id):nt)-lt/2,st-g*1.3,lt,g*1.3)},F=R=>{const J=B.r+R.out+g*.9,nt={x:B.cx+Math.cos(R.mid)*J,y:B.cy+Math.sin(R.mid)*J},ot=g*4.2,st=Math.cos(R.mid),lt=st>.2?nt.x:st<-.2?nt.x-ot:nt.x-ot/2;return Mt(lt,nt.y-g*.7,ot,g*1.4)},X=R=>Mt(t.x+R.left,t.y+R.top,R.width,R.height),j=R=>`${t.prefix??""}${R.toFixed(t.decimals??0)}${t.suffix??""}`,Q=new Map,et={type:"custom",x:t.x,y:t.y,width:t.width,height:t.height,props:O,about:{kind:`${s} chart`,summary:`A ${s} chart of ${t.data.length} values (${t.data.map(R=>R.id).join(", ")})${o?` in ${r.length} series (${r.map(R=>R.id).join(", ")})`:""}${i?"":`, scaled to ${p}`}. Its ${d}s and labels are places in the scene (anchor()); its edits record tracks (edit(), tracks()).`,props:Object.fromEntries(Object.keys(O).map(R=>[R,Mv(R)])),actions:pn.edits},draw(R,J){const nt=J.props??{},ot=tt=>Number(nt[tt]??O[tt]??0);if(R.save(),R.fillStyle=n.background,tg(R,0,0,t.width,t.height,8),R.fill(),R.font=`${g}px ${n.font}`,R.textBaseline="middle",t.title&&(R.fillStyle=n.text,R.textAlign="left",R.font=`600 ${g*1.2}px ${n.font}`,R.fillText(t.title,i?g:b.left,g*1.5),R.font=`${g}px ${n.font}`),m){R.textAlign="left";for(const tt of r){const U=Y.get(tt.id);R.fillStyle=c(tt.id),tg(R,U.left,U.top+g*.25,g*.9,g*.9,2),R.fill(),R.fillStyle=n.text,R.fillText(tt.label??tt.id,U.left+g*1.3,U.top+U.height/2)}}if(i){rt(R,ot),R.restore();return}R.lineWidth=1,R.textAlign="right";for(let tt=0;tt<=4;tt++){const U=b.bottom-E*tt/4;R.strokeStyle=n.grid,R.beginPath(),R.moveTo(b.left,U),R.lineTo(b.right,U),R.stroke(),R.fillStyle=n.text,R.globalAlpha=.7,R.fillText(kv(p*tt/4),b.left-g*.5,U),R.globalAlpha=1}(v||w)&&(R.fillStyle=n.text,R.textAlign="center",R.globalAlpha=.85,v&&(R.save(),R.translate(g*.9,(b.top+b.bottom)/2),R.rotate(-Math.PI/2),R.fillText(v,0,0),R.restore()),w&&R.fillText(w,(b.left+b.right)/2,b.bottom+g*2.3),R.globalAlpha=1);const st=(tt,U)=>ot(P(tt,U,"value"))*(s==="bar"?ot(P(tt,U,"show")):1)*T,lt=(tt,U)=>$l(c(U),n.highlight,ot(P(tt,U,"highlight")));if(s==="line"){R.lineWidth=Math.max(2,g*.2),R.lineJoin="round",R.lineCap="round";for(const tt of r)R.strokeStyle=c(tt.id),R.beginPath(),t.data.forEach((U,it)=>{const ut={x:A(U.id),y:b.bottom-st(U.id,tt.id)},gt=ot(P(U.id,tt.id,"show"));if(it===0){gt>0&&R.moveTo(ut.x,ut.y);return}const kt=t.data[it-1];if(ot(P(kt.id,tt.id,"show"))<1||gt<=0)return;const yt={x:A(kt.id),y:b.bottom-st(kt.id,tt.id)};R.lineTo(yt.x+(ut.x-yt.x)*gt,yt.y+(ut.y-yt.y)*gt)}),R.stroke()}R.textAlign="center";for(const tt of t.data){for(const U of r){const it=s==="bar"?C(tt.id,U.id):A(tt.id),ut=st(tt.id,U.id),gt=ot(P(tt.id,U.id,"show"));if(R.fillStyle=lt(tt.id,U.id),s==="bar"?ut>.5&&(vv(R,it-x/2,b.bottom-ut,x,ut,Math.min(6,x/4)),R.fill()):gt>0&&(R.beginPath(),R.arc(it,b.bottom-ut,M*Math.min(1,gt*1.5)*(1+.3*ot(P(tt.id,U.id,"highlight"))),0,Math.PI*2),R.fill()),t.values!==!1&>>0){R.globalAlpha=Math.min(1,gt*2),R.font=`600 ${o?g*.85:g}px ${n.font}`,R.fillStyle=$l(n.text,n.highlight,ot(P(tt.id,U.id,"highlight")));const kt=b.bottom-ut-(s==="line"?M:0)-g*.95;R.fillText(j(ot(P(tt.id,U.id,"value"))),it,kt),R.font=`${g}px ${n.font}`,R.globalAlpha=1}}R.fillStyle=n.text,R.fillText(tt.label??tt.id,A(tt.id),b.bottom+g*1.1)}R.strokeStyle=n.text,R.lineWidth=1.5,R.beginPath(),R.moveTo(b.left,b.bottom),R.lineTo(b.right,b.bottom),R.stroke(),R.restore()}};function rt(R,J){const nt=r[0].id,ot=q(J);t.data.forEach((st,lt)=>{const tt=ot.get(st.id);if(tt.sweep<=1e-4)return;const U=Q.get(st.id),it=U?{x:J(`piece.${U.id}.x`),y:J(`piece.${U.id}.y`)}:{x:0,y:0},ut=U?J(`piece.${U.id}.rotate`)*Math.PI/180:0,gt=U?J(`piece.${U.id}.opacity`):1;if(gt<=0)return;R.save(),R.globalAlpha=gt;const kt={x:B.cx+Math.cos(tt.mid)*tt.out,y:B.cy+Math.sin(tt.mid)*tt.out};R.translate(tt.centre.x+it.x,tt.centre.y+it.y),R.rotate(ut),R.translate(-tt.centre.x,-tt.centre.y),R.beginPath(),R.arc(kt.x,kt.y,B.r,tt.start,tt.start+tt.sweep),G>0?R.arc(kt.x,kt.y,G,tt.start+tt.sweep,tt.start,!0):R.lineTo(kt.x,kt.y),R.closePath(),R.fillStyle=$l(n.palette[lt%n.palette.length],n.highlight,J(P(st.id,nt,"highlight"))),R.fill(),R.strokeStyle=n.background,R.lineWidth=Math.max(1.5,g*.15),R.stroke(),t.values!==!1&&tt.sweep>=.3&&(R.fillStyle=n.background,R.font=`600 ${g}px ${n.font}`,R.textAlign="center",R.fillText(j(J(P(st.id,nt,"value"))),tt.centre.x,tt.centre.y),R.font=`${g}px ${n.font}`),R.restore();const yt=F(tt),oe=Math.cos(tt.mid);R.globalAlpha=gt,R.fillStyle=n.text,R.textAlign=oe>.2?"left":oe<-.2?"right":"center";const ai=oe>.2?yt.left:oe<-.2?yt.right:yt.left+yt.width/2;R.fillText(st.label??st.id,ai,yt.top+yt.height/2),t.values!==!1&&tt.sweep<.3&&(R.globalAlpha=gt*.8,R.fillText(j(J(P(st.id,nt,"value"))),ai,yt.bottom+g*.65)),R.globalAlpha=1})}const at={kind:"chart",chartKind:s,about:pn,target:et,max:p,box:Mt(t.x,t.y,t.width,t.height),anchor(R,J=1/0){return X(V(K(R),J))},piece(R){const J=K(R);if(J.kind!=="slice")throw new Error(i?`chart: a piece is a slice, slice:ID, not "${R}"`:`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=Q.get(J.id);if(nt)return nt;const ot={id:Q.size+1,datum:J.id,home:X(V(J,0))};Q.set(J.id,ot);for(const st of["x","y","rotate"])O[`piece.${ot.id}.${st}`]=0;return O[`piece.${ot.id}.opacity`]=1,ot},edit(R,J,nt){const ot=Array.isArray(J)?J:[J];if(ot.length===0)throw new Error(`chart.edit: ${R} takes at least one anchor`);if(!(R in pn.edits))throw Gs("chart",R,pn);if(R==="pull"&&!i)throw new Error(`chart.edit: pull takes slice anchors of a pie or donut; a ${s} chart has ${d}s`);const st=ot.map(lt=>{const tt=K(lt);if(tt.kind!==d)throw new Error(`chart.edit: ${R} takes ${d} anchors (${d}:ID), not "${lt}"`);return tt});for(const{id:lt,series:tt}of st){const U=it=>P(lt,tt,it);if(R==="set"){if(typeof nt.value!="number"||!Number.isFinite(nt.value))throw new Error("chart.edit: set needs `value`, a number");L.tween(U("value"),H(U("value"),nt.at),nt.value,nt,fv)}else R==="show"?L.tween(U("show"),H(U("show"),nt.at),nt.on===!1?0:1,nt,gv):R==="pull"?L.tween(U("pull"),H(U("pull"),nt.at),nt.on===!1?0:1,nt,mv):L.tween(U("highlight"),H(U("highlight"),nt.at),nt.on===!1?0:1,nt,pv)}return at},follow(R,J){return z.follow(R,J),at},fling(R,J){return z.fling(R,J),at},move(R,J){return z.move(R,J),at},ride(R,J,nt){if(s!=="bar")return R;const ot=t.data.flatMap(st=>r.map(lt=>{const tt=W(st.id,lt.id,0),U=[...Jn(L.keys(P(st.id,lt.id,"value"))),...Jn(L.keys(P(st.id,lt.id,"show")))];return{top:t.y+b.bottom-tt,offset:it=>tt-W(st.id,lt.id,it),windows:U}}));return Co(R,J,{ground:nt.ground,every:nt.every??ze,floors:ot})},tracks:L.tracks};return at}function Qf(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 kv(t){return Number.isInteger(t)?String(t):String(Number(t.toFixed(2)))}function $l(t,e,n){if(n<=0)return t;if(n>=1)return e;const s=r=>[1,3,5].map(a=>parseInt(r.slice(a,a+2),16));if(!/^#[0-9a-f]{6}$/i.test(t)||!/^#[0-9a-f]{6}$/i.test(e))return n<.5?t:e;const[i,o]=[s(t),s(e)];return`#${i.map((r,a)=>Math.round(r+(o[a]-r)*n).toString(16).padStart(2,"0")).join("")}`}function tg(t,e,n,s,i,o){t.beginPath(),t.moveTo(e+o,n),t.arcTo(e+s,n,e+s,n+i,o),t.arcTo(e+s,n+i,e,n+i,o),t.arcTo(e,n+i,e,n,o),t.arcTo(e,n,e+s,n,o),t.closePath()}function vv(t,e,n,s,i,o){const r=Math.min(o,i);t.beginPath(),t.moveTo(e,n+i),t.lineTo(e,n+r),t.arcTo(e,n,e+r,n,r),t.lineTo(e+s-r,n),t.arcTo(e+s,n,e+s,n+r,r),t.lineTo(e+s,n+i),t.closePath()}function Mv(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}}const eg={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"}}}},ng={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"}}}},Il={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:me.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:me.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:me.black},ears:!0,outfit:{shirt:"#9b5fc0",trousers:"#2f2f3a",sleeves:"long"}}},grandpa:{label:"Grandpa",group:"family",scale:.96,options:{build:"stocky",hair:{style:"receding",color:me.gray},facialHair:{style:"shortBoxed",color:me.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:me.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:me.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:me.blond},hat:"sunHat",ears:!0,outfit:{shirt:"#d64535",trousers:"#4f6b3a",sleeves:"long"}}},...eg,...ng};function Sv(t,e=300,n={}){const s=Il[t];if(!s)throw new Error(`castMember: unknown cast member '${t}'`);return{...s.options,height:Math.round(e*s.scale),...n}}const Zs={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 Tv(t,e,n){return Zs[t].spacing*Math.min(e.height,n.height)}const sg=.075;function xv(t,e,n,s={}){const i=Zs[t];if(!i)throw new Error(`meetHands: unknown meeting '${t}' (one of ${Object.keys(Zs).join(", ")})`);const[o,r]=e.x<=n.x?[e,n]:[n,e],a=s.view==="side",l=Math.min(o.character.height,r.character.height),c={x:(o.x+r.x)/2,y:-(s.height??i.height)*l},h=(m,w)=>{const v=w?a?1:.62:a?3:3.38;let k={...ht,...m.pose,turn:v,lean:(m.pose?.lean??0)+i.lean};const b=w?1:-1,E=($,S,x)=>{k=ve(m.character,k,$,{x:c.x+S-m.x,y:c.y,depth:x})};if(t==="handOver"){const $=sg*l;E("arm.left",-b*$*.9,$),E("arm.right",-b*$*.9,-$)}else E("arm.right",0,0);return t==="fistBump"&&(k={...k,"hand.right.index.curl":1,"hand.right.middle.curl":1,"hand.right.ring.curl":1,"hand.right.pinky.curl":1}),k},u=h(o,!0),d=h(r,!1),f=.03*l,p=(m,w)=>{const v=ie(m.character,w),k=t==="handOver"?["hand.left","hand.right"]:["hand.right"],b=t==="handOver"?sg*l+f:f;return k.every(E=>Math.abs(v.points[E].y-c.y)<f&&Math.abs(v.points[E].x+m.x-c.x)<b)},g=p(o,u)&&p(r,d);return e.x<=n.x?{a:u,b:d,point:c,reached:g}:{a:d,b:u,point:c,reached:g}}const No={spacing:.3,lean:10,tilt:8};function Ev(t,e){return No.spacing*Math.min(t.height,e.height)}function Av(t,e,n={}){const[s,i]=t.x<=e.x?[t,e]:[e,t],o=n.view==="side",r=Math.min(s.character.height,i.character.height),a=(p,g,m)=>({over:{x:g.x-m*.02*r-p.x,y:-.72*r,depth:-.08*r},round:{x:g.x-m*.04*r-p.x,y:-.5*r,depth:.06*r}}),l=(p,g,m)=>{const w=m?o?1:.62:o?3:3.38,v=m?1:-1;let k={...ht,...p.pose,turn:w,lean:(p.pose?.lean??0)+No.lean,"head.tilt":(p.pose?.["head.tilt"]??0)+v*No.tilt};const{over:b,round:E}=a(p,g,v);return k=ve(p.character,k,"arm.right",b),k=ve(p.character,k,"arm.left",E),k},c=l(s,i,!0),h=l(i,s,!1),u=.05*r,d=(p,g,m,w)=>{const v=ie(p.character,w).points,{over:k,round:b}=a(p,g,m);return Math.hypot(v["hand.right"].x-k.x,v["hand.right"].y-k.y)<u&&Math.hypot(v["hand.left"].x-b.x,v["hand.left"].y-b.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 mn={spacing:.32,low:.3,high:.5,helperLean:40,helperBend:16};function Pv(t,e){return mn.spacing*Math.min(t.height,e.height)}function $v(t,e,n,s={}){const i=Math.max(0,Math.min(1,n)),o=s.view==="side",r=t.x<=e.x,a=Math.min(t.character.height,e.character.height),l={x:(t.x+e.x)/2,y:-(mn.low+(mn.high-mn.low)*i)*a},c=m=>m?o?1:.62:o?3:3.38;let h={...ht,...t.pose,turn:c(r),lean:(t.pose?.lean??0)+mn.helperLean*(1-i)+4,bend:(t.pose?.bend??0)+mn.helperBend*(1-i),"head.nod":18*(1-i)};h=ve(t.character,h,"arm.right",{x:l.x-t.x,y:l.y});const u={...le.sitFloor,...e.pose,turn:c(!r)},d={...ht,...e.pose,turn:c(!r)};let f=Za(u,d,i);f=ve(e.character,f,"arm.right",{x:l.x-e.x,y:l.y});const p=.04*a,g=(m,w)=>{const v=ie(m.character,w).points["hand.right"];return Math.hypot(v.x+m.x-l.x,v.y-l.y)<p};return{helper:h,sitter:f,point:l,reached:g(t,h)&&g(e,f)}}const Iv=.7,Ov=50,_v=1.2,Cv=.8,Hv=3,Rv=30,Lv=.8,Nv=.6,Ol=(t,e)=>Math.max(-e,Math.min(e,t)),Fv=["hair.swing","hair.trail","hair.lift"];function ig(t,e){const n=e.start??0,s=e.amount??1,i=Math.max(1e-6,e.headRadius);let o=NaN,r={x:0,y:0,turn:0};const a=f=>(f!==o&&(r=t(f),o=f),r),l=f=>{const p=a(f);return p.turn*90+(p.headTurn??0)},c={start:n,end:e.end,step:e.step,stiffness:e.stiffness??70,damping:e.damping??6},h=vs(l,c),u=vs(f=>a(f).x,c),d=vs(f=>a(f).y,c);return h.map((f,p)=>{const g=a(f.time),m=f.value-l(f.time),w=u[p].value-g.x-(e.wind??0)*Iv*i,v=d[p].value-g.y,k=Math.sin(g.turn*Math.PI/2),b=Math.cos(g.turn*Math.PI/2),E=m*Hv+w*b/i*Rv,$=-w*k/i*Lv,S=-v/i*Nv;return{time:f.time,swing:Ol(E*s,Ov),trail:Ol($*s,_v),lift:Ol(S*s,Cv)}})}function Dv(t,e){if(t.length===0)return{"hair.swing":0,"hair.trail":0,"hair.lift":0};if(e<=t[0].time)return og(t[0]);if(e>=t[t.length-1].time)return og(t[t.length-1]);let n=0,s=t.length-1;for(;s-n>1;){const a=n+s>>1;t[a].time<=e?n=a:s=a}const i=t[n],o=t[s],r=o.time===i.time?0:(e-i.time)/(o.time-i.time);return{"hair.swing":i.swing+(o.swing-i.swing)*r,"hair.trail":i.trail+(o.trail-i.trail)*r,"hair.lift":i.lift+(o.lift-i.lift)*r}}const og=t=>({"hair.swing":t.swing,"hair.trail":t.trail,"hair.lift":t.lift}),Zn=16,Wv=1500;function Bv(t,e,n,s={}){const i=n.head.hair;if(!i||!sd(i))return[];const o=e.filter(v=>v.target===t),r=o.reduce((v,k)=>k.keyframes.reduce((b,E)=>Math.max(b,E.time),v),0),a=ht,l=new Set(["x","y","turn","head.turn"]),c=new It({id:`${t}-hair-follow`,tracks:o.filter(v=>l.has(v.property))}),h=(v,k,b)=>{const E=c.getStateAtTime(v).values.get(t)?.get(k);return typeof E=="number"?E:b},u=new It({id:`${t}-hair-pose`,tracks:o}),d=v=>u.getStateAtTime(v).values.get(t),f=new Map,p=v=>{const k=Math.round(v/Zn);let b=f.get(k);if(!b){const E={};for(const[S,x]of d(k*Zn)??[])E[S]=x;const $=ie(n,wo(E,a,s.gaits)).head.center;f.set(k,b={x:$.x,y:$.y})}return b},g=v=>{const k=Math.floor(v/Zn),b=v/Zn-k,E=p(k*Zn),$=p((k+1)*Zn);return{x:E.x+($.x-E.x)*b,y:E.y+($.y-E.y)*b}},m=ig(v=>{const k=g(v);return{x:h(v,"x",0)+k.x,y:h(v,"y",0)+k.y,turn:h(v,"turn",a.turn??0),headTurn:h(v,"head.turn",a["head.turn"]??0)}},{start:0,end:r+(s.settle??Wv),headRadius:ie(n,ht).head.rx,step:s.step,stiffness:s.stiffness,damping:s.damping,amount:s.amount,wind:s.wind}),w=[];for(const v of Fv){const k=v.slice(5);let b=m.map($=>({time:$.time,value:$[k]}));if(b.every($=>Math.abs($.value)<.001))continue;const E=o.find($=>$.property===v);if(E){const $=new It({id:`${t}-${v}-own`,tracks:[E]}),S=x=>Number($.getStateAtTime(x).values.get(t)?.get(v)??0);b=b.map(x=>({time:x.time,value:x.value+S(x.time)}))}w.push({id:`${t}-${v}`,target:t,property:v,keyframes:b})}return w}const yn={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 _l(t){if(t===void 0)return yn.full;if(typeof t=="string")return yn[t];const{base:e,...n}=t;return{...yn[e??"full"],...n}}const Cl=160,zv=120,qv=700,Hl=60,Yv=90,Fo=3200,Qn=1,bn=1e-6;function Do(t,e,n={}){const s=_l(n.style),i=n.seed??1,o={};if(t.length===0)return o;const r=Object.keys(t[0].pose).filter(u=>t.some(d=>Math.abs(d.pose[u]-t[0].pose[u])>bn));for(const u of r)o[u]=jv(u,t,e,s,i);const a=e.blink,l=a!==void 0&&r.includes(a);if(s.blinks&&a!==void 0&&!l&&a in t[0].pose){const u=Kv(t,e,s,i,t[0].pose[a]);u.length>0&&(o[a]=u)}const{lift:c,stretch:h}=e;if(s.jumpSquash>0&&c&&h&&r.includes(c)&&!r.includes(h)&&h in t[0].pose){const u=Xv(t,c,t[0].pose[h],s.jumpSquash);u.length>0&&(o[h]=u)}return o}function jv(t,e,n,s,i){const o=n.eyes.includes(t),r=n.limits[t],a=r!==void 0,l=o?-s.eyeLead:(n.depth[t]??1)*s.overlap,c=f=>{const p=(e[f].time-e[f-1].time)/2;return Math.max(-p,Math.min(p,l))},h=[{time:e[0].time,value:e[0].pose[t]}],u=(f,p,g)=>{const m=h[h.length-1];if(f<=m.time+Qn){h[h.length-1]={...m,value:p,...g?{easing:g}:{}};return}h.push({time:f,value:p,...g?{easing:g}:{}})};let d=e[0].pose[t];for(let f=1;f<e.length;f++){const p=e[f],g=e[f-1].pose[t],m=p.pose[t],w=m-g,v=h[h.length-1].time,k=p.act!==!1;if(Math.abs(w)<=bn){const I=p.time+(k?c(f):0);if(f===e.length-1)Math.abs(d-m)>bn&&u(Math.max(I,v+Cl),m,"ease-in-out"),d=m;else if(k&&a&&s.drift>0&&n.drift.includes(t)&&I-v>=qv){const A=Kt(`${i}:${t}:${f}`)%2===0?1:-1;d=m+A*s.drift*r,u(I,d,"ease-in-out")}continue}if(!k){u(e[f-1].time,d),u(p.time,m,p.easing),d=m;continue}const b=c(f),E=Math.max(e[f-1].time+b,v);let $=p.time+b;o&&s.eyeDart>0&&($=Math.min($,E+s.eyeDart));const S=$-E;if(S<=Qn){u(p.time,m,p.easing),d=m;continue}u(E,d);const x=Math.sign(w);if(a&&s.anticipation>0&&r>0&&S>=Cl){const I=d-x*Math.min(Math.abs(w)*s.anticipation,r),A=E+S*s.anticipationTime;u(A,I,"ease-in-out"),s.hold>0&&u(A+S*s.hold,I)}const M=f+1<e.length?e[f+1].time-p.time:1/0,T=Math.min(s.settle,M/2);if(a&&s.overshoot>0&&r>0&&S>=zv&&T>Qn){const I=Math.min(Math.abs(w)*s.overshoot,r);u($,m+x*I,p.easing??s.actionEase),u($+T,m,s.settleEase)}else u($,m,p.easing??s.actionEase);d=m}return h}function Kv(t,e,n,s,i){const o=[],r=Hl+Yv;for(let f=1;f<t.length;f++){const p=t[f-1].pose,g=t[f].pose;Object.entries(e.headTurns).some(([w,v])=>Math.abs((g[w]??0)-(p[w]??0))>v)&&t[f].act!==!1&&o.push(Math.max(t[0].time,t[f-1].time-n.eyeLead))}const a=t[0].time,l=t[t.length-1].time,c=[...o];let h=a+Fo*.6,u=0;for(;h<l;){c.some(g=>Math.abs(g-h)<Fo/2)||o.push(h);const p=(Kt(`${s}:blink:${u++}`)%1e3/1e3-.5)*(Fo*.66);h+=Fo+p}o.sort((f,p)=>f-p);const d=[{time:a,value:i}];for(const f of o){const p=d[d.length-1].time;f+Hl<=p+Qn||(f>p+Qn&&d.push({time:f,value:i}),d.push({time:f+Hl,value:1,easing:"ease-in"}),d.push({time:f+r,value:i,easing:"ease-out"}))}return d.length>1?d:[]}function Xv(t,e,n,s){const i=n*(1-.18*s),o=n*(1+.14*s),r=[{time:t[0].time,value:n}],a=(l,c,h)=>{const u=r[r.length-1];l<=u.time+Qn||r.push({time:l,value:c,...h?{easing:h}:{}})};for(let l=1;l<t.length;l++){const c=t[l-1].pose[e],h=t[l].pose[e],u=t[l-1].time,d=t[l].time,f=d-u;if(!(f<Cl||t[l].act===!1)){if(c<=bn&&h>bn)a(u,n),a(u+f*.2,i,"ease-out"),a(u+f*.45,o,"ease-out"),a(d,n,"ease-in-out");else if(c>bn&&h<=bn){const p=l+1<t.length?t[l+1].time-d:400;a(u+f*.5,n),a(d-Math.min(60,f*.15),o,"ease-in"),a(d,i,"ease-out"),a(d+Math.min(260,p/2),n,{type:"back",mode:"out",overshoot:1.4})}}}return r.length>1?r:[]}const rg={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 Gv(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 Uv(){const t={},e={};for(const n of Object.keys(ht)){const s=Gv(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 ag=Uv();function lg(t,e){return Object.entries(e).map(([n,s])=>({id:`${t}-${n}`,target:t,property:n,keyframes:s}))}function cg(t,e,n={}){const s=Yi(e),i=e.map((o,r)=>({time:o.time,pose:{...s[r]},easing:o.easing,act:o.act}));return lg(t,Do(i,n.rig??rg,n))}function hg(t,e,n={}){const s=n.rest??ht,i=Qa(e,s),o=e.map((r,a)=>({time:r.time,pose:{...s,...i[a]},easing:r.easing,act:r.act}));return lg(t,Do(o,n.rig??ag,n))}const ug=vt.shocked,Vv=vt.scared,Ye={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,...ug,headTilt:0},easing:"ease-out-cubic"},{after:720,pose:{rise:.25,stretch:1.25,bend:-10,leftShoulder:140,rightShoulder:140},easing:"ease-in-out"},{after:900,pose:{rise:0,stretch:.74,bend:12,leftShoulder:70,rightShoulder:70,leftHip:18,rightHip:18,leftKnee:30,rightKnee:30},easing:"ease-in-quad"},{after:1060,pose:{stretch:1.06,bend:-3,leftShoulder:60,rightShoulder:60,leftHip:t.leftHip,rightHip:t.rightHip,leftKnee:t.leftKnee,rightKnee:t.rightKnee},easing:"ease-out"},{after:1260,pose:{stretch:t.stretch,bend:t.bend,...vt.surprised,leftShoulder:70,rightShoulder:70,leftElbow:60,rightElbow:60},easing:"ease-in-out"}],doubleTake:t=>[{after:160,pose:{lookX:1,lookY:0},easing:"ease-out"},{after:520,pose:{lookX:-.6,headTilt:t.headTilt-4,smile:.6,mouth:0},easing:"ease-in-out"},{after:1100,pose:{lookX:-.6}},{after:1180,pose:{bend:t.bend-10,headTilt:t.headTilt+10,rise:.05,stretch:1.18,...ug,lookX:1,lookY:0},easing:"ease-out-cubic"},{after:1360,pose:{rise:0,stretch:.88,bend:t.bend+4,headTilt:t.headTilt+4},easing:"ease-in-quad"},{after:1560,pose:{stretch:t.stretch,bend:t.bend,headTilt:t.headTilt},easing:{type:"elastic",mode:"out",amplitude:1,period:.35}}],windUp:()=>[{after:220,pose:{lean:-18,bend:-16,headTilt:-6,leftShoulder:70,leftElbow:-100,rightShoulder:40,rightElbow:100,leftHip:-45,leftKnee:-80,stretch:.92,...vt.angry,lookX:1},easing:"ease-out"},{after:620,pose:{lean:-20,bend:-18,stretch:.9}},{after:700,pose:{lean:28,bend:14,headTilt:6,leftShoulder:30,rightShoulder:60,leftHip:30,leftKnee:-30,rightHip:-20,stretch:1.12},easing:"ease-out-cubic"}],land:t=>[{after:120,pose:{rise:0,stretch:.7,bend:14,leftShoulder:75,rightShoulder:75,leftHip:20,rightHip:20,leftKnee:35,rightKnee:35},easing:"ease-in-quad"},{after:300,pose:{stretch:1.05,bend:-4,leftShoulder:t.leftShoulder,rightShoulder:t.rightShoulder},easing:"ease-out"},{after:460,pose:{rise:0,stretch:t.stretch,bend:t.bend,leftHip:ct.leftHip,rightHip:ct.rightHip,leftKnee:0,rightKnee:0},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...Vv,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:{...Vt.sad,bend:18,stretch:.92,lean:t.lean+5,turn:t.turn,sit:t.sit},easing:"ease-in-out"}]};function Rl(t,e){const n=typeof e.from=="string"?Vt[e.from]:e.from??ct;return Ll(Ye[t](n),{...e,from:n})}function Ll(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 Qs(t,e=1){const n=Ye[t](ct);return n[n.length-1].after*e}function dg(t,e,n={}){if(e.length<2)return;const s=Math.max(1,Math.round(n.lines??3)),i=n.spacing??5,o=n.lineWidth??2,r=n.opacity??.7;t.save(),t.strokeStyle=n.color??"#222",t.lineCap="round";for(let a=0;a<s;a++){const l=(a-(s-1)/2)*i,c=Math.floor(Math.abs(l)/Math.max(i,1)*(e.length/6));for(let h=c+1;h<e.length;h++){const u=e[h-1],d=e[h],f=d.x-u.x,p=d.y-u.y,g=Math.hypot(f,p)||1,m=-p/g,w=f/g,v=1-h/(e.length-1);t.globalAlpha=r*(1-v),t.lineWidth=o*(1-v*.7),t.beginPath(),t.moveTo(u.x+m*l,u.y+w*l),t.lineTo(d.x+m*l,d.y+w*l),t.stroke()}}t.restore()}const Jv={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 Zv(t,e,n,s,i={}){const o=n.stateAt;if(!o)return;const r=i.length??120,a=Math.max(2,Math.round(i.samples??8)),l=Math.max(0,n.time-r);if(n.time-l<1)return;const c=[];for(let f=0;f<a;f++){const p=l+(n.time-l)*f/(a-1);c.push(ma(e,{time:p,state:o(p)},s).joints)}const h=c[c.length-1].height,u=(i.threshold??1.2)*h,d=(i.parts??["hands","toes","head"]).flatMap(f=>Jv[f]);for(const f of d){const p=c.map(f.at);let g=0;for(let v=1;v<p.length;v++)g+=Math.hypot(p[v].x-p[v-1].x,p[v].y-p[v-1].y);const m=g/((n.time-l)/1e3);if(m<=u)continue;const w=Math.min(1,(m-u)/(u*.5));dg(t,p,{...i,opacity:(i.opacity??.7)*w,spacing:i.spacing??h*.02})}}function fg(t,e,n,s={}){if(n<=0||n>=1)return;const i=s.size??40,o=s.seed??1,r=.45+.55*(1-(1-n)**3);t.save(),t.strokeStyle=s.color??"#555",t.lineWidth=Math.max(1,i*.03),t.globalAlpha=Math.min(1,n/.08)*(1-n);for(let a=0;a<5;a++){const l=Kt(`${o}:puff:${a}`)%1e3/1e3,c=a-2,h=e.x+c*i*.3*r,u=e.y-i*(.06+.12*l)*r+Math.abs(c)*i*.03,d=i*(.11+.07*l)*r;t.beginPath(),t.arc(h,u,d,Math.PI*.95,Math.PI*2.05),t.stroke()}t.restore()}function Qv(t,e,n,s={}){if(n<=0||n>=1)return;const i=s.size??40,o=5,r=1-(1-n)**2;t.save(),t.strokeStyle=s.color??"#222",t.lineWidth=Math.max(1,i*.035),t.lineJoin="round",t.globalAlpha=n<.7?1:(1-n)/.3;for(let a=0;a<o;a++){const l=-Math.PI/2+(a-(o-1)/2)*Math.PI/(o+1),c=i*(.3+.7*r),h=e.x+Math.cos(l)*c,u=e.y+Math.sin(l)*c;tM(t,h,u,i*.14,n*Math.PI+a),t.stroke()}t.restore()}function tM(t,e,n,s,i){t.beginPath();for(let o=0;o<10;o++){const r=o%2===0?s:s*.45,a=i+o*Math.PI/5-Math.PI/2,l=e+Math.cos(a)*r,c=n+Math.sin(a)*r;o===0?t.moveTo(l,c):t.lineTo(l,c)}t.closePath()}const ti={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 Nl(t={}){return[...Object.keys(Wt),...Object.keys(Vt),...Object.keys(Ye),...Object.keys(ti),...Object.keys(t.gaits??{}),...Object.keys(t.actions??{})]}function Fl(t={}){const e=new Set(Nl()),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 Dl(t={}){const e={};for(const n of Object.keys(Wt))e[n]=`Walks to \`to\` in the ${n} gait, feet planted, turning round first if needed.`;for(const n of Object.keys(Vt))e[n]=`Moves into the ${n} pose and holds it.`;for(const n of Object.keys(Ye))e[n]=`The ${n} gag, built on the current pose.`;for(const[n,s]of Object.entries(ti))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 Wo=["do","at","for","to","toward","mood","say","pose","target","onto"],eM={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"},Bo=["viewer","ahead","back"],wn=t=>typeof t=="number"&&Number.isFinite(t);function ei(t,e={}){const n=Fl(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=Nl(e),i=l=>l in Wt||l in(e.gaits??{}),o=Object.keys(vt),r=Object.keys(ct);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))Wo.includes(g)||h(dt("beat field",g,Wo,eM[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 p=ti[f]??e.actions?.[f];for(const g of p?.needs??[])d[g]===void 0&&h(`\`${f}\` needs \`${g}\`.`);if(i(f)&&d.to===void 0&&u(`\`${f}\` without \`to\` walks nowhere.`),f==="leap"&&d.to===void 0&&d.onto===void 0&&u("`leap` without `to` or `onto` jumps on the spot."),d.mood!==void 0&&(typeof d.mood!="string"||!o.includes(d.mood))&&h(dt("mood",d.mood,o)),d.pose!==void 0)if(!d.pose||typeof d.pose!="object"||Array.isArray(d.pose))h("`pose` is joints to change, an object like { rightShoulder: 90 } (for a named pose, use it as the action).");else for(const[g,m]of Object.entries(d.pose))r.includes(g)?wn(m)||h(`Pose joint \`${g}\` must be a number (got ${JSON.stringify(m)}).`):h(dt("pose joint",g,r));for(const g of["at","for"]){const m=d[g];m!==void 0&&!(wn(m)&&m>=0)&&h(`\`${g}\` is milliseconds, a number ≥ 0 (got ${JSON.stringify(m)}).`)}wn(d.at)&&(d.at<a&&u(`\`at\` ${d.at} is before an earlier beat's \`at\` (${a}); beats run in order, so it starts when the one before ends.`),a=d.at);for(const g of["to","onto"]){const m=d[g];m!==void 0&&!wn(m)&&h(`\`${g}\` is a scene ${g==="to"?"x":"y"} in px, a number (got ${JSON.stringify(m)}).`)}if(d.toward!==void 0&&!wn(d.toward)&&!Bo.includes(d.toward)&&h(`\`toward\` is a scene x or one of ${Bo.join(", ")}${typeof d.toward=="string"&&ks(d.toward,Bo)?` (did you mean "${ks(d.toward,Bo)}"?)`:""} (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"||!wn(g.x)||!wn(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 Wl(t,e={},n="scriptTracks"){const s=ei(t,e).filter(i=>i.level==="error");if(s.length!==0)throw new Error(`${n}: ${s.length} problem(s) in the beats:
|
|
53
|
+
`;function Ow(t){if(t.getElementById(Q0))return;const e=t.createElement("style");e.id=Q0,e.textContent=Iw,t.head.appendChild(e)}function tu(t,e){const n=Array.from(e.querySelectorAll("[data-tinyfly-choose]"));if(n.length===0)return()=>{};Ow(e.ownerDocument);const s=[],i=[];for(const a of n){const l=a.getAttribute("data-tinyfly-choose")??"",c=[],h=(p,g)=>{a.hasAttribute(p)||(a.setAttribute(p,g),c.push(p))};h("role","button"),h("tabindex","0");const u=t.scenarios.find(p=>p.id===l)?.label;u!==void 0&&h("aria-label",u),a.setAttribute("aria-pressed","false"),c.push("aria-pressed"),s.push({element:a,attributes:c});const d=()=>t.setScenario(l),f=p=>{const g=p.key;g!=="Enter"&&g!==" "||(p.preventDefault(),d())};a.addEventListener("click",d),a.addEventListener("keydown",f),i.push(()=>{a.removeEventListener("click",d),a.removeEventListener("keydown",f)})}const o=()=>{for(const{element:a}of s)a.setAttribute("aria-pressed",String(a.getAttribute("data-tinyfly-choose")===t.scenario))},r=t.subscribe(o);return o(),()=>{r();for(const a of i)a();for(const{element:a,attributes:l}of s)for(const c of l)a.removeAttribute(c)}}const zi=new WeakMap,ma=new WeakMap;let _w=0;function Os(t,e,n){if(t)try{return JSON.parse(t)}catch(s){console.warn(`tinyfly: invalid ${e} JSON on`,n,s);return}}async function eu(t,e={}){const n=zi.get(t);if(n)return n;const s=Array.from(t.querySelectorAll("script[data-tinyfly-timeline]")),i=s[0],o=t.getAttribute("data-src"),r=Hw(t.getAttribute("data-markers")),a=s.length>1||i?.hasAttribute("data-scenario")?Cw(s,r,t):void 0;if(a&&a.length===0)return;let l=i&&!a?Os(i.textContent,"timeline",t):void 0;if(!l&&o&&r){const f=await fetch(o);f.ok&&(l=await f.json())}if(l&&r&&(l=nu(l,r)),!l&&!o&&!a){console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)',t);return}const c=Os(t.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",t),h={playWhenVisible:!0,...e.player,...c&&{captions:c},...Os(t.getAttribute("data-options"),"data-options",t)};Lw(t);const u=new Bi(t,h),d={element:t,player:u};if(zi.set(t,d),t.setAttribute("data-tinyfly-mounted",""),a){const f=t.getAttribute("data-scenario")??void 0;await u.loadScenarios(a,{initial:a.some(p=>p.id===f)?f:void 0}),ma.set(t,tu(u,t))}else await u.load(l??o);if(t.getAttribute("data-controls")!=="false"){const f=Os(t.getAttribute("data-labels"),"data-labels",t),p=t.querySelector("figcaption"),g=t.getAttribute("data-scenario-legend"),m=t.getAttribute("data-scenario-control");d.controls=Z0(u,t,{...e.controls,...t.getAttribute("data-fullscreen")==="true"?{fullscreen:!0}:{},...m==="slider"||m==="buttons"?{scenarioControl:m}:{},labels:{...e.controls?.labels,...f,...g?{scenario:g}:{}},mount:void 0}),p?t.insertBefore(d.controls.element,p):t.appendChild(d.controls.element)}return d}function Cw(t,e,n){const s=[];return t.forEach((i,o)=>{const r=Os(i.textContent,"timeline",n);if(!r)return;const a=i.getAttribute("data-scenario")||`scenario-${o+1}`;if(s.some(c=>c.id===a)){console.warn(`tinyfly: scenario id "${a}" is used more than once; the later one is skipped`,n);return}const l=i.getAttribute("data-scenario-label")??void 0;s.push({id:a,label:l,timeline:e?nu(r,e):r})}),s}function nu(t,e){return t.config.markers?.length?t:{...t,config:{...t.config,markers:e.map((n,s)=>({id:`step-${s+1}`,time:n}))}}}function Hw(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 su(t=document,e={}){const n=Array.from(t.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(n.map(i=>eu(i,e)))).filter(i=>i!==void 0)}function Rw(t){const e=zi.get(t);e&&(ma.get(t)?.(),ma.delete(t),e.controls?.destroy(),e.player.destroy(),zi.delete(t),t.removeAttribute("data-tinyfly-mounted"))}function Lw(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-${++_w}`,e.setAttribute("aria-labelledby",s.id))}function Nw(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const e=()=>{su()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}class iu{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 sn,this.adapterB=new sn}async load(e){let n;if(typeof e=="string"){const s=await fetch(e);if(!s.ok)throw new Error(`Failed to load sequence: ${s.statusText}`);n=await s.json()}else n=e;this.sequence=n,this.symbolDefs.clear();for(const s of n.symbols??[])s.timeline?.tracks?.length&&this.symbolDefs.set(s.id,s.timeline);this.container.style.width=`${n.canvas.width}px`,this.container.style.height=`${n.canvas.height}px`,n.scenes.length>0&&(this.renderScene(n.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(n.scenes[0])),this.options.autoplay&&this.play()}play(){if(!(!this.sequence||this._isDestroyed)&&this.sequence.scenes.length!==0){if(this._isPlaying=!0,this._state==="idle"){if(this._state="playing-scene",this._currentSceneIndex=0,this.timelineA)this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play();else{this.onSceneComplete();return}this.options.onSceneChange?.(0)}else this._state==="playing-scene"&&this.timelineA&&this.timelineA.play();this.startAnimationLoop()}}pause(){this._isPlaying&&(this._isPlaying=!1,this.timelineA&&this.timelineA.pause(),this.timelineB&&this.timelineB.pause(),this.stopAnimationLoop())}stop(){if(this._isPlaying=!1,this._state="idle",this._currentSceneIndex=0,this.loopIteration=0,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.stopAnimationLoop(),this.sequence&&this.sequence.scenes.length>0&&(this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this.renderScene(this.sequence.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(this.sequence.scenes[0]),this.timelineA)){const e=this.timelineA.getStateAtTime(0);this.adapterA.applyState(e),this.applyNested(this.adapterA,0)}}goToScene(e){if(!this.sequence||e<0||e>=this.sequence.scenes.length)return;const n=this._isPlaying;this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this._currentSceneIndex=e,this._state=n?"playing-scene":"idle",this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB);const s=this.sequence.scenes[e];if(this.renderScene(s,this.containerA,this.adapterA),this.timelineA=this.createTimeline(s),this.options.onSceneChange?.(e),n)this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play(),this.startAnimationLoop()):this.onSceneComplete();else if(this.timelineA){const i=this.timelineA.getStateAtTime(0);this.adapterA.applyState(i),this.applyNested(this.adapterA,0)}}destroy(){this._isDestroyed=!0,this._isPlaying=!1,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.adapterA.clearTargets(),this.adapterB.clearTargets();for(const e of this.nestedByAdapter.values())for(const n of e)n.adapter.clearTargets();this.nestedByAdapter.clear(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.timelineA=null,this.timelineB=null,this.containerA.parentNode&&this.containerA.remove(),this.containerB.parentNode&&this.containerB.remove(),this.sequence=null}get currentSceneIndex(){return this._currentSceneIndex}get sceneCount(){return this.sequence?.scenes.length??0}get isPlaying(){return this._isPlaying}get state(){return this._state}createSceneContainer(){const e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.width="100%",e.style.height="100%",e}renderScene(e,n,s){n.innerHTML="",s.clearTargets();const i=document.createElement("div");i.style.cssText="position:absolute;inset:0;transform-origin:center center",i.setAttribute("data-tinyfly","Camera"),n.appendChild(i),s.registerTarget("Camera",i);for(const o of e.elements){if(!o.html)continue;const r=document.createElement("div");r.innerHTML=o.html.trim();const a=r.firstElementChild;if(a){i.appendChild(a);const l=a.getAttribute("data-tinyfly");l&&s.registerTarget(l,a)}}this.setupNested(i,s)}setupNested(e,n){const s=[];e.querySelectorAll("[data-tinyfly-symbol]").forEach(i=>{const o=i.getAttribute("data-tinyfly-symbol");if(!o)return;const r=this.symbolDefs.get(o);if(!r)return;const a=new sn;i.querySelectorAll("[data-tinyfly]").forEach(l=>{const c=l.getAttribute("data-tinyfly");c&&a.registerTarget(c,l)}),s.push({adapter:a,timeline:$n(r)})}),s.length?this.nestedByAdapter.set(n,s):this.nestedByAdapter.delete(n)}applyNested(e,n){const s=this.nestedByAdapter.get(e);if(s)for(const i of s){const o=i.timeline.duration;i.adapter.applyState(i.timeline.getStateAtTime(o>0?n%o:n))}}clearContainer(e){e.innerHTML=""}createTimeline(e){return e.timeline?$n(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 Fw(t,e,n={}){const s=new iu(t,{...n,autoplay:!0});return await s.load(e),s}const Ww={type:"none",duration:0},_t=t=>({description:t,unit:"degrees"}),xt=(t,e=0,n=1)=>({description:t,unit:`${e}..${n}`,min:e,max:n}),ou={lean:_t("Upper body tipped about the hips (+ toward the way it faces)"),bend:_t("Line of action: the spine curved (+ curls forward, − arches back)"),headTilt:_t("Head tilt"),leftShoulder:_t("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:_t("Right upper arm: 0 hangs down, 90 straight out (forward, in profile), 180 straight up"),leftElbow:_t("Left elbow bend, added to the upper arm"),rightElbow:_t("Right elbow bend, added to the upper arm"),leftHip:_t("Left thigh: 0 straight down; in profile negative is forward"),rightHip:_t("Right thigh: 0 straight down; in profile positive is forward"),leftKnee:_t("Left knee bend (negative folds the shin back)"),rightKnee:_t("Right knee bend (positive folds the shin back)"),leftWrist:_t("Left wrist bend, added to the forearm"),rightWrist:_t("Right wrist bend, added to the forearm"),leftAnkle:_t("Left ankle: + points the toe down (tiptoe), − onto the heel"),rightAnkle:_t("Right ankle: + points the toe down (tiptoe), − onto the heel"),leftFootOut:xt("Left foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),rightFootOut:xt("Right foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),mouth:xt("Mouth open: 0 closed, 1 wide open"),smile:xt("−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:xt("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:xt("Left eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),rightBrow:xt("Right eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),browTilt:xt("Eyebrow slant: −1 angry, 1 worried",-1,1),lookX:xt("Eyes look across: + the way it faces",-1,1),lookY:xt("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:xt("0 front-on, 1 in profile, turned the way it faces"),sit:xt("0 standing, 1 seated"),spin:_t("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"}},ru={walk:{description:"Walk-cycle phase, in strides: animate 0 → n for n strides",unit:"strides"},walking:xt("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:xt("How much the mouth chatters"),rubber:xt("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:xt("How much of the dance is applied")},au={"thumb.curl":xt("Thumb curled in"),"thumb.across":xt("Thumb across the palm"),"index.curl":xt("Index finger curled"),"middle.curl":xt("Middle finger curled"),"ring.curl":xt("Ring finger curled"),"pinky.curl":xt("Little finger curled"),spread:xt("Fingers spread apart"),turn:_t("Hand turned about the forearm"),bend:_t("Hand bent at the wrist, palm-ward"),tilt:_t("Hand tilted sideways"),roll:_t("Hand rolled to show the back or the palm")};let lu;function Dw(t){lu=t}function Bw(t){return lu?.(t)??{}}function cu(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 Nn(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=cu(t)*n;const i=[t[0]];for(let o=1;o<t.length;o++){const r=t[o-1],a=t[o],l=Math.hypot(a.x-r.x,a.y-r.y);if(l>=s){const c=l===0?0:s/l;return i.push({x:r.x+(a.x-r.x)*c,y:r.y+(a.y-r.y)*c}),i}i.push(a),s-=l}return i}function qi(t,e){const n=Nn(t,e);return n[n.length-1]}function ya(t,e){return e>0?Math.floor(Math.max(0,t)*e/1e3):0}function Yi(t,e,n){const s=e.roughness??2,i=Math.max(1,Math.round(e.passes??2)),o=ya(n,e.boil??8);let r=0;const a=()=>{const d=r++;return f=>He(Xt(`${e.seed??1}:${o}:${d}:${f}`))},l=(d,f)=>(d.next()*2-1)*f,c=d=>{const f=a(),p=t.lineWidth,g=t.globalAlpha;for(let m=0;m<i;m++)t.lineWidth=m===0?p:p*.55,t.globalAlpha=m===0?g:g*.6,d(f(m));t.lineWidth=p,t.globalAlpha=g},h=(d,f=1)=>{if(d.length<2)return;const p=d.slice(1).map((m,w)=>Math.hypot(m.x-d[w].x,m.y-d[w].y)),g=p.reduce((m,w)=>m+w,0)*Math.min(1,Math.max(0,f));c(m=>{const w=[],v=[];if(d.forEach((y,T)=>{w.push({x:y.x+l(m,s*.5),y:y.y+l(m,s*.5)}),T>0&&v.push([m.next()*2-1,m.next()*2-1])}),g<=0)return;t.beginPath(),t.moveTo(w[0].x,w[0].y);let k=0;for(let y=1;y<w.length;y++){const T=zw(w[y-1],w[y],s,v[y-1]),$=p[y-1];if(k+$<=g){t.bezierCurveTo(T[1].x,T[1].y,T[2].x,T[2].y,T[3].x,T[3].y),k+=$;continue}const M=qw(T,$===0?1:(g-k)/$);t.bezierCurveTo(M[1].x,M[1].y,M[2].x,M[2].y,M[3].x,M[3].y);break}t.stroke()})},u=(d,f,p,g,m=1)=>{c(w=>{const k=w.next()*Math.PI*2,y=Math.PI*2+.15+w.next()*.3,T=[];for(let M=0;M<=14;M++){const x=k+y*M/14,S=l(w,s*.6);T.push({x:d+Math.cos(x)*(p+S),y:f+Math.sin(x)*(g+S)})}const $=Nn(T,m);$.length<2||(hu(t,$),t.stroke())})};return{line:h,curve(d,f=1){if(d.length<2)return;const p=d[0],g=d[d.length-1],m=Math.hypot(g.x-p.x,g.y-p.y)||1,w=-(g.y-p.y)/m,v=(g.x-p.x)/m;c(k=>{const y={x:l(k,s*.5),y:l(k,s*.5)},T={x:l(k,s*.5),y:l(k,s*.5)},$=l(k,s*Math.min(1.5,Math.max(.3,m/80))),M=d.map((S,E)=>{const P=E/(d.length-1),A=Math.sin(Math.PI*P)*$;return{x:S.x+y.x+(T.x-y.x)*P+w*A,y:S.y+y.y+(T.y-y.y)*P+v*A}}),x=Nn(M,f);x.length<2||(hu(t,x),t.stroke())})},circle(d,f,p,g=1){u(d,f,p,p,g)},ellipse:u,nudge(d=.5){const f=a()(0);return{x:l(f,s*d),y:l(f,s*d)}}}}function zw(t,e,n,s){const i=e.x-t.x,o=e.y-t.y,r=Math.hypot(i,o)||1,a=n*Math.min(1.5,Math.max(.3,r/80)),l=-o/r,c=i/r;return[t,{x:t.x+i/3+l*s[0]*a,y:t.y+o/3+c*s[0]*a},{x:t.x+2*i/3+l*s[1]*a,y:t.y+2*o/3+c*s[1]*a},e]}function qw([t,e,n,s],i){const o=(u,d)=>({x:u.x+(d.x-u.x)*i,y:u.y+(d.y-u.y)*i}),r=o(t,e),a=o(e,n),l=o(n,s),c=o(r,a),h=o(a,l);return[t,r,c,o(c,h)]}function hu(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 Ft(t,e,n){const s=t.length;if(s<2)return[];const i=[],o=[],r=a=>e+(n-e)*a/(s-1);return t.forEach((a,l)=>{const c=t[Math.max(0,l-1)],h=t[Math.min(s-1,l+1)],u=Math.hypot(h.x-c.x,h.y-c.y)||1,d=r(l)/2,f=-(h.y-c.y)/u*d,p=(h.x-c.x)/u*d;i.push({x:a.x+f,y:a.y+p}),o.push({x:a.x-f,y:a.y-p})}),[...i,...o.reverse()]}function Ki(t,e,n,s){const i=e.length;if(i<2)return;const o=Ft(e,n,s),r=a=>n+(s-n)*a/(i-1);t.beginPath(),t.moveTo(o[0].x,o[0].y);for(const a of o.slice(1))t.lineTo(a.x,a.y);t.closePath(),t.fill(),e.forEach((a,l)=>{l!==0&&l!==i-1&&i>3||(t.beginPath(),t.arc(a.x,a.y,r(l)/2,0,Math.PI*2),t.fill())})}function on(t,e,n,s,i=16){const o={x:2*e.x-(t.x+n.x)/2,y:2*e.y-(t.y+n.y)/2},r=[];for(let a=0;a<=i;a++){const l=a/i,c=l<.5?{x:t.x+(e.x-t.x)*2*l,y:t.y+(e.y-t.y)*2*l}:{x:e.x+(n.x-e.x)*(2*l-1),y:e.y+(n.y-e.y)*(2*l-1)},h=1-l,u={x:h*h*t.x+2*h*l*o.x+l*l*n.x,y:h*h*t.y+2*h*l*o.y+l*l*n.y};r.push({x:c.x+(u.x-c.x)*s,y:c.y+(u.y-c.y)*s})}return r}function ji(t,e,n,s,i,o=0,r=1,a=40){const l=Math.cos(i),c=Math.sin(i);return Array.from({length:a+1},(h,u)=>{const d=o+Math.PI*2*r*u/a,f=Math.cos(d)*n,p=Math.sin(d)*s;return{x:t+f*l-p*c,y:e+f*c+p*l}})}function _s(t,e){return e.look==="pencil"?jw(t,e):uu(t,e.ink,e.look)}function Xi(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 Cs(t,e){return e.look==="silhouette"?uu(t,e.ink,"silhouette",!1):e}function uu(t,e,n,s=!0){const i=n==="silhouette",o=i?1.25:1;return{look:n,ink:e,limb(r,a,l){t.fillStyle=e,Ki(t,r,a*o,l*o)},line(r,a){r.length<2||(t.strokeStyle=e,t.lineWidth=a*o,t.lineCap="round",t.lineJoin="round",Xi(t,r),t.stroke())},shape(r,a,l){Xi(t,r,!0),(a!==null||i&&s)&&(t.fillStyle=i?e:a,t.fill()),!(l<=0)&&(t.strokeStyle=e,t.lineWidth=l*o,t.lineJoin="round",t.stroke())},ellipse(r,a,l,c,h,u,d){t.beginPath(),t.ellipse(r,a,l,c,h,0,Math.PI*2),(u!==null||i&&s)&&(t.fillStyle=i?e:u,t.fill()),!(d<=0)&&(t.strokeStyle=e,t.lineWidth=d*o,t.stroke())},dot(r,a,l){t.fillStyle=e,t.beginPath(),t.arc(r,a,l*o,0,Math.PI*2),t.fill()},guide(){},guideEllipse(){}}}function Yw(t,e){const n=[t[0]];let s=0;for(let r=1;r<t.length;r++){const a=t[r-1],l=t[r],c=Math.hypot(l.x-a.x,l.y-a.y);let h=e-s;for(;h<c;){const u=h/c;n.push({x:a.x+(l.x-a.x)*u,y:a.y+(l.y-a.y)*u}),h+=e}s=c-(h-e)}const i=t[t.length-1],o=n[n.length-1];return Math.hypot(i.x-o.x,i.y-o.y)>e*.25?n.push(i):n[n.length-1]=i,n}function Kw(t,e){const n=t.length;return t.map((s,i)=>{const o=t[Math.max(0,i-1)],r=t[Math.min(n-1,i+1)],a=Math.hypot(r.x-o.x,r.y-o.y)||1,l=e(n===1?0:i/(n-1));return{x:s.x-(r.y-o.y)/a*l,y:s.y+(r.x-o.x)/a*l}})}function du(t){const e=[.6,1.4,2.9].map(s=>({frequency:s*(.8+t.next()*.4),phase:t.next()*Math.PI*2,amount:.5+t.next()*.5})),n=e.reduce((s,i)=>s+i.amount,0);return s=>e.reduce((i,o)=>i+o.amount*Math.sin(Math.PI*2*o.frequency*s+o.phase),0)/n}function jw(t,e){const n=e.pencil??{},s=e.ink,i=n.roughness??Math.max(1,e.lineWidth*.12),o=Math.max(1,Math.round(n.passes??2)),r=Math.min(1,Math.max(0,n.pressure??.25)),a=Math.min(1,Math.max(0,n.rubbedOut??.15)),l=ya(e.time,n.boil??8);let c=0;const h=(p,g,m=!1)=>He(Xt(`${e.seed}:${m?"paper":l}:${p}:${g}`)),u=(p,g,m,w,v,k=0)=>{if(p.length<2)return;const y=p.slice(1).reduce((P,A,I)=>P+Math.hypot(A.x-p[I].x,A.y-p[I].y),0);let T=Yw(p,Math.max(1.5,Math.min(e.lineWidth*.8,y/24)));if(k>0&&T.length>=2){const[P,A]=[T[T.length-2],T[T.length-1]],I=Math.hypot(A.x-P.x,A.y-P.y)||1;T=[...T,{x:A.x+(A.x-P.x)/I*k,y:A.y+(A.y-P.y)/I*k}]}const $=du(m),M=du(m),x=T.length,S=[],E=[];T.forEach((P,A)=>{const I=x===1?0:A/(x-1),_=T[Math.max(0,A-1)],N=T[Math.min(x-1,A+1)],Y=Math.hypot(N.x-_.x,N.y-_.y)||1,V=-(N.y-_.y)/Y,tt=(N.x-_.x)/Y,X=$(I)*v,R=Math.min(1,I/.08,(1-I)/.08),z=(.55+.45*Math.sqrt(Math.max(0,R)))*(1+r*M(I)),K=Math.max(.3,g(I)*z/2),O=P.x+V*X,D=P.y+tt*X;S.push({x:O+V*K,y:D+tt*K}),E.push({x:O-V*K,y:D-tt*K})}),t.save(),t.globalAlpha*=w,t.fillStyle=s,Xi(t,[...S,...E.reverse()],!0),t.fill(),t.restore()},d=(p,g)=>{const m=c++,w=h(m,99,!0);if(w.next()<a){const T=(w.next()*2-1)*e.lineWidth*1.4,$=(w.next()*2-1)*e.lineWidth*1.4,M=p.map(x=>({x:x.x+T,y:x.y+$}));u(M,x=>g(x)*1.8,h(m,98,!0),.035,i),u(M,x=>g(x)*.45,h(m,97,!0),.12,i*1.5)}const v=p.slice(1).reduce((T,$,M)=>T+Math.hypot($.x-p[M].x,$.y-p[M].y),0),k=g(.5)>4&&v>g(.5)*6,y=k?[-.3,.3,0]:[0];for(let T=0;T<o;T++){const $=T===0;y.forEach((M,x)=>{const S=h(m,T*10+x),E=M===0?p:Kw(p,A=>g(A)*M*Math.sqrt(Math.sin(Math.PI*A))),P=!$&&M===0?e.lineWidth*(.3+S.next()*.8):0;u(E,A=>g(A)*(k?.5:1)*($?1:.6),S,$?.85:.45,i*($?.6:1),P)})}},f=(p,g,m,w,v,k)=>{const T=h(c,50).next()*Math.PI*2;d(ji(p,g,m,w,v,T,1.08,48),()=>k)};return{look:"pencil",ink:s,limb(p,g,m){d(p,w=>g+(m-g)*w)},line(p,g){d(p,()=>g)},shape(p,g,m){g!==null&&(t.save(),t.globalAlpha*=.88,t.fillStyle=g,Xi(t,p,!0),t.fill(),t.restore()),m>0&&d([...p,p[0]],()=>m)},ellipse(p,g,m,w,v,k,y){k!==null&&(t.save(),t.globalAlpha*=.9,t.fillStyle=k,t.beginPath(),t.ellipse(p,g,m,w,v,0,Math.PI*2),t.fill(),t.restore()),f(p,g,m,w,v,y)},dot(p,g,m){t.save(),t.globalAlpha*=.9,t.fillStyle=s,t.beginPath(),t.arc(p,g,m,0,Math.PI*2),t.fill(),t.restore()},guide(p){if(n.construction===!1||p.length<2)return;const g=c++;u(p,()=>Math.max(.6,e.lineWidth*.18),h(g,0),.28,i*1.2,e.lineWidth)},guideEllipse(p,g,m,w,v){if(n.construction===!1)return;const k=c++,y=h(k,0),T=ji(p,g,m,w,v,y.next()*Math.PI*2,1.12,48);u(T,()=>Math.max(.6,e.lineWidth*.18),y,.28,i*1.5)}}}const fu=["thumb","index","middle","ring","pinky"],Pt={"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 Ht(t={}){return{...Pt,...t}}const Vt=(t,e,n,s,i)=>({"thumb.curl":t,"index.curl":e,"middle.curl":n,"ring.curl":s,"pinky.curl":i}),Ct={relaxed:Pt,open:Ht({...Vt(0,0,0,0,0),"thumb.across":0,spread:.55}),spread:Ht({...Vt(0,0,0,0,0),"thumb.across":0,spread:1}),flat:Ht({...Vt(0,0,0,0,0),"thumb.across":.35,spread:0}),fist:Ht({...Vt(.7,1,1,1,1),"thumb.across":.9,spread:0}),point:Ht({...Vt(.75,0,1,1,1),"thumb.across":.9,spread:0}),thumbsUp:Ht({...Vt(0,1,1,1,1),"thumb.across":0,spread:0,roll:70}),peace:Ht({...Vt(.75,0,0,1,1),"thumb.across":.9,spread:1}),ok:Ht({...Vt(.12,.6,.1,.15,.2),"thumb.across":.55,spread:.6}),pinch:Ht({...Vt(.1,.65,.75,.85,.9),"thumb.across":.55,spread:0}),cupped:Ht({...Vt(.25,.4,.4,.4,.4),"thumb.across":.4,spread:.05,turn:2}),wave:Ht({...Vt(0,.05,.05,.1,.12),"thumb.across":0,spread:.7,turn:2}),pencilGrip:Ht({...Vt(.1,.6,.72,.88,.95),"thumb.across":.5,spread:0,turn:.8,bend:10}),hold:Ht({...Vt(.5,.7,.72,.74,.76),"thumb.across":.75,spread:0,turn:1})};function Fn(t,e,n){const s={...t};for(const[i,o]of Object.entries(e)){const r=t[i]??o;s[i]=r+(o-r)*n}return s}const Xw={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}},Gw={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}},we={base:[-.11,.1,-.05],bones:[.2,.15,.12],widths:[.2,.145,.135],out:[-.7,.68,-.22],across:[.35,.5,-.8]},Uw=[82,100,62],Vw=[48,72],Jw=3,Zw=13,Qw=.035,t2=-.075,e2=[[-.17,0],[-.215,.12],[-.235,.26],[-.225,.4],[-.185,.49],[-.075,.525],[.05,.51],[.16,.465],[.215,.4],[.225,.26],[.2,.1],[.16,0]],Le=t=>t*Math.PI/180,ba=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Gi=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],wa=(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]],Hs=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function Ne(t,e,n){const s=Math.cos(n),i=Math.sin(n),o=wa(e,t),r=e[0]*t[0]+e[1]*t[1]+e[2]*t[2];return[t[0]*s+o[0]*i+e[0]*r*(1-s),t[1]*s+o[1]*i+e[1]*r*(1-s),t[2]*s+o[2]*i+e[2]*r*(1-s)]}const gu=[1,0,0],pu=[0,1,0],Rs=[0,0,1];function n2(t,e,n){const s=Le(t.fan*(Jw+Zw*n)),i=[Math.sin(s),Math.cos(s),0],o=[Math.cos(s),-Math.sin(s),0],r=[t.knuckle];let a=0;t.bones.forEach((h,u)=>{a+=Le(Uw[u]*e),r.push(ba(r[u],Gi(Ne(i,o,-a),h)))});const l=Ne(Rs,o,-a),c=r.map((h,u)=>t.width*(1-.14*(u/(r.length-1))));return{joints:r,back:l,widths:c}}function s2(t,e,n=1,s=1){const i=Math.min(1,Math.max(0,e)),o=Hs(ba(Gi(Hs(we.out),1-i),Gi(Hs(we.across),i))),r=Hs(wa(Rs,o)),a=Hs(wa(o,r)),l=[[we.base[0]*s,we.base[1],we.base[2]]];let c=0;we.bones.forEach((d,f)=>{f>0&&(c+=Le(Vw[f-1]*t)),l.push(ba(l[f],Gi(Ne(o,r,c),d)))});const h=Ne(a,r,c),u=[...we.widths,we.widths[we.widths.length-1]*.92].map(d=>d*n);return{joints:l,back:h,widths:u}}function Ui(t,e={}){const n={...Pt,...t},s=e.size??100,i=e.side??"right",o=i==="left"?-1:1,r=Le(e.angle??0),a=e.fingers===4,l=Math.max(.5,e.plump??1),c=1+(l-1)*.7,h=A=>({...A,knuckle:[A.knuckle[0]*c,A.knuckle[1],A.knuckle[2]],width:A.width*l}),u=Le(n.bend??0),d=Le(n.tilt??0),f=Le(90*(n.turn??0)),p=A=>Ne(Ne(Ne(A,gu,-u),Rs,-d),pu,f),g=Math.cos(r),m=Math.sin(r),w=Le(n.roll??0),v=Math.cos(w),k=Math.sin(w),y=A=>{const I=A[0]*s,_=-A[1]*s,N=(I*v-_*k)*o,Y=I*k+_*v;return{x:N*g-Y*m,y:N*m+Y*g}},T=A=>{const I=y(A),_=Math.hypot(I.x,I.y);return _>1e-6*s?{x:I.x/_,y:I.y/_}:{x:0,y:0}},$={thumb:s2(n["thumb.curl"]??0,n["thumb.across"]??0,l,c)},M=a?Gw:Xw;for(const A of fu){const I=M[A];I&&($[A]=n2(h(I),n[`${A}.curl`]??0,n.spread??0))}const x={};for(const[A,I]of Object.entries($)){const _=I.joints.map(p),N=p(I.back);x[A]={points:_.map(y),depths:_.map(Y=>Y[2]*s),widths:I.widths.map(Y=>Y*s),nail:N[2],back:T(N)}}const S=e2.flatMap(([A,I])=>[p([A*c,I,Qw]),p([A*c,I,t2])]),E=i2(S.map(y)),P=S.reduce((A,I)=>A+I[2],0)/S.length*s;return{size:s,side:i,wrist:{x:0,y:0},palm:E,palmDepth:P,palmFacing:-p(Rs)[2],fingers:x,axes:{up:T(p(pu)),across:T(p(gu)),out:T(p(Rs))},curls:Object.fromEntries(Object.keys(x).map(A=>[A,n[`${A}.curl`]??0]))}}function mu(t,e){const n=i=>({x:i.x+e.x-t.wrist.x,y:i.y+e.y-t.wrist.y}),s={};for(const[i,o]of Object.entries(t.fingers))s[i]={...o,points:o.points.map(n)};return{...t,wrist:n(t.wrist),palm:t.palm.map(n),fingers:s}}function i2(t){const e=[...t].sort((o,r)=>o.x-r.x||o.y-r.y);if(e.length<3)return e;const n=(o,r,a)=>(r.x-o.x)*(a.y-o.y)-(r.y-o.y)*(a.x-o.x),s=[];for(const o of e){for(;s.length>=2&&n(s[s.length-2],s[s.length-1],o)<=0;)s.pop();s.push(o)}const i=[];for(const o of[...e].reverse()){for(;i.length>=2&&n(i[i.length-2],i[i.length-1],o)<=0;)i.pop();i.push(o)}return[...s.slice(0,-1),...i.slice(0,-1)]}function yu(t,e,n,s){if(s.mode!=="cel"||e.length<3)return;const i=Math.hypot(...s.light),o=e.map(a=>{const l=a.x-n.x,c=a.y-n.y,h=(l*s.light[0]+c*s.light[1])/((Math.hypot(l,c)||1)*i),u=Math.max(0,-h)*.24;return{x:a.x-l*u,y:a.y-c*u}}),r=a=>{t.beginPath(),t.moveTo(a[0].x,a[0].y);for(const l of a.slice(1))t.lineTo(l.x,l.y);t.closePath()};t.save(),r(e),t.clip(),r([...e,...o.reverse()]),t.globalAlpha*=s.opacity,t.fillStyle=s.shadow,t.fill(),t.restore()}const o2="#f1c9a5",r2="#2f2f33";function Vi(t,e,n,s={},i=0){const o=mu(Ui(n,s),e),r=s.ink??r2,a=s.lineWidth??o.size*.035;let l=s.pen??_s(t,{look:s.look??"clean",ink:r,lineWidth:a,seed:s.seed??1,time:i,pencil:{construction:!1,...s.pencil}});const c=s.skin??o2;c==="none"&&(l=Cs(t,l));const h=s.nails??!0,u=[{depth:o.palmDepth,draw:()=>a2(t,l,o,c,a,s)}];for(const d of Object.values(o.fingers)){const f=d.depths.reduce((p,g)=>p+g,0)/d.depths.length;u.push({depth:f,draw:()=>l2(t,l,d,c,a,h)})}if(s.prop){const d=s.prop;u.push({depth:d.depth,draw:()=>d.draw(l)})}t.save(),t.lineCap="round",t.lineJoin="round";for(const d of[...u].sort((f,p)=>f.depth-p.depth))d.draw();return t.restore(),o}function a2(t,e,n,s,i,o){if(e.shape(n.palm,s==="none"?null:s,o.connected?0:i),s!=="none"&&o.shading&&e.look==="clean"){const r=n.palm.reduce((a,l)=>({x:a.x+l.x/n.palm.length,y:a.y+l.y/n.palm.length}),{x:0,y:0});yu(t,n.palm,r,o.shading)}if(o.connected&&i>0&&(e.look!=="silhouette"||s==="none")){const{up:r}=n.axes;let a=[];for(let l=0;l<=n.palm.length;l++){const c=n.palm[l%n.palm.length],h=n.palm[(l+1)%n.palm.length];((c.x+h.x)/2-n.wrist.x)*r.x+((c.y+h.y)/2-n.wrist.y)*r.y<n.size*.08?(a.length>1&&e.line(a,i),a=[]):(a.length===0&&a.push(c),a.push(h))}a.length>1&&e.line(a,i)}if(n.palmFacing<-.3&&e.look!=="silhouette"){const{up:r}=n.axes;for(const[a,l]of Object.entries(n.fingers)){const c=n.curls[a]??0;if(a==="thumb"||c<.5)continue;const h=l.points[0],u=l.widths[0]*.42,d={x:h.x-r.x*u*.2,y:h.y-r.y*u*.2},f=Math.atan2(r.y,r.x),p=Array.from({length:7},(g,m)=>{const w=f-Math.PI/2+Math.PI*m/6;return{x:d.x+Math.cos(w)*u,y:d.y+Math.sin(w)*u}});e.line(p,i*.6)}}if(n.palmFacing>.45&&e.look!=="silhouette"){const{up:r,across:a}=n.axes,l=n.size,c=n.wrist,h=(d,f)=>({x:c.x+(a.x*d+r.x*f)*l,y:c.y+(a.y*d+r.y*f)*l}),u=n.side==="left"?-1:1;e.line([h(-.15*u,.36),h(-.04*u,.3),h(.1*u,.33)],i*.5)}}function l2(t,e,n,s,i,o){const{widths:r}=n,a=c2(n.points,2),l=n.points[0],c=a[a.length-1],h=r[0],u=r[r.length-1];if(t.save(),e.look!=="silhouette"||s==="none"){t.beginPath(),t.rect(l.x-1e5,l.y-1e5,2e5,2e5);const g=h/2+i*1.6;t.moveTo(l.x+g,l.y),t.arc(l.x,l.y,g,0,Math.PI*2),t.clip("evenodd")}if(s==="none"){const g=Ft(a,h,u),m=a[a.length-2],w=Math.atan2(c.y-m.y,c.x-m.x),v=Array.from({length:13},(k,y)=>{const T=w+Math.PI/2-y*Math.PI/12;return{x:c.x+Math.cos(T)*u/2,y:c.y+Math.sin(T)*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,Ki(t,a,h,u)),s==="none"||e.look==="silhouette"||!o||n.nail<.25)return;const d=a[a.length-2],f=h2({x:c.x-d.x,y:c.y-d.y})??{x:0,y:-1},p={x:c.x-f.x*u*.22+n.back.x*u*.1,y:c.y-f.y*u*.22+n.back.y*u*.1};e.ellipse(p.x,p.y,u*.24*Math.max(.35,n.nail),u*.19,Math.atan2(f.y,f.x),"#f8e3d3",i*.45)}function c2(t,e){let n=t;for(let s=0;s<e;s++){if(n.length<3)return n;const i=[n[0]];for(let o=0;o<n.length-1;o++){const r=n[o],a=n[o+1];o>0&&i.push({x:r.x*.75+a.x*.25,y:r.y*.75+a.y*.25}),o<n.length-2&&i.push({x:r.x*.25+a.x*.75,y:r.y*.25+a.y*.75})}i.push(n[n.length-1]),n=i}return n}const h2=t=>{const e=Math.hypot(t.x,t.y);return e>1e-6?{x:t.x/e,y:t.y/e}:null},Dt={walk:{swing:24,knee:30,arm:22,elbow:28,lean:4},bouncy:{swing:26,knee:45,arm:34,elbow:30,lean:2,bend:-4,bounce:.035,squash:.06},doubleBounce:{swing:22,knee:40,arm:26,elbow:24,lean:3,bounce:.02,bounces:2,squash:.04},sneak:{swing:28,knee:70,arm:6,elbow:0,forearm:110,shoulder:55,lean:16,bend:14,headTilt:-8,crouch:50,tiptoe:25},strut:{swing:26,knee:30,arm:30,elbow:20,lean:-4,bend:-10,headTilt:-6,sway:4,bounce:.01},tired:{swing:14,knee:14,arm:6,elbow:6,lean:10,bend:16,headTilt:12},run:{swing:40,knee:95,arm:45,elbow:0,forearm:90,lean:16,bend:6,bounce:.05,squash:.06},shove:{swing:18,knee:28,arm:0,elbow:0,lean:0}},u2=40;function Ls(t){return t===void 0?Dt.walk:typeof t=="string"?Dt[t]??Dt.walk:t}function bu(t,e,n=ht,s=1){const i=Ls(t);if(i===Dt.walk)return Su(e,n,s);const o=e*Math.PI*2,r=Math.sin(o)*s,a=Math.cos(o)*s,l=w=>Math.abs(w)<=u2,c=i.shoulder??0,h=(w,v)=>l(w)?v*c+i.arm*r:w,u=i.forearm??0,d=l(n.leftShoulder)?n.leftElbow-u-i.elbow*Math.max(0,-r):n.leftElbow,f=l(n.rightShoulder)?n.rightElbow+u+i.elbow*Math.max(0,r):n.rightElbow,p=i.bounces??1,g=(1+Math.cos(o*2*p))/2,m=i.crouch??0;return{...n,lean:n.lean+i.lean*s+(i.sway??0)*Math.sin(o)*(1-(n.turn??0)),bend:(n.bend??0)+(i.bend??0),headTilt:n.headTilt-i.lean*.5*s+(i.headTilt??0),leftElbow:d,rightElbow:f,leftHip:-i.swing*r-m*.5,rightHip:-i.swing*r+m*.5,leftKnee:-i.knee*Math.max(0,a)-m,rightKnee:i.knee*Math.max(0,-a)+m,leftAnkle:(n.leftAnkle??0)+(i.tiptoe??0),rightAnkle:(n.rightAnkle??0)+(i.tiptoe??0),leftShoulder:h(n.leftShoulder,-1),rightShoulder:h(n.rightShoulder,1),rise:(n.rise??0)+(i.bounce??0)*s*g,stretch:n.stretch*(1+(i.squash??0)*(g-.5))}}function Ji(t,e,n=1){const s=Ls(t),i=Dt.walk.swing,o=r=>Math.sin(r*Math.PI/180);return xu(e,n)*o(s.swing*n)/o(i*n)}const ht={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 Rt(t){return{...ht,...t}}const wu={mouth:0,smile:0,mouthWidth:1,leftEye:1,rightEye:1,leftBrow:0,rightBrow:0,browTilt:0,lookX:0,lookY:0},Wt=t=>({...wu,...t}),vt={neutral:wu,happy:Wt({smile:.9,leftBrow:.2,rightBrow:.2}),joyful:Wt({mouth:.6,smile:1,mouthWidth:1.2,leftEye:0,rightEye:0,leftBrow:.4,rightBrow:.4}),sad:Wt({smile:-.8,leftEye:.8,rightEye:.8,browTilt:.9,leftBrow:-.1,rightBrow:-.1,lookY:.6}),crying:Wt({mouth:.45,smile:-1,leftEye:0,rightEye:0,browTilt:1,lookY:.4}),surprised:Wt({mouth:.7,mouthWidth:.7,leftEye:1.5,rightEye:1.5,leftBrow:1,rightBrow:1}),shocked:Wt({mouth:1,mouthWidth:.8,leftEye:1.6,rightEye:1.6,leftBrow:1,rightBrow:1,browTilt:.4}),angry:Wt({smile:-.6,mouthWidth:.9,leftEye:.8,rightEye:.8,leftBrow:-.6,rightBrow:-.6,browTilt:-1}),furious:Wt({mouth:.5,smile:-1,mouthWidth:1.3,leftEye:.9,rightEye:.9,leftBrow:-.9,rightBrow:-.9,browTilt:-1}),worried:Wt({smile:-.3,mouthWidth:.8,leftEye:1.1,rightEye:1.1,leftBrow:.3,rightBrow:.3,browTilt:.8,lookX:-.5}),scared:Wt({mouth:.35,smile:-.5,mouthWidth:.8,leftEye:1.45,rightEye:1.45,leftBrow:.8,rightBrow:.8,browTilt:.9}),confused:Wt({smile:-.2,mouthWidth:.8,leftEye:.9,rightEye:1.15,leftBrow:-.3,rightBrow:.8,lookX:.5,lookY:-.4}),skeptical:Wt({smile:-.1,leftEye:.6,rightEye:1,leftBrow:-.4,rightBrow:.7,lookX:.4}),thinking:Wt({smile:0,mouthWidth:.7,leftBrow:.3,rightBrow:.5,lookX:.6,lookY:-.8}),sleepy:Wt({smile:.1,leftEye:.25,rightEye:.25,leftBrow:-.3,rightBrow:-.3,lookY:.5}),disgusted:Wt({smile:-.7,mouthWidth:.9,leftEye:.6,rightEye:.75,leftBrow:-.5,rightBrow:-.2,browTilt:-.4,lookX:-.6}),smug:Wt({smile:.6,mouthWidth:.9,leftEye:.6,rightEye:.6,leftBrow:.1,rightBrow:.5,lookX:.5}),wink:Wt({smile:.9,leftEye:0,rightEye:1,leftBrow:-.2,rightBrow:.3})};function Fe(t,e){return{...t,...typeof e=="string"?vt[e]:e}}const Jt={rest:ht,wave:Rt({rightShoulder:135,rightElbow:30,headTilt:6,...vt.happy}),cheer:Rt({leftShoulder:125,leftElbow:20,rightShoulder:125,rightElbow:20,...vt.joyful}),shrug:Rt({leftShoulder:30,leftElbow:85,rightShoulder:30,rightElbow:85,headTilt:-10,...vt.confused,lookX:0,lookY:0}),point:Rt({rightShoulder:90,rightElbow:0,lean:4,smile:.4}),think:Rt({rightShoulder:60,rightElbow:150,headTilt:10,...vt.thinking}),handsOnHips:Rt({leftShoulder:45,leftElbow:-100,rightShoulder:45,rightElbow:-100,leftHip:14,rightHip:14,smile:.8}),sad:Rt({leftShoulder:14,rightShoulder:14,leftElbow:-4,rightElbow:-4,headTilt:-14,lean:-3,...vt.sad}),surprised:Rt({leftShoulder:70,leftElbow:60,rightShoulder:70,rightElbow:60,...vt.surprised}),crouch:Rt({stretch:.72,leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50,leftHip:22,rightHip:22,headTilt:-4}),sit:Rt({sit:1,turn:.5,leftShoulder:-25,rightShoulder:25,leftElbow:-55,rightElbow:55}),jump:Rt({stretch:1.22,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4,...vt.joyful}),duck:Rt({stretch:.62,bend:28,headTilt:-8,leftShoulder:150,rightShoulder:150,leftElbow:130,rightElbow:130,leftHip:25,rightHip:25,...vt.scared}),lie:Rt({spin:-90,rise:-.42,leftShoulder:165,rightShoulder:165,leftElbow:150,rightElbow:150,...vt.sleepy}),sideSplit:Rt({leftHip:90,rightHip:90,leftAnkle:-45,rightAnkle:-45,leftShoulder:120,rightShoulder:120,leftElbow:10,rightElbow:10,...vt.happy}),frontSplit:Rt({turn:1,leftHip:-90,rightHip:-90,leftAnkle:-45,rightAnkle:-45,leftShoulder:-150,rightShoulder:150,leftElbow:10,rightElbow:-10,...vt.happy})},ku=Object.keys(ht);function Wn(t,e,n){const s={...t};for(const i of ku)s[i]=t[i]+(e[i]-t[i])*n;return s}const ka=24,vu=4,Mu=28,d2=40;function Su(t,e=ht,n=1){const s=Math.sin(t*Math.PI*2)*n,i=Math.cos(t*Math.PI*2)*n,o=c=>Math.abs(c)<=d2,r=c=>o(c)?22*s:c,a=o(e.leftShoulder)?e.leftElbow-Mu*Math.max(0,-s):e.leftElbow,l=o(e.rightShoulder)?e.rightElbow+Mu*Math.max(0,s):e.rightElbow;return{...e,lean:e.lean+vu*n,headTilt:e.headTilt-vu*.5*n,leftElbow:a,rightElbow:l,leftHip:-ka*s,rightHip:-ka*s,leftKnee:-30*Math.max(0,i),rightKnee:30*Math.max(0,-i),leftShoulder:r(e.leftShoulder),rightShoulder:r(e.rightShoulder)}}function xu(t,e=1){return 4*((va+Zi)*t)*Math.sin(ka*e*Math.PI/180)}function Tu(t){const e=Math.abs(Math.sin(t/65)),n=.55+.45*Math.sin(t/310);return e*n}const Eu=.12,Au=.46,f2=1-2*Eu,g2=.1,p2=.21,m2=.19,va=.24,Zi=.22,Pu=.12,y2=.14,$u=.33,Iu=.7,Ou=.3,b2=.35,w2=[1.7,1.05],k2=[1.3,.75],_u=[1.45,.85],v2=[1.15,.75],Cu=.06,M2=.7,S2=.65,Hu=.075,x2=.3,T2=.02,E2=.012,A2=12,P2=.25,Qi=90,$2=.25,I2=.04,Ru=.01,rn=t=>Math.min(1,Math.max(0,t??0));function O2(t,e=1){return Zi*t*e}const Ma=-.12,Lu=.4,ne=t=>t*Math.PI/180,_2=(t,e)=>({x:e*Math.sin(ne(t)),y:Math.cos(ne(t))}),Nu=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),Fu=(t,e,n,s)=>t-.3*e-n*.14*e-Math.max(0,s-1)*.12*e;function C2(t,e,n,s,i,o){const r=Math.max(1,Math.min(o*.6,y2*n)),a=rn(e.turn),l=(Pu+$u*a)*n,c=s+Ma*n,h=l+e.lookX*.08*n,u=e.lookY*.07*n,d=[{x:-.34*n*(1-Iu*a),squeeze:1-Iu*a,open:e.leftEye,brow:e.leftBrow,side:-1},{x:.34*n*(1-Ou*a),squeeze:1-Ou*a,open:e.rightEye,brow:e.rightBrow,side:1}];t.fillStyle=i,t.strokeStyle=i,t.lineWidth=r;for(const w of d){const v=Nu(w.open,e.blink);if(v<.2){const $=e.smile>.5?-.12*n:.06*n;t.beginPath(),t.moveTo(w.x+l-.12*n,c),t.quadraticCurveTo(w.x+l,c+$,w.x+l+.12*n,c),t.stroke()}else{if(v>1.2){const M=.13*n*v;t.beginPath(),t.ellipse(w.x+l,c,M*.85,M,0,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.stroke(),t.fillStyle=i}const $=v>1.2?.075*n:.1*n;t.beginPath(),t.ellipse(w.x+h,c+u,$,$*1.1*Math.min(v,1),0,0,Math.PI*2),t.fill()}const k=Fu(c,n,w.brow,v),y=w.x+l-w.side*.13*n*w.squeeze,T=w.x+l+w.side*.13*n*w.squeeze;t.beginPath(),t.moveTo(T,k),t.lineTo(y,k-e.browTilt*.1*n),t.stroke()}const f=s+Lu*n,p=.25*n*Math.max(.3,e.mouthWidth)*(1-b2*a),g=Math.min(1,Math.max(0,e.mouth));if(t.beginPath(),g<=.05){t.moveTo(l-p,f),t.quadraticCurveTo(l,f+e.smile*.25*n,l+p,f),t.stroke();return}const m=.3*n*g;e.smile>.3?(t.moveTo(l-p,f-.05*n),t.lineTo(l+p,f-.05*n),t.quadraticCurveTo(l,f+m*2,l-p,f-.05*n)):e.smile<-.3?(t.moveTo(l-p,f+m*.6),t.lineTo(l+p,f+m*.6),t.quadraticCurveTo(l,f-m*1.4,l-p,f+m*.6)):t.ellipse(l,f,p*.8,m,0,0,Math.PI*2),t.fill()}function Wu(t,e){const n=e.height??300,s=Math.min(3,Math.max(.3,t.stretch??1)),i=Math.sqrt(s),o=e.armLength??1;if(!Number.isFinite(o)||o<=0)throw new Error("stick figure: armLength must be a positive finite multiplier");const r=(e.headSize??2*Eu)/2,a=e.headSize===void 0?f2:1-2*r,l=r*n,c=rn(t.sit),h=t.leftHip+(-Qi-t.leftHip)*c,u=t.leftKnee+(-Qi-t.leftKnee)*c,d=t.rightHip+(Qi-t.rightHip)*c,f=t.rightKnee+(Qi-t.rightKnee)*c,p=e.classic===!0,g=rn(t.turn),m=(X,R,z,K,O)=>{const D=Math.max(-Math.PI/2,Math.min(Math.PI/2,Math.abs(ne(R-z)/2)+ne(K))),st=Math.max(-1,Math.min(1,M2+O)),H=g+(1-g)*X*st;return p?{x:0,y:0}:{x:Math.cos(D)*Cu*H,y:Math.sin(D)*Cu}},w={left:t.leftAnkle??0,right:t.rightAnkle??0},v={left:t.leftFootOut??0,right:t.rightFootOut??0};let k=0;if(c>0||!p){const X=(O,D,st,H,L)=>va*Math.cos(ne(D))+Zi*Math.cos(ne(D-st))+Math.max(0,m(O,D,st,H,L).y),R=Math.max(X(-1,h,u,w.left,v.left),X(1,d,f,w.right,v.right)),z=1-rn((t.rise??0)/I2),K=(p?Math.min(1,c/$2):1)*z;k=(Au-R)*K*n*s}const y=-Au*n*s+k,T=-a*n*s+k,$=p?0:(T2*rn(t.turn)+E2*c)*n*s,M=ne(t.bend??0),x={end:Bu(y,T,M,1),bend:M};let S;if(M!==0){S=[];for(let X=0;X<=Du;X++){const R=X/Du,z=Bu(y,T,M,R);S.push({x:z.x-$*Math.sin(Math.PI*R),y:z.y})}}else S=$===0?[{x:0,y},{x:0,y:T}]:on({x:0,y},{x:-$,y:(y+T)/2},{x:0,y:T},1,8);const E=T+g2*n*s,P=(e.shoulderWidth??0)*n*Math.cos(g*Math.PI/2),A=(X,R,z,K,O)=>{const D=_2(z,K);return{x:X+D.x*O*n,y:R+D.y*O*n}},I=(X,R,z)=>{const K=A(0,y,R,X,va*s);return{root:{x:0,y},joint:K,end:A(K.x,K.y,R-z,X,Zi*s)}},_=(X,R,z)=>{const K={x:X*P,y:E},O=A(K.x,K.y,R,X,p2*i*o);return{root:K,joint:O,end:A(O.x,O.y,R+z,X,m2*i*o)}},N={left:I(-1,h,u),right:I(1,d,f)},Y=(X,R,z,K,O,D)=>{const st=m(X,z,K,O,D);return{x:R.end.x+st.x*n*s,y:R.end.y+st.y*n*s}},V=(X,R,z,K,O)=>A(R.end.x,R.end.y,z+K+O,X,Hu*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(p?0:x2,e.rubber??0)),r:l,headRx:l/Math.sqrt(s),headRy:l*Math.sqrt(s),hipY:y,neckY:T,drop:k,lean:p?t.lean:t.lean+A2*Math.sin(Math.PI*c),classic:p,legs:N,toes:{left:Y(-1,N.left,h,u,w.left,v.left),right:Y(1,N.right,d,f,w.right,v.right)},spine:S,chest:x,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 Du=10;function Bu(t,e,n,s){const i=t-e,o=n*s;if(Math.abs(n)<1e-9)return{x:0,y:t-i*s};const r=i/n;return{x:r*(1-Math.cos(o)),y:t-r*Math.sin(o)}}function H2(t,e){if(t.chest.bend===0)return e;const n=Fs(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 Ns=(t,e)=>e===0?[t.root,t.joint,t.end]:on(t.root,t.joint,t.end,e);function Fs(t,e,n){const s=Math.cos(n),i=Math.sin(n),o=t.x-e.x,r=t.y-e.y;return{x:e.x+o*s-r*i,y:e.y+o*i+r*s}}function zu(t,e,n=!0){const s=L2(t,e),i=e.spin??0,o=e.rise??0;return n&&(i!==0||o!==0)?R2(s,t,i,o):s}function qu(t,e,n){return{pivot:{x:0,y:t.hipY},angle:t.facing*ne(e),lift:n*t.height}}function R2(t,e,n,s){const{pivot:i,angle:o,lift:r}=qu(e,n,s),a=d=>{const f=Fs(d,i,o);return{x:f.x,y:f.y-r}},l=d=>({left:a(d.left),right:a(d.right)}),c={left:Math.max(a(t.feet.left).y,a(t.toes.left).y),right:Math.max(a(t.feet.right).y,a(t.toes.right).y)},h=Math.max(c.left,c.right),u=Ru*e.height;return{...t,hip:a(t.hip),neck:a(t.neck),shoulders:l(t.shoulders),elbows:l(t.elbows),hands:l(t.hands),fingertips:l(t.fingertips),knees:l(t.knees),feet:l(t.feet),toes:l(t.toes),feetY:h,grounded:{left:c.left>=h-u,right:c.right>=h-u},handAngle:{left:t.handAngle.left+o,right:t.handAngle.right+o},limbs:{leftArm:t.limbs.leftArm.map(a),rightArm:t.limbs.rightArm.map(a),leftLeg:t.limbs.leftLeg.map(a),rightLeg:t.limbs.rightLeg.map(a),spine:t.limbs.spine.map(a)},head:{...t.head,center:a(t.head.center),angle:t.head.angle+o}}}function L2(t,e){const n=ne(t.lean),s=ne(e.headTilt),i={x:0,y:t.hipY},o=y=>({x:t.facing*y.x,y:y.y}),r=y=>o(Fs(y,i,n)),a=y=>r(H2(t,y)),l=y=>a(Fs({x:y.x,y:y.y+t.neckY},{x:0,y:t.neckY},s)),c=Ns(t.arms.left,t.rubber).map(a),h=Ns(t.arms.right,t.rubber).map(a),u=(y,T)=>Math.atan2(T.y-y.y,T.x-y.x),d={left:a(t.handTips.left),right:a(t.handTips.right)},f=(y,T)=>{const[$,M]=y.slice(-2),x=t.arms[T],S=u(a(x.end),d[T])-u(a(x.joint),a(x.end));return u($,M)+S};let p=1/0;for(const[y,T]of[[e.leftBrow,e.leftEye],[e.rightBrow,e.rightEye]]){const $=Fu(Ma,1,y,Nu(T,e.blink));p=Math.min(p,$,$-e.browTilt*.1)}const g={left:o(t.legs.left.end),right:o(t.legs.right.end)},m={left:o(t.toes.left),right:o(t.toes.right)},w={left:Math.max(g.left.y,m.left.y),right:Math.max(g.right.y,m.right.y)},v=Math.max(w.left,w.right),k=Ru*t.height;return{facing:t.facing,height:t.height,stretch:t.stretch,lineWidth:t.lineWidth,hip:i,neck:a({x:0,y:t.neckY}),shoulders:{left:a(t.arms.left.root),right:a(t.arms.right.root)},elbows:{left:a(t.arms.left.joint),right:a(t.arms.right.joint)},hands:{left:a(t.arms.left.end),right:a(t.arms.right.end)},knees:{left:o(t.legs.left.joint),right:o(t.legs.right.joint)},feet:g,toes:m,feetY:v,grounded:{left:w.left>=v-k,right:w.right>=v-k},fingertips:d,handAngle:{left:f(c,"left"),right:f(h,"right")},limbs:{leftArm:c,rightArm:h,leftLeg:Ns(t.legs.left,t.rubber).map(o),rightLeg:Ns(t.legs.right,t.rubber).map(o),spine:t.spine.map(r)},head:{center:l({x:0,y:-t.headRy}),rx:t.headRx,ry:t.headRy,angle:t.facing*(n+t.chest.bend+s),eyeY:Ma,browTopY:p,mouthY:Lu,faceX:t.facing*(Pu+$u*rn(e.turn))}}}function le(t,e={}){return zu(Wu(t,e),t)}function N2(t,e,n){return Fs({x:t.center.x+e*t.rx,y:t.center.y+n*t.ry},t.center,t.angle)}function Yu(t,e,n){const s=o=>({x:o.x+e,y:o.y+n}),i=o=>({left:s(o.left),right:s(o.right)});return{...t,hip:s(t.hip),neck:s(t.neck),shoulders:i(t.shoulders),elbows:i(t.elbows),hands:i(t.hands),fingertips:i(t.fingertips),knees:i(t.knees),feet:i(t.feet),toes:i(t.toes),feetY:t.feetY+n,grounded:{...t.grounded},handAngle:{...t.handAngle},limbs:{leftArm:t.limbs.leftArm.map(s),rightArm:t.limbs.rightArm.map(s),leftLeg:t.limbs.leftLeg.map(s),rightLeg:t.limbs.rightLeg.map(s),spine:t.limbs.spine.map(s)},head:{...t.head,center:s(t.head.center)}}}function Ku(t,e,n={},s=0){const i=Wu(e,n),o=n.color??"#1e293b",r=n.layers??{},a=n.layers?zu(i,e,!1):void 0,l=n.sketch?Yi(t,n.sketch,s):void 0,c=n.sketch&&n.layers?Yi(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(ne(i.lean)),t.translate(0,-i.hipY)},p=()=>{f(),i.chest.bend!==0&&(t.translate(i.chest.end.x,i.chest.end.y),t.rotate(i.chest.bend),t.translate(0,-i.neckY))},g=(M,x,S)=>{if(l)return x?l.curve(M):l.line(M);if(i.classic){t.beginPath(),t.moveTo(M[0].x,M[0].y);for(const E of M.slice(1))t.lineTo(E.x,E.y);t.stroke();return}Ki(t,M,S[0]*i.lineWidth,S[1]*i.lineWidth)},m=(M,x)=>g(Ns(M,i.rubber),i.rubber>0,x),w=M=>{i.classic||g([i.legs[M].end,i.toes[M]],!1,v2)},v=M=>{if(n.hands&&!i.classic)return y(M);if(i.classic||l)return;const x=i.arms[M].end;t.beginPath(),t.arc(x.x,x.y,S2*i.lineWidth,0,Math.PI*2),t.fill()};t.save(),t.strokeStyle=o,t.fillStyle=o,t.lineWidth=i.lineWidth,t.lineCap="round",t.lineJoin="round";const k=qu(i,e.spin??0,e.rise??0);(k.angle!==0||k.lift!==0)&&(t.translate(0,-k.lift),t.translate(k.pivot.x,k.pivot.y),t.rotate(k.angle),t.translate(-k.pivot.x,-k.pivot.y));function y(M){const x=n.hands??{},S=i.arms[M].end,E=i.handTips[M],P=n.headFill??"#ffffff";Vi(t,S,x[M]??Pt,{side:M,angle:Math.atan2(E.x-S.x,S.y-E.y)*180/Math.PI,size:(x.size??Hu)*i.height*Math.sqrt(i.stretch),skin:x.skin??(P==="none"?void 0:P),ink:o,lineWidth:i.lineWidth*.45,fingers:x.fingers,plump:x.plump,look:n.sketch?"pencil":"clean",seed:n.sketch?.seed},s)}const T=M=>{h(()=>{p(),m(i.arms[M],k2),v(M)});const x=r.sleeve;x&&a&&h(()=>x(t,a,M,s,c))},$=rn(e.turn)>P2;u(r.behind),h(()=>{d(),m(i.legs.left,_u),w("left"),m(i.legs.right,_u),w("right")}),$&&T("left"),h(()=>{f(),g(i.spine,i.spine.length>2,w2)}),h(()=>{p();const{left:M,right:x}={left:i.arms.left.root,right:i.arms.right.root};if(M.x!==x.x)if(i.classic)g([M,x],!1,[1,1]);else{const S={x:(M.x+x.x)/2,y:M.y-.3*Math.abs(x.x-M.x)};g(on(M,S,x,1,8),!0,[1.1,1.1])}}),u(r.body),$||T("left"),T("right"),u(r.behindHead),h(()=>{p(),t.translate(0,i.neckY),t.rotate(ne(e.headTilt));const M=-i.headRy;t.beginPath(),t.ellipse(0,M,i.headRx,i.headRy,0,0,Math.PI*2);const x=n.headFill??"#ffffff";if(x!=="none"&&(t.fillStyle=x,t.fill()),l){l.ellipse(0,M,i.headRx,i.headRy);const S=l.nudge();t.translate(S.x,S.y)}else t.stroke();t.translate(0,M),t.scale(i.headRx/i.r,i.headRy/i.r),C2(t,e,i.r,0,o,i.lineWidth)}),u(r.overHead),u(r.front),t.restore(),n.label&&(t.save(),t.fillStyle=o,t.font=n.labelFont??`700 ${Math.round(i.height*.11)}px sans-serif`,t.textAlign="center",t.textBaseline="bottom",t.fillText(n.label,0,-i.height*i.stretch-.04*i.height+i.drop),t.restore())}function Sa(t,e,n,s){const i={...t},o=t.gait&&s?.[t.gait]||t.gait;let r=t.walking>0?Wn(i,bu(o,t.walk,i),t.walking):i,a=F2(t);const l=t.dancing??0;if(n&&l>0){const c=n(t.beat??0);if(r=Wn(r,c.pose,l),c.hands){const h=(u,d)=>d?Fn(u??Pt,d,l):u;a={left:h(a?.left,c.hands.left),right:h(a?.right,c.hands.right)}}}return t.talk>0&&(r={...r,mouth:Math.max(r.mouth,t.talk*Tu(e))}),{pose:r,hands:a}}function ju(t,e,n,s){return Sa(t,e,n,s).pose}const Xu=(t,e)=>(t.facing??e.facing??1)<0?-1:1,Ws=(t,e)=>`hand.${t}.${e}`;function F2(t){const e=i=>{if(typeof t[Ws(i,"spread")]=="number")return Object.fromEntries(Object.keys(Pt).map(o=>[o,t[Ws(i,o)]]))},n=e("left"),s=e("right");return n||s?{left:n,right:s}:void 0}function W2(t,e){return!e||!t.hands?t:{...t,hands:{...t.hands,left:e.left??t.hands.left,right:e.right??t.hands.right}}}function xa(t){const e=t.style??{},n=e.height??300,s=n*.8,i={...Rt(t.pose??{}),walk:0,walking:0,gait:"walk",facing:(e.facing??1)<0?-1:1,talk:0,rubber:e.rubber??0,beat:0,dancing:0},o={};if(e.hands)for(const r of["left","right"]){const a=e.hands[r]??Pt;for(const l of Object.keys(Pt))o[Ws(r,l)]=a[l]??Pt[l]}return{type:"custom",x:t.x-s/2,y:t.y-n,width:s,height:n,props:{...i,...o},about:D2(Object.keys(o),t.cast),figureStyle:e,figureDance:t.dance,figureGaits:t.cast?.gaits,draw(r,a,l){const c=a.props,h=Sa(c,l,t.dance,t.cast?.gaits);r.translate(s/2,n),Ku(r,h.pose,W2({...e,rubber:c.rubber,facing:Xu(c,e)},h.hands),l)}}}function D2(t,e){const n={...ou,...ru};for(const s of t){const[,i,...o]=s.split("."),r=au[o.join(".")];r&&(n[s]={...r,description:`${i==="left"?"Left":"Right"} hand: ${r.description.toLowerCase()}`})}return{kind:"stick figure",summary:"A poseable stick figure: pose it with joint tracks, or give it beats (`scriptTracks`) that compile into acted tracks.",props:n,get actions(){return Bw(e)}}}function Ta(t,e,n){const s=t.figureStyle;if(!s)throw new Error("stickFigureAt: the target was not made by stickFigureTarget");const i={...t.props};let o=0,r=0;for(const[c,h]of e.state?.values.get(n)??[])c==="gait"&&typeof h=="string"&&(i.gait=h),typeof h=="number"&&(c==="x"||c==="motionPathX"?o=h:c==="y"||c==="motionPathY"?r=h:c in i&&(i[c]=h));const a=ju(i,e.time,t.figureDance,t.figureGaits),l=le(a,{...s,rubber:i.rubber,facing:Xu(i,s)});return{pose:a,joints:Yu(l,t.x+o+t.width/2,t.y+r+t.height)}}function to(t){const e=[];return t.forEach((n,s)=>{const i=s===0?ht:e[s-1],o=typeof n.pose=="string"?Jt[n.pose]:{...i,...n.pose};e.push(n.expression?Fe(o,n.expression):o)}),e}function B2(t,e){const n=to(e);return ku.filter(s=>n.some(i=>i[s]!==ht[s])).map(s=>({id:`${t}-${s}`,target:t,property:s,keyframes:e.map((i,o)=>({time:i.time,value:n[o][s],...i.easing?{easing:i.easing}:{}}))}))}const Ea=.5,eo={pataka:Ht({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:0,turn:2}),tripataka:Ht({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":1,"pinky.curl":0,spread:0,turn:2}),alapadma:Ht({"thumb.curl":.1,"thumb.across":0,"index.curl":.05,"middle.curl":.15,"ring.curl":.25,"pinky.curl":.35,spread:1,turn:2}),mushti:Ct.fist,shikhara:Ct.thumbsUp,hamsasya:Ht({"thumb.curl":.15,"thumb.across":.6,"index.curl":.6,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:.7,turn:2}),katakamukha:Ht({"thumb.curl":.2,"thumb.across":.6,"index.curl":.65,"middle.curl":.7,"ring.curl":0,"pinky.curl":0,spread:.4,turn:2})};function no(t){return typeof t!="string"?t:t in eo?eo[t]:Ct[t]}function Gu(t,e,n){const s=[];for(const i of t.keys){const o=s[s.length-1],r=!o||i.reset?{pose:e,...n}:o;s.push({beat:i.beat,pose:{...r.pose,...i.pose},left:i.hands?.left?no(i.hands.left):r.left,right:i.hands?.right?no(i.hands.right):r.right,easing:i.easing??t.easing})}return s}const Aa=(t,e)=>(t%e+e)%e;function z2(t,e,n,s){const i=Gu(t,n,s);if(i.length===0)return{pose:n,hands:s};const o=Aa(e,t.beats);let r=i.length-1;for(let f=0;f<i.length;f++)i[f].beat<=o&&(r=f);const a=i[r],l=i[(r+1)%i.length],c=a.beat<=o?a.beat:a.beat-t.beats,h=l.beat>c?l.beat:l.beat+t.beats,u=h>c?(o-c)/(h-c):0,d=Lt(l.easing??"ease-in-out")(Math.min(1,Math.max(0,u)));return{pose:Wn(a.pose,l.pose,d),hands:{left:Fn(a.left,l.left,d),right:Fn(a.right,l.right,d)}}}const q2=[["leftShoulder","rightShoulder"],["leftElbow","rightElbow"],["leftWrist","rightWrist"],["leftHip","rightHip"],["leftKnee","rightKnee"],["leftAnkle","rightAnkle"],["leftFootOut","rightFootOut"],["leftEye","rightEye"],["leftBrow","rightBrow"]],Y2=["lean","headTilt","lookX","spin"],K2=new Set(["leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee"]);function Uu(t){const e={...t},n=(t.turn??0)>=.5;for(const[s,i]of q2){const o=n&&K2.has(s)?-1:1;e[s]=o*t[i],e[i]=o*t[s]}if(!n)for(const s of Y2)e[s]=-t[s];return e}const j2=t=>Math.min(1,Math.max(-1,(.5-t)*4));function Vu(t,e,n){const s=Aa(n,1),i=(1+Math.cos(2*Math.PI*s))/2,o=e.bounce*(e.accent==="up"?1-i:i),r=Math.min(1,Math.max(0,t.turn??0)),a=j2(r);return{...t,leftHip:t.leftHip+a*o/2,rightHip:t.rightHip+o/2,leftKnee:t.leftKnee+a*o,rightKnee:t.rightKnee+o,lean:t.lean+(e.sway??0)*(1-r)*Math.sin(Math.PI*n)}}function so(t){const e={...ht,...t.stance};return t.expression?Fe(e,t.expression):e}function Ju(t){return{left:t.hands?.left?no(t.hands.left):Pt,right:t.hands?.right?no(t.hands.right):Pt}}function Pa(t,e,n){const s=t.moves[e.move];if(!s)throw new Error(`dance: "${t.label}" has no move "${e.move}"`);const i=z2(s,n,so(t),Ju(t));return e.mirror?{pose:Uu(i.pose),hands:{left:i.hands?.right,right:i.hands?.left}}:i}function io(t,e,n={}){const s=typeof t=="string"?We[t]:t;let i;if(n.move)i=Pa(s,{move:n.move,mirror:n.mirror},e);else{const o=s.routine,r=o.reduce((u,d)=>u+d.beats,0),a=Aa(e,r);let l=0,c=0;for(;c<o.length-1&&a>=l+o[c].beats;)l+=o[c++].beats;const h=a-l;if(i=Pa(s,o[c],h),h<Ea&&o.length>1&&e>=Ea){const u=o[(c-1+o.length)%o.length],d=Pa(s,u,u.beats+h),f=Lt("ease-in-out")(h/Ea);i={pose:Wn(d.pose,i.pose,f),hands:{left:Fn(d.hands.left,i.hands.left,f),right:Fn(d.hands.right,i.hands.right,f)}}}}return{...i,pose:Vu(i.pose,s.groove,e)}}function X2(t,e,n={}){return io(t,e,n).pose}function oo(t){return(typeof t=="string"?We[t]:t).routine.reduce((n,s)=>n+s.beats,0)}const G2={leftToe:"rightToe",rightToe:"leftToe",leftHeel:"rightHeel",rightHeel:"leftHeel"};function Zu(t,e,n,s,i,o,r){for(let a=0;a*t.beats<n;a++)for(const l of t.keys){const c=a*t.beats+l.beat,h=e+c;if(!(c>=n||h<o||h>=r))for(const u of l.taps??[])i.push({beat:h,tap:s?G2[u]:u})}}function U2(t,e,n,s={}){const i=typeof t=="string"?We[t]:t,o=[];if(n<=e)return o;if(s.move){const r=i.moves[s.move],a=Math.floor(e/r.beats)*r.beats;Zu(r,a,Math.ceil((n-a)/r.beats)*r.beats,s.mirror,o,e,n)}else{const r=oo(i);for(let a=Math.floor(e/r)*r;a<n;a+=r){let l=a;for(const c of i.routine)Zu(i.moves[c.move],l,c.beats,c.mirror,o,e,n),l+=c.beats}}return o.sort((r,a)=>r.beat-a.beat)}function Qu(t,e){const n=t.moves[e.move];if(!n?.travel)return 0;const s=n.travel/n.beats;return e.mirror?(Gu(n,so(t),Ju(t))[0]?.pose.turn??so(t).turn??0)>=.5?s:-s:s}function td(t,e){return e.move?[{move:e.move,beats:t.moves[e.move].beats,mirror:e.mirror}]:t.routine}function ro(t,e,n={}){const s=typeof t=="string"?We[t]:t,i=td(s,n),o=i.reduce((h,u)=>h+u.beats,0),r=i.reduce((h,u)=>h+Qu(s,u)*u.beats,0),a=Math.floor(e/o);let l=a*r,c=e-a*o;for(const h of i){const u=Math.min(h.beats,c);if(l+=Qu(s,h)*u,c-=u,c<=0)break}return l}function V2(t,e,n){const s=td(t,n),i=[0];let o=0;for(let r=0;o<e;r=(r+1)%s.length)o+=s[r].beats,i.push(Math.min(o,e));return i}const J2=8;function ed(t,e,n){const s=typeof e=="string"?We[e]:e,i=n.bpm??s.bpm,o=n.beats??(n.move?s.moves[n.move].beats:oo(s)),r=V2(s,o,n);if(r.every(w=>ro(s,w,n)===0))return;const a=Math.min(n.fade??1,o/2),l=Lt("ease-in-out"),c=w=>a<=0?1:Math.min(l(Math.min(1,w/a)),l(Math.min(1,(o-w)/a))),h=Math.ceil(a*J2),u=a<=0?[]:Array.from({length:h+1},(w,v)=>[v/h*a,o-v/h*a]).flat(),d=[...new Set([...r,...u])].sort((w,v)=>w-v);let f=0;const p=d.map((w,v)=>{if(v>0){const k=d[v-1],y=Math.max(1,Math.ceil((w-k)*16));for(let T=0;T<y;T++){const $=k+(w-k)*T/y,M=k+(w-k)*(T+1)/y;f+=(ro(s,M,n)-ro(s,$,n))*c(($+M)/2)}}return{beat:w,travel:f}}),g=n.start??0,m=n.x??0;return{id:`${t}-x`,target:t,property:"x",keyframes:p.map(w=>({time:g+w.beat*6e4/i,value:m+n.height*w.travel,easing:"linear"}))}}function Z2(t,e,n=0){return(t-n)*e/6e4}function Q2(t,e={}){return n=>io(t,n,e)}function tk(t,e){const n=e.start??0,s=6e4/e.bpm,i=n+e.beats*s,o=Math.min((e.fade??1)*s,(i-n)/2);return[{id:`${t}-beat`,target:t,property:"beat",keyframes:[{time:n,value:0},{time:i,value:e.beats,easing:"linear"}]},{id:`${t}-dancing`,target:t,property:"dancing",keyframes:[{time:n,value:0},{time:n+o,value:1,easing:"ease-in-out"},{time:i-o,value:1},{time:i,value:0,easing:"ease-in-out"}]}]}function ek(t,e,n={}){const s=typeof e=="string"?We[e]:e,i=n.bpm??s.bpm,o=n.beats??(n.move?s.moves[n.move].beats:oo(s)),r=n.samplesPerBeat??4,a=n.start??0,l=Math.round(o*r),c=Array.from({length:l+1},(g,m)=>{const w=m/r;return{time:a+w*6e4/i,frame:io(s,w,n)}}),h=(g,m)=>({id:`${t}-${g}`,target:t,property:g,keyframes:c.map(w=>({time:w.time,value:m(w.frame)}))}),d=Object.keys(ht).filter(g=>c.some(m=>m.frame.pose[g]!==c[0].frame.pose[g])||c[0].frame.pose[g]!==ht[g]).map(g=>h(g,m=>m.pose[g])),f=n.height===void 0?void 0:ed(t,s,{...n,bpm:i,beats:o,start:a,height:n.height,fade:0});if(f&&d.push(f),n.hands===!1)return d;const p=[];for(const g of["left","right"])for(const m of Object.keys(Pt)){const w=v=>v.hands?.[g]?.[m]??Pt[m];c.some(v=>w(v.frame)!==Pt[m])&&p.push(h(Ws(g,m),w))}return[...d,...p]}const Ds={type:"back",mode:"out",overshoot:1.1},Yt="ease-out-cubic",nk={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:Yt,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:Yt},{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:Yt},{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}]},sk={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}]},ik={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:Yt},{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:Yt},{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:Yt},{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:Ds},{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}]},ok={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:{...Ct.spread,turn:2},right:{...Ct.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:Yt},{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}]},rk={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:Ds,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:Ds},{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:Ds},{beat:3,pose:{headTilt:4}}]},isolations:{label:"Isolations",beats:2,easing:Yt,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}]},ak={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:{...Ct.cupped,roll:-30},left:{...Ct.flat,turn:0}}},{beat:.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{...Ct.cupped,roll:30}}},{beat:1,pose:{rightWrist:-15,rightElbow:12,leftWrist:-45,lean:-4,rightHip:16,leftHip:6},hands:{right:{...Ct.cupped,roll:-30}}},{beat:1.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{...Ct.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:{...Ct.open,turn:2}},easing:Yt},{beat:.5,pose:{lean:-4,rightHip:12,headTilt:6}},{beat:1,pose:{lean:-11,rightHip:22,headTilt:10},easing:Yt},{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:Yt},{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:Yt}]}},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}]},lk={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}]},ck={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}]},hk={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:{...Ct.spread,turn:2},right:{...Ct.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:Yt},{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:Yt},{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}]},uk={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:{...Ct.spread,turn:2},right:{...Ct.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}]},We={disco:nk,hipHop:sk,breaking:ik,jazz:ok,kpop:rk,bollywood:ak,bhangra:lk,bharatanatyam:ck,charleston:hk,tap:uk,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:Ds},{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}]}},ao={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}},$a=.215,Ia=.205,dk=.065,nd=.035,fk=.165,gk=.155,pk=12,mk=.3,yk=.7,bk=.35,wk=t=>t*Math.PI/180,ut={turn:0,lean:0,bend:0,side:0,"head.turn":0,"head.nod":0,"head.tilt":0,"arm.left.swing":0,"arm.left.spread":12,"arm.left.elbow":8,"arm.left.bend":0,"arm.right.swing":0,"arm.right.spread":12,"arm.right.elbow":8,"arm.right.bend":0,"leg.left.swing":0,"leg.left.spread":3,"leg.left.knee":0,"leg.left.ankle":0,"leg.left.toeOut":0,"leg.left.rotate":0,"leg.right.swing":0,"leg.right.spread":3,"leg.right.knee":0,"leg.right.ankle":0,"leg.right.toeOut":0,"leg.right.rotate":0,stretch:1,lift:0,roll:0,mouth:0,smile:.5,mouthWidth:1,blink:0,"eye.left":1,"eye.right":1,pupil:1,lid:0,bulge:0,"brow.left":0,"brow.right":0,browTilt:0,lookX:0,lookY:0,blush:0,tears:0,sweat:0,"hair.swing":0,"hair.trail":0,"hair.lift":0,"held.left":1,"held.right":1,"held.both":1};function kt(t={}){return{...ut,...t}}const kk=new Set(["turn","side","head.turn","head.tilt","roll","lookX","hair.swing"]);function sd(t){const e={};for(const[n,s]of Object.entries(t)){const i=n.replace(/(^|\.)(left|right)(\.|$)/,(o,r,a,l)=>`${r}${a==="left"?"right":"left"}${l}`);e[i]=kk.has(n)?-s:s}return e}function Tt(t,e){const n={};for(const s of["left","right"])for(const[i,o]of Object.entries(e))n[`${t}.${s}.${i}`]=o;return n}const ce={rest:ut,wave:kt({"arm.right.spread":115,"arm.right.bend":55,"arm.right.elbow":0,"head.tilt":-6,smile:.9}),cheer:kt({...Tt("arm",{spread:140,bend:20,elbow:0}),mouth:.6,smile:1,"eye.left":0,"eye.right":0}),point:kt({"arm.right.spread":88,"arm.right.elbow":0,"arm.right.bend":0,"head.turn":-20,smile:.4}),handsOnHips:kt({...Tt("arm",{spread:50,bend:-105,elbow:0}),...Tt("leg",{spread:9}),smile:.8}),think:kt({"arm.right.spread":22,"arm.right.bend":-150,"arm.right.elbow":0,"head.tilt":10,lookX:-.5,lookY:-.8,smile:0}),shrug:kt({...Tt("arm",{spread:35,bend:75,elbow:0}),"head.tilt":-10,smile:-.2}),sit:kt({...Tt("leg",{swing:90,knee:90,spread:4}),...Tt("arm",{swing:25,elbow:45,spread:8})}),kneel:kt({"leg.left.swing":90,"leg.left.knee":90,"leg.right.swing":-18,"leg.right.knee":108,"leg.right.ankle":16,...Tt("arm",{swing:20,elbow:30})}),crouch:kt({...Tt("leg",{swing:75,knee:140,spread:6}),lean:25,...Tt("arm",{swing:50,elbow:40}),"head.nod":-15}),crawl:kt({lean:82,"head.nod":-35,...Tt("arm",{swing:80,elbow:0,spread:4}),...Tt("leg",{knee:92,ankle:-88})}),lieDown:kt({roll:90,...Tt("arm",{spread:8}),"head.nod":0}),sleep:kt({roll:90,...Tt("arm",{spread:8,swing:20,elbow:40}),"leg.left.knee":20,"leg.left.swing":15,blink:1,smile:.2}),stretch:kt({side:-16,"arm.left.spread":165,"arm.left.bend":35,"arm.left.elbow":0,"arm.right.spread":40,"arm.right.bend":-110,"arm.right.elbow":0,"head.tilt":-10,"eye.left":0,"eye.right":0,smile:.4}),sitFloor:kt({...Tt("leg",{swing:80,spread:22,rotate:75,knee:145}),...Tt("arm",{swing:25,spread:18,elbow:30}),lean:5,smile:.5}),carry:kt({...Tt("arm",{spread:16,elbow:4}),lean:-3,smile:.4}),cane:kt({"arm.right.swing":16,"arm.right.spread":10,"arm.right.elbow":0,"arm.right.bend":0,"arm.left.swing":2,side:-3,lean:4,"leg.right.swing":4,smile:.3}),lift:kt({...Tt("arm",{swing:28,spread:24,elbow:85,bend:-45}),...Tt("leg",{swing:12,knee:22,spread:6}),lean:-4,smile:.2}),push:kt({lean:28,...Tt("arm",{swing:82,spread:12,elbow:18}),"leg.left.swing":28,"leg.left.knee":30,"leg.right.swing":-28,"leg.right.knee":6,"head.nod":-20,browTilt:-.6,smile:-.2}),pull:kt({lean:-22,...Tt("arm",{swing:70,spread:6,elbow:0}),"leg.left.swing":32,"leg.left.knee":8,"leg.right.swing":-8,"leg.right.knee":34,"head.nod":12,browTilt:-.6,smile:-.2}),drink:kt({"arm.right.swing":85,"arm.right.spread":8,"arm.right.elbow":120,"arm.right.bend":0,"head.nod":-14,"eye.left":.5,"eye.right":.5,smile:0}),phone:kt({"arm.right.swing":80,"arm.right.spread":8,"arm.right.elbow":80,"arm.right.bend":-10,"head.nod":18,lookY:.7,lookX:-.3,smile:.4}),read:kt({...Tt("arm",{swing:32,spread:10,elbow:82,bend:-28}),"head.nod":22,lookY:.8,smile:.2}),type:kt({...Tt("leg",{swing:90,knee:90,spread:4}),...Tt("arm",{swing:40,spread:10,elbow:55,bend:-20}),lean:8,"head.nod":10,lookY:.5,smile:0})},id=["round","flat","pointed","big"],vk={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 Oa(t={}){const e=t.headSize??.3,n=t.shoulderWidth??.06,s=t.hipWidth??.022,i=t.legLength??1,o=t.armLength??1,r=vk[t.feet??"round"],a=Math.max(.12,1-e-nd-($a+Ia)*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:fk*o,width:[1.25,.9]},{length:gk*o,width:[.9,.75]}]}),c=u=>({id:`leg.${u}`,parent:null,offset:[(u==="left"?1:-1)*s,0,0],rest:[0,-1,0],side:u==="left"?1:-1,bones:[{length:$a*i,width:[1.45,1.05]},{length:Ia*i,width:[1.05,.85]},{length:dk*Math.sqrt(i)*r.length,width:r.width}]}),h=(u,d)=>u[d]??ut[d]??0;return{id:"human",hipHeight:($a+Ia)*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:nd,width:[1,.9]}]},l("left"),l("right")],head:{on:"neck",size:e},contacts:[...["left","right"].flatMap(u=>[{chain:`leg.${u}`,joint:1},{chain:`leg.${u}`,joint:2},{chain:`leg.${u}`,joint:3},{chain:`arm.${u}`,joint:1},{chain:`arm.${u}`,joint:2}]),{chain:"spine",joint:0},{chain:"spine",joint:1},{chain:"spine",joint:2},{head:"top"}],angles(u,d){if(d.id==="spine"){const v=-h(u,"lean")/2,k=h(u,"side")/2,y=-h(u,"bend");return[{swing:v+y*mk,spread:k},{swing:v+y*yk,spread:k}]}if(d.id==="neck")return[{swing:-h(u,"bend")*bk,spread:0}];const[f,p]=d.id.split("."),g=v=>h(u,`${f}.${p}.${v}`);if(f==="arm")return[{swing:g("swing"),spread:g("spread")},{swing:g("elbow"),spread:g("bend")}];const m=(d.side??1)*g("rotate"),w=1-Math.cos(wk(g("rotate")));return[{swing:g("swing"),spread:g("spread"),yaw:m},{swing:-g("knee"),spread:0,yaw:m},{swing:90+g("ankle")-w*(g("swing")-g("knee")),spread:0,yaw:(pk+g("toeOut"))*(d.side??1)}]},withAngles(u,d,f){const[p,g]=d.id.split("."),m=w=>`${p}.${g}.${w}`;return p==="arm"?{...u,[m("swing")]:f[0].swing,[m("spread")]:f[0].spread,[m("elbow")]:f[1].swing,[m("bend")]:f[1].spread}:p==="leg"?{...u,[m("swing")]:f[0].swing,[m("spread")]:f[0].spread,[m("knee")]:-f[1].swing}:u},boneScale(u,d){const f=Math.min(3,Math.max(.3,h(u,"stretch")));return d?.id.startsWith("arm.")?Math.sqrt(f):f},headPose(u){const d=Math.min(3,Math.max(.3,h(u,"stretch")));return{yaw:h(u,"head.turn"),nod:h(u,"head.nod"),tilt:h(u,"head.tilt"),sx:1/Math.sqrt(d),sy:Math.sqrt(d)}},landmarks:{neck:["neck",0],"shoulder.left":["arm.left",0],"elbow.left":["arm.left",1],"hand.left":["arm.left",2],"shoulder.right":["arm.right",0],"elbow.right":["arm.right",1],"hand.right":["arm.right",2],"hip.left":["leg.left",0],"knee.left":["leg.left",1],"ankle.left":["leg.left",2],"toe.left":["leg.left",3],"hip.right":["leg.right",0],"knee.right":["leg.right",1],"ankle.right":["leg.right",2],"toe.right":["leg.right",3]}}}function Mk(t){const e=t.split(".");if(e[0]==="hand"&&e.length>=3){const s=`${e[1]==="left"?"Left":"Right"} hand`,i={spread:"finger spread",turn:"wrist turn",bend:"wrist bend",tilt:"wrist tilt",roll:"roll"},o=e.slice(2).join(".");return`${s} · ${i[o]??o.replace(".curl"," curl").replace(".across"," across")}`}if(e.length===3){const[s,i,o]=e;return`${`${i==="left"?"Left":"Right"} ${s}`} · ${{swing:"forward / back",spread:"out / in",elbow:"elbow bend",bend:"forearm out / in",knee:"knee bend",ankle:"foot tilt",toeOut:"toes out / in",rotate:"turn out at the hip"}[o]??o}`}return{turn:"View (front → side → back)",lean:"Lean forward / back",bend:"Back curve (line of action)",side:"Lean sideways","head.turn":"Head · turn","head.nod":"Head · nod","head.tilt":"Head · tilt",stretch:"Squash / stretch",lift:"Lift off the ground",roll:"Roll (whole figure)",mouth:"Mouth open",smile:"Smile",mouthWidth:"Mouth width",blink:"Blink","eye.left":"Left eye open","eye.right":"Right eye open",pupil:"Pupil size",lid:"Eyelids lowered",bulge:"Eyes bulging","brow.left":"Left brow","brow.right":"Right brow",browTilt:"Brow slant",lookX:"Look left / right",lookY:"Look up / down",blush:"Blush",tears:"Tears",sweat:"Sweat","hair.swing":"Hair · swing","hair.trail":"Hair · trail","hair.lift":"Hair · lift","held.left":"Left hand · holding","held.right":"Right hand · holding","held.both":"Both hands · holding"}[t]??t}const Sk={leftEye:"eye.left",rightEye:"eye.right",leftBrow:"brow.left",rightBrow:"brow.right"},xk={blush:0,tears:0,sweat:0,pupil:1,lid:0,bulge:0},an=Object.fromEntries(Object.entries(vt).map(([t,e])=>[t,{...Object.fromEntries(Object.entries(e).map(([n,s])=>[Sk[n]??n,s])),...xk}]));an.crying.tears=1,an.scared.sweat=.8,an.scared.bulge=.4,an.sleepy.lid=.5,an.worried.sweat=.6;const se=t=>({...an.neutral,...t}),_a={...an,laughing:se({mouth:.75,smile:1,mouthWidth:1.25,"eye.left":0,"eye.right":0,"brow.left":.5,"brow.right":.5}),afraid:se({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:se({smile:-.05,mouthWidth:.6,"eye.left":.45,"eye.right":.45,"brow.left":-.4,"brow.right":-.4,lookX:.5}),tired:se({mouth:.2,smile:-.3,mouthWidth:.7,"eye.left":.3,"eye.right":.3,"brow.left":-.1,"brow.right":-.1,browTilt:.6,lookY:.6}),embarrassed:se({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:se({smile:.75,mouthWidth:1,"eye.left":.75,"eye.right":.75,"brow.left":.5,"brow.right":.5,lookY:-.2}),determined:se({smile:.35,mouthWidth:.8,"eye.left":.85,"eye.right":.85,"brow.left":-.5,"brow.right":-.5,browTilt:-.9}),affectionate:se({smile:.85,"eye.left":0,"eye.right":0,"brow.left":.3,"brow.right":.3,blush:.8}),hurt:se({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:se({smile:-.25,mouthWidth:.7,"eye.left":.5,"eye.right":.85,"brow.left":-.6,"brow.right":.4,browTilt:-.3,lookX:.8,lid:.3}),relieved:se({smile:.7,"eye.left":0,"eye.right":0,"brow.left":.4,"brow.right":.4,browTilt:.4}),excited:se({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})},ie=t=>t*Math.PI/180;function Ca([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t,e*i+n*o,-e*o+n*i]}function Bs([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i-e*o,t*o+e*i,n]}function Zt([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i+n*o,e,-t*o+n*i]}const ke=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],lo=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],co=(t,e)=>Bs(Ca(t,e.swing),e.spread);function ho(t,e){const n=Zt(t,e);return{point:{x:n[0],y:-n[1]},depth:n[2]}}function zs(t,e,n){const s=n,o=[0,t.hipHeight*s*(t.boneScale?.(e,null)??1),0],r={};for(const g of t.chains){const m=g.parent?r[g.parent]:void 0;if(g.parent&&!m)throw new Error(`body plan ${t.id}: chain ${g.id} comes before its parent ${g.parent}`);const w=g.at??(m?m.joints3.length-1:0),v=m?m.joints3[w]:o,k=m?m.frames[Math.max(0,w-1)]:{swing:0,spread:0},y=g.offset?ke(v,co(lo(g.offset,s),k)):v,T=g.side??1,$=t.boneScale?.(e,g)??1,M=t.angles(e,g),x=[y],S=[];let E=k.swing,P=k.spread;g.bones.forEach((A,I)=>{const _=M[I]??{swing:0,spread:0};E+=ie(_.swing),P+=ie(_.spread)*T,S.push({swing:E,spread:P});const N=Zt(co(g.rest,{swing:E,spread:P}),ie(_.yaw??0));x.push(ke(x[I],lo(N,A.length*s*$)))}),r[g.id]={joints3:x,frames:S}}const a=r[t.head.on],l=t.headPose?.(e)??{yaw:0,nod:0,tilt:0,sx:1,sy:1},c=a.frames[a.frames.length-1],h=t.head.size/2*s,u=h*l.sx,d=h*l.sy,f=g=>co(Zt(Ca(Bs(g,-ie(l.tilt)),-ie(l.nod)),ie(l.yaw)),c),p=ke(a.joints3[a.joints3.length-1],f([0,d,0]));return{height:s,root:o,chains:r,head:{center:p,rx:u,ry:d,toBody:f}}}function Ha(t,e,n){const s=n.height,i=ie(90*(e.turn??0)),o=zs(t,e,s),{root:r}=o,a=o.chains,{rx:l,ry:c}=o.head,h=o.head.toBody,u=o.head.center,d={};for(const S of t.chains){const{joints3:E,frames:P}=a[S.id],A=E.map(I=>ho(I,i));d[S.id]={id:S.id,joints3:E,frames:P,points:A.map(I=>I.point),depths:A.map(I=>I.depth)}}const f=ho(u,i),p=[[1,0,0],[0,1,0],[0,0,1]].map(S=>Zt(h(S),i)),g=ho(r,i).point,m=ie(e.roll??0),w=S=>{const E=S.x-g.x,P=S.y-g.y;return{x:g.x+E*Math.cos(m)-P*Math.sin(m),y:g.y+E*Math.sin(m)+P*Math.cos(m)}},v=([S,E,P])=>[S*Math.cos(m)+E*Math.sin(m),-S*Math.sin(m)+E*Math.cos(m),P];for(const S of Object.values(d))S.points=S.points.map(w);const k={center:w(f.point),depth:f.depth,rx:l,ry:c,angle:0,axes:p.map(v)},y=k.axes[1];k.angle=Math.atan2(y[0],y[1]);const T=S=>{if("head"in S)return{x:k.center.x+y[0]*c,y:k.center.y-y[1]*c};const E=d[S.chain];return E.points[Math.min(S.joint,E.points.length-1)]};let $=0;(n.contact??"ground")==="ground"&&($=-Math.max(...t.contacts.map(S=>T(S).y))),$-=(e.lift??0)*s;const M=S=>({x:S.x,y:S.y+$});for(const S of Object.values(d))S.points=S.points.map(M);k.center=M(k.center);const x=t.contacts.map(S=>({spec:S,point:T(S)}));return{height:s,view:i,chains:d,head:k,hip:M(w(g)),hipDepth:ho(r,i).depth,contacts:x,groundY:Math.max(...x.map(S=>S.point.y))}}const uo=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Ra=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function qs(t,e,n){const s=n.height,i=ie(90*(e.turn??0)),o=ie(e.roll??0),r=zs(t,e,s),a=Zt(r.root,i),l=m=>ke(Bs(uo(Zt(m,i),a),-o),a),c={};for(const m of t.chains)c[m.id]=r.chains[m.id].joints3.map(l);const h=l(r.head.center),u=m=>Ra(uo(l(ke(r.head.center,r.head.toBody(m))),h)),d=[u([1,0,0]),u([0,1,0]),u([0,0,1])],f=m=>{if("head"in m)return ke(h,lo(d[1],r.head.ry));const w=c[m.chain];return w[Math.min(m.joint,w.length-1)]};let p=0;(n.contact??"ground")==="ground"&&(p=-Math.min(...t.contacts.map(m=>f(m)[1]))),p+=(e.lift??0)*s;const g=m=>[m[0],m[1]+p,m[2]];return{height:s,hip:g(a),chains:Object.fromEntries(Object.entries(c).map(([m,w])=>[m,w.map(g)])),head:{center:g(h),rx:r.head.rx,ry:r.head.ry,axes:d}}}function fo(t,e,n,s){const i=n.height,o=ie(90*(e.turn??0)),r=zs(t,e,i),a=qs(t,e,n),l=a.hip,c=a.chains,h=a.head.center,u=P=>{if("head"in P)return ke(h,lo(a.head.axes[1],a.head.ry));const A=c[P.chain];return A[Math.min(P.joint,A.length-1)]},d=s.toView(l),f=Bs(Zt([0,0,1],o),-ie(e.roll??0)),p=Ra(uo(s.toView(ke(l,f)),d)),g=s.toScreen(d),m=s.toScreen([d[0]+1,d[1],d[2]]),w=Math.hypot(m.x-g.x,m.y-g.y),v=P=>{const A=s.toView(P);return{point:s.toScreen(A),depth:A[2]*w}},k={};for(const P of t.chains){const A=c[P.id].map(v);k[P.id]={id:P.id,joints3:r.chains[P.id].joints3,frames:r.chains[P.id].frames,points:A.map(I=>I.point),depths:A.map(I=>I.depth)}}const y=s.toView(h),T=s.toScreen(y),$=s.toScreen([y[0]+1,y[1],y[2]]),M=Math.hypot($.x-T.x,$.y-T.y),x=a.head.axes.map(P=>Ra(uo(s.toView(ke(h,P)),y))),S={center:T,depth:y[2]*w,rx:r.head.rx*M,ry:r.head.ry*M,angle:Math.atan2(x[1][0],x[1][1]),axes:x},E=t.contacts.map(P=>({spec:P,point:v(u(P)).point}));return{height:i*w,view:o,bodyForward:p,chains:k,head:S,hip:g,hipDepth:d[2]*w,contacts:E,groundY:Math.max(...E.map(P=>P.point.y))}}function Dn(t,[e,n,s]){const[i,o,r]=t.axes,a=[i[0]*e*t.rx+o[0]*n*t.ry+r[0]*s*t.rx,i[1]*e*t.rx+o[1]*n*t.ry+r[1]*s*t.rx,i[2]*e*t.rx+o[2]*n*t.ry+r[2]*s*t.rx],l=Math.hypot(e,n,s)||1,c=(i[2]*e+o[2]*n+r[2]*s)/l;return{point:{x:t.center.x+a[0],y:t.center.y-a[1]},depth:t.depth+a[2],facing:c}}const go=t=>t*180/Math.PI,ln=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],La=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Bn=t=>Math.hypot(t[0],t[1],t[2]),Na=t=>{const e=Bn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},po=t=>Math.atan2(Math.sin(t),Math.cos(t));function od(t){const[e,n,s]=Na(t);return{swing:Math.asin(Math.max(-1,Math.min(1,s))),spread:Math.atan2(e,-n)}}function mo(t,e,n,s,i){const o=t.chains.find(A=>A.id===n);if(!o)throw new Error(`reach: no chain ${n} in ${t.id}`);if(o.bones.length<2||o.rest[1]>-.99)throw new Error(`reach: ${n} is not a hanging limb of two bones or more`);if(!t.withAngles)throw new Error(`reach: the ${t.id} plan cannot set angles`);const r=Ha(t,{...e,turn:0,roll:0,lift:0},{height:i.height,contact:"none"}),a=r.chains[n];if(Bn(ln(s,a.joints3[2]))<i.height*1e-12)return e;const l=a.joints3[0],c=Bn(ln(a.joints3[1],a.joints3[0])),h=Bn(ln(a.joints3[2],a.joints3[1])),u=o.parent?r.chains[o.parent].frames[Math.max(0,(o.at??r.chains[o.parent].joints3.length-1)-1)]:{swing:0,spread:0},d=ln(s,l),f=t.angles(e,o),p=A=>(f[A]?.yaw??0)*Math.PI/180,g=Math.min(c+h-1e-6,Math.max(Math.abs(c-h)+1e-6,Bn(d))),m=Na(d),w=o.parent!==null,v=Zt(co(o.pole??(w?[0,-.35,-1]:[0,0,1]),u),p(0));let k=ln(v,[m[0]*La(v,m),m[1]*La(v,m),m[2]*La(v,m)]);Bn(k)<1e-6&&(k=Zt([1,0,0],p(0))),k=Na(k);const y=(c*c+g*g-h*h)/(2*c*g),T=Math.sqrt(Math.max(0,1-y*y)),$=[l[0]+c*(y*m[0]+T*k[0]),l[1]+c*(y*m[1]+T*k[1]),l[2]+c*(y*m[2]+T*k[2])],M=[l[0]+m[0]*g,l[1]+m[1]*g,l[2]+m[2]*g],x=o.side??1,S=od(Zt(ln($,l),-p(0))),E=od(Zt(ln(M,$),-p(1))),P=[{swing:go(po(S.swing-u.swing)),spread:go(po(S.spread-u.spread))*x},{swing:go(po(E.swing-S.swing)),spread:go(po(E.spread-S.spread))*x}];return t.withAngles(e,o,P)}const zn=(t,e)=>(t%e+e)%e,rd=t=>t*t*(3-2*t),Tk=t=>Object.fromEntries(["left","right"].flatMap(e=>Object.entries(Ct[t]).map(([n,s])=>[`hand.${e}.${n}`,s])));function Fa(t,e=!1){const n=Oa(),s=mo(n,ut,"arm.left",[.015,.68,.2],{height:1}),i=mo(n,s,"arm.right",[-.015,.68,.2],{height:1});return Array.from({length:32},(o,r)=>{const a=r/4,l=Math.floor(a),c=a-l,h=l%2===0,u=Math.sin(Math.PI*c),d=Math.max(0,...t.map(p=>1-Math.min(zn(a-p,8),zn(p-a,8))/.5)),f={side:(h?1:-1)*5*Math.sin(Math.PI*c),bend:2+3*u,"head.tilt":(h?-1:1)*3*u,"head.nod":-2*u,"leg.left.swing":h?-4*u:17*u,"leg.right.swing":h?17*u:-4*u,"leg.left.knee":h?5*u:36*u,"leg.right.knee":h?36*u:5*u,"leg.left.spread":4,"leg.right.spread":4,"arm.left.swing":22+d*(e?45:42),"arm.right.swing":22+d*(e?45:42),"arm.left.spread":28-22*d,"arm.right.spread":28-22*d,"arm.left.elbow":48+22*d,"arm.right.elbow":48+22*d,"arm.left.bend":-35*d,"arm.right.bend":-35*d,smile:.9,...Tk(e?"hold":"spread")};if(!e)for(const p of Object.keys(i))p.startsWith("arm.")&&(f[p]+=(i[p]-f[p])*d);return{beat:a,pose:f}})}const cn={garba:{label:"Garba · two clap",bpm:120,beats:8,strikes:[2,3,6,7],keys:Fa([2,3,6,7])},garbaThreeClap:{label:"Garba · three clap",bpm:120,beats:8,strikes:[1,2,3,5,6,7],keys:Fa([1,2,3,5,6,7])},dandiya:{label:"Dandiya · partner strikes",bpm:120,beats:8,strikes:[1,3,5,7],keys:Fa([1,3,5,7],!0)}};function ad(t){const e=typeof t=="string"&&Object.hasOwn(cn,t)?cn[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 Ys(t,e,n=ut){const s=ad(t);if(!Number.isFinite(e))throw new Error("humanDanceFrame: beat must be finite");const i=zn(e,s.beats);let o=s.keys.length-1;for(let m=0;m<s.keys.length;m++)s.keys[m].beat<=i&&(o=m);const r=s.keys[o],a=s.keys[(o+1)%s.keys.length],l=r.beat>i?r.beat-s.beats:r.beat,c=a.beat<=r.beat?a.beat+s.beats:a.beat,h=rd((i-l)/(c-r.beat)),u={...ut,...n};for(const m of new Set(s.keys.flatMap(w=>Object.keys(w.pose)))){if(m==="turn"||m==="roll")continue;const w=m.match(/^hand\.(?:left|right)\.(.+)$/)?.[1],v=n[m]??ut[m]??(w?Pt[w]:void 0)??0,k=r.pose[m]??v;u[m]=k+((a.pose[m]??v)-k)*h}const d=Math.floor(e),f=e-d,p=f<=.6?1:1-rd((f-.6)/.4),g=Math.max(0,...s.strikes.map(m=>1-Math.min(zn(i-m,s.beats),zn(m-i,s.beats))/.25));return{pose:u,contact:{side:zn(d,2)===0?"left":"right",start:d,weight:p},strike:g}}function Ek(t,e){const n=ad(e.style),s=e.bpm??n.bpm,i=e.beats??n.beats,o=e.samplesPerBeat??16;if(![s,i,o].every(l=>Number.isFinite(l)&&l>0))throw new Error("humanDanceTracks: bpm, beats and samplesPerBeat must be positive and finite");if(!Number.isFinite(e.start??0))throw new Error("humanDanceTracks: start must be finite");const r=Math.max(1,Math.ceil(i*o)),a=Array.from({length:r+1},(l,c)=>({time:(e.start??0)+i*c/r*6e4/s,pose:Ys(n,i*c/r,e.pose).pose}));return Object.keys(a[0].pose).filter(l=>l!=="turn"&&l!=="roll"&&a.some(c=>c.pose[l]!==(e.pose?.[l]??ut[l]))).map(l=>({id:`${t}-dance-${l}`,target:t,property:l,keyframes:a.map(c=>({time:c.time,value:c.pose[l],easing:"linear"}))}))}function qn(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 yo(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(qn(n.at,`${e}.at`,0,1),qn(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 ld(t,e){const n=Math.max(.095,e.shoulderWidth+.025),s=Math.max(.085,e.hipWidth+.032),i=t.shading??{},o=i.light??[-.8,-.6];if(o.length!==2||!o.every(Number.isFinite)||Math.hypot(...o)===0)throw new Error("organic body: light must be a finite nonzero 2D vector");if(i.mode!==void 0&&i.mode!=="none"&&i.mode!=="cel")throw new Error("organic body: unknown shading mode");return{torso:yo(t.torso??[{at:0,width:s},{at:.2,width:s},{at:.42,width:s*.72},{at:.68,width:n*.9},{at:.86,width:n},{at:1,width:.024}],"torso"),arm:yo(t.arm??[{at:0,width:.028},{at:.22,width:.027},{at:.5,width:.019},{at:.68,width:.023},{at:1,width:.012}],"arm"),leg:yo(t.leg??[{at:0,width:.04},{at:.24,width:.042},{at:.5,width:.027},{at:.68,width:.032},{at:1,width:.016}],"leg"),neck:yo(t.neck??[{at:0,width:.024},{at:1,width:.023}],"neck"),depth:qn(t.depth??.55,"depth",.2,1),fill:t.fill??e.skin,outline:{color:t.outline?.color??e.ink,width:qn(t.outline?.width??e.lineWidth,"outline.width",0,100)},shading:{mode:i.mode??"cel",light:[...o],shadow:i.shadow??"#633923",opacity:qn(i.opacity??.17,"shading.opacity",0,1),highlight:qn(i.highlight??.12,"shading.highlight",0,1)}}}function cd(t,e){const n=Math.min(1,Math.max(0,e)),s=t.findIndex(a=>a.at>=n);if(s<=0)return t[0].width;const i=t[s-1],o=t[s],r=(n-i.at)/(o.at-i.at);return i.width+(o.width-i.width)*r*r*(3-2*r)}const hd=8,Ak=(t,e,n)=>({x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n}),hn=(t,e)=>{const n=Math.hypot(e.x-t.x,e.y-t.y)||1;return{x:(e.x-t.x)/n,y:(e.y-t.y)/n}},bo=(t,e,n)=>({x:t.x+e.x*n,y:t.y+e.y*n});function Ks(t,e=12){if(!Number.isInteger(e)||e<1||e>128)throw new Error("organicCenterLine: steps must be an integer from 1 to 128");if(t.length<2)return t.map(i=>({...i}));const n=t.map((i,o)=>{const r=hn(t[Math.max(0,o-1)],i),a=hn(i,t[Math.min(t.length-1,o+1)]),l=Math.hypot(r.x+a.x,r.y+a.y);return l>1e-6?{x:(r.x+a.x)/l,y:(r.y+a.y)/l}:a}),s=[];for(let i=0;i<t.length-1;i++){const o=t[i],r=t[i+1],a=Math.hypot(r.x-o.x,r.y-o.y)*.28,l=bo(o,n[i],a),c=bo(r,n[i+1],-a);for(let h=i===0?0:1;h<=e;h++){const u=h/e,d=1-u;s.push({x:d**3*o.x+3*d*d*u*l.x+3*d*u*u*c.x+u**3*r.x,y:d**3*o.y+3*d*d*u*l.y+3*d*u*u*c.y+u**3*r.y})}}return s}function wo(t,e,n,s=1,i=1){const o=t.map((h,u)=>{const d=t[Math.max(0,u-1)],f=t[Math.min(t.length-1,u+1)];let p=hn(d,f);Math.hypot(p.x,p.y)<1e-6&&(p={x:0,y:1});const g={x:-p.y,y:p.x},m=u/Math.max(1,t.length-1),w=cd(e,m)*n*s,v=hn(d,h),k=hn(h,f),y=v.x*k.y-v.y*k.x,T=Math.acos(Math.min(1,Math.max(-1,v.x*k.x+v.y*k.y))),$=(Math.hypot(h.x-d.x,h.y-d.y)+Math.hypot(f.x-h.x,f.y-h.y))/(2*Math.max(1e-6,T)),M=Math.min(w,Math.max(w*.2,$*.8));return{center:h,width:w,at:m,left:bo(h,g,y>0?M:w),right:bo(h,g,y<0?-M:-w)}}),r=[],a=[],l=(h,u)=>{r.push(h),a.push(u)};for(const h of o)l(h.left,h.at);const c=(h,u,d)=>{const f={x:-u.y,y:u.x};for(let p=1;p<hd;p++){const g=p*Math.PI/hd,m=(d?1:-1)*Math.cos(g),w=(d?1:-i)*Math.sin(g);l({x:h.center.x+h.width*(f.x*m+u.x*w),y:h.center.y+h.width*(f.y*m+u.y*w)},h.at)}};c(o.at(-1),hn(t[Math.max(0,t.length-2)],t.at(-1)),!0);for(const h of[...o].reverse())l(h.right,h.at);return c(o[0],hn(t[0],t[Math.min(1,t.length-1)]),!1),{outline:r,samples:o,positions:a}}function ud(t,e,n){const s={},i=e.height,o=e.chains.spine;if(o?.length>=2){const r=e.points["shoulder.left"],a=e.points["shoulder.right"],l=n.chains.find(f=>f.id==="arm.left")?.offset?.[0]??.07,c=Math.max(1e-6,Math.abs(l)*i*2),h=r&&a?Math.min(1,Math.hypot(r.x-a.x,r.y-a.y)/c):Math.abs(Math.cos(e.turn*Math.PI/2)),u=Math.sqrt(h*h+t.depth*t.depth*(1-h*h)),d=[Ak(o[0],o[1],-.16),...o.slice(1)];s.spine=wo(Ks(d),t.torso,i,u,.25)}e.chains.neck?.length>=2&&(s.neck=wo(Ks(e.chains.neck),t.neck,i));for(const r of["left","right"])for(const a of["arm","leg"]){const l=e.chains[`${a}.${r}`];!l||l.length<3||(s[`${a}.${r}`]=wo(Ks(l.slice(0,3)),t[a],i),a==="leg"&&l.length>3&&(s[`foot.${r}`]=wo(Ks(l.slice(2)),[{at:0,width:.019},{at:1,width:.014}],i)))}return s}function dd(t,e){let n=!1;for(let s=0,i=e.length-1;s<e.length;i=s++){const o=e[s],r=e[i];o.y>t.y!=r.y>t.y&&t.x<(r.x-o.x)*(t.y-o.y)/(r.y-o.y)+o.x&&(n=!n)}return n}function Wa(t,e,n,s=0){const i=t.samples.filter(a=>a.at>=e&&a.at<=n),o=(a,l)=>{const c=a[l],h=a.center,u=Math.hypot(c.x-h.x,c.y-h.y)||1;return{x:c.x+(c.x-h.x)*s/u,y:c.y+(c.y-h.y)*s/u}},r=[...i.map(a=>o(a,"left")),...[...i].reverse().map(a=>o(a,"right"))];{const a=t.samples[0].center;for(const l of t.outline.slice(-7)){const c=Math.hypot(l.x-a.x,l.y-a.y)||1;r.push({x:l.x+(l.x-a.x)*s/c,y:l.y+(l.y-a.y)*s/c})}}return r}function fd(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 Pk(t,e,n){const s=n.shading;if(s.mode==="none"||n.fill==="none")return;const i=Math.hypot(...s.light),o={x:s.light[0]/i,y:s.light[1]/i},r=t.globalAlpha;t.save(),fd(t,e.outline),t.clip();for(const a of["left","right"]){const l=e.samples.map(h=>h[a]),c=e.samples.map(h=>{const u=h[a],d=h.center,f=u.x-d.x,p=u.y-d.y,g=(f*o.x+p*o.y)/(Math.hypot(f,p)||1),m=Math.max(0,-g)*.44;return{x:u.x+(d.x-u.x)*m,y:u.y+(d.y-u.y)*m}});if(fd(t,[...l,...c.reverse()]),t.fillStyle=s.shadow,t.globalAlpha=r*s.opacity,t.fill(),s.highlight>0){const h=e.samples.map(f=>{const p=f[a],g=f.center;return{x:p.x+(g.x-p.x)*.2,y:p.y+(g.y-p.y)*.2}}),u=e.samples[Math.floor(e.samples.length/2)][a],d=e.samples[Math.floor(e.samples.length/2)].center;if((u.x-d.x)*o.x+(u.y-d.y)*o.y>0){t.globalAlpha=r*s.highlight,t.strokeStyle="#ffffff",t.lineWidth=Math.max(1,e.samples[0].width*.16),t.beginPath(),t.moveTo(h[0].x,h[0].y);for(const f of h.slice(1))t.lineTo(f.x,f.y);t.stroke()}}}t.restore()}function $k(t,e,n,s){const i=s.bodyContours,o=r=>i[r]&&dd(t,i[r].outline);if(n.startsWith("arm."))return e<.2&&o("spine");if(n.startsWith("leg."))return e<.2&&o("spine")||e>.85&&o(n.replace("leg.","foot."));if(n.startsWith("foot."))return e<.25&&o(n.replace("foot.","leg."));if(n==="neck")return e<.6&&o("spine");if(n==="spine"){if(e>.85&&o("neck"))return!0;for(const r of["left","right"]){if(e>.6&&o(`arm.${r}`)){const a=s.chains[`arm.${r}`]?.[0];if(a&&Math.hypot(a.x-t.x,a.y-t.y)<s.height*.07)return!0}if(e<.25&&o(`leg.${r}`))return!0}}return!1}function gd(t,e,n,s,i){const o=s.bodyContours?.[i];if(!o)return!1;if(n.fill==="none"&&(e=Cs(t,e)),e.shape(o.outline,n.fill==="none"?null:n.fill,0),e.look==="clean"&&Pk(t,o,n),(e.look!=="silhouette"||n.fill==="none")&&s.lineWidth>0){let r=[];for(let a=0;a<=o.outline.length;a++){const l=a%o.outline.length,c=o.outline[l],h=o.outline[(l+1)%o.outline.length],u={x:(c.x+h.x)/2,y:(c.y+h.y)/2};i.startsWith("arm.")&&o.positions[l]===1||$k(u,o.positions[l],i,s)?(r.length>=2&&e.line(r,s.lineWidth),r=[]):(r.length===0&&r.push(c),r.push(h))}r.length>=2&&e.line(r,s.lineWidth)}return!0}function pd(t){return[[.01,-.12,.8],[0,-.25,.98],[-.04,-.31,.8]].map(e=>Dn(t,e).point)}function md(t,e){const n=e.shape==="angular"?Ik(t,e):e.projection==="volume"?Ok(t):ji(t.center.x,t.center.y,t.rx,t.ry,t.angle);if(e.projection!=="volume"||!e.nose)return n;const s=Math.cos(t.angle),i=Math.sin(t.angle),o=u=>({x:((u.x-t.center.x)*s+(u.y-t.center.y)*i)/t.rx,y:((u.x-t.center.x)*i-(u.y-t.center.y)*s)/t.ry}),r=o(pd(t)[1]),a=Math.sign(r.x),l=r.y,c=n.flatMap((u,d)=>{const f=o(u),p=o(n[(d+1)%n.length]);if(f.y>l==p.y>l)return[];const g=(l-f.y)/(p.y-f.y);return[(f.x+(p.x-f.x)*g)*a]}),h=Math.max(0,r.x*a-Math.max(...c));return!Number.isFinite(h)||h===0?n:n.flatMap((u,d)=>{const f=n[(d+1)%n.length],p=o(u),g=o(f),m=Math.max(1,Math.ceil(Math.hypot(g.x-p.x,g.y-p.y)/.025));return Array.from({length:m},(w,v)=>{const k=v/m,y={x:u.x+(f.x-u.x)*k,y:u.y+(f.y-u.y)*k},T=o(y),$=(T.y-l+.115)/.23;if(T.x*a<.5||$<=0||$>=1)return y;const M=Math.sin($*Math.PI)**2*h*t.rx*a;return{x:y.x+M*s,y:y.y+M*i}})})}function Ik(t,e){const n=Math.min(.95,Math.max(.55,e.jawWidth??.74)),s=Math.min(.35,Math.max(.03,e.chinWidth??.14)),i=[[-1,0],[-.92,s],[-.5,n],[-.12,Math.sqrt(1-.12**2)]];for(let o=0;o<=12;o++){const r=o*Math.PI/24;i.push([Math.sin(r),Math.cos(r)])}return yd(t,i,e.jawRoundness??0,e.projection==="volume")}function Ok(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 yd(t,e,0,!0)}function yd(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(Dn(t,[l*Math.cos(h),a,s?Math.min(u,.82):u]).point)}let o=Da(i);if(n=Math.min(1,Math.max(0,n)),n===0)return o;const r=n*.25;for(let a=0;a<3;a++)o=o.flatMap((l,c)=>{const h=o[(c+1)%o.length];return[{x:l.x+(h.x-l.x)*r,y:l.y+(h.y-l.y)*r},{x:h.x+(l.x-h.x)*r,y:h.y+(l.y-h.y)*r}]});return o}function Da(t){const e=t.sort((i,o)=>i.x-o.x||i.y-o.y),n=(i,o,r)=>(o.x-i.x)*(r.y-i.y)-(o.y-i.y)*(r.x-i.x),s=i=>{const o=[];for(const r of i){for(;o.length>=2&&n(o[o.length-2],o[o.length-1],r)<=0;)o.pop();o.push(r)}return o.slice(0,-1)};return[...s(e),...s([...e].reverse())]}const bd=.34,Bt=.12,zt=-.4,qt=(t,e,n)=>t[e]??n,_k=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),Ck=.45,Hk=.35,Rk=.7,wd=.78;function St(t,e,n,s="cartoon"){const i=f=>Math.sqrt(Math.max(0,1-f.x*f.x-f.y*f.y));let o=Dn(t,[n.x,n.y,i(n)]).facing;const r=t.axes[2];s==="volume"&&n.x*r[0]>0&&(o=Math.max(o,r[2]));const a=Math.atan2(r[0],r[2]),l=Math.cos(a),c=Math.max(Hk,l),h=Math.max(Rk,l),u=Math.cos(t.angle),d=Math.sin(t.angle);if(s==="volume"){const f=Dn(t,[n.x,n.y,i(n)*wd]).point,p=Math.abs(n.x)>.1?Math.min(1,Math.max(0,o)/.25):1,g=Math.max(n.x*r[0]>0?.2:.5,l);return{facing:o,points:e.map(m=>{const w=(m.x-n.x)*g*t.rx*p,v=(m.y-n.y+r[1]*(i(m)-i(n))*wd)*t.ry*p;return{x:f.x+w*u+v*d,y:f.y+w*d-v*u}})}}return{facing:o,points:e.map(f=>{const p=Ck*Math.sin(a)+n.x*c+(f.x-n.x)*h,g=f.y+r[1]*i(f),m=p*t.rx,w=g*t.ry;return{x:t.center.x+m*u+w*d,y:t.center.y+m*d-w*u}})}}const De=(t,e,n,s=12)=>Array.from({length:s+1},(i,o)=>{const r=o/s,a=1-r;return{x:a*a*t.x+2*a*r*e.x+r*r*n.x,y:a*a*t.y+2*a*r*e.y+r*r*n.y}}),js=(t,e,n,s)=>{const i=Math.min(1,Math.max(0,(s-t.x)/(n.x-t.x))),o=1-i;return o*o*t.y+2*o*i*e.y+i*i*n.y},ve=(t,e,n,s,i=16)=>Array.from({length:i},(o,r)=>{const a=Math.PI*2*r/i;return{x:t+Math.cos(a)*n,y:e+Math.sin(a)*s}}),un=.05,Lk=.3,Nk="#e06b7d";function Fk(t,e,n,s,i={},o){const r=Math.max(1,Math.min(s*.6,.14*e.rx)),a=(A,I)=>St(e,A,I,i.projection).points,l=(A,I)=>St(e,[],{x:A,y:I},i.projection).facing,c=qt(n,"smile",0),h=qt(n,"blink",0),u=qt(n,"lookX",0),d=qt(n,"lookY",0),f=qt(n,"browTilt",0),p=Math.max(.2,qt(n,"pupil",1)),g=Math.min(1,Math.max(0,qt(n,"lid",0))),m=Math.min(1,Math.max(0,qt(n,"bulge",0)));for(const A of[1,-1]){const I=A===1?"left":"right",_=bd*A;if(l(_,Bt)<un)continue;const N={x:_,y:Bt},Y=_k(qt(n,`eye.${I}`,1),h);if(Y<.2||i.style==="anime"&&g>=.98){const R=c>.5?.12:-.06;t.line(a(De({x:_-.12,y:Bt},{x:_,y:Bt+R},{x:_+.12,y:Bt}),N),r)}else if(i.style==="anime")Wk(t,e,N,A,Y,g,m,p,u,d,r,i,o);else{const R=Y>1.2||m>.02,z=.13*Math.max(Y,1)*(1+m*.7);R&&t.shape(a(ve(_,Bt,z*.85,z),N),"#ffffff",r);const K=(Y>1.2?.075:.1)*p*(1+m*.3),O=_+u*.08,D=Bt-d*.07,st=ve(O,D,K,K*1.1*Math.min(Y,1));if(t.shape(a(st,N),t.ink,0),i.inPupil&&o){const[H]=a([{x:O,y:D}],N),L=a(st,N),q=Math.min(...L.map(U=>Math.hypot(U.x-H.x,U.y-H.y)));q>.5&&(o.save(),o.beginPath(),o.arc(H.x,H.y,q,0,Math.PI*2),o.clip(),i.inPupil(o,{x:H.x,y:H.y,r:q,side:I}),o.restore())}if(g>.02){const H=R?z*1.15:K*1.4,L=Bt+H,q=L-H*2*g,U=H*1.1;t.shape(a([{x:_-U,y:L+.02},{x:_+U,y:L+.02},{x:_+U,y:q},{x:_-U,y:q}],N),i.skin??"#ffffff",0),t.line(a([{x:_-U,y:q},{x:_+U,y:q}],N),r)}}const V=Bt+(i.style==="anime"?.38:.3)+qt(n,`brow.${I}`,0)*.14+Math.max(0,Y-1)*.12,tt={x:_+A*.13,y:V},X={x:_-A*.13,y:V+f*.1};t.line(a([tt,{x:(tt.x+X.x)/2,y:(tt.y+X.y)/2},X],{x:_,y:V}),r)}Bk(t,e,n,r,i.projection),Dk(t,e,i.ageLines??0,r,i.projection);const w={x:0,y:zt};if(l(0,zt)<-un)return;i.nose&&l(0,Bt-.15)>=un&&(i.projection==="volume"?t.line(pd(e),r):t.line(a([{x:.01,y:Bt-.1},{x:.03,y:zt+.2},{x:-.05,y:zt+.17}],{x:0,y:zt+.22}),r));const v=.25*Math.max(.3,qt(n,"mouthWidth",1)),k=Math.min(1,Math.max(0,qt(n,"mouth",0)));if(k<=.05){t.line(a(De({x:-v,y:zt},{x:0,y:zt-c*.25},{x:v,y:zt}),w),r);return}const y=.3*k;let T,$,M,x;if(c>.3){const A=zt+.05,I={x:0,y:zt-y*2};T=[...De({x:v,y:A},I,{x:-v,y:A})],$=()=>A,M=_=>js({x:v,y:A},I,{x:-v,y:A},_),x=.85}else if(c<-.3){const A=zt-y*.6,I={x:0,y:zt+y*1.4};T=[...De({x:v,y:A},I,{x:-v,y:A})],$=_=>js({x:v,y:A},I,{x:-v,y:A},_),M=()=>A,x=.5}else{const A=v*.8;T=ve(0,zt,A,y);const I=_=>y*Math.sqrt(Math.max(0,1-(_/A)**2));$=_=>zt+I(_),M=_=>zt-I(_),x=.5}if(t.shape(a(T,w),t.ink,0),k<Lk)return;const S=$(0)-M(0),E=v*x,P=(A,I,_=8)=>Array.from({length:_+1},(N,Y)=>A+(I-A)*Y/_);if(i.tongue){const A=E*.55,I=P(A,-A).map(N=>({x:N,y:M(N)})),_=De({x:-A,y:M(-A)},{x:0,y:M(0)+S*.8},{x:A,y:M(A)},8);t.shape(a([...I,..._.slice(1,-1)],w),Nk,0)}if(i.teeth){const A=Math.min(.06,S*.4),I=P(-E,E).map(N=>({x:N,y:$(N)})),_=I.map(({x:N,y:Y})=>({x:N*.92,y:Y-A})).reverse();t.shape(a([...I,..._],w),"#ffffff",0);for(const N of[-.5,0,.5]){const Y=E*N;t.line(a([{x:Y,y:$(Y)},{x:Y*.92,y:$(Y)-A}],w),r*.6)}}}function Wk(t,e,n,s,i,o,r,a,l,c,h,u,d){const{x:f,y:p}=n,g=Math.min(1.2,Math.max(.5,u.eyeScale??1)),m=Math.min(1.2,Math.max(.45,u.eyeAspect??1)),w=.21*g*(1+r*.15),v=.25*g*m*Math.min(i,1.6)*(1-o)*(1+r*.3),k={x:f-w,y:p},y={x:f+w,y:p},T={x:f,y:p+v*1.9},$={x:f,y:p-v*1.35},M=De(k,T,y),x=De(y,$,k),S=V=>St(e,V,n,u.projection).points,E=V=>V.map(tt=>{const X=Math.min(y.x,Math.max(k.x,tt.x));return{x:X,y:Math.min(js(k,T,y,X),Math.max(js(y,$,k,X),tt.y))}});t.shape(S([...M,...x.slice(1,-1)]),"#ffffff",h*.5);const P=f+Math.max(-1,Math.min(1,l))*.07*g,A=p-Math.max(-1,Math.min(1,c))*.055*g,I=.115*g,_=.185*g;t.shape(S(E(ve(P,A,I,_,24))),u.iris??"#4b7fce",h*.4),t.shape(S(E(ve(P,A-.075*g,I*.7,_*.35))),"rgba(255,255,255,0.25)",0);const N=Math.min(.085,.042*a)*g,Y=E(ve(P,A,N,N*1.35));if(t.shape(S(Y),t.ink,0),u.inPupil&&d){const[V]=S([{x:P,y:A}]),tt=Math.min(...S(Y).map(X=>Math.hypot(X.x-V.x,X.y-V.y)));tt>.5&&(d.save(),d.beginPath(),d.arc(V.x,V.y,tt,0,Math.PI*2),d.clip(),u.inPupil(d,{...V,r:tt,side:s===1?"left":"right"}),d.restore())}if(t.shape(S(E(ve(P-.038*g,A+.075*g,.035*g,.045*g))),"#ffffff",0),t.shape(S(E(ve(P+.04*g,A-.04*g,.014*g,.02*g))),"#ffffff",0),t.line(S(M),h*1.1),u.lashes!==!1)for(const V of[0,.035]){const tt=f+s*(w-V),X=js(k,T,y,tt);t.line(S([{x:tt,y:X},{x:tt+s*.055,y:X+.07}]),h*.75)}}function Dk(t,e,n,s,i){const o=Math.min(1,Math.max(0,n));if(!(o<=0))for(const r of[-1,1]){const a={x:r*.59,y:Bt};if(St(e,[],a,i).facing<un)continue;for(const h of[-.06,.035]){const u=[{x:a.x,y:a.y},{x:a.x+r*.1,y:a.y+h}];t.line(St(e,u,a,i).points,s*.45*o)}const l={x:r*.3,y:-.38},c=De({x:l.x,y:-.31},{x:l.x+r*.07,y:-.4},{x:l.x+r*.035,y:-.49});t.line(St(e,c,l,i).points,s*.35*o)}}const kd="#8fd0f5",vd=(t,e,n)=>Array.from({length:18},(s,i)=>{const o=Math.PI*2*i/18,r=Math.sin(o/2);return{x:t+Math.sin(o)*n*r,y:e-n*.9+Math.cos(o)*n*1.6*(.55+.45*r)-n*.4}});function Bk(t,e,n,s,i){const o=Math.min(1,Math.max(0,qt(n,"blush",0))),r=Math.min(1,Math.max(0,qt(n,"tears",0))),a=Math.min(1,Math.max(0,qt(n,"sweat",0)));if(!(o+r+a<=.01)){for(const l of[1,-1]){const c={x:.5*l,y:-.16},h=St(e,[],c,i).facing>=un;if(o>.01&&h){const{points:d}=St(e,ve(c.x,c.y,.17,.1),c,i);if(t.shape(d,`rgba(240, 120, 140, ${(.75*o).toFixed(3)})`,0),o>.5)for(const f of[-.07,0,.07]){const p=[{x:c.x+f-.018,y:c.y-.03},{x:c.x+f+.018,y:c.y+.03}];t.line(St(e,p,c,i).points,s*.3)}}const u={x:bd*l,y:Bt};if(r>.01&&St(e,[],u,i).facing>=un){const d=.05+.04*r,f={x:u.x+.06*l,y:Bt-.2-.12*r};if(t.shape(St(e,vd(f.x,f.y,d),f,i).points,kd,s*.35),r>.6){const p=[{x:u.x+.05*l,y:Bt-.1},{x:f.x,y:f.y+d*.8}];t.line(St(e,p,f,i).points,s*.3)}}}if(a>.01){const l={x:.64,y:.42};St(e,[],l,i).facing>=un&&t.shape(St(e,vd(l.x,l.y,.05+.05*a),l,i).points,kd,s*.35)}}}const zk=15;function pe(t,e){const n=Math.sqrt(Math.max(0,1-e*e));return[n*Math.sin(t),e,n*Math.cos(t)]}const qk=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function Kt(t,[e,n,s]){const[i,o,r]=t.axes;return i[2]*e+o[2]*n+r[2]*s}function $t(t,e){return Dn(t,e).point}function ko(t,e){const n=Math.abs(t-e)%(Math.PI*2);return n>Math.PI?Math.PI*2-n:n}function vo(t,e,n=64){const s=e.top??1,i=e.bottom??-1,o=Math.max(8,Math.ceil((s-i)*zk)),r=p=>Math.min(s,Math.max(i,s-(s-i)*(p-1)/o)),a=p=>-Math.PI+Math.PI*2*p/n,l=(p,g)=>e.normal?e.normal(p,g):qk(e.position(p,g)),c=o+3,h=new Float64Array(n*c),u=new Float64Array(n*c);for(let p=0;p<c;p++){const g=p===0||p===c-1,m=r(p);for(let w=0;w<n;w++){const v=p*n+w;if(g){h[v]=-1;continue}const k=a(w);h[v]=e.inside(k,m),u[v]=h[v]>-.35?Kt(t,l(k,m)):0}}const d=p=>(p%n+n)%n,f=p=>{const g=n+1,m=new Float64Array(g*c);for(let A=0;A<c;A++)for(let I=0;I<=n;I++){const _=A*n+(I===n?0:I);m[A*g+I]=Math.min(h[_],p*u[_])}const w=(A,I)=>m[I*g+A],v=(A,I,_,N)=>{const Y=w(A,I),V=w(_,N),tt=Y===V?.5:Math.min(1,Math.max(0,Y/(Y-V)));return $t(t,e.position(a(A+(_-A)*tt),r(I+(N-I)*tt)))},k=n*c*2,y=new Int32Array(k).fill(-1),T=new Int32Array(k).fill(-1),$=new Map,M=(A,I,_)=>{const N=(_*n+d(I))*2+(A?1:0);return $.has(N)||$.set(N,A?v(d(I),_,d(I),_+1):v(I,_,I+1,_)),N},x=(A,I)=>{y[A]===-1?y[A]=I:T[A]=I},S=(A,I)=>{x(A,I),x(I,A)};for(let A=0;A<c-1;A++)for(let I=0;I<n;I++){const _=A*g+I,N=(m[_]>0?8:0)|(m[_+1]>0?4:0)|(m[_+g+1]>0?2:0)|(m[_+g]>0?1:0);if(N===0||N===15)continue;const Y=()=>M(!1,I,A),V=()=>M(!1,I,A+1),tt=()=>M(!0,I,A),X=()=>M(!0,I+1,A);switch(N){case 1:case 14:S(tt(),V());break;case 2:case 13:S(V(),X());break;case 3:case 12:S(tt(),X());break;case 4:case 11:S(Y(),X());break;case 6:case 9:S(Y(),V());break;case 7:case 8:S(tt(),Y());break;case 5:case 10:{const R=(w(I,A)+w(I+1,A)+w(I+1,A+1)+w(I,A+1))/4>0;N===5===R?(S(tt(),Y()),S(V(),X())):(S(tt(),V()),S(Y(),X()));break}}}const E=[],P=new Uint8Array(k);for(const A of $.keys()){if(P[A])continue;const I=[];let _=-1,N=A;for(;N!==-1&&!P[N];){P[N]=1,I.push($.get(N));const Y=y[N],V=T[N],tt=Y!==-1&&Y!==_&&!P[Y]?Y:V!==-1&&V!==_&&!P[V]?V:-1;_=N,N=tt}I.length>=3&&E.push(I)}return E};return{near:f(1),far:f(-1)}}const Md=new WeakMap;function Ba(t,e,n){let s=Md.get(t);s||Md.set(t,s=new Map);let i=s.get(e);return i||s.set(e,i=n()),i}function za(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 Sd(t,e,n,s=.04){const i=[];let o=[];return e.forEach((r,a)=>{Kt(t,n[a])>s?o.push($t(t,r)):(o.length>=2&&i.push(o),o=[])}),o.length>=2&&i.push(o),i}const xd=t=>t*Math.PI/180,qa=t=>{const e=Math.hypot(...t)||1;return t.map(n=>n/e)},Yk=(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 Td(t,e,n){return t>=e+n?t:t<=e-n?e:e+(t-e+n)**2/(4*n)}function Ya(t,e,n){const s=qa(n),i=t.reduce((c,h,u)=>c+h*s[u],0),r=t.map((c,h)=>c-i*s[h]).reduce((c,h)=>c+h*h,0),a=Math.sqrt(Td(1-r,e*e,e*e)),l=Td(i,a,e)-i;return l===0?t:t.map((c,h)=>c+s[h]*l)}function Kk(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 jk(t,e,n,s){const i=(t.path.length-1)/3,o=i*20,r=[],a=[],l=s.trail!==0||s.lift!==0,c=Math.max(0,e+n);for(let h=0;h<=o;h++){const u=h/o,d=Math.min(i-1,Math.floor(u*i)),f=u*i-d,p=1-f,g=[p**3,3*p*p*f,3*p*f*f,f**3],m=t.path.slice(d*3,d*3+4),w=xd(m.reduce((_,N,Y)=>_+N.around*g[Y],0)),v=m.reduce((_,N,Y)=>_+N.up*g[Y],0),k=m.reduce((_,N,Y)=>_+(N.lift??0)*g[Y],0),y=1+e+n+k,T=v>=0?Math.sqrt(Math.max(0,1-v*v)):1,$=u*u*(t.follow??1),M=xd(s.swing)*$,x=w-M,S=[Math.sin(x)*T*y,v*(v>=0?y:1),Math.cos(x)*T*y],E=[S[0],S[1]+s.lift*$,S[2]-s.trail*$],P=[Math.sin(x)*T,Math.max(0,v),Math.cos(x)*T],A=qa(S),I=l&&$>0?Ya(E,c,A):E;a.push(A),r.push({center:I,normal:P,left:I,right:I,t:u})}return r.forEach((h,u)=>{const d=r[Math.max(0,u-1)].center,p=r[Math.min(o,u+1)].center.map((w,v)=>w-d[v]),g=qa(Yk(h.normal,p)),m=t.width*Math.sin(Math.PI*h.t)**.6*.5;h.left=h.center.map((w,v)=>w+g[v]*m),h.right=h.center.map((w,v)=>w-g[v]*m),l&&h.t>0&&(t.follow??1)>0&&(h.left=Ya(h.left,c,a[u]),h.right=Ya(h.right,c,a[u]))}),r}const Yn=(t,e,n)=>t.map((s,i)=>s+(e[i]-s)*n);function Xk(t,e,n){const s=n?1:-1,i=[];let o=[];for(let r=0;r<e.length;r++){const a=e[r],l=s*Kt(t,a.normal)>=0;if(r>0){const c=e[r-1],h=s*Kt(t,c.normal),u=s*Kt(t,a.normal);if(h>=0!==l){const d=h/(h-u),f={center:Yn(c.center,a.center,d),left:Yn(c.left,a.left,d),right:Yn(c.right,a.right,d),normal:Yn(c.normal,a.normal,d),t:c.t+(a.t-c.t)*d};l?o=[f]:(o.push(f),o.length>=2&&i.push(o),o=[])}}l&&o.push(a)}return o.length>=2&&i.push(o),i}function Ed(t,e,n,s,i,o,r){const a=(n.locks??[]).map(h=>jk(h,n.volume,s,i)),l=h=>h.reduce((u,d)=>u+Kt(e,d.center),0)/h.length;a.sort((h,u)=>l(h)-l(u));const c=Math.max(.7,o*.35);for(const h of a)for(const u of Xk(e,h,r)){const d=u.map(g=>$t(e,g.left)),f=u.map(g=>$t(e,g.right));if(t.shape([...d,...f.slice().reverse()],n.color,0),t.look==="clean"&&(n.shine??0)>0){const g=u.filter(m=>m.t>=.2&&m.t<=.75);if(g.length>=3){const m=g.map((v,k)=>{const y=.16*Math.sin(Math.PI*k/(g.length-1));return $t(e,Yn(v.center,v.left,.16+y))}),w=g.map(v=>$t(e,Yn(v.center,v.left,.16)));t.shape([...m,...w.reverse()],`rgba(255,255,255,${n.shine})`,0)}}const p=u.filter(g=>g.t>.3);p.length>=2&&t.line(p.map(g=>$t(e,g.left)),c)}}const Et=(t,e,n=0)=>({around:t,up:e,lift:n}),Ka=()=>[{width:.66,follow:.22,path:[Et(-38,.88),Et(-12,.94,.08),Et(58,.76,.09),Et(94,.16,.03)]},{width:.58,follow:.3,path:[Et(-42,.8),Et(-24,.7,.12),Et(18,.57,.09),Et(64,.3)]},{width:.36,follow:.18,path:[Et(-58,.76),Et(-76,.56,.07),Et(-90,.12,.06),Et(-102,-.36)]}];function Ad(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?[Et(e,.7),Et(e+s*9,.2,.12),Et(e-s*13,-.5,.2),Et(e-s*8,-.95,.16),Et(e-s*3,-1.4,.12),Et(e+s*18,i+.35,.22),Et(e+s*12,i,.03)]:[Et(e,.7),Et(e+s*7,.15,.2),Et(e-s*8,-.75,.25),Et(e+s*5,i)]}})}const Gk={softSweep:{volume:.12,shine:.16,part:-38,strands:"part",sweep:-.08,hairline:{front:.64,side:.12,back:-.8},locks:Ka()},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:[...Ad(!1),...Ka()]},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:[...Ad(!0),...Ka()]}},Kn={swing:0,trail:0,lift:0};function Xs(t){if(!t)return Kn;const e=t["hair.swing"]??0,n=t["hair.trail"]??0,s=t["hair.lift"]??0;return e===0&&n===0&&s===0?Kn:{swing:e,trail:n,lift:s}}const Pd=t=>t.swing===0&&t.trail===0&&t.lift===0;function $d(t){return t.length>0||t.ties.some(e=>e.kind!=="bun")||(t.locks??[]).some(e=>(e.follow??1)>0)}function ja([t,e,n],s){if(s===0)return[t,e,n];const i=Math.cos(s),o=Math.sin(s);return[t*i-n*o,e,n*i+t*o]}const Id={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},Od=1.75,Xa={...Gk,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:Od,opening:84,part:0,strands:"part",hairline:{front:.5,side:.05,back:-.85},coversEars:!0},shoulderWaves:{volume:.22,length:Od,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}},me={black:"#22201f",brown:"#6b4630",chestnut:"#7b4a2b",auburn:"#9a4426",blond:"#d9b55a",ginger:"#c8662f",gray:"#a7a29c",white:"#ecebe7"};function _d(t){const e=typeof t=="string"?{style:t}:t,n=e.style?Xa[e.style]:{};if(e.style&&!n)throw new Error(`hair: unknown style '${e.style}'`);const{style:s,hairline:i,...o}=e,r={...Id,...n,...o,hairline:{...Id.hairline,...n.hairline,...i},ties:(o.ties??n.ties??[]).map(a=>({...a})),...o.spikes??n.spikes?{spikes:(o.spikes??n.spikes).map(a=>({...a}))}:{},...o.locks??n.locks?{locks:(o.locks??n.locks).map(Kk)}:{},...o.fall??n.fall?{fall:{...o.fall??n.fall}}:{}};if(r.shine!==void 0&&(!Number.isFinite(r.shine)||r.shine<0||r.shine>1))throw new Error("hair: shine must be between 0 and 1");if(r.fall&&(!Number.isFinite(r.fall.taper)||r.fall.taper<0||r.fall.taper>1||!Number.isFinite(r.fall.wave)||r.fall.wave<0))throw new Error("hair: fall needs taper between 0 and 1 and nonnegative wave");return r}const dn=t=>t*Math.PI/180,jn=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},Ga=t=>1-Math.abs(2*(t-Math.floor(t))-1);function Gs(t,e){const{front:n,side:s,back:i}=t.hairline,o=(n-i)/2,r=(n+i)/2,a=(r+s)/2,l=(r-s)/2,c=Math.max(0,Math.cos(e));let h=a+o*Math.cos(e)+l*Math.cos(2*e);return h-=t.sweep*Math.sin(e)*c,h+=t.recede*Math.exp(-(((Math.abs(e)-.75)/.32)**2)),(t.texture==="spiky"||t.texture==="curly")&&(h-=t.textureAmount*.6*Ga(e*11/(Math.PI*2))*c),h}function Cd(t,e,n){const s=t.textureAmount;switch(t.texture){case"spiky":return s*(Ga(e*11/(Math.PI*2))*Ga(n*2.6+.5))**1.2*jn(-.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 Hd(t,e,n=Kn){const s=t.length>0,i=new Map,o=h=>{let u=i.get(h);return u===void 0&&i.set(h,u=Gs(t,h)),u},r=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,p=Math.sqrt(1-.45*.45)*d*(1-f**5),g=.45+(1+t.flat-.45)*Math.min(1,f*1.8);return[p*Math.sin(h),g*(1+e),p*Math.cos(h)]},c={top:1,bottom:s?-(t.length+.25+Math.abs(t.fall?.wave??0)):-1,inside(h,u){const d=u-o(h);if(!s)return d;const f=Math.min(u+a(h),ko(h,0)-r);return Math.max(d,f)},position(h,u){if(s&&u<0){const k=t.length<1.5?.14*jn(-t.length+.45,-t.length-.1,u):0,y=(t.fall?.taper??0)*jn(0,-Math.max(.1,a(h)),u),T=1+e+t.volume*(1-k*2.5)+Cd(t,h,u)-k-y;return[T*Math.sin(h),u,T*Math.cos(h)]}const d=.4+.6*jn(0,.3,u-Gs(t,h)),f=1+e+(t.volume+Cd(t,h,u))*d,p=l(h,u,f);if(p)return p;const[g,m,w]=pe(h,u),v=[g*f,m*f,w*f];if(t.quiff>0){const k=t.quiff*Math.exp(-((h/.7)**2))*jn(.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)]:pe(h,u)}};return s&&!Pd(n)?Uk(c,t,n):c}function Uk(t,e,n){const s=o=>o<0?jn(-.15,-Math.max(.7,e.length),o):0,i=o=>dn(n.swing)*s(o);return{top:t.top,bottom:t.bottom,inside:(o,r)=>t.inside(o+i(r),r),position(o,r){const a=s(r);if(a===0)return t.position(o,r);const l=i(r),[c,h,u]=ja(t.position(o+l,r),l);return[c,h+n.lift*a,u-n.trail*a]},normal:(o,r)=>ja(t.normal(o+i(r),r),i(r))}}const Vk=t=>t.texture==="spiky"||t.texture==="curly"||t.texture==="locs"?104:t.texture==="wavy"?80:64;function Rd(t,e,n,s){return Ba(t,Zk(e,s),()=>vo(t,n,Vk(e)))}const Ld=new WeakMap;let Jk=1;function Zk(t,e){if(Pd(e))return t;let n=Ld.get(t);return n||Ld.set(t,n=Jk++),`${n}:${e.swing}:${e.trail}:${e.lift}`}function Nd(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 Ua(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 Qk(t,e,n,s=16){return Array.from({length:s+1},(i,o)=>{const r=o/s,a=1-r;return{x:a*a*t.x+2*a*r*e.x+r*r*n.x,y:a*a*t.y+2*a*r*e.y+r*r*n.y}})}function t5(t,e,n,s,i){const o=t.ry,r=(e.length??1.8)*o,a=Ua(t,ja(s,dn(i.swing))),l=Ua(t,[0,i.lift,-i.trail]),c=Math.hypot(a.x,a.y)||1,h=e.at==="high"||e.at==="low"||e.at==="top"?Ua(t,[.95,0,0]):{x:0},u=e.kind==="braid"?.15:.5,d={x:n.x+a.x/c*o*u+h.x*.9+l.x*.5,y:n.y+a.y/c*o*u*.6+l.y*.5},f={x:n.x+a.x/c*o*u*.6+h.x*1.3+l.x,y:n.y+r+l.y};return Qk(n,d,f)}const Mo=t=>Math.max(1,t*.5),Fd=(t,e)=>Math.max(.8,Math.min(t*.4,.1*e.rx));function Wd(t,e,n,s,i,o){const{point:r,out:a}=Nd(s.at),l=1+n.volume,c=$t(e,[r[0]*l,r[1]*l,r[2]*l]),h=Mo(i),u=Fd(i,e);if(s.kind==="bun"){const g=s.size??.32,m=$t(e,[r[0]*l+a[0]*g,r[1]*l+a[1]*g,r[2]*l+a[2]*g]);t.ellipse(m.x,m.y,g*e.rx,g*e.ry,e.angle,n.color,h);const w=g*e.rx*.55;t.line(Array.from({length:9},(v,k)=>{const y=-.4+k/8*Math.PI*1.3;return{x:m.x+Math.cos(y)*w,y:m.y+Math.sin(y)*w*.8}}),u);return}const d=t5(e,s,c,a,o),f=(s.size??(s.kind==="braid"?.2:.34))*e.rx*2;if(s.kind==="ponytail")t.shape(Ft(d,f,f*.15),n.color,h),t.line(d.slice(3,d.length-3),u);else{const m=d.slice(0,d.length-3);for(let k=0;k<7;k++){const y=m[Math.floor(k/7*(m.length-1))],T=m[Math.floor((k+1)/7*(m.length-1))],$=Math.atan2(T.y-y.y,T.x-y.x),M=Math.hypot(T.x-y.x,T.y-y.y),x=f*(1-k/(7*2.2)),S=(k%2===0?1:-1)*.35,E={x:(y.x+T.x)/2,y:(y.y+T.y)/2};t.ellipse(E.x,E.y,M*.62,x*.5,$+S,n.color,h*.8)}const w=m[m.length-1],v=d[d.length-1];t.shape(Ft([w,v],f*.7,f*.2),n.color,h*.8)}const p=d[s.kind==="braid"?d.length-4:2];t.ellipse(p.x,p.y,f*.32,f*.22,e.angle,n.color,h)}function Dd(t,e){return Kt(t,Nd(e.at).out)<-.2}function e5(t){const e=(i,o,r=0,a=14)=>Array.from({length:a+1},(l,c)=>{const h=c/a;return[i[0]+(o[0]-i[0])*h+r*Math.sin(Math.PI*h),i[1]+(o[1]-i[1])*h]}),n=dn(t.part??0),s=i=>Gs(t,i)+.04;switch(t.strands){case"part":return[e([n,s(n)],[n,.97])];case"sweep":{const i=Math.sign(t.sweep||-1),o=[.9,.72,.55].map((r,a)=>{const l=n+i*(.6+a*.35);return e([n,r],[l,Math.max(s(l)+.05,r-.35)],.05*i)});return[e([n,s(n)],[n,.97]),...o]}case"combed":return[-.75,-.35,.35,.75].map(i=>e([i,s(i)+.02],[i*.3,.86]));case"thin":return[-.5,.05,.6].map(i=>e([i,s(i)+.02],[i*.5,.95],.12));case"hanging":{const i=t.length>0?-t.length+.25:-.4,o=[-2.6,-2,-1.4,1.4,2,2.6,3.05].map(r=>e([r,Gs(t,r)<.9?.6:.9],[r,i],0));return t.part!==null&&o.push(e([n,s(n)],[n,.97])),o}default:return[]}}function n5(t,e,n,s,i){if(s.fill==="stipple"||s.hairline.front>1.5)return;const o=i.motion??Kn,r=i.lineWidth*.45/n.rx,{far:a}=Rd(n,s,Hd(s,r,o),o);za(e,n,()=>{for(const l of s.ties)Dd(n,l)&&Wd(t,n,s,l,i.lineWidth,o);Bd(t,n,s,i.lineWidth,r,!1);for(const l of a)t.shape(l,s.color,Mo(i.lineWidth));Ed(t,n,s,r,o,i.lineWidth,!1)},i.headOutline)}function Va(t,e,n,s){if(n.hairline.front>1.5)return;const i=s.motion??Kn,o=s.lineWidth*.45/e.rx,r=Hd(n,o,i),a=Fd(s.lineWidth,e);if(n.fill==="stipple"){for(let h=.97;h>-1;h-=.17)for(let u=-Math.PI;u<Math.PI;u+=.27){const d=Math.round(h*100)%2*.13;if(r.inside(u+d,h)<.02)continue;const f=pe(u+d,h);if(Kt(e,f)<.12)continue;const p=$t(e,f);t.dot(p.x,p.y,a*.4)}return}const{near:l}=Rd(e,n,r,i),c=Mo(s.lineWidth);Bd(t,e,n,s.lineWidth,o,!0);for(const h of l)t.shape(h,n.color,c);Ed(t,e,n,o,i,s.lineWidth,!0);for(const h of e5(n)){const u=h.map(([f,p])=>{const[g,m,w]=r.position(f,p);return[g*.985,m*.985,w*.985]}),d=h.map(([f,p])=>r.normal(f,p));for(const f of Sd(e,u,d,.12))t.line(f,a)}for(const h of n.ties)Dd(e,h)||Wd(t,e,n,h,s.lineWidth,i)}function Bd(t,e,n,s,i,o){for(const r of n.spikes??[]){const a=pe(dn(r.around),Math.max(-1,Math.min(1,r.up)));if(Kt(e,a)>=0!==o)continue;const l=[Math.cos(dn(r.around)),0,-Math.sin(dn(r.around))],c=[a[1]*l[2],a[2]*l[0]-a[0]*l[2],-a[1]*l[0]],h=1+n.volume+i,u=Math.max(0,r.width),d=Math.max(0,r.length),f=[$t(e,a.map(p=>p*(h+d)))];for(let p=0;p<8;p++){const g=p*Math.PI/4,m=a.map((w,v)=>w*h+u*(l[v]*Math.cos(g)+c[v]*Math.sin(g)));f.push($t(e,m))}t.shape(Da(f),n.color,Mo(s))}}const zd=.35,Ja=t=>({centre:[t*.98,-.02,-.08],out:[t,0,-.12]});function qd(t,e,n,s,i){const{centre:o,out:r}=Ja(n),a=Kt(e,r),l=Math.max(1,s.lineWidth*.55),c=s.skin==="none"?null:s.skin,h=e.ry*.27;if(!i){const m=$t(e,[o[0]*1.06,o[1],o[2]]);t.ellipse(m.x,m.y,e.rx*.17,h,e.angle,c,l);return}const u=$t(e,o),d=e.rx*(.12+.08*a);t.ellipse(u.x,u.y,d,h,e.angle,c,l);const f=Math.cos(e.angle),p=Math.sin(e.angle),g=Array.from({length:9},(m,w)=>{const v=-Math.PI*.55+w/8*Math.PI*1.1,k=Math.cos(v)*d*.45*-n,y=Math.sin(v)*h*.55;return{x:u.x+k*f-y*p,y:u.y+k*p+y*f}});t.line(g,Math.max(.8,l*.7))}function s5(t,e,n,s){za(e,n,()=>{for(const i of[1,-1])Kt(n,Ja(i).out)<zd&&qd(t,n,i,s,!1)},s.headOutline)}function i5(t,e,n){for(const s of[1,-1])Kt(e,Ja(s).out)>=zd&&qd(t,e,s,n,!0)}const Za={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 Yd(t,e){const n=typeof t=="string"?{style:t}:t,s=n.style?Za[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 Be=t=>t*Math.PI/180,So=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},Kd={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}},o5=(t,e)=>{const n=So(Be(48),Be(100),ko(e,0));return t.top[0]+(t.top[1]-t.top[0])*n},r5=t=>t==="sideburns"||t==="muttonChops";function Qa(t,e){const n=Kd[t];if(!n)return null;const s=Be(n.reach),i=o=>{const r=ko(o,0);return n.shape==="point"?Math.exp(-((r/.42)**2)):n.shape==="square"?1-So(Be(45),Be(85),r):Math.cos(Math.min(r,Math.PI/2))**.7};return{top:Math.max(n.top[0],n.top[1])+.05,bottom:-1,inside(o,r){const a=ko(o,0),l=o5(n,o);let c=Math.min(l-r,s-a);if(n.band>0&&(c=Math.min(c,r-(l-n.band))),r5(t)){const h=t==="muttonChops"?Be(70)-Be(22)*So(.08,-.6,r):Be(72);c=Math.min(c,a-h)}return c},position(o,r){const[a,l,c]=pe(o,r),h=1+e+n.volume,u=n.length*i(o)*So(-.45,-1,r);return[a*h,l*h-u,c*h+u*.25]},normal:(o,r)=>pe(o,r)}}function a5(t){const n=s=>s.map(([i,o])=>({x:i,y:-.24+o}));switch(t){case"short":return n([[-.17,-.02],[-.1,.04],[0,.03],[.1,.04],[.17,-.02],[.08,-.05],[0,-.03],[-.08,-.05]]);case"chevron":return n([[-.28,-.1],[-.16,.05],[0,.07],[.16,.05],[.28,-.1],[.12,-.08],[0,-.06],[-.12,-.08]]);case"walrus":return n([[-.38,-.2],[-.3,.02],[-.12,.09],[0,.07],[.12,.09],[.3,.02],[.38,-.2],[.2,-.13],[0,-.11],[-.2,-.13]]);case"handlebar":return n([[-.24,-.03],[-.12,.04],[0,.03],[.12,.04],[.24,-.03],[.1,-.05],[0,-.03],[-.1,-.05]]);default:return null}}const Us=t=>Math.max(1,t*.45);function l5(t,e,n,s){for(let i=.1;i>-1;i-=.13)for(let o=-Math.PI/1.7;o<Math.PI/1.7;o+=.2){const r=Math.round(i*100)%2*.1;if(n.inside(o+r,i)<.02)continue;const a=pe(o+r,i);if(Kt(e,a)<.15)continue;const l=$t(e,a);t.dot(l.x,l.y,s)}}function c5(t,e,n,s,i){const o=s.beard==="stubble"?null:Qa(s.beard,i.lineWidth*.45/n.rx);if(!o)return;const{far:r}=Ba(n,s,()=>vo(n,o));za(e,n,()=>{for(const a of r)t.shape(a,s.color,Us(i.lineWidth))},i.headOutline)}function h5(t,e,n,s,i){if(n.beard==="none")return;const o=s.lineWidth*.45/e.rx;if(n.beard==="stubble"){l5(t,e,Qa("full",o),Math.max(.5,s.lineWidth*.09));return}if(n.beard==="soulPatch"){const l=[{x:-.05,y:-.55},{x:.05,y:-.55},{x:0,y:-.68}],{points:c,facing:h}=St(e,l,{x:0,y:-.6},s.face?.projection);h>-.05&&t.shape(c,n.color,Us(s.lineWidth)*.7);return}const r=Qa(n.beard,o);if(!r)return;const{near:a}=Ba(e,n,()=>vo(e,r));for(const l of a)t.shape(l,n.color,Us(s.lineWidth));if(Kd[n.beard]?.aroundMouth){const l=.27*Math.max(.3,i),c=Array.from({length:20},(d,f)=>{const p=Math.PI*2*f/20;return{x:Math.cos(p)*l,y:-.42+Math.sin(p)*.13}}),{points:h,facing:u}=St(e,c,{x:0,y:-.42},s.face?.projection);u>-.05&&t.shape(h,s.skin==="none"?"#ffffff":s.skin,0)}}function u5(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}=St(e,l,i,s.face?.projection);h>-.05&&t.line(c,Math.max(1,s.lineWidth*.32));return}const o=a5(n.moustache);if(!o)return;const{points:r,facing:a}=St(e,o,i,s.face?.projection);if(!(a<=-.05)&&(t.shape(r,n.color,Us(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(St(e,c,i,s.face?.projection).points,Us(s.lineWidth)*.8)}}const tl={round:!0,square:!0,sunglasses:!0};function jd(t){const n=(typeof t=="string"?{style:t}:t).style??"round";if(!(n in tl))throw new Error(`glasses: unknown style '${n}'`);return{style:n}}const Xd=.34,ye=.12,d5=.05;function f5(t,e){return Array.from({length:28},(s,i)=>{const o=Math.PI*2*i/28;if(t==="round")return{x:e+Math.cos(o)*.2,y:ye+Math.sin(o)*.19};const r=Math.cos(o),a=Math.sin(o),l=t==="sunglasses"?.22:.21,c=t==="sunglasses"?.17:.16;return{x:e+Math.sign(r)*Math.abs(r)**.45*l,y:ye-.01+Math.sign(a)*Math.abs(a)**.45*c}})}function g5(t,e,n,s){const i=Math.max(1,Math.min(s.lineWidth*.5,.11*e.rx)),o=[];for(const r of[1,-1]){const a=Xd*r,{points:l,facing:c}=St(e,f5(n.style,a),{x:a,y:ye},s.face?.projection);if(c<d5)continue;o.push(r),t.shape(l,n.style==="sunglasses"?"#1f2328":null,i);const h=[r*.97,ye+.02,-.1];if(Kt(e,[r,0,0])>.15){const u=St(e,[{x:a+r*.21,y:ye+.02}],{x:a,y:ye},s.face?.projection).points[0];t.line([u,$t(e,h)],i*.9)}}if(o.length===2){const r=[{x:Xd-.2,y:ye+.02},{x:0,y:ye+.07},{x:-.14,y:ye+.02}];t.line(St(e,r,{x:0,y:ye},s.face?.projection).points,i)}}const xo={cap:{color:"#d64535",brim:[.36,.16],height:1,peak:.7,detail:"seams"},beanie:{color:"#3a6ea5",brim:[.3,.12],height:1.08,detail:"fold"},hardHat:{color:"#f2c230",brim:[.34,.22],height:1.12,ring:.16,detail:"ridge"},sunHat:{color:"#e3c98f",brim:[.36,.3],height:1.02,ring:.62,detail:"band"},bowler:{color:"#2f2b2a",brim:[.36,.28],height:1.15,ring:.2,detail:"band"}};function Gd(t){const e=typeof t=="string"?{style:t}:t,n=e.style??"cap",s=xo[n];if(!s)throw new Error(`hat: unknown style '${n}'`);return{style:n,color:e.color??s.color}}const fn=(t,e)=>t.brim[1]+(t.brim[0]-t.brim[1])*(1+Math.cos(e))/2;function p5(t,e){return{top:1,bottom:Math.min(...t.brim)-.05,inside:(n,s)=>s-fn(t,n),position(n,s){const[i,o,r]=pe(n,s),a=fn(t,n),l=s>a?(o-a)*(t.height-1):0;return[i*e,o*e+l,r*e]},normal:(n,s)=>pe(n,s)}}function m5(t,e,n){const i=(o,r,a)=>{const l=fn(e,o)*n-a;return[Math.sin(o)*r,l,Math.cos(o)*r]};if(e.peak){const o=[],r=[];for(let a=0;a<=24;a++){const l=(-80+160*a/24)*(Math.PI/180),c=e.peak*Math.cos(l)**.6;o.push($t(t,[Math.sin(l)*(n+c*.25),fn(e,l)*n-.07*Math.cos(l),Math.cos(l)*(n+c)])),r.push($t(t,i(l,n,0)))}return[...o,...r.reverse()]}return e.ring?Array.from({length:48},(o,r)=>$t(t,i(Math.PI*2*r/48,n+e.ring,.07))):null}function y5(t){const e=s=>Array.from({length:13},(i,o)=>[s,fn(t,s)+(.97-fn(t,s))*o/12]),n=s=>Array.from({length:49},(i,o)=>{const r=-Math.PI+Math.PI*2*o/48;return[r,fn(t,r)+s]});switch(t.detail){case"seams":return[e(.55),e(-.55)];case"fold":return[n(.2)];case"ridge":return[e(0),e(Math.PI)];case"band":return[n(.12)]}}function Ud(t,e,n,s){const i=xo[n.style],r=1+s.lineWidth*.45/e.rx+Math.max(.05,Math.min(.3,s.hairVolume)+.04),a=Math.max(1,s.lineWidth*.5),l=m5(e,i,r);l&&t.shape(l,n.color,a);const c=p5(i,r),{near:h,far:u}=vo(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 y5(i)){const p=f.map(([m,w])=>{const[v,k,y]=c.position(m,w);return[v*.99,k*.99,y*.99]}),g=f.map(([m,w])=>pe(m,w));for(const m of Sd(e,p,g,.1))t.line(m,d)}if(i.detail==="seams"){const f=$t(e,[0,r*1.01,0]);t.dot(f.x,f.y,a*.9)}}function Vd(t){const e=t.hair?_d(t.hair):null;return{hair:e,facialHair:t.facialHair?Yd(t.facialHair,e?.color):null,glasses:t.glasses?jd(t.glasses):null,hat:t.hat?Gd(t.hat):null,ears:t.ears??!1}}const Jd=t=>!t.hair&&!t.facialHair&&!t.glasses&&!t.hat&&!t.ears,Zd=t=>t.axes[2][2]<-.3,Qd=t=>t.ears&&!t.hair?.coversEars;function tf(t,e,n,s,i,o){if(Jd(n))return;const r={...o,headOutline:o.face&&(o.face.shape==="angular"||o.face.projection==="volume")?md(s,o.face):void 0};n.hair&&n5(e,t,s,n.hair,{...r,motion:Xs(i)}),n.facialHair&&c5(e,t,s,n.facialHair,r),Qd(n)&&s5(e,t,s,r)}function b5(t,e,n,s,i,o,r){if(Jd(n)){r();return}const a=Zd(s);Qd(n)&&i5(e,s,o),n.hair&&!a&&!o.faceUnderHair&&Va(e,s,n.hair,{...o,motion:Xs(i)}),n.facialHair&&h5(e,s,n.facialHair,o,i.mouthWidth??1),r(),n.hair&&!a&&o.faceUnderHair&&Va(e,s,n.hair,{...o,motion:Xs(i)}),n.facialHair&&u5(e,s,n.facialHair,o),n.glasses&&g5(e,s,n.glasses,o),n.hat&&!a&&Ud(e,s,n.hat,{lineWidth:o.lineWidth,hairVolume:n.hair?.volume??0})}function ef(t,e,n,s,i,o){Zd(s)&&(n.hair&&Va(e,s,n.hair,{...o,motion:Xs(i)}),n.hat&&Ud(e,s,n.hat,{lineWidth:o.lineWidth,hairVolume:n.hair?.volume??0}))}const nf=40,w5=.215+.205,Qt=(t,e)=>{const n={};for(const s of["left","right"])for(const[i,o]of Object.entries(e))n[`${t}.${s}.${i}`]=o;return n},gt=(t,e)=>t[e]??ut[e]??0;function el(t,e,n=ut,s=1){const i=Ls(t),o=e*Math.PI*2,r=Math.sin(o)*s,a=Math.cos(o)*s,l=(1+Math.cos(o*2*(i.bounces??1)))/2,c=i.crouch??0,h=i.shoulder??0,u=i.forearm??0,d={...ut,...n};d["leg.left.swing"]=i.swing*r+c*.6,d["leg.right.swing"]=-i.swing*r+c*.6,d["leg.left.knee"]=i.knee*Math.max(0,a)+c*1.2,d["leg.right.knee"]=i.knee*Math.max(0,-a)+c*1.2,d["leg.left.ankle"]=gt(n,"leg.left.ankle")-(i.tiptoe??0),d["leg.right.ankle"]=gt(n,"leg.right.ankle")-(i.tiptoe??0);for(const[f,p]of[["left",-1],["right",1]])gt(n,`arm.${f}.spread`)>nf||gt(n,`arm.${f}.swing`)>nf||(d[`arm.${f}.swing`]=h+p*i.arm*r,d[`arm.${f}.elbow`]=gt(n,`arm.${f}.elbow`)+u+i.elbow*Math.max(0,p*r));return d.lean=gt(n,"lean")+i.lean*s,d.bend=gt(n,"bend")+(i.bend??0),d["head.nod"]=gt(n,"head.nod")-i.lean*.5*s+(i.headTilt??0),d.side=gt(n,"side")+(i.sway??0)*Math.sin(o),d.lift=gt(n,"lift")+(i.bounce??0)*s*l,d.stretch=gt(n,"stretch")*(1+(i.squash??0)*(l-.5)),d}function nl(t,e,n=1,s=1){const i=Ls(t);return 4*w5*s*e*Math.sin(i.swing*n*Math.PI/180)}const Xn=t=>_a[t],To={take:t=>[{after:140,pose:{stretch:.8,bend:10,lean:gt(t,"lean")-4,...Qt("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,...Qt("arm",{spread:150,bend:35,swing:0,elbow:0}),...Qt("leg",{swing:25,knee:60}),...Xn("shocked")},easing:"ease-out-cubic"},{after:720,pose:{lift:.25,stretch:1.25,bend:-10,...Qt("arm",{spread:140})},easing:"ease-in-out"},{after:900,pose:{lift:0,stretch:.74,bend:12,...Qt("arm",{spread:70,bend:0}),...Qt("leg",{swing:30,knee:60})},easing:"ease-in-quad"},{after:1060,pose:{stretch:1.06,bend:-3,...Qt("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"),...Xn("surprised"),...Qt("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,...Xn("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,...Xn("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,...Qt("arm",{spread:75}),...Qt("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"),...Qt("leg",{swing:0,knee:0})},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...Xn("scared"),...Qt("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:{...Xn("sad"),bend:18,stretch:.92,lean:gt(t,"lean")+5,"head.nod":14,...Qt("arm",{spread:6,swing:0,elbow:4,bend:0})},easing:"ease-in-out"}]};function sf(t,e){const n=kt(e.from??{}),s=e.speed??1;let i=n;return[{time:e.at,pose:n},...To[t](n).map(o=>(i={...i,...o.pose},{time:e.at+o.after*s,pose:i,act:!1,...o.easing?{easing:o.easing}:{}}))]}function of(t,e=ut){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 rf(t,e=ut){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 sl={sweeping:of,brushing:rf};function k5(t,e,n=ut){const s=sl[t];if(!s)throw new Error(`humanCyclePose: ${ft("cycle",t,Object.keys(sl))}`);return s(e,n)}function af(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 lf(t,e){const n=t.flatMap(i=>Array.from({length:8},(o,r)=>({x:i.x+Math.cos(r*Math.PI/4)*e,y:i.y+Math.sin(r*Math.PI/4)*e})));let s=Da(n);for(let i=0;i<2;i++)s=s.flatMap((o,r)=>{const a=s[(r+1)%s.length];return[{x:o.x*.75+a.x*.25,y:o.y*.75+a.y*.25},{x:o.x*.25+a.x*.75,y:o.y*.25+a.y*.75}]});return s}const cf=t=>t.flatMap(e=>[e.left,e.right]);function il(t,e={}){const{top:n,length:s}=af(e),i=t.bodyContours;if(!i?.spine)throw new Error("leafOutfit requires organic body contours");const o=i.spine.samples.filter(a=>a.at<=.3),r=["left","right"].flatMap(a=>i[`leg.${a}`]?.samples.filter(l=>l.at<=s)??[]);return{...n?{top:lf(cf(i.spine.samples.filter(a=>a.at>=.52&&a.at<=.91)),t.height*.01)}:{},skirt:lf(cf([...o,...r]),t.height*.012)}}function v5(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 M5(t,e,n){const s=e.x-t.x,i=e.y-t.y,o=Math.hypot(s,i)||1,r=-i/o,a=s/o,l=[];for(const c of[1,-1])for(let h=0;h<=16;h++){const u=c===1?h/16:1-h/16,f=3*(1-u)*u*n*c;l.push({x:t.x+s*u+r*f,y:t.y+i*u+a*f})}return l}function hf(t,e,n,s,i,o){const r=e.lineWidth*.7;if(n.shape(s,i,r),n.look==="silhouette")return;t.save(),v5(t,s),t.clip();const a=Math.min(...s.map(f=>f.x)),l=Math.max(...s.map(f=>f.x)),c=Math.min(...s.map(f=>f.y)),h=Math.max(...s.map(f=>f.y)),u=l-a,d=h-c;for(let f=0;f<2;f++)for(let p=0;p<5;p++){const g={x:a+u*(p/4+(f?.07:-.04)),y:c+d*(f?.38:-.1)},m={x:g.x+u*.09,y:g.y+d*.78};n.shape(M5(g,m,u*.13),(p+f)%2?i:o,r*.6),n.line([g,{x:g.x*.45+m.x*.55,y:g.y*.45+m.y*.55},m],r*.45);for(const w of[.32,.52,.7]){const v={x:g.x+(m.x-g.x)*w,y:g.y+(m.y-g.y)*w};n.line([{x:v.x-u*.045,y:v.y-d*.065},v,{x:v.x+u*.045,y:v.y-d*.05}],r*.3)}}t.restore()}function uf(t={}){const e=af(t),{color:n,accent:s}=e,i=o=>(r,a,l)=>{const c=il(a,e);o==="spine"&&c.top&&hf(r,a,l,c.top,n,s);const h=["spine","leg.left","leg.right"].reduce((u,d)=>a.parts[u].order>a.parts[d].order?u:d);o===h&&hf(r,a,l,c.skirt,n,s)};return{parts:{spine:{over:i("spine")},"leg.left":{over:i("leg.left")},"leg.right":{over:i("leg.right")}}}}const S5={apron:"#d8b48a",labCoat:"#f4f6f8",hoodie:"#6b7280",cardigan:"#6b8e4e",overalls:"",sari:"#16a34a"},ol=(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 x5(t){return t.parts["leg.left"].order>t.parts["leg.right"].order?"left":"right"}const df=t=>Math.max(t.parts["leg.left"].order,t.parts["leg.right"].order)>t.parts.spine.order,jt=t=>t.bodyForward?.[2]??Math.cos(t.turn*Math.PI/2),Me=t=>t.bodyForward?.[0]??Math.sin(t.turn*Math.PI/2);function ff(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 gf(t,e,n=0){const s=e*(t.length-1),i=Math.min(t.length-2,Math.floor(s)),o=t[i],r=t[i+1],a=pt(o,r,s-i),l=Math.hypot(r.x-o.x,r.y-o.y)||1;return{x:a.x+(r.y-o.y)/l*n,y:a.y-(r.x-o.x)/l*n}}function pf(t={}){if(t={...t},t.top!==void 0&&!["tshirt","shirt","blouse","dress"].includes(t.top))throw new Error(`basicOutfit: unknown top '${t.top}'`);if(t.trouserStyle!==void 0&&!["plain","jeans","cargo"].includes(t.trouserStyle))throw new Error(`basicOutfit: unknown trouser style '${t.trouserStyle}'`);const e=t.top,n=t.trouserStyle??"plain",s=t.collar??e==="shirt",i=t.shirt??"#e2493b",o=e==="dress"?i:t.trousers??"#24476b",r=t.sleeves??"short",a=e==="dress"?"skirt":t.bottom??"trousers",l=t.over==="labCoat",c=t.over==="hoodie",h=t.over==="cardigan",u=t.over==="overalls",d=t.over==="sari",f=t.overColor??(t.over&&t.over!=="overalls"?S5[t.over]:o),p=t.shoes==="boots",g=t.shoeColor??"#3b2a1e",m=H=>H.lineWidth*.45,w=(H,L,q,U)=>{const F=L.parts[`leg.${U}`].points;if(a==="skirt"&&!u)return;const W=a==="shorts"&&!u,B=L.bodyContours?.[`leg.${U}`],J=B?Wa(B,0,W?.5:1,L.height*.006):Ft(W?ol(F,0,.5):F,L.height*(W?.085:.08),L.height*(W?.07:.05));q.shape(J,o,m(L)),!(n==="plain"||jt(L)<.15)&&ff(H,J,()=>{const j=(Q,et=0)=>gf(F,Q,et*L.height);if(n==="jeans")q.line([j(.07,-.018),j(.17,-.02),j(.23,0),j(.17,.02),j(.07,.018)],m(L)*.65),q.line([j(.27,.013),...[.4,.55,.7,.85,.96].filter(Q=>!W||Q<.5).map(Q=>j(Q,.013))],m(L)*.5);else{const Q=[j(.25,-.024),j(.25,.024),j(.43,.024),j(.43,-.024)];q.shape(Q,o,m(L)*.65),q.line([j(.28,-.024),j(.32,0),j(.28,.024)],m(L)*.65);const et=j(.32);q.dot(et.x,et.y,m(L)*.8)}})},v=(H,L,q)=>{const U=H.parts[`leg.${q}`].points,F=ol(U,.7,1);if(F.length<2)return;L.shape(Ft(F,H.height*.075,H.height*.07),g,m(H));const W=F[0],B=F[1],J=B.x-W.x,j=B.y-W.y,Q=Math.hypot(J,j)||1,et=H.height*.04;L.line([{x:W.x-j/Q*et,y:W.y+J/Q*et},{x:W.x+j/Q*et,y:W.y-J/Q*et}],m(H)*.9)},k=H=>{const L=H.chains.spine,q=L[0],U=L[L.length-1],F={x:q.x-(U.x-q.x)*.25,y:q.y-(U.y-q.y)*.25};return{hip:q,top:U,below:F,line:[F,...H.parts.spine.points]}},y=H=>{if(H.bodyContours?.spine)return Wa(H.bodyContours.spine,0,.97,H.height*(c?.014:.006));const L=c?1.14:1,q=Math.hypot(H.points["hip.left"].x-H.points["hip.right"].x,H.points["hip.left"].y-H.points["hip.right"].y),U=Math.max(H.height*.15*L,q+Math.max(H.height*.08,H.lineWidth*1.45)+m(H));return Ft(k(H).line,U,H.height*.14*L)},T=(H,L)=>{const q=[y(L)],{top:U,hip:F}=k(L);h&&q.push(Ft([U,pt(U,F,.5),pt(U,F,1.08)],L.height*.155,L.height*.15)),l&&q.push(Ft([U,pt(U,F,.5),F],L.height*.14,L.height*.15));const W=Object.values(L.points),B=Math.min(...W.map(et=>et.x))-L.height,J=Math.min(...W.map(et=>et.y))-L.height,j=Math.max(...W.map(et=>et.x))+L.height,Q=Math.max(...W.map(et=>et.y))+L.height;for(const et of q){H.beginPath(),H.rect(B,J,j-B,Q-J),H.moveTo(et[0].x,et[0].y);for(const C of et.slice(1))H.lineTo(C.x,C.y);H.closePath(),H.clip("evenodd")}},$=(H,L)=>{const q=c?f:i;L.shape(y(H),q,m(H))},M=(H,L,q)=>{const U=jt(L);if(!e||U<.2||c)return;const{top:F,hip:W}=k(L),B=Me(L)*L.height*.025,J=[F,W],j=(Q,et=0)=>gf(J,Q,B+et*L.height*U);ff(H,y(L),()=>{if(e==="shirt"){q.line([j(.12),j(.92)],m(L)*.65);for(const Q of[.24,.4,.56,.72,.88]){const et=j(Q,.008);q.dot(et.x,et.y,m(L)*.9)}}else if(e==="blouse"){q.line([j(.025,-.04),j(.24),j(.025,.04)],m(L)*.75);const Q=j(.31);q.dot(Q.x,Q.y,m(L))}else e==="dress"?q.line([j(.04,-.035),j(.17,-.028),j(.17,.028),j(.04,.035)],m(L)*.75):q.line([j(.025,-.035),j(.1,-.02),j(.12),j(.1,.02),j(.025,.035)],m(L)*.65)})},x=(H,L)=>{const q=jt(H),{top:U,hip:F}=k(H),W=H.height*.07,B={x:(U.x-F.x)*.16,y:(U.y-F.y)*.16};if(q>=0){L.shape([{x:U.x-W,y:U.y+B.y*.25},{x:U.x-W*.8+B.x,y:U.y+B.y},{x:U.x+B.x*1.2,y:U.y+B.y*1.35},{x:U.x+W*.8+B.x,y:U.y+B.y},{x:U.x+W,y:U.y+B.y*.25}],f,m(H));return}const J=pt(U,F,.42);L.shape([{x:U.x-W*.9,y:U.y},{x:U.x+W*.9,y:U.y},{x:J.x+W*.7,y:J.y},{x:J.x,y:J.y+H.height*.02},{x:J.x-W*.7,y:J.y}],f,m(H))},S=(H,L)=>{const q=jt(H);if(q<.2)return;const{top:U,hip:F}=k(H),W=Me(H)*H.height*.03,B=H.height*.06*q,J=pt(U,F,.62),j=pt(U,F,.9);L.line([{x:J.x+W-B,y:J.y},{x:j.x+W-B*1.1,y:j.y}],m(H)*.7),L.line([{x:J.x+W+B,y:J.y},{x:j.x+W+B*1.1,y:j.y}],m(H)*.7);const Q=pt(U,F,.1);for(const et of[-1,1])L.line([{x:Q.x+W+et*B*.2,y:Q.y},{x:Q.x+W+et*B*.35,y:Q.y+H.height*.07}],m(H)*.6)},E=(H,L)=>{const{top:q,hip:U}=k(H),F=jt(H);if(L.shape(Ft([q,pt(q,U,.5),pt(q,U,1.08)],H.height*.155,H.height*.15),f,m(H)),F<.2)return;const W=Me(H)*H.height*.03,B=H.height*.02*F,J=pt(q,U,.12),j=pt(q,U,1.05);L.shape([{x:J.x+W-B,y:J.y},{x:J.x+W+B,y:J.y},{x:j.x+W+B*1.3,y:j.y},{x:j.x+W-B*1.3,y:j.y}],i,m(H)*.7);for(const Q of[.35,.55,.75]){const et=pt(q,U,Q);L.dot(et.x+W+B*1.6,et.y,m(H)*1.2)}},P=(H,L)=>{const q=jt(H),{top:U,hip:F}=k(H),W=Me(H)*H.height*.04,B=pt(F,U,.12),J=pt(F,U,.74);if(q<.15){if(q<-.3){const C=H.points["shoulder.left"],G=H.points["shoulder.right"];L.line([C,{x:B.x+H.height*.03,y:B.y}],m(H)*.8),L.line([G,{x:B.x-H.height*.03,y:B.y}],m(H)*.8)}return}const j=H.height*.07*q;L.shape([{x:J.x+W-j*.75,y:J.y},{x:J.x+W+j*.75,y:J.y},{x:B.x+W+j*1.1,y:B.y},{x:B.x+W-j*1.1,y:B.y}],o,m(H));for(const C of["left","right"]){const G=H.points[`shoulder.${C}`],ot={x:J.x+W+(G.x>J.x+W?1:-1)*j*.55,y:J.y};L.line([ot,{x:G.x+(ot.x-G.x)*.15,y:G.y+(ot.y-G.y)*.15}],m(H)*1.6)}const Q=pt(J,B,.3),et=j*.4;L.line([{x:Q.x+W-et,y:Q.y},{x:Q.x+W-et,y:Q.y+et*1.4},{x:Q.x+W+et,y:Q.y+et*1.4},{x:Q.x+W+et,y:Q.y}],m(H)*.6)},A=(H,L)=>{const{hip:q,top:U}=k(H),F=pt(q,U,.2),W=[H.points["ankle.left"],H.points["ankle.right"]],B=pt(q,{x:(W[0].x+W[1].x)/2,y:(W[0].y+W[1].y)/2},.98),J=H.height*.075,j=Math.max(H.height*.12,Math.abs(W[0].x-W[1].x)/2+H.height*.07),Q=B.x-F.x,et=B.y-F.y,C=Math.hypot(Q,et)||1,G={x:-et/C,y:Q/C};if(L.shape([{x:F.x+G.x*J,y:F.y+G.y*J},{x:B.x+G.x*j,y:B.y+G.y*j},{x:B.x-G.x*j,y:B.y-G.y*j},{x:F.x-G.x*J,y:F.y-G.y*J}],f,m(H)),jt(H)>.2){const at=Me(H)*H.height*.03;for(const it of[-.35,0,.35]){const lt=J*.5*it,nt=j*.45*it;L.line([{x:F.x+at+G.x*lt,y:F.y+G.y*lt+H.height*.02},{x:B.x+at+G.x*nt,y:B.y+G.y*nt}],m(H)*.5)}}},I=(H,L)=>{const q=jt(H),{top:U,hip:F}=k(H),W=Me(H),B=W>=0?"left":"right",J=B==="left"?"right":"left",j=H.points[`shoulder.${B}`],Q=H.height*.035;if(q<.15){const G=pt(U,F,.9);L.shape(Ft([j,{x:G.x+(j.x-U.x)*.5,y:G.y}],Q*2.2,Q*2.6),f,m(H));return}const et={x:F.x+(H.points[`hip.${J}`].x-F.x)*1.2,y:pt(F,U,.08).y};L.shape(Ft([et,pt(et,j,.5),j],Q*2.4,Q*2),f,m(H));const C={x:j.x-(F.x-j.x)*.05-W*H.height*.03,y:j.y+H.height*.16};L.shape(Ft([j,C],Q*2,Q*1.6),f,m(H))},_=(H,L)=>{if(H.bodyContours){L.shape(il(H,{top:!1,length:.45}).skirt,o,m(H));return}const{hip:q,top:U}=k(H),F=pt(q,U,.18),W=[H.points["knee.left"],H.points["knee.right"]],B=pt(q,{x:(W[0].x+W[1].x)/2,y:(W[0].y+W[1].y)/2},1.05),J=H.height*.075,j=Math.max(H.height*.13,Math.abs(W[0].x-W[1].x)/2+H.height*.08),Q=B.x-F.x,et=B.y-F.y,C=Math.hypot(Q,et)||1,G={x:-et/C,y:Q/C};L.shape([{x:F.x+G.x*J,y:F.y+G.y*J},{x:B.x+G.x*j,y:B.y+G.y*j},{x:B.x-G.x*j,y:B.y-G.y*j},{x:F.x-G.x*J,y:F.y-G.y*J}],o,m(H))},N=(H,L)=>{const q=jt(H);if(q<.2)return;const{top:U,hip:F}=k(H),W={x:(F.x-U.x)*.12,y:(F.y-U.y)*.12},B=H.height*.045*q;for(const J of[-1,1])L.shape([{x:U.x+J*B*.2,y:U.y+W.y*.1},{x:U.x+J*B*1.3,y:U.y-W.y*.1},{x:U.x+J*B*.6+W.x,y:U.y+W.y}],i,m(H)*.8)},Y=(H,L,q)=>{const U=jt(H);if(U<.25)return;const{top:F,hip:W}=k(H),B=Me(H)*H.height*.03,J=C=>({x:pt(F,W,C).x+B,y:pt(F,W,C).y}),j=H.height*.022*U,Q=J(.08),et=J(.62);L.shape([{x:Q.x-j,y:Q.y-j},{x:Q.x+j,y:Q.y-j},{x:Q.x+j*.6,y:Q.y+j},{x:Q.x-j*.6,y:Q.y+j}],q,m(H)*.7),L.shape([{x:Q.x-j*.6,y:Q.y+j},{x:Q.x+j*.6,y:Q.y+j},{x:et.x+j*1.4,y:et.y-j*2},et,{x:et.x-j*1.4,y:et.y-j*2}],q,m(H)*.7)},V=(H,L)=>{const q=jt(H),{top:U,hip:F}=k(H),W=pt(F,U,.72),B=[H.points["knee.left"],H.points["knee.right"]],J=pt(F,{x:(B[0].x+B[1].x)/2,y:(B[0].y+B[1].y)/2},.9),j=Me(H)*H.height*.04;if(q<.15){const C=pt(F,U,.2);q<-.3&&L.line([{x:C.x-H.height*.05,y:C.y},{x:C.x+H.height*.05,y:C.y}],m(H));return}const Q=H.height*.075*q,et=pt(F,U,.2);L.shape([{x:W.x+j-Q*.7,y:W.y},{x:W.x+j+Q*.7,y:W.y},{x:et.x+j+Q,y:et.y},{x:J.x+j+Q*1.15,y:J.y},{x:J.x+j-Q*1.15,y:J.y},{x:et.x+j-Q,y:et.y}],f,m(H)),L.line([{x:W.x+j-Q*.6,y:W.y},{x:U.x-Q*.2,y:U.y},{x:W.x+j+Q*.6,y:W.y}],m(H)*.8)},tt=(H,L,q)=>{const{top:U,hip:F}=k(H),W=[H.points["knee.left"],H.points["knee.right"]],B=pt(F,{x:(W[0].x+W[1].x)/2,y:(W[0].y+W[1].y)/2},.95);q?L.shape(Ft([pt(U,F,.8),F,B],H.height*.145,H.height*.17),f,m(H)):L.shape(Ft([U,pt(U,F,.5),F],H.height*.14,H.height*.15),f,m(H));const J=jt(H);if(J>.2){const j=Me(H)*H.height*.03,[Q,et]=q?[F,B]:[U,F];if(L.line([{x:Q.x+j,y:Q.y},{x:et.x+j,y:et.y}],m(H)*.8),!q){const C=pt(U,F,.35),G=H.height*.025*J;L.shape([{x:C.x+j-G*2.4,y:C.y},{x:C.x+j-G*.6,y:C.y},{x:C.x+j-G*.6,y:C.y+G*1.6},{x:C.x+j-G*2.4,y:C.y+G*1.6}],f,m(H)*.6)}}},X=(H,L,q,U,F)=>{const W=H.bodyContours?.[`arm.${q}`];if(W){const Z=Wa(W,0,F,H.height*.006);L.shape(Z,U,0);const rt=y(H);for(let ct=0;ct<Z.length;ct++){const dt=Z[ct],yt=Z[(ct+1)%Z.length];dd({x:(dt.x+yt.x)/2,y:(dt.y+yt.y)/2},rt)||L.line([dt,yt],m(H))}return}const B=H.parts[`arm.${q}`].points,J=B[0],j=H.chains.spine[H.chains.spine.length-1],et=[{x:J.x+(j.x-J.x)*.45,y:J.y+(j.y-J.y)*.45},...ol(B,0,F)],C=Ft(et,H.height*.085,H.height*(F>.6?.045:.06)),G=et.length,ot=C.slice(0,G),at=C.slice(G).reverse();L.shape(C,U,0);const it=Z=>Math.hypot(Z[1].x-j.x,Z[1].y-j.y),[lt,nt]=it(ot)>it(at)?[ot,at]:[at,ot];L.line(lt.slice(1),m(H)),L.line(nt.slice(Math.ceil(G*.45)),m(H)),L.line([ot[G-1],at[G-1]],m(H))},R=l||c||h,z=R?f:i,K=R||r==="long"?.95:.45,O=R||r!=="none",D=(H,L)=>{a==="skirt"&&!u&&!d&&_(H,L),d&&A(H,L),l&&tt(H,L,!0),t.over==="apron"&&V(H,L)},st=H=>(L,q,U)=>{L.save(),T(L,q),w(L,q,U,H),p&&v(q,U,H),L.restore(),x5(q)===H&&df(q)&&D(q,U)};return{parts:{"leg.left":{clip:T,over:st("left")},"leg.right":{clip:T,over:st("right")},spine:{over:(H,L,q)=>{c&&jt(L)>=0&&x(L,q),$(L,q),M(H,L,q),s&&!c&&N(L,q),t.tie&&!c&&Y(L,q,t.tie),l&&tt(L,q,!1),h&&E(L,q),c&&(jt(L)<0&&x(L,q),S(L,q)),u&&P(L,q),d&&I(L,q),df(L)||D(L,q)}},"arm.left":{over:O?(H,L,q)=>X(L,q,"left",z,K):void 0},"arm.right":{over:O?(H,L,q)=>X(L,q,"right",z,K):void 0}}}}const rl={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 mf(t){const e={};for(const n of["left","right","both"]){const s=t[n];if(!s)continue;const i=typeof s=="string"?s:s.item,o=rl[i];if(!o)throw new Error(`holding: unknown item '${i}'`);if(n==="both"&&o.hands==="one")throw new Error(`holding: a ${i} is held in one hand ('left' or 'right'), not 'both'`);if(n!=="both"&&o.hands==="both")throw new Error(`holding: a ${i} is held in both hands ('both')`);e[n]={item:i,color:(typeof s=="object"?s.color:void 0)??o.color}}return e}function Eo(t,e){const n=t.chains[`arm.${e}`],s=n[n.length-1],i=n[n.length-2],o=Math.hypot(s.x-i.x,s.y-i.y)||1,r={x:(s.x-i.x)/o,y:(s.y-i.y)/o},a=t.lineWidth*.5;return{point:{x:s.x+r.x*a,y:s.y+r.y*a},along:r,depth:t.parts[`arm.${e}`]?.depth??0}}function Gn(t,e,n,s=0){const i=Math.cos(s),o=Math.sin(s);return[[-e/2,-n/2],[e/2,-n/2],[e/2,n/2],[-e/2,n/2]].map(([r,a])=>({x:t.x+r*i-a*o,y:t.y+r*o+a*i}))}const Un=(t,e,n,s,i=12)=>Array.from({length:i+1},(o,r)=>{const a=n+(s-n)*r/i;return{x:t.x+Math.cos(a)*e,y:t.y+Math.sin(a)*e}});function al(t,e,n,s,i,o=1,r){const{point:a,along:l}=n,c=s/300;switch(e.item){case"mug":{const h=Gn({x:a.x,y:a.y-4*c},20*c,24*c);t.line(Un({x:a.x+10*c*Math.sign(o||1),y:a.y-4*c},7*c,-Math.PI/2,Math.PI/2).map(u=>({x:a.x+(u.x-a.x)*Math.sign(o||1),y:u.y})),i),t.shape(h,e.color,i);return}case"phone":{const h=Math.atan2(l.y,l.x)-Math.PI/2;t.shape(Gn(a,13*c,24*c,h),e.color,i),t.shape(Gn(a,9*c,17*c,h),"#8fd0f5",0);return}case"book":{const h=26*c,u=34*c;t.shape([{x:a.x,y:a.y-u/2},{x:a.x-h,y:a.y-u/2-3*c},{x:a.x-h,y:a.y+u/2-3*c},{x:a.x,y:a.y+u/2}],e.color,i),t.shape([{x:a.x,y:a.y-u/2},{x:a.x+h,y:a.y-u/2-3*c},{x:a.x+h,y:a.y+u/2-3*c},{x:a.x,y:a.y+u/2}],e.color,i);for(const d of[-1,1])for(const f of[.3,.5,.7]){const p=a.y-u/2+u*f;t.line([{x:a.x+d*5*c,y:p},{x:a.x+d*(h-5*c),y:p-2*c}],Math.max(.8,i*.5))}return}case"bag":{const h=a.y+10*c;t.line([{x:a.x-9*c,y:h},{x:a.x-5*c,y:a.y-2*c},{x:a.x+5*c,y:a.y-2*c},{x:a.x+9*c,y:h}],i),t.shape([{x:a.x-17*c,y:h},{x:a.x+17*c,y:h},{x:a.x+20*c,y:h+40*c},{x:a.x-20*c,y:h+40*c}],e.color,i);return}case"briefcase":{t.line(Un({x:a.x,y:a.y+6*c},7*c,Math.PI,Math.PI*2),i),t.shape(Gn({x:a.x,y:a.y+22*c},46*c,32*c),e.color,i),t.line([{x:a.x-23*c,y:a.y+14*c},{x:a.x+23*c,y:a.y+14*c}],Math.max(.8,i*.6));return}case"umbrella":{const h=78*c,u=(r??a.y-120*c)-14*c,d={x:a.x,y:Math.min(a.y-60*c,u-h*.55)};t.line([{x:a.x,y:a.y+10*c},d],i),t.line(Un({x:a.x+5*c,y:a.y+10*c},5*c,Math.PI,0,8),i);const f=[...Un({x:d.x,y:d.y+h*.55},h,Math.PI,Math.PI*2,24)],p=[];for(let g=4;g>=0;g--){const m=d.x-h+2*h*g/5;p.push(...Un({x:m+h/5,y:d.y+h*.55},h/5,0,-Math.PI,6).reverse())}t.shape([...f,...p],e.color,i);return}case"broom":{const h={x:l.x*.4+.25*Math.sign(o||1),y:Math.max(.6,l.y)},u=Math.hypot(h.x,h.y),d={x:h.x/u,y:h.y/u},f={x:a.x-d.x*40*c,y:a.y-d.y*40*c},p={x:a.x+d.x*120*c,y:a.y+d.y*120*c};t.line([f,p],i*1.1);const g={x:-d.y,y:d.x},m=[{x:p.x+g.x*6*c,y:p.y+g.y*6*c},{x:p.x-g.x*6*c,y:p.y-g.y*6*c},{x:p.x-g.x*16*c+d.x*34*c,y:p.y-g.y*16*c+d.y*34*c},{x:p.x+g.x*16*c+d.x*34*c,y:p.y+g.y*16*c+d.y*34*c}];t.shape(m,e.color,i);return}case"cane":{const h=Math.min(.56*s,Math.max(.3*s,-a.y)),u=.12*Math.sign(o||1),d={x:u/Math.hypot(u,1),y:1/Math.hypot(u,1)},f={x:a.x+d.x*h,y:a.y+d.y*h},p=Un({x:a.x+7*c*Math.sign(o||1),y:a.y-2*c},7*c,Math.PI,Math.PI*2,8).map(g=>({x:a.x+(g.x-a.x)*Math.sign(o||1),y:g.y}));t.line([...p,{x:a.x,y:a.y+2*c},f],i*1.2),t.shape(Gn({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(Gn(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 ll=(t,e)=>(t[`held.${e}`]??1)>=.5,yf=t=>Math.sin(t*Math.PI/2);function bf(t){const e=o=>Math.max(1,o.lineWidth*.45),n=o=>(r,a,l,c,h)=>{const u=t[o];u&&ll(h??{},o)&&al(l,u,Eo(a,o),a.height,e(a),yf(a.turn),a.head.center.y-a.head.ry)},s=(o,r,a,l,c)=>{const h=t.both;if(!h||!ll(c??{},"both"))return;const u=Eo(r,"left"),d=Eo(r,"right"),f={point:{x:(u.point.x+d.point.x)/2,y:(u.point.y+d.point.y)/2},along:{x:(u.along.x+d.along.x)/2,y:(u.along.y+d.along.y)/2},depth:(u.depth+d.depth)/2};al(a,h,f,r.height,e(r),yf(r.turn),r.head.center.y-r.head.ry)},i={parts:{}};if(t.left&&(i.parts["arm.left"]={over:n("left")}),t.right&&(i.parts["arm.right"]={over:n("right")}),t.both){const o=r=>(a,l,c,h,u)=>{const d=r==="left"?"right":"left";(r==="left"?l.parts["arm.left"].depth>=l.parts["arm.right"].depth:l.parts["arm.right"].depth>l.parts[`arm.${d}`].depth)&&s(a,l,c,h,u)};for(const r of["left","right"])i.parts[`arm.${r}`]={...i.parts[`arm.${r}`],over:T5(i.parts[`arm.${r}`]?.over,o(r))}}return i}function T5(t,e){return t?(n,s,i,o,r)=>{t(n,s,i,o,r),e(n,s,i,o,r)}:e}function cl(t,e){const n=(i,o)=>i&&o?(r,a,l,c,h)=>{i(r,a,l,c,h),o(r,a,l,c,h)}:i??o,s={};for(const i of new Set([...Object.keys(t.parts??{}),...Object.keys(e.parts??{})])){const o=t.parts?.[i],r=e.parts?.[i];s[i]={under:n(o?.under,r?.under),clip:n(o?.clip,r?.clip),over:n(o?.over,r?.over)}}return{behind:n(t.behind,e.behind),parts:s,front:n(t.front,e.front)}}function Vs(t={}){if(t.build&&!(t.build in ao))throw new Error(`character: unknown build '${t.build}'`);const e=t.build?ao[t.build]:{},n=(t.proportions??"bold")==="bold",s=t.figure??"fluid",i=t.look??"clean",o=t.height??300,r=s==="stick",a=s==="organic",l=t.shoulderWidth??e.shoulderWidth??(a?.07:.06),c=t.hipWidth??e.hipWidth??(a?.045:.022),h=t.lineWidth??o*(a?.005:n?.045:.022),u=t.ink??(a?"#53362d":i==="pencil"?"#2f2f33":"#1e293b"),d=t.skin??(a?"#f1bf98":i==="pencil"?"none":"#ffffff"),f=a?ld(t.body??{},{skin:d,ink:u,lineWidth:h,shoulderWidth:l,hipWidth:c}):void 0;if(t.leafOutfit&&!a)throw new Error("character: leafOutfit requires figure: 'organic'");const p=t.outfit?pf(t.outfit):null,g=t.holding?mf(t.holding):{};let m=p?cl(p,t.layers??{}):t.layers??{};return t.leafOutfit&&(m=cl(uf(t.leafOutfit),m)),Object.keys(g).length>0&&(m=cl(m,bf(g))),{plan:t.plan??Oa({headSize:t.headSize??e.headSize??(a?.27:n?.3:.24),shoulderWidth:r?0:l,hipWidth:r?0:c,legLength:t.legLength??e.legLength??1,armLength:t.armLength??e.armLength??1,feet:t.feet??e.feet}),figure:s,...f?{body:f}:{},look:i,height:o,lineWidth:f?.outline.width??h,ink:f?.outline.color??u,skin:f?.fill??d,seed:t.seed??1,pencil:a?{construction:!1,...t.pencil}:t.pencil??{},layers:m,holding:g,contact:t.contact??"ground",hands:t.hands??(a?"cartoon":"dot"),handStyle:t.handStyle??(a?"natural":"glove"),handSize:t.handSize??(a?.073:t.handStyle==="natural"?.14:.17),head:Vd(t),face:{...a?{style:"anime",projection:"volume",iris:"#66422e",nose:!0}:{},...t.face,teeth:t.face?.teeth??!1,tongue:t.face?.tongue??!1}}}function E5(t,e,n,s){const{point:i,facing:o}=Dn(t,[e,n,s]);return{point:i,facing:o}}const hl=t=>t.rest[1]<-.5,A5=.3;function P5(t,e,n){return t.figure==="stick"?hl(e)?n.slice(0,3):n:hl(e)&&n.length>=3?on(n[0],n[1],n[2],A5):n.length===3?on(n[0],n[1],n[2],1):n}function Js(t,e){const n=t.plan.id==="human"?{...ut,...e}:e;return Ao(t,n,Ha(t.plan,n,{height:t.height,contact:t.contact}))}function Ao(t,e,n){const s={},i={},o={},r=.01*t.height;t.plan.chains.forEach(f=>{const p=n.chains[f.id];s[f.id]=p.points;const g=p.depths.reduce((k,y)=>k+y,0)/p.depths.length,m=f.parent?n.chains[f.parent]:void 0,w=m?m.depths[f.at??m.depths.length-1]:n.hipDepth,v=g-w;o[f.id]=Math.abs(v)<r?0:v,i[f.id]={points:P5(t,f,p.points),depth:g,order:0}}),i.head={points:[n.head.center],depth:n.head.depth,order:0},o.head=0;const a=[...t.plan.chains.map(f=>f.id),"head"],l=f=>t.body&&f.startsWith("arm.")&&o[f]>=0?1:0,c=[...a].sort((f,p)=>l(f)-l(p)||o[f]-o[p]||a.indexOf(f)-a.indexOf(p));c.forEach((f,p)=>{i[f].order=p});const h={hip:n.hip};for(const[f,[p,g]]of Object.entries(t.plan.landmarks??{})){const m=n.chains[p]?.points;m&&(h[f]=m[Math.min(g,m.length-1)])}const u={};for(const[f,p]of Object.entries(h))u[f]=p.y>=n.groundY-.01*t.height;const d={height:t.height,lineWidth:t.lineWidth,turn:e.turn??0,...n.bodyForward?{bodyForward:n.bodyForward}:{},points:h,chains:s,parts:i,head:n.head,groundY:n.groundY,grounded:u};return t.body&&(d.bodyContours=ud(t.body,d,t.plan)),{skeleton:n,joints:d,order:c}}function oe(t,e){return Js(t,e).joints}function wf(t,e,n){const{head:s}=n;t.guideEllipse(s.center.x,s.center.y,s.rx*1.03,s.ry*1.03,s.angle);const i=Array.from({length:13},(l,c)=>({x:0,y:-.95+1.9*c/12})),o=Array.from({length:13},(l,c)=>({x:-.95+1.9*c/12,y:.12})),r=St(s,i,{x:0,y:0});r.facing>0&&t.guide(r.points),t.guide(St(s,o,{x:0,y:.12}).points),t.guide(n.chains.spine??[]);const a=e.lineWidth*.9;for(const l of["shoulder.left","shoulder.right","elbow.left","elbow.right","hip.left","hip.right","knee.left","knee.right"]){const c=n.points[l];c&&t.guideEllipse(c.x,c.y,a,a,0)}}function kf(t,e,n,s,i,o){const r=n.lineWidth;if(n.body&&n.skin==="none"&&(e=Cs(t,e)),i==="head"){const{head:f}=s;let p;const g=()=>p??=md(f,n.face),m=n.skin==="none"?null:n.skin;n.face.projection==="volume"||n.face.shape==="angular"?e.shape(g(),m,r):e.ellipse(f.center.x,f.center.y,f.rx,f.ry,f.angle,m,r),n.body&&n.skin!=="none"&&e.look==="clean"&&yu(t,g(),f.center,n.body.shading),b5(t,e,n.head,f,o,{lineWidth:r,skin:n.skin,face:n.face,faceUnderHair:!!n.body},()=>{e.look!=="silhouette"&&(t.save(),n.body&&(t.beginPath(),g().forEach((w,v)=>v?t.lineTo(w.x,w.y):t.moveTo(w.x,w.y)),t.closePath(),t.clip()),Fk(e,f,o,r,{...n.face,skin:n.skin==="none"?"#ffffff":n.skin},t),t.restore())});return}const a=n.plan.chains.find(f=>f.id===i),l=s.chains[i],c=s.parts[i].points;if(n.body&&gd(t,e,n.body,s,i)){if(i.startsWith("leg.")&&gd(t,e,n.body,s,i.replace("leg.","foot.")),i.startsWith("arm."))if(n.hands==="cartoon")Mf(t,e,n,l,i.endsWith(".left")?"left":"right",o);else{const f=l.at(-1);e.ellipse(f.x,f.y,n.height*.014,n.height*.014,0,n.skin==="none"?null:n.skin,r)}return}if(n.figure==="stick"){if(i==="neck")return;const f=i==="spine"?[...l,...s.chains.neck?.slice(1)??[]]:c;e.line(f,r);return}const h=(f,p)=>[a.bones[f].width[0]*r,a.bones[p].width[1]*r];if(hl(a)){const[f,p]=h(0,1);if(e.limb(c,f,p),a.bones.length>=3)e.limb([l[2],l[3]],a.bones[2].width[0]*r,a.bones[2].width[1]*r);else if(n.hands==="cartoon"&&i.startsWith("arm."))Mf(t,e,n,l,i.endsWith(".left")?"left":"right",o);else{const g=l[l.length-1];e.dot(g.x,g.y,r*.62)}return}if(i==="spine"){const f=s.points["hip.left"],p=s.points["hip.right"];f&&p&&Math.hypot(f.x-p.x,f.y-p.y)>.5&&e.limb([f,p],r*1.3,r*1.3);const[g,m]=h(0,a.bones.length-1);e.limb(c,g,m);const w=s.points["shoulder.left"],v=s.points["shoulder.right"];w&&v&&Math.hypot(w.x-v.x,w.y-v.y)>.5&&e.limb(on(w,l[l.length-1],v,1,10),r*1.15,r*1.15);return}const[u,d]=h(0,a.bones.length-1);e.limb(c,u,d)}function vf(t,e){const n=`hand.${e}.`,s={};for(const[r,a]of Object.entries(t))r.startsWith(n)&&(s[r.slice(n.length)]=a);const i=t.turn??0,o=e==="right"?1-i:1+i;return{...Pt,...s,turn:o+(s.turn??0)}}function Mf(t,e,n,s,i,o){const r=s[s.length-1],a=s[s.length-2],l=Math.atan2(r.x-a.x,-(r.y-a.y))*180/Math.PI;Vi(t,r,vf(o,i),{size:n.handSize*n.height,side:i,angle:l,pen:e,skin:n.skin==="none"&&!n.body?"#ffffff":n.skin,fingers:n.handStyle==="natural"?5:4,plump:n.handStyle==="natural"?1.15:1.6,lineWidth:n.lineWidth*(n.body?.65:.3),connected:!!n.body,shading:n.body?.shading,nails:n.body?!1:void 0})}function Sf(t,e,n,s=0){const i=e.plan.id==="human"?{...ut,...n}:n;ul(t,e,i,Js(e,i),s)}function Po(t,e){const n=e/t.height;return{...t,height:e,lineWidth:t.lineWidth*n}}function $5(t,e,n,s){const i=t.plan.id==="human"?{...ut,...e}:e,o=fo(t.plan,i,{height:s.height,contact:t.contact},n);return Ao(Po(t,o.height),i,o).joints}function I5(t,e,n,s,i){const o=e.plan.id==="human"?{...ut,...n}:n,r=fo(e.plan,o,{height:i.height,contact:e.contact},s),a=Po(e,r.height);ul(t,a,o,Ao(a,o,r),i.time??0)}function xf(t,e,n,s){const i=t.plan.id==="human"?{...ut,...e}:e,o=fo(t.plan,i,{height:s.height,contact:t.contact},n),r=Po(t,o.height),{joints:a,order:l}=Ao(r,i,o),c=o.height/s.height,h=l.map(p=>(a.parts[p]?.depth??0)/c),u=l.filter(p=>p==="spine"||p.startsWith("leg.")),d=Math.max(...u.map(p=>a.parts[p].depth/c)),f=Math.max(...u.map(p=>a.parts[p].order));return l.map((p,g)=>({part:p,depth:h[g],...r.body?{sortDepth:p.startsWith("arm.")&&g>f?Math.max(h[g],d):h[g]}:{},draw(m,w=0){const v=_s(m,{look:r.look,ink:r.ink,lineWidth:r.lineWidth,seed:Xt(`${r.seed}:${p}`),time:w,pencil:r.pencil}),k=T=>{T&&(m.save(),T(m,a,v,w,i),m.restore())};m.save(),m.lineCap="round",m.lineJoin="round",g===0&&(r.look==="pencil"&&r.pencil.construction!==!1&&wf(v,r,a),k(r.layers.behind),tf(m,r.body&&r.skin==="none"?Cs(m,v):v,r.head,a.head,i,{lineWidth:r.lineWidth,skin:r.skin,face:r.face}));const y=r.layers.parts?.[p];k(y?.under),m.save(),y?.clip?.(m,a,v,w,i),kf(m,v,r,a,p,i),m.restore(),k(y?.over),g===l.length-1&&(ef(m,v,r.head,a.head,i,{lineWidth:r.lineWidth,skin:r.skin}),k(r.layers.front)),m.restore()}}))}function ul(t,e,n,s,i,o){const{joints:r}=s,a=o?s.order.filter(h=>o.has(h)):s.order,l=_s(t,{look:e.look,ink:e.ink,lineWidth:e.lineWidth,seed:e.seed,time:i,pencil:e.pencil}),c=h=>{h&&(t.save(),h(t,r,l,i,n),t.restore())};t.save(),t.lineCap="round",t.lineJoin="round",!o&&e.look==="pencil"&&e.pencil.construction!==!1&&wf(l,e,r),o||c(e.layers.behind),tf(t,e.body&&e.skin==="none"?Cs(t,l):l,e.head,r.head,n,{lineWidth:e.lineWidth,skin:e.skin,face:e.face});for(const h of a){const u=e.layers.parts?.[h];c(u?.under),t.save(),u?.clip?.(t,r,l,i,n),kf(t,l,e,r,h,n),t.restore(),c(u?.over)}ef(t,l,e.head,r.head,n,{lineWidth:e.lineWidth,skin:e.skin}),o||c(e.layers.front),t.restore()}function O5(t,e,n,s){const i=e.plan.id==="human"?{...ut,...n}:n,o=Js(e,i).joints.head.rx,r=Po(e,e.height*s.radius/Math.max(1e-6,o)),a=Js(r,i);t.save(),t.translate(s.x-a.joints.head.center.x,s.y-a.joints.head.center.y),ul(t,r,i,a,s.time??0,new Set(["head"])),t.restore()}function dl(t,e,n){const s={...t};for(const[i,o]of Object.entries(e)){const r=t[i]??o;s[i]=r+(o-r)*n}return s}function Se(t,e,n,s){const i=t.plan.id==="human"?{...ut,...e}:e;let o;if(Array.isArray(s))o=s;else{const{skeleton:r}=Js(t,i),a=Ha(t.plan,{...i,roll:0},{height:t.height,contact:"none"}),l=(i.roll??0)*Math.PI/180,c=s.x-r.hip.x,h=s.y-r.hip.y,u=a.hip.x+c*Math.cos(-l)-h*Math.sin(-l),d=a.hip.y+c*Math.sin(-l)+h*Math.cos(-l),f=Math.PI/2*(i.turn??0),p=s.depth??r.chains[n].depths[r.chains[n].depths.length-1],g=Math.cos(f),m=Math.sin(f);o=[u*g-p*m,-d,u*m+p*g]}return mo(t.plan,i,n,o,{height:t.height})}const Tf=new Set(["walk","walking","gait"]);function $o(t,e=ut,n){let s={...e};for(const[o,r]of Object.entries(t))typeof r=="number"&&!Tf.has(o)&&(s[o]=r);const i=Math.max(0,Math.min(1,typeof t.walking=="number"?t.walking:0));if(i>0){const o=typeof t.gait=="string"?t.gait:void 0,r=o?n?.[o]??o:void 0,a=el(r,typeof t.walk=="number"?t.walk:0,s);s=Object.fromEntries(Object.keys({...s,...a}).map(l=>[l,(s[l]??0)+((a[l]??0)-(s[l]??0))*i]))}return s}function _5(t){const{character:e}=t,n=e.height*.8,s=e.height,i=e.plan.id==="human"?ut:{};return{type:"custom",x:t.x-n/2,y:t.y-s,width:n,height:s,props:{...i,...t.pose},character:e,...t.gaits?{gaits:t.gaits}:{},draw(o,r,a){o.translate(n/2,s),Sf(o,e,$o(r.props??{},i,t.gaits),a)}}}function Ef(t,e,n){const s=o=>({x:o.x+e,y:o.y+n}),i=o=>Object.fromEntries(Object.entries(o).map(([r,a])=>[r,a.map(s)]));return{...t,...t.bodyContours?{bodyContours:Object.fromEntries(Object.entries(t.bodyContours).map(([o,r])=>[o,{...r,outline:r.outline.map(s),samples:r.samples.map(a=>({...a,center:s(a.center),left:s(a.left),right:s(a.right)}))}]))}:{},points:Object.fromEntries(Object.entries(t.points).map(([o,r])=>[o,s(r)])),chains:i(t.chains),parts:Object.fromEntries(Object.entries(t.parts).map(([o,r])=>[o,{...r,points:r.points.map(s)}])),head:{...t.head,center:s(t.head.center)},groundY:t.groundY+n}}function C5(t,e,n){const s=t.character;if(!s)throw new Error("characterAt: the target was not made by characterTarget");const i={...t.props};let o=0,r=0;for(const[c,h]of e.state?.values.get(n)??[])c==="x"||c==="motionPathX"?o=typeof h=="number"?h:o:c==="y"||c==="motionPathY"?r=typeof h=="number"?h:r:(typeof h=="number"||Tf.has(c))&&(i[c]=h);const a=$o(i,s.plan.id==="human"?ut:{},t.gaits),l=oe(s,a);return{pose:a,joints:Ef(l,t.x+o+t.width/2,t.y+r+t.height)}}function fl(t,e=ut){const n=[];return t.forEach((s,i)=>{const o=i===0?e:n[i-1],r=typeof s.pose=="string"?ce[s.pose]:void 0;n.push(r?{...r,turn:o.turn??0}:{...o,...s.pose})}),n}function H5(t,e,n=ut){const s=fl(e,n);return Object.keys(n).filter(o=>s.some(r=>(r[o]??n[o])!==n[o])).map(o=>({id:`${t}-${o}`,target:t,property:o,keyframes:e.map((r,a)=>({time:r.time,value:s[a][o]??n[o],...r.easing?{easing:r.easing}:{}}))}))}const Io=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],be=(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],gl=t=>Math.hypot(...t),Af=t=>Oo(t,1/(gl(t)||1)),_o=t=>({...ut,...t}),pl=t=>qs(t.character.plan,_o(t.pose),{height:t.character.height,contact:t.character.contact});function gn(t,e,n){return Io(t.position,pl(t).chains[e][n])}function Pf(t,e,n){const s=_o(t.pose),i=pl(t).hip,o=zs(t.character.plan,s,t.character.height),r=be(be(n,t.position),i),a=Bs(r,(s.roll??0)*Math.PI/180),l=Io(o.root,Zt(a,-(s.turn??0)*Math.PI/2));return mo(t.character.plan,s,e,l,{height:t.character.height})}function $f(t,e,n,s="toe"){const i=`leg.${e}`,o=s==="toe"?3:2;let r={...t,pose:_o(t.pose),position:[...t.position]};for(let l=0;l<6;l++){const c=pl(r).chains[i],h=be(c[o],c[2]);r={...r,pose:Pf(r,i,be(n,h))};const u=gn(r,i,o);r.position[1]+=n[1]-u[1]}const a=gl(be(gn(r,i,o),n));return{...r,reached:a<t.character.height*.002}}function If(t,e){const n=gn(t,`arm.${e}`,2),s=gn(t,`arm.${e}`,1);return Io(n,Oo(Af(be(n,s)),t.character.lineWidth*.5))}function R5(t,e,n={}){const s=Math.min(t.character.height,e.character.height),i=n.length??s*.22;if(!(i>0)||!Number.isFinite(i))throw new Error("meetDandiya: stick length must be positive and finite");const o=n.point??[(t.position[0]+e.position[0])/2,Math.max(t.position[1],e.position[1])+s*.62,(t.position[2]+e.position[2])/2],r=(c,h)=>{const u=Af([o[0]-c.position[0],s*.2,o[2]-c.position[2]]),d=be(o,Oo(u,i));let f=_o(c.pose);for(let g=0;g<6;g++){const m={...c,pose:f},w=gn(m,`arm.${h}`,2);f=Pf(m,`arm.${h}`,be(d,be(If(m,h),w)))}for(const[g,m]of Object.entries(Ct.hold))f[`hand.${h}.${g}`]=m;const p=If({...c,pose:f},h);return{pose:f,stick:{grip:p,tip:Io(p,Oo(u,i))}}},a=r(t,n.sideA??"right"),l=r(e,n.sideB??"right");return{a:a.pose,b:l.pose,sticks:[a.stick,l.stick],point:o,reached:[a.stick,l.stick].every(c=>gl(be(c.tip,o))<s*.002)}}function Of(t,e){const n=e.count??8,s=e.beatsPerTurn??32;if(!Number.isFinite(t)||!Number.isFinite(e.radius)||e.radius<=0||!Number.isInteger(n)||n<1||!Number.isFinite(s)||s<=0)throw new Error("danceCircleAt: finite beat, positive radius/beatsPerTurn and a positive integer count are required");const i=e.center??[0,0],o=e.direction??1;if(i.length!==2||!i.every(Number.isFinite)||!Number.isFinite(e.angle??0)||!Number.isFinite(e.spins??0)||![1,-1].includes(o)||e.facing!==void 0&&!(typeof e.facing=="number"?Number.isFinite(e.facing):["inward","outward","tangent"].includes(e.facing)))throw new Error("danceCircleAt: center, angle, spins and facing must be finite; direction is 1 or -1");const r=e.character??Vs({height:1.7}),a=e.style??"garba",l=(h,u)=>{const d=(e.angle??0)+360*u/n+o*360*h/s,f=d*Math.PI/180,p=e.facing??"inward",g=(typeof p=="number"?p:d+(p==="inward"?180:p==="tangent"?o*90:0))+(e.spins??0)*360*h/s,m=Ys(a,h,{...e.pose,turn:g/90});return{character:r,position:[i[0]+e.radius*Math.sin(f),0,i[1]+e.radius*Math.cos(f)],pose:m.pose,heading:g,strike:m.strike}},c=Ys(a,t).contact;return Array.from({length:n},(h,u)=>{const d=l(t,u);if(e.plantFeet===!1)return{...d,planted:!1};const f=l(c.start,u),p=gn(f,`leg.${c.side}`,3),g=$f(d,c.side,p);return{...d,pose:dl(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 L5(t,e){if(e.count!==void 0&&e.count!==t.length)throw new Error("danceCircleTracks: count must match targets.length");const n=e.bpm??120,s=e.samplesPerBeat??16;if(!t.length||![n,e.beats,s].every(l=>Number.isFinite(l)&&l>0))throw new Error("danceCircleTracks: targets and positive finite bpm, beats and samplesPerBeat are required");if(!Number.isFinite(e.start??0))throw new Error("danceCircleTracks: start must be finite");const i=Math.max(1,Math.ceil(e.beats*s)),o=Array.from({length:i+1},(l,c)=>({time:(e.start??0)+e.beats*c/i*6e4/n,members:Of(e.beats*c/i,{...e,count:t.length})})),r=o.some(l=>l.members.some(c=>c.pose.roll!==0)),a=new Set(["x","y","z","rotateY",...r?["turn","roll"]:[]]);return t.flatMap((l,c)=>{const h=o.map(u=>{const d=u.members[c],{turn:f,...p}=d.pose;return{time:u.time,pose:{...r?d.pose:p,x:d.position[0],y:d.position[1],z:d.position[2],rotateY:r?0:d.heading}}});return Object.keys(h[0].pose).filter(u=>a.has(u)||h.some(d=>d.pose[u]!==(e.pose?.[u]??ut[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 Co=t=>Math.min(1,Math.max(0,t));function N5(t){const e={...ht,turn:t.view},n=[];for(const s of t.keys){const i=n[n.length-1],o=!i||s.reset?e:i.pose;n.push({at:s.at,pose:{...o,...s.pose},easing:s.easing})}return n}function F5(t){return t-W5*Math.sin(2*Math.PI*t)/(2*Math.PI)}const W5=.5;function D5(t,e){if(!(e<=t.takeoff||e>=t.landing))return(e-t.takeoff)/(t.landing-t.takeoff)}function _f(t,e){const n=typeof t=="string"?Zs[t]:t,s=N5(n),i=Co(e);let o=0;for(let u=0;u<s.length;u++)s[u].at<=i&&(o=u);const r=s[o],a=s[Math.min(o+1,s.length-1)],l=a.at>r.at?(i-r.at)/(a.at-r.at):0,c=Wn(r.pose,a.pose,Lt(a.easing??"ease-in-out")(Co(l))),h=D5(n,i);return h===void 0?{...c,spin:0,rise:0}:{...c,spin:n.spin*F5(h),rise:4*n.height*h*(1-h)}}function Cf(t,e,n){const s=typeof t=="string"?Zs[t]:t,i=Co(e),o=Co((i-s.takeoff)/(s.landing-s.takeoff));return s.travel*n*o}function B5(t,e,n={}){const s=typeof e=="string"?Zs[e]:e,i=n.start??0,o=n.duration??s.duration,r=n.samples??48,a=Array.from({length:r+1},(h,u)=>{const d=u/r;return{time:i+d*o,progress:d,pose:_f(s,d)}}),c=Object.keys(ht).filter(h=>a.some(u=>u.pose[h]!==ht[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*Cf(s,u.progress,n.height)}))})}return c}const z5={leftHip:-55,leftKnee:-95,rightHip:55,rightKnee:95,leftShoulder:45,rightShoulder:-45,leftElbow:10,rightElbow:-10,lean:22,stretch:.94,headTilt:6},q5={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},Ho={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},Y5={leftHip:-22,leftKnee:-30,rightHip:22,rightKnee:30,leftAnkle:10,rightAnkle:10,leftShoulder:-125,rightShoulder:125,leftElbow:0,rightElbow:0,lean:8,headTilt:0},K5={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 Vn(t,e,n,s,i,o=1300){return{label:t,view:1,spin:e,height:n,travel:s,takeoff:.27,landing:.8,duration:o,keys:[{at:0,reset:!0},{at:.16,pose:z5},{at:.27,pose:q5,easing:"ease-out-quad"},...i,{at:.76,pose:Y5},{at:.86,pose:K5,easing:"ease-out-quad"},{at:1,reset:!0}]}}const Zs={frontFlip:Vn("Front flip (tuck)",360,.56,.35,[{at:.38,pose:Ho,easing:"ease-out-cubic"},{at:.64,pose:Ho}]),backFlip:Vn("Back flip (tuck)",-360,.58,-.15,[{at:.36,pose:{...Ho,lean:18},easing:"ease-out-cubic"},{at:.64,pose:{...Ho,lean:18}}]),layout:Vn("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:Vn("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:Vn("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:Vn("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 Hf(t,e){const n=Math.min(1,Math.max(0,t.turn??0)),s=1-n,i={...ut,turn:n},o=[{stick:"right",human:"left",s:1},{stick:"left",human:"right",s:-1}];for(const{stick:a,human:l,s:c}of o){const h=t[`${a}Shoulder`],u=t[`${a}Elbow`];i[`arm.${l}.spread`]=h*s,i[`arm.${l}.swing`]=c*h*n,i[`arm.${l}.bend`]=u*s,i[`arm.${l}.elbow`]=c*u*n;const d=t[`${a}Hip`],f=t[`${a}Knee`],p=s+c*n;i[`leg.${l}.rotate`]=90*s,i[`leg.${l}.spread`]=0,i[`leg.${l}.swing`]=d*p,i[`leg.${l}.knee`]=f*p,i[`leg.${l}.ankle`]=-(t[`${a}Ankle`]??0),i[`leg.${l}.toeOut`]=(t[`${a}FootOut`]??0)*j5,i[`eye.${l}`]=t[`${a}Eye`],i[`brow.${l}`]=t[`${a}Brow`],e&&Object.assign(i,X5(l,e[a]??Pt,t[`${a}Wrist`]??0,n))}const r=t.bend??0;i.lean=t.lean*n,i.bend=r*n,i.side=(t.lean+r*.5)*s,i["head.tilt"]=(t.headTilt+r*.5)*s,i["head.nod"]=t.headTilt*n;for(const a of["mouth","smile","mouthWidth","blink","browTilt","lookX","lookY","stretch"])i[a]=t[a];return i.lift=t.rise??0,i.roll=t.spin??0,i}const j5=70;function X5(t,e,n,s){const i=t==="right"?1-s:1+s,o={};for(const r of Object.keys(Pt))o[`hand.${t}.${r}`]=e[r]??Pt[r];return o[`hand.${t}.turn`]=(e.turn??0)-i,o[`hand.${t}.roll`]=(e.roll??0)+n,o}class Rf{positions=[];normals=[];indices=[];vertex(e,n,s,i,o,r){const a=Math.hypot(i,o,r)||1;return this.positions.push(e,n,s),this.normals.push(i/a,o/a,r/a),this.positions.length/3-1}triangle(e,n,s){this.indices.push(e,n,s)}quad(e,n,s,i){this.indices.push(e,n,s,e,s,i)}build(){return{positions:this.positions,normals:this.normals,indices:this.indices}}}function G5(t){const e=new Map,n=[];for(let i=0;i<t.positions.length/3;i++){const o=[0,1,2].map(r=>Math.round(t.positions[i*3+r]*1e6)).join(",");e.has(o)||e.set(o,i),n.push(e.get(o))}const s=new Map;for(let i=0;i<t.indices.length/3;i++)for(let o=0;o<3;o++){const r=n[t.indices[i*3+o]],a=n[t.indices[i*3+(o+1)%3]];if(r===a)continue;const l=r<a?`${r}-${a}`:`${a}-${r}`,c=s.get(l);c?c.faces.push(i):s.set(l,{a:Math.min(r,a),b:Math.max(r,a),faces:[i]})}return[...s.values()]}const ml=Math.PI*2;function U5(t,e=16){const n=new Rf,s=Math.max(6,Math.round(e)),i=Math.max(3,Math.round(s/2)),o=[];for(let r=0;r<=i;r++){const a=r/i*Math.PI,l=[];for(let c=0;c<=s;c++){const h=c/s*ml,u=Math.sin(a)*Math.sin(h),d=Math.cos(a),f=Math.sin(a)*Math.cos(h);l.push(n.vertex(u*t,d*t,f*t,u,d,f))}o.push(l)}for(let r=0;r<i;r++)for(let a=0;a<s;a++){const l=o[r][a],c=o[r+1][a],h=o[r+1][a+1],u=o[r][a+1];r>0&&n.triangle(l,c,u),r<i-1&&n.triangle(c,h,u)}return n.build()}function Lf(t,e,n,s,i){const o=t.vertex(0,n,0,0,s,0),r=Array.from({length:i},(a,l)=>{const c=l/i*ml;return t.vertex(Math.sin(c)*e,n,Math.cos(c)*e,0,s,0)});for(let a=0;a<i;a++){const l=r[a],c=r[(a+1)%i];s===1?t.triangle(o,l,c):t.triangle(o,c,l)}}function Nf(t,e,n=24){const s=new Rf,i=Math.max(6,Math.round(n)),o=e/2,r=-e/2,a=h=>Array.from({length:i+1},(u,d)=>{const f=d/i*ml;return s.vertex(Math.sin(f)*t,h,Math.cos(f)*t,Math.sin(f),0,Math.cos(f))}),l=a(r),c=a(o);for(let h=0;h<i;h++)s.quad(l[h],l[h+1],c[h+1],c[h]);return Lf(s,t,o,1,i),Lf(s,t,r,-1,i),s.build()}function Ro(t){const e=Array.from({length:t.indices.length/3},()=>[]);for(const n of G5(t))for(const s of n.faces){const i=n.faces.find(o=>o!==s)??-1;e[s].push({a:n.a,b:n.b,across:i})}return{...t,faceEdges:e}}const yl=new Map;function V5(t){const e=yl.get(t);if(e)return e;let n=[1,1,1];const s=t.trim().replace("#","");if(t.trim().startsWith("#")&&(s.length===3||s.length===6)){const i=s.length===3?s.split("").map(o=>o+o).join(""):s;n=[0,2,4].map(o=>Number.parseInt(i.slice(o,o+2),16)/255)}else{const i=t.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/);i&&(n=[Number(i[1])/255,Number(i[2])/255,Number(i[3])/255])}return yl.size<512&&yl.set(t,n),n}Qe([-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 Ff(t,e,n){const s=[0,0,0];for(const i of n){const o=V5(i.color);let r;if(i.light==="ambient")r=i.intensity;else if(i.light==="directional")r=i.intensity*Math.max(0,-Re(e,i.direction));else{const a=On(i.position,t),l=Hi(a),c=l>0?_n(a,1/l):e,h=i.range?Math.max(0,1-l/i.range)**2:1;if(r=i.intensity*Math.max(0,Re(e,c))*h,i.light==="spot"){const u=Math.cos(i.angle*Math.PI/180),d=Math.cos(i.angle*.8*Math.PI/180);r*=J5(u,d,-Re(c,i.direction))}}s[0]+=o[0]*r,s[1]+=o[1]*r,s[2]+=o[2]*r}return s}function Wf(t,e){return t?Math.min(1,Math.max(0,(e-t.near)/(t.far-t.near))):0}function bl(t,e,n={}){t.save(),Z5(t,e,n),t.restore()}function Z5(t,e,n){const s=wl(e,n);n.shadow!==!1&&kl(t,e,n);for(const i of e.under)Df(t,i,s,n);if(n.rider){if(t.save(),e.openings.length>0){t.beginPath();for(const i of e.openings){t.moveTo(i[0].x,i[0].y);for(const o of i.slice(1))t.lineTo(o.x,o.y);t.closePath()}t.clip("nonzero")}n.rider(t),t.restore()}for(const i of e.over)Df(t,i,s,n)}function Df(t,e,n,s){const i=s.loose?.[e.part.id];if(!i){Sl(t,e,n,s);return}if(i.opacity<=0)return;const o=e.faces.flatMap(c=>c.points);if(o.length===0)return;const r=o.map(c=>c.x),a=o.map(c=>c.y),l={x:(Math.min(...r)+Math.max(...r))/2,y:(Math.min(...a)+Math.max(...a))/2};t.save(),t.globalAlpha*=Math.min(1,i.opacity),t.translate(l.x+i.x,l.y+i.y),t.rotate(i.rotate*Math.PI/180),t.translate(-l.x,-l.y),Sl(t,e,n,s),t.restore()}function wl(t,e={}){return e.lineWidth??Math.max(1.3,t.sizePx*.022)}function kl(t,e,n={}){e.shadow.opacity<=0||e.shadow.points.length<3||(t.save(),t.globalAlpha=e.shadow.opacity,Lo(t,e.shadow.points,n.ink??"#26262b",!1),t.restore())}function Q5(t,e,n,s={}){t.save(),Sl(t,e,n,s),t.restore()}function Bf(t,e,n,s={}){const i=s.style==="stick",o=e.flatMap(h=>{if(i&&h.part.solidOnly)return[];const u=h.part.layer??0;return i&&h.spine?[{depth:h.depth,layer:u,part:h}]:h.faces.map(d=>({depth:d.depth,layer:u,part:h,face:d}))}),r=new Map;for(const h of o){const u=h.face?.normal;if(!h.face?.center||!u)continue;const d=Math.abs(u[0])>=Math.abs(u[1])&&Math.abs(u[0])>=Math.abs(u[2])?0:Math.abs(u[1])>=Math.abs(u[2])?1:2,f=d*2+(u[d]<0?1:0);r.set(f,[...r.get(f)??[],h])}for(const h of r.values())for(const u of h){const{center:d,normal:f}=u.face;for(const p of h){if(p.part.part.id===u.part.part.id)continue;const g=p.face;if(g.normal[0]*f[0]+g.normal[1]*f[1]+g.normal[2]*f[2]<=.8)continue;const w=g.normal[0]*(d[0]-g.center[0])+g.normal[1]*(d[1]-g.center[1])+g.normal[2]*(d[2]-g.center[2]);w>-zf/5&&w<zf&&(u.layer=Math.max(u.layer,p.layer),u.depth=Math.max(u.depth,p.depth+1e-6))}}o.sort((h,u)=>h.layer-u.layer||h.depth-u.depth);const a=new Map,l=h=>{let u=a.get(h.part.id);return u||a.set(h.part.id,u=vl(t,h,n,s)),u};t.save();const c=t.globalAlpha;for(const{part:h,face:u}of o){t.globalAlpha=c*h.opacity;const d=l(h);if(!u)d.line(h.spine,n*1.15);else{const f=i?qf(h,s):u.light?tv(h,u,s):Ml(h);f&&(!i&&s.look==="silhouette"?d.shape(u.points,f,0):Lo(t,u.points,i||u.light?f:No(f,u.tone),!0,h.cut?1.6:.8));const p=(h.part.outline??1)*n;if(p>0)for(const g of u.edges??[])g.length>1&&d.line(g,p);for(const g of u.marks??[])d.line(g,n*.7)}}t.restore()}const zf=.05;function vl(t,e,n,s){return _s(t,{look:s.look??"clean",ink:e.part.ink??s.ink??"#26262b",lineWidth:n,seed:Xt(`${s.seed??0}:${e.part.id}`),time:s.time??0,pencil:{construction:!1,rubbedOut:0,...s.pencil}})}function Ml(t){const{part:e}=t;return e.glow&&t.glow>0&&e.fill?El(e.fill,e.glow.color,t.glow):e.fill}function tv(t,e,n){const{part:s}=t;if(!s.fill)return;const i=Tl(s.fill,e.light,e.fog??0,n.fog);return s.glow&&t.glow>0?El(i,s.glow.color,t.glow):i}function qf(t,e){const n=Ml(t);return n&&(nv(n)||t.glow>0)?n:e.paper??"#fbf8ef"}function Sl(t,e,n,s){e.opacity<1?(t.save(),t.globalAlpha*=e.opacity,Yf(t,e,n,s),t.restore()):Yf(t,e,n,s)}function Yf(t,e,n,s){if(s.style==="stick")return ev(t,e,n,s);const{part:i}=e,o=vl(t,e,n,s),r=Ml(e),a=s.look==="silhouette";for(const c of e.faces)r&&(a?o.shape(c.points,r,0):Lo(t,c.points,No(r,c.tone)));const l=(i.outline??1)*n;if(l>0)for(const c of e.edges)c.length>1&&o.line(c,l);for(const c of e.marks)o.line(c,n*.7)}function ev(t,e,n,s){const{part:i}=e;if(i.solidOnly)return;const o=vl(t,e,n,s);if(e.spine){o.line(e.spine,n*1.15);return}const r=qf(e,s);for(const l of e.faces)Lo(t,l.points,r);const a=(i.outline??1)*n;if(a>0)for(const l of e.edges)l.length>1&&o.line(l,a);for(const l of e.marks)o.line(l,n*.7)}function nv(t){const e=Jn(t);return e?(.299*e[0]+.587*e[1]+.114*e[2])/255<.3:!1}function Lo(t,e,n,s=!0,i=.8){t.fillStyle=n,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let o=1;o<e.length;o++)t.lineTo(e[o].x,e[o].y);t.closePath(),t.fill(),s&&(t.strokeStyle=n,t.lineWidth=i,t.lineJoin="round",t.stroke())}function Jn(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 xl=t=>`#${t.map(e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0")).join("")}`;function No(t,e){const n=Jn(t);return n?xl(e>=1?n.map(s=>s+(255-s)*(e-1)*2):n.map(s=>s*e)):t}function Tl(t,e,n,s){const i=Jn(t);if(!i)return t;let o=i.map((a,l)=>a*e[l]);const r=s?Jn(s):void 0;return r&&n>0&&(o=o.map((a,l)=>a+(r[l]-a)*n)),xl(o)}function El(t,e,n){const s=Jn(t),i=Jn(e);return!s||!i?n<.5?t:e:xl(s.map((o,r)=>o+(i[r]-o)*n))}const sv=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),iv=new Set(["walk","walking","gait"]),Kf=t=>typeof t=="number"?t:void 0,ov=1.7;function rv(t,e,n){const s=Array.from({length:24},(i,o)=>{const r=o/24*Math.PI*2,a=e.toView([Math.cos(r)*n,0,Math.sin(r)*n*.8]);return a[2]<-.001?e.toScreen(a):null});s.some(i=>i===null)||(t.beginPath(),s.forEach((i,o)=>o===0?t.moveTo(i.x,i.y):t.lineTo(i.x,i.y)),t.closePath(),t.fillStyle="rgba(0, 0, 0, 0.22)",t.fill())}function av(t){const e=Re([0,1,0],t);if(e>.999999)return Ri();if(e<-.999999)return ae(ee([1,0,0],180));const n=Ci([0,1,0],t);return ae(ee(n,Math.acos(e)*180/Math.PI))}function lv(t,e,n,s,i){const o=t.solid??{},r=o.outline===!1?void 0:o.outline??{width:2,color:"#0f172a"},a={color:o.color??"#475569",shading:o.shading??"toon",outline:r},l={color:o.skin??"#f2c49b",shading:o.shading??"toon",outline:r},c={color:"#0f172a",shading:"unlit"},h=s.height*.034,u=[],d=(k,y,T)=>u.push({mesh:k,world:Ot(i,y),material:T}),f=(k,y,T)=>d(e.sphere,jr(k,[0,0,0,1],[y,y,y]),T);for(const k of n.chains){const y=s.chains[k.id],T=k.id==="spine"?1.9:1;k.bones.forEach(($,M)=>{const x=y[M],S=y[M+1],E=Kr(x,S),[P,A]=$.width??[1,1],I=h*T*(P+A)/2;if(E>1e-6){const _=Qh(x,S,.5),N=av(Qe(On(S,x)));d(e.cylinder,Ot(tn(_),Ot(N,en([I,E,I]))),a)}f(x,h*T*P,a),f(S,h*T*A,a)}),k.id.startsWith("arm.")&&f(y[y.length-1],h*1.5,l)}const{center:p,rx:g,ry:m,axes:w}=s.head,v=[...w[0],0,...w[1],0,...w[2],0,...p,1];d(e.sphere,Ot(v,en([g,m,g])),l);for(const k of[-1,1]){const y=Qe([k*.36,.15,.92]),T=_i(p,_i(_i(_n(w[0],y[0]*g*1.04),_n(w[1],y[1]*m*1.04)),_n(w[2],y[2]*g*1.04))),$=[...w[0],0,...w[1],0,...w[2],0,...T,1];d(e.sphere,Ot($,en([g*.11,m*.14,g*.03])),c)}return u}const cv={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:Vs({...t.character,height:1}),cylinder:Ro(Nf(1,1,16)),sphere:Ro(U5(1,20))}},resolve({object:t,prepared:e,values:n,world:s,camera:i,lights:o=[],fog:r,toScreen:a}){const l=t,c=e,h=c.who;let u={...ut,...l.pose};for(const[x,S]of n)typeof S=="number"&&!sv.has(x)&&!iv.has(x)&&(u[x]=S);const d=Math.max(0,Math.min(1,Kf(n.get("walking"))??l.walking??0));if(d>0){const x=typeof n.get("gait")=="string"?n.get("gait"):l.gait,S=el(x,Kf(n.get("walk"))??0,u);u=Object.fromEntries(Object.keys({...u,...S}).map(E=>[E,(u[E]??0)+((S[E]??0)-(u[E]??0))*d]))}const f=l.height??ov,p=Ot(i.view,s),g={toView:x=>Gt(p,x),toScreen:x=>a(x)},w=-g.toView([0,f/2,0])[2];if(w<=i.near)return null;const v=l.shadow===!1?[]:[{depth:w+f,draw:x=>rv(x,g,f*.18)}];if(l.look==="solid"){const x=qs(h.plan,u,{height:f,contact:h.contact});return{meshes:lv(l,c,h.plan,x,s),drawables:v}}const k=Gt(s,[0,f*.6,0]),y=Qe(On(i.position,k)),T=Ff(k,y,o).map(x=>Math.min(1,x));let $=h;if(o.length>0&&h.skin!=="none"){const x=Tl(h.skin,T,Wf(r,Kr(k,i.position)),r?.color);$={...h,skin:x,...h.body?{body:{...h.body,fill:x}}:{}}}const M=xf($,u,g,{height:f});return{drawables:[...v,...M.map((x,S)=>({depth:-(x.sortDepth??x.depth)-S*1e-6,draw:(E,P)=>x.draw(E,P.time)}))]}}},ze={rest:{mouth:0,mouthWidth:1},a:{mouth:.75,mouthWidth:1.1},e:{mouth:.45,mouthWidth:1.3},i:{mouth:.28,mouthWidth:1.45},o:{mouth:.6,mouthWidth:.7},u:{mouth:.32,mouthWidth:.55},m:{mouth:0,mouthWidth:.9},f:{mouth:.1,mouthWidth:1.05},l:{mouth:.3,mouthWidth:1},c:{mouth:.2,mouthWidth:1}},Qs=1,Fo=.55,jf=.35,hv=1.6,Xf={a:"a",e:"e",i:"i",y:"i",o:"o",u:"u"},Gf={m:"m",b:"m",p:"m",f:"f",v:"f",w:"u",q:"u",l:"l",n:"l",d:"l",t:"l"},Uf={अ:"a",आ:"a",इ:"i",ई:"i",उ:"u",ऊ:"u",ऋ:"i",ए:"e",ऐ:"e",ओ:"o",औ:"o",ऍ:"e",ऑ:"o"},Vf={"ा":"a","ि":"i","ी":"i","ु":"u","ू":"u","ृ":"i","े":"e","ै":"e","ो":"o","ौ":"o","ॅ":"e","ॉ":"o"},uv={प:"m",फ:"m",ब:"m",भ:"m",म:"m",व:"u"},dv="्",Jf="़",fv=t=>t>="क"&&t<="ह",Zf=new Set([".",",","!","?",";",":","…","।","॥","—","-"]);function Qf(t){const e=[],n=Array.from(t.toLowerCase()),s=(i,o)=>{const r=e[e.length-1];r&&r.viseme===i?r.weight+=o*.5:e.push({viseme:i,weight:o})};for(let i=0;i<n.length;i++){const o=n[i],r=n[i+1];if(Zf.has(o))s("rest",hv);else if(/\s/.test(o)){const a=e[e.length-1];a&&a.viseme!=="rest"&&e.push({viseme:"c",weight:jf})}else if((o==="o"||o==="e")&&r===o)s(o==="o"?"u":"i",Qs),i++;else if(o in Xf)s(Xf[o],Qs);else if(o in Gf)s(Gf[o],Fo);else{if(o==="h")continue;if(/[a-z]/.test(o))s("c",Fo);else if(o in Uf)s(Uf[o],Qs);else if(fv(o)){const a=r===Jf?o==="फ"?"f":void 0:uv[o];s(a??"c",Fo);let l=i+1;n[l]===Jf&&l++;const c=n[l];c===dv?i=l:c&&c in Vf?(s(Vf[c],Qs),i=l):(!c||/\s/.test(c)||Zf.has(c)||s("a",Qs*.6),i=l-1)}else(o==="ं"||o==="ँ")&&s("l",Fo*.6)}}for(;e.length>0&&(e[e.length-1].viseme==="rest"||e[e.length-1].weight===jf);)e.pop();return e}function Al(t,e={}){const n=e.fields?.mouth??"mouth",s=e.fields?.mouthWidth??"mouthWidth",i=e.energy??1,o=Qf(t.text),r=[{time:t.start,value:ze.rest.mouth}],a=[{time:t.start,value:ze.rest.mouthWidth}],l=o.reduce((h,u)=>h+u.weight,0),c=t.end-t.start;if(l>0&&c>0){let h=t.start;for(const u of o){const d=c*u.weight/l,f=h+Math.min(d*.4,60);if(f>r[r.length-1].time){const p=ze[u.viseme];r.push({time:f,value:p.mouth*i,easing:"ease-out"}),a.push({time:f,value:1+(p.mouthWidth-1)*Math.min(1.3,i),easing:"ease-out"})}h+=d}}return t.end>r[r.length-1].time&&(r.push({time:t.end,value:ze.rest.mouth,easing:"ease-in-out"}),a.push({time:t.end,value:ze.rest.mouthWidth,easing:"ease-in-out"})),{[n]:r,[s]:a}}function gv(t,e,n={}){const s={};for(const i of[...e].sort((o,r)=>o.start-r.start))for(const[o,r]of Object.entries(Al(i,n))){const a=s[o]??=[],l=a.length>0?a[a.length-1].time:-1/0;a.push(...r.filter(c=>c.time>l))}return Object.entries(s).map(([i,o])=>({id:`${t}-${i}`,target:t,property:i,keyframes:o}))}function Wo(t,e,n,s={}){if(n.length===0)return e;const i=s.fields?.mouth??"mouth",o=s.fields?.mouthWidth??"mouthWidth",r={[i]:ze.rest.mouth,[o]:ze.rest.mouthWidth,...s.rest},a=new It({id:"before-speech",tracks:e}),l=(u,d)=>a.getStateAtTime(d).values.get(t)?.get(u)??r[u],c=[i,o],h=e.filter(u=>u.target!==t||!c.includes(u.property));for(const u of c){const d=e.find(p=>p.target===t&&p.property===u);let f=d?[...d.keyframes]:[{time:0,value:l(u,0)}];for(const p of n){const g=Al(p,s)[u];g[0]={...g[0],value:l(u,p.start)},g[g.length-1]={...g[g.length-1],value:l(u,p.end)},f=[...f.filter(m=>m.time<p.start||m.time>p.end),...g],f.sort((m,w)=>m.time-w.time)}h.push({id:d?.id??`${t}-${u}`,target:t,property:u,keyframes:f})}return h}const ti=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function tg([t,e,n]){const[s,i,o]=[t/2,e/2,n/2];return{vertices:[[-s,-i,-o],[s,-i,-o],[s,i,-o],[-s,i,-o],[-s,-i,o],[s,-i,o],[s,i,o],[-s,i,o]],faces:[{corners:[4,5,6,7],normal:[0,0,1]},{corners:[1,0,3,2],normal:[0,0,-1]},{corners:[5,1,2,6],normal:[1,0,0]},{corners:[0,4,7,3],normal:[-1,0,0]},{corners:[7,6,2,3],normal:[0,1,0]},{corners:[0,1,5,4],normal:[0,-1,0]}]}}const Zn=(t,[e,n,s])=>t==="z"?[e,n,s]:t==="x"?[s,n,e]:[e,s,n];function eg(t,e,n="x",s=20,i=0){const o=[],r=e/2;for(const c of[-r,r])for(let h=0;h<s;h++){const u=Math.PI*2*h/s;o.push(Zn(n,[Math.cos(u)*t,Math.sin(u)*t,c]))}const a=[{corners:Array.from({length:s},(c,h)=>s-1-h),normal:Zn(n,[0,0,-1])},{corners:Array.from({length:s},(c,h)=>s+h),normal:Zn(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:Zn(n,[Math.cos(u),Math.sin(u),0])})}const l=[];if(i>0)for(const c of[-r,r]){const h=o.push(Zn(n,[0,0,c*1.01]))-1;for(let u=0;u<i;u++){const d=Math.PI*2*u/i,f=o.push(Zn(n,[Math.cos(d)*t*.82,Math.sin(d)*t*.82,c*1.01]))-1;l.push([h,f])}}return{vertices:o,faces:a,marks:l,creases:!0}}function ng([t,e,n],s=16){const i=Math.max(4,Math.round(s/2)),o=[[0,e,0]];for(let h=1;h<i;h++){const u=Math.PI*h/i;for(let d=0;d<s;d++){const f=Math.PI*2*d/s;o.push([Math.sin(u)*Math.cos(f)*t,Math.cos(u)*e,Math.sin(u)*Math.sin(f)*n])}}const r=o.push([0,-e,0])-1,a=(h,u)=>1+(h-1)*s+u%s,l=h=>{const u=h.reduce((d,f)=>[d[0]+o[f][0],d[1]+o[f][1],d[2]+o[f][2]],[0,0,0]);return ti([u[0]/(t*t),u[1]/(e*e),u[2]/(n*n)])},c=[];for(let h=0;h<s;h++){const u=[0,a(1,h+1),a(1,h)];c.push({corners:u,normal:l(u)});for(let f=1;f<i-1;f++){const p=[a(f,h),a(f,h+1),a(f+1,h+1),a(f+1,h)];c.push({corners:p,normal:l(p)})}const d=[a(i-1,h),a(i-1,h+1),r];c.push({corners:d,normal:l(d)})}return{vertices:o,faces:c,creases:!1}}const pv=t=>t.reduce((e,[n,s],i)=>{const[o,r]=t[(i+1)%t.length];return e+n*r-o*s},0)/2;function sg(t,e){const n=pv(t)<0?[...t].reverse():t,s=n.length,i=e/2,o=[...n.map(([a,l])=>[i,l,a]),...n.map(([a,l])=>[-i,l,a])],r=[{corners:Array.from({length:s},(a,l)=>s-1-l),normal:[1,0,0]},{corners:Array.from({length:s},(a,l)=>s+l),normal:[-1,0,0]}];for(let a=0;a<s;a++){const l=(a+1)%s,[c,h]=[n[l][0]-n[a][0],n[l][1]-n[a][1]];r.push({corners:[a,l,s+l,s+a],normal:ti([0,-c,h])})}return{vertices:o,faces:r,creases:!0}}function ig(t,e){const n={left:([i,o])=>[0,o,i],right:([i,o])=>[0,o,i],front:([i,o])=>[i,o,0],back:([i,o])=>[i,o,0],up:([i,o])=>[i,0,o]},s={left:[1,0,0],right:[-1,0,0],front:[0,0,1],back:[0,0,-1],up:[0,1,0]};return{vertices:t.map(n[e]),faces:[{corners:t.map((i,o)=>o),normal:s[e]}]}}function og(t,e,n=8){const s=r=>Array.isArray(e)?e[Math.min(r,e.length-1)]:e,i=[],o=[];t.forEach((r,a)=>{const l=t[Math.min(a+1,t.length-1)],c=t[Math.max(a-1,0)],h=ti([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=ti(rg(h,u)),f=rg(d,h);for(let p=0;p<n;p++){const g=Math.PI*2*p/n,m=Math.cos(g)*s(a),w=Math.sin(g)*s(a);i.push([r[0]+d[0]*m+f[0]*w,r[1]+d[1]*m+f[1]*w,r[2]+d[2]*m+f[2]*w])}});for(let r=0;r<t.length-1;r++)for(let a=0;a<n;a++){const l=(a+1)%n,c=[r*n+a,r*n+l,(r+1)*n+l,(r+1)*n+a],h=c.reduce((d,f)=>[d[0]+i[f][0]/4,d[1]+i[f][1]/4,d[2]+i[f][2]/4],[0,0,0]),u=[(t[r][0]+t[r+1][0])/2,(t[r][1]+t[r+1][1])/2,(t[r][2]+t[r+1][2])/2];o.push({corners:c,normal:ti([h[0]-u[0],h[1]-u[1],h[2]-u[2]])})}return{vertices:i,faces:o,creases:!1}}function rg(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 ag(t){switch(t.type){case"box":return tg(t.size);case"cylinder":return eg(t.radius,t.length,t.axis,t.segments,t.spokes);case"ellipsoid":return ng(t.radii,t.segments);case"extrude":return sg(t.profile,t.width);case"panel":return ig(t.points,t.facing);case"tube":return{...og(t.points,t.radius,t.segments),joined:t.joined}}}function Pl(t,e){if(t.length<2)return t;const n=i=>t[Math.max(0,Math.min(t.length-1,i))],s=i=>{const o=i*(t.length-1),r=Math.min(t.length-2,Math.floor(o)),a=o-r,[l,c,h,u]=[n(r-1),n(r),n(r+1),n(r+2)];return[0,1,2].map(d=>{const f=l[d],p=c[d],g=h[d],m=u[d];return .5*(2*p+(-f+g)*a+(2*f-5*p+4*g-m)*a*a+(-f+3*p-3*g+m)*a*a*a)})};return Array.from({length:e},(i,o)=>s(o/(e-1)))}const pn=t=>Array.isArray(t)&&t.length===2&&t.every(e=>typeof e=="number"&&Number.isFinite(e));function Do(t,e){return((e-t)%360+540)%360-180}function lg(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 Qn(t,e){return Math.atan2(e[0]-t[0],e[1]-t[1])*180/Math.PI}function cg(t){const e=t.filter((i,o)=>o===0||Math.hypot(i[0]-t[o-1][0],i[1]-t[o-1][1])>1e-6);if(e.length<2)return[];const n=e.length===2?e:Pl(e.map(([i,o])=>[i,0,o]),(e.length-1)*12).map(([i,,o])=>[i,o]);let s=0;return n.map((i,o)=>(o>0&&(s+=Math.hypot(i[0]-n[o-1][0],i[1]-n[o-1][1])),{point:i,at:s}))}function hg(t,e){let n=1;for(;n<t.length-1&&t[n].at<e;)n++;const s=t[n-1],i=t[n],o=i.at>s.at?Math.max(0,Math.min(1,(e-s.at)/(i.at-s.at))):0;return{point:[s.point[0]+(i.point[0]-s.point[0])*o,s.point[1]+(i.point[1]-s.point[1])*o],direction:[i.point[0]-s.point[0],i.point[1]-s.point[1]]}}function ug(t,e){if(e<=0)return 0;if(e>=1)return 1;let n=0,s=1;for(let i=0;i<40;i++){const o=(n+s)/2;t(o)<e?n=o:s=o}return(n+s)/2}const ei=520,$l=["do","at","for","to","through","toward","speed","pose","gag","say","look","turns","dance","bpm","beats"],dg=t=>Math.max(700,Array.from(t).length*65),fg=70,gg=35;function Il(t,e){const n=e[0]-t.x,s=e[1]-t.eyeHeight,i=e[2]-t.z,o=t.heading*Math.PI/180,r=n*Math.cos(o)-i*Math.sin(o),a=n*Math.sin(o)+i*Math.cos(o),l=Math.atan2(r,a)*180/Math.PI,c=Math.hypot(r,a),h=-Math.atan2(s,c)*180/Math.PI,u=Math.max(-fg,Math.min(fg,l*.75)),d=Math.max(-gg,Math.min(gg,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 pg={walk:1.3,bouncy:1.4,doubleBounce:1.2,sneak:.6,strut:1.2,tired:.8,run:3.6,shove:.7},Ol=Object.keys(Dt),_l=Object.keys(ce),Cl=Object.keys(To),mv=.25,yv=700/180,bv=200,wv=300;function mg(t){if(!Array.isArray(t))return[{beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const e=[...Ol,"face","spin","dance","hold","pose","gag","place","say","look"],n=[];return t.forEach((s,i)=>{const o=c=>n.push({beat:i,message:c});if(!s||typeof s!="object"||Array.isArray(s))return o("Each beat must be an object like { do: 'walk', to: [x, z] }.");const r=s,a={duration:"for",path:"through",position:"to",heading:"toward",direction:"toward"};for(const c of Object.keys(r))$l.includes(c)||o(ft("beat field",c,$l,a[c]));const l=typeof r.do=="string"?_l.includes(r.do)?"pose":Cl.includes(r.do)?"gag":r.do==="turn"?"face":void 0:void 0;if(typeof r.do!="string"||!e.includes(r.do))return o(ft("character 3D beat",r.do,e,l));for(const c of["at","for","turns","bpm","beats"]){const h=r[c];h!==void 0&&(typeof h!="number"||!Number.isFinite(h)||(c==="at"?h<0:c!=="turns"&&h<=0))&&o(`\`${c}\` must be finite${c==="turns"?"":c==="at"?" and non-negative":" and positive"}.`)}if(r.do==="dance"&&!(typeof r.dance=="string"&&Object.hasOwn(cn,r.dance))&&o(ft("native dance",r.dance,Object.keys(cn))),Ol.includes(r.do)&&(r.to===void 0&&r.through===void 0&&o(`\`${r.do}\` needs \`to\` ([x, z] metres) or \`through\` (a list of them).`),r.to!==void 0&&!pn(r.to)&&o(`\`to\` is a point on the ground, [x, z] metres (got ${JSON.stringify(r.to)}).`),r.through!==void 0&&!(Array.isArray(r.through)&&r.through.length>0&&r.through.every(pn))&&o("`through` is a list of points on the ground, each [x, z] metres.")),r.do==="place"&&!pn(r.to)&&o("`place` needs `to`: a point on the ground, [x, z] metres."),r.do==="face"&&!(pn(r.toward)||typeof r.toward=="number"&&Number.isFinite(r.toward))&&o("`face` needs `toward`: a point [x, z] or a finite heading in degrees."),r.do==="say"&&!(typeof r.say=="string"&&r.say.trim().length>0)&&o("`say` needs `say`: the line spoken."),r.do==="look"){const c=r.look??r.toward;Array.isArray(c)&&(c.length===2||c.length===3)&&c.every(u=>typeof u=="number"&&Number.isFinite(u))||c==="camera"||o("`look` needs `look`: a point [x, z] or [x, y, z] to look at, or `camera`.")}r.do==="pose"&&!(typeof r.pose=="object"&&r.pose!==null)&&!_l.includes(r.pose)&&o(ft("pose",r.pose,_l)),r.do==="gag"&&!Cl.includes(r.gag)&&o(ft("gag",r.gag,Cl))}),n}function kv(t,e,n){const s=mg(e);if(s.length>0)throw new Error(`characterScript3D: ${s.length} problem(s) in the beats:
|
|
54
|
+
${s.map(M=>` beat ${M.beat}: ${M.message}`).join(`
|
|
55
|
+
`)}`);const i=n.height??1.7,o={...ut,...n.pose},r=(M,x=o)=>{const S=M.match(/^hand\.(?:left|right)\.(.+)$/)?.[1];return x[M]??ut[M]??(S?Pt[S]:void 0)??0};let[a,l]=n.position??[0,0],c=n.heading??0,h=0;const u=new Map,d=[],f=(M,x,S,E="linear")=>{const P=u.get(M)??[];P.push({time:x,value:S,easing:E}),u.set(M,P)},p=(M,x,S)=>{const E=u.get(M)??[];for(let P=E.length-1;P>=0;P--)if(E[P].time===x){if(E[P].value===S)return;break}f(M,x,S)};f("x",0,a),f("z",0,l),f("rotateY",0,c);const g=(M,x,S)=>{const E=Do(c,x);if(Math.abs(E)<1)return S!==void 0&&(p("rotateY",M,c),f("rotateY",M+S,c)),M+(S??0);const P=S??Math.max(bv,Math.abs(E)*yv);return p("rotateY",M,c),c+=E,f("rotateY",M+P,c,"ease-in-out"),M+P},m=(M,x,S,E="ease-in-out")=>{for(const[P,A]of Object.entries(S))r(P)!==A&&(p(P,M,r(P)),f(P,x,A,E),o[P]=A)},w=(M,x,S)=>{const E=cg([[a,l],...x.through??[x.to]]);if(E.length<2)return S;const P=g(S,Qn(E[0].point,E[1].point)),A=E[E.length-1].at,I=x.speed??pg[M]*Math.sqrt(i/1.7),_=x.for??A/I*1e3,N=nl(M,i),Y=Lt("ease-in-out"),V=Math.min(wv,_/4);d.push({time:P,value:M}),p("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 X=c;for(let R=0;;R=Math.min(A,R+mv)){const z=P+ug(Y,R/A)*_,{point:K,direction:O}=hg(E,R);X+=Do(X,Qn([0,0],O));const D=R===0?p:f;if(D("x",z,K[0]),D("z",z,K[1]),D("rotateY",z,X),D("walk",z,tt+R/N),R>=A)break}return h=tt+A/N,[a,l]=E[E.length-1].point,c=X,P+_},v=[],k=[];let y=0;for(const M of e){const x=M.at??y;let S=x;if(Ol.includes(M.do))S=w(M.do,M,x);else if(M.do==="face")S=g(x,typeof M.toward=="number"?M.toward:Qn([a,l],M.toward),M.for);else if(M.do==="spin")S=x+(M.for??1e3),p("rotateY",x,c),c+=(M.turns??1)*360,f("rotateY",S,c,"linear");else if(M.do==="dance"){const E=cn[M.dance],P=M.bpm??E.bpm,A=M.beats??(M.for!==void 0?M.for*P/6e4:E.beats);S=x+(M.for??A*6e4/P);const I={...o},_=Math.max(1,Math.ceil(A*16)),N=Array.from({length:_+1},(V,tt)=>Ys(M.dance,A*tt/_,I).pose),Y=Math.min(150,(S-x)/4);for(const V of Object.keys(N[0])){const tt=r(V,I);V==="turn"||V==="roll"||N.every(X=>X[V]===tt)||(p(V,x,tt),N.slice(1).forEach((X,R)=>{const z=x+(S-x)*(R+1)/_,K=Math.min(1,(z-x)/Y),O=K*K*(3-2*K);f(V,z,tt+(X[V]-tt)*O)}),o[V]=N[_][V])}}else if(M.do==="hold")S=x+(M.for??1e3);else if(M.do==="place")p("x",x,a),p("z",x,l),[a,l]=M.to,f("x",x+1,a),f("z",x+1,l),typeof M.toward=="number"&&(p("rotateY",x,c),c=M.toward,f("rotateY",x+1,c)),S=x+1;else if(M.do==="pose"){S=x+(M.for??500);const E=typeof M.pose=="string"?ce[M.pose]:M.pose;m(x,S,E)}else if(M.do==="gag"){const E=sf(M.gag,{at:x,from:{...o}});let P=E[0];for(const A of E.slice(1))m(P.time,A.time,Object.fromEntries(Object.entries(A.pose).filter(([I,_])=>o[I]!==_)),A.easing??"ease-in-out"),P=A;S=P.time}else if(M.do==="say"){S=x+(M.for??dg(M.say)),k.push({text:M.say,start:x,end:S});const E={tilt:o["head.tilt"]??0,left:o["brow.left"]??0,right:o["brow.right"]??0};let P=0;for(let A=x+ei;A<S-ei/2;A+=ei,P++){const I=P%2===0;m(A-ei/2,A,{"head.tilt":E.tilt+(I?3:-2),"brow.left":E.left+(I?.25:0),"brow.right":E.right+(I?.25:0)})}P>0&&m(S-ei/2,S,{"head.tilt":E.tilt,"brow.left":E.left,"brow.right":E.right})}else if(M.do==="look"){const E=M.look??M.toward,P=i*.9,A=E==="camera"?n.camera??[0,1.6,8]:E.length===3?E:[E[0],P,E[1]];S=x+(M.for??500),m(x,S,Il({x:a,z:l,heading:c,eyeHeight:P},A),"ease-out")}v.push({do:M.do,start:x,end:S}),y=S}const T=`${n.scene}/${t}`;let $=[...u].map(([M,x])=>({id:`${t}-${M}`,target:T,property:M,keyframes:lg(x)}));return d.length>0&&$.push({id:`${t}-gait`,target:T,property:"gait",keyframes:d}),k.length>0&&($=Wo(T,$,k,{rest:{mouth:n.pose?.mouth??ut.mouth??0,mouthWidth:n.pose?.mouthWidth??ut.mouthWidth??1}})),{tracks:$,duration:y,beats:v,end:{position:[a,l],heading:c,pose:{...o}}}}function Hl(t,e,n=[0,0,0]){const s=t.filter(o=>o.target===e),i=new It({id:`${e}-position`,tracks:s});return o=>{const r=i.getStateAtTime(o).values.get(e),a=r?.get("position");if(Array.isArray(a)&&a.length===3)return[a[0],a[1],a[2]];const l=(c,h)=>{const u=r?.get(c);return typeof u=="number"?u:h};return[l("x",n[0]),l("y",n[1]),l("z",n[2])]}}function vv(t,e){const n=`${e.scene}/${e.character}`,s=e.height??1.7,i=Math.max(1,e.every??66),o=e.objects?.[e.character]??[0,0,0],r=new It({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?Hl(t,`${e.scene}/${a.camera}`,e.objects?.[a.camera]??[0,1.6,8]):(()=>{const u=Hl(t,`${e.scene}/${a.object}`,e.objects?.[a.object]??[0,0,0]),d=a.eyeHeight??s*.9;return f=>{const p=u(f);return[p[0],p[1]+d,p[2]]}})(),c=["head.turn","head.nod","lookX","lookY"],h={"head.turn":[],"head.nod":[],lookX:[],lookY:[]};for(let u=e.start;;u=Math.min(e.end,u+i)){const d=r.getStateAtTime(u).values.get(n),f=(g,m)=>{const w=d?.get(g);return typeof w=="number"?w:m},p=Il({x:f("x",o[0]),z:f("z",o[2]),heading:f("rotateY",0),eyeHeight:f("y",o[1])+s*.9},l(u));for(const g of c)h[g].push({time:u,value:p[g]??0});if(u>=e.end)break}return c.map(u=>({id:`${n}-lookAt-${u}`,target:n,property:u,keyframes:h[u]}))}function Mv(t){const e=Math.max(1,Math.round(t.count)),[n,s]=t.centre??[0,0],i=t.spacing??1.2,o=t.shape??"line",r=[];if(o==="circle"){const h=e<2?0:Math.max(i,i*e/(Math.PI*2));for(let u=0;u<e;u++){const d=u/e*Math.PI*2,f=n+Math.sin(d)*h,p=s+Math.cos(d)*h;r.push({position:[f,p],heading:(Math.atan2(n-f,s-p)*180/Math.PI+360)%360})}return r}if(o==="cluster"){let h=(t.seed??1)>>>0||7;const u=()=>(h^=h<<13,h>>>=0,h^=h>>17,h^=h<<5,h>>>=0,h/4294967296),d=[];for(let f=0;f<e;f++){let p=[n,s],g=-1/0;for(let m=0;m<24;m++){const w=Math.sqrt(u())*i*Math.max(1,Math.sqrt(e)*.9),v=u()*Math.PI*2,k=[n+Math.cos(v)*w,s+Math.sin(v)*w],y=d.length===0?1/0:Math.min(...d.map(T=>Math.hypot(T[0]-k[0],T[1]-k[1])));if(y>g&&(g=y,p=k),y>=i)break}d.push(p),r.push({position:p,heading:0})}return r}const a=(t.heading??90)*Math.PI/180,l=i*(e-1),c=(t.bend??60)*Math.PI/180;for(let h=0;h<e;h++){const u=e===1?0:h/(e-1)-.5,d=u*l;let f=n+Math.sin(a)*d,p=s+Math.cos(a)*d,g=((t.heading??90)-90+360)%360;if(o==="arc"){const m=(1-Math.cos(u*c))*l*.5;f-=Math.cos(a)*m,p+=Math.sin(a)*m,g=(g-u*(t.bend??60)+360)%360}r.push({position:[f,p],heading:g})}return r}const yg={x:0,y:0,scale:1,rotate:0,shakeX:0,shakeY:0,shakeRotate:0};function Sv(t){const e=n=>{const s=t?.get(n);return typeof s=="number"?s:yg[n]};return{x:e("x"),y:e("y"),scale:e("scale"),rotate:e("rotate"),shakeX:e("shakeX"),shakeY:e("shakeY"),shakeRotate:e("shakeRotate")}}function xv(t,e,n){const s=n.width/2,i=n.height/2,r=1+2*Math.max(Math.abs(e.shakeX),Math.abs(e.shakeY))/Math.max(1,Math.min(n.width,n.height));t.translate(s+e.x+e.shakeX,i+e.y+e.shakeY),t.rotate((e.rotate+e.shakeRotate)*Math.PI/180),t.scale(e.scale*r,e.scale*r),t.translate(-s,-i)}function Tv(t,e,n){const s=e.width/2,i=e.height/2,o=(t.rotate+t.shakeRotate)*Math.PI/180,r=(n.x-s)*t.scale,a=(n.y-i)*t.scale;return{x:s+t.x+t.shakeX+r*Math.cos(o)-a*Math.sin(o),y:i+t.y+t.shakeY+r*Math.sin(o)+a*Math.cos(o)}}function bg(t,e,n={},s){const i=n.length??240,o=9,r=28,a=i-22;t.save(),t.translate(e.x,e.y),t.rotate((n.angle??-30)*Math.PI/180),t.fillStyle=n.color??"#f4c542",t.fillRect(r,-o,a-r,2*o),t.fillStyle="#e8b4a0",t.fillRect(a,-o,i-a,2*o),t.fillStyle="#f1dcbf",t.beginPath(),t.moveTo(0,0),t.lineTo(r,-o),t.lineTo(r,o),t.closePath(),t.fill(),t.fillStyle=n.outline??"#2f2f33",t.beginPath(),t.moveTo(0,0),t.lineTo(r*.35,-o*.35),t.lineTo(r*.35,o*.35),t.closePath(),t.fill(),t.strokeStyle=n.outline??"#2f2f33",t.lineWidth=3,t.lineJoin="round",t.lineCap="round";const l=[[{x:0,y:0},{x:r,y:-o},{x:i,y:-o},{x:i,y:o},{x:r,y:o},{x:0,y:0}],[{x:r,y:-o},{x:r,y:o}],[{x:a,y:-o},{x:a,y:o}]];for(const c of l)vg(t,c,s);t.restore()}function Rl(t,e,n={},s){const i=n.length??90,o=n.thickness??34;t.save(),t.translate(e.x,e.y),t.rotate((n.angle??-35)*Math.PI/180);const r=-o/2;t.fillStyle=n.color??"#f4a7b9",t.fillRect(0,r,i,o),t.fillStyle="#e9edf2",t.fillRect(i*.45,r,i*.55,o),t.strokeStyle=n.outline??"#2f2f33",t.lineWidth=3,t.lineJoin="round";const a=[{x:0,y:r},{x:i,y:r},{x:i,y:-r},{x:0,y:-r},{x:0,y:r}],l=[{x:i*.45,y:r},{x:i*.45,y:-r}];if(s)s.line(a),s.line(l);else for(const c of[a,l]){t.beginPath(),t.moveTo(c[0].x,c[0].y);for(const h of c.slice(1))t.lineTo(h.x,h.y);t.stroke()}t.restore()}const wg=150,Ev={pencil:44,eraser:30};function Ll(t,e,n={},s){const i=n.tool??"pencil",o=n.skin??"#f1c9a5",r=n.outline??"#2f2f33",a=n.scale??1,l=Math.min(1,Math.max(0,n.lift??0)),c=(n.angle??-30)*Math.PI/180,h=s?s.nudge(.6):{x:0,y:0},u=wg*a*(1+.05*l);l>0&&(t.save(),t.fillStyle=r,t.globalAlpha=.15*l,t.beginPath(),t.ellipse(e.x,e.y,9*a,4*a,0,0,Math.PI*2),t.fill(),t.restore());const d={x:e.x+h.x+6*l*a,y:e.y+h.y-18*l*a},f=Ct.pencilGrip,p=M=>{const x=M.fingers.thumb,S=M.fingers.index,E=M.fingers.middle,P=kg([x.points[3],S.points[3],E.points[3]]),A=kg([x.points[1],S.points[0]]),I=(x.depths[3]+S.depths[3]+E.depths[3])/3;return{pinch:P,direction:Math.atan2(A.y-P.y,A.x-P.x),depth:I}},g=Ui(f,{size:u}),m=c-p(g).direction,w=Ui(f,{size:u,angle:m*180/Math.PI}),v=p(w),k=Ev[i]*a,y={x:v.pinch.x-Math.cos(c)*k,y:v.pinch.y-Math.sin(c)*k},T={x:d.x-y.x,y:d.y-y.y},$=w.axes.up;Av(t,T,{x:-$.x,y:-$.y},u,n.arm??300*a,o,n.sleeve??"#5b7db1",r),Vi(t,T,f,{size:u,angle:m*180/Math.PI,skin:o,ink:r,lineWidth:3*a,prop:{depth:v.depth,draw:()=>{t.save(),t.translate(d.x,d.y),t.scale(a,a),i==="eraser"?Rl(t,{x:0,y:0},{angle:c*180/Math.PI,outline:r},s):bg(t,{x:0,y:0},{angle:c*180/Math.PI,length:190,outline:r},s),t.restore()}}})}const kg=t=>({x:t.reduce((e,n)=>e+n.x,0)/t.length,y:t.reduce((e,n)=>e+n.y,0)/t.length});function Av(t,e,n,s,i,o,r,a){const l={x:-n.y,y:n.x},c=s*.15,h=(g,m,w)=>({x:e.x+n.x*g+l.x*m*w,y:e.y+n.y*g+l.y*m*w}),u=h(i,0,0),d=g=>{const m=t.createLinearGradient(e.x,e.y,u.x,u.y);return m.addColorStop(0,g),m.addColorStop(.6,g),m.addColorStop(1,Ov(g)),m},f=Math.min(s*.55,i*.35);t.save(),t.lineJoin="round",t.lineCap="round",t.lineWidth=3*(s/wg),t.beginPath(),t.moveTo(h(-s*.1,-1,c).x,h(-s*.1,-1,c).y),t.lineTo(h(f+4,-1,c*1.1).x,h(f+4,-1,c*1.1).y),t.lineTo(h(f+4,1,c*1.1).x,h(f+4,1,c*1.1).y),t.lineTo(h(-s*.1,1,c).x,h(-s*.1,1,c).y),t.closePath(),t.fillStyle=o,t.fill(),t.strokeStyle=a,t.beginPath(),t.moveTo(h(0,-1,c).x,h(0,-1,c).y),t.lineTo(h(f,-1,c*1.1).x,h(f,-1,c*1.1).y),t.moveTo(h(0,1,c).x,h(0,1,c).y),t.lineTo(h(f,1,c*1.1).x,h(f,1,c*1.1).y),t.stroke();const p=[h(f,-1,c*1.3),h(i,-1,c*1.5),h(i,1,c*1.5),h(f,1,c*1.3)];t.beginPath(),p.forEach((g,m)=>m?t.lineTo(g.x,g.y):t.moveTo(g.x,g.y)),t.closePath(),t.fillStyle=d(r),t.fill(),t.strokeStyle=d(a),t.beginPath(),t.moveTo(p[1].x,p[1].y),t.lineTo(p[0].x,p[0].y),t.lineTo(p[3].x,p[3].y),t.lineTo(p[2].x,p[2].y),t.stroke(),t.restore()}function Pv(t,e,n={}){const s=n.offstage??{x:2e3,y:1400},i=n.enter??450,o=n.exit??450,r=n.linger??1500,a=[...t].filter(g=>g.path.length>0).sort((g,m)=>g.start-m.start),l=g=>g.tool??"pencil",c=g=>{const m=Math.min(1,Math.max(0,g));return m*m*(3-2*m)},h=(g,m,w)=>({x:g.x+(m.x-g.x)*w,y:g.y+(m.y-g.y)*w}),u=a.find(g=>e>=g.start&&e<=g.end);if(u){const g=u.end-u.start,m=g>0?(e-u.start)/g:1;return{at:qi(u.path,m),tool:l(u),lift:0,drawing:!0}}const d=[...a].reverse().find(g=>g.end<e),f=a.find(g=>g.start>e),p=g=>g.path[g.path.length-1];if(d&&f&&f.start-d.end<=r){const g=(e-d.end)/(f.start-d.end),m=g<.5?l(d):l(f);return{at:h(p(d),f.path[0],c(g)),tool:m,lift:Math.sin(Math.PI*g),drawing:!1}}if(f&&f.start-e<=i){const g=1-(f.start-e)/i;return{at:h(s,f.path[0],c(g)),tool:l(f),lift:1-c(g),drawing:!1}}if(d&&e-d.end<=o){const g=(e-d.end)/o;return{at:h(p(d),s,c(g)),tool:l(d),lift:c(g),drawing:!1}}return null}function $v(t,e,n,s=.08,i=32){const o=Math.PI*2*(1+s),r=[];for(let a=0;a<=i;a++){const l=-Math.PI/2+o*a/i;r.push({x:t+Math.cos(l)*n,y:e+Math.sin(l)*n})}return r}function Iv(t){const{path:e}=t,n=e.map(a=>a.x),s=e.map(a=>a.y),i=Math.min(...n),o=Math.min(...s),r=t.hand===!1?void 0:t.hand===!0||t.hand===void 0?{}:t.hand;return{type:"custom",x:i,y:o,width:Math.max(1,Math.max(...n)-i),height:Math.max(1,Math.max(...s)-o),props:{draw:0},draw(a,l,c){const h=Math.min(1,Math.max(0,Number(l.props?.draw??0)));a.translate(-i,-o),a.strokeStyle=t.color??"#2f2f33",a.lineWidth=t.lineWidth??5,a.lineCap="round",a.lineJoin="round";const u=t.sketch?Yi(a,t.sketch,c):void 0;h>0&&(u?t.smooth?u.curve(e,h):u.line(e,h):vg(a,Nn(e,h))),r&&h>0&&h<1&&Ll(a,qi(e,h),r,u)}}}function Ov(t){const e=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim());if(!e)return"rgba(0, 0, 0, 0)";const n=e[1].length===3?[...e[1]].map(r=>r+r).join(""):e[1],[s,i,o]=[0,2,4].map(r=>parseInt(n.slice(r,r+2),16));return`rgba(${s}, ${i}, ${o}, 0)`}function vg(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 _v(t,e,n,s,i=6){const o=[],r=Math.max(1,Math.round(i));for(let a=0;a<=r;a++)o.push({x:a%2===0?t:t+n,y:e+s*a/r});return o}function Nl(t,e,n,s){if(s<=0||e.length===0)return;const i=Nn(e,s),o=n/2,r=a=>{t.beginPath(),t.rect(-Bo,-Bo,2*Bo,2*Bo),a(),t.clip("evenodd")};for(const a of i)r(()=>{t.moveTo(a.x+o,a.y),t.arc(a.x,a.y,o,0,Math.PI*2)});for(let a=1;a<i.length;a++){const l=i[a-1],c=i[a],h=Math.hypot(c.x-l.x,c.y-l.y);if(h===0)continue;const u=-(c.y-l.y)/h*o,d=(c.x-l.x)/h*o;r(()=>{t.moveTo(l.x+u,l.y+d),t.lineTo(c.x+u,c.y+d),t.lineTo(c.x-u,c.y-d),t.lineTo(l.x-u,l.y-d),t.closePath()})}}function Cv(t,e,n,s,i){t.save(),Nl(t,e,n,s),i(),t.restore()}function Hv(t,e){const n=e.width??40,s=e.hand===!0?{}:e.hand||void 0,i=e.eraser===!1?void 0:e.eraser===!0||e.eraser===void 0?{}:e.eraser;return{...t,props:{...t.props,erase:0},draw(o,r,a){const l=Number(r.props?.erase??0);if(o.save(),Nl(o,e.path,n,l),t.draw(o,r,a),o.restore(),!i||l<=0||l>=1)return;const c=qi(e.path,l);s?Ll(o,c,{...s,tool:"eraser"}):Rl(o,c,i)}}}function ts(){const t=new Map,e=(n,...s)=>t.set(n,[...t.get(n)??[],...s]);return{keys:n=>t.get(n),push:e,tween(n,s,i,o,r=300){e(n,{time:o.at,value:s},{time:o.at+(o.duration??r),value:i,...o.easing?{easing:o.easing}:{}})},last(n,s){const i=t.get(n);return i?[...i].sort((o,r)=>o.time-r.time)[i.length-1].value:s},valueAt:(n,s)=>zo(t.get(n),s),cutAfter(n,s){for(const i of n)t.set(i,(t.get(i)??[]).filter(o=>o.time<=s))},tracks(n){return[...t].filter(([,s])=>s.length>0).map(([s,i])=>({id:`${n}-${s}`,target:n,property:s,keyframes:Rv(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],o=n[s];return o.time===i.time?o.value:i.value+(o.value-i.value)*(e-i.time)/(o.time-i.time)}return n[n.length-1].value}function es(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 Rv(t){return[...t].sort((n,s)=>n.time-s.time).map(n=>({time:n.time,value:n.value,...n.easing?{easing:n.easing}:{}}))}const Lv=.0016,Nv=.6,qe=33;function ni(t){const e=(o,r)=>`piece.${o.id}.${r}`,n=(o,r)=>({x:o.home.x+t.valueAt(e(o,"x"),r),y:o.home.y+t.valueAt(e(o,"y"),r)}),s=(o,r)=>{const a=t.keys(e(o,"x"));if(!a||a.length<2)return;const l=n(o,r-qe),c=n(o,r);return{x:(c.x-l.x)/qe,y:(c.y-l.y)/qe}},i=(o,r)=>t.cutAfter(["x","y","rotate"].map(a=>e(o,a)),r);return{at:n,cutAfter:i,follow(o,r){for(const a of r)t.push(e(o,"x"),{time:a.time,value:a.x-o.home.x}),t.push(e(o,"y"),{time:a.time,value:a.y-o.home.y})},fling(o,r){const a=n(o,r.at),l=r.velocity??s(o,r.at)??{x:.5,y:-.6},c=r.gravity??Lv,h=r.duration??900,u=(r.spin??Nv)*(l.x<0?-1:1),d=t.valueAt(e(o,"rotate"),r.at);i(o,r.at);for(let f=0;f<=h;f+=qe){const p=a.x+l.x*f,g=a.y+l.y*f+.5*c*f*f;t.push(e(o,"x"),{time:r.at+f,value:p-o.home.x}),t.push(e(o,"y"),{time:r.at+f,value:g-o.home.y}),t.push(e(o,"rotate"),{time:r.at+f,value:d+u*f})}t.tween(e(o,"opacity"),1,0,{at:r.at+h*.6,duration:h*.4})},move(o,r){const a=n(o,r.at);t.tween(e(o,"x"),a.x-o.home.x,r.to.x-o.home.x,r,400),t.tween(e(o,"y"),a.y-o.home.y,r.to.y-o.home.y,r,400)}}}function qo(t,e,{ground:n,every:s,floors:i}){if(i.every(k=>k.windows.length===0))return t;const o=t.find(k=>k.target===e&&k.property==="y"),r=new It({id:`${e}-ride`,tracks:o?[o]:[]}),a=k=>o?Number(r.getStateAtTime(k).values.get(e)?.get("y")??0):0,l=k=>{const y=n+a(k);return i.findIndex(T=>Math.abs(T.top-y)<.5)},c=(o?.keyframes??[]).map(k=>k.time),h=k=>{const y=S=>S<0?0:i[S].offset(k),T=l(k);if(T>=0)return y(T);if(Math.abs(a(k))<.5)return 0;const $=S=>l(S)>=0||Math.abs(a(S))<.5,M=[...c].reverse().find(S=>S<=k&&$(S)),x=c.find(S=>S>=k&&$(S));return M===void 0&&x===void 0?0:M===void 0?y(l(x)):x===void 0||x===M?y(l(M)):y(l(M))+(y(l(x))-y(l(M)))*(k-M)/(x-M)},u=i.flatMap(k=>k.windows),d=(k,y)=>u.some(T=>T.start<y&&T.end>k)||h(k)!==h(y),f=o?[...o.keyframes]:[{time:0,value:0}],p=[{...f[0],value:f[0].value+h(f[0].time)}],g=(k,y)=>{const T=new Set([y]);for(let $=k+s;$<y;$+=s)T.add($);for(const $ of u)for(const M of[$.start,$.end])M>k&&M<y&&T.add(M);for(const $ of[...T].sort((M,x)=>M-x))p.push({time:$,value:a($)+h($)})};for(let k=1;k<f.length;k++){const y=f[k-1].time,T=f[k].time;d(y,T)?g(y,T):p.push({...f[k],value:f[k].value+h(T)})}const m=f[f.length-1].time,w=Math.max(m,...u.map(k=>k.end));w>m&&g(m,w);const v={id:o?.id??`${e}-y`,target:e,property:"y",keyframes:p};return o?t.map(k=>k===o?v:k):[...t,v]}function mn(t){const e=t.indexOf(":");return e<0?{kind:t,rest:""}:{kind:t.slice(0,e),rest:t.slice(e+1)}}function Ye(t,e,n,s){const i=Object.keys(n.anchors).map(r=>mn(r).kind),{kind:o}=mn(e);return i.includes(o)?new Error(`${t}: no anchor "${e}"${s?`: ${s}`:""} (anchors: ${Object.keys(n.anchors).join(", ")})`):new Error(`${t}: ${ft("anchor",o,i)} (anchors: ${Object.keys(n.anchors).join(", ")})`)}function si(t,e,n){return new Error(`${t}.edit: ${ft("edit",e,Object.keys(n.edits))}`)}function Mt(t,e,n,s){return{x:t+n/2,y:e+s/2,left:t,right:t+n,top:e,bottom:e+s,width:n,height:s}}const Mg={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"},Yo=["wipe","fly","blur"],ii={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"}},Fv=.9,Wv=8;function Dv(t){const e={...Mg,...t.theme},n=t.code.replace(/\t/g," ").replace(/\n$/,"").split(`
|
|
56
|
+
`),s=t.fontSize??16,i=(t.lineHeight??1.6)*s,o=(t.charWidth??.6)*s,r=t.padding??12,a=t.lineNumbers===!1?0:(String(n.length).length+2)*o,l=Math.max(1,...n.map(R=>R.length)),c=t.width??r*2+a+l*o,h=r*2+n.length*i,u=t.x+r+a,d=new Set(t.hidden??[]),f=t.language??"plain";if(!jo.includes(f))throw new Error(`codePanel: ${ft("language",f,jo)}`);const p=n.map(R=>xg(R,f).flatMap(z=>Array.from(z.text,()=>e[z.kind]))),g=ts(),m=ni(g),w=[],v=new Map,k=[],y=[],T=R=>{if(!Number.isInteger(R)||R<1||R>n.length)throw new Error(`codePanel: no line ${R} (it has ${n.length})`)},$=g.tween,M=g.last,x=(R,z,K,O,D,st=300)=>{T(R),$(`line.${R}.${z}`,K,O,D,st)},S=(R,z)=>w.filter(K=>K.line<R&&K.closed<=z).length,E=Mt,P=R=>t.y+r+(R-1)*i,A=R=>Array.isArray(R)?R:[R],I=(R,z,K)=>{let O=-1;for(let D=0;D<K;D++)if(O=n[R-1].indexOf(z,O+1),O<0)throw new Error(`codePanel: line ${R} has no ${K>1?`${K}th `:""}"${z}"`);return O},_={};n.forEach((R,z)=>{const K=z+1;_[`line.${K}.highlight`]=0,_[`line.${K}.strike`]=0,_[`line.${K}.wipe`]=0,_[`line.${K}.reveal`]=d.has(K)?0:1,_[`line.${K}.shift`]=0});const N={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 zv(Object.keys(_))},actions:Fl},draw(R,z){const K=z.props??{},O=L=>Number(K[L]??_[L]),D=r+a,st=L=>r+(L-1)*i-O(`line.${L}.shift`)*i;R.fillStyle=e.background,Sg(R,0,0,c,h,8),R.fill(),R.font=`${s}px ${e.font}`,R.textBaseline="middle",R.textAlign="left";const H=(L,q,U,F,W)=>{const B=n[L-1];for(let J=q;J<U;J++)B[J]!==" "&&(R.fillStyle=p[L-1][J],R.fillText(B[J],F+(J-q)*o,W))};R.save(),Sg(R,0,0,c,h,8),R.clip(),n.forEach((L,q)=>{const U=q+1,F=O(`line.${U}.wipe`);if(F>=1)return;const W=st(U),B=W+i/2,J=Math.max(1,L.length)*o,j=Math.round(O(`line.${U}.reveal`)*L.length),Q=v.get(U)??{style:"wipe",from:"left"};R.save(),F>0&&Bv(R,Q,F,{left:D-a,top:W,width:a+J+o,height:i},c);const et=O(`line.${U}.highlight`);et>0&&(R.globalAlpha*=Math.min(1,et),R.fillStyle=e.highlight,R.fillRect(D-o/2,W,J+o,i),R.globalAlpha/=Math.min(1,et)),a>0&&j>0&&(R.fillStyle=e.gutter,R.textAlign="right",R.fillText(String(U),D-o,B),R.textAlign="left");const C=[...k.filter(it=>it.line===U).map(it=>({column:it.column,length:it.text.length,piece:it,insert:void 0})),...y.filter(it=>it.line===U).map(it=>({column:it.column,length:0,piece:void 0,insert:it}))].sort((it,lt)=>it.column-lt.column||it.length-lt.length);let G=0,ot=D;for(const it of C){H(U,G,Math.min(it.column,j),ot,B),ot+=(it.column-G)*o;let lt=it.length,nt="";if(it.piece){const Z=it.piece.written??"",rt=O(`piece.${it.piece.id}.write`);Z&&rt>0?(nt=Z.slice(0,Math.round(rt*Z.length)),lt=it.length+(Z.length-it.length)*Math.min(1,rt*2)):lt=it.length*(1-O(`piece.${it.piece.id}.away`))}else it.insert&&(lt=it.insert.chars*O(`insert.${it.insert.id}.open`),it.insert.text&&(nt=it.insert.text.slice(0,Math.round(O(`insert.${it.insert.id}.type`)*it.insert.text.length))));R.fillStyle=e.text;for(let Z=0;Z<nt.length;Z++)nt[Z]!==" "&&R.fillText(nt[Z],ot+Z*o,B);ot+=lt*o,G=it.column+it.length}H(U,G,Math.max(G,j),ot,B);const at=O(`line.${U}.strike`);at>0&&(R.strokeStyle=e.strike,R.lineWidth=Math.max(1.5,s/10),R.beginPath(),R.moveTo(D,B),R.lineTo(D+J*Math.min(1,at),B),R.stroke()),R.restore()});for(const L of k){const q=O(`piece.${L.id}.opacity`);if(q<=0||O(`line.${L.line}.wipe`)>=1)continue;const U=D+(L.column+L.text.length/2)*o+O(`piece.${L.id}.x`),F=st(L.line)+i/2+O(`piece.${L.id}.y`);R.save(),R.globalAlpha=Math.min(1,q),R.translate(U,F),R.rotate(O(`piece.${L.id}.rotate`)*Math.PI/180),H(L.line,L.column,L.column+L.text.length,-L.text.length*o/2,0),R.restore()}R.restore()}},Y=R=>{const{kind:z,rest:K}=mn(R),O=D=>Ye("codePanel",R,ii,D);if(z==="box"){if(K)throw O("box takes no arguments");return{kind:z}}if(z==="line"){if(!/^\d+$/.test(K))throw O("write it line:N");return{kind:z,n:Number(K)}}if(z==="token"){const D=/^(\d+)(?:#(\d+))?:(.+)$/.exec(K);if(!D)throw O("write it token:N:TEXT, or token:N#K:TEXT for the Kth");return{kind:z,n:Number(D[1]),occurrence:D[2]?Number(D[2]):1,text:D[3]}}if(z==="spot"){const D=/^(\d+):(\d+)(?::(\d+))?$/.exec(K);if(!D)throw O("write it spot:N:C, or spot:N:C:W for W characters");return{kind:z,n:Number(D[1]),column:Number(D[2]),width:D[3]?Number(D[3]):1}}throw O()},V=(R,z,K,O=!1)=>{const D=Array.isArray(z)?z:[z];if(D.length===0||O&&D.length>1)throw new Error(`codePanel.edit: ${R} takes ${O?"one":"at least one"} ${K} anchor`);return D.map(st=>{const H=Y(st);if(H.kind!==K)throw new Error(`codePanel.edit: ${R} takes ${K} anchors (${K}:…), not "${st}"`);return H})},tt=(R,z)=>{if(typeof z.text!="string")throw new Error(`codePanel.edit: ${R} needs \`text\` (the text to write)`);return z.text},X={kind:"code",about:ii,target:N,lines:n,box:E(t.x,t.y,c,h),line(R,z=1/0){return T(R),E(u,P(R)-S(R,z)*i,Math.max(1,n[R-1].length)*o,i)},token(R,z,K=1,O=1/0){T(R);const D=I(R,z,K);return E(u+D*o,P(R)-S(R,O)*i,z.length*o,i)},highlight(R,z){for(const K of A(R)){const O=M(`line.${K}.highlight`,0);x(K,"highlight",O,z.on===!1?0:1,z,200)}return X},strike(R,z){for(const K of A(R))x(K,"strike",M(`line.${K}.strike`,0),1,z);return X},remove(R,z){const K=A(R),O=z.style??"wipe";if(!Yo.includes(O))throw new Error(`codePanel.remove: ${ft("style",O,Yo)}`);const D=O==="wipe"?300:450,st=z.at+(z.duration??D),H=z.close??250;for(const L of K)x(L,"wipe",0,1,{...z,easing:z.easing??(O==="fly"?"ease-in":void 0)},D),v.set(L,{style:O,from:z.from??"left"}),w.push({line:L,closed:st+H});for(let L=1;L<=n.length;L++){if(K.includes(L))continue;const q=K.filter(F=>F<L).length;if(q===0)continue;const U=M(`line.${L}.shift`,0);x(L,"shift",U,U+q,{at:st,duration:H,easing:"ease-in-out"})}return X},type(R,z){return x(R,"reveal",0,1,{duration:n[R-1].length*45,...z}),X},piece(R,z,K=1){if(typeof R=="string"){const L=Y(R);if(L.kind!=="token")throw new Error(`codePanel.piece: a piece is a word, token:N:TEXT, not "${R}"`);return X.piece(L.n,L.text,L.occurrence)}const O=R;if(z===void 0)throw new Error('codePanel.piece: which word? piece(n, text) or piece("token:N:TEXT")');T(O);const D=I(O,z,K),st=k.find(L=>L.line===O&&L.column===D&&L.text===z);if(st)return st;if(k.some(L=>L.line===O&&D<L.column+L.text.length&&L.column<D+z.length))throw new Error(`codePanel: "${z}" on line ${O} overlaps another piece`);const H={id:k.length+1,line:O,column:D,text:z,home:X.token(O,z,K,0)};k.push(H);for(const L of["x","y","rotate","write","away"])_[`piece.${H.id}.${L}`]=0;return _[`piece.${H.id}.opacity`]=1,H},follow(R,z){return m.follow(R,z),X},fling(R,z){return m.fling(R,z),X},move(R,z){return m.move(R,z),X},write(R,z,K){return R.written=z,$(`piece.${R.id}.write`,0,1,{duration:Math.max(1,z.length)*70,...K}),X},spot(R,z,K=1,O=1/0){T(R);const D=y.filter(st=>st.line===R&&st.column<=z&&st.at<=O).reduce((st,H)=>st+H.chars,0);return E(u+(z+D)*o,P(R)-S(R,O)*i,K*o,i)},insert(R,z,K,O){T(R);const D={id:y.length+1,line:R,column:z,chars:K.length,text:K,at:O.at};y.push(D),_[`insert.${D.id}.open`]=0,_[`insert.${D.id}.type`]=0;const st=O.duration??K.length*70;return $(`insert.${D.id}.open`,0,1,{at:O.at,duration:st*.6,easing:"ease-out"}),$(`insert.${D.id}.type`,0,1,{at:O.at,duration:st}),X},drop(R,z,K,O){T(z);const D=O.duration??250,st=z===R.line,H=O.easing??(st?"linear":"ease-out"),L=X.landing(R,z,K,O.at),q={id:y.length+1,line:z,column:K,chars:R.text.length,at:O.at};return y.push(q),_[`insert.${q.id}.open`]=0,$(`insert.${q.id}.open`,0,1,{at:O.at,duration:D,easing:st?H:"ease-out"}),$(`piece.${R.id}.away`,M(`piece.${R.id}.away`,0),1,{at:O.at,duration:D,easing:st?H:"ease-in-out"}),m.cutAfter(R,O.at),X.move(R,{at:O.at,duration:D,easing:H,to:{x:L.x,y:L.y}}),$(`piece.${R.id}.rotate`,g.valueAt(`piece.${R.id}.rotate`,O.at),0,{at:O.at,duration:D}),X},landing(R,z,K,O=1/0){const D=X.spot(z,K,R.text.length,O),st=z===R.line&&K>R.column?R.text.length*o:0;return E(D.left-st,D.top,D.width,D.height)},ride(R,z,K){const O=n.map((D,st)=>{const H=g.keys(`line.${st+1}.shift`)??[];return{top:P(st+1),offset:L=>-zo(H,L)*i,windows:es(H)}});return qo(R,z,{ground:K.ground,every:K.every??qe,floors:O})},tracks:g.tracks,anchor(R,z=1/0){const K=Y(R);return K.kind==="box"?X.box:K.kind==="line"?X.line(K.n,z):K.kind==="token"?X.token(K.n,K.text,K.occurrence,z):X.spot(K.n,K.column,K.width,z)},edit(R,z,K){const O=()=>V(R,z,"line").map(D=>D.n);if(R==="highlight")return X.highlight(O(),K);if(R==="strike")return X.strike(O(),K);if(R==="remove")return X.remove(O(),K);if(R==="type"){for(const D of O())X.type(D,K);return X}if(R==="insert"){const[D]=V(R,z,"spot",!0);return X.insert(D.n,D.column,tt(R,K),K)}if(R==="write"||R==="drop"||R==="move"||R==="fling"){const[D]=V(R,z,"token",!0),st=X.piece(D.n,D.text,D.occurrence);if(R==="write")return X.write(st,tt(R,K),K);if(R==="fling")return X.fling(st,K);if(R==="drop"){const L=typeof K.into=="string"?Y(K.into):void 0;if(L?.kind!=="spot")throw new Error("codePanel.edit: drop needs `into`, a spot anchor (spot:N:C)");return X.drop(st,L.n,L.column,K)}const H=typeof K.to=="string"?X.anchor(K.to,K.at):K.to;if(!H||typeof H.x!="number"||typeof H.y!="number")throw new Error("codePanel.edit: move needs `to`, an anchor name or { x, y }");return X.move(st,{...K,to:H})}throw si("codePanel",R,ii)}};return X}function Bv(t,e,n,s,i){if(e.style==="wipe"){t.beginPath(),e.from==="right"?t.rect(s.left,s.top,s.width*(1-n),s.height):t.rect(s.left+n*s.width,s.top,s.width*(1-n),s.height),t.clip();return}const o=Wv*n;if(o>.2&&"filter"in t&&(t.filter=`blur(${o.toFixed(1)}px)`),t.globalAlpha*=1-n,e.style==="fly"){const r=e.from==="right"?-1:1;t.translate(r*n*Fv*i,0),t.rotate(r*n*.08)}else{const r=1+.08*n,a=s.left+s.width/2,l=s.top+s.height/2;t.translate(a,l),t.scale(r,r),t.translate(-a,-l)}}const Fl={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 zv(t){const e=[[/^line\.\d+\.highlight$/,{description:"How much the line is tinted",unit:"0..1",min:0,max:1}],[/^line\.\d+\.strike$/,{description:"How far the strike-through has drawn",unit:"0..1",min:0,max:1}],[/^line\.\d+\.wipe$/,{description:"How far the line has gone (wiped, flown off or blurred)",unit:"0..1",min:0,max:1}],[/^line\.\d+\.reveal$/,{description:"How much of the line is typed in",unit:"0..1",min:0,max:1}],[/^line\.\d+\.shift$/,{description:"How many rows the line has moved up",unit:"rows"}],[/^piece\.\d+\.(x|y)$/,{description:"The piece moved from its home",unit:"px"}],[/^piece\.\d+\.rotate$/,{description:"The piece turned",unit:"degrees"}],[/^piece\.\d+\.opacity$/,{description:"How opaque the piece is",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.write$/,{description:"How much of the text written into its place is typed",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.away$/,{description:"How far its old place has closed",unit:"0..1",min:0,max:1}],[/^insert\.\d+\.open$/,{description:"How much room the insert has opened",unit:"0..1",min:0,max:1}],[/^insert\.\d+\.type$/,{description:"How much of the inserted text is typed",unit:"0..1",min:0,max:1}]],n={};for(const s of t){const i=e.find(([o])=>o.test(s));i&&(n[s]=i[1])}return n}function Sg(t,e,n,s,i,o){t.beginPath(),t.moveTo(e+o,n),t.arcTo(e+s,n,e+s,n+i,o),t.arcTo(e+s,n+i,e,n+i,o),t.arcTo(e,n+i,e,n,o),t.arcTo(e,n,e+s,n,o),t.closePath()}const 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 jo=Object.keys(Ko),qv={go:"//",rust:"//",csharp:"//",javascript:"//",typescript:"//",python:"#",plain:null};function xg(t,e){const n=new Set(Ko[e]),s=qv[e],i=[],o=(a,l)=>{const c=i[i.length-1];c&&c.kind===l?c.text+=a:i.push({text:a,kind:l})};let r=0;for(;r<t.length;){const a=t[r];if(e!=="plain"&&s&&t.startsWith(s,r)){o(t.slice(r),"comment");break}if(e!=="plain"&&(a==='"'||a==="'"||a==="`")){let h=r+1;for(;h<t.length&&t[h]!==a;)h+=t[h]==="\\"?2:1;o(t.slice(r,h+1),"string"),r=h+1;continue}const l=/^[A-Za-z_][A-Za-z0-9_]*/.exec(t.slice(r));if(l){o(l[0],n.has(l[0])?"keyword":"text"),r+=l[0].length;continue}const c=/^\d[\d_.]*/.exec(t.slice(r));if(c&&e!=="plain"){o(c[0],"number"),r+=c[0].length;continue}o(a,"text"),r++}return i}const Wl='"Patrick Hand", "Segoe Print", "Bradley Hand", "Comic Sans MS", "Chalkboard SE", cursive',oi={whiteboard:{background:"#f7f7f2",frame:"#b8bcc4",ink:"#1f2a44",colors:{ink:"#1f2a44",red:"#d03b3b",blue:"#2f6fd0",green:"#2e9a52",orange:"#e07b1a"},font:Wl,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:Wl,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:Wl,stroke:.08,opacity:1,rule:{color:"#c9d6ec",spacing:1.55,margin:"#f0a3a3"}}},Dl=["circle","box","underline","arrow"],xe={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"}},Tg=90,Eg=300,Yv=.3;function Kv(t){const e=typeof t.theme=="string"?t.theme:"whiteboard";if(!(e in oi))throw new Error(`whiteboard: ${ft("theme",e,Object.keys(oi))}`);const n=typeof t.theme=="object"?{...oi.whiteboard,...t.theme}:oi[e],s=t.fontSize??28,i=t.charWidth??.55,o=y=>y===void 0?n.ink:n.colors[y]??y,r=y=>Mt(t.x+y.left,t.y+y.top,y.width,y.height),a=ts(),l=ni(a),c={},h=new Map,u=[],d=[],f=(y,T,$,M)=>{const x=h.get(y);if(!x||x.kind!=="text")throw Ye("whiteboard",M,xe,`there is no text "${y}" (texts: ${p().join(", ")||"none"})`);let S=-1;for(let P=0;P<$;P++)if(S=x.item.text.indexOf(T,S+1),S<0)throw Ye("whiteboard",M,xe,`text "${y}" has no ${$>1?`${$}th `:""}"${T}"`);const E=x.size*i;return{column:S,box:Mt(x.box.left+S*E,x.box.top,T.length*E,x.box.height)}},p=()=>[...h.values()].filter(y=>y.kind==="text").map(y=>y.item.id),g=y=>{const{kind:T,rest:$}=mn(y),M=x=>Ye("whiteboard",y,xe,x);if(T==="box"){if($)throw M("box takes no arguments");return{kind:T}}if(T==="text"||T==="mark"){if(!$)throw M(`write it ${T}:ID`);return{kind:T,id:$}}if(T==="term"){const x=/^([^:#]+)(?:#(\d+))?:(.+)$/.exec($);if(!x)throw M("write it term:ID:TEXT, or term:ID#K:TEXT for the Kth");return{kind:T,id:x[1],occurrence:x[2]?Number(x[2]):1,text:x[3]}}throw M()},m=y=>{const T=g(y);if(T.kind==="box")return Mt(0,0,t.width,t.height);if(T.kind==="term")return f(T.id,T.text,T.occurrence,y).box;const $=h.get(T.id);if(!$||$.kind!==T.kind){const M=[...h.values()].filter(x=>x.kind===T.kind).map(x=>x.item.id);throw Ye("whiteboard",y,xe,`there is no ${T.kind} "${T.id}" (${T.kind}s: ${M.join(", ")||"none"})`)}return $.box};for(const y of t.items??[]){if(!y||typeof y.id!="string"||!y.id||/[:#]/.test(y.id))throw new Error(`whiteboard: every item needs an \`id\` without ":" or "#" (got ${JSON.stringify(y?.id)})`);if(h.has(y.id))throw new Error(`whiteboard: two items are called "${y.id}"`);if("text"in y){if(!Array.isArray(y.at)||y.at.length!==2||!y.at.every(P=>typeof P=="number"))throw new Error(`whiteboard: text "${y.id}" needs \`at\`, [x, y] from the board's top-left`);const S=y.size??s,E=Mt(y.at[0],y.at[1],Math.max(1,y.text.length)*S*i,S*1.3);h.set(y.id,{kind:"text",item:y,size:S,color:o(y.color),box:E}),c[`text.${y.id}.write`]=y.hidden?0:1,c[`text.${y.id}.erase`]=0;continue}if(!Dl.includes(y.mark))throw new Error(`whiteboard: mark "${y.id}": ${ft("mark",y.mark,Dl)}`);const T=y.mark==="arrow"?["from","to"]:["around"];for(const S of T)if(typeof y[S]!="string")throw new Error(`whiteboard: ${y.mark} "${y.id}" needs \`${S}\`, a place on the board (an item before it)`);const $=new Set([y.from,y.to].filter(S=>typeof S=="string").map(S=>S.split(":")[1])),M=y.mark==="arrow"?[...h.values()].filter(S=>S.kind==="text"&&!$.has(S.item.id)).map(S=>S.box):[],x=jv(y,m,s,M);h.set(y.id,{kind:"mark",item:y,color:o(y.color),points:x,box:Uv(x)}),c[`mark.${y.id}.draw`]=y.hidden?0:1,c[`mark.${y.id}.erase`]=0}const w=y=>u.filter(T=>T.item===y),v={type:"custom",x:t.x,y:t.y,width:t.width,height:t.height,props:c,about:{kind:"whiteboard",summary:`A board with ${h.size} items. Its texts, terms and marks are places in the scene (anchor()); its edits record tracks (edit(), tracks()).`,get props(){return Vv(Object.keys(c))},actions:xe.edits},draw(y,T){const $=T.props??{},M=x=>Number($[x]??c[x]??0);if(y.save(),y.fillStyle=n.background,$g(y,0,0,t.width,t.height,10),y.fill(),y.lineWidth=Math.max(4,t.width*.012),y.strokeStyle=n.frame,y.stroke(),n.rule){y.save(),y.beginPath(),$g(y,0,0,t.width,t.height,10),y.clip(),y.lineWidth=1,y.strokeStyle=n.rule.color;const x=s*(n.rule.spacing??1.55);for(let S=x;S<t.height;S+=x)y.beginPath(),y.moveTo(0,S),y.lineTo(t.width,S),y.stroke();n.rule.margin&&(y.strokeStyle=n.rule.margin,y.beginPath(),y.moveTo(s*2.2,0),y.lineTo(s*2.2,t.height),y.stroke()),y.restore()}y.textAlign="center",y.textBaseline="middle",y.lineCap="round",y.lineJoin="round",y.globalAlpha=n.opacity;for(const x of h.values()){if(y.save(),Bl(y,x.box,M(`${x.kind}.${x.item.id}.erase`)),x.kind==="text"){const S=w(x.item.id),E=M(`text.${x.item.id}.write`)*x.item.text.length;y.font=`${x.size}px ${n.font}`,y.fillStyle=x.color;for(let P=0;P<Math.ceil(E);P++)x.item.text[P]===" "||S.some(A=>P>=A.column&&P<A.column+A.text.length)||(y.globalAlpha=n.opacity*Math.min(1,E-P),y.fillText(x.item.text[P],x.box.left+(P+.5)*x.size*i,x.box.y))}else Pg(y,x.points,M(`mark.${x.item.id}.draw`),x.color,s*n.stroke,x.item.mark==="arrow");y.restore()}for(const x of d){const S=M(`strike.${x.id}.draw`);if(S<=0)continue;const{box:E}=x,P=E.height*.15;Pg(y,[{x:E.left-3,y:E.y+P},{x:E.right+3,y:E.y-P}],S,n.colors.red??n.ink,s*n.stroke*.8,!1)}for(const x of u){const S=h.get(x.item),E=S.size*i;y.font=`${S.size}px ${n.font}`,y.fillStyle=S.color;const P=x.written;if(P){const N=M(`piece.${x.id}.write`)*P.length,Y=x.home.x-t.x-P.length*E/2;for(let V=0;V<Math.ceil(N);V++)P[V]!==" "&&(y.globalAlpha=n.opacity*Math.min(1,N-V),y.fillText(P[V],Y+(V+.5)*E,x.home.y-t.y))}const A=M(`piece.${x.id}.opacity`)*Math.min(1,M(`text.${x.item}.write`)*S.item.text.length-x.column);if(A<=0)continue;y.save();const I={x:x.home.x-t.x,y:x.home.y-t.y},_={x:M(`piece.${x.id}.x`),y:M(`piece.${x.id}.y`)};Bl(y,Mt(I.x+_.x-x.home.width/2,I.y+_.y-x.home.height/2,x.home.width,x.home.height),M(`piece.${x.id}.erase`)),Math.hypot(_.x,_.y)<1&&Bl(y,S.box,M(`text.${x.item}.erase`)),y.globalAlpha=n.opacity*Math.min(1,A),y.translate(I.x+_.x,I.y+_.y),y.rotate(M(`piece.${x.id}.rotate`)*Math.PI/180);for(let N=0;N<x.text.length;N++)x.text[N]!==" "&&y.fillText(x.text[N],(N+.5-x.text.length/2)*E,0);y.restore()}y.restore()}},k={kind:"board",about:xe,target:v,box:Mt(t.x,t.y,t.width,t.height),anchor(y){return r(m(y))},piece(y){const T=g(y);if(T.kind!=="term")throw new Error(`whiteboard.piece: a piece is a term, term:ID:TEXT, not "${y}"`);const{column:$,box:M}=f(T.id,T.text,T.occurrence,y),x=u.find(E=>E.item===T.id&&E.column===$&&E.text===T.text);if(x)return x;if(u.some(E=>E.item===T.id&&$<E.column+E.text.length&&E.column<$+T.text.length))throw new Error(`whiteboard: "${T.text}" in "${T.id}" overlaps another piece`);const S={id:u.length+1,item:T.id,column:$,text:T.text,home:r(M)};u.push(S);for(const E of["x","y","rotate","erase","write"])c[`piece.${S.id}.${E}`]=0;return c[`piece.${S.id}.opacity`]=1,S},edit(y,T,$){const M=Array.isArray(T)?T:[T];if(M.length===0)throw new Error(`whiteboard.edit: ${y} takes at least one anchor`);const x=M.map(P=>({name:P,anchor:g(P)}));for(const{name:P}of x)m(P);const S=(P,A=!1)=>{const I=x.find(_=>!P.includes(_.anchor.kind));if(I)throw new Error(`whiteboard.edit: ${y} takes ${P.join(" or ")} anchors, not "${I.name}"`);if(A&&x.length>1)throw new Error(`whiteboard.edit: ${y} takes one ${P.join(" or ")} anchor`)},E=()=>k.piece(x[0].name);if(y==="write"){if(x.some(P=>P.anchor.kind==="term")){if(S(["term"],!0),typeof $.text!="string")throw new Error("whiteboard.edit: write into a term needs `text` (the new text)");const P=E();return P.written=$.text,a.tween(`piece.${P.id}.write`,0,1,{duration:Math.max(Eg,$.text.length*Tg),...$}),k}S(["text"]);for(const{anchor:P}of x){const A=P.id,I=h.get(A).item.text;a.tween(`text.${A}.write`,0,1,{duration:Math.max(Eg,I.length*Tg),...$})}return k}if(y==="draw"){S(["mark"]);for(const{anchor:P}of x)a.tween(`mark.${P.id}.draw`,0,1,{duration:500,...$});return k}if(y==="erase"){S(["text","term","mark"]);for(const P of x){const A=P.anchor.kind==="term"?`piece.${k.piece(P.name).id}.erase`:`${P.anchor.kind}.${P.anchor.id}.erase`;a.tween(A,0,1,{duration:400,...$})}return k}if(y==="strike"){S(["text","term"]);for(const P of x){const A={id:d.length+1,box:m(P.name)};d.push(A),c[`strike.${A.id}.draw`]=0,a.tween(`strike.${A.id}.draw`,0,1,{duration:250,...$})}return k}if(y==="move"){S(["term"],!0);const P=typeof $.to=="string"?k.anchor($.to):$.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(E(),{...$,to:P})}if(y==="fling")return S(["term"],!0),k.fling(E(),$);throw si("whiteboard",y,xe)},follow(y,T){return l.follow(y,T),k},fling(y,T){return l.fling(y,T),k},move(y,T){return l.move(y,T),k},ride(y){return y},tracks:a.tracks};return k}function jv(t,e,n,s=[]){const i=He(Xt(t.id)),o=g=>(i.next()*2-1)*g,r=n*Yv;if(t.mark==="arrow"){const g=e(t.from),m=e(t.to),w=Ag(g,m,r*.6),v=Ag(m,g,r*.6),k=Math.hypot(v.x-w.x,v.y-w.y),y=Gv(w,v);let T=k*(.06+o(.04));if(t.bend!==void 0)T=k*t.bend;else{const x=Xv(w,v,y,s,r);x!==0&&(T=x)}const $={x:(w.x+v.x)/2+y.x*T,y:(w.y+v.y)/2+y.y*T},M=[];for(let x=0;x<=24;x++){const S=x/24;M.push({x:(1-S)**2*w.x+2*(1-S)*S*$.x+S*S*v.x,y:(1-S)**2*w.y+2*(1-S)*S*$.y+S*S*v.y})}return M}const a=e(t.around);if(t.mark==="underline"){const g=a.bottom+r*.4;return[{x:a.left-r*.3,y:g+o(2)},{x:a.x,y:g+2+o(2)},{x:a.right+r*.5,y:g-1+o(3)}]}if(t.mark==="box"){const g=a.left-r,m=a.right+r,w=a.top-r*.6,v=a.bottom+r*.6,k=(T,$)=>({x:T+o(r*.2),y:$+o(r*.2)}),y=k(g,w);return[y,k(m,w),k(m,v),k(g,v),y,{x:y.x+r*.8,y:y.y+o(2)}]}const l=a.width/2+r,c=a.height/2+r*.6,h=-2.2+o(.3),u=i.next()*Math.PI*2,d=1.12,f=64,p=[];for(let g=0;g<=f*d;g++){const m=g/f,w=h+m*Math.PI*2,v=1+.035*Math.sin(m*Math.PI*4+u)+.06*m;p.push({x:a.x+Math.cos(w)*l*v,y:a.y+Math.sin(w)*c*v})}return p}function Xv(t,e,n,s,i){const o=Math.hypot(e.x-t.x,e.y-t.y);if(o<1e-6)return 0;const r={x:(e.x-t.x)/o,y:(e.y-t.y)/o};let a=0,l=0;for(const c of s){const u=[{x:c.left,y:c.top},{x:c.right,y:c.top},{x:c.right,y:c.bottom},{x:c.left,y:c.bottom}].map(p=>({t:(p.x-t.x)*r.x+(p.y-t.y)*r.y,n:(p.x-t.x)*n.x+(p.y-t.y)*n.y})),d=u.some(p=>p.t>0&&p.t<o),f=u.some(p=>p.n>0)&&u.some(p=>p.n<0);!d||!f||(a=Math.max(a,...u.map(p=>p.n)),l=Math.min(l,...u.map(p=>p.n)))}return a===0&&l===0?0:a<=-l?2*(a+i):2*(l-i)}function Ag(t,e,n){const s=e.x-t.x,i=e.y-t.y;if(s===0&&i===0)return{x:t.x,y:t.y};const o=Math.min(s===0?1/0:(t.width/2+n)/Math.abs(s),i===0?1/0:(t.height/2+n)/Math.abs(i));return{x:t.x+s*o,y:t.y+i*o}}function Gv(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 Uv(t){const e=t.map(o=>o.x),n=t.map(o=>o.y),s=Math.min(...e),i=Math.min(...n);return Mt(s,i,Math.max(...e)-s,Math.max(...n)-i)}function Pg(t,e,n,s,i,o){if(n<=0||e.length<2)return;const r=[0];for(let p=1;p<e.length;p++)r.push(r[p-1]+Math.hypot(e[p].x-e[p-1].x,e[p].y-e[p-1].y));const l=r[r.length-1]*Math.min(1,n/(o?.85:1));t.strokeStyle=s,t.lineWidth=i,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let p=1;p<e.length;p++){if(r[p]<=l){t.lineTo(e[p].x,e[p].y);continue}const g=(l-r[p-1])/(r[p]-r[p-1]||1);t.lineTo(e[p-1].x+(e[p].x-e[p-1].x)*g,e[p-1].y+(e[p].y-e[p-1].y)*g);break}if(t.stroke(),!o||n<=.85)return;const c=(n-.85)/.15,h=e[e.length-1],u=e[e.length-3]??e[0],d=Math.atan2(h.y-u.y,h.x-u.x),f=i*4.5*c;t.beginPath();for(const p of[-1,1])t.moveTo(h.x,h.y),t.lineTo(h.x-Math.cos(d+p*.45)*f,h.y-Math.sin(d+p*.45)*f);t.stroke()}function Bl(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 $g(t,e,n,s,i,o){t.beginPath(),t.moveTo(e+o,n),t.arcTo(e+s,n,e+s,n+i,o),t.arcTo(e+s,n+i,e,n+i,o),t.arcTo(e,n+i,e,n,o),t.arcTo(e,n,e+s,n,o),t.closePath()}function Vv(t){const e=[[/^text\..+\.write$/,{description:"How much of the text is written",unit:"0..1",min:0,max:1}],[/^(text|mark)\..+\.erase$/,{description:"How far it has been wiped off, left to right",unit:"0..1",min:0,max:1}],[/^mark\..+\.draw$/,{description:"How much of the mark is drawn",unit:"0..1",min:0,max:1}],[/^strike\.\d+\.draw$/,{description:"How far the strike-through has drawn",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.(x|y)$/,{description:"The term moved from its home",unit:"px"}],[/^piece\.\d+\.rotate$/,{description:"The term turned",unit:"degrees"}],[/^piece\.\d+\.opacity$/,{description:"How opaque the term is",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.erase$/,{description:"How far the term has been wiped off",unit:"0..1",min:0,max:1}],[/^piece\.\d+\.write$/,{description:"How much of the text written into its place is written",unit:"0..1",min:0,max:1}]],n={};for(const s of t){const i=e.find(([o])=>o.test(s));i&&(n[s]=i[1])}return n}const zl=["bar","line","pie","donut"],Ig='system-ui, -apple-system, "Segoe UI", sans-serif',ri={light:{background:"#ffffff",text:"#3b4252",grid:"#d8dee9",color:"#4c7bd9",highlight:"#e8833a",palette:["#4c7bd9","#3fa66b","#b05cc9","#d9c04c","#4cb8c4","#d95c6f","#8a7a5a","#6b7a99"],font:Ig},dark:{background:"#1e2230",text:"#cdd6f4",grid:"#3a4055",color:"#89b4fa",highlight:"#fab387",palette:["#89b4fa","#a6e3a1","#cba6f7","#f9e2af","#94e2d5","#f38ba8","#b4a58a","#9399b2"],font:Ig}},yn={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)"}},Jv=600,Zv=500,Qv=200,tM=400,eM=.14,nM=Math.PI*2;function sM(t){if(!zl.includes(t.kind))throw new Error(`chart: ${ft("kind",t.kind,zl)}`);const e=typeof t.theme=="string"?t.theme:"light";if(!(e in ri))throw new Error(`chart: ${ft("theme",e,Object.keys(ri))}`);const n=typeof t.theme=="object"?{...ri.light,...t.theme}:ri[e];if(!Array.isArray(t.data)||t.data.length===0)throw new Error("chart: `data` needs at least one { id, value }");const s=t.kind,i=s==="pie"||s==="donut",o=Array.isArray(t.series)&&t.series.length>1,r=Array.isArray(t.series)&&t.series.length>0?t.series:[{id:"value"}];if(i&&o)throw new Error(`chart: a ${s} shows one series (got ${r.length}); make a chart per series`);const a=new Set;for(const C of r){if(typeof C?.id!="string"||!C.id||/[:.]/.test(C.id))throw new Error(`chart: every series needs an \`id\` without ":" or "." (got ${JSON.stringify(C?.id)})`);if(a.has(C.id))throw new Error(`chart: two series are called "${C.id}"`);a.add(C.id)}const l=new Map(r.map((C,G)=>[C.id,G])),c=C=>r[l.get(C)].color??(l.get(C)===0?n.color:n.palette[l.get(C)%n.palette.length]),h=new Set,u=(C,G)=>{const ot=C.values?.[G.id]??(t.series?void 0:C.value)??C.value;if(typeof ot!="number"||!Number.isFinite(ot))throw new Error(o?`chart: "${C.id}" needs a value for series "${G.id}" (\`values: { ${G.id}: … }\`)`:`chart: "${C.id}" needs a \`value\`, a number`);return ot};for(const C of t.data){if(typeof C?.id!="string"||!C.id||/[:.]/.test(C.id))throw new Error(`chart: every datum needs an \`id\` without ":" or "." (got ${JSON.stringify(C?.id)})`);if(h.has(C.id))throw new Error(`chart: two data are called "${C.id}"`);for(const G of r)u(C,G);h.add(C.id)}const d=s==="bar"?"bar":s==="line"?"point":"slice",f=Math.max(...t.data.flatMap(C=>r.map(G=>u(C,G)))),p=i?t.data.reduce((C,G)=>C+u(G,r[0]),0):t.max??Og(f*1.1);if(!i&&!(p>0))throw new Error(`chart: \`max\` must be above 0 (got ${p})`);const g=Math.max(10,Math.min(16,t.height/20)),m=o&&t.legend!==!1,w=i?void 0:t.axis?.x,v=i?void 0:t.axis?.y,k=t.title?g*2.3:g*.5,y={left:g*3.6+(v?g*1.5:0),right:t.width-g,top:(t.title?g*3:g*1.6)+(m?g*1.6:0),bottom:t.height-g*2.4-(w?g*1.4:0)},T=y.bottom-y.top,$=(y.right-y.left)/t.data.length,M=o?$*.72/r.length:$*.6,x=o?M*.86:M,S=Math.max(4,g*.35),E=T/p,P=new Map(t.data.map((C,G)=>[C.id,G])),A=C=>y.left+$*(P.get(C)+.5),I=(C,G)=>o?A(C)-$*.36+M*l.get(G)+(M-x)/2:A(C)-x/2,_=(C,G)=>I(C,G)+x/2,N=t.height-g*1.2,Y={cx:t.width/2,cy:(y.top+N)/2,r:Math.max(10,Math.min(t.width/2,(N-y.top)/2)-g*2.6)},V=s==="donut"?Y.r*.55:0,tt=s==="donut"?(V+Y.r)/2:Y.r*.62,X=new Map;if(m){let C=y.right;for(const G of[...r].reverse()){const ot=G.label??G.id,at=g*.62*ot.length+g*1.9;X.set(G.id,Mt(C-at,k,at,g*1.4)),C-=at+g*.6}}const R=ts(),z=ni(R),K={},O=(C,G,ot)=>o?`${d}.${C}.${G}.${ot}`:`${d}.${C}.${ot}`;for(const C of t.data)for(const G of r)K[O(C.id,G.id,"value")]=u(C,G),K[O(C.id,G.id,"show")]=C.hidden?0:1,K[O(C.id,G.id,"highlight")]=0,i&&(K[O(C.id,G.id,"pull")]=0);const D=(C,G)=>R.keys(C)?.length?zo(R.keys(C),G):K[C],st=(C,G,ot)=>D(O(C,G,"value"),ot)*(s==="bar"?D(O(C,G,"show"),ot):1)*E,H=C=>{const G=r[0].id,ot=t.data.map(nt=>Math.max(0,C(O(nt.id,G,"value")))*Math.max(0,Math.min(1,C(O(nt.id,G,"show"))))),at=ot.reduce((nt,Z)=>nt+Z,0),it=new Map;let lt=-Math.PI/2;return t.data.forEach((nt,Z)=>{const rt=at>0?nM*ot[Z]/at:0,ct=lt+rt/2,dt=Math.max(0,Math.min(1,C(O(nt.id,G,"pull"))))*Y.r*eM;it.set(nt.id,{start:lt,sweep:rt,mid:ct,out:dt,centre:{x:Y.cx+Math.cos(ct)*(tt+dt),y:Y.cy+Math.sin(ct)*(tt+dt)}}),lt+=rt}),it},L=C=>H(G=>D(G,C)),q=C=>{const{kind:G,rest:ot}=mn(C),at=it=>Ye("chart",C,yn,it);if(G==="box"){if(ot)throw at("box takes no arguments");return{kind:"box"}}if(G==="legend"){if(!X.has(ot))throw at(m?`there is no series "${ot}" (series: ${r.map(it=>it.id).join(", ")})`:"only a chart with several series has a legend");return{kind:"legend",series:ot}}if(G==="bar"||G==="point"||G==="slice"||G==="label"||G==="value"){if(!ot)throw at(`write it ${G}:ID`);const it=ot.indexOf(":"),lt=it<0?ot:ot.slice(0,it),nt=it<0?r[0].id:ot.slice(it+1);if(!P.has(lt))throw at(`there is no "${lt}" (data: ${[...P.keys()].join(", ")})`);if(!a.has(nt))throw at(`there is no series "${nt}" (series: ${r.map(Z=>Z.id).join(", ")})`);if(G==="label"&&it>=0)throw at("a label is one per datum: label:ID");if((G==="bar"||G==="point"||G==="slice")&&G!==d)throw at(`a ${s} chart has ${d}s, not ${G}s: ${d}:${lt}`);return{kind:G,id:lt,series:nt}}throw at()},U=(C,G)=>{if(C.kind==="box")return Mt(0,0,t.width,t.height);if(C.kind==="legend")return X.get(C.series);if(i){const nt=L(G).get(C.id),Z=Math.max(g*1.5,Y.r*.42);if(C.kind==="slice")return Mt(nt.centre.x-Z/2,nt.centre.y-Z/2,Z,Z);const rt=F(nt);return C.kind==="label"?rt:nt.sweep>=.3?Mt(nt.centre.x-g*1.6,nt.centre.y-g*.65,g*3.2,g*1.3):Mt(rt.left,rt.bottom,rt.width,g*1.3)}const ot=C.kind==="label"?A(C.id):_(C.id,C.series),at=y.bottom-st(C.id,C.series,G);if(C.kind==="bar")return Mt(ot-x/2,at,x,y.bottom-at);if(C.kind==="point")return Mt(A(C.id)-S,at-S,S*2,S*2);if(C.kind==="label")return Mt(ot-$/2,y.bottom+g*.4,$,g*1.4);const it=at-(s==="line"?S:0)-g*.3,lt=o&&s==="bar"?M:$;return Mt((s==="line"?A(C.id):ot)-lt/2,it-g*1.3,lt,g*1.3)},F=C=>{const G=Y.r+C.out+g*.9,ot={x:Y.cx+Math.cos(C.mid)*G,y:Y.cy+Math.sin(C.mid)*G},at=g*4.2,it=Math.cos(C.mid),lt=it>.2?ot.x:it<-.2?ot.x-at:ot.x-at/2;return Mt(lt,ot.y-g*.7,at,g*1.4)},W=C=>Mt(t.x+C.left,t.y+C.top,C.width,C.height),B=C=>`${t.prefix??""}${C.toFixed(t.decimals??0)}${t.suffix??""}`,J=new Map,j={type:"custom",x:t.x,y:t.y,width:t.width,height:t.height,props:K,about:{kind:`${s} chart`,summary:`A ${s} chart of ${t.data.length} values (${t.data.map(C=>C.id).join(", ")})${o?` in ${r.length} series (${r.map(C=>C.id).join(", ")})`:""}${i?"":`, scaled to ${p}`}. Its ${d}s and labels are places in the scene (anchor()); its edits record tracks (edit(), tracks()).`,props:Object.fromEntries(Object.keys(K).map(C=>[C,rM(C)])),actions:yn.edits},draw(C,G){const ot=G.props??{},at=nt=>Number(ot[nt]??K[nt]??0);if(C.save(),C.fillStyle=n.background,_g(C,0,0,t.width,t.height,8),C.fill(),C.font=`${g}px ${n.font}`,C.textBaseline="middle",t.title&&(C.fillStyle=n.text,C.textAlign="left",C.font=`600 ${g*1.2}px ${n.font}`,C.fillText(t.title,i?g:y.left,g*1.5),C.font=`${g}px ${n.font}`),m){C.textAlign="left";for(const nt of r){const Z=X.get(nt.id);C.fillStyle=c(nt.id),_g(C,Z.left,Z.top+g*.25,g*.9,g*.9,2),C.fill(),C.fillStyle=n.text,C.fillText(nt.label??nt.id,Z.left+g*1.3,Z.top+Z.height/2)}}if(i){Q(C,at),C.restore();return}C.lineWidth=1,C.textAlign="right";for(let nt=0;nt<=4;nt++){const Z=y.bottom-T*nt/4;C.strokeStyle=n.grid,C.beginPath(),C.moveTo(y.left,Z),C.lineTo(y.right,Z),C.stroke(),C.fillStyle=n.text,C.globalAlpha=.7,C.fillText(iM(p*nt/4),y.left-g*.5,Z),C.globalAlpha=1}(v||w)&&(C.fillStyle=n.text,C.textAlign="center",C.globalAlpha=.85,v&&(C.save(),C.translate(g*.9,(y.top+y.bottom)/2),C.rotate(-Math.PI/2),C.fillText(v,0,0),C.restore()),w&&C.fillText(w,(y.left+y.right)/2,y.bottom+g*2.3),C.globalAlpha=1);const it=(nt,Z)=>at(O(nt,Z,"value"))*(s==="bar"?at(O(nt,Z,"show")):1)*E,lt=(nt,Z)=>ql(c(Z),n.highlight,at(O(nt,Z,"highlight")));if(s==="line"){C.lineWidth=Math.max(2,g*.2),C.lineJoin="round",C.lineCap="round";for(const nt of r)C.strokeStyle=c(nt.id),C.beginPath(),t.data.forEach((Z,rt)=>{const ct={x:A(Z.id),y:y.bottom-it(Z.id,nt.id)},dt=at(O(Z.id,nt.id,"show"));if(rt===0){dt>0&&C.moveTo(ct.x,ct.y);return}const yt=t.data[rt-1];if(at(O(yt.id,nt.id,"show"))<1||dt<=0)return;const bt={x:A(yt.id),y:y.bottom-it(yt.id,nt.id)};C.lineTo(bt.x+(ct.x-bt.x)*dt,bt.y+(ct.y-bt.y)*dt)}),C.stroke()}C.textAlign="center";for(const nt of t.data){for(const Z of r){const rt=s==="bar"?_(nt.id,Z.id):A(nt.id),ct=it(nt.id,Z.id),dt=at(O(nt.id,Z.id,"show"));if(C.fillStyle=lt(nt.id,Z.id),s==="bar"?ct>.5&&(oM(C,rt-x/2,y.bottom-ct,x,ct,Math.min(6,x/4)),C.fill()):dt>0&&(C.beginPath(),C.arc(rt,y.bottom-ct,S*Math.min(1,dt*1.5)*(1+.3*at(O(nt.id,Z.id,"highlight"))),0,Math.PI*2),C.fill()),t.values!==!1&&dt>0){C.globalAlpha=Math.min(1,dt*2),C.font=`600 ${o?g*.85:g}px ${n.font}`,C.fillStyle=ql(n.text,n.highlight,at(O(nt.id,Z.id,"highlight")));const yt=y.bottom-ct-(s==="line"?S:0)-g*.95;C.fillText(B(at(O(nt.id,Z.id,"value"))),rt,yt),C.font=`${g}px ${n.font}`,C.globalAlpha=1}}C.fillStyle=n.text,C.fillText(nt.label??nt.id,A(nt.id),y.bottom+g*1.1)}C.strokeStyle=n.text,C.lineWidth=1.5,C.beginPath(),C.moveTo(y.left,y.bottom),C.lineTo(y.right,y.bottom),C.stroke(),C.restore()}};function Q(C,G){const ot=r[0].id,at=H(G);t.data.forEach((it,lt)=>{const nt=at.get(it.id);if(nt.sweep<=1e-4)return;const Z=J.get(it.id),rt=Z?{x:G(`piece.${Z.id}.x`),y:G(`piece.${Z.id}.y`)}:{x:0,y:0},ct=Z?G(`piece.${Z.id}.rotate`)*Math.PI/180:0,dt=Z?G(`piece.${Z.id}.opacity`):1;if(dt<=0)return;C.save(),C.globalAlpha=dt;const yt={x:Y.cx+Math.cos(nt.mid)*nt.out,y:Y.cy+Math.sin(nt.mid)*nt.out};C.translate(nt.centre.x+rt.x,nt.centre.y+rt.y),C.rotate(ct),C.translate(-nt.centre.x,-nt.centre.y),C.beginPath(),C.arc(yt.x,yt.y,Y.r,nt.start,nt.start+nt.sweep),V>0?C.arc(yt.x,yt.y,V,nt.start+nt.sweep,nt.start,!0):C.lineTo(yt.x,yt.y),C.closePath(),C.fillStyle=ql(n.palette[lt%n.palette.length],n.highlight,G(O(it.id,ot,"highlight"))),C.fill(),C.strokeStyle=n.background,C.lineWidth=Math.max(1.5,g*.15),C.stroke(),t.values!==!1&&nt.sweep>=.3&&(C.fillStyle=n.background,C.font=`600 ${g}px ${n.font}`,C.textAlign="center",C.fillText(B(G(O(it.id,ot,"value"))),nt.centre.x,nt.centre.y),C.font=`${g}px ${n.font}`),C.restore();const bt=F(nt),re=Math.cos(nt.mid);C.globalAlpha=dt,C.fillStyle=n.text,C.textAlign=re>.2?"left":re<-.2?"right":"center";const mi=re>.2?bt.left:re<-.2?bt.right:bt.left+bt.width/2;C.fillText(it.label??it.id,mi,bt.top+bt.height/2),t.values!==!1&&nt.sweep<.3&&(C.globalAlpha=dt*.8,C.fillText(B(G(O(it.id,ot,"value"))),mi,bt.bottom+g*.65)),C.globalAlpha=1})}const et={kind:"chart",chartKind:s,about:yn,target:j,max:p,box:Mt(t.x,t.y,t.width,t.height),anchor(C,G=1/0){return W(U(q(C),G))},piece(C){const G=q(C);if(G.kind!=="slice")throw new Error(i?`chart: a piece is a slice, slice:ID, not "${C}"`:`chart: a ${d} is not a piece; slices of a pie or donut are (slice:ID). Change a ${d} with edit('set' | 'show' | 'highlight', …)`);const ot=J.get(G.id);if(ot)return ot;const at={id:J.size+1,datum:G.id,home:W(U(G,0))};J.set(G.id,at);for(const it of["x","y","rotate"])K[`piece.${at.id}.${it}`]=0;return K[`piece.${at.id}.opacity`]=1,at},edit(C,G,ot){const at=Array.isArray(G)?G:[G];if(at.length===0)throw new Error(`chart.edit: ${C} takes at least one anchor`);if(!(C in yn.edits))throw si("chart",C,yn);if(C==="pull"&&!i)throw new Error(`chart.edit: pull takes slice anchors of a pie or donut; a ${s} chart has ${d}s`);const it=at.map(lt=>{const nt=q(lt);if(nt.kind!==d)throw new Error(`chart.edit: ${C} takes ${d} anchors (${d}:ID), not "${lt}"`);return nt});for(const{id:lt,series:nt}of it){const Z=rt=>O(lt,nt,rt);if(C==="set"){if(typeof ot.value!="number"||!Number.isFinite(ot.value))throw new Error("chart.edit: set needs `value`, a number");R.tween(Z("value"),D(Z("value"),ot.at),ot.value,ot,Jv)}else C==="show"?R.tween(Z("show"),D(Z("show"),ot.at),ot.on===!1?0:1,ot,Zv):C==="pull"?R.tween(Z("pull"),D(Z("pull"),ot.at),ot.on===!1?0:1,ot,tM):R.tween(Z("highlight"),D(Z("highlight"),ot.at),ot.on===!1?0:1,ot,Qv)}return et},follow(C,G){return z.follow(C,G),et},fling(C,G){return z.fling(C,G),et},move(C,G){return z.move(C,G),et},ride(C,G,ot){if(s!=="bar")return C;const at=t.data.flatMap(it=>r.map(lt=>{const nt=st(it.id,lt.id,0),Z=[...es(R.keys(O(it.id,lt.id,"value"))),...es(R.keys(O(it.id,lt.id,"show")))];return{top:t.y+y.bottom-nt,offset:rt=>nt-st(it.id,lt.id,rt),windows:Z}}));return qo(C,G,{ground:ot.ground,every:ot.every??qe,floors:at})},tracks:R.tracks};return et}function Og(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 iM(t){return Number.isInteger(t)?String(t):String(Number(t.toFixed(2)))}function ql(t,e,n){if(n<=0)return t;if(n>=1)return e;const s=r=>[1,3,5].map(a=>parseInt(r.slice(a,a+2),16));if(!/^#[0-9a-f]{6}$/i.test(t)||!/^#[0-9a-f]{6}$/i.test(e))return n<.5?t:e;const[i,o]=[s(t),s(e)];return`#${i.map((r,a)=>Math.round(r+(o[a]-r)*n).toString(16).padStart(2,"0")).join("")}`}function _g(t,e,n,s,i,o){t.beginPath(),t.moveTo(e+o,n),t.arcTo(e+s,n,e+s,n+i,o),t.arcTo(e+s,n+i,e,n+i,o),t.arcTo(e,n+i,e,n,o),t.arcTo(e,n,e+s,n,o),t.closePath()}function oM(t,e,n,s,i,o){const r=Math.min(o,i);t.beginPath(),t.moveTo(e,n+i),t.lineTo(e,n+r),t.arcTo(e,n,e+r,n,r),t.lineTo(e+s-r,n),t.arcTo(e+s,n,e+s,n+r,r),t.lineTo(e+s,n+i),t.closePath()}function rM(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 Cg(){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 Yl={youngMan:{figure:"organic",skin:"#edb98d",ink:"#53372d",headSize:.28,shoulderWidth:.074,hipWidth:.045,handSize:.078,hair:{style:"softSweep",color:"#38291f"},ears:!0,face:{style:"anime",shape:"angular",jawWidth:.83,chinWidth:.35,jawRoundness:1,eyeScale:.95,eyeAspect:1.1,nose:!0,iris:"#6a472d"},outfit:{shirt:"#bc7050",trousers:"#495a67",sleeves:"short"}},youngWoman:{figure:"organic",skin:"#f1c299",ink:"#53372d",headSize:.28,shoulderWidth:.065,hipWidth:.054,handSize:.075,body:{torso:[{at:0,width:.098},{at:.18,width:.097},{at:.44,width:.061},{at:.7,width:.087},{at:.85,width:.09},{at:1,width:.024}]},hair:{style:"flowingBob",color:"#38291f"},ears:!0,face:{style:"anime",shape:"angular",jawWidth:.78,chinWidth:.32,jawRoundness:1,eyeScale:.95,eyeAspect:1.1,nose:!0,iris:"#6a472d",lashes:!0},outfit:{shirt:"#72958b",trousers:"#6b6888",sleeves:"short",bottom:"skirt"}},childBoy:{figure:"organic",height:230,skin:"#edb98d",ink:"#53372d",headSize:.36,shoulderWidth:.052,hipWidth:.038,legLength:.82,armLength:.8,handSize:.074,body:Cg(),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:Cg(),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 aM(t,e={}){if(!Object.prototype.hasOwnProperty.call(Yl,t))throw new Error(`softCartoonCharacter: unknown actor '${t}'`);const n=Yl[t];return Vs({...n,...e,body:{...n.body,...e.body},face:{...n.face,...e.face}})}const Hg={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"}}}},Rg={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"}}}},Kl={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:me.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:me.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:me.black},ears:!0,outfit:{shirt:"#9b5fc0",trousers:"#2f2f3a",sleeves:"long"}}},grandpa:{label:"Grandpa",group:"family",scale:.96,options:{build:"stocky",hair:{style:"receding",color:me.gray},facialHair:{style:"shortBoxed",color:me.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:me.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:me.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:me.blond},hat:"sunHat",ears:!0,outfit:{shirt:"#d64535",trousers:"#4f6b3a",sleeves:"long"}}},...Hg,...Rg};function lM(t,e=300,n={}){const s=Kl[t];if(!s)throw new Error(`castMember: unknown cast member '${t}'`);return{...s.options,height:Math.round(e*s.scale),...n}}const ai={handshake:{height:.47,spacing:.42,lean:6},highFive:{height:.9,spacing:.4,lean:4},fistBump:{height:.55,spacing:.44,lean:6},handOver:{height:.52,spacing:.46,lean:8}};function cM(t,e,n){return ai[t].spacing*Math.min(e.height,n.height)}const Lg=.075;function hM(t,e,n,s={}){const i=ai[t];if(!i)throw new Error(`meetHands: unknown meeting '${t}' (one of ${Object.keys(ai).join(", ")})`);const[o,r]=e.x<=n.x?[e,n]:[n,e],a=s.view==="side",l=Math.min(o.character.height,r.character.height),c={x:(o.x+r.x)/2,y:-(s.height??i.height)*l},h=(m,w)=>{const v=w?a?1:.62:a?3:3.38;let k={...ut,...m.pose,turn:v,lean:(m.pose?.lean??0)+i.lean};const y=w?1:-1,T=($,M,x)=>{k=Se(m.character,k,$,{x:c.x+M-m.x,y:c.y,depth:x})};if(t==="handOver"){const $=Lg*l;T("arm.left",-y*$*.9,$),T("arm.right",-y*$*.9,-$)}else T("arm.right",0,0);return t==="fistBump"&&(k={...k,"hand.right.index.curl":1,"hand.right.middle.curl":1,"hand.right.ring.curl":1,"hand.right.pinky.curl":1}),k},u=h(o,!0),d=h(r,!1),f=.03*l,p=(m,w)=>{const v=oe(m.character,w),k=t==="handOver"?["hand.left","hand.right"]:["hand.right"],y=t==="handOver"?Lg*l+f:f;return k.every(T=>Math.abs(v.points[T].y-c.y)<f&&Math.abs(v.points[T].x+m.x-c.x)<y)},g=p(o,u)&&p(r,d);return e.x<=n.x?{a:u,b:d,point:c,reached:g}:{a:d,b:u,point:c,reached:g}}const Xo={spacing:.3,lean:10,tilt:8};function uM(t,e){return Xo.spacing*Math.min(t.height,e.height)}function dM(t,e,n={}){const[s,i]=t.x<=e.x?[t,e]:[e,t],o=n.view==="side",r=Math.min(s.character.height,i.character.height),a=(p,g,m)=>({over:{x:g.x-m*.02*r-p.x,y:-.72*r,depth:-.08*r},round:{x:g.x-m*.04*r-p.x,y:-.5*r,depth:.06*r}}),l=(p,g,m)=>{const w=m?o?1:.62:o?3:3.38,v=m?1:-1;let k={...ut,...p.pose,turn:w,lean:(p.pose?.lean??0)+Xo.lean,"head.tilt":(p.pose?.["head.tilt"]??0)+v*Xo.tilt};const{over:y,round:T}=a(p,g,v);return k=Se(p.character,k,"arm.right",y),k=Se(p.character,k,"arm.left",T),k},c=l(s,i,!0),h=l(i,s,!1),u=.05*r,d=(p,g,m,w)=>{const v=oe(p.character,w).points,{over:k,round:y}=a(p,g,m);return Math.hypot(v["hand.right"].x-k.x,v["hand.right"].y-k.y)<u&&Math.hypot(v["hand.left"].x-y.x,v["hand.left"].y-y.y)<u},f=d(s,i,1,c)&&d(i,s,-1,h);return t.x<=e.x?{a:c,b:h,reached:f}:{a:h,b:c,reached:f}}const bn={spacing:.32,low:.3,high:.5,helperLean:40,helperBend:16};function fM(t,e){return bn.spacing*Math.min(t.height,e.height)}function gM(t,e,n,s={}){const i=Math.max(0,Math.min(1,n)),o=s.view==="side",r=t.x<=e.x,a=Math.min(t.character.height,e.character.height),l={x:(t.x+e.x)/2,y:-(bn.low+(bn.high-bn.low)*i)*a},c=m=>m?o?1:.62:o?3:3.38;let h={...ut,...t.pose,turn:c(r),lean:(t.pose?.lean??0)+bn.helperLean*(1-i)+4,bend:(t.pose?.bend??0)+bn.helperBend*(1-i),"head.nod":18*(1-i)};h=Se(t.character,h,"arm.right",{x:l.x-t.x,y:l.y});const u={...ce.sitFloor,...e.pose,turn:c(!r)},d={...ut,...e.pose,turn:c(!r)};let f=dl(u,d,i);f=Se(e.character,f,"arm.right",{x:l.x-e.x,y:l.y});const p=.04*a,g=(m,w)=>{const v=oe(m.character,w).points["hand.right"];return Math.hypot(v.x+m.x-l.x,v.y-l.y)<p};return{helper:h,sitter:f,point:l,reached:g(t,h)&&g(e,f)}}const jl=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 pM(t,e={}){if(!Object.prototype.hasOwnProperty.call(jl,t))throw new Error(`outfitPreset: unknown category '${t}'`);const n={...jl[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 mM=.7,yM=50,bM=1.2,wM=.8,kM=3,vM=30,MM=.8,SM=.6,Xl=(t,e)=>Math.max(-e,Math.min(e,t)),xM=["hair.swing","hair.trail","hair.lift"];function Ng(t,e){const n=e.start??0,s=e.amount??1,i=Math.max(1e-6,e.headRadius);let o=NaN,r={x:0,y:0,turn:0};const a=f=>(f!==o&&(r=t(f),o=f),r),l=f=>{const p=a(f);return p.turn*90+(p.headTurn??0)},c={start:n,end:e.end,step:e.step,stiffness:e.stiffness??70,damping:e.damping??6},h=Ts(l,c),u=Ts(f=>a(f).x,c),d=Ts(f=>a(f).y,c);return h.map((f,p)=>{const g=a(f.time),m=f.value-l(f.time),w=u[p].value-g.x-(e.wind??0)*mM*i,v=d[p].value-g.y,k=Math.sin(g.turn*Math.PI/2),y=Math.cos(g.turn*Math.PI/2),T=m*kM+w*y/i*vM,$=-w*k/i*MM,M=-v/i*SM;return{time:f.time,swing:Xl(T*s,yM),trail:Xl($*s,bM),lift:Xl(M*s,wM)}})}function TM(t,e){if(t.length===0)return{"hair.swing":0,"hair.trail":0,"hair.lift":0};if(e<=t[0].time)return Fg(t[0]);if(e>=t[t.length-1].time)return Fg(t[t.length-1]);let n=0,s=t.length-1;for(;s-n>1;){const a=n+s>>1;t[a].time<=e?n=a:s=a}const i=t[n],o=t[s],r=o.time===i.time?0:(e-i.time)/(o.time-i.time);return{"hair.swing":i.swing+(o.swing-i.swing)*r,"hair.trail":i.trail+(o.trail-i.trail)*r,"hair.lift":i.lift+(o.lift-i.lift)*r}}const Fg=t=>({"hair.swing":t.swing,"hair.trail":t.trail,"hair.lift":t.lift}),ns=16,EM=1500;function AM(t,e,n,s={}){const i=n.head.hair;if(!i||!$d(i))return[];const o=e.filter(v=>v.target===t),r=o.reduce((v,k)=>k.keyframes.reduce((y,T)=>Math.max(y,T.time),v),0),a=ut,l=new Set(["x","y","turn","head.turn"]),c=new It({id:`${t}-hair-follow`,tracks:o.filter(v=>l.has(v.property))}),h=(v,k,y)=>{const T=c.getStateAtTime(v).values.get(t)?.get(k);return typeof T=="number"?T:y},u=new It({id:`${t}-hair-pose`,tracks:o}),d=v=>u.getStateAtTime(v).values.get(t),f=new Map,p=v=>{const k=Math.round(v/ns);let y=f.get(k);if(!y){const T={};for(const[M,x]of d(k*ns)??[])T[M]=x;const $=oe(n,$o(T,a,s.gaits)).head.center;f.set(k,y={x:$.x,y:$.y})}return y},g=v=>{const k=Math.floor(v/ns),y=v/ns-k,T=p(k*ns),$=p((k+1)*ns);return{x:T.x+($.x-T.x)*y,y:T.y+($.y-T.y)*y}},m=Ng(v=>{const k=g(v);return{x:h(v,"x",0)+k.x,y:h(v,"y",0)+k.y,turn:h(v,"turn",a.turn??0),headTurn:h(v,"head.turn",a["head.turn"]??0)}},{start:0,end:r+(s.settle??EM),headRadius:oe(n,ut).head.rx,step:s.step,stiffness:s.stiffness,damping:s.damping,amount:s.amount,wind:s.wind}),w=[];for(const v of xM){const k=v.slice(5);let y=m.map($=>({time:$.time,value:$[k]}));if(y.every($=>Math.abs($.value)<.001))continue;const T=o.find($=>$.property===v);if(T){const $=new It({id:`${t}-${v}-own`,tracks:[T]}),M=x=>Number($.getStateAtTime(x).values.get(t)?.get(v)??0);y=y.map(x=>({time:x.time,value:x.value+M(x.time)}))}w.push({id:`${t}-${v}`,target:t,property:v,keyframes:y})}return w}const wn={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 Gl(t){if(t===void 0)return wn.full;if(typeof t=="string")return wn[t];const{base:e,...n}=t;return{...wn[e??"full"],...n}}const Ul=160,PM=120,$M=700,Vl=60,IM=90,Go=3200,ss=1,kn=1e-6;function Uo(t,e,n={}){const s=Gl(n.style),i=n.seed??1,o={};if(t.length===0)return o;const r=Object.keys(t[0].pose).filter(u=>t.some(d=>Math.abs(d.pose[u]-t[0].pose[u])>kn));for(const u of r)o[u]=OM(u,t,e,s,i);const a=e.blink,l=a!==void 0&&r.includes(a);if(s.blinks&&a!==void 0&&!l&&a in t[0].pose){const u=_M(t,e,s,i,t[0].pose[a]);u.length>0&&(o[a]=u)}const{lift:c,stretch:h}=e;if(s.jumpSquash>0&&c&&h&&r.includes(c)&&!r.includes(h)&&h in t[0].pose){const u=CM(t,c,t[0].pose[h],s.jumpSquash);u.length>0&&(o[h]=u)}return o}function OM(t,e,n,s,i){const o=n.eyes.includes(t),r=n.limits[t],a=r!==void 0,l=o?-s.eyeLead:(n.depth[t]??1)*s.overlap,c=f=>{const p=(e[f].time-e[f-1].time)/2;return Math.max(-p,Math.min(p,l))},h=[{time:e[0].time,value:e[0].pose[t]}],u=(f,p,g)=>{const m=h[h.length-1];if(f<=m.time+ss){h[h.length-1]={...m,value:p,...g?{easing:g}:{}};return}h.push({time:f,value:p,...g?{easing:g}:{}})};let d=e[0].pose[t];for(let f=1;f<e.length;f++){const p=e[f],g=e[f-1].pose[t],m=p.pose[t],w=m-g,v=h[h.length-1].time,k=p.act!==!1;if(Math.abs(w)<=kn){const P=p.time+(k?c(f):0);if(f===e.length-1)Math.abs(d-m)>kn&&u(Math.max(P,v+Ul),m,"ease-in-out"),d=m;else if(k&&a&&s.drift>0&&n.drift.includes(t)&&P-v>=$M){const A=Xt(`${i}:${t}:${f}`)%2===0?1:-1;d=m+A*s.drift*r,u(P,d,"ease-in-out")}continue}if(!k){u(e[f-1].time,d),u(p.time,m,p.easing),d=m;continue}const y=c(f),T=Math.max(e[f-1].time+y,v);let $=p.time+y;o&&s.eyeDart>0&&($=Math.min($,T+s.eyeDart));const M=$-T;if(M<=ss){u(p.time,m,p.easing),d=m;continue}u(T,d);const x=Math.sign(w);if(a&&s.anticipation>0&&r>0&&M>=Ul){const P=d-x*Math.min(Math.abs(w)*s.anticipation,r),A=T+M*s.anticipationTime;u(A,P,"ease-in-out"),s.hold>0&&u(A+M*s.hold,P)}const S=f+1<e.length?e[f+1].time-p.time:1/0,E=Math.min(s.settle,S/2);if(a&&s.overshoot>0&&r>0&&M>=PM&&E>ss){const P=Math.min(Math.abs(w)*s.overshoot,r);u($,m+x*P,p.easing??s.actionEase),u($+E,m,s.settleEase)}else u($,m,p.easing??s.actionEase);d=m}return h}function _M(t,e,n,s,i){const o=[],r=Vl+IM;for(let f=1;f<t.length;f++){const p=t[f-1].pose,g=t[f].pose;Object.entries(e.headTurns).some(([w,v])=>Math.abs((g[w]??0)-(p[w]??0))>v)&&t[f].act!==!1&&o.push(Math.max(t[0].time,t[f-1].time-n.eyeLead))}const a=t[0].time,l=t[t.length-1].time,c=[...o];let h=a+Go*.6,u=0;for(;h<l;){c.some(g=>Math.abs(g-h)<Go/2)||o.push(h);const p=(Xt(`${s}:blink:${u++}`)%1e3/1e3-.5)*(Go*.66);h+=Go+p}o.sort((f,p)=>f-p);const d=[{time:a,value:i}];for(const f of o){const p=d[d.length-1].time;f+Vl<=p+ss||(f>p+ss&&d.push({time:f,value:i}),d.push({time:f+Vl,value:1,easing:"ease-in"}),d.push({time:f+r,value:i,easing:"ease-out"}))}return d.length>1?d:[]}function CM(t,e,n,s){const i=n*(1-.18*s),o=n*(1+.14*s),r=[{time:t[0].time,value:n}],a=(l,c,h)=>{const u=r[r.length-1];l<=u.time+ss||r.push({time:l,value:c,...h?{easing:h}:{}})};for(let l=1;l<t.length;l++){const c=t[l-1].pose[e],h=t[l].pose[e],u=t[l-1].time,d=t[l].time,f=d-u;if(!(f<Ul||t[l].act===!1)){if(c<=kn&&h>kn)a(u,n),a(u+f*.2,i,"ease-out"),a(u+f*.45,o,"ease-out"),a(d,n,"ease-in-out");else if(c>kn&&h<=kn){const p=l+1<t.length?t[l+1].time-d:400;a(u+f*.5,n),a(d-Math.min(60,f*.15),o,"ease-in"),a(d,i,"ease-out"),a(d+Math.min(260,p/2),n,{type:"back",mode:"out",overshoot:1.4})}}}return r.length>1?r:[]}const Wg={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 HM(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 RM(){const t={},e={};for(const n of Object.keys(ut)){const s=HM(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 Dg=RM();function Bg(t,e){return Object.entries(e).map(([n,s])=>({id:`${t}-${n}`,target:t,property:n,keyframes:s}))}function zg(t,e,n={}){const s=to(e),i=e.map((o,r)=>({time:o.time,pose:{...s[r]},easing:o.easing,act:o.act}));return Bg(t,Uo(i,n.rig??Wg,n))}function qg(t,e,n={}){const s=n.rest??ut,i=fl(e,s),o=e.map((r,a)=>({time:r.time,pose:{...s,...i[a]},easing:r.easing,act:r.act}));return Bg(t,Uo(o,n.rig??Dg,n))}const Yg=vt.shocked,LM=vt.scared,Ke={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,...Yg,headTilt:0},easing:"ease-out-cubic"},{after:720,pose:{rise:.25,stretch:1.25,bend:-10,leftShoulder:140,rightShoulder:140},easing:"ease-in-out"},{after:900,pose:{rise:0,stretch:.74,bend:12,leftShoulder:70,rightShoulder:70,leftHip:18,rightHip:18,leftKnee:30,rightKnee:30},easing:"ease-in-quad"},{after:1060,pose:{stretch:1.06,bend:-3,leftShoulder:60,rightShoulder:60,leftHip:t.leftHip,rightHip:t.rightHip,leftKnee:t.leftKnee,rightKnee:t.rightKnee},easing:"ease-out"},{after:1260,pose:{stretch:t.stretch,bend:t.bend,...vt.surprised,leftShoulder:70,rightShoulder:70,leftElbow:60,rightElbow:60},easing:"ease-in-out"}],doubleTake:t=>[{after:160,pose:{lookX:1,lookY:0},easing:"ease-out"},{after:520,pose:{lookX:-.6,headTilt:t.headTilt-4,smile:.6,mouth:0},easing:"ease-in-out"},{after:1100,pose:{lookX:-.6}},{after:1180,pose:{bend:t.bend-10,headTilt:t.headTilt+10,rise:.05,stretch:1.18,...Yg,lookX:1,lookY:0},easing:"ease-out-cubic"},{after:1360,pose:{rise:0,stretch:.88,bend:t.bend+4,headTilt:t.headTilt+4},easing:"ease-in-quad"},{after:1560,pose:{stretch:t.stretch,bend:t.bend,headTilt:t.headTilt},easing:{type:"elastic",mode:"out",amplitude:1,period:.35}}],windUp:()=>[{after:220,pose:{lean:-18,bend:-16,headTilt:-6,leftShoulder:70,leftElbow:-100,rightShoulder:40,rightElbow:100,leftHip:-45,leftKnee:-80,stretch:.92,...vt.angry,lookX:1},easing:"ease-out"},{after:620,pose:{lean:-20,bend:-18,stretch:.9}},{after:700,pose:{lean:28,bend:14,headTilt:6,leftShoulder:30,rightShoulder:60,leftHip:30,leftKnee:-30,rightHip:-20,stretch:1.12},easing:"ease-out-cubic"}],land:t=>[{after:120,pose:{rise:0,stretch:.7,bend:14,leftShoulder:75,rightShoulder:75,leftHip:20,rightHip:20,leftKnee:35,rightKnee:35},easing:"ease-in-quad"},{after:300,pose:{stretch:1.05,bend:-4,leftShoulder:t.leftShoulder,rightShoulder:t.rightShoulder},easing:"ease-out"},{after:460,pose:{rise:0,stretch:t.stretch,bend:t.bend,leftHip:ht.leftHip,rightHip:ht.rightHip,leftKnee:0,rightKnee:0},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...LM,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:{...Jt.sad,bend:18,stretch:.92,lean:t.lean+5,turn:t.turn,sit:t.sit},easing:"ease-in-out"}]};function Jl(t,e){const n=typeof e.from=="string"?Jt[e.from]:e.from??ht;return Zl(Ke[t](n),{...e,from:n})}function Zl(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 li(t,e=1){const n=Ke[t](ht);return n[n.length-1].after*e}function Kg(t,e,n={}){if(e.length<2)return;const s=Math.max(1,Math.round(n.lines??3)),i=n.spacing??5,o=n.lineWidth??2,r=n.opacity??.7;t.save(),t.strokeStyle=n.color??"#222",t.lineCap="round";for(let a=0;a<s;a++){const l=(a-(s-1)/2)*i,c=Math.floor(Math.abs(l)/Math.max(i,1)*(e.length/6));for(let h=c+1;h<e.length;h++){const u=e[h-1],d=e[h],f=d.x-u.x,p=d.y-u.y,g=Math.hypot(f,p)||1,m=-p/g,w=f/g,v=1-h/(e.length-1);t.globalAlpha=r*(1-v),t.lineWidth=o*(1-v*.7),t.beginPath(),t.moveTo(u.x+m*l,u.y+w*l),t.lineTo(d.x+m*l,d.y+w*l),t.stroke()}}t.restore()}const NM={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 FM(t,e,n,s,i={}){const o=n.stateAt;if(!o)return;const r=i.length??120,a=Math.max(2,Math.round(i.samples??8)),l=Math.max(0,n.time-r);if(n.time-l<1)return;const c=[];for(let f=0;f<a;f++){const p=l+(n.time-l)*f/(a-1);c.push(Ta(e,{time:p,state:o(p)},s).joints)}const h=c[c.length-1].height,u=(i.threshold??1.2)*h,d=(i.parts??["hands","toes","head"]).flatMap(f=>NM[f]);for(const f of d){const p=c.map(f.at);let g=0;for(let v=1;v<p.length;v++)g+=Math.hypot(p[v].x-p[v-1].x,p[v].y-p[v-1].y);const m=g/((n.time-l)/1e3);if(m<=u)continue;const w=Math.min(1,(m-u)/(u*.5));Kg(t,p,{...i,opacity:(i.opacity??.7)*w,spacing:i.spacing??h*.02})}}function jg(t,e,n,s={}){if(n<=0||n>=1)return;const i=s.size??40,o=s.seed??1,r=.45+.55*(1-(1-n)**3);t.save(),t.strokeStyle=s.color??"#555",t.lineWidth=Math.max(1,i*.03),t.globalAlpha=Math.min(1,n/.08)*(1-n);for(let a=0;a<5;a++){const l=Xt(`${o}:puff:${a}`)%1e3/1e3,c=a-2,h=e.x+c*i*.3*r,u=e.y-i*(.06+.12*l)*r+Math.abs(c)*i*.03,d=i*(.11+.07*l)*r;t.beginPath(),t.arc(h,u,d,Math.PI*.95,Math.PI*2.05),t.stroke()}t.restore()}function WM(t,e,n,s={}){if(n<=0||n>=1)return;const i=s.size??40,o=5,r=1-(1-n)**2;t.save(),t.strokeStyle=s.color??"#222",t.lineWidth=Math.max(1,i*.035),t.lineJoin="round",t.globalAlpha=n<.7?1:(1-n)/.3;for(let a=0;a<o;a++){const l=-Math.PI/2+(a-(o-1)/2)*Math.PI/(o+1),c=i*(.3+.7*r),h=e.x+Math.cos(l)*c,u=e.y+Math.sin(l)*c;DM(t,h,u,i*.14,n*Math.PI+a),t.stroke()}t.restore()}function DM(t,e,n,s,i){t.beginPath();for(let o=0;o<10;o++){const r=o%2===0?s:s*.45,a=i+o*Math.PI/5-Math.PI/2,l=e+Math.cos(a)*r,c=n+Math.sin(a)*r;o===0?t.moveTo(l,c):t.lineTo(l,c)}t.closePath()}const ci={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 Ql(t={}){return[...Object.keys(Dt),...Object.keys(Jt),...Object.keys(Ke),...Object.keys(ci),...Object.keys(t.gaits??{}),...Object.keys(t.actions??{})]}function tc(t={}){const e=new Set(Ql()),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 ec(t={}){const e={};for(const n of Object.keys(Dt))e[n]=`Walks to \`to\` in the ${n} gait, feet planted, turning round first if needed.`;for(const n of Object.keys(Jt))e[n]=`Moves into the ${n} pose and holds it.`;for(const n of Object.keys(Ke))e[n]=`The ${n} gag, built on the current pose.`;for(const[n,s]of Object.entries(ci))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"],BM={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"],vn=t=>typeof t=="number"&&Number.isFinite(t);function hi(t,e={}){const n=tc(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=Ql(e),i=l=>l in Dt||l in(e.gaits??{}),o=Object.keys(vt),r=Object.keys(ht);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(ft("beat field",g,Vo,BM[g.toLowerCase()]));const f=d.do;if(f===void 0){h(`A beat needs \`do\` (what happens). Actions: ${s.join(", ")}`);return}if(typeof f!="string"||!s.includes(f)){h(ft("action",f,s));return}const p=ci[f]??e.actions?.[f];for(const g of p?.needs??[])d[g]===void 0&&h(`\`${f}\` needs \`${g}\`.`);if(i(f)&&d.to===void 0&&u(`\`${f}\` without \`to\` walks nowhere.`),f==="leap"&&d.to===void 0&&d.onto===void 0&&u("`leap` without `to` or `onto` jumps on the spot."),d.mood!==void 0&&(typeof d.mood!="string"||!o.includes(d.mood))&&h(ft("mood",d.mood,o)),d.pose!==void 0)if(!d.pose||typeof d.pose!="object"||Array.isArray(d.pose))h("`pose` is joints to change, an object like { rightShoulder: 90 } (for a named pose, use it as the action).");else for(const[g,m]of Object.entries(d.pose))r.includes(g)?vn(m)||h(`Pose joint \`${g}\` must be a number (got ${JSON.stringify(m)}).`):h(ft("pose joint",g,r));for(const g of["at","for"]){const m=d[g];m!==void 0&&!(vn(m)&&m>=0)&&h(`\`${g}\` is milliseconds, a number ≥ 0 (got ${JSON.stringify(m)}).`)}vn(d.at)&&(d.at<a&&u(`\`at\` ${d.at} is before an earlier beat's \`at\` (${a}); beats run in order, so it starts when the one before ends.`),a=d.at);for(const g of["to","onto"]){const m=d[g];m!==void 0&&!vn(m)&&h(`\`${g}\` is a scene ${g==="to"?"x":"y"} in px, a number (got ${JSON.stringify(m)}).`)}if(d.toward!==void 0&&!vn(d.toward)&&!Jo.includes(d.toward)&&h(`\`toward\` is a scene x or one of ${Jo.join(", ")}${typeof d.toward=="string"&&xs(d.toward,Jo)?` (did you mean "${xs(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"||!vn(g.x)||!vn(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 nc(t,e={},n="scriptTracks"){const s=hi(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
|
-
`)}`)}aw(Dl);function nM(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 sM(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 gg=8;function zo(t,e={},n=0){if(n>gg)throw new Error(`scriptTracks: custom actions nest more than ${gg} deep (does one build itself?)`);return t.flatMap(s=>{const i=e[s.do];if(!i||!("beats"in i))return[s];const o=i.beats(s).map((r,a)=>a===0?{...r,...s.at!==void 0&&r.at===void 0?{at:s.at}:{},...s.mood&&!r.mood?{mood:s.mood}:{},...s.say&&!r.say?{say:s.say}:{}}:r);return zo(o,e,n+1)})}function pg(t){return t.length===0?0:Math.max(...t.map(e=>e.after))}const Bl={walk:1e3,bouncy:900,doubleBounce:1100,sneak:1600,strut:1100,tired:1500,shove:1300,run:560},iM=450,oM=2.4,rM=160,mg=2.5,aM=200,lM=340,cM=1.1,yg=[380,900],hM=.35,qo=300,zl=150,uM=260,dM=1.2,ql=160,bg=400,ni=300,fM=450,wg=500,Yl=350,kg=150,gM=120,jl=180,vg=420,pM=300,Mg=300,mM=140,Kl=150,Sg=450,yM=450,Xl=150,Tg=350,xg=400,bM=12,wM=600,Eg=90,Ag=400,kM=200,vM=.09,Pg=350,Se=450,Gl=1200,MM=700,ts=320,Te=220,SM=65,TM=700,$g=t=>t in Ye,xM=t=>t in Vt;function Ig(t){return Math.max(TM,Array.from(t).length*SM)}function Yo(t,e,n={}){const s={actions:n.actions,gaits:n.gaits};Wl(e,s);const i=n.gait??"walk",o=zo(e,n.actions).map(P=>P.do==="go"?{...P,do:i}:P);Wl(o,s,"scriptTracks (after expanding custom actions)");const r=P=>Wt[P]??n.gaits?.[P],a=P=>Bl[P]??n.gaits?.[P]?.cycle??1e3,l=P=>{const H=n.actions?.[P];return H&&"steps"in H?H:void 0},c=n.from??0,h=n.ground??0,u=n.height??300;let d=c,f=h,p=n.facing??1,g=n.start??ct,m=0,w=0;const v=[{time:0,pose:g}],k=[{time:0,value:0}],b=[{time:0,value:0}],E=[{time:0,value:0}],$=[{time:0,value:0}],S=[{time:0,value:"walk"}],x=[{time:0,value:p}],M=[],T=[],I=[],A=(P,H,W,q)=>{g={...g,...H},W&&(g=Le(g,W)),v.push({time:P,pose:g,...q===!1?{act:q}:{}})},_=(P,H,W)=>(A(P+ts/2,{turn:0},W),x.push({time:P+ts/2,value:p},{time:P+ts/2+1,value:H}),p=H,A(P+ts,{turn:1}),P+ts),C=P=>P<d?-1:1,N=(P,H,W)=>C(H)!==p?_(P,C(H),W):P,B=(P,H,W,q="arm")=>{const D=q==="arm",K=ae({...P,...D?{rightShoulder:0,rightElbow:0}:{rightHip:0,rightKnee:0}},{height:u,facing:p}),V=D?K.shoulders.right:K.hip,F=D?K.elbows.right:K.knees.right,X=(et,rt)=>Math.atan2(p*et,rt)*180/Math.PI,Q=((X(H-(d+V.x),W-(f+V.y))-X(F.x-V.x,F.y-V.y))%360+360)%360;return Q>270?Q-360:Q},G=(P,H,W,q)=>{const D=q==="arm",K=ae({...P,...D?{rightShoulder:90,rightElbow:0,rightWrist:0}:{rightHip:90,rightKnee:0}},{height:u,facing:p}),V=D?K.shoulders.right:K.hip,F=D?{x:(K.hands.right.x+K.fingertips.right.x)/2,y:(K.hands.right.y+K.fingertips.right.y)/2}:K.feet.right,X=Math.hypot(F.x-V.x,F.y-V.y)*((D?n.reach?.arm:n.reach?.leg)??1),j=W-(f+V.y),Q=Math.abs(j)<X?Math.sqrt(X*X-j*j):X*.1;return H-V.x-p*Q},Z=P=>{const H=ae(P,{height:u,facing:p});return{x:d+(H.hands.right.x+H.fingertips.right.x)/2,y:f+(H.hands.right.y+H.fingertips.right.y)/2}},Y=(P,H,W)=>{const q={...P,rightWrist:0,rightElbow:0,rightShoulder:B(P,H,W)},D=ae(q,{height:u,facing:p}),K={x:d+D.shoulders.right.x,y:f+D.shoulders.right.y},V={x:d+D.elbows.right.x,y:f+D.elbows.right.y},F=Z(q),X=Math.hypot(V.x-K.x,V.y-K.y),j=Math.hypot(F.x-V.x,F.y-V.y),Q=Math.min(X+j-.01,Math.max(Math.abs(X-j)+.01,Math.hypot(H-K.x,W-K.y))),et=nt=>nt*180/Math.PI,rt=et(Math.acos((X*X+Q*Q-j*j)/(2*X*Q))),at=180-et(Math.acos((X*X+j*j-Q*Q)/(2*X*j)));let R={rightShoulder:q.rightShoulder,rightElbow:0},J=1/0;for(const nt of[1,-1])for(const ot of[1,-1]){const st={rightShoulder:q.rightShoulder+nt*rt,rightElbow:ot*at},lt={...P,rightWrist:0,...st},tt=Z(lt),it=Math.hypot(tt.x-H,tt.y-W)-ae(lt,{height:u,facing:p}).elbows.right.y*.001;it<J&&(J=it,R=st)}return R},L=(P,H,W)=>Math.abs(H-d)<2?P:(k.push({time:P,value:d-c},{time:P+W,value:H-c,easing:"ease-in-out"}),d=H,P+W);for(const P of o){const H=Math.max(P.at??w,w===0?0:v[v.length-1].time);let W=H,q,D;const K=P.pose??{},V=l(P.do);if(r(P.do)){const F=P.to??d,X=F===d?p:C(F);let j=H;X!==p?j=_(H,X,P.mood):g.turn<1?(j=H+Te,A(j,{turn:1,...K},P.mood)):(P.mood||P.pose)&&A(H+Te,K,P.mood);const et=Math.abs(F-d)/Bi(r(P.do),u),rt=P.for??Math.max(Te*2,et*a(P.do)),at=j+rt;S.push({time:j,value:P.do}),$.push({time:j,value:0},{time:j+Te,value:1,easing:"ease-out"}),$.push({time:at-Te,value:1},{time:at,value:0,easing:"ease-in"}),E.push({time:j,value:m},{time:at,value:m+et}),k.push({time:j,value:d-c},{time:at,value:F-c}),m+=et,d=F,A(at,{}),W=at}else if(P.do==="zip"){const F=P.to??d,X=F===d?p:C(F);let j=H;X!==p?j=_(H,X,P.mood):g.turn<1&&(j=H+Te,A(j,{turn:1},P.mood));const Q=Rl("windUp",{at:j,from:P.mood?Le(g,P.mood):g});v.push(...Q),g=Q[Q.length-1].pose;const et=j+Qs("windUp"),rt=et+iM,at=rt+Math.max(rM,Math.abs(F-d)/oM);S.push({time:et,value:"run"}),$.push({time:et,value:0},{time:et+80,value:1,easing:"ease-out"},{time:at,value:1},{time:at+120,value:0}),E.push({time:et,value:m},{time:rt,value:m+mg,easing:"ease-in"}),m+=mg+(at-rt)/Bl.run*1.5,E.push({time:at,value:m}),k.push({time:rt,value:d-c},{time:at,value:F-c,easing:"ease-in"}),I.push({kind:"dust",time:rt,x:d,y:f,length:900}),d=F,A(at,{}),W=at}else if(P.do==="leap"){const F=P.to??d,X=P.onto??f;let j=F===d?H:N(H,F,P.mood);g.turn<1&&(j+=Te,A(j,{turn:1},P.mood));const Q={leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50};A(j+aM,{stretch:.75,bend:12,leftHip:22,rightHip:22,...Q},P.mood,!1);const et=j+lM;A(et-40,{stretch:.72},void 0,!1),A(et,{stretch:1.2,bend:-6,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4},void 0,!1);const rt=Math.hypot(F-d,X-f),at=P.for??Math.min(yg[1],Math.max(yg[0],300+rt*cM)),R=Math.min(f,X)-hM*u,J=Math.sqrt(f-R),nt=Math.sqrt(X-R),ot=et+at*J/(J+nt),st=et+at;A(ot,{stretch:1,bend:4,leftHip:-55,leftKnee:-80,rightHip:55,rightKnee:80,leftShoulder:110,rightShoulder:110},void 0,!1),A(st,{stretch:.72,bend:12,leftShoulder:75,rightShoulder:75,leftElbow:0,rightElbow:0,leftHip:18,rightHip:18,leftKnee:0,rightKnee:0},void 0,!1),A(st+180,{stretch:1.05,bend:-3},void 0,!1),A(st+340,{stretch:1,bend:0,leftHip:ct.leftHip,rightHip:ct.rightHip,leftShoulder:ct.leftShoulder,rightShoulder:ct.rightShoulder,leftElbow:ct.leftElbow,rightElbow:ct.rightElbow},void 0,!1),k.push({time:et,value:d-c},{time:st,value:F-c}),b.push({time:et,value:f-h},{time:ot,value:R-h,easing:"ease-out-quad"},{time:st,value:X-h,easing:"ease-in-quad"}),d=F,f=X,I.push({kind:"dust",time:st,x:d,y:f,length:500}),W=st+340,q=st}else if(P.do==="point"&&P.target){const F=P.target,X=N(H,F.x,P.mood),j={...g,...P.mood?vt[P.mood]:{},turn:Math.max(g.turn,.6),rightElbow:0,rightWrist:0,...K},Q=ae(j,{height:u,facing:p}).head.center,et=Math.abs(F.x-(d+Q.x)),rt=F.y-(f+Q.y),at=X+Se;A(at,{...j,rightShoulder:B(j,F.x,F.y),lookX:1,lookY:EM(rt/Math.max(1,Math.hypot(et,rt)))*.8}),W=at+(P.for??Gl),q=at,D=W}else if(P.do==="swipe"){const F=P.target??{x:d+p*u*.5,y:f-u*.6},X=C(F.x),j=N(H,F.x,P.mood),Q=X===1?F.left??F.x:F.right??F.x,et=X===1?F.right??F.x:F.left??F.x,rt={...g,turn:1,lean:-10,bend:-8,rightElbow:40,lookX:1,...K};A(j+qo,{...rt,rightShoulder:B(rt,d-p*u*.3,f-u*1.1)},P.mood,!1);const at={...g,lean:6,bend:4,rightElbow:0,rightWrist:0},R={...g,lean:14,bend:12,rightElbow:0,rightWrist:0};L(j,G(at,Q,F.y,"arm"),qo+zl),A(j+qo+zl,{lean:-12},void 0,!1);const J=j+qo+zl+80;A(J,{...at,rightShoulder:B(at,Q,F.y)},void 0,!1);const nt=J+(P.for??Math.max(uM,Math.abs(et-Q)/dM));k.push({time:J,value:d-c}),d=G(R,et,F.y,"arm"),k.push({time:nt,value:d-c}),A(nt,{...R,rightShoulder:B(R,et,F.y)},void 0,!1),A(nt+ql,{lean:16,bend:14,rightShoulder:B(g,et+X*u*.4,F.y+u*.25)},void 0,!1),A(nt+ql+bg,{lean:0,bend:0,rightShoulder:ct.rightShoulder,rightElbow:ct.rightElbow}),W=nt+ql+bg,q=J,D=nt}else if(P.do==="grab"&&P.target){const F=P.target,X=N(H,F.x,P.mood),j=F.y>f-u*.5,Q={...g,turn:1,rightElbow:0,bend:j?35:0,lean:j?12:0,stretch:j?.75:1,lookX:1,lookY:j?.8:0,...K},rt=L(X,G(Q,F.x,F.y,"arm"),ni)+fM;A(rt,{...Q,rightShoulder:B(Q,F.x,F.y)},P.mood,!1),A(rt+120,{},void 0,!1),A(rt+wg,{bend:0,lean:-3,stretch:1,rightShoulder:165,rightElbow:20,lookY:-.6}),W=rt+wg+150,q=rt}else if(P.do==="throw"){const F=P.target?.x??P.to??d+p*u,X=N(H,F,P.mood),j={...g,turn:1,lean:-12,bend:-10,rightElbow:60,stretch:.95,lookX:1,lookY:-.3,...K};A(X+Yl,{...j,rightShoulder:B(j,d-p*u*.4,f-u*1.05)},P.mood,!1),A(X+Yl+kg,{lean:-14},void 0,!1);const Q=X+Yl+kg+gM,et={...g,lean:14,bend:12,rightElbow:0,stretch:1.04};v.push({time:Q,pose:g={...et,rightShoulder:B(et,d+p*u,f-u*1.1)},easing:"ease-in",act:!1}),A(Q+jl,{lean:18,bend:14,rightShoulder:55,stretch:1},void 0,!1),A(Q+jl+vg,{lean:0,bend:0,rightShoulder:ct.rightShoulder,rightElbow:ct.rightElbow,lookY:0}),W=Q+jl+vg,q=Q,D=Q}else if(P.do==="kick"&&P.target){const F=P.target,X=N(H,F.x,P.mood),j={...g,turn:1,lean:-12,bend:-6,rightKnee:0,leftShoulder:100,rightShoulder:70},Q=L(X,G(j,F.x,F.y,"leg"),pM),et={leftShoulder:70,rightShoulder:50,leftElbow:-20,rightElbow:20};A(Q+Mg,{turn:1,lean:8,bend:6,rightHip:-40,rightKnee:80,lookX:1,lookY:.7,...et,...K},P.mood,!1);const rt=Q+Mg+mM,at=B(j,F.x,F.y,"leg");v.push({time:rt,pose:g={...g,...j,rightHip:at},easing:"ease-in",act:!1}),A(rt+Kl,{lean:-15,rightHip:at+20},void 0,!1),A(rt+Kl+Sg,{lean:0,bend:0,rightHip:ct.rightHip,rightKnee:0,leftShoulder:ct.leftShoulder,rightShoulder:ct.rightShoulder,leftElbow:ct.leftElbow,rightElbow:ct.rightElbow,lookY:0}),W=rt+Kl+Sg,q=rt}else if(P.do==="put"&&P.target){const F=P.target,X=N(H,F.x,P.mood),j=F.y>f-u*.5,Q={...g,turn:1,rightElbow:0,rightWrist:0,bend:j?35:0,lean:j?12:0,stretch:j?.75:1,lookX:1,lookY:j?.8:0,...K},rt=L(X,G(Q,F.x,F.y,"arm"),ni)+yM;A(rt,{...Q,rightShoulder:B(Q,F.x,F.y)},P.mood,!1),A(rt+Xl,{},void 0,!1),A(rt+Xl+Tg,{bend:0,lean:0,stretch:1,rightShoulder:ct.rightShoulder,rightElbow:ct.rightElbow,lookY:0}),W=rt+Xl+Tg,q=rt}else if(P.do==="write"&&P.target){const F=P.target,X=F.left??F.x,j=F.right??F.x,Q=N(H,(X+j)/2,P.mood),et={...g,turn:1,rightElbow:0,rightWrist:0,...vt.thinking,lookX:1,lookY:0,...K},rt=tt=>G(et,tt,F.y,"arm")+p*u*.08,at=tt=>{const U=Z({...et,...Y(et,tt,F.y),rightWrist:0});return Math.hypot(U.x-tt,U.y-F.y)<2},R=p===1?X:j,J=L(Q,rt((X+j)/2),ni),nt=!at(X)||!at(j),ot=nt?L(J,rt(X),ni)+xg:J+xg;A(ot,{...et,...Y(et,nt?X:R,F.y)},P.mood,!1);const st=P.for??Math.max(wM,Math.abs(j-X)*bM);nt&&k.push({time:ot,value:d-c});for(let tt=Eg,U=0;tt<=st;tt+=Eg,U++){const it=X+(j-X)*Math.min(tt,st)/st;nt&&(d=rt(it),k.push({time:ot+tt,value:d-c}));const ut=(U%2===0?-1:1)*u*.02;A(ot+tt,Y(et,it,F.y+ut),void 0,!1)}const lt=ot+st;A(lt,Y(et,j,F.y),void 0,!1),A(lt+Ag,{rightShoulder:ct.rightShoulder,rightElbow:ct.rightElbow,...vt.happy}),W=lt+Ag,q=ot,D=lt}else if(P.do==="push"&&P.target){const F=P.target,X=P.to??F.x,j=N(H,d+(X>=F.x?1:-1),P.mood),Q=p===1?F.left??F.x:F.right??F.x,et={...g,turn:1,lean:16,bend:8,rightWrist:0,leftWrist:0,lookX:1,...K},rt=G(et,Q,F.y,"arm"),at=L(j,rt+p*u*.06,ni),R=Y(et,Q,F.y),J={...et,...R,leftShoulder:-R.rightShoulder,leftElbow:-R.rightElbow},nt=at+kM;A(nt,J,P.mood,!1);const ot=Math.abs(X-F.x),st=nt+(P.for??Math.max(600,ot/vM)),lt=ot/Bi("shove",u);S.push({time:nt,value:"shove"}),$.push({time:nt,value:0},{time:nt+Te,value:1,easing:"ease-out"},{time:st-Te,value:1},{time:st,value:0,easing:"ease-in"}),E.push({time:nt,value:m},{time:st,value:m+lt}),m+=lt,k.push({time:nt,value:d-c},{time:st,value:d+(X-F.x)-c}),d+=X-F.x,A(st,{},void 0,!1),A(st+Pg,{lean:0,bend:0,rightShoulder:ct.rightShoulder,leftShoulder:ct.leftShoulder,rightElbow:ct.rightElbow,leftElbow:ct.leftElbow}),W=st+Pg,q=nt,D=st}else if(V){const F=P.mood?Le(g,P.mood):g,X=V.steps(F,P),j=Ll(X,{at:H,from:F});v.push(...j),g=j[j.length-1].pose,W=H+Math.max(pg(X),P.for??0)}else if($g(P.do)){const F=Rl(P.do,{at:H,from:P.mood?Le(g,P.mood):g});v.push(...F),g=F[F.length-1].pose,W=H+Qs(P.do),P.do==="take"&&I.push({kind:"dust",time:H+900,x:d,y:f,length:500}),P.do==="land"&&I.push({kind:"dust",time:H+120,x:d,y:f,length:500})}else if(P.do==="look"||P.do==="face"){const F=P.toward??"viewer",X=P.for??MM;if(F==="viewer")A(H+Se,{turn:0,lookX:0,lookY:0,...K},P.mood);else if(F==="ahead")A(H+Se,{turn:P.do==="face"?1:.6,lookX:1,...K},P.mood);else if(F==="back")A(H+Se,{turn:.2,lookX:-1,...K},P.mood);else{const j=C(F);j!==p&&P.do==="face"?(_(H,j,P.mood),A(H+ts+1,{lookX:1,...K})):j!==p?A(H+Se,{turn:.25,lookX:-1,...K},P.mood):A(H+Se,{turn:P.do==="face"?1:.6,lookX:1,...K},P.mood)}W=H+Math.max(X,Se)}else if(xM(P.do)||P.do==="stand"){const F=P.do==="stand"?n.rest??ct:Vt[P.do],X=F.turn!==ct.turn?F.turn:g.turn,j=P.mood?vt[P.mood]:{lookX:g.lookX,lookY:g.lookY};A(H+Se,{...F,turn:X,...j,...K}),W=H+(P.for??Gl)}else{const F=P.for??(P.say?Ig(P.say):Gl);(P.mood||P.pose)&&A(H+Math.min(Se,F/2),K,P.mood),W=H+F}if(P.say){const F=r(P.do)||$g(P.do)||V?H:H+Math.min(150,(W-H)/4),X=r(P.do)?W:Math.max(F+200,W-100);M.push({text:P.say,start:F,end:X}),P.do==="say"&&$M(v,g,F,X)}P.onto!==void 0&&P.do!=="leap"&&P.onto!==f&&(b.push({time:H,value:f-h},{time:W,value:P.onto-h,easing:"ease-in-out"}),f=P.onto),W>v[v.length-1].time&&v.push({time:W,pose:g}),T.push({start:H,end:W,...q!==void 0?{contact:q}:{},...D!==void 0?{release:D}:{}}),w=W}const z=cg(t,PM(v),n),O=[{id:`${t}-x`,target:t,property:"x",keyframes:k},{id:`${t}-y`,target:t,property:"y",keyframes:b},{id:`${t}-walk`,target:t,property:"walk",keyframes:E},{id:`${t}-walking`,target:t,property:"walking",keyframes:$},{id:`${t}-gait`,target:t,property:"gait",keyframes:S},{id:`${t}-facing`,target:t,property:"facing",keyframes:x}].filter(P=>P.keyframes.length>1||P.property==="x"||P.property==="facing"&&P.keyframes[0].value===-1);return{tracks:[...$o(t,z,M,{energy:n.energy}),...O],duration:w,lines:M,keys:v,beats:T,effects:I}}const EM=t=>Math.max(-1,Math.min(1,t)),AM=30;function PM(t){const e=[];for(const n of t){const s=e[e.length-1];s&&n.time-s.time<AM?e[e.length-1]={...n,time:s.time}:e.push(n)}return e}function $M(t,e,n,s){const o=t.filter(l=>l.time>n),r=t.filter(l=>l.time<=n),a=[];for(let l=n+520,c=0;l<s-520/2;l+=520,c++){const h=c%2===0?3:-2;a.push({time:l,pose:{...e,headTilt:e.headTilt+h,leftBrow:e.leftBrow+(c%2===0?.25:0),rightBrow:e.rightBrow+(c%2===0?.25:0)}})}a.length>0&&a.push({time:s,pose:e}),t.length=0,t.push(...r,...a.filter(l=>!o.some(c=>Math.abs(c.time-l.time)<60)),...o),t.sort((l,c)=>l.time-c.time)}function Ul(t,e,n){const s=new It({id:`${t}-hand`,tracks:e.filter(l=>l.target===t)}),i=pa({x:n.x,y:n.y,style:n.style,cast:n.cast}),o=n.side??"right",r=n.every??33,a=[];for(let l=n.start;;l=Math.min(n.end,l+r)){const{joints:c}=ma(i,{time:l,state:s.getStateAtTime(l)},t),h=c.hands[o],u=c.fingertips[o];if(a.push({time:l,x:(h.x+u.x)/2,y:(h.y+u.y)/2}),l>=n.end)break}return a}const es=["start","contact","release","end"],IM=["surface","edit","anchor","at","until"],OM=["carry"],jo=t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&"surface"in t&&"anchor"in t,_M=t=>t.then===void 0?[]:Array.isArray(t.then)?t.then:[t.then];function CM(t,e,n,s={}){const i=Og(n,e,s).filter(d=>d.level==="error");if(i.length>0)throw new Error(`surfaceScript: ${i.length} problem(s) in the beats:
|
|
58
|
+
`)}`)}Dw(ec);function zM(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 qM(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 Xg=8;function Zo(t,e={},n=0){if(n>Xg)throw new Error(`scriptTracks: custom actions nest more than ${Xg} deep (does one build itself?)`);return t.flatMap(s=>{const i=e[s.do];if(!i||!("beats"in i))return[s];const o=i.beats(s).map((r,a)=>a===0?{...r,...s.at!==void 0&&r.at===void 0?{at:s.at}:{},...s.mood&&!r.mood?{mood:s.mood}:{},...s.say&&!r.say?{say:s.say}:{}}:r);return Zo(o,e,n+1)})}function Gg(t){return t.length===0?0:Math.max(...t.map(e=>e.after))}const sc={walk:1e3,bouncy:900,doubleBounce:1100,sneak:1600,strut:1100,tired:1500,shove:1300,run:560},YM=450,KM=2.4,jM=160,Ug=2.5,XM=200,GM=340,UM=1.1,Vg=[380,900],VM=.35,Qo=300,ic=150,JM=260,ZM=1.2,oc=160,Jg=400,ui=300,QM=450,Zg=500,rc=350,Qg=150,tS=120,ac=180,tp=420,eS=300,ep=300,nS=140,lc=150,np=450,sS=450,cc=150,sp=350,ip=400,iS=12,oS=600,op=90,rp=400,rS=200,aS=.09,ap=350,Te=450,hc=1200,lS=700,is=320,Ee=220,cS=65,hS=700,lp=t=>t in Ke,uS=t=>t in Jt;function cp(t){return Math.max(hS,Array.from(t).length*cS)}function tr(t,e,n={}){const s={actions:n.actions,gaits:n.gaits};nc(e,s);const i=n.gait??"walk",o=Zo(e,n.actions).map(O=>O.do==="go"?{...O,do:i}:O);nc(o,s,"scriptTracks (after expanding custom actions)");const r=O=>Dt[O]??n.gaits?.[O],a=O=>sc[O]??n.gaits?.[O]?.cycle??1e3,l=O=>{const D=n.actions?.[O];return D&&"steps"in D?D:void 0},c=n.from??0,h=n.ground??0,u=n.height??300;let d=c,f=h,p=n.facing??1,g=n.start??ht,m=0,w=0;const v=[{time:0,pose:g}],k=[{time:0,value:0}],y=[{time:0,value:0}],T=[{time:0,value:0}],$=[{time:0,value:0}],M=[{time:0,value:"walk"}],x=[{time:0,value:p}],S=[],E=[],P=[],A=(O,D,st,H)=>{g={...g,...D},st&&(g=Fe(g,st)),v.push({time:O,pose:g,...H===!1?{act:H}:{}})},I=(O,D,st)=>(A(O+is/2,{turn:0},st),x.push({time:O+is/2,value:p},{time:O+is/2+1,value:D}),p=D,A(O+is,{turn:1}),O+is),_=O=>O<d?-1:1,N=(O,D,st)=>_(D)!==p?I(O,_(D),st):O,Y=(O,D,st,H="arm")=>{const L=H==="arm",q=le({...O,...L?{rightShoulder:0,rightElbow:0}:{rightHip:0,rightKnee:0}},{height:u,facing:p}),U=L?q.shoulders.right:q.hip,F=L?q.elbows.right:q.knees.right,W=(j,Q)=>Math.atan2(p*j,Q)*180/Math.PI,J=((W(D-(d+U.x),st-(f+U.y))-W(F.x-U.x,F.y-U.y))%360+360)%360;return J>270?J-360:J},V=(O,D,st,H)=>{const L=H==="arm",q=le({...O,...L?{rightShoulder:90,rightElbow:0,rightWrist:0}:{rightHip:90,rightKnee:0}},{height:u,facing:p}),U=L?q.shoulders.right:q.hip,F=L?{x:(q.hands.right.x+q.fingertips.right.x)/2,y:(q.hands.right.y+q.fingertips.right.y)/2}:q.feet.right,W=Math.hypot(F.x-U.x,F.y-U.y)*((L?n.reach?.arm:n.reach?.leg)??1),B=st-(f+U.y),J=Math.abs(B)<W?Math.sqrt(W*W-B*B):W*.1;return D-U.x-p*J},tt=O=>{const D=le(O,{height:u,facing:p});return{x:d+(D.hands.right.x+D.fingertips.right.x)/2,y:f+(D.hands.right.y+D.fingertips.right.y)/2}},X=(O,D,st)=>{const H={...O,rightWrist:0,rightElbow:0,rightShoulder:Y(O,D,st)},L=le(H,{height:u,facing:p}),q={x:d+L.shoulders.right.x,y:f+L.shoulders.right.y},U={x:d+L.elbows.right.x,y:f+L.elbows.right.y},F=tt(H),W=Math.hypot(U.x-q.x,U.y-q.y),B=Math.hypot(F.x-U.x,F.y-U.y),J=Math.min(W+B-.01,Math.max(Math.abs(W-B)+.01,Math.hypot(D-q.x,st-q.y))),j=ot=>ot*180/Math.PI,Q=j(Math.acos((W*W+J*J-B*B)/(2*W*J))),et=180-j(Math.acos((W*W+B*B-J*J)/(2*W*B)));let C={rightShoulder:H.rightShoulder,rightElbow:0},G=1/0;for(const ot of[1,-1])for(const at of[1,-1]){const it={rightShoulder:H.rightShoulder+ot*Q,rightElbow:at*et},lt={...O,rightWrist:0,...it},nt=tt(lt),rt=Math.hypot(nt.x-D,nt.y-st)-le(lt,{height:u,facing:p}).elbows.right.y*.001;rt<G&&(G=rt,C=it)}return C},R=(O,D,st)=>Math.abs(D-d)<2?O:(k.push({time:O,value:d-c},{time:O+st,value:D-c,easing:"ease-in-out"}),d=D,O+st);for(const O of o){const D=Math.max(O.at??w,w===0?0:v[v.length-1].time);let st=D,H,L;const q=O.pose??{},U=l(O.do);if(r(O.do)){const F=O.to??d,W=F===d?p:_(F);let B=D;W!==p?B=I(D,W,O.mood):g.turn<1?(B=D+Ee,A(B,{turn:1,...q},O.mood)):(O.mood||O.pose)&&A(D+Ee,q,O.mood);const j=Math.abs(F-d)/Ji(r(O.do),u),Q=O.for??Math.max(Ee*2,j*a(O.do)),et=B+Q;M.push({time:B,value:O.do}),$.push({time:B,value:0},{time:B+Ee,value:1,easing:"ease-out"}),$.push({time:et-Ee,value:1},{time:et,value:0,easing:"ease-in"}),T.push({time:B,value:m},{time:et,value:m+j}),k.push({time:B,value:d-c},{time:et,value:F-c}),m+=j,d=F,A(et,{}),st=et}else if(O.do==="zip"){const F=O.to??d,W=F===d?p:_(F);let B=D;W!==p?B=I(D,W,O.mood):g.turn<1&&(B=D+Ee,A(B,{turn:1},O.mood));const J=Jl("windUp",{at:B,from:O.mood?Fe(g,O.mood):g});v.push(...J),g=J[J.length-1].pose;const j=B+li("windUp"),Q=j+YM,et=Q+Math.max(jM,Math.abs(F-d)/KM);M.push({time:j,value:"run"}),$.push({time:j,value:0},{time:j+80,value:1,easing:"ease-out"},{time:et,value:1},{time:et+120,value:0}),T.push({time:j,value:m},{time:Q,value:m+Ug,easing:"ease-in"}),m+=Ug+(et-Q)/sc.run*1.5,T.push({time:et,value:m}),k.push({time:Q,value:d-c},{time:et,value:F-c,easing:"ease-in"}),P.push({kind:"dust",time:Q,x:d,y:f,length:900}),d=F,A(et,{}),st=et}else if(O.do==="leap"){const F=O.to??d,W=O.onto??f;let B=F===d?D:N(D,F,O.mood);g.turn<1&&(B+=Ee,A(B,{turn:1},O.mood));const J={leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50};A(B+XM,{stretch:.75,bend:12,leftHip:22,rightHip:22,...J},O.mood,!1);const j=B+GM;A(j-40,{stretch:.72},void 0,!1),A(j,{stretch:1.2,bend:-6,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4},void 0,!1);const Q=Math.hypot(F-d,W-f),et=O.for??Math.min(Vg[1],Math.max(Vg[0],300+Q*UM)),C=Math.min(f,W)-VM*u,G=Math.sqrt(f-C),ot=Math.sqrt(W-C),at=j+et*G/(G+ot),it=j+et;A(at,{stretch:1,bend:4,leftHip:-55,leftKnee:-80,rightHip:55,rightKnee:80,leftShoulder:110,rightShoulder:110},void 0,!1),A(it,{stretch:.72,bend:12,leftShoulder:75,rightShoulder:75,leftElbow:0,rightElbow:0,leftHip:18,rightHip:18,leftKnee:0,rightKnee:0},void 0,!1),A(it+180,{stretch:1.05,bend:-3},void 0,!1),A(it+340,{stretch:1,bend:0,leftHip:ht.leftHip,rightHip:ht.rightHip,leftShoulder:ht.leftShoulder,rightShoulder:ht.rightShoulder,leftElbow:ht.leftElbow,rightElbow:ht.rightElbow},void 0,!1),k.push({time:j,value:d-c},{time:it,value:F-c}),y.push({time:j,value:f-h},{time:at,value:C-h,easing:"ease-out-quad"},{time:it,value:W-h,easing:"ease-in-quad"}),d=F,f=W,P.push({kind:"dust",time:it,x:d,y:f,length:500}),st=it+340,H=it}else if(O.do==="point"&&O.target){const F=O.target,W=N(D,F.x,O.mood),B={...g,...O.mood?vt[O.mood]:{},turn:Math.max(g.turn,.6),rightElbow:0,rightWrist:0,...q},J=le(B,{height:u,facing:p}).head.center,j=Math.abs(F.x-(d+J.x)),Q=F.y-(f+J.y),et=W+Te;A(et,{...B,rightShoulder:Y(B,F.x,F.y),lookX:1,lookY:dS(Q/Math.max(1,Math.hypot(j,Q)))*.8}),st=et+(O.for??hc),H=et,L=st}else if(O.do==="swipe"){const F=O.target??{x:d+p*u*.5,y:f-u*.6},W=_(F.x),B=N(D,F.x,O.mood),J=W===1?F.left??F.x:F.right??F.x,j=W===1?F.right??F.x:F.left??F.x,Q={...g,turn:1,lean:-10,bend:-8,rightElbow:40,lookX:1,...q};A(B+Qo,{...Q,rightShoulder:Y(Q,d-p*u*.3,f-u*1.1)},O.mood,!1);const et={...g,lean:6,bend:4,rightElbow:0,rightWrist:0},C={...g,lean:14,bend:12,rightElbow:0,rightWrist:0};R(B,V(et,J,F.y,"arm"),Qo+ic),A(B+Qo+ic,{lean:-12},void 0,!1);const G=B+Qo+ic+80;A(G,{...et,rightShoulder:Y(et,J,F.y)},void 0,!1);const ot=G+(O.for??Math.max(JM,Math.abs(j-J)/ZM));k.push({time:G,value:d-c}),d=V(C,j,F.y,"arm"),k.push({time:ot,value:d-c}),A(ot,{...C,rightShoulder:Y(C,j,F.y)},void 0,!1),A(ot+oc,{lean:16,bend:14,rightShoulder:Y(g,j+W*u*.4,F.y+u*.25)},void 0,!1),A(ot+oc+Jg,{lean:0,bend:0,rightShoulder:ht.rightShoulder,rightElbow:ht.rightElbow}),st=ot+oc+Jg,H=G,L=ot}else if(O.do==="grab"&&O.target){const F=O.target,W=N(D,F.x,O.mood),B=F.y>f-u*.5,J={...g,turn:1,rightElbow:0,bend:B?35:0,lean:B?12:0,stretch:B?.75:1,lookX:1,lookY:B?.8:0,...q},Q=R(W,V(J,F.x,F.y,"arm"),ui)+QM;A(Q,{...J,rightShoulder:Y(J,F.x,F.y)},O.mood,!1),A(Q+120,{},void 0,!1),A(Q+Zg,{bend:0,lean:-3,stretch:1,rightShoulder:165,rightElbow:20,lookY:-.6}),st=Q+Zg+150,H=Q}else if(O.do==="throw"){const F=O.target?.x??O.to??d+p*u,W=N(D,F,O.mood),B={...g,turn:1,lean:-12,bend:-10,rightElbow:60,stretch:.95,lookX:1,lookY:-.3,...q};A(W+rc,{...B,rightShoulder:Y(B,d-p*u*.4,f-u*1.05)},O.mood,!1),A(W+rc+Qg,{lean:-14},void 0,!1);const J=W+rc+Qg+tS,j={...g,lean:14,bend:12,rightElbow:0,stretch:1.04};v.push({time:J,pose:g={...j,rightShoulder:Y(j,d+p*u,f-u*1.1)},easing:"ease-in",act:!1}),A(J+ac,{lean:18,bend:14,rightShoulder:55,stretch:1},void 0,!1),A(J+ac+tp,{lean:0,bend:0,rightShoulder:ht.rightShoulder,rightElbow:ht.rightElbow,lookY:0}),st=J+ac+tp,H=J,L=J}else if(O.do==="kick"&&O.target){const F=O.target,W=N(D,F.x,O.mood),B={...g,turn:1,lean:-12,bend:-6,rightKnee:0,leftShoulder:100,rightShoulder:70},J=R(W,V(B,F.x,F.y,"leg"),eS),j={leftShoulder:70,rightShoulder:50,leftElbow:-20,rightElbow:20};A(J+ep,{turn:1,lean:8,bend:6,rightHip:-40,rightKnee:80,lookX:1,lookY:.7,...j,...q},O.mood,!1);const Q=J+ep+nS,et=Y(B,F.x,F.y,"leg");v.push({time:Q,pose:g={...g,...B,rightHip:et},easing:"ease-in",act:!1}),A(Q+lc,{lean:-15,rightHip:et+20},void 0,!1),A(Q+lc+np,{lean:0,bend:0,rightHip:ht.rightHip,rightKnee:0,leftShoulder:ht.leftShoulder,rightShoulder:ht.rightShoulder,leftElbow:ht.leftElbow,rightElbow:ht.rightElbow,lookY:0}),st=Q+lc+np,H=Q}else if(O.do==="put"&&O.target){const F=O.target,W=N(D,F.x,O.mood),B=F.y>f-u*.5,J={...g,turn:1,rightElbow:0,rightWrist:0,bend:B?35:0,lean:B?12:0,stretch:B?.75:1,lookX:1,lookY:B?.8:0,...q},Q=R(W,V(J,F.x,F.y,"arm"),ui)+sS;A(Q,{...J,rightShoulder:Y(J,F.x,F.y)},O.mood,!1),A(Q+cc,{},void 0,!1),A(Q+cc+sp,{bend:0,lean:0,stretch:1,rightShoulder:ht.rightShoulder,rightElbow:ht.rightElbow,lookY:0}),st=Q+cc+sp,H=Q}else if(O.do==="write"&&O.target){const F=O.target,W=F.left??F.x,B=F.right??F.x,J=N(D,(W+B)/2,O.mood),j={...g,turn:1,rightElbow:0,rightWrist:0,...vt.thinking,lookX:1,lookY:0,...q},Q=nt=>V(j,nt,F.y,"arm")+p*u*.08,et=nt=>{const Z=tt({...j,...X(j,nt,F.y),rightWrist:0});return Math.hypot(Z.x-nt,Z.y-F.y)<2},C=p===1?W:B,G=R(J,Q((W+B)/2),ui),ot=!et(W)||!et(B),at=ot?R(G,Q(W),ui)+ip:G+ip;A(at,{...j,...X(j,ot?W:C,F.y)},O.mood,!1);const it=O.for??Math.max(oS,Math.abs(B-W)*iS);ot&&k.push({time:at,value:d-c});for(let nt=op,Z=0;nt<=it;nt+=op,Z++){const rt=W+(B-W)*Math.min(nt,it)/it;ot&&(d=Q(rt),k.push({time:at+nt,value:d-c}));const ct=(Z%2===0?-1:1)*u*.02;A(at+nt,X(j,rt,F.y+ct),void 0,!1)}const lt=at+it;A(lt,X(j,B,F.y),void 0,!1),A(lt+rp,{rightShoulder:ht.rightShoulder,rightElbow:ht.rightElbow,...vt.happy}),st=lt+rp,H=at,L=lt}else if(O.do==="push"&&O.target){const F=O.target,W=O.to??F.x,B=N(D,d+(W>=F.x?1:-1),O.mood),J=p===1?F.left??F.x:F.right??F.x,j={...g,turn:1,lean:16,bend:8,rightWrist:0,leftWrist:0,lookX:1,...q},Q=V(j,J,F.y,"arm"),et=R(B,Q+p*u*.06,ui),C=X(j,J,F.y),G={...j,...C,leftShoulder:-C.rightShoulder,leftElbow:-C.rightElbow},ot=et+rS;A(ot,G,O.mood,!1);const at=Math.abs(W-F.x),it=ot+(O.for??Math.max(600,at/aS)),lt=at/Ji("shove",u);M.push({time:ot,value:"shove"}),$.push({time:ot,value:0},{time:ot+Ee,value:1,easing:"ease-out"},{time:it-Ee,value:1},{time:it,value:0,easing:"ease-in"}),T.push({time:ot,value:m},{time:it,value:m+lt}),m+=lt,k.push({time:ot,value:d-c},{time:it,value:d+(W-F.x)-c}),d+=W-F.x,A(it,{},void 0,!1),A(it+ap,{lean:0,bend:0,rightShoulder:ht.rightShoulder,leftShoulder:ht.leftShoulder,rightElbow:ht.rightElbow,leftElbow:ht.leftElbow}),st=it+ap,H=ot,L=it}else if(U){const F=O.mood?Fe(g,O.mood):g,W=U.steps(F,O),B=Zl(W,{at:D,from:F});v.push(...B),g=B[B.length-1].pose,st=D+Math.max(Gg(W),O.for??0)}else if(lp(O.do)){const F=Jl(O.do,{at:D,from:O.mood?Fe(g,O.mood):g});v.push(...F),g=F[F.length-1].pose,st=D+li(O.do),O.do==="take"&&P.push({kind:"dust",time:D+900,x:d,y:f,length:500}),O.do==="land"&&P.push({kind:"dust",time:D+120,x:d,y:f,length:500})}else if(O.do==="look"||O.do==="face"){const F=O.toward??"viewer",W=O.for??lS;if(F==="viewer")A(D+Te,{turn:0,lookX:0,lookY:0,...q},O.mood);else if(F==="ahead")A(D+Te,{turn:O.do==="face"?1:.6,lookX:1,...q},O.mood);else if(F==="back")A(D+Te,{turn:.2,lookX:-1,...q},O.mood);else{const B=_(F);B!==p&&O.do==="face"?(I(D,B,O.mood),A(D+is+1,{lookX:1,...q})):B!==p?A(D+Te,{turn:.25,lookX:-1,...q},O.mood):A(D+Te,{turn:O.do==="face"?1:.6,lookX:1,...q},O.mood)}st=D+Math.max(W,Te)}else if(uS(O.do)||O.do==="stand"){const F=O.do==="stand"?n.rest??ht:Jt[O.do],W=F.turn!==ht.turn?F.turn:g.turn,B=O.mood?vt[O.mood]:{lookX:g.lookX,lookY:g.lookY};A(D+Te,{...F,turn:W,...B,...q}),st=D+(O.for??hc)}else{const F=O.for??(O.say?cp(O.say):hc);(O.mood||O.pose)&&A(D+Math.min(Te,F/2),q,O.mood),st=D+F}if(O.say){const F=r(O.do)||lp(O.do)||U?D:D+Math.min(150,(st-D)/4),W=r(O.do)?st:Math.max(F+200,st-100);S.push({text:O.say,start:F,end:W}),O.do==="say"&&pS(v,g,F,W)}O.onto!==void 0&&O.do!=="leap"&&O.onto!==f&&(y.push({time:D,value:f-h},{time:st,value:O.onto-h,easing:"ease-in-out"}),f=O.onto),st>v[v.length-1].time&&v.push({time:st,pose:g}),E.push({start:D,end:st,...H!==void 0?{contact:H}:{},...L!==void 0?{release:L}:{}}),w=st}const z=zg(t,gS(v),n),K=[{id:`${t}-x`,target:t,property:"x",keyframes:k},{id:`${t}-y`,target:t,property:"y",keyframes:y},{id:`${t}-walk`,target:t,property:"walk",keyframes:T},{id:`${t}-walking`,target:t,property:"walking",keyframes:$},{id:`${t}-gait`,target:t,property:"gait",keyframes:M},{id:`${t}-facing`,target:t,property:"facing",keyframes:x}].filter(O=>O.keyframes.length>1||O.property==="x"||O.property==="facing"&&O.keyframes[0].value===-1);return{tracks:[...Wo(t,z,S,{energy:n.energy}),...K],duration:w,lines:S,keys:v,beats:E,effects:P}}const dS=t=>Math.max(-1,Math.min(1,t)),fS=30;function gS(t){const e=[];for(const n of t){const s=e[e.length-1];s&&n.time-s.time<fS?e[e.length-1]={...n,time:s.time}:e.push(n)}return e}function pS(t,e,n,s){const o=t.filter(l=>l.time>n),r=t.filter(l=>l.time<=n),a=[];for(let l=n+520,c=0;l<s-520/2;l+=520,c++){const h=c%2===0?3:-2;a.push({time:l,pose:{...e,headTilt:e.headTilt+h,leftBrow:e.leftBrow+(c%2===0?.25:0),rightBrow:e.rightBrow+(c%2===0?.25:0)}})}a.length>0&&a.push({time:s,pose:e}),t.length=0,t.push(...r,...a.filter(l=>!o.some(c=>Math.abs(c.time-l.time)<60)),...o),t.sort((l,c)=>l.time-c.time)}function uc(t,e,n){const s=new It({id:`${t}-hand`,tracks:e.filter(l=>l.target===t)}),i=xa({x:n.x,y:n.y,style:n.style,cast:n.cast}),o=n.side??"right",r=n.every??33,a=[];for(let l=n.start;;l=Math.min(n.end,l+r)){const{joints:c}=Ta(i,{time:l,state:s.getStateAtTime(l)},t),h=c.hands[o],u=c.fingertips[o];if(a.push({time:l,x:(h.x+u.x)/2,y:(h.y+u.y)/2}),l>=n.end)break}return a}const os=["start","contact","release","end"],mS=["surface","edit","anchor","at","until"],yS=["carry"],er=t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&"surface"in t&&"anchor"in t,bS=t=>t.then===void 0?[]:Array.isArray(t.then)?t.then:[t.then];function wS(t,e,n,s={}){const i=hp(n,e,s).filter(d=>d.level==="error");if(i.length>0)throw new Error(`surfaceScript: ${i.length} problem(s) in the beats:
|
|
59
59
|
${i.map(d=>` ${d.beat>=0?`beat ${d.beat}: `:""}${d.message}`).join(`
|
|
60
|
-
`)}`);const o=n.map(d=>_g(d,e)),r=Yo(t,o,s),a=HM(o,r.beats,s),l=s.ground??0,c=d=>s.ride===!1?d:Object.values(e).reduce((f,p)=>p.ride(f,t,{ground:l}),d);n.forEach((d,f)=>{for(const p of _M(d)){const g=b=>new Error(`surfaceScript: beat ${f} (${d.do}), ${p.edit} on ${p.surface}: ${b}`),m=(b,E)=>{const $=typeof b=="object"?b.beat:f,S=(typeof b=="object"?b.at:b)??E??"start",x=a[$][S];if(x===void 0){const M=es.filter(T=>a[$][T]!==void 0).join(", ");throw g(`beat ${$} (${n[$].do}) has no ${S} (it has ${M})`)}return x},w=e[p.surface],v=m(p.at??(a[f].contact!==void 0?"contact":"start")),k=p.until===void 0?void 0:m(p.until,"end");if(k!==void 0&&k<v)throw g(`it ends (${k} ms) before it starts (${v} ms)`);try{if(p.edit==="carry"){const E=w.piece(p.anchor),$=Ul(t,c(r.tracks),{x:s.from??0,y:l,style:s.figureStyle??(s.height?{height:s.height}:void 0),cast:s,start:v,end:k});w.follow(E,$);continue}const b=Object.fromEntries(Object.entries(p).filter(([E])=>!IM.includes(E)));w.edit(p.edit,p.anchor,{...b,at:v,...k!==void 0?{duration:k-v}:{}})}catch(b){throw g(b.message)}}});const h=c(r.tracks),u=Object.entries(e).flatMap(([d,f])=>f.tracks(d));return{...r,tracks:[...h,...u],figureTracks:h}}function Og(t,e,n={}){if(!Array.isArray(t))return ei(t,n);const s=[],i=Object.keys(e),o=(c,h,u)=>{const d=typeof h=="string"?e[h]:void 0;return d||s.push({level:"error",beat:c,message:`${u}: ${dt("surface",h,i)}`}),d},r=(c,h,u,d)=>{if(typeof u!="string"){s.push({level:"error",beat:c,message:`${d}: \`anchor\` is a place name such as ${Object.keys(h.about.anchors).join(", ")} (got ${JSON.stringify(u)}).`});return}try{h.anchor(u,0)}catch(f){s.push({level:"error",beat:c,message:`${d}: ${f.message}`})}},a=(c,h,u)=>{const d=typeof h=="object"&&h!==null?h.at:h;if(typeof h=="object"&&h!==null){const f=h.beat;if((typeof f!="number"||!Number.isInteger(f)||f<c||f>=t.length)&&s.push({level:"error",beat:c,message:`${u}: \`beat\` is the index of this beat or a later one, ${c} to ${t.length-1} (got ${JSON.stringify(f)}).`}),d===void 0)return}typeof d=="number"?s.push({level:"error",beat:c,message:`${u}: a cue starts at a moment of its beat (${es.join(", ")}), not at ms; set the beat's own \`at\` to move it.`}):(typeof d!="string"||!es.includes(d))&&s.push({level:"error",beat:c,message:`${u}: ${dt("moment",d,es)}`})};t.forEach((c,h)=>{if(!c||typeof c!="object"||Array.isArray(c))return;const u=c;for(const f of["target","to","onto"]){if(!jo(u[f]))continue;const p=u[f],g=o(h,p.surface,`\`${f}\``);g&&r(h,g,p.anchor,`\`${f}\``)}if(u.then===void 0)return;(Array.isArray(u.then)?u.then:[u.then]).forEach(f=>{if(!f||typeof f!="object"||Array.isArray(f)){s.push({level:"error",beat:h,message:"`then` is a cue, { surface, edit, anchor, at?, until? }, or a list of them."});return}const p=f,g=o(h,p.surface,"`then`");if(!g)return;const m=`\`then\` (${String(p.edit)} on ${String(p.surface)})`,w=[...Object.keys(g.about.edits),...OM];if(typeof p.edit!="string"||!w.includes(p.edit)){s.push({level:"error",beat:h,message:`\`then\`: ${dt("edit",p.edit,w)}`});return}for(const v of Array.isArray(p.anchor)?p.anchor:[p.anchor])r(h,g,v,m);p.edit==="carry"&&typeof p.anchor!="string"&&s.push({level:"error",beat:h,message:`${m}: \`carry\` takes one anchor, the piece it carries.`}),p.edit==="carry"&&p.until===void 0&&s.push({level:"error",beat:h,message:`${m}: \`carry\` needs \`until\` (when it lets go, such as { beat: ${h+1}, at: 'release' }).`}),p.at!==void 0&&a(h,p.at,`${m} \`at\``),p.until!==void 0&&a(h,p.until,`${m} \`until\``),p.until!==void 0&&p.duration!==void 0&&s.push({level:"error",beat:h,message:`${m}: give \`until\` or \`duration\`, not both.`})})});const l=t.map(c=>c&&typeof c=="object"&&!Array.isArray(c)?_g(c,e,!0):c);return[...ei(l,n),...s]}function _g(t,e,n=!1){const{then:s,...i}=t,o=a=>{try{return e[a.surface].anchor(a.anchor,0)}catch(l){if(n)return{x:0,y:0,left:0,right:0,top:0,bottom:0,width:0,height:0};throw l}},r={...i};return jo(t.target)&&(r.target=o(t.target)),jo(t.to)&&(r.to=o(t.to).x),jo(t.onto)&&(r.onto=o(t.onto).top),r}function HM(t,e,n){let s=0;return t.map(i=>{const o=zo([i],n.actions).length,r=e.slice(s,s+o);s+=o;const a=r.find(c=>c.contact!==void 0)?.contact,l=[...r].reverse().find(c=>c.release!==void 0)?.release;return{start:r[0]?.start,end:r[r.length-1]?.end,...a!==void 0?{contact:a}:{},...l!==void 0?{release:l}:{}}})}function RM(t){const e={actions:t.actions,gaits:t.gaits},n=Fl(e);if(n.length>0)throw new Error(`persona "${t.name}": ${n.join(" ")}`);const s=[...Object.keys(Wt),...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 vt))throw new Error(`persona "${t.name}": ${dt("mood",t.mood,Object.keys(vt))}`);const o=t.acting??"snappy";if(typeof o=="string"&&!(o in yn))throw new Error(`persona "${t.name}": ${dt("acting style",o,Object.keys(yn))}`);if(typeof t.stance=="string"&&!(t.stance in Vt))throw new Error(`persona "${t.name}": ${dt("stance",t.stance,Object.keys(Vt))}`);const r=t.height??120,a=typeof t.stance=="string"?Vt[t.stance]:Rt(t.stance??{}),l=t.mood?Le(a,t.mood):a,c={...t.look,height:r},h=t.summary??`${t.name}, a stick figure`;return{name:t.name,summary:h,cast:e,rest:l,height:r,figure:u=>pa({x:u.x,y:u.y,pose:l,style:{...c,...u.facing?{facing:u.facing}:{}},cast:e}),script:(u,d,f={})=>Yo(u,d,{...e,from:f.from,ground:f.ground,facing:f.facing,height:r,style:o,gait:i,start:l,rest:l,energy:t.energy}),check:u=>ei(u,e),handPath:(u,d,f)=>Ul(u,d,{...f,style:c,cast:e}),describe:()=>({name:t.name,summary:h,habits:{height:r,acting:typeof o=="string"?o:"custom",gait:i,...t.mood?{mood:t.mood}:{},stance:typeof t.stance=="string"?t.stance:t.stance?"custom":"rest"},actions:Dl(e),own:{actions:Object.keys(t.actions??{}),gaits:Object.keys(t.gaits??{})}})}}const LM=new Set(["x","y","walking","gait"]),Cg=.215+.205;function Hg(t,e,n=1){const{points:s}=ie(t,ht),i=s["hip.left"],o=s["knee.left"],r=s["ankle.left"],a=i&&o&&r?Math.hypot(o.x-i.x,o.y-i.y)+Math.hypot(r.x-o.x,r.y-o.y):Cg*t.height;return Ya(e,a/Cg,n)}function NM(t,e,n,s={}){const i=Yo(t,n,{...s,height:e.height,reach:s.reach??Rg(e)}),o=i.tracks.find(w=>w.property==="facing")?.keyframes??[],r=w=>{let v=s.facing??1;for(const k of o)k.time<=w&&(v=k.value);return v},a=Yi(i.keys),l=i.keys.map((w,v)=>{const k=ef(a[v]);return{time:w.time,pose:r(w.time)<0?Du(k):k,...w.easing?{easing:w.easing}:{},...w.act===!1?{act:!1}:{}}}),{rest:c,start:h,...u}=s;WM(l,a,n,i,e,r,s);const d=hg(t,l,u),f=$o(t,d,i.lines,{energy:s.energy}),p=i.tracks.filter(w=>LM.has(w.property)),g=i.tracks.find(w=>w.property==="walk");return{tracks:g?[...f,...p,KM(t,g,i.tracks,e,s)]:[...f,...p],duration:i.duration,lines:i.lines,keys:l,beats:i.beats,effects:i.effects}}function Rg(t){const e=bt({"arm.left.spread":90,"arm.left.elbow":0,"arm.left.bend":0,"leg.left.knee":0}),n=ie(t,e).points,s=Math.hypot(n["hand.left"].x-n["shoulder.left"].x,n["hand.left"].y-n["shoulder.left"].y),i=Math.hypot(n["toe.left"].x-n["hip.left"].x,n["toe.left"].y-n["hip.left"].y),o=ae({...ct,rightShoulder:90,rightElbow:0,rightWrist:0},{height:t.height,facing:1}),r=ae({...ct,rightHip:90,rightKnee:0},{height:t.height,facing:1}),a={x:(o.hands.right.x+o.fingertips.right.x)/2,y:(o.hands.right.y+o.fingertips.right.y)/2},l=Math.hypot(a.x-o.shoulders.right.x,a.y-o.shoulders.right.y),c=Math.hypot(r.feet.right.x-r.hip.x,r.feet.right.y-r.hip.y);return{arm:l>0?s/l:1,leg:c>0?i/c:1}}const FM={point:"arm",grab:"arm",put:"arm",write:"arm",swipe:"arm",push:"arm",kick:"leg"},DM=new Set(["point","grab","put","kick"]);function WM(t,e,n,s,i,o,r){const a=s.beats;if(n.length!==a.length)return;const l=new It({id:"placed",tracks:s.tracks.filter(h=>h.property==="x"||h.property==="y")}),c=h=>{const u=l.getStateAtTime(h).values.get(s.tracks[0]?.target??"");return{x:(r.from??0)+Number(u?.get("x")??0),y:(r.ground??0)+Number(u?.get("y")??0)}};n.forEach((h,u)=>{const d=FM[h.do],f=a[u];if(!d||f.contact===void 0||h.do!=="swipe"&&!h.target)return;const p=f.contact,g=f.release??f.contact;t.forEach((m,w)=>{if(m.time<p-1||m.time>g+1)return;const v=o(m.time),k=ae(e[w],{height:i.height,facing:v<0?-1:1}),b=c(m.time),E=DM.has(h.do)&&h.target?{x:h.target.x-b.x,y:h.target.y-b.y}:void 0,$={x:(k.hands.right.x+k.fingertips.right.x)/2,y:(k.hands.right.y+k.fingertips.right.y)/2},S=E??(d==="arm"?$:k.toes.right),x=v<0?"right":"left",M=`${d}.${x}`;let T=m.pose;if(h.do==="point")T=ve(i,T,M,S);else if(d==="arm")T=ve(i,jM(i,T,x,S),M,S);else for(let I=0;I<3;I++){const A=ie(i,T).points,_=A[`ankle.${x}`],C=A[`toe.${x}`];T=ve(i,T,M,{x:S.x-(C.x-_.x),y:S.y-(C.y-_.y)})}t[w]={...m,pose:T}})})}function BM(t,e){const n=bt({[`arm.${e}.spread`]:90,[`arm.${e}.elbow`]:0,[`arm.${e}.bend`]:0}),s=ie(t,n).points;return Math.hypot(s[`hand.${e}`].x-s[`shoulder.${e}`].x,s[`hand.${e}`].y-s[`shoulder.${e}`].y)}const zM=5,qM=4,YM=8;function jM(t,e,n,s){const i=BM(t,n)*.9,o=a=>{const l=ie(t,a).points[`shoulder.${n}`];return Math.hypot(s.x-l.x,s.y-l.y)<=i};if(o(e))return e;let r=e;for(let a=1;a<=YM;a++)if(r={...e,lean:(e.lean??0)+zM*a,bend:(e.bend??0)+qM*a},o(r))return r;return r}function KM(t,e,n,s,i){const o=n.find(u=>u.property==="gait"),r=o?new It({id:`${t}-gait-of`,tracks:[o]}):void 0,a=u=>{const d=r?.getStateAtTime(u).values.get(t)?.get("gait");if(typeof d=="string")return Wt[d]??i.gaits?.[d]??d},l=e.keyframes,c=[];let h=l[0]?.value??0;return l.forEach((u,d)=>{if(d>0){const f=l[d-1],p=a((f.time+u.time)/2),g=Bi(p,s.height),m=Hg(s,p);h+=(u.value-f.value)*(m>0?g/m:1)}else h=u.value;c.push({...u,value:h})}),{...e,keyframes:c}}const pt=["rect","circle","text","line","path","image","custom"],Ko={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:pt},y:{description:"Moves it down by this much from where it was placed (an offset)",unit:"px",types:pt},opacity:{description:"How opaque it is",unit:"0..1",min:0,max:1,types:pt},rotate:{description:"Turns it clockwise about its origin",unit:"degrees",types:pt},rotateX:{description:"Tips it about the horizontal axis (3D; shows with perspective)",unit:"degrees",types:pt},rotateY:{description:"Turns it about the vertical axis (3D; shows with perspective)",unit:"degrees",types:pt},z:{description:"Depth toward the viewer (shows with perspective)",unit:"px",types:pt},perspective:{description:"Distance from the viewer: nearer parts grow, further ones shrink",unit:"px",min:1,types:pt},scale:{description:"Size, both ways",unit:"factor",types:pt},scaleX:{description:"Width factor",unit:"factor",types:pt},scaleY:{description:"Height factor",unit:"factor",types:pt},skewX:{description:"Slants it sideways",unit:"degrees",types:pt},skewY:{description:"Slants it up and down",unit:"degrees",types:pt},originX:{description:"Transform pivot across its box",unit:"% (0 left, 50 centre, 100 right)",min:0,max:100,types:pt},originY:{description:"Transform pivot down its box",unit:"% (0 top, 50 centre, 100 bottom)",min:0,max:100,types:pt},fill:{description:"Fill colour (also written fillStyle)",kind:"color",types:pt},stroke:{description:"Outline colour (also written strokeStyle)",kind:"color",types:pt},strokeWidth:{description:"Outline width (also written lineWidth)",unit:"px",min:0,types:pt},clipTop:{description:"Hides this much from the top edge, for reveals",unit:"% of its height",min:0,max:100,types:pt},clipRight:{description:"Hides this much from the right edge",unit:"% of its width",min:0,max:100,types:pt},clipBottom:{description:"Hides this much from the bottom edge",unit:"% of its height",min:0,max:100,types:pt},clipLeft:{description:"Hides this much from the left edge",unit:"% of its width",min:0,max:100,types:pt},blur:{description:"Gaussian blur",unit:"px",min:0,types:pt},brightness:{description:"Brightness factor (1 unchanged)",unit:"factor",min:0,types:pt},glow:{description:"Soft glow around it, in glowColor",unit:"px",min:0,types:pt},glowColor:{description:"Colour of the glow",kind:"color",types:pt},shadowX:{description:"Drop shadow offset right",unit:"px",types:pt},shadowY:{description:"Drop shadow offset down",unit:"px",types:pt},shadowBlur:{description:"Drop shadow softness",unit:"px",min:0,types:pt},shadowColor:{description:"Drop shadow colour",kind:"color",types:pt},shine:{description:"A highlight sweeping across the fill",unit:"0..1 (progress)",min:0,max:1,types:pt},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:pt},quaternion:{description:'A rotation as [x, y, z, w] (a track with interpolation: "slerp")',kind:"list",types:pt}},Vl={fillStyle:"fill",strokeStyle:"stroke",lineWidth:"strokeWidth",rotateZ:"rotate",motionPathX:"x",motionPathY:"y",motionPathRotate:"rotate"},XM={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 Lg(t){const e=t,n=Object.entries(Ko).filter(([,i])=>i.types.includes(t.type)).map(([i,{types:o,...r}])=>({name:i,...r,...e[i]!==void 0&&typeof e[i]!="object"?{value:e[i]}:{}}));if(t.type!=="custom")return{type:t.type,properties:n};const s=t.about;for(const[i,o]of Object.entries(t.props??{}))n.push({name:i,description:s?.props?.[i]?.description??"",...s?.props?.[i],value:o});return{type:"custom",...s?{kind:s.kind,summary:s.summary}:{},properties:n,...s?.actions?{actions:s.actions}:{}}}function Ng(t){const e=Lg(t).properties.map(n=>n.name);return[...e,...Object.keys(Vl).filter(n=>e.includes(Vl[n]))]}function GM(t,e){const n=[],s=Object.keys(e);for(const i of t){const o=d=>n.push({level:"error",track:i.id,message:d}),r=e[i.target];if(!r){o(dt("target",i.target,s));continue}const a=Ng(r),l=r.type==="custom"&&r.acceptsProp?.(i.property);if(!a.includes(i.property)&&!l){o(`${i.target}: ${dt("property",i.property,a,XM[i.property])}`);continue}const c=i.keyframes??[];for(let d=1;d<c.length;d++)c[d].time<c[d-1].time&&o(`${i.target}.${i.property}: keyframes out of time order (${c[d-1].time} ms, then ${c[d].time} ms).`);const h=Ko[Vl[i.property]??i.property]??r.about?.props?.[i.property],u=h&&(h.kind??"number")==="number";for(const d of c){if(u&&typeof d.value!="number"){o(`${i.target}.${i.property}: values are numbers${h.unit?` (${h.unit})`:""} (got ${JSON.stringify(d.value)} at ${d.time} ms).`);break}if(u&&typeof d.value=="number"&&(h.min!==void 0&&d.value<h.min||h.max!==void 0&&d.value>h.max)){n.push({level:"warning",track:i.id,message:`${i.target}.${i.property}: ${d.value} at ${d.time} ms is outside ${h.min??"−∞"}..${h.max??"∞"}${h.unit?` (${h.unit})`:""}.`});break}}}return n}const ns=(t,e)=>t[2]<=-e;function Jl(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 Fg(t,e){if(t.every(s=>ns(s,e)))return t;const n=[];return t.forEach((s,i)=>{const o=t[(i+t.length-1)%t.length],r=ns(s,e),a=ns(o,e);r!==a&&n.push(Jl(o,s,e)),r&&n.push(s)}),n.length>=3?n:[]}function UM(t,e){if(t.every(i=>ns(i,e)))return[t];const n=[];let s=[];return t.forEach((i,o)=>{const r=ns(i,e);if(o>0){const a=t[o-1],l=ns(a,e);l&&!r?(s.push(Jl(a,i,e)),n.push(s),s=[]):!l&&r&&s.push(Jl(a,i,e))}r&&s.push(i)}),s.length>0&&n.push(s),n.filter(i=>i.length>=2)}function Dg(t,e,n){const s=e-t;if(!(s>=n*1.5))return[t,e];const i=Math.round(s/n);return Array.from({length:i+1},(o,r)=>t+s*r/i)}function VM(t,e,n){const s=(i,o)=>Math.max(0,Math.min(i.length-2,i.findIndex((r,a)=>a>0&&o<=r)-1));return[s(t,n[0]),s(e,n[2])]}function JM(t,e){const n=s=>{const i=[e[0]*s[0]+e[4]*s[1]+e[8]*s[2],e[1]*s[0]+e[5]*s[1]+e[9]*s[2],e[2]*s[0]+e[6]*s[1]+e[10]*s[2]],o=Math.hypot(...i)||1;return[i[0]/o,i[1]/o,i[2]/o]};return{...t,vertices:t.vertices.map(s=>Xt(e,s)),faces:t.faces.map(s=>({corners:s.corners,normal:n(s.normal)}))}}function Xo(t,e,n,s){const i=r=>(r[e]-n)*s>=0;if(t.every(i))return t;const o=[];return t.forEach((r,a)=>{const l=t[(a+t.length-1)%t.length];if(i(r)!==i(l)){const c=(n-l[e])/(r[e]-l[e]);o.push([0,1,2].map(h=>h===e?n:l[h]+(r[h]-l[h])*c))}i(r)&&o.push(r)}),o.length>=3?o:[]}function ZM(t,e,n){const s=t.faces.map(r=>({points:r.corners.map(a=>t.vertices[a]),normal:r.normal})),i=[],o={x:e.slice(1,-1),z:n.slice(1,-1)};for(let r=0;r+1<e.length;r++)for(let a=0;a+1<n.length;a++){const l=[],c=new Map,h=p=>{const g=p.map(w=>Math.round(w*1e6)).join(",");let m=c.get(g);return m===void 0&&(m=l.length,l.push(p),c.set(g,m)),m},u=[],d=p=>p===0,f=(p,g)=>p+2===g.length;for(const p of s){let g=p.points;d(r)||(g=Xo(g,0,e[r],1)),g.length&&!f(r,e)&&(g=Xo(g,0,e[r+1],-1)),g.length&&!d(a)&&(g=Xo(g,2,n[a],1)),g.length&&!f(a,n)&&(g=Xo(g,2,n[a+1],-1)),g.length>=3&&u.push({corners:g.map(h),normal:p.normal})}u.length>0&&i.push({cell:[r,a],mesh:{vertices:l,faces:u,creases:t.creases,joined:t.joined,walls:o}})}return i}const QM=new WeakMap,tS=new WeakMap,eS=48,Wg=t=>t.map(e=>Math.round(e*1e5)).join(",");function Bg(t,e,n,s){let i=t.get(e);i||t.set(e,i=new Map);let o=i.get(n);return o===void 0&&(i.size>=eS&&i.clear(),i.set(n,o=s())),o}function Zl(t,e){const n=Wg(e);return Bg(QM,t,n,()=>{const s=JM(t,e),i=[1/0,1/0,1/0],o=[-1/0,-1/0,-1/0];for(const r of s.vertices)for(const a of[0,1,2])i[a]=Math.min(i[a],r[a]),o[a]=Math.max(o[a],r[a]);return{key:n,inSpace:s,low:i,high:o}})}function nS(t,e){const n=t.map(h=>({...h,...Zl(h.mesh,h.local)})),s=[1/0,1/0,1/0],i=[-1/0,-1/0,-1/0];for(const h of n)for(const u of[0,1,2])s[u]=Math.min(s[u],h.low[u]),i[u]=Math.max(i[u],h.high[u]);const o=Dg(s[0],i[0],e),r=Dg(s[2],i[2],e),a=`${o.join(",")}|${r.join(",")}`,l=n.flatMap(h=>{if(h.high[0]-h.low[0]<=e*2.5&&h.high[2]-h.low[2]<=e*2.5||h.whole||h.mesh.joined||(h.mesh.marks?.length??0)>0){const d=[(h.low[0]+h.high[0])/2,(h.low[1]+h.high[1])/2,(h.low[2]+h.high[2])/2];return[{part:h.part,mesh:h.mesh,cut:!1,cell:VM(o,r,d)}]}return Bg(tS,h.inSpace,a,()=>ZM(h.inSpace,o,r)).map(d=>({part:h.part,mesh:d.mesh,cut:!0,cell:d.cell}))}),c=(s[1]+i[1])/2;return{pieces:l,middle:([h,u])=>[(o[h]+o[h+1])/2,c,(r[u]+r[u+1])/2]}}const zg=.004,Ql=.05,qg=new WeakMap;function sS(t){let e=qg.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)}),qg.set(t,e)),e}const Yg=new WeakMap;function jg(t){return t.filter(({mesh:e})=>sS(e)).map(({part:e,key:n,inSpace:s,low:i,high:o})=>{let r=Yg.get(s);return r||(r=s.faces.map(a=>{const l=s.vertices[a.corners[0]];return{normal:a.normal,offset:a.normal[0]*l[0]+a.normal[1]*l[1]+a.normal[2]*l[2]}}),Yg.set(s,r)),{part:e,key:n,planes:r,low:i,high:o}})}function iS(t,e,n,s){const i=e.reduce((o,r)=>[o[0]+r[0]/e.length,o[1]+r[1]/e.length,o[2]+r[2]/e.length],[0,0,0]);for(const o of s){if(o.part===t||[0,1,2].some(a=>i[a]<o.low[a]-Ql||i[a]>o.high[a]+Ql))continue;if(o.planes.every(a=>{const l=a.normal[0]*n[0]+a.normal[1]*n[1]+a.normal[2]*n[2],c=e.map(u=>a.normal[0]*u[0]+a.normal[1]*u[1]+a.normal[2]*u[2]-a.offset);if(c.every(u=>Math.abs(u)<=zg))return l<-.9;const h=Math.abs(l)<.5?Ql:zg;return c.every(u=>u<=h)}))return!0}return!1}const Kg=new WeakMap;function Xg(t,e,n,s,i){const o=`${s}|${i.map(l=>l.key).join(";")}`;let r=Kg.get(e);r||Kg.set(e,r=new Map);let a=r.get(o);if(!a){r.size>=48&&r.clear();const l=h=>{const u=[n[0]*h[0]+n[4]*h[1]+n[8]*h[2],n[1]*h[0]+n[5]*h[1]+n[9]*h[2],n[2]*h[0]+n[6]*h[1]+n[10]*h[2]],d=Math.hypot(...u)||1;return[u[0]/d,u[1]/d,u[2]/d]},c=e.vertices.map(h=>Xt(n,h));a=e.faces.map(h=>iS(t,h.corners.map(u=>c[u]),l(h.normal),i)),r.set(o,a)}return a}const ss={turn:{description:"Which way it faces: 0 toward the viewer, 1 screen-right, 2 away, 3 (or −1) screen-left; in between turns it in 3D",unit:"quarter turns"},tilt:{description:"How far the camera looks down on it: 0 level, 12 the ¾ look, 90 straight down",unit:"degrees",default:12,min:-90,max:90},pitch:{description:"Nose up (+) or down (−), about its middle on the ground",unit:"degrees"},roll:{description:"Tipped onto its right (+) or left (−) side",unit:"degrees"},squash:{description:"Squash and stretch about the ground, keeping its volume: 1 normal, below squashed, above stretched",unit:"factor",default:1,min:.3,max:3},lift:{description:"Off the ground",unit:"metres"},lean:{description:"The top sheared forward (+) or back (−): speed and drag",unit:"shear"},size:{description:"Its size, about the ground: 1 as built, 0 gone (pop it in or out)",unit:"factor",default:1,min:0}},tc=Math.PI/180;function Gg(t,e,n){return{toView:s=>Ta(ne(s,t*90*tc),-e*tc),toScreen:s=>({x:s[0]*n,y:-s[1]*n})}}const Ug=new WeakMap,si=t=>Go(t),Go=t=>{let e=Ug.get(t);return e||Ug.set(t,e=$f(t)),e};function At(t,e,n){return e[n]??t.controls[n]?.default??ss[n]?.default??0}function ii(t,e){const n=Math.max(.05,At(t,e,"squash")),s=1/Math.sqrt(n),o=[1,0,0,0,0,1,At(t,e,"lean"),0,0,0,1,0,0,0,0,1];return[Qe([0,At(t,e,"lift"),0]),re(Qt([1,0,0],-At(t,e,"pitch"))),re(Qt([0,0,1],At(t,e,"roll"))),o,tn([s,n,s]),tn(Array(3).fill(Math.max(0,At(t,e,"size"))))].reduce((r,a)=>Ot(r,a))}function ec(t,e){const n=ii(t,e),s=new Map,i=Object.entries(t.controls).flatMap(([r,a])=>(a.bind??[]).map(l=>({value:At(t,e,r),bind:l}))),o=r=>{const a=s.get(r.id);if(a)return a;const l=r.parent?t.parts.find(h=>h.id===r.parent):void 0;if(r.parent&&!l)throw new Error(`prop rig: part "${r.id}" hangs from "${r.parent}", which is not a part`);let c=Ot(l?o(l):n,Qe(r.at??[0,0,0]));if(r.rotate){const[h,u,d]=r.rotate;h&&(c=Ot(c,re(Qt([1,0,0],h)))),u&&(c=Ot(c,re(Qt([0,1,0],u)))),d&&(c=Ot(c,re(Qt([0,0,1],d))))}for(const{value:h,bind:u}of i)if(!(!u.parts.includes(r.id)||h===0)){if(u.translate&&(c=Ot(c,Qe([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,Qe(d),re(Qt(f,u.rotate.degrees*h)),Qe([-d[0],-d[1],-d[2]])].reduce((p,g)=>Ot(p,g))}u.scale&&(c=Ot(c,tn([1+(u.scale[0]-1)*h,1+(u.scale[1]-1)*h,1+(u.scale[2]-1)*h])))}return s.set(r.id,c),c};for(const r of t.parts)o(r);return s}const nc=(()=>{const t=[-.45,.75,.5],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),oS=Math.cos(35*tc);function sc(t,e,n,s,i={}){const o=t.derive?{...e,...t.derive(e)}:e,r=ec(t,o),a=n.toView([0,0,0]),l=C=>N=>[C[0]*N[0]+C[4]*N[1]+C[8]*N[2],C[1]*N[0]+C[5]*N[1]+C[9]*N[2],C[2]*N[0]+C[6]*N[1]+C[10]*N[2]],c=ii(t,o),h=i.slice===void 0?null:Nr(c),u=h?t.parts.map(C=>({part:C,mesh:Go(C.shape),local:Ot(h,r.get(C.id)),whole:C.shape.type==="tube"})):void 0,d=u?nS(u,i.slice):void 0,f=u?jg(u.map(C=>({part:C.part.id,mesh:C.mesh,...Zl(C.mesh,C.local)}))):void 0,p=(C,N,B,G)=>{const Z=U=>n.toView(Xt(B,U)),Y=N.vertices.map(Z),L=Y.map(U=>n.toScreen(U)),z=i.perspective?i.near:void 0,O=U=>U.map(it=>n.toScreen(it)),P=U=>z===void 0?U:Fg(U,z),H=U=>z===void 0?[U]:UM(U,z),W=l(B),q=N.faces.map(U=>{const it=n.toView(W(U.normal)),ut=[it[0]-a[0],it[1]-a[1],it[2]-a[2]],gt=Math.hypot(...ut)||1;return[ut[0]/gt,ut[1]/gt,ut[2]/gt]}),D=f&&G?Xg(C.id,N,G,Wg(G),f):void 0,K=U=>D?.[U]??!1,V=q.map((U,it)=>{if(K(it))return!1;if(!i.perspective)return U[2]>1e-6;const gt=N.faces[it].corners.reduce((kt,yt)=>[kt[0]+Y[yt][0],kt[1]+Y[yt][1],kt[2]+Y[yt][2]],[0,0,0]);return-(U[0]*gt[0]+U[1]*gt[1]+U[2]*gt[2])>1e-9}),F=U=>N.faces[U].corners.reduce((it,ut)=>it+Y[ut][2],0)/N.faces[U].corners.length,X=N.faces.map((U,it)=>({face:U,i:it})).filter(({i:U})=>V[U]).map(({face:U,i:it})=>({i:it,solved:{points:z===void 0?U.corners.map(ut=>L[ut]):O(P(U.corners.map(ut=>Y[ut]))),depth:F(it),tone:.72+.33*Math.max(0,q[it][0]*nc[0]+q[it][1]*nc[1]+q[it][2]*nc[2])}})).filter(U=>U.solved.points.length>=3).sort((U,it)=>U.solved.depth-it.solved.depth);if(i.light){const U=l(B);for(const{i:it,solved:ut}of X){const gt=N.faces[it].corners,kt=gt.reduce((bc,Y3)=>{const wc=Xt(B,N.vertices[Y3]);return[bc[0]+wc[0]/gt.length,bc[1]+wc[1]/gt.length,bc[2]+wc[2]/gt.length]},[0,0,0]),yt=U(N.faces[it].normal),oe=Math.hypot(...yt)||1,ai=i.light(kt,[yt[0]/oe,yt[1]/oe,yt[2]/oe]);ut.light=ai.light,ut.fog=ai.fog}}const j=X.map(U=>U.solved),Q=rS(N),et=[],rt=[];for(const[U,it]of Q){const ut=it.filter(kt=>V[kt]).length;if(ut===0)continue;const gt=it.length===2&&ut===2&&N.creases!==!1&&q[it[0]][0]*q[it[1]][0]+q[it[0]][1]*q[it[1]][1]+q[it[0]][2]*q[it[1]][2]<oS;it.length===1&&(N.joined||aS(N,U))||(it.length===1||ut===1||gt)&&(et.push(U.split("-").map(Number)),rt.push(it.filter(kt=>V[kt]).reduce((kt,yt)=>F(yt)>F(kt)?yt:kt)))}const at=U=>N.faces.findIndex(it=>it.corners.length>4&&Math.sign(cS(N.vertices[U],it.normal))>0),R=(N.marks??[]).filter(([U])=>at(U)<0||V[at(U)]),J=([U,it])=>z===void 0?[[L[U],L[it]]]:H([Y[U],Y[it]]).map(O),nt=R.flatMap(J),ot=U=>z===void 0?[U.map(it=>L[it])]:H(U.map(it=>Y[it])).map(O);if(i.slice!==void 0){const U=new Map;et.forEach((it,ut)=>U.set(rt[ut],[...U.get(rt[ut])??[],it]));for(const{i:it,solved:ut}of X){ut.edges=Qg(U.get(it)??[]).flatMap(ot);const gt=N.faces[it].corners;ut.center=gt.reduce((yt,oe)=>[yt[0]+Y[oe][0]/gt.length,yt[1]+Y[oe][1]/gt.length,yt[2]+Y[oe][2]/gt.length],[0,0,0]),ut.normal=q[it];const kt=X[X.length-1].i;ut.marks=R.filter(([yt])=>(at(yt)>=0?at(yt):kt)===it).flatMap(J)}}const st=C.glow?Math.max(0,Math.min(1,At(t,o,C.glow.control))):0,lt=C.fade?Math.max(0,Math.min(1,At(t,o,C.fade.control))):0,tt=C.fade?Math.max(0,Math.min(1,C.fade.from+(C.fade.to-C.fade.from)*lt)):1;return{part:C,depth:Y.reduce((U,it)=>U+it[2],0)/Math.max(1,Y.length),faces:j,edges:Qg(et).flatMap(ot),marks:nt,glow:st,opacity:tt,...C.shape.type==="tube"?{spine:lS(H(C.shape.points.map(Z)).map(O))}:{},...N.walls?{cut:!0}:{}}},g=new Map(u?.map(C=>[C.part.id,C.local])),w=(d?d.pieces.map(C=>({part:C.part,mesh:C.mesh,m:C.cut?c:r.get(C.part.id),local:C.cut?Ei():g.get(C.part.id),cell:C.cell})):t.parts.map(C=>({part:C,mesh:Go(C.shape),m:r.get(C.id),local:void 0,cell:void 0}))).map(C=>({cell:C.cell,solved:p(C.part,C.mesh,C.m,C.local)})),v=w.map(C=>C.solved),k=C=>C.filter(N=>N.faces.length>0&&N.opacity>.01).sort((N,B)=>N.depth-B.depth);let b;if(d){const C=new Map(t.parts.map(B=>{const G=r.get(B.id),Z=Go(B.shape).vertices;return[B.id,Z.reduce((Y,L)=>Y+n.toView(Xt(G,L))[2],0)/Math.max(1,Z.length)]})),N=new Map;for(const B of w){const G=B.cell.join(",");N.has(G)||N.set(G,{cell:B.cell,parts:[]}),N.get(G).parts.push(B.solved),B.solved.depth=C.get(B.solved.part.id)}b=[...N.values()].map(({cell:B,parts:G})=>({depth:n.toView(Xt(c,d.middle(B)))[2],parts:k(G)})).filter(B=>B.parts.length>0)}const E={};for(const[C,N]of Object.entries(t.anchors??{})){const B=N.part?r.get(N.part):ii(t,o);if(!B)throw new Error(`prop rig: anchor "${C}" is on "${N.part}", which is not a part`);const G=n.toView(Xt(B,N.at));E[C]={point:n.toScreen(G),depth:G[2]}}const[$,S]=t.footprint??[t.length*.45,t.length],x=Math.max(0,At(t,o,"lift")),M=Math.max(0,At(t,o,"size"))/(1+x*.8),T=Array.from({length:24},(C,N)=>{const B=Math.PI*2*N/24;return n.toView([Math.cos(B)*$*.55*M,0,Math.sin(B)*S*.55*M])}),I=i.perspective?i.near:void 0,A={points:(I===void 0?T:Fg(T,I)).map(C=>n.toScreen(C)),opacity:.16*M},_=v.filter(C=>C.part.seeThrough&&C.opacity>.01).flatMap(C=>C.faces.map(N=>N.points));return{under:k(v.filter(C=>!C.part.overRider)),over:k(v.filter(C=>C.part.overRider)),...b?{cells:b}:{},anchors:E,openings:_,shadow:A,pxPerUnit:s,sizePx:t.height*s}}const Vg=new WeakMap;function rS(t){let e=Vg.get(t);if(!e){e=new Map;for(let n=0;n<t.faces.length;n++){const s=t.faces[n].corners;for(let i=0;i<s.length;i++){const o=s[i],r=s[(i+1)%s.length],a=o<r?`${o}-${r}`:`${r}-${o}`,l=e.get(a);l?l.push(n):e.set(a,[n])}}Vg.set(t,e)}return e}function Jg(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=ec(t,n),i=Nr(ii(t,n))??Ei(),o=r=>Math.max(0,Math.min(1,r));return t.parts.map(r=>{const a=r.fade?o(At(t,n,r.fade.control)):0;return{part:r,matrix:s.get(r.id),local:Ot(i,s.get(r.id)),glow:r.glow?o(At(t,n,r.glow.control)):0,opacity:r.fade?o(r.fade.from+(r.fade.to-r.fade.from)*a):1}})}function Zg(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=ec(t,n),i=ii(t,n),o={};for(const[r,a]of Object.entries(t.anchors??{})){const l=a.part?s.get(a.part):i;if(!l)throw new Error(`prop rig: anchor "${r}" is on "${a.part}", which is not a part`);o[r]=Xt(l,a.at)}return o}function aS(t,e){if(!t.walls)return!1;const[n,s]=e.split("-").map(o=>t.vertices[Number(o)]),i=(o,r)=>r.some(a=>Math.abs(n[o]-a)<1e-6&&Math.abs(s[o]-a)<1e-6);return i(0,t.walls.x)||i(2,t.walls.z)}function lS(t){return t.reduce((e,n)=>!e||n.length>e.length?n:e,void 0)}const cS=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2];function Qg(t){const e=t.map(s=>[...s]),n=[];for(;e.length>0;){const s=[...e.shift()];let i=!0;for(;i;){i=!1;for(let o=0;o<e.length;o++){const[r,a]=e[o],l=s[s.length-1],c=s[0];if(r===l)s.push(a);else if(a===l)s.push(r);else if(a===c)s.unshift(r);else if(r===c)s.unshift(a);else continue;e.splice(o,1),i=!0;break}}n.push(s)}return n}function ic(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 oc(t){const e={};for(const[n,s]of Object.entries({...ss,...t.rig.controls})){const{bind:i,...o}=s;e[n]=o}return e}function tp(t){const{prop:e}=t,n=t.scale??60,s=e.rig.length*n*1.4,i=e.rig.height*n*1.6,o=oc(e),r={};for(const[l,c]of Object.entries(o))r[l]=t.values?.[l]??c.default??0;const a={look:t.look,ink:t.ink,lineWidth:t.lineWidth,pencil:t.pencil,seed:t.seed,style:t.style,paper:t.paper};return{type:"custom",x:t.x-s/2,y:t.y-i,width:s,height:i,props:r,prop:e,propScale:n,propDraw:a,about:{kind:e.kind,summary:e.summary,props:o,actions:Object.fromEntries(Object.entries(e.actions).map(([l,c])=>[l,c.summary]))},draw(l,c,h){const u=c.props??{};l.translate(s/2,i),il(l,is(e,u,n),{...a,time:h,loose:ic(c,u)})}}}function is(t,e,n){const s=Gg(At(t.rig,e,"turn"),At(t.rig,e,"tilt"),n);return sc(t.rig,e,s,n)}function Uo(t,e,n){const s={...t.props};let i=0,o=0;for(const[l,c]of e.state?.values.get(n)??[])typeof c=="number"&&(l==="x"?i=c:l==="y"?o=c:l in s&&(s[l]=c));const r={x:t.x+t.width/2+i,y:t.y+t.height+o},a=is(t.prop,s,t.propScale);return{values:s,origin:r,solved:a,anchor(l){const c=a.anchors[l];if(!c)throw new Error(`${t.prop.kind}: no anchor "${l}" (it has ${Object.keys(a.anchors).join(", ")||"none"})`);return{x:r.x+c.point.x,y:r.y+c.point.y,depth:c.depth}}}}function hS(t,e,n,s,i={}){const o=Uo(e,n,s);return t.save(),t.translate(o.origin.x,o.origin.y),il(t,o.solved,{...e.propDraw,time:n.time,loose:ic(e,o.values),rider:i.rider?r=>{r.save(),r.translate(-o.origin.x,-o.origin.y),i.rider(r),r.restore()}:void 0}),t.restore(),o}const os={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"}},uS=400,dS=.2;function fS(t,e={}){const{prop:n}=t,s=oc(n),i=Object.keys(s),o=Object.keys(n.rig.anchors??{}),r=n.rig.parts.map($=>$.id),a=Vn(),l=Xs(a),c=e.tracks?.length?new It({id:`${n.kind}-surface`,tracks:e.tracks}):void 0,h=Math.max(0,...(e.tracks??[]).flatMap($=>$.keyframes.map(S=>S.time))),u=new Map,d=new Map;t.loose=d;const f=t.props,p=$=>{const S={...t.props};let x=0,M=0;if(c){const T=c.getStateAtTime(Math.min($,h));for(const I of T.values.values())for(const[A,_]of I)typeof _=="number"&&(A==="x"?x=_:A==="y"?M=_:A in S&&(S[A]=_))}for(const T of i)a.keys(T)?.length&&(S[T]=a.valueAt(T,$));return{values:S,origin:{x:t.x+t.width/2+x,y:t.y+t.height+M}}},g=$=>{const{kind:S,rest:x}=gn($),M=T=>qe(n.kind,$,os,T);if(S==="box"){if(x)throw M("box takes no arguments");return{kind:S}}if(S==="anchor"){if(!o.includes(x))throw M(dt(`${n.kind} anchor`,x,o));return{kind:S,name:x}}if(S==="part"){if(!r.includes(x))throw M(dt(`${n.kind} part`,x,r));return{kind:S,name:x}}if(S==="control"){if(!i.includes(x))throw M(dt(`${n.kind} control`,x,i));return{kind:S,name:x}}throw M()},m=$=>{const S=(n.rig.controls[$]?.bind??[]).flatMap(M=>M.parts),x=n.rig.parts.filter(M=>M.glow?.control===$).map(M=>M.id);return new Set([...S,...x])},w=new Map,v=$=>{let S=w.get($);if(!S){const x=p($);w.set($,S={...x,solved:is(n,x.values,t.propScale)})}return S},k=($,S)=>{const x=g($),{values:M,origin:T,solved:I}=v(S);if(x.kind==="box")return Mt(T.x-t.width/2,T.y-t.height,t.width,t.height);if(x.kind==="anchor"){const C=I.anchors[x.name].point,N=dS*t.propScale;return Mt(T.x+C.x-N/2,T.y+C.y-N/2,N,N)}if(x.kind==="part")return _(new Set([x.name]),`part "${x.name}" is`);const A=m(x.name);if(A.size===0)return Mt(T.x-t.width/2,T.y-t.height,t.width,t.height);return _(A,`the parts control "${x.name}" moves are`);function _(C,N){const B=[...I.under,...I.over].filter(z=>C.has(z.part.id)).flatMap(z=>z.faces.flatMap(O=>O.points));if(B.length===0){const z=Number.isFinite(S)?`at ${S} ms`:"after its edits";throw new Error(`${n.kind}: ${N} turned away from the viewer ${z}; aim at an anchor (${o.map(O=>`anchor:${O}`).join(", ")||"none"}) or box`)}const G=B.map(z=>z.x),Z=B.map(z=>z.y),Y=Math.min(...G),L=Math.min(...Z);return Mt(T.x+Y,T.y+L,Math.max(...G)-Y,Math.max(...Z)-L)}},b=($,S)=>{try{return k($,S)}catch{return}},E={kind:"prop",prop:t,about:os,target:t,box:Mt(t.x,t.y,t.width,t.height),anchor($,S=1/0){return k($,S)},piece($){const S=g($);if(S.kind!=="part")throw new Error(`${n.kind}: a piece is a part, part:ID (${r.slice(0,6).map(I=>`part:${I}`).join(", ")}…), not "${$}"`);const x=u.get(S.name);if(x)return x;const M=[S.name];for(let I=0;I<M.length;I++)for(const A of n.rig.parts)A.parent===M[I]&&!M.includes(A.id)&&M.push(A.id);const T={id:u.size+1,part:S.name,home:k($,0)};u.set(S.name,T);for(const I of M)d.set(I,T.id);for(const I of["x","y","rotate"])f[`piece.${T.id}.${I}`]=0;return f[`piece.${T.id}.opacity`]=1,T},edit($,S,x){if(!($ in os.edits))throw Gs(n.kind,$,os);const M=Array.isArray(S)?S:[S];if(M.length===0)throw new Error(`${n.kind}.edit: ${$} takes at least one anchor`);if(w.clear(),$==="move"||$==="fling"){if(M.length>1)throw new Error(`${n.kind}.edit: ${$} takes one part anchor`);const T=E.piece(M[0]);if($==="fling")return E.fling(T,x);const I=x.to;if(!I)throw new Error(`${n.kind}.edit: move needs \`to\`, an anchor name or { x, y }`);const A=typeof I=="string"?k(I,x.at):void 0;return E.move(T,{...x,to:A?{x:A.left+A.width/2,y:A.top+A.height/2}:I})}for(const T of M){const I=g(T);if(I.kind!=="control")throw new Error(`${n.kind}.edit: ${$} takes control anchors (control:${i.join(", control:")}), not "${T}"`);const A=s[I.name];let _;if($==="set"){if(typeof x.value!="number"||!Number.isFinite(x.value))throw new Error(`${n.kind}.edit: set needs \`value\`, a number (${I.name}: ${A.description})`);_=x.value}else _=x.on===!1?A.default??A.min??0:A.max??1;a.tween(I.name,p(x.at).values[I.name],_,x,uS)}return E},follow($,S){return w.clear(),l.follow($,S),E},fling($,S){return w.clear(),l.fling($,S),E},move($,S){return w.clear(),l.move($,S),E},ride($,S,x){const M=[...i.flatMap(I=>Jn(a.keys(I))),...(e.tracks??[]).flatMap(I=>Jn(I.keyframes.filter(A=>typeof A.value=="number")))];if(M.length===0)return $;const T=[...o.map(I=>`anchor:${I}`),...r.map(I=>`part:${I}`)].flatMap(I=>{const A=b(I,0);return A?[{top:A.top,offset:_=>(b(I,_)?.top??A.top)-A.top,windows:M}]:[]});return Co($,S,{ground:x.ground,every:x.every??ze,floors:T})},tracks:a.tracks};return E}const gS={body:"#e8574a",trim:"#3b3b44",glass:"#bfe3f2",tyre:"#2c2c33",hub:"#c9ccd3",light:"#fff4b8",tail:"#ff5a4f",inside:"#3b3640",seat:"#6d5d55"};function xe(t){const e={...gS,...t.colors},n=[],{forwardMost:s,backMost:i,top:o}=ep(t);t.body&&n.push({id:"body",shape:{type:"extrude",profile:t.body,width:t.width},fill:e.body});for(const[h,u]of(t.frame??[]).entries())n.push({id:`frame-${h}`,shape:{type:"tube",points:u.points,radius:u.radius??.035,segments:6},fill:u.color??e.body,outline:.7});for(const[h,u]of(t.windows??[]).entries())for(const d of[1,-1])n.push({id:`window-${h}-${d>0?"left":"right"}`,shape:{type:"panel",points:[[u.from,u.low],[u.to,u.low],[u.to,u.high],[u.from,u.high]],facing:d>0?"left":"right"},at:[d*(t.width/2+.01),0,0],fill:e.glass,outline:.7,seeThrough:!0,glow:t.lights?{control:"lights",color:"#ffe9a3"}:void 0});for(const h of t.extras??[])n.push(h);if(t.cabin){const h=t.cabin.width??t.width*.85;n.push({id:"cabin",shape:{type:"extrude",profile:t.cabin.profile,width:h},fill:e.glass,outline:.9,seeThrough:!0,layer:1});const u=Math.min(...t.cabin.profile.map(([,f])=>f)),d=Math.max(...t.cabin.profile.map(([,f])=>f));for(const[f,p]of(t.cabin.pillars??[]).entries())n.push({id:`pillar-${f}`,shape:{type:"box",size:[h+.02,d-u,.1]},at:[0,(u+d)/2,p],fill:e.body,outline:.8,layer:1})}const r=t.wheels[0]?.radius??.4,a=[];t.wheels.forEach((h,u)=>{const d=h.side===0?[0]:[1,-1],f=h.thickness??(h.style==="spoked"?.05:.26);for(const p of d){const g=`wheel-${u}-${p>0?"left":p<0?"right":"middle"}`;if(a.push({parts:[g],rotate:{axis:"x",degrees:r/h.radius}}),n.push({id:g,shape:{type:"cylinder",radius:h.radius,length:f,axis:"x",segments:20,spokes:h.style==="spoked"?8:0},at:[p*h.side,h.radius,h.forward],fill:h.style==="spoked"?void 0:e.tyre,ink:h.style==="spoked"?e.tyre:void 0,outline:h.style==="spoked"?1.3:1}),h.style!=="spoked")for(const m of p===0?[1,-1]:[p])n.push({id:`${g}-hub${p===0?m>0?"-left":"-right":""}`,parent:g,shape:{type:"cylinder",radius:h.radius*.55,length:.02,axis:"x",segments:14,spokes:5},at:[m*(f/2+.012),0,0],fill:e.hub,outline:.6})}});const l={wheelSpin:{description:"How far the wheels have turned (keyed exactly with the distance driven, so they never skate)",unit:"degrees",bind:a}};if(t.door){const{from:h,to:u,low:d,high:f}=t.door,p=[[h,d],[u,d],[u,f],[h,f]];for(const g of[1,-1]){const m=g>0?"left":"right";n.push({id:`doorway-${m}`,shape:{type:"panel",points:p,facing:g>0?"left":"right"},at:[g*(t.width/2+.004),0,0],fill:e.inside,outline:.5,seeThrough:!0});const w=h+(u-h)*.15,v=h+(u-h)*.55;n.push({id:`seat-back-${m}`,shape:{type:"panel",points:[[w,d+.05],[v,d+.05],[v-.08,f-.06],[w+.06,f-.04]],facing:g>0?"left":"right"},at:[g*(t.width/2+.006),0,0],fill:e.seat,outline:.4}),n.push({id:`door-${m}`,shape:{type:"panel",points:p.map(([k,b])=>[k-u,b]),facing:g>0?"left":"right"},at:[g*(t.width/2+.01),0,u],fill:e.body,outline:.7,overRider:!0})}l.door={description:"Doors open: 0 shut, 1 open (hinged at the front)",unit:"0..1",min:0,max:1,bind:[{parts:["door-left"],rotate:{axis:"y",degrees:-70}},{parts:["door-right"],rotate:{axis:"y",degrees:70}}]}}if(t.lights){const{across:h,low:u,high:d,front:f,back:p}=t.lights,g=(t.lights.size??.32)/2,m=[[-g,u],[g,u],[g,d],[-g,d]];for(const w of[1,-1])n.push({id:`headlight-${w}`,shape:{type:"panel",points:m,facing:"front"},at:[w*h,0,f],fill:e.light,outline:.6,glow:{control:"lights",color:"#ffffff"}}),n.push({id:`taillight-${w}`,shape:{type:"panel",points:m,facing:"back"},at:[w*h,0,p],fill:Ao(e.tail,.62),outline:.6,glow:{control:"lights",color:e.tail}});l.lights={description:"Lights on: 0 off, 1 on",unit:"0..1",min:0,max:1}}t.antenna&&(n.push({id:"antenna",shape:{type:"tube",points:[[0,0,0],[0,.75,0]],radius:.018,segments:5},at:t.antenna,fill:e.trim,outline:.6}),n.push({id:"antenna-tip",parent:"antenna",shape:{type:"ellipsoid",radii:[.05,.05,.05],segments:8},at:[0,.77,0],fill:e.tail,outline:.6}),l.antenna={description:"Antenna bend (follow-through: it trails the motion on a spring)",unit:"degrees",bind:[{parts:["antenna"],rotate:{axis:"x",degrees:1}}]});const c={parts:n,controls:l,length:s-i,height:o,footprint:[t.width,s-i],anchors:{...t.seat?{seat:{at:t.seat}}:{},front:{at:[0,o*.45,s]},back:{at:[0,o*.45,i]},roof:{at:[0,o,0]},...t.door?{door:{at:[-t.width/2,(t.door.low+t.door.high)/2,(t.door.from+t.door.to)/2]}}:{},...t.anchors}};return{kind:t.kind??"vehicle",family:"vehicle",summary:t.summary??"A wheeled vehicle",rig:c,actions:pS(t),acting:np,colors:{body:e.body,ink:"#26262b"},follow:t.antenna?[{control:"antenna",of:"x",per:.9,stiffness:140,damping:7,limit:35}]:void 0,wheelRadius:r,...t.wheels.length>0?{moves:{drive:{speed:t.speed??6,perMetre:{wheelSpin:180/(Math.PI*r)}}}}:{}}}function ep(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 np={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 Vo(t,e,n,s,i,o,r=!1){const a=t.facing()||Math.sign(s-t.x)||1,l=t.values.wheelSpin??0,c=(s-t.x)*a/t.scale;t.set("wheelSpin",e,l),t.move(e,n,s,{easing:i}),t.set("wheelSpin",n,r?l:l+c/o*(180/Math.PI),i)}const sp=.4;function pS(t){const e=t.wheels[0]?.radius??.4,{forwardMost:n,backMost:s}=ep(t),i=(n-s)/2,o=(a,l,c)=>{const h=a.exaggeration;let u=l;return a.facing()!==c&&(u=a.turnTo(u,c>0?"right":"left")),a.key(u+200,{pitch:4*h,squash:1-.07*h,lean:-.1*h},{act:!1,easing:"ease-out"}),Vo(a,u,u+200,a.x-c*.15*h*a.scale,"ease-out",e),a.effect({kind:"exhaust",time:u+150,x:a.x-c*i*a.scale,y:a.floor-.3*a.scale,length:900,direction:-c}),u+260},r=(a,l,c)=>{const h=a.exaggeration*(c?1.8:1);a.key(l,{pitch:-5*h,lean:-.08*h,squash:.95},{act:!1,easing:"ease-out"}),a.key(l+380,{pitch:0,lean:0,squash:1})};return{drive:{summary:"Drives to `to`: rocks back and squats, lunges forward stretched, and stops with a nose-dive that settles; wheels roll exactly the distance.",needs:["to"],uses:["speed","for"],run(a,l,c){const h=Math.sign(l.to-a.x);if(h===0)return{end:c};const u=o(a,c,h),d=a.exaggeration,f=Math.abs(l.to-a.x),p=l.for??Math.max(500,f/(l.speed??sp));return a.effect({kind:"dust",time:u,x:a.x-h*i*a.scale,y:a.floor,length:600,direction:-h}),a.key(u+140,{pitch:-1.5*d,squash:1+.05*d,lean:.12*d},{act:!1,easing:"ease-out"}),a.key(u+Math.max(160,p-160),{pitch:0,lean:.08*d,squash:1.02},{act:!1}),Vo(a,u,u+p,l.to,"ease-in-out",e),r(a,u+p,!1),{end:u+p+380,contact:u,release:u+p}}},brake:{summary:"Drives toward `to` and slams on the brakes: the wheels lock and it skids the last stretch, nose diving, leaving skid marks.",needs:["to"],uses:["speed","for"],run(a,l,c){const h=Math.sign(l.to-a.x);if(h===0)return{end:c};const u=o(a,c,h),d=a.exaggeration,f=a.x,p=Math.abs(l.to-f),g=l.for??Math.max(600,p/(l.speed??sp*1.2)),m=u+g*.55,w=f+(l.to-f)*.65;return a.key(u+140,{pitch:-1.5*d,squash:1+.06*d,lean:.14*d},{act:!1,easing:"ease-out"}),Vo(a,u,m,w,"ease-in",e),a.key(m+80,{pitch:-7*d,lean:-.12*d,squash:.94},{act:!1,easing:"ease-out"}),Vo(a,m,u+g,l.to,"ease-out",e,!0),a.effect({kind:"skid",time:m,x:w,toX:l.to,y:a.floor,length:g*.45+1500}),a.effect({kind:"dust",time:u+g,x:l.to+h*i*a.scale,y:a.floor,length:600,direction:h}),r(a,u+g,!0),{end:u+g+380,contact:m,release:u+g}}},bump:{summary:"Hits a bump: squashes, hops up stretched, lands squashed with dust, and springs back.",uses:["for"],run(a,l,c){const h=a.exaggeration;return a.key(c+90,{squash:1-.16*h,pitch:3*h},{act:!1,easing:"ease-out"}),a.key(c+300,{lift:.35*h,squash:1+.12*h,pitch:-3*h},{act:!1,easing:"ease-out"}),a.key(c+540,{lift:0,squash:1-.2*h,pitch:0},{act:!1,easing:"ease-in"}),a.key(c+820,{squash:1}),a.effect({kind:"dust",time:c+540,x:a.x,y:a.floor,length:500}),{end:c+820,contact:c+540}}},honk:{summary:"Honks: a stretch and squash pulse, with honk lines from the front.",run(a,l,c){const h=a.exaggeration;a.key(c+110,{squash:1+.12*h,lean:.04*h},{act:!1,easing:"ease-out"}),a.key(c+240,{squash:1-.06*h,lean:0},{act:!1}),a.key(c+520,{squash:1});const u=a.facing();return a.effect({kind:"honk",time:c+60,x:a.x+(u||1)*i*a.scale,y:a.floor-.7*a.scale,length:700,direction:u||1}),{end:c+520,contact:c+60}}},...t.door?{door:{summary:"Opens the doors (`open: true`) or shuts them (`open: false`).",needs:["open"],run(a,l,c){return a.key(c+450,{door:l.open?1:0}),{end:c+600,contact:c+450}}}}:{},...t.lights?{lights:{summary:"Switches the lights on (`on: true`) or off.",needs:["on"],run(a,l,c){return a.key(c+120,{lights:l.on?1:0},{act:!1}),{end:c+300,contact:c+120}}}}:{}}}function ip(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 op(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 rp(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 ap(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 lp(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 cp(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 hp(t={}){const e=t.colors?.body??"#e0473b",n=[0,.32,-.05],s=[0,.86,-.22],i=[0,.9,.42],o=[0,.34,.56],r=[0,.34,-.56];return xe({kind:"bike",summary:"A bicycle: rides (drive) with its wire wheels turning, brakes, bumps, rings its bell (honk).",width:.5,frame:[{points:[r,n]},{points:[n,s]},{points:[s,r]},{points:[s,i]},{points:[n,i]},{points:[i,o]},{points:[[.24,.98,.44],[-.24,.98,.44]],radius:.025,color:"#3b3b44"},{points:[i,[0,.98,.44]],radius:.025,color:"#3b3b44"}],extras:[{id:"saddle",shape:{type:"ellipsoid",radii:[.08,.035,.15],segments:10},at:[0,.89,-.22],fill:"#3b3b44",outline:.7}],wheels:[{forward:.56,side:0,radius:.34,style:"spoked"},{forward:-.56,side:0,radius:.34,style:"spoked"}],seat:[0,.9,-.22],colors:{body:e,tyre:"#2c2c33",...t.colors}})}function up(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 dp(t={}){const e=t.height??2.4,n=t.trunkRadius??.16,s=t.canopy?.radius??1.1,i=t.canopy?.shape==="tall",o={trunk:"#8a5a3b",leaves:"#5cae5a",...t.colors},r=_e(t.canopy?.seed??7),a=[{id:"trunk",shape:{type:"tube",points:[[0,0,0],[.06,e*.5,0],[-.02,e,0]],radius:n,segments:8},fill:o.trunk},{id:"branch",parent:"trunk",shape:{type:"tube",points:[[0,0,0],[.45,.4,.1]],radius:n*.45,segments:6},at:[.04,e*.62,0],fill:o.trunk},{id:"canopy",parent:"trunk",shape:{type:"ellipsoid",radii:[s,s*(i?1.35:.88),s],segments:14},at:[-.02,e+s*.55,0],fill:o.leaves}],l=t.canopy?.lobes??7;for(let h=0;h<l;h++){const u=Math.PI*2*h/l+r.next()*.6,d=(r.next()-.25)*s*(i?1.1:.7),f=s*(.48+r.next()*.22),p=[Math.cos(u)*s*.78,d,Math.sin(u)*s*.6];a.push({id:`lobe-${h}`,parent:"canopy",shape:{type:"ellipsoid",radii:[f,f*.86,f],segments:12},at:p,fill:o.leaves})}const c={parts:a,controls:{sway:{description:"The whole tree bending in the wind, about its base",unit:"degrees",bind:[{parts:["trunk"],rotate:{axis:"z",degrees:1}}]},canopySway:{description:"The canopy bending further than the trunk (it trails the sway)",unit:"degrees",bind:[{parts:["canopy"],rotate:{axis:"z",degrees:1,pivot:[0,-s*.8,0]}}]}},length:s*2.2,height:e+s*2,footprint:[s*1.6,s*1.6],anchors:{canopy:{part:"canopy",at:[0,0,0]},top:{part:"canopy",at:[0,s*.9,0]},base:{at:[0,0,0]},branch:{part:"branch",at:[.45,.4,.1]}}};return{kind:t.kind??"tree",family:"plant",summary:t.summary??"A tree: sways in the wind with its canopy trailing, shakes, sheds leaves, pops up.",rig:c,actions:mS(),acting:fp,colors:{body:o.leaves}}}const fp={depth:{sway:1,canopySway:2,size:0,squash:1},limits:{sway:2,canopySway:3,squash:.08},eyes:[],headTurns:{},drift:[]};function mS(){const t=(e,n,s,i)=>{const o=e.anchor("canopy");e.effect({kind:"leaves",time:n,x:o.x,y:o.y,length:s,direction:i,toY:e.floor})};return{sway:{summary:"Sways in gusts of `wind` (0..1, default 0.5) for `for` ms (default 3000); the canopy trails the trunk, and a strong wind sheds leaves.",uses:["wind","for"],run(e,n,s){const i=n.wind??.5,o=n.for??3e3,r=e.exaggeration,a=260;let l=0;for(let c=a;c<o;c+=a){const h=.55+.45*Math.sin(c/o*Math.PI*2.3),u=Math.sin(c/170)*.35,d=-i*9*r*(h+u*i);e.key(s+c,{sway:d,canopySway:l*1.3},{act:!1,easing:"ease-in-out"}),l=d}if(e.key(s+o,{sway:0,canopySway:0}),i>.45)for(let c=0;c<o;c+=700)t(e,s+c,2200,1);return{end:s+o}}},shake:{summary:"Shakes (something hit it): a quick wobble that dies away, shedding leaves.",uses:["for"],run(e,n,s){const i=n.for??900,o=e.exaggeration,r=6;for(let a=1;a<=r;a++){const l=1-a/(r+1),c=a%2===0?1:-1;e.key(s+i*a/(r+1),{sway:c*5*o*l,canopySway:-c*6*o*l},{act:!1,easing:"ease-in-out"})}return e.key(s+i,{sway:0,canopySway:0}),t(e,s+60,1800,1),t(e,s+260,1800,-1),{end:s+i,contact:s}}},shedLeaves:{summary:"Leaves fall from the canopy for `for` ms (default 2000).",uses:["for"],run(e,n,s){const i=n.for??2e3;for(let o=0;o<i;o+=500)t(e,s+o,2e3,o%1e3===0?1:-1);return{end:s+i}}}}}function gp(t={}){const e=t.width??4,n=t.depth??3.2,s=t.wallHeight??2.5,i=t.roofHeight??1.5,o=t.overhang??.25,r={walls:"#f1d9a8",roof:"#b8433a",door:"#7a4b2a",doorway:"#3a2a22",glass:"#bfe3f2",lit:"#ffd66b",chimney:"#9b5a45",...t.colors},a=n/2+.01,l=t.door?.width??.9,c=t.door?.height??1.9,h=t.door?.at??0,u=t.windows??[{at:-1.25,low:1,width:.8,height:.8},{at:1.25,low:1,width:.8,height:.8}],d=[{id:"walls",shape:{type:"box",size:[e,s,n]},at:[0,s/2,0],fill:r.walls},{id:"roof",shape:{type:"extrude",profile:[[-n/2-o,s],[n/2+o,s],[0,s+i]],width:e+o*2},fill:r.roof,layer:1},{id:"doorway",shape:{type:"panel",points:[[0,0],[l,0],[l,c],[0,c]],facing:"front"},at:[h-l/2,0,a-.005],fill:r.doorway,outline:.6,seeThrough:!0},{id:"door",shape:{type:"panel",points:[[0,0],[l,0],[l,c],[0,c]],facing:"front"},at:[h-l/2,0,a+.005],fill:r.door,outline:.8,overRider:!0}];u.forEach((g,m)=>{d.push({id:`window-${m}`,shape:{type:"panel",points:[[-g.width/2,g.low],[g.width/2,g.low],[g.width/2,g.low+g.height],[-g.width/2,g.low+g.height]],facing:"front"},at:[g.at,0,a+.01],fill:r.glass,outline:.8,glow:{control:"lights",color:r.lit}})});for(const g of[1,-1])d.push({id:`side-window-${g>0?"left":"right"}`,shape:{type:"panel",points:[[-.4,1],[.4,1],[.4,1.8],[-.4,1.8]],facing:g>0?"left":"right"},at:[g*(e/2+.01),0,0],fill:r.glass,outline:.8,glow:{control:"lights",color:r.lit}});const f=t.chimney===!1?void 0:{at:t.chimney?.at??e*.28,back:t.chimney?.back??-n*.18};if(f){const g=s+i*(1-Math.abs(f.back)/(n/2+o)),m=s+i+.45;d.push({id:"chimney",shape:{type:"box",size:[.42,m-g+.3,.42]},at:[f.at,(m+g-.3)/2,f.back],fill:r.chimney,layer:1})}const p={parts:d,controls:{door:{description:"The front door open: 0 shut, 1 open",unit:"0..1",min:0,max:1,bind:[{parts:["door"],rotate:{axis:"y",degrees:-80}}]},lights:{description:"The windows lit: 0 dark, 1 lit",unit:"0..1",min:0,max:1}},length:n+o*2,height:s+i+.6,footprint:[e+.6,n+.6],anchors:{door:{at:[h,c/2,a]},doorstep:{at:[h,0,a+.4]},ridge:{at:[0,s+i,0]},...f?{chimney:{at:[f.at,s+i+.5,f.back]}}:{}}};return{kind:t.kind??"house",family:"building",summary:t.summary??"A house: opens its door, lights its windows, puffs chimney smoke, shakes, pops up.",rig:p,actions:yS(!!f),acting:pp,colors:{body:r.walls}}}const pp={depth:{door:1,lights:0,roll:1,squash:1,size:0},limits:{door:.1,roll:1.5,squash:.05},eyes:[],headTurns:{},drift:[]};function yS(t){return{door:{summary:"Opens the front door (`open: true`) or shuts it (`open: false`).",needs:["open"],run(e,n,s){return e.key(s+500,{door:n.open?1:0}),{end:s+650,contact:s+500}}},lights:{summary:"Lights the windows (`on: true`) or puts them out.",needs:["on"],run(e,n,s){return e.key(s+150,{lights:n.on?1:0},{act:!1}),{end:s+300,contact:s+150}}},shake:{summary:"Shakes, as when a door slams or something lands on it: a squash and a wobble that dies away, with dust.",uses:["for"],run(e,n,s){const i=n.for??700,o=e.exaggeration;e.key(s+80,{squash:1-.06*o},{act:!1,easing:"ease-out"});for(let r=1;r<=5;r++){const a=1-r/6;e.key(s+80+i*r/6,{roll:(r%2===0?1:-1)*2.2*o*a,squash:1+.02*a},{act:!1,easing:"ease-in-out"})}return e.key(s+i+80,{roll:0,squash:1}),e.effect({kind:"dust",time:s+80,x:e.x,y:e.floor,length:600}),{end:s+i+80,contact:s+80}}},...t?{smoke:{summary:"Starts smoke puffing from the chimney for `for` ms (default 3000), drifting with the wind; the next beat starts at once (the smoke carries on).",uses:["for","wind"],run(e,n,s){const i=n.for??3e3,o=e.anchor("chimney");return e.effect({kind:"smoke",time:s,x:o.x,y:o.y,length:i+1500,direction:(n.wind??.4)>=0?1:-1}),{end:s+50,release:s+i}}}}:{}}}function mp(t={}){const e=t.width??.46,n=t.depth??.46,s=t.seatHeight??.46,i=t.backHeight??.95,o={wood:"#8a5a3b",seat:"#c48a4a",...t.colors},r=.05,a=.025,l=[{id:"seat",shape:{type:"box",size:[e,r,n]},at:[0,s-r/2,0],fill:o.seat},{id:"back",shape:{type:"box",size:[e,i-s,r]},at:[0,(i+s)/2,-n/2+r/2],fill:o.wood}];for(const[h,u,d]of[[-1,1,"front-left"],[1,1,"front-right"],[-1,-1,"back-left"],[1,-1,"back-right"]])l.push({id:`leg-${d}`,shape:{type:"tube",points:[[0,0,0],[0,s-r,0]],radius:a,segments:6},at:[h*(e/2-a*1.5),0,u*(n/2-a*1.5)],fill:o.wood});const c={parts:l,controls:{tip:{description:"Tipped back on its rear legs (+), degrees",unit:"degrees",min:0,max:60,bind:[{parts:l.map(h=>h.id),rotate:{axis:"x",degrees:1,pivot:[0,0,-n/2+a*1.5]}}]}},length:n,height:i,footprint:[e,n],anchors:{seat:{at:[0,s,0]},back:{at:[0,i,-n/2]},front:{at:[0,0,n/2+.3]}}};return{kind:t.kind??"chair",family:"furniture",summary:t.summary??"A chair: a seat to sit on (`seat`), tips back on its rear legs and settles, or falls over.",rig:c,actions:bS(),acting:yp,colors:{body:o.seat}}}const yp={depth:{tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.05},eyes:[],headTurns:{},drift:[]};function bS(){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 bp(t={}){const e=t.width??1.4,n=t.depth??.7,s=t.height??.75,i={wood:"#8a5a3b",top:"#a9754a",knob:"#2b2b2b",...t.colors},o=.04,r=.03,a=.14,l=e*.4,c=[{id:"top",shape:{type:"box",size:[e,o,n]},at:[0,s-o/2,0],fill:i.top},{id:"drawer",shape:{type:"box",size:[l,a,n*.8]},at:[-e/2+l/2+.05,s-o-a/2,0],fill:i.wood},{id:"knob",parent:"drawer",shape:{type:"ellipsoid",radii:[.02,.02,.015],segments:8},at:[0,0,n*.4+.012],fill:i.knob,outline:.6}];for(const[u,d,f]of[[-1,1,"front-left"],[1,1,"front-right"],[-1,-1,"back-left"],[1,-1,"back-right"]])c.push({id:`leg-${f}`,shape:{type:"tube",points:[[0,0,0],[0,s-o,0]],radius:r,segments:6},at:[u*(e/2-r*2),0,d*(n/2-r*2)],fill:i.wood});const h={parts:c,controls:{drawer:{description:"The drawer out: 0 shut, 1 open",unit:"0..1",min:0,max:1,bind:[{parts:["drawer"],translate:[0,0,n*.5]}]}},length:n,height:s,footprint:[e,n],anchors:{top:{at:[0,s,0]},edge:{at:[0,s,n/2]},drawer:{part:"drawer",at:[0,0,n*.4]},chair:{at:[0,0,n/2+.35]}}};return{kind:t.kind??"desk",family:"furniture",summary:t.summary??"A desk: a top to work at (`top`, `edge`), a drawer that opens (`drawer`), a place for a chair in front (`chair`).",rig:h,actions:{drawer:{summary:"Opens the drawer (`open: true`) or shuts it (`open: false`).",needs:["open"],run(u,d,f){return u.key(f+400,{drawer:d.open?1:0},{easing:d.open?"ease-out":"ease-in"}),{end:f+500,contact:f+400}}}},acting:wp,colors:{body:i.top}}}const wp={depth:{drawer:1,roll:1,squash:1,size:0},limits:{drawer:.08,roll:1,squash:.04},eyes:[],headTurns:{},drift:[]};function kp(t={}){const e=t.length??2,n=t.width??1,s=t.height??.55,i=t.headboard??.95,o={wood:"#8a5a3b",mattress:"#f1ece2",blanket:"#5b7fb0",pillow:"#fbf8f2",...t.colors},r=.3,a=s-r,c={parts:[{id:"frame",shape:{type:"box",size:[n,r,e]},at:[0,r/2,0],fill:o.wood},{id:"headboard",shape:{type:"box",size:[n+.06,i-r,.06]},at:[0,(i+r)/2,-e/2-.03],fill:o.wood},{id:"mattress",shape:{type:"box",size:[n-.04,a,e-.04]},at:[0,r+a/2,0],fill:o.mattress},{id:"blanket",parent:"mattress",shape:{type:"box",size:[n-.02,.04,e*.62]},at:[0,a/2+.02,e*.19],fill:o.blanket,outline:.7},{id:"pillow",parent:"mattress",shape:{type:"ellipsoid",radii:[n*.32,.07,.22],segments:12},at:[0,a/2+.06,-e/2+.32],fill:o.pillow,outline:.7}],controls:{give:{description:"The mattress pressed down: 1 as made, below squashed (someone landed on it)",unit:"factor",default:1,min:.5,max:1.2,bind:[{parts:["mattress"],scale:[1,1,1]}]}},length:e,height:i,footprint:[n,e],anchors:{mattress:{part:"mattress",at:[0,a/2,0]},pillow:{part:"mattress",at:[0,a/2+.1,-e/2+.32]},foot:{at:[0,s,e/2]},side:{at:[n/2+.25,0,0]}}};return{kind:t.kind??"bed",family:"furniture",summary:t.summary??"A bed: a mattress to lie on (`mattress`, `pillow`) that gives and springs back when someone lands on it (`bounce`), a side to sit on (`side`).",rig:c,actions:{bounce:{summary:"The mattress gives (someone landed on it) and springs back over `for` ms (default 700).",uses:["for"],run(h,u,d){const f=u.for??700,p=h.exaggeration;return h.key(d+90,{give:1-.18*p},{act:!1,easing:"ease-out"}),h.key(d+f*.45,{give:1+.05*p},{act:!1,easing:"ease-in-out"}),h.key(d+f*.7,{give:1-.04*p},{act:!1,easing:"ease-in-out"}),h.key(d+f,{give:1}),{end:d+f,contact:d+90}}}},acting:vp,colors:{body:o.blanket}}}const vp={depth:{give:1,roll:1,squash:1,size:0},limits:{give:.03,roll:.5,squash:.03},eyes:[],headTurns:{},drift:[]};function Mp(t={}){const e=t.width??.9,n=t.height??2.05,s=t.hinge??"left",i={frame:"#d9d2c3",door:"#7a4b2a",handle:"#c9a227",beyond:"#2a2f3a",...t.colors},o=.1,r=s==="left"?1:-1,a=r>0?[[0,0],[-e,0],[-e,n],[0,n]]:[[0,0],[e,0],[e,n],[0,n]],c={parts:[{id:"post-left",shape:{type:"box",size:[o,n+o,o]},at:[e/2+o/2,(n+o)/2,0],fill:i.frame},{id:"post-right",shape:{type:"box",size:[o,n+o,o]},at:[-e/2-o/2,(n+o)/2,0],fill:i.frame},{id:"lintel",shape:{type:"box",size:[e+o*2,o,o]},at:[0,n+o/2,0],fill:i.frame},{id:"beyond",shape:{type:"panel",points:[[-e/2,0],[e/2,0],[e/2,n],[-e/2,n]],facing:"front"},at:[0,0,-.03],fill:i.beyond,outline:.4,seeThrough:!0},{id:"door",shape:{type:"panel",points:a,facing:"front"},at:[r*e/2,0,.005],fill:i.door,outline:.9,overRider:!0},{id:"handle",parent:"door",shape:{type:"ellipsoid",radii:[.03,.03,.03],segments:8},at:[-r*(e-.1),n*.47,.03],fill:i.handle,outline:.5}],controls:{open:{description:"How far the door is open: 0 shut, 1 open wide",unit:"0..1",min:0,max:1,bind:[{parts:["door"],rotate:{axis:"y",degrees:r*-95}}]}},length:.3,height:n+o,footprint:[e+o*2,.3],anchors:{handle:{part:"door",at:[-r*(e-.1),n*.47,.03]},doorway:{at:[0,0,0]},front:{at:[0,0,.5]},beyond:{at:[0,0,-.5]}}};return{kind:t.kind??"door",family:"furniture",summary:t.summary??"A door in its frame: opens and shuts on its hinge (`open`), slams, rattles when knocked; a figure goes through the `doorway` from `front` to `beyond`.",rig:c,actions:wS(),acting:Sp,colors:{body:i.door}}}const Sp={depth:{open:1,roll:1,squash:1,size:0},limits:{open:.08,roll:.6,squash:.03},eyes:[],headTurns:{},drift:[]};function wS(){return{open:{summary:"Opens the door (`open: true`, default) or shuts it (`open: false`), over `for` ms (default 600).",uses:["open","for"],run(t,e,n){const s=e.for??600;return t.key(n+s,{open:e.open===!1?0:1},{easing:"ease-in-out"}),{end:n+s+80,contact:n+s}}},slam:{summary:"Slams shut: a fast swing, a shudder in the frame, dust.",run(t,e,n){const s=t.exaggeration;t.key(n+180,{open:0},{act:!1,easing:"ease-in"});for(let i=1;i<=4;i++)t.key(n+180+i*70,{roll:(i%2===0?1:-1)*1.2*s*(1-i/5)},{act:!1});return t.key(n+180+350,{roll:0}),t.effect({kind:"dust",time:n+180,x:t.x,y:t.floor,length:500}),{end:n+180+350,contact:n+180}}},knock:{summary:"Someone knocks three times: the door rattles over `for` ms (default 700).",uses:["for"],run(t,e,n){const i=e.for??700,o=t.exaggeration;for(let r=0;r<3;r++){const a=n+i*(r+.5)/3;t.key(a,{open:.03*o},{act:!1,easing:"ease-out"}),t.key(a+60,{open:0},{act:!1,easing:"ease-in"})}return{end:n+i,contact:n+i/6}}}}}const Tp=1.4;function xp(t={}){const e=t.width??.5,n=t.seatHeight??.5,s=t.wheelRadius??.3,i=.08,o={frame:"#2b2f36",seat:"#3c6ea5",tyre:"#1f2328",...t.colors},r=.04,a=.018,l=.44,c=n+.5,h=-.08,u=e/2+.06,d=[{id:"seat",shape:{type:"box",size:[e,r,l]},at:[0,n-r/2,0],fill:o.seat},{id:"back",shape:{type:"box",size:[e,c-n-.02,r]},at:[0,(c+n)/2,-l/2+r/2],fill:o.seat},{id:"footrest",shape:{type:"box",size:[e*.8,.02,.14]},at:[0,.12,l/2+.22],fill:o.frame}];for(const[g,m]of[[-1,"left"],[1,"right"]]){const w=g*u,v=(k,b,E=a)=>{d.push({id:k,shape:{type:"tube",points:b,radius:E,segments:6},fill:o.frame,outline:.7})};v(`post-${m}`,[[w,n-.1,-l/2],[w,c+.04,-l/2],[w,c+.04,-l/2-.14]]),v(`rail-${m}`,[[w,n-.03,-l/2],[w,n-.03,l/2]]),v(`leg-${m}`,[[w,n-.03,l/2],[w*.85,i,l/2+.06]]),v(`strut-${m}`,[[w*.85,i+.08,l/2+.04],[w*.8,.13,l/2+.22]]),v(`armrest-${m}`,[[w,n+.22,-l/2+.02],[w,n+.22,l/2-.08]],a*1.3),d.push({id:`wheel-${m}`,shape:{type:"cylinder",radius:s,length:.04,axis:"x",segments:20,spokes:8},at:[w+g*.03,s,h],ink:o.tyre,outline:1.3}),d.push({id:`rim-${m}`,shape:{type:"cylinder",radius:s*.9,length:.012,axis:"x",segments:20},at:[g*.045,0,0],parent:`wheel-${m}`,ink:o.frame,outline:.8}),d.push({id:`castor-${m}`,shape:{type:"cylinder",radius:i,length:.03,axis:"x",segments:12,spokes:3},at:[w*.85,i,l/2+.06],fill:o.tyre})}const f=d.map(g=>g.id).filter(g=>!g.startsWith("rim-")),p={parts:d,controls:{wheelSpin:{description:"How far the big wheels have turned, degrees (keyed with the distance rolled, so they never skate); the castors turn faster",unit:"degrees",bind:[{parts:["wheel-left","wheel-right"],rotate:{axis:"x",degrees:1}},{parts:["castor-left","castor-right"],rotate:{axis:"x",degrees:s/i}}]},tip:{description:"Tipped back on its big wheels (+), degrees: a wheelie, or a helper tipping it up a kerb",unit:"degrees",min:0,max:45,bind:[{parts:f,rotate:{axis:"x",degrees:1,pivot:[0,s,h]}}]}},length:l+.4,height:c+.04,footprint:[u*2+.1,l+.4],anchors:{seat:{at:[0,n,.02]},handles:{at:[0,0,-l/2-.5]},front:{at:[0,0,l/2+.6]},footrest:{at:[0,.13,l/2+.22]}}};return{kind:t.kind??"wheelchair",family:"furniture",summary:t.summary??"A wheelchair: rolls to `to` with its wheels turning the distance (roll), brakes, tips back on its big wheels (wheelie); its `seat` is ridden in the `wheeling` pose and a pusher stands at `handles`.",rig:p,actions:kS(s),acting:Ep,colors:{body:o.seat,ink:o.frame},wheelRadius:s,moves:{roll:{speed:Tp,perMetre:{wheelSpin:180/(Math.PI*s)}}}}}const Ep={depth:{wheelSpin:0,tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.03},eyes:[],headTurns:{},drift:[]};function Ap(t,e,n,s,i,o,r=!1){const a=t.facing()||Math.sign(s-t.x)||1,l=t.values.wheelSpin??0,c=(s-t.x)*a/t.scale;t.set("wheelSpin",e,l),t.move(e,n,s,{easing:i}),t.set("wheelSpin",n,r?l:l+c/o*(180/Math.PI),i)}function kS(t){return{roll:{summary:"Rolls to `to` at `speed` px/ms (or over `for` ms): a small push-off, the wheels turning exactly the distance, and a gentle stop.",needs:["to"],uses:["speed","for"],run(e,n,s){const i=Math.sign(n.to-e.x);if(i===0)return{end:s};let o=s;e.facing()!==i&&(o=e.turnTo(o,i>0?"right":"left"));const r=Math.abs(n.to-e.x),a=n.for??Math.max(300,r/(n.speed??Tp*e.scale/1e3));return e.key(o+150,{tip:1.5*e.exaggeration},{act:!1,easing:"ease-out"}),Ap(e,o,o+a,n.to,"ease-in-out",t),e.key(o+a,{tip:0},{easing:"ease-out"}),{end:o+a}}},brake:{summary:"Stops short at `to`: the wheels lock and it skids the last bit, tipping forward a touch.",needs:["to"],uses:["for"],run(e,n,s){if(Math.sign(n.to-e.x)===0)return{end:s};const o=n.for??500;return Ap(e,s,s+o,n.to,"ease-out",t,!0),e.key(s+o,{tip:0},{easing:"ease-out"}),e.effect({kind:"dust",time:s+o*.5,x:n.to,y:e.floor,length:500}),{end:s+o,contact:s+o}}},wheelie:{summary:"Tips back onto its big wheels, balances there for `for` ms (default 1200), and drops down.",uses:["for"],run(e,n,s){const i=24*e.exaggeration,o=n.for??1200;return e.key(s+300,{tip:i},{easing:"ease-out"}),e.key(s+300+o*.5,{tip:i*.9},{act:!1,easing:"ease-in-out"}),e.key(s+300+o,{tip:i},{act:!1,easing:"ease-in-out"}),e.key(s+300+o+250,{tip:0},{easing:"ease-in"}),e.effect({kind:"dust",time:s+300+o+250,x:e.x,y:e.floor,length:400}),{end:s+300+o+250,contact:s+300+o+250}}}}}function Pp(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:vS(),acting:rc,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:15,flies:!0,hold:{blur:1},perSecond:{rotor:je*1e3}}}}}const rc={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:[]},je=2.6;function vS(){const t=(n,s,i,o,r)=>{const a=n.values.rotor??0;n.set("rotor",s,a);const l=r?o*(i-s)*.5:o*(i-s);n.set("rotor",i,a+l,r)},e=n=>n.values.lift>.05;return{takeOff:{summary:"Spools the rotor up (the skids squash as it bites), then lifts off nose-down to `height` metres (default 3).",uses:["height"],run(n,s,i){const o=n.exaggeration,r=s.height??3;t(n,i,i+900,je,"ease-in"),n.key(i+900,{blur:1},{act:!1,easing:"ease-in"}),n.key(i+700,{squash:1-.08*o},{act:!1,easing:"ease-in"});const a=i+1e3;return n.key(a+150,{squash:1+.06*o,lift:.3},{act:!1,easing:"ease-out"}),n.key(a+1300,{squash:1,lift:r,pitch:-4*o},{act:!1,easing:"ease-in-out"}),n.key(a+1700,{pitch:0}),t(n,i+900,a+1700,je),n.effect({kind:"dust",time:a,x:n.x,y:n.floor,length:900}),{end:a+1700,contact:a}}},fly:{summary:"Flies to `to` (and to `height`, if given): nose down and banked into the move, nose up and leveling as it stops.",needs:["to"],uses:["height","speed","for"],run(n,s,i){const o=n.exaggeration,r=Math.sign(s.to-n.x);let a=i;r!==0&&n.facing()!==r&&(a=n.turnTo(a,r>0?"right":"left"));const l=Math.abs(s.to-n.x),c=s.for??Math.max(700,l/(s.speed??.3)),h=s.height??n.values.lift;return n.key(a+300,{pitch:-9*o,roll:6*o},{act:!1,easing:"ease-out"}),n.key(a+c-250,{pitch:-4*o,roll:3*o,lift:h},{act:!1}),n.key(a+c,{pitch:7*o,roll:0},{act:!1,easing:"ease-out"}),n.key(a+c+450,{pitch:0}),n.move(a,a+c,s.to,{easing:"ease-in-out"}),t(n,i,a+c+450,je),{end:a+c+450,contact:a,release:a+c}}},hover:{summary:"Hovers in place for `for` ms (default 2000), bobbing gently.",uses:["for"],run(n,s,i){const o=s.for??2e3,r=n.values.lift,a=n.exaggeration;for(let l=350,c=0;l<o;l+=350,c++)n.key(i+l,{lift:r+(c%2===0?.12:-.06)*a,roll:(c%2===0?1.5:-1.5)*a},{act:!1,easing:"ease-in-out"});return n.key(i+o,{lift:r,roll:0},{act:!1,easing:"ease-in-out"}),(e(n)||r>0)&&t(n,i,i+o,je),{end:i+o}}},land:{summary:"Settles down onto its skids: a flare, a squash on touchdown with dust, and the rotor spools down.",run(n,s,i){const o=n.exaggeration,r=i+Math.max(900,n.values.lift*450);return n.key(i+400,{pitch:3*o},{act:!1,easing:"ease-out"}),n.key(r,{lift:0,pitch:0,squash:1-.14*o},{act:!1,easing:"ease-in"}),n.key(r+280,{squash:1}),t(n,i,r,je),t(n,r,r+1600,je,"ease-out"),n.key(r+1600,{blur:0},{act:!1,easing:"ease-out"}),n.effect({kind:"dust",time:r,x:n.x,y:n.floor,length:800}),{end:r+1600,contact:r}}}}}function $p(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:SS(),acting:rc,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:30,flies:!0,hold:{blur:1},perSecond:{rotor:je*1e3}}}}}const MS=3.2;function SS(){const t=(n,s,i,o)=>{const r=n.values.rotor??0;n.set("rotor",s,r),n.set("rotor",i,r+MS*(i-s)*(o?.5:1),o)},e=(n,s,i)=>{const o=Math.sign(i-n.x);return o!==0&&n.facing()!==o?n.turnTo(s,o>0?"right":"left"):s};return{takeOff:{summary:"Spins the propeller up, runs along the ground toward `to`, lifts its nose and climbs to `height` metres (default 4).",needs:["to"],uses:["height","for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to);t(n,r,r+700,"ease-in"),n.key(r+700,{blur:1},{act:!1,easing:"ease-in"});const a=s.for??2600,l=n.x,c=r+700+a*.55,h=l+(s.to-l)*.45;return n.move(r+700,c,h,{easing:"ease-in"}),n.key(c,{pitch:8*o,squash:1+.04*o},{act:!1,easing:"ease-out"}),n.key(r+700+a,{lift:s.height??4,pitch:10*o,squash:1},{act:!1,easing:"ease-in-out"}),n.move(c,r+700+a,s.to),n.key(r+700+a+500,{pitch:0}),t(n,r+700,r+700+a+500),n.effect({kind:"dust",time:c,x:h,y:n.floor,length:700}),{end:r+700+a+500,contact:c}}},fly:{summary:"Flies to `to` (and `height`), banking into the move and leveling out.",needs:["to"],uses:["height","speed","for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to),a=s.for??Math.max(800,Math.abs(s.to-n.x)/(s.speed??.45)),l=s.height??n.values.lift;return n.key(r+350,{roll:10*o,pitch:l>n.values.lift?6*o:-3*o},{act:!1,easing:"ease-out"}),n.key(r+a-300,{roll:4*o,lift:l},{act:!1}),n.key(r+a,{roll:0,pitch:0}),n.move(r,r+a,s.to,{easing:"ease-in-out"}),t(n,i,r+a),{end:r+a,contact:r,release:r+a}}},loop:{summary:"Loops the loop: pulls up and over in a full circle (`for` ms, default 2400), carrying on the way it was going.",uses:["for"],run(n,s,i){const o=s.for??2400,r=2.2*n.exaggeration,a=n.facing()||1,l=16,c=n.x,h=n.values.lift,u=n.values.pitch;for(let d=1;d<=l;d++){const f=Math.PI*2*d/l,p=i+o*d/l;n.key(p,{lift:h+r*(1-Math.cos(f)),pitch:u+360*d/l},{act:!1}),n.move(i+o*(d-1)/l,p,c+a*(r*Math.sin(f)+d/l*r*1.2)*n.scale)}return n.key(i+o+1,{pitch:u},{act:!1}),t(n,i,i+o),{end:i+o+1}}},land:{summary:"Comes down toward `to`: descends, flares nose-up, touches down with a squash and dust, rolls to a stop and the propeller spools down.",needs:["to"],uses:["for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to),a=n.x,l=s.for??2200,c=r+l,h=a+(s.to-a)*.7;return n.key(r+l*.4,{pitch:-4*o},{act:!1,easing:"ease-out"}),n.key(c-250,{pitch:6*o,lift:.15},{act:!1,easing:"ease-in-out"}),n.key(c,{lift:0,pitch:0,squash:1-.12*o},{act:!1,easing:"ease-in"}),n.key(c+260,{squash:1}),n.move(r,c,h),n.move(c,c+1200,s.to,{easing:"ease-out"}),t(n,i,c),t(n,c,c+1600,"ease-out"),n.key(c+1600,{blur:0},{act:!1,easing:"ease-out"}),n.effect({kind:"dust",time:c,x:h,y:n.floor,length:700}),{end:c+1600,contact:c}}}}}const rs=["walk","trot","canter","gallop"],TS=rs,Ip=["fl","fr","hl","hr"],Jo={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}},Ke=Math.PI/180;function Zo(t,e){return 4*t*Math.sin(Jo[e].swing*Ke)}function Xe(t){const{legs:e,colors:n}=t,s=e.upper+e.lower+e.foot,i=s+t.body.rise,o=(u,d)=>[d*u[0],u[1],u[2]],r=[{id:"body",shape:{type:"ellipsoid",radii:t.body.radii,segments:18},at:[0,i,0],fill:n.coat},{id:"neck",shape:{type:"tube",points:t.neck.points,radius:t.neck.points.map((u,d,f)=>t.neck.radius*(1.25-.4*d/Math.max(1,f.length-1))),segments:12},at:t.neck.at,fill:n.coat},{id:"head",parent:"neck",shape:{type:"ellipsoid",radii:t.head.radii,segments:14},at:t.head.at,rotate:t.head.rotate,fill:n.coat},...ES(t,n,i)];t.mane&&r.push({id:"mane",parent:"neck",shape:{type:"tube",points:t.mane.points,radius:t.mane.radius,segments:6},fill:n.dark,outline:.7}),t.muzzle&&r.push({id:"muzzle",parent:"head",shape:{type:"ellipsoid",radii:t.muzzle.radii,segments:10},at:t.muzzle.at,fill:n.muzzle,outline:.8});for(const u of[1,-1]){const d=u>0?"left":"right",f=t.ears.rotate?o(t.ears.rotate,1).map((p,g)=>g===2?u*p:p):void 0;r.push({id:`ear-${d}`,parent:"head",shape:{type:"ellipsoid",radii:t.ears.radii,segments:8},at:o(t.ears.at,u),rotate:f,fill:n.coat,outline:.7},{id:`eye-${d}`,parent:"head",shape:{type:"ellipsoid",radii:[t.eyes.size*.8,t.eyes.size,t.eyes.size*.9],segments:8},at:o(t.eyes.at,u),fill:"#1d1d22",outline:.4})}r.push(...t.extras?.(n)??[]);const a={walk:{description:"Phase of the stride, in full cycles (keyed in step with the distance covered)",unit:"cycles"},walking:{description:"How much of the gait is applied: 0 standing, 1 moving",unit:"0..1",min:0,max:1},gait:{description:`Which gait: ${t.gaits.map(u=>`${rs.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:he,rotate:{axis:"x",degrees:1/he.length}}]},wag:{description:"Tail swung side to side, curling",unit:"degrees",bind:[{parts:he,rotate:{axis:"y",degrees:1/he.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 Ip){const d=u[0]==="f",f=u[1]==="l"?1:-1,p=d?e.thickness[0]:e.thickness[1];r.push({id:`${u}-upper`,shape:{type:"tube",points:[[0,e.upper*.2,0],[0,-e.upper*.5,0],[0,-e.upper,0]],radius:[p,p*.85,e.lowerThickness*1.15],segments:10},at:[f*e.across,s,d?e.front:e.hind],fill:n.coat},{id:`${u}-knee`,parent:`${u}-upper`,shape:{type:"ellipsoid",radii:Array(3).fill(e.lowerThickness*1.08),segments:10},at:[0,-e.upper,0],fill:n.coat,solidOnly:!0},{id:`${u}-lower`,parent:`${u}-upper`,shape:{type:"tube",points:[[0,0,0],[0,-e.lower,0]],radius:[e.lowerThickness*1.1,e.lowerThickness*.85],segments:10},at:[0,-e.upper,0],fill:n.coat},{id:`${u}-foot`,parent:`${u}-lower`,shape:{type:"ellipsoid",radii:[e.footSize[0]/2,e.foot/2+.004,e.footSize[1]/2],segments:12},at:[0,-e.lower-e.foot/2,e.footSize[1]*.12],fill:n.foot,outline:.8});const g=`${d?"Front":"Hind"} ${f>0?"left":"right"} leg`;a[`${u}.swing`]={description:`${g}: forward (+) or back (−) from the hip`,unit:"degrees",bind:[{parts:[`${u}-upper`],rotate:{axis:"x",degrees:-1}}]},a[`${u}.knee`]={description:`${g}: knee (hock) folded`,unit:"degrees",bind:[{parts:[`${u}-lower`],rotate:{axis:"x",degrees:d?1:-1}}]},a[`${u}.ankle`]={description:`${g}: foot turned at the ankle (+ toe forward)`,unit:"degrees",bind:[{parts:[`${u}-foot`],rotate:{axis:"x",degrees:-1,pivot:[0,e.foot/2,-e.footSize[1]*.12]}}]}}const l=t.neck.points[t.neck.points.length-1],c={parts:r,controls:a,length:t.body.radii[2]*2+Math.max(0,t.neck.at[2]+l[2]+t.head.radii[2]-t.body.radii[2])+.3,height:t.neck.at[1]+l[1]+t.head.radii[1]*2,footprint:[e.across*2+t.body.radii[0],(e.front-e.hind)*1.4],anchors:{back:{at:[0,i+t.body.radii[1],-t.body.radii[2]*.05]},head:{part:"head",at:[0,0,0]},mouth:{part:t.muzzle?"muzzle":"head",at:t.muzzle?[0,0,t.muzzle.radii[2]]:[0,0,t.head.radii[2]]},front:{at:[0,i,t.body.radii[2]]},...t.anchors},derive:u=>AS(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:{...$S(t,h),...t.actions?.(h)},acting:lc,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:xS(t,s)}}function xS(t,e){const n=i=>{const o=Zo(e,i);return{speed:o/(Jo[i].cycle*(t.cycleScale??1)/1e3),set:{gait:rs.indexOf(i)},hold:{walking:1},perMetre:{walk:1/o}}},s=Object.fromEntries(t.gaits.map(i=>[i==="gallop"&&!t.gaits.includes("canter")?"run":i,n(i)]));return t.gaits.includes("gallop")&&!s.gallop&&(s.gallop=n("gallop")),s}const he=Array.from({length:7},(t,e)=>e===0?"tail":`tail-${e}`);function ES(t,e,n){const s=gl(t.tail.points,he.length+1),[,i,o]=t.body.radii,r=(t.tail.at[1]-n)/i,a=Math.abs(r)<1?-o*Math.sqrt(1-r*r):t.tail.at[2],l=[t.tail.at[0],t.tail.at[1],a+Math.min(.04,o*.08)],c=f=>t.tail.radius*(1-.5*f/he.length),h=he.map((f,p)=>{const g=s[p],m=s[p+1],w=[m[0]-g[0],m[1]-g[1],m[2]-g[2]],v=p===0?void 0:s[p-1];return{id:f,...p>0?{parent:he[p-1]}:{},shape:{type:"tube",points:[[0,0,0],w],radius:[c(p),c(p+1)],segments:8,joined:!0},at:p===0?l:[g[0]-v[0],g[1]-v[1],g[2]-v[2]],fill:e.dark,outline:.8}}),u=s[s.length-1],d=s[s.length-2];return h.push({id:"tail-tip",parent:he[he.length-1],shape:{type:"ellipsoid",radii:Array(3).fill(c(he.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 AS(t,e,n){const s=Math.max(0,Math.min(1,t.walking??0));if(s===0)return{};const i=rs[Math.max(0,Math.min(3,Math.round(t.gait??0)))],o=Jo[e.gaits.includes(i)?i:e.gaits[0]],r=t.walk??0,a={};for(const c of Ip){const h=Math.PI*2*(r+o.offsets[c]);a[`${c}.swing`]=(t[`${c}.swing`]??0)+s*o.swing*Math.sin(h),a[`${c}.knee`]=(t[`${c}.knee`]??0)+s*o.lift*Math.max(0,Math.cos(h))}const l=Math.PI*2*r;return a.lift=(t.lift??0)+s*o.bob*n*Math.abs(Math.sin(l*2)),a.pitch=(t.pitch??0)+s*o.rock*Math.sin(l),a.neck=(t.neck??0)+s*(o.rock>0?-o.rock*1.4:5)*Math.sin(l*2),a}function ac(t){const n=Math.sin(32*Ke),s=t.legLength-(t.front-t.hind)*n,i=72,r=(s-t.upper*Math.cos(i*Ke)-t.foot)/t.lower,a=r>=1?0:r<=-1?180:Math.acos(r)/Ke,l={pitch:32,lift:t.legLength*(1-Math.cos(32*Ke))-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 lc={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:[]},PS=lc;function Op(t){const e=(t.upper+t.lower)*.32,n=Math.asin(Math.min(1,e/(t.upper+t.lower+t.foot)))/Ke,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 $S(t,e){const n=t.cycleScale??1,s=r=>({summary:{walk:"Walks to `to` (four beats), its head bobbing.",trot:"Trots to `to`: legs in diagonal pairs, the body bouncing.",canter:"Canters to `to`: three beats, the body rocking.",gallop:"Gallops (runs) to `to`: legs reaching, the body rocking hard, kicking up dust."}[r],needs:["to"],uses:["for"],run(a,l,c){const h=Math.sign(l.to-a.x);if(h===0)return{end:c};let u=c;a.facing()!==h&&(u=a.turnTo(u,h>0?"right":"left"));const d=a.exaggeration;a.key(u+180,{neck:-12*d},{act:!1,easing:"ease-out"});const p=Math.abs(l.to-a.x)/a.scale/Zo(e.legLength,r),g=l.for??Math.max(500,p*Jo[r].cycle*n),m=a.values.walk??0;return a.set("gait",u,a.values.gait??0),a.set("gait",u+1,rs.indexOf(r)),a.set("walking",u,0),a.set("walking",u+240,1,"ease-out"),a.set("walking",u+g-240,1),a.set("walking",u+g,0,"ease-in"),a.set("walk",u,m),a.move(u,u+g,l.to,{easing:"ease-in-out"}),a.set("walk",u+g,m+p,"ease-in-out"),a.key(u+g+300,{neck:0}),(r==="gallop"||r==="canter")&&(a.effect({kind:"dust",time:u+200,x:a.x-h*e.legLength*a.scale,y:a.floor,length:700,direction:-h}),a.effect({kind:"dust",time:u+g,x:l.to+h*e.legLength*.6*a.scale,y:a.floor,length:600,direction:h})),{end:u+g+300,contact:u,release:u+g}}}),i=Object.fromEntries(t.gaits.map(r=>[r==="gallop"&&!t.gaits.includes("canter")?"run":r,s(r)]));t.gaits.includes("gallop")&&!i.gallop&&(i.gallop=s("gallop"));const o={...i,[t.call]:{summary:`Throws its head up and ${t.call}s.`,run(r,a,l){const c=r.exaggeration;return r.key(l+150,{neck:10*c},{act:!1,easing:"ease-out"}),r.key(l+380,{neck:-28*c,squash:1.05},{act:!1,easing:"ease-out"}),r.key(l+680,{neck:-20*c},{act:!1}),r.key(l+980,{neck:0,squash:1}),e.call(r,l+380),{end:l+980,contact:l+380}}},sit:{summary:"Sits on its haunches for `for` ms (default 1500): the rump goes down onto folded hind legs, paws flat on the ground, the front legs stay planted; then it gets up.",uses:["for"],run(r,a,l){const c=ac(e),h=l+450;r.key(h,c,{act:!1,easing:"ease-in-out"}),r.key(h+(a.for??1500),c,{act:!1});const u=h+(a.for??1500)+450,d={};for(const f of Object.keys(c))d[f]=0;return r.key(u,d),{end:u,contact:h,release:u-450}}},lie:{summary:"Lies down for `for` ms (default 2000), head up and front paws forward (sinking back onto its haunches first), then gets up.",uses:["for"],run(r,a,l){const c=Op(e),h={...ac(e)},u=l+400,d=u+450;r.key(u,h,{act:!1,easing:"ease-in-out"}),r.key(d,c,{act:!1,easing:"ease-in-out"}),r.key(d+(a.for??2e3),c,{act:!1});const f=d+(a.for??2e3)+600,p={};for(const g of new Set([...Object.keys(c),...Object.keys(h)]))p[g]=0;return r.key(f,p),{end:f,contact:d,release:f-600}}},jump:{summary:"Crouches and jumps (forward to `to`, or up on the spot), legs tucked in the air, landing with a squash and dust.",uses:["to"],run(r,a,l){const c=r.exaggeration,h=e.legLength*.8*c,u=l+260,d=u+90,f=d+520;if(r.key(u,{squash:.86,"hl.knee":40,"hr.knee":40,"fl.knee":25,"fr.knee":25,neck:8},{act:!1,easing:"ease-out"}),r.key(d,{squash:1.12,"hl.knee":0,"hr.knee":0,"fl.knee":0,"fr.knee":0,pitch:8,"fl.swing":35,"fr.swing":35,"hl.swing":-35,"hr.swing":-35},{act:!1,easing:"ease-out"}),r.key((d+f)/2,{lift:h,squash:1,pitch:0,"fl.knee":60,"fr.knee":60,"hl.knee":60,"hr.knee":60,"fl.swing":25,"fr.swing":25,"hl.swing":-20,"hr.swing":-20},{act:!1,easing:"ease-out"}),r.key(f,{lift:0,squash:.85,pitch:-4,"fl.knee":0,"fr.knee":0,"hl.knee":0,"hr.knee":0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0},{act:!1,easing:"ease-in"}),r.key(f+280,{squash:1,pitch:0,neck:0}),a.to!==void 0){const p=Math.sign(a.to-r.x);p!==0&&r.facing()!==p&&r.turnTo(l,p>0?"right":"left"),r.move(d,f,a.to)}return r.effect({kind:"dust",time:f,x:r.x,y:r.floor,length:550}),{end:f+280,contact:f}}},nod:{summary:"Nods its head twice.",run(r,a,l){return r.key(l+200,{neck:20},{act:!1,easing:"ease-out"}),r.key(l+400,{neck:-5},{act:!1,easing:"ease-in-out"}),r.key(l+600,{neck:18},{act:!1,easing:"ease-in-out"}),r.key(l+900,{neck:0}),{end:l+900}}},swish:{summary:"Swishes its tail a few times.",uses:["for"],run(r,a,l){const c=a.for??900;for(let h=1;h<=4;h++)r.key(l+c*h/5,{tail:h%2===0?10:35},{act:!1,easing:"ease-in-out"});return r.key(l+c,{tail:0}),{end:l+c}}}};return t.grazes&&(o.graze={summary:"Lowers its head to graze for `for` ms (default 1800), nibbling, then looks up.",uses:["for"],run(r,a,l){const c=a.for??1800;r.key(l+600,{neck:75},{act:!1,easing:"ease-in-out"});for(let h=900;h<600+c;h+=400)r.key(l+h,{neck:h%800===100?70:78},{act:!1,easing:"ease-in-out"});return r.key(l+600+c+500,{neck:0}),{end:l+600+c+500}}}),o}function _p(t={}){return Xe({kind:t.kind??"horse",summary:t.summary??"A cartoon horse: walks, trots, canters and gallops with its hooves in step with the ground, rears, bucks, neighs, grazes and swishes its tail.",legs:{upper:.5,lower:.42,foot:.08,footSize:[.12,.16],front:.62,hind:-.62,across:.2,thickness:[.075,.09],lowerThickness:.05},body:{radii:[.32,.36,.95],rise:.25},neck:{at:[0,1.42,.7],points:[[0,0,0],[0,.5,.3]],radius:.15},head:{at:[0,.48,.5],radii:[.13,.14,.3],rotate:[38,0,0]},muzzle:{at:[0,-.02,.24],radii:[.11,.1,.1]},ears:{at:[.07,.16,-.17],radii:[.035,.1,.05]},eyes:{at:[.115,.05,-.04],size:.04},tail:{at:[0,1.4,-.9],points:[[0,0,0],[0,-.22,-.2],[0,-.62,-.24]],radius:.08},mane:{points:[[0,.1,-.12],[0,.55,.17]],radius:.07},colors:{coat:"#b5763a",dark:"#4a2e1a",foot:"#3a2a22",muzzle:"#8d5a2c",accent:"#e8c9a0",...t.colors},gaits:["walk","trot","canter","gallop"],call:"neigh",grazes:!0,anchors:{hitch:{at:[0,.95,-.15]},saddle:{at:[0,1.6,-.05]}},actions:e=>({rear:{summary:"Rears up on its hind legs, front legs tucked and pawing, neighs, and drops back down with dust.",uses:["for"],run(n,s,i){const o=n.exaggeration,r=Math.min(55,32*o),a=-e.hind*Math.sin(r*Ke),l=s.for??700;n.key(i+200,{pitch:-4,neck:6,"hl.knee":12,"hr.knee":12},{act:!1,easing:"ease-out"}),n.key(i+520,{pitch:r,lift:a,neck:-25,"fl.swing":55,"fl.knee":95,"fr.swing":40,"fr.knee":80,"hl.knee":0,"hr.knee":0},{act:!1,easing:"ease-out"}),n.key(i+520+l*.5,{"fl.swing":35,"fl.knee":70,"fr.swing":58,"fr.knee":100},{act:!1,easing:"ease-in-out"}),n.key(i+520+l,{"fl.swing":55,"fl.knee":95,"fr.swing":40,"fr.knee":80},{act:!1,easing:"ease-in-out"});const c=i+520+l+380;return n.key(c,{pitch:0,lift:0,neck:8,squash:.94,"fl.swing":0,"fl.knee":0,"fr.swing":0,"fr.knee":0},{act:!1,easing:"ease-in"}),n.key(c+320,{neck:0,squash:1}),e.call(n,i+520),n.effect({kind:"dust",time:c,x:n.x+(n.facing()||1)*e.front*n.scale,y:n.floor,length:600}),{end:c+320,contact:c}}},buck:{summary:"Bucks: drops its head and kicks both hind legs up and back.",run(n,s,i){const o=n.exaggeration,r=Math.min(35,18*o),a=e.front*Math.sin(r*Ke);return n.key(i+220,{pitch:3,squash:.95},{act:!1,easing:"ease-out"}),n.key(i+480,{pitch:-r,lift:a,neck:30,"hl.swing":-65,"hr.swing":-60,"hl.knee":10,"hr.knee":10},{act:!1,easing:"ease-out"}),n.key(i+900,{pitch:0,lift:0,neck:0,squash:.95,"hl.swing":0,"hr.swing":0,"hl.knee":0,"hr.knee":0},{act:!1,easing:"ease-in"}),n.key(i+1150,{squash:1}),n.effect({kind:"dust",time:i+900,x:n.x-(n.facing()||1)*.6*n.scale,y:n.floor,length:600}),{end:i+1150,contact:i+480}}}})})}function Cp(t={}){return Xe({kind:t.kind??"dog",summary:t.summary??"A cartoon dog: walks, trots and runs, barks, wags its tail, sits, jumps, sniffs the ground.",legs:{upper:.19,lower:.16,foot:.05,footSize:[.07,.1],front:.24,hind:-.24,across:.09,thickness:[.04,.05],lowerThickness:.032},body:{radii:[.14,.15,.36],rise:.1},neck:{at:[0,.56,.27],points:[[0,0,0],[0,.14,.06]],radius:.075},head:{at:[0,.15,.08],radii:[.12,.11,.13]},muzzle:{at:[0,-.03,.13],radii:[.065,.055,.08]},ears:{at:[.11,0,-.02],radii:[.025,.09,.05],rotate:[0,0,18]},eyes:{at:[.08,.04,.08],size:.025},tail:{at:[0,.58,-.34],points:[[0,0,0],[0,.1,-.08],[0,.2,-.1]],radius:.03},extras:e=>[{id:"nose",parent:"muzzle",shape:{type:"ellipsoid",radii:[.025,.02,.02],segments:8},at:[0,.03,.08],fill:"#1d1d22",outline:.4},{id:"patch",parent:"body",shape:{type:"ellipsoid",radii:[.012,.09,.11],segments:10},at:[.135,.04,-.06],fill:e.accent,outline:.5}],colors:{coat:"#d9a066",dark:"#a8703a",foot:"#a8703a",muzzle:"#f0d2a8",accent:"#f6ead8",...t.colors},gaits:["walk","trot","gallop"],cycleScale:.55,call:"bark",anchors:{leash:{part:"neck",at:[0,.06,0]}},actions:()=>({wag:{summary:"Wags its tail fast for `for` ms (default 1200).",uses:["for"],run(e,n,s){const i=n.for??1200;for(let o=80,r=0;o<i;o+=80,r++)e.key(s+o,{wag:r%2===0?35:-35,tail:25},{act:!1,easing:"ease-in-out"});return e.key(s+i,{wag:0,tail:0}),{end:s+i}}},sniff:{summary:"Puts its nose to the ground and sniffs (`for` ms, default 1400).",uses:["for"],run(e,n,s){const i=n.for??1400;e.key(s+350,{neck:70,pitch:-6},{act:!1,easing:"ease-in-out"});for(let o=500,r=0;o<i;o+=140,r++)e.key(s+o,{neck:r%2===0?74:66},{act:!1});return e.key(s+i+300,{neck:0,pitch:0}),{end:s+i+300}}}})})}function Hp(t={}){return Xe({kind:t.kind??"cat",summary:t.summary??"A cartoon cat: walks, trots and runs, meows, arches its back, pounces, sits and swishes its tail.",legs:{upper:.13,lower:.11,foot:.035,footSize:[.05,.07],front:.17,hind:-.18,across:.06,thickness:[.028,.035],lowerThickness:.022},body:{radii:[.1,.105,.27],rise:.07},neck:{at:[0,.39,.2],points:[[0,0,0],[0,.08,.04]],radius:.05},head:{at:[0,.1,.05],radii:[.095,.085,.085]},muzzle:{at:[0,-.03,.07],radii:[.04,.03,.03]},ears:{at:[.055,.085,-.01],radii:[.03,.055,.02],rotate:[0,0,-12]},eyes:{at:[.045,.02,.07],size:.022},tail:{at:[0,.42,-.26],points:[[0,0,0],[0,.08,-.12],[0,.24,-.16],[0,.34,-.1]],radius:.022},extras:()=>[{id:"nose",parent:"muzzle",shape:{type:"ellipsoid",radii:[.014,.01,.01],segments:8},at:[0,.015,.03],fill:"#e48a9a",outline:.4}],colors:{coat:"#8f8a86",dark:"#5f5a57",foot:"#f2efe9",muzzle:"#f2efe9",accent:"#f2efe9",...t.colors},gaits:["walk","trot","gallop"],cycleScale:.5,call:"meow",actions:e=>({arch:{summary:"Arches its back, fur up and tail high, for `for` ms (default 1200): a startled cat.",uses:["for"],run(n,s,i){const o=n.exaggeration,r=s.for??1200,a={squash:1+.25*o,neck:25,tail:-45,"fl.swing":-8,"fr.swing":-8,"hl.swing":8,"hr.swing":8};return n.key(i+180,a,{act:!1,easing:"ease-out"}),n.key(i+180+r,a,{act:!1}),n.key(i+r+520,{squash:1,neck:0,tail:0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0}),{end:i+r+520,contact:i+180}}},pounce:{summary:"Crouches low, wiggles, and pounces to `to`, landing with a squash.",needs:["to"],run(n,s,i){const o=n.exaggeration,r=Math.sign(s.to-n.x);let a=i;r!==0&&n.facing()!==r&&(a=n.turnTo(a,r>0?"right":"left"));const l={squash:.75,"hl.knee":60,"hr.knee":60,"fl.knee":45,"fr.knee":45,neck:10,tail:-15};n.key(a+300,l,{act:!1,easing:"ease-out"});for(let u=1;u<=4;u++)n.key(a+300+u*110,{roll:u%2===0?3:-3},{act:!1});const c=a+300+550,h=c+480;return n.key(c,{roll:0,squash:1.2,"hl.knee":0,"hr.knee":0,"fl.knee":0,"fr.knee":0,"fl.swing":45,"fr.swing":45,"hl.swing":-45,"hr.swing":-45,tail:20},{act:!1,easing:"ease-out"}),n.key((c+h)/2,{lift:e.legLength*.9*o,squash:1.1,pitch:-6},{act:!1,easing:"ease-out"}),n.key(h,{lift:0,squash:.8,pitch:0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0,neck:0,tail:0},{act:!1,easing:"ease-in"}),n.key(h+260,{squash:1}),n.move(c,h,s.to),n.effect({kind:"dust",time:h,x:s.to,y:n.floor,length:450}),{end:h+260,contact:h}}}})})}function Rp(t={}){return Xe({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 IS(t){return Zo(1,t)}function Lp(t={}){return Xe({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 Np(t={}){return Xe({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 Fp(t={}){return Xe({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 Ge=.6,Dp=75,cc=80;function Ue(t){const{colors:e}=t,[n,s,i]=t.body.radii,o=(t.tail.raised??15)*Math.PI/180,r=t.tail.length*.4,a=[{id:"body",shape:{type:"ellipsoid",radii:t.body.radii,segments:16},at:[0,t.body.height,0],fill:e.body},{id:"neck",shape:{type:"ellipsoid",radii:[n*.55,s*.55,i*.3],segments:10},at:[0,t.body.height+s*.45,i*.65],fill:e.body,outline:.5,solidOnly:!0},{id:"head",parent:"neck",shape:{type:"ellipsoid",radii:[t.head.radius,t.head.radius*1.02,t.head.radius*1.05],segments:14},at:[t.head.at[0],t.head.at[1]-(t.body.height+s*.45),t.head.at[2]-i*.65],fill:e.body},{id:"beak",parent:"head",shape:{type:"tube",points:[[0,0,0],[0,-t.beak.thickness*.4,t.beak.length]],radius:[t.beak.thickness,t.beak.thickness*.08],segments:8},at:[0,-t.head.radius*.1,t.head.radius*.8],fill:e.beak,outline:.8},{id:"tail",shape:{type:"ellipsoid",radii:[t.tail.width/2,.012*(i/.08),t.tail.length/2],segments:10},at:[t.tail.at[0],t.tail.at[1]+r*Math.sin(o),t.tail.at[2]-r*Math.cos(o)],rotate:[t.tail.raised??15,0,0],fill:e.wing,outline:.8}];if(e.belly&&a.push({id:"belly",parent:"body",shape:{type:"ellipsoid",radii:[n*.82,s*.7,i*.75],segments:12},at:[0,-s*.25,i*.12],fill:e.belly,outline:.4}),t.comb){const h=t.head.radius;a.push({id:"comb",parent:"head",shape:{type:"extrude",profile:[[-h*.5,h*.6],[h*.6,h*.6],[h*.5,h*1.3],[h*.15,h*1.05],[-h*.05,h*1.4],[-h*.3,h*1.05],[-h*.6,h*1.25]],width:h*.25},fill:e.comb??"#d9372e",outline:.7},{id:"wattle",parent:"head",shape:{type:"ellipsoid",radii:[h*.15,h*.35,h*.2],segments:8},at:[0,-h*.7,h*.6],fill:e.comb??"#d9372e",outline:.6})}for(const h of[1,-1]){const u=h>0?"left":"right",d=t.head.radius;a.push({id:`eye-${u}`,parent:"head",shape:{type:"ellipsoid",radii:[d*.16,d*.2,d*.18],segments:8},at:[h*d*.72,d*.18,d*.42],fill:"#1d1d22",outline:.3}),a.push({id:`wing-${u}`,shape:{type:"ellipsoid",radii:[.004,.004,.004],segments:4},at:[h*t.wing.shoulder[0],t.wing.shoulder[1],t.wing.shoulder[2]],rotate:[-8,h*90,0],outline:0}),a.push({id:`wing-${u}-blade`,parent:`wing-${u}`,shape:{type:"ellipsoid",radii:[t.wing.span*Ge/2,t.wing.chord*.1,t.wing.chord/2],segments:12},at:[h*t.wing.span*Ge/2,0,-t.wing.chord*.1],rotate:[-cc,0,0],fill:e.wing,outline:.8}),a.push({id:`wing-${u}-tip`,parent:`wing-${u}-blade`,shape:{type:"ellipsoid",radii:[t.wing.span*Ge/2.4,t.wing.chord*.06,t.wing.chord*.3],segments:10},at:[h*t.wing.span*Ge/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-Ge)/2,0,0],rotate:{axis:"x",degrees:cc},scale:[1/Ge,1,1]},{parts:["wing-right-blade"],translate:[-t.wing.span*(1-Ge)/2,0,0],rotate:{axis:"x",degrees:cc},scale:[1/Ge,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)/Dp,0]}]},step:{description:"Phase of a walk, in steps (a chicken’s legs)",unit:"steps"},stepping:{description:"How much of the walk is applied",unit:"0..1",min:0,max:1},"leg.left":{description:"Left leg swung forward (+)",unit:"degrees",bind:[{parts:["leg-left"],rotate:{axis:"x",degrees:-1}}]},"leg.right":{description:"Right leg swung forward (+)",unit:"degrees",bind:[{parts:["leg-right"],rotate:{axis:"x",degrees:-1}}]},grip:{description:"The toes curled down round a perch: 0 flat on the ground, 1 gripping",unit:"0..1",min:0,max:1,bind:[{parts:["toes-left","toes-right"],rotate:{axis:"x",degrees:55}}]}},c={parts:a,controls:l,length:i*2+t.tail.length+t.beak.length,height:t.head.at[1]+t.head.radius,footprint:[n*2.2,i*2.4],anchors:{beak:{part:"beak",at:[0,0,t.beak.length]},head:{part:"head",at:[0,0,0]},back:{at:[0,t.body.height+s,0]},feet:{at:[0,0,0]}},derive:h=>{const u={},d=Math.max(0,Math.min(1,h.flapping??0));d>0&&(u.flap=(h.flap??0)+d*48*Math.sin(Math.PI*2*(h.wingbeat??0)));const f=Math.max(0,Math.min(1,h.stepping??0));if(f>0){const p=Math.sin(Math.PI*2*(h.step??0));u["leg.left"]=(h["leg.left"]??0)+f*28*p,u["leg.right"]=(h["leg.right"]??0)-f*28*p,u.peck=(h.peck??0)+f*12*Math.sin(Math.PI*4*(h.step??0))}return u}};return{kind:t.kind,family:"bird",summary:t.summary,rig:c,actions:_S(t),acting:Wp,colors:{body:e.body,ink:"#26262b"},moves:OS(t)}}function OS(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 Wp={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 _S(t){const e=(t.beatsPerSecond??4)/1e3,n=(r,a,l)=>{const c=r.values.wingbeat??0;r.set("wingbeat",a,c),r.set("wingbeat",l,c+(l-a)*e)},s=(r,a,l)=>{const c=Math.sign(l-r.x);return c!==0&&r.facing()!==c?r.turnTo(a,c>0?"right":"left"):a},i=(r,a)=>{const l=r.anchor("beak");r.effect({kind:"honk",time:a,x:l.x,y:l.y,length:600,direction:r.facing()||1})},o={hop:{summary:"Hops to `to` in little bounces, wings twitching.",needs:["to"],run(r,a,l){const c=s(r,l,a.to),h=r.x,u=Math.abs(a.to-h),d=Math.max(1,Math.round(u/(t.body.radii[2]*3*r.scale))),f=260;for(let p=0;p<d;p++){const g=c+p*f;r.key(g+60,{squash:.85},{act:!1,easing:"ease-out"}),r.key(g+150,{squash:1.1,lift:t.legs.length*1.4,spread:.15},{act:!1,easing:"ease-out"}),r.key(g+f,{squash:.9,lift:0,spread:0},{act:!1,easing:"ease-in"}),r.move(g+60,g+f,h+(a.to-h)*(p+1)/d,{easing:"ease-in-out"})}return r.key(c+d*f+120,{squash:1}),{end:c+d*f+120}}},walk:{summary:"Walks to `to` on its two legs, its head bobbing with each step.",needs:["to"],uses:["for"],run(r,a,l){const c=s(r,l,a.to),h=Math.abs(a.to-r.x)/r.scale,u=t.legs.length*1.2,d=h/u,f=a.for??Math.max(400,d*420),p=r.values.step??0;return r.set("stepping",c,0),r.set("stepping",c+150,1,"ease-out"),r.set("stepping",c+f-150,1),r.set("stepping",c+f,0,"ease-in"),r.set("step",c,p),r.move(c,c+f,a.to,{easing:"ease-in-out"}),r.set("step",c+f,p+d/2,"ease-in-out"),{end:c+f,contact:c,release:c+f}}},peck:{summary:"Pecks at the ground (`for` ms, default 900): quick jabs of the head.",uses:["for"],run(r,a,l){const c=a.for??900,h=Math.max(1,Math.round(c/300));r.key(l+120,{pitch:-(t.stoop??12)},{act:!1,easing:"ease-out"});for(let u=0;u<h;u++)r.key(l+120+u*300+90,{peck:Dp},{act:!1,easing:"ease-in"}),r.key(l+120+u*300+260,{peck:20},{act:!1,easing:"ease-out"});return r.key(l+120+h*300+200,{peck:0,pitch:0}),{end:l+120+h*300+200,contact:l+210}}},flap:{summary:"Flaps its wings on the spot (`for` ms, default 900), lifting a little.",uses:["for"],run(r,a,l){const c=a.for??900;return r.key(l+120,{spread:1},{act:!1,easing:"ease-out"}),r.set("flapping",l,0),r.set("flapping",l+150,1,"ease-out"),r.set("flapping",l+c-150,1),r.set("flapping",l+c,0,"ease-in"),n(r,l,l+c),r.key(l+c*.5,{lift:t.legs.length*.6},{act:!1,easing:"ease-out"}),r.key(l+c,{lift:0,spread:0},{act:!1,easing:"ease-in"}),{end:l+c+80}}},[t.call]:{summary:`${t.call[0].toUpperCase()}${t.call.slice(1)}s: its head comes up and its beak opens to call.`,run(r,a,l){return r.key(l+120,{peck:-25,squash:1.06},{act:!1,easing:"ease-out"}),r.key(l+500,{peck:-20},{act:!1}),r.key(l+760,{peck:0,squash:1}),i(r,l+150),{end:l+760,contact:l+150}}}};return t.flies!==!1?(o.fly={summary:"Takes off (a crouch and a leap, wings beating) and flies to `to` at `height` metres (default 2); `land` brings it down.",needs:["to"],uses:["height","for"],run(r,a,l){const c=r.exaggeration;r.key(l+60,{grip:0},{act:!1});const h=s(r,l,a.to),u=a.height??2,d=a.for??Math.max(700,Math.abs(a.to-r.x)/.35),f=r.values.lift>t.legs.length,p=f?h:h+200;return f||(r.key(h+160,{squash:1-.18*c,spread:.6},{act:!1,easing:"ease-out"}),r.effect({kind:"dust",time:p,x:r.x,y:r.floor,length:400})),r.key(p+100,{spread:1,squash:1.08,pitch:10},{act:!1,easing:"ease-out"}),r.set("flapping",p,r.values.flapping??0),r.set("flapping",p+100,1,"ease-out"),r.set("flapping",p+d,.6),n(r,p,p+d),r.key(p+d*.4,{lift:u,pitch:-5,squash:1},{act:!1,easing:"ease-out"}),r.key(p+d,{lift:u,pitch:0},{act:!1,easing:"ease-in-out"}),r.move(p,p+d,a.to,{easing:"ease-in-out"}),{end:p+d,contact:p,release:p+d}}},o.glide={summary:"Glides to `to` on still, spread wings, sinking gently to `height` metres (default: a third lower than it is); from the ground it takes off first, flying the first stretch.",needs:["to"],uses:["height","for"],run(r,a,l){let c=l;if(r.values.lift<=t.legs.length){const f=r.x+(a.to-r.x)/3;c=o.fly.run(r,{do:"fly",to:f,height:(a.height??1.5)*1.3},l).end}c=s(r,c,a.to);const h=r.values.lift,u=a.height??h*.67,d=a.for??Math.max(900,Math.abs(a.to-r.x)/.3);return r.set("flapping",c,r.values.flapping??1),r.set("flapping",c+250,0,"ease-out"),n(r,c,c+250),r.key(c+300,{spread:1,flap:10,pitch:-6},{act:!1,easing:"ease-out"}),r.key(c+d,{lift:u,pitch:-3,flap:10},{act:!1,easing:"ease-in-out"}),r.move(c,c+d,a.to,{easing:"ease-in-out"}),{end:c+d,contact:c,release:c+d}}},o.land={summary:"Comes down to the floor it is over (or to `height` metres above it, a branch or a roof): wings braking, a squash on touchdown.",uses:["height","to"],run(r,a,l){const h=a.height??0;return r.set("flapping",l,r.values.flapping??1),r.set("flapping",l+700-120,1),r.set("flapping",l+700,0,"ease-in"),n(r,l,l+700),r.key(l+700*.6,{pitch:14},{act:!1,easing:"ease-out"}),r.key(l+700,{lift:h,pitch:0,squash:.85,grip:h>0?1:0},{act:!1,easing:"ease-in"}),a.to!==void 0&&r.move(l,l+700,a.to,{easing:"ease-out"}),r.key(l+700+160,{squash:1,spread:0,flap:0}),{end:l+700+200,contact:l+700}}}):o.flutter={summary:"Flutters up a little way and back down, wings beating hard (a chicken’s flight).",run(r,a,l){return r.key(l+100,{spread:1,squash:.9},{act:!1,easing:"ease-out"}),r.set("flapping",l+80,0),r.set("flapping",l+160,1,"ease-out"),r.set("flapping",l+900-100,1),r.set("flapping",l+900,0,"ease-in"),n(r,l+80,l+900),r.key(l+900*.5,{lift:t.legs.length*2.5,squash:1.08},{act:!1,easing:"ease-out"}),r.key(l+900,{lift:0,squash:.85,spread:0},{act:!1,easing:"ease-in"}),r.key(l+900+160,{squash:1}),{end:l+900+160,contact:l+900}}},o}function Bp(t={}){return Ue({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 zp(t={}){return Ue({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 qp(t={}){return Ue({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 Yp(t={}){return Ue({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 jp(t={}){return Ue({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 Kp(t={}){return Ue({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 Xp(t={}){return Ue({kind:"parrot",summary:"A parrot: bright, with a big hooked beak and a long tail; squawks, bobs, flies and lands on a perch, gripping it.",body:{radii:[.07,.08,.13],height:.15},head:{at:[0,.29,.1],radius:.055},beak:{length:.045,thickness:.03},wing:{shoulder:[.06,.2,.05],span:.26,chord:.11},tail:{at:[0,.12,-.12],length:.22,width:.06,raised:-20},legs:{length:.06,across:.03},colors:{body:"#4caf50",wing:"#2e7d32",beak:"#5a5a66",legs:"#8d8d8d",belly:"#a5d66f",comb:"#d9372e",...t.colors},call:"squawk",beatsPerSecond:6,stoop:10})}const as={car:ip,truck:op,bus:rp,tractor:ap,cart:lp,trainCar:cp,bike:hp,motorbike:up,tree:dp,house:gp,chair:mp,desk:bp,bed:kp,door:Mp,wheelchair:xp,helicopter:Pp,airplane:$p,horse:_p,dog:Cp,cat:Hp,cow:Rp,goat:Lp,rabbit:Np,squirrel:Fp,songbird:Bp,crow:zp,chicken:qp,pigeon:Yp,duck:jp,owl:Kp,parrot:Xp};function hc(t,e={}){const n=as[t];if(!n)throw new Error(dt("prop preset",t,Object.keys(as)));return n(e)}const Qo=["do","at","for","to","toward","speed","open","on","height","wind"],uc={viewer:0,right:1,away:2,left:3},CS=420,dc={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 tr(t){return{...dc,...t.actions}}const fc=t=>typeof t=="number"&&Number.isFinite(t);function Gp(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=tr(e),s=Object.keys(n),i=[];return t.forEach((o,r)=>{const a=c=>i.push({level:"error",beat:r,message:c});if(!o||typeof o!="object"||Array.isArray(o))return a(`Each beat must be an object like { do: '${s[s.length-1]}' }.`);const l=o;for(const c of Object.keys(l))Qo.includes(c)||a(dt("beat field",c,Qo,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&&!(fc(l[c])&&l[c]>=0)&&a(`\`${c}\` must be a number ≥ 0 (got ${JSON.stringify(l[c])}).`);if(l.to!==void 0&&!fc(l.to)&&a(`\`to\` is a scene x in px (got ${JSON.stringify(l.to)}).`),l.toward!==void 0&&!fc(l.toward)&&!(typeof l.toward=="string"&&l.toward in uc)){const c=typeof l.toward=="string"?ks(l.toward,Object.keys(uc)):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 Up(t,e,n,s={}){const i=Gp(n,e).filter(M=>M.level==="error");if(i.length>0)throw new Error(`propScript (${e.kind}): ${i.length} problem(s) in the beats:
|
|
61
|
-
${i.map(
|
|
62
|
-
`)}`);const o=s.from??0,r=s.ground??0,a=s.scale??60,l=s.exaggeration??1,c=tr(e),h={};for(const M of[...Object.keys(ss),...Object.keys(e.rig.controls)])h[M]=s.start?.[M]??At(e.rig,{},M);const u=[{time:0,pose:{...h}}],d=new Map,f=[];let p=o,g=r;const m=(M,T,I,A)=>{const _=d.get(M)??[{time:0,value:M==="x"||M==="y"?0:h[M]}];_.push({time:T,value:I,...A?{easing:A}:{}}),d.set(M,_),M!=="x"&&M!=="y"&&(h[M]=I)},w=(M,T)=>{const I=M==="x"?p-o:M==="y"?g-r:h[M],A=d.get(M);(!A||A[A.length-1].time<T)&&m(M,T,I)},v={prop:e,scale:a,exaggeration:l,get x(){return p},get floor(){return g},values:h,facing(){const M=Math.sin(h.turn*Math.PI/2);return Math.abs(M)<.5?0:M>0?1:-1},key(M,T,I={}){Object.assign(h,T),u.push({time:M,pose:{...h},...I.act===!1?{act:!1}:{},...I.easing?{easing:I.easing}:{}})},move(M,T,I,A={}){w("x",M),m("x",T,I-o,A.easing),p=I,A.floor!==void 0&&(w("y",M),m("y",T,A.floor-r,A.easing),g=A.floor)},set(M,T,I,A){m(M,T,I,A)},turnTo(M,T){const I=typeof T=="number"?T:uc[T],A=h.turn,C=[I-4,I,I+4].map(B=>({t:B,d:Math.abs(B-A)})).sort((B,G)=>B.d-G.d||Math.abs(B.t)-Math.abs(G.t))[0];if(C.d<.001)return M;const N=M+CS*Math.max(1,C.d);return v.key(N,{turn:C.t}),N},effect(M){f.push(M)},anchor(M){const I=is(e,h,a).anchors[M];if(!I)throw new Error(`${e.kind}: no anchor "${M}"`);return{x:p+I.point.x,y:g+I.point.y}}},k=[];let b=0;for(const M of n){const T=Math.max(M.at??b,u[u.length-1].time),I=c[M.do].run(v,M,T);I.end>u[u.length-1].time&&u.push({time:I.end,pose:{...h}}),k.push({start:T,end:I.end,...I.contact!==void 0?{contact:I.contact}:{},...I.release!==void 0?{release:I.release}:{}}),b=I.end}const E=_l(s.style??"snappy"),$={...E,anticipation:E.anticipation*l,overshoot:E.overshoot*l},S=Do(NS(u),e.acting,{style:$}),x=[...Object.entries(S).filter(([M])=>!d.has(M)).map(([M,T])=>({id:`${t}-${M}`,target:t,property:M,keyframes:T})),...[...d].map(([M,T])=>({id:`${t}-${M}`,target:t,property:M,keyframes:FS(T)}))];for(const M of RS(t,e,x,b,u[0].pose)){const T=x.findIndex(_=>_.property===M.property);if(T<0){x.push(M);continue}const I=new It({id:`${t}-own`,tracks:[x[T]]}),A=_=>Number(I.getStateAtTime(_).values.get(t)?.get(M.property)??0);x[T]={...M,keyframes:M.keyframes.map(_=>({time:_.time,value:Number(_.value)+A(_.time)}))}}return{tracks:x,duration:b,beats:k,effects:f}}const HS=1500;function RS(t,e,n,s,i){if(!e.follow?.length)return[];const o=new It({id:`${t}-follow`,tracks:n.filter(a=>a.property==="turn"||e.follow.some(l=>l.of===a.property))}),r=(a,l)=>{const c=o.getStateAtTime(a).values.get(t)?.get(l);return typeof c=="number"?c:i[l]??0};return e.follow.map(a=>{const l=s+HS,c=vs(d=>r(d,a.of),{start:0,end:l,stiffness:a.stiffness,damping:a.damping}),h=a.limit??1/0,u=c.map(({time:d,value:f})=>{const p=Math.sin(r(d,"turn")*Math.PI/2),g=(f-r(d,a.of))*p;return{time:d,value:Math.max(-h,Math.min(h,g*a.per))}});return{id:`${t}-${a.control}`,target:t,property:a.control,keyframes:u}})}const LS=20;function NS(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<LS?n[n.length-1]={...s,time:i.time}:n.push(s)}return n}function FS(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 DS={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 Vp(t,e={}){const n={};for(const s of Object.keys(Wt))n[s]={summary:`Walks to \`to\` in the ${s} gait.`,needs:["to"]};for(const s of Object.keys(Vt))n[s]={summary:`Moves into the ${s} pose and holds it (\`for\` ms).`};for(const s of Object.keys(Ye))n[s]={summary:`The ${s} gag (${Qs(s)} ms).`};for(const[s,i]of Object.entries(ti))n[s]={...i};return{...t?{version:t}:{},timing:"JSON timelines and tracks are in milliseconds; the GSAP-style API (live.to, tf.timeline) takes seconds. Scene x grows right, y grows down, in px.",easings:{named:Object.keys(DS),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:Ko,stickFigure:{poseFields:q0,props:Y0,handFields:j0,poses:Object.keys(Vt),expressions:Object.keys(vt),gags:Object.fromEntries(Object.keys(Ye).map(s=>[s,Qs(s)])),gaits:Object.keys(Wt),actingStyles:Object.keys(yn),beatFields:Wo,actions:n,dances:Object.fromEntries(Object.entries(Ne).map(([s,i])=>[s,Object.keys(i.moves)])),flips:Object.fromEntries(Object.entries(qs).map(([s,i])=>[s,i.label])),handShapes:Object.keys(Ct),mudras:Object.keys(ji)},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:Qo,commonControls:Object.fromEntries(Object.entries(ss).map(([s,i])=>[s,`${i.description}${i.unit?` (${i.unit})`:""}`])),commonActions:Object.fromEntries(Object.entries(dc).map(([s,i])=>[s,i.summary])),presets:Object.fromEntries(Object.entries(as).map(([s,i])=>{const o=i();return[s,{family:o.family,summary:o.summary,actions:Object.fromEntries(Object.entries(o.actions).map(([r,a])=>[r,{summary:a.summary,...a.needs?{needs:a.needs}:{}}])),controls:Object.keys(o.rig.controls),anchors:Object.keys(o.rig.anchors??{})}]}))},custom:{api:{"defineAction({ summary, needs?, steps: (from, beat) => [{ after, pose, easing? }] })":"a new action written as timed pose steps from the current pose, like a gag","defineAction({ summary, needs?, beats: (beat) => [beats] })":"a new action built from other beats (which may be custom too)","defineGait({ swing, knee, arm, elbow, lean, cycle?, … })":"a new gait (the Gait fields in degrees; cycle is ms per two steps)","scriptTracks(id, beats, { actions, gaits })":"beats may then use those names; checkBeats(beats, { actions, gaits }) knows them","stickFigureTarget({ …, cast: { actions, gaits } })":"a figure that draws the gaits and lists the actions in describeTarget","persona({ name, summary?, height?, look?, acting?, gait?, mood?, stance?, energy?, actions?, gaits? })":"a character’s look, acting style and habits: .figure({ x, y }), .script(id, beats, { from, ground }), .check(beats), .handPath(…), .describe(); `go` walks in its gait, `stand` returns to its stance and face"},actions:Object.fromEntries(Object.entries(e.actions??{}).map(([s,i])=>[s,{summary:i.summary,...i.needs?{needs:i.needs}:{}}])),gaits:Object.fromEntries(Object.entries(e.gaits??{}).map(([s,i])=>[s,i.summary??"custom gait"]))},character:{poses:Object.keys(le),dances:Object.keys(ln),expressions:Object.keys(Sa),faceStyles:["simple","anime"],faceShapes:["round","angular"],gags:Object.keys(go),builds:Object.keys(Ji),hair:Object.keys(La),hairColors:{...me},facialHair:Object.keys(Wa),glasses:Object.keys(za),hats:Object.keys(fo),feet:[...Wu],cast:Object.keys(Il),heldItems:Object.fromEntries(Object.entries(Xa).map(([s,i])=>[s,i.hands])),handMeetings:Object.keys(Zs)},codePanel:{languages:Lo,removeStyles:Ho,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:Tl},surfaces:{code:Us,board:Me,chart:pn,prop:os},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: ${es.join(", ")} (default contact, or start when the beat has none); not ms`,until:"a moment of this beat, or { beat: index, at? } of a later one; sets the edit’s duration (carry needs it)"},cameraShots:{frame:"{ at, duration?, easing?, frame: { focus?: { x, y }, scale?, rotate? } }: push in, pull out, or cut (duration 0)",shake:"{ at, duration, shake: { strength?, frequency?, roll?, seed? } }",follow:"{ at, until, follow: { x: <the subject’s x keyframes>, lead?, y?, lag?, scale? } }: keeps a subject centred"},teach:{"lesson({ id })":"steps as timeline JSON: to, set, together, wait, marker (with pause, question, captions)","cells, pointer, stack, queue, table, pipeline":"diagram primitives (SVG markup + step helpers)","figure({ width, height, children })":"the SVG holding the pieces"},cli:{"tinyfly capabilities [--json]":"this catalog","tinyfly check <beats.json>":"check a beat script (names, fields) with suggestions","tinyfly validate <timeline.json> [--markup file]":"check a timeline against its markup","tinyfly render <timeline.json> <markup> [--at …]":"a frame as static markup","tinyfly video <scene.mjs> [--stills dir --times …]":"MP4, or PNG stills to look at"}}}const wt=t=>t.map(e=>`\`${e}\``).join(", "),Jp=t=>Object.entries(t).map(([e,n])=>`| \`${e}\` | ${n.unit??n.kind??""} | ${n.description} |`).join(`
|
|
63
|
-
`);function WS(t,e={}){const n=Vp(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: ${wt(n.easings.named)}.`,"",...Object.entries(n.easings.parametric).map(([o,r])=>`- ${o}: \`${r}\``),"","## Track kinds","",...Object.entries(n.trackKinds).map(([o,r])=>`- **${o}**: ${r}`),"","## Canvas targets","","Types: `rect`, `circle`, `text`, `line`, `path`, `image`, `custom`. `describeTarget(target)` lists what one can animate with its values; `checkTracks(tracks, targets)` checks tracks before playing them.","","| Property | Unit | What it does | Types |","|---|---|---|---|",...Object.entries(n.canvasProperties).map(([o,r])=>`| \`${o}\` | ${r.unit??r.kind??""} | ${r.description} | ${r.types.length===7?"all":r.types.join(", ")} |`),"","## Stick figure (`@algorisys/tinyfly/characters`)","","`stickFigureTarget({ x, y, style })` is a custom canvas target; its props are the pose fields and the props below. Pose it with tracks (`poseTracks`), or write beats (`scriptTracks`).","","Style proportions: `headSize` is a fraction of height; `armLength` multiplies both upper arm and forearm lengths (default 1, positive finite). Hands, shoulders, torso and legs retain their sizes.","","### Pose fields","","| Field | Unit | What it does |","|---|---|---|",Jp(s.poseFields),"","### Other props","","| Prop | Unit | What it does |","|---|---|---|",Jp(s.props),"",`With \`style.hands\`, each hand has \`hand.left.<field>\` / \`hand.right.<field>\` props: ${wt(Object.keys(s.handFields))}.`,"",`**Poses** (a beat's \`do\`, or a pose key): ${wt(s.poses)}.`,"",`**Expressions** (a beat's \`mood\`): ${wt(s.expressions)}.`,"",`**Gags** (ms): ${Object.entries(s.gags).map(([o,r])=>`\`${o}\` (${r})`).join(", ")}.`,"",`**Gaits**: ${wt(s.gaits)}. **Acting styles** (\`style\`): ${wt(s.actingStyles)}.`,"","### Beat scripts","",`\`scriptTracks(target, beats, { from, ground, height, facing, style })\`. A beat has these fields only: ${wt(s.beatFields)}. Times are ms; \`to\` and \`target\` are scene px; \`onto\` is a floor's scene y.`,"","`characterScript(target, who, beats, options)` compiles the same beats for a v2 `character()` on a `characterTarget` (every option but `height`; the same result, its key poses on the human body; the walk phase keyed to that character's stride, and `walk` / `walking` / `gait` tracks that step the gait as the target draws). Add `hairFollowTracks(target, tracks, who)` after it so hanging hair swings.","","| `do` | Needs | What happens |","|---|---|---|",...Object.entries(s.actions).map(([o,r])=>`| \`${o}\` | ${(r.needs??[]).map(a=>`\`${a}\``).join(", ")} | ${r.summary} |`),"","Beats that touch something report `contact` (and `release`) times in `result.beats[i]`; key the thing they touch to those.","",`**Dances** (\`dancer(style, { move })\`): ${Object.entries(s.dances).map(([o,r])=>`\`${o}\` (${r.join(", ")})`).join("; ")}.`,"",`**Flips**: ${Object.entries(s.flips).map(([o,r])=>`\`${o}\` (${r})`).join(", ")}.`,"",`**Hand shapes**: ${wt(s.handShapes)}. **Mudras**: ${wt(s.mudras)}.`,"","### Your own actions, gaits and personas","","Nothing is registered globally: pass your definitions where they are used.","",...Object.entries(n.custom.api).map(([o,r])=>`- \`${o}\`: ${r}`),"",...Object.keys(n.custom.actions).length||Object.keys(n.custom.gaits).length?["**This cast’s own:**","",...Object.entries(n.custom.actions).map(([o,r])=>`- \`${o}\`${r.needs?.length?` (needs ${r.needs.map(a=>`\`${a}\``).join(", ")})`:""}: ${r.summary}`),...Object.entries(n.custom.gaits).map(([o,r])=>`- \`${o}\` (gait): ${r}`),""]:[],"## Props (everyday objects with behaviours)","","A prop is a 3D rig of simple parts drawn with the characters’ pens (clean, pencil, silhouette), so it turns toward the camera (`turn`), and its beats go through the same acting pass (anticipation, overshoot, overlap; `exaggeration` scales them).","",...Object.entries(n.props.api).map(([o,r])=>`- \`${o}\`: ${r}`),"",`Prop beat fields: ${wt(n.props.beatFields)}. Every prop has the controls ${Object.keys(n.props.commonControls).map(o=>`\`${o}\``).join(", ")} and the actions ${Object.keys(n.props.commonActions).map(o=>`\`${o}\``).join(", ")}.`,"","Scenery: `scenery({ x, y, width, height, kind: sky | room, hour, clouds, wind, rain, snow, horizon: hills | city | flat })` is a canvas target whose values `hour` (0–24), `clouds`, `rain`, `snow` (0–1) and `wind` (−1..1) are tracks (`set(prop, { at, value, duration })`, `tracks(id)`; `anchor('sun' | 'moon' | 'horizon' | 'ground', time)`); the same `wind` streams hair (`hairFollowTracks(…, { wind })`). `scenePreset('park' | 'street' | 'office' | 'home', { width, height })` lays out scenery and props as data; `buildScene` builds them into targets.","","| Preset | Family | Actions (needs) | Controls | Anchors |","|---|---|---|---|---|",...Object.entries(n.props.presets).map(([o,r])=>`| \`${o}()\` | ${r.family} | ${Object.entries(r.actions).map(([a,l])=>`\`${a}\`${l.needs?.length?` (${l.needs.join(", ")})`:""}`).join(", ")} | ${r.controls.map(a=>`\`${a}\``).join(", ")} | ${r.anchors.join(", ")} |`),"","## Character (v2 human)","",`Poses: ${wt(n.character.poses)}. Expressions: ${wt(n.character.expressions)}. Gags: ${wt(n.character.gags)}.`,`Native dances: ${wt(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\`: ${wt(n.character.builds)}`,`- \`hair\`: ${wt(n.character.hair)} (colours: ${wt(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\`: ${wt(n.character.facialHair)}`,`- \`glasses\`: ${wt(n.character.glasses)}; \`hat\`: ${wt(n.character.hats)}; \`ears: true\`; \`face: { teeth, tongue }\` (shown when the mouth opens); \`feet\`: ${wt(n.character.feet)}`,"- `outfit`: `{ shirt, trousers, 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)\`: ${wt(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: ${wt(n.character.faceStyles)}; \`face: { style: 'anime', iris: '#4b7fce', lashes: true, ageLines: 0.8 }\` uses coloured eyes and the same expressions, blinks and gaze. \`ANIME_CAST\` contains eight age presets, also available through \`castMember\`.`,`- Face shapes: ${wt(n.character.faceShapes)}; \`face: { shape: 'angular', jawWidth: 0.74, chinWidth: 0.14, eyeScale: 0.8, eyeAspect: 0.65 }\` sets a tapered 3D jaw and narrower anime eyes; \`jawRoundness: 1\` softens the cheek/chin corners (default 0 keeps sharp jaws). \`MANGA_CAST\` contains four original young adult presets; hair styles \`mangaSpikes\` and \`mangaSweep\` remain editable.`,"- Hair in motion (pose fields): `hair.swing` (degrees round the head, + toward its left), `hair.trail` (head radii back), `hair.lift` (head radii up); key them with `hairFollowTracks(target, tracks, who)` after the character's tracks, or `hairFollow` + `hairMotionAt` when posing per frame",`- \`holding\`: ${Object.entries(n.character.heldItems).map(([o,r])=>`\`${o}\` (${r==="both"?"both":r==="either"?"one hand or both":"left or right"})`).join(", ")}; pose fields \`held.left\`, \`held.right\`, \`held.both\` (below 0.5 lets go); \`handGrip(joints, side)\``,`- \`meetHands(kind, a, b)\` (stand them \`meetingSpacing(kind, a, b)\` apart): ${wt(n.character.handMeetings)}; \`embrace(a, b)\` (a hug, \`embraceSpacing\` apart); \`helpUp(helper, sitter, progress)\` (0 on the floor, hand taken; 1 standing; \`helpUpSpacing\` apart)`,"- Everyday cycles like a gait: `humanCyclePose('sweeping' | 'brushing', phase, base)` (0 → 1 is one stroke and back; sweeping with `holding: { right: 'broom' }`)","","## Code panel","",`\`codePanel({ code, language, x, y, fontSize?, lineHeight?, width? })\`: a code listing as a scene object. Languages: ${wt(n.codePanel.languages)}. Remove styles: ${wt(n.codePanel.removeStyles)}.`,"",...Object.entries(n.codePanel.anchors).map(([o,r])=>`- \`${o}\`: ${r}`),"",...Object.values(n.codePanel.edits).map(o=>`- \`${o.split(":")[0]}\`:${o.split(":").slice(1).join(":")}`),"","## Surfaces","","Scene objects figures act on. Places are named `kind:args`: `surface.anchor(name)` gives the box there (stand on `top`, point at `x`, `y`; pass it as a beat `target`), `surface.piece(name)` makes the part there come loose, and `surface.edit(name, anchor, options)` changes the surface at a time (`at`, ms).","","Beats name places and say what surfaces do in answer (`surfaceScript`):","",...Object.entries(n.surfaceScript).map(([o,r])=>`- \`${o}\`: ${r}`),"",...Object.entries(n.surfaces).flatMap(([o,r])=>[`### ${o}`,"",...r.create?[`\`${r.create}\``,""]:[],"Anchors:",...Object.entries(r.anchors).map(([a,l])=>`- \`${a}\`: ${l}`),"","Edits:",...Object.entries(r.edits).map(([a,l])=>`- \`${a}\`: ${l}`),""]),"## Camera shots (`cameraTracks(shots, { stage })`)","",...Object.entries(n.cameraShots).map(([o,r])=>`- **${o}**: \`${r}\``),"","## Teaching (`@algorisys/tinyfly/teach`)","",...Object.entries(n.teach).map(([o,r])=>`- \`${o}\`: ${r}`),"","## Command line","",...Object.entries(n.cli).map(([o,r])=>`- \`${o}\`: ${r}`),""].join(`
|
|
64
|
-
`)}function BS(t,e,n,s={}){const i=s.color??"#555",o=s.size??60;for(const r of e){const a=(n-r.time)/r.length;if(a<=0||a>=1)continue;const l=Kt(`${r.kind}:${r.time}:${r.x}`);r.kind==="dust"?fg(t,{x:r.x,y:r.y},a,{size:o,color:i,seed:l}):r.kind==="exhaust"?YS(t,r,a,o,i,l):r.kind==="skid"?jS(t,r,a,n,i):r.kind==="honk"?KS(t,r,a,o,i):r.kind==="smoke"?zS(t,r,n,o,i):r.kind==="leaves"&&qS(t,r,a,o,s.leafColor??"#5cae5a",i,l)}}function zS(t,e,n,s,i,o){const r=e.direction??1,a=380,l=1500;t.save(),t.strokeStyle=i,t.lineWidth=Math.max(1,s*.025);for(let c=e.time;c<=e.time+e.length-l;c+=a){const h=(n-c)/l;if(h<=0||h>=1)continue;const u=Math.sin(c/97+h*4)*s*.06,d=e.x+r*h*s*.7+u,f=e.y-h*s*1.6;t.globalAlpha=Math.min(1,h*6)*(1-h)*.85,t.beginPath(),t.arc(d,f,s*(.07+h*.2),0,Math.PI*2),t.stroke()}t.restore()}function qS(t,e,n,s,i,o,r){const a=e.direction??1,l=e.toY??e.y+s*3;t.save(),t.lineWidth=Math.max(1,s*.02),t.strokeStyle=o,t.fillStyle=i;for(let c=0;c<4;c++){const h=Kt(`${r}:${c}`)%1e3/1e3,u=Math.min(1,n*(1.1+h*.4)),d=e.x+(h-.5)*s*1.2,f=e.y+(h-.3)*s*.4,p=u*u*.4+u*.6,g=d+a*u*s*(.6+h)+Math.sin(u*9+h*6)*s*.18,m=Math.min(l-2,f+(l-f)*p);t.globalAlpha=n>.85?(1-n)/.15:1,t.save(),t.translate(g,m),t.rotate(Math.sin(u*7+h*5)*1.2),t.beginPath(),t.ellipse(0,0,s*.07,s*.035,0,0,Math.PI*2),t.fill(),t.stroke(),t.restore()}t.restore()}function YS(t,e,n,s,i,o){const r=e.direction??-1;t.save(),t.strokeStyle=i,t.lineWidth=Math.max(1,s*.025);for(let a=0;a<3;a++){const l=n*1.6-a*.25;if(l<=0||l>=1)continue;const c=(Kt(`${o}:${a}`)%100/100-.5)*s*.1,h=e.x+r*l*s*.9,u=e.y-l*s*.45+c;t.globalAlpha=(1-l)*.9,t.beginPath(),t.arc(h,u,s*(.06+l*.14),0,Math.PI*2),t.stroke()}t.restore()}function jS(t,e,n,s,i){const o=e.toX??e.x,r=Math.min(1,(s-e.time)/e.length*3),a=e.x+(o-e.x)*r;t.save(),t.strokeStyle=i,t.lineCap="round",t.globalAlpha=n<.6?.8:.8*(1-(n-.6)/.4),t.lineWidth=3;for(const l of[-2,4])t.beginPath(),t.moveTo(e.x,e.y+l),t.lineTo(a,e.y+l),t.stroke();t.restore()}function KS(t,e,n,s,i){const o=e.direction??1;t.save(),t.strokeStyle=i,t.lineWidth=Math.max(1.5,s*.04),t.lineCap="round",t.globalAlpha=n<.7?1:(1-n)/.3;const r=s*(.15+.5*(1-(1-n)**2));for(let a=-1;a<=1;a++){const l=a*Math.PI/7,c=e.x+o*Math.cos(l)*r,h=e.y+Math.sin(l)*r;t.beginPath(),t.arc(c,h,s*.12,o>0?-Math.PI/3:Math.PI*2/3,o>0?Math.PI/3:Math.PI*4/3),t.stroke()}t.restore()}function XS(t){const e=new It({id:`${t.propId}-ride`,tracks:t.propTracks.filter(h=>h.target===t.propId)}),n=t.every??33,s=[],i=[],o=[],r=[];let a=1;for(let h=t.start;;h=Math.min(t.end,h+n)){const u=Uo(t.prop,{state:e.getStateAtTime(h)},t.propId),d=u.anchor(t.anchor);s.push({time:h,value:d.x+(t.offset?.x??0)-t.figure.x}),i.push({time:h,value:d.y+(t.offset?.y??0)-t.figure.y});const f=Math.sin(u.values.turn*Math.PI/2);if(Math.abs(f)>.15&&(a=f>0?1:-1),o.push({time:h,value:Math.abs(f)}),r.push({time:h,value:a}),h>=t.end)break}const l=t.figureId,c=[{id:`${l}-x`,target:l,property:"x",keyframes:s},{id:`${l}-y`,target:l,property:"y",keyframes:i}];return t.turn!==!1&&c.push({id:`${l}-turn`,target:l,property:"turn",keyframes:o},{id:`${l}-facing`,target:l,property:"facing",keyframes:GS(r)}),c}function GS(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 US(t,e,n){const s=r=>`${r.target}\0${r.property}`,i=new Map(e.map(r=>[s(r),r]));return[...t.map(r=>{const a=i.get(s(r));if(!a)return r;i.delete(s(r));const c=[...(r.keyframes??[]).filter(h=>h.time<n.from||h.time>n.to),...a.keyframes??[]].sort((h,u)=>h.time-u.time);return{...r,keyframes:c}}),...i.values()]}function VS(t){const e=new It({id:`${t.leaderId}-tow`,tracks:t.leaderTracks.filter(f=>f.target===t.leaderId)}),n=t.every??33,s=t.towed,i=s.x+s.width/2,o=s.props,r=s.prop.wheelRadius,a=[],l=[],c=[];let h=o.wheelSpin??0,u;for(let f=t.start;;f=Math.min(t.end,f+n)){const p=Uo(t.leader,{state:e.getStateAtTime(f)},t.leaderId),g=p.anchor(t.hitch),m=p.values.turn,w=is(s.prop,{...o,turn:m},s.propScale).anchors[t.anchor];if(!w)throw new Error(`propTow: ${s.prop.kind} has no anchor "${t.anchor}"`);const v=g.x-w.point.x;if(u!==void 0&&r){const k=Math.sin(m*Math.PI/2);h+=(v-u)*(k||1)/s.propScale/r*(180/Math.PI)}if(u=v,a.push({time:f,value:v-i}),l.push({time:f,value:m}),c.push({time:f,value:h}),f>=t.end)break}const d=t.towedId;return[{id:`${d}-x`,target:d,property:"x",keyframes:a},{id:`${d}-turn`,target:d,property:"turn",keyframes:l},...r?[{id:`${d}-wheelSpin`,target:d,property:"wheelSpin",keyframes:c}]:[]]}const Zp=new WeakMap;function JS(t,e){const n=e?.some(Boolean)?e.map(d=>d?1:0).join(""):"";let s=Zp.get(t);s||Zp.set(t,s=new Map);const i=s.get(n);if(i)return i;const o=si(t),r={vertices:o.vertices,faces:o.faces.filter((d,f)=>!e?.[f])},a=r.vertices.flatMap(d=>[d[0],d[1],d[2]]),l=r.vertices.map(()=>[0,0,0]),c=[];r.faces.forEach(d=>{for(const g of d.corners)for(const m of[0,1,2])l[g][m]+=d.normal[m];const[f,...p]=d.corners;for(let g=0;g+1<p.length;g++){const[m,w,v]=[f,p[g],p[g+1]],[k,b,E]=[r.vertices[m],r.vertices[w],r.vertices[v]],$=[b[0]-k[0],b[1]-k[1],b[2]-k[2]],S=[E[0]-k[0],E[1]-k[1],E[2]-k[2]],x=[$[1]*S[2]-$[2]*S[1],$[2]*S[0]-$[0]*S[2],$[0]*S[1]-$[1]*S[0]],M=x[0]*d.normal[0]+x[1]*d.normal[1]+x[2]*d.normal[2];c.push(...M>=0?[m,w,v]:[m,v,w])}});const h=l.flatMap(d=>{const f=Math.hypot(...d)||1;return[d[0]/f,d[1]/f,d[2]/f]}),u=xo({positions:a,normals:h,indices:c});return s.size>=16&&s.clear(),s.set(n,u),u}function ZS(t,e,n={}){const s=t.ink??n.ink??"#26262b",i=(n.outline??2)*(t.outline??1),o=t.glow&&e.glow>0?QS(t.glow.color,e.glow):void 0;return{color:t.fill??s,creases:si(t.shape).creases!==!1,shading:n.shading??"toon",...i>0?{outline:{width:i,color:s}}:{},...o?{emissive:o}:{},...t.seeThrough?{opacity:.45*e.opacity}:e.opacity<1?{opacity:e.opacity}:{}}}function QS(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 t3=xo(of(1,.002,28));function e3(t,e,n){const s=t.rig,[i,o]=s.footprint??[s.length*.45,s.length],r=Math.max(0,At(s,e,"lift")),a=Math.max(0,At(s,e,"size"))/(1+r*.8);return{mesh:t3,world:Ot(n,Lr([0,.004,0],[0,0,0,1],[i*.55*a||1e-4,1,o*.55*a||1e-4])),material:{color:"#000000",shading:"unlit",opacity:.16*a}}}const n3=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),s3=1,i3={kind:"prop",validate(t){const e=t,n=typeof e.prop=="string"&&e.prop in as?[]:[dt("prop preset",e.prop,Object.keys(as))];for(const[s,i]of[[0,"rotateX"],[1,"rotateY"],[2,"rotateZ"]])i in e&&n.push(`${i} is a track, not a field: place it turned with rotation: [${[0,1,2].map(o=>o===s?e[i]:0).join(", ")}]`);return n},prepare(t){const e=t;return hc(e.prop,e.options)},resolve({object:t,prepared:e,values:n,world:s,camera:i,lights:o=[],fog:r,toScreen:a}){const l=t,c=e,h={...l.values};for(const[S,x]of n)typeof x=="number"&&!n3.has(S)&&(h[S]=x);h.turn=0,h.tilt=0;const u=Ot(i.view,s),d={toView:S=>Xt(u,S),toScreen:S=>a(S)},f=d.toView([0,c.rig.height/2,0]);if(-f[2]<=i.near)return null;if(l.look==="mesh"){const S=Jg(c.rig,h),x=S.map(({part:I,local:A})=>({part:I.id,mesh:si(I.shape),...Zl(si(I.shape),A)})),M=jg(x),T=S.map((I,A)=>({...I,hidden:Xg(I.part.id,x[A].mesh,I.local,x[A].key,M)})).filter(({opacity:I})=>I>.01).map(({part:I,matrix:A,glow:_,opacity:C,hidden:N})=>({mesh:JS(I.shape,N),world:Ot(s,A),material:ZS(I,{glow:_,opacity:C},{shading:l.shading,ink:l.ink,outline:l.outline})}));return{meshes:l.shadow===!1?T:[e3(c,h,s),...T]}}const p=a(f),g=a(d.toView([0,c.rig.height/2+1,0])),m=Math.hypot(g.x-p.x,g.y-p.y),w=o.length===0?void 0:(S,x)=>{const M=Xt(s,S),T=[s[0]*x[0]+s[4]*x[1]+s[8]*x[2],s[1]*x[0]+s[5]*x[1]+s[9]*x[2],s[2]*x[0]+s[6]*x[1]+s[10]*x[2]],I=Math.hypot(...T)||1;return{light:rf(M,[T[0]/I,T[1]/I,T[2]/I],o),fog:af(r,Math.hypot(M[0]-i.position[0],M[1]-i.position[1],M[2]-i.position[2]))}},v=sc(c.rig,h,d,m,{perspective:!0,near:i.near,slice:s3,light:w}),k={look:l.look,style:l.style,ink:l.ink,paper:l.paper,fog:r?.color},b=ol(v),E=v.cells??[],$=Math.max(...E.map(S=>-S.depth),-f[2]);return{drawables:[...l.shadow===!1?[]:[{depth:$+c.rig.length,draw:S=>rl(S,v,k)}],...E.map(S=>({depth:-S.depth,draw(x,M){x.lineCap="round",x.lineJoin="round",cf(x,S.parts,b,{...k,time:M.time})}}))]}}},gc=["do","at","for","to","through","toward","speed","height","open","on","wind"],o3=.25,r3=800/180,a3=220,l3=300,c3=["turn"];function h3(t){const e=tr(t),n=Object.keys(t.moves??{});return Object.keys(e).filter(s=>!n.includes(s)&&!c3.includes(s)&&!(e[s].needs??[]).includes("to"))}function Qp(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=h3(e),i=[...n,"face","hold",...s.filter(r=>r!=="hold")],o=[];return t.forEach((r,a)=>{const l=u=>o.push({beat:a,message:u});if(!r||typeof r!="object"||Array.isArray(r))return l(`Each beat must be an object like { do: '${i[0]??"hold"}' }.`);const c=r,h={duration:"for",path:"through",points:"through",position:"to",heading:"toward",direction:"toward"};for(const u of Object.keys(c))gc.includes(u)||l(dt("beat field",u,gc,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&&!fn(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(fn))&&l("`through` is a list of points on the ground, each [x, z] metres.")),c.do==="face"&&!(fn(c.toward)||typeof c.toward=="number")&&l("`face` needs `toward`: a point [x, z] or a heading in degrees.")}),o}function u3(t,e,n,s){const i=Qp(n,e);if(i.length>0)throw new Error(`propScript3D (${e.kind}): ${i.length} problem(s) in the beats:
|
|
60
|
+
`)}`);const o=n.map(d=>up(d,e)),r=tr(t,o,s),a=kS(o,r.beats,s),l=s.ground??0,c=d=>s.ride===!1?d:Object.values(e).reduce((f,p)=>p.ride(f,t,{ground:l}),d);n.forEach((d,f)=>{for(const p of bS(d)){const g=y=>new Error(`surfaceScript: beat ${f} (${d.do}), ${p.edit} on ${p.surface}: ${y}`),m=(y,T)=>{const $=typeof y=="object"?y.beat:f,M=(typeof y=="object"?y.at:y)??T??"start",x=a[$][M];if(x===void 0){const S=os.filter(E=>a[$][E]!==void 0).join(", ");throw g(`beat ${$} (${n[$].do}) has no ${M} (it has ${S})`)}return x},w=e[p.surface],v=m(p.at??(a[f].contact!==void 0?"contact":"start")),k=p.until===void 0?void 0:m(p.until,"end");if(k!==void 0&&k<v)throw g(`it ends (${k} ms) before it starts (${v} ms)`);try{if(p.edit==="carry"){const T=w.piece(p.anchor),$=uc(t,c(r.tracks),{x:s.from??0,y:l,style:s.figureStyle??(s.height?{height:s.height}:void 0),cast:s,start:v,end:k});w.follow(T,$);continue}const y=Object.fromEntries(Object.entries(p).filter(([T])=>!mS.includes(T)));w.edit(p.edit,p.anchor,{...y,at:v,...k!==void 0?{duration:k-v}:{}})}catch(y){throw g(y.message)}}});const h=c(r.tracks),u=Object.entries(e).flatMap(([d,f])=>f.tracks(d));return{...r,tracks:[...h,...u],figureTracks:h}}function hp(t,e,n={}){if(!Array.isArray(t))return hi(t,n);const s=[],i=Object.keys(e),o=(c,h,u)=>{const d=typeof h=="string"?e[h]:void 0;return d||s.push({level:"error",beat:c,message:`${u}: ${ft("surface",h,i)}`}),d},r=(c,h,u,d)=>{if(typeof u!="string"){s.push({level:"error",beat:c,message:`${d}: \`anchor\` is a place name such as ${Object.keys(h.about.anchors).join(", ")} (got ${JSON.stringify(u)}).`});return}try{h.anchor(u,0)}catch(f){s.push({level:"error",beat:c,message:`${d}: ${f.message}`})}},a=(c,h,u)=>{const d=typeof h=="object"&&h!==null?h.at:h;if(typeof h=="object"&&h!==null){const f=h.beat;if((typeof f!="number"||!Number.isInteger(f)||f<c||f>=t.length)&&s.push({level:"error",beat:c,message:`${u}: \`beat\` is the index of this beat or a later one, ${c} to ${t.length-1} (got ${JSON.stringify(f)}).`}),d===void 0)return}typeof d=="number"?s.push({level:"error",beat:c,message:`${u}: a cue starts at a moment of its beat (${os.join(", ")}), not at ms; set the beat's own \`at\` to move it.`}):(typeof d!="string"||!os.includes(d))&&s.push({level:"error",beat:c,message:`${u}: ${ft("moment",d,os)}`})};t.forEach((c,h)=>{if(!c||typeof c!="object"||Array.isArray(c))return;const u=c;for(const f of["target","to","onto"]){if(!er(u[f]))continue;const p=u[f],g=o(h,p.surface,`\`${f}\``);g&&r(h,g,p.anchor,`\`${f}\``)}if(u.then===void 0)return;(Array.isArray(u.then)?u.then:[u.then]).forEach(f=>{if(!f||typeof f!="object"||Array.isArray(f)){s.push({level:"error",beat:h,message:"`then` is a cue, { surface, edit, anchor, at?, until? }, or a list of them."});return}const p=f,g=o(h,p.surface,"`then`");if(!g)return;const m=`\`then\` (${String(p.edit)} on ${String(p.surface)})`,w=[...Object.keys(g.about.edits),...yS];if(typeof p.edit!="string"||!w.includes(p.edit)){s.push({level:"error",beat:h,message:`\`then\`: ${ft("edit",p.edit,w)}`});return}for(const v of Array.isArray(p.anchor)?p.anchor:[p.anchor])r(h,g,v,m);p.edit==="carry"&&typeof p.anchor!="string"&&s.push({level:"error",beat:h,message:`${m}: \`carry\` takes one anchor, the piece it carries.`}),p.edit==="carry"&&p.until===void 0&&s.push({level:"error",beat:h,message:`${m}: \`carry\` needs \`until\` (when it lets go, such as { beat: ${h+1}, at: 'release' }).`}),p.at!==void 0&&a(h,p.at,`${m} \`at\``),p.until!==void 0&&a(h,p.until,`${m} \`until\``),p.until!==void 0&&p.duration!==void 0&&s.push({level:"error",beat:h,message:`${m}: give \`until\` or \`duration\`, not both.`})})});const l=t.map(c=>c&&typeof c=="object"&&!Array.isArray(c)?up(c,e,!0):c);return[...hi(l,n),...s]}function up(t,e,n=!1){const{then:s,...i}=t,o=a=>{try{return e[a.surface].anchor(a.anchor,0)}catch(l){if(n)return{x:0,y:0,left:0,right:0,top:0,bottom:0,width:0,height:0};throw l}},r={...i};return er(t.target)&&(r.target=o(t.target)),er(t.to)&&(r.to=o(t.to).x),er(t.onto)&&(r.onto=o(t.onto).top),r}function kS(t,e,n){let s=0;return t.map(i=>{const o=Zo([i],n.actions).length,r=e.slice(s,s+o);s+=o;const a=r.find(c=>c.contact!==void 0)?.contact,l=[...r].reverse().find(c=>c.release!==void 0)?.release;return{start:r[0]?.start,end:r[r.length-1]?.end,...a!==void 0?{contact:a}:{},...l!==void 0?{release:l}:{}}})}function vS(t){const e={actions:t.actions,gaits:t.gaits},n=tc(e);if(n.length>0)throw new Error(`persona "${t.name}": ${n.join(" ")}`);const s=[...Object.keys(Dt),...Object.keys(t.gaits??{})],i=t.gait??"walk";if(!s.includes(i))throw new Error(`persona "${t.name}": ${ft("gait",i,s)}`);if(t.mood&&!(t.mood in vt))throw new Error(`persona "${t.name}": ${ft("mood",t.mood,Object.keys(vt))}`);const o=t.acting??"snappy";if(typeof o=="string"&&!(o in wn))throw new Error(`persona "${t.name}": ${ft("acting style",o,Object.keys(wn))}`);if(typeof t.stance=="string"&&!(t.stance in Jt))throw new Error(`persona "${t.name}": ${ft("stance",t.stance,Object.keys(Jt))}`);const r=t.height??120,a=typeof t.stance=="string"?Jt[t.stance]:Rt(t.stance??{}),l=t.mood?Fe(a,t.mood):a,c={...t.look,height:r},h=t.summary??`${t.name}, a stick figure`;return{name:t.name,summary:h,cast:e,rest:l,height:r,figure:u=>xa({x:u.x,y:u.y,pose:l,style:{...c,...u.facing?{facing:u.facing}:{}},cast:e}),script:(u,d,f={})=>tr(u,d,{...e,from:f.from,ground:f.ground,facing:f.facing,height:r,style:o,gait:i,start:l,rest:l,energy:t.energy}),check:u=>hi(u,e),handPath:(u,d,f)=>uc(u,d,{...f,style:c,cast:e}),describe:()=>({name:t.name,summary:h,habits:{height:r,acting:typeof o=="string"?o:"custom",gait:i,...t.mood?{mood:t.mood}:{},stance:typeof t.stance=="string"?t.stance:t.stance?"custom":"rest"},actions:ec(e),own:{actions:Object.keys(t.actions??{}),gaits:Object.keys(t.gaits??{})}})}}const MS=new Set(["x","y","walking","gait"]),dp=.215+.205;function fp(t,e,n=1){const{points:s}=oe(t,ut),i=s["hip.left"],o=s["knee.left"],r=s["ankle.left"],a=i&&o&&r?Math.hypot(o.x-i.x,o.y-i.y)+Math.hypot(r.x-o.x,r.y-o.y):dp*t.height;return nl(e,a/dp,n)}function SS(t,e,n,s={}){const i=tr(t,n,{...s,height:e.height,reach:s.reach??gp(e)}),o=i.tracks.find(w=>w.property==="facing")?.keyframes??[],r=w=>{let v=s.facing??1;for(const k of o)k.time<=w&&(v=k.value);return v},a=to(i.keys),l=i.keys.map((w,v)=>{const k=Hf(a[v]);return{time:w.time,pose:r(w.time)<0?sd(k):k,...w.easing?{easing:w.easing}:{},...w.act===!1?{act:!1}:{}}}),{rest:c,start:h,...u}=s;ES(l,a,n,i,e,r,s);const d=qg(t,l,u),f=Wo(t,d,i.lines,{energy:s.energy}),p=i.tracks.filter(w=>MS.has(w.property)),g=i.tracks.find(w=>w.property==="walk");return{tracks:g?[...f,...p,_S(t,g,i.tracks,e,s)]:[...f,...p],duration:i.duration,lines:i.lines,keys:l,beats:i.beats,effects:i.effects}}function gp(t){const e=kt({"arm.left.spread":90,"arm.left.elbow":0,"arm.left.bend":0,"leg.left.knee":0}),n=oe(t,e).points,s=Math.hypot(n["hand.left"].x-n["shoulder.left"].x,n["hand.left"].y-n["shoulder.left"].y),i=Math.hypot(n["toe.left"].x-n["hip.left"].x,n["toe.left"].y-n["hip.left"].y),o=le({...ht,rightShoulder:90,rightElbow:0,rightWrist:0},{height:t.height,facing:1}),r=le({...ht,rightHip:90,rightKnee:0},{height:t.height,facing:1}),a={x:(o.hands.right.x+o.fingertips.right.x)/2,y:(o.hands.right.y+o.fingertips.right.y)/2},l=Math.hypot(a.x-o.shoulders.right.x,a.y-o.shoulders.right.y),c=Math.hypot(r.feet.right.x-r.hip.x,r.feet.right.y-r.hip.y);return{arm:l>0?s/l:1,leg:c>0?i/c:1}}const xS={point:"arm",grab:"arm",put:"arm",write:"arm",swipe:"arm",push:"arm",kick:"leg"},TS=new Set(["point","grab","put","kick"]);function ES(t,e,n,s,i,o,r){const a=s.beats;if(n.length!==a.length)return;const l=new It({id:"placed",tracks:s.tracks.filter(h=>h.property==="x"||h.property==="y")}),c=h=>{const u=l.getStateAtTime(h).values.get(s.tracks[0]?.target??"");return{x:(r.from??0)+Number(u?.get("x")??0),y:(r.ground??0)+Number(u?.get("y")??0)}};n.forEach((h,u)=>{const d=xS[h.do],f=a[u];if(!d||f.contact===void 0||h.do!=="swipe"&&!h.target)return;const p=f.contact,g=f.release??f.contact;t.forEach((m,w)=>{if(m.time<p-1||m.time>g+1)return;const v=o(m.time),k=le(e[w],{height:i.height,facing:v<0?-1:1}),y=c(m.time),T=TS.has(h.do)&&h.target?{x:h.target.x-y.x,y:h.target.y-y.y}:void 0,$={x:(k.hands.right.x+k.fingertips.right.x)/2,y:(k.hands.right.y+k.fingertips.right.y)/2},M=T??(d==="arm"?$:k.toes.right),x=v<0?"right":"left",S=`${d}.${x}`;let E=m.pose;if(h.do==="point")E=Se(i,E,S,M);else if(d==="arm")E=Se(i,OS(i,E,x,M),S,M);else for(let P=0;P<3;P++){const A=oe(i,E).points,I=A[`ankle.${x}`],_=A[`toe.${x}`];E=Se(i,E,S,{x:M.x-(_.x-I.x),y:M.y-(_.y-I.y)})}t[w]={...m,pose:E}})})}function AS(t,e){const n=kt({[`arm.${e}.spread`]:90,[`arm.${e}.elbow`]:0,[`arm.${e}.bend`]:0}),s=oe(t,n).points;return Math.hypot(s[`hand.${e}`].x-s[`shoulder.${e}`].x,s[`hand.${e}`].y-s[`shoulder.${e}`].y)}const PS=5,$S=4,IS=8;function OS(t,e,n,s){const i=AS(t,n)*.9,o=a=>{const l=oe(t,a).points[`shoulder.${n}`];return Math.hypot(s.x-l.x,s.y-l.y)<=i};if(o(e))return e;let r=e;for(let a=1;a<=IS;a++)if(r={...e,lean:(e.lean??0)+PS*a,bend:(e.bend??0)+$S*a},o(r))return r;return r}function _S(t,e,n,s,i){const o=n.find(u=>u.property==="gait"),r=o?new It({id:`${t}-gait-of`,tracks:[o]}):void 0,a=u=>{const d=r?.getStateAtTime(u).values.get(t)?.get("gait");if(typeof d=="string")return Dt[d]??i.gaits?.[d]??d},l=e.keyframes,c=[];let h=l[0]?.value??0;return l.forEach((u,d)=>{if(d>0){const f=l[d-1],p=a((f.time+u.time)/2),g=Ji(p,s.height),m=fp(s,p);h+=(u.value-f.value)*(m>0?g/m:1)}else h=u.value;c.push({...u,value:h})}),{...e,keyframes:c}}const mt=["rect","circle","text","line","path","image","custom"],nr={x:{description:"Moves it right by this much from where it was placed (an offset; the target’s own x is its place)",unit:"px",types:mt},y:{description:"Moves it down by this much from where it was placed (an offset)",unit:"px",types:mt},opacity:{description:"How opaque it is",unit:"0..1",min:0,max:1,types:mt},rotate:{description:"Turns it clockwise about its origin",unit:"degrees",types:mt},rotateX:{description:"Tips it about the horizontal axis (3D; shows with perspective)",unit:"degrees",types:mt},rotateY:{description:"Turns it about the vertical axis (3D; shows with perspective)",unit:"degrees",types:mt},z:{description:"Depth toward the viewer (shows with perspective)",unit:"px",types:mt},perspective:{description:"Distance from the viewer: nearer parts grow, further ones shrink",unit:"px",min:1,types:mt},scale:{description:"Size, both ways",unit:"factor",types:mt},scaleX:{description:"Width factor",unit:"factor",types:mt},scaleY:{description:"Height factor",unit:"factor",types:mt},skewX:{description:"Slants it sideways",unit:"degrees",types:mt},skewY:{description:"Slants it up and down",unit:"degrees",types:mt},originX:{description:"Transform pivot across its box",unit:"% (0 left, 50 centre, 100 right)",min:0,max:100,types:mt},originY:{description:"Transform pivot down its box",unit:"% (0 top, 50 centre, 100 bottom)",min:0,max:100,types:mt},fill:{description:"Fill colour (also written fillStyle)",kind:"color",types:mt},stroke:{description:"Outline colour (also written strokeStyle)",kind:"color",types:mt},strokeWidth:{description:"Outline width (also written lineWidth)",unit:"px",min:0,types:mt},clipTop:{description:"Hides this much from the top edge, for reveals",unit:"% of its height",min:0,max:100,types:mt},clipRight:{description:"Hides this much from the right edge",unit:"% of its width",min:0,max:100,types:mt},clipBottom:{description:"Hides this much from the bottom edge",unit:"% of its height",min:0,max:100,types:mt},clipLeft:{description:"Hides this much from the left edge",unit:"% of its width",min:0,max:100,types:mt},blur:{description:"Gaussian blur",unit:"px",min:0,types:mt},brightness:{description:"Brightness factor (1 unchanged)",unit:"factor",min:0,types:mt},glow:{description:"Soft glow around it, in glowColor",unit:"px",min:0,types:mt},glowColor:{description:"Colour of the glow",kind:"color",types:mt},shadowX:{description:"Drop shadow offset right",unit:"px",types:mt},shadowY:{description:"Drop shadow offset down",unit:"px",types:mt},shadowBlur:{description:"Drop shadow softness",unit:"px",min:0,types:mt},shadowColor:{description:"Drop shadow colour",kind:"color",types:mt},shine:{description:"A highlight sweeping across the fill",unit:"0..1 (progress)",min:0,max:1,types:mt},drawOn:{description:"How much of the outline is drawn, for drawing a shape on; the fill appears when it is complete",unit:"0..1",min:0,max:1,types:["rect","circle","line","path"]},width:{description:"Box width",unit:"px",min:0,types:["rect","image"]},height:{description:"Box height",unit:"px",min:0,types:["rect","image"]},borderRadius:{description:"Rounded corners",unit:"px",min:0,types:["rect","image"]},radius:{description:"Circle radius",unit:"px",min:0,types:["circle"]},x2:{description:"Line end, x",unit:"px",types:["line"]},y2:{description:"Line end, y",unit:"px",types:["line"]},d:{description:"SVG path data; tween between paths to morph",kind:"string",types:["path"]},text:{description:"The text shown (a text track types or scrambles it)",kind:"string",types:["text"]},fontSize:{description:"Font size",unit:"px",min:0,types:["text"]},fontWeight:{description:"Font weight",unit:"100..900",min:100,max:900,types:["text"]},motionPath:{description:"Moves it along an SVG path (a motion-path track writes motionPathX/Y and, aligned, rotate)",kind:"string",types:mt},quaternion:{description:'A rotation as [x, y, z, w] (a track with interpolation: "slerp")',kind:"list",types:mt}},dc={fillStyle:"fill",strokeStyle:"stroke",lineWidth:"strokeWidth",rotateZ:"rotate",motionPathX:"x",motionPathY:"y",motionPathRotate:"rotate"},CS={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 pp(t){const e=t,n=Object.entries(nr).filter(([,i])=>i.types.includes(t.type)).map(([i,{types:o,...r}])=>({name:i,...r,...e[i]!==void 0&&typeof e[i]!="object"?{value:e[i]}:{}}));if(t.type!=="custom")return{type:t.type,properties:n};const s=t.about;for(const[i,o]of Object.entries(t.props??{}))n.push({name:i,description:s?.props?.[i]?.description??"",...s?.props?.[i],value:o});return{type:"custom",...s?{kind:s.kind,summary:s.summary}:{},properties:n,...s?.actions?{actions:s.actions}:{}}}function mp(t){const e=pp(t).properties.map(n=>n.name);return[...e,...Object.keys(dc).filter(n=>e.includes(dc[n]))]}function HS(t,e){const n=[],s=Object.keys(e);for(const i of t){const o=d=>n.push({level:"error",track:i.id,message:d}),r=e[i.target];if(!r){o(ft("target",i.target,s));continue}const a=mp(r),l=r.type==="custom"&&r.acceptsProp?.(i.property);if(!a.includes(i.property)&&!l){o(`${i.target}: ${ft("property",i.property,a,CS[i.property])}`);continue}const c=i.keyframes??[];for(let d=1;d<c.length;d++)c[d].time<c[d-1].time&&o(`${i.target}.${i.property}: keyframes out of time order (${c[d-1].time} ms, then ${c[d].time} ms).`);const h=nr[dc[i.property]??i.property]??r.about?.props?.[i.property],u=h&&(h.kind??"number")==="number";for(const d of c){if(u&&typeof d.value!="number"){o(`${i.target}.${i.property}: values are numbers${h.unit?` (${h.unit})`:""} (got ${JSON.stringify(d.value)} at ${d.time} ms).`);break}if(u&&typeof d.value=="number"&&(h.min!==void 0&&d.value<h.min||h.max!==void 0&&d.value>h.max)){n.push({level:"warning",track:i.id,message:`${i.target}.${i.property}: ${d.value} at ${d.time} ms is outside ${h.min??"−∞"}..${h.max??"∞"}${h.unit?` (${h.unit})`:""}.`});break}}}return n}const rs=(t,e)=>t[2]<=-e;function fc(t,e,n){const s=(-n-t[2])/(e[2]-t[2]);return[t[0]+(e[0]-t[0])*s,t[1]+(e[1]-t[1])*s,-n]}function yp(t,e){if(t.every(s=>rs(s,e)))return t;const n=[];return t.forEach((s,i)=>{const o=t[(i+t.length-1)%t.length],r=rs(s,e),a=rs(o,e);r!==a&&n.push(fc(o,s,e)),r&&n.push(s)}),n.length>=3?n:[]}function RS(t,e){if(t.every(i=>rs(i,e)))return[t];const n=[];let s=[];return t.forEach((i,o)=>{const r=rs(i,e);if(o>0){const a=t[o-1],l=rs(a,e);l&&!r?(s.push(fc(a,i,e)),n.push(s),s=[]):!l&&r&&s.push(fc(a,i,e))}r&&s.push(i)}),s.length>0&&n.push(s),n.filter(i=>i.length>=2)}function bp(t,e,n){const s=e-t;if(!(s>=n*1.5))return[t,e];const i=Math.round(s/n);return Array.from({length:i+1},(o,r)=>t+s*r/i)}function LS(t,e,n){const s=(i,o)=>Math.max(0,Math.min(i.length-2,i.findIndex((r,a)=>a>0&&o<=r)-1));return[s(t,n[0]),s(e,n[2])]}function NS(t,e){const n=s=>{const i=[e[0]*s[0]+e[4]*s[1]+e[8]*s[2],e[1]*s[0]+e[5]*s[1]+e[9]*s[2],e[2]*s[0]+e[6]*s[1]+e[10]*s[2]],o=Math.hypot(...i)||1;return[i[0]/o,i[1]/o,i[2]/o]};return{...t,vertices:t.vertices.map(s=>Gt(e,s)),faces:t.faces.map(s=>({corners:s.corners,normal:n(s.normal)}))}}function sr(t,e,n,s){const i=r=>(r[e]-n)*s>=0;if(t.every(i))return t;const o=[];return t.forEach((r,a)=>{const l=t[(a+t.length-1)%t.length];if(i(r)!==i(l)){const c=(n-l[e])/(r[e]-l[e]);o.push([0,1,2].map(h=>h===e?n:l[h]+(r[h]-l[h])*c))}i(r)&&o.push(r)}),o.length>=3?o:[]}function FS(t,e,n){const s=t.faces.map(r=>({points:r.corners.map(a=>t.vertices[a]),normal:r.normal})),i=[],o={x:e.slice(1,-1),z:n.slice(1,-1)};for(let r=0;r+1<e.length;r++)for(let a=0;a+1<n.length;a++){const l=[],c=new Map,h=p=>{const g=p.map(w=>Math.round(w*1e6)).join(",");let m=c.get(g);return m===void 0&&(m=l.length,l.push(p),c.set(g,m)),m},u=[],d=p=>p===0,f=(p,g)=>p+2===g.length;for(const p of s){let g=p.points;d(r)||(g=sr(g,0,e[r],1)),g.length&&!f(r,e)&&(g=sr(g,0,e[r+1],-1)),g.length&&!d(a)&&(g=sr(g,2,n[a],1)),g.length&&!f(a,n)&&(g=sr(g,2,n[a+1],-1)),g.length>=3&&u.push({corners:g.map(h),normal:p.normal})}u.length>0&&i.push({cell:[r,a],mesh:{vertices:l,faces:u,creases:t.creases,joined:t.joined,walls:o}})}return i}const WS=new WeakMap,DS=new WeakMap,BS=48,wp=t=>t.map(e=>Math.round(e*1e5)).join(",");function kp(t,e,n,s){let i=t.get(e);i||t.set(e,i=new Map);let o=i.get(n);return o===void 0&&(i.size>=BS&&i.clear(),i.set(n,o=s())),o}function gc(t,e){const n=wp(e);return kp(WS,t,n,()=>{const s=NS(t,e),i=[1/0,1/0,1/0],o=[-1/0,-1/0,-1/0];for(const r of s.vertices)for(const a of[0,1,2])i[a]=Math.min(i[a],r[a]),o[a]=Math.max(o[a],r[a]);return{key:n,inSpace:s,low:i,high:o}})}function zS(t,e){const n=t.map(h=>({...h,...gc(h.mesh,h.local)})),s=[1/0,1/0,1/0],i=[-1/0,-1/0,-1/0];for(const h of n)for(const u of[0,1,2])s[u]=Math.min(s[u],h.low[u]),i[u]=Math.max(i[u],h.high[u]);const o=bp(s[0],i[0],e),r=bp(s[2],i[2],e),a=`${o.join(",")}|${r.join(",")}`,l=n.flatMap(h=>{if(h.high[0]-h.low[0]<=e*2.5&&h.high[2]-h.low[2]<=e*2.5||h.whole||h.mesh.joined||(h.mesh.marks?.length??0)>0){const d=[(h.low[0]+h.high[0])/2,(h.low[1]+h.high[1])/2,(h.low[2]+h.high[2])/2];return[{part:h.part,mesh:h.mesh,cut:!1,cell:LS(o,r,d)}]}return kp(DS,h.inSpace,a,()=>FS(h.inSpace,o,r)).map(d=>({part:h.part,mesh:d.mesh,cut:!0,cell:d.cell}))}),c=(s[1]+i[1])/2;return{pieces:l,middle:([h,u])=>[(o[h]+o[h+1])/2,c,(r[u]+r[u+1])/2]}}const vp=.004,pc=.05,Mp=new WeakMap;function qS(t){let e=Mp.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)}),Mp.set(t,e)),e}const Sp=new WeakMap;function xp(t){return t.filter(({mesh:e})=>qS(e)).map(({part:e,key:n,inSpace:s,low:i,high:o})=>{let r=Sp.get(s);return r||(r=s.faces.map(a=>{const l=s.vertices[a.corners[0]];return{normal:a.normal,offset:a.normal[0]*l[0]+a.normal[1]*l[1]+a.normal[2]*l[2]}}),Sp.set(s,r)),{part:e,key:n,planes:r,low:i,high:o}})}function YS(t,e,n,s){const i=e.reduce((o,r)=>[o[0]+r[0]/e.length,o[1]+r[1]/e.length,o[2]+r[2]/e.length],[0,0,0]);for(const o of s){if(o.part===t||[0,1,2].some(a=>i[a]<o.low[a]-pc||i[a]>o.high[a]+pc))continue;if(o.planes.every(a=>{const l=a.normal[0]*n[0]+a.normal[1]*n[1]+a.normal[2]*n[2],c=e.map(u=>a.normal[0]*u[0]+a.normal[1]*u[1]+a.normal[2]*u[2]-a.offset);if(c.every(u=>Math.abs(u)<=vp))return l<-.9;const h=Math.abs(l)<.5?pc:vp;return c.every(u=>u<=h)}))return!0}return!1}const Tp=new WeakMap;function Ep(t,e,n,s,i){const o=`${s}|${i.map(l=>l.key).join(";")}`;let r=Tp.get(e);r||Tp.set(e,r=new Map);let a=r.get(o);if(!a){r.size>=48&&r.clear();const l=h=>{const u=[n[0]*h[0]+n[4]*h[1]+n[8]*h[2],n[1]*h[0]+n[5]*h[1]+n[9]*h[2],n[2]*h[0]+n[6]*h[1]+n[10]*h[2]],d=Math.hypot(...u)||1;return[u[0]/d,u[1]/d,u[2]/d]},c=e.vertices.map(h=>Gt(n,h));a=e.faces.map(h=>YS(t,h.corners.map(u=>c[u]),l(h.normal),i)),r.set(o,a)}return a}const as={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}},mc=Math.PI/180;function Ap(t,e,n){return{toView:s=>Ca(Zt(s,t*90*mc),-e*mc),toScreen:s=>({x:s[0]*n,y:-s[1]*n})}}const Pp=new WeakMap,di=t=>ir(t),ir=t=>{let e=Pp.get(t);return e||Pp.set(t,e=ag(t)),e};function At(t,e,n){return e[n]??t.controls[n]?.default??as[n]?.default??0}function fi(t,e){const n=Math.max(.05,At(t,e,"squash")),s=1/Math.sqrt(n),o=[1,0,0,0,0,1,At(t,e,"lean"),0,0,0,1,0,0,0,0,1];return[tn([0,At(t,e,"lift"),0]),ae(ee([1,0,0],-At(t,e,"pitch"))),ae(ee([0,0,1],At(t,e,"roll"))),o,en([s,n,s]),en(Array(3).fill(Math.max(0,At(t,e,"size"))))].reduce((r,a)=>Ot(r,a))}function yc(t,e){const n=fi(t,e),s=new Map,i=Object.entries(t.controls).flatMap(([r,a])=>(a.bind??[]).map(l=>({value:At(t,e,r),bind:l}))),o=r=>{const a=s.get(r.id);if(a)return a;const l=r.parent?t.parts.find(h=>h.id===r.parent):void 0;if(r.parent&&!l)throw new Error(`prop rig: part "${r.id}" hangs from "${r.parent}", which is not a part`);let c=Ot(l?o(l):n,tn(r.at??[0,0,0]));if(r.rotate){const[h,u,d]=r.rotate;h&&(c=Ot(c,ae(ee([1,0,0],h)))),u&&(c=Ot(c,ae(ee([0,1,0],u)))),d&&(c=Ot(c,ae(ee([0,0,1],d))))}for(const{value:h,bind:u}of i)if(!(!u.parts.includes(r.id)||h===0)){if(u.translate&&(c=Ot(c,tn([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,tn(d),ae(ee(f,u.rotate.degrees*h)),tn([-d[0],-d[1],-d[2]])].reduce((p,g)=>Ot(p,g))}u.scale&&(c=Ot(c,en([1+(u.scale[0]-1)*h,1+(u.scale[1]-1)*h,1+(u.scale[2]-1)*h])))}return s.set(r.id,c),c};for(const r of t.parts)o(r);return s}const bc=(()=>{const t=[-.45,.75,.5],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),KS=Math.cos(35*mc);function wc(t,e,n,s,i={}){const o=t.derive?{...e,...t.derive(e)}:e,r=yc(t,o),a=n.toView([0,0,0]),l=_=>N=>[_[0]*N[0]+_[4]*N[1]+_[8]*N[2],_[1]*N[0]+_[5]*N[1]+_[9]*N[2],_[2]*N[0]+_[6]*N[1]+_[10]*N[2]],c=fi(t,o),h=i.slice===void 0?null:Xr(c),u=h?t.parts.map(_=>({part:_,mesh:ir(_.shape),local:Ot(h,r.get(_.id)),whole:_.shape.type==="tube"})):void 0,d=u?zS(u,i.slice):void 0,f=u?xp(u.map(_=>({part:_.part.id,mesh:_.mesh,...gc(_.mesh,_.local)}))):void 0,p=(_,N,Y,V)=>{const tt=Z=>n.toView(Gt(Y,Z)),X=N.vertices.map(tt),R=X.map(Z=>n.toScreen(Z)),z=i.perspective?i.near:void 0,K=Z=>Z.map(rt=>n.toScreen(rt)),O=Z=>z===void 0?Z:yp(Z,z),D=Z=>z===void 0?[Z]:RS(Z,z),st=l(Y),H=N.faces.map(Z=>{const rt=n.toView(st(Z.normal)),ct=[rt[0]-a[0],rt[1]-a[1],rt[2]-a[2]],dt=Math.hypot(...ct)||1;return[ct[0]/dt,ct[1]/dt,ct[2]/dt]}),L=f&&V?Ep(_.id,N,V,wp(V),f):void 0,q=Z=>L?.[Z]??!1,U=H.map((Z,rt)=>{if(q(rt))return!1;if(!i.perspective)return Z[2]>1e-6;const dt=N.faces[rt].corners.reduce((yt,bt)=>[yt[0]+X[bt][0],yt[1]+X[bt][1],yt[2]+X[bt][2]],[0,0,0]);return-(Z[0]*dt[0]+Z[1]*dt[1]+Z[2]*dt[2])>1e-9}),F=Z=>N.faces[Z].corners.reduce((rt,ct)=>rt+X[ct][2],0)/N.faces[Z].corners.length,W=N.faces.map((Z,rt)=>({face:Z,i:rt})).filter(({i:Z})=>U[Z]).map(({face:Z,i:rt})=>({i:rt,solved:{points:z===void 0?Z.corners.map(ct=>R[ct]):K(O(Z.corners.map(ct=>X[ct]))),depth:F(rt),tone:.72+.33*Math.max(0,H[rt][0]*bc[0]+H[rt][1]*bc[1]+H[rt][2]*bc[2])}})).filter(Z=>Z.solved.points.length>=3).sort((Z,rt)=>Z.solved.depth-rt.solved.depth);if(i.light){const Z=l(Y);for(const{i:rt,solved:ct}of W){const dt=N.faces[rt].corners,yt=dt.reduce((Hc,Ix)=>{const Rc=Gt(Y,N.vertices[Ix]);return[Hc[0]+Rc[0]/dt.length,Hc[1]+Rc[1]/dt.length,Hc[2]+Rc[2]/dt.length]},[0,0,0]),bt=Z(N.faces[rt].normal),re=Math.hypot(...bt)||1,mi=i.light(yt,[bt[0]/re,bt[1]/re,bt[2]/re]);ct.light=mi.light,ct.fog=mi.fog}}const B=W.map(Z=>Z.solved),J=jS(N),j=[],Q=[];for(const[Z,rt]of J){const ct=rt.filter(yt=>U[yt]).length;if(ct===0)continue;const dt=rt.length===2&&ct===2&&N.creases!==!1&&H[rt[0]][0]*H[rt[1]][0]+H[rt[0]][1]*H[rt[1]][1]+H[rt[0]][2]*H[rt[1]][2]<KS;rt.length===1&&(N.joined||XS(N,Z))||(rt.length===1||ct===1||dt)&&(j.push(Z.split("-").map(Number)),Q.push(rt.filter(yt=>U[yt]).reduce((yt,bt)=>F(bt)>F(yt)?bt:yt)))}const et=Z=>N.faces.findIndex(rt=>rt.corners.length>4&&Math.sign(US(N.vertices[Z],rt.normal))>0),C=(N.marks??[]).filter(([Z])=>et(Z)<0||U[et(Z)]),G=([Z,rt])=>z===void 0?[[R[Z],R[rt]]]:D([X[Z],X[rt]]).map(K),ot=C.flatMap(G),at=Z=>z===void 0?[Z.map(rt=>R[rt])]:D(Z.map(rt=>X[rt])).map(K);if(i.slice!==void 0){const Z=new Map;j.forEach((rt,ct)=>Z.set(Q[ct],[...Z.get(Q[ct])??[],rt]));for(const{i:rt,solved:ct}of W){ct.edges=_p(Z.get(rt)??[]).flatMap(at);const dt=N.faces[rt].corners;ct.center=dt.reduce((bt,re)=>[bt[0]+X[re][0]/dt.length,bt[1]+X[re][1]/dt.length,bt[2]+X[re][2]/dt.length],[0,0,0]),ct.normal=H[rt];const yt=W[W.length-1].i;ct.marks=C.filter(([bt])=>(et(bt)>=0?et(bt):yt)===rt).flatMap(G)}}const it=_.glow?Math.max(0,Math.min(1,At(t,o,_.glow.control))):0,lt=_.fade?Math.max(0,Math.min(1,At(t,o,_.fade.control))):0,nt=_.fade?Math.max(0,Math.min(1,_.fade.from+(_.fade.to-_.fade.from)*lt)):1;return{part:_,depth:X.reduce((Z,rt)=>Z+rt[2],0)/Math.max(1,X.length),faces:B,edges:_p(j).flatMap(at),marks:ot,glow:it,opacity:nt,..._.shape.type==="tube"?{spine:GS(D(_.shape.points.map(tt)).map(K))}:{},...N.walls?{cut:!0}:{}}},g=new Map(u?.map(_=>[_.part.id,_.local])),w=(d?d.pieces.map(_=>({part:_.part,mesh:_.mesh,m:_.cut?c:r.get(_.part.id),local:_.cut?Ri():g.get(_.part.id),cell:_.cell})):t.parts.map(_=>({part:_,mesh:ir(_.shape),m:r.get(_.id),local:void 0,cell:void 0}))).map(_=>({cell:_.cell,solved:p(_.part,_.mesh,_.m,_.local)})),v=w.map(_=>_.solved),k=_=>_.filter(N=>N.faces.length>0&&N.opacity>.01).sort((N,Y)=>N.depth-Y.depth);let y;if(d){const _=new Map(t.parts.map(Y=>{const V=r.get(Y.id),tt=ir(Y.shape).vertices;return[Y.id,tt.reduce((X,R)=>X+n.toView(Gt(V,R))[2],0)/Math.max(1,tt.length)]})),N=new Map;for(const Y of w){const V=Y.cell.join(",");N.has(V)||N.set(V,{cell:Y.cell,parts:[]}),N.get(V).parts.push(Y.solved),Y.solved.depth=_.get(Y.solved.part.id)}y=[...N.values()].map(({cell:Y,parts:V})=>({depth:n.toView(Gt(c,d.middle(Y)))[2],parts:k(V)})).filter(Y=>Y.parts.length>0)}const T={};for(const[_,N]of Object.entries(t.anchors??{})){const Y=N.part?r.get(N.part):fi(t,o);if(!Y)throw new Error(`prop rig: anchor "${_}" is on "${N.part}", which is not a part`);const V=n.toView(Gt(Y,N.at));T[_]={point:n.toScreen(V),depth:V[2]}}const[$,M]=t.footprint??[t.length*.45,t.length],x=Math.max(0,At(t,o,"lift")),S=Math.max(0,At(t,o,"size"))/(1+x*.8),E=Array.from({length:24},(_,N)=>{const Y=Math.PI*2*N/24;return n.toView([Math.cos(Y)*$*.55*S,0,Math.sin(Y)*M*.55*S])}),P=i.perspective?i.near:void 0,A={points:(P===void 0?E:yp(E,P)).map(_=>n.toScreen(_)),opacity:.16*S},I=v.filter(_=>_.part.seeThrough&&_.opacity>.01).flatMap(_=>_.faces.map(N=>N.points));return{under:k(v.filter(_=>!_.part.overRider)),over:k(v.filter(_=>_.part.overRider)),...y?{cells:y}:{},anchors:T,openings:I,shadow:A,pxPerUnit:s,sizePx:t.height*s}}const $p=new WeakMap;function jS(t){let e=$p.get(t);if(!e){e=new Map;for(let n=0;n<t.faces.length;n++){const s=t.faces[n].corners;for(let i=0;i<s.length;i++){const o=s[i],r=s[(i+1)%s.length],a=o<r?`${o}-${r}`:`${r}-${o}`,l=e.get(a);l?l.push(n):e.set(a,[n])}}$p.set(t,e)}return e}function Ip(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=yc(t,n),i=Xr(fi(t,n))??Ri(),o=r=>Math.max(0,Math.min(1,r));return t.parts.map(r=>{const a=r.fade?o(At(t,n,r.fade.control)):0;return{part:r,matrix:s.get(r.id),local:Ot(i,s.get(r.id)),glow:r.glow?o(At(t,n,r.glow.control)):0,opacity:r.fade?o(r.fade.from+(r.fade.to-r.fade.from)*a):1}})}function Op(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=yc(t,n),i=fi(t,n),o={};for(const[r,a]of Object.entries(t.anchors??{})){const l=a.part?s.get(a.part):i;if(!l)throw new Error(`prop rig: anchor "${r}" is on "${a.part}", which is not a part`);o[r]=Gt(l,a.at)}return o}function XS(t,e){if(!t.walls)return!1;const[n,s]=e.split("-").map(o=>t.vertices[Number(o)]),i=(o,r)=>r.some(a=>Math.abs(n[o]-a)<1e-6&&Math.abs(s[o]-a)<1e-6);return i(0,t.walls.x)||i(2,t.walls.z)}function GS(t){return t.reduce((e,n)=>!e||n.length>e.length?n:e,void 0)}const US=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2];function _p(t){const e=t.map(s=>[...s]),n=[];for(;e.length>0;){const s=[...e.shift()];let i=!0;for(;i;){i=!1;for(let o=0;o<e.length;o++){const[r,a]=e[o],l=s[s.length-1],c=s[0];if(r===l)s.push(a);else if(a===l)s.push(r);else if(a===c)s.unshift(r);else if(r===c)s.unshift(a);else continue;e.splice(o,1),i=!0;break}}n.push(s)}return n}function kc(t,e){if(!t.loose?.size)return;const n={};for(const[s,i]of t.loose)n[s]={x:e[`piece.${i}.x`]??0,y:e[`piece.${i}.y`]??0,rotate:e[`piece.${i}.rotate`]??0,opacity:e[`piece.${i}.opacity`]??1};return n}function vc(t){const e={};for(const[n,s]of Object.entries({...as,...t.rig.controls})){const{bind:i,...o}=s;e[n]=o}return e}function Cp(t){const{prop:e}=t,n=t.scale??60,s=e.rig.length*n*1.4,i=e.rig.height*n*1.6,o=vc(e),r={};for(const[l,c]of Object.entries(o))r[l]=t.values?.[l]??c.default??0;const a={look:t.look,ink:t.ink,lineWidth:t.lineWidth,pencil:t.pencil,seed:t.seed,style:t.style,paper:t.paper};return{type:"custom",x:t.x-s/2,y:t.y-i,width:s,height:i,props:r,prop:e,propScale:n,propDraw:a,about:{kind:e.kind,summary:e.summary,props:o,actions:Object.fromEntries(Object.entries(e.actions).map(([l,c])=>[l,c.summary]))},draw(l,c,h){const u=c.props??{};l.translate(s/2,i),bl(l,ls(e,u,n),{...a,time:h,loose:kc(c,u)})}}}function ls(t,e,n){const s=Ap(At(t.rig,e,"turn"),At(t.rig,e,"tilt"),n);return wc(t.rig,e,s,n)}function or(t,e,n){const s={...t.props};let i=0,o=0;for(const[l,c]of e.state?.values.get(n)??[])typeof c=="number"&&(l==="x"?i=c:l==="y"?o=c:l in s&&(s[l]=c));const r={x:t.x+t.width/2+i,y:t.y+t.height+o},a=ls(t.prop,s,t.propScale);return{values:s,origin:r,solved:a,anchor(l){const c=a.anchors[l];if(!c)throw new Error(`${t.prop.kind}: no anchor "${l}" (it has ${Object.keys(a.anchors).join(", ")||"none"})`);return{x:r.x+c.point.x,y:r.y+c.point.y,depth:c.depth}}}}function VS(t,e,n,s,i={}){const o=or(e,n,s);return t.save(),t.translate(o.origin.x,o.origin.y),bl(t,o.solved,{...e.propDraw,time:n.time,loose:kc(e,o.values),rider:i.rider?r=>{r.save(),r.translate(-o.origin.x,-o.origin.y),i.rider(r),r.restore()}:void 0}),t.restore(),o}const cs={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"}},JS=400,ZS=.2;function QS(t,e={}){const{prop:n}=t,s=vc(n),i=Object.keys(s),o=Object.keys(n.rig.anchors??{}),r=n.rig.parts.map($=>$.id),a=ts(),l=ni(a),c=e.tracks?.length?new It({id:`${n.kind}-surface`,tracks:e.tracks}):void 0,h=Math.max(0,...(e.tracks??[]).flatMap($=>$.keyframes.map(M=>M.time))),u=new Map,d=new Map;t.loose=d;const f=t.props,p=$=>{const M={...t.props};let x=0,S=0;if(c){const E=c.getStateAtTime(Math.min($,h));for(const P of E.values.values())for(const[A,I]of P)typeof I=="number"&&(A==="x"?x=I:A==="y"?S=I:A in M&&(M[A]=I))}for(const E of i)a.keys(E)?.length&&(M[E]=a.valueAt(E,$));return{values:M,origin:{x:t.x+t.width/2+x,y:t.y+t.height+S}}},g=$=>{const{kind:M,rest:x}=mn($),S=E=>Ye(n.kind,$,cs,E);if(M==="box"){if(x)throw S("box takes no arguments");return{kind:M}}if(M==="anchor"){if(!o.includes(x))throw S(ft(`${n.kind} anchor`,x,o));return{kind:M,name:x}}if(M==="part"){if(!r.includes(x))throw S(ft(`${n.kind} part`,x,r));return{kind:M,name:x}}if(M==="control"){if(!i.includes(x))throw S(ft(`${n.kind} control`,x,i));return{kind:M,name:x}}throw S()},m=$=>{const M=(n.rig.controls[$]?.bind??[]).flatMap(S=>S.parts),x=n.rig.parts.filter(S=>S.glow?.control===$).map(S=>S.id);return new Set([...M,...x])},w=new Map,v=$=>{let M=w.get($);if(!M){const x=p($);w.set($,M={...x,solved:ls(n,x.values,t.propScale)})}return M},k=($,M)=>{const x=g($),{values:S,origin:E,solved:P}=v(M);if(x.kind==="box")return Mt(E.x-t.width/2,E.y-t.height,t.width,t.height);if(x.kind==="anchor"){const _=P.anchors[x.name].point,N=ZS*t.propScale;return Mt(E.x+_.x-N/2,E.y+_.y-N/2,N,N)}if(x.kind==="part")return I(new Set([x.name]),`part "${x.name}" is`);const A=m(x.name);if(A.size===0)return Mt(E.x-t.width/2,E.y-t.height,t.width,t.height);return I(A,`the parts control "${x.name}" moves are`);function I(_,N){const Y=[...P.under,...P.over].filter(z=>_.has(z.part.id)).flatMap(z=>z.faces.flatMap(K=>K.points));if(Y.length===0){const z=Number.isFinite(M)?`at ${M} ms`:"after its edits";throw new Error(`${n.kind}: ${N} turned away from the viewer ${z}; aim at an anchor (${o.map(K=>`anchor:${K}`).join(", ")||"none"}) or box`)}const V=Y.map(z=>z.x),tt=Y.map(z=>z.y),X=Math.min(...V),R=Math.min(...tt);return Mt(E.x+X,E.y+R,Math.max(...V)-X,Math.max(...tt)-R)}},y=($,M)=>{try{return k($,M)}catch{return}},T={kind:"prop",prop:t,about:cs,target:t,box:Mt(t.x,t.y,t.width,t.height),anchor($,M=1/0){return k($,M)},piece($){const M=g($);if(M.kind!=="part")throw new Error(`${n.kind}: a piece is a part, part:ID (${r.slice(0,6).map(P=>`part:${P}`).join(", ")}…), not "${$}"`);const x=u.get(M.name);if(x)return x;const S=[M.name];for(let P=0;P<S.length;P++)for(const A of n.rig.parts)A.parent===S[P]&&!S.includes(A.id)&&S.push(A.id);const E={id:u.size+1,part:M.name,home:k($,0)};u.set(M.name,E);for(const P of S)d.set(P,E.id);for(const P of["x","y","rotate"])f[`piece.${E.id}.${P}`]=0;return f[`piece.${E.id}.opacity`]=1,E},edit($,M,x){if(!($ in cs.edits))throw si(n.kind,$,cs);const S=Array.isArray(M)?M:[M];if(S.length===0)throw new Error(`${n.kind}.edit: ${$} takes at least one anchor`);if(w.clear(),$==="move"||$==="fling"){if(S.length>1)throw new Error(`${n.kind}.edit: ${$} takes one part anchor`);const E=T.piece(S[0]);if($==="fling")return T.fling(E,x);const P=x.to;if(!P)throw new Error(`${n.kind}.edit: move needs \`to\`, an anchor name or { x, y }`);const A=typeof P=="string"?k(P,x.at):void 0;return T.move(E,{...x,to:A?{x:A.left+A.width/2,y:A.top+A.height/2}:P})}for(const E of S){const P=g(E);if(P.kind!=="control")throw new Error(`${n.kind}.edit: ${$} takes control anchors (control:${i.join(", control:")}), not "${E}"`);const A=s[P.name];let I;if($==="set"){if(typeof x.value!="number"||!Number.isFinite(x.value))throw new Error(`${n.kind}.edit: set needs \`value\`, a number (${P.name}: ${A.description})`);I=x.value}else I=x.on===!1?A.default??A.min??0:A.max??1;a.tween(P.name,p(x.at).values[P.name],I,x,JS)}return T},follow($,M){return w.clear(),l.follow($,M),T},fling($,M){return w.clear(),l.fling($,M),T},move($,M){return w.clear(),l.move($,M),T},ride($,M,x){const S=[...i.flatMap(P=>es(a.keys(P))),...(e.tracks??[]).flatMap(P=>es(P.keyframes.filter(A=>typeof A.value=="number")))];if(S.length===0)return $;const E=[...o.map(P=>`anchor:${P}`),...r.map(P=>`part:${P}`)].flatMap(P=>{const A=y(P,0);return A?[{top:A.top,offset:I=>(y(P,I)?.top??A.top)-A.top,windows:S}]:[]});return qo($,M,{ground:x.ground,every:x.every??qe,floors:E})},tracks:a.tracks};return T}const t3={body:"#e8574a",trim:"#3b3b44",glass:"#bfe3f2",tyre:"#2c2c33",hub:"#c9ccd3",light:"#fff4b8",tail:"#ff5a4f",inside:"#3b3640",seat:"#6d5d55"};function Ae(t){const e={...t3,...t.colors},n=[],{forwardMost:s,backMost:i,top:o}=Hp(t);t.body&&n.push({id:"body",shape:{type:"extrude",profile:t.body,width:t.width},fill:e.body});for(const[h,u]of(t.frame??[]).entries())n.push({id:`frame-${h}`,shape:{type:"tube",points:u.points,radius:u.radius??.035,segments:6},fill:u.color??e.body,outline:.7});for(const[h,u]of(t.windows??[]).entries())for(const d of[1,-1])n.push({id:`window-${h}-${d>0?"left":"right"}`,shape:{type:"panel",points:[[u.from,u.low],[u.to,u.low],[u.to,u.high],[u.from,u.high]],facing:d>0?"left":"right"},at:[d*(t.width/2+.01),0,0],fill:e.glass,outline:.7,seeThrough:!0,glow:t.lights?{control:"lights",color:"#ffe9a3"}:void 0});for(const h of t.extras??[])n.push(h);if(t.cabin){const h=t.cabin.width??t.width*.85;n.push({id:"cabin",shape:{type:"extrude",profile:t.cabin.profile,width:h},fill:e.glass,outline:.9,seeThrough:!0,layer:1});const u=Math.min(...t.cabin.profile.map(([,f])=>f)),d=Math.max(...t.cabin.profile.map(([,f])=>f));for(const[f,p]of(t.cabin.pillars??[]).entries())n.push({id:`pillar-${f}`,shape:{type:"box",size:[h+.02,d-u,.1]},at:[0,(u+d)/2,p],fill:e.body,outline:.8,layer:1})}const r=t.wheels[0]?.radius??.4,a=[];t.wheels.forEach((h,u)=>{const d=h.side===0?[0]:[1,-1],f=h.thickness??(h.style==="spoked"?.05:.26);for(const p of d){const g=`wheel-${u}-${p>0?"left":p<0?"right":"middle"}`;if(a.push({parts:[g],rotate:{axis:"x",degrees:r/h.radius}}),n.push({id:g,shape:{type:"cylinder",radius:h.radius,length:f,axis:"x",segments:20,spokes:h.style==="spoked"?8:0},at:[p*h.side,h.radius,h.forward],fill:h.style==="spoked"?void 0:e.tyre,ink:h.style==="spoked"?e.tyre:void 0,outline:h.style==="spoked"?1.3:1}),h.style!=="spoked")for(const m of p===0?[1,-1]:[p])n.push({id:`${g}-hub${p===0?m>0?"-left":"-right":""}`,parent:g,shape:{type:"cylinder",radius:h.radius*.55,length:.02,axis:"x",segments:14,spokes:5},at:[m*(f/2+.012),0,0],fill:e.hub,outline:.6})}});const l={wheelSpin:{description:"How far the wheels have turned (keyed exactly with the distance driven, so they never skate)",unit:"degrees",bind:a}};if(t.door){const{from:h,to:u,low:d,high:f}=t.door,p=[[h,d],[u,d],[u,f],[h,f]];for(const g of[1,-1]){const m=g>0?"left":"right";n.push({id:`doorway-${m}`,shape:{type:"panel",points:p,facing:g>0?"left":"right"},at:[g*(t.width/2+.004),0,0],fill:e.inside,outline:.5,seeThrough:!0});const w=h+(u-h)*.15,v=h+(u-h)*.55;n.push({id:`seat-back-${m}`,shape:{type:"panel",points:[[w,d+.05],[v,d+.05],[v-.08,f-.06],[w+.06,f-.04]],facing:g>0?"left":"right"},at:[g*(t.width/2+.006),0,0],fill:e.seat,outline:.4}),n.push({id:`door-${m}`,shape:{type:"panel",points:p.map(([k,y])=>[k-u,y]),facing:g>0?"left":"right"},at:[g*(t.width/2+.01),0,u],fill:e.body,outline:.7,overRider:!0})}l.door={description:"Doors open: 0 shut, 1 open (hinged at the front)",unit:"0..1",min:0,max:1,bind:[{parts:["door-left"],rotate:{axis:"y",degrees:-70}},{parts:["door-right"],rotate:{axis:"y",degrees:70}}]}}if(t.lights){const{across:h,low:u,high:d,front:f,back:p}=t.lights,g=(t.lights.size??.32)/2,m=[[-g,u],[g,u],[g,d],[-g,d]];for(const w of[1,-1])n.push({id:`headlight-${w}`,shape:{type:"panel",points:m,facing:"front"},at:[w*h,0,f],fill:e.light,outline:.6,glow:{control:"lights",color:"#ffffff"}}),n.push({id:`taillight-${w}`,shape:{type:"panel",points:m,facing:"back"},at:[w*h,0,p],fill:No(e.tail,.62),outline:.6,glow:{control:"lights",color:e.tail}});l.lights={description:"Lights on: 0 off, 1 on",unit:"0..1",min:0,max:1}}t.antenna&&(n.push({id:"antenna",shape:{type:"tube",points:[[0,0,0],[0,.75,0]],radius:.018,segments:5},at:t.antenna,fill:e.trim,outline:.6}),n.push({id:"antenna-tip",parent:"antenna",shape:{type:"ellipsoid",radii:[.05,.05,.05],segments:8},at:[0,.77,0],fill:e.tail,outline:.6}),l.antenna={description:"Antenna bend (follow-through: it trails the motion on a spring)",unit:"degrees",bind:[{parts:["antenna"],rotate:{axis:"x",degrees:1}}]});const c={parts:n,controls:l,length:s-i,height:o,footprint:[t.width,s-i],anchors:{...t.seat?{seat:{at:t.seat}}:{},front:{at:[0,o*.45,s]},back:{at:[0,o*.45,i]},roof:{at:[0,o,0]},...t.door?{door:{at:[-t.width/2,(t.door.low+t.door.high)/2,(t.door.from+t.door.to)/2]}}:{},...t.anchors}};return{kind:t.kind??"vehicle",family:"vehicle",summary:t.summary??"A wheeled vehicle",rig:c,actions:e3(t),acting:Rp,colors:{body:e.body,ink:"#26262b"},follow:t.antenna?[{control:"antenna",of:"x",per:.9,stiffness:140,damping:7,limit:35}]:void 0,wheelRadius:r,...t.wheels.length>0?{moves:{drive:{speed:t.speed??6,perMetre:{wheelSpin:180/(Math.PI*r)}}}}:{}}}function Hp(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 Rp={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 rr(t,e,n,s,i,o,r=!1){const a=t.facing()||Math.sign(s-t.x)||1,l=t.values.wheelSpin??0,c=(s-t.x)*a/t.scale;t.set("wheelSpin",e,l),t.move(e,n,s,{easing:i}),t.set("wheelSpin",n,r?l:l+c/o*(180/Math.PI),i)}const Lp=.4;function e3(t){const e=t.wheels[0]?.radius??.4,{forwardMost:n,backMost:s}=Hp(t),i=(n-s)/2,o=(a,l,c)=>{const h=a.exaggeration;let u=l;return a.facing()!==c&&(u=a.turnTo(u,c>0?"right":"left")),a.key(u+200,{pitch:4*h,squash:1-.07*h,lean:-.1*h},{act:!1,easing:"ease-out"}),rr(a,u,u+200,a.x-c*.15*h*a.scale,"ease-out",e),a.effect({kind:"exhaust",time:u+150,x:a.x-c*i*a.scale,y:a.floor-.3*a.scale,length:900,direction:-c}),u+260},r=(a,l,c)=>{const h=a.exaggeration*(c?1.8:1);a.key(l,{pitch:-5*h,lean:-.08*h,squash:.95},{act:!1,easing:"ease-out"}),a.key(l+380,{pitch:0,lean:0,squash:1})};return{drive:{summary:"Drives to `to`: rocks back and squats, lunges forward stretched, and stops with a nose-dive that settles; wheels roll exactly the distance.",needs:["to"],uses:["speed","for"],run(a,l,c){const h=Math.sign(l.to-a.x);if(h===0)return{end:c};const u=o(a,c,h),d=a.exaggeration,f=Math.abs(l.to-a.x),p=l.for??Math.max(500,f/(l.speed??Lp));return a.effect({kind:"dust",time:u,x:a.x-h*i*a.scale,y:a.floor,length:600,direction:-h}),a.key(u+140,{pitch:-1.5*d,squash:1+.05*d,lean:.12*d},{act:!1,easing:"ease-out"}),a.key(u+Math.max(160,p-160),{pitch:0,lean:.08*d,squash:1.02},{act:!1}),rr(a,u,u+p,l.to,"ease-in-out",e),r(a,u+p,!1),{end:u+p+380,contact:u,release:u+p}}},brake:{summary:"Drives toward `to` and slams on the brakes: the wheels lock and it skids the last stretch, nose diving, leaving skid marks.",needs:["to"],uses:["speed","for"],run(a,l,c){const h=Math.sign(l.to-a.x);if(h===0)return{end:c};const u=o(a,c,h),d=a.exaggeration,f=a.x,p=Math.abs(l.to-f),g=l.for??Math.max(600,p/(l.speed??Lp*1.2)),m=u+g*.55,w=f+(l.to-f)*.65;return a.key(u+140,{pitch:-1.5*d,squash:1+.06*d,lean:.14*d},{act:!1,easing:"ease-out"}),rr(a,u,m,w,"ease-in",e),a.key(m+80,{pitch:-7*d,lean:-.12*d,squash:.94},{act:!1,easing:"ease-out"}),rr(a,m,u+g,l.to,"ease-out",e,!0),a.effect({kind:"skid",time:m,x:w,toX:l.to,y:a.floor,length:g*.45+1500}),a.effect({kind:"dust",time:u+g,x:l.to+h*i*a.scale,y:a.floor,length:600,direction:h}),r(a,u+g,!0),{end:u+g+380,contact:m,release:u+g}}},bump:{summary:"Hits a bump: squashes, hops up stretched, lands squashed with dust, and springs back.",uses:["for"],run(a,l,c){const h=a.exaggeration;return a.key(c+90,{squash:1-.16*h,pitch:3*h},{act:!1,easing:"ease-out"}),a.key(c+300,{lift:.35*h,squash:1+.12*h,pitch:-3*h},{act:!1,easing:"ease-out"}),a.key(c+540,{lift:0,squash:1-.2*h,pitch:0},{act:!1,easing:"ease-in"}),a.key(c+820,{squash:1}),a.effect({kind:"dust",time:c+540,x:a.x,y:a.floor,length:500}),{end:c+820,contact:c+540}}},honk:{summary:"Honks: a stretch and squash pulse, with honk lines from the front.",run(a,l,c){const h=a.exaggeration;a.key(c+110,{squash:1+.12*h,lean:.04*h},{act:!1,easing:"ease-out"}),a.key(c+240,{squash:1-.06*h,lean:0},{act:!1}),a.key(c+520,{squash:1});const u=a.facing();return a.effect({kind:"honk",time:c+60,x:a.x+(u||1)*i*a.scale,y:a.floor-.7*a.scale,length:700,direction:u||1}),{end:c+520,contact:c+60}}},...t.door?{door:{summary:"Opens the doors (`open: true`) or shuts them (`open: false`).",needs:["open"],run(a,l,c){return a.key(c+450,{door:l.open?1:0}),{end:c+600,contact:c+450}}}}:{},...t.lights?{lights:{summary:"Switches the lights on (`on: true`) or off.",needs:["on"],run(a,l,c){return a.key(c+120,{lights:l.on?1:0},{act:!1}),{end:c+300,contact:c+120}}}}:{}}}function Np(t={}){return Ae({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 Fp(t={}){return Ae({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 Wp(t={}){return Ae({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 Dp(t={}){return Ae({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 Bp(t={}){const e=t.colors?.body??"#a8743f";return Ae({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 zp(t={}){return Ae({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 qp(t={}){const e=t.colors?.body??"#e0473b",n=[0,.32,-.05],s=[0,.86,-.22],i=[0,.9,.42],o=[0,.34,.56],r=[0,.34,-.56];return Ae({kind:"bike",summary:"A bicycle: rides (drive) with its wire wheels turning, brakes, bumps, rings its bell (honk).",width:.5,frame:[{points:[r,n]},{points:[n,s]},{points:[s,r]},{points:[s,i]},{points:[n,i]},{points:[i,o]},{points:[[.24,.98,.44],[-.24,.98,.44]],radius:.025,color:"#3b3b44"},{points:[i,[0,.98,.44]],radius:.025,color:"#3b3b44"}],extras:[{id:"saddle",shape:{type:"ellipsoid",radii:[.08,.035,.15],segments:10},at:[0,.89,-.22],fill:"#3b3b44",outline:.7}],wheels:[{forward:.56,side:0,radius:.34,style:"spoked"},{forward:-.56,side:0,radius:.34,style:"spoked"}],seat:[0,.9,-.22],colors:{body:e,tyre:"#2c2c33",...t.colors}})}function Yp(t={}){return Ae({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 Kp(t={}){const e=t.height??2.4,n=t.trunkRadius??.16,s=t.canopy?.radius??1.1,i=t.canopy?.shape==="tall",o={trunk:"#8a5a3b",leaves:"#5cae5a",...t.colors},r=He(t.canopy?.seed??7),a=[{id:"trunk",shape:{type:"tube",points:[[0,0,0],[.06,e*.5,0],[-.02,e,0]],radius:n,segments:8},fill:o.trunk},{id:"branch",parent:"trunk",shape:{type:"tube",points:[[0,0,0],[.45,.4,.1]],radius:n*.45,segments:6},at:[.04,e*.62,0],fill:o.trunk},{id:"canopy",parent:"trunk",shape:{type:"ellipsoid",radii:[s,s*(i?1.35:.88),s],segments:14},at:[-.02,e+s*.55,0],fill:o.leaves}],l=t.canopy?.lobes??7;for(let h=0;h<l;h++){const u=Math.PI*2*h/l+r.next()*.6,d=(r.next()-.25)*s*(i?1.1:.7),f=s*(.48+r.next()*.22),p=[Math.cos(u)*s*.78,d,Math.sin(u)*s*.6];a.push({id:`lobe-${h}`,parent:"canopy",shape:{type:"ellipsoid",radii:[f,f*.86,f],segments:12},at:p,fill:o.leaves})}const c={parts:a,controls:{sway:{description:"The whole tree bending in the wind, about its base",unit:"degrees",bind:[{parts:["trunk"],rotate:{axis:"z",degrees:1}}]},canopySway:{description:"The canopy bending further than the trunk (it trails the sway)",unit:"degrees",bind:[{parts:["canopy"],rotate:{axis:"z",degrees:1,pivot:[0,-s*.8,0]}}]}},length:s*2.2,height:e+s*2,footprint:[s*1.6,s*1.6],anchors:{canopy:{part:"canopy",at:[0,0,0]},top:{part:"canopy",at:[0,s*.9,0]},base:{at:[0,0,0]},branch:{part:"branch",at:[.45,.4,.1]}}};return{kind:t.kind??"tree",family:"plant",summary:t.summary??"A tree: sways in the wind with its canopy trailing, shakes, sheds leaves, pops up.",rig:c,actions:n3(),acting:jp,colors:{body:o.leaves}}}const jp={depth:{sway:1,canopySway:2,size:0,squash:1},limits:{sway:2,canopySway:3,squash:.08},eyes:[],headTurns:{},drift:[]};function n3(){const t=(e,n,s,i)=>{const o=e.anchor("canopy");e.effect({kind:"leaves",time:n,x:o.x,y:o.y,length:s,direction:i,toY:e.floor})};return{sway:{summary:"Sways in gusts of `wind` (0..1, default 0.5) for `for` ms (default 3000); the canopy trails the trunk, and a strong wind sheds leaves.",uses:["wind","for"],run(e,n,s){const i=n.wind??.5,o=n.for??3e3,r=e.exaggeration,a=260;let l=0;for(let c=a;c<o;c+=a){const h=.55+.45*Math.sin(c/o*Math.PI*2.3),u=Math.sin(c/170)*.35,d=-i*9*r*(h+u*i);e.key(s+c,{sway:d,canopySway:l*1.3},{act:!1,easing:"ease-in-out"}),l=d}if(e.key(s+o,{sway:0,canopySway:0}),i>.45)for(let c=0;c<o;c+=700)t(e,s+c,2200,1);return{end:s+o}}},shake:{summary:"Shakes (something hit it): a quick wobble that dies away, shedding leaves.",uses:["for"],run(e,n,s){const i=n.for??900,o=e.exaggeration,r=6;for(let a=1;a<=r;a++){const l=1-a/(r+1),c=a%2===0?1:-1;e.key(s+i*a/(r+1),{sway:c*5*o*l,canopySway:-c*6*o*l},{act:!1,easing:"ease-in-out"})}return e.key(s+i,{sway:0,canopySway:0}),t(e,s+60,1800,1),t(e,s+260,1800,-1),{end:s+i,contact:s}}},shedLeaves:{summary:"Leaves fall from the canopy for `for` ms (default 2000).",uses:["for"],run(e,n,s){const i=n.for??2e3;for(let o=0;o<i;o+=500)t(e,s+o,2e3,o%1e3===0?1:-1);return{end:s+i}}}}}function Xp(t={}){const e=t.width??4,n=t.depth??3.2,s=t.wallHeight??2.5,i=t.roofHeight??1.5,o=t.overhang??.25,r={walls:"#f1d9a8",roof:"#b8433a",door:"#7a4b2a",doorway:"#3a2a22",glass:"#bfe3f2",lit:"#ffd66b",chimney:"#9b5a45",...t.colors},a=n/2+.01,l=t.door?.width??.9,c=t.door?.height??1.9,h=t.door?.at??0,u=t.windows??[{at:-1.25,low:1,width:.8,height:.8},{at:1.25,low:1,width:.8,height:.8}],d=[{id:"walls",shape:{type:"box",size:[e,s,n]},at:[0,s/2,0],fill:r.walls},{id:"roof",shape:{type:"extrude",profile:[[-n/2-o,s],[n/2+o,s],[0,s+i]],width:e+o*2},fill:r.roof,layer:1},{id:"doorway",shape:{type:"panel",points:[[0,0],[l,0],[l,c],[0,c]],facing:"front"},at:[h-l/2,0,a-.005],fill:r.doorway,outline:.6,seeThrough:!0},{id:"door",shape:{type:"panel",points:[[0,0],[l,0],[l,c],[0,c]],facing:"front"},at:[h-l/2,0,a+.005],fill:r.door,outline:.8,overRider:!0}];u.forEach((g,m)=>{d.push({id:`window-${m}`,shape:{type:"panel",points:[[-g.width/2,g.low],[g.width/2,g.low],[g.width/2,g.low+g.height],[-g.width/2,g.low+g.height]],facing:"front"},at:[g.at,0,a+.01],fill:r.glass,outline:.8,glow:{control:"lights",color:r.lit}})});for(const g of[1,-1])d.push({id:`side-window-${g>0?"left":"right"}`,shape:{type:"panel",points:[[-.4,1],[.4,1],[.4,1.8],[-.4,1.8]],facing:g>0?"left":"right"},at:[g*(e/2+.01),0,0],fill:r.glass,outline:.8,glow:{control:"lights",color:r.lit}});const f=t.chimney===!1?void 0:{at:t.chimney?.at??e*.28,back:t.chimney?.back??-n*.18};if(f){const g=s+i*(1-Math.abs(f.back)/(n/2+o)),m=s+i+.45;d.push({id:"chimney",shape:{type:"box",size:[.42,m-g+.3,.42]},at:[f.at,(m+g-.3)/2,f.back],fill:r.chimney,layer:1})}const p={parts:d,controls:{door:{description:"The front door open: 0 shut, 1 open",unit:"0..1",min:0,max:1,bind:[{parts:["door"],rotate:{axis:"y",degrees:-80}}]},lights:{description:"The windows lit: 0 dark, 1 lit",unit:"0..1",min:0,max:1}},length:n+o*2,height:s+i+.6,footprint:[e+.6,n+.6],anchors:{door:{at:[h,c/2,a]},doorstep:{at:[h,0,a+.4]},ridge:{at:[0,s+i,0]},...f?{chimney:{at:[f.at,s+i+.5,f.back]}}:{}}};return{kind:t.kind??"house",family:"building",summary:t.summary??"A house: opens its door, lights its windows, puffs chimney smoke, shakes, pops up.",rig:p,actions:s3(!!f),acting:Gp,colors:{body:r.walls}}}const Gp={depth:{door:1,lights:0,roll:1,squash:1,size:0},limits:{door:.1,roll:1.5,squash:.05},eyes:[],headTurns:{},drift:[]};function s3(t){return{door:{summary:"Opens the front door (`open: true`) or shuts it (`open: false`).",needs:["open"],run(e,n,s){return e.key(s+500,{door:n.open?1:0}),{end:s+650,contact:s+500}}},lights:{summary:"Lights the windows (`on: true`) or puts them out.",needs:["on"],run(e,n,s){return e.key(s+150,{lights:n.on?1:0},{act:!1}),{end:s+300,contact:s+150}}},shake:{summary:"Shakes, as when a door slams or something lands on it: a squash and a wobble that dies away, with dust.",uses:["for"],run(e,n,s){const i=n.for??700,o=e.exaggeration;e.key(s+80,{squash:1-.06*o},{act:!1,easing:"ease-out"});for(let r=1;r<=5;r++){const a=1-r/6;e.key(s+80+i*r/6,{roll:(r%2===0?1:-1)*2.2*o*a,squash:1+.02*a},{act:!1,easing:"ease-in-out"})}return e.key(s+i+80,{roll:0,squash:1}),e.effect({kind:"dust",time:s+80,x:e.x,y:e.floor,length:600}),{end:s+i+80,contact:s+80}}},...t?{smoke:{summary:"Starts smoke puffing from the chimney for `for` ms (default 3000), drifting with the wind; the next beat starts at once (the smoke carries on).",uses:["for","wind"],run(e,n,s){const i=n.for??3e3,o=e.anchor("chimney");return e.effect({kind:"smoke",time:s,x:o.x,y:o.y,length:i+1500,direction:(n.wind??.4)>=0?1:-1}),{end:s+50,release:s+i}}}}:{}}}function Up(t={}){const e=t.width??.46,n=t.depth??.46,s=t.seatHeight??.46,i=t.backHeight??.95,o={wood:"#8a5a3b",seat:"#c48a4a",...t.colors},r=.05,a=.025,l=[{id:"seat",shape:{type:"box",size:[e,r,n]},at:[0,s-r/2,0],fill:o.seat},{id:"back",shape:{type:"box",size:[e,i-s,r]},at:[0,(i+s)/2,-n/2+r/2],fill:o.wood}];for(const[h,u,d]of[[-1,1,"front-left"],[1,1,"front-right"],[-1,-1,"back-left"],[1,-1,"back-right"]])l.push({id:`leg-${d}`,shape:{type:"tube",points:[[0,0,0],[0,s-r,0]],radius:a,segments:6},at:[h*(e/2-a*1.5),0,u*(n/2-a*1.5)],fill:o.wood});const c={parts:l,controls:{tip:{description:"Tipped back on its rear legs (+), degrees",unit:"degrees",min:0,max:60,bind:[{parts:l.map(h=>h.id),rotate:{axis:"x",degrees:1,pivot:[0,0,-n/2+a*1.5]}}]}},length:n,height:i,footprint:[e,n],anchors:{seat:{at:[0,s,0]},back:{at:[0,i,-n/2]},front:{at:[0,0,n/2+.3]}}};return{kind:t.kind??"chair",family:"furniture",summary:t.summary??"A chair: a seat to sit on (`seat`), tips back on its rear legs and settles, or falls over.",rig:c,actions:i3(),acting:Vp,colors:{body:o.seat}}}const Vp={depth:{tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.05},eyes:[],headTurns:{},drift:[]};function i3(){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 Jp(t={}){const e=t.width??1.4,n=t.depth??.7,s=t.height??.75,i={wood:"#8a5a3b",top:"#a9754a",knob:"#2b2b2b",...t.colors},o=.04,r=.03,a=.14,l=e*.4,c=[{id:"top",shape:{type:"box",size:[e,o,n]},at:[0,s-o/2,0],fill:i.top},{id:"drawer",shape:{type:"box",size:[l,a,n*.8]},at:[-e/2+l/2+.05,s-o-a/2,0],fill:i.wood},{id:"knob",parent:"drawer",shape:{type:"ellipsoid",radii:[.02,.02,.015],segments:8},at:[0,0,n*.4+.012],fill:i.knob,outline:.6}];for(const[u,d,f]of[[-1,1,"front-left"],[1,1,"front-right"],[-1,-1,"back-left"],[1,-1,"back-right"]])c.push({id:`leg-${f}`,shape:{type:"tube",points:[[0,0,0],[0,s-o,0]],radius:r,segments:6},at:[u*(e/2-r*2),0,d*(n/2-r*2)],fill:i.wood});const h={parts:c,controls:{drawer:{description:"The drawer out: 0 shut, 1 open",unit:"0..1",min:0,max:1,bind:[{parts:["drawer"],translate:[0,0,n*.5]}]}},length:n,height:s,footprint:[e,n],anchors:{top:{at:[0,s,0]},edge:{at:[0,s,n/2]},drawer:{part:"drawer",at:[0,0,n*.4]},chair:{at:[0,0,n/2+.35]}}};return{kind:t.kind??"desk",family:"furniture",summary:t.summary??"A desk: a top to work at (`top`, `edge`), a drawer that opens (`drawer`), a place for a chair in front (`chair`).",rig:h,actions:{drawer:{summary:"Opens the drawer (`open: true`) or shuts it (`open: false`).",needs:["open"],run(u,d,f){return u.key(f+400,{drawer:d.open?1:0},{easing:d.open?"ease-out":"ease-in"}),{end:f+500,contact:f+400}}}},acting:Zp,colors:{body:i.top}}}const Zp={depth:{drawer:1,roll:1,squash:1,size:0},limits:{drawer:.08,roll:1,squash:.04},eyes:[],headTurns:{},drift:[]};function Qp(t={}){const e=t.length??2,n=t.width??1,s=t.height??.55,i=t.headboard??.95,o={wood:"#8a5a3b",mattress:"#f1ece2",blanket:"#5b7fb0",pillow:"#fbf8f2",...t.colors},r=.3,a=s-r,c={parts:[{id:"frame",shape:{type:"box",size:[n,r,e]},at:[0,r/2,0],fill:o.wood},{id:"headboard",shape:{type:"box",size:[n+.06,i-r,.06]},at:[0,(i+r)/2,-e/2-.03],fill:o.wood},{id:"mattress",shape:{type:"box",size:[n-.04,a,e-.04]},at:[0,r+a/2,0],fill:o.mattress},{id:"blanket",parent:"mattress",shape:{type:"box",size:[n-.02,.04,e*.62]},at:[0,a/2+.02,e*.19],fill:o.blanket,outline:.7},{id:"pillow",parent:"mattress",shape:{type:"ellipsoid",radii:[n*.32,.07,.22],segments:12},at:[0,a/2+.06,-e/2+.32],fill:o.pillow,outline:.7}],controls:{give:{description:"The mattress pressed down: 1 as made, below squashed (someone landed on it)",unit:"factor",default:1,min:.5,max:1.2,bind:[{parts:["mattress"],scale:[1,1,1]}]}},length:e,height:i,footprint:[n,e],anchors:{mattress:{part:"mattress",at:[0,a/2,0]},pillow:{part:"mattress",at:[0,a/2+.1,-e/2+.32]},foot:{at:[0,s,e/2]},side:{at:[n/2+.25,0,0]}}};return{kind:t.kind??"bed",family:"furniture",summary:t.summary??"A bed: a mattress to lie on (`mattress`, `pillow`) that gives and springs back when someone lands on it (`bounce`), a side to sit on (`side`).",rig:c,actions:{bounce:{summary:"The mattress gives (someone landed on it) and springs back over `for` ms (default 700).",uses:["for"],run(h,u,d){const f=u.for??700,p=h.exaggeration;return h.key(d+90,{give:1-.18*p},{act:!1,easing:"ease-out"}),h.key(d+f*.45,{give:1+.05*p},{act:!1,easing:"ease-in-out"}),h.key(d+f*.7,{give:1-.04*p},{act:!1,easing:"ease-in-out"}),h.key(d+f,{give:1}),{end:d+f,contact:d+90}}}},acting:tm,colors:{body:o.blanket}}}const tm={depth:{give:1,roll:1,squash:1,size:0},limits:{give:.03,roll:.5,squash:.03},eyes:[],headTurns:{},drift:[]};function em(t={}){const e=t.width??.9,n=t.height??2.05,s=t.hinge??"left",i={frame:"#d9d2c3",door:"#7a4b2a",handle:"#c9a227",beyond:"#2a2f3a",...t.colors},o=.1,r=s==="left"?1:-1,a=r>0?[[0,0],[-e,0],[-e,n],[0,n]]:[[0,0],[e,0],[e,n],[0,n]],c={parts:[{id:"post-left",shape:{type:"box",size:[o,n+o,o]},at:[e/2+o/2,(n+o)/2,0],fill:i.frame},{id:"post-right",shape:{type:"box",size:[o,n+o,o]},at:[-e/2-o/2,(n+o)/2,0],fill:i.frame},{id:"lintel",shape:{type:"box",size:[e+o*2,o,o]},at:[0,n+o/2,0],fill:i.frame},{id:"beyond",shape:{type:"panel",points:[[-e/2,0],[e/2,0],[e/2,n],[-e/2,n]],facing:"front"},at:[0,0,-.03],fill:i.beyond,outline:.4,seeThrough:!0},{id:"door",shape:{type:"panel",points:a,facing:"front"},at:[r*e/2,0,.005],fill:i.door,outline:.9,overRider:!0},{id:"handle",parent:"door",shape:{type:"ellipsoid",radii:[.03,.03,.03],segments:8},at:[-r*(e-.1),n*.47,.03],fill:i.handle,outline:.5}],controls:{open:{description:"How far the door is open: 0 shut, 1 open wide",unit:"0..1",min:0,max:1,bind:[{parts:["door"],rotate:{axis:"y",degrees:r*-95}}]}},length:.3,height:n+o,footprint:[e+o*2,.3],anchors:{handle:{part:"door",at:[-r*(e-.1),n*.47,.03]},doorway:{at:[0,0,0]},front:{at:[0,0,.5]},beyond:{at:[0,0,-.5]}}};return{kind:t.kind??"door",family:"furniture",summary:t.summary??"A door in its frame: opens and shuts on its hinge (`open`), slams, rattles when knocked; a figure goes through the `doorway` from `front` to `beyond`.",rig:c,actions:o3(),acting:nm,colors:{body:i.door}}}const nm={depth:{open:1,roll:1,squash:1,size:0},limits:{open:.08,roll:.6,squash:.03},eyes:[],headTurns:{},drift:[]};function o3(){return{open:{summary:"Opens the door (`open: true`, default) or shuts it (`open: false`), over `for` ms (default 600).",uses:["open","for"],run(t,e,n){const s=e.for??600;return t.key(n+s,{open:e.open===!1?0:1},{easing:"ease-in-out"}),{end:n+s+80,contact:n+s}}},slam:{summary:"Slams shut: a fast swing, a shudder in the frame, dust.",run(t,e,n){const s=t.exaggeration;t.key(n+180,{open:0},{act:!1,easing:"ease-in"});for(let i=1;i<=4;i++)t.key(n+180+i*70,{roll:(i%2===0?1:-1)*1.2*s*(1-i/5)},{act:!1});return t.key(n+180+350,{roll:0}),t.effect({kind:"dust",time:n+180,x:t.x,y:t.floor,length:500}),{end:n+180+350,contact:n+180}}},knock:{summary:"Someone knocks three times: the door rattles over `for` ms (default 700).",uses:["for"],run(t,e,n){const i=e.for??700,o=t.exaggeration;for(let r=0;r<3;r++){const a=n+i*(r+.5)/3;t.key(a,{open:.03*o},{act:!1,easing:"ease-out"}),t.key(a+60,{open:0},{act:!1,easing:"ease-in"})}return{end:n+i,contact:n+i/6}}}}}const sm=1.4;function im(t={}){const e=t.width??.5,n=t.seatHeight??.5,s=t.wheelRadius??.3,i=.08,o={frame:"#2b2f36",seat:"#3c6ea5",tyre:"#1f2328",...t.colors},r=.04,a=.018,l=.44,c=n+.5,h=-.08,u=e/2+.06,d=[{id:"seat",shape:{type:"box",size:[e,r,l]},at:[0,n-r/2,0],fill:o.seat},{id:"back",shape:{type:"box",size:[e,c-n-.02,r]},at:[0,(c+n)/2,-l/2+r/2],fill:o.seat},{id:"footrest",shape:{type:"box",size:[e*.8,.02,.14]},at:[0,.12,l/2+.22],fill:o.frame}];for(const[g,m]of[[-1,"left"],[1,"right"]]){const w=g*u,v=(k,y,T=a)=>{d.push({id:k,shape:{type:"tube",points:y,radius:T,segments:6},fill:o.frame,outline:.7})};v(`post-${m}`,[[w,n-.1,-l/2],[w,c+.04,-l/2],[w,c+.04,-l/2-.14]]),v(`rail-${m}`,[[w,n-.03,-l/2],[w,n-.03,l/2]]),v(`leg-${m}`,[[w,n-.03,l/2],[w*.85,i,l/2+.06]]),v(`strut-${m}`,[[w*.85,i+.08,l/2+.04],[w*.8,.13,l/2+.22]]),v(`armrest-${m}`,[[w,n+.22,-l/2+.02],[w,n+.22,l/2-.08]],a*1.3),d.push({id:`wheel-${m}`,shape:{type:"cylinder",radius:s,length:.04,axis:"x",segments:20,spokes:8},at:[w+g*.03,s,h],ink:o.tyre,outline:1.3}),d.push({id:`rim-${m}`,shape:{type:"cylinder",radius:s*.9,length:.012,axis:"x",segments:20},at:[g*.045,0,0],parent:`wheel-${m}`,ink:o.frame,outline:.8}),d.push({id:`castor-${m}`,shape:{type:"cylinder",radius:i,length:.03,axis:"x",segments:12,spokes:3},at:[w*.85,i,l/2+.06],fill:o.tyre})}const f=d.map(g=>g.id).filter(g=>!g.startsWith("rim-")),p={parts:d,controls:{wheelSpin:{description:"How far the big wheels have turned, degrees (keyed with the distance rolled, so they never skate); the castors turn faster",unit:"degrees",bind:[{parts:["wheel-left","wheel-right"],rotate:{axis:"x",degrees:1}},{parts:["castor-left","castor-right"],rotate:{axis:"x",degrees:s/i}}]},tip:{description:"Tipped back on its big wheels (+), degrees: a wheelie, or a helper tipping it up a kerb",unit:"degrees",min:0,max:45,bind:[{parts:f,rotate:{axis:"x",degrees:1,pivot:[0,s,h]}}]}},length:l+.4,height:c+.04,footprint:[u*2+.1,l+.4],anchors:{seat:{at:[0,n,.02]},handles:{at:[0,0,-l/2-.5]},front:{at:[0,0,l/2+.6]},footrest:{at:[0,.13,l/2+.22]}}};return{kind:t.kind??"wheelchair",family:"furniture",summary:t.summary??"A wheelchair: rolls to `to` with its wheels turning the distance (roll), brakes, tips back on its big wheels (wheelie); its `seat` is ridden in the `wheeling` pose and a pusher stands at `handles`.",rig:p,actions:r3(s),acting:om,colors:{body:o.seat,ink:o.frame},wheelRadius:s,moves:{roll:{speed:sm,perMetre:{wheelSpin:180/(Math.PI*s)}}}}}const om={depth:{wheelSpin:0,tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.03},eyes:[],headTurns:{},drift:[]};function rm(t,e,n,s,i,o,r=!1){const a=t.facing()||Math.sign(s-t.x)||1,l=t.values.wheelSpin??0,c=(s-t.x)*a/t.scale;t.set("wheelSpin",e,l),t.move(e,n,s,{easing:i}),t.set("wheelSpin",n,r?l:l+c/o*(180/Math.PI),i)}function r3(t){return{roll:{summary:"Rolls to `to` at `speed` px/ms (or over `for` ms): a small push-off, the wheels turning exactly the distance, and a gentle stop.",needs:["to"],uses:["speed","for"],run(e,n,s){const i=Math.sign(n.to-e.x);if(i===0)return{end:s};let o=s;e.facing()!==i&&(o=e.turnTo(o,i>0?"right":"left"));const r=Math.abs(n.to-e.x),a=n.for??Math.max(300,r/(n.speed??sm*e.scale/1e3));return e.key(o+150,{tip:1.5*e.exaggeration},{act:!1,easing:"ease-out"}),rm(e,o,o+a,n.to,"ease-in-out",t),e.key(o+a,{tip:0},{easing:"ease-out"}),{end:o+a}}},brake:{summary:"Stops short at `to`: the wheels lock and it skids the last bit, tipping forward a touch.",needs:["to"],uses:["for"],run(e,n,s){if(Math.sign(n.to-e.x)===0)return{end:s};const o=n.for??500;return rm(e,s,s+o,n.to,"ease-out",t,!0),e.key(s+o,{tip:0},{easing:"ease-out"}),e.effect({kind:"dust",time:s+o*.5,x:n.to,y:e.floor,length:500}),{end:s+o,contact:s+o}}},wheelie:{summary:"Tips back onto its big wheels, balances there for `for` ms (default 1200), and drops down.",uses:["for"],run(e,n,s){const i=24*e.exaggeration,o=n.for??1200;return e.key(s+300,{tip:i},{easing:"ease-out"}),e.key(s+300+o*.5,{tip:i*.9},{act:!1,easing:"ease-in-out"}),e.key(s+300+o,{tip:i},{act:!1,easing:"ease-in-out"}),e.key(s+300+o+250,{tip:0},{easing:"ease-in"}),e.effect({kind:"dust",time:s+300+o+250,x:e.x,y:e.floor,length:400}),{end:s+300+o+250,contact:s+300+o+250}}}}}function am(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:a3(),acting:Mc,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:15,flies:!0,hold:{blur:1},perSecond:{rotor:je*1e3}}}}}const Mc={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:[]},je=2.6;function a3(){const t=(n,s,i,o,r)=>{const a=n.values.rotor??0;n.set("rotor",s,a);const l=r?o*(i-s)*.5:o*(i-s);n.set("rotor",i,a+l,r)},e=n=>n.values.lift>.05;return{takeOff:{summary:"Spools the rotor up (the skids squash as it bites), then lifts off nose-down to `height` metres (default 3).",uses:["height"],run(n,s,i){const o=n.exaggeration,r=s.height??3;t(n,i,i+900,je,"ease-in"),n.key(i+900,{blur:1},{act:!1,easing:"ease-in"}),n.key(i+700,{squash:1-.08*o},{act:!1,easing:"ease-in"});const a=i+1e3;return n.key(a+150,{squash:1+.06*o,lift:.3},{act:!1,easing:"ease-out"}),n.key(a+1300,{squash:1,lift:r,pitch:-4*o},{act:!1,easing:"ease-in-out"}),n.key(a+1700,{pitch:0}),t(n,i+900,a+1700,je),n.effect({kind:"dust",time:a,x:n.x,y:n.floor,length:900}),{end:a+1700,contact:a}}},fly:{summary:"Flies to `to` (and to `height`, if given): nose down and banked into the move, nose up and leveling as it stops.",needs:["to"],uses:["height","speed","for"],run(n,s,i){const o=n.exaggeration,r=Math.sign(s.to-n.x);let a=i;r!==0&&n.facing()!==r&&(a=n.turnTo(a,r>0?"right":"left"));const l=Math.abs(s.to-n.x),c=s.for??Math.max(700,l/(s.speed??.3)),h=s.height??n.values.lift;return n.key(a+300,{pitch:-9*o,roll:6*o},{act:!1,easing:"ease-out"}),n.key(a+c-250,{pitch:-4*o,roll:3*o,lift:h},{act:!1}),n.key(a+c,{pitch:7*o,roll:0},{act:!1,easing:"ease-out"}),n.key(a+c+450,{pitch:0}),n.move(a,a+c,s.to,{easing:"ease-in-out"}),t(n,i,a+c+450,je),{end:a+c+450,contact:a,release:a+c}}},hover:{summary:"Hovers in place for `for` ms (default 2000), bobbing gently.",uses:["for"],run(n,s,i){const o=s.for??2e3,r=n.values.lift,a=n.exaggeration;for(let l=350,c=0;l<o;l+=350,c++)n.key(i+l,{lift:r+(c%2===0?.12:-.06)*a,roll:(c%2===0?1.5:-1.5)*a},{act:!1,easing:"ease-in-out"});return n.key(i+o,{lift:r,roll:0},{act:!1,easing:"ease-in-out"}),(e(n)||r>0)&&t(n,i,i+o,je),{end:i+o}}},land:{summary:"Settles down onto its skids: a flare, a squash on touchdown with dust, and the rotor spools down.",run(n,s,i){const o=n.exaggeration,r=i+Math.max(900,n.values.lift*450);return n.key(i+400,{pitch:3*o},{act:!1,easing:"ease-out"}),n.key(r,{lift:0,pitch:0,squash:1-.14*o},{act:!1,easing:"ease-in"}),n.key(r+280,{squash:1}),t(n,i,r,je),t(n,r,r+1600,je,"ease-out"),n.key(r+1600,{blur:0},{act:!1,easing:"ease-out"}),n.effect({kind:"dust",time:r,x:n.x,y:n.floor,length:800}),{end:r+1600,contact:r}}}}}function lm(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:c3(),acting:Mc,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:30,flies:!0,hold:{blur:1},perSecond:{rotor:je*1e3}}}}}const l3=3.2;function c3(){const t=(n,s,i,o)=>{const r=n.values.rotor??0;n.set("rotor",s,r),n.set("rotor",i,r+l3*(i-s)*(o?.5:1),o)},e=(n,s,i)=>{const o=Math.sign(i-n.x);return o!==0&&n.facing()!==o?n.turnTo(s,o>0?"right":"left"):s};return{takeOff:{summary:"Spins the propeller up, runs along the ground toward `to`, lifts its nose and climbs to `height` metres (default 4).",needs:["to"],uses:["height","for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to);t(n,r,r+700,"ease-in"),n.key(r+700,{blur:1},{act:!1,easing:"ease-in"});const a=s.for??2600,l=n.x,c=r+700+a*.55,h=l+(s.to-l)*.45;return n.move(r+700,c,h,{easing:"ease-in"}),n.key(c,{pitch:8*o,squash:1+.04*o},{act:!1,easing:"ease-out"}),n.key(r+700+a,{lift:s.height??4,pitch:10*o,squash:1},{act:!1,easing:"ease-in-out"}),n.move(c,r+700+a,s.to),n.key(r+700+a+500,{pitch:0}),t(n,r+700,r+700+a+500),n.effect({kind:"dust",time:c,x:h,y:n.floor,length:700}),{end:r+700+a+500,contact:c}}},fly:{summary:"Flies to `to` (and `height`), banking into the move and leveling out.",needs:["to"],uses:["height","speed","for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to),a=s.for??Math.max(800,Math.abs(s.to-n.x)/(s.speed??.45)),l=s.height??n.values.lift;return n.key(r+350,{roll:10*o,pitch:l>n.values.lift?6*o:-3*o},{act:!1,easing:"ease-out"}),n.key(r+a-300,{roll:4*o,lift:l},{act:!1}),n.key(r+a,{roll:0,pitch:0}),n.move(r,r+a,s.to,{easing:"ease-in-out"}),t(n,i,r+a),{end:r+a,contact:r,release:r+a}}},loop:{summary:"Loops the loop: pulls up and over in a full circle (`for` ms, default 2400), carrying on the way it was going.",uses:["for"],run(n,s,i){const o=s.for??2400,r=2.2*n.exaggeration,a=n.facing()||1,l=16,c=n.x,h=n.values.lift,u=n.values.pitch;for(let d=1;d<=l;d++){const f=Math.PI*2*d/l,p=i+o*d/l;n.key(p,{lift:h+r*(1-Math.cos(f)),pitch:u+360*d/l},{act:!1}),n.move(i+o*(d-1)/l,p,c+a*(r*Math.sin(f)+d/l*r*1.2)*n.scale)}return n.key(i+o+1,{pitch:u},{act:!1}),t(n,i,i+o),{end:i+o+1}}},land:{summary:"Comes down toward `to`: descends, flares nose-up, touches down with a squash and dust, rolls to a stop and the propeller spools down.",needs:["to"],uses:["for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to),a=n.x,l=s.for??2200,c=r+l,h=a+(s.to-a)*.7;return n.key(r+l*.4,{pitch:-4*o},{act:!1,easing:"ease-out"}),n.key(c-250,{pitch:6*o,lift:.15},{act:!1,easing:"ease-in-out"}),n.key(c,{lift:0,pitch:0,squash:1-.12*o},{act:!1,easing:"ease-in"}),n.key(c+260,{squash:1}),n.move(r,c,h),n.move(c,c+1200,s.to,{easing:"ease-out"}),t(n,i,c),t(n,c,c+1600,"ease-out"),n.key(c+1600,{blur:0},{act:!1,easing:"ease-out"}),n.effect({kind:"dust",time:c,x:h,y:n.floor,length:700}),{end:c+1600,contact:c}}}}}const hs=["walk","trot","canter","gallop"],h3=hs,cm=["fl","fr","hl","hr"],ar={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}},Xe=Math.PI/180;function lr(t,e){return 4*t*Math.sin(ar[e].swing*Xe)}function Ge(t){const{legs:e,colors:n}=t,s=e.upper+e.lower+e.foot,i=s+t.body.rise,o=(u,d)=>[d*u[0],u[1],u[2]],r=[{id:"body",shape:{type:"ellipsoid",radii:t.body.radii,segments:18},at:[0,i,0],fill:n.coat},{id:"neck",shape:{type:"tube",points:t.neck.points,radius:t.neck.points.map((u,d,f)=>t.neck.radius*(1.25-.4*d/Math.max(1,f.length-1))),segments:12},at:t.neck.at,fill:n.coat},{id:"head",parent:"neck",shape:{type:"ellipsoid",radii:t.head.radii,segments:14},at:t.head.at,rotate:t.head.rotate,fill:n.coat},...d3(t,n,i)];t.mane&&r.push({id:"mane",parent:"neck",shape:{type:"tube",points:t.mane.points,radius:t.mane.radius,segments:6},fill:n.dark,outline:.7}),t.muzzle&&r.push({id:"muzzle",parent:"head",shape:{type:"ellipsoid",radii:t.muzzle.radii,segments:10},at:t.muzzle.at,fill:n.muzzle,outline:.8});for(const u of[1,-1]){const d=u>0?"left":"right",f=t.ears.rotate?o(t.ears.rotate,1).map((p,g)=>g===2?u*p:p):void 0;r.push({id:`ear-${d}`,parent:"head",shape:{type:"ellipsoid",radii:t.ears.radii,segments:8},at:o(t.ears.at,u),rotate:f,fill:n.coat,outline:.7},{id:`eye-${d}`,parent:"head",shape:{type:"ellipsoid",radii:[t.eyes.size*.8,t.eyes.size,t.eyes.size*.9],segments:8},at:o(t.eyes.at,u),fill:"#1d1d22",outline:.4})}r.push(...t.extras?.(n)??[]);const a={walk:{description:"Phase of the stride, in full cycles (keyed in step with the distance covered)",unit:"cycles"},walking:{description:"How much of the gait is applied: 0 standing, 1 moving",unit:"0..1",min:0,max:1},gait:{description:`Which gait: ${t.gaits.map(u=>`${hs.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:he,rotate:{axis:"x",degrees:1/he.length}}]},wag:{description:"Tail swung side to side, curling",unit:"degrees",bind:[{parts:he,rotate:{axis:"y",degrees:1/he.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 cm){const d=u[0]==="f",f=u[1]==="l"?1:-1,p=d?e.thickness[0]:e.thickness[1];r.push({id:`${u}-upper`,shape:{type:"tube",points:[[0,e.upper*.2,0],[0,-e.upper*.5,0],[0,-e.upper,0]],radius:[p,p*.85,e.lowerThickness*1.15],segments:10},at:[f*e.across,s,d?e.front:e.hind],fill:n.coat},{id:`${u}-knee`,parent:`${u}-upper`,shape:{type:"ellipsoid",radii:Array(3).fill(e.lowerThickness*1.08),segments:10},at:[0,-e.upper,0],fill:n.coat,solidOnly:!0},{id:`${u}-lower`,parent:`${u}-upper`,shape:{type:"tube",points:[[0,0,0],[0,-e.lower,0]],radius:[e.lowerThickness*1.1,e.lowerThickness*.85],segments:10},at:[0,-e.upper,0],fill:n.coat},{id:`${u}-foot`,parent:`${u}-lower`,shape:{type:"ellipsoid",radii:[e.footSize[0]/2,e.foot/2+.004,e.footSize[1]/2],segments:12},at:[0,-e.lower-e.foot/2,e.footSize[1]*.12],fill:n.foot,outline:.8});const g=`${d?"Front":"Hind"} ${f>0?"left":"right"} leg`;a[`${u}.swing`]={description:`${g}: forward (+) or back (−) from the hip`,unit:"degrees",bind:[{parts:[`${u}-upper`],rotate:{axis:"x",degrees:-1}}]},a[`${u}.knee`]={description:`${g}: knee (hock) folded`,unit:"degrees",bind:[{parts:[`${u}-lower`],rotate:{axis:"x",degrees:d?1:-1}}]},a[`${u}.ankle`]={description:`${g}: foot turned at the ankle (+ toe forward)`,unit:"degrees",bind:[{parts:[`${u}-foot`],rotate:{axis:"x",degrees:-1,pivot:[0,e.foot/2,-e.footSize[1]*.12]}}]}}const l=t.neck.points[t.neck.points.length-1],c={parts:r,controls:a,length:t.body.radii[2]*2+Math.max(0,t.neck.at[2]+l[2]+t.head.radii[2]-t.body.radii[2])+.3,height:t.neck.at[1]+l[1]+t.head.radii[1]*2,footprint:[e.across*2+t.body.radii[0],(e.front-e.hind)*1.4],anchors:{back:{at:[0,i+t.body.radii[1],-t.body.radii[2]*.05]},head:{part:"head",at:[0,0,0]},mouth:{part:t.muzzle?"muzzle":"head",at:t.muzzle?[0,0,t.muzzle.radii[2]]:[0,0,t.head.radii[2]]},front:{at:[0,i,t.body.radii[2]]},...t.anchors},derive:u=>f3(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:{...p3(t,h),...t.actions?.(h)},acting:xc,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:u3(t,s)}}function u3(t,e){const n=i=>{const o=lr(e,i);return{speed:o/(ar[i].cycle*(t.cycleScale??1)/1e3),set:{gait:hs.indexOf(i)},hold:{walking:1},perMetre:{walk:1/o}}},s=Object.fromEntries(t.gaits.map(i=>[i==="gallop"&&!t.gaits.includes("canter")?"run":i,n(i)]));return t.gaits.includes("gallop")&&!s.gallop&&(s.gallop=n("gallop")),s}const he=Array.from({length:7},(t,e)=>e===0?"tail":`tail-${e}`);function d3(t,e,n){const s=Pl(t.tail.points,he.length+1),[,i,o]=t.body.radii,r=(t.tail.at[1]-n)/i,a=Math.abs(r)<1?-o*Math.sqrt(1-r*r):t.tail.at[2],l=[t.tail.at[0],t.tail.at[1],a+Math.min(.04,o*.08)],c=f=>t.tail.radius*(1-.5*f/he.length),h=he.map((f,p)=>{const g=s[p],m=s[p+1],w=[m[0]-g[0],m[1]-g[1],m[2]-g[2]],v=p===0?void 0:s[p-1];return{id:f,...p>0?{parent:he[p-1]}:{},shape:{type:"tube",points:[[0,0,0],w],radius:[c(p),c(p+1)],segments:8,joined:!0},at:p===0?l:[g[0]-v[0],g[1]-v[1],g[2]-v[2]],fill:e.dark,outline:.8}}),u=s[s.length-1],d=s[s.length-2];return h.push({id:"tail-tip",parent:he[he.length-1],shape:{type:"ellipsoid",radii:Array(3).fill(c(he.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 f3(t,e,n){const s=Math.max(0,Math.min(1,t.walking??0));if(s===0)return{};const i=hs[Math.max(0,Math.min(3,Math.round(t.gait??0)))],o=ar[e.gaits.includes(i)?i:e.gaits[0]],r=t.walk??0,a={};for(const c of cm){const h=Math.PI*2*(r+o.offsets[c]);a[`${c}.swing`]=(t[`${c}.swing`]??0)+s*o.swing*Math.sin(h),a[`${c}.knee`]=(t[`${c}.knee`]??0)+s*o.lift*Math.max(0,Math.cos(h))}const l=Math.PI*2*r;return a.lift=(t.lift??0)+s*o.bob*n*Math.abs(Math.sin(l*2)),a.pitch=(t.pitch??0)+s*o.rock*Math.sin(l),a.neck=(t.neck??0)+s*(o.rock>0?-o.rock*1.4:5)*Math.sin(l*2),a}function Sc(t){const n=Math.sin(32*Xe),s=t.legLength-(t.front-t.hind)*n,i=72,r=(s-t.upper*Math.cos(i*Xe)-t.foot)/t.lower,a=r>=1?0:r<=-1?180:Math.acos(r)/Xe,l={pitch:32,lift:t.legLength*(1-Math.cos(32*Xe))-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 xc={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:[]},g3=xc;function hm(t){const e=(t.upper+t.lower)*.32,n=Math.asin(Math.min(1,e/(t.upper+t.lower+t.foot)))/Xe,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 p3(t,e){const n=t.cycleScale??1,s=r=>({summary:{walk:"Walks to `to` (four beats), its head bobbing.",trot:"Trots to `to`: legs in diagonal pairs, the body bouncing.",canter:"Canters to `to`: three beats, the body rocking.",gallop:"Gallops (runs) to `to`: legs reaching, the body rocking hard, kicking up dust."}[r],needs:["to"],uses:["for"],run(a,l,c){const h=Math.sign(l.to-a.x);if(h===0)return{end:c};let u=c;a.facing()!==h&&(u=a.turnTo(u,h>0?"right":"left"));const d=a.exaggeration;a.key(u+180,{neck:-12*d},{act:!1,easing:"ease-out"});const p=Math.abs(l.to-a.x)/a.scale/lr(e.legLength,r),g=l.for??Math.max(500,p*ar[r].cycle*n),m=a.values.walk??0;return a.set("gait",u,a.values.gait??0),a.set("gait",u+1,hs.indexOf(r)),a.set("walking",u,0),a.set("walking",u+240,1,"ease-out"),a.set("walking",u+g-240,1),a.set("walking",u+g,0,"ease-in"),a.set("walk",u,m),a.move(u,u+g,l.to,{easing:"ease-in-out"}),a.set("walk",u+g,m+p,"ease-in-out"),a.key(u+g+300,{neck:0}),(r==="gallop"||r==="canter")&&(a.effect({kind:"dust",time:u+200,x:a.x-h*e.legLength*a.scale,y:a.floor,length:700,direction:-h}),a.effect({kind:"dust",time:u+g,x:l.to+h*e.legLength*.6*a.scale,y:a.floor,length:600,direction:h})),{end:u+g+300,contact:u,release:u+g}}}),i=Object.fromEntries(t.gaits.map(r=>[r==="gallop"&&!t.gaits.includes("canter")?"run":r,s(r)]));t.gaits.includes("gallop")&&!i.gallop&&(i.gallop=s("gallop"));const o={...i,[t.call]:{summary:`Throws its head up and ${t.call}s.`,run(r,a,l){const c=r.exaggeration;return r.key(l+150,{neck:10*c},{act:!1,easing:"ease-out"}),r.key(l+380,{neck:-28*c,squash:1.05},{act:!1,easing:"ease-out"}),r.key(l+680,{neck:-20*c},{act:!1}),r.key(l+980,{neck:0,squash:1}),e.call(r,l+380),{end:l+980,contact:l+380}}},sit:{summary:"Sits on its haunches for `for` ms (default 1500): the rump goes down onto folded hind legs, paws flat on the ground, the front legs stay planted; then it gets up.",uses:["for"],run(r,a,l){const c=Sc(e),h=l+450;r.key(h,c,{act:!1,easing:"ease-in-out"}),r.key(h+(a.for??1500),c,{act:!1});const u=h+(a.for??1500)+450,d={};for(const f of Object.keys(c))d[f]=0;return r.key(u,d),{end:u,contact:h,release:u-450}}},lie:{summary:"Lies down for `for` ms (default 2000), head up and front paws forward (sinking back onto its haunches first), then gets up.",uses:["for"],run(r,a,l){const c=hm(e),h={...Sc(e)},u=l+400,d=u+450;r.key(u,h,{act:!1,easing:"ease-in-out"}),r.key(d,c,{act:!1,easing:"ease-in-out"}),r.key(d+(a.for??2e3),c,{act:!1});const f=d+(a.for??2e3)+600,p={};for(const g of new Set([...Object.keys(c),...Object.keys(h)]))p[g]=0;return r.key(f,p),{end:f,contact:d,release:f-600}}},jump:{summary:"Crouches and jumps (forward to `to`, or up on the spot), legs tucked in the air, landing with a squash and dust.",uses:["to"],run(r,a,l){const c=r.exaggeration,h=e.legLength*.8*c,u=l+260,d=u+90,f=d+520;if(r.key(u,{squash:.86,"hl.knee":40,"hr.knee":40,"fl.knee":25,"fr.knee":25,neck:8},{act:!1,easing:"ease-out"}),r.key(d,{squash:1.12,"hl.knee":0,"hr.knee":0,"fl.knee":0,"fr.knee":0,pitch:8,"fl.swing":35,"fr.swing":35,"hl.swing":-35,"hr.swing":-35},{act:!1,easing:"ease-out"}),r.key((d+f)/2,{lift:h,squash:1,pitch:0,"fl.knee":60,"fr.knee":60,"hl.knee":60,"hr.knee":60,"fl.swing":25,"fr.swing":25,"hl.swing":-20,"hr.swing":-20},{act:!1,easing:"ease-out"}),r.key(f,{lift:0,squash:.85,pitch:-4,"fl.knee":0,"fr.knee":0,"hl.knee":0,"hr.knee":0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0},{act:!1,easing:"ease-in"}),r.key(f+280,{squash:1,pitch:0,neck:0}),a.to!==void 0){const p=Math.sign(a.to-r.x);p!==0&&r.facing()!==p&&r.turnTo(l,p>0?"right":"left"),r.move(d,f,a.to)}return r.effect({kind:"dust",time:f,x:r.x,y:r.floor,length:550}),{end:f+280,contact:f}}},nod:{summary:"Nods its head twice.",run(r,a,l){return r.key(l+200,{neck:20},{act:!1,easing:"ease-out"}),r.key(l+400,{neck:-5},{act:!1,easing:"ease-in-out"}),r.key(l+600,{neck:18},{act:!1,easing:"ease-in-out"}),r.key(l+900,{neck:0}),{end:l+900}}},swish:{summary:"Swishes its tail a few times.",uses:["for"],run(r,a,l){const c=a.for??900;for(let h=1;h<=4;h++)r.key(l+c*h/5,{tail:h%2===0?10:35},{act:!1,easing:"ease-in-out"});return r.key(l+c,{tail:0}),{end:l+c}}}};return t.grazes&&(o.graze={summary:"Lowers its head to graze for `for` ms (default 1800), nibbling, then looks up.",uses:["for"],run(r,a,l){const c=a.for??1800;r.key(l+600,{neck:75},{act:!1,easing:"ease-in-out"});for(let h=900;h<600+c;h+=400)r.key(l+h,{neck:h%800===100?70:78},{act:!1,easing:"ease-in-out"});return r.key(l+600+c+500,{neck:0}),{end:l+600+c+500}}}),o}function um(t={}){return Ge({kind:t.kind??"horse",summary:t.summary??"A cartoon horse: walks, trots, canters and gallops with its hooves in step with the ground, rears, bucks, neighs, grazes and swishes its tail.",legs:{upper:.5,lower:.42,foot:.08,footSize:[.12,.16],front:.62,hind:-.62,across:.2,thickness:[.075,.09],lowerThickness:.05},body:{radii:[.32,.36,.95],rise:.25},neck:{at:[0,1.42,.7],points:[[0,0,0],[0,.5,.3]],radius:.15},head:{at:[0,.48,.5],radii:[.13,.14,.3],rotate:[38,0,0]},muzzle:{at:[0,-.02,.24],radii:[.11,.1,.1]},ears:{at:[.07,.16,-.17],radii:[.035,.1,.05]},eyes:{at:[.115,.05,-.04],size:.04},tail:{at:[0,1.4,-.9],points:[[0,0,0],[0,-.22,-.2],[0,-.62,-.24]],radius:.08},mane:{points:[[0,.1,-.12],[0,.55,.17]],radius:.07},colors:{coat:"#b5763a",dark:"#4a2e1a",foot:"#3a2a22",muzzle:"#8d5a2c",accent:"#e8c9a0",...t.colors},gaits:["walk","trot","canter","gallop"],call:"neigh",grazes:!0,anchors:{hitch:{at:[0,.95,-.15]},saddle:{at:[0,1.6,-.05]}},actions:e=>({rear:{summary:"Rears up on its hind legs, front legs tucked and pawing, neighs, and drops back down with dust.",uses:["for"],run(n,s,i){const o=n.exaggeration,r=Math.min(55,32*o),a=-e.hind*Math.sin(r*Xe),l=s.for??700;n.key(i+200,{pitch:-4,neck:6,"hl.knee":12,"hr.knee":12},{act:!1,easing:"ease-out"}),n.key(i+520,{pitch:r,lift:a,neck:-25,"fl.swing":55,"fl.knee":95,"fr.swing":40,"fr.knee":80,"hl.knee":0,"hr.knee":0},{act:!1,easing:"ease-out"}),n.key(i+520+l*.5,{"fl.swing":35,"fl.knee":70,"fr.swing":58,"fr.knee":100},{act:!1,easing:"ease-in-out"}),n.key(i+520+l,{"fl.swing":55,"fl.knee":95,"fr.swing":40,"fr.knee":80},{act:!1,easing:"ease-in-out"});const c=i+520+l+380;return n.key(c,{pitch:0,lift:0,neck:8,squash:.94,"fl.swing":0,"fl.knee":0,"fr.swing":0,"fr.knee":0},{act:!1,easing:"ease-in"}),n.key(c+320,{neck:0,squash:1}),e.call(n,i+520),n.effect({kind:"dust",time:c,x:n.x+(n.facing()||1)*e.front*n.scale,y:n.floor,length:600}),{end:c+320,contact:c}}},buck:{summary:"Bucks: drops its head and kicks both hind legs up and back.",run(n,s,i){const o=n.exaggeration,r=Math.min(35,18*o),a=e.front*Math.sin(r*Xe);return n.key(i+220,{pitch:3,squash:.95},{act:!1,easing:"ease-out"}),n.key(i+480,{pitch:-r,lift:a,neck:30,"hl.swing":-65,"hr.swing":-60,"hl.knee":10,"hr.knee":10},{act:!1,easing:"ease-out"}),n.key(i+900,{pitch:0,lift:0,neck:0,squash:.95,"hl.swing":0,"hr.swing":0,"hl.knee":0,"hr.knee":0},{act:!1,easing:"ease-in"}),n.key(i+1150,{squash:1}),n.effect({kind:"dust",time:i+900,x:n.x-(n.facing()||1)*.6*n.scale,y:n.floor,length:600}),{end:i+1150,contact:i+480}}}})})}function dm(t={}){return Ge({kind:t.kind??"dog",summary:t.summary??"A cartoon dog: walks, trots and runs, barks, wags its tail, sits, jumps, sniffs the ground.",legs:{upper:.19,lower:.16,foot:.05,footSize:[.07,.1],front:.24,hind:-.24,across:.09,thickness:[.04,.05],lowerThickness:.032},body:{radii:[.14,.15,.36],rise:.1},neck:{at:[0,.56,.27],points:[[0,0,0],[0,.14,.06]],radius:.075},head:{at:[0,.15,.08],radii:[.12,.11,.13]},muzzle:{at:[0,-.03,.13],radii:[.065,.055,.08]},ears:{at:[.11,0,-.02],radii:[.025,.09,.05],rotate:[0,0,18]},eyes:{at:[.08,.04,.08],size:.025},tail:{at:[0,.58,-.34],points:[[0,0,0],[0,.1,-.08],[0,.2,-.1]],radius:.03},extras:e=>[{id:"nose",parent:"muzzle",shape:{type:"ellipsoid",radii:[.025,.02,.02],segments:8},at:[0,.03,.08],fill:"#1d1d22",outline:.4},{id:"patch",parent:"body",shape:{type:"ellipsoid",radii:[.012,.09,.11],segments:10},at:[.135,.04,-.06],fill:e.accent,outline:.5}],colors:{coat:"#d9a066",dark:"#a8703a",foot:"#a8703a",muzzle:"#f0d2a8",accent:"#f6ead8",...t.colors},gaits:["walk","trot","gallop"],cycleScale:.55,call:"bark",anchors:{leash:{part:"neck",at:[0,.06,0]}},actions:()=>({wag:{summary:"Wags its tail fast for `for` ms (default 1200).",uses:["for"],run(e,n,s){const i=n.for??1200;for(let o=80,r=0;o<i;o+=80,r++)e.key(s+o,{wag:r%2===0?35:-35,tail:25},{act:!1,easing:"ease-in-out"});return e.key(s+i,{wag:0,tail:0}),{end:s+i}}},sniff:{summary:"Puts its nose to the ground and sniffs (`for` ms, default 1400).",uses:["for"],run(e,n,s){const i=n.for??1400;e.key(s+350,{neck:70,pitch:-6},{act:!1,easing:"ease-in-out"});for(let o=500,r=0;o<i;o+=140,r++)e.key(s+o,{neck:r%2===0?74:66},{act:!1});return e.key(s+i+300,{neck:0,pitch:0}),{end:s+i+300}}}})})}function fm(t={}){return Ge({kind:t.kind??"cat",summary:t.summary??"A cartoon cat: walks, trots and runs, meows, arches its back, pounces, sits and swishes its tail.",legs:{upper:.13,lower:.11,foot:.035,footSize:[.05,.07],front:.17,hind:-.18,across:.06,thickness:[.028,.035],lowerThickness:.022},body:{radii:[.1,.105,.27],rise:.07},neck:{at:[0,.39,.2],points:[[0,0,0],[0,.08,.04]],radius:.05},head:{at:[0,.1,.05],radii:[.095,.085,.085]},muzzle:{at:[0,-.03,.07],radii:[.04,.03,.03]},ears:{at:[.055,.085,-.01],radii:[.03,.055,.02],rotate:[0,0,-12]},eyes:{at:[.045,.02,.07],size:.022},tail:{at:[0,.42,-.26],points:[[0,0,0],[0,.08,-.12],[0,.24,-.16],[0,.34,-.1]],radius:.022},extras:()=>[{id:"nose",parent:"muzzle",shape:{type:"ellipsoid",radii:[.014,.01,.01],segments:8},at:[0,.015,.03],fill:"#e48a9a",outline:.4}],colors:{coat:"#8f8a86",dark:"#5f5a57",foot:"#f2efe9",muzzle:"#f2efe9",accent:"#f2efe9",...t.colors},gaits:["walk","trot","gallop"],cycleScale:.5,call:"meow",actions:e=>({arch:{summary:"Arches its back, fur up and tail high, for `for` ms (default 1200): a startled cat.",uses:["for"],run(n,s,i){const o=n.exaggeration,r=s.for??1200,a={squash:1+.25*o,neck:25,tail:-45,"fl.swing":-8,"fr.swing":-8,"hl.swing":8,"hr.swing":8};return n.key(i+180,a,{act:!1,easing:"ease-out"}),n.key(i+180+r,a,{act:!1}),n.key(i+r+520,{squash:1,neck:0,tail:0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0}),{end:i+r+520,contact:i+180}}},pounce:{summary:"Crouches low, wiggles, and pounces to `to`, landing with a squash.",needs:["to"],run(n,s,i){const o=n.exaggeration,r=Math.sign(s.to-n.x);let a=i;r!==0&&n.facing()!==r&&(a=n.turnTo(a,r>0?"right":"left"));const l={squash:.75,"hl.knee":60,"hr.knee":60,"fl.knee":45,"fr.knee":45,neck:10,tail:-15};n.key(a+300,l,{act:!1,easing:"ease-out"});for(let u=1;u<=4;u++)n.key(a+300+u*110,{roll:u%2===0?3:-3},{act:!1});const c=a+300+550,h=c+480;return n.key(c,{roll:0,squash:1.2,"hl.knee":0,"hr.knee":0,"fl.knee":0,"fr.knee":0,"fl.swing":45,"fr.swing":45,"hl.swing":-45,"hr.swing":-45,tail:20},{act:!1,easing:"ease-out"}),n.key((c+h)/2,{lift:e.legLength*.9*o,squash:1.1,pitch:-6},{act:!1,easing:"ease-out"}),n.key(h,{lift:0,squash:.8,pitch:0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0,neck:0,tail:0},{act:!1,easing:"ease-in"}),n.key(h+260,{squash:1}),n.move(c,h,s.to),n.effect({kind:"dust",time:h,x:s.to,y:n.floor,length:450}),{end:h+260,contact:h}}}})})}function gm(t={}){return Ge({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 m3(t){return lr(1,t)}function pm(t={}){return Ge({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 mm(t={}){return Ge({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 ym(t={}){return Ge({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 Ue=.6,bm=75,Tc=80;function Ve(t){const{colors:e}=t,[n,s,i]=t.body.radii,o=(t.tail.raised??15)*Math.PI/180,r=t.tail.length*.4,a=[{id:"body",shape:{type:"ellipsoid",radii:t.body.radii,segments:16},at:[0,t.body.height,0],fill:e.body},{id:"neck",shape:{type:"ellipsoid",radii:[n*.55,s*.55,i*.3],segments:10},at:[0,t.body.height+s*.45,i*.65],fill:e.body,outline:.5,solidOnly:!0},{id:"head",parent:"neck",shape:{type:"ellipsoid",radii:[t.head.radius,t.head.radius*1.02,t.head.radius*1.05],segments:14},at:[t.head.at[0],t.head.at[1]-(t.body.height+s*.45),t.head.at[2]-i*.65],fill:e.body},{id:"beak",parent:"head",shape:{type:"tube",points:[[0,0,0],[0,-t.beak.thickness*.4,t.beak.length]],radius:[t.beak.thickness,t.beak.thickness*.08],segments:8},at:[0,-t.head.radius*.1,t.head.radius*.8],fill:e.beak,outline:.8},{id:"tail",shape:{type:"ellipsoid",radii:[t.tail.width/2,.012*(i/.08),t.tail.length/2],segments:10},at:[t.tail.at[0],t.tail.at[1]+r*Math.sin(o),t.tail.at[2]-r*Math.cos(o)],rotate:[t.tail.raised??15,0,0],fill:e.wing,outline:.8}];if(e.belly&&a.push({id:"belly",parent:"body",shape:{type:"ellipsoid",radii:[n*.82,s*.7,i*.75],segments:12},at:[0,-s*.25,i*.12],fill:e.belly,outline:.4}),t.comb){const h=t.head.radius;a.push({id:"comb",parent:"head",shape:{type:"extrude",profile:[[-h*.5,h*.6],[h*.6,h*.6],[h*.5,h*1.3],[h*.15,h*1.05],[-h*.05,h*1.4],[-h*.3,h*1.05],[-h*.6,h*1.25]],width:h*.25},fill:e.comb??"#d9372e",outline:.7},{id:"wattle",parent:"head",shape:{type:"ellipsoid",radii:[h*.15,h*.35,h*.2],segments:8},at:[0,-h*.7,h*.6],fill:e.comb??"#d9372e",outline:.6})}for(const h of[1,-1]){const u=h>0?"left":"right",d=t.head.radius;a.push({id:`eye-${u}`,parent:"head",shape:{type:"ellipsoid",radii:[d*.16,d*.2,d*.18],segments:8},at:[h*d*.72,d*.18,d*.42],fill:"#1d1d22",outline:.3}),a.push({id:`wing-${u}`,shape:{type:"ellipsoid",radii:[.004,.004,.004],segments:4},at:[h*t.wing.shoulder[0],t.wing.shoulder[1],t.wing.shoulder[2]],rotate:[-8,h*90,0],outline:0}),a.push({id:`wing-${u}-blade`,parent:`wing-${u}`,shape:{type:"ellipsoid",radii:[t.wing.span*Ue/2,t.wing.chord*.1,t.wing.chord/2],segments:12},at:[h*t.wing.span*Ue/2,0,-t.wing.chord*.1],rotate:[-Tc,0,0],fill:e.wing,outline:.8}),a.push({id:`wing-${u}-tip`,parent:`wing-${u}-blade`,shape:{type:"ellipsoid",radii:[t.wing.span*Ue/2.4,t.wing.chord*.06,t.wing.chord*.3],segments:10},at:[h*t.wing.span*Ue/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-Ue)/2,0,0],rotate:{axis:"x",degrees:Tc},scale:[1/Ue,1,1]},{parts:["wing-right-blade"],translate:[-t.wing.span*(1-Ue)/2,0,0],rotate:{axis:"x",degrees:Tc},scale:[1/Ue,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)/bm,0]}]},step:{description:"Phase of a walk, in steps (a chicken’s legs)",unit:"steps"},stepping:{description:"How much of the walk is applied",unit:"0..1",min:0,max:1},"leg.left":{description:"Left leg swung forward (+)",unit:"degrees",bind:[{parts:["leg-left"],rotate:{axis:"x",degrees:-1}}]},"leg.right":{description:"Right leg swung forward (+)",unit:"degrees",bind:[{parts:["leg-right"],rotate:{axis:"x",degrees:-1}}]},grip:{description:"The toes curled down round a perch: 0 flat on the ground, 1 gripping",unit:"0..1",min:0,max:1,bind:[{parts:["toes-left","toes-right"],rotate:{axis:"x",degrees:55}}]}},c={parts:a,controls:l,length:i*2+t.tail.length+t.beak.length,height:t.head.at[1]+t.head.radius,footprint:[n*2.2,i*2.4],anchors:{beak:{part:"beak",at:[0,0,t.beak.length]},head:{part:"head",at:[0,0,0]},back:{at:[0,t.body.height+s,0]},feet:{at:[0,0,0]}},derive:h=>{const u={},d=Math.max(0,Math.min(1,h.flapping??0));d>0&&(u.flap=(h.flap??0)+d*48*Math.sin(Math.PI*2*(h.wingbeat??0)));const f=Math.max(0,Math.min(1,h.stepping??0));if(f>0){const p=Math.sin(Math.PI*2*(h.step??0));u["leg.left"]=(h["leg.left"]??0)+f*28*p,u["leg.right"]=(h["leg.right"]??0)-f*28*p,u.peck=(h.peck??0)+f*12*Math.sin(Math.PI*4*(h.step??0))}return u}};return{kind:t.kind,family:"bird",summary:t.summary,rig:c,actions:b3(t),acting:wm,colors:{body:e.body,ink:"#26262b"},moves:y3(t)}}function y3(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 wm={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 b3(t){const e=(t.beatsPerSecond??4)/1e3,n=(r,a,l)=>{const c=r.values.wingbeat??0;r.set("wingbeat",a,c),r.set("wingbeat",l,c+(l-a)*e)},s=(r,a,l)=>{const c=Math.sign(l-r.x);return c!==0&&r.facing()!==c?r.turnTo(a,c>0?"right":"left"):a},i=(r,a)=>{const l=r.anchor("beak");r.effect({kind:"honk",time:a,x:l.x,y:l.y,length:600,direction:r.facing()||1})},o={hop:{summary:"Hops to `to` in little bounces, wings twitching.",needs:["to"],run(r,a,l){const c=s(r,l,a.to),h=r.x,u=Math.abs(a.to-h),d=Math.max(1,Math.round(u/(t.body.radii[2]*3*r.scale))),f=260;for(let p=0;p<d;p++){const g=c+p*f;r.key(g+60,{squash:.85},{act:!1,easing:"ease-out"}),r.key(g+150,{squash:1.1,lift:t.legs.length*1.4,spread:.15},{act:!1,easing:"ease-out"}),r.key(g+f,{squash:.9,lift:0,spread:0},{act:!1,easing:"ease-in"}),r.move(g+60,g+f,h+(a.to-h)*(p+1)/d,{easing:"ease-in-out"})}return r.key(c+d*f+120,{squash:1}),{end:c+d*f+120}}},walk:{summary:"Walks to `to` on its two legs, its head bobbing with each step.",needs:["to"],uses:["for"],run(r,a,l){const c=s(r,l,a.to),h=Math.abs(a.to-r.x)/r.scale,u=t.legs.length*1.2,d=h/u,f=a.for??Math.max(400,d*420),p=r.values.step??0;return r.set("stepping",c,0),r.set("stepping",c+150,1,"ease-out"),r.set("stepping",c+f-150,1),r.set("stepping",c+f,0,"ease-in"),r.set("step",c,p),r.move(c,c+f,a.to,{easing:"ease-in-out"}),r.set("step",c+f,p+d/2,"ease-in-out"),{end:c+f,contact:c,release:c+f}}},peck:{summary:"Pecks at the ground (`for` ms, default 900): quick jabs of the head.",uses:["for"],run(r,a,l){const c=a.for??900,h=Math.max(1,Math.round(c/300));r.key(l+120,{pitch:-(t.stoop??12)},{act:!1,easing:"ease-out"});for(let u=0;u<h;u++)r.key(l+120+u*300+90,{peck:bm},{act:!1,easing:"ease-in"}),r.key(l+120+u*300+260,{peck:20},{act:!1,easing:"ease-out"});return r.key(l+120+h*300+200,{peck:0,pitch:0}),{end:l+120+h*300+200,contact:l+210}}},flap:{summary:"Flaps its wings on the spot (`for` ms, default 900), lifting a little.",uses:["for"],run(r,a,l){const c=a.for??900;return r.key(l+120,{spread:1},{act:!1,easing:"ease-out"}),r.set("flapping",l,0),r.set("flapping",l+150,1,"ease-out"),r.set("flapping",l+c-150,1),r.set("flapping",l+c,0,"ease-in"),n(r,l,l+c),r.key(l+c*.5,{lift:t.legs.length*.6},{act:!1,easing:"ease-out"}),r.key(l+c,{lift:0,spread:0},{act:!1,easing:"ease-in"}),{end:l+c+80}}},[t.call]:{summary:`${t.call[0].toUpperCase()}${t.call.slice(1)}s: its head comes up and its beak opens to call.`,run(r,a,l){return r.key(l+120,{peck:-25,squash:1.06},{act:!1,easing:"ease-out"}),r.key(l+500,{peck:-20},{act:!1}),r.key(l+760,{peck:0,squash:1}),i(r,l+150),{end:l+760,contact:l+150}}}};return t.flies!==!1?(o.fly={summary:"Takes off (a crouch and a leap, wings beating) and flies to `to` at `height` metres (default 2); `land` brings it down.",needs:["to"],uses:["height","for"],run(r,a,l){const c=r.exaggeration;r.key(l+60,{grip:0},{act:!1});const h=s(r,l,a.to),u=a.height??2,d=a.for??Math.max(700,Math.abs(a.to-r.x)/.35),f=r.values.lift>t.legs.length,p=f?h:h+200;return f||(r.key(h+160,{squash:1-.18*c,spread:.6},{act:!1,easing:"ease-out"}),r.effect({kind:"dust",time:p,x:r.x,y:r.floor,length:400})),r.key(p+100,{spread:1,squash:1.08,pitch:10},{act:!1,easing:"ease-out"}),r.set("flapping",p,r.values.flapping??0),r.set("flapping",p+100,1,"ease-out"),r.set("flapping",p+d,.6),n(r,p,p+d),r.key(p+d*.4,{lift:u,pitch:-5,squash:1},{act:!1,easing:"ease-out"}),r.key(p+d,{lift:u,pitch:0},{act:!1,easing:"ease-in-out"}),r.move(p,p+d,a.to,{easing:"ease-in-out"}),{end:p+d,contact:p,release:p+d}}},o.glide={summary:"Glides to `to` on still, spread wings, sinking gently to `height` metres (default: a third lower than it is); from the ground it takes off first, flying the first stretch.",needs:["to"],uses:["height","for"],run(r,a,l){let c=l;if(r.values.lift<=t.legs.length){const f=r.x+(a.to-r.x)/3;c=o.fly.run(r,{do:"fly",to:f,height:(a.height??1.5)*1.3},l).end}c=s(r,c,a.to);const h=r.values.lift,u=a.height??h*.67,d=a.for??Math.max(900,Math.abs(a.to-r.x)/.3);return r.set("flapping",c,r.values.flapping??1),r.set("flapping",c+250,0,"ease-out"),n(r,c,c+250),r.key(c+300,{spread:1,flap:10,pitch:-6},{act:!1,easing:"ease-out"}),r.key(c+d,{lift:u,pitch:-3,flap:10},{act:!1,easing:"ease-in-out"}),r.move(c,c+d,a.to,{easing:"ease-in-out"}),{end:c+d,contact:c,release:c+d}}},o.land={summary:"Comes down to the floor it is over (or to `height` metres above it, a branch or a roof): wings braking, a squash on touchdown.",uses:["height","to"],run(r,a,l){const h=a.height??0;return r.set("flapping",l,r.values.flapping??1),r.set("flapping",l+700-120,1),r.set("flapping",l+700,0,"ease-in"),n(r,l,l+700),r.key(l+700*.6,{pitch:14},{act:!1,easing:"ease-out"}),r.key(l+700,{lift:h,pitch:0,squash:.85,grip:h>0?1:0},{act:!1,easing:"ease-in"}),a.to!==void 0&&r.move(l,l+700,a.to,{easing:"ease-out"}),r.key(l+700+160,{squash:1,spread:0,flap:0}),{end:l+700+200,contact:l+700}}}):o.flutter={summary:"Flutters up a little way and back down, wings beating hard (a chicken’s flight).",run(r,a,l){return r.key(l+100,{spread:1,squash:.9},{act:!1,easing:"ease-out"}),r.set("flapping",l+80,0),r.set("flapping",l+160,1,"ease-out"),r.set("flapping",l+900-100,1),r.set("flapping",l+900,0,"ease-in"),n(r,l+80,l+900),r.key(l+900*.5,{lift:t.legs.length*2.5,squash:1.08},{act:!1,easing:"ease-out"}),r.key(l+900,{lift:0,squash:.85,spread:0},{act:!1,easing:"ease-in"}),r.key(l+900+160,{squash:1}),{end:l+900+160,contact:l+900}}},o}function km(t={}){return Ve({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 vm(t={}){return Ve({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 Mm(t={}){return Ve({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 Sm(t={}){return Ve({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 xm(t={}){return Ve({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 Tm(t={}){return Ve({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 Em(t={}){return Ve({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 us={car:Np,truck:Fp,bus:Wp,tractor:Dp,cart:Bp,trainCar:zp,bike:qp,motorbike:Yp,tree:Kp,house:Xp,chair:Up,desk:Jp,bed:Qp,door:em,wheelchair:im,helicopter:am,airplane:lm,horse:um,dog:dm,cat:fm,cow:gm,goat:pm,rabbit:mm,squirrel:ym,songbird:km,crow:vm,chicken:Mm,pigeon:Sm,duck:xm,owl:Tm,parrot:Em};function Ec(t,e={}){const n=us[t];if(!n)throw new Error(ft("prop preset",t,Object.keys(us)));return n(e)}const cr=["do","at","for","to","toward","speed","open","on","height","wind"],Ac={viewer:0,right:1,away:2,left:3},w3=420,Pc={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 hr(t){return{...Pc,...t.actions}}const $c=t=>typeof t=="number"&&Number.isFinite(t);function Am(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=hr(e),s=Object.keys(n),i=[];return t.forEach((o,r)=>{const a=c=>i.push({level:"error",beat:r,message:c});if(!o||typeof o!="object"||Array.isArray(o))return a(`Each beat must be an object like { do: '${s[s.length-1]}' }.`);const l=o;for(const c of Object.keys(l))cr.includes(c)||a(ft("beat field",c,cr,c==="duration"?"for":c==="direction"?"toward":void 0));if(typeof l.do!="string"||!s.includes(l.do))return a(ft(`${e.kind} action`,l.do,s));for(const c of n[l.do].needs??[])l[c]===void 0&&a(`\`${l.do}\` needs \`${c}\`.`);for(const c of["at","for","speed","height","wind"])l[c]!==void 0&&!($c(l[c])&&l[c]>=0)&&a(`\`${c}\` must be a number ≥ 0 (got ${JSON.stringify(l[c])}).`);if(l.to!==void 0&&!$c(l.to)&&a(`\`to\` is a scene x in px (got ${JSON.stringify(l.to)}).`),l.toward!==void 0&&!$c(l.toward)&&!(typeof l.toward=="string"&&l.toward in Ac)){const c=typeof l.toward=="string"?xs(l.toward,Object.keys(Ac)):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 Pm(t,e,n,s={}){const i=Am(n,e).filter(S=>S.level==="error");if(i.length>0)throw new Error(`propScript (${e.kind}): ${i.length} problem(s) in the beats:
|
|
61
|
+
${i.map(S=>` beat ${S.beat}: ${S.message}`).join(`
|
|
62
|
+
`)}`);const o=s.from??0,r=s.ground??0,a=s.scale??60,l=s.exaggeration??1,c=hr(e),h={};for(const S of[...Object.keys(as),...Object.keys(e.rig.controls)])h[S]=s.start?.[S]??At(e.rig,{},S);const u=[{time:0,pose:{...h}}],d=new Map,f=[];let p=o,g=r;const m=(S,E,P,A)=>{const I=d.get(S)??[{time:0,value:S==="x"||S==="y"?0:h[S]}];I.push({time:E,value:P,...A?{easing:A}:{}}),d.set(S,I),S!=="x"&&S!=="y"&&(h[S]=P)},w=(S,E)=>{const P=S==="x"?p-o:S==="y"?g-r:h[S],A=d.get(S);(!A||A[A.length-1].time<E)&&m(S,E,P)},v={prop:e,scale:a,exaggeration:l,get x(){return p},get floor(){return g},values:h,facing(){const S=Math.sin(h.turn*Math.PI/2);return Math.abs(S)<.5?0:S>0?1:-1},key(S,E,P={}){Object.assign(h,E),u.push({time:S,pose:{...h},...P.act===!1?{act:!1}:{},...P.easing?{easing:P.easing}:{}})},move(S,E,P,A={}){w("x",S),m("x",E,P-o,A.easing),p=P,A.floor!==void 0&&(w("y",S),m("y",E,A.floor-r,A.easing),g=A.floor)},set(S,E,P,A){m(S,E,P,A)},turnTo(S,E){const P=typeof E=="number"?E:Ac[E],A=h.turn,_=[P-4,P,P+4].map(Y=>({t:Y,d:Math.abs(Y-A)})).sort((Y,V)=>Y.d-V.d||Math.abs(Y.t)-Math.abs(V.t))[0];if(_.d<.001)return S;const N=S+w3*Math.max(1,_.d);return v.key(N,{turn:_.t}),N},effect(S){f.push(S)},anchor(S){const P=ls(e,h,a).anchors[S];if(!P)throw new Error(`${e.kind}: no anchor "${S}"`);return{x:p+P.point.x,y:g+P.point.y}}},k=[];let y=0;for(const S of n){const E=Math.max(S.at??y,u[u.length-1].time),P=c[S.do].run(v,S,E);P.end>u[u.length-1].time&&u.push({time:P.end,pose:{...h}}),k.push({start:E,end:P.end,...P.contact!==void 0?{contact:P.contact}:{},...P.release!==void 0?{release:P.release}:{}}),y=P.end}const T=Gl(s.style??"snappy"),$={...T,anticipation:T.anticipation*l,overshoot:T.overshoot*l},M=Uo(S3(u),e.acting,{style:$}),x=[...Object.entries(M).filter(([S])=>!d.has(S)).map(([S,E])=>({id:`${t}-${S}`,target:t,property:S,keyframes:E})),...[...d].map(([S,E])=>({id:`${t}-${S}`,target:t,property:S,keyframes:x3(E)}))];for(const S of v3(t,e,x,y,u[0].pose)){const E=x.findIndex(I=>I.property===S.property);if(E<0){x.push(S);continue}const P=new It({id:`${t}-own`,tracks:[x[E]]}),A=I=>Number(P.getStateAtTime(I).values.get(t)?.get(S.property)??0);x[E]={...S,keyframes:S.keyframes.map(I=>({time:I.time,value:Number(I.value)+A(I.time)}))}}return{tracks:x,duration:y,beats:k,effects:f}}const k3=1500;function v3(t,e,n,s,i){if(!e.follow?.length)return[];const o=new It({id:`${t}-follow`,tracks:n.filter(a=>a.property==="turn"||e.follow.some(l=>l.of===a.property))}),r=(a,l)=>{const c=o.getStateAtTime(a).values.get(t)?.get(l);return typeof c=="number"?c:i[l]??0};return e.follow.map(a=>{const l=s+k3,c=Ts(d=>r(d,a.of),{start:0,end:l,stiffness:a.stiffness,damping:a.damping}),h=a.limit??1/0,u=c.map(({time:d,value:f})=>{const p=Math.sin(r(d,"turn")*Math.PI/2),g=(f-r(d,a.of))*p;return{time:d,value:Math.max(-h,Math.min(h,g*a.per))}});return{id:`${t}-${a.control}`,target:t,property:a.control,keyframes:u}})}const M3=20;function S3(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<M3?n[n.length-1]={...s,time:i.time}:n.push(s)}return n}function x3(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 T3={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 $m(t,e={}){const n={};for(const s of Object.keys(Dt))n[s]={summary:`Walks to \`to\` in the ${s} gait.`,needs:["to"]};for(const s of Object.keys(Jt))n[s]={summary:`Moves into the ${s} pose and holds it (\`for\` ms).`};for(const s of Object.keys(Ke))n[s]={summary:`The ${s} gag (${li(s)} ms).`};for(const[s,i]of Object.entries(ci))n[s]={...i};return{...t?{version:t}:{},timing:"JSON timelines and tracks are in milliseconds; the GSAP-style API (live.to, tf.timeline) takes seconds. Scene x grows right, y grows down, in px.",easings:{named:Object.keys(T3),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:nr,stickFigure:{poseFields:ou,props:ru,handFields:au,poses:Object.keys(Jt),expressions:Object.keys(vt),gags:Object.fromEntries(Object.keys(Ke).map(s=>[s,li(s)])),gaits:Object.keys(Dt),actingStyles:Object.keys(wn),beatFields:Vo,actions:n,dances:Object.fromEntries(Object.entries(We).map(([s,i])=>[s,Object.keys(i.moves)])),flips:Object.fromEntries(Object.entries(Zs).map(([s,i])=>[s,i.label])),handShapes:Object.keys(Ct),mudras:Object.keys(eo)},props:{api:{"car() · truck() · bus() · tractor() · cart() · trainCar() · bike() · motorbike()":"wheeled vehicles (vehicle(spec) makes your own)","tree() · house()":"environment (tree(spec), house(spec))","helicopter() · airplane()":"aircraft","horse() · dog() · cat() · cow()":"animals (quadruped(spec) makes your own): gaits with footfall patterns keyed in step with the distance, sit, jump, their calls, species actions","songbird() · crow() · chicken()":"birds (bird(spec) makes your own): hop, walk, peck, flap, fly and land (a chicken flutters), their calls; wings fold and beat in rhythm","{ kind: 'prop', prop: 'car', position, rotation, values } with loadScene3D(scene, { kinds: [characterObjects, propObjects] })":"props in 3D scenes, by preset name, seen in perspective by the scene camera; controls are tracks on the object","characterScript3D(id, beats, { scene, position?, heading?, height?, pose? })":"a v2 character in world metres: gaits, face (shortest turn), spin (signed turns and duration), dance (native style, bpm, beats), hold, pose, gag; checkCharacterBeats3D checks the beats","propRide3D({ prop, propId, propTracks, scene, placement, anchor, riderId, pose, start, end, mount?, dismount? })":"a character riding a prop in a 3D scene: hips on a seat anchor (saddle, seat) as it moves, hopping on and off; RIDING_POSES.astride / .seated / .driving / .cycling / .wheeling (a wheelchair)","propScript3D(id, prop, beats, { scene, position?, heading?, values? })":"props scripted in world metres for 3D scenes: moves to [x, z] or through points (wheels and strides keyed with the distance), face, hold, and their actions; checkPropBeats3D checks the beats","propPreset(name, options?)":"a prop preset by name (did-you-mean on a wrong one)","propTarget({ …, style: 'stick' })":"line art to go with stick figures: tubes as single strokes, shapes outlined over paper","propTow({ leader, leaderId, leaderTracks, hitch, towed, towedId, anchor, start, end })":"a prop towed by another (a cart behind a horse): turns with it, its wheels roll exactly","propTarget({ x, y, prop, scale?, values?, look?, ink? })":"a canvas target that draws a prop (x, y: its middle on the ground; scale px per metre, default 60)","propScript(id, prop, beats, { from, ground, scale, style?, exaggeration?, start? })":"beats → acted tracks, with contact times and effect cues; checkPropBeats(beats, prop) checks them","drawProp(ctx, target, frame, id, { rider? })":"draw it as it is in a frame (a rider is drawn between its far and near parts)","propAt(target, frame, id).anchor(name)":"where an anchor (seat, door, chimney…) is, in scene px","propRide({ prop, propId, propTracks, anchor, figure, figureId, start, end, offset? })":"a figure carried at an anchor, turning with the prop; spliceTracks() puts it into the figure’s tracks","drawPropEffects(ctx, effects, time)":"dust, exhaust, skid marks, honk lines, leaves, smoke"},beatFields:cr,commonControls:Object.fromEntries(Object.entries(as).map(([s,i])=>[s,`${i.description}${i.unit?` (${i.unit})`:""}`])),commonActions:Object.fromEntries(Object.entries(Pc).map(([s,i])=>[s,i.summary])),presets:Object.fromEntries(Object.entries(us).map(([s,i])=>{const o=i();return[s,{family:o.family,summary:o.summary,actions:Object.fromEntries(Object.entries(o.actions).map(([r,a])=>[r,{summary:a.summary,...a.needs?{needs:a.needs}:{}}])),controls:Object.keys(o.rig.controls),anchors:Object.keys(o.rig.anchors??{})}]}))},custom:{api:{"defineAction({ summary, needs?, steps: (from, beat) => [{ after, pose, easing? }] })":"a new action written as timed pose steps from the current pose, like a gag","defineAction({ summary, needs?, beats: (beat) => [beats] })":"a new action built from other beats (which may be custom too)","defineGait({ swing, knee, arm, elbow, lean, cycle?, … })":"a new gait (the Gait fields in degrees; cycle is ms per two steps)","scriptTracks(id, beats, { actions, gaits })":"beats may then use those names; checkBeats(beats, { actions, gaits }) knows them","stickFigureTarget({ …, cast: { actions, gaits } })":"a figure that draws the gaits and lists the actions in describeTarget","persona({ name, summary?, height?, look?, acting?, gait?, mood?, stance?, energy?, actions?, gaits? })":"a character’s look, acting style and habits: .figure({ x, y }), .script(id, beats, { from, ground }), .check(beats), .handPath(…), .describe(); `go` walks in its gait, `stand` returns to its stance and face"},actions:Object.fromEntries(Object.entries(e.actions??{}).map(([s,i])=>[s,{summary:i.summary,...i.needs?{needs:i.needs}:{}}])),gaits:Object.fromEntries(Object.entries(e.gaits??{}).map(([s,i])=>[s,i.summary??"custom gait"]))},character:{figureStyles:["fluid","stick","organic"],body:{"body.torso · body.arm · body.leg · body.neck":"Organic half-width profiles: [{ at: 0..1, width: fractionOfHeight }], increasing from 0 to 1; independent of ink width.","body.fill · body.outline · body.shading":"Shared skin fill, outline { color, width }, cel material { mode: cel | none, light: [x,y], shadow, opacity, highlight }.","softCartoonCharacter(name, options?)":"Original youngMan / youngWoman / childBoy / childGirl story presets. Children have larger head proportions, shorter limbs and rounded torsos; every face, hair, build, hand, clothing and material option can be overridden.","face.projection":"Organic default volume follows the head axes, keeps both eyes in three-quarter views and projects a small nose above the mouth; opaque hair covers features. cartoon keeps the classic face slide.","outfitPreset(category, overrides?)":"Fresh JSON Everyday / Formal / Casual wardrobe defaults for every actor; top: tshirt | shirt | blouse | dress, trouserStyle: plain | jeans | cargo, colours, sleeves, bottoms, collar and tie are editable.",leafOutfit:"Organic-only JSON garment { top?, color?, accent?, length? }; curved leaves follow torso/thighs at native part depths. Everyday basicOutfit also follows organic contours."},poses:Object.keys(ce),dances:Object.keys(cn),expressions:Object.keys(_a),faceStyles:["simple","anime"],faceShapes:["round","angular"],gags:Object.keys(To),builds:Object.keys(ao),hair:Object.keys(Xa),hairColors:{...me},facialHair:Object.keys(Za),glasses:Object.keys(tl),hats:Object.keys(xo),feet:[...id],cast:Object.keys(Kl),heldItems:Object.fromEntries(Object.entries(rl).map(([s,i])=>[s,i.hands])),handMeetings:Object.keys(ai)},codePanel:{languages:jo,removeStyles:Yo,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:Fl},surfaces:{code:ii,board:xe,chart:yn,prop:cs},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: ${os.join(", ")} (default contact, or start when the beat has none); not ms`,until:"a moment of this beat, or { beat: index, at? } of a later one; sets the edit’s duration (carry needs it)"},cameraShots:{frame:"{ at, duration?, easing?, frame: { focus?: { x, y }, scale?, rotate? } }: push in, pull out, or cut (duration 0)",shake:"{ at, duration, shake: { strength?, frequency?, roll?, seed? } }",follow:"{ at, until, follow: { x: <the subject’s x keyframes>, lead?, y?, lag?, scale? } }: keeps a subject centred"},teach:{"lesson({ id })":"steps as timeline JSON: to, set, together, wait, marker (with pause, question, captions)","cells, pointer, stack, queue, table, pipeline":"diagram primitives (SVG markup + step helpers)","figure({ width, height, children })":"the SVG holding the pieces"},cli:{"tinyfly capabilities [--json]":"this catalog","tinyfly check <beats.json>":"check a beat script (names, fields) with suggestions","tinyfly validate <timeline.json> [--markup file]":"check a timeline against its markup","tinyfly render <timeline.json> <markup> [--at …]":"a frame as static markup","tinyfly video <scene.mjs> [--stills dir --times …]":"MP4, or PNG stills to look at"}}}const wt=t=>t.map(e=>`\`${e}\``).join(", "),Im=t=>Object.entries(t).map(([e,n])=>`| \`${e}\` | ${n.unit??n.kind??""} | ${n.description} |`).join(`
|
|
63
|
+
`);function E3(t,e={}){const n=$m(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: ${wt(n.easings.named)}.`,"",...Object.entries(n.easings.parametric).map(([o,r])=>`- ${o}: \`${r}\``),"","## Track kinds","",...Object.entries(n.trackKinds).map(([o,r])=>`- **${o}**: ${r}`),"","## Canvas targets","","Types: `rect`, `circle`, `text`, `line`, `path`, `image`, `custom`. `describeTarget(target)` lists what one can animate with its values; `checkTracks(tracks, targets)` checks tracks before playing them.","","| Property | Unit | What it does | Types |","|---|---|---|---|",...Object.entries(n.canvasProperties).map(([o,r])=>`| \`${o}\` | ${r.unit??r.kind??""} | ${r.description} | ${r.types.length===7?"all":r.types.join(", ")} |`),"","## Stick figure (`@algorisys/tinyfly/characters`)","","`stickFigureTarget({ x, y, style })` is a custom canvas target; its props are the pose fields and the props below. Pose it with tracks (`poseTracks`), or write beats (`scriptTracks`).","","Style proportions: `headSize` is a fraction of height; `armLength` multiplies both upper arm and forearm lengths (default 1, positive finite). Hands, shoulders, torso and legs retain their sizes.","","### Pose fields","","| Field | Unit | What it does |","|---|---|---|",Im(s.poseFields),"","### Other props","","| Prop | Unit | What it does |","|---|---|---|",Im(s.props),"",`With \`style.hands\`, each hand has \`hand.left.<field>\` / \`hand.right.<field>\` props: ${wt(Object.keys(s.handFields))}.`,"",`**Poses** (a beat's \`do\`, or a pose key): ${wt(s.poses)}.`,"",`**Expressions** (a beat's \`mood\`): ${wt(s.expressions)}.`,"",`**Gags** (ms): ${Object.entries(s.gags).map(([o,r])=>`\`${o}\` (${r})`).join(", ")}.`,"",`**Gaits**: ${wt(s.gaits)}. **Acting styles** (\`style\`): ${wt(s.actingStyles)}.`,"","### Beat scripts","",`\`scriptTracks(target, beats, { from, ground, height, facing, style })\`. A beat has these fields only: ${wt(s.beatFields)}. Times are ms; \`to\` and \`target\` are scene px; \`onto\` is a floor's scene y.`,"","`characterScript(target, who, beats, options)` compiles the same beats for a v2 `character()` on a `characterTarget` (every option but `height`; the same result, its key poses on the human body; the walk phase keyed to that character's stride, and `walk` / `walking` / `gait` tracks that step the gait as the target draws). Add `hairFollowTracks(target, tracks, who)` after it so hanging hair swings.","","| `do` | Needs | What happens |","|---|---|---|",...Object.entries(s.actions).map(([o,r])=>`| \`${o}\` | ${(r.needs??[]).map(a=>`\`${a}\``).join(", ")} | ${r.summary} |`),"","Beats that touch something report `contact` (and `release`) times in `result.beats[i]`; key the thing they touch to those.","",`**Dances** (\`dancer(style, { move })\`): ${Object.entries(s.dances).map(([o,r])=>`\`${o}\` (${r.join(", ")})`).join("; ")}.`,"",`**Flips**: ${Object.entries(s.flips).map(([o,r])=>`\`${o}\` (${r})`).join(", ")}.`,"",`**Hand shapes**: ${wt(s.handShapes)}. **Mudras**: ${wt(s.mudras)}.`,"","### Your own actions, gaits and personas","","Nothing is registered globally: pass your definitions where they are used.","",...Object.entries(n.custom.api).map(([o,r])=>`- \`${o}\`: ${r}`),"",...Object.keys(n.custom.actions).length||Object.keys(n.custom.gaits).length?["**This cast’s own:**","",...Object.entries(n.custom.actions).map(([o,r])=>`- \`${o}\`${r.needs?.length?` (needs ${r.needs.map(a=>`\`${a}\``).join(", ")})`:""}: ${r.summary}`),...Object.entries(n.custom.gaits).map(([o,r])=>`- \`${o}\` (gait): ${r}`),""]:[],"## Props (everyday objects with behaviours)","","A prop is a 3D rig of simple parts drawn with the characters’ pens (clean, pencil, silhouette), so it turns toward the camera (`turn`), and its beats go through the same acting pass (anticipation, overshoot, overlap; `exaggeration` scales them).","",...Object.entries(n.props.api).map(([o,r])=>`- \`${o}\`: ${r}`),"",`Prop beat fields: ${wt(n.props.beatFields)}. Every prop has the controls ${Object.keys(n.props.commonControls).map(o=>`\`${o}\``).join(", ")} and the actions ${Object.keys(n.props.commonActions).map(o=>`\`${o}\``).join(", ")}.`,"","Scenery: `scenery({ x, y, width, height, kind: sky | room, hour, clouds, wind, rain, snow, horizon: hills | city | flat })` is a canvas target whose values `hour` (0–24), `clouds`, `rain`, `snow` (0–1) and `wind` (−1..1) are tracks (`set(prop, { at, value, duration })`, `tracks(id)`; `anchor('sun' | 'moon' | 'horizon' | 'ground', time)`); the same `wind` streams hair (`hairFollowTracks(…, { wind })`). `scenePreset('park' | 'street' | 'office' | 'home', { width, height })` lays out scenery and props as data; `buildScene` builds them into targets.","","| Preset | Family | Actions (needs) | Controls | Anchors |","|---|---|---|---|---|",...Object.entries(n.props.presets).map(([o,r])=>`| \`${o}()\` | ${r.family} | ${Object.entries(r.actions).map(([a,l])=>`\`${a}\`${l.needs?.length?` (${l.needs.join(", ")})`:""}`).join(", ")} | ${r.controls.map(a=>`\`${a}\``).join(", ")} | ${r.anchors.join(", ")} |`),"","## Character (v2 human)","",`Poses: ${wt(n.character.poses)}. Expressions: ${wt(n.character.expressions)}. Gags: ${wt(n.character.gags)}.`,`Native dances: ${wt(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\`: ${wt(n.character.builds)}`,`- \`figure\`: ${wt(n.character.figureStyles)}`,...Object.entries(n.character.body).map(([o,r])=>`- \`${o}\`: ${r}`),`- \`hair\`: ${wt(n.character.hair)} (colours: ${wt(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\`: ${wt(n.character.facialHair)}`,`- \`glasses\`: ${wt(n.character.glasses)}; \`hat\`: ${wt(n.character.hats)}; \`ears: true\`; \`face: { teeth, tongue }\` (shown when the mouth opens); \`feet\`: ${wt(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)\`: ${wt(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: ${wt(n.character.faceStyles)}; \`face: { style: 'anime', iris: '#4b7fce', lashes: true, ageLines: 0.8 }\` uses coloured eyes and the same expressions, blinks and gaze. \`ANIME_CAST\` contains eight age presets, also available through \`castMember\`.`,`- Face shapes: ${wt(n.character.faceShapes)}; \`face: { shape: 'angular', jawWidth: 0.74, chinWidth: 0.14, eyeScale: 0.8, eyeAspect: 0.65 }\` sets a tapered 3D jaw and narrower anime eyes; \`jawRoundness: 1\` softens the cheek/chin corners (default 0 keeps sharp jaws). \`MANGA_CAST\` contains four original young adult presets; hair styles \`mangaSpikes\` and \`mangaSweep\` remain editable.`,"- Hair in motion (pose fields): `hair.swing` (degrees round the head, + toward its left), `hair.trail` (head radii back), `hair.lift` (head radii up); key them with `hairFollowTracks(target, tracks, who)` after the character's tracks, or `hairFollow` + `hairMotionAt` when posing per frame",`- \`holding\`: ${Object.entries(n.character.heldItems).map(([o,r])=>`\`${o}\` (${r==="both"?"both":r==="either"?"one hand or both":"left or right"})`).join(", ")}; pose fields \`held.left\`, \`held.right\`, \`held.both\` (below 0.5 lets go); \`handGrip(joints, side)\``,`- \`meetHands(kind, a, b)\` (stand them \`meetingSpacing(kind, a, b)\` apart): ${wt(n.character.handMeetings)}; \`embrace(a, b)\` (a hug, \`embraceSpacing\` apart); \`helpUp(helper, sitter, progress)\` (0 on the floor, hand taken; 1 standing; \`helpUpSpacing\` apart)`,"- Everyday cycles like a gait: `humanCyclePose('sweeping' | 'brushing', phase, base)` (0 → 1 is one stroke and back; sweeping with `holding: { right: 'broom' }`)","","## Code panel","",`\`codePanel({ code, language, x, y, fontSize?, lineHeight?, width? })\`: a code listing as a scene object. Languages: ${wt(n.codePanel.languages)}. Remove styles: ${wt(n.codePanel.removeStyles)}.`,"",...Object.entries(n.codePanel.anchors).map(([o,r])=>`- \`${o}\`: ${r}`),"",...Object.values(n.codePanel.edits).map(o=>`- \`${o.split(":")[0]}\`:${o.split(":").slice(1).join(":")}`),"","## Surfaces","","Scene objects figures act on. Places are named `kind:args`: `surface.anchor(name)` gives the box there (stand on `top`, point at `x`, `y`; pass it as a beat `target`), `surface.piece(name)` makes the part there come loose, and `surface.edit(name, anchor, options)` changes the surface at a time (`at`, ms).","","Beats name places and say what surfaces do in answer (`surfaceScript`):","",...Object.entries(n.surfaceScript).map(([o,r])=>`- \`${o}\`: ${r}`),"",...Object.entries(n.surfaces).flatMap(([o,r])=>[`### ${o}`,"",...r.create?[`\`${r.create}\``,""]:[],"Anchors:",...Object.entries(r.anchors).map(([a,l])=>`- \`${a}\`: ${l}`),"","Edits:",...Object.entries(r.edits).map(([a,l])=>`- \`${a}\`: ${l}`),""]),"## Camera shots (`cameraTracks(shots, { stage })`)","",...Object.entries(n.cameraShots).map(([o,r])=>`- **${o}**: \`${r}\``),"","## Teaching (`@algorisys/tinyfly/teach`)","",...Object.entries(n.teach).map(([o,r])=>`- \`${o}\`: ${r}`),"","## Command line","",...Object.entries(n.cli).map(([o,r])=>`- \`${o}\`: ${r}`),""].join(`
|
|
64
|
+
`)}function A3(t,e,n,s={}){const i=s.color??"#555",o=s.size??60;for(const r of e){const a=(n-r.time)/r.length;if(a<=0||a>=1)continue;const l=Xt(`${r.kind}:${r.time}:${r.x}`);r.kind==="dust"?jg(t,{x:r.x,y:r.y},a,{size:o,color:i,seed:l}):r.kind==="exhaust"?I3(t,r,a,o,i,l):r.kind==="skid"?O3(t,r,a,n,i):r.kind==="honk"?_3(t,r,a,o,i):r.kind==="smoke"?P3(t,r,n,o,i):r.kind==="leaves"&&$3(t,r,a,o,s.leafColor??"#5cae5a",i,l)}}function P3(t,e,n,s,i,o){const r=e.direction??1,a=380,l=1500;t.save(),t.strokeStyle=i,t.lineWidth=Math.max(1,s*.025);for(let c=e.time;c<=e.time+e.length-l;c+=a){const h=(n-c)/l;if(h<=0||h>=1)continue;const u=Math.sin(c/97+h*4)*s*.06,d=e.x+r*h*s*.7+u,f=e.y-h*s*1.6;t.globalAlpha=Math.min(1,h*6)*(1-h)*.85,t.beginPath(),t.arc(d,f,s*(.07+h*.2),0,Math.PI*2),t.stroke()}t.restore()}function $3(t,e,n,s,i,o,r){const a=e.direction??1,l=e.toY??e.y+s*3;t.save(),t.lineWidth=Math.max(1,s*.02),t.strokeStyle=o,t.fillStyle=i;for(let c=0;c<4;c++){const h=Xt(`${r}:${c}`)%1e3/1e3,u=Math.min(1,n*(1.1+h*.4)),d=e.x+(h-.5)*s*1.2,f=e.y+(h-.3)*s*.4,p=u*u*.4+u*.6,g=d+a*u*s*(.6+h)+Math.sin(u*9+h*6)*s*.18,m=Math.min(l-2,f+(l-f)*p);t.globalAlpha=n>.85?(1-n)/.15:1,t.save(),t.translate(g,m),t.rotate(Math.sin(u*7+h*5)*1.2),t.beginPath(),t.ellipse(0,0,s*.07,s*.035,0,0,Math.PI*2),t.fill(),t.stroke(),t.restore()}t.restore()}function I3(t,e,n,s,i,o){const r=e.direction??-1;t.save(),t.strokeStyle=i,t.lineWidth=Math.max(1,s*.025);for(let a=0;a<3;a++){const l=n*1.6-a*.25;if(l<=0||l>=1)continue;const c=(Xt(`${o}:${a}`)%100/100-.5)*s*.1,h=e.x+r*l*s*.9,u=e.y-l*s*.45+c;t.globalAlpha=(1-l)*.9,t.beginPath(),t.arc(h,u,s*(.06+l*.14),0,Math.PI*2),t.stroke()}t.restore()}function O3(t,e,n,s,i){const o=e.toX??e.x,r=Math.min(1,(s-e.time)/e.length*3),a=e.x+(o-e.x)*r;t.save(),t.strokeStyle=i,t.lineCap="round",t.globalAlpha=n<.6?.8:.8*(1-(n-.6)/.4),t.lineWidth=3;for(const l of[-2,4])t.beginPath(),t.moveTo(e.x,e.y+l),t.lineTo(a,e.y+l),t.stroke();t.restore()}function _3(t,e,n,s,i){const o=e.direction??1;t.save(),t.strokeStyle=i,t.lineWidth=Math.max(1.5,s*.04),t.lineCap="round",t.globalAlpha=n<.7?1:(1-n)/.3;const r=s*(.15+.5*(1-(1-n)**2));for(let a=-1;a<=1;a++){const l=a*Math.PI/7,c=e.x+o*Math.cos(l)*r,h=e.y+Math.sin(l)*r;t.beginPath(),t.arc(c,h,s*.12,o>0?-Math.PI/3:Math.PI*2/3,o>0?Math.PI/3:Math.PI*4/3),t.stroke()}t.restore()}function C3(t){const e=new It({id:`${t.propId}-ride`,tracks:t.propTracks.filter(h=>h.target===t.propId)}),n=t.every??33,s=[],i=[],o=[],r=[];let a=1;for(let h=t.start;;h=Math.min(t.end,h+n)){const u=or(t.prop,{state:e.getStateAtTime(h)},t.propId),d=u.anchor(t.anchor);s.push({time:h,value:d.x+(t.offset?.x??0)-t.figure.x}),i.push({time:h,value:d.y+(t.offset?.y??0)-t.figure.y});const f=Math.sin(u.values.turn*Math.PI/2);if(Math.abs(f)>.15&&(a=f>0?1:-1),o.push({time:h,value:Math.abs(f)}),r.push({time:h,value:a}),h>=t.end)break}const l=t.figureId,c=[{id:`${l}-x`,target:l,property:"x",keyframes:s},{id:`${l}-y`,target:l,property:"y",keyframes:i}];return t.turn!==!1&&c.push({id:`${l}-turn`,target:l,property:"turn",keyframes:o},{id:`${l}-facing`,target:l,property:"facing",keyframes:H3(r)}),c}function H3(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 R3(t,e,n){const s=r=>`${r.target}\0${r.property}`,i=new Map(e.map(r=>[s(r),r]));return[...t.map(r=>{const a=i.get(s(r));if(!a)return r;i.delete(s(r));const c=[...(r.keyframes??[]).filter(h=>h.time<n.from||h.time>n.to),...a.keyframes??[]].sort((h,u)=>h.time-u.time);return{...r,keyframes:c}}),...i.values()]}function L3(t){const e=new It({id:`${t.leaderId}-tow`,tracks:t.leaderTracks.filter(f=>f.target===t.leaderId)}),n=t.every??33,s=t.towed,i=s.x+s.width/2,o=s.props,r=s.prop.wheelRadius,a=[],l=[],c=[];let h=o.wheelSpin??0,u;for(let f=t.start;;f=Math.min(t.end,f+n)){const p=or(t.leader,{state:e.getStateAtTime(f)},t.leaderId),g=p.anchor(t.hitch),m=p.values.turn,w=ls(s.prop,{...o,turn:m},s.propScale).anchors[t.anchor];if(!w)throw new Error(`propTow: ${s.prop.kind} has no anchor "${t.anchor}"`);const v=g.x-w.point.x;if(u!==void 0&&r){const k=Math.sin(m*Math.PI/2);h+=(v-u)*(k||1)/s.propScale/r*(180/Math.PI)}if(u=v,a.push({time:f,value:v-i}),l.push({time:f,value:m}),c.push({time:f,value:h}),f>=t.end)break}const d=t.towedId;return[{id:`${d}-x`,target:d,property:"x",keyframes:a},{id:`${d}-turn`,target:d,property:"turn",keyframes:l},...r?[{id:`${d}-wheelSpin`,target:d,property:"wheelSpin",keyframes:c}]:[]]}const Om=new WeakMap;function N3(t,e){const n=e?.some(Boolean)?e.map(d=>d?1:0).join(""):"";let s=Om.get(t);s||Om.set(t,s=new Map);const i=s.get(n);if(i)return i;const o=di(t),r={vertices:o.vertices,faces:o.faces.filter((d,f)=>!e?.[f])},a=r.vertices.flatMap(d=>[d[0],d[1],d[2]]),l=r.vertices.map(()=>[0,0,0]),c=[];r.faces.forEach(d=>{for(const g of d.corners)for(const m of[0,1,2])l[g][m]+=d.normal[m];const[f,...p]=d.corners;for(let g=0;g+1<p.length;g++){const[m,w,v]=[f,p[g],p[g+1]],[k,y,T]=[r.vertices[m],r.vertices[w],r.vertices[v]],$=[y[0]-k[0],y[1]-k[1],y[2]-k[2]],M=[T[0]-k[0],T[1]-k[1],T[2]-k[2]],x=[$[1]*M[2]-$[2]*M[1],$[2]*M[0]-$[0]*M[2],$[0]*M[1]-$[1]*M[0]],S=x[0]*d.normal[0]+x[1]*d.normal[1]+x[2]*d.normal[2];c.push(...S>=0?[m,w,v]:[m,v,w])}});const h=l.flatMap(d=>{const f=Math.hypot(...d)||1;return[d[0]/f,d[1]/f,d[2]/f]}),u=Ro({positions:a,normals:h,indices:c});return s.size>=16&&s.clear(),s.set(n,u),u}function F3(t,e,n={}){const s=t.ink??n.ink??"#26262b",i=(n.outline??2)*(t.outline??1),o=t.glow&&e.glow>0?W3(t.glow.color,e.glow):void 0;return{color:t.fill??s,creases:di(t.shape).creases!==!1,shading:n.shading??"toon",...i>0?{outline:{width:i,color:s}}:{},...o?{emissive:o}:{},...t.seeThrough?{opacity:.45*e.opacity}:e.opacity<1?{opacity:e.opacity}:{}}}function W3(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 D3=Ro(Nf(1,.002,28));function B3(t,e,n){const s=t.rig,[i,o]=s.footprint??[s.length*.45,s.length],r=Math.max(0,At(s,e,"lift")),a=Math.max(0,At(s,e,"size"))/(1+r*.8);return{mesh:D3,world:Ot(n,jr([0,.004,0],[0,0,0,1],[i*.55*a||1e-4,1,o*.55*a||1e-4])),material:{color:"#000000",shading:"unlit",opacity:.16*a}}}const z3=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),q3=1,Y3={kind:"prop",validate(t){const e=t,n=typeof e.prop=="string"&&e.prop in us?[]:[ft("prop preset",e.prop,Object.keys(us))];for(const[s,i]of[[0,"rotateX"],[1,"rotateY"],[2,"rotateZ"]])i in e&&n.push(`${i} is a track, not a field: place it turned with rotation: [${[0,1,2].map(o=>o===s?e[i]:0).join(", ")}]`);return n},prepare(t){const e=t;return Ec(e.prop,e.options)},resolve({object:t,prepared:e,values:n,world:s,camera:i,lights:o=[],fog:r,toScreen:a}){const l=t,c=e,h={...l.values};for(const[M,x]of n)typeof x=="number"&&!z3.has(M)&&(h[M]=x);h.turn=0,h.tilt=0;const u=Ot(i.view,s),d={toView:M=>Gt(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=Ip(c.rig,h),x=M.map(({part:P,local:A})=>({part:P.id,mesh:di(P.shape),...gc(di(P.shape),A)})),S=xp(x),E=M.map((P,A)=>({...P,hidden:Ep(P.part.id,x[A].mesh,P.local,x[A].key,S)})).filter(({opacity:P})=>P>.01).map(({part:P,matrix:A,glow:I,opacity:_,hidden:N})=>({mesh:N3(P.shape,N),world:Ot(s,A),material:F3(P,{glow:I,opacity:_},{shading:l.shading,ink:l.ink,outline:l.outline})}));return{meshes:l.shadow===!1?E:[B3(c,h,s),...E]}}const p=a(f),g=a(d.toView([0,c.rig.height/2+1,0])),m=Math.hypot(g.x-p.x,g.y-p.y),w=o.length===0?void 0:(M,x)=>{const S=Gt(s,M),E=[s[0]*x[0]+s[4]*x[1]+s[8]*x[2],s[1]*x[0]+s[5]*x[1]+s[9]*x[2],s[2]*x[0]+s[6]*x[1]+s[10]*x[2]],P=Math.hypot(...E)||1;return{light:Ff(S,[E[0]/P,E[1]/P,E[2]/P],o),fog:Wf(r,Math.hypot(S[0]-i.position[0],S[1]-i.position[1],S[2]-i.position[2]))}},v=wc(c.rig,h,d,m,{perspective:!0,near:i.near,slice:q3,light:w}),k={look:l.look,style:l.style,ink:l.ink,paper:l.paper,fog:r?.color},y=wl(v),T=v.cells??[],$=Math.max(...T.map(M=>-M.depth),-f[2]);return{drawables:[...l.shadow===!1?[]:[{depth:$+c.rig.length,draw:M=>kl(M,v,k)}],...T.map(M=>({depth:-M.depth,draw(x,S){x.lineCap="round",x.lineJoin="round",Bf(x,M.parts,y,{...k,time:S.time})}}))]}}},Ic=["do","at","for","to","through","toward","speed","height","open","on","wind"],K3=.25,j3=800/180,X3=220,G3=300,U3=["turn"];function V3(t){const e=hr(t),n=Object.keys(t.moves??{});return Object.keys(e).filter(s=>!n.includes(s)&&!U3.includes(s)&&!(e[s].needs??[]).includes("to"))}function _m(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=V3(e),i=[...n,"face","hold",...s.filter(r=>r!=="hold")],o=[];return t.forEach((r,a)=>{const l=u=>o.push({beat:a,message:u});if(!r||typeof r!="object"||Array.isArray(r))return l(`Each beat must be an object like { do: '${i[0]??"hold"}' }.`);const c=r,h={duration:"for",path:"through",points:"through",position:"to",heading:"toward",direction:"toward"};for(const u of Object.keys(c))Ic.includes(u)||l(ft("beat field",u,Ic,h[u]));if(typeof c.do!="string"||!i.includes(c.do)){const u=c.do==="turn"?"face":void 0;return l(ft(`${e.kind} 3D beat`,c.do,i,u))}n.includes(c.do)&&(c.to===void 0&&c.through===void 0&&l(`\`${c.do}\` needs \`to\` ([x, z] metres) or \`through\` (a list of them).`),c.to!==void 0&&!pn(c.to)&&l(`\`to\` is a point on the ground, [x, z] metres (got ${JSON.stringify(c.to)}).`),c.through!==void 0&&!(Array.isArray(c.through)&&c.through.length>0&&c.through.every(pn))&&l("`through` is a list of points on the ground, each [x, z] metres.")),c.do==="face"&&!(pn(c.toward)||typeof c.toward=="number")&&l("`face` needs `toward`: a point [x, z] or a heading in degrees.")}),o}function J3(t,e,n,s){const i=_m(n,e);if(i.length>0)throw new Error(`propScript3D (${e.kind}): ${i.length} problem(s) in the beats:
|
|
65
65
|
${i.map(k=>` beat ${k.beat}: ${k.message}`).join(`
|
|
66
|
-
`)}`);const o={};for(const k of[...Object.keys(ss),...Object.keys(e.rig.controls)])o[k]=s.values?.[k]??At(e.rig,{},k);let[r,a]=s.position??[0,0],l=s.heading??0;const c=new Map,h=(k,b,E,$="linear")=>{const S=c.get(k)??[];S.push({time:b,value:E,easing:$}),c.set(k,S)},u=(k,b,E)=>h(k,b,E);h("x",0,r),h("z",0,a),h("rotateY",0,l);const d=(k,b)=>{const E=Io(l,b);if(Math.abs(E)<1)return k;const $=Math.max(a3,Math.abs(E)*r3);return u("rotateY",k,l),l+=E,h("rotateY",k+$,l,"ease-in-out"),k+$},f=(k,b,E)=>{const $=Of([[r,a],...b.through??[b.to]]);if($.length<2)return E;const S=d(E,Un($[0].point,$[1].point)),x=$[$.length-1].at,M=b.for??x/(b.speed??k.speed)*1e3,T=Lt("ease-in-out"),I=Math.min(l3,M/4);for(const[G,Z]of Object.entries(k.set??{}))u(G,S,o[G]),h(G,S+1,Z),o[G]=Z;const A=k.flies?b.height??(o.lift>.05?o.lift:2):void 0,_=A!==void 0&&A>.05;for(const[G,Z]of Object.entries(k.hold??{}))u(G,S,o[G]),h(G,S+I,Z,"ease-out"),_||(h(G,S+M-I,Z),h(G,S+M,0,"ease-in")),o[G]=_?Z:0;A!==void 0&&(u("lift",S,o.lift),h("lift",S+Math.min(M*.35,1400),A,"ease-out"),h("lift",S+M,A),o.lift=A);const C={...o};let N=l;for(let G=0;;G=Math.min(x,G+o3)){const Z=S+Cf(T,G/x)*M,{point:Y,direction:L}=_f($,G);N+=Io(N,Un([0,0],L)),h("x",Z,Y[0]),h("z",Z,Y[1]),h("rotateY",Z,N);for(const[z,O]of Object.entries(k.perMetre??{}))h(z,Z,C[z]+G*O);for(const[z,O]of Object.entries(k.perSecond??{}))h(z,Z,C[z]+(Z-S)/1e3*O);if(G>=x)break}for(const[G,Z]of Object.entries(k.perMetre??{}))o[G]=C[G]+x*Z;for(const[G,Z]of Object.entries(k.perSecond??{}))o[G]=C[G]+M/1e3*Z;return[r,a]=$[$.length-1].point,l=N,S+M},p=(k,b)=>{const E=Object.fromEntries(Object.entries(k).filter(([S])=>!["at","to","through","toward"].includes(S))),$=Up(t,e,[E],{start:{...o,turn:1},scale:100,style:s.style,exaggeration:s.exaggeration});for(const S of $.tracks){if(d3.includes(S.property))continue;const x=S.keyframes??[],M=o[S.property];if(!x.every(T=>T.value===M)){u(S.property,b,M);for(const T of x)T.time>0&&c.get(S.property).push({...T,time:b+T.time});o[S.property]=x[x.length-1].value}}return b+$.duration},g=[];let m=0;for(const k of n){const b=k.at??m;let E=b;const $=e.moves?.[k.do];$?E=f($,k,b):k.do==="face"?E=d(b,typeof k.toward=="number"?k.toward:Un([r,a],k.toward)):k.do==="hold"?E=b+(k.for??1e3):E=p(k,b),g.push({do:k.do,start:b,end:E}),m=E}const w=`${s.scene}/${t}`;return{tracks:[...c].map(([k,b])=>({id:`${t}-${k}`,target:w,property:k,keyframes:If(b)})),duration:m,beats:g,end:{position:[r,a],heading:l,values:{...o}}}}const d3=["x","y","turn","facing","tilt"],f3=.35,pc={seated:le.sit,astride:{...le.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:{...le.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:{...le.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:{...le.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}},g3=22,tm=38;function mc(t,e=pc.cycling){const n=t*Math.PI*2,s=r=>({swing:(e["leg.left.swing"]??40)+g3*Math.cos(n+r),knee:(e["leg.left.knee"]??70)+tm*(.5+.5*Math.cos(n+r))-tm*.5,ankle:12*Math.sin(n+r)}),i=s(0),o=s(Math.PI);return{...e,"leg.left.swing":i.swing,"leg.left.knee":i.knee,"leg.left.ankle":i.ankle,"leg.right.swing":o.swing,"leg.right.knee":o.knee,"leg.right.ankle":o.ankle}}function p3(t){const e=t.cadence??1.2,n=Math.max(2,t.samplesPerTurn??8),s=1e3/e/n,i=[];for(let o=t.start,r=0;o<t.end;o+=s,r++)i.push({time:Math.round(o),pose:mc((o-t.start)/1e3*e,t.base),...r>0?{act:!1}:{}});return i.push({time:t.end,pose:mc((t.end-t.start)/1e3*e,t.base),act:!1}),i}const em=(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 m3(t){const e=`${t.scene}/${t.propId}`,n=new It({id:`${t.propId}-ride-3d`,tracks:t.propTracks.filter(m=>m.target===e)}),s=t.placement??{},[i,o,r]=s.position??[0,0,0],a=t.prop.rig,l=mo({...t.character,height:1}),c={...ht,...t.pose??pc.seated},h=Ns(l.plan,c,{height:t.height??1.7,contact:l.contact}).hip,u=t.facing??0,d=t.every??33,f={x:[],y:[],z:[],rotateY:[]};for(let m=t.start;;m=Math.min(t.end,m+d)){const w=n.getStateAtTime(m).values.get(e)??new Map,v=(C,N)=>{const B=w.get(C);return typeof B=="number"?B:N},k={...s.values};for(const C of Object.keys(a.controls))k[C]=v(C,s.values?.[C]??At(a,{},C));for(const C of["pitch","roll","squash","lift","lean","size"])k[C]=v(C,s.values?.[C]??At(a,{},C));const b=Zg(a,k)[t.anchor];if(!b)throw new Error(`propRide3D: ${t.prop.kind} has no anchor "${t.anchor}" (it has ${Object.keys(a.anchors??{}).join(", ")||"none"})`);const E=v("rotateY",s.heading??0),$=em(b,E),S=[v("x",i)+$[0],v("y",o)+$[1],v("z",r)+$[2]],x=E+u,M=em(h,x);let T=[S[0]-M[0],S[1]-M[1],S[2]-M[2]];const I=(C,N)=>{const B=N*N*(3-2*N);return[C[0]+(T[0]-C[0])*B,T[1]*B+f3*Math.sin(Math.PI*N),C[1]+(T[2]-C[1])*B]},A=t.mount?Math.max(1,t.mount.for??450):0,_=t.dismount?Math.max(1,t.dismount.for??450):0;if(t.mount&&m<t.start+A?T=I(t.mount.from,(m-t.start)/A):t.dismount&&m>t.end-_&&(T=I(t.dismount.to,(t.end-m)/_)),f.x.push({time:m,value:T[0]}),f.y.push({time:m,value:T[1]}),f.z.push({time:m,value:T[2]}),f.rotateY.push({time:m,value:x}),m>=t.end)break}const p=t.riderId,g=`${t.scene}/${p}`;return Object.keys(f).map(m=>({id:`${p}-${m}`,target:g,property:m,keyframes:f[m]}))}const nm={ground:"#7fb56a",hills:"#5f9a58",city:"#4b5468",cloud:"#ffffff",sun:"#ffd45c",moon:"#f3f0e0",rain:"#9fc4e8",snow:"#ffffff",wall:"#e9e1cf",floor:"#b08a5e",skirting:"#8a6a44",frame:"#f7f3ea"},oi=[[0,"#0b1530","#1b2a4a"],[4.5,"#141a3e","#2a2f5a"],[6,"#4a3f7a","#f0a070"],[7.5,"#86c2ee","#d8ecf8"],[12,"#5aaef2","#c0e2f8"],[16.5,"#69b0e6","#f5d79a"],[18.5,"#4c3f78","#f08a5a"],[20.5,"#17203f","#2d3660"],[24,"#0b1530","#1b2a4a"]],ri=(t,e,n)=>{const s=r=>[1,3,5].map(a=>parseInt(r.slice(a,a+2),16)),[i,o]=[s(t),s(e)];return`#${i.map((r,a)=>Math.round(r+(o[a]-r)*n).toString(16).padStart(2,"0")).join("")}`},y3=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 sm(t){const e=(t%24+24)%24;for(let n=1;n<oi.length;n++){const[s,i,o]=oi[n-1],[r,a,l]=oi[n];if(e<=r){const c=(e-s)/(r-s);return{top:ri(i,a,c),bottom:ri(o,l,c)}}}return{top:oi[0][1],bottom:oi[0][2]}}const b3=(t,e)=>{const n=((t-e)%24+24)%24;return n<=12?n/12:-1},w3=9,k3=55,v3=28;function im(t){const{x:e,y:n,width:s,height:i}=t,o=t.kind??"sky",r=t.ground??n+i*.85,a={...nm,...t.colors},l=t.horizon??"hills",c=t.window!==!1,h=_e(t.seed??1),u=s*i/1e5,d=Array.from({length:Math.ceil(w3*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(k3*u)+4},()=>({u:h.next(),v:h.next(),speed:.8+h.next()*.5})),p=Array.from({length:Math.ceil(v3*u)+4},()=>({u:h.next(),v:h.next(),speed:.7+h.next()*.6,sway:h.next()*Math.PI*2,size:1.5+h.next()*2})),g=Array.from({length:Math.ceil(30*u)+10},()=>({u:h.next(),v:h.next()*.6,size:.6+h.next()*1.2})),m=Array.from({length:6},()=>({phase:h.next()*Math.PI*2,amp:.5+h.next()})),w=Array.from({length:24},()=>({h:.35+h.next()*.65,w:.6+h.next()*.8,windows:h.next()>.3})),v={hour:t.hour??12,clouds:t.clouds??.3,wind:t.wind??0,rain:t.rain??0,snow:t.snow??0},k=Vn(),b=(T,I)=>k.keys(T)?.length?k.valueAt(T,I):v[T],E=(T,I)=>{const A=b3(T,I),_=A<0?.5:A,C=r-n;return{x:.1*s+.8*s*_,y:A<0?C+i*.2:C-Math.sin(_*Math.PI)*C*.8,up:A>=0}},$=(T,I,A,_,C)=>{const N=I("hour"),{top:B,bottom:G}=sm(N),Z=T.createLinearGradient(0,_.y,0,_.ground);Z.addColorStop(0,B),Z.addColorStop(1,G),T.fillStyle=Z,T.fillRect(_.x,_.y,_.w,_.ground-_.y);const Y=y3(N);if(Y<.6){T.fillStyle="#ffffff",T.globalAlpha=(.6-Y)/.6*.9;for(const D of g)T.beginPath(),T.arc(_.x+D.u*_.w,_.y+D.v*(_.ground-_.y),D.size,0,Math.PI*2),T.fill();T.globalAlpha=1}const L=E(N,6),z=E(N,18),O=Math.min(_.w,_.h)*.06;if(L.up&&(T.fillStyle=a.sun,T.beginPath(),T.arc(_.x+L.x/s*_.w,_.y+L.y/i*_.h,O,0,Math.PI*2),T.fill()),z.up){const D=_.x+z.x/s*_.w,K=_.y+z.y/i*_.h;T.fillStyle=a.moon,T.beginPath(),T.arc(D,K,O*.8,0,Math.PI*2),T.fill(),T.fillStyle=B,T.beginPath(),T.arc(D-O*.35,K-O*.15,O*.7,0,Math.PI*2),T.fill()}const P=Math.max(0,Math.min(1,I("clouds"))),H=Math.max(-1,Math.min(1,I("wind"))),W=Math.round(P*d.length);T.fillStyle=ri("#ffffff",a.cloud==="#ffffff"?"#ffffff":a.cloud,1),T.globalAlpha=.55+.4*Y;for(let D=0;D<W;D++){const K=d[D],V=((K.u*_.w+H*A*.012*(.6+K.size*.5))%(_.w*1.4)+_.w*1.4)%(_.w*1.4)-_.w*.2,F=_.x+V,X=_.y+(.08+K.v*.42)*(_.ground-_.y),j=Math.min(_.w,_.h)*.07*K.size;for(let Q=0;Q<K.puffs;Q++)T.beginPath(),T.ellipse(F+(Q-(K.puffs-1)/2)*j*.9,X+Q%2*j*.25,j*(Q%2?.8:1),j*.62,0,0,Math.PI*2),T.fill()}T.globalAlpha=1;const q=D=>ri(ri(D,"#0b1530",.65),D,Y);if(l==="hills"){T.fillStyle=q(a.hills),T.beginPath(),T.moveTo(_.x,_.ground);const D=40;for(let K=0;K<=D;K++){const V=K/D;let F=0;m.forEach((X,j)=>F+=Math.sin(V*Math.PI*(1.5+j*.7)+X.phase)*X.amp),T.lineTo(_.x+V*_.w,_.ground-Math.max(0,F)*_.h*.045-_.h*.03)}T.lineTo(_.x+_.w,_.ground),T.closePath(),T.fill()}else if(l==="city"){T.fillStyle=q(a.city);let D=_.x;const K=_.w/18;for(const V of w){if(D>_.x+_.w)break;const F=K*V.w,X=_.h*.22*V.h;if(T.fillRect(D,_.ground-X,F,X),V.windows&&Y<.5){T.fillStyle="#ffd66b",T.globalAlpha=.5-Y;for(let j=_.ground-X+6;j<_.ground-8;j+=9)for(let Q=D+4;Q<D+F-4;Q+=8)T.fillRect(Q,j,3,4);T.globalAlpha=1,T.fillStyle=q(a.city)}D+=F+K*.15}}T.fillStyle=q(a.ground),T.fillRect(_.x,_.ground,_.w,_.y+_.h-_.ground)},S=(T,I,A,_)=>{const C=Math.max(-1,Math.min(1,I("wind"))),N=Math.max(0,Math.min(1,I("rain"))),B=Math.max(0,Math.min(1,I("snow")));if(N>0){T.strokeStyle=a.rain,T.globalAlpha=.35+.45*N,T.lineWidth=1.2,T.lineCap="round";const G=_.h*.05,Z=C*.45,Y=Math.round(N*f.length);T.beginPath();for(let L=0;L<Y;L++){const z=f[L],O=((z.v*_.h+A*z.speed*.9)%_.h+_.h)%_.h,P=((z.u*_.w+O*Z)%_.w+_.w)%_.w;T.moveTo(_.x+P,_.y+O),T.lineTo(_.x+P+Z*G,_.y+O+G)}T.stroke(),T.globalAlpha=1}if(B>0){T.fillStyle=a.snow,T.globalAlpha=.85;const G=Math.round(B*p.length);for(let Z=0;Z<G;Z++){const Y=p[Z],L=((Y.v*_.h+A*Y.speed*.08)%_.h+_.h)%_.h,z=Math.sin(A*.002+Y.sway)*_.w*.02,O=((Y.u*_.w+z+C*L*.3)%_.w+_.w)%_.w;T.beginPath(),T.arc(_.x+O,_.y+L,Y.size,0,Math.PI*2),T.fill()}T.globalAlpha=1}},M={kind:"scenery",target:{type:"custom",x:e,y:n,width:s,height:i,props:v,about:{kind:o==="room"?"room":"sky",summary:o==="room"?"A room: a wall, a floor and a window on the sky. Its values are tracks: hour, clouds, wind, rain, snow (seen through the window).":`A sky over ${l==="flat"?"the ground":l}: the sun and moon on their arcs, stars, clouds on the wind, rain and snow. Its values are tracks: hour (0–24), clouds, wind (−1..1), rain, snow (0..1).`,props:Object.fromEntries(Object.keys(v).map(T=>[T,M3(T)]))},draw(T,I,A){const _=I.props??{},C=B=>Number(_[B]??v[B]??0);T.save();const N={x:0,y:0,w:s,h:i,ground:r-n};if(o==="sky")$(T,C,A,N),S(T,C,A,N);else if(T.fillStyle=a.wall,T.fillRect(0,0,s,N.ground),T.fillStyle=a.floor,T.fillRect(0,N.ground,s,i-N.ground),T.fillStyle=a.skirting,T.fillRect(0,N.ground-i*.012,s,i*.012),c){const B=s*.26,G=N.ground*.5,Z=s*.62,Y=N.ground*.14;T.fillStyle=a.frame,T.fillRect(Z-6,Y-6,B+12,G+12),T.save(),T.beginPath(),T.rect(Z,Y,B,G),T.clip(),$(T,C,A,{x:Z,y:Y,w:B,h:G,ground:Y+G*.8}),S(T,C,A,{x:Z,y:Y,w:B,h:G}),T.restore(),T.strokeStyle=a.frame,T.lineWidth=4,T.beginPath(),T.moveTo(Z+B/2,Y),T.lineTo(Z+B/2,Y+G),T.moveTo(Z,Y+G/2),T.lineTo(Z+B,Y+G/2),T.stroke()}T.restore()}},ground:r,anchor(T,I=1/0){const A=b("hour",I);if(T==="sun"||T==="moon"){const _=E(A,T==="sun"?6:18);return{x:e+_.x,y:n+_.y}}if(T==="horizon")return{x:e+s/2,y:r-i*.03};if(T==="ground")return{x:e+s/2,y:r};throw new Error(`scenery: ${dt("place",T,["sun","moon","horizon","ground"])}`)},set(T,I){if(!(T in v))throw new Error(`scenery: ${dt("value",T,Object.keys(v))}`);if(typeof I.value!="number"||!Number.isFinite(I.value))throw new Error("scenery.set needs `value`, a number");return k.tween(T,b(T,I.at),I.value,I,1e3),M},tracks:k.tracks};return M}function M3(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 om(t,e){const{width:n,height:s}=e,i=e.ground??s*.85,o=e.scale??s/4.5,r={x:0,y:0,width:n,height:s,ground:i},a=(l,c,h={})=>({preset:l,x:n*c,scale:o,...h});switch(t){case"park":return{scenery:{...r,hour:10.5,clouds:.35,horizon:"hills",...e.scenery},props:[a("tree",.14,{scale:o*1.1}),a("chair",.5,{turn:0}),a("tree",.86,{scale:o*.9})]};case"street":return{scenery:{...r,hour:16,clouds:.25,horizon:"city",colors:{ground:"#8a8f99"},...e.scenery},props:[a("house",.2,{scale:o*.75,turn:.1}),a("car",.5,{turn:1,scale:o*.9}),a("house",.78,{scale:o*.7,turn:.1}),a("tree",.95,{scale:o*.8})]};case"office":return{scenery:{...r,kind:"room",hour:11,clouds:.3,colors:{wall:"#dfe5ec",floor:"#9aa3ad",skirting:"#6c757d"},...e.scenery},props:[a("door",.1,{turn:.15}),a("chair",.46,{turn:0}),a("desk",.58,{turn:0})]};case"home":return{scenery:{...r,kind:"room",hour:20,clouds:.2,...e.scenery},props:[a("door",.08,{turn:.15}),a("chair",.35,{turn:.3}),a("bed",.72,{turn:.25})]};default:throw new Error(dt("scene preset",t,["park","street","office","home"]))}}function S3(t,e){const n=om(t,e),s=im(n.scenery),i=n.props.map(o=>tp({x:o.x,y:s.ground,prop:hc(o.preset),scale:o.scale,values:{turn:o.turn??0,...o.values}}));return{scenery:s,props:i,ground:s.ground}}function T3(t){const{timeline:e}=t,n=new nn;for(const[c,h]of Object.entries(t.targets)){const u=typeof h=="string"?document.querySelector(h):h;if(!u)throw new Error(`quickPlay: no element found for target "${c}" (${String(h)})`);n.registerTarget(c,u)}e.onUpdate=c=>{n.applyState(c),t.onUpdate?.(c)},t.onComplete&&(e.onComplete=t.onComplete);let s=null,i=null,o=!1;const r=c=>{if(o)return;const h=i===null?0:c-i;i=c,h>0&&e.tick(h),s=requestAnimationFrame(r)},a=()=>{s!==null||o||(i=null,s=requestAnimationFrame(r))},l=()=>{s!==null&&cancelAnimationFrame(s),s=null,i=null};return n.applyState(e.getStateAtTime(e.currentTime)),t.autoplay!==!1&&(e.play(),a()),{timeline:e,adapter:n,play(){e.play(),a()},pause(){e.pause(),l()},restart(){e.stop(),e.play(),a()},seek(c){e.seek(c*1e3),n.applyState(e.getStateAtTime(e.currentTime))},destroy(){o=!0,l(),e.stop(),n.clearTargets()}}}const x3={timeline:Oy,to(t,e,n){const s=new en(n);return s.to(t,e),s},from(t,e,n){const s=new en(n);return s.from(t,e),s},fromTo(t,e,n,s){const i=new en(s);return i.fromTo(t,e,n),i},set(t,e,n){const s=new en(n);return s.set(t,e),s}};function rm(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 E3(t,e){const n=t.length/4,s=new Float32Array(n*3),i=Math.min(.999,Math.max(0,e));for(let o=0;o<n;o++){const r=t[o*4]/255,a=t[o*4+1]/255,l=t[o*4+2]/255,c=t[o*4+3]/255,h=Math.max(r,a,l);if(h<=i)continue;const u=(h-i)/(1-i)*c/h;s[o*3]=r*u,s[o*3+1]=a*u,s[o*3+2]=l*u}return s}function am(t,e,n,s,i){const o=new Float32Array(t.length),r=i?n:e,a=i?e:n,l=(h,u)=>(i?h*e+u:u*e+h)*3,c=s*2+1;for(let h=0;h<r;h++)for(let u=0;u<3;u++){let d=0;for(let f=-s;f<=s;f++)d+=t[l(h,Math.min(a-1,Math.max(0,f)))+u];for(let f=0;f<a;f++){o[l(h,f)+u]=d/c;const p=t[l(h,Math.max(0,f-s))+u],g=t[l(h,Math.min(a-1,f+s+1))+u];d+=g-p}}return o}function lm(t,e,n,s){const i=Math.max(1,Math.round(s/Math.sqrt(3)));let o=t;for(let r=0;r<3;r++)o=am(o,e,n,i,!0),o=am(o,e,n,i,!1);return o}function A3(t,e={}){const n=t.canvas,s=n.width,i=n.height;if(!(s>0&&i>0))return;const o=Math.max(1,Math.round(e.downsample??4)),r=Math.max(1,Math.ceil(s/o)),a=Math.max(1,Math.ceil(i/o)),l=rm(t,r,a),c=l?.getContext("2d");if(!l||!c)return;c.imageSmoothingEnabled=!0,c.drawImage(t.canvas,0,0,r,a);const h=E3(c.getImageData(0,0,r,a).data,e.threshold??.55),u=(e.radius??Math.max(s,i)*.02)/o,d=lm(h,r,a,u),f=lm(h,r,a,u*3),p=e.halo??.6,g=c.createImageData(r,a);for(let m=0;m<r*a;m++){for(let w=0;w<3;w++)g.data[m*4+w]=Math.round(Math.min(1,d[m*3+w]+f[m*3+w]*p)*255);g.data[m*4+3]=255}c.putImageData(g,0,0),t.save(),t.setTransform(1,0,0,1,0,0),t.globalCompositeOperation="lighter",t.globalAlpha=Math.max(0,e.strength??.9),t.imageSmoothingEnabled=!0,t.drawImage(l,0,0,s,i),t.restore()}function P3(t,e,n){const s=n.width??6,i=n.taper??1,o=n.fade??1,r=n.opacity??1,a=n.blend==="add";if(t.save(),e.length>=2){const c=I3(e,s,i,o,r);a?(t.globalCompositeOperation="lighter",yc(t,c,n.color)):O3(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,$3(t,c)),t.globalAlpha=r,t.fillStyle=h,t.beginPath(),t.arc(l.at.x,l.at.y,n.head.radius,0,Math.PI*2),t.fill()}t.restore()}function $3(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 I3(t,e,n,s,i){const o=t.map(c=>({x:c.at.x,y:c.at.y,width:e*(1-n*c.age)})),r=Oh(o),a=_h(o)??void 0,l=[];for(let c=0;c+1<t.length;c++){const h=(t[c].age+t[c+1].age)/2,u=i*(1-s*h);if(u<=0)continue;const d=c+2===t.length;l.push({corners:[r.left[c],r.left[c+1],r.right[c+1],r.right[c]],alpha:u,...d&&a&&{cap:a}})}return l}function yc(t,e,n){t.fillStyle=n;for(const s of e){const[i,o,r,a]=s.corners;t.globalAlpha=Math.min(1,s.alpha),t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(o.x,o.y),s.cap&&t.arc(s.cap.x,s.cap.y,s.cap.radius,s.cap.start,s.cap.start-Math.PI,!0),t.lineTo(r.x,r.y),t.lineTo(a.x,a.y),t.closePath(),t.fill()}}function O3(t,e,n){const s=typeof t.getTransform=="function"?t.getTransform():null,i=g=>s?{x:s.a*g.x+s.c*g.y+s.e,y:s.b*g.x+s.d*g.y+s.f}:g,o=s?Math.sqrt(Math.abs(s.a*s.d-s.b*s.c)):1,r=e.map(g=>({...g,corners:g.corners.map(i),...g.cap&&{cap:{...g.cap,...i(g.cap),radius:g.cap.radius*o,start:g.cap.start+(s?Math.atan2(s.b,s.a):0)}}}));let a=1/0,l=1/0,c=-1/0,h=-1/0;for(const g of r){const m=g.cap?[{x:g.cap.x-g.cap.radius,y:g.cap.y-g.cap.radius},{x:g.cap.x+g.cap.radius,y:g.cap.y+g.cap.radius}]:[];for(const w of[...g.corners,...m])a=Math.min(a,w.x),l=Math.min(l,w.y),c=Math.max(c,w.x),h=Math.max(h,w.y)}if(!(c>a&&h>l))return;const u=Math.floor(a)-1,d=Math.floor(l)-1,f=s?rm(t,Math.ceil(c)+1-u,Math.ceil(h)+1-d):null,p=f?.getContext("2d");if(!f||!p){yc(t,e,n);return}p.translate(-u,-d),p.globalCompositeOperation="lighter",yc(p,r,n),t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=1,t.drawImage(f,u,d),t.restore()}const _3=Gt.to,C3=Gt.from,H3=Gt.fromTo,R3=Gt.set,L3=Gt.timeline,N3=Gt.ticker,F3=Gt.splitText,D3=Gt.context,W3=Gt.matchMedia,B3=Gt.quickTo,z3=Gt.imageSequence,q3=Gt.pageTransition;iw(),y.ACTING_STYLES=yn,y.AIRCRAFT_ACTING=rc,y.ANIMAL_GAITS=rs,y.ANIME_CAST=eg,y.BEAT_FIELDS=Wo,y.BEAT_MOMENTS=es,y.BED_ACTING=vp,y.BIRD_ACTING=Wp,y.BOARD_MARKS=El,y.BOARD_THEMES=Vs,y.CANVAS_PROPERTIES=Ko,y.CHAIR_ACTING=yp,y.CHARACTER_BEAT_3D_FIELDS=pl,y.CHARACTER_CAST=Il,y.CHARACTER_GAIT_SPEEDS=Nf,y.CHART_KINDS=Pl,y.CHART_SURFACE=pn,y.CHART_THEMES=Js,y.CODE_LANGUAGES=Lo,y.CODE_PANEL_EDITS=Tl,y.CODE_SURFACE=Us,y.CODE_THEME=Yf,y.Clock=um,y.CompatTimeline=en,y.CustomBounce=T0,y.CustomEase=S0,y.CustomWiggle=x0,y.DANCE_STYLES=Ne,y.DEFAULT_BAKE_INTERVAL_MS=wr,y.DEFAULT_INERTIA_FRICTION=ar,y.DEFAULT_LABELS=H0,y.DEFAULT_SPRING=Zt,y.DEFAULT_TRANSITION=rw,y.DESK_ACTING=wp,y.DOOR_ACTING=Sp,y.Draggable=jr,y.EMBRACE=No,y.EXPRESSIONS=vt,y.FACIAL_HAIR_STYLES=Wa,y.FINGERS=V0,y.FLIPS=qs,y.FOOT_SHAPES=Wu,y.FORMAT_VERSION=er,y.FRAME_ASPECTS=$h,y.GAGS=Ye,y.GAITS=Wt,y.GAIT_CYCLE_MS=Bl,y.GLASSES_STYLES=za,y.HAIR_COLORS=me,y.HAIR_STILL=Bn,y.HAIR_STYLES=La,y.HAND_MEETINGS=Zs,y.HAND_REST=Pt,y.HAND_SHAPES=Ct,y.HAT_STYLES=fo,y.HELD_ITEMS=Xa,y.HELP_UP=mn,y.HORSE_ACTING=PS,y.HORSE_GAITS=TS,y.HOUSE_ACTING=pp,y.HUMAN_ACTING_RIG=ag,y.HUMAN_BUILDS=Ji,y.HUMAN_CYCLES=ja,y.HUMAN_DANCES=ln,y.HUMAN_EXPRESSIONS=Sa,y.HUMAN_GAGS=go,y.HUMAN_POSES=le,y.HUMAN_REST=ht,y.IDENTITY_CAMERA=Df,y.IDENTITY_SIMILARITY=z1,y.INERTIA_MAX_DURATION_MS=Tc,y.InertiaTrackPlayer=hh,y.LiveTimeline=ge,y.MANGA_CAST=ng,y.MORPH_SAMPLES=Cm,y.MUDRAS=ji,y.ManualClock=hm,y.MediaSync=oa,y.Observer=t0,y.POSES=Vt,y.PROP_BEAT_3D_FIELDS=gc,y.PROP_BEAT_FIELDS=Qo,y.PROP_COMMON_ACTIONS=dc,y.PROP_COMMON_CONTROLS=ss,y.PROP_PRESETS=as,y.PROP_SURFACE=os,y.QUADRUPED_ACTING=lc,y.REMOVE_STYLES=Ho,y.REST_POSE=ct,y.RIDING_POSES=pc,y.SAMPLE_STEP=ze,y.SCENERY_COLORS=nm,y.SCRIPT_ACTIONS=ti,y.SPRING_MAX_DURATION_MS=rr,y.SPRING_PRESETS=di,y.SPRING_STEP_MS=kn,y.STICK_ACTING_RIG=rg,y.ScrollAnimator=m0,y.ScrollDriver=xs,y.ScrollMarkers=y0,y.ScrollPin=d0,y.SmoothScroll=na,y.SpringSampler=hs,y.SpringTrackPlayer=ch,y.Stage=Gh,y.TREE_ACTING=fp,y.Timeline=It,y.TinyflyPlayer=_i,y.TinyflySequencer=z0,y.TrackPlayer=ys,y.VEHICLE_ACTING=np,y.VISEMES=Be,y.ValueResolver=a1,y.VisibilityDriver=u0,y.WHEELCHAIR_ACTING=Ep,y.WHITEBOARD_SURFACE=Me,y.actCharacterTracks=hg,y.actKeyframes=Do,y.actTracks=cg,y.actionNames=Nl,y.airplane=$p,y.anchorError=qe,y.animalStrideLength=Zo,y.animatableProperties=Ng,y.applyBloom=A3,y.applyCamera=W5,y.applyGroove=_u,y.applySimilarity=Or,y.aspectOf=Ir,y.assertBeats=Wl,y.audioEnvelope=H1,y.backOut=Hc,y.bakeDanceTracks=S2,y.bakeEasing=Mr,y.bakeInertiaTrack=vr,y.bakeSpringTrack=kr,y.basicOutfit=Ld,y.beatAt=k2,y.beatAtTime=ws,y.beatLength=bs,y.beatPeriod=O1,y.beatPulse=C1,y.beatTime=wi,y.beatsBetween=w1,y.bed=kp,y.bike=hp,y.bindChoiceHotspots=F0,y.bird=Ue,y.blendPose=Nn,y.boilFrame=aa,y.bounceOut=Cc,y.boxMesh=Mf,y.brushingPose=Hd,y.bubblePath=Q1,y.bubblePop=ty,y.buildScene=S3,y.bus=rp,y.cameraFromValues=D5,y.cameraPoint=B5,y.cameraTracks=S1,y.capabilities=Vp,y.capabilitiesMarkdown=WS,y.car=ip,y.cart=lp,y.castMember=Sv,y.cat=Hp,y.chair=mp,y.changingWindows=Jn,y.character=mo,y.characterAt=Uk,y.characterHandPose=qd,y.characterJoints=ie,y.characterJointsInView=jk,y.characterLookAtTracks=N5,y.characterObjects=x5,y.characterPartsInView=jd,y.characterPoseOf=wo,y.characterPoseTracks=Vk,y.characterScript=NM,y.characterScript3D=L5,y.characterStrideLength=Hg,y.characterTarget=Gk,y.charactersFor=uh,y.chart=wv,y.checkBeats=ei,y.checkCast=Fl,y.checkCharacterBeats3D=Ff,y.checkPropBeats=Gp,y.checkPropBeats3D=Qp,y.checkSurfaceBeats=Og,y.checkTracks=GM,y.chicken=qp,y.circlePath=j5,y.clamp01=Zr,y.clearMorphCache=zm,y.clearPathCache=Pm,y.clipErased=Sl,y.closestName=ks,y.codePanel=nv,y.codeTokens=Kf,y.composeSimilarity=Y1,y.containerProgressAt=Qr,y.context=D3,y.controlValue=At,y.cow=Rp,y.create=qb,y.createControls=L0,y.createCubicBezier=Oc,y.createLive=P0,y.createPen=Ps,y.createRandom=_e,y.createTrack=bi,y.criticalDamping=gm,y.crow=zp,y.curve=I1,y.customBounce=Mh,y.customEase=vh,y.customWiggle=Sh,y.cylinderMesh=Sf,y.danceCircleAt=Zd,y.danceCircleTracks=Zk,y.danceFrame=Gi,y.danceJoint=dn,y.dancePose=p2,y.danceStance=Xi,y.danceTaps=y2,y.danceTracks=M2,y.danceTravel=Vi,y.danceTravelTrack=Nu,y.dancer=v2,y.defineAction=nM,y.defineGait=sM,y.describeTarget=Lg,y.deserializeTimeline=An,y.deserializeTrack=ph,y.desk=bp,y.detectTempo=k1,y.dog=Cp,y.door=Mp,y.draggable=nb,y.drawCartoonHand=Wi,y.drawCharacter=Yd,y.drawCharacterHead=Xk,y.drawCharacterInView=Kk,y.drawDustPuff=fg,y.drawEraser=vl,y.drawHand=Ml,y.drawHeldItem=Ga,y.drawImpactStars=Qv,y.drawPencil=Wf,y.drawProp=hS,y.drawPropEffects=BS,y.drawPropShadow=rl,y.drawSolvedFaces=cf,y.drawSolvedPart=p5,y.drawSolvedProp=il,y.drawSpeedLines=dg,y.drawStickFigure=Au,y.drawStickSmear=Zv,y.drawTrail=P3,y.drawnPathTarget=K5,y.dripPath=Z1,y.duck=jp,y.easeIn=Pc,y.easeInCubic=lr,y.easeInOut=Ic,y.easeInOutCubic=ds,y.easeInOutQuad=Ac,y.easeInQuad=xc,y.easeOut=$c,y.easeOutCubic=cr,y.easeOutQuad=Ec,y.editDistance=Eh,y.editError=Gs,y.editLog=Vn,y.elasticOut=_c,y.ellipsePoints=la,y.ellipsoidMesh=Tf,y.embrace=Av,y.embraceSpacing=Ev,y.envelopeAt=R1,y.erasable=V5,y.expandBeats=zo,y.expandParametricEasings=ah,y.extrudeMesh=xf,y.flipPose=Qd,y.flipTracks=s5,y.flipTravel=tf,y.formatVersionFor=nr,y.frameRect=L1,y.frameSize=N1,y.from=C3,y.fromJSON=i1,y.fromTo=H3,y.gag=Rl,y.gagDuration=Qs,y.gaitPose=tu,y.gaitStrideLength=Bi,y.getEasingFunction=Lt,y.getInterpolator=ms,y.getMotionPathPoint=Sr,y.getPathLength=$m,y.getPointAtProgress=Dc,y.goat=Lp,y.gridLinesFor=s0,y.hairFollow=ig,y.hairFollowTracks=Bv,y.hairHangs=sd,y.hairMotionAt=Dv,y.hairMotionOf=co,y.hairlineAt=Ws,y.handAt=Y5,y.handGrip=po,y.handJoints=Di,y.handJointsAt=Q0,y.handPath=Ul,y.handPose=Ht,y.handProp=Hs,y.hasKeyframes=vc,y.hashSeed=Kt,y.headPoint=o2,y.heldTime=Mc,y.helicopter=Pp,y.helpUp=$v,y.helpUpSpacing=Pv,y.holdingLayers=Dd,y.horse=_p,y.horseStrideLength=IS,y.house=gp,y.humanCyclePose=Nk,y.humanDanceFrame=Fs,y.humanDanceTracks=G2,y.humanFieldLabel=Y2,y.humanGag=_d,y.humanGaitPose=qa,y.humanGaitStrideLength=Ya,y.humanPlan=Ma,y.humanPose=bt,y.imageSequence=z3,y.inertiaDuration=Mn,y.inertiaRest=vn,y.inertiaValueAt=gi,y.inertiaVelocityAt=bm,y.interpolateArray=sh,y.interpolateColor=nh,y.interpolateMotionPath=Qm,y.interpolateNumber=ue,y.interpolatePathString=oh,y.interpolateQuaternion=ih,y.interpolateString=br,y.invertSimilarity=j1,y.isCubicBezierEasing=kc,y.isHeld=Ua,y.isInertiaTrack=Ee,y.isMotionPathPoint=cm,y.isMotionPathTrack=sr,y.isParametricEasing=ls,y.isPathData=Tn,y.isSpringTrack=Ae,y.isTextTrack=li,y.isUnderdamped=fm,y.isUnresolved=r1,y.isoDepth=_r,y.isometricBoxFaces=Cr,y.isometricFaces=Hr,y.jointsInScene=Xd,y.jointsToScene=Eu,y.linear=pi,y.lipSyncKeyframes=fl,y.lipSyncOver=$o,y.lipSyncTracks=I5,y.lit=ul,y.live=Gt,y.lookFields=ml,y.loopBeats=_1,y.loopEase=x1,y.loopNoise=E1,y.loosePartsOf=ic,y.lyingPose=Op,y.mapEase=Ms,y.mat4=cy,y.matchMedia=W3,y.maxStaggerDistance=or,y.meetDandiya=Jk,y.meetHands=xv,y.meetingSpacing=Tv,y.metaballContours=V1,y.metaballField=Rh,y.mirrorHumanPose=Du,y.mirrorPose=Ou,y.mixColors=dl,y.mixHandPoses=Ln,y.mixPoses=Za,y.morphPath=Kc,y.motorbike=up,y.mount=D0,y.mountAll=B0,y.narrationMarkers=p1,y.narrationSceneAt=m1,y.naturalRest=us,y.nearestBeat=y1,y.nextBeat=b1,y.niceCeiling=Qf,y.objectPositionAt=kl,y.owl=Kp,y.pageTransition=q3,y.panelMesh=Ef,y.parametricEasing=Lc,y.parrot=Xp,y.parseAnchor=gn,y.parseEdge=Vr,y.parsePath=Ve,y.parseTrigger=Jr,y.partialPath=Rn,y.pathLength=X0,y.pedallingKeys=p3,y.pedallingPose=mc,y.penroseStairs=U1,y.penroseTriangle=G1,y.persona=RM,y.phaseOf=Je,y.pieceMotion=Xs,y.pigeon=Yp,y.pingPong=$r,y.planNarration=g1,y.plantDanceFoot=Vd,y.play=zb,y.playSequence=ow,y.playWhenVisible=pb,y.playheadCrossings=xr,y.pointAlong=Hi,y.pointAtDistance=ur,y.pointOnHead=Bk,y.pointsToPath=Ih,y.pose=Rt,y.poseTracks=c2,y.powSimilarity=K1,y.projectIsometric=Mi,y.propActions=tr,y.propAnchors3D=Zg,y.propAt=Uo,y.propControls=oc,y.propLineWidth=ol,y.propObjects=i3,y.propPartsInSpace=Jg,y.propPreset=hc,y.propRide=XS,y.propRide3D=m3,y.propScript=Up,y.propScript3D=u3,y.propShapeMesh=si,y.propSurface=fS,y.propTarget=tp,y.propTow=VS,y.propView=Gg,y.quadruped=Xe,y.quat=Gm,y.quickPlay=T3,y.quickTo=B3,y.rabbit=Np,y.randomBetween=Ar,y.randomChoice=o1,y.randomSnapped=yh,y.reachCharacter=ve,y.reachOf=Rg,y.resolveActingStyle=_l,y.resolveCharacterPoseKeys=Qa,y.resolveFacialHair=wd,y.resolveGait=Os,y.resolveGlasses=vd,y.resolveHair=rd,y.resolveHat=Sd,y.resolveHeadLook=xd,y.resolveHolding=Nd,y.resolvePoseKeys=Yi,y.resolveSequence=kh,y.resolveStickFrame=ga,y.resolveStickPose=Pu,y.resolveValue=Pr,y.ribbon=Oh,y.ribbonHeadCap=_h,y.rideFloors=Co,y.rotateAbout=Re,y.routineBeats=Ui,y.rubberLimb=sn,y.safeAreas=F1,y.scalePoints=ny,y.scenePreset=om,y.scenery=im,y.scriptActionSummaries=Dl,y.scriptTracks=Yo,y.scrollProgress=gb,y.scrubOnScroll=wb,y.scrubPath=G5,y.seatHeight=Qw,y.serializeTimeline=mh,y.serializeTrack=fh,y.set=R3,y.shade=Ao,y.shapeMesh=$f,y.shapeToPathData=ki,y.similarity=q1,y.similarityAbout=Ch,y.similarityFixedPoint=Hh,y.similarityMatrix=X1,y.simplifyKeyframes=lh,y.sittingPose=ac,y.skeletonInView=no,y.sketchPen=Ri,y.skyColors=sm,y.smoothPath=gl,y.smoothToward=h0,y.snapAxis=n0,y.snapConfig=f0,y.snapDuration=p0,y.snapProgress=g0,y.solveAt=is,y.solvePlanSpace=Ls,y.solveProp=sc,y.songbird=Bp,y.soundsOf=vf,y.speechDuration=Ig,y.speechLength=Hf,y.spliceTracks=US,y.splitText=F3,y.springDuration=Sc,y.springFollow=vs,y.springValueAt=dm,y.squashStretch=ey,y.squirrel=Fp,y.stagePlanSpace=Ns,y.stageSpots=F5,y.staggerDistance=ir,y.staggerOffset=ci,y.staggerOffsets=hi,y.staggerSpan=cs,y.stepsDuration=pg,y.stepsEasing=Rc,y.stepsToKeys=Ll,y.stickFigureAt=ma,y.stickFigureJoints=ae,y.stickFigureTarget=pa,y.stickToHuman=ef,y.strideLength=ru,y.surfaceBox=Mt,y.surfaceScript=CM,y.sweepingPose=Cd,y.syncMediaElement=C0,y.talkingMouth=au,y.taperedLine=Li,y.taperedOutline=Ft,y.textAt=dh,y.tf=x3,y.ticker=N3,y.timeline=L3,y.to=_3,y.toJSON=s1,y.toKeyframedTrack=Jm,y.toKeyframedTracks=Zm,y.torusNoise=A1,y.trackTargets=Oe,y.tractor=ap,y.trailSamples=W1,y.trainCar=cp,y.tree=dp,y.triggerDistance=On,y.truck=op,y.tubeMesh=Af,y.unknownName=dt,y.unmount=nw,y.valueAt=_o,y.vec3=sy,y.vehicle=xe,y.walkPose=ou,y.wheelchair=xp,y.whiteboard=av,y.withErased=U5,y.withExpression=Le,y.wobble=T1,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})})(this.tinyfly=this.tinyfly||{});
|
|
66
|
+
`)}`);const o={};for(const k of[...Object.keys(as),...Object.keys(e.rig.controls)])o[k]=s.values?.[k]??At(e.rig,{},k);let[r,a]=s.position??[0,0],l=s.heading??0;const c=new Map,h=(k,y,T,$="linear")=>{const M=c.get(k)??[];M.push({time:y,value:T,easing:$}),c.set(k,M)},u=(k,y,T)=>h(k,y,T);h("x",0,r),h("z",0,a),h("rotateY",0,l);const d=(k,y)=>{const T=Do(l,y);if(Math.abs(T)<1)return k;const $=Math.max(X3,Math.abs(T)*j3);return u("rotateY",k,l),l+=T,h("rotateY",k+$,l,"ease-in-out"),k+$},f=(k,y,T)=>{const $=cg([[r,a],...y.through??[y.to]]);if($.length<2)return T;const M=d(T,Qn($[0].point,$[1].point)),x=$[$.length-1].at,S=y.for??x/(y.speed??k.speed)*1e3,E=Lt("ease-in-out"),P=Math.min(G3,S/4);for(const[V,tt]of Object.entries(k.set??{}))u(V,M,o[V]),h(V,M+1,tt),o[V]=tt;const A=k.flies?y.height??(o.lift>.05?o.lift:2):void 0,I=A!==void 0&&A>.05;for(const[V,tt]of Object.entries(k.hold??{}))u(V,M,o[V]),h(V,M+P,tt,"ease-out"),I||(h(V,M+S-P,tt),h(V,M+S,0,"ease-in")),o[V]=I?tt:0;A!==void 0&&(u("lift",M,o.lift),h("lift",M+Math.min(S*.35,1400),A,"ease-out"),h("lift",M+S,A),o.lift=A);const _={...o};let N=l;for(let V=0;;V=Math.min(x,V+K3)){const tt=M+ug(E,V/x)*S,{point:X,direction:R}=hg($,V);N+=Do(N,Qn([0,0],R)),h("x",tt,X[0]),h("z",tt,X[1]),h("rotateY",tt,N);for(const[z,K]of Object.entries(k.perMetre??{}))h(z,tt,_[z]+V*K);for(const[z,K]of Object.entries(k.perSecond??{}))h(z,tt,_[z]+(tt-M)/1e3*K);if(V>=x)break}for(const[V,tt]of Object.entries(k.perMetre??{}))o[V]=_[V]+x*tt;for(const[V,tt]of Object.entries(k.perSecond??{}))o[V]=_[V]+S/1e3*tt;return[r,a]=$[$.length-1].point,l=N,M+S},p=(k,y)=>{const T=Object.fromEntries(Object.entries(k).filter(([M])=>!["at","to","through","toward"].includes(M))),$=Pm(t,e,[T],{start:{...o,turn:1},scale:100,style:s.style,exaggeration:s.exaggeration});for(const M of $.tracks){if(Z3.includes(M.property))continue;const x=M.keyframes??[],S=o[M.property];if(!x.every(E=>E.value===S)){u(M.property,y,S);for(const E of x)E.time>0&&c.get(M.property).push({...E,time:y+E.time});o[M.property]=x[x.length-1].value}}return y+$.duration},g=[];let m=0;for(const k of n){const y=k.at??m;let T=y;const $=e.moves?.[k.do];$?T=f($,k,y):k.do==="face"?T=d(y,typeof k.toward=="number"?k.toward:Qn([r,a],k.toward)):k.do==="hold"?T=y+(k.for??1e3):T=p(k,y),g.push({do:k.do,start:y,end:T}),m=T}const w=`${s.scene}/${t}`;return{tracks:[...c].map(([k,y])=>({id:`${t}-${k}`,target:w,property:k,keyframes:lg(y)})),duration:m,beats:g,end:{position:[r,a],heading:l,values:{...o}}}}const Z3=["x","y","turn","facing","tilt"],Q3=.35,Oc={seated:ce.sit,astride:{...ce.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:{...ce.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:{...ce.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:{...ce.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}},tx=22,Cm=38;function _c(t,e=Oc.cycling){const n=t*Math.PI*2,s=r=>({swing:(e["leg.left.swing"]??40)+tx*Math.cos(n+r),knee:(e["leg.left.knee"]??70)+Cm*(.5+.5*Math.cos(n+r))-Cm*.5,ankle:12*Math.sin(n+r)}),i=s(0),o=s(Math.PI);return{...e,"leg.left.swing":i.swing,"leg.left.knee":i.knee,"leg.left.ankle":i.ankle,"leg.right.swing":o.swing,"leg.right.knee":o.knee,"leg.right.ankle":o.ankle}}function ex(t){const e=t.cadence??1.2,n=Math.max(2,t.samplesPerTurn??8),s=1e3/e/n,i=[];for(let o=t.start,r=0;o<t.end;o+=s,r++)i.push({time:Math.round(o),pose:_c((o-t.start)/1e3*e,t.base),...r>0?{act:!1}:{}});return i.push({time:t.end,pose:_c((t.end-t.start)/1e3*e,t.base),act:!1}),i}const Hm=(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 nx(t){const e=`${t.scene}/${t.propId}`,n=new It({id:`${t.propId}-ride-3d`,tracks:t.propTracks.filter(m=>m.target===e)}),s=t.placement??{},[i,o,r]=s.position??[0,0,0],a=t.prop.rig,l=Vs({...t.character,height:1}),c={...ut,...t.pose??Oc.seated},h=qs(l.plan,c,{height:t.height??1.7,contact:l.contact}).hip,u=t.facing??0,d=t.every??33,f={x:[],y:[],z:[],rotateY:[]};for(let m=t.start;;m=Math.min(t.end,m+d)){const w=n.getStateAtTime(m).values.get(e)??new Map,v=(_,N)=>{const Y=w.get(_);return typeof Y=="number"?Y:N},k={...s.values};for(const _ of Object.keys(a.controls))k[_]=v(_,s.values?.[_]??At(a,{},_));for(const _ of["pitch","roll","squash","lift","lean","size"])k[_]=v(_,s.values?.[_]??At(a,{},_));const y=Op(a,k)[t.anchor];if(!y)throw new Error(`propRide3D: ${t.prop.kind} has no anchor "${t.anchor}" (it has ${Object.keys(a.anchors??{}).join(", ")||"none"})`);const T=v("rotateY",s.heading??0),$=Hm(y,T),M=[v("x",i)+$[0],v("y",o)+$[1],v("z",r)+$[2]],x=T+u,S=Hm(h,x);let E=[M[0]-S[0],M[1]-S[1],M[2]-S[2]];const P=(_,N)=>{const Y=N*N*(3-2*N);return[_[0]+(E[0]-_[0])*Y,E[1]*Y+Q3*Math.sin(Math.PI*N),_[1]+(E[2]-_[1])*Y]},A=t.mount?Math.max(1,t.mount.for??450):0,I=t.dismount?Math.max(1,t.dismount.for??450):0;if(t.mount&&m<t.start+A?E=P(t.mount.from,(m-t.start)/A):t.dismount&&m>t.end-I&&(E=P(t.dismount.to,(t.end-m)/I)),f.x.push({time:m,value:E[0]}),f.y.push({time:m,value:E[1]}),f.z.push({time:m,value:E[2]}),f.rotateY.push({time:m,value:x}),m>=t.end)break}const p=t.riderId,g=`${t.scene}/${p}`;return Object.keys(f).map(m=>({id:`${p}-${m}`,target:g,property:m,keyframes:f[m]}))}const Rm={ground:"#7fb56a",hills:"#5f9a58",city:"#4b5468",cloud:"#ffffff",sun:"#ffd45c",moon:"#f3f0e0",rain:"#9fc4e8",snow:"#ffffff",wall:"#e9e1cf",floor:"#b08a5e",skirting:"#8a6a44",frame:"#f7f3ea"},gi=[[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"]],pi=(t,e,n)=>{const s=r=>[1,3,5].map(a=>parseInt(r.slice(a,a+2),16)),[i,o]=[s(t),s(e)];return`#${i.map((r,a)=>Math.round(r+(o[a]-r)*n).toString(16).padStart(2,"0")).join("")}`},sx=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 Lm(t){const e=(t%24+24)%24;for(let n=1;n<gi.length;n++){const[s,i,o]=gi[n-1],[r,a,l]=gi[n];if(e<=r){const c=(e-s)/(r-s);return{top:pi(i,a,c),bottom:pi(o,l,c)}}}return{top:gi[0][1],bottom:gi[0][2]}}const ix=(t,e)=>{const n=((t-e)%24+24)%24;return n<=12?n/12:-1},ox=9,rx=55,ax=28;function Nm(t){const{x:e,y:n,width:s,height:i}=t,o=t.kind??"sky",r=t.ground??n+i*.85,a={...Rm,...t.colors},l=t.horizon??"hills",c=t.window!==!1,h=He(t.seed??1),u=s*i/1e5,d=Array.from({length:Math.ceil(ox*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(rx*u)+4},()=>({u:h.next(),v:h.next(),speed:.8+h.next()*.5})),p=Array.from({length:Math.ceil(ax*u)+4},()=>({u:h.next(),v:h.next(),speed:.7+h.next()*.6,sway:h.next()*Math.PI*2,size:1.5+h.next()*2})),g=Array.from({length:Math.ceil(30*u)+10},()=>({u:h.next(),v:h.next()*.6,size:.6+h.next()*1.2})),m=Array.from({length:6},()=>({phase:h.next()*Math.PI*2,amp:.5+h.next()})),w=Array.from({length:24},()=>({h:.35+h.next()*.65,w:.6+h.next()*.8,windows:h.next()>.3})),v={hour:t.hour??12,clouds:t.clouds??.3,wind:t.wind??0,rain:t.rain??0,snow:t.snow??0},k=ts(),y=(E,P)=>k.keys(E)?.length?k.valueAt(E,P):v[E],T=(E,P)=>{const A=ix(E,P),I=A<0?.5:A,_=r-n;return{x:.1*s+.8*s*I,y:A<0?_+i*.2:_-Math.sin(I*Math.PI)*_*.8,up:A>=0}},$=(E,P,A,I,_)=>{const N=P("hour"),{top:Y,bottom:V}=Lm(N),tt=E.createLinearGradient(0,I.y,0,I.ground);tt.addColorStop(0,Y),tt.addColorStop(1,V),E.fillStyle=tt,E.fillRect(I.x,I.y,I.w,I.ground-I.y);const X=sx(N);if(X<.6){E.fillStyle="#ffffff",E.globalAlpha=(.6-X)/.6*.9;for(const L of g)E.beginPath(),E.arc(I.x+L.u*I.w,I.y+L.v*(I.ground-I.y),L.size,0,Math.PI*2),E.fill();E.globalAlpha=1}const R=T(N,6),z=T(N,18),K=Math.min(I.w,I.h)*.06;if(R.up&&(E.fillStyle=a.sun,E.beginPath(),E.arc(I.x+R.x/s*I.w,I.y+R.y/i*I.h,K,0,Math.PI*2),E.fill()),z.up){const L=I.x+z.x/s*I.w,q=I.y+z.y/i*I.h;E.fillStyle=a.moon,E.beginPath(),E.arc(L,q,K*.8,0,Math.PI*2),E.fill(),E.fillStyle=Y,E.beginPath(),E.arc(L-K*.35,q-K*.15,K*.7,0,Math.PI*2),E.fill()}const O=Math.max(0,Math.min(1,P("clouds"))),D=Math.max(-1,Math.min(1,P("wind"))),st=Math.round(O*d.length);E.fillStyle=pi("#ffffff",a.cloud==="#ffffff"?"#ffffff":a.cloud,1),E.globalAlpha=.55+.4*X;for(let L=0;L<st;L++){const q=d[L],U=((q.u*I.w+D*A*.012*(.6+q.size*.5))%(I.w*1.4)+I.w*1.4)%(I.w*1.4)-I.w*.2,F=I.x+U,W=I.y+(.08+q.v*.42)*(I.ground-I.y),B=Math.min(I.w,I.h)*.07*q.size;for(let J=0;J<q.puffs;J++)E.beginPath(),E.ellipse(F+(J-(q.puffs-1)/2)*B*.9,W+J%2*B*.25,B*(J%2?.8:1),B*.62,0,0,Math.PI*2),E.fill()}E.globalAlpha=1;const H=L=>pi(pi(L,"#0b1530",.65),L,X);if(l==="hills"){E.fillStyle=H(a.hills),E.beginPath(),E.moveTo(I.x,I.ground);const L=40;for(let q=0;q<=L;q++){const U=q/L;let F=0;m.forEach((W,B)=>F+=Math.sin(U*Math.PI*(1.5+B*.7)+W.phase)*W.amp),E.lineTo(I.x+U*I.w,I.ground-Math.max(0,F)*I.h*.045-I.h*.03)}E.lineTo(I.x+I.w,I.ground),E.closePath(),E.fill()}else if(l==="city"){E.fillStyle=H(a.city);let L=I.x;const q=I.w/18;for(const U of w){if(L>I.x+I.w)break;const F=q*U.w,W=I.h*.22*U.h;if(E.fillRect(L,I.ground-W,F,W),U.windows&&X<.5){E.fillStyle="#ffd66b",E.globalAlpha=.5-X;for(let B=I.ground-W+6;B<I.ground-8;B+=9)for(let J=L+4;J<L+F-4;J+=8)E.fillRect(J,B,3,4);E.globalAlpha=1,E.fillStyle=H(a.city)}L+=F+q*.15}}E.fillStyle=H(a.ground),E.fillRect(I.x,I.ground,I.w,I.y+I.h-I.ground)},M=(E,P,A,I)=>{const _=Math.max(-1,Math.min(1,P("wind"))),N=Math.max(0,Math.min(1,P("rain"))),Y=Math.max(0,Math.min(1,P("snow")));if(N>0){E.strokeStyle=a.rain,E.globalAlpha=.35+.45*N,E.lineWidth=1.2,E.lineCap="round";const V=I.h*.05,tt=_*.45,X=Math.round(N*f.length);E.beginPath();for(let R=0;R<X;R++){const z=f[R],K=((z.v*I.h+A*z.speed*.9)%I.h+I.h)%I.h,O=((z.u*I.w+K*tt)%I.w+I.w)%I.w;E.moveTo(I.x+O,I.y+K),E.lineTo(I.x+O+tt*V,I.y+K+V)}E.stroke(),E.globalAlpha=1}if(Y>0){E.fillStyle=a.snow,E.globalAlpha=.85;const V=Math.round(Y*p.length);for(let tt=0;tt<V;tt++){const X=p[tt],R=((X.v*I.h+A*X.speed*.08)%I.h+I.h)%I.h,z=Math.sin(A*.002+X.sway)*I.w*.02,K=((X.u*I.w+z+_*R*.3)%I.w+I.w)%I.w;E.beginPath(),E.arc(I.x+K,I.y+R,X.size,0,Math.PI*2),E.fill()}E.globalAlpha=1}},S={kind:"scenery",target:{type:"custom",x:e,y:n,width:s,height:i,props:v,about:{kind:o==="room"?"room":"sky",summary:o==="room"?"A room: a wall, a floor and a window on the sky. Its values are tracks: hour, clouds, wind, rain, snow (seen through the window).":`A sky over ${l==="flat"?"the ground":l}: the sun and moon on their arcs, stars, clouds on the wind, rain and snow. Its values are tracks: hour (0–24), clouds, wind (−1..1), rain, snow (0..1).`,props:Object.fromEntries(Object.keys(v).map(E=>[E,lx(E)]))},draw(E,P,A){const I=P.props??{},_=Y=>Number(I[Y]??v[Y]??0);E.save();const N={x:0,y:0,w:s,h:i,ground:r-n};if(o==="sky")$(E,_,A,N),M(E,_,A,N);else if(E.fillStyle=a.wall,E.fillRect(0,0,s,N.ground),E.fillStyle=a.floor,E.fillRect(0,N.ground,s,i-N.ground),E.fillStyle=a.skirting,E.fillRect(0,N.ground-i*.012,s,i*.012),c){const Y=s*.26,V=N.ground*.5,tt=s*.62,X=N.ground*.14;E.fillStyle=a.frame,E.fillRect(tt-6,X-6,Y+12,V+12),E.save(),E.beginPath(),E.rect(tt,X,Y,V),E.clip(),$(E,_,A,{x:tt,y:X,w:Y,h:V,ground:X+V*.8}),M(E,_,A,{x:tt,y:X,w:Y,h:V}),E.restore(),E.strokeStyle=a.frame,E.lineWidth=4,E.beginPath(),E.moveTo(tt+Y/2,X),E.lineTo(tt+Y/2,X+V),E.moveTo(tt,X+V/2),E.lineTo(tt+Y,X+V/2),E.stroke()}E.restore()}},ground:r,anchor(E,P=1/0){const A=y("hour",P);if(E==="sun"||E==="moon"){const I=T(A,E==="sun"?6:18);return{x:e+I.x,y:n+I.y}}if(E==="horizon")return{x:e+s/2,y:r-i*.03};if(E==="ground")return{x:e+s/2,y:r};throw new Error(`scenery: ${ft("place",E,["sun","moon","horizon","ground"])}`)},set(E,P){if(!(E in v))throw new Error(`scenery: ${ft("value",E,Object.keys(v))}`);if(typeof P.value!="number"||!Number.isFinite(P.value))throw new Error("scenery.set needs `value`, a number");return k.tween(E,y(E,P.at),P.value,P,1e3),S},tracks:k.tracks};return S}function lx(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 Fm(t,e){const{width:n,height:s}=e,i=e.ground??s*.85,o=e.scale??s/4.5,r={x:0,y:0,width:n,height:s,ground:i},a=(l,c,h={})=>({preset:l,x:n*c,scale:o,...h});switch(t){case"park":return{scenery:{...r,hour:10.5,clouds:.35,horizon:"hills",...e.scenery},props:[a("tree",.14,{scale:o*1.1}),a("chair",.5,{turn:0}),a("tree",.86,{scale:o*.9})]};case"street":return{scenery:{...r,hour:16,clouds:.25,horizon:"city",colors:{ground:"#8a8f99"},...e.scenery},props:[a("house",.2,{scale:o*.75,turn:.1}),a("car",.5,{turn:1,scale:o*.9}),a("house",.78,{scale:o*.7,turn:.1}),a("tree",.95,{scale:o*.8})]};case"office":return{scenery:{...r,kind:"room",hour:11,clouds:.3,colors:{wall:"#dfe5ec",floor:"#9aa3ad",skirting:"#6c757d"},...e.scenery},props:[a("door",.1,{turn:.15}),a("chair",.46,{turn:0}),a("desk",.58,{turn:0})]};case"home":return{scenery:{...r,kind:"room",hour:20,clouds:.2,...e.scenery},props:[a("door",.08,{turn:.15}),a("chair",.35,{turn:.3}),a("bed",.72,{turn:.25})]};default:throw new Error(ft("scene preset",t,["park","street","office","home"]))}}function cx(t,e){const n=Fm(t,e),s=Nm(n.scenery),i=n.props.map(o=>Cp({x:o.x,y:s.ground,prop:Ec(o.preset),scale:o.scale,values:{turn:o.turn??0,...o.values}}));return{scenery:s,props:i,ground:s.ground}}function hx(t){const{timeline:e}=t,n=new sn;for(const[c,h]of Object.entries(t.targets)){const u=typeof h=="string"?document.querySelector(h):h;if(!u)throw new Error(`quickPlay: no element found for target "${c}" (${String(h)})`);n.registerTarget(c,u)}e.onUpdate=c=>{n.applyState(c),t.onUpdate?.(c)},t.onComplete&&(e.onComplete=t.onComplete);let s=null,i=null,o=!1;const r=c=>{if(o)return;const h=i===null?0:c-i;i=c,h>0&&e.tick(h),s=requestAnimationFrame(r)},a=()=>{s!==null||o||(i=null,s=requestAnimationFrame(r))},l=()=>{s!==null&&cancelAnimationFrame(s),s=null,i=null};return n.applyState(e.getStateAtTime(e.currentTime)),t.autoplay!==!1&&(e.play(),a()),{timeline:e,adapter:n,play(){e.play(),a()},pause(){e.pause(),l()},restart(){e.stop(),e.play(),a()},seek(c){e.seek(c*1e3),n.applyState(e.getStateAtTime(e.currentTime))},destroy(){o=!0,l(),e.stop(),n.clearTargets()}}}const ux={timeline:hb,to(t,e,n){const s=new nn(n);return s.to(t,e),s},from(t,e,n){const s=new nn(n);return s.from(t,e),s},fromTo(t,e,n,s){const i=new nn(s);return i.fromTo(t,e,n),i},set(t,e,n){const s=new nn(n);return s.set(t,e),s}};function Wm(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 dx(t,e){const n=t.length/4,s=new Float32Array(n*3),i=Math.min(.999,Math.max(0,e));for(let o=0;o<n;o++){const r=t[o*4]/255,a=t[o*4+1]/255,l=t[o*4+2]/255,c=t[o*4+3]/255,h=Math.max(r,a,l);if(h<=i)continue;const u=(h-i)/(1-i)*c/h;s[o*3]=r*u,s[o*3+1]=a*u,s[o*3+2]=l*u}return s}function Dm(t,e,n,s,i){const o=new Float32Array(t.length),r=i?n:e,a=i?e:n,l=(h,u)=>(i?h*e+u:u*e+h)*3,c=s*2+1;for(let h=0;h<r;h++)for(let u=0;u<3;u++){let d=0;for(let f=-s;f<=s;f++)d+=t[l(h,Math.min(a-1,Math.max(0,f)))+u];for(let f=0;f<a;f++){o[l(h,f)+u]=d/c;const p=t[l(h,Math.max(0,f-s))+u],g=t[l(h,Math.min(a-1,f+s+1))+u];d+=g-p}}return o}function Bm(t,e,n,s){const i=Math.max(1,Math.round(s/Math.sqrt(3)));let o=t;for(let r=0;r<3;r++)o=Dm(o,e,n,i,!0),o=Dm(o,e,n,i,!1);return o}function fx(t,e={}){const n=t.canvas,s=n.width,i=n.height;if(!(s>0&&i>0))return;const o=Math.max(1,Math.round(e.downsample??4)),r=Math.max(1,Math.ceil(s/o)),a=Math.max(1,Math.ceil(i/o)),l=Wm(t,r,a),c=l?.getContext("2d");if(!l||!c)return;c.imageSmoothingEnabled=!0,c.drawImage(t.canvas,0,0,r,a);const h=dx(c.getImageData(0,0,r,a).data,e.threshold??.55),u=(e.radius??Math.max(s,i)*.02)/o,d=Bm(h,r,a,u),f=Bm(h,r,a,u*3),p=e.halo??.6,g=c.createImageData(r,a);for(let m=0;m<r*a;m++){for(let w=0;w<3;w++)g.data[m*4+w]=Math.round(Math.min(1,d[m*3+w]+f[m*3+w]*p)*255);g.data[m*4+3]=255}c.putImageData(g,0,0),t.save(),t.setTransform(1,0,0,1,0,0),t.globalCompositeOperation="lighter",t.globalAlpha=Math.max(0,e.strength??.9),t.imageSmoothingEnabled=!0,t.drawImage(l,0,0,s,i),t.restore()}function gx(t,e,n){const s=n.width??6,i=n.taper??1,o=n.fade??1,r=n.opacity??1,a=n.blend==="add";if(t.save(),e.length>=2){const c=mx(e,s,i,o,r);a?(t.globalCompositeOperation="lighter",Cc(t,c,n.color)):yx(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,px(t,c)),t.globalAlpha=r,t.fillStyle=h,t.beginPath(),t.arc(l.at.x,l.at.y,n.head.radius,0,Math.PI*2),t.fill()}t.restore()}function px(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 mx(t,e,n,s,i){const o=t.map(c=>({x:c.at.x,y:c.at.y,width:e*(1-n*c.age)})),r=Xh(o),a=Gh(o)??void 0,l=[];for(let c=0;c+1<t.length;c++){const h=(t[c].age+t[c+1].age)/2,u=i*(1-s*h);if(u<=0)continue;const d=c+2===t.length;l.push({corners:[r.left[c],r.left[c+1],r.right[c+1],r.right[c]],alpha:u,...d&&a&&{cap:a}})}return l}function Cc(t,e,n){t.fillStyle=n;for(const s of e){const[i,o,r,a]=s.corners;t.globalAlpha=Math.min(1,s.alpha),t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(o.x,o.y),s.cap&&t.arc(s.cap.x,s.cap.y,s.cap.radius,s.cap.start,s.cap.start-Math.PI,!0),t.lineTo(r.x,r.y),t.lineTo(a.x,a.y),t.closePath(),t.fill()}}function yx(t,e,n){const s=typeof t.getTransform=="function"?t.getTransform():null,i=g=>s?{x:s.a*g.x+s.c*g.y+s.e,y:s.b*g.x+s.d*g.y+s.f}:g,o=s?Math.sqrt(Math.abs(s.a*s.d-s.b*s.c)):1,r=e.map(g=>({...g,corners:g.corners.map(i),...g.cap&&{cap:{...g.cap,...i(g.cap),radius:g.cap.radius*o,start:g.cap.start+(s?Math.atan2(s.b,s.a):0)}}}));let a=1/0,l=1/0,c=-1/0,h=-1/0;for(const g of r){const m=g.cap?[{x:g.cap.x-g.cap.radius,y:g.cap.y-g.cap.radius},{x:g.cap.x+g.cap.radius,y:g.cap.y+g.cap.radius}]:[];for(const w of[...g.corners,...m])a=Math.min(a,w.x),l=Math.min(l,w.y),c=Math.max(c,w.x),h=Math.max(h,w.y)}if(!(c>a&&h>l))return;const u=Math.floor(a)-1,d=Math.floor(l)-1,f=s?Wm(t,Math.ceil(c)+1-u,Math.ceil(h)+1-d):null,p=f?.getContext("2d");if(!f||!p){Cc(t,e,n);return}p.translate(-u,-d),p.globalCompositeOperation="lighter",Cc(p,r,n),t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=1,t.drawImage(f,u,d),t.restore()}const bx=Ut.to,wx=Ut.from,kx=Ut.fromTo,vx=Ut.set,Mx=Ut.timeline,Sx=Ut.ticker,xx=Ut.splitText,Tx=Ut.context,Ex=Ut.matchMedia,Ax=Ut.quickTo,Px=Ut.imageSequence,$x=Ut.pageTransition;Nw(),b.ACTING_STYLES=wn,b.AIRCRAFT_ACTING=Mc,b.ANIMAL_GAITS=hs,b.ANIME_CAST=Hg,b.BEAT_FIELDS=Vo,b.BEAT_MOMENTS=os,b.BED_ACTING=tm,b.BIRD_ACTING=wm,b.BOARD_MARKS=Dl,b.BOARD_THEMES=oi,b.CANVAS_PROPERTIES=nr,b.CHAIR_ACTING=Vp,b.CHARACTER_BEAT_3D_FIELDS=$l,b.CHARACTER_CAST=Kl,b.CHARACTER_GAIT_SPEEDS=pg,b.CHART_KINDS=zl,b.CHART_SURFACE=yn,b.CHART_THEMES=ri,b.CODE_LANGUAGES=jo,b.CODE_PANEL_EDITS=Fl,b.CODE_SURFACE=ii,b.CODE_THEME=Mg,b.Clock=Ym,b.CompatTimeline=nn,b.CustomBounce=D0,b.CustomEase=W0,b.CustomWiggle=B0,b.DANCE_STYLES=We,b.DEFAULT_BAKE_INTERVAL_MS=$r,b.DEFAULT_INERTIA_FRICTION=yr,b.DEFAULT_LABELS=V0,b.DEFAULT_SPRING=te,b.DEFAULT_TRANSITION=Ww,b.DESK_ACTING=Zp,b.DOOR_ACTING=nm,b.Draggable=ea,b.EMBRACE=Xo,b.EXPRESSIONS=vt,b.FACIAL_HAIR_STYLES=Za,b.FINGERS=fu,b.FLIPS=Zs,b.FOOT_SHAPES=id,b.FORMAT_VERSION=ur,b.FRAME_ASPECTS=Kh,b.GAGS=Ke,b.GAITS=Dt,b.GAIT_CYCLE_MS=sc,b.GLASSES_STYLES=tl,b.HAIR_COLORS=me,b.HAIR_STILL=Kn,b.HAIR_STYLES=Xa,b.HAND_MEETINGS=ai,b.HAND_REST=Pt,b.HAND_SHAPES=Ct,b.HAT_STYLES=xo,b.HELD_ITEMS=rl,b.HELP_UP=bn,b.HORSE_ACTING=g3,b.HORSE_GAITS=h3,b.HOUSE_ACTING=Gp,b.HUMAN_ACTING_RIG=Dg,b.HUMAN_BUILDS=ao,b.HUMAN_CYCLES=sl,b.HUMAN_DANCES=cn,b.HUMAN_EXPRESSIONS=_a,b.HUMAN_GAGS=To,b.HUMAN_POSES=ce,b.HUMAN_REST=ut,b.IDENTITY_CAMERA=yg,b.IDENTITY_SIMILARITY=v1,b.INERTIA_MAX_DURATION_MS=Dc,b.InertiaTrackPlayer=Eh,b.LiveTimeline=ge,b.MANGA_CAST=Rg,b.MORPH_SAMPLES=dy,b.MUDRAS=eo,b.ManualClock=qm,b.MediaSync=pa,b.OUTFIT_PRESETS=jl,b.Observer=m0,b.POSES=Jt,b.PROP_BEAT_3D_FIELDS=Ic,b.PROP_BEAT_FIELDS=cr,b.PROP_COMMON_ACTIONS=Pc,b.PROP_COMMON_CONTROLS=as,b.PROP_PRESETS=us,b.PROP_SURFACE=cs,b.QUADRUPED_ACTING=xc,b.REMOVE_STYLES=Yo,b.REST_POSE=ht,b.RIDING_POSES=Oc,b.SAMPLE_STEP=qe,b.SCENERY_COLORS=Rm,b.SCRIPT_ACTIONS=ci,b.SOFT_CARTOON_CAST=Yl,b.SPRING_MAX_DURATION_MS=mr,b.SPRING_PRESETS=vi,b.SPRING_STEP_MS=Mn,b.STICK_ACTING_RIG=Wg,b.ScrollAnimator=_0,b.ScrollDriver=$s,b.ScrollMarkers=C0,b.ScrollPin=P0,b.SmoothScroll=da,b.SpringSampler=gs,b.SpringTrackPlayer=Th,b.Stage=h0,b.TREE_ACTING=jp,b.Timeline=It,b.TinyflyPlayer=Bi,b.TinyflySequencer=iu,b.TrackPlayer=vs,b.VEHICLE_ACTING=Rp,b.VISEMES=ze,b.ValueResolver=Dy,b.VisibilityDriver=A0,b.WHEELCHAIR_ACTING=om,b.WHITEBOARD_SURFACE=xe,b.actCharacterTracks=qg,b.actKeyframes=Uo,b.actTracks=zg,b.actionNames=Ql,b.airplane=lm,b.anchorError=Ye,b.animalStrideLength=lr,b.animatableProperties=mp,b.applyBloom=fx,b.applyCamera=xv,b.applyGroove=Vu,b.applySimilarity=Br,b.aspectOf=Dr,b.assertBeats=nc,b.audioEnvelope=f1,b.backOut=Vc,b.bakeDanceTracks=ek,b.bakeEasing=_r,b.bakeInertiaTrack=Or,b.bakeSpringTrack=Ir,b.basicOutfit=pf,b.beatAt=Z2,b.beatAtTime=Ss,b.beatLength=Ms,b.beatPeriod=h1,b.beatPulse=d1,b.beatTime=Pi,b.beatsBetween=Zy,b.bed=Qp,b.bike=qp,b.bindChoiceHotspots=tu,b.bird=Ve,b.blendPose=Wn,b.bodyProfileWidth=cd,b.boilFrame=ya,b.bounceOut=Uc,b.boxMesh=tg,b.brushingPose=rf,b.bubblePath=_1,b.bubblePop=C1,b.buildScene=cx,b.bus=Wp,b.cameraFromValues=Sv,b.cameraPoint=Tv,b.cameraTracks=n1,b.capabilities=$m,b.capabilitiesMarkdown=E3,b.car=Np,b.cart=Bp,b.castMember=lM,b.cat=fm,b.chair=Up,b.changingWindows=es,b.character=Vs,b.characterAt=C5,b.characterHandPose=vf,b.characterJoints=oe,b.characterJointsInView=$5,b.characterLookAtTracks=vv,b.characterObjects=cv,b.characterPartsInView=xf,b.characterPoseOf=$o,b.characterPoseTracks=H5,b.characterScript=SS,b.characterScript3D=kv,b.characterStrideLength=fp,b.characterTarget=_5,b.charactersFor=Ah,b.chart=sM,b.checkBeats=hi,b.checkCast=tc,b.checkCharacterBeats3D=mg,b.checkPropBeats=Am,b.checkPropBeats3D=_m,b.checkSurfaceBeats=hp,b.checkTracks=HS,b.chicken=Mm,b.circlePath=$v,b.clamp01=la,b.clearMorphCache=vy,b.clearPathCache=ay,b.clipErased=Nl,b.closestName=xs,b.codePanel=Dv,b.codeTokens=xg,b.composeSimilarity=S1,b.containerProgressAt=ca,b.context=Tx,b.controlValue=At,b.cow=gm,b.create=Mw,b.createControls=Z0,b.createCubicBezier=Xc,b.createLive=Y0,b.createPen=_s,b.createRandom=He,b.createTrack=Ai,b.criticalDamping=Xm,b.crow=vm,b.curve=c1,b.customBounce=Fh,b.customEase=Nh,b.customWiggle=Wh,b.cylinderMesh=eg,b.danceCircleAt=Of,b.danceCircleTracks=L5,b.danceFrame=io,b.danceJoint=gn,b.dancePose=X2,b.danceStance=so,b.danceTaps=U2,b.danceTracks=tk,b.danceTravel=ro,b.danceTravelTrack=ed,b.dancer=Q2,b.defineAction=zM,b.defineGait=qM,b.describeTarget=pp,b.deserializeTimeline=$n,b.deserializeTrack=Oh,b.desk=Jp,b.detectTempo=Qy,b.dog=dm,b.door=em,b.draggable=Rb,b.drawCartoonHand=Vi,b.drawCharacter=Sf,b.drawCharacterHead=O5,b.drawCharacterInView=I5,b.drawDustPuff=jg,b.drawEraser=Rl,b.drawHand=Ll,b.drawHeldItem=al,b.drawImpactStars=WM,b.drawPencil=bg,b.drawProp=VS,b.drawPropEffects=A3,b.drawPropShadow=kl,b.drawSolvedFaces=Bf,b.drawSolvedPart=Q5,b.drawSolvedProp=bl,b.drawSpeedLines=Kg,b.drawStickFigure=Ku,b.drawStickSmear=FM,b.drawTrail=gx,b.drawnPathTarget=Iv,b.dripPath=O1,b.duck=xm,b.easeIn=Yc,b.easeInCubic=br,b.easeInOut=jc,b.easeInOutCubic=ms,b.easeInOutQuad=qc,b.easeInQuad=Bc,b.easeOut=Kc,b.easeOutCubic=wr,b.easeOutQuad=zc,b.editDistance=zh,b.editError=si,b.editLog=ts,b.elasticOut=Gc,b.ellipsePoints=ji,b.ellipsoidMesh=ng,b.embrace=dM,b.embraceSpacing=uM,b.envelopeAt=g1,b.erasable=Hv,b.expandBeats=Zo,b.expandParametricEasings=Sh,b.extrudeMesh=sg,b.flipPose=_f,b.flipTracks=B5,b.flipTravel=Cf,b.formatVersionFor=dr,b.frameRect=p1,b.frameSize=m1,b.from=wx,b.fromJSON=Ny,b.fromTo=kx,b.gag=Jl,b.gagDuration=li,b.gaitPose=bu,b.gaitStrideLength=Ji,b.getEasingFunction=Lt,b.getInterpolator=ks,b.getMotionPathPoint=Cr,b.getPathLength=ly,b.getPointAtProgress=eh,b.goat=pm,b.gridLinesFor=w0,b.hairFollow=Ng,b.hairFollowTracks=AM,b.hairHangs=$d,b.hairMotionAt=TM,b.hairMotionOf=Xs,b.hairlineAt=Gs,b.handAt=Pv,b.handGrip=Eo,b.handJoints=Ui,b.handJointsAt=mu,b.handPath=uc,b.handPose=Ht,b.handProp=Ws,b.hasKeyframes=Nc,b.hashSeed=Xt,b.headPoint=N2,b.heldTime=Fc,b.helicopter=am,b.helpUp=gM,b.helpUpSpacing=fM,b.holdingLayers=bf,b.horse=um,b.horseStrideLength=m3,b.house=Xp,b.humanCyclePose=k5,b.humanDanceFrame=Ys,b.humanDanceTracks=Ek,b.humanFieldLabel=Mk,b.humanGag=sf,b.humanGaitPose=el,b.humanGaitStrideLength=nl,b.humanPlan=Oa,b.humanPose=kt,b.imageSequence=Px,b.inertiaDuration=xn,b.inertiaRest=Sn,b.inertiaValueAt=Si,b.inertiaVelocityAt=Jm,b.interpolateArray=wh,b.interpolateColor=bh,b.interpolateMotionPath=_y,b.interpolateNumber=ue,b.interpolatePathString=vh,b.interpolateQuaternion=kh,b.interpolateString=Pr,b.invertSimilarity=x1,b.isCubicBezierEasing=Lc,b.isHeld=ll,b.isInertiaTrack=Pe,b.isMotionPathPoint=zm,b.isMotionPathTrack=fr,b.isParametricEasing=ds,b.isPathData=En,b.isSpringTrack=$e,b.isTextTrack=yi,b.isUnderdamped=jm,b.isUnresolved=Wy,b.isoDepth=zr,b.isometricBoxFaces=qr,b.isometricFaces=Yr,b.jointsInScene=Ef,b.jointsToScene=Yu,b.leafOutfit=uf,b.leafOutfitContours=il,b.linear=xi,b.lipSyncKeyframes=Al,b.lipSyncOver=Wo,b.lipSyncTracks=gv,b.lit=Tl,b.live=Ut,b.lookFields=Il,b.loopBeats=u1,b.loopEase=i1,b.loopNoise=o1,b.loosePartsOf=kc,b.lyingPose=hm,b.mapEase=Es,b.mat4=z1,b.matchMedia=Ex,b.maxStaggerDistance=pr,b.meetDandiya=R5,b.meetHands=hM,b.meetingSpacing=cM,b.metaballContours=$1,b.metaballField=Jh,b.mirrorHumanPose=sd,b.mirrorPose=Uu,b.mixColors=El,b.mixHandPoses=Fn,b.mixPoses=dl,b.morphPath=lh,b.motorbike=Yp,b.mount=eu,b.mountAll=su,b.narrationMarkers=Gy,b.narrationSceneAt=Uy,b.naturalRest=ps,b.nearestBeat=Vy,b.nextBeat=Jy,b.niceCeiling=Og,b.objectPositionAt=Hl,b.organicBodyContours=ud,b.organicCenterLine=Ks,b.outfitPreset=pM,b.owl=Tm,b.pageTransition=$x,b.panelMesh=ig,b.parametricEasing=Zc,b.parrot=Em,b.parseAnchor=mn,b.parseEdge=ra,b.parsePath=Je,b.parseTrigger=aa,b.partialPath=Nn,b.pathLength=cu,b.pedallingKeys=ex,b.pedallingPose=_c,b.penroseStairs=P1,b.penroseTriangle=A1,b.persona=vS,b.phaseOf=Ze,b.pieceMotion=ni,b.pigeon=Sm,b.pingPong=Wr,b.planNarration=Xy,b.plantDanceFoot=$f,b.play=vw,b.playSequence=Fw,b.playWhenVisible=Gb,b.playheadCrossings=Rr,b.pointAlong=qi,b.pointAtDistance=vr,b.pointOnHead=E5,b.pointsToPath=jh,b.pose=Rt,b.poseTracks=B2,b.powSimilarity=T1,b.projectIsometric=Oi,b.propActions=hr,b.propAnchors3D=Op,b.propAt=or,b.propControls=vc,b.propLineWidth=wl,b.propObjects=Y3,b.propPartsInSpace=Ip,b.propPreset=Ec,b.propRide=C3,b.propRide3D=nx,b.propScript=Pm,b.propScript3D=J3,b.propShapeMesh=di,b.propSurface=QS,b.propTarget=Cp,b.propTow=L3,b.propView=Ap,b.quadruped=Ge,b.quat=Ay,b.quickPlay=hx,b.quickTo=Ax,b.rabbit=mm,b.randomBetween=Nr,b.randomChoice=Fy,b.randomSnapped=Ch,b.reachCharacter=Se,b.reachOf=gp,b.resolveActingStyle=Gl,b.resolveCharacterPoseKeys=fl,b.resolveFacialHair=Yd,b.resolveGait=Ls,b.resolveGlasses=jd,b.resolveHair=_d,b.resolveHat=Gd,b.resolveHeadLook=Vd,b.resolveHolding=mf,b.resolveOrganicBody=ld,b.resolvePoseKeys=to,b.resolveSequence=Lh,b.resolveStickFrame=Sa,b.resolveStickPose=ju,b.resolveValue=Fr,b.ribbon=Xh,b.ribbonHeadCap=Gh,b.rideFloors=qo,b.rotateAbout=Ne,b.routineBeats=oo,b.rubberLimb=on,b.safeAreas=y1,b.scalePoints=R1,b.scenePreset=Fm,b.scenery=Nm,b.scriptActionSummaries=ec,b.scriptTracks=tr,b.scrollProgress=Xb,b.scrubOnScroll=Zb,b.scrubPath=_v,b.seatHeight=O2,b.serializeTimeline=_h,b.serializeTrack=$h,b.set=vx,b.shade=No,b.shapeMesh=ag,b.shapeToPathData=$i,b.similarity=M1,b.similarityAbout=Uh,b.similarityFixedPoint=Vh,b.similarityMatrix=E1,b.simplifyKeyframes=xh,b.sittingPose=Sc,b.skeletonInView=fo,b.sketchPen=Yi,b.skyColors=Lm,b.smoothPath=Pl,b.smoothToward=E0,b.snapAxis=b0,b.snapConfig=$0,b.snapDuration=O0,b.snapProgress=I0,b.softCartoonCharacter=aM,b.solveAt=ls,b.solvePlanSpace=zs,b.solveProp=wc,b.songbird=km,b.soundsOf=Qf,b.speechDuration=cp,b.speechLength=dg,b.spliceTracks=R3,b.splitText=xx,b.springDuration=Wc,b.springFollow=Ts,b.springValueAt=Km,b.squashStretch=H1,b.squirrel=ym,b.stagePlanSpace=qs,b.stageSpots=Mv,b.staggerDistance=gr,b.staggerOffset=bi,b.staggerOffsets=wi,b.staggerSpan=fs,b.stepsDuration=Gg,b.stepsEasing=Jc,b.stepsToKeys=Zl,b.stickFigureAt=Ta,b.stickFigureJoints=le,b.stickFigureTarget=xa,b.stickToHuman=Hf,b.strideLength=xu,b.surfaceBox=Mt,b.surfaceScript=wS,b.sweepingPose=of,b.syncMediaElement=U0,b.talkingMouth=Tu,b.taperedLine=Ki,b.taperedOutline=Ft,b.textAt=Ph,b.tf=ux,b.ticker=Sx,b.timeline=Mx,b.to=bx,b.toJSON=Ly,b.toKeyframedTrack=Iy,b.toKeyframedTracks=Oy,b.torusNoise=r1,b.trackTargets=Ce,b.tractor=Dp,b.trailSamples=w1,b.trainCar=zp,b.tree=Kp,b.triggerDistance=Cn,b.truck=Fp,b.tubeMesh=og,b.unknownName=ft,b.unmount=Rw,b.valueAt=zo,b.vec3=L1,b.vehicle=Ae,b.walkPose=Su,b.wheelchair=im,b.whiteboard=Kv,b.withErased=Cv,b.withExpression=Fe,b.wobble=s1,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})})(this.tinyfly=this.tinyfly||{});
|