@algorisys/tinyfly 0.100.0 → 0.102.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.
Files changed (71) hide show
  1. package/README.md +6 -6
  2. package/bin/tinyfly.mjs +16 -6
  3. package/docs/character-appearance.md +26 -0
  4. package/docs/editor-guide.md +1 -1
  5. package/docs/examples.md +1 -1
  6. package/docs/getting-started.md +1 -1
  7. package/docs/gsap-compat.md +1 -1
  8. package/docs/llm-guide.md +22 -4
  9. package/docs/maps.md +2 -2
  10. package/docs/scene-3d.md +140 -9
  11. package/docs/teaching.md +1 -1
  12. package/docs/video-rendering.md +198 -1
  13. package/lib/addons/adapters.js +431 -332
  14. package/lib/addons/characters.js +3889 -3773
  15. package/lib/addons/load-scene-oWNsYYC1.js +372 -0
  16. package/lib/addons/scene-3d-webgl.js +31 -31
  17. package/lib/addons/scene-3d.js +669 -314
  18. package/lib/addons/shading-0lPgnXmD.js +96 -0
  19. package/lib/browser/tinyfly-scene-3d-webgl.iife.js +2 -2
  20. package/lib/browser/tinyfly-scene-3d.iife.js +2 -2
  21. package/lib/browser/tinyfly.iife.js +15 -15
  22. package/lib/browser/tinyfly.js +6232 -5723
  23. package/lib/browser/tinyfly.umd.js +15 -15
  24. package/lib/engine/tinyfly-engine.js +1563 -1170
  25. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  26. package/lib/headless/headless.js +189 -6
  27. package/lib/types/adapters/canvas/framing.d.ts +27 -0
  28. package/lib/types/adapters/canvas/impossible.d.ts +15 -0
  29. package/lib/types/adapters/canvas/index.d.ts +4 -0
  30. package/lib/types/adapters/canvas/nested-zoom.d.ts +40 -0
  31. package/lib/types/adapters/canvas/zoom-blur.d.ts +49 -0
  32. package/lib/types/characters/character-script-3d.d.ts +21 -1
  33. package/lib/types/characters/character.d.ts +23 -3
  34. package/lib/types/characters/head/face.d.ts +19 -2
  35. package/lib/types/characters/index.d.ts +2 -1
  36. package/lib/types/characters/staging-3d.d.ts +56 -0
  37. package/lib/types/engine/authoring/beat-loop.d.ts +46 -0
  38. package/lib/types/engine/authoring/curve.d.ts +26 -0
  39. package/lib/types/engine/authoring/framing.d.ts +48 -0
  40. package/lib/types/engine/authoring/index.d.ts +4 -0
  41. package/lib/types/engine/authoring/periodic.d.ts +89 -0
  42. package/lib/types/engine/path/goo.d.ts +103 -0
  43. package/lib/types/engine/path/impossible.d.ts +92 -0
  44. package/lib/types/engine/path/index.d.ts +6 -0
  45. package/lib/types/engine/path/similarity.d.ts +48 -0
  46. package/lib/types/headless/audio-mix.d.ts +40 -0
  47. package/lib/types/headless/ffmpeg-args.d.ts +2 -0
  48. package/lib/types/headless/frame-renderer.d.ts +7 -1
  49. package/lib/types/headless/index.d.ts +2 -0
  50. package/lib/types/headless/loop-audio.d.ts +21 -0
  51. package/lib/types/headless/node-audio.d.ts +39 -0
  52. package/lib/types/headless/node-video.d.ts +2 -0
  53. package/lib/types/headless/video-scene.d.ts +21 -0
  54. package/lib/types/scene-3d/camera.d.ts +11 -2
  55. package/lib/types/scene-3d/geometry/mesh.d.ts +2 -0
  56. package/lib/types/scene-3d/geometry/primitives.d.ts +7 -0
  57. package/lib/types/scene-3d/impossible-3d.d.ts +29 -0
  58. package/lib/types/scene-3d/index.d.ts +7 -3
  59. package/lib/types/scene-3d/lighting.d.ts +58 -0
  60. package/lib/types/scene-3d/resolve-scene.d.ts +18 -2
  61. package/lib/types/scene-3d/scene-3d-adapter.d.ts +4 -0
  62. package/lib/types/scene-3d/scene-types.d.ts +43 -6
  63. package/lib/types/scene-3d/shading.d.ts +2 -0
  64. package/lib/types/scene-3d/shots.d.ts +162 -0
  65. package/lib/types/scene-3d/software-renderer.d.ts +40 -0
  66. package/llms-full.txt +395 -23
  67. package/llms.txt +29 -29
  68. package/package.json +1 -1
  69. package/skills/tinyfly/SKILL.md +11 -1
  70. package/lib/addons/load-scene-CQvcFWGJ.js +0 -331
  71. package/lib/addons/shading-o5T_v9DT.js +0 -89
@@ -1,5 +1,5 @@
1
- (function(b,cn){typeof exports=="object"&&typeof module<"u"?cn(exports):typeof define=="function"&&define.amd?define(["exports"],cn):(b=typeof globalThis<"u"?globalThis:b||self,cn(b.tinyfly=b.tinyfly||{}))})(this,(function(b){"use strict";function cn(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function Un(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const Oo=2;function _o(t){return t.some(e=>e.interpolation!==void 0)?2:1}function Ks(t){return t.property==="text"&&"textConfig"in t}function Me(t){return t.kind==="inertia"&&"inertia"in t}function Se(t){return t.kind==="spring"&&"spring"in t}function Co(t){return t.property==="motionPath"&&"motionPathConfig"in t}function cp(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"angle"in t}function zl(t){return"keyframes"in t}class hp{_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 dp{_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 Yl(t,e){if(!(e>0))return t;const n=1e3/e;return Math.floor(t/n+1e-9)*n}function Ho(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 Ro(t,e="start"){if(t<=1)return 0;let n=0;for(let s=0;s<t;s++)n=Math.max(n,Ho(s,t,e));return n}function js(t,e,n){if(n.offsets)return n.offsets[t]??0;const s=n.from??"start",i=Ho(t,e,s);if(n.amount!==void 0){const o=Ro(e,s);return o===0?0:n.amount*i/o}return n.each!==void 0?n.each*i:0}function Xs(t,e){return Array.from({length:t},(n,s)=>js(s,t,e))}function Vn(t,e){return t<=1?0:Math.max(...Xs(t,e))}const hn=1,Lo=6e4,Gs=Lo/hn,jt={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1},Us={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 Jn{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??jt.stiffness,this.damping=e.damping??jt.damping,this.mass=e.mass??jt.mass,this.restDelta=e.restDelta??jt.restDelta,this.restSpeed=e.restSpeed??jt.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=e.velocity??jt.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/hn);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/hn-n;return s+(i-s)*o}settleTime(){return this.simulateTo(Gs+1),this.settledStep!==null?this.settledStep*hn:Lo}simulateTo(e){if(this.settledStep!==null)return;const n=Math.min(e,Gs+1),s=hn/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>Gs&&(this.settledStep=Gs)}}function up(t,e){return new Jn(t).valueAt(e)}function Kl(t){return new Jn(t).settleTime()}function fp(t){const e=t.stiffness??jt.stiffness,n=t.damping??jt.damping,s=t.mass??jt.mass;return n<2*Math.sqrt(e*s)}function gp(t){const e=t.stiffness??jt.stiffness,n=t.mass??jt.mass;return 2*Math.sqrt(e*n)}const No=4,pp=.002,mp=1e-4,jl=6e4;function Vs(t){const e=t.friction??No;return e>0?e:No}function Zn(t){return t.from+t.velocity/Vs(t)}function yp(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 dn(t){let e=yp(Zn(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 un(t){const e=Math.abs(dn(t)-t.from);if(e===0)return 0;const n=t.restDelta??Math.max(mp,e*pp);if(n>=e)return 0;const s=Math.log(e/n)/Vs(t);return Math.min(jl,s*1e3)}function Js(t,e){if(e<=0)return t.from;const n=dn(t);if(e>=un(t))return n;const s=Vs(t);return t.from+(n-t.from)*(1-Math.exp(-s*e/1e3))}function bp(t,e){const n=Vs(t),s=dn(t);return e>=un(t)?0:(s-t.from)*n*Math.exp(-n*Math.max(0,e)/1e3)}const Zs=t=>t,Xl=t=>t*t,Gl=t=>1-(1-t)*(1-t),Ul=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,Do=t=>t*t*t,Fo=t=>1-Math.pow(1-t,3),Qn=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,Vl=Do,Jl=Fo,Zl=Qn,wp={linear:Zs,"ease-in":Vl,"ease-out":Jl,"ease-in-out":Zl,"ease-in-quad":Xl,"ease-out-quad":Gl,"ease-in-out-quad":Ul,"ease-in-cubic":Do,"ease-out-cubic":Fo,"ease-in-out-cubic":Qn};function Ql(t){const[e,n,s,i]=t,o=3*e,r=3*(s-e)-o,a=1-o-r,l=3*n,c=3*(i-n)-l,h=1-l-c,d=g=>((a*g+r)*g+o)*g,u=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=d(m)-g;if(Math.abs(y)<1e-7)return m;const E=f(m);if(Math.abs(E)<1e-7)break;m-=y/E}let w=0,S=1;for(m=g;w<S;){const k=d(m);if(Math.abs(k-g)<1e-7)return m;g>k?w=m:S=m,m=(w+S)/2}return m};return g=>{if(g<=0)return 0;if(g>=1)return 1;const m=p(g);return u(m)}}function Wo(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 tc(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 ec=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 nc(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 sc(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 ic(t){switch(t.type){case"steps":return sc(t.count,t.position);case"elastic":return Wo(tc(t.amplitude,t.period),t.mode);case"bounce":return Wo(ec,t.mode);case"back":return Wo(nc(t.overshoot),t.mode)}}function Lt(t){return t===void 0?Zs:cn(t)?Ql(t.points):Un(t)?ic(t):wp[t]??Zs}const oc=32,kp=256,fn=new Map,vp=/[MmLlHhVvCcSsQqTtAaZz]/,Mp=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,Sp={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function Tp(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(vp.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=Mp.exec(t.slice(n));if(!l)break;s.args.push(parseFloat(l[0])),n+=l[0].length}return e}function Ep(t,e,n,s,i,o,r,a,l){if(t===a&&e===l)return[];let c=Math.abs(n),h=Math.abs(s);if(c===0||h===0)return[[t,e,a,l,a,l]];const d=i*Math.PI/180,u=Math.cos(d),f=Math.sin(d),p=(t-a)/2,g=(e-l)/2,m=u*p+f*g,w=-f*p+u*g,S=m*m/(c*c)+w*w/(h*h);if(S>1){const A=Math.sqrt(S);c*=A,h*=A}const k=o===r?-1:1,y=c*c*h*h-c*c*w*w-h*h*m*m,E=c*c*w*w+h*h*m*m,x=k*Math.sqrt(Math.max(0,y/E)),$=x*c*w/h,M=-x*h*m/c,v=u*$-f*M+(t+a)/2,T=f*$+u*M+(e+l)/2,I=(A,R,N,P)=>{const L=A*N+R*P,W=Math.sqrt((A*A+R*R)*(N*N+P*P)),z=Math.acos(Math.max(-1,Math.min(1,L/W)));return A*P-R*N<0?-z:z},O=I(1,0,(m-$)/c,(w-M)/h);let _=I((m-$)/c,(w-M)/h,(-m-$)/c,(-w-M)/h);!r&&_>0&&(_-=2*Math.PI),r&&_<0&&(_+=2*Math.PI);const C=Math.max(1,Math.ceil(Math.abs(_)/(Math.PI/2))),D=_/C,q=4/3*Math.tan(D/4),X=A=>{const R=c*Math.cos(A),N=h*Math.sin(A);return[u*R-f*N+v,f*R+u*N+T]},J=A=>{const R=-c*Math.sin(A),N=h*Math.cos(A);return[u*R-f*N,f*R+u*N]},j=[];for(let A=0;A<C;A++){const R=O+A*D,N=R+D,[P,L]=X(R),[W,z]=A===C-1?[a,l]:X(N),[B,Y]=J(R),[V,F]=J(N);j.push([P+q*B,L+q*Y,W-q*V,z-q*F,W,z])}return j}function Te(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 rc(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 ts(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 Qs(t,e,n){const[s,i,o,r,a,l]=n,c=[0];let h=t,d=e,u=0;for(let f=1;f<=oc;f++){const p=f/oc,g=Te(t,s,o,a,p),m=Te(e,i,r,l,p);u+=Math.hypot(g-h,m-d),c.push(u),h=g,d=m}return{subpath:0,type:"C",points:[s,i,o,r,a,l],startX:t,startY:e,endX:a,endY:l,length:u,lengths:c}}function je(t){const e=fn.get(t);if(e)return e;const n=[];let s=0,i=0,o=0,r=0,a=null,l=null,c=-1;const h=new Set,d=g=>{c<0&&(c=0),g.subpath=c,n.push(g)};for(const{type:g,args:m}of Tp(t)){const w=g.toUpperCase(),S=g!==w,k=Sp[w];if(w==="Z"){(s!==o||i!==r)&&d(ts(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 E=m.slice(y,y+k),x=S?s:0,$=S?i:0;let M=null,v=null;switch(w){case"M":y===0?(s=E[0]+x,i=E[1]+$,o=s,r=i,(c<0||n[n.length-1]?.subpath===c)&&c++):(d(ts(s,i,E[0]+x,E[1]+$)),s=E[0]+x,i=E[1]+$);break;case"L":d(ts(s,i,E[0]+x,E[1]+$)),s=E[0]+x,i=E[1]+$;break;case"H":d(ts(s,i,E[0]+x,i)),s=E[0]+x;break;case"V":d(ts(s,i,s,E[0]+$)),i=E[0]+$;break;case"C":{const T=[E[0]+x,E[1]+$,E[2]+x,E[3]+$,E[4]+x,E[5]+$];d(Qs(s,i,T)),M=[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],O=[T,I,E[0]+x,E[1]+$,E[2]+x,E[3]+$];d(Qs(s,i,O)),M=[O[2],O[3]],s=O[4],i=O[5];break}case"Q":case"T":{let T=s,I=i;w==="Q"?(T=E[0]+x,I=E[1]+$):l&&(T=2*s-l[0],I=2*i-l[1]);const O=w==="Q"?E[2]+x:E[0]+x,_=w==="Q"?E[3]+$:E[1]+$;d(Qs(s,i,[s+2/3*(T-s),i+2/3*(I-i),O+2/3*(T-O),_+2/3*(I-_),O,_])),v=[T,I],s=O,i=_;break}case"A":{const T=E[5]+x,I=E[6]+$;let O=s,_=i;for(const C of Ep(s,i,E[0],E[1],E[2],E[3],E[4],T,I))d(Qs(O,_,C)),O=C[4],_=C[5];s=T,i=I;break}}a=M,l=v}}const u=n.reduce((g,m)=>g+m.length,0),f=[];for(let g=0;g<n.length;){const m=n[g].subpath;let w=g,S=0;for(;w<n.length&&n[w].subpath===m;)S+=n[w++].length;const k=n[g],y=n[w-1],E=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:S,closed:E}),g=w}const p={segments:n,totalLength:u,subpaths:f};return fn.size>=kp&&fn.delete(fn.keys().next().value),fn.set(t,p),p}function Ap(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 xp(t,e){if(t.type==="L"){const d=t.length>0?Math.max(0,Math.min(1,e/t.length)):0;return{x:t.startX+(t.endX-t.startX)*d,y:t.startY+(t.endY-t.startY)*d,angle:Math.atan2(t.endY-t.startY,t.endX-t.startX)*180/Math.PI}}const[n,s,i,o,r,a]=t.points,l=Ap(t,e);let c=rc(t.startX,n,i,r,l),h=rc(t.startY,s,o,a,l);if(Math.hypot(c,h)<1e-9){const d=l<.5?Math.min(1,l+.001):Math.max(0,l-.001),u=Te(t.startX,n,i,r,d),f=Te(t.startY,s,o,a,d),p=Te(t.startX,n,i,r,l),g=Te(t.startY,s,o,a,l);c=l<.5?u-p:p-u,h=l<.5?f-g:g-f}return{x:Te(t.startX,n,i,r,l),y:Te(t.startY,s,o,a,l),angle:Math.atan2(h,c)*180/Math.PI}}function Bo(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 xp(r,e-i);i+=r.length}return{x:0,y:0,angle:0}}function ac(t,e){const{segments:n,totalLength:s}=je(t);return Bo(n,Math.max(0,Math.min(1,e))*s)}function $p(){fn.clear()}function Pp(t){return je(t).totalLength}const Ip=24,Op=320,_p=2.5,es=72,Cp=64,Hp=.2,Rp=128,ns=new Map;let ti=0,Ee;const lc=t=>Math.round(t*100)/100;function cc(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 qo(t,e){const n=t.closed?(e%1+1)%1:Math.max(0,Math.min(1,e)),s=Bo(t.segments,n*t.length,t.start,t.end);return[s.x,s.y]}function hc(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 dc(t,e){const n=[];for(let s=0;s<e;s++)n.push(qo(t,t.closed?s/e:s/(e-1)));return n}function uc(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 Lp(t,e,n){const s=t.closed&&e.closed;if(n!==void 0)return{offset:s?Math.abs(n)%es/es:0,reversed:n<0};const i=uc(dc(t,es)),o=uc(dc(e,es)),r=es;let a={offset:0,reversed:!1},l=1/0;for(const c of[!1,!0]){const h=s?r:1;for(let d=0;d<h;d++){let u=0;for(let f=0;f<r&&u<l;f++){const p=s?c?(d-f+r)%r:(f+d)%r:c?r-1-f:f,g=i[f][0]-o[p][0],m=i[f][1]-o[p][1];u+=g*g+m*m}u<l&&(l=u,a={offset:s?d/r:0,reversed:c})}}return a}function Np(t,e,n){return n?((e.reversed?e.offset-t:t+e.offset)%1+1)%1:e.reversed?1-t:t}function Dp(t,e,n){return n?((e.reversed?e.offset-t:t-e.offset)%1+1)%1:e.reversed?1-t:t}function Fp(t,e,n){const s=t.closed&&e.closed,i=Lp(t,e,n.shapeIndex),o=Math.max(Ip,Math.min(Op,Math.ceil(Math.max(t.length,e.length)/_p))),r=new Set,a=d=>r.add(Math.round(d*1e7)/1e7);for(let d=0;d<=o;d++)a(d/o);for(const d of hc(t))a(d);for(const d of hc(e))a(Dp(d,i,s));let l=[...r].sort((d,u)=>d-u);s&&(l=l.filter(d=>d<1));const c=[],h=[];for(const d of l)c.push(...qo(t,d)),h.push(...qo(e,Np(d,i,s)));return Wp({from:c,to:h,closed:s})}function Wp(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=Hp;for(let h=r+1;h<a;h++){const d=Math.max(fc(t.from,r,a,h),fc(t.to,r,a,h));d>c&&(c=d,l=h)}l!==-1&&(n[l]=1,s.push([r,l],[l,a]))}const i=[],o=[];for(let r=0;r<e;r++)n[r]&&(i.push(t.from[r*2],t.from[r*2+1]),o.push(t.to[r*2],t.to[r*2+1]));return{from:i,to:o,closed:t.closed}}function fc(t,e,n,s){const i=t[e*2],o=t[e*2+1],r=t[n*2]-i,a=t[n*2+1]-o,l=t[s*2]-i,c=t[s*2+1]-o,h=r*r+a*a,d=h===0?0:Math.max(0,Math.min(1,(l*r+c*a)/h));return Math.hypot(l-d*r,c-d*a)}function Bp(t,e,n){const s=n.shapeIndex;if(Ee&&Ee.from===t&&Ee.to===e&&Ee.shapeIndex===s)return Ee.plan;const o=ns.get(String(s??"auto"))?.get(t)?.get(e);if(o)return Ee={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=cc(t,!r),l=cc(e,!r),c={pairs:a.map((f,p)=>Fp(f,l[p],n))};ti>=Rp&&(ns.clear(),ti=0);const h=String(s??"auto"),d=ns.get(h)??new Map;ns.set(h,d);const u=d.get(t)??new Map;return d.set(t,u),u.set(e,c),ti++,Ee={from:t,to:e,shapeIndex:s,plan:c},c}function gc(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=Bp(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=lc(a.from[l]+(a.to[l]-a.from[l])*i),h=lc(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 qp(){ns.clear(),ti=0,Ee=void 0}function gn(t){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(t)}const pn=Math.PI/180,zp=.9995;function zo(){return[0,0,0,1]}function Xt(t,e){const n=Math.hypot(t[0],t[1],t[2]);if(n===0)return zo();const s=e*pn/2,i=Math.sin(s)/n;return[t[0]*i,t[1]*i,t[2]*i,Math.cos(s)]}function Yp(t,e,n){return Yo(Yo(Xt([0,1,0],e),Xt([1,0,0],t)),Xt([0,0,1],n))}function Kp(t){const[e,n,s,i]=Ae(t),o=2*(e*s+n*i),r=2*(e*n+s*i),a=1-2*(e*e+s*s),l=2*(n*s-e*i),c=1-2*(n*n+s*s),h=2*(e*s-n*i),d=1-2*(e*e+n*n),u=Math.asin(Math.max(-1,Math.min(1,-l)));return Math.abs(l)<.9999999?[u/pn,Math.atan2(o,d)/pn,Math.atan2(r,a)/pn]:[u/pn,Math.atan2(-h,c)/pn,0]}function Yo(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 pc(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function mc(t){return Math.hypot(t[0],t[1],t[2],t[3])}function Ae(t){const e=mc(t);return e===0?zo():[t[0]/e,t[1]/e,t[2]/e,t[3]/e]}function jp(t){return[-t[0],-t[1],-t[2],t[3]]}function yc(t,e,n){const s=Ae(t);let i=Ae(e),o=pc(s,i);if(o<0&&(i=[-i[0],-i[1],-i[2],-i[3]],o=-o),o>zp)return Ae([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 Ae([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 Xp(t,e){const[n,s,i,o]=Ae(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 Gp=Object.freeze(Object.defineProperty({__proto__:null,conjugate:jp,dot:pc,fromAxisAngle:Xt,fromEuler:Yp,identity:zo,length:mc,multiply:Yo,normalize:Ae,rotateVec3:Xp,slerp:yc,toEuler:Kp},Symbol.toStringTag,{value:"Module"})),le=(t,e,n)=>t+(e-t)*n,bc=512,Ko=new Map,jo=new Map;function wc(t){const e=Ko.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 Ko.size<bc&&Ko.set(t,s),s}const kc=t=>t.charCodeAt(0)===35,vc=t=>t.startsWith("rgb"),Mc=t=>t.startsWith("rgba"),Up=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,Xo=t=>Math.round(t).toString(16).padStart(2,"0");function Vp(t,e,n){return`#${Xo(t)}${Xo(e)}${Xo(n)}`}function Sc(t){const e=jo.get(t);if(e)return e;const n=t.match(Up);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 jo.size<bc&&jo.set(t,r),r}const Tc=(t,e,n)=>{if(kc(t)&&kc(e)){const[s,i,o]=wc(t),[r,a,l]=wc(e),c=le(s,r,n),h=le(i,a,n),d=le(o,l,n);return Vp(c,h,d)}if((vc(t)||Mc(t))&&(vc(e)||Mc(e))){const s=Sc(t),i=Sc(e),o=Math.round(le(s[0],i[0],n)),r=Math.round(le(s[1],i[1],n)),a=Math.round(le(s[2],i[2],n));if(s.length===4||i.length===4){const l=s[3]??1,c=i[3]??1,h=le(l,c,n);return`rgba(${o}, ${r}, ${a}, ${h})`}return`rgb(${o}, ${r}, ${a})`}return n<1?t:e},Ec=(t,e,n)=>{const s=Math.min(t.length,e.length),i=[];for(let o=0;o<s;o++)i.push(le(t[o],e[o],n));return i},Ac=(t,e,n)=>yc(t,e,n),Go=(t,e,n)=>n<1?t:e,xc=(t,e,n)=>gc(t,e,n);function ss(t,e){return e==="slerp"?Ac:typeof t=="number"?le:Array.isArray(t)?Ec:typeof t=="string"?t.startsWith("#")||t.startsWith("rgb")?Tc:gn(t)?xc:Go:Go}const Uo=1e3/60;function Vo(t,e={}){if(!Se(t))throw new Error(`bakeSpringTrack: track "${t.id}" is not a spring track`);const n=new Jn(t.spring);return $c(t,s=>n.valueAt(s),n.settleTime(),t.spring.from,t.spring.to,e)}function Jo(t,e={}){if(!Me(t))throw new Error(`bakeInertiaTrack: track "${t.id}" is not an inertia track`);const n=t.inertia;return $c(t,s=>Js(n,s),un(n),n.from,dn(n),e)}function $c(t,e,n,s,i,o){const r=o.intervalMs??Uo,a=o.tolerance??.01,l=t.delay??0,c=[];for(let d=0;d<=n;d+=r)c.push({time:d+l,value:e(d),easing:"linear"});const h=c[c.length-1];return!h||h.time<n+l?c.push({time:n+l,value:i,easing:"linear"}):h.value=i,l>0&&c.unshift({time:0,value:s,easing:"linear"}),{id:t.id,target:t.target,property:t.property,keyframes:a>0?Ic(c,a):c,...t.targets&&{targets:[...t.targets]},...t.stagger&&{stagger:{...t.stagger}}}}function Zo(t,e,n,s={}){const i=s.intervalMs??Uo,o=typeof n=="function"?n:Lt(n),r=ss(t.value,s.interpolation),a=e.time-t.time;if(a<=0)return[e];const l=[];for(let h=i;h<a;h+=i){const d=h/a;l.push({time:t.time+h,value:r(t.value,e.value,o(d)),easing:"linear"})}const c=o(1);return l.push({...e,...c!==1&&{value:r(t.value,e.value,c)},easing:"linear"}),l}function Jp(t,e){return Se(t)?Vo(t,e):Me(t)?Jo(t,e):t}function Pc(t,e={}){const n=t.keyframes;if(!n.some(o=>Un(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];Un(r.easing)?s.push(...Zo(n[o-1],r,r.easing,i)):s.push(r)}return{...t,keyframes:s}}function Zp(t,e){return t.filter(zl).map(n=>Pc(n,e)).concat(t.filter(Se).map(n=>Vo(n,e)),t.filter(Me).map(n=>Jo(n,e)))}function Ic(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 ei(t){const e=[...t.keyframes].sort((n,s)=>n.time-s.time);return{...t,keyframes:e}}function xe(t){return t.targets&&t.targets.length>0?t.targets:[t.target]}function mn(t,e,n,s){const i=n??0;return!s||e<=1?i:i+js(t,e,s)}class ni{track;targets;constructor(e){this.track=e,this.targets=xe(e)}getValueAtTime(e){return this.valueForOffset(e-mn(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=mn(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?Vn(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 ss(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 Oc{track;targets;sampler;constructor(e){this.track=e,this.targets=xe(e),this.sampler=new Jn(e.spring)}getValueAtTime(e){return this.sampler.valueAt(e-mn(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=mn(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?Vn(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+e}getTrack(){return this.track}}class _c{track;targets;duration;constructor(e){this.track=e,this.targets=xe(e),this.duration=un(e.inertia)}getValueAtTime(e){return Js(this.track.inertia,e-mn(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=mn(i,n,this.track.delay,this.track.stagger);s.push({target:this.targets[i],value:Js(this.track.inertia,e-o),start:o})}return s}getDuration(){const e=this.track.stagger?Vn(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+e}getTrack(){return this.track}}function Qo(t,e){const n={...ac(t.pathData,e)};if(t.matrix){const[s,i,o,r,a,l]=t.matrix,{x:c,y:h}=n;n.x=s*c+o*h+a,n.y=i*c+r*h+l;const d=n.angle*Math.PI/180,u=Math.cos(d),f=Math.sin(d);n.angle=Math.atan2(i*u+r*f,s*u+o*f)*180/Math.PI}return t.autoRotate&&t.rotateOffset&&(n.angle+=t.rotateOffset),n}function Qp(t,e,n,s){const i=e+(n-e)*s;return Qo(t,i)}const tr={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},tm=20;function Cc(t){const e=tr[t??"upperCase"]??t??tr.upperCase,n=Array.from(e);return n.length>0?n:Array.from(tr.upperCase)}function em(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 Hc(t,e,n=0){const s=t.from??"",i=t.to,o=Math.max(0,Math.min(1,e));if(o<=0)return s;if(o>=1)return i;const r=Array.from(s),a=Array.from(i),l=t.rightToLeft??!1;if(t.mode==="type"){const S=Math.round(o*Math.max(r.length,a.length));return l?r.slice(0,Math.max(0,r.length-S)).join("")+a.slice(Math.max(0,a.length-S)).join(""):a.slice(0,S).join("")+r.slice(S).join("")}const c=Math.max(0,Math.min(.999,t.revealDelay??0)),h=Math.max(0,(o-c)/(1-c)),d=Math.floor(h*a.length),u=t.tweenLength===!1?a.length:Math.round(r.length+(a.length-r.length)*o),f=Cc(t.chars),p=t.refreshRate??tm,g=p>0?Math.floor(n*p/1e3):0,m=t.seed??1;let w="";for(let S=0;S<u;S++){const k=l?S>=u-d:S<d,y=l?a[a.length-(u-S)]:a[S];k&&y!==void 0||y===" "||y===`
2
- `?w+=y:w+=f[em(m,S,g)%f.length]}return w}class Ot{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=Yl(e,this._config.drawingRate??0),this._hasSharedWrites())this._resolveShared(e,n);else for(const[s,i]of this._trackPlayers){const o=i.getTrack().property;for(const{target:r,value:a,start:l}of i.getTargetValues(e))this._write(n,s,r,o,a,e-l)}return{values:n,currentTime:this._currentTime,playbackState:this._playbackState,direction:this._direction,loopIteration:this._loopIteration}}_resolveShared(e,n){const s=new Map;for(const[i,o]of this._trackPlayers){const r=o.getTrack().property;for(const{target:a,value:l,start:c}of o.getTargetValues(e)){const h=`${a}\0${r}`,d=c<=e,u=s.get(h);(!u||(d!==u.started?d:d?c>=u.start:c<=u.start))&&s.set(h,{trackId:i,target:a,property:r,value:l,start:c,started:d})}}for(const{trackId:i,target:o,property:r,value:a,start:l}of s.values())this._write(n,i,o,r,a,e-l)}_write(e,n,s,i,o,r){if(o===void 0)return;let a=e.get(s);a||(a=new Map,e.set(s,a));const l=this._textTracks.get(n);if(l&&typeof o=="number"){a.set("text",Hc(l.textConfig,o,Math.max(0,r)));return}const c=this._motionPathTracks.get(n);if(c&&typeof o=="number"){const h=Qo(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 xe(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,Me(e)){this._trackPlayers.set(e.id,new _c(e));return}if(Se(e)){this._trackPlayers.set(e.id,new Oc(e)),this._springTracks.set(e.id,e);return}if(Ks(e))this._trackPlayers.set(e.id,new ni(e)),this._textTracks.set(e.id,e);else if(Co(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 ni(n)),this._motionPathTracks.set(e.id,e)}else this._trackPlayers.set(e.id,new ni(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(Se(s)||Me(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=xe(r).filter(d=>xe(s).includes(d));if(a.length===0)continue;const l=this.getTrackSpan(r.id);if(!l||!(l.from<=i.to&&i.from<=l.to))continue;const h=i.from>=l.from;for(const d of a)e.push({target:d,property:s.property,losingTrackId:h?r.id:s.id,winningTrackId:h?s.id:r.id})}}return e}_matches(e,n){if(n.id!==void 0&&e.id!==n.id||n.property!==void 0&&e.property!==n.property||n.target!==void 0&&!xe(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:_o(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 nm=100;function er(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((S,k)=>{(g==="forward"?(m?S>=f:S>f)&&S<=p:(m?S<=f:S<f)&&S>=p)&&w.push(k)}),w.sort((S,k)=>(g==="forward"?t[S]-t[k]:t[k]-t[S])||S-k);for(const S of w)i.push({kind:"event",index:S,direction:g})};let c=e.time,h=e.direction,d=e.fresh===!0;const u=Math.min(nm,Math.max(0,n.iteration-e.iteration));for(let f=0;f<u;f++){const p=h==="forward"?r:0;l(c,p,h,d),i.push({kind:"repeat"}),a?(h=h==="forward"?"reverse":"forward",c=p,d=!1):(c=h==="forward"?0:r,d=!0)}return u>0&&s.holding&&!a?{crossings:i,passes:o}:(l(c,n.time,h,d),{crossings:i,passes:o})}function Rc(t){return Me(t)?{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:Lc(t.inertia),...ce(t)}:Se(t)?{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...ce(t)}:Ks(t)?{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:t.keyframes.map(nr),...ce(t)}:Co(t)?{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:t.keyframes.map(nr),...ce(t)}:{id:t.id,target:t.target,property:t.property,keyframes:t.keyframes.map(nr),...t.interpolation!==void 0&&{interpolation:t.interpolation},...ce(t)}}function Lc(t){return{...t,...Array.isArray(t.end)&&{end:[...t.end]}}}function nr(t){return{time:t.time,value:t.value,...t.easing&&{easing:t.easing}}}function ce(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 Nc(t){if(Me(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"inertia",inertia:Lc(e.inertia),...ce(e)}}if(Se(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"spring",spring:{...e.spring},...ce(e)}}if(Ks(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),...ce(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,...ce(e)}}return ei({id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,...t.interpolation!==void 0&&{interpolation:t.interpolation},...ce(t)})}function Dc(t){const e=t._config.markers;return{formatVersion:_o(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(Rc),...t.captions&&{captions:JSON.parse(JSON.stringify(t.captions))}}}function yn(t){const e=t.formatVersion??1;if(e>Oo)throw new Error(`tinyfly: this animation uses format version ${e}, but this tinyfly reads up to version ${Oo}. Update tinyfly to play it.`);return new Ot({id:t.id,name:t.name,config:t.config,tracks:t.tracks.map(Nc),captions:t.captions})}function sm(t){return JSON.stringify(Dc(t))}function im(t){const e=JSON.parse(t);return yn(e)}function Gt(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 sr(t,e,n){return e+t.next()*(n-e)}function Fc(t,e,n,s){if(s<=0)return sr(t,e,n);const i=Math.floor((n-e)/s),o=Math.round(t.next()*i);return e+o*s}function om(t,e){if(e.length!==0)return e[Math.floor(t.next()*e.length)]}const Wc=/^([+\-*/])=\s*(-?[\d.]+)$/,Bc=/^random\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*(?:,\s*(-?[\d.]+)\s*)?\)$/i;function rm(t){return typeof t!="string"?!1:Wc.test(t.trim())||Bc.test(t.trim())}function ir(t,e={}){if(typeof t!="string")return t;const n=t.trim(),s=Wc.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=Bc.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?Fc(e.random,o,r,a):sr(e.random,o,r)}return t}function qc(t,e=0,n){const s=[];let i=e;for(const o of t){const r=ir(o,{base:i,random:n});s.push(r),typeof r=="number"&&(i=r)}return s}class am{random;constructor(e){this.random=$e(e)}get seed(){return this.random.seed}resolve(e,n=0){return ir(e,{base:n,random:this.random})}resolveSequence(e,n=0){return qc(e,n,this.random)}}const lm=600;function zc(t){if(Array.isArray(t)){const[u,f,p,g]=t;return{fn:jc(u,f,p,g),bezier:[u,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=u=>(u-n)/o,l=u=>(u-s)/r;if(e.length===1&&i.type==="C"){const[u,f,p,g]=i.points,m=[a(u),l(f),a(p),l(g)];return{fn:jc(...m),bezier:m}}const c=[],h=[],d=Math.max(8,Math.ceil(lm/e.length));for(const u of e)for(let f=c.length===0?0:1;f<=d;f++){const[p,g]=cm(u,f/d);c.push(a(p)),h.push(l(g))}return{fn:hm(c,h)}}function Yc(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 Kc(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 cm(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 hm(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 jc(t,e,n,s){const i=(r,a,l)=>3*(1-r)*(1-r)*r*a+3*(1-r)*r*r*l+r*r*r,o=(r,a,l)=>3*(1-r)*(1-r)*a+6*(1-r)*r*(l-a)+3*r*r*(1-l);return r=>{if(r<=0)return 0;if(r>=1)return 1;let a=r;for(let h=0;h<8;h++){const d=i(a,t,n)-r,u=o(a,t,n);if(Math.abs(d)<1e-6)return i(a,e,s);if(Math.abs(u)<1e-6)break;a-=d/u}let l=0,c=1;a=r;for(let h=0;h<40;h++)i(a,t,n)<r?l=a:c=a,a=(l+c)/2;return i(a,e,s)}}const dm=350,um=300,fm=550;function gm(t,e={}){const n=e.lead??dm,s=e.gap??um,i=e.tail??fm,o=[];let r=0;return t.forEach((a,l)=>{const c=[];let h=r+n;a.lines.forEach((u,f)=>{if(!(u.duration>=0))throw new Error(`narration: scene ${l} line ${f} has an invalid duration (${u.duration})`);f>0&&(h+=s),c.push({id:u.id??`s${l}-l${f}`,scene:l,line:f,start:h,end:h+u.duration,text:u.text}),h+=u.duration});const d=h+i+(a.tail??0);o.push({id:a.id??`s${l}`,start:r,duration:d-r,cues:c}),r=d}),{duration:r,scenes:o,cues:o.flatMap(a=>a.cues)}}function pm(t){return t.cues.map(e=>({id:e.id,time:e.start,label:e.text}))}function mm(t,e){let n=t.scenes[0];for(const s of t.scenes)if(e>=s.start)n=s;else break;return n}const or=t=>6e4/t.bpm;function si(t,e){return t.offset+e*or(t)}function ii(t,e){return(e-t.offset)/or(t)}function ym(t,e){return si(t,Math.round(ii(t,e)))}function bm(t,e){return si(t,Math.ceil(ii(t,e)-1e-9))}function wm(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(ii(t,e)-1e-9);;o++){const r=si(t,o);if(r>n+1e-9)break;i.push({time:r,bar:(o%s+s)%s===0,n:o})}return i}const bn=100;function km(t,e,n={}){const s=n.minBpm??70,i=n.maxBpm??180,o=Math.max(1,Math.round(e/bn)),r=Math.min(t.length,Math.round((n.maxSeconds??60)*e)),a=Math.floor(r/o);if(a<4)return{bpm:120,offset:0,confidence:0};const l=new Float64Array(a);for(let v=0;v<a;v++){let T=0;for(let I=v*o;I<(v+1)*o;I++)T+=t[I]*t[I];l[v]=Math.log(1e-6+T/o)}const c=new Float64Array(a);for(let v=1;v<a;v++)c[v]=Math.max(0,l[v]-l[v-1]);const h=c.reduce((v,T)=>v+T,0)/a;for(let v=0;v<a;v++)c[v]=Math.max(0,c[v]-h);const d=Math.max(1,Math.floor(60*bn/i)),u=Math.min(a-1,Math.ceil(60*bn/s)),f=v=>{let T=0;for(let I=v;I<a;I++)T+=c[I]*c[I-v];return T/(a-v)};let p=0;for(let v=0;v<a;v++)p+=c[v]*c[v];p/=a;let g=d,m=-1/0;for(let v=d;v<=u;v++){const T=60*bn/v,I=Math.exp(-.5*(Math.log2(T/120)/.9)**2),O=f(v)*I;O>m&&(m=O,g=v)}const w=v=>{const T=Math.floor(v);return T<0||T+1>=a?0:c[T]+(c[T+1]-c[T])*(v-T)},S=(v,T)=>{let I=0;for(let O=T;O<a;O+=v)I+=w(O);return I};let k=g,y=0,E=-1/0;for(let v=g-.6;v<=g+.6+1e-9;v+=.02){if(v<1)continue;const T=Math.max(1,Math.round(v*4));for(let I=0;I<T;I++){const O=I/T*v,_=S(v,O);_>E&&(E=_,y=O,k=v)}}const x=60*bn/k,$=p>0?Math.max(0,Math.min(1,f(g)/p)):0,M=(y+.5)*1e3/bn;return{bpm:Math.round(x*100)/100,offset:Math.round(M%(6e4/x)),confidence:$}}const vm=600,Mm=250,Xc=1;function Sm(t,e){const n=e.target??"Camera",s={x:e.stage.width/2,y:e.stage.height/2},i={},o=(d,u,f,p)=>{const g=i[d]??=[];for(;g.length>0&&g[g.length-1].time>=u;)g.pop();g.push({time:u,value:f,...p?{easing:p}:{}})},r=d=>{const u=d.rotate*Math.PI/180,f=(d.focusX-s.x)*d.scale,p=(d.focusY-s.y)*d.scale;return{x:-(f*Math.cos(u)-p*Math.sin(u)),y:-(f*Math.sin(u)+p*Math.cos(u)),scale:d.scale,rotate:d.rotate}},a=(d,u,f)=>{const p=r(u);for(const g of["x","y","scale","rotate"])o(g,d,p[g],f)};let l={focusX:s.x,focusY:s.y,scale:1,rotate:0};const c=[...t].sort((d,u)=>d.at-u.at),h=c.filter(d=>!("shake"in d));h.length>0&&a(0,l);for(const d of h)if("frame"in d){const u=Math.max(Xc,d.duration??vm);a(d.at,l),l={focusX:d.frame.focus?.x??s.x,focusY:d.frame.focus?.y??s.y,scale:d.frame.scale??1,rotate:d.frame.rotate??0},a(d.at+u,l,d.easing??(u>Xc?"ease-in-out":void 0))}else{const{follow:u}=d,f=u.lag??Mm,p=new Ot({id:"follow",tracks:[{id:"x",target:"s",property:"x",keyframes:u.x}]}),g=S=>p.getStateAtTime(S).values.get("s")?.get("x")??l.focusX,m=[d.at,...u.x.map(S=>S.time).filter(S=>S>d.at&&S<d.until),d.until];a(d.at,l);const w=S=>({focusX:g(S)+(u.lead??0),focusY:u.y??l.focusY,scale:u.scale??l.scale,rotate:l.rotate});for(const S of m){const k=u.x.find(y=>y.time===S)?.easing;a(S+f,w(S),S===d.at?"ease-in-out":k)}l=w(d.until)}for(const d of c.filter(u=>"shake"in u)){const u=d.shake.strength??12,f=d.shake.roll??1.5,p=1e3/(d.shake.frequency??24),g=$e(d.shake.seed??Math.round(d.at)+1),m=()=>g.next()*2-1;for(const w of["shakeX","shakeY","shakeRotate"])o(w,d.at,0);for(let w=d.at+p;w<d.at+d.duration;w+=p){const S=1-(w-d.at)/d.duration;o("shakeX",w,m()*u*S),o("shakeY",w,m()*u*S),o("shakeRotate",w,m()*f*S)}for(const w of["shakeX","shakeY","shakeRotate"])o(w,d.at+d.duration,0,"ease-out")}return Object.entries(i).map(([d,u])=>({id:`${n}-${d}`,target:n,property:d,keyframes:u}))}function Gc(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 is(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=Gc(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??is(e,n):void 0;return`Unknown ${t} ${JSON.stringify(e)}${i?`: did you mean "${i}"?`:"."} Known: ${n.join(", ")}`}function os(t,e){const n=e.step??33,s=e.stiffness??120,i=e.damping??9,o=e.mass??1;let r=t(e.start),a=0;const l=[{time:e.start,value:r}];let c=e.start+n;for(let h=e.start+1;h<=e.end;h++){const u=s*(t(h)-r)-i*a;a+=u/o*.001,r+=a*.001,(h>=c||h===e.end)&&(l.push({time:h,value:r}),c+=n)}return l}const he=t=>Math.round(t*1e3)/1e3;function Uc(t,e={}){if(t.length===0)return"";const n=e.curviness??1,s=e.closed??!1,i=t.length;let o=`M${he(t[0].x)} ${he(t[0].y)}`;if(i===1)return o;const r=l=>s?t[(l%i+i)%i]:t[Math.max(0,Math.min(i-1,l))],a=s?i:i-1;for(let l=0;l<a;l++){const c=r(l-1),h=r(l),d=r(l+1),u=r(l+2);if(n===0){o+=` L${he(d.x)} ${he(d.y)}`;continue}const f=n/6,p=h.x+(d.x-c.x)*f,g=h.y+(d.y-c.y)*f,m=d.x-(u.x-h.x)*f,w=d.y-(u.y-h.y)*f;o+=` C${he(p)} ${he(g)} ${he(m)} ${he(w)} ${he(d.x)} ${he(d.y)}`}return s?`${o} Z`:o}const Ht=(t,e=0)=>{const n=parseFloat(t??"");return Number.isFinite(n)?n:e};function Tm(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 oi(t){const e=t.attributes;switch(t.tag.toLowerCase()){case"path":return e.d??null;case"circle":case"ellipse":{const n=Ht(e.cx),s=Ht(e.cy),i=t.tag.toLowerCase()==="circle"?Ht(e.r):Ht(e.rx),o=t.tag.toLowerCase()==="circle"?Ht(e.r):Ht(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=Ht(e.x),s=Ht(e.y),i=Ht(e.width),o=Ht(e.height);let r=e.rx!=null?Ht(e.rx):e.ry!=null?Ht(e.ry):0,a=e.ry!=null?Ht(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${Ht(e.x1)} ${Ht(e.y1)} L${Ht(e.x2)} ${Ht(e.y2)}`;case"polyline":case"polygon":{const n=Tm(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 Em(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 Am=2.5;function Vc(t){const e=[],n=[],s=t.length,i=(o,r)=>{for(let a=o+r;a>=0&&a<s;a+=r){const l=(t[a].x-t[o].x)*r,c=(t[a].y-t[o].y)*r,h=Math.hypot(l,c);if(h>1e-9)return[l/h,c/h]}return null};for(let o=0;o<s;o++){const r=t[o],a=i(o,-1),l=i(o,1),c=a??l??[1,0],h=l??a??[1,0];let d=c[0]+h[0],u=c[1]+h[1];const f=Math.hypot(d,u);f<1e-9?(d=c[0],u=c[1]):(d/=f,u/=f);const p=d*c[0]+u*c[1],g=Math.min(Am,1/Math.max(p,1e-6)),m=r.width/2*g;e.push({x:r.x-u*m,y:r.y+d*m}),n.push({x:r.x+u*m,y:r.y-d*m})}return{left:e,right:n}}function Jc(t){const e=t.length;if(e<2)return null;const n=t[e-1];for(let s=e-2;s>=0;s--){const i=n.x-t[s].x,o=n.y-t[s].y,r=Math.hypot(i,o);if(r>1e-9)return{x:n.x,y:n.y,radius:n.width/2,start:Math.atan2(i/r,-o/r)}}return null}function ri(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function wn(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function kn(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function Pe(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function ai(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 li(t){return Math.hypot(t[0],t[1],t[2])}function rr(t,e){return li(wn(t,e))}function Xe(t){const e=li(t);return e===0?[0,0,0]:kn(t,1/e)}function Zc(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 xm=Object.freeze(Object.defineProperty({__proto__:null,add:ri,cross:ai,distance:rr,dot:Pe,length:li,lerp:Zc,normalize:Xe,scale:kn,subtract:wn},Symbol.toStringTag,{value:"Module"})),$m=Math.PI/180;function ci(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function At(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 Ge(t){return[1,0,0,0,0,1,0,0,0,0,1,0,t[0],t[1],t[2],1]}function Ue(t){return[t[0],0,0,0,0,t[1],0,0,0,0,t[2],0,0,0,0,1]}function ne(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 ar(t,e,n){const s=ne(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 Pm(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 lr(t){const[e,n,s,i,o,r,a,l,c,h,d,u,f,p,g,m]=t,w=e*r-n*o,S=e*a-s*o,k=e*l-i*o,y=n*a-s*r,E=n*l-i*r,x=s*l-i*a,$=c*p-h*f,M=c*g-d*f,v=c*m-u*f,T=h*g-d*p,I=h*m-u*p,O=d*m-u*g,_=w*O-S*I+k*T+y*v-E*M+x*$;if(Math.abs(_)<1e-12)return null;const C=1/_;return[(r*O-a*I+l*T)*C,(s*I-n*O-i*T)*C,(p*x-g*E+m*y)*C,(d*E-h*x-u*y)*C,(a*v-o*O-l*M)*C,(e*O-s*v+i*M)*C,(g*k-f*x-m*S)*C,(c*x-d*k+u*S)*C,(o*I-r*v+l*$)*C,(n*v-e*I-i*$)*C,(f*E-p*k+m*w)*C,(h*k-c*E-u*w)*C,(r*M-o*T-a*$)*C,(e*T-n*M+s*$)*C,(p*S-f*y-g*w)*C,(c*y-h*S+d*w)*C]}function Im(t,e,n,s){const i=1/Math.tan(t*$m/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 Om(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 _m(t,e,n=[0,1,0]){const s=Xe(wn(t,e)),i=Xe(ai(n,s)),o=ai(s,i);return[i[0],o[0],s[0],0,i[1],o[1],s[1],0,i[2],o[2],s[2],0,-Pe(i,t),-Pe(o,t),-Pe(s,t),1]}function Bt(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 Cm=Object.freeze(Object.defineProperty({__proto__:null,compose:ar,fromQuat:ne,identity:ci,invert:lr,lookAt:_m,multiply:At,orthographic:Om,perspective:Im,scaling:Ue,transformPoint:Bt,translation:Ge,transpose:Pm},Symbol.toStringTag,{value:"Module"})),hi={"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]},Qc={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 Hm(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 rs(t){const e=th.get(t.trim().toLowerCase());if(e)return e;const n=Hm(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(d=>Number.parseFloat(d)).filter(d=>Number.isFinite(d)),c=r==="inout"?"in-out":r;if(o==="back"&&l.length===0&&n in hi)return{easing:{type:"cubic-bezier",points:hi[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 Qc?{easing:Qc[n]}:n in hi?{easing:{type:"cubic-bezier",points:hi[n]}}:{easing:"ease-out"}}const th=new Map;function cr(t,e){return th.set(t.trim().toLowerCase(),e.bezier?{easing:{type:"cubic-bezier",points:e.bezier},fn:e.fn}:{fn:e.fn,requiresBaking:"custom"}),t}function hr(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 eh=/^\s*random\(\s*(\[.*\]|[^)]*)\s*\)\s*$/;function nh(t){return typeof t=="string"&&eh.test(t)}function Rm(t=1){let e=hr(t);const n=(l,c)=>((...h)=>h.length>=l?c(...h):d=>c(...h,d)),s=(l,c,h)=>Math.min(Math.max(h,Math.min(l,c)),Math.max(l,c)),i=(l,c,h,d,u)=>c===l?h:h+(u-l)/(c-l)*(d-h),o=(l,c)=>{if(typeof l=="number")return l===0?c:Math.round(c/l)*l;if(Array.isArray(l))return sh(l,c,1/0);if("values"in l)return sh(l.values,c,l.radius??1/0);const h=Math.round(c/l.increment)*l.increment;return Math.abs(h-c)<=(l.radius??1/0)?h:c},r=(l,c,h)=>{const d=l+e()*(c-l);return h?Math.round(d/h)*h:d};return{clamp:n(3,s),mapRange:n(5,i),normalize:n(3,(l,c,h)=>i(l,c,0,1,h)),interpolate:n(3,(l,c,h)=>{if(typeof l=="object"&&!Array.isArray(l)){const d={};for(const u of Object.keys(l))d[u]=ss(l[u])(l[u],c[u],h);return d}return ss(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 d=l,f=c-d,p=g=>f===0?d:((g-d)%f+f)%f+d;return h===void 0?p:p(h)}),wrapYoyo:n(3,(l,c,h)=>{const d=c-l;if(d===0)return l;const u=((h-l)%(d*2)+d*2)%(d*2);return l+(u>d?d*2-u:u)}),snap:n(2,o),random:((l,c,h,d)=>{if(Array.isArray(l)){const f=()=>l[Math.floor(e()*l.length)];return c===!0?f:f()}const u=()=>r(l,c,h);return d?u:u()}),shuffle:l=>{for(let c=l.length-1;c>0;c--){const h=Math.floor(e()*(c+1));[l[c],l[h]]=[l[h],l[c]]}return l},distribute:({base:l=0,amount:c,each:h,from:d="start",ease:u})=>(f,p,g)=>{const m=g.length,S=js(f,m,{...c!==void 0?{amount:c}:{each:h??1},from:d}),k=c!==void 0?c:(h??1)*Ro(m,d),y=u&&k>0?u(S/k)*k:S;return l+y},pipe:(...l)=>c=>l.reduce((h,d)=>d(h),c),splitColor:l=>Lm(l),getUnit:l=>typeof l=="number"?"":/^-?[\d.]+(?:e[-+]?\d+)?([a-z%]*)$/i.exec(l.trim())?.[1]??"",seed:l=>{e=hr(l)},resolveRandomString:l=>{const c=eh.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,d,u]=c.split(",").map(f=>Number.parseFloat(f));return r(h,d,Number.isFinite(u)?u:void 0)}}}function sh(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 Lm(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 Nm=/^([+-])=\s*(-?[\d.]+)$/,Dm=/^([<>])\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=Nm.exec(i);if(o){const c=s(o[2]);return e.cursor+(o[1]==="-"?-c:c)}const r=Dm.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 Fm(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 Wm(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),S=Math.abs(m-a.y);return e.axis==="x"?w:e.axis==="y"?S:Math.hypot(w,S)};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 d=e.amount!==void 0?e.amount:(e.each??0)*h,u=e.ease?rs(e.ease):void 0,f=u?u.fn??Lt(u.easing):void 0;return c.map(p=>{const g=h===0?0:p/h;return(f?f(g):g)*d})}const dr=new Set(["duration","delay","ease","repeat","repeatDelay","yoyo","stagger","onComplete","onUpdate","onStart","onRepeat","onReverseComplete","repeatRefresh","keyframes","easeEach","scrollTo","id","immediateRender","overwrite","paused","scrollTrigger","spring"]),Bm={rotation:"rotate",rotationZ:"rotate",rotationX:"rotateX",rotationY:"rotateY",transformPerspective:"perspective",perspective:"childPerspective"};function di(t){const e={},n={};for(const[s,i]of Object.entries(t))dr.has(s)?e[s]=i:n[Bm[s]??s]=i;return{config:e,properties:n}}function ui(t,e){return t===void 0?e:t*1e3}function ur(t,e){if(t!==void 0)return typeof t=="number"?{each:t*1e3}:Fm(t)?{offsets:Wm(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 qm={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 ih(t){return qm[t]}function zm(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=Uc(e.path,{curviness:e.curviness});else if(gn(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 Ym(t){const e=typeof t=="string"||Array.isArray(t)?{path:t}:{...t};return{...e,start:e.end??1,end:e.start??0}}function oh(t){return typeof t=="object"&&t!==null&&"shape"in t?t.shape:t}function Km(t){if(t.morphSVG===void 0)return t;const{morphSVG:e,...n}=t,s=oh(e);if(typeof s!="string"||!gn(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 jm(t,e){if(t===!0)return[0,e];if(t===!1)return[0,0];if(typeof t=="number")return[0,rh(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 rh(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 Xm(t,e){const[n,s]=jm(t,e);return{strokeDasharray:[s-n,e],strokeDashoffset:-n}}function Gm(t,e){if(t.drawSVG===void 0)return t;const{drawSVG:n,...s}=t;return{...s,...Xm(n,e)}}function Um(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 rh(t,e){return Math.max(0,Math.min(e,t))}function Vm(t){let e=2166136261;for(let n=0;n<t.length;n++)e=Math.imul(e^t.charCodeAt(n),16777619);return e>>>0}function Jm(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??Vm(`${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 fr(t){return Math.max(.1,t/25)}function Zm(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?fr(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(Zn(i))]:n.end!==void 0&&(i.end=Array.isArray(n.end)?[...n.end]:n.end),i}function Qm(t){const e=t===!0?{}:typeof t=="string"?{preset:t}:t;if(e.preset!==void 0&&!(e.preset in Us))throw new Error(`gsap-compat: unknown spring preset "${e.preset}" — use one of ${Object.keys(Us).join(", ")}`);return{...e.preset?Us[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 t1(t,e){if(t===!0||typeof t=="string")return;const n=t.velocity;return typeof n=="number"?n:n?.[e]}class Ve{timeline;options;cursor=0;fallbackRandom=hr(1);previousStart=0;previousEnd=0;labels=new Map;trackCounter=0;lastValues=new Map;constructor(e={}){this.options=e,this.timeline=new Ot({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,ls(n),s)}from(e,n,s){const{config:i,properties:o}=di(ls(n)),{motionPath:r,text:a,scrambleText:l,...c}=o,h=this.targetsOf(e)[0],d={...i};for(const p of Object.keys(c))d[p]=this.resolveStart(h,p);r!==void 0&&(d.motionPath=Ym(r));const u={},f=String(this.resolveStart(h,"text"));return a!==void 0&&(u.text=gr(a),d.text=typeof a=="object"?{...a,value:f}:f),l!==void 0&&(u.text=gr(l),d.scrambleText=typeof l=="object"?{...l,text:f}:f),this.build(e,{...c,...u},d,s)}fromTo(e,n,s,i){const{properties:o}=di(ls(n));return this.build(e,o,ls(s),i)}set(e,n,s){return this.build(e,void 0,{...ls(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=ei({...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}=di(s),{motionPath:a,text:l,scrambleText:c,inertia:h,...d}=r,u=this.targetsOf(e),f=as(i,this.context()),p=ui(o.delay,0),g=ui(o.duration,500),m=ur(o.stagger,{count:u.length,columnsFromLayout:this.options.layoutColumns?()=>this.options.layoutColumns(u):void 0,random:this.options.random??this.fallbackRandom}),w=this.easingFor(o.ease),S=[],k=o.spring;let y=0,E=!1;for(const[I,O]of Object.entries(d)){const _=O;let C=n?.[I]!==void 0?n[I]:this.resolveStart(u[0],I);if(typeof C!=typeof _&&(this.warn(`no usable start value for "${I}" on "${u[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 "${u[0]}" eases instead`),k!==void 0&&typeof C=="number"&&typeof _=="number"){const X={...Qm(k),from:C,to:_,velocity:t1(k,I)??this.options.startVelocity?.(u[0],I)??0},J=this.nextTrackId(`${u[0]}-${I}-spring`),j={id:J,target:u[0],...u.length>1&&{targets:u},...m&&u.length>1&&{stagger:m},property:I,kind:"spring",spring:X,delay:f+p};this.timeline.addTrack(j),S.push(J),y=Math.max(y,Kl(X));for(const A of u)this.lastValues.set(`${A}|${I}`,_);continue}E=!0;const D=this.keyframesFor(C,_,g,w,o.ease),q=this.nextTrackId(`${u[0]}-${I}`);this.timeline.addTrack(ei({id:q,target:u[0],...u.length>1&&{targets:u},...m&&u.length>1&&{stagger:m},property:I,delay:f+p,keyframes:D,...I==="quaternion"&&{interpolation:"slerp"}})),S.push(q);for(const X of u)this.lastValues.set(`${X}|${I}`,_)}const x=Jm({text:l,scrambleText:c},u[0],g);if(x){const I=n?.text??n?.scrambleText,O=I!==void 0?gr(I):this.resolveStart(u[0],"text"),_=this.nextTrackId(`${u[0]}-text`),C={id:_,target:u[0],...u.length>1&&{targets:u},...m&&u.length>1&&{stagger:m},property:"text",textConfig:{from:typeof O=="string"?O:String(O??""),...x},delay:f+p,keyframes:this.keyframesFor(0,1,g,w,o.ease)};this.timeline.addTrack(C),S.push(_);for(const D of u)this.lastValues.set(`${D}|text`,x.to)}if(a!==void 0){const{config:I,start:O,end:_}=zm(a),C=this.nextTrackId(`${u[0]}-motionPath`),D={id:C,target:u[0],...u.length>1&&{targets:u},...m&&u.length>1&&{stagger:m},property:"motionPath",motionPathConfig:I,delay:f+p,keyframes:this.keyframesFor(O,_,g,w,o.ease)};this.timeline.addTrack(D),S.push(C)}if(h!==void 0)for(const[I,O]of Object.entries(h)){const _=this.resolveStart(u[0],I);if(typeof _!="number"){this.warn(`inertia on "${I}" needs a numeric start value; skipped`);continue}const C=Zm(_,O),D=this.nextTrackId(`${u[0]}-${I}-inertia`),q={id:D,target:u[0],...u.length>1&&{targets:u},...m&&u.length>1&&{stagger:m},property:I,kind:"inertia",inertia:C,delay:f+p};this.timeline.addTrack(q),S.push(D),y=Math.max(y,un(C));for(const X of u)this.lastValues.set(`${X}|${I}`,dn(C))}const v=((h!==void 0||k!==void 0)&&!E&&!x&&a===void 0?y:Math.max(g,y))+(m&&u.length>1?Vn(u.length,m):0),T=f+p+v;return this.previousStart=f+p,this.previousEnd=T,this.cursor=Math.max(this.cursor,T),{trackIds:S,start:f+p,end:T,kill:()=>{for(const I of S)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"?rs(o):void 0;if(a?.requiresBaking==="custom"||this.options.bakeEases&&Un(i)){const c=a?.fn??Lt(i);return[r,...Zo(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=ih(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 rs(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 gr(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 e1(t){return new Ve(t)}function ls(t){return Um(Km(t))}function n1(t){return!Array.isArray(t)||t.length!==4?null:`matrix3d(${ne(Ae(t)).map(n=>Math.round(n*1e6)/1e6+0).join(", ")})`}const s1=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),i1="#ffffff",o1="rgba(0, 0, 0, 0.5)";function r1(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??i1})`),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??o1})`)}return e.length>0?e.join(" "):null}function a1(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 l1(t){if(!("ownerSVGElement"in t))return;const e=t.style;!e||e.transformBox||(e.transformBox="fill-box",e.transformOrigin||(e.transformOrigin="50% 50%"))}const ah=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"]),c1=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),h1=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],d1=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),u1=new Set(["originX","originY"]),f1=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),g1=new Set(["drawOn"]),p1={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},lh={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},m1="http://www.w3.org/2000/svg";class Je{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)&&!g1.has(p)){if(c1.has(p))(s??={})[p]=g;else if(d1.has(p))typeof g=="number"&&((i??={})[p]=g);else if(u1.has(p))typeof g=="number"&&((o??={})[p]=g);else if(f1.has(p))typeof g=="number"&&((r??={})[p]=g);else if(s1.has(p))(a??={})[p]=g;else if(p!=="perspective"){if(p!=="shine")if(p==="text"&&typeof g=="string")a1(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 d=n.get("shine");typeof d=="number"&&this.applyShine(e,d);const u=[],f=n.get("perspective");if(typeof f=="number"&&f>0&&u.push(`perspective(${f}px)`),s)for(const p of h1){const g=s[p];if(g===void 0)continue;const m=this.buildTransformPart(p,g);m&&u.push(m)}if(u.length>0&&(e.style.transform=u.join(" "),l1(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=r1(a);p&&(e.style.filter=p)}}buildTransformPart(e,n){if(e==="quaternion")return n1(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===m1&&n in lh){const a=Array.isArray(s)?s.join(", "):String(s);e.style[lh[n]]=a;return}else n==="fill"&&e.dataset?.elementType==="text"?i="color":i=p1[n]??n;let r;typeof s=="number"?ah.has(n)||ah.has(i)?r=`${s}px`:r=String(s):Array.isArray(s)?r=s.join(", "):r=s,e.style[i]=r}}const y1={request:t=>requestAnimationFrame(t),cancel:t=>cancelAnimationFrame(t)};class ch{adapter=new Je;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=Rm();active=new Map;applied=new Map;dirty=new Set;frameId=null;lastTimestamp=null;destroyed=!1;constructor(e={}){this.scheduler=e.scheduler??y1,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);pr(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(pr(e))return[e];if(!b1(e))return[e];const n=[];for(const s of Array.from(e))n.push(...this.targetsOf(s));return n}nameFor(e){return pr(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 pr(t){return typeof t=="object"&&t!==null&&t.nodeType===1}function b1(t){if(Array.isArray(t))return!0;const e=t;return typeof e.length=="number"&&typeof e.item=="function"}function fi(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 hh=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function w1(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function k1(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 v1(t,e){const n=typeof t=="string"||Array.isArray(t)||hh(t)?{path:t}:t,{align:s,alignOrigin:i,path:o,...r}=n,a=x=>{const $=hh(x)?x:e.query(x);return $||e.warn(`gsap-compat: motionPath could not find "${String(x)}"`),$};let l=null,c="";if(Array.isArray(o)||typeof o=="string"&&gn(o))c=o;else{l=a(o);const x=l&&oi({tag:l.localName,attributes:w1(l)});l&&!x&&e.warn(`gsap-compat: motionPath element <${l.localName}> has no path geometry`),c=x??""}const h={...r,path:c};if(s===void 0||s===!1)return h;const d=s===!0?l:a(s);if(!d)return s===!0&&e.warn("gsap-compat: motionPath align: true needs the path to be an element"),h;const u=e.targets[0];if(!u)return h;const[f,p,g,m,w,S]=k1(d),k=fi(u),[y,E]=i??[.5,.5];for(const x of e.targets.slice(1)){const $=fi(x);if(Math.abs($.left-k.left)>.5||Math.abs($.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,S-k.top-E*k.height],h}const dh=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function uh(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function fh(t){if(!t)return null;const e=oi({tag:t.localName,attributes:uh(t)});return e||(t.querySelector("path")?.getAttribute("d")??null)}function M1(t,e,n){const s=oh(t);if(typeof s=="string"&&gn(s))return s;const i=dh(s)?s:typeof s=="string"?e(s):null,o=fh(i);return o||(n(`gsap-compat: morphSVG could not find a shape for "${String(s)}"`),"")}const S1=new Set(["cx","cy","r","rx","ry","x","y","width","height","x1","y1","x2","y2","points"]);function T1(t,e=document){return(typeof t=="string"?Array.from(e.querySelectorAll(t)):dh(t)?[t]:Array.from(t)).map(s=>{if(s.localName==="path")return s;const i=oi({tag:s.localName,attributes:uh(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))S1.has(r.name)||o.setAttribute(r.name,r.value);return o.setAttribute("d",i),s.parentNode.replaceChild(o,s),o})}const gh=.3;class ph{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=mh(),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=mh(),i=Math.max(1,s-this.lastTime);this.lastTime=s;const o=e/i*1e3,r=n/i*1e3;this.velocityX+=(o-this.velocityX)*gh,this.velocityY+=(r-this.velocityY)*gh}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 mh(){return typeof performance<"u"?performance.now():Date.now()}function yh(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 bh(t,e){return e<=0?[]:t.map(n=>Math.round(n/e)*e)}class mr{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 ph({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=E1(i/s);e.pause(),e.seek(o*n)}applyConstraints(e,n){let s=e;const i=[...bh([s],this.options.snap??0),...(n==="x"?this.options.snapLinesX:this.options.snapLinesY)??[]],o=yh([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 E1(t){return t<0?0:t>1?1:t}function A1(t){const e=new mr(t);return e.start(),e}const x1={x:"x",y:"y","x,y":"both"},yr=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function wh(t,e){const n=fi(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 kh(t){return Array.isArray(t)?[...t]:t}function $1(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 P1(t,e,i,o,s);const r=x1[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):yr(s.bounds)?s.bounds:null,h={bounds:(!l&&s.bounds&&!yr(s.bounds)?s.bounds:void 0)??(l?wh(o,l):void 0)};let d=null;const u=()=>{d?.kill(),d=null},f=g=>{const m=s.inertia===!0?{}:s.inertia,w=m.friction??(m.resistance!==void 0?fr(m.resistance):4),S=a(),k=h.bounds??{};let y,E;const x=m.end;if(Array.isArray(x)){const M=Zn({from:S.x,velocity:r==="y"?0:g.x,friction:w}),v=Zn({from:S.y,velocity:r==="x"?0:g.y,friction:w});let T=x[0];for(const I of x)Math.hypot(I.x-M,I.y-v)<Math.hypot(T.x-M,T.y-v)&&(T=I);T&&(y=[T.x],E=[T.y])}else typeof x=="number"?(y=x,E=x):x&&(y=kh(x.x),E=kh(x.y));const $={};r!=="y"&&($.x={velocity:g.x,friction:w,min:k.minX,max:k.maxX,end:y}),r!=="x"&&($.y={velocity:g.y,friction:w,min:k.minY,max:k.maxY,end:E}),d=t.to(o,{inertia:$,onComplete:()=>s.onThrowComplete?.()})},p=new mr({target:o,axis:r,snap:s.snap,get bounds(){return h.bounds},getPosition:a,onPress:()=>{u(),l&&(h.bounds=wh(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(){u(),p.destroy()}}}function P1(t,e,n,s,i){const o=typeof i.bounds=="object"&&i.bounds!==null&&!yr(i.bounds)?i.bounds:{},r=()=>{const k=e.appliedValue(n,"rotate");return typeof k=="number"?k:0},a=k=>Math.min(o.maxRotation??1/0,Math.max(o.minRotation??-1/0,k));let l=null,c=!1,h,d={x:0,y:0},u=0,f=0,p=[];const g=k=>Math.atan2(k.clientY-d.y,k.clientX-d.x)*180/Math.PI,m=k=>{if(c)return;l?.kill(),l=null,c=!0,h=k.pointerId,s.setPointerCapture?.(k.pointerId);const y=s.getBoundingClientRect();d={x:y.left+y.width/2,y:y.top+y.height/2},u=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 E=y-u;E>180&&(E-=360),E<-180&&(E+=360),u=y,f+=E;let x=a(f);i.snap&&(x=a(Math.round(x/i.snap)*i.snap)),e.apply(n,{rotate:x});const $=performance.now();for(p.push({time:$,rotation:x});p.length>2&&$-p[0].time>100;)p.shift();const M={x:0,y:0};i.onDrag?.(M)},S=k=>{if(!c||k.pointerId!==h)return;c=!1;const y=p[0],E=p[p.length-1],x=y&&E?(E.time-y.time)/1e3:0,$=x>0?(E.rotation-y.rotation)/x:0;if(i.onRelease?.({x:$,y:0}),!i.inertia)return;const M=i.inertia===!0?{}:i.inertia,v=M.friction??(M.resistance!==void 0?fr(M.resistance):4),T=typeof M.end=="number"||Array.isArray(M.end)?M.end:void 0;l=t.to(s,{inertia:{rotate:{velocity:$,friction:v,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",S),s.addEventListener("pointercancel",S),s.style.touchAction="none",{draggable:void 0,position:{x:0,y:0},get rotation(){return r()},destroy(){l?.kill(),s.removeEventListener("pointerdown",m),s.removeEventListener("pointermove",w),s.removeEventListener("pointerup",S),s.removeEventListener("pointercancel",S)}}}const I1={opacity:0,scale:.6};function O1(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 vh(t){const e=fi(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 br(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=O1(r);i.set(r,a);const l=Mh(r);a&&l!==void 0&&!o.has(l)&&o.set(l,{element:r,box:a})}return{elements:s,boxes:i,ids:o}}const wr=new WeakMap;function kr(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?I1: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),d=e({onComplete:s.onComplete});let u=0;for(const f of h){const p=vh(f);if(!p)continue;let g=n.boxes.get(f)??null,m;const w=Mh(f),S=!g&&w!==void 0?n.ids.get(w):void 0;S&&S.element!==f&&(g=S.box,m=S.element);const[k]=t.resolveTargets(f);wr.get(f)?.timeline.removeTracks({target:k});const y=u*r;if(!g){if(l===!1)continue;d.fromTo(f,{x:0,y:0,scaleX:1,scaleY:1,...l},{...Sh(l),x:0,y:0,scaleX:1,scaleY:1,duration:i,ease:o,delay:y},0),wr.set(f,d),u++;continue}const E=g.cx-p.cx,x=g.cy-p.cy,$=a?g.width/p.width:1,M=a?g.height/p.height:1;if(!(Math.abs(E)>.5||Math.abs(x)>.5||Math.abs($-1)>.001||Math.abs(M-1)>.001)){const I=(O,_)=>{const C=t.appliedValue(k,O);return typeof C=="number"&&Math.abs(C-_)>1e-6};(I("x",0)||I("y",0)||I("scaleX",1)||I("scaleY",1))&&d.set(f,{x:0,y:0,scaleX:1,scaleY:1},0);continue}const T=s.fade===!0&&m!==void 0;d.fromTo(f,{x:E,y:x,scaleX:$,scaleY:M,...T&&{opacity:0}},{x:0,y:0,scaleX:1,scaleY:1,...T&&{opacity:1},duration:i,ease:o,delay:y},0),T&&m&&vh(m)&&d.fromTo(m,{opacity:1},{opacity:0,duration:i,ease:o,delay:y},0),wr.set(f,d),u++}return d}function Mh(t){return t.dataset?.flipId}function Sh(t){const e={};for(const n of Object.keys(t))e[n]=n==="opacity"||n.startsWith("scale")?1:0;return e}function _1(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)},d=()=>{a&&(a.revert?a.revert():a.kill?.(),a=void 0)},u=()=>{const g={chars:[],words:[],lines:[],masks:[]};for(const{element:m}of o){const w=(m.textContent??"").replace(/\s+/g," ").trim(),S=C1(m,s.words),k=n.has("chars")?S.flatMap(x=>H1(x,s.chars)):[],y=n.has("lines")?L1(m,S,s.lines):[];if(i){!m.hasAttribute("aria-label")&&w&&m.setAttribute("aria-label",w);for(const x of S)x.setAttribute("aria-hidden","true")}if(n.has("words"))g.words.push(...S);else for(const x of S)x.removeAttribute("class");g.chars.push(...k),g.lines.push(...y);const E=e.mask==="lines"?y:e.mask==="words"?S:e.mask==="chars"?k:[];for(const x of E)g.masks.push(N1(x,`${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||(d(),h(),u(),a=e.onSplit?.(f))},revert(){c=!0,l?.disconnect(),d(),h()}};u(),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 E of k){const x=Math.round(E.contentRect.width),$=g.get(E.target);g.set(E.target,x),$!==void 0&&$!==x&&(y=!0)}y&&w()});for(const k of t)l.observe(k)}const S=t[0]?.ownerDocument?.fonts;S&&S.status!=="loaded"&&S.ready.then(()=>w())}return f}function C1(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 H1(t,e){const n=t.ownerDocument,s=R1(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 R1(t){const e=Intl.Segmenter;return e?Array.from(new e(void 0,{granularity:"grapheme"}).segment(t),n=>n.segment):Array.from(t)}function L1(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,d=!1,u=[];const f=()=>{l=s.createElement("span"),l.className=n,l.style.display="block",a.push(l),u=[]};for(const p of o){if(p.tagName==="BR"){d=!0;continue}const g=i.get(p);if(g&&(!l||d||g.top>c+h)&&(f(),c=g.top,h=g.height/2,d=!1),!l)continue;const m=[];for(let k=p.parentNode;k&&k!==t;k=k.parentNode)m.unshift(k);let w=0;for(;w<u.length&&w<m.length&&u[w].original===m[w];)w++;u.length=w;let S=w===0?l:u[w-1].clone;for(const k of m.slice(w)){const y=k.cloneNode(!1);S.appendChild(y),u.push({original:k,clone:y}),S=y}S.appendChild(p)}return t.replaceChildren(...a),a}function N1(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 Th={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 Th)return Th[e];if(e.endsWith("%")){const n=Number.parseFloat(e.slice(0,-1));return Number.isNaN(n)?void 0:n/100}}function Mr(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 vn(t,e,n){const s=Mr(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 D1(t,e,n,s){const i=vn(t,e,n),r=vn(t,e,s)-i;return r<=0?i<=0?1:0:Sr(-i/r)}function Sr(t){return t<0?0:t>1?1:t===0?0:t}function Eh(t,e,n,s){if(n<=0)return e;const i=1-Math.exp(-(s/1e3)/n);return t+(e-t)*i}function Tr(t,e,n,s,i){const o=h=>vn({top:t+i(h),bottom:t+i(h)+e,height:e},n,s),r=o(0),a=o(1);if(Math.sign(r)===Math.sign(a)||r===0||a===0)return r===0?0:a===0?1:Math.abs(r)<Math.abs(a)?0:1;let l=0,c=1;for(let h=0;h<40;h++){const d=(l+c)/2;Math.sign(o(d))===Math.sign(r)?l=d:c=d}return(l+c)/2}class Ah{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 F1(t){const e=new Ah(t);return e.start(),e}class xh{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 W1=.15;function $h(t){return typeof t=="object"&&!Array.isArray(t)?t:{snapTo:t}}function Ph(t,e,n){const s=gi(t+e*W1);if(typeof n=="function")return gi(n(s));if(typeof n=="number")return n<=0?t:gi(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 gi(i)}function Ih(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 Oh{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=Qn,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 gi(t){return Math.max(0,Math.min(1,t))}class _h{options;scroller;nodes=[];scrollerStart;scrollerEnd;start;end;constructor(e,n,s){this.options=s===!0?{}:s,this.scroller=n;const{startColor:i="#3ecf7a",endColor:o="#ff5a5a",id:r}=this.options,a=r?`${r} `:"",l=(c,h,d)=>{const u=e.createElement("div");return u.textContent=`${a}${c}`,u.setAttribute("aria-hidden","true"),u.className="scroll-marker",Object.assign(u.style,{position:d?"fixed":"absolute",right:`${this.options.indent??0}px`,zIndex:"2147483646",pointerEvents:"none",borderTop:`1px solid ${h}`,color:h,font:`${this.options.fontSize??"11px"} ui-monospace, monospace`,padding:"2px 6px",whiteSpace:"nowrap",background:"rgba(0, 0, 0, 0.35)"}),(n??e.body).appendChild(u),this.nodes.push(u),u};this.scrollerStart=l("scroller-start",i,!n),this.scrollerEnd=l("scroller-end",o,!n),this.start=l("start",i,!1),this.end=l("end",o,!1),n&&getComputedStyle(n).position==="static"&&(n.style.position="relative")}place(e,n){this.start.style.top=`${e.startPage}px`,this.end.style.top=`${e.endPage}px`;const s=this.scroller?n:0;this.scrollerStart.style.top=`${s+e.startViewport}px`,this.scrollerEnd.style.top=`${s+e.endViewport}px`}follow(e,n){this.scroller&&this.place(e,n)}destroy(){for(const e of this.nodes.splice(0))e.remove()}}const B1=120,Mn=[],Sn=new Set;let Er=!1;const q1=()=>{Er||Sn.size===0||(Er=!0,queueMicrotask(()=>{Er=!1;for(const t of Sn)t.afterRefresh()}))},Ch=()=>{for(const t of Sn)t.beforeRefresh();for(const t of Mn)t.refresh();for(const t of Sn)t.afterRefresh()};let Tn={width:0,height:0};const Hh=()=>{const t=window.innerWidth,e=window.innerHeight,n=t===Tn.width&&e!==Tn.height,s=Math.abs(e-Tn.height)<Tn.height*.25,i=typeof navigator<"u"&&(navigator.maxTouchPoints??0)>0;n&&s&&i||(Tn={width:t,height:e},Ch())};class cs{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 Oh(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 xh(e,{axis:this.options.horizontal?"x":"y",spacing:this.options.pinSpacing!==!1})),this.options.markers&&!this.options.horizontal&&typeof document<"u"&&(this.markers=new _h(document,this.options.scroller??null,this.options.markers)),this.scrollTarget()?.addEventListener("scroll",this.onScroll,{passive:!0}),Mn.length===0&&typeof window<"u"&&(Tn={width:window.innerWidth,height:window.innerHeight},window.addEventListener("resize",Hh,{passive:!0})),Mn.push(this),this.refresh()}stop(){this.running&&(this.running=!1,this.scrollTarget()?.removeEventListener("scroll",this.onScroll),Mn.splice(Mn.indexOf(this),1),Mn.length===0&&typeof window<"u"&&window.removeEventListener("resize",Hh),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(){Ch()}static onRefresh(e){return Sn.add(e),()=>Sn.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+vn(n,s,hs(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,q1()}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?Sr((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=hs(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+vn(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()},B1))}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=$h(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+Ph(r,this.releaseVelocity/i,n.snapTo)*i;Math.abs(a-o)<1||this.snapper.animate(o,a,Ih(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=Tr(r,s.width,o,hs(this.options.start)??"left right",e.shiftAt);this.startPx=c(h);const d=hs(this.options.end)??"right left",u=typeof d=="string"?d.trim().match(/^\+=\s*(-?[\d.]+)\s*(px)?$/):null;this.endPx=u?this.startPx+Number.parseFloat(u[1]):c(Tr(r,s.width,o,d,e.shiftAt)),this.markerGeometry=null}markersFor(e){const n=(o,r)=>{const a=hs(o)??r;if(typeof a=="number")return 0;if(/^\s*\+=/.test(a))return;const l=Mr(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=Eh(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 hs(t){return typeof t=="function"?t():t}function z1(t){const e=new cs(t);return e.start(),e}const Ar=new Set,Y1=16,Rh=.5,K1=2;class xr{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),Ar.add(this),this.stopListening=cs.onRefresh({beforeRefresh:()=>this.rest(),afterRefresh:()=>this.refresh()}),this.refresh(),this}static refreshAll(){for(const e of Ar)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),Ar.delete(this),this.stopListening?.(),this.stopListening=null,this.cancelFrame(),this.journey=null,this}destroy(){this.stop();for(const e of this.effects)$r(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??Qn,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)$r(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?Y1: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)<=K1||(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)<Rh&&(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)<Rh?i.lagged=s:n=!0,o+=s-i.lagged}$r(i.element,o===0?i.saved:`0 ${j1(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 $r(t,e){e?t.style.setProperty("translate",e):t.style.removeProperty("translate")}function j1(t){return Math.round(t*100)/100}function X1(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 Pr(t,e,n,s,i=()=>{}){const o=f=>typeof f=="string"?t.query(f)??void 0:f,r=o(e.trigger)??s;if(!r){i(`gsap-compat: scrollTrigger has no trigger element${typeof e.trigger=="string"?` for "${e.trigger}"`:""}`);return}const a=e.scrub===void 0||e.scrub===!1?!1:e.scrub,l=(e.toggleActions??"play none none none").trim().split(/\s+/);let c=0,h;const d=(f,p)=>()=>{p?.(),n&&!a&&X1(n,l[f]??"none"),e.once&&f===0&&queueMicrotask(()=>h.destroy())},u=e.containerAnimation?V1(t,e.containerAnimation,r,i):void 0;return h=new cs({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:G1(e.snap,n),markers:e.markers,container:u,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:d(0,e.onEnter),onLeave:d(1,e.onLeave),onEnterBack:d(2,e.onEnterBack),onLeaveBack:d(3,e.onLeaveBack)}),n&&a===!1&&n.progress(0),h.start(),t.own(h)}function G1(t,e){const n=i=>i==="labels"?o=>U1(o,e?.labelProgresses?.()??[]):i;if(typeof t!="object"||Array.isArray(t))return n(t);const s=t.ease?rs(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 U1(t,e){return e.reduce((n,s)=>Math.abs(s-t)<Math.abs(n-t)?s:n,e[0]??t)}function V1(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 Lh{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 J1{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 Lh(this.host,this.scope);o.conditions=n,o.add(()=>e.setup(o)),e.context=o}}class Z1{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 Q1={opacity:0,y:-16},ty={opacity:0,y:16};async function ey(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 ny(o,s,r);const a=s.duration??.35,l=s.ease??"power2.inOut",c=m=>new Promise(w=>{m(w)||w()}),h=r(),d=h.length?br(e,h):void 0,u=s.from!==void 0?Nh(e,s.from,s.shared):[];if(u.length&&s.leave!==!1){const m=s.leave??Q1;await c(w=>t.to(u,{...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?Nh(e,p,s.shared):[];if(g.length&&s.enter!==!1){const m=s.enter??ty;f.push(c(w=>t.fromTo(g,m,{...Sh(m),duration:a,ease:l,onComplete:w})))}if(d){const m=r().filter(w=>!h.includes(w));m.length&&f.push(c(w=>kr(e,n,d,{targets:m,duration:a*1.4,ease:l,enter:!1,onComplete:w})))}await Promise.all(f)}function Nh(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 ny(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 Dh={create:(t,e)=>cr(t,zc(e))},Fh={create:(t,e)=>cr(t,{fn:Yc(e)})},Wh={create:(t,e)=>cr(t,{fn:Kc(e)})},sy=new Set(["keyframes","duration","delay","ease","easeEach","stagger","repeat","repeatDelay","yoyo","repeatRefresh","paused","id","onStart","onUpdate","onComplete","onRepeat","onReverseComplete","scrollTrigger"]),Bh=.5,iy="power1.inOut";function oy(t){return t.keyframes!==void 0&&t.keyframes!==null}function ry(t){const e=t.keyframes,n={};for(const[c,h]of Object.entries(t))sy.has(c)||(n[c]=h);if(Array.isArray(e))return e.map(c=>({...n,...c,duration:c.duration??t.duration??Bh}));const s=Object.entries(e),i=t.duration??Bh,o=e.easeEach??t.easeEach??iy;if(s.length>0&&s.every(([c])=>/^\s*-?\d+(\.\d+)?\s*%\s*$/.test(c)||c==="easeEach")){const c=s.filter(([u])=>u!=="easeEach").map(([u,f])=>({at:Number.parseFloat(u)/100,step:f})).sort((u,f)=>u.at-f.at),h=[];let d=0;for(const{at:u,step:f}of c){const p=Math.max(0,u-d);h.push({...n,ease:o,...f,duration:p*i}),d=u}return h}const r=s.filter(([c,h])=>c!=="easeEach"&&Array.isArray(h)),a=Math.max(0,...r.map(([,c])=>c.length)),l=[];for(let c=0;c<a;c++){const h={...n,ease:o,duration:i/a};for(const[d,u]of r)c<u.length&&(h[d]=u[c]);l.push(h)}return l}function qh(t,e,n,s={}){const i=e.collector?.scope??e.root,o=typeof s.scroller=="string"?i.querySelector(s.scroller):s.scroller??null,r={x:o?o.scrollLeft:window.scrollX,y:o?o.scrollTop:window.scrollY},a={x:o?o.scrollWidth-o.clientWidth:document.documentElement.scrollWidth-window.innerWidth,y:o?o.scrollHeight-o.clientHeight:document.documentElement.scrollHeight-window.innerHeight},l=(S,k)=>{if(k===void 0)return r[S];if(typeof k=="number")return k;if(k==="max")return a[S];const y=typeof k=="string"?i.querySelector(k):k;if(!y)return r[S];const E=y.getBoundingClientRect(),x=o?.getBoundingClientRect(),$=(S==="x"?s.offsetX:s.offsetY)??s.offset??0;return S==="x"?E.left-(x?.left??0)+r.x-$:E.top-(x?.top??0)+r.y-$},c=typeof n=="object"&&n!==null&&!("nodeType"in n)?{x:l("x",n.x),y:l("y",n.y)}:{x:r.x,y:l("y",n)},h={x:Math.max(0,Math.min(a.x,c.x)),y:Math.max(0,Math.min(a.y,c.y))},d={...r},u=()=>{o?(o.scrollLeft=d.x,o.scrollTop=d.y):window.scrollTo({left:d.x,top:d.y,behavior:"instant"})},f=["wheel","touchstart","keydown"],p=o??window,g=()=>{w.kill(),m()},m=()=>{for(const S of f)p.removeEventListener(S,g)},w=t.to(d,{x:h.x,y:h.y,duration:s.duration??1,ease:s.ease??"power2.inOut",onStart:s.onStart,onUpdate:()=>{u(),s.onUpdate?.()},onComplete:()=>{m(),s.onComplete?.()}});if(s.autoKill!==!1)for(const S of f)p.addEventListener(S,g,{passive:!0});return w}function ay(t,e,n){const s=t.collector?.scope??t.root,i=typeof e=="string"?[...s.querySelectorAll(e)]:"nodeType"in e?[e]:Array.from(e),{interval:o=.1,batchMax:r,onEnter:a,onLeave:l,onEnterBack:c,onLeaveBack:h,...d}=n,u={onEnter:a,onLeave:l,onEnterBack:c,onLeaveBack:h},f={onEnter:[],onLeave:[],onEnterBack:[],onLeaveBack:[]},p={},g=w=>{p[w]!==void 0&&clearTimeout(p[w]),p[w]=void 0;const S=f[w].splice(0);S.length>0&&u[w]?.(S)},m=(w,S)=>{if(u[w]){if(f[w].push(S),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=>Pr(t,{...d,trigger:w,onEnter:()=>m("onEnter",w),onLeave:()=>m("onLeave",w),onEnterBack:()=>m("onEnterBack",w),onLeaveBack:()=>m("onLeaveBack",w)})).filter(w=>w!==void 0)}class de{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 Ve({...s,startValue:(i,o)=>{const r=e.objectFor(i);if(r)return hy(r[o]);const a=e.appliedValue(i,o);if(a!==void 0)return a;if(o==="d")return fh(e.elementFor(i))??void 0;if(o==="text")return e.elementFor(i)?.textContent??void 0;if(o==="strokeDasharray"||o==="strokeDashoffset"){const l=Xh(e.elementFor(i));if(l!==void 0)return o==="strokeDasharray"?[l,l]:0}},startVelocity:(i,o)=>e.velocityOf(i,o),layoutColumns:i=>jh(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=Pr(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 oy(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 de(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}=er(i.map(a=>a.time),e,n,{duration:this.timeline.duration,alternate:this.options.yoyo===!0,holding:s});for(const a of o){if(this.killed)return!0;if(a.kind==="repeat"){this.options.repeatRefresh&&this.refreshForRepeat(),this.options.onRepeat?.();continue}const l=i[a.index];if(!(l.direction&&l.direction!==a.direction)){if(l.pause)return this.timeline.seek(l.time),this.stage.render(this.timeline),this.pause(),this.playhead=this.readPlayhead(),this.waitingToWrap=!1,l.run(),!0;l.run()}}for(const a of this.ranges)r.some(([c,h])=>c!==h&&Math.max(c,h)>=a.start&&Math.min(c,h)<=a.end)&&a.run();return!1}tween(e,n,s,i){const o=this.resolve(e);if(!o)return;const{onStart:r,onUpdate:a,onComplete:l}=n[n.length-1];if(r||a||l){let c=1/0,h=-1/0;const d=(u,f,p)=>{i(u,f,p),c=Math.min(c,this.compat.lastStart),h=Math.max(h,this.compat.lastEnd)};if(this.buildTween(o,n,s,d),c===1/0)return;r&&this.events.push({time:c,direction:"forward",run:r}),a&&this.ranges.push({start:c,end:h,run:a}),l&&this.events.push({time:h,direction:"forward",run:l});return}this.buildTween(o,n,s,i)}keyframed(e,n,s){const i=this.resolve(e);if(!i)return;const o=ry(n);if(o.length===0)return;const r=i.length>1?ur(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?Xs(i.length,r).map(m=>m/1e3):[0],h=this.compat.timeOf(s)/1e3+ui(n.delay,0)/1e3;let d=1/0,u=-1/0;if(l.forEach((m,w)=>{o.forEach((S,k)=>{const y=k===0?h+c[w]:">";this.tween(m,[S],y,([E],x,$)=>this.compat.to(x,E,$)),d=Math.min(d,this.compat.lastStart),u=Math.max(u,this.compat.lastEnd)})}),d===1/0)return;const{onStart:f,onUpdate:p,onComplete:g}=n;f&&this.events.push({time:d,direction:"forward",run:f}),p&&this.ranges.push({start:d,end:u,run:p}),g&&this.events.push({time:u,direction:"forward",run:g})}staggerContext(e){return{count:e.length,columnsFromLayout:()=>jh(e.map(n=>this.stage.elementFor(n))),random:()=>this.stage.utils.random(0,1)}}buildTween(e,n,s,i){const o=e.map(u=>this.targetFor(u));if(!(e.length>1&&(n.some(cy)||e.some(u=>this.stage.objectFor(u)!==void 0)))){const u=this.targetFor(e[0]);i(n.map(f=>this.prepare(Kh(f,0,u,this.stage.utils,o),e)),e,s);return}const a=n.length-1,{stagger:l,...c}=n[a],h=ur(l,this.staggerContext(e)),d=h?Xs(e.length,h).map(u=>u/1e3):e.map(()=>0);e.forEach((u,f)=>{const p=f===0?ui(c.delay,0)/1e3+d[0]:0,g=f===0?0:d[f]-d[f-1],m=f===0?s:`<${g<0?"-":"+"}${Math.abs(g).toFixed(6)}`,S=n.map((k,y)=>y===a?{...c,delay:p}:k).map(k=>this.prepare(Kh(k,f,this.targetFor(u),this.stage.utils,o),[u]));i(S,[u],m)})}targetFor(e){return this.stage.elementFor(e)??this.stage.objectFor(e)}prepare(e,n){const s=r=>this.options.onWarning?.(r),i=r=>this.stage.query(r);let o=e;if(e.motionPath!==void 0){const r=v1(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=M1(e.morphSVG,i,s),{morphSVG:a,...l}=o;o=r?{...o,morphSVG:r}:l}if(e.drawSVG!==void 0){const r=Xh(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=Gm(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 ${dy(e)}`);return}return this.firstElement??=n.map(s=>this.stage.elementFor(s)).find(s=>s!==void 0),n}}function zh(t=new ch){const e=o=>{const{config:r}=di(o);return new de(t,{repeat:r.repeat,yoyo:r.yoyo,repeatDelay:r.repeatDelay,paused:r.paused,onStart:r.onStart,onUpdate:r.onUpdate,onComplete:r.onComplete,onRepeat:r.onRepeat,onReverseComplete:r.onReverseComplete,repeatRefresh:r.repeatRefresh,scrollTrigger:r.scrollTrigger})},n=o=>{const{onStart:r,onUpdate:a,onComplete:l,onRepeat:c,onReverseComplete:h,repeatRefresh:d,...u}=o;return u},s=o=>(o&&t.collector?.track(o),o),i={stage:t,ticker:t.ticker,utils:t.utils,getProperty:(o,r)=>{const[a]=t.resolveTargets(o);if(a===void 0)return;const l=t.objectFor(a);return l?l[r]:t.appliedValue(a,r)??ih(r)},scrollTrigger:o=>s(Pr(t,o)),scrollBatch:(o,r)=>ay(t,o,r).map(a=>s(a)),scrollTo:(o,r)=>qh(i,t,o,r),refreshScroll:()=>{cs.refreshAll(),xr.refreshAll()},smoothScroll:(o={})=>{const r=typeof o.scroller=="string"?(t.collector?.scope??t.root).querySelector(o.scroller):o.scroller;return s(new xr({...o,scroller:r}).start())},context:(o,r)=>{const a=new Lh(t,r);return o&&a.add(()=>o(a)),a},matchMedia:o=>new J1(t,o),customEase:Dh.create,customBounce:Fh.create,customWiggle:Wh.create,pageTransition:o=>ey(i,t,r=>new de(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 Z1(a,r))},quickTo:(o,r,a={})=>{const l=new de(t,{paused:!0}),[c]=t.resolveTargets(o);return Object.assign(d=>{if(!c)return;const u=a.spring!==void 0?t.velocityOf(c,r)??0:0;l.compat.reset(),l.compat.to(c,{[r]:d,duration:a.duration??.4,ease:a.ease??"power3.out",...a.spring!==void 0&&{spring:ly(a.spring,r,u)}}),l.timeline.stop(),l.timeline.play(),t.activate(l.timeline)},{tween:l,kill:()=>l.kill()})},timeline:o=>new de(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 qh(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 de(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=>T1(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(_1(l,r))},draggable:(o,r)=>s($1(i,t,o,r)),getFlipState:o=>br(t,o),flipFrom:(o,r)=>kr(t,a=>new de(t,a),o,r),flip:(o,r,a)=>{const l=br(t,o);return r(),kr(t,c=>new de(t,c),l,{targets:o,...a})}};return i}const qt=zh();function ly(t,e,n){return t===!0?{velocity:{[e]:n}}:typeof t=="string"?{preset:t,velocity:{[e]:n}}:{...t,velocity:{[e]:n}}}function cy(t){return t.morphSVG!==void 0||t.drawSVG!==void 0||t.text!==void 0||t.scrambleText!==void 0||Yh(t)}function Yh(t){return Object.entries(t).some(([e,n])=>(typeof n=="function"||nh(n))&&!dr.has(e))}function Kh(t,e,n,s,i){if(!Yh(t))return t;const o={};for(const[r,a]of Object.entries(t))dr.has(r)?o[r]=a:typeof a=="function"?o[r]=a(e,n,i):nh(a)?o[r]=s.resolveRandomString(a):o[r]=a;return o}function jh(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 Xh(t){const e=t;if(typeof e?.getTotalLength=="function")return e.getTotalLength()}function hy(t){if(typeof t=="number"||typeof t=="string"||Array.isArray(t)&&t.every(e=>typeof e=="number"))return t}function dy(t){return typeof t=="string"?`"${t}"`:String(t)}class Ir{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 Gh(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 pi{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 Je}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=yn({...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 Ir(s)})})}syncAllMedia(e,n){for(const s of this.mediaTargets)Gh(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 Je;s.querySelectorAll("[data-tinyfly]").forEach(a=>{const l=a.getAttribute("data-tinyfly");l&&r.registerTarget(l,a)}),this.symbolInstances.push({adapter:r,timeline:yn(o.timeline)})})}attachMedia(e,n){this.mediaSync=new Ir(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}=er(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 uy(t,e,n={}){const s=new pi(t,{...n,autoplay:!0});return await s.load(e),s}function fy(t,e={}){return new pi(t,e)}const Uh={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"},Vh="tinyfly-controls-style",gy=`
1
+ (function(y,un){typeof exports=="object"&&typeof module<"u"?un(exports):typeof define=="function"&&define.amd?define(["exports"],un):(y=typeof globalThis<"u"?globalThis:y||self,un(y.tinyfly=y.tinyfly||{}))})(this,(function(y){"use strict";function un(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function Zn(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const Do=2;function Wo(t){return t.some(e=>e.interpolation!==void 0)?2:1}function Js(t){return t.property==="text"&&"textConfig"in t}function Me(t){return t.kind==="inertia"&&"inertia"in t}function Se(t){return t.kind==="spring"&&"spring"in t}function Bo(t){return t.property==="motionPath"&&"motionPathConfig"in t}function Op(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"angle"in t}function nc(t){return"keyframes"in t}class _p{_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 Cp{_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 sc(t,e){if(!(e>0))return t;const n=1e3/e;return Math.floor(t/n+1e-9)*n}function zo(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 qo(t,e="start"){if(t<=1)return 0;let n=0;for(let s=0;s<t;s++)n=Math.max(n,zo(s,t,e));return n}function Zs(t,e,n){if(n.offsets)return n.offsets[t]??0;const s=n.from??"start",i=zo(t,e,s);if(n.amount!==void 0){const o=qo(e,s);return o===0?0:n.amount*i/o}return n.each!==void 0?n.each*i:0}function Qs(t,e){return Array.from({length:t},(n,s)=>Zs(s,t,e))}function Qn(t,e){return t<=1?0:Math.max(...Qs(t,e))}const dn=1,Yo=6e4,ti=Yo/dn,Vt={stiffness:180,damping:12,mass:1,velocity:0,restDelta:.01,restSpeed:.1},ei={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 ts{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??Vt.stiffness,this.damping=e.damping??Vt.damping,this.mass=e.mass??Vt.mass,this.restDelta=e.restDelta??Vt.restDelta,this.restSpeed=e.restSpeed??Vt.restSpeed,this.distance=Math.abs(this.to-this.from)||1,this.samples=[this.from],this.velocity=e.velocity??Vt.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/dn);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/dn-n;return s+(i-s)*o}settleTime(){return this.simulateTo(ti+1),this.settledStep!==null?this.settledStep*dn:Yo}simulateTo(e){if(this.settledStep!==null)return;const n=Math.min(e,ti+1),s=dn/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>ti&&(this.settledStep=ti)}}function Hp(t,e){return new ts(t).valueAt(e)}function ic(t){return new ts(t).settleTime()}function Rp(t){const e=t.stiffness??Vt.stiffness,n=t.damping??Vt.damping,s=t.mass??Vt.mass;return n<2*Math.sqrt(e*s)}function Lp(t){const e=t.stiffness??Vt.stiffness,n=t.mass??Vt.mass;return 2*Math.sqrt(e*n)}const jo=4,Np=.002,Fp=1e-4,oc=6e4;function ni(t){const e=t.friction??jo;return e>0?e:jo}function es(t){return t.from+t.velocity/ni(t)}function Dp(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 fn(t){let e=Dp(es(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 gn(t){const e=Math.abs(fn(t)-t.from);if(e===0)return 0;const n=t.restDelta??Math.max(Fp,e*Np);if(n>=e)return 0;const s=Math.log(e/n)/ni(t);return Math.min(oc,s*1e3)}function si(t,e){if(e<=0)return t.from;const n=fn(t);if(e>=gn(t))return n;const s=ni(t);return t.from+(n-t.from)*(1-Math.exp(-s*e/1e3))}function Wp(t,e){const n=ni(t),s=fn(t);return e>=gn(t)?0:(s-t.from)*n*Math.exp(-n*Math.max(0,e)/1e3)}const ii=t=>t,rc=t=>t*t,ac=t=>1-(1-t)*(1-t),lc=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,Ko=t=>t*t*t,Xo=t=>1-Math.pow(1-t,3),ns=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,cc=Ko,hc=Xo,uc=ns,Bp={linear:ii,"ease-in":cc,"ease-out":hc,"ease-in-out":uc,"ease-in-quad":rc,"ease-out-quad":ac,"ease-in-out-quad":lc,"ease-in-cubic":Ko,"ease-out-cubic":Xo,"ease-in-out-cubic":ns};function dc(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 M=f(m);if(Math.abs(M)<1e-7)break;m-=b/M}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 Go(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 fc(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 gc=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 pc(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 mc(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 yc(t){switch(t.type){case"steps":return mc(t.count,t.position);case"elastic":return Go(fc(t.amplitude,t.period),t.mode);case"bounce":return Go(gc,t.mode);case"back":return Go(pc(t.overshoot),t.mode)}}function Ht(t){return t===void 0?ii:un(t)?dc(t.points):Zn(t)?yc(t):Bp[t]??ii}const bc=32,zp=256,pn=new Map,qp=/[MmLlHhVvCcSsQqTtAaZz]/,Yp=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,jp={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function Kp(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(qp.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=Yp.exec(t.slice(n));if(!l)break;s.args.push(parseFloat(l[0])),n+=l[0].length}return e}function Xp(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 P=Math.sqrt(v);c*=P,h*=P}const k=o===r?-1:1,b=c*c*h*h-c*c*w*w-h*h*m*m,M=c*c*w*w+h*h*m*m,E=k*Math.sqrt(Math.max(0,b/M)),A=E*c*w/h,T=-E*h*m/c,S=d*A-f*T+(t+a)/2,x=f*A+d*T+(e+l)/2,O=(P,R,N,$)=>{const L=P*N+R*$,W=Math.sqrt((P*P+R*R)*(N*N+$*$)),q=Math.acos(Math.max(-1,Math.min(1,L/W)));return P*$-R*N<0?-q:q},I=O(1,0,(m-A)/c,(w-T)/h);let _=O((m-A)/c,(w-T)/h,(-m-A)/c,(-w-T)/h);!r&&_>0&&(_-=2*Math.PI),r&&_<0&&(_+=2*Math.PI);const C=Math.max(1,Math.ceil(Math.abs(_)/(Math.PI/2))),F=_/C,z=4/3*Math.tan(F/4),X=P=>{const R=c*Math.cos(P),N=h*Math.sin(P);return[d*R-f*N+S,f*R+d*N+x]},J=P=>{const R=-c*Math.sin(P),N=h*Math.cos(P);return[d*R-f*N,f*R+d*N]},K=[];for(let P=0;P<C;P++){const R=I+P*F,N=R+F,[$,L]=X(R),[W,q]=P===C-1?[a,l]:X(N),[B,Y]=J(R),[U,D]=J(N);K.push([$+z*B,L+z*Y,W-z*U,q-z*D,W,q])}return K}function Te(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 wc(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 ss(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 oi(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<=bc;f++){const p=f/bc,g=Te(t,s,o,a,p),m=Te(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 Ke(t){const e=pn.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 Kp(t)){const w=g.toUpperCase(),v=g!==w,k=jp[w];if(w==="Z"){(s!==o||i!==r)&&u(ss(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 M=m.slice(b,b+k),E=v?s:0,A=v?i:0;let T=null,S=null;switch(w){case"M":b===0?(s=M[0]+E,i=M[1]+A,o=s,r=i,(c<0||n[n.length-1]?.subpath===c)&&c++):(u(ss(s,i,M[0]+E,M[1]+A)),s=M[0]+E,i=M[1]+A);break;case"L":u(ss(s,i,M[0]+E,M[1]+A)),s=M[0]+E,i=M[1]+A;break;case"H":u(ss(s,i,M[0]+E,i)),s=M[0]+E;break;case"V":u(ss(s,i,s,M[0]+A)),i=M[0]+A;break;case"C":{const x=[M[0]+E,M[1]+A,M[2]+E,M[3]+A,M[4]+E,M[5]+A];u(oi(s,i,x)),T=[x[2],x[3]],s=x[4],i=x[5];break}case"S":{const[x,O]=a?[2*s-a[0],2*i-a[1]]:[s,i],I=[x,O,M[0]+E,M[1]+A,M[2]+E,M[3]+A];u(oi(s,i,I)),T=[I[2],I[3]],s=I[4],i=I[5];break}case"Q":case"T":{let x=s,O=i;w==="Q"?(x=M[0]+E,O=M[1]+A):l&&(x=2*s-l[0],O=2*i-l[1]);const I=w==="Q"?M[2]+E:M[0]+E,_=w==="Q"?M[3]+A:M[1]+A;u(oi(s,i,[s+2/3*(x-s),i+2/3*(O-i),I+2/3*(x-I),_+2/3*(O-_),I,_])),S=[x,O],s=I,i=_;break}case"A":{const x=M[5]+E,O=M[6]+A;let I=s,_=i;for(const C of Xp(s,i,M[0],M[1],M[2],M[3],M[4],x,O))u(oi(I,_,C)),I=C[4],_=C[5];s=x,i=O;break}}a=T,l=S}}const d=n.reduce((g,m)=>g+m.length,0),f=[];for(let g=0;g<n.length;){const m=n[g].subpath;let w=g,v=0;for(;w<n.length&&n[w].subpath===m;)v+=n[w++].length;const k=n[g],b=n[w-1],M=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:M}),g=w}const p={segments:n,totalLength:d,subpaths:f};return pn.size>=zp&&pn.delete(pn.keys().next().value),pn.set(t,p),p}function Gp(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 Up(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=Gp(t,e);let c=wc(t.startX,n,i,r,l),h=wc(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=Te(t.startX,n,i,r,u),f=Te(t.startY,s,o,a,u),p=Te(t.startX,n,i,r,l),g=Te(t.startY,s,o,a,l);c=l<.5?d-p:p-d,h=l<.5?f-g:g-f}return{x:Te(t.startX,n,i,r,l),y:Te(t.startY,s,o,a,l),angle:Math.atan2(h,c)*180/Math.PI}}function Uo(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 Up(r,e-i);i+=r.length}return{x:0,y:0,angle:0}}function kc(t,e){const{segments:n,totalLength:s}=Ke(t);return Uo(n,Math.max(0,Math.min(1,e))*s)}function Vp(){pn.clear()}function Jp(t){return Ke(t).totalLength}const Zp=24,Qp=320,tm=2.5,is=72,em=64,nm=.2,sm=128,os=new Map;let ri=0,xe;const vc=t=>Math.round(t*100)/100;function Mc(t,e){const{segments:n,subpaths:s,totalLength:i}=Ke(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 Vo(t,e){const n=t.closed?(e%1+1)%1:Math.max(0,Math.min(1,e)),s=Uo(t.segments,n*t.length,t.start,t.end);return[s.x,s.y]}function Sc(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 Tc(t,e){const n=[];for(let s=0;s<e;s++)n.push(Vo(t,t.closed?s/e:s/(e-1)));return n}function xc(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 im(t,e,n){const s=t.closed&&e.closed;if(n!==void 0)return{offset:s?Math.abs(n)%is/is:0,reversed:n<0};const i=xc(Tc(t,is)),o=xc(Tc(e,is)),r=is;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 om(t,e,n){return n?((e.reversed?e.offset-t:t+e.offset)%1+1)%1:e.reversed?1-t:t}function rm(t,e,n){return n?((e.reversed?e.offset-t:t-e.offset)%1+1)%1:e.reversed?1-t:t}function am(t,e,n){const s=t.closed&&e.closed,i=im(t,e,n.shapeIndex),o=Math.max(Zp,Math.min(Qp,Math.ceil(Math.max(t.length,e.length)/tm))),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 Sc(t))a(u);for(const u of Sc(e))a(rm(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(...Vo(t,u)),h.push(...Vo(e,om(u,i,s)));return lm({from:c,to:h,closed:s})}function lm(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=nm;for(let h=r+1;h<a;h++){const u=Math.max(Ec(t.from,r,a,h),Ec(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 Ec(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 cm(t,e,n){const s=n.shapeIndex;if(xe&&xe.from===t&&xe.to===e&&xe.shapeIndex===s)return xe.plan;const o=os.get(String(s??"auto"))?.get(t)?.get(e);if(o)return xe={from:t,to:e,shapeIndex:s,plan:o},o;const r=Ke(t).subpaths.filter(f=>f.length>0).length===Ke(e).subpaths.filter(f=>f.length>0).length,a=Mc(t,!r),l=Mc(e,!r),c={pairs:a.map((f,p)=>am(f,l[p],n))};ri>=sm&&(os.clear(),ri=0);const h=String(s??"auto"),u=os.get(h)??new Map;os.set(h,u);const d=u.get(t)??new Map;return u.set(t,d),d.set(e,c),ri++,xe={from:t,to:e,shapeIndex:s,plan:c},c}function Ac(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=cm(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=vc(a.from[l]+(a.to[l]-a.from[l])*i),h=vc(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 hm(){os.clear(),ri=0,xe=void 0}function mn(t){return/^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(t)}const yn=Math.PI/180,um=.9995;function Jo(){return[0,0,0,1]}function Jt(t,e){const n=Math.hypot(t[0],t[1],t[2]);if(n===0)return Jo();const s=e*yn/2,i=Math.sin(s)/n;return[t[0]*i,t[1]*i,t[2]*i,Math.cos(s)]}function dm(t,e,n){return Zo(Zo(Jt([0,1,0],e),Jt([1,0,0],t)),Jt([0,0,1],n))}function fm(t){const[e,n,s,i]=Ee(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/yn,Math.atan2(o,u)/yn,Math.atan2(r,a)/yn]:[d/yn,Math.atan2(-h,c)/yn,0]}function Zo(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 Pc(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function $c(t){return Math.hypot(t[0],t[1],t[2],t[3])}function Ee(t){const e=$c(t);return e===0?Jo():[t[0]/e,t[1]/e,t[2]/e,t[3]/e]}function gm(t){return[-t[0],-t[1],-t[2],t[3]]}function Ic(t,e,n){const s=Ee(t);let i=Ee(e),o=Pc(s,i);if(o<0&&(i=[-i[0],-i[1],-i[2],-i[3]],o=-o),o>um)return Ee([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 Ee([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 pm(t,e){const[n,s,i,o]=Ee(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 mm=Object.freeze(Object.defineProperty({__proto__:null,conjugate:gm,dot:Pc,fromAxisAngle:Jt,fromEuler:dm,identity:Jo,length:$c,multiply:Zo,normalize:Ee,rotateVec3:pm,slerp:Ic,toEuler:fm},Symbol.toStringTag,{value:"Module"})),le=(t,e,n)=>t+(e-t)*n,Oc=512,Qo=new Map,tr=new Map;function _c(t){const e=Qo.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 Qo.size<Oc&&Qo.set(t,s),s}const Cc=t=>t.charCodeAt(0)===35,Hc=t=>t.startsWith("rgb"),Rc=t=>t.startsWith("rgba"),ym=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/,er=t=>Math.round(t).toString(16).padStart(2,"0");function bm(t,e,n){return`#${er(t)}${er(e)}${er(n)}`}function Lc(t){const e=tr.get(t);if(e)return e;const n=t.match(ym);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 tr.size<Oc&&tr.set(t,r),r}const Nc=(t,e,n)=>{if(Cc(t)&&Cc(e)){const[s,i,o]=_c(t),[r,a,l]=_c(e),c=le(s,r,n),h=le(i,a,n),u=le(o,l,n);return bm(c,h,u)}if((Hc(t)||Rc(t))&&(Hc(e)||Rc(e))){const s=Lc(t),i=Lc(e),o=Math.round(le(s[0],i[0],n)),r=Math.round(le(s[1],i[1],n)),a=Math.round(le(s[2],i[2],n));if(s.length===4||i.length===4){const l=s[3]??1,c=i[3]??1,h=le(l,c,n);return`rgba(${o}, ${r}, ${a}, ${h})`}return`rgb(${o}, ${r}, ${a})`}return n<1?t:e},Fc=(t,e,n)=>{const s=Math.min(t.length,e.length),i=[];for(let o=0;o<s;o++)i.push(le(t[o],e[o],n));return i},Dc=(t,e,n)=>Ic(t,e,n),nr=(t,e,n)=>n<1?t:e,Wc=(t,e,n)=>Ac(t,e,n);function rs(t,e){return e==="slerp"?Dc:typeof t=="number"?le:Array.isArray(t)?Fc:typeof t=="string"?t.startsWith("#")||t.startsWith("rgb")?Nc:mn(t)?Wc:nr:nr}const sr=1e3/60;function ir(t,e={}){if(!Se(t))throw new Error(`bakeSpringTrack: track "${t.id}" is not a spring track`);const n=new ts(t.spring);return Bc(t,s=>n.valueAt(s),n.settleTime(),t.spring.from,t.spring.to,e)}function or(t,e={}){if(!Me(t))throw new Error(`bakeInertiaTrack: track "${t.id}" is not an inertia track`);const n=t.inertia;return Bc(t,s=>si(n,s),gn(n),n.from,fn(n),e)}function Bc(t,e,n,s,i,o){const r=o.intervalMs??sr,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?qc(c,a):c,...t.targets&&{targets:[...t.targets]},...t.stagger&&{stagger:{...t.stagger}}}}function rr(t,e,n,s={}){const i=s.intervalMs??sr,o=typeof n=="function"?n:Ht(n),r=rs(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 wm(t,e){return Se(t)?ir(t,e):Me(t)?or(t,e):t}function zc(t,e={}){const n=t.keyframes;if(!n.some(o=>Zn(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];Zn(r.easing)?s.push(...rr(n[o-1],r,r.easing,i)):s.push(r)}return{...t,keyframes:s}}function km(t,e){return t.filter(nc).map(n=>zc(n,e)).concat(t.filter(Se).map(n=>ir(n,e)),t.filter(Me).map(n=>or(n,e)))}function qc(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 Ae(t){return t.targets&&t.targets.length>0?t.targets:[t.target]}function bn(t,e,n,s){const i=n??0;return!s||e<=1?i:i+Zs(t,e,s)}class as{track;targets;constructor(e){this.track=e,this.targets=Ae(e)}getValueAtTime(e){return this.valueForOffset(e-bn(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=bn(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?Qn(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=Ht(i.easing)(r);return rs(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 Yc{track;targets;sampler;constructor(e){this.track=e,this.targets=Ae(e),this.sampler=new ts(e.spring)}getValueAtTime(e){return this.sampler.valueAt(e-bn(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=bn(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?Qn(this.targets.length,this.track.stagger):0;return this.sampler.settleTime()+(this.track.delay??0)+e}getTrack(){return this.track}}class jc{track;targets;duration;constructor(e){this.track=e,this.targets=Ae(e),this.duration=gn(e.inertia)}getValueAtTime(e){return si(this.track.inertia,e-bn(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=bn(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?Qn(this.targets.length,this.track.stagger):0;return this.duration+(this.track.delay??0)+e}getTrack(){return this.track}}function ar(t,e){const n={...kc(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 vm(t,e,n,s){const i=e+(n-e)*s;return ar(t,i)}const lr={upperCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",lowerCase:"abcdefghijklmnopqrstuvwxyz",upperAndLowerCase:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",numbers:"0123456789"},Mm=20;function Kc(t){const e=lr[t??"upperCase"]??t??lr.upperCase,n=Array.from(e);return n.length>0?n:Array.from(lr.upperCase)}function Sm(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 Xc(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=Kc(t.chars),p=t.refreshRate??Mm,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[Sm(m,v,g)%f.length]}return w}class Et{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=sc(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",Xc(l.textConfig,o,Math.max(0,r)));return}const c=this._motionPathTracks.get(n);if(c&&typeof o=="number"){const h=ar(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 Ae(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,Me(e)){this._trackPlayers.set(e.id,new jc(e));return}if(Se(e)){this._trackPlayers.set(e.id,new Yc(e)),this._springTracks.set(e.id,e);return}if(Js(e))this._trackPlayers.set(e.id,new as(e)),this._textTracks.set(e.id,e);else if(Bo(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 as(n)),this._motionPathTracks.set(e.id,e)}else this._trackPlayers.set(e.id,new as(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(Se(s)||Me(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=Ae(r).filter(u=>Ae(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&&!Ae(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:Wo(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 Tm=100;function cr(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(Tm,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 Gc(t){return Me(t)?{id:t.id,target:t.target,property:t.property,kind:"inertia",inertia:Uc(t.inertia),...ce(t)}:Se(t)?{id:t.id,target:t.target,property:t.property,kind:"spring",spring:{...t.spring},...ce(t)}:Js(t)?{id:t.id,target:t.target,property:"text",textConfig:{...t.textConfig},keyframes:t.keyframes.map(hr),...ce(t)}:Bo(t)?{id:t.id,target:t.target,property:"motionPath",motionPathConfig:{...t.motionPathConfig},keyframes:t.keyframes.map(hr),...ce(t)}:{id:t.id,target:t.target,property:t.property,keyframes:t.keyframes.map(hr),...t.interpolation!==void 0&&{interpolation:t.interpolation},...ce(t)}}function Uc(t){return{...t,...Array.isArray(t.end)&&{end:[...t.end]}}}function hr(t){return{time:t.time,value:t.value,...t.easing&&{easing:t.easing}}}function ce(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 Vc(t){if(Me(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"inertia",inertia:Uc(e.inertia),...ce(e)}}if(Se(t)){const e=t;return{id:e.id,target:e.target,property:e.property,kind:"spring",spring:{...e.spring},...ce(e)}}if(Js(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),...ce(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,...ce(e)}}return ai({id:t.id,target:t.target,property:t.property,keyframes:t.keyframes,...t.interpolation!==void 0&&{interpolation:t.interpolation},...ce(t)})}function Jc(t){const e=t._config.markers;return{formatVersion:Wo(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(Gc),...t.captions&&{captions:JSON.parse(JSON.stringify(t.captions))}}}function wn(t){const e=t.formatVersion??1;if(e>Do)throw new Error(`tinyfly: this animation uses format version ${e}, but this tinyfly reads up to version ${Do}. Update tinyfly to play it.`);return new Et({id:t.id,name:t.name,config:t.config,tracks:t.tracks.map(Vc),captions:t.captions})}function xm(t){return JSON.stringify(Jc(t))}function Em(t){const e=JSON.parse(t);return wn(e)}function Yt(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 Pe(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 ur(t,e,n){return e+t.next()*(n-e)}function Zc(t,e,n,s){if(s<=0)return ur(t,e,n);const i=Math.floor((n-e)/s),o=Math.round(t.next()*i);return e+o*s}function Am(t,e){if(e.length!==0)return e[Math.floor(t.next()*e.length)]}const Qc=/^([+\-*/])=\s*(-?[\d.]+)$/,th=/^random\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*(?:,\s*(-?[\d.]+)\s*)?\)$/i;function Pm(t){return typeof t!="string"?!1:Qc.test(t.trim())||th.test(t.trim())}function dr(t,e={}){if(typeof t!="string")return t;const n=t.trim(),s=Qc.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=th.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?Zc(e.random,o,r,a):ur(e.random,o,r)}return t}function eh(t,e=0,n){const s=[];let i=e;for(const o of t){const r=dr(o,{base:i,random:n});s.push(r),typeof r=="number"&&(i=r)}return s}class $m{random;constructor(e){this.random=Pe(e)}get seed(){return this.random.seed}resolve(e,n=0){return dr(e,{base:n,random:this.random})}resolveSequence(e,n=0){return eh(e,n,this.random)}}const Im=600;function nh(t){if(Array.isArray(t)){const[d,f,p,g]=t;return{fn:oh(d,f,p,g),bezier:[d,f,p,g]}}const{segments:e}=Ke(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:oh(...m),bezier:m}}const c=[],h=[],u=Math.max(8,Math.ceil(Im/e.length));for(const d of e)for(let f=c.length===0?0:1;f<=u;f++){const[p,g]=Om(d,f/u);c.push(a(p)),h.push(l(g))}return{fn:_m(c,h)}}function sh(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 ih(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 Om(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 _m(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 oh(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 Cm=350,Hm=300,Rm=550;function Lm(t,e={}){const n=e.lead??Cm,s=e.gap??Hm,i=e.tail??Rm,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 Nm(t){return t.cues.map(e=>({id:e.id,time:e.start,label:e.text}))}function Fm(t,e){let n=t.scenes[0];for(const s of t.scenes)if(e>=s.start)n=s;else break;return n}const ls=t=>6e4/t.bpm;function li(t,e){return t.offset+e*ls(t)}function cs(t,e){return(e-t.offset)/ls(t)}function Dm(t,e){return li(t,Math.round(cs(t,e)))}function Wm(t,e){return li(t,Math.ceil(cs(t,e)-1e-9))}function Bm(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(cs(t,e)-1e-9);;o++){const r=li(t,o);if(r>n+1e-9)break;i.push({time:r,bar:(o%s+s)%s===0,n:o})}return i}const kn=100;function zm(t,e,n={}){const s=n.minBpm??70,i=n.maxBpm??180,o=Math.max(1,Math.round(e/kn)),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 x=0;for(let O=S*o;O<(S+1)*o;O++)x+=t[O]*t[O];l[S]=Math.log(1e-6+x/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,x)=>S+x,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*kn/i)),d=Math.min(a-1,Math.ceil(60*kn/s)),f=S=>{let x=0;for(let O=S;O<a;O++)x+=c[O]*c[O-S];return x/(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 x=60*kn/S,O=Math.exp(-.5*(Math.log2(x/120)/.9)**2),I=f(S)*O;I>m&&(m=I,g=S)}const w=S=>{const x=Math.floor(S);return x<0||x+1>=a?0:c[x]+(c[x+1]-c[x])*(S-x)},v=(S,x)=>{let O=0;for(let I=x;I<a;I+=S)O+=w(I);return O};let k=g,b=0,M=-1/0;for(let S=g-.6;S<=g+.6+1e-9;S+=.02){if(S<1)continue;const x=Math.max(1,Math.round(S*4));for(let O=0;O<x;O++){const I=O/x*S,_=v(S,I);_>M&&(M=_,b=I,k=S)}}const E=60*kn/k,A=p>0?Math.max(0,Math.min(1,f(g)/p)):0,T=(b+.5)*1e3/kn;return{bpm:Math.round(E*100)/100,offset:Math.round(T%(6e4/E)),confidence:A}}const qm=600,Ym=250,rh=1;function jm(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(rh,u.duration??qm);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>rh?"ease-in-out":void 0))}else{const{follow:d}=u,f=d.lag??Ym,p=new Et({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=Pe(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 ah(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 hs(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=ah(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 ut(t,e,n,s){const i=typeof e=="string"?s??hs(e,n):void 0;return`Unknown ${t} ${JSON.stringify(e)}${i?`: did you mean "${i}"?`:"."} Known: ${n.join(", ")}`}function us(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 Xe(t,e,n=1){if(!(e>0))return 0;const s=t*n/e;return s-Math.floor(s)}function fr(t){const e=t-Math.floor(t);return 1-Math.abs(e*2-1)}function Km(t,e){const n=Math.max(1,Math.round(e.cycles??1)),s=e.amplitude??1,i=Xe(t,e.period,n)+(e.phase??0),o=i-Math.floor(i);switch(e.shape??"sine"){case"triangle":return s*(fr(o+.25)*2-1);case"square":return o<.5?s:-s;default:return s*Math.sin(o*Math.PI*2)}}function Xm(t,e){const n=Math.max(1,Math.round(e.cycles??1)),s=typeof e.easing=="function"?e.easing:Ht(e.easing??"ease-in-out"),i=Xe(t,e.period,n)+(e.phase??0);return s(fr(i))}function Gm(t,e){const n=lh(e.seed),s=Math.max(1,Math.round(e.cycles??1)),i=(Xe(t,e.period,1)+(e.phase??0))*Math.PI*2,o=s/Math.PI;return ch([Math.cos(i)*o+7.31,Math.sin(i)*o+3.17],n,e.octaves??1)}function Um(t,e,n){const s=lh(n.seed),i=Math.max(1,Math.round(n.cycles??1)),o=Math.max(1,Math.round(n.cyclesAlong??1)),r=Xe(t,n.period,1)*Math.PI*2,a=Xe(e,n.periodAlong,1)*Math.PI*2,l=i/Math.PI,c=o/Math.PI;return ch([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 lh=t=>typeof t=="string"?Yt(t):(t??0)>>>0;function ch(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*Vm(t.map(c=>c*l),e+a*1013),r+=o,o*=.5}return i/r}function Vm(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*Jm(c,e))}return r}function Jm(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 Zm(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 as(s);return o=>i.getValueAtTime(o)}function Qm(t,e){return e*ls({bpm:t.bpm})}function t1(t,e){const n=Math.max(1,Math.round(t/ls(e)));return{beats:n,grid:{...e,bpm:n*6e4/t}}}function e1(t,e,n={}){const s=Math.max(1e-6,n.attack??.05),i=Math.max(1e-6,n.decay??.4),o=cs(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 n1(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 s1(t,e,n=30,s){if(t.length===0)return 0;const o=(s?Xe(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 hh={"16:9":16/9,"2.39:1":2.39,"4:3":4/3,"1:1":1,"9:16":9/16,"4:5":4/5},gr=t=>typeof t=="number"?t:hh[t];function i1(t,e){const n=gr(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 o1(t,e){const n=gr(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 r1(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 he=t=>Math.round(t*1e3)/1e3;function uh(t,e={}){if(t.length===0)return"";const n=e.curviness??1,s=e.closed??!1,i=t.length;let o=`M${he(t[0].x)} ${he(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${he(u.x)} ${he(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${he(p)} ${he(g)} ${he(m)} ${he(w)} ${he(u.x)} ${he(u.y)}`}return s?`${o} Z`:o}const Rt=(t,e=0)=>{const n=parseFloat(t??"");return Number.isFinite(n)?n:e};function a1(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 ci(t){const e=t.attributes;switch(t.tag.toLowerCase()){case"path":return e.d??null;case"circle":case"ellipse":{const n=Rt(e.cx),s=Rt(e.cy),i=t.tag.toLowerCase()==="circle"?Rt(e.r):Rt(e.rx),o=t.tag.toLowerCase()==="circle"?Rt(e.r):Rt(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=Rt(e.x),s=Rt(e.y),i=Rt(e.width),o=Rt(e.height);let r=e.rx!=null?Rt(e.rx):e.ry!=null?Rt(e.ry):0,a=e.ry!=null?Rt(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${Rt(e.x1)} ${Rt(e.y1)} L${Rt(e.x2)} ${Rt(e.y2)}`;case"polyline":case"polygon":{const n=a1(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 l1(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 c1=2.5;function dh(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(c1,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 fh(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 h1={scale:1,turn:0,x:0,y:0};function u1(t={}){return{scale:t.scale??1,turn:t.turn??0,x:t.x??0,y:t.y??0}}function gh(t,e,n){const{ax:s,ay:i}=hi(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 pr(t,e){const{ax:n,ay:s}=hi(t.scale,t.turn);return{x:n*e.x-s*e.y+t.x,y:s*e.x+n*e.y+t.y}}function d1(t,e){const n=pr(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 f1(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=pr(e,{x:t.x,y:t.y});return{...e,x:-n.x,y:-n.y}}function ph(t){const{ax:e,ay:n}=hi(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 g1(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=ph(t);return i?gh(n,s,i):{scale:n,turn:s,x:t.x*e,y:t.y*e}}function p1(t){const{ax:e,ay:n}=hi(t.scale,t.turn);return[e,n,-n,e,t.x,t.y]}const hi=(t,e)=>{const n=e*Math.PI/180;return{ax:t*Math.cos(n),ay:t*Math.sin(n)}};function ui([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 mr=([t,e,n])=>t+e+n;function yr(t,e={}){const[n,s,i]=t.min,[o,r,a]=t.max,l=d=>ui(d,e),c=[(n+o)/2,(s+r)/2,(i+a)/2],h=mr(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 br(t,e={}){return t.map(n=>({box:n,depth:mr([(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})=>yr(n,e))}function m1(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=ui([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:[...br(i,a),...yr({...i[0],hide:["right"]},a)]}}function y1(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],M=[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],M[0]),Math.min(b[1],M[1]),0],max:[Math.max(b[0],M[0]),Math.max(b[1],M[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=ui([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:br(h,m),rise:l}}function mh(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 b1(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]=mh(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 M=()=>h(g,m,k[0],w,m,k[1]),E=()=>h(w,m,k[1],w,v,k[2]),A=()=>h(g,v,k[3],w,v,k[2]),T=()=>h(g,m,k[0],g,v,k[3]),S=(k[0]+k[1]+k[2]+k[3])/4>0;switch(b){case 1:case 14:u.push([T(),M()]);break;case 2:case 13:u.push([M(),E()]);break;case 3:case 12:u.push([T(),E()]);break;case 4:case 11:u.push([E(),A()]);break;case 6:case 9:u.push([M(),A()]);break;case 7:case 8:u.push([T(),A()]);break;case 5:S?u.push([T(),A()],[M(),E()]):u.push([T(),M()],[E(),A()]);break;case 10:S?u.push([T(),M()],[E(),A()]):u.push([T(),A()],[M(),E()]);break}}const d=w1(u);return e.smooth===!1?d:d.map(f=>yh(yh(f)))}function w1(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 yh(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 k1(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 v1(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 M1(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 S1(t,e={}){const n=Math.max(.05,1+t);return{sx:e.keep==="volume"?1/Math.sqrt(n):1/n,sy:n}}function T1(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 di(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function vn(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function Mn(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function $e(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function fi(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 gi(t){return Math.hypot(t[0],t[1],t[2])}function wr(t,e){return gi(vn(t,e))}function Ge(t){const e=gi(t);return e===0?[0,0,0]:Mn(t,1/e)}function bh(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 x1=Object.freeze(Object.defineProperty({__proto__:null,add:di,cross:fi,distance:wr,dot:$e,length:gi,lerp:bh,normalize:Ge,scale:Mn,subtract:vn},Symbol.toStringTag,{value:"Module"})),E1=Math.PI/180;function pi(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function At(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 Ue(t){return[1,0,0,0,0,1,0,0,0,0,1,0,t[0],t[1],t[2],1]}function Ve(t){return[t[0],0,0,0,0,t[1],0,0,0,0,t[2],0,0,0,0,1]}function se(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 kr(t,e,n){const s=se(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 A1(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 vr(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,M=n*l-i*r,E=s*l-i*a,A=c*p-h*f,T=c*g-u*f,S=c*m-d*f,x=h*g-u*p,O=h*m-d*p,I=u*m-d*g,_=w*I-v*O+k*x+b*S-M*T+E*A;if(Math.abs(_)<1e-12)return null;const C=1/_;return[(r*I-a*O+l*x)*C,(s*O-n*I-i*x)*C,(p*E-g*M+m*b)*C,(u*M-h*E-d*b)*C,(a*S-o*I-l*T)*C,(e*I-s*S+i*T)*C,(g*k-f*E-m*v)*C,(c*E-u*k+d*v)*C,(o*O-r*S+l*A)*C,(n*S-e*O-i*A)*C,(f*M-p*k+m*w)*C,(h*k-c*M-d*w)*C,(r*T-o*x-a*A)*C,(e*x-n*T+s*A)*C,(p*v-f*b-g*w)*C,(c*b-h*v+u*w)*C]}function P1(t,e,n,s){const i=1/Math.tan(t*E1/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 $1(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 I1(t,e,n=[0,1,0]){const s=Ge(vn(t,e)),i=Ge(fi(n,s)),o=fi(s,i);return[i[0],o[0],s[0],0,i[1],o[1],s[1],0,i[2],o[2],s[2],0,-$e(i,t),-$e(o,t),-$e(s,t),1]}function jt(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 O1=Object.freeze(Object.defineProperty({__proto__:null,compose:kr,fromQuat:se,identity:pi,invert:vr,lookAt:I1,multiply:At,orthographic:$1,perspective:P1,scaling:Ve,transformPoint:jt,translation:Ue,transpose:A1},Symbol.toStringTag,{value:"Module"})),mi={"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]},wh={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 _1(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}Ht({type:"bounce",mode:"in"}),Ht({type:"bounce",mode:"in-out"});function ds(t){const e=kh.get(t.trim().toLowerCase());if(e)return e;const n=_1(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:Ht(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 mi)return{easing:{type:"cubic-bezier",points:mi[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:Ht(h)}}return n in wh?{easing:wh[n]}:n in mi?{easing:{type:"cubic-bezier",points:mi[n]}}:{easing:"ease-out"}}const kh=new Map;function Mr(t,e){return kh.set(t.trim().toLowerCase(),e.bezier?{easing:{type:"cubic-bezier",points:e.bezier},fn:e.fn}:{fn:e.fn,requiresBaking:"custom"}),t}function Sr(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 vh=/^\s*random\(\s*(\[.*\]|[^)]*)\s*\)\s*$/;function Mh(t){return typeof t=="string"&&vh.test(t)}function C1(t=1){let e=Sr(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 Sh(l,c,1/0);if("values"in l)return Sh(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]=rs(l[d])(l[d],c[d],h);return u}return rs(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=Zs(f,m,{...c!==void 0?{amount:c}:{each:h??1},from:u}),k=c!==void 0?c:(h??1)*qo(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=>H1(l),getUnit:l=>typeof l=="number"?"":/^-?[\d.]+(?:e[-+]?\d+)?([a-z%]*)$/i.exec(l.trim())?.[1]??"",seed:l=>{e=Sr(l)},resolveRandomString:l=>{const c=vh.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 Sh(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 H1(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 R1=/^([+-])=\s*(-?[\d.]+)$/,L1=/^([<>])\s*(?:([+-])?=?\s*(-?[\d.]+))?$/;function fs(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=R1.exec(i);if(o){const c=s(o[2]);return e.cursor+(o[1]==="-"?-c:c)}const r=L1.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 N1(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 F1(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?ds(e.ease):void 0,f=d?d.fn??Ht(d.easing):void 0;return c.map(p=>{const g=h===0?0:p/h;return(f?f(g):g)*u})}const Tr=new Set(["duration","delay","ease","repeat","repeatDelay","yoyo","stagger","onComplete","onUpdate","onStart","onRepeat","onReverseComplete","repeatRefresh","keyframes","easeEach","scrollTo","id","immediateRender","overwrite","paused","scrollTrigger","spring"]),D1={rotation:"rotate",rotationZ:"rotate",rotationX:"rotateX",rotationY:"rotateY",transformPerspective:"perspective",perspective:"childPerspective"};function yi(t){const e={},n={};for(const[s,i]of Object.entries(t))Tr.has(s)?e[s]=i:n[D1[s]??s]=i;return{config:e,properties:n}}function bi(t,e){return t===void 0?e:t*1e3}function xr(t,e){if(t!==void 0)return typeof t=="number"?{each:t*1e3}:N1(t)?{offsets:F1(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 W1={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 Th(t){return W1[t]}function B1(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=uh(e.path,{curviness:e.curviness});else if(mn(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 z1(t){const e=typeof t=="string"||Array.isArray(t)?{path:t}:{...t};return{...e,start:e.end??1,end:e.start??0}}function xh(t){return typeof t=="object"&&t!==null&&"shape"in t?t.shape:t}function q1(t){if(t.morphSVG===void 0)return t;const{morphSVG:e,...n}=t,s=xh(e);if(typeof s!="string"||!mn(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 Y1(t,e){if(t===!0)return[0,e];if(t===!1)return[0,0];if(typeof t=="number")return[0,Eh(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 Eh(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 j1(t,e){const[n,s]=Y1(t,e);return{strokeDasharray:[s-n,e],strokeDashoffset:-n}}function K1(t,e){if(t.drawSVG===void 0)return t;const{drawSVG:n,...s}=t;return{...s,...j1(n,e)}}function X1(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 Eh(t,e){return Math.max(0,Math.min(e,t))}function G1(t){let e=2166136261;for(let n=0;n<t.length;n++)e=Math.imul(e^t.charCodeAt(n),16777619);return e>>>0}function U1(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??G1(`${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 Er(t){return Math.max(.1,t/25)}function V1(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?Er(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(es(i))]:n.end!==void 0&&(i.end=Array.isArray(n.end)?[...n.end]:n.end),i}function J1(t){const e=t===!0?{}:typeof t=="string"?{preset:t}:t;if(e.preset!==void 0&&!(e.preset in ei))throw new Error(`gsap-compat: unknown spring preset "${e.preset}" — use one of ${Object.keys(ei).join(", ")}`);return{...e.preset?ei[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 Z1(t,e){if(t===!0||typeof t=="string")return;const n=t.velocity;return typeof n=="number"?n:n?.[e]}class Je{timeline;options;cursor=0;fallbackRandom=Sr(1);previousStart=0;previousEnd=0;labels=new Map;trackCounter=0;lastValues=new Map;constructor(e={}){this.options=e,this.timeline=new Et({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,gs(n),s)}from(e,n,s){const{config:i,properties:o}=yi(gs(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=z1(r));const d={},f=String(this.resolveStart(h,"text"));return a!==void 0&&(d.text=Ar(a),u.text=typeof a=="object"?{...a,value:f}:f),l!==void 0&&(d.text=Ar(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}=yi(gs(n));return this.build(e,o,gs(s),i)}set(e,n,s){return this.build(e,void 0,{...gs(n),duration:0},s)}get lastStart(){return this.previousStart}get lastEnd(){return this.previousEnd}addEvent(e){const n=Math.max(0,fs(e,this.context()));return this.previousStart=n,this.previousEnd=n,this.cursor=Math.max(this.cursor,n),n}timeOf(e){return fs(e,this.context())}addLabel(e,n){return this.labels.set(e,fs(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=fs(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}=yi(s),{motionPath:a,text:l,scrambleText:c,inertia:h,...u}=r,d=this.targetsOf(e),f=fs(i,this.context()),p=bi(o.delay,0),g=bi(o.duration,500),m=xr(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,M=!1;for(const[O,I]of Object.entries(u)){const _=I;let C=n?.[O]!==void 0?n[O]:this.resolveStart(d[0],O);if(typeof C!=typeof _&&(this.warn(`no usable start value for "${O}" 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 "${O}" on "${d[0]}" eases instead`),k!==void 0&&typeof C=="number"&&typeof _=="number"){const X={...J1(k),from:C,to:_,velocity:Z1(k,O)??this.options.startVelocity?.(d[0],O)??0},J=this.nextTrackId(`${d[0]}-${O}-spring`),K={id:J,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:O,kind:"spring",spring:X,delay:f+p};this.timeline.addTrack(K),v.push(J),b=Math.max(b,ic(X));for(const P of d)this.lastValues.set(`${P}|${O}`,_);continue}M=!0;const F=this.keyframesFor(C,_,g,w,o.ease),z=this.nextTrackId(`${d[0]}-${O}`);this.timeline.addTrack(ai({id:z,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:O,delay:f+p,keyframes:F,...O==="quaternion"&&{interpolation:"slerp"}})),v.push(z);for(const X of d)this.lastValues.set(`${X}|${O}`,_)}const E=U1({text:l,scrambleText:c},d[0],g);if(E){const O=n?.text??n?.scrambleText,I=O!==void 0?Ar(O):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 I=="string"?I:String(I??""),...E},delay:f+p,keyframes:this.keyframesFor(0,1,g,w,o.ease)};this.timeline.addTrack(C),v.push(_);for(const F of d)this.lastValues.set(`${F}|text`,E.to)}if(a!==void 0){const{config:O,start:I,end:_}=B1(a),C=this.nextTrackId(`${d[0]}-motionPath`),F={id:C,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:"motionPath",motionPathConfig:O,delay:f+p,keyframes:this.keyframesFor(I,_,g,w,o.ease)};this.timeline.addTrack(F),v.push(C)}if(h!==void 0)for(const[O,I]of Object.entries(h)){const _=this.resolveStart(d[0],O);if(typeof _!="number"){this.warn(`inertia on "${O}" needs a numeric start value; skipped`);continue}const C=V1(_,I),F=this.nextTrackId(`${d[0]}-${O}-inertia`),z={id:F,target:d[0],...d.length>1&&{targets:d},...m&&d.length>1&&{stagger:m},property:O,kind:"inertia",inertia:C,delay:f+p};this.timeline.addTrack(z),v.push(F),b=Math.max(b,gn(C));for(const X of d)this.lastValues.set(`${X}|${O}`,fn(C))}const S=((h!==void 0||k!==void 0)&&!M&&!E&&a===void 0?b:Math.max(g,b))+(m&&d.length>1?Qn(d.length,m):0),x=f+p+S;return this.previousStart=f+p,this.previousEnd=x,this.cursor=Math.max(this.cursor,x),{trackIds:v,start:f+p,end:x,kill:()=>{for(const O of v)this.timeline.removeTrack(O)}}}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"?ds(o):void 0;if(a?.requiresBaking==="custom"||this.options.bakeEases&&Zn(i)){const c=a?.fn??Ht(i);return[r,...rr(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=Th(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 ds(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 Ar(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 Q1(t){return new Je(t)}function gs(t){return X1(q1(t))}function ty(t){return!Array.isArray(t)||t.length!==4?null:`matrix3d(${se(Ee(t)).map(n=>Math.round(n*1e6)/1e6+0).join(", ")})`}const ey=new Set(["blur","brightness","glow","glowColor","shadowX","shadowY","shadowBlur","shadowColor"]),ny="#ffffff",sy="rgba(0, 0, 0, 0.5)";function iy(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??ny})`),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??sy})`)}return e.length>0?e.join(" "):null}function oy(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 ry(t){if(!("ownerSVGElement"in t))return;const e=t.style;!e||e.transformBox||(e.transformBox="fill-box",e.transformOrigin||(e.transformOrigin="50% 50%"))}const Ah=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"]),ay=new Set(["x","y","z","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY","quaternion","motionPathX","motionPathY","motionPathRotate"]),ly=["x","motionPathX","y","motionPathY","z","rotate","rotateZ","motionPathRotate","rotateX","rotateY","quaternion","scale","scaleX","scaleY","scaleZ","skewX","skewY"],cy=new Set(["childPerspective","perspectiveOriginX","perspectiveOriginY"]),hy=new Set(["originX","originY"]),uy=new Set(["clipTop","clipRight","clipBottom","clipLeft"]),dy=new Set(["drawOn"]),fy={fill:"backgroundColor",stroke:"borderColor",strokeWidth:"borderWidth",color:"color",backgroundColor:"backgroundColor",borderColor:"borderColor"},Ph={fill:"fill",stroke:"stroke",strokeWidth:"strokeWidth",strokeDasharray:"strokeDasharray",strokeDashoffset:"strokeDashoffset",fillOpacity:"fillOpacity",strokeOpacity:"strokeOpacity"},gy="http://www.w3.org/2000/svg";class Ze{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)&&!dy.has(p)){if(ay.has(p))(s??={})[p]=g;else if(cy.has(p))typeof g=="number"&&((i??={})[p]=g);else if(hy.has(p))typeof g=="number"&&((o??={})[p]=g);else if(uy.has(p))typeof g=="number"&&((r??={})[p]=g);else if(ey.has(p))(a??={})[p]=g;else if(p!=="perspective"){if(p!=="shine")if(p==="text"&&typeof g=="string")oy(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 ly){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(" "),ry(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=iy(a);p&&(e.style.filter=p)}}buildTransformPart(e,n){if(e==="quaternion")return ty(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===gy&&n in Ph){const a=Array.isArray(s)?s.join(", "):String(s);e.style[Ph[n]]=a;return}else n==="fill"&&e.dataset?.elementType==="text"?i="color":i=fy[n]??n;let r;typeof s=="number"?Ah.has(n)||Ah.has(i)?r=`${s}px`:r=String(s):Array.isArray(s)?r=s.join(", "):r=s,e.style[i]=r}}const py={request:t=>requestAnimationFrame(t),cancel:t=>cancelAnimationFrame(t)};class $h{adapter=new Ze;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=C1();active=new Map;applied=new Map;dirty=new Set;frameId=null;lastTimestamp=null;destroyed=!1;constructor(e={}){this.scheduler=e.scheduler??py,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);Pr(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(Pr(e))return[e];if(!my(e))return[e];const n=[];for(const s of Array.from(e))n.push(...this.targetsOf(s));return n}nameFor(e){return Pr(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 Pr(t){return typeof t=="object"&&t!==null&&t.nodeType===1}function my(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 Ih=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function yy(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function by(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 wy(t,e){const n=typeof t=="string"||Array.isArray(t)||Ih(t)?{path:t}:t,{align:s,alignOrigin:i,path:o,...r}=n,a=E=>{const A=Ih(E)?E:e.query(E);return A||e.warn(`gsap-compat: motionPath could not find "${String(E)}"`),A};let l=null,c="";if(Array.isArray(o)||typeof o=="string"&&mn(o))c=o;else{l=a(o);const E=l&&ci({tag:l.localName,attributes:yy(l)});l&&!E&&e.warn(`gsap-compat: motionPath element <${l.localName}> has no path geometry`),c=E??""}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]=by(u),k=wi(d),[b,M]=i??[.5,.5];for(const E of e.targets.slice(1)){const A=wi(E);if(Math.abs(A.left-k.left)>.5||Math.abs(A.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-M*k.height],h}const Oh=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function _h(t){const e={};for(const n of Array.from(t.attributes))e[n.name]=n.value;return e}function Ch(t){if(!t)return null;const e=ci({tag:t.localName,attributes:_h(t)});return e||(t.querySelector("path")?.getAttribute("d")??null)}function ky(t,e,n){const s=xh(t);if(typeof s=="string"&&mn(s))return s;const i=Oh(s)?s:typeof s=="string"?e(s):null,o=Ch(i);return o||(n(`gsap-compat: morphSVG could not find a shape for "${String(s)}"`),"")}const vy=new Set(["cx","cy","r","rx","ry","x","y","width","height","x1","y1","x2","y2","points"]);function My(t,e=document){return(typeof t=="string"?Array.from(e.querySelectorAll(t)):Oh(t)?[t]:Array.from(t)).map(s=>{if(s.localName==="path")return s;const i=ci({tag:s.localName,attributes:_h(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))vy.has(r.name)||o.setAttribute(r.name,r.value);return o.setAttribute("d",i),s.parentNode.replaceChild(o,s),o})}const Hh=.3;class Rh{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=Lh(),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=Lh(),i=Math.max(1,s-this.lastTime);this.lastTime=s;const o=e/i*1e3,r=n/i*1e3;this.velocityX+=(o-this.velocityX)*Hh,this.velocityY+=(r-this.velocityY)*Hh}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 Lh(){return typeof performance<"u"?performance.now():Date.now()}function Nh(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 Fh(t,e){return e<=0?[]:t.map(n=>Math.round(n/e)*e)}class $r{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 Rh({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=Sy(i/s);e.pause(),e.seek(o*n)}applyConstraints(e,n){let s=e;const i=[...Fh([s],this.options.snap??0),...(n==="x"?this.options.snapLinesX:this.options.snapLinesY)??[]],o=Nh([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 Sy(t){return t<0?0:t>1?1:t}function Ty(t){const e=new $r(t);return e.start(),e}const xy={x:"x",y:"y","x,y":"both"},Ir=t=>typeof t=="object"&&t!==null&&t.nodeType===1;function Dh(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 Wh(t){return Array.isArray(t)?[...t]:t}function Ey(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 Ay(t,e,i,o,s);const r=xy[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):Ir(s.bounds)?s.bounds:null,h={bounds:(!l&&s.bounds&&!Ir(s.bounds)?s.bounds:void 0)??(l?Dh(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?Er(m.resistance):4),v=a(),k=h.bounds??{};let b,M;const E=m.end;if(Array.isArray(E)){const T=es({from:v.x,velocity:r==="y"?0:g.x,friction:w}),S=es({from:v.y,velocity:r==="x"?0:g.y,friction:w});let x=E[0];for(const O of E)Math.hypot(O.x-T,O.y-S)<Math.hypot(x.x-T,x.y-S)&&(x=O);x&&(b=[x.x],M=[x.y])}else typeof E=="number"?(b=E,M=E):E&&(b=Wh(E.x),M=Wh(E.y));const A={};r!=="y"&&(A.x={velocity:g.x,friction:w,min:k.minX,max:k.maxX,end:b}),r!=="x"&&(A.y={velocity:g.y,friction:w,min:k.minY,max:k.maxY,end:M}),u=t.to(o,{inertia:A,onComplete:()=>s.onThrowComplete?.()})},p=new $r({target:o,axis:r,snap:s.snap,get bounds(){return h.bounds},getPosition:a,onPress:()=>{d(),l&&(h.bounds=Dh(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 Ay(t,e,n,s,i){const o=typeof i.bounds=="object"&&i.bounds!==null&&!Ir(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 M=b-d;M>180&&(M-=360),M<-180&&(M+=360),d=b,f+=M;let E=a(f);i.snap&&(E=a(Math.round(E/i.snap)*i.snap)),e.apply(n,{rotate:E});const A=performance.now();for(p.push({time:A,rotation:E});p.length>2&&A-p[0].time>100;)p.shift();const T={x:0,y:0};i.onDrag?.(T)},v=k=>{if(!c||k.pointerId!==h)return;c=!1;const b=p[0],M=p[p.length-1],E=b&&M?(M.time-b.time)/1e3:0,A=E>0?(M.rotation-b.rotation)/E:0;if(i.onRelease?.({x:A,y:0}),!i.inertia)return;const T=i.inertia===!0?{}:i.inertia,S=T.friction??(T.resistance!==void 0?Er(T.resistance):4),x=typeof T.end=="number"||Array.isArray(T.end)?T.end:void 0;l=t.to(s,{inertia:{rotate:{velocity:A,friction:S,min:o.minRotation,max:o.maxRotation,end:Array.isArray(x)?x.filter(O=>typeof O=="number"):x}},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 Py={opacity:0,scale:.6};function $y(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 Bh(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 Or(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=$y(r);i.set(r,a);const l=zh(r);a&&l!==void 0&&!o.has(l)&&o.set(l,{element:r,box:a})}return{elements:s,boxes:i,ids:o}}const _r=new WeakMap;function Cr(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?Py: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=Bh(f);if(!p)continue;let g=n.boxes.get(f)??null,m;const w=zh(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);_r.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},{...qh(l),x:0,y:0,scaleX:1,scaleY:1,duration:i,ease:o,delay:b},0),_r.set(f,u),d++;continue}const M=g.cx-p.cx,E=g.cy-p.cy,A=a?g.width/p.width:1,T=a?g.height/p.height:1;if(!(Math.abs(M)>.5||Math.abs(E)>.5||Math.abs(A-1)>.001||Math.abs(T-1)>.001)){const O=(I,_)=>{const C=t.appliedValue(k,I);return typeof C=="number"&&Math.abs(C-_)>1e-6};(O("x",0)||O("y",0)||O("scaleX",1)||O("scaleY",1))&&u.set(f,{x:0,y:0,scaleX:1,scaleY:1},0);continue}const x=s.fade===!0&&m!==void 0;u.fromTo(f,{x:M,y:E,scaleX:A,scaleY:T,...x&&{opacity:0}},{x:0,y:0,scaleX:1,scaleY:1,...x&&{opacity:1},duration:i,ease:o,delay:b},0),x&&m&&Bh(m)&&u.fromTo(m,{opacity:1},{opacity:0,duration:i,ease:o,delay:b},0),_r.set(f,u),d++}return u}function zh(t){return t.dataset?.flipId}function qh(t){const e={};for(const n of Object.keys(t))e[n]=n==="opacity"||n.startsWith("scale")?1:0;return e}function Iy(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=Oy(m,s.words),k=n.has("chars")?v.flatMap(E=>_y(E,s.chars)):[],b=n.has("lines")?Hy(m,v,s.lines):[];if(i){!m.hasAttribute("aria-label")&&w&&m.setAttribute("aria-label",w);for(const E of v)E.setAttribute("aria-hidden","true")}if(n.has("words"))g.words.push(...v);else for(const E of v)E.removeAttribute("class");g.chars.push(...k),g.lines.push(...b);const M=e.mask==="lines"?b:e.mask==="words"?v:e.mask==="chars"?k:[];for(const E of M)g.masks.push(Ry(E,`${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 M of k){const E=Math.round(M.contentRect.width),A=g.get(M.target);g.set(M.target,E),A!==void 0&&A!==E&&(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 Oy(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 _y(t,e){const n=t.ownerDocument,s=Cy(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 Cy(t){const e=Intl.Segmenter;return e?Array.from(new e(void 0,{granularity:"grapheme"}).segment(t),n=>n.segment):Array.from(t)}function Hy(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 Ry(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 Yh={top:0,left:0,start:0,center:.5,centre:.5,middle:.5,bottom:1,right:1,end:1};function Hr(t){const e=t.trim().toLowerCase();if(e in Yh)return Yh[e];if(e.endsWith("%")){const n=Number.parseFloat(e.slice(0,-1));return Number.isNaN(n)?void 0:n/100}}function Rr(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?Hr(s[0]):void 0,o=s[1]!==void 0?Hr(s[1]):void 0;return{elementFraction:i??0,viewportFraction:o??0,offsetPx:e}}function Sn(t,e,n){const s=Rr(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 Ly(t,e,n,s){const i=Sn(t,e,n),r=Sn(t,e,s)-i;return r<=0?i<=0?1:0:Lr(-i/r)}function Lr(t){return t<0?0:t>1?1:t===0?0:t}function jh(t,e,n,s){if(n<=0)return e;const i=1-Math.exp(-(s/1e3)/n);return t+(e-t)*i}function Nr(t,e,n,s,i){const o=h=>Sn({top:t+i(h),bottom:t+i(h)+e,height:e},n,s),r=o(0),a=o(1);if(Math.sign(r)===Math.sign(a)||r===0||a===0)return r===0?0:a===0?1:Math.abs(r)<Math.abs(a)?0:1;let l=0,c=1;for(let h=0;h<40;h++){const u=(l+c)/2;Math.sign(o(u))===Math.sign(r)?l=u:c=u}return(l+c)/2}class Kh{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 Ny(t){const e=new Kh(t);return e.start(),e}class Xh{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 Fy=.15;function Gh(t){return typeof t=="object"&&!Array.isArray(t)?t:{snapTo:t}}function Uh(t,e,n){const s=ki(t+e*Fy);if(typeof n=="function")return ki(n(s));if(typeof n=="number")return n<=0?t:ki(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 ki(i)}function Vh(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 Jh{rafId=null;cancelEvents=["wheel","touchstart","pointerdown","keydown"];onInterrupt=()=>this.cancel();write;eventTarget;constructor(e,n){this.write=e,this.eventTarget=n}get active(){return this.rafId!==null}animate(e,n,s,i=ns,o){if(this.cancel(),typeof requestAnimationFrame>"u"||s<=0){this.write(n),o?.();return}for(const l of this.cancelEvents)this.eventTarget?.addEventListener(l,this.onInterrupt,{passive:!0});let r=null;const a=l=>{r??=l;const c=Math.min(1,(l-r)/(s*1e3));this.write(e+(n-e)*i(c)),c<1?this.rafId=requestAnimationFrame(a):(this.rafId=null,this.detach(),o?.())};this.rafId=requestAnimationFrame(a)}cancel(){this.rafId!==null&&typeof cancelAnimationFrame<"u"&&cancelAnimationFrame(this.rafId),this.rafId=null,this.detach()}detach(){for(const e of this.cancelEvents)this.eventTarget?.removeEventListener(e,this.onInterrupt)}}function ki(t){return Math.max(0,Math.min(1,t))}class Zh{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 Dy=120,Tn=[],xn=new Set;let Fr=!1;const Wy=()=>{Fr||xn.size===0||(Fr=!0,queueMicrotask(()=>{Fr=!1;for(const t of xn)t.afterRefresh()}))},Qh=()=>{for(const t of xn)t.beforeRefresh();for(const t of Tn)t.refresh();for(const t of xn)t.afterRefresh()};let En={width:0,height:0};const t0=()=>{const t=window.innerWidth,e=window.innerHeight,n=t===En.width&&e!==En.height,s=Math.abs(e-En.height)<En.height*.25,i=typeof navigator<"u"&&(navigator.maxTouchPoints??0)>0;n&&s&&i||(En={width:t,height:e},Qh())};class ps{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 Jh(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 Xh(e,{axis:this.options.horizontal?"x":"y",spacing:this.options.pinSpacing!==!1})),this.options.markers&&!this.options.horizontal&&typeof document<"u"&&(this.markers=new Zh(document,this.options.scroller??null,this.options.markers)),this.scrollTarget()?.addEventListener("scroll",this.onScroll,{passive:!0}),Tn.length===0&&typeof window<"u"&&(En={width:window.innerWidth,height:window.innerHeight},window.addEventListener("resize",t0,{passive:!0})),Tn.push(this),this.refresh()}stop(){this.running&&(this.running=!1,this.scrollTarget()?.removeEventListener("scroll",this.onScroll),Tn.splice(Tn.indexOf(this),1),Tn.length===0&&typeof window<"u"&&window.removeEventListener("resize",t0),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(){Qh()}static onRefresh(e){return xn.add(e),()=>xn.delete(e)}get progress(){return this.targetProgress}get velocity(){return this.velocityPxPerSecond}refresh(){if(!this.running)return;this.measured&&this.options.onRefresh?.();const e=this.scrollPosition();this.pin?.release();const n=this.triggerRect();if(n&&this.options.container)this.measureInContainer(this.options.container);else if(n){const s=this.viewportHeight();if(this.startPx=e+Sn(n,s,ms(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,Wy()}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?Lr((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=ms(this.options.end)??"bottom top",o=typeof i=="string"?i.trim().match(/^\+=\s*(-?[\d.]+)\s*(%|px)?$/):null;if(o){const r=Number.parseFloat(o[1]);return this.startPx+(o[2]==="%"?n*r/100:r)}return s+Sn(e,n,i)}applyProgress(){const e=this.timeline?.duration??0;this.timeline&&e>0&&this.timeline.seek(this.displayProgress*e),this.emitUpdate()}emitUpdate(){if(!this.options.onUpdate)return;const e=[this.displayProgress,this.velocityPxPerSecond];this.lastEmitted&&this.lastEmitted[0]===e[0]&&this.lastEmitted[1]===e[1]||(this.lastEmitted=e,this.options.onUpdate(e[0],e[1]))}trackVelocity(e){const n=typeof performance<"u"?performance.now():Date.now();this.lastScroll!==null&&n>this.lastScrollTime&&e!==this.lastScroll&&(this.velocityPxPerSecond=(e-this.lastScroll)/(n-this.lastScrollTime)*1e3),(this.lastScroll===null||e!==this.lastScroll)&&(this.lastScroll=e,this.lastScrollTime=n),!(this.velocityPxPerSecond===0||typeof setTimeout>"u")&&(this.idleTimer!==null&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.idleTimer=null,this.releaseVelocity=this.velocityPxPerSecond,this.velocityPxPerSecond=0,this.emitUpdate(),this.scheduleSnap()},Dy))}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=Gh(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+Uh(r,this.releaseVelocity/i,n.snapTo)*i;Math.abs(a-o)<1||this.snapper.animate(o,a,Vh(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=Nr(r,s.width,o,ms(this.options.start)??"left right",e.shiftAt);this.startPx=c(h);const u=ms(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(Nr(r,s.width,o,u,e.shiftAt)),this.markerGeometry=null}markersFor(e){const n=(o,r)=>{const a=ms(o)??r;if(typeof a=="number")return 0;if(/^\s*\+=/.test(a))return;const l=Rr(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=jh(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 ms(t){return typeof t=="function"?t():t}function By(t){const e=new ps(t);return e.start(),e}const Dr=new Set,zy=16,e0=.5,qy=2;class Wr{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),Dr.add(this),this.stopListening=ps.onRefresh({beforeRefresh:()=>this.rest(),afterRefresh:()=>this.refresh()}),this.refresh(),this}static refreshAll(){for(const e of Dr)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),Dr.delete(this),this.stopListening?.(),this.stopListening=null,this.cancelFrame(),this.journey=null,this}destroy(){this.stop();for(const e of this.effects)Br(e.element,e.saved);this.effects=[]}kill(){this.destroy()}get state(){const e=this.limit();return{scroll:this.current,target:this.target,progress:e>0?this.current/e:0,velocity:this.velocityPxPerSecond}}paused(e){return e!==void 0&&(this.pausedState=e,e&&(this.target=this.current,this.journey=null)),this.pausedState}scrollTo(e,n={}){if(!this.running)return;const s=this.clamp(this.resolve(e)+(n.offset??0)),i=Math.abs(s-this.current),o=this.reduced?0:n.duration??Math.min(1.2,Math.max(.4,i/2500));if(o<=0){this.journey=null,this.current=this.target=s,this.write(s),this.applyEffects(0);return}this.target=s,this.journey={from:this.current,to:s,ms:o*1e3,ease:n.ease??ns,elapsed:0},this.requestFrame()}refresh(){if(!this.running)return;this.rest(),this.effects=[];const e=this.options.effects===!0?"[data-speed], [data-lag]":this.options.effects||"";if(e&&!this.reduced){const n=this.options.scroller??document,s=this.position(),i=this.viewportHeight(),o=this.options.scroller?.getBoundingClientRect().top??0;for(const r of n.querySelectorAll(e)){const a=Number.parseFloat(r.dataset.speed??""),l=Number.parseFloat(r.dataset.lag??""),c=r.getBoundingClientRect(),h=c.top-o+s;this.effects.push({element:r,speed:Number.isFinite(a)?a:void 0,lag:Number.isFinite(l)&&l>0?l:void 0,centre:h+c.height/2-i/2,lagged:s,shift:0,saved:r.style.getPropertyValue("translate")})}}this.current=this.target=this.clamp(this.position()),this.applyEffects(0)}rest(){for(const e of this.effects)Br(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?zy: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)<=qy||(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)<e0&&(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)<e0?i.lagged=s:n=!0,o+=s-i.lagged}Br(i.element,o===0?i.saved:`0 ${Yy(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 Br(t,e){e?t.style.setProperty("translate",e):t.style.removeProperty("translate")}function Yy(t){return Math.round(t*100)/100}function jy(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 zr(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&&jy(n,l[f]??"none"),e.once&&f===0&&queueMicrotask(()=>h.destroy())},d=e.containerAnimation?Gy(t,e.containerAnimation,r,i):void 0;return h=new ps({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:Ky(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 Ky(t,e){const n=i=>i==="labels"?o=>Xy(o,e?.labelProgresses?.()??[]):i;if(typeof t!="object"||Array.isArray(t))return n(t);const s=t.ease?ds(t.ease):void 0;return{snapTo:n(t.snapTo),duration:t.duration,delay:t.delay,ease:s?s.fn??Ht(s.easing):void 0}}function Xy(t,e){return e.reduce((n,s)=>Math.abs(s-t)<Math.abs(n-t)?s:n,e[0]??t)}function Gy(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 Uy{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 Vy{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 Jy={opacity:0,y:-16},Zy={opacity:0,y:16};async function Qy(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 tb(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?Or(e,h):void 0,d=s.from!==void 0?s0(e,s.from,s.shared):[];if(d.length&&s.leave!==!1){const m=s.leave??Jy;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?s0(e,p,s.shared):[];if(g.length&&s.enter!==!1){const m=s.enter??Zy;f.push(c(w=>t.fromTo(g,m,{...qh(m),duration:a,ease:l,onComplete:w})))}if(u){const m=r().filter(w=>!h.includes(w));m.length&&f.push(c(w=>Cr(e,n,u,{targets:m,duration:a*1.4,ease:l,enter:!1,onComplete:w})))}await Promise.all(f)}function s0(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 tb(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 i0={create:(t,e)=>Mr(t,nh(e))},o0={create:(t,e)=>Mr(t,{fn:sh(e)})},r0={create:(t,e)=>Mr(t,{fn:ih(e)})},eb=new Set(["keyframes","duration","delay","ease","easeEach","stagger","repeat","repeatDelay","yoyo","repeatRefresh","paused","id","onStart","onUpdate","onComplete","onRepeat","onReverseComplete","scrollTrigger"]),a0=.5,nb="power1.inOut";function sb(t){return t.keyframes!==void 0&&t.keyframes!==null}function ib(t){const e=t.keyframes,n={};for(const[c,h]of Object.entries(t))eb.has(c)||(n[c]=h);if(Array.isArray(e))return e.map(c=>({...n,...c,duration:c.duration??t.duration??a0}));const s=Object.entries(e),i=t.duration??a0,o=e.easeEach??t.easeEach??nb;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 l0(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 M=b.getBoundingClientRect(),E=o?.getBoundingClientRect(),A=(v==="x"?s.offsetX:s.offsetY)??s.offset??0;return v==="x"?M.left-(E?.left??0)+r.x-A:M.top-(E?.top??0)+r.y-A},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 ob(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=>zr(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 ue{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 Je({...s,startValue:(i,o)=>{const r=e.objectFor(i);if(r)return lb(r[o]);const a=e.appliedValue(i,o);if(a!==void 0)return a;if(o==="d")return Ch(e.elementFor(i))??void 0;if(o==="text")return e.elementFor(i)?.textContent??void 0;if(o==="strokeDasharray"||o==="strokeDashoffset"){const l=f0(e.elementFor(i));if(l!==void 0)return o==="strokeDasharray"?[l,l]:0}},startVelocity:(i,o)=>e.velocityOf(i,o),layoutColumns:i=>d0(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=zr(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 sb(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 ue(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}=cr(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=ib(n);if(o.length===0)return;const r=i.length>1?xr(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?Qs(i.length,r).map(m=>m/1e3):[0],h=this.compat.timeOf(s)/1e3+bi(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,([M],E,A)=>this.compat.to(E,M,A)),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:()=>d0(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(ab)||e.some(d=>this.stage.objectFor(d)!==void 0)))){const d=this.targetFor(e[0]);i(n.map(f=>this.prepare(u0(f,0,d,this.stage.utils,o),e)),e,s);return}const a=n.length-1,{stagger:l,...c}=n[a],h=xr(l,this.staggerContext(e)),u=h?Qs(e.length,h).map(d=>d/1e3):e.map(()=>0);e.forEach((d,f)=>{const p=f===0?bi(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(u0(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=wy(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=ky(e.morphSVG,i,s),{morphSVG:a,...l}=o;o=r?{...o,morphSVG:r}:l}if(e.drawSVG!==void 0){const r=f0(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=K1(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 ${cb(e)}`);return}return this.firstElement??=n.map(s=>this.stage.elementFor(s)).find(s=>s!==void 0),n}}function c0(t=new $h){const e=o=>{const{config:r}=yi(o);return new ue(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)??Th(r)},scrollTrigger:o=>s(zr(t,o)),scrollBatch:(o,r)=>ob(t,o,r).map(a=>s(a)),scrollTo:(o,r)=>l0(i,t,o,r),refreshScroll:()=>{ps.refreshAll(),Wr.refreshAll()},smoothScroll:(o={})=>{const r=typeof o.scroller=="string"?(t.collector?.scope??t.root).querySelector(o.scroller):o.scroller;return s(new Wr({...o,scroller:r}).start())},context:(o,r)=>{const a=new n0(t,r);return o&&a.add(()=>o(a)),a},matchMedia:o=>new Uy(t,o),customEase:i0.create,customBounce:o0.create,customWiggle:r0.create,pageTransition:o=>Qy(i,t,r=>new ue(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 Vy(a,r))},quickTo:(o,r,a={})=>{const l=new ue(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:rb(a.spring,r,d)}}),l.timeline.stop(),l.timeline.play(),t.activate(l.timeline)},{tween:l,kill:()=>l.kill()})},timeline:o=>new ue(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 l0(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 ue(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=>My(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(Iy(l,r))},draggable:(o,r)=>s(Ey(i,t,o,r)),getFlipState:o=>Or(t,o),flipFrom:(o,r)=>Cr(t,a=>new ue(t,a),o,r),flip:(o,r,a)=>{const l=Or(t,o);return r(),Cr(t,c=>new ue(t,c),l,{targets:o,...a})}};return i}const Kt=c0();function rb(t,e,n){return t===!0?{velocity:{[e]:n}}:typeof t=="string"?{preset:t,velocity:{[e]:n}}:{...t,velocity:{[e]:n}}}function ab(t){return t.morphSVG!==void 0||t.drawSVG!==void 0||t.text!==void 0||t.scrambleText!==void 0||h0(t)}function h0(t){return Object.entries(t).some(([e,n])=>(typeof n=="function"||Mh(n))&&!Tr.has(e))}function u0(t,e,n,s,i){if(!h0(t))return t;const o={};for(const[r,a]of Object.entries(t))Tr.has(r)?o[r]=a:typeof a=="function"?o[r]=a(e,n,i):Mh(a)?o[r]=s.resolveRandomString(a):o[r]=a;return o}function d0(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 f0(t){const e=t;if(typeof e?.getTotalLength=="function")return e.getTotalLength()}function lb(t){if(typeof t=="number"||typeof t=="string"||Array.isArray(t)&&t.every(e=>typeof e=="number"))return t}function cb(t){return typeof t=="string"?`"${t}"`:String(t)}class qr{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 g0(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 vi{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 Ze}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=wn({...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 qr(s)})})}syncAllMedia(e,n){for(const s of this.mediaTargets)g0(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 Ze;s.querySelectorAll("[data-tinyfly]").forEach(a=>{const l=a.getAttribute("data-tinyfly");l&&r.registerTarget(l,a)}),this.symbolInstances.push({adapter:r,timeline:wn(o.timeline)})})}attachMedia(e,n){this.mediaSync=new qr(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}=cr(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 hb(t,e,n={}){const s=new vi(t,{...n,autoplay:!0});return await s.load(e),s}function ub(t,e={}){return new vi(t,e)}const p0={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"},m0="tinyfly-controls-style",db=`
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 py=0;function my(t){if(t.getElementById(Vh))return;const e=t.createElement("style");e.id=Vh,e.textContent=gy,t.head.appendChild(e)}function Jh(t,e,n={}){const s=e.ownerDocument;my(s);const i={...Uh,...n.labels},o=n.speeds??[.5,1,2],r=()=>t.markers.length>0,a=()=>t.markers.some(D=>D.label!==void 0||t.caption(D.id)!==void 0),l=s.createElement("div");l.className="tf-ctl";const c=s.createElement("div");c.className="tf-ctl-bar",c.setAttribute("role","group");const h=(D,q,X,J="")=>{const j=s.createElement("button");return j.type="button",j.className=`tf-ctl-btn ${J}`.trim(),j.setAttribute("aria-label",D),j.title=D,j.textContent=q,j.addEventListener("click",X),j},d=h(i.restart,"⟲",()=>{t.pause(),t.seek(0)}),u=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 S=s.createElement("select");S.className="tf-ctl-speed",S.setAttribute("aria-label",i.speed);for(const D of o){const q=s.createElement("option");q.value=String(D),q.textContent=`${D}×`,D===1&&(q.selected=!0),S.appendChild(q)}S.addEventListener("change",()=>t.setSpeed(Number(S.value))),c.append(d,u,f,p,m,w),o.length>0&&c.append(S),l.append(c);const k=n.fullscreen?ky(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 E=s.createElement("div");E.className="tf-ctl-question",E.hidden=!0;const x=s.createElement("span"),$=h(i.reveal,i.reveal,()=>t.play(),"tf-ctl-primary");E.append(x,$),l.append(E);const M=yy(t,s,i.scenario,n.scenarioControl??"buttons");M&&l.append(M.element);const v=n.mount;v?v.appendChild(l):e.insertAdjacentElement("afterend",l);const T=()=>{const D=t.isPlaying;f.textContent=D?"❚❚":"▶",f.setAttribute("aria-label",D?i.pause:i.play),f.title=D?i.pause:i.play;const q=t.duration;s.activeElement!==m&&(m.value=String(q>0?Math.round(t.currentTime/q*1e3):0));const X=t.markers;if(u.hidden=p.hidden=w.hidden=X.length===0,X.length>0){const J=t.currentMarker,j=J?X.indexOf(J)+1:0;w.textContent=i.stepFormat.replace("{index}",String(j)).replace("{total}",String(X.length)),w.setAttribute("aria-label",`${i.step} ${j} ${i.of} ${X.length}`),u.disabled=t.currentTime<=.5,p.disabled=t.currentTime>=q-.5;const A=t.caption()??"";y.textContent!==A&&(y.textContent=A),y.hidden=!a();const R=!D&&J?.question!==void 0&&Math.abs(t.currentTime-J.time)<1;E.hidden=!R,R&&x.textContent!==J.question&&(x.textContent=J.question)}else E.hidden=!0,y.hidden=!0;M?.update()},I=t.subscribe(T);T();const O=n.keyboardScope??e;!O.hasAttribute("tabindex")&&O.tabIndex<0&&(O.tabIndex=0);const _=new WeakSet,C=D=>{if(_.has(D)||(_.add(D),D.defaultPrevented||D.altKey||D.ctrlKey||D.metaKey))return;const q=D.target;if(!(q.tagName==="INPUT"||q.tagName==="SELECT")&&!(D.key===" "&&q.tagName==="BUTTON"))switch(D.key){case" ":D.preventDefault(),t.isPlaying?t.pause():g();break;case"ArrowRight":if(!r())return;D.preventDefault(),t.next();break;case"ArrowLeft":if(!r())return;D.preventDefault(),t.prev();break;case"Home":D.preventDefault(),t.pause(),t.seek(0);break;case"f":case"F":if(!k)return;D.preventDefault(),k.active?k.exit():k.enter();break}};return O.addEventListener("keydown",C),l.addEventListener("keydown",C),{element:l,fullscreen:k&&{get active(){return k.active},enter:k.enter,exit:k.exit},destroy(){k?.destroy(),I(),O.removeEventListener("keydown",C),l.removeEventListener("keydown",C),l.remove()}}}function yy(t,e,n,s){const i=t.scenarios;if(i.length<2)return;if(s==="slider"){const h=e.createElement("div");h.className="tf-ctl-choice-slider";const d=e.createElement("span");d.textContent=n,d.setAttribute("aria-hidden","true");const u=e.createElement("input");u.type="range",u.min="0",u.max=String(i.length-1),u.step="1",u.setAttribute("aria-label",n);const f=e.createElement("output");return f.setAttribute("aria-hidden","true"),u.addEventListener("input",()=>{const g=i[Number(u.value)];g&&t.setScenario(g.id)}),h.append(d,u,f),{element:h,update:()=>{const g=Math.max(0,i.findIndex(w=>w.id===t.scenario));e.activeElement!==u&&(u.value=String(g));const m=i[g].label;f.textContent!==m&&(f.textContent=m),u.setAttribute("aria-valuetext",m)}}}const o=e.createElement("fieldset");o.className="tf-ctl-choices";const r=e.createElement("legend");r.textContent=n,o.append(r);const a=`tf-ctl-scenario-${++py}`,l=i.map(h=>{const d=e.createElement("label");d.className="tf-ctl-choice";const u=e.createElement("input");u.type="radio",u.name=a,u.value=h.id,u.addEventListener("change",()=>{u.checked&&t.setScenario(h.id)});const f=e.createElement("span");return f.textContent=h.label,d.append(u,f),o.append(d),u});return{element:o,update:()=>{for(const h of l){const d=h.value===t.scenario;h.checked!==d&&(h.checked=d)}}}}const by='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',wy='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';function ky(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?wy:by;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()},d=g=>{g.key==="Escape"&&p()},u=()=>{r="overlay",a=e.documentElement.style.overflow,e.documentElement.style.overflow="hidden",e.addEventListener("keydown",d),l()};async function f(){if(r)return;const 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{}u()}async function p(){if(r==="overlay")e.removeEventListener("keydown",d),e.documentElement.style.overflow=a,r=void 0,l();else if(r==="native"){r=void 0,l();const 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 Zh="tinyfly-choices-style",vy=`
50
+ `;let fb=0;function gb(t){if(t.getElementById(m0))return;const e=t.createElement("style");e.id=m0,e.textContent=db,t.head.appendChild(e)}function y0(t,e,n={}){const s=e.ownerDocument;gb(s);const i={...p0,...n.labels},o=n.speeds??[.5,1,2],r=()=>t.markers.length>0,a=()=>t.markers.some(F=>F.label!==void 0||t.caption(F.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=(F,z,X,J="")=>{const K=s.createElement("button");return K.type="button",K.className=`tf-ctl-btn ${J}`.trim(),K.setAttribute("aria-label",F),K.title=F,K.textContent=z,K.addEventListener("click",X),K},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 F of o){const z=s.createElement("option");z.value=String(F),z.textContent=`${F}×`,F===1&&(z.selected=!0),v.appendChild(z)}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?bb(e,s,i):void 0;k&&c.append(k.button);const b=s.createElement("p");b.className="tf-ctl-caption",b.setAttribute("aria-live","polite"),n.captions!==!1&&l.append(b);const M=s.createElement("div");M.className="tf-ctl-question",M.hidden=!0;const E=s.createElement("span"),A=h(i.reveal,i.reveal,()=>t.play(),"tf-ctl-primary");M.append(E,A),l.append(M);const T=pb(t,s,i.scenario,n.scenarioControl??"buttons");T&&l.append(T.element);const S=n.mount;S?S.appendChild(l):e.insertAdjacentElement("afterend",l);const x=()=>{const F=t.isPlaying;f.textContent=F?"❚❚":"▶",f.setAttribute("aria-label",F?i.pause:i.play),f.title=F?i.pause:i.play;const z=t.duration;s.activeElement!==m&&(m.value=String(z>0?Math.round(t.currentTime/z*1e3):0));const X=t.markers;if(d.hidden=p.hidden=w.hidden=X.length===0,X.length>0){const J=t.currentMarker,K=J?X.indexOf(J)+1:0;w.textContent=i.stepFormat.replace("{index}",String(K)).replace("{total}",String(X.length)),w.setAttribute("aria-label",`${i.step} ${K} ${i.of} ${X.length}`),d.disabled=t.currentTime<=.5,p.disabled=t.currentTime>=z-.5;const P=t.caption()??"";b.textContent!==P&&(b.textContent=P),b.hidden=!a();const R=!F&&J?.question!==void 0&&Math.abs(t.currentTime-J.time)<1;M.hidden=!R,R&&E.textContent!==J.question&&(E.textContent=J.question)}else M.hidden=!0,b.hidden=!0;T?.update()},O=t.subscribe(x);x();const I=n.keyboardScope??e;!I.hasAttribute("tabindex")&&I.tabIndex<0&&(I.tabIndex=0);const _=new WeakSet,C=F=>{if(_.has(F)||(_.add(F),F.defaultPrevented||F.altKey||F.ctrlKey||F.metaKey))return;const z=F.target;if(!(z.tagName==="INPUT"||z.tagName==="SELECT")&&!(F.key===" "&&z.tagName==="BUTTON"))switch(F.key){case" ":F.preventDefault(),t.isPlaying?t.pause():g();break;case"ArrowRight":if(!r())return;F.preventDefault(),t.next();break;case"ArrowLeft":if(!r())return;F.preventDefault(),t.prev();break;case"Home":F.preventDefault(),t.pause(),t.seek(0);break;case"f":case"F":if(!k)return;F.preventDefault(),k.active?k.exit():k.enter();break}};return I.addEventListener("keydown",C),l.addEventListener("keydown",C),{element:l,fullscreen:k&&{get active(){return k.active},enter:k.enter,exit:k.exit},destroy(){k?.destroy(),O(),I.removeEventListener("keydown",C),l.removeEventListener("keydown",C),l.remove()}}}function pb(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-${++fb}`,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 mb='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',yb='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';function bb(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?yb:mb;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 b0="tinyfly-choices-style",wb=`
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 My(t){if(t.getElementById(Zh))return;const e=t.createElement("style");e.id=Zh,e.textContent=vy,t.head.appendChild(e)}function Qh(t,e){const n=Array.from(e.querySelectorAll("[data-tinyfly-choose]"));if(n.length===0)return()=>{};My(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 d=t.scenarios.find(p=>p.id===l)?.label;d!==void 0&&h("aria-label",d),a.setAttribute("aria-pressed","false"),c.push("aria-pressed"),s.push({element:a,attributes:c});const u=()=>t.setScenario(l),f=p=>{const g=p.key;g!=="Enter"&&g!==" "||(p.preventDefault(),u())};a.addEventListener("click",u),a.addEventListener("keydown",f),i.push(()=>{a.removeEventListener("click",u),a.removeEventListener("keydown",f)})}const o=()=>{for(const{element:a}of s)a.setAttribute("aria-pressed",String(a.getAttribute("data-tinyfly-choose")===t.scenario))},r=t.subscribe(o);return o(),()=>{r();for(const a of i)a();for(const{element:a,attributes:l}of s)for(const c of l)a.removeAttribute(c)}}const mi=new WeakMap,Or=new WeakMap;let Sy=0;function ds(t,e,n){if(t)try{return JSON.parse(t)}catch(s){console.warn(`tinyfly: invalid ${e} JSON on`,n,s);return}}async function t0(t,e={}){const n=mi.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=Ey(t.getAttribute("data-markers")),a=s.length>1||i?.hasAttribute("data-scenario")?Ty(s,r,t):void 0;if(a&&a.length===0)return;let l=i&&!a?ds(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=e0(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=ds(t.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",t),h={playWhenVisible:!0,...e.player,...c&&{captions:c},...ds(t.getAttribute("data-options"),"data-options",t)};xy(t);const d=new pi(t,h),u={element:t,player:d};if(mi.set(t,u),t.setAttribute("data-tinyfly-mounted",""),a){const f=t.getAttribute("data-scenario")??void 0;await d.loadScenarios(a,{initial:a.some(p=>p.id===f)?f:void 0}),Or.set(t,Qh(d,t))}else await d.load(l??o);if(t.getAttribute("data-controls")!=="false"){const f=ds(t.getAttribute("data-labels"),"data-labels",t),p=t.querySelector("figcaption"),g=t.getAttribute("data-scenario-legend"),m=t.getAttribute("data-scenario-control");u.controls=Jh(d,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(u.controls.element,p):t.appendChild(u.controls.element)}return u}function Ty(t,e,n){const s=[];return t.forEach((i,o)=>{const r=ds(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?e0(r,e):r})}),s}function e0(t,e){return t.config.markers?.length?t:{...t,config:{...t.config,markers:e.map((n,s)=>({id:`step-${s+1}`,time:n}))}}}function Ey(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 n0(t=document,e={}){const n=Array.from(t.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(n.map(i=>t0(i,e)))).filter(i=>i!==void 0)}function Ay(t){const e=mi.get(t);e&&(Or.get(t)?.(),Or.delete(t),e.controls?.destroy(),e.player.destroy(),mi.delete(t),t.removeAttribute("data-tinyfly-mounted"))}function xy(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-${++Sy}`,e.setAttribute("aria-labelledby",s.id))}function $y(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const e=()=>{n0()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}class s0{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 Je,this.adapterB=new Je}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 Je;i.querySelectorAll("[data-tinyfly]").forEach(l=>{const c=l.getAttribute("data-tinyfly");c&&a.registerTarget(c,l)}),s.push({adapter:a,timeline:yn(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?yn(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 Py(t,e,n={}){const s=new s0(t,{...n,autoplay:!0});return await s.load(e),s}const Iy={type:"none",duration:0},xt=t=>({description:t,unit:"degrees"}),St=(t,e=0,n=1)=>({description:t,unit:`${e}..${n}`,min:e,max:n}),i0={lean:xt("Upper body tipped about the hips (+ toward the way it faces)"),bend:xt("Line of action: the spine curved (+ curls forward, − arches back)"),headTilt:xt("Head tilt"),leftShoulder:xt("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:xt("Right upper arm: 0 hangs down, 90 straight out (forward, in profile), 180 straight up"),leftElbow:xt("Left elbow bend, added to the upper arm"),rightElbow:xt("Right elbow bend, added to the upper arm"),leftHip:xt("Left thigh: 0 straight down; in profile negative is forward"),rightHip:xt("Right thigh: 0 straight down; in profile positive is forward"),leftKnee:xt("Left knee bend (negative folds the shin back)"),rightKnee:xt("Right knee bend (positive folds the shin back)"),leftWrist:xt("Left wrist bend, added to the forearm"),rightWrist:xt("Right wrist bend, added to the forearm"),leftAnkle:xt("Left ankle: + points the toe down (tiptoe), − onto the heel"),rightAnkle:xt("Right ankle: + points the toe down (tiptoe), − onto the heel"),leftFootOut:St("Left foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),rightFootOut:St("Right foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),mouth:St("Mouth open: 0 closed, 1 wide open"),smile:St("−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:St("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:St("Left eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),rightBrow:St("Right eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),browTilt:St("Eyebrow slant: −1 angry, 1 worried",-1,1),lookX:St("Eyes look across: + the way it faces",-1,1),lookY:St("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:St("0 front-on, 1 in profile, turned the way it faces"),sit:St("0 standing, 1 seated"),spin:xt("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"}},o0={walk:{description:"Walk-cycle phase, in strides: animate 0 → n for n strides",unit:"strides"},walking:St("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:St("How much the mouth chatters"),rubber:St("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:St("How much of the dance is applied")},r0={"thumb.curl":St("Thumb curled in"),"thumb.across":St("Thumb across the palm"),"index.curl":St("Index finger curled"),"middle.curl":St("Middle finger curled"),"ring.curl":St("Ring finger curled"),"pinky.curl":St("Little finger curled"),spread:St("Fingers spread apart"),turn:xt("Hand turned about the forearm"),bend:xt("Hand bent at the wrist, palm-ward"),tilt:xt("Hand tilted sideways"),roll:xt("Hand rolled to show the back or the palm")};let a0;function Oy(t){a0=t}function _y(t){return a0?.(t)??{}}function l0(t){let e=0;for(let n=1;n<t.length;n++)e+=Math.hypot(t[n].x-t[n-1].x,t[n].y-t[n-1].y);return e}function En(t,e){const n=Math.min(1,Math.max(0,e));if(t.length<2||n===1)return t.slice();if(n===0)return t.slice(0,1);let s=l0(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 yi(t,e){const n=En(t,e);return n[n.length-1]}function _r(t,e){return e>0?Math.floor(Math.max(0,t)*e/1e3):0}function bi(t,e,n){const s=e.roughness??2,i=Math.max(1,Math.round(e.passes??2)),o=_r(n,e.boil??8);let r=0;const a=()=>{const u=r++;return f=>$e(Gt(`${e.seed??1}:${o}:${u}:${f}`))},l=(u,f)=>(u.next()*2-1)*f,c=u=>{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,u(f(m));t.lineWidth=p,t.globalAlpha=g},h=(u,f=1)=>{if(u.length<2)return;const p=u.slice(1).map((m,w)=>Math.hypot(m.x-u[w].x,m.y-u[w].y)),g=p.reduce((m,w)=>m+w,0)*Math.min(1,Math.max(0,f));c(m=>{const w=[],S=[];if(u.forEach((y,E)=>{w.push({x:y.x+l(m,s*.5),y:y.y+l(m,s*.5)}),E>0&&S.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 E=Cy(w[y-1],w[y],s,S[y-1]),x=p[y-1];if(k+x<=g){t.bezierCurveTo(E[1].x,E[1].y,E[2].x,E[2].y,E[3].x,E[3].y),k+=x;continue}const $=Hy(E,x===0?1:(g-k)/x);t.bezierCurveTo($[1].x,$[1].y,$[2].x,$[2].y,$[3].x,$[3].y);break}t.stroke()})},d=(u,f,p,g,m=1)=>{c(w=>{const k=w.next()*Math.PI*2,y=Math.PI*2+.15+w.next()*.3,E=[];for(let $=0;$<=14;$++){const M=k+y*$/14,v=l(w,s*.6);E.push({x:u+Math.cos(M)*(p+v),y:f+Math.sin(M)*(g+v)})}const x=En(E,m);x.length<2||(c0(t,x),t.stroke())})};return{line:h,curve(u,f=1){if(u.length<2)return;const p=u[0],g=u[u.length-1],m=Math.hypot(g.x-p.x,g.y-p.y)||1,w=-(g.y-p.y)/m,S=(g.x-p.x)/m;c(k=>{const y={x:l(k,s*.5),y:l(k,s*.5)},E={x:l(k,s*.5),y:l(k,s*.5)},x=l(k,s*Math.min(1.5,Math.max(.3,m/80))),$=u.map((v,T)=>{const I=T/(u.length-1),O=Math.sin(Math.PI*I)*x;return{x:v.x+y.x+(E.x-y.x)*I+w*O,y:v.y+y.y+(E.y-y.y)*I+S*O}}),M=En($,f);M.length<2||(c0(t,M),t.stroke())})},circle(u,f,p,g=1){d(u,f,p,p,g)},ellipse:d,nudge(u=.5){const f=a()(0);return{x:l(f,s*u),y:l(f,s*u)}}}}function Cy(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 Hy([t,e,n,s],i){const o=(d,u)=>({x:d.x+(u.x-d.x)*i,y:d.y+(u.y-d.y)*i}),r=o(t,e),a=o(e,n),l=o(n,s),c=o(r,a),h=o(a,l);return[t,r,c,o(c,h)]}function c0(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 Nt(t,e,n){const s=t.length;if(s<2)return[];const i=[],o=[],r=a=>e+(n-e)*a/(s-1);return t.forEach((a,l)=>{const c=t[Math.max(0,l-1)],h=t[Math.min(s-1,l+1)],d=Math.hypot(h.x-c.x,h.y-c.y)||1,u=r(l)/2,f=-(h.y-c.y)/d*u,p=(h.x-c.x)/d*u;i.push({x:a.x+f,y:a.y+p}),o.push({x:a.x-f,y:a.y-p})}),[...i,...o.reverse()]}function wi(t,e,n,s){const i=e.length;if(i<2)return;const o=Nt(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 Ze(t,e,n,s,i=16){const o={x:2*e.x-(t.x+n.x)/2,y:2*e.y-(t.y+n.y)/2},r=[];for(let a=0;a<=i;a++){const l=a/i,c=l<.5?{x:t.x+(e.x-t.x)*2*l,y:t.y+(e.y-t.y)*2*l}:{x:e.x+(n.x-e.x)*(2*l-1),y:e.y+(n.y-e.y)*(2*l-1)},h=1-l,d={x:h*h*t.x+2*h*l*o.x+l*l*n.x,y:h*h*t.y+2*h*l*o.y+l*l*n.y};r.push({x:c.x+(d.x-c.x)*s,y:c.y+(d.y-c.y)*s})}return r}function Cr(t,e,n,s,i,o=0,r=1,a=40){const l=Math.cos(i),c=Math.sin(i);return Array.from({length:a+1},(h,d)=>{const u=o+Math.PI*2*r*d/a,f=Math.cos(u)*n,p=Math.sin(u)*s;return{x:t+f*l-p*c,y:e+f*c+p*l}})}function us(t,e){return e.look==="pencil"?Dy(t,e):Ry(t,e.ink,e.look)}function ki(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 Ry(t,e,n){const s=n==="silhouette",i=s?1.25:1;return{look:n,ink:e,limb(o,r,a){t.fillStyle=e,wi(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",ki(t,o),t.stroke())},shape(o,r,a){ki(t,o,!0),(r!==null||s)&&(t.fillStyle=s?e:r,t.fill()),!(a<=0)&&(t.strokeStyle=e,t.lineWidth=a*i,t.lineJoin="round",t.stroke())},ellipse(o,r,a,l,c,h,d){t.beginPath(),t.ellipse(o,r,a,l,c,0,Math.PI*2),(h!==null||s)&&(t.fillStyle=s?e:h,t.fill()),!(d<=0)&&(t.strokeStyle=e,t.lineWidth=d*i,t.stroke())},dot(o,r,a){t.fillStyle=e,t.beginPath(),t.arc(o,r,a*i,0,Math.PI*2),t.fill()},guide(){},guideEllipse(){}}}function Ly(t,e){const n=[t[0]];let s=0;for(let r=1;r<t.length;r++){const a=t[r-1],l=t[r],c=Math.hypot(l.x-a.x,l.y-a.y);let h=e-s;for(;h<c;){const d=h/c;n.push({x:a.x+(l.x-a.x)*d,y:a.y+(l.y-a.y)*d}),h+=e}s=c-(h-e)}const i=t[t.length-1],o=n[n.length-1];return Math.hypot(i.x-o.x,i.y-o.y)>e*.25?n.push(i):n[n.length-1]=i,n}function Ny(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 h0(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 Dy(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=_r(e.time,n.boil??8);let c=0;const h=(p,g,m=!1)=>$e(Gt(`${e.seed}:${m?"paper":l}:${p}:${g}`)),d=(p,g,m,w,S,k=0)=>{if(p.length<2)return;const y=p.slice(1).reduce((I,O,_)=>I+Math.hypot(O.x-p[_].x,O.y-p[_].y),0);let E=Ly(p,Math.max(1.5,Math.min(e.lineWidth*.8,y/24)));if(k>0&&E.length>=2){const[I,O]=[E[E.length-2],E[E.length-1]],_=Math.hypot(O.x-I.x,O.y-I.y)||1;E=[...E,{x:O.x+(O.x-I.x)/_*k,y:O.y+(O.y-I.y)/_*k}]}const x=h0(m),$=h0(m),M=E.length,v=[],T=[];E.forEach((I,O)=>{const _=M===1?0:O/(M-1),C=E[Math.max(0,O-1)],D=E[Math.min(M-1,O+1)],q=Math.hypot(D.x-C.x,D.y-C.y)||1,X=-(D.y-C.y)/q,J=(D.x-C.x)/q,j=x(_)*S,A=Math.min(1,_/.08,(1-_)/.08),R=(.55+.45*Math.sqrt(Math.max(0,A)))*(1+r*$(_)),N=Math.max(.3,g(_)*R/2),P=I.x+X*j,L=I.y+J*j;v.push({x:P+X*N,y:L+J*N}),T.push({x:P-X*N,y:L-J*N})}),t.save(),t.globalAlpha*=w,t.fillStyle=s,ki(t,[...v,...T.reverse()],!0),t.fill(),t.restore()},u=(p,g)=>{const m=c++,w=h(m,99,!0);if(w.next()<a){const E=(w.next()*2-1)*e.lineWidth*1.4,x=(w.next()*2-1)*e.lineWidth*1.4,$=p.map(M=>({x:M.x+E,y:M.y+x}));d($,M=>g(M)*1.8,h(m,98,!0),.035,i),d($,M=>g(M)*.45,h(m,97,!0),.12,i*1.5)}const S=p.slice(1).reduce((E,x,$)=>E+Math.hypot(x.x-p[$].x,x.y-p[$].y),0),k=g(.5)>4&&S>g(.5)*6,y=k?[-.3,.3,0]:[0];for(let E=0;E<o;E++){const x=E===0;y.forEach(($,M)=>{const v=h(m,E*10+M),T=$===0?p:Ny(p,O=>g(O)*$*Math.sqrt(Math.sin(Math.PI*O))),I=!x&&$===0?e.lineWidth*(.3+v.next()*.8):0;d(T,O=>g(O)*(k?.5:1)*(x?1:.6),v,x?.85:.45,i*(x?.6:1),I)})}},f=(p,g,m,w,S,k)=>{const E=h(c,50).next()*Math.PI*2;u(Cr(p,g,m,w,S,E,1.08,48),()=>k)};return{look:"pencil",ink:s,limb(p,g,m){u(p,w=>g+(m-g)*w)},line(p,g){u(p,()=>g)},shape(p,g,m){g!==null&&(t.save(),t.globalAlpha*=.88,t.fillStyle=g,ki(t,p,!0),t.fill(),t.restore()),m>0&&u([...p,p[0]],()=>m)},ellipse(p,g,m,w,S,k,y){k!==null&&(t.save(),t.globalAlpha*=.9,t.fillStyle=k,t.beginPath(),t.ellipse(p,g,m,w,S,0,Math.PI*2),t.fill(),t.restore()),f(p,g,m,w,S,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++;d(p,()=>Math.max(.6,e.lineWidth*.18),h(g,0),.28,i*1.2,e.lineWidth)},guideEllipse(p,g,m,w,S){if(n.construction===!1)return;const k=c++,y=h(k,0),E=Cr(p,g,m,w,S,y.next()*Math.PI*2,1.12,48);d(E,()=>Math.max(.6,e.lineWidth*.18),y,.28,i*1.5)}}}const d0=["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 It(t={}){return{...Pt,...t}}const zt=(t,e,n,s,i)=>({"thumb.curl":t,"index.curl":e,"middle.curl":n,"ring.curl":s,"pinky.curl":i}),_t={relaxed:Pt,open:It({...zt(0,0,0,0,0),"thumb.across":0,spread:.55}),spread:It({...zt(0,0,0,0,0),"thumb.across":0,spread:1}),flat:It({...zt(0,0,0,0,0),"thumb.across":.35,spread:0}),fist:It({...zt(.7,1,1,1,1),"thumb.across":.9,spread:0}),point:It({...zt(.75,0,1,1,1),"thumb.across":.9,spread:0}),thumbsUp:It({...zt(0,1,1,1,1),"thumb.across":0,spread:0,roll:70}),peace:It({...zt(.75,0,0,1,1),"thumb.across":.9,spread:1}),ok:It({...zt(.12,.6,.1,.15,.2),"thumb.across":.55,spread:.6}),pinch:It({...zt(.1,.65,.75,.85,.9),"thumb.across":.55,spread:0}),cupped:It({...zt(.25,.4,.4,.4,.4),"thumb.across":.4,spread:.05,turn:2}),wave:It({...zt(0,.05,.05,.1,.12),"thumb.across":0,spread:.7,turn:2}),pencilGrip:It({...zt(.1,.6,.72,.88,.95),"thumb.across":.5,spread:0,turn:.8,bend:10}),hold:It({...zt(.5,.7,.72,.74,.76),"thumb.across":.75,spread:0,turn:1})};function An(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 Fy={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}},Wy={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}},ge={base:[-.11,.1,-.05],bones:[.2,.15,.12],widths:[.2,.145,.135],out:[-.7,.68,-.22],across:[.35,.5,-.8]},By=[82,100,62],qy=[48,72],zy=3,Yy=13,Ky=.035,jy=-.075,Xy=[[-.17,0],[-.215,.12],[-.235,.26],[-.225,.4],[-.185,.49],[-.075,.525],[.05,.51],[.16,.465],[.215,.4],[.225,.26],[.2,.1],[.16,0]],Ie=t=>t*Math.PI/180,Hr=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],vi=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],Rr=(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]],fs=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function Oe(t,e,n){const s=Math.cos(n),i=Math.sin(n),o=Rr(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 u0=[1,0,0],f0=[0,1,0],gs=[0,0,1];function Gy(t,e,n){const s=Ie(t.fan*(zy+Yy*n)),i=[Math.sin(s),Math.cos(s),0],o=[Math.cos(s),-Math.sin(s),0],r=[t.knuckle];let a=0;t.bones.forEach((h,d)=>{a+=Ie(By[d]*e),r.push(Hr(r[d],vi(Oe(i,o,-a),h)))});const l=Oe(gs,o,-a),c=r.map((h,d)=>t.width*(1-.14*(d/(r.length-1))));return{joints:r,back:l,widths:c}}function Uy(t,e,n=1,s=1){const i=Math.min(1,Math.max(0,e)),o=fs(Hr(vi(fs(ge.out),1-i),vi(fs(ge.across),i))),r=fs(Rr(gs,o)),a=fs(Rr(o,r)),l=[[ge.base[0]*s,ge.base[1],ge.base[2]]];let c=0;ge.bones.forEach((u,f)=>{f>0&&(c+=Ie(qy[f-1]*t)),l.push(Hr(l[f],vi(Oe(o,r,c),u)))});const h=Oe(a,r,c),d=[...ge.widths,ge.widths[ge.widths.length-1]*.92].map(u=>u*n);return{joints:l,back:h,widths:d}}function Mi(t,e={}){const n={...Pt,...t},s=e.size??100,i=e.side??"right",o=i==="left"?-1:1,r=Ie(e.angle??0),a=e.fingers===4,l=Math.max(.5,e.plump??1),c=1+(l-1)*.7,h=O=>({...O,knuckle:[O.knuckle[0]*c,O.knuckle[1],O.knuckle[2]],width:O.width*l}),d=Ie(n.bend??0),u=Ie(n.tilt??0),f=Ie(90*(n.turn??0)),p=O=>Oe(Oe(Oe(O,u0,-d),gs,-u),f0,f),g=Math.cos(r),m=Math.sin(r),w=Ie(n.roll??0),S=Math.cos(w),k=Math.sin(w),y=O=>{const _=O[0]*s,C=-O[1]*s,D=(_*S-C*k)*o,q=_*k+C*S;return{x:D*g-q*m,y:D*m+q*g}},E=O=>{const _=y(O),C=Math.hypot(_.x,_.y);return C>1e-6*s?{x:_.x/C,y:_.y/C}:{x:0,y:0}},x={thumb:Uy(n["thumb.curl"]??0,n["thumb.across"]??0,l,c)},$=a?Wy:Fy;for(const O of d0){const _=$[O];_&&(x[O]=Gy(h(_),n[`${O}.curl`]??0,n.spread??0))}const M={};for(const[O,_]of Object.entries(x)){const C=_.joints.map(p),D=p(_.back);M[O]={points:C.map(y),depths:C.map(q=>q[2]*s),widths:_.widths.map(q=>q*s),nail:D[2],back:E(D)}}const v=Xy.flatMap(([O,_])=>[p([O*c,_,Ky]),p([O*c,_,jy])]),T=Vy(v.map(y)),I=v.reduce((O,_)=>O+_[2],0)/v.length*s;return{size:s,side:i,wrist:{x:0,y:0},palm:T,palmDepth:I,palmFacing:-p(gs)[2],fingers:M,axes:{up:E(p(f0)),across:E(p(u0)),out:E(p(gs))},curls:Object.fromEntries(Object.keys(M).map(O=>[O,n[`${O}.curl`]??0]))}}function g0(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 Vy(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 Jy="#f1c9a5",Zy="#2f2f33";function Si(t,e,n,s={},i=0){const o=g0(Mi(n,s),e),r=s.ink??Zy,a=s.lineWidth??o.size*.035,l=s.pen??us(t,{look:s.look??"clean",ink:r,lineWidth:a,seed:s.seed??1,time:i,pencil:{construction:!1,...s.pencil}}),c=s.skin??Jy,h=s.nails??!0,d=[{depth:o.palmDepth,draw:()=>Qy(l,o,c,a)}];for(const u of Object.values(o.fingers)){const f=u.depths.reduce((p,g)=>p+g,0)/u.depths.length;d.push({depth:f,draw:()=>tb(t,l,u,c,a,h)})}if(s.prop){const u=s.prop;d.push({depth:u.depth,draw:()=>u.draw(l)})}t.save(),t.lineCap="round",t.lineJoin="round";for(const u of[...d].sort((f,p)=>f.depth-p.depth))u.draw();return t.restore(),o}function Qy(t,e,n,s){if(t.shape(e.palm,n,s),e.palmFacing<-.3&&t.look!=="silhouette"){const{up:i}=e.axes;for(const[o,r]of Object.entries(e.fingers)){const a=e.curls[o]??0;if(o==="thumb"||a<.5)continue;const l=r.points[0],c=r.widths[0]*.42,h={x:l.x-i.x*c*.2,y:l.y-i.y*c*.2},d=Math.atan2(i.y,i.x),u=Array.from({length:7},(f,p)=>{const g=d-Math.PI/2+Math.PI*p/6;return{x:h.x+Math.cos(g)*c,y:h.y+Math.sin(g)*c}});t.line(u,s*.6)}}if(e.palmFacing>.45&&t.look!=="silhouette"){const{up:i,across:o}=e.axes,r=e.size,a=e.wrist,l=(h,d)=>({x:a.x+(o.x*h+i.x*d)*r,y:a.y+(o.y*h+i.y*d)*r}),c=e.side==="left"?-1:1;t.line([l(-.15*c,.36),l(-.04*c,.3),l(.1*c,.33)],s*.5)}}function tb(t,e,n,s,i,o){const{widths:r}=n,a=eb(n.points,2),l=n.points[0],c=a[a.length-1],h=r[0],d=r[r.length-1];if(t.save(),e.look!=="silhouette"){t.beginPath(),t.rect(l.x-1e5,l.y-1e5,2e5,2e5);const 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,d+2*i),t.restore(),e.look!=="silhouette"&&(t.fillStyle=s,wi(t,a,h,d)),e.look==="silhouette"||!o||n.nail<.25)return;const u=a[a.length-2],f=nb({x:c.x-u.x,y:c.y-u.y})??{x:0,y:-1},p={x:c.x-f.x*d*.22+n.back.x*d*.1,y:c.y-f.y*d*.22+n.back.y*d*.1};e.ellipse(p.x,p.y,d*.24*Math.max(.35,n.nail),d*.19,Math.atan2(f.y,f.x),"#f8e3d3",i*.45)}function eb(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 nb=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}},sb=40;function ps(t){return t===void 0?Dt.walk:typeof t=="string"?Dt[t]??Dt.walk:t}function p0(t,e,n=ct,s=1){const i=ps(t);if(i===Dt.walk)return k0(e,n,s);const o=e*Math.PI*2,r=Math.sin(o)*s,a=Math.cos(o)*s,l=w=>Math.abs(w)<=sb,c=i.shoulder??0,h=(w,S)=>l(w)?S*c+i.arm*r:w,d=i.forearm??0,u=l(n.leftShoulder)?n.leftElbow-d-i.elbow*Math.max(0,-r):n.leftElbow,f=l(n.rightShoulder)?n.rightElbow+d+i.elbow*Math.max(0,r):n.rightElbow,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:u,rightElbow:f,leftHip:-i.swing*r-m*.5,rightHip:-i.swing*r+m*.5,leftKnee:-i.knee*Math.max(0,a)-m,rightKnee:i.knee*Math.max(0,-a)+m,leftAnkle:(n.leftAnkle??0)+(i.tiptoe??0),rightAnkle:(n.rightAnkle??0)+(i.tiptoe??0),leftShoulder:h(n.leftShoulder,-1),rightShoulder:h(n.rightShoulder,1),rise:(n.rise??0)+(i.bounce??0)*s*g,stretch:n.stretch*(1+(i.squash??0)*(g-.5))}}function Ti(t,e,n=1){const s=ps(t),i=Dt.walk.swing,o=r=>Math.sin(r*Math.PI/180);return v0(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 Ct(t){return{...ct,...t}}const m0={mouth:0,smile:0,mouthWidth:1,leftEye:1,rightEye:1,leftBrow:0,rightBrow:0,browTilt:0,lookX:0,lookY:0},Rt=t=>({...m0,...t}),kt={neutral:m0,happy:Rt({smile:.9,leftBrow:.2,rightBrow:.2}),joyful:Rt({mouth:.6,smile:1,mouthWidth:1.2,leftEye:0,rightEye:0,leftBrow:.4,rightBrow:.4}),sad:Rt({smile:-.8,leftEye:.8,rightEye:.8,browTilt:.9,leftBrow:-.1,rightBrow:-.1,lookY:.6}),crying:Rt({mouth:.45,smile:-1,leftEye:0,rightEye:0,browTilt:1,lookY:.4}),surprised:Rt({mouth:.7,mouthWidth:.7,leftEye:1.5,rightEye:1.5,leftBrow:1,rightBrow:1}),shocked:Rt({mouth:1,mouthWidth:.8,leftEye:1.6,rightEye:1.6,leftBrow:1,rightBrow:1,browTilt:.4}),angry:Rt({smile:-.6,mouthWidth:.9,leftEye:.8,rightEye:.8,leftBrow:-.6,rightBrow:-.6,browTilt:-1}),furious:Rt({mouth:.5,smile:-1,mouthWidth:1.3,leftEye:.9,rightEye:.9,leftBrow:-.9,rightBrow:-.9,browTilt:-1}),worried:Rt({smile:-.3,mouthWidth:.8,leftEye:1.1,rightEye:1.1,leftBrow:.3,rightBrow:.3,browTilt:.8,lookX:-.5}),scared:Rt({mouth:.35,smile:-.5,mouthWidth:.8,leftEye:1.45,rightEye:1.45,leftBrow:.8,rightBrow:.8,browTilt:.9}),confused:Rt({smile:-.2,mouthWidth:.8,leftEye:.9,rightEye:1.15,leftBrow:-.3,rightBrow:.8,lookX:.5,lookY:-.4}),skeptical:Rt({smile:-.1,leftEye:.6,rightEye:1,leftBrow:-.4,rightBrow:.7,lookX:.4}),thinking:Rt({smile:0,mouthWidth:.7,leftBrow:.3,rightBrow:.5,lookX:.6,lookY:-.8}),sleepy:Rt({smile:.1,leftEye:.25,rightEye:.25,leftBrow:-.3,rightBrow:-.3,lookY:.5}),disgusted:Rt({smile:-.7,mouthWidth:.9,leftEye:.6,rightEye:.75,leftBrow:-.5,rightBrow:-.2,browTilt:-.4,lookX:-.6}),smug:Rt({smile:.6,mouthWidth:.9,leftEye:.6,rightEye:.6,leftBrow:.1,rightBrow:.5,lookX:.5}),wink:Rt({smile:.9,leftEye:0,rightEye:1,leftBrow:-.2,rightBrow:.3})};function _e(t,e){return{...t,...typeof e=="string"?kt[e]:e}}const Yt={rest:ct,wave:Ct({rightShoulder:135,rightElbow:30,headTilt:6,...kt.happy}),cheer:Ct({leftShoulder:125,leftElbow:20,rightShoulder:125,rightElbow:20,...kt.joyful}),shrug:Ct({leftShoulder:30,leftElbow:85,rightShoulder:30,rightElbow:85,headTilt:-10,...kt.confused,lookX:0,lookY:0}),point:Ct({rightShoulder:90,rightElbow:0,lean:4,smile:.4}),think:Ct({rightShoulder:60,rightElbow:150,headTilt:10,...kt.thinking}),handsOnHips:Ct({leftShoulder:45,leftElbow:-100,rightShoulder:45,rightElbow:-100,leftHip:14,rightHip:14,smile:.8}),sad:Ct({leftShoulder:14,rightShoulder:14,leftElbow:-4,rightElbow:-4,headTilt:-14,lean:-3,...kt.sad}),surprised:Ct({leftShoulder:70,leftElbow:60,rightShoulder:70,rightElbow:60,...kt.surprised}),crouch:Ct({stretch:.72,leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50,leftHip:22,rightHip:22,headTilt:-4}),sit:Ct({sit:1,turn:.5,leftShoulder:-25,rightShoulder:25,leftElbow:-55,rightElbow:55}),jump:Ct({stretch:1.22,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4,...kt.joyful}),duck:Ct({stretch:.62,bend:28,headTilt:-8,leftShoulder:150,rightShoulder:150,leftElbow:130,rightElbow:130,leftHip:25,rightHip:25,...kt.scared}),lie:Ct({spin:-90,rise:-.42,leftShoulder:165,rightShoulder:165,leftElbow:150,rightElbow:150,...kt.sleepy}),sideSplit:Ct({leftHip:90,rightHip:90,leftAnkle:-45,rightAnkle:-45,leftShoulder:120,rightShoulder:120,leftElbow:10,rightElbow:10,...kt.happy}),frontSplit:Ct({turn:1,leftHip:-90,rightHip:-90,leftAnkle:-45,rightAnkle:-45,leftShoulder:-150,rightShoulder:150,leftElbow:10,rightElbow:-10,...kt.happy})},y0=Object.keys(ct);function xn(t,e,n){const s={...t};for(const i of y0)s[i]=t[i]+(e[i]-t[i])*n;return s}const Lr=24,b0=4,w0=28,ib=40;function k0(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)<=ib,r=c=>o(c)?22*s:c,a=o(e.leftShoulder)?e.leftElbow-w0*Math.max(0,-s):e.leftElbow,l=o(e.rightShoulder)?e.rightElbow+w0*Math.max(0,s):e.rightElbow;return{...e,lean:e.lean+b0*n,headTilt:e.headTilt-b0*.5*n,leftElbow:a,rightElbow:l,leftHip:-Lr*s,rightHip:-Lr*s,leftKnee:-30*Math.max(0,i),rightKnee:30*Math.max(0,-i),leftShoulder:r(e.leftShoulder),rightShoulder:r(e.rightShoulder)}}function v0(t,e=1){return 4*((Nr+Ei)*t)*Math.sin(Lr*e*Math.PI/180)}function M0(t){const e=Math.abs(Math.sin(t/65)),n=.55+.45*Math.sin(t/310);return e*n}const S0=.12,T0=.46,ob=1-2*S0,rb=.1,ab=.21,lb=.19,Nr=.24,Ei=.22,E0=.12,cb=.14,A0=.33,x0=.7,$0=.3,hb=.35,db=[1.7,1.05],ub=[1.3,.75],P0=[1.45,.85],fb=[1.15,.75],I0=.06,gb=.7,pb=.65,O0=.075,mb=.3,yb=.02,bb=.012,wb=12,kb=.25,Ai=90,vb=.25,Mb=.04,_0=.01,Qe=t=>Math.min(1,Math.max(0,t??0));function Sb(t,e=1){return Ei*t*e}const Dr=-.12,C0=.4,Ut=t=>t*Math.PI/180,Tb=(t,e)=>({x:e*Math.sin(Ut(t)),y:Math.cos(Ut(t))}),H0=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),R0=(t,e,n,s)=>t-.3*e-n*.14*e-Math.max(0,s-1)*.12*e;function Eb(t,e,n,s,i,o){const r=Math.max(1,Math.min(o*.6,cb*n)),a=Qe(e.turn),l=(E0+A0*a)*n,c=s+Dr*n,h=l+e.lookX*.08*n,d=e.lookY*.07*n,u=[{x:-.34*n*(1-x0*a),squeeze:1-x0*a,open:e.leftEye,brow:e.leftBrow,side:-1},{x:.34*n*(1-$0*a),squeeze:1-$0*a,open:e.rightEye,brow:e.rightBrow,side:1}];t.fillStyle=i,t.strokeStyle=i,t.lineWidth=r;for(const w of u){const S=H0(w.open,e.blink);if(S<.2){const x=e.smile>.5?-.12*n:.06*n;t.beginPath(),t.moveTo(w.x+l-.12*n,c),t.quadraticCurveTo(w.x+l,c+x,w.x+l+.12*n,c),t.stroke()}else{if(S>1.2){const $=.13*n*S;t.beginPath(),t.ellipse(w.x+l,c,$*.85,$,0,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.stroke(),t.fillStyle=i}const x=S>1.2?.075*n:.1*n;t.beginPath(),t.ellipse(w.x+h,c+d,x,x*1.1*Math.min(S,1),0,0,Math.PI*2),t.fill()}const k=R0(c,n,w.brow,S),y=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(y,k-e.browTilt*.1*n),t.stroke()}const f=s+C0*n,p=.25*n*Math.max(.3,e.mouthWidth)*(1-hb*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 L0(t,e){const n=e.height??300,s=Math.min(3,Math.max(.3,t.stretch??1)),i=Math.sqrt(s),o=(e.headSize??2*S0)/2,r=e.headSize===void 0?ob:1-2*o,a=o*n,l=Qe(t.sit),c=t.leftHip+(-Ai-t.leftHip)*l,h=t.leftKnee+(-Ai-t.leftKnee)*l,d=t.rightHip+(Ai-t.rightHip)*l,u=t.rightKnee+(Ai-t.rightKnee)*l,f=e.classic===!0,p=Qe(t.turn),g=(J,j,A,R,N)=>{const P=Math.max(-Math.PI/2,Math.min(Math.PI/2,Math.abs(Ut(j-A)/2)+Ut(R))),L=Math.max(-1,Math.min(1,gb+N)),W=p+(1-p)*J*L;return f?{x:0,y:0}:{x:Math.cos(P)*I0*W,y:Math.sin(P)*I0}},m={left:t.leftAnkle??0,right:t.rightAnkle??0},w={left:t.leftFootOut??0,right:t.rightFootOut??0};let S=0;if(l>0||!f){const J=(N,P,L,W,z)=>Nr*Math.cos(Ut(P))+Ei*Math.cos(Ut(P-L))+Math.max(0,g(N,P,L,W,z).y),j=Math.max(J(-1,c,h,m.left,w.left),J(1,d,u,m.right,w.right)),A=1-Qe((t.rise??0)/Mb),R=(f?Math.min(1,l/vb):1)*A;S=(T0-j)*R*n*s}const k=-T0*n*s+S,y=-r*n*s+S,E=f?0:(yb*Qe(t.turn)+bb*l)*n*s,x=Ut(t.bend??0),$={end:D0(k,y,x,1),bend:x};let M;if(x!==0){M=[];for(let J=0;J<=N0;J++){const j=J/N0,A=D0(k,y,x,j);M.push({x:A.x-E*Math.sin(Math.PI*j),y:A.y})}}else M=E===0?[{x:0,y:k},{x:0,y}]:Ze({x:0,y:k},{x:-E,y:(k+y)/2},{x:0,y},1,8);const v=y+rb*n*s,T=(e.shoulderWidth??0)*n*Math.cos(p*Math.PI/2),I=(J,j,A,R,N)=>{const P=Tb(A,R);return{x:J+P.x*N*n,y:j+P.y*N*n}},O=(J,j,A)=>{const R=I(0,k,j,J,Nr*s);return{root:{x:0,y:k},joint:R,end:I(R.x,R.y,j-A,J,Ei*s)}},_=(J,j,A)=>{const R={x:J*T,y:v},N=I(R.x,R.y,j,J,ab*i);return{root:R,joint:N,end:I(N.x,N.y,j+A,J,lb*i)}},C={left:O(-1,c,h),right:O(1,d,u)},D=(J,j,A,R,N,P)=>{const L=g(J,A,R,N,P);return{x:j.end.x+L.x*n*s,y:j.end.y+L.y*n*s}},q=(J,j,A,R,N)=>I(j.end.x,j.end.y,A+R+N,J,O0*i),X={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(f?0:mb,e.rubber??0)),r:a,headRx:a/Math.sqrt(s),headRy:a*Math.sqrt(s),hipY:k,neckY:y,drop:S,lean:f?t.lean:t.lean+wb*Math.sin(Math.PI*l),classic:f,legs:C,toes:{left:D(-1,C.left,c,h,m.left,w.left),right:D(1,C.right,d,u,m.right,w.right)},spine:M,chest:$,arms:X,handTips:{left:q(-1,X.left,t.leftShoulder,t.leftElbow,t.leftWrist??0),right:q(1,X.right,t.rightShoulder,t.rightElbow,t.rightWrist??0)}}}const N0=10;function D0(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 Ab(t,e){if(t.chest.bend===0)return e;const n=ys(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 ms=(t,e)=>e===0?[t.root,t.joint,t.end]:Ze(t.root,t.joint,t.end,e);function ys(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 F0(t,e,n=!0){const s=$b(t,e),i=e.spin??0,o=e.rise??0;return n&&(i!==0||o!==0)?xb(s,t,i,o):s}function W0(t,e,n){return{pivot:{x:0,y:t.hipY},angle:t.facing*Ut(e),lift:n*t.height}}function xb(t,e,n,s){const{pivot:i,angle:o,lift:r}=W0(e,n,s),a=u=>{const f=ys(u,i,o);return{x:f.x,y:f.y-r}},l=u=>({left:a(u.left),right:a(u.right)}),c={left:Math.max(a(t.feet.left).y,a(t.toes.left).y),right:Math.max(a(t.feet.right).y,a(t.toes.right).y)},h=Math.max(c.left,c.right),d=_0*e.height;return{...t,hip:a(t.hip),neck:a(t.neck),shoulders:l(t.shoulders),elbows:l(t.elbows),hands:l(t.hands),fingertips:l(t.fingertips),knees:l(t.knees),feet:l(t.feet),toes:l(t.toes),feetY:h,grounded:{left:c.left>=h-d,right:c.right>=h-d},handAngle:{left:t.handAngle.left+o,right:t.handAngle.right+o},limbs:{leftArm:t.limbs.leftArm.map(a),rightArm:t.limbs.rightArm.map(a),leftLeg:t.limbs.leftLeg.map(a),rightLeg:t.limbs.rightLeg.map(a),spine:t.limbs.spine.map(a)},head:{...t.head,center:a(t.head.center),angle:t.head.angle+o}}}function $b(t,e){const n=Ut(t.lean),s=Ut(e.headTilt),i={x:0,y:t.hipY},o=y=>({x:t.facing*y.x,y:y.y}),r=y=>o(ys(y,i,n)),a=y=>r(Ab(t,y)),l=y=>a(ys({x:y.x,y:y.y+t.neckY},{x:0,y:t.neckY},s)),c=ms(t.arms.left,t.rubber).map(a),h=ms(t.arms.right,t.rubber).map(a),d=(y,E)=>Math.atan2(E.y-y.y,E.x-y.x),u={left:a(t.handTips.left),right:a(t.handTips.right)},f=(y,E)=>{const[x,$]=y.slice(-2),M=t.arms[E],v=d(a(M.end),u[E])-d(a(M.joint),a(M.end));return d(x,$)+v};let p=1/0;for(const[y,E]of[[e.leftBrow,e.leftEye],[e.rightBrow,e.rightEye]]){const x=R0(Dr,1,y,H0(E,e.blink));p=Math.min(p,x,x-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)},S=Math.max(w.left,w.right),k=_0*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:S,grounded:{left:w.left>=S-k,right:w.right>=S-k},fingertips:u,handAngle:{left:f(c,"left"),right:f(h,"right")},limbs:{leftArm:c,rightArm:h,leftLeg:ms(t.legs.left,t.rubber).map(o),rightLeg:ms(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:Dr,browTopY:p,mouthY:C0,faceX:t.facing*(E0+A0*Qe(e.turn))}}}function se(t,e={}){return F0(L0(t,e),t)}function Pb(t,e,n){return ys({x:t.center.x+e*t.rx,y:t.center.y+n*t.ry},t.center,t.angle)}function B0(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 q0(t,e,n={},s=0){const i=L0(e,n),o=n.color??"#1e293b",r=n.layers??{},a=n.layers?F0(i,e,!1):void 0,l=n.sketch?bi(t,n.sketch,s):void 0,c=n.sketch&&n.layers?bi(t,n.sketch,s):void 0,h=$=>{t.save(),$(),t.restore()},d=$=>{$&&a&&h(()=>$(t,a,s,c))},u=()=>t.scale(i.facing,1),f=()=>{u(),t.translate(0,i.hipY),t.rotate(Ut(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,v)=>{if(l)return M?l.curve($):l.line($);if(i.classic){t.beginPath(),t.moveTo($[0].x,$[0].y);for(const T of $.slice(1))t.lineTo(T.x,T.y);t.stroke();return}wi(t,$,v[0]*i.lineWidth,v[1]*i.lineWidth)},m=($,M)=>g(ms($,i.rubber),i.rubber>0,M),w=$=>{i.classic||g([i.legs[$].end,i.toes[$]],!1,fb)},S=$=>{if(n.hands&&!i.classic)return y($);if(i.classic||l)return;const M=i.arms[$].end;t.beginPath(),t.arc(M.x,M.y,pb*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=W0(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($){const M=n.hands??{},v=i.arms[$].end,T=i.handTips[$],I=n.headFill??"#ffffff";Si(t,v,M[$]??Pt,{side:$,angle:Math.atan2(T.x-v.x,v.y-T.y)*180/Math.PI,size:(M.size??O0)*i.height*Math.sqrt(i.stretch),skin:M.skin??(I==="none"?void 0:I),ink:o,lineWidth:i.lineWidth*.45,fingers:M.fingers,plump:M.plump,look:n.sketch?"pencil":"clean",seed:n.sketch?.seed},s)}const E=$=>{h(()=>{p(),m(i.arms[$],ub),S($)});const M=r.sleeve;M&&a&&h(()=>M(t,a,$,s,c))},x=Qe(e.turn)>kb;d(r.behind),h(()=>{u(),m(i.legs.left,P0),w("left"),m(i.legs.right,P0),w("right")}),x&&E("left"),h(()=>{f(),g(i.spine,i.spine.length>2,db)}),h(()=>{p();const{left:$,right:M}={left:i.arms.left.root,right:i.arms.right.root};if($.x!==M.x)if(i.classic)g([$,M],!1,[1,1]);else{const v={x:($.x+M.x)/2,y:$.y-.3*Math.abs(M.x-$.x)};g(Ze($,v,M,1,8),!0,[1.1,1.1])}}),d(r.body),x||E("left"),E("right"),d(r.behindHead),h(()=>{p(),t.translate(0,i.neckY),t.rotate(Ut(e.headTilt));const $=-i.headRy;t.beginPath(),t.ellipse(0,$,i.headRx,i.headRy,0,0,Math.PI*2);const M=n.headFill??"#ffffff";if(M!=="none"&&(t.fillStyle=M,t.fill()),l){l.ellipse(0,$,i.headRx,i.headRy);const v=l.nudge();t.translate(v.x,v.y)}else t.stroke();t.translate(0,$),t.scale(i.headRx/i.r,i.headRy/i.r),Eb(t,e,i.r,0,o,i.lineWidth)}),d(r.overHead),d(r.front),t.restore(),n.label&&(t.save(),t.fillStyle=o,t.font=n.labelFont??`700 ${Math.round(i.height*.11)}px sans-serif`,t.textAlign="center",t.textBaseline="bottom",t.fillText(n.label,0,-i.height*i.stretch-.04*i.height+i.drop),t.restore())}function Fr(t,e,n,s){const i={...t},o=t.gait&&s?.[t.gait]||t.gait;let r=t.walking>0?xn(i,p0(o,t.walk,i),t.walking):i,a=Ib(t);const l=t.dancing??0;if(n&&l>0){const c=n(t.beat??0);if(r=xn(r,c.pose,l),c.hands){const h=(d,u)=>u?An(d??Pt,u,l):d;a={left:h(a?.left,c.hands.left),right:h(a?.right,c.hands.right)}}}return t.talk>0&&(r={...r,mouth:Math.max(r.mouth,t.talk*M0(e))}),{pose:r,hands:a}}function z0(t,e,n,s){return Fr(t,e,n,s).pose}const Y0=(t,e)=>(t.facing??e.facing??1)<0?-1:1,bs=(t,e)=>`hand.${t}.${e}`;function Ib(t){const e=i=>{if(typeof t[bs(i,"spread")]=="number")return Object.fromEntries(Object.keys(Pt).map(o=>[o,t[bs(i,o)]]))},n=e("left"),s=e("right");return n||s?{left:n,right:s}:void 0}function Ob(t,e){return!e||!t.hands?t:{...t,hands:{...t.hands,left:e.left??t.hands.left,right:e.right??t.hands.right}}}function Wr(t){const e=t.style??{},n=e.height??300,s=n*.8,i={...Ct(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[bs(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:_b(Object.keys(o),t.cast),figureStyle:e,figureDance:t.dance,figureGaits:t.cast?.gaits,draw(r,a,l){const c=a.props,h=Fr(c,l,t.dance,t.cast?.gaits);r.translate(s/2,n),q0(r,h.pose,Ob({...e,rubber:c.rubber,facing:Y0(c,e)},h.hands),l)}}}function _b(t,e){const n={...i0,...o0};for(const s of t){const[,i,...o]=s.split("."),r=r0[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 _y(e)}}}function Br(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=z0(i,e.time,t.figureDance,t.figureGaits),l=se(a,{...s,rubber:i.rubber,facing:Y0(i,s)});return{pose:a,joints:B0(l,t.x+o+t.width/2,t.y+r+t.height)}}function xi(t){const e=[];return t.forEach((n,s)=>{const i=s===0?ct:e[s-1],o=typeof n.pose=="string"?Yt[n.pose]:{...i,...n.pose};e.push(n.expression?_e(o,n.expression):o)}),e}function Cb(t,e){const n=xi(e);return y0.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 qr=.5,$i={pataka:It({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:0,turn:2}),tripataka:It({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":1,"pinky.curl":0,spread:0,turn:2}),alapadma:It({"thumb.curl":.1,"thumb.across":0,"index.curl":.05,"middle.curl":.15,"ring.curl":.25,"pinky.curl":.35,spread:1,turn:2}),mushti:_t.fist,shikhara:_t.thumbsUp,hamsasya:It({"thumb.curl":.15,"thumb.across":.6,"index.curl":.6,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:.7,turn:2}),katakamukha:It({"thumb.curl":.2,"thumb.across":.6,"index.curl":.65,"middle.curl":.7,"ring.curl":0,"pinky.curl":0,spread:.4,turn:2})};function Pi(t){return typeof t!="string"?t:t in $i?$i[t]:_t[t]}function K0(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?Pi(i.hands.left):r.left,right:i.hands?.right?Pi(i.hands.right):r.right,easing:i.easing??t.easing})}return s}const zr=(t,e)=>(t%e+e)%e;function Hb(t,e,n,s){const i=K0(t,n,s);if(i.length===0)return{pose:n,hands:s};const o=zr(e,t.beats);let r=i.length-1;for(let f=0;f<i.length;f++)i[f].beat<=o&&(r=f);const a=i[r],l=i[(r+1)%i.length],c=a.beat<=o?a.beat:a.beat-t.beats,h=l.beat>c?l.beat:l.beat+t.beats,d=h>c?(o-c)/(h-c):0,u=Lt(l.easing??"ease-in-out")(Math.min(1,Math.max(0,d)));return{pose:xn(a.pose,l.pose,u),hands:{left:An(a.left,l.left,u),right:An(a.right,l.right,u)}}}const Rb=[["leftShoulder","rightShoulder"],["leftElbow","rightElbow"],["leftWrist","rightWrist"],["leftHip","rightHip"],["leftKnee","rightKnee"],["leftAnkle","rightAnkle"],["leftFootOut","rightFootOut"],["leftEye","rightEye"],["leftBrow","rightBrow"]],Lb=["lean","headTilt","lookX","spin"],Nb=new Set(["leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee"]);function j0(t){const e={...t},n=(t.turn??0)>=.5;for(const[s,i]of Rb){const o=n&&Nb.has(s)?-1:1;e[s]=o*t[i],e[i]=o*t[s]}if(!n)for(const s of Lb)e[s]=-t[s];return e}const Db=t=>Math.min(1,Math.max(-1,(.5-t)*4));function X0(t,e,n){const s=zr(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=Db(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 Ii(t){const e={...ct,...t.stance};return t.expression?_e(e,t.expression):e}function G0(t){return{left:t.hands?.left?Pi(t.hands.left):Pt,right:t.hands?.right?Pi(t.hands.right):Pt}}function Yr(t,e,n){const s=t.moves[e.move];if(!s)throw new Error(`dance: "${t.label}" has no move "${e.move}"`);const i=Hb(s,n,Ii(t),G0(t));return e.mirror?{pose:j0(i.pose),hands:{left:i.hands?.right,right:i.hands?.left}}:i}function Oi(t,e,n={}){const s=typeof t=="string"?Ce[t]:t;let i;if(n.move)i=Yr(s,{move:n.move,mirror:n.mirror},e);else{const o=s.routine,r=o.reduce((d,u)=>d+u.beats,0),a=zr(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=Yr(s,o[c],h),h<qr&&o.length>1&&e>=qr){const d=o[(c-1+o.length)%o.length],u=Yr(s,d,d.beats+h),f=Lt("ease-in-out")(h/qr);i={pose:xn(u.pose,i.pose,f),hands:{left:An(u.hands.left,i.hands.left,f),right:An(u.hands.right,i.hands.right,f)}}}}return{...i,pose:X0(i.pose,s.groove,e)}}function Fb(t,e,n={}){return Oi(t,e,n).pose}function _i(t){return(typeof t=="string"?Ce[t]:t).routine.reduce((n,s)=>n+s.beats,0)}const Wb={leftToe:"rightToe",rightToe:"leftToe",leftHeel:"rightHeel",rightHeel:"leftHeel"};function U0(t,e,n,s,i,o,r){for(let a=0;a*t.beats<n;a++)for(const l of t.keys){const c=a*t.beats+l.beat,h=e+c;if(!(c>=n||h<o||h>=r))for(const d of l.taps??[])i.push({beat:h,tap:s?Wb[d]:d})}}function Bb(t,e,n,s={}){const i=typeof t=="string"?Ce[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;U0(r,a,Math.ceil((n-a)/r.beats)*r.beats,s.mirror,o,e,n)}else{const r=_i(i);for(let a=Math.floor(e/r)*r;a<n;a+=r){let l=a;for(const c of i.routine)U0(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 V0(t,e){const n=t.moves[e.move];if(!n?.travel)return 0;const s=n.travel/n.beats;return e.mirror?(K0(n,Ii(t),G0(t))[0]?.pose.turn??Ii(t).turn??0)>=.5?s:-s:s}function J0(t,e){return e.move?[{move:e.move,beats:t.moves[e.move].beats,mirror:e.mirror}]:t.routine}function Ci(t,e,n={}){const s=typeof t=="string"?Ce[t]:t,i=J0(s,n),o=i.reduce((h,d)=>h+d.beats,0),r=i.reduce((h,d)=>h+V0(s,d)*d.beats,0),a=Math.floor(e/o);let l=a*r,c=e-a*o;for(const h of i){const d=Math.min(h.beats,c);if(l+=V0(s,h)*d,c-=d,c<=0)break}return l}function qb(t,e,n){const s=J0(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 zb=8;function Z0(t,e,n){const s=typeof e=="string"?Ce[e]:e,i=n.bpm??s.bpm,o=n.beats??(n.move?s.moves[n.move].beats:_i(s)),r=qb(s,o,n);if(r.every(w=>Ci(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*zb),d=a<=0?[]:Array.from({length:h+1},(w,S)=>[S/h*a,o-S/h*a]).flat(),u=[...new Set([...r,...d])].sort((w,S)=>w-S);let f=0;const p=u.map((w,S)=>{if(S>0){const k=u[S-1],y=Math.max(1,Math.ceil((w-k)*16));for(let E=0;E<y;E++){const x=k+(w-k)*E/y,$=k+(w-k)*(E+1)/y;f+=(Ci(s,$,n)-Ci(s,x,n))*c((x+$)/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 Yb(t,e,n=0){return(t-n)*e/6e4}function Kb(t,e={}){return n=>Oi(t,n,e)}function jb(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 Xb(t,e,n={}){const s=typeof e=="string"?Ce[e]:e,i=n.bpm??s.bpm,o=n.beats??(n.move?s.moves[n.move].beats:_i(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:Oi(s,w,n)}}),h=(g,m)=>({id:`${t}-${g}`,target:t,property:g,keyframes:c.map(w=>({time:w.time,value:m(w.frame)}))}),u=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:Z0(t,s,{...n,bpm:i,beats:o,start:a,height:n.height,fade:0});if(f&&u.push(f),n.hands===!1)return u;const p=[];for(const g of["left","right"])for(const m of Object.keys(Pt)){const w=S=>S.hands?.[g]?.[m]??Pt[m];c.some(S=>w(S.frame)!==Pt[m])&&p.push(h(bs(g,m),w))}return[...u,...p]}const ws={type:"back",mode:"out",overshoot:1.1},Ft="ease-out-cubic",Gb={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:Ft,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:Ft},{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:Ft},{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}]},Ub={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}]},Vb={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:Ft},{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:Ft},{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:Ft},{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:ws},{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}]},Jb={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:{..._t.spread,turn:2},right:{..._t.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:Ft},{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}]},Zb={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:ws,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:ws},{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:ws},{beat:3,pose:{headTilt:4}}]},isolations:{label:"Isolations",beats:2,easing:Ft,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}]},Qb={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:{..._t.cupped,roll:-30},left:{..._t.flat,turn:0}}},{beat:.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{..._t.cupped,roll:30}}},{beat:1,pose:{rightWrist:-15,rightElbow:12,leftWrist:-45,lean:-4,rightHip:16,leftHip:6},hands:{right:{..._t.cupped,roll:-30}}},{beat:1.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{..._t.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:{..._t.open,turn:2}},easing:Ft},{beat:.5,pose:{lean:-4,rightHip:12,headTilt:6}},{beat:1,pose:{lean:-11,rightHip:22,headTilt:10},easing:Ft},{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:Ft},{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:Ft}]}},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}]},tw={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}]},ew={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}]},nw={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:{..._t.spread,turn:2},right:{..._t.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:Ft},{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:Ft},{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}]},sw={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:{..._t.spread,turn:2},right:{..._t.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}]},Ce={disco:Gb,hipHop:Ub,breaking:Vb,jazz:Jb,kpop:Zb,bollywood:Qb,bhangra:tw,bharatanatyam:ew,charleston:nw,tap:sw,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:ws},{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}]}},Hi=t=>Math.min(1,Math.max(0,t));function iw(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 ow(t){return t-rw*Math.sin(2*Math.PI*t)/(2*Math.PI)}const rw=.5;function aw(t,e){if(!(e<=t.takeoff||e>=t.landing))return(e-t.takeoff)/(t.landing-t.takeoff)}function Q0(t,e){const n=typeof t=="string"?ks[t]:t,s=iw(n),i=Hi(e);let o=0;for(let d=0;d<s.length;d++)s[d].at<=i&&(o=d);const r=s[o],a=s[Math.min(o+1,s.length-1)],l=a.at>r.at?(i-r.at)/(a.at-r.at):0,c=xn(r.pose,a.pose,Lt(a.easing??"ease-in-out")(Hi(l))),h=aw(n,i);return h===void 0?{...c,spin:0,rise:0}:{...c,spin:n.spin*ow(h),rise:4*n.height*h*(1-h)}}function td(t,e,n){const s=typeof t=="string"?ks[t]:t,i=Hi(e),o=Hi((i-s.takeoff)/(s.landing-s.takeoff));return s.travel*n*o}function lw(t,e,n={}){const s=typeof e=="string"?ks[e]:e,i=n.start??0,o=n.duration??s.duration,r=n.samples??48,a=Array.from({length:r+1},(h,d)=>{const u=d/r;return{time:i+u*o,progress:u,pose:Q0(s,u)}}),c=Object.keys(ct).filter(h=>a.some(d=>d.pose[h]!==ct[h])).map(h=>({id:`${t}-${h}`,target:t,property:h,keyframes:a.map(d=>({time:d.time,value:d.pose[h]}))}));if(n.height!==void 0&&s.travel!==0){const h=(n.facing??1)<0?-1:1;c.push({id:`${t}-x`,target:t,property:"x",keyframes:a.map(d=>({time:d.time,value:(n.x??0)+h*td(s,d.progress,n.height)}))})}return c}const cw={leftHip:-55,leftKnee:-95,rightHip:55,rightKnee:95,leftShoulder:45,rightShoulder:-45,leftElbow:10,rightElbow:-10,lean:22,stretch:.94,headTilt:6},hw={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},Ri={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},dw={leftHip:-22,leftKnee:-30,rightHip:22,rightKnee:30,leftAnkle:10,rightAnkle:10,leftShoulder:-125,rightShoulder:125,leftElbow:0,rightElbow:0,lean:8,headTilt:0},uw={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 $n(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:cw},{at:.27,pose:hw,easing:"ease-out-quad"},...i,{at:.76,pose:dw},{at:.86,pose:uw,easing:"ease-out-quad"},{at:1,reset:!0}]}}const ks={frontFlip:$n("Front flip (tuck)",360,.56,.35,[{at:.38,pose:Ri,easing:"ease-out-cubic"},{at:.64,pose:Ri}]),backFlip:$n("Back flip (tuck)",-360,.58,-.15,[{at:.36,pose:{...Ri,lean:18},easing:"ease-out-cubic"},{at:.64,pose:{...Ri,lean:18}}]),layout:$n("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:$n("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:$n("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:$n("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)},Li={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}},Kr=.215,jr=.205,fw=.065,ed=.035,gw=.165,pw=.155,mw=12,yw=.3,bw=.7,ww=.35,kw=t=>t*Math.PI/180,gt={turn:0,lean:0,bend:0,side:0,"head.turn":0,"head.nod":0,"head.tilt":0,"arm.left.swing":0,"arm.left.spread":12,"arm.left.elbow":8,"arm.left.bend":0,"arm.right.swing":0,"arm.right.spread":12,"arm.right.elbow":8,"arm.right.bend":0,"leg.left.swing":0,"leg.left.spread":3,"leg.left.knee":0,"leg.left.ankle":0,"leg.left.toeOut":0,"leg.left.rotate":0,"leg.right.swing":0,"leg.right.spread":3,"leg.right.knee":0,"leg.right.ankle":0,"leg.right.toeOut":0,"leg.right.rotate":0,stretch:1,lift:0,roll:0,mouth:0,smile:.5,mouthWidth:1,blink:0,"eye.left":1,"eye.right":1,"brow.left":0,"brow.right":0,browTilt:0,lookX:0,lookY:0,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{...gt,...t}}const vw=new Set(["turn","side","head.turn","head.tilt","roll","lookX","hair.swing"]);function nd(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]=vw.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 ie={rest:gt,wave:bt({"arm.right.spread":115,"arm.right.bend":55,"arm.right.elbow":0,"head.tilt":-6,smile:.9}),cheer:bt({...Tt("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({...Tt("arm",{spread:50,bend:-105,elbow:0}),...Tt("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({...Tt("arm",{spread:35,bend:75,elbow:0}),"head.tilt":-10,smile:-.2}),sit:bt({...Tt("leg",{swing:90,knee:90,spread:4}),...Tt("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,...Tt("arm",{swing:20,elbow:30})}),crouch:bt({...Tt("leg",{swing:75,knee:140,spread:6}),lean:25,...Tt("arm",{swing:50,elbow:40}),"head.nod":-15}),crawl:bt({lean:82,"head.nod":-35,...Tt("arm",{swing:80,elbow:0,spread:4}),...Tt("leg",{knee:92,ankle:-88})}),lieDown:bt({roll:90,...Tt("arm",{spread:8}),"head.nod":0}),sleep:bt({roll:90,...Tt("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({...Tt("leg",{swing:80,spread:22,rotate:75,knee:145}),...Tt("arm",{swing:25,spread:18,elbow:30}),lean:5,smile:.5}),carry:bt({...Tt("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({...Tt("arm",{swing:28,spread:24,elbow:85,bend:-45}),...Tt("leg",{swing:12,knee:22,spread:6}),lean:-4,smile:.2}),push:bt({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:bt({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: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({...Tt("arm",{swing:32,spread:10,elbow:82,bend:-28}),"head.nod":22,lookY:.8,smile:.2}),type:bt({...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})},sd=["round","flat","pointed","big"],Mw={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 id(t={}){const e=t.headSize??.3,n=t.shoulderWidth??.06,s=t.hipWidth??.022,i=t.legLength??1,o=t.armLength??1,r=Mw[t.feet??"round"],a=Math.max(.12,1-e-ed-(Kr+jr)*i),l=d=>({id:`arm.${d}`,parent:"spine",offset:[(d==="left"?1:-1)*n,-.035,0],rest:[0,-1,0],side:d==="left"?1:-1,bones:[{length:gw*o,width:[1.25,.9]},{length:pw*o,width:[.9,.75]}]}),c=d=>({id:`leg.${d}`,parent:null,offset:[(d==="left"?1:-1)*s,0,0],rest:[0,-1,0],side:d==="left"?1:-1,bones:[{length:Kr*i,width:[1.45,1.05]},{length:jr*i,width:[1.05,.85]},{length:fw*Math.sqrt(i)*r.length,width:r.width}]}),h=(d,u)=>d[u]??gt[u]??0;return{id:"human",hipHeight:(Kr+jr)*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:ed,width:[1,.9]}]},l("left"),l("right")],head:{on:"neck",size:e},contacts:[...["left","right"].flatMap(d=>[{chain:`leg.${d}`,joint:1},{chain:`leg.${d}`,joint:2},{chain:`leg.${d}`,joint:3},{chain:`arm.${d}`,joint:1},{chain:`arm.${d}`,joint:2}]),{chain:"spine",joint:0},{chain:"spine",joint:1},{chain:"spine",joint:2},{head:"top"}],angles(d,u){if(u.id==="spine"){const S=-h(d,"lean")/2,k=h(d,"side")/2,y=-h(d,"bend");return[{swing:S+y*yw,spread:k},{swing:S+y*bw,spread:k}]}if(u.id==="neck")return[{swing:-h(d,"bend")*ww,spread:0}];const[f,p]=u.id.split("."),g=S=>h(d,`${f}.${p}.${S}`);if(f==="arm")return[{swing:g("swing"),spread:g("spread")},{swing:g("elbow"),spread:g("bend")}];const m=(u.side??1)*g("rotate"),w=1-Math.cos(kw(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:(mw+g("toeOut"))*(u.side??1)}]},withAngles(d,u,f){const[p,g]=u.id.split("."),m=w=>`${p}.${g}.${w}`;return p==="arm"?{...d,[m("swing")]:f[0].swing,[m("spread")]:f[0].spread,[m("elbow")]:f[1].swing,[m("bend")]:f[1].spread}:p==="leg"?{...d,[m("swing")]:f[0].swing,[m("spread")]:f[0].spread,[m("knee")]:-f[1].swing}:d},boneScale(d,u){const f=Math.min(3,Math.max(.3,h(d,"stretch")));return u?.id.startsWith("arm.")?Math.sqrt(f):f},headPose(d){const u=Math.min(3,Math.max(.3,h(d,"stretch")));return{yaw:h(d,"head.turn"),nod:h(d,"head.nod"),tilt:h(d,"head.tilt"),sx:1/Math.sqrt(u),sy:Math.sqrt(u)}},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 Sw(t){const e=t.split(".");if(e[0]==="hand"&&e.length>=3){const s=`${e[1]==="left"?"Left":"Right"} hand`,i={spread:"finger spread",turn:"wrist turn",bend:"wrist bend",tilt:"wrist tilt",roll:"roll"},o=e.slice(2).join(".");return`${s} · ${i[o]??o.replace(".curl"," curl").replace(".across"," across")}`}if(e.length===3){const[s,i,o]=e;return`${`${i==="left"?"Left":"Right"} ${s}`} · ${{swing:"forward / back",spread:"out / in",elbow:"elbow bend",bend:"forearm out / in",knee:"knee bend",ankle:"foot tilt",toeOut:"toes out / in",rotate:"turn out at the hip"}[o]??o}`}return{turn:"View (front → side → back)",lean:"Lean forward / back",bend:"Back curve (line of action)",side:"Lean sideways","head.turn":"Head · turn","head.nod":"Head · nod","head.tilt":"Head · tilt",stretch:"Squash / stretch",lift:"Lift off the ground",roll:"Roll (whole figure)",mouth:"Mouth open",smile:"Smile",mouthWidth:"Mouth width",blink:"Blink","eye.left":"Left eye open","eye.right":"Right eye open","brow.left":"Left brow","brow.right":"Right brow",browTilt:"Brow slant",lookX:"Look left / right",lookY:"Look up / down",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 Tw={leftEye:"eye.left",rightEye:"eye.right",leftBrow:"brow.left",rightBrow:"brow.right"},Ew={blush:0,tears:0,sweat:0},vs=Object.fromEntries(Object.entries(kt).map(([t,e])=>[t,{...Object.fromEntries(Object.entries(e).map(([n,s])=>[Tw[n]??n,s])),...Ew}]));vs.crying.tears=1,vs.scared.sweat=.8,vs.worried.sweat=.6;const Vt=t=>({...vs.neutral,...t}),Xr={...vs,laughing:Vt({mouth:.75,smile:1,mouthWidth:1.25,"eye.left":0,"eye.right":0,"brow.left":.5,"brow.right":.5}),afraid:Vt({mouth:.4,smile:-.6,mouthWidth:.9,"eye.left":1.3,"eye.right":1.3,"brow.left":.6,"brow.right":.6,browTilt:1,sweat:1}),bored:Vt({smile:-.05,mouthWidth:.6,"eye.left":.45,"eye.right":.45,"brow.left":-.4,"brow.right":-.4,lookX:.5}),tired:Vt({mouth:.2,smile:-.3,mouthWidth:.7,"eye.left":.3,"eye.right":.3,"brow.left":-.1,"brow.right":-.1,browTilt:.6,lookY:.6}),embarrassed:Vt({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:Vt({smile:.75,mouthWidth:1,"eye.left":.75,"eye.right":.75,"brow.left":.5,"brow.right":.5,lookY:-.2}),determined:Vt({smile:.35,mouthWidth:.8,"eye.left":.85,"eye.right":.85,"brow.left":-.5,"brow.right":-.5,browTilt:-.9}),affectionate:Vt({smile:.85,"eye.left":0,"eye.right":0,"brow.left":.3,"brow.right":.3,blush:.8}),hurt:Vt({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:Vt({smile:-.25,mouthWidth:.7,"eye.left":.5,"eye.right":.85,"brow.left":-.6,"brow.right":.4,browTilt:-.3,lookX:.8}),relieved:Vt({smile:.7,"eye.left":0,"eye.right":0,"brow.left":.4,"brow.right":.4,browTilt:.4}),excited:Vt({mouth:.6,smile:1,mouthWidth:1.1,"eye.left":1.4,"eye.right":1.4,"brow.left":.9,"brow.right":.9,blush:.4})};function od(t,e){const n=Math.min(1,Math.max(0,t.turn??0)),s=1-n,i={...gt,turn:n},o=[{stick:"right",human:"left",s:1},{stick:"left",human:"right",s:-1}];for(const{stick:a,human:l,s:c}of o){const h=t[`${a}Shoulder`],d=t[`${a}Elbow`];i[`arm.${l}.spread`]=h*s,i[`arm.${l}.swing`]=c*h*n,i[`arm.${l}.bend`]=d*s,i[`arm.${l}.elbow`]=c*d*n;const u=t[`${a}Hip`],f=t[`${a}Knee`],p=s+c*n;i[`leg.${l}.rotate`]=90*s,i[`leg.${l}.spread`]=0,i[`leg.${l}.swing`]=u*p,i[`leg.${l}.knee`]=f*p,i[`leg.${l}.ankle`]=-(t[`${a}Ankle`]??0),i[`leg.${l}.toeOut`]=(t[`${a}FootOut`]??0)*Aw,i[`eye.${l}`]=t[`${a}Eye`],i[`brow.${l}`]=t[`${a}Brow`],e&&Object.assign(i,xw(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 Aw=70;function xw(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}const oe=t=>t*Math.PI/180;function Gr([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t,e*i+n*o,-e*o+n*i]}function Ur([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i-e*o,t*o+e*i,n]}function He([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i+n*o,e,-t*o+n*i]}const Re=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Ni=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],Di=(t,e)=>Ur(Gr(t,e.swing),e.spread);function Vr(t,e){const n=He(t,e);return{point:{x:n[0],y:-n[1]},depth:n[2]}}function Fi(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),S=m?m.joints3[w]:o,k=m?m.frames[Math.max(0,w-1)]:{swing:0,spread:0},y=g.offset?Re(S,Di(Ni(g.offset,s),k)):S,E=g.side??1,x=t.boneScale?.(e,g)??1,$=t.angles(e,g),M=[y],v=[];let T=k.swing,I=k.spread;g.bones.forEach((O,_)=>{const C=$[_]??{swing:0,spread:0};T+=oe(C.swing),I+=oe(C.spread)*E,v.push({swing:T,spread:I});const D=He(Di(g.rest,{swing:T,spread:I}),oe(C.yaw??0));M.push(Re(M[_],Ni(D,O.length*s*x)))}),r[g.id]={joints3:M,frames:v}}const a=r[t.head.on],l=t.headPose?.(e)??{yaw:0,nod:0,tilt:0,sx:1,sy:1},c=a.frames[a.frames.length-1],h=t.head.size/2*s,d=h*l.sx,u=h*l.sy,f=g=>Di(He(Gr(Ur(g,-oe(l.tilt)),-oe(l.nod)),oe(l.yaw)),c),p=Re(a.joints3[a.joints3.length-1],f([0,u,0]));return{height:s,root:o,chains:r,head:{center:p,rx:d,ry:u,toBody:f}}}function Jr(t,e,n){const s=n.height,i=oe(90*(e.turn??0)),o=Fi(t,e,s),{root:r}=o,a=o.chains,{rx:l,ry:c}=o.head,h=o.head.toBody,d=o.head.center,u={};for(const v of t.chains){const{joints3:T,frames:I}=a[v.id],O=T.map(_=>Vr(_,i));u[v.id]={id:v.id,joints3:T,frames:I,points:O.map(_=>_.point),depths:O.map(_=>_.depth)}}const f=Vr(d,i),p=[[1,0,0],[0,1,0],[0,0,1]].map(v=>He(h(v),i)),g=Vr(r,i).point,m=oe(e.roll??0),w=v=>{const T=v.x-g.x,I=v.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)}},S=([v,T,I])=>[v*Math.cos(m)+T*Math.sin(m),-v*Math.sin(m)+T*Math.cos(m),I];for(const v of Object.values(u))v.points=v.points.map(w);const k={center:w(f.point),depth:f.depth,rx:l,ry:c,angle:0,axes:p.map(S)},y=k.axes[1];k.angle=Math.atan2(y[0],y[1]);const E=v=>{if("head"in v)return{x:k.center.x+y[0]*c,y:k.center.y-y[1]*c};const T=u[v.chain];return T.points[Math.min(v.joint,T.points.length-1)]};let x=0;(n.contact??"ground")==="ground"&&(x=-Math.max(...t.contacts.map(v=>E(v).y))),x-=(e.lift??0)*s;const $=v=>({x:v.x,y:v.y+x});for(const v of Object.values(u))v.points=v.points.map($);k.center=$(k.center);const M=t.contacts.map(v=>({spec:v,point:E(v)}));return{height:s,view:i,chains:u,head:k,hip:$(w(g)),contacts:M,groundY:Math.max(...M.map(v=>v.point.y))}}const Zr=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],rd=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function Wi(t,e,n){const s=n.height,i=oe(90*(e.turn??0)),o=oe(e.roll??0),r=Fi(t,e,s),a=He(r.root,i),l=m=>Re(Ur(Zr(He(m,i),a),-o),a),c={};for(const m of t.chains)c[m.id]=r.chains[m.id].joints3.map(l);const h=l(r.head.center),d=m=>rd(Zr(l(Re(r.head.center,r.head.toBody(m))),h)),u=[d([1,0,0]),d([0,1,0]),d([0,0,1])],f=m=>{if("head"in m)return Re(h,Ni(u[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:u}}}function Bi(t,e,n,s){const i=n.height,o=oe(90*(e.turn??0)),r=Fi(t,e,i),a=Wi(t,e,n),l=a.hip,c=a.chains,h=a.head.center,d=v=>{if("head"in v)return Re(h,Ni(a.head.axes[1],a.head.ry));const T=c[v.chain];return T[Math.min(v.joint,T.length-1)]},u=s.toView(l),f=s.toScreen(u),p=s.toScreen([u[0]+1,u[1],u[2]]),g=Math.hypot(p.x-f.x,p.y-f.y),m=v=>{const T=s.toView(v);return{point:s.toScreen(T),depth:T[2]*g}},w={};for(const v of t.chains){const T=c[v.id].map(m);w[v.id]={id:v.id,joints3:r.chains[v.id].joints3,frames:r.chains[v.id].frames,points:T.map(I=>I.point),depths:T.map(I=>I.depth)}}const S=s.toView(h),k=s.toScreen(S),y=s.toScreen([S[0]+1,S[1],S[2]]),E=Math.hypot(y.x-k.x,y.y-k.y),x=a.head.axes.map(v=>rd(Zr(s.toView(Re(h,v)),S))),$={center:k,depth:S[2]*g,rx:r.head.rx*E,ry:r.head.ry*E,angle:Math.atan2(x[1][0],x[1][1]),axes:x},M=t.contacts.map(v=>({spec:v,point:m(d(v)).point}));return{height:i*g,view:o,chains:w,head:$,hip:f,contacts:M,groundY:Math.max(...M.map(v=>v.point.y))}}function Qr(t,[e,n,s]){const[i,o,r]=t.axes,a=[i[0]*e*t.rx+o[0]*n*t.ry+r[0]*s*t.rx,i[1]*e*t.rx+o[1]*n*t.ry+r[1]*s*t.rx,i[2]*e*t.rx+o[2]*n*t.ry+r[2]*s*t.rx],l=Math.hypot(e,n,s)||1,c=(i[2]*e+o[2]*n+r[2]*s)/l;return{point:{x:t.center.x+a[0],y:t.center.y-a[1]},depth:t.depth+a[2],facing:c}}class ad{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 $w(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 ta=Math.PI*2;function Pw(t,e=16){const n=new ad,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*ta,d=Math.sin(a)*Math.sin(h),u=Math.cos(a),f=Math.sin(a)*Math.cos(h);l.push(n.vertex(d*t,u*t,f*t,d,u,f))}o.push(l)}for(let r=0;r<i;r++)for(let a=0;a<s;a++){const l=o[r][a],c=o[r+1][a],h=o[r+1][a+1],d=o[r][a+1];r>0&&n.triangle(l,c,d),r<i-1&&n.triangle(c,h,d)}return n.build()}function ld(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*ta;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 cd(t,e,n=24){const s=new ad,i=Math.max(6,Math.round(n)),o=e/2,r=-e/2,a=h=>Array.from({length:i+1},(d,u)=>{const f=u/i*ta;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 ld(s,t,o,1,i),ld(s,t,r,-1,i),s.build()}function qi(t){const e=Array.from({length:t.indices.length/3},()=>[]);for(const n of $w(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 zi=t=>t*180/Math.PI,Pn=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],ea=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Ms=t=>Math.hypot(t[0],t[1],t[2]),na=t=>{const e=Ms(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},Yi=t=>Math.atan2(Math.sin(t),Math.cos(t));function hd(t){const[e,n,s]=na(t);return{swing:Math.asin(Math.max(-1,Math.min(1,s))),spread:Math.atan2(e,-n)}}function Iw(t,e,n,s,i){const o=t.chains.find(T=>T.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=Jr(t,{...e,turn:0,roll:0,lift:0},{height:i.height,contact:"none"}),a=r.chains[n],l=a.joints3[0],c=Ms(Pn(a.joints3[1],a.joints3[0])),h=Ms(Pn(a.joints3[2],a.joints3[1])),d=o.parent?r.chains[o.parent].frames[Math.max(0,(o.at??r.chains[o.parent].joints3.length-1)-1)]:{swing:0,spread:0},u=Pn(s,l),f=Math.min(c+h-1e-6,Math.max(Math.abs(c-h)+1e-6,Ms(u))),p=na(u),g=o.parent!==null,m=Di(o.pole??(g?[0,-.35,-1]:[0,0,1]),d);let w=Pn(m,[p[0]*ea(m,p),p[1]*ea(m,p),p[2]*ea(m,p)]);Ms(w)<1e-6&&(w=He([1,0,0],0)),w=na(w);const S=(c*c+f*f-h*h)/(2*c*f),k=Math.sqrt(Math.max(0,1-S*S)),y=[l[0]+c*(S*p[0]+k*w[0]),l[1]+c*(S*p[1]+k*w[1]),l[2]+c*(S*p[2]+k*w[2])],E=[l[0]+p[0]*f,l[1]+p[1]*f,l[2]+p[2]*f],x=o.side??1,$=hd(Pn(y,l)),M=hd(Pn(E,y)),v=[{swing:zi(Yi($.swing-d.swing)),spread:zi(Yi($.spread-d.spread))*x},{swing:zi(Yi(M.swing-$.swing)),spread:zi(Yi(M.spread-$.spread))*x}];return t.withAngles(e,o,v)}const dd=.34,re=.12,Jt=-.4,Zt=(t,e,n)=>t[e]??n,Ow=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),_w=.45,Cw=.35,Hw=.7;function $t(t,e,n){const s=f=>Math.sqrt(Math.max(0,1-f.x*f.x-f.y*f.y)),i=Qr(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(Cw,Math.abs(a)),h=l*Math.max(Hw,Math.abs(a)),d=Math.cos(t.angle),u=Math.sin(t.angle);return{facing:i,points:e.map(f=>{const p=_w*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*d+w*u,y:t.center.y+m*u-w*d}})}}const Ss=(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}}),ud=(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},Ki=(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}}),Ts=.05,Rw=.3,Lw="#e06b7d";function Nw(t,e,n,s,i={}){const o=Math.max(1,Math.min(s*.6,.14*e.rx)),r=(M,v)=>$t(e,M,v).points,a=(M,v)=>$t(e,[],{x:M,y:v}).facing,l=Zt(n,"smile",0),c=Zt(n,"blink",0),h=Zt(n,"lookX",0),d=Zt(n,"lookY",0),u=Zt(n,"browTilt",0);for(const M of[1,-1]){const v=M===1?"left":"right",T=dd*M;if(a(T,re)<Ts)continue;const I={x:T,y:re},O=Ow(Zt(n,`eye.${v}`,1),c);if(O<.2){const q=l>.5?.12:-.06;t.line(r(Ss({x:T-.12,y:re},{x:T,y:re+q},{x:T+.12,y:re}),I),o)}else{if(O>1.2){const j=.13*O;t.shape(r(Ki(T,re,j*.85,j),I),"#ffffff",o)}const q=O>1.2?.075:.1,X=T+h*.08,J=re-d*.07;t.shape(r(Ki(X,J,q,q*1.1*Math.min(O,1)),I),t.ink,0)}const _=re+.3+Zt(n,`brow.${v}`,0)*.14+Math.max(0,O-1)*.12,C={x:T+M*.13,y:_},D={x:T-M*.13,y:_+u*.1};t.line(r([C,{x:(C.x+D.x)/2,y:(C.y+D.y)/2},D],{x:T,y:_}),o)}Dw(t,e,n,o);const f={x:0,y:Jt};if(a(0,Jt)<-Ts)return;const p=.25*Math.max(.3,Zt(n,"mouthWidth",1)),g=Math.min(1,Math.max(0,Zt(n,"mouth",0)));if(g<=.05){t.line(r(Ss({x:-p,y:Jt},{x:0,y:Jt-l*.25},{x:p,y:Jt}),f),o);return}const m=.3*g;let w,S,k,y;if(l>.3){const M=Jt+.05,v={x:0,y:Jt-m*2};w=[...Ss({x:p,y:M},v,{x:-p,y:M})],S=()=>M,k=T=>ud({x:p,y:M},v,{x:-p,y:M},T),y=.85}else if(l<-.3){const M=Jt-m*.6,v={x:0,y:Jt+m*1.4};w=[...Ss({x:p,y:M},v,{x:-p,y:M})],S=T=>ud({x:p,y:M},v,{x:-p,y:M},T),k=()=>M,y=.5}else{const M=p*.8;w=Ki(0,Jt,M,m);const v=T=>m*Math.sqrt(Math.max(0,1-(T/M)**2));S=T=>Jt+v(T),k=T=>Jt-v(T),y=.5}if(t.shape(r(w,f),t.ink,0),g<Rw)return;const E=S(0)-k(0),x=p*y,$=(M,v,T=8)=>Array.from({length:T+1},(I,O)=>M+(v-M)*O/T);if(i.tongue){const M=x*.55,v=$(M,-M).map(I=>({x:I,y:k(I)})),T=Ss({x:-M,y:k(-M)},{x:0,y:k(0)+E*.8},{x:M,y:k(M)},8);t.shape(r([...v,...T.slice(1,-1)],f),Lw,0)}if(i.teeth){const M=Math.min(.06,E*.4),v=$(-x,x).map(I=>({x:I,y:S(I)})),T=v.map(({x:I,y:O})=>({x:I*.92,y:O-M})).reverse();t.shape(r([...v,...T],f),"#ffffff",0);for(const I of[-.5,0,.5]){const O=x*I;t.line(r([{x:O,y:S(O)},{x:O*.92,y:S(O)-M}],f),o*.6)}}}const fd="#8fd0f5",gd=(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 Dw(t,e,n,s){const i=Math.min(1,Math.max(0,Zt(n,"blush",0))),o=Math.min(1,Math.max(0,Zt(n,"tears",0))),r=Math.min(1,Math.max(0,Zt(n,"sweat",0)));if(!(i+o+r<=.01)){for(const a of[1,-1]){const l={x:.5*a,y:-.16},c=$t(e,[],l).facing>=Ts;if(i>.01&&c){const{points:d}=$t(e,Ki(l.x,l.y,.17,.1),l);if(t.shape(d,`rgba(240, 120, 140, ${(.75*i).toFixed(3)})`,0),i>.5)for(const u of[-.07,0,.07]){const f=[{x:l.x+u-.018,y:l.y-.03},{x:l.x+u+.018,y:l.y+.03}];t.line($t(e,f,l).points,s*.3)}}const h={x:dd*a,y:re};if(o>.01&&$t(e,[],h).facing>=Ts){const d=.05+.04*o,u={x:h.x+.06*a,y:re-.2-.12*o};if(t.shape($t(e,gd(u.x,u.y,d),u).points,fd,s*.35),o>.6){const f=[{x:h.x+.05*a,y:re-.1},{x:u.x,y:u.y+d*.8}];t.line($t(e,f,u).points,s*.3)}}}if(r>.01){const a={x:.64,y:.42};$t(e,[],a).facing>=Ts&&t.shape($t(e,gd(a.x,a.y,.05+.05*r),a).points,fd,s*.35)}}}const Fw=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 Ww=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function me(t,[e,n,s]){const[i,o,r]=t.axes;return i[2]*e+o[2]*n+r[2]*s}function Wt(t,e){return Qr(t,e).point}function ji(t,e){const n=Math.abs(t-e)%(Math.PI*2);return n>Math.PI?Math.PI*2-n:n}function Xi(t,e,n=64){const s=e.top??1,i=e.bottom??-1,o=Math.max(8,Math.ceil((s-i)*Fw)),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):Ww(e.position(p,g)),c=o+3,h=new Float64Array(n*c),d=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 S=p*n+w;if(g){h[S]=-1;continue}const k=a(w);h[S]=e.inside(k,m),d[S]=h[S]>-.35?me(t,l(k,m)):0}}const u=p=>(p%n+n)%n,f=p=>{const g=n+1,m=new Float64Array(g*c);for(let O=0;O<c;O++)for(let _=0;_<=n;_++){const C=O*n+(_===n?0:_);m[O*g+_]=Math.min(h[C],p*d[C])}const w=(O,_)=>m[_*g+O],S=(O,_,C,D)=>{const q=w(O,_),X=w(C,D),J=q===X?.5:Math.min(1,Math.max(0,q/(q-X)));return Wt(t,e.position(a(O+(C-O)*J),r(_+(D-_)*J)))},k=n*c*2,y=new Int32Array(k).fill(-1),E=new Int32Array(k).fill(-1),x=new Map,$=(O,_,C)=>{const D=(C*n+u(_))*2+(O?1:0);return x.has(D)||x.set(D,O?S(u(_),C,u(_),C+1):S(_,C,_+1,C)),D},M=(O,_)=>{y[O]===-1?y[O]=_:E[O]=_},v=(O,_)=>{M(O,_),M(_,O)};for(let O=0;O<c-1;O++)for(let _=0;_<n;_++){const C=O*g+_,D=(m[C]>0?8:0)|(m[C+1]>0?4:0)|(m[C+g+1]>0?2:0)|(m[C+g]>0?1:0);if(D===0||D===15)continue;const q=()=>$(!1,_,O),X=()=>$(!1,_,O+1),J=()=>$(!0,_,O),j=()=>$(!0,_+1,O);switch(D){case 1:case 14:v(J(),X());break;case 2:case 13:v(X(),j());break;case 3:case 12:v(J(),j());break;case 4:case 11:v(q(),j());break;case 6:case 9:v(q(),X());break;case 7:case 8:v(J(),q());break;case 5:case 10:{const A=(w(_,O)+w(_+1,O)+w(_+1,O+1)+w(_,O+1))/4>0;D===5===A?(v(J(),q()),v(X(),j())):(v(J(),X()),v(q(),j()));break}}}const T=[],I=new Uint8Array(k);for(const O of x.keys()){if(I[O])continue;const _=[];let C=-1,D=O;for(;D!==-1&&!I[D];){I[D]=1,_.push(x.get(D));const q=y[D],X=E[D],J=q!==-1&&q!==C&&!I[q]?q:X!==-1&&X!==C&&!I[X]?X:-1;C=D,D=J}_.length>=3&&T.push(_)}return T};return{near:f(1),far:f(-1)}}const pd=new WeakMap;function sa(t,e,n){let s=pd.get(t);s||pd.set(t,s=new Map);let i=s.get(e);return i||s.set(e,i=n()),i}function ia(t,e,n){t.save(),t.beginPath(),t.rect(-1e5,-1e5,2e5,2e5),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 md(t,e,n,s=.04){const i=[];let o=[];return e.forEach((r,a)=>{me(t,n[a])>s?o.push(Wt(t,r)):(o.length>=2&&i.push(o),o=[])}),o.length>=2&&i.push(o),i}const In={swing:0,trail:0,lift:0};function Gi(t){if(!t)return In;const e=t["hair.swing"]??0,n=t["hair.trail"]??0,s=t["hair.lift"]??0;return e===0&&n===0&&s===0?In:{swing:e,trail:n,lift:s}}const yd=t=>t.swing===0&&t.trail===0&&t.lift===0;function bd(t){return t.length>0||t.ties.some(e=>e.kind!=="bun")}function oa([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 wd={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},kd=1.75,ra={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}},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:kd,opening:84,part:0,strands:"part",hairline:{front:.5,side:.05,back:-.85},coversEars:!0},shoulderWaves:{volume:.22,length:kd,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}},ue={black:"#22201f",brown:"#6b4630",chestnut:"#7b4a2b",auburn:"#9a4426",blond:"#d9b55a",ginger:"#c8662f",gray:"#a7a29c",white:"#ecebe7"};function vd(t){const e=typeof t=="string"?{style:t}:t,n=e.style?ra[e.style]:{};if(e.style&&!n)throw new Error(`hair: unknown style '${e.style}'`);const{style:s,hairline:i,...o}=e;return{...wd,...n,...o,hairline:{...wd.hairline,...n.hairline,...i},ties:(o.ties??n.ties??[]).map(r=>({...r}))}}const Ui=t=>t*Math.PI/180,Es=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},aa=t=>1-Math.abs(2*(t-Math.floor(t))-1);function As(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*aa(e*11/(Math.PI*2))*c),h}function Md(t,e,n){const s=t.textureAmount;switch(t.texture){case"spiky":return s*(aa(e*11/(Math.PI*2))*aa(n*2.6+.5))**1.2*Es(-.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 Sd(t,e,n=In){const s=t.length>0,i=new Map,o=h=>{let d=i.get(h);return d===void 0&&i.set(h,d=As(t,h)),d},r=Ui(t.opening),a=h=>t.length+(t.texture==="wavy"||t.texture==="curly"||t.texture==="locs"?.12*Math.sin(h*9):0),l=(h,d,u)=>{if(t.flat<=0||d<.45)return null;const f=(d-.45)/.55,p=Math.sqrt(1-.45*.45)*u*(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):-1,inside(h,d){const u=d-o(h);if(!s)return u;const f=Math.min(d+a(h),ji(h,0)-r);return Math.max(u,f)},position(h,d){if(s&&d<0){const k=t.length<1.5?.14*Es(-t.length+.45,-t.length-.1,d):0,y=1+e+t.volume*(1-k*2.5)+Md(t,h,d)-k;return[y*Math.sin(h),d,y*Math.cos(h)]}const u=.4+.6*Es(0,.3,d-As(t,h)),f=1+e+(t.volume+Md(t,h,d))*u,p=l(h,d,f);if(p)return p;const[g,m,w]=pe(h,d),S=[g*f,m*f,w*f];if(t.quiff>0){const k=t.quiff*Math.exp(-((h/.7)**2))*Es(.15,.85,d);S[1]+=k*.7,S[2]+=k*.45}return S},normal(h,d){return s&&d<0?[Math.sin(h),0,Math.cos(h)]:pe(h,d)}};return s&&!yd(n)?Bw(c,t,n):c}function Bw(t,e,n){const s=o=>o<0?Es(-.15,-Math.max(.7,e.length),o):0,i=o=>Ui(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,d]=oa(t.position(o+l,r),l);return[c,h+n.lift*a,d-n.trail*a]},normal:(o,r)=>oa(t.normal(o+i(r),r),i(r))}}const qw=t=>t.texture==="spiky"||t.texture==="curly"||t.texture==="locs"?104:t.texture==="wavy"?80:64;function Td(t,e,n,s){return sa(t,Yw(e,s),()=>Xi(t,n,qw(e)))}const Ed=new WeakMap;let zw=1;function Yw(t,e){if(yd(e))return t;let n=Ed.get(t);return n||Ed.set(t,n=zw++),`${n}:${e.swing}:${e.trail}:${e.lift}`}function Ad(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 la(t,[e,n,s]){const i=Wt(t,[e,n,s]);return{x:i.x-t.center.x,y:i.y-t.center.y}}function Kw(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 jw(t,e,n,s,i){const o=t.ry,r=(e.length??1.8)*o,a=la(t,oa(s,Ui(i.swing))),l=la(t,[0,i.lift,-i.trail]),c=Math.hypot(a.x,a.y)||1,h=e.at==="high"||e.at==="low"||e.at==="top"?la(t,[.95,0,0]):{x:0},d=e.kind==="braid"?.15:.5,u={x:n.x+a.x/c*o*d+h.x*.9+l.x*.5,y:n.y+a.y/c*o*d*.6+l.y*.5},f={x:n.x+a.x/c*o*d*.6+h.x*1.3+l.x,y:n.y+r+l.y};return Kw(n,u,f)}const ca=t=>Math.max(1,t*.5),xd=(t,e)=>Math.max(.8,Math.min(t*.4,.1*e.rx));function $d(t,e,n,s,i,o){const{point:r,out:a}=Ad(s.at),l=1+n.volume,c=Wt(e,[r[0]*l,r[1]*l,r[2]*l]),h=ca(i),d=xd(i,e);if(s.kind==="bun"){const g=s.size??.32,m=Wt(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},(S,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}}),d);return}const u=jw(e,s,c,a,o),f=(s.size??(s.kind==="braid"?.2:.34))*e.rx*2;if(s.kind==="ponytail")t.shape(Nt(u,f,f*.15),n.color,h),t.line(u.slice(3,u.length-3),d);else{const m=u.slice(0,u.length-3);for(let k=0;k<7;k++){const y=m[Math.floor(k/7*(m.length-1))],E=m[Math.floor((k+1)/7*(m.length-1))],x=Math.atan2(E.y-y.y,E.x-y.x),$=Math.hypot(E.x-y.x,E.y-y.y),M=f*(1-k/(7*2.2)),v=(k%2===0?1:-1)*.35,T={x:(y.x+E.x)/2,y:(y.y+E.y)/2};t.ellipse(T.x,T.y,$*.62,M*.5,x+v,n.color,h*.8)}const w=m[m.length-1],S=u[u.length-1];t.shape(Nt([w,S],f*.7,f*.2),n.color,h*.8)}const p=u[s.kind==="braid"?u.length-4:2];t.ellipse(p.x,p.y,f*.32,f*.22,e.angle,n.color,h)}function Pd(t,e){return me(t,Ad(e.at).out)<-.2}function Xw(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=Ui(t.part??0),s=i=>As(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,As(t,r)<.9?.6:.9],[r,i],0));return t.part!==null&&o.push(e([n,s(n)],[n,.97])),o}default:return[]}}function Gw(t,e,n,s,i){if(s.fill==="stipple"||s.hairline.front>1.5)return;const o=i.motion??In,r=i.lineWidth*.45/n.rx,{far:a}=Td(n,s,Sd(s,r,o),o);ia(e,n,()=>{for(const l of s.ties)Pd(n,l)&&$d(t,n,s,l,i.lineWidth,o);for(const l of a)t.shape(l,s.color,ca(i.lineWidth))})}function Id(t,e,n,s){if(n.hairline.front>1.5)return;const i=s.motion??In,o=s.lineWidth*.45/e.rx,r=Sd(n,o,i),a=xd(s.lineWidth,e);if(n.fill==="stipple"){for(let h=.97;h>-1;h-=.17)for(let d=-Math.PI;d<Math.PI;d+=.27){const u=Math.round(h*100)%2*.13;if(r.inside(d+u,h)<.02)continue;const f=pe(d+u,h);if(me(e,f)<.12)continue;const p=Wt(e,f);t.dot(p.x,p.y,a*.4)}return}const{near:l}=Td(e,n,r,i),c=ca(s.lineWidth);for(const h of l)t.shape(h,n.color,c);for(const h of Xw(n)){const d=h.map(([f,p])=>{const[g,m,w]=r.position(f,p);return[g*.985,m*.985,w*.985]}),u=h.map(([f,p])=>r.normal(f,p));for(const f of md(e,d,u,.12))t.line(f,a)}for(const h of n.ties)Pd(e,h)||$d(t,e,n,h,s.lineWidth,i)}const Od=.35,ha=t=>({centre:[t*.98,-.02,-.08],out:[t,0,-.12]});function _d(t,e,n,s,i){const{centre:o,out:r}=ha(n),a=me(e,r),l=Math.max(1,s.lineWidth*.55),c=s.skin==="none"?null:s.skin,h=e.ry*.27;if(!i){const m=Wt(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 d=Wt(e,o),u=e.rx*(.12+.08*a);t.ellipse(d.x,d.y,u,h,e.angle,c,l);const f=Math.cos(e.angle),p=Math.sin(e.angle),g=Array.from({length:9},(m,w)=>{const S=-Math.PI*.55+w/8*Math.PI*1.1,k=Math.cos(S)*u*.45*-n,y=Math.sin(S)*h*.55;return{x:d.x+k*f-y*p,y:d.y+k*p+y*f}});t.line(g,Math.max(.8,l*.7))}function Uw(t,e,n,s){ia(e,n,()=>{for(const i of[1,-1])me(n,ha(i).out)<Od&&_d(t,n,i,s,!1)})}function Vw(t,e,n){for(const s of[1,-1])me(e,ha(s).out)>=Od&&_d(t,e,s,n,!0)}const da={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 Cd(t,e){const n=typeof t=="string"?{style:t}:t,s=n.style?da[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 Le=t=>t*Math.PI/180,Vi=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},Hd={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}},Jw=(t,e)=>{const n=Vi(Le(48),Le(100),ji(e,0));return t.top[0]+(t.top[1]-t.top[0])*n},Zw=t=>t==="sideburns"||t==="muttonChops";function ua(t,e){const n=Hd[t];if(!n)return null;const s=Le(n.reach),i=o=>{const r=ji(o,0);return n.shape==="point"?Math.exp(-((r/.42)**2)):n.shape==="square"?1-Vi(Le(45),Le(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=ji(o,0),l=Jw(n,o);let c=Math.min(l-r,s-a);if(n.band>0&&(c=Math.min(c,r-(l-n.band))),Zw(t)){const h=t==="muttonChops"?Le(70)-Le(22)*Vi(.08,-.6,r):Le(72);c=Math.min(c,a-h)}return c},position(o,r){const[a,l,c]=pe(o,r),h=1+e+n.volume,d=n.length*i(o)*Vi(-.45,-1,r);return[a*h,l*h-d,c*h+d*.25]},normal:(o,r)=>pe(o,r)}}function Qw(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 xs=t=>Math.max(1,t*.45);function t2(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(me(e,a)<.15)continue;const l=Wt(e,a);t.dot(l.x,l.y,s)}}function e2(t,e,n,s,i){const o=s.beard==="stubble"?null:ua(s.beard,i.lineWidth*.45/n.rx);if(!o)return;const{far:r}=sa(n,s,()=>Xi(n,o));ia(e,n,()=>{for(const a of r)t.shape(a,s.color,xs(i.lineWidth))})}function n2(t,e,n,s,i){if(n.beard==="none")return;const o=s.lineWidth*.45/e.rx;if(n.beard==="stubble"){t2(t,e,ua("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}=$t(e,l,{x:0,y:-.6});h>-.05&&t.shape(c,n.color,xs(s.lineWidth)*.7);return}const r=ua(n.beard,o);if(!r)return;const{near:a}=sa(e,n,()=>Xi(e,r));for(const l of a)t.shape(l,n.color,xs(s.lineWidth));if(Hd[n.beard]?.aroundMouth){const l=.27*Math.max(.3,i),c=Array.from({length:20},(u,f)=>{const p=Math.PI*2*f/20;return{x:Math.cos(p)*l,y:-.42+Math.sin(p)*.13}}),{points:h,facing:d}=$t(e,c,{x:0,y:-.42});d>-.05&&t.shape(h,s.skin==="none"?"#ffffff":s.skin,0)}}function s2(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(d=>({x:d,y:-.25+.03*Math.cos(d/.2*Math.PI)})),{points:c,facing:h}=$t(e,l,i);h>-.05&&t.line(c,Math.max(1,s.lineWidth*.32));return}const o=Qw(n.moustache);if(!o)return;const{points:r,facing:a}=$t(e,o,i);if(!(a<=-.05)&&(t.shape(r,n.color,xs(s.lineWidth)*.8),n.moustache==="handlebar"))for(const l of[1,-1]){const c=Array.from({length:10},(h,d)=>{const u=-Math.PI/2+d/9*Math.PI*1.4;return{x:l*(.27+.05*Math.cos(u)),y:-.21+.05*(1+Math.sin(u))}});c.unshift({x:l*.22,y:-.27}),t.line($t(e,c,i).points,xs(s.lineWidth)*.8)}}const fa={round:!0,square:!0,sunglasses:!0};function Rd(t){const n=(typeof t=="string"?{style:t}:t).style??"round";if(!(n in fa))throw new Error(`glasses: unknown style '${n}'`);return{style:n}}const Ld=.34,fe=.12,i2=.05;function o2(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:fe+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:fe-.01+Math.sign(a)*Math.abs(a)**.45*c}})}function r2(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=Ld*r,{points:l,facing:c}=$t(e,o2(n.style,a),{x:a,y:fe});if(c<i2)continue;o.push(r),t.shape(l,n.style==="sunglasses"?"#1f2328":null,i);const h=[r*.97,fe+.02,-.1];if(me(e,[r,0,0])>.15){const d=$t(e,[{x:a+r*.21,y:fe+.02}],{x:a,y:fe}).points[0];t.line([d,Wt(e,h)],i*.9)}}if(o.length===2){const r=[{x:Ld-.2,y:fe+.02},{x:0,y:fe+.07},{x:-.14,y:fe+.02}];t.line($t(e,r,{x:0,y:fe}).points,i)}}const Ji={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 Nd(t){const e=typeof t=="string"?{style:t}:t,n=e.style??"cap",s=Ji[n];if(!s)throw new Error(`hat: unknown style '${n}'`);return{style:n,color:e.color??s.color}}const tn=(t,e)=>t.brim[1]+(t.brim[0]-t.brim[1])*(1+Math.cos(e))/2;function a2(t,e){return{top:1,bottom:Math.min(...t.brim)-.05,inside:(n,s)=>s-tn(t,n),position(n,s){const[i,o,r]=pe(n,s),a=tn(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 l2(t,e,n){const i=(o,r,a)=>{const l=tn(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(Wt(t,[Math.sin(l)*(n+c*.25),tn(e,l)*n-.07*Math.cos(l),Math.cos(l)*(n+c)])),r.push(Wt(t,i(l,n,0)))}return[...o,...r.reverse()]}return e.ring?Array.from({length:48},(o,r)=>Wt(t,i(Math.PI*2*r/48,n+e.ring,.07))):null}function c2(t){const e=s=>Array.from({length:13},(i,o)=>[s,tn(t,s)+(.97-tn(t,s))*o/12]),n=s=>Array.from({length:49},(i,o)=>{const r=-Math.PI+Math.PI*2*o/48;return[r,tn(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 Dd(t,e,n,s){const i=Ji[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=l2(e,i,r);l&&t.shape(l,n.color,a);const c=a2(i,r),{near:h,far:d}=Xi(e,c);for(const f of[...d,...h])t.shape(f,n.color,a);const u=Math.max(.8,a*.7);for(const f of c2(i)){const p=f.map(([m,w])=>{const[S,k,y]=c.position(m,w);return[S*.99,k*.99,y*.99]}),g=f.map(([m,w])=>pe(m,w));for(const m of md(e,p,g,.1))t.line(m,u)}if(i.detail==="seams"){const f=Wt(e,[0,r*1.01,0]);t.dot(f.x,f.y,a*.9)}}function Fd(t){const e=t.hair?vd(t.hair):null;return{hair:e,facialHair:t.facialHair?Cd(t.facialHair,e?.color):null,glasses:t.glasses?Rd(t.glasses):null,hat:t.hat?Nd(t.hat):null,ears:t.ears??!1}}const Wd=t=>!t.hair&&!t.facialHair&&!t.glasses&&!t.hat&&!t.ears,Bd=t=>t.axes[2][2]<-.3,qd=t=>t.ears&&!t.hair?.coversEars;function zd(t,e,n,s,i,o){Wd(n)||(n.hair&&Gw(e,t,s,n.hair,{...o,motion:Gi(i)}),n.facialHair&&e2(e,t,s,n.facialHair,o),qd(n)&&Uw(e,t,s,o))}function h2(t,e,n,s,i,o,r){if(Wd(n)){r();return}const a=Bd(s);qd(n)&&Vw(e,s,o),n.hair&&!a&&Id(e,s,n.hair,{...o,motion:Gi(i)}),n.facialHair&&n2(e,s,n.facialHair,o,i.mouthWidth??1),r(),n.facialHair&&s2(e,s,n.facialHair,o),n.glasses&&r2(e,s,n.glasses,o),n.hat&&!a&&Dd(e,s,n.hat,{lineWidth:o.lineWidth,hairVolume:n.hair?.volume??0})}function Yd(t,e,n,s,i,o){Bd(s)&&(n.hair&&Id(e,s,n.hair,{...o,motion:Gi(i)}),n.hat&&Dd(e,s,n.hat,{lineWidth:o.lineWidth,hairVolume:n.hair?.volume??0}))}const Kd=40,d2=.215+.205,Kt=(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},ut=(t,e)=>t[e]??gt[e]??0;function ga(t,e,n=gt,s=1){const i=ps(t),o=e*Math.PI*2,r=Math.sin(o)*s,a=Math.cos(o)*s,l=(1+Math.cos(o*2*(i.bounces??1)))/2,c=i.crouch??0,h=i.shoulder??0,d=i.forearm??0,u={...gt,...n};u["leg.left.swing"]=i.swing*r+c*.6,u["leg.right.swing"]=-i.swing*r+c*.6,u["leg.left.knee"]=i.knee*Math.max(0,a)+c*1.2,u["leg.right.knee"]=i.knee*Math.max(0,-a)+c*1.2,u["leg.left.ankle"]=ut(n,"leg.left.ankle")-(i.tiptoe??0),u["leg.right.ankle"]=ut(n,"leg.right.ankle")-(i.tiptoe??0);for(const[f,p]of[["left",-1],["right",1]])ut(n,`arm.${f}.spread`)>Kd||ut(n,`arm.${f}.swing`)>Kd||(u[`arm.${f}.swing`]=h+p*i.arm*r,u[`arm.${f}.elbow`]=ut(n,`arm.${f}.elbow`)+d+i.elbow*Math.max(0,p*r));return u.lean=ut(n,"lean")+i.lean*s,u.bend=ut(n,"bend")+(i.bend??0),u["head.nod"]=ut(n,"head.nod")-i.lean*.5*s+(i.headTilt??0),u.side=ut(n,"side")+(i.sway??0)*Math.sin(o),u.lift=ut(n,"lift")+(i.bounce??0)*s*l,u.stretch=ut(n,"stretch")*(1+(i.squash??0)*(l-.5)),u}function pa(t,e,n=1,s=1){const i=ps(t);return 4*d2*s*e*Math.sin(i.swing*n*Math.PI/180)}const On=t=>Xr[t],Zi={take:t=>[{after:140,pose:{stretch:.8,bend:10,lean:ut(t,"lean")-4,...Kt("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,...Kt("arm",{spread:150,bend:35,swing:0,elbow:0}),...Kt("leg",{swing:25,knee:60}),...On("shocked")},easing:"ease-out-cubic"},{after:720,pose:{lift:.25,stretch:1.25,bend:-10,...Kt("arm",{spread:140})},easing:"ease-in-out"},{after:900,pose:{lift:0,stretch:.74,bend:12,...Kt("arm",{spread:70,bend:0}),...Kt("leg",{swing:30,knee:60})},easing:"ease-in-quad"},{after:1060,pose:{stretch:1.06,bend:-3,...Kt("arm",{spread:60}),"leg.left.swing":ut(t,"leg.left.swing"),"leg.right.swing":ut(t,"leg.right.swing"),"leg.left.knee":ut(t,"leg.left.knee"),"leg.right.knee":ut(t,"leg.right.knee")},easing:"ease-out"},{after:1260,pose:{stretch:ut(t,"stretch"),bend:ut(t,"bend"),...On("surprised"),...Kt("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":ut(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":ut(t,"head.nod")-10,bend:ut(t,"bend")-10,lift:.05,stretch:1.18,...On("shocked"),lookX:1,lookY:0},easing:"ease-out-cubic"},{after:1360,pose:{lift:0,stretch:.88,"head.nod":ut(t,"head.nod")-4,bend:ut(t,"bend")+4},easing:"ease-in-quad"},{after:1560,pose:{stretch:ut(t,"stretch"),"head.nod":ut(t,"head.nod"),bend:ut(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,...On("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,...Kt("arm",{spread:75}),...Kt("leg",{swing:25,knee:50})},easing:"ease-in-quad"},{after:300,pose:{stretch:1.05,bend:-4,"arm.left.spread":ut(t,"arm.left.spread"),"arm.right.spread":ut(t,"arm.right.spread")},easing:"ease-out"},{after:460,pose:{lift:0,stretch:ut(t,"stretch"),bend:ut(t,"bend"),...Kt("leg",{swing:0,knee:0})},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...On("scared"),...Kt("arm",{swing:40,elbow:110,spread:14}),stretch:.94,bend:ut(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:ut(t,"side")+2.5*s,"head.tilt":ut(t,"head.tilt")-2*s}})}return e.push({after:755,pose:{side:ut(t,"side"),"head.tilt":ut(t,"head.tilt"),bend:ut(t,"bend")}}),e},deflate:t=>[{after:260,pose:{stretch:1.04,"head.nod":ut(t,"head.nod")-4,"brow.left":.3,"brow.right":.3},easing:"ease-in-out"},{after:900,pose:{...On("sad"),bend:18,stretch:.92,lean:ut(t,"lean")+5,"head.nod":14,...Kt("arm",{spread:6,swing:0,elbow:4,bend:0})},easing:"ease-in-out"}]};function jd(t,e){const n=bt(e.from??{}),s=e.speed??1;let i=n;return[{time:e.at,pose:n},...Zi[t](n).map(o=>(i={...i,...o.pose},{time:e.at+o.after*s,pose:i,act:!1,...o.easing?{easing:o.easing}:{}}))]}function Xd(t,e=gt){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 Gd(t,e=gt){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 ma={sweeping:Xd,brushing:Gd};function u2(t,e,n=gt){const s=ma[t];if(!s)throw new Error(`humanCyclePose: ${dt("cycle",t,Object.keys(ma))}`);return s(e,n)}const f2={apron:"#d8b48a",labCoat:"#f4f6f8",hoodie:"#6b7280",cardigan:"#6b8e4e",overalls:"",sari:"#16a34a"},ya=(t,e,n)=>t.slice(Math.floor((t.length-1)*e),Math.ceil((t.length-1)*n)+1),yt=(t,e,n)=>({x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n});function g2(t){return ba(t,t.parts["leg.left"].depth)>ba(t,t.parts["leg.right"].depth)?"left":"right"}const ba=(t,e)=>Math.abs(e)<.01*t.height?0:e,Ud=t=>ba(t,Math.max(t.parts["leg.left"].depth,t.parts["leg.right"].depth))>0,Qt=t=>Math.cos(t.turn*Math.PI/2);function Vd(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"?f2[t.over]:n),d=t.shoes==="boots",u=t.shoeColor??"#3b2a1e",f=A=>A.lineWidth*.45,p=(A,R,N)=>{const P=A.parts[`leg.${N}`].points;if(!(i==="skirt"&&!l)){if(i==="shorts"&&!l){const L=ya(P,0,.5);R.shape(Nt(L,A.height*.085,A.height*.07),n,f(A));return}R.shape(Nt(P,A.height*.08,A.height*.05),n,f(A))}},g=(A,R,N)=>{const P=A.parts[`leg.${N}`].points,L=ya(P,.7,1);if(L.length<2)return;R.shape(Nt(L,A.height*.075,A.height*.07),u,f(A));const W=L[0],z=L[1],B=z.x-W.x,Y=z.y-W.y,V=Math.hypot(B,Y)||1,F=A.height*.04;R.line([{x:W.x-Y/V*F,y:W.y+B/V*F},{x:W.x+Y/V*F,y:W.y-B/V*F}],f(A)*.9)},m=A=>{const R=A.chains.spine,N=R[0],P=R[R.length-1],L={x:N.x-(P.x-N.x)*.25,y:N.y-(P.y-N.y)*.25};return{hip:N,top:P,below:L,line:[L,...A.parts.spine.points]}},w=(A,R)=>{const N=r?h:e,P=r?1.14:1;R.shape(Nt(m(A).line,A.height*.15*P,A.height*.14*P),N,f(A))},S=(A,R)=>{const N=Qt(A),{top:P,hip:L}=m(A),W=A.height*.07,z={x:(P.x-L.x)*.16,y:(P.y-L.y)*.16};if(N>=0){R.shape([{x:P.x-W,y:P.y+z.y*.25},{x:P.x-W*.8+z.x,y:P.y+z.y},{x:P.x+z.x*1.2,y:P.y+z.y*1.35},{x:P.x+W*.8+z.x,y:P.y+z.y},{x:P.x+W,y:P.y+z.y*.25}],h,f(A));return}const B=yt(P,L,.42);R.shape([{x:P.x-W*.9,y:P.y},{x:P.x+W*.9,y:P.y},{x:B.x+W*.7,y:B.y},{x:B.x,y:B.y+A.height*.02},{x:B.x-W*.7,y:B.y}],h,f(A))},k=(A,R)=>{const N=Qt(A);if(N<.2)return;const{top:P,hip:L}=m(A),W=Math.sin(A.turn*Math.PI/2)*A.height*.03,z=A.height*.06*N,B=yt(P,L,.62),Y=yt(P,L,.9);R.line([{x:B.x+W-z,y:B.y},{x:Y.x+W-z*1.1,y:Y.y}],f(A)*.7),R.line([{x:B.x+W+z,y:B.y},{x:Y.x+W+z*1.1,y:Y.y}],f(A)*.7);const V=yt(P,L,.1);for(const F of[-1,1])R.line([{x:V.x+W+F*z*.2,y:V.y},{x:V.x+W+F*z*.35,y:V.y+A.height*.07}],f(A)*.6)},y=(A,R)=>{const{top:N,hip:P}=m(A),L=Qt(A);if(R.shape(Nt([N,yt(N,P,.5),yt(N,P,1.08)],A.height*.155,A.height*.15),h,f(A)),L<.2)return;const W=Math.sin(A.turn*Math.PI/2)*A.height*.03,z=A.height*.02*L,B=yt(N,P,.12),Y=yt(N,P,1.05);R.shape([{x:B.x+W-z,y:B.y},{x:B.x+W+z,y:B.y},{x:Y.x+W+z*1.3,y:Y.y},{x:Y.x+W-z*1.3,y:Y.y}],e,f(A)*.7);for(const V of[.35,.55,.75]){const F=yt(N,P,V);R.dot(F.x+W+z*1.6,F.y,f(A)*1.2)}},E=(A,R)=>{const N=Qt(A),{top:P,hip:L}=m(A),W=Math.sin(A.turn*Math.PI/2)*A.height*.04,z=yt(L,P,.12),B=yt(L,P,.74);if(N<.15){if(N<-.3){const U=A.points["shoulder.left"],K=A.points["shoulder.right"];R.line([U,{x:z.x+A.height*.03,y:z.y}],f(A)*.8),R.line([K,{x:z.x-A.height*.03,y:z.y}],f(A)*.8)}return}const Y=A.height*.07*N;R.shape([{x:B.x+W-Y*.75,y:B.y},{x:B.x+W+Y*.75,y:B.y},{x:z.x+W+Y*1.1,y:z.y},{x:z.x+W-Y*1.1,y:z.y}],n,f(A));for(const U of["left","right"]){const K=A.points[`shoulder.${U}`],st={x:B.x+W+(K.x>B.x+W?1:-1)*Y*.55,y:B.y};R.line([st,{x:K.x+(st.x-K.x)*.15,y:K.y+(st.y-K.y)*.15}],f(A)*1.6)}const V=yt(B,z,.3),F=Y*.4;R.line([{x:V.x+W-F,y:V.y},{x:V.x+W-F,y:V.y+F*1.4},{x:V.x+W+F,y:V.y+F*1.4},{x:V.x+W+F,y:V.y}],f(A)*.6)},x=(A,R)=>{const{hip:N,top:P}=m(A),L=yt(N,P,.2),W=[A.points["ankle.left"],A.points["ankle.right"]],z=yt(N,{x:(W[0].x+W[1].x)/2,y:(W[0].y+W[1].y)/2},.98),B=A.height*.075,Y=Math.max(A.height*.12,Math.abs(W[0].x-W[1].x)/2+A.height*.07),V=z.x-L.x,F=z.y-L.y,U=Math.hypot(V,F)||1,K={x:-F/U,y:V/U};if(R.shape([{x:L.x+K.x*B,y:L.y+K.y*B},{x:z.x+K.x*Y,y:z.y+K.y*Y},{x:z.x-K.x*Y,y:z.y-K.y*Y},{x:L.x-K.x*B,y:L.y-K.y*B}],h,f(A)),Qt(A)>.2){const ot=Math.sin(A.turn*Math.PI/2)*A.height*.03;for(const rt of[-.35,0,.35]){const at=B*.5*rt,H=Y*.45*rt;R.line([{x:L.x+ot+K.x*at,y:L.y+K.y*at+A.height*.02},{x:z.x+ot+K.x*H,y:z.y+K.y*H}],f(A)*.5)}}},$=(A,R)=>{const N=Qt(A),{top:P,hip:L}=m(A),W=Math.sin(A.turn*Math.PI/2),z=W>=0?"left":"right",B=z==="left"?"right":"left",Y=A.points[`shoulder.${z}`],V=A.height*.035;if(N<.15){const K=yt(P,L,.9);R.shape(Nt([Y,{x:K.x+(Y.x-P.x)*.5,y:K.y}],V*2.2,V*2.6),h,f(A));return}const F={x:L.x+(A.points[`hip.${B}`].x-L.x)*1.2,y:yt(L,P,.08).y};R.shape(Nt([F,yt(F,Y,.5),Y],V*2.4,V*2),h,f(A));const U={x:Y.x-(L.x-Y.x)*.05-W*A.height*.03,y:Y.y+A.height*.16};R.shape(Nt([Y,U],V*2,V*1.6),h,f(A))},M=(A,R)=>{const{hip:N,top:P}=m(A),L=yt(N,P,.18),W=[A.points["knee.left"],A.points["knee.right"]],z=yt(N,{x:(W[0].x+W[1].x)/2,y:(W[0].y+W[1].y)/2},1.05),B=A.height*.075,Y=Math.max(A.height*.13,Math.abs(W[0].x-W[1].x)/2+A.height*.08),V=z.x-L.x,F=z.y-L.y,U=Math.hypot(V,F)||1,K={x:-F/U,y:V/U};R.shape([{x:L.x+K.x*B,y:L.y+K.y*B},{x:z.x+K.x*Y,y:z.y+K.y*Y},{x:z.x-K.x*Y,y:z.y-K.y*Y},{x:L.x-K.x*B,y:L.y-K.y*B}],n,f(A))},v=(A,R)=>{const N=Qt(A);if(N<.2)return;const{top:P,hip:L}=m(A),W={x:(L.x-P.x)*.12,y:(L.y-P.y)*.12},z=A.height*.045*N;for(const B of[-1,1])R.shape([{x:P.x+B*z*.2,y:P.y+W.y*.1},{x:P.x+B*z*1.3,y:P.y-W.y*.1},{x:P.x+B*z*.6+W.x,y:P.y+W.y}],e,f(A)*.8)},T=(A,R,N)=>{const P=Qt(A);if(P<.25)return;const{top:L,hip:W}=m(A),z=Math.sin(A.turn*Math.PI/2)*A.height*.03,B=U=>({x:yt(L,W,U).x+z,y:yt(L,W,U).y}),Y=A.height*.022*P,V=B(.08),F=B(.62);R.shape([{x:V.x-Y,y:V.y-Y},{x:V.x+Y,y:V.y-Y},{x:V.x+Y*.6,y:V.y+Y},{x:V.x-Y*.6,y:V.y+Y}],N,f(A)*.7),R.shape([{x:V.x-Y*.6,y:V.y+Y},{x:V.x+Y*.6,y:V.y+Y},{x:F.x+Y*1.4,y:F.y-Y*2},F,{x:F.x-Y*1.4,y:F.y-Y*2}],N,f(A)*.7)},I=(A,R)=>{const N=Qt(A),{top:P,hip:L}=m(A),W=yt(L,P,.72),z=[A.points["knee.left"],A.points["knee.right"]],B=yt(L,{x:(z[0].x+z[1].x)/2,y:(z[0].y+z[1].y)/2},.9),Y=Math.sin(A.turn*Math.PI/2)*A.height*.04;if(N<.15){const U=yt(L,P,.2);N<-.3&&R.line([{x:U.x-A.height*.05,y:U.y},{x:U.x+A.height*.05,y:U.y}],f(A));return}const V=A.height*.075*N,F=yt(L,P,.2);R.shape([{x:W.x+Y-V*.7,y:W.y},{x:W.x+Y+V*.7,y:W.y},{x:F.x+Y+V,y:F.y},{x:B.x+Y+V*1.15,y:B.y},{x:B.x+Y-V*1.15,y:B.y},{x:F.x+Y-V,y:F.y}],h,f(A)),R.line([{x:W.x+Y-V*.6,y:W.y},{x:P.x-V*.2,y:P.y},{x:W.x+Y+V*.6,y:W.y}],f(A)*.8)},O=(A,R,N)=>{const{top:P,hip:L}=m(A),W=[A.points["knee.left"],A.points["knee.right"]],z=yt(L,{x:(W[0].x+W[1].x)/2,y:(W[0].y+W[1].y)/2},.95);N?R.shape(Nt([yt(P,L,.8),L,z],A.height*.145,A.height*.17),h,f(A)):R.shape(Nt([P,yt(P,L,.5),L],A.height*.14,A.height*.15),h,f(A));const B=Qt(A);if(B>.2){const Y=Math.sin(A.turn*Math.PI/2)*A.height*.03,[V,F]=N?[L,z]:[P,L];if(R.line([{x:V.x+Y,y:V.y},{x:F.x+Y,y:F.y}],f(A)*.8),!N){const U=yt(P,L,.35),K=A.height*.025*B;R.shape([{x:U.x+Y-K*2.4,y:U.y},{x:U.x+Y-K*.6,y:U.y},{x:U.x+Y-K*.6,y:U.y+K*1.6},{x:U.x+Y-K*2.4,y:U.y+K*1.6}],h,f(A)*.6)}}},_=(A,R,N,P,L)=>{const W=A.parts[`arm.${N}`].points,z=W[0],B=A.chains.spine[A.chains.spine.length-1],V=[{x:z.x+(B.x-z.x)*.45,y:z.y+(B.y-z.y)*.45},...ya(W,0,L)],F=Nt(V,A.height*.085,A.height*(L>.6?.045:.06)),U=V.length,K=F.slice(0,U),st=F.slice(U).reverse();R.shape(F,P,0);const ot=H=>Math.hypot(H[1].x-B.x,H[1].y-B.y),[rt,at]=ot(K)>ot(st)?[K,st]:[st,K];R.line(rt.slice(1),f(A)),R.line(at.slice(Math.ceil(U*.45)),f(A)),R.line([K[U-1],st[U-1]],f(A))},C=o||r||a,D=C?h:e,q=C||s==="long"?.95:.45,X=C||s!=="none",J=(A,R)=>{i==="skirt"&&!l&&!c&&M(A,R),c&&x(A,R),o&&O(A,R,!0),t.over==="apron"&&I(A,R)},j=A=>(R,N,P)=>{p(N,P,A),d&&g(N,P,A),g2(N)===A&&Ud(N)&&J(N,P)};return{parts:{"leg.left":{over:j("left")},"leg.right":{over:j("right")},spine:{over:(A,R,N)=>{r&&Qt(R)>=0&&S(R,N),w(R,N),t.collar&&!r&&v(R,N),t.tie&&!r&&T(R,N,t.tie),o&&O(R,N,!1),a&&y(R,N),r&&(Qt(R)<0&&S(R,N),k(R,N)),l&&E(R,N),c&&$(R,N),Ud(R)||J(R,N)}},"arm.left":{over:X?(A,R,N)=>_(R,N,"left",D,q):void 0},"arm.right":{over:X?(A,R,N)=>_(R,N,"right",D,q):void 0}}}}const wa={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 Jd(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=wa[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 Qi(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 _n(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 Cn=(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 ka(t,e,n,s,i,o=1,r){const{point:a,along:l}=n,c=s/300;switch(e.item){case"mug":{const h=_n({x:a.x,y:a.y-4*c},20*c,24*c);t.line(Cn({x:a.x+10*c*Math.sign(o||1),y:a.y-4*c},7*c,-Math.PI/2,Math.PI/2).map(d=>({x:a.x+(d.x-a.x)*Math.sign(o||1),y:d.y})),i),t.shape(h,e.color,i);return}case"phone":{const h=Math.atan2(l.y,l.x)-Math.PI/2;t.shape(_n(a,13*c,24*c,h),e.color,i),t.shape(_n(a,9*c,17*c,h),"#8fd0f5",0);return}case"book":{const h=26*c,d=34*c;t.shape([{x:a.x,y:a.y-d/2},{x:a.x-h,y:a.y-d/2-3*c},{x:a.x-h,y:a.y+d/2-3*c},{x:a.x,y:a.y+d/2}],e.color,i),t.shape([{x:a.x,y:a.y-d/2},{x:a.x+h,y:a.y-d/2-3*c},{x:a.x+h,y:a.y+d/2-3*c},{x:a.x,y:a.y+d/2}],e.color,i);for(const u of[-1,1])for(const f of[.3,.5,.7]){const p=a.y-d/2+d*f;t.line([{x:a.x+u*5*c,y:p},{x:a.x+u*(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(Cn({x:a.x,y:a.y+6*c},7*c,Math.PI,Math.PI*2),i),t.shape(_n({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,d=(r??a.y-120*c)-14*c,u={x:a.x,y:Math.min(a.y-60*c,d-h*.55)};t.line([{x:a.x,y:a.y+10*c},u],i),t.line(Cn({x:a.x+5*c,y:a.y+10*c},5*c,Math.PI,0,8),i);const f=[...Cn({x:u.x,y:u.y+h*.55},h,Math.PI,Math.PI*2,24)],p=[];for(let g=4;g>=0;g--){const m=u.x-h+2*h*g/5;p.push(...Cn({x:m+h/5,y:u.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)},d=Math.hypot(h.x,h.y),u={x:h.x/d,y:h.y/d},f={x:a.x-u.x*40*c,y:a.y-u.y*40*c},p={x:a.x+u.x*120*c,y:a.y+u.y*120*c};t.line([f,p],i*1.1);const g={x:-u.y,y:u.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+u.x*34*c,y:p.y-g.y*16*c+u.y*34*c},{x:p.x+g.x*16*c+u.x*34*c,y:p.y+g.y*16*c+u.y*34*c}];t.shape(m,e.color,i);return}case"cane":{const h=Math.min(.56*s,Math.max(.3*s,-a.y)),d=.12*Math.sign(o||1),u={x:d/Math.hypot(d,1),y:1/Math.hypot(d,1)},f={x:a.x+u.x*h,y:a.y+u.y*h},p=Cn({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(_n({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(_n(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 va=(t,e)=>(t[`held.${e}`]??1)>=.5,Zd=t=>Math.sin(t*Math.PI/2);function Qd(t){const e=o=>Math.max(1,o.lineWidth*.45),n=o=>(r,a,l,c,h)=>{const d=t[o];d&&va(h??{},o)&&ka(l,d,Qi(a,o),a.height,e(a),Zd(a.turn),a.head.center.y-a.head.ry)},s=(o,r,a,l,c)=>{const h=t.both;if(!h||!va(c??{},"both"))return;const d=Qi(r,"left"),u=Qi(r,"right"),f={point:{x:(d.point.x+u.point.x)/2,y:(d.point.y+u.point.y)/2},along:{x:(d.along.x+u.along.x)/2,y:(d.along.y+u.along.y)/2},depth:(d.depth+u.depth)/2};ka(a,h,f,r.height,e(r),Zd(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,d)=>{const u=r==="left"?"right":"left";(r==="left"?l.parts["arm.left"].depth>=l.parts["arm.right"].depth:l.parts["arm.right"].depth>l.parts[`arm.${u}`].depth)&&s(a,l,c,h,d)};for(const r of["left","right"])i.parts[`arm.${r}`]={...i.parts[`arm.${r}`],over:p2(i.parts[`arm.${r}`]?.over,o(r))}}return i}function p2(t,e){return t?(n,s,i,o,r)=>{t(n,s,i,o,r),e(n,s,i,o,r)}:e}function tu(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),over:n(o?.over,r?.over)}}return{behind:n(t.behind,e.behind),parts:s,front:n(t.front,e.front)}}function Ma(t={}){if(t.build&&!(t.build in Li))throw new Error(`character: unknown build '${t.build}'`);const e=t.build?Li[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?Vd(t.outfit):null,l=t.holding?Jd(t.holding):{};let c=a?tu(a,t.layers??{}):t.layers??{};return Object.keys(l).length>0&&(c=tu(c,Qd(l))),{plan:t.plan??id({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:Fd(t),face:{teeth:t.face?.teeth??!1,tongue:t.face?.tongue??!1}}}function m2(t,e,n,s){const{point:i,facing:o}=Qr(t,[e,n,s]);return{point:i,facing:o}}const Sa=t=>t.rest[1]<-.5,y2=.3;function b2(t,e,n){return t.figure==="stick"?Sa(e)?n.slice(0,3):n:Sa(e)&&n.length>=3?Ze(n[0],n[1],n[2],y2):n.length===3?Ze(n[0],n[1],n[2],1):n}function Ta(t,e){const n=t.plan.id==="human"?{...gt,...e}:e;return to(t,n,Jr(t.plan,n,{height:t.height,contact:t.contact}))}function to(t,e,n){const s={},i={},o={},r=.01*t.height;t.plan.chains.forEach(u=>{const f=n.chains[u.id];s[u.id]=f.points;const p=f.depths.reduce((S,k)=>S+k,0)/f.depths.length,g=u.parent?n.chains[u.parent]:void 0,m=g?g.depths[u.at??g.depths.length-1]:0,w=p-m;o[u.id]=Math.abs(w)<r?0:w,i[u.id]={points:b2(t,u,f.points),depth:p}}),i.head={points:[n.head.center],depth:n.head.depth},o.head=0;const a=[...t.plan.chains.map(u=>u.id),"head"],l=[...a].sort((u,f)=>o[u]-o[f]||a.indexOf(u)-a.indexOf(f)),c={hip:n.hip};for(const[u,[f,p]]of Object.entries(t.plan.landmarks??{})){const g=n.chains[f]?.points;g&&(c[u]=g[Math.min(p,g.length-1)])}const h={};for(const[u,f]of Object.entries(c))h[u]=f.y>=n.groundY-.01*t.height;const d={height:t.height,lineWidth:t.lineWidth,turn:e.turn??0,points:c,chains:s,parts:i,head:n.head,groundY:n.groundY,grounded:h};return{skeleton:n,joints:d,order:l}}function te(t,e){return Ta(t,e).joints}function eu(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=$t(s,i,{x:0,y:0});r.facing>0&&t.guide(r.points),t.guide($t(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 nu(t,e,n,s,i,o){const r=n.lineWidth;if(i==="head"){const{head:f}=s,p=n.skin==="none"?null:n.skin;e.ellipse(f.center.x,f.center.y,f.rx,f.ry,f.angle,p,r),h2(t,e,n.head,f,o,{lineWidth:r,skin:n.skin},()=>{e.look!=="silhouette"&&Nw(e,f,o,r,n.face)});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(Sa(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."))w2(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"],S=s.points["shoulder.right"];w&&S&&Math.hypot(w.x-S.x,w.y-S.y)>.5&&e.limb(Ze(w,l[l.length-1],S,1,10),r*1.15,r*1.15);return}const[d,u]=h(0,a.bones.length-1);e.limb(c,d,u)}function su(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 w2(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;Si(t,r,su(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 iu(t,e,n,s=0){const i=e.plan.id==="human"?{...gt,...n}:n;ru(t,e,i,Ta(e,i),s)}function Ea(t,e){const n=e/t.height;return{...t,height:e,lineWidth:t.lineWidth*n}}function k2(t,e,n,s){const i=t.plan.id==="human"?{...gt,...e}:e,o=Bi(t.plan,i,{height:s.height,contact:t.contact},n);return to(Ea(t,o.height),i,o).joints}function v2(t,e,n,s,i){const o=e.plan.id==="human"?{...gt,...n}:n,r=Bi(e.plan,o,{height:i.height,contact:e.contact},s),a=Ea(e,r.height);ru(t,a,o,to(a,o,r),i.time??0)}function ou(t,e,n,s){const i=t.plan.id==="human"?{...gt,...e}:e,o=Bi(t.plan,i,{height:s.height,contact:t.contact},n),r=Ea(t,o.height),{joints:a,order:l}=to(r,i,o),c=o.height/s.height;return l.map((h,d)=>({part:h,depth:(a.parts[h]?.depth??0)/c,draw(u,f=0){const p=us(u,{look:r.look,ink:r.ink,lineWidth:r.lineWidth,seed:Gt(`${r.seed}:${h}`),time:f,pencil:r.pencil}),g=w=>{w&&(u.save(),w(u,a,p,f,i),u.restore())};u.save(),u.lineCap="round",u.lineJoin="round",d===0&&(r.look==="pencil"&&r.pencil.construction!==!1&&eu(p,r,a),g(r.layers.behind),zd(u,p,r.head,a.head,i,{lineWidth:r.lineWidth,skin:r.skin}));const m=r.layers.parts?.[h];g(m?.under),nu(u,p,r,a,h,i),g(m?.over),d===l.length-1&&(Yd(u,p,r.head,a.head,i,{lineWidth:r.lineWidth,skin:r.skin}),g(r.layers.front)),u.restore()}}))}function ru(t,e,n,s,i){const{joints:o,order:r}=s,a=us(t,{look:e.look,ink:e.ink,lineWidth:e.lineWidth,seed:e.seed,time:i,pencil:e.pencil}),l=c=>{c&&(t.save(),c(t,o,a,i,n),t.restore())};t.save(),t.lineCap="round",t.lineJoin="round",e.look==="pencil"&&e.pencil.construction!==!1&&eu(a,e,o),l(e.layers.behind),zd(t,a,e.head,o.head,n,{lineWidth:e.lineWidth,skin:e.skin});for(const c of r){const h=e.layers.parts?.[c];l(h?.under),nu(t,a,e,o,c,n),l(h?.over)}Yd(t,a,e.head,o.head,n,{lineWidth:e.lineWidth,skin:e.skin}),l(e.layers.front),t.restore()}function au(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 ye(t,e,n,s){const i=t.plan.id==="human"?{...gt,...e}:e;let o;if(Array.isArray(s))o=s;else{const{skeleton:r}=Ta(t,i),a=Jr(t.plan,{...i,roll:0},{height:t.height,contact:"none"}),l=(i.roll??0)*Math.PI/180,c=s.x-r.hip.x,h=s.y-r.hip.y,d=a.hip.x+c*Math.cos(-l)-h*Math.sin(-l),u=a.hip.y+c*Math.sin(-l)+h*Math.cos(-l),f=Math.PI/2*(i.turn??0),p=s.depth??r.chains[n].depths[r.chains[n].depths.length-1],g=Math.cos(f),m=Math.sin(f);o=[d*g-p*m,-u,d*m+p*g]}return Iw(t.plan,i,n,o,{height:t.height})}const lu=new Set(["walk","walking","gait"]);function eo(t,e=gt,n){let s={...e};for(const[o,r]of Object.entries(t))typeof r=="number"&&!lu.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=ga(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 M2(t){const{character:e}=t,n=e.height*.8,s=e.height,i=e.plan.id==="human"?gt:{};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),iu(o,e,eo(r.props??{},i,t.gaits),a)}}}function cu(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 S2(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"||lu.has(c))&&(i[c]=h);const a=eo(i,s.plan.id==="human"?gt:{},t.gaits),l=te(s,a);return{pose:a,joints:cu(l,t.x+o+t.width/2,t.y+r+t.height)}}function Aa(t,e=gt){const n=[];return t.forEach((s,i)=>{const o=i===0?e:n[i-1],r=typeof s.pose=="string"?ie[s.pose]:void 0;n.push(r?{...r,turn:o.turn??0}:{...o,...s.pose})}),n}function T2(t,e,n=gt){const s=Aa(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 xa=new Map;function E2(t){const e=xa.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 xa.size<512&&xa.set(t,n),n}Xe([-3,-5,-4]);const A2=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)};function hu(t,e,n){const s=[0,0,0];for(const i of n){const o=E2(i.color);let r;if(i.light==="ambient")r=i.intensity;else if(i.light==="directional")r=i.intensity*Math.max(0,-Pe(e,i.direction));else{const a=wn(i.position,t),l=li(a),c=l>0?kn(a,1/l):e,h=i.range?Math.max(0,1-l/i.range)**2:1;if(r=i.intensity*Math.max(0,Pe(e,c))*h,i.light==="spot"){const d=Math.cos(i.angle*Math.PI/180),u=Math.cos(i.angle*.8*Math.PI/180);r*=A2(d,u,-Pe(c,i.direction))}}s[0]+=o[0]*r,s[1]+=o[1]*r,s[2]+=o[2]*r}return s}function du(t,e){return t?Math.min(1,Math.max(0,(e-t.near)/(t.far-t.near))):0}function $a(t,e,n={}){t.save(),x2(t,e,n),t.restore()}function x2(t,e,n){const s=Pa(e,n);n.shadow!==!1&&Ia(t,e,n);for(const i of e.under)uu(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)uu(t,i,s,n)}function uu(t,e,n,s){const i=s.loose?.[e.part.id];if(!i){Ca(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),Ca(t,e,n,s),t.restore()}function Pa(t,e={}){return e.lineWidth??Math.max(1.3,t.sizePx*.022)}function Ia(t,e,n={}){e.shadow.opacity<=0||e.shadow.points.length<3||(t.save(),t.globalAlpha=e.shadow.opacity,no(t,e.shadow.points,n.ink??"#26262b",!1),t.restore())}function $2(t,e,n,s={}){t.save(),Ca(t,e,n,s),t.restore()}function fu(t,e,n,s={}){const i=s.style==="stick",o=e.flatMap(h=>{if(i&&h.part.solidOnly)return[];const d=h.part.layer??0;return i&&h.spine?[{depth:h.depth,layer:d,part:h}]:h.faces.map(u=>({depth:u.depth,layer:d,part:h,face:u}))}),r=new Map;for(const h of o){const d=h.face?.normal;if(!h.face?.center||!d)continue;const u=Math.abs(d[0])>=Math.abs(d[1])&&Math.abs(d[0])>=Math.abs(d[2])?0:Math.abs(d[1])>=Math.abs(d[2])?1:2,f=u*2+(d[u]<0?1:0);r.set(f,[...r.get(f)??[],h])}for(const h of r.values())for(const d of h){const{center:u,normal:f}=d.face;for(const p of h){if(p.part.part.id===d.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]*(u[0]-g.center[0])+g.normal[1]*(u[1]-g.center[1])+g.normal[2]*(u[2]-g.center[2]);w>-gu/5&&w<gu&&(d.layer=Math.max(d.layer,p.layer),d.depth=Math.max(d.depth,p.depth+1e-6))}}o.sort((h,d)=>h.layer-d.layer||h.depth-d.depth);const a=new Map,l=h=>{let d=a.get(h.part.id);return d||a.set(h.part.id,d=Oa(t,h,n,s)),d};t.save();const c=t.globalAlpha;for(const{part:h,face:d}of o){t.globalAlpha=c*h.opacity;const u=l(h);if(!d)u.line(h.spine,n*1.15);else{const f=i?pu(h,s):d.light?P2(h,d,s):_a(h);f&&(!i&&s.look==="silhouette"?u.shape(d.points,f,0):no(t,d.points,i||d.light?f:so(f,d.tone),!0,h.cut?1.6:.8));const p=(h.part.outline??1)*n;if(p>0)for(const g of d.edges??[])g.length>1&&u.line(g,p);for(const g of d.marks??[])u.line(g,n*.7)}}t.restore()}const gu=.05;function Oa(t,e,n,s){return us(t,{look:s.look??"clean",ink:e.part.ink??s.ink??"#26262b",lineWidth:n,seed:Gt(`${s.seed??0}:${e.part.id}`),time:s.time??0,pencil:{construction:!1,rubbedOut:0,...s.pencil}})}function _a(t){const{part:e}=t;return e.glow&&t.glow>0&&e.fill?La(e.fill,e.glow.color,t.glow):e.fill}function P2(t,e,n){const{part:s}=t;if(!s.fill)return;const i=Ra(s.fill,e.light,e.fog??0,n.fog);return s.glow&&t.glow>0?La(i,s.glow.color,t.glow):i}function pu(t,e){const n=_a(t);return n&&(O2(n)||t.glow>0)?n:e.paper??"#fbf8ef"}function Ca(t,e,n,s){e.opacity<1?(t.save(),t.globalAlpha*=e.opacity,mu(t,e,n,s),t.restore()):mu(t,e,n,s)}function mu(t,e,n,s){if(s.style==="stick")return I2(t,e,n,s);const{part:i}=e,o=Oa(t,e,n,s),r=_a(e),a=s.look==="silhouette";for(const c of e.faces)r&&(a?o.shape(c.points,r,0):no(t,c.points,so(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 I2(t,e,n,s){const{part:i}=e;if(i.solidOnly)return;const o=Oa(t,e,n,s);if(e.spine){o.line(e.spine,n*1.15);return}const r=pu(e,s);for(const l of e.faces)no(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 O2(t){const e=Hn(t);return e?(.299*e[0]+.587*e[1]+.114*e[2])/255<.3:!1}function no(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 Hn(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 Ha=t=>`#${t.map(e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0")).join("")}`;function so(t,e){const n=Hn(t);return n?Ha(e>=1?n.map(s=>s+(255-s)*(e-1)*2):n.map(s=>s*e)):t}function Ra(t,e,n,s){const i=Hn(t);if(!i)return t;let o=i.map((a,l)=>a*e[l]);const r=s?Hn(s):void 0;return r&&n>0&&(o=o.map((a,l)=>a+(r[l]-a)*n)),Ha(o)}function La(t,e,n){const s=Hn(t),i=Hn(e);return!s||!i?n<.5?t:e:Ha(s.map((o,r)=>o+(i[r]-o)*n))}const _2=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),C2=new Set(["walk","walking","gait"]),yu=t=>typeof t=="number"?t:void 0,H2=1.7;function R2(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 L2(t){const e=Pe([0,1,0],t);if(e>.999999)return ci();if(e<-.999999)return ne(Xt([1,0,0],180));const n=ai([0,1,0],t);return ne(Xt(n,Math.acos(e)*180/Math.PI))}function N2(t,e,n,s,i){const o=t.solid??{},r=o.outline===!1?void 0:o.outline??{width:2,color:"#0f172a"},a={color:o.color??"#475569",shading:o.shading??"toon",outline:r},l={color:o.skin??"#f2c49b",shading:o.shading??"toon",outline:r},c={color:"#0f172a",shading:"unlit"},h=s.height*.034,d=[],u=(k,y,E)=>d.push({mesh:k,world:At(i,y),material:E}),f=(k,y,E)=>u(e.sphere,ar(k,[0,0,0,1],[y,y,y]),E);for(const k of n.chains){const y=s.chains[k.id],E=k.id==="spine"?1.9:1;k.bones.forEach((x,$)=>{const M=y[$],v=y[$+1],T=rr(M,v),[I,O]=x.width??[1,1],_=h*E*(I+O)/2;if(T>1e-6){const C=Zc(M,v,.5),D=L2(Xe(wn(v,M)));u(e.cylinder,At(Ge(C),At(D,Ue([_,T,_]))),a)}f(M,h*E*I,a),f(v,h*E*O,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,S=[...w[0],0,...w[1],0,...w[2],0,...p,1];u(e.sphere,At(S,Ue([g,m,g])),l);for(const k of[-1,1]){const y=Xe([k*.36,.15,.92]),E=ri(p,ri(ri(kn(w[0],y[0]*g*1.04),kn(w[1],y[1]*m*1.04)),kn(w[2],y[2]*g*1.04))),x=[...w[0],0,...w[1],0,...w[2],0,...E,1];u(e.sphere,At(x,Ue([g*.11,m*.14,g*.03])),c)}return d}const D2={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:Ma({...t.character,height:1}),cylinder:qi(cd(1,1,16)),sphere:qi(Pw(1,20))}},resolve({object:t,prepared:e,values:n,world:s,camera:i,lights:o=[],fog:r,toScreen:a}){const l=t,c=e,h=c.who;let d={...gt,...l.pose};for(const[M,v]of n)typeof v=="number"&&!_2.has(M)&&!C2.has(M)&&(d[M]=v);const u=Math.max(0,Math.min(1,yu(n.get("walking"))??l.walking??0));if(u>0){const M=typeof n.get("gait")=="string"?n.get("gait"):l.gait,v=ga(M,yu(n.get("walk"))??0,d);d=Object.fromEntries(Object.keys({...d,...v}).map(T=>[T,(d[T]??0)+((v[T]??0)-(d[T]??0))*u]))}const f=l.height??H2,p=At(i.view,s),g={toView:M=>Bt(p,M),toScreen:M=>a(M)},w=-g.toView([0,f/2,0])[2];if(w<=i.near)return null;const S=l.shadow===!1?[]:[{depth:w+f,draw:M=>R2(M,g,f*.18)}];if(l.look==="solid"){const M=Wi(h.plan,d,{height:f,contact:h.contact});return{meshes:N2(l,c,h.plan,M,s),drawables:S}}const k=Bt(s,[0,f*.6,0]),y=Xe(wn(i.position,k)),E=hu(k,y,o).map(M=>Math.min(1,M)),x=o.length>0&&h.skin!=="none"?{...h,skin:Ra(h.skin,E,du(r,rr(k,i.position)),r?.color)}:h,$=ou(x,d,g,{height:f});return{drawables:[...S,...$.map((M,v)=>({depth:-M.depth-v*1e-6,draw:(T,I)=>M.draw(T,I.time)}))]}}},$s=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function bu([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 Rn=(t,[e,n,s])=>t==="z"?[e,n,s]:t==="x"?[s,n,e]:[e,s,n];function wu(t,e,n="x",s=20,i=0){const o=[],r=e/2;for(const c of[-r,r])for(let h=0;h<s;h++){const d=Math.PI*2*h/s;o.push(Rn(n,[Math.cos(d)*t,Math.sin(d)*t,c]))}const a=[{corners:Array.from({length:s},(c,h)=>s-1-h),normal:Rn(n,[0,0,-1])},{corners:Array.from({length:s},(c,h)=>s+h),normal:Rn(n,[0,0,1])}];for(let c=0;c<s;c++){const h=(c+1)%s,d=Math.PI*2*(c+.5)/s;a.push({corners:[c,h,s+h,s+c],normal:Rn(n,[Math.cos(d),Math.sin(d),0])})}const l=[];if(i>0)for(const c of[-r,r]){const h=o.push(Rn(n,[0,0,c*1.01]))-1;for(let d=0;d<i;d++){const u=Math.PI*2*d/i,f=o.push(Rn(n,[Math.cos(u)*t*.82,Math.sin(u)*t*.82,c*1.01]))-1;l.push([h,f])}}return{vertices:o,faces:a,marks:l,creases:!0}}function ku([t,e,n],s=16){const i=Math.max(4,Math.round(s/2)),o=[[0,e,0]];for(let h=1;h<i;h++){const d=Math.PI*h/i;for(let u=0;u<s;u++){const f=Math.PI*2*u/s;o.push([Math.sin(d)*Math.cos(f)*t,Math.cos(d)*e,Math.sin(d)*Math.sin(f)*n])}}const r=o.push([0,-e,0])-1,a=(h,d)=>1+(h-1)*s+d%s,l=h=>{const d=h.reduce((u,f)=>[u[0]+o[f][0],u[1]+o[f][1],u[2]+o[f][2]],[0,0,0]);return $s([d[0]/(t*t),d[1]/(e*e),d[2]/(n*n)])},c=[];for(let h=0;h<s;h++){const d=[0,a(1,h+1),a(1,h)];c.push({corners:d,normal:l(d)});for(let f=1;f<i-1;f++){const 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 u=[a(i-1,h),a(i-1,h+1),r];c.push({corners:u,normal:l(u)})}return{vertices:o,faces:c,creases:!1}}const F2=t=>t.reduce((e,[n,s],i)=>{const[o,r]=t[(i+1)%t.length];return e+n*r-o*s},0)/2;function vu(t,e){const n=F2(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:$s([0,-c,h])})}return{vertices:o,faces:r,creases:!0}}function Mu(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 Su(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=$s([l[0]-c[0],l[1]-c[1],l[2]-c[2]]),d=Math.abs(h[1])<.9?[0,1,0]:[1,0,0],u=$s(Tu(h,d)),f=Tu(u,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]+u[0]*m+f[0]*w,r[1]+u[1]*m+f[1]*w,r[2]+u[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((u,f)=>[u[0]+i[f][0]/4,u[1]+i[f][1]/4,u[2]+i[f][2]/4],[0,0,0]),d=[(t[r][0]+t[r+1][0])/2,(t[r][1]+t[r+1][1])/2,(t[r][2]+t[r+1][2])/2];o.push({corners:c,normal:$s([h[0]-d[0],h[1]-d[1],h[2]-d[2]])})}return{vertices:i,faces:o,creases:!1}}function Tu(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 Eu(t){switch(t.type){case"box":return bu(t.size);case"cylinder":return wu(t.radius,t.length,t.axis,t.segments,t.spokes);case"ellipsoid":return ku(t.radii,t.segments);case"extrude":return vu(t.profile,t.width);case"panel":return Mu(t.points,t.facing);case"tube":return{...Su(t.points,t.radius,t.segments),joined:t.joined}}}function Na(t,e){if(t.length<2)return t;const n=i=>t[Math.max(0,Math.min(t.length-1,i))],s=i=>{const o=i*(t.length-1),r=Math.min(t.length-2,Math.floor(o)),a=o-r,[l,c,h,d]=[n(r-1),n(r),n(r+1),n(r+2)];return[0,1,2].map(u=>{const f=l[u],p=c[u],g=h[u],m=d[u];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 en=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 Au(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 Ln(t,e){return Math.atan2(e[0]-t[0],e[1]-t[1])*180/Math.PI}function xu(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:Na(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 $u(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 Pu(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 Da=["do","at","for","to","through","toward","speed","pose","gag"],Iu={walk:1.3,bouncy:1.4,doubleBounce:1.2,sneak:.6,strut:1.2,tired:.8,run:3.6,shove:.7},Fa=Object.keys(Dt),Wa=Object.keys(ie),Ba=Object.keys(Zi),W2=.25,B2=700/180,q2=200,z2=300;function Ou(t){if(!Array.isArray(t))return[{beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const e=[...Fa,"face","hold","pose","gag","place"],n=[];return t.forEach((s,i)=>{const o=c=>n.push({beat:i,message:c});if(!s||typeof s!="object"||Array.isArray(s))return o("Each beat must be an object like { do: 'walk', to: [x, z] }.");const r=s,a={duration:"for",path:"through",position:"to",heading:"toward",direction:"toward"};for(const c of Object.keys(r))Da.includes(c)||o(dt("beat field",c,Da,a[c]));const l=typeof r.do=="string"?Wa.includes(r.do)?"pose":Ba.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));Fa.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&&!en(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(en))&&o("`through` is a list of points on the ground, each [x, z] metres.")),r.do==="place"&&!en(r.to)&&o("`place` needs `to`: a point on the ground, [x, z] metres."),r.do==="face"&&!(en(r.toward)||typeof r.toward=="number")&&o("`face` needs `toward`: a point [x, z] or a heading in degrees."),r.do==="pose"&&!(typeof r.pose=="object"&&r.pose!==null)&&!Wa.includes(r.pose)&&o(dt("pose",r.pose,Wa)),r.do==="gag"&&!Ba.includes(r.gag)&&o(dt("gag",r.gag,Ba))}),n}function Y2(t,e,n){const s=Ou(e);if(s.length>0)throw new Error(`characterScript3D: ${s.length} problem(s) in the beats:
54
- ${s.map(y=>` beat ${y.beat}: ${y.message}`).join(`
55
- `)}`);const i=n.height??1.7,o={...gt,...n.pose};let[r,a]=n.position??[0,0],l=n.heading??0,c=0;const h=new Map,d=[],u=(y,E,x,$="linear")=>{const M=h.get(y)??[];M.push({time:E,value:x,easing:$}),h.set(y,M)};u("x",0,r),u("z",0,a),u("rotateY",0,l);const f=(y,E)=>{const x=io(l,E);if(Math.abs(x)<1)return y;const $=Math.max(q2,Math.abs(x)*B2);return u("rotateY",y,l),l+=x,u("rotateY",y+$,l,"ease-in-out"),y+$},p=(y,E,x,$="ease-in-out")=>{for(const[M,v]of Object.entries(x))o[M]!==v&&(u(M,y,o[M]??0),u(M,E,v,$),o[M]=v)},g=(y,E,x)=>{const $=xu([[r,a],...E.through??[E.to]]);if($.length<2)return x;const M=f(x,Ln($[0].point,$[1].point)),v=$[$.length-1].at,T=E.speed??Iu[y]*Math.sqrt(i/1.7),I=E.for??v/T*1e3,O=pa(y,i),_=Lt("ease-in-out"),C=Math.min(z2,I/4);d.push({time:M,value:y}),u("walking",M,0),u("walking",M+C,1,"ease-out"),u("walking",M+I-C,1),u("walking",M+I,0,"ease-in");const D=c;let q=l;for(let X=0;;X=Math.min(v,X+W2)){const J=M+Pu(_,X/v)*I,{point:j,direction:A}=$u($,X);if(q+=io(q,Ln([0,0],A)),u("x",J,j[0]),u("z",J,j[1]),u("rotateY",J,q),u("walk",J,D+X/O),X>=v)break}return c=D+v/O,[r,a]=$[$.length-1].point,l=q,M+I},m=[];let w=0;for(const y of e){const E=y.at??w;let x=E;if(Fa.includes(y.do))x=g(y.do,y,E);else if(y.do==="face")x=f(E,typeof y.toward=="number"?y.toward:Ln([r,a],y.toward));else if(y.do==="hold")x=E+(y.for??1e3);else if(y.do==="place")u("x",E,r),u("z",E,a),[r,a]=y.to,u("x",E+1,r),u("z",E+1,a),typeof y.toward=="number"&&(u("rotateY",E,l),l=y.toward,u("rotateY",E+1,l)),x=E+1;else if(y.do==="pose"){x=E+(y.for??500);const $=typeof y.pose=="string"?ie[y.pose]:y.pose;p(E,x,$)}else if(y.do==="gag"){const $=jd(y.gag,{at:E,from:{...o}});let M=$[0];for(const v of $.slice(1))p(M.time,v.time,Object.fromEntries(Object.entries(v.pose).filter(([T,I])=>o[T]!==I)),v.easing??"ease-in-out"),M=v;x=M.time}m.push({do:y.do,start:E,end:x}),w=x}const S=`${n.scene}/${t}`,k=[...h].map(([y,E])=>({id:`${t}-${y}`,target:S,property:y,keyframes:Au(E)}));return d.length>0&&k.push({id:`${t}-gait`,target:S,property:"gait",keyframes:d}),{tracks:k,duration:w,beats:m,end:{position:[r,a],heading:l,pose:{...o}}}}const _u={x:0,y:0,scale:1,rotate:0,shakeX:0,shakeY:0,shakeRotate:0};function K2(t){const e=n=>{const s=t?.get(n);return typeof s=="number"?s:_u[n]};return{x:e("x"),y:e("y"),scale:e("scale"),rotate:e("rotate"),shakeX:e("shakeX"),shakeY:e("shakeY"),shakeRotate:e("shakeRotate")}}function j2(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 X2(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 Cu(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)Lu(t,c,s);t.restore()}function qa(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 Hu=150,G2={pencil:44,eraser:30};function za(t,e,n={},s){const i=n.tool??"pencil",o=n.skin??"#f1c9a5",r=n.outline??"#2f2f33",a=n.scale??1,l=Math.min(1,Math.max(0,n.lift??0)),c=(n.angle??-30)*Math.PI/180,h=s?s.nudge(.6):{x:0,y:0},d=Hu*a*(1+.05*l);l>0&&(t.save(),t.fillStyle=r,t.globalAlpha=.15*l,t.beginPath(),t.ellipse(e.x,e.y,9*a,4*a,0,0,Math.PI*2),t.fill(),t.restore());const u={x:e.x+h.x+6*l*a,y:e.y+h.y-18*l*a},f=_t.pencilGrip,p=$=>{const M=$.fingers.thumb,v=$.fingers.index,T=$.fingers.middle,I=Ru([M.points[3],v.points[3],T.points[3]]),O=Ru([M.points[1],v.points[0]]),_=(M.depths[3]+v.depths[3]+T.depths[3])/3;return{pinch:I,direction:Math.atan2(O.y-I.y,O.x-I.x),depth:_}},g=Mi(f,{size:d}),m=c-p(g).direction,w=Mi(f,{size:d,angle:m*180/Math.PI}),S=p(w),k=G2[i]*a,y={x:S.pinch.x-Math.cos(c)*k,y:S.pinch.y-Math.sin(c)*k},E={x:u.x-y.x,y:u.y-y.y},x=w.axes.up;U2(t,E,{x:-x.x,y:-x.y},d,n.arm??300*a,o,n.sleeve??"#5b7db1",r),Si(t,E,f,{size:d,angle:m*180/Math.PI,skin:o,ink:r,lineWidth:3*a,prop:{depth:S.depth,draw:()=>{t.save(),t.translate(u.x,u.y),t.scale(a,a),i==="eraser"?qa(t,{x:0,y:0},{angle:c*180/Math.PI,outline:r},s):Cu(t,{x:0,y:0},{angle:c*180/Math.PI,length:190,outline:r},s),t.restore()}}})}const Ru=t=>({x:t.reduce((e,n)=>e+n.x,0)/t.length,y:t.reduce((e,n)=>e+n.y,0)/t.length});function U2(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}),d=h(i,0,0),u=g=>{const m=t.createLinearGradient(e.x,e.y,d.x,d.y);return m.addColorStop(0,g),m.addColorStop(.6,g),m.addColorStop(1,Q2(g)),m},f=Math.min(s*.55,i*.35);t.save(),t.lineJoin="round",t.lineCap="round",t.lineWidth=3*(s/Hu),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=u(r),t.fill(),t.strokeStyle=u(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 V2(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}),d=a.find(g=>e>=g.start&&e<=g.end);if(d){const g=d.end-d.start,m=g>0?(e-d.start)/g:1;return{at:yi(d.path,m),tool:l(d),lift:0,drawing:!0}}const u=[...a].reverse().find(g=>g.end<e),f=a.find(g=>g.start>e),p=g=>g.path[g.path.length-1];if(u&&f&&f.start-u.end<=r){const g=(e-u.end)/(f.start-u.end),m=g<.5?l(u):l(f);return{at:h(p(u),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(u&&e-u.end<=o){const g=(e-u.end)/o;return{at:h(p(u),s,c(g)),tool:l(u),lift:c(g),drawing:!1}}return null}function J2(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 Z2(t){const{path:e}=t,n=e.map(a=>a.x),s=e.map(a=>a.y),i=Math.min(...n),o=Math.min(...s),r=t.hand===!1?void 0:t.hand===!0||t.hand===void 0?{}:t.hand;return{type:"custom",x:i,y:o,width:Math.max(1,Math.max(...n)-i),height:Math.max(1,Math.max(...s)-o),props:{draw:0},draw(a,l,c){const h=Math.min(1,Math.max(0,Number(l.props?.draw??0)));a.translate(-i,-o),a.strokeStyle=t.color??"#2f2f33",a.lineWidth=t.lineWidth??5,a.lineCap="round",a.lineJoin="round";const d=t.sketch?bi(a,t.sketch,c):void 0;h>0&&(d?t.smooth?d.curve(e,h):d.line(e,h):Lu(a,En(e,h))),r&&h>0&&h<1&&za(a,yi(e,h),r,d)}}}function Q2(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 Lu(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 tk(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 Ya(t,e,n,s){if(s<=0||e.length===0)return;const i=En(e,s),o=n/2,r=a=>{t.beginPath(),t.rect(-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 d=-(c.y-l.y)/h*o,u=(c.x-l.x)/h*o;r(()=>{t.moveTo(l.x+d,l.y+u),t.lineTo(c.x+d,c.y+u),t.lineTo(c.x-d,c.y-u),t.lineTo(l.x-d,l.y-u),t.closePath()})}}function ek(t,e,n,s,i){t.save(),Ya(t,e,n,s),i(),t.restore()}function nk(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(),Ya(o,e.path,n,l),t.draw(o,r,a),o.restore(),!i||l<=0||l>=1)return;const c=yi(e.path,l);s?za(o,c,{...s,tool:"eraser"}):qa(o,c,i)}}}function Nn(){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)=>ro(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:sk(i)}))}}}function ro(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 Dn(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 sk(t){return[...t].sort((n,s)=>n.time-s.time).map(n=>({time:n.time,value:n.value,...n.easing?{easing:n.easing}:{}}))}const ik=.0016,ok=.6,Ne=33;function Ps(t){const e=(o,r)=>`piece.${o.id}.${r}`,n=(o,r)=>({x:o.home.x+t.valueAt(e(o,"x"),r),y:o.home.y+t.valueAt(e(o,"y"),r)}),s=(o,r)=>{const a=t.keys(e(o,"x"));if(!a||a.length<2)return;const l=n(o,r-Ne),c=n(o,r);return{x:(c.x-l.x)/Ne,y:(c.y-l.y)/Ne}},i=(o,r)=>t.cutAfter(["x","y","rotate"].map(a=>e(o,a)),r);return{at:n,cutAfter:i,follow(o,r){for(const a of r)t.push(e(o,"x"),{time:a.time,value:a.x-o.home.x}),t.push(e(o,"y"),{time:a.time,value:a.y-o.home.y})},fling(o,r){const a=n(o,r.at),l=r.velocity??s(o,r.at)??{x:.5,y:-.6},c=r.gravity??ik,h=r.duration??900,d=(r.spin??ok)*(l.x<0?-1:1),u=t.valueAt(e(o,"rotate"),r.at);i(o,r.at);for(let f=0;f<=h;f+=Ne){const 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:u+d*f})}t.tween(e(o,"opacity"),1,0,{at:r.at+h*.6,duration:h*.4})},move(o,r){const a=n(o,r.at);t.tween(e(o,"x"),a.x-o.home.x,r.to.x-o.home.x,r,400),t.tween(e(o,"y"),a.y-o.home.y,r.to.y-o.home.y,r,400)}}}function ao(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 Ot({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(E=>Math.abs(E.top-y)<.5)},c=(o?.keyframes??[]).map(k=>k.time),h=k=>{const y=v=>v<0?0:i[v].offset(k),E=l(k);if(E>=0)return y(E);if(Math.abs(a(k))<.5)return 0;const x=v=>l(v)>=0||Math.abs(a(v))<.5,$=[...c].reverse().find(v=>v<=k&&x(v)),M=c.find(v=>v>=k&&x(v));return $===void 0&&M===void 0?0:$===void 0?y(l(M)):M===void 0||M===$?y(l($)):y(l($))+(y(l(M))-y(l($)))*(k-$)/(M-$)},d=i.flatMap(k=>k.windows),u=(k,y)=>d.some(E=>E.start<y&&E.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 E=new Set([y]);for(let x=k+s;x<y;x+=s)E.add(x);for(const x of d)for(const $ of[x.start,x.end])$>k&&$<y&&E.add($);for(const x of[...E].sort(($,M)=>$-M))p.push({time:x,value:a(x)+h(x)})};for(let k=1;k<f.length;k++){const y=f[k-1].time,E=f[k].time;u(y,E)?g(y,E):p.push({...f[k],value:f[k].value+h(E)})}const m=f[f.length-1].time,w=Math.max(m,...d.map(k=>k.end));w>m&&g(m,w);const S={id:o?.id??`${e}-y`,target:e,property:"y",keyframes:p};return o?t.map(k=>k===o?S:k):[...t,S]}function nn(t){const e=t.indexOf(":");return e<0?{kind:t,rest:""}:{kind:t.slice(0,e),rest:t.slice(e+1)}}function De(t,e,n,s){const i=Object.keys(n.anchors).map(r=>nn(r).kind),{kind:o}=nn(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 Is(t,e,n){return new Error(`${t}.edit: ${dt("edit",e,Object.keys(n.edits))}`)}function vt(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 Nu={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"},lo=["wipe","fly","blur"],Os={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"}},rk=.9,ak=8;function lk(t){const e={...Nu,...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(A=>A.length)),c=t.width??r*2+a+l*o,h=r*2+n.length*i,d=t.x+r+a,u=new Set(t.hidden??[]),f=t.language??"plain";if(!ho.includes(f))throw new Error(`codePanel: ${dt("language",f,ho)}`);const p=n.map(A=>Fu(A,f).flatMap(R=>Array.from(R.text,()=>e[R.kind]))),g=Nn(),m=Ps(g),w=[],S=new Map,k=[],y=[],E=A=>{if(!Number.isInteger(A)||A<1||A>n.length)throw new Error(`codePanel: no line ${A} (it has ${n.length})`)},x=g.tween,$=g.last,M=(A,R,N,P,L,W=300)=>{E(A),x(`line.${A}.${R}`,N,P,L,W)},v=(A,R)=>w.filter(N=>N.line<A&&N.closed<=R).length,T=vt,I=A=>t.y+r+(A-1)*i,O=A=>Array.isArray(A)?A:[A],_=(A,R,N)=>{let P=-1;for(let L=0;L<N;L++)if(P=n[A-1].indexOf(R,P+1),P<0)throw new Error(`codePanel: line ${A} has no ${N>1?`${N}th `:""}"${R}"`);return P},C={};n.forEach((A,R)=>{const N=R+1;C[`line.${N}.highlight`]=0,C[`line.${N}.strike`]=0,C[`line.${N}.wipe`]=0,C[`line.${N}.reveal`]=u.has(N)?0:1,C[`line.${N}.shift`]=0});const D={type:"custom",x:t.x,y:t.y,width:c,height:h,props:C,about:{kind:"code panel",summary:`${n.length} lines of ${f} code. Its lines and words are places in the scene (line(), token(), spot()); its edits are methods that record tracks (tracks()).`,get props(){return hk(Object.keys(C))},actions:Ka},draw(A,R){const N=R.props??{},P=B=>Number(N[B]??C[B]),L=r+a,W=B=>r+(B-1)*i-P(`line.${B}.shift`)*i;A.fillStyle=e.background,Du(A,0,0,c,h,8),A.fill(),A.font=`${s}px ${e.font}`,A.textBaseline="middle",A.textAlign="left";const z=(B,Y,V,F,U)=>{const K=n[B-1];for(let st=Y;st<V;st++)K[st]!==" "&&(A.fillStyle=p[B-1][st],A.fillText(K[st],F+(st-Y)*o,U))};A.save(),Du(A,0,0,c,h,8),A.clip(),n.forEach((B,Y)=>{const V=Y+1,F=P(`line.${V}.wipe`);if(F>=1)return;const U=W(V),K=U+i/2,st=Math.max(1,B.length)*o,ot=Math.round(P(`line.${V}.reveal`)*B.length),rt=S.get(V)??{style:"wipe",from:"left"};A.save(),F>0&&ck(A,rt,F,{left:L-a,top:U,width:a+st+o,height:i},c);const at=P(`line.${V}.highlight`);at>0&&(A.globalAlpha*=Math.min(1,at),A.fillStyle=e.highlight,A.fillRect(L-o/2,U,st+o,i),A.globalAlpha/=Math.min(1,at)),a>0&&ot>0&&(A.fillStyle=e.gutter,A.textAlign="right",A.fillText(String(V),L-o,K),A.textAlign="left");const H=[...k.filter(tt=>tt.line===V).map(tt=>({column:tt.column,length:tt.text.length,piece:tt,insert:void 0})),...y.filter(tt=>tt.line===V).map(tt=>({column:tt.column,length:0,piece:void 0,insert:tt}))].sort((tt,lt)=>tt.column-lt.column||tt.length-lt.length);let Z=0,et=L;for(const tt of H){z(V,Z,Math.min(tt.column,ot),et,K),et+=(tt.column-Z)*o;let lt=tt.length,Q="";if(tt.piece){const G=tt.piece.written??"",nt=P(`piece.${tt.piece.id}.write`);G&&nt>0?(Q=G.slice(0,Math.round(nt*G.length)),lt=tt.length+(G.length-tt.length)*Math.min(1,nt*2)):lt=tt.length*(1-P(`piece.${tt.piece.id}.away`))}else tt.insert&&(lt=tt.insert.chars*P(`insert.${tt.insert.id}.open`),tt.insert.text&&(Q=tt.insert.text.slice(0,Math.round(P(`insert.${tt.insert.id}.type`)*tt.insert.text.length))));A.fillStyle=e.text;for(let G=0;G<Q.length;G++)Q[G]!==" "&&A.fillText(Q[G],et+G*o,K);et+=lt*o,Z=tt.column+tt.length}z(V,Z,Math.max(Z,ot),et,K);const it=P(`line.${V}.strike`);it>0&&(A.strokeStyle=e.strike,A.lineWidth=Math.max(1.5,s/10),A.beginPath(),A.moveTo(L,K),A.lineTo(L+st*Math.min(1,it),K),A.stroke()),A.restore()});for(const B of k){const Y=P(`piece.${B.id}.opacity`);if(Y<=0||P(`line.${B.line}.wipe`)>=1)continue;const V=L+(B.column+B.text.length/2)*o+P(`piece.${B.id}.x`),F=W(B.line)+i/2+P(`piece.${B.id}.y`);A.save(),A.globalAlpha=Math.min(1,Y),A.translate(V,F),A.rotate(P(`piece.${B.id}.rotate`)*Math.PI/180),z(B.line,B.column,B.column+B.text.length,-B.text.length*o/2,0),A.restore()}A.restore()}},q=A=>{const{kind:R,rest:N}=nn(A),P=L=>De("codePanel",A,Os,L);if(R==="box"){if(N)throw P("box takes no arguments");return{kind:R}}if(R==="line"){if(!/^\d+$/.test(N))throw P("write it line:N");return{kind:R,n:Number(N)}}if(R==="token"){const L=/^(\d+)(?:#(\d+))?:(.+)$/.exec(N);if(!L)throw P("write it token:N:TEXT, or token:N#K:TEXT for the Kth");return{kind:R,n:Number(L[1]),occurrence:L[2]?Number(L[2]):1,text:L[3]}}if(R==="spot"){const L=/^(\d+):(\d+)(?::(\d+))?$/.exec(N);if(!L)throw P("write it spot:N:C, or spot:N:C:W for W characters");return{kind:R,n:Number(L[1]),column:Number(L[2]),width:L[3]?Number(L[3]):1}}throw P()},X=(A,R,N,P=!1)=>{const L=Array.isArray(R)?R:[R];if(L.length===0||P&&L.length>1)throw new Error(`codePanel.edit: ${A} takes ${P?"one":"at least one"} ${N} anchor`);return L.map(W=>{const z=q(W);if(z.kind!==N)throw new Error(`codePanel.edit: ${A} takes ${N} anchors (${N}:…), not "${W}"`);return z})},J=(A,R)=>{if(typeof R.text!="string")throw new Error(`codePanel.edit: ${A} needs \`text\` (the text to write)`);return R.text},j={kind:"code",about:Os,target:D,lines:n,box:T(t.x,t.y,c,h),line(A,R=1/0){return E(A),T(d,I(A)-v(A,R)*i,Math.max(1,n[A-1].length)*o,i)},token(A,R,N=1,P=1/0){E(A);const L=_(A,R,N);return T(d+L*o,I(A)-v(A,P)*i,R.length*o,i)},highlight(A,R){for(const N of O(A)){const P=$(`line.${N}.highlight`,0);M(N,"highlight",P,R.on===!1?0:1,R,200)}return j},strike(A,R){for(const N of O(A))M(N,"strike",$(`line.${N}.strike`,0),1,R);return j},remove(A,R){const N=O(A),P=R.style??"wipe";if(!lo.includes(P))throw new Error(`codePanel.remove: ${dt("style",P,lo)}`);const L=P==="wipe"?300:450,W=R.at+(R.duration??L),z=R.close??250;for(const B of N)M(B,"wipe",0,1,{...R,easing:R.easing??(P==="fly"?"ease-in":void 0)},L),S.set(B,{style:P,from:R.from??"left"}),w.push({line:B,closed:W+z});for(let B=1;B<=n.length;B++){if(N.includes(B))continue;const Y=N.filter(F=>F<B).length;if(Y===0)continue;const V=$(`line.${B}.shift`,0);M(B,"shift",V,V+Y,{at:W,duration:z,easing:"ease-in-out"})}return j},type(A,R){return M(A,"reveal",0,1,{duration:n[A-1].length*45,...R}),j},piece(A,R,N=1){if(typeof A=="string"){const B=q(A);if(B.kind!=="token")throw new Error(`codePanel.piece: a piece is a word, token:N:TEXT, not "${A}"`);return j.piece(B.n,B.text,B.occurrence)}const P=A;if(R===void 0)throw new Error('codePanel.piece: which word? piece(n, text) or piece("token:N:TEXT")');E(P);const L=_(P,R,N),W=k.find(B=>B.line===P&&B.column===L&&B.text===R);if(W)return W;if(k.some(B=>B.line===P&&L<B.column+B.text.length&&B.column<L+R.length))throw new Error(`codePanel: "${R}" on line ${P} overlaps another piece`);const z={id:k.length+1,line:P,column:L,text:R,home:j.token(P,R,N,0)};k.push(z);for(const B of["x","y","rotate","write","away"])C[`piece.${z.id}.${B}`]=0;return C[`piece.${z.id}.opacity`]=1,z},follow(A,R){return m.follow(A,R),j},fling(A,R){return m.fling(A,R),j},move(A,R){return m.move(A,R),j},write(A,R,N){return A.written=R,x(`piece.${A.id}.write`,0,1,{duration:Math.max(1,R.length)*70,...N}),j},spot(A,R,N=1,P=1/0){E(A);const L=y.filter(W=>W.line===A&&W.column<=R&&W.at<=P).reduce((W,z)=>W+z.chars,0);return T(d+(R+L)*o,I(A)-v(A,P)*i,N*o,i)},insert(A,R,N,P){E(A);const L={id:y.length+1,line:A,column:R,chars:N.length,text:N,at:P.at};y.push(L),C[`insert.${L.id}.open`]=0,C[`insert.${L.id}.type`]=0;const W=P.duration??N.length*70;return x(`insert.${L.id}.open`,0,1,{at:P.at,duration:W*.6,easing:"ease-out"}),x(`insert.${L.id}.type`,0,1,{at:P.at,duration:W}),j},drop(A,R,N,P){E(R);const L=P.duration??250,W=R===A.line,z=P.easing??(W?"linear":"ease-out"),B=j.landing(A,R,N,P.at),Y={id:y.length+1,line:R,column:N,chars:A.text.length,at:P.at};return y.push(Y),C[`insert.${Y.id}.open`]=0,x(`insert.${Y.id}.open`,0,1,{at:P.at,duration:L,easing:W?z:"ease-out"}),x(`piece.${A.id}.away`,$(`piece.${A.id}.away`,0),1,{at:P.at,duration:L,easing:W?z:"ease-in-out"}),m.cutAfter(A,P.at),j.move(A,{at:P.at,duration:L,easing:z,to:{x:B.x,y:B.y}}),x(`piece.${A.id}.rotate`,g.valueAt(`piece.${A.id}.rotate`,P.at),0,{at:P.at,duration:L}),j},landing(A,R,N,P=1/0){const L=j.spot(R,N,A.text.length,P),W=R===A.line&&N>A.column?A.text.length*o:0;return T(L.left-W,L.top,L.width,L.height)},ride(A,R,N){const P=n.map((L,W)=>{const z=g.keys(`line.${W+1}.shift`)??[];return{top:I(W+1),offset:B=>-ro(z,B)*i,windows:Dn(z)}});return ao(A,R,{ground:N.ground,every:N.every??Ne,floors:P})},tracks:g.tracks,anchor(A,R=1/0){const N=q(A);return N.kind==="box"?j.box:N.kind==="line"?j.line(N.n,R):N.kind==="token"?j.token(N.n,N.text,N.occurrence,R):j.spot(N.n,N.column,N.width,R)},edit(A,R,N){const P=()=>X(A,R,"line").map(L=>L.n);if(A==="highlight")return j.highlight(P(),N);if(A==="strike")return j.strike(P(),N);if(A==="remove")return j.remove(P(),N);if(A==="type"){for(const L of P())j.type(L,N);return j}if(A==="insert"){const[L]=X(A,R,"spot",!0);return j.insert(L.n,L.column,J(A,N),N)}if(A==="write"||A==="drop"||A==="move"||A==="fling"){const[L]=X(A,R,"token",!0),W=j.piece(L.n,L.text,L.occurrence);if(A==="write")return j.write(W,J(A,N),N);if(A==="fling")return j.fling(W,N);if(A==="drop"){const B=typeof N.into=="string"?q(N.into):void 0;if(B?.kind!=="spot")throw new Error("codePanel.edit: drop needs `into`, a spot anchor (spot:N:C)");return j.drop(W,B.n,B.column,N)}const z=typeof N.to=="string"?j.anchor(N.to,N.at):N.to;if(!z||typeof z.x!="number"||typeof z.y!="number")throw new Error("codePanel.edit: move needs `to`, an anchor name or { x, y }");return j.move(W,{...N,to:z})}throw Is("codePanel",A,Os)}};return j}function ck(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=ak*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*rk*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 Ka={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 hk(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 Du(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 co={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:[]};co.typescript=[...co.javascript,"enum","interface","type","implements","private","public","readonly","keyof","as","declare","namespace"];const ho=Object.keys(co),dk={go:"//",rust:"//",csharp:"//",javascript:"//",typescript:"//",python:"#",plain:null};function Fu(t,e){const n=new Set(co[e]),s=dk[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 ja='"Patrick Hand", "Segoe Print", "Bradley Hand", "Comic Sans MS", "Chalkboard SE", cursive',_s={whiteboard:{background:"#f7f7f2",frame:"#b8bcc4",ink:"#1f2a44",colors:{ink:"#1f2a44",red:"#d03b3b",blue:"#2f6fd0",green:"#2e9a52",orange:"#e07b1a"},font:ja,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:ja,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:ja,stroke:.08,opacity:1,rule:{color:"#c9d6ec",spacing:1.55,margin:"#f0a3a3"}}},Xa=["circle","box","underline","arrow"],be={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"}},Wu=90,Bu=300,uk=.3;function fk(t){const e=typeof t.theme=="string"?t.theme:"whiteboard";if(!(e in _s))throw new Error(`whiteboard: ${dt("theme",e,Object.keys(_s))}`);const n=typeof t.theme=="object"?{..._s.whiteboard,...t.theme}:_s[e],s=t.fontSize??28,i=t.charWidth??.55,o=y=>y===void 0?n.ink:n.colors[y]??y,r=y=>vt(t.x+y.left,t.y+y.top,y.width,y.height),a=Nn(),l=Ps(a),c={},h=new Map,d=[],u=[],f=(y,E,x,$)=>{const M=h.get(y);if(!M||M.kind!=="text")throw De("whiteboard",$,be,`there is no text "${y}" (texts: ${p().join(", ")||"none"})`);let v=-1;for(let I=0;I<x;I++)if(v=M.item.text.indexOf(E,v+1),v<0)throw De("whiteboard",$,be,`text "${y}" has no ${x>1?`${x}th `:""}"${E}"`);const T=M.size*i;return{column:v,box:vt(M.box.left+v*T,M.box.top,E.length*T,M.box.height)}},p=()=>[...h.values()].filter(y=>y.kind==="text").map(y=>y.item.id),g=y=>{const{kind:E,rest:x}=nn(y),$=M=>De("whiteboard",y,be,M);if(E==="box"){if(x)throw $("box takes no arguments");return{kind:E}}if(E==="text"||E==="mark"){if(!x)throw $(`write it ${E}:ID`);return{kind:E,id:x}}if(E==="term"){const M=/^([^:#]+)(?:#(\d+))?:(.+)$/.exec(x);if(!M)throw $("write it term:ID:TEXT, or term:ID#K:TEXT for the Kth");return{kind:E,id:M[1],occurrence:M[2]?Number(M[2]):1,text:M[3]}}throw $()},m=y=>{const E=g(y);if(E.kind==="box")return vt(0,0,t.width,t.height);if(E.kind==="term")return f(E.id,E.text,E.occurrence,y).box;const x=h.get(E.id);if(!x||x.kind!==E.kind){const $=[...h.values()].filter(M=>M.kind===E.kind).map(M=>M.item.id);throw De("whiteboard",y,be,`there is no ${E.kind} "${E.id}" (${E.kind}s: ${$.join(", ")||"none"})`)}return x.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(I=>typeof I=="number"))throw new Error(`whiteboard: text "${y.id}" needs \`at\`, [x, y] from the board's top-left`);const v=y.size??s,T=vt(y.at[0],y.at[1],Math.max(1,y.text.length)*v*i,v*1.3);h.set(y.id,{kind:"text",item:y,size:v,color:o(y.color),box:T}),c[`text.${y.id}.write`]=y.hidden?0:1,c[`text.${y.id}.erase`]=0;continue}if(!Xa.includes(y.mark))throw new Error(`whiteboard: mark "${y.id}": ${dt("mark",y.mark,Xa)}`);const E=y.mark==="arrow"?["from","to"]:["around"];for(const v of E)if(typeof y[v]!="string")throw new Error(`whiteboard: ${y.mark} "${y.id}" needs \`${v}\`, a place on the board (an item before it)`);const x=new Set([y.from,y.to].filter(v=>typeof v=="string").map(v=>v.split(":")[1])),$=y.mark==="arrow"?[...h.values()].filter(v=>v.kind==="text"&&!x.has(v.item.id)).map(v=>v.box):[],M=gk(y,m,s,$);h.set(y.id,{kind:"mark",item:y,color:o(y.color),points:M,box:yk(M)}),c[`mark.${y.id}.draw`]=y.hidden?0:1,c[`mark.${y.id}.erase`]=0}const w=y=>d.filter(E=>E.item===y),S={type:"custom",x:t.x,y:t.y,width:t.width,height:t.height,props:c,about:{kind:"whiteboard",summary:`A board with ${h.size} items. Its texts, terms and marks are places in the scene (anchor()); its edits record tracks (edit(), tracks()).`,get props(){return bk(Object.keys(c))},actions:be.edits},draw(y,E){const x=E.props??{},$=M=>Number(x[M]??c[M]??0);if(y.save(),y.fillStyle=n.background,Yu(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(),Yu(y,0,0,t.width,t.height,10),y.clip(),y.lineWidth=1,y.strokeStyle=n.rule.color;const M=s*(n.rule.spacing??1.55);for(let v=M;v<t.height;v+=M)y.beginPath(),y.moveTo(0,v),y.lineTo(t.width,v),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 M of h.values()){if(y.save(),Ga(y,M.box,$(`${M.kind}.${M.item.id}.erase`)),M.kind==="text"){const v=w(M.item.id),T=$(`text.${M.item.id}.write`)*M.item.text.length;y.font=`${M.size}px ${n.font}`,y.fillStyle=M.color;for(let I=0;I<Math.ceil(T);I++)M.item.text[I]===" "||v.some(O=>I>=O.column&&I<O.column+O.text.length)||(y.globalAlpha=n.opacity*Math.min(1,T-I),y.fillText(M.item.text[I],M.box.left+(I+.5)*M.size*i,M.box.y))}else zu(y,M.points,$(`mark.${M.item.id}.draw`),M.color,s*n.stroke,M.item.mark==="arrow");y.restore()}for(const M of u){const v=$(`strike.${M.id}.draw`);if(v<=0)continue;const{box:T}=M,I=T.height*.15;zu(y,[{x:T.left-3,y:T.y+I},{x:T.right+3,y:T.y-I}],v,n.colors.red??n.ink,s*n.stroke*.8,!1)}for(const M of d){const v=h.get(M.item),T=v.size*i;y.font=`${v.size}px ${n.font}`,y.fillStyle=v.color;const I=M.written;if(I){const D=$(`piece.${M.id}.write`)*I.length,q=M.home.x-t.x-I.length*T/2;for(let X=0;X<Math.ceil(D);X++)I[X]!==" "&&(y.globalAlpha=n.opacity*Math.min(1,D-X),y.fillText(I[X],q+(X+.5)*T,M.home.y-t.y))}const O=$(`piece.${M.id}.opacity`)*Math.min(1,$(`text.${M.item}.write`)*v.item.text.length-M.column);if(O<=0)continue;y.save();const _={x:M.home.x-t.x,y:M.home.y-t.y},C={x:$(`piece.${M.id}.x`),y:$(`piece.${M.id}.y`)};Ga(y,vt(_.x+C.x-M.home.width/2,_.y+C.y-M.home.height/2,M.home.width,M.home.height),$(`piece.${M.id}.erase`)),Math.hypot(C.x,C.y)<1&&Ga(y,v.box,$(`text.${M.item}.erase`)),y.globalAlpha=n.opacity*Math.min(1,O),y.translate(_.x+C.x,_.y+C.y),y.rotate($(`piece.${M.id}.rotate`)*Math.PI/180);for(let D=0;D<M.text.length;D++)M.text[D]!==" "&&y.fillText(M.text[D],(D+.5-M.text.length/2)*T,0);y.restore()}y.restore()}},k={kind:"board",about:be,target:S,box:vt(t.x,t.y,t.width,t.height),anchor(y){return r(m(y))},piece(y){const E=g(y);if(E.kind!=="term")throw new Error(`whiteboard.piece: a piece is a term, term:ID:TEXT, not "${y}"`);const{column:x,box:$}=f(E.id,E.text,E.occurrence,y),M=d.find(T=>T.item===E.id&&T.column===x&&T.text===E.text);if(M)return M;if(d.some(T=>T.item===E.id&&x<T.column+T.text.length&&T.column<x+E.text.length))throw new Error(`whiteboard: "${E.text}" in "${E.id}" overlaps another piece`);const v={id:d.length+1,item:E.id,column:x,text:E.text,home:r($)};d.push(v);for(const T of["x","y","rotate","erase","write"])c[`piece.${v.id}.${T}`]=0;return c[`piece.${v.id}.opacity`]=1,v},edit(y,E,x){const $=Array.isArray(E)?E:[E];if($.length===0)throw new Error(`whiteboard.edit: ${y} takes at least one anchor`);const M=$.map(I=>({name:I,anchor:g(I)}));for(const{name:I}of M)m(I);const v=(I,O=!1)=>{const _=M.find(C=>!I.includes(C.anchor.kind));if(_)throw new Error(`whiteboard.edit: ${y} takes ${I.join(" or ")} anchors, not "${_.name}"`);if(O&&M.length>1)throw new Error(`whiteboard.edit: ${y} takes one ${I.join(" or ")} anchor`)},T=()=>k.piece(M[0].name);if(y==="write"){if(M.some(I=>I.anchor.kind==="term")){if(v(["term"],!0),typeof x.text!="string")throw new Error("whiteboard.edit: write into a term needs `text` (the new text)");const I=T();return I.written=x.text,a.tween(`piece.${I.id}.write`,0,1,{duration:Math.max(Bu,x.text.length*Wu),...x}),k}v(["text"]);for(const{anchor:I}of M){const O=I.id,_=h.get(O).item.text;a.tween(`text.${O}.write`,0,1,{duration:Math.max(Bu,_.length*Wu),...x})}return k}if(y==="draw"){v(["mark"]);for(const{anchor:I}of M)a.tween(`mark.${I.id}.draw`,0,1,{duration:500,...x});return k}if(y==="erase"){v(["text","term","mark"]);for(const I of M){const O=I.anchor.kind==="term"?`piece.${k.piece(I.name).id}.erase`:`${I.anchor.kind}.${I.anchor.id}.erase`;a.tween(O,0,1,{duration:400,...x})}return k}if(y==="strike"){v(["text","term"]);for(const I of M){const O={id:u.length+1,box:m(I.name)};u.push(O),c[`strike.${O.id}.draw`]=0,a.tween(`strike.${O.id}.draw`,0,1,{duration:250,...x})}return k}if(y==="move"){v(["term"],!0);const I=typeof x.to=="string"?k.anchor(x.to):x.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(),{...x,to:I})}if(y==="fling")return v(["term"],!0),k.fling(T(),x);throw Is("whiteboard",y,be)},follow(y,E){return l.follow(y,E),k},fling(y,E){return l.fling(y,E),k},move(y,E){return l.move(y,E),k},ride(y){return y},tracks:a.tracks};return k}function gk(t,e,n,s=[]){const i=$e(Gt(t.id)),o=g=>(i.next()*2-1)*g,r=n*uk;if(t.mark==="arrow"){const g=e(t.from),m=e(t.to),w=qu(g,m,r*.6),S=qu(m,g,r*.6),k=Math.hypot(S.x-w.x,S.y-w.y),y=mk(w,S);let E=k*(.06+o(.04));if(t.bend!==void 0)E=k*t.bend;else{const M=pk(w,S,y,s,r);M!==0&&(E=M)}const x={x:(w.x+S.x)/2+y.x*E,y:(w.y+S.y)/2+y.y*E},$=[];for(let M=0;M<=24;M++){const v=M/24;$.push({x:(1-v)**2*w.x+2*(1-v)*v*x.x+v*v*S.x,y:(1-v)**2*w.y+2*(1-v)*v*x.y+v*v*S.y})}return $}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,S=a.bottom+r*.6,k=(E,x)=>({x:E+o(r*.2),y:x+o(r*.2)}),y=k(g,w);return[y,k(m,w),k(m,S),k(g,S),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),d=i.next()*Math.PI*2,u=1.12,f=64,p=[];for(let g=0;g<=f*u;g++){const m=g/f,w=h+m*Math.PI*2,S=1+.035*Math.sin(m*Math.PI*4+d)+.06*m;p.push({x:a.x+Math.cos(w)*l*S,y:a.y+Math.sin(w)*c*S})}return p}function pk(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 d=[{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})),u=d.some(p=>p.t>0&&p.t<o),f=d.some(p=>p.n>0)&&d.some(p=>p.n<0);!u||!f||(a=Math.max(a,...d.map(p=>p.n)),l=Math.min(l,...d.map(p=>p.n)))}return a===0&&l===0?0:a<=-l?2*(a+i):2*(l-i)}function qu(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 mk(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 yk(t){const e=t.map(o=>o.x),n=t.map(o=>o.y),s=Math.min(...e),i=Math.min(...n);return vt(s,i,Math.max(...e)-s,Math.max(...n)-i)}function zu(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],d=e[e.length-3]??e[0],u=Math.atan2(h.y-d.y,h.x-d.x),f=i*4.5*c;t.beginPath();for(const p of[-1,1])t.moveTo(h.x,h.y),t.lineTo(h.x-Math.cos(u+p*.45)*f,h.y-Math.sin(u+p*.45)*f);t.stroke()}function Ga(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 Yu(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 bk(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 Ua=["bar","line","pie","donut"],Ku='system-ui, -apple-system, "Segoe UI", sans-serif',Cs={light:{background:"#ffffff",text:"#3b4252",grid:"#d8dee9",color:"#4c7bd9",highlight:"#e8833a",palette:["#4c7bd9","#3fa66b","#b05cc9","#d9c04c","#4cb8c4","#d95c6f","#8a7a5a","#6b7a99"],font:Ku},dark:{background:"#1e2230",text:"#cdd6f4",grid:"#3a4055",color:"#89b4fa",highlight:"#fab387",palette:["#89b4fa","#a6e3a1","#cba6f7","#f9e2af","#94e2d5","#f38ba8","#b4a58a","#9399b2"],font:Ku}},sn={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)"}},wk=600,kk=500,vk=200,Mk=400,Sk=.14,Tk=Math.PI*2;function Ek(t){if(!Ua.includes(t.kind))throw new Error(`chart: ${dt("kind",t.kind,Ua)}`);const e=typeof t.theme=="string"?t.theme:"light";if(!(e in Cs))throw new Error(`chart: ${dt("theme",e,Object.keys(Cs))}`);const n=typeof t.theme=="object"?{...Cs.light,...t.theme}:Cs[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 H of r){if(typeof H?.id!="string"||!H.id||/[:.]/.test(H.id))throw new Error(`chart: every series needs an \`id\` without ":" or "." (got ${JSON.stringify(H?.id)})`);if(a.has(H.id))throw new Error(`chart: two series are called "${H.id}"`);a.add(H.id)}const l=new Map(r.map((H,Z)=>[H.id,Z])),c=H=>r[l.get(H)].color??(l.get(H)===0?n.color:n.palette[l.get(H)%n.palette.length]),h=new Set,d=(H,Z)=>{const et=H.values?.[Z.id]??(t.series?void 0:H.value)??H.value;if(typeof et!="number"||!Number.isFinite(et))throw new Error(o?`chart: "${H.id}" needs a value for series "${Z.id}" (\`values: { ${Z.id}: … }\`)`:`chart: "${H.id}" needs a \`value\`, a number`);return et};for(const H of t.data){if(typeof H?.id!="string"||!H.id||/[:.]/.test(H.id))throw new Error(`chart: every datum needs an \`id\` without ":" or "." (got ${JSON.stringify(H?.id)})`);if(h.has(H.id))throw new Error(`chart: two data are called "${H.id}"`);for(const Z of r)d(H,Z);h.add(H.id)}const u=s==="bar"?"bar":s==="line"?"point":"slice",f=Math.max(...t.data.flatMap(H=>r.map(Z=>d(H,Z)))),p=i?t.data.reduce((H,Z)=>H+d(Z,r[0]),0):t.max??ju(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,S=i?void 0:t.axis?.y,k=t.title?g*2.3:g*.5,y={left:g*3.6+(S?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=y.bottom-y.top,x=(y.right-y.left)/t.data.length,$=o?x*.72/r.length:x*.6,M=o?$*.86:$,v=Math.max(4,g*.35),T=E/p,I=new Map(t.data.map((H,Z)=>[H.id,Z])),O=H=>y.left+x*(I.get(H)+.5),_=(H,Z)=>o?O(H)-x*.36+$*l.get(Z)+($-M)/2:O(H)-M/2,C=(H,Z)=>_(H,Z)+M/2,D=t.height-g*1.2,q={cx:t.width/2,cy:(y.top+D)/2,r:Math.max(10,Math.min(t.width/2,(D-y.top)/2)-g*2.6)},X=s==="donut"?q.r*.55:0,J=s==="donut"?(X+q.r)/2:q.r*.62,j=new Map;if(m){let H=y.right;for(const Z of[...r].reverse()){const et=Z.label??Z.id,it=g*.62*et.length+g*1.9;j.set(Z.id,vt(H-it,k,it,g*1.4)),H-=it+g*.6}}const A=Nn(),R=Ps(A),N={},P=(H,Z,et)=>o?`${u}.${H}.${Z}.${et}`:`${u}.${H}.${et}`;for(const H of t.data)for(const Z of r)N[P(H.id,Z.id,"value")]=d(H,Z),N[P(H.id,Z.id,"show")]=H.hidden?0:1,N[P(H.id,Z.id,"highlight")]=0,i&&(N[P(H.id,Z.id,"pull")]=0);const L=(H,Z)=>A.keys(H)?.length?ro(A.keys(H),Z):N[H],W=(H,Z,et)=>L(P(H,Z,"value"),et)*(s==="bar"?L(P(H,Z,"show"),et):1)*T,z=H=>{const Z=r[0].id,et=t.data.map(Q=>Math.max(0,H(P(Q.id,Z,"value")))*Math.max(0,Math.min(1,H(P(Q.id,Z,"show"))))),it=et.reduce((Q,G)=>Q+G,0),tt=new Map;let lt=-Math.PI/2;return t.data.forEach((Q,G)=>{const nt=it>0?Tk*et[G]/it:0,ht=lt+nt/2,ft=Math.max(0,Math.min(1,H(P(Q.id,Z,"pull"))))*q.r*Sk;tt.set(Q.id,{start:lt,sweep:nt,mid:ht,out:ft,centre:{x:q.cx+Math.cos(ht)*(J+ft),y:q.cy+Math.sin(ht)*(J+ft)}}),lt+=nt}),tt},B=H=>z(Z=>L(Z,H)),Y=H=>{const{kind:Z,rest:et}=nn(H),it=tt=>De("chart",H,sn,tt);if(Z==="box"){if(et)throw it("box takes no arguments");return{kind:"box"}}if(Z==="legend"){if(!j.has(et))throw it(m?`there is no series "${et}" (series: ${r.map(tt=>tt.id).join(", ")})`:"only a chart with several series has a legend");return{kind:"legend",series:et}}if(Z==="bar"||Z==="point"||Z==="slice"||Z==="label"||Z==="value"){if(!et)throw it(`write it ${Z}:ID`);const tt=et.indexOf(":"),lt=tt<0?et:et.slice(0,tt),Q=tt<0?r[0].id:et.slice(tt+1);if(!I.has(lt))throw it(`there is no "${lt}" (data: ${[...I.keys()].join(", ")})`);if(!a.has(Q))throw it(`there is no series "${Q}" (series: ${r.map(G=>G.id).join(", ")})`);if(Z==="label"&&tt>=0)throw it("a label is one per datum: label:ID");if((Z==="bar"||Z==="point"||Z==="slice")&&Z!==u)throw it(`a ${s} chart has ${u}s, not ${Z}s: ${u}:${lt}`);return{kind:Z,id:lt,series:Q}}throw it()},V=(H,Z)=>{if(H.kind==="box")return vt(0,0,t.width,t.height);if(H.kind==="legend")return j.get(H.series);if(i){const Q=B(Z).get(H.id),G=Math.max(g*1.5,q.r*.42);if(H.kind==="slice")return vt(Q.centre.x-G/2,Q.centre.y-G/2,G,G);const nt=F(Q);return H.kind==="label"?nt:Q.sweep>=.3?vt(Q.centre.x-g*1.6,Q.centre.y-g*.65,g*3.2,g*1.3):vt(nt.left,nt.bottom,nt.width,g*1.3)}const et=H.kind==="label"?O(H.id):C(H.id,H.series),it=y.bottom-W(H.id,H.series,Z);if(H.kind==="bar")return vt(et-M/2,it,M,y.bottom-it);if(H.kind==="point")return vt(O(H.id)-v,it-v,v*2,v*2);if(H.kind==="label")return vt(et-x/2,y.bottom+g*.4,x,g*1.4);const tt=it-(s==="line"?v:0)-g*.3,lt=o&&s==="bar"?$:x;return vt((s==="line"?O(H.id):et)-lt/2,tt-g*1.3,lt,g*1.3)},F=H=>{const Z=q.r+H.out+g*.9,et={x:q.cx+Math.cos(H.mid)*Z,y:q.cy+Math.sin(H.mid)*Z},it=g*4.2,tt=Math.cos(H.mid),lt=tt>.2?et.x:tt<-.2?et.x-it:et.x-it/2;return vt(lt,et.y-g*.7,it,g*1.4)},U=H=>vt(t.x+H.left,t.y+H.top,H.width,H.height),K=H=>`${t.prefix??""}${H.toFixed(t.decimals??0)}${t.suffix??""}`,st=new Map,ot={type:"custom",x:t.x,y:t.y,width:t.width,height:t.height,props:N,about:{kind:`${s} chart`,summary:`A ${s} chart of ${t.data.length} values (${t.data.map(H=>H.id).join(", ")})${o?` in ${r.length} series (${r.map(H=>H.id).join(", ")})`:""}${i?"":`, scaled to ${p}`}. Its ${u}s and labels are places in the scene (anchor()); its edits record tracks (edit(), tracks()).`,props:Object.fromEntries(Object.keys(N).map(H=>[H,$k(H)])),actions:sn.edits},draw(H,Z){const et=Z.props??{},it=Q=>Number(et[Q]??N[Q]??0);if(H.save(),H.fillStyle=n.background,Xu(H,0,0,t.width,t.height,8),H.fill(),H.font=`${g}px ${n.font}`,H.textBaseline="middle",t.title&&(H.fillStyle=n.text,H.textAlign="left",H.font=`600 ${g*1.2}px ${n.font}`,H.fillText(t.title,i?g:y.left,g*1.5),H.font=`${g}px ${n.font}`),m){H.textAlign="left";for(const Q of r){const G=j.get(Q.id);H.fillStyle=c(Q.id),Xu(H,G.left,G.top+g*.25,g*.9,g*.9,2),H.fill(),H.fillStyle=n.text,H.fillText(Q.label??Q.id,G.left+g*1.3,G.top+G.height/2)}}if(i){rt(H,it),H.restore();return}H.lineWidth=1,H.textAlign="right";for(let Q=0;Q<=4;Q++){const G=y.bottom-E*Q/4;H.strokeStyle=n.grid,H.beginPath(),H.moveTo(y.left,G),H.lineTo(y.right,G),H.stroke(),H.fillStyle=n.text,H.globalAlpha=.7,H.fillText(Ak(p*Q/4),y.left-g*.5,G),H.globalAlpha=1}(S||w)&&(H.fillStyle=n.text,H.textAlign="center",H.globalAlpha=.85,S&&(H.save(),H.translate(g*.9,(y.top+y.bottom)/2),H.rotate(-Math.PI/2),H.fillText(S,0,0),H.restore()),w&&H.fillText(w,(y.left+y.right)/2,y.bottom+g*2.3),H.globalAlpha=1);const tt=(Q,G)=>it(P(Q,G,"value"))*(s==="bar"?it(P(Q,G,"show")):1)*T,lt=(Q,G)=>Va(c(G),n.highlight,it(P(Q,G,"highlight")));if(s==="line"){H.lineWidth=Math.max(2,g*.2),H.lineJoin="round",H.lineCap="round";for(const Q of r)H.strokeStyle=c(Q.id),H.beginPath(),t.data.forEach((G,nt)=>{const ht={x:O(G.id),y:y.bottom-tt(G.id,Q.id)},ft=it(P(G.id,Q.id,"show"));if(nt===0){ft>0&&H.moveTo(ht.x,ht.y);return}const wt=t.data[nt-1];if(it(P(wt.id,Q.id,"show"))<1||ft<=0)return;const mt={x:O(wt.id),y:y.bottom-tt(wt.id,Q.id)};H.lineTo(mt.x+(ht.x-mt.x)*ft,mt.y+(ht.y-mt.y)*ft)}),H.stroke()}H.textAlign="center";for(const Q of t.data){for(const G of r){const nt=s==="bar"?C(Q.id,G.id):O(Q.id),ht=tt(Q.id,G.id),ft=it(P(Q.id,G.id,"show"));if(H.fillStyle=lt(Q.id,G.id),s==="bar"?ht>.5&&(xk(H,nt-M/2,y.bottom-ht,M,ht,Math.min(6,M/4)),H.fill()):ft>0&&(H.beginPath(),H.arc(nt,y.bottom-ht,v*Math.min(1,ft*1.5)*(1+.3*it(P(Q.id,G.id,"highlight"))),0,Math.PI*2),H.fill()),t.values!==!1&&ft>0){H.globalAlpha=Math.min(1,ft*2),H.font=`600 ${o?g*.85:g}px ${n.font}`,H.fillStyle=Va(n.text,n.highlight,it(P(Q.id,G.id,"highlight")));const wt=y.bottom-ht-(s==="line"?v:0)-g*.95;H.fillText(K(it(P(Q.id,G.id,"value"))),nt,wt),H.font=`${g}px ${n.font}`,H.globalAlpha=1}}H.fillStyle=n.text,H.fillText(Q.label??Q.id,O(Q.id),y.bottom+g*1.1)}H.strokeStyle=n.text,H.lineWidth=1.5,H.beginPath(),H.moveTo(y.left,y.bottom),H.lineTo(y.right,y.bottom),H.stroke(),H.restore()}};function rt(H,Z){const et=r[0].id,it=z(Z);t.data.forEach((tt,lt)=>{const Q=it.get(tt.id);if(Q.sweep<=1e-4)return;const G=st.get(tt.id),nt=G?{x:Z(`piece.${G.id}.x`),y:Z(`piece.${G.id}.y`)}:{x:0,y:0},ht=G?Z(`piece.${G.id}.rotate`)*Math.PI/180:0,ft=G?Z(`piece.${G.id}.opacity`):1;if(ft<=0)return;H.save(),H.globalAlpha=ft;const wt={x:q.cx+Math.cos(Q.mid)*Q.out,y:q.cy+Math.sin(Q.mid)*Q.out};H.translate(Q.centre.x+nt.x,Q.centre.y+nt.y),H.rotate(ht),H.translate(-Q.centre.x,-Q.centre.y),H.beginPath(),H.arc(wt.x,wt.y,q.r,Q.start,Q.start+Q.sweep),X>0?H.arc(wt.x,wt.y,X,Q.start+Q.sweep,Q.start,!0):H.lineTo(wt.x,wt.y),H.closePath(),H.fillStyle=Va(n.palette[lt%n.palette.length],n.highlight,Z(P(tt.id,et,"highlight"))),H.fill(),H.strokeStyle=n.background,H.lineWidth=Math.max(1.5,g*.15),H.stroke(),t.values!==!1&&Q.sweep>=.3&&(H.fillStyle=n.background,H.font=`600 ${g}px ${n.font}`,H.textAlign="center",H.fillText(K(Z(P(tt.id,et,"value"))),Q.centre.x,Q.centre.y),H.font=`${g}px ${n.font}`),H.restore();const mt=F(Q),ee=Math.cos(Q.mid);H.globalAlpha=ft,H.fillStyle=n.text,H.textAlign=ee>.2?"left":ee<-.2?"right":"center";const Ys=ee>.2?mt.left:ee<-.2?mt.right:mt.left+mt.width/2;H.fillText(tt.label??tt.id,Ys,mt.top+mt.height/2),t.values!==!1&&Q.sweep<.3&&(H.globalAlpha=ft*.8,H.fillText(K(Z(P(tt.id,et,"value"))),Ys,mt.bottom+g*.65)),H.globalAlpha=1})}const at={kind:"chart",chartKind:s,about:sn,target:ot,max:p,box:vt(t.x,t.y,t.width,t.height),anchor(H,Z=1/0){return U(V(Y(H),Z))},piece(H){const Z=Y(H);if(Z.kind!=="slice")throw new Error(i?`chart: a piece is a slice, slice:ID, not "${H}"`:`chart: a ${u} is not a piece; slices of a pie or donut are (slice:ID). Change a ${u} with edit('set' | 'show' | 'highlight', …)`);const et=st.get(Z.id);if(et)return et;const it={id:st.size+1,datum:Z.id,home:U(V(Z,0))};st.set(Z.id,it);for(const tt of["x","y","rotate"])N[`piece.${it.id}.${tt}`]=0;return N[`piece.${it.id}.opacity`]=1,it},edit(H,Z,et){const it=Array.isArray(Z)?Z:[Z];if(it.length===0)throw new Error(`chart.edit: ${H} takes at least one anchor`);if(!(H in sn.edits))throw Is("chart",H,sn);if(H==="pull"&&!i)throw new Error(`chart.edit: pull takes slice anchors of a pie or donut; a ${s} chart has ${u}s`);const tt=it.map(lt=>{const Q=Y(lt);if(Q.kind!==u)throw new Error(`chart.edit: ${H} takes ${u} anchors (${u}:ID), not "${lt}"`);return Q});for(const{id:lt,series:Q}of tt){const G=nt=>P(lt,Q,nt);if(H==="set"){if(typeof et.value!="number"||!Number.isFinite(et.value))throw new Error("chart.edit: set needs `value`, a number");A.tween(G("value"),L(G("value"),et.at),et.value,et,wk)}else H==="show"?A.tween(G("show"),L(G("show"),et.at),et.on===!1?0:1,et,kk):H==="pull"?A.tween(G("pull"),L(G("pull"),et.at),et.on===!1?0:1,et,Mk):A.tween(G("highlight"),L(G("highlight"),et.at),et.on===!1?0:1,et,vk)}return at},follow(H,Z){return R.follow(H,Z),at},fling(H,Z){return R.fling(H,Z),at},move(H,Z){return R.move(H,Z),at},ride(H,Z,et){if(s!=="bar")return H;const it=t.data.flatMap(tt=>r.map(lt=>{const Q=W(tt.id,lt.id,0),G=[...Dn(A.keys(P(tt.id,lt.id,"value"))),...Dn(A.keys(P(tt.id,lt.id,"show")))];return{top:t.y+y.bottom-Q,offset:nt=>Q-W(tt.id,lt.id,nt),windows:G}}));return ao(H,Z,{ground:et.ground,every:et.every??Ne,floors:it})},tracks:A.tracks};return at}function ju(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 Ak(t){return Number.isInteger(t)?String(t):String(Number(t.toFixed(2)))}function Va(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 Xu(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 xk(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 $k(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 Ja={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:ue.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:ue.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:ue.black},ears:!0,outfit:{shirt:"#9b5fc0",trousers:"#2f2f3a",sleeves:"long"}}},grandpa:{label:"Grandpa",group:"family",scale:.96,options:{build:"stocky",hair:{style:"receding",color:ue.gray},facialHair:{style:"shortBoxed",color:ue.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:ue.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:ue.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:ue.blond},hat:"sunHat",ears:!0,outfit:{shirt:"#d64535",trousers:"#4f6b3a",sleeves:"long"}}}};function Pk(t,e=300,n={}){const s=Ja[t];if(!s)throw new Error(`castMember: unknown cast member '${t}'`);return{...s.options,height:Math.round(e*s.scale),...n}}const Hs={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 Ik(t,e,n){return Hs[t].spacing*Math.min(e.height,n.height)}const Gu=.075;function Ok(t,e,n,s={}){const i=Hs[t];if(!i)throw new Error(`meetHands: unknown meeting '${t}' (one of ${Object.keys(Hs).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 S=w?a?1:.62:a?3:3.38;let k={...gt,...m.pose,turn:S,lean:(m.pose?.lean??0)+i.lean};const y=w?1:-1,E=(x,$,M)=>{k=ye(m.character,k,x,{x:c.x+$-m.x,y:c.y,depth:M})};if(t==="handOver"){const x=Gu*l;E("arm.left",-y*x*.9,x),E("arm.right",-y*x*.9,-x)}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},d=h(o,!0),u=h(r,!1),f=.03*l,p=(m,w)=>{const S=te(m.character,w),k=t==="handOver"?["hand.left","hand.right"]:["hand.right"],y=t==="handOver"?Gu*l+f:f;return k.every(E=>Math.abs(S.points[E].y-c.y)<f&&Math.abs(S.points[E].x+m.x-c.x)<y)},g=p(o,d)&&p(r,u);return e.x<=n.x?{a:d,b:u,point:c,reached:g}:{a:u,b:d,point:c,reached:g}}const uo={spacing:.3,lean:10,tilt:8};function _k(t,e){return uo.spacing*Math.min(t.height,e.height)}function Ck(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,S=m?1:-1;let k={...gt,...p.pose,turn:w,lean:(p.pose?.lean??0)+uo.lean,"head.tilt":(p.pose?.["head.tilt"]??0)+S*uo.tilt};const{over:y,round:E}=a(p,g,S);return k=ye(p.character,k,"arm.right",y),k=ye(p.character,k,"arm.left",E),k},c=l(s,i,!0),h=l(i,s,!1),d=.05*r,u=(p,g,m,w)=>{const S=te(p.character,w).points,{over:k,round:y}=a(p,g,m);return Math.hypot(S["hand.right"].x-k.x,S["hand.right"].y-k.y)<d&&Math.hypot(S["hand.left"].x-y.x,S["hand.left"].y-y.y)<d},f=u(s,i,1,c)&&u(i,s,-1,h);return t.x<=e.x?{a:c,b:h,reached:f}:{a:h,b:c,reached:f}}const on={spacing:.32,low:.3,high:.5,helperLean:40,helperBend:16};function Hk(t,e){return on.spacing*Math.min(t.height,e.height)}function Rk(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:-(on.low+(on.high-on.low)*i)*a},c=m=>m?o?1:.62:o?3:3.38;let h={...gt,...t.pose,turn:c(r),lean:(t.pose?.lean??0)+on.helperLean*(1-i)+4,bend:(t.pose?.bend??0)+on.helperBend*(1-i),"head.nod":18*(1-i)};h=ye(t.character,h,"arm.right",{x:l.x-t.x,y:l.y});const d={...ie.sitFloor,...e.pose,turn:c(!r)},u={...gt,...e.pose,turn:c(!r)};let f=au(d,u,i);f=ye(e.character,f,"arm.right",{x:l.x-e.x,y:l.y});const p=.04*a,g=(m,w)=>{const S=te(m.character,w).points["hand.right"];return Math.hypot(S.x+m.x-l.x,S.y-l.y)<p};return{helper:h,sitter:f,point:l,reached:g(t,h)&&g(e,f)}}const Lk=.7,Nk=50,Dk=1.2,Fk=.8,Wk=3,Bk=30,qk=.8,zk=.6,Za=(t,e)=>Math.max(-e,Math.min(e,t)),Yk=["hair.swing","hair.trail","hair.lift"];function Uu(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=os(l,c),d=os(f=>a(f).x,c),u=os(f=>a(f).y,c);return h.map((f,p)=>{const g=a(f.time),m=f.value-l(f.time),w=d[p].value-g.x-(e.wind??0)*Lk*i,S=u[p].value-g.y,k=Math.sin(g.turn*Math.PI/2),y=Math.cos(g.turn*Math.PI/2),E=m*Wk+w*y/i*Bk,x=-w*k/i*qk,$=-S/i*zk;return{time:f.time,swing:Za(E*s,Nk),trail:Za(x*s,Dk),lift:Za($*s,Fk)}})}function Kk(t,e){if(t.length===0)return{"hair.swing":0,"hair.trail":0,"hair.lift":0};if(e<=t[0].time)return Vu(t[0]);if(e>=t[t.length-1].time)return Vu(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 Vu=t=>({"hair.swing":t.swing,"hair.trail":t.trail,"hair.lift":t.lift}),Fn=16,jk=1500;function Xk(t,e,n,s={}){const i=n.head.hair;if(!i||!bd(i))return[];const o=e.filter(S=>S.target===t),r=o.reduce((S,k)=>k.keyframes.reduce((y,E)=>Math.max(y,E.time),S),0),a=gt,l=new Set(["x","y","turn","head.turn"]),c=new Ot({id:`${t}-hair-follow`,tracks:o.filter(S=>l.has(S.property))}),h=(S,k,y)=>{const E=c.getStateAtTime(S).values.get(t)?.get(k);return typeof E=="number"?E:y},d=new Ot({id:`${t}-hair-pose`,tracks:o}),u=S=>d.getStateAtTime(S).values.get(t),f=new Map,p=S=>{const k=Math.round(S/Fn);let y=f.get(k);if(!y){const E={};for(const[$,M]of u(k*Fn)??[])E[$]=M;const x=te(n,eo(E,a,s.gaits)).head.center;f.set(k,y={x:x.x,y:x.y})}return y},g=S=>{const k=Math.floor(S/Fn),y=S/Fn-k,E=p(k*Fn),x=p((k+1)*Fn);return{x:E.x+(x.x-E.x)*y,y:E.y+(x.y-E.y)*y}},m=Uu(S=>{const k=g(S);return{x:h(S,"x",0)+k.x,y:h(S,"y",0)+k.y,turn:h(S,"turn",a.turn??0),headTurn:h(S,"head.turn",a["head.turn"]??0)}},{start:0,end:r+(s.settle??jk),headRadius:te(n,gt).head.rx,step:s.step,stiffness:s.stiffness,damping:s.damping,amount:s.amount,wind:s.wind}),w=[];for(const S of Yk){const k=S.slice(5);let y=m.map(x=>({time:x.time,value:x[k]}));if(y.every(x=>Math.abs(x.value)<.001))continue;const E=o.find(x=>x.property===S);if(E){const x=new Ot({id:`${t}-${S}-own`,tracks:[E]}),$=M=>Number(x.getStateAtTime(M).values.get(t)?.get(S)??0);y=y.map(M=>({time:M.time,value:M.value+$(M.time)}))}w.push({id:`${t}-${S}`,target:t,property:S,keyframes:y})}return w}const rn={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 Qa(t){if(t===void 0)return rn.full;if(typeof t=="string")return rn[t];const{base:e,...n}=t;return{...rn[e??"full"],...n}}const tl=160,Gk=120,Uk=700,el=60,Vk=90,fo=3200,Wn=1,an=1e-6;function go(t,e,n={}){const s=Qa(n.style),i=n.seed??1,o={};if(t.length===0)return o;const r=Object.keys(t[0].pose).filter(d=>t.some(u=>Math.abs(u.pose[d]-t[0].pose[d])>an));for(const d of r)o[d]=Jk(d,t,e,s,i);const a=e.blink,l=a!==void 0&&r.includes(a);if(s.blinks&&a!==void 0&&!l&&a in t[0].pose){const d=Zk(t,e,s,i,t[0].pose[a]);d.length>0&&(o[a]=d)}const{lift:c,stretch:h}=e;if(s.jumpSquash>0&&c&&h&&r.includes(c)&&!r.includes(h)&&h in t[0].pose){const d=Qk(t,c,t[0].pose[h],s.jumpSquash);d.length>0&&(o[h]=d)}return o}function Jk(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]}],d=(f,p,g)=>{const m=h[h.length-1];if(f<=m.time+Wn){h[h.length-1]={...m,value:p,...g?{easing:g}:{}};return}h.push({time:f,value:p,...g?{easing:g}:{}})};let u=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,S=h[h.length-1].time,k=p.act!==!1;if(Math.abs(w)<=an){const I=p.time+(k?c(f):0);if(f===e.length-1)Math.abs(u-m)>an&&d(Math.max(I,S+tl),m,"ease-in-out"),u=m;else if(k&&a&&s.drift>0&&n.drift.includes(t)&&I-S>=Uk){const O=Gt(`${i}:${t}:${f}`)%2===0?1:-1;u=m+O*s.drift*r,d(I,u,"ease-in-out")}continue}if(!k){d(e[f-1].time,u),d(p.time,m,p.easing),u=m;continue}const y=c(f),E=Math.max(e[f-1].time+y,S);let x=p.time+y;o&&s.eyeDart>0&&(x=Math.min(x,E+s.eyeDart));const $=x-E;if($<=Wn){d(p.time,m,p.easing),u=m;continue}d(E,u);const M=Math.sign(w);if(a&&s.anticipation>0&&r>0&&$>=tl){const I=u-M*Math.min(Math.abs(w)*s.anticipation,r),O=E+$*s.anticipationTime;d(O,I,"ease-in-out"),s.hold>0&&d(O+$*s.hold,I)}const v=f+1<e.length?e[f+1].time-p.time:1/0,T=Math.min(s.settle,v/2);if(a&&s.overshoot>0&&r>0&&$>=Gk&&T>Wn){const I=Math.min(Math.abs(w)*s.overshoot,r);d(x,m+M*I,p.easing??s.actionEase),d(x+T,m,s.settleEase)}else d(x,m,p.easing??s.actionEase);u=m}return h}function Zk(t,e,n,s,i){const o=[],r=el+Vk;for(let f=1;f<t.length;f++){const p=t[f-1].pose,g=t[f].pose;Object.entries(e.headTurns).some(([w,S])=>Math.abs((g[w]??0)-(p[w]??0))>S)&&t[f].act!==!1&&o.push(Math.max(t[0].time,t[f-1].time-n.eyeLead))}const a=t[0].time,l=t[t.length-1].time,c=[...o];let h=a+fo*.6,d=0;for(;h<l;){c.some(g=>Math.abs(g-h)<fo/2)||o.push(h);const p=(Gt(`${s}:blink:${d++}`)%1e3/1e3-.5)*(fo*.66);h+=fo+p}o.sort((f,p)=>f-p);const u=[{time:a,value:i}];for(const f of o){const p=u[u.length-1].time;f+el<=p+Wn||(f>p+Wn&&u.push({time:f,value:i}),u.push({time:f+el,value:1,easing:"ease-in"}),u.push({time:f+r,value:i,easing:"ease-out"}))}return u.length>1?u:[]}function Qk(t,e,n,s){const i=n*(1-.18*s),o=n*(1+.14*s),r=[{time:t[0].time,value:n}],a=(l,c,h)=>{const d=r[r.length-1];l<=d.time+Wn||r.push({time:l,value:c,...h?{easing:h}:{}})};for(let l=1;l<t.length;l++){const c=t[l-1].pose[e],h=t[l].pose[e],d=t[l-1].time,u=t[l].time,f=u-d;if(!(f<tl||t[l].act===!1)){if(c<=an&&h>an)a(d,n),a(d+f*.2,i,"ease-out"),a(d+f*.45,o,"ease-out"),a(u,n,"ease-in-out");else if(c>an&&h<=an){const p=l+1<t.length?t[l+1].time-u:400;a(d+f*.5,n),a(u-Math.min(60,f*.15),o,"ease-in"),a(u,i,"ease-out"),a(u+Math.min(260,p/2),n,{type:"back",mode:"out",overshoot:1.4})}}}return r.length>1?r:[]}const Ju={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 t5(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 e5(){const t={},e={};for(const n of Object.keys(gt)){const s=t5(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 Zu=e5();function Qu(t,e){return Object.entries(e).map(([n,s])=>({id:`${t}-${n}`,target:t,property:n,keyframes:s}))}function tf(t,e,n={}){const s=xi(e),i=e.map((o,r)=>({time:o.time,pose:{...s[r]},easing:o.easing,act:o.act}));return Qu(t,go(i,n.rig??Ju,n))}function ef(t,e,n={}){const s=n.rest??gt,i=Aa(e,s),o=e.map((r,a)=>({time:r.time,pose:{...s,...i[a]},easing:r.easing,act:r.act}));return Qu(t,go(o,n.rig??Zu,n))}const nf=kt.shocked,n5=kt.scared,Fe={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,...nf,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,...kt.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,...nf,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,...kt.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:{...n5,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:{...Yt.sad,bend:18,stretch:.92,lean:t.lean+5,turn:t.turn,sit:t.sit},easing:"ease-in-out"}]};function nl(t,e){const n=typeof e.from=="string"?Yt[e.from]:e.from??ct;return sl(Fe[t](n),{...e,from:n})}function sl(t,e){const n=e.speed??1;let s=e.from;return[{time:e.at,pose:e.from},...t.map(i=>(s={...s,...i.pose},{time:e.at+i.after*n,pose:s,act:!1,...i.easing?{easing:i.easing}:{}}))]}function Rs(t,e=1){const n=Fe[t](ct);return n[n.length-1].after*e}function sf(t,e,n={}){if(e.length<2)return;const s=Math.max(1,Math.round(n.lines??3)),i=n.spacing??5,o=n.lineWidth??2,r=n.opacity??.7;t.save(),t.strokeStyle=n.color??"#222",t.lineCap="round";for(let a=0;a<s;a++){const l=(a-(s-1)/2)*i,c=Math.floor(Math.abs(l)/Math.max(i,1)*(e.length/6));for(let h=c+1;h<e.length;h++){const d=e[h-1],u=e[h],f=u.x-d.x,p=u.y-d.y,g=Math.hypot(f,p)||1,m=-p/g,w=f/g,S=1-h/(e.length-1);t.globalAlpha=r*(1-S),t.lineWidth=o*(1-S*.7),t.beginPath(),t.moveTo(d.x+m*l,d.y+w*l),t.lineTo(u.x+m*l,u.y+w*l),t.stroke()}}t.restore()}const s5={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 i5(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(Br(e,{time:p,state:o(p)},s).joints)}const h=c[c.length-1].height,d=(i.threshold??1.2)*h,u=(i.parts??["hands","toes","head"]).flatMap(f=>s5[f]);for(const f of u){const p=c.map(f.at);let g=0;for(let S=1;S<p.length;S++)g+=Math.hypot(p[S].x-p[S-1].x,p[S].y-p[S-1].y);const m=g/((n.time-l)/1e3);if(m<=d)continue;const w=Math.min(1,(m-d)/(d*.5));sf(t,p,{...i,opacity:(i.opacity??.7)*w,spacing:i.spacing??h*.02})}}function of(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=Gt(`${o}:puff:${a}`)%1e3/1e3,c=a-2,h=e.x+c*i*.3*r,d=e.y-i*(.06+.12*l)*r+Math.abs(c)*i*.03,u=i*(.11+.07*l)*r;t.beginPath(),t.arc(h,d,u,Math.PI*.95,Math.PI*2.05),t.stroke()}t.restore()}function o5(t,e,n,s={}){if(n<=0||n>=1)return;const i=s.size??40,o=5,r=1-(1-n)**2;t.save(),t.strokeStyle=s.color??"#222",t.lineWidth=Math.max(1,i*.035),t.lineJoin="round",t.globalAlpha=n<.7?1:(1-n)/.3;for(let a=0;a<o;a++){const l=-Math.PI/2+(a-(o-1)/2)*Math.PI/(o+1),c=i*(.3+.7*r),h=e.x+Math.cos(l)*c,d=e.y+Math.sin(l)*c;r5(t,h,d,i*.14,n*Math.PI+a),t.stroke()}t.restore()}function r5(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 We={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}},Ls=1,po=.55,rf=.35,a5=1.6,af={a:"a",e:"e",i:"i",y:"i",o:"o",u:"u"},lf={m:"m",b:"m",p:"m",f:"f",v:"f",w:"u",q:"u",l:"l",n:"l",d:"l",t:"l"},cf={अ:"a",आ:"a",इ:"i",ई:"i",उ:"u",ऊ:"u",ऋ:"i",ए:"e",ऐ:"e",ओ:"o",औ:"o",ऍ:"e",ऑ:"o"},hf={"ा":"a","ि":"i","ी":"i","ु":"u","ू":"u","ृ":"i","े":"e","ै":"e","ो":"o","ौ":"o","ॅ":"e","ॉ":"o"},l5={प:"m",फ:"m",ब:"m",भ:"m",म:"m",व:"u"},c5="्",df="़",h5=t=>t>="क"&&t<="ह",uf=new Set([".",",","!","?",";",":","…","।","॥","—","-"]);function ff(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(uf.has(o))s("rest",a5);else if(/\s/.test(o)){const a=e[e.length-1];a&&a.viseme!=="rest"&&e.push({viseme:"c",weight:rf})}else if((o==="o"||o==="e")&&r===o)s(o==="o"?"u":"i",Ls),i++;else if(o in af)s(af[o],Ls);else if(o in lf)s(lf[o],po);else{if(o==="h")continue;if(/[a-z]/.test(o))s("c",po);else if(o in cf)s(cf[o],Ls);else if(h5(o)){const a=r===df?o==="फ"?"f":void 0:l5[o];s(a??"c",po);let l=i+1;n[l]===df&&l++;const c=n[l];c===c5?i=l:c&&c in hf?(s(hf[c],Ls),i=l):(!c||/\s/.test(c)||uf.has(c)||s("a",Ls*.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===rf);)e.pop();return e}function il(t,e={}){const n=e.fields?.mouth??"mouth",s=e.fields?.mouthWidth??"mouthWidth",i=e.energy??1,o=ff(t.text),r=[{time:t.start,value:We.rest.mouth}],a=[{time:t.start,value:We.rest.mouthWidth}],l=o.reduce((h,d)=>h+d.weight,0),c=t.end-t.start;if(l>0&&c>0){let h=t.start;for(const d of o){const u=c*d.weight/l,f=h+Math.min(u*.4,60);if(f>r[r.length-1].time){const p=We[d.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+=u}}return t.end>r[r.length-1].time&&(r.push({time:t.end,value:We.rest.mouth,easing:"ease-in-out"}),a.push({time:t.end,value:We.rest.mouthWidth,easing:"ease-in-out"})),{[n]:r,[s]:a}}function d5(t,e,n={}){const s={};for(const i of[...e].sort((o,r)=>o.start-r.start))for(const[o,r]of Object.entries(il(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 ol(t,e,n,s={}){if(n.length===0)return e;const i=s.fields?.mouth??"mouth",o=s.fields?.mouthWidth??"mouthWidth",r={[i]:We.rest.mouth,[o]:We.rest.mouthWidth,...s.rest},a=new Ot({id:"before-speech",tracks:e}),l=(d,u)=>a.getStateAtTime(u).values.get(t)?.get(d)??r[d],c=[i,o],h=e.filter(d=>d.target!==t||!c.includes(d.property));for(const d of c){const u=e.find(p=>p.target===t&&p.property===d);let f=u?[...u.keyframes]:[{time:0,value:l(d,0)}];for(const p of n){const g=il(p,s)[d];g[0]={...g[0],value:l(d,p.start)},g[g.length-1]={...g[g.length-1],value:l(d,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:u?.id??`${t}-${d}`,target:t,property:d,keyframes:f})}return h}const Ns={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 rl(t={}){return[...Object.keys(Dt),...Object.keys(Yt),...Object.keys(Fe),...Object.keys(Ns),...Object.keys(t.gaits??{}),...Object.keys(t.actions??{})]}function al(t={}){const e=new Set(rl()),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 ll(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(Yt))e[n]=`Moves into the ${n} pose and holds it.`;for(const n of Object.keys(Fe))e[n]=`The ${n} gag, built on the current pose.`;for(const[n,s]of Object.entries(Ns))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 mo=["do","at","for","to","toward","mood","say","pose","target","onto"],u5={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"},yo=["viewer","ahead","back"],ln=t=>typeof t=="number"&&Number.isFinite(t);function Ds(t,e={}){const n=al(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=rl(e),i=l=>l in Dt||l in(e.gaits??{}),o=Object.keys(kt),r=Object.keys(ct);let a=-1/0;return t.forEach((l,c)=>{const h=g=>n.push({level:"error",beat:c,message:g}),d=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 u=l;for(const g of Object.keys(u))mo.includes(g)||h(dt("beat field",g,mo,u5[g.toLowerCase()]));const f=u.do;if(f===void 0){h(`A beat needs \`do\` (what happens). Actions: ${s.join(", ")}`);return}if(typeof f!="string"||!s.includes(f)){h(dt("action",f,s));return}const p=Ns[f]??e.actions?.[f];for(const g of p?.needs??[])u[g]===void 0&&h(`\`${f}\` needs \`${g}\`.`);if(i(f)&&u.to===void 0&&d(`\`${f}\` without \`to\` walks nowhere.`),f==="leap"&&u.to===void 0&&u.onto===void 0&&d("`leap` without `to` or `onto` jumps on the spot."),u.mood!==void 0&&(typeof u.mood!="string"||!o.includes(u.mood))&&h(dt("mood",u.mood,o)),u.pose!==void 0)if(!u.pose||typeof u.pose!="object"||Array.isArray(u.pose))h("`pose` is joints to change, an object like { rightShoulder: 90 } (for a named pose, use it as the action).");else for(const[g,m]of Object.entries(u.pose))r.includes(g)?ln(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=u[g];m!==void 0&&!(ln(m)&&m>=0)&&h(`\`${g}\` is milliseconds, a number ≥ 0 (got ${JSON.stringify(m)}).`)}ln(u.at)&&(u.at<a&&d(`\`at\` ${u.at} is before an earlier beat's \`at\` (${a}); beats run in order, so it starts when the one before ends.`),a=u.at);for(const g of["to","onto"]){const m=u[g];m!==void 0&&!ln(m)&&h(`\`${g}\` is a scene ${g==="to"?"x":"y"} in px, a number (got ${JSON.stringify(m)}).`)}if(u.toward!==void 0&&!ln(u.toward)&&!yo.includes(u.toward)&&h(`\`toward\` is a scene x or one of ${yo.join(", ")}${typeof u.toward=="string"&&is(u.toward,yo)?` (did you mean "${is(u.toward,yo)}"?)`:""} (got ${JSON.stringify(u.toward)}).`),u.say!==void 0&&typeof u.say!="string"&&h(`\`say\` is the line spoken, a string (got ${JSON.stringify(u.say)}).`),u.target!==void 0){const g=u.target;(!g||typeof g!="object"||!ln(g.x)||!ln(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 cl(t,e={},n="scriptTracks"){const s=Ds(t,e).filter(i=>i.level==="error");if(s.length!==0)throw new Error(`${n}: ${s.length} problem(s) in the beats:
53
+ `;function kb(t){if(t.getElementById(b0))return;const e=t.createElement("style");e.id=b0,e.textContent=wb,t.head.appendChild(e)}function w0(t,e){const n=Array.from(e.querySelectorAll("[data-tinyfly-choose]"));if(n.length===0)return()=>{};kb(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 Mi=new WeakMap,Yr=new WeakMap;let vb=0;function ys(t,e,n){if(t)try{return JSON.parse(t)}catch(s){console.warn(`tinyfly: invalid ${e} JSON on`,n,s);return}}async function k0(t,e={}){const n=Mi.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=Sb(t.getAttribute("data-markers")),a=s.length>1||i?.hasAttribute("data-scenario")?Mb(s,r,t):void 0;if(a&&a.length===0)return;let l=i&&!a?ys(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=v0(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=ys(t.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",t),h={playWhenVisible:!0,...e.player,...c&&{captions:c},...ys(t.getAttribute("data-options"),"data-options",t)};xb(t);const u=new vi(t,h),d={element:t,player:u};if(Mi.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}),Yr.set(t,w0(u,t))}else await u.load(l??o);if(t.getAttribute("data-controls")!=="false"){const f=ys(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=y0(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 Mb(t,e,n){const s=[];return t.forEach((i,o)=>{const r=ys(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?v0(r,e):r})}),s}function v0(t,e){return t.config.markers?.length?t:{...t,config:{...t.config,markers:e.map((n,s)=>({id:`step-${s+1}`,time:n}))}}}function Sb(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 M0(t=document,e={}){const n=Array.from(t.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(n.map(i=>k0(i,e)))).filter(i=>i!==void 0)}function Tb(t){const e=Mi.get(t);e&&(Yr.get(t)?.(),Yr.delete(t),e.controls?.destroy(),e.player.destroy(),Mi.delete(t),t.removeAttribute("data-tinyfly-mounted"))}function xb(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-${++vb}`,e.setAttribute("aria-labelledby",s.id))}function Eb(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const e=()=>{M0()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}class S0{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 Ze,this.adapterB=new Ze}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 Ze;i.querySelectorAll("[data-tinyfly]").forEach(l=>{const c=l.getAttribute("data-tinyfly");c&&a.registerTarget(c,l)}),s.push({adapter:a,timeline:wn(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?wn(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 Ab(t,e,n={}){const s=new S0(t,{...n,autoplay:!0});return await s.load(e),s}const Pb={type:"none",duration:0},Pt=t=>({description:t,unit:"degrees"}),St=(t,e=0,n=1)=>({description:t,unit:`${e}..${n}`,min:e,max:n}),T0={lean:Pt("Upper body tipped about the hips (+ toward the way it faces)"),bend:Pt("Line of action: the spine curved (+ curls forward, − arches back)"),headTilt:Pt("Head tilt"),leftShoulder:Pt("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:Pt("Right upper arm: 0 hangs down, 90 straight out (forward, in profile), 180 straight up"),leftElbow:Pt("Left elbow bend, added to the upper arm"),rightElbow:Pt("Right elbow bend, added to the upper arm"),leftHip:Pt("Left thigh: 0 straight down; in profile negative is forward"),rightHip:Pt("Right thigh: 0 straight down; in profile positive is forward"),leftKnee:Pt("Left knee bend (negative folds the shin back)"),rightKnee:Pt("Right knee bend (positive folds the shin back)"),leftWrist:Pt("Left wrist bend, added to the forearm"),rightWrist:Pt("Right wrist bend, added to the forearm"),leftAnkle:Pt("Left ankle: + points the toe down (tiptoe), − onto the heel"),rightAnkle:Pt("Right ankle: + points the toe down (tiptoe), − onto the heel"),leftFootOut:St("Left foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),rightFootOut:St("Right foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in",-1,1),mouth:St("Mouth open: 0 closed, 1 wide open"),smile:St("−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:St("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:St("Left eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),rightBrow:St("Right eyebrow: −1 lowered, 0 rest, 1 raised",-1,1),browTilt:St("Eyebrow slant: −1 angry, 1 worried",-1,1),lookX:St("Eyes look across: + the way it faces",-1,1),lookY:St("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:St("0 front-on, 1 in profile, turned the way it faces"),sit:St("0 standing, 1 seated"),spin:Pt("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"}},x0={walk:{description:"Walk-cycle phase, in strides: animate 0 → n for n strides",unit:"strides"},walking:St("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:St("How much the mouth chatters"),rubber:St("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:St("How much of the dance is applied")},E0={"thumb.curl":St("Thumb curled in"),"thumb.across":St("Thumb across the palm"),"index.curl":St("Index finger curled"),"middle.curl":St("Middle finger curled"),"ring.curl":St("Ring finger curled"),"pinky.curl":St("Little finger curled"),spread:St("Fingers spread apart"),turn:Pt("Hand turned about the forearm"),bend:Pt("Hand bent at the wrist, palm-ward"),tilt:Pt("Hand tilted sideways"),roll:Pt("Hand rolled to show the back or the palm")};let A0;function $b(t){A0=t}function Ib(t){return A0?.(t)??{}}function P0(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 An(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=P0(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 Si(t,e){const n=An(t,e);return n[n.length-1]}function jr(t,e){return e>0?Math.floor(Math.max(0,t)*e/1e3):0}function Ti(t,e,n){const s=e.roughness??2,i=Math.max(1,Math.round(e.passes??2)),o=jr(n,e.boil??8);let r=0;const a=()=>{const d=r++;return f=>Pe(Yt(`${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,M)=>{w.push({x:b.x+l(m,s*.5),y:b.y+l(m,s*.5)}),M>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 M=Ob(w[b-1],w[b],s,v[b-1]),E=p[b-1];if(k+E<=g){t.bezierCurveTo(M[1].x,M[1].y,M[2].x,M[2].y,M[3].x,M[3].y),k+=E;continue}const A=_b(M,E===0?1:(g-k)/E);t.bezierCurveTo(A[1].x,A[1].y,A[2].x,A[2].y,A[3].x,A[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,M=[];for(let A=0;A<=14;A++){const T=k+b*A/14,S=l(w,s*.6);M.push({x:d+Math.cos(T)*(p+S),y:f+Math.sin(T)*(g+S)})}const E=An(M,m);E.length<2||($0(t,E),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)},M={x:l(k,s*.5),y:l(k,s*.5)},E=l(k,s*Math.min(1.5,Math.max(.3,m/80))),A=d.map((S,x)=>{const O=x/(d.length-1),I=Math.sin(Math.PI*O)*E;return{x:S.x+b.x+(M.x-b.x)*O+w*I,y:S.y+b.y+(M.y-b.y)*O+v*I}}),T=An(A,f);T.length<2||($0(t,T),t.stroke())})},circle(d,f,p,g=1){u(d,f,p,p,g)},ellipse:u,nudge(d=.5){const f=a()(0);return{x:l(f,s*d),y:l(f,s*d)}}}}function Ob(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 _b([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 $0(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 Nt(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 xi(t,e,n,s){const i=e.length;if(i<2)return;const o=Nt(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 Qe(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 Kr(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 bs(t,e){return e.look==="pencil"?Lb(t,e):Cb(t,e.ink,e.look)}function Ei(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 Cb(t,e,n){const s=n==="silhouette",i=s?1.25:1;return{look:n,ink:e,limb(o,r,a){t.fillStyle=e,xi(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",Ei(t,o),t.stroke())},shape(o,r,a){Ei(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 Hb(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 Rb(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 I0(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 Lb(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=jr(e.time,n.boil??8);let c=0;const h=(p,g,m=!1)=>Pe(Yt(`${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((O,I,_)=>O+Math.hypot(I.x-p[_].x,I.y-p[_].y),0);let M=Hb(p,Math.max(1.5,Math.min(e.lineWidth*.8,b/24)));if(k>0&&M.length>=2){const[O,I]=[M[M.length-2],M[M.length-1]],_=Math.hypot(I.x-O.x,I.y-O.y)||1;M=[...M,{x:I.x+(I.x-O.x)/_*k,y:I.y+(I.y-O.y)/_*k}]}const E=I0(m),A=I0(m),T=M.length,S=[],x=[];M.forEach((O,I)=>{const _=T===1?0:I/(T-1),C=M[Math.max(0,I-1)],F=M[Math.min(T-1,I+1)],z=Math.hypot(F.x-C.x,F.y-C.y)||1,X=-(F.y-C.y)/z,J=(F.x-C.x)/z,K=E(_)*v,P=Math.min(1,_/.08,(1-_)/.08),R=(.55+.45*Math.sqrt(Math.max(0,P)))*(1+r*A(_)),N=Math.max(.3,g(_)*R/2),$=O.x+X*K,L=O.y+J*K;S.push({x:$+X*N,y:L+J*N}),x.push({x:$-X*N,y:L-J*N})}),t.save(),t.globalAlpha*=w,t.fillStyle=s,Ei(t,[...S,...x.reverse()],!0),t.fill(),t.restore()},d=(p,g)=>{const m=c++,w=h(m,99,!0);if(w.next()<a){const M=(w.next()*2-1)*e.lineWidth*1.4,E=(w.next()*2-1)*e.lineWidth*1.4,A=p.map(T=>({x:T.x+M,y:T.y+E}));u(A,T=>g(T)*1.8,h(m,98,!0),.035,i),u(A,T=>g(T)*.45,h(m,97,!0),.12,i*1.5)}const v=p.slice(1).reduce((M,E,A)=>M+Math.hypot(E.x-p[A].x,E.y-p[A].y),0),k=g(.5)>4&&v>g(.5)*6,b=k?[-.3,.3,0]:[0];for(let M=0;M<o;M++){const E=M===0;b.forEach((A,T)=>{const S=h(m,M*10+T),x=A===0?p:Rb(p,I=>g(I)*A*Math.sqrt(Math.sin(Math.PI*I))),O=!E&&A===0?e.lineWidth*(.3+S.next()*.8):0;u(x,I=>g(I)*(k?.5:1)*(E?1:.6),S,E?.85:.45,i*(E?.6:1),O)})}},f=(p,g,m,w,v,k)=>{const M=h(c,50).next()*Math.PI*2;d(Kr(p,g,m,w,v,M,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,Ei(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),M=Kr(p,g,m,w,v,b.next()*Math.PI*2,1.12,48);u(M,()=>Math.max(.6,e.lineWidth*.18),b,.28,i*1.5)}}}const O0=["thumb","index","middle","ring","pinky"],It={"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 Ot(t={}){return{...It,...t}}const Xt=(t,e,n,s,i)=>({"thumb.curl":t,"index.curl":e,"middle.curl":n,"ring.curl":s,"pinky.curl":i}),_t={relaxed:It,open:Ot({...Xt(0,0,0,0,0),"thumb.across":0,spread:.55}),spread:Ot({...Xt(0,0,0,0,0),"thumb.across":0,spread:1}),flat:Ot({...Xt(0,0,0,0,0),"thumb.across":.35,spread:0}),fist:Ot({...Xt(.7,1,1,1,1),"thumb.across":.9,spread:0}),point:Ot({...Xt(.75,0,1,1,1),"thumb.across":.9,spread:0}),thumbsUp:Ot({...Xt(0,1,1,1,1),"thumb.across":0,spread:0,roll:70}),peace:Ot({...Xt(.75,0,0,1,1),"thumb.across":.9,spread:1}),ok:Ot({...Xt(.12,.6,.1,.15,.2),"thumb.across":.55,spread:.6}),pinch:Ot({...Xt(.1,.65,.75,.85,.9),"thumb.across":.55,spread:0}),cupped:Ot({...Xt(.25,.4,.4,.4,.4),"thumb.across":.4,spread:.05,turn:2}),wave:Ot({...Xt(0,.05,.05,.1,.12),"thumb.across":0,spread:.7,turn:2}),pencilGrip:Ot({...Xt(.1,.6,.72,.88,.95),"thumb.across":.5,spread:0,turn:.8,bend:10}),hold:Ot({...Xt(.5,.7,.72,.74,.76),"thumb.across":.75,spread:0,turn:1})};function Pn(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 Nb={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}},Fb={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}},ge={base:[-.11,.1,-.05],bones:[.2,.15,.12],widths:[.2,.145,.135],out:[-.7,.68,-.22],across:[.35,.5,-.8]},Db=[82,100,62],Wb=[48,72],Bb=3,zb=13,qb=.035,Yb=-.075,jb=[[-.17,0],[-.215,.12],[-.235,.26],[-.225,.4],[-.185,.49],[-.075,.525],[.05,.51],[.16,.465],[.215,.4],[.225,.26],[.2,.1],[.16,0]],Ie=t=>t*Math.PI/180,Xr=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Ai=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],Gr=(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]],ws=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function Oe(t,e,n){const s=Math.cos(n),i=Math.sin(n),o=Gr(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 _0=[1,0,0],C0=[0,1,0],ks=[0,0,1];function Kb(t,e,n){const s=Ie(t.fan*(Bb+zb*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+=Ie(Db[u]*e),r.push(Xr(r[u],Ai(Oe(i,o,-a),h)))});const l=Oe(ks,o,-a),c=r.map((h,u)=>t.width*(1-.14*(u/(r.length-1))));return{joints:r,back:l,widths:c}}function Xb(t,e,n=1,s=1){const i=Math.min(1,Math.max(0,e)),o=ws(Xr(Ai(ws(ge.out),1-i),Ai(ws(ge.across),i))),r=ws(Gr(ks,o)),a=ws(Gr(o,r)),l=[[ge.base[0]*s,ge.base[1],ge.base[2]]];let c=0;ge.bones.forEach((d,f)=>{f>0&&(c+=Ie(Wb[f-1]*t)),l.push(Xr(l[f],Ai(Oe(o,r,c),d)))});const h=Oe(a,r,c),u=[...ge.widths,ge.widths[ge.widths.length-1]*.92].map(d=>d*n);return{joints:l,back:h,widths:u}}function Pi(t,e={}){const n={...It,...t},s=e.size??100,i=e.side??"right",o=i==="left"?-1:1,r=Ie(e.angle??0),a=e.fingers===4,l=Math.max(.5,e.plump??1),c=1+(l-1)*.7,h=I=>({...I,knuckle:[I.knuckle[0]*c,I.knuckle[1],I.knuckle[2]],width:I.width*l}),u=Ie(n.bend??0),d=Ie(n.tilt??0),f=Ie(90*(n.turn??0)),p=I=>Oe(Oe(Oe(I,_0,-u),ks,-d),C0,f),g=Math.cos(r),m=Math.sin(r),w=Ie(n.roll??0),v=Math.cos(w),k=Math.sin(w),b=I=>{const _=I[0]*s,C=-I[1]*s,F=(_*v-C*k)*o,z=_*k+C*v;return{x:F*g-z*m,y:F*m+z*g}},M=I=>{const _=b(I),C=Math.hypot(_.x,_.y);return C>1e-6*s?{x:_.x/C,y:_.y/C}:{x:0,y:0}},E={thumb:Xb(n["thumb.curl"]??0,n["thumb.across"]??0,l,c)},A=a?Fb:Nb;for(const I of O0){const _=A[I];_&&(E[I]=Kb(h(_),n[`${I}.curl`]??0,n.spread??0))}const T={};for(const[I,_]of Object.entries(E)){const C=_.joints.map(p),F=p(_.back);T[I]={points:C.map(b),depths:C.map(z=>z[2]*s),widths:_.widths.map(z=>z*s),nail:F[2],back:M(F)}}const S=jb.flatMap(([I,_])=>[p([I*c,_,qb]),p([I*c,_,Yb])]),x=Gb(S.map(b)),O=S.reduce((I,_)=>I+_[2],0)/S.length*s;return{size:s,side:i,wrist:{x:0,y:0},palm:x,palmDepth:O,palmFacing:-p(ks)[2],fingers:T,axes:{up:M(p(C0)),across:M(p(_0)),out:M(p(ks))},curls:Object.fromEntries(Object.keys(T).map(I=>[I,n[`${I}.curl`]??0]))}}function H0(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 Gb(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 Ub="#f1c9a5",Vb="#2f2f33";function $i(t,e,n,s={},i=0){const o=H0(Pi(n,s),e),r=s.ink??Vb,a=s.lineWidth??o.size*.035,l=s.pen??bs(t,{look:s.look??"clean",ink:r,lineWidth:a,seed:s.seed??1,time:i,pencil:{construction:!1,...s.pencil}}),c=s.skin??Ub,h=s.nails??!0,u=[{depth:o.palmDepth,draw:()=>Jb(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:()=>Zb(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 Jb(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 Zb(t,e,n,s,i,o){const{widths:r}=n,a=Qb(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,xi(t,a,h,u)),e.look==="silhouette"||!o||n.nail<.25)return;const d=a[a.length-2],f=tw({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 Qb(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 tw=t=>{const e=Math.hypot(t.x,t.y);return e>1e-6?{x:t.x/e,y:t.y/e}:null},Ft={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}},ew=40;function vs(t){return t===void 0?Ft.walk:typeof t=="string"?Ft[t]??Ft.walk:t}function R0(t,e,n=ct,s=1){const i=vs(t);if(i===Ft.walk)return W0(e,n,s);const o=e*Math.PI*2,r=Math.sin(o)*s,a=Math.cos(o)*s,l=w=>Math.abs(w)<=ew,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 Ii(t,e,n=1){const s=vs(t),i=Ft.walk.swing,o=r=>Math.sin(r*Math.PI/180);return B0(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 Ct(t){return{...ct,...t}}const L0={mouth:0,smile:0,mouthWidth:1,leftEye:1,rightEye:1,leftBrow:0,rightBrow:0,browTilt:0,lookX:0,lookY:0},Lt=t=>({...L0,...t}),kt={neutral:L0,happy:Lt({smile:.9,leftBrow:.2,rightBrow:.2}),joyful:Lt({mouth:.6,smile:1,mouthWidth:1.2,leftEye:0,rightEye:0,leftBrow:.4,rightBrow:.4}),sad:Lt({smile:-.8,leftEye:.8,rightEye:.8,browTilt:.9,leftBrow:-.1,rightBrow:-.1,lookY:.6}),crying:Lt({mouth:.45,smile:-1,leftEye:0,rightEye:0,browTilt:1,lookY:.4}),surprised:Lt({mouth:.7,mouthWidth:.7,leftEye:1.5,rightEye:1.5,leftBrow:1,rightBrow:1}),shocked:Lt({mouth:1,mouthWidth:.8,leftEye:1.6,rightEye:1.6,leftBrow:1,rightBrow:1,browTilt:.4}),angry:Lt({smile:-.6,mouthWidth:.9,leftEye:.8,rightEye:.8,leftBrow:-.6,rightBrow:-.6,browTilt:-1}),furious:Lt({mouth:.5,smile:-1,mouthWidth:1.3,leftEye:.9,rightEye:.9,leftBrow:-.9,rightBrow:-.9,browTilt:-1}),worried:Lt({smile:-.3,mouthWidth:.8,leftEye:1.1,rightEye:1.1,leftBrow:.3,rightBrow:.3,browTilt:.8,lookX:-.5}),scared:Lt({mouth:.35,smile:-.5,mouthWidth:.8,leftEye:1.45,rightEye:1.45,leftBrow:.8,rightBrow:.8,browTilt:.9}),confused:Lt({smile:-.2,mouthWidth:.8,leftEye:.9,rightEye:1.15,leftBrow:-.3,rightBrow:.8,lookX:.5,lookY:-.4}),skeptical:Lt({smile:-.1,leftEye:.6,rightEye:1,leftBrow:-.4,rightBrow:.7,lookX:.4}),thinking:Lt({smile:0,mouthWidth:.7,leftBrow:.3,rightBrow:.5,lookX:.6,lookY:-.8}),sleepy:Lt({smile:.1,leftEye:.25,rightEye:.25,leftBrow:-.3,rightBrow:-.3,lookY:.5}),disgusted:Lt({smile:-.7,mouthWidth:.9,leftEye:.6,rightEye:.75,leftBrow:-.5,rightBrow:-.2,browTilt:-.4,lookX:-.6}),smug:Lt({smile:.6,mouthWidth:.9,leftEye:.6,rightEye:.6,leftBrow:.1,rightBrow:.5,lookX:.5}),wink:Lt({smile:.9,leftEye:0,rightEye:1,leftBrow:-.2,rightBrow:.3})};function _e(t,e){return{...t,...typeof e=="string"?kt[e]:e}}const Gt={rest:ct,wave:Ct({rightShoulder:135,rightElbow:30,headTilt:6,...kt.happy}),cheer:Ct({leftShoulder:125,leftElbow:20,rightShoulder:125,rightElbow:20,...kt.joyful}),shrug:Ct({leftShoulder:30,leftElbow:85,rightShoulder:30,rightElbow:85,headTilt:-10,...kt.confused,lookX:0,lookY:0}),point:Ct({rightShoulder:90,rightElbow:0,lean:4,smile:.4}),think:Ct({rightShoulder:60,rightElbow:150,headTilt:10,...kt.thinking}),handsOnHips:Ct({leftShoulder:45,leftElbow:-100,rightShoulder:45,rightElbow:-100,leftHip:14,rightHip:14,smile:.8}),sad:Ct({leftShoulder:14,rightShoulder:14,leftElbow:-4,rightElbow:-4,headTilt:-14,lean:-3,...kt.sad}),surprised:Ct({leftShoulder:70,leftElbow:60,rightShoulder:70,rightElbow:60,...kt.surprised}),crouch:Ct({stretch:.72,leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50,leftHip:22,rightHip:22,headTilt:-4}),sit:Ct({sit:1,turn:.5,leftShoulder:-25,rightShoulder:25,leftElbow:-55,rightElbow:55}),jump:Ct({stretch:1.22,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4,...kt.joyful}),duck:Ct({stretch:.62,bend:28,headTilt:-8,leftShoulder:150,rightShoulder:150,leftElbow:130,rightElbow:130,leftHip:25,rightHip:25,...kt.scared}),lie:Ct({spin:-90,rise:-.42,leftShoulder:165,rightShoulder:165,leftElbow:150,rightElbow:150,...kt.sleepy}),sideSplit:Ct({leftHip:90,rightHip:90,leftAnkle:-45,rightAnkle:-45,leftShoulder:120,rightShoulder:120,leftElbow:10,rightElbow:10,...kt.happy}),frontSplit:Ct({turn:1,leftHip:-90,rightHip:-90,leftAnkle:-45,rightAnkle:-45,leftShoulder:-150,rightShoulder:150,leftElbow:10,rightElbow:-10,...kt.happy})},N0=Object.keys(ct);function $n(t,e,n){const s={...t};for(const i of N0)s[i]=t[i]+(e[i]-t[i])*n;return s}const Ur=24,F0=4,D0=28,nw=40;function W0(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)<=nw,r=c=>o(c)?22*s:c,a=o(e.leftShoulder)?e.leftElbow-D0*Math.max(0,-s):e.leftElbow,l=o(e.rightShoulder)?e.rightElbow+D0*Math.max(0,s):e.rightElbow;return{...e,lean:e.lean+F0*n,headTilt:e.headTilt-F0*.5*n,leftElbow:a,rightElbow:l,leftHip:-Ur*s,rightHip:-Ur*s,leftKnee:-30*Math.max(0,i),rightKnee:30*Math.max(0,-i),leftShoulder:r(e.leftShoulder),rightShoulder:r(e.rightShoulder)}}function B0(t,e=1){return 4*((Vr+Oi)*t)*Math.sin(Ur*e*Math.PI/180)}function z0(t){const e=Math.abs(Math.sin(t/65)),n=.55+.45*Math.sin(t/310);return e*n}const q0=.12,Y0=.46,sw=1-2*q0,iw=.1,ow=.21,rw=.19,Vr=.24,Oi=.22,j0=.12,aw=.14,K0=.33,X0=.7,G0=.3,lw=.35,cw=[1.7,1.05],hw=[1.3,.75],U0=[1.45,.85],uw=[1.15,.75],V0=.06,dw=.7,fw=.65,J0=.075,gw=.3,pw=.02,mw=.012,yw=12,bw=.25,_i=90,ww=.25,kw=.04,Z0=.01,tn=t=>Math.min(1,Math.max(0,t??0));function vw(t,e=1){return Oi*t*e}const Jr=-.12,Q0=.4,Zt=t=>t*Math.PI/180,Mw=(t,e)=>({x:e*Math.sin(Zt(t)),y:Math.cos(Zt(t))}),tu=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),eu=(t,e,n,s)=>t-.3*e-n*.14*e-Math.max(0,s-1)*.12*e;function Sw(t,e,n,s,i,o){const r=Math.max(1,Math.min(o*.6,aw*n)),a=tn(e.turn),l=(j0+K0*a)*n,c=s+Jr*n,h=l+e.lookX*.08*n,u=e.lookY*.07*n,d=[{x:-.34*n*(1-X0*a),squeeze:1-X0*a,open:e.leftEye,brow:e.leftBrow,side:-1},{x:.34*n*(1-G0*a),squeeze:1-G0*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=tu(w.open,e.blink);if(v<.2){const E=e.smile>.5?-.12*n:.06*n;t.beginPath(),t.moveTo(w.x+l-.12*n,c),t.quadraticCurveTo(w.x+l,c+E,w.x+l+.12*n,c),t.stroke()}else{if(v>1.2){const A=.13*n*v;t.beginPath(),t.ellipse(w.x+l,c,A*.85,A,0,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.stroke(),t.fillStyle=i}const E=v>1.2?.075*n:.1*n;t.beginPath(),t.ellipse(w.x+h,c+u,E,E*1.1*Math.min(v,1),0,0,Math.PI*2),t.fill()}const k=eu(c,n,w.brow,v),b=w.x+l-w.side*.13*n*w.squeeze,M=w.x+l+w.side*.13*n*w.squeeze;t.beginPath(),t.moveTo(M,k),t.lineTo(b,k-e.browTilt*.1*n),t.stroke()}const f=s+Q0*n,p=.25*n*Math.max(.3,e.mouthWidth)*(1-lw*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 nu(t,e){const n=e.height??300,s=Math.min(3,Math.max(.3,t.stretch??1)),i=Math.sqrt(s),o=(e.headSize??2*q0)/2,r=e.headSize===void 0?sw:1-2*o,a=o*n,l=tn(t.sit),c=t.leftHip+(-_i-t.leftHip)*l,h=t.leftKnee+(-_i-t.leftKnee)*l,u=t.rightHip+(_i-t.rightHip)*l,d=t.rightKnee+(_i-t.rightKnee)*l,f=e.classic===!0,p=tn(t.turn),g=(J,K,P,R,N)=>{const $=Math.max(-Math.PI/2,Math.min(Math.PI/2,Math.abs(Zt(K-P)/2)+Zt(R))),L=Math.max(-1,Math.min(1,dw+N)),W=p+(1-p)*J*L;return f?{x:0,y:0}:{x:Math.cos($)*V0*W,y:Math.sin($)*V0}},m={left:t.leftAnkle??0,right:t.rightAnkle??0},w={left:t.leftFootOut??0,right:t.rightFootOut??0};let v=0;if(l>0||!f){const J=(N,$,L,W,q)=>Vr*Math.cos(Zt($))+Oi*Math.cos(Zt($-L))+Math.max(0,g(N,$,L,W,q).y),K=Math.max(J(-1,c,h,m.left,w.left),J(1,u,d,m.right,w.right)),P=1-tn((t.rise??0)/kw),R=(f?Math.min(1,l/ww):1)*P;v=(Y0-K)*R*n*s}const k=-Y0*n*s+v,b=-r*n*s+v,M=f?0:(pw*tn(t.turn)+mw*l)*n*s,E=Zt(t.bend??0),A={end:iu(k,b,E,1),bend:E};let T;if(E!==0){T=[];for(let J=0;J<=su;J++){const K=J/su,P=iu(k,b,E,K);T.push({x:P.x-M*Math.sin(Math.PI*K),y:P.y})}}else T=M===0?[{x:0,y:k},{x:0,y:b}]:Qe({x:0,y:k},{x:-M,y:(k+b)/2},{x:0,y:b},1,8);const S=b+iw*n*s,x=(e.shoulderWidth??0)*n*Math.cos(p*Math.PI/2),O=(J,K,P,R,N)=>{const $=Mw(P,R);return{x:J+$.x*N*n,y:K+$.y*N*n}},I=(J,K,P)=>{const R=O(0,k,K,J,Vr*s);return{root:{x:0,y:k},joint:R,end:O(R.x,R.y,K-P,J,Oi*s)}},_=(J,K,P)=>{const R={x:J*x,y:S},N=O(R.x,R.y,K,J,ow*i);return{root:R,joint:N,end:O(N.x,N.y,K+P,J,rw*i)}},C={left:I(-1,c,h),right:I(1,u,d)},F=(J,K,P,R,N,$)=>{const L=g(J,P,R,N,$);return{x:K.end.x+L.x*n*s,y:K.end.y+L.y*n*s}},z=(J,K,P,R,N)=>O(K.end.x,K.end.y,P+R+N,J,J0*i),X={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(f?0:gw,e.rubber??0)),r:a,headRx:a/Math.sqrt(s),headRy:a*Math.sqrt(s),hipY:k,neckY:b,drop:v,lean:f?t.lean:t.lean+yw*Math.sin(Math.PI*l),classic:f,legs:C,toes:{left:F(-1,C.left,c,h,m.left,w.left),right:F(1,C.right,u,d,m.right,w.right)},spine:T,chest:A,arms:X,handTips:{left:z(-1,X.left,t.leftShoulder,t.leftElbow,t.leftWrist??0),right:z(1,X.right,t.rightShoulder,t.rightElbow,t.rightWrist??0)}}}const su=10;function iu(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 Tw(t,e){if(t.chest.bend===0)return e;const n=Ss(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 Ms=(t,e)=>e===0?[t.root,t.joint,t.end]:Qe(t.root,t.joint,t.end,e);function Ss(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 ou(t,e,n=!0){const s=Ew(t,e),i=e.spin??0,o=e.rise??0;return n&&(i!==0||o!==0)?xw(s,t,i,o):s}function ru(t,e,n){return{pivot:{x:0,y:t.hipY},angle:t.facing*Zt(e),lift:n*t.height}}function xw(t,e,n,s){const{pivot:i,angle:o,lift:r}=ru(e,n,s),a=d=>{const f=Ss(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=Z0*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 Ew(t,e){const n=Zt(t.lean),s=Zt(e.headTilt),i={x:0,y:t.hipY},o=b=>({x:t.facing*b.x,y:b.y}),r=b=>o(Ss(b,i,n)),a=b=>r(Tw(t,b)),l=b=>a(Ss({x:b.x,y:b.y+t.neckY},{x:0,y:t.neckY},s)),c=Ms(t.arms.left,t.rubber).map(a),h=Ms(t.arms.right,t.rubber).map(a),u=(b,M)=>Math.atan2(M.y-b.y,M.x-b.x),d={left:a(t.handTips.left),right:a(t.handTips.right)},f=(b,M)=>{const[E,A]=b.slice(-2),T=t.arms[M],S=u(a(T.end),d[M])-u(a(T.joint),a(T.end));return u(E,A)+S};let p=1/0;for(const[b,M]of[[e.leftBrow,e.leftEye],[e.rightBrow,e.rightEye]]){const E=eu(Jr,1,b,tu(M,e.blink));p=Math.min(p,E,E-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=Z0*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:Ms(t.legs.left,t.rubber).map(o),rightLeg:Ms(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:Jr,browTopY:p,mouthY:Q0,faceX:t.facing*(j0+K0*tn(e.turn))}}}function ie(t,e={}){return ou(nu(t,e),t)}function Aw(t,e,n){return Ss({x:t.center.x+e*t.rx,y:t.center.y+n*t.ry},t.center,t.angle)}function au(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 lu(t,e,n={},s=0){const i=nu(e,n),o=n.color??"#1e293b",r=n.layers??{},a=n.layers?ou(i,e,!1):void 0,l=n.sketch?Ti(t,n.sketch,s):void 0,c=n.sketch&&n.layers?Ti(t,n.sketch,s):void 0,h=A=>{t.save(),A(),t.restore()},u=A=>{A&&a&&h(()=>A(t,a,s,c))},d=()=>t.scale(i.facing,1),f=()=>{d(),t.translate(0,i.hipY),t.rotate(Zt(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=(A,T,S)=>{if(l)return T?l.curve(A):l.line(A);if(i.classic){t.beginPath(),t.moveTo(A[0].x,A[0].y);for(const x of A.slice(1))t.lineTo(x.x,x.y);t.stroke();return}xi(t,A,S[0]*i.lineWidth,S[1]*i.lineWidth)},m=(A,T)=>g(Ms(A,i.rubber),i.rubber>0,T),w=A=>{i.classic||g([i.legs[A].end,i.toes[A]],!1,uw)},v=A=>{if(n.hands&&!i.classic)return b(A);if(i.classic||l)return;const T=i.arms[A].end;t.beginPath(),t.arc(T.x,T.y,fw*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=ru(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(A){const T=n.hands??{},S=i.arms[A].end,x=i.handTips[A],O=n.headFill??"#ffffff";$i(t,S,T[A]??It,{side:A,angle:Math.atan2(x.x-S.x,S.y-x.y)*180/Math.PI,size:(T.size??J0)*i.height*Math.sqrt(i.stretch),skin:T.skin??(O==="none"?void 0:O),ink:o,lineWidth:i.lineWidth*.45,fingers:T.fingers,plump:T.plump,look:n.sketch?"pencil":"clean",seed:n.sketch?.seed},s)}const M=A=>{h(()=>{p(),m(i.arms[A],hw),v(A)});const T=r.sleeve;T&&a&&h(()=>T(t,a,A,s,c))},E=tn(e.turn)>bw;u(r.behind),h(()=>{d(),m(i.legs.left,U0),w("left"),m(i.legs.right,U0),w("right")}),E&&M("left"),h(()=>{f(),g(i.spine,i.spine.length>2,cw)}),h(()=>{p();const{left:A,right:T}={left:i.arms.left.root,right:i.arms.right.root};if(A.x!==T.x)if(i.classic)g([A,T],!1,[1,1]);else{const S={x:(A.x+T.x)/2,y:A.y-.3*Math.abs(T.x-A.x)};g(Qe(A,S,T,1,8),!0,[1.1,1.1])}}),u(r.body),E||M("left"),M("right"),u(r.behindHead),h(()=>{p(),t.translate(0,i.neckY),t.rotate(Zt(e.headTilt));const A=-i.headRy;t.beginPath(),t.ellipse(0,A,i.headRx,i.headRy,0,0,Math.PI*2);const T=n.headFill??"#ffffff";if(T!=="none"&&(t.fillStyle=T,t.fill()),l){l.ellipse(0,A,i.headRx,i.headRy);const S=l.nudge();t.translate(S.x,S.y)}else t.stroke();t.translate(0,A),t.scale(i.headRx/i.r,i.headRy/i.r),Sw(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 Zr(t,e,n,s){const i={...t},o=t.gait&&s?.[t.gait]||t.gait;let r=t.walking>0?$n(i,R0(o,t.walk,i),t.walking):i,a=Pw(t);const l=t.dancing??0;if(n&&l>0){const c=n(t.beat??0);if(r=$n(r,c.pose,l),c.hands){const h=(u,d)=>d?Pn(u??It,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*z0(e))}),{pose:r,hands:a}}function cu(t,e,n,s){return Zr(t,e,n,s).pose}const hu=(t,e)=>(t.facing??e.facing??1)<0?-1:1,Ts=(t,e)=>`hand.${t}.${e}`;function Pw(t){const e=i=>{if(typeof t[Ts(i,"spread")]=="number")return Object.fromEntries(Object.keys(It).map(o=>[o,t[Ts(i,o)]]))},n=e("left"),s=e("right");return n||s?{left:n,right:s}:void 0}function $w(t,e){return!e||!t.hands?t:{...t,hands:{...t.hands,left:e.left??t.hands.left,right:e.right??t.hands.right}}}function Qr(t){const e=t.style??{},n=e.height??300,s=n*.8,i={...Ct(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]??It;for(const l of Object.keys(It))o[Ts(r,l)]=a[l]??It[l]}return{type:"custom",x:t.x-s/2,y:t.y-n,width:s,height:n,props:{...i,...o},about:Iw(Object.keys(o),t.cast),figureStyle:e,figureDance:t.dance,figureGaits:t.cast?.gaits,draw(r,a,l){const c=a.props,h=Zr(c,l,t.dance,t.cast?.gaits);r.translate(s/2,n),lu(r,h.pose,$w({...e,rubber:c.rubber,facing:hu(c,e)},h.hands),l)}}}function Iw(t,e){const n={...T0,...x0};for(const s of t){const[,i,...o]=s.split("."),r=E0[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 Ib(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=cu(i,e.time,t.figureDance,t.figureGaits),l=ie(a,{...s,rubber:i.rubber,facing:hu(i,s)});return{pose:a,joints:au(l,t.x+o+t.width/2,t.y+r+t.height)}}function Ci(t){const e=[];return t.forEach((n,s)=>{const i=s===0?ct:e[s-1],o=typeof n.pose=="string"?Gt[n.pose]:{...i,...n.pose};e.push(n.expression?_e(o,n.expression):o)}),e}function Ow(t,e){const n=Ci(e);return N0.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 ea=.5,Hi={pataka:Ot({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:0,turn:2}),tripataka:Ot({"thumb.curl":.3,"thumb.across":.6,"index.curl":0,"middle.curl":0,"ring.curl":1,"pinky.curl":0,spread:0,turn:2}),alapadma:Ot({"thumb.curl":.1,"thumb.across":0,"index.curl":.05,"middle.curl":.15,"ring.curl":.25,"pinky.curl":.35,spread:1,turn:2}),mushti:_t.fist,shikhara:_t.thumbsUp,hamsasya:Ot({"thumb.curl":.15,"thumb.across":.6,"index.curl":.6,"middle.curl":0,"ring.curl":0,"pinky.curl":0,spread:.7,turn:2}),katakamukha:Ot({"thumb.curl":.2,"thumb.across":.6,"index.curl":.65,"middle.curl":.7,"ring.curl":0,"pinky.curl":0,spread:.4,turn:2})};function Ri(t){return typeof t!="string"?t:t in Hi?Hi[t]:_t[t]}function uu(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?Ri(i.hands.left):r.left,right:i.hands?.right?Ri(i.hands.right):r.right,easing:i.easing??t.easing})}return s}const na=(t,e)=>(t%e+e)%e;function _w(t,e,n,s){const i=uu(t,n,s);if(i.length===0)return{pose:n,hands:s};const o=na(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=Ht(l.easing??"ease-in-out")(Math.min(1,Math.max(0,u)));return{pose:$n(a.pose,l.pose,d),hands:{left:Pn(a.left,l.left,d),right:Pn(a.right,l.right,d)}}}const Cw=[["leftShoulder","rightShoulder"],["leftElbow","rightElbow"],["leftWrist","rightWrist"],["leftHip","rightHip"],["leftKnee","rightKnee"],["leftAnkle","rightAnkle"],["leftFootOut","rightFootOut"],["leftEye","rightEye"],["leftBrow","rightBrow"]],Hw=["lean","headTilt","lookX","spin"],Rw=new Set(["leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee"]);function du(t){const e={...t},n=(t.turn??0)>=.5;for(const[s,i]of Cw){const o=n&&Rw.has(s)?-1:1;e[s]=o*t[i],e[i]=o*t[s]}if(!n)for(const s of Hw)e[s]=-t[s];return e}const Lw=t=>Math.min(1,Math.max(-1,(.5-t)*4));function fu(t,e,n){const s=na(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=Lw(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 Li(t){const e={...ct,...t.stance};return t.expression?_e(e,t.expression):e}function gu(t){return{left:t.hands?.left?Ri(t.hands.left):It,right:t.hands?.right?Ri(t.hands.right):It}}function sa(t,e,n){const s=t.moves[e.move];if(!s)throw new Error(`dance: "${t.label}" has no move "${e.move}"`);const i=_w(s,n,Li(t),gu(t));return e.mirror?{pose:du(i.pose),hands:{left:i.hands?.right,right:i.hands?.left}}:i}function Ni(t,e,n={}){const s=typeof t=="string"?Ce[t]:t;let i;if(n.move)i=sa(s,{move:n.move,mirror:n.mirror},e);else{const o=s.routine,r=o.reduce((u,d)=>u+d.beats,0),a=na(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=sa(s,o[c],h),h<ea&&o.length>1&&e>=ea){const u=o[(c-1+o.length)%o.length],d=sa(s,u,u.beats+h),f=Ht("ease-in-out")(h/ea);i={pose:$n(d.pose,i.pose,f),hands:{left:Pn(d.hands.left,i.hands.left,f),right:Pn(d.hands.right,i.hands.right,f)}}}}return{...i,pose:fu(i.pose,s.groove,e)}}function Nw(t,e,n={}){return Ni(t,e,n).pose}function Fi(t){return(typeof t=="string"?Ce[t]:t).routine.reduce((n,s)=>n+s.beats,0)}const Fw={leftToe:"rightToe",rightToe:"leftToe",leftHeel:"rightHeel",rightHeel:"leftHeel"};function pu(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?Fw[u]:u})}}function Dw(t,e,n,s={}){const i=typeof t=="string"?Ce[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;pu(r,a,Math.ceil((n-a)/r.beats)*r.beats,s.mirror,o,e,n)}else{const r=Fi(i);for(let a=Math.floor(e/r)*r;a<n;a+=r){let l=a;for(const c of i.routine)pu(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 mu(t,e){const n=t.moves[e.move];if(!n?.travel)return 0;const s=n.travel/n.beats;return e.mirror?(uu(n,Li(t),gu(t))[0]?.pose.turn??Li(t).turn??0)>=.5?s:-s:s}function yu(t,e){return e.move?[{move:e.move,beats:t.moves[e.move].beats,mirror:e.mirror}]:t.routine}function Di(t,e,n={}){const s=typeof t=="string"?Ce[t]:t,i=yu(s,n),o=i.reduce((h,u)=>h+u.beats,0),r=i.reduce((h,u)=>h+mu(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+=mu(s,h)*u,c-=u,c<=0)break}return l}function Ww(t,e,n){const s=yu(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 Bw=8;function bu(t,e,n){const s=typeof e=="string"?Ce[e]:e,i=n.bpm??s.bpm,o=n.beats??(n.move?s.moves[n.move].beats:Fi(s)),r=Ww(s,o,n);if(r.every(w=>Di(s,w,n)===0))return;const a=Math.min(n.fade??1,o/2),l=Ht("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*Bw),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 M=0;M<b;M++){const E=k+(w-k)*M/b,A=k+(w-k)*(M+1)/b;f+=(Di(s,A,n)-Di(s,E,n))*c((E+A)/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 zw(t,e,n=0){return(t-n)*e/6e4}function qw(t,e={}){return n=>Ni(t,n,e)}function Yw(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 jw(t,e,n={}){const s=typeof e=="string"?Ce[e]:e,i=n.bpm??s.bpm,o=n.beats??(n.move?s.moves[n.move].beats:Fi(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:Ni(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:bu(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(It)){const w=v=>v.hands?.[g]?.[m]??It[m];c.some(v=>w(v.frame)!==It[m])&&p.push(h(Ts(g,m),w))}return[...d,...p]}const xs={type:"back",mode:"out",overshoot:1.1},Bt="ease-out-cubic",Kw={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:Bt,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:Bt},{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:Bt},{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}]},Xw={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}]},Gw={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:Bt},{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:Bt},{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:Bt},{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:xs},{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}]},Uw={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:{..._t.spread,turn:2},right:{..._t.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:Bt},{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}]},Vw={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:xs,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:xs},{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:xs},{beat:3,pose:{headTilt:4}}]},isolations:{label:"Isolations",beats:2,easing:Bt,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}]},Jw={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:{..._t.cupped,roll:-30},left:{..._t.flat,turn:0}}},{beat:.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{..._t.cupped,roll:30}}},{beat:1,pose:{rightWrist:-15,rightElbow:12,leftWrist:-45,lean:-4,rightHip:16,leftHip:6},hands:{right:{..._t.cupped,roll:-30}}},{beat:1.5,pose:{rightWrist:25,rightElbow:22,leftWrist:10,lean:4,rightHip:6,leftHip:16},hands:{right:{..._t.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:{..._t.open,turn:2}},easing:Bt},{beat:.5,pose:{lean:-4,rightHip:12,headTilt:6}},{beat:1,pose:{lean:-11,rightHip:22,headTilt:10},easing:Bt},{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:Bt},{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:Bt}]}},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}]},Zw={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}]},Qw={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}]},t2={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:{..._t.spread,turn:2},right:{..._t.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:Bt},{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:Bt},{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}]},e2={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:{..._t.spread,turn:2},right:{..._t.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}]},Ce={disco:Kw,hipHop:Xw,breaking:Gw,jazz:Uw,kpop:Vw,bollywood:Jw,bhangra:Zw,bharatanatyam:Qw,charleston:t2,tap:e2,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:xs},{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}]}},Wi=t=>Math.min(1,Math.max(0,t));function n2(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 s2(t){return t-i2*Math.sin(2*Math.PI*t)/(2*Math.PI)}const i2=.5;function o2(t,e){if(!(e<=t.takeoff||e>=t.landing))return(e-t.takeoff)/(t.landing-t.takeoff)}function wu(t,e){const n=typeof t=="string"?Es[t]:t,s=n2(n),i=Wi(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=$n(r.pose,a.pose,Ht(a.easing??"ease-in-out")(Wi(l))),h=o2(n,i);return h===void 0?{...c,spin:0,rise:0}:{...c,spin:n.spin*s2(h),rise:4*n.height*h*(1-h)}}function ku(t,e,n){const s=typeof t=="string"?Es[t]:t,i=Wi(e),o=Wi((i-s.takeoff)/(s.landing-s.takeoff));return s.travel*n*o}function r2(t,e,n={}){const s=typeof e=="string"?Es[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:wu(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*ku(s,u.progress,n.height)}))})}return c}const a2={leftHip:-55,leftKnee:-95,rightHip:55,rightKnee:95,leftShoulder:45,rightShoulder:-45,leftElbow:10,rightElbow:-10,lean:22,stretch:.94,headTilt:6},l2={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},Bi={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},c2={leftHip:-22,leftKnee:-30,rightHip:22,rightKnee:30,leftAnkle:10,rightAnkle:10,leftShoulder:-125,rightShoulder:125,leftElbow:0,rightElbow:0,lean:8,headTilt:0},h2={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 In(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:a2},{at:.27,pose:l2,easing:"ease-out-quad"},...i,{at:.76,pose:c2},{at:.86,pose:h2,easing:"ease-out-quad"},{at:1,reset:!0}]}}const Es={frontFlip:In("Front flip (tuck)",360,.56,.35,[{at:.38,pose:Bi,easing:"ease-out-cubic"},{at:.64,pose:Bi}]),backFlip:In("Back flip (tuck)",-360,.58,-.15,[{at:.36,pose:{...Bi,lean:18},easing:"ease-out-cubic"},{at:.64,pose:{...Bi,lean:18}}]),layout:In("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:In("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:In("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:In("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)},zi={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}},ia=.215,oa=.205,u2=.065,vu=.035,d2=.165,f2=.155,g2=12,p2=.3,m2=.7,y2=.35,b2=t=>t*Math.PI/180,gt={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{...gt,...t}}const w2=new Set(["turn","side","head.turn","head.tilt","roll","lookX","hair.swing"]);function Mu(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]=w2.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 oe={rest:gt,wave:bt({"arm.right.spread":115,"arm.right.bend":55,"arm.right.elbow":0,"head.tilt":-6,smile:.9}),cheer:bt({...Tt("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({...Tt("arm",{spread:50,bend:-105,elbow:0}),...Tt("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({...Tt("arm",{spread:35,bend:75,elbow:0}),"head.tilt":-10,smile:-.2}),sit:bt({...Tt("leg",{swing:90,knee:90,spread:4}),...Tt("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,...Tt("arm",{swing:20,elbow:30})}),crouch:bt({...Tt("leg",{swing:75,knee:140,spread:6}),lean:25,...Tt("arm",{swing:50,elbow:40}),"head.nod":-15}),crawl:bt({lean:82,"head.nod":-35,...Tt("arm",{swing:80,elbow:0,spread:4}),...Tt("leg",{knee:92,ankle:-88})}),lieDown:bt({roll:90,...Tt("arm",{spread:8}),"head.nod":0}),sleep:bt({roll:90,...Tt("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({...Tt("leg",{swing:80,spread:22,rotate:75,knee:145}),...Tt("arm",{swing:25,spread:18,elbow:30}),lean:5,smile:.5}),carry:bt({...Tt("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({...Tt("arm",{swing:28,spread:24,elbow:85,bend:-45}),...Tt("leg",{swing:12,knee:22,spread:6}),lean:-4,smile:.2}),push:bt({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:bt({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: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({...Tt("arm",{swing:32,spread:10,elbow:82,bend:-28}),"head.nod":22,lookY:.8,smile:.2}),type:bt({...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})},Su=["round","flat","pointed","big"],k2={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 Tu(t={}){const e=t.headSize??.3,n=t.shoulderWidth??.06,s=t.hipWidth??.022,i=t.legLength??1,o=t.armLength??1,r=k2[t.feet??"round"],a=Math.max(.12,1-e-vu-(ia+oa)*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:d2*o,width:[1.25,.9]},{length:f2*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:ia*i,width:[1.45,1.05]},{length:oa*i,width:[1.05,.85]},{length:u2*Math.sqrt(i)*r.length,width:r.width}]}),h=(u,d)=>u[d]??gt[d]??0;return{id:"human",hipHeight:(ia+oa)*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:vu,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*p2,spread:k},{swing:v+b*m2,spread:k}]}if(d.id==="neck")return[{swing:-h(u,"bend")*y2,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:(g2+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 v2(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 M2={leftEye:"eye.left",rightEye:"eye.right",leftBrow:"brow.left",rightBrow:"brow.right"},S2={blush:0,tears:0,sweat:0,pupil:1,lid:0,bulge:0},en=Object.fromEntries(Object.entries(kt).map(([t,e])=>[t,{...Object.fromEntries(Object.entries(e).map(([n,s])=>[M2[n]??n,s])),...S2}]));en.crying.tears=1,en.scared.sweat=.8,en.scared.bulge=.4,en.sleepy.lid=.5,en.worried.sweat=.6;const Qt=t=>({...en.neutral,...t}),ra={...en,laughing:Qt({mouth:.75,smile:1,mouthWidth:1.25,"eye.left":0,"eye.right":0,"brow.left":.5,"brow.right":.5}),afraid:Qt({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:Qt({smile:-.05,mouthWidth:.6,"eye.left":.45,"eye.right":.45,"brow.left":-.4,"brow.right":-.4,lookX:.5}),tired:Qt({mouth:.2,smile:-.3,mouthWidth:.7,"eye.left":.3,"eye.right":.3,"brow.left":-.1,"brow.right":-.1,browTilt:.6,lookY:.6}),embarrassed:Qt({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:Qt({smile:.75,mouthWidth:1,"eye.left":.75,"eye.right":.75,"brow.left":.5,"brow.right":.5,lookY:-.2}),determined:Qt({smile:.35,mouthWidth:.8,"eye.left":.85,"eye.right":.85,"brow.left":-.5,"brow.right":-.5,browTilt:-.9}),affectionate:Qt({smile:.85,"eye.left":0,"eye.right":0,"brow.left":.3,"brow.right":.3,blush:.8}),hurt:Qt({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:Qt({smile:-.25,mouthWidth:.7,"eye.left":.5,"eye.right":.85,"brow.left":-.6,"brow.right":.4,browTilt:-.3,lookX:.8,lid:.3}),relieved:Qt({smile:.7,"eye.left":0,"eye.right":0,"brow.left":.4,"brow.right":.4,browTilt:.4}),excited:Qt({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})};function xu(t,e){const n=Math.min(1,Math.max(0,t.turn??0)),s=1-n,i={...gt,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)*T2,i[`eye.${l}`]=t[`${a}Eye`],i[`brow.${l}`]=t[`${a}Brow`],e&&Object.assign(i,x2(l,e[a]??It,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 T2=70;function x2(t,e,n,s){const i=t==="right"?1-s:1+s,o={};for(const r of Object.keys(It))o[`hand.${t}.${r}`]=e[r]??It[r];return o[`hand.${t}.turn`]=(e.turn??0)-i,o[`hand.${t}.roll`]=(e.roll??0)+n,o}const re=t=>t*Math.PI/180;function aa([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t,e*i+n*o,-e*o+n*i]}function la([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i-e*o,t*o+e*i,n]}function He([t,e,n],s){const i=Math.cos(s),o=Math.sin(s);return[t*i+n*o,e,-t*o+n*i]}const Re=(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],Yi=(t,e)=>la(aa(t,e.swing),e.spread);function ca(t,e){const n=He(t,e);return{point:{x:n[0],y:-n[1]},depth:n[2]}}function ji(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?Re(v,Yi(qi(g.offset,s),k)):v,M=g.side??1,E=t.boneScale?.(e,g)??1,A=t.angles(e,g),T=[b],S=[];let x=k.swing,O=k.spread;g.bones.forEach((I,_)=>{const C=A[_]??{swing:0,spread:0};x+=re(C.swing),O+=re(C.spread)*M,S.push({swing:x,spread:O});const F=He(Yi(g.rest,{swing:x,spread:O}),re(C.yaw??0));T.push(Re(T[_],qi(F,I.length*s*E)))}),r[g.id]={joints3:T,frames:S}}const a=r[t.head.on],l=t.headPose?.(e)??{yaw:0,nod:0,tilt:0,sx:1,sy:1},c=a.frames[a.frames.length-1],h=t.head.size/2*s,u=h*l.sx,d=h*l.sy,f=g=>Yi(He(aa(la(g,-re(l.tilt)),-re(l.nod)),re(l.yaw)),c),p=Re(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=re(90*(e.turn??0)),o=ji(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:x,frames:O}=a[S.id],I=x.map(_=>ca(_,i));d[S.id]={id:S.id,joints3:x,frames:O,points:I.map(_=>_.point),depths:I.map(_=>_.depth)}}const f=ca(u,i),p=[[1,0,0],[0,1,0],[0,0,1]].map(S=>He(h(S),i)),g=ca(r,i).point,m=re(e.roll??0),w=S=>{const x=S.x-g.x,O=S.y-g.y;return{x:g.x+x*Math.cos(m)-O*Math.sin(m),y:g.y+x*Math.sin(m)+O*Math.cos(m)}},v=([S,x,O])=>[S*Math.cos(m)+x*Math.sin(m),-S*Math.sin(m)+x*Math.cos(m),O];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)},b=k.axes[1];k.angle=Math.atan2(b[0],b[1]);const M=S=>{if("head"in S)return{x:k.center.x+b[0]*c,y:k.center.y-b[1]*c};const x=d[S.chain];return x.points[Math.min(S.joint,x.points.length-1)]};let E=0;(n.contact??"ground")==="ground"&&(E=-Math.max(...t.contacts.map(S=>M(S).y))),E-=(e.lift??0)*s;const A=S=>({x:S.x,y:S.y+E});for(const S of Object.values(d))S.points=S.points.map(A);k.center=A(k.center);const T=t.contacts.map(S=>({spec:S,point:M(S)}));return{height:s,view:i,chains:d,head:k,hip:A(w(g)),contacts:T,groundY:Math.max(...T.map(S=>S.point.y))}}const ua=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Eu=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]};function Ki(t,e,n){const s=n.height,i=re(90*(e.turn??0)),o=re(e.roll??0),r=ji(t,e,s),a=He(r.root,i),l=m=>Re(la(ua(He(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=>Eu(ua(l(Re(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 Re(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 Xi(t,e,n,s){const i=n.height,o=re(90*(e.turn??0)),r=ji(t,e,i),a=Ki(t,e,n),l=a.hip,c=a.chains,h=a.head.center,u=S=>{if("head"in S)return Re(h,qi(a.head.axes[1],a.head.ry));const x=c[S.chain];return x[Math.min(S.joint,x.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=S=>{const x=s.toView(S);return{point:s.toScreen(x),depth:x[2]*g}},w={};for(const S of t.chains){const x=c[S.id].map(m);w[S.id]={id:S.id,joints3:r.chains[S.id].joints3,frames:r.chains[S.id].frames,points:x.map(O=>O.point),depths:x.map(O=>O.depth)}}const v=s.toView(h),k=s.toScreen(v),b=s.toScreen([v[0]+1,v[1],v[2]]),M=Math.hypot(b.x-k.x,b.y-k.y),E=a.head.axes.map(S=>Eu(ua(s.toView(Re(h,S)),v))),A={center:k,depth:v[2]*g,rx:r.head.rx*M,ry:r.head.ry*M,angle:Math.atan2(E[1][0],E[1][1]),axes:E},T=t.contacts.map(S=>({spec:S,point:m(u(S)).point}));return{height:i*g,view:o,chains:w,head:A,hip:f,contacts:T,groundY:Math.max(...T.map(S=>S.point.y))}}function da(t,[e,n,s]){const[i,o,r]=t.axes,a=[i[0]*e*t.rx+o[0]*n*t.ry+r[0]*s*t.rx,i[1]*e*t.rx+o[1]*n*t.ry+r[1]*s*t.rx,i[2]*e*t.rx+o[2]*n*t.ry+r[2]*s*t.rx],l=Math.hypot(e,n,s)||1,c=(i[2]*e+o[2]*n+r[2]*s)/l;return{point:{x:t.center.x+a[0],y:t.center.y-a[1]},depth:t.depth+a[2],facing:c}}class Au{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 E2(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 fa=Math.PI*2;function A2(t,e=16){const n=new Au,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*fa,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 Pu(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*fa;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 $u(t,e,n=24){const s=new Au,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*fa;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 Pu(s,t,o,1,i),Pu(s,t,r,-1,i),s.build()}function Gi(t){const e=Array.from({length:t.indices.length/3},()=>[]);for(const n of E2(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 Ui=t=>t*180/Math.PI,On=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],ga=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],As=t=>Math.hypot(t[0],t[1],t[2]),pa=t=>{const e=As(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},Vi=t=>Math.atan2(Math.sin(t),Math.cos(t));function Iu(t){const[e,n,s]=pa(t);return{swing:Math.asin(Math.max(-1,Math.min(1,s))),spread:Math.atan2(e,-n)}}function P2(t,e,n,s,i){const o=t.chains.find(x=>x.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],l=a.joints3[0],c=As(On(a.joints3[1],a.joints3[0])),h=As(On(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=On(s,l),f=Math.min(c+h-1e-6,Math.max(Math.abs(c-h)+1e-6,As(d))),p=pa(d),g=o.parent!==null,m=Yi(o.pole??(g?[0,-.35,-1]:[0,0,1]),u);let w=On(m,[p[0]*ga(m,p),p[1]*ga(m,p),p[2]*ga(m,p)]);As(w)<1e-6&&(w=He([1,0,0],0)),w=pa(w);const v=(c*c+f*f-h*h)/(2*c*f),k=Math.sqrt(Math.max(0,1-v*v)),b=[l[0]+c*(v*p[0]+k*w[0]),l[1]+c*(v*p[1]+k*w[1]),l[2]+c*(v*p[2]+k*w[2])],M=[l[0]+p[0]*f,l[1]+p[1]*f,l[2]+p[2]*f],E=o.side??1,A=Iu(On(b,l)),T=Iu(On(M,b)),S=[{swing:Ui(Vi(A.swing-u.swing)),spread:Ui(Vi(A.spread-u.spread))*E},{swing:Ui(Vi(T.swing-A.swing)),spread:Ui(Vi(T.spread-A.spread))*E}];return t.withAngles(e,o,S)}const Ou=.34,zt=.12,Dt=-.4,Wt=(t,e,n)=>t[e]??n,$2=(t,e)=>Math.max(0,t)*(1-Math.min(1,Math.max(0,e))),I2=.45,O2=.35,_2=.7;function $t(t,e,n){const s=f=>Math.sqrt(Math.max(0,1-f.x*f.x-f.y*f.y)),i=da(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(O2,Math.abs(a)),h=l*Math.max(_2,Math.abs(a)),u=Math.cos(t.angle),d=Math.sin(t.angle);return{facing:i,points:e.map(f=>{const p=I2*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 Ps=(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}}),_u=(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},Ji=(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}}),_n=.05,C2=.3,H2="#e06b7d";function R2(t,e,n,s,i={},o){const r=Math.max(1,Math.min(s*.6,.14*e.rx)),a=(I,_)=>$t(e,I,_).points,l=(I,_)=>$t(e,[],{x:I,y:_}).facing,c=Wt(n,"smile",0),h=Wt(n,"blink",0),u=Wt(n,"lookX",0),d=Wt(n,"lookY",0),f=Wt(n,"browTilt",0),p=Math.max(.2,Wt(n,"pupil",1)),g=Math.min(1,Math.max(0,Wt(n,"lid",0))),m=Math.min(1,Math.max(0,Wt(n,"bulge",0)));for(const I of[1,-1]){const _=I===1?"left":"right",C=Ou*I;if(l(C,zt)<_n)continue;const F={x:C,y:zt},z=$2(Wt(n,`eye.${_}`,1),h);if(z<.2){const P=c>.5?.12:-.06;t.line(a(Ps({x:C-.12,y:zt},{x:C,y:zt+P},{x:C+.12,y:zt}),F),r)}else{const P=z>1.2||m>.02,R=.13*Math.max(z,1)*(1+m*.7);P&&t.shape(a(Ji(C,zt,R*.85,R),F),"#ffffff",r);const N=(z>1.2?.075:.1)*p*(1+m*.3),$=C+u*.08,L=zt-d*.07,W=Ji($,L,N,N*1.1*Math.min(z,1));if(t.shape(a(W,F),t.ink,0),i.inPupil&&o){const[q]=a([{x:$,y:L}],F),B=a(W,F),Y=Math.min(...B.map(U=>Math.hypot(U.x-q.x,U.y-q.y)));Y>.5&&(o.save(),o.beginPath(),o.arc(q.x,q.y,Y,0,Math.PI*2),o.clip(),i.inPupil(o,{x:q.x,y:q.y,r:Y,side:_}),o.restore())}if(g>.02){const q=P?R*1.15:N*1.4,B=zt+q,Y=B-q*2*g,U=q*1.1;t.shape(a([{x:C-U,y:B+.02},{x:C+U,y:B+.02},{x:C+U,y:Y},{x:C-U,y:Y}],F),i.skin??"#ffffff",0),t.line(a([{x:C-U,y:Y},{x:C+U,y:Y}],F),r)}}const X=zt+.3+Wt(n,`brow.${_}`,0)*.14+Math.max(0,z-1)*.12,J={x:C+I*.13,y:X},K={x:C-I*.13,y:X+f*.1};t.line(a([J,{x:(J.x+K.x)/2,y:(J.y+K.y)/2},K],{x:C,y:X}),r)}L2(t,e,n,r);const w={x:0,y:Dt};if(l(0,Dt)<-_n)return;i.nose&&l(0,zt-.15)>=_n&&t.line(a([{x:.01,y:zt-.1},{x:.03,y:Dt+.2},{x:-.05,y:Dt+.17}],{x:0,y:Dt+.22}),r);const v=.25*Math.max(.3,Wt(n,"mouthWidth",1)),k=Math.min(1,Math.max(0,Wt(n,"mouth",0)));if(k<=.05){t.line(a(Ps({x:-v,y:Dt},{x:0,y:Dt-c*.25},{x:v,y:Dt}),w),r);return}const b=.3*k;let M,E,A,T;if(c>.3){const I=Dt+.05,_={x:0,y:Dt-b*2};M=[...Ps({x:v,y:I},_,{x:-v,y:I})],E=()=>I,A=C=>_u({x:v,y:I},_,{x:-v,y:I},C),T=.85}else if(c<-.3){const I=Dt-b*.6,_={x:0,y:Dt+b*1.4};M=[...Ps({x:v,y:I},_,{x:-v,y:I})],E=C=>_u({x:v,y:I},_,{x:-v,y:I},C),A=()=>I,T=.5}else{const I=v*.8;M=Ji(0,Dt,I,b);const _=C=>b*Math.sqrt(Math.max(0,1-(C/I)**2));E=C=>Dt+_(C),A=C=>Dt-_(C),T=.5}if(t.shape(a(M,w),t.ink,0),k<C2)return;const S=E(0)-A(0),x=v*T,O=(I,_,C=8)=>Array.from({length:C+1},(F,z)=>I+(_-I)*z/C);if(i.tongue){const I=x*.55,_=O(I,-I).map(F=>({x:F,y:A(F)})),C=Ps({x:-I,y:A(-I)},{x:0,y:A(0)+S*.8},{x:I,y:A(I)},8);t.shape(a([..._,...C.slice(1,-1)],w),H2,0)}if(i.teeth){const I=Math.min(.06,S*.4),_=O(-x,x).map(F=>({x:F,y:E(F)})),C=_.map(({x:F,y:z})=>({x:F*.92,y:z-I})).reverse();t.shape(a([..._,...C],w),"#ffffff",0);for(const F of[-.5,0,.5]){const z=x*F;t.line(a([{x:z,y:E(z)},{x:z*.92,y:E(z)-I}],w),r*.6)}}}const Cu="#8fd0f5",Hu=(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 L2(t,e,n,s){const i=Math.min(1,Math.max(0,Wt(n,"blush",0))),o=Math.min(1,Math.max(0,Wt(n,"tears",0))),r=Math.min(1,Math.max(0,Wt(n,"sweat",0)));if(!(i+o+r<=.01)){for(const a of[1,-1]){const l={x:.5*a,y:-.16},c=$t(e,[],l).facing>=_n;if(i>.01&&c){const{points:u}=$t(e,Ji(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($t(e,f,l).points,s*.3)}}const h={x:Ou*a,y:zt};if(o>.01&&$t(e,[],h).facing>=_n){const u=.05+.04*o,d={x:h.x+.06*a,y:zt-.2-.12*o};if(t.shape($t(e,Hu(d.x,d.y,u),d).points,Cu,s*.35),o>.6){const f=[{x:h.x+.05*a,y:zt-.1},{x:d.x,y:d.y+u*.8}];t.line($t(e,f,d).points,s*.3)}}}if(r>.01){const a={x:.64,y:.42};$t(e,[],a).facing>=_n&&t.shape($t(e,Hu(a.x,a.y,.05+.05*r),a).points,Cu,s*.35)}}}const N2=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 F2=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function me(t,[e,n,s]){const[i,o,r]=t.axes;return i[2]*e+o[2]*n+r[2]*s}function qt(t,e){return da(t,e).point}function Zi(t,e){const n=Math.abs(t-e)%(Math.PI*2);return n>Math.PI?Math.PI*2-n:n}function Qi(t,e,n=64){const s=e.top??1,i=e.bottom??-1,o=Math.max(8,Math.ceil((s-i)*N2)),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):F2(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?me(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 I=0;I<c;I++)for(let _=0;_<=n;_++){const C=I*n+(_===n?0:_);m[I*g+_]=Math.min(h[C],p*u[C])}const w=(I,_)=>m[_*g+I],v=(I,_,C,F)=>{const z=w(I,_),X=w(C,F),J=z===X?.5:Math.min(1,Math.max(0,z/(z-X)));return qt(t,e.position(a(I+(C-I)*J),r(_+(F-_)*J)))},k=n*c*2,b=new Int32Array(k).fill(-1),M=new Int32Array(k).fill(-1),E=new Map,A=(I,_,C)=>{const F=(C*n+d(_))*2+(I?1:0);return E.has(F)||E.set(F,I?v(d(_),C,d(_),C+1):v(_,C,_+1,C)),F},T=(I,_)=>{b[I]===-1?b[I]=_:M[I]=_},S=(I,_)=>{T(I,_),T(_,I)};for(let I=0;I<c-1;I++)for(let _=0;_<n;_++){const C=I*g+_,F=(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(F===0||F===15)continue;const z=()=>A(!1,_,I),X=()=>A(!1,_,I+1),J=()=>A(!0,_,I),K=()=>A(!0,_+1,I);switch(F){case 1:case 14:S(J(),X());break;case 2:case 13:S(X(),K());break;case 3:case 12:S(J(),K());break;case 4:case 11:S(z(),K());break;case 6:case 9:S(z(),X());break;case 7:case 8:S(J(),z());break;case 5:case 10:{const P=(w(_,I)+w(_+1,I)+w(_+1,I+1)+w(_,I+1))/4>0;F===5===P?(S(J(),z()),S(X(),K())):(S(J(),X()),S(z(),K()));break}}}const x=[],O=new Uint8Array(k);for(const I of E.keys()){if(O[I])continue;const _=[];let C=-1,F=I;for(;F!==-1&&!O[F];){O[F]=1,_.push(E.get(F));const z=b[F],X=M[F],J=z!==-1&&z!==C&&!O[z]?z:X!==-1&&X!==C&&!O[X]?X:-1;C=F,F=J}_.length>=3&&x.push(_)}return x};return{near:f(1),far:f(-1)}}const Ru=new WeakMap;function ma(t,e,n){let s=Ru.get(t);s||Ru.set(t,s=new Map);let i=s.get(e);return i||s.set(e,i=n()),i}function ya(t,e,n){t.save(),t.beginPath(),t.rect(-1e5,-1e5,2e5,2e5),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 Lu(t,e,n,s=.04){const i=[];let o=[];return e.forEach((r,a)=>{me(t,n[a])>s?o.push(qt(t,r)):(o.length>=2&&i.push(o),o=[])}),o.length>=2&&i.push(o),i}const Cn={swing:0,trail:0,lift:0};function to(t){if(!t)return Cn;const e=t["hair.swing"]??0,n=t["hair.trail"]??0,s=t["hair.lift"]??0;return e===0&&n===0&&s===0?Cn:{swing:e,trail:n,lift:s}}const Nu=t=>t.swing===0&&t.trail===0&&t.lift===0;function Fu(t){return t.length>0||t.ties.some(e=>e.kind!=="bun")}function ba([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 Du={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},Wu=1.75,wa={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}},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:Wu,opening:84,part:0,strands:"part",hairline:{front:.5,side:.05,back:-.85},coversEars:!0},shoulderWaves:{volume:.22,length:Wu,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}},de={black:"#22201f",brown:"#6b4630",chestnut:"#7b4a2b",auburn:"#9a4426",blond:"#d9b55a",ginger:"#c8662f",gray:"#a7a29c",white:"#ecebe7"};function Bu(t){const e=typeof t=="string"?{style:t}:t,n=e.style?wa[e.style]:{};if(e.style&&!n)throw new Error(`hair: unknown style '${e.style}'`);const{style:s,hairline:i,...o}=e;return{...Du,...n,...o,hairline:{...Du.hairline,...n.hairline,...i},ties:(o.ties??n.ties??[]).map(r=>({...r}))}}const eo=t=>t*Math.PI/180,$s=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},ka=t=>1-Math.abs(2*(t-Math.floor(t))-1);function Is(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*ka(e*11/(Math.PI*2))*c),h}function zu(t,e,n){const s=t.textureAmount;switch(t.texture){case"spiky":return s*(ka(e*11/(Math.PI*2))*ka(n*2.6+.5))**1.2*$s(-.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 qu(t,e,n=Cn){const s=t.length>0,i=new Map,o=h=>{let u=i.get(h);return u===void 0&&i.set(h,u=Is(t,h)),u},r=eo(t.opening),a=h=>t.length+(t.texture==="wavy"||t.texture==="curly"||t.texture==="locs"?.12*Math.sin(h*9):0),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):-1,inside(h,u){const d=u-o(h);if(!s)return d;const f=Math.min(u+a(h),Zi(h,0)-r);return Math.max(d,f)},position(h,u){if(s&&u<0){const k=t.length<1.5?.14*$s(-t.length+.45,-t.length-.1,u):0,b=1+e+t.volume*(1-k*2.5)+zu(t,h,u)-k;return[b*Math.sin(h),u,b*Math.cos(h)]}const d=.4+.6*$s(0,.3,u-Is(t,h)),f=1+e+(t.volume+zu(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))*$s(.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&&!Nu(n)?D2(c,t,n):c}function D2(t,e,n){const s=o=>o<0?$s(-.15,-Math.max(.7,e.length),o):0,i=o=>eo(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]=ba(t.position(o+l,r),l);return[c,h+n.lift*a,u-n.trail*a]},normal:(o,r)=>ba(t.normal(o+i(r),r),i(r))}}const W2=t=>t.texture==="spiky"||t.texture==="curly"||t.texture==="locs"?104:t.texture==="wavy"?80:64;function Yu(t,e,n,s){return ma(t,z2(e,s),()=>Qi(t,n,W2(e)))}const ju=new WeakMap;let B2=1;function z2(t,e){if(Nu(e))return t;let n=ju.get(t);return n||ju.set(t,n=B2++),`${n}:${e.swing}:${e.trail}:${e.lift}`}function Ku(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 va(t,[e,n,s]){const i=qt(t,[e,n,s]);return{x:i.x-t.center.x,y:i.y-t.center.y}}function q2(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 Y2(t,e,n,s,i){const o=t.ry,r=(e.length??1.8)*o,a=va(t,ba(s,eo(i.swing))),l=va(t,[0,i.lift,-i.trail]),c=Math.hypot(a.x,a.y)||1,h=e.at==="high"||e.at==="low"||e.at==="top"?va(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 q2(n,d,f)}const Ma=t=>Math.max(1,t*.5),Xu=(t,e)=>Math.max(.8,Math.min(t*.4,.1*e.rx));function Gu(t,e,n,s,i,o){const{point:r,out:a}=Ku(s.at),l=1+n.volume,c=qt(e,[r[0]*l,r[1]*l,r[2]*l]),h=Ma(i),u=Xu(i,e);if(s.kind==="bun"){const g=s.size??.32,m=qt(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=Y2(e,s,c,a,o),f=(s.size??(s.kind==="braid"?.2:.34))*e.rx*2;if(s.kind==="ponytail")t.shape(Nt(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))],M=m[Math.floor((k+1)/7*(m.length-1))],E=Math.atan2(M.y-b.y,M.x-b.x),A=Math.hypot(M.x-b.x,M.y-b.y),T=f*(1-k/(7*2.2)),S=(k%2===0?1:-1)*.35,x={x:(b.x+M.x)/2,y:(b.y+M.y)/2};t.ellipse(x.x,x.y,A*.62,T*.5,E+S,n.color,h*.8)}const w=m[m.length-1],v=d[d.length-1];t.shape(Nt([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 Uu(t,e){return me(t,Ku(e.at).out)<-.2}function j2(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=eo(t.part??0),s=i=>Is(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,Is(t,r)<.9?.6:.9],[r,i],0));return t.part!==null&&o.push(e([n,s(n)],[n,.97])),o}default:return[]}}function K2(t,e,n,s,i){if(s.fill==="stipple"||s.hairline.front>1.5)return;const o=i.motion??Cn,r=i.lineWidth*.45/n.rx,{far:a}=Yu(n,s,qu(s,r,o),o);ya(e,n,()=>{for(const l of s.ties)Uu(n,l)&&Gu(t,n,s,l,i.lineWidth,o);for(const l of a)t.shape(l,s.color,Ma(i.lineWidth))})}function Vu(t,e,n,s){if(n.hairline.front>1.5)return;const i=s.motion??Cn,o=s.lineWidth*.45/e.rx,r=qu(n,o,i),a=Xu(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(me(e,f)<.12)continue;const p=qt(e,f);t.dot(p.x,p.y,a*.4)}return}const{near:l}=Yu(e,n,r,i),c=Ma(s.lineWidth);for(const h of l)t.shape(h,n.color,c);for(const h of j2(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 Lu(e,u,d,.12))t.line(f,a)}for(const h of n.ties)Uu(e,h)||Gu(t,e,n,h,s.lineWidth,i)}const Ju=.35,Sa=t=>({centre:[t*.98,-.02,-.08],out:[t,0,-.12]});function Zu(t,e,n,s,i){const{centre:o,out:r}=Sa(n),a=me(e,r),l=Math.max(1,s.lineWidth*.55),c=s.skin==="none"?null:s.skin,h=e.ry*.27;if(!i){const m=qt(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=qt(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 X2(t,e,n,s){ya(e,n,()=>{for(const i of[1,-1])me(n,Sa(i).out)<Ju&&Zu(t,n,i,s,!1)})}function G2(t,e,n){for(const s of[1,-1])me(e,Sa(s).out)>=Ju&&Zu(t,e,s,n,!0)}const Ta={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 Qu(t,e){const n=typeof t=="string"?{style:t}:t,s=n.style?Ta[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 Le=t=>t*Math.PI/180,no=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)},td={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}},U2=(t,e)=>{const n=no(Le(48),Le(100),Zi(e,0));return t.top[0]+(t.top[1]-t.top[0])*n},V2=t=>t==="sideburns"||t==="muttonChops";function xa(t,e){const n=td[t];if(!n)return null;const s=Le(n.reach),i=o=>{const r=Zi(o,0);return n.shape==="point"?Math.exp(-((r/.42)**2)):n.shape==="square"?1-no(Le(45),Le(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=Zi(o,0),l=U2(n,o);let c=Math.min(l-r,s-a);if(n.band>0&&(c=Math.min(c,r-(l-n.band))),V2(t)){const h=t==="muttonChops"?Le(70)-Le(22)*no(.08,-.6,r):Le(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)*no(-.45,-1,r);return[a*h,l*h-u,c*h+u*.25]},normal:(o,r)=>pe(o,r)}}function J2(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 Os=t=>Math.max(1,t*.45);function Z2(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(me(e,a)<.15)continue;const l=qt(e,a);t.dot(l.x,l.y,s)}}function Q2(t,e,n,s,i){const o=s.beard==="stubble"?null:xa(s.beard,i.lineWidth*.45/n.rx);if(!o)return;const{far:r}=ma(n,s,()=>Qi(n,o));ya(e,n,()=>{for(const a of r)t.shape(a,s.color,Os(i.lineWidth))})}function tk(t,e,n,s,i){if(n.beard==="none")return;const o=s.lineWidth*.45/e.rx;if(n.beard==="stubble"){Z2(t,e,xa("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}=$t(e,l,{x:0,y:-.6});h>-.05&&t.shape(c,n.color,Os(s.lineWidth)*.7);return}const r=xa(n.beard,o);if(!r)return;const{near:a}=ma(e,n,()=>Qi(e,r));for(const l of a)t.shape(l,n.color,Os(s.lineWidth));if(td[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}=$t(e,c,{x:0,y:-.42});u>-.05&&t.shape(h,s.skin==="none"?"#ffffff":s.skin,0)}}function ek(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}=$t(e,l,i);h>-.05&&t.line(c,Math.max(1,s.lineWidth*.32));return}const o=J2(n.moustache);if(!o)return;const{points:r,facing:a}=$t(e,o,i);if(!(a<=-.05)&&(t.shape(r,n.color,Os(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($t(e,c,i).points,Os(s.lineWidth)*.8)}}const Ea={round:!0,square:!0,sunglasses:!0};function ed(t){const n=(typeof t=="string"?{style:t}:t).style??"round";if(!(n in Ea))throw new Error(`glasses: unknown style '${n}'`);return{style:n}}const nd=.34,fe=.12,nk=.05;function sk(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:fe+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:fe-.01+Math.sign(a)*Math.abs(a)**.45*c}})}function ik(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=nd*r,{points:l,facing:c}=$t(e,sk(n.style,a),{x:a,y:fe});if(c<nk)continue;o.push(r),t.shape(l,n.style==="sunglasses"?"#1f2328":null,i);const h=[r*.97,fe+.02,-.1];if(me(e,[r,0,0])>.15){const u=$t(e,[{x:a+r*.21,y:fe+.02}],{x:a,y:fe}).points[0];t.line([u,qt(e,h)],i*.9)}}if(o.length===2){const r=[{x:nd-.2,y:fe+.02},{x:0,y:fe+.07},{x:-.14,y:fe+.02}];t.line($t(e,r,{x:0,y:fe}).points,i)}}const so={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=so[n];if(!s)throw new Error(`hat: unknown style '${n}'`);return{style:n,color:e.color??s.color}}const nn=(t,e)=>t.brim[1]+(t.brim[0]-t.brim[1])*(1+Math.cos(e))/2;function ok(t,e){return{top:1,bottom:Math.min(...t.brim)-.05,inside:(n,s)=>s-nn(t,n),position(n,s){const[i,o,r]=pe(n,s),a=nn(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 rk(t,e,n){const i=(o,r,a)=>{const l=nn(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(qt(t,[Math.sin(l)*(n+c*.25),nn(e,l)*n-.07*Math.cos(l),Math.cos(l)*(n+c)])),r.push(qt(t,i(l,n,0)))}return[...o,...r.reverse()]}return e.ring?Array.from({length:48},(o,r)=>qt(t,i(Math.PI*2*r/48,n+e.ring,.07))):null}function ak(t){const e=s=>Array.from({length:13},(i,o)=>[s,nn(t,s)+(.97-nn(t,s))*o/12]),n=s=>Array.from({length:49},(i,o)=>{const r=-Math.PI+Math.PI*2*o/48;return[r,nn(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 id(t,e,n,s){const i=so[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=rk(e,i,r);l&&t.shape(l,n.color,a);const c=ok(i,r),{near:h,far:u}=Qi(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 ak(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 Lu(e,p,g,.1))t.line(m,d)}if(i.detail==="seams"){const f=qt(e,[0,r*1.01,0]);t.dot(f.x,f.y,a*.9)}}function od(t){const e=t.hair?Bu(t.hair):null;return{hair:e,facialHair:t.facialHair?Qu(t.facialHair,e?.color):null,glasses:t.glasses?ed(t.glasses):null,hat:t.hat?sd(t.hat):null,ears:t.ears??!1}}const rd=t=>!t.hair&&!t.facialHair&&!t.glasses&&!t.hat&&!t.ears,ad=t=>t.axes[2][2]<-.3,ld=t=>t.ears&&!t.hair?.coversEars;function cd(t,e,n,s,i,o){rd(n)||(n.hair&&K2(e,t,s,n.hair,{...o,motion:to(i)}),n.facialHair&&Q2(e,t,s,n.facialHair,o),ld(n)&&X2(e,t,s,o))}function lk(t,e,n,s,i,o,r){if(rd(n)){r();return}const a=ad(s);ld(n)&&G2(e,s,o),n.hair&&!a&&Vu(e,s,n.hair,{...o,motion:to(i)}),n.facialHair&&tk(e,s,n.facialHair,o,i.mouthWidth??1),r(),n.facialHair&&ek(e,s,n.facialHair,o),n.glasses&&ik(e,s,n.glasses,o),n.hat&&!a&&id(e,s,n.hat,{lineWidth:o.lineWidth,hairVolume:n.hair?.volume??0})}function hd(t,e,n,s,i,o){ad(s)&&(n.hair&&Vu(e,s,n.hair,{...o,motion:to(i)}),n.hat&&id(e,s,n.hat,{lineWidth:o.lineWidth,hairVolume:n.hair?.volume??0}))}const ud=40,ck=.215+.205,Ut=(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},dt=(t,e)=>t[e]??gt[e]??0;function Aa(t,e,n=gt,s=1){const i=vs(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={...gt,...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"]=dt(n,"leg.left.ankle")-(i.tiptoe??0),d["leg.right.ankle"]=dt(n,"leg.right.ankle")-(i.tiptoe??0);for(const[f,p]of[["left",-1],["right",1]])dt(n,`arm.${f}.spread`)>ud||dt(n,`arm.${f}.swing`)>ud||(d[`arm.${f}.swing`]=h+p*i.arm*r,d[`arm.${f}.elbow`]=dt(n,`arm.${f}.elbow`)+u+i.elbow*Math.max(0,p*r));return d.lean=dt(n,"lean")+i.lean*s,d.bend=dt(n,"bend")+(i.bend??0),d["head.nod"]=dt(n,"head.nod")-i.lean*.5*s+(i.headTilt??0),d.side=dt(n,"side")+(i.sway??0)*Math.sin(o),d.lift=dt(n,"lift")+(i.bounce??0)*s*l,d.stretch=dt(n,"stretch")*(1+(i.squash??0)*(l-.5)),d}function Pa(t,e,n=1,s=1){const i=vs(t);return 4*ck*s*e*Math.sin(i.swing*n*Math.PI/180)}const Hn=t=>ra[t],io={take:t=>[{after:140,pose:{stretch:.8,bend:10,lean:dt(t,"lean")-4,...Ut("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,...Ut("arm",{spread:150,bend:35,swing:0,elbow:0}),...Ut("leg",{swing:25,knee:60}),...Hn("shocked")},easing:"ease-out-cubic"},{after:720,pose:{lift:.25,stretch:1.25,bend:-10,...Ut("arm",{spread:140})},easing:"ease-in-out"},{after:900,pose:{lift:0,stretch:.74,bend:12,...Ut("arm",{spread:70,bend:0}),...Ut("leg",{swing:30,knee:60})},easing:"ease-in-quad"},{after:1060,pose:{stretch:1.06,bend:-3,...Ut("arm",{spread:60}),"leg.left.swing":dt(t,"leg.left.swing"),"leg.right.swing":dt(t,"leg.right.swing"),"leg.left.knee":dt(t,"leg.left.knee"),"leg.right.knee":dt(t,"leg.right.knee")},easing:"ease-out"},{after:1260,pose:{stretch:dt(t,"stretch"),bend:dt(t,"bend"),...Hn("surprised"),...Ut("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":dt(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":dt(t,"head.nod")-10,bend:dt(t,"bend")-10,lift:.05,stretch:1.18,...Hn("shocked"),lookX:1,lookY:0},easing:"ease-out-cubic"},{after:1360,pose:{lift:0,stretch:.88,"head.nod":dt(t,"head.nod")-4,bend:dt(t,"bend")+4},easing:"ease-in-quad"},{after:1560,pose:{stretch:dt(t,"stretch"),"head.nod":dt(t,"head.nod"),bend:dt(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,...Hn("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,...Ut("arm",{spread:75}),...Ut("leg",{swing:25,knee:50})},easing:"ease-in-quad"},{after:300,pose:{stretch:1.05,bend:-4,"arm.left.spread":dt(t,"arm.left.spread"),"arm.right.spread":dt(t,"arm.right.spread")},easing:"ease-out"},{after:460,pose:{lift:0,stretch:dt(t,"stretch"),bend:dt(t,"bend"),...Ut("leg",{swing:0,knee:0})},easing:"ease-in-out"}],tremble:t=>{const e=[{after:80,pose:{...Hn("scared"),...Ut("arm",{swing:40,elbow:110,spread:14}),stretch:.94,bend:dt(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:dt(t,"side")+2.5*s,"head.tilt":dt(t,"head.tilt")-2*s}})}return e.push({after:755,pose:{side:dt(t,"side"),"head.tilt":dt(t,"head.tilt"),bend:dt(t,"bend")}}),e},deflate:t=>[{after:260,pose:{stretch:1.04,"head.nod":dt(t,"head.nod")-4,"brow.left":.3,"brow.right":.3},easing:"ease-in-out"},{after:900,pose:{...Hn("sad"),bend:18,stretch:.92,lean:dt(t,"lean")+5,"head.nod":14,...Ut("arm",{spread:6,swing:0,elbow:4,bend:0})},easing:"ease-in-out"}]};function dd(t,e){const n=bt(e.from??{}),s=e.speed??1;let i=n;return[{time:e.at,pose:n},...io[t](n).map(o=>(i={...i,...o.pose},{time:e.at+o.after*s,pose:i,act:!1,...o.easing?{easing:o.easing}:{}}))]}function fd(t,e=gt){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 gd(t,e=gt){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 $a={sweeping:fd,brushing:gd};function hk(t,e,n=gt){const s=$a[t];if(!s)throw new Error(`humanCyclePose: ${ut("cycle",t,Object.keys($a))}`);return s(e,n)}const uk={apron:"#d8b48a",labCoat:"#f4f6f8",hoodie:"#6b7280",cardigan:"#6b8e4e",overalls:"",sari:"#16a34a"},Ia=(t,e,n)=>t.slice(Math.floor((t.length-1)*e),Math.ceil((t.length-1)*n)+1),yt=(t,e,n)=>({x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n});function dk(t){return Oa(t,t.parts["leg.left"].depth)>Oa(t,t.parts["leg.right"].depth)?"left":"right"}const Oa=(t,e)=>Math.abs(e)<.01*t.height?0:e,pd=t=>Oa(t,Math.max(t.parts["leg.left"].depth,t.parts["leg.right"].depth))>0,te=t=>Math.cos(t.turn*Math.PI/2);function md(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"?uk[t.over]:n),u=t.shoes==="boots",d=t.shoeColor??"#3b2a1e",f=P=>P.lineWidth*.45,p=(P,R,N)=>{const $=P.parts[`leg.${N}`].points;if(!(i==="skirt"&&!l)){if(i==="shorts"&&!l){const L=Ia($,0,.5);R.shape(Nt(L,P.height*.085,P.height*.07),n,f(P));return}R.shape(Nt($,P.height*.08,P.height*.05),n,f(P))}},g=(P,R,N)=>{const $=P.parts[`leg.${N}`].points,L=Ia($,.7,1);if(L.length<2)return;R.shape(Nt(L,P.height*.075,P.height*.07),d,f(P));const W=L[0],q=L[1],B=q.x-W.x,Y=q.y-W.y,U=Math.hypot(B,Y)||1,D=P.height*.04;R.line([{x:W.x-Y/U*D,y:W.y+B/U*D},{x:W.x+Y/U*D,y:W.y-B/U*D}],f(P)*.9)},m=P=>{const R=P.chains.spine,N=R[0],$=R[R.length-1],L={x:N.x-($.x-N.x)*.25,y:N.y-($.y-N.y)*.25};return{hip:N,top:$,below:L,line:[L,...P.parts.spine.points]}},w=(P,R)=>{const N=r?h:e,$=r?1.14:1;R.shape(Nt(m(P).line,P.height*.15*$,P.height*.14*$),N,f(P))},v=(P,R)=>{const N=te(P),{top:$,hip:L}=m(P),W=P.height*.07,q={x:($.x-L.x)*.16,y:($.y-L.y)*.16};if(N>=0){R.shape([{x:$.x-W,y:$.y+q.y*.25},{x:$.x-W*.8+q.x,y:$.y+q.y},{x:$.x+q.x*1.2,y:$.y+q.y*1.35},{x:$.x+W*.8+q.x,y:$.y+q.y},{x:$.x+W,y:$.y+q.y*.25}],h,f(P));return}const B=yt($,L,.42);R.shape([{x:$.x-W*.9,y:$.y},{x:$.x+W*.9,y:$.y},{x:B.x+W*.7,y:B.y},{x:B.x,y:B.y+P.height*.02},{x:B.x-W*.7,y:B.y}],h,f(P))},k=(P,R)=>{const N=te(P);if(N<.2)return;const{top:$,hip:L}=m(P),W=Math.sin(P.turn*Math.PI/2)*P.height*.03,q=P.height*.06*N,B=yt($,L,.62),Y=yt($,L,.9);R.line([{x:B.x+W-q,y:B.y},{x:Y.x+W-q*1.1,y:Y.y}],f(P)*.7),R.line([{x:B.x+W+q,y:B.y},{x:Y.x+W+q*1.1,y:Y.y}],f(P)*.7);const U=yt($,L,.1);for(const D of[-1,1])R.line([{x:U.x+W+D*q*.2,y:U.y},{x:U.x+W+D*q*.35,y:U.y+P.height*.07}],f(P)*.6)},b=(P,R)=>{const{top:N,hip:$}=m(P),L=te(P);if(R.shape(Nt([N,yt(N,$,.5),yt(N,$,1.08)],P.height*.155,P.height*.15),h,f(P)),L<.2)return;const W=Math.sin(P.turn*Math.PI/2)*P.height*.03,q=P.height*.02*L,B=yt(N,$,.12),Y=yt(N,$,1.05);R.shape([{x:B.x+W-q,y:B.y},{x:B.x+W+q,y:B.y},{x:Y.x+W+q*1.3,y:Y.y},{x:Y.x+W-q*1.3,y:Y.y}],e,f(P)*.7);for(const U of[.35,.55,.75]){const D=yt(N,$,U);R.dot(D.x+W+q*1.6,D.y,f(P)*1.2)}},M=(P,R)=>{const N=te(P),{top:$,hip:L}=m(P),W=Math.sin(P.turn*Math.PI/2)*P.height*.04,q=yt(L,$,.12),B=yt(L,$,.74);if(N<.15){if(N<-.3){const V=P.points["shoulder.left"],j=P.points["shoulder.right"];R.line([V,{x:q.x+P.height*.03,y:q.y}],f(P)*.8),R.line([j,{x:q.x-P.height*.03,y:q.y}],f(P)*.8)}return}const Y=P.height*.07*N;R.shape([{x:B.x+W-Y*.75,y:B.y},{x:B.x+W+Y*.75,y:B.y},{x:q.x+W+Y*1.1,y:q.y},{x:q.x+W-Y*1.1,y:q.y}],n,f(P));for(const V of["left","right"]){const j=P.points[`shoulder.${V}`],st={x:B.x+W+(j.x>B.x+W?1:-1)*Y*.55,y:B.y};R.line([st,{x:j.x+(st.x-j.x)*.15,y:j.y+(st.y-j.y)*.15}],f(P)*1.6)}const U=yt(B,q,.3),D=Y*.4;R.line([{x:U.x+W-D,y:U.y},{x:U.x+W-D,y:U.y+D*1.4},{x:U.x+W+D,y:U.y+D*1.4},{x:U.x+W+D,y:U.y}],f(P)*.6)},E=(P,R)=>{const{hip:N,top:$}=m(P),L=yt(N,$,.2),W=[P.points["ankle.left"],P.points["ankle.right"]],q=yt(N,{x:(W[0].x+W[1].x)/2,y:(W[0].y+W[1].y)/2},.98),B=P.height*.075,Y=Math.max(P.height*.12,Math.abs(W[0].x-W[1].x)/2+P.height*.07),U=q.x-L.x,D=q.y-L.y,V=Math.hypot(U,D)||1,j={x:-D/V,y:U/V};if(R.shape([{x:L.x+j.x*B,y:L.y+j.y*B},{x:q.x+j.x*Y,y:q.y+j.y*Y},{x:q.x-j.x*Y,y:q.y-j.y*Y},{x:L.x-j.x*B,y:L.y-j.y*B}],h,f(P)),te(P)>.2){const ot=Math.sin(P.turn*Math.PI/2)*P.height*.03;for(const rt of[-.35,0,.35]){const at=B*.5*rt,H=Y*.45*rt;R.line([{x:L.x+ot+j.x*at,y:L.y+j.y*at+P.height*.02},{x:q.x+ot+j.x*H,y:q.y+j.y*H}],f(P)*.5)}}},A=(P,R)=>{const N=te(P),{top:$,hip:L}=m(P),W=Math.sin(P.turn*Math.PI/2),q=W>=0?"left":"right",B=q==="left"?"right":"left",Y=P.points[`shoulder.${q}`],U=P.height*.035;if(N<.15){const j=yt($,L,.9);R.shape(Nt([Y,{x:j.x+(Y.x-$.x)*.5,y:j.y}],U*2.2,U*2.6),h,f(P));return}const D={x:L.x+(P.points[`hip.${B}`].x-L.x)*1.2,y:yt(L,$,.08).y};R.shape(Nt([D,yt(D,Y,.5),Y],U*2.4,U*2),h,f(P));const V={x:Y.x-(L.x-Y.x)*.05-W*P.height*.03,y:Y.y+P.height*.16};R.shape(Nt([Y,V],U*2,U*1.6),h,f(P))},T=(P,R)=>{const{hip:N,top:$}=m(P),L=yt(N,$,.18),W=[P.points["knee.left"],P.points["knee.right"]],q=yt(N,{x:(W[0].x+W[1].x)/2,y:(W[0].y+W[1].y)/2},1.05),B=P.height*.075,Y=Math.max(P.height*.13,Math.abs(W[0].x-W[1].x)/2+P.height*.08),U=q.x-L.x,D=q.y-L.y,V=Math.hypot(U,D)||1,j={x:-D/V,y:U/V};R.shape([{x:L.x+j.x*B,y:L.y+j.y*B},{x:q.x+j.x*Y,y:q.y+j.y*Y},{x:q.x-j.x*Y,y:q.y-j.y*Y},{x:L.x-j.x*B,y:L.y-j.y*B}],n,f(P))},S=(P,R)=>{const N=te(P);if(N<.2)return;const{top:$,hip:L}=m(P),W={x:(L.x-$.x)*.12,y:(L.y-$.y)*.12},q=P.height*.045*N;for(const B of[-1,1])R.shape([{x:$.x+B*q*.2,y:$.y+W.y*.1},{x:$.x+B*q*1.3,y:$.y-W.y*.1},{x:$.x+B*q*.6+W.x,y:$.y+W.y}],e,f(P)*.8)},x=(P,R,N)=>{const $=te(P);if($<.25)return;const{top:L,hip:W}=m(P),q=Math.sin(P.turn*Math.PI/2)*P.height*.03,B=V=>({x:yt(L,W,V).x+q,y:yt(L,W,V).y}),Y=P.height*.022*$,U=B(.08),D=B(.62);R.shape([{x:U.x-Y,y:U.y-Y},{x:U.x+Y,y:U.y-Y},{x:U.x+Y*.6,y:U.y+Y},{x:U.x-Y*.6,y:U.y+Y}],N,f(P)*.7),R.shape([{x:U.x-Y*.6,y:U.y+Y},{x:U.x+Y*.6,y:U.y+Y},{x:D.x+Y*1.4,y:D.y-Y*2},D,{x:D.x-Y*1.4,y:D.y-Y*2}],N,f(P)*.7)},O=(P,R)=>{const N=te(P),{top:$,hip:L}=m(P),W=yt(L,$,.72),q=[P.points["knee.left"],P.points["knee.right"]],B=yt(L,{x:(q[0].x+q[1].x)/2,y:(q[0].y+q[1].y)/2},.9),Y=Math.sin(P.turn*Math.PI/2)*P.height*.04;if(N<.15){const V=yt(L,$,.2);N<-.3&&R.line([{x:V.x-P.height*.05,y:V.y},{x:V.x+P.height*.05,y:V.y}],f(P));return}const U=P.height*.075*N,D=yt(L,$,.2);R.shape([{x:W.x+Y-U*.7,y:W.y},{x:W.x+Y+U*.7,y:W.y},{x:D.x+Y+U,y:D.y},{x:B.x+Y+U*1.15,y:B.y},{x:B.x+Y-U*1.15,y:B.y},{x:D.x+Y-U,y:D.y}],h,f(P)),R.line([{x:W.x+Y-U*.6,y:W.y},{x:$.x-U*.2,y:$.y},{x:W.x+Y+U*.6,y:W.y}],f(P)*.8)},I=(P,R,N)=>{const{top:$,hip:L}=m(P),W=[P.points["knee.left"],P.points["knee.right"]],q=yt(L,{x:(W[0].x+W[1].x)/2,y:(W[0].y+W[1].y)/2},.95);N?R.shape(Nt([yt($,L,.8),L,q],P.height*.145,P.height*.17),h,f(P)):R.shape(Nt([$,yt($,L,.5),L],P.height*.14,P.height*.15),h,f(P));const B=te(P);if(B>.2){const Y=Math.sin(P.turn*Math.PI/2)*P.height*.03,[U,D]=N?[L,q]:[$,L];if(R.line([{x:U.x+Y,y:U.y},{x:D.x+Y,y:D.y}],f(P)*.8),!N){const V=yt($,L,.35),j=P.height*.025*B;R.shape([{x:V.x+Y-j*2.4,y:V.y},{x:V.x+Y-j*.6,y:V.y},{x:V.x+Y-j*.6,y:V.y+j*1.6},{x:V.x+Y-j*2.4,y:V.y+j*1.6}],h,f(P)*.6)}}},_=(P,R,N,$,L)=>{const W=P.parts[`arm.${N}`].points,q=W[0],B=P.chains.spine[P.chains.spine.length-1],U=[{x:q.x+(B.x-q.x)*.45,y:q.y+(B.y-q.y)*.45},...Ia(W,0,L)],D=Nt(U,P.height*.085,P.height*(L>.6?.045:.06)),V=U.length,j=D.slice(0,V),st=D.slice(V).reverse();R.shape(D,$,0);const ot=H=>Math.hypot(H[1].x-B.x,H[1].y-B.y),[rt,at]=ot(j)>ot(st)?[j,st]:[st,j];R.line(rt.slice(1),f(P)),R.line(at.slice(Math.ceil(V*.45)),f(P)),R.line([j[V-1],st[V-1]],f(P))},C=o||r||a,F=C?h:e,z=C||s==="long"?.95:.45,X=C||s!=="none",J=(P,R)=>{i==="skirt"&&!l&&!c&&T(P,R),c&&E(P,R),o&&I(P,R,!0),t.over==="apron"&&O(P,R)},K=P=>(R,N,$)=>{p(N,$,P),u&&g(N,$,P),dk(N)===P&&pd(N)&&J(N,$)};return{parts:{"leg.left":{over:K("left")},"leg.right":{over:K("right")},spine:{over:(P,R,N)=>{r&&te(R)>=0&&v(R,N),w(R,N),t.collar&&!r&&S(R,N),t.tie&&!r&&x(R,N,t.tie),o&&I(R,N,!1),a&&b(R,N),r&&(te(R)<0&&v(R,N),k(R,N)),l&&M(R,N),c&&A(R,N),pd(R)||J(R,N)}},"arm.left":{over:X?(P,R,N)=>_(R,N,"left",F,z):void 0},"arm.right":{over:X?(P,R,N)=>_(R,N,"right",F,z):void 0}}}}const _a={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 yd(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=_a[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 oo(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 Rn(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 Ln=(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 Ca(t,e,n,s,i,o=1,r){const{point:a,along:l}=n,c=s/300;switch(e.item){case"mug":{const h=Rn({x:a.x,y:a.y-4*c},20*c,24*c);t.line(Ln({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(Rn(a,13*c,24*c,h),e.color,i),t.shape(Rn(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(Ln({x:a.x,y:a.y+6*c},7*c,Math.PI,Math.PI*2),i),t.shape(Rn({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(Ln({x:a.x+5*c,y:a.y+10*c},5*c,Math.PI,0,8),i);const f=[...Ln({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(...Ln({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=Ln({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(Rn({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(Rn(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 Ha=(t,e)=>(t[`held.${e}`]??1)>=.5,bd=t=>Math.sin(t*Math.PI/2);function wd(t){const e=o=>Math.max(1,o.lineWidth*.45),n=o=>(r,a,l,c,h)=>{const u=t[o];u&&Ha(h??{},o)&&Ca(l,u,oo(a,o),a.height,e(a),bd(a.turn),a.head.center.y-a.head.ry)},s=(o,r,a,l,c)=>{const h=t.both;if(!h||!Ha(c??{},"both"))return;const u=oo(r,"left"),d=oo(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};Ca(a,h,f,r.height,e(r),bd(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:fk(i.parts[`arm.${r}`]?.over,o(r))}}return i}function fk(t,e){return t?(n,s,i,o,r)=>{t(n,s,i,o,r),e(n,s,i,o,r)}:e}function kd(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),over:n(o?.over,r?.over)}}return{behind:n(t.behind,e.behind),parts:s,front:n(t.front,e.front)}}function Ra(t={}){if(t.build&&!(t.build in zi))throw new Error(`character: unknown build '${t.build}'`);const e=t.build?zi[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?md(t.outfit):null,l=t.holding?yd(t.holding):{};let c=a?kd(a,t.layers??{}):t.layers??{};return Object.keys(l).length>0&&(c=kd(c,wd(l))),{plan:t.plan??Tu({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:od(t),face:{...t.face,teeth:t.face?.teeth??!1,tongue:t.face?.tongue??!1}}}function gk(t,e,n,s){const{point:i,facing:o}=da(t,[e,n,s]);return{point:i,facing:o}}const La=t=>t.rest[1]<-.5,pk=.3;function mk(t,e,n){return t.figure==="stick"?La(e)?n.slice(0,3):n:La(e)&&n.length>=3?Qe(n[0],n[1],n[2],pk):n.length===3?Qe(n[0],n[1],n[2],1):n}function _s(t,e){const n=t.plan.id==="human"?{...gt,...e}:e;return ro(t,n,ha(t.plan,n,{height:t.height,contact:t.contact}))}function ro(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]:0,w=p-m;o[d.id]=Math.abs(w)<r?0:w,i[d.id]={points:mk(t,d,f.points),depth:p}}),i.head={points:[n.head.center],depth:n.head.depth},o.head=0;const a=[...t.plan.chains.map(d=>d.id),"head"],l=[...a].sort((d,f)=>o[d]-o[f]||a.indexOf(d)-a.indexOf(f)),c={hip:n.hip};for(const[d,[f,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 ee(t,e){return _s(t,e).joints}function vd(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=$t(s,i,{x:0,y:0});r.facing>0&&t.guide(r.points),t.guide($t(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 Md(t,e,n,s,i,o){const r=n.lineWidth;if(i==="head"){const{head:f}=s,p=n.skin==="none"?null:n.skin;e.ellipse(f.center.x,f.center.y,f.rx,f.ry,f.angle,p,r),lk(t,e,n.head,f,o,{lineWidth:r,skin:n.skin},()=>{e.look!=="silhouette"&&R2(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(La(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(Qe(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 Sd(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{...It,...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;$i(t,r,Sd(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 Td(t,e,n,s=0){const i=e.plan.id==="human"?{...gt,...n}:n;Na(t,e,i,_s(e,i),s)}function ao(t,e){const n=e/t.height;return{...t,height:e,lineWidth:t.lineWidth*n}}function bk(t,e,n,s){const i=t.plan.id==="human"?{...gt,...e}:e,o=Xi(t.plan,i,{height:s.height,contact:t.contact},n);return ro(ao(t,o.height),i,o).joints}function wk(t,e,n,s,i){const o=e.plan.id==="human"?{...gt,...n}:n,r=Xi(e.plan,o,{height:i.height,contact:e.contact},s),a=ao(e,r.height);Na(t,a,o,ro(a,o,r),i.time??0)}function xd(t,e,n,s){const i=t.plan.id==="human"?{...gt,...e}:e,o=Xi(t.plan,i,{height:s.height,contact:t.contact},n),r=ao(t,o.height),{joints:a,order:l}=ro(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=bs(d,{look:r.look,ink:r.ink,lineWidth:r.lineWidth,seed:Yt(`${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&&vd(p,r,a),g(r.layers.behind),cd(d,p,r.head,a.head,i,{lineWidth:r.lineWidth,skin:r.skin}));const m=r.layers.parts?.[h];g(m?.under),Md(d,p,r,a,h,i),g(m?.over),u===l.length-1&&(hd(d,p,r.head,a.head,i,{lineWidth:r.lineWidth,skin:r.skin}),g(r.layers.front)),d.restore()}}))}function Na(t,e,n,s,i,o){const{joints:r}=s,a=o?s.order.filter(h=>o.has(h)):s.order,l=bs(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&&vd(l,e,r),o||c(e.layers.behind),cd(t,l,e.head,r.head,n,{lineWidth:e.lineWidth,skin:e.skin});for(const h of a){const u=e.layers.parts?.[h];c(u?.under),Md(t,l,e,r,h,n),c(u?.over)}hd(t,l,e.head,r.head,n,{lineWidth:e.lineWidth,skin:e.skin}),o||c(e.layers.front),t.restore()}function kk(t,e,n,s){const i=e.plan.id==="human"?{...gt,...n}:n,o=_s(e,i).joints.head.rx,r=ao(e,e.height*s.radius/Math.max(1e-6,o)),a=_s(r,i);t.save(),t.translate(s.x-a.joints.head.center.x,s.y-a.joints.head.center.y),Na(t,r,i,a,s.time??0,new Set(["head"])),t.restore()}function Ed(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 ye(t,e,n,s){const i=t.plan.id==="human"?{...gt,...e}:e;let o;if(Array.isArray(s))o=s;else{const{skeleton:r}=_s(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 P2(t.plan,i,n,o,{height:t.height})}const Ad=new Set(["walk","walking","gait"]);function lo(t,e=gt,n){let s={...e};for(const[o,r]of Object.entries(t))typeof r=="number"&&!Ad.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=Aa(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 vk(t){const{character:e}=t,n=e.height*.8,s=e.height,i=e.plan.id==="human"?gt:{};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),Td(o,e,lo(r.props??{},i,t.gaits),a)}}}function Pd(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 Mk(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"||Ad.has(c))&&(i[c]=h);const a=lo(i,s.plan.id==="human"?gt:{},t.gaits),l=ee(s,a);return{pose:a,joints:Pd(l,t.x+o+t.width/2,t.y+r+t.height)}}function Fa(t,e=gt){const n=[];return t.forEach((s,i)=>{const o=i===0?e:n[i-1],r=typeof s.pose=="string"?oe[s.pose]:void 0;n.push(r?{...r,turn:o.turn??0}:{...o,...s.pose})}),n}function Sk(t,e,n=gt){const s=Fa(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 Da=new Map;function Tk(t){const e=Da.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 Da.size<512&&Da.set(t,n),n}Ge([-3,-5,-4]);const xk=(t,e,n)=>{const s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)};function $d(t,e,n){const s=[0,0,0];for(const i of n){const o=Tk(i.color);let r;if(i.light==="ambient")r=i.intensity;else if(i.light==="directional")r=i.intensity*Math.max(0,-$e(e,i.direction));else{const a=vn(i.position,t),l=gi(a),c=l>0?Mn(a,1/l):e,h=i.range?Math.max(0,1-l/i.range)**2:1;if(r=i.intensity*Math.max(0,$e(e,c))*h,i.light==="spot"){const u=Math.cos(i.angle*Math.PI/180),d=Math.cos(i.angle*.8*Math.PI/180);r*=xk(u,d,-$e(c,i.direction))}}s[0]+=o[0]*r,s[1]+=o[1]*r,s[2]+=o[2]*r}return s}function Id(t,e){return t?Math.min(1,Math.max(0,(e-t.near)/(t.far-t.near))):0}function Wa(t,e,n={}){t.save(),Ek(t,e,n),t.restore()}function Ek(t,e,n){const s=Ba(e,n);n.shadow!==!1&&za(t,e,n);for(const i of e.under)Od(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)Od(t,i,s,n)}function Od(t,e,n,s){const i=s.loose?.[e.part.id];if(!i){ja(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),ja(t,e,n,s),t.restore()}function Ba(t,e={}){return e.lineWidth??Math.max(1.3,t.sizePx*.022)}function za(t,e,n={}){e.shadow.opacity<=0||e.shadow.points.length<3||(t.save(),t.globalAlpha=e.shadow.opacity,co(t,e.shadow.points,n.ink??"#26262b",!1),t.restore())}function Ak(t,e,n,s={}){t.save(),ja(t,e,n,s),t.restore()}function _d(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>-Cd/5&&w<Cd&&(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=qa(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?Hd(h,s):u.light?Pk(h,u,s):Ya(h);f&&(!i&&s.look==="silhouette"?d.shape(u.points,f,0):co(t,u.points,i||u.light?f:ho(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 Cd=.05;function qa(t,e,n,s){return bs(t,{look:s.look??"clean",ink:e.part.ink??s.ink??"#26262b",lineWidth:n,seed:Yt(`${s.seed??0}:${e.part.id}`),time:s.time??0,pencil:{construction:!1,rubbedOut:0,...s.pencil}})}function Ya(t){const{part:e}=t;return e.glow&&t.glow>0&&e.fill?Ga(e.fill,e.glow.color,t.glow):e.fill}function Pk(t,e,n){const{part:s}=t;if(!s.fill)return;const i=Xa(s.fill,e.light,e.fog??0,n.fog);return s.glow&&t.glow>0?Ga(i,s.glow.color,t.glow):i}function Hd(t,e){const n=Ya(t);return n&&(Ik(n)||t.glow>0)?n:e.paper??"#fbf8ef"}function ja(t,e,n,s){e.opacity<1?(t.save(),t.globalAlpha*=e.opacity,Rd(t,e,n,s),t.restore()):Rd(t,e,n,s)}function Rd(t,e,n,s){if(s.style==="stick")return $k(t,e,n,s);const{part:i}=e,o=qa(t,e,n,s),r=Ya(e),a=s.look==="silhouette";for(const c of e.faces)r&&(a?o.shape(c.points,r,0):co(t,c.points,ho(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 $k(t,e,n,s){const{part:i}=e;if(i.solidOnly)return;const o=qa(t,e,n,s);if(e.spine){o.line(e.spine,n*1.15);return}const r=Hd(e,s);for(const l of e.faces)co(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 Ik(t){const e=Nn(t);return e?(.299*e[0]+.587*e[1]+.114*e[2])/255<.3:!1}function co(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 Nn(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 Ka=t=>`#${t.map(e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0")).join("")}`;function ho(t,e){const n=Nn(t);return n?Ka(e>=1?n.map(s=>s+(255-s)*(e-1)*2):n.map(s=>s*e)):t}function Xa(t,e,n,s){const i=Nn(t);if(!i)return t;let o=i.map((a,l)=>a*e[l]);const r=s?Nn(s):void 0;return r&&n>0&&(o=o.map((a,l)=>a+(r[l]-a)*n)),Ka(o)}function Ga(t,e,n){const s=Nn(t),i=Nn(e);return!s||!i?n<.5?t:e:Ka(s.map((o,r)=>o+(i[r]-o)*n))}const Ok=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),_k=new Set(["walk","walking","gait"]),Ld=t=>typeof t=="number"?t:void 0,Ck=1.7;function Hk(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 Rk(t){const e=$e([0,1,0],t);if(e>.999999)return pi();if(e<-.999999)return se(Jt([1,0,0],180));const n=fi([0,1,0],t);return se(Jt(n,Math.acos(e)*180/Math.PI))}function Lk(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,M)=>u.push({mesh:k,world:At(i,b),material:M}),f=(k,b,M)=>d(e.sphere,kr(k,[0,0,0,1],[b,b,b]),M);for(const k of n.chains){const b=s.chains[k.id],M=k.id==="spine"?1.9:1;k.bones.forEach((E,A)=>{const T=b[A],S=b[A+1],x=wr(T,S),[O,I]=E.width??[1,1],_=h*M*(O+I)/2;if(x>1e-6){const C=bh(T,S,.5),F=Rk(Ge(vn(S,T)));d(e.cylinder,At(Ue(C),At(F,Ve([_,x,_]))),a)}f(T,h*M*O,a),f(S,h*M*I,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,At(v,Ve([g,m,g])),l);for(const k of[-1,1]){const b=Ge([k*.36,.15,.92]),M=di(p,di(di(Mn(w[0],b[0]*g*1.04),Mn(w[1],b[1]*m*1.04)),Mn(w[2],b[2]*g*1.04))),E=[...w[0],0,...w[1],0,...w[2],0,...M,1];d(e.sphere,At(E,Ve([g*.11,m*.14,g*.03])),c)}return u}const Nk={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:Ra({...t.character,height:1}),cylinder:Gi($u(1,1,16)),sphere:Gi(A2(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={...gt,...l.pose};for(const[T,S]of n)typeof S=="number"&&!Ok.has(T)&&!_k.has(T)&&(u[T]=S);const d=Math.max(0,Math.min(1,Ld(n.get("walking"))??l.walking??0));if(d>0){const T=typeof n.get("gait")=="string"?n.get("gait"):l.gait,S=Aa(T,Ld(n.get("walk"))??0,u);u=Object.fromEntries(Object.keys({...u,...S}).map(x=>[x,(u[x]??0)+((S[x]??0)-(u[x]??0))*d]))}const f=l.height??Ck,p=At(i.view,s),g={toView:T=>jt(p,T),toScreen:T=>a(T)},w=-g.toView([0,f/2,0])[2];if(w<=i.near)return null;const v=l.shadow===!1?[]:[{depth:w+f,draw:T=>Hk(T,g,f*.18)}];if(l.look==="solid"){const T=Ki(h.plan,u,{height:f,contact:h.contact});return{meshes:Lk(l,c,h.plan,T,s),drawables:v}}const k=jt(s,[0,f*.6,0]),b=Ge(vn(i.position,k)),M=$d(k,b,o).map(T=>Math.min(1,T)),E=o.length>0&&h.skin!=="none"?{...h,skin:Xa(h.skin,M,Id(r,wr(k,i.position)),r?.color)}:h,A=xd(E,u,g,{height:f});return{drawables:[...v,...A.map((T,S)=>({depth:-T.depth-S*1e-6,draw:(x,O)=>T.draw(x,O.time)}))]}}},Ne={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}},Cs=1,uo=.55,Nd=.35,Fk=1.6,Fd={a:"a",e:"e",i:"i",y:"i",o:"o",u:"u"},Dd={m:"m",b:"m",p:"m",f:"f",v:"f",w:"u",q:"u",l:"l",n:"l",d:"l",t:"l"},Wd={अ:"a",आ:"a",इ:"i",ई:"i",उ:"u",ऊ:"u",ऋ:"i",ए:"e",ऐ:"e",ओ:"o",औ:"o",ऍ:"e",ऑ:"o"},Bd={"ा":"a","ि":"i","ी":"i","ु":"u","ू":"u","ृ":"i","े":"e","ै":"e","ो":"o","ौ":"o","ॅ":"e","ॉ":"o"},Dk={प:"m",फ:"m",ब:"m",भ:"m",म:"m",व:"u"},Wk="्",zd="़",Bk=t=>t>="क"&&t<="ह",qd=new Set([".",",","!","?",";",":","…","।","॥","—","-"]);function Yd(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(qd.has(o))s("rest",Fk);else if(/\s/.test(o)){const a=e[e.length-1];a&&a.viseme!=="rest"&&e.push({viseme:"c",weight:Nd})}else if((o==="o"||o==="e")&&r===o)s(o==="o"?"u":"i",Cs),i++;else if(o in Fd)s(Fd[o],Cs);else if(o in Dd)s(Dd[o],uo);else{if(o==="h")continue;if(/[a-z]/.test(o))s("c",uo);else if(o in Wd)s(Wd[o],Cs);else if(Bk(o)){const a=r===zd?o==="फ"?"f":void 0:Dk[o];s(a??"c",uo);let l=i+1;n[l]===zd&&l++;const c=n[l];c===Wk?i=l:c&&c in Bd?(s(Bd[c],Cs),i=l):(!c||/\s/.test(c)||qd.has(c)||s("a",Cs*.6),i=l-1)}else(o==="ं"||o==="ँ")&&s("l",uo*.6)}}for(;e.length>0&&(e[e.length-1].viseme==="rest"||e[e.length-1].weight===Nd);)e.pop();return e}function Ua(t,e={}){const n=e.fields?.mouth??"mouth",s=e.fields?.mouthWidth??"mouthWidth",i=e.energy??1,o=Yd(t.text),r=[{time:t.start,value:Ne.rest.mouth}],a=[{time:t.start,value:Ne.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=Ne[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:Ne.rest.mouth,easing:"ease-in-out"}),a.push({time:t.end,value:Ne.rest.mouthWidth,easing:"ease-in-out"})),{[n]:r,[s]:a}}function zk(t,e,n={}){const s={};for(const i of[...e].sort((o,r)=>o.start-r.start))for(const[o,r]of Object.entries(Ua(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 fo(t,e,n,s={}){if(n.length===0)return e;const i=s.fields?.mouth??"mouth",o=s.fields?.mouthWidth??"mouthWidth",r={[i]:Ne.rest.mouth,[o]:Ne.rest.mouthWidth,...s.rest},a=new Et({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=Ua(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 Hs=([t,e,n])=>{const s=Math.hypot(t,e,n)||1;return[t/s,e/s,n/s]};function jd([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 Fn=(t,[e,n,s])=>t==="z"?[e,n,s]:t==="x"?[s,n,e]:[e,s,n];function Kd(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(Fn(n,[Math.cos(u)*t,Math.sin(u)*t,c]))}const a=[{corners:Array.from({length:s},(c,h)=>s-1-h),normal:Fn(n,[0,0,-1])},{corners:Array.from({length:s},(c,h)=>s+h),normal:Fn(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:Fn(n,[Math.cos(u),Math.sin(u),0])})}const l=[];if(i>0)for(const c of[-r,r]){const h=o.push(Fn(n,[0,0,c*1.01]))-1;for(let u=0;u<i;u++){const d=Math.PI*2*u/i,f=o.push(Fn(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 Xd([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 Hs([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 qk=t=>t.reduce((e,[n,s],i)=>{const[o,r]=t[(i+1)%t.length];return e+n*r-o*s},0)/2;function Gd(t,e){const n=qk(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:Hs([0,-c,h])})}return{vertices:o,faces:r,creases:!0}}function Ud(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 Vd(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=Hs([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=Hs(Jd(h,u)),f=Jd(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:Hs([h[0]-u[0],h[1]-u[1],h[2]-u[2]])})}return{vertices:i,faces:o,creases:!1}}function Jd(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 Zd(t){switch(t.type){case"box":return jd(t.size);case"cylinder":return Kd(t.radius,t.length,t.axis,t.segments,t.spokes);case"ellipsoid":return Xd(t.radii,t.segments);case"extrude":return Gd(t.profile,t.width);case"panel":return Ud(t.points,t.facing);case"tube":return{...Vd(t.points,t.radius,t.segments),joined:t.joined}}}function Va(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 sn=t=>Array.isArray(t)&&t.length===2&&t.every(e=>typeof e=="number"&&Number.isFinite(e));function go(t,e){return((e-t)%360+540)%360-180}function Qd(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 Dn(t,e){return Math.atan2(e[0]-t[0],e[1]-t[1])*180/Math.PI}function tf(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:Va(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 ef(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 nf(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 Rs=520,Ja=["do","at","for","to","through","toward","speed","pose","gag","say","look"],sf=t=>Math.max(700,Array.from(t).length*65),of=70,rf=35;function Za(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(-of,Math.min(of,l*.75)),d=Math.max(-rf,Math.min(rf,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 af={walk:1.3,bouncy:1.4,doubleBounce:1.2,sneak:.6,strut:1.2,tired:.8,run:3.6,shove:.7},Qa=Object.keys(Ft),tl=Object.keys(oe),el=Object.keys(io),Yk=.25,jk=700/180,Kk=200,Xk=300;function lf(t){if(!Array.isArray(t))return[{beat:-1,message:`Beats must be an array of { do: … } objects (got ${typeof t}).`}];const e=[...Qa,"face","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))Ja.includes(c)||o(ut("beat field",c,Ja,a[c]));const l=typeof r.do=="string"?tl.includes(r.do)?"pose":el.includes(r.do)?"gag":r.do==="turn"?"face":void 0:void 0;if(typeof r.do!="string"||!e.includes(r.do))return o(ut("character 3D beat",r.do,e,l));if(Qa.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&&!sn(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(sn))&&o("`through` is a list of points on the ground, each [x, z] metres.")),r.do==="place"&&!sn(r.to)&&o("`place` needs `to`: a point on the ground, [x, z] metres."),r.do==="face"&&!(sn(r.toward)||typeof r.toward=="number")&&o("`face` needs `toward`: a point [x, z] or a 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)&&!tl.includes(r.pose)&&o(ut("pose",r.pose,tl)),r.do==="gag"&&!el.includes(r.gag)&&o(ut("gag",r.gag,el))}),n}function Gk(t,e,n){const s=lf(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={...gt,...n.pose};let[r,a]=n.position??[0,0],l=n.heading??0,c=0;const h=new Map,u=[],d=(M,E,A,T="linear")=>{const S=h.get(M)??[];S.push({time:E,value:A,easing:T}),h.set(M,S)};d("x",0,r),d("z",0,a),d("rotateY",0,l);const f=(M,E)=>{const A=go(l,E);if(Math.abs(A)<1)return M;const T=Math.max(Kk,Math.abs(A)*jk);return d("rotateY",M,l),l+=A,d("rotateY",M+T,l,"ease-in-out"),M+T},p=(M,E,A,T="ease-in-out")=>{for(const[S,x]of Object.entries(A))o[S]!==x&&(d(S,M,o[S]??0),d(S,E,x,T),o[S]=x)},g=(M,E,A)=>{const T=tf([[r,a],...E.through??[E.to]]);if(T.length<2)return A;const S=f(A,Dn(T[0].point,T[1].point)),x=T[T.length-1].at,O=E.speed??af[M]*Math.sqrt(i/1.7),I=E.for??x/O*1e3,_=Pa(M,i),C=Ht("ease-in-out"),F=Math.min(Xk,I/4);u.push({time:S,value:M}),d("walking",S,0),d("walking",S+F,1,"ease-out"),d("walking",S+I-F,1),d("walking",S+I,0,"ease-in");const z=c;let X=l;for(let J=0;;J=Math.min(x,J+Yk)){const K=S+nf(C,J/x)*I,{point:P,direction:R}=ef(T,J);if(X+=go(X,Dn([0,0],R)),d("x",K,P[0]),d("z",K,P[1]),d("rotateY",K,X),d("walk",K,z+J/_),J>=x)break}return c=z+x/_,[r,a]=T[T.length-1].point,l=X,S+I},m=[],w=[];let v=0;for(const M of e){const E=M.at??v;let A=E;if(Qa.includes(M.do))A=g(M.do,M,E);else if(M.do==="face")A=f(E,typeof M.toward=="number"?M.toward:Dn([r,a],M.toward));else if(M.do==="hold")A=E+(M.for??1e3);else if(M.do==="place")d("x",E,r),d("z",E,a),[r,a]=M.to,d("x",E+1,r),d("z",E+1,a),typeof M.toward=="number"&&(d("rotateY",E,l),l=M.toward,d("rotateY",E+1,l)),A=E+1;else if(M.do==="pose"){A=E+(M.for??500);const T=typeof M.pose=="string"?oe[M.pose]:M.pose;p(E,A,T)}else if(M.do==="gag"){const T=dd(M.gag,{at:E,from:{...o}});let S=T[0];for(const x of T.slice(1))p(S.time,x.time,Object.fromEntries(Object.entries(x.pose).filter(([O,I])=>o[O]!==I)),x.easing??"ease-in-out"),S=x;A=S.time}else if(M.do==="say"){A=E+(M.for??sf(M.say)),w.push({text:M.say,start:E,end:A});const T={tilt:o["head.tilt"]??0,left:o["brow.left"]??0,right:o["brow.right"]??0};let S=0;for(let x=E+Rs;x<A-Rs/2;x+=Rs,S++){const O=S%2===0;p(x-Rs/2,x,{"head.tilt":T.tilt+(O?3:-2),"brow.left":T.left+(O?.25:0),"brow.right":T.right+(O?.25:0)})}S>0&&p(A-Rs/2,A,{"head.tilt":T.tilt,"brow.left":T.left,"brow.right":T.right})}else if(M.do==="look"){const T=M.look??M.toward,S=i*.9,x=T==="camera"?n.camera??[0,1.6,8]:T.length===3?T:[T[0],S,T[1]];A=E+(M.for??500),p(E,A,Za({x:r,z:a,heading:l,eyeHeight:S},x),"ease-out")}m.push({do:M.do,start:E,end:A}),v=A}const k=`${n.scene}/${t}`;let b=[...h].map(([M,E])=>({id:`${t}-${M}`,target:k,property:M,keyframes:Qd(E)}));return u.length>0&&b.push({id:`${t}-gait`,target:k,property:"gait",keyframes:u}),w.length>0&&(b=fo(k,b,w,{rest:{mouth:n.pose?.mouth??gt.mouth??0,mouthWidth:n.pose?.mouthWidth??gt.mouthWidth??1}})),{tracks:b,duration:v,beats:m,end:{position:[r,a],heading:l,pose:{...o}}}}function nl(t,e,n=[0,0,0]){const s=t.filter(o=>o.target===e),i=new Et({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 Uk(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 Et({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?nl(t,`${e.scene}/${a.camera}`,e.objects?.[a.camera]??[0,1.6,8]):(()=>{const u=nl(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=Za({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 Vk(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(M=>Math.hypot(M[0]-k[0],M[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 cf={x:0,y:0,scale:1,rotate:0,shakeX:0,shakeY:0,shakeRotate:0};function Jk(t){const e=n=>{const s=t?.get(n);return typeof s=="number"?s:cf[n]};return{x:e("x"),y:e("y"),scale:e("scale"),rotate:e("rotate"),shakeX:e("shakeX"),shakeY:e("shakeY"),shakeRotate:e("shakeRotate")}}function Zk(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 Qk(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 hf(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)ff(t,c,s);t.restore()}function sl(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 uf=150,t5={pencil:44,eraser:30};function il(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=uf*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=_t.pencilGrip,p=A=>{const T=A.fingers.thumb,S=A.fingers.index,x=A.fingers.middle,O=df([T.points[3],S.points[3],x.points[3]]),I=df([T.points[1],S.points[0]]),_=(T.depths[3]+S.depths[3]+x.depths[3])/3;return{pinch:O,direction:Math.atan2(I.y-O.y,I.x-O.x),depth:_}},g=Pi(f,{size:u}),m=c-p(g).direction,w=Pi(f,{size:u,angle:m*180/Math.PI}),v=p(w),k=t5[i]*a,b={x:v.pinch.x-Math.cos(c)*k,y:v.pinch.y-Math.sin(c)*k},M={x:d.x-b.x,y:d.y-b.y},E=w.axes.up;e5(t,M,{x:-E.x,y:-E.y},u,n.arm??300*a,o,n.sleeve??"#5b7db1",r),$i(t,M,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"?sl(t,{x:0,y:0},{angle:c*180/Math.PI,outline:r},s):hf(t,{x:0,y:0},{angle:c*180/Math.PI,length:190,outline:r},s),t.restore()}}})}const df=t=>({x:t.reduce((e,n)=>e+n.x,0)/t.length,y:t.reduce((e,n)=>e+n.y,0)/t.length});function e5(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,o5(g)),m},f=Math.min(s*.55,i*.35);t.save(),t.lineJoin="round",t.lineCap="round",t.lineWidth=3*(s/uf),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 n5(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:Si(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 s5(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 i5(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?Ti(a,t.sketch,c):void 0;h>0&&(u?t.smooth?u.curve(e,h):u.line(e,h):ff(a,An(e,h))),r&&h>0&&h<1&&il(a,Si(e,h),r,u)}}}function o5(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 ff(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 po=1e5;function r5(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 ol(t,e,n,s){if(s<=0||e.length===0)return;const i=An(e,s),o=n/2,r=a=>{t.beginPath(),t.rect(-po,-po,2*po,2*po),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 a5(t,e,n,s,i){t.save(),ol(t,e,n,s),i(),t.restore()}function l5(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(),ol(o,e.path,n,l),t.draw(o,r,a),o.restore(),!i||l<=0||l>=1)return;const c=Si(e.path,l);s?il(o,c,{...s,tool:"eraser"}):sl(o,c,i)}}}function Wn(){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)=>mo(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:c5(i)}))}}}function mo(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 Bn(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 c5(t){return[...t].sort((n,s)=>n.time-s.time).map(n=>({time:n.time,value:n.value,...n.easing?{easing:n.easing}:{}}))}const h5=.0016,u5=.6,Fe=33;function Ls(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-Fe),c=n(o,r);return{x:(c.x-l.x)/Fe,y:(c.y-l.y)/Fe}},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??h5,h=r.duration??900,u=(r.spin??u5)*(l.x<0?-1:1),d=t.valueAt(e(o,"rotate"),r.at);i(o,r.at);for(let f=0;f<=h;f+=Fe){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 yo(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 Et({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(M=>Math.abs(M.top-b)<.5)},c=(o?.keyframes??[]).map(k=>k.time),h=k=>{const b=S=>S<0?0:i[S].offset(k),M=l(k);if(M>=0)return b(M);if(Math.abs(a(k))<.5)return 0;const E=S=>l(S)>=0||Math.abs(a(S))<.5,A=[...c].reverse().find(S=>S<=k&&E(S)),T=c.find(S=>S>=k&&E(S));return A===void 0&&T===void 0?0:A===void 0?b(l(T)):T===void 0||T===A?b(l(A)):b(l(A))+(b(l(T))-b(l(A)))*(k-A)/(T-A)},u=i.flatMap(k=>k.windows),d=(k,b)=>u.some(M=>M.start<b&&M.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 M=new Set([b]);for(let E=k+s;E<b;E+=s)M.add(E);for(const E of u)for(const A of[E.start,E.end])A>k&&A<b&&M.add(A);for(const E of[...M].sort((A,T)=>A-T))p.push({time:E,value:a(E)+h(E)})};for(let k=1;k<f.length;k++){const b=f[k-1].time,M=f[k].time;d(b,M)?g(b,M):p.push({...f[k],value:f[k].value+h(M)})}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 on(t){const e=t.indexOf(":");return e<0?{kind:t,rest:""}:{kind:t.slice(0,e),rest:t.slice(e+1)}}function De(t,e,n,s){const i=Object.keys(n.anchors).map(r=>on(r).kind),{kind:o}=on(e);return i.includes(o)?new Error(`${t}: no anchor "${e}"${s?`: ${s}`:""} (anchors: ${Object.keys(n.anchors).join(", ")})`):new Error(`${t}: ${ut("anchor",o,i)} (anchors: ${Object.keys(n.anchors).join(", ")})`)}function Ns(t,e,n){return new Error(`${t}.edit: ${ut("edit",e,Object.keys(n.edits))}`)}function vt(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 gf={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"},bo=["wipe","fly","blur"],Fs={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"}},d5=.9,f5=8;function g5(t){const e={...gf,...t.theme},n=t.code.replace(/\t/g," ").replace(/\n$/,"").split(`
56
+ `),s=t.fontSize??16,i=(t.lineHeight??1.6)*s,o=(t.charWidth??.6)*s,r=t.padding??12,a=t.lineNumbers===!1?0:(String(n.length).length+2)*o,l=Math.max(1,...n.map(P=>P.length)),c=t.width??r*2+a+l*o,h=r*2+n.length*i,u=t.x+r+a,d=new Set(t.hidden??[]),f=t.language??"plain";if(!ko.includes(f))throw new Error(`codePanel: ${ut("language",f,ko)}`);const p=n.map(P=>mf(P,f).flatMap(R=>Array.from(R.text,()=>e[R.kind]))),g=Wn(),m=Ls(g),w=[],v=new Map,k=[],b=[],M=P=>{if(!Number.isInteger(P)||P<1||P>n.length)throw new Error(`codePanel: no line ${P} (it has ${n.length})`)},E=g.tween,A=g.last,T=(P,R,N,$,L,W=300)=>{M(P),E(`line.${P}.${R}`,N,$,L,W)},S=(P,R)=>w.filter(N=>N.line<P&&N.closed<=R).length,x=vt,O=P=>t.y+r+(P-1)*i,I=P=>Array.isArray(P)?P:[P],_=(P,R,N)=>{let $=-1;for(let L=0;L<N;L++)if($=n[P-1].indexOf(R,$+1),$<0)throw new Error(`codePanel: line ${P} has no ${N>1?`${N}th `:""}"${R}"`);return $},C={};n.forEach((P,R)=>{const N=R+1;C[`line.${N}.highlight`]=0,C[`line.${N}.strike`]=0,C[`line.${N}.wipe`]=0,C[`line.${N}.reveal`]=d.has(N)?0:1,C[`line.${N}.shift`]=0});const F={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 m5(Object.keys(C))},actions:rl},draw(P,R){const N=R.props??{},$=B=>Number(N[B]??C[B]),L=r+a,W=B=>r+(B-1)*i-$(`line.${B}.shift`)*i;P.fillStyle=e.background,pf(P,0,0,c,h,8),P.fill(),P.font=`${s}px ${e.font}`,P.textBaseline="middle",P.textAlign="left";const q=(B,Y,U,D,V)=>{const j=n[B-1];for(let st=Y;st<U;st++)j[st]!==" "&&(P.fillStyle=p[B-1][st],P.fillText(j[st],D+(st-Y)*o,V))};P.save(),pf(P,0,0,c,h,8),P.clip(),n.forEach((B,Y)=>{const U=Y+1,D=$(`line.${U}.wipe`);if(D>=1)return;const V=W(U),j=V+i/2,st=Math.max(1,B.length)*o,ot=Math.round($(`line.${U}.reveal`)*B.length),rt=v.get(U)??{style:"wipe",from:"left"};P.save(),D>0&&p5(P,rt,D,{left:L-a,top:V,width:a+st+o,height:i},c);const at=$(`line.${U}.highlight`);at>0&&(P.globalAlpha*=Math.min(1,at),P.fillStyle=e.highlight,P.fillRect(L-o/2,V,st+o,i),P.globalAlpha/=Math.min(1,at)),a>0&&ot>0&&(P.fillStyle=e.gutter,P.textAlign="right",P.fillText(String(U),L-o,j),P.textAlign="left");const H=[...k.filter(tt=>tt.line===U).map(tt=>({column:tt.column,length:tt.text.length,piece:tt,insert:void 0})),...b.filter(tt=>tt.line===U).map(tt=>({column:tt.column,length:0,piece:void 0,insert:tt}))].sort((tt,lt)=>tt.column-lt.column||tt.length-lt.length);let Z=0,et=L;for(const tt of H){q(U,Z,Math.min(tt.column,ot),et,j),et+=(tt.column-Z)*o;let lt=tt.length,Q="";if(tt.piece){const G=tt.piece.written??"",nt=$(`piece.${tt.piece.id}.write`);G&&nt>0?(Q=G.slice(0,Math.round(nt*G.length)),lt=tt.length+(G.length-tt.length)*Math.min(1,nt*2)):lt=tt.length*(1-$(`piece.${tt.piece.id}.away`))}else tt.insert&&(lt=tt.insert.chars*$(`insert.${tt.insert.id}.open`),tt.insert.text&&(Q=tt.insert.text.slice(0,Math.round($(`insert.${tt.insert.id}.type`)*tt.insert.text.length))));P.fillStyle=e.text;for(let G=0;G<Q.length;G++)Q[G]!==" "&&P.fillText(Q[G],et+G*o,j);et+=lt*o,Z=tt.column+tt.length}q(U,Z,Math.max(Z,ot),et,j);const it=$(`line.${U}.strike`);it>0&&(P.strokeStyle=e.strike,P.lineWidth=Math.max(1.5,s/10),P.beginPath(),P.moveTo(L,j),P.lineTo(L+st*Math.min(1,it),j),P.stroke()),P.restore()});for(const B of k){const Y=$(`piece.${B.id}.opacity`);if(Y<=0||$(`line.${B.line}.wipe`)>=1)continue;const U=L+(B.column+B.text.length/2)*o+$(`piece.${B.id}.x`),D=W(B.line)+i/2+$(`piece.${B.id}.y`);P.save(),P.globalAlpha=Math.min(1,Y),P.translate(U,D),P.rotate($(`piece.${B.id}.rotate`)*Math.PI/180),q(B.line,B.column,B.column+B.text.length,-B.text.length*o/2,0),P.restore()}P.restore()}},z=P=>{const{kind:R,rest:N}=on(P),$=L=>De("codePanel",P,Fs,L);if(R==="box"){if(N)throw $("box takes no arguments");return{kind:R}}if(R==="line"){if(!/^\d+$/.test(N))throw $("write it line:N");return{kind:R,n:Number(N)}}if(R==="token"){const L=/^(\d+)(?:#(\d+))?:(.+)$/.exec(N);if(!L)throw $("write it token:N:TEXT, or token:N#K:TEXT for the Kth");return{kind:R,n:Number(L[1]),occurrence:L[2]?Number(L[2]):1,text:L[3]}}if(R==="spot"){const L=/^(\d+):(\d+)(?::(\d+))?$/.exec(N);if(!L)throw $("write it spot:N:C, or spot:N:C:W for W characters");return{kind:R,n:Number(L[1]),column:Number(L[2]),width:L[3]?Number(L[3]):1}}throw $()},X=(P,R,N,$=!1)=>{const L=Array.isArray(R)?R:[R];if(L.length===0||$&&L.length>1)throw new Error(`codePanel.edit: ${P} takes ${$?"one":"at least one"} ${N} anchor`);return L.map(W=>{const q=z(W);if(q.kind!==N)throw new Error(`codePanel.edit: ${P} takes ${N} anchors (${N}:…), not "${W}"`);return q})},J=(P,R)=>{if(typeof R.text!="string")throw new Error(`codePanel.edit: ${P} needs \`text\` (the text to write)`);return R.text},K={kind:"code",about:Fs,target:F,lines:n,box:x(t.x,t.y,c,h),line(P,R=1/0){return M(P),x(u,O(P)-S(P,R)*i,Math.max(1,n[P-1].length)*o,i)},token(P,R,N=1,$=1/0){M(P);const L=_(P,R,N);return x(u+L*o,O(P)-S(P,$)*i,R.length*o,i)},highlight(P,R){for(const N of I(P)){const $=A(`line.${N}.highlight`,0);T(N,"highlight",$,R.on===!1?0:1,R,200)}return K},strike(P,R){for(const N of I(P))T(N,"strike",A(`line.${N}.strike`,0),1,R);return K},remove(P,R){const N=I(P),$=R.style??"wipe";if(!bo.includes($))throw new Error(`codePanel.remove: ${ut("style",$,bo)}`);const L=$==="wipe"?300:450,W=R.at+(R.duration??L),q=R.close??250;for(const B of N)T(B,"wipe",0,1,{...R,easing:R.easing??($==="fly"?"ease-in":void 0)},L),v.set(B,{style:$,from:R.from??"left"}),w.push({line:B,closed:W+q});for(let B=1;B<=n.length;B++){if(N.includes(B))continue;const Y=N.filter(D=>D<B).length;if(Y===0)continue;const U=A(`line.${B}.shift`,0);T(B,"shift",U,U+Y,{at:W,duration:q,easing:"ease-in-out"})}return K},type(P,R){return T(P,"reveal",0,1,{duration:n[P-1].length*45,...R}),K},piece(P,R,N=1){if(typeof P=="string"){const B=z(P);if(B.kind!=="token")throw new Error(`codePanel.piece: a piece is a word, token:N:TEXT, not "${P}"`);return K.piece(B.n,B.text,B.occurrence)}const $=P;if(R===void 0)throw new Error('codePanel.piece: which word? piece(n, text) or piece("token:N:TEXT")');M($);const L=_($,R,N),W=k.find(B=>B.line===$&&B.column===L&&B.text===R);if(W)return W;if(k.some(B=>B.line===$&&L<B.column+B.text.length&&B.column<L+R.length))throw new Error(`codePanel: "${R}" on line ${$} overlaps another piece`);const q={id:k.length+1,line:$,column:L,text:R,home:K.token($,R,N,0)};k.push(q);for(const B of["x","y","rotate","write","away"])C[`piece.${q.id}.${B}`]=0;return C[`piece.${q.id}.opacity`]=1,q},follow(P,R){return m.follow(P,R),K},fling(P,R){return m.fling(P,R),K},move(P,R){return m.move(P,R),K},write(P,R,N){return P.written=R,E(`piece.${P.id}.write`,0,1,{duration:Math.max(1,R.length)*70,...N}),K},spot(P,R,N=1,$=1/0){M(P);const L=b.filter(W=>W.line===P&&W.column<=R&&W.at<=$).reduce((W,q)=>W+q.chars,0);return x(u+(R+L)*o,O(P)-S(P,$)*i,N*o,i)},insert(P,R,N,$){M(P);const L={id:b.length+1,line:P,column:R,chars:N.length,text:N,at:$.at};b.push(L),C[`insert.${L.id}.open`]=0,C[`insert.${L.id}.type`]=0;const W=$.duration??N.length*70;return E(`insert.${L.id}.open`,0,1,{at:$.at,duration:W*.6,easing:"ease-out"}),E(`insert.${L.id}.type`,0,1,{at:$.at,duration:W}),K},drop(P,R,N,$){M(R);const L=$.duration??250,W=R===P.line,q=$.easing??(W?"linear":"ease-out"),B=K.landing(P,R,N,$.at),Y={id:b.length+1,line:R,column:N,chars:P.text.length,at:$.at};return b.push(Y),C[`insert.${Y.id}.open`]=0,E(`insert.${Y.id}.open`,0,1,{at:$.at,duration:L,easing:W?q:"ease-out"}),E(`piece.${P.id}.away`,A(`piece.${P.id}.away`,0),1,{at:$.at,duration:L,easing:W?q:"ease-in-out"}),m.cutAfter(P,$.at),K.move(P,{at:$.at,duration:L,easing:q,to:{x:B.x,y:B.y}}),E(`piece.${P.id}.rotate`,g.valueAt(`piece.${P.id}.rotate`,$.at),0,{at:$.at,duration:L}),K},landing(P,R,N,$=1/0){const L=K.spot(R,N,P.text.length,$),W=R===P.line&&N>P.column?P.text.length*o:0;return x(L.left-W,L.top,L.width,L.height)},ride(P,R,N){const $=n.map((L,W)=>{const q=g.keys(`line.${W+1}.shift`)??[];return{top:O(W+1),offset:B=>-mo(q,B)*i,windows:Bn(q)}});return yo(P,R,{ground:N.ground,every:N.every??Fe,floors:$})},tracks:g.tracks,anchor(P,R=1/0){const N=z(P);return N.kind==="box"?K.box:N.kind==="line"?K.line(N.n,R):N.kind==="token"?K.token(N.n,N.text,N.occurrence,R):K.spot(N.n,N.column,N.width,R)},edit(P,R,N){const $=()=>X(P,R,"line").map(L=>L.n);if(P==="highlight")return K.highlight($(),N);if(P==="strike")return K.strike($(),N);if(P==="remove")return K.remove($(),N);if(P==="type"){for(const L of $())K.type(L,N);return K}if(P==="insert"){const[L]=X(P,R,"spot",!0);return K.insert(L.n,L.column,J(P,N),N)}if(P==="write"||P==="drop"||P==="move"||P==="fling"){const[L]=X(P,R,"token",!0),W=K.piece(L.n,L.text,L.occurrence);if(P==="write")return K.write(W,J(P,N),N);if(P==="fling")return K.fling(W,N);if(P==="drop"){const B=typeof N.into=="string"?z(N.into):void 0;if(B?.kind!=="spot")throw new Error("codePanel.edit: drop needs `into`, a spot anchor (spot:N:C)");return K.drop(W,B.n,B.column,N)}const q=typeof N.to=="string"?K.anchor(N.to,N.at):N.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 K.move(W,{...N,to:q})}throw Ns("codePanel",P,Fs)}};return K}function p5(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=f5*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*d5*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 rl={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 m5(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 pf(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 wo={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:[]};wo.typescript=[...wo.javascript,"enum","interface","type","implements","private","public","readonly","keyof","as","declare","namespace"];const ko=Object.keys(wo),y5={go:"//",rust:"//",csharp:"//",javascript:"//",typescript:"//",python:"#",plain:null};function mf(t,e){const n=new Set(wo[e]),s=y5[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 al='"Patrick Hand", "Segoe Print", "Bradley Hand", "Comic Sans MS", "Chalkboard SE", cursive',Ds={whiteboard:{background:"#f7f7f2",frame:"#b8bcc4",ink:"#1f2a44",colors:{ink:"#1f2a44",red:"#d03b3b",blue:"#2f6fd0",green:"#2e9a52",orange:"#e07b1a"},font:al,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:al,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:al,stroke:.08,opacity:1,rule:{color:"#c9d6ec",spacing:1.55,margin:"#f0a3a3"}}},ll=["circle","box","underline","arrow"],be={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"}},yf=90,bf=300,b5=.3;function w5(t){const e=typeof t.theme=="string"?t.theme:"whiteboard";if(!(e in Ds))throw new Error(`whiteboard: ${ut("theme",e,Object.keys(Ds))}`);const n=typeof t.theme=="object"?{...Ds.whiteboard,...t.theme}:Ds[e],s=t.fontSize??28,i=t.charWidth??.55,o=b=>b===void 0?n.ink:n.colors[b]??b,r=b=>vt(t.x+b.left,t.y+b.top,b.width,b.height),a=Wn(),l=Ls(a),c={},h=new Map,u=[],d=[],f=(b,M,E,A)=>{const T=h.get(b);if(!T||T.kind!=="text")throw De("whiteboard",A,be,`there is no text "${b}" (texts: ${p().join(", ")||"none"})`);let S=-1;for(let O=0;O<E;O++)if(S=T.item.text.indexOf(M,S+1),S<0)throw De("whiteboard",A,be,`text "${b}" has no ${E>1?`${E}th `:""}"${M}"`);const x=T.size*i;return{column:S,box:vt(T.box.left+S*x,T.box.top,M.length*x,T.box.height)}},p=()=>[...h.values()].filter(b=>b.kind==="text").map(b=>b.item.id),g=b=>{const{kind:M,rest:E}=on(b),A=T=>De("whiteboard",b,be,T);if(M==="box"){if(E)throw A("box takes no arguments");return{kind:M}}if(M==="text"||M==="mark"){if(!E)throw A(`write it ${M}:ID`);return{kind:M,id:E}}if(M==="term"){const T=/^([^:#]+)(?:#(\d+))?:(.+)$/.exec(E);if(!T)throw A("write it term:ID:TEXT, or term:ID#K:TEXT for the Kth");return{kind:M,id:T[1],occurrence:T[2]?Number(T[2]):1,text:T[3]}}throw A()},m=b=>{const M=g(b);if(M.kind==="box")return vt(0,0,t.width,t.height);if(M.kind==="term")return f(M.id,M.text,M.occurrence,b).box;const E=h.get(M.id);if(!E||E.kind!==M.kind){const A=[...h.values()].filter(T=>T.kind===M.kind).map(T=>T.item.id);throw De("whiteboard",b,be,`there is no ${M.kind} "${M.id}" (${M.kind}s: ${A.join(", ")||"none"})`)}return E.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(O=>typeof O=="number"))throw new Error(`whiteboard: text "${b.id}" needs \`at\`, [x, y] from the board's top-left`);const S=b.size??s,x=vt(b.at[0],b.at[1],Math.max(1,b.text.length)*S*i,S*1.3);h.set(b.id,{kind:"text",item:b,size:S,color:o(b.color),box:x}),c[`text.${b.id}.write`]=b.hidden?0:1,c[`text.${b.id}.erase`]=0;continue}if(!ll.includes(b.mark))throw new Error(`whiteboard: mark "${b.id}": ${ut("mark",b.mark,ll)}`);const M=b.mark==="arrow"?["from","to"]:["around"];for(const S of M)if(typeof b[S]!="string")throw new Error(`whiteboard: ${b.mark} "${b.id}" needs \`${S}\`, a place on the board (an item before it)`);const E=new Set([b.from,b.to].filter(S=>typeof S=="string").map(S=>S.split(":")[1])),A=b.mark==="arrow"?[...h.values()].filter(S=>S.kind==="text"&&!E.has(S.item.id)).map(S=>S.box):[],T=k5(b,m,s,A);h.set(b.id,{kind:"mark",item:b,color:o(b.color),points:T,box:S5(T)}),c[`mark.${b.id}.draw`]=b.hidden?0:1,c[`mark.${b.id}.erase`]=0}const w=b=>u.filter(M=>M.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 T5(Object.keys(c))},actions:be.edits},draw(b,M){const E=M.props??{},A=T=>Number(E[T]??c[T]??0);if(b.save(),b.fillStyle=n.background,vf(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(),vf(b,0,0,t.width,t.height,10),b.clip(),b.lineWidth=1,b.strokeStyle=n.rule.color;const T=s*(n.rule.spacing??1.55);for(let S=T;S<t.height;S+=T)b.beginPath(),b.moveTo(0,S),b.lineTo(t.width,S),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 T of h.values()){if(b.save(),cl(b,T.box,A(`${T.kind}.${T.item.id}.erase`)),T.kind==="text"){const S=w(T.item.id),x=A(`text.${T.item.id}.write`)*T.item.text.length;b.font=`${T.size}px ${n.font}`,b.fillStyle=T.color;for(let O=0;O<Math.ceil(x);O++)T.item.text[O]===" "||S.some(I=>O>=I.column&&O<I.column+I.text.length)||(b.globalAlpha=n.opacity*Math.min(1,x-O),b.fillText(T.item.text[O],T.box.left+(O+.5)*T.size*i,T.box.y))}else kf(b,T.points,A(`mark.${T.item.id}.draw`),T.color,s*n.stroke,T.item.mark==="arrow");b.restore()}for(const T of d){const S=A(`strike.${T.id}.draw`);if(S<=0)continue;const{box:x}=T,O=x.height*.15;kf(b,[{x:x.left-3,y:x.y+O},{x:x.right+3,y:x.y-O}],S,n.colors.red??n.ink,s*n.stroke*.8,!1)}for(const T of u){const S=h.get(T.item),x=S.size*i;b.font=`${S.size}px ${n.font}`,b.fillStyle=S.color;const O=T.written;if(O){const F=A(`piece.${T.id}.write`)*O.length,z=T.home.x-t.x-O.length*x/2;for(let X=0;X<Math.ceil(F);X++)O[X]!==" "&&(b.globalAlpha=n.opacity*Math.min(1,F-X),b.fillText(O[X],z+(X+.5)*x,T.home.y-t.y))}const I=A(`piece.${T.id}.opacity`)*Math.min(1,A(`text.${T.item}.write`)*S.item.text.length-T.column);if(I<=0)continue;b.save();const _={x:T.home.x-t.x,y:T.home.y-t.y},C={x:A(`piece.${T.id}.x`),y:A(`piece.${T.id}.y`)};cl(b,vt(_.x+C.x-T.home.width/2,_.y+C.y-T.home.height/2,T.home.width,T.home.height),A(`piece.${T.id}.erase`)),Math.hypot(C.x,C.y)<1&&cl(b,S.box,A(`text.${T.item}.erase`)),b.globalAlpha=n.opacity*Math.min(1,I),b.translate(_.x+C.x,_.y+C.y),b.rotate(A(`piece.${T.id}.rotate`)*Math.PI/180);for(let F=0;F<T.text.length;F++)T.text[F]!==" "&&b.fillText(T.text[F],(F+.5-T.text.length/2)*x,0);b.restore()}b.restore()}},k={kind:"board",about:be,target:v,box:vt(t.x,t.y,t.width,t.height),anchor(b){return r(m(b))},piece(b){const M=g(b);if(M.kind!=="term")throw new Error(`whiteboard.piece: a piece is a term, term:ID:TEXT, not "${b}"`);const{column:E,box:A}=f(M.id,M.text,M.occurrence,b),T=u.find(x=>x.item===M.id&&x.column===E&&x.text===M.text);if(T)return T;if(u.some(x=>x.item===M.id&&E<x.column+x.text.length&&x.column<E+M.text.length))throw new Error(`whiteboard: "${M.text}" in "${M.id}" overlaps another piece`);const S={id:u.length+1,item:M.id,column:E,text:M.text,home:r(A)};u.push(S);for(const x of["x","y","rotate","erase","write"])c[`piece.${S.id}.${x}`]=0;return c[`piece.${S.id}.opacity`]=1,S},edit(b,M,E){const A=Array.isArray(M)?M:[M];if(A.length===0)throw new Error(`whiteboard.edit: ${b} takes at least one anchor`);const T=A.map(O=>({name:O,anchor:g(O)}));for(const{name:O}of T)m(O);const S=(O,I=!1)=>{const _=T.find(C=>!O.includes(C.anchor.kind));if(_)throw new Error(`whiteboard.edit: ${b} takes ${O.join(" or ")} anchors, not "${_.name}"`);if(I&&T.length>1)throw new Error(`whiteboard.edit: ${b} takes one ${O.join(" or ")} anchor`)},x=()=>k.piece(T[0].name);if(b==="write"){if(T.some(O=>O.anchor.kind==="term")){if(S(["term"],!0),typeof E.text!="string")throw new Error("whiteboard.edit: write into a term needs `text` (the new text)");const O=x();return O.written=E.text,a.tween(`piece.${O.id}.write`,0,1,{duration:Math.max(bf,E.text.length*yf),...E}),k}S(["text"]);for(const{anchor:O}of T){const I=O.id,_=h.get(I).item.text;a.tween(`text.${I}.write`,0,1,{duration:Math.max(bf,_.length*yf),...E})}return k}if(b==="draw"){S(["mark"]);for(const{anchor:O}of T)a.tween(`mark.${O.id}.draw`,0,1,{duration:500,...E});return k}if(b==="erase"){S(["text","term","mark"]);for(const O of T){const I=O.anchor.kind==="term"?`piece.${k.piece(O.name).id}.erase`:`${O.anchor.kind}.${O.anchor.id}.erase`;a.tween(I,0,1,{duration:400,...E})}return k}if(b==="strike"){S(["text","term"]);for(const O of T){const I={id:d.length+1,box:m(O.name)};d.push(I),c[`strike.${I.id}.draw`]=0,a.tween(`strike.${I.id}.draw`,0,1,{duration:250,...E})}return k}if(b==="move"){S(["term"],!0);const O=typeof E.to=="string"?k.anchor(E.to):E.to;if(!O||typeof O.x!="number"||typeof O.y!="number")throw new Error("whiteboard.edit: move needs `to`, an anchor name or { x, y }");return k.move(x(),{...E,to:O})}if(b==="fling")return S(["term"],!0),k.fling(x(),E);throw Ns("whiteboard",b,be)},follow(b,M){return l.follow(b,M),k},fling(b,M){return l.fling(b,M),k},move(b,M){return l.move(b,M),k},ride(b){return b},tracks:a.tracks};return k}function k5(t,e,n,s=[]){const i=Pe(Yt(t.id)),o=g=>(i.next()*2-1)*g,r=n*b5;if(t.mark==="arrow"){const g=e(t.from),m=e(t.to),w=wf(g,m,r*.6),v=wf(m,g,r*.6),k=Math.hypot(v.x-w.x,v.y-w.y),b=M5(w,v);let M=k*(.06+o(.04));if(t.bend!==void 0)M=k*t.bend;else{const T=v5(w,v,b,s,r);T!==0&&(M=T)}const E={x:(w.x+v.x)/2+b.x*M,y:(w.y+v.y)/2+b.y*M},A=[];for(let T=0;T<=24;T++){const S=T/24;A.push({x:(1-S)**2*w.x+2*(1-S)*S*E.x+S*S*v.x,y:(1-S)**2*w.y+2*(1-S)*S*E.y+S*S*v.y})}return A}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=(M,E)=>({x:M+o(r*.2),y:E+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 v5(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 wf(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 M5(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 S5(t){const e=t.map(o=>o.x),n=t.map(o=>o.y),s=Math.min(...e),i=Math.min(...n);return vt(s,i,Math.max(...e)-s,Math.max(...n)-i)}function kf(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 cl(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 vf(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 T5(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 hl=["bar","line","pie","donut"],Mf='system-ui, -apple-system, "Segoe UI", sans-serif',Ws={light:{background:"#ffffff",text:"#3b4252",grid:"#d8dee9",color:"#4c7bd9",highlight:"#e8833a",palette:["#4c7bd9","#3fa66b","#b05cc9","#d9c04c","#4cb8c4","#d95c6f","#8a7a5a","#6b7a99"],font:Mf},dark:{background:"#1e2230",text:"#cdd6f4",grid:"#3a4055",color:"#89b4fa",highlight:"#fab387",palette:["#89b4fa","#a6e3a1","#cba6f7","#f9e2af","#94e2d5","#f38ba8","#b4a58a","#9399b2"],font:Mf}},rn={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)"}},x5=600,E5=500,A5=200,P5=400,$5=.14,I5=Math.PI*2;function O5(t){if(!hl.includes(t.kind))throw new Error(`chart: ${ut("kind",t.kind,hl)}`);const e=typeof t.theme=="string"?t.theme:"light";if(!(e in Ws))throw new Error(`chart: ${ut("theme",e,Object.keys(Ws))}`);const n=typeof t.theme=="object"?{...Ws.light,...t.theme}:Ws[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 H of r){if(typeof H?.id!="string"||!H.id||/[:.]/.test(H.id))throw new Error(`chart: every series needs an \`id\` without ":" or "." (got ${JSON.stringify(H?.id)})`);if(a.has(H.id))throw new Error(`chart: two series are called "${H.id}"`);a.add(H.id)}const l=new Map(r.map((H,Z)=>[H.id,Z])),c=H=>r[l.get(H)].color??(l.get(H)===0?n.color:n.palette[l.get(H)%n.palette.length]),h=new Set,u=(H,Z)=>{const et=H.values?.[Z.id]??(t.series?void 0:H.value)??H.value;if(typeof et!="number"||!Number.isFinite(et))throw new Error(o?`chart: "${H.id}" needs a value for series "${Z.id}" (\`values: { ${Z.id}: … }\`)`:`chart: "${H.id}" needs a \`value\`, a number`);return et};for(const H of t.data){if(typeof H?.id!="string"||!H.id||/[:.]/.test(H.id))throw new Error(`chart: every datum needs an \`id\` without ":" or "." (got ${JSON.stringify(H?.id)})`);if(h.has(H.id))throw new Error(`chart: two data are called "${H.id}"`);for(const Z of r)u(H,Z);h.add(H.id)}const d=s==="bar"?"bar":s==="line"?"point":"slice",f=Math.max(...t.data.flatMap(H=>r.map(Z=>u(H,Z)))),p=i?t.data.reduce((H,Z)=>H+u(Z,r[0]),0):t.max??Sf(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)},M=b.bottom-b.top,E=(b.right-b.left)/t.data.length,A=o?E*.72/r.length:E*.6,T=o?A*.86:A,S=Math.max(4,g*.35),x=M/p,O=new Map(t.data.map((H,Z)=>[H.id,Z])),I=H=>b.left+E*(O.get(H)+.5),_=(H,Z)=>o?I(H)-E*.36+A*l.get(Z)+(A-T)/2:I(H)-T/2,C=(H,Z)=>_(H,Z)+T/2,F=t.height-g*1.2,z={cx:t.width/2,cy:(b.top+F)/2,r:Math.max(10,Math.min(t.width/2,(F-b.top)/2)-g*2.6)},X=s==="donut"?z.r*.55:0,J=s==="donut"?(X+z.r)/2:z.r*.62,K=new Map;if(m){let H=b.right;for(const Z of[...r].reverse()){const et=Z.label??Z.id,it=g*.62*et.length+g*1.9;K.set(Z.id,vt(H-it,k,it,g*1.4)),H-=it+g*.6}}const P=Wn(),R=Ls(P),N={},$=(H,Z,et)=>o?`${d}.${H}.${Z}.${et}`:`${d}.${H}.${et}`;for(const H of t.data)for(const Z of r)N[$(H.id,Z.id,"value")]=u(H,Z),N[$(H.id,Z.id,"show")]=H.hidden?0:1,N[$(H.id,Z.id,"highlight")]=0,i&&(N[$(H.id,Z.id,"pull")]=0);const L=(H,Z)=>P.keys(H)?.length?mo(P.keys(H),Z):N[H],W=(H,Z,et)=>L($(H,Z,"value"),et)*(s==="bar"?L($(H,Z,"show"),et):1)*x,q=H=>{const Z=r[0].id,et=t.data.map(Q=>Math.max(0,H($(Q.id,Z,"value")))*Math.max(0,Math.min(1,H($(Q.id,Z,"show"))))),it=et.reduce((Q,G)=>Q+G,0),tt=new Map;let lt=-Math.PI/2;return t.data.forEach((Q,G)=>{const nt=it>0?I5*et[G]/it:0,ht=lt+nt/2,ft=Math.max(0,Math.min(1,H($(Q.id,Z,"pull"))))*z.r*$5;tt.set(Q.id,{start:lt,sweep:nt,mid:ht,out:ft,centre:{x:z.cx+Math.cos(ht)*(J+ft),y:z.cy+Math.sin(ht)*(J+ft)}}),lt+=nt}),tt},B=H=>q(Z=>L(Z,H)),Y=H=>{const{kind:Z,rest:et}=on(H),it=tt=>De("chart",H,rn,tt);if(Z==="box"){if(et)throw it("box takes no arguments");return{kind:"box"}}if(Z==="legend"){if(!K.has(et))throw it(m?`there is no series "${et}" (series: ${r.map(tt=>tt.id).join(", ")})`:"only a chart with several series has a legend");return{kind:"legend",series:et}}if(Z==="bar"||Z==="point"||Z==="slice"||Z==="label"||Z==="value"){if(!et)throw it(`write it ${Z}:ID`);const tt=et.indexOf(":"),lt=tt<0?et:et.slice(0,tt),Q=tt<0?r[0].id:et.slice(tt+1);if(!O.has(lt))throw it(`there is no "${lt}" (data: ${[...O.keys()].join(", ")})`);if(!a.has(Q))throw it(`there is no series "${Q}" (series: ${r.map(G=>G.id).join(", ")})`);if(Z==="label"&&tt>=0)throw it("a label is one per datum: label:ID");if((Z==="bar"||Z==="point"||Z==="slice")&&Z!==d)throw it(`a ${s} chart has ${d}s, not ${Z}s: ${d}:${lt}`);return{kind:Z,id:lt,series:Q}}throw it()},U=(H,Z)=>{if(H.kind==="box")return vt(0,0,t.width,t.height);if(H.kind==="legend")return K.get(H.series);if(i){const Q=B(Z).get(H.id),G=Math.max(g*1.5,z.r*.42);if(H.kind==="slice")return vt(Q.centre.x-G/2,Q.centre.y-G/2,G,G);const nt=D(Q);return H.kind==="label"?nt:Q.sweep>=.3?vt(Q.centre.x-g*1.6,Q.centre.y-g*.65,g*3.2,g*1.3):vt(nt.left,nt.bottom,nt.width,g*1.3)}const et=H.kind==="label"?I(H.id):C(H.id,H.series),it=b.bottom-W(H.id,H.series,Z);if(H.kind==="bar")return vt(et-T/2,it,T,b.bottom-it);if(H.kind==="point")return vt(I(H.id)-S,it-S,S*2,S*2);if(H.kind==="label")return vt(et-E/2,b.bottom+g*.4,E,g*1.4);const tt=it-(s==="line"?S:0)-g*.3,lt=o&&s==="bar"?A:E;return vt((s==="line"?I(H.id):et)-lt/2,tt-g*1.3,lt,g*1.3)},D=H=>{const Z=z.r+H.out+g*.9,et={x:z.cx+Math.cos(H.mid)*Z,y:z.cy+Math.sin(H.mid)*Z},it=g*4.2,tt=Math.cos(H.mid),lt=tt>.2?et.x:tt<-.2?et.x-it:et.x-it/2;return vt(lt,et.y-g*.7,it,g*1.4)},V=H=>vt(t.x+H.left,t.y+H.top,H.width,H.height),j=H=>`${t.prefix??""}${H.toFixed(t.decimals??0)}${t.suffix??""}`,st=new Map,ot={type:"custom",x:t.x,y:t.y,width:t.width,height:t.height,props:N,about:{kind:`${s} chart`,summary:`A ${s} chart of ${t.data.length} values (${t.data.map(H=>H.id).join(", ")})${o?` in ${r.length} series (${r.map(H=>H.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(N).map(H=>[H,H5(H)])),actions:rn.edits},draw(H,Z){const et=Z.props??{},it=Q=>Number(et[Q]??N[Q]??0);if(H.save(),H.fillStyle=n.background,Tf(H,0,0,t.width,t.height,8),H.fill(),H.font=`${g}px ${n.font}`,H.textBaseline="middle",t.title&&(H.fillStyle=n.text,H.textAlign="left",H.font=`600 ${g*1.2}px ${n.font}`,H.fillText(t.title,i?g:b.left,g*1.5),H.font=`${g}px ${n.font}`),m){H.textAlign="left";for(const Q of r){const G=K.get(Q.id);H.fillStyle=c(Q.id),Tf(H,G.left,G.top+g*.25,g*.9,g*.9,2),H.fill(),H.fillStyle=n.text,H.fillText(Q.label??Q.id,G.left+g*1.3,G.top+G.height/2)}}if(i){rt(H,it),H.restore();return}H.lineWidth=1,H.textAlign="right";for(let Q=0;Q<=4;Q++){const G=b.bottom-M*Q/4;H.strokeStyle=n.grid,H.beginPath(),H.moveTo(b.left,G),H.lineTo(b.right,G),H.stroke(),H.fillStyle=n.text,H.globalAlpha=.7,H.fillText(_5(p*Q/4),b.left-g*.5,G),H.globalAlpha=1}(v||w)&&(H.fillStyle=n.text,H.textAlign="center",H.globalAlpha=.85,v&&(H.save(),H.translate(g*.9,(b.top+b.bottom)/2),H.rotate(-Math.PI/2),H.fillText(v,0,0),H.restore()),w&&H.fillText(w,(b.left+b.right)/2,b.bottom+g*2.3),H.globalAlpha=1);const tt=(Q,G)=>it($(Q,G,"value"))*(s==="bar"?it($(Q,G,"show")):1)*x,lt=(Q,G)=>ul(c(G),n.highlight,it($(Q,G,"highlight")));if(s==="line"){H.lineWidth=Math.max(2,g*.2),H.lineJoin="round",H.lineCap="round";for(const Q of r)H.strokeStyle=c(Q.id),H.beginPath(),t.data.forEach((G,nt)=>{const ht={x:I(G.id),y:b.bottom-tt(G.id,Q.id)},ft=it($(G.id,Q.id,"show"));if(nt===0){ft>0&&H.moveTo(ht.x,ht.y);return}const wt=t.data[nt-1];if(it($(wt.id,Q.id,"show"))<1||ft<=0)return;const mt={x:I(wt.id),y:b.bottom-tt(wt.id,Q.id)};H.lineTo(mt.x+(ht.x-mt.x)*ft,mt.y+(ht.y-mt.y)*ft)}),H.stroke()}H.textAlign="center";for(const Q of t.data){for(const G of r){const nt=s==="bar"?C(Q.id,G.id):I(Q.id),ht=tt(Q.id,G.id),ft=it($(Q.id,G.id,"show"));if(H.fillStyle=lt(Q.id,G.id),s==="bar"?ht>.5&&(C5(H,nt-T/2,b.bottom-ht,T,ht,Math.min(6,T/4)),H.fill()):ft>0&&(H.beginPath(),H.arc(nt,b.bottom-ht,S*Math.min(1,ft*1.5)*(1+.3*it($(Q.id,G.id,"highlight"))),0,Math.PI*2),H.fill()),t.values!==!1&&ft>0){H.globalAlpha=Math.min(1,ft*2),H.font=`600 ${o?g*.85:g}px ${n.font}`,H.fillStyle=ul(n.text,n.highlight,it($(Q.id,G.id,"highlight")));const wt=b.bottom-ht-(s==="line"?S:0)-g*.95;H.fillText(j(it($(Q.id,G.id,"value"))),nt,wt),H.font=`${g}px ${n.font}`,H.globalAlpha=1}}H.fillStyle=n.text,H.fillText(Q.label??Q.id,I(Q.id),b.bottom+g*1.1)}H.strokeStyle=n.text,H.lineWidth=1.5,H.beginPath(),H.moveTo(b.left,b.bottom),H.lineTo(b.right,b.bottom),H.stroke(),H.restore()}};function rt(H,Z){const et=r[0].id,it=q(Z);t.data.forEach((tt,lt)=>{const Q=it.get(tt.id);if(Q.sweep<=1e-4)return;const G=st.get(tt.id),nt=G?{x:Z(`piece.${G.id}.x`),y:Z(`piece.${G.id}.y`)}:{x:0,y:0},ht=G?Z(`piece.${G.id}.rotate`)*Math.PI/180:0,ft=G?Z(`piece.${G.id}.opacity`):1;if(ft<=0)return;H.save(),H.globalAlpha=ft;const wt={x:z.cx+Math.cos(Q.mid)*Q.out,y:z.cy+Math.sin(Q.mid)*Q.out};H.translate(Q.centre.x+nt.x,Q.centre.y+nt.y),H.rotate(ht),H.translate(-Q.centre.x,-Q.centre.y),H.beginPath(),H.arc(wt.x,wt.y,z.r,Q.start,Q.start+Q.sweep),X>0?H.arc(wt.x,wt.y,X,Q.start+Q.sweep,Q.start,!0):H.lineTo(wt.x,wt.y),H.closePath(),H.fillStyle=ul(n.palette[lt%n.palette.length],n.highlight,Z($(tt.id,et,"highlight"))),H.fill(),H.strokeStyle=n.background,H.lineWidth=Math.max(1.5,g*.15),H.stroke(),t.values!==!1&&Q.sweep>=.3&&(H.fillStyle=n.background,H.font=`600 ${g}px ${n.font}`,H.textAlign="center",H.fillText(j(Z($(tt.id,et,"value"))),Q.centre.x,Q.centre.y),H.font=`${g}px ${n.font}`),H.restore();const mt=D(Q),ne=Math.cos(Q.mid);H.globalAlpha=ft,H.fillStyle=n.text,H.textAlign=ne>.2?"left":ne<-.2?"right":"center";const Vs=ne>.2?mt.left:ne<-.2?mt.right:mt.left+mt.width/2;H.fillText(tt.label??tt.id,Vs,mt.top+mt.height/2),t.values!==!1&&Q.sweep<.3&&(H.globalAlpha=ft*.8,H.fillText(j(Z($(tt.id,et,"value"))),Vs,mt.bottom+g*.65)),H.globalAlpha=1})}const at={kind:"chart",chartKind:s,about:rn,target:ot,max:p,box:vt(t.x,t.y,t.width,t.height),anchor(H,Z=1/0){return V(U(Y(H),Z))},piece(H){const Z=Y(H);if(Z.kind!=="slice")throw new Error(i?`chart: a piece is a slice, slice:ID, not "${H}"`:`chart: a ${d} is not a piece; slices of a pie or donut are (slice:ID). Change a ${d} with edit('set' | 'show' | 'highlight', …)`);const et=st.get(Z.id);if(et)return et;const it={id:st.size+1,datum:Z.id,home:V(U(Z,0))};st.set(Z.id,it);for(const tt of["x","y","rotate"])N[`piece.${it.id}.${tt}`]=0;return N[`piece.${it.id}.opacity`]=1,it},edit(H,Z,et){const it=Array.isArray(Z)?Z:[Z];if(it.length===0)throw new Error(`chart.edit: ${H} takes at least one anchor`);if(!(H in rn.edits))throw Ns("chart",H,rn);if(H==="pull"&&!i)throw new Error(`chart.edit: pull takes slice anchors of a pie or donut; a ${s} chart has ${d}s`);const tt=it.map(lt=>{const Q=Y(lt);if(Q.kind!==d)throw new Error(`chart.edit: ${H} takes ${d} anchors (${d}:ID), not "${lt}"`);return Q});for(const{id:lt,series:Q}of tt){const G=nt=>$(lt,Q,nt);if(H==="set"){if(typeof et.value!="number"||!Number.isFinite(et.value))throw new Error("chart.edit: set needs `value`, a number");P.tween(G("value"),L(G("value"),et.at),et.value,et,x5)}else H==="show"?P.tween(G("show"),L(G("show"),et.at),et.on===!1?0:1,et,E5):H==="pull"?P.tween(G("pull"),L(G("pull"),et.at),et.on===!1?0:1,et,P5):P.tween(G("highlight"),L(G("highlight"),et.at),et.on===!1?0:1,et,A5)}return at},follow(H,Z){return R.follow(H,Z),at},fling(H,Z){return R.fling(H,Z),at},move(H,Z){return R.move(H,Z),at},ride(H,Z,et){if(s!=="bar")return H;const it=t.data.flatMap(tt=>r.map(lt=>{const Q=W(tt.id,lt.id,0),G=[...Bn(P.keys($(tt.id,lt.id,"value"))),...Bn(P.keys($(tt.id,lt.id,"show")))];return{top:t.y+b.bottom-Q,offset:nt=>Q-W(tt.id,lt.id,nt),windows:G}}));return yo(H,Z,{ground:et.ground,every:et.every??Fe,floors:it})},tracks:P.tracks};return at}function Sf(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 _5(t){return Number.isInteger(t)?String(t):String(Number(t.toFixed(2)))}function ul(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 Tf(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 C5(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 H5(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 dl={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:de.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:de.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:de.black},ears:!0,outfit:{shirt:"#9b5fc0",trousers:"#2f2f3a",sleeves:"long"}}},grandpa:{label:"Grandpa",group:"family",scale:.96,options:{build:"stocky",hair:{style:"receding",color:de.gray},facialHair:{style:"shortBoxed",color:de.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:de.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:de.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:de.blond},hat:"sunHat",ears:!0,outfit:{shirt:"#d64535",trousers:"#4f6b3a",sleeves:"long"}}}};function R5(t,e=300,n={}){const s=dl[t];if(!s)throw new Error(`castMember: unknown cast member '${t}'`);return{...s.options,height:Math.round(e*s.scale),...n}}const Bs={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 L5(t,e,n){return Bs[t].spacing*Math.min(e.height,n.height)}const xf=.075;function N5(t,e,n,s={}){const i=Bs[t];if(!i)throw new Error(`meetHands: unknown meeting '${t}' (one of ${Object.keys(Bs).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={...gt,...m.pose,turn:v,lean:(m.pose?.lean??0)+i.lean};const b=w?1:-1,M=(E,A,T)=>{k=ye(m.character,k,E,{x:c.x+A-m.x,y:c.y,depth:T})};if(t==="handOver"){const E=xf*l;M("arm.left",-b*E*.9,E),M("arm.right",-b*E*.9,-E)}else M("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=ee(m.character,w),k=t==="handOver"?["hand.left","hand.right"]:["hand.right"],b=t==="handOver"?xf*l+f:f;return k.every(M=>Math.abs(v.points[M].y-c.y)<f&&Math.abs(v.points[M].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 vo={spacing:.3,lean:10,tilt:8};function F5(t,e){return vo.spacing*Math.min(t.height,e.height)}function D5(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={...gt,...p.pose,turn:w,lean:(p.pose?.lean??0)+vo.lean,"head.tilt":(p.pose?.["head.tilt"]??0)+v*vo.tilt};const{over:b,round:M}=a(p,g,v);return k=ye(p.character,k,"arm.right",b),k=ye(p.character,k,"arm.left",M),k},c=l(s,i,!0),h=l(i,s,!1),u=.05*r,d=(p,g,m,w)=>{const v=ee(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 an={spacing:.32,low:.3,high:.5,helperLean:40,helperBend:16};function W5(t,e){return an.spacing*Math.min(t.height,e.height)}function B5(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:-(an.low+(an.high-an.low)*i)*a},c=m=>m?o?1:.62:o?3:3.38;let h={...gt,...t.pose,turn:c(r),lean:(t.pose?.lean??0)+an.helperLean*(1-i)+4,bend:(t.pose?.bend??0)+an.helperBend*(1-i),"head.nod":18*(1-i)};h=ye(t.character,h,"arm.right",{x:l.x-t.x,y:l.y});const u={...oe.sitFloor,...e.pose,turn:c(!r)},d={...gt,...e.pose,turn:c(!r)};let f=Ed(u,d,i);f=ye(e.character,f,"arm.right",{x:l.x-e.x,y:l.y});const p=.04*a,g=(m,w)=>{const v=ee(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 z5=.7,q5=50,Y5=1.2,j5=.8,K5=3,X5=30,G5=.8,U5=.6,fl=(t,e)=>Math.max(-e,Math.min(e,t)),V5=["hair.swing","hair.trail","hair.lift"];function Ef(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=us(l,c),u=us(f=>a(f).x,c),d=us(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)*z5*i,v=d[p].value-g.y,k=Math.sin(g.turn*Math.PI/2),b=Math.cos(g.turn*Math.PI/2),M=m*K5+w*b/i*X5,E=-w*k/i*G5,A=-v/i*U5;return{time:f.time,swing:fl(M*s,q5),trail:fl(E*s,Y5),lift:fl(A*s,j5)}})}function J5(t,e){if(t.length===0)return{"hair.swing":0,"hair.trail":0,"hair.lift":0};if(e<=t[0].time)return Af(t[0]);if(e>=t[t.length-1].time)return Af(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 Af=t=>({"hair.swing":t.swing,"hair.trail":t.trail,"hair.lift":t.lift}),zn=16,Z5=1500;function Q5(t,e,n,s={}){const i=n.head.hair;if(!i||!Fu(i))return[];const o=e.filter(v=>v.target===t),r=o.reduce((v,k)=>k.keyframes.reduce((b,M)=>Math.max(b,M.time),v),0),a=gt,l=new Set(["x","y","turn","head.turn"]),c=new Et({id:`${t}-hair-follow`,tracks:o.filter(v=>l.has(v.property))}),h=(v,k,b)=>{const M=c.getStateAtTime(v).values.get(t)?.get(k);return typeof M=="number"?M:b},u=new Et({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 M={};for(const[A,T]of d(k*zn)??[])M[A]=T;const E=ee(n,lo(M,a,s.gaits)).head.center;f.set(k,b={x:E.x,y:E.y})}return b},g=v=>{const k=Math.floor(v/zn),b=v/zn-k,M=p(k*zn),E=p((k+1)*zn);return{x:M.x+(E.x-M.x)*b,y:M.y+(E.y-M.y)*b}},m=Ef(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??Z5),headRadius:ee(n,gt).head.rx,step:s.step,stiffness:s.stiffness,damping:s.damping,amount:s.amount,wind:s.wind}),w=[];for(const v of V5){const k=v.slice(5);let b=m.map(E=>({time:E.time,value:E[k]}));if(b.every(E=>Math.abs(E.value)<.001))continue;const M=o.find(E=>E.property===v);if(M){const E=new Et({id:`${t}-${v}-own`,tracks:[M]}),A=T=>Number(E.getStateAtTime(T).values.get(t)?.get(v)??0);b=b.map(T=>({time:T.time,value:T.value+A(T.time)}))}w.push({id:`${t}-${v}`,target:t,property:v,keyframes:b})}return w}const ln={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 ln.full;if(typeof t=="string")return ln[t];const{base:e,...n}=t;return{...ln[e??"full"],...n}}const pl=160,tv=120,ev=700,ml=60,nv=90,Mo=3200,qn=1,cn=1e-6;function So(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])>cn));for(const u of r)o[u]=sv(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=iv(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=ov(t,c,t[0].pose[h],s.jumpSquash);u.length>0&&(o[h]=u)}return o}function sv(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)<=cn){const O=p.time+(k?c(f):0);if(f===e.length-1)Math.abs(d-m)>cn&&u(Math.max(O,v+pl),m,"ease-in-out"),d=m;else if(k&&a&&s.drift>0&&n.drift.includes(t)&&O-v>=ev){const I=Yt(`${i}:${t}:${f}`)%2===0?1:-1;d=m+I*s.drift*r,u(O,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),M=Math.max(e[f-1].time+b,v);let E=p.time+b;o&&s.eyeDart>0&&(E=Math.min(E,M+s.eyeDart));const A=E-M;if(A<=qn){u(p.time,m,p.easing),d=m;continue}u(M,d);const T=Math.sign(w);if(a&&s.anticipation>0&&r>0&&A>=pl){const O=d-T*Math.min(Math.abs(w)*s.anticipation,r),I=M+A*s.anticipationTime;u(I,O,"ease-in-out"),s.hold>0&&u(I+A*s.hold,O)}const S=f+1<e.length?e[f+1].time-p.time:1/0,x=Math.min(s.settle,S/2);if(a&&s.overshoot>0&&r>0&&A>=tv&&x>qn){const O=Math.min(Math.abs(w)*s.overshoot,r);u(E,m+T*O,p.easing??s.actionEase),u(E+x,m,s.settleEase)}else u(E,m,p.easing??s.actionEase);d=m}return h}function iv(t,e,n,s,i){const o=[],r=ml+nv;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+Mo*.6,u=0;for(;h<l;){c.some(g=>Math.abs(g-h)<Mo/2)||o.push(h);const p=(Yt(`${s}:blink:${u++}`)%1e3/1e3-.5)*(Mo*.66);h+=Mo+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+ml<=p+qn||(f>p+qn&&d.push({time:f,value:i}),d.push({time:f+ml,value:1,easing:"ease-in"}),d.push({time:f+r,value:i,easing:"ease-out"}))}return d.length>1?d:[]}function ov(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<pl||t[l].act===!1)){if(c<=cn&&h>cn)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>cn&&h<=cn){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 Pf={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 rv(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 av(){const t={},e={};for(const n of Object.keys(gt)){const s=rv(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 $f=av();function If(t,e){return Object.entries(e).map(([n,s])=>({id:`${t}-${n}`,target:t,property:n,keyframes:s}))}function Of(t,e,n={}){const s=Ci(e),i=e.map((o,r)=>({time:o.time,pose:{...s[r]},easing:o.easing,act:o.act}));return If(t,So(i,n.rig??Pf,n))}function _f(t,e,n={}){const s=n.rest??gt,i=Fa(e,s),o=e.map((r,a)=>({time:r.time,pose:{...s,...i[a]},easing:r.easing,act:r.act}));return If(t,So(o,n.rig??$f,n))}const Cf=kt.shocked,lv=kt.scared,We={take:t=>[{after:140,pose:{stretch:.8,bend:10,lean:t.lean-4,leftShoulder:8,rightShoulder:8,leftEye:.35,rightEye:.35,leftBrow:-.6,rightBrow:-.6,mouth:0},easing:"ease-in-out"},{after:260,pose:{stretch:.78}},{after:360,pose:{rise:.22,stretch:1.35,bend:-14,leftShoulder:150,rightShoulder:150,leftElbow:35,rightElbow:35,leftHip:22,rightHip:22,leftKnee:45,rightKnee:45,...Cf,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,...kt.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,...Cf,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,...kt.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:{...lv,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:{...Gt.sad,bend:18,stretch:.92,lean:t.lean+5,turn:t.turn,sit:t.sit},easing:"ease-in-out"}]};function yl(t,e){const n=typeof e.from=="string"?Gt[e.from]:e.from??ct;return bl(We[t](n),{...e,from:n})}function bl(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 zs(t,e=1){const n=We[t](ct);return n[n.length-1].after*e}function Hf(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 cv={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 hv(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=>cv[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));Hf(t,p,{...i,opacity:(i.opacity??.7)*w,spacing:i.spacing??h*.02})}}function Rf(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=Yt(`${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 uv(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;dv(t,h,u,i*.14,n*Math.PI+a),t.stroke()}t.restore()}function dv(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 qs={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 wl(t={}){return[...Object.keys(Ft),...Object.keys(Gt),...Object.keys(We),...Object.keys(qs),...Object.keys(t.gaits??{}),...Object.keys(t.actions??{})]}function kl(t={}){const e=new Set(wl()),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 vl(t={}){const e={};for(const n of Object.keys(Ft))e[n]=`Walks to \`to\` in the ${n} gait, feet planted, turning round first if needed.`;for(const n of Object.keys(Gt))e[n]=`Moves into the ${n} pose and holds it.`;for(const n of Object.keys(We))e[n]=`The ${n} gag, built on the current pose.`;for(const[n,s]of Object.entries(qs))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 To=["do","at","for","to","toward","mood","say","pose","target","onto"],fv={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"},xo=["viewer","ahead","back"],hn=t=>typeof t=="number"&&Number.isFinite(t);function Ys(t,e={}){const n=kl(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=wl(e),i=l=>l in Ft||l in(e.gaits??{}),o=Object.keys(kt),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))To.includes(g)||h(ut("beat field",g,To,fv[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(ut("action",f,s));return}const p=qs[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(ut("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)?hn(m)||h(`Pose joint \`${g}\` must be a number (got ${JSON.stringify(m)}).`):h(ut("pose joint",g,r));for(const g of["at","for"]){const m=d[g];m!==void 0&&!(hn(m)&&m>=0)&&h(`\`${g}\` is milliseconds, a number ≥ 0 (got ${JSON.stringify(m)}).`)}hn(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&&!hn(m)&&h(`\`${g}\` is a scene ${g==="to"?"x":"y"} in px, a number (got ${JSON.stringify(m)}).`)}if(d.toward!==void 0&&!hn(d.toward)&&!xo.includes(d.toward)&&h(`\`toward\` is a scene x or one of ${xo.join(", ")}${typeof d.toward=="string"&&hs(d.toward,xo)?` (did you mean "${hs(d.toward,xo)}"?)`:""} (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"||!hn(g.x)||!hn(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 Ml(t,e={},n="scriptTracks"){const s=Ys(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
- `)}`)}Oy(ll);function f5(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 g5(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 gf=8;function bo(t,e={},n=0){if(n>gf)throw new Error(`scriptTracks: custom actions nest more than ${gf} 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 bo(o,e,n+1)})}function pf(t){return t.length===0?0:Math.max(...t.map(e=>e.after))}const hl={walk:1e3,bouncy:900,doubleBounce:1100,sneak:1600,strut:1100,tired:1500,shove:1300,run:560},p5=450,m5=2.4,y5=160,mf=2.5,b5=200,w5=340,k5=1.1,yf=[380,900],v5=.35,wo=300,dl=150,M5=260,S5=1.2,ul=160,bf=400,Fs=300,T5=450,wf=500,fl=350,kf=150,E5=120,gl=180,vf=420,A5=300,Mf=300,x5=140,pl=150,Sf=450,$5=450,ml=150,Tf=350,Ef=400,P5=12,I5=600,Af=90,xf=400,O5=200,_5=.09,$f=350,we=450,yl=1200,C5=700,Bn=320,ke=220,H5=65,R5=700,Pf=t=>t in Fe,L5=t=>t in Yt;function If(t){return Math.max(R5,Array.from(t).length*H5)}function ko(t,e,n={}){const s={actions:n.actions,gaits:n.gaits};cl(e,s);const i=n.gait??"walk",o=bo(e,n.actions).map(P=>P.do==="go"?{...P,do:i}:P);cl(o,s,"scriptTracks (after expanding custom actions)");const r=P=>Dt[P]??n.gaits?.[P],a=P=>hl[P]??n.gaits?.[P]?.cycle??1e3,l=P=>{const L=n.actions?.[P];return L&&"steps"in L?L:void 0},c=n.from??0,h=n.ground??0,d=n.height??300;let u=c,f=h,p=n.facing??1,g=n.start??ct,m=0,w=0;const S=[{time:0,pose:g}],k=[{time:0,value:0}],y=[{time:0,value:0}],E=[{time:0,value:0}],x=[{time:0,value:0}],$=[{time:0,value:"walk"}],M=[{time:0,value:p}],v=[],T=[],I=[],O=(P,L,W,z)=>{g={...g,...L},W&&(g=_e(g,W)),S.push({time:P,pose:g,...z===!1?{act:z}:{}})},_=(P,L,W)=>(O(P+Bn/2,{turn:0},W),M.push({time:P+Bn/2,value:p},{time:P+Bn/2+1,value:L}),p=L,O(P+Bn,{turn:1}),P+Bn),C=P=>P<u?-1:1,D=(P,L,W)=>C(L)!==p?_(P,C(L),W):P,q=(P,L,W,z="arm")=>{const B=z==="arm",Y=se({...P,...B?{rightShoulder:0,rightElbow:0}:{rightHip:0,rightKnee:0}},{height:d,facing:p}),V=B?Y.shoulders.right:Y.hip,F=B?Y.elbows.right:Y.knees.right,U=(ot,rt)=>Math.atan2(p*ot,rt)*180/Math.PI,st=((U(L-(u+V.x),W-(f+V.y))-U(F.x-V.x,F.y-V.y))%360+360)%360;return st>270?st-360:st},X=(P,L,W,z)=>{const B=z==="arm",Y=se({...P,...B?{rightShoulder:90,rightElbow:0,rightWrist:0}:{rightHip:90,rightKnee:0}},{height:d,facing:p}),V=B?Y.shoulders.right:Y.hip,F=B?{x:(Y.hands.right.x+Y.fingertips.right.x)/2,y:(Y.hands.right.y+Y.fingertips.right.y)/2}:Y.feet.right,U=Math.hypot(F.x-V.x,F.y-V.y)*((B?n.reach?.arm:n.reach?.leg)??1),K=W-(f+V.y),st=Math.abs(K)<U?Math.sqrt(U*U-K*K):U*.1;return L-V.x-p*st},J=P=>{const L=se(P,{height:d,facing:p});return{x:u+(L.hands.right.x+L.fingertips.right.x)/2,y:f+(L.hands.right.y+L.fingertips.right.y)/2}},j=(P,L,W)=>{const z={...P,rightWrist:0,rightElbow:0,rightShoulder:q(P,L,W)},B=se(z,{height:d,facing:p}),Y={x:u+B.shoulders.right.x,y:f+B.shoulders.right.y},V={x:u+B.elbows.right.x,y:f+B.elbows.right.y},F=J(z),U=Math.hypot(V.x-Y.x,V.y-Y.y),K=Math.hypot(F.x-V.x,F.y-V.y),st=Math.min(U+K-.01,Math.max(Math.abs(U-K)+.01,Math.hypot(L-Y.x,W-Y.y))),ot=et=>et*180/Math.PI,rt=ot(Math.acos((U*U+st*st-K*K)/(2*U*st))),at=180-ot(Math.acos((U*U+K*K-st*st)/(2*U*K)));let H={rightShoulder:z.rightShoulder,rightElbow:0},Z=1/0;for(const et of[1,-1])for(const it of[1,-1]){const tt={rightShoulder:z.rightShoulder+et*rt,rightElbow:it*at},lt={...P,rightWrist:0,...tt},Q=J(lt),nt=Math.hypot(Q.x-L,Q.y-W)-se(lt,{height:d,facing:p}).elbows.right.y*.001;nt<Z&&(Z=nt,H=tt)}return H},A=(P,L,W)=>Math.abs(L-u)<2?P:(k.push({time:P,value:u-c},{time:P+W,value:L-c,easing:"ease-in-out"}),u=L,P+W);for(const P of o){const L=Math.max(P.at??w,w===0?0:S[S.length-1].time);let W=L,z,B;const Y=P.pose??{},V=l(P.do);if(r(P.do)){const F=P.to??u,U=F===u?p:C(F);let K=L;U!==p?K=_(L,U,P.mood):g.turn<1?(K=L+ke,O(K,{turn:1,...Y},P.mood)):(P.mood||P.pose)&&O(L+ke,Y,P.mood);const ot=Math.abs(F-u)/Ti(r(P.do),d),rt=P.for??Math.max(ke*2,ot*a(P.do)),at=K+rt;$.push({time:K,value:P.do}),x.push({time:K,value:0},{time:K+ke,value:1,easing:"ease-out"}),x.push({time:at-ke,value:1},{time:at,value:0,easing:"ease-in"}),E.push({time:K,value:m},{time:at,value:m+ot}),k.push({time:K,value:u-c},{time:at,value:F-c}),m+=ot,u=F,O(at,{}),W=at}else if(P.do==="zip"){const F=P.to??u,U=F===u?p:C(F);let K=L;U!==p?K=_(L,U,P.mood):g.turn<1&&(K=L+ke,O(K,{turn:1},P.mood));const st=nl("windUp",{at:K,from:P.mood?_e(g,P.mood):g});S.push(...st),g=st[st.length-1].pose;const ot=K+Rs("windUp"),rt=ot+p5,at=rt+Math.max(y5,Math.abs(F-u)/m5);$.push({time:ot,value:"run"}),x.push({time:ot,value:0},{time:ot+80,value:1,easing:"ease-out"},{time:at,value:1},{time:at+120,value:0}),E.push({time:ot,value:m},{time:rt,value:m+mf,easing:"ease-in"}),m+=mf+(at-rt)/hl.run*1.5,E.push({time:at,value:m}),k.push({time:rt,value:u-c},{time:at,value:F-c,easing:"ease-in"}),I.push({kind:"dust",time:rt,x:u,y:f,length:900}),u=F,O(at,{}),W=at}else if(P.do==="leap"){const F=P.to??u,U=P.onto??f;let K=F===u?L:D(L,F,P.mood);g.turn<1&&(K+=ke,O(K,{turn:1},P.mood));const st={leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50};O(K+b5,{stretch:.75,bend:12,leftHip:22,rightHip:22,...st},P.mood,!1);const ot=K+w5;O(ot-40,{stretch:.72},void 0,!1),O(ot,{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-u,U-f),at=P.for??Math.min(yf[1],Math.max(yf[0],300+rt*k5)),H=Math.min(f,U)-v5*d,Z=Math.sqrt(f-H),et=Math.sqrt(U-H),it=ot+at*Z/(Z+et),tt=ot+at;O(it,{stretch:1,bend:4,leftHip:-55,leftKnee:-80,rightHip:55,rightKnee:80,leftShoulder:110,rightShoulder:110},void 0,!1),O(tt,{stretch:.72,bend:12,leftShoulder:75,rightShoulder:75,leftElbow:0,rightElbow:0,leftHip:18,rightHip:18,leftKnee:0,rightKnee:0},void 0,!1),O(tt+180,{stretch:1.05,bend:-3},void 0,!1),O(tt+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:ot,value:u-c},{time:tt,value:F-c}),y.push({time:ot,value:f-h},{time:it,value:H-h,easing:"ease-out-quad"},{time:tt,value:U-h,easing:"ease-in-quad"}),u=F,f=U,I.push({kind:"dust",time:tt,x:u,y:f,length:500}),W=tt+340,z=tt}else if(P.do==="point"&&P.target){const F=P.target,U=D(L,F.x,P.mood),K={...g,...P.mood?kt[P.mood]:{},turn:Math.max(g.turn,.6),rightElbow:0,rightWrist:0,...Y},st=se(K,{height:d,facing:p}).head.center,ot=Math.abs(F.x-(u+st.x)),rt=F.y-(f+st.y),at=U+we;O(at,{...K,rightShoulder:q(K,F.x,F.y),lookX:1,lookY:N5(rt/Math.max(1,Math.hypot(ot,rt)))*.8}),W=at+(P.for??yl),z=at,B=W}else if(P.do==="swipe"){const F=P.target??{x:u+p*d*.5,y:f-d*.6},U=C(F.x),K=D(L,F.x,P.mood),st=U===1?F.left??F.x:F.right??F.x,ot=U===1?F.right??F.x:F.left??F.x,rt={...g,turn:1,lean:-10,bend:-8,rightElbow:40,lookX:1,...Y};O(K+wo,{...rt,rightShoulder:q(rt,u-p*d*.3,f-d*1.1)},P.mood,!1);const at={...g,lean:6,bend:4,rightElbow:0,rightWrist:0},H={...g,lean:14,bend:12,rightElbow:0,rightWrist:0};A(K,X(at,st,F.y,"arm"),wo+dl),O(K+wo+dl,{lean:-12},void 0,!1);const Z=K+wo+dl+80;O(Z,{...at,rightShoulder:q(at,st,F.y)},void 0,!1);const et=Z+(P.for??Math.max(M5,Math.abs(ot-st)/S5));k.push({time:Z,value:u-c}),u=X(H,ot,F.y,"arm"),k.push({time:et,value:u-c}),O(et,{...H,rightShoulder:q(H,ot,F.y)},void 0,!1),O(et+ul,{lean:16,bend:14,rightShoulder:q(g,ot+U*d*.4,F.y+d*.25)},void 0,!1),O(et+ul+bf,{lean:0,bend:0,rightShoulder:ct.rightShoulder,rightElbow:ct.rightElbow}),W=et+ul+bf,z=Z,B=et}else if(P.do==="grab"&&P.target){const F=P.target,U=D(L,F.x,P.mood),K=F.y>f-d*.5,st={...g,turn:1,rightElbow:0,bend:K?35:0,lean:K?12:0,stretch:K?.75:1,lookX:1,lookY:K?.8:0,...Y},rt=A(U,X(st,F.x,F.y,"arm"),Fs)+T5;O(rt,{...st,rightShoulder:q(st,F.x,F.y)},P.mood,!1),O(rt+120,{},void 0,!1),O(rt+wf,{bend:0,lean:-3,stretch:1,rightShoulder:165,rightElbow:20,lookY:-.6}),W=rt+wf+150,z=rt}else if(P.do==="throw"){const F=P.target?.x??P.to??u+p*d,U=D(L,F,P.mood),K={...g,turn:1,lean:-12,bend:-10,rightElbow:60,stretch:.95,lookX:1,lookY:-.3,...Y};O(U+fl,{...K,rightShoulder:q(K,u-p*d*.4,f-d*1.05)},P.mood,!1),O(U+fl+kf,{lean:-14},void 0,!1);const st=U+fl+kf+E5,ot={...g,lean:14,bend:12,rightElbow:0,stretch:1.04};S.push({time:st,pose:g={...ot,rightShoulder:q(ot,u+p*d,f-d*1.1)},easing:"ease-in",act:!1}),O(st+gl,{lean:18,bend:14,rightShoulder:55,stretch:1},void 0,!1),O(st+gl+vf,{lean:0,bend:0,rightShoulder:ct.rightShoulder,rightElbow:ct.rightElbow,lookY:0}),W=st+gl+vf,z=st,B=st}else if(P.do==="kick"&&P.target){const F=P.target,U=D(L,F.x,P.mood),K={...g,turn:1,lean:-12,bend:-6,rightKnee:0,leftShoulder:100,rightShoulder:70},st=A(U,X(K,F.x,F.y,"leg"),A5),ot={leftShoulder:70,rightShoulder:50,leftElbow:-20,rightElbow:20};O(st+Mf,{turn:1,lean:8,bend:6,rightHip:-40,rightKnee:80,lookX:1,lookY:.7,...ot,...Y},P.mood,!1);const rt=st+Mf+x5,at=q(K,F.x,F.y,"leg");S.push({time:rt,pose:g={...g,...K,rightHip:at},easing:"ease-in",act:!1}),O(rt+pl,{lean:-15,rightHip:at+20},void 0,!1),O(rt+pl+Sf,{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+pl+Sf,z=rt}else if(P.do==="put"&&P.target){const F=P.target,U=D(L,F.x,P.mood),K=F.y>f-d*.5,st={...g,turn:1,rightElbow:0,rightWrist:0,bend:K?35:0,lean:K?12:0,stretch:K?.75:1,lookX:1,lookY:K?.8:0,...Y},rt=A(U,X(st,F.x,F.y,"arm"),Fs)+$5;O(rt,{...st,rightShoulder:q(st,F.x,F.y)},P.mood,!1),O(rt+ml,{},void 0,!1),O(rt+ml+Tf,{bend:0,lean:0,stretch:1,rightShoulder:ct.rightShoulder,rightElbow:ct.rightElbow,lookY:0}),W=rt+ml+Tf,z=rt}else if(P.do==="write"&&P.target){const F=P.target,U=F.left??F.x,K=F.right??F.x,st=D(L,(U+K)/2,P.mood),ot={...g,turn:1,rightElbow:0,rightWrist:0,...kt.thinking,lookX:1,lookY:0,...Y},rt=Q=>X(ot,Q,F.y,"arm")+p*d*.08,at=Q=>{const G=J({...ot,...j(ot,Q,F.y),rightWrist:0});return Math.hypot(G.x-Q,G.y-F.y)<2},H=p===1?U:K,Z=A(st,rt((U+K)/2),Fs),et=!at(U)||!at(K),it=et?A(Z,rt(U),Fs)+Ef:Z+Ef;O(it,{...ot,...j(ot,et?U:H,F.y)},P.mood,!1);const tt=P.for??Math.max(I5,Math.abs(K-U)*P5);et&&k.push({time:it,value:u-c});for(let Q=Af,G=0;Q<=tt;Q+=Af,G++){const nt=U+(K-U)*Math.min(Q,tt)/tt;et&&(u=rt(nt),k.push({time:it+Q,value:u-c}));const ht=(G%2===0?-1:1)*d*.02;O(it+Q,j(ot,nt,F.y+ht),void 0,!1)}const lt=it+tt;O(lt,j(ot,K,F.y),void 0,!1),O(lt+xf,{rightShoulder:ct.rightShoulder,rightElbow:ct.rightElbow,...kt.happy}),W=lt+xf,z=it,B=lt}else if(P.do==="push"&&P.target){const F=P.target,U=P.to??F.x,K=D(L,u+(U>=F.x?1:-1),P.mood),st=p===1?F.left??F.x:F.right??F.x,ot={...g,turn:1,lean:16,bend:8,rightWrist:0,leftWrist:0,lookX:1,...Y},rt=X(ot,st,F.y,"arm"),at=A(K,rt+p*d*.06,Fs),H=j(ot,st,F.y),Z={...ot,...H,leftShoulder:-H.rightShoulder,leftElbow:-H.rightElbow},et=at+O5;O(et,Z,P.mood,!1);const it=Math.abs(U-F.x),tt=et+(P.for??Math.max(600,it/_5)),lt=it/Ti("shove",d);$.push({time:et,value:"shove"}),x.push({time:et,value:0},{time:et+ke,value:1,easing:"ease-out"},{time:tt-ke,value:1},{time:tt,value:0,easing:"ease-in"}),E.push({time:et,value:m},{time:tt,value:m+lt}),m+=lt,k.push({time:et,value:u-c},{time:tt,value:u+(U-F.x)-c}),u+=U-F.x,O(tt,{},void 0,!1),O(tt+$f,{lean:0,bend:0,rightShoulder:ct.rightShoulder,leftShoulder:ct.leftShoulder,rightElbow:ct.rightElbow,leftElbow:ct.leftElbow}),W=tt+$f,z=et,B=tt}else if(V){const F=P.mood?_e(g,P.mood):g,U=V.steps(F,P),K=sl(U,{at:L,from:F});S.push(...K),g=K[K.length-1].pose,W=L+Math.max(pf(U),P.for??0)}else if(Pf(P.do)){const F=nl(P.do,{at:L,from:P.mood?_e(g,P.mood):g});S.push(...F),g=F[F.length-1].pose,W=L+Rs(P.do),P.do==="take"&&I.push({kind:"dust",time:L+900,x:u,y:f,length:500}),P.do==="land"&&I.push({kind:"dust",time:L+120,x:u,y:f,length:500})}else if(P.do==="look"||P.do==="face"){const F=P.toward??"viewer",U=P.for??C5;if(F==="viewer")O(L+we,{turn:0,lookX:0,lookY:0,...Y},P.mood);else if(F==="ahead")O(L+we,{turn:P.do==="face"?1:.6,lookX:1,...Y},P.mood);else if(F==="back")O(L+we,{turn:.2,lookX:-1,...Y},P.mood);else{const K=C(F);K!==p&&P.do==="face"?(_(L,K,P.mood),O(L+Bn+1,{lookX:1,...Y})):K!==p?O(L+we,{turn:.25,lookX:-1,...Y},P.mood):O(L+we,{turn:P.do==="face"?1:.6,lookX:1,...Y},P.mood)}W=L+Math.max(U,we)}else if(L5(P.do)||P.do==="stand"){const F=P.do==="stand"?n.rest??ct:Yt[P.do],U=F.turn!==ct.turn?F.turn:g.turn,K=P.mood?kt[P.mood]:{lookX:g.lookX,lookY:g.lookY};O(L+we,{...F,turn:U,...K,...Y}),W=L+(P.for??yl)}else{const F=P.for??(P.say?If(P.say):yl);(P.mood||P.pose)&&O(L+Math.min(we,F/2),Y,P.mood),W=L+F}if(P.say){const F=r(P.do)||Pf(P.do)||V?L:L+Math.min(150,(W-L)/4),U=r(P.do)?W:Math.max(F+200,W-100);v.push({text:P.say,start:F,end:U}),P.do==="say"&&W5(S,g,F,U)}P.onto!==void 0&&P.do!=="leap"&&P.onto!==f&&(y.push({time:L,value:f-h},{time:W,value:P.onto-h,easing:"ease-in-out"}),f=P.onto),W>S[S.length-1].time&&S.push({time:W,pose:g}),T.push({start:L,end:W,...z!==void 0?{contact:z}:{},...B!==void 0?{release:B}:{}}),w=W}const R=tf(t,F5(S),n),N=[{id:`${t}-x`,target:t,property:"x",keyframes:k},{id:`${t}-y`,target:t,property:"y",keyframes:y},{id:`${t}-walk`,target:t,property:"walk",keyframes:E},{id:`${t}-walking`,target:t,property:"walking",keyframes:x},{id:`${t}-gait`,target:t,property:"gait",keyframes:$},{id:`${t}-facing`,target:t,property:"facing",keyframes:M}].filter(P=>P.keyframes.length>1||P.property==="x"||P.property==="facing"&&P.keyframes[0].value===-1);return{tracks:[...ol(t,R,v,{energy:n.energy}),...N],duration:w,lines:v,keys:S,beats:T,effects:I}}const N5=t=>Math.max(-1,Math.min(1,t)),D5=30;function F5(t){const e=[];for(const n of t){const s=e[e.length-1];s&&n.time-s.time<D5?e[e.length-1]={...n,time:s.time}:e.push(n)}return e}function W5(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 bl(t,e,n){const s=new Ot({id:`${t}-hand`,tracks:e.filter(l=>l.target===t)}),i=Wr({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}=Br(i,{time:l,state:s.getStateAtTime(l)},t),h=c.hands[o],d=c.fingertips[o];if(a.push({time:l,x:(h.x+d.x)/2,y:(h.y+d.y)/2}),l>=n.end)break}return a}const qn=["start","contact","release","end"],B5=["surface","edit","anchor","at","until"],q5=["carry"],vo=t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&"surface"in t&&"anchor"in t,z5=t=>t.then===void 0?[]:Array.isArray(t.then)?t.then:[t.then];function Y5(t,e,n,s={}){const i=Of(n,e,s).filter(u=>u.level==="error");if(i.length>0)throw new Error(`surfaceScript: ${i.length} problem(s) in the beats:
59
- ${i.map(u=>` ${u.beat>=0?`beat ${u.beat}: `:""}${u.message}`).join(`
60
- `)}`);const o=n.map(u=>_f(u,e)),r=ko(t,o,s),a=K5(o,r.beats,s),l=s.ground??0,c=u=>s.ride===!1?u:Object.values(e).reduce((f,p)=>p.ride(f,t,{ground:l}),u);n.forEach((u,f)=>{for(const p of z5(u)){const g=y=>new Error(`surfaceScript: beat ${f} (${u.do}), ${p.edit} on ${p.surface}: ${y}`),m=(y,E)=>{const x=typeof y=="object"?y.beat:f,$=(typeof y=="object"?y.at:y)??E??"start",M=a[x][$];if(M===void 0){const v=qn.filter(T=>a[x][T]!==void 0).join(", ");throw g(`beat ${x} (${n[x].do}) has no ${$} (it has ${v})`)}return M},w=e[p.surface],S=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<S)throw g(`it ends (${k} ms) before it starts (${S} ms)`);try{if(p.edit==="carry"){const E=w.piece(p.anchor),x=bl(t,c(r.tracks),{x:s.from??0,y:l,style:s.figureStyle??(s.height?{height:s.height}:void 0),cast:s,start:S,end:k});w.follow(E,x);continue}const y=Object.fromEntries(Object.entries(p).filter(([E])=>!B5.includes(E)));w.edit(p.edit,p.anchor,{...y,at:S,...k!==void 0?{duration:k-S}:{}})}catch(y){throw g(y.message)}}});const h=c(r.tracks),d=Object.entries(e).flatMap(([u,f])=>f.tracks(u));return{...r,tracks:[...h,...d],figureTracks:h}}function Of(t,e,n={}){if(!Array.isArray(t))return Ds(t,n);const s=[],i=Object.keys(e),o=(c,h,d)=>{const u=typeof h=="string"?e[h]:void 0;return u||s.push({level:"error",beat:c,message:`${d}: ${dt("surface",h,i)}`}),u},r=(c,h,d,u)=>{if(typeof d!="string"){s.push({level:"error",beat:c,message:`${u}: \`anchor\` is a place name such as ${Object.keys(h.about.anchors).join(", ")} (got ${JSON.stringify(d)}).`});return}try{h.anchor(d,0)}catch(f){s.push({level:"error",beat:c,message:`${u}: ${f.message}`})}},a=(c,h,d)=>{const u=typeof h=="object"&&h!==null?h.at:h;if(typeof h=="object"&&h!==null){const f=h.beat;if((typeof f!="number"||!Number.isInteger(f)||f<c||f>=t.length)&&s.push({level:"error",beat:c,message:`${d}: \`beat\` is the index of this beat or a later one, ${c} to ${t.length-1} (got ${JSON.stringify(f)}).`}),u===void 0)return}typeof u=="number"?s.push({level:"error",beat:c,message:`${d}: a cue starts at a moment of its beat (${qn.join(", ")}), not at ms; set the beat's own \`at\` to move it.`}):(typeof u!="string"||!qn.includes(u))&&s.push({level:"error",beat:c,message:`${d}: ${dt("moment",u,qn)}`})};t.forEach((c,h)=>{if(!c||typeof c!="object"||Array.isArray(c))return;const d=c;for(const f of["target","to","onto"]){if(!vo(d[f]))continue;const p=d[f],g=o(h,p.surface,`\`${f}\``);g&&r(h,g,p.anchor,`\`${f}\``)}if(d.then===void 0)return;(Array.isArray(d.then)?d.then:[d.then]).forEach(f=>{if(!f||typeof f!="object"||Array.isArray(f)){s.push({level:"error",beat:h,message:"`then` is a cue, { surface, edit, anchor, at?, until? }, or a list of them."});return}const 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),...q5];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 S of Array.isArray(p.anchor)?p.anchor:[p.anchor])r(h,g,S,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)?_f(c,e,!0):c);return[...Ds(l,n),...s]}function _f(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 vo(t.target)&&(r.target=o(t.target)),vo(t.to)&&(r.to=o(t.to).x),vo(t.onto)&&(r.onto=o(t.onto).top),r}function K5(t,e,n){let s=0;return t.map(i=>{const o=bo([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 j5(t){const e={actions:t.actions,gaits:t.gaits},n=al(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}": ${dt("gait",i,s)}`);if(t.mood&&!(t.mood in kt))throw new Error(`persona "${t.name}": ${dt("mood",t.mood,Object.keys(kt))}`);const o=t.acting??"snappy";if(typeof o=="string"&&!(o in rn))throw new Error(`persona "${t.name}": ${dt("acting style",o,Object.keys(rn))}`);if(typeof t.stance=="string"&&!(t.stance in Yt))throw new Error(`persona "${t.name}": ${dt("stance",t.stance,Object.keys(Yt))}`);const r=t.height??120,a=typeof t.stance=="string"?Yt[t.stance]:Ct(t.stance??{}),l=t.mood?_e(a,t.mood):a,c={...t.look,height:r},h=t.summary??`${t.name}, a stick figure`;return{name:t.name,summary:h,cast:e,rest:l,height:r,figure:d=>Wr({x:d.x,y:d.y,pose:l,style:{...c,...d.facing?{facing:d.facing}:{}},cast:e}),script:(d,u,f={})=>ko(d,u,{...e,from:f.from,ground:f.ground,facing:f.facing,height:r,style:o,gait:i,start:l,rest:l,energy:t.energy}),check:d=>Ds(d,e),handPath:(d,u,f)=>bl(d,u,{...f,style:c,cast:e}),describe:()=>({name:t.name,summary:h,habits:{height:r,acting:typeof o=="string"?o:"custom",gait:i,...t.mood?{mood:t.mood}:{},stance:typeof t.stance=="string"?t.stance:t.stance?"custom":"rest"},actions:ll(e),own:{actions:Object.keys(t.actions??{}),gaits:Object.keys(t.gaits??{})}})}}const X5=new Set(["x","y","walking","gait"]),Cf=.215+.205;function Hf(t,e,n=1){const{points:s}=te(t,gt),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):Cf*t.height;return pa(e,a/Cf,n)}function G5(t,e,n,s={}){const i=ko(t,n,{...s,height:e.height,reach:s.reach??Rf(e)}),o=i.tracks.find(w=>w.property==="facing")?.keyframes??[],r=w=>{let S=s.facing??1;for(const k of o)k.time<=w&&(S=k.value);return S},a=xi(i.keys),l=i.keys.map((w,S)=>{const k=od(a[S]);return{time:w.time,pose:r(w.time)<0?nd(k):k,...w.easing?{easing:w.easing}:{},...w.act===!1?{act:!1}:{}}}),{rest:c,start:h,...d}=s;J5(l,a,n,i,e,r,s);const u=ef(t,l,d),f=ol(t,u,i.lines,{energy:s.energy}),p=i.tracks.filter(w=>X5.has(w.property)),g=i.tracks.find(w=>w.property==="walk");return{tracks:g?[...f,...p,sv(t,g,i.tracks,e,s)]:[...f,...p],duration:i.duration,lines:i.lines,keys:l,beats:i.beats,effects:i.effects}}function Rf(t){const e=bt({"arm.left.spread":90,"arm.left.elbow":0,"arm.left.bend":0,"leg.left.knee":0}),n=te(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=se({...ct,rightShoulder:90,rightElbow:0,rightWrist:0},{height:t.height,facing:1}),r=se({...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 U5={point:"arm",grab:"arm",put:"arm",write:"arm",swipe:"arm",push:"arm",kick:"leg"},V5=new Set(["point","grab","put","kick"]);function J5(t,e,n,s,i,o,r){const a=s.beats;if(n.length!==a.length)return;const l=new Ot({id:"placed",tracks:s.tracks.filter(h=>h.property==="x"||h.property==="y")}),c=h=>{const d=l.getStateAtTime(h).values.get(s.tracks[0]?.target??"");return{x:(r.from??0)+Number(d?.get("x")??0),y:(r.ground??0)+Number(d?.get("y")??0)}};n.forEach((h,d)=>{const u=U5[h.do],f=a[d];if(!u||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 S=o(m.time),k=se(e[w],{height:i.height,facing:S<0?-1:1}),y=c(m.time),E=V5.has(h.do)&&h.target?{x:h.target.x-y.x,y:h.target.y-y.y}:void 0,x={x:(k.hands.right.x+k.fingertips.right.x)/2,y:(k.hands.right.y+k.fingertips.right.y)/2},$=E??(u==="arm"?x:k.toes.right),M=S<0?"right":"left",v=`${u}.${M}`;let T=m.pose;if(h.do==="point")T=ye(i,T,v,$);else if(u==="arm")T=ye(i,nv(i,T,M,$),v,$);else for(let I=0;I<3;I++){const O=te(i,T).points,_=O[`ankle.${M}`],C=O[`toe.${M}`];T=ye(i,T,v,{x:$.x-(C.x-_.x),y:$.y-(C.y-_.y)})}t[w]={...m,pose:T}})})}function Z5(t,e){const n=bt({[`arm.${e}.spread`]:90,[`arm.${e}.elbow`]:0,[`arm.${e}.bend`]:0}),s=te(t,n).points;return Math.hypot(s[`hand.${e}`].x-s[`shoulder.${e}`].x,s[`hand.${e}`].y-s[`shoulder.${e}`].y)}const Q5=5,tv=4,ev=8;function nv(t,e,n,s){const i=Z5(t,n)*.9,o=a=>{const l=te(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<=ev;a++)if(r={...e,lean:(e.lean??0)+Q5*a,bend:(e.bend??0)+tv*a},o(r))return r;return r}function sv(t,e,n,s,i){const o=n.find(d=>d.property==="gait"),r=o?new Ot({id:`${t}-gait-of`,tracks:[o]}):void 0,a=d=>{const u=r?.getStateAtTime(d).values.get(t)?.get("gait");if(typeof u=="string")return Dt[u]??i.gaits?.[u]??u},l=e.keyframes,c=[];let h=l[0]?.value??0;return l.forEach((d,u)=>{if(u>0){const f=l[u-1],p=a((f.time+d.time)/2),g=Ti(p,s.height),m=Hf(s,p);h+=(d.value-f.value)*(m>0?g/m:1)}else h=d.value;c.push({...d,value:h})}),{...e,keyframes:c}}const pt=["rect","circle","text","line","path","image","custom"],Mo={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}},wl={fillStyle:"fill",strokeStyle:"stroke",lineWidth:"strokeWidth",rotateZ:"rotate",motionPathX:"x",motionPathY:"y",motionPathRotate:"rotate"},iv={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 Lf(t){const e=t,n=Object.entries(Mo).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 Nf(t){const e=Lf(t).properties.map(n=>n.name);return[...e,...Object.keys(wl).filter(n=>e.includes(wl[n]))]}function ov(t,e){const n=[],s=Object.keys(e);for(const i of t){const o=u=>n.push({level:"error",track:i.id,message:u}),r=e[i.target];if(!r){o(dt("target",i.target,s));continue}const a=Nf(r),l=r.type==="custom"&&r.acceptsProp?.(i.property);if(!a.includes(i.property)&&!l){o(`${i.target}: ${dt("property",i.property,a,iv[i.property])}`);continue}const c=i.keyframes??[];for(let u=1;u<c.length;u++)c[u].time<c[u-1].time&&o(`${i.target}.${i.property}: keyframes out of time order (${c[u-1].time} ms, then ${c[u].time} ms).`);const h=Mo[wl[i.property]??i.property]??r.about?.props?.[i.property],d=h&&(h.kind??"number")==="number";for(const u of c){if(d&&typeof u.value!="number"){o(`${i.target}.${i.property}: values are numbers${h.unit?` (${h.unit})`:""} (got ${JSON.stringify(u.value)} at ${u.time} ms).`);break}if(d&&typeof u.value=="number"&&(h.min!==void 0&&u.value<h.min||h.max!==void 0&&u.value>h.max)){n.push({level:"warning",track:i.id,message:`${i.target}.${i.property}: ${u.value} at ${u.time} ms is outside ${h.min??"−∞"}..${h.max??"∞"}${h.unit?` (${h.unit})`:""}.`});break}}}return n}const zn=(t,e)=>t[2]<=-e;function kl(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 Df(t,e){if(t.every(s=>zn(s,e)))return t;const n=[];return t.forEach((s,i)=>{const o=t[(i+t.length-1)%t.length],r=zn(s,e),a=zn(o,e);r!==a&&n.push(kl(o,s,e)),r&&n.push(s)}),n.length>=3?n:[]}function rv(t,e){if(t.every(i=>zn(i,e)))return[t];const n=[];let s=[];return t.forEach((i,o)=>{const r=zn(i,e);if(o>0){const a=t[o-1],l=zn(a,e);l&&!r?(s.push(kl(a,i,e)),n.push(s),s=[]):!l&&r&&s.push(kl(a,i,e))}r&&s.push(i)}),s.length>0&&n.push(s),n.filter(i=>i.length>=2)}function Ff(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 av(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 lv(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=>Bt(e,s)),faces:t.faces.map(s=>({corners:s.corners,normal:n(s.normal)}))}}function So(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 cv(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},d=[],u=p=>p===0,f=(p,g)=>p+2===g.length;for(const p of s){let g=p.points;u(r)||(g=So(g,0,e[r],1)),g.length&&!f(r,e)&&(g=So(g,0,e[r+1],-1)),g.length&&!u(a)&&(g=So(g,2,n[a],1)),g.length&&!f(a,n)&&(g=So(g,2,n[a+1],-1)),g.length>=3&&d.push({corners:g.map(h),normal:p.normal})}d.length>0&&i.push({cell:[r,a],mesh:{vertices:l,faces:d,creases:t.creases,joined:t.joined,walls:o}})}return i}const hv=new WeakMap,dv=new WeakMap,uv=48,Wf=t=>t.map(e=>Math.round(e*1e5)).join(",");function Bf(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>=uv&&i.clear(),i.set(n,o=s())),o}function vl(t,e){const n=Wf(e);return Bf(hv,t,n,()=>{const s=lv(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 fv(t,e){const n=t.map(h=>({...h,...vl(h.mesh,h.local)})),s=[1/0,1/0,1/0],i=[-1/0,-1/0,-1/0];for(const h of n)for(const d of[0,1,2])s[d]=Math.min(s[d],h.low[d]),i[d]=Math.max(i[d],h.high[d]);const o=Ff(s[0],i[0],e),r=Ff(s[2],i[2],e),a=`${o.join(",")}|${r.join(",")}`,l=n.flatMap(h=>{if(h.high[0]-h.low[0]<=e*2.5&&h.high[2]-h.low[2]<=e*2.5||h.whole||h.mesh.joined||(h.mesh.marks?.length??0)>0){const u=[(h.low[0]+h.high[0])/2,(h.low[1]+h.high[1])/2,(h.low[2]+h.high[2])/2];return[{part:h.part,mesh:h.mesh,cut:!1,cell:av(o,r,u)}]}return Bf(dv,h.inSpace,a,()=>cv(h.inSpace,o,r)).map(u=>({part:h.part,mesh:u.mesh,cut:!0,cell:u.cell}))}),c=(s[1]+i[1])/2;return{pieces:l,middle:([h,d])=>[(o[h]+o[h+1])/2,c,(r[d]+r[d+1])/2]}}const qf=.004,Ml=.05,zf=new WeakMap;function gv(t){let e=zf.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)}),zf.set(t,e)),e}const Yf=new WeakMap;function Kf(t){return t.filter(({mesh:e})=>gv(e)).map(({part:e,key:n,inSpace:s,low:i,high:o})=>{let r=Yf.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]}}),Yf.set(s,r)),{part:e,key:n,planes:r,low:i,high:o}})}function pv(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]-Ml||i[a]>o.high[a]+Ml))continue;if(o.planes.every(a=>{const l=a.normal[0]*n[0]+a.normal[1]*n[1]+a.normal[2]*n[2],c=e.map(d=>a.normal[0]*d[0]+a.normal[1]*d[1]+a.normal[2]*d[2]-a.offset);if(c.every(d=>Math.abs(d)<=qf))return l<-.9;const h=Math.abs(l)<.5?Ml:qf;return c.every(d=>d<=h)}))return!0}return!1}const jf=new WeakMap;function Xf(t,e,n,s,i){const o=`${s}|${i.map(l=>l.key).join(";")}`;let r=jf.get(e);r||jf.set(e,r=new Map);let a=r.get(o);if(!a){r.size>=48&&r.clear();const l=h=>{const d=[n[0]*h[0]+n[4]*h[1]+n[8]*h[2],n[1]*h[0]+n[5]*h[1]+n[9]*h[2],n[2]*h[0]+n[6]*h[1]+n[10]*h[2]],u=Math.hypot(...d)||1;return[d[0]/u,d[1]/u,d[2]/u]},c=e.vertices.map(h=>Bt(n,h));a=e.faces.map(h=>pv(t,h.corners.map(d=>c[d]),l(h.normal),i)),r.set(o,a)}return a}const Yn={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}},Sl=Math.PI/180;function Gf(t,e,n){return{toView:s=>Gr(He(s,t*90*Sl),-e*Sl),toScreen:s=>({x:s[0]*n,y:-s[1]*n})}}const Uf=new WeakMap,Ws=t=>To(t),To=t=>{let e=Uf.get(t);return e||Uf.set(t,e=Eu(t)),e};function Et(t,e,n){return e[n]??t.controls[n]?.default??Yn[n]?.default??0}function Bs(t,e){const n=Math.max(.05,Et(t,e,"squash")),s=1/Math.sqrt(n),o=[1,0,0,0,0,1,Et(t,e,"lean"),0,0,0,1,0,0,0,0,1];return[Ge([0,Et(t,e,"lift"),0]),ne(Xt([1,0,0],-Et(t,e,"pitch"))),ne(Xt([0,0,1],Et(t,e,"roll"))),o,Ue([s,n,s]),Ue(Array(3).fill(Math.max(0,Et(t,e,"size"))))].reduce((r,a)=>At(r,a))}function Tl(t,e){const n=Bs(t,e),s=new Map,i=Object.entries(t.controls).flatMap(([r,a])=>(a.bind??[]).map(l=>({value:Et(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=At(l?o(l):n,Ge(r.at??[0,0,0]));if(r.rotate){const[h,d,u]=r.rotate;h&&(c=At(c,ne(Xt([1,0,0],h)))),d&&(c=At(c,ne(Xt([0,1,0],d)))),u&&(c=At(c,ne(Xt([0,0,1],u))))}for(const{value:h,bind:d}of i)if(!(!d.parts.includes(r.id)||h===0)){if(d.translate&&(c=At(c,Ge([d.translate[0]*h,d.translate[1]*h,d.translate[2]*h]))),d.rotate){const u=d.rotate.pivot??[0,0,0],f=d.rotate.axis==="x"?[1,0,0]:d.rotate.axis==="y"?[0,1,0]:[0,0,1];c=[c,Ge(u),ne(Xt(f,d.rotate.degrees*h)),Ge([-u[0],-u[1],-u[2]])].reduce((p,g)=>At(p,g))}d.scale&&(c=At(c,Ue([1+(d.scale[0]-1)*h,1+(d.scale[1]-1)*h,1+(d.scale[2]-1)*h])))}return s.set(r.id,c),c};for(const r of t.parts)o(r);return s}const El=(()=>{const t=[-.45,.75,.5],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),mv=Math.cos(35*Sl);function Al(t,e,n,s,i={}){const o=t.derive?{...e,...t.derive(e)}:e,r=Tl(t,o),a=n.toView([0,0,0]),l=C=>D=>[C[0]*D[0]+C[4]*D[1]+C[8]*D[2],C[1]*D[0]+C[5]*D[1]+C[9]*D[2],C[2]*D[0]+C[6]*D[1]+C[10]*D[2]],c=Bs(t,o),h=i.slice===void 0?null:lr(c),d=h?t.parts.map(C=>({part:C,mesh:To(C.shape),local:At(h,r.get(C.id)),whole:C.shape.type==="tube"})):void 0,u=d?fv(d,i.slice):void 0,f=d?Kf(d.map(C=>({part:C.part.id,mesh:C.mesh,...vl(C.mesh,C.local)}))):void 0,p=(C,D,q,X)=>{const J=G=>n.toView(Bt(q,G)),j=D.vertices.map(J),A=j.map(G=>n.toScreen(G)),R=i.perspective?i.near:void 0,N=G=>G.map(nt=>n.toScreen(nt)),P=G=>R===void 0?G:Df(G,R),L=G=>R===void 0?[G]:rv(G,R),W=l(q),z=D.faces.map(G=>{const nt=n.toView(W(G.normal)),ht=[nt[0]-a[0],nt[1]-a[1],nt[2]-a[2]],ft=Math.hypot(...ht)||1;return[ht[0]/ft,ht[1]/ft,ht[2]/ft]}),B=f&&X?Xf(C.id,D,X,Wf(X),f):void 0,Y=G=>B?.[G]??!1,V=z.map((G,nt)=>{if(Y(nt))return!1;if(!i.perspective)return G[2]>1e-6;const ft=D.faces[nt].corners.reduce((wt,mt)=>[wt[0]+j[mt][0],wt[1]+j[mt][1],wt[2]+j[mt][2]],[0,0,0]);return-(G[0]*ft[0]+G[1]*ft[1]+G[2]*ft[2])>1e-9}),F=G=>D.faces[G].corners.reduce((nt,ht)=>nt+j[ht][2],0)/D.faces[G].corners.length,U=D.faces.map((G,nt)=>({face:G,i:nt})).filter(({i:G})=>V[G]).map(({face:G,i:nt})=>({i:nt,solved:{points:R===void 0?G.corners.map(ht=>A[ht]):N(P(G.corners.map(ht=>j[ht]))),depth:F(nt),tone:.72+.33*Math.max(0,z[nt][0]*El[0]+z[nt][1]*El[1]+z[nt][2]*El[2])}})).filter(G=>G.solved.points.length>=3).sort((G,nt)=>G.solved.depth-nt.solved.depth);if(i.light){const G=l(q);for(const{i:nt,solved:ht}of U){const ft=D.faces[nt].corners,wt=ft.reduce((Bl,eS)=>{const ql=Bt(q,D.vertices[eS]);return[Bl[0]+ql[0]/ft.length,Bl[1]+ql[1]/ft.length,Bl[2]+ql[2]/ft.length]},[0,0,0]),mt=G(D.faces[nt].normal),ee=Math.hypot(...mt)||1,Ys=i.light(wt,[mt[0]/ee,mt[1]/ee,mt[2]/ee]);ht.light=Ys.light,ht.fog=Ys.fog}}const K=U.map(G=>G.solved),st=yv(D),ot=[],rt=[];for(const[G,nt]of st){const ht=nt.filter(wt=>V[wt]).length;if(ht===0)continue;const ft=nt.length===2&&ht===2&&D.creases!==!1&&z[nt[0]][0]*z[nt[1]][0]+z[nt[0]][1]*z[nt[1]][1]+z[nt[0]][2]*z[nt[1]][2]<mv;nt.length===1&&(D.joined||bv(D,G))||(nt.length===1||ht===1||ft)&&(ot.push(G.split("-").map(Number)),rt.push(nt.filter(wt=>V[wt]).reduce((wt,mt)=>F(mt)>F(wt)?mt:wt)))}const at=G=>D.faces.findIndex(nt=>nt.corners.length>4&&Math.sign(kv(D.vertices[G],nt.normal))>0),H=(D.marks??[]).filter(([G])=>at(G)<0||V[at(G)]),Z=([G,nt])=>R===void 0?[[A[G],A[nt]]]:L([j[G],j[nt]]).map(N),et=H.flatMap(Z),it=G=>R===void 0?[G.map(nt=>A[nt])]:L(G.map(nt=>j[nt])).map(N);if(i.slice!==void 0){const G=new Map;ot.forEach((nt,ht)=>G.set(rt[ht],[...G.get(rt[ht])??[],nt]));for(const{i:nt,solved:ht}of U){ht.edges=Qf(G.get(nt)??[]).flatMap(it);const ft=D.faces[nt].corners;ht.center=ft.reduce((mt,ee)=>[mt[0]+j[ee][0]/ft.length,mt[1]+j[ee][1]/ft.length,mt[2]+j[ee][2]/ft.length],[0,0,0]),ht.normal=z[nt];const wt=U[U.length-1].i;ht.marks=H.filter(([mt])=>(at(mt)>=0?at(mt):wt)===nt).flatMap(Z)}}const tt=C.glow?Math.max(0,Math.min(1,Et(t,o,C.glow.control))):0,lt=C.fade?Math.max(0,Math.min(1,Et(t,o,C.fade.control))):0,Q=C.fade?Math.max(0,Math.min(1,C.fade.from+(C.fade.to-C.fade.from)*lt)):1;return{part:C,depth:j.reduce((G,nt)=>G+nt[2],0)/Math.max(1,j.length),faces:K,edges:Qf(ot).flatMap(it),marks:et,glow:tt,opacity:Q,...C.shape.type==="tube"?{spine:wv(L(C.shape.points.map(J)).map(N))}:{},...D.walls?{cut:!0}:{}}},g=new Map(d?.map(C=>[C.part.id,C.local])),w=(u?u.pieces.map(C=>({part:C.part,mesh:C.mesh,m:C.cut?c:r.get(C.part.id),local:C.cut?ci():g.get(C.part.id),cell:C.cell})):t.parts.map(C=>({part:C,mesh:To(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)})),S=w.map(C=>C.solved),k=C=>C.filter(D=>D.faces.length>0&&D.opacity>.01).sort((D,q)=>D.depth-q.depth);let y;if(u){const C=new Map(t.parts.map(q=>{const X=r.get(q.id),J=To(q.shape).vertices;return[q.id,J.reduce((j,A)=>j+n.toView(Bt(X,A))[2],0)/Math.max(1,J.length)]})),D=new Map;for(const q of w){const X=q.cell.join(",");D.has(X)||D.set(X,{cell:q.cell,parts:[]}),D.get(X).parts.push(q.solved),q.solved.depth=C.get(q.solved.part.id)}y=[...D.values()].map(({cell:q,parts:X})=>({depth:n.toView(Bt(c,u.middle(q)))[2],parts:k(X)})).filter(q=>q.parts.length>0)}const E={};for(const[C,D]of Object.entries(t.anchors??{})){const q=D.part?r.get(D.part):Bs(t,o);if(!q)throw new Error(`prop rig: anchor "${C}" is on "${D.part}", which is not a part`);const X=n.toView(Bt(q,D.at));E[C]={point:n.toScreen(X),depth:X[2]}}const[x,$]=t.footprint??[t.length*.45,t.length],M=Math.max(0,Et(t,o,"lift")),v=Math.max(0,Et(t,o,"size"))/(1+M*.8),T=Array.from({length:24},(C,D)=>{const q=Math.PI*2*D/24;return n.toView([Math.cos(q)*x*.55*v,0,Math.sin(q)*$*.55*v])}),I=i.perspective?i.near:void 0,O={points:(I===void 0?T:Df(T,I)).map(C=>n.toScreen(C)),opacity:.16*v},_=S.filter(C=>C.part.seeThrough&&C.opacity>.01).flatMap(C=>C.faces.map(D=>D.points));return{under:k(S.filter(C=>!C.part.overRider)),over:k(S.filter(C=>C.part.overRider)),...y?{cells:y}:{},anchors:E,openings:_,shadow:O,pxPerUnit:s,sizePx:t.height*s}}const Vf=new WeakMap;function yv(t){let e=Vf.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])}}Vf.set(t,e)}return e}function Jf(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=Tl(t,n),i=lr(Bs(t,n))??ci(),o=r=>Math.max(0,Math.min(1,r));return t.parts.map(r=>{const a=r.fade?o(Et(t,n,r.fade.control)):0;return{part:r,matrix:s.get(r.id),local:At(i,s.get(r.id)),glow:r.glow?o(Et(t,n,r.glow.control)):0,opacity:r.fade?o(r.fade.from+(r.fade.to-r.fade.from)*a):1}})}function Zf(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=Tl(t,n),i=Bs(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]=Bt(l,a.at)}return o}function bv(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 wv(t){return t.reduce((e,n)=>!e||n.length>e.length?n:e,void 0)}const kv=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2];function Qf(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 xl(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 $l(t){const e={};for(const[n,s]of Object.entries({...Yn,...t.rig.controls})){const{bind:i,...o}=s;e[n]=o}return e}function tg(t){const{prop:e}=t,n=t.scale??60,s=e.rig.length*n*1.4,i=e.rig.height*n*1.6,o=$l(e),r={};for(const[l,c]of Object.entries(o))r[l]=t.values?.[l]??c.default??0;const a={look:t.look,ink:t.ink,lineWidth:t.lineWidth,pencil:t.pencil,seed:t.seed,style:t.style,paper:t.paper};return{type:"custom",x:t.x-s/2,y:t.y-i,width:s,height:i,props:r,prop:e,propScale:n,propDraw:a,about:{kind:e.kind,summary:e.summary,props:o,actions:Object.fromEntries(Object.entries(e.actions).map(([l,c])=>[l,c.summary]))},draw(l,c,h){const d=c.props??{};l.translate(s/2,i),$a(l,Kn(e,d,n),{...a,time:h,loose:xl(c,d)})}}}function Kn(t,e,n){const s=Gf(Et(t.rig,e,"turn"),Et(t.rig,e,"tilt"),n);return Al(t.rig,e,s,n)}function Eo(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=Kn(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 vv(t,e,n,s,i={}){const o=Eo(e,n,s);return t.save(),t.translate(o.origin.x,o.origin.y),$a(t,o.solved,{...e.propDraw,time:n.time,loose:xl(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 jn={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"}},Mv=400,Sv=.2;function Tv(t,e={}){const{prop:n}=t,s=$l(n),i=Object.keys(s),o=Object.keys(n.rig.anchors??{}),r=n.rig.parts.map(x=>x.id),a=Nn(),l=Ps(a),c=e.tracks?.length?new Ot({id:`${n.kind}-surface`,tracks:e.tracks}):void 0,h=Math.max(0,...(e.tracks??[]).flatMap(x=>x.keyframes.map($=>$.time))),d=new Map,u=new Map;t.loose=u;const f=t.props,p=x=>{const $={...t.props};let M=0,v=0;if(c){const T=c.getStateAtTime(Math.min(x,h));for(const I of T.values.values())for(const[O,_]of I)typeof _=="number"&&(O==="x"?M=_:O==="y"?v=_:O in $&&($[O]=_))}for(const T of i)a.keys(T)?.length&&($[T]=a.valueAt(T,x));return{values:$,origin:{x:t.x+t.width/2+M,y:t.y+t.height+v}}},g=x=>{const{kind:$,rest:M}=nn(x),v=T=>De(n.kind,x,jn,T);if($==="box"){if(M)throw v("box takes no arguments");return{kind:$}}if($==="anchor"){if(!o.includes(M))throw v(dt(`${n.kind} anchor`,M,o));return{kind:$,name:M}}if($==="part"){if(!r.includes(M))throw v(dt(`${n.kind} part`,M,r));return{kind:$,name:M}}if($==="control"){if(!i.includes(M))throw v(dt(`${n.kind} control`,M,i));return{kind:$,name:M}}throw v()},m=x=>{const $=(n.rig.controls[x]?.bind??[]).flatMap(v=>v.parts),M=n.rig.parts.filter(v=>v.glow?.control===x).map(v=>v.id);return new Set([...$,...M])},w=new Map,S=x=>{let $=w.get(x);if(!$){const M=p(x);w.set(x,$={...M,solved:Kn(n,M.values,t.propScale)})}return $},k=(x,$)=>{const M=g(x),{values:v,origin:T,solved:I}=S($);if(M.kind==="box")return vt(T.x-t.width/2,T.y-t.height,t.width,t.height);if(M.kind==="anchor"){const C=I.anchors[M.name].point,D=Sv*t.propScale;return vt(T.x+C.x-D/2,T.y+C.y-D/2,D,D)}if(M.kind==="part")return _(new Set([M.name]),`part "${M.name}" is`);const O=m(M.name);if(O.size===0)return vt(T.x-t.width/2,T.y-t.height,t.width,t.height);return _(O,`the parts control "${M.name}" moves are`);function _(C,D){const q=[...I.under,...I.over].filter(R=>C.has(R.part.id)).flatMap(R=>R.faces.flatMap(N=>N.points));if(q.length===0){const R=Number.isFinite($)?`at ${$} ms`:"after its edits";throw new Error(`${n.kind}: ${D} turned away from the viewer ${R}; aim at an anchor (${o.map(N=>`anchor:${N}`).join(", ")||"none"}) or box`)}const X=q.map(R=>R.x),J=q.map(R=>R.y),j=Math.min(...X),A=Math.min(...J);return vt(T.x+j,T.y+A,Math.max(...X)-j,Math.max(...J)-A)}},y=(x,$)=>{try{return k(x,$)}catch{return}},E={kind:"prop",prop:t,about:jn,target:t,box:vt(t.x,t.y,t.width,t.height),anchor(x,$=1/0){return k(x,$)},piece(x){const $=g(x);if($.kind!=="part")throw new Error(`${n.kind}: a piece is a part, part:ID (${r.slice(0,6).map(I=>`part:${I}`).join(", ")}…), not "${x}"`);const M=d.get($.name);if(M)return M;const v=[$.name];for(let I=0;I<v.length;I++)for(const O of n.rig.parts)O.parent===v[I]&&!v.includes(O.id)&&v.push(O.id);const T={id:d.size+1,part:$.name,home:k(x,0)};d.set($.name,T);for(const I of v)u.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(x,$,M){if(!(x in jn.edits))throw Is(n.kind,x,jn);const v=Array.isArray($)?$:[$];if(v.length===0)throw new Error(`${n.kind}.edit: ${x} takes at least one anchor`);if(w.clear(),x==="move"||x==="fling"){if(v.length>1)throw new Error(`${n.kind}.edit: ${x} takes one part anchor`);const T=E.piece(v[0]);if(x==="fling")return E.fling(T,M);const I=M.to;if(!I)throw new Error(`${n.kind}.edit: move needs \`to\`, an anchor name or { x, y }`);const O=typeof I=="string"?k(I,M.at):void 0;return E.move(T,{...M,to:O?{x:O.left+O.width/2,y:O.top+O.height/2}:I})}for(const T of v){const I=g(T);if(I.kind!=="control")throw new Error(`${n.kind}.edit: ${x} takes control anchors (control:${i.join(", control:")}), not "${T}"`);const O=s[I.name];let _;if(x==="set"){if(typeof M.value!="number"||!Number.isFinite(M.value))throw new Error(`${n.kind}.edit: set needs \`value\`, a number (${I.name}: ${O.description})`);_=M.value}else _=M.on===!1?O.default??O.min??0:O.max??1;a.tween(I.name,p(M.at).values[I.name],_,M,Mv)}return E},follow(x,$){return w.clear(),l.follow(x,$),E},fling(x,$){return w.clear(),l.fling(x,$),E},move(x,$){return w.clear(),l.move(x,$),E},ride(x,$,M){const v=[...i.flatMap(I=>Dn(a.keys(I))),...(e.tracks??[]).flatMap(I=>Dn(I.keyframes.filter(O=>typeof O.value=="number")))];if(v.length===0)return x;const T=[...o.map(I=>`anchor:${I}`),...r.map(I=>`part:${I}`)].flatMap(I=>{const O=y(I,0);return O?[{top:O.top,offset:_=>(y(I,_)?.top??O.top)-O.top,windows:v}]:[]});return ao(x,$,{ground:M.ground,every:M.every??Ne,floors:T})},tracks:a.tracks};return E}const Ev={body:"#e8574a",trim:"#3b3b44",glass:"#bfe3f2",tyre:"#2c2c33",hub:"#c9ccd3",light:"#fff4b8",tail:"#ff5a4f",inside:"#3b3640",seat:"#6d5d55"};function ve(t){const e={...Ev,...t.colors},n=[],{forwardMost:s,backMost:i,top:o}=eg(t);t.body&&n.push({id:"body",shape:{type:"extrude",profile:t.body,width:t.width},fill:e.body});for(const[h,d]of(t.frame??[]).entries())n.push({id:`frame-${h}`,shape:{type:"tube",points:d.points,radius:d.radius??.035,segments:6},fill:d.color??e.body,outline:.7});for(const[h,d]of(t.windows??[]).entries())for(const u of[1,-1])n.push({id:`window-${h}-${u>0?"left":"right"}`,shape:{type:"panel",points:[[d.from,d.low],[d.to,d.low],[d.to,d.high],[d.from,d.high]],facing:u>0?"left":"right"},at:[u*(t.width/2+.01),0,0],fill:e.glass,outline:.7,seeThrough:!0,glow:t.lights?{control:"lights",color:"#ffe9a3"}:void 0});for(const h of t.extras??[])n.push(h);if(t.cabin){const h=t.cabin.width??t.width*.85;n.push({id:"cabin",shape:{type:"extrude",profile:t.cabin.profile,width:h},fill:e.glass,outline:.9,seeThrough:!0,layer:1});const d=Math.min(...t.cabin.profile.map(([,f])=>f)),u=Math.max(...t.cabin.profile.map(([,f])=>f));for(const[f,p]of(t.cabin.pillars??[]).entries())n.push({id:`pillar-${f}`,shape:{type:"box",size:[h+.02,u-d,.1]},at:[0,(d+u)/2,p],fill:e.body,outline:.8,layer:1})}const r=t.wheels[0]?.radius??.4,a=[];t.wheels.forEach((h,d)=>{const u=h.side===0?[0]:[1,-1],f=h.thickness??(h.style==="spoked"?.05:.26);for(const p of u){const g=`wheel-${d}-${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:d,low:u,high:f}=t.door,p=[[h,u],[d,u],[d,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+(d-h)*.15,S=h+(d-h)*.55;n.push({id:`seat-back-${m}`,shape:{type:"panel",points:[[w,u+.05],[S,u+.05],[S-.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-d,y]),facing:g>0?"left":"right"},at:[g*(t.width/2+.01),0,d],fill:e.body,outline:.7,overRider:!0})}l.door={description:"Doors open: 0 shut, 1 open (hinged at the front)",unit:"0..1",min:0,max:1,bind:[{parts:["door-left"],rotate:{axis:"y",degrees:-70}},{parts:["door-right"],rotate:{axis:"y",degrees:70}}]}}if(t.lights){const{across:h,low:d,high:u,front:f,back:p}=t.lights,g=(t.lights.size??.32)/2,m=[[-g,d],[g,d],[g,u],[-g,u]];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:so(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:Av(t),acting:ng,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 eg(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 ng={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 Ao(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 sg=.4;function Av(t){const e=t.wheels[0]?.radius??.4,{forwardMost:n,backMost:s}=eg(t),i=(n-s)/2,o=(a,l,c)=>{const h=a.exaggeration;let d=l;return a.facing()!==c&&(d=a.turnTo(d,c>0?"right":"left")),a.key(d+200,{pitch:4*h,squash:1-.07*h,lean:-.1*h},{act:!1,easing:"ease-out"}),Ao(a,d,d+200,a.x-c*.15*h*a.scale,"ease-out",e),a.effect({kind:"exhaust",time:d+150,x:a.x-c*i*a.scale,y:a.floor-.3*a.scale,length:900,direction:-c}),d+260},r=(a,l,c)=>{const h=a.exaggeration*(c?1.8:1);a.key(l,{pitch:-5*h,lean:-.08*h,squash:.95},{act:!1,easing:"ease-out"}),a.key(l+380,{pitch:0,lean:0,squash:1})};return{drive:{summary:"Drives to `to`: rocks back and squats, lunges forward stretched, and stops with a nose-dive that settles; wheels roll exactly the distance.",needs:["to"],uses:["speed","for"],run(a,l,c){const h=Math.sign(l.to-a.x);if(h===0)return{end:c};const d=o(a,c,h),u=a.exaggeration,f=Math.abs(l.to-a.x),p=l.for??Math.max(500,f/(l.speed??sg));return a.effect({kind:"dust",time:d,x:a.x-h*i*a.scale,y:a.floor,length:600,direction:-h}),a.key(d+140,{pitch:-1.5*u,squash:1+.05*u,lean:.12*u},{act:!1,easing:"ease-out"}),a.key(d+Math.max(160,p-160),{pitch:0,lean:.08*u,squash:1.02},{act:!1}),Ao(a,d,d+p,l.to,"ease-in-out",e),r(a,d+p,!1),{end:d+p+380,contact:d,release:d+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 d=o(a,c,h),u=a.exaggeration,f=a.x,p=Math.abs(l.to-f),g=l.for??Math.max(600,p/(l.speed??sg*1.2)),m=d+g*.55,w=f+(l.to-f)*.65;return a.key(d+140,{pitch:-1.5*u,squash:1+.06*u,lean:.14*u},{act:!1,easing:"ease-out"}),Ao(a,d,m,w,"ease-in",e),a.key(m+80,{pitch:-7*u,lean:-.12*u,squash:.94},{act:!1,easing:"ease-out"}),Ao(a,m,d+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:d+g,x:l.to+h*i*a.scale,y:a.floor,length:600,direction:h}),r(a,d+g,!0),{end:d+g+380,contact:m,release:d+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 d=a.facing();return a.effect({kind:"honk",time:c+60,x:a.x+(d||1)*i*a.scale,y:a.floor-.7*a.scale,length:700,direction:d||1}),{end:c+520,contact:c+60}}},...t.door?{door:{summary:"Opens the doors (`open: true`) or shuts them (`open: false`).",needs:["open"],run(a,l,c){return a.key(c+450,{door:l.open?1:0}),{end:c+600,contact:c+450}}}}:{},...t.lights?{lights:{summary:"Switches the lights on (`on: true`) or off.",needs:["on"],run(a,l,c){return a.key(c+120,{lights:l.on?1:0},{act:!1}),{end:c+300,contact:c+120}}}}:{}}}function ig(t={}){return ve({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 og(t={}){return ve({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 rg(t={}){return ve({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 ag(t={}){return ve({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 lg(t={}){const e=t.colors?.body??"#a8743f";return ve({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 cg(t={}){return ve({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 hg(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 ve({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 dg(t={}){return ve({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 ug(t={}){const e=t.height??2.4,n=t.trunkRadius??.16,s=t.canopy?.radius??1.1,i=t.canopy?.shape==="tall",o={trunk:"#8a5a3b",leaves:"#5cae5a",...t.colors},r=$e(t.canopy?.seed??7),a=[{id:"trunk",shape:{type:"tube",points:[[0,0,0],[.06,e*.5,0],[-.02,e,0]],radius:n,segments:8},fill:o.trunk},{id:"branch",parent:"trunk",shape:{type:"tube",points:[[0,0,0],[.45,.4,.1]],radius:n*.45,segments:6},at:[.04,e*.62,0],fill:o.trunk},{id:"canopy",parent:"trunk",shape:{type:"ellipsoid",radii:[s,s*(i?1.35:.88),s],segments:14},at:[-.02,e+s*.55,0],fill:o.leaves}],l=t.canopy?.lobes??7;for(let h=0;h<l;h++){const d=Math.PI*2*h/l+r.next()*.6,u=(r.next()-.25)*s*(i?1.1:.7),f=s*(.48+r.next()*.22),p=[Math.cos(d)*s*.78,u,Math.sin(d)*s*.6];a.push({id:`lobe-${h}`,parent:"canopy",shape:{type:"ellipsoid",radii:[f,f*.86,f],segments:12},at: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:xv(),acting:fg,colors:{body:o.leaves}}}const fg={depth:{sway:1,canopySway:2,size:0,squash:1},limits:{sway:2,canopySway:3,squash:.08},eyes:[],headTurns:{},drift:[]};function xv(){const t=(e,n,s,i)=>{const o=e.anchor("canopy");e.effect({kind:"leaves",time:n,x:o.x,y:o.y,length:s,direction:i,toY:e.floor})};return{sway:{summary:"Sways in gusts of `wind` (0..1, default 0.5) for `for` ms (default 3000); the canopy trails the trunk, and a strong wind sheds leaves.",uses:["wind","for"],run(e,n,s){const i=n.wind??.5,o=n.for??3e3,r=e.exaggeration,a=260;let l=0;for(let c=a;c<o;c+=a){const h=.55+.45*Math.sin(c/o*Math.PI*2.3),d=Math.sin(c/170)*.35,u=-i*9*r*(h+d*i);e.key(s+c,{sway:u,canopySway:l*1.3},{act:!1,easing:"ease-in-out"}),l=u}if(e.key(s+o,{sway:0,canopySway:0}),i>.45)for(let c=0;c<o;c+=700)t(e,s+c,2200,1);return{end:s+o}}},shake:{summary:"Shakes (something hit it): a quick wobble that dies away, shedding leaves.",uses:["for"],run(e,n,s){const i=n.for??900,o=e.exaggeration,r=6;for(let a=1;a<=r;a++){const l=1-a/(r+1),c=a%2===0?1:-1;e.key(s+i*a/(r+1),{sway:c*5*o*l,canopySway:-c*6*o*l},{act:!1,easing:"ease-in-out"})}return e.key(s+i,{sway:0,canopySway:0}),t(e,s+60,1800,1),t(e,s+260,1800,-1),{end:s+i,contact:s}}},shedLeaves:{summary:"Leaves fall from the canopy for `for` ms (default 2000).",uses:["for"],run(e,n,s){const i=n.for??2e3;for(let o=0;o<i;o+=500)t(e,s+o,2e3,o%1e3===0?1:-1);return{end:s+i}}}}}function gg(t={}){const e=t.width??4,n=t.depth??3.2,s=t.wallHeight??2.5,i=t.roofHeight??1.5,o=t.overhang??.25,r={walls:"#f1d9a8",roof:"#b8433a",door:"#7a4b2a",doorway:"#3a2a22",glass:"#bfe3f2",lit:"#ffd66b",chimney:"#9b5a45",...t.colors},a=n/2+.01,l=t.door?.width??.9,c=t.door?.height??1.9,h=t.door?.at??0,d=t.windows??[{at:-1.25,low:1,width:.8,height:.8},{at:1.25,low:1,width:.8,height:.8}],u=[{id:"walls",shape:{type:"box",size:[e,s,n]},at:[0,s/2,0],fill:r.walls},{id:"roof",shape:{type:"extrude",profile:[[-n/2-o,s],[n/2+o,s],[0,s+i]],width:e+o*2},fill:r.roof,layer:1},{id:"doorway",shape:{type:"panel",points:[[0,0],[l,0],[l,c],[0,c]],facing:"front"},at:[h-l/2,0,a-.005],fill:r.doorway,outline:.6,seeThrough:!0},{id:"door",shape:{type:"panel",points:[[0,0],[l,0],[l,c],[0,c]],facing:"front"},at:[h-l/2,0,a+.005],fill:r.door,outline:.8,overRider:!0}];d.forEach((g,m)=>{u.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])u.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;u.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:u,controls:{door:{description:"The front door open: 0 shut, 1 open",unit:"0..1",min:0,max:1,bind:[{parts:["door"],rotate:{axis:"y",degrees:-80}}]},lights:{description:"The windows lit: 0 dark, 1 lit",unit:"0..1",min:0,max:1}},length:n+o*2,height:s+i+.6,footprint:[e+.6,n+.6],anchors:{door:{at:[h,c/2,a]},doorstep:{at:[h,0,a+.4]},ridge:{at:[0,s+i,0]},...f?{chimney:{at:[f.at,s+i+.5,f.back]}}:{}}};return{kind:t.kind??"house",family:"building",summary:t.summary??"A house: opens its door, lights its windows, puffs chimney smoke, shakes, pops up.",rig:p,actions:$v(!!f),acting:pg,colors:{body:r.walls}}}const pg={depth:{door:1,lights:0,roll:1,squash:1,size:0},limits:{door:.1,roll:1.5,squash:.05},eyes:[],headTurns:{},drift:[]};function $v(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 mg(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,d,u]of[[-1,1,"front-left"],[1,1,"front-right"],[-1,-1,"back-left"],[1,-1,"back-right"]])l.push({id:`leg-${u}`,shape:{type:"tube",points:[[0,0,0],[0,s-r,0]],radius:a,segments:6},at:[h*(e/2-a*1.5),0,d*(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:Pv(),acting:yg,colors:{body:o.seat}}}const yg={depth:{tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.05},eyes:[],headTurns:{},drift:[]};function Pv(){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 bg(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[d,u,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:[d*(e/2-r*2),0,u*(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(d,u,f){return d.key(f+400,{drawer:u.open?1:0},{easing:u.open?"ease-out":"ease-in"}),{end:f+500,contact:f+400}}}},acting:wg,colors:{body:i.top}}}const wg={depth:{drawer:1,roll:1,squash:1,size:0},limits:{drawer:.08,roll:1,squash:.04},eyes:[],headTurns:{},drift:[]};function kg(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,d,u){const f=d.for??700,p=h.exaggeration;return h.key(u+90,{give:1-.18*p},{act:!1,easing:"ease-out"}),h.key(u+f*.45,{give:1+.05*p},{act:!1,easing:"ease-in-out"}),h.key(u+f*.7,{give:1-.04*p},{act:!1,easing:"ease-in-out"}),h.key(u+f,{give:1}),{end:u+f,contact:u+90}}}},acting:vg,colors:{body:o.blanket}}}const vg={depth:{give:1,roll:1,squash:1,size:0},limits:{give:.03,roll:.5,squash:.03},eyes:[],headTurns:{},drift:[]};function Mg(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:Iv(),acting:Sg,colors:{body:i.door}}}const Sg={depth:{open:1,roll:1,squash:1,size:0},limits:{open:.08,roll:.6,squash:.03},eyes:[],headTurns:{},drift:[]};function Iv(){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 Tg=1.4;function Eg(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,d=e/2+.06,u=[{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*d,S=(k,y,E=a)=>{u.push({id:k,shape:{type:"tube",points:y,radius:E,segments:6},fill:o.frame,outline:.7})};S(`post-${m}`,[[w,n-.1,-l/2],[w,c+.04,-l/2],[w,c+.04,-l/2-.14]]),S(`rail-${m}`,[[w,n-.03,-l/2],[w,n-.03,l/2]]),S(`leg-${m}`,[[w,n-.03,l/2],[w*.85,i,l/2+.06]]),S(`strut-${m}`,[[w*.85,i+.08,l/2+.04],[w*.8,.13,l/2+.22]]),S(`armrest-${m}`,[[w,n+.22,-l/2+.02],[w,n+.22,l/2-.08]],a*1.3),u.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}),u.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}),u.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=u.map(g=>g.id).filter(g=>!g.startsWith("rim-")),p={parts:u,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:[d*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:Ov(s),acting:Ag,colors:{body:o.seat,ink:o.frame},wheelRadius:s,moves:{roll:{speed:Tg,perMetre:{wheelSpin:180/(Math.PI*s)}}}}}const Ag={depth:{wheelSpin:0,tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.03},eyes:[],headTurns:{},drift:[]};function xg(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 Ov(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??Tg*e.scale/1e3));return e.key(o+150,{tip:1.5*e.exaggeration},{act:!1,easing:"ease-out"}),xg(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 xg(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 $g(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:_v(),acting:Pl,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:15,flies:!0,hold:{blur:1},perSecond:{rotor:Be*1e3}}}}}const Pl={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:[]},Be=2.6;function _v(){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,Be,"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,Be),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,Be),{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,Be),{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,Be),t(n,r,r+1600,Be,"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 Pg(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:Hv(),acting:Pl,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:30,flies:!0,hold:{blur:1},perSecond:{rotor:Be*1e3}}}}}const Cv=3.2;function Hv(){const t=(n,s,i,o)=>{const r=n.values.rotor??0;n.set("rotor",s,r),n.set("rotor",i,r+Cv*(i-s)*(o?.5:1),o)},e=(n,s,i)=>{const o=Math.sign(i-n.x);return o!==0&&n.facing()!==o?n.turnTo(s,o>0?"right":"left"):s};return{takeOff:{summary:"Spins the propeller up, runs along the ground toward `to`, lifts its nose and climbs to `height` metres (default 4).",needs:["to"],uses:["height","for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to);t(n,r,r+700,"ease-in"),n.key(r+700,{blur:1},{act:!1,easing:"ease-in"});const a=s.for??2600,l=n.x,c=r+700+a*.55,h=l+(s.to-l)*.45;return n.move(r+700,c,h,{easing:"ease-in"}),n.key(c,{pitch:8*o,squash:1+.04*o},{act:!1,easing:"ease-out"}),n.key(r+700+a,{lift:s.height??4,pitch:10*o,squash:1},{act:!1,easing:"ease-in-out"}),n.move(c,r+700+a,s.to),n.key(r+700+a+500,{pitch:0}),t(n,r+700,r+700+a+500),n.effect({kind:"dust",time:c,x:h,y:n.floor,length:700}),{end:r+700+a+500,contact:c}}},fly:{summary:"Flies to `to` (and `height`), banking into the move and leveling out.",needs:["to"],uses:["height","speed","for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to),a=s.for??Math.max(800,Math.abs(s.to-n.x)/(s.speed??.45)),l=s.height??n.values.lift;return n.key(r+350,{roll:10*o,pitch:l>n.values.lift?6*o:-3*o},{act:!1,easing:"ease-out"}),n.key(r+a-300,{roll:4*o,lift:l},{act:!1}),n.key(r+a,{roll:0,pitch:0}),n.move(r,r+a,s.to,{easing:"ease-in-out"}),t(n,i,r+a),{end:r+a,contact:r,release:r+a}}},loop:{summary:"Loops the loop: pulls up and over in a full circle (`for` ms, default 2400), carrying on the way it was going.",uses:["for"],run(n,s,i){const o=s.for??2400,r=2.2*n.exaggeration,a=n.facing()||1,l=16,c=n.x,h=n.values.lift,d=n.values.pitch;for(let u=1;u<=l;u++){const f=Math.PI*2*u/l,p=i+o*u/l;n.key(p,{lift:h+r*(1-Math.cos(f)),pitch:d+360*u/l},{act:!1}),n.move(i+o*(u-1)/l,p,c+a*(r*Math.sin(f)+u/l*r*1.2)*n.scale)}return n.key(i+o+1,{pitch:d},{act:!1}),t(n,i,i+o),{end:i+o+1}}},land:{summary:"Comes down toward `to`: descends, flares nose-up, touches down with a squash and dust, rolls to a stop and the propeller spools down.",needs:["to"],uses:["for"],run(n,s,i){const o=n.exaggeration,r=e(n,i,s.to),a=n.x,l=s.for??2200,c=r+l,h=a+(s.to-a)*.7;return n.key(r+l*.4,{pitch:-4*o},{act:!1,easing:"ease-out"}),n.key(c-250,{pitch:6*o,lift:.15},{act:!1,easing:"ease-in-out"}),n.key(c,{lift:0,pitch:0,squash:1-.12*o},{act:!1,easing:"ease-in"}),n.key(c+260,{squash:1}),n.move(r,c,h),n.move(c,c+1200,s.to,{easing:"ease-out"}),t(n,i,c),t(n,c,c+1600,"ease-out"),n.key(c+1600,{blur:0},{act:!1,easing:"ease-out"}),n.effect({kind:"dust",time:c,x:h,y:n.floor,length:700}),{end:c+1600,contact:c}}}}}const Xn=["walk","trot","canter","gallop"],Rv=Xn,Ig=["fl","fr","hl","hr"],xo={walk:{offsets:{hl:0,fl:.25,hr:.5,fr:.75},swing:16,lift:45,bob:.02,rock:0,cycle:1100},trot:{offsets:{fl:0,hr:0,fr:.5,hl:.5},swing:22,lift:75,bob:.05,rock:0,cycle:640},canter:{offsets:{hr:0,hl:.33,fr:.33,fl:.66},swing:30,lift:70,bob:.08,rock:5,cycle:560},gallop:{offsets:{hr:0,hl:.1,fr:.5,fl:.6},swing:40,lift:80,bob:.1,rock:7,cycle:460}},qe=Math.PI/180;function $o(t,e){return 4*t*Math.sin(xo[e].swing*qe)}function ze(t){const{legs:e,colors:n}=t,s=e.upper+e.lower+e.foot,i=s+t.body.rise,o=(d,u)=>[u*d[0],d[1],d[2]],r=[{id:"body",shape:{type:"ellipsoid",radii:t.body.radii,segments:18},at:[0,i,0],fill:n.coat},{id:"neck",shape:{type:"tube",points:t.neck.points,radius:t.neck.points.map((d,u,f)=>t.neck.radius*(1.25-.4*u/Math.max(1,f.length-1))),segments:12},at:t.neck.at,fill:n.coat},{id:"head",parent:"neck",shape:{type:"ellipsoid",radii:t.head.radii,segments:14},at:t.head.at,rotate:t.head.rotate,fill:n.coat},...Nv(t,n,i)];t.mane&&r.push({id:"mane",parent:"neck",shape:{type:"tube",points:t.mane.points,radius:t.mane.radius,segments:6},fill:n.dark,outline:.7}),t.muzzle&&r.push({id:"muzzle",parent:"head",shape:{type:"ellipsoid",radii:t.muzzle.radii,segments:10},at:t.muzzle.at,fill:n.muzzle,outline:.8});for(const d of[1,-1]){const u=d>0?"left":"right",f=t.ears.rotate?o(t.ears.rotate,1).map((p,g)=>g===2?d*p:p):void 0;r.push({id:`ear-${u}`,parent:"head",shape:{type:"ellipsoid",radii:t.ears.radii,segments:8},at:o(t.ears.at,d),rotate:f,fill:n.coat,outline:.7},{id:`eye-${u}`,parent:"head",shape:{type:"ellipsoid",radii:[t.eyes.size*.8,t.eyes.size,t.eyes.size*.9],segments:8},at:o(t.eyes.at,d),fill:"#1d1d22",outline:.4})}r.push(...t.extras?.(n)??[]);const a={walk:{description:"Phase of the stride, in full cycles (keyed in step with the distance covered)",unit:"cycles"},walking:{description:"How much of the gait is applied: 0 standing, 1 moving",unit:"0..1",min:0,max:1},gait:{description:`Which gait: ${t.gaits.map(d=>`${Xn.indexOf(d)} ${d}`).join(", ")}`,unit:"index",min:0,max:3},neck:{description:"Neck bent down (+, eating, sniffing) or up (−, alert)",unit:"degrees",bind:[{parts:["neck"],rotate:{axis:"x",degrees:1}}]},tail:{description:"Tail flicked up and back (+), curling along its length, on a spring behind the motion",unit:"degrees",bind:[{parts:ae,rotate:{axis:"x",degrees:1/ae.length}}]},wag:{description:"Tail swung side to side, curling",unit:"degrees",bind:[{parts:ae,rotate:{axis:"y",degrees:1/ae.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 d of Ig){const u=d[0]==="f",f=d[1]==="l"?1:-1,p=u?e.thickness[0]:e.thickness[1];r.push({id:`${d}-upper`,shape:{type:"tube",points:[[0,e.upper*.2,0],[0,-e.upper*.5,0],[0,-e.upper,0]],radius:[p,p*.85,e.lowerThickness*1.15],segments:10},at:[f*e.across,s,u?e.front:e.hind],fill:n.coat},{id:`${d}-knee`,parent:`${d}-upper`,shape:{type:"ellipsoid",radii:Array(3).fill(e.lowerThickness*1.08),segments:10},at:[0,-e.upper,0],fill:n.coat,solidOnly:!0},{id:`${d}-lower`,parent:`${d}-upper`,shape:{type:"tube",points:[[0,0,0],[0,-e.lower,0]],radius:[e.lowerThickness*1.1,e.lowerThickness*.85],segments:10},at:[0,-e.upper,0],fill:n.coat},{id:`${d}-foot`,parent:`${d}-lower`,shape:{type:"ellipsoid",radii:[e.footSize[0]/2,e.foot/2+.004,e.footSize[1]/2],segments:12},at:[0,-e.lower-e.foot/2,e.footSize[1]*.12],fill:n.foot,outline:.8});const g=`${u?"Front":"Hind"} ${f>0?"left":"right"} leg`;a[`${d}.swing`]={description:`${g}: forward (+) or back (−) from the hip`,unit:"degrees",bind:[{parts:[`${d}-upper`],rotate:{axis:"x",degrees:-1}}]},a[`${d}.knee`]={description:`${g}: knee (hock) folded`,unit:"degrees",bind:[{parts:[`${d}-lower`],rotate:{axis:"x",degrees:u?1:-1}}]},a[`${d}.ankle`]={description:`${g}: foot turned at the ankle (+ toe forward)`,unit:"degrees",bind:[{parts:[`${d}-foot`],rotate:{axis:"x",degrees:-1,pivot:[0,e.foot/2,-e.footSize[1]*.12]}}]}}const l=t.neck.points[t.neck.points.length-1],c={parts:r,controls:a,length:t.body.radii[2]*2+Math.max(0,t.neck.at[2]+l[2]+t.head.radii[2]-t.body.radii[2])+.3,height:t.neck.at[1]+l[1]+t.head.radii[1]*2,footprint:[e.across*2+t.body.radii[0],(e.front-e.hind)*1.4],anchors:{back:{at:[0,i+t.body.radii[1],-t.body.radii[2]*.05]},head:{part:"head",at:[0,0,0]},mouth:{part:t.muzzle?"muzzle":"head",at:t.muzzle?[0,0,t.muzzle.radii[2]]:[0,0,t.head.radii[2]]},front:{at:[0,i,t.body.radii[2]]},...t.anchors},derive:d=>Dv(d,t,s)},h={legLength:s,upper:e.upper,lower:e.lower,foot:e.foot,tailHangs:t.tail.points[t.tail.points.length-1][1]<0,front:e.front,hind:e.hind,call(d,u){const f=d.anchor("mouth");d.effect({kind:"honk",time:u,x:f.x,y:f.y,length:800,direction:d.facing()||1})}};return{kind:t.kind,family:"animal",summary:t.summary,rig:c,actions:{...Wv(t,h),...t.actions?.(h)},acting:Ol,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:Lv(t,s)}}function Lv(t,e){const n=i=>{const o=$o(e,i);return{speed:o/(xo[i].cycle*(t.cycleScale??1)/1e3),set:{gait:Xn.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 ae=Array.from({length:7},(t,e)=>e===0?"tail":`tail-${e}`);function Nv(t,e,n){const s=Na(t.tail.points,ae.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/ae.length),h=ae.map((f,p)=>{const g=s[p],m=s[p+1],w=[m[0]-g[0],m[1]-g[1],m[2]-g[2]],S=p===0?void 0:s[p-1];return{id:f,...p>0?{parent:ae[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]-S[0],g[1]-S[1],g[2]-S[2]],fill:e.dark,outline:.8}}),d=s[s.length-1],u=s[s.length-2];return h.push({id:"tail-tip",parent:ae[ae.length-1],shape:{type:"ellipsoid",radii:Array(3).fill(c(ae.length)*1.05),segments:8},at:[d[0]-u[0],d[1]-u[1],d[2]-u[2]],fill:e.dark,outline:.8,solidOnly:!0}),h}function Dv(t,e,n){const s=Math.max(0,Math.min(1,t.walking??0));if(s===0)return{};const i=Xn[Math.max(0,Math.min(3,Math.round(t.gait??0)))],o=xo[e.gaits.includes(i)?i:e.gaits[0]],r=t.walk??0,a={};for(const c of Ig){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 Il(t){const n=Math.sin(32*qe),s=t.legLength-(t.front-t.hind)*n,i=72,r=(s-t.upper*Math.cos(i*qe)-t.foot)/t.lower,a=r>=1?0:r<=-1?180:Math.acos(r)/qe,l={pitch:32,lift:t.legLength*(1-Math.cos(32*qe))-t.front*n,neck:-10,tail:t.tailHangs?35:-40,"fl.swing":-32,"fr.swing":-32};for(const c of["hl","hr"])l[`${c}.swing`]=i-32,l[`${c}.knee`]=-(i+a),l[`${c}.ankle`]=a;return l}const Ol={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:[]},Fv=Ol;function Og(t){const e=(t.upper+t.lower)*.32,n=Math.asin(Math.min(1,e/(t.upper+t.lower+t.foot)))/qe,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 Wv(t,e){const n=t.cycleScale??1,s=r=>({summary:{walk:"Walks to `to` (four beats), its head bobbing.",trot:"Trots to `to`: legs in diagonal pairs, the body bouncing.",canter:"Canters to `to`: three beats, the body rocking.",gallop:"Gallops (runs) to `to`: legs reaching, the body rocking hard, kicking up dust."}[r],needs:["to"],uses:["for"],run(a,l,c){const h=Math.sign(l.to-a.x);if(h===0)return{end:c};let d=c;a.facing()!==h&&(d=a.turnTo(d,h>0?"right":"left"));const u=a.exaggeration;a.key(d+180,{neck:-12*u},{act:!1,easing:"ease-out"});const p=Math.abs(l.to-a.x)/a.scale/$o(e.legLength,r),g=l.for??Math.max(500,p*xo[r].cycle*n),m=a.values.walk??0;return a.set("gait",d,a.values.gait??0),a.set("gait",d+1,Xn.indexOf(r)),a.set("walking",d,0),a.set("walking",d+240,1,"ease-out"),a.set("walking",d+g-240,1),a.set("walking",d+g,0,"ease-in"),a.set("walk",d,m),a.move(d,d+g,l.to,{easing:"ease-in-out"}),a.set("walk",d+g,m+p,"ease-in-out"),a.key(d+g+300,{neck:0}),(r==="gallop"||r==="canter")&&(a.effect({kind:"dust",time:d+200,x:a.x-h*e.legLength*a.scale,y:a.floor,length:700,direction:-h}),a.effect({kind:"dust",time:d+g,x:l.to+h*e.legLength*.6*a.scale,y:a.floor,length:600,direction:h})),{end:d+g+300,contact:d,release:d+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=Il(e),h=l+450;r.key(h,c,{act:!1,easing:"ease-in-out"}),r.key(h+(a.for??1500),c,{act:!1});const d=h+(a.for??1500)+450,u={};for(const f of Object.keys(c))u[f]=0;return r.key(d,u),{end:d,contact:h,release:d-450}}},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=Og(e),h={...Il(e)},d=l+400,u=d+450;r.key(d,h,{act:!1,easing:"ease-in-out"}),r.key(u,c,{act:!1,easing:"ease-in-out"}),r.key(u+(a.for??2e3),c,{act:!1});const f=u+(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:u,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,d=l+260,u=d+90,f=u+520;if(r.key(d,{squash:.86,"hl.knee":40,"hr.knee":40,"fl.knee":25,"fr.knee":25,neck:8},{act:!1,easing:"ease-out"}),r.key(u,{squash:1.12,"hl.knee":0,"hr.knee":0,"fl.knee":0,"fr.knee":0,pitch:8,"fl.swing":35,"fr.swing":35,"hl.swing":-35,"hr.swing":-35},{act:!1,easing:"ease-out"}),r.key((u+f)/2,{lift:h,squash:1,pitch:0,"fl.knee":60,"fr.knee":60,"hl.knee":60,"hr.knee":60,"fl.swing":25,"fr.swing":25,"hl.swing":-20,"hr.swing":-20},{act:!1,easing:"ease-out"}),r.key(f,{lift:0,squash:.85,pitch:-4,"fl.knee":0,"fr.knee":0,"hl.knee":0,"hr.knee":0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0},{act:!1,easing:"ease-in"}),r.key(f+280,{squash:1,pitch:0,neck:0}),a.to!==void 0){const p=Math.sign(a.to-r.x);p!==0&&r.facing()!==p&&r.turnTo(l,p>0?"right":"left"),r.move(u,f,a.to)}return r.effect({kind:"dust",time:f,x:r.x,y:r.floor,length:550}),{end:f+280,contact:f}}},nod:{summary:"Nods its head twice.",run(r,a,l){return r.key(l+200,{neck:20},{act:!1,easing:"ease-out"}),r.key(l+400,{neck:-5},{act:!1,easing:"ease-in-out"}),r.key(l+600,{neck:18},{act:!1,easing:"ease-in-out"}),r.key(l+900,{neck:0}),{end:l+900}}},swish:{summary:"Swishes its tail a few times.",uses:["for"],run(r,a,l){const c=a.for??900;for(let h=1;h<=4;h++)r.key(l+c*h/5,{tail:h%2===0?10:35},{act:!1,easing:"ease-in-out"});return r.key(l+c,{tail:0}),{end:l+c}}}};return t.grazes&&(o.graze={summary:"Lowers its head to graze for `for` ms (default 1800), nibbling, then looks up.",uses:["for"],run(r,a,l){const c=a.for??1800;r.key(l+600,{neck:75},{act:!1,easing:"ease-in-out"});for(let h=900;h<600+c;h+=400)r.key(l+h,{neck:h%800===100?70:78},{act:!1,easing:"ease-in-out"});return r.key(l+600+c+500,{neck:0}),{end:l+600+c+500}}}),o}function _g(t={}){return ze({kind:t.kind??"horse",summary:t.summary??"A cartoon horse: walks, trots, canters and gallops with its hooves in step with the ground, rears, bucks, neighs, grazes and swishes its tail.",legs:{upper:.5,lower:.42,foot:.08,footSize:[.12,.16],front:.62,hind:-.62,across:.2,thickness:[.075,.09],lowerThickness:.05},body:{radii:[.32,.36,.95],rise:.25},neck:{at:[0,1.42,.7],points:[[0,0,0],[0,.5,.3]],radius:.15},head:{at:[0,.48,.5],radii:[.13,.14,.3],rotate:[38,0,0]},muzzle:{at:[0,-.02,.24],radii:[.11,.1,.1]},ears:{at:[.07,.16,-.17],radii:[.035,.1,.05]},eyes:{at:[.115,.05,-.04],size:.04},tail:{at:[0,1.4,-.9],points:[[0,0,0],[0,-.22,-.2],[0,-.62,-.24]],radius:.08},mane:{points:[[0,.1,-.12],[0,.55,.17]],radius:.07},colors:{coat:"#b5763a",dark:"#4a2e1a",foot:"#3a2a22",muzzle:"#8d5a2c",accent:"#e8c9a0",...t.colors},gaits:["walk","trot","canter","gallop"],call:"neigh",grazes:!0,anchors:{hitch:{at:[0,.95,-.15]},saddle:{at:[0,1.6,-.05]}},actions:e=>({rear:{summary:"Rears up on its hind legs, front legs tucked and pawing, neighs, and drops back down with dust.",uses:["for"],run(n,s,i){const o=n.exaggeration,r=Math.min(55,32*o),a=-e.hind*Math.sin(r*qe),l=s.for??700;n.key(i+200,{pitch:-4,neck:6,"hl.knee":12,"hr.knee":12},{act:!1,easing:"ease-out"}),n.key(i+520,{pitch:r,lift:a,neck:-25,"fl.swing":55,"fl.knee":95,"fr.swing":40,"fr.knee":80,"hl.knee":0,"hr.knee":0},{act:!1,easing:"ease-out"}),n.key(i+520+l*.5,{"fl.swing":35,"fl.knee":70,"fr.swing":58,"fr.knee":100},{act:!1,easing:"ease-in-out"}),n.key(i+520+l,{"fl.swing":55,"fl.knee":95,"fr.swing":40,"fr.knee":80},{act:!1,easing:"ease-in-out"});const c=i+520+l+380;return n.key(c,{pitch:0,lift:0,neck:8,squash:.94,"fl.swing":0,"fl.knee":0,"fr.swing":0,"fr.knee":0},{act:!1,easing:"ease-in"}),n.key(c+320,{neck:0,squash:1}),e.call(n,i+520),n.effect({kind:"dust",time:c,x:n.x+(n.facing()||1)*e.front*n.scale,y:n.floor,length:600}),{end:c+320,contact:c}}},buck:{summary:"Bucks: drops its head and kicks both hind legs up and back.",run(n,s,i){const o=n.exaggeration,r=Math.min(35,18*o),a=e.front*Math.sin(r*qe);return n.key(i+220,{pitch:3,squash:.95},{act:!1,easing:"ease-out"}),n.key(i+480,{pitch:-r,lift:a,neck:30,"hl.swing":-65,"hr.swing":-60,"hl.knee":10,"hr.knee":10},{act:!1,easing:"ease-out"}),n.key(i+900,{pitch:0,lift:0,neck:0,squash:.95,"hl.swing":0,"hr.swing":0,"hl.knee":0,"hr.knee":0},{act:!1,easing:"ease-in"}),n.key(i+1150,{squash:1}),n.effect({kind:"dust",time:i+900,x:n.x-(n.facing()||1)*.6*n.scale,y:n.floor,length:600}),{end:i+1150,contact:i+480}}}})})}function Cg(t={}){return ze({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 Hg(t={}){return ze({kind:t.kind??"cat",summary:t.summary??"A cartoon cat: walks, trots and runs, meows, arches its back, pounces, sits and swishes its tail.",legs:{upper:.13,lower:.11,foot:.035,footSize:[.05,.07],front:.17,hind:-.18,across:.06,thickness:[.028,.035],lowerThickness:.022},body:{radii:[.1,.105,.27],rise:.07},neck:{at:[0,.39,.2],points:[[0,0,0],[0,.08,.04]],radius:.05},head:{at:[0,.1,.05],radii:[.095,.085,.085]},muzzle:{at:[0,-.03,.07],radii:[.04,.03,.03]},ears:{at:[.055,.085,-.01],radii:[.03,.055,.02],rotate:[0,0,-12]},eyes:{at:[.045,.02,.07],size:.022},tail:{at:[0,.42,-.26],points:[[0,0,0],[0,.08,-.12],[0,.24,-.16],[0,.34,-.1]],radius:.022},extras:()=>[{id:"nose",parent:"muzzle",shape:{type:"ellipsoid",radii:[.014,.01,.01],segments:8},at:[0,.015,.03],fill:"#e48a9a",outline:.4}],colors:{coat:"#8f8a86",dark:"#5f5a57",foot:"#f2efe9",muzzle:"#f2efe9",accent:"#f2efe9",...t.colors},gaits:["walk","trot","gallop"],cycleScale:.5,call:"meow",actions:e=>({arch:{summary:"Arches its back, fur up and tail high, for `for` ms (default 1200): a startled cat.",uses:["for"],run(n,s,i){const o=n.exaggeration,r=s.for??1200,a={squash:1+.25*o,neck:25,tail:-45,"fl.swing":-8,"fr.swing":-8,"hl.swing":8,"hr.swing":8};return n.key(i+180,a,{act:!1,easing:"ease-out"}),n.key(i+180+r,a,{act:!1}),n.key(i+r+520,{squash:1,neck:0,tail:0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0}),{end:i+r+520,contact:i+180}}},pounce:{summary:"Crouches low, wiggles, and pounces to `to`, landing with a squash.",needs:["to"],run(n,s,i){const o=n.exaggeration,r=Math.sign(s.to-n.x);let a=i;r!==0&&n.facing()!==r&&(a=n.turnTo(a,r>0?"right":"left"));const l={squash:.75,"hl.knee":60,"hr.knee":60,"fl.knee":45,"fr.knee":45,neck:10,tail:-15};n.key(a+300,l,{act:!1,easing:"ease-out"});for(let d=1;d<=4;d++)n.key(a+300+d*110,{roll:d%2===0?3:-3},{act:!1});const c=a+300+550,h=c+480;return n.key(c,{roll:0,squash:1.2,"hl.knee":0,"hr.knee":0,"fl.knee":0,"fr.knee":0,"fl.swing":45,"fr.swing":45,"hl.swing":-45,"hr.swing":-45,tail:20},{act:!1,easing:"ease-out"}),n.key((c+h)/2,{lift:e.legLength*.9*o,squash:1.1,pitch:-6},{act:!1,easing:"ease-out"}),n.key(h,{lift:0,squash:.8,pitch:0,"fl.swing":0,"fr.swing":0,"hl.swing":0,"hr.swing":0,neck:0,tail:0},{act:!1,easing:"ease-in"}),n.key(h+260,{squash:1}),n.move(c,h,s.to),n.effect({kind:"dust",time:h,x:s.to,y:n.floor,length:450}),{end:h+260,contact:h}}}})})}function Rg(t={}){return ze({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 Bv(t){return $o(1,t)}function Lg(t={}){return ze({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 Ng(t={}){return ze({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 Dg(t={}){return ze({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 Ye=.6,Fg=75,_l=80;function Ke(t){const{colors:e}=t,[n,s,i]=t.body.radii,o=(t.tail.raised??15)*Math.PI/180,r=t.tail.length*.4,a=[{id:"body",shape:{type:"ellipsoid",radii:t.body.radii,segments:16},at:[0,t.body.height,0],fill:e.body},{id:"neck",shape:{type:"ellipsoid",radii:[n*.55,s*.55,i*.3],segments:10},at:[0,t.body.height+s*.45,i*.65],fill:e.body,outline:.5,solidOnly:!0},{id:"head",parent:"neck",shape:{type:"ellipsoid",radii:[t.head.radius,t.head.radius*1.02,t.head.radius*1.05],segments:14},at:[t.head.at[0],t.head.at[1]-(t.body.height+s*.45),t.head.at[2]-i*.65],fill:e.body},{id:"beak",parent:"head",shape:{type:"tube",points:[[0,0,0],[0,-t.beak.thickness*.4,t.beak.length]],radius:[t.beak.thickness,t.beak.thickness*.08],segments:8},at:[0,-t.head.radius*.1,t.head.radius*.8],fill:e.beak,outline:.8},{id:"tail",shape:{type:"ellipsoid",radii:[t.tail.width/2,.012*(i/.08),t.tail.length/2],segments:10},at:[t.tail.at[0],t.tail.at[1]+r*Math.sin(o),t.tail.at[2]-r*Math.cos(o)],rotate:[t.tail.raised??15,0,0],fill:e.wing,outline:.8}];if(e.belly&&a.push({id:"belly",parent:"body",shape:{type:"ellipsoid",radii:[n*.82,s*.7,i*.75],segments:12},at:[0,-s*.25,i*.12],fill:e.belly,outline:.4}),t.comb){const h=t.head.radius;a.push({id:"comb",parent:"head",shape:{type:"extrude",profile:[[-h*.5,h*.6],[h*.6,h*.6],[h*.5,h*1.3],[h*.15,h*1.05],[-h*.05,h*1.4],[-h*.3,h*1.05],[-h*.6,h*1.25]],width:h*.25},fill:e.comb??"#d9372e",outline:.7},{id:"wattle",parent:"head",shape:{type:"ellipsoid",radii:[h*.15,h*.35,h*.2],segments:8},at:[0,-h*.7,h*.6],fill:e.comb??"#d9372e",outline:.6})}for(const h of[1,-1]){const d=h>0?"left":"right",u=t.head.radius;a.push({id:`eye-${d}`,parent:"head",shape:{type:"ellipsoid",radii:[u*.16,u*.2,u*.18],segments:8},at:[h*u*.72,u*.18,u*.42],fill:"#1d1d22",outline:.3}),a.push({id:`wing-${d}`,shape:{type:"ellipsoid",radii:[.004,.004,.004],segments:4},at:[h*t.wing.shoulder[0],t.wing.shoulder[1],t.wing.shoulder[2]],rotate:[-8,h*90,0],outline:0}),a.push({id:`wing-${d}-blade`,parent:`wing-${d}`,shape:{type:"ellipsoid",radii:[t.wing.span*Ye/2,t.wing.chord*.1,t.wing.chord/2],segments:12},at:[h*t.wing.span*Ye/2,0,-t.wing.chord*.1],rotate:[-_l,0,0],fill:e.wing,outline:.8}),a.push({id:`wing-${d}-tip`,parent:`wing-${d}-blade`,shape:{type:"ellipsoid",radii:[t.wing.span*Ye/2.4,t.wing.chord*.06,t.wing.chord*.3],segments:10},at:[h*t.wing.span*Ye/4,0,-t.wing.chord*.3],rotate:[0,h*14,0],fill:e.wing,outline:.8}),a.push({id:`leg-${d}`,shape:{type:"tube",points:[[0,0,0],[0,-t.legs.length,0]],radius:Math.max(.004,t.legs.length*.05),segments:5},at:[h*t.legs.across,t.legs.length,0],fill:e.legs,outline:.6}),a.push({id:`toes-${d}`,parent:`leg-${d}`,shape:{type:"tube",points:[[0,0,-t.legs.length*.15],[0,0,t.legs.length*.35]],radius:Math.max(.003,t.legs.length*.04),segments:5},at:[0,-t.legs.length,0],fill:e.legs,outline:.6})}const l={spread:{description:"Wings: 0 folded back along the body, 1 spread out",unit:"0..1",min:0,max:1,bind:[{parts:["wing-left"],rotate:{axis:"y",degrees:-90}},{parts:["wing-right"],rotate:{axis:"y",degrees:90}},{parts:["wing-left-blade"],translate:[t.wing.span*(1-Ye)/2,0,0],rotate:{axis:"x",degrees:_l},scale:[1/Ye,1,1]},{parts:["wing-right-blade"],translate:[-t.wing.span*(1-Ye)/2,0,0],rotate:{axis:"x",degrees:_l},scale:[1/Ye,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)/Fg,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 d={},u=Math.max(0,Math.min(1,h.flapping??0));u>0&&(d.flap=(h.flap??0)+u*48*Math.sin(Math.PI*2*(h.wingbeat??0)));const f=Math.max(0,Math.min(1,h.stepping??0));if(f>0){const p=Math.sin(Math.PI*2*(h.step??0));d["leg.left"]=(h["leg.left"]??0)+f*28*p,d["leg.right"]=(h["leg.right"]??0)-f*28*p,d.peck=(h.peck??0)+f*12*Math.sin(Math.PI*4*(h.step??0))}return d}};return{kind:t.kind,family:"bird",summary:t.summary,rig:c,actions:zv(t),acting:Wg,colors:{body:e.body,ink:"#26262b"},moves:qv(t)}}function qv(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 Wg={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 zv(t){const e=(t.beatsPerSecond??4)/1e3,n=(r,a,l)=>{const c=r.values.wingbeat??0;r.set("wingbeat",a,c),r.set("wingbeat",l,c+(l-a)*e)},s=(r,a,l)=>{const c=Math.sign(l-r.x);return c!==0&&r.facing()!==c?r.turnTo(a,c>0?"right":"left"):a},i=(r,a)=>{const l=r.anchor("beak");r.effect({kind:"honk",time:a,x:l.x,y:l.y,length:600,direction:r.facing()||1})},o={hop:{summary:"Hops to `to` in little bounces, wings twitching.",needs:["to"],run(r,a,l){const c=s(r,l,a.to),h=r.x,d=Math.abs(a.to-h),u=Math.max(1,Math.round(d/(t.body.radii[2]*3*r.scale))),f=260;for(let p=0;p<u;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)/u,{easing:"ease-in-out"})}return r.key(c+u*f+120,{squash:1}),{end:c+u*f+120}}},walk:{summary:"Walks to `to` on its two legs, its head bobbing with each step.",needs:["to"],uses:["for"],run(r,a,l){const c=s(r,l,a.to),h=Math.abs(a.to-r.x)/r.scale,d=t.legs.length*1.2,u=h/d,f=a.for??Math.max(400,u*420),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+u/2,"ease-in-out"),{end:c+f,contact:c,release:c+f}}},peck:{summary:"Pecks at the ground (`for` ms, default 900): quick jabs of the head.",uses:["for"],run(r,a,l){const c=a.for??900,h=Math.max(1,Math.round(c/300));r.key(l+120,{pitch:-(t.stoop??12)},{act:!1,easing:"ease-out"});for(let d=0;d<h;d++)r.key(l+120+d*300+90,{peck:Fg},{act:!1,easing:"ease-in"}),r.key(l+120+d*300+260,{peck:20},{act:!1,easing:"ease-out"});return r.key(l+120+h*300+200,{peck:0,pitch:0}),{end:l+120+h*300+200,contact:l+210}}},flap:{summary:"Flaps its wings on the spot (`for` ms, default 900), lifting a little.",uses:["for"],run(r,a,l){const c=a.for??900;return r.key(l+120,{spread:1},{act:!1,easing:"ease-out"}),r.set("flapping",l,0),r.set("flapping",l+150,1,"ease-out"),r.set("flapping",l+c-150,1),r.set("flapping",l+c,0,"ease-in"),n(r,l,l+c),r.key(l+c*.5,{lift:t.legs.length*.6},{act:!1,easing:"ease-out"}),r.key(l+c,{lift:0,spread:0},{act:!1,easing:"ease-in"}),{end:l+c+80}}},[t.call]:{summary:`${t.call[0].toUpperCase()}${t.call.slice(1)}s: its head comes up and its beak opens to call.`,run(r,a,l){return r.key(l+120,{peck:-25,squash:1.06},{act:!1,easing:"ease-out"}),r.key(l+500,{peck:-20},{act:!1}),r.key(l+760,{peck:0,squash:1}),i(r,l+150),{end:l+760,contact:l+150}}}};return t.flies!==!1?(o.fly={summary:"Takes off (a crouch and a leap, wings beating) and flies to `to` at `height` metres (default 2); `land` brings it down.",needs:["to"],uses:["height","for"],run(r,a,l){const c=r.exaggeration;r.key(l+60,{grip:0},{act:!1});const h=s(r,l,a.to),d=a.height??2,u=a.for??Math.max(700,Math.abs(a.to-r.x)/.35),f=r.values.lift>t.legs.length,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+u,.6),n(r,p,p+u),r.key(p+u*.4,{lift:d,pitch:-5,squash:1},{act:!1,easing:"ease-out"}),r.key(p+u,{lift:d,pitch:0},{act:!1,easing:"ease-in-out"}),r.move(p,p+u,a.to,{easing:"ease-in-out"}),{end:p+u,contact:p,release:p+u}}},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,d=a.height??h*.67,u=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+u,{lift:d,pitch:-3,flap:10},{act:!1,easing:"ease-in-out"}),r.move(c,c+u,a.to,{easing:"ease-in-out"}),{end:c+u,contact:c,release:c+u}}},o.land={summary:"Comes down to the floor it is over (or to `height` metres above it, a branch or a roof): wings braking, a squash on touchdown.",uses:["height","to"],run(r,a,l){const h=a.height??0;return r.set("flapping",l,r.values.flapping??1),r.set("flapping",l+700-120,1),r.set("flapping",l+700,0,"ease-in"),n(r,l,l+700),r.key(l+700*.6,{pitch:14},{act:!1,easing:"ease-out"}),r.key(l+700,{lift:h,pitch:0,squash:.85,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 Bg(t={}){return Ke({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 qg(t={}){return Ke({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 zg(t={}){return Ke({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 Yg(t={}){return Ke({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 Kg(t={}){return Ke({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 jg(t={}){return Ke({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 Xg(t={}){return Ke({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 Gn={car:ig,truck:og,bus:rg,tractor:ag,cart:lg,trainCar:cg,bike:hg,motorbike:dg,tree:ug,house:gg,chair:mg,desk:bg,bed:kg,door:Mg,wheelchair:Eg,helicopter:$g,airplane:Pg,horse:_g,dog:Cg,cat:Hg,cow:Rg,goat:Lg,rabbit:Ng,squirrel:Dg,songbird:Bg,crow:qg,chicken:zg,pigeon:Yg,duck:Kg,owl:jg,parrot:Xg};function Cl(t,e={}){const n=Gn[t];if(!n)throw new Error(dt("prop preset",t,Object.keys(Gn)));return n(e)}const Po=["do","at","for","to","toward","speed","open","on","height","wind"],Hl={viewer:0,right:1,away:2,left:3},Yv=420,Rl={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 Io(t){return{...Rl,...t.actions}}const Ll=t=>typeof t=="number"&&Number.isFinite(t);function Gg(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=Io(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))Po.includes(c)||a(dt("beat field",c,Po,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&&!(Ll(l[c])&&l[c]>=0)&&a(`\`${c}\` must be a number ≥ 0 (got ${JSON.stringify(l[c])}).`);if(l.to!==void 0&&!Ll(l.to)&&a(`\`to\` is a scene x in px (got ${JSON.stringify(l.to)}).`),l.toward!==void 0&&!Ll(l.toward)&&!(typeof l.toward=="string"&&l.toward in Hl)){const c=typeof l.toward=="string"?is(l.toward,Object.keys(Hl)):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 Ug(t,e,n,s={}){const i=Gg(n,e).filter(v=>v.level==="error");if(i.length>0)throw new Error(`propScript (${e.kind}): ${i.length} problem(s) in the beats:
61
- ${i.map(v=>` beat ${v.beat}: ${v.message}`).join(`
62
- `)}`);const o=s.from??0,r=s.ground??0,a=s.scale??60,l=s.exaggeration??1,c=Io(e),h={};for(const v of[...Object.keys(Yn),...Object.keys(e.rig.controls)])h[v]=s.start?.[v]??Et(e.rig,{},v);const d=[{time:0,pose:{...h}}],u=new Map,f=[];let p=o,g=r;const m=(v,T,I,O)=>{const _=u.get(v)??[{time:0,value:v==="x"||v==="y"?0:h[v]}];_.push({time:T,value:I,...O?{easing:O}:{}}),u.set(v,_),v!=="x"&&v!=="y"&&(h[v]=I)},w=(v,T)=>{const I=v==="x"?p-o:v==="y"?g-r:h[v],O=u.get(v);(!O||O[O.length-1].time<T)&&m(v,T,I)},S={prop:e,scale:a,exaggeration:l,get x(){return p},get floor(){return g},values:h,facing(){const v=Math.sin(h.turn*Math.PI/2);return Math.abs(v)<.5?0:v>0?1:-1},key(v,T,I={}){Object.assign(h,T),d.push({time:v,pose:{...h},...I.act===!1?{act:!1}:{},...I.easing?{easing:I.easing}:{}})},move(v,T,I,O={}){w("x",v),m("x",T,I-o,O.easing),p=I,O.floor!==void 0&&(w("y",v),m("y",T,O.floor-r,O.easing),g=O.floor)},set(v,T,I,O){m(v,T,I,O)},turnTo(v,T){const I=typeof T=="number"?T:Hl[T],O=h.turn,C=[I-4,I,I+4].map(q=>({t:q,d:Math.abs(q-O)})).sort((q,X)=>q.d-X.d||Math.abs(q.t)-Math.abs(X.t))[0];if(C.d<.001)return v;const D=v+Yv*Math.max(1,C.d);return S.key(D,{turn:C.t}),D},effect(v){f.push(v)},anchor(v){const I=Kn(e,h,a).anchors[v];if(!I)throw new Error(`${e.kind}: no anchor "${v}"`);return{x:p+I.point.x,y:g+I.point.y}}},k=[];let y=0;for(const v of n){const T=Math.max(v.at??y,d[d.length-1].time),I=c[v.do].run(S,v,T);I.end>d[d.length-1].time&&d.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}:{}}),y=I.end}const E=Qa(s.style??"snappy"),x={...E,anticipation:E.anticipation*l,overshoot:E.overshoot*l},$=go(Gv(d),e.acting,{style:x}),M=[...Object.entries($).filter(([v])=>!u.has(v)).map(([v,T])=>({id:`${t}-${v}`,target:t,property:v,keyframes:T})),...[...u].map(([v,T])=>({id:`${t}-${v}`,target:t,property:v,keyframes:Uv(T)}))];for(const v of jv(t,e,M,y,d[0].pose)){const T=M.findIndex(_=>_.property===v.property);if(T<0){M.push(v);continue}const I=new Ot({id:`${t}-own`,tracks:[M[T]]}),O=_=>Number(I.getStateAtTime(_).values.get(t)?.get(v.property)??0);M[T]={...v,keyframes:v.keyframes.map(_=>({time:_.time,value:Number(_.value)+O(_.time)}))}}return{tracks:M,duration:y,beats:k,effects:f}}const Kv=1500;function jv(t,e,n,s,i){if(!e.follow?.length)return[];const o=new Ot({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+Kv,c=os(u=>r(u,a.of),{start:0,end:l,stiffness:a.stiffness,damping:a.damping}),h=a.limit??1/0,d=c.map(({time:u,value:f})=>{const p=Math.sin(r(u,"turn")*Math.PI/2),g=(f-r(u,a.of))*p;return{time:u,value:Math.max(-h,Math.min(h,g*a.per))}});return{id:`${t}-${a.control}`,target:t,property:a.control,keyframes:d}})}const Xv=20;function Gv(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<Xv?n[n.length-1]={...s,time:i.time}:n.push(s)}return n}function Uv(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 Vv={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 Vg(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(Yt))n[s]={summary:`Moves into the ${s} pose and holds it (\`for\` ms).`};for(const s of Object.keys(Fe))n[s]={summary:`The ${s} gag (${Rs(s)} ms).`};for(const[s,i]of Object.entries(Ns))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(Vv),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:Mo,stickFigure:{poseFields:i0,props:o0,handFields:r0,poses:Object.keys(Yt),expressions:Object.keys(kt),gags:Object.fromEntries(Object.keys(Fe).map(s=>[s,Rs(s)])),gaits:Object.keys(Dt),actingStyles:Object.keys(rn),beatFields:mo,actions:n,dances:Object.fromEntries(Object.entries(Ce).map(([s,i])=>[s,Object.keys(i.moves)])),flips:Object.fromEntries(Object.entries(ks).map(([s,i])=>[s,i.label])),handShapes:Object.keys(_t),mudras:Object.keys($i)},props:{api:{"car() · truck() · bus() · tractor() · cart() · trainCar() · bike() · motorbike()":"wheeled vehicles (vehicle(spec) makes your own)","tree() · house()":"environment (tree(spec), house(spec))","helicopter() · airplane()":"aircraft","horse() · dog() · cat() · cow()":"animals (quadruped(spec) makes your own): gaits with footfall patterns keyed in step with the distance, sit, jump, their calls, species actions","songbird() · crow() · chicken()":"birds (bird(spec) makes your own): hop, walk, peck, flap, fly and land (a chicken flutters), their calls; wings fold and beat in rhythm","{ kind: 'prop', prop: 'car', position, rotation, values } with loadScene3D(scene, { kinds: [characterObjects, propObjects] })":"props in 3D scenes, by preset name, seen in perspective by the scene camera; controls are tracks on the object","characterScript3D(id, beats, { scene, position?, heading?, height?, pose? })":"a v2 character in a 3D scene in world metres: gaits to [x, z] or through points (its walk phase keyed with the distance), face, hold, pose, gag; checkCharacterBeats3D checks the beats","propRide3D({ prop, propId, propTracks, scene, placement, anchor, riderId, pose, start, end, mount?, dismount? })":"a character riding a prop in a 3D scene: hips on a seat anchor (saddle, seat) as it moves, hopping on and off; RIDING_POSES.astride / .seated / .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:Po,commonControls:Object.fromEntries(Object.entries(Yn).map(([s,i])=>[s,`${i.description}${i.unit?` (${i.unit})`:""}`])),commonActions:Object.fromEntries(Object.entries(Rl).map(([s,i])=>[s,i.summary])),presets:Object.fromEntries(Object.entries(Gn).map(([s,i])=>{const o=i();return[s,{family:o.family,summary:o.summary,actions:Object.fromEntries(Object.entries(o.actions).map(([r,a])=>[r,{summary:a.summary,...a.needs?{needs:a.needs}:{}}])),controls:Object.keys(o.rig.controls),anchors:Object.keys(o.rig.anchors??{})}]}))},custom:{api:{"defineAction({ summary, needs?, steps: (from, beat) => [{ after, pose, easing? }] })":"a new action written as timed pose steps from the current pose, like a gag","defineAction({ summary, needs?, beats: (beat) => [beats] })":"a new action built from other beats (which may be custom too)","defineGait({ swing, knee, arm, elbow, lean, cycle?, … })":"a new gait (the Gait fields in degrees; cycle is ms per two steps)","scriptTracks(id, beats, { actions, gaits })":"beats may then use those names; checkBeats(beats, { actions, gaits }) knows them","stickFigureTarget({ …, cast: { actions, gaits } })":"a figure that draws the gaits and lists the actions in describeTarget","persona({ name, summary?, height?, look?, acting?, gait?, mood?, stance?, energy?, actions?, gaits? })":"a character’s look, acting style and habits: .figure({ x, y }), .script(id, beats, { from, ground }), .check(beats), .handPath(…), .describe(); `go` walks in its gait, `stand` returns to its stance and face"},actions:Object.fromEntries(Object.entries(e.actions??{}).map(([s,i])=>[s,{summary:i.summary,...i.needs?{needs:i.needs}:{}}])),gaits:Object.fromEntries(Object.entries(e.gaits??{}).map(([s,i])=>[s,i.summary??"custom gait"]))},character:{poses:Object.keys(ie),expressions:Object.keys(Xr),gags:Object.keys(Zi),builds:Object.keys(Li),hair:Object.keys(ra),hairColors:{...ue},facialHair:Object.keys(da),glasses:Object.keys(fa),hats:Object.keys(Ji),feet:[...sd],cast:Object.keys(Ja),heldItems:Object.fromEntries(Object.entries(wa).map(([s,i])=>[s,i.hands])),handMeetings:Object.keys(Hs)},codePanel:{languages:ho,removeStyles:lo,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:Ka},surfaces:{code:Os,board:be,chart:sn,prop:jn},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: ${qn.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 Mt=t=>t.map(e=>`\`${e}\``).join(", "),Jg=t=>Object.entries(t).map(([e,n])=>`| \`${e}\` | ${n.unit??n.kind??""} | ${n.description} |`).join(`
63
- `);function Jv(t,e={}){const n=Vg(t,e),s=n.stickFigure;return[`# tinyfly capabilities${n.version?` (v${n.version})`:""}`,"","Generated from the library itself: every name below is accepted, and names not listed are rejected (beat scripts, code panels and `checkTracks` say which name was probably meant).","",`**Timing.** ${n.timing}`,"","## Easings","",`Named: ${Mt(n.easings.named)}.`,"",...Object.entries(n.easings.parametric).map(([o,r])=>`- ${o}: \`${r}\``),"","## Track kinds","",...Object.entries(n.trackKinds).map(([o,r])=>`- **${o}**: ${r}`),"","## Canvas targets","","Types: `rect`, `circle`, `text`, `line`, `path`, `image`, `custom`. `describeTarget(target)` lists what one can animate with its values; `checkTracks(tracks, targets)` checks tracks before playing them.","","| Property | Unit | What it does | Types |","|---|---|---|---|",...Object.entries(n.canvasProperties).map(([o,r])=>`| \`${o}\` | ${r.unit??r.kind??""} | ${r.description} | ${r.types.length===7?"all":r.types.join(", ")} |`),"","## Stick figure (`@algorisys/tinyfly/characters`)","","`stickFigureTarget({ x, y, style })` is a custom canvas target; its props are the pose fields and the props below. Pose it with tracks (`poseTracks`), or write beats (`scriptTracks`).","","### Pose fields","","| Field | Unit | What it does |","|---|---|---|",Jg(s.poseFields),"","### Other props","","| Prop | Unit | What it does |","|---|---|---|",Jg(s.props),"",`With \`style.hands\`, each hand has \`hand.left.<field>\` / \`hand.right.<field>\` props: ${Mt(Object.keys(s.handFields))}.`,"",`**Poses** (a beat's \`do\`, or a pose key): ${Mt(s.poses)}.`,"",`**Expressions** (a beat's \`mood\`): ${Mt(s.expressions)}.`,"",`**Gags** (ms): ${Object.entries(s.gags).map(([o,r])=>`\`${o}\` (${r})`).join(", ")}.`,"",`**Gaits**: ${Mt(s.gaits)}. **Acting styles** (\`style\`): ${Mt(s.actingStyles)}.`,"","### Beat scripts","",`\`scriptTracks(target, beats, { from, ground, height, facing, style })\`. A beat has these fields only: ${Mt(s.beatFields)}. Times are ms; \`to\` and \`target\` are scene px; \`onto\` is a floor's scene y.`,"","`characterScript(target, who, beats, options)` compiles the same beats for a v2 `character()` on a `characterTarget` (every option but `height`; the same result, its key poses on the human body; the walk phase keyed to that character's stride, and `walk` / `walking` / `gait` tracks that step the gait as the target draws). Add `hairFollowTracks(target, tracks, who)` after it so hanging hair swings.","","| `do` | Needs | What happens |","|---|---|---|",...Object.entries(s.actions).map(([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**: ${Mt(s.handShapes)}. **Mudras**: ${Mt(s.mudras)}.`,"","### Your own actions, gaits and personas","","Nothing is registered globally: pass your definitions where they are used.","",...Object.entries(n.custom.api).map(([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: ${Mt(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: ${Mt(n.character.poses)}. Expressions: ${Mt(n.character.expressions)}. Gags: ${Mt(n.character.gags)}.`,"","Appearance options of `character({ … })`, all plain data that turns with the head (see docs/character-appearance.md):","",`- \`build\`: ${Mt(n.character.builds)}`,`- \`hair\`: ${Mt(n.character.hair)} (colours: ${Mt(Object.keys(n.character.hairColors))} in \`HAIR_COLORS\`)`,`- \`facialHair\`: ${Mt(n.character.facialHair)}`,`- \`glasses\`: ${Mt(n.character.glasses)}; \`hat\`: ${Mt(n.character.hats)}; \`ears: true\`; \`face: { teeth, tongue }\` (shown when the mouth opens); \`feet\`: ${Mt(n.character.feet)}`,"- `outfit`: `{ 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)\`: ${Mt(n.character.cast)}`,"- Face marks (pose fields, 0–1): `blush`, `tears`, `sweat`","- 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): ${Mt(n.character.handMeetings)}; \`embrace(a, b)\` (a hug, \`embraceSpacing\` apart); \`helpUp(helper, sitter, progress)\` (0 on the floor, hand taken; 1 standing; \`helpUpSpacing\` apart)`,"- Everyday cycles like a gait: `humanCyclePose('sweeping' | 'brushing', phase, base)` (0 → 1 is one stroke and back; sweeping with `holding: { right: 'broom' }`)","","## Code panel","",`\`codePanel({ code, language, x, y, fontSize?, lineHeight?, width? })\`: a code listing as a scene object. Languages: ${Mt(n.codePanel.languages)}. Remove styles: ${Mt(n.codePanel.removeStyles)}.`,"",...Object.entries(n.codePanel.anchors).map(([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 Zv(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=Gt(`${r.kind}:${r.time}:${r.x}`);r.kind==="dust"?of(t,{x:r.x,y:r.y},a,{size:o,color:i,seed:l}):r.kind==="exhaust"?eM(t,r,a,o,i,l):r.kind==="skid"?nM(t,r,a,n,i):r.kind==="honk"?sM(t,r,a,o,i):r.kind==="smoke"?Qv(t,r,n,o,i):r.kind==="leaves"&&tM(t,r,a,o,s.leafColor??"#5cae5a",i,l)}}function Qv(t,e,n,s,i,o){const r=e.direction??1,a=380,l=1500;t.save(),t.strokeStyle=i,t.lineWidth=Math.max(1,s*.025);for(let c=e.time;c<=e.time+e.length-l;c+=a){const h=(n-c)/l;if(h<=0||h>=1)continue;const d=Math.sin(c/97+h*4)*s*.06,u=e.x+r*h*s*.7+d,f=e.y-h*s*1.6;t.globalAlpha=Math.min(1,h*6)*(1-h)*.85,t.beginPath(),t.arc(u,f,s*(.07+h*.2),0,Math.PI*2),t.stroke()}t.restore()}function tM(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=Gt(`${r}:${c}`)%1e3/1e3,d=Math.min(1,n*(1.1+h*.4)),u=e.x+(h-.5)*s*1.2,f=e.y+(h-.3)*s*.4,p=d*d*.4+d*.6,g=u+a*d*s*(.6+h)+Math.sin(d*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(d*7+h*5)*1.2),t.beginPath(),t.ellipse(0,0,s*.07,s*.035,0,0,Math.PI*2),t.fill(),t.stroke(),t.restore()}t.restore()}function eM(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=(Gt(`${o}:${a}`)%100/100-.5)*s*.1,h=e.x+r*l*s*.9,d=e.y-l*s*.45+c;t.globalAlpha=(1-l)*.9,t.beginPath(),t.arc(h,d,s*(.06+l*.14),0,Math.PI*2),t.stroke()}t.restore()}function nM(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 sM(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 iM(t){const e=new Ot({id:`${t.propId}-ride`,tracks:t.propTracks.filter(h=>h.target===t.propId)}),n=t.every??33,s=[],i=[],o=[],r=[];let a=1;for(let h=t.start;;h=Math.min(t.end,h+n)){const d=Eo(t.prop,{state:e.getStateAtTime(h)},t.propId),u=d.anchor(t.anchor);s.push({time:h,value:u.x+(t.offset?.x??0)-t.figure.x}),i.push({time:h,value:u.y+(t.offset?.y??0)-t.figure.y});const f=Math.sin(d.values.turn*Math.PI/2);if(Math.abs(f)>.15&&(a=f>0?1:-1),o.push({time:h,value:Math.abs(f)}),r.push({time:h,value:a}),h>=t.end)break}const l=t.figureId,c=[{id:`${l}-x`,target:l,property:"x",keyframes:s},{id:`${l}-y`,target:l,property:"y",keyframes:i}];return t.turn!==!1&&c.push({id:`${l}-turn`,target:l,property:"turn",keyframes:o},{id:`${l}-facing`,target:l,property:"facing",keyframes:oM(r)}),c}function oM(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 rM(t,e,n){const s=r=>`${r.target}\0${r.property}`,i=new Map(e.map(r=>[s(r),r]));return[...t.map(r=>{const a=i.get(s(r));if(!a)return r;i.delete(s(r));const c=[...(r.keyframes??[]).filter(h=>h.time<n.from||h.time>n.to),...a.keyframes??[]].sort((h,d)=>h.time-d.time);return{...r,keyframes:c}}),...i.values()]}function aM(t){const e=new Ot({id:`${t.leaderId}-tow`,tracks:t.leaderTracks.filter(f=>f.target===t.leaderId)}),n=t.every??33,s=t.towed,i=s.x+s.width/2,o=s.props,r=s.prop.wheelRadius,a=[],l=[],c=[];let h=o.wheelSpin??0,d;for(let f=t.start;;f=Math.min(t.end,f+n)){const p=Eo(t.leader,{state:e.getStateAtTime(f)},t.leaderId),g=p.anchor(t.hitch),m=p.values.turn,w=Kn(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 S=g.x-w.point.x;if(d!==void 0&&r){const k=Math.sin(m*Math.PI/2);h+=(S-d)*(k||1)/s.propScale/r*(180/Math.PI)}if(d=S,a.push({time:f,value:S-i}),l.push({time:f,value:m}),c.push({time:f,value:h}),f>=t.end)break}const u=t.towedId;return[{id:`${u}-x`,target:u,property:"x",keyframes:a},{id:`${u}-turn`,target:u,property:"turn",keyframes:l},...r?[{id:`${u}-wheelSpin`,target:u,property:"wheelSpin",keyframes:c}]:[]]}const Zg=new WeakMap;function lM(t,e){const n=e?.some(Boolean)?e.map(u=>u?1:0).join(""):"";let s=Zg.get(t);s||Zg.set(t,s=new Map);const i=s.get(n);if(i)return i;const o=Ws(t),r={vertices:o.vertices,faces:o.faces.filter((u,f)=>!e?.[f])},a=r.vertices.flatMap(u=>[u[0],u[1],u[2]]),l=r.vertices.map(()=>[0,0,0]),c=[];r.faces.forEach(u=>{for(const g of u.corners)for(const m of[0,1,2])l[g][m]+=u.normal[m];const[f,...p]=u.corners;for(let g=0;g+1<p.length;g++){const[m,w,S]=[f,p[g],p[g+1]],[k,y,E]=[r.vertices[m],r.vertices[w],r.vertices[S]],x=[y[0]-k[0],y[1]-k[1],y[2]-k[2]],$=[E[0]-k[0],E[1]-k[1],E[2]-k[2]],M=[x[1]*$[2]-x[2]*$[1],x[2]*$[0]-x[0]*$[2],x[0]*$[1]-x[1]*$[0]],v=M[0]*u.normal[0]+M[1]*u.normal[1]+M[2]*u.normal[2];c.push(...v>=0?[m,w,S]:[m,S,w])}});const h=l.flatMap(u=>{const f=Math.hypot(...u)||1;return[u[0]/f,u[1]/f,u[2]/f]}),d=qi({positions:a,normals:h,indices:c});return s.size>=16&&s.clear(),s.set(n,d),d}function cM(t,e,n={}){const s=t.ink??n.ink??"#26262b",i=(n.outline??2)*(t.outline??1),o=t.glow&&e.glow>0?hM(t.glow.color,e.glow):void 0;return{color:t.fill??s,creases:Ws(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 hM(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 dM=qi(cd(1,.002,28));function uM(t,e,n){const s=t.rig,[i,o]=s.footprint??[s.length*.45,s.length],r=Math.max(0,Et(s,e,"lift")),a=Math.max(0,Et(s,e,"size"))/(1+r*.8);return{mesh:dM,world:At(n,ar([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 fM=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),gM=1,pM={kind:"prop",validate(t){const e=t,n=typeof e.prop=="string"&&e.prop in Gn?[]:[dt("prop preset",e.prop,Object.keys(Gn))];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 Cl(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]of n)typeof M=="number"&&!fM.has($)&&(h[$]=M);h.turn=0,h.tilt=0;const d=At(i.view,s),u={toView:$=>Bt(d,$),toScreen:$=>a($)},f=u.toView([0,c.rig.height/2,0]);if(-f[2]<=i.near)return null;if(l.look==="mesh"){const $=Jf(c.rig,h),M=$.map(({part:I,local:O})=>({part:I.id,mesh:Ws(I.shape),...vl(Ws(I.shape),O)})),v=Kf(M),T=$.map((I,O)=>({...I,hidden:Xf(I.part.id,M[O].mesh,I.local,M[O].key,v)})).filter(({opacity:I})=>I>.01).map(({part:I,matrix:O,glow:_,opacity:C,hidden:D})=>({mesh:lM(I.shape,D),world:At(s,O),material:cM(I,{glow:_,opacity:C},{shading:l.shading,ink:l.ink,outline:l.outline})}));return{meshes:l.shadow===!1?T:[uM(c,h,s),...T]}}const p=a(f),g=a(u.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)=>{const v=Bt(s,$),T=[s[0]*M[0]+s[4]*M[1]+s[8]*M[2],s[1]*M[0]+s[5]*M[1]+s[9]*M[2],s[2]*M[0]+s[6]*M[1]+s[10]*M[2]],I=Math.hypot(...T)||1;return{light:hu(v,[T[0]/I,T[1]/I,T[2]/I],o),fog:du(r,Math.hypot(v[0]-i.position[0],v[1]-i.position[1],v[2]-i.position[2]))}},S=Al(c.rig,h,u,m,{perspective:!0,near:i.near,slice:gM,light:w}),k={look:l.look,style:l.style,ink:l.ink,paper:l.paper,fog:r?.color},y=Pa(S),E=S.cells??[],x=Math.max(...E.map($=>-$.depth),-f[2]);return{drawables:[...l.shadow===!1?[]:[{depth:x+c.rig.length,draw:$=>Ia($,S,k)}],...E.map($=>({depth:-$.depth,draw(M,v){M.lineCap="round",M.lineJoin="round",fu(M,$.parts,y,{...k,time:v.time})}}))]}}},Nl=["do","at","for","to","through","toward","speed","height","open","on","wind"],mM=.25,yM=800/180,bM=220,wM=300,kM=["turn"];function vM(t){const e=Io(t),n=Object.keys(t.moves??{});return Object.keys(e).filter(s=>!n.includes(s)&&!kM.includes(s)&&!(e[s].needs??[]).includes("to"))}function Qg(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=vM(e),i=[...n,"face","hold",...s.filter(r=>r!=="hold")],o=[];return t.forEach((r,a)=>{const l=d=>o.push({beat:a,message:d});if(!r||typeof r!="object"||Array.isArray(r))return l(`Each beat must be an object like { do: '${i[0]??"hold"}' }.`);const c=r,h={duration:"for",path:"through",points:"through",position:"to",heading:"toward",direction:"toward"};for(const d of Object.keys(c))Nl.includes(d)||l(dt("beat field",d,Nl,h[d]));if(typeof c.do!="string"||!i.includes(c.do)){const d=c.do==="turn"?"face":void 0;return l(dt(`${e.kind} 3D beat`,c.do,i,d))}n.includes(c.do)&&(c.to===void 0&&c.through===void 0&&l(`\`${c.do}\` needs \`to\` ([x, z] metres) or \`through\` (a list of them).`),c.to!==void 0&&!en(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(en))&&l("`through` is a list of points on the ground, each [x, z] metres.")),c.do==="face"&&!(en(c.toward)||typeof c.toward=="number")&&l("`face` needs `toward`: a point [x, z] or a heading in degrees.")}),o}function MM(t,e,n,s){const i=Qg(n,e);if(i.length>0)throw new Error(`propScript3D (${e.kind}): ${i.length} problem(s) in the beats:
58
+ `)}`)}$b(vl);function gv(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 pv(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 Lf=8;function Eo(t,e={},n=0){if(n>Lf)throw new Error(`scriptTracks: custom actions nest more than ${Lf} 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 Eo(o,e,n+1)})}function Nf(t){return t.length===0?0:Math.max(...t.map(e=>e.after))}const Sl={walk:1e3,bouncy:900,doubleBounce:1100,sneak:1600,strut:1100,tired:1500,shove:1300,run:560},mv=450,yv=2.4,bv=160,Ff=2.5,wv=200,kv=340,vv=1.1,Df=[380,900],Mv=.35,Ao=300,Tl=150,Sv=260,Tv=1.2,xl=160,Wf=400,js=300,xv=450,Bf=500,El=350,zf=150,Ev=120,Al=180,qf=420,Av=300,Yf=300,Pv=140,Pl=150,jf=450,$v=450,$l=150,Kf=350,Xf=400,Iv=12,Ov=600,Gf=90,Uf=400,_v=200,Cv=.09,Vf=350,we=450,Il=1200,Hv=700,Yn=320,ke=220,Rv=65,Lv=700,Jf=t=>t in We,Nv=t=>t in Gt;function Zf(t){return Math.max(Lv,Array.from(t).length*Rv)}function Po(t,e,n={}){const s={actions:n.actions,gaits:n.gaits};Ml(e,s);const i=n.gait??"walk",o=Eo(e,n.actions).map($=>$.do==="go"?{...$,do:i}:$);Ml(o,s,"scriptTracks (after expanding custom actions)");const r=$=>Ft[$]??n.gaits?.[$],a=$=>Sl[$]??n.gaits?.[$]?.cycle??1e3,l=$=>{const L=n.actions?.[$];return L&&"steps"in L?L: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}],M=[{time:0,value:0}],E=[{time:0,value:0}],A=[{time:0,value:"walk"}],T=[{time:0,value:p}],S=[],x=[],O=[],I=($,L,W,q)=>{g={...g,...L},W&&(g=_e(g,W)),v.push({time:$,pose:g,...q===!1?{act:q}:{}})},_=($,L,W)=>(I($+Yn/2,{turn:0},W),T.push({time:$+Yn/2,value:p},{time:$+Yn/2+1,value:L}),p=L,I($+Yn,{turn:1}),$+Yn),C=$=>$<d?-1:1,F=($,L,W)=>C(L)!==p?_($,C(L),W):$,z=($,L,W,q="arm")=>{const B=q==="arm",Y=ie({...$,...B?{rightShoulder:0,rightElbow:0}:{rightHip:0,rightKnee:0}},{height:u,facing:p}),U=B?Y.shoulders.right:Y.hip,D=B?Y.elbows.right:Y.knees.right,V=(ot,rt)=>Math.atan2(p*ot,rt)*180/Math.PI,st=((V(L-(d+U.x),W-(f+U.y))-V(D.x-U.x,D.y-U.y))%360+360)%360;return st>270?st-360:st},X=($,L,W,q)=>{const B=q==="arm",Y=ie({...$,...B?{rightShoulder:90,rightElbow:0,rightWrist:0}:{rightHip:90,rightKnee:0}},{height:u,facing:p}),U=B?Y.shoulders.right:Y.hip,D=B?{x:(Y.hands.right.x+Y.fingertips.right.x)/2,y:(Y.hands.right.y+Y.fingertips.right.y)/2}:Y.feet.right,V=Math.hypot(D.x-U.x,D.y-U.y)*((B?n.reach?.arm:n.reach?.leg)??1),j=W-(f+U.y),st=Math.abs(j)<V?Math.sqrt(V*V-j*j):V*.1;return L-U.x-p*st},J=$=>{const L=ie($,{height:u,facing:p});return{x:d+(L.hands.right.x+L.fingertips.right.x)/2,y:f+(L.hands.right.y+L.fingertips.right.y)/2}},K=($,L,W)=>{const q={...$,rightWrist:0,rightElbow:0,rightShoulder:z($,L,W)},B=ie(q,{height:u,facing:p}),Y={x:d+B.shoulders.right.x,y:f+B.shoulders.right.y},U={x:d+B.elbows.right.x,y:f+B.elbows.right.y},D=J(q),V=Math.hypot(U.x-Y.x,U.y-Y.y),j=Math.hypot(D.x-U.x,D.y-U.y),st=Math.min(V+j-.01,Math.max(Math.abs(V-j)+.01,Math.hypot(L-Y.x,W-Y.y))),ot=et=>et*180/Math.PI,rt=ot(Math.acos((V*V+st*st-j*j)/(2*V*st))),at=180-ot(Math.acos((V*V+j*j-st*st)/(2*V*j)));let H={rightShoulder:q.rightShoulder,rightElbow:0},Z=1/0;for(const et of[1,-1])for(const it of[1,-1]){const tt={rightShoulder:q.rightShoulder+et*rt,rightElbow:it*at},lt={...$,rightWrist:0,...tt},Q=J(lt),nt=Math.hypot(Q.x-L,Q.y-W)-ie(lt,{height:u,facing:p}).elbows.right.y*.001;nt<Z&&(Z=nt,H=tt)}return H},P=($,L,W)=>Math.abs(L-d)<2?$:(k.push({time:$,value:d-c},{time:$+W,value:L-c,easing:"ease-in-out"}),d=L,$+W);for(const $ of o){const L=Math.max($.at??w,w===0?0:v[v.length-1].time);let W=L,q,B;const Y=$.pose??{},U=l($.do);if(r($.do)){const D=$.to??d,V=D===d?p:C(D);let j=L;V!==p?j=_(L,V,$.mood):g.turn<1?(j=L+ke,I(j,{turn:1,...Y},$.mood)):($.mood||$.pose)&&I(L+ke,Y,$.mood);const ot=Math.abs(D-d)/Ii(r($.do),u),rt=$.for??Math.max(ke*2,ot*a($.do)),at=j+rt;A.push({time:j,value:$.do}),E.push({time:j,value:0},{time:j+ke,value:1,easing:"ease-out"}),E.push({time:at-ke,value:1},{time:at,value:0,easing:"ease-in"}),M.push({time:j,value:m},{time:at,value:m+ot}),k.push({time:j,value:d-c},{time:at,value:D-c}),m+=ot,d=D,I(at,{}),W=at}else if($.do==="zip"){const D=$.to??d,V=D===d?p:C(D);let j=L;V!==p?j=_(L,V,$.mood):g.turn<1&&(j=L+ke,I(j,{turn:1},$.mood));const st=yl("windUp",{at:j,from:$.mood?_e(g,$.mood):g});v.push(...st),g=st[st.length-1].pose;const ot=j+zs("windUp"),rt=ot+mv,at=rt+Math.max(bv,Math.abs(D-d)/yv);A.push({time:ot,value:"run"}),E.push({time:ot,value:0},{time:ot+80,value:1,easing:"ease-out"},{time:at,value:1},{time:at+120,value:0}),M.push({time:ot,value:m},{time:rt,value:m+Ff,easing:"ease-in"}),m+=Ff+(at-rt)/Sl.run*1.5,M.push({time:at,value:m}),k.push({time:rt,value:d-c},{time:at,value:D-c,easing:"ease-in"}),O.push({kind:"dust",time:rt,x:d,y:f,length:900}),d=D,I(at,{}),W=at}else if($.do==="leap"){const D=$.to??d,V=$.onto??f;let j=D===d?L:F(L,D,$.mood);g.turn<1&&(j+=ke,I(j,{turn:1},$.mood));const st={leftShoulder:35,rightShoulder:35,leftElbow:-50,rightElbow:-50};I(j+wv,{stretch:.75,bend:12,leftHip:22,rightHip:22,...st},$.mood,!1);const ot=j+kv;I(ot-40,{stretch:.72},void 0,!1),I(ot,{stretch:1.2,bend:-6,leftShoulder:140,rightShoulder:140,leftElbow:20,rightElbow:20,leftHip:4,rightHip:4},void 0,!1);const rt=Math.hypot(D-d,V-f),at=$.for??Math.min(Df[1],Math.max(Df[0],300+rt*vv)),H=Math.min(f,V)-Mv*u,Z=Math.sqrt(f-H),et=Math.sqrt(V-H),it=ot+at*Z/(Z+et),tt=ot+at;I(it,{stretch:1,bend:4,leftHip:-55,leftKnee:-80,rightHip:55,rightKnee:80,leftShoulder:110,rightShoulder:110},void 0,!1),I(tt,{stretch:.72,bend:12,leftShoulder:75,rightShoulder:75,leftElbow:0,rightElbow:0,leftHip:18,rightHip:18,leftKnee:0,rightKnee:0},void 0,!1),I(tt+180,{stretch:1.05,bend:-3},void 0,!1),I(tt+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:ot,value:d-c},{time:tt,value:D-c}),b.push({time:ot,value:f-h},{time:it,value:H-h,easing:"ease-out-quad"},{time:tt,value:V-h,easing:"ease-in-quad"}),d=D,f=V,O.push({kind:"dust",time:tt,x:d,y:f,length:500}),W=tt+340,q=tt}else if($.do==="point"&&$.target){const D=$.target,V=F(L,D.x,$.mood),j={...g,...$.mood?kt[$.mood]:{},turn:Math.max(g.turn,.6),rightElbow:0,rightWrist:0,...Y},st=ie(j,{height:u,facing:p}).head.center,ot=Math.abs(D.x-(d+st.x)),rt=D.y-(f+st.y),at=V+we;I(at,{...j,rightShoulder:z(j,D.x,D.y),lookX:1,lookY:Fv(rt/Math.max(1,Math.hypot(ot,rt)))*.8}),W=at+($.for??Il),q=at,B=W}else if($.do==="swipe"){const D=$.target??{x:d+p*u*.5,y:f-u*.6},V=C(D.x),j=F(L,D.x,$.mood),st=V===1?D.left??D.x:D.right??D.x,ot=V===1?D.right??D.x:D.left??D.x,rt={...g,turn:1,lean:-10,bend:-8,rightElbow:40,lookX:1,...Y};I(j+Ao,{...rt,rightShoulder:z(rt,d-p*u*.3,f-u*1.1)},$.mood,!1);const at={...g,lean:6,bend:4,rightElbow:0,rightWrist:0},H={...g,lean:14,bend:12,rightElbow:0,rightWrist:0};P(j,X(at,st,D.y,"arm"),Ao+Tl),I(j+Ao+Tl,{lean:-12},void 0,!1);const Z=j+Ao+Tl+80;I(Z,{...at,rightShoulder:z(at,st,D.y)},void 0,!1);const et=Z+($.for??Math.max(Sv,Math.abs(ot-st)/Tv));k.push({time:Z,value:d-c}),d=X(H,ot,D.y,"arm"),k.push({time:et,value:d-c}),I(et,{...H,rightShoulder:z(H,ot,D.y)},void 0,!1),I(et+xl,{lean:16,bend:14,rightShoulder:z(g,ot+V*u*.4,D.y+u*.25)},void 0,!1),I(et+xl+Wf,{lean:0,bend:0,rightShoulder:ct.rightShoulder,rightElbow:ct.rightElbow}),W=et+xl+Wf,q=Z,B=et}else if($.do==="grab"&&$.target){const D=$.target,V=F(L,D.x,$.mood),j=D.y>f-u*.5,st={...g,turn:1,rightElbow:0,bend:j?35:0,lean:j?12:0,stretch:j?.75:1,lookX:1,lookY:j?.8:0,...Y},rt=P(V,X(st,D.x,D.y,"arm"),js)+xv;I(rt,{...st,rightShoulder:z(st,D.x,D.y)},$.mood,!1),I(rt+120,{},void 0,!1),I(rt+Bf,{bend:0,lean:-3,stretch:1,rightShoulder:165,rightElbow:20,lookY:-.6}),W=rt+Bf+150,q=rt}else if($.do==="throw"){const D=$.target?.x??$.to??d+p*u,V=F(L,D,$.mood),j={...g,turn:1,lean:-12,bend:-10,rightElbow:60,stretch:.95,lookX:1,lookY:-.3,...Y};I(V+El,{...j,rightShoulder:z(j,d-p*u*.4,f-u*1.05)},$.mood,!1),I(V+El+zf,{lean:-14},void 0,!1);const st=V+El+zf+Ev,ot={...g,lean:14,bend:12,rightElbow:0,stretch:1.04};v.push({time:st,pose:g={...ot,rightShoulder:z(ot,d+p*u,f-u*1.1)},easing:"ease-in",act:!1}),I(st+Al,{lean:18,bend:14,rightShoulder:55,stretch:1},void 0,!1),I(st+Al+qf,{lean:0,bend:0,rightShoulder:ct.rightShoulder,rightElbow:ct.rightElbow,lookY:0}),W=st+Al+qf,q=st,B=st}else if($.do==="kick"&&$.target){const D=$.target,V=F(L,D.x,$.mood),j={...g,turn:1,lean:-12,bend:-6,rightKnee:0,leftShoulder:100,rightShoulder:70},st=P(V,X(j,D.x,D.y,"leg"),Av),ot={leftShoulder:70,rightShoulder:50,leftElbow:-20,rightElbow:20};I(st+Yf,{turn:1,lean:8,bend:6,rightHip:-40,rightKnee:80,lookX:1,lookY:.7,...ot,...Y},$.mood,!1);const rt=st+Yf+Pv,at=z(j,D.x,D.y,"leg");v.push({time:rt,pose:g={...g,...j,rightHip:at},easing:"ease-in",act:!1}),I(rt+Pl,{lean:-15,rightHip:at+20},void 0,!1),I(rt+Pl+jf,{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+Pl+jf,q=rt}else if($.do==="put"&&$.target){const D=$.target,V=F(L,D.x,$.mood),j=D.y>f-u*.5,st={...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,...Y},rt=P(V,X(st,D.x,D.y,"arm"),js)+$v;I(rt,{...st,rightShoulder:z(st,D.x,D.y)},$.mood,!1),I(rt+$l,{},void 0,!1),I(rt+$l+Kf,{bend:0,lean:0,stretch:1,rightShoulder:ct.rightShoulder,rightElbow:ct.rightElbow,lookY:0}),W=rt+$l+Kf,q=rt}else if($.do==="write"&&$.target){const D=$.target,V=D.left??D.x,j=D.right??D.x,st=F(L,(V+j)/2,$.mood),ot={...g,turn:1,rightElbow:0,rightWrist:0,...kt.thinking,lookX:1,lookY:0,...Y},rt=Q=>X(ot,Q,D.y,"arm")+p*u*.08,at=Q=>{const G=J({...ot,...K(ot,Q,D.y),rightWrist:0});return Math.hypot(G.x-Q,G.y-D.y)<2},H=p===1?V:j,Z=P(st,rt((V+j)/2),js),et=!at(V)||!at(j),it=et?P(Z,rt(V),js)+Xf:Z+Xf;I(it,{...ot,...K(ot,et?V:H,D.y)},$.mood,!1);const tt=$.for??Math.max(Ov,Math.abs(j-V)*Iv);et&&k.push({time:it,value:d-c});for(let Q=Gf,G=0;Q<=tt;Q+=Gf,G++){const nt=V+(j-V)*Math.min(Q,tt)/tt;et&&(d=rt(nt),k.push({time:it+Q,value:d-c}));const ht=(G%2===0?-1:1)*u*.02;I(it+Q,K(ot,nt,D.y+ht),void 0,!1)}const lt=it+tt;I(lt,K(ot,j,D.y),void 0,!1),I(lt+Uf,{rightShoulder:ct.rightShoulder,rightElbow:ct.rightElbow,...kt.happy}),W=lt+Uf,q=it,B=lt}else if($.do==="push"&&$.target){const D=$.target,V=$.to??D.x,j=F(L,d+(V>=D.x?1:-1),$.mood),st=p===1?D.left??D.x:D.right??D.x,ot={...g,turn:1,lean:16,bend:8,rightWrist:0,leftWrist:0,lookX:1,...Y},rt=X(ot,st,D.y,"arm"),at=P(j,rt+p*u*.06,js),H=K(ot,st,D.y),Z={...ot,...H,leftShoulder:-H.rightShoulder,leftElbow:-H.rightElbow},et=at+_v;I(et,Z,$.mood,!1);const it=Math.abs(V-D.x),tt=et+($.for??Math.max(600,it/Cv)),lt=it/Ii("shove",u);A.push({time:et,value:"shove"}),E.push({time:et,value:0},{time:et+ke,value:1,easing:"ease-out"},{time:tt-ke,value:1},{time:tt,value:0,easing:"ease-in"}),M.push({time:et,value:m},{time:tt,value:m+lt}),m+=lt,k.push({time:et,value:d-c},{time:tt,value:d+(V-D.x)-c}),d+=V-D.x,I(tt,{},void 0,!1),I(tt+Vf,{lean:0,bend:0,rightShoulder:ct.rightShoulder,leftShoulder:ct.leftShoulder,rightElbow:ct.rightElbow,leftElbow:ct.leftElbow}),W=tt+Vf,q=et,B=tt}else if(U){const D=$.mood?_e(g,$.mood):g,V=U.steps(D,$),j=bl(V,{at:L,from:D});v.push(...j),g=j[j.length-1].pose,W=L+Math.max(Nf(V),$.for??0)}else if(Jf($.do)){const D=yl($.do,{at:L,from:$.mood?_e(g,$.mood):g});v.push(...D),g=D[D.length-1].pose,W=L+zs($.do),$.do==="take"&&O.push({kind:"dust",time:L+900,x:d,y:f,length:500}),$.do==="land"&&O.push({kind:"dust",time:L+120,x:d,y:f,length:500})}else if($.do==="look"||$.do==="face"){const D=$.toward??"viewer",V=$.for??Hv;if(D==="viewer")I(L+we,{turn:0,lookX:0,lookY:0,...Y},$.mood);else if(D==="ahead")I(L+we,{turn:$.do==="face"?1:.6,lookX:1,...Y},$.mood);else if(D==="back")I(L+we,{turn:.2,lookX:-1,...Y},$.mood);else{const j=C(D);j!==p&&$.do==="face"?(_(L,j,$.mood),I(L+Yn+1,{lookX:1,...Y})):j!==p?I(L+we,{turn:.25,lookX:-1,...Y},$.mood):I(L+we,{turn:$.do==="face"?1:.6,lookX:1,...Y},$.mood)}W=L+Math.max(V,we)}else if(Nv($.do)||$.do==="stand"){const D=$.do==="stand"?n.rest??ct:Gt[$.do],V=D.turn!==ct.turn?D.turn:g.turn,j=$.mood?kt[$.mood]:{lookX:g.lookX,lookY:g.lookY};I(L+we,{...D,turn:V,...j,...Y}),W=L+($.for??Il)}else{const D=$.for??($.say?Zf($.say):Il);($.mood||$.pose)&&I(L+Math.min(we,D/2),Y,$.mood),W=L+D}if($.say){const D=r($.do)||Jf($.do)||U?L:L+Math.min(150,(W-L)/4),V=r($.do)?W:Math.max(D+200,W-100);S.push({text:$.say,start:D,end:V}),$.do==="say"&&Bv(v,g,D,V)}$.onto!==void 0&&$.do!=="leap"&&$.onto!==f&&(b.push({time:L,value:f-h},{time:W,value:$.onto-h,easing:"ease-in-out"}),f=$.onto),W>v[v.length-1].time&&v.push({time:W,pose:g}),x.push({start:L,end:W,...q!==void 0?{contact:q}:{},...B!==void 0?{release:B}:{}}),w=W}const R=Of(t,Wv(v),n),N=[{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:M},{id:`${t}-walking`,target:t,property:"walking",keyframes:E},{id:`${t}-gait`,target:t,property:"gait",keyframes:A},{id:`${t}-facing`,target:t,property:"facing",keyframes:T}].filter($=>$.keyframes.length>1||$.property==="x"||$.property==="facing"&&$.keyframes[0].value===-1);return{tracks:[...fo(t,R,S,{energy:n.energy}),...N],duration:w,lines:S,keys:v,beats:x,effects:O}}const Fv=t=>Math.max(-1,Math.min(1,t)),Dv=30;function Wv(t){const e=[];for(const n of t){const s=e[e.length-1];s&&n.time-s.time<Dv?e[e.length-1]={...n,time:s.time}:e.push(n)}return e}function Bv(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 Ol(t,e,n){const s=new Et({id:`${t}-hand`,tracks:e.filter(l=>l.target===t)}),i=Qr({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 jn=["start","contact","release","end"],zv=["surface","edit","anchor","at","until"],qv=["carry"],$o=t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&"surface"in t&&"anchor"in t,Yv=t=>t.then===void 0?[]:Array.isArray(t.then)?t.then:[t.then];function jv(t,e,n,s={}){const i=Qf(n,e,s).filter(d=>d.level==="error");if(i.length>0)throw new Error(`surfaceScript: ${i.length} problem(s) in the beats:
59
+ ${i.map(d=>` ${d.beat>=0?`beat ${d.beat}: `:""}${d.message}`).join(`
60
+ `)}`);const o=n.map(d=>tg(d,e)),r=Po(t,o,s),a=Kv(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 Yv(d)){const g=b=>new Error(`surfaceScript: beat ${f} (${d.do}), ${p.edit} on ${p.surface}: ${b}`),m=(b,M)=>{const E=typeof b=="object"?b.beat:f,A=(typeof b=="object"?b.at:b)??M??"start",T=a[E][A];if(T===void 0){const S=jn.filter(x=>a[E][x]!==void 0).join(", ");throw g(`beat ${E} (${n[E].do}) has no ${A} (it has ${S})`)}return T},w=e[p.surface],v=m(p.at??(a[f].contact!==void 0?"contact":"start")),k=p.until===void 0?void 0:m(p.until,"end");if(k!==void 0&&k<v)throw g(`it ends (${k} ms) before it starts (${v} ms)`);try{if(p.edit==="carry"){const M=w.piece(p.anchor),E=Ol(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(M,E);continue}const b=Object.fromEntries(Object.entries(p).filter(([M])=>!zv.includes(M)));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 Qf(t,e,n={}){if(!Array.isArray(t))return Ys(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}: ${ut("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 (${jn.join(", ")}), not at ms; set the beat's own \`at\` to move it.`}):(typeof d!="string"||!jn.includes(d))&&s.push({level:"error",beat:c,message:`${u}: ${ut("moment",d,jn)}`})};t.forEach((c,h)=>{if(!c||typeof c!="object"||Array.isArray(c))return;const u=c;for(const f of["target","to","onto"]){if(!$o(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),...qv];if(typeof p.edit!="string"||!w.includes(p.edit)){s.push({level:"error",beat:h,message:`\`then\`: ${ut("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)?tg(c,e,!0):c);return[...Ys(l,n),...s]}function tg(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 $o(t.target)&&(r.target=o(t.target)),$o(t.to)&&(r.to=o(t.to).x),$o(t.onto)&&(r.onto=o(t.onto).top),r}function Kv(t,e,n){let s=0;return t.map(i=>{const o=Eo([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 Xv(t){const e={actions:t.actions,gaits:t.gaits},n=kl(e);if(n.length>0)throw new Error(`persona "${t.name}": ${n.join(" ")}`);const s=[...Object.keys(Ft),...Object.keys(t.gaits??{})],i=t.gait??"walk";if(!s.includes(i))throw new Error(`persona "${t.name}": ${ut("gait",i,s)}`);if(t.mood&&!(t.mood in kt))throw new Error(`persona "${t.name}": ${ut("mood",t.mood,Object.keys(kt))}`);const o=t.acting??"snappy";if(typeof o=="string"&&!(o in ln))throw new Error(`persona "${t.name}": ${ut("acting style",o,Object.keys(ln))}`);if(typeof t.stance=="string"&&!(t.stance in Gt))throw new Error(`persona "${t.name}": ${ut("stance",t.stance,Object.keys(Gt))}`);const r=t.height??120,a=typeof t.stance=="string"?Gt[t.stance]:Ct(t.stance??{}),l=t.mood?_e(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=>Qr({x:u.x,y:u.y,pose:l,style:{...c,...u.facing?{facing:u.facing}:{}},cast:e}),script:(u,d,f={})=>Po(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=>Ys(u,e),handPath:(u,d,f)=>Ol(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:vl(e),own:{actions:Object.keys(t.actions??{}),gaits:Object.keys(t.gaits??{})}})}}const Gv=new Set(["x","y","walking","gait"]),eg=.215+.205;function ng(t,e,n=1){const{points:s}=ee(t,gt),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):eg*t.height;return Pa(e,a/eg,n)}function Uv(t,e,n,s={}){const i=Po(t,n,{...s,height:e.height,reach:s.reach??sg(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=Ci(i.keys),l=i.keys.map((w,v)=>{const k=xu(a[v]);return{time:w.time,pose:r(w.time)<0?Mu(k):k,...w.easing?{easing:w.easing}:{},...w.act===!1?{act:!1}:{}}}),{rest:c,start:h,...u}=s;Zv(l,a,n,i,e,r,s);const d=_f(t,l,u),f=fo(t,d,i.lines,{energy:s.energy}),p=i.tracks.filter(w=>Gv.has(w.property)),g=i.tracks.find(w=>w.property==="walk");return{tracks:g?[...f,...p,iM(t,g,i.tracks,e,s)]:[...f,...p],duration:i.duration,lines:i.lines,keys:l,beats:i.beats,effects:i.effects}}function sg(t){const e=bt({"arm.left.spread":90,"arm.left.elbow":0,"arm.left.bend":0,"leg.left.knee":0}),n=ee(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=ie({...ct,rightShoulder:90,rightElbow:0,rightWrist:0},{height:t.height,facing:1}),r=ie({...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 Vv={point:"arm",grab:"arm",put:"arm",write:"arm",swipe:"arm",push:"arm",kick:"leg"},Jv=new Set(["point","grab","put","kick"]);function Zv(t,e,n,s,i,o,r){const a=s.beats;if(n.length!==a.length)return;const l=new Et({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=Vv[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=ie(e[w],{height:i.height,facing:v<0?-1:1}),b=c(m.time),M=Jv.has(h.do)&&h.target?{x:h.target.x-b.x,y:h.target.y-b.y}:void 0,E={x:(k.hands.right.x+k.fingertips.right.x)/2,y:(k.hands.right.y+k.fingertips.right.y)/2},A=M??(d==="arm"?E:k.toes.right),T=v<0?"right":"left",S=`${d}.${T}`;let x=m.pose;if(h.do==="point")x=ye(i,x,S,A);else if(d==="arm")x=ye(i,sM(i,x,T,A),S,A);else for(let O=0;O<3;O++){const I=ee(i,x).points,_=I[`ankle.${T}`],C=I[`toe.${T}`];x=ye(i,x,S,{x:A.x-(C.x-_.x),y:A.y-(C.y-_.y)})}t[w]={...m,pose:x}})})}function Qv(t,e){const n=bt({[`arm.${e}.spread`]:90,[`arm.${e}.elbow`]:0,[`arm.${e}.bend`]:0}),s=ee(t,n).points;return Math.hypot(s[`hand.${e}`].x-s[`shoulder.${e}`].x,s[`hand.${e}`].y-s[`shoulder.${e}`].y)}const tM=5,eM=4,nM=8;function sM(t,e,n,s){const i=Qv(t,n)*.9,o=a=>{const l=ee(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<=nM;a++)if(r={...e,lean:(e.lean??0)+tM*a,bend:(e.bend??0)+eM*a},o(r))return r;return r}function iM(t,e,n,s,i){const o=n.find(u=>u.property==="gait"),r=o?new Et({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 Ft[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=Ii(p,s.height),m=ng(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"],Io={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}},_l={fillStyle:"fill",strokeStyle:"stroke",lineWidth:"strokeWidth",rotateZ:"rotate",motionPathX:"x",motionPathY:"y",motionPathRotate:"rotate"},oM={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 ig(t){const e=t,n=Object.entries(Io).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 og(t){const e=ig(t).properties.map(n=>n.name);return[...e,...Object.keys(_l).filter(n=>e.includes(_l[n]))]}function rM(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(ut("target",i.target,s));continue}const a=og(r),l=r.type==="custom"&&r.acceptsProp?.(i.property);if(!a.includes(i.property)&&!l){o(`${i.target}: ${ut("property",i.property,a,oM[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=Io[_l[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 Kn=(t,e)=>t[2]<=-e;function Cl(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 rg(t,e){if(t.every(s=>Kn(s,e)))return t;const n=[];return t.forEach((s,i)=>{const o=t[(i+t.length-1)%t.length],r=Kn(s,e),a=Kn(o,e);r!==a&&n.push(Cl(o,s,e)),r&&n.push(s)}),n.length>=3?n:[]}function aM(t,e){if(t.every(i=>Kn(i,e)))return[t];const n=[];let s=[];return t.forEach((i,o)=>{const r=Kn(i,e);if(o>0){const a=t[o-1],l=Kn(a,e);l&&!r?(s.push(Cl(a,i,e)),n.push(s),s=[]):!l&&r&&s.push(Cl(a,i,e))}r&&s.push(i)}),s.length>0&&n.push(s),n.filter(i=>i.length>=2)}function ag(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 lM(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 cM(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=>jt(e,s)),faces:t.faces.map(s=>({corners:s.corners,normal:n(s.normal)}))}}function Oo(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 hM(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=Oo(g,0,e[r],1)),g.length&&!f(r,e)&&(g=Oo(g,0,e[r+1],-1)),g.length&&!d(a)&&(g=Oo(g,2,n[a],1)),g.length&&!f(a,n)&&(g=Oo(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 uM=new WeakMap,dM=new WeakMap,fM=48,lg=t=>t.map(e=>Math.round(e*1e5)).join(",");function cg(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>=fM&&i.clear(),i.set(n,o=s())),o}function Hl(t,e){const n=lg(e);return cg(uM,t,n,()=>{const s=cM(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 gM(t,e){const n=t.map(h=>({...h,...Hl(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=ag(s[0],i[0],e),r=ag(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:lM(o,r,d)}]}return cg(dM,h.inSpace,a,()=>hM(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 hg=.004,Rl=.05,ug=new WeakMap;function pM(t){let e=ug.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)}),ug.set(t,e)),e}const dg=new WeakMap;function fg(t){return t.filter(({mesh:e})=>pM(e)).map(({part:e,key:n,inSpace:s,low:i,high:o})=>{let r=dg.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]}}),dg.set(s,r)),{part:e,key:n,planes:r,low:i,high:o}})}function mM(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]-Rl||i[a]>o.high[a]+Rl))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)<=hg))return l<-.9;const h=Math.abs(l)<.5?Rl:hg;return c.every(u=>u<=h)}))return!0}return!1}const gg=new WeakMap;function pg(t,e,n,s,i){const o=`${s}|${i.map(l=>l.key).join(";")}`;let r=gg.get(e);r||gg.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=>jt(n,h));a=e.faces.map(h=>mM(t,h.corners.map(u=>c[u]),l(h.normal),i)),r.set(o,a)}return a}const Xn={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}},Ll=Math.PI/180;function mg(t,e,n){return{toView:s=>aa(He(s,t*90*Ll),-e*Ll),toScreen:s=>({x:s[0]*n,y:-s[1]*n})}}const yg=new WeakMap,Ks=t=>_o(t),_o=t=>{let e=yg.get(t);return e||yg.set(t,e=Zd(t)),e};function xt(t,e,n){return e[n]??t.controls[n]?.default??Xn[n]?.default??0}function Xs(t,e){const n=Math.max(.05,xt(t,e,"squash")),s=1/Math.sqrt(n),o=[1,0,0,0,0,1,xt(t,e,"lean"),0,0,0,1,0,0,0,0,1];return[Ue([0,xt(t,e,"lift"),0]),se(Jt([1,0,0],-xt(t,e,"pitch"))),se(Jt([0,0,1],xt(t,e,"roll"))),o,Ve([s,n,s]),Ve(Array(3).fill(Math.max(0,xt(t,e,"size"))))].reduce((r,a)=>At(r,a))}function Nl(t,e){const n=Xs(t,e),s=new Map,i=Object.entries(t.controls).flatMap(([r,a])=>(a.bind??[]).map(l=>({value:xt(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=At(l?o(l):n,Ue(r.at??[0,0,0]));if(r.rotate){const[h,u,d]=r.rotate;h&&(c=At(c,se(Jt([1,0,0],h)))),u&&(c=At(c,se(Jt([0,1,0],u)))),d&&(c=At(c,se(Jt([0,0,1],d))))}for(const{value:h,bind:u}of i)if(!(!u.parts.includes(r.id)||h===0)){if(u.translate&&(c=At(c,Ue([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,Ue(d),se(Jt(f,u.rotate.degrees*h)),Ue([-d[0],-d[1],-d[2]])].reduce((p,g)=>At(p,g))}u.scale&&(c=At(c,Ve([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 Fl=(()=>{const t=[-.45,.75,.5],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),yM=Math.cos(35*Ll);function Dl(t,e,n,s,i={}){const o=t.derive?{...e,...t.derive(e)}:e,r=Nl(t,o),a=n.toView([0,0,0]),l=C=>F=>[C[0]*F[0]+C[4]*F[1]+C[8]*F[2],C[1]*F[0]+C[5]*F[1]+C[9]*F[2],C[2]*F[0]+C[6]*F[1]+C[10]*F[2]],c=Xs(t,o),h=i.slice===void 0?null:vr(c),u=h?t.parts.map(C=>({part:C,mesh:_o(C.shape),local:At(h,r.get(C.id)),whole:C.shape.type==="tube"})):void 0,d=u?gM(u,i.slice):void 0,f=u?fg(u.map(C=>({part:C.part.id,mesh:C.mesh,...Hl(C.mesh,C.local)}))):void 0,p=(C,F,z,X)=>{const J=G=>n.toView(jt(z,G)),K=F.vertices.map(J),P=K.map(G=>n.toScreen(G)),R=i.perspective?i.near:void 0,N=G=>G.map(nt=>n.toScreen(nt)),$=G=>R===void 0?G:rg(G,R),L=G=>R===void 0?[G]:aM(G,R),W=l(z),q=F.faces.map(G=>{const nt=n.toView(W(G.normal)),ht=[nt[0]-a[0],nt[1]-a[1],nt[2]-a[2]],ft=Math.hypot(...ht)||1;return[ht[0]/ft,ht[1]/ft,ht[2]/ft]}),B=f&&X?pg(C.id,F,X,lg(X),f):void 0,Y=G=>B?.[G]??!1,U=q.map((G,nt)=>{if(Y(nt))return!1;if(!i.perspective)return G[2]>1e-6;const ft=F.faces[nt].corners.reduce((wt,mt)=>[wt[0]+K[mt][0],wt[1]+K[mt][1],wt[2]+K[mt][2]],[0,0,0]);return-(G[0]*ft[0]+G[1]*ft[1]+G[2]*ft[2])>1e-9}),D=G=>F.faces[G].corners.reduce((nt,ht)=>nt+K[ht][2],0)/F.faces[G].corners.length,V=F.faces.map((G,nt)=>({face:G,i:nt})).filter(({i:G})=>U[G]).map(({face:G,i:nt})=>({i:nt,solved:{points:R===void 0?G.corners.map(ht=>P[ht]):N($(G.corners.map(ht=>K[ht]))),depth:D(nt),tone:.72+.33*Math.max(0,q[nt][0]*Fl[0]+q[nt][1]*Fl[1]+q[nt][2]*Fl[2])}})).filter(G=>G.solved.points.length>=3).sort((G,nt)=>G.solved.depth-nt.solved.depth);if(i.light){const G=l(z);for(const{i:nt,solved:ht}of V){const ft=F.faces[nt].corners,wt=ft.reduce((tc,nT)=>{const ec=jt(z,F.vertices[nT]);return[tc[0]+ec[0]/ft.length,tc[1]+ec[1]/ft.length,tc[2]+ec[2]/ft.length]},[0,0,0]),mt=G(F.faces[nt].normal),ne=Math.hypot(...mt)||1,Vs=i.light(wt,[mt[0]/ne,mt[1]/ne,mt[2]/ne]);ht.light=Vs.light,ht.fog=Vs.fog}}const j=V.map(G=>G.solved),st=bM(F),ot=[],rt=[];for(const[G,nt]of st){const ht=nt.filter(wt=>U[wt]).length;if(ht===0)continue;const ft=nt.length===2&&ht===2&&F.creases!==!1&&q[nt[0]][0]*q[nt[1]][0]+q[nt[0]][1]*q[nt[1]][1]+q[nt[0]][2]*q[nt[1]][2]<yM;nt.length===1&&(F.joined||wM(F,G))||(nt.length===1||ht===1||ft)&&(ot.push(G.split("-").map(Number)),rt.push(nt.filter(wt=>U[wt]).reduce((wt,mt)=>D(mt)>D(wt)?mt:wt)))}const at=G=>F.faces.findIndex(nt=>nt.corners.length>4&&Math.sign(vM(F.vertices[G],nt.normal))>0),H=(F.marks??[]).filter(([G])=>at(G)<0||U[at(G)]),Z=([G,nt])=>R===void 0?[[P[G],P[nt]]]:L([K[G],K[nt]]).map(N),et=H.flatMap(Z),it=G=>R===void 0?[G.map(nt=>P[nt])]:L(G.map(nt=>K[nt])).map(N);if(i.slice!==void 0){const G=new Map;ot.forEach((nt,ht)=>G.set(rt[ht],[...G.get(rt[ht])??[],nt]));for(const{i:nt,solved:ht}of V){ht.edges=vg(G.get(nt)??[]).flatMap(it);const ft=F.faces[nt].corners;ht.center=ft.reduce((mt,ne)=>[mt[0]+K[ne][0]/ft.length,mt[1]+K[ne][1]/ft.length,mt[2]+K[ne][2]/ft.length],[0,0,0]),ht.normal=q[nt];const wt=V[V.length-1].i;ht.marks=H.filter(([mt])=>(at(mt)>=0?at(mt):wt)===nt).flatMap(Z)}}const tt=C.glow?Math.max(0,Math.min(1,xt(t,o,C.glow.control))):0,lt=C.fade?Math.max(0,Math.min(1,xt(t,o,C.fade.control))):0,Q=C.fade?Math.max(0,Math.min(1,C.fade.from+(C.fade.to-C.fade.from)*lt)):1;return{part:C,depth:K.reduce((G,nt)=>G+nt[2],0)/Math.max(1,K.length),faces:j,edges:vg(ot).flatMap(it),marks:et,glow:tt,opacity:Q,...C.shape.type==="tube"?{spine:kM(L(C.shape.points.map(J)).map(N))}:{},...F.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?pi():g.get(C.part.id),cell:C.cell})):t.parts.map(C=>({part:C,mesh:_o(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(F=>F.faces.length>0&&F.opacity>.01).sort((F,z)=>F.depth-z.depth);let b;if(d){const C=new Map(t.parts.map(z=>{const X=r.get(z.id),J=_o(z.shape).vertices;return[z.id,J.reduce((K,P)=>K+n.toView(jt(X,P))[2],0)/Math.max(1,J.length)]})),F=new Map;for(const z of w){const X=z.cell.join(",");F.has(X)||F.set(X,{cell:z.cell,parts:[]}),F.get(X).parts.push(z.solved),z.solved.depth=C.get(z.solved.part.id)}b=[...F.values()].map(({cell:z,parts:X})=>({depth:n.toView(jt(c,d.middle(z)))[2],parts:k(X)})).filter(z=>z.parts.length>0)}const M={};for(const[C,F]of Object.entries(t.anchors??{})){const z=F.part?r.get(F.part):Xs(t,o);if(!z)throw new Error(`prop rig: anchor "${C}" is on "${F.part}", which is not a part`);const X=n.toView(jt(z,F.at));M[C]={point:n.toScreen(X),depth:X[2]}}const[E,A]=t.footprint??[t.length*.45,t.length],T=Math.max(0,xt(t,o,"lift")),S=Math.max(0,xt(t,o,"size"))/(1+T*.8),x=Array.from({length:24},(C,F)=>{const z=Math.PI*2*F/24;return n.toView([Math.cos(z)*E*.55*S,0,Math.sin(z)*A*.55*S])}),O=i.perspective?i.near:void 0,I={points:(O===void 0?x:rg(x,O)).map(C=>n.toScreen(C)),opacity:.16*S},_=v.filter(C=>C.part.seeThrough&&C.opacity>.01).flatMap(C=>C.faces.map(F=>F.points));return{under:k(v.filter(C=>!C.part.overRider)),over:k(v.filter(C=>C.part.overRider)),...b?{cells:b}:{},anchors:M,openings:_,shadow:I,pxPerUnit:s,sizePx:t.height*s}}const bg=new WeakMap;function bM(t){let e=bg.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])}}bg.set(t,e)}return e}function wg(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=Nl(t,n),i=vr(Xs(t,n))??pi(),o=r=>Math.max(0,Math.min(1,r));return t.parts.map(r=>{const a=r.fade?o(xt(t,n,r.fade.control)):0;return{part:r,matrix:s.get(r.id),local:At(i,s.get(r.id)),glow:r.glow?o(xt(t,n,r.glow.control)):0,opacity:r.fade?o(r.fade.from+(r.fade.to-r.fade.from)*a):1}})}function kg(t,e){const n=t.derive?{...e,...t.derive(e)}:e,s=Nl(t,n),i=Xs(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]=jt(l,a.at)}return o}function wM(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 kM(t){return t.reduce((e,n)=>!e||n.length>e.length?n:e,void 0)}const vM=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2];function vg(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 Wl(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 Bl(t){const e={};for(const[n,s]of Object.entries({...Xn,...t.rig.controls})){const{bind:i,...o}=s;e[n]=o}return e}function Mg(t){const{prop:e}=t,n=t.scale??60,s=e.rig.length*n*1.4,i=e.rig.height*n*1.6,o=Bl(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),Wa(l,Gn(e,u,n),{...a,time:h,loose:Wl(c,u)})}}}function Gn(t,e,n){const s=mg(xt(t.rig,e,"turn"),xt(t.rig,e,"tilt"),n);return Dl(t.rig,e,s,n)}function Co(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=Gn(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 MM(t,e,n,s,i={}){const o=Co(e,n,s);return t.save(),t.translate(o.origin.x,o.origin.y),Wa(t,o.solved,{...e.propDraw,time:n.time,loose:Wl(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 Un={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"}},SM=400,TM=.2;function xM(t,e={}){const{prop:n}=t,s=Bl(n),i=Object.keys(s),o=Object.keys(n.rig.anchors??{}),r=n.rig.parts.map(E=>E.id),a=Wn(),l=Ls(a),c=e.tracks?.length?new Et({id:`${n.kind}-surface`,tracks:e.tracks}):void 0,h=Math.max(0,...(e.tracks??[]).flatMap(E=>E.keyframes.map(A=>A.time))),u=new Map,d=new Map;t.loose=d;const f=t.props,p=E=>{const A={...t.props};let T=0,S=0;if(c){const x=c.getStateAtTime(Math.min(E,h));for(const O of x.values.values())for(const[I,_]of O)typeof _=="number"&&(I==="x"?T=_:I==="y"?S=_:I in A&&(A[I]=_))}for(const x of i)a.keys(x)?.length&&(A[x]=a.valueAt(x,E));return{values:A,origin:{x:t.x+t.width/2+T,y:t.y+t.height+S}}},g=E=>{const{kind:A,rest:T}=on(E),S=x=>De(n.kind,E,Un,x);if(A==="box"){if(T)throw S("box takes no arguments");return{kind:A}}if(A==="anchor"){if(!o.includes(T))throw S(ut(`${n.kind} anchor`,T,o));return{kind:A,name:T}}if(A==="part"){if(!r.includes(T))throw S(ut(`${n.kind} part`,T,r));return{kind:A,name:T}}if(A==="control"){if(!i.includes(T))throw S(ut(`${n.kind} control`,T,i));return{kind:A,name:T}}throw S()},m=E=>{const A=(n.rig.controls[E]?.bind??[]).flatMap(S=>S.parts),T=n.rig.parts.filter(S=>S.glow?.control===E).map(S=>S.id);return new Set([...A,...T])},w=new Map,v=E=>{let A=w.get(E);if(!A){const T=p(E);w.set(E,A={...T,solved:Gn(n,T.values,t.propScale)})}return A},k=(E,A)=>{const T=g(E),{values:S,origin:x,solved:O}=v(A);if(T.kind==="box")return vt(x.x-t.width/2,x.y-t.height,t.width,t.height);if(T.kind==="anchor"){const C=O.anchors[T.name].point,F=TM*t.propScale;return vt(x.x+C.x-F/2,x.y+C.y-F/2,F,F)}if(T.kind==="part")return _(new Set([T.name]),`part "${T.name}" is`);const I=m(T.name);if(I.size===0)return vt(x.x-t.width/2,x.y-t.height,t.width,t.height);return _(I,`the parts control "${T.name}" moves are`);function _(C,F){const z=[...O.under,...O.over].filter(R=>C.has(R.part.id)).flatMap(R=>R.faces.flatMap(N=>N.points));if(z.length===0){const R=Number.isFinite(A)?`at ${A} ms`:"after its edits";throw new Error(`${n.kind}: ${F} turned away from the viewer ${R}; aim at an anchor (${o.map(N=>`anchor:${N}`).join(", ")||"none"}) or box`)}const X=z.map(R=>R.x),J=z.map(R=>R.y),K=Math.min(...X),P=Math.min(...J);return vt(x.x+K,x.y+P,Math.max(...X)-K,Math.max(...J)-P)}},b=(E,A)=>{try{return k(E,A)}catch{return}},M={kind:"prop",prop:t,about:Un,target:t,box:vt(t.x,t.y,t.width,t.height),anchor(E,A=1/0){return k(E,A)},piece(E){const A=g(E);if(A.kind!=="part")throw new Error(`${n.kind}: a piece is a part, part:ID (${r.slice(0,6).map(O=>`part:${O}`).join(", ")}…), not "${E}"`);const T=u.get(A.name);if(T)return T;const S=[A.name];for(let O=0;O<S.length;O++)for(const I of n.rig.parts)I.parent===S[O]&&!S.includes(I.id)&&S.push(I.id);const x={id:u.size+1,part:A.name,home:k(E,0)};u.set(A.name,x);for(const O of S)d.set(O,x.id);for(const O of["x","y","rotate"])f[`piece.${x.id}.${O}`]=0;return f[`piece.${x.id}.opacity`]=1,x},edit(E,A,T){if(!(E in Un.edits))throw Ns(n.kind,E,Un);const S=Array.isArray(A)?A:[A];if(S.length===0)throw new Error(`${n.kind}.edit: ${E} takes at least one anchor`);if(w.clear(),E==="move"||E==="fling"){if(S.length>1)throw new Error(`${n.kind}.edit: ${E} takes one part anchor`);const x=M.piece(S[0]);if(E==="fling")return M.fling(x,T);const O=T.to;if(!O)throw new Error(`${n.kind}.edit: move needs \`to\`, an anchor name or { x, y }`);const I=typeof O=="string"?k(O,T.at):void 0;return M.move(x,{...T,to:I?{x:I.left+I.width/2,y:I.top+I.height/2}:O})}for(const x of S){const O=g(x);if(O.kind!=="control")throw new Error(`${n.kind}.edit: ${E} takes control anchors (control:${i.join(", control:")}), not "${x}"`);const I=s[O.name];let _;if(E==="set"){if(typeof T.value!="number"||!Number.isFinite(T.value))throw new Error(`${n.kind}.edit: set needs \`value\`, a number (${O.name}: ${I.description})`);_=T.value}else _=T.on===!1?I.default??I.min??0:I.max??1;a.tween(O.name,p(T.at).values[O.name],_,T,SM)}return M},follow(E,A){return w.clear(),l.follow(E,A),M},fling(E,A){return w.clear(),l.fling(E,A),M},move(E,A){return w.clear(),l.move(E,A),M},ride(E,A,T){const S=[...i.flatMap(O=>Bn(a.keys(O))),...(e.tracks??[]).flatMap(O=>Bn(O.keyframes.filter(I=>typeof I.value=="number")))];if(S.length===0)return E;const x=[...o.map(O=>`anchor:${O}`),...r.map(O=>`part:${O}`)].flatMap(O=>{const I=b(O,0);return I?[{top:I.top,offset:_=>(b(O,_)?.top??I.top)-I.top,windows:S}]:[]});return yo(E,A,{ground:T.ground,every:T.every??Fe,floors:x})},tracks:a.tracks};return M}const EM={body:"#e8574a",trim:"#3b3b44",glass:"#bfe3f2",tyre:"#2c2c33",hub:"#c9ccd3",light:"#fff4b8",tail:"#ff5a4f",inside:"#3b3640",seat:"#6d5d55"};function ve(t){const e={...EM,...t.colors},n=[],{forwardMost:s,backMost:i,top:o}=Sg(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:ho(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:AM(t),acting:Tg,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 Sg(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 Tg={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 Ho(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 xg=.4;function AM(t){const e=t.wheels[0]?.radius??.4,{forwardMost:n,backMost:s}=Sg(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"}),Ho(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??xg));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}),Ho(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??xg*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"}),Ho(a,u,m,w,"ease-in",e),a.key(m+80,{pitch:-7*d,lean:-.12*d,squash:.94},{act:!1,easing:"ease-out"}),Ho(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 Eg(t={}){return ve({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 Ag(t={}){return ve({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 Pg(t={}){return ve({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 $g(t={}){return ve({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 Ig(t={}){const e=t.colors?.body??"#a8743f";return ve({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 Og(t={}){return ve({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 _g(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 ve({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 Cg(t={}){return ve({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 Hg(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=Pe(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:PM(),acting:Rg,colors:{body:o.leaves}}}const Rg={depth:{sway:1,canopySway:2,size:0,squash:1},limits:{sway:2,canopySway:3,squash:.08},eyes:[],headTurns:{},drift:[]};function PM(){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 Lg(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:$M(!!f),acting:Ng,colors:{body:r.walls}}}const Ng={depth:{door:1,lights:0,roll:1,squash:1,size:0},limits:{door:.1,roll:1.5,squash:.05},eyes:[],headTurns:{},drift:[]};function $M(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 Fg(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:IM(),acting:Dg,colors:{body:o.seat}}}const Dg={depth:{tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.05},eyes:[],headTurns:{},drift:[]};function IM(){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 Wg(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:Bg,colors:{body:i.top}}}const Bg={depth:{drawer:1,roll:1,squash:1,size:0},limits:{drawer:.08,roll:1,squash:.04},eyes:[],headTurns:{},drift:[]};function zg(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:qg,colors:{body:o.blanket}}}const qg={depth:{give:1,roll:1,squash:1,size:0},limits:{give:.03,roll:.5,squash:.03},eyes:[],headTurns:{},drift:[]};function Yg(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:OM(),acting:jg,colors:{body:i.door}}}const jg={depth:{open:1,roll:1,squash:1,size:0},limits:{open:.08,roll:.6,squash:.03},eyes:[],headTurns:{},drift:[]};function OM(){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 Kg=1.4;function Xg(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,M=a)=>{d.push({id:k,shape:{type:"tube",points:b,radius:M,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:_M(s),acting:Gg,colors:{body:o.seat,ink:o.frame},wheelRadius:s,moves:{roll:{speed:Kg,perMetre:{wheelSpin:180/(Math.PI*s)}}}}}const Gg={depth:{wheelSpin:0,tip:1,roll:1,squash:1,size:0},limits:{tip:2,roll:1,squash:.03},eyes:[],headTurns:{},drift:[]};function Ug(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 _M(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??Kg*e.scale/1e3));return e.key(o+150,{tip:1.5*e.exaggeration},{act:!1,easing:"ease-out"}),Ug(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 Ug(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 Vg(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:CM(),acting:zl,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:15,flies:!0,hold:{blur:1},perSecond:{rotor:Be*1e3}}}}}const zl={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:[]},Be=2.6;function CM(){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,Be,"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,Be),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,Be),{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,Be),{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,Be),t(n,r,r+1600,Be,"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 Jg(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:RM(),acting:zl,colors:{body:e.body,ink:"#26262b"},moves:{fly:{speed:30,flies:!0,hold:{blur:1},perSecond:{rotor:Be*1e3}}}}}const HM=3.2;function RM(){const t=(n,s,i,o)=>{const r=n.values.rotor??0;n.set("rotor",s,r),n.set("rotor",i,r+HM*(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 Vn=["walk","trot","canter","gallop"],LM=Vn,Zg=["fl","fr","hl","hr"],Ro={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}},ze=Math.PI/180;function Lo(t,e){return 4*t*Math.sin(Ro[e].swing*ze)}function qe(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},...FM(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=>`${Vn.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:ae,rotate:{axis:"x",degrees:1/ae.length}}]},wag:{description:"Tail swung side to side, curling",unit:"degrees",bind:[{parts:ae,rotate:{axis:"y",degrees:1/ae.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 Zg){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=>DM(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:{...BM(t,h),...t.actions?.(h)},acting:Yl,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:NM(t,s)}}function NM(t,e){const n=i=>{const o=Lo(e,i);return{speed:o/(Ro[i].cycle*(t.cycleScale??1)/1e3),set:{gait:Vn.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 ae=Array.from({length:7},(t,e)=>e===0?"tail":`tail-${e}`);function FM(t,e,n){const s=Va(t.tail.points,ae.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/ae.length),h=ae.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:ae[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:ae[ae.length-1],shape:{type:"ellipsoid",radii:Array(3).fill(c(ae.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 DM(t,e,n){const s=Math.max(0,Math.min(1,t.walking??0));if(s===0)return{};const i=Vn[Math.max(0,Math.min(3,Math.round(t.gait??0)))],o=Ro[e.gaits.includes(i)?i:e.gaits[0]],r=t.walk??0,a={};for(const c of Zg){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 ql(t){const n=Math.sin(32*ze),s=t.legLength-(t.front-t.hind)*n,i=72,r=(s-t.upper*Math.cos(i*ze)-t.foot)/t.lower,a=r>=1?0:r<=-1?180:Math.acos(r)/ze,l={pitch:32,lift:t.legLength*(1-Math.cos(32*ze))-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 Yl={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:[]},WM=Yl;function Qg(t){const e=(t.upper+t.lower)*.32,n=Math.asin(Math.min(1,e/(t.upper+t.lower+t.foot)))/ze,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 BM(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/Lo(e.legLength,r),g=l.for??Math.max(500,p*Ro[r].cycle*n),m=a.values.walk??0;return a.set("gait",u,a.values.gait??0),a.set("gait",u+1,Vn.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=ql(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=Qg(e),h={...ql(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 tp(t={}){return qe({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*ze),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*ze);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 ep(t={}){return qe({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 np(t={}){return qe({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 sp(t={}){return qe({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 zM(t){return Lo(1,t)}function ip(t={}){return qe({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 op(t={}){return qe({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 rp(t={}){return qe({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 Ye=.6,ap=75,jl=80;function je(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*Ye/2,t.wing.chord*.1,t.wing.chord/2],segments:12},at:[h*t.wing.span*Ye/2,0,-t.wing.chord*.1],rotate:[-jl,0,0],fill:e.wing,outline:.8}),a.push({id:`wing-${u}-tip`,parent:`wing-${u}-blade`,shape:{type:"ellipsoid",radii:[t.wing.span*Ye/2.4,t.wing.chord*.06,t.wing.chord*.3],segments:10},at:[h*t.wing.span*Ye/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-Ye)/2,0,0],rotate:{axis:"x",degrees:jl},scale:[1/Ye,1,1]},{parts:["wing-right-blade"],translate:[-t.wing.span*(1-Ye)/2,0,0],rotate:{axis:"x",degrees:jl},scale:[1/Ye,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)/ap,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:YM(t),acting:lp,colors:{body:e.body,ink:"#26262b"},moves:qM(t)}}function qM(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 lp={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 YM(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:ap},{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 cp(t={}){return je({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 hp(t={}){return je({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 up(t={}){return je({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 dp(t={}){return je({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 fp(t={}){return je({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 gp(t={}){return je({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 pp(t={}){return je({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 Jn={car:Eg,truck:Ag,bus:Pg,tractor:$g,cart:Ig,trainCar:Og,bike:_g,motorbike:Cg,tree:Hg,house:Lg,chair:Fg,desk:Wg,bed:zg,door:Yg,wheelchair:Xg,helicopter:Vg,airplane:Jg,horse:tp,dog:ep,cat:np,cow:sp,goat:ip,rabbit:op,squirrel:rp,songbird:cp,crow:hp,chicken:up,pigeon:dp,duck:fp,owl:gp,parrot:pp};function Kl(t,e={}){const n=Jn[t];if(!n)throw new Error(ut("prop preset",t,Object.keys(Jn)));return n(e)}const No=["do","at","for","to","toward","speed","open","on","height","wind"],Xl={viewer:0,right:1,away:2,left:3},jM=420,Gl={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 Fo(t){return{...Gl,...t.actions}}const Ul=t=>typeof t=="number"&&Number.isFinite(t);function mp(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=Fo(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))No.includes(c)||a(ut("beat field",c,No,c==="duration"?"for":c==="direction"?"toward":void 0));if(typeof l.do!="string"||!s.includes(l.do))return a(ut(`${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&&!(Ul(l[c])&&l[c]>=0)&&a(`\`${c}\` must be a number ≥ 0 (got ${JSON.stringify(l[c])}).`);if(l.to!==void 0&&!Ul(l.to)&&a(`\`to\` is a scene x in px (got ${JSON.stringify(l.to)}).`),l.toward!==void 0&&!Ul(l.toward)&&!(typeof l.toward=="string"&&l.toward in Xl)){const c=typeof l.toward=="string"?hs(l.toward,Object.keys(Xl)):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 yp(t,e,n,s={}){const i=mp(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=Fo(e),h={};for(const S of[...Object.keys(Xn),...Object.keys(e.rig.controls)])h[S]=s.start?.[S]??xt(e.rig,{},S);const u=[{time:0,pose:{...h}}],d=new Map,f=[];let p=o,g=r;const m=(S,x,O,I)=>{const _=d.get(S)??[{time:0,value:S==="x"||S==="y"?0:h[S]}];_.push({time:x,value:O,...I?{easing:I}:{}}),d.set(S,_),S!=="x"&&S!=="y"&&(h[S]=O)},w=(S,x)=>{const O=S==="x"?p-o:S==="y"?g-r:h[S],I=d.get(S);(!I||I[I.length-1].time<x)&&m(S,x,O)},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,x,O={}){Object.assign(h,x),u.push({time:S,pose:{...h},...O.act===!1?{act:!1}:{},...O.easing?{easing:O.easing}:{}})},move(S,x,O,I={}){w("x",S),m("x",x,O-o,I.easing),p=O,I.floor!==void 0&&(w("y",S),m("y",x,I.floor-r,I.easing),g=I.floor)},set(S,x,O,I){m(S,x,O,I)},turnTo(S,x){const O=typeof x=="number"?x:Xl[x],I=h.turn,C=[O-4,O,O+4].map(z=>({t:z,d:Math.abs(z-I)})).sort((z,X)=>z.d-X.d||Math.abs(z.t)-Math.abs(X.t))[0];if(C.d<.001)return S;const F=S+jM*Math.max(1,C.d);return v.key(F,{turn:C.t}),F},effect(S){f.push(S)},anchor(S){const O=Gn(e,h,a).anchors[S];if(!O)throw new Error(`${e.kind}: no anchor "${S}"`);return{x:p+O.point.x,y:g+O.point.y}}},k=[];let b=0;for(const S of n){const x=Math.max(S.at??b,u[u.length-1].time),O=c[S.do].run(v,S,x);O.end>u[u.length-1].time&&u.push({time:O.end,pose:{...h}}),k.push({start:x,end:O.end,...O.contact!==void 0?{contact:O.contact}:{},...O.release!==void 0?{release:O.release}:{}}),b=O.end}const M=gl(s.style??"snappy"),E={...M,anticipation:M.anticipation*l,overshoot:M.overshoot*l},A=So(UM(u),e.acting,{style:E}),T=[...Object.entries(A).filter(([S])=>!d.has(S)).map(([S,x])=>({id:`${t}-${S}`,target:t,property:S,keyframes:x})),...[...d].map(([S,x])=>({id:`${t}-${S}`,target:t,property:S,keyframes:VM(x)}))];for(const S of XM(t,e,T,b,u[0].pose)){const x=T.findIndex(_=>_.property===S.property);if(x<0){T.push(S);continue}const O=new Et({id:`${t}-own`,tracks:[T[x]]}),I=_=>Number(O.getStateAtTime(_).values.get(t)?.get(S.property)??0);T[x]={...S,keyframes:S.keyframes.map(_=>({time:_.time,value:Number(_.value)+I(_.time)}))}}return{tracks:T,duration:b,beats:k,effects:f}}const KM=1500;function XM(t,e,n,s,i){if(!e.follow?.length)return[];const o=new Et({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+KM,c=us(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 GM=20;function UM(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<GM?n[n.length-1]={...s,time:i.time}:n.push(s)}return n}function VM(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 JM={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 bp(t,e={}){const n={};for(const s of Object.keys(Ft))n[s]={summary:`Walks to \`to\` in the ${s} gait.`,needs:["to"]};for(const s of Object.keys(Gt))n[s]={summary:`Moves into the ${s} pose and holds it (\`for\` ms).`};for(const s of Object.keys(We))n[s]={summary:`The ${s} gag (${zs(s)} ms).`};for(const[s,i]of Object.entries(qs))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(JM),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:Io,stickFigure:{poseFields:T0,props:x0,handFields:E0,poses:Object.keys(Gt),expressions:Object.keys(kt),gags:Object.fromEntries(Object.keys(We).map(s=>[s,zs(s)])),gaits:Object.keys(Ft),actingStyles:Object.keys(ln),beatFields:To,actions:n,dances:Object.fromEntries(Object.entries(Ce).map(([s,i])=>[s,Object.keys(i.moves)])),flips:Object.fromEntries(Object.entries(Es).map(([s,i])=>[s,i.label])),handShapes:Object.keys(_t),mudras:Object.keys(Hi)},props:{api:{"car() · truck() · bus() · tractor() · cart() · trainCar() · bike() · motorbike()":"wheeled vehicles (vehicle(spec) makes your own)","tree() · house()":"environment (tree(spec), house(spec))","helicopter() · airplane()":"aircraft","horse() · dog() · cat() · cow()":"animals (quadruped(spec) makes your own): gaits with footfall patterns keyed in step with the distance, sit, jump, their calls, species actions","songbird() · crow() · chicken()":"birds (bird(spec) makes your own): hop, walk, peck, flap, fly and land (a chicken flutters), their calls; wings fold and beat in rhythm","{ kind: 'prop', prop: 'car', position, rotation, values } with loadScene3D(scene, { kinds: [characterObjects, propObjects] })":"props in 3D scenes, by preset name, seen in perspective by the scene camera; controls are tracks on the object","characterScript3D(id, beats, { scene, position?, heading?, height?, pose? })":"a v2 character in a 3D scene in world metres: gaits to [x, z] or through points (its walk phase keyed with the distance), face, hold, pose, gag; checkCharacterBeats3D checks the beats","propRide3D({ prop, propId, propTracks, scene, placement, anchor, riderId, pose, start, end, mount?, dismount? })":"a character riding a prop in a 3D scene: hips on a seat anchor (saddle, seat) as it moves, hopping on and off; RIDING_POSES.astride / .seated / .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:No,commonControls:Object.fromEntries(Object.entries(Xn).map(([s,i])=>[s,`${i.description}${i.unit?` (${i.unit})`:""}`])),commonActions:Object.fromEntries(Object.entries(Gl).map(([s,i])=>[s,i.summary])),presets:Object.fromEntries(Object.entries(Jn).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(oe),expressions:Object.keys(ra),gags:Object.keys(io),builds:Object.keys(zi),hair:Object.keys(wa),hairColors:{...de},facialHair:Object.keys(Ta),glasses:Object.keys(Ea),hats:Object.keys(so),feet:[...Su],cast:Object.keys(dl),heldItems:Object.fromEntries(Object.entries(_a).map(([s,i])=>[s,i.hands])),handMeetings:Object.keys(Bs)},codePanel:{languages:ko,removeStyles:bo,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:rl},surfaces:{code:Fs,board:be,chart:rn,prop:Un},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: ${jn.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 Mt=t=>t.map(e=>`\`${e}\``).join(", "),wp=t=>Object.entries(t).map(([e,n])=>`| \`${e}\` | ${n.unit??n.kind??""} | ${n.description} |`).join(`
63
+ `);function ZM(t,e={}){const n=bp(t,e),s=n.stickFigure;return[`# tinyfly capabilities${n.version?` (v${n.version})`:""}`,"","Generated from the library itself: every name below is accepted, and names not listed are rejected (beat scripts, code panels and `checkTracks` say which name was probably meant).","",`**Timing.** ${n.timing}`,"","## Easings","",`Named: ${Mt(n.easings.named)}.`,"",...Object.entries(n.easings.parametric).map(([o,r])=>`- ${o}: \`${r}\``),"","## Track kinds","",...Object.entries(n.trackKinds).map(([o,r])=>`- **${o}**: ${r}`),"","## Canvas targets","","Types: `rect`, `circle`, `text`, `line`, `path`, `image`, `custom`. `describeTarget(target)` lists what one can animate with its values; `checkTracks(tracks, targets)` checks tracks before playing them.","","| Property | Unit | What it does | Types |","|---|---|---|---|",...Object.entries(n.canvasProperties).map(([o,r])=>`| \`${o}\` | ${r.unit??r.kind??""} | ${r.description} | ${r.types.length===7?"all":r.types.join(", ")} |`),"","## Stick figure (`@algorisys/tinyfly/characters`)","","`stickFigureTarget({ x, y, style })` is a custom canvas target; its props are the pose fields and the props below. Pose it with tracks (`poseTracks`), or write beats (`scriptTracks`).","","### Pose fields","","| Field | Unit | What it does |","|---|---|---|",wp(s.poseFields),"","### Other props","","| Prop | Unit | What it does |","|---|---|---|",wp(s.props),"",`With \`style.hands\`, each hand has \`hand.left.<field>\` / \`hand.right.<field>\` props: ${Mt(Object.keys(s.handFields))}.`,"",`**Poses** (a beat's \`do\`, or a pose key): ${Mt(s.poses)}.`,"",`**Expressions** (a beat's \`mood\`): ${Mt(s.expressions)}.`,"",`**Gags** (ms): ${Object.entries(s.gags).map(([o,r])=>`\`${o}\` (${r})`).join(", ")}.`,"",`**Gaits**: ${Mt(s.gaits)}. **Acting styles** (\`style\`): ${Mt(s.actingStyles)}.`,"","### Beat scripts","",`\`scriptTracks(target, beats, { from, ground, height, facing, style })\`. A beat has these fields only: ${Mt(s.beatFields)}. Times are ms; \`to\` and \`target\` are scene px; \`onto\` is a floor's scene y.`,"","`characterScript(target, who, beats, options)` compiles the same beats for a v2 `character()` on a `characterTarget` (every option but `height`; the same result, its key poses on the human body; the walk phase keyed to that character's stride, and `walk` / `walking` / `gait` tracks that step the gait as the target draws). Add `hairFollowTracks(target, tracks, who)` after it so hanging hair swings.","","| `do` | Needs | What happens |","|---|---|---|",...Object.entries(s.actions).map(([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**: ${Mt(s.handShapes)}. **Mudras**: ${Mt(s.mudras)}.`,"","### Your own actions, gaits and personas","","Nothing is registered globally: pass your definitions where they are used.","",...Object.entries(n.custom.api).map(([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: ${Mt(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: ${Mt(n.character.poses)}. Expressions: ${Mt(n.character.expressions)}. Gags: ${Mt(n.character.gags)}.`,"","Appearance options of `character({ … })`, all plain data that turns with the head (see docs/character-appearance.md):","",`- \`build\`: ${Mt(n.character.builds)}`,`- \`hair\`: ${Mt(n.character.hair)} (colours: ${Mt(Object.keys(n.character.hairColors))} in \`HAIR_COLORS\`)`,`- \`facialHair\`: ${Mt(n.character.facialHair)}`,`- \`glasses\`: ${Mt(n.character.glasses)}; \`hat\`: ${Mt(n.character.hats)}; \`ears: true\`; \`face: { teeth, tongue }\` (shown when the mouth opens); \`feet\`: ${Mt(n.character.feet)}`,"- `outfit`: `{ 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)\`: ${Mt(n.character.cast)}`,"- Face marks (pose fields, 0–1): `blush`, `tears`, `sweat`; close-up fields `pupil` (size, 1 usual), `lid` (upper lids lowered, 0–1), `bulge` (eyes out of the head, 0–1); `face: { nose: true, inPupil(ctx, pupil) }`; `drawCharacterHead(ctx, who, pose, { x, y, radius })` draws just the head big","- 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): ${Mt(n.character.handMeetings)}; \`embrace(a, b)\` (a hug, \`embraceSpacing\` apart); \`helpUp(helper, sitter, progress)\` (0 on the floor, hand taken; 1 standing; \`helpUpSpacing\` apart)`,"- Everyday cycles like a gait: `humanCyclePose('sweeping' | 'brushing', phase, base)` (0 → 1 is one stroke and back; sweeping with `holding: { right: 'broom' }`)","","## Code panel","",`\`codePanel({ code, language, x, y, fontSize?, lineHeight?, width? })\`: a code listing as a scene object. Languages: ${Mt(n.codePanel.languages)}. Remove styles: ${Mt(n.codePanel.removeStyles)}.`,"",...Object.entries(n.codePanel.anchors).map(([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 QM(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=Yt(`${r.kind}:${r.time}:${r.x}`);r.kind==="dust"?Rf(t,{x:r.x,y:r.y},a,{size:o,color:i,seed:l}):r.kind==="exhaust"?nS(t,r,a,o,i,l):r.kind==="skid"?sS(t,r,a,n,i):r.kind==="honk"?iS(t,r,a,o,i):r.kind==="smoke"?tS(t,r,n,o,i):r.kind==="leaves"&&eS(t,r,a,o,s.leafColor??"#5cae5a",i,l)}}function tS(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 eS(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=Yt(`${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 nS(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=(Yt(`${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 sS(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 iS(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 oS(t){const e=new Et({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=Co(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:rS(r)}),c}function rS(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 aS(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 lS(t){const e=new Et({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=Co(t.leader,{state:e.getStateAtTime(f)},t.leaderId),g=p.anchor(t.hitch),m=p.values.turn,w=Gn(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 kp=new WeakMap;function cS(t,e){const n=e?.some(Boolean)?e.map(d=>d?1:0).join(""):"";let s=kp.get(t);s||kp.set(t,s=new Map);const i=s.get(n);if(i)return i;const o=Ks(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,M]=[r.vertices[m],r.vertices[w],r.vertices[v]],E=[b[0]-k[0],b[1]-k[1],b[2]-k[2]],A=[M[0]-k[0],M[1]-k[1],M[2]-k[2]],T=[E[1]*A[2]-E[2]*A[1],E[2]*A[0]-E[0]*A[2],E[0]*A[1]-E[1]*A[0]],S=T[0]*d.normal[0]+T[1]*d.normal[1]+T[2]*d.normal[2];c.push(...S>=0?[m,w,v]:[m,v,w])}});const h=l.flatMap(d=>{const f=Math.hypot(...d)||1;return[d[0]/f,d[1]/f,d[2]/f]}),u=Gi({positions:a,normals:h,indices:c});return s.size>=16&&s.clear(),s.set(n,u),u}function hS(t,e,n={}){const s=t.ink??n.ink??"#26262b",i=(n.outline??2)*(t.outline??1),o=t.glow&&e.glow>0?uS(t.glow.color,e.glow):void 0;return{color:t.fill??s,creases:Ks(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 uS(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 dS=Gi($u(1,.002,28));function fS(t,e,n){const s=t.rig,[i,o]=s.footprint??[s.length*.45,s.length],r=Math.max(0,xt(s,e,"lift")),a=Math.max(0,xt(s,e,"size"))/(1+r*.8);return{mesh:dS,world:At(n,kr([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 gS=new Set(["x","y","z","position","rotateX","rotateY","rotateZ","quaternion","scale","scaleX","scaleY","scaleZ","visible","opacity","color"]),pS=1,mS={kind:"prop",validate(t){const e=t,n=typeof e.prop=="string"&&e.prop in Jn?[]:[ut("prop preset",e.prop,Object.keys(Jn))];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 Kl(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[A,T]of n)typeof T=="number"&&!gS.has(A)&&(h[A]=T);h.turn=0,h.tilt=0;const u=At(i.view,s),d={toView:A=>jt(u,A),toScreen:A=>a(A)},f=d.toView([0,c.rig.height/2,0]);if(-f[2]<=i.near)return null;if(l.look==="mesh"){const A=wg(c.rig,h),T=A.map(({part:O,local:I})=>({part:O.id,mesh:Ks(O.shape),...Hl(Ks(O.shape),I)})),S=fg(T),x=A.map((O,I)=>({...O,hidden:pg(O.part.id,T[I].mesh,O.local,T[I].key,S)})).filter(({opacity:O})=>O>.01).map(({part:O,matrix:I,glow:_,opacity:C,hidden:F})=>({mesh:cS(O.shape,F),world:At(s,I),material:hS(O,{glow:_,opacity:C},{shading:l.shading,ink:l.ink,outline:l.outline})}));return{meshes:l.shadow===!1?x:[fS(c,h,s),...x]}}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:(A,T)=>{const S=jt(s,A),x=[s[0]*T[0]+s[4]*T[1]+s[8]*T[2],s[1]*T[0]+s[5]*T[1]+s[9]*T[2],s[2]*T[0]+s[6]*T[1]+s[10]*T[2]],O=Math.hypot(...x)||1;return{light:$d(S,[x[0]/O,x[1]/O,x[2]/O],o),fog:Id(r,Math.hypot(S[0]-i.position[0],S[1]-i.position[1],S[2]-i.position[2]))}},v=Dl(c.rig,h,d,m,{perspective:!0,near:i.near,slice:pS,light:w}),k={look:l.look,style:l.style,ink:l.ink,paper:l.paper,fog:r?.color},b=Ba(v),M=v.cells??[],E=Math.max(...M.map(A=>-A.depth),-f[2]);return{drawables:[...l.shadow===!1?[]:[{depth:E+c.rig.length,draw:A=>za(A,v,k)}],...M.map(A=>({depth:-A.depth,draw(T,S){T.lineCap="round",T.lineJoin="round",_d(T,A.parts,b,{...k,time:S.time})}}))]}}},Vl=["do","at","for","to","through","toward","speed","height","open","on","wind"],yS=.25,bS=800/180,wS=220,kS=300,vS=["turn"];function MS(t){const e=Fo(t),n=Object.keys(t.moves??{});return Object.keys(e).filter(s=>!n.includes(s)&&!vS.includes(s)&&!(e[s].needs??[]).includes("to"))}function vp(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=MS(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))Vl.includes(u)||l(ut("beat field",u,Vl,h[u]));if(typeof c.do!="string"||!i.includes(c.do)){const u=c.do==="turn"?"face":void 0;return l(ut(`${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&&!sn(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(sn))&&l("`through` is a list of points on the ground, each [x, z] metres.")),c.do==="face"&&!(sn(c.toward)||typeof c.toward=="number")&&l("`face` needs `toward`: a point [x, z] or a heading in degrees.")}),o}function SS(t,e,n,s){const i=vp(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(Yn),...Object.keys(e.rig.controls)])o[k]=s.values?.[k]??Et(e.rig,{},k);let[r,a]=s.position??[0,0],l=s.heading??0;const c=new Map,h=(k,y,E,x="linear")=>{const $=c.get(k)??[];$.push({time:y,value:E,easing:x}),c.set(k,$)},d=(k,y,E)=>h(k,y,E);h("x",0,r),h("z",0,a),h("rotateY",0,l);const u=(k,y)=>{const E=io(l,y);if(Math.abs(E)<1)return k;const x=Math.max(bM,Math.abs(E)*yM);return d("rotateY",k,l),l+=E,h("rotateY",k+x,l,"ease-in-out"),k+x},f=(k,y,E)=>{const x=xu([[r,a],...y.through??[y.to]]);if(x.length<2)return E;const $=u(E,Ln(x[0].point,x[1].point)),M=x[x.length-1].at,v=y.for??M/(y.speed??k.speed)*1e3,T=Lt("ease-in-out"),I=Math.min(wM,v/4);for(const[X,J]of Object.entries(k.set??{}))d(X,$,o[X]),h(X,$+1,J),o[X]=J;const O=k.flies?y.height??(o.lift>.05?o.lift:2):void 0,_=O!==void 0&&O>.05;for(const[X,J]of Object.entries(k.hold??{}))d(X,$,o[X]),h(X,$+I,J,"ease-out"),_||(h(X,$+v-I,J),h(X,$+v,0,"ease-in")),o[X]=_?J:0;O!==void 0&&(d("lift",$,o.lift),h("lift",$+Math.min(v*.35,1400),O,"ease-out"),h("lift",$+v,O),o.lift=O);const C={...o};let D=l;for(let X=0;;X=Math.min(M,X+mM)){const J=$+Pu(T,X/M)*v,{point:j,direction:A}=$u(x,X);D+=io(D,Ln([0,0],A)),h("x",J,j[0]),h("z",J,j[1]),h("rotateY",J,D);for(const[R,N]of Object.entries(k.perMetre??{}))h(R,J,C[R]+X*N);for(const[R,N]of Object.entries(k.perSecond??{}))h(R,J,C[R]+(J-$)/1e3*N);if(X>=M)break}for(const[X,J]of Object.entries(k.perMetre??{}))o[X]=C[X]+M*J;for(const[X,J]of Object.entries(k.perSecond??{}))o[X]=C[X]+v/1e3*J;return[r,a]=x[x.length-1].point,l=D,$+v},p=(k,y)=>{const E=Object.fromEntries(Object.entries(k).filter(([$])=>!["at","to","through","toward"].includes($))),x=Ug(t,e,[E],{start:{...o,turn:1},scale:100,style:s.style,exaggeration:s.exaggeration});for(const $ of x.tracks){if(SM.includes($.property))continue;const M=$.keyframes??[],v=o[$.property];if(!M.every(T=>T.value===v)){d($.property,y,v);for(const T of M)T.time>0&&c.get($.property).push({...T,time:y+T.time});o[$.property]=M[M.length-1].value}}return y+x.duration},g=[];let m=0;for(const k of n){const y=k.at??m;let E=y;const x=e.moves?.[k.do];x?E=f(x,k,y):k.do==="face"?E=u(y,typeof k.toward=="number"?k.toward:Ln([r,a],k.toward)):k.do==="hold"?E=y+(k.for??1e3):E=p(k,y),g.push({do:k.do,start:y,end:E}),m=E}const w=`${s.scene}/${t}`;return{tracks:[...c].map(([k,y])=>({id:`${t}-${k}`,target:w,property:k,keyframes:Au(y)})),duration:m,beats:g,end:{position:[r,a],heading:l,values:{...o}}}}const SM=["x","y","turn","facing","tilt"],TM=.35,Dl={seated:ie.sit,astride:{...ie.sit,"leg.left.spread":26,"leg.right.spread":26,"leg.left.swing":40,"leg.right.swing":40,"leg.left.knee":70,"leg.right.knee":70},driving:{...ie.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:{...ie.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:{...ie.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}},EM=22,tp=38;function Fl(t,e=Dl.cycling){const n=t*Math.PI*2,s=r=>({swing:(e["leg.left.swing"]??40)+EM*Math.cos(n+r),knee:(e["leg.left.knee"]??70)+tp*(.5+.5*Math.cos(n+r))-tp*.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 AM(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:Fl((o-t.start)/1e3*e,t.base),...r>0?{act:!1}:{}});return i.push({time:t.end,pose:Fl((t.end-t.start)/1e3*e,t.base),act:!1}),i}const ep=(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 xM(t){const e=`${t.scene}/${t.propId}`,n=new Ot({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=Ma({...t.character,height:1}),c={...gt,...t.pose??Dl.seated},h=Wi(l.plan,c,{height:t.height??1.7,contact:l.contact}).hip,d=t.facing??0,u=t.every??33,f={x:[],y:[],z:[],rotateY:[]};for(let m=t.start;;m=Math.min(t.end,m+u)){const w=n.getStateAtTime(m).values.get(e)??new Map,S=(C,D)=>{const q=w.get(C);return typeof q=="number"?q:D},k={...s.values};for(const C of Object.keys(a.controls))k[C]=S(C,s.values?.[C]??Et(a,{},C));for(const C of["pitch","roll","squash","lift","lean","size"])k[C]=S(C,s.values?.[C]??Et(a,{},C));const y=Zf(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 E=S("rotateY",s.heading??0),x=ep(y,E),$=[S("x",i)+x[0],S("y",o)+x[1],S("z",r)+x[2]],M=E+d,v=ep(h,M);let T=[$[0]-v[0],$[1]-v[1],$[2]-v[2]];const I=(C,D)=>{const q=D*D*(3-2*D);return[C[0]+(T[0]-C[0])*q,T[1]*q+TM*Math.sin(Math.PI*D),C[1]+(T[2]-C[1])*q]},O=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+O?T=I(t.mount.from,(m-t.start)/O):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:M}),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 np={ground:"#7fb56a",hills:"#5f9a58",city:"#4b5468",cloud:"#ffffff",sun:"#ffd45c",moon:"#f3f0e0",rain:"#9fc4e8",snow:"#ffffff",wall:"#e9e1cf",floor:"#b08a5e",skirting:"#8a6a44",frame:"#f7f3ea"},qs=[[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"]],zs=(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("")}`},$M=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 sp(t){const e=(t%24+24)%24;for(let n=1;n<qs.length;n++){const[s,i,o]=qs[n-1],[r,a,l]=qs[n];if(e<=r){const c=(e-s)/(r-s);return{top:zs(i,a,c),bottom:zs(o,l,c)}}}return{top:qs[0][1],bottom:qs[0][2]}}const PM=(t,e)=>{const n=((t-e)%24+24)%24;return n<=12?n/12:-1},IM=9,OM=55,_M=28;function ip(t){const{x:e,y:n,width:s,height:i}=t,o=t.kind??"sky",r=t.ground??n+i*.85,a={...np,...t.colors},l=t.horizon??"hills",c=t.window!==!1,h=$e(t.seed??1),d=s*i/1e5,u=Array.from({length:Math.ceil(IM*d)+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(OM*d)+4},()=>({u:h.next(),v:h.next(),speed:.8+h.next()*.5})),p=Array.from({length:Math.ceil(_M*d)+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*d)+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})),S={hour:t.hour??12,clouds:t.clouds??.3,wind:t.wind??0,rain:t.rain??0,snow:t.snow??0},k=Nn(),y=(T,I)=>k.keys(T)?.length?k.valueAt(T,I):S[T],E=(T,I)=>{const O=PM(T,I),_=O<0?.5:O,C=r-n;return{x:.1*s+.8*s*_,y:O<0?C+i*.2:C-Math.sin(_*Math.PI)*C*.8,up:O>=0}},x=(T,I,O,_,C)=>{const D=I("hour"),{top:q,bottom:X}=sp(D),J=T.createLinearGradient(0,_.y,0,_.ground);J.addColorStop(0,q),J.addColorStop(1,X),T.fillStyle=J,T.fillRect(_.x,_.y,_.w,_.ground-_.y);const j=$M(D);if(j<.6){T.fillStyle="#ffffff",T.globalAlpha=(.6-j)/.6*.9;for(const B of g)T.beginPath(),T.arc(_.x+B.u*_.w,_.y+B.v*(_.ground-_.y),B.size,0,Math.PI*2),T.fill();T.globalAlpha=1}const A=E(D,6),R=E(D,18),N=Math.min(_.w,_.h)*.06;if(A.up&&(T.fillStyle=a.sun,T.beginPath(),T.arc(_.x+A.x/s*_.w,_.y+A.y/i*_.h,N,0,Math.PI*2),T.fill()),R.up){const B=_.x+R.x/s*_.w,Y=_.y+R.y/i*_.h;T.fillStyle=a.moon,T.beginPath(),T.arc(B,Y,N*.8,0,Math.PI*2),T.fill(),T.fillStyle=q,T.beginPath(),T.arc(B-N*.35,Y-N*.15,N*.7,0,Math.PI*2),T.fill()}const P=Math.max(0,Math.min(1,I("clouds"))),L=Math.max(-1,Math.min(1,I("wind"))),W=Math.round(P*u.length);T.fillStyle=zs("#ffffff",a.cloud==="#ffffff"?"#ffffff":a.cloud,1),T.globalAlpha=.55+.4*j;for(let B=0;B<W;B++){const Y=u[B],V=((Y.u*_.w+L*O*.012*(.6+Y.size*.5))%(_.w*1.4)+_.w*1.4)%(_.w*1.4)-_.w*.2,F=_.x+V,U=_.y+(.08+Y.v*.42)*(_.ground-_.y),K=Math.min(_.w,_.h)*.07*Y.size;for(let st=0;st<Y.puffs;st++)T.beginPath(),T.ellipse(F+(st-(Y.puffs-1)/2)*K*.9,U+st%2*K*.25,K*(st%2?.8:1),K*.62,0,0,Math.PI*2),T.fill()}T.globalAlpha=1;const z=B=>zs(zs(B,"#0b1530",.65),B,j);if(l==="hills"){T.fillStyle=z(a.hills),T.beginPath(),T.moveTo(_.x,_.ground);const B=40;for(let Y=0;Y<=B;Y++){const V=Y/B;let F=0;m.forEach((U,K)=>F+=Math.sin(V*Math.PI*(1.5+K*.7)+U.phase)*U.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=z(a.city);let B=_.x;const Y=_.w/18;for(const V of w){if(B>_.x+_.w)break;const F=Y*V.w,U=_.h*.22*V.h;if(T.fillRect(B,_.ground-U,F,U),V.windows&&j<.5){T.fillStyle="#ffd66b",T.globalAlpha=.5-j;for(let K=_.ground-U+6;K<_.ground-8;K+=9)for(let st=B+4;st<B+F-4;st+=8)T.fillRect(st,K,3,4);T.globalAlpha=1,T.fillStyle=z(a.city)}B+=F+Y*.15}}T.fillStyle=z(a.ground),T.fillRect(_.x,_.ground,_.w,_.y+_.h-_.ground)},$=(T,I,O,_)=>{const C=Math.max(-1,Math.min(1,I("wind"))),D=Math.max(0,Math.min(1,I("rain"))),q=Math.max(0,Math.min(1,I("snow")));if(D>0){T.strokeStyle=a.rain,T.globalAlpha=.35+.45*D,T.lineWidth=1.2,T.lineCap="round";const X=_.h*.05,J=C*.45,j=Math.round(D*f.length);T.beginPath();for(let A=0;A<j;A++){const R=f[A],N=((R.v*_.h+O*R.speed*.9)%_.h+_.h)%_.h,P=((R.u*_.w+N*J)%_.w+_.w)%_.w;T.moveTo(_.x+P,_.y+N),T.lineTo(_.x+P+J*X,_.y+N+X)}T.stroke(),T.globalAlpha=1}if(q>0){T.fillStyle=a.snow,T.globalAlpha=.85;const X=Math.round(q*p.length);for(let J=0;J<X;J++){const j=p[J],A=((j.v*_.h+O*j.speed*.08)%_.h+_.h)%_.h,R=Math.sin(O*.002+j.sway)*_.w*.02,N=((j.u*_.w+R+C*A*.3)%_.w+_.w)%_.w;T.beginPath(),T.arc(_.x+N,_.y+A,j.size,0,Math.PI*2),T.fill()}T.globalAlpha=1}},v={kind:"scenery",target:{type:"custom",x:e,y:n,width:s,height:i,props:S,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(S).map(T=>[T,CM(T)]))},draw(T,I,O){const _=I.props??{},C=q=>Number(_[q]??S[q]??0);T.save();const D={x:0,y:0,w:s,h:i,ground:r-n};if(o==="sky")x(T,C,O,D),$(T,C,O,D);else if(T.fillStyle=a.wall,T.fillRect(0,0,s,D.ground),T.fillStyle=a.floor,T.fillRect(0,D.ground,s,i-D.ground),T.fillStyle=a.skirting,T.fillRect(0,D.ground-i*.012,s,i*.012),c){const q=s*.26,X=D.ground*.5,J=s*.62,j=D.ground*.14;T.fillStyle=a.frame,T.fillRect(J-6,j-6,q+12,X+12),T.save(),T.beginPath(),T.rect(J,j,q,X),T.clip(),x(T,C,O,{x:J,y:j,w:q,h:X,ground:j+X*.8}),$(T,C,O,{x:J,y:j,w:q,h:X}),T.restore(),T.strokeStyle=a.frame,T.lineWidth=4,T.beginPath(),T.moveTo(J+q/2,j),T.lineTo(J+q/2,j+X),T.moveTo(J,j+X/2),T.lineTo(J+q,j+X/2),T.stroke()}T.restore()}},ground:r,anchor(T,I=1/0){const O=y("hour",I);if(T==="sun"||T==="moon"){const _=E(O,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 S))throw new Error(`scenery: ${dt("value",T,Object.keys(S))}`);if(typeof I.value!="number"||!Number.isFinite(I.value))throw new Error("scenery.set needs `value`, a number");return k.tween(T,y(T,I.at),I.value,I,1e3),v},tracks:k.tracks};return v}function CM(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 op(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 HM(t,e){const n=op(t,e),s=ip(n.scenery),i=n.props.map(o=>tg({x:o.x,y:s.ground,prop:Cl(o.preset),scale:o.scale,values:{turn:o.turn??0,...o.values}}));return{scenery:s,props:i,ground:s.ground}}function RM(t){const{timeline:e}=t,n=new Je;for(const[c,h]of Object.entries(t.targets)){const d=typeof h=="string"?document.querySelector(h):h;if(!d)throw new Error(`quickPlay: no element found for target "${c}" (${String(h)})`);n.registerTarget(c,d)}e.onUpdate=c=>{n.applyState(c),t.onUpdate?.(c)},t.onComplete&&(e.onComplete=t.onComplete);let s=null,i=null,o=!1;const r=c=>{if(o)return;const h=i===null?0:c-i;i=c,h>0&&e.tick(h),s=requestAnimationFrame(r)},a=()=>{s!==null||o||(i=null,s=requestAnimationFrame(r))},l=()=>{s!==null&&cancelAnimationFrame(s),s=null,i=null};return n.applyState(e.getStateAtTime(e.currentTime)),t.autoplay!==!1&&(e.play(),a()),{timeline:e,adapter:n,play(){e.play(),a()},pause(){e.pause(),l()},restart(){e.stop(),e.play(),a()},seek(c){e.seek(c*1e3),n.applyState(e.getStateAtTime(e.currentTime))},destroy(){o=!0,l(),e.stop(),n.clearTargets()}}}const LM={timeline:e1,to(t,e,n){const s=new Ve(n);return s.to(t,e),s},from(t,e,n){const s=new Ve(n);return s.from(t,e),s},fromTo(t,e,n,s){const i=new Ve(s);return i.fromTo(t,e,n),i},set(t,e,n){const s=new Ve(n);return s.set(t,e),s}};function rp(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 NM(t,e){const n=t.length/4,s=new Float32Array(n*3),i=Math.min(.999,Math.max(0,e));for(let o=0;o<n;o++){const r=t[o*4]/255,a=t[o*4+1]/255,l=t[o*4+2]/255,c=t[o*4+3]/255,h=Math.max(r,a,l);if(h<=i)continue;const d=(h-i)/(1-i)*c/h;s[o*3]=r*d,s[o*3+1]=a*d,s[o*3+2]=l*d}return s}function ap(t,e,n,s,i){const o=new Float32Array(t.length),r=i?n:e,a=i?e:n,l=(h,d)=>(i?h*e+d:d*e+h)*3,c=s*2+1;for(let h=0;h<r;h++)for(let d=0;d<3;d++){let u=0;for(let f=-s;f<=s;f++)u+=t[l(h,Math.min(a-1,Math.max(0,f)))+d];for(let f=0;f<a;f++){o[l(h,f)+d]=u/c;const p=t[l(h,Math.max(0,f-s))+d],g=t[l(h,Math.min(a-1,f+s+1))+d];u+=g-p}}return o}function lp(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=ap(o,e,n,i,!0),o=ap(o,e,n,i,!1);return o}function DM(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=rp(t,r,a),c=l?.getContext("2d");if(!l||!c)return;c.imageSmoothingEnabled=!0,c.drawImage(t.canvas,0,0,r,a);const h=NM(c.getImageData(0,0,r,a).data,e.threshold??.55),d=(e.radius??Math.max(s,i)*.02)/o,u=lp(h,r,a,d),f=lp(h,r,a,d*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,u[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 FM(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=BM(e,s,i,o,r);a?(t.globalCompositeOperation="lighter",Wl(t,c,n.color)):qM(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,WM(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 WM(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 BM(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=Vc(o),a=Jc(o)??void 0,l=[];for(let c=0;c+1<t.length;c++){const h=(t[c].age+t[c+1].age)/2,d=i*(1-s*h);if(d<=0)continue;const u=c+2===t.length;l.push({corners:[r.left[c],r.left[c+1],r.right[c+1],r.right[c]],alpha:d,...u&&a&&{cap:a}})}return l}function Wl(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 qM(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 d=Math.floor(a)-1,u=Math.floor(l)-1,f=s?rp(t,Math.ceil(c)+1-d,Math.ceil(h)+1-u):null,p=f?.getContext("2d");if(!f||!p){Wl(t,e,n);return}p.translate(-d,-u),p.globalCompositeOperation="lighter",Wl(p,r,n),t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=1,t.drawImage(f,d,u),t.restore()}const zM=qt.to,YM=qt.from,KM=qt.fromTo,jM=qt.set,XM=qt.timeline,GM=qt.ticker,UM=qt.splitText,VM=qt.context,JM=qt.matchMedia,ZM=qt.quickTo,QM=qt.imageSequence,tS=qt.pageTransition;$y(),b.ACTING_STYLES=rn,b.AIRCRAFT_ACTING=Pl,b.ANIMAL_GAITS=Xn,b.BEAT_FIELDS=mo,b.BEAT_MOMENTS=qn,b.BED_ACTING=vg,b.BIRD_ACTING=Wg,b.BOARD_MARKS=Xa,b.BOARD_THEMES=_s,b.CANVAS_PROPERTIES=Mo,b.CHAIR_ACTING=yg,b.CHARACTER_BEAT_3D_FIELDS=Da,b.CHARACTER_CAST=Ja,b.CHARACTER_GAIT_SPEEDS=Iu,b.CHART_KINDS=Ua,b.CHART_SURFACE=sn,b.CHART_THEMES=Cs,b.CODE_LANGUAGES=ho,b.CODE_PANEL_EDITS=Ka,b.CODE_SURFACE=Os,b.CODE_THEME=Nu,b.Clock=dp,b.CompatTimeline=Ve,b.CustomBounce=Fh,b.CustomEase=Dh,b.CustomWiggle=Wh,b.DANCE_STYLES=Ce,b.DEFAULT_BAKE_INTERVAL_MS=Uo,b.DEFAULT_INERTIA_FRICTION=No,b.DEFAULT_LABELS=Uh,b.DEFAULT_SPRING=jt,b.DEFAULT_TRANSITION=Iy,b.DESK_ACTING=wg,b.DOOR_ACTING=Sg,b.Draggable=mr,b.EMBRACE=uo,b.EXPRESSIONS=kt,b.FACIAL_HAIR_STYLES=da,b.FINGERS=d0,b.FLIPS=ks,b.FOOT_SHAPES=sd,b.FORMAT_VERSION=Oo,b.GAGS=Fe,b.GAITS=Dt,b.GAIT_CYCLE_MS=hl,b.GLASSES_STYLES=fa,b.HAIR_COLORS=ue,b.HAIR_STILL=In,b.HAIR_STYLES=ra,b.HAND_MEETINGS=Hs,b.HAND_REST=Pt,b.HAND_SHAPES=_t,b.HAT_STYLES=Ji,b.HELD_ITEMS=wa,b.HELP_UP=on,b.HORSE_ACTING=Fv,b.HORSE_GAITS=Rv,b.HOUSE_ACTING=pg,b.HUMAN_ACTING_RIG=Zu,b.HUMAN_BUILDS=Li,b.HUMAN_CYCLES=ma,b.HUMAN_EXPRESSIONS=Xr,b.HUMAN_GAGS=Zi,b.HUMAN_POSES=ie,b.HUMAN_REST=gt,b.IDENTITY_CAMERA=_u,b.INERTIA_MAX_DURATION_MS=jl,b.InertiaTrackPlayer=_c,b.LiveTimeline=de,b.MORPH_SAMPLES=Cp,b.MUDRAS=$i,b.ManualClock=hp,b.MediaSync=Ir,b.Observer=ph,b.POSES=Yt,b.PROP_BEAT_3D_FIELDS=Nl,b.PROP_BEAT_FIELDS=Po,b.PROP_COMMON_ACTIONS=Rl,b.PROP_COMMON_CONTROLS=Yn,b.PROP_PRESETS=Gn,b.PROP_SURFACE=jn,b.QUADRUPED_ACTING=Ol,b.REMOVE_STYLES=lo,b.REST_POSE=ct,b.RIDING_POSES=Dl,b.SAMPLE_STEP=Ne,b.SCENERY_COLORS=np,b.SCRIPT_ACTIONS=Ns,b.SPRING_MAX_DURATION_MS=Lo,b.SPRING_PRESETS=Us,b.SPRING_STEP_MS=hn,b.STICK_ACTING_RIG=Ju,b.ScrollAnimator=Oh,b.ScrollDriver=cs,b.ScrollMarkers=_h,b.ScrollPin=xh,b.SmoothScroll=xr,b.SpringSampler=Jn,b.SpringTrackPlayer=Oc,b.Stage=ch,b.TREE_ACTING=fg,b.Timeline=Ot,b.TinyflyPlayer=pi,b.TinyflySequencer=s0,b.TrackPlayer=ni,b.VEHICLE_ACTING=ng,b.VISEMES=We,b.ValueResolver=am,b.VisibilityDriver=Ah,b.WHEELCHAIR_ACTING=Ag,b.WHITEBOARD_SURFACE=be,b.actCharacterTracks=ef,b.actKeyframes=go,b.actTracks=tf,b.actionNames=rl,b.airplane=Pg,b.anchorError=De,b.animalStrideLength=$o,b.animatableProperties=Nf,b.applyBloom=DM,b.applyCamera=j2,b.applyGroove=X0,b.assertBeats=cl,b.backOut=nc,b.bakeDanceTracks=Xb,b.bakeEasing=Zo,b.bakeInertiaTrack=Jo,b.bakeSpringTrack=Vo,b.basicOutfit=Vd,b.beatAt=Yb,b.beatAtTime=ii,b.beatLength=or,b.beatTime=si,b.beatsBetween=wm,b.bed=kg,b.bike=hg,b.bindChoiceHotspots=Qh,b.bird=Ke,b.blendPose=xn,b.boilFrame=_r,b.bounceOut=ec,b.boxMesh=bu,b.brushingPose=Gd,b.buildScene=HM,b.bus=rg,b.cameraFromValues=K2,b.cameraPoint=X2,b.cameraTracks=Sm,b.capabilities=Vg,b.capabilitiesMarkdown=Jv,b.car=ig,b.cart=lg,b.castMember=Pk,b.cat=Hg,b.chair=mg,b.changingWindows=Dn,b.character=Ma,b.characterAt=S2,b.characterHandPose=su,b.characterJoints=te,b.characterJointsInView=k2,b.characterObjects=D2,b.characterPartsInView=ou,b.characterPoseOf=eo,b.characterPoseTracks=T2,b.characterScript=G5,b.characterScript3D=Y2,b.characterStrideLength=Hf,b.characterTarget=M2,b.charactersFor=Cc,b.chart=Ek,b.checkBeats=Ds,b.checkCast=al,b.checkCharacterBeats3D=Ou,b.checkPropBeats=Gg,b.checkPropBeats3D=Qg,b.checkSurfaceBeats=Of,b.checkTracks=ov,b.chicken=zg,b.circlePath=J2,b.clamp01=Sr,b.clearMorphCache=qp,b.clearPathCache=$p,b.clipErased=Ya,b.closestName=is,b.codePanel=lk,b.codeTokens=Fu,b.containerProgressAt=Tr,b.context=VM,b.controlValue=Et,b.cow=Rg,b.create=fy,b.createControls=Jh,b.createCubicBezier=Ql,b.createLive=zh,b.createPen=us,b.createRandom=$e,b.createTrack=ei,b.criticalDamping=gp,b.crow=qg,b.customBounce=Yc,b.customEase=zc,b.customWiggle=Kc,b.cylinderMesh=wu,b.danceFrame=Oi,b.dancePose=Fb,b.danceStance=Ii,b.danceTaps=Bb,b.danceTracks=jb,b.danceTravel=Ci,b.danceTravelTrack=Z0,b.dancer=Kb,b.defineAction=f5,b.defineGait=g5,b.describeTarget=Lf,b.deserializeTimeline=yn,b.deserializeTrack=Nc,b.desk=bg,b.detectTempo=km,b.dog=Cg,b.door=Mg,b.draggable=A1,b.drawCartoonHand=Si,b.drawCharacter=iu,b.drawCharacterInView=v2,b.drawDustPuff=of,b.drawEraser=qa,b.drawHand=za,b.drawHeldItem=ka,b.drawImpactStars=o5,b.drawPencil=Cu,b.drawProp=vv,b.drawPropEffects=Zv,b.drawPropShadow=Ia,b.drawSolvedFaces=fu,b.drawSolvedPart=$2,b.drawSolvedProp=$a,b.drawSpeedLines=sf,b.drawStickFigure=q0,b.drawStickSmear=i5,b.drawTrail=FM,b.drawnPathTarget=Z2,b.duck=Kg,b.easeIn=Vl,b.easeInCubic=Do,b.easeInOut=Zl,b.easeInOutCubic=Qn,b.easeInOutQuad=Ul,b.easeInQuad=Xl,b.easeOut=Jl,b.easeOutCubic=Fo,b.easeOutQuad=Gl,b.editDistance=Gc,b.editError=Is,b.editLog=Nn,b.elasticOut=tc,b.ellipsePoints=Cr,b.ellipsoidMesh=ku,b.embrace=Ck,b.embraceSpacing=_k,b.erasable=nk,b.expandBeats=bo,b.expandParametricEasings=Pc,b.extrudeMesh=vu,b.flipPose=Q0,b.flipTracks=lw,b.flipTravel=td,b.formatVersionFor=_o,b.from=YM,b.fromJSON=im,b.fromTo=KM,b.gag=nl,b.gagDuration=Rs,b.gaitPose=p0,b.gaitStrideLength=Ti,b.getEasingFunction=Lt,b.getInterpolator=ss,b.getMotionPathPoint=Qo,b.getPathLength=Pp,b.getPointAtProgress=ac,b.goat=Lg,b.gridLinesFor=bh,b.hairFollow=Uu,b.hairFollowTracks=Xk,b.hairHangs=bd,b.hairMotionAt=Kk,b.hairMotionOf=Gi,b.hairlineAt=As,b.handAt=V2,b.handGrip=Qi,b.handJoints=Mi,b.handJointsAt=g0,b.handPath=bl,b.handPose=It,b.handProp=bs,b.hasKeyframes=zl,b.hashSeed=Gt,b.headPoint=Pb,b.heldTime=Yl,b.helicopter=$g,b.helpUp=Rk,b.helpUpSpacing=Hk,b.holdingLayers=Qd,b.horse=_g,b.horseStrideLength=Bv,b.house=gg,b.humanCyclePose=u2,b.humanFieldLabel=Sw,b.humanGag=jd,b.humanGaitPose=ga,b.humanGaitStrideLength=pa,b.humanPlan=id,b.humanPose=bt,b.imageSequence=QM,b.inertiaDuration=un,b.inertiaRest=dn,b.inertiaValueAt=Js,b.inertiaVelocityAt=bp,b.interpolateArray=Ec,b.interpolateColor=Tc,b.interpolateMotionPath=Qp,b.interpolateNumber=le,b.interpolatePathString=xc,b.interpolateQuaternion=Ac,b.interpolateString=Go,b.isCubicBezierEasing=cn,b.isHeld=va,b.isInertiaTrack=Me,b.isMotionPathPoint=cp,b.isMotionPathTrack=Co,b.isParametricEasing=Un,b.isPathData=gn,b.isSpringTrack=Se,b.isTextTrack=Ks,b.isUnderdamped=fp,b.isUnresolved=rm,b.jointsInScene=cu,b.jointsToScene=B0,b.linear=Zs,b.lipSyncKeyframes=il,b.lipSyncOver=ol,b.lipSyncTracks=d5,b.lit=Ra,b.live=qt,b.loosePartsOf=xl,b.lyingPose=Og,b.mapEase=rs,b.mat4=Cm,b.matchMedia=JM,b.maxStaggerDistance=Ro,b.meetHands=Ok,b.meetingSpacing=Ik,b.mirrorHumanPose=nd,b.mirrorPose=j0,b.mixColors=La,b.mixHandPoses=An,b.mixPoses=au,b.morphPath=gc,b.motorbike=dg,b.mount=t0,b.mountAll=n0,b.narrationMarkers=pm,b.narrationSceneAt=mm,b.naturalRest=Zn,b.nearestBeat=ym,b.nextBeat=bm,b.niceCeiling=ju,b.owl=jg,b.pageTransition=tS,b.panelMesh=Mu,b.parametricEasing=ic,b.parrot=Xg,b.parseAnchor=nn,b.parseEdge=vr,b.parsePath=je,b.parseTrigger=Mr,b.partialPath=En,b.pathLength=l0,b.pedallingKeys=AM,b.pedallingPose=Fl,b.persona=j5,b.pieceMotion=Ps,b.pigeon=Yg,b.planNarration=gm,b.play=uy,b.playSequence=Py,b.playWhenVisible=F1,b.playheadCrossings=er,b.pointAlong=yi,b.pointAtDistance=Bo,b.pointOnHead=m2,b.pointsToPath=Uc,b.pose=Ct,b.poseTracks=Cb,b.propActions=Io,b.propAnchors3D=Zf,b.propAt=Eo,b.propControls=$l,b.propLineWidth=Pa,b.propObjects=pM,b.propPartsInSpace=Jf,b.propPreset=Cl,b.propRide=iM,b.propRide3D=xM,b.propScript=Ug,b.propScript3D=MM,b.propShapeMesh=Ws,b.propSurface=Tv,b.propTarget=tg,b.propTow=aM,b.propView=Gf,b.quadruped=ze,b.quat=Gp,b.quickPlay=RM,b.quickTo=ZM,b.rabbit=Ng,b.randomBetween=sr,b.randomChoice=om,b.randomSnapped=Fc,b.reachCharacter=ye,b.reachOf=Rf,b.resolveActingStyle=Qa,b.resolveCharacterPoseKeys=Aa,b.resolveFacialHair=Cd,b.resolveGait=ps,b.resolveGlasses=Rd,b.resolveHair=vd,b.resolveHat=Nd,b.resolveHeadLook=Fd,b.resolveHolding=Jd,b.resolvePoseKeys=xi,b.resolveSequence=qc,b.resolveStickFrame=Fr,b.resolveStickPose=z0,b.resolveValue=ir,b.ribbon=Vc,b.ribbonHeadCap=Jc,b.rideFloors=ao,b.rotateAbout=Oe,b.routineBeats=_i,b.rubberLimb=Ze,b.scenePreset=op,b.scenery=ip,b.scriptActionSummaries=ll,b.scriptTracks=ko,b.scrollProgress=D1,b.scrubOnScroll=z1,b.scrubPath=tk,b.seatHeight=Sb,b.serializeTimeline=Dc,b.serializeTrack=Rc,b.set=jM,b.shade=so,b.shapeMesh=Eu,b.shapeToPathData=oi,b.simplifyKeyframes=Ic,b.sittingPose=Il,b.skeletonInView=Bi,b.sketchPen=bi,b.skyColors=sp,b.smoothPath=Na,b.smoothToward=Eh,b.snapAxis=yh,b.snapConfig=$h,b.snapDuration=Ih,b.snapProgress=Ph,b.solveAt=Kn,b.solvePlanSpace=Fi,b.solveProp=Al,b.songbird=Bg,b.soundsOf=ff,b.speechDuration=If,b.spliceTracks=rM,b.splitText=UM,b.springDuration=Kl,b.springFollow=os,b.springValueAt=up,b.squirrel=Dg,b.stagePlanSpace=Wi,b.staggerDistance=Ho,b.staggerOffset=js,b.staggerOffsets=Xs,b.staggerSpan=Vn,b.stepsDuration=pf,b.stepsEasing=sc,b.stepsToKeys=sl,b.stickFigureAt=Br,b.stickFigureJoints=se,b.stickFigureTarget=Wr,b.stickToHuman=od,b.strideLength=v0,b.surfaceBox=vt,b.surfaceScript=Y5,b.sweepingPose=Xd,b.syncMediaElement=Gh,b.talkingMouth=M0,b.taperedLine=wi,b.taperedOutline=Nt,b.textAt=Hc,b.tf=LM,b.ticker=GM,b.timeline=XM,b.to=zM,b.toJSON=sm,b.toKeyframedTrack=Jp,b.toKeyframedTracks=Zp,b.trackTargets=xe,b.tractor=ag,b.trailSamples=Em,b.trainCar=cg,b.tree=ug,b.triggerDistance=vn,b.truck=og,b.tubeMesh=Su,b.unknownName=dt,b.unmount=Ay,b.valueAt=ro,b.vec3=xm,b.vehicle=ve,b.walkPose=k0,b.wheelchair=Eg,b.whiteboard=fk,b.withErased=ek,b.withExpression=_e,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
66
+ `)}`);const o={};for(const k of[...Object.keys(Xn),...Object.keys(e.rig.controls)])o[k]=s.values?.[k]??xt(e.rig,{},k);let[r,a]=s.position??[0,0],l=s.heading??0;const c=new Map,h=(k,b,M,E="linear")=>{const A=c.get(k)??[];A.push({time:b,value:M,easing:E}),c.set(k,A)},u=(k,b,M)=>h(k,b,M);h("x",0,r),h("z",0,a),h("rotateY",0,l);const d=(k,b)=>{const M=go(l,b);if(Math.abs(M)<1)return k;const E=Math.max(wS,Math.abs(M)*bS);return u("rotateY",k,l),l+=M,h("rotateY",k+E,l,"ease-in-out"),k+E},f=(k,b,M)=>{const E=tf([[r,a],...b.through??[b.to]]);if(E.length<2)return M;const A=d(M,Dn(E[0].point,E[1].point)),T=E[E.length-1].at,S=b.for??T/(b.speed??k.speed)*1e3,x=Ht("ease-in-out"),O=Math.min(kS,S/4);for(const[X,J]of Object.entries(k.set??{}))u(X,A,o[X]),h(X,A+1,J),o[X]=J;const I=k.flies?b.height??(o.lift>.05?o.lift:2):void 0,_=I!==void 0&&I>.05;for(const[X,J]of Object.entries(k.hold??{}))u(X,A,o[X]),h(X,A+O,J,"ease-out"),_||(h(X,A+S-O,J),h(X,A+S,0,"ease-in")),o[X]=_?J:0;I!==void 0&&(u("lift",A,o.lift),h("lift",A+Math.min(S*.35,1400),I,"ease-out"),h("lift",A+S,I),o.lift=I);const C={...o};let F=l;for(let X=0;;X=Math.min(T,X+yS)){const J=A+nf(x,X/T)*S,{point:K,direction:P}=ef(E,X);F+=go(F,Dn([0,0],P)),h("x",J,K[0]),h("z",J,K[1]),h("rotateY",J,F);for(const[R,N]of Object.entries(k.perMetre??{}))h(R,J,C[R]+X*N);for(const[R,N]of Object.entries(k.perSecond??{}))h(R,J,C[R]+(J-A)/1e3*N);if(X>=T)break}for(const[X,J]of Object.entries(k.perMetre??{}))o[X]=C[X]+T*J;for(const[X,J]of Object.entries(k.perSecond??{}))o[X]=C[X]+S/1e3*J;return[r,a]=E[E.length-1].point,l=F,A+S},p=(k,b)=>{const M=Object.fromEntries(Object.entries(k).filter(([A])=>!["at","to","through","toward"].includes(A))),E=yp(t,e,[M],{start:{...o,turn:1},scale:100,style:s.style,exaggeration:s.exaggeration});for(const A of E.tracks){if(TS.includes(A.property))continue;const T=A.keyframes??[],S=o[A.property];if(!T.every(x=>x.value===S)){u(A.property,b,S);for(const x of T)x.time>0&&c.get(A.property).push({...x,time:b+x.time});o[A.property]=T[T.length-1].value}}return b+E.duration},g=[];let m=0;for(const k of n){const b=k.at??m;let M=b;const E=e.moves?.[k.do];E?M=f(E,k,b):k.do==="face"?M=d(b,typeof k.toward=="number"?k.toward:Dn([r,a],k.toward)):k.do==="hold"?M=b+(k.for??1e3):M=p(k,b),g.push({do:k.do,start:b,end:M}),m=M}const w=`${s.scene}/${t}`;return{tracks:[...c].map(([k,b])=>({id:`${t}-${k}`,target:w,property:k,keyframes:Qd(b)})),duration:m,beats:g,end:{position:[r,a],heading:l,values:{...o}}}}const TS=["x","y","turn","facing","tilt"],xS=.35,Jl={seated:oe.sit,astride:{...oe.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:{...oe.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:{...oe.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:{...oe.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}},ES=22,Mp=38;function Zl(t,e=Jl.cycling){const n=t*Math.PI*2,s=r=>({swing:(e["leg.left.swing"]??40)+ES*Math.cos(n+r),knee:(e["leg.left.knee"]??70)+Mp*(.5+.5*Math.cos(n+r))-Mp*.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 AS(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:Zl((o-t.start)/1e3*e,t.base),...r>0?{act:!1}:{}});return i.push({time:t.end,pose:Zl((t.end-t.start)/1e3*e,t.base),act:!1}),i}const Sp=(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 PS(t){const e=`${t.scene}/${t.propId}`,n=new Et({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=Ra({...t.character,height:1}),c={...gt,...t.pose??Jl.seated},h=Ki(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,F)=>{const z=w.get(C);return typeof z=="number"?z:F},k={...s.values};for(const C of Object.keys(a.controls))k[C]=v(C,s.values?.[C]??xt(a,{},C));for(const C of["pitch","roll","squash","lift","lean","size"])k[C]=v(C,s.values?.[C]??xt(a,{},C));const b=kg(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 M=v("rotateY",s.heading??0),E=Sp(b,M),A=[v("x",i)+E[0],v("y",o)+E[1],v("z",r)+E[2]],T=M+u,S=Sp(h,T);let x=[A[0]-S[0],A[1]-S[1],A[2]-S[2]];const O=(C,F)=>{const z=F*F*(3-2*F);return[C[0]+(x[0]-C[0])*z,x[1]*z+xS*Math.sin(Math.PI*F),C[1]+(x[2]-C[1])*z]},I=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+I?x=O(t.mount.from,(m-t.start)/I):t.dismount&&m>t.end-_&&(x=O(t.dismount.to,(t.end-m)/_)),f.x.push({time:m,value:x[0]}),f.y.push({time:m,value:x[1]}),f.z.push({time:m,value:x[2]}),f.rotateY.push({time:m,value:T}),m>=t.end)break}const p=t.riderId,g=`${t.scene}/${p}`;return Object.keys(f).map(m=>({id:`${p}-${m}`,target:g,property:m,keyframes:f[m]}))}const Tp={ground:"#7fb56a",hills:"#5f9a58",city:"#4b5468",cloud:"#ffffff",sun:"#ffd45c",moon:"#f3f0e0",rain:"#9fc4e8",snow:"#ffffff",wall:"#e9e1cf",floor:"#b08a5e",skirting:"#8a6a44",frame:"#f7f3ea"},Gs=[[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"]],Us=(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("")}`},$S=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 xp(t){const e=(t%24+24)%24;for(let n=1;n<Gs.length;n++){const[s,i,o]=Gs[n-1],[r,a,l]=Gs[n];if(e<=r){const c=(e-s)/(r-s);return{top:Us(i,a,c),bottom:Us(o,l,c)}}}return{top:Gs[0][1],bottom:Gs[0][2]}}const IS=(t,e)=>{const n=((t-e)%24+24)%24;return n<=12?n/12:-1},OS=9,_S=55,CS=28;function Ep(t){const{x:e,y:n,width:s,height:i}=t,o=t.kind??"sky",r=t.ground??n+i*.85,a={...Tp,...t.colors},l=t.horizon??"hills",c=t.window!==!1,h=Pe(t.seed??1),u=s*i/1e5,d=Array.from({length:Math.ceil(OS*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(_S*u)+4},()=>({u:h.next(),v:h.next(),speed:.8+h.next()*.5})),p=Array.from({length:Math.ceil(CS*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=Wn(),b=(x,O)=>k.keys(x)?.length?k.valueAt(x,O):v[x],M=(x,O)=>{const I=IS(x,O),_=I<0?.5:I,C=r-n;return{x:.1*s+.8*s*_,y:I<0?C+i*.2:C-Math.sin(_*Math.PI)*C*.8,up:I>=0}},E=(x,O,I,_,C)=>{const F=O("hour"),{top:z,bottom:X}=xp(F),J=x.createLinearGradient(0,_.y,0,_.ground);J.addColorStop(0,z),J.addColorStop(1,X),x.fillStyle=J,x.fillRect(_.x,_.y,_.w,_.ground-_.y);const K=$S(F);if(K<.6){x.fillStyle="#ffffff",x.globalAlpha=(.6-K)/.6*.9;for(const B of g)x.beginPath(),x.arc(_.x+B.u*_.w,_.y+B.v*(_.ground-_.y),B.size,0,Math.PI*2),x.fill();x.globalAlpha=1}const P=M(F,6),R=M(F,18),N=Math.min(_.w,_.h)*.06;if(P.up&&(x.fillStyle=a.sun,x.beginPath(),x.arc(_.x+P.x/s*_.w,_.y+P.y/i*_.h,N,0,Math.PI*2),x.fill()),R.up){const B=_.x+R.x/s*_.w,Y=_.y+R.y/i*_.h;x.fillStyle=a.moon,x.beginPath(),x.arc(B,Y,N*.8,0,Math.PI*2),x.fill(),x.fillStyle=z,x.beginPath(),x.arc(B-N*.35,Y-N*.15,N*.7,0,Math.PI*2),x.fill()}const $=Math.max(0,Math.min(1,O("clouds"))),L=Math.max(-1,Math.min(1,O("wind"))),W=Math.round($*d.length);x.fillStyle=Us("#ffffff",a.cloud==="#ffffff"?"#ffffff":a.cloud,1),x.globalAlpha=.55+.4*K;for(let B=0;B<W;B++){const Y=d[B],U=((Y.u*_.w+L*I*.012*(.6+Y.size*.5))%(_.w*1.4)+_.w*1.4)%(_.w*1.4)-_.w*.2,D=_.x+U,V=_.y+(.08+Y.v*.42)*(_.ground-_.y),j=Math.min(_.w,_.h)*.07*Y.size;for(let st=0;st<Y.puffs;st++)x.beginPath(),x.ellipse(D+(st-(Y.puffs-1)/2)*j*.9,V+st%2*j*.25,j*(st%2?.8:1),j*.62,0,0,Math.PI*2),x.fill()}x.globalAlpha=1;const q=B=>Us(Us(B,"#0b1530",.65),B,K);if(l==="hills"){x.fillStyle=q(a.hills),x.beginPath(),x.moveTo(_.x,_.ground);const B=40;for(let Y=0;Y<=B;Y++){const U=Y/B;let D=0;m.forEach((V,j)=>D+=Math.sin(U*Math.PI*(1.5+j*.7)+V.phase)*V.amp),x.lineTo(_.x+U*_.w,_.ground-Math.max(0,D)*_.h*.045-_.h*.03)}x.lineTo(_.x+_.w,_.ground),x.closePath(),x.fill()}else if(l==="city"){x.fillStyle=q(a.city);let B=_.x;const Y=_.w/18;for(const U of w){if(B>_.x+_.w)break;const D=Y*U.w,V=_.h*.22*U.h;if(x.fillRect(B,_.ground-V,D,V),U.windows&&K<.5){x.fillStyle="#ffd66b",x.globalAlpha=.5-K;for(let j=_.ground-V+6;j<_.ground-8;j+=9)for(let st=B+4;st<B+D-4;st+=8)x.fillRect(st,j,3,4);x.globalAlpha=1,x.fillStyle=q(a.city)}B+=D+Y*.15}}x.fillStyle=q(a.ground),x.fillRect(_.x,_.ground,_.w,_.y+_.h-_.ground)},A=(x,O,I,_)=>{const C=Math.max(-1,Math.min(1,O("wind"))),F=Math.max(0,Math.min(1,O("rain"))),z=Math.max(0,Math.min(1,O("snow")));if(F>0){x.strokeStyle=a.rain,x.globalAlpha=.35+.45*F,x.lineWidth=1.2,x.lineCap="round";const X=_.h*.05,J=C*.45,K=Math.round(F*f.length);x.beginPath();for(let P=0;P<K;P++){const R=f[P],N=((R.v*_.h+I*R.speed*.9)%_.h+_.h)%_.h,$=((R.u*_.w+N*J)%_.w+_.w)%_.w;x.moveTo(_.x+$,_.y+N),x.lineTo(_.x+$+J*X,_.y+N+X)}x.stroke(),x.globalAlpha=1}if(z>0){x.fillStyle=a.snow,x.globalAlpha=.85;const X=Math.round(z*p.length);for(let J=0;J<X;J++){const K=p[J],P=((K.v*_.h+I*K.speed*.08)%_.h+_.h)%_.h,R=Math.sin(I*.002+K.sway)*_.w*.02,N=((K.u*_.w+R+C*P*.3)%_.w+_.w)%_.w;x.beginPath(),x.arc(_.x+N,_.y+P,K.size,0,Math.PI*2),x.fill()}x.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(x=>[x,HS(x)]))},draw(x,O,I){const _=O.props??{},C=z=>Number(_[z]??v[z]??0);x.save();const F={x:0,y:0,w:s,h:i,ground:r-n};if(o==="sky")E(x,C,I,F),A(x,C,I,F);else if(x.fillStyle=a.wall,x.fillRect(0,0,s,F.ground),x.fillStyle=a.floor,x.fillRect(0,F.ground,s,i-F.ground),x.fillStyle=a.skirting,x.fillRect(0,F.ground-i*.012,s,i*.012),c){const z=s*.26,X=F.ground*.5,J=s*.62,K=F.ground*.14;x.fillStyle=a.frame,x.fillRect(J-6,K-6,z+12,X+12),x.save(),x.beginPath(),x.rect(J,K,z,X),x.clip(),E(x,C,I,{x:J,y:K,w:z,h:X,ground:K+X*.8}),A(x,C,I,{x:J,y:K,w:z,h:X}),x.restore(),x.strokeStyle=a.frame,x.lineWidth=4,x.beginPath(),x.moveTo(J+z/2,K),x.lineTo(J+z/2,K+X),x.moveTo(J,K+X/2),x.lineTo(J+z,K+X/2),x.stroke()}x.restore()}},ground:r,anchor(x,O=1/0){const I=b("hour",O);if(x==="sun"||x==="moon"){const _=M(I,x==="sun"?6:18);return{x:e+_.x,y:n+_.y}}if(x==="horizon")return{x:e+s/2,y:r-i*.03};if(x==="ground")return{x:e+s/2,y:r};throw new Error(`scenery: ${ut("place",x,["sun","moon","horizon","ground"])}`)},set(x,O){if(!(x in v))throw new Error(`scenery: ${ut("value",x,Object.keys(v))}`);if(typeof O.value!="number"||!Number.isFinite(O.value))throw new Error("scenery.set needs `value`, a number");return k.tween(x,b(x,O.at),O.value,O,1e3),S},tracks:k.tracks};return S}function HS(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 Ap(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(ut("scene preset",t,["park","street","office","home"]))}}function RS(t,e){const n=Ap(t,e),s=Ep(n.scenery),i=n.props.map(o=>Mg({x:o.x,y:s.ground,prop:Kl(o.preset),scale:o.scale,values:{turn:o.turn??0,...o.values}}));return{scenery:s,props:i,ground:s.ground}}function LS(t){const{timeline:e}=t,n=new Ze;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 NS={timeline:Q1,to(t,e,n){const s=new Je(n);return s.to(t,e),s},from(t,e,n){const s=new Je(n);return s.from(t,e),s},fromTo(t,e,n,s){const i=new Je(s);return i.fromTo(t,e,n),i},set(t,e,n){const s=new Je(n);return s.set(t,e),s}};function Pp(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 FS(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 $p(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 Ip(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=$p(o,e,n,i,!0),o=$p(o,e,n,i,!1);return o}function DS(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=Pp(t,r,a),c=l?.getContext("2d");if(!l||!c)return;c.imageSmoothingEnabled=!0,c.drawImage(t.canvas,0,0,r,a);const h=FS(c.getImageData(0,0,r,a).data,e.threshold??.55),u=(e.radius??Math.max(s,i)*.02)/o,d=Ip(h,r,a,u),f=Ip(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 WS(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=zS(e,s,i,o,r);a?(t.globalCompositeOperation="lighter",Ql(t,c,n.color)):qS(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,BS(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 BS(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 zS(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=dh(o),a=fh(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 Ql(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 qS(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?Pp(t,Math.ceil(c)+1-u,Math.ceil(h)+1-d):null,p=f?.getContext("2d");if(!f||!p){Ql(t,e,n);return}p.translate(-u,-d),p.globalCompositeOperation="lighter",Ql(p,r,n),t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=1,t.drawImage(f,u,d),t.restore()}const YS=Kt.to,jS=Kt.from,KS=Kt.fromTo,XS=Kt.set,GS=Kt.timeline,US=Kt.ticker,VS=Kt.splitText,JS=Kt.context,ZS=Kt.matchMedia,QS=Kt.quickTo,tT=Kt.imageSequence,eT=Kt.pageTransition;Eb(),y.ACTING_STYLES=ln,y.AIRCRAFT_ACTING=zl,y.ANIMAL_GAITS=Vn,y.BEAT_FIELDS=To,y.BEAT_MOMENTS=jn,y.BED_ACTING=qg,y.BIRD_ACTING=lp,y.BOARD_MARKS=ll,y.BOARD_THEMES=Ds,y.CANVAS_PROPERTIES=Io,y.CHAIR_ACTING=Dg,y.CHARACTER_BEAT_3D_FIELDS=Ja,y.CHARACTER_CAST=dl,y.CHARACTER_GAIT_SPEEDS=af,y.CHART_KINDS=hl,y.CHART_SURFACE=rn,y.CHART_THEMES=Ws,y.CODE_LANGUAGES=ko,y.CODE_PANEL_EDITS=rl,y.CODE_SURFACE=Fs,y.CODE_THEME=gf,y.Clock=Cp,y.CompatTimeline=Je,y.CustomBounce=o0,y.CustomEase=i0,y.CustomWiggle=r0,y.DANCE_STYLES=Ce,y.DEFAULT_BAKE_INTERVAL_MS=sr,y.DEFAULT_INERTIA_FRICTION=jo,y.DEFAULT_LABELS=p0,y.DEFAULT_SPRING=Vt,y.DEFAULT_TRANSITION=Pb,y.DESK_ACTING=Bg,y.DOOR_ACTING=jg,y.Draggable=$r,y.EMBRACE=vo,y.EXPRESSIONS=kt,y.FACIAL_HAIR_STYLES=Ta,y.FINGERS=O0,y.FLIPS=Es,y.FOOT_SHAPES=Su,y.FORMAT_VERSION=Do,y.FRAME_ASPECTS=hh,y.GAGS=We,y.GAITS=Ft,y.GAIT_CYCLE_MS=Sl,y.GLASSES_STYLES=Ea,y.HAIR_COLORS=de,y.HAIR_STILL=Cn,y.HAIR_STYLES=wa,y.HAND_MEETINGS=Bs,y.HAND_REST=It,y.HAND_SHAPES=_t,y.HAT_STYLES=so,y.HELD_ITEMS=_a,y.HELP_UP=an,y.HORSE_ACTING=WM,y.HORSE_GAITS=LM,y.HOUSE_ACTING=Ng,y.HUMAN_ACTING_RIG=$f,y.HUMAN_BUILDS=zi,y.HUMAN_CYCLES=$a,y.HUMAN_EXPRESSIONS=ra,y.HUMAN_GAGS=io,y.HUMAN_POSES=oe,y.HUMAN_REST=gt,y.IDENTITY_CAMERA=cf,y.IDENTITY_SIMILARITY=h1,y.INERTIA_MAX_DURATION_MS=oc,y.InertiaTrackPlayer=jc,y.LiveTimeline=ue,y.MORPH_SAMPLES=em,y.MUDRAS=Hi,y.ManualClock=_p,y.MediaSync=qr,y.Observer=Rh,y.POSES=Gt,y.PROP_BEAT_3D_FIELDS=Vl,y.PROP_BEAT_FIELDS=No,y.PROP_COMMON_ACTIONS=Gl,y.PROP_COMMON_CONTROLS=Xn,y.PROP_PRESETS=Jn,y.PROP_SURFACE=Un,y.QUADRUPED_ACTING=Yl,y.REMOVE_STYLES=bo,y.REST_POSE=ct,y.RIDING_POSES=Jl,y.SAMPLE_STEP=Fe,y.SCENERY_COLORS=Tp,y.SCRIPT_ACTIONS=qs,y.SPRING_MAX_DURATION_MS=Yo,y.SPRING_PRESETS=ei,y.SPRING_STEP_MS=dn,y.STICK_ACTING_RIG=Pf,y.ScrollAnimator=Jh,y.ScrollDriver=ps,y.ScrollMarkers=Zh,y.ScrollPin=Xh,y.SmoothScroll=Wr,y.SpringSampler=ts,y.SpringTrackPlayer=Yc,y.Stage=$h,y.TREE_ACTING=Rg,y.Timeline=Et,y.TinyflyPlayer=vi,y.TinyflySequencer=S0,y.TrackPlayer=as,y.VEHICLE_ACTING=Tg,y.VISEMES=Ne,y.ValueResolver=$m,y.VisibilityDriver=Kh,y.WHEELCHAIR_ACTING=Gg,y.WHITEBOARD_SURFACE=be,y.actCharacterTracks=_f,y.actKeyframes=So,y.actTracks=Of,y.actionNames=wl,y.airplane=Jg,y.anchorError=De,y.animalStrideLength=Lo,y.animatableProperties=og,y.applyBloom=DS,y.applyCamera=Zk,y.applyGroove=fu,y.applySimilarity=pr,y.aspectOf=gr,y.assertBeats=Ml,y.audioEnvelope=n1,y.backOut=pc,y.bakeDanceTracks=jw,y.bakeEasing=rr,y.bakeInertiaTrack=or,y.bakeSpringTrack=ir,y.basicOutfit=md,y.beatAt=zw,y.beatAtTime=cs,y.beatLength=ls,y.beatPeriod=Qm,y.beatPulse=e1,y.beatTime=li,y.beatsBetween=Bm,y.bed=zg,y.bike=_g,y.bindChoiceHotspots=w0,y.bird=je,y.blendPose=$n,y.boilFrame=jr,y.bounceOut=gc,y.boxMesh=jd,y.brushingPose=gd,y.bubblePath=v1,y.bubblePop=M1,y.buildScene=RS,y.bus=Pg,y.cameraFromValues=Jk,y.cameraPoint=Qk,y.cameraTracks=jm,y.capabilities=bp,y.capabilitiesMarkdown=ZM,y.car=Eg,y.cart=Ig,y.castMember=R5,y.cat=np,y.chair=Fg,y.changingWindows=Bn,y.character=Ra,y.characterAt=Mk,y.characterHandPose=Sd,y.characterJoints=ee,y.characterJointsInView=bk,y.characterLookAtTracks=Uk,y.characterObjects=Nk,y.characterPartsInView=xd,y.characterPoseOf=lo,y.characterPoseTracks=Sk,y.characterScript=Uv,y.characterScript3D=Gk,y.characterStrideLength=ng,y.characterTarget=vk,y.charactersFor=Kc,y.chart=O5,y.checkBeats=Ys,y.checkCast=kl,y.checkCharacterBeats3D=lf,y.checkPropBeats=mp,y.checkPropBeats3D=vp,y.checkSurfaceBeats=Qf,y.checkTracks=rM,y.chicken=up,y.circlePath=s5,y.clamp01=Lr,y.clearMorphCache=hm,y.clearPathCache=Vp,y.clipErased=ol,y.closestName=hs,y.codePanel=g5,y.codeTokens=mf,y.composeSimilarity=d1,y.containerProgressAt=Nr,y.context=JS,y.controlValue=xt,y.cow=sp,y.create=ub,y.createControls=y0,y.createCubicBezier=dc,y.createLive=c0,y.createPen=bs,y.createRandom=Pe,y.createTrack=ai,y.criticalDamping=Lp,y.crow=hp,y.curve=Zm,y.customBounce=sh,y.customEase=nh,y.customWiggle=ih,y.cylinderMesh=Kd,y.danceFrame=Ni,y.dancePose=Nw,y.danceStance=Li,y.danceTaps=Dw,y.danceTracks=Yw,y.danceTravel=Di,y.danceTravelTrack=bu,y.dancer=qw,y.defineAction=gv,y.defineGait=pv,y.describeTarget=ig,y.deserializeTimeline=wn,y.deserializeTrack=Vc,y.desk=Wg,y.detectTempo=zm,y.dog=ep,y.door=Yg,y.draggable=Ty,y.drawCartoonHand=$i,y.drawCharacter=Td,y.drawCharacterHead=kk,y.drawCharacterInView=wk,y.drawDustPuff=Rf,y.drawEraser=sl,y.drawHand=il,y.drawHeldItem=Ca,y.drawImpactStars=uv,y.drawPencil=hf,y.drawProp=MM,y.drawPropEffects=QM,y.drawPropShadow=za,y.drawSolvedFaces=_d,y.drawSolvedPart=Ak,y.drawSolvedProp=Wa,y.drawSpeedLines=Hf,y.drawStickFigure=lu,y.drawStickSmear=hv,y.drawTrail=WS,y.drawnPathTarget=i5,y.dripPath=k1,y.duck=fp,y.easeIn=cc,y.easeInCubic=Ko,y.easeInOut=uc,y.easeInOutCubic=ns,y.easeInOutQuad=lc,y.easeInQuad=rc,y.easeOut=hc,y.easeOutCubic=Xo,y.easeOutQuad=ac,y.editDistance=ah,y.editError=Ns,y.editLog=Wn,y.elasticOut=fc,y.ellipsePoints=Kr,y.ellipsoidMesh=Xd,y.embrace=D5,y.embraceSpacing=F5,y.envelopeAt=s1,y.erasable=l5,y.expandBeats=Eo,y.expandParametricEasings=zc,y.extrudeMesh=Gd,y.flipPose=wu,y.flipTracks=r2,y.flipTravel=ku,y.formatVersionFor=Wo,y.frameRect=i1,y.frameSize=o1,y.from=jS,y.fromJSON=Em,y.fromTo=KS,y.gag=yl,y.gagDuration=zs,y.gaitPose=R0,y.gaitStrideLength=Ii,y.getEasingFunction=Ht,y.getInterpolator=rs,y.getMotionPathPoint=ar,y.getPathLength=Jp,y.getPointAtProgress=kc,y.goat=ip,y.gridLinesFor=Fh,y.hairFollow=Ef,y.hairFollowTracks=Q5,y.hairHangs=Fu,y.hairMotionAt=J5,y.hairMotionOf=to,y.hairlineAt=Is,y.handAt=n5,y.handGrip=oo,y.handJoints=Pi,y.handJointsAt=H0,y.handPath=Ol,y.handPose=Ot,y.handProp=Ts,y.hasKeyframes=nc,y.hashSeed=Yt,y.headPoint=Aw,y.heldTime=sc,y.helicopter=Vg,y.helpUp=B5,y.helpUpSpacing=W5,y.holdingLayers=wd,y.horse=tp,y.horseStrideLength=zM,y.house=Lg,y.humanCyclePose=hk,y.humanFieldLabel=v2,y.humanGag=dd,y.humanGaitPose=Aa,y.humanGaitStrideLength=Pa,y.humanPlan=Tu,y.humanPose=bt,y.imageSequence=tT,y.inertiaDuration=gn,y.inertiaRest=fn,y.inertiaValueAt=si,y.inertiaVelocityAt=Wp,y.interpolateArray=Fc,y.interpolateColor=Nc,y.interpolateMotionPath=vm,y.interpolateNumber=le,y.interpolatePathString=Wc,y.interpolateQuaternion=Dc,y.interpolateString=nr,y.invertSimilarity=f1,y.isCubicBezierEasing=un,y.isHeld=Ha,y.isInertiaTrack=Me,y.isMotionPathPoint=Op,y.isMotionPathTrack=Bo,y.isParametricEasing=Zn,y.isPathData=mn,y.isSpringTrack=Se,y.isTextTrack=Js,y.isUnderdamped=Rp,y.isUnresolved=Pm,y.isoDepth=mr,y.isometricBoxFaces=yr,y.isometricFaces=br,y.jointsInScene=Pd,y.jointsToScene=au,y.linear=ii,y.lipSyncKeyframes=Ua,y.lipSyncOver=fo,y.lipSyncTracks=zk,y.lit=Xa,y.live=Kt,y.lookFields=Za,y.loopBeats=t1,y.loopEase=Xm,y.loopNoise=Gm,y.loosePartsOf=Wl,y.lyingPose=Qg,y.mapEase=ds,y.mat4=O1,y.matchMedia=ZS,y.maxStaggerDistance=qo,y.meetHands=N5,y.meetingSpacing=L5,y.metaballContours=b1,y.metaballField=mh,y.mirrorHumanPose=Mu,y.mirrorPose=du,y.mixColors=Ga,y.mixHandPoses=Pn,y.mixPoses=Ed,y.morphPath=Ac,y.motorbike=Cg,y.mount=k0,y.mountAll=M0,y.narrationMarkers=Nm,y.narrationSceneAt=Fm,y.naturalRest=es,y.nearestBeat=Dm,y.nextBeat=Wm,y.niceCeiling=Sf,y.objectPositionAt=nl,y.owl=gp,y.pageTransition=eT,y.panelMesh=Ud,y.parametricEasing=yc,y.parrot=pp,y.parseAnchor=on,y.parseEdge=Hr,y.parsePath=Ke,y.parseTrigger=Rr,y.partialPath=An,y.pathLength=P0,y.pedallingKeys=AS,y.pedallingPose=Zl,y.penroseStairs=y1,y.penroseTriangle=m1,y.persona=Xv,y.phaseOf=Xe,y.pieceMotion=Ls,y.pigeon=dp,y.pingPong=fr,y.planNarration=Lm,y.play=hb,y.playSequence=Ab,y.playWhenVisible=Ny,y.playheadCrossings=cr,y.pointAlong=Si,y.pointAtDistance=Uo,y.pointOnHead=gk,y.pointsToPath=uh,y.pose=Ct,y.poseTracks=Ow,y.powSimilarity=g1,y.projectIsometric=ui,y.propActions=Fo,y.propAnchors3D=kg,y.propAt=Co,y.propControls=Bl,y.propLineWidth=Ba,y.propObjects=mS,y.propPartsInSpace=wg,y.propPreset=Kl,y.propRide=oS,y.propRide3D=PS,y.propScript=yp,y.propScript3D=SS,y.propShapeMesh=Ks,y.propSurface=xM,y.propTarget=Mg,y.propTow=lS,y.propView=mg,y.quadruped=qe,y.quat=mm,y.quickPlay=LS,y.quickTo=QS,y.rabbit=op,y.randomBetween=ur,y.randomChoice=Am,y.randomSnapped=Zc,y.reachCharacter=ye,y.reachOf=sg,y.resolveActingStyle=gl,y.resolveCharacterPoseKeys=Fa,y.resolveFacialHair=Qu,y.resolveGait=vs,y.resolveGlasses=ed,y.resolveHair=Bu,y.resolveHat=sd,y.resolveHeadLook=od,y.resolveHolding=yd,y.resolvePoseKeys=Ci,y.resolveSequence=eh,y.resolveStickFrame=Zr,y.resolveStickPose=cu,y.resolveValue=dr,y.ribbon=dh,y.ribbonHeadCap=fh,y.rideFloors=yo,y.rotateAbout=Oe,y.routineBeats=Fi,y.rubberLimb=Qe,y.safeAreas=r1,y.scalePoints=T1,y.scenePreset=Ap,y.scenery=Ep,y.scriptActionSummaries=vl,y.scriptTracks=Po,y.scrollProgress=Ly,y.scrubOnScroll=By,y.scrubPath=r5,y.seatHeight=vw,y.serializeTimeline=Jc,y.serializeTrack=Gc,y.set=XS,y.shade=ho,y.shapeMesh=Zd,y.shapeToPathData=ci,y.similarity=u1,y.similarityAbout=gh,y.similarityFixedPoint=ph,y.similarityMatrix=p1,y.simplifyKeyframes=qc,y.sittingPose=ql,y.skeletonInView=Xi,y.sketchPen=Ti,y.skyColors=xp,y.smoothPath=Va,y.smoothToward=jh,y.snapAxis=Nh,y.snapConfig=Gh,y.snapDuration=Vh,y.snapProgress=Uh,y.solveAt=Gn,y.solvePlanSpace=ji,y.solveProp=Dl,y.songbird=cp,y.soundsOf=Yd,y.speechDuration=Zf,y.speechLength=sf,y.spliceTracks=aS,y.splitText=VS,y.springDuration=ic,y.springFollow=us,y.springValueAt=Hp,y.squashStretch=S1,y.squirrel=rp,y.stagePlanSpace=Ki,y.stageSpots=Vk,y.staggerDistance=zo,y.staggerOffset=Zs,y.staggerOffsets=Qs,y.staggerSpan=Qn,y.stepsDuration=Nf,y.stepsEasing=mc,y.stepsToKeys=bl,y.stickFigureAt=ta,y.stickFigureJoints=ie,y.stickFigureTarget=Qr,y.stickToHuman=xu,y.strideLength=B0,y.surfaceBox=vt,y.surfaceScript=jv,y.sweepingPose=fd,y.syncMediaElement=g0,y.talkingMouth=z0,y.taperedLine=xi,y.taperedOutline=Nt,y.textAt=Xc,y.tf=NS,y.ticker=US,y.timeline=GS,y.to=YS,y.toJSON=xm,y.toKeyframedTrack=wm,y.toKeyframedTracks=km,y.torusNoise=Um,y.trackTargets=Ae,y.tractor=$g,y.trailSamples=l1,y.trainCar=Og,y.tree=Hg,y.triggerDistance=Sn,y.truck=Ag,y.tubeMesh=Vd,y.unknownName=ut,y.unmount=Tb,y.valueAt=mo,y.vec3=x1,y.vehicle=ve,y.walkPose=W0,y.wheelchair=Xg,y.whiteboard=w5,y.withErased=a5,y.withExpression=_e,y.wobble=Km,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));