@idosgames/characters 0.1.2 → 0.1.3

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.
@@ -1,2 +1,2 @@
1
- 'use strict';var F=require('phaser');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var F__default=/*#__PURE__*/_interopDefault(F);var X=Math.PI/180,ht=1e-5;function Mt(l,t){return l.type==="ik"?new E(l,t):new dt(l,t)}var pt=l=>l>180?l-360:l<=-180?l+360:l,E=class{constructor(t,e){this.data=t;this.bones=t.bones.map(n=>e.bones[n.index]),this.target=e.bones[t.target.index],this.mix=t.mix,this.bendDirection=t.bendDirection;}data;mix;bendDirection;bones;target;setupPose(){this.mix=this.data.mix,this.bendDirection=this.data.bendDirection;}sort(t){t.sortBone(this.target);let e=this.bones[0];t.sortBone(e),t.pushConstraint(this),e.sorted=false,t.sortReset(e.children);}update(t){if(this.mix===0)return;let e=this.target.applied;this.bones.length===1?St(t,this.bones[0].applied,e.worldX,e.worldY,this.mix):Ot(t,this.bones[0].applied,this.bones[1].applied,e.worldX,e.worldY,this.bendDirection,this.mix);}};function St(l,t,e,n,o){let s=t.bone.parent;if(!s)return;t.modifyLocal(l);let i=s.applied,r=i.a,c=i.b,a=i.c,h=i.d,p=-t.shearX-t.rotation,u=r*h-c*a,m=e-i.worldX,f=n-i.worldY,y=(m*h-f*c)/u-t.x,d=(f*r-m*a)/u-t.y;p+=Math.atan2(d,y)/X,t.scaleX<0&&(p+=180),t.rotation+=pt(p)*o;}function Ot(l,t,e,n,o,s,i){t.modifyLocal(l),e.modifyLocal(l);let r=t.x,c=t.y,a=t.scaleX,h=t.scaleY,p=e.scaleX,u,m,f;a<0?(a=-a,u=180,f=-1):(u=0,f=1),h<0&&(h=-h,f=-f),p<0?(p=-p,m=180):m=0;let y=Math.abs(a-h)<=ht,d,g;y?(d=t.a*e.x+t.b*e.y+t.worldX,g=t.c*e.x+t.d*e.y+t.worldY):(e.y=0,d=t.a*e.x+t.worldX,g=t.c*e.x+t.worldY);let v=t.bone.parent;if(!v)return;let b=v.applied,B=b.a,$=b.b,it=b.c,at=b.d,A=B*at-$*it,H=d-b.worldX,W=g-b.worldY;A=Math.abs(A)<=ht?0:1/A;let gt=(H*at-W*$)*A-r,yt=(W*B-H*it)*A-c,x=Math.sqrt(gt*gt+yt*yt),T=e.bone.data.length*p;if(x<ht){St(l,t,n,o,i),e.rotation=0;return}H=n-b.worldX,W=o-b.worldY;let N=(H*at-W*$)*A-r,q=(W*B-H*it)*A-c,K=N*N+q*q,P=0,M=0;if(y){T*=a;let k=(K-x*x-T*T)/(2*x*T);k<-1?(k=-1,M=Math.PI*s):k>1?(k=1,M=0):M=Math.acos(k)*s;let L=x+T*k,D=T*Math.sin(M);P=Math.atan2(q*L-N*D,N*L+q*D);}else {let k=a*T,L=h*T,D=k*k,G=L*L,lt=Math.atan2(q,N),w=G*x*x+D*K-D*G,z=-2*G*x,xt=G-D,kt=z*z-4*xt*w,vt=false;if(kt>=0){let S=Math.sqrt(kt);z<0&&(S=-S),S=-(z+S)*.5;let I=S/xt,O=w/S,Y=Math.abs(I)<Math.abs(O)?I:O,V=K-Y*Y;if(V>=0){let C=Math.sqrt(V)*s;P=lt-Math.atan2(C,Y),M=Math.atan2(C/h,(Y-x)/a),vt=true;}}if(!vt){let S=Math.PI,I=x-k,O=I*I,Y=0,V=0,C=x+k,ct=C*C,wt=0;if(w=-k*x/(D-G),w>=-1&&w<=1){w=Math.acos(w);let _=k*Math.cos(w)+x,Z=L*Math.sin(w),Q=_*_+Z*Z;Q<O&&(S=w,O=Q,I=_,Y=Z),Q>ct&&(V=w,ct=Q,C=_,wt=Z);}K<=(O+ct)*.5?(P=lt-Math.atan2(Y*s,I),M=S*s):(P=lt-Math.atan2(wt*s,C),M=V*s);}}let bt=Math.atan2(e.y,e.x)*f;P=pt((P-bt)/X+u-t.rotation),M=pt(((M+bt)/X-e.shearX)*f+m-e.rotation),t.rotation+=P*i,e.rotation+=M*i;}var dt=class{constructor(t,e){this.data=t;this.source=e.bones[t.source.index],this.bones=t.bones.map(n=>e.bones[n.index]),this.mix={...t.mix};}data;mix;source;bones;setupPose(){Object.assign(this.mix,this.data.mix);}sort(t){t.sortBone(this.source);for(let e of this.bones)t.sortBone(e);t.pushConstraint(this);for(let e of this.bones)t.sortReset(e.children);for(let e of this.bones)e.sorted=true;}update(t){let e=this.mix;if(!e.rotate&&!e.x&&!e.y&&!e.scaleX&&!e.scaleY&&!e.shearY)return;let n=this.source.applied,o=this.data.offsets;for(let s of this.bones){let i=s.applied;i.modifyWorld(t);for(let r of this.data.properties){let c=Et(t,n,r.prop,o)-r.offset;for(let a of r.to){let h=e[a.prop];h!==0&&Rt(t,i,a.prop,a.offset+c*a.scale,h);}}}}};function Et(l,t,e,n){let o=l.scaleX,s=l.scaleY;switch(e){case "rotate":{let i=(t.a*t.d-t.b*t.c)*o*s>0?1:-1,r=Math.atan2(t.c/s,t.a/o)/X+i*n.rotate;return r<0&&(r+=360),r}case "x":return (n.x*t.a+n.y*t.b+t.worldX)/o;case "y":return (n.x*t.c+n.y*t.d+t.worldY)/s;case "scaleX":return Math.hypot(t.a/o,t.c/s)+n.scaleX;case "scaleY":return Math.hypot(t.b/o,t.d/s)+n.scaleY;case "shearY":return (Math.atan2(t.d/s,t.b/o)-Math.atan2(t.c/s,t.a/o))/X-90+n.shearY}}function Rt(l,t,e,n,o){let s=l.scaleX,i=l.scaleY;switch(e){case "rotate":{let r=t.a/s,c=t.b/s,a=t.c/i,h=t.d/i,p=n*X-Math.atan2(a,r);p>Math.PI?p-=2*Math.PI:p<-Math.PI&&(p+=2*Math.PI),p*=o;let u=Math.cos(p),m=Math.sin(p);t.a=(u*r-m*a)*s,t.b=(u*c-m*h)*s,t.c=(m*r+u*a)*i,t.d=(m*c+u*h)*i;return}case "x":t.worldX+=(n-t.worldX/s)*o*s;return;case "y":t.worldY+=(n-t.worldY/i)*o*i;return;case "scaleX":{let r=Math.hypot(t.a/s,t.c/i);r!==0&&(r=1+(n-r)*o/r,t.a*=r,t.c*=r);return}case "scaleY":{let r=Math.hypot(t.b/s,t.d/i);r!==0&&(r=1+(n-r)*o/r,t.b*=r,t.d*=r);return}case "shearY":{let r=t.b/s,c=t.d/i,a=Math.atan2(c,r),h=(n+90)*X;h-=a-Math.atan2(t.c/i,t.a/s),h>Math.PI?h-=2*Math.PI:h<-Math.PI&&(h+=2*Math.PI),h=a+h*o;let p=Math.hypot(r,c);t.b=Math.cos(h)*p*s,t.d=Math.sin(h)*p*i;return}}}var tt=class{constructor(t,e,n=.2){this.skeleton=t;this.data=e;this.defaultMix=n;this.snapshot=new Float32Array(t.bones.length*5),this.slotSnapshot=new Float32Array(t.slots.length*4),this.ikSnapshot=new Float32Array(t.constraints.length);}skeleton;data;defaultMix;track=null;previous=null;mixTime=0;mixDuration=0;listeners=new Map;snapshot;slotSnapshot;ikSnapshot;blink=null;setBlink(t){let e=t?this.data.animations.get(t.animation):void 0;if(!t||!e){this.blink=null;return}let n={bones:new Set(t.bones.map(o=>this.data.bone(o).index)),slots:new Set(t.slots.map(o=>this.data.slot(o).index))};this.blink={source:e,filter:n,options:t,wait:this.nextBlink(t),at:-1};}blinkNow(){this.blink&&(this.blink.at=0);}blinking(){return (this.blink?.at??-1)>=0}setRandom(t){this.random=t;}random=Math.random;nextBlink(t){return t.every[0]+this.random()*(t.every[1]-t.every[0])}names(){return [...this.data.animations.keys()]}has(t){return this.data.animations.has(t)}play(t,e={}){let n=this.data.animations.get(t);if(!n)return false;let o=e.mix??this.defaultMix;return this.previous=this.track&&o>0?this.track:null,this.mixTime=0,this.mixDuration=this.previous?o:0,this.track={animation:n,time:Math.max(0,e.from??0),speed:e.speed??1,loop:e.loop??true,done:false},true}current(){return this.track?.animation.name??null}time(){return this.track?this.local(this.track):0}duration(){return this.track?.animation.duration??0}finished(){return this.track?.done??false}setSpeed(t){this.track&&(this.track.speed=t);}on(t,e){let n=this.listeners.get(t)??new Set;return n.add(e),this.listeners.set(t,n),()=>n.delete(e)}update(t){let e=[],n=this.track;if(n&&!n.done){let o=n.time;n.time+=Math.max(0,t)*n.speed,this.collect(n,o,n.time,e),!n.loop&&n.time>=n.animation.duration&&(n.time=n.animation.duration,n.done=true,e.push({name:"end",animation:n.animation.name}));}if(this.previous){let o=this.previous;o.time+=Math.max(0,t)*o.speed,this.mixTime+=Math.max(0,t),this.mixTime>=this.mixDuration&&(this.previous=null);}this.advanceBlink(Math.max(0,t)),this.pose();for(let o of e){for(let s of this.listeners.get(o.name)??[])s(o);for(let s of this.listeners.get("*")??[])s(o);}}pose(){let t=this.skeleton,e=this.previous;e&&this.mixDuration>0&&(t.setupPose(),e.animation.apply(t,this.local(e)),this.save()),t.setupPose(),this.track&&this.track.animation.apply(t,this.local(this.track)),e&&this.mixDuration>0&&this.blendFromSaved(Math.min(1,this.mixTime/this.mixDuration));let n=this.blink;n&&n.at>=0&&n.source.applyOnly(t,n.options.from+n.at,n.filter),t.resolveAttachments();}advanceBlink(t){let e=this.blink;if(e){if(this.track?.animation.touches(e.filter)){e.at=-1;return}if(e.at>=0){e.at+=t,e.at>=e.options.to-e.options.from&&(e.at=-1,e.wait=this.nextBlink(e.options));return}e.wait-=t,e.wait<=0&&(e.at=0);}}local(t){let e=t.animation.duration;return e<=0?0:t.loop?t.time%e:Math.min(t.time,e)}collect(t,e,n,o){let s=t.animation.duration;if(s<=0||n<=e)return;let i=Math.floor(e/s),r=t.loop?Math.floor(n/s):0;for(let c=i;c<=r;c++)for(let a of t.animation.events){let h=c*s+a.time;h>=e&&(h<n||!t.loop&&h<=n)&&o.push({name:a.name,animation:t.animation.name});}}save(){let t=this.skeleton;t.bones.forEach((e,n)=>{let o=e.pose;this.snapshot.set([o.x,o.y,o.rotation,o.scaleX,o.scaleY],n*5);}),t.slots.forEach((e,n)=>this.slotSnapshot.set([e.color.r,e.color.g,e.color.b,e.color.a],n*4)),t.constraints.forEach((e,n)=>{e instanceof E&&(this.ikSnapshot[n]=e.mix);});}blendFromSaved(t){let e=this.skeleton,n=(o,s)=>o+(s-o)*t;e.bones.forEach((o,s)=>{let i=this.snapshot,r=o.pose,c=s*5;r.x=n(i[c],r.x),r.y=n(i[c+1],r.y);let a=r.rotation-i[c+2];a-=Math.round(a/360)*360,r.rotation=i[c+2]+a*t,r.scaleX=n(i[c+3],r.scaleX),r.scaleY=n(i[c+4],r.scaleY);}),e.slots.forEach((o,s)=>{let i=this.slotSnapshot;o.color.r=n(i[s*4],o.color.r),o.color.g=n(i[s*4+1],o.color.g),o.color.b=n(i[s*4+2],o.color.b),o.color.a=n(i[s*4+3],o.color.a);}),e.constraints.forEach((o,s)=>{o instanceof E&&(o.mix=n(this.ikSnapshot[s],o.mix));});}};var Tt=Math.PI/180,Ft=new Float32Array([0,1,0,0,1,0,1,1]),Ht=new Uint16Array([0,1,2,2,3,0]),At=new WeakMap;function Wt(l){let t=At.get(l);if(t)return t;let e=-l.width/2*l.scaleX,n=-l.height/2*l.scaleY,o=l.width/2*l.scaleX,s=l.height/2*l.scaleY,i=Math.cos(l.rotation*Tt),r=Math.sin(l.rotation*Tt),c=(a,h)=>[a*i-h*r+l.x,a*r+h*i+l.y];return t=Float32Array.from([...c(e,n),...c(e,s),...c(o,s),...c(o,n)]),At.set(l,t),t}function et(l,t,e,n){if(e.type==="region"){let o=n&&n.length===8?n:new Float32Array(8),s=Wt(e),i=t.bone.applied;for(let r=0;r<8;r+=2){let c=s[r],a=s[r+1];o[r]=c*i.a+a*i.b+i.worldX,o[r+1]=c*i.c+a*i.d+i.worldY;}return {positions:o,uvs:Ft,triangles:Ht}}return Nt(l,t,e,n)}function Nt(l,t,e,n){let o=e.vertexCount*2,s=n&&n.length===o?n:new Float32Array(o),i=e.vertices;if(e.weighted){let r=0;for(let c=0;c<o;c+=2){let a=i[r++],h=0,p=0;for(let u=0;u<a;u++,r+=4){let m=l.bones[i[r]].applied,f=i[r+1],y=i[r+2],d=i[r+3];h+=(f*m.a+y*m.b+m.worldX)*d,p+=(f*m.c+y*m.d+m.worldY)*d;}s[c]=h,s[c+1]=p;}}else {let r=t.bone.applied;for(let c=0;c<o;c+=2){let a=i[c],h=i[c+1];s[c]=a*r.a+h*r.b+r.worldX,s[c+1]=a*r.c+h*r.d+r.worldY;}}return {positions:s,uvs:e.uvs,triangles:e.triangles}}function Pt(l){let t=/^#?([0-9a-f]{6})$/i.exec(l.trim());return t?parseInt(t[1],16):16777215}var Dt=new WeakMap;function It(l){let t=Dt.get(l);if(t)return t;t=new Map;for(let e of l.skins.values())for(let n of e.attachments.values())for(let o of n.values())t.has(o.path)||t.set(o.path,{w:o.width,h:o.height});return Dt.set(l,t),t}function Yt(l,t){let e=l.skins.get(t);if(!e)return [];let n=new Set;for(let o of e.attachments.values())for(let s of o.values())n.add(s.path);return [...n]}var nt=class{constructor(t,e=()=>true){this.rig=t;this.drawable=e;let n=(o,s)=>t.colorTargets.find(i=>(i.into??"tint")===s&&i.slotPrefixes.some(r=>o.startsWith(r)))?.id??null;this.slotTarget=t.data.slots.map(o=>n(o.name,"tint")),this.slotArt=t.data.slots.map(o=>n(o.name,"art")),this.rebuildLists(),this.init();}rig;drawable;chosen=new Map;hidden=new Map;colors=new Map;lists=new Map;listeners=new Set;slotTarget;slotArt;face=null;emotionFace=null;speech="rest";setDrawable(t){let e=new Set(this.rig.partTypes.filter(n=>!this.count(n.id)).map(n=>n.id));this.drawable=t,this.rebuildLists();for(let n of this.rig.partTypes){if(n.auto)continue;let o=this.chosen.get(n.id);(o&&!this.lists.get(n.id).includes(o)||!o&&e.has(n.id))&&this.chosen.set(n.id,this.first(n));}this.emit({kind:"part",type:"*",skin:null});}on(t){return this.listeners.add(t),()=>this.listeners.delete(t)}emit(t){for(let e of [...this.listeners])e(t);}typeDef(t){return this.rig.partTypes.find(e=>e.id===t)}list(t){return this.lists.get(t)??[]}count(t){return this.list(t).length}part(t){return this.chosen.get(t)??null}index(t){let e=this.part(t);return e?this.list(t).indexOf(e):-1}isHidden(t){return this.hidden.get(t)??false}isWorn(t){return this.part(t)!==null&&!this.isHidden(t)}color(t){return this.colors.get(t)??null}wornSkins(){let t=new Map;for(let a of this.rig.partTypes)t.set(a.id,!a.auto&&this.isWorn(a.id)?this.part(a.id):null);let e={worn:a=>t.get(a)??null,setWorn:(a,h)=>t.set(a,h),exists:a=>this.rig.data.skins.has(a)&&this.drawable(a)};for(let a of this.rig.rules)a.apply(e);let n=this.rig.expressions,o=this.face??this.emotionFace,s=o?n?.faces[o]:void 0;for(let[a,h]of Object.entries(s??{}))t.get(a)&&e.exists(h)&&t.set(a,h);let i=this.speech!=="rest"?n?.speech:void 0,r=i?.visemes[this.speech];i&&r&&t.get(i.type)&&e.exists(r)&&t.set(i.type,r);let c=[];for(let a of this.rig.partTypes){let h=t.get(a.id);h&&c.push(h);}return c}slotColor(t){let e=this.slotTarget[t];return e?this.color(e):null}artColor(t){let e=this.slotArt[t];return e?this.color(e):null}expression(){return this.face}equip(t,e){let n=this.lists.get(t);if(!n)return;let o;if(e===null||e===-1)o=null;else if(typeof e=="number")o=n[Math.max(0,Math.min(n.length-1,e))]??null;else if(n.includes(e))o=e;else return;o===null&&!this.typeDef(t)?.canHide||(this.chosen.set(t,o),this.emit({kind:"part",type:t,skin:o}));}unequip(t){this.equip(t,null);}setHidden(t,e){this.typeDef(t)?.canHide&&(this.hidden.set(t,e),this.emit({kind:"hidden",type:t,hidden:e}));}next(t){let e=this.count(t);if(!e)return;let n=this.index(t);this.typeDef(t)?.canHide?this.equip(t,n>=e-1?-1:n+1):this.equip(t,(n+1)%e);}prev(t){let e=this.count(t);if(!e)return;let n=this.index(t);this.typeDef(t)?.canHide?this.equip(t,n<=-1?e-1:n-1):this.equip(t,(n-1+e)%e);}setColor(t,e){this.colors.set(t,e),this.emit({kind:"color",target:t,color:e});}setExpression(t){let e=t&&this.rig.expressions?.faces[t]?t:null;e!==this.face&&(this.face=e,this.emit({kind:"expression",name:e}));}setEmotion(t){let e=this.rig.expressions?.emotions?.[t]??null,n=e&&this.rig.expressions?.faces[e]?e:null;n!==this.emotionFace&&(this.emotionFace=n,this.emit({kind:"expression",name:this.face??n}));}setSpeech(t){t!==this.speech&&(this.speech=t,this.emit({kind:"speech",viseme:t}));}randomize(t=Math.random){for(let e of this.rig.partTypes){if(e.auto)continue;let n=this.count(e.id);n&&this.equip(e.id,e.canHide&&t()<.3?-1:Math.floor(t()*n));}}reset(){this.init();for(let t of this.rig.partTypes)this.emit({kind:"part",type:t.id,skin:this.part(t.id)});}toLook(){let t={};for(let n of this.rig.partTypes)n.auto||(t[n.id]=this.isWorn(n.id)?this.part(n.id):null);let e={};for(let[n,o]of this.colors)o&&(e[n]=o);return {v:1,parts:t,colors:e}}applyLook(t){for(let[e,n]of Object.entries(t.parts??{}))n===void 0||this.typeDef(e)?.auto||(this.equip(e,n),n!==null&&this.part(e)===n&&this.hidden.set(e,false));for(let[e,n]of Object.entries(t.colors??{}))n&&this.setColor(e,n);}rebuildLists(){for(let t of this.rig.partTypes)this.lists.set(t.id,this.rig.data.skinOrder.filter(e=>e.startsWith(t.skinPrefix)&&this.drawable(e)));}first(t){return this.lists.get(t.id)?.[0]??null}init(){this.chosen.clear(),this.hidden.clear(),this.colors.clear();for(let t of this.rig.partTypes)this.chosen.set(t.id,t.auto?null:this.first(t));}};var U=Math.PI/180,ut=1e-5,ot=class{constructor(t){this.bone=t;}bone;x=0;y=0;rotation=0;scaleX=1;scaleY=1;shearX=0;shearY=0;a=1;b=0;c=0;d=1;worldX=0;worldY=0;world=0;local=0;copyLocal(t){this.x=t.x,this.y=t.y,this.rotation=t.rotation,this.scaleX=t.scaleX,this.scaleY=t.scaleY,this.shearX=t.shearX,this.shearY=t.shearY;}update(t){this.world!==t.updateId&&this.updateWorldTransform(t);}updateWorldTransform(t){this.local===t.updateId?this.updateLocalTransform(t):this.world=t.updateId;let e=(this.rotation+this.shearX)*U,n=(this.rotation+90+this.shearY)*U,o=Math.cos(e)*this.scaleX,s=Math.cos(n)*this.scaleY,i=Math.sin(e)*this.scaleX,r=Math.sin(n)*this.scaleY,c=this.bone.parent;if(!c){let h=t.scaleX,p=t.scaleY;this.a=o*h,this.b=s*h,this.c=i*p,this.d=r*p,this.worldX=this.x*h+t.x,this.worldY=this.y*p+t.y;return}let a=c.applied;this.worldX=a.a*this.x+a.b*this.y+a.worldX,this.worldY=a.c*this.x+a.d*this.y+a.worldY,this.a=a.a*o+a.b*i,this.b=a.a*s+a.b*r,this.c=a.c*o+a.d*i,this.d=a.c*s+a.d*r;}updateLocalTransform(t){this.local=0,this.world=t.updateId;let e=this.bone.parent;if(!e){this.x=(this.worldX-t.x)/t.scaleX,this.y=(this.worldY-t.y)/t.scaleY,this.set5(this.a/t.scaleX,this.b/t.scaleX,this.c/t.scaleY,this.d/t.scaleY);return}let n=e.applied,o=1/(n.a*n.d-n.b*n.c),s=n.d*o,i=n.b*o,r=n.c*o,c=n.a*o,a=this.worldX-n.worldX,h=this.worldY-n.worldY;this.x=a*s-h*i,this.y=h*c-a*r,this.set5(s*this.a-i*this.c,s*this.b-i*this.d,c*this.c-r*this.a,c*this.d-r*this.b);}set5(t,e,n,o){this.shearX=0;let s=t*t+n*n,i=e*e+o*o;if(s>ut){let r=Math.atan2(n,t)/U;this.rotation=r,this.scaleX=Math.sqrt(s),this.scaleY=Math.sqrt(i),i>ut?(this.shearY=Math.atan2(o,e)/U,t*o-e*n<0?(this.scaleY=-this.scaleY,this.shearY+=90-r):this.shearY-=90+r,this.shearY>180?this.shearY-=360:this.shearY<=-180&&(this.shearY+=360)):this.shearY=0;}else this.scaleX=0,this.scaleY=Math.sqrt(i),this.shearY=0,this.rotation=i>ut?Math.atan2(o,e)/U-90:0;}modifyLocal(t){this.local===t.updateId&&this.updateLocalTransform(t),this.world=0,this.resetWorld(t);}modifyWorld(t){this.local=t.updateId,this.world=t.updateId,this.resetWorld(t);}resetWorld(t){for(let e of this.bone.children){let n=e.applied;n.world===t.updateId&&(n.local===t.updateId&&n.updateLocalTransform(t),n.world=0,n.resetWorld(t));}}},st=class{constructor(t){this.data=t;this.pose=new ot(this),this.applied=new ot(this),this.setupPose();}data;pose;applied;parent=null;children=[];sorted=false;setupPose(){let t=this.data,e=this.pose;e.x=t.x,e.y=t.y,e.rotation=t.rotation,e.scaleX=t.scaleX,e.scaleY=t.scaleY,e.shearX=0,e.shearY=0;}},mt=class{constructor(t,e){this.data=t;this.bone=e;this.color={...t.color},this.attachmentKey=t.attachment;}data;bone;color;attachmentKey;attachment=null},R=class{constructor(t){this.data=t;this.bones=t.bones.map(e=>new st(e));for(let e of this.bones)e.data.parent&&(e.parent=this.bones[e.data.parent.index],e.parent.children.push(e));this.slots=t.slots.map(e=>new mt(e,this.bones[e.bone.index])),this.constraints=t.constraints.map(e=>Mt(e,this)),this.updateCache();}data;bones;slots;constraints;skins=[];scaleX=1;scaleY=1;x=0;y=0;updateId=0;cache=[];bone(t){return this.bones[this.data.bone(t).index]}slot(t){return this.slots[this.data.slot(t).index]}setSkins(t){this.skins=[...t],this.resolveAttachments();}getAttachment(t,e){for(let n=this.skins.length-1;n>=0;n--){let o=this.skins[n].attachments.get(t)?.get(e);if(o)return o}return null}resolveAttachments(){for(let t of this.slots)t.attachment=t.attachmentKey?this.getAttachment(t.data.index,t.attachmentKey):null;}setupPose(){for(let t of this.bones)t.setupPose();for(let t of this.constraints)t.setupPose();for(let t of this.slots)Object.assign(t.color,t.data.color),t.attachmentKey=t.data.attachment;}updateWorldTransform(){this.updateId++;for(let t of this.bones)t.applied.copyLocal(t.pose),t.applied.world=0,t.applied.local=0;for(let t of this.cache)t instanceof st?t.applied.update(this):t.update(this);}updateCache(){this.cache=[];for(let t of this.bones)t.sorted=false;for(let t of this.constraints)t.sort(this);for(let t of this.bones)this.sortBone(t);}sortBone(t){t.sorted||(t.parent&&this.sortBone(t.parent),t.sorted=true,this.cache.push(t));}sortReset(t){for(let e of t)e.sorted&&this.sortReset(e.children),e.sorted=false;}pushConstraint(t){this.cache.push(t);}};var Ct=new WeakMap;function Xt(l,t){let e=Ct.get(l);if(e)return e;e=new Map;let n=new R(l);n.setupPose(),n.updateWorldTransform();let[o,s]=t.light;for(let i of l.skins.values())for(let[r,c]of i.attachments)for(let a of c.values()){if(e.has(a.path)||t.skip?.some(d=>a.path.startsWith(d)))continue;let h=et(n,n.slots[r],a,null),p=qt(h.positions,h.uvs,a.width,a.height);if(!p)continue;let u=p.a*p.d-p.b*p.c;if(Math.abs(u)<1e-9)continue;let m=(p.d*o-p.b*s)/u,f=(-p.c*o+p.a*s)/u,y=Math.hypot(m,f)||1;e.set(a.path,{x:m/y,y:f/y});}return Ct.set(l,e),e}function qt(l,t,e,n){let o=t.length/2;if(o<3)return null;let s=0,i=0,r=0,c=0;for(let g=0;g<o;g++)s+=t[g*2]*e,i+=t[g*2+1]*n,r+=l[g*2],c+=l[g*2+1];s/=o,i/=o,r/=o,c/=o;let a=0,h=0,p=0,u=0,m=0,f=0,y=0;for(let g=0;g<o;g++){let v=t[g*2]*e-s,b=t[g*2+1]*n-i,B=l[g*2]-r,$=l[g*2+1]-c;a+=v*v,h+=v*b,p+=b*b,u+=B*v,m+=B*b,f+=$*v,y+=$*b;}let d=a*p-h*h;return Math.abs(d)<1e-9?null:{a:(u*p-m*h)/d,b:(m*a-u*h)/d,c:(f*p-y*h)/d,d:(y*a-f*h)/d}}var J=class{constructor(t,e){this.scene=t;let n=this.rig=e.rig;this.art=e.art,this.skeleton=new R(n.data),this.sizes=It(n.data),this.lights=n.shading?Xt(n.data,n.shading):new Map,this.parts=new nt(n,o=>this.drawsSkin(o)),e.look&&this.parts.applyLook(e.look),this.offs.push(this.parts.on(()=>this.skinsDirty=true)),this.animator=new tt(this.skeleton,n.data,n.mix),this.animator.setBlink(n.blink??null),this.play(e.animation??n.defaultAnimation,{mix:0}),this.root=t.add.container(e.x??0,e.y??0);for(let o=0;o<this.skeleton.slots.length;o++){let s=new F__default.default.GameObjects.Mesh2D(t,0,0,"__DEFAULT",[],[],true);s.setRenderAsTriangles(true),s.setVisible(false),this.root.add(s),this.slots.push({mesh:s,positions:null,vertices:[],indices:[],path:null,key:null,paint:null,waiting:false});}if(this.setScale(e.scale??1),e.autoUpdate!==false){let o=(s,i)=>this.update(i/1e3);t.events.on(F__default.default.Scenes.Events.UPDATE,o),this.offs.push(()=>t.events.off(F__default.default.Scenes.Events.UPDATE,o));}this.root.once(F__default.default.GameObjects.Events.DESTROY,()=>{for(let o of this.offs.splice(0))o();}),this.update(0);}scene;root;skeleton;animator;parts;slots=[];sizes;lights;skinsDirty=true;overlay=null;flashUntil=0;flashColor=16777215;facing=1;size=1;offs=[];asked=null;rig;art;play(t,e){return this.asked={name:t,...e?{options:e}:{}},this.animator.play(this.stanceOf(t),e)}animation(){return this.asked?.name??null}stanceOf(t){let e=this.parts;return this.rig.stance?.(t,n=>e.isWorn(n)?e.part(n):null)??t}on(t,e){let n=this.animator.on(t,e);return this.offs.push(n),n}setLook(t){this.parts.applyLook(t);}setArt(t){this.art=t;for(let e of this.slots)e.key=e.path=null,e.waiting=false;this.parts.setDrawable(e=>this.drawsSkin(e));}setPosition(t,e){return this.root.setPosition(t,e),this}setScale(t){return this.size=t,this.root.setScale(t*this.facing,t),this}setFacing(t){return this.facing=t,this.setScale(this.size)}setDepth(t){return this.root.setDepth(t),this}setVisible(t){return this.root.setVisible(t),this}setAlpha(t){return this.root.setAlpha(t),this}setOverlay(t){return this.overlay=t,this}flash(t=16777215,e=90){this.flashColor=t,this.flashUntil=this.scene.time.now+e;}worldPoint(t){let e=this.rig.anchors[t]??t,n=this.skeleton.bone(e).applied,o=this.root.getWorldTransformMatrix();return {x:o.tx+o.a*n.worldX+o.c*-n.worldY,y:o.ty+o.b*n.worldX+o.d*-n.worldY}}get displayHeight(){return this.rig.data.height*this.size}destroy(){this.root.destroy();}update(t){let e=this.skeleton,n=this.rig.expressions;if(n&&this.parts.setExpression(n.byAnimation[this.animator.current()??""]??null),this.skinsDirty){this.skinsDirty=false,e.setSkins(this.parts.wornSkins().flatMap(i=>{let r=this.rig.data.skins.get(i);return r?[r]:[]}));let s=this.asked;s&&this.stanceOf(s.name)!==this.animator.current()&&this.animator.play(this.stanceOf(s.name),{...s.options,mix:.15});}this.animator.update(t),e.slots.forEach((s,i)=>{let r=this.parts.slotColor(i);if(!r)return;let c=Pt(r);s.color.r=(c>>16&255)/255,s.color.g=(c>>8&255)/255,s.color.b=(c&255)/255,s.color.a=1;}),e.updateWorldTransform();let o=this.flashUntil>this.scene.time.now;e.slots.forEach((s,i)=>this.drawSlot(i,o));}drawSlot(t,e){let n=this.slots[t],o=this.skeleton.slots[t],s=o.attachment,i=n.mesh;if(!s||o.color.a<=0){i.setVisible(false);return}let r=this.parts.artColor(t);if((n.path!==s.path||n.paint!==r)&&(n.path=s.path,n.paint=r,n.key=null,n.waiting=false),!n.key&&!n.waiting){let d=this.sizes.get(s.path)??{w:s.width,h:s.height},g=s.path,v=this.art.texture(g,d,()=>{n.path===g&&(n.waiting=false);},{paint:r,light:this.lights.get(g)??null});v?(n.key=v,i.setTexture(v)):n.waiting=true;}if(!n.key){i.setVisible(false);return}let c=et(this.skeleton,o,s,n.positions);n.positions=c.positions;let a=c.uvs.length/2,h=n.vertices;h.length=a*4;for(let d=0;d<a;d++)h[d*4]=c.positions[d*2],h[d*4+1]=-c.positions[d*2+1],h[d*4+2]=c.uvs[d*2],h[d*4+3]=c.uvs[d*2+1];let p=c.triangles,u=n.indices;if(u.length!==p.length/3*4){u.length=0;for(let d=0;d<p.length;d+=3)u.push(p[d],p[d+1],p[d+2],0);}else for(let d=0,g=0;d<p.length;d+=3,g+=4)u[g]=p[d],u[g+1]=p[d+1],u[g+2]=p[d+2];i.vertices=h,i.indices=u;let m=o.color,f=s.color,y=Math.round(m.r*f.r*255)<<16|Math.round(m.g*f.g*255)<<8|Math.round(m.b*f.b*255);this.overlay!==null&&(y=Gt(y,this.overlay)),e?i.setTint(this.flashColor).setTintMode(F__default.default.TintModes.FILL):i.setTint(y).setTintMode(F__default.default.TintModes.MULTIPLY),i.setAlpha(m.a*f.a),i.setVisible(true);}drawsSkin(t){return Yt(this.rig.data,t).every(e=>this.art.has(e))}};function Gt(l,t){let e=n=>Math.round((l>>n&255)*(t>>n&255)/255)<<n;return e(16)|e(8)|e(0)}function Bt(l,t,e=1,n={}){let o=Math.max(1,Math.ceil(t.w*e)),s=Math.max(1,Math.ceil(t.h*e)),i=n.paint??l.paint,r=n.light?Vt(t,n.light):"";return `<svg xmlns="http://www.w3.org/2000/svg" width="${o}" height="${s}" viewBox="0 0 ${t.w} ${t.h}"${i?` color="${i}"`:""}>${r}<g stroke-linejoin="round" stroke-linecap="round"${r?' filter="url(#cel)"':""}>${l.svg}</g></svg>`}var j={depth:.18,min:2.6,max:11,dark:.3,shine:.36};function Vt(l,t){let e=Math.max(j.min,Math.min(j.max,Math.min(l.w,l.h)*j.depth)),n=o=>+o.toFixed(2);return `<defs><filter id="cel" filterUnits="userSpaceOnUse" x="0" y="0" width="${l.w}" height="${l.h}" color-interpolation-filters="sRGB"><feMorphology in="SourceAlpha" operator="erode" radius="${n(3.6*.7)}" result="body"/><feOffset in="body" dx="${n(t.x*e)}" dy="${n(t.y*e)}" result="moved"/><feComposite in="body" in2="moved" operator="out" result="far"/><feFlood flood-color="#000000" flood-opacity="${j.dark}"/><feComposite in2="far" operator="in" result="dark"/><feMorphology in="SourceAlpha" operator="erode" radius="${n(3.6*1.05)}" result="inner"/><feOffset in="inner" dx="${n(-t.x*e*.42)}" dy="${n(-t.y*e*.42)}" result="back"/><feComposite in="inner" in2="back" operator="out" result="near"/><feFlood flood-color="#ffffff" flood-opacity="${j.shine}"/><feComposite in2="near" operator="in" result="shine"/><feMerge><feMergeNode in="SourceGraphic"/><feMergeNode in="dark"/><feMergeNode in="shine"/></feMerge></filter></defs>`}var $t=new WeakMap;function Ut(l,t,e){return `chr:${l}@${t}${e||""}`}function Lt(l,t,e,n,o,s,i={}){let r=e.paint?i.paint??null:null,c=Ut(t,o,r);if(l.exists(c))return c;let a=$t.get(l);a||$t.set(l,a=new Map);let h=a.get(c);if(h)return h.push(s),null;let p=[s];a.set(c,p);let u=new Image,m=()=>{a.delete(c);for(let f of p)f();};return u.onload=()=>{l.exists(c)||l.addImage(c,u),m();},u.onerror=()=>{console.warn(`[character] art ${t} did not render`),m();},u.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(Bt(e,n,o,{paint:r,light:i.light??null})),null}function ft(l,t,e=2){return {has:n=>t.has(n),texture(n,o,s,i){let r=t.get(n);return r?Lt(l,n,r,o,e,s,i):null}}}function Jt(l,t){return new Promise(e=>{let{width:n,height:o}=t,s=Math.min(2,Math.max(1,typeof devicePixelRatio=="number"&&devicePixelRatio||1));class i extends F__default.default.Scene{create(){this.cameras.main.setOrigin(0,0).setZoom(s);let a=t.scale??1,h=ft(this.textures,t.catalog,Math.max(2,Math.ceil(a*s*1.5))),p=new J(this,{rig:t.rig,art:h,...t.look?{look:t.look}:{},x:n/2,y:Math.round(o*.88),scale:a});e({view:p,game:r,vector:h,destroy:()=>r.destroy(true)});}}let r=new F__default.default.Game({type:F__default.default.WEBGL,parent:l,width:Math.ceil(n*s),height:Math.ceil(o*s),scale:{mode:F__default.default.Scale.NONE,zoom:1/s},render:{autoMobileTextures:false},transparent:!t.background,...t.background?{backgroundColor:t.background}:{},scene:i,banner:false,audio:{noAudio:true}});})}
2
- exports.CharacterView=J;exports.createCharacterStage=Jt;exports.vectorArt=ft;
1
+ 'use strict';var F=require('phaser');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var F__default=/*#__PURE__*/_interopDefault(F);var R=Math.PI/180,ht=1e-5;function St(l,t){return l.type==="ik"?new O(l,t):new pt(l,t)}var dt=l=>l>180?l-360:l<=-180?l+360:l,O=class{constructor(t,e){this.data=t;this.bones=t.bones.map(o=>e.bones[o.index]),this.target=e.bones[t.target.index],this.mix=t.mix,this.bendDirection=t.bendDirection;}data;mix;bendDirection;bones;target;setupPose(){this.mix=this.data.mix,this.bendDirection=this.data.bendDirection;}sort(t){t.sortBone(this.target);let e=this.bones[0];t.sortBone(e),t.pushConstraint(this),e.sorted=false,t.sortReset(e.children);}update(t){if(this.mix===0)return;let e=this.target.applied;this.bones.length===1?Mt(t,this.bones[0].applied,e.worldX,e.worldY,this.mix):Ot(t,this.bones[0].applied,this.bones[1].applied,e.worldX,e.worldY,this.bendDirection,this.mix);}};function Mt(l,t,e,o,n){let r=t.bone.parent;if(!r)return;t.modifyLocal(l);let s=r.applied,i=s.a,c=s.b,a=s.c,h=s.d,d=-t.shearX-t.rotation,u=i*h-c*a,f=e-s.worldX,m=o-s.worldY,y=(f*h-m*c)/u-t.x,p=(m*i-f*a)/u-t.y;d+=Math.atan2(p,y)/R,t.scaleX<0&&(d+=180),t.rotation+=dt(d)*n;}function Ot(l,t,e,o,n,r,s){t.modifyLocal(l),e.modifyLocal(l);let i=t.x,c=t.y,a=t.scaleX,h=t.scaleY,d=e.scaleX,u,f,m;a<0?(a=-a,u=180,m=-1):(u=0,m=1),h<0&&(h=-h,m=-m),d<0?(d=-d,f=180):f=0;let y=Math.abs(a-h)<=ht,p,g;y?(p=t.a*e.x+t.b*e.y+t.worldX,g=t.c*e.x+t.d*e.y+t.worldY):(e.y=0,p=t.a*e.x+t.worldX,g=t.c*e.x+t.worldY);let v=t.bone.parent;if(!v)return;let b=v.applied,X=b.a,L=b.b,it=b.c,at=b.d,A=X*at-L*it,H=p-b.worldX,W=g-b.worldY;A=Math.abs(A)<=ht?0:1/A;let gt=(H*at-W*L)*A-i,yt=(W*X-H*it)*A-c,x=Math.sqrt(gt*gt+yt*yt),T=e.bone.data.length*d;if(x<ht){Mt(l,t,o,n,s),e.rotation=0;return}H=o-b.worldX,W=n-b.worldY;let G=(H*at-W*L)*A-i,N=(W*X-H*it)*A-c,K=G*G+N*N,P=0,S=0;if(y){T*=a;let k=(K-x*x-T*T)/(2*x*T);k<-1?(k=-1,S=Math.PI*r):k>1?(k=1,S=0):S=Math.acos(k)*r;let B=x+T*k,D=T*Math.sin(S);P=Math.atan2(N*B-G*D,G*B+N*D);}else {let k=a*T,B=h*T,D=k*k,q=B*B,lt=Math.atan2(N,G),w=q*x*x+D*K-D*q,z=-2*q*x,xt=q-D,kt=z*z-4*xt*w,vt=false;if(kt>=0){let M=Math.sqrt(kt);z<0&&(M=-M),M=-(z+M)*.5;let C=M/xt,$=w/M,I=Math.abs(C)<Math.abs($)?C:$,V=K-I*I;if(V>=0){let Y=Math.sqrt(V)*r;P=lt-Math.atan2(Y,I),S=Math.atan2(Y/h,(I-x)/a),vt=true;}}if(!vt){let M=Math.PI,C=x-k,$=C*C,I=0,V=0,Y=x+k,ct=Y*Y,wt=0;if(w=-k*x/(D-q),w>=-1&&w<=1){w=Math.acos(w);let _=k*Math.cos(w)+x,Z=B*Math.sin(w),Q=_*_+Z*Z;Q<$&&(M=w,$=Q,C=_,I=Z),Q>ct&&(V=w,ct=Q,Y=_,wt=Z);}K<=($+ct)*.5?(P=lt-Math.atan2(I*r,C),S=M*r):(P=lt-Math.atan2(wt*r,Y),S=V*r);}}let bt=Math.atan2(e.y,e.x)*m;P=dt((P-bt)/R+u-t.rotation),S=dt(((S+bt)/R-e.shearX)*m+f-e.rotation),t.rotation+=P*s,e.rotation+=S*s;}var pt=class{constructor(t,e){this.data=t;this.source=e.bones[t.source.index],this.bones=t.bones.map(o=>e.bones[o.index]),this.mix={...t.mix};}data;mix;source;bones;setupPose(){Object.assign(this.mix,this.data.mix);}sort(t){t.sortBone(this.source);for(let e of this.bones)t.sortBone(e);t.pushConstraint(this);for(let e of this.bones)t.sortReset(e.children);for(let e of this.bones)e.sorted=true;}update(t){let e=this.mix;if(!e.rotate&&!e.x&&!e.y&&!e.scaleX&&!e.scaleY&&!e.shearY)return;let o=this.source.applied,n=this.data.offsets;for(let r of this.bones){let s=r.applied;s.modifyWorld(t);for(let i of this.data.properties){let c=Et(t,o,i.prop,n)-i.offset;for(let a of i.to){let h=e[a.prop];h!==0&&Ft(t,s,a.prop,a.offset+c*a.scale,h);}}}}};function Et(l,t,e,o){let n=l.scaleX,r=l.scaleY;switch(e){case "rotate":{let s=(t.a*t.d-t.b*t.c)*n*r>0?1:-1,i=Math.atan2(t.c/r,t.a/n)/R+s*o.rotate;return i<0&&(i+=360),i}case "x":return (o.x*t.a+o.y*t.b+t.worldX)/n;case "y":return (o.x*t.c+o.y*t.d+t.worldY)/r;case "scaleX":return Math.hypot(t.a/n,t.c/r)+o.scaleX;case "scaleY":return Math.hypot(t.b/n,t.d/r)+o.scaleY;case "shearY":return (Math.atan2(t.d/r,t.b/n)-Math.atan2(t.c/r,t.a/n))/R-90+o.shearY}}function Ft(l,t,e,o,n){let r=l.scaleX,s=l.scaleY;switch(e){case "rotate":{let i=t.a/r,c=t.b/r,a=t.c/s,h=t.d/s,d=o*R-Math.atan2(a,i);d>Math.PI?d-=2*Math.PI:d<-Math.PI&&(d+=2*Math.PI),d*=n;let u=Math.cos(d),f=Math.sin(d);t.a=(u*i-f*a)*r,t.b=(u*c-f*h)*r,t.c=(f*i+u*a)*s,t.d=(f*c+u*h)*s;return}case "x":t.worldX+=(o-t.worldX/r)*n*r;return;case "y":t.worldY+=(o-t.worldY/s)*n*s;return;case "scaleX":{let i=Math.hypot(t.a/r,t.c/s);i!==0&&(i=1+(o-i)*n/i,t.a*=i,t.c*=i);return}case "scaleY":{let i=Math.hypot(t.b/r,t.d/s);i!==0&&(i=1+(o-i)*n/i,t.b*=i,t.d*=i);return}case "shearY":{let i=t.b/r,c=t.d/s,a=Math.atan2(c,i),h=(o+90)*R;h-=a-Math.atan2(t.c/s,t.a/r),h>Math.PI?h-=2*Math.PI:h<-Math.PI&&(h+=2*Math.PI),h=a+h*n;let d=Math.hypot(i,c);t.b=Math.cos(h)*d*r,t.d=Math.sin(h)*d*s;return}}}var tt=class{constructor(t,e,o=.2){this.skeleton=t;this.data=e;this.defaultMix=o;this.snapshot=new Float32Array(t.bones.length*5),this.slotSnapshot=new Float32Array(t.slots.length*4),this.ikSnapshot=new Float32Array(t.constraints.length);}skeleton;data;defaultMix;track=null;previous=null;mixTime=0;mixDuration=0;listeners=new Map;snapshot;slotSnapshot;ikSnapshot;blink=null;setBlink(t){let e=t?this.data.animations.get(t.animation):void 0;if(!t||!e){this.blink=null;return}let o={bones:new Set(t.bones.map(n=>this.data.bone(n).index)),slots:new Set(t.slots.map(n=>this.data.slot(n).index))};this.blink={source:e,filter:o,options:t,wait:this.nextBlink(t),at:-1};}blinkNow(){this.blink&&(this.blink.at=0);}blinking(){return (this.blink?.at??-1)>=0}setRandom(t){this.random=t;}random=Math.random;nextBlink(t){return t.every[0]+this.random()*(t.every[1]-t.every[0])}names(){return [...this.data.animations.keys()]}has(t){return this.data.animations.has(t)}play(t,e={}){let o=this.data.animations.get(t);if(!o)return false;let n=e.mix??this.defaultMix;return this.previous=this.track&&n>0?this.track:null,this.mixTime=0,this.mixDuration=this.previous?n:0,this.track={animation:o,time:Math.max(0,e.from??0),speed:e.speed??1,loop:e.loop??true,done:false},true}current(){return this.track?.animation.name??null}time(){return this.track?this.local(this.track):0}duration(){return this.track?.animation.duration??0}finished(){return this.track?.done??false}setSpeed(t){this.track&&(this.track.speed=t);}on(t,e){let o=this.listeners.get(t)??new Set;return o.add(e),this.listeners.set(t,o),()=>o.delete(e)}update(t){let e=[],o=this.track;if(o&&!o.done){let n=o.time;o.time+=Math.max(0,t)*o.speed,this.collect(o,n,o.time,e),!o.loop&&o.time>=o.animation.duration&&(o.time=o.animation.duration,o.done=true,e.push({name:"end",animation:o.animation.name}));}if(this.previous){let n=this.previous;n.time+=Math.max(0,t)*n.speed,this.mixTime+=Math.max(0,t),this.mixTime>=this.mixDuration&&(this.previous=null);}this.advanceBlink(Math.max(0,t)),this.pose();for(let n of e){for(let r of this.listeners.get(n.name)??[])r(n);for(let r of this.listeners.get("*")??[])r(n);}}pose(){let t=this.skeleton,e=this.previous;e&&this.mixDuration>0&&(t.setupPose(),e.animation.apply(t,this.local(e)),this.save()),t.setupPose(),this.track&&this.track.animation.apply(t,this.local(this.track)),e&&this.mixDuration>0&&this.blendFromSaved(Math.min(1,this.mixTime/this.mixDuration));let o=this.blink;o&&o.at>=0&&o.source.applyOnly(t,o.options.from+o.at,o.filter),t.resolveAttachments();}advanceBlink(t){let e=this.blink;if(e){if(this.track?.animation.touches(e.filter)){e.at=-1;return}if(e.at>=0){e.at+=t,e.at>=e.options.to-e.options.from&&(e.at=-1,e.wait=this.nextBlink(e.options));return}e.wait-=t,e.wait<=0&&(e.at=0);}}local(t){let e=t.animation.duration;return e<=0?0:t.loop?t.time%e:Math.min(t.time,e)}collect(t,e,o,n){let r=t.animation.duration;if(r<=0||o<=e)return;let s=Math.floor(e/r),i=t.loop?Math.floor(o/r):0;for(let c=s;c<=i;c++)for(let a of t.animation.events){let h=c*r+a.time;h>=e&&(h<o||!t.loop&&h<=o)&&n.push({name:a.name,animation:t.animation.name});}}save(){let t=this.skeleton;t.bones.forEach((e,o)=>{let n=e.pose;this.snapshot.set([n.x,n.y,n.rotation,n.scaleX,n.scaleY],o*5);}),t.slots.forEach((e,o)=>this.slotSnapshot.set([e.color.r,e.color.g,e.color.b,e.color.a],o*4)),t.constraints.forEach((e,o)=>{e instanceof O&&(this.ikSnapshot[o]=e.mix);});}blendFromSaved(t){let e=this.skeleton,o=(n,r)=>n+(r-n)*t;e.bones.forEach((n,r)=>{let s=this.snapshot,i=n.pose,c=r*5;i.x=o(s[c],i.x),i.y=o(s[c+1],i.y);let a=i.rotation-s[c+2];a-=Math.round(a/360)*360,i.rotation=s[c+2]+a*t,i.scaleX=o(s[c+3],i.scaleX),i.scaleY=o(s[c+4],i.scaleY);}),e.slots.forEach((n,r)=>{let s=this.slotSnapshot;n.color.r=o(s[r*4],n.color.r),n.color.g=o(s[r*4+1],n.color.g),n.color.b=o(s[r*4+2],n.color.b),n.color.a=o(s[r*4+3],n.color.a);}),e.constraints.forEach((n,r)=>{n instanceof O&&(n.mix=o(this.ikSnapshot[r],n.mix));});}};var Tt=Math.PI/180,Ht=new Float32Array([0,1,0,0,1,0,1,1]),Wt=new Uint16Array([0,1,2,2,3,0]),At=new WeakMap;function Gt(l){let t=At.get(l);if(t)return t;let e=-l.width/2*l.scaleX,o=-l.height/2*l.scaleY,n=l.width/2*l.scaleX,r=l.height/2*l.scaleY,s=Math.cos(l.rotation*Tt),i=Math.sin(l.rotation*Tt),c=(a,h)=>[a*s-h*i+l.x,a*i+h*s+l.y];return t=Float32Array.from([...c(e,o),...c(e,r),...c(n,r),...c(n,o)]),At.set(l,t),t}function et(l,t,e,o){if(e.type==="region"){let n=o&&o.length===8?o:new Float32Array(8),r=Gt(e),s=t.bone.applied;for(let i=0;i<8;i+=2){let c=r[i],a=r[i+1];n[i]=c*s.a+a*s.b+s.worldX,n[i+1]=c*s.c+a*s.d+s.worldY;}return {positions:n,uvs:Ht,triangles:Wt}}return Nt(l,t,e,o)}function Nt(l,t,e,o){let n=e.vertexCount*2,r=o&&o.length===n?o:new Float32Array(n),s=e.vertices;if(e.weighted){let i=0;for(let c=0;c<n;c+=2){let a=s[i++],h=0,d=0;for(let u=0;u<a;u++,i+=4){let f=l.bones[s[i]].applied,m=s[i+1],y=s[i+2],p=s[i+3];h+=(m*f.a+y*f.b+f.worldX)*p,d+=(m*f.c+y*f.d+f.worldY)*p;}r[c]=h,r[c+1]=d;}}else {let i=t.bone.applied;for(let c=0;c<n;c+=2){let a=s[c],h=s[c+1];r[c]=a*i.a+h*i.b+i.worldX,r[c+1]=a*i.c+h*i.d+i.worldY;}}return {positions:r,uvs:e.uvs,triangles:e.triangles}}function Pt(l){let t=/^#?([0-9a-f]{6})$/i.exec(l.trim());return t?parseInt(t[1],16):16777215}var Dt=new WeakMap;function Ct(l){let t=Dt.get(l);if(t)return t;t=new Map;for(let e of l.skins.values())for(let o of e.attachments.values())for(let n of o.values())t.has(n.path)||t.set(n.path,{w:n.width,h:n.height});return Dt.set(l,t),t}function It(l,t){let e=l.skins.get(t);if(!e)return [];let o=new Set;for(let n of e.attachments.values())for(let r of n.values())o.add(r.path);return [...o]}function Yt(l,t){return !l.skin?.length||l.skin.some(e=>e.toLowerCase()===t.toLowerCase())}var ot=class{constructor(t,e=()=>true){this.rig=t;this.drawable=e;let o=(n,r)=>t.colorTargets.find(s=>(s.into??"tint")===r&&s.slotPrefixes.some(i=>n.startsWith(i)))?.id??null;this.slotTarget=t.data.slots.map(n=>o(n.name,"tint")),this.slotArt=t.data.slots.map(n=>o(n.name,"art")),this.rebuildLists(),this.init();}rig;drawable;chosen=new Map;hidden=new Map;colors=new Map;lists=new Map;listeners=new Set;slotTarget;slotArt;face=null;emotionFace=null;speech="rest";body={};raceSaved=new Map;raceGiven=new Map;setDrawable(t){let e=new Set(this.rig.partTypes.filter(o=>!this.count(o.id)).map(o=>o.id));this.drawable=t,this.rebuildLists();for(let o of this.rig.partTypes){if(o.auto)continue;let n=this.chosen.get(o.id);(n&&!this.lists.get(o.id).includes(n)||!n&&e.has(o.id))&&this.chosen.set(o.id,this.first(o));}this.emit({kind:"part",type:"*",skin:null});}on(t){return this.listeners.add(t),()=>this.listeners.delete(t)}emit(t){for(let e of [...this.listeners])e(t);}typeDef(t){return this.rig.partTypes.find(e=>e.id===t)}list(t){return this.lists.get(t)??[]}count(t){return this.list(t).length}part(t){return this.chosen.get(t)??null}index(t){let e=this.part(t);return e?this.list(t).indexOf(e):-1}isHidden(t){return this.hidden.get(t)??false}isWorn(t){return this.part(t)!==null&&!this.isHidden(t)}color(t){return this.colors.get(t)??null}wornSkins(){let t=new Map;for(let a of this.rig.partTypes)t.set(a.id,!a.auto&&this.isWorn(a.id)?this.part(a.id):null);let e={worn:a=>t.get(a)??null,setWorn:(a,h)=>t.set(a,h),exists:a=>this.rig.data.skins.has(a)&&this.drawable(a),race:()=>this.race(),types:()=>this.rig.partTypes.map(a=>a.id)};for(let a of this.rig.rules)a.apply(e);let o=this.rig.expressions,n=this.face??this.emotionFace,r=n?o?.faces[n]:void 0;for(let[a,h]of Object.entries(r??{}))t.get(a)&&e.exists(h)&&t.set(a,h);let s=this.speech!=="rest"?o?.speech:void 0,i=s?.visemes[this.speech];s&&i&&t.get(s.type)&&e.exists(i)&&t.set(s.type,i);let c=[];for(let a of this.rig.partTypes){let h=t.get(a.id);h&&c.push(h);}return c}slotColor(t){let e=this.slotTarget[t];return e?this.color(e):null}artColor(t){let e=this.slotArt[t];return e?this.color(e):null}bodyLook(){return {...this.body}}race(){return this.rig.races?.get(this.body.race)??null}expression(){return this.face}equip(t,e){let o=this.lists.get(t);if(!o)return;let n;if(e===null||e===-1)n=null;else if(typeof e=="number")n=o[Math.max(0,Math.min(o.length-1,e))]??null;else if(o.includes(e))n=e;else return;n===null&&!this.typeDef(t)?.canHide||(this.chosen.set(t,n),this.emit({kind:"part",type:t,skin:n}));}unequip(t){this.equip(t,null);}setHidden(t,e){this.typeDef(t)?.canHide&&(this.hidden.set(t,e),this.emit({kind:"hidden",type:t,hidden:e}));}next(t){let e=this.count(t);if(!e)return;let o=this.index(t);this.typeDef(t)?.canHide?this.equip(t,o>=e-1?-1:o+1):this.equip(t,(o+1)%e);}prev(t){let e=this.count(t);if(!e)return;let o=this.index(t);this.typeDef(t)?.canHide?this.equip(t,o<=-1?e-1:o-1):this.equip(t,(o-1+e)%e);}setColor(t,e){this.colors.set(t,e),this.emit({kind:"color",target:t,color:e});}setExpression(t){let e=t&&this.rig.expressions?.faces[t]?t:null;e!==this.face&&(this.face=e,this.emit({kind:"expression",name:e}));}setEmotion(t){let e=this.rig.expressions?.emotions?.[t]??null,o=e&&this.rig.expressions?.faces[e]?e:null;o!==this.emotionFace&&(this.emotionFace=o,this.emit({kind:"expression",name:this.face??o}));}setSpeech(t){t!==this.speech&&(this.speech=t,this.emit({kind:"speech",viseme:t}));}setBody(t){let e=this.race();if(this.body={...t},this.body.race!==e?.id){this.dropRaceColors();let o=new Map(this.colors);this.fitRaceColors(false),this.rememberRaceColors(o);}this.emit({kind:"body",body:this.bodyLook()});}setRace(t){let e={...this.body};t?e.race=t:delete e.race,this.setBody(e);}randomize(t=Math.random){for(let e of this.rig.partTypes){if(e.auto)continue;let o=this.count(e.id);o&&this.equip(e.id,e.canHide&&t()<.3?-1:Math.floor(t()*o));}}reset(){this.init();for(let t of this.rig.partTypes)this.emit({kind:"part",type:t.id,skin:this.part(t.id)});}toLook(){let t={};for(let n of this.rig.partTypes)n.auto||(t[n.id]=this.isWorn(n.id)?this.part(n.id):null);let e={};for(let[n,r]of this.colors)r&&(e[n]=r);let o=this.bodyLook();return {v:2,parts:t,colors:e,...Object.keys(o).length?{body:o}:{}}}applyLook(t){let e=this.race(),o=!!t.body&&t.body.race!==e?.id;o&&this.dropRaceColors();let n=new Map(this.colors);for(let[r,s]of Object.entries(t.parts??{}))s===void 0||this.typeDef(r)?.auto||(this.equip(r,s),s!==null&&this.part(r)===s&&this.hidden.set(r,false));for(let[r,s]of Object.entries(t.colors??{}))s&&this.setColor(r,s);t.body&&(this.body={...this.body,...t.body},o&&(this.fitRaceColors(true,t),this.rememberRaceColors(n)),this.emit({kind:"body",body:this.bodyLook()}));}dropRaceColors(){for(let[t,e]of this.raceGiven)this.color(t)?.toLowerCase()===e.toLowerCase()&&this.setColor(t,this.raceSaved.get(t)??null);this.raceGiven.clear(),this.raceSaved.clear();}rememberRaceColors(t){let e=this.race();if(!e)return;let o=new Set(Object.keys(e.colors??{}));e.skin?.length&&o.add(this.rig.skinColor??"Skin");for(let n of o){let r=this.color(n);!r||r===(t.get(n)??null)||(this.raceSaved.set(n,t.get(n)??null),this.raceGiven.set(n,r));}}fitRaceColors(t,e){let o=this.race();if(!o)return;for(let[i,c]of Object.entries(o.colors??{}))(t?e?.colors?.[i]:this.color(i))||this.setColor(i,c);let n=this.rig.skinColor??"Skin",r=this.color(n),s=t?e?.colors?.[n]??r:r;o.skin?.length&&(!s||!Yt(o,s))&&this.setColor(n,o.skin[0]);}rebuildLists(){for(let t of this.rig.partTypes)this.lists.set(t.id,this.rig.data.skinOrder.filter(e=>e.startsWith(t.skinPrefix)&&this.drawable(e)));}first(t){return this.lists.get(t.id)?.[0]??null}init(){this.chosen.clear(),this.hidden.clear(),this.colors.clear(),this.body={},this.raceSaved.clear(),this.raceGiven.clear();for(let t of this.rig.partTypes)this.chosen.set(t.id,t.auto?null:this.first(t));}};var U=Math.PI/180,ut=1e-5,nt=class{constructor(t){this.bone=t;}bone;x=0;y=0;rotation=0;scaleX=1;scaleY=1;shearX=0;shearY=0;a=1;b=0;c=0;d=1;worldX=0;worldY=0;world=0;local=0;copyLocal(t){this.x=t.x,this.y=t.y,this.rotation=t.rotation,this.scaleX=t.scaleX,this.scaleY=t.scaleY,this.shearX=t.shearX,this.shearY=t.shearY;}update(t){this.world!==t.updateId&&this.updateWorldTransform(t);}updateWorldTransform(t){this.local===t.updateId?this.updateLocalTransform(t):this.world=t.updateId;let e=(this.rotation+this.shearX)*U,o=(this.rotation+90+this.shearY)*U,n=Math.cos(e)*this.scaleX,r=Math.cos(o)*this.scaleY,s=Math.sin(e)*this.scaleX,i=Math.sin(o)*this.scaleY,c=this.bone.parent;if(!c){let h=t.scaleX,d=t.scaleY;this.a=n*h,this.b=r*h,this.c=s*d,this.d=i*d,this.worldX=this.x*h+t.x,this.worldY=this.y*d+t.y;return}let a=c.applied;this.worldX=a.a*this.x+a.b*this.y+a.worldX,this.worldY=a.c*this.x+a.d*this.y+a.worldY,this.a=a.a*n+a.b*s,this.b=a.a*r+a.b*i,this.c=a.c*n+a.d*s,this.d=a.c*r+a.d*i;}updateLocalTransform(t){this.local=0,this.world=t.updateId;let e=this.bone.parent;if(!e){this.x=(this.worldX-t.x)/t.scaleX,this.y=(this.worldY-t.y)/t.scaleY,this.set5(this.a/t.scaleX,this.b/t.scaleX,this.c/t.scaleY,this.d/t.scaleY);return}let o=e.applied,n=1/(o.a*o.d-o.b*o.c),r=o.d*n,s=o.b*n,i=o.c*n,c=o.a*n,a=this.worldX-o.worldX,h=this.worldY-o.worldY;this.x=a*r-h*s,this.y=h*c-a*i,this.set5(r*this.a-s*this.c,r*this.b-s*this.d,c*this.c-i*this.a,c*this.d-i*this.b);}set5(t,e,o,n){this.shearX=0;let r=t*t+o*o,s=e*e+n*n;if(r>ut){let i=Math.atan2(o,t)/U;this.rotation=i,this.scaleX=Math.sqrt(r),this.scaleY=Math.sqrt(s),s>ut?(this.shearY=Math.atan2(n,e)/U,t*n-e*o<0?(this.scaleY=-this.scaleY,this.shearY+=90-i):this.shearY-=90+i,this.shearY>180?this.shearY-=360:this.shearY<=-180&&(this.shearY+=360)):this.shearY=0;}else this.scaleX=0,this.scaleY=Math.sqrt(s),this.shearY=0,this.rotation=s>ut?Math.atan2(n,e)/U-90:0;}modifyLocal(t){this.local===t.updateId&&this.updateLocalTransform(t),this.world=0,this.resetWorld(t);}modifyWorld(t){this.local=t.updateId,this.world=t.updateId,this.resetWorld(t);}resetWorld(t){for(let e of this.bone.children){let o=e.applied;o.world===t.updateId&&(o.local===t.updateId&&o.updateLocalTransform(t),o.world=0,o.resetWorld(t));}}},rt=class{constructor(t){this.data=t;this.pose=new nt(this),this.applied=new nt(this),this.setupPose();}data;pose;applied;parent=null;children=[];sorted=false;setupPose(){let t=this.data,e=this.pose;e.x=t.x,e.y=t.y,e.rotation=t.rotation,e.scaleX=t.scaleX,e.scaleY=t.scaleY,e.shearX=0,e.shearY=0;}},ft=class{constructor(t,e){this.data=t;this.bone=e;this.color={...t.color},this.attachmentKey=t.attachment;}data;bone;color;attachmentKey;attachment=null},E=class{constructor(t){this.data=t;this.bones=t.bones.map(e=>new rt(e));for(let e of this.bones)e.data.parent&&(e.parent=this.bones[e.data.parent.index],e.parent.children.push(e));this.slots=t.slots.map(e=>new ft(e,this.bones[e.bone.index])),this.constraints=t.constraints.map(e=>St(e,this)),this.updateCache();}data;bones;slots;constraints;skins=[];scaleX=1;scaleY=1;x=0;y=0;updateId=0;cache=[];bone(t){return this.bones[this.data.bone(t).index]}slot(t){return this.slots[this.data.slot(t).index]}setSkins(t){this.skins=[...t],this.resolveAttachments();}getAttachment(t,e){for(let o=this.skins.length-1;o>=0;o--){let n=this.skins[o].attachments.get(t)?.get(e);if(n)return n}return null}resolveAttachments(){for(let t of this.slots)t.attachment=t.attachmentKey?this.getAttachment(t.data.index,t.attachmentKey):null;}setupPose(){for(let t of this.bones)t.setupPose();for(let t of this.constraints)t.setupPose();for(let t of this.slots)Object.assign(t.color,t.data.color),t.attachmentKey=t.data.attachment;}updateWorldTransform(){this.updateId++;for(let t of this.bones)t.applied.copyLocal(t.pose),t.applied.world=0,t.applied.local=0;for(let t of this.cache)t instanceof rt?t.applied.update(this):t.update(this);}updateCache(){this.cache=[];for(let t of this.bones)t.sorted=false;for(let t of this.constraints)t.sort(this);for(let t of this.bones)this.sortBone(t);}sortBone(t){t.sorted||(t.parent&&this.sortBone(t.parent),t.sorted=true,this.cache.push(t));}sortReset(t){for(let e of t)e.sorted&&this.sortReset(e.children),e.sorted=false;}pushConstraint(t){this.cache.push(t);}};var Rt=new WeakMap;function Xt(l,t){let e=Rt.get(l);if(e)return e;e=new Map;let o=new E(l);o.setupPose(),o.updateWorldTransform();let[n,r]=t.light;for(let s of l.skins.values())for(let[i,c]of s.attachments)for(let a of c.values()){if(e.has(a.path)||t.skip?.some(p=>a.path.startsWith(p)))continue;let h=et(o,o.slots[i],a,null),d=qt(h.positions,h.uvs,a.width,a.height);if(!d)continue;let u=d.a*d.d-d.b*d.c;if(Math.abs(u)<1e-9)continue;let f=(d.d*n-d.b*r)/u,m=(-d.c*n+d.a*r)/u,y=Math.hypot(f,m)||1;e.set(a.path,{x:f/y,y:m/y});}return Rt.set(l,e),e}function qt(l,t,e,o){let n=t.length/2;if(n<3)return null;let r=0,s=0,i=0,c=0;for(let g=0;g<n;g++)r+=t[g*2]*e,s+=t[g*2+1]*o,i+=l[g*2],c+=l[g*2+1];r/=n,s/=n,i/=n,c/=n;let a=0,h=0,d=0,u=0,f=0,m=0,y=0;for(let g=0;g<n;g++){let v=t[g*2]*e-r,b=t[g*2+1]*o-s,X=l[g*2]-i,L=l[g*2+1]-c;a+=v*v,h+=v*b,d+=b*b,u+=X*v,f+=X*b,m+=L*v,y+=L*b;}let p=a*d-h*h;return Math.abs(p)<1e-9?null:{a:(u*d-f*h)/p,b:(f*a-u*h)/p,c:(m*d-y*h)/p,d:(y*a-m*h)/p}}var j=class{constructor(t,e){this.scene=t;let o=this.rig=e.rig;this.art=e.art,this.skeleton=new E(o.data),this.sizes=Ct(o.data),this.lights=o.shading?Xt(o.data,o.shading):new Map,this.parts=new ot(o,n=>this.drawsSkin(n)),e.look&&this.parts.applyLook(e.look),this.offs.push(this.parts.on(()=>this.skinsDirty=true)),this.animator=new tt(this.skeleton,o.data,o.mix),this.animator.setBlink(o.blink??null),this.play(e.animation??o.defaultAnimation,{mix:0}),this.root=t.add.container(e.x??0,e.y??0);for(let n=0;n<this.skeleton.slots.length;n++){let r=new F__default.default.GameObjects.Mesh2D(t,0,0,"__DEFAULT",[],[],true);r.setRenderAsTriangles(true),r.setVisible(false),this.root.add(r),this.slots.push({mesh:r,positions:null,vertices:[],indices:[],path:null,key:null,paint:null,waiting:false});}if(this.setScale(e.scale??1),e.autoUpdate!==false){let n=(r,s)=>this.update(s/1e3);t.events.on(F__default.default.Scenes.Events.UPDATE,n),this.offs.push(()=>t.events.off(F__default.default.Scenes.Events.UPDATE,n));}this.root.once(F__default.default.GameObjects.Events.DESTROY,()=>{for(let n of this.offs.splice(0))n();}),this.update(0);}scene;root;skeleton;animator;parts;slots=[];sizes;lights;skinsDirty=true;overlay=null;flashUntil=0;flashColor=16777215;facing=1;size=1;offs=[];asked=null;rig;art;play(t,e){return this.asked={name:t,...e?{options:e}:{}},this.animator.play(this.stanceOf(t),e)}animation(){return this.asked?.name??null}stanceOf(t){let e=this.parts;return this.rig.stance?.(t,o=>e.isWorn(o)?e.part(o):null)??t}on(t,e){let o=this.animator.on(t,e);return this.offs.push(o),o}setLook(t){this.parts.applyLook(t);}setArt(t){this.art=t;for(let e of this.slots)e.key=e.path=null,e.waiting=false;this.parts.setDrawable(e=>this.drawsSkin(e));}setPosition(t,e){return this.root.setPosition(t,e),this}setScale(t){return this.size=t,this.root.setScale(t*this.facing,t),this}setFacing(t){return this.facing=t,this.setScale(this.size)}setDepth(t){return this.root.setDepth(t),this}setVisible(t){return this.root.setVisible(t),this}setAlpha(t){return this.root.setAlpha(t),this}setOverlay(t){return this.overlay=t,this}flash(t=16777215,e=90){this.flashColor=t,this.flashUntil=this.scene.time.now+e;}worldPoint(t){let e=this.rig.anchors[t]??t,o=this.skeleton.bone(e).applied,n=this.root.getWorldTransformMatrix();return {x:n.tx+n.a*o.worldX+n.c*-o.worldY,y:n.ty+n.b*o.worldX+n.d*-o.worldY}}get displayHeight(){return this.rig.data.height*this.size}destroy(){this.root.destroy();}update(t){let e=this.skeleton,o=this.rig.expressions;if(o&&this.parts.setExpression(o.byAnimation[this.animator.current()??""]??null),this.skinsDirty){this.skinsDirty=false,e.setSkins(this.parts.wornSkins().flatMap(s=>{let i=this.rig.data.skins.get(s);return i?[i]:[]}));let r=this.asked;r&&this.stanceOf(r.name)!==this.animator.current()&&this.animator.play(this.stanceOf(r.name),{...r.options,mix:.15});}this.animator.update(t),e.slots.forEach((r,s)=>{let i=this.parts.slotColor(s);if(!i)return;let c=Pt(i);r.color.r=(c>>16&255)/255,r.color.g=(c>>8&255)/255,r.color.b=(c&255)/255,r.color.a=1;}),e.updateWorldTransform();let n=this.flashUntil>this.scene.time.now;e.slots.forEach((r,s)=>this.drawSlot(s,n));}drawSlot(t,e){let o=this.slots[t],n=this.skeleton.slots[t],r=n.attachment,s=o.mesh;if(!r||n.color.a<=0){s.setVisible(false);return}let i=this.parts.artColor(t);if((o.path!==r.path||o.paint!==i)&&(o.path=r.path,o.paint=i,o.key=null,o.waiting=false),!o.key&&!o.waiting){let p=this.sizes.get(r.path)??{w:r.width,h:r.height},g=r.path,v=this.art.texture(g,p,()=>{o.path===g&&(o.waiting=false);},{paint:i,light:this.lights.get(g)??null});v?(o.key=v,s.setTexture(v)):o.waiting=true;}if(!o.key){s.setVisible(false);return}let c=et(this.skeleton,n,r,o.positions);o.positions=c.positions;let a=c.uvs.length/2,h=o.vertices;h.length=a*4;for(let p=0;p<a;p++)h[p*4]=c.positions[p*2],h[p*4+1]=-c.positions[p*2+1],h[p*4+2]=c.uvs[p*2],h[p*4+3]=c.uvs[p*2+1];let d=c.triangles,u=o.indices;if(u.length!==d.length/3*4){u.length=0;for(let p=0;p<d.length;p+=3)u.push(d[p],d[p+1],d[p+2],0);}else for(let p=0,g=0;p<d.length;p+=3,g+=4)u[g]=d[p],u[g+1]=d[p+1],u[g+2]=d[p+2];s.vertices=h,s.indices=u;let f=n.color,m=r.color,y=Math.round(f.r*m.r*255)<<16|Math.round(f.g*m.g*255)<<8|Math.round(f.b*m.b*255);this.overlay!==null&&(y=Vt(y,this.overlay)),e?s.setTint(this.flashColor).setTintMode(F__default.default.TintModes.FILL):s.setTint(y).setTintMode(F__default.default.TintModes.MULTIPLY),s.setAlpha(f.a*m.a),s.setVisible(true);}drawsSkin(t){return It(this.rig.data,t).every(e=>this.art.has(e))}};function Vt(l,t){let e=o=>Math.round((l>>o&255)*(t>>o&255)/255)<<o;return e(16)|e(8)|e(0)}function Lt(l,t,e=1,o={}){let n=Math.max(1,Math.ceil(t.w*e)),r=Math.max(1,Math.ceil(t.h*e)),s=o.paint??l.paint,i=o.light?Ut(t,o.light):"";return `<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${r}" viewBox="0 0 ${t.w} ${t.h}"${s?` color="${s}"`:""}>${i}<g stroke-linejoin="round" stroke-linecap="round"${i?' filter="url(#cel)"':""}>${l.svg}</g></svg>`}var J={depth:.18,min:2.6,max:11,dark:.3,shine:.36};function Ut(l,t){let e=Math.max(J.min,Math.min(J.max,Math.min(l.w,l.h)*J.depth)),o=n=>+n.toFixed(2);return `<defs><filter id="cel" filterUnits="userSpaceOnUse" x="0" y="0" width="${l.w}" height="${l.h}" color-interpolation-filters="sRGB"><feMorphology in="SourceAlpha" operator="erode" radius="${o(3.6*.7)}" result="body"/><feOffset in="body" dx="${o(t.x*e)}" dy="${o(t.y*e)}" result="moved"/><feComposite in="body" in2="moved" operator="out" result="far"/><feFlood flood-color="#000000" flood-opacity="${J.dark}"/><feComposite in2="far" operator="in" result="dark"/><feMorphology in="SourceAlpha" operator="erode" radius="${o(3.6*1.05)}" result="inner"/><feOffset in="inner" dx="${o(-t.x*e*.42)}" dy="${o(-t.y*e*.42)}" result="back"/><feComposite in="inner" in2="back" operator="out" result="near"/><feFlood flood-color="#ffffff" flood-opacity="${J.shine}"/><feComposite in2="near" operator="in" result="shine"/><feMerge><feMergeNode in="SourceGraphic"/><feMergeNode in="dark"/><feMergeNode in="shine"/></feMerge></filter></defs>`}var Bt=new WeakMap;function jt(l,t,e){return `chr:${l}@${t}${e||""}`}function $t(l,t,e,o,n,r,s={}){let i=e.paint?s.paint??null:null,c=jt(t,n,i);if(l.exists(c))return c;let a=Bt.get(l);a||Bt.set(l,a=new Map);let h=a.get(c);if(h)return h.push(r),null;let d=[r];a.set(c,d);let u=new Image,f=()=>{a.delete(c);for(let m of d)m();};return u.onload=()=>{l.exists(c)||l.addImage(c,u),f();},u.onerror=()=>{console.warn(`[character] art ${t} did not render`),f();},u.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(Lt(e,o,n,{paint:i,light:s.light??null})),null}function mt(l,t,e=2){return {has:o=>t.has(o),texture(o,n,r,s){let i=t.get(o);return i?$t(l,o,i,n,e,r,s):null}}}function Jt(l,t){return new Promise(e=>{let{width:o,height:n}=t,r=Math.min(2,Math.max(1,typeof devicePixelRatio=="number"&&devicePixelRatio||1));class s extends F__default.default.Scene{create(){this.cameras.main.setOrigin(0,0).setZoom(r);let a=t.scale??1,h=mt(this.textures,t.catalog,Math.max(2,Math.ceil(a*r*1.5))),d=new j(this,{rig:t.rig,art:h,...t.look?{look:t.look}:{},x:o/2,y:Math.round(n*.88),scale:a});e({view:d,game:i,vector:h,destroy:()=>i.destroy(true)});}}let i=new F__default.default.Game({type:F__default.default.WEBGL,parent:l,width:Math.ceil(o*r),height:Math.ceil(n*r),scale:{mode:F__default.default.Scale.NONE,zoom:1/r},render:{autoMobileTextures:false},transparent:!t.background,...t.background?{backgroundColor:t.background}:{},scene:s,banner:false,audio:{noAudio:true}});})}
2
+ exports.CharacterView=j;exports.createCharacterStage=Jt;exports.vectorArt=mt;
@@ -1,5 +1,5 @@
1
1
  import Phaser from 'phaser';
2
- import { h as ArtStyle, A as ArtCatalog, S as Skeleton, a as Animator, P as PartsManager, R as RigDef, C as CharacterLook, b as PlayOptions, c as AnimationEvent } from '../../PartsManager-Cn3MU-VS.cjs';
2
+ import { i as ArtStyle, A as ArtCatalog, S as Skeleton, a as Animator, P as PartsManager, R as RigDef, C as CharacterLook, b as PlayOptions, c as AnimationEvent } from '../../PartsManager-CmrzoyJR.cjs';
3
3
  import '../../contract-DhZuKNIf.cjs';
4
4
 
5
5
  interface ArtSource {
@@ -1,5 +1,5 @@
1
1
  import Phaser from 'phaser';
2
- import { h as ArtStyle, A as ArtCatalog, S as Skeleton, a as Animator, P as PartsManager, R as RigDef, C as CharacterLook, b as PlayOptions, c as AnimationEvent } from '../../PartsManager-CAVBKvp6.js';
2
+ import { i as ArtStyle, A as ArtCatalog, S as Skeleton, a as Animator, P as PartsManager, R as RigDef, C as CharacterLook, b as PlayOptions, c as AnimationEvent } from '../../PartsManager-BpAUMQXw.js';
3
3
  import '../../contract-DhZuKNIf.js';
4
4
 
5
5
  interface ArtSource {
@@ -1 +1 @@
1
- export{a as CharacterView,c as createCharacterStage,b as vectorArt}from'../../chunk-2GCXXAHU.js';import'../../chunk-OF4BH3JZ.js';
1
+ export{a as CharacterView,c as createCharacterStage,b as vectorArt}from'../../chunk-SDZXML7V.js';import'../../chunk-UUX4NEC2.js';
@@ -1,2 +1,2 @@
1
- 'use strict';var y=require('three');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var y__namespace=/*#__PURE__*/_interopNamespace(y);function vt(l){let t=l>>>0;return function(){t|=0,t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}function wt(l,t,e=1,n={}){let o=Math.max(1,Math.ceil(t.w*e)),r=Math.max(1,Math.ceil(t.h*e)),i=n.paint??l.paint,s=n.light?$t(t,n.light):"";return `<svg xmlns="http://www.w3.org/2000/svg" width="${o}" height="${r}" viewBox="0 0 ${t.w} ${t.h}"${i?` color="${i}"`:""}>${s}<g stroke-linejoin="round" stroke-linecap="round"${s?' filter="url(#cel)"':""}>${l.svg}</g></svg>`}var V={depth:.18,min:2.6,max:11,dark:.3,shine:.36};function $t(l,t){let e=Math.max(V.min,Math.min(V.max,Math.min(l.w,l.h)*V.depth)),n=o=>+o.toFixed(2);return `<defs><filter id="cel" filterUnits="userSpaceOnUse" x="0" y="0" width="${l.w}" height="${l.h}" color-interpolation-filters="sRGB"><feMorphology in="SourceAlpha" operator="erode" radius="${n(3.6*.7)}" result="body"/><feOffset in="body" dx="${n(t.x*e)}" dy="${n(t.y*e)}" result="moved"/><feComposite in="body" in2="moved" operator="out" result="far"/><feFlood flood-color="#000000" flood-opacity="${V.dark}"/><feComposite in2="far" operator="in" result="dark"/><feMorphology in="SourceAlpha" operator="erode" radius="${n(3.6*1.05)}" result="inner"/><feOffset in="inner" dx="${n(-t.x*e*.42)}" dy="${n(-t.y*e*.42)}" result="back"/><feComposite in="inner" in2="back" operator="out" result="near"/><feFlood flood-color="#ffffff" flood-opacity="${V.shine}"/><feComposite in2="near" operator="in" result="shine"/><feMerge><feMergeNode in="SourceGraphic"/><feMergeNode in="dark"/><feMergeNode in="shine"/></feMerge></filter></defs>`}var R=Math.PI/180,lt=1e-5;function Mt(l,t){return l.type==="ik"?new L(l,t):new ht(l,t)}var ct=l=>l>180?l-360:l<=-180?l+360:l,L=class{constructor(t,e){this.data=t;this.bones=t.bones.map(n=>e.bones[n.index]),this.target=e.bones[t.target.index],this.mix=t.mix,this.bendDirection=t.bendDirection;}data;mix;bendDirection;bones;target;setupPose(){this.mix=this.data.mix,this.bendDirection=this.data.bendDirection;}sort(t){t.sortBone(this.target);let e=this.bones[0];t.sortBone(e),t.pushConstraint(this),e.sorted=false,t.sortReset(e.children);}update(t){if(this.mix===0)return;let e=this.target.applied;this.bones.length===1?St(t,this.bones[0].applied,e.worldX,e.worldY,this.mix):Ht(t,this.bones[0].applied,this.bones[1].applied,e.worldX,e.worldY,this.bendDirection,this.mix);}};function St(l,t,e,n,o){let r=t.bone.parent;if(!r)return;t.modifyLocal(l);let i=r.applied,s=i.a,c=i.b,a=i.c,h=i.d,p=-t.shearX-t.rotation,m=s*h-c*a,u=e-i.worldX,f=n-i.worldY,b=(u*h-f*c)/m-t.x,g=(f*s-u*a)/m-t.y;p+=Math.atan2(g,b)/R,t.scaleX<0&&(p+=180),t.rotation+=ct(p)*o;}function Ht(l,t,e,n,o,r,i){t.modifyLocal(l),e.modifyLocal(l);let s=t.x,c=t.y,a=t.scaleX,h=t.scaleY,p=e.scaleX,m,u,f;a<0?(a=-a,m=180,f=-1):(m=0,f=1),h<0&&(h=-h,f=-f),p<0?(p=-p,u=180):u=0;let b=Math.abs(a-h)<=lt,g,d;b?(g=t.a*e.x+t.b*e.y+t.worldX,d=t.c*e.x+t.d*e.y+t.worldY):(e.y=0,g=t.a*e.x+t.worldX,d=t.c*e.x+t.worldY);let k=t.bone.parent;if(!k)return;let x=k.applied,P=x.a,S=x.b,st=x.c,rt=x.d,I=P*rt-S*st,F=g-x.worldX,W=d-x.worldY;I=Math.abs(I)<=lt?0:1/I;let mt=(F*rt-W*S)*I-s,ft=(W*P-F*st)*I-c,v=Math.sqrt(mt*mt+ft*ft),D=e.bone.data.length*p;if(v<lt){St(l,t,n,o,i),e.rotation=0;return}F=n-x.worldX,W=o-x.worldY;let N=(F*rt-W*S)*I-s,q=(W*P-F*st)*I-c,K=N*N+q*q,Y=0,T=0;if(b){D*=a;let w=(K-v*v-D*D)/(2*v*D);w<-1?(w=-1,T=Math.PI*r):w>1?(w=1,T=0):T=Math.acos(w)*r;let $=v+D*w,E=D*Math.sin(T);Y=Math.atan2(q*$-N*E,N*$+q*E);}else {let w=a*D,$=h*D,E=w*w,G=$*$,it=Math.atan2(q,N),M=G*v*v+E*K-E*G,z=-2*G*v,yt=G-E,bt=z*z-4*yt*M,xt=false;if(bt>=0){let A=Math.sqrt(bt);z<0&&(A=-A),A=-(z+A)*.5;let X=A/yt,H=M/A,B=Math.abs(X)<Math.abs(H)?X:H,U=K-B*B;if(U>=0){let C=Math.sqrt(U)*r;Y=it-Math.atan2(C,B),T=Math.atan2(C/h,(B-v)/a),xt=true;}}if(!xt){let A=Math.PI,X=v-w,H=X*X,B=0,U=0,C=v+w,at=C*C,kt=0;if(M=-w*v/(E-G),M>=-1&&M<=1){M=Math.acos(M);let j=w*Math.cos(M)+v,_=$*Math.sin(M),Q=j*j+_*_;Q<H&&(A=M,H=Q,X=j,B=_),Q>at&&(U=M,at=Q,C=j,kt=_);}K<=(H+at)*.5?(Y=it-Math.atan2(B*r,X),T=A*r):(Y=it-Math.atan2(kt*r,C),T=U*r);}}let gt=Math.atan2(e.y,e.x)*f;Y=ct((Y-gt)/R+m-t.rotation),T=ct(((T+gt)/R-e.shearX)*f+u-e.rotation),t.rotation+=Y*i,e.rotation+=T*i;}var ht=class{constructor(t,e){this.data=t;this.source=e.bones[t.source.index],this.bones=t.bones.map(n=>e.bones[n.index]),this.mix={...t.mix};}data;mix;source;bones;setupPose(){Object.assign(this.mix,this.data.mix);}sort(t){t.sortBone(this.source);for(let e of this.bones)t.sortBone(e);t.pushConstraint(this);for(let e of this.bones)t.sortReset(e.children);for(let e of this.bones)e.sorted=true;}update(t){let e=this.mix;if(!e.rotate&&!e.x&&!e.y&&!e.scaleX&&!e.scaleY&&!e.shearY)return;let n=this.source.applied,o=this.data.offsets;for(let r of this.bones){let i=r.applied;i.modifyWorld(t);for(let s of this.data.properties){let c=Lt(t,n,s.prop,o)-s.offset;for(let a of s.to){let h=e[a.prop];h!==0&&Ot(t,i,a.prop,a.offset+c*a.scale,h);}}}}};function Lt(l,t,e,n){let o=l.scaleX,r=l.scaleY;switch(e){case "rotate":{let i=(t.a*t.d-t.b*t.c)*o*r>0?1:-1,s=Math.atan2(t.c/r,t.a/o)/R+i*n.rotate;return s<0&&(s+=360),s}case "x":return (n.x*t.a+n.y*t.b+t.worldX)/o;case "y":return (n.x*t.c+n.y*t.d+t.worldY)/r;case "scaleX":return Math.hypot(t.a/o,t.c/r)+n.scaleX;case "scaleY":return Math.hypot(t.b/o,t.d/r)+n.scaleY;case "shearY":return (Math.atan2(t.d/r,t.b/o)-Math.atan2(t.c/r,t.a/o))/R-90+n.shearY}}function Ot(l,t,e,n,o){let r=l.scaleX,i=l.scaleY;switch(e){case "rotate":{let s=t.a/r,c=t.b/r,a=t.c/i,h=t.d/i,p=n*R-Math.atan2(a,s);p>Math.PI?p-=2*Math.PI:p<-Math.PI&&(p+=2*Math.PI),p*=o;let m=Math.cos(p),u=Math.sin(p);t.a=(m*s-u*a)*r,t.b=(m*c-u*h)*r,t.c=(u*s+m*a)*i,t.d=(u*c+m*h)*i;return}case "x":t.worldX+=(n-t.worldX/r)*o*r;return;case "y":t.worldY+=(n-t.worldY/i)*o*i;return;case "scaleX":{let s=Math.hypot(t.a/r,t.c/i);s!==0&&(s=1+(n-s)*o/s,t.a*=s,t.c*=s);return}case "scaleY":{let s=Math.hypot(t.b/r,t.d/i);s!==0&&(s=1+(n-s)*o/s,t.b*=s,t.d*=s);return}case "shearY":{let s=t.b/r,c=t.d/i,a=Math.atan2(c,s),h=(n+90)*R;h-=a-Math.atan2(t.c/i,t.a/r),h>Math.PI?h-=2*Math.PI:h<-Math.PI&&(h+=2*Math.PI),h=a+h*o;let p=Math.hypot(s,c);t.b=Math.cos(h)*p*r,t.d=Math.sin(h)*p*i;return}}}var Z=class{constructor(t,e,n=.2){this.skeleton=t;this.data=e;this.defaultMix=n;this.snapshot=new Float32Array(t.bones.length*5),this.slotSnapshot=new Float32Array(t.slots.length*4),this.ikSnapshot=new Float32Array(t.constraints.length);}skeleton;data;defaultMix;track=null;previous=null;mixTime=0;mixDuration=0;listeners=new Map;snapshot;slotSnapshot;ikSnapshot;blink=null;setBlink(t){let e=t?this.data.animations.get(t.animation):void 0;if(!t||!e){this.blink=null;return}let n={bones:new Set(t.bones.map(o=>this.data.bone(o).index)),slots:new Set(t.slots.map(o=>this.data.slot(o).index))};this.blink={source:e,filter:n,options:t,wait:this.nextBlink(t),at:-1};}blinkNow(){this.blink&&(this.blink.at=0);}blinking(){return (this.blink?.at??-1)>=0}setRandom(t){this.random=t;}random=Math.random;nextBlink(t){return t.every[0]+this.random()*(t.every[1]-t.every[0])}names(){return [...this.data.animations.keys()]}has(t){return this.data.animations.has(t)}play(t,e={}){let n=this.data.animations.get(t);if(!n)return false;let o=e.mix??this.defaultMix;return this.previous=this.track&&o>0?this.track:null,this.mixTime=0,this.mixDuration=this.previous?o:0,this.track={animation:n,time:Math.max(0,e.from??0),speed:e.speed??1,loop:e.loop??true,done:false},true}current(){return this.track?.animation.name??null}time(){return this.track?this.local(this.track):0}duration(){return this.track?.animation.duration??0}finished(){return this.track?.done??false}setSpeed(t){this.track&&(this.track.speed=t);}on(t,e){let n=this.listeners.get(t)??new Set;return n.add(e),this.listeners.set(t,n),()=>n.delete(e)}update(t){let e=[],n=this.track;if(n&&!n.done){let o=n.time;n.time+=Math.max(0,t)*n.speed,this.collect(n,o,n.time,e),!n.loop&&n.time>=n.animation.duration&&(n.time=n.animation.duration,n.done=true,e.push({name:"end",animation:n.animation.name}));}if(this.previous){let o=this.previous;o.time+=Math.max(0,t)*o.speed,this.mixTime+=Math.max(0,t),this.mixTime>=this.mixDuration&&(this.previous=null);}this.advanceBlink(Math.max(0,t)),this.pose();for(let o of e){for(let r of this.listeners.get(o.name)??[])r(o);for(let r of this.listeners.get("*")??[])r(o);}}pose(){let t=this.skeleton,e=this.previous;e&&this.mixDuration>0&&(t.setupPose(),e.animation.apply(t,this.local(e)),this.save()),t.setupPose(),this.track&&this.track.animation.apply(t,this.local(this.track)),e&&this.mixDuration>0&&this.blendFromSaved(Math.min(1,this.mixTime/this.mixDuration));let n=this.blink;n&&n.at>=0&&n.source.applyOnly(t,n.options.from+n.at,n.filter),t.resolveAttachments();}advanceBlink(t){let e=this.blink;if(e){if(this.track?.animation.touches(e.filter)){e.at=-1;return}if(e.at>=0){e.at+=t,e.at>=e.options.to-e.options.from&&(e.at=-1,e.wait=this.nextBlink(e.options));return}e.wait-=t,e.wait<=0&&(e.at=0);}}local(t){let e=t.animation.duration;return e<=0?0:t.loop?t.time%e:Math.min(t.time,e)}collect(t,e,n,o){let r=t.animation.duration;if(r<=0||n<=e)return;let i=Math.floor(e/r),s=t.loop?Math.floor(n/r):0;for(let c=i;c<=s;c++)for(let a of t.animation.events){let h=c*r+a.time;h>=e&&(h<n||!t.loop&&h<=n)&&o.push({name:a.name,animation:t.animation.name});}}save(){let t=this.skeleton;t.bones.forEach((e,n)=>{let o=e.pose;this.snapshot.set([o.x,o.y,o.rotation,o.scaleX,o.scaleY],n*5);}),t.slots.forEach((e,n)=>this.slotSnapshot.set([e.color.r,e.color.g,e.color.b,e.color.a],n*4)),t.constraints.forEach((e,n)=>{e instanceof L&&(this.ikSnapshot[n]=e.mix);});}blendFromSaved(t){let e=this.skeleton,n=(o,r)=>o+(r-o)*t;e.bones.forEach((o,r)=>{let i=this.snapshot,s=o.pose,c=r*5;s.x=n(i[c],s.x),s.y=n(i[c+1],s.y);let a=s.rotation-i[c+2];a-=Math.round(a/360)*360,s.rotation=i[c+2]+a*t,s.scaleX=n(i[c+3],s.scaleX),s.scaleY=n(i[c+4],s.scaleY);}),e.slots.forEach((o,r)=>{let i=this.slotSnapshot;o.color.r=n(i[r*4],o.color.r),o.color.g=n(i[r*4+1],o.color.g),o.color.b=n(i[r*4+2],o.color.b),o.color.a=n(i[r*4+3],o.color.a);}),e.constraints.forEach((o,r)=>{o instanceof L&&(o.mix=n(this.ikSnapshot[r],o.mix));});}};var Tt=Math.PI/180,Ft=new Float32Array([0,1,0,0,1,0,1,1]),Wt=new Uint16Array([0,1,2,2,3,0]),Pt=new WeakMap;function Nt(l){let t=Pt.get(l);if(t)return t;let e=-l.width/2*l.scaleX,n=-l.height/2*l.scaleY,o=l.width/2*l.scaleX,r=l.height/2*l.scaleY,i=Math.cos(l.rotation*Tt),s=Math.sin(l.rotation*Tt),c=(a,h)=>[a*i-h*s+l.x,a*s+h*i+l.y];return t=Float32Array.from([...c(e,n),...c(e,r),...c(o,r),...c(o,n)]),Pt.set(l,t),t}function tt(l,t,e,n){if(e.type==="region"){let o=n&&n.length===8?n:new Float32Array(8),r=Nt(e),i=t.bone.applied;for(let s=0;s<8;s+=2){let c=r[s],a=r[s+1];o[s]=c*i.a+a*i.b+i.worldX,o[s+1]=c*i.c+a*i.d+i.worldY;}return {positions:o,uvs:Ft,triangles:Wt}}return qt(l,t,e,n)}function qt(l,t,e,n){let o=e.vertexCount*2,r=n&&n.length===o?n:new Float32Array(o),i=e.vertices;if(e.weighted){let s=0;for(let c=0;c<o;c+=2){let a=i[s++],h=0,p=0;for(let m=0;m<a;m++,s+=4){let u=l.bones[i[s]].applied,f=i[s+1],b=i[s+2],g=i[s+3];h+=(f*u.a+b*u.b+u.worldX)*g,p+=(f*u.c+b*u.d+u.worldY)*g;}r[c]=h,r[c+1]=p;}}else {let s=t.bone.applied;for(let c=0;c<o;c+=2){let a=i[c],h=i[c+1];r[c]=a*s.a+h*s.b+s.worldX,r[c+1]=a*s.c+h*s.d+s.worldY;}}return {positions:r,uvs:e.uvs,triangles:e.triangles}}function At(l){let t=/^#?([0-9a-f]{6})$/i.exec(l.trim());return t?parseInt(t[1],16):16777215}var Dt=new WeakMap;function It(l){let t=Dt.get(l);if(t)return t;t=new Map;for(let e of l.skins.values())for(let n of e.attachments.values())for(let o of n.values())t.has(o.path)||t.set(o.path,{w:o.width,h:o.height});return Dt.set(l,t),t}function Yt(l,t){let e=l.skins.get(t);if(!e)return [];let n=new Set;for(let o of e.attachments.values())for(let r of o.values())n.add(r.path);return [...n]}var et=class{constructor(t,e=()=>true){this.rig=t;this.drawable=e;let n=(o,r)=>t.colorTargets.find(i=>(i.into??"tint")===r&&i.slotPrefixes.some(s=>o.startsWith(s)))?.id??null;this.slotTarget=t.data.slots.map(o=>n(o.name,"tint")),this.slotArt=t.data.slots.map(o=>n(o.name,"art")),this.rebuildLists(),this.init();}rig;drawable;chosen=new Map;hidden=new Map;colors=new Map;lists=new Map;listeners=new Set;slotTarget;slotArt;face=null;emotionFace=null;speech="rest";setDrawable(t){let e=new Set(this.rig.partTypes.filter(n=>!this.count(n.id)).map(n=>n.id));this.drawable=t,this.rebuildLists();for(let n of this.rig.partTypes){if(n.auto)continue;let o=this.chosen.get(n.id);(o&&!this.lists.get(n.id).includes(o)||!o&&e.has(n.id))&&this.chosen.set(n.id,this.first(n));}this.emit({kind:"part",type:"*",skin:null});}on(t){return this.listeners.add(t),()=>this.listeners.delete(t)}emit(t){for(let e of [...this.listeners])e(t);}typeDef(t){return this.rig.partTypes.find(e=>e.id===t)}list(t){return this.lists.get(t)??[]}count(t){return this.list(t).length}part(t){return this.chosen.get(t)??null}index(t){let e=this.part(t);return e?this.list(t).indexOf(e):-1}isHidden(t){return this.hidden.get(t)??false}isWorn(t){return this.part(t)!==null&&!this.isHidden(t)}color(t){return this.colors.get(t)??null}wornSkins(){let t=new Map;for(let a of this.rig.partTypes)t.set(a.id,!a.auto&&this.isWorn(a.id)?this.part(a.id):null);let e={worn:a=>t.get(a)??null,setWorn:(a,h)=>t.set(a,h),exists:a=>this.rig.data.skins.has(a)&&this.drawable(a)};for(let a of this.rig.rules)a.apply(e);let n=this.rig.expressions,o=this.face??this.emotionFace,r=o?n?.faces[o]:void 0;for(let[a,h]of Object.entries(r??{}))t.get(a)&&e.exists(h)&&t.set(a,h);let i=this.speech!=="rest"?n?.speech:void 0,s=i?.visemes[this.speech];i&&s&&t.get(i.type)&&e.exists(s)&&t.set(i.type,s);let c=[];for(let a of this.rig.partTypes){let h=t.get(a.id);h&&c.push(h);}return c}slotColor(t){let e=this.slotTarget[t];return e?this.color(e):null}artColor(t){let e=this.slotArt[t];return e?this.color(e):null}expression(){return this.face}equip(t,e){let n=this.lists.get(t);if(!n)return;let o;if(e===null||e===-1)o=null;else if(typeof e=="number")o=n[Math.max(0,Math.min(n.length-1,e))]??null;else if(n.includes(e))o=e;else return;o===null&&!this.typeDef(t)?.canHide||(this.chosen.set(t,o),this.emit({kind:"part",type:t,skin:o}));}unequip(t){this.equip(t,null);}setHidden(t,e){this.typeDef(t)?.canHide&&(this.hidden.set(t,e),this.emit({kind:"hidden",type:t,hidden:e}));}next(t){let e=this.count(t);if(!e)return;let n=this.index(t);this.typeDef(t)?.canHide?this.equip(t,n>=e-1?-1:n+1):this.equip(t,(n+1)%e);}prev(t){let e=this.count(t);if(!e)return;let n=this.index(t);this.typeDef(t)?.canHide?this.equip(t,n<=-1?e-1:n-1):this.equip(t,(n-1+e)%e);}setColor(t,e){this.colors.set(t,e),this.emit({kind:"color",target:t,color:e});}setExpression(t){let e=t&&this.rig.expressions?.faces[t]?t:null;e!==this.face&&(this.face=e,this.emit({kind:"expression",name:e}));}setEmotion(t){let e=this.rig.expressions?.emotions?.[t]??null,n=e&&this.rig.expressions?.faces[e]?e:null;n!==this.emotionFace&&(this.emotionFace=n,this.emit({kind:"expression",name:this.face??n}));}setSpeech(t){t!==this.speech&&(this.speech=t,this.emit({kind:"speech",viseme:t}));}randomize(t=Math.random){for(let e of this.rig.partTypes){if(e.auto)continue;let n=this.count(e.id);n&&this.equip(e.id,e.canHide&&t()<.3?-1:Math.floor(t()*n));}}reset(){this.init();for(let t of this.rig.partTypes)this.emit({kind:"part",type:t.id,skin:this.part(t.id)});}toLook(){let t={};for(let n of this.rig.partTypes)n.auto||(t[n.id]=this.isWorn(n.id)?this.part(n.id):null);let e={};for(let[n,o]of this.colors)o&&(e[n]=o);return {v:1,parts:t,colors:e}}applyLook(t){for(let[e,n]of Object.entries(t.parts??{}))n===void 0||this.typeDef(e)?.auto||(this.equip(e,n),n!==null&&this.part(e)===n&&this.hidden.set(e,false));for(let[e,n]of Object.entries(t.colors??{}))n&&this.setColor(e,n);}rebuildLists(){for(let t of this.rig.partTypes)this.lists.set(t.id,this.rig.data.skinOrder.filter(e=>e.startsWith(t.skinPrefix)&&this.drawable(e)));}first(t){return this.lists.get(t.id)?.[0]??null}init(){this.chosen.clear(),this.hidden.clear(),this.colors.clear();for(let t of this.rig.partTypes)this.chosen.set(t.id,t.auto?null:this.first(t));}};var J=Math.PI/180,pt=1e-5,nt=class{constructor(t){this.bone=t;}bone;x=0;y=0;rotation=0;scaleX=1;scaleY=1;shearX=0;shearY=0;a=1;b=0;c=0;d=1;worldX=0;worldY=0;world=0;local=0;copyLocal(t){this.x=t.x,this.y=t.y,this.rotation=t.rotation,this.scaleX=t.scaleX,this.scaleY=t.scaleY,this.shearX=t.shearX,this.shearY=t.shearY;}update(t){this.world!==t.updateId&&this.updateWorldTransform(t);}updateWorldTransform(t){this.local===t.updateId?this.updateLocalTransform(t):this.world=t.updateId;let e=(this.rotation+this.shearX)*J,n=(this.rotation+90+this.shearY)*J,o=Math.cos(e)*this.scaleX,r=Math.cos(n)*this.scaleY,i=Math.sin(e)*this.scaleX,s=Math.sin(n)*this.scaleY,c=this.bone.parent;if(!c){let h=t.scaleX,p=t.scaleY;this.a=o*h,this.b=r*h,this.c=i*p,this.d=s*p,this.worldX=this.x*h+t.x,this.worldY=this.y*p+t.y;return}let a=c.applied;this.worldX=a.a*this.x+a.b*this.y+a.worldX,this.worldY=a.c*this.x+a.d*this.y+a.worldY,this.a=a.a*o+a.b*i,this.b=a.a*r+a.b*s,this.c=a.c*o+a.d*i,this.d=a.c*r+a.d*s;}updateLocalTransform(t){this.local=0,this.world=t.updateId;let e=this.bone.parent;if(!e){this.x=(this.worldX-t.x)/t.scaleX,this.y=(this.worldY-t.y)/t.scaleY,this.set5(this.a/t.scaleX,this.b/t.scaleX,this.c/t.scaleY,this.d/t.scaleY);return}let n=e.applied,o=1/(n.a*n.d-n.b*n.c),r=n.d*o,i=n.b*o,s=n.c*o,c=n.a*o,a=this.worldX-n.worldX,h=this.worldY-n.worldY;this.x=a*r-h*i,this.y=h*c-a*s,this.set5(r*this.a-i*this.c,r*this.b-i*this.d,c*this.c-s*this.a,c*this.d-s*this.b);}set5(t,e,n,o){this.shearX=0;let r=t*t+n*n,i=e*e+o*o;if(r>pt){let s=Math.atan2(n,t)/J;this.rotation=s,this.scaleX=Math.sqrt(r),this.scaleY=Math.sqrt(i),i>pt?(this.shearY=Math.atan2(o,e)/J,t*o-e*n<0?(this.scaleY=-this.scaleY,this.shearY+=90-s):this.shearY-=90+s,this.shearY>180?this.shearY-=360:this.shearY<=-180&&(this.shearY+=360)):this.shearY=0;}else this.scaleX=0,this.scaleY=Math.sqrt(i),this.shearY=0,this.rotation=i>pt?Math.atan2(o,e)/J-90:0;}modifyLocal(t){this.local===t.updateId&&this.updateLocalTransform(t),this.world=0,this.resetWorld(t);}modifyWorld(t){this.local=t.updateId,this.world=t.updateId,this.resetWorld(t);}resetWorld(t){for(let e of this.bone.children){let n=e.applied;n.world===t.updateId&&(n.local===t.updateId&&n.updateLocalTransform(t),n.world=0,n.resetWorld(t));}}},ot=class{constructor(t){this.data=t;this.pose=new nt(this),this.applied=new nt(this),this.setupPose();}data;pose;applied;parent=null;children=[];sorted=false;setupPose(){let t=this.data,e=this.pose;e.x=t.x,e.y=t.y,e.rotation=t.rotation,e.scaleX=t.scaleX,e.scaleY=t.scaleY,e.shearX=0,e.shearY=0;}},dt=class{constructor(t,e){this.data=t;this.bone=e;this.color={...t.color},this.attachmentKey=t.attachment;}data;bone;color;attachmentKey;attachment=null},O=class{constructor(t){this.data=t;this.bones=t.bones.map(e=>new ot(e));for(let e of this.bones)e.data.parent&&(e.parent=this.bones[e.data.parent.index],e.parent.children.push(e));this.slots=t.slots.map(e=>new dt(e,this.bones[e.bone.index])),this.constraints=t.constraints.map(e=>Mt(e,this)),this.updateCache();}data;bones;slots;constraints;skins=[];scaleX=1;scaleY=1;x=0;y=0;updateId=0;cache=[];bone(t){return this.bones[this.data.bone(t).index]}slot(t){return this.slots[this.data.slot(t).index]}setSkins(t){this.skins=[...t],this.resolveAttachments();}getAttachment(t,e){for(let n=this.skins.length-1;n>=0;n--){let o=this.skins[n].attachments.get(t)?.get(e);if(o)return o}return null}resolveAttachments(){for(let t of this.slots)t.attachment=t.attachmentKey?this.getAttachment(t.data.index,t.attachmentKey):null;}setupPose(){for(let t of this.bones)t.setupPose();for(let t of this.constraints)t.setupPose();for(let t of this.slots)Object.assign(t.color,t.data.color),t.attachmentKey=t.data.attachment;}updateWorldTransform(){this.updateId++;for(let t of this.bones)t.applied.copyLocal(t.pose),t.applied.world=0,t.applied.local=0;for(let t of this.cache)t instanceof ot?t.applied.update(this):t.update(this);}updateCache(){this.cache=[];for(let t of this.bones)t.sorted=false;for(let t of this.constraints)t.sort(this);for(let t of this.bones)this.sortBone(t);}sortBone(t){t.sorted||(t.parent&&this.sortBone(t.parent),t.sorted=true,this.cache.push(t));}sortReset(t){for(let e of t)e.sorted&&this.sortReset(e.children),e.sorted=false;}pushConstraint(t){this.cache.push(t);}};var Et=new WeakMap;function Xt(l,t){let e=Et.get(l);if(e)return e;e=new Map;let n=new O(l);n.setupPose(),n.updateWorldTransform();let[o,r]=t.light;for(let i of l.skins.values())for(let[s,c]of i.attachments)for(let a of c.values()){if(e.has(a.path)||t.skip?.some(g=>a.path.startsWith(g)))continue;let h=tt(n,n.slots[s],a,null),p=Gt(h.positions,h.uvs,a.width,a.height);if(!p)continue;let m=p.a*p.d-p.b*p.c;if(Math.abs(m)<1e-9)continue;let u=(p.d*o-p.b*r)/m,f=(-p.c*o+p.a*r)/m,b=Math.hypot(u,f)||1;e.set(a.path,{x:u/b,y:f/b});}return Et.set(l,e),e}function Gt(l,t,e,n){let o=t.length/2;if(o<3)return null;let r=0,i=0,s=0,c=0;for(let d=0;d<o;d++)r+=t[d*2]*e,i+=t[d*2+1]*n,s+=l[d*2],c+=l[d*2+1];r/=o,i/=o,s/=o,c/=o;let a=0,h=0,p=0,m=0,u=0,f=0,b=0;for(let d=0;d<o;d++){let k=t[d*2]*e-r,x=t[d*2+1]*n-i,P=l[d*2]-s,S=l[d*2+1]-c;a+=k*k,h+=k*x,p+=x*x,m+=P*k,u+=P*x,f+=S*k,b+=S*x;}let g=a*p-h*h;return Math.abs(g)<1e-9?null:{a:(m*p-u*h)/g,b:(u*a-m*h)/g,c:(f*p-b*h)/g,d:(b*a-f*h)/g}}var Bt=new Map,Rt=new Map,Ct=new WeakMap,Ut=1;function Vt(l,t,e){let n=Ct.get(l);return n===void 0&&Ct.set(l,n=Ut++),`${n}@${t}${e??""}`}function Jt(l,t,e,n,o){let r=Bt.get(l);return r||(r=new Promise(i=>{let s=new Image;s.onload=()=>{let c=new y__namespace.Texture(s);c.flipY=false,c.colorSpace=y__namespace.SRGBColorSpace,c.needsUpdate=true,Rt.set(l,c),i(c);},s.onerror=()=>i(null),s.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(wt(t,e,n,{paint:o.paint??null,light:o.light??null}));}),Bt.set(l,r),r)}var ut=class{root=new y__namespace.Group;skeleton;animator;parts;rig;catalog;slots=[];sizes;lights;resolution;unitsPerPx;offs=[];pending=new Set;asked=null;skinsDirty=true;facing=1;size=1;constructor(t){let e=this.rig=t.rig;this.catalog=t.catalog,this.resolution=t.resolution??2,this.unitsPerPx=t.unitsPerPx??.01,this.skeleton=new O(e.data),this.sizes=It(e.data),this.lights=e.shading?Xt(e.data,e.shading):new Map,this.parts=new et(e,n=>Yt(e.data,n).every(o=>this.catalog.has(o))),t.look&&this.parts.applyLook(t.look),this.offs.push(this.parts.on(()=>this.skinsDirty=true)),this.animator=new Z(this.skeleton,e.data,e.mix),this.animator.setRandom(vt(t.seed??1)),this.animator.setBlink(e.blink??null),this.play(t.animation??e.defaultAnimation,{mix:0});for(let n=0;n<this.skeleton.slots.length;n++){let o=new y__namespace.BufferGeometry,r=new y__namespace.MeshBasicMaterial({transparent:true,depthWrite:false,side:y__namespace.DoubleSide}),i=new y__namespace.Mesh(o,r);i.renderOrder=n,i.visible=false,i.frustumCulled=false,this.root.add(i),this.slots.push({mesh:i,positions:null,path:null,paint:null,key:null});}this.applyScale(),this.update(0);}play(t,e){return this.asked={name:t,...e?{options:e}:{}},this.animator.play(this.stanceOf(t),e)}on(t,e){let n=this.animator.on(t,e);return this.offs.push(n),n}setLook(t){this.parts.reset(),this.parts.applyLook(t);}setEmotion(t){this.parts.setEmotion(t);}setViseme(t){this.parts.setSpeech(t);}setFacing(t){return this.facing=t,this.applyScale(),this}setScale(t){return this.size=t,this.applyScale(),this}setRenderOrder(t){return this.slots.forEach((e,n)=>e.mesh.renderOrder=t+n),this}worldPoint(t,e=new y__namespace.Vector3){let n=this.rig.anchors[t]??t,o=this.skeleton.bone(n).applied;return e.set(o.worldX*this.unitsPerPx,o.worldY*this.unitsPerPx,0),this.root.localToWorld(e)}get height(){return this.rig.data.height*this.unitsPerPx*this.size}async ready(){for(this.update(0);this.pending.size>0;)await Promise.all([...this.pending]),this.update(0);}dispose(){for(let t of this.offs.splice(0))t();for(let t of this.slots)t.mesh.geometry.dispose(),t.mesh.material.dispose();this.root.removeFromParent();}update(t){let e=this.skeleton,n=this.rig.expressions;if(n&&this.parts.setExpression(n.byAnimation[this.animator.current()??""]??null),this.skinsDirty){this.skinsDirty=false,e.setSkins(this.parts.wornSkins().flatMap(r=>{let i=this.rig.data.skins.get(r);return i?[i]:[]}));let o=this.asked;o&&this.stanceOf(o.name)!==this.animator.current()&&this.animator.play(this.stanceOf(o.name),{...o.options,mix:.15});}this.animator.update(t),e.slots.forEach((o,r)=>{let i=this.parts.slotColor(r);if(!i)return;let s=At(i);o.color.r=(s>>16&255)/255,o.color.g=(s>>8&255)/255,o.color.b=(s&255)/255,o.color.a=1;}),e.updateWorldTransform();for(let o=0;o<e.slots.length;o++)this.drawSlot(o);}drawSlot(t){let e=this.slots[t],n=this.skeleton.slots[t],o=n.attachment,r=e.mesh;if(!o||n.color.a*o.color.a<=0){r.visible=false;return}let i=this.parts.artColor(t);if((e.path!==o.path||e.paint!==i)&&(e.path=o.path,e.paint=i,e.key=null),!e.key){let d=this.catalog.get(o.path);if(!d){r.visible=false;return}let k=d.paint?i:null,x=Vt(d,this.resolution,k),P=Rt.get(x);if(!P){let S=Jt(x,d,this.sizes.get(o.path)??{w:o.width,h:o.height},this.resolution,{paint:k,light:this.lights.get(o.path)??null});this.pending.add(S),S.then(()=>this.pending.delete(S)),r.visible=false;return}e.key=x,r.material.map=P,r.material.needsUpdate=true;}let s=tt(this.skeleton,n,o,e.positions);e.positions=s.positions;let c=r.geometry,a=s.uvs.length/2,h=c.getAttribute("position");(!h||h.count!==a)&&(h=new y__namespace.BufferAttribute(new Float32Array(a*3),3),c.setAttribute("position",h),c.setAttribute("uv",new y__namespace.BufferAttribute(new Float32Array(a*2),2)));let p=h.array,m=c.getAttribute("uv").array;for(let d=0;d<a;d++)p[d*3]=s.positions[d*2]*this.unitsPerPx,p[d*3+1]=s.positions[d*2+1]*this.unitsPerPx,p[d*3+2]=0,m[d*2]=s.uvs[d*2],m[d*2+1]=s.uvs[d*2+1];h.needsUpdate=true,c.getAttribute("uv").needsUpdate=true;let u=s.triangles,f=c.getIndex();if(!f||f.count!==u.length)c.setIndex(Array.from(u));else {let d=f.array;for(let k=0;k<u.length;k++)d[k]=u[k];f.needsUpdate=true;}let b=n.color,g=o.color;r.material.color.setRGB(b.r*g.r,b.g*g.g,b.b*g.b,y__namespace.SRGBColorSpace),r.material.opacity=b.a*g.a,r.visible=true;}stanceOf(t){let e=this.parts;return this.rig.stance?.(t,n=>e.isWorn(n)?e.part(n):null)??t}applyScale(){this.root.scale.set(this.size*this.facing,this.size,this.size);}};
1
+ 'use strict';var y=require('three');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var y__namespace=/*#__PURE__*/_interopNamespace(y);function wt(l){let t=l>>>0;return function(){t|=0,t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}function vt(l,t,e=1,o={}){let n=Math.max(1,Math.ceil(t.w*e)),s=Math.max(1,Math.ceil(t.h*e)),r=o.paint??l.paint,i=o.light?Lt(t,o.light):"";return `<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${s}" viewBox="0 0 ${t.w} ${t.h}"${r?` color="${r}"`:""}>${i}<g stroke-linejoin="round" stroke-linecap="round"${i?' filter="url(#cel)"':""}>${l.svg}</g></svg>`}var U={depth:.18,min:2.6,max:11,dark:.3,shine:.36};function Lt(l,t){let e=Math.max(U.min,Math.min(U.max,Math.min(l.w,l.h)*U.depth)),o=n=>+n.toFixed(2);return `<defs><filter id="cel" filterUnits="userSpaceOnUse" x="0" y="0" width="${l.w}" height="${l.h}" color-interpolation-filters="sRGB"><feMorphology in="SourceAlpha" operator="erode" radius="${o(3.6*.7)}" result="body"/><feOffset in="body" dx="${o(t.x*e)}" dy="${o(t.y*e)}" result="moved"/><feComposite in="body" in2="moved" operator="out" result="far"/><feFlood flood-color="#000000" flood-opacity="${U.dark}"/><feComposite in2="far" operator="in" result="dark"/><feMorphology in="SourceAlpha" operator="erode" radius="${o(3.6*1.05)}" result="inner"/><feOffset in="inner" dx="${o(-t.x*e*.42)}" dy="${o(-t.y*e*.42)}" result="back"/><feComposite in="inner" in2="back" operator="out" result="near"/><feFlood flood-color="#ffffff" flood-opacity="${U.shine}"/><feComposite in2="near" operator="in" result="shine"/><feMerge><feMergeNode in="SourceGraphic"/><feMergeNode in="dark"/><feMergeNode in="shine"/></feMerge></filter></defs>`}var X=Math.PI/180,lt=1e-5;function St(l,t){return l.type==="ik"?new O(l,t):new ht(l,t)}var ct=l=>l>180?l-360:l<=-180?l+360:l,O=class{constructor(t,e){this.data=t;this.bones=t.bones.map(o=>e.bones[o.index]),this.target=e.bones[t.target.index],this.mix=t.mix,this.bendDirection=t.bendDirection;}data;mix;bendDirection;bones;target;setupPose(){this.mix=this.data.mix,this.bendDirection=this.data.bendDirection;}sort(t){t.sortBone(this.target);let e=this.bones[0];t.sortBone(e),t.pushConstraint(this),e.sorted=false,t.sortReset(e.children);}update(t){if(this.mix===0)return;let e=this.target.applied;this.bones.length===1?Mt(t,this.bones[0].applied,e.worldX,e.worldY,this.mix):Ot(t,this.bones[0].applied,this.bones[1].applied,e.worldX,e.worldY,this.bendDirection,this.mix);}};function Mt(l,t,e,o,n){let s=t.bone.parent;if(!s)return;t.modifyLocal(l);let r=s.applied,i=r.a,c=r.b,a=r.c,h=r.d,d=-t.shearX-t.rotation,f=i*h-c*a,u=e-r.worldX,m=o-r.worldY,b=(u*h-m*c)/f-t.x,g=(m*i-u*a)/f-t.y;d+=Math.atan2(g,b)/X,t.scaleX<0&&(d+=180),t.rotation+=ct(d)*n;}function Ot(l,t,e,o,n,s,r){t.modifyLocal(l),e.modifyLocal(l);let i=t.x,c=t.y,a=t.scaleX,h=t.scaleY,d=e.scaleX,f,u,m;a<0?(a=-a,f=180,m=-1):(f=0,m=1),h<0&&(h=-h,m=-m),d<0?(d=-d,u=180):u=0;let b=Math.abs(a-h)<=lt,g,p;b?(g=t.a*e.x+t.b*e.y+t.worldX,p=t.c*e.x+t.d*e.y+t.worldY):(e.y=0,g=t.a*e.x+t.worldX,p=t.c*e.x+t.worldY);let k=t.bone.parent;if(!k)return;let x=k.applied,P=x.a,M=x.b,st=x.c,rt=x.d,D=P*rt-M*st,F=g-x.worldX,W=p-x.worldY;D=Math.abs(D)<=lt?0:1/D;let ft=(F*rt-W*M)*D-i,mt=(W*P-F*st)*D-c,w=Math.sqrt(ft*ft+mt*mt),I=e.bone.data.length*d;if(w<lt){Mt(l,t,o,n,r),e.rotation=0;return}F=o-x.worldX,W=n-x.worldY;let G=(F*rt-W*M)*D-i,N=(W*P-F*st)*D-c,j=G*G+N*N,R=0,T=0;if(b){I*=a;let v=(j-w*w-I*I)/(2*w*I);v<-1?(v=-1,T=Math.PI*s):v>1?(v=1,T=0):T=Math.acos(v)*s;let $=w+I*v,C=I*Math.sin(T);R=Math.atan2(N*$-G*C,G*$+N*C);}else {let v=a*I,$=h*I,C=v*v,q=$*$,it=Math.atan2(N,G),S=q*w*w+C*j-C*q,K=-2*q*w,yt=q-C,bt=K*K-4*yt*S,xt=false;if(bt>=0){let A=Math.sqrt(bt);K<0&&(A=-A),A=-(K+A)*.5;let E=A/yt,L=S/A,Y=Math.abs(E)<Math.abs(L)?E:L,V=j-Y*Y;if(V>=0){let B=Math.sqrt(V)*s;R=it-Math.atan2(B,Y),T=Math.atan2(B/h,(Y-w)/a),xt=true;}}if(!xt){let A=Math.PI,E=w-v,L=E*E,Y=0,V=0,B=w+v,at=B*B,kt=0;if(S=-v*w/(C-q),S>=-1&&S<=1){S=Math.acos(S);let z=v*Math.cos(S)+w,_=$*Math.sin(S),Q=z*z+_*_;Q<L&&(A=S,L=Q,E=z,Y=_),Q>at&&(V=S,at=Q,B=z,kt=_);}j<=(L+at)*.5?(R=it-Math.atan2(Y*s,E),T=A*s):(R=it-Math.atan2(kt*s,B),T=V*s);}}let gt=Math.atan2(e.y,e.x)*m;R=ct((R-gt)/X+f-t.rotation),T=ct(((T+gt)/X-e.shearX)*m+u-e.rotation),t.rotation+=R*r,e.rotation+=T*r;}var ht=class{constructor(t,e){this.data=t;this.source=e.bones[t.source.index],this.bones=t.bones.map(o=>e.bones[o.index]),this.mix={...t.mix};}data;mix;source;bones;setupPose(){Object.assign(this.mix,this.data.mix);}sort(t){t.sortBone(this.source);for(let e of this.bones)t.sortBone(e);t.pushConstraint(this);for(let e of this.bones)t.sortReset(e.children);for(let e of this.bones)e.sorted=true;}update(t){let e=this.mix;if(!e.rotate&&!e.x&&!e.y&&!e.scaleX&&!e.scaleY&&!e.shearY)return;let o=this.source.applied,n=this.data.offsets;for(let s of this.bones){let r=s.applied;r.modifyWorld(t);for(let i of this.data.properties){let c=Ht(t,o,i.prop,n)-i.offset;for(let a of i.to){let h=e[a.prop];h!==0&&Ft(t,r,a.prop,a.offset+c*a.scale,h);}}}}};function Ht(l,t,e,o){let n=l.scaleX,s=l.scaleY;switch(e){case "rotate":{let r=(t.a*t.d-t.b*t.c)*n*s>0?1:-1,i=Math.atan2(t.c/s,t.a/n)/X+r*o.rotate;return i<0&&(i+=360),i}case "x":return (o.x*t.a+o.y*t.b+t.worldX)/n;case "y":return (o.x*t.c+o.y*t.d+t.worldY)/s;case "scaleX":return Math.hypot(t.a/n,t.c/s)+o.scaleX;case "scaleY":return Math.hypot(t.b/n,t.d/s)+o.scaleY;case "shearY":return (Math.atan2(t.d/s,t.b/n)-Math.atan2(t.c/s,t.a/n))/X-90+o.shearY}}function Ft(l,t,e,o,n){let s=l.scaleX,r=l.scaleY;switch(e){case "rotate":{let i=t.a/s,c=t.b/s,a=t.c/r,h=t.d/r,d=o*X-Math.atan2(a,i);d>Math.PI?d-=2*Math.PI:d<-Math.PI&&(d+=2*Math.PI),d*=n;let f=Math.cos(d),u=Math.sin(d);t.a=(f*i-u*a)*s,t.b=(f*c-u*h)*s,t.c=(u*i+f*a)*r,t.d=(u*c+f*h)*r;return}case "x":t.worldX+=(o-t.worldX/s)*n*s;return;case "y":t.worldY+=(o-t.worldY/r)*n*r;return;case "scaleX":{let i=Math.hypot(t.a/s,t.c/r);i!==0&&(i=1+(o-i)*n/i,t.a*=i,t.c*=i);return}case "scaleY":{let i=Math.hypot(t.b/s,t.d/r);i!==0&&(i=1+(o-i)*n/i,t.b*=i,t.d*=i);return}case "shearY":{let i=t.b/s,c=t.d/r,a=Math.atan2(c,i),h=(o+90)*X;h-=a-Math.atan2(t.c/r,t.a/s),h>Math.PI?h-=2*Math.PI:h<-Math.PI&&(h+=2*Math.PI),h=a+h*n;let d=Math.hypot(i,c);t.b=Math.cos(h)*d*s,t.d=Math.sin(h)*d*r;return}}}var Z=class{constructor(t,e,o=.2){this.skeleton=t;this.data=e;this.defaultMix=o;this.snapshot=new Float32Array(t.bones.length*5),this.slotSnapshot=new Float32Array(t.slots.length*4),this.ikSnapshot=new Float32Array(t.constraints.length);}skeleton;data;defaultMix;track=null;previous=null;mixTime=0;mixDuration=0;listeners=new Map;snapshot;slotSnapshot;ikSnapshot;blink=null;setBlink(t){let e=t?this.data.animations.get(t.animation):void 0;if(!t||!e){this.blink=null;return}let o={bones:new Set(t.bones.map(n=>this.data.bone(n).index)),slots:new Set(t.slots.map(n=>this.data.slot(n).index))};this.blink={source:e,filter:o,options:t,wait:this.nextBlink(t),at:-1};}blinkNow(){this.blink&&(this.blink.at=0);}blinking(){return (this.blink?.at??-1)>=0}setRandom(t){this.random=t;}random=Math.random;nextBlink(t){return t.every[0]+this.random()*(t.every[1]-t.every[0])}names(){return [...this.data.animations.keys()]}has(t){return this.data.animations.has(t)}play(t,e={}){let o=this.data.animations.get(t);if(!o)return false;let n=e.mix??this.defaultMix;return this.previous=this.track&&n>0?this.track:null,this.mixTime=0,this.mixDuration=this.previous?n:0,this.track={animation:o,time:Math.max(0,e.from??0),speed:e.speed??1,loop:e.loop??true,done:false},true}current(){return this.track?.animation.name??null}time(){return this.track?this.local(this.track):0}duration(){return this.track?.animation.duration??0}finished(){return this.track?.done??false}setSpeed(t){this.track&&(this.track.speed=t);}on(t,e){let o=this.listeners.get(t)??new Set;return o.add(e),this.listeners.set(t,o),()=>o.delete(e)}update(t){let e=[],o=this.track;if(o&&!o.done){let n=o.time;o.time+=Math.max(0,t)*o.speed,this.collect(o,n,o.time,e),!o.loop&&o.time>=o.animation.duration&&(o.time=o.animation.duration,o.done=true,e.push({name:"end",animation:o.animation.name}));}if(this.previous){let n=this.previous;n.time+=Math.max(0,t)*n.speed,this.mixTime+=Math.max(0,t),this.mixTime>=this.mixDuration&&(this.previous=null);}this.advanceBlink(Math.max(0,t)),this.pose();for(let n of e){for(let s of this.listeners.get(n.name)??[])s(n);for(let s of this.listeners.get("*")??[])s(n);}}pose(){let t=this.skeleton,e=this.previous;e&&this.mixDuration>0&&(t.setupPose(),e.animation.apply(t,this.local(e)),this.save()),t.setupPose(),this.track&&this.track.animation.apply(t,this.local(this.track)),e&&this.mixDuration>0&&this.blendFromSaved(Math.min(1,this.mixTime/this.mixDuration));let o=this.blink;o&&o.at>=0&&o.source.applyOnly(t,o.options.from+o.at,o.filter),t.resolveAttachments();}advanceBlink(t){let e=this.blink;if(e){if(this.track?.animation.touches(e.filter)){e.at=-1;return}if(e.at>=0){e.at+=t,e.at>=e.options.to-e.options.from&&(e.at=-1,e.wait=this.nextBlink(e.options));return}e.wait-=t,e.wait<=0&&(e.at=0);}}local(t){let e=t.animation.duration;return e<=0?0:t.loop?t.time%e:Math.min(t.time,e)}collect(t,e,o,n){let s=t.animation.duration;if(s<=0||o<=e)return;let r=Math.floor(e/s),i=t.loop?Math.floor(o/s):0;for(let c=r;c<=i;c++)for(let a of t.animation.events){let h=c*s+a.time;h>=e&&(h<o||!t.loop&&h<=o)&&n.push({name:a.name,animation:t.animation.name});}}save(){let t=this.skeleton;t.bones.forEach((e,o)=>{let n=e.pose;this.snapshot.set([n.x,n.y,n.rotation,n.scaleX,n.scaleY],o*5);}),t.slots.forEach((e,o)=>this.slotSnapshot.set([e.color.r,e.color.g,e.color.b,e.color.a],o*4)),t.constraints.forEach((e,o)=>{e instanceof O&&(this.ikSnapshot[o]=e.mix);});}blendFromSaved(t){let e=this.skeleton,o=(n,s)=>n+(s-n)*t;e.bones.forEach((n,s)=>{let r=this.snapshot,i=n.pose,c=s*5;i.x=o(r[c],i.x),i.y=o(r[c+1],i.y);let a=i.rotation-r[c+2];a-=Math.round(a/360)*360,i.rotation=r[c+2]+a*t,i.scaleX=o(r[c+3],i.scaleX),i.scaleY=o(r[c+4],i.scaleY);}),e.slots.forEach((n,s)=>{let r=this.slotSnapshot;n.color.r=o(r[s*4],n.color.r),n.color.g=o(r[s*4+1],n.color.g),n.color.b=o(r[s*4+2],n.color.b),n.color.a=o(r[s*4+3],n.color.a);}),e.constraints.forEach((n,s)=>{n instanceof O&&(n.mix=o(this.ikSnapshot[s],n.mix));});}};var Tt=Math.PI/180,Wt=new Float32Array([0,1,0,0,1,0,1,1]),Gt=new Uint16Array([0,1,2,2,3,0]),Pt=new WeakMap;function Nt(l){let t=Pt.get(l);if(t)return t;let e=-l.width/2*l.scaleX,o=-l.height/2*l.scaleY,n=l.width/2*l.scaleX,s=l.height/2*l.scaleY,r=Math.cos(l.rotation*Tt),i=Math.sin(l.rotation*Tt),c=(a,h)=>[a*r-h*i+l.x,a*i+h*r+l.y];return t=Float32Array.from([...c(e,o),...c(e,s),...c(n,s),...c(n,o)]),Pt.set(l,t),t}function tt(l,t,e,o){if(e.type==="region"){let n=o&&o.length===8?o:new Float32Array(8),s=Nt(e),r=t.bone.applied;for(let i=0;i<8;i+=2){let c=s[i],a=s[i+1];n[i]=c*r.a+a*r.b+r.worldX,n[i+1]=c*r.c+a*r.d+r.worldY;}return {positions:n,uvs:Wt,triangles:Gt}}return qt(l,t,e,o)}function qt(l,t,e,o){let n=e.vertexCount*2,s=o&&o.length===n?o:new Float32Array(n),r=e.vertices;if(e.weighted){let i=0;for(let c=0;c<n;c+=2){let a=r[i++],h=0,d=0;for(let f=0;f<a;f++,i+=4){let u=l.bones[r[i]].applied,m=r[i+1],b=r[i+2],g=r[i+3];h+=(m*u.a+b*u.b+u.worldX)*g,d+=(m*u.c+b*u.d+u.worldY)*g;}s[c]=h,s[c+1]=d;}}else {let i=t.bone.applied;for(let c=0;c<n;c+=2){let a=r[c],h=r[c+1];s[c]=a*i.a+h*i.b+i.worldX,s[c+1]=a*i.c+h*i.d+i.worldY;}}return {positions:s,uvs:e.uvs,triangles:e.triangles}}function At(l){let t=/^#?([0-9a-f]{6})$/i.exec(l.trim());return t?parseInt(t[1],16):16777215}var It=new WeakMap;function Dt(l){let t=It.get(l);if(t)return t;t=new Map;for(let e of l.skins.values())for(let o of e.attachments.values())for(let n of o.values())t.has(n.path)||t.set(n.path,{w:n.width,h:n.height});return It.set(l,t),t}function Rt(l,t){let e=l.skins.get(t);if(!e)return [];let o=new Set;for(let n of e.attachments.values())for(let s of n.values())o.add(s.path);return [...o]}function Ct(l,t){return !l.skin?.length||l.skin.some(e=>e.toLowerCase()===t.toLowerCase())}var et=class{constructor(t,e=()=>true){this.rig=t;this.drawable=e;let o=(n,s)=>t.colorTargets.find(r=>(r.into??"tint")===s&&r.slotPrefixes.some(i=>n.startsWith(i)))?.id??null;this.slotTarget=t.data.slots.map(n=>o(n.name,"tint")),this.slotArt=t.data.slots.map(n=>o(n.name,"art")),this.rebuildLists(),this.init();}rig;drawable;chosen=new Map;hidden=new Map;colors=new Map;lists=new Map;listeners=new Set;slotTarget;slotArt;face=null;emotionFace=null;speech="rest";body={};raceSaved=new Map;raceGiven=new Map;setDrawable(t){let e=new Set(this.rig.partTypes.filter(o=>!this.count(o.id)).map(o=>o.id));this.drawable=t,this.rebuildLists();for(let o of this.rig.partTypes){if(o.auto)continue;let n=this.chosen.get(o.id);(n&&!this.lists.get(o.id).includes(n)||!n&&e.has(o.id))&&this.chosen.set(o.id,this.first(o));}this.emit({kind:"part",type:"*",skin:null});}on(t){return this.listeners.add(t),()=>this.listeners.delete(t)}emit(t){for(let e of [...this.listeners])e(t);}typeDef(t){return this.rig.partTypes.find(e=>e.id===t)}list(t){return this.lists.get(t)??[]}count(t){return this.list(t).length}part(t){return this.chosen.get(t)??null}index(t){let e=this.part(t);return e?this.list(t).indexOf(e):-1}isHidden(t){return this.hidden.get(t)??false}isWorn(t){return this.part(t)!==null&&!this.isHidden(t)}color(t){return this.colors.get(t)??null}wornSkins(){let t=new Map;for(let a of this.rig.partTypes)t.set(a.id,!a.auto&&this.isWorn(a.id)?this.part(a.id):null);let e={worn:a=>t.get(a)??null,setWorn:(a,h)=>t.set(a,h),exists:a=>this.rig.data.skins.has(a)&&this.drawable(a),race:()=>this.race(),types:()=>this.rig.partTypes.map(a=>a.id)};for(let a of this.rig.rules)a.apply(e);let o=this.rig.expressions,n=this.face??this.emotionFace,s=n?o?.faces[n]:void 0;for(let[a,h]of Object.entries(s??{}))t.get(a)&&e.exists(h)&&t.set(a,h);let r=this.speech!=="rest"?o?.speech:void 0,i=r?.visemes[this.speech];r&&i&&t.get(r.type)&&e.exists(i)&&t.set(r.type,i);let c=[];for(let a of this.rig.partTypes){let h=t.get(a.id);h&&c.push(h);}return c}slotColor(t){let e=this.slotTarget[t];return e?this.color(e):null}artColor(t){let e=this.slotArt[t];return e?this.color(e):null}bodyLook(){return {...this.body}}race(){return this.rig.races?.get(this.body.race)??null}expression(){return this.face}equip(t,e){let o=this.lists.get(t);if(!o)return;let n;if(e===null||e===-1)n=null;else if(typeof e=="number")n=o[Math.max(0,Math.min(o.length-1,e))]??null;else if(o.includes(e))n=e;else return;n===null&&!this.typeDef(t)?.canHide||(this.chosen.set(t,n),this.emit({kind:"part",type:t,skin:n}));}unequip(t){this.equip(t,null);}setHidden(t,e){this.typeDef(t)?.canHide&&(this.hidden.set(t,e),this.emit({kind:"hidden",type:t,hidden:e}));}next(t){let e=this.count(t);if(!e)return;let o=this.index(t);this.typeDef(t)?.canHide?this.equip(t,o>=e-1?-1:o+1):this.equip(t,(o+1)%e);}prev(t){let e=this.count(t);if(!e)return;let o=this.index(t);this.typeDef(t)?.canHide?this.equip(t,o<=-1?e-1:o-1):this.equip(t,(o-1+e)%e);}setColor(t,e){this.colors.set(t,e),this.emit({kind:"color",target:t,color:e});}setExpression(t){let e=t&&this.rig.expressions?.faces[t]?t:null;e!==this.face&&(this.face=e,this.emit({kind:"expression",name:e}));}setEmotion(t){let e=this.rig.expressions?.emotions?.[t]??null,o=e&&this.rig.expressions?.faces[e]?e:null;o!==this.emotionFace&&(this.emotionFace=o,this.emit({kind:"expression",name:this.face??o}));}setSpeech(t){t!==this.speech&&(this.speech=t,this.emit({kind:"speech",viseme:t}));}setBody(t){let e=this.race();if(this.body={...t},this.body.race!==e?.id){this.dropRaceColors();let o=new Map(this.colors);this.fitRaceColors(false),this.rememberRaceColors(o);}this.emit({kind:"body",body:this.bodyLook()});}setRace(t){let e={...this.body};t?e.race=t:delete e.race,this.setBody(e);}randomize(t=Math.random){for(let e of this.rig.partTypes){if(e.auto)continue;let o=this.count(e.id);o&&this.equip(e.id,e.canHide&&t()<.3?-1:Math.floor(t()*o));}}reset(){this.init();for(let t of this.rig.partTypes)this.emit({kind:"part",type:t.id,skin:this.part(t.id)});}toLook(){let t={};for(let n of this.rig.partTypes)n.auto||(t[n.id]=this.isWorn(n.id)?this.part(n.id):null);let e={};for(let[n,s]of this.colors)s&&(e[n]=s);let o=this.bodyLook();return {v:2,parts:t,colors:e,...Object.keys(o).length?{body:o}:{}}}applyLook(t){let e=this.race(),o=!!t.body&&t.body.race!==e?.id;o&&this.dropRaceColors();let n=new Map(this.colors);for(let[s,r]of Object.entries(t.parts??{}))r===void 0||this.typeDef(s)?.auto||(this.equip(s,r),r!==null&&this.part(s)===r&&this.hidden.set(s,false));for(let[s,r]of Object.entries(t.colors??{}))r&&this.setColor(s,r);t.body&&(this.body={...this.body,...t.body},o&&(this.fitRaceColors(true,t),this.rememberRaceColors(n)),this.emit({kind:"body",body:this.bodyLook()}));}dropRaceColors(){for(let[t,e]of this.raceGiven)this.color(t)?.toLowerCase()===e.toLowerCase()&&this.setColor(t,this.raceSaved.get(t)??null);this.raceGiven.clear(),this.raceSaved.clear();}rememberRaceColors(t){let e=this.race();if(!e)return;let o=new Set(Object.keys(e.colors??{}));e.skin?.length&&o.add(this.rig.skinColor??"Skin");for(let n of o){let s=this.color(n);!s||s===(t.get(n)??null)||(this.raceSaved.set(n,t.get(n)??null),this.raceGiven.set(n,s));}}fitRaceColors(t,e){let o=this.race();if(!o)return;for(let[i,c]of Object.entries(o.colors??{}))(t?e?.colors?.[i]:this.color(i))||this.setColor(i,c);let n=this.rig.skinColor??"Skin",s=this.color(n),r=t?e?.colors?.[n]??s:s;o.skin?.length&&(!r||!Ct(o,r))&&this.setColor(n,o.skin[0]);}rebuildLists(){for(let t of this.rig.partTypes)this.lists.set(t.id,this.rig.data.skinOrder.filter(e=>e.startsWith(t.skinPrefix)&&this.drawable(e)));}first(t){return this.lists.get(t.id)?.[0]??null}init(){this.chosen.clear(),this.hidden.clear(),this.colors.clear(),this.body={},this.raceSaved.clear(),this.raceGiven.clear();for(let t of this.rig.partTypes)this.chosen.set(t.id,t.auto?null:this.first(t));}};var J=Math.PI/180,dt=1e-5,ot=class{constructor(t){this.bone=t;}bone;x=0;y=0;rotation=0;scaleX=1;scaleY=1;shearX=0;shearY=0;a=1;b=0;c=0;d=1;worldX=0;worldY=0;world=0;local=0;copyLocal(t){this.x=t.x,this.y=t.y,this.rotation=t.rotation,this.scaleX=t.scaleX,this.scaleY=t.scaleY,this.shearX=t.shearX,this.shearY=t.shearY;}update(t){this.world!==t.updateId&&this.updateWorldTransform(t);}updateWorldTransform(t){this.local===t.updateId?this.updateLocalTransform(t):this.world=t.updateId;let e=(this.rotation+this.shearX)*J,o=(this.rotation+90+this.shearY)*J,n=Math.cos(e)*this.scaleX,s=Math.cos(o)*this.scaleY,r=Math.sin(e)*this.scaleX,i=Math.sin(o)*this.scaleY,c=this.bone.parent;if(!c){let h=t.scaleX,d=t.scaleY;this.a=n*h,this.b=s*h,this.c=r*d,this.d=i*d,this.worldX=this.x*h+t.x,this.worldY=this.y*d+t.y;return}let a=c.applied;this.worldX=a.a*this.x+a.b*this.y+a.worldX,this.worldY=a.c*this.x+a.d*this.y+a.worldY,this.a=a.a*n+a.b*r,this.b=a.a*s+a.b*i,this.c=a.c*n+a.d*r,this.d=a.c*s+a.d*i;}updateLocalTransform(t){this.local=0,this.world=t.updateId;let e=this.bone.parent;if(!e){this.x=(this.worldX-t.x)/t.scaleX,this.y=(this.worldY-t.y)/t.scaleY,this.set5(this.a/t.scaleX,this.b/t.scaleX,this.c/t.scaleY,this.d/t.scaleY);return}let o=e.applied,n=1/(o.a*o.d-o.b*o.c),s=o.d*n,r=o.b*n,i=o.c*n,c=o.a*n,a=this.worldX-o.worldX,h=this.worldY-o.worldY;this.x=a*s-h*r,this.y=h*c-a*i,this.set5(s*this.a-r*this.c,s*this.b-r*this.d,c*this.c-i*this.a,c*this.d-i*this.b);}set5(t,e,o,n){this.shearX=0;let s=t*t+o*o,r=e*e+n*n;if(s>dt){let i=Math.atan2(o,t)/J;this.rotation=i,this.scaleX=Math.sqrt(s),this.scaleY=Math.sqrt(r),r>dt?(this.shearY=Math.atan2(n,e)/J,t*n-e*o<0?(this.scaleY=-this.scaleY,this.shearY+=90-i):this.shearY-=90+i,this.shearY>180?this.shearY-=360:this.shearY<=-180&&(this.shearY+=360)):this.shearY=0;}else this.scaleX=0,this.scaleY=Math.sqrt(r),this.shearY=0,this.rotation=r>dt?Math.atan2(n,e)/J-90:0;}modifyLocal(t){this.local===t.updateId&&this.updateLocalTransform(t),this.world=0,this.resetWorld(t);}modifyWorld(t){this.local=t.updateId,this.world=t.updateId,this.resetWorld(t);}resetWorld(t){for(let e of this.bone.children){let o=e.applied;o.world===t.updateId&&(o.local===t.updateId&&o.updateLocalTransform(t),o.world=0,o.resetWorld(t));}}},nt=class{constructor(t){this.data=t;this.pose=new ot(this),this.applied=new ot(this),this.setupPose();}data;pose;applied;parent=null;children=[];sorted=false;setupPose(){let t=this.data,e=this.pose;e.x=t.x,e.y=t.y,e.rotation=t.rotation,e.scaleX=t.scaleX,e.scaleY=t.scaleY,e.shearX=0,e.shearY=0;}},pt=class{constructor(t,e){this.data=t;this.bone=e;this.color={...t.color},this.attachmentKey=t.attachment;}data;bone;color;attachmentKey;attachment=null},H=class{constructor(t){this.data=t;this.bones=t.bones.map(e=>new nt(e));for(let e of this.bones)e.data.parent&&(e.parent=this.bones[e.data.parent.index],e.parent.children.push(e));this.slots=t.slots.map(e=>new pt(e,this.bones[e.bone.index])),this.constraints=t.constraints.map(e=>St(e,this)),this.updateCache();}data;bones;slots;constraints;skins=[];scaleX=1;scaleY=1;x=0;y=0;updateId=0;cache=[];bone(t){return this.bones[this.data.bone(t).index]}slot(t){return this.slots[this.data.slot(t).index]}setSkins(t){this.skins=[...t],this.resolveAttachments();}getAttachment(t,e){for(let o=this.skins.length-1;o>=0;o--){let n=this.skins[o].attachments.get(t)?.get(e);if(n)return n}return null}resolveAttachments(){for(let t of this.slots)t.attachment=t.attachmentKey?this.getAttachment(t.data.index,t.attachmentKey):null;}setupPose(){for(let t of this.bones)t.setupPose();for(let t of this.constraints)t.setupPose();for(let t of this.slots)Object.assign(t.color,t.data.color),t.attachmentKey=t.data.attachment;}updateWorldTransform(){this.updateId++;for(let t of this.bones)t.applied.copyLocal(t.pose),t.applied.world=0,t.applied.local=0;for(let t of this.cache)t instanceof nt?t.applied.update(this):t.update(this);}updateCache(){this.cache=[];for(let t of this.bones)t.sorted=false;for(let t of this.constraints)t.sort(this);for(let t of this.bones)this.sortBone(t);}sortBone(t){t.sorted||(t.parent&&this.sortBone(t.parent),t.sorted=true,this.cache.push(t));}sortReset(t){for(let e of t)e.sorted&&this.sortReset(e.children),e.sorted=false;}pushConstraint(t){this.cache.push(t);}};var Et=new WeakMap;function Yt(l,t){let e=Et.get(l);if(e)return e;e=new Map;let o=new H(l);o.setupPose(),o.updateWorldTransform();let[n,s]=t.light;for(let r of l.skins.values())for(let[i,c]of r.attachments)for(let a of c.values()){if(e.has(a.path)||t.skip?.some(g=>a.path.startsWith(g)))continue;let h=tt(o,o.slots[i],a,null),d=Vt(h.positions,h.uvs,a.width,a.height);if(!d)continue;let f=d.a*d.d-d.b*d.c;if(Math.abs(f)<1e-9)continue;let u=(d.d*n-d.b*s)/f,m=(-d.c*n+d.a*s)/f,b=Math.hypot(u,m)||1;e.set(a.path,{x:u/b,y:m/b});}return Et.set(l,e),e}function Vt(l,t,e,o){let n=t.length/2;if(n<3)return null;let s=0,r=0,i=0,c=0;for(let p=0;p<n;p++)s+=t[p*2]*e,r+=t[p*2+1]*o,i+=l[p*2],c+=l[p*2+1];s/=n,r/=n,i/=n,c/=n;let a=0,h=0,d=0,f=0,u=0,m=0,b=0;for(let p=0;p<n;p++){let k=t[p*2]*e-s,x=t[p*2+1]*o-r,P=l[p*2]-i,M=l[p*2+1]-c;a+=k*k,h+=k*x,d+=x*x,f+=P*k,u+=P*x,m+=M*k,b+=M*x;}let g=a*d-h*h;return Math.abs(g)<1e-9?null:{a:(f*d-u*h)/g,b:(u*a-f*h)/g,c:(m*d-b*h)/g,d:(b*a-m*h)/g}}var Bt=new Map,$t=new Map,Xt=new WeakMap,Ut=1;function Jt(l,t,e){let o=Xt.get(l);return o===void 0&&Xt.set(l,o=Ut++),`${o}@${t}${e??""}`}function jt(l,t,e,o,n){let s=Bt.get(l);return s||(s=new Promise(r=>{let i=new Image;i.onload=()=>{let c=new y__namespace.Texture(i);c.flipY=false,c.colorSpace=y__namespace.SRGBColorSpace,c.needsUpdate=true,$t.set(l,c),r(c);},i.onerror=()=>r(null),i.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(vt(t,e,o,{paint:n.paint??null,light:n.light??null}));}),Bt.set(l,s),s)}var ut=class{root=new y__namespace.Group;skeleton;animator;parts;rig;catalog;slots=[];sizes;lights;resolution;unitsPerPx;offs=[];pending=new Set;asked=null;skinsDirty=true;facing=1;size=1;constructor(t){let e=this.rig=t.rig;this.catalog=t.catalog,this.resolution=t.resolution??2,this.unitsPerPx=t.unitsPerPx??.01,this.skeleton=new H(e.data),this.sizes=Dt(e.data),this.lights=e.shading?Yt(e.data,e.shading):new Map,this.parts=new et(e,o=>Rt(e.data,o).every(n=>this.catalog.has(n))),t.look&&this.parts.applyLook(t.look),this.offs.push(this.parts.on(()=>this.skinsDirty=true)),this.animator=new Z(this.skeleton,e.data,e.mix),this.animator.setRandom(wt(t.seed??1)),this.animator.setBlink(e.blink??null),this.play(t.animation??e.defaultAnimation,{mix:0});for(let o=0;o<this.skeleton.slots.length;o++){let n=new y__namespace.BufferGeometry,s=new y__namespace.MeshBasicMaterial({transparent:true,depthWrite:false,side:y__namespace.DoubleSide}),r=new y__namespace.Mesh(n,s);r.renderOrder=o,r.visible=false,r.frustumCulled=false,this.root.add(r),this.slots.push({mesh:r,positions:null,path:null,paint:null,key:null});}this.applyScale(),this.update(0);}play(t,e){return this.asked={name:t,...e?{options:e}:{}},this.animator.play(this.stanceOf(t),e)}on(t,e){let o=this.animator.on(t,e);return this.offs.push(o),o}setLook(t){this.parts.reset(),this.parts.applyLook(t);}setEmotion(t){this.parts.setEmotion(t);}setViseme(t){this.parts.setSpeech(t);}setFacing(t){return this.facing=t,this.applyScale(),this}setScale(t){return this.size=t,this.applyScale(),this}setRenderOrder(t){return this.slots.forEach((e,o)=>e.mesh.renderOrder=t+o),this}worldPoint(t,e=new y__namespace.Vector3){let o=this.rig.anchors[t]??t,n=this.skeleton.bone(o).applied;return e.set(n.worldX*this.unitsPerPx,n.worldY*this.unitsPerPx,0),this.root.localToWorld(e)}get height(){return this.rig.data.height*this.unitsPerPx*this.size}async ready(){for(this.update(0);this.pending.size>0;)await Promise.all([...this.pending]),this.update(0);}dispose(){for(let t of this.offs.splice(0))t();for(let t of this.slots)t.mesh.geometry.dispose(),t.mesh.material.dispose();this.root.removeFromParent();}update(t){let e=this.skeleton,o=this.rig.expressions;if(o&&this.parts.setExpression(o.byAnimation[this.animator.current()??""]??null),this.skinsDirty){this.skinsDirty=false,e.setSkins(this.parts.wornSkins().flatMap(s=>{let r=this.rig.data.skins.get(s);return r?[r]:[]}));let n=this.asked;n&&this.stanceOf(n.name)!==this.animator.current()&&this.animator.play(this.stanceOf(n.name),{...n.options,mix:.15});}this.animator.update(t),e.slots.forEach((n,s)=>{let r=this.parts.slotColor(s);if(!r)return;let i=At(r);n.color.r=(i>>16&255)/255,n.color.g=(i>>8&255)/255,n.color.b=(i&255)/255,n.color.a=1;}),e.updateWorldTransform();for(let n=0;n<e.slots.length;n++)this.drawSlot(n);}drawSlot(t){let e=this.slots[t],o=this.skeleton.slots[t],n=o.attachment,s=e.mesh;if(!n||o.color.a*n.color.a<=0){s.visible=false;return}let r=this.parts.artColor(t);if((e.path!==n.path||e.paint!==r)&&(e.path=n.path,e.paint=r,e.key=null),!e.key){let p=this.catalog.get(n.path);if(!p){s.visible=false;return}let k=p.paint?r:null,x=Jt(p,this.resolution,k),P=$t.get(x);if(!P){let M=jt(x,p,this.sizes.get(n.path)??{w:n.width,h:n.height},this.resolution,{paint:k,light:this.lights.get(n.path)??null});this.pending.add(M),M.then(()=>this.pending.delete(M)),s.visible=false;return}e.key=x,s.material.map=P,s.material.needsUpdate=true;}let i=tt(this.skeleton,o,n,e.positions);e.positions=i.positions;let c=s.geometry,a=i.uvs.length/2,h=c.getAttribute("position");(!h||h.count!==a)&&(h=new y__namespace.BufferAttribute(new Float32Array(a*3),3),c.setAttribute("position",h),c.setAttribute("uv",new y__namespace.BufferAttribute(new Float32Array(a*2),2)));let d=h.array,f=c.getAttribute("uv").array;for(let p=0;p<a;p++)d[p*3]=i.positions[p*2]*this.unitsPerPx,d[p*3+1]=i.positions[p*2+1]*this.unitsPerPx,d[p*3+2]=0,f[p*2]=i.uvs[p*2],f[p*2+1]=i.uvs[p*2+1];h.needsUpdate=true,c.getAttribute("uv").needsUpdate=true;let u=i.triangles,m=c.getIndex();if(!m||m.count!==u.length)c.setIndex(Array.from(u));else {let p=m.array;for(let k=0;k<u.length;k++)p[k]=u[k];m.needsUpdate=true;}let b=o.color,g=n.color;s.material.color.setRGB(b.r*g.r,b.g*g.g,b.b*g.b,y__namespace.SRGBColorSpace),s.material.opacity=b.a*g.a,s.visible=true;}stanceOf(t){let e=this.parts;return this.rig.stance?.(t,o=>e.isWorn(o)?e.part(o):null)??t}applyScale(){this.root.scale.set(this.size*this.facing,this.size,this.size);}};
2
2
  exports.Rig2dView=ut;
@@ -1,6 +1,6 @@
1
1
  import * as THREE from 'three';
2
2
  import { E as Emotion, V as Viseme } from '../../contract-DhZuKNIf.cjs';
3
- import { S as Skeleton, a as Animator, P as PartsManager, R as RigDef, A as ArtCatalog, C as CharacterLook, b as PlayOptions, c as AnimationEvent } from '../../PartsManager-Cn3MU-VS.cjs';
3
+ import { S as Skeleton, a as Animator, P as PartsManager, R as RigDef, A as ArtCatalog, C as CharacterLook, b as PlayOptions, c as AnimationEvent } from '../../PartsManager-CmrzoyJR.cjs';
4
4
 
5
5
  interface Rig2dViewOptions {
6
6
  rig: RigDef;
@@ -1,6 +1,6 @@
1
1
  import * as THREE from 'three';
2
2
  import { E as Emotion, V as Viseme } from '../../contract-DhZuKNIf.js';
3
- import { S as Skeleton, a as Animator, P as PartsManager, R as RigDef, A as ArtCatalog, C as CharacterLook, b as PlayOptions, c as AnimationEvent } from '../../PartsManager-CAVBKvp6.js';
3
+ import { S as Skeleton, a as Animator, P as PartsManager, R as RigDef, A as ArtCatalog, C as CharacterLook, b as PlayOptions, c as AnimationEvent } from '../../PartsManager-BpAUMQXw.js';
4
4
 
5
5
  interface Rig2dViewOptions {
6
6
  rig: RigDef;
@@ -1 +1 @@
1
- import {w,s,D,C,t,x,n,y,c}from'../../chunk-OF4BH3JZ.js';import {a}from'../../chunk-CGF2TQVK.js';import*as o from'three';var O=new Map,I=new Map,z=new WeakMap,L=1;function U(p,t,e){let i=z.get(p);return i===void 0&&z.set(p,i=L++),`${i}@${t}${e??""}`}function V(p,t,e,i,s){let r=O.get(p);return r||(r=new Promise(n=>{let l=new Image;l.onload=()=>{let h=new o.Texture(l);h.flipY=false,h.colorSpace=o.SRGBColorSpace,h.needsUpdate=true,I.set(p,h),n(h);},l.onerror=()=>n(null),l.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(c(t,e,i,{paint:s.paint??null,light:s.light??null}));}),O.set(p,r),r)}var b=class{root=new o.Group;skeleton;animator;parts;rig;catalog;slots=[];sizes;lights;resolution;unitsPerPx;offs=[];pending=new Set;asked=null;skinsDirty=true;facing=1;size=1;constructor(t$1){let e=this.rig=t$1.rig;this.catalog=t$1.catalog,this.resolution=t$1.resolution??2,this.unitsPerPx=t$1.unitsPerPx??.01,this.skeleton=new w(e.data),this.sizes=s(e.data),this.lights=e.shading?D(e.data,e.shading):new Map,this.parts=new C(e,i=>t(e.data,i).every(s=>this.catalog.has(s))),t$1.look&&this.parts.applyLook(t$1.look),this.offs.push(this.parts.on(()=>this.skinsDirty=true)),this.animator=new x(this.skeleton,e.data,e.mix),this.animator.setRandom(a(t$1.seed??1)),this.animator.setBlink(e.blink??null),this.play(t$1.animation??e.defaultAnimation,{mix:0});for(let i=0;i<this.skeleton.slots.length;i++){let s=new o.BufferGeometry,r=new o.MeshBasicMaterial({transparent:true,depthWrite:false,side:o.DoubleSide}),n=new o.Mesh(s,r);n.renderOrder=i,n.visible=false,n.frustumCulled=false,this.root.add(n),this.slots.push({mesh:n,positions:null,path:null,paint:null,key:null});}this.applyScale(),this.update(0);}play(t,e){return this.asked={name:t,...e?{options:e}:{}},this.animator.play(this.stanceOf(t),e)}on(t,e){let i=this.animator.on(t,e);return this.offs.push(i),i}setLook(t){this.parts.reset(),this.parts.applyLook(t);}setEmotion(t){this.parts.setEmotion(t);}setViseme(t){this.parts.setSpeech(t);}setFacing(t){return this.facing=t,this.applyScale(),this}setScale(t){return this.size=t,this.applyScale(),this}setRenderOrder(t){return this.slots.forEach((e,i)=>e.mesh.renderOrder=t+i),this}worldPoint(t,e=new o.Vector3){let i=this.rig.anchors[t]??t,s=this.skeleton.bone(i).applied;return e.set(s.worldX*this.unitsPerPx,s.worldY*this.unitsPerPx,0),this.root.localToWorld(e)}get height(){return this.rig.data.height*this.unitsPerPx*this.size}async ready(){for(this.update(0);this.pending.size>0;)await Promise.all([...this.pending]),this.update(0);}dispose(){for(let t of this.offs.splice(0))t();for(let t of this.slots)t.mesh.geometry.dispose(),t.mesh.material.dispose();this.root.removeFromParent();}update(t){let e=this.skeleton,i=this.rig.expressions;if(i&&this.parts.setExpression(i.byAnimation[this.animator.current()??""]??null),this.skinsDirty){this.skinsDirty=false,e.setSkins(this.parts.wornSkins().flatMap(r=>{let n=this.rig.data.skins.get(r);return n?[n]:[]}));let s=this.asked;s&&this.stanceOf(s.name)!==this.animator.current()&&this.animator.play(this.stanceOf(s.name),{...s.options,mix:.15});}this.animator.update(t),e.slots.forEach((s,r)=>{let n$1=this.parts.slotColor(r);if(!n$1)return;let l=n(n$1);s.color.r=(l>>16&255)/255,s.color.g=(l>>8&255)/255,s.color.b=(l&255)/255,s.color.a=1;}),e.updateWorldTransform();for(let s=0;s<e.slots.length;s++)this.drawSlot(s);}drawSlot(t){let e=this.slots[t],i=this.skeleton.slots[t],s=i.attachment,r=e.mesh;if(!s||i.color.a*s.color.a<=0){r.visible=false;return}let n=this.parts.artColor(t);if((e.path!==s.path||e.paint!==n)&&(e.path=s.path,e.paint=n,e.key=null),!e.key){let a=this.catalog.get(s.path);if(!a){r.visible=false;return}let u=a.paint?n:null,v=U(a,this.resolution,u),A=I.get(v);if(!A){let k=V(v,a,this.sizes.get(s.path)??{w:s.width,h:s.height},this.resolution,{paint:u,light:this.lights.get(s.path)??null});this.pending.add(k),k.then(()=>this.pending.delete(k)),r.visible=false;return}e.key=v,r.material.map=A,r.material.needsUpdate=true;}let l=y(this.skeleton,i,s,e.positions);e.positions=l.positions;let h=r.geometry,c=l.uvs.length/2,m=h.getAttribute("position");(!m||m.count!==c)&&(m=new o.BufferAttribute(new Float32Array(c*3),3),h.setAttribute("position",m),h.setAttribute("uv",new o.BufferAttribute(new Float32Array(c*2),2)));let E=m.array,w=h.getAttribute("uv").array;for(let a=0;a<c;a++)E[a*3]=l.positions[a*2]*this.unitsPerPx,E[a*3+1]=l.positions[a*2+1]*this.unitsPerPx,E[a*3+2]=0,w[a*2]=l.uvs[a*2],w[a*2+1]=l.uvs[a*2+1];m.needsUpdate=true,h.getAttribute("uv").needsUpdate=true;let d=l.triangles,g=h.getIndex();if(!g||g.count!==d.length)h.setIndex(Array.from(d));else {let a=g.array;for(let u=0;u<d.length;u++)a[u]=d[u];g.needsUpdate=true;}let f=i.color,y$1=s.color;r.material.color.setRGB(f.r*y$1.r,f.g*y$1.g,f.b*y$1.b,o.SRGBColorSpace),r.material.opacity=f.a*y$1.a,r.visible=true;}stanceOf(t){let e=this.parts;return this.rig.stance?.(t,i=>e.isWorn(i)?e.part(i):null)??t}applyScale(){this.root.scale.set(this.size*this.facing,this.size,this.size);}};export{b as Rig2dView};
1
+ import {w,s,M,L as L$1,t,x,n,y,c}from'../../chunk-UUX4NEC2.js';import {a}from'../../chunk-CGF2TQVK.js';import*as o from'three';var O=new Map,I=new Map,z=new WeakMap,L=1;function U(p,t,e){let i=z.get(p);return i===void 0&&z.set(p,i=L++),`${i}@${t}${e??""}`}function V(p,t,e,i,s){let r=O.get(p);return r||(r=new Promise(n=>{let l=new Image;l.onload=()=>{let h=new o.Texture(l);h.flipY=false,h.colorSpace=o.SRGBColorSpace,h.needsUpdate=true,I.set(p,h),n(h);},l.onerror=()=>n(null),l.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(c(t,e,i,{paint:s.paint??null,light:s.light??null}));}),O.set(p,r),r)}var b=class{root=new o.Group;skeleton;animator;parts;rig;catalog;slots=[];sizes;lights;resolution;unitsPerPx;offs=[];pending=new Set;asked=null;skinsDirty=true;facing=1;size=1;constructor(t$1){let e=this.rig=t$1.rig;this.catalog=t$1.catalog,this.resolution=t$1.resolution??2,this.unitsPerPx=t$1.unitsPerPx??.01,this.skeleton=new w(e.data),this.sizes=s(e.data),this.lights=e.shading?M(e.data,e.shading):new Map,this.parts=new L$1(e,i=>t(e.data,i).every(s=>this.catalog.has(s))),t$1.look&&this.parts.applyLook(t$1.look),this.offs.push(this.parts.on(()=>this.skinsDirty=true)),this.animator=new x(this.skeleton,e.data,e.mix),this.animator.setRandom(a(t$1.seed??1)),this.animator.setBlink(e.blink??null),this.play(t$1.animation??e.defaultAnimation,{mix:0});for(let i=0;i<this.skeleton.slots.length;i++){let s=new o.BufferGeometry,r=new o.MeshBasicMaterial({transparent:true,depthWrite:false,side:o.DoubleSide}),n=new o.Mesh(s,r);n.renderOrder=i,n.visible=false,n.frustumCulled=false,this.root.add(n),this.slots.push({mesh:n,positions:null,path:null,paint:null,key:null});}this.applyScale(),this.update(0);}play(t,e){return this.asked={name:t,...e?{options:e}:{}},this.animator.play(this.stanceOf(t),e)}on(t,e){let i=this.animator.on(t,e);return this.offs.push(i),i}setLook(t){this.parts.reset(),this.parts.applyLook(t);}setEmotion(t){this.parts.setEmotion(t);}setViseme(t){this.parts.setSpeech(t);}setFacing(t){return this.facing=t,this.applyScale(),this}setScale(t){return this.size=t,this.applyScale(),this}setRenderOrder(t){return this.slots.forEach((e,i)=>e.mesh.renderOrder=t+i),this}worldPoint(t,e=new o.Vector3){let i=this.rig.anchors[t]??t,s=this.skeleton.bone(i).applied;return e.set(s.worldX*this.unitsPerPx,s.worldY*this.unitsPerPx,0),this.root.localToWorld(e)}get height(){return this.rig.data.height*this.unitsPerPx*this.size}async ready(){for(this.update(0);this.pending.size>0;)await Promise.all([...this.pending]),this.update(0);}dispose(){for(let t of this.offs.splice(0))t();for(let t of this.slots)t.mesh.geometry.dispose(),t.mesh.material.dispose();this.root.removeFromParent();}update(t){let e=this.skeleton,i=this.rig.expressions;if(i&&this.parts.setExpression(i.byAnimation[this.animator.current()??""]??null),this.skinsDirty){this.skinsDirty=false,e.setSkins(this.parts.wornSkins().flatMap(r=>{let n=this.rig.data.skins.get(r);return n?[n]:[]}));let s=this.asked;s&&this.stanceOf(s.name)!==this.animator.current()&&this.animator.play(this.stanceOf(s.name),{...s.options,mix:.15});}this.animator.update(t),e.slots.forEach((s,r)=>{let n$1=this.parts.slotColor(r);if(!n$1)return;let l=n(n$1);s.color.r=(l>>16&255)/255,s.color.g=(l>>8&255)/255,s.color.b=(l&255)/255,s.color.a=1;}),e.updateWorldTransform();for(let s=0;s<e.slots.length;s++)this.drawSlot(s);}drawSlot(t){let e=this.slots[t],i=this.skeleton.slots[t],s=i.attachment,r=e.mesh;if(!s||i.color.a*s.color.a<=0){r.visible=false;return}let n=this.parts.artColor(t);if((e.path!==s.path||e.paint!==n)&&(e.path=s.path,e.paint=n,e.key=null),!e.key){let a=this.catalog.get(s.path);if(!a){r.visible=false;return}let u=a.paint?n:null,v=U(a,this.resolution,u),A=I.get(v);if(!A){let k=V(v,a,this.sizes.get(s.path)??{w:s.width,h:s.height},this.resolution,{paint:u,light:this.lights.get(s.path)??null});this.pending.add(k),k.then(()=>this.pending.delete(k)),r.visible=false;return}e.key=v,r.material.map=A,r.material.needsUpdate=true;}let l=y(this.skeleton,i,s,e.positions);e.positions=l.positions;let h=r.geometry,c=l.uvs.length/2,m=h.getAttribute("position");(!m||m.count!==c)&&(m=new o.BufferAttribute(new Float32Array(c*3),3),h.setAttribute("position",m),h.setAttribute("uv",new o.BufferAttribute(new Float32Array(c*2),2)));let E=m.array,w=h.getAttribute("uv").array;for(let a=0;a<c;a++)E[a*3]=l.positions[a*2]*this.unitsPerPx,E[a*3+1]=l.positions[a*2+1]*this.unitsPerPx,E[a*3+2]=0,w[a*2]=l.uvs[a*2],w[a*2+1]=l.uvs[a*2+1];m.needsUpdate=true,h.getAttribute("uv").needsUpdate=true;let d=l.triangles,g=h.getIndex();if(!g||g.count!==d.length)h.setIndex(Array.from(d));else {let a=g.array;for(let u=0;u<d.length;u++)a[u]=d[u];g.needsUpdate=true;}let f=i.color,y$1=s.color;r.material.color.setRGB(f.r*y$1.r,f.g*y$1.g,f.b*y$1.b,o.SRGBColorSpace),r.material.opacity=f.a*y$1.a,r.visible=true;}stanceOf(t){let e=this.parts;return this.rig.stance?.(t,i=>e.isWorn(i)?e.part(i):null)??t}applyScale(){this.root.scale.set(this.size*this.facing,this.size,this.size);}};export{b as Rig2dView};
@@ -1,4 +1,4 @@
1
- import { C as CharacterLook, H as Hex, R as RigDef, A as ArtCatalog } from './PartsManager-Cn3MU-VS.cjs';
1
+ import { C as CharacterLook, H as Hex, R as RigDef, A as ArtCatalog } from './PartsManager-CmrzoyJR.cjs';
2
2
 
3
3
  interface LookPreset {
4
4
  id: string;
@@ -1,4 +1,4 @@
1
- import { C as CharacterLook, H as Hex, R as RigDef, A as ArtCatalog } from './PartsManager-CAVBKvp6.js';
1
+ import { C as CharacterLook, H as Hex, R as RigDef, A as ArtCatalog } from './PartsManager-BpAUMQXw.js';
2
2
 
3
3
  interface LookPreset {
4
4
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idosgames/characters",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Characters of the iDosGames platform in one standard for games and videos: voxel characters (CharacterSpec recipes on three.js), layered 2D characters on a skeleton with a full wardrobe (clothes, hair, weapons, shields) in vector art, and GLB characters on the humanoid-v1 skeleton — one actor contract (emotions, mouth visemes, poses, sockets) and lip-sync from text.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,2 +0,0 @@
1
- var Tt="#1f1a21";var Qt="currentColor";function zt(s,t,e=1,n={}){let o=Math.max(1,Math.ceil(t.w*e)),r=Math.max(1,Math.ceil(t.h*e)),a=n.paint??s.paint,i=n.light?$t(t,n.light):"";return `<svg xmlns="http://www.w3.org/2000/svg" width="${o}" height="${r}" viewBox="0 0 ${t.w} ${t.h}"${a?` color="${a}"`:""}>${i}<g stroke-linejoin="round" stroke-linecap="round"${i?' filter="url(#cel)"':""}>${s.svg}</g></svg>`}var K={depth:.18,min:2.6,max:11,dark:.3,shine:.36};function $t(s,t){let e=Math.max(K.min,Math.min(K.max,Math.min(s.w,s.h)*K.depth)),n=o=>+o.toFixed(2);return `<defs><filter id="cel" filterUnits="userSpaceOnUse" x="0" y="0" width="${s.w}" height="${s.h}" color-interpolation-filters="sRGB"><feMorphology in="SourceAlpha" operator="erode" radius="${n(3.6*.7)}" result="body"/><feOffset in="body" dx="${n(t.x*e)}" dy="${n(t.y*e)}" result="moved"/><feComposite in="body" in2="moved" operator="out" result="far"/><feFlood flood-color="#000000" flood-opacity="${K.dark}"/><feComposite in2="far" operator="in" result="dark"/><feMorphology in="SourceAlpha" operator="erode" radius="${n(3.6*1.05)}" result="inner"/><feOffset in="inner" dx="${n(-t.x*e*.42)}" dy="${n(-t.y*e*.42)}" result="back"/><feComposite in="inner" in2="back" operator="out" result="near"/><feFlood flood-color="#ffffff" flood-opacity="${K.shine}"/><feComposite in2="near" operator="in" result="shine"/><feMerge><feMergeNode in="SourceGraphic"/><feMergeNode in="dark"/><feMergeNode in="shine"/></feMerge></filter></defs>`}function lt(s={}){let t=s.stroke??Tt,e=(s.opacity!==void 0?` opacity="${s.opacity}"`:"")+(s.holes?' fill-rule="evenodd"':"");return t==="none"?` stroke="none"${e}`:` stroke="${t}" stroke-width="${s.width??3.6}"${e}`}var Rt=(s,t,e)=>`<path d="${s}" fill="${t}"${lt(e)}/>`,Ft=(s,t,e,n,o,r)=>`<ellipse cx="${s}" cy="${t}" rx="${e}" ry="${n}" fill="${o}"${lt(r)}/>`,te=(s,t,e,n,o)=>Ft(s,t,e,e,n,o),ee=(s,t,e,n,o,r,a)=>`<rect x="${s}" y="${t}" width="${e}" height="${n}" rx="${o}" fill="${r}"${lt(a)}/>`,ne=(s,t=Tt,e=2.2)=>`<path d="${s}" fill="none" stroke="${t}" stroke-width="${e}"/>`,oe=(s,t,e)=>Rt(s,t,{stroke:"none",...e!==void 0?{opacity:e}:{}}),se=(s,t,...e)=>`<clipPath id="${s}"><path d="${t}" clip-rule="evenodd"/></clipPath><g clip-path="url(#${s})">${e.join("")}</g>`,re=(s,...t)=>`<g transform="${s}">${t.join("")}</g>`;function ie(s,t){let e=parseInt(s.replace("#",""),16),n=i=>Math.max(0,Math.min(255,Math.round(t<0?i*(1+t):i+(255-i)*t))),o=n(e>>16&255),r=n(e>>8&255),a=n(e&255);return `#${(o<<16|r<<8|a).toString(16).padStart(6,"0")}`}var le="#ffffff";function ce(s){let t=/^#?([0-9a-f]{6})$/i.exec(s.trim());return t?parseInt(t[1],16):16777215}function he(s){return `#${(s&16777215).toString(16).padStart(6,"0")}`}function O(s){let t=(s??"ffffffff").replace("#","").padEnd(8,"f"),e=n=>parseInt(t.slice(n,n+2),16)/255;return {r:e(0),g:e(2),b:e(4),a:e(6)}}var L=Math.PI/180,ct=1e-5;function At(s,t){return s.type==="ik"?new I(s,t):new pt(s,t)}var ht=s=>s>180?s-360:s<=-180?s+360:s,I=class{constructor(t,e){this.data=t;this.bones=t.bones.map(n=>e.bones[n.index]),this.target=e.bones[t.target.index],this.mix=t.mix,this.bendDirection=t.bendDirection;}data;mix;bendDirection;bones;target;setupPose(){this.mix=this.data.mix,this.bendDirection=this.data.bendDirection;}sort(t){t.sortBone(this.target);let e=this.bones[0];t.sortBone(e),t.pushConstraint(this),e.sorted=false,t.sortReset(e.children);}update(t){if(this.mix===0)return;let e=this.target.applied;this.bones.length===1?Pt(t,this.bones[0].applied,e.worldX,e.worldY,this.mix):Nt(t,this.bones[0].applied,this.bones[1].applied,e.worldX,e.worldY,this.bendDirection,this.mix);}};function Pt(s,t,e,n,o){let r=t.bone.parent;if(!r)return;t.modifyLocal(s);let a=r.applied,i=a.a,p=a.b,l=a.c,c=a.d,d=-t.shearX-t.rotation,h=i*c-p*l,u=e-a.worldX,m=n-a.worldY,f=(u*c-m*p)/h-t.x,b=(m*i-u*l)/h-t.y;d+=Math.atan2(b,f)/L,t.scaleX<0&&(d+=180),t.rotation+=ht(d)*o;}function Nt(s,t,e,n,o,r,a){t.modifyLocal(s),e.modifyLocal(s);let i=t.x,p=t.y,l=t.scaleX,c=t.scaleY,d=e.scaleX,h,u,m;l<0?(l=-l,h=180,m=-1):(h=0,m=1),c<0&&(c=-c,m=-m),d<0?(d=-d,u=180):u=0;let f=Math.abs(l-c)<=ct,b,y;f?(b=t.a*e.x+t.b*e.y+t.worldX,y=t.c*e.x+t.d*e.y+t.worldY):(e.y=0,b=t.a*e.x+t.worldX,y=t.c*e.x+t.worldY);let x=t.bone.parent;if(!x)return;let g=x.applied,w=g.a,M=g.b,st=g.c,rt=g.d,Y=w*rt-M*st,F=b-g.worldX,N=y-g.worldY;Y=Math.abs(Y)<=ct?0:1/Y;let gt=(F*rt-N*M)*Y-i,xt=(N*w-F*st)*Y-p,k=Math.sqrt(gt*gt+xt*xt),P=e.bone.data.length*d;if(k<ct){Pt(s,t,n,o,a),e.rotation=0;return}F=n-g.worldX,N=o-g.worldY;let H=(F*rt-N*M)*Y-i,J=(N*w-F*st)*Y-p,G=H*H+J*J,D=0,T=0;if(f){P*=l;let v=(G-k*k-P*P)/(2*k*P);v<-1?(v=-1,T=Math.PI*r):v>1?(v=1,T=0):T=Math.acos(v)*r;let $=k+P*v,X=P*Math.sin(T);D=Math.atan2(J*$-H*X,H*$+J*X);}else {let v=l*P,$=c*P,X=v*v,q=$*$,it=Math.atan2(J,H),S=q*k*k+X*G-X*q,V=-2*q*k,vt=q-X,wt=V*V-4*vt*S,St=false;if(wt>=0){let A=Math.sqrt(wt);V<0&&(A=-A),A=-(V+A)*.5;let E=A/vt,R=S/A,B=Math.abs(E)<Math.abs(R)?E:R,W=G-B*B;if(W>=0){let C=Math.sqrt(W)*r;D=it-Math.atan2(C,B),T=Math.atan2(C/c,(B-k)/l),St=true;}}if(!St){let A=Math.PI,E=k-v,R=E*E,B=0,W=0,C=k+v,at=C*C,Mt=0;if(S=-v*k/(X-q),S>=-1&&S<=1){S=Math.acos(S);let U=v*Math.cos(S)+k,_=$*Math.sin(S),Z=U*U+_*_;Z<R&&(A=S,R=Z,E=U,B=_),Z>at&&(W=S,at=Z,C=U,Mt=_);}G<=(R+at)*.5?(D=it-Math.atan2(B*r,E),T=A*r):(D=it-Math.atan2(Mt*r,C),T=W*r);}}let kt=Math.atan2(e.y,e.x)*m;D=ht((D-kt)/L+h-t.rotation),T=ht(((T+kt)/L-e.shearX)*m+u-e.rotation),t.rotation+=D*a,e.rotation+=T*a;}var pt=class{constructor(t,e){this.data=t;this.source=e.bones[t.source.index],this.bones=t.bones.map(n=>e.bones[n.index]),this.mix={...t.mix};}data;mix;source;bones;setupPose(){Object.assign(this.mix,this.data.mix);}sort(t){t.sortBone(this.source);for(let e of this.bones)t.sortBone(e);t.pushConstraint(this);for(let e of this.bones)t.sortReset(e.children);for(let e of this.bones)e.sorted=true;}update(t){let e=this.mix;if(!e.rotate&&!e.x&&!e.y&&!e.scaleX&&!e.scaleY&&!e.shearY)return;let n=this.source.applied,o=this.data.offsets;for(let r of this.bones){let a=r.applied;a.modifyWorld(t);for(let i of this.data.properties){let p=Ht(t,n,i.prop,o)-i.offset;for(let l of i.to){let c=e[l.prop];c!==0&&Jt(t,a,l.prop,l.offset+p*l.scale,c);}}}}};function Ht(s,t,e,n){let o=s.scaleX,r=s.scaleY;switch(e){case "rotate":{let a=(t.a*t.d-t.b*t.c)*o*r>0?1:-1,i=Math.atan2(t.c/r,t.a/o)/L+a*n.rotate;return i<0&&(i+=360),i}case "x":return (n.x*t.a+n.y*t.b+t.worldX)/o;case "y":return (n.x*t.c+n.y*t.d+t.worldY)/r;case "scaleX":return Math.hypot(t.a/o,t.c/r)+n.scaleX;case "scaleY":return Math.hypot(t.b/o,t.d/r)+n.scaleY;case "shearY":return (Math.atan2(t.d/r,t.b/o)-Math.atan2(t.c/r,t.a/o))/L-90+n.shearY}}function Jt(s,t,e,n,o){let r=s.scaleX,a=s.scaleY;switch(e){case "rotate":{let i=t.a/r,p=t.b/r,l=t.c/a,c=t.d/a,d=n*L-Math.atan2(l,i);d>Math.PI?d-=2*Math.PI:d<-Math.PI&&(d+=2*Math.PI),d*=o;let h=Math.cos(d),u=Math.sin(d);t.a=(h*i-u*l)*r,t.b=(h*p-u*c)*r,t.c=(u*i+h*l)*a,t.d=(u*p+h*c)*a;return}case "x":t.worldX+=(n-t.worldX/r)*o*r;return;case "y":t.worldY+=(n-t.worldY/a)*o*a;return;case "scaleX":{let i=Math.hypot(t.a/r,t.c/a);i!==0&&(i=1+(n-i)*o/i,t.a*=i,t.c*=i);return}case "scaleY":{let i=Math.hypot(t.b/r,t.d/a);i!==0&&(i=1+(n-i)*o/i,t.b*=i,t.d*=i);return}case "shearY":{let i=t.b/r,p=t.d/a,l=Math.atan2(p,i),c=(n+90)*L;c-=l-Math.atan2(t.c/a,t.a/r),c>Math.PI?c-=2*Math.PI:c<-Math.PI&&(c+=2*Math.PI),c=l+c*o;let d=Math.hypot(i,p);t.b=Math.cos(c)*d*r,t.d=Math.sin(c)*d*a;return}}}var Q=class{constructor(t){this.channels=t;}channels;times=[];values=[];kinds=[];samples=[];get count(){return this.times.length}add(t,e){this.times.push(t);for(let n=0;n<this.channels;n++)this.values.push(e[n]??0);this.kinds.push(0);for(let n=0;n<this.channels;n++)this.samples.push(null);}setCurve(t,e){if(e==="stepped"){this.kinds[t]=1;return}if(!Array.isArray(e)||t+1>=this.count)return;this.kinds[t]=2;let n=this.times[t],o=this.times[t+1];for(let r=0;r<this.channels;r++){let a=r*4;if(e.length<a+4)continue;let i=this.values[t*this.channels+r],p=this.values[(t+1)*this.channels+r];this.samples[t*this.channels+r]=qt(n,i,Number(e[a]),Number(e[a+1]),Number(e[a+2]),Number(e[a+3]),o,p);}}keyAt(t){let e=this.times;if(!e.length||t<e[0])return -1;let n=0,o=e.length-1;for(;n<o;){let r=n+o+1>>1;e[r]<=t?n=r:o=r-1;}return n}value(t,e=0){let n=Math.max(0,this.keyAt(t)),o=this.channels,r=this.values[n*o+e];if(n+1>=this.count)return r;let a=this.kinds[n];if(a===1)return r;let i=this.times[n],p=this.times[n+1],l=this.values[(n+1)*o+e],c=this.samples[n*o+e];if(a!==2||!c)return r+(t-i)/(p-i)*(l-r);if(c[0]>t)return r+(t-i)/(c[0]-i)*(c[1]-r);for(let u=2;u<18;u+=2)if(c[u]>=t){let m=c[u-2],f=c[u-1];return f+(t-m)/(c[u]-m)*(c[u+1]-f)}let d=c[16],h=c[17];return h+(t-d)/(p-d)*(l-h)}};function qt(s,t,e,n,o,r,a,i){let p=new Float32Array(18);for(let l=1;l<=9;l++){let c=l/10,d=1-c,h=d*d*d,u=3*d*d*c,m=3*d*c*c,f=c*c*c;p[(l-1)*2]=h*s+u*e+m*o+f*a,p[(l-1)*2+1]=h*t+u*n+m*r+f*i;}return p}var It=(s,t)=>s.bone!==void 0&&t.bones.has(s.bone)||s.slot!==void 0&&t.slots.has(s.slot),dt=class{constructor(t,e,n,o){this.name=t;this.duration=e;this.timelines=n;this.events=o;}name;duration;timelines;events;apply(t,e){for(let n of this.timelines)n.apply(t,e);}applyOnly(t,e,n){for(let o of this.timelines)It(o,n)&&o.apply(t,e);}touches(t){return this.timelines.some(e=>It(e,t))}},ut=class{constructor(t,e,n){this.bone=t;this.keys=e;this.props=n;}bone;keys;props;apply(t,e){if(this.keys.keyAt(e)<0)return;let n=t.bones[this.bone],o=n.pose,r=n.data;this.props.forEach((a,i)=>{let p=this.keys.value(e,i);switch(a){case "rotate":o.rotation=r.rotation+p;break;case "x":o.x=r.x+p;break;case "y":o.y=r.y+p;break;case "scaleX":o.scaleX=r.scaleX*p;break;case "scaleY":o.scaleY=r.scaleY*p;break}});}},tt=class{constructor(t,e,n){this.slot=t;this.keys=e;this.channels=n;}slot;keys;channels;apply(t,e){if(this.keys.keyAt(e)<0)return;let n=t.slots[this.slot].color;this.channels.forEach((o,r)=>n[o]=this.keys.value(e,r));}},mt=class{constructor(t,e,n){this.slot=t;this.times=e;this.names=n;}slot;times;names;apply(t,e){if(e<this.times[0])return;let n=0;for(;n+1<this.times.length&&this.times[n+1]<=e;)n++;t.slots[this.slot].attachmentKey=this.names[n];}},ft=class{constructor(t,e,n){this.constraint=t;this.keys=e;this.bends=n;}constraint;keys;bends;apply(t,e){let n=this.keys.keyAt(e);if(n<0)return;let o=t.constraints[this.constraint];o instanceof I&&(o.mix=this.keys.value(e,0),o.bendDirection=this.bends[n]);}};function z(s,t,e){let n=new Q(t);for(let o of s)n.add(o.time??0,e(o));return s.forEach((o,r)=>n.setCurve(r,o.curve)),n}var Wt={rotate:{props:["rotate"],read:s=>[s.value??0]},translate:{props:["x","y"],read:s=>[s.x??0,s.y??0]},translatex:{props:["x"],read:s=>[s.value??0]},translatey:{props:["y"],read:s=>[s.value??0]},scale:{props:["scaleX","scaleY"],read:s=>[s.x??1,s.y??1]},scalex:{props:["scaleX"],read:s=>[s.value??1]},scaley:{props:["scaleY"],read:s=>[s.value??1]}};function Yt(s,t,e){let n=[],o=0,r=i=>{for(let p of i)o=Math.max(o,p.time??0);};for(let[i,p]of Object.entries(t.bones??{})){let l=e.bone(i).index;for(let[c,d]of Object.entries(p)){let h=Wt[c];!h||!d.length||(r(d),n.push(new ut(l,z(d,h.props.length,h.read),h.props)));}}for(let[i,p]of Object.entries(t.slots??{})){let l=e.slot(i).index;for(let[c,d]of Object.entries(p))if(d.length)if(r(d),c==="attachment")n.push(new mt(l,d.map(h=>h.time??0),d.map(h=>h.name??null)));else if(c==="rgba"||c==="rgb"){let h=c==="rgba"?["r","g","b","a"]:["r","g","b"],u=z(d,h.length,m=>{let f=O(m.color);return h.map(b=>f[b])});n.push(new tt(l,u,[...h]));}else c==="alpha"&&n.push(new tt(l,z(d,1,h=>[h.value??0]),["a"]));}for(let[i,p]of Object.entries(t.ik??{})){let l=e.constraints.find(c=>c.type==="ik"&&c.name===i);!l||!p.length||(r(p),n.push(new ft(l.index,z(p,1,c=>[c.mix??1]),p.map(c=>c.bendPositive===false?-1:1))));}let a=(t.events??[]).map(i=>({time:i.time??0,name:i.name}));for(let i of a)o=Math.max(o,i.time);return new dt(s,o,n,a)}function ve(s){let t=[],e=new Map;for(let h of s.bones){let u=h.parent?e.get(h.parent)??null:null,m={index:t.length,name:h.name,parent:u,children:[],length:h.length??0,x:h.x??0,y:h.y??0,rotation:h.rotation??0,scaleX:h.scaleX??1,scaleY:h.scaleY??1};u?.children.push(m),t.push(m),e.set(m.name,m);}let n=h=>{let u=e.get(h);if(!u)throw new Error(`no bone ${h}`);return u},o=[],r=new Map;for(let h of s.slots){let u={index:o.length,name:h.name,bone:n(h.bone),attachment:h.attachment??null,color:O(h.color)};o.push(u),r.set(u.name,u);}let a=h=>{let u=r.get(h);if(!u)throw new Error(`no slot ${h}`);return u},i=[];for(let h of s.constraints??[])if(h.type==="ik")i.push({type:"ik",index:i.length,name:h.name,bones:h.bones.map(n),target:n(h.target),mix:h.mix??1,bendDirection:h.bendPositive===false?-1:1});else if(h.type==="transform"){let u=[],m=new Set;for(let[y,x]of Object.entries(h.properties??{})){let g=[];for(let[w,M]of Object.entries(x.to??{}))m.add(w),g.push({prop:w,offset:M.offset??0,max:M.max??1,scale:M.scale??1});g.length&&u.push({prop:y,offset:x.offset??0,to:g});}let f=h.mixX??1,b=h.mixScaleX??1;i.push({type:"transform",index:i.length,name:h.name,source:n(h.source),bones:h.bones.map(n),offsets:{rotate:h.rotation??0,x:h.x??0,y:h.y??0,scaleX:h.scaleX??0,scaleY:h.scaleY??0,shearY:h.shearY??0},mix:{rotate:m.has("rotate")?h.mixRotate??1:0,x:m.has("x")?f:0,y:m.has("y")?h.mixY??f:0,scaleX:m.has("scaleX")?b:0,scaleY:m.has("scaleY")?h.mixScaleY??b:0,shearY:m.has("shearY")?h.mixShearY??1:0},properties:u});}let p=new Map,l=[],c=[];for(let h of s.skins){let u={name:h.name,attachments:new Map};for(let[m,f]of Object.entries(h.attachments??{})){let b=a(m).index,y=new Map;u.attachments.set(b,y);for(let[x,g]of Object.entries(f)){let w=g.type??"region";w==="linkedmesh"?c.push({skin:u,slot:b,key:x,a:g}):y.set(x,Kt(x,g,w));}}p.set(u.name,u),l.push(u.name);}for(let{skin:h,slot:u,key:m,a:f}of c){let y=(p.get(f.skin??"default")??h).attachments.get(u)?.get(f.source??f.parent);if(!y||y.type!=="mesh")throw new Error(`linked mesh ${h.name}/${m}: no source mesh`);h.attachments.get(u).set(m,{...y,key:m,path:f.path??f.name??m,width:f.width??y.width,height:f.height??y.height,color:O(f.color)});}let d={width:s.skeleton?.width??0,height:s.skeleton?.height??0,x:s.skeleton?.x??0,y:s.skeleton?.y??0,bones:t,slots:o,constraints:i,skins:p,skinOrder:l,animations:new Map,events:Object.keys(s.events??{}),bone:n,slot:a};for(let[h,u]of Object.entries(s.animations??{}))d.animations.set(h,Yt(h,u,d));return d}function Kt(s,t,e){let n=t.path??t.name??s;if(e==="mesh"){let o=Float32Array.from(t.uvs),r=o.length/2,a=t.vertices;return {type:"mesh",key:s,path:n,uvs:o,triangles:Uint16Array.from(t.triangles),vertices:Float32Array.from(a),weighted:a.length>o.length,vertexCount:r,width:t.width??0,height:t.height??0,color:O(t.color)}}return {type:"region",key:s,path:n,x:t.x??0,y:t.y??0,rotation:t.rotation??0,scaleX:t.scaleX??1,scaleY:t.scaleY??1,width:t.width??0,height:t.height??0,color:O(t.color)}}var Dt=new WeakMap;function we(s){let t=Dt.get(s);if(t)return t;t=new Map;for(let e of s.skins.values())for(let n of e.attachments.values())for(let o of n.values())t.has(o.path)||t.set(o.path,{w:o.width,h:o.height});return Dt.set(s,t),t}function Se(s,t){let e=s.skins.get(t);if(!e)return [];let n=new Set;for(let o of e.attachments.values())for(let r of o.values())n.add(r.path);return [...n]}var j=Math.PI/180,yt=1e-5,et=class{constructor(t){this.bone=t;}bone;x=0;y=0;rotation=0;scaleX=1;scaleY=1;shearX=0;shearY=0;a=1;b=0;c=0;d=1;worldX=0;worldY=0;world=0;local=0;copyLocal(t){this.x=t.x,this.y=t.y,this.rotation=t.rotation,this.scaleX=t.scaleX,this.scaleY=t.scaleY,this.shearX=t.shearX,this.shearY=t.shearY;}update(t){this.world!==t.updateId&&this.updateWorldTransform(t);}updateWorldTransform(t){this.local===t.updateId?this.updateLocalTransform(t):this.world=t.updateId;let e=(this.rotation+this.shearX)*j,n=(this.rotation+90+this.shearY)*j,o=Math.cos(e)*this.scaleX,r=Math.cos(n)*this.scaleY,a=Math.sin(e)*this.scaleX,i=Math.sin(n)*this.scaleY,p=this.bone.parent;if(!p){let c=t.scaleX,d=t.scaleY;this.a=o*c,this.b=r*c,this.c=a*d,this.d=i*d,this.worldX=this.x*c+t.x,this.worldY=this.y*d+t.y;return}let l=p.applied;this.worldX=l.a*this.x+l.b*this.y+l.worldX,this.worldY=l.c*this.x+l.d*this.y+l.worldY,this.a=l.a*o+l.b*a,this.b=l.a*r+l.b*i,this.c=l.c*o+l.d*a,this.d=l.c*r+l.d*i;}updateLocalTransform(t){this.local=0,this.world=t.updateId;let e=this.bone.parent;if(!e){this.x=(this.worldX-t.x)/t.scaleX,this.y=(this.worldY-t.y)/t.scaleY,this.set5(this.a/t.scaleX,this.b/t.scaleX,this.c/t.scaleY,this.d/t.scaleY);return}let n=e.applied,o=1/(n.a*n.d-n.b*n.c),r=n.d*o,a=n.b*o,i=n.c*o,p=n.a*o,l=this.worldX-n.worldX,c=this.worldY-n.worldY;this.x=l*r-c*a,this.y=c*p-l*i,this.set5(r*this.a-a*this.c,r*this.b-a*this.d,p*this.c-i*this.a,p*this.d-i*this.b);}set5(t,e,n,o){this.shearX=0;let r=t*t+n*n,a=e*e+o*o;if(r>yt){let i=Math.atan2(n,t)/j;this.rotation=i,this.scaleX=Math.sqrt(r),this.scaleY=Math.sqrt(a),a>yt?(this.shearY=Math.atan2(o,e)/j,t*o-e*n<0?(this.scaleY=-this.scaleY,this.shearY+=90-i):this.shearY-=90+i,this.shearY>180?this.shearY-=360:this.shearY<=-180&&(this.shearY+=360)):this.shearY=0;}else this.scaleX=0,this.scaleY=Math.sqrt(a),this.shearY=0,this.rotation=a>yt?Math.atan2(o,e)/j-90:0;}modifyLocal(t){this.local===t.updateId&&this.updateLocalTransform(t),this.world=0,this.resetWorld(t);}modifyWorld(t){this.local=t.updateId,this.world=t.updateId,this.resetWorld(t);}resetWorld(t){for(let e of this.bone.children){let n=e.applied;n.world===t.updateId&&(n.local===t.updateId&&n.updateLocalTransform(t),n.world=0,n.resetWorld(t));}}},nt=class{constructor(t){this.data=t;this.pose=new et(this),this.applied=new et(this),this.setupPose();}data;pose;applied;parent=null;children=[];sorted=false;setupPose(){let t=this.data,e=this.pose;e.x=t.x,e.y=t.y,e.rotation=t.rotation,e.scaleX=t.scaleX,e.scaleY=t.scaleY,e.shearX=0,e.shearY=0;}},bt=class{constructor(t,e){this.data=t;this.bone=e;this.color={...t.color},this.attachmentKey=t.attachment;}data;bone;color;attachmentKey;attachment=null},ot=class{constructor(t){this.data=t;this.bones=t.bones.map(e=>new nt(e));for(let e of this.bones)e.data.parent&&(e.parent=this.bones[e.data.parent.index],e.parent.children.push(e));this.slots=t.slots.map(e=>new bt(e,this.bones[e.bone.index])),this.constraints=t.constraints.map(e=>At(e,this)),this.updateCache();}data;bones;slots;constraints;skins=[];scaleX=1;scaleY=1;x=0;y=0;updateId=0;cache=[];bone(t){return this.bones[this.data.bone(t).index]}slot(t){return this.slots[this.data.slot(t).index]}setSkins(t){this.skins=[...t],this.resolveAttachments();}getAttachment(t,e){for(let n=this.skins.length-1;n>=0;n--){let o=this.skins[n].attachments.get(t)?.get(e);if(o)return o}return null}resolveAttachments(){for(let t of this.slots)t.attachment=t.attachmentKey?this.getAttachment(t.data.index,t.attachmentKey):null;}setupPose(){for(let t of this.bones)t.setupPose();for(let t of this.constraints)t.setupPose();for(let t of this.slots)Object.assign(t.color,t.data.color),t.attachmentKey=t.data.attachment;}updateWorldTransform(){this.updateId++;for(let t of this.bones)t.applied.copyLocal(t.pose),t.applied.world=0,t.applied.local=0;for(let t of this.cache)t instanceof nt?t.applied.update(this):t.update(this);}updateCache(){this.cache=[];for(let t of this.bones)t.sorted=false;for(let t of this.constraints)t.sort(this);for(let t of this.bones)this.sortBone(t);}sortBone(t){t.sorted||(t.parent&&this.sortBone(t.parent),t.sorted=true,this.cache.push(t));}sortReset(t){for(let e of t)e.sorted&&this.sortReset(e.children),e.sorted=false;}pushConstraint(t){this.cache.push(t);}};var Xt=class{constructor(t,e,n=.2){this.skeleton=t;this.data=e;this.defaultMix=n;this.snapshot=new Float32Array(t.bones.length*5),this.slotSnapshot=new Float32Array(t.slots.length*4),this.ikSnapshot=new Float32Array(t.constraints.length);}skeleton;data;defaultMix;track=null;previous=null;mixTime=0;mixDuration=0;listeners=new Map;snapshot;slotSnapshot;ikSnapshot;blink=null;setBlink(t){let e=t?this.data.animations.get(t.animation):void 0;if(!t||!e){this.blink=null;return}let n={bones:new Set(t.bones.map(o=>this.data.bone(o).index)),slots:new Set(t.slots.map(o=>this.data.slot(o).index))};this.blink={source:e,filter:n,options:t,wait:this.nextBlink(t),at:-1};}blinkNow(){this.blink&&(this.blink.at=0);}blinking(){return (this.blink?.at??-1)>=0}setRandom(t){this.random=t;}random=Math.random;nextBlink(t){return t.every[0]+this.random()*(t.every[1]-t.every[0])}names(){return [...this.data.animations.keys()]}has(t){return this.data.animations.has(t)}play(t,e={}){let n=this.data.animations.get(t);if(!n)return false;let o=e.mix??this.defaultMix;return this.previous=this.track&&o>0?this.track:null,this.mixTime=0,this.mixDuration=this.previous?o:0,this.track={animation:n,time:Math.max(0,e.from??0),speed:e.speed??1,loop:e.loop??true,done:false},true}current(){return this.track?.animation.name??null}time(){return this.track?this.local(this.track):0}duration(){return this.track?.animation.duration??0}finished(){return this.track?.done??false}setSpeed(t){this.track&&(this.track.speed=t);}on(t,e){let n=this.listeners.get(t)??new Set;return n.add(e),this.listeners.set(t,n),()=>n.delete(e)}update(t){let e=[],n=this.track;if(n&&!n.done){let o=n.time;n.time+=Math.max(0,t)*n.speed,this.collect(n,o,n.time,e),!n.loop&&n.time>=n.animation.duration&&(n.time=n.animation.duration,n.done=true,e.push({name:"end",animation:n.animation.name}));}if(this.previous){let o=this.previous;o.time+=Math.max(0,t)*o.speed,this.mixTime+=Math.max(0,t),this.mixTime>=this.mixDuration&&(this.previous=null);}this.advanceBlink(Math.max(0,t)),this.pose();for(let o of e){for(let r of this.listeners.get(o.name)??[])r(o);for(let r of this.listeners.get("*")??[])r(o);}}pose(){let t=this.skeleton,e=this.previous;e&&this.mixDuration>0&&(t.setupPose(),e.animation.apply(t,this.local(e)),this.save()),t.setupPose(),this.track&&this.track.animation.apply(t,this.local(this.track)),e&&this.mixDuration>0&&this.blendFromSaved(Math.min(1,this.mixTime/this.mixDuration));let n=this.blink;n&&n.at>=0&&n.source.applyOnly(t,n.options.from+n.at,n.filter),t.resolveAttachments();}advanceBlink(t){let e=this.blink;if(e){if(this.track?.animation.touches(e.filter)){e.at=-1;return}if(e.at>=0){e.at+=t,e.at>=e.options.to-e.options.from&&(e.at=-1,e.wait=this.nextBlink(e.options));return}e.wait-=t,e.wait<=0&&(e.at=0);}}local(t){let e=t.animation.duration;return e<=0?0:t.loop?t.time%e:Math.min(t.time,e)}collect(t,e,n,o){let r=t.animation.duration;if(r<=0||n<=e)return;let a=Math.floor(e/r),i=t.loop?Math.floor(n/r):0;for(let p=a;p<=i;p++)for(let l of t.animation.events){let c=p*r+l.time;c>=e&&(c<n||!t.loop&&c<=n)&&o.push({name:l.name,animation:t.animation.name});}}save(){let t=this.skeleton;t.bones.forEach((e,n)=>{let o=e.pose;this.snapshot.set([o.x,o.y,o.rotation,o.scaleX,o.scaleY],n*5);}),t.slots.forEach((e,n)=>this.slotSnapshot.set([e.color.r,e.color.g,e.color.b,e.color.a],n*4)),t.constraints.forEach((e,n)=>{e instanceof I&&(this.ikSnapshot[n]=e.mix);});}blendFromSaved(t){let e=this.skeleton,n=(o,r)=>o+(r-o)*t;e.bones.forEach((o,r)=>{let a=this.snapshot,i=o.pose,p=r*5;i.x=n(a[p],i.x),i.y=n(a[p+1],i.y);let l=i.rotation-a[p+2];l-=Math.round(l/360)*360,i.rotation=a[p+2]+l*t,i.scaleX=n(a[p+3],i.scaleX),i.scaleY=n(a[p+4],i.scaleY);}),e.slots.forEach((o,r)=>{let a=this.slotSnapshot;o.color.r=n(a[r*4],o.color.r),o.color.g=n(a[r*4+1],o.color.g),o.color.b=n(a[r*4+2],o.color.b),o.color.a=n(a[r*4+3],o.color.a);}),e.constraints.forEach((o,r)=>{o instanceof I&&(o.mix=n(this.ikSnapshot[r],o.mix));});}};var Et=Math.PI/180,jt=new Float32Array([0,1,0,0,1,0,1,1]),Gt=new Uint16Array([0,1,2,2,3,0]),Bt=new WeakMap;function Vt(s){let t=Bt.get(s);if(t)return t;let e=-s.width/2*s.scaleX,n=-s.height/2*s.scaleY,o=s.width/2*s.scaleX,r=s.height/2*s.scaleY,a=Math.cos(s.rotation*Et),i=Math.sin(s.rotation*Et),p=(l,c)=>[l*a-c*i+s.x,l*i+c*a+s.y];return t=Float32Array.from([...p(e,n),...p(e,r),...p(o,r),...p(o,n)]),Bt.set(s,t),t}function Ct(s,t,e,n){if(e.type==="region"){let o=n&&n.length===8?n:new Float32Array(8),r=Vt(e),a=t.bone.applied;for(let i=0;i<8;i+=2){let p=r[i],l=r[i+1];o[i]=p*a.a+l*a.b+a.worldX,o[i+1]=p*a.c+l*a.d+a.worldY;}return {positions:o,uvs:jt,triangles:Gt}}return Ut(s,t,e,n)}function Ut(s,t,e,n){let o=e.vertexCount*2,r=n&&n.length===o?n:new Float32Array(o),a=e.vertices;if(e.weighted){let i=0;for(let p=0;p<o;p+=2){let l=a[i++],c=0,d=0;for(let h=0;h<l;h++,i+=4){let u=s.bones[a[i]].applied,m=a[i+1],f=a[i+2],b=a[i+3];c+=(m*u.a+f*u.b+u.worldX)*b,d+=(m*u.c+f*u.d+u.worldY)*b;}r[p]=c,r[p+1]=d;}}else {let i=t.bone.applied;for(let p=0;p<o;p+=2){let l=a[p],c=a[p+1];r[p]=l*i.a+c*i.b+i.worldX,r[p+1]=l*i.c+c*i.d+i.worldY;}}return {positions:r,uvs:e.uvs,triangles:e.triangles}}var _t=1;function De(...s){let t={v:1,parts:{},colors:{}};for(let e of s)e&&(Object.assign(t.parts,e.parts),Object.assign(t.colors,e.colors));return t}function Xe(s){if(!s||typeof s!="object")return null;let t=s;if(t.v!==1)return null;let e={},n={};if(t.parts&&typeof t.parts=="object")for(let[o,r]of Object.entries(t.parts))(r===null||typeof r=="string")&&(e[o]=r);if(t.colors&&typeof t.colors=="object")for(let[o,r]of Object.entries(t.colors))typeof r=="string"&&/^#[0-9a-f]{6}$/i.test(r)&&(n[o]=r);return {v:1,parts:e,colors:n}}var Ot=class{constructor(t,e=()=>true){this.rig=t;this.drawable=e;let n=(o,r)=>t.colorTargets.find(a=>(a.into??"tint")===r&&a.slotPrefixes.some(i=>o.startsWith(i)))?.id??null;this.slotTarget=t.data.slots.map(o=>n(o.name,"tint")),this.slotArt=t.data.slots.map(o=>n(o.name,"art")),this.rebuildLists(),this.init();}rig;drawable;chosen=new Map;hidden=new Map;colors=new Map;lists=new Map;listeners=new Set;slotTarget;slotArt;face=null;emotionFace=null;speech="rest";setDrawable(t){let e=new Set(this.rig.partTypes.filter(n=>!this.count(n.id)).map(n=>n.id));this.drawable=t,this.rebuildLists();for(let n of this.rig.partTypes){if(n.auto)continue;let o=this.chosen.get(n.id);(o&&!this.lists.get(n.id).includes(o)||!o&&e.has(n.id))&&this.chosen.set(n.id,this.first(n));}this.emit({kind:"part",type:"*",skin:null});}on(t){return this.listeners.add(t),()=>this.listeners.delete(t)}emit(t){for(let e of [...this.listeners])e(t);}typeDef(t){return this.rig.partTypes.find(e=>e.id===t)}list(t){return this.lists.get(t)??[]}count(t){return this.list(t).length}part(t){return this.chosen.get(t)??null}index(t){let e=this.part(t);return e?this.list(t).indexOf(e):-1}isHidden(t){return this.hidden.get(t)??false}isWorn(t){return this.part(t)!==null&&!this.isHidden(t)}color(t){return this.colors.get(t)??null}wornSkins(){let t=new Map;for(let l of this.rig.partTypes)t.set(l.id,!l.auto&&this.isWorn(l.id)?this.part(l.id):null);let e={worn:l=>t.get(l)??null,setWorn:(l,c)=>t.set(l,c),exists:l=>this.rig.data.skins.has(l)&&this.drawable(l)};for(let l of this.rig.rules)l.apply(e);let n=this.rig.expressions,o=this.face??this.emotionFace,r=o?n?.faces[o]:void 0;for(let[l,c]of Object.entries(r??{}))t.get(l)&&e.exists(c)&&t.set(l,c);let a=this.speech!=="rest"?n?.speech:void 0,i=a?.visemes[this.speech];a&&i&&t.get(a.type)&&e.exists(i)&&t.set(a.type,i);let p=[];for(let l of this.rig.partTypes){let c=t.get(l.id);c&&p.push(c);}return p}slotColor(t){let e=this.slotTarget[t];return e?this.color(e):null}artColor(t){let e=this.slotArt[t];return e?this.color(e):null}expression(){return this.face}equip(t,e){let n=this.lists.get(t);if(!n)return;let o;if(e===null||e===-1)o=null;else if(typeof e=="number")o=n[Math.max(0,Math.min(n.length-1,e))]??null;else if(n.includes(e))o=e;else return;o===null&&!this.typeDef(t)?.canHide||(this.chosen.set(t,o),this.emit({kind:"part",type:t,skin:o}));}unequip(t){this.equip(t,null);}setHidden(t,e){this.typeDef(t)?.canHide&&(this.hidden.set(t,e),this.emit({kind:"hidden",type:t,hidden:e}));}next(t){let e=this.count(t);if(!e)return;let n=this.index(t);this.typeDef(t)?.canHide?this.equip(t,n>=e-1?-1:n+1):this.equip(t,(n+1)%e);}prev(t){let e=this.count(t);if(!e)return;let n=this.index(t);this.typeDef(t)?.canHide?this.equip(t,n<=-1?e-1:n-1):this.equip(t,(n-1+e)%e);}setColor(t,e){this.colors.set(t,e),this.emit({kind:"color",target:t,color:e});}setExpression(t){let e=t&&this.rig.expressions?.faces[t]?t:null;e!==this.face&&(this.face=e,this.emit({kind:"expression",name:e}));}setEmotion(t){let e=this.rig.expressions?.emotions?.[t]??null,n=e&&this.rig.expressions?.faces[e]?e:null;n!==this.emotionFace&&(this.emotionFace=n,this.emit({kind:"expression",name:this.face??n}));}setSpeech(t){t!==this.speech&&(this.speech=t,this.emit({kind:"speech",viseme:t}));}randomize(t=Math.random){for(let e of this.rig.partTypes){if(e.auto)continue;let n=this.count(e.id);n&&this.equip(e.id,e.canHide&&t()<.3?-1:Math.floor(t()*n));}}reset(){this.init();for(let t of this.rig.partTypes)this.emit({kind:"part",type:t.id,skin:this.part(t.id)});}toLook(){let t={};for(let n of this.rig.partTypes)n.auto||(t[n.id]=this.isWorn(n.id)?this.part(n.id):null);let e={};for(let[n,o]of this.colors)o&&(e[n]=o);return {v:1,parts:t,colors:e}}applyLook(t){for(let[e,n]of Object.entries(t.parts??{}))n===void 0||this.typeDef(e)?.auto||(this.equip(e,n),n!==null&&this.part(e)===n&&this.hidden.set(e,false));for(let[e,n]of Object.entries(t.colors??{}))n&&this.setColor(e,n);}rebuildLists(){for(let t of this.rig.partTypes)this.lists.set(t.id,this.rig.data.skinOrder.filter(e=>e.startsWith(t.skinPrefix)&&this.drawable(e)));}first(t){return this.lists.get(t.id)?.[0]??null}init(){this.chosen.clear(),this.hidden.clear(),this.colors.clear();for(let t of this.rig.partTypes)this.chosen.set(t.id,t.auto?null:this.first(t));}};var Lt=new WeakMap;function Le(s,t){let e=Lt.get(s);if(e)return e;e=new Map;let n=new ot(s);n.setupPose(),n.updateWorldTransform();let[o,r]=t.light;for(let a of s.skins.values())for(let[i,p]of a.attachments)for(let l of p.values()){if(e.has(l.path)||t.skip?.some(b=>l.path.startsWith(b)))continue;let c=Ct(n,n.slots[i],l,null),d=Zt(c.positions,c.uvs,l.width,l.height);if(!d)continue;let h=d.a*d.d-d.b*d.c;if(Math.abs(h)<1e-9)continue;let u=(d.d*o-d.b*r)/h,m=(-d.c*o+d.a*r)/h,f=Math.hypot(u,m)||1;e.set(l.path,{x:u/f,y:m/f});}return Lt.set(s,e),e}function Zt(s,t,e,n){let o=t.length/2;if(o<3)return null;let r=0,a=0,i=0,p=0;for(let y=0;y<o;y++)r+=t[y*2]*e,a+=t[y*2+1]*n,i+=s[y*2],p+=s[y*2+1];r/=o,a/=o,i/=o,p/=o;let l=0,c=0,d=0,h=0,u=0,m=0,f=0;for(let y=0;y<o;y++){let x=t[y*2]*e-r,g=t[y*2+1]*n-a,w=s[y*2]-i,M=s[y*2+1]-p;l+=x*x,c+=x*g,d+=g*g,h+=w*x,u+=w*g,m+=M*x,f+=M*g;}let b=l*d-c*c;return Math.abs(b)<1e-9?null:{a:(h*d-u*c)/b,b:(u*l-h*c)/b,c:(m*d-f*c)/b,d:(f*l-m*c)/b}}
2
- export{De as A,Xe as B,Ot as C,Le as D,Tt as a,Qt as b,zt as c,Rt as d,Ft as e,te as f,ee as g,ne as h,oe as i,se as j,re as k,ie as l,le as m,ce as n,he as o,O as p,dt as q,ve as r,we as s,Se as t,nt as u,bt as v,ot as w,Xt as x,Ct as y,_t as z};