mien-avatar 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -26
- 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/format.js +1 -1
- package/dist/guide.md +21 -38
- package/dist/index.js +1 -1
- package/dist/react.js +1 -1
- package/dist/runtime/{activate-C80BK8CF.js → activate-CCUqRQyO.js} +1 -1
- package/dist/runtime/{adapter-Dn8Z0VEL.js → adapter-onjjGk6m.js} +1 -1
- package/dist/runtime/{depth-BA77ksjs.js → depth-C0ucFmd8.js} +1 -1
- package/dist/runtime/{handle-BgLTnSgy.js → handle-p7slzKMG.js} +1 -1
- package/dist/runtime/live-C2QiAIQ9.js +1 -0
- package/dist/runtime/{mount-DhC05CLb.js → mount-CzvXPeZF.js} +1 -1
- package/dist/runtime/{paint-DAEjGO2k.js → paint-CxkSCDga.js} +1 -1
- package/dist/runtime/{playback-DxnlsAAY.js → playback-BeRsJu6S.js} +1 -1
- package/dist/runtime/{playerPaint-DylZy_iE.js → playerPaint-DaCo2Clx.js} +1 -1
- package/dist/runtime/{poster-BxyQVVcf.js → poster-Cs69ty3T.js} +1 -1
- package/dist/runtime/reader-JcTNbEkh.js +1 -0
- package/dist/runtime/render-f6uGZFDG.js +1 -0
- package/dist/runtime/{request-CGIlAb4P.js → request-Ca14lwoC.js} +1 -1
- package/dist/runtime/{response-DZAPeoVT.js → response-DPh_8Rji.js} +1 -1
- package/dist/runtime/{sampledProfiles-_9uwa85K.js → sampledProfiles-BvP-O0oY.js} +1 -1
- package/dist/runtime/{sculpt-DTgDSjd1.js → sculpt-DWr8rXDB.js} +1 -1
- package/dist/runtime/{sockets-PNoBQrfx.js → sockets-CM-eyf8W.js} +1 -1
- package/dist/still.js +1 -1
- package/dist/types/format/types.d.ts +6 -0
- package/dist/types/playerPaint.d.ts +13 -2
- package/dist/vue.js +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/runtime/live-Cu0tA6c7.js +0 -1
- package/dist/runtime/reader-D8GMfJy6.js +0 -1
- package/dist/runtime/render-CubDnPM7.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime-DK3Fl9T5.js";import{s as t,t as n}from"./reader-D8GMfJy6.js";import{t as r}from"./runs-BIIveHSZ.js";var i=e=>e*Math.PI/180,a=([e,t,n,r])=>{let i=Math.hypot(e,t,n,r)||1;return[e/i,t/i,n/i,r/i]},o=([e,t,n,r],[i,o,s,c])=>a([e*i-t*o-n*s-r*c,e*o+t*i+n*c-r*s,e*s-t*c+n*i+r*o,e*c+t*s-n*o+r*i]),s=([e,t,n],r)=>{let i=Math.sin(r/2);return a([Math.cos(r/2),e*i,t*i,n*i])},c=(e,t,n)=>o(o(s([0,0,1],n),s([1,0,0],e)),s([0,1,0],t)),l=([e,t,n,r],i=new Float64Array(9))=>(i[0]=1-2*(n*n+r*r),i[1]=2*(t*n-e*r),i[2]=2*(t*r+e*n),i[3]=2*(t*n+e*r),i[4]=1-2*(t*t+r*r),i[5]=2*(n*r-e*t),i[6]=2*(t*r-e*n),i[7]=2*(n*r+e*t),i[8]=1-2*(t*t+n*n),i),u=(e,t)=>{let n=new Float64Array(9);for(let r=0;r<3;r+=1)for(let i=0;i<3;i+=1)n[r*3+i]=e[r*3]*t[i]+e[r*3+1]*t[3+i]+e[r*3+2]*t[6+i];return n},d=(e,[t,n,r])=>[e[0]*t+e[1]*n+e[2]*r,e[3]*t+e[4]*n+e[5]*r,e[6]*t+e[7]*n+e[8]*r],f=(e,t=[0,0,0])=>{let n=d(e,t);return[t[0]-n[0],t[1]-n[1],t[2]-n[2]]},p={x:1,y:1},m=Math.PI*2,h={x:0,y:0,z:0,offsetX:0,offsetY:0,grow:0,stretch:0,flap:0},g=e=>{let t=1+Math.max(-.5,e.grow),n=1+Math.max(-.5,e.stretch);return{x:t/n,y:t*n}},_=e=>{if(e.headGestureMix)return e.headGestureMix;if(e.headGesture)return{[e.headGesture]:e.headGestureAmount??1}},v=(e,t)=>e<=0?0:1-Math.exp(-t*e)*(Math.cos(t*e)+Math.sin(t*e)),y=(e,t,n,r=14)=>e<=0?0:Math.exp(-t*e)*Math.sin(m*n*e)*(1-Math.exp(-r*e)),b=(e,t,n)=>{let r=(e-t)/n;return r<=0||r>=1?0:Math.sin(Math.PI*r)**2},x=(e,t,n,r)=>{let i=Math.min(1,Math.max(0,(e-t)/n));return i<.5?2**(r-1)*i**r:1-(2-2*i)**r/2},S=(e,t,n)=>{if(e<=0)return 0;if(e>=t)return 1;let r=e=>1-(1+n*e)*Math.exp(-n*e);return r(e)/r(t)},C=e=>((e+180)%360+360)%360-180,w=(e,t,n)=>{let r=t/1e3,i=e=>n&&n>0?n/1e3/Math.max(1,Math.round(n/1e3/e)):e,a=e=>{let t=i(e);return{since:(r%t+t)%t,length:t}},o=(e,t=0)=>m*(r/i(1/e))+t,s=(e,t,n)=>n.reduce((n,[r,i])=>n+i*v(e-r,t),0);switch(e){case`nod`:{let{since:e}=a(2),t=y(e,2.4,1.7,12);return{...h,x:-15*t,offsetY:2*t}}case`headShake`:{let{since:e}=a(2.2);return{...h,y:20*y(e,2.8,2.3,16),z:-4*y(e-.07,2.8,2.3,16)}}case`wiggle`:return{...h,z:9*Math.sin(o(1.5)),y:5*Math.sin(o(1.5,-.5)),offsetY:-3.5*(.5-.5*Math.cos(o(3)))};case`twirl`:{let{since:e}=a(4.4),t=(t,n)=>n*(360*S(e-t,1.2,5.5)-16*b(e,t-.28,.56)),n=t=>b(e,t,1.1),r=(t,n)=>n*7*b(e,t,1.3);return{...h,y:t(.3,1)+t(2.5,-1),z:r(.3,1)+r(2.5,-1),offsetY:-10*(n(.3)+n(2.5))}}case`lookAround`:{let{since:e}=a(5.6),t=s(e,7,[[.3,26],[1.6,-2],[2.9,-48],[4.3,24]]),n=s(e,7,[[1.6,13],[2.9,-10],[4.3,-3]]);return{...h,x:n,y:t,z:-.15*t}}case`hop`:{let e=Math.sin(o(.575)),t=Math.abs(Math.cos(o(.575)));return{...h,x:3*Math.abs(e),z:4*e,offsetY:-13*Math.abs(e),stretch:.07*t-.15*(1-Math.abs(e))**10}}case`tilt`:{let{since:e}=a(4.8);return{...h,z:s(e,5.5,[[.2,15],[1.7,-15],[2.5,-11],[3.9,11]]),x:s(e,5.5,[[.2,4],[1.7,-4],[2.5,3],[3.9,-3]])}}case`dance`:return{...h,z:8*Math.sin(o(1)),y:7*Math.sin(o(.5,.6)),x:2*Math.sin(o(2,1)),offsetY:-3.5*(.5-.5*Math.cos(o(2)))};case`bow`:{let{since:e}=a(3.8),t=s(e,6,[[.3,1],[1.5,-1]]);return{...h,x:-24*t,offsetY:5*t}}case`eagerNod`:{let{since:e}=a(2.2),t=(t,n)=>n*(b(e,t,.42)-.25*b(e,t-.16,.2)),n=t(.2,1)+t(.68,.8);return{...h,x:-20*n,offsetY:4*n}}case`peek`:{let{since:e}=a(4.2),t=s(e,6,[[.3,1],[2.2,-1]]);return{...h,z:14*t,y:10*t,offsetX:16*t,offsetY:3*t}}case`shrug`:{let{since:e}=a(3.2),t=s(e,9,[[.25,1],[1.2,-1]]);return{...h,z:-8*t,x:4*t,offsetY:-9*t}}case`recoil`:{let{since:e}=a(3),t=v(e-.1,14)-v(e-.9,4);return{...h,x:14*t,offsetY:-6*t-6*b(e,.1,.35),stretch:.05*b(e,.1,.35)}}case`doubleTake`:{let{since:e}=a(4.6),t=v(e-1.4,13)-v(e-2.6,7),n=s(e,6,[[.3,16],[.9,-16]])+26*t;return{...h,y:n,x:8*t,z:-.15*n,offsetY:-5*b(e,1.4,.4)}}case`eyeRoll`:{let{since:e}=a(4.2),t=s(e,6,[[.3,-10],[.8,10],[1.3,10],[2.3,-10]]),n=s(e,6,[[.3,-4],[.8,18],[1.3,-16],[2.3,2]]);return{...h,x:n,y:t,z:.4*t,offsetY:3*b(e,1.5,1.5)}}case`dizzy`:{let{since:e,length:t}=a(4),n=b(e,0,t),r=m*3*e/t;return{...h,x:9*n*Math.sin(r),y:12*n*Math.cos(r),z:7*n*Math.cos(r-.6),offsetX:3*n*Math.cos(r)}}case`sneeze`:{let{since:e}=a(3.8),t=s(e,6,[[.3,7],[.85,7]])-30*v(e-1.55,16)+16*v(e-2,7);return{...h,x:t,y:5*y(e-1.65,3.5,3,16),offsetY:5*b(e,1.5,.5)-2*b(e,.3,1.2)}}case`yawn`:{let{since:e}=a(4.4),t=s(e,3.6,[[.2,1],[1.7,-1.25],[2.4,.25]]),n=1.5*Math.sin(m*6*e)*b(e,.7,1);return{...h,x:16*t,z:4*t+n,offsetY:-4*t}}case`shiver`:{let{since:e,length:t}=a(3),n=b(e,0,.45*t)+.7*b(e,.5*t,.45*t),r=b(e,0,t),i=m*8*e;return{...h,x:-3*r,y:3.5*n*Math.sin(i),z:1.5*n*Math.sin(i+1.2),offsetY:3*r}}case`tickTock`:{let{since:e}=a(4.6),t=s(e,14,[[.2,6],[.7,-12],[1.2,12],[1.7,-12],[2.2,6]]),n=b(e,2.4,.9);return{...h,z:t,y:.3*t,x:-7*n,offsetY:3*n}}case`bashful`:{let{since:e}=a(4.8),t=s(e,5,[[.2,1],[2,-.6],[2.7,-.4]]),n=4*Math.sin(m*(e-.7)/.65)*b(e,.7,1.3);return{...h,y:-16*t,x:-8*t,z:-6*t+n,offsetY:2*t}}case`roll`:{let{since:e}=a(4);return{...h,y:C(-18*b(e,0,.5)+360*S(e-.22,1.3,5.5))}}case`flip`:{let{since:e}=a(4),t=v(e,12)-v(e-.3,12);return{...h,x:C(-14*t+360*S(e-.28,1.3,5.5)),offsetY:18*b(e,.05,1)}}case`spin`:{let{since:e}=a(4);return{...h,y:C(28*b(e,0,.7)-720*S(e-.3,2.1,3.6))}}case`bounce`:{let{since:e}=a(3),t=v(e,14)-v(e-.27,16);return{...h,offsetY:-2*b(e,.25,.3),stretch:-.1*t+.11*b(e,.25,.3)-.04*b(e,.58,.34)}}case`breathe`:{let{since:e,length:t}=a(3.8),n=.42*t,r=e<n?e/n:1-(e-n)/(t-n),i=.08*(1-Math.cos(Math.PI*r))/2;return{...h,grow:i,offsetY:115*i,flap:40*i}}case`shrink`:{let{since:e}=a(4),t=v(e,11)*(1-x(e,3.2,.7,2));return{...h,grow:-.18*t,stretch:-.04*t,offsetY:-24*t}}case`stomp`:{let e=Math.sin(o(.6)),t=e*e;return{...h,z:6*e,y:4*e,x:-3*t,offsetY:5*t,stretch:-.05*t**3}}case`sway`:{let e=Math.sin(o(.45));return{...h,z:10*e,y:6*Math.sin(o(.45,-.6)),offsetX:4*e,offsetY:3*(1-e*e)}}case`earFlap`:{let{since:e,length:t}=a(2),n=b(e,0,t),r=(1-Math.cos(m*4*e/t))/2,i=Math.sin(m*e/t);return{...h,flap:10*n*r,x:3*n,y:9*n*i,z:5*n*i,offsetY:-1.5*n*r*r}}case`shakeOff`:{let{since:e}=a(2.6);return{...h,y:12*y(e,3.2,4.8,20),z:6*y(e-.05,3.2,4.8,20),offsetY:-2.5*y(e,3.2,9.6,20),flap:5*y(e-.08,3.2,4.8,20)}}}},T=(e,t,n)=>{if(e.sampledGesture&&e.sampledGestureTime===t)return e.sampledGesture;let r=_(e);if(!r)return e.sampledGesture?h:void 0;let i={...h};for(let[a,o]of Object.entries(r)){if(!(o>0))continue;let r=e.headGestureStarts?.[a],s=e.headGestureRates?.[a]??1,c=r===void 0?w(a,t*s,n===void 0?void 0:n*s):w(a,Math.max(0,t-r)*s),l=Math.min(1,o);i.x+=c.x*l,i.y+=c.y*l,i.z+=c.z*l,i.offsetX+=c.offsetX*l,i.offsetY+=c.offsetY*l,i.grow+=c.grow*l,i.stretch+=c.stretch*l,i.flap+=c.flap*l}return i},E=(e,t,n)=>{let r=T(e.expression,t,n);if(!r)return{pose:e,offset:{x:0,y:0},squash:p};let a=c(i(r.x),i(r.y),i(r.z));return{pose:{...e,orientation:o(e.orientation,a)},offset:{x:r.offsetX,y:r.offsetY},squash:r.grow||r.stretch?g(r):p}},D=e=>{if(e.markMotionMix)return e.markMotionMix;if(e.markMotion)return{[e.markMotion]:e.markMotionAmount??1}},O=Math.PI*2,k=e=>e.width>.5&&e.height>.5,A=9,j=e=>e<=0?0:1-Math.exp(-9*e)*(Math.cos(A*e)+Math.sin(A*e)),M=(e,t,n,r,i=r)=>({...e,x:t+(e.x-t)*r,y:n+(e.y-n)*i,width:e.width*r,height:e.height*i,...e.bend===void 0?{}:{bend:e.bend*i/r}}),N=(e,t,n,r)=>{let i=r*Math.PI/180,a=e.x-t,o=e.y-n;return{...e,x:t+a*Math.cos(i)-o*Math.sin(i),y:n+a*Math.sin(i)+o*Math.cos(i),angle:e.angle+r}},P=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n,width:e.width+(t.width-e.width)*n,height:e.height+(t.height-e.height)*n,angle:e.angle+(t.angle-e.angle)*n,...e.bend!==void 0||t.bend!==void 0?{bend:(e.bend??0)+((t.bend??0)-(e.bend??0))*n}:{}}),F=(e,t,n,r,i)=>{if(n<=0)return[...e];let a=r/1e3,o=e=>i&&i>0?Math.max(1,Math.round(e*i/1e3))/(i/1e3):e,s=(e,t=0)=>O*o(e)*a+t,c=e.map((e,t)=>({mark:e,index:t})).filter(({mark:e})=>k(e)).sort((e,t)=>e.mark.x-t.mark.x),l=new Map(c.map(({index:e},t)=>[e,t])),u=c.map(({mark:e})=>e),d=u.length?u.reduce((e,t)=>e+t.x,0)/u.length:0,f=u.length?u.reduce((e,t)=>e+t.y,0)/u.length:0,p=u.length?Math.min(...u.map(e=>e.y-Math.max(e.width,e.height)/2)):f,m=(e,n)=>{let r=l.get(n)??0;switch(t){case`drift`:{let t=3.5*Math.sin(s(.21))+1.5*Math.sin(s(.53,1)),n=2.5*Math.sin(s(.17,2));return{...e,x:e.x+t,y:e.y+n}}case`scan`:return{...e,x:e.x+12*Math.sin(s(.42)),y:e.y+1.5*Math.sin(s(.84))};case`wave`:{let t=r*.95,n=1+(.26+.08*Math.sin(s(.23)))*Math.sin(s(1.05,-t))+.09*Math.sin(s(2.1,.7-2*t));return M(e,e.x,e.y,1,Math.max(.3,n))}case`talk`:{let t=r*.8,n=1+(.62+.24*Math.sin(s(.37))+.14*Math.sin(s(.71,1.3)))*(.46*Math.sin(s(2.3,-t))+.14*Math.sin(s(4.6,.9-2*t)));return M(e,e.x,e.y,1,Math.max(.3,n))}case`bounce`:{let t=s(.95,-r*1.1),n=.5-.5*Math.cos(t),i=11*n**1.6,a=.1*Math.abs(Math.sin(t))*n**.6,o={...e,y:e.y-i};return M(o,o.x,o.y,1-a/2,1+a)}case`type`:{let t=[...u].sort((e,t)=>e.y-t.y).indexOf(e),n=1/o(.32),r=((a/n+.5)%1+1)%1,i=j((r-.02-t*.11)*n)-j((r-.6-t*.07)*n),s=Math.min(e.height,e.width);return{...e,width:Math.max(s*.6,s+(e.width-s)*i)}}case`orbit`:{let t=N(e,d,f,360*o(.75)*a),n=[1.15,.92,.7][r]??1;return{...t,angle:e.angle,width:e.width*n,height:e.height*n}}case`pulse`:{let t=1+.16*(.5-.5*Math.cos(s(.8)));return M(e,d,f,t)}case`breathe`:return M(e,d,f,1+.045*Math.sin(s(.35)));case`sway`:{let t=Math.max(0,e.y-p)/60;return N(e,d,p,9*Math.sin(s(.75,-.45*t)))}case`shake`:{let t=1/o(1/2.2),n=(a%t+t)%t,r=Math.exp(-4.5*n)*Math.sin(O*5.5*n);return N({...e,x:e.x+10*r},d,f,3*r)}case`hop`:{let t=Math.abs(Math.cos(s(.55,e.x>d?-.35:0))),n=Math.max(0,1-t/.22),r={...e,y:e.y-9*t};return M(r,r.x,r.y+r.height/2,1+.07*n,1-.12*n)}case`beat`:{let t=1/o(1/1.1),n=(a%t+t)%t,r=(e,r)=>{let i=n-e-t*Math.round((n-e)/t);return Math.exp(-((i/r)**2))},i=1+.14*r(.12,.07)+.08*r(.34,.08)+.012*Math.sin(s(.6));return M(e,d,f,i)}case`twinkle`:{let t=Math.atan2(e.y-f,e.x-d),n=1+.3*Math.sin(s(.8,t));return{...N(e,d,f,8*Math.sin(s(.2))),width:e.width*n,height:e.height*n}}case`rise`:case`fall`:{let n=t===`rise`?-1:1,r=.5-.5*Math.cos(s(.85)),i=n*8*r**1.4,a=1+.04*Math.abs(Math.sin(s(.85)));return M({...e,y:e.y+i},d,f+i,a)}}};return e.map((e,t)=>k(e)?P(e,m(e,t),Math.min(1,n)):e)},I=(e,t,n,r)=>{let i=Object.entries(t).filter(([,e])=>e>0);if(i.length===1)return F(e,i[0][0],i[0][1],n,r);let a=e.map(e=>({...e}));for(let[t,o]of i)F(e,t,o,n,r).forEach((t,n)=>{let r=e[n],i=a[n];i.x+=t.x-r.x,i.y+=t.y-r.y,i.width+=t.width-r.width,i.height+=t.height-r.height,i.angle+=t.angle-r.angle,(r.bend!==void 0||t.bend!==void 0)&&(i.bend=(i.bend??0)+(t.bend??0)-(r.bend??0))});return a},L=[`lidLeft`,`lidRight`,`lidTiltLeft`,`lidTiltRight`,`lowerLidLeft`,`lowerLidRight`],R=1/5,z=(e,t,n)=>{let r=.010000001;return t<=r&&e>r?Math.min(1,Math.max(0,n/R)):e<=r&&t>r?Math.min(1,Math.max(0,1-(1-n)/R)):n},ee=[`headX`,`headY`,`headZ`,`widthLeft`,`widthRight`,`heightLeft`,`heightRight`,`spacing`,`positionXLeft`,`positionXRight`,`positionYLeft`,`positionYRight`,`leftAngle`,`rightAngle`,`perspective`],te={id:`neutral`,headX:0,headY:0,headZ:0,widthLeft:20,widthRight:20,heightLeft:50,heightRight:50,spacing:35,positionXLeft:0,positionXRight:0,positionYLeft:-7,positionYRight:-7,leftAngle:0,rightAngle:0,perspective:1},B=e=>e===`ellipse`||e===`circle`,ne=[`widthLeft`,`widthRight`,`heightLeft`,`heightRight`,`spacing`,`positionXLeft`,`positionXRight`,`positionYLeft`,`positionYRight`,`leftAngle`,`rightAngle`],V=Object.fromEntries(ne.map(e=>[e,te[e]])),re=(e,t=V)=>{let n={...e};return ne.forEach(r=>{n[r]=e[r]+t[r]-V[r]}),n.widthLeft=Math.max(10,n.widthLeft),n.widthRight=Math.max(10,n.widthRight),n.heightLeft=Math.max(10,n.heightLeft),n.heightRight=Math.max(10,n.heightRight),e.marks&&(n.marks=oe(e.marks,t,1,e.glyphWeight??1)),B(t.shape)&&(n.eyeShape=`ellipse`),n},ie=e=>((e+90)%180+180)%180-90,H=e=>{let[t,n,...r]=e;if(!t||!n||e.some(e=>e.bend))return 0;let i=Math.max(t.width,t.height,n.width,n.height,1),a=Math.max(t.width,n.width,1),o=U(1-r.reduce((e,t)=>Math.max(e,t.width,t.height),0)/(i*.25)),s=U((25-Math.max(Math.abs(ie(t.angle)),Math.abs(ie(n.angle))))/15),c=U(1-Math.abs(t.y-n.y)/(i*.5)),l=U(1-Math.abs(t.width-n.width)/(i*.4))*U(1-Math.abs(t.height-n.height)/(i*.4)),u=U((Math.abs(t.x-n.x)/a-1)/.5);return o*s*c*l*u},ae=(e,t)=>{let n=[t.positionXLeft-V.positionXLeft,t.positionXRight-V.positionXRight],r=[t.positionYLeft-V.positionYLeft,t.positionYRight-V.positionYRight],i=(t.spacing-V.spacing)/2,a=(n[0]+n[1])/2,o=(r[0]+r[1])/2+(t.glyphY??0),s=[t.widthLeft-V.widthLeft,t.widthRight-V.widthRight],c=[t.heightLeft-V.heightLeft,t.heightRight-V.heightRight],l=[t.leftAngle-V.leftAngle,t.rightAngle-V.rightAngle],u=t=>e.map((e,u)=>{if(u>=2)return{...e,x:e.x-a,y:e.y-o};let d=(e,n)=>{let r=e-t*n;return Math.max(0,n>=0||r+n>=0||t===1?r:e/(1-t))},f=n[u]+(u===0?-i:i);return{...e,x:e.x-t*f-(1-t)*a,y:e.y-t*r[u]-(1-t)*o,width:d(e.width,s[u]),height:d(e.height,c[u]),angle:e.angle-t*l[u]}}),d=u(0);if(H(d)===0)return d;let f=u(1);if(H(f)===1)return f;let p=0,m=1;for(let e=0;e<64;e+=1){let e=(p+m)/2,t=u(e),n=H(t)-e;if(Math.abs(n)<1e-14)return t;n>0?p=e:m=e}return u((p+m)/2)},oe=(e,t,n,r=1)=>{if(n===-1&&r===1&&B(t.shape))return ae(e,t);{let i=e=>(t[e]-V[e])*n,a=i(`spacing`)/2,o=[{x:i(`positionXLeft`)-a,y:i(`positionYLeft`),w:`widthLeft`,h:`heightLeft`,a:`leftAngle`},{x:i(`positionXRight`)+a,y:i(`positionYRight`),w:`widthRight`,h:`heightRight`,a:`rightAngle`}],s=((t.widthLeft+t.widthRight)/(V.widthLeft+V.widthRight))**n,c=((t.heightLeft+t.heightRight)/(V.heightLeft+V.heightRight))**n,l=(o[0].x+o[1].x)/2,u=(o[0].y+o[1].y)/2+(t.glyphY??0)*n,d=B(t.shape)?H(e):0;return e.map((e,t)=>{let n=o[t],a=n?r*(1-d):r,f=n?{x:e.x+n.x,y:e.y+n.y,width:Math.max(0,e.width+i(n.w)),height:Math.max(0,e.height+i(n.h)),angle:e.angle+i(n.a)}:{x:e.x+l,y:e.y+u,width:e.width*s,height:e.height*c,angle:e.angle},p={...e,x:e.x+l,y:e.y+u};return{x:f.x+(p.x-f.x)*a,y:f.y+(p.y-f.y)*a,width:f.width+(p.width-f.width)*a,height:f.height+(p.height-f.height)*a,angle:f.angle+(p.angle-f.angle)*a,...e.bend===void 0?{}:{bend:e.bend}}})}},se=e=>{if(e.marks)return e.marks;let t=t=>{let n=t<0?`Left`:`Right`;return{x:t*e.spacing/2+e[`positionX${n}`],y:e[`positionY${n}`],width:e[`width${n}`],height:e[`height${n}`],angle:t<0?e.leftAngle:e.rightAngle}},[n,r]=[t(-1),t(1)],i={x:(n.x+r.x)/2,y:(n.y+r.y)/2,width:0,height:0,angle:0};return[n,r,...Array.from({length:2},()=>i)]},ce=(e,t)=>t?e.map(e=>{let n=t[e.id];if(!n)return e;let r=n.turn??0,a=Math.cos(i(r)),o=Math.sin(i(r)),s=n.scale??1,[c,l,u]=e.position,d=e.follow?.hinge,f=d?c+d[0]:0,p=d?l+d[1]:0;return{...e,surface:s===1?e.surface:{...e.surface,width:e.surface.width*s,height:e.surface.height*s,depth:e.surface.depth*s},position:[f+(c-f)*a-(l-p)*o+(n.x??0),p+(c-f)*o+(l-p)*a+(n.y??0),u],rotation:[e.rotation[0],e.rotation[1],e.rotation[2]+r]}}):e,le=e=>({expression:e,orientation:c(i(e.headX),i(e.headY),i(e.headZ))}),ue=e=>e<.5,U=e=>Math.min(1,Math.max(0,e)),de=(e,t)=>({...t,body:e.bodyColor??t.body,eyes:e.eyeColor??t.eyes}),fe=1-(1+2*Math.PI)*Math.exp(-2*Math.PI),pe={decay:6,frequency:8},me={decay:4.2,frequency:12},he=1-Math.exp(-me.decay)*Math.cos(me.frequency),ge=({decay:e,frequency:t},n)=>1-Math.exp(-e*n)*Math.cos(t*n),_e=(e,t)=>{let n=Math.min(Math.max(t,0),1);if(e===`cut`)return+(n>0);if(e===`linear`)return n;if(e===`snappy`)return 1-(1-n)**5;if(e===`glide`){let e=2*Math.PI*n;return(1-(1+e)*Math.exp(-e))/fe}return e===`spring`?ge(pe,n):e===`bounce`?ge(me,n)/he:1-(1-n)**4},ve=e=>{let t=Math.min(Math.max(e,0),1);return t<.4?(1+Math.cos(Math.PI*t/.4))/2:t<.5?0:(1-Math.cos(Math.PI*(t-.5)/.5))/2},ye=e=>e*e*(3-2*e);function W(e){let t=Math.sin(e*127.1+311.7)*43758.5453;return(t-Math.floor(t))*2-1}function G(e,t,n,r){let i=e/r,a=Math.floor(i),o=W(a*3+t+n);return o+(W((a+1)*3+t+n)-o)*ye(i-a)}function be(e,t){let n=Math.floor(e/1100),r=t+17.29,i=n===0?0:W((n-1)*2+r);return i+(W(n*2+r)-i)*ye(Math.min(1,(e-n*1100)/140))}function xe(e,t,n,r,i){let a=t[n],o=t[n+1],s=t[n+2],c=t[n+3],l=e/1e3;if(a&&(t[r]+=1.5*a*be(e,0),t[r+1]+=.9*a*be(e,1)),o&&(t[r]+=(Math.sin(l*47)+.45*Math.sin(l*71))*1.2*o,t[r+1]+=(Math.sin(l*59)+.4*Math.sin(l*83))*.8*o),s){let n=t[0]*.71+t[1]*1.13+t[2]*1.37;t[i]=1.45*G(e,3,n,2900)*s,t[i+1]=1.1*G(e,4,n,3700)*s,t[0]+=.8*G(e,0,n,2600)*s,t[1]+=1.15*G(e,1,n,3300)*s,t[2]+=.45*G(e,2,n,4100)*s}if(c){let e=Math.sin(l*31)+.45*Math.sin(l*53),n=Math.sin(l*37)+.4*Math.sin(l*61);t[i]+=e*1.35*c,t[i+1]+=n*1.1*c,t[0]+=e*1.15*c,t[1]+=n*1.35*c,t[2]+=.7*Math.sin(l*43)*c}return!!(a||o||s||c)}var K=[...ee,...L],q=[`x`,`y`,`width`,`height`,`angle`,`bend`],Se=[`x`,`y`,`turn`,`scale`],Ce=e=>Math.min(1,Math.max(0,e));function we(e){let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}function Te(e){let t=Ce(e);return Math.round(255*(t<=.0031308?12.92*t:1.055*t**(1/2.4)-.055))}function Ee(e,t,n){let r=parseInt(e.slice(1),16);t[n]=we(r>>16),t[n+1]=we(r>>8&255),t[n+2]=we(r&255)}function De(e,t){return Te(e[t])*65536+Te(e[t+1])*256+Te(e[t+2])}var Oe=e=>`#`+e.toString(16).padStart(6,`0`),ke=e=>[...new Set(e)];function Ae(e){let t=Object.values(e.expressions),n=ke(t.flatMap(e=>Object.keys(e.pieces??{}))),r=ke(t.flatMap(e=>e.headGesture?[e.headGesture]:[])),i=ke(t.flatMap(e=>e.markMotion?[e.markMotion]:[])),a=t.some(e=>e.marks||e.markMotion),o=t.some(e=>e.glyphApart&&e.marks),s=[],c=[],l=[];function u(e=-1/0,t=1/0,n=!1){return l.push(n),c.push(t),s.push(e)-1}for(let e of K){let t=e===`lidLeft`||e===`lidRight`||e.startsWith(`lowerLid`),n=e.startsWith(`lidTilt`);u(n?-80:t||e.startsWith(`width`)||e.startsWith(`height`)?0:-1/0,n?80:t?1:1/0,e.startsWith(`head`)||e.endsWith(`Angle`)||n)}let d=s.length;for(let e=0;e<6;e++)u(0,1);let f=s.length,p=[];for(let e of n)for(let e of Se){let t=u(e===`scale`?0:-1/0,1/0,e===`turn`);e===`scale`&&p.push(t)}let m=s.length;r.forEach(()=>u(0,1));let h=s.length;i.forEach(()=>u(0,1));let g=u(0,1),_=u(0,1),v=s.length;if(a)for(let e=0;e<4*(o?2:1);e++)for(let e of q)u(e===`width`||e===`height`?0:-1/0,1/0,e===`angle`&&!o);let y=o?8:0;function b(e,t,n){for(let r=0;r<y;r++){let i=v+r*q.length+4,a=r<4?1-e[_]:e[_],o=n?.[r]??0;if(t){let s=r<4?1-t[_]:t[_];o=a>0&&s>0?360*Math.round((t[i]/s-e[i]/a)/360):0,n&&(n[r]=o)}e[i]+=a*o}}let x=s.length,S=[`x`,`y`,`z`,`offsetX`,`offsetY`,`grow`,`stretch`,`flap`];if(r.length)for(let e of S)u(-1/0,1/0,e===`x`||e===`y`||e===`z`);let C=u(-1,1);u(-1,1),u(0,1);let T=u(),E=u(),D=u(),O=u(),k=s.length;for(let e=0;e<4;e++)u(0,1);let A=s.length,j=new Uint8Array(A);for(let e of p)j[e]=1;function M(e,t){if(!t)return;let n=1-e[C+2];e[C]+=n*t.x,e[C+1]+=n*t.y,e[C+2]=1}function N(e,t,n){return n?(t[0]=t[1]=t[2]=0,t.fill(0,m,g),!1):xe(e,t,k,T,D)}function P(t){let o=new Float64Array(A);for(let e=0;e<K.length;e++)o[e]=t[K[e]]??0;Ee(t.bodyColor??e.file.avatar.colors.body,o,d),Ee(t.eyeColor??e.file.avatar.colors.eyes,o,d+3);let s=f;for(let e of n)for(let n of Se)o[s++]=t.pieces?.[e]?.[n]??+(n===`scale`);if(t.headGesture&&(o[m+r.indexOf(t.headGesture)]=t.headGestureAmount??1),t.markMotion&&(o[h+i.indexOf(t.markMotion)]=1),o[k]=Number(t.eyeMotion===`microSaccades`),o[k+1]=Number(t.eyeMotion===`shake`),o[k+2]=Number(t.bodyMotion===`slowDrift`),o[k+3]=Number(t.bodyMotion===`shake`),o[g]=+!!t.marks,o[_]=t.glyphApart&&t.marks?1:0,a){s=v+o[_]*4*q.length;for(let e of se(t))for(let t of q)o[s++]=e[t]??0}return o}function F(){let t={...e.expressions.neutral,headGesture:void 0,markMotion:void 0},s=Object.create(null);for(let e of n)s[e]={};n.length&&(t.pieces=s);let c={},l={},u=Array.from({length:4},()=>({x:0,y:0,width:0,height:0,angle:0,bend:0})),p={},y=u.map(e=>({...e})),b={},C={x:0,y:0,z:0,offsetX:0,offsetY:0,grow:0,stretch:0,flap:0},T=new Float64Array(6).fill(-1),E=-1,D=-1;return{expression:t,activate(e,t){for(let n=0;n<r.length;n++)p[r[n]]=t[m+n]>0?l[r[n]]??0:e},resolveMarks(e,t){if(!i.length)return;let n=!1;for(let e=0;e<i.length;e++){let r=t[h+e];b[i[e]]=r,r>0&&(n=!0)}if(!(!n||!a))for(let n=0;n<(o?2:1);n++){let r=n===0?1-t[_]:t[_];if(r<=0)continue;let i=v+n*4*q.length;for(let e of y)for(let n of q)e[n]=t[i++]/r;let a=I(y,b,e);i=v+n*4*q.length;for(let e of a)for(let n of q)t[i++]=(e[n]??0)*r}},resolveGestures(e,t,n,i){for(let a=0;a<r.length;a++){let o=t[m+a];if(o<=0)continue;let s=r[a],c=i(a,e);l[s]=c>0?n+c:p[s]??n;let u=w(s,Math.max(0,e-(l[s]??0)));for(let e=0;e<S.length;e++)t[x+e]+=u[S[e]]*Math.min(1,o)}},write(e,o){for(let n=0;n<K.length;n++)t[K[n]]=e[n];for(let n=0;n<6;n+=3){let r=d+n;if(T[n]===e[r]&&T[n+1]===e[r+1]&&T[n+2]===e[r+2])continue;T[n]=e[r],T[n+1]=e[r+1],T[n+2]=e[r+2];let i=De(e,r);n===0&&i!==E&&(E=i,t.bodyColor=Oe(i)),n===3&&i!==D&&(D=i,t.eyeColor=Oe(i))}let p=f;for(let t of n)for(let n of Se)s[t][n]=e[p++];let y=!1,b=!1;for(let t=0;t<r.length;t++)c[r[t]]=e[m+t],e[m+t]>0&&(y=!0);for(let t=0;t<i.length;t++)e[h+t]>0&&(b=!0);let w=y;if(r.length)for(let t=0;t<S.length;t++){let n=e[x+t];C[S[t]]=n,n!==0&&(w=!0)}t.sampledGesture=w?C:void 0,t.sampledGestureTime=o,t.headGestureMix=y?c:void 0,t.headGestureStarts=y?l:void 0;let O=Ce(e[_]),k=O>=.5,A=k?1:Ce((e[g]-O)/(1-O));if(t.glyphHandover=O>0?O:void 0,t.glyphApart=k?!0:void 0,t.glyphWeight=A,t.marks=a&&(A>0||b)?u:void 0,t.marks){p=v+(k?4*q.length:0);let t=k?O:1-O;for(let n of u)for(let r of q)n[r]=e[p++]/t}return y||b}}}return{size:A,angles:l,scaled:j,min:s,max:c,encode:P,colors:d,writer:F,gesture:m,gestureCount:r.length,weightedAngles:y,alignMarks:b,inheritGaze:M,style:N,gaze:C,eyeX:T,eyeY:E,bodyX:D,bodyY:O}}function J(e,t,n){let r=e-t;return n&&Math.abs(r)>180?(r%360+540)%360-180:r}function je(e,t){let n=Math.imul(e^t,73244475);return n=Math.imul(n^n>>>16,73244475),((n^n>>>16)>>>0)/4294967296}function Y(e,t,n,r){return e===0?0:e*(n+r)/2+(je(e,t)-.5)*(r-n)/2}function Me(e,t){let n=-1,r=e.length;for(;n+1<r;){let i=n+r>>>1;e[i]<=t?n=i:r=i}return n}function Ne(e,t,n,r){let i=-1/0,a=1/0;if(e.mode!==`off`)switch(e.mode){case`once`:t>=e.delayMs?i=e.delayMs:a=e.delayMs;break;case`times`:{let n=Me(e.atMs,t);i=e.atMs[n]??-1/0,a=e.atMs[n+1]??1/0;break}case`interval`:{let n=e.initialDelayMs??e.everyMs;t<n?a=n:(i=n+Math.floor((t-n)/e.everyMs)*e.everyMs,a=i+e.everyMs);break}case`random`:{let r=e.initialDelayMs??e.minMs+je(0,n)*(e.maxMs-e.minMs);if(t<r)a=r;else{let o=t-r,s=Math.max(0,Math.floor(o/((e.minMs+e.maxMs)/2)));Y(s,n,e.minMs,e.maxMs)>o?s--:Y(s+1,n,e.minMs,e.maxMs)<=o&&s++,i=r+Y(s,n,e.minMs,e.maxMs),a=r+Y(s+1,n,e.minMs,e.maxMs)}break}}r.start=i,r.next=a}function Pe(e,t,n,r,i){Ne(e,t,n,r);let a=r.start,o=r.next;if(r.openness=1,t-a>=i){r.next=o-t;return}Ne(e,t-i*.45,n,r);let s=ve((t-r.start)/i),c=ve((t-r.next)/i);c<s&&(r.start=r.next),r.openness=Math.min(s,c),r.openness===1&&(r.start=a),r.next=0}function Fe(e,t){let n=e-t,r=Math.round(n);return Math.abs(r-n)<=Math.min(1e-6,2*2**-52*Math.max(1,Math.abs(e),Math.abs(t)))?r:n}function X(e,t){let n=0,r=e.visits.length;for(;n+1<r;){let i=n+r>>>1;e.visits[i].start<=t?n=i:r=i}return n}var Ie=new WeakMap;function Le(e,t){let n=Ie.get(e);n||Ie.set(e,n=new WeakMap);let r=n.get(t);if(r)return r;let i=[];for(let n of e.visits)for(let e=Me(t.atMs,n.forwardStart-1)+1;e<t.atMs.length;e++){let r=t.atMs[e]-n.forwardStart;if(r>=n.length)break;i.push(n.start+r)}let a={...t,atMs:i};return n.set(t,a),a}function Re(e,t,n,r){if(`pose`in e)return;e.policy&&(r.policy=e.policy,r.since=n,r.cycle=1/0);let i=Fe(t,n),a=e.once&&i>=e.duration,o=e.once?Math.min(i,e.duration):(i+e.skip)%e.duration,s=n+(e.once?0:i-o);r.policy.mode===`times`&&r.since===n&&r.cycle===1/0&&(r.policy=Le(e,r.policy),r.since=s,r.cycle=e.duration);let c=e.visits[X(e,o)],l=s+c.start;!a&&(e.visits.length>1||!(`pose`in c.track)||r.policy.mode===`times`||c.state?.blink)&&(r.next=Math.min(r.next,l+c.length)),r.quiet||=c.quiet,c.state?.blink&&(r.policy=c.state.blink,r.since=Math.max(l,n),r.cycle=1/0);let u=r.next;Re(c.track,a?n+e.duration:t,Math.max(l,n),r),a&&(r.next=u)}function ze(e,t,n){if(`pose`in e||!e.hasQuiet||n<=t)return!1;let r=e.duration;if(e.once&&t>=r){let t=e.visits[e.visits.length-1];return t.quiet||ze(t.track,t.length,t.length+1)}let i=e.once?t:(t+e.skip)%r,a=e.once?Math.min(n,r):i+Math.min(n-t,r);for(let t=0;t<2;t++){let n=t===0?i:0,o=Math.min(r,a-t*r);if(o<=n)break;for(let t=X(e,n);t<e.visits.length;t++){let r=e.visits[t];if(r.start>=o)break;if(r.length&&(r.quiet||ze(r.track,Math.max(0,n-r.start),Math.min(r.length,o-r.start))))return!0}}return!1}function Z(e,t,n){if(`pose`in e)return 0;let r=e.once?Math.min(t,e.duration):(t+e.skip)%e.duration,i=e.visits[X(e,r)],a=e.once?0:t-r,o=Z(i.track,Math.min(t,r-i.start),n);return Math.max(0,a+(o>0?i.start+o:i.carry[n]))}function Be(e,t,n,r,i,a=0,o=0){if(`pose`in e)return n.set(e.pose),1/0;let{duration:s,once:c,visits:l}=e,u=c&&t>=s,d=c?Math.min(s,t):(t+e.skip)%s,f=X(e,d),p=l[f],m=d-p.start,h=Be(p.track,Math.min(t,m),n,r,u?void 0:i,a+(u?s:t)-Math.min(t,m),o);if(r.inheritGaze(n,p.state?.gaze),u||!c&&l.length===1&&`pose`in p.track)return 1/0;let g=o?Math.min(o,p.length):p.entry;if(i){let e=m<g?g:p.length;i.boundary=Math.min(i.boundary,a+t-m+e)}if(m<g&&(f>0||t+e.skip>=s)&&(o||p.curve!==`cut`)){let e=l[(f+l.length-1)%l.length].end;r.weightedAngles&&r.alignMarks(n,e);let t=m/g,i=o?t*t*(3-2*t):_e(p.curve,t);for(let t=0;t<n.length;t++){let a=r.scaled[t]?z(e[t],n[t],i):i;n[t]=Math.max(r.min[t],Math.min(r.max[t],e[t]+J(n[t],e[t],r.angles[t])*a))}h=0}return Math.min(h,p.length-m)}function Ve(e){let t=Ae(e),n=new Map(Object.entries(e.expressions).map(([e,n])=>[e,{pose:t.encode(n)}])),r=new Map;function i(t){let r=e.states[t];return r.expression===void 0?a(r.sequence):n.get(r.expression)}function a(a){let o=r.get(a);if(o)return o;let s=e.sequences[a],c=0,l=s.steps.map(r=>{let a=r.expression===void 0?i(r.state):n.get(r.expression),o=r.transitionMs??180,s=o+r.holdMs,l=new Float64Array(t.size);Be(a,s,l,t);let u=r.state===void 0?void 0:e.states[r.state];t.inheritGaze(l,u?.gaze);let d=c;return c+=s,{track:a,entry:o,length:s,curve:r.transition,end:l,forwardStart:d,state:u,quiet:r.blink===!1}}),u=s.mode===`pingPong`?[...l,...l.slice(1,-1).reverse()]:l,d=0,f=u.map(e=>{let n=d;return d+=e.length,{...e,start:n,carry:new Float64Array(t.gestureCount)}});for(let e=0;e<t.gestureCount;e++){let n=-1/0;for(let r=s.mode===`once`?0:-1;r<=0;r++)for(let i of f){let a=r*d+i.start;i.carry[e]=n;let o=Z(i.track,i.length,e);o>0&&(n=a+o),i.end[t.gesture+e]<=0&&(n=a+i.length)}}let p={visits:f,duration:d,once:s.mode===`once`,skip:s.mode===`once`?0:l[0].entry,policy:s.blink,hasQuiet:l.some(e=>e.quiet||`hasQuiet`in e.track&&e.track.hasQuiet)};return r.set(a,p),p}let o=new Map(e.stateNames.map(e=>[e,i(e)]));return Object.keys(e.sequences).forEach(a),{model:e,channels:t,expressions:n,states:o,sequences:r}}var He=.001;function Q(e,t){let n=()=>new Float64Array(e.size),r=e.weightedAngles?new Float64Array(e.weightedAngles):void 0,i=n(),a=n(),o=n(),s=n(),c=n(),l=n(),u=n(),d=0,f=0,p=1/0,m={boundary:1/0};function h(e,n){return m.boundary=1/0,t(e,n,m)}function g(t,n){let i=h(t,n);if(t>=f)return i;r&&e.alignMarks(n,null,r);let a=f-d,o=(t-d)/a,p=(1+2*o)*(1-o)**2,m=o*(1-o)**2*a;for(let t=0;t<n.length;t++){let r=p,i=m;e.scaled?.[t]&&c[t]&&(r=1-z(s[t]+c[t],n[t],1-p),i=p>0?m*r/p:0),n[t]=Math.max(e.min[t],Math.min(e.max[t],n[t]+u[t]+r*c[t]+i*l[t]))}return 0}function _(t,n){d=t,f=n,h(t,s),m.boundary<=t&&h(t+Math.max(1e-9,Math.abs(t)*2**-52),s),p=m.boundary>t?m.boundary:1/0;let g=Math.min(He,(p-t)/2);h(t+g,o),r&&(e.alignMarks(s,i,r),e.alignMarks(o,null,r));for(let t=0;t<s.length;t++){let n=e.angles[t];c[t]=J(i[t],s[t],n),u[t]=i[t]-s[t]-c[t],l[t]=a[t]-(g>0?J(o[t],s[t],n)/g:0)}}function v(t){if(!(t>=f))for(;p<=t&&p<f;){let t=p,n=Math.min(He,(t-d)/3);g(t-2*n,o),g(t-n,i);for(let t=0;t<i.length;t++)a[t]=J(i[t],o[t],e.angles[t])/n,i[t]=i[t]+n*a[t];_(t,f)}}function y(t){v(t),g(t,i);let n=Math.min(He,(m.boundary-t)/2,t<f?(f-t)/2:1/0);g(t+n,o);for(let t=0;t<a.length;t++)a[t]=n>0?J(o[t],i[t],e.angles[t])/n:0}return{fromDisplayed(e,t,n){i.set(n),a.fill(0),_(e,t)},capture:y,begin:_,sample(e,t){return v(e),g(e,t)}}}var Ue={size:1,min:[0],max:[1],angles:[!1]};function We(e,t,n,r,i){let a={openness:1,next:1/0,start:-1/0},o=null,s=0,c=``,l=-1/0,u=160,d=new Float64Array(1),f=new Float64Array(1),p=Q(Ue,(c,l,u)=>{let d=t(c),f=o??d.policy,p=o?s:d.since,m=i()?Math.min(160,f.mode===`off`?160:f.durationMs??160):f.mode===`off`?160:f.durationMs??160;Pe(f,c-p,e^(p|0),a,m);let h=d.quiet||a.start!==-1/0&&a.next===0&&ze(n(),Math.max(0,p+a.start-r()),p+a.start-r()+m);return l[0]=h?1:a.openness,u.boundary=d.next,Math.min(d.next-c,h&&a.next===0?Math.max(1,p+a.start+m-c):a.next)}),m=Q(Ue,(e,t)=>{let n=e-l;return t[0]=n<u*.5?0:ve(n/u),n<u?0:1/0}),h={openness:1,next:1/0};return{captureMotion(e){p.capture(e),m.capture(e)},finishMotion(e){if(p.begin(e,e+80),i()&&u>160&&e<l+u){let t=(e-l)/u;u=160,l=e-t*u,m.begin(e,e+Math.min(80,(1-t)*u))}},capture:p.capture,begin:e=>p.begin(e,e+80),set(e,t){let n=e&&e.mode!==`off`?{...e,durationMs:e.durationMs??160}:e,r=n?JSON.stringify(n,Object.keys(n).sort()):``;r!==c&&(p.capture(t),c=r,o=n?JSON.parse(r):null,s=t,p.begin(t,t+80))},blink(e){m.capture(e);let n=o??t(e).policy;u=i()||n.mode===`off`?160:n.durationMs??160,l=e,m.begin(e,e+u*.4)},sample(e){return h.next=Math.min(p.sample(e,d),m.sample(e,f)),h.openness=Math.min(d[0],f[0]),h}}}var Ge={size:3,min:[-1,-1,0],max:[1,1,1],angles:[!1,!1,!1]};function Ke(e){let t=e.file.avatar.body.primary,n=(t.geometry??e.file.geometry?.[t.geometryIndex])?.sockets,r=new Float64Array(3),i=new Float64Array(3),a=Q(Ge,(e,t)=>(t.set(r),1/0)),o=0,s={x:0,y:0},c=e.file.avatar.eyes??V;function l(r,i,a){let o=1,l=r*r+i*i;if(l>0){let s=a.marks&&e.file.avatar.eyes?oe(a.marks,c,1,a.glyphWeight??1):a.marks,u=a.spacing+c.spacing-V.spacing;for(let e=0;e<(s?.length??2);e++){let d=e===0?`Left`:`Right`,f=s?.[e],p=f?.x??(e===0?-u:u)/2+a[`positionX${d}`]+c[`positionX${d}`],m=f?.y??a[`positionY${d}`]+c[`positionY${d}`]+7,h=f?.width??Math.max(10,a[`width${d}`]+c[`width${d}`]-20),g=f?.height??Math.max(10,a[`height${d}`]+c[`height${d}`]-50);if(h<=0||g<=0)continue;r&&(o=Math.min(o,Math.max(0,(t.width/2-h/2-Math.sign(r)*p)/Math.abs(r)))),i&&(o=Math.min(o,Math.max(0,(t.height/2-g/2-Math.sign(i)*m)/Math.abs(i))));let _=n?.centers[e];if(!_||a.glyphApart)continue;let v=p-_[0]*t.width,y=m-_[1]*t.width,b=Math.max(0,n.apertureRadius*t.width-Math.max(h,g)/2),x=v*r+y*i,S=Math.max(0,b*b-v*v-y*y),C=(Math.sqrt(x*x+l*S)-x)/l;o=Math.min(o,C+(1-C)*(a.glyphWeight??0))}}s.x=o*r,s.y=o*i}return{offset:s,retime(e,t){e>=o||(a.capture(e),o=e+(t?360:160),a.begin(e,o))},look(e,t,n){let i=Math.max(-1,Math.min(1,e?.x??0)),s=Math.max(-1,Math.min(1,e?.y??0)),c=+!!e;(r[0]!==i||r[1]!==s||r[2]!==c)&&(a.capture(t),r[0]=i,r[1]=s,r[2]=c,o=t+(n?360:160),a.begin(t,o))},sample(e,n,r,o,s,c){let u=a.sample(e,i),d=1-i[2],f=(d*n+i[0])*t.width*.1+o,p=(d*r+i[1])*t.height*.1+s;return l(Math.min(t.width*.1,Math.max(-t.width*.1,f)),Math.min(t.height*.1,Math.max(-t.height*.1,p)),c),u}}}var qe=e({createCursor:()=>Xe,createPlayback:()=>Ze,prepare:()=>Ye}),Je=new WeakMap,$=new WeakMap;function Ye(e){if(e&&typeof e==`object`){let t=$.get(e);if(t)return t}let t=n(e),r=$.get(t);if(r)return r;let i=Object.freeze({avatar:t});return Je.set(i,Ve(t)),$.set(t,i),$.set(t.file,i),e&&typeof e==`object`&&$.set(e,i),i}function Xe(e,n={},r){let i=Je.get(e);if(!i)throw TypeError(`Use prepare() to create a playback model.`);let{model:a,channels:o,states:s,sequences:c,expressions:l}=i,u=a.file.initial,d=s.get(u),f=0,p=0,m=!1,h=n.motion??`full`,g={policy:a.blink,since:0,next:1/0,quiet:!1,cycle:1/0};function _(e){let t=u===void 0?void 0:a.states[u];return g.policy=t?.blink??a.blink,g.since=f,g.next=1/0,g.quiet=!1,g.cycle=1/0,Re(d,e,f,g),g}let v=We(n.seed??Math.floor(Math.random()*4294967296),_,()=>d,()=>f,()=>h===`reduced`),y=Ke(a),b={x:0,y:0},x=new Float64Array(o.size),S=o.writer(),C=(e,t)=>Z(d,Fe(t,f),e);function w(e,t,n,r){let i=Be(d,Fe(e,f),t,o,n,f,r);return o.inheritGaze(t,u===void 0?void 0:a.states[u]?.gaze),i}let T=new Float64Array(2);function E(){let e=new Float64Array(o.size);return Q({size:2,angles:[!1,!1],min:[-1,-1],max:[1,1]},(t,n,r)=>{let i=w(t,e,r,h===`reduced`?360:0);return n[0]=e[o.gaze],n[1]=e[o.gaze+1],i})}let D=Object.values(a.states).some(e=>e.gaze)?E():void 0,O=Q(o,(e,t,n)=>{let r=w(e,t,n,h===`reduced`?80:0),i=o.style(e,t,h===`reduced`);return S.resolveMarks(e,t),S.resolveGestures(e,t,f,C),i?0:r}),k={expression:S.expression,blink:1,eyeOffset:y.offset,bodyOffset:b,half:a.file.poster.half,time:0},A={frame:k,nextTime:1/0,geometryStable:!1},j,M={blink:1,x:0,y:0},N={blink:0,x:0,y:0},P=0,F=0;function I(e){if(m)throw Error(`Playback disposed.`);if(!Number.isFinite(e)||e<p)throw RangeError(`Use monotonic milliseconds.`);p=e,A.geometryStable=!1,A.nextTime=e+O.sample(e,x),S.write(x,e)&&(A.nextTime=e);let t=v.sample(e);k.blink=t.openness,b.x=x[o.bodyX],b.y=x[o.bodyY];let n=D?.sample(e,T)??1/0,r=y.sample(e,T[0],T[1],x[o.eyeX],x[o.eyeY],k.expression);A.nextTime=Math.min(A.nextTime,e+t.next,e+r,e+n),k.time=e}function L(e){return I(e),r?.(e),A}function R(e,t,n){if(!e)throw Error(`Missing compiled track.`);I(n),D?.capture(n),v.capture(n),O.capture(n),d=e,u=t,S.activate(n,x),f=n,v.begin(n);let r=t?a.states[t]?.entryMs??180:180;O.begin(n,n+(h===`reduced`?80:r)),D?.begin(n,n+(h===`reduced`?360:r))}function z(e,t,n,r){(j??=new Float64Array(x.length)).set(e),M.blink=t,M.x=n,M.y=r}return{sample:L,sampleDisplay(e,t,n=!1){let r=t&&!!j;if(r&&(P=e,F=e+(h===`reduced`?80:(u===void 0?void 0:a.states[u]?.entryMs)??180),O.fromDisplayed(e,F,j)),L(e),r&&(N.blink=M.blink-k.blink,N.x=M.x-k.eyeOffset.x,N.y=M.y-k.eyeOffset.y),e<F){let t=(e-P)/(F-P),n=(1+2*t)*(1-t)**2;k.blink=Math.max(0,Math.min(1,k.blink+n*N.blink)),k.eyeOffset.x+=n*N.x,k.eyeOffset.y+=n*N.y,A.nextTime=e}return A.geometryStable=j!==void 0&&k.blink===M.blink&&k.eyeOffset.x===M.x&&k.eyeOffset.y===M.y&&!k.expression.sampledGesture&&x.every((e,t)=>t>=o.gaze||t>=o.colors&&t<o.colors+6||e===j[t]),n||z(x,k.blink,k.eyeOffset.x,k.eyeOffset.y),A},pendingDisplay(){let e=x.slice(),t=k.blink,{x:n,y:r}=k.eyeOffset;return()=>z(e,t,n,r)},set(e,n){if(s.has(e)||t(`states`,e,[...s.keys()]),e===u){L(n);return}R(s.get(e),e,n)},expression(e,n){l.has(e)||t(`expressions`,e,[...l.keys()]),R(l.get(e),void 0,n)},sequence(e,n){c.has(e)||t(`sequences`,e,[...c.keys()]),R(c.get(e),void 0,n)},look(e,t){L(t),y.look(e,t,h===`reduced`)},setBlink(e,t){L(t),v.set(e,t)},blink(e){L(e),v.blink(e)},setMotion(e,t){L(t),e!==h&&(O.capture(t),D?.capture(t),v.captureMotion(t),y.retime(t,e===`reduced`),h=e,D?.begin(t,t+(e===`reduced`?360:160)),v.finishMotion(t),O.begin(t,t+80))},dispose(){m=!0}}}function Ze(e,t={}){let n=e.avatar,i=r(n,t.onSequenceEnd),{sequence:a,...o}=Xe(e,t,i.settle);return{...o,get completionTime(){return i.deadline},settle:i.settle,set(e,t){let r=i.state!==e;o.set(e,t),r&&i.select(e,n.states[e]?.sequence,t)},expression(e,t){o.expression(e,t),i.select(void 0,void 0,t)},async play(e,t){return a(e,t),i.play(e,t)},dispose(){o.dispose(),i.dispose()}}}var Qe=new WeakMap;function $e(e){let t=Qe.get(e);if(t)return t;let n=e.file;function r({geometryIndex:e,...t}){let r=e===void 0?t.geometry:n.geometry[e];return{...t,geometry:r}}return t={...n.avatar,body:{primary:r(n.avatar.body.primary),nodes:n.avatar.body.nodes.map(e=>({...e,surface:r(e.surface)}))}},Qe.set(e,t),t}function et(e,t=!0){let{primary:n,nodes:r}=e.file.avatar.body;return!(t&&!r.length&&n.type===`sphere`&&!n.rotationCenter&&n.width===n.height&&n.width===n.depth&&n.width>=1&&n.width<=620&&Object.values(e.expressions).every(e=>e.perspective===1))}export{f as C,l as S,E as _,Ye as a,i as b,se as c,ce as d,re as f,T as g,p as h,qe as i,H as l,I as m,et as n,de as o,D as p,Ze as r,ue as s,$e as t,le as u,u as v,d as x,c as y};
|
|
1
|
+
import{t as e}from"./rolldown-runtime-DK3Fl9T5.js";import{s as t,t as n}from"./reader-JcTNbEkh.js";import{t as r}from"./runs-BIIveHSZ.js";var i=e=>e*Math.PI/180,a=([e,t,n,r])=>{let i=Math.hypot(e,t,n,r)||1;return[e/i,t/i,n/i,r/i]},o=([e,t,n,r],[i,o,s,c])=>a([e*i-t*o-n*s-r*c,e*o+t*i+n*c-r*s,e*s-t*c+n*i+r*o,e*c+t*s-n*o+r*i]),s=([e,t,n],r)=>{let i=Math.sin(r/2);return a([Math.cos(r/2),e*i,t*i,n*i])},c=(e,t,n)=>o(o(s([0,0,1],n),s([1,0,0],e)),s([0,1,0],t)),l=([e,t,n,r],i=new Float64Array(9))=>(i[0]=1-2*(n*n+r*r),i[1]=2*(t*n-e*r),i[2]=2*(t*r+e*n),i[3]=2*(t*n+e*r),i[4]=1-2*(t*t+r*r),i[5]=2*(n*r-e*t),i[6]=2*(t*r-e*n),i[7]=2*(n*r+e*t),i[8]=1-2*(t*t+n*n),i),u=(e,t)=>{let n=new Float64Array(9);for(let r=0;r<3;r+=1)for(let i=0;i<3;i+=1)n[r*3+i]=e[r*3]*t[i]+e[r*3+1]*t[3+i]+e[r*3+2]*t[6+i];return n},d=(e,[t,n,r])=>[e[0]*t+e[1]*n+e[2]*r,e[3]*t+e[4]*n+e[5]*r,e[6]*t+e[7]*n+e[8]*r],f=(e,t=[0,0,0])=>{let n=d(e,t);return[t[0]-n[0],t[1]-n[1],t[2]-n[2]]},p={x:1,y:1},m=Math.PI*2,h={x:0,y:0,z:0,offsetX:0,offsetY:0,grow:0,stretch:0,flap:0},g=e=>{let t=1+Math.max(-.5,e.grow),n=1+Math.max(-.5,e.stretch);return{x:t/n,y:t*n}},_=e=>{if(e.headGestureMix)return e.headGestureMix;if(e.headGesture)return{[e.headGesture]:e.headGestureAmount??1}},v=(e,t)=>e<=0?0:1-Math.exp(-t*e)*(Math.cos(t*e)+Math.sin(t*e)),y=(e,t,n,r=14)=>e<=0?0:Math.exp(-t*e)*Math.sin(m*n*e)*(1-Math.exp(-r*e)),b=(e,t,n)=>{let r=(e-t)/n;return r<=0||r>=1?0:Math.sin(Math.PI*r)**2},x=(e,t,n,r)=>{let i=Math.min(1,Math.max(0,(e-t)/n));return i<.5?2**(r-1)*i**r:1-(2-2*i)**r/2},S=(e,t,n)=>{if(e<=0)return 0;if(e>=t)return 1;let r=e=>1-(1+n*e)*Math.exp(-n*e);return r(e)/r(t)},C=e=>((e+180)%360+360)%360-180,w=(e,t,n)=>{let r=t/1e3,i=e=>n&&n>0?n/1e3/Math.max(1,Math.round(n/1e3/e)):e,a=e=>{let t=i(e);return{since:(r%t+t)%t,length:t}},o=(e,t=0)=>m*(r/i(1/e))+t,s=(e,t,n)=>n.reduce((n,[r,i])=>n+i*v(e-r,t),0);switch(e){case`nod`:{let{since:e}=a(2),t=y(e,2.4,1.7,12);return{...h,x:-15*t,offsetY:2*t}}case`headShake`:{let{since:e}=a(2.2);return{...h,y:20*y(e,2.8,2.3,16),z:-4*y(e-.07,2.8,2.3,16)}}case`wiggle`:return{...h,z:9*Math.sin(o(1.5)),y:5*Math.sin(o(1.5,-.5)),offsetY:-3.5*(.5-.5*Math.cos(o(3)))};case`twirl`:{let{since:e}=a(4.4),t=(t,n)=>n*(360*S(e-t,1.2,5.5)-16*b(e,t-.28,.56)),n=t=>b(e,t,1.1),r=(t,n)=>n*7*b(e,t,1.3);return{...h,y:t(.3,1)+t(2.5,-1),z:r(.3,1)+r(2.5,-1),offsetY:-10*(n(.3)+n(2.5))}}case`lookAround`:{let{since:e}=a(5.6),t=s(e,7,[[.3,26],[1.6,-2],[2.9,-48],[4.3,24]]),n=s(e,7,[[1.6,13],[2.9,-10],[4.3,-3]]);return{...h,x:n,y:t,z:-.15*t}}case`hop`:{let e=Math.sin(o(.575)),t=Math.abs(Math.cos(o(.575)));return{...h,x:3*Math.abs(e),z:4*e,offsetY:-13*Math.abs(e),stretch:.07*t-.15*(1-Math.abs(e))**10}}case`tilt`:{let{since:e}=a(4.8);return{...h,z:s(e,5.5,[[.2,15],[1.7,-15],[2.5,-11],[3.9,11]]),x:s(e,5.5,[[.2,4],[1.7,-4],[2.5,3],[3.9,-3]])}}case`dance`:return{...h,z:8*Math.sin(o(1)),y:7*Math.sin(o(.5,.6)),x:2*Math.sin(o(2,1)),offsetY:-3.5*(.5-.5*Math.cos(o(2)))};case`bow`:{let{since:e}=a(3.8),t=s(e,6,[[.3,1],[1.5,-1]]);return{...h,x:-24*t,offsetY:5*t}}case`eagerNod`:{let{since:e}=a(2.2),t=(t,n)=>n*(b(e,t,.42)-.25*b(e,t-.16,.2)),n=t(.2,1)+t(.68,.8);return{...h,x:-20*n,offsetY:4*n}}case`peek`:{let{since:e}=a(4.2),t=s(e,6,[[.3,1],[2.2,-1]]);return{...h,z:14*t,y:10*t,offsetX:16*t,offsetY:3*t}}case`shrug`:{let{since:e}=a(3.2),t=s(e,9,[[.25,1],[1.2,-1]]);return{...h,z:-8*t,x:4*t,offsetY:-9*t}}case`recoil`:{let{since:e}=a(3),t=v(e-.1,14)-v(e-.9,4);return{...h,x:14*t,offsetY:-6*t-6*b(e,.1,.35),stretch:.05*b(e,.1,.35)}}case`doubleTake`:{let{since:e}=a(4.6),t=v(e-1.4,13)-v(e-2.6,7),n=s(e,6,[[.3,16],[.9,-16]])+26*t;return{...h,y:n,x:8*t,z:-.15*n,offsetY:-5*b(e,1.4,.4)}}case`eyeRoll`:{let{since:e}=a(4.2),t=s(e,6,[[.3,-10],[.8,10],[1.3,10],[2.3,-10]]),n=s(e,6,[[.3,-4],[.8,18],[1.3,-16],[2.3,2]]);return{...h,x:n,y:t,z:.4*t,offsetY:3*b(e,1.5,1.5)}}case`dizzy`:{let{since:e,length:t}=a(4),n=b(e,0,t),r=m*3*e/t;return{...h,x:9*n*Math.sin(r),y:12*n*Math.cos(r),z:7*n*Math.cos(r-.6),offsetX:3*n*Math.cos(r)}}case`sneeze`:{let{since:e}=a(3.8),t=s(e,6,[[.3,7],[.85,7]])-30*v(e-1.55,16)+16*v(e-2,7);return{...h,x:t,y:5*y(e-1.65,3.5,3,16),offsetY:5*b(e,1.5,.5)-2*b(e,.3,1.2)}}case`yawn`:{let{since:e}=a(4.4),t=s(e,3.6,[[.2,1],[1.7,-1.25],[2.4,.25]]),n=1.5*Math.sin(m*6*e)*b(e,.7,1);return{...h,x:16*t,z:4*t+n,offsetY:-4*t}}case`shiver`:{let{since:e,length:t}=a(3),n=b(e,0,.45*t)+.7*b(e,.5*t,.45*t),r=b(e,0,t),i=m*8*e;return{...h,x:-3*r,y:3.5*n*Math.sin(i),z:1.5*n*Math.sin(i+1.2),offsetY:3*r}}case`tickTock`:{let{since:e}=a(4.6),t=s(e,14,[[.2,6],[.7,-12],[1.2,12],[1.7,-12],[2.2,6]]),n=b(e,2.4,.9);return{...h,z:t,y:.3*t,x:-7*n,offsetY:3*n}}case`bashful`:{let{since:e}=a(4.8),t=s(e,5,[[.2,1],[2,-.6],[2.7,-.4]]),n=4*Math.sin(m*(e-.7)/.65)*b(e,.7,1.3);return{...h,y:-16*t,x:-8*t,z:-6*t+n,offsetY:2*t}}case`roll`:{let{since:e}=a(4);return{...h,y:C(-18*b(e,0,.5)+360*S(e-.22,1.3,5.5))}}case`flip`:{let{since:e}=a(4),t=v(e,12)-v(e-.3,12);return{...h,x:C(-14*t+360*S(e-.28,1.3,5.5)),offsetY:18*b(e,.05,1)}}case`spin`:{let{since:e}=a(4);return{...h,y:C(28*b(e,0,.7)-720*S(e-.3,2.1,3.6))}}case`bounce`:{let{since:e}=a(3),t=v(e,14)-v(e-.27,16);return{...h,offsetY:-2*b(e,.25,.3),stretch:-.1*t+.11*b(e,.25,.3)-.04*b(e,.58,.34)}}case`breathe`:{let{since:e,length:t}=a(3.8),n=.42*t,r=e<n?e/n:1-(e-n)/(t-n),i=.08*(1-Math.cos(Math.PI*r))/2;return{...h,grow:i,offsetY:115*i,flap:40*i}}case`shrink`:{let{since:e}=a(4),t=v(e,11)*(1-x(e,3.2,.7,2));return{...h,grow:-.18*t,stretch:-.04*t,offsetY:-24*t}}case`stomp`:{let e=Math.sin(o(.6)),t=e*e;return{...h,z:6*e,y:4*e,x:-3*t,offsetY:5*t,stretch:-.05*t**3}}case`sway`:{let e=Math.sin(o(.45));return{...h,z:10*e,y:6*Math.sin(o(.45,-.6)),offsetX:4*e,offsetY:3*(1-e*e)}}case`earFlap`:{let{since:e,length:t}=a(2),n=b(e,0,t),r=(1-Math.cos(m*4*e/t))/2,i=Math.sin(m*e/t);return{...h,flap:10*n*r,x:3*n,y:9*n*i,z:5*n*i,offsetY:-1.5*n*r*r}}case`shakeOff`:{let{since:e}=a(2.6);return{...h,y:12*y(e,3.2,4.8,20),z:6*y(e-.05,3.2,4.8,20),offsetY:-2.5*y(e,3.2,9.6,20),flap:5*y(e-.08,3.2,4.8,20)}}}},T=(e,t,n)=>{if(e.sampledGesture&&e.sampledGestureTime===t)return e.sampledGesture;let r=_(e);if(!r)return e.sampledGesture?h:void 0;let i={...h};for(let[a,o]of Object.entries(r)){if(!(o>0))continue;let r=e.headGestureStarts?.[a],s=e.headGestureRates?.[a]??1,c=r===void 0?w(a,t*s,n===void 0?void 0:n*s):w(a,Math.max(0,t-r)*s),l=Math.min(1,o);i.x+=c.x*l,i.y+=c.y*l,i.z+=c.z*l,i.offsetX+=c.offsetX*l,i.offsetY+=c.offsetY*l,i.grow+=c.grow*l,i.stretch+=c.stretch*l,i.flap+=c.flap*l}return i},E=(e,t,n)=>{let r=T(e.expression,t,n);if(!r)return{pose:e,offset:{x:0,y:0},squash:p};let a=c(i(r.x),i(r.y),i(r.z));return{pose:{...e,orientation:o(e.orientation,a)},offset:{x:r.offsetX,y:r.offsetY},squash:r.grow||r.stretch?g(r):p}},D=e=>{if(e.markMotionMix)return e.markMotionMix;if(e.markMotion)return{[e.markMotion]:e.markMotionAmount??1}},O=Math.PI*2,k=e=>e.width>.5&&e.height>.5,A=9,j=e=>e<=0?0:1-Math.exp(-9*e)*(Math.cos(A*e)+Math.sin(A*e)),M=(e,t,n,r,i=r)=>({...e,x:t+(e.x-t)*r,y:n+(e.y-n)*i,width:e.width*r,height:e.height*i,...e.bend===void 0?{}:{bend:e.bend*i/r}}),N=(e,t,n,r)=>{let i=r*Math.PI/180,a=e.x-t,o=e.y-n;return{...e,x:t+a*Math.cos(i)-o*Math.sin(i),y:n+a*Math.sin(i)+o*Math.cos(i),angle:e.angle+r}},P=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n,width:e.width+(t.width-e.width)*n,height:e.height+(t.height-e.height)*n,angle:e.angle+(t.angle-e.angle)*n,...e.bend!==void 0||t.bend!==void 0?{bend:(e.bend??0)+((t.bend??0)-(e.bend??0))*n}:{}}),F=(e,t,n,r,i)=>{if(n<=0)return[...e];let a=r/1e3,o=e=>i&&i>0?Math.max(1,Math.round(e*i/1e3))/(i/1e3):e,s=(e,t=0)=>O*o(e)*a+t,c=e.map((e,t)=>({mark:e,index:t})).filter(({mark:e})=>k(e)).sort((e,t)=>e.mark.x-t.mark.x),l=new Map(c.map(({index:e},t)=>[e,t])),u=c.map(({mark:e})=>e),d=u.length?u.reduce((e,t)=>e+t.x,0)/u.length:0,f=u.length?u.reduce((e,t)=>e+t.y,0)/u.length:0,p=u.length?Math.min(...u.map(e=>e.y-Math.max(e.width,e.height)/2)):f,m=(e,n)=>{let r=l.get(n)??0;switch(t){case`drift`:{let t=3.5*Math.sin(s(.21))+1.5*Math.sin(s(.53,1)),n=2.5*Math.sin(s(.17,2));return{...e,x:e.x+t,y:e.y+n}}case`scan`:return{...e,x:e.x+12*Math.sin(s(.42)),y:e.y+1.5*Math.sin(s(.84))};case`wave`:{let t=r*.95,n=1+(.26+.08*Math.sin(s(.23)))*Math.sin(s(1.05,-t))+.09*Math.sin(s(2.1,.7-2*t));return M(e,e.x,e.y,1,Math.max(.3,n))}case`talk`:{let t=r*.8,n=1+(.62+.24*Math.sin(s(.37))+.14*Math.sin(s(.71,1.3)))*(.46*Math.sin(s(2.3,-t))+.14*Math.sin(s(4.6,.9-2*t)));return M(e,e.x,e.y,1,Math.max(.3,n))}case`bounce`:{let t=s(.95,-r*1.1),n=.5-.5*Math.cos(t),i=11*n**1.6,a=.1*Math.abs(Math.sin(t))*n**.6,o={...e,y:e.y-i};return M(o,o.x,o.y,1-a/2,1+a)}case`type`:{let t=[...u].sort((e,t)=>e.y-t.y).indexOf(e),n=1/o(.32),r=((a/n+.5)%1+1)%1,i=j((r-.02-t*.11)*n)-j((r-.6-t*.07)*n),s=Math.min(e.height,e.width);return{...e,width:Math.max(s*.6,s+(e.width-s)*i)}}case`orbit`:{let t=N(e,d,f,360*o(.75)*a),n=[1.15,.92,.7][r]??1;return{...t,angle:e.angle,width:e.width*n,height:e.height*n}}case`pulse`:{let t=1+.16*(.5-.5*Math.cos(s(.8)));return M(e,d,f,t)}case`breathe`:return M(e,d,f,1+.045*Math.sin(s(.35)));case`sway`:{let t=Math.max(0,e.y-p)/60;return N(e,d,p,9*Math.sin(s(.75,-.45*t)))}case`shake`:{let t=1/o(1/2.2),n=(a%t+t)%t,r=Math.exp(-4.5*n)*Math.sin(O*5.5*n);return N({...e,x:e.x+10*r},d,f,3*r)}case`hop`:{let t=Math.abs(Math.cos(s(.55,e.x>d?-.35:0))),n=Math.max(0,1-t/.22),r={...e,y:e.y-9*t};return M(r,r.x,r.y+r.height/2,1+.07*n,1-.12*n)}case`beat`:{let t=1/o(1/1.1),n=(a%t+t)%t,r=(e,r)=>{let i=n-e-t*Math.round((n-e)/t);return Math.exp(-((i/r)**2))},i=1+.14*r(.12,.07)+.08*r(.34,.08)+.012*Math.sin(s(.6));return M(e,d,f,i)}case`twinkle`:{let t=Math.atan2(e.y-f,e.x-d),n=1+.3*Math.sin(s(.8,t));return{...N(e,d,f,8*Math.sin(s(.2))),width:e.width*n,height:e.height*n}}case`rise`:case`fall`:{let n=t===`rise`?-1:1,r=.5-.5*Math.cos(s(.85)),i=n*8*r**1.4,a=1+.04*Math.abs(Math.sin(s(.85)));return M({...e,y:e.y+i},d,f+i,a)}}};return e.map((e,t)=>k(e)?P(e,m(e,t),Math.min(1,n)):e)},I=(e,t,n,r)=>{let i=Object.entries(t).filter(([,e])=>e>0);if(i.length===1)return F(e,i[0][0],i[0][1],n,r);let a=e.map(e=>({...e}));for(let[t,o]of i)F(e,t,o,n,r).forEach((t,n)=>{let r=e[n],i=a[n];i.x+=t.x-r.x,i.y+=t.y-r.y,i.width+=t.width-r.width,i.height+=t.height-r.height,i.angle+=t.angle-r.angle,(r.bend!==void 0||t.bend!==void 0)&&(i.bend=(i.bend??0)+(t.bend??0)-(r.bend??0))});return a},L=[`lidLeft`,`lidRight`,`lidTiltLeft`,`lidTiltRight`,`lowerLidLeft`,`lowerLidRight`],R=1/5,z=(e,t,n)=>{let r=.010000001;return t<=r&&e>r?Math.min(1,Math.max(0,n/R)):e<=r&&t>r?Math.min(1,Math.max(0,1-(1-n)/R)):n},ee=[`headX`,`headY`,`headZ`,`widthLeft`,`widthRight`,`heightLeft`,`heightRight`,`spacing`,`positionXLeft`,`positionXRight`,`positionYLeft`,`positionYRight`,`leftAngle`,`rightAngle`,`perspective`],te={id:`neutral`,headX:0,headY:0,headZ:0,widthLeft:20,widthRight:20,heightLeft:50,heightRight:50,spacing:35,positionXLeft:0,positionXRight:0,positionYLeft:-7,positionYRight:-7,leftAngle:0,rightAngle:0,perspective:1},B=e=>e===`ellipse`||e===`circle`,ne=[`widthLeft`,`widthRight`,`heightLeft`,`heightRight`,`spacing`,`positionXLeft`,`positionXRight`,`positionYLeft`,`positionYRight`,`leftAngle`,`rightAngle`],V=Object.fromEntries(ne.map(e=>[e,te[e]])),re=(e,t=V)=>{let n={...e};return ne.forEach(r=>{n[r]=e[r]+t[r]-V[r]}),n.widthLeft=Math.max(10,n.widthLeft),n.widthRight=Math.max(10,n.widthRight),n.heightLeft=Math.max(10,n.heightLeft),n.heightRight=Math.max(10,n.heightRight),e.marks&&(n.marks=oe(e.marks,t,1,e.glyphWeight??1)),B(t.shape)&&(n.eyeShape=`ellipse`),n},ie=e=>((e+90)%180+180)%180-90,H=e=>{let[t,n,...r]=e;if(!t||!n||e.some(e=>e.bend))return 0;let i=Math.max(t.width,t.height,n.width,n.height,1),a=Math.max(t.width,n.width,1),o=U(1-r.reduce((e,t)=>Math.max(e,t.width,t.height),0)/(i*.25)),s=U((25-Math.max(Math.abs(ie(t.angle)),Math.abs(ie(n.angle))))/15),c=U(1-Math.abs(t.y-n.y)/(i*.5)),l=U(1-Math.abs(t.width-n.width)/(i*.4))*U(1-Math.abs(t.height-n.height)/(i*.4)),u=U((Math.abs(t.x-n.x)/a-1)/.5);return o*s*c*l*u},ae=(e,t)=>{let n=[t.positionXLeft-V.positionXLeft,t.positionXRight-V.positionXRight],r=[t.positionYLeft-V.positionYLeft,t.positionYRight-V.positionYRight],i=(t.spacing-V.spacing)/2,a=(n[0]+n[1])/2,o=(r[0]+r[1])/2+(t.glyphY??0),s=[t.widthLeft-V.widthLeft,t.widthRight-V.widthRight],c=[t.heightLeft-V.heightLeft,t.heightRight-V.heightRight],l=[t.leftAngle-V.leftAngle,t.rightAngle-V.rightAngle],u=t=>e.map((e,u)=>{if(u>=2)return{...e,x:e.x-a,y:e.y-o};let d=(e,n)=>{let r=e-t*n;return Math.max(0,n>=0||r+n>=0||t===1?r:e/(1-t))},f=n[u]+(u===0?-i:i);return{...e,x:e.x-t*f-(1-t)*a,y:e.y-t*r[u]-(1-t)*o,width:d(e.width,s[u]),height:d(e.height,c[u]),angle:e.angle-t*l[u]}}),d=u(0);if(H(d)===0)return d;let f=u(1);if(H(f)===1)return f;let p=0,m=1;for(let e=0;e<64;e+=1){let e=(p+m)/2,t=u(e),n=H(t)-e;if(Math.abs(n)<1e-14)return t;n>0?p=e:m=e}return u((p+m)/2)},oe=(e,t,n,r=1)=>{if(n===-1&&r===1&&B(t.shape))return ae(e,t);{let i=e=>(t[e]-V[e])*n,a=i(`spacing`)/2,o=[{x:i(`positionXLeft`)-a,y:i(`positionYLeft`),w:`widthLeft`,h:`heightLeft`,a:`leftAngle`},{x:i(`positionXRight`)+a,y:i(`positionYRight`),w:`widthRight`,h:`heightRight`,a:`rightAngle`}],s=((t.widthLeft+t.widthRight)/(V.widthLeft+V.widthRight))**n,c=((t.heightLeft+t.heightRight)/(V.heightLeft+V.heightRight))**n,l=(o[0].x+o[1].x)/2,u=(o[0].y+o[1].y)/2+(t.glyphY??0)*n,d=B(t.shape)?H(e):0;return e.map((e,t)=>{let n=o[t],a=n?r*(1-d):r,f=n?{x:e.x+n.x,y:e.y+n.y,width:Math.max(0,e.width+i(n.w)),height:Math.max(0,e.height+i(n.h)),angle:e.angle+i(n.a)}:{x:e.x+l,y:e.y+u,width:e.width*s,height:e.height*c,angle:e.angle},p={...e,x:e.x+l,y:e.y+u};return{x:f.x+(p.x-f.x)*a,y:f.y+(p.y-f.y)*a,width:f.width+(p.width-f.width)*a,height:f.height+(p.height-f.height)*a,angle:f.angle+(p.angle-f.angle)*a,...e.bend===void 0?{}:{bend:e.bend}}})}},se=e=>{if(e.marks)return e.marks;let t=t=>{let n=t<0?`Left`:`Right`;return{x:t*e.spacing/2+e[`positionX${n}`],y:e[`positionY${n}`],width:e[`width${n}`],height:e[`height${n}`],angle:t<0?e.leftAngle:e.rightAngle}},[n,r]=[t(-1),t(1)],i={x:(n.x+r.x)/2,y:(n.y+r.y)/2,width:0,height:0,angle:0};return[n,r,...Array.from({length:2},()=>i)]},ce=(e,t)=>t?e.map(e=>{let n=t[e.id];if(!n)return e;let r=n.turn??0,a=Math.cos(i(r)),o=Math.sin(i(r)),s=n.scale??1,[c,l,u]=e.position,d=e.follow?.hinge,f=d?c+d[0]:0,p=d?l+d[1]:0;return{...e,surface:s===1?e.surface:{...e.surface,width:e.surface.width*s,height:e.surface.height*s,depth:e.surface.depth*s},position:[f+(c-f)*a-(l-p)*o+(n.x??0),p+(c-f)*o+(l-p)*a+(n.y??0),u],rotation:[e.rotation[0],e.rotation[1],e.rotation[2]+r]}}):e,le=e=>({expression:e,orientation:c(i(e.headX),i(e.headY),i(e.headZ))}),ue=e=>e<.5,U=e=>Math.min(1,Math.max(0,e)),de=(e,t)=>({...t,body:e.bodyColor??t.body,eyes:e.eyeColor??t.eyes}),fe=1-(1+2*Math.PI)*Math.exp(-2*Math.PI),pe={decay:6,frequency:8},me={decay:4.2,frequency:12},he=1-Math.exp(-me.decay)*Math.cos(me.frequency),ge=({decay:e,frequency:t},n)=>1-Math.exp(-e*n)*Math.cos(t*n),_e=(e,t)=>{let n=Math.min(Math.max(t,0),1);if(e===`cut`)return+(n>0);if(e===`linear`)return n;if(e===`snappy`)return 1-(1-n)**5;if(e===`glide`){let e=2*Math.PI*n;return(1-(1+e)*Math.exp(-e))/fe}return e===`spring`?ge(pe,n):e===`bounce`?ge(me,n)/he:1-(1-n)**4},ve=e=>{let t=Math.min(Math.max(e,0),1);return t<.4?(1+Math.cos(Math.PI*t/.4))/2:t<.5?0:(1-Math.cos(Math.PI*(t-.5)/.5))/2},ye=e=>e*e*(3-2*e);function W(e){let t=Math.sin(e*127.1+311.7)*43758.5453;return(t-Math.floor(t))*2-1}function G(e,t,n,r){let i=e/r,a=Math.floor(i),o=W(a*3+t+n);return o+(W((a+1)*3+t+n)-o)*ye(i-a)}function be(e,t){let n=Math.floor(e/1100),r=t+17.29,i=n===0?0:W((n-1)*2+r);return i+(W(n*2+r)-i)*ye(Math.min(1,(e-n*1100)/140))}function xe(e,t,n,r,i){let a=t[n],o=t[n+1],s=t[n+2],c=t[n+3],l=e/1e3;if(a&&(t[r]+=1.5*a*be(e,0),t[r+1]+=.9*a*be(e,1)),o&&(t[r]+=(Math.sin(l*47)+.45*Math.sin(l*71))*1.2*o,t[r+1]+=(Math.sin(l*59)+.4*Math.sin(l*83))*.8*o),s){let n=t[0]*.71+t[1]*1.13+t[2]*1.37;t[i]=1.45*G(e,3,n,2900)*s,t[i+1]=1.1*G(e,4,n,3700)*s,t[0]+=.8*G(e,0,n,2600)*s,t[1]+=1.15*G(e,1,n,3300)*s,t[2]+=.45*G(e,2,n,4100)*s}if(c){let e=Math.sin(l*31)+.45*Math.sin(l*53),n=Math.sin(l*37)+.4*Math.sin(l*61);t[i]+=e*1.35*c,t[i+1]+=n*1.1*c,t[0]+=e*1.15*c,t[1]+=n*1.35*c,t[2]+=.7*Math.sin(l*43)*c}return!!(a||o||s||c)}var K=[...ee,...L],q=[`x`,`y`,`width`,`height`,`angle`,`bend`],Se=[`x`,`y`,`turn`,`scale`],Ce=e=>Math.min(1,Math.max(0,e));function we(e){let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}function Te(e){let t=Ce(e);return Math.round(255*(t<=.0031308?12.92*t:1.055*t**(1/2.4)-.055))}function Ee(e,t,n){let r=parseInt(e.slice(1),16);t[n]=we(r>>16),t[n+1]=we(r>>8&255),t[n+2]=we(r&255)}function De(e,t){return Te(e[t])*65536+Te(e[t+1])*256+Te(e[t+2])}var Oe=e=>`#`+e.toString(16).padStart(6,`0`),ke=e=>[...new Set(e)];function Ae(e){let t=Object.values(e.expressions),n=ke(t.flatMap(e=>Object.keys(e.pieces??{}))),r=ke(t.flatMap(e=>e.headGesture?[e.headGesture]:[])),i=ke(t.flatMap(e=>e.markMotion?[e.markMotion]:[])),a=t.some(e=>e.marks||e.markMotion),o=t.some(e=>e.glyphApart&&e.marks),s=[],c=[],l=[];function u(e=-1/0,t=1/0,n=!1){return l.push(n),c.push(t),s.push(e)-1}for(let e of K){let t=e===`lidLeft`||e===`lidRight`||e.startsWith(`lowerLid`),n=e.startsWith(`lidTilt`);u(n?-80:t||e.startsWith(`width`)||e.startsWith(`height`)?0:-1/0,n?80:t?1:1/0,e.startsWith(`head`)||e.endsWith(`Angle`)||n)}let d=s.length;for(let e=0;e<6;e++)u(0,1);let f=s.length,p=[];for(let e of n)for(let e of Se){let t=u(e===`scale`?0:-1/0,1/0,e===`turn`);e===`scale`&&p.push(t)}let m=s.length;r.forEach(()=>u(0,1));let h=s.length;i.forEach(()=>u(0,1));let g=u(0,1),_=u(0,1),v=s.length;if(a)for(let e=0;e<4*(o?2:1);e++)for(let e of q)u(e===`width`||e===`height`?0:-1/0,1/0,e===`angle`&&!o);let y=o?8:0;function b(e,t,n){for(let r=0;r<y;r++){let i=v+r*q.length+4,a=r<4?1-e[_]:e[_],o=n?.[r]??0;if(t){let s=r<4?1-t[_]:t[_];o=a>0&&s>0?360*Math.round((t[i]/s-e[i]/a)/360):0,n&&(n[r]=o)}e[i]+=a*o}}let x=s.length,S=[`x`,`y`,`z`,`offsetX`,`offsetY`,`grow`,`stretch`,`flap`];if(r.length)for(let e of S)u(-1/0,1/0,e===`x`||e===`y`||e===`z`);let C=u(-1,1);u(-1,1),u(0,1);let T=u(),E=u(),D=u(),O=u(),k=s.length;for(let e=0;e<4;e++)u(0,1);let A=s.length,j=new Uint8Array(A);for(let e of p)j[e]=1;function M(e,t){if(!t)return;let n=1-e[C+2];e[C]+=n*t.x,e[C+1]+=n*t.y,e[C+2]=1}function N(e,t,n){return n?(t[0]=t[1]=t[2]=0,t.fill(0,m,g),!1):xe(e,t,k,T,D)}function P(t){let o=new Float64Array(A);for(let e=0;e<K.length;e++)o[e]=t[K[e]]??0;Ee(t.bodyColor??e.file.avatar.colors.body,o,d),Ee(t.eyeColor??e.file.avatar.colors.eyes,o,d+3);let s=f;for(let e of n)for(let n of Se)o[s++]=t.pieces?.[e]?.[n]??+(n===`scale`);if(t.headGesture&&(o[m+r.indexOf(t.headGesture)]=t.headGestureAmount??1),t.markMotion&&(o[h+i.indexOf(t.markMotion)]=1),o[k]=Number(t.eyeMotion===`microSaccades`),o[k+1]=Number(t.eyeMotion===`shake`),o[k+2]=Number(t.bodyMotion===`slowDrift`),o[k+3]=Number(t.bodyMotion===`shake`),o[g]=+!!t.marks,o[_]=t.glyphApart&&t.marks?1:0,a){s=v+o[_]*4*q.length;for(let e of se(t))for(let t of q)o[s++]=e[t]??0}return o}function F(){let t={...e.expressions.neutral,headGesture:void 0,markMotion:void 0},s=Object.create(null);for(let e of n)s[e]={};n.length&&(t.pieces=s);let c={},l={},u=Array.from({length:4},()=>({x:0,y:0,width:0,height:0,angle:0,bend:0})),p={},y=u.map(e=>({...e})),b={},C={x:0,y:0,z:0,offsetX:0,offsetY:0,grow:0,stretch:0,flap:0},T=new Float64Array(6).fill(-1),E=-1,D=-1;return{expression:t,activate(e,t){for(let n=0;n<r.length;n++)p[r[n]]=t[m+n]>0?l[r[n]]??0:e},resolveMarks(e,t){if(!i.length)return;let n=!1;for(let e=0;e<i.length;e++){let r=t[h+e];b[i[e]]=r,r>0&&(n=!0)}if(!(!n||!a))for(let n=0;n<(o?2:1);n++){let r=n===0?1-t[_]:t[_];if(r<=0)continue;let i=v+n*4*q.length;for(let e of y)for(let n of q)e[n]=t[i++]/r;let a=I(y,b,e);i=v+n*4*q.length;for(let e of a)for(let n of q)t[i++]=(e[n]??0)*r}},resolveGestures(e,t,n,i){for(let a=0;a<r.length;a++){let o=t[m+a];if(o<=0)continue;let s=r[a],c=i(a,e);l[s]=c>0?n+c:p[s]??n;let u=w(s,Math.max(0,e-(l[s]??0)));for(let e=0;e<S.length;e++)t[x+e]+=u[S[e]]*Math.min(1,o)}},write(e,o){for(let n=0;n<K.length;n++)t[K[n]]=e[n];for(let n=0;n<6;n+=3){let r=d+n;if(T[n]===e[r]&&T[n+1]===e[r+1]&&T[n+2]===e[r+2])continue;T[n]=e[r],T[n+1]=e[r+1],T[n+2]=e[r+2];let i=De(e,r);n===0&&i!==E&&(E=i,t.bodyColor=Oe(i)),n===3&&i!==D&&(D=i,t.eyeColor=Oe(i))}let p=f;for(let t of n)for(let n of Se)s[t][n]=e[p++];let y=!1,b=!1;for(let t=0;t<r.length;t++)c[r[t]]=e[m+t],e[m+t]>0&&(y=!0);for(let t=0;t<i.length;t++)e[h+t]>0&&(b=!0);let w=y;if(r.length)for(let t=0;t<S.length;t++){let n=e[x+t];C[S[t]]=n,n!==0&&(w=!0)}t.sampledGesture=w?C:void 0,t.sampledGestureTime=o,t.headGestureMix=y?c:void 0,t.headGestureStarts=y?l:void 0;let O=Ce(e[_]),k=O>=.5,A=k?1:Ce((e[g]-O)/(1-O));if(t.glyphHandover=O>0?O:void 0,t.glyphApart=k?!0:void 0,t.glyphWeight=A,t.marks=a&&(A>0||b)?u:void 0,t.marks){p=v+(k?4*q.length:0);let t=k?O:1-O;for(let n of u)for(let r of q)n[r]=e[p++]/t}return y||b}}}return{size:A,angles:l,scaled:j,min:s,max:c,encode:P,colors:d,writer:F,gesture:m,gestureCount:r.length,weightedAngles:y,alignMarks:b,inheritGaze:M,style:N,gaze:C,eyeX:T,eyeY:E,bodyX:D,bodyY:O}}function J(e,t,n){let r=e-t;return n&&Math.abs(r)>180?(r%360+540)%360-180:r}function je(e,t){let n=Math.imul(e^t,73244475);return n=Math.imul(n^n>>>16,73244475),((n^n>>>16)>>>0)/4294967296}function Y(e,t,n,r){return e===0?0:e*(n+r)/2+(je(e,t)-.5)*(r-n)/2}function Me(e,t){let n=-1,r=e.length;for(;n+1<r;){let i=n+r>>>1;e[i]<=t?n=i:r=i}return n}function Ne(e,t,n,r){let i=-1/0,a=1/0;if(e.mode!==`off`)switch(e.mode){case`once`:t>=e.delayMs?i=e.delayMs:a=e.delayMs;break;case`times`:{let n=Me(e.atMs,t);i=e.atMs[n]??-1/0,a=e.atMs[n+1]??1/0;break}case`interval`:{let n=e.initialDelayMs??e.everyMs;t<n?a=n:(i=n+Math.floor((t-n)/e.everyMs)*e.everyMs,a=i+e.everyMs);break}case`random`:{let r=e.initialDelayMs??e.minMs+je(0,n)*(e.maxMs-e.minMs);if(t<r)a=r;else{let o=t-r,s=Math.max(0,Math.floor(o/((e.minMs+e.maxMs)/2)));Y(s,n,e.minMs,e.maxMs)>o?s--:Y(s+1,n,e.minMs,e.maxMs)<=o&&s++,i=r+Y(s,n,e.minMs,e.maxMs),a=r+Y(s+1,n,e.minMs,e.maxMs)}break}}r.start=i,r.next=a}function Pe(e,t,n,r,i){Ne(e,t,n,r);let a=r.start,o=r.next;if(r.openness=1,t-a>=i){r.next=o-t;return}Ne(e,t-i*.45,n,r);let s=ve((t-r.start)/i),c=ve((t-r.next)/i);c<s&&(r.start=r.next),r.openness=Math.min(s,c),r.openness===1&&(r.start=a),r.next=0}function Fe(e,t){let n=e-t,r=Math.round(n);return Math.abs(r-n)<=Math.min(1e-6,2*2**-52*Math.max(1,Math.abs(e),Math.abs(t)))?r:n}function X(e,t){let n=0,r=e.visits.length;for(;n+1<r;){let i=n+r>>>1;e.visits[i].start<=t?n=i:r=i}return n}var Ie=new WeakMap;function Le(e,t){let n=Ie.get(e);n||Ie.set(e,n=new WeakMap);let r=n.get(t);if(r)return r;let i=[];for(let n of e.visits)for(let e=Me(t.atMs,n.forwardStart-1)+1;e<t.atMs.length;e++){let r=t.atMs[e]-n.forwardStart;if(r>=n.length)break;i.push(n.start+r)}let a={...t,atMs:i};return n.set(t,a),a}function Re(e,t,n,r){if(`pose`in e)return;e.policy&&(r.policy=e.policy,r.since=n,r.cycle=1/0);let i=Fe(t,n),a=e.once&&i>=e.duration,o=e.once?Math.min(i,e.duration):(i+e.skip)%e.duration,s=n+(e.once?0:i-o);r.policy.mode===`times`&&r.since===n&&r.cycle===1/0&&(r.policy=Le(e,r.policy),r.since=s,r.cycle=e.duration);let c=e.visits[X(e,o)],l=s+c.start;!a&&(e.visits.length>1||!(`pose`in c.track)||r.policy.mode===`times`||c.state?.blink)&&(r.next=Math.min(r.next,l+c.length)),r.quiet||=c.quiet,c.state?.blink&&(r.policy=c.state.blink,r.since=Math.max(l,n),r.cycle=1/0);let u=r.next;Re(c.track,a?n+e.duration:t,Math.max(l,n),r),a&&(r.next=u)}function ze(e,t,n){if(`pose`in e||!e.hasQuiet||n<=t)return!1;let r=e.duration;if(e.once&&t>=r){let t=e.visits[e.visits.length-1];return t.quiet||ze(t.track,t.length,t.length+1)}let i=e.once?t:(t+e.skip)%r,a=e.once?Math.min(n,r):i+Math.min(n-t,r);for(let t=0;t<2;t++){let n=t===0?i:0,o=Math.min(r,a-t*r);if(o<=n)break;for(let t=X(e,n);t<e.visits.length;t++){let r=e.visits[t];if(r.start>=o)break;if(r.length&&(r.quiet||ze(r.track,Math.max(0,n-r.start),Math.min(r.length,o-r.start))))return!0}}return!1}function Z(e,t,n){if(`pose`in e)return 0;let r=e.once?Math.min(t,e.duration):(t+e.skip)%e.duration,i=e.visits[X(e,r)],a=e.once?0:t-r,o=Z(i.track,Math.min(t,r-i.start),n);return Math.max(0,a+(o>0?i.start+o:i.carry[n]))}function Be(e,t,n,r,i,a=0,o=0){if(`pose`in e)return n.set(e.pose),1/0;let{duration:s,once:c,visits:l}=e,u=c&&t>=s,d=c?Math.min(s,t):(t+e.skip)%s,f=X(e,d),p=l[f],m=d-p.start,h=Be(p.track,Math.min(t,m),n,r,u?void 0:i,a+(u?s:t)-Math.min(t,m),o);if(r.inheritGaze(n,p.state?.gaze),u||!c&&l.length===1&&`pose`in p.track)return 1/0;let g=o?Math.min(o,p.length):p.entry;if(i){let e=m<g?g:p.length;i.boundary=Math.min(i.boundary,a+t-m+e)}if(m<g&&(f>0||t+e.skip>=s)&&(o||p.curve!==`cut`)){let e=l[(f+l.length-1)%l.length].end;r.weightedAngles&&r.alignMarks(n,e);let t=m/g,i=o?t*t*(3-2*t):_e(p.curve,t);for(let t=0;t<n.length;t++){let a=r.scaled[t]?z(e[t],n[t],i):i;n[t]=Math.max(r.min[t],Math.min(r.max[t],e[t]+J(n[t],e[t],r.angles[t])*a))}h=0}return Math.min(h,p.length-m)}function Ve(e){let t=Ae(e),n=new Map(Object.entries(e.expressions).map(([e,n])=>[e,{pose:t.encode(n)}])),r=new Map;function i(t){let r=e.states[t];return r.expression===void 0?a(r.sequence):n.get(r.expression)}function a(a){let o=r.get(a);if(o)return o;let s=e.sequences[a],c=0,l=s.steps.map(r=>{let a=r.expression===void 0?i(r.state):n.get(r.expression),o=r.transitionMs??180,s=o+r.holdMs,l=new Float64Array(t.size);Be(a,s,l,t);let u=r.state===void 0?void 0:e.states[r.state];t.inheritGaze(l,u?.gaze);let d=c;return c+=s,{track:a,entry:o,length:s,curve:r.transition,end:l,forwardStart:d,state:u,quiet:r.blink===!1}}),u=s.mode===`pingPong`?[...l,...l.slice(1,-1).reverse()]:l,d=0,f=u.map(e=>{let n=d;return d+=e.length,{...e,start:n,carry:new Float64Array(t.gestureCount)}});for(let e=0;e<t.gestureCount;e++){let n=-1/0;for(let r=s.mode===`once`?0:-1;r<=0;r++)for(let i of f){let a=r*d+i.start;i.carry[e]=n;let o=Z(i.track,i.length,e);o>0&&(n=a+o),i.end[t.gesture+e]<=0&&(n=a+i.length)}}let p={visits:f,duration:d,once:s.mode===`once`,skip:s.mode===`once`?0:l[0].entry,policy:s.blink,hasQuiet:l.some(e=>e.quiet||`hasQuiet`in e.track&&e.track.hasQuiet)};return r.set(a,p),p}let o=new Map(e.stateNames.map(e=>[e,i(e)]));return Object.keys(e.sequences).forEach(a),{model:e,channels:t,expressions:n,states:o,sequences:r}}var He=.001;function Q(e,t){let n=()=>new Float64Array(e.size),r=e.weightedAngles?new Float64Array(e.weightedAngles):void 0,i=n(),a=n(),o=n(),s=n(),c=n(),l=n(),u=n(),d=0,f=0,p=1/0,m={boundary:1/0};function h(e,n){return m.boundary=1/0,t(e,n,m)}function g(t,n){let i=h(t,n);if(t>=f)return i;r&&e.alignMarks(n,null,r);let a=f-d,o=(t-d)/a,p=(1+2*o)*(1-o)**2,m=o*(1-o)**2*a;for(let t=0;t<n.length;t++){let r=p,i=m;e.scaled?.[t]&&c[t]&&(r=1-z(s[t]+c[t],n[t],1-p),i=p>0?m*r/p:0),n[t]=Math.max(e.min[t],Math.min(e.max[t],n[t]+u[t]+r*c[t]+i*l[t]))}return 0}function _(t,n){d=t,f=n,h(t,s),m.boundary<=t&&h(t+Math.max(1e-9,Math.abs(t)*2**-52),s),p=m.boundary>t?m.boundary:1/0;let g=Math.min(He,(p-t)/2);h(t+g,o),r&&(e.alignMarks(s,i,r),e.alignMarks(o,null,r));for(let t=0;t<s.length;t++){let n=e.angles[t];c[t]=J(i[t],s[t],n),u[t]=i[t]-s[t]-c[t],l[t]=a[t]-(g>0?J(o[t],s[t],n)/g:0)}}function v(t){if(!(t>=f))for(;p<=t&&p<f;){let t=p,n=Math.min(He,(t-d)/3);g(t-2*n,o),g(t-n,i);for(let t=0;t<i.length;t++)a[t]=J(i[t],o[t],e.angles[t])/n,i[t]=i[t]+n*a[t];_(t,f)}}function y(t){v(t),g(t,i);let n=Math.min(He,(m.boundary-t)/2,t<f?(f-t)/2:1/0);g(t+n,o);for(let t=0;t<a.length;t++)a[t]=n>0?J(o[t],i[t],e.angles[t])/n:0}return{fromDisplayed(e,t,n){i.set(n),a.fill(0),_(e,t)},capture:y,begin:_,sample(e,t){return v(e),g(e,t)}}}var Ue={size:1,min:[0],max:[1],angles:[!1]};function We(e,t,n,r,i){let a={openness:1,next:1/0,start:-1/0},o=null,s=0,c=``,l=-1/0,u=160,d=new Float64Array(1),f=new Float64Array(1),p=Q(Ue,(c,l,u)=>{let d=t(c),f=o??d.policy,p=o?s:d.since,m=i()?Math.min(160,f.mode===`off`?160:f.durationMs??160):f.mode===`off`?160:f.durationMs??160;Pe(f,c-p,e^(p|0),a,m);let h=d.quiet||a.start!==-1/0&&a.next===0&&ze(n(),Math.max(0,p+a.start-r()),p+a.start-r()+m);return l[0]=h?1:a.openness,u.boundary=d.next,Math.min(d.next-c,h&&a.next===0?Math.max(1,p+a.start+m-c):a.next)}),m=Q(Ue,(e,t)=>{let n=e-l;return t[0]=n<u*.5?0:ve(n/u),n<u?0:1/0}),h={openness:1,next:1/0};return{captureMotion(e){p.capture(e),m.capture(e)},finishMotion(e){if(p.begin(e,e+80),i()&&u>160&&e<l+u){let t=(e-l)/u;u=160,l=e-t*u,m.begin(e,e+Math.min(80,(1-t)*u))}},capture:p.capture,begin:e=>p.begin(e,e+80),set(e,t){let n=e&&e.mode!==`off`?{...e,durationMs:e.durationMs??160}:e,r=n?JSON.stringify(n,Object.keys(n).sort()):``;r!==c&&(p.capture(t),c=r,o=n?JSON.parse(r):null,s=t,p.begin(t,t+80))},blink(e){m.capture(e);let n=o??t(e).policy;u=i()||n.mode===`off`?160:n.durationMs??160,l=e,m.begin(e,e+u*.4)},sample(e){return h.next=Math.min(p.sample(e,d),m.sample(e,f)),h.openness=Math.min(d[0],f[0]),h}}}var Ge={size:3,min:[-1,-1,0],max:[1,1,1],angles:[!1,!1,!1]};function Ke(e){let t=e.file.avatar.body.primary,n=(t.geometry??e.file.geometry?.[t.geometryIndex])?.sockets,r=new Float64Array(3),i=new Float64Array(3),a=Q(Ge,(e,t)=>(t.set(r),1/0)),o=0,s={x:0,y:0},c=e.file.avatar.eyes??V;function l(r,i,a){let o=1,l=r*r+i*i;if(l>0){let s=a.marks&&e.file.avatar.eyes?oe(a.marks,c,1,a.glyphWeight??1):a.marks,u=a.spacing+c.spacing-V.spacing;for(let e=0;e<(s?.length??2);e++){let d=e===0?`Left`:`Right`,f=s?.[e],p=f?.x??(e===0?-u:u)/2+a[`positionX${d}`]+c[`positionX${d}`],m=f?.y??a[`positionY${d}`]+c[`positionY${d}`]+7,h=f?.width??Math.max(10,a[`width${d}`]+c[`width${d}`]-20),g=f?.height??Math.max(10,a[`height${d}`]+c[`height${d}`]-50);if(h<=0||g<=0)continue;r&&(o=Math.min(o,Math.max(0,(t.width/2-h/2-Math.sign(r)*p)/Math.abs(r)))),i&&(o=Math.min(o,Math.max(0,(t.height/2-g/2-Math.sign(i)*m)/Math.abs(i))));let _=n?.centers[e];if(!_||a.glyphApart)continue;let v=p-_[0]*t.width,y=m-_[1]*t.width,b=Math.max(0,n.apertureRadius*t.width-Math.max(h,g)/2),x=v*r+y*i,S=Math.max(0,b*b-v*v-y*y),C=(Math.sqrt(x*x+l*S)-x)/l;o=Math.min(o,C+(1-C)*(a.glyphWeight??0))}}s.x=o*r,s.y=o*i}return{offset:s,retime(e,t){e>=o||(a.capture(e),o=e+(t?360:160),a.begin(e,o))},look(e,t,n){let i=Math.max(-1,Math.min(1,e?.x??0)),s=Math.max(-1,Math.min(1,e?.y??0)),c=+!!e;(r[0]!==i||r[1]!==s||r[2]!==c)&&(a.capture(t),r[0]=i,r[1]=s,r[2]=c,o=t+(n?360:160),a.begin(t,o))},sample(e,n,r,o,s,c){let u=a.sample(e,i),d=1-i[2],f=(d*n+i[0])*t.width*.1+o,p=(d*r+i[1])*t.height*.1+s;return l(Math.min(t.width*.1,Math.max(-t.width*.1,f)),Math.min(t.height*.1,Math.max(-t.height*.1,p)),c),u}}}var qe=e({createCursor:()=>Xe,createPlayback:()=>Ze,prepare:()=>Ye}),Je=new WeakMap,$=new WeakMap;function Ye(e){if(e&&typeof e==`object`){let t=$.get(e);if(t)return t}let t=n(e),r=$.get(t);if(r)return r;let i=Object.freeze({avatar:t});return Je.set(i,Ve(t)),$.set(t,i),$.set(t.file,i),e&&typeof e==`object`&&$.set(e,i),i}function Xe(e,n={},r){let i=Je.get(e);if(!i)throw TypeError(`Use prepare() to create a playback model.`);let{model:a,channels:o,states:s,sequences:c,expressions:l}=i,u=a.file.initial,d=s.get(u),f=0,p=0,m=!1,h=n.motion??`full`,g={policy:a.blink,since:0,next:1/0,quiet:!1,cycle:1/0};function _(e){let t=u===void 0?void 0:a.states[u];return g.policy=t?.blink??a.blink,g.since=f,g.next=1/0,g.quiet=!1,g.cycle=1/0,Re(d,e,f,g),g}let v=We(n.seed??Math.floor(Math.random()*4294967296),_,()=>d,()=>f,()=>h===`reduced`),y=Ke(a),b={x:0,y:0},x=new Float64Array(o.size),S=o.writer(),C=(e,t)=>Z(d,Fe(t,f),e);function w(e,t,n,r){let i=Be(d,Fe(e,f),t,o,n,f,r);return o.inheritGaze(t,u===void 0?void 0:a.states[u]?.gaze),i}let T=new Float64Array(2);function E(){let e=new Float64Array(o.size);return Q({size:2,angles:[!1,!1],min:[-1,-1],max:[1,1]},(t,n,r)=>{let i=w(t,e,r,h===`reduced`?360:0);return n[0]=e[o.gaze],n[1]=e[o.gaze+1],i})}let D=Object.values(a.states).some(e=>e.gaze)?E():void 0,O=Q(o,(e,t,n)=>{let r=w(e,t,n,h===`reduced`?80:0),i=o.style(e,t,h===`reduced`);return S.resolveMarks(e,t),S.resolveGestures(e,t,f,C),i?0:r}),k={expression:S.expression,blink:1,eyeOffset:y.offset,bodyOffset:b,half:a.file.poster.half,time:0},A={frame:k,nextTime:1/0,geometryStable:!1},j,M={blink:1,x:0,y:0},N={blink:0,x:0,y:0},P=0,F=0;function I(e){if(m)throw Error(`Playback disposed.`);if(!Number.isFinite(e)||e<p)throw RangeError(`Use monotonic milliseconds.`);p=e,A.geometryStable=!1,A.nextTime=e+O.sample(e,x),S.write(x,e)&&(A.nextTime=e);let t=v.sample(e);k.blink=t.openness,b.x=x[o.bodyX],b.y=x[o.bodyY];let n=D?.sample(e,T)??1/0,r=y.sample(e,T[0],T[1],x[o.eyeX],x[o.eyeY],k.expression);A.nextTime=Math.min(A.nextTime,e+t.next,e+r,e+n),k.time=e}function L(e){return I(e),r?.(e),A}function R(e,t,n){if(!e)throw Error(`Missing compiled track.`);I(n),D?.capture(n),v.capture(n),O.capture(n),d=e,u=t,S.activate(n,x),f=n,v.begin(n);let r=t?a.states[t]?.entryMs??180:180;O.begin(n,n+(h===`reduced`?80:r)),D?.begin(n,n+(h===`reduced`?360:r))}function z(e,t,n,r){(j??=new Float64Array(x.length)).set(e),M.blink=t,M.x=n,M.y=r}return{sample:L,sampleDisplay(e,t,n=!1){let r=t&&!!j;if(r&&(P=e,F=e+(h===`reduced`?80:(u===void 0?void 0:a.states[u]?.entryMs)??180),O.fromDisplayed(e,F,j)),L(e),r&&(N.blink=M.blink-k.blink,N.x=M.x-k.eyeOffset.x,N.y=M.y-k.eyeOffset.y),e<F){let t=(e-P)/(F-P),n=(1+2*t)*(1-t)**2;k.blink=Math.max(0,Math.min(1,k.blink+n*N.blink)),k.eyeOffset.x+=n*N.x,k.eyeOffset.y+=n*N.y,A.nextTime=e}return A.geometryStable=j!==void 0&&k.blink===M.blink&&k.eyeOffset.x===M.x&&k.eyeOffset.y===M.y&&!k.expression.sampledGesture&&x.every((e,t)=>t>=o.gaze||t>=o.colors&&t<o.colors+6||e===j[t]),n||z(x,k.blink,k.eyeOffset.x,k.eyeOffset.y),A},pendingDisplay(){let e=x.slice(),t=k.blink,{x:n,y:r}=k.eyeOffset;return()=>z(e,t,n,r)},set(e,n){if(s.has(e)||t(`states`,e,[...s.keys()]),e===u){L(n);return}R(s.get(e),e,n)},expression(e,n){l.has(e)||t(`expressions`,e,[...l.keys()]),R(l.get(e),void 0,n)},sequence(e,n){c.has(e)||t(`sequences`,e,[...c.keys()]),R(c.get(e),void 0,n)},look(e,t){L(t),y.look(e,t,h===`reduced`)},setBlink(e,t){L(t),v.set(e,t)},blink(e){L(e),v.blink(e)},setMotion(e,t){L(t),e!==h&&(O.capture(t),D?.capture(t),v.captureMotion(t),y.retime(t,e===`reduced`),h=e,D?.begin(t,t+(e===`reduced`?360:160)),v.finishMotion(t),O.begin(t,t+80))},dispose(){m=!0}}}function Ze(e,t={}){let n=e.avatar,i=r(n,t.onSequenceEnd),{sequence:a,...o}=Xe(e,t,i.settle);return{...o,get completionTime(){return i.deadline},settle:i.settle,set(e,t){let r=i.state!==e;o.set(e,t),r&&i.select(e,n.states[e]?.sequence,t)},expression(e,t){o.expression(e,t),i.select(void 0,void 0,t)},async play(e,t){return a(e,t),i.play(e,t)},dispose(){o.dispose(),i.dispose()}}}var Qe=new WeakMap;function $e(e){let t=Qe.get(e);if(t)return t;let n=e.file;function r({geometryIndex:e,...t}){let r=e===void 0?t.geometry:n.geometry[e];return{...t,geometry:r}}return t={...n.avatar,body:{primary:r(n.avatar.body.primary),nodes:n.avatar.body.nodes.map(e=>({...e,surface:r(e.surface)}))}},Qe.set(e,t),t}function et(e,t=!0){let{primary:n,nodes:r}=e.file.avatar.body;return!(t&&!r.length&&n.type===`sphere`&&!n.rotationCenter&&n.width===n.height&&n.width===n.depth&&n.width>=1&&n.width<=620&&Object.values(e.expressions).every(e=>e.perspective===1))}export{f as C,l as S,E as _,Ye as a,i as b,se as c,ce as d,re as f,T as g,p as h,qe as i,H as l,I as m,et as n,de as o,D as p,Ze as r,ue as s,$e as t,le as u,u as v,d as x,c as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e,n as t,r as n}from"./poster-
|
|
1
|
+
import{i as e,n as t,r as n}from"./poster-Cs69ty3T.js";var r=`http://www.w3.org/2000/svg`,i=(e,t,n)=>{n===null?e.removeAttribute(t):e.setAttribute(t,n)},a=()=>{let e=new WeakMap;return(t,n,r)=>{let a=e.get(t);a||e.set(t,a=new Map),a.get(n)!==r&&(a.set(n,r),i(t,n,r))}},o=(e,t,n,a=i)=>{for(;e.children.length<t.length;)e.appendChild(e.ownerDocument.createElementNS(r,`path`));Array.from(e.children).forEach((e,r)=>{let i=t[r];i?(a(e,`d`,i.path),a(e,`fill`,n(i)),a(e,`display`,`inline`)):a(e,`display`,`none`)})},s=(e,t,n,a=i)=>{for(;e.children.length>t.length;)e.lastElementChild.remove();for(;e.children.length<t.length;)e.appendChild(e.ownerDocument.createElementNS(r,`g`));t.forEach((t,r)=>{let i=e.children[r];a(i,`fill`,t.fill),a(i,`clip-path`,t.clip?`url(#${n[t.clip]})`:null),o(i,t.paths.map(e=>({path:e})),()=>null,a)})},c=`http://www.w3.org/2000/svg`,l=0,u=(r,i)=>{l+=1;let u=i?i+`-clip`:`morph-clip-${l}`,d=i?i+`-eyes`:`morph-eyes-${l}`,f=(e,t)=>t.appendChild(r.ownerDocument.createElementNS(c,e));r.replaceChildren(),r.setAttribute(`role`,`img`),r.style.overflow=`visible`;let p=f(`defs`,r),m=f(`clipPath`,p);m.id=u;let h=f(`path`,m),g=f(`mask`,p);g.id=d,g.setAttribute(`maskUnits`,`userSpaceOnUse`);let _=f(`rect`,g);_.setAttribute(`fill`,`#fff`);let v=f(`clipPath`,p);v.id=i?i+`-face`:`morph-face-${l}`;let y=f(`path`,v),b=f(`g`,r),x=f(`g`,b),S=f(`g`,x),C=f(`path`,x),w=f(`g`,b);w.setAttribute(`clip-path`,`url(#${u})`);let T=[],E=f(`g`,b);E.setAttribute(`clip-path`,`url(#${v.id})`);let D=f(`path`,E),O=f(`g`,g),k=f(`g`,b),A=a(),j=``;return{fit(e,t){let n=t?.x??0,i=t?.y??0,a=`${n-e} ${i-e} ${e*2} ${e*2}`;a!==j&&(j=a,r.setAttribute(`viewBox`,a),[g,_].forEach(t=>{t.setAttribute(`x`,`${n-2*e}`),t.setAttribute(`y`,`${i-2*e}`),t.setAttribute(`width`,`${4*e}`),t.setAttribute(`height`,`${4*e}`)}))},paint({frame:r,colors:i,transform:a,windowed:c}){let l=!!i.eyeHoles,p=t=>l&&t.color===`eyes`?`none`:t.color?e(n(i,t.color)):null,m=r.pieces.filter(e=>!e.front),g=r.pieces.filter(e=>e.front);for(A(b,`transform`,a),A(C,`d`,r.body),A(h,`d`,r.body);T.length<r.eyes.length;)T.push(f(`path`,w));r.eyes.forEach((e,t)=>{A(T[t],`d`,e.path),A(T[t],`opacity`,e.visible?`1`:`0`)});for(let e=r.eyes.length;e<T.length;e++)A(T[e],`opacity`,`0`);o(S,m,p,A),o(k,g,p,A),[S,C,k].forEach(t=>A(t,`fill`,e(i.body))),A(y,`d`,r.face?.opening??`M0 0Z`),A(D,`d`,r.face?.plate??`M0 0Z`),A(D,`fill`,e(i.eyes)),A(D,`display`,l?`none`:`inline`),s(O,l?t({body:r.body,eyes:r.eyes.filter(e=>e.visible).map(e=>e.path),...r.face?{face:r.face}:{},back:m.map(e=>e.path),backColors:m.map(e=>e.color??`body`),front:g.map(e=>e.path),frontColors:g.map(e=>e.color??`body`)}):[],{body:u,face:v.id},A);let _=c?E:b;w.parentNode!==_&&(_===b?b.insertBefore(w,E):_.appendChild(w)),A(b,`mask`,l?`url(#${d})`:null),A(w,`display`,l&&!c?`none`:`inline`),A(w,`fill`,e(c?i.body:i.eyes))},setLabel(e){r.setAttribute(`aria-label`,e??``)},destroy(){r.replaceChildren()}}};export{u as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=e=>{let t=/^#([0-9a-f]{6})$/i.exec(e)?.[1];if(!t)return e;let n=e=>Number((Number.parseInt(t.slice(e,e+2),16)/255).toFixed(4));return`color(display-p3 ${n(0)} ${n(2)} ${n(4)})`},t=(e,t=`body`)=>t===`accent`?e.linkAccentToBody?e.body:e.accent??e.body:t===`secondary`?e.secondary??e.body:t===`tertiary`?e.tertiary??e.body:t===`mark`?e.mark??e.eyes:e[t],n=e=>{let{body:t,eyes:n,face:r,back:i,backColors:a,front:o,frontColors:s}=e;return[...a.some(e=>e===`eyes`)?[...i.map((e,t)=>({paths:[e],fill:a[t]===`eyes`?`#000`:`#fff`})),{paths:[t],fill:`#fff`}]:[],...r?[{paths:[r.plate],fill:`#000`,clip:`face`}]:[],{paths:n,fill:r?`#fff`:`#000`,clip:r?`face`:`body`},{paths:[...o.filter((e,t)=>s[t]===`eyes`)],fill:`#000`},...r?[{paths:o.filter((e,t)=>s[t]!==`eyes`),fill:`#fff`}]:[]]};function r(r,i,a,o){let s=`mien-`+i.replace(/[^a-zA-Z0-9-]/gu,e=>`_`+e.codePointAt(0).toString(16)+`_`),c=r.file.poster,l=c.colors??r.file.avatar.colors,u=(e,t)=>o(`path`,t?{d:e,fill:t}:{d:e}),d=e=>`url(#`+s+`-`+e+`)`,f=(e,t={})=>o(`g`,t,e),p=[o(`clipPath`,{id:s+`-body`},[u(c.body)])];c.face&&p.push(o(`clipPath`,{id:s+`-face`},[u(c.face.opening)]));let m=c.back??[],h=c.front??[],g=c.half;if(l.eyeHoles){let e={x
|
|
1
|
+
var e=e=>{let t=/^#([0-9a-f]{6})$/i.exec(e)?.[1];if(!t)return e;let n=e=>Number((Number.parseInt(t.slice(e,e+2),16)/255).toFixed(4));return`color(display-p3 ${n(0)} ${n(2)} ${n(4)})`},t=(e,t=`body`)=>t===`accent`?e.linkAccentToBody?e.body:e.accent??e.body:t===`secondary`?e.secondary??e.body:t===`tertiary`?e.tertiary??e.body:t===`mark`?e.mark??e.eyes:e[t],n=e=>{let{body:t,eyes:n,face:r,back:i,backColors:a,front:o,frontColors:s}=e;return[...a.some(e=>e===`eyes`)?[...i.map((e,t)=>({paths:[e],fill:a[t]===`eyes`?`#000`:`#fff`})),{paths:[t],fill:`#fff`}]:[],...r?[{paths:[r.plate],fill:`#000`,clip:`face`}]:[],{paths:n,fill:r?`#fff`:`#000`,clip:r?`face`:`body`},{paths:[...o.filter((e,t)=>s[t]===`eyes`)],fill:`#000`},...r?[{paths:o.filter((e,t)=>s[t]!==`eyes`),fill:`#fff`}]:[]]};function r(r,i,a,o){let s=`mien-`+i.replace(/[^a-zA-Z0-9-]/gu,e=>`_`+e.codePointAt(0).toString(16)+`_`),c=r.file.poster,l=c.colors??r.file.avatar.colors,u=(e,t)=>o(`path`,t?{d:e,fill:t}:{d:e}),d=e=>`url(#`+s+`-`+e+`)`,f=(e,t={})=>o(`g`,t,e),p=[o(`clipPath`,{id:s+`-body`},[u(c.body)])];c.face&&p.push(o(`clipPath`,{id:s+`-face`},[u(c.face.opening)]));let m=c.back??[],h=c.front??[],g=c.half,_=c.center?.x??0,v=c.center?.y??0;if(l.eyeHoles){let e={x:_-2*g,y:v-2*g,width:4*g,height:4*g},t=n({body:c.body,eyes:c.eyes,face:c.face,back:m.map(e=>e.path),backColors:m.map(e=>e.color),front:h.map(e=>e.path),frontColors:h.map(e=>e.color)});p.push(o(`mask`,{id:s+`-mask`,maskUnits:`userSpaceOnUse`,...e},[o(`rect`,{...e,fill:`#fff`}),...t.map(e=>f(e.paths.map(e=>u(e)),{fill:e.fill,...e.clip?{"clip-path":d(e.clip)}:{}}))]))}let y=n=>n.map(n=>u(n.path,l.eyeHoles&&n.color===`eyes`?`none`:e(t(l,n.color)))),b=[...y(m),u(c.body,e(l.body))],x=f(c.eyes.map(e=>u(e)),{fill:e(c.face?l.body:l.eyes),"clip-path":d(`body`)});c.face?b.push(f([...l.eyeHoles?[]:[u(c.face.plate,e(l.eyes))],x],{"clip-path":d(`face`)})):l.eyeHoles||b.push(x),b.push(...y(h));let S=c.placement;return o(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`${_-g} ${v-g} ${2*g} ${2*g}`,...a?{role:`img`,"aria-label":a}:{"aria-hidden":`true`}},[o(`defs`,{},p),f(b,{...S?{transform:`matrix(${S.scaleX} 0 0 ${S.scaleY} ${S.x} ${S.y})`}:{},...l.eyeHoles?{mask:d(`mask`)}:{}})])}export{e as i,n,t as r,r as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=(e,t)=>typeof t==`number`||!/[~/]/.test(t)?e+`/`+t:e+`/`+t.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`),t=(e,t)=>typeof e==`boolean`?void 0:t,n=(e,t)=>e===null?void 0:t,r=(...e)=>(t,n)=>e.includes(t)?void 0:n,i=(e,t,n,r)=>(i,a)=>typeof i==`number`&&(r?i>e:i>=e)&&i<=t&&(!n||Number.isInteger(i))?void 0:a,a=(e,t,n)=>{let r=n?new RegExp(n,`u`):null;return(n,i)=>{if(typeof n!=`string`)return i;let a=/[\uD800-\uDBFF]/.test(n)?Array.from(n).length:n.length;return a>=e&&a<=t&&(!r||r.test(n))?void 0:i}},o=(t,n,r)=>(i,a)=>{if(!Array.isArray(i)||i.length<n||i.length>r)return a;for(let n=0;n<i.length;n++){let r=t(i[n],e(a,n));if(r!==void 0)return r}},s=e=>typeof e==`object`&&!!e&&!Array.isArray(e),c=(t,n,r)=>(i,a)=>{if(!s(i)||Object.keys(i).length<r)return a;for(let t of n)if(!Object.hasOwn(i,t))return e(a,t);for(let[n,r]of Object.entries(i)){let i=e(a,n);if(!Object.hasOwn(t,n))return i;let o=t[n](r,i);if(o!==void 0)return o}},l=(t,n,r,i)=>(a,o)=>{if(!s(a)||Object.keys(a).length>r)return o;for(let t of i)if(!Object.hasOwn(a,t))return e(o,t);for(let[r,i]of Object.entries(a)){let a=e(o,r),s=n(r,a)??t(i,a);if(s!==void 0)return s}},u=(...e)=>(t,n)=>{let r=n;for(let i of e){let e=i(t,n);if(e===void 0)return;e.length>r.length&&(r=e)}return r},d=1048576,f=class extends Error{code;path;fix;source;constructor(e,t,n,r){super(`${e} at ${t||`/`}${r?` in `+r:``}.${n?` `+n:``}`),this.code=e,this.path=t,this.fix=n,this.source=r,this.name=`MienFormatError`}};function p(e,t,n){let r=n.find(e=>e.startsWith(t.slice(0,Math.max(3,t.length-2))));throw new f(`MIEN_`+e.slice(0,-1).toUpperCase()+`_UNKNOWN`,`/`+e+`/`+t,(r?`Did you mean "${r}"? `:``)+`Names: `+n.join(`, `)+`.`)}function m(e,t,n=`MIEN_INVALID`){throw new f(n,e,t)}var h=/^[\x20\x21\x23-\x5b\x5d-\x7e]*$/;function g(t){let n=d,r=new TextEncoder;function i(e,t){n-=e,n<0&&m(t,`Use a file of at most 1 MiB.`,`MIEN_SIZE`)}function a(e,t){e.length>n&&m(t,`Use a file of at most 1 MiB.`,`MIEN_SIZE`),i(h.test(e)?e.length+2:r.encode(JSON.stringify(e)).length,t)}function o(t,n,r){if(r>32&&m(n,`Reduce nesting to 32 levels.`,`MIEN_DEPTH`),typeof t==`string`)return a(t,n),t;if(t===null||typeof t==`boolean`||typeof t==`number`&&Number.isFinite(t))return i(t===null?4:String(t).length,n),t;(!t||typeof t!=`object`)&&m(n,`Supply a JSON value.`);let s=Array.isArray(t);!s&&Object.prototype.toString.call(t)!==`[object Object]`&&m(n,`Supply a plain object.`),!s&&Object.getPrototypeOf(t)!==null&&Object.getPrototypeOf(Object.getPrototypeOf(t))!==null&&m(n,`Supply own JSON properties.`),i(2,n);let c=Object.keys(t);s&&c.length!==t.length&&m(n,`Supply a dense JSON array.`);let l=s?[]:Object.create(null);for(let u=0;u<c.length;u++){let d=c[u];s&&d!==String(u)&&m(n,`Supply only array elements.`),s||(a(d,n),i(1,n)),u&&i(1,n);let f=e(n,s?u:d),p=Object.getOwnPropertyDescriptor(t,d);`value`in p||m(f,`Supply data instead of a getter.`),l[d]=o(p.value,f,r+1)}return Object.freeze(l)}return o(t,``,0)}var _=i(.001,1e4,!1,!1),v=i(0,2,!1,!1),y=i(-1e4,1e4,!1,!1),b=o(y,3,3),x=o(y,2,2),S=c({sockets:c({centers:o(o(i(-1,1,!1,!1),2,2),1,4),apertureRadius:i(0,1,!1,!0),rimOuterRadius:i(0,1,!1,!0),padRadius:i(0,1,!1,!0),plane:i(-1,1,!1,!1),depth:i(0,1,!1,!0),power:r(3)},[`centers`,`apertureRadius`,`rimOuterRadius`,`padRadius`,`plane`,`depth`,`power`],0),eyePlane:i(-1,1,!1,!1),radii:o(i(0,1/0,!1,!0),3,8192),sections:c({profile:o(b,2,512),frontPower:i(2,8,!1,!1),frontTaper:i(0,1,!1,!1)},[`profile`,`frontPower`],0),hull:o(b,4,8192),revolve:r(`x`,`y`),window:o(x,3,8192),plate:o(x,3,8192),flush:t,bend:c({x:i(-1/0,1/0,!1,!1),y:i(-1/0,1/0,!1,!1),from:i(-1/0,1/0,!1,!1)},[`x`],0),relief:c({size:i(2,256,!0,!1),range:i(0,1e4,!1,!0),scale:i(0,1e4,!1,!0),rim:i(0,1,!1,!0),front:a(0,174764,void 0),back:a(0,174764,void 0),bits:r(16),coding:r(`delta`)},[`size`,`range`,`scale`,`front`,`back`],0),lobes:c({blend:i(0,.25,!1,!0),parts:o(c({center:b,radii:o(i(.001,4,!1,!1),3,3),power:i(2,6,!1,!1),horizontalPower:i(2,6,!1,!1),rotation:i(-180,180,!1,!1),tilt:i(-180,180,!1,!1)},[`center`,`radii`],0),1,16),crown:c({dip:i(0,.25,!1,!1),lift:i(0,.25,!1,!1),width:i(.05,1,!1,!1)},[`dip`,`lift`,`width`],0)},[`blend`,`parts`],0),radialDepthPower:i(2,32,!1,!1)},[`radii`],0),C=c({type:r(`sphere`,`mickey`,`cursor`,`cube`,`capsule`,`cylinder`,`cone`,`diamond`,`blob`),width:_,height:_,depth:i(0,1e4,!1,!1),roundness:v,outlineRounding:i(0,1,!1,!1),morphRoundness:v,tipRoundness:v,baseRoundness:v,geometry:S,rotationCenter:o(y,3,3),geometryIndex:i(0,16,!0,!1)},[`type`,`width`,`height`,`depth`,`roundness`],0),ee=o(y,3,3),w=o(i(-360,360,!1,!1),3,3),T=a(0,64,`^(?!constructor$|prototype$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*$`),E=c({primary:C,nodes:o(c({surface:C,position:ee,rotation:w,fixed:t,rooted:t,follow:c({lag:i(0,1e3,!1,!1),swing:i(-10,10,!1,!1),loose:t,hinge:o(i(-500,500,!1,!1),2,2),range:o(i(-180,180,!1,!1),2,2)},[`lag`],0),color:r(`eyes`,`accent`,`secondary`,`tertiary`,`mark`),paintOn:T,id:T},[`surface`,`position`,`rotation`,`id`],0),0,16)},[`primary`,`nodes`],0),D=a(0,1/0,`^#[0-9a-fA-F]{6}$`),O=c({body:D,eyes:D,eyeHoles:t,accent:D,secondary:D,tertiary:D,mark:D,linkAccentToBody:t},[`body`,`eyes`],0),k=c({widthLeft:y,widthRight:y,heightLeft:y,heightRight:y,spacing:y,positionXLeft:y,positionXRight:y,positionYLeft:y,positionYRight:y,leftAngle:y,rightAngle:y,shape:r(`pill`,`ellipse`,`circle`),glyphY:y},[`widthLeft`,`widthRight`,`heightLeft`,`heightRight`,`spacing`,`positionXLeft`,`positionXRight`,`positionYLeft`,`positionYRight`,`leftAngle`,`rightAngle`],0),A=a(1,262144,`^[Mm][MmZzLlHhVvCcSsQqTtAaEe0-9+., \\t\\r\\n-]*$`),j=c({half:i(1,1e6,!1,!1),body:A,eyes:o(A,0,4),back:o(c({path:A,color:r(`body`,`eyes`,`accent`,`secondary`,`tertiary`,`mark`)},[`path`,`color`],0),0,128),front:o(c({path:A,color:r(`body`,`eyes`,`accent`,`secondary`,`tertiary`,`mark`)},[`path`,`color`],0),0,128),face:c({opening:A,plate:A},[`opening`,`plate`],0),placement:c({x:y,y,scaleX:y,scaleY:y},[`x`,`y`,`scaleX`,`scaleY`],0),center:c({x:y,y},[`x`,`y`],0),colors:O},[`half`,`body`,`eyes`],0),M=u(c({mode:r(`off`)},[`mode`],0),c({mode:r(`interval`),everyMs:i(1,12e4,!0,!1),initialDelayMs:i(0,12e4,!0,!1),durationMs:i(1,12e4,!0,!1)},[`mode`,`everyMs`],0),c({mode:r(`random`),minMs:i(1,12e4,!0,!1),maxMs:i(1,12e4,!0,!1),initialDelayMs:i(0,12e4,!0,!1),durationMs:i(1,12e4,!0,!1)},[`mode`,`minMs`,`maxMs`],0),c({mode:r(`times`),atMs:o(i(0,2147483647,!0,!1),0,4096),durationMs:i(1,12e4,!0,!1)},[`mode`,`atMs`],0),c({mode:r(`once`),delayMs:i(0,12e4,!0,!1),durationMs:i(1,12e4,!0,!1)},[`mode`,`delayMs`],0)),N=c({turn:y,x:y,y,scale:i(.01,100,!1,!1)},[],1),P=c({x:y,y,width:y,height:y,angle:y,bend:i(-1,1,!1,!1)},[`x`,`y`,`width`,`height`,`angle`],0),F=c({headX:y,headY:y,headZ:y,widthLeft:y,widthRight:y,heightLeft:y,heightRight:y,spacing:y,positionXLeft:y,positionXRight:y,positionYLeft:y,positionYRight:y,leftAngle:y,rightAngle:y,perspective:y,eyeMotion:u(r(`none`,`microSaccades`,`shake`),n),bodyMotion:u(r(`none`,`slowDrift`,`shake`),n),bodyColor:u(D,n),eyeColor:u(D,n),pieces:u(l(N,T,16,[]),n),marks:u(o(P,4,4),n),glyphApart:u(r(!0),n),headGestureAmount:u(i(0,1,!1,!1),n),headGesture:u(r(`nod`,`headShake`,`wiggle`,`twirl`,`lookAround`,`hop`,`tilt`,`dance`,`bow`,`shakeOff`,`eagerNod`,`peek`,`shrug`,`recoil`,`doubleTake`,`eyeRoll`,`dizzy`,`sneeze`,`yawn`,`shiver`,`tickTock`,`bashful`,`roll`,`flip`,`spin`,`bounce`,`breathe`,`shrink`,`stomp`,`sway`,`earFlap`),n),markMotion:u(r(`drift`,`scan`,`wave`,`talk`,`bounce`,`type`,`orbit`,`pulse`,`breathe`,`sway`,`shake`,`hop`,`beat`,`twinkle`,`rise`,`fall`),n),lidLeft:u(i(0,1,!1,!1),n),lowerLidLeft:u(i(0,1,!1,!1),n),lidTiltLeft:u(i(-80,80,!1,!1),n),lidRight:u(i(0,1,!1,!1),n),lowerLidRight:u(i(0,1,!1,!1),n),lidTiltRight:u(i(-80,80,!1,!1),n)},[],0),I=u(c({expression:T,gaze:c({x:i(-1,1,!1,!1),y:i(-1,1,!1,!1)},[`x`,`y`],0),blink:M,entryMs:i(80,1e3,!0,!1)},[`expression`],0),c({sequence:T,gaze:c({x:i(-1,1,!1,!1),y:i(-1,1,!1,!1)},[`x`,`y`],0),blink:M,entryMs:i(80,1e3,!0,!1)},[`sequence`],0)),L=u(c({expression:T,holdMs:i(0,6e4,!0,!1),transitionMs:i(0,5e3,!0,!1),transition:r(`spring`,`bounce`,`smooth`,`snappy`,`glide`,`linear`,`cut`),blink:r(!1)},[`expression`,`holdMs`],0),c({state:T,holdMs:i(0,6e4,!0,!1),transitionMs:i(0,5e3,!0,!1),transition:r(`spring`,`bounce`,`smooth`,`snappy`,`glide`,`linear`,`cut`),blink:r(!1)},[`state`,`holdMs`],0)),R=c({mode:r(`once`,`loop`,`pingPong`),steps:o(L,1,1024),blink:M},[`mode`,`steps`],0),z=c({format:r(`mien`),version:r(1),name:a(0,256,void 0),avatar:c({body:E,colors:O,eyes:k},[`body`,`colors`],0),geometry:o(S,1,17),initial:T,poster:j,blink:M,expressions:l(F,T,512,[`neutral`]),states:l(I,T,256,[]),sequences:l(R,T,256,[])},[`format`,`version`,`avatar`,`initial`,`poster`,`expressions`,`states`,`sequences`],0),B=M;function V(e){if(e&&!(Number.isFinite(e.x)&&Number.isFinite(e.y)))throw new f(`MIEN_GAZE`,`/look`,`Use finite numbers from -1 to 1 for x and y. Received x=${e.x}, y=${e.y}.`)}function H(e,t){let n=t.slice(7);if(e?.mode===`times`){if(n===`atMs`)return`Use an atMs array with up to 4096 times.`;if(n.startsWith(`atMs/`))return`Use whole numbers from 0 to 2,147,483,647 ms in atMs.`}if(n.endsWith(`Ms`)){let r=n===`delayMs`||n===`initialDelayMs`?0:1;if(B({...e,[n]:r},`/blink`)!==t)return`Set ${n} to a whole number from ${r} to 120,000 ms.`}return`Use a valid blink policy, such as { "mode": "off" }.`}function U(e){try{return JSON.stringify(e,(e,t)=>typeof t==`number`&&!Number.isFinite(t)||typeof t==`bigint`?String(t):t)}catch{return`an unserializable value`}}function W(e){if(e===null)return;let t=B(e,`/blink`),n;if(t)n=H(e,t);else if(e.mode===`random`&&e.minMs>e.maxMs)n=`Set minMs to a value less than or equal to maxMs.`;else if(e.mode===`times`&&e.atMs.some((e,t,n)=>t>0&&n[t-1]>e))n=`Put the times in atMs in ascending order.`;else return;throw new f(`MIEN_BLINK`,t??`/blink`,`${n} Received ${U(e)}.`)}var G=Object.freeze({headX:0,headY:0,headZ:0,widthLeft:20,widthRight:20,heightLeft:50,heightRight:50,spacing:35,positionXLeft:0,positionXRight:0,positionYLeft:-7,positionYRight:-7,leftAngle:0,rightAngle:0,perspective:1}),K=Object.freeze({mode:`random`,minMs:2600,maxMs:4700,durationMs:160});function q(e,t){let n={...e};for(let[e,r]of Object.entries(t))r===null?delete n[e]:Object.assign(n,{[e]:r});return Object.freeze(n)}function J(e){return e.mode===`off`?e:Object.freeze({durationMs:160,...e})}var Y={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7,z:0};function X(e){let t=/[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y,n=/[ \n\r\t]*/y,r=0;function i(){n.lastIndex=r,n.exec(e),r=n.lastIndex}let a=``;if(!/^[Mm]/.test(e))return!1;for(;r<e.length;){let n=e[r].toLowerCase(),o=Object.hasOwn(Y,n);if(o)a=n,r++,i();else if(!a)return!1;if(a===`z`){a=``;continue}for(let n=0;n<Y[a];n++){if((!o||n>0)&&e[r]===`,`&&(r++,i()),a===`a`&&(n===3||n===4)){if(e[r]!==`0`&&e[r]!==`1`)return!1;r++}else{t.lastIndex=r;let i=t.exec(e);if(!i)return!1;let o=Number(i[0]);if(Math.abs(o)>1e6||a===`a`&&n<2&&o<0)return!1;r=t.lastIndex}i()}}return!0}function Z(e,t){e?.mode===`random`&&e.minMs>e.maxMs&&m(t+`/maxMs`,`Use a maximum at least as large as the minimum.`),e?.mode===`times`&&e.atMs.some((e,t,n)=>t>0&&n[t-1]>e)&&m(t+`/atMs`,`Sort cues in time order.`)}function Q(e,t){if(!t){let t=e.replace(/[\t\n\f\r ]/g,``);return t.length%4==0&&(t=t.replace(/={1,2}$/,``)),t.length%4==1||/[^A-Za-z0-9+/]/.test(t)?-1:Math.floor(t.length*3/4)}let n=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`,r=0;for(let t=0;t<e.length;){let i=e[t++];if(i===`~`){if(t+2>e.length)return-1;let i=n.indexOf(e[t++]),a=n.indexOf(e[t++]);if(i<0||a<0)return-1;r+=64*i+a}else{if(i===`.`){if(t+3>e.length||!/^[A-P][\w-]{2}$/.test(e.slice(t,t+3)))return-1;t+=3}else if(!n.includes(i))return-1;r++}}return r}function te(e){let t=0,n=0,r=e.avatar.body.nodes,i=new Map(r.map(e=>[e.id,e]));i.size!==r.length&&m(`/avatar/body/nodes`,`Give each node a unique ID.`);let a=new Set;function o(r,i){let o=r.geometry??(r.geometryIndex===void 0?void 0:e.geometry?.[r.geometryIndex]);if(r.geometryIndex!==void 0&&(!o||r.geometry)&&m(i+`/geometryIndex`,`Use one valid geometry index or inline geometry.`),r.type===`blob`!=!!o&&m(i,`Give each blob its own geometry.`),!o)return;let s=r.geometryIndex===void 0?i+`/geometry`:`/geometry/`+r.geometryIndex,{relief:c,sockets:l,sections:u,lobes:d}=o;if(n+=o.radii.length+(o.hull?.length??0)+(o.plate?.length??0)+(o.window?.length??0)+(u?.profile.length??0),t+=2*(c?.size??0)**2,(t>2097152||n>65536)&&m(i,`Reduce total decoded geometry.`,`MIEN_SIZE`),!a.has(o)){if(a.add(o),(o.radialDepthPower&&(d||u||o.hull||o.plate||o.revolve||c||l)||d&&(u||o.hull||o.plate||c||o.revolve))&&m(s,`Use compatible solid constructions.`),l){let{apertureRadius:e,rimOuterRadius:t,padRadius:n,centers:r}=l;(d||o.hull||o.plate||o.revolve||o.window||o.eyePlane!==void 0||!(e<t&&t<n)||r.some(([e,t],i)=>r.slice(i+1).some(([r,i])=>Math.hypot(e-r,t-i)<=2*n)))&&m(s+`/sockets`,`Use separate socket pads with increasing rim radii on a compatible solid.`)}for(let[e,t]of(d?.parts??[]).entries()){let[n,r,i]=t.center,a=(t.rotation??0)*Math.PI/180,o=(t.tilt??0)*Math.PI/180,c=-Math.sin(a)*n+Math.cos(a)*r,[l,u,d]=t.radii,f=t.power??2,p=t.horizontalPower??f;(Math.abs((Math.cos(a)*n+Math.sin(a)*r)/l)**p+Math.abs((-Math.sin(o)*c+Math.cos(o)*i)/d)**p)**(f/p)+Math.abs((Math.cos(o)*c+Math.sin(o)*i)/u)**f>=1&&m(s+`/lobes/parts/`+e,`Each lobe must contain the origin.`)}if(u?.profile.some(([e,t,n],r,i)=>t<n||r>0&&e<=i[r-1][0])&&m(s+`/sections/profile`,`Order the sections and place fronts ahead of backs.`),c){c.coding&&c.bits!==16&&m(s+`/relief/bits`,`Use 16-bit delta grids.`);for(let e of[`front`,`back`])Q(c[e],!!c.coding)!==c.size**2*(c.bits===16&&!c.coding?2:1)&&m(s+`/relief/`+e,`Encode one signed sample per grid cell.`)}}}o(e.avatar.body.primary,`/avatar/body/primary`),r.forEach((e,t)=>{let n=`/avatar/body/nodes/`+t;if(o(e.surface,n+`/surface`),(e.surface.type===`mickey`||e.surface.type===`cursor`)&&m(n+`/surface/type`,`Use a supported node surface.`),e.paintOn){let t=i.get(e.paintOn);(!t||t===e||t.paintOn||t.color===`eyes`||t.color===`mark`)&&m(n+`/paintOn`,`Select an existing solid host.`)}let r=e.follow?.range;r&&r[0]>r[1]&&m(n+`/follow/range`,`Order the hinge limits.`)}),e.geometry?.forEach((e,t)=>{a.has(e)||m(`/geometry/`+t,`Remove unused geometry.`)});for(let[t,n]of Object.entries(e.expressions))for(let e of Object.keys(n.pieces??{}))i.has(e)||m(`/expressions/`+t+`/pieces/`+e,`Select an existing node.`)}function ne(e){te(e);let t=e.poster;function n(e,t){X(e)||m(`/poster/`+t,`Supply valid bounded SVG path commands.`)}n(t.body,`body`),t.eyes.forEach((e,t)=>n(e,`eyes/`+t));for(let e of[`back`,`front`])t[e]?.forEach((t,r)=>n(t.path,e+`/`+r+`/path`));t.face&&(n(t.face.plate,`face/plate`),n(t.face.opening,`face/opening`)),re(e)}function re(e){let t=new Map,n=new Set;function r(i,a,o,s){if(Object.hasOwn(e[i],a)||m(o,`Choose an existing key in `+i+`.`,`MIEN_REFERENCE`),i===`expressions`)return 0;let c=i+`/`+a,l=`/`+c;n.has(c)&&m(o,`Remove recursive state or sequence references.`,`MIEN_CYCLE`),s>8&&m(o,`Limit playback references to eight levels.`,`MIEN_DEPTH`);let u=t.get(c);if(u!==void 0)return u;n.add(c);let d=1;if(i===`states`){let t=e.states[a];Z(t.blink,l+`/blink`),d+=t.sequence===void 0?r(`expressions`,t.expression,l+`/expression`,s+1):r(`sequences`,t.sequence,l+`/sequence`,s+1)}else{let t=e.sequences[a];Z(t.blink,l+`/blink`);let n=0;t.steps.forEach((e,t)=>{let i=l+`/steps/`+t;n+=e.holdMs+(e.transitionMs??180);let a=e.state===void 0?r(`expressions`,e.expression,i+`/expression`,s+1):r(`states`,e.state,i+`/state`,s+1);d=Math.max(d,a+1)}),!n&&t.mode!==`once`&&m(l+`/steps`,`Give a repeating sequence a positive duration.`)}return d>8&&m(o,`Limit playback references to eight levels.`,`MIEN_DEPTH`),n.delete(c),t.set(c,d),d}Object.values(e.sequences).reduce((e,t)=>e+t.steps.length,0)>4096&&m(`/sequences`,`Use at most 4096 steps.`,`MIEN_SIZE`),Z(e.blink,`/blink`),r(`states`,e.initial,`/initial`,1);for(let t of[`states`,`sequences`])for(let n of Object.keys(e[t]))r(t,n,`/`+t+`/`+n,1)}var $=new WeakMap;function ie(e){if(e&&typeof e==`object`){let t=$.get(e);if(t)return t}let t=g(e),n=t;n?.format!==`mien`&&m(`/format`,n?.format===`morph-avatar`?`Re-export the avatar as .mien.json in Mien Studio.`:`Supply a Mien avatar file.`,`MIEN_FORMAT`),n.version!==1&&m(`/version`,Number.isInteger(n.version)&&n.version>1?`This file was made for a newer mien-avatar. Update the package: npm i mien-avatar@latest.`:`Re-export the avatar from Mien Studio.`,`MIEN_VERSION`);let r=z(t,``);r!==void 0&&m(r,`Use the field type and range in the v1 schema.`);let i=t;ne(i);let a=q(G,i.expressions.neutral);function o(e,t){let n=Object.create(null);for(let[r,i]of Object.entries(e))n[r]=t(i,r);return Object.freeze(n)}let s=e=>e.blink?{blink:J(e.blink)}:{},c=Object.freeze({file:i,blink:J(i.blink??K),states:o(i.states,e=>Object.freeze({entryMs:180,...e,...s(e)})),sequences:o(i.sequences,e=>Object.freeze({...e,...s(e),steps:Object.freeze(e.steps.map(e=>Object.freeze({transitionMs:180,transition:`smooth`,...e})))})),expressions:o(i.expressions,(e,t)=>t===`neutral`?a:q(a,e)),stateNames:Object.freeze(Object.keys(i.states)),hasState:e=>Object.hasOwn(i.states,e)});return $.set(c,c),$.set(i,c),$.set(e,c),c}export{d as a,f as i,W as n,m as o,V as r,p as s,ie as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./playback-BeRsJu6S.js";import{t as n}from"./playerPaint-DaCo2Clx.js";var r=new WeakMap;function i(e,t,n){let i=r.get(e);i||r.set(e,i=new WeakMap);let o=i.get(t);return o||(o=a(t(),()=>i.delete(t)),i.set(t,o)),o.add(n)}function a(e,t){let n=new Map,r=new Map,i=!1,a=!1,o=!1,s=0,c=0,l;function u(){o=!0,clearTimeout(l),t(),e.onmessage=e.onerror=e.onmessageerror=null,e.terminate(),r.clear()}function d(e){o||(u(),console.warn(`mien-avatar: the drawing worker stopped, so avatars draw on the page instead.`,e),n.forEach(e=>e.failed()))}function f(t){try{e.postMessage(t)}catch{d()}}function p(){if(a=!1,o||i||!r.size)return;let e=[...r.values()].filter(e=>n.get(e.id)?.accept(e));r.clear(),e.length&&(i=!0,l=setTimeout(()=>d(`No answer within 10 s.`),1e4),f({kind:`project`,turn:++s,requests:e}))}return e.onerror=e.onmessageerror=d,e.onmessage=({data:e})=>{if(!(o||!i||e.turn!==s)){if(clearTimeout(l),e.kind!==`projected`||e.error){d(e.error);return}i=!1;for(let t of e.frames)n.get(t.id)?.receive(t);for(let t of e.failed??[])n.get(t)?.failed();p()}},{add(e){let t=++c;return n.set(t,e),{id:t,send(e){r.set(t,e),a||(a=!0,queueMicrotask(p))},remove(){!n.delete(t)||o||(r.delete(t),n.size?f({kind:`release`,id:t}):u())}}}}}var o=r=>async(a,o,s,c)=>{if(!c.visible())return;let l=o.cloneNode(!1),u=n(l,s);u.fit(a.file.poster.half,a.file.poster.center);let d=!1,f=!1,p=!1,m=!1,h=!0,g,_,v=!1,y,b,x=0;function S(){f||p||(p=!0,b=void 0,g?.remove(),c.visible()&&C())}function C(){v||(v=!0,import(`./activate-CCUqRQyO.js`).then(e=>e.t).then(e=>e.prepareGeometry(a,!0)).then(e=>{f||(_=e.createProjector(),c.invalidate())}).catch(c.report))}function w(e){u.paint(e),d||=(o.style.overflow=`visible`,o.replaceChildren(...l.childNodes),!0)}try{g=i(o.ownerDocument,r,{failed:S,accept(e){return c.visible()&&e.generation===c.generation()&&e.revision===c.revision()?(D=!1,!0):(b=void 0,h=!0,c.invalidate(),!1)},receive(e){let t=b;!t||f||p||Object.entries(t.stamp).some(([t,n])=>e[t]!==n)||(b=void 0,c.visible()&&c.generation()===e.generation&&c.revision()===e.revision&&c.runId()===e.runId?(w(e.painting),t.commit(),y=t):h=!0,c.invalidate())}})}catch{S()}let T=-1,E=0,D=!0;return{draw(n,r,i,o){if(m||=i,p){if(!_)return C(),1/0;y&&=(_(y.sample,y.pixels),void 0);let e=n.sampleDisplay(r,m||!d);return w(_(e.frame,d?o:192,e.geometryStable)),m=!1,e.nextTime}if(b)return 1/0;if(!h&&!m&&T===c.revision()&&o===E&&r<x)return x;let s=n.sampleDisplay(r,m||!d,!0);m=!1,h=!1,E=o,T=c.revision(),x=s.nextTime;let l={id:g.id,runId:c.runId(),generation:c.generation(),revision:T,at:r,commandTime:c.commandTime()},u=structuredClone(s.frame);return o=d?o:192,b={sample:u,pixels:o,stamp:l,commit:n.pendingDisplay()},g.send({...l,sample:u,pixels:o,...D&&{avatar:t(a),grid:e(a)}}),1/0},dispose(){f=!0,g?.remove(),_?.dispose(),b=y=void 0}}};export{o as workerTransport};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./reader-
|
|
1
|
+
import{i as e}from"./reader-JcTNbEkh.js";async function t(t,n,r){try{n?.throwIfAborted();let[e,i]=await Promise.all([fetch(t,{signal:n}),r]);return await i(e,n)}catch(r){n?.throwIfAborted();let i=String(t);throw r instanceof e?new e(r.code,r.path,r.fix,i):new e(`MIEN_LOAD`,``,`Check the URL and the UTF-8 JSON response.`,i)}}export{t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime-DK3Fl9T5.js";import{o as t,t as n}from"./reader-
|
|
1
|
+
import{t as e}from"./rolldown-runtime-DK3Fl9T5.js";import{o as t,t as n}from"./reader-JcTNbEkh.js";var r=e({readAvatarResponse:()=>i});async function i(e,r){r?.aborted&&(await e.body?.cancel(),r.throwIfAborted()),e.ok||(await e.body?.cancel(),t(``,`Check the HTTP response (`+e.status+`).`,`MIEN_HTTP`)),Number(e.headers.get(`content-length`))>1048576&&(await e.body?.cancel(),t(``,`Use a file of at most 1 MiB.`,`MIEN_SIZE`));let i=e.body?.getReader();i||t(``,`Supply a nonempty UTF-8 JSON response.`);let a=0,o=``,s=new TextDecoder(`utf-8`,{fatal:!0}),c=()=>{i.cancel().catch(()=>{})};r?.addEventListener(`abort`,c,{once:!0});try{for(;;){r?.throwIfAborted();let e=await i.read();if(e.done)break;a+=e.value.byteLength,a>1048576&&t(``,`Use a file of at most 1 MiB.`,`MIEN_SIZE`),o+=s.decode(e.value,{stream:!0})}return r?.throwIfAborted(),n(JSON.parse(o+s.decode()))}catch(e){throw await i.cancel().catch(()=>{}),e}finally{r?.removeEventListener(`abort`,c),i.releaseLock()}}export{r as n,i as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{L as e,g as t,h as n,l as r,m as i,r as a,s as o,u as s,y as c}from"./activate-
|
|
1
|
+
import{L as e,g as t,h as n,l as r,m as i,r as a,s as o,u as s,y as c}from"./activate-CCUqRQyO.js";var l=.5,u=new Float64Array(o*3),d=new Float64Array(o*3),f=new Uint32Array(o*3),p=new Int32Array(128),m=[],h=new Int32Array(4096),g=new Int8Array(4608),_=384,v=Float64Array.from({length:769},(e,t)=>Math.cos((t-_)*r)),y=Float64Array.from({length:769},(e,t)=>Math.sin((t-_)*r)),b=97,x=new Float64Array(o),S=({positions:e,normals:t},n,r,a)=>{let{m:s,t:l}=n,u=r/620;for(let n=0;n<o;n+=1){let r=n*3,i=e[r],a=e[r+1],o=e[r+2],c=t[r],d=t[r+1],f=t[r+2],p=s[0]*i+s[1]*a+s[2]*o+l[0],m=s[3]*i+s[4]*a+s[5]*o+l[1],h=s[6]*i+s[7]*a+s[8]*o+l[2],g=s[0]*c+s[1]*d+s[2]*f,_=s[3]*c+s[4]*d+s[5]*f,v=s[6]*c+s[7]*d+s[8]*f;x[n]=v*(1-u*h)-u*(g*p+_*m)}let d=(t,o)=>{let s=x[t],l=x[o];if(s>0==l>0)return;let u=s/(s-l),d=n=>e[t*3+n]+(e[o*3+n]-e[t*3+n])*u;i(n,r,d(0),d(1),d(2)),a(c[0],c[1])};for(let e=0;e<=48;e+=1)for(let t=0;t<96;t+=1){let n=e*b+t;d(n,n+1),e<48&&d(n,n+b)}},C=(e,t,n,l,f,p=1)=>{f.fill(0);let{positions:m}=e;for(let e=0;e<o;e+=1)i(t,n,m[e*3],m[e*3+1],m[e*3+2]),u[e]=c[0]-l[0],d[e]=c[1]-l[1];for(let e=0;e<48;e+=1)for(let t=0;t<96;t+=1){let n=e*b+t,r=n+1,i=r+b,a=n+b,o=u[n],s=d[n],c=u[r],l=d[r],f=u[i],p=d[i],m=u[a],h=d[a],_=(c-o)*(h-s)-(l-s)*(m-o),v=(f-c)*(s-l)-(p-l)*(o-c),y=(m-f)*(l-p)-(h-p)*(c-f),x=(o-m)*(p-h)-(s-h)*(f-m);g[e*96+t]=_>0&&v>0&&y>0&&x>0?1:_<0&&v<0&&y<0&&x<0?-1:0}let h=(e,t)=>{let n=u[e],i=d[e],a=u[t],o=d[t],c=Math.atan2(i,n),l=Math.atan2(o,a);if(l-c>Math.PI&&(l-=s),c-l>Math.PI&&(l+=s),c>l){let e=c;c=l,l=e}let p=a-n,m=o-i,h=n*m-i*p,g=Math.floor(l/r);for(let e=Math.ceil(c/r);e<=g;e+=1){let t=v[e+_]*m-y[e+_]*p;if(Math.abs(t)<1e-9)continue;let n=h/t,r=(e%192+192)%192;n>f[r]&&(f[r]=n)}};for(let e=0;e<=48;e+=1)for(let t=0;t<96;t+=1){let n=e*b+t,r=e*96+t,i=e>0?g[r-96]:0,a=e<48?g[r]:0;if((!i||i!==a)&&h(n,n+1),e<48){let e=t>0?g[r-1]:0;(!e||e!==a)&&h(n,n+b)}}return a(f,p)},w=(e,t,n)=>(u[t]-u[e])*(d[n]-d[e])-(d[t]-d[e])*(u[n]-u[e]),T=(e,t,n,r,a,s,p=1)=>{let{positions:g,normals:_}=e,{m:v}=n,y=0;S(e,n,r,(e,t)=>{u[y]=e,d[y]=t,y+=1});let b=y,x=0,C=0;if(b>=3){for(let e=0;e<b;e+=1)f[e]=e;A(b),m.length=0;for(let e=0;e<2;e+=1){let t=m.length;for(let n=0;n<b;n+=1){let r=f[e===0?n:b-1-n];for(;m.length>=t+2&&w(m[m.length-2],m[m.length-1],r)<=0;)m.pop();m.push(r)}m.pop(),e===0&&(x=m.length)}C=Math.min(m.length,h.length-1);for(let e=0;e<C;e+=1)h[e]=m[e];h[C]=m[0]}let T=C>=3&&x>=1&&C-x>=1&&C===m.length,E=(e,t,n)=>{let r=h[e],i=h[e+1],a=u[i]-u[r],o=d[i]-d[r];return a*(n-d[r])-o*(t-u[r])>1e-7*(Math.abs(a)+Math.abs(o))+1e-9};for(let e=0;e<o;e+=t){let t=v[6]*_[e*3]+v[7]*_[e*3+1]+v[8]*_[e*3+2];if(Math.abs(t)>l)continue;i(n,r,g[e*3],g[e*3+1],g[e*3+2]);let a=c[0],o=c[1];if(T&&a>u[h[0]]&&a<u[h[x]]){let e=0,t=x;for(;t-e>1;){let n=e+t>>1;u[h[n]]<=a?e=n:t=n}if(E(e,a,o)){for(e=x,t=C;t-e>1;){let n=e+t>>1;u[h[n]]>a?e=n:t=n}if(E(e,a,o))continue}}u[y]=a,d[y]=o,y+=1}return M(y,a,s,p)},E=(e,t)=>u[e]<u[t]||u[e]===u[t]&&d[e]<d[t],D=e=>{let t=0;for(p[t++]=0,p[t++]=e-1;t>0;){let e=p[--t],n=p[--t];if(e-n<16){for(let t=n+1;t<=e;t+=1){let e=f[t],r=t-1;for(;r>=n&&E(e,f[r]);)f[r+1]=f[r],--r;f[r+1]=e}continue}let r=n+e>>>1;E(f[r],f[n])&&j(r,n),E(f[e],f[n])&&j(e,n),E(f[e],f[r])&&j(e,r);let i=f[r],a=n,o=e;for(;a<=o;){for(;E(f[a],i);)a+=1;for(;E(i,f[o]);)--o;a<=o&&(j(a,o),a+=1,--o)}o-n<e-a?(a<e&&(p[t++]=a,p[t++]=e),n<o&&(p[t++]=n,p[t++]=o)):(n<o&&(p[t++]=n,p[t++]=o),a<e&&(p[t++]=a,p[t++]=e))}},O=new Uint32Array(f.length+1),k=new Uint32Array(f.length),A=e=>{let t=1/0,n=-1/0;for(let r=0;r<e;r+=1){let e=u[f[r]];e<t&&(t=e),e>n&&(n=e),e!==e&&(t=NaN)}if(!(n>t)||!Number.isFinite(n-t))return D(e);let r=(e-1)/(n-t);O.fill(0,0,e+1);for(let n=0;n<e;n+=1)O[((u[f[n]]-t)*r|0)+1]+=1;for(let t=0;t<e;t+=1)O[t+1]+=O[t];for(let n=0;n<e;n+=1){let e=f[n],i=(u[e]-t)*r|0;k[O[i]]=e,O[i]+=1}f.set(k.subarray(0,e));for(let t=1;t<e;t+=1){let e=f[t],n=t-1;for(;n>=0&&E(e,f[n]);)f[n+1]=f[n],--n;f[n+1]=e}},j=(e,t)=>{let n=f[e];f[e]=f[t],f[t]=n},M=(e,i,o,c=1)=>{for(let t=0;t<e;t+=1)f[t]=t;e>1&&A(e),m.length=0;for(let t=0;t<2;t+=1){let n=m.length;for(let r=0;r<e;r+=1){let i=f[t===0?r:e-1-r];for(;m.length>=n+2&&w(m[m.length-2],m[m.length-1],i)<=0;)m.pop();m.push(i)}m.pop()}o.fill(0);for(let e=0;e<m.length;e+=1){let a=m[e],c=m[(e+1)%m.length],l=u[a]-i[0],f=d[a]-i[1],p=u[c]-i[0],h=d[c]-i[1],g=p-l,_=h-f,v=Math.atan2(f,l),y=Math.atan2(h,p);y-v>Math.PI&&(y-=s),v-y>Math.PI&&(y+=s),v>y&&([v,y]=[y,v]);let b=m.length<3||Math.abs(l*h-f*p)<1e-10,x=b?0:Math.floor(v/r)-1,S=b?191:Math.ceil(y/r)+1;for(let e=x;e<=S;e+=1){let r=(e%192+192)%192,i=n[r],a=t[r],s=i*_-a*g;if(Math.abs(s)<1e-9)continue;let c=(l*_-f*g)/s,u=(l*a-f*i)/s;c>o[r]&&u>=-1e-6&&u<=1+1e-6&&(o[r]=c)}}return a(o,c)},N=(t,n,r,a,o)=>{let s=t.type===`blob`?e(t).hull:void 0;if(!s)return!1;for(let e=0;e<s.length;e++){let a=s[e];i(n,r,a[0]*t.width/2,a[1]*t.height/2,a[2]*t.depth/2),u[e]=c[0],d[e]=c[1]}return M(s.length,a,o,t.outlineRounding??1),!0};export{T as convexProfile,N as sculptProfile,C as starProfile};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime-DK3Fl9T5.js";import{A as t,F as n,I as r,L as i,M as a,P as o,a as s,x as c}from"./activate-C80BK8CF.js";var l=()=>{let e=new Float64Array,t=new Float64Array,n=new Float64Array,r=new Float64Array,i=new Float64Array;return(a,o,s,c,l,u,d,f)=>{let p=a.length/3,m=f.length;e.length!==p&&(e=new Float64Array(p),t=new Float64Array(p),n=new Float64Array(p)),r.length!==m*4+1&&(r=Float64Array.from({length:m*4+1},(e,t)=>Math.cos((t-m*2)/m*Math.PI*2)),i=Float64Array.from({length:m*4+1},(e,t)=>Math.sin((t-m*2)/m*Math.PI*2)));let h=Math.PI*2,g=h/m;f.fill(0);for(let r=0;r<p;r+=1){let i=a[r*3],o=a[r*3+1],s=a[r*3+2],f=c[0]*i+c[1]*o+c[2]*s+l[0],p=c[3]*i+c[4]*o+c[5]*s+l[1],m=620-(c[6]*i+c[7]*o+c[8]*s+l[2])*u,h=620/(Math.abs(m)<1e-4?1e-4:m);e[r]=f*h-d[0],t[r]=p*h-d[1],n[r]=Math.atan2(t[r],e[r])}let _=(a,o)=>{let s=e[a],c=t[a],l=e[o]-s,u=t[o]-c,d=n[a],p=n[o];p-d>Math.PI&&(p-=h),d-p>Math.PI&&(p+=h),d>p&&([d,p]=[p,d]);let _=s*u-c*l;for(let e=Math.ceil(d/g),t=Math.floor(p/g);e<=t;e+=1){let t=r[e+m*2]*u-i[e+m*2]*l;if(Math.abs(t)<1e-9)continue;let n=_/t,a=(e%m+m)%m;n>f[a]&&(f[a]=n)}};for(let e=0;e<o;e+=1)for(let t=0;t<s;t+=1){let n=e*s+t;t+1<s&&_(n,n+1),e+1<o&&_(n,n+s)}return f}},u=new WeakMap,d=e=>{if(e.type!==`blob`)return;let n=i(e),o=n?.radialDepthPower;if(!n||!o)return;let s=a(e)+`|`+o,c=u.get(n.radii);c||u.set(n.radii,c=new Map);let l=c.get(s);if(l)return l;let d=new Float32Array(13107);for(let i=0;i<17;i+=1){let a=-Math.PI/2+i/16*Math.PI,s=i===0||i===16?0:Math.max(0,Math.cos(a))**(2/o);for(let o=0;o<=256;o+=1){let c=o/256*Math.PI*2,l=r(n.radii,c)*s,u=l*Math.cos(c)*e.width/2,f=l*Math.sin(c)*e.height/2,p=i===8?0:Math.sign(a)*t(e,u,f).point[2],m=(i*257+o)*3;d[m]=u,d[m+1]=f,d[m+2]=p}}let f={positions:d,rows:17,columns:257};return c.size>=8&&c.delete(c.keys().next().value),c.set(s,f),f},f;function p(e,t,n,r,i){let a=d(e);return a?((f??=l())(a.positions,a.rows,a.columns,t.m,t.t,n,r,i),!0):!1}var m=e({ellipsoidUnionOutline:()=>v}),h=Math.PI/4,g=4/3*Math.tan(h/4),_=.01,v=(e,t,n,r)=>{if(e.type!==`blob`||e.outlineRounding!==0)return;let a=i(e).lobes;if(!a||!a.parts.length||a.crown||a.parts.some(e=>(e.power??2)!==2||(e.horizontalPower??e.power??2)!==2))return;let o=[e.width/2,e.height/2,e.depth/2],l=a.blend*Math.log(a.parts.length),{m:u,t:d}=t,f=n/620,p=[],m=0,v=0;for(let e of a.parts){let t=(e.rotation??0)*Math.PI/180,n=(e.tilt??0)*Math.PI/180,r=Math.cos(t),i=Math.sin(t),a=Math.cos(n),c=Math.sin(n),h=[r,-i*a,i*c,i,r*a,-r*c,0,c,a],g=Array.from({length:9},(t,n)=>{let r=Math.floor(n/3),i=n%3;return(u[r*3]*o[0]*h[i]+u[r*3+1]*o[1]*h[i+3]+u[r*3+2]*o[2]*h[i+6])*e.radii[i]}),y=[0,1,2].map(t=>d[t]+u[t*3]*o[0]*e.center[0]+u[t*3+1]*o[1]*e.center[1]+u[t*3+2]*o[2]*e.center[2]),b=(e,t)=>g[e*3]*g[t*3]+g[e*3+1]*g[t*3+1]+g[e*3+2]*g[t*3+2],x=[b(0,0),b(0,1),b(0,2),b(1,1),b(1,2),b(2,2)],S=s(y,x,f);if(!S)return;let C=1+l/Math.min(...e.radii),w=s(y,x.map(e=>e*C*C),f);if(!w)return;let T=Math.hypot(w.x-S.x,w.y-S.y)+Math.hypot(w.ux-S.ux,w.uy-S.uy,w.vy-S.vy),E=43e-7*Math.hypot(S.ux,S.uy,S.vy);if(m=Math.max(m,T+E),m>_)return;let D=S.ux**2,O=S.ux*S.uy,k=S.uy**2+S.vy**2;v=Math.max(v,Math.hypot(S.x,S.y)+Math.sqrt((D+k+Math.hypot(D-k,2*O))/2)+E),p.push(S)}let y=10**r,b=e=>Math.round(e*y)/y,x=``;for(let e of p){let t=t=>[e.x+e.ux*Math.cos(t),e.y+e.uy*Math.cos(t)+e.vy*Math.sin(t)],n=t=>[-e.ux*Math.sin(t),-e.uy*Math.sin(t)+e.vy*Math.cos(t)],r=t(0);x+=`M${b(r[0])} ${b(r[1])}`;for(let e=0;e<8;e++){let r=e*h,i=r+h,a=t(r),o=t(i),s=n(r),c=n(i);x+=`C${b(a[0]+g*s[0])} ${b(a[1]+g*s[1])} ${b(o[0]-g*c[0])} ${b(o[1]-g*c[1])} ${b(o[0])} ${b(o[1])}`}x+=`Z`}let S=Math.SQRT2*.5*10**-r;return{path:c(x),reach:v+S,enclosureMargin:m,maximumEnclosureMargin:m+S}},y=.65,b=e=>{if(e>=-.35)return[0,0];if(e<=-1)return[1,0];let t=(-e-.35)/y;return[t*t*t*(t*(t*6-15)+10),-30*t*t*(1-t)*(1-t)/y]},x=({dip:e,lift:t,width:n},r,i)=>{let a=r/n,o=i/n,s=Math.exp(-(a**4)),c=Math.exp(-(o**4)),l=e+t;return[l*(s+c-s*c)-t,-l*(1-c)*4*a**3*s/n,-l*(1-s)*4*o**3*c/n]},S=(e,t)=>t[1]>=-.35||!(e.dip||e.lift)?t:[t[0],t[1]+b(t[1])[0]*x(e,t[0],t[2])[0],t[2]],C=(e,t,n,r)=>{if(n>=-.35||!(e.dip||e.lift))return n;let i=x(e,t,r)[0],a=n-e.dip,o=n+e.lift,s=n;for(let e=0;e<48;e++){let[e,t]=b(s),r=s+i*e-n;if(Math.abs(r)<=1e-14)return s;r<=0?a=s:o=s;let c=s-r/(1+i*t);s=c>a&&c<o?c:(a+o)/2}return(a+o)/2},w=(e,t)=>{let n=C(e,...t),[r,i]=b(n),[a,o,s]=x(e,t[0],t[2]),c=1/(1+a*i);return{point:[t[0],n,t[2]],row:[-r*o*c,c,-r*s*c]}},T=(e,t,n)=>{if(t[1]>=-.35||!(e.dip||e.lift))return n;let[r,i]=b(t[1]),[a,o,s]=x(e,t[0],t[2]),c=n[1]/(1+a*i),l=n[0]-c*r*o,u=n[2]-c*r*s,d=Math.hypot(l,c,u)||1;return[l/d,c/d,u/d]},E=({dip:e,lift:t,width:n})=>Math.hypot(1,(e+t)*4*(3/4)**.75*Math.exp(-.75)/n/(1-e*1.875/y)),D=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`,O=46,k=126,A=new Int8Array(128).fill(-1);for(let e=0;e<64;e+=1)A[D.charCodeAt(e)]=e;var j=e=>((e+32768&65535)>>>0)-32768,ee=(e,t,n)=>{let r=n%t,i=r?e[n-1]:0,a=n>=t?e[n-t]:0,o=r&&n>=t?e[n-t-1]:0;return i+a-o},te=(e,t)=>{let n=new Int16Array(t*t),r=t=>{let n=e.charCodeAt(t);return n<128?A[n]:-1},i=0,a=0;for(;a<e.length;){let o=e.charCodeAt(a);if(o===k){let e=r(a+1),o=r(a+2);if(e<0||o<0)return;let s=i+e*64+o;if(s>n.length)return;for(;i<s;i+=1)n[i]=j(ee(n,t,i));a+=3;continue}let s;if(o===O){let e=r(a+1),t=r(a+2),n=r(a+3);if(e<0||t<0||n<0)return;s=e<<12|t<<6|n,a+=4}else{if(s=r(a),s<0)return;a+=1}if(i>=n.length)return;let c=s&1?-(s+1>>1):s>>1;n[i]=j(ee(n,t,i)+c),i+=1}return i===n.length?n:void 0},M=new WeakMap;function ne(e){let t=e.geometry?.relief;t&&M.delete(t)}var re=e=>{let t=M.get(e),n=e.bits??8;if(!t||t.bits!==n||t.scale!==e.scale||t.packedFront!==e.front||t.packedBack!==e.back){let r=t=>{if(e.coding===`delta`){let n=te(t,e.size)??new Int16Array(e.size**2);return Float32Array.from(n,t=>t/32767*e.scale)}let r=Uint8Array.from(atob(t),e=>e.charCodeAt(0));if(n===16){let t=new DataView(r.buffer);return Float32Array.from({length:r.length/2},(n,r)=>t.getInt16(r*2,!0)/32767*e.scale)}return Float32Array.from(r,t=>(t>127?t-256:t)/127*e.scale)};t={bits:n,scale:e.scale,packedFront:e.front,packedBack:e.back,front:r(e.front),back:r(e.back)},M.set(e,t)}return t},N=(e,t,n,r)=>{let{size:i,range:a}=t,o=(n+a)/(2*a)*(i-1),s=(r+a)/(2*a)*(i-1),c=Math.floor(o),l=Math.floor(s),u=(t,n)=>e[Math.min(i-1,Math.max(0,n))*i+Math.min(i-1,Math.max(0,t))],d=(e,t,n,r,i)=>t+.5*i*(n-e+i*(2*e-5*t+4*n-r+i*(3*(t-n)+r-e))),f=e=>d(u(c-1,e),u(c,e),u(c+1,e),u(c+2,e),o-c);return d(f(l-1),f(l),f(l+1),f(l+2),s-l)};function ie(e,t,r,i,a){let o=re(t),s=N(o.front,t,i,a)*e.depth,c=N(o.back,t,i,a)*e.depth,l=(s+c)/2,u=Math.min(1,Math.max(0,n(r,i,a)/(t.rim??.05))),d=u*u*(3-2*u);return{front:l+(s-l)*d,back:l+(c-l)*d}}var ae=e({lobeFieldAt:()=>oe,lobeFrontRead:()=>be,lobeFrontSample:()=>ye,lobePoint:()=>se,lobeRayFieldAt:()=>$,lobeSample:()=>ce,lobeVisibility:()=>xe,releaseRelief:()=>ne,reliefFaces:()=>ie}),P=new WeakMap,F=1e-8,I=1e-11,L=e=>{let t=P.get(e);if(t)return t;let n=e.blend,r=n*Math.log(e.parts.length),i=e.parts.map(({center:e,radii:t,power:n,horizontalPower:r,rotation:i,tilt:a})=>({center:e,inverseX:1/t[0],inverseY:1/t[1],inverseZ:1/t[2],distanceScale:Math.min(...t),power:n??2,horizontalPower:r??n??2,cosine:Math.cos((i??0)*Math.PI/180),sine:Math.sin((i??0)*Math.PI/180),tiltCosine:Math.cos((a??0)*Math.PI/180),tiltSine:Math.sin((a??0)*Math.PI/180)})),a={parts:i,blend:n,radialBound:Math.max(...e.parts.map(({center:e,radii:t})=>{let n=Math.hypot(...t);return Math.hypot(...e)+n+r*n/Math.min(...t)}))+1e-6,fields:new Float64Array(i.length),hint:0};return P.set(e,a),a},R=(e,t,n)=>n===2?Math.hypot(e,t):(Math.abs(e)**n+Math.abs(t)**n)**(1/n),z=(e,t,n,r,i)=>r===i?r===2?Math.hypot(e,t,n):(Math.abs(e)**r+Math.abs(t)**r+Math.abs(n)**r)**(1/r):R(R(e,n,i),t,r),B=(e,t,n,r,i,a,o)=>{let s=z(e,t,n,r,i);if(s<=1e-15)return[0,0];if(r===i)return[s,r===2?(t*a+n*o)/s:Math.sign(t)*(Math.abs(t)/s)**(r-1)*a+Math.sign(n)*(Math.abs(n)/s)**(r-1)*o];let c=R(e,n,i);return[s,Math.sign(t)*(Math.abs(t)/s)**(r-1)*a+(c>0?(c/s)**(r-1)*Math.sign(n)*(Math.abs(n)/c)**(i-1)*o:0)]},V=(e,t,n,r,i)=>{let a=R(e,n,i),o=R(a,t,r);if(o<=1e-15)return[0,0,0];let s=(a/o)**(r-1);return[a>0?s*Math.sign(e)*(Math.abs(e)/a)**(i-1):0,Math.sign(t)*(Math.abs(t)/o)**(r-1),a>0?s*Math.sign(n)*(Math.abs(n)/a)**(i-1):0]},H=(e,t,n,r)=>{let i=t-e.center[0],a=n-e.center[1],o=r-e.center[2],s=-e.sine*i+e.cosine*a;return(z((e.cosine*i+e.sine*a)*e.inverseX,(e.tiltCosine*s+e.tiltSine*o)*e.inverseY,(-e.tiltSine*s+e.tiltCosine*o)*e.inverseZ,e.power,e.horizontalPower)-1)*e.distanceScale},U=({parts:e,blend:t,fields:n},r,i,a)=>{let o=1/0;for(let t=0;t<e.length;t+=1){let s=H(e[t],r,i,a);n[t]=s,o=Math.min(o,s)}let s=0;for(let r=0;r<e.length;r+=1)s+=Math.exp((o-n[r])/t);return o-t*Math.log(s)},oe=(e,t)=>{let n=e.crown&&t[1]<-.35?[t[0],C(e.crown,...t),t[2]]:t;return U(L(e),...n)},W=({parts:e,blend:t},n,r,i)=>{let a=1/0;for(let t of e)a=Math.min(a,H(t,n,r,i));let o=0,s=0,c=0;for(let l of e){let e=n-l.center[0],u=r-l.center[1],d=i-l.center[2],f=-l.sine*e+l.cosine*u,p=(l.cosine*e+l.sine*u)*l.inverseX,m=(l.tiltCosine*f+l.tiltSine*d)*l.inverseY,h=(-l.tiltSine*f+l.tiltCosine*d)*l.inverseZ,g=z(p,m,h,l.power,l.horizontalPower);if(g<=1e-12)continue;let _=Math.exp((a-(g-1)*l.distanceScale)/t)*l.distanceScale,v=V(p,m,h,l.power,l.horizontalPower),y=v[0]*l.inverseX*_,b=v[1]*l.inverseY*_,x=v[2]*l.inverseZ*_,S=l.tiltCosine*b-l.tiltSine*x;o+=l.cosine*y-l.sine*S,s+=l.sine*y+l.cosine*S,c+=l.tiltSine*b+l.tiltCosine*x}let l=Math.hypot(o,s,c)||1;return[o/l,s/l,c/l]},G=(e,t,n)=>{let r=L(e),i=Math.cos(n)*Math.sin(t),a=Math.sin(n),o=Math.cos(n)*Math.cos(t),s=0;for(let e of r.parts){if(e.power!==2||e.horizontalPower!==2)continue;let t=-e.sine*i+e.cosine*a,n=(e.cosine*i+e.sine*a)*e.inverseX,r=(e.tiltCosine*t+e.tiltSine*o)*e.inverseY,c=(-e.tiltSine*t+e.tiltCosine*o)*e.inverseZ,l=-e.sine*e.center[0]+e.cosine*e.center[1],u=(e.cosine*e.center[0]+e.sine*e.center[1])*e.inverseX,d=(e.tiltCosine*l+e.tiltSine*e.center[2])*e.inverseY,f=(-e.tiltSine*l+e.tiltCosine*e.center[2])*e.inverseZ,p=n*n+r*r+c*c,m=n*u+r*d+c*f,h=u*u+d*d+f*f-1;s=Math.max(s,(m+Math.sqrt(Math.max(0,m*m-p*h)))/p)}let c=r.radialBound,l=e=>U(r,i*e,a*e,o*e),u=-1/0,d=1/0,f=s,p=c,m,h,g=r.hint;if(g>s&&g<c){let e=l(g),t=g*.01;if(e<=0)for(f=g,m=e;;){let e=f+t;if(!(e<c)){h=l(c);break}let n=l(e);if(n>0){p=e,h=n;break}f=e,m=n,t*=4}else for(p=g,h=e;;){let e=p-t;if(!(e>s)){m=l(s);break}let n=l(e);if(n<=0){f=e,m=n;break}p=e,h=n,t*=4}}else m=l(f),h=l(p);if(m<=0&&h>=I){d=p,m<=-1e-11&&(u=f);let e=f,t=m,n=p,r=h,i=0,a=m>-1e-11?f:NaN;for(let o=0;o<16&&a!==a;o++){let o=f-m*(p-f)/(h-m);if(o>f&&o<p||(o=(f+p)/2),!(o>f&&o<p))break;let s=l(o);if(e=n,t=r,n=o,r=s,s<=0?(f=o,m=s,s<=-1e-11&&(u=o),i>0&&(h*=.5),i=1):(p=o,h=s,s>=I&&(d=o),i<0&&(m*=.5),i=-1),s>-1e-11&&s<I){a=o;break}}let o=(r-t)/(n-e);if(a===a&&o>0){for(let e=4*I/o,t=0;t<4;e*=8,t++){let t=a-e;if(!(t>u))break;if(l(t)<=-1e-11){u=t;break}}for(let e=4*I/o,t=0;t<4;e*=8,t++){let t=a+e;if(!(t<d))break;if(l(t)>=I){d=t;break}}}}for(let e=0;e<30;e++){let e=(s+c)/2;e<=u||e<d&&l(e)<=0?s=e:c=e}let _=(s+c)/2;return r.hint=_,[i*_,a*_,o*_]},se=(e,t,n)=>{let r=G(e,t,n);return e.crown?S(e.crown,r):r},ce=(e,t,n)=>{let r=G(e,t,n),i=W(L(e),...r);return e.crown?{point:S(e.crown,r),normal:T(e.crown,r,i)}:{point:r,normal:i}},K=(e,t,n)=>{let r=t;for(let i=0;i<16&&t-e>1e-10;i++){let[i,a]=n(r);i<=0?e=r:t=r;let o=a>1e-15?i/a:1/0;if(i>0&&Number.isFinite(o)){let i=r-2*o-1e-10;i>e&&i<t&&(n(i)[0]<=0?e=i:t=i)}let s=r-o;r=s>e&&s<t?s:(e+t)/2}for(let r=0;r<40&&t-e>1e-10;r++){let r=(e+t)/2;n(r)[0]<=0?e=r:t=r}return[e,t]},le=(e,t,n,r)=>{let i=e.parts.map(e=>{let i=t-e.center[0],a=n-e.center[1],o=r-e.center[2],s=-e.sine*i+e.cosine*a,c=B((e.cosine*i+e.sine*a)*e.inverseX,(e.tiltCosine*s+e.tiltSine*o)*e.inverseY,(-e.tiltSine*s+e.tiltCosine*o)*e.inverseZ,e.power,e.horizontalPower,e.tiltSine*e.inverseY,e.tiltCosine*e.inverseZ);return[(c[0]-1)*e.distanceScale,c[1]*e.distanceScale]}),a=Math.min(...i.map(e=>e[0])),o=0,s=0;return i.forEach(([t,n])=>{let r=Math.exp((a-t)/e.blend);o+=r,s+=r*n}),[a-e.blend*Math.log(o),s/o]},ue=(e,t,n,r)=>{let i=t-e.center[0],a=n-e.center[1],o=(e.cosine*i+e.sine*a)*e.inverseX,s=-e.sine*i+e.cosine*a,c=e.tiltSine*e.inverseY,l=e.tiltCosine*s*e.inverseY,u=e.tiltCosine*e.inverseZ,d=-e.tiltSine*s*e.inverseZ,f;if(Math.abs(c)<1e-15)f=-d/u;else if(Math.abs(u)<1e-15)f=-l/c;else if(e.power===e.horizontalPower){let t=-Math.sign(u/c)*Math.abs(u/c)**(1/(e.power-1));f=(t*d-l)/(c-t*u)}else{let t=Math.min(-l/c,-d/u),n=Math.max(-l/c,-d/u);for(let r=0;r<44;r++){let r=(t+n)/2,i=V(o,c*r+l,u*r+d,e.power,e.horizontalPower);i[1]*c+i[2]*u<=0?t=r:n=r}f=(t+n)/2}let p=e.power/(e.power-1),m=(Math.abs(e.tiltSine/e.inverseY)**p+Math.abs(e.tiltCosine/e.inverseZ)**p)**(1/p),h=e.center[2]-m*r,g=t=>z(o,c*t+l,u*t+d,e.power,e.horizontalPower),_=t=>{if(Math.abs(e.tiltSine)<1e-12){let n=t**e.power-Math.abs(l)**e.power;if(n<0)return;let r=n**(e.horizontalPower/e.power)-Math.abs(o)**e.horizontalPower;return r<0?void 0:e.center[2]+r**(1/e.horizontalPower)/e.inverseZ}if(e.power===2&&e.horizontalPower===2){let n=c*c+u*u,r=c*l+u*d,i=o*o+l*l+d*d-t*t,a=r*r-n*i;return a<0?void 0:e.center[2]+(-r+Math.sqrt(a))/n}let n=t;if(g(f)>n)return;let r=K(f,m*t,t=>{let r=B(o,c*t+l,u*t+d,e.power,e.horizontalPower,c,u);return[r[0]-n,r[1]]});return e.center[2]+r[t===1?0:1]};return{minimum:e.center[2]+f,front:_(r),rawFront:_(1),lower:h}},de=(e,t,n,r)=>{let i=e.parts.map(e=>H(e,t,n,r)),a=e.parts.map(e=>{let t=e.power/(e.power-1);return e.distanceScale*(Math.abs(e.tiltSine*e.inverseY)**t+Math.abs(e.tiltCosine*e.inverseZ)**t)**(1/t)}),o=0,s=Math.min(...i.map((e,t)=>e/a[t]));for(let t=0;t<20;t++){let t=(o+s)/2,n=1/0;for(let e=0;e<i.length;e++)n=Math.min(n,i[e]-a[e]*t);let r=0;for(let o=0;o<i.length;o++)r+=Math.exp((n-i[o]+a[o]*t)/e.blend);n-e.blend*Math.log(r)>0?o=t:s=t}return o},fe=(e,t,n)=>{let r=L(e),i=r.blend*Math.log(r.parts.length),a=-1/0,o=1/0,s=-1/0,c=-1/0;for(let e of r.parts){let r=ue(e,t,n,1+i/e.distanceScale);c=Math.max(c,r.minimum),r.front!==void 0&&(a=Math.max(a,r.front),o=Math.min(o,r.lower),r.rawFront!==void 0&&(s=Math.max(s,r.rawFront)))}if(a===-1/0)return{point:[t,n,0],normal:[0,0,1]};if(s=Math.max(s,c),s<=a&&U(r,t,n,s)<=0){let e=K(s,a,e=>le(r,t,n,e)),i=(e[0]+e[1])/2;return{point:[t,n,i],normal:W(r,t,n,i)}}let l=a+F,u=l;for(let e=0;e<2048&&l>=o-F;e++){let i=U(r,t,n,l);if(Math.abs(i)<=F)return{point:[t,n,l],normal:W(r,t,n,l)};if(i<0){let e=l;for(let i=0;i<40;i++){let i=(e+u)/2;U(r,t,n,i)<=0?e=i:u=i}let i=(e+u)/2;return{point:[t,n,i],normal:W(r,t,n,i)}}u=l,l-=e<32?i:de(r,t,n,l)}return{point:[t,n,0],normal:[0,0,1]}},pe=(e,t,n,r,i)=>{let a=n.z<=0&&r.z>=0?Math.min(i,n.sourceY,r.sourceY):Math.min(n.sourceY,r.sourceY),o=Math.max(n.sourceY,r.sourceY),s=(a+o)/2,c=(o-a)/2,l=(n.z+r.z)/2,u=(r.z-n.z)/2,d=e.parts.map(e=>{let n=t-e.center[0],r=s-e.center[1],i=l-e.center[2],a=-e.sine*n+e.cosine*r;return(z(Math.max(0,Math.abs(e.cosine*n+e.sine*r)-Math.abs(e.sine)*c)*e.inverseX,Math.max(0,Math.abs(e.tiltCosine*a+e.tiltSine*i)-Math.abs(e.tiltCosine*e.cosine)*c-Math.abs(e.tiltSine)*u)*e.inverseY,Math.max(0,Math.abs(-e.tiltSine*a+e.tiltCosine*i)-Math.abs(e.tiltSine*e.cosine)*c-Math.abs(e.tiltCosine)*u)*e.inverseZ,e.power,e.horizontalPower)-1)*e.distanceScale}),f=Math.min(...d);return f-e.blend*Math.log(d.reduce((t,n)=>t+Math.exp((f-n)/e.blend),0))},me=(e,t,n)=>{let r=e.crown,i=L(e),a=i.radialBound,o=e=>{let a=C(r,t,n,e);return{z:e,sourceY:a,value:U(i,t,a,e)}},s=C(r,t,n,0),c=E(r),l=[{lo:o(-a),hi:o(a),depth:0}];for(;l.length;){let{lo:e,hi:a,depth:u}=l.pop(),d=a.z-e.z;if(e.value>0&&a.value>0&&e.value+a.value>c*d||pe(i,t,e,a,s)>0)continue;let f=(e.z+a.z)/2;if(u>=48||d<=1e-9/c||f===e.z||f===a.z){let o=Math.abs(e.value)<Math.abs(a.value)?e:a;if(o.value>F)continue;let s=[t,o.sourceY,o.z];return{point:[t,n,o.z],normal:T(r,s,W(i,...s))}}let p=o(f);l.push({lo:e,hi:p,depth:u+1},{lo:p,hi:a,depth:u+1})}return{point:[t,n,0],normal:[0,0,1]}},q=new WeakMap,he=2048,J=(e,t,n)=>e.crown&&n<-.35?me(e,t,n):fe(e,t,n),Y=1.25,X=64,ge=Math.round(Y*2*X)+1,_e=[.02,.05,.05,.05],Z=new WeakMap,Q=new Float64Array(4),ve=(e,t,n)=>{let r=Z.get(e);if(r||(r=o(ge,4,(t,n,r)=>{let i=J(e,t/X-Y,n/X-Y);return r[0]=i.point[2],r[1]=i.normal[0],r[2]=i.normal[1],r[3]=i.normal[2],i.point[2]!==0||i.normal[2]!==1},_e),Z.set(e,r)),!r.read((t+Y)*X,(n+Y)*X,Q))return;let[i,a,s,c]=Q,l=Math.hypot(a,s,c);if(l>1e-6)return{point:[t,n,i],normal:[a/l,s/l,c/l]}},ye=(e,t,n)=>{let r=q.get(e);r||q.set(e,r=new Map);let i=`${t}|${n}`,a=r.get(i);if(a)return r.delete(i),r.set(i,a),a;let o=J(e,t,n);return r.set(i,o),r.size>he&&r.delete(r.keys().next().value),o},be=(e,t,n)=>ve(e,t,n)??ye(e,t,n),$=(e,t,n)=>{let r=L(e);if(e.crown&&t[1]<-.35){let r=w(e.crown,t);n=[n[0],r.row[0]*n[0]+r.row[1]*n[1]+r.row[2]*n[2],n[2]],t=r.point}let i=r.parts.map(e=>{let r=t[0]-e.center[0],i=t[1]-e.center[1],a=t[2]-e.center[2],o=-e.sine*r+e.cosine*i,s=(e.cosine*r+e.sine*i)*e.inverseX,c=(e.tiltCosine*o+e.tiltSine*a)*e.inverseY,l=(-e.tiltSine*o+e.tiltCosine*a)*e.inverseZ,u=-e.sine*n[0]+e.cosine*n[1],d=(e.cosine*n[0]+e.sine*n[1])*e.inverseX,f=(e.tiltCosine*u+e.tiltSine*n[2])*e.inverseY,p=(-e.tiltSine*u+e.tiltCosine*n[2])*e.inverseZ,m=V(s,c,l,e.power,e.horizontalPower);return[(z(s,c,l,e.power,e.horizontalPower)-1)*e.distanceScale,(m[0]*d+m[1]*f+m[2]*p)*e.distanceScale]}),a=Math.min(...i.map(e=>e[0])),o=0,s=0;for(let[e,t]of i){let n=Math.exp((a-e)/r.blend);o+=n,s+=n*t}return[a-r.blend*Math.log(o),s/o]},xe=(e,t,n,r,i)=>a=>{let{m:o}=t,s=i().depthAt(a[0],a[1]),c=a[2]-s+.1;if(c>=0||!Number.isFinite(s))return c;let l=a[0]-t.t[0],u=a[1]-t.t[1],d=-t.t[2],f=-n*a[0]/620,p=-n*a[1]/620,m=[r.width/2,r.height/2,r.depth/2],h=[0,1,2].map(e=>(o[e]*l+o[3+e]*u+o[6+e]*d)/m[e]),g=[0,1,2].map(e=>(o[e]*f+o[3+e]*p+o[6+e])/m[e]),_=s;for(let t=0;t<8;t++){let[t,n]=$(e,h.map((e,t)=>e+_*g[t]),g);if(n<=1e-10)return c;let r=t/n;if(!Number.isFinite(r)||Math.abs(r)>Math.max(...m)/2)return c;if(_-=r,Math.abs(r)<1e-6)return a[2]-_+.1}return c},Se={radial:p,sculpt:ae,union:m};export{Se as sculpt};
|
|
1
|
+
import{t as e}from"./rolldown-runtime-DK3Fl9T5.js";import{A as t,F as n,I as r,L as i,M as a,P as o,a as s,x as c}from"./activate-CCUqRQyO.js";var l=()=>{let e=new Float64Array,t=new Float64Array,n=new Float64Array,r=new Float64Array,i=new Float64Array;return(a,o,s,c,l,u,d,f)=>{let p=a.length/3,m=f.length;e.length!==p&&(e=new Float64Array(p),t=new Float64Array(p),n=new Float64Array(p)),r.length!==m*4+1&&(r=Float64Array.from({length:m*4+1},(e,t)=>Math.cos((t-m*2)/m*Math.PI*2)),i=Float64Array.from({length:m*4+1},(e,t)=>Math.sin((t-m*2)/m*Math.PI*2)));let h=Math.PI*2,g=h/m;f.fill(0);for(let r=0;r<p;r+=1){let i=a[r*3],o=a[r*3+1],s=a[r*3+2],f=c[0]*i+c[1]*o+c[2]*s+l[0],p=c[3]*i+c[4]*o+c[5]*s+l[1],m=620-(c[6]*i+c[7]*o+c[8]*s+l[2])*u,h=620/(Math.abs(m)<1e-4?1e-4:m);e[r]=f*h-d[0],t[r]=p*h-d[1],n[r]=Math.atan2(t[r],e[r])}let _=(a,o)=>{let s=e[a],c=t[a],l=e[o]-s,u=t[o]-c,d=n[a],p=n[o];p-d>Math.PI&&(p-=h),d-p>Math.PI&&(p+=h),d>p&&([d,p]=[p,d]);let _=s*u-c*l;for(let e=Math.ceil(d/g),t=Math.floor(p/g);e<=t;e+=1){let t=r[e+m*2]*u-i[e+m*2]*l;if(Math.abs(t)<1e-9)continue;let n=_/t,a=(e%m+m)%m;n>f[a]&&(f[a]=n)}};for(let e=0;e<o;e+=1)for(let t=0;t<s;t+=1){let n=e*s+t;t+1<s&&_(n,n+1),e+1<o&&_(n,n+s)}return f}},u=new WeakMap,d=e=>{if(e.type!==`blob`)return;let n=i(e),o=n?.radialDepthPower;if(!n||!o)return;let s=a(e)+`|`+o,c=u.get(n.radii);c||u.set(n.radii,c=new Map);let l=c.get(s);if(l)return l;let d=new Float32Array(13107);for(let i=0;i<17;i+=1){let a=-Math.PI/2+i/16*Math.PI,s=i===0||i===16?0:Math.max(0,Math.cos(a))**(2/o);for(let o=0;o<=256;o+=1){let c=o/256*Math.PI*2,l=r(n.radii,c)*s,u=l*Math.cos(c)*e.width/2,f=l*Math.sin(c)*e.height/2,p=i===8?0:Math.sign(a)*t(e,u,f).point[2],m=(i*257+o)*3;d[m]=u,d[m+1]=f,d[m+2]=p}}let f={positions:d,rows:17,columns:257};return c.size>=8&&c.delete(c.keys().next().value),c.set(s,f),f},f;function p(e,t,n,r,i){let a=d(e);return a?((f??=l())(a.positions,a.rows,a.columns,t.m,t.t,n,r,i),!0):!1}var m=e({ellipsoidUnionOutline:()=>v}),h=Math.PI/4,g=4/3*Math.tan(h/4),_=.01,v=(e,t,n,r)=>{if(e.type!==`blob`||e.outlineRounding!==0)return;let a=i(e).lobes;if(!a||!a.parts.length||a.crown||a.parts.some(e=>(e.power??2)!==2||(e.horizontalPower??e.power??2)!==2))return;let o=[e.width/2,e.height/2,e.depth/2],l=a.blend*Math.log(a.parts.length),{m:u,t:d}=t,f=n/620,p=[],m=0,v=0;for(let e of a.parts){let t=(e.rotation??0)*Math.PI/180,n=(e.tilt??0)*Math.PI/180,r=Math.cos(t),i=Math.sin(t),a=Math.cos(n),c=Math.sin(n),h=[r,-i*a,i*c,i,r*a,-r*c,0,c,a],g=Array.from({length:9},(t,n)=>{let r=Math.floor(n/3),i=n%3;return(u[r*3]*o[0]*h[i]+u[r*3+1]*o[1]*h[i+3]+u[r*3+2]*o[2]*h[i+6])*e.radii[i]}),y=[0,1,2].map(t=>d[t]+u[t*3]*o[0]*e.center[0]+u[t*3+1]*o[1]*e.center[1]+u[t*3+2]*o[2]*e.center[2]),b=(e,t)=>g[e*3]*g[t*3]+g[e*3+1]*g[t*3+1]+g[e*3+2]*g[t*3+2],x=[b(0,0),b(0,1),b(0,2),b(1,1),b(1,2),b(2,2)],S=s(y,x,f);if(!S)return;let C=1+l/Math.min(...e.radii),w=s(y,x.map(e=>e*C*C),f);if(!w)return;let T=Math.hypot(w.x-S.x,w.y-S.y)+Math.hypot(w.ux-S.ux,w.uy-S.uy,w.vy-S.vy),E=43e-7*Math.hypot(S.ux,S.uy,S.vy);if(m=Math.max(m,T+E),m>_)return;let D=S.ux**2,O=S.ux*S.uy,k=S.uy**2+S.vy**2;v=Math.max(v,Math.hypot(S.x,S.y)+Math.sqrt((D+k+Math.hypot(D-k,2*O))/2)+E),p.push(S)}let y=10**r,b=e=>Math.round(e*y)/y,x=``;for(let e of p){let t=t=>[e.x+e.ux*Math.cos(t),e.y+e.uy*Math.cos(t)+e.vy*Math.sin(t)],n=t=>[-e.ux*Math.sin(t),-e.uy*Math.sin(t)+e.vy*Math.cos(t)],r=t(0);x+=`M${b(r[0])} ${b(r[1])}`;for(let e=0;e<8;e++){let r=e*h,i=r+h,a=t(r),o=t(i),s=n(r),c=n(i);x+=`C${b(a[0]+g*s[0])} ${b(a[1]+g*s[1])} ${b(o[0]-g*c[0])} ${b(o[1]-g*c[1])} ${b(o[0])} ${b(o[1])}`}x+=`Z`}let S=Math.SQRT2*.5*10**-r;return{path:c(x),reach:v+S,enclosureMargin:m,maximumEnclosureMargin:m+S}},y=.65,b=e=>{if(e>=-.35)return[0,0];if(e<=-1)return[1,0];let t=(-e-.35)/y;return[t*t*t*(t*(t*6-15)+10),-30*t*t*(1-t)*(1-t)/y]},x=({dip:e,lift:t,width:n},r,i)=>{let a=r/n,o=i/n,s=Math.exp(-(a**4)),c=Math.exp(-(o**4)),l=e+t;return[l*(s+c-s*c)-t,-l*(1-c)*4*a**3*s/n,-l*(1-s)*4*o**3*c/n]},S=(e,t)=>t[1]>=-.35||!(e.dip||e.lift)?t:[t[0],t[1]+b(t[1])[0]*x(e,t[0],t[2])[0],t[2]],C=(e,t,n,r)=>{if(n>=-.35||!(e.dip||e.lift))return n;let i=x(e,t,r)[0],a=n-e.dip,o=n+e.lift,s=n;for(let e=0;e<48;e++){let[e,t]=b(s),r=s+i*e-n;if(Math.abs(r)<=1e-14)return s;r<=0?a=s:o=s;let c=s-r/(1+i*t);s=c>a&&c<o?c:(a+o)/2}return(a+o)/2},w=(e,t)=>{let n=C(e,...t),[r,i]=b(n),[a,o,s]=x(e,t[0],t[2]),c=1/(1+a*i);return{point:[t[0],n,t[2]],row:[-r*o*c,c,-r*s*c]}},T=(e,t,n)=>{if(t[1]>=-.35||!(e.dip||e.lift))return n;let[r,i]=b(t[1]),[a,o,s]=x(e,t[0],t[2]),c=n[1]/(1+a*i),l=n[0]-c*r*o,u=n[2]-c*r*s,d=Math.hypot(l,c,u)||1;return[l/d,c/d,u/d]},E=({dip:e,lift:t,width:n})=>Math.hypot(1,(e+t)*4*(3/4)**.75*Math.exp(-.75)/n/(1-e*1.875/y)),D=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`,O=46,k=126,A=new Int8Array(128).fill(-1);for(let e=0;e<64;e+=1)A[D.charCodeAt(e)]=e;var j=e=>((e+32768&65535)>>>0)-32768,ee=(e,t,n)=>{let r=n%t,i=r?e[n-1]:0,a=n>=t?e[n-t]:0,o=r&&n>=t?e[n-t-1]:0;return i+a-o},te=(e,t)=>{let n=new Int16Array(t*t),r=t=>{let n=e.charCodeAt(t);return n<128?A[n]:-1},i=0,a=0;for(;a<e.length;){let o=e.charCodeAt(a);if(o===k){let e=r(a+1),o=r(a+2);if(e<0||o<0)return;let s=i+e*64+o;if(s>n.length)return;for(;i<s;i+=1)n[i]=j(ee(n,t,i));a+=3;continue}let s;if(o===O){let e=r(a+1),t=r(a+2),n=r(a+3);if(e<0||t<0||n<0)return;s=e<<12|t<<6|n,a+=4}else{if(s=r(a),s<0)return;a+=1}if(i>=n.length)return;let c=s&1?-(s+1>>1):s>>1;n[i]=j(ee(n,t,i)+c),i+=1}return i===n.length?n:void 0},M=new WeakMap;function ne(e){let t=e.geometry?.relief;t&&M.delete(t)}var re=e=>{let t=M.get(e),n=e.bits??8;if(!t||t.bits!==n||t.scale!==e.scale||t.packedFront!==e.front||t.packedBack!==e.back){let r=t=>{if(e.coding===`delta`){let n=te(t,e.size)??new Int16Array(e.size**2);return Float32Array.from(n,t=>t/32767*e.scale)}let r=Uint8Array.from(atob(t),e=>e.charCodeAt(0));if(n===16){let t=new DataView(r.buffer);return Float32Array.from({length:r.length/2},(n,r)=>t.getInt16(r*2,!0)/32767*e.scale)}return Float32Array.from(r,t=>(t>127?t-256:t)/127*e.scale)};t={bits:n,scale:e.scale,packedFront:e.front,packedBack:e.back,front:r(e.front),back:r(e.back)},M.set(e,t)}return t},N=(e,t,n,r)=>{let{size:i,range:a}=t,o=(n+a)/(2*a)*(i-1),s=(r+a)/(2*a)*(i-1),c=Math.floor(o),l=Math.floor(s),u=(t,n)=>e[Math.min(i-1,Math.max(0,n))*i+Math.min(i-1,Math.max(0,t))],d=(e,t,n,r,i)=>t+.5*i*(n-e+i*(2*e-5*t+4*n-r+i*(3*(t-n)+r-e))),f=e=>d(u(c-1,e),u(c,e),u(c+1,e),u(c+2,e),o-c);return d(f(l-1),f(l),f(l+1),f(l+2),s-l)};function ie(e,t,r,i,a){let o=re(t),s=N(o.front,t,i,a)*e.depth,c=N(o.back,t,i,a)*e.depth,l=(s+c)/2,u=Math.min(1,Math.max(0,n(r,i,a)/(t.rim??.05))),d=u*u*(3-2*u);return{front:l+(s-l)*d,back:l+(c-l)*d}}var ae=e({lobeFieldAt:()=>oe,lobeFrontRead:()=>be,lobeFrontSample:()=>ye,lobePoint:()=>se,lobeRayFieldAt:()=>$,lobeSample:()=>ce,lobeVisibility:()=>xe,releaseRelief:()=>ne,reliefFaces:()=>ie}),P=new WeakMap,F=1e-8,I=1e-11,L=e=>{let t=P.get(e);if(t)return t;let n=e.blend,r=n*Math.log(e.parts.length),i=e.parts.map(({center:e,radii:t,power:n,horizontalPower:r,rotation:i,tilt:a})=>({center:e,inverseX:1/t[0],inverseY:1/t[1],inverseZ:1/t[2],distanceScale:Math.min(...t),power:n??2,horizontalPower:r??n??2,cosine:Math.cos((i??0)*Math.PI/180),sine:Math.sin((i??0)*Math.PI/180),tiltCosine:Math.cos((a??0)*Math.PI/180),tiltSine:Math.sin((a??0)*Math.PI/180)})),a={parts:i,blend:n,radialBound:Math.max(...e.parts.map(({center:e,radii:t})=>{let n=Math.hypot(...t);return Math.hypot(...e)+n+r*n/Math.min(...t)}))+1e-6,fields:new Float64Array(i.length),hint:0};return P.set(e,a),a},R=(e,t,n)=>n===2?Math.hypot(e,t):(Math.abs(e)**n+Math.abs(t)**n)**(1/n),z=(e,t,n,r,i)=>r===i?r===2?Math.hypot(e,t,n):(Math.abs(e)**r+Math.abs(t)**r+Math.abs(n)**r)**(1/r):R(R(e,n,i),t,r),B=(e,t,n,r,i,a,o)=>{let s=z(e,t,n,r,i);if(s<=1e-15)return[0,0];if(r===i)return[s,r===2?(t*a+n*o)/s:Math.sign(t)*(Math.abs(t)/s)**(r-1)*a+Math.sign(n)*(Math.abs(n)/s)**(r-1)*o];let c=R(e,n,i);return[s,Math.sign(t)*(Math.abs(t)/s)**(r-1)*a+(c>0?(c/s)**(r-1)*Math.sign(n)*(Math.abs(n)/c)**(i-1)*o:0)]},V=(e,t,n,r,i)=>{let a=R(e,n,i),o=R(a,t,r);if(o<=1e-15)return[0,0,0];let s=(a/o)**(r-1);return[a>0?s*Math.sign(e)*(Math.abs(e)/a)**(i-1):0,Math.sign(t)*(Math.abs(t)/o)**(r-1),a>0?s*Math.sign(n)*(Math.abs(n)/a)**(i-1):0]},H=(e,t,n,r)=>{let i=t-e.center[0],a=n-e.center[1],o=r-e.center[2],s=-e.sine*i+e.cosine*a;return(z((e.cosine*i+e.sine*a)*e.inverseX,(e.tiltCosine*s+e.tiltSine*o)*e.inverseY,(-e.tiltSine*s+e.tiltCosine*o)*e.inverseZ,e.power,e.horizontalPower)-1)*e.distanceScale},U=({parts:e,blend:t,fields:n},r,i,a)=>{let o=1/0;for(let t=0;t<e.length;t+=1){let s=H(e[t],r,i,a);n[t]=s,o=Math.min(o,s)}let s=0;for(let r=0;r<e.length;r+=1)s+=Math.exp((o-n[r])/t);return o-t*Math.log(s)},oe=(e,t)=>{let n=e.crown&&t[1]<-.35?[t[0],C(e.crown,...t),t[2]]:t;return U(L(e),...n)},W=({parts:e,blend:t},n,r,i)=>{let a=1/0;for(let t of e)a=Math.min(a,H(t,n,r,i));let o=0,s=0,c=0;for(let l of e){let e=n-l.center[0],u=r-l.center[1],d=i-l.center[2],f=-l.sine*e+l.cosine*u,p=(l.cosine*e+l.sine*u)*l.inverseX,m=(l.tiltCosine*f+l.tiltSine*d)*l.inverseY,h=(-l.tiltSine*f+l.tiltCosine*d)*l.inverseZ,g=z(p,m,h,l.power,l.horizontalPower);if(g<=1e-12)continue;let _=Math.exp((a-(g-1)*l.distanceScale)/t)*l.distanceScale,v=V(p,m,h,l.power,l.horizontalPower),y=v[0]*l.inverseX*_,b=v[1]*l.inverseY*_,x=v[2]*l.inverseZ*_,S=l.tiltCosine*b-l.tiltSine*x;o+=l.cosine*y-l.sine*S,s+=l.sine*y+l.cosine*S,c+=l.tiltSine*b+l.tiltCosine*x}let l=Math.hypot(o,s,c)||1;return[o/l,s/l,c/l]},G=(e,t,n)=>{let r=L(e),i=Math.cos(n)*Math.sin(t),a=Math.sin(n),o=Math.cos(n)*Math.cos(t),s=0;for(let e of r.parts){if(e.power!==2||e.horizontalPower!==2)continue;let t=-e.sine*i+e.cosine*a,n=(e.cosine*i+e.sine*a)*e.inverseX,r=(e.tiltCosine*t+e.tiltSine*o)*e.inverseY,c=(-e.tiltSine*t+e.tiltCosine*o)*e.inverseZ,l=-e.sine*e.center[0]+e.cosine*e.center[1],u=(e.cosine*e.center[0]+e.sine*e.center[1])*e.inverseX,d=(e.tiltCosine*l+e.tiltSine*e.center[2])*e.inverseY,f=(-e.tiltSine*l+e.tiltCosine*e.center[2])*e.inverseZ,p=n*n+r*r+c*c,m=n*u+r*d+c*f,h=u*u+d*d+f*f-1;s=Math.max(s,(m+Math.sqrt(Math.max(0,m*m-p*h)))/p)}let c=r.radialBound,l=e=>U(r,i*e,a*e,o*e),u=-1/0,d=1/0,f=s,p=c,m,h,g=r.hint;if(g>s&&g<c){let e=l(g),t=g*.01;if(e<=0)for(f=g,m=e;;){let e=f+t;if(!(e<c)){h=l(c);break}let n=l(e);if(n>0){p=e,h=n;break}f=e,m=n,t*=4}else for(p=g,h=e;;){let e=p-t;if(!(e>s)){m=l(s);break}let n=l(e);if(n<=0){f=e,m=n;break}p=e,h=n,t*=4}}else m=l(f),h=l(p);if(m<=0&&h>=I){d=p,m<=-1e-11&&(u=f);let e=f,t=m,n=p,r=h,i=0,a=m>-1e-11?f:NaN;for(let o=0;o<16&&a!==a;o++){let o=f-m*(p-f)/(h-m);if(o>f&&o<p||(o=(f+p)/2),!(o>f&&o<p))break;let s=l(o);if(e=n,t=r,n=o,r=s,s<=0?(f=o,m=s,s<=-1e-11&&(u=o),i>0&&(h*=.5),i=1):(p=o,h=s,s>=I&&(d=o),i<0&&(m*=.5),i=-1),s>-1e-11&&s<I){a=o;break}}let o=(r-t)/(n-e);if(a===a&&o>0){for(let e=4*I/o,t=0;t<4;e*=8,t++){let t=a-e;if(!(t>u))break;if(l(t)<=-1e-11){u=t;break}}for(let e=4*I/o,t=0;t<4;e*=8,t++){let t=a+e;if(!(t<d))break;if(l(t)>=I){d=t;break}}}}for(let e=0;e<30;e++){let e=(s+c)/2;e<=u||e<d&&l(e)<=0?s=e:c=e}let _=(s+c)/2;return r.hint=_,[i*_,a*_,o*_]},se=(e,t,n)=>{let r=G(e,t,n);return e.crown?S(e.crown,r):r},ce=(e,t,n)=>{let r=G(e,t,n),i=W(L(e),...r);return e.crown?{point:S(e.crown,r),normal:T(e.crown,r,i)}:{point:r,normal:i}},K=(e,t,n)=>{let r=t;for(let i=0;i<16&&t-e>1e-10;i++){let[i,a]=n(r);i<=0?e=r:t=r;let o=a>1e-15?i/a:1/0;if(i>0&&Number.isFinite(o)){let i=r-2*o-1e-10;i>e&&i<t&&(n(i)[0]<=0?e=i:t=i)}let s=r-o;r=s>e&&s<t?s:(e+t)/2}for(let r=0;r<40&&t-e>1e-10;r++){let r=(e+t)/2;n(r)[0]<=0?e=r:t=r}return[e,t]},le=(e,t,n,r)=>{let i=e.parts.map(e=>{let i=t-e.center[0],a=n-e.center[1],o=r-e.center[2],s=-e.sine*i+e.cosine*a,c=B((e.cosine*i+e.sine*a)*e.inverseX,(e.tiltCosine*s+e.tiltSine*o)*e.inverseY,(-e.tiltSine*s+e.tiltCosine*o)*e.inverseZ,e.power,e.horizontalPower,e.tiltSine*e.inverseY,e.tiltCosine*e.inverseZ);return[(c[0]-1)*e.distanceScale,c[1]*e.distanceScale]}),a=Math.min(...i.map(e=>e[0])),o=0,s=0;return i.forEach(([t,n])=>{let r=Math.exp((a-t)/e.blend);o+=r,s+=r*n}),[a-e.blend*Math.log(o),s/o]},ue=(e,t,n,r)=>{let i=t-e.center[0],a=n-e.center[1],o=(e.cosine*i+e.sine*a)*e.inverseX,s=-e.sine*i+e.cosine*a,c=e.tiltSine*e.inverseY,l=e.tiltCosine*s*e.inverseY,u=e.tiltCosine*e.inverseZ,d=-e.tiltSine*s*e.inverseZ,f;if(Math.abs(c)<1e-15)f=-d/u;else if(Math.abs(u)<1e-15)f=-l/c;else if(e.power===e.horizontalPower){let t=-Math.sign(u/c)*Math.abs(u/c)**(1/(e.power-1));f=(t*d-l)/(c-t*u)}else{let t=Math.min(-l/c,-d/u),n=Math.max(-l/c,-d/u);for(let r=0;r<44;r++){let r=(t+n)/2,i=V(o,c*r+l,u*r+d,e.power,e.horizontalPower);i[1]*c+i[2]*u<=0?t=r:n=r}f=(t+n)/2}let p=e.power/(e.power-1),m=(Math.abs(e.tiltSine/e.inverseY)**p+Math.abs(e.tiltCosine/e.inverseZ)**p)**(1/p),h=e.center[2]-m*r,g=t=>z(o,c*t+l,u*t+d,e.power,e.horizontalPower),_=t=>{if(Math.abs(e.tiltSine)<1e-12){let n=t**e.power-Math.abs(l)**e.power;if(n<0)return;let r=n**(e.horizontalPower/e.power)-Math.abs(o)**e.horizontalPower;return r<0?void 0:e.center[2]+r**(1/e.horizontalPower)/e.inverseZ}if(e.power===2&&e.horizontalPower===2){let n=c*c+u*u,r=c*l+u*d,i=o*o+l*l+d*d-t*t,a=r*r-n*i;return a<0?void 0:e.center[2]+(-r+Math.sqrt(a))/n}let n=t;if(g(f)>n)return;let r=K(f,m*t,t=>{let r=B(o,c*t+l,u*t+d,e.power,e.horizontalPower,c,u);return[r[0]-n,r[1]]});return e.center[2]+r[t===1?0:1]};return{minimum:e.center[2]+f,front:_(r),rawFront:_(1),lower:h}},de=(e,t,n,r)=>{let i=e.parts.map(e=>H(e,t,n,r)),a=e.parts.map(e=>{let t=e.power/(e.power-1);return e.distanceScale*(Math.abs(e.tiltSine*e.inverseY)**t+Math.abs(e.tiltCosine*e.inverseZ)**t)**(1/t)}),o=0,s=Math.min(...i.map((e,t)=>e/a[t]));for(let t=0;t<20;t++){let t=(o+s)/2,n=1/0;for(let e=0;e<i.length;e++)n=Math.min(n,i[e]-a[e]*t);let r=0;for(let o=0;o<i.length;o++)r+=Math.exp((n-i[o]+a[o]*t)/e.blend);n-e.blend*Math.log(r)>0?o=t:s=t}return o},fe=(e,t,n)=>{let r=L(e),i=r.blend*Math.log(r.parts.length),a=-1/0,o=1/0,s=-1/0,c=-1/0;for(let e of r.parts){let r=ue(e,t,n,1+i/e.distanceScale);c=Math.max(c,r.minimum),r.front!==void 0&&(a=Math.max(a,r.front),o=Math.min(o,r.lower),r.rawFront!==void 0&&(s=Math.max(s,r.rawFront)))}if(a===-1/0)return{point:[t,n,0],normal:[0,0,1]};if(s=Math.max(s,c),s<=a&&U(r,t,n,s)<=0){let e=K(s,a,e=>le(r,t,n,e)),i=(e[0]+e[1])/2;return{point:[t,n,i],normal:W(r,t,n,i)}}let l=a+F,u=l;for(let e=0;e<2048&&l>=o-F;e++){let i=U(r,t,n,l);if(Math.abs(i)<=F)return{point:[t,n,l],normal:W(r,t,n,l)};if(i<0){let e=l;for(let i=0;i<40;i++){let i=(e+u)/2;U(r,t,n,i)<=0?e=i:u=i}let i=(e+u)/2;return{point:[t,n,i],normal:W(r,t,n,i)}}u=l,l-=e<32?i:de(r,t,n,l)}return{point:[t,n,0],normal:[0,0,1]}},pe=(e,t,n,r,i)=>{let a=n.z<=0&&r.z>=0?Math.min(i,n.sourceY,r.sourceY):Math.min(n.sourceY,r.sourceY),o=Math.max(n.sourceY,r.sourceY),s=(a+o)/2,c=(o-a)/2,l=(n.z+r.z)/2,u=(r.z-n.z)/2,d=e.parts.map(e=>{let n=t-e.center[0],r=s-e.center[1],i=l-e.center[2],a=-e.sine*n+e.cosine*r;return(z(Math.max(0,Math.abs(e.cosine*n+e.sine*r)-Math.abs(e.sine)*c)*e.inverseX,Math.max(0,Math.abs(e.tiltCosine*a+e.tiltSine*i)-Math.abs(e.tiltCosine*e.cosine)*c-Math.abs(e.tiltSine)*u)*e.inverseY,Math.max(0,Math.abs(-e.tiltSine*a+e.tiltCosine*i)-Math.abs(e.tiltSine*e.cosine)*c-Math.abs(e.tiltCosine)*u)*e.inverseZ,e.power,e.horizontalPower)-1)*e.distanceScale}),f=Math.min(...d);return f-e.blend*Math.log(d.reduce((t,n)=>t+Math.exp((f-n)/e.blend),0))},me=(e,t,n)=>{let r=e.crown,i=L(e),a=i.radialBound,o=e=>{let a=C(r,t,n,e);return{z:e,sourceY:a,value:U(i,t,a,e)}},s=C(r,t,n,0),c=E(r),l=[{lo:o(-a),hi:o(a),depth:0}];for(;l.length;){let{lo:e,hi:a,depth:u}=l.pop(),d=a.z-e.z;if(e.value>0&&a.value>0&&e.value+a.value>c*d||pe(i,t,e,a,s)>0)continue;let f=(e.z+a.z)/2;if(u>=48||d<=1e-9/c||f===e.z||f===a.z){let o=Math.abs(e.value)<Math.abs(a.value)?e:a;if(o.value>F)continue;let s=[t,o.sourceY,o.z];return{point:[t,n,o.z],normal:T(r,s,W(i,...s))}}let p=o(f);l.push({lo:e,hi:p,depth:u+1},{lo:p,hi:a,depth:u+1})}return{point:[t,n,0],normal:[0,0,1]}},q=new WeakMap,he=2048,J=(e,t,n)=>e.crown&&n<-.35?me(e,t,n):fe(e,t,n),Y=1.25,X=64,ge=Math.round(Y*2*X)+1,_e=[.02,.05,.05,.05],Z=new WeakMap,Q=new Float64Array(4),ve=(e,t,n)=>{let r=Z.get(e);if(r||(r=o(ge,4,(t,n,r)=>{let i=J(e,t/X-Y,n/X-Y);return r[0]=i.point[2],r[1]=i.normal[0],r[2]=i.normal[1],r[3]=i.normal[2],i.point[2]!==0||i.normal[2]!==1},_e),Z.set(e,r)),!r.read((t+Y)*X,(n+Y)*X,Q))return;let[i,a,s,c]=Q,l=Math.hypot(a,s,c);if(l>1e-6)return{point:[t,n,i],normal:[a/l,s/l,c/l]}},ye=(e,t,n)=>{let r=q.get(e);r||q.set(e,r=new Map);let i=`${t}|${n}`,a=r.get(i);if(a)return r.delete(i),r.set(i,a),a;let o=J(e,t,n);return r.set(i,o),r.size>he&&r.delete(r.keys().next().value),o},be=(e,t,n)=>ve(e,t,n)??ye(e,t,n),$=(e,t,n)=>{let r=L(e);if(e.crown&&t[1]<-.35){let r=w(e.crown,t);n=[n[0],r.row[0]*n[0]+r.row[1]*n[1]+r.row[2]*n[2],n[2]],t=r.point}let i=r.parts.map(e=>{let r=t[0]-e.center[0],i=t[1]-e.center[1],a=t[2]-e.center[2],o=-e.sine*r+e.cosine*i,s=(e.cosine*r+e.sine*i)*e.inverseX,c=(e.tiltCosine*o+e.tiltSine*a)*e.inverseY,l=(-e.tiltSine*o+e.tiltCosine*a)*e.inverseZ,u=-e.sine*n[0]+e.cosine*n[1],d=(e.cosine*n[0]+e.sine*n[1])*e.inverseX,f=(e.tiltCosine*u+e.tiltSine*n[2])*e.inverseY,p=(-e.tiltSine*u+e.tiltCosine*n[2])*e.inverseZ,m=V(s,c,l,e.power,e.horizontalPower);return[(z(s,c,l,e.power,e.horizontalPower)-1)*e.distanceScale,(m[0]*d+m[1]*f+m[2]*p)*e.distanceScale]}),a=Math.min(...i.map(e=>e[0])),o=0,s=0;for(let[e,t]of i){let n=Math.exp((a-e)/r.blend);o+=n,s+=n*t}return[a-r.blend*Math.log(o),s/o]},xe=(e,t,n,r,i)=>a=>{let{m:o}=t,s=i().depthAt(a[0],a[1]),c=a[2]-s+.1;if(c>=0||!Number.isFinite(s))return c;let l=a[0]-t.t[0],u=a[1]-t.t[1],d=-t.t[2],f=-n*a[0]/620,p=-n*a[1]/620,m=[r.width/2,r.height/2,r.depth/2],h=[0,1,2].map(e=>(o[e]*l+o[3+e]*u+o[6+e]*d)/m[e]),g=[0,1,2].map(e=>(o[e]*f+o[3+e]*p+o[6+e])/m[e]),_=s;for(let t=0;t<8;t++){let[t,n]=$(e,h.map((e,t)=>e+_*g[t]),g);if(n<=1e-10)return c;let r=t/n;if(!Number.isFinite(r)||Math.abs(r)>Math.max(...m)/2)return c;if(_-=r,Math.abs(r)<1e-6)return a[2]-_+.1}return c},Se={radial:p,sculpt:ae,union:m};export{Se as sculpt};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime-DK3Fl9T5.js";import{N as t}from"./activate-
|
|
1
|
+
import{t as e}from"./rolldown-runtime-DK3Fl9T5.js";import{N as t}from"./activate-CCUqRQyO.js";var n=e({createSocketVisibility:()=>f,filledSocketLayout:()=>o,socketBowlClearance:()=>d,socketFrontAt:()=>a}),r=e=>Math.max(0,Math.min(1,e)),i=e=>e*e*e*(10+e*(-15+6*e)),a=(e,t,n,a)=>{for(let[o,s]of e.centers){let c=Math.hypot(t-o,n-s);if(c>=e.padRadius)continue;if(c<=e.apertureRadius){let t=c/e.apertureRadius;return e.plane-e.depth*Math.max(0,1-t*t)**3}let l=i(r((c-e.rimOuterRadius)/(e.padRadius-e.rimOuterRadius)));return e.plane*(1-l)+a*l}return a},o=(e,t,n,r)=>{if(e.bend)return;let i=t.apertureRadius*n,a=Math.min(e.width,e.height)/2,o=r===void 0?t.centers:t.centers[r]?[t.centers[r]]:[];for(let[t,r]of o){let o=t*n,s=r*n,c=o-e.centerX,l=s-e.centerY,u=c*e.cos+l*e.sin,d=-c*e.sin+l*e.cos,f=e.lidSlope??0,p=-e.height/2+(e.lid??0)*e.height,m=e.height/2-(e.lowerLid??0)*e.height,h=Math.hypot(c,l)+i<=a+1e-6,g=e.ellipse===1&&((Math.abs(u)+i)/(e.width/2))**2+((Math.abs(d)+i)/(e.height/2))**2<=1+1e-10;if(!(!h&&!g)&&!(d-f*u-i*Math.hypot(1,f)<p-1e-6||d+i>m+1e-6))return{...e,centerX:o,centerY:s,width:i*2,height:i*2,cos:1,sin:0,ellipse:1,...e.lid||e.lidSlope||e.lowerLid?{lid:0,lidSlope:0,lowerLid:0}:{}}}},s=(e,t)=>{let n=0;for(let r=e.length-1;r>=0;r--)n=n*t+e[r];return n},c=e=>e.slice(1).map((e,t)=>e*(t+1)),l=(e,t=0,n=1)=>{let r=[...e];for(;r.length>1&&Math.abs(r.at(-1))<1e-13;)r.pop();if(r.length<2)return[];if(r.length===2){let e=-r[0]/r[1];return e>t&&e<n?[e]:[]}let i=l(c(r),t,n),a=[t,...i,n],o=i.filter(e=>Math.abs(s(r,e))<1e-11);for(let e=0;e<a.length-1;e++){let t=a[e],n=a[e+1],i=s(r,t),c=s(r,n);if(!(i*c>=0)){for(let e=0;e<36;e++){let e=(t+n)/2,a=s(r,e);i*a<=0?n=e:(t=e,i=a)}o.push((t+n)/2)}}return o.sort((e,t)=>e-t)},u=(e,t)=>{let n=Array.from({length:e.length+t.length-1},()=>0);return e.forEach((e,r)=>t.forEach((t,i)=>{n[r+i]+=e*t})),n},d=(e,t,n,r)=>{let i=e.apertureRadius,a=t[0]-r[0],o=t[1]-r[1];if(i-Math.hypot(a,o)<-1e-7||n[2]<=1e-9)return{clearance:-1,distance:0};let d=Math.max(0,(e.plane-t[2])/n[2]),f=n[0]*d,p=n[1]*d,m=i-Math.hypot(a+f,o+p);if(m<-1e-8)return{clearance:m,distance:d};if(d<1e-8)return{clearance:m+1e-7,distance:d};let h=1/(i*i),g=[1-(a*a+o*o)*h,-2*(a*f+o*p)*h,-(f*f+p*p)*h],_=u(u(g,g),g).map(t=>t*e.depth);_[0]+=t[2]-e.plane,_[1]+=e.plane-t[2];let v=_.slice(1),y=[0,1,...l(c(v))],b=Math.min(...y.map(e=>s(v,e)));return{clearance:Math.min(m,b)+1e-7,distance:d}},f=(e,n,r,i,a,o,s)=>{let{m:c,t:l}=i,u=(e,t,n)=>[c[0]*e+c[3]*t+c[6]*n,c[1]*e+c[4]*t+c[7]*n,c[2]*e+c[5]*t+c[8]*n],f=(Math.sqrt(5)-1)/2,p=1e-4,m=e.centers.map(([e,t])=>[e*n,t*n]),h=(e.rimOuterRadius*n)**2,g=e.plane*n,_=m.map((t,r)=>m.every((i,a)=>r===a||Math.hypot(t[0]-i[0],t[1]-i[1])>(e.rimOuterRadius+e.padRadius)*n+1e-7));return t(t=>{let i=1-t[2]*a/620,c=u(t[0]*i-l[0],t[1]*i-l[1],t[2]-l[2]);if(s!==void 0){let t=m[s];if(!t)return-1;let r=e.apertureRadius*n-Math.hypot(c[0]-t[0],c[1]-t[1]);if(r<=0)return r}let v=u(-a*t[0]/620,-a*t[1]/620,1);if(v[2]<=1e-10)return-1;for(let t of e.centers){let r=c[0]/n-t[0],i=c[1]/n-t[1],a=Math.hypot(r,i)/e.apertureRadius,o=e.plane-e.depth*Math.max(0,1-a*a)**3;if(a<=1&&Math.abs(c[2]/n-o)<1e-8){let r=d(e,[c[0]/n,c[1]/n,c[2]/n],v,t);if(r.clearance<=0)return r.clearance*n}}let y=v[0]/v[2],b=v[1]/v[2],x=r-c[2];if(x<=0)return 1;if(c[2]>=g-1e-9){let e=c[0]+y*x,t=c[1]+b*x;for(let n=0;n<m.length;n++){if(!_[n])continue;let[r,i]=m[n];if((c[0]-r)**2+(c[1]-i)**2<h-1e-6&&(e-r)**2+(t-i)**2<h-1e-6)return p}}let S=e=>{let t=c[2]+e,n=c[0]+y*e,r=c[1]+b*e;if(t>=g-1e-9)for(let e=0;e<m.length;e++){if(!_[e])continue;let i=m[e];if((n-i[0])**2+(r-i[1])**2<=h)return Math.min(0,g-t)}let i=o(n,r);return i?Math.min(i.front-t,t-i.back):-1/0},C=Array.from({length:13},(e,t)=>x*t/12),w=y*y+b*b;if(w>1e-20)for(let[t,r]of e.centers)for(let i of[e.apertureRadius,e.rimOuterRadius,e.padRadius]){let e=c[0]-t*n,a=c[1]-r*n,o=i*n,s=2*(e*y+a*b),l=e*e+a*a-o*o,u=s*s-4*w*l;if(u<0)continue;let d=Math.sqrt(u);for(let e of[(-s-d)/(2*w),(-s+d)/(2*w)])e>0&&e<x&&C.push(e)}C.sort((e,t)=>e-t);for(let e=C.length-1;e>0;e--)Math.abs(C[e]-C[e-1])<1e-10&&C.splice(e,1);let T=new Float64Array(C.length),E=-1/0;for(let e=0;e<C.length;e++){let t=T[e]=S(C[e]);if(E=Math.max(E,t),t>p)return p-t}for(let e=1;e<C.length-1;e++){if(!Number.isFinite(T[e])||T[e]<T[e-1]||T[e]<T[e+1]||T[e]===T[e-1]&&T[e]===T[e+1])continue;let t=C[e-1],n=C[e+1],r=n-f*(n-t),i=t+f*(n-t),a=S(r),o=S(i);if(a>p||o>p)return p-Math.max(a,o);for(let e=0;e<14;e++)if(a>o?(n=i,i=r,o=a,r=n-f*(n-t),a=S(r)):(t=r,r=i,a=o,i=t+f*(n-t),o=S(i)),a>p||o>p)return p-Math.max(a,o);E=Math.max(E,a,o)}return Number.isFinite(E)?p-E:1})},p={sockets:n};export{p as sockets};
|
package/dist/still.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e,t}from"./runtime/reader-
|
|
1
|
+
import{i as e,t}from"./runtime/reader-JcTNbEkh.js";import{t as n}from"./runtime/poster-Cs69ty3T.js";var r=e=>String(e).replaceAll(`&`,`&`).replaceAll(`"`,`"`).replaceAll(`<`,`<`).replaceAll(`>`,`>`);function i(i,{id:a,label:o}){if(!a)throw new e(`MIEN_ID`,`/id`,`Pass an id unique on the page, such as { id: "assistant" }.`);return n(t(i),a,o,(e,t,n)=>`<`+e+Object.entries(t).map(([e,t])=>` `+e+`="`+r(t)+`"`).join(``)+`>`+(n?.join(``)??``)+`</`+e+`>`)}export{i as renderStill};
|
|
@@ -85,7 +85,13 @@ type Layer = {
|
|
|
85
85
|
color: ColorRole;
|
|
86
86
|
};
|
|
87
87
|
export type PosterV1 = {
|
|
88
|
+
/** Half the side of the square the avatar is drawn in. */
|
|
88
89
|
half: number;
|
|
90
|
+
/** Where that square is centred, in face units; the origin when left out. */
|
|
91
|
+
center?: {
|
|
92
|
+
x: number;
|
|
93
|
+
y: number;
|
|
94
|
+
};
|
|
89
95
|
body: string;
|
|
90
96
|
eyes: readonly string[];
|
|
91
97
|
back?: readonly Layer[];
|
|
@@ -8,13 +8,24 @@ export type Painting = {
|
|
|
8
8
|
transform: string;
|
|
9
9
|
/** Half the side of the square that frames the character's faces. */
|
|
10
10
|
half: number;
|
|
11
|
+
/** Where that square is centred; the origin when left out. */
|
|
12
|
+
center?: {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
};
|
|
11
16
|
/** The face is set into the head, so the eyes are drawn on its plate. */
|
|
12
17
|
windowed: boolean;
|
|
13
18
|
};
|
|
14
19
|
export type PlayerPainter = {
|
|
15
20
|
paint(painting: Painting): void;
|
|
16
|
-
/**
|
|
17
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Sizes the view box to a square of this half side around `center` (the origin when left out), with the mask that
|
|
23
|
+
* cuts eye holes over all of it.
|
|
24
|
+
*/
|
|
25
|
+
fit(half: number, center?: {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
}): void;
|
|
18
29
|
setLabel(label: string | undefined): void;
|
|
19
30
|
/** Empties the `<svg>`. */
|
|
20
31
|
destroy(): void;
|
package/dist/vue.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./runtime/reader-
|
|
1
|
+
import"./runtime/reader-JcTNbEkh.js";import"./runtime/runs-BIIveHSZ.js";import"./runtime/poster-Cs69ty3T.js";import"./still.js";import{a as e}from"./runtime/mount-CzvXPeZF.js";import{t}from"./runtime/adapter-onjjGk6m.js";import{n,t as r}from"./runtime/handle-p7slzKMG.js";import{defineComponent as i,h as a,onBeforeUnmount as o,onMounted as s,shallowRef as c,toRaw as l,useId as u,watchEffect as d}from"vue";var f=i((i,{expose:f,emit:p})=>{let m=c(),h=u(),g=n(l(i.avatar),h,i.label),_;return f(r(()=>_)),s(()=>{let e=_=t(m.value);d(()=>{e.update({avatar:l(i.avatar),state:i.state,label:i.label,motion:i.motion,onSequenceEnd:e=>{i.onSequenceEnd?.(e),p(`sequenceend`,e)},onError:i.onError})})}),o(()=>{_?.destroy(),_=null}),()=>a(`span`,{ref:m,innerHTML:g,style:e(i.size)})},{name:`Mien`,props:[`avatar`,`state`,`label`,`motion`,`size`,`onSequenceEnd`,`onError`],emits:[`sequenceend`]});export{f as Mien};
|
package/dist/worker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./runtime/reader-
|
|
1
|
+
import"./runtime/reader-JcTNbEkh.js";import"./runtime/runs-BIIveHSZ.js";import"./runtime/poster-Cs69ty3T.js";import{i as e,n as t}from"./runtime/mount-CzvXPeZF.js";var n=()=>new Worker(new URL("./worker-script.js",import.meta.url),{type:"module"});function r(r,i,a={}){return a.size!==void 0&&e(r,a.size),t(r,i,a,void 0,async(...e)=>(await Promise.all([import("./runtime/rolldown-runtime-DK3Fl9T5.js"),import("./runtime/playback-BeRsJu6S.js"),import("./runtime/playerPaint-DaCo2Clx.js"),import("./runtime/render-f6uGZFDG.js")]).then(m=>m[3])).workerTransport(a.workerFactory??n)(...e))}export{r as mount};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./activate-C80BK8CF.js";import{t}from"./playerPaint-DylZy_iE.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);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 +0,0 @@
|
|
|
1
|
-
var e=(e,t)=>typeof t==`number`||!/[~/]/.test(t)?e+`/`+t:e+`/`+t.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`),t=(e,t)=>typeof e==`boolean`?void 0:t,n=(e,t)=>e===null?void 0:t,r=(...e)=>(t,n)=>e.includes(t)?void 0:n,i=(e,t,n,r)=>(i,a)=>typeof i==`number`&&(r?i>e:i>=e)&&i<=t&&(!n||Number.isInteger(i))?void 0:a,a=(e,t,n)=>{let r=n?new RegExp(n,`u`):null;return(n,i)=>{if(typeof n!=`string`)return i;let a=/[\uD800-\uDBFF]/.test(n)?Array.from(n).length:n.length;return a>=e&&a<=t&&(!r||r.test(n))?void 0:i}},o=(t,n,r)=>(i,a)=>{if(!Array.isArray(i)||i.length<n||i.length>r)return a;for(let n=0;n<i.length;n++){let r=t(i[n],e(a,n));if(r!==void 0)return r}},s=e=>typeof e==`object`&&!!e&&!Array.isArray(e),c=(t,n,r)=>(i,a)=>{if(!s(i)||Object.keys(i).length<r)return a;for(let t of n)if(!Object.hasOwn(i,t))return e(a,t);for(let[n,r]of Object.entries(i)){let i=e(a,n);if(!Object.hasOwn(t,n))return i;let o=t[n](r,i);if(o!==void 0)return o}},l=(t,n,r,i)=>(a,o)=>{if(!s(a)||Object.keys(a).length>r)return o;for(let t of i)if(!Object.hasOwn(a,t))return e(o,t);for(let[r,i]of Object.entries(a)){let a=e(o,r),s=n(r,a)??t(i,a);if(s!==void 0)return s}},u=(...e)=>(t,n)=>{let r=n;for(let i of e){let e=i(t,n);if(e===void 0)return;e.length>r.length&&(r=e)}return r},d=1048576,f=class extends Error{code;path;fix;source;constructor(e,t,n,r){super(`${e} at ${t||`/`}${r?` in `+r:``}.${n?` `+n:``}`),this.code=e,this.path=t,this.fix=n,this.source=r,this.name=`MienFormatError`}};function p(e,t,n){let r=n.find(e=>e.startsWith(t.slice(0,Math.max(3,t.length-2))));throw new f(`MIEN_`+e.slice(0,-1).toUpperCase()+`_UNKNOWN`,`/`+e+`/`+t,(r?`Did you mean "${r}"? `:``)+`Names: `+n.join(`, `)+`.`)}function m(e,t,n=`MIEN_INVALID`){throw new f(n,e,t)}var h=/^[\x20\x21\x23-\x5b\x5d-\x7e]*$/;function g(t){let n=d,r=new TextEncoder;function i(e,t){n-=e,n<0&&m(t,`Use a file of at most 1 MiB.`,`MIEN_SIZE`)}function a(e,t){e.length>n&&m(t,`Use a file of at most 1 MiB.`,`MIEN_SIZE`),i(h.test(e)?e.length+2:r.encode(JSON.stringify(e)).length,t)}function o(t,n,r){if(r>32&&m(n,`Reduce nesting to 32 levels.`,`MIEN_DEPTH`),typeof t==`string`)return a(t,n),t;if(t===null||typeof t==`boolean`||typeof t==`number`&&Number.isFinite(t))return i(t===null?4:String(t).length,n),t;(!t||typeof t!=`object`)&&m(n,`Supply a JSON value.`);let s=Array.isArray(t);!s&&Object.prototype.toString.call(t)!==`[object Object]`&&m(n,`Supply a plain object.`),!s&&Object.getPrototypeOf(t)!==null&&Object.getPrototypeOf(Object.getPrototypeOf(t))!==null&&m(n,`Supply own JSON properties.`),i(2,n);let c=Object.keys(t);s&&c.length!==t.length&&m(n,`Supply a dense JSON array.`);let l=s?[]:Object.create(null);for(let u=0;u<c.length;u++){let d=c[u];s&&d!==String(u)&&m(n,`Supply only array elements.`),s||(a(d,n),i(1,n)),u&&i(1,n);let f=e(n,s?u:d),p=Object.getOwnPropertyDescriptor(t,d);`value`in p||m(f,`Supply data instead of a getter.`),l[d]=o(p.value,f,r+1)}return Object.freeze(l)}return o(t,``,0)}var _=i(.001,1e4,!1,!1),v=i(0,2,!1,!1),y=i(-1e4,1e4,!1,!1),b=o(y,3,3),x=o(y,2,2),S=c({sockets:c({centers:o(o(i(-1,1,!1,!1),2,2),1,4),apertureRadius:i(0,1,!1,!0),rimOuterRadius:i(0,1,!1,!0),padRadius:i(0,1,!1,!0),plane:i(-1,1,!1,!1),depth:i(0,1,!1,!0),power:r(3)},[`centers`,`apertureRadius`,`rimOuterRadius`,`padRadius`,`plane`,`depth`,`power`],0),eyePlane:i(-1,1,!1,!1),radii:o(i(0,1/0,!1,!0),3,8192),sections:c({profile:o(b,2,512),frontPower:i(2,8,!1,!1),frontTaper:i(0,1,!1,!1)},[`profile`,`frontPower`],0),hull:o(b,4,8192),revolve:r(`x`,`y`),window:o(x,3,8192),plate:o(x,3,8192),flush:t,bend:c({x:i(-1/0,1/0,!1,!1),y:i(-1/0,1/0,!1,!1),from:i(-1/0,1/0,!1,!1)},[`x`],0),relief:c({size:i(2,256,!0,!1),range:i(0,1e4,!1,!0),scale:i(0,1e4,!1,!0),rim:i(0,1,!1,!0),front:a(0,174764,void 0),back:a(0,174764,void 0),bits:r(16),coding:r(`delta`)},[`size`,`range`,`scale`,`front`,`back`],0),lobes:c({blend:i(0,.25,!1,!0),parts:o(c({center:b,radii:o(i(.001,4,!1,!1),3,3),power:i(2,6,!1,!1),horizontalPower:i(2,6,!1,!1),rotation:i(-180,180,!1,!1),tilt:i(-180,180,!1,!1)},[`center`,`radii`],0),1,16),crown:c({dip:i(0,.25,!1,!1),lift:i(0,.25,!1,!1),width:i(.05,1,!1,!1)},[`dip`,`lift`,`width`],0)},[`blend`,`parts`],0),radialDepthPower:i(2,32,!1,!1)},[`radii`],0),C=c({type:r(`sphere`,`mickey`,`cursor`,`cube`,`capsule`,`cylinder`,`cone`,`diamond`,`blob`),width:_,height:_,depth:i(0,1e4,!1,!1),roundness:v,outlineRounding:i(0,1,!1,!1),morphRoundness:v,tipRoundness:v,baseRoundness:v,geometry:S,rotationCenter:o(y,3,3),geometryIndex:i(0,16,!0,!1)},[`type`,`width`,`height`,`depth`,`roundness`],0),ee=o(y,3,3),w=o(i(-360,360,!1,!1),3,3),T=a(0,64,`^(?!constructor$|prototype$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*$`),E=c({primary:C,nodes:o(c({surface:C,position:ee,rotation:w,fixed:t,rooted:t,follow:c({lag:i(0,1e3,!1,!1),swing:i(-10,10,!1,!1),loose:t,hinge:o(i(-500,500,!1,!1),2,2),range:o(i(-180,180,!1,!1),2,2)},[`lag`],0),color:r(`eyes`,`accent`,`secondary`,`tertiary`,`mark`),paintOn:T,id:T},[`surface`,`position`,`rotation`,`id`],0),0,16)},[`primary`,`nodes`],0),D=a(0,1/0,`^#[0-9a-fA-F]{6}$`),O=c({body:D,eyes:D,eyeHoles:t,accent:D,secondary:D,tertiary:D,mark:D,linkAccentToBody:t},[`body`,`eyes`],0),k=c({widthLeft:y,widthRight:y,heightLeft:y,heightRight:y,spacing:y,positionXLeft:y,positionXRight:y,positionYLeft:y,positionYRight:y,leftAngle:y,rightAngle:y,shape:r(`pill`,`ellipse`,`circle`),glyphY:y},[`widthLeft`,`widthRight`,`heightLeft`,`heightRight`,`spacing`,`positionXLeft`,`positionXRight`,`positionYLeft`,`positionYRight`,`leftAngle`,`rightAngle`],0),A=a(1,262144,`^[Mm][MmZzLlHhVvCcSsQqTtAaEe0-9+., \\t\\r\\n-]*$`),j=c({half:i(1,1e6,!1,!1),body:A,eyes:o(A,0,4),back:o(c({path:A,color:r(`body`,`eyes`,`accent`,`secondary`,`tertiary`,`mark`)},[`path`,`color`],0),0,128),front:o(c({path:A,color:r(`body`,`eyes`,`accent`,`secondary`,`tertiary`,`mark`)},[`path`,`color`],0),0,128),face:c({opening:A,plate:A},[`opening`,`plate`],0),placement:c({x:y,y,scaleX:y,scaleY:y},[`x`,`y`,`scaleX`,`scaleY`],0),colors:O},[`half`,`body`,`eyes`],0),M=u(c({mode:r(`off`)},[`mode`],0),c({mode:r(`interval`),everyMs:i(1,12e4,!0,!1),initialDelayMs:i(0,12e4,!0,!1),durationMs:i(1,12e4,!0,!1)},[`mode`,`everyMs`],0),c({mode:r(`random`),minMs:i(1,12e4,!0,!1),maxMs:i(1,12e4,!0,!1),initialDelayMs:i(0,12e4,!0,!1),durationMs:i(1,12e4,!0,!1)},[`mode`,`minMs`,`maxMs`],0),c({mode:r(`times`),atMs:o(i(0,2147483647,!0,!1),0,4096),durationMs:i(1,12e4,!0,!1)},[`mode`,`atMs`],0),c({mode:r(`once`),delayMs:i(0,12e4,!0,!1),durationMs:i(1,12e4,!0,!1)},[`mode`,`delayMs`],0)),N=c({turn:y,x:y,y,scale:i(.01,100,!1,!1)},[],1),P=c({x:y,y,width:y,height:y,angle:y,bend:i(-1,1,!1,!1)},[`x`,`y`,`width`,`height`,`angle`],0),F=c({headX:y,headY:y,headZ:y,widthLeft:y,widthRight:y,heightLeft:y,heightRight:y,spacing:y,positionXLeft:y,positionXRight:y,positionYLeft:y,positionYRight:y,leftAngle:y,rightAngle:y,perspective:y,eyeMotion:u(r(`none`,`microSaccades`,`shake`),n),bodyMotion:u(r(`none`,`slowDrift`,`shake`),n),bodyColor:u(D,n),eyeColor:u(D,n),pieces:u(l(N,T,16,[]),n),marks:u(o(P,4,4),n),glyphApart:u(r(!0),n),headGestureAmount:u(i(0,1,!1,!1),n),headGesture:u(r(`nod`,`headShake`,`wiggle`,`twirl`,`lookAround`,`hop`,`tilt`,`dance`,`bow`,`shakeOff`,`eagerNod`,`peek`,`shrug`,`recoil`,`doubleTake`,`eyeRoll`,`dizzy`,`sneeze`,`yawn`,`shiver`,`tickTock`,`bashful`,`roll`,`flip`,`spin`,`bounce`,`breathe`,`shrink`,`stomp`,`sway`,`earFlap`),n),markMotion:u(r(`drift`,`scan`,`wave`,`talk`,`bounce`,`type`,`orbit`,`pulse`,`breathe`,`sway`,`shake`,`hop`,`beat`,`twinkle`,`rise`,`fall`),n),lidLeft:u(i(0,1,!1,!1),n),lowerLidLeft:u(i(0,1,!1,!1),n),lidTiltLeft:u(i(-80,80,!1,!1),n),lidRight:u(i(0,1,!1,!1),n),lowerLidRight:u(i(0,1,!1,!1),n),lidTiltRight:u(i(-80,80,!1,!1),n)},[],0),I=u(c({expression:T,gaze:c({x:i(-1,1,!1,!1),y:i(-1,1,!1,!1)},[`x`,`y`],0),blink:M,entryMs:i(80,1e3,!0,!1)},[`expression`],0),c({sequence:T,gaze:c({x:i(-1,1,!1,!1),y:i(-1,1,!1,!1)},[`x`,`y`],0),blink:M,entryMs:i(80,1e3,!0,!1)},[`sequence`],0)),L=u(c({expression:T,holdMs:i(0,6e4,!0,!1),transitionMs:i(0,5e3,!0,!1),transition:r(`spring`,`bounce`,`smooth`,`snappy`,`glide`,`linear`,`cut`),blink:r(!1)},[`expression`,`holdMs`],0),c({state:T,holdMs:i(0,6e4,!0,!1),transitionMs:i(0,5e3,!0,!1),transition:r(`spring`,`bounce`,`smooth`,`snappy`,`glide`,`linear`,`cut`),blink:r(!1)},[`state`,`holdMs`],0)),R=c({mode:r(`once`,`loop`,`pingPong`),steps:o(L,1,1024),blink:M},[`mode`,`steps`],0),z=c({format:r(`mien`),version:r(1),name:a(0,256,void 0),avatar:c({body:E,colors:O,eyes:k},[`body`,`colors`],0),geometry:o(S,1,17),initial:T,poster:j,blink:M,expressions:l(F,T,512,[`neutral`]),states:l(I,T,256,[]),sequences:l(R,T,256,[])},[`format`,`version`,`avatar`,`initial`,`poster`,`expressions`,`states`,`sequences`],0),B=M;function V(e){if(e&&!(Number.isFinite(e.x)&&Number.isFinite(e.y)))throw new f(`MIEN_GAZE`,`/look`,`Use finite numbers from -1 to 1 for x and y. Received x=${e.x}, y=${e.y}.`)}function H(e,t){let n=t.slice(7);if(e?.mode===`times`){if(n===`atMs`)return`Use an atMs array with up to 4096 times.`;if(n.startsWith(`atMs/`))return`Use whole numbers from 0 to 2,147,483,647 ms in atMs.`}if(n.endsWith(`Ms`)){let r=n===`delayMs`||n===`initialDelayMs`?0:1;if(B({...e,[n]:r},`/blink`)!==t)return`Set ${n} to a whole number from ${r} to 120,000 ms.`}return`Use a valid blink policy, such as { "mode": "off" }.`}function U(e){try{return JSON.stringify(e,(e,t)=>typeof t==`number`&&!Number.isFinite(t)||typeof t==`bigint`?String(t):t)}catch{return`an unserializable value`}}function W(e){if(e===null)return;let t=B(e,`/blink`),n;if(t)n=H(e,t);else if(e.mode===`random`&&e.minMs>e.maxMs)n=`Set minMs to a value less than or equal to maxMs.`;else if(e.mode===`times`&&e.atMs.some((e,t,n)=>t>0&&n[t-1]>e))n=`Put the times in atMs in ascending order.`;else return;throw new f(`MIEN_BLINK`,t??`/blink`,`${n} Received ${U(e)}.`)}var G=Object.freeze({headX:0,headY:0,headZ:0,widthLeft:20,widthRight:20,heightLeft:50,heightRight:50,spacing:35,positionXLeft:0,positionXRight:0,positionYLeft:-7,positionYRight:-7,leftAngle:0,rightAngle:0,perspective:1}),K=Object.freeze({mode:`random`,minMs:2600,maxMs:4700,durationMs:160});function q(e,t){let n={...e};for(let[e,r]of Object.entries(t))r===null?delete n[e]:Object.assign(n,{[e]:r});return Object.freeze(n)}function J(e){return e.mode===`off`?e:Object.freeze({durationMs:160,...e})}var Y={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7,z:0};function X(e){let t=/[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y,n=/[ \n\r\t]*/y,r=0;function i(){n.lastIndex=r,n.exec(e),r=n.lastIndex}let a=``;if(!/^[Mm]/.test(e))return!1;for(;r<e.length;){let n=e[r].toLowerCase(),o=Object.hasOwn(Y,n);if(o)a=n,r++,i();else if(!a)return!1;if(a===`z`){a=``;continue}for(let n=0;n<Y[a];n++){if((!o||n>0)&&e[r]===`,`&&(r++,i()),a===`a`&&(n===3||n===4)){if(e[r]!==`0`&&e[r]!==`1`)return!1;r++}else{t.lastIndex=r;let i=t.exec(e);if(!i)return!1;let o=Number(i[0]);if(Math.abs(o)>1e6||a===`a`&&n<2&&o<0)return!1;r=t.lastIndex}i()}}return!0}function Z(e,t){e?.mode===`random`&&e.minMs>e.maxMs&&m(t+`/maxMs`,`Use a maximum at least as large as the minimum.`),e?.mode===`times`&&e.atMs.some((e,t,n)=>t>0&&n[t-1]>e)&&m(t+`/atMs`,`Sort cues in time order.`)}function Q(e,t){if(!t){let t=e.replace(/[\t\n\f\r ]/g,``);return t.length%4==0&&(t=t.replace(/={1,2}$/,``)),t.length%4==1||/[^A-Za-z0-9+/]/.test(t)?-1:Math.floor(t.length*3/4)}let n=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`,r=0;for(let t=0;t<e.length;){let i=e[t++];if(i===`~`){if(t+2>e.length)return-1;let i=n.indexOf(e[t++]),a=n.indexOf(e[t++]);if(i<0||a<0)return-1;r+=64*i+a}else{if(i===`.`){if(t+3>e.length||!/^[A-P][\w-]{2}$/.test(e.slice(t,t+3)))return-1;t+=3}else if(!n.includes(i))return-1;r++}}return r}function te(e){let t=0,n=0,r=e.avatar.body.nodes,i=new Map(r.map(e=>[e.id,e]));i.size!==r.length&&m(`/avatar/body/nodes`,`Give each node a unique ID.`);let a=new Set;function o(r,i){let o=r.geometry??(r.geometryIndex===void 0?void 0:e.geometry?.[r.geometryIndex]);if(r.geometryIndex!==void 0&&(!o||r.geometry)&&m(i+`/geometryIndex`,`Use one valid geometry index or inline geometry.`),r.type===`blob`!=!!o&&m(i,`Give each blob its own geometry.`),!o)return;let s=r.geometryIndex===void 0?i+`/geometry`:`/geometry/`+r.geometryIndex,{relief:c,sockets:l,sections:u,lobes:d}=o;if(n+=o.radii.length+(o.hull?.length??0)+(o.plate?.length??0)+(o.window?.length??0)+(u?.profile.length??0),t+=2*(c?.size??0)**2,(t>2097152||n>65536)&&m(i,`Reduce total decoded geometry.`,`MIEN_SIZE`),!a.has(o)){if(a.add(o),(o.radialDepthPower&&(d||u||o.hull||o.plate||o.revolve||c||l)||d&&(u||o.hull||o.plate||c||o.revolve))&&m(s,`Use compatible solid constructions.`),l){let{apertureRadius:e,rimOuterRadius:t,padRadius:n,centers:r}=l;(d||o.hull||o.plate||o.revolve||o.window||o.eyePlane!==void 0||!(e<t&&t<n)||r.some(([e,t],i)=>r.slice(i+1).some(([r,i])=>Math.hypot(e-r,t-i)<=2*n)))&&m(s+`/sockets`,`Use separate socket pads with increasing rim radii on a compatible solid.`)}for(let[e,t]of(d?.parts??[]).entries()){let[n,r,i]=t.center,a=(t.rotation??0)*Math.PI/180,o=(t.tilt??0)*Math.PI/180,c=-Math.sin(a)*n+Math.cos(a)*r,[l,u,d]=t.radii,f=t.power??2,p=t.horizontalPower??f;(Math.abs((Math.cos(a)*n+Math.sin(a)*r)/l)**p+Math.abs((-Math.sin(o)*c+Math.cos(o)*i)/d)**p)**(f/p)+Math.abs((Math.cos(o)*c+Math.sin(o)*i)/u)**f>=1&&m(s+`/lobes/parts/`+e,`Each lobe must contain the origin.`)}if(u?.profile.some(([e,t,n],r,i)=>t<n||r>0&&e<=i[r-1][0])&&m(s+`/sections/profile`,`Order the sections and place fronts ahead of backs.`),c){c.coding&&c.bits!==16&&m(s+`/relief/bits`,`Use 16-bit delta grids.`);for(let e of[`front`,`back`])Q(c[e],!!c.coding)!==c.size**2*(c.bits===16&&!c.coding?2:1)&&m(s+`/relief/`+e,`Encode one signed sample per grid cell.`)}}}o(e.avatar.body.primary,`/avatar/body/primary`),r.forEach((e,t)=>{let n=`/avatar/body/nodes/`+t;if(o(e.surface,n+`/surface`),(e.surface.type===`mickey`||e.surface.type===`cursor`)&&m(n+`/surface/type`,`Use a supported node surface.`),e.paintOn){let t=i.get(e.paintOn);(!t||t===e||t.paintOn||t.color===`eyes`||t.color===`mark`)&&m(n+`/paintOn`,`Select an existing solid host.`)}let r=e.follow?.range;r&&r[0]>r[1]&&m(n+`/follow/range`,`Order the hinge limits.`)}),e.geometry?.forEach((e,t)=>{a.has(e)||m(`/geometry/`+t,`Remove unused geometry.`)});for(let[t,n]of Object.entries(e.expressions))for(let e of Object.keys(n.pieces??{}))i.has(e)||m(`/expressions/`+t+`/pieces/`+e,`Select an existing node.`)}function ne(e){te(e);let t=e.poster;function n(e,t){X(e)||m(`/poster/`+t,`Supply valid bounded SVG path commands.`)}n(t.body,`body`),t.eyes.forEach((e,t)=>n(e,`eyes/`+t));for(let e of[`back`,`front`])t[e]?.forEach((t,r)=>n(t.path,e+`/`+r+`/path`));t.face&&(n(t.face.plate,`face/plate`),n(t.face.opening,`face/opening`)),re(e)}function re(e){let t=new Map,n=new Set;function r(i,a,o,s){if(Object.hasOwn(e[i],a)||m(o,`Choose an existing key in `+i+`.`,`MIEN_REFERENCE`),i===`expressions`)return 0;let c=i+`/`+a,l=`/`+c;n.has(c)&&m(o,`Remove recursive state or sequence references.`,`MIEN_CYCLE`),s>8&&m(o,`Limit playback references to eight levels.`,`MIEN_DEPTH`);let u=t.get(c);if(u!==void 0)return u;n.add(c);let d=1;if(i===`states`){let t=e.states[a];Z(t.blink,l+`/blink`),d+=t.sequence===void 0?r(`expressions`,t.expression,l+`/expression`,s+1):r(`sequences`,t.sequence,l+`/sequence`,s+1)}else{let t=e.sequences[a];Z(t.blink,l+`/blink`);let n=0;t.steps.forEach((e,t)=>{let i=l+`/steps/`+t;n+=e.holdMs+(e.transitionMs??180);let a=e.state===void 0?r(`expressions`,e.expression,i+`/expression`,s+1):r(`states`,e.state,i+`/state`,s+1);d=Math.max(d,a+1)}),!n&&t.mode!==`once`&&m(l+`/steps`,`Give a repeating sequence a positive duration.`)}return d>8&&m(o,`Limit playback references to eight levels.`,`MIEN_DEPTH`),n.delete(c),t.set(c,d),d}Object.values(e.sequences).reduce((e,t)=>e+t.steps.length,0)>4096&&m(`/sequences`,`Use at most 4096 steps.`,`MIEN_SIZE`),Z(e.blink,`/blink`),r(`states`,e.initial,`/initial`,1);for(let t of[`states`,`sequences`])for(let n of Object.keys(e[t]))r(t,n,`/`+t+`/`+n,1)}var $=new WeakMap;function ie(e){if(e&&typeof e==`object`){let t=$.get(e);if(t)return t}let t=g(e),n=t;n?.format!==`mien`&&m(`/format`,n?.format===`morph-avatar`?`Re-export the avatar as .mien.json in Mien Studio.`:`Supply a Mien avatar file.`,`MIEN_FORMAT`),n.version!==1&&m(`/version`,Number.isInteger(n.version)&&n.version>1?`This file was made for a newer mien-avatar. Update the package: npm i mien-avatar@latest.`:`Re-export the avatar from Mien Studio.`,`MIEN_VERSION`);let r=z(t,``);r!==void 0&&m(r,`Use the field type and range in the v1 schema.`);let i=t;ne(i);let a=q(G,i.expressions.neutral);function o(e,t){let n=Object.create(null);for(let[r,i]of Object.entries(e))n[r]=t(i,r);return Object.freeze(n)}let s=e=>e.blink?{blink:J(e.blink)}:{},c=Object.freeze({file:i,blink:J(i.blink??K),states:o(i.states,e=>Object.freeze({entryMs:180,...e,...s(e)})),sequences:o(i.sequences,e=>Object.freeze({...e,...s(e),steps:Object.freeze(e.steps.map(e=>Object.freeze({transitionMs:180,transition:`smooth`,...e})))})),expressions:o(i.expressions,(e,t)=>t===`neutral`?a:q(a,e)),stateNames:Object.freeze(Object.keys(i.states)),hasState:e=>Object.hasOwn(i.states,e)});return $.set(c,c),$.set(i,c),$.set(e,c),c}export{d as a,f as i,W as n,m as o,V as r,p as s,ie as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,t}from"./playback-DxnlsAAY.js";import{t as n}from"./playerPaint-DylZy_iE.js";var r=new WeakMap;function i(e,t,n){let i=r.get(e);i||r.set(e,i=new WeakMap);let o=i.get(t);return o||(o=a(t(),()=>i.delete(t)),i.set(t,o)),o.add(n)}function a(e,t){let n=new Map,r=new Map,i=!1,a=!1,o=!1,s=0,c=0,l;function u(){o=!0,clearTimeout(l),t(),e.onmessage=e.onerror=e.onmessageerror=null,e.terminate(),r.clear()}function d(e){o||(u(),console.warn(`mien-avatar: the drawing worker stopped, so avatars draw on the page instead.`,e),n.forEach(e=>e.failed()))}function f(t){try{e.postMessage(t)}catch{d()}}function p(){if(a=!1,o||i||!r.size)return;let e=[...r.values()].filter(e=>n.get(e.id)?.accept(e));r.clear(),e.length&&(i=!0,l=setTimeout(()=>d(`No answer within 10 s.`),1e4),f({kind:`project`,turn:++s,requests:e}))}return e.onerror=e.onmessageerror=d,e.onmessage=({data:e})=>{if(!(o||!i||e.turn!==s)){if(clearTimeout(l),e.kind!==`projected`||e.error){d(e.error);return}i=!1;for(let t of e.frames)n.get(t.id)?.receive(t);for(let t of e.failed??[])n.get(t)?.failed();p()}},{add(e){let t=++c;return n.set(t,e),{id:t,send(e){r.set(t,e),a||(a=!0,queueMicrotask(p))},remove(){!n.delete(t)||o||(r.delete(t),n.size?f({kind:`release`,id:t}):u())}}}}}var o=r=>async(a,o,s,c)=>{if(!c.visible())return;let l=o.cloneNode(!1),u=n(l,s);u.fit(a.file.poster.half);let d=!1,f=!1,p=!1,m=!1,h=!0,g,_,v=!1,y,b,x=0;function S(){f||p||(p=!0,b=void 0,g?.remove(),c.visible()&&C())}function C(){v||(v=!0,import(`./activate-C80BK8CF.js`).then(e=>e.t).then(e=>e.prepareGeometry(a,!0)).then(e=>{f||(_=e.createProjector(),c.invalidate())}).catch(c.report))}function w(e){u.paint(e),d||=(o.style.overflow=`visible`,o.replaceChildren(...l.childNodes),!0)}try{g=i(o.ownerDocument,r,{failed:S,accept(e){return c.visible()&&e.generation===c.generation()&&e.revision===c.revision()?(D=!1,!0):(b=void 0,h=!0,c.invalidate(),!1)},receive(e){let t=b;!t||f||p||Object.entries(t.stamp).some(([t,n])=>e[t]!==n)||(b=void 0,c.visible()&&c.generation()===e.generation&&c.revision()===e.revision&&c.runId()===e.runId?(w(e.painting),t.commit(),y=t):h=!0,c.invalidate())}})}catch{S()}let T=-1,E=0,D=!0;return{draw(n,r,i,o){if(m||=i,p){if(!_)return C(),1/0;y&&=(_(y.sample,y.pixels),void 0);let e=n.sampleDisplay(r,m||!d);return w(_(e.frame,d?o:192,e.geometryStable)),m=!1,e.nextTime}if(b)return 1/0;if(!h&&!m&&T===c.revision()&&o===E&&r<x)return x;let s=n.sampleDisplay(r,m||!d,!0);m=!1,h=!1,E=o,T=c.revision(),x=s.nextTime;let l={id:g.id,runId:c.runId(),generation:c.generation(),revision:T,at:r,commandTime:c.commandTime()},u=structuredClone(s.frame);return o=d?o:192,b={sample:u,pixels:o,stamp:l,commit:n.pendingDisplay()},g.send({...l,sample:u,pixels:o,...D&&{avatar:t(a),grid:e(a)}}),1/0},dispose(){f=!0,g?.remove(),_?.dispose(),b=y=void 0}}};export{o as workerTransport};
|