mien-avatar 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/avatars/aster.js +1 -1
- package/avatars/bloom.js +1 -1
- package/avatars/bombo.js +1 -1
- package/avatars/bud.js +1 -1
- package/avatars/cal.js +1 -1
- package/avatars/dew.js +1 -1
- package/avatars/dot.js +1 -1
- package/avatars/drift.js +1 -1
- package/avatars/ember.js +1 -1
- package/avatars/hex.js +1 -1
- package/avatars/hopper.js +1 -1
- package/avatars/kabo.js +1 -1
- package/avatars/kubo.js +1 -1
- package/avatars/lumi.js +1 -1
- package/avatars/mello.js +1 -1
- package/avatars/michi.js +1 -1
- package/avatars/miro.js +1 -1
- package/avatars/momo-solid.js +1 -1
- package/avatars/momo.js +1 -1
- package/avatars/moss.js +1 -1
- package/avatars/nimbus.js +1 -1
- package/avatars/nox.js +1 -1
- package/avatars/orbit.js +1 -1
- package/avatars/peony.js +1 -1
- package/avatars/pepo.js +1 -1
- package/avatars/pico.js +1 -1
- package/avatars/pip.js +1 -1
- package/avatars/pogo.js +1 -1
- package/avatars/puddle.js +1 -1
- package/avatars/puff.js +1 -1
- package/avatars/reed.js +1 -1
- package/avatars/rill.js +1 -1
- package/avatars/sable.js +1 -1
- package/avatars/sprig.js +1 -1
- package/avatars/sunny.js +1 -1
- package/avatars/taro.js +1 -1
- package/avatars/tempo.js +1 -1
- package/avatars/toque.js +1 -1
- package/avatars/wisp.js +1 -1
- package/avatars/zest.js +1 -1
- package/dist/core.js +1 -1
- package/dist/element.js +1 -1
- package/dist/index.js +1 -1
- package/dist/react.js +1 -1
- package/dist/runtime/{activate-CCUqRQyO.js → activate-C16bLpUy.js} +1 -1
- package/dist/runtime/{adapter-onjjGk6m.js → adapter-BtyIFq4s.js} +1 -1
- package/dist/runtime/{depth-C0ucFmd8.js → depth-Cj2wTnRA.js} +1 -1
- package/dist/runtime/{live-C2QiAIQ9.js → live-3QIUR7dM.js} +1 -1
- package/dist/runtime/{mount-CzvXPeZF.js → mount-Do-RWK8s.js} +1 -1
- package/dist/runtime/{paint-CxkSCDga.js → paint-T6aENHGJ.js} +1 -1
- package/dist/runtime/{playback-BeRsJu6S.js → playback-a02m3NQr.js} +1 -1
- package/dist/runtime/{render-f6uGZFDG.js → render-BZ-ifVuu.js} +1 -1
- package/dist/runtime/runs-BQEucHaT.js +1 -0
- package/dist/runtime/{sampledProfiles-BvP-O0oY.js → sampledProfiles-Bnlm4vdZ.js} +1 -1
- package/dist/runtime/{sculpt-DWr8rXDB.js → sculpt-CVu30RFI.js} +1 -1
- package/dist/runtime/{sockets-CM-eyf8W.js → sockets-n9lhW9hh.js} +1 -1
- package/dist/vue.js +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/runtime/runs-BIIveHSZ.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime-DK3Fl9T5.js";import{C as t,S as n,_ as r,b as i,c as a,d as o,f as s,g as c,h as l,l as u,m as d,n as f,o as p,p as m,s as h,t as g,u as _}from"./playback-BeRsJu6S.js";var v={},y={radial:`sculpt`,union:`sculpt`,hosts:`depth`,pieces:`depth`},b={},x;function ee(e,t){let n=x;x=e;try{return t()}finally{x=n}}var S=e=>{let t=x?x[e]:b[e]??v[e];if(!t)throw Error(`This avatar needs the "${y[e]??e}" part of the player. Import it and pass it to use().`);return t},te=e=>x?x[e]:b[e]??v[e],C=(...e)=>S(`sculpt`).reliefFaces(...e),w=e=>e.geometry,T=(e,t)=>{let n=e.length,r=(t/(Math.PI*2)%1+1)%1*n,i=Math.floor(r),a=r-i,o=t=>e[(i+t+n)%n],[s,c,l,u]=[o(-1),o(0),o(1),o(2)];return c+.5*a*(l-s+a*(2*s-5*c+4*l-u+a*(3*(c-l)+u-s)))},ne=(e,t,n,r)=>{let i=T(e,Math.atan2(n,t)),a=Math.hypot(t,n)/i;return Math.sqrt(Math.max(0,1-a**r))},E=1.2,D=2*E/120,O=160,k=new WeakMap,A=(e,t,n)=>{let r=Math.min(Math.max((t+E)/D,1),118.999),i=Math.min(Math.max((n+E)/D,1),118.999),a=Math.floor(r),o=Math.floor(i),s=(e,t,n,r,i)=>t+.5*i*(n-e+i*(2*e-5*t+4*n-r+i*(3*(t-n)+r-e))),c=t=>{let n=(o+t)*121+a;return s(e[n-1],e[n],e[n+1],e[n+2],r-a)};return s(c(-1),c(0),c(1),c(2),i-o)},re=[1,-1,121,-121],j=e=>{let t=new Float64Array(O),n=new Float64Array(O);for(let r=0;r<O;r+=1){let i=r/O*Math.PI*2,a=T(e,i);t[r]=a*Math.cos(i),n[r]=a*Math.sin(i)}let r=new Float64Array(O),i=new Float64Array(O),a=new Float64Array(O);for(let e=0;e<O;e+=1)r[e]=t[(e+1)%O]-t[e],i[e]=n[(e+1)%O]-n[e],a[e]=r[e]*r[e]+i[e]*i[e];let o=new Float32Array(14641);for(let s=0;s<121;s+=1)for(let c=0;c<121;c+=1){let l=-1.2+c*D,u=-1.2+s*D,d=1/0;for(let e=0;e<O;e+=1){let o=l-t[e],s=u-n[e],c=r[e],f=i[e],p=Math.min(Math.max((o*c+s*f)/a[e],0),1),m=o-c*p,h=s-f*p,g=m*m+h*h;g<d&&(d=g)}let f=Math.hypot(l,u)<T(e,Math.atan2(u,l));o[s*121+c]=f?Math.sqrt(d):-Math.sqrt(d)}return o},ie=(e,t,n)=>{let r=(t,r)=>e[r*n*121+t*n],i=[];for(let e=0;e<t;e+=1)for(let n=0;n<t;n+=1)r(n,e)>1e-6&&i.push(e*t+n);let a=new Int32Array(i.length*4).fill(-1),o=new Float64Array(i.length).fill(4);return i.forEach((e,n)=>{let i=e%t,s=(e-i)/t,c=r(i,s);[[i+1,s],[i-1,s],[i,s+1],[i,s-1]].forEach(([e,i],s)=>{let l=r(e,i);l>1e-6?a[n*4+s]=i*t+e:o[n]=o[n]+Math.min(-l/c,1e3)})}),{size:t,cells:Int32Array.from(i),inner:a,weight:o,height:new Float64Array(t*t),load:new Float64Array(t*t),left:new Float64Array(t*t)}},M=({cells:e,inner:t,weight:n,height:r,load:i},a)=>{for(let o=0;o<a;o+=1)for(let a=0;a<e.length;a+=1){let o=e[a],s=i[o];for(let e=0;e<4;e+=1){let n=t[a*4+e];n>=0&&(s+=r[n])}r[o]=s/n[a]}},ae=({cells:e,inner:t,weight:n,height:r,load:i,left:a})=>{let o=0;for(let s=0;s<e.length;s+=1){let c=e[s],l=i[c]-n[s]*r[c];for(let e=0;e<4;e+=1){let n=t[s*4+e];n>=0&&(l+=r[n])}a[c]=l,o=Math.max(o,Math.abs(l))}return o},oe=(e,t)=>{let n=e[t],r=e[t+1];if(!r){M(n,60);return}M(n,2),ae(n);let i=n.size;r.height.fill(0);for(let e of r.cells){let t=e%r.size,a=(e-t)/r.size*2*i+t*2,o=n.left;r.load[e]=4*(4*o[a]+2*(o[a-1]+o[a+1]+o[a-i]+o[a+i])+(o[a-i-1]+o[a-i+1]+o[a+i-1]+o[a+i+1]))/16}oe(e,t+1);let a=r.height,o=r.size;for(let e of n.cells){let t=e%i,r=(e-t)/i,s=t>>1,c=(r>>1)*o+s,l;l=t%2==0&&r%2==0?a[c]:r%2==0?(a[c]+a[c+1])/2:t%2==0?(a[c]+a[c+o])/2:(a[c]+a[c+1]+a[c+o]+a[c+o+1])/4,n.height[e]=n.height[e]+l}M(n,2)},se=[[121,1],[61,2],[31,4],[16,8]],N=1e-9,ce=e=>{let t=se.map(([t,n])=>ie(e,t,n)),n=t[0],r=D*D;for(let e of n.cells)n.load[e]=r;for(let e=0;e<40&&(oe(t,0),!(ae(n)<r*N));e+=1);return le(e,Array.from(n.cells),Float32Array.from(n.height))},le=(e,t,n)=>{let r=0,i=new Float32Array(14641);for(let a of t)r=Math.max(r,n[a]),i[a]=n[a]/e[a];for(let e=0;e<3;e+=1){let e=i.slice();for(let t=122;t<14519;t+=1){if(i[t]>0)continue;let n=0,r=0;for(let e of re)i[t+e]>0&&(n+=i[t+e],r+=1);r&&(e[t]=n/r)}i.set(e)}return{height:n,slope:i,peak:r}},ue=()=>{let e=new Map;return(t,n)=>{if(typeof WeakRef!=`function`)return n();let r=t.join(`,`),i=e.get(r)?.deref();if(i)return i;let a=n();if(e.size>=64)for(let[t,n]of e)n.deref()||e.delete(t);return e.set(r,new WeakRef(a)),a}},de=ue(),fe=ue(),P=new WeakMap,F=e=>{let t=P.get(e);return t||P.set(e,t=de(e,()=>j(e))),t},pe=e=>{let t=k.get(e);return t||(t=fe(e,()=>{let t=F(e);return{distance:t,...ce(t)}}),k.set(e,t)),t},me=new WeakMap,he=e=>{let t=me.get(e);if(t)return t;let{height:n}=pe(e),r=n.reduce((e,t)=>Math.max(e,t),0),i=0,a=0,o=0;n.forEach((e,t)=>{let n=e-r*.9;n<=0||(i+=n,a+=n*(-1.2+t%121*D),o+=n*(-1.2+Math.floor(t/121)*D))});let s=i>0?{x:a/i,y:o/i}:{x:0,y:0};return me.set(e,s),s},I=(e,t,n)=>A(F(e),t,n),ge=(e,t,n)=>{let r=pe(e),i=A(r.distance,t,n);if(i<=0)return 0;let a=Math.min(Math.max((i-2*D)/(2*D),0),1),o=A(r.slope,t,n)*i,s=a>0?A(r.height,t,n):0;return Math.sqrt(Math.max(s*a+o*(1-a),0)/r.peak)},_e=new WeakMap,ve=241,ye=(e,t)=>{let n=Array.from({length:O},(n,r)=>{let i=r/O*Math.PI*2,a=T(e,i),o=a*Math.cos(i),s=a*Math.sin(i);return t===`y`?{along:s,across:o}:{along:o,across:s}}),r=new Float32Array(ve),i=new Float32Array(ve),a=0;for(let e=0;e<ve;e+=1){let t=-1.2+e/240*2*E,o=1/0,s=-1/0;for(let e=0;e<O;e+=1){let r=n[e],i=n[(e+1)%O];if((r.along-t)*(i.along-t)>0||r.along===i.along)continue;let a=r.across+(t-r.along)/(i.along-r.along)*(i.across-r.across);o=Math.min(o,a),s=Math.max(s,a)}s>o&&(r[e]=(o+s)/2,i[e]=(s-o)/2,a=Math.max(a,i[e]))}return{centre:r,half:i,peak:a}},be=(e,t,n,r)=>{let i=_e.get(e);i||_e.set(e,i=new Map);let a=i.get(t);a||i.set(t,a=ye(e,t));let o=t===`y`?r:n,s=t===`y`?n:r,c=Math.min(Math.max((o+E)/(2*E)*240,0),239.999),l=Math.floor(c),u=c-l,d=e=>e[l]*(1-u)+e[l+1]*u,f=d(a.half),p=s-d(a.centre);return Math.sqrt(Math.max(0,f*f-p*p))/a.peak},xe=new WeakMap,Se=(e,t,n)=>{let r=xe.get(e);if(!r){r=new Float32Array(14641);for(let t=0;t<121;t++){let n=-1.2+t*D,i=0;for(let t=0;t<121;t++)i=Math.max(i,ge(e,-1.2+t*D,n));for(let e=0;e<121;e++)r[t*121+e]=i}xe.set(e,r)}return Math.max(0,Math.min(1,ge(e,t,n)/Math.max(1e-6,A(r,0,n))))},Ce=0,we=1,L=2,R=new Float64Array(8),Te=(e,t)=>{R[t]=((-e+2)*e-1)*e/2,R[t+1]=((3*e-5)*e*e+2)/2,R[t+2]=((-3*e+4)*e+1)*e/2,R[t+3]=(e-1)*e*e/2},Ee=(e,t,n,r)=>{let i=new Uint8Array(e*e),a=new Uint8Array(e*e),o=new Float32Array(e*e*t),s=new Float64Array(t);return{read:(c,l,u)=>{let d=Math.floor(c),f=Math.floor(l);if(!(d>=1&&f>=1&&d<e-2&&f<e-2))return!1;let p=f*e+d;if(a[p]===L)return!1;for(let r=0;a[p]===Ce&&r<4;r+=1)for(let c=0;c<4;c+=1){let l=(f-1+r)*e+d-1+c;if(i[l]===Ce&&(i[l]=n(d-1+c,f-1+r,s)?we:L,o.set(s,l*t)),i[l]===L)return a[p]=L,!1}let m=((f-1)*e+d-1)*t,h=e*t;if(a[p]===Ce){let e=(e,n,r)=>o[m+n*h+e*t+r],n=!0;for(let i=0;n&&i<t;i+=1)for(let t=0;n&&t<4;t+=1)for(let a=1;a<3;a+=1)(Math.abs(e(a-1,t,i)-2*e(a,t,i)+e(a+1,t,i))>r[i]||Math.abs(e(t,a-1,i)-2*e(t,a,i)+e(t,a+1,i))>r[i])&&(n=!1);if(a[p]=n?we:L,!n)return!1}Te(c-d,0),Te(l-f,4);let g=R[0],_=R[1],v=R[2],y=R[3];for(let e=0;e<t;e+=1){let n=0,r=m+e;for(let e=0;e<4;e+=1)n+=R[4+e]*(g*o[r]+_*o[r+t]+v*o[r+t*2]+y*o[r+t*3]),r+=h;u[e]=n}return!0}}},De=new WeakSet,Oe=e=>(De.add(e),e),ke=e=>e!==void 0&&De.has(e),Ae=e=>{if(e.type!==`blob`)return{x:0,y:0};let t=he(B(e));return{x:t.x*e.width/2,y:t.y*e.height/2}},je=e=>{if(e.type===`blob`)return(w(e)?.plate)?.map(([t,n])=>[t*e.width/2,n*e.height/2])},Me=(e,t,n)=>{if(!e)return 0;let r=Math.max(0,n-(e.from??0));return e.x*t*t+(e.y??0)*r*r},Ne=e=>{if(e.type!==`blob`)return;let t=w(e)?.bend;if(!t)return;let n=e.width/2||1,r=e.height/2||1;return(e,i)=>Me(t,e/n,i/r)*n},Pe=new WeakMap,z=e=>{if(e.type!==`blob`)return;let t=w(e).window;if(!t)return;let n=Pe.get(e);if(n?.source===t&&n.width===e.width&&n.height===e.height)return n.points;let r=t.map(([t,n])=>[t*e.width/2,n*e.height/2]);return Pe.set(e,{source:t,width:e.width,height:e.height,points:r}),r},Fe=e=>e.type===`cone`||e.type===`cylinder`||e.type===`cursor`,Ie=new WeakMap,Le=e=>{let t=e.type===`blob`?w(e):void 0,n=`${e.type}|${e.width}|${e.height}|${e.depth}|${e.roundness}|${e.morphRoundness??``}|${e.tipRoundness??``}|${e.baseRoundness??``}|${ze(e)}`,r=t?.radialDepthPower===void 0?n:`${n}|radialDepthPower:${t.radialDepthPower}`,i=Ie.get(e);if(i&&i.shape===t&&i.key===r)return i.sample;let a=(t,n)=>Xt(e,t,n);return Fe(e)&&Oe(a),Ie.set(e,{shape:t,key:r,sample:a}),a},Re=e=>e.type===`blob`&&w(e)?.flush?0:Math.min(12,e.depth*.04),ze=e=>{let t=e.type===`blob`?w(e).sockets:void 0;return t?[t.centers.flat().join(`,`),t.apertureRadius,t.rimOuterRadius,t.padRadius,t.plane,t.depth,t.power].join(`|`):``},Be=new WeakMap,Ve=0,He=e=>{if(!e)return``;let t=Be.get(e);return t===void 0&&Be.set(e,t=++Ve),t},Ue=e=>{let t=`${e.type}|${e.width}|${e.height}|${e.depth}|${e.roundness}|${e.morphRoundness??``}|${e.tipRoundness??``}|${e.baseRoundness??``}|${e.outline??``}|${He(e.geometry)}|${e.geometry?.relief?.rim??``}|${e.geometry?.relief?.bits??``}|${e.rotationCenter?.join(`,`)??``}|${ze(e)}`,n=e.type===`blob`?w(e).radialDepthPower:void 0;return n===void 0?t:`${t}|radialDepthPower:${n}`},We=e=>{let t=Ue(e),n=e.outlineRounding??1;return n===1?t:`${t}|outlineRounding:${n}`},Ge=e=>{if(e.type!==`blob`)return;let t=w(e);return t.sockets?t.sockets.plane*e.width:t.eyePlane===void 0?void 0:t.eyePlane*e.depth},Ke=new WeakMap,qe=(e,t=Ge(e))=>{if(t===void 0)return;let n=w(e),r=Ke.get(e);if(r?.shape===n&&r.depth===t)return r.sample;let i=(e,n)=>({point:[e,n,t],normal:[0,0,1]});return Ke.set(e,{shape:n,depth:t,sample:i}),i},Je=e=>{let t=Le(e),n=e.type===`blob`&&w(e).sockets?t:qe(e);if(n)return{sample:n,planar:!0};let r=z(e)?Re(e):0;return{sample:r?$e(t,r):t,planar:!1}},Ye=new WeakMap,Xe=e=>{let t=z(e);if(!t)return;let n=Ue(e),r=w(e),i=Ye.get(e),a=i?.key===n&&i.shape===r?i.floor:void 0;if(a===void 0){a=1/0;for(let[n,r]of t)a=Math.min(a,Xt(e,n,r).point[2]);a-=Re(e),Ye.set(e,{key:n,shape:r,floor:a})}return a},Ze=(e,t,n,r)=>{let i=Xe(e);return i!==void 0&&n[2]+Math.abs(r[0])*(t.width/2)+Math.abs(r[1])*(t.height/2)+Math.abs(r[2])*(t.depth/2)<i},Qe=new WeakMap,$e=(e,t)=>{let n=Qe.get(e);n||Qe.set(e,n=new Map);let r=n.get(t);if(r)return r;let i=(n,r)=>{let{point:i,normal:a}=e(n,r);return{point:[i[0],i[1],i[2]-t],normal:a}};return ke(e)&&Oe(i),n.size>=8&&n.delete(n.keys().next().value),n.set(t,i),i},B=e=>w(e).radii,et=(e,t,n,r)=>{let i=e.depth/2,a=Math.max(0,Math.min(1,e.roundness)),o=w(e),s=o.revolve,c=a>0?i*(o.radialDepthPower?ne(t,n,r,o.radialDepthPower):s?be(t,s,n,r):ge(t,n,r)):0;if(a>=1)return c;let l=I(t,n,r)*Math.min(e.width,e.height)/2,u=l>=i?i:Math.sqrt(Math.max(0,i**2-(i-l)**2));return u+(c-u)*a},tt=(e,t,n,r)=>{let i=w(e);if(i?.plate){let t=-Me(i.bend,n,r)*(e.width/2);return{front:e.depth/2+t,back:-e.depth/2+t}}let a=i?.relief;if(!a){let a=i.sections;if(!a){let i=et(e,t,n,r);return{front:i,back:-i}}let{profile:o}=a,s=0,c=o.length-2;for(;s<c;){let e=Math.floor((s+c)/2);o[e+1][0]<r?s=e+1:c=e}let l=o[s],u=o[s+1],d=Math.max(0,Math.min(1,(r-l[0])/(u[0]-l[0]))),f=e=>{let t=o[Math.max(0,s-1)],n=o[Math.min(o.length-1,s+2)],r=u[0]-l[0],i=(u[e]-t[e])/(u[0]-t[0])*r,a=(n[e]-l[e])/(n[0]-l[0])*r;return(2*d*d*d-3*d*d+1)*l[e]+(d*d*d-2*d*d+d)*i+(-2*d*d*d+3*d*d)*u[e]+(d*d*d-d*d)*a},p=f(1)*e.depth,m=f(2)*e.depth,h=(p+m)/2,g=Math.max(0,(p-m)/2),_=Se(t,n,r),v=Math.sqrt(Math.max(0,1-(1-_*_)**(a.frontPower/2))),y=a.frontTaper??0;return{front:h+g*(v*(1-y+y*v*v)),back:h-g*_}}return C(e,a,t,n,r)},nt=(e,t,n,r)=>{let i=w(e).sockets;return i?{front:S(`sockets`).socketFrontAt(i,n/2,r*e.height/(e.width*2),t.front/e.width)*e.width,back:t.back}:t},rt=(e,t,n,r)=>nt(e,tt(e,t,n,r),n,r),it=e=>{if(e.type!==`blob`)return;let t=w(e);if(!t.sections||t.relief||t.lobes||t.hull||t.plate||t.revolve)return;let{profile:n}=t.sections,r=t.sockets?t.sockets.plane*e.width:-1/0;for(let t=0;t<n.length-1;t++){let i=n[t],a=n[t+1],o=n[Math.max(0,t-1)],s=n[Math.min(n.length-1,t+2)],c=a[0]-i[0];for(let t of[1,2]){let n=(a[t]-o[t])/(a[0]-o[0])*c,l=(s[t]-i[t])/(s[0]-i[0])*c;r=Math.max(r,i[t]*e.depth,(i[t]+n/3)*e.depth,(a[t]-l/3)*e.depth,a[t]*e.depth)}}return r+Math.max(1,Math.abs(r),e.depth)*1e-7},at=(e,t,n)=>{if(e.type!==`blob`)return;let r=w(e);if(r.lobes||r.hull||r.plate||r.revolve)return;let i=t/(e.width/2||1),a=n/(e.height/2||1),o=ft(e);if(o?.read(t/o.step+V,n/o.step+V,ct))return nt(e,{front:ct[0],back:ct[1]},i,a);let s=ot(e,t,n);return s&&nt(e,s,i,a)},ot=(e,t,n)=>{let r=B(e),i=t/(e.width/2||1),a=n/(e.height/2||1);if(!(Math.hypot(i,a)>T(r,Math.atan2(a,i))))return tt(e,r,i,a)},st=160,V=82,ct=new Float64Array(2),H=new Float64Array(3),lt=(e,t,n)=>{let r=w(t),i=r.relief,a=e.get(t);return(!a||a.width!==t.width||a.height!==t.height||a.depth!==t.depth||a.roundness!==t.roundness||a.shape!==r||a.radii!==r.radii||a.sections!==r.sections||a.profile!==r.sections?.profile||a.sockets!==r.sockets||a.relief!==i||a.front!==i?.front||a.back!==i?.back||a.bits!==i?.bits||a.rim!==i?.rim)&&(a={width:t.width,height:t.height,depth:t.depth,roundness:t.roundness,shape:r,radii:r.radii,sections:r.sections,profile:r.sections?.profile,sockets:r.sockets,relief:i,front:i?.front,back:i?.back,bits:i?.bits,rim:i?.rim},e.set(t,a)),a.lattice??=n()},ut=new WeakMap,dt=new WeakMap,ft=e=>lt(dt,e,()=>{let t=Math.max(e.width,e.height)/st,n=t*.12;return Object.assign(Ee(165,2,(n,r,i)=>{let a=ot(e,(n-V)*t,(r-V)*t);return a?(i[0]=a.front,i[1]=a.back,!0):!1},[n,n]),{step:t})}),U=(e,t,n,r)=>{let i=w(e).lobes;if(i){let t=S(`sculpt`).lobePoint(i,n,r);return[t[0]*e.width/2,t[1]*e.height/2,t[2]*e.depth/2]}let a=Math.cos(r)*Math.sin(n),o=Math.sin(r),s=Math.cos(r)*Math.cos(n),c=T(t,Math.atan2(o,a));return[e.width/2*c*a,e.height/2*c*o,s>=0?rt(e,t,c*a,c*o).front:rt(e,t,c*a,c*o).back]},pt=(e,t)=>{let n=e.width/2||1,r=e.height/2||1,i=e.depth/2||1,a=t.normal[0]/n,o=t.normal[1]/r,s=t.normal[2]/i,c=Math.hypot(a,o,s)||1;return{point:[t.point[0]*n,t.point[1]*r,t.point[2]*i],normal:[a/c,o/c,s/c]}},mt=.001,ht=(e,t,n)=>{let r=w(e).lobes;if(r)return pt(e,S(`sculpt`).lobeSample(r,t,n));let i=B(e),a=Math.max(-Math.PI/2+mt*4,Math.min(Math.PI/2-mt*4,n)),o=U(e,i,t,a);if(w(e).sockets&&Math.cos(t)>=0)return gt(e,o[0],o[1]);let s=U(e,i,t+mt,a),c=U(e,i,t,a+mt),l=[s[0]-o[0],s[1]-o[1],s[2]-o[2]],u=[c[0]-o[0],c[1]-o[1],c[2]-o[2]],d=l[1]*u[2]-l[2]*u[1],f=l[2]*u[0]-l[0]*u[2],p=l[0]*u[1]-l[1]*u[0];d*o[0]+f*o[1]+p*o[2]<0&&(d=-d,f=-f,p=-p);let m=Math.hypot(d,f,p)||1;return{point:U(e,i,t,n),normal:[d/m,f/m,p/m]}},gt=(e,t,n)=>{let r=w(e).lobes;if(r)return pt(e,S(`sculpt`).lobeFrontRead(r,t/(e.width/2||1),n/(e.height/2||1)));let i=B(e),a=e.width/2||1,o=e.height/2||1,s=(t,n)=>rt(e,i,t/a,n/o).front,c=w(e);if(!c.plate&&!c.sockets){let r=lt(ut,e,()=>{let t=Math.max(e.width,e.height)/st;return Object.assign(Ee(165,3,(e,n,r)=>{let c=(e-V)*t,l=(n-V)*t;return Math.hypot(c/a,l/o)>T(i,Math.atan2(l/o,c/a))?!1:(r[0]=s(c,l),r[1]=s(c+.5,l)-s(c-.5,l),r[2]=s(c,l+.5)-s(c,l-.5),!0)},[t*.12,.03,.03]),{step:t})});if(r?.read(t/r.step+V,n/r.step+V,H)){let e=Math.hypot(H[1],H[2],1);return{point:[t,n,H[0]],normal:[-H[1]/e,-H[2]/e,1/e]}}}let l=s(t,n),u=s(t+.5,n)-s(t-.5,n),d=s(t,n+.5)-s(t,n-.5),f=Math.hypot(u,d,1);return{point:[t,n,l],normal:[-u/f,-d/f,1/f]}},_t=(e,t)=>Math.sign(e)*Math.abs(e)**t,vt=(e,t,n,r,i,a,o)=>{let s=_t(Math.cos(t),a);return[n/2*s*_t(Math.sin(e),o),r/2*_t(Math.sin(t),a),i/2*s*_t(Math.cos(e),o)]},yt=(e,t,n)=>{let r=e.width/2,i=e.depth/2,a=Math.min(r,e.height/2),o=Math.max(0,(e.height-a*2)/2),s=o*2+Math.PI*a,c=(n+Math.PI/2)/Math.PI*s,l=r,u=0;if(c<Math.PI*a/2){let e=-Math.PI/2+c/a;l=r*Math.cos(e),u=-o+a*Math.sin(e)}else if(c<=Math.PI*a/2+o*2)u=-o+c-Math.PI*a/2;else{let e=(c-Math.PI*a/2-o*2)/a;l=r*Math.cos(e),u=o+a*Math.sin(e)}let d=r?i/r:1;return[l*Math.sin(t),u,l*d*Math.cos(t)]},bt=e=>Math.max(0,Math.min(2,e??0)),xt=e=>1+bt(e.roundness)/2,St=.04,Ct=e=>e.roundness<=0?1/0:2/(St+bt(e.roundness)/2*.96),wt=(e,t,n,r)=>{let i=Math.cos(n)*Math.sin(t),a=Math.sin(n),o=Math.cos(n)*Math.cos(t),s=Number.isFinite(r)?(Math.abs(i)**r+Math.abs(a)**r+Math.abs(o)**r)**(1/r)||1:Math.max(Math.abs(i),Math.abs(a),Math.abs(o))||1;return[e.width/2*(i/s),e.height/2*(a/s),e.depth/2*(o/s)]},Tt=(e,t,n)=>wt(e,t,n,xt(e)),Et=(e,t,n)=>wt(e,t,n,Ct(e)),Dt=.24,Ot=.2,kt=.22,At=e=>bt(e.morphRoundness)/2,jt=(e,t,n)=>{let r=At(e),i=Math.max(0,Math.min(1,t)),a=Math.sin(i*Math.PI),o=(1-Math.cos(i*Math.PI))/2;return{radiusScale:n.radiusScale+(a-n.radiusScale)*r,verticalProgress:n.verticalProgress+(o-n.verticalProgress)*r}},Mt=(e,t,n,r,i)=>{let a=1-i;return a**3*e+3*a*a*i*t+3*a*i*i*n+i**3*r},Nt=e=>({tipFraction:(e.tipRoundness??0)*Dt,baseFraction:(e.baseRoundness??0)*Ot}),Pt=(e,t)=>{let n=Math.max(0,Math.min(1,t)),r=e.roundness*kt;if(r<=0)return{radiusScale:1,verticalProgress:(Math.sin((n-.5)*Math.PI)+1)/2};if(n<r){let e=-Math.PI/2+n/r*(Math.PI/2);return{radiusScale:1-r+r*Math.cos(e),verticalProgress:(r+r*Math.sin(e))/2}}if(n>1-r){let e=(n-(1-r))/r*(Math.PI/2);return{radiusScale:1-r+r*Math.cos(e),verticalProgress:1-r/2+r*Math.sin(e)/2}}let i=(n-r)/(1-r*2);return{radiusScale:1,verticalProgress:r/2+i*(1-r)}},Ft=(e,t)=>jt(e,t,Pt(e,t)),It=(e,t,n)=>{let r=Math.max(0,Math.min(1,t)),i=0,a=1;for(let t=0;t<14;t+=1){let t=(i+a)/2;n(e,t).verticalProgress<r?i=t:a=t}return n(e,(i+a)/2).radiusScale},Lt=(e,t)=>{let n=Math.max(0,Math.min(1,t)),{tipFraction:r,baseFraction:i}=Nt(e);if(i>0&&n<i){let e=n/i;return{radiusScale:Mt(1-i,1,1-i/2,1-i,e),verticalProgress:Mt(0,0,i/2,i,e)}}if(r>0&&n>1-r){let e=(n-(1-r))/r;return{radiusScale:Mt(r,r/2,r/4,0,e),verticalProgress:Mt(1-r,1-r/2,1,1,e)}}return{radiusScale:1-n,verticalProgress:n}},Rt=(e,t)=>jt(e,t,Lt(e,t)),zt=e=>{let t=e.height*.36,n=e.height-t;return{coneApexY:-e.height/2,coneBaseY:-e.height/2+t,bodyHeight:n,bodyCenterY:e.height/2-n/2,bodyWidth:e.width*.54,bodyDepth:e.depth*.62}},W=(e,t,n)=>{let{width:r,height:i,depth:a}=e;switch(e.type){case`sphere`:case`mickey`:return vt(t,n,r,i,a,1,1);case`cube`:return Et(e,t,n);case`cylinder`:{let o=Ft(e,(n+Math.PI/2)/Math.PI);return[r/2*o.radiusScale*Math.sin(t),-i/2+i*o.verticalProgress,a/2*o.radiusScale*Math.cos(t)]}case`cursor`:{let r=zt(e),i=(n+Math.PI/2)/Math.PI,a=Pt({...e,width:r.bodyWidth,height:r.bodyHeight,depth:r.bodyDepth},i);return[r.bodyWidth/2*a.radiusScale*Math.sin(t),r.bodyCenterY-r.bodyHeight/2+r.bodyHeight*a.verticalProgress,r.bodyDepth/2*a.radiusScale*Math.cos(t)]}case`diamond`:return Tt(e,t,n);case`capsule`:return yt(e,t,n);case`cone`:{let o=Rt(e,(n+Math.PI/2)/Math.PI);return[r/2*o.radiusScale*Math.sin(t),i/2-i*o.verticalProgress,a/2*o.radiusScale*Math.cos(t)]}case`blob`:return U(e,B(e),t,n)}},Bt=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],G=([e,t,n])=>{let r=Math.hypot(e,t,n)||1;return[e/r,t/r,n/r]},Vt=(e,t,n)=>{let r=e.type===`cone`?-1:1;return G([r*(t[1]*n[2]-t[2]*n[1]),r*(t[2]*n[0]-t[0]*n[2]),r*(t[0]*n[1]-t[1]*n[0])])},Ht=(e,t,n)=>{let r=5e-4;if(e.type===`cone`&&n>=Math.PI/2-r)return[0,-1,0];let i=W(e,t-r,n),a=W(e,t+r,n),o=W(e,t,Math.max(-Math.PI/2,n-r)),s=W(e,t,Math.min(Math.PI/2,n+r));return Vt(e,Bt(a,i),Bt(s,o))},Ut=(e,t)=>Math.sign(e)*Math.abs(e)**t,Wt=(e,t,n)=>{let r=e.width/2||1,i=e.height/2||1,a=e.depth/2||1;return G([Ut(t[0]/r,n-1)/r,Ut(t[1]/i,n-1)/i,Ut(t[2]/a,n-1)/a])},Gt=(e,t)=>Wt(e,t,xt(e)),Kt=(e,t)=>{let n=Ct(e);if(Number.isFinite(n))return Wt(e,t,n);let r=[t[0]/(e.width/2||1),t[1]/(e.height/2||1),t[2]/(e.depth/2||1)],i=r.reduce((e,t,n)=>Math.abs(t)>Math.abs(r[e])?n:e,0);return[i===0?Math.sign(r[0]):0,i===1?Math.sign(r[1]):0,i===2?Math.sign(r[2]):0]},qt=(e,t,n,r,i)=>{let a=e.width/2||1,o=e.height/2||1,s=e.depth/2||1;if(!Number.isFinite(r)){let r=[Math.max(-a,Math.min(a,t)),Math.max(-o,Math.min(o,n)),s];return{point:r,normal:i(e,r)}}let c=Math.max(-1,Math.min(1,n/o)),l=Math.max(0,1-Math.abs(c)**r)**(1/r),u=Math.max(-a*l,Math.min(a*l,t)),d=u/a,f=Math.max(0,1-Math.abs(d)**r-Math.abs(c)**r)**(1/r),p=[u,c*o,s*f];return{point:p,normal:i(e,p)}},Jt=(e,t,n,r,i,a=0)=>{let o=t-a,s=Math.max(0,1-(e/(n||1))**2-(o/(r||1))**2),c=i*Math.sqrt(s);return{point:[e,t,c],normal:G([e/(n*n||1),o/(r*r||1),c/(i*i||1)])}},Yt=(e,t,n,r,i)=>{let a=e.width/2||1,o=e.depth/2||1,s=Math.max(0,Math.min(1,.5+i*(n/e.height))),c=It(e,s,r),l=a*c,u=o*c,d=Math.max(-l,Math.min(l,t)),f=l>0?Math.max(0,1-(d/l)**2):0,p=u*Math.sqrt(f),m=1e-4,h=Math.max(0,s-m),g=Math.min(1,s+m),_=It(e,h,r),v=(It(e,g,r)-_)/(g-h||1),y=Math.max(Math.sqrt(f),1e-4),b=-(o/a)*d/(l*y||1),x=i*o*v/(e.height*y||1);return{point:[d,n,p],normal:G([-b,-x,1])}},Xt=(e,t,n)=>{let r=e.width/2||1,i=e.height/2||1,a=e.depth/2||1;switch(e.type){case`sphere`:case`mickey`:return Jt(t,n,r,i,a);case`cube`:return qt(e,t,n,Ct(e),Kt);case`capsule`:{let e=Math.min(r,i),o=Math.max(0,i-e);return Jt(t,n,r,e,a,n<-o?-o:n>o?o:n)}case`cylinder`:return Yt(e,t,n,Ft,1);case`cursor`:{let r=zt(e),i=Yt({...e,width:r.bodyWidth,height:r.bodyHeight,depth:r.bodyDepth},t,n-r.bodyCenterY,Pt,1);return{point:[i.point[0],i.point[1]+r.bodyCenterY,i.point[2]],normal:i.normal}}case`cone`:return Yt(e,t,n,Rt,-1);case`diamond`:return qt(e,t,n,xt(e),Gt);case`blob`:return gt(e,t,n)}},Zt=(e,t,n)=>{let r=W(e,t,n);if(e.type===`sphere`||e.type===`mickey`){let t=e.width/2||1,n=e.height/2||1,i=e.depth/2||1;return{point:r,normal:G([r[0]/(t*t),r[1]/(n*n),r[2]/(i*i)])}}return e.type===`cylinder`&&e.roundness<=0&&(e.morphRoundness??0)<=0?{point:r,normal:G([Math.sin(t)/(e.width/2||1),0,Math.cos(t)/(e.depth/2||1)])}:e.type===`diamond`?{point:r,normal:Gt(e,r)}:e.type===`cube`?{point:r,normal:Kt(e,r)}:e.type===`blob`?ht(e,t,n):{point:r,normal:Ht(e,t,n)}},Qt=new WeakMap,$t=e=>{let t=Qt.get(e);if(t===void 0){let n=e.length,r=t=>{let r=(t%n+n)%n*(Math.PI*2/n),i=e[(t%n+n)%n];return[Math.cos(r)*i,Math.sin(r)*i]};t=e.every((e,t)=>{let[n,i]=r(t-1),[a,o]=r(t),[s,c]=r(t+1);return(a-n)*(c-o)-(o-i)*(s-a)>=-1e-9}),Qt.set(e,t)}return t},en=e=>{if(e.type===`mickey`){let t=Math.min(e.width,e.height)*.23,n=Math.min(t,e.depth*.29);return[-1,1].map(r=>({id:`ear-${r}`,name:``,surface:{type:`sphere`,width:t*2,height:t*2,depth:n*2,roundness:1},position:[r*e.width*.37,-e.height*.39,-e.depth*.12],rotation:[0,0,0]}))}if(e.type===`cursor`){let t=zt(e),n=t.coneBaseY-t.coneApexY;return[{id:`cursor-tip`,name:``,surface:{type:`cone`,width:e.width,height:n,depth:e.depth,roundness:0,morphRoundness:0,tipRoundness:0,baseRoundness:0},position:[0,(t.coneApexY+t.coneBaseY)/2,0],rotation:[0,0,0]}]}return[]},tn=(e,t)=>{if(z(e))return!1;let n=t.filter(e=>!e.paintOn&&e.color!==`eyes`&&e.color!==`mark`);return n.some(e=>e.color===`accent`)&&n.some(e=>e.color===`secondary`||e.color===`tertiary`)&&n.every(e=>!e.rooted&&!e.fixed&&(e.color===`accent`||e.color===`secondary`||e.color===`tertiary`))},nn=e=>e.type===`blob`?w(e):void 0,rn=e=>{let t=[...en(e.body.primary),...e.body.nodes],n=[e.body.primary,...t.map(e=>e.surface)],r=n.some(e=>nn(e)?.lobes),i=n.some(e=>nn(e)?.sockets),a=t.some(e=>e.paintOn),o=[];return r&&o.push(`sculpt`),i&&o.push(`sockets`),a&&o.push(`paint`),(r||t.length)&&o.push(`depth`),o},an=(e,...t)=>!!e.geometry?.radialDepthPower&&S(`radial`)(e,...t),on=e=>{let t=0;for(let n=0;n<e.length;n+=1)t+=e[n];return t>e.length*.25},sn=(e,t,n)=>{for(let r=0;r<e;r+=1){if(t[r]>0){n(r,r,r,0);continue}let i=1;for(;i<e&&t[(r-i+e)%e]<=0;)i+=1;let a=1;for(;a<e&&t[(r+a)%e]<=0;)a+=1;if(i>=e)return;n(r,(r-i+e)%e,(r+a)%e,i/(i+a))}},cn=e=>{let t=10**e;return e=>Math.round(e*t)/t},ln=Array.from({length:2048},(e,t)=>String(t)),un=new Map,dn=e=>{let t=un.get(e);if(!t){let n=10**e;t=Array.from({length:n},(t,n)=>n?`.${String(n).padStart(e,`0`).replace(/0+$/,``)}`:``),un.set(e,t)}return t},fn=e=>{if(!Number.isInteger(e)||e<0||e>4){let t=cn(e);return e=>`${t(e)}`}let t=10**e,n=dn(e);return e=>{let r=Math.round(e*t),i=r<0?-r:r;if(!(i<1e9))return`${r/t}`;let a=i/t|0,o=(a<2048?ln[a]:String(a))+n[i-a*t];return r<0?`-${o}`:o}},K=e=>(e.charCodeAt(0),e),pn=new Map,mn=e=>{let t=pn.get(e);return t||pn.set(e,t=fn(e)),t},hn=Math.cos(75*Math.PI/180),gn=class{xs;ys;handleXs;handleYs;constructor(e){this.xs=new Float64Array(e),this.ys=new Float64Array(e),this.handleXs=new Float64Array(e),this.handleYs=new Float64Array(e)}reserve(e){if(e<=this.xs.length)return;let t=new Float64Array(e),n=new Float64Array(e);t.set(this.xs),n.set(this.ys),this.xs=t,this.ys=n,this.handleXs=new Float64Array(e),this.handleYs=new Float64Array(e)}set(e,t,n){e>=this.xs.length&&this.reserve(e+1),this.xs[e]=t,this.ys[e]=n}point(e){return[this.xs[e],this.ys[e]]}closeHorizon(e,t){sn(e,t,(e,t,n,r)=>{this.xs[e]=this.xs[t]+(this.xs[n]-this.xs[t])*r,this.ys[e]=this.ys[t]+(this.ys[n]-this.ys[t])*r})}closed(e,{precision:t,curve:n},r=1){let i=cn(t),a=mn(t);if(n===`spline`&&r===1){let n=mn(t+1);for(let t=0;t<e;t+=1)this.xs[t]=i(this.xs[t]),this.ys[t]=i(this.ys[t]);let r=t=>n((this.xs[t]+this.xs[(t+1)%e])/2),o=t=>n((this.ys[t]+this.ys[(t+1)%e])/2),s=`M${r(e-1)} ${o(e-1)}Q${a(this.xs[0])} ${a(this.ys[0])} ${r(0)} ${o(0)}`;for(let t=1;t<e;t+=1)s+=`T${r(t)} ${o(t)}`;return K(`${s}Z`)}let o=r===1?1/6:r/6;for(let t=0;t<e;t+=1){let n=(t-1+e)%e,r=(t+1)%e,i=this.xs[t]-this.xs[n],a=this.ys[t]-this.ys[n],s=this.xs[r]-this.xs[t],c=this.ys[r]-this.ys[t],l=Math.hypot(i,a),u=Math.hypot(s,c),d=(this.xs[r]-this.xs[n])*o,f=(this.ys[r]-this.ys[n])*o;i*s+a*c<hn*l*u&&(d=f=0);let p=Math.min(l,u)/2,m=Math.hypot(d,f);m>p&&(d*=p/m,f*=p/m),this.handleXs[t]=d,this.handleYs[t]=f}let s=`M${a(this.xs[0])} ${a(this.ys[0])}`;for(let t=0;t<e;t+=1){let n=(t+1)%e;s+=`C${a(this.xs[t]+this.handleXs[t])} ${a(this.ys[t]+this.handleYs[t])} ${a(this.xs[n]-this.handleXs[n])} ${a(this.ys[n]-this.handleYs[n])} ${a(this.xs[n])} ${a(this.ys[n])}`}return K(`${s}Z`)}},_n=(e,t)=>{let n=620-e*t;return Math.abs(n)<1e-4?62e5:620/n},vn=(e,t)=>{let n=Math.min(Math.abs(e*t),619);return 620/Math.sqrt(384400-n*n)},yn=Math.PI*2,q=yn/192,bn=Float64Array.from({length:192},(e,t)=>Math.cos(t*q)),xn=Float64Array.from({length:192},(e,t)=>Math.sin(t*q)),J=new gn(192),Y=new Float64Array(3),X=(e,t,n,r,i)=>{let{m:a,t:o}=e,s=a[0]*n+a[1]*r+a[2]*i+o[0],c=a[3]*n+a[4]*r+a[5]*i+o[1],l=a[6]*n+a[7]*r+a[8]*i+o[2],u=_n(l,t);return Y[0]=s*u,Y[1]=c*u,Y[2]=l,Y},Sn=new Map,Z=(e,t,n)=>{e.set(K(t),typeof n==`string`?K(n):n),e.size>64&&e.delete(e.keys().next().value)},Q=(e,t)=>{let n=e.get(t);return n!==void 0&&(e.delete(t),e.set(t,n)),n},Cn={precision:2,step:1,curve:`catmull`},wn=(e,t)=>t===1||e.step===1?e:{...e,step:1},Tn=e=>1-(1-e)**5,En=4753,Dn=()=>({positions:new Float32Array(En*3),normals:new Float32Array(En*3)}),On=e=>-Math.PI/2+(Math.min(Math.max(e,1),47)-1)/46*Math.PI,kn=e=>-Math.PI+e/96*Math.PI*2,An=e=>{let t=t=>{let n=0;for(let r=0;r<97;r+=1)n+=e.positions[(t*97+r)*3+1];return n/97};if(t(1)<=t(47))return e;for(let t=1;t<24;t+=1){let n=48-t;for(let r of[e.positions,e.normals]){let e=r.slice(t*291,(t+1)*291);r.copyWithin(t*291,n*291,(n+1)*291),r.set(e,n*291)}}return e},jn=e=>([[0,1,-1],[48,47,1]].forEach(([t,n,r])=>{let i=0,a=0,o=0;for(let t=0;t<96;t+=1){let r=(n*97+t)*3;i+=e.positions[r],a+=e.positions[r+1],o+=e.positions[r+2]}for(let n=0;n<97;n+=1){let s=(t*97+n)*3;e.positions[s]=i/96,e.positions[s+1]=a/96,e.positions[s+2]=o/96,e.normals[s]=0,e.normals[s+1]=r,e.normals[s+2]=0}}),e),Mn=e=>jn(An(e)),Nn=(e,t=Dn())=>{let n=0;for(let r=0;r<=48;r+=1){let i=On(r);for(let r=0;r<=96;r+=1){let{point:a,normal:o}=Zt(e,kn(r),i),s=!(e.type===`blob`&&w(e).sockets)&&o[0]*a[0]+o[1]*a[1]+o[2]*a[2]<0?-1:1,c=(Math.hypot(o[0],o[1],o[2])||1)*s;t.positions.set(a,n),t.normals[n]=o[0]/c,t.normals[n+1]=o[1]/c,t.normals[n+2]=o[2]/c,n+=3}}return Mn(t)},Pn=24,$=new Map,Fn=e=>{let t=Ue(e),n=$.get(t);if(n)return $.delete(t),$.set(t,n),n;let r=Nn(e);return $.set(t,r),$.size>Pn&&$.delete($.keys().next().value),r},In=(e,t,n)=>{let[r,i,a,o,s,c]=t,l=1-n*e[2],u=l*l-n*n*c;if(l<=0||u<=1e-10)return;let d=(e[0]*l+n*a)/u,f=(e[1]*l+n*s)/u,p=(r-e[0]**2)/u+d*d,m=(i-e[0]*e[1])/u+d*f,h=(o-e[1]**2)/u+f*f;if(!(p>0))return;let g=Math.sqrt(p),_=m/g,v=h-_*_;if(!(v>0))return;let y=Math.sqrt(v);return[d,f,g,_,y].every(Number.isFinite)?{x:d,y:f,ux:g,uy:_,vy:y}:void 0},Ln=(e,t,n,r,i)=>{if(e.type!==`sphere`&&e.type!==`mickey`)return!1;let{m:a,t:o}=t,s=e.width/2,c=e.height/2,l=e.depth/2,u=(e,t)=>a[e*3]*a[t*3]*s*s+a[e*3+1]*a[t*3+1]*c*c+a[e*3+2]*a[t*3+2]*l*l,d=In(o,[u(0,0),u(0,1),u(0,2),u(1,1),u(1,2),u(2,2)],n/620);if(!d)return!1;let{x:f,y:p,ux:m,uy:h,vy:g}=d,_=(r[0]-f)/m,v=(r[1]-p-h*_)/g,y=_*_+v*v-1;if(!(y<0))return!1;let b=Math.PI*2/i.length;for(let e=0;e<i.length;e+=1){let t=Math.cos(e*b)/m,n=(Math.sin(e*b)-h*t)/g,r=t*t+n*n,a=_*t+v*n;i[e]=(-a+Math.sqrt(a*a-r*y))/r}return!0},Rn=(e,t,n)=>{let r=Math.min(e,t),i=Math.max(e,t)-r,a=Math.PI*r,o=(e,t,n)=>[e+r*Math.cos(n),t+r*Math.sin(n)],s=(n-Math.floor(n))*(4*i+2*a);return t>e?s<i?[r,s]:(s-=i,s<a?o(0,i,s/r):(s-=a,s<2*i?[-r,i-s]:(s-=2*i,s<a?o(0,-i,Math.PI+s/r):(s-=a,[r,-i+s])))):s<a/2?o(i,0,s/r):(s-=a/2,s<2*i?[i-s,r]:(s-=2*i,s<a?o(-i,0,Math.PI/2+s/r):(s-=a,s<2*i?[-i+s,-r]:(s-=2*i,o(i,0,Math.PI*3/2+s/r)))))},zn=new Map,Bn=720,Vn=e=>{let t=Math.round(Math.log(Math.max(.001,e))*200),n=zn.get(t);if(n)return n;let r=Math.exp(t/200),i=new Float64Array(721);for(let e=1;e<=Bn;e+=1){let t=(e-.5)/Bn*2*Math.PI;i[e]=i[e-1]+Math.hypot(Math.sin(t),r*Math.cos(t))}n=new Float64Array(73);let a=0;for(let e=0;e<=72;e+=1){let t=e/72*i[Bn];for(;a<719&&i[a+1]<t;)a+=1;let r=i[a+1]-i[a]||1;n[e]=(a+(t-i[a])/r)/Bn*2*Math.PI}return zn.size>512&&zn.clear(),zn.set(t,n),n},Hn=(e,t,n)=>{let r=Vn(t/Math.max(e,1e-6)),i=(n-Math.floor(n))*72,a=Math.floor(i),o=r[a]+(r[a+1]-r[a])*(i-a);return[e*Math.cos(o),t*Math.sin(o)]},Un=(e,t,n)=>{let r=t/120,i=n/120;return e(120*Math.cos(i)*Math.sin(r),120*Math.sin(i))},Wn=(e,t,n)=>{let r=t<0?`Left`:`Right`,a=(e[`lid${r}`]??0)*n,o=(e[`lidTilt${r}`]??0)*n,s=(e[`lowerLid${r}`]??0)*n;return!a&&!o&&!s?{}:{lid:a,lidSlope:-t*Math.tan(i(Math.max(-80,Math.min(80,o)))),lowerLid:s}},Gn=e=>!!(e.lid||e.lidSlope||e.lowerLid),Kn=(e,t)=>{let n=e.height/2,r=-n+(e.lid??0)*e.height+(e.lidSlope??0)*t,i=n-(e.lowerLid??0)*e.height;return r<i?[r,i]:[(r+i)/2,(r+i)/2]},qn=e=>{if(!Gn(e))return[0,0];let[t,n]=Kn(e,0);return[0,(Math.max(t,-e.height/2)+Math.min(n,e.height/2))/2]},Jn=(e,t)=>{let n=t/72,r=Rn(e.width/2,e.height/2,n),i=e.ellipse??0,a=i>0?Hn(e.width/2,e.height/2,n):r,o=i>=1?a[0]:r[0]+(a[0]-r[0])*i,s=i>=1?a[1]:r[1]+(a[1]-r[1])*i;if(!Gn(e))return[o,s];let[c,l]=Kn(e,o);return[o,Math.min(Math.max(s,c),l)]},Yn=(e,t,n)=>{if(!e.bend||e.width<=0)return[t,n];let r=Math.min(e.width,e.height)/2,i=Math.max(0,e.width/2-r),a=Math.max(-i,Math.min(i,t)),o=-8*e.bend*a/e.width,s=Math.hypot(1,o),c=e.bend*e.width*(1-(2*a/e.width)**2);return[a+(t-a-o*n)/s,c+(o*(t-a)+n)/s]},Xn=(e,t,n)=>{let[r,i]=Jn(e,t),[a,o]=qn(e),[s,c]=Yn(e,a+(r-a)*n,o+(i-o)*n);return[e.centerX+s*e.cos-c*e.sin,e.centerY+s*e.sin+c*e.cos]},Zn=.01,Qn=e=>e.width>.5&&e.height>.5,$n=(e,t,n,r=0,o)=>{let s=m(e),c=s?d(a(e),s,r,o):a(e),l=e.marks?e.glyphWeight??1:0,f=e.eyeShape===`ellipse`?1-l+(l>0?l*u(a(e)):0):0,p=e.glyphHandover,h=p!==void 0&&p<.5?(p*2)**2:0,g=p!==void 0&&p>=.5?1-(2-p*2)**2:1;return c.map((r,a)=>{let o=i(r.angle),s=(r.height>5?5+(r.height-5)*t:r.height)*(1-h)*g;return{width:Math.max(r.width*g,Zn),height:Math.max(s,Zn),centerX:r.x+n.x,centerY:r.y+n.y,cos:Math.cos(o),sin:Math.sin(o),ellipse:a<2?f:0,...r.bend===void 0?{}:{bend:r.bend},...a<2?Wn(e,a===0?-1:1,1-l):{}}})},er=16,tr=new WeakMap,nr=(e,t)=>{let n=tr.get(e);n||tr.set(e,n=new Map);let r=n.get(t);return r?n.delete(t):(r=t.map(([t,n])=>e(t,n)),n.size>=er&&n.delete(n.keys().next().value)),n.set(t,r),r},rr=22,ir=2**rr,ar=4,or=1e-12,sr=(e,t,n,r,i,a)=>{let o=e.length,s=e=>{let t=r(e),{point:n,normal:o}=t,s=o[2]-i/620*(o[0]*n[0]+o[1]*n[1]),c=a?Math.min(s,a(n)):s;return{...t,facing:c}},c=(e,t)=>s(n(e,t)),l=nr(n,e).map(s),u=t,d=c(...t),f=Math.max(1e-6,Math.max(...l.map(e=>e.facing))*.1);if(d.facing<=f){let t=e.filter((e,t)=>l[t].facing>f);if(t.length&&(u=[t.reduce((e,t)=>e+t[0],0)/t.length,t.reduce((e,t)=>e+t[1],0)/t.length],d=c(...u),d.facing<=f)){let t=0;for(let e=1;e<o;e++)l[e].facing>l[t].facing&&(t=e);u=e[t],d=l[t]}}if(d.facing<=0)return{points:l.map(()=>d.point),visible:!1};let p=ke(n)||ke(a),m=l.map((t,n)=>{if(t.facing>0)return t.point;let r=e[n],i=e=>c(u[0]+(r[0]-u[0])*e,u[1]+(r[1]-u[1])*e),a=p||Math.abs(t.facing)<or||Math.abs(d.facing)<or;if(!a){let e=e=>{let t=i(e/ir);return Math.abs(t.facing)<or&&(a=!0),t},n=0,r=ir,o=d.facing,s=t.facing,c=d;for(let t=0;t<ar&&!a;t++){let t=(n+r)/2,i=e(t);i.facing>0?(n=t,c=i,o=i.facing):(r=t,s=i.facing)}let l=n,u=o,f=r,p=s,m=NaN,h=0;for(;r-n>1&&!a;){let t=l+(f-l)*u/(u-p);t>n&&t<r||(t=n+(r-n)*o/(o-s));let i=Math.floor(t);i>n||(i=n+1),i<r||(i=r-1),i>n&&i<r||(i=Math.floor((n+r)/2));let a=Math.abs(t-m)<4;m=t;let d=e(i);if(l=f,u=p,f=i,p=d.facing,d.facing>0){if(n=i,c=d,o=d.facing,h>0&&(s*=.5),h=1,a&&r-n>1){let t=e(n+1);t.facing>0?(n+=1,c=t,o=t.facing):(r=n+1,s=t.facing)}}else if(r=i,s=d.facing,h<0&&(o*=.5),h=-1,a&&r-n>1){let t=e(r-1);t.facing>0?(n=r-1,c=t,o=t.facing):(--r,s=t.facing)}}if(!a)return c.point}let o=0,s=1,l=d;for(let e=0;e<rr;e++){let e=(o+s)/2,t=i(e);t.facing>0?(o=e,l=t):s=e}return l.point}),h=0;return m.forEach((e,t)=>{let n=m[(t+1)%o];h+=e[0]*n[1]-n[0]*e[1]}),{points:m,visible:Math.abs(h)>1e-6}},cr=new Map,lr=new WeakMap,ur=e=>{let t=lr.get(e);return t||(t=(t,n)=>Un(e,t,n),ke(e)&&Oe(t),lr.set(e,t)),t},dr=(e,t,n,r,i=1,a,o=!1)=>{let s=Math.floor(72/i),c=[e.centerX,e.centerY,e.width,e.height,e.cos,e.sin,e.ellipse??0,e.lid??0,e.lidSlope??0,e.lowerLid??0,e.bend??0,i].join(`|`),l=cr.get(c);l||(l=Array.from({length:s},(t,n)=>Xn(e,n*i,1)),cr.size>=128&&cr.delete(cr.keys().next().value),cr.set(c,l));let u=sr(l,Xn(e,0,0),o?t:ur(t),n,r,a);return{...u,visible:Qn(e)&&u.visible}},fr=new Float32Array(192),pr=(e,t=1)=>{for(let t=0;t<192;t+=1){if(e[t]>0)continue;let n=1,r=1;for(;e[(t-n+192)%192]===0&&n<192;)n+=1;for(;e[(t+r)%192]===0&&r<192;)r+=1;let i=e[(t-n+192)%192],a=e[(t+r)%192];e[t]=i+(a-i)*n/(n+r)}if(t===0)return e;fr.set(e);for(let n=0;n<192;n+=1){let r=e=>fr[(n+e+192)%192],i=(r(-2)+4*r(-1)+6*r(0)+4*r(1)+r(2))/16;e[n]=t===1?i:r(0)+(i-r(0))*t}return e},mr=(e,...t)=>!!e.geometry?.hull&&S(`grid`).sculptProfile(e,...t),hr=(...e)=>S(`grid`).convexProfile(...e),gr=(...e)=>S(`grid`).starProfile(...e),_r=e=>{let t=e.squash;return t?{scaleX:t.x,scaleY:t.y,x:e.offset.x,y:e.offset.y+(1-t.y)*t.base}:{scaleX:1,scaleY:1,x:e.offset.x,y:e.offset.y}},vr=e=>Math.round(e*1e3)/1e3,yr=e=>{let{scaleX:t,scaleY:n,x:r,y:i}=_r(e);return e.squash?`matrix(${vr(t)} 0 0 ${vr(n)} ${vr(r)} ${vr(i)})`:`translate(${r} ${i})`},br=new Map,xr=new Map,Sr=new Map,Cr=new Map,wr=(e,t)=>`${e.map(e=>Math.round(e*1e5)).join(`,`)}|${t}`,Tr=(e,t)=>Math.max(...e)+Math.hypot(t[0],t[1]),Er=(e,t,n,r,i,a,o=1)=>{i=wn(i,o);let s=0,c=Math.floor(e.length/i.step);J.reserve(c);let l=t=>{let o=new Float64Array(c*2);for(let l=0;l<c;l+=1){let[c,u]=e[l*i.step];X(n,r,c,u,a?t-a(c,u):t),o[l*2]=Y[0],o[l*2+1]=Y[1],s=Math.max(s,Math.hypot(Y[0],Y[1]))}return o},u=l(t),d=l(-t),f=e=>{let t=0;for(let n=0;n<e.length/2;n+=1){let r=(n+1)%(e.length/2);t+=e[n*2]*e[r*2+1]-e[r*2]*e[n*2+1]}return t},p=e=>{let t=f(e)<0;for(let n=0;n<c;n+=1){let r=t?c-1-n:n;J.set(n,e[r*2],e[r*2+1])}return J.closed(c,i,o)};if(i.curve===`spline`&&o===1){let e=f(u)<0?-1:1;for(let t=0;t<c;t+=1){let n=(t-1+c)%c*2,r=(t+1)%c*2,i=e*(u[r+1]-u[n+1]),a=e*(u[n]-u[r]),o=i*(d[t*2]-u[t*2])+a*(d[t*2+1]-u[t*2+1])>0?d:u;J.set(t,o[t*2],o[t*2+1])}return{path:J.closed(c,i,o),reach:s}}let m=cn(i.precision),h=``,g=new Float64Array(8);for(let e=0;e<c;e+=1){let t=(e+1)%c;g.set([u[e*2],u[e*2+1],u[t*2],u[t*2+1],d[t*2],d[t*2+1],d[e*2],d[e*2+1]]);let n=f(g)<0?[3,2,1,0]:[0,1,2,3];h+=n.map((e,t)=>`${t?`L`:`M`}${m(g[e*2])} ${m(g[e*2+1])}`).join(``),h+=`Z`}return{path:`${p(u)}${p(d)}${h}`,reach:s}},Dr=(e,t,n,r=1)=>{n=wn(n,r);let i=Math.floor(192/n.step);for(let r=0;r<i;r+=1){let i=r*n.step;J.set(r,t[0]+Math.cos(i*q)*e[i],t[1]+Math.sin(i*q)*e[i])}return J.closed(i,n,r)},Or=class{bodyKey=``;bodySamples=null;current=new Float32Array(192);from=new Float32Array(192);shown=new Float32Array(192);head={m:new Float64Array(9),t:[0,0,0]};morphStartedAt=-1;pieceLayer;detail;reducedMotion=!1;constructor(e={}){this.detail={...Cn,...e}}setDetail(e){this.detail={...Cn,...e}}project(e,r,i=`frame`){let o=i!==`pieces`,{orientation:s,expression:c}=e.pose,l=c.perspective;n(s,this.head.m),this.head.t=t(this.head.m,e.surface.rotationCenter);let d=X(this.head,l,0,0,0),f=[d[0],d[1]],p=e.surface.outlineRounding??1,m=wn(this.detail,p),g=We(e.surface);g!==this.bodyKey&&(this.bodySamples=null,this.bodyKey&&this.from.set(this.shown),this.morphStartedAt=this.bodyKey&&!this.reducedMotion?r:-1,this.bodyKey=g);let _=wr(s,l),v=`${g}|${_}`,y=o?Q(br,v):void 0;y?this.current.set(y):o&&(an(e.surface,this.head,l,f,this.current)?pr(this.current,0):mr(e.surface,this.head,l,f,this.current)||(e.surface.type!==`blob`||!w(e.surface).lobes&&$t(B(e.surface))?Ln(e.surface,this.head,l,f,this.current)?pr(this.current,p):hr(this.bodySamples??=Fn(e.surface),1,this.head,l,f,this.current,p):gr(this.bodySamples??=Fn(e.surface),this.head,l,f,this.current,p)),Z(br,v,Float32Array.from(this.current)));let b=this.morphStartedAt<0?1:Math.min(1,(r-this.morphStartedAt)/450),x=Tn(b);for(let e=0;o&&e<192;e+=1)this.shown[e]=b>=1?this.current[e]:this.from[e]+(this.current[e]-this.from[e])*x;b>=1&&(this.morphStartedAt=-1);let ee=je(e.surface),C=ee&&o?Er(ee,e.surface.depth/2,this.head,l,{...this.detail,step:1},Ne(e.surface),p):void 0,T=C?C.reach:o?Tr(this.shown,f):0,ne=`${this.detail.precision},${this.detail.step},${this.detail.curve}${this.detail.compoundOutline===!1?`,sampled`:``}`,E,D=()=>E??=S(`depth`).createProjectedDepthField(e.surface,this.head,l),O=[...en(e.surface),...e.bodyNodes],k=O.length?(this.pieceLayer??=S(`pieces`).createPieceLayer({plateFaces:Er,profileReach:Tr,profilePath:Dr,finishProfile:pr,convexProfile:hr,starProfile:gr,sculptProfile:mr})).project({input:e,head:this.head,detail:this.detail,perspective:l,parts:O,key:g,pose:_,detailKey:ne,headDepth:D,bodyDetail:m,rounding:p,bodyOutline:v}):void 0,A=k?.placed??[];T=Math.max(T,k?.reach??0);let re=Le(e.surface),j=z(e.surface),ie=j?Re(e.surface):0,M=e.surface.type===`blob`?w(e.surface).sockets:void 0,ae=M?re:qe(e.surface),oe=M?qe(e.surface,M.plane*e.surface.width):void 0,se=Je(e.surface).sample,{m:N}=this.head,ce=Ae(e.surface),le=e.surface.type===`blob`?w(e.surface).lobes:void 0,ue=M?it(e.surface)??Math.max(e.surface.depth,M.plane*e.surface.width):void 0,de=le&&!ae?S(`sculpt`).lobeVisibility(le,this.head,l,e.surface,D):void 0,fe=i===`frame`?$n(c,e.blink,{x:e.eyeOffset.x+ce.x,y:e.eyeOffset.y+ce.y},e.time,e.loop).map((t,n)=>{let r=M&&n<2&&(!c.marks||c.glyphHandover!==void 0&&h(c.glyphHandover)||u(a(c))>0),i=M&&r?S(`sockets`).filledSocketLayout(t,M,e.surface.width,n):void 0,o=M&&r?S(`sockets`).createSocketVisibility(M,e.surface.width,ue,this.head,l,(t,n)=>at(e.surface,t,n),n):void 0,s=dr(i??t,r&&oe?oe:se,({point:e,normal:t})=>(X(this.head,l,e[0],e[1],e[2]),{point:[Y[0],Y[1],Y[2]],normal:[N[0]*t[0]+N[1]*t[1]+N[2]*t[2],N[3]*t[0]+N[4]*t[1]+N[5]*t[2],N[6]*t[0]+N[7]*t[1]+N[8]*t[2]]}),l,this.detail.step,M?o:de,ae!==void 0);return s.points.forEach((e,t)=>{J.set(t,e[0],e[1])}),{path:J.closed(s.points.length,this.detail),visible:s.visible}}):[],P,F=`${v}|${ne}`,pe=i===`frame`||i===`pieces`&&N[8]>0&&A.some(e=>e.behind),me=j&&pe?Q(Cr,F):void 0;if(me!==void 0)P=me??void 0;else if(pe){if(j&&ie===0){let e=m.step===1?j:j.filter((e,t)=>t%m.step===0),t=sr(e,[e.reduce((e,t)=>e+t[0],0)/e.length,e.reduce((e,t)=>e+t[1],0)/e.length],re,({point:e,normal:t})=>(X(this.head,l,e[0],e[1],e[2]),{point:[Y[0],Y[1],Y[2]],normal:[N[0]*t[0]+N[1]*t[1]+N[2]*t[2],N[3]*t[0]+N[4]*t[1]+N[5]*t[2],N[6]*t[0]+N[7]*t[1]+N[8]*t[2]]}),l);if(t.visible){J.reserve(t.points.length),t.points.forEach((e,t)=>{J.set(t,e[0],e[1])});let e=J.closed(t.points.length,m,p);P={opening:e,plate:e}}Z(Cr,F,P??null)}else if(j){let e=Math.floor(j.length/m.step);J.reserve(e);let t=new Float64Array(e),n=new Float64Array(e),r=new Float64Array(e),i=(i,a)=>{for(let a=0;a<e;a+=1){let[e,o]=j[a*m.step],{point:s,normal:c}=i(e,o);X(this.head,l,s[0],s[1],s[2]),t[a]=Y[0],n[a]=Y[1],r[a]=N[6]*c[0]+N[7]*c[1]+N[8]*c[2]}for(let r=0;r<e;r+=1)J.set(r,t[r],n[r]);return a&&J.closeHorizon(e,r),{path:J.closed(e,m,p),visible:on(r)}},a=i(re,!0);a.visible&&(P={opening:a.path,plate:i(se,!1).path}),Z(Cr,F,P??null)}}let he=e.bodySquash.x!==1||e.bodySquash.y!==1,I;if(!o)I=``;else if(C)I=C.path;else if(b<1)I=Dr(this.shown,f,m,p);else{let t=`${v}|${ne}`,n=Q(xr,t);if(n!==void 0)I=n,T=Math.max(T,Q(Sr,t)??0);else{let n=this.detail.compoundOutline===!1?void 0:te(`union`)?.ellipsoidUnionOutline(e.surface,this.head,l,this.detail.precision);I=n?.path??Dr(this.shown,f,m,p),n&&(T=Math.max(T,n.reach),Z(Sr,t,n.reach)),Z(xr,t,I)}}o&&k?.pigment&&(I=k.pigment());let ge=A.map(e=>P&&N[8]>0&&e.behind?{...e.piece,front:!1}:e.piece);return{frame:{body:I,pieces:ge,eyes:j&&!P?fe.map(e=>({...e,visible:!1})):fe,...P?{face:P}:{},offset:e.bodyOffset,...he?{squash:{...e.bodySquash,base:e.surface.height/2}}:{},reach:(he?T*Math.max(e.bodySquash.x,e.bodySquash.y)+Math.abs(1-e.bodySquash.y)*(e.surface.height/2):T)+Math.hypot(e.bodyOffset.x,e.bodyOffset.y)},morphing:this.morphStartedAt>=0}}},kr={x:0,y:0},Ar=.45,jr=.3,Mr=.25,Nr=(e,t,n,r)=>{let i=c(e,t,n),a=r?.(t);return{x:(i?.x??0)+(a?.x??0),z:(i?.z??0)+(a?.z??0),offsetY:i?.offsetY??0,flap:i?.flap??0}},Pr=(e,t,n)=>e>=0?n*Math.tanh(e/n):-t*Math.tanh(e/-t),Fr=({range:e=[-90,90]},t)=>Pr(t,e[0],e[1]),Ir=(e,t,n,r,i)=>{let{lag:a,swing:o=0,range:s=[-90,90]}=e,[c,l]=s,u=r(i),d=r(i-a),f=r(i-2*a),p=e=>e(d)-e(u)+Mr*(e(d)-e(f));return Pr(n+(u.flap+t*Ar*p(e=>e.z)+jr*p(e=>e.x)-o*p(e=>e.offsetY)),c,l)},Lr=(e,t,n,r,i)=>{let a=e.filter(e=>e.follow);if(!a.length)return;let o=c(t,n??0,r),s={};for(let e of a){let a=e.follow,l=e.position[0]<0?1:-1;if(a.hinge){let c=t.pieces?.[e.id]?.turn??0,u=l*c,d=l*(n===void 0||!o&&!i?Fr(a,u+(o?.flap??0)):Ir(a,l,u,e=>Nr(t,e,r,i),n))-c;d!==0&&(s[e.id]={turn:d});continue}if(!o||n===void 0)continue;let{lag:u,swing:d=0,loose:f=!1}=a,p=c(t,n-u,r),m=c(t,n-2*u,r),h=e=>e(p)-e(o)+.25*(e(p)-e(m));s[e.id]={turn:h(e=>e.z)-d*l*h(e=>e.offsetY),...f?{x:h(e=>e.offsetX),y:h(e=>e.offsetY)}:{}}}return Object.keys(s).length?s:void 0},Rr=(e,t)=>{if(!t)return e;let n={...e};for(let[e,r]of Object.entries(t)){let t=n[e]??{};n[e]={...t,turn:(t.turn??0)+(r.turn??0),x:(t.x??0)+(r.x??0),y:(t.y??0)+(r.y??0)}}return n},zr=e=>{let t=e.time??0,n=e.bodyOffset??kr,{pose:i,offset:a,squash:s}=r(e.pose,t,e.loop),c=e.bodySquash??l;return{pose:i,surface:e.surface,bodyNodes:o(e.bodyNodes,Rr(e.pose.expression.pieces,Lr(e.bodyNodes,e.pose.expression,e.time,e.loop,e.headAt))),blink:e.blink??1,eyeOffset:e.eyeOffset??kr,bodyOffset:{x:n.x+a.x,y:n.y+a.y},bodySquash:s===l?c:{x:c.x*s.x,y:c.y*s.y},time:t,...e.loop===void 0?{}:{loop:e.loop}}};function Br(e){let t=new Or,n=!!z(e.body.primary),r=0,i,a=!e.body.nodes.some(e=>e.follow);return(o,c=192,l=!1)=>{let u=c>=192?0:c>=96?1:2;u!==r&&(i=void 0,r=u,t.setDetail({precision:r===0?2:1,step:r===2?2:1}));let{expression:d,eyeOffset:f,bodyOffset:m,blink:h,time:g,half:v}=o,y=i;return l&&a&&y?(y.reach+=Math.hypot(m.x,m.y)-Math.hypot(y.offset.x,y.offset.y),y.offset={...m}):(y=t.project(zr({surface:e.body.primary,bodyNodes:e.body.nodes,pose:_(s(d,e.eyes)),eyeOffset:f,bodyOffset:m,blink:h,time:g}),g).frame,i=y),{frame:y,colors:p(d,e.colors),transform:yr(y),half:v,windowed:n}}}var Vr=e({activateGeometry:()=>Gr,prepareGeometry:()=>Jr}),Hr={sculpt:()=>import(`./sculpt-DWr8rXDB.js`).then(e=>e.sculpt),sockets:()=>import(`./sockets-CM-eyf8W.js`).then(e=>e.sockets),paint:()=>import(`./paint-CxkSCDga.js`).then(e=>e.paint),depth:()=>import(`./depth-C0ucFmd8.js`).then(e=>e.depth)},Ur=new Map;function Wr(e){let t=Ur.get(e);if(t)return t;let n=Hr[e]().catch(t=>{throw Ur.delete(e),t});return Ur.set(e,n),n}async function Gr(e,t){let n=rn(e);(e.body.primary.geometry?.radialDepthPower||e.body.primary.geometry?.relief||e.body.nodes.some(e=>e.surface.geometry?.relief))&&!n.includes(`sculpt`)&&n.push(`sculpt`);let r=Object.freeze(Object.assign({},...await Promise.all([...n.map(Wr),t?import(`./sampledProfiles-BvP-O0oY.js`).then(e=>({grid:e})):void 0]))),i=0;return Object.freeze({capabilities:Object.freeze(n),createProjector(){let t=Br(e);i++;let n=!1;return Object.assign((...e)=>{if(n)throw Error(`Projector disposed.`);return ee(r,()=>t(...e))},{dispose(){if(!n&&(n=!0,--i===0)){r.sculpt?.releaseRelief(e.body.primary);for(let t of e.body.nodes)r.sculpt?.releaseRelief(t.surface)}}})}})}var Kr=new WeakMap,qr=new WeakMap;function Jr(e,t=!1){let n=f(e,t),r=n?Kr:qr,i=r.get(e);if(i)return i;let a=Gr(g(e),n).catch(t=>{throw r.delete(e),t});return r.set(e,a),a}export{Xt as A,$t as C,je as D,B as E,I as F,T as I,w as L,Ue as M,Oe as N,Ne as O,Ee as P,S as R,cn as S,Ze as T,Q as _,In as a,vn as b,Fn as c,Sn as d,wn as f,xn as g,bn as h,sr as i,We as j,Fe as k,q as l,X as m,Jr as n,Ln as o,J as p,pr as r,En as s,Vr as t,yn as u,Z as v,tn as w,K as x,Y as y};
|
|
1
|
+
import{t as e}from"./rolldown-runtime-DK3Fl9T5.js";import{C as t,S as n,_ as r,b as i,c as a,d as o,f as s,g as c,h as l,l as u,m as d,n as f,o as p,p as m,s as h,t as g,u as _}from"./playback-a02m3NQr.js";var v={},y={radial:`sculpt`,union:`sculpt`,hosts:`depth`,pieces:`depth`},b={},x;function ee(e,t){let n=x;x=e;try{return t()}finally{x=n}}var S=e=>{let t=x?x[e]:b[e]??v[e];if(!t)throw Error(`This avatar needs the "${y[e]??e}" part of the player. Import it and pass it to use().`);return t},te=e=>x?x[e]:b[e]??v[e],C=(...e)=>S(`sculpt`).reliefFaces(...e),w=e=>e.geometry,T=(e,t)=>{let n=e.length,r=(t/(Math.PI*2)%1+1)%1*n,i=Math.floor(r),a=r-i,o=t=>e[(i+t+n)%n],[s,c,l,u]=[o(-1),o(0),o(1),o(2)];return c+.5*a*(l-s+a*(2*s-5*c+4*l-u+a*(3*(c-l)+u-s)))},ne=(e,t,n,r)=>{let i=T(e,Math.atan2(n,t)),a=Math.hypot(t,n)/i;return Math.sqrt(Math.max(0,1-a**r))},E=1.2,D=2*E/120,O=160,k=new WeakMap,A=(e,t,n)=>{let r=Math.min(Math.max((t+E)/D,1),118.999),i=Math.min(Math.max((n+E)/D,1),118.999),a=Math.floor(r),o=Math.floor(i),s=(e,t,n,r,i)=>t+.5*i*(n-e+i*(2*e-5*t+4*n-r+i*(3*(t-n)+r-e))),c=t=>{let n=(o+t)*121+a;return s(e[n-1],e[n],e[n+1],e[n+2],r-a)};return s(c(-1),c(0),c(1),c(2),i-o)},re=[1,-1,121,-121],j=e=>{let t=new Float64Array(O),n=new Float64Array(O);for(let r=0;r<O;r+=1){let i=r/O*Math.PI*2,a=T(e,i);t[r]=a*Math.cos(i),n[r]=a*Math.sin(i)}let r=new Float64Array(O),i=new Float64Array(O),a=new Float64Array(O);for(let e=0;e<O;e+=1)r[e]=t[(e+1)%O]-t[e],i[e]=n[(e+1)%O]-n[e],a[e]=r[e]*r[e]+i[e]*i[e];let o=new Float32Array(14641);for(let s=0;s<121;s+=1)for(let c=0;c<121;c+=1){let l=-1.2+c*D,u=-1.2+s*D,d=1/0;for(let e=0;e<O;e+=1){let o=l-t[e],s=u-n[e],c=r[e],f=i[e],p=Math.min(Math.max((o*c+s*f)/a[e],0),1),m=o-c*p,h=s-f*p,g=m*m+h*h;g<d&&(d=g)}let f=Math.hypot(l,u)<T(e,Math.atan2(u,l));o[s*121+c]=f?Math.sqrt(d):-Math.sqrt(d)}return o},ie=(e,t,n)=>{let r=(t,r)=>e[r*n*121+t*n],i=[];for(let e=0;e<t;e+=1)for(let n=0;n<t;n+=1)r(n,e)>1e-6&&i.push(e*t+n);let a=new Int32Array(i.length*4).fill(-1),o=new Float64Array(i.length).fill(4);return i.forEach((e,n)=>{let i=e%t,s=(e-i)/t,c=r(i,s);[[i+1,s],[i-1,s],[i,s+1],[i,s-1]].forEach(([e,i],s)=>{let l=r(e,i);l>1e-6?a[n*4+s]=i*t+e:o[n]=o[n]+Math.min(-l/c,1e3)})}),{size:t,cells:Int32Array.from(i),inner:a,weight:o,height:new Float64Array(t*t),load:new Float64Array(t*t),left:new Float64Array(t*t)}},M=({cells:e,inner:t,weight:n,height:r,load:i},a)=>{for(let o=0;o<a;o+=1)for(let a=0;a<e.length;a+=1){let o=e[a],s=i[o];for(let e=0;e<4;e+=1){let n=t[a*4+e];n>=0&&(s+=r[n])}r[o]=s/n[a]}},ae=({cells:e,inner:t,weight:n,height:r,load:i,left:a})=>{let o=0;for(let s=0;s<e.length;s+=1){let c=e[s],l=i[c]-n[s]*r[c];for(let e=0;e<4;e+=1){let n=t[s*4+e];n>=0&&(l+=r[n])}a[c]=l,o=Math.max(o,Math.abs(l))}return o},oe=(e,t)=>{let n=e[t],r=e[t+1];if(!r){M(n,60);return}M(n,2),ae(n);let i=n.size;r.height.fill(0);for(let e of r.cells){let t=e%r.size,a=(e-t)/r.size*2*i+t*2,o=n.left;r.load[e]=4*(4*o[a]+2*(o[a-1]+o[a+1]+o[a-i]+o[a+i])+(o[a-i-1]+o[a-i+1]+o[a+i-1]+o[a+i+1]))/16}oe(e,t+1);let a=r.height,o=r.size;for(let e of n.cells){let t=e%i,r=(e-t)/i,s=t>>1,c=(r>>1)*o+s,l;l=t%2==0&&r%2==0?a[c]:r%2==0?(a[c]+a[c+1])/2:t%2==0?(a[c]+a[c+o])/2:(a[c]+a[c+1]+a[c+o]+a[c+o+1])/4,n.height[e]=n.height[e]+l}M(n,2)},se=[[121,1],[61,2],[31,4],[16,8]],N=1e-9,ce=e=>{let t=se.map(([t,n])=>ie(e,t,n)),n=t[0],r=D*D;for(let e of n.cells)n.load[e]=r;for(let e=0;e<40&&(oe(t,0),!(ae(n)<r*N));e+=1);return le(e,Array.from(n.cells),Float32Array.from(n.height))},le=(e,t,n)=>{let r=0,i=new Float32Array(14641);for(let a of t)r=Math.max(r,n[a]),i[a]=n[a]/e[a];for(let e=0;e<3;e+=1){let e=i.slice();for(let t=122;t<14519;t+=1){if(i[t]>0)continue;let n=0,r=0;for(let e of re)i[t+e]>0&&(n+=i[t+e],r+=1);r&&(e[t]=n/r)}i.set(e)}return{height:n,slope:i,peak:r}},ue=()=>{let e=new Map;return(t,n)=>{if(typeof WeakRef!=`function`)return n();let r=t.join(`,`),i=e.get(r)?.deref();if(i)return i;let a=n();if(e.size>=64)for(let[t,n]of e)n.deref()||e.delete(t);return e.set(r,new WeakRef(a)),a}},de=ue(),fe=ue(),P=new WeakMap,F=e=>{let t=P.get(e);return t||P.set(e,t=de(e,()=>j(e))),t},pe=e=>{let t=k.get(e);return t||(t=fe(e,()=>{let t=F(e);return{distance:t,...ce(t)}}),k.set(e,t)),t},me=new WeakMap,he=e=>{let t=me.get(e);if(t)return t;let{height:n}=pe(e),r=n.reduce((e,t)=>Math.max(e,t),0),i=0,a=0,o=0;n.forEach((e,t)=>{let n=e-r*.9;n<=0||(i+=n,a+=n*(-1.2+t%121*D),o+=n*(-1.2+Math.floor(t/121)*D))});let s=i>0?{x:a/i,y:o/i}:{x:0,y:0};return me.set(e,s),s},I=(e,t,n)=>A(F(e),t,n),ge=(e,t,n)=>{let r=pe(e),i=A(r.distance,t,n);if(i<=0)return 0;let a=Math.min(Math.max((i-2*D)/(2*D),0),1),o=A(r.slope,t,n)*i,s=a>0?A(r.height,t,n):0;return Math.sqrt(Math.max(s*a+o*(1-a),0)/r.peak)},_e=new WeakMap,ve=241,ye=(e,t)=>{let n=Array.from({length:O},(n,r)=>{let i=r/O*Math.PI*2,a=T(e,i),o=a*Math.cos(i),s=a*Math.sin(i);return t===`y`?{along:s,across:o}:{along:o,across:s}}),r=new Float32Array(ve),i=new Float32Array(ve),a=0;for(let e=0;e<ve;e+=1){let t=-1.2+e/240*2*E,o=1/0,s=-1/0;for(let e=0;e<O;e+=1){let r=n[e],i=n[(e+1)%O];if((r.along-t)*(i.along-t)>0||r.along===i.along)continue;let a=r.across+(t-r.along)/(i.along-r.along)*(i.across-r.across);o=Math.min(o,a),s=Math.max(s,a)}s>o&&(r[e]=(o+s)/2,i[e]=(s-o)/2,a=Math.max(a,i[e]))}return{centre:r,half:i,peak:a}},be=(e,t,n,r)=>{let i=_e.get(e);i||_e.set(e,i=new Map);let a=i.get(t);a||i.set(t,a=ye(e,t));let o=t===`y`?r:n,s=t===`y`?n:r,c=Math.min(Math.max((o+E)/(2*E)*240,0),239.999),l=Math.floor(c),u=c-l,d=e=>e[l]*(1-u)+e[l+1]*u,f=d(a.half),p=s-d(a.centre);return Math.sqrt(Math.max(0,f*f-p*p))/a.peak},xe=new WeakMap,Se=(e,t,n)=>{let r=xe.get(e);if(!r){r=new Float32Array(14641);for(let t=0;t<121;t++){let n=-1.2+t*D,i=0;for(let t=0;t<121;t++)i=Math.max(i,ge(e,-1.2+t*D,n));for(let e=0;e<121;e++)r[t*121+e]=i}xe.set(e,r)}return Math.max(0,Math.min(1,ge(e,t,n)/Math.max(1e-6,A(r,0,n))))},Ce=0,we=1,L=2,R=new Float64Array(8),Te=(e,t)=>{R[t]=((-e+2)*e-1)*e/2,R[t+1]=((3*e-5)*e*e+2)/2,R[t+2]=((-3*e+4)*e+1)*e/2,R[t+3]=(e-1)*e*e/2},Ee=(e,t,n,r)=>{let i=new Uint8Array(e*e),a=new Uint8Array(e*e),o=new Float32Array(e*e*t),s=new Float64Array(t);return{read:(c,l,u)=>{let d=Math.floor(c),f=Math.floor(l);if(!(d>=1&&f>=1&&d<e-2&&f<e-2))return!1;let p=f*e+d;if(a[p]===L)return!1;for(let r=0;a[p]===Ce&&r<4;r+=1)for(let c=0;c<4;c+=1){let l=(f-1+r)*e+d-1+c;if(i[l]===Ce&&(i[l]=n(d-1+c,f-1+r,s)?we:L,o.set(s,l*t)),i[l]===L)return a[p]=L,!1}let m=((f-1)*e+d-1)*t,h=e*t;if(a[p]===Ce){let e=(e,n,r)=>o[m+n*h+e*t+r],n=!0;for(let i=0;n&&i<t;i+=1)for(let t=0;n&&t<4;t+=1)for(let a=1;a<3;a+=1)(Math.abs(e(a-1,t,i)-2*e(a,t,i)+e(a+1,t,i))>r[i]||Math.abs(e(t,a-1,i)-2*e(t,a,i)+e(t,a+1,i))>r[i])&&(n=!1);if(a[p]=n?we:L,!n)return!1}Te(c-d,0),Te(l-f,4);let g=R[0],_=R[1],v=R[2],y=R[3];for(let e=0;e<t;e+=1){let n=0,r=m+e;for(let e=0;e<4;e+=1)n+=R[4+e]*(g*o[r]+_*o[r+t]+v*o[r+t*2]+y*o[r+t*3]),r+=h;u[e]=n}return!0}}},De=new WeakSet,Oe=e=>(De.add(e),e),ke=e=>e!==void 0&&De.has(e),Ae=e=>{if(e.type!==`blob`)return{x:0,y:0};let t=he(B(e));return{x:t.x*e.width/2,y:t.y*e.height/2}},je=e=>{if(e.type===`blob`)return(w(e)?.plate)?.map(([t,n])=>[t*e.width/2,n*e.height/2])},Me=(e,t,n)=>{if(!e)return 0;let r=Math.max(0,n-(e.from??0));return e.x*t*t+(e.y??0)*r*r},Ne=e=>{if(e.type!==`blob`)return;let t=w(e)?.bend;if(!t)return;let n=e.width/2||1,r=e.height/2||1;return(e,i)=>Me(t,e/n,i/r)*n},Pe=new WeakMap,z=e=>{if(e.type!==`blob`)return;let t=w(e).window;if(!t)return;let n=Pe.get(e);if(n?.source===t&&n.width===e.width&&n.height===e.height)return n.points;let r=t.map(([t,n])=>[t*e.width/2,n*e.height/2]);return Pe.set(e,{source:t,width:e.width,height:e.height,points:r}),r},Fe=e=>e.type===`cone`||e.type===`cylinder`||e.type===`cursor`,Ie=new WeakMap,Le=e=>{let t=e.type===`blob`?w(e):void 0,n=`${e.type}|${e.width}|${e.height}|${e.depth}|${e.roundness}|${e.morphRoundness??``}|${e.tipRoundness??``}|${e.baseRoundness??``}|${ze(e)}`,r=t?.radialDepthPower===void 0?n:`${n}|radialDepthPower:${t.radialDepthPower}`,i=Ie.get(e);if(i&&i.shape===t&&i.key===r)return i.sample;let a=(t,n)=>Xt(e,t,n);return Fe(e)&&Oe(a),Ie.set(e,{shape:t,key:r,sample:a}),a},Re=e=>e.type===`blob`&&w(e)?.flush?0:Math.min(12,e.depth*.04),ze=e=>{let t=e.type===`blob`?w(e).sockets:void 0;return t?[t.centers.flat().join(`,`),t.apertureRadius,t.rimOuterRadius,t.padRadius,t.plane,t.depth,t.power].join(`|`):``},Be=new WeakMap,Ve=0,He=e=>{if(!e)return``;let t=Be.get(e);return t===void 0&&Be.set(e,t=++Ve),t},Ue=e=>{let t=`${e.type}|${e.width}|${e.height}|${e.depth}|${e.roundness}|${e.morphRoundness??``}|${e.tipRoundness??``}|${e.baseRoundness??``}|${e.outline??``}|${He(e.geometry)}|${e.geometry?.relief?.rim??``}|${e.geometry?.relief?.bits??``}|${e.rotationCenter?.join(`,`)??``}|${ze(e)}`,n=e.type===`blob`?w(e).radialDepthPower:void 0;return n===void 0?t:`${t}|radialDepthPower:${n}`},We=e=>{let t=Ue(e),n=e.outlineRounding??1;return n===1?t:`${t}|outlineRounding:${n}`},Ge=e=>{if(e.type!==`blob`)return;let t=w(e);return t.sockets?t.sockets.plane*e.width:t.eyePlane===void 0?void 0:t.eyePlane*e.depth},Ke=new WeakMap,qe=(e,t=Ge(e))=>{if(t===void 0)return;let n=w(e),r=Ke.get(e);if(r?.shape===n&&r.depth===t)return r.sample;let i=(e,n)=>({point:[e,n,t],normal:[0,0,1]});return Ke.set(e,{shape:n,depth:t,sample:i}),i},Je=e=>{let t=Le(e),n=e.type===`blob`&&w(e).sockets?t:qe(e);if(n)return{sample:n,planar:!0};let r=z(e)?Re(e):0;return{sample:r?$e(t,r):t,planar:!1}},Ye=new WeakMap,Xe=e=>{let t=z(e);if(!t)return;let n=Ue(e),r=w(e),i=Ye.get(e),a=i?.key===n&&i.shape===r?i.floor:void 0;if(a===void 0){a=1/0;for(let[n,r]of t)a=Math.min(a,Xt(e,n,r).point[2]);a-=Re(e),Ye.set(e,{key:n,shape:r,floor:a})}return a},Ze=(e,t,n,r)=>{let i=Xe(e);return i!==void 0&&n[2]+Math.abs(r[0])*(t.width/2)+Math.abs(r[1])*(t.height/2)+Math.abs(r[2])*(t.depth/2)<i},Qe=new WeakMap,$e=(e,t)=>{let n=Qe.get(e);n||Qe.set(e,n=new Map);let r=n.get(t);if(r)return r;let i=(n,r)=>{let{point:i,normal:a}=e(n,r);return{point:[i[0],i[1],i[2]-t],normal:a}};return ke(e)&&Oe(i),n.size>=8&&n.delete(n.keys().next().value),n.set(t,i),i},B=e=>w(e).radii,et=(e,t,n,r)=>{let i=e.depth/2,a=Math.max(0,Math.min(1,e.roundness)),o=w(e),s=o.revolve,c=a>0?i*(o.radialDepthPower?ne(t,n,r,o.radialDepthPower):s?be(t,s,n,r):ge(t,n,r)):0;if(a>=1)return c;let l=I(t,n,r)*Math.min(e.width,e.height)/2,u=l>=i?i:Math.sqrt(Math.max(0,i**2-(i-l)**2));return u+(c-u)*a},tt=(e,t,n,r)=>{let i=w(e);if(i?.plate){let t=-Me(i.bend,n,r)*(e.width/2);return{front:e.depth/2+t,back:-e.depth/2+t}}let a=i?.relief;if(!a){let a=i.sections;if(!a){let i=et(e,t,n,r);return{front:i,back:-i}}let{profile:o}=a,s=0,c=o.length-2;for(;s<c;){let e=Math.floor((s+c)/2);o[e+1][0]<r?s=e+1:c=e}let l=o[s],u=o[s+1],d=Math.max(0,Math.min(1,(r-l[0])/(u[0]-l[0]))),f=e=>{let t=o[Math.max(0,s-1)],n=o[Math.min(o.length-1,s+2)],r=u[0]-l[0],i=(u[e]-t[e])/(u[0]-t[0])*r,a=(n[e]-l[e])/(n[0]-l[0])*r;return(2*d*d*d-3*d*d+1)*l[e]+(d*d*d-2*d*d+d)*i+(-2*d*d*d+3*d*d)*u[e]+(d*d*d-d*d)*a},p=f(1)*e.depth,m=f(2)*e.depth,h=(p+m)/2,g=Math.max(0,(p-m)/2),_=Se(t,n,r),v=Math.sqrt(Math.max(0,1-(1-_*_)**(a.frontPower/2))),y=a.frontTaper??0;return{front:h+g*(v*(1-y+y*v*v)),back:h-g*_}}return C(e,a,t,n,r)},nt=(e,t,n,r)=>{let i=w(e).sockets;return i?{front:S(`sockets`).socketFrontAt(i,n/2,r*e.height/(e.width*2),t.front/e.width)*e.width,back:t.back}:t},rt=(e,t,n,r)=>nt(e,tt(e,t,n,r),n,r),it=e=>{if(e.type!==`blob`)return;let t=w(e);if(!t.sections||t.relief||t.lobes||t.hull||t.plate||t.revolve)return;let{profile:n}=t.sections,r=t.sockets?t.sockets.plane*e.width:-1/0;for(let t=0;t<n.length-1;t++){let i=n[t],a=n[t+1],o=n[Math.max(0,t-1)],s=n[Math.min(n.length-1,t+2)],c=a[0]-i[0];for(let t of[1,2]){let n=(a[t]-o[t])/(a[0]-o[0])*c,l=(s[t]-i[t])/(s[0]-i[0])*c;r=Math.max(r,i[t]*e.depth,(i[t]+n/3)*e.depth,(a[t]-l/3)*e.depth,a[t]*e.depth)}}return r+Math.max(1,Math.abs(r),e.depth)*1e-7},at=(e,t,n)=>{if(e.type!==`blob`)return;let r=w(e);if(r.lobes||r.hull||r.plate||r.revolve)return;let i=t/(e.width/2||1),a=n/(e.height/2||1),o=ft(e);if(o?.read(t/o.step+V,n/o.step+V,ct))return nt(e,{front:ct[0],back:ct[1]},i,a);let s=ot(e,t,n);return s&&nt(e,s,i,a)},ot=(e,t,n)=>{let r=B(e),i=t/(e.width/2||1),a=n/(e.height/2||1);if(!(Math.hypot(i,a)>T(r,Math.atan2(a,i))))return tt(e,r,i,a)},st=160,V=82,ct=new Float64Array(2),H=new Float64Array(3),lt=(e,t,n)=>{let r=w(t),i=r.relief,a=e.get(t);return(!a||a.width!==t.width||a.height!==t.height||a.depth!==t.depth||a.roundness!==t.roundness||a.shape!==r||a.radii!==r.radii||a.sections!==r.sections||a.profile!==r.sections?.profile||a.sockets!==r.sockets||a.relief!==i||a.front!==i?.front||a.back!==i?.back||a.bits!==i?.bits||a.rim!==i?.rim)&&(a={width:t.width,height:t.height,depth:t.depth,roundness:t.roundness,shape:r,radii:r.radii,sections:r.sections,profile:r.sections?.profile,sockets:r.sockets,relief:i,front:i?.front,back:i?.back,bits:i?.bits,rim:i?.rim},e.set(t,a)),a.lattice??=n()},ut=new WeakMap,dt=new WeakMap,ft=e=>lt(dt,e,()=>{let t=Math.max(e.width,e.height)/st,n=t*.12;return Object.assign(Ee(165,2,(n,r,i)=>{let a=ot(e,(n-V)*t,(r-V)*t);return a?(i[0]=a.front,i[1]=a.back,!0):!1},[n,n]),{step:t})}),U=(e,t,n,r)=>{let i=w(e).lobes;if(i){let t=S(`sculpt`).lobePoint(i,n,r);return[t[0]*e.width/2,t[1]*e.height/2,t[2]*e.depth/2]}let a=Math.cos(r)*Math.sin(n),o=Math.sin(r),s=Math.cos(r)*Math.cos(n),c=T(t,Math.atan2(o,a));return[e.width/2*c*a,e.height/2*c*o,s>=0?rt(e,t,c*a,c*o).front:rt(e,t,c*a,c*o).back]},pt=(e,t)=>{let n=e.width/2||1,r=e.height/2||1,i=e.depth/2||1,a=t.normal[0]/n,o=t.normal[1]/r,s=t.normal[2]/i,c=Math.hypot(a,o,s)||1;return{point:[t.point[0]*n,t.point[1]*r,t.point[2]*i],normal:[a/c,o/c,s/c]}},mt=.001,ht=(e,t,n)=>{let r=w(e).lobes;if(r)return pt(e,S(`sculpt`).lobeSample(r,t,n));let i=B(e),a=Math.max(-Math.PI/2+mt*4,Math.min(Math.PI/2-mt*4,n)),o=U(e,i,t,a);if(w(e).sockets&&Math.cos(t)>=0)return gt(e,o[0],o[1]);let s=U(e,i,t+mt,a),c=U(e,i,t,a+mt),l=[s[0]-o[0],s[1]-o[1],s[2]-o[2]],u=[c[0]-o[0],c[1]-o[1],c[2]-o[2]],d=l[1]*u[2]-l[2]*u[1],f=l[2]*u[0]-l[0]*u[2],p=l[0]*u[1]-l[1]*u[0];d*o[0]+f*o[1]+p*o[2]<0&&(d=-d,f=-f,p=-p);let m=Math.hypot(d,f,p)||1;return{point:U(e,i,t,n),normal:[d/m,f/m,p/m]}},gt=(e,t,n)=>{let r=w(e).lobes;if(r)return pt(e,S(`sculpt`).lobeFrontRead(r,t/(e.width/2||1),n/(e.height/2||1)));let i=B(e),a=e.width/2||1,o=e.height/2||1,s=(t,n)=>rt(e,i,t/a,n/o).front,c=w(e);if(!c.plate&&!c.sockets){let r=lt(ut,e,()=>{let t=Math.max(e.width,e.height)/st;return Object.assign(Ee(165,3,(e,n,r)=>{let c=(e-V)*t,l=(n-V)*t;return Math.hypot(c/a,l/o)>T(i,Math.atan2(l/o,c/a))?!1:(r[0]=s(c,l),r[1]=s(c+.5,l)-s(c-.5,l),r[2]=s(c,l+.5)-s(c,l-.5),!0)},[t*.12,.03,.03]),{step:t})});if(r?.read(t/r.step+V,n/r.step+V,H)){let e=Math.hypot(H[1],H[2],1);return{point:[t,n,H[0]],normal:[-H[1]/e,-H[2]/e,1/e]}}}let l=s(t,n),u=s(t+.5,n)-s(t-.5,n),d=s(t,n+.5)-s(t,n-.5),f=Math.hypot(u,d,1);return{point:[t,n,l],normal:[-u/f,-d/f,1/f]}},_t=(e,t)=>Math.sign(e)*Math.abs(e)**t,vt=(e,t,n,r,i,a,o)=>{let s=_t(Math.cos(t),a);return[n/2*s*_t(Math.sin(e),o),r/2*_t(Math.sin(t),a),i/2*s*_t(Math.cos(e),o)]},yt=(e,t,n)=>{let r=e.width/2,i=e.depth/2,a=Math.min(r,e.height/2),o=Math.max(0,(e.height-a*2)/2),s=o*2+Math.PI*a,c=(n+Math.PI/2)/Math.PI*s,l=r,u=0;if(c<Math.PI*a/2){let e=-Math.PI/2+c/a;l=r*Math.cos(e),u=-o+a*Math.sin(e)}else if(c<=Math.PI*a/2+o*2)u=-o+c-Math.PI*a/2;else{let e=(c-Math.PI*a/2-o*2)/a;l=r*Math.cos(e),u=o+a*Math.sin(e)}let d=r?i/r:1;return[l*Math.sin(t),u,l*d*Math.cos(t)]},bt=e=>Math.max(0,Math.min(2,e??0)),xt=e=>1+bt(e.roundness)/2,St=.04,Ct=e=>e.roundness<=0?1/0:2/(St+bt(e.roundness)/2*.96),wt=(e,t,n,r)=>{let i=Math.cos(n)*Math.sin(t),a=Math.sin(n),o=Math.cos(n)*Math.cos(t),s=Number.isFinite(r)?(Math.abs(i)**r+Math.abs(a)**r+Math.abs(o)**r)**(1/r)||1:Math.max(Math.abs(i),Math.abs(a),Math.abs(o))||1;return[e.width/2*(i/s),e.height/2*(a/s),e.depth/2*(o/s)]},Tt=(e,t,n)=>wt(e,t,n,xt(e)),Et=(e,t,n)=>wt(e,t,n,Ct(e)),Dt=.24,Ot=.2,kt=.22,At=e=>bt(e.morphRoundness)/2,jt=(e,t,n)=>{let r=At(e),i=Math.max(0,Math.min(1,t)),a=Math.sin(i*Math.PI),o=(1-Math.cos(i*Math.PI))/2;return{radiusScale:n.radiusScale+(a-n.radiusScale)*r,verticalProgress:n.verticalProgress+(o-n.verticalProgress)*r}},Mt=(e,t,n,r,i)=>{let a=1-i;return a**3*e+3*a*a*i*t+3*a*i*i*n+i**3*r},Nt=e=>({tipFraction:(e.tipRoundness??0)*Dt,baseFraction:(e.baseRoundness??0)*Ot}),Pt=(e,t)=>{let n=Math.max(0,Math.min(1,t)),r=e.roundness*kt;if(r<=0)return{radiusScale:1,verticalProgress:(Math.sin((n-.5)*Math.PI)+1)/2};if(n<r){let e=-Math.PI/2+n/r*(Math.PI/2);return{radiusScale:1-r+r*Math.cos(e),verticalProgress:(r+r*Math.sin(e))/2}}if(n>1-r){let e=(n-(1-r))/r*(Math.PI/2);return{radiusScale:1-r+r*Math.cos(e),verticalProgress:1-r/2+r*Math.sin(e)/2}}let i=(n-r)/(1-r*2);return{radiusScale:1,verticalProgress:r/2+i*(1-r)}},Ft=(e,t)=>jt(e,t,Pt(e,t)),It=(e,t,n)=>{let r=Math.max(0,Math.min(1,t)),i=0,a=1;for(let t=0;t<14;t+=1){let t=(i+a)/2;n(e,t).verticalProgress<r?i=t:a=t}return n(e,(i+a)/2).radiusScale},Lt=(e,t)=>{let n=Math.max(0,Math.min(1,t)),{tipFraction:r,baseFraction:i}=Nt(e);if(i>0&&n<i){let e=n/i;return{radiusScale:Mt(1-i,1,1-i/2,1-i,e),verticalProgress:Mt(0,0,i/2,i,e)}}if(r>0&&n>1-r){let e=(n-(1-r))/r;return{radiusScale:Mt(r,r/2,r/4,0,e),verticalProgress:Mt(1-r,1-r/2,1,1,e)}}return{radiusScale:1-n,verticalProgress:n}},Rt=(e,t)=>jt(e,t,Lt(e,t)),zt=e=>{let t=e.height*.36,n=e.height-t;return{coneApexY:-e.height/2,coneBaseY:-e.height/2+t,bodyHeight:n,bodyCenterY:e.height/2-n/2,bodyWidth:e.width*.54,bodyDepth:e.depth*.62}},W=(e,t,n)=>{let{width:r,height:i,depth:a}=e;switch(e.type){case`sphere`:case`mickey`:return vt(t,n,r,i,a,1,1);case`cube`:return Et(e,t,n);case`cylinder`:{let o=Ft(e,(n+Math.PI/2)/Math.PI);return[r/2*o.radiusScale*Math.sin(t),-i/2+i*o.verticalProgress,a/2*o.radiusScale*Math.cos(t)]}case`cursor`:{let r=zt(e),i=(n+Math.PI/2)/Math.PI,a=Pt({...e,width:r.bodyWidth,height:r.bodyHeight,depth:r.bodyDepth},i);return[r.bodyWidth/2*a.radiusScale*Math.sin(t),r.bodyCenterY-r.bodyHeight/2+r.bodyHeight*a.verticalProgress,r.bodyDepth/2*a.radiusScale*Math.cos(t)]}case`diamond`:return Tt(e,t,n);case`capsule`:return yt(e,t,n);case`cone`:{let o=Rt(e,(n+Math.PI/2)/Math.PI);return[r/2*o.radiusScale*Math.sin(t),i/2-i*o.verticalProgress,a/2*o.radiusScale*Math.cos(t)]}case`blob`:return U(e,B(e),t,n)}},Bt=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],G=([e,t,n])=>{let r=Math.hypot(e,t,n)||1;return[e/r,t/r,n/r]},Vt=(e,t,n)=>{let r=e.type===`cone`?-1:1;return G([r*(t[1]*n[2]-t[2]*n[1]),r*(t[2]*n[0]-t[0]*n[2]),r*(t[0]*n[1]-t[1]*n[0])])},Ht=(e,t,n)=>{let r=5e-4;if(e.type===`cone`&&n>=Math.PI/2-r)return[0,-1,0];let i=W(e,t-r,n),a=W(e,t+r,n),o=W(e,t,Math.max(-Math.PI/2,n-r)),s=W(e,t,Math.min(Math.PI/2,n+r));return Vt(e,Bt(a,i),Bt(s,o))},Ut=(e,t)=>Math.sign(e)*Math.abs(e)**t,Wt=(e,t,n)=>{let r=e.width/2||1,i=e.height/2||1,a=e.depth/2||1;return G([Ut(t[0]/r,n-1)/r,Ut(t[1]/i,n-1)/i,Ut(t[2]/a,n-1)/a])},Gt=(e,t)=>Wt(e,t,xt(e)),Kt=(e,t)=>{let n=Ct(e);if(Number.isFinite(n))return Wt(e,t,n);let r=[t[0]/(e.width/2||1),t[1]/(e.height/2||1),t[2]/(e.depth/2||1)],i=r.reduce((e,t,n)=>Math.abs(t)>Math.abs(r[e])?n:e,0);return[i===0?Math.sign(r[0]):0,i===1?Math.sign(r[1]):0,i===2?Math.sign(r[2]):0]},qt=(e,t,n,r,i)=>{let a=e.width/2||1,o=e.height/2||1,s=e.depth/2||1;if(!Number.isFinite(r)){let r=[Math.max(-a,Math.min(a,t)),Math.max(-o,Math.min(o,n)),s];return{point:r,normal:i(e,r)}}let c=Math.max(-1,Math.min(1,n/o)),l=Math.max(0,1-Math.abs(c)**r)**(1/r),u=Math.max(-a*l,Math.min(a*l,t)),d=u/a,f=Math.max(0,1-Math.abs(d)**r-Math.abs(c)**r)**(1/r),p=[u,c*o,s*f];return{point:p,normal:i(e,p)}},Jt=(e,t,n,r,i,a=0)=>{let o=t-a,s=Math.max(0,1-(e/(n||1))**2-(o/(r||1))**2),c=i*Math.sqrt(s);return{point:[e,t,c],normal:G([e/(n*n||1),o/(r*r||1),c/(i*i||1)])}},Yt=(e,t,n,r,i)=>{let a=e.width/2||1,o=e.depth/2||1,s=Math.max(0,Math.min(1,.5+i*(n/e.height))),c=It(e,s,r),l=a*c,u=o*c,d=Math.max(-l,Math.min(l,t)),f=l>0?Math.max(0,1-(d/l)**2):0,p=u*Math.sqrt(f),m=1e-4,h=Math.max(0,s-m),g=Math.min(1,s+m),_=It(e,h,r),v=(It(e,g,r)-_)/(g-h||1),y=Math.max(Math.sqrt(f),1e-4),b=-(o/a)*d/(l*y||1),x=i*o*v/(e.height*y||1);return{point:[d,n,p],normal:G([-b,-x,1])}},Xt=(e,t,n)=>{let r=e.width/2||1,i=e.height/2||1,a=e.depth/2||1;switch(e.type){case`sphere`:case`mickey`:return Jt(t,n,r,i,a);case`cube`:return qt(e,t,n,Ct(e),Kt);case`capsule`:{let e=Math.min(r,i),o=Math.max(0,i-e);return Jt(t,n,r,e,a,n<-o?-o:n>o?o:n)}case`cylinder`:return Yt(e,t,n,Ft,1);case`cursor`:{let r=zt(e),i=Yt({...e,width:r.bodyWidth,height:r.bodyHeight,depth:r.bodyDepth},t,n-r.bodyCenterY,Pt,1);return{point:[i.point[0],i.point[1]+r.bodyCenterY,i.point[2]],normal:i.normal}}case`cone`:return Yt(e,t,n,Rt,-1);case`diamond`:return qt(e,t,n,xt(e),Gt);case`blob`:return gt(e,t,n)}},Zt=(e,t,n)=>{let r=W(e,t,n);if(e.type===`sphere`||e.type===`mickey`){let t=e.width/2||1,n=e.height/2||1,i=e.depth/2||1;return{point:r,normal:G([r[0]/(t*t),r[1]/(n*n),r[2]/(i*i)])}}return e.type===`cylinder`&&e.roundness<=0&&(e.morphRoundness??0)<=0?{point:r,normal:G([Math.sin(t)/(e.width/2||1),0,Math.cos(t)/(e.depth/2||1)])}:e.type===`diamond`?{point:r,normal:Gt(e,r)}:e.type===`cube`?{point:r,normal:Kt(e,r)}:e.type===`blob`?ht(e,t,n):{point:r,normal:Ht(e,t,n)}},Qt=new WeakMap,$t=e=>{let t=Qt.get(e);if(t===void 0){let n=e.length,r=t=>{let r=(t%n+n)%n*(Math.PI*2/n),i=e[(t%n+n)%n];return[Math.cos(r)*i,Math.sin(r)*i]};t=e.every((e,t)=>{let[n,i]=r(t-1),[a,o]=r(t),[s,c]=r(t+1);return(a-n)*(c-o)-(o-i)*(s-a)>=-1e-9}),Qt.set(e,t)}return t},en=e=>{if(e.type===`mickey`){let t=Math.min(e.width,e.height)*.23,n=Math.min(t,e.depth*.29);return[-1,1].map(r=>({id:`ear-${r}`,name:``,surface:{type:`sphere`,width:t*2,height:t*2,depth:n*2,roundness:1},position:[r*e.width*.37,-e.height*.39,-e.depth*.12],rotation:[0,0,0]}))}if(e.type===`cursor`){let t=zt(e),n=t.coneBaseY-t.coneApexY;return[{id:`cursor-tip`,name:``,surface:{type:`cone`,width:e.width,height:n,depth:e.depth,roundness:0,morphRoundness:0,tipRoundness:0,baseRoundness:0},position:[0,(t.coneApexY+t.coneBaseY)/2,0],rotation:[0,0,0]}]}return[]},tn=(e,t)=>{if(z(e))return!1;let n=t.filter(e=>!e.paintOn&&e.color!==`eyes`&&e.color!==`mark`);return n.some(e=>e.color===`accent`)&&n.some(e=>e.color===`secondary`||e.color===`tertiary`)&&n.every(e=>!e.rooted&&!e.fixed&&(e.color===`accent`||e.color===`secondary`||e.color===`tertiary`))},nn=e=>e.type===`blob`?w(e):void 0,rn=e=>{let t=[...en(e.body.primary),...e.body.nodes],n=[e.body.primary,...t.map(e=>e.surface)],r=n.some(e=>nn(e)?.lobes),i=n.some(e=>nn(e)?.sockets),a=t.some(e=>e.paintOn),o=[];return r&&o.push(`sculpt`),i&&o.push(`sockets`),a&&o.push(`paint`),(r||t.length)&&o.push(`depth`),o},an=(e,...t)=>!!e.geometry?.radialDepthPower&&S(`radial`)(e,...t),on=e=>{let t=0;for(let n=0;n<e.length;n+=1)t+=e[n];return t>e.length*.25},sn=(e,t,n)=>{for(let r=0;r<e;r+=1){if(t[r]>0){n(r,r,r,0);continue}let i=1;for(;i<e&&t[(r-i+e)%e]<=0;)i+=1;let a=1;for(;a<e&&t[(r+a)%e]<=0;)a+=1;if(i>=e)return;n(r,(r-i+e)%e,(r+a)%e,i/(i+a))}},cn=e=>{let t=10**e;return e=>Math.round(e*t)/t},ln=Array.from({length:2048},(e,t)=>String(t)),un=new Map,dn=e=>{let t=un.get(e);if(!t){let n=10**e;t=Array.from({length:n},(t,n)=>n?`.${String(n).padStart(e,`0`).replace(/0+$/,``)}`:``),un.set(e,t)}return t},fn=e=>{if(!Number.isInteger(e)||e<0||e>4){let t=cn(e);return e=>`${t(e)}`}let t=10**e,n=dn(e);return e=>{let r=Math.round(e*t),i=r<0?-r:r;if(!(i<1e9))return`${r/t}`;let a=i/t|0,o=(a<2048?ln[a]:String(a))+n[i-a*t];return r<0?`-${o}`:o}},K=e=>(e.charCodeAt(0),e),pn=new Map,mn=e=>{let t=pn.get(e);return t||pn.set(e,t=fn(e)),t},hn=Math.cos(75*Math.PI/180),gn=class{xs;ys;handleXs;handleYs;constructor(e){this.xs=new Float64Array(e),this.ys=new Float64Array(e),this.handleXs=new Float64Array(e),this.handleYs=new Float64Array(e)}reserve(e){if(e<=this.xs.length)return;let t=new Float64Array(e),n=new Float64Array(e);t.set(this.xs),n.set(this.ys),this.xs=t,this.ys=n,this.handleXs=new Float64Array(e),this.handleYs=new Float64Array(e)}set(e,t,n){e>=this.xs.length&&this.reserve(e+1),this.xs[e]=t,this.ys[e]=n}point(e){return[this.xs[e],this.ys[e]]}closeHorizon(e,t){sn(e,t,(e,t,n,r)=>{this.xs[e]=this.xs[t]+(this.xs[n]-this.xs[t])*r,this.ys[e]=this.ys[t]+(this.ys[n]-this.ys[t])*r})}closed(e,{precision:t,curve:n},r=1){let i=cn(t),a=mn(t);if(n===`spline`&&r===1){let n=mn(t+1);for(let t=0;t<e;t+=1)this.xs[t]=i(this.xs[t]),this.ys[t]=i(this.ys[t]);let r=t=>n((this.xs[t]+this.xs[(t+1)%e])/2),o=t=>n((this.ys[t]+this.ys[(t+1)%e])/2),s=`M${r(e-1)} ${o(e-1)}Q${a(this.xs[0])} ${a(this.ys[0])} ${r(0)} ${o(0)}`;for(let t=1;t<e;t+=1)s+=`T${r(t)} ${o(t)}`;return K(`${s}Z`)}let o=r===1?1/6:r/6;for(let t=0;t<e;t+=1){let n=(t-1+e)%e,r=(t+1)%e,i=this.xs[t]-this.xs[n],a=this.ys[t]-this.ys[n],s=this.xs[r]-this.xs[t],c=this.ys[r]-this.ys[t],l=Math.hypot(i,a),u=Math.hypot(s,c),d=(this.xs[r]-this.xs[n])*o,f=(this.ys[r]-this.ys[n])*o;i*s+a*c<hn*l*u&&(d=f=0);let p=Math.min(l,u)/2,m=Math.hypot(d,f);m>p&&(d*=p/m,f*=p/m),this.handleXs[t]=d,this.handleYs[t]=f}let s=`M${a(this.xs[0])} ${a(this.ys[0])}`;for(let t=0;t<e;t+=1){let n=(t+1)%e;s+=`C${a(this.xs[t]+this.handleXs[t])} ${a(this.ys[t]+this.handleYs[t])} ${a(this.xs[n]-this.handleXs[n])} ${a(this.ys[n]-this.handleYs[n])} ${a(this.xs[n])} ${a(this.ys[n])}`}return K(`${s}Z`)}},_n=(e,t)=>{let n=620-e*t;return Math.abs(n)<1e-4?62e5:620/n},vn=(e,t)=>{let n=Math.min(Math.abs(e*t),619);return 620/Math.sqrt(384400-n*n)},yn=Math.PI*2,q=yn/192,bn=Float64Array.from({length:192},(e,t)=>Math.cos(t*q)),xn=Float64Array.from({length:192},(e,t)=>Math.sin(t*q)),J=new gn(192),Y=new Float64Array(3),X=(e,t,n,r,i)=>{let{m:a,t:o}=e,s=a[0]*n+a[1]*r+a[2]*i+o[0],c=a[3]*n+a[4]*r+a[5]*i+o[1],l=a[6]*n+a[7]*r+a[8]*i+o[2],u=_n(l,t);return Y[0]=s*u,Y[1]=c*u,Y[2]=l,Y},Sn=new Map,Z=(e,t,n)=>{e.set(K(t),typeof n==`string`?K(n):n),e.size>64&&e.delete(e.keys().next().value)},Q=(e,t)=>{let n=e.get(t);return n!==void 0&&(e.delete(t),e.set(t,n)),n},Cn={precision:2,step:1,curve:`catmull`},wn=(e,t)=>t===1||e.step===1?e:{...e,step:1},Tn=e=>1-(1-e)**5,En=4753,Dn=()=>({positions:new Float32Array(En*3),normals:new Float32Array(En*3)}),On=e=>-Math.PI/2+(Math.min(Math.max(e,1),47)-1)/46*Math.PI,kn=e=>-Math.PI+e/96*Math.PI*2,An=e=>{let t=t=>{let n=0;for(let r=0;r<97;r+=1)n+=e.positions[(t*97+r)*3+1];return n/97};if(t(1)<=t(47))return e;for(let t=1;t<24;t+=1){let n=48-t;for(let r of[e.positions,e.normals]){let e=r.slice(t*291,(t+1)*291);r.copyWithin(t*291,n*291,(n+1)*291),r.set(e,n*291)}}return e},jn=e=>([[0,1,-1],[48,47,1]].forEach(([t,n,r])=>{let i=0,a=0,o=0;for(let t=0;t<96;t+=1){let r=(n*97+t)*3;i+=e.positions[r],a+=e.positions[r+1],o+=e.positions[r+2]}for(let n=0;n<97;n+=1){let s=(t*97+n)*3;e.positions[s]=i/96,e.positions[s+1]=a/96,e.positions[s+2]=o/96,e.normals[s]=0,e.normals[s+1]=r,e.normals[s+2]=0}}),e),Mn=e=>jn(An(e)),Nn=(e,t=Dn())=>{let n=0;for(let r=0;r<=48;r+=1){let i=On(r);for(let r=0;r<=96;r+=1){let{point:a,normal:o}=Zt(e,kn(r),i),s=!(e.type===`blob`&&w(e).sockets)&&o[0]*a[0]+o[1]*a[1]+o[2]*a[2]<0?-1:1,c=(Math.hypot(o[0],o[1],o[2])||1)*s;t.positions.set(a,n),t.normals[n]=o[0]/c,t.normals[n+1]=o[1]/c,t.normals[n+2]=o[2]/c,n+=3}}return Mn(t)},Pn=24,$=new Map,Fn=e=>{let t=Ue(e),n=$.get(t);if(n)return $.delete(t),$.set(t,n),n;let r=Nn(e);return $.set(t,r),$.size>Pn&&$.delete($.keys().next().value),r},In=(e,t,n)=>{let[r,i,a,o,s,c]=t,l=1-n*e[2],u=l*l-n*n*c;if(l<=0||u<=1e-10)return;let d=(e[0]*l+n*a)/u,f=(e[1]*l+n*s)/u,p=(r-e[0]**2)/u+d*d,m=(i-e[0]*e[1])/u+d*f,h=(o-e[1]**2)/u+f*f;if(!(p>0))return;let g=Math.sqrt(p),_=m/g,v=h-_*_;if(!(v>0))return;let y=Math.sqrt(v);return[d,f,g,_,y].every(Number.isFinite)?{x:d,y:f,ux:g,uy:_,vy:y}:void 0},Ln=(e,t,n,r,i)=>{if(e.type!==`sphere`&&e.type!==`mickey`)return!1;let{m:a,t:o}=t,s=e.width/2,c=e.height/2,l=e.depth/2,u=(e,t)=>a[e*3]*a[t*3]*s*s+a[e*3+1]*a[t*3+1]*c*c+a[e*3+2]*a[t*3+2]*l*l,d=In(o,[u(0,0),u(0,1),u(0,2),u(1,1),u(1,2),u(2,2)],n/620);if(!d)return!1;let{x:f,y:p,ux:m,uy:h,vy:g}=d,_=(r[0]-f)/m,v=(r[1]-p-h*_)/g,y=_*_+v*v-1;if(!(y<0))return!1;let b=Math.PI*2/i.length;for(let e=0;e<i.length;e+=1){let t=Math.cos(e*b)/m,n=(Math.sin(e*b)-h*t)/g,r=t*t+n*n,a=_*t+v*n;i[e]=(-a+Math.sqrt(a*a-r*y))/r}return!0},Rn=(e,t,n)=>{let r=Math.min(e,t),i=Math.max(e,t)-r,a=Math.PI*r,o=(e,t,n)=>[e+r*Math.cos(n),t+r*Math.sin(n)],s=(n-Math.floor(n))*(4*i+2*a);return t>e?s<i?[r,s]:(s-=i,s<a?o(0,i,s/r):(s-=a,s<2*i?[-r,i-s]:(s-=2*i,s<a?o(0,-i,Math.PI+s/r):(s-=a,[r,-i+s])))):s<a/2?o(i,0,s/r):(s-=a/2,s<2*i?[i-s,r]:(s-=2*i,s<a?o(-i,0,Math.PI/2+s/r):(s-=a,s<2*i?[-i+s,-r]:(s-=2*i,o(i,0,Math.PI*3/2+s/r)))))},zn=new Map,Bn=720,Vn=e=>{let t=Math.round(Math.log(Math.max(.001,e))*200),n=zn.get(t);if(n)return n;let r=Math.exp(t/200),i=new Float64Array(721);for(let e=1;e<=Bn;e+=1){let t=(e-.5)/Bn*2*Math.PI;i[e]=i[e-1]+Math.hypot(Math.sin(t),r*Math.cos(t))}n=new Float64Array(73);let a=0;for(let e=0;e<=72;e+=1){let t=e/72*i[Bn];for(;a<719&&i[a+1]<t;)a+=1;let r=i[a+1]-i[a]||1;n[e]=(a+(t-i[a])/r)/Bn*2*Math.PI}return zn.size>512&&zn.clear(),zn.set(t,n),n},Hn=(e,t,n)=>{let r=Vn(t/Math.max(e,1e-6)),i=(n-Math.floor(n))*72,a=Math.floor(i),o=r[a]+(r[a+1]-r[a])*(i-a);return[e*Math.cos(o),t*Math.sin(o)]},Un=(e,t,n)=>{let r=t/120,i=n/120;return e(120*Math.cos(i)*Math.sin(r),120*Math.sin(i))},Wn=(e,t,n)=>{let r=t<0?`Left`:`Right`,a=(e[`lid${r}`]??0)*n,o=(e[`lidTilt${r}`]??0)*n,s=(e[`lowerLid${r}`]??0)*n;return!a&&!o&&!s?{}:{lid:a,lidSlope:-t*Math.tan(i(Math.max(-80,Math.min(80,o)))),lowerLid:s}},Gn=e=>!!(e.lid||e.lidSlope||e.lowerLid),Kn=(e,t)=>{let n=e.height/2,r=-n+(e.lid??0)*e.height+(e.lidSlope??0)*t,i=n-(e.lowerLid??0)*e.height;return r<i?[r,i]:[(r+i)/2,(r+i)/2]},qn=e=>{if(!Gn(e))return[0,0];let[t,n]=Kn(e,0);return[0,(Math.max(t,-e.height/2)+Math.min(n,e.height/2))/2]},Jn=(e,t)=>{let n=t/72,r=Rn(e.width/2,e.height/2,n),i=e.ellipse??0,a=i>0?Hn(e.width/2,e.height/2,n):r,o=i>=1?a[0]:r[0]+(a[0]-r[0])*i,s=i>=1?a[1]:r[1]+(a[1]-r[1])*i;if(!Gn(e))return[o,s];let[c,l]=Kn(e,o);return[o,Math.min(Math.max(s,c),l)]},Yn=(e,t,n)=>{if(!e.bend||e.width<=0)return[t,n];let r=Math.min(e.width,e.height)/2,i=Math.max(0,e.width/2-r),a=Math.max(-i,Math.min(i,t)),o=-8*e.bend*a/e.width,s=Math.hypot(1,o),c=e.bend*e.width*(1-(2*a/e.width)**2);return[a+(t-a-o*n)/s,c+(o*(t-a)+n)/s]},Xn=(e,t,n)=>{let[r,i]=Jn(e,t),[a,o]=qn(e),[s,c]=Yn(e,a+(r-a)*n,o+(i-o)*n);return[e.centerX+s*e.cos-c*e.sin,e.centerY+s*e.sin+c*e.cos]},Zn=.01,Qn=e=>e.width>.5&&e.height>.5,$n=(e,t,n,r=0,o)=>{let s=m(e),c=s?d(a(e),s,r,o):a(e),l=e.marks?e.glyphWeight??1:0,f=e.eyeShape===`ellipse`?1-l+(l>0?l*u(a(e)):0):0,p=e.glyphHandover,h=p!==void 0&&p<.5?(p*2)**2:0,g=p!==void 0&&p>=.5?1-(2-p*2)**2:1;return c.map((r,a)=>{let o=i(r.angle),s=(r.height>5?5+(r.height-5)*t:r.height)*(1-h)*g;return{width:Math.max(r.width*g,Zn),height:Math.max(s,Zn),centerX:r.x+n.x,centerY:r.y+n.y,cos:Math.cos(o),sin:Math.sin(o),ellipse:a<2?f:0,...r.bend===void 0?{}:{bend:r.bend},...a<2?Wn(e,a===0?-1:1,1-l):{}}})},er=16,tr=new WeakMap,nr=(e,t)=>{let n=tr.get(e);n||tr.set(e,n=new Map);let r=n.get(t);return r?n.delete(t):(r=t.map(([t,n])=>e(t,n)),n.size>=er&&n.delete(n.keys().next().value)),n.set(t,r),r},rr=22,ir=2**rr,ar=4,or=1e-12,sr=(e,t,n,r,i,a)=>{let o=e.length,s=e=>{let t=r(e),{point:n,normal:o}=t,s=o[2]-i/620*(o[0]*n[0]+o[1]*n[1]),c=a?Math.min(s,a(n)):s;return{...t,facing:c}},c=(e,t)=>s(n(e,t)),l=nr(n,e).map(s),u=t,d=c(...t),f=Math.max(1e-6,Math.max(...l.map(e=>e.facing))*.1);if(d.facing<=f){let t=e.filter((e,t)=>l[t].facing>f);if(t.length&&(u=[t.reduce((e,t)=>e+t[0],0)/t.length,t.reduce((e,t)=>e+t[1],0)/t.length],d=c(...u),d.facing<=f)){let t=0;for(let e=1;e<o;e++)l[e].facing>l[t].facing&&(t=e);u=e[t],d=l[t]}}if(d.facing<=0)return{points:l.map(()=>d.point),visible:!1};let p=ke(n)||ke(a),m=l.map((t,n)=>{if(t.facing>0)return t.point;let r=e[n],i=e=>c(u[0]+(r[0]-u[0])*e,u[1]+(r[1]-u[1])*e),a=p||Math.abs(t.facing)<or||Math.abs(d.facing)<or;if(!a){let e=e=>{let t=i(e/ir);return Math.abs(t.facing)<or&&(a=!0),t},n=0,r=ir,o=d.facing,s=t.facing,c=d;for(let t=0;t<ar&&!a;t++){let t=(n+r)/2,i=e(t);i.facing>0?(n=t,c=i,o=i.facing):(r=t,s=i.facing)}let l=n,u=o,f=r,p=s,m=NaN,h=0;for(;r-n>1&&!a;){let t=l+(f-l)*u/(u-p);t>n&&t<r||(t=n+(r-n)*o/(o-s));let i=Math.floor(t);i>n||(i=n+1),i<r||(i=r-1),i>n&&i<r||(i=Math.floor((n+r)/2));let a=Math.abs(t-m)<4;m=t;let d=e(i);if(l=f,u=p,f=i,p=d.facing,d.facing>0){if(n=i,c=d,o=d.facing,h>0&&(s*=.5),h=1,a&&r-n>1){let t=e(n+1);t.facing>0?(n+=1,c=t,o=t.facing):(r=n+1,s=t.facing)}}else if(r=i,s=d.facing,h<0&&(o*=.5),h=-1,a&&r-n>1){let t=e(r-1);t.facing>0?(n=r-1,c=t,o=t.facing):(--r,s=t.facing)}}if(!a)return c.point}let o=0,s=1,l=d;for(let e=0;e<rr;e++){let e=(o+s)/2,t=i(e);t.facing>0?(o=e,l=t):s=e}return l.point}),h=0;return m.forEach((e,t)=>{let n=m[(t+1)%o];h+=e[0]*n[1]-n[0]*e[1]}),{points:m,visible:Math.abs(h)>1e-6}},cr=new Map,lr=new WeakMap,ur=e=>{let t=lr.get(e);return t||(t=(t,n)=>Un(e,t,n),ke(e)&&Oe(t),lr.set(e,t)),t},dr=(e,t,n,r,i=1,a,o=!1)=>{let s=Math.floor(72/i),c=[e.centerX,e.centerY,e.width,e.height,e.cos,e.sin,e.ellipse??0,e.lid??0,e.lidSlope??0,e.lowerLid??0,e.bend??0,i].join(`|`),l=cr.get(c);l||(l=Array.from({length:s},(t,n)=>Xn(e,n*i,1)),cr.size>=128&&cr.delete(cr.keys().next().value),cr.set(c,l));let u=sr(l,Xn(e,0,0),o?t:ur(t),n,r,a);return{...u,visible:Qn(e)&&u.visible}},fr=new Float32Array(192),pr=(e,t=1)=>{for(let t=0;t<192;t+=1){if(e[t]>0)continue;let n=1,r=1;for(;e[(t-n+192)%192]===0&&n<192;)n+=1;for(;e[(t+r)%192]===0&&r<192;)r+=1;let i=e[(t-n+192)%192],a=e[(t+r)%192];e[t]=i+(a-i)*n/(n+r)}if(t===0)return e;fr.set(e);for(let n=0;n<192;n+=1){let r=e=>fr[(n+e+192)%192],i=(r(-2)+4*r(-1)+6*r(0)+4*r(1)+r(2))/16;e[n]=t===1?i:r(0)+(i-r(0))*t}return e},mr=(e,...t)=>!!e.geometry?.hull&&S(`grid`).sculptProfile(e,...t),hr=(...e)=>S(`grid`).convexProfile(...e),gr=(...e)=>S(`grid`).starProfile(...e),_r=e=>{let t=e.squash;return t?{scaleX:t.x,scaleY:t.y,x:e.offset.x,y:e.offset.y+(1-t.y)*t.base}:{scaleX:1,scaleY:1,x:e.offset.x,y:e.offset.y}},vr=e=>Math.round(e*1e3)/1e3,yr=e=>{let{scaleX:t,scaleY:n,x:r,y:i}=_r(e);return e.squash?`matrix(${vr(t)} 0 0 ${vr(n)} ${vr(r)} ${vr(i)})`:`translate(${r} ${i})`},br=new Map,xr=new Map,Sr=new Map,Cr=new Map,wr=(e,t)=>`${e.map(e=>Math.round(e*1e5)).join(`,`)}|${t}`,Tr=(e,t)=>Math.max(...e)+Math.hypot(t[0],t[1]),Er=(e,t,n,r,i,a,o=1)=>{i=wn(i,o);let s=0,c=Math.floor(e.length/i.step);J.reserve(c);let l=t=>{let o=new Float64Array(c*2);for(let l=0;l<c;l+=1){let[c,u]=e[l*i.step];X(n,r,c,u,a?t-a(c,u):t),o[l*2]=Y[0],o[l*2+1]=Y[1],s=Math.max(s,Math.hypot(Y[0],Y[1]))}return o},u=l(t),d=l(-t),f=e=>{let t=0;for(let n=0;n<e.length/2;n+=1){let r=(n+1)%(e.length/2);t+=e[n*2]*e[r*2+1]-e[r*2]*e[n*2+1]}return t},p=e=>{let t=f(e)<0;for(let n=0;n<c;n+=1){let r=t?c-1-n:n;J.set(n,e[r*2],e[r*2+1])}return J.closed(c,i,o)};if(i.curve===`spline`&&o===1){let e=f(u)<0?-1:1;for(let t=0;t<c;t+=1){let n=(t-1+c)%c*2,r=(t+1)%c*2,i=e*(u[r+1]-u[n+1]),a=e*(u[n]-u[r]),o=i*(d[t*2]-u[t*2])+a*(d[t*2+1]-u[t*2+1])>0?d:u;J.set(t,o[t*2],o[t*2+1])}return{path:J.closed(c,i,o),reach:s}}let m=cn(i.precision),h=``,g=new Float64Array(8);for(let e=0;e<c;e+=1){let t=(e+1)%c;g.set([u[e*2],u[e*2+1],u[t*2],u[t*2+1],d[t*2],d[t*2+1],d[e*2],d[e*2+1]]);let n=f(g)<0?[3,2,1,0]:[0,1,2,3];h+=n.map((e,t)=>`${t?`L`:`M`}${m(g[e*2])} ${m(g[e*2+1])}`).join(``),h+=`Z`}return{path:`${p(u)}${p(d)}${h}`,reach:s}},Dr=(e,t,n,r=1)=>{n=wn(n,r);let i=Math.floor(192/n.step);for(let r=0;r<i;r+=1){let i=r*n.step;J.set(r,t[0]+Math.cos(i*q)*e[i],t[1]+Math.sin(i*q)*e[i])}return J.closed(i,n,r)},Or=class{bodyKey=``;bodySamples=null;current=new Float32Array(192);from=new Float32Array(192);shown=new Float32Array(192);head={m:new Float64Array(9),t:[0,0,0]};morphStartedAt=-1;pieceLayer;detail;reducedMotion=!1;constructor(e={}){this.detail={...Cn,...e}}setDetail(e){this.detail={...Cn,...e}}project(e,r,i=`frame`){let o=i!==`pieces`,{orientation:s,expression:c}=e.pose,l=c.perspective;n(s,this.head.m),this.head.t=t(this.head.m,e.surface.rotationCenter);let d=X(this.head,l,0,0,0),f=[d[0],d[1]],p=e.surface.outlineRounding??1,m=wn(this.detail,p),g=We(e.surface);g!==this.bodyKey&&(this.bodySamples=null,this.bodyKey&&this.from.set(this.shown),this.morphStartedAt=this.bodyKey&&!this.reducedMotion?r:-1,this.bodyKey=g);let _=wr(s,l),v=`${g}|${_}`,y=o?Q(br,v):void 0;y?this.current.set(y):o&&(an(e.surface,this.head,l,f,this.current)?pr(this.current,0):mr(e.surface,this.head,l,f,this.current)||(e.surface.type!==`blob`||!w(e.surface).lobes&&$t(B(e.surface))?Ln(e.surface,this.head,l,f,this.current)?pr(this.current,p):hr(this.bodySamples??=Fn(e.surface),1,this.head,l,f,this.current,p):gr(this.bodySamples??=Fn(e.surface),this.head,l,f,this.current,p)),Z(br,v,Float32Array.from(this.current)));let b=this.morphStartedAt<0?1:Math.min(1,(r-this.morphStartedAt)/450),x=Tn(b);for(let e=0;o&&e<192;e+=1)this.shown[e]=b>=1?this.current[e]:this.from[e]+(this.current[e]-this.from[e])*x;b>=1&&(this.morphStartedAt=-1);let ee=je(e.surface),C=ee&&o?Er(ee,e.surface.depth/2,this.head,l,{...this.detail,step:1},Ne(e.surface),p):void 0,T=C?C.reach:o?Tr(this.shown,f):0,ne=`${this.detail.precision},${this.detail.step},${this.detail.curve}${this.detail.compoundOutline===!1?`,sampled`:``}`,E,D=()=>E??=S(`depth`).createProjectedDepthField(e.surface,this.head,l),O=[...en(e.surface),...e.bodyNodes],k=O.length?(this.pieceLayer??=S(`pieces`).createPieceLayer({plateFaces:Er,profileReach:Tr,profilePath:Dr,finishProfile:pr,convexProfile:hr,starProfile:gr,sculptProfile:mr})).project({input:e,head:this.head,detail:this.detail,perspective:l,parts:O,key:g,pose:_,detailKey:ne,headDepth:D,bodyDetail:m,rounding:p,bodyOutline:v}):void 0,A=k?.placed??[];T=Math.max(T,k?.reach??0);let re=Le(e.surface),j=z(e.surface),ie=j?Re(e.surface):0,M=e.surface.type===`blob`?w(e.surface).sockets:void 0,ae=M?re:qe(e.surface),oe=M?qe(e.surface,M.plane*e.surface.width):void 0,se=Je(e.surface).sample,{m:N}=this.head,ce=Ae(e.surface),le=e.surface.type===`blob`?w(e.surface).lobes:void 0,ue=M?it(e.surface)??Math.max(e.surface.depth,M.plane*e.surface.width):void 0,de=le&&!ae?S(`sculpt`).lobeVisibility(le,this.head,l,e.surface,D):void 0,fe=i===`frame`?$n(c,e.blink,{x:e.eyeOffset.x+ce.x,y:e.eyeOffset.y+ce.y},e.time,e.loop).map((t,n)=>{let r=M&&n<2&&(!c.marks||c.glyphHandover!==void 0&&h(c.glyphHandover)||u(a(c))>0),i=M&&r?S(`sockets`).filledSocketLayout(t,M,e.surface.width,n):void 0,o=M&&r?S(`sockets`).createSocketVisibility(M,e.surface.width,ue,this.head,l,(t,n)=>at(e.surface,t,n),n):void 0,s=dr(i??t,r&&oe?oe:se,({point:e,normal:t})=>(X(this.head,l,e[0],e[1],e[2]),{point:[Y[0],Y[1],Y[2]],normal:[N[0]*t[0]+N[1]*t[1]+N[2]*t[2],N[3]*t[0]+N[4]*t[1]+N[5]*t[2],N[6]*t[0]+N[7]*t[1]+N[8]*t[2]]}),l,this.detail.step,M?o:de,ae!==void 0);return s.points.forEach((e,t)=>{J.set(t,e[0],e[1])}),{path:J.closed(s.points.length,this.detail),visible:s.visible}}):[],P,F=`${v}|${ne}`,pe=i===`frame`||i===`pieces`&&N[8]>0&&A.some(e=>e.behind),me=j&&pe?Q(Cr,F):void 0;if(me!==void 0)P=me??void 0;else if(pe){if(j&&ie===0){let e=m.step===1?j:j.filter((e,t)=>t%m.step===0),t=sr(e,[e.reduce((e,t)=>e+t[0],0)/e.length,e.reduce((e,t)=>e+t[1],0)/e.length],re,({point:e,normal:t})=>(X(this.head,l,e[0],e[1],e[2]),{point:[Y[0],Y[1],Y[2]],normal:[N[0]*t[0]+N[1]*t[1]+N[2]*t[2],N[3]*t[0]+N[4]*t[1]+N[5]*t[2],N[6]*t[0]+N[7]*t[1]+N[8]*t[2]]}),l);if(t.visible){J.reserve(t.points.length),t.points.forEach((e,t)=>{J.set(t,e[0],e[1])});let e=J.closed(t.points.length,m,p);P={opening:e,plate:e}}Z(Cr,F,P??null)}else if(j){let e=Math.floor(j.length/m.step);J.reserve(e);let t=new Float64Array(e),n=new Float64Array(e),r=new Float64Array(e),i=(i,a)=>{for(let a=0;a<e;a+=1){let[e,o]=j[a*m.step],{point:s,normal:c}=i(e,o);X(this.head,l,s[0],s[1],s[2]),t[a]=Y[0],n[a]=Y[1],r[a]=N[6]*c[0]+N[7]*c[1]+N[8]*c[2]}for(let r=0;r<e;r+=1)J.set(r,t[r],n[r]);return a&&J.closeHorizon(e,r),{path:J.closed(e,m,p),visible:on(r)}},a=i(re,!0);a.visible&&(P={opening:a.path,plate:i(se,!1).path}),Z(Cr,F,P??null)}}let he=e.bodySquash.x!==1||e.bodySquash.y!==1,I;if(!o)I=``;else if(C)I=C.path;else if(b<1)I=Dr(this.shown,f,m,p);else{let t=`${v}|${ne}`,n=Q(xr,t);if(n!==void 0)I=n,T=Math.max(T,Q(Sr,t)??0);else{let n=this.detail.compoundOutline===!1?void 0:te(`union`)?.ellipsoidUnionOutline(e.surface,this.head,l,this.detail.precision);I=n?.path??Dr(this.shown,f,m,p),n&&(T=Math.max(T,n.reach),Z(Sr,t,n.reach)),Z(xr,t,I)}}o&&k?.pigment&&(I=k.pigment());let ge=A.map(e=>P&&N[8]>0&&e.behind?{...e.piece,front:!1}:e.piece);return{frame:{body:I,pieces:ge,eyes:j&&!P?fe.map(e=>({...e,visible:!1})):fe,...P?{face:P}:{},offset:e.bodyOffset,...he?{squash:{...e.bodySquash,base:e.surface.height/2}}:{},reach:(he?T*Math.max(e.bodySquash.x,e.bodySquash.y)+Math.abs(1-e.bodySquash.y)*(e.surface.height/2):T)+Math.hypot(e.bodyOffset.x,e.bodyOffset.y)},morphing:this.morphStartedAt>=0}}},kr={x:0,y:0},Ar=.45,jr=.3,Mr=.25,Nr=(e,t,n,r)=>{let i=c(e,t,n),a=r?.(t);return{x:(i?.x??0)+(a?.x??0),z:(i?.z??0)+(a?.z??0),offsetY:i?.offsetY??0,flap:i?.flap??0}},Pr=(e,t,n)=>e>=0?n*Math.tanh(e/n):-t*Math.tanh(e/-t),Fr=({range:e=[-90,90]},t)=>Pr(t,e[0],e[1]),Ir=(e,t,n,r,i)=>{let{lag:a,swing:o=0,range:s=[-90,90]}=e,[c,l]=s,u=r(i),d=r(i-a),f=r(i-2*a),p=e=>e(d)-e(u)+Mr*(e(d)-e(f));return Pr(n+(u.flap+t*Ar*p(e=>e.z)+jr*p(e=>e.x)-o*p(e=>e.offsetY)),c,l)},Lr=(e,t,n,r,i)=>{let a=e.filter(e=>e.follow);if(!a.length)return;let o=c(t,n??0,r),s={};for(let e of a){let a=e.follow,l=e.position[0]<0?1:-1;if(a.hinge){let c=t.pieces?.[e.id]?.turn??0,u=l*c,d=l*(n===void 0||!o&&!i?Fr(a,u+(o?.flap??0)):Ir(a,l,u,e=>Nr(t,e,r,i),n))-c;d!==0&&(s[e.id]={turn:d});continue}if(!o||n===void 0)continue;let{lag:u,swing:d=0,loose:f=!1}=a,p=c(t,n-u,r),m=c(t,n-2*u,r),h=e=>e(p)-e(o)+.25*(e(p)-e(m));s[e.id]={turn:h(e=>e.z)-d*l*h(e=>e.offsetY),...f?{x:h(e=>e.offsetX),y:h(e=>e.offsetY)}:{}}}return Object.keys(s).length?s:void 0},Rr=(e,t)=>{if(!t)return e;let n={...e};for(let[e,r]of Object.entries(t)){let t=n[e]??{};n[e]={...t,turn:(t.turn??0)+(r.turn??0),x:(t.x??0)+(r.x??0),y:(t.y??0)+(r.y??0)}}return n},zr=e=>{let t=e.time??0,n=e.bodyOffset??kr,{pose:i,offset:a,squash:s}=r(e.pose,t,e.loop),c=e.bodySquash??l;return{pose:i,surface:e.surface,bodyNodes:o(e.bodyNodes,Rr(e.pose.expression.pieces,Lr(e.bodyNodes,e.pose.expression,e.time,e.loop,e.headAt))),blink:e.blink??1,eyeOffset:e.eyeOffset??kr,bodyOffset:{x:n.x+a.x,y:n.y+a.y},bodySquash:s===l?c:{x:c.x*s.x,y:c.y*s.y},time:t,...e.loop===void 0?{}:{loop:e.loop}}};function Br(e){let t=new Or,n=!!z(e.body.primary),r=0,i,a=!e.body.nodes.some(e=>e.follow);return(o,c=192,l=!1)=>{let u=c>=192?0:c>=96?1:2;u!==r&&(i=void 0,r=u,t.setDetail({precision:r===0?2:1,step:r===2?2:1}));let{expression:d,eyeOffset:f,bodyOffset:m,blink:h,time:g,half:v}=o,y=i;return l&&a&&y?(y.reach+=Math.hypot(m.x,m.y)-Math.hypot(y.offset.x,y.offset.y),y.offset={...m}):(y=t.project(zr({surface:e.body.primary,bodyNodes:e.body.nodes,pose:_(s(d,e.eyes)),eyeOffset:f,bodyOffset:m,blink:h,time:g}),g).frame,i=y),{frame:y,colors:p(d,e.colors),transform:yr(y),half:v,windowed:n}}}var Vr=e({activateGeometry:()=>Gr,prepareGeometry:()=>Jr}),Hr={sculpt:()=>import(`./sculpt-CVu30RFI.js`).then(e=>e.sculpt),sockets:()=>import(`./sockets-n9lhW9hh.js`).then(e=>e.sockets),paint:()=>import(`./paint-T6aENHGJ.js`).then(e=>e.paint),depth:()=>import(`./depth-Cj2wTnRA.js`).then(e=>e.depth)},Ur=new Map;function Wr(e){let t=Ur.get(e);if(t)return t;let n=Hr[e]().catch(t=>{throw Ur.delete(e),t});return Ur.set(e,n),n}async function Gr(e,t){let n=rn(e);(e.body.primary.geometry?.radialDepthPower||e.body.primary.geometry?.relief||e.body.nodes.some(e=>e.surface.geometry?.relief))&&!n.includes(`sculpt`)&&n.push(`sculpt`);let r=Object.freeze(Object.assign({},...await Promise.all([...n.map(Wr),t?import(`./sampledProfiles-Bnlm4vdZ.js`).then(e=>({grid:e})):void 0]))),i=0;return Object.freeze({capabilities:Object.freeze(n),createProjector(){let t=Br(e);i++;let n=!1;return Object.assign((...e)=>{if(n)throw Error(`Projector disposed.`);return ee(r,()=>t(...e))},{dispose(){if(!n&&(n=!0,--i===0)){r.sculpt?.releaseRelief(e.body.primary);for(let t of e.body.nodes)r.sculpt?.releaseRelief(t.surface)}}})}})}var Kr=new WeakMap,qr=new WeakMap;function Jr(e,t=!1){let n=f(e,t),r=n?Kr:qr,i=r.get(e);if(i)return i;let a=Gr(g(e),n).catch(t=>{throw r.delete(e),t});return r.set(e,a),a}export{Xt as A,$t as C,je as D,B as E,I as F,T as I,w as L,Ue as M,Oe as N,Ne as O,Ee as P,S as R,cn as S,Ze as T,Q as _,In as a,vn as b,Fn as c,Sn as d,wn as f,xn as g,bn as h,sr as i,We as j,Fe as k,q as l,X as m,Jr as n,Ln as o,J as p,pr as r,En as s,Vr as t,yn as u,Z as v,tn as w,K as x,Y as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./mount-
|
|
1
|
+
import{n as e}from"./mount-Do-RWK8s.js";import{i as t}from"./reader-JcTNbEkh.js";function n(n){let r,i=n.querySelector(`svg`)??void 0,a=!0,o,s;function c(){if(r?.state!==void 0)throw new t(`MIEN_CONTROLLED`,`/state`,`Remove the state prop to call commands.`)}return{get handle(){return s},update(t,d=!1){try{if(!r||t.avatar!==r.avatar){let u=o,d=a?i:void 0;a=!1;let f=e(n,t.avatar,{...t,onError:e=>l(e)},d);d||i?.remove(),i=void 0,u?.destroy(),o=f,f.on(`sequenceend`,e=>r?.onSequenceEnd?.(e));let{destroy:p,...m}=f;s={...m,set(e){c(),f.set(e)},expression(e){c(),f.expression(e)},play(e){return c(),f.play(e)}}}else if(t.state!==void 0&&t.state!==r.state&&o.set(t.state),t.motion!==r.motion&&o.setMotion(t.motion),t.label!==r.label){let e=n.querySelector(`svg`);for(let t of[`role`,`aria-label`,`aria-hidden`])e.removeAttribute(t);t.label?(e.setAttribute(`role`,`img`),e.setAttribute(`aria-label`,t.label)):e.setAttribute(`aria-hidden`,`true`)}r=t}catch(e){if(d)throw e;(t.onError??u)(e)}},destroy(){o?.destroy(),o=void 0,r=void 0}};function l(e){(r?.onError??u)(e)}function u(e){n.ownerDocument.defaultView?.console.error(e)}}export{n as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime-DK3Fl9T5.js";import{S as t,b as n,v as r,x as i,y as a}from"./playback-BeRsJu6S.js";import{A as o,C as s,D as c,E as l,I as u,L as d,N as f,O as p,R as m,S as h,T as g,_,b as v,c as y,d as b,f as x,g as S,h as C,i as w,j as T,k as E,l as D,m as O,o as k,p as A,u as j,v as M,w as N,x as P,y as F}from"./activate-CCUqRQyO.js";var I=e({clipHostedMarkOutline:()=>ie,combineProjectedDepthFields:()=>H,createProjectedDepthField:()=>z,deferProjectedDepthField:()=>V,visibleSolidContours:()=>G,visibleSolidOutline:()=>re}),L=1e-5,R=(e,t,n,r,i)=>{let[a,o,s,c]=r,l=64/Math.max(L,s-a),u=64/Math.max(L,c-o),d=e=>Math.max(0,Math.min(63,Math.floor((e-a)*l))),f=e=>Math.max(0,Math.min(63,Math.floor((e-o)*u))),p=Math.max(1,(t-1)*(n-1)),m=new Float64Array(p*12),h=new Uint8Array(p*4),g=new Uint32Array(4096),_=0,v=(t,n,r)=>{let i=t*4,a=n*4,o=r*4,s=e[i],c=e[i+1],l=e[a],u=e[a+1],v=e[o],y=e[o+1],b=l-s,x=u-c,S=v-s,C=y-c,w=b*C-x*S;if(!Number.isFinite(w)||w<1e-9)return;if(_===p){p*=2;let e=new Float64Array(p*12);e.set(m),m=e;let t=new Uint8Array(p*4);t.set(h),h=t}let T=_++,E=1/w,D=C*E,O=-S*E,k=-s*D-c*O,A=-x*E,j=b*E,M=-s*A-c*j,N=T*12;m[N]=D,m[N+1]=O,m[N+2]=k,m[N+3]=A,m[N+4]=j,m[N+5]=M;let P=e[i+3],F=e[a+3],I=e[o+3],L=F-P,R=I-P;m[N+6]=D*L+A*R,m[N+7]=O*L+j*R,m[N+8]=P+k*L+M*R;let ee=e[i+2]*P,z=e[a+2]*F-ee,B=e[o+2]*I-ee;m[N+9]=D*z+A*B,m[N+10]=O*z+j*B,m[N+11]=ee+k*z+M*B;let V=d(Math.min(s,l,v)),H=d(Math.max(s,l,v)),U=f(Math.min(c,u,y)),W=f(Math.max(c,u,y));h[T*4]=V,h[T*4+1]=H,h[T*4+2]=U,h[T*4+3]=W;for(let e=U;e<=W;e++)for(let t=V;t<=H;t++)g[e*64+t]++};for(let e=0;e<n-1;e++)for(let n=0;n<t-1;n++){let r=e*t+n,i=r+1,a=r+t,o=a+1;v(r,i,a),v(i,o,a)}let y=new Uint32Array(g.length+1);for(let e=0;e<g.length;e++)y[e+1]=y[e]+g[e];let b=new Uint32Array(y[g.length]),x=y.slice(0,g.length);for(let e=0;e<_;e++){let t=e*4;for(let n=h[t+2];n<=h[t+3];n++)for(let r=h[t];r<=h[t+1];r++){let t=n*64+r;b[x[t]]=e*12,x[t]++}}return{bounds:r,get points(){return i()},depthAt:(e,t)=>{if(e<a||e>s||t<o||t>c)return-1/0;let n=f(t)*64+d(e),r=-1/0;for(let i=y[n];i<y[n+1];i++){let n=b[i],a=m[n]*e+m[n+1]*t+m[n+2],o=m[n+3]*e+m[n+4]*t+m[n+5];if(a<-1e-5||o<-1e-5||a+o>1.00001)continue;let s=m[n+6]*e+m[n+7]*t+m[n+8],c=(m[n+9]*e+m[n+10]*t+m[n+11])/s;r=Math.max(r,c)}return r}}},ee=(e,t,n)=>{let{m:r,t:i}=t,a,o=r[0],s=r[1],c=r[2],l=r[3],u=r[4],d=r[5],f=r[6],p=r[7],m=r[8],h=o*(u*m-d*p)-s*(l*m-d*f)+c*(l*p-u*f),g=[u*m-d*p,c*p-s*m,s*d-c*u,d*f-l*m,o*m-c*f,c*l-o*d,l*p-u*f,s*f-o*p,o*u-s*l].map(e=>e/h),_=[e.width/2,e.height/2,e.depth/2],v=[0,1,2].map(e=>g.slice(e*3,e*3+3).map(t=>t/_[e])),b=620-n*i[2],x=[r[6]*_[0],r[7]*_[1],r[8]*_[2]],S=x.reduce((e,t)=>e+t*t,0),C=e=>{let t=[0,1,2].map(t=>r[e*3+t]*_[t]),a=t.reduce((e,t)=>e+t*t,0),o=t.reduce((e,t,n)=>e+t*x[n],0),s=b*b-n*n*S,c=-2*(b*i[e]+n*o),l=i[e]*i[e]-a,u=Math.sqrt(Math.max(0,c*c-4*s*l));return[620*(-c-u)/(2*s),620*(-c+u)/(2*s)]},w=C(0),T=C(1);return{bounds:[w[0],T[0],w[1],T[1]],get points(){if(a)return a;let t=y(e);a=[];for(let e=0;e<t.positions.length;e+=3){let o=t.positions[e],s=t.positions[e+1],c=t.positions[e+2],l=r[0]*o+r[1]*s+r[2]*c+i[0],u=r[3]*o+r[4]*s+r[5]*c+i[1],d=r[6]*o+r[7]*s+r[8]*c+i[2],f=620/(620-n*d);a.push([l*f,u*f,d])}return a},depthAt:(e,t)=>{let r=e-i[0],a=t-i[1],o=-i[2],s=-n*e/620,c=-n*t/620,l=0,u=0,d=-1;for(let e of v){let t=e[0]*r+e[1]*a+e[2]*o,n=e[0]*s+e[1]*c+e[2];l+=n*n,u+=2*t*n,d+=t*t}let f=u*u-4*l*d;return f<0?-1/0:(-u+Math.sqrt(f))/(2*l)}}},z=(e,t,n,r=1)=>{if(!(`positions`in e)&&e.type===`sphere`)return ee(e,t,n);let i=`positions`in e?e:y(e),a=96/r+1,o=48/r+1,s=new Float64Array(a*o*4),c=0,l,{m:u,t:d}=t,f=1/0,p=1/0,m=-1/0,h=-1/0;for(let e=0;e<=48;e+=r)for(let t=0;t<=96;t+=r){let r=(e*97+t)*3,a=i.positions[r],o=i.positions[r+1],l=i.positions[r+2],g=u[0]*a+u[1]*o+u[2]*l+d[0],_=u[3]*a+u[4]*o+u[5]*l+d[1],v=u[6]*a+u[7]*o+u[8]*l+d[2],y=620/(620-n*v),b=g*y,x=_*y;s[c]=b,s[c+1]=x,s[c+2]=v,s[c+3]=y,c+=4,f=Math.min(f,b),m=Math.max(m,b),p=Math.min(p,x),h=Math.max(h,x)}return R(s,a,o,[f,p,m,h],()=>{if(l)return l;l=[];for(let e=0;e<c;e+=4)l.push([s[e],s[e+1],s[e+2]]);return l})},B=new WeakMap,V=(e,t,n,r)=>{let i=B.get(e);if(!i){let t=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0];for(let r=0;r<e.positions.length;r+=3)for(let i=0;i<3;i++)t[i]=Math.min(t[i],e.positions[r+i]),n[i]=Math.max(n[i],e.positions[r+i]);i=[t,n],B.set(e,i)}let{m:a,t:o}=t,s=1/0,c=1/0,l=-1/0,u=-1/0,d=-1/0,f=1/0;for(let e=0;e<8;e++){let t=i[e&1?1:0][0],p=i[e&2?1:0][1],m=i[e&4?1:0][2],h=a[0]*t+a[1]*p+a[2]*m+o[0],g=a[3]*t+a[4]*p+a[5]*m+o[1],_=a[6]*t+a[7]*p+a[8]*m+o[2],v=620-n*_;if(v<=L)return r();let y=620/v;s=Math.min(s,h*y),l=Math.max(l,h*y),c=Math.min(c,g*y),u=Math.max(u,g*y),d=Math.max(d,_),f=Math.min(f,_)}let p=L*Math.max(1,l-s,u-c);s-=p,c-=p,l+=p,u+=p,d+=L*Math.max(1,d-f)*4;let m,h=()=>m??=r(),g=(e,t)=>e>=s&&e<=l&&t>=c&&t<=u;return{bounds:[s,c,l,u],get points(){return h().points},depthAt:(e,t)=>g(e,t)?h().depthAt(e,t):-1/0,occludesDepth:(e,t,n)=>g(e,t)&&d>n&&h().depthAt(e,t)>n}},H=e=>({bounds:[Math.min(...e.map(e=>e.bounds[0])),Math.min(...e.map(e=>e.bounds[1])),Math.max(...e.map(e=>e.bounds[2])),Math.max(...e.map(e=>e.bounds[3]))],points:[],depthAt:(t,n)=>{let r=-1/0;for(let i=0;i<e.length;i+=1)r=Math.max(r,e[i].depthAt(t,n));return r},occludesDepth:(t,n,r)=>{for(let i=0;i<e.length;i+=1){let a=e[i];if(a.occludesDepth?a.occludesDepth(t,n,r):a.depthAt(t,n)>r)return!0}return!1}}),U=e=>Math.abs(e.reduce((t,n,r)=>{let i=e[(r+1)%e.length];return t+n[0]*i[1]-n[1]*i[0]},0))/2,W=(e,t,n,r)=>{let i=e.depthAt(n,r);return Number.isFinite(i)&&!(t.occludesDepth?t.occludesDepth(n,r,i+L):t.depthAt(n,r)>i+L)},te=(e,t,n)=>{let r=!1;for(let i=0,a=n.length-1;i<n.length;a=i++){let o=n[i],s=n[a];o[1]>t!=s[1]>t&&e<(s[0]-o[0])*(t-o[1])/(s[1]-o[1])+o[0]&&(r=!r)}return r},ne=(e,t,n,r,i)=>{let[a,o,s,c]=e,l=s-a,u=c-o,d=[];for(let e=0;e<32;e++)for(let n=0;n<32;n++){let r=a+l*(n+.5)/32,i=o+u*(e+.5)/32;t(r,i)&&d.push([r,i])}if(!d.length)for(let e of r)t(e[0],e[1])&&d.push([e[0],e[1]]);if(!d.length){let e=[(a+s)/2,(o+c)/2,0];return{points:Array.from({length:i},()=>e),visible:!1}}let f=[d.reduce((e,t)=>e+t[0],0)/d.length,d.reduce((e,t)=>e+t[1],0)/d.length],p=t(f[0],f[1])?f:d.reduce((e,t)=>Math.hypot(t[0]-f[0],t[1]-f[1])<Math.hypot(e[0]-f[0],e[1]-f[1])?t:e),m=Math.hypot(l,u),h=Array.from({length:i},(e,r)=>{let a=r*2*Math.PI/i,o=Math.cos(a),s=Math.sin(a),c=0,l=m;for(let e=1;e<=48;e++){let n=m*e/48;if(!t(p[0]+o*n,p[1]+s*n)){l=n;break}c=n}for(let e=0;e<18;e++){let e=(c+l)/2;t(p[0]+o*e,p[1]+s*e)?c=e:l=e}let u=p[0]+o*c,d=p[1]+s*c,f=n(u,d);return[u,d,Number.isFinite(f)?f:0]});return{points:h,visible:U(h)>1e-6,complete:d.every(([e,t])=>{let n=(Math.atan2(t-p[1],e-p[0])/(2*Math.PI)+1)%1*i,r=Math.floor(n),a=h[r],o=h[(r+1)%i];return(o[0]-a[0])*(t-a[1])-(o[1]-a[1])*(e-a[0])>=-1e-5})}},re=(e,t,n=192)=>ne(t.bounds,(n,r)=>W(t,e,n,r),t.depthAt,t.points,n),ie=(e,t,n)=>{if(!e.length)return{points:[],visible:!1};let r=Math.min(...e.map(e=>e[0])),i=Math.max(...e.map(e=>e[0])),a=Math.min(...e.map(e=>e[1])),o=Math.max(...e.map(e=>e[1])),s=[e.reduce((e,t)=>e+t[0],0)/e.length,e.reduce((e,t)=>e+t[1],0)/e.length],c=(e,r)=>W(n,t,e,r);return e.every(e=>c(e[0],e[1]))&&c(s[0],s[1])?{points:[...e],visible:U(e)>1e-6}:ne([r,a,i,o],(t,n)=>te(t,n,e)&&c(t,n),n.depthAt,e,e.length)},G=(e,t,n=80)=>{let[r,i,a,o]=t.bounds,s=Math.max(a-r,o-i)/n;if(!(s>0))return[];let c=r-s,l=i-s,u=Math.ceil((a-r)/s)+2,d=Math.ceil((o-i)/s)+2,f=u+1,p=(n,r)=>W(t,e,n,r),m=new Uint8Array(f*(d+1));for(let e=0;e<=d;e++)for(let t=0;t<=u;t++)m[e*f+t]=+!!p(c+t*s,l+e*s);let h=new Map,g=new Map,_=(e,n,r)=>{let i=`${r?`v`:`h`}${e},${n}`;if(h.has(i))return i;let a=c+n*s,o=l+e*s,u=m[e*f+n]===1,d=0,g=1;for(let e=0;e<14;e++){let e=(d+g)/2;p(a+(r?0:e*s),o+(r?e*s:0))===u?d=e:g=e}let _=u?d:g,v=a+(r?0:_*s),y=o+(r?_*s:0),b=t.depthAt(v,y);return h.set(i,[v,y,Number.isFinite(b)?b:0]),i};for(let e=0;e<d;e++)for(let t=0;t<u;t++){let n=e*f+t,r=m[n]+m[n+1]*2+m[n+f+1]*4+m[n+f]*8;if(r===0||r===15)continue;let i=n=>n===0?_(e,t,!1):n===1?_(e,t+1,!0):n===2?_(e+1,t,!1):_(e,t,!0),a;switch(r){case 1:a=[[0,3]];break;case 2:a=[[1,0]];break;case 3:a=[[1,3]];break;case 4:a=[[2,1]];break;case 5:a=p(c+(t+.5)*s,l+(e+.5)*s)?[[0,1],[2,3]]:[[0,3],[2,1]];break;case 6:a=[[2,0]];break;case 7:a=[[2,3]];break;case 8:a=[[3,2]];break;case 9:a=[[0,2]];break;case 10:a=p(c+(t+.5)*s,l+(e+.5)*s)?[[1,2],[3,0]]:[[1,0],[3,2]];break;case 11:a=[[1,2]];break;case 12:a=[[3,1]];break;case 13:a=[[0,1]];break;default:a=[[3,0]]}for(let e of a)g.set(i(e[0]),i(e[1]))}let v=[],y=new Set;for(let e of g.keys()){if(y.has(e))continue;let n=[],r=e;for(;r!==void 0&&!y.has(r);)y.add(r),n.push(h.get(r)),r=g.get(r);if(r===e&&n.length>2&&U(n)>1e-6){let e=(n,r,i)=>{if(i>=8)return[];let a=r[0]-n[0],o=r[1]-n[1],c=Math.hypot(a,o);if(c<s*.005)return[];for(let l of[.5,.25,.75]){let u=n[0]+a*l,d=n[1]+o*l,f=-o/c,m=a/c,h=p(u,d),g=h?-1:1,_=s*(h?.005:.001);if(p(u+f*g*_,d+m*g*_)!==h)continue;let v=s/8;for(;v<=s*2&&p(u+f*g*v,d+m*g*v)===h;)v+=s/8;if(v>s*2)continue;let y=0,b=v;for(let e=0;e<14;e++){let e=(y+b)/2;p(u+f*g*e,d+m*g*e)===h?y=e:b=e}let x=h?y:b,S=u+f*g*x,C=d+m*g*x,w=[S,C,t.depthAt(S,C)];return[...e(n,w,i+1),w,...e(w,r,i+1)]}return[]};v.push(n.flatMap((t,r)=>[t,...e(t,n[(r+1)%n.length],0)]))}}if(!v.length){let n=re(e,t);n.visible&&v.push(n.points)}return v},ae=e({findInsetHost:()=>ce,forgetInsetHosts:()=>oe,insetHostCoversCenter:()=>se}),K=new Map,oe=()=>K.clear(),se=(e,r)=>{let i=t(a(...e.rotation.map(n))),o=r.position[0]-e.position[0],s=r.position[1]-e.position[1],c=r.position[2]-e.position[2],l=i[0]*o+i[3]*s+i[6]*c,u=i[1]*o+i[4]*s+i[7]*c,d=T(e.surface),f=K.get(d);return f&&(K.delete(d),K.set(d,f)),f||(f=z(e.surface,{m:new Float64Array([1,0,0,0,1,0,0,0,1]),t:[0,0,0]},0),K.set(d,f),K.size>8&&K.delete(K.keys().next().value)),Number.isFinite(f.depthAt(l,u))},ce=(e,t)=>{if(t.paintOn)return e.find(e=>e.id===t.paintOn);let n,r=1/0;for(let i of e){if(i.paintOn||i.color===`eyes`||i.color===`mark`||!se(i,t))continue;let e=Math.hypot(i.position[0]-t.position[0],i.position[1]-t.position[1],i.position[2]-t.position[2]);e<r&&(r=e,n=i)}return n},le=new Map,ue=new Map;function q(){le.clear(),ue.clear()}function de({plateFaces:e,profileReach:o,profilePath:u,finishProfile:f,convexProfile:b,starProfile:S,sculptProfile:C}){let w=new Map,E=new Float32Array(192),D=new Float64Array(9);return{project({input:j,head:F,detail:I,perspective:L,parts:R,key:ee,pose:z,detailKey:B,headDepth:V,bodyDetail:H,rounding:U,bodyOutline:W}){let te=0,ne=new Set,re=e=>{let t=i(F.m,e);return[t[0]+F.t[0],t[1]+F.t[1],t[2]+F.t[2]]},ie=(e,t)=>{P(t.piece.path);let n=t.carrier?.depthField?{...t,carrier:{...t.carrier,depthField:void 0,depthClipped:!0}}:t;return M(le,e,n),te=Math.max(te,t.reach),t},G=R.filter(e=>!e.paintOn&&e.color!==`eyes`&&e.color!==`mark`),ae=new Set(R.flatMap(e=>e.paintOn?[e.paintOn]:[])),K=N(j.surface,R),oe=new Map(R.map(e=>[e.id,`${e.id}|${T(e.surface)}|${e.position.join(`,`)}|${e.rotation.join(`,`)}|${+!!e.fixed}|${+!!e.rooted}|${e.color??`body`}|${e.paintOn??``}`])),se=G.map(e=>oe.get(e.id)).join(`;`),ce=new Map,q=e=>{let i=t(a(...e.rotation.map(n))),o=e.fixed===!0,s=o?v(j.surface.width/2,L):1,c=o?v(j.surface.height/2,L):1;return o?{m:Float64Array.from(i,(e,t)=>t<3?e*s:t<6?e*c:e),t:[e.position[0]*s,e.position[1]*c,e.position[2]]}:{m:r(F.m,i),t:re(e.position)}},de=(e,t)=>{let n=ce.get(e.id);if(n)return n;let r=t??q(e),i=m(`depth`).createProjectedDepthField(e.surface,r,e.fixed?0:L);return ce.set(e.id,i),i},J=new Map,Y=e=>{let t=J.get(e.id);if(!t){let n=q(e);t=m(`depth`).deferProjectedDepthField(y(e.surface),n,e.fixed?0:L,()=>de(e,n)),J.set(e.id,t)}return t},X=(e,t=!1)=>m(`depth`).combineProjectedDepthFields([V(),...G.filter(n=>n.id!==e.id&&(t||n.color!==e.color)).map(e=>Y(e))]),fe=m(`pieces`).onHosts(R,R.map(i=>{if(ne.add(i.id),i.paintOn)return{key:`${oe.get(i.id)}|${ee}|${z}|${B}|${se}|paint:${i.paintOn}`,depth:0,behind:!1,facing:1,reach:0,piece:{id:i.id,color:i.color,path:`M0 0Z`,front:!1}};let M=i.surface.outlineRounding??1,N=x(I,M),P=T(i.surface),R=K&&i.color===`accent`,V=!R&&(i.color===`accent`||i.color===`secondary`||i.color===`tertiary`||ae.has(i.id))&&!i.fixed&&!i.rooted,H=`${oe.get(i.id)}|${ee}|${z}|${B}|${K?`pigment`:``}${V?`|${se}`:``}`,U=_(le,H);if(U)return te=Math.max(te,U.reach),U;let W=w.get(i.id);(!W||W.key!==P)&&(W={key:P},w.set(i.id,W)),t(a(n(i.rotation[0]),n(i.rotation[1]),n(i.rotation[2])),D);let G=i.fixed===!0,ce=G?v(j.surface.width/2,L):1,ue=G?v(j.surface.height/2,L):1,q=G?{m:Float64Array.from(D,(e,t)=>t<3?e*ce:t<6?e*ue:e),t:[i.position[0]*ce,i.position[1]*ue,i.position[2]]}:{m:r(F.m,D),t:re(i.position)},J=G?0:L,Y=!G&&g(j.surface,i.surface,i.position,D.slice(6,9)),fe=G?q.t:O(F,L,i.position[0],i.position[1],i.position[2]),Z=[fe[0],fe[1]];if(V){let e=de(i,q),t=X(i),n=m(`depth`).visibleSolidOutline(t,e,Math.floor(192/N.step)),r=n.complete===!1,a=r?m(`depth`).visibleSolidContours(t,e):[n.points],o=a.map(e=>{if(A.reserve(e.length),e.forEach((e,t)=>{A.set(t,e[0],e[1])}),!r)return A.closed(e.length,N,M);let t=h(I.precision+1),n=`M${t(e[0][0])} ${t(e[0][1])}`;return e.forEach((r,i)=>{let a=e[(i+1)%e.length];n+=`C${t(r[0])} ${t(r[1])} ${t(a[0])} ${t(a[1])} ${t(a[0])} ${t(a[1])}`}),`${n}Z`}).join(``)||`M0 0Z`,s=a.reduce((e,t)=>t.reduce((e,t)=>Math.max(e,Math.hypot(t[0],t[1])),e),0);return ie(H,{key:H,depth:q.t[2],behind:Y,facing:q.m[8],reach:s,carrier:{part:i,placement:q,perspective:J,depthField:e},piece:{id:i.id,color:i.color,path:o,front:!0}})}let pe=c(i.surface);if(pe){let t=e(pe,i.surface.depth/2,q,J,{...I,step:I.curve===`spline`?I.step*2:I.step},p(i.surface),M),n=Math.max(i.surface.width,i.surface.height,i.surface.depth)/2;return ie(H,{key:H,facing:q.m[8],...i.color===`eyes`||i.color===`mark`?{}:{carrier:{part:i,placement:q,perspective:J}},depth:q.t[2],behind:Y,piece:{id:i.id,...i.color?{color:i.color}:{},path:t.path,front:!R&&!i.rooted&&q.t[2]>n*.1},reach:t.reach})}let me=Z;i.color===`eyes`?me=m(`pieces`).hollowProfile(i.surface,q,J,E):C(i.surface,q,J,Z,E)||(i.surface.type===`blob`&&(d(i.surface).lobes||!s(l(i.surface)))?S(W.samples??=y(i.surface),q,J,Z,E,M):k(i.surface,q,J,Z,E)?f(E,M):b(W.samples??=y(i.surface),2,q,J,Z,E,M));let he=Math.max(i.surface.width,i.surface.height,i.surface.depth)/2;return ie(H,{key:H,facing:q.m[8],...i.color===`eyes`||i.color===`mark`?{}:{carrier:{part:i,placement:q,perspective:J}},depth:q.t[2],behind:Y,piece:{id:i.id,...i.color?{color:i.color}:{},path:u(E,me,{...I,step:I.curve===`spline`?I.step*4:I.step},M),front:!R&&!i.rooted&&q.t[2]>he*.1},reach:o(E,me),outline:{center:me,profile:Float32Array.from(E)}})}),I,{part:{id:`primary`,surface:j.surface,position:[0,0,0],rotation:[0,0,0]},placement:F,perspective:L},e=>X(e,!0),de,e=>{let t=G.filter(t=>{if(t.id===e.id)return!1;if(K&&t.color===`accent`||t.rooted)return!0;if(t.color===`accent`||t.color===`secondary`||t.color===`tertiary`||ae.has(t.id))return!1;let n=Math.max(t.surface.width,t.surface.height,t.surface.depth)/2;return q(t).t[2]<=n*.1});return t.length?m(`depth`).combineProjectedDepthFields(t.map(Y)):void 0}).sort((e,t)=>e.depth-t.depth);w.forEach((e,t)=>{ne.has(t)||w.delete(t)});function Z(){let e,t=`${W}|${B}|${se}|pigment`,n=_(ue,t);if(n!==void 0)e=n;else{let n=m(`depth`).combineProjectedDepthFields(G.filter(e=>e.color===`accent`).map(e=>Y(e))),r=m(`depth`).visibleSolidOutline(n,V(),Math.floor(192/H.step));e=(r.complete===!1?m(`depth`).visibleSolidContours(n,V()):[r.points]).map(e=>{if(!e.length)return``;if(A.reserve(e.length),e.forEach((e,t)=>{A.set(t,e[0],e[1])}),r.complete!==!1)return A.closed(e.length,H,U);let t=h(I.precision+1),n=`M${t(e[0][0])} ${t(e[0][1])}`;return e.forEach((r,i)=>{let a=e[(i+1)%e.length];n+=`C${t(r[0])} ${t(r[1])} ${t(a[0])} ${t(a[1])} ${t(a[0])} ${t(a[1])}`}),`${n}Z`}).join(``)||`M0 0Z`,M(ue,t,e)}return e}return{placed:fe,reach:te,pigment:K?Z:void 0}}}}var J=e({createPieceLayer:()=>de,forgetPieceOutlines:()=>q,hollowProfile:()=>Oe,onHosts:()=>ye}),Y=.06,X=[.5,.25],fe=(e,t,n,r,i=1)=>{r=x(r,i);let a=Math.min(1,Math.max(0,(n-X[1])/(X[0]-X[1]))),o=0;for(let e=0;e<192;e+=1)o+=t.profile[e]/192;let s=o*Y,c=Math.floor(192/r.step);for(let n=0;n<c;n+=1){let i=n*r.step,o=e.center[0]+Math.cos(i*D)*e.profile[i],c=e.center[1]+Math.sin(i*D)*e.profile[i],l=o-t.center[0],u=c-t.center[1],d=Math.hypot(l,u),f=(Math.atan2(u,l)+j)%j/D,p=Math.floor(f),m=f-p,h=t.profile[p%192]*(1-m)+t.profile[(p+1)%192]*m,g=Math.max(h-s,0);d>g&&d>0&&(o=t.center[0]+l*g/d,c=t.center[1]+u*g/d),A.set(n,e.center[0]+(o-e.center[0])*a,e.center[1]+(c-e.center[1])*a)}return A.closed(c,r,i)},Z=new WeakMap,pe=new WeakMap,me=new Float64Array(192),he=new Float64Array(192),ge=new Float64Array(192),_e=(e,r,i,s)=>{let c=e.surface.outlineRounding??1;i=x(i,c);let d=t(a(...r.part.rotation.map(n))),p=[0,1,2].map(t=>e.position[t]-r.part.position[t]),h=d[0]*p[0]+d[3]*p[1]+d[6]*p[2],g=d[1]*p[0]+d[4]*p[1]+d[7]*p[2],_=n(e.rotation[2]-r.part.rotation[2]),v=Math.floor(192/i.step),y=`${T(r.part.surface)}|${r.part.position.join(`,`)}|${r.part.rotation.join(`,`)}|${T(e.surface)}|${e.position.join(`,`)}|${e.rotation[2]}|${v}`,b=Z.get(e);if(b?.key!==y){let t=r.part.surface;b={key:y,face:Array.from({length:v},(t,n)=>{let r=n/v*j,i=e.surface.type===`blob`?u(l(e.surface),r):1,a=Math.cos(r)*e.surface.width*i/2,o=Math.sin(r)*e.surface.height*i/2;return[h+a*Math.cos(_)-o*Math.sin(_),g+a*Math.sin(_)+o*Math.cos(_)]}),front:E(t)?f((e,n)=>o(t,e,n)):(e,n)=>o(t,e,n)},Z.set(e,b)}let S=b.face,C=r.placement.m,D=w(S,[h,g],b.front,({point:e,normal:t})=>(O(r.placement,r.perspective,e[0],e[1],e[2]),{point:[F[0],F[1],F[2]],normal:[C[0]*t[0]+C[1]*t[1]+C[2]*t[2],C[3]*t[0]+C[4]*t[1]+C[5]*t[2],C[6]*t[0]+C[7]*t[1]+C[8]*t[2]]}),r.perspective);return(s&&r.depthField?m(`depth`).clipHostedMarkOutline(D.points,s,r.depthField):D).points.forEach((e,t)=>{A.set(t,e[0],e[1])}),A.closed(v,i,c)},ve=(e,r,i,s)=>{let c=e.surface.outlineRounding??1;if(i=x(i,c),e.surface.depth===0)return _e(e,r,i,s);let d=new Float64Array(9);t(a(n(r.part.rotation[0]),n(r.part.rotation[1]),n(r.part.rotation[2])),d);let f=[0,1,2].map(t=>e.position[t]-r.part.position[t]),p=d[0]*f[0]+d[3]*f[1]+d[6]*f[2],m=d[1]*f[0]+d[4]*f[1]+d[7]*f[2],h=n(e.rotation[2]),{m:g}=r.placement,_=Math.floor(192/i.step),v=`${T(r.part.surface)}|${r.part.position.join(`,`)}|${r.part.rotation.join(`,`)}|${T(e.surface)}|${e.position.join(`,`)}|${e.rotation[2]}|${_}`,y=pe.get(e);y?.key!==v&&(y={key:v,samples:Array.from({length:_},(t,n)=>{let i=n/_*j,a=e.surface.type===`blob`?u(l(e.surface),i):1,s=Math.cos(i)*e.surface.width*a/2,c=Math.sin(i)*e.surface.height*a/2;return o(r.part.surface,p+s*Math.cos(h)-c*Math.sin(h),m+s*Math.sin(h)+c*Math.cos(h))})},pe.set(e,y));let b=y.samples,S=e=>{let t=0;for(let n=0;n<_;n+=1){let{point:i,normal:a}=b[n];O(r.placement,r.perspective,i[0],i[1],i[2]-e),me[n]=F[0],he[n]=F[1],ge[n]=g[6]*a[0]+g[7]*a[1]+g[8]*a[2],t+=ge[n]}for(let e=0;e<_;e+=1)A.set(e,me[e],he[e]);A.closeHorizon(_,ge);let n=[];for(let e=0;e<_;e+=1)n.push(A.point(e));return{closed:n,facing:t/_}},C=S(0),w=De(S(e.surface.depth).closed,C.closed),E=new Float32Array(192),k=Pe(w.length>=3?w:C.closed,E),M=w.length>=3?Math.min(1,Math.max(0,(C.facing-X[1])/(X[0]-X[1]))):0;for(let e=0;e<_;e+=1){let t=e*i.step;A.set(e,k[0]+Math.cos(t*D)*E[t]*M,k[1]+Math.sin(t*D)*E[t]*M)}return A.closed(_,i,c)},ye=(e,t,n,r,i,a,o)=>t.map((s,c)=>{let l=e[c];if(!l.paintOn&&l.color!==`eyes`&&l.color!==`mark`)return s;let u=m(`hosts`).findInsetHost(e,l),d=u?t[e.indexOf(u)]:void 0;if(!d&&l.paintOn)return{...s,piece:{...s.piece,path:`M0 0Z`,front:!1}};if(!d)return{...s,behind:!1,piece:{...s.piece,front:!0,path:l.color===`mark`?_e(l,r,n):ve(l,r,n)}};let f=s.piece.path,p=d,h=`${s.key}|${p.key}`;return p.carrier?(f=_(b,h)??(()=>{let e=p.carrier;if(l.paintOn){let t=p.piece.front?i(e.part):o(e.part);return m(`paint`).wrappedPaintContours(l,e,a(e.part),t).map(e=>(A.reserve(e.length),e.forEach((e,t)=>{A.set(t,e[0],e[1])}),A.closed(e.length,n,l.surface.outlineRounding??1))).join(``)||`M0 0Z`}let t=e.depthField!==void 0||e.depthClipped===!0,r=t?{...e,depthField:e.depthField??a(e.part)}:e,s=t?i(e.part):void 0;return l.color===`mark`?_e(l,r,n,s):ve(l,r,n,s)})(),M(b,h,f)):s.outline&&p.outline&&(f=_(b,h)??fe(s.outline,p.outline,s.facing,n,l.surface.outlineRounding??1),M(b,h,f)),{...s,depth:p.depth+.001,behind:p.behind,piece:{...s.piece,path:f,front:p.piece.front}}}),be=64,xe=Array.from({length:be},()=>[0,0]),Se=Array.from({length:be},()=>[0,0]),Q=new Float64Array(512),$=new Float64Array(512),Ce=new Float64Array(512),we=new Float64Array(512),Te=new Float64Array(512),Ee=e=>{if(e<=Q.length)return;let t=Math.max(e,Q.length*2),n=e=>{let n=new Float64Array(t);return n.set(e),n};Q=n(Q),$=n($),Ce=new Float64Array(t),we=new Float64Array(t),Te=new Float64Array(t)},De=(e,t)=>{let n=0;for(let e=0;e<t.length;e+=1){let r=t[e],i=t[(e+1)%t.length];n+=r[0]*i[1]-i[0]*r[1]}let r=Math.sign(n)||1,i=e.length;Ee(i);for(let t=0;t<i;t+=1)Q[t]=e[t][0],$[t]=e[t][1];for(let e=0;e<t.length&&i;e+=1){let n=t[e][0],a=t[e][1],o=t[(e+1)%t.length],s=o[0]-n,c=o[1]-a;for(let e=0;e<i;e+=1)Te[e]=r*(s*($[e]-a)-c*(Q[e]-n));Ee(i*2);let l=0;for(let e=0;e<i;e+=1){let t=(e+i-1)%i,n=Te[e],r=Te[t];if(n>=0?r<0:r>=0){let i=r/(r-n);Ce[l]=Q[t]+(Q[e]-Q[t])*i,we[l]=$[t]+($[e]-$[t])*i,l+=1}n>=0&&(Ce[l]=Q[e],we[l]=$[e],l+=1)}[Q,Ce]=[Ce,Q],[$,we]=[we,$],i=l}let a=Array(i);for(let e=0;e<i;e+=1)a[e]=[Q[e],$[e]];return a},Oe=(e,t,n,r)=>{let i=(r,i)=>{for(let a=0;a<be;a+=1){let o=a/be*j;O(t,n,Math.cos(o)*e.width/2,Math.sin(o)*e.height/2,r),i[a][0]=F[0],i[a][1]=F[1]}};i(e.depth/2,xe),i(-e.depth/2,Se);let a=De(Se,xe);if(!a.length){let e=Pe(xe,r);return r.fill(0),e}return Pe(a,r)},ke=new Float64Array(512),Ae=new Float64Array(512),je=new Float64Array(512),Me=new Float64Array(512),Ne=new Float64Array(512),Pe=(e,t)=>{let n=0,r=0;for(let t of e)n+=t[0]/e.length,r+=t[1]/e.length;let i=e.length;i>ke.length&&(ke=new Float64Array(i),Ae=new Float64Array(i),je=new Float64Array(i),Me=new Float64Array(i),Ne=new Float64Array(i));for(let t=0;t<i;t+=1){let a=e[t],o=e[(t+1)%i],s=o[0]-a[0],c=o[1]-a[1],l=a[0]-n,u=a[1]-r;ke[t]=s,Ae[t]=c,je[t]=l,Me[t]=u,Ne[t]=l*c-u*s}for(let e=0;e<192;e+=1){let n=C[e],r=S[e],a=0;for(let e=0;e<i;e+=1){let t=ke[e],i=n*Ae[e]-r*t;if(Math.abs(i)<1e-9)continue;let o=Ne[e]/i,s=(je[e]*r-Me[e]*n)/i;o>a&&s>=-1e-6&&s<=1+1e-6&&(a=o)}t[e]=a}return[n,r]},Fe={depth:I,hosts:ae,pieces:J};export{Fe as depth};
|
|
1
|
+
import{t as e}from"./rolldown-runtime-DK3Fl9T5.js";import{S as t,b as n,v as r,x as i,y as a}from"./playback-a02m3NQr.js";import{A as o,C as s,D as c,E as l,I as u,L as d,N as f,O as p,R as m,S as h,T as g,_,b as v,c as y,d as b,f as x,g as S,h as C,i as w,j as T,k as E,l as D,m as O,o as k,p as A,u as j,v as M,w as N,x as P,y as F}from"./activate-C16bLpUy.js";var I=e({clipHostedMarkOutline:()=>ie,combineProjectedDepthFields:()=>H,createProjectedDepthField:()=>z,deferProjectedDepthField:()=>V,visibleSolidContours:()=>G,visibleSolidOutline:()=>re}),L=1e-5,R=(e,t,n,r,i)=>{let[a,o,s,c]=r,l=64/Math.max(L,s-a),u=64/Math.max(L,c-o),d=e=>Math.max(0,Math.min(63,Math.floor((e-a)*l))),f=e=>Math.max(0,Math.min(63,Math.floor((e-o)*u))),p=Math.max(1,(t-1)*(n-1)),m=new Float64Array(p*12),h=new Uint8Array(p*4),g=new Uint32Array(4096),_=0,v=(t,n,r)=>{let i=t*4,a=n*4,o=r*4,s=e[i],c=e[i+1],l=e[a],u=e[a+1],v=e[o],y=e[o+1],b=l-s,x=u-c,S=v-s,C=y-c,w=b*C-x*S;if(!Number.isFinite(w)||w<1e-9)return;if(_===p){p*=2;let e=new Float64Array(p*12);e.set(m),m=e;let t=new Uint8Array(p*4);t.set(h),h=t}let T=_++,E=1/w,D=C*E,O=-S*E,k=-s*D-c*O,A=-x*E,j=b*E,M=-s*A-c*j,N=T*12;m[N]=D,m[N+1]=O,m[N+2]=k,m[N+3]=A,m[N+4]=j,m[N+5]=M;let P=e[i+3],F=e[a+3],I=e[o+3],L=F-P,R=I-P;m[N+6]=D*L+A*R,m[N+7]=O*L+j*R,m[N+8]=P+k*L+M*R;let ee=e[i+2]*P,z=e[a+2]*F-ee,B=e[o+2]*I-ee;m[N+9]=D*z+A*B,m[N+10]=O*z+j*B,m[N+11]=ee+k*z+M*B;let V=d(Math.min(s,l,v)),H=d(Math.max(s,l,v)),U=f(Math.min(c,u,y)),W=f(Math.max(c,u,y));h[T*4]=V,h[T*4+1]=H,h[T*4+2]=U,h[T*4+3]=W;for(let e=U;e<=W;e++)for(let t=V;t<=H;t++)g[e*64+t]++};for(let e=0;e<n-1;e++)for(let n=0;n<t-1;n++){let r=e*t+n,i=r+1,a=r+t,o=a+1;v(r,i,a),v(i,o,a)}let y=new Uint32Array(g.length+1);for(let e=0;e<g.length;e++)y[e+1]=y[e]+g[e];let b=new Uint32Array(y[g.length]),x=y.slice(0,g.length);for(let e=0;e<_;e++){let t=e*4;for(let n=h[t+2];n<=h[t+3];n++)for(let r=h[t];r<=h[t+1];r++){let t=n*64+r;b[x[t]]=e*12,x[t]++}}return{bounds:r,get points(){return i()},depthAt:(e,t)=>{if(e<a||e>s||t<o||t>c)return-1/0;let n=f(t)*64+d(e),r=-1/0;for(let i=y[n];i<y[n+1];i++){let n=b[i],a=m[n]*e+m[n+1]*t+m[n+2],o=m[n+3]*e+m[n+4]*t+m[n+5];if(a<-1e-5||o<-1e-5||a+o>1.00001)continue;let s=m[n+6]*e+m[n+7]*t+m[n+8],c=(m[n+9]*e+m[n+10]*t+m[n+11])/s;r=Math.max(r,c)}return r}}},ee=(e,t,n)=>{let{m:r,t:i}=t,a,o=r[0],s=r[1],c=r[2],l=r[3],u=r[4],d=r[5],f=r[6],p=r[7],m=r[8],h=o*(u*m-d*p)-s*(l*m-d*f)+c*(l*p-u*f),g=[u*m-d*p,c*p-s*m,s*d-c*u,d*f-l*m,o*m-c*f,c*l-o*d,l*p-u*f,s*f-o*p,o*u-s*l].map(e=>e/h),_=[e.width/2,e.height/2,e.depth/2],v=[0,1,2].map(e=>g.slice(e*3,e*3+3).map(t=>t/_[e])),b=620-n*i[2],x=[r[6]*_[0],r[7]*_[1],r[8]*_[2]],S=x.reduce((e,t)=>e+t*t,0),C=e=>{let t=[0,1,2].map(t=>r[e*3+t]*_[t]),a=t.reduce((e,t)=>e+t*t,0),o=t.reduce((e,t,n)=>e+t*x[n],0),s=b*b-n*n*S,c=-2*(b*i[e]+n*o),l=i[e]*i[e]-a,u=Math.sqrt(Math.max(0,c*c-4*s*l));return[620*(-c-u)/(2*s),620*(-c+u)/(2*s)]},w=C(0),T=C(1);return{bounds:[w[0],T[0],w[1],T[1]],get points(){if(a)return a;let t=y(e);a=[];for(let e=0;e<t.positions.length;e+=3){let o=t.positions[e],s=t.positions[e+1],c=t.positions[e+2],l=r[0]*o+r[1]*s+r[2]*c+i[0],u=r[3]*o+r[4]*s+r[5]*c+i[1],d=r[6]*o+r[7]*s+r[8]*c+i[2],f=620/(620-n*d);a.push([l*f,u*f,d])}return a},depthAt:(e,t)=>{let r=e-i[0],a=t-i[1],o=-i[2],s=-n*e/620,c=-n*t/620,l=0,u=0,d=-1;for(let e of v){let t=e[0]*r+e[1]*a+e[2]*o,n=e[0]*s+e[1]*c+e[2];l+=n*n,u+=2*t*n,d+=t*t}let f=u*u-4*l*d;return f<0?-1/0:(-u+Math.sqrt(f))/(2*l)}}},z=(e,t,n,r=1)=>{if(!(`positions`in e)&&e.type===`sphere`)return ee(e,t,n);let i=`positions`in e?e:y(e),a=96/r+1,o=48/r+1,s=new Float64Array(a*o*4),c=0,l,{m:u,t:d}=t,f=1/0,p=1/0,m=-1/0,h=-1/0;for(let e=0;e<=48;e+=r)for(let t=0;t<=96;t+=r){let r=(e*97+t)*3,a=i.positions[r],o=i.positions[r+1],l=i.positions[r+2],g=u[0]*a+u[1]*o+u[2]*l+d[0],_=u[3]*a+u[4]*o+u[5]*l+d[1],v=u[6]*a+u[7]*o+u[8]*l+d[2],y=620/(620-n*v),b=g*y,x=_*y;s[c]=b,s[c+1]=x,s[c+2]=v,s[c+3]=y,c+=4,f=Math.min(f,b),m=Math.max(m,b),p=Math.min(p,x),h=Math.max(h,x)}return R(s,a,o,[f,p,m,h],()=>{if(l)return l;l=[];for(let e=0;e<c;e+=4)l.push([s[e],s[e+1],s[e+2]]);return l})},B=new WeakMap,V=(e,t,n,r)=>{let i=B.get(e);if(!i){let t=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0];for(let r=0;r<e.positions.length;r+=3)for(let i=0;i<3;i++)t[i]=Math.min(t[i],e.positions[r+i]),n[i]=Math.max(n[i],e.positions[r+i]);i=[t,n],B.set(e,i)}let{m:a,t:o}=t,s=1/0,c=1/0,l=-1/0,u=-1/0,d=-1/0,f=1/0;for(let e=0;e<8;e++){let t=i[e&1?1:0][0],p=i[e&2?1:0][1],m=i[e&4?1:0][2],h=a[0]*t+a[1]*p+a[2]*m+o[0],g=a[3]*t+a[4]*p+a[5]*m+o[1],_=a[6]*t+a[7]*p+a[8]*m+o[2],v=620-n*_;if(v<=L)return r();let y=620/v;s=Math.min(s,h*y),l=Math.max(l,h*y),c=Math.min(c,g*y),u=Math.max(u,g*y),d=Math.max(d,_),f=Math.min(f,_)}let p=L*Math.max(1,l-s,u-c);s-=p,c-=p,l+=p,u+=p,d+=L*Math.max(1,d-f)*4;let m,h=()=>m??=r(),g=(e,t)=>e>=s&&e<=l&&t>=c&&t<=u;return{bounds:[s,c,l,u],get points(){return h().points},depthAt:(e,t)=>g(e,t)?h().depthAt(e,t):-1/0,occludesDepth:(e,t,n)=>g(e,t)&&d>n&&h().depthAt(e,t)>n}},H=e=>({bounds:[Math.min(...e.map(e=>e.bounds[0])),Math.min(...e.map(e=>e.bounds[1])),Math.max(...e.map(e=>e.bounds[2])),Math.max(...e.map(e=>e.bounds[3]))],points:[],depthAt:(t,n)=>{let r=-1/0;for(let i=0;i<e.length;i+=1)r=Math.max(r,e[i].depthAt(t,n));return r},occludesDepth:(t,n,r)=>{for(let i=0;i<e.length;i+=1){let a=e[i];if(a.occludesDepth?a.occludesDepth(t,n,r):a.depthAt(t,n)>r)return!0}return!1}}),U=e=>Math.abs(e.reduce((t,n,r)=>{let i=e[(r+1)%e.length];return t+n[0]*i[1]-n[1]*i[0]},0))/2,W=(e,t,n,r)=>{let i=e.depthAt(n,r);return Number.isFinite(i)&&!(t.occludesDepth?t.occludesDepth(n,r,i+L):t.depthAt(n,r)>i+L)},te=(e,t,n)=>{let r=!1;for(let i=0,a=n.length-1;i<n.length;a=i++){let o=n[i],s=n[a];o[1]>t!=s[1]>t&&e<(s[0]-o[0])*(t-o[1])/(s[1]-o[1])+o[0]&&(r=!r)}return r},ne=(e,t,n,r,i)=>{let[a,o,s,c]=e,l=s-a,u=c-o,d=[];for(let e=0;e<32;e++)for(let n=0;n<32;n++){let r=a+l*(n+.5)/32,i=o+u*(e+.5)/32;t(r,i)&&d.push([r,i])}if(!d.length)for(let e of r)t(e[0],e[1])&&d.push([e[0],e[1]]);if(!d.length){let e=[(a+s)/2,(o+c)/2,0];return{points:Array.from({length:i},()=>e),visible:!1}}let f=[d.reduce((e,t)=>e+t[0],0)/d.length,d.reduce((e,t)=>e+t[1],0)/d.length],p=t(f[0],f[1])?f:d.reduce((e,t)=>Math.hypot(t[0]-f[0],t[1]-f[1])<Math.hypot(e[0]-f[0],e[1]-f[1])?t:e),m=Math.hypot(l,u),h=Array.from({length:i},(e,r)=>{let a=r*2*Math.PI/i,o=Math.cos(a),s=Math.sin(a),c=0,l=m;for(let e=1;e<=48;e++){let n=m*e/48;if(!t(p[0]+o*n,p[1]+s*n)){l=n;break}c=n}for(let e=0;e<18;e++){let e=(c+l)/2;t(p[0]+o*e,p[1]+s*e)?c=e:l=e}let u=p[0]+o*c,d=p[1]+s*c,f=n(u,d);return[u,d,Number.isFinite(f)?f:0]});return{points:h,visible:U(h)>1e-6,complete:d.every(([e,t])=>{let n=(Math.atan2(t-p[1],e-p[0])/(2*Math.PI)+1)%1*i,r=Math.floor(n),a=h[r],o=h[(r+1)%i];return(o[0]-a[0])*(t-a[1])-(o[1]-a[1])*(e-a[0])>=-1e-5})}},re=(e,t,n=192)=>ne(t.bounds,(n,r)=>W(t,e,n,r),t.depthAt,t.points,n),ie=(e,t,n)=>{if(!e.length)return{points:[],visible:!1};let r=Math.min(...e.map(e=>e[0])),i=Math.max(...e.map(e=>e[0])),a=Math.min(...e.map(e=>e[1])),o=Math.max(...e.map(e=>e[1])),s=[e.reduce((e,t)=>e+t[0],0)/e.length,e.reduce((e,t)=>e+t[1],0)/e.length],c=(e,r)=>W(n,t,e,r);return e.every(e=>c(e[0],e[1]))&&c(s[0],s[1])?{points:[...e],visible:U(e)>1e-6}:ne([r,a,i,o],(t,n)=>te(t,n,e)&&c(t,n),n.depthAt,e,e.length)},G=(e,t,n=80)=>{let[r,i,a,o]=t.bounds,s=Math.max(a-r,o-i)/n;if(!(s>0))return[];let c=r-s,l=i-s,u=Math.ceil((a-r)/s)+2,d=Math.ceil((o-i)/s)+2,f=u+1,p=(n,r)=>W(t,e,n,r),m=new Uint8Array(f*(d+1));for(let e=0;e<=d;e++)for(let t=0;t<=u;t++)m[e*f+t]=+!!p(c+t*s,l+e*s);let h=new Map,g=new Map,_=(e,n,r)=>{let i=`${r?`v`:`h`}${e},${n}`;if(h.has(i))return i;let a=c+n*s,o=l+e*s,u=m[e*f+n]===1,d=0,g=1;for(let e=0;e<14;e++){let e=(d+g)/2;p(a+(r?0:e*s),o+(r?e*s:0))===u?d=e:g=e}let _=u?d:g,v=a+(r?0:_*s),y=o+(r?_*s:0),b=t.depthAt(v,y);return h.set(i,[v,y,Number.isFinite(b)?b:0]),i};for(let e=0;e<d;e++)for(let t=0;t<u;t++){let n=e*f+t,r=m[n]+m[n+1]*2+m[n+f+1]*4+m[n+f]*8;if(r===0||r===15)continue;let i=n=>n===0?_(e,t,!1):n===1?_(e,t+1,!0):n===2?_(e+1,t,!1):_(e,t,!0),a;switch(r){case 1:a=[[0,3]];break;case 2:a=[[1,0]];break;case 3:a=[[1,3]];break;case 4:a=[[2,1]];break;case 5:a=p(c+(t+.5)*s,l+(e+.5)*s)?[[0,1],[2,3]]:[[0,3],[2,1]];break;case 6:a=[[2,0]];break;case 7:a=[[2,3]];break;case 8:a=[[3,2]];break;case 9:a=[[0,2]];break;case 10:a=p(c+(t+.5)*s,l+(e+.5)*s)?[[1,2],[3,0]]:[[1,0],[3,2]];break;case 11:a=[[1,2]];break;case 12:a=[[3,1]];break;case 13:a=[[0,1]];break;default:a=[[3,0]]}for(let e of a)g.set(i(e[0]),i(e[1]))}let v=[],y=new Set;for(let e of g.keys()){if(y.has(e))continue;let n=[],r=e;for(;r!==void 0&&!y.has(r);)y.add(r),n.push(h.get(r)),r=g.get(r);if(r===e&&n.length>2&&U(n)>1e-6){let e=(n,r,i)=>{if(i>=8)return[];let a=r[0]-n[0],o=r[1]-n[1],c=Math.hypot(a,o);if(c<s*.005)return[];for(let l of[.5,.25,.75]){let u=n[0]+a*l,d=n[1]+o*l,f=-o/c,m=a/c,h=p(u,d),g=h?-1:1,_=s*(h?.005:.001);if(p(u+f*g*_,d+m*g*_)!==h)continue;let v=s/8;for(;v<=s*2&&p(u+f*g*v,d+m*g*v)===h;)v+=s/8;if(v>s*2)continue;let y=0,b=v;for(let e=0;e<14;e++){let e=(y+b)/2;p(u+f*g*e,d+m*g*e)===h?y=e:b=e}let x=h?y:b,S=u+f*g*x,C=d+m*g*x,w=[S,C,t.depthAt(S,C)];return[...e(n,w,i+1),w,...e(w,r,i+1)]}return[]};v.push(n.flatMap((t,r)=>[t,...e(t,n[(r+1)%n.length],0)]))}}if(!v.length){let n=re(e,t);n.visible&&v.push(n.points)}return v},ae=e({findInsetHost:()=>ce,forgetInsetHosts:()=>oe,insetHostCoversCenter:()=>se}),K=new Map,oe=()=>K.clear(),se=(e,r)=>{let i=t(a(...e.rotation.map(n))),o=r.position[0]-e.position[0],s=r.position[1]-e.position[1],c=r.position[2]-e.position[2],l=i[0]*o+i[3]*s+i[6]*c,u=i[1]*o+i[4]*s+i[7]*c,d=T(e.surface),f=K.get(d);return f&&(K.delete(d),K.set(d,f)),f||(f=z(e.surface,{m:new Float64Array([1,0,0,0,1,0,0,0,1]),t:[0,0,0]},0),K.set(d,f),K.size>8&&K.delete(K.keys().next().value)),Number.isFinite(f.depthAt(l,u))},ce=(e,t)=>{if(t.paintOn)return e.find(e=>e.id===t.paintOn);let n,r=1/0;for(let i of e){if(i.paintOn||i.color===`eyes`||i.color===`mark`||!se(i,t))continue;let e=Math.hypot(i.position[0]-t.position[0],i.position[1]-t.position[1],i.position[2]-t.position[2]);e<r&&(r=e,n=i)}return n},le=new Map,ue=new Map;function q(){le.clear(),ue.clear()}function de({plateFaces:e,profileReach:o,profilePath:u,finishProfile:f,convexProfile:b,starProfile:S,sculptProfile:C}){let w=new Map,E=new Float32Array(192),D=new Float64Array(9);return{project({input:j,head:F,detail:I,perspective:L,parts:R,key:ee,pose:z,detailKey:B,headDepth:V,bodyDetail:H,rounding:U,bodyOutline:W}){let te=0,ne=new Set,re=e=>{let t=i(F.m,e);return[t[0]+F.t[0],t[1]+F.t[1],t[2]+F.t[2]]},ie=(e,t)=>{P(t.piece.path);let n=t.carrier?.depthField?{...t,carrier:{...t.carrier,depthField:void 0,depthClipped:!0}}:t;return M(le,e,n),te=Math.max(te,t.reach),t},G=R.filter(e=>!e.paintOn&&e.color!==`eyes`&&e.color!==`mark`),ae=new Set(R.flatMap(e=>e.paintOn?[e.paintOn]:[])),K=N(j.surface,R),oe=new Map(R.map(e=>[e.id,`${e.id}|${T(e.surface)}|${e.position.join(`,`)}|${e.rotation.join(`,`)}|${+!!e.fixed}|${+!!e.rooted}|${e.color??`body`}|${e.paintOn??``}`])),se=G.map(e=>oe.get(e.id)).join(`;`),ce=new Map,q=e=>{let i=t(a(...e.rotation.map(n))),o=e.fixed===!0,s=o?v(j.surface.width/2,L):1,c=o?v(j.surface.height/2,L):1;return o?{m:Float64Array.from(i,(e,t)=>t<3?e*s:t<6?e*c:e),t:[e.position[0]*s,e.position[1]*c,e.position[2]]}:{m:r(F.m,i),t:re(e.position)}},de=(e,t)=>{let n=ce.get(e.id);if(n)return n;let r=t??q(e),i=m(`depth`).createProjectedDepthField(e.surface,r,e.fixed?0:L);return ce.set(e.id,i),i},J=new Map,Y=e=>{let t=J.get(e.id);if(!t){let n=q(e);t=m(`depth`).deferProjectedDepthField(y(e.surface),n,e.fixed?0:L,()=>de(e,n)),J.set(e.id,t)}return t},X=(e,t=!1)=>m(`depth`).combineProjectedDepthFields([V(),...G.filter(n=>n.id!==e.id&&(t||n.color!==e.color)).map(e=>Y(e))]),fe=m(`pieces`).onHosts(R,R.map(i=>{if(ne.add(i.id),i.paintOn)return{key:`${oe.get(i.id)}|${ee}|${z}|${B}|${se}|paint:${i.paintOn}`,depth:0,behind:!1,facing:1,reach:0,piece:{id:i.id,color:i.color,path:`M0 0Z`,front:!1}};let M=i.surface.outlineRounding??1,N=x(I,M),P=T(i.surface),R=K&&i.color===`accent`,V=!R&&(i.color===`accent`||i.color===`secondary`||i.color===`tertiary`||ae.has(i.id))&&!i.fixed&&!i.rooted,H=`${oe.get(i.id)}|${ee}|${z}|${B}|${K?`pigment`:``}${V?`|${se}`:``}`,U=_(le,H);if(U)return te=Math.max(te,U.reach),U;let W=w.get(i.id);(!W||W.key!==P)&&(W={key:P},w.set(i.id,W)),t(a(n(i.rotation[0]),n(i.rotation[1]),n(i.rotation[2])),D);let G=i.fixed===!0,ce=G?v(j.surface.width/2,L):1,ue=G?v(j.surface.height/2,L):1,q=G?{m:Float64Array.from(D,(e,t)=>t<3?e*ce:t<6?e*ue:e),t:[i.position[0]*ce,i.position[1]*ue,i.position[2]]}:{m:r(F.m,D),t:re(i.position)},J=G?0:L,Y=!G&&g(j.surface,i.surface,i.position,D.slice(6,9)),fe=G?q.t:O(F,L,i.position[0],i.position[1],i.position[2]),Z=[fe[0],fe[1]];if(V){let e=de(i,q),t=X(i),n=m(`depth`).visibleSolidOutline(t,e,Math.floor(192/N.step)),r=n.complete===!1,a=r?m(`depth`).visibleSolidContours(t,e):[n.points],o=a.map(e=>{if(A.reserve(e.length),e.forEach((e,t)=>{A.set(t,e[0],e[1])}),!r)return A.closed(e.length,N,M);let t=h(I.precision+1),n=`M${t(e[0][0])} ${t(e[0][1])}`;return e.forEach((r,i)=>{let a=e[(i+1)%e.length];n+=`C${t(r[0])} ${t(r[1])} ${t(a[0])} ${t(a[1])} ${t(a[0])} ${t(a[1])}`}),`${n}Z`}).join(``)||`M0 0Z`,s=a.reduce((e,t)=>t.reduce((e,t)=>Math.max(e,Math.hypot(t[0],t[1])),e),0);return ie(H,{key:H,depth:q.t[2],behind:Y,facing:q.m[8],reach:s,carrier:{part:i,placement:q,perspective:J,depthField:e},piece:{id:i.id,color:i.color,path:o,front:!0}})}let pe=c(i.surface);if(pe){let t=e(pe,i.surface.depth/2,q,J,{...I,step:I.curve===`spline`?I.step*2:I.step},p(i.surface),M),n=Math.max(i.surface.width,i.surface.height,i.surface.depth)/2;return ie(H,{key:H,facing:q.m[8],...i.color===`eyes`||i.color===`mark`?{}:{carrier:{part:i,placement:q,perspective:J}},depth:q.t[2],behind:Y,piece:{id:i.id,...i.color?{color:i.color}:{},path:t.path,front:!R&&!i.rooted&&q.t[2]>n*.1},reach:t.reach})}let me=Z;i.color===`eyes`?me=m(`pieces`).hollowProfile(i.surface,q,J,E):C(i.surface,q,J,Z,E)||(i.surface.type===`blob`&&(d(i.surface).lobes||!s(l(i.surface)))?S(W.samples??=y(i.surface),q,J,Z,E,M):k(i.surface,q,J,Z,E)?f(E,M):b(W.samples??=y(i.surface),2,q,J,Z,E,M));let he=Math.max(i.surface.width,i.surface.height,i.surface.depth)/2;return ie(H,{key:H,facing:q.m[8],...i.color===`eyes`||i.color===`mark`?{}:{carrier:{part:i,placement:q,perspective:J}},depth:q.t[2],behind:Y,piece:{id:i.id,...i.color?{color:i.color}:{},path:u(E,me,{...I,step:I.curve===`spline`?I.step*4:I.step},M),front:!R&&!i.rooted&&q.t[2]>he*.1},reach:o(E,me),outline:{center:me,profile:Float32Array.from(E)}})}),I,{part:{id:`primary`,surface:j.surface,position:[0,0,0],rotation:[0,0,0]},placement:F,perspective:L},e=>X(e,!0),de,e=>{let t=G.filter(t=>{if(t.id===e.id)return!1;if(K&&t.color===`accent`||t.rooted)return!0;if(t.color===`accent`||t.color===`secondary`||t.color===`tertiary`||ae.has(t.id))return!1;let n=Math.max(t.surface.width,t.surface.height,t.surface.depth)/2;return q(t).t[2]<=n*.1});return t.length?m(`depth`).combineProjectedDepthFields(t.map(Y)):void 0}).sort((e,t)=>e.depth-t.depth);w.forEach((e,t)=>{ne.has(t)||w.delete(t)});function Z(){let e,t=`${W}|${B}|${se}|pigment`,n=_(ue,t);if(n!==void 0)e=n;else{let n=m(`depth`).combineProjectedDepthFields(G.filter(e=>e.color===`accent`).map(e=>Y(e))),r=m(`depth`).visibleSolidOutline(n,V(),Math.floor(192/H.step));e=(r.complete===!1?m(`depth`).visibleSolidContours(n,V()):[r.points]).map(e=>{if(!e.length)return``;if(A.reserve(e.length),e.forEach((e,t)=>{A.set(t,e[0],e[1])}),r.complete!==!1)return A.closed(e.length,H,U);let t=h(I.precision+1),n=`M${t(e[0][0])} ${t(e[0][1])}`;return e.forEach((r,i)=>{let a=e[(i+1)%e.length];n+=`C${t(r[0])} ${t(r[1])} ${t(a[0])} ${t(a[1])} ${t(a[0])} ${t(a[1])}`}),`${n}Z`}).join(``)||`M0 0Z`,M(ue,t,e)}return e}return{placed:fe,reach:te,pigment:K?Z:void 0}}}}var J=e({createPieceLayer:()=>de,forgetPieceOutlines:()=>q,hollowProfile:()=>Oe,onHosts:()=>ye}),Y=.06,X=[.5,.25],fe=(e,t,n,r,i=1)=>{r=x(r,i);let a=Math.min(1,Math.max(0,(n-X[1])/(X[0]-X[1]))),o=0;for(let e=0;e<192;e+=1)o+=t.profile[e]/192;let s=o*Y,c=Math.floor(192/r.step);for(let n=0;n<c;n+=1){let i=n*r.step,o=e.center[0]+Math.cos(i*D)*e.profile[i],c=e.center[1]+Math.sin(i*D)*e.profile[i],l=o-t.center[0],u=c-t.center[1],d=Math.hypot(l,u),f=(Math.atan2(u,l)+j)%j/D,p=Math.floor(f),m=f-p,h=t.profile[p%192]*(1-m)+t.profile[(p+1)%192]*m,g=Math.max(h-s,0);d>g&&d>0&&(o=t.center[0]+l*g/d,c=t.center[1]+u*g/d),A.set(n,e.center[0]+(o-e.center[0])*a,e.center[1]+(c-e.center[1])*a)}return A.closed(c,r,i)},Z=new WeakMap,pe=new WeakMap,me=new Float64Array(192),he=new Float64Array(192),ge=new Float64Array(192),_e=(e,r,i,s)=>{let c=e.surface.outlineRounding??1;i=x(i,c);let d=t(a(...r.part.rotation.map(n))),p=[0,1,2].map(t=>e.position[t]-r.part.position[t]),h=d[0]*p[0]+d[3]*p[1]+d[6]*p[2],g=d[1]*p[0]+d[4]*p[1]+d[7]*p[2],_=n(e.rotation[2]-r.part.rotation[2]),v=Math.floor(192/i.step),y=`${T(r.part.surface)}|${r.part.position.join(`,`)}|${r.part.rotation.join(`,`)}|${T(e.surface)}|${e.position.join(`,`)}|${e.rotation[2]}|${v}`,b=Z.get(e);if(b?.key!==y){let t=r.part.surface;b={key:y,face:Array.from({length:v},(t,n)=>{let r=n/v*j,i=e.surface.type===`blob`?u(l(e.surface),r):1,a=Math.cos(r)*e.surface.width*i/2,o=Math.sin(r)*e.surface.height*i/2;return[h+a*Math.cos(_)-o*Math.sin(_),g+a*Math.sin(_)+o*Math.cos(_)]}),front:E(t)?f((e,n)=>o(t,e,n)):(e,n)=>o(t,e,n)},Z.set(e,b)}let S=b.face,C=r.placement.m,D=w(S,[h,g],b.front,({point:e,normal:t})=>(O(r.placement,r.perspective,e[0],e[1],e[2]),{point:[F[0],F[1],F[2]],normal:[C[0]*t[0]+C[1]*t[1]+C[2]*t[2],C[3]*t[0]+C[4]*t[1]+C[5]*t[2],C[6]*t[0]+C[7]*t[1]+C[8]*t[2]]}),r.perspective);return(s&&r.depthField?m(`depth`).clipHostedMarkOutline(D.points,s,r.depthField):D).points.forEach((e,t)=>{A.set(t,e[0],e[1])}),A.closed(v,i,c)},ve=(e,r,i,s)=>{let c=e.surface.outlineRounding??1;if(i=x(i,c),e.surface.depth===0)return _e(e,r,i,s);let d=new Float64Array(9);t(a(n(r.part.rotation[0]),n(r.part.rotation[1]),n(r.part.rotation[2])),d);let f=[0,1,2].map(t=>e.position[t]-r.part.position[t]),p=d[0]*f[0]+d[3]*f[1]+d[6]*f[2],m=d[1]*f[0]+d[4]*f[1]+d[7]*f[2],h=n(e.rotation[2]),{m:g}=r.placement,_=Math.floor(192/i.step),v=`${T(r.part.surface)}|${r.part.position.join(`,`)}|${r.part.rotation.join(`,`)}|${T(e.surface)}|${e.position.join(`,`)}|${e.rotation[2]}|${_}`,y=pe.get(e);y?.key!==v&&(y={key:v,samples:Array.from({length:_},(t,n)=>{let i=n/_*j,a=e.surface.type===`blob`?u(l(e.surface),i):1,s=Math.cos(i)*e.surface.width*a/2,c=Math.sin(i)*e.surface.height*a/2;return o(r.part.surface,p+s*Math.cos(h)-c*Math.sin(h),m+s*Math.sin(h)+c*Math.cos(h))})},pe.set(e,y));let b=y.samples,S=e=>{let t=0;for(let n=0;n<_;n+=1){let{point:i,normal:a}=b[n];O(r.placement,r.perspective,i[0],i[1],i[2]-e),me[n]=F[0],he[n]=F[1],ge[n]=g[6]*a[0]+g[7]*a[1]+g[8]*a[2],t+=ge[n]}for(let e=0;e<_;e+=1)A.set(e,me[e],he[e]);A.closeHorizon(_,ge);let n=[];for(let e=0;e<_;e+=1)n.push(A.point(e));return{closed:n,facing:t/_}},C=S(0),w=De(S(e.surface.depth).closed,C.closed),E=new Float32Array(192),k=Pe(w.length>=3?w:C.closed,E),M=w.length>=3?Math.min(1,Math.max(0,(C.facing-X[1])/(X[0]-X[1]))):0;for(let e=0;e<_;e+=1){let t=e*i.step;A.set(e,k[0]+Math.cos(t*D)*E[t]*M,k[1]+Math.sin(t*D)*E[t]*M)}return A.closed(_,i,c)},ye=(e,t,n,r,i,a,o)=>t.map((s,c)=>{let l=e[c];if(!l.paintOn&&l.color!==`eyes`&&l.color!==`mark`)return s;let u=m(`hosts`).findInsetHost(e,l),d=u?t[e.indexOf(u)]:void 0;if(!d&&l.paintOn)return{...s,piece:{...s.piece,path:`M0 0Z`,front:!1}};if(!d)return{...s,behind:!1,piece:{...s.piece,front:!0,path:l.color===`mark`?_e(l,r,n):ve(l,r,n)}};let f=s.piece.path,p=d,h=`${s.key}|${p.key}`;return p.carrier?(f=_(b,h)??(()=>{let e=p.carrier;if(l.paintOn){let t=p.piece.front?i(e.part):o(e.part);return m(`paint`).wrappedPaintContours(l,e,a(e.part),t).map(e=>(A.reserve(e.length),e.forEach((e,t)=>{A.set(t,e[0],e[1])}),A.closed(e.length,n,l.surface.outlineRounding??1))).join(``)||`M0 0Z`}let t=e.depthField!==void 0||e.depthClipped===!0,r=t?{...e,depthField:e.depthField??a(e.part)}:e,s=t?i(e.part):void 0;return l.color===`mark`?_e(l,r,n,s):ve(l,r,n,s)})(),M(b,h,f)):s.outline&&p.outline&&(f=_(b,h)??fe(s.outline,p.outline,s.facing,n,l.surface.outlineRounding??1),M(b,h,f)),{...s,depth:p.depth+.001,behind:p.behind,piece:{...s.piece,path:f,front:p.piece.front}}}),be=64,xe=Array.from({length:be},()=>[0,0]),Se=Array.from({length:be},()=>[0,0]),Q=new Float64Array(512),$=new Float64Array(512),Ce=new Float64Array(512),we=new Float64Array(512),Te=new Float64Array(512),Ee=e=>{if(e<=Q.length)return;let t=Math.max(e,Q.length*2),n=e=>{let n=new Float64Array(t);return n.set(e),n};Q=n(Q),$=n($),Ce=new Float64Array(t),we=new Float64Array(t),Te=new Float64Array(t)},De=(e,t)=>{let n=0;for(let e=0;e<t.length;e+=1){let r=t[e],i=t[(e+1)%t.length];n+=r[0]*i[1]-i[0]*r[1]}let r=Math.sign(n)||1,i=e.length;Ee(i);for(let t=0;t<i;t+=1)Q[t]=e[t][0],$[t]=e[t][1];for(let e=0;e<t.length&&i;e+=1){let n=t[e][0],a=t[e][1],o=t[(e+1)%t.length],s=o[0]-n,c=o[1]-a;for(let e=0;e<i;e+=1)Te[e]=r*(s*($[e]-a)-c*(Q[e]-n));Ee(i*2);let l=0;for(let e=0;e<i;e+=1){let t=(e+i-1)%i,n=Te[e],r=Te[t];if(n>=0?r<0:r>=0){let i=r/(r-n);Ce[l]=Q[t]+(Q[e]-Q[t])*i,we[l]=$[t]+($[e]-$[t])*i,l+=1}n>=0&&(Ce[l]=Q[e],we[l]=$[e],l+=1)}[Q,Ce]=[Ce,Q],[$,we]=[we,$],i=l}let a=Array(i);for(let e=0;e<i;e+=1)a[e]=[Q[e],$[e]];return a},Oe=(e,t,n,r)=>{let i=(r,i)=>{for(let a=0;a<be;a+=1){let o=a/be*j;O(t,n,Math.cos(o)*e.width/2,Math.sin(o)*e.height/2,r),i[a][0]=F[0],i[a][1]=F[1]}};i(e.depth/2,xe),i(-e.depth/2,Se);let a=De(Se,xe);if(!a.length){let e=Pe(xe,r);return r.fill(0),e}return Pe(a,r)},ke=new Float64Array(512),Ae=new Float64Array(512),je=new Float64Array(512),Me=new Float64Array(512),Ne=new Float64Array(512),Pe=(e,t)=>{let n=0,r=0;for(let t of e)n+=t[0]/e.length,r+=t[1]/e.length;let i=e.length;i>ke.length&&(ke=new Float64Array(i),Ae=new Float64Array(i),je=new Float64Array(i),Me=new Float64Array(i),Ne=new Float64Array(i));for(let t=0;t<i;t+=1){let a=e[t],o=e[(t+1)%i],s=o[0]-a[0],c=o[1]-a[1],l=a[0]-n,u=a[1]-r;ke[t]=s,Ae[t]=c,je[t]=l,Me[t]=u,Ne[t]=l*c-u*s}for(let e=0;e<192;e+=1){let n=C[e],r=S[e],a=0;for(let e=0;e<i;e+=1){let t=ke[e],i=n*Ae[e]-r*t;if(Math.abs(i)<1e-9)continue;let o=Ne[e]/i,s=(je[e]*r-Me[e]*n)/i;o>a&&s>=-1e-6&&s<=1+1e-6&&(a=o)}t[e]=a}return[n,r]},Fe={depth:I,hosts:ae,pieces:J};export{Fe as depth};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./activate-
|
|
1
|
+
import{n as e}from"./activate-C16bLpUy.js";import{t}from"./playerPaint-DaCo2Clx.js";async function n(n,r,i){let a=(await e(n,!0)).createProjector(),o=r.cloneNode(!1),s=t(o,i);s.fit(n.file.poster.half,n.file.poster.center);let c=!1;return Object.assign((...e)=>{s.paint(a(...e)),c||=(r.style.overflow=`visible`,r.replaceChildren(...o.childNodes),!0)},{dispose:a.dispose})}export{n as live};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e,n as t,r as n,s as r,t as i}from"./reader-JcTNbEkh.js";import{t as a}from"./runs-
|
|
1
|
+
import{i as e,n as t,r as n,s as r,t as i}from"./reader-JcTNbEkh.js";import{t as a}from"./runs-BQEucHaT.js";import{t as o}from"./poster-Cs69ty3T.js";var s=e=>typeof e==`number`?e+`px`:e,c=e=>e===void 0?void 0:{display:`inline-block`,width:s(e),height:s(e),lineHeight:`0`},l=(e,t)=>Object.assign(e.style,c(t)??{display:``,width:``,height:``,lineHeight:``}),u=class{items=[];get first(){return this.items[0]}update(e,t){if(e.at===t)return;e.at=t;let n=e.index;if(t===1/0){if(n<0)return;let t=this.items.pop();if(e.index=-1,t===e)return;e=t}else n<0&&(n=this.items.length);for(;n>0;){let t=n-1>>1,r=this.items[t];if(r.at<=e.at)break;this.items[n]=r,r.index=n,n=t}for(;2*n+1<this.items.length;){let t=2*n+1;(this.items[t+1]?.at??1/0)<this.items[t].at&&t++;let r=this.items[t];if(r.at>=e.at)break;this.items[n]=r,r.index=n,n=t}this.items[n]=e,e.index=n}},d=Symbol.for(`mien-avatar.scheduler.v1`);function f(e,t){let n=e.ownerDocument;return(n[d]??=p(n)).add(e,t)}function p(e){let t=e.defaultView,n,r=()=>n??t.performance.now(),i=new Map,a=new Set,o=new u,s,c=t.matchMedia?.(`(prefers-reduced-motion: reduce)`),l,f,p=1/0,m=!1,h=!1,g=e=>i.get(e.target)===e;function _(){if(m)return;a.size&&l===void 0&&(l=t.requestAnimationFrame(S)),!a.size&&l!==void 0&&(t.cancelAnimationFrame(l),l=void 0);let e=o.first?.at??1/0;e!==p&&(f!==void 0&&t.clearTimeout(f),p=e,f=e===1/0?void 0:t.setTimeout(x,Math.min(2147483647,Math.max(0,Math.ceil(e-r())))))}function v(e){g(e)&&o.update(e,Math.min(e.active?e.drawAt:1/0,e.client.completionTime()))}function y(e,n){A(e);try{e.client.error(n)}catch(e){t.console.error(e)}}function b(e){for(;o.first&&o.first.at<=e;){let t=o.first;o.update(t,1/0);try{if(t.client.completionTime()<=e&&t.client.settle(e),t.active&&t.drawAt<=e&&(t.drawAt=1/0,a.add(t)),v(t),t.at<=e)throw Error(`Completion did not advance its deadline.`)}catch(e){y(t,e)}}}function x(){f=void 0,p=1/0,m=!0,b(r()),m=!1,_()}function S(){l=void 0,m=!0;let e=r();n=e,b(e);for(let t of Array.from(a))if(!(!a.delete(t)||!t.active||!g(t)))try{let n=t.client.draw(e,t.returning,t.pixels);if(t.returning=!1,t.painted=!0,!g(t)||!t.active)continue;n<=e&&a.add(t),t.drawAt=n>e?n:1/0,v(t)}catch(e){y(t,e)}n=void 0,m=!1,_()}function C(t){let n=t.seen&&!e.hidden;n!==t.active&&(t.generation++,t.active=n,n?(t.returning=t.painted,a.add(t)):(a.delete(t),t.drawAt=1/0),v(t))}function w(){m=!0;for(let e of i.values())C(e);b(r()),m=!1,_()}function T(e,n){if(n<=0)return;let r=n*(t.devicePixelRatio||1);r!==e.pixels&&(e.pixels=r,e.active&&a.add(e))}let E=t.IntersectionObserver&&new t.IntersectionObserver(e=>{for(let t of e){let e=i.get(t.target);e&&(e.seen=t.isIntersecting,C(e))}_()}),D=t.ResizeObserver&&new t.ResizeObserver(e=>{for(let t of e){let e=i.get(t.target);e&&T(e,t.contentRect.width)}_()});function O(){h||(h=!0,queueMicrotask(()=>{h=!1;for(let e of i.values()){let n=e.target.getBoundingClientRect();D||T(e,n.width),E||(e.seen=n.width>0&&n.height>0&&n.right>0&&n.bottom>0&&n.left<t.innerWidth&&n.top<t.innerHeight,C(e))}_()}))}function k(){for(let e of i.values())try{e.client.motion(!!c?.matches)}catch(t){y(e,t)}}c?.addEventListener(`change`,k),e.addEventListener(`visibilitychange`,w),E||t.addEventListener(`scroll`,O,!0),(!E||!D)&&t.addEventListener(`resize`,O);function A(n){g(n)&&(i.delete(n.target),a.delete(n),o.update(n,1/0),E?.unobserve(n.target),D?.unobserve(n.target),i.size||(E?.disconnect(),D?.disconnect(),e.removeEventListener(`visibilitychange`,w),c?.removeEventListener(`change`,k),t.removeEventListener(`scroll`,O,!0),t.removeEventListener(`resize`,O),delete e[d]),_())}return{motion:k,add(e,t){let n={target:e,client:t,generation:0,seen:!1,active:!1,returning:!1,painted:!1,pixels:192,drawAt:1/0,index:-1,at:1/0};return i.set(e,n),E?.observe(e),D?.observe(e),(!E||!D)&&O(),v(n),_(),s===void 0&&(s=r(),queueMicrotask(()=>{s=void 0})),{origin:s,now:r,get generation(){return n.generation},get visible(){return n.active},get reduced(){return!!c?.matches},invalidate(){g(n)&&(n.active&&a.add(n),n.drawAt=1/0,v(n),_())},remove:()=>A(n)}}}}function m(e){e[d]?.motion()}var h=Symbol.for(`mien-avatar.motion.v1`),g=Symbol.for(`mien-avatar.poster.v1`);function _(t){if(![`auto`,`full`,`reduced`].includes(t))throw new e(`MIEN_MOTION`,`/motion`,`Use auto, full or reduced, not ${JSON.stringify(t)}.`)}function v({motion:e},t=document){_(e),t[h]=e,m(t)}function y(e,t,n={}){return n.size!==void 0&&l(e,n.size),b(e,t,n)}function b(s,c,l,u,d){let p=i(c),m=s.ownerDocument,v=(e,t)=>{Object.hasOwn(p[e],t)||r(e,t,Object.keys(p[e]))};l.state!==void 0&&v(`states`,l.state);let y=l.motion;y!==void 0&&_(y);let b=m[g]=(m[g]??0)+1,x=u??o(p,`dom-`+b,l.label,(e,t,n)=>{let r=m.createElementNS(`http://www.w3.org/2000/svg`,e);for(let[e,n]of Object.entries(t))r.setAttribute(e,String(n));return n&&r.append(...n),r});u||s.append(x);let S=new Set,C=!1,w=!1,T,E,D,O=!1,k=p.states[p.file.initial],A=k.expression&&p.expressions[k.expression],j=!!(k.sequence||k.gaze||(k.blink??p.blink).mode!==`off`||A&&(A.headGesture||A.markMotion||A.eyeMotion&&A.eyeMotion!==`none`||A.bodyMotion&&A.bodyMotion!==`none`));function M(e){w||(l.onError?l.onError(e):m.defaultView?.console.error(e))}let N=a(p,e=>{for(let t of S)try{t(e)}catch(e){M(e)}}),P,F=0,I=0,L=m.defaultView.performance.now(),R=f(x,{draw(e,t,n){if(!j)return 1/0;if(!T)return U().catch(M),1/0;if(P)return L+P.draw(T,e-L,t,n);if(!D)return O||(O=!0,(d?d(p,x,`mien-live-`+b,{revision:()=>F,generation:()=>R.generation,runId:()=>N.runId,commandTime:()=>I,visible:()=>!w&&R.visible,invalidate:R.invalidate,report:M}).then(e=>{w?e?.dispose():e&&(P=e,R.invalidate())}):H().then(e=>w||!R.visible?void 0:e.live(p,x,`mien-live-`+b)).then(e=>{w?e?.dispose():e&&(D=e,R.invalidate())})).catch(M).finally(()=>{O=!1})),1/0;let r=e-L,{frame:i,nextTime:a,geometryStable:o}=T.sampleDisplay(r,t||!B);return w||(D(i,B?n:192,o),B=!0),L+a},completionTime:()=>L+N.deadline,settle:e=>N.settle(Math.max(N.deadline,e-L)),motion:()=>K(),error(e){C=!0,N.dispose(),M(e)}});L=R.origin,R.invalidate();function z(){let e=y??m[h]??`auto`;return e===`auto`?R.reduced?`reduced`:`full`:e}let B=!1,V=z(),H=()=>Promise.all([import("./rolldown-runtime-DK3Fl9T5.js"),import("./playback-a02m3NQr.js"),import("./activate-C16bLpUy.js"),import("./playerPaint-DaCo2Clx.js"),import("./live-3QIUR7dM.js")]).then(m=>m[4]);function U(){let e=V;if(!E&&!d&&R.visible){H().catch(()=>{});let{primary:e,nodes:t}=p.file.avatar.body;(t.length||e.type!==`sphere`||e.width!==e.height||e.width!==e.depth)&&Promise.all([import("./rolldown-runtime-DK3Fl9T5.js"),import("./playback-a02m3NQr.js"),import("./activate-C16bLpUy.js"),import("./sampledProfiles-Bnlm4vdZ.js")]).then(m=>m[3]).catch(()=>{})}return E??=Promise.all([import("./rolldown-runtime-DK3Fl9T5.js"),import("./playback-a02m3NQr.js")]).then(m=>m[1]).then(e=>e.i).then(t=>(T=t.createCursor(t.prepare(p),{motion:`full`}),T.sampleDisplay(0,!1),e===`reduced`&&T.setMotion(e,0),R.invalidate(),T)).catch(e=>{throw E=void 0,e})}function W(){if(w||C)throw new e(`MIEN_DISPOSED`,``,`Mount a new avatar.`)}function G(e){W();let t=R.now()-L;F++,I=t,j=!0;let n=n=>{e(n,t),R.invalidate()};return T?n(T):U().then(n).catch(M),t}function K(){let e=z();e!==V&&(V=e,(E||j||A&&(A.headX||A.headY||A.headZ))&&G((t,n)=>t.setMotion(e,n)))}function q(e){if(W(),v(`states`,e),e===N.state){N.settle(R.now()-L);return}let t=G((t,n)=>t.set(e,n));N.select(e,p.states[e].sequence,t),R.invalidate()}return V===`reduced`&&A&&(A.headX||A.headY||A.headZ)&&(j=!0),l.state!==void 0&&q(l.state),{set:q,expression(e){v(`expressions`,e);let t=G((t,n)=>t.expression(e,n));N.select(void 0,void 0,t),R.invalidate()},async play(e){v(`sequences`,e);let t=G((t,n)=>t.sequence(e,n)),n=N.play(e,t);return R.invalidate(),n},blink(){G((e,t)=>e.blink(t))},setBlink(e){t(e),G((t,n)=>t.setBlink(e,n))},look(e){n(e),G((t,n)=>t.look(e,n))},setMotion(e){W(),e!==void 0&&_(e),y=e,K()},on(e,t){return W(),S.add(t),()=>{S.delete(t)}},destroy(){w||(w=!0,R.remove(),S.clear(),N.dispose(),x.remove(),P?.dispose(),D?.dispose(),T?T.dispose():E&&E.then(e=>e.dispose(),()=>{}))}}}export{c as a,l as i,b as n,v as r,y as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime-DK3Fl9T5.js";import{S as t,b as n,y as r}from"./playback-
|
|
1
|
+
import{t as e}from"./rolldown-runtime-DK3Fl9T5.js";import{S as t,b as n,y as r}from"./playback-a02m3NQr.js";import{I as i,L as a,c as o,j as s}from"./activate-C16bLpUy.js";var c=e({wrappedPaintContours:()=>g,wrappedPaintMesh:()=>m}),l=(e,t)=>{let n=new Float64Array(e.length*3),r=new Float64Array(e.length*3);return e.forEach(({point:e,normal:t},i)=>{n.set(e,i*3),r.set(t,i*3)}),{points:n,normals:r,triangles:Uint32Array.from(t)}},u=new Map,d=e=>{let t=Math.hypot(...e)||1;return[e[0]/t,e[1]/t,e[2]/t]},f=(e,t,n)=>[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n],p=(e,c)=>{let p=[s(e.surface),s(c.surface),...e.position,...c.position,...e.rotation,...c.rotation].join(`|`),m=u.get(p);if(m)return m;let h=t(r(...c.rotation.map(n))),g=e.position.map((e,t)=>e-c.position[t]),_=h[0]*g[0]+h[3]*g[1]+h[6]*g[2],v=h[1]*g[0]+h[4]*g[1]+h[7]*g[2],y=t(r(...e.rotation.map(n))),b=(e,t)=>h[e]*y[t]+h[3+e]*y[3+t]+h[6+e]*y[6+t],x=b(0,0),S=b(0,1),C=b(1,0),w=b(1,1),T=x*w-S*C;if(Math.abs(T)<1e-8){let e=l([],[]);return u.set(p,e),e}let E=e.surface.type===`blob`?a(e.surface):void 0,D=t=>{let n=t[0]-_,r=t[1]-v,a=(w*n-S*r)/T/(e.surface.width/2),o=(-C*n+x*r)/T/(e.surface.height/2);if(E?.plate){let e=!1,t=1/0;for(let n=0;n<E.plate.length;n++){let r=E.plate[n],i=E.plate[(n+1)%E.plate.length],s=i[0]-r[0],c=i[1]-r[1],l=Math.max(0,Math.min(1,((a-r[0])*s+(o-r[1])*c)/(s*s+c*c||1)));t=Math.min(t,Math.hypot(a-r[0]-l*s,o-r[1]-l*c)),r[1]>o!=i[1]>o&&a<(i[0]-r[0])*(o-r[1])/(i[1]-r[1])+r[0]&&(e=!e)}return e?t:-t}return(E?i(E.radii,Math.atan2(o,a)):1)-Math.hypot(a,o)},O=o(c.surface),k=new Map,A=e=>{let t=k.get(e);if(t)return t;let n=e*3,r=[O.positions[n],O.positions[n+1],O.positions[n+2]],i={point:r,normal:[O.normals[n],O.normals[n+1],O.normals[n+2]],mask:D(r),id:`s${e}`};return k.set(e,i),i},j=new Map,M=(e,t)=>{let n=e.id<t.id?`${e.id}/${t.id}`:`${t.id}/${e.id}`,r=j.get(n);if(r)return r;let i=0,a=1;for(let n=0;n<26;n++){let n=(i+a)/2,r=f(e.point,t.point,n);D(r)>0==e.mask>0?i=n:a=n}let o=(i+a)/2,s={point:f(e.point,t.point,o),normal:d(f(e.normal,t.normal,o)),mask:0,id:n};return j.set(n,s),s},N=[],P=[],F=new Map,I=e=>{let t=[...e.point.map(e=>Math.round(e*1e5)),...e.normal.map(e=>Math.round(e*1e3))].join(`,`),n=F.get(t);return n===void 0&&(n=N.length,F.set(t,n),N.push({point:e.point,normal:e.normal})),n},L=(e,t,n)=>{let r=[A(e),A(t),A(n)],i=[];for(let e=0;e<3;e++){let t=r[e],n=r[(e+1)%3];t.mask>0&&i.push(t),t.mask>0!=n.mask>0&&i.push(M(t,n))}if(i.length<3)return;let a=I(i[0]);for(let e=1;e+1<i.length;e++){let t=I(i[e]),n=I(i[e+1]);a!==t&&a!==n&&t!==n&&P.push(a,t,n)}};for(let e=0;e<48;e+=1)for(let t=0;t<96;t+=1){let n=e*97+t,r=(e+1)*97+t,i=(e+1)*97+t+1,a=e*97+t+1;L(n,a,r),L(a,i,r)}let R=l(N,P);return u.size>=32&&u.delete(u.keys().next().value),u.set(p,R),R},m=(e,t)=>p(e,t),h=2**24,g=(e,t,n,r)=>{let i=p(e,t.part),{m:a,t:o}=t.placement,s=t.perspective/620,c=i.triangles,l=Array(i.points.length/3);for(let e=0;e<l.length;e++){let t=i.points[e*3],n=i.points[e*3+1],r=i.points[e*3+2],c=[a[0]*t+a[1]*n+a[2]*r+o[0],a[3]*t+a[4]*n+a[5]*r+o[1],a[6]*t+a[7]*n+a[8]*r+o[2]],u=1/(1-s*c[2]),d=c[0]*u,f=c[1]*u;l[e]={screen:[d,f,c[2]],camera:c,facing:1,key:e}}let u=new Uint8Array(c.length/3),d=new Uint8Array(l.length);for(let e=0;e<u.length;e++){let t=c[e*3],n=c[e*3+1],r=c[e*3+2],i=l[t].screen,a=l[n].screen,o=l[r].screen;(a[0]-i[0])*(o[1]-i[1])-(a[1]-i[1])*(o[0]-i[0])>1e-10&&(u[e]=1,d[t]=d[n]=d[r]=1)}let m=([e,t,i])=>{let a=n.depthAt(e,t),o=Number.isFinite(a)?i-a+.02:1;if(r){let n=r.depthAt(e,t);Number.isFinite(n)&&(o=Math.min(o,i-n+.02))}return o},g=e=>{let t=1/(1-s*e[2]);return[e[0]*t,e[1]*t,e[2]]};l.forEach((e,t)=>{e.facing=d[t]?m(e.screen):-1});let _=new Map,v=new Map,y=l.length,b=(e,t)=>{let n=e.key<t.key?e.key*h+t.key:t.key*h+e.key,r=_.get(n);if(r)return r;let i=0,a=1,o=e.facing>0;for(let n=0;n<18;n++){let n=(i+a)/2,r=g(f(e.camera,t.camera,n));m(r)>0===o?i=n:a=n}let s=f(e.camera,t.camera,o?i:a),c={screen:g(s),camera:s,facing:0,key:y++};return _.set(n,c),c};for(let e=0;e<u.length;e++){if(!u[e])continue;let t=[l[c[e*3]],l[c[e*3+1]],l[c[e*3+2]]],n=[];for(let e=0;e<3;e++){let r=t[e],i=t[(e+1)%3];r.facing>0&&n.push(r),r.facing>0!=i.facing>0&&n.push(b(r,i))}if(!(n.length<3))for(let e=0;e<n.length;e++){let t=n[e],r=n[(e+1)%n.length],i=t.key*h+r.key,a=r.key*h+t.key,o=v.get(a);if(o)--o.count===0&&v.delete(a);else{let e=v.get(i);e?e.count++:v.set(i,{edge:[t,r],count:1})}}}let x=new Map,S=0;for(let{edge:e,count:t}of v.values()){let n=x.get(e[0].key)??[];for(let r=0;r<t;r++)n.push(e);S+=t,x.set(e[0].key,n)}let C=[];for(;x.size;){let e=x.values().next().value[0][0],t=[],n=e.key,r=0;for(;r++<S+2;){let r=x.get(n);if(!r?.length)break;let i=r.pop();if(r.length||x.delete(n),t.push(i[0].screen),n=i[1].key,n===e.key)break}t.length>=3&&n===e.key&&C.push(t)}return C},_={paint:c};export{_ as paint};
|