@fabi-play/engine 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var zn=Object.defineProperty;var Ci=(s,r,e)=>r in s?zn(s,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[r]=e;var Li=(s,r)=>{for(var e in r)zn(s,e,{get:r[e],enumerable:!0})};var h=(s,r,e)=>Ci(s,typeof r!="symbol"?r+"":r,e);var Fn={};Li(Fn,{AnimatedSprite:()=>ae,Atlas:()=>Le,AvatarPainter:()=>Ve,AvatarsNode:()=>Bt,BitmapFont:()=>ht,DEFAULT_FONT:()=>Kr,EASE:()=>_e,Group:()=>$e,HALO:()=>We,MAX_LAYERS:()=>St,NameTags:()=>Ie,Node:()=>oe,NodePool:()=>Dt,Particles:()=>et,STAGE_HEIGHT:()=>q,Shape:()=>fe,ShelfPacker:()=>Ft,Sound:()=>dt,Sprite:()=>re,TIERS:()=>be,Text:()=>pe,Timeline:()=>mt,Tweens:()=>pt,avatarPortrait:()=>Ds,blur:()=>pi,brightness:()=>ai,colorMatrix:()=>mi,contrast:()=>li,createAvatarRenderer:()=>Bs,createEngine:()=>ei,createRenderer:()=>lt,dropShadow:()=>bi,grayscale:()=>ci,handsOf:()=>dr,hits:()=>It,hueRotate:()=>fi,invert:()=>di,nodePool:()=>wi,packColor:()=>Re,parseBMFont:()=>ft,parseColor:()=>K,pickTier:()=>br,playerColor:()=>Nt,rendererOrder:()=>jr,rng:()=>Qn,saturate:()=>ui,sepia:()=>hi,shader:()=>yi,shapeBounds:()=>hr,tier:()=>Se,tint:()=>oi,touching:()=>mr,wrists:()=>Jr});var Pi=33,Cr={nose:0,leftShoulder:11,rightShoulder:12,leftElbow:13,rightElbow:14,leftWrist:15,rightWrist:16,leftHip:23,rightHip:24,leftKnee:25,rightKnee:26,leftAnkle:27,rightAnkle:28};var Ni=4,vt=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"];var Ii={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},No=Ii["6-8"];var $n=(s,r)=>s?{x:s.x+r.x*s.w,y:s.y+r.y*s.h}:{x:r.x,y:r.y};var Oi=12,Bi=Pi*4,Di=s=>Oi+s*Bi,Io=Di(Ni);var Gi=s=>s.startsWith("fabi-play.")?`fablee-play.${s.slice(10)}`:null;function Vn(s,r,e=Gi(r)){if(!(!s||!e))try{let t=s.getItem(e);if(t===null)return;s.getItem(r)===null&&s.setItem(r,t),s.removeItem(e)}catch{}}var Wn=globalThis.FabiPlay?.avatars;if(!Wn)throw new Error("[engine] fabi-play-engine.lite.js needs fabi-play.js (with FabiPlay.avatars) loaded before it");var{avatarById:Ke,avatarShapes:Xn,BAND_BODY:Bo,DEFAULT_AVATAR:Ye,drawShapes:Lr,frameOf:qn,iconShapes:jn}=Wn;var ve=()=>Float64Array.of(1,0,0,1,0,0);function ee(s,r,e,t,n,i,o){let a=n?Math.cos(n):1,l=n?Math.sin(n):0,u=a*i,c=l*i,f=-l*o,d=a*o;if(!r)return s[0]=u,s[1]=c,s[2]=f,s[3]=d,s[4]=e,s[5]=t,s;let b=r[0],g=r[1],p=r[2],m=r[3];return s[0]=b*u+p*c,s[1]=g*u+m*c,s[2]=b*f+p*d,s[3]=g*f+m*d,s[4]=b*e+p*t+r[4],s[5]=g*e+m*t+r[5],s}function Yn(s,r,e){let t=s[0]*s[3]-s[1]*s[2];if(Math.abs(t)<1e-12)return null;let n=r-s[4],i=e-s[5];return[(s[3]*n-s[2]*i)/t,(-s[1]*n+s[0]*i)/t]}var Kn={white:16777215,black:0,red:16711680,transparent:0},wt=new Map;function K(s){if(typeof s=="number")return[s&16777215,1];let r=wt.get(s);if(r)return r;let e=[16777215,1],t=s.trim().toLowerCase();if(t[0]==="#"){let n=t.slice(1),i=n.length<=4?[...n].map(a=>a+a).join(""):n,o=parseInt(i.slice(0,6),16);Number.isFinite(o)&&(e=[o,i.length===8?parseInt(i.slice(6,8),16)/255:1])}else if(t.startsWith("rgb")){let n=t.match(/-?\d*\.?\d+%?/g)?.map(u=>u.endsWith("%")?parseFloat(u)/100*255:parseFloat(u))??[],[i=255,o=255,a=255]=n,l=n[3]===void 0?1:t.match(/,\s*[\d.]+%\s*\)$/)?n[3]/255:n[3];e=[(Pr(i)<<16|Pr(o)<<8|Pr(a))>>>0,Math.min(Math.max(l,0),1)]}else if(t in Kn)e=[Kn[t],t==="transparent"?0:1];else if(typeof document<"u"){let n=document.createElement("canvas").getContext("2d");if(n){n.fillStyle="#ffffff",n.fillStyle=t;let i=n.fillStyle;if(i!==t)return wt.set(s,e=K(i)),e}}return wt.size>512&&wt.clear(),wt.set(s,e),e}var Pr=s=>Math.min(Math.max(Math.round(s),0),255);function Re(s,r,e=!1){let t=Math.min(Math.max(r,0),1),n=(s>>16&255)*t,i=(s>>8&255)*t,o=(s&255)*t,a=e?0:t*255;return(Math.round(a)<<24|Math.round(o)<<16|Math.round(i)<<8|Math.round(n))>>>0}var Ue=(s,r=1)=>`rgba(${s>>16&255},${s>>8&255},${s&255},${r})`;function Nr(s,r){if(s===16777215)return r;if(r===16777215)return s;let e=t=>Math.round((s>>t&255)*(r>>t&255)/255);return(e(16)<<16|e(8)<<8|e(0))>>>0}var _e={linear:s=>s,quadIn:s=>s*s,quadOut:s=>s*(2-s),quadInOut:s=>s<.5?2*s*s:-1+(4-2*s)*s,cubicOut:s=>1-(1-s)**3,sineInOut:s=>-(Math.cos(Math.PI*s)-1)/2,backOut:s=>1+(1.70158+1)*(s-1)**3+1.70158*(s-1)**2,elasticOut:s=>s===0||s===1?s:2**(-10*s)*Math.sin((s*10-.75)*(2*Math.PI/3))+1,bounceOut:s=>s<1/2.75?7.5625*s*s:s<2/2.75?7.5625*(s-=1.5/2.75)*s+.75:s<2.5/2.75?7.5625*(s-=2.25/2.75)*s+.9375:7.5625*(s-=2.625/2.75)*s+.984375};function Qn(s){let r=s>>>0;return()=>{r=r+1831565813>>>0;let e=r;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}var T={cap:0,epoch:0,x:new Float64Array(0),y:new Float64Array(0),rot:new Float64Array(0),sx:new Float64Array(0),sy:new Float64Array(0),alpha:new Float64Array(0),la:new Float64Array(0),lb:new Float64Array(0),lc:new Float64Array(0),ld:new Float64Array(0),world:new Float64Array(0),tint:new Uint32Array(0),flags:new Uint8Array(0),moved:new Uint8Array(0),dirty:new Uint8Array(0),gen:new Uint32Array(0),parent:new Int32Array(0),first:new Int32Array(0),next:new Int32Array(0),prev:new Int32Array(0),stamp:new Uint32Array(0),pass:0,free:new Int32Array(0),freeHead:0,freeCount:0,top:2},Ce=[],Ui="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function Zn(s){let r=T;for(let t of Ui){let n=r[t],i=new n.constructor(t==="world"?s*6:s);i.set(n),r[t]=i}let e=new Int32Array(s);for(let t=0;t<T.freeCount;t++)e[t]=T.free[(T.freeHead+t)%T.cap];for(T.free=e,T.freeHead=0,T.cap=s,T.epoch++;Ce.length<s;)Ce.push(null)}function Or(s){T.x[s]=T.y[s]=T.rot[s]=0,T.sx[s]=T.sy[s]=T.alpha[s]=1,T.la[s]=T.ld[s]=1,T.lb[s]=T.lc[s]=0;let r=s*6,e=T.world;e[r]=e[r+3]=1,e[r+1]=e[r+2]=e[r+4]=e[r+5]=0,T.tint[s]=16777215,T.flags[s]=3,T.moved[s]=1,T.dirty[s]=0,T.parent[s]=T.first[s]=T.next[s]=T.prev[s]=-1}Zn(256);Or(0);T.flags[0]=0;Or(1);T.flags[1]=0;function Jn(){let s;if(T.freeCount){s=T.free[T.freeHead],T.freeHead=(T.freeHead+1)%T.cap,T.freeCount--;let r=Ce[s];r&&(r._i=0,r._g=-1,Ce[s]=null)}else T.top===T.cap&&Zn(T.cap*2),s=T.top++;return Or(s),s}function Br(s,r){Yt(s);for(let t=T.first[s];t>=0;){let n=T.next[t];T.parent[t]=T.next[t]=T.prev[t]=-1,t=n}T.first[s]=-1,T.flags[s]=T.flags[s]&-3,T.moved[s]=0;let e=T.gen[s]+1;T.gen[s]=e,e!==4294967295&&(r&&(Ce[s]=r),T.free[(T.freeHead+T.freeCount)%T.cap]=s,T.freeCount++)}function es(s){for(let r=0;r<Ce.length;r++){let e=Ce[r];e&&s(e)&&(e._i=0,e._g=-1,Ce[r]=null)}}function ts(s,r){Yt(s);let e=T.first[r];T.parent[s]=r,T.next[s]=e,T.prev[s]=-1,e>=0&&(T.prev[e]=s),T.first[r]=s,T.moved[s]=1}function Yt(s){let r=T.parent[s];if(r<0)return;let e=T.next[s],t=T.prev[s];t>=0?T.next[t]=e:T.first[r]=e,e>=0&&(T.prev[e]=t),T.parent[s]=T.next[s]=T.prev[s]=-1}var kt={root:-1,gen:-1,world:new Float64Array(6)};function rs(s){let r=++T.pass,e=T.world,t=s*6,n=kt.world,i=kt.root!==s||kt.gen!==T.gen[s];for(let o=0;o<6;o++)n[o]!==e[t+o]&&(i=!0),n[o]=e[t+o];kt.root=s,kt.gen=T.gen[s],T.stamp[s]=i?r:r-1}function ns(s){T.stamp[s]=T.pass}function ss(s){for(let r=T.first[s];r>=0;){let e=T.next[r];ss(r),r=e}Br(s)}var Ir=typeof FinalizationRegistry=="function"?new FinalizationRegistry(s=>T.gen[s.i]===s.g&&ss(s.i)):null;function Dr(s){s._reg||!Ir||(s._reg=!0,Ir.register(s,{i:s._i,g:s._g},s))}function is(s){s._reg&&Ir.unregister(s)}function At(s){if(s){for(let r=0;r<s.length;r++)if(s[r].enabled)return!0}return!1}function os(s,r){let e=0;for(let t=0;t<s.length;t++){let n=s[t];n.enabled&&n.pad&&(e+=n.pad(r))}return e}var te={gl:null,c2d:null,live:null};var B=new Float64Array(3),St=4,Hi=1,Tt=()=>Hi++;var W=ve(),_=T,oe=class{constructor(r){h(this,"kernel",r);h(this,"_i",Jn());h(this,"_g",_.gen[this._i]);h(this,"_wv",null);h(this,"_wi",-1);h(this,"_we",-1);h(this,"blend","normal");h(this,"_data",null);h(this,"parent",null);h(this,"hitRadius",null);h(this,"clip",null);h(this,"mask",null);h(this,"filters",null);h(this,"_z",0);h(this,"anchorX",0);h(this,"anchorY",0);h(this,"_pool",null);h(this,"_free",!1);h(this,"_reg",!1)}get x(){return _.x[this._i]}set x(r){let e=this._i||1;_.x[e]=r,_.moved[e]=1}get y(){return _.y[this._i]}set y(r){let e=this._i||1;_.y[e]=r,_.moved[e]=1}get rotation(){return _.rot[this._i]}set rotation(r){let e=this._i||1;_.rot[e]=r,_.dirty[e]=_.moved[e]=1}get scaleX(){return _.sx[this._i]}set scaleX(r){let e=this._i||1;_.sx[e]=r,_.dirty[e]=_.moved[e]=1}get scaleY(){return _.sy[this._i]}set scaleY(r){let e=this._i||1;_.sy[e]=r,_.dirty[e]=_.moved[e]=1}get alpha(){return _.alpha[this._i]}set alpha(r){let e=this._i||1;_.alpha[e]=r,_.moved[e]=1}get visible(){return(_.flags[this._i]&1)!==0}set visible(r){let e=this._i||1;r?_.flags[e]=_.flags[e]|1:_.flags[e]=_.flags[e]&-2,_.moved[e]=1}get destroyed(){return _.gen[this._i]!==this._g}get world(){let r=this._i||1;return(this._wi!==r||this._we!==_.epoch)&&(this._wv=_.world.subarray(r*6,r*6+6),this._wi=r,this._we=_.epoch),this._wv}get data(){return this._data??(this._data={})}set data(r){this._data=r}get scale(){return this.scaleX}set scale(r){this.scaleX=this.scaleY=r}get z(){return this._z}set z(r){r!==this._z&&(this._z=r,this.parent&&(this.parent.sortDirty=!0))}get tint(){return _.tint[this._i]}set tint(r){_.tint[this._i||1]=typeof r=="number"?r&16777215:K(r)[0]}set anchor(r){typeof r=="number"?this.anchorX=this.anchorY=r:(this.anchorX=r.x,this.anchorY=r.y)}get width(){return 0}set width(r){}get height(){return 0}set height(r){}set(r){for(let e in r){let t=r[e];t!==void 0&&(this[e]=t)}return this}destroy(){this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),Br(this._i,this),is(this),this.kernel.tweens.stopAll(this),this._pool?.forget(this))}updateWorld(){let r=this.parent?this.parent.updateWorld():null;return ee(this.world,r,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(r,e,t){}};function cs(s){es(r=>r.kernel===s)}var Gr=!1,as=Object.freeze([]),$e=class s extends oe{constructor(e){super(e);h(this,"children",as);h(this,"sortDirty",!1);h(this,"dead",!1);Dr(this)}add(e,...t){this.adopt(e);for(let n=0;n<t.length;n++)this.adopt(t[n]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&ts(e._i,this._i),this.children===as&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||Dr(e)}detach(e){let t=this.children,n=t.indexOf(e);if(n>=0){for(let i=n+1;i<t.length;i++)t[i-1]=t[i];t.pop()}e.parent===this&&(e.parent=null,e.destroyed||Yt(e._i))}clear(){for(let e of this.children)e.destroy()}destroy(){for(let e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(let t of this.children)t.destroyed?t.parent===this&&(t.parent=null):this.children[e++]=t;this.children.length=e}for(let e of this.children)e instanceof s&&e.sweep()}draw(e,t,n){if(Gr)return _.parent[this._i]<0&&!this.destroyed&&ns(this._i),this.drawChildren(e,t,n);Gr=!0;try{this.destroyed||rs(this._i),this.drawChildren(e,t,n)}finally{Gr=!1}}drawChildren(e,t,n){if(this.sortDirty){let l=new Map(this.children.map((u,c)=>[u,c]));this.children.sort((u,c)=>u.z-c.z||l.get(u)-l.get(c)),this.sortDirty=!1}let i=this.children,o=this._i,a=_.stamp[o]===_.pass;for(let l=0;l<i.length;l++){let u=i[l],c=u._i,f=_.alpha[c];if(_.gen[c]!==u._g||!(_.flags[c]&1)||f<=0)continue;if(a||_.moved[c]){_.moved[c]=0,_.stamp[c]=_.pass;let g,p,m,v;if(_.dirty[c]){_.dirty[c]=0;let z=_.rot[c],G=z?Math.cos(z):1,U=z?Math.sin(z):0,ge=_.sx[c],Me=_.sy[c];_.la[c]=g=G*ge,_.lb[c]=p=U*ge,_.lc[c]=m=-U*Me,_.ld[c]=v=G*Me}else g=_.la[c],p=_.lb[c],m=_.lc[c],v=_.ld[c];let x=_.world,S=_.x[c],w=_.y[c],A=c*6,E=o*6,R=x[E],C=x[E+1],I=x[E+2],H=x[E+3];x[A]=R*g+I*p,x[A+1]=C*g+H*p,x[A+2]=R*m+I*v,x[A+3]=C*m+H*v,x[A+4]=R*S+I*w+x[E+4],x[A+5]=C*S+H*w+x[E+5]}let d=t*f,b=Nr(n,_.tint[c]);u.clip||u.mask||u.filters?hs(e,u,d,b):u.draw(e,d,b)}}},Q=new Float64Array(128),He=0,Ur=new Float64Array(8);function Hr(s,r,e,t){r.clip||r.mask||r.filters?hs(s,r,e,t):r.draw(s,e,t)}function hs(s,r,e,t){let n=s.r,i=r.world,o=r.clip,a=!1,l=!1;if(o)if(Math.abs(i[1])<1e-9&&Math.abs(i[2])<1e-9&&He<32){let f=i[0]*o.x+i[4],d=i[0]*(o.x+o.width)+i[4],b=i[3]*o.y+i[5],g=i[3]*(o.y+o.height)+i[5],p=Math.min(f,d),m=Math.max(f,d),v=Math.min(b,g),x=Math.max(b,g);if(He){let w=(He-1)*4;p=Math.max(p,Q[w]),v=Math.max(v,Q[w+1]),m=Math.min(m,Q[w+2]),x=Math.min(x,Q[w+3])}let S=He++*4;Q[S]=p,Q[S+1]=v,Q[S+2]=m,Q[S+3]=x,n.clip(p,v,Math.max(m-p,0),Math.max(x-v,0)),l=!0}else a=!0;let u=r.mask&&r.mask.visible?r.mask:null,c=At(r.filters)?r.filters:null;try{if(a&&n.beginLayer(),u&&n.beginLayer(),c?(r.draw(s,n.beginLayer()?1:e,t),n.endLayer(e,c)):r.draw(s,e,t),u&&(n.beginMask(),ee(u.world,i,u.x,u.y,u.rotation,u.scaleX,u.scaleY),Hr(s,u,u.alpha,16777215),n.endLayer(1)),a&&o){n.beginMask();for(let f=0;f<4;f++){let d=f===1||f===2?o.x+o.width:o.x,b=f>1?o.y+o.height:o.y;Ur[f*2]=i[0]*d+i[2]*b+i[4],Ur[f*2+1]=i[1]*d+i[3]*b+i[5]}n.polygon(Ur,4,16777215,1),n.endLayer(1)}}finally{if(l)if(He--,He){let f=(He-1)*4;n.clip(Q[f],Q[f+1],Q[f+2]-Q[f],Q[f+3]-Q[f+1])}else n.unclip()}}var re=class extends oe{constructor(e,t,n){super(e);h(this,"_frame",null);h(this,"_w",null);h(this,"_h",null);h(this,"slice",0);h(this,"autoAnchor",!0);h(this,"frameName",null);t&&(this.frame=t),n?.anchor===void 0&&this.useFrameAnchor(),n&&this.set(n)}get frame(){return this._frame}set frame(e){this.frameName=typeof e=="string"?e:null,this._frame=typeof e=="string"?this.kernel.frame(e):e,this.autoAnchor&&this.useFrameAnchor()}set anchor(e){this.autoAnchor=!1,super.anchor=e}get naturalWidth(){let e=this.frameNow();return e?(e.sw??e.w)/e.scale-e.margin*2:0}get naturalHeight(){let e=this.frameNow();return e?(e.sh??e.h)/e.scale-e.margin*2:0}get width(){return this._w??this.naturalWidth}set width(e){this._w=e}get height(){return this._h??this.naturalHeight}set height(e){this._h=e}sizeQ(e){Je[0]=this._w??(e.sw??e.w)/e.scale-e.margin*2,Je[1]=this._h??(e.sh??e.h)/e.scale-e.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){let e=this._frame;if(!e)return;let t=(e.sw??e.w)/e.scale-e.margin*2,n=(e.sh??e.h)/e.scale-e.margin*2;this.anchorX=t>0?(e.ox-e.margin)/t:0,this.anchorY=n>0?(e.oy-e.margin)/n:0}draw(e,t,n){let i=this.frameNow();if(!i)return;let o=Je;this.sizeQ(i),o[2]=this.anchorX,o[3]=this.anchorY,o[4]=t,zi(e,i,this.world,this.slice,n,this.blend)}},Qe=new Float64Array(12),Ze=new Float64Array(12),Mt={x:0,y:0,w:0,h:0};function ls(s,r,e,t,n,i){r=Math.max(r,0),e=Math.max(e,0),t=Math.max(t,0);let o=e+t>n?e*n/(e+t):e,a=e+t>n?t*n/(e+t):t,l=o/i,u=a/i;if(l+u>r){let c=r/(l+u);l*=c,u*=c}s[0]=0,s[1]=l,s[2]=0,s[3]=o,s[4]=l,s[5]=r-l-u,s[6]=o,s[7]=n-o-a,s[8]=r-u,s[9]=u,s[10]=n-a,s[11]=a}var Je=new Float64Array(5);function zi(s,r,e,t,n,i){let o=Je,a=o[0],l=o[1],u=o[2],c=o[3],f=o[4],d=s.tex(r.surface),b=t===0?r.slice??0:t;if(b===0){let w=(r.sw??r.w)/r.scale-r.margin*2,A=(r.sh??r.h)/r.scale-r.margin*2,E=w>0?a/w:1,R=A>0?l/A:1,C=-u*a+((r.tx??0)/r.scale-r.margin)*E,I=-c*l+((r.ty??0)/r.scale-r.margin)*R;Et(e,C,I),B[0]=r.w/r.scale*E,B[1]=r.h/r.scale*R,B[2]=f,s.r.quadQ(d,r,W,n,i);return}let g=r.tx??0,p=r.ty??0,m=(r.sw??r.w)-r.w-g,v=(r.sh??r.h)-r.h-p,x=-u*a-r.margin+g/r.scale,S=-c*l-r.margin+p/r.scale;if(ls(Qe,a+r.margin*2-(g+m)/r.scale,(typeof b=="number"?b:b[3])-g,(typeof b=="number"?b:b[1])-m,r.w,r.scale),ls(Ze,l+r.margin*2-(p+v)/r.scale,(typeof b=="number"?b:b[0])-p,(typeof b=="number"?b:b[2])-v,r.h,r.scale),Et(e,x,S),B[2]=f,!s.r.nineQ?.(d,r,Qe,Ze,W,n,i))for(let w=0;w<12;w+=4){let A=Ze[w+1],E=Ze[w+3];if(!(A<=0||E<=0))for(let R=0;R<12;R+=4){let C=Qe[R+1],I=Qe[R+3];C<=0||I<=0||(Mt.x=r.x+Qe[R+2],Mt.y=r.y+Ze[w+2],Mt.w=I,Mt.h=E,Et(e,x+Qe[R],S+Ze[w]),B[0]=C,B[1]=A,B[2]=f,s.r.quadQ(d,Mt,W,n,i))}}}function Et(s,r,e){W[0]=s[0],W[1]=s[1],W[2]=s[2],W[3]=s[3],W[4]=s[0]*r+s[2]*e+s[4],W[5]=s[1]*r+s[3]*e+s[5]}var fe=class extends re{constructor(e,t,n={}){super(e,null);h(this,"_spec");h(this,"baked",null);h(this,"bakedEffects",!0);this._spec=t,this.bake(),n.anchor===void 0&&this.useFrameAnchor(),this.set(n)}get spec(){return this._spec}set spec(e){this._spec=e,this.baked=null,this._w=this._h=null,this.bake()}bake(){let e=this.kernel;return this.baked&&e.atlas.valid(this.baked.frame)&&this.baked.frame.scale===e.pixelScale&&this.bakedEffects===e.effects?this.baked:(this.bakedEffects=e.effects,this.baked=e.shape(this._spec),this._frame=this.baked.frame,this.slice=this.baked.slice,this.baked)}frameNow(){return this.bake().frame}sizeQ(){let e=this.bake();Je[0]=this._w??e.w,Je[1]=this._h??e.h}get width(){return this._w??this.bake().w}set width(e){this._w=e}get height(){return this._h??this.bake().h}set height(e){this._h=e}},us=(s,r,e)=>s===void 0?r:typeof s=="number"?s:s[0]+(s[1]-s[0])*e(),ze=class ze extends oe{constructor(e,t,n={}){super(e);h(this,"max");h(this,"f");h(this,"tints");h(this,"count",0);h(this,"gravity");h(this,"drag");h(this,"frameRef");h(this,"random",Math.random);this.frameRef=t,this.max=Math.max(1,Math.floor(n.max??200)),this.f=new Float32Array(this.max*ze.W),this.tints=new Uint32Array(this.max),this.blend=n.blend??"normal",this.gravity=n.gravity??0,this.drag=n.drag??1}get alive(){return this.count}burst(e,t,n,i={}){let o=ze.W,a=this.random,l=i.tint===void 0?16777215:K(i.tint)[0];for(let u=0;u<n;u++){let c=this.count;if(c>=this.max){let m=0,v=1/0;for(let x=0;x<this.max;x++){let S=this.f[x*o+5]-this.f[x*o+4];S<v&&(v=S,m=x)}c=m}else this.count++;let f=(i.angle??0)+(i.spread===void 0?a()*Math.PI*2:(a()-.5)*i.spread),d=us(i.speed,200,a),b=Array.isArray(i.scale)?i.scale[0]:i.scale??1,g=Array.isArray(i.scale)?i.scale[1]:i.scale??1,p=c*o;this.f[p]=e,this.f[p+1]=t,this.f[p+2]=Math.cos(f)*d,this.f[p+3]=Math.sin(f)*d,this.f[p+4]=0,this.f[p+5]=Math.max(us(i.life,.8,a),.01),this.f[p+6]=a()*Math.PI*2,this.f[p+7]=(a()-.5)*2*(i.spin??0),this.f[p+8]=b,this.f[p+9]=g,this.f[p+10]=i.alpha??1,this.tints[c]=l}}update(e){let t=ze.W,n=this.f,i=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let o=0;o<this.count;){let a=o*t;if(n[a+4]=n[a+4]+e,n[a+4]>=n[a+5]){let l=--this.count;o!==l&&(n.copyWithin(a,l*t,l*t+t),this.tints[o]=this.tints[l]);continue}n[a+3]=(n[a+3]+this.gravity*e)*i,n[a+2]=n[a+2]*i,n[a]=n[a]+n[a+2]*e,n[a+1]=n[a+1]+n[a+3]*e,n[a+6]=n[a+6]+n[a+7]*e,o++}}clear(){this.count=0}draw(e,t,n){if(!this.count)return;let i=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,o=ze.W,a=this.f,l=this.world,u=i.w/i.scale,c=i.h/i.scale;for(let f=0;f<this.count;f++){let d=f*o,b=a[d+4]/a[d+5],g=a[d+8]+(a[d+9]-a[d+8])*b,p=t*a[d+10]*(1-b*b),m=a[d+6],v=Math.cos(m)*g,x=Math.sin(m)*g,S=a[d],w=a[d+1],A=l[0],E=l[1],R=l[2],C=l[3],I=A*v+R*x,H=E*v+C*x,z=R*v-A*x,G=C*v-E*x;W[0]=I,W[1]=H,W[2]=z,W[3]=G,W[4]=A*S+R*w+l[4]-(I*u+z*c)/2,W[5]=E*S+C*w+l[5]-(H*u+G*c)/2,B[0]=u,B[1]=c,B[2]=p,e.r.quadQ(e.tex(i.surface),i,W,Nr(n,this.tints[f]),this.blend)}}};h(ze,"W",11);var et=ze;var ae=class extends re{constructor(e,t,n={}){let{fps:i,loop:o,playing:a,speed:l,onComplete:u,...c}=n;if(!t.frames.length)throw new Error("[engine] an animation needs at least one frame");super(e,t.frames[0],c);h(this,"frames");h(this,"durations");h(this,"fps");h(this,"loop");h(this,"speed");h(this,"onComplete");h(this,"_playing");h(this,"index",0);h(this,"t",0);this.frames=t.frames,this.durations=t.durations&&i===void 0?t.durations:null,this.fps=i??12,this.loop=o!==!1,this.speed=l??1,this.onComplete=u??null,this._playing=a!==!1,this.speed<0&&this.show(t.frames.length-1)}get frameIndex(){return this.index}get frameCount(){return this.frames.length}get playing(){return this._playing}play(){return!this.loop&&!this._playing&&this.index===(this.speed<0?0:this.frames.length-1)&&this.show(this.speed<0?this.frames.length-1:0),this._playing=!0,this}stop(){return this._playing=!1,this}gotoFrame(e){let t=this.frames.length;return this.show((Math.floor(e)%t+t)%t),this.t=0,this}gotoAndPlay(e){return this._playing=!0,this.gotoFrame(e)}gotoAndStop(e){return this._playing=!1,this.gotoFrame(e)}show(e){e===this.index&&this._frame||(this.index=e,this.frame=this.frames[e])}secondsOf(e){let t=this.durations?.[e];return t!==void 0&&t>0?t:1/Math.max(this.fps,.001)}update(e){if(!this._playing||this.destroyed||this.speed===0)return;let t=this.frames.length,n=this.speed<0;this.t+=e*Math.abs(this.speed);let i=this.index;for(let o=0;o<1e3;o++){let a=this.secondsOf(i);if(this.t<a)break;this.t-=a;let l=n?i-1:i+1;if(l<0||l>=t){if(!this.loop){this.t=0,this._playing=!1,this.show(i),this.onComplete?.();return}i=n?t-1:0}else i=l}this.show(i)}},fs=(s,r)=>s.localeCompare(r,void 0,{numeric:!0});var Ft=class{constructor(r,e,t=2){h(this,"width",r);h(this,"height",e);h(this,"padding",t);h(this,"shelves",[]);h(this,"free",[]);h(this,"bottom",0)}alloc(r,e){let t=Math.ceil(r)+this.padding*2,n=Math.ceil(e)+this.padding*2;if(t>this.width||n>this.height)return null;for(let a=0;a<this.free.length;a++){let l=this.free[a];if(l.w>=t&&l.h>=n&&l.w*l.h<=t*n*2)return this.free.splice(a,1),this.inner(l.x,l.y,r,e)}let i=null;for(let a of this.shelves)a.h>=n&&a.h<=n*1.5+8&&this.width-a.x>=t&&(!i||a.h<i.h)&&(i=a);if(!i)if(this.bottom+n>this.height){for(let a of this.shelves)a.h>=n&&this.width-a.x>=t&&(i=a);if(!i)return null}else i={y:this.bottom,h:n,x:0},this.shelves.push(i),this.bottom+=n;let o=i.x;return i.x+=t,this.inner(o,i.y,r,e)}release(r){this.free.push({x:r.x-this.padding,y:r.y-this.padding,w:Math.ceil(r.w)+this.padding*2,h:Math.ceil(r.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(r,e,t,n){return{x:r+this.padding,y:e+this.padding,w:t,h:n}}},tt=s=>({source:s,texture:null,pending:[]}),Le=class{constructor(r=2048,e=4){h(this,"pageSize",r);h(this,"maxPages",e);h(this,"pages",[]);h(this,"gen",1);h(this,"onPage",()=>{});h(this,"onDrop",()=>{})}valid(r){return!!r&&(r.gen===this.gen||r.gen===0)}bake(r,e,t,n=1,i=0,o=0,a=0){let l=Math.max(1,Math.ceil(r)),u=Math.max(1,Math.ceil(e)),c=document.createElement("canvas");c.width=l,c.height=u;let f=c.getContext("2d");return t(f),this.put(c,l,u,n,i,o,a)}add(r,e=1,t=0,n=0){let i=document.createElement("canvas");return i.width=Math.max(1,r.width),i.height=Math.max(1,r.height),i.getContext("2d").drawImage(r,0,0),this.put(i,i.width,i.height,e,t,n,0)}release(r){if(r.gen!==this.gen)return;this.pages.find(t=>t.surface===r.surface)?.packer.release(r)}rebake(r,e,t,n,i=r.w,o=r.h){if(!this.valid(r)||e>i||t>o)return null;let a=Math.max(1,Math.ceil(e)),l=Math.max(1,Math.ceil(t)),u=this.pages.find(f=>f.surface===r.surface);if(!u)return null;let c=document.createElement("canvas");return c.width=Math.ceil(i),c.height=Math.ceil(o),n(c.getContext("2d")),u.ctx.clearRect(r.x,r.y,c.width,c.height),u.ctx.drawImage(c,r.x,r.y),r.surface.pending.push([c,r.x,r.y]),r.w=a,r.h=l,r}put(r,e,t,n,i,o,a){let l=null,u=this.pages.find(f=>(l=f.packer.alloc(e,t))!==null);if(u||(!(Math.max(e,t)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),u=this.pages[0],l=u?u.packer.alloc(e,t):null),(!u||!l)&&(u=this.newPage(Math.max(e,t)),l=u.packer.alloc(e,t))),!l)throw new Error(`[engine] ${e}\xD7${t} does not fit an atlas page`);let c=l;return u.ctx.drawImage(r,c.x,c.y),u.surface.pending.push([r,c.x,c.y]),{surface:u.surface,x:c.x,y:c.y,w:e,h:t,scale:n,gen:this.gen,ox:i,oy:o,margin:a}}newPage(r){let e=this.pageSize;for(;e<r+4;)e*=2;let t=document.createElement("canvas");t.width=t.height=e;let n=t.getContext("2d"),i=tt(t),o={surface:i,packer:new Ft(e,e),ctx:n};return this.pages.push(o),this.onPage(i),o}wipe(){this.gen++;let r=0;for(let e=0;e<this.pages.length;e++){let t=this.pages[e];if(r<this.maxPages&&t.surface.source.width===this.pageSize){this.pages[r++]=t;continue}t.surface.pending=[],this.onDrop(t.surface)}this.pages.length=r;for(let e of this.pages)e.packer.reset(),e.ctx.clearRect(0,0,e.surface.source.width,e.surface.source.height),e.surface.pending=[],e.surface.pending.push([e.surface.source,0,0])}};var $i=()=>globalThis.FabiPlay,Rt=class{posed(r,e,t,n=!0){let i={id:r,body:e};return $i()?.smoothedBody(i,{smooth:t<1?t:!1,interpolate:n})??e}};var ps=new Float64Array(1),ds=new Int32Array(ps.buffer),rt=(s,r)=>(s=Math.imul(s^r,1540483477),s^s>>>15);function ke(s,r=2538058380){return s!==s?rt(r,2146959360):(ps[0]=s===0?0:s,rt(rt(r,ds[0]),ds[1]))}function ms(s,r=2166136261){for(let e=0;e<s.length;e++)r=Math.imul(r^s.charCodeAt(e),16777619);return r}function ce(s){switch(typeof s){case"number":return ke(s);case"string":return ms(s);case"boolean":return s?1013904242:461845907;case"object":{if(s===null)return 625341585;if(Array.isArray(s)||s instanceof Float64Array){let t=1779033703^s.length;for(let n=0;n<s.length;n++){let i=s[n];t=rt(t,typeof i=="number"?ke(i):ce(i))}return t}let r=1359893119,e=s;for(let t in e){let n=e[t];n!==void 0&&(r=r+rt(ms(t),ce(n))|0)}return rt(r,2600822924)}default:return 0}}function nt(s,r){if(s===r)return!0;if(typeof s!="object"||typeof r!="object"||s===null||r===null)return typeof s=="number"&&typeof r=="number"&&s!==s&&r!==r;let e=Array.isArray(s)||s instanceof Float64Array;if(e!==(Array.isArray(r)||r instanceof Float64Array))return!1;if(e){let i=s,o=r;if(i.length!==o.length)return!1;for(let a=0;a<i.length;a++)if(i[a]!==o[a]&&!nt(i[a],o[a]))return!1;return!0}let t=s,n=r;for(let i in t)if(t[i]!==void 0&&!nt(t[i],n[i]))return!1;for(let i in n)if(n[i]!==void 0&&t[i]===void 0)return!1;return!0}function _t(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return s.map(_t);if(s instanceof Float64Array)return s.slice();let r={};for(let e in s)s[e]!==void 0&&(r[e]=_t(s[e]));return r}var st=class{constructor(r=1/0){h(this,"max",r);h(this,"buckets",new Map);h(this,"n",0)}get size(){return this.n}get(r,e=ce(r)){let t=this.buckets.get(e);if(t){for(let n=0;n<t.length;n++)if(nt(t[n].key,r))return t[n].value}}set(r,e,t=ce(r)){let n=this.buckets.get(t);if(n){for(let i of n)if(nt(i.key,r)){i.value=e;return}}this.n>=this.max&&this.clear(),(!n||!this.buckets.has(t))&&this.buckets.set(t,n=[]),n.push({key:_t(r),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}};var zr=0,bs=1,Zt=2,$r=3,it=class{constructor(){h(this,"scale",1);h(this,"cOn",!1);h(this,"px0",0);h(this,"py0",0);h(this,"px1",0);h(this,"py1",0);h(this,"clipVer",0);h(this,"stack",[]);h(this,"sp",0);h(this,"real",0);h(this,"mute",0);h(this,"bnd",new Float64Array(4*(St+1)));h(this,"rx0",0);h(this,"ry0",0);h(this,"rx1",0);h(this,"ry1",0);h(this,"maxBlur",1/0);h(this,"time",0);h(this,"skipped",0);h(this,"gq",new Float64Array(4))}resetLayers(r){this.scale=r,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){let r=this.gq;this.grow(r[0],r[1],r[2],r[3])}grow(r,e,t,n){if(!this.real)return;let i=this.bnd,o=(this.real-1)*4;r<i[o]&&(i[o]=r),e<i[o+1]&&(i[o+1]=e),t>i[o+2]&&(i[o+2]=t),n>i[o+3]&&(i[o+3]=n)}area(r,e){let t=this.bnd,n=r*4,i=this.scale;return this.rx0=Math.max(Math.floor((t[n]-e)*i)-1,0),this.ry0=Math.max(Math.floor((t[n+1]-e)*i)-1,0),this.rx1=Math.min(Math.ceil((t[n+2]+e)*i)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((t[n+3]+e)*i)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(r,e,t,n){let i=this.scale,o=this.canvas.width,a=this.canvas.height,l=Math.min(Math.max(Math.round(r*i),0),o),u=Math.min(Math.max(Math.round(e*i),0),a),c=Math.min(Math.max(Math.round((r+t)*i),l),o),f=Math.min(Math.max(Math.round((e+n)*i),u),a);this.cOn&&l===this.px0&&u===this.py0&&c===this.px1&&f===this.py1||(this.cOn=!0,this.px0=l,this.py0=u,this.px1=c,this.py1=f,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(r){if(r<Zt&&(this.mute||this.real>=St||!this.pushLayer())&&(r+=2),r===$r)this.mute++;else if(r!==Zt){let e=this.real*4;this.bnd[e]=this.bnd[e+1]=1/0,this.bnd[e+2]=this.bnd[e+3]=-1/0,this.real++}return this.stack[this.sp++]=r,r<Zt}beginLayer(){return this.push(zr)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===zr?bs:$r)}endLayer(r,e){if(!this.sp)return;let t=this.stack[--this.sp];if(t===$r){if(this.mute--,!this.sp)return;t=this.stack[--this.sp]}if(t===bs){let n=--this.real,i=this.popLayer();this.area(n-1,0)&&this.composite(i,!0,1,null);let o=this.bnd,a=(n-1)*4,l=n*4;o[a]=Math.max(o[a],o[l]),o[a+1]=Math.max(o[a+1],o[l+1]),o[a+2]=Math.min(o[a+2],o[l+2]),o[a+3]=Math.min(o[a+3],o[l+3]),t=this.stack[--this.sp]}if(t===Zt)At(e)&&(this.skipped+=e.length);else if(t===zr){let n=--this.real,i=At(e)?e:null,o=this.popLayer();if(this.area(n,i?os(i,this.maxBlur):0)){this.composite(o,!1,r,i);let a=this.scale;this.grow(this.rx0/a,this.ry0/a,this.rx1/a,this.ry1/a)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}};var Vi=256,ys=8<<20,ne=new Float64Array(32),se={x:0,y:0,w:0,h:0};function Wi(s){if(typeof s.filter!="string")return!1;s.filter="blur(1px)";let r=s.filter==="blur(1px)";return s.filter="none",r}function ot(s){let r=s.getContext("2d",{alpha:!0});return r?new Vr(s,r):null}var Vr=class extends it{constructor(e,t){super();h(this,"canvas",e);h(this,"ctx",t);h(this,"kind","canvas2d");h(this,"maxTextureSize",4096);h(this,"features",{});h(this,"info",{renderer:"canvas2d"});h(this,"support");h(this,"lost",!1);h(this,"fxr",null);h(this,"quads",0);h(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0});h(this,"tinted",new Map);h(this,"tintedN",0);h(this,"lostListeners",[]);h(this,"restoredListeners",[]);h(this,"base");h(this,"top");h(this,"layers",[]);h(this,"scratch",[]);h(this,"nines",new Map);h(this,"ninePx",0);h(this,"frame",0);h(this,"hit",!1);h(this,"missed",new Map);this.support={filters:Wi(t),shaders:!1},this.base=this.top={ctx:t,clipped:!1,ver:0},e.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(n=>n())}),e.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(n=>n())})}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){return{id:Tt(),width:e.width,height:e.height,source:e}}updateTexture(e,t,n=0,i=0){let o=t?n+t.width:1/0,a=t?i+t.height:1/0;for(let l of this.nines.values()){let u=l.key;u[0]===e.id&&u[1]<o&&u[1]+u[3]>n&&u[2]<a&&u[2]+u[4]>i&&this.dropNine(l)}for(let[l,u]of this.tinted){let c=u.filter(f=>f.id!==e.id);this.tintedN-=u.length-c.length,c.length?this.tinted.set(l,c):this.tinted.delete(l)}}destroyTexture(e){this.updateTexture(e)}begin(e,t,n){this.resetLayers(n),this.fxr?.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;let i=this.ctx;this.base.clipped&&i.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,this.canvas.width,this.canvas.height),t>0&&(i.fillStyle=Ue(e,t),i.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(e,t,n,i,o,a,l,u){B[0]=i,B[1]=o,B[2]=l,this.quadQ(e,t,n,a,u)}quadQ(e,t,n,i,o){t.w<=0||t.h<=0||(i===16777215?this.blit(e.source,t.x,t.y,t.w,t.h,n,o):this.blit(this.tint(e,t,i),0,0,t.w,t.h,n,o))}blit(e,t,n,i,o,a,l){let u=B[0],c=B[1],f=B[2];if(f<=0||this.mute)return;this.sync();let d=this.ctx,b=this.scale;if(this.real){let g=a[0]*u,p=a[1]*u,m=a[2]*c,v=a[3]*c;this.grow(a[4]+Math.min(0,g,m,g+m),a[5]+Math.min(0,p,v,p+v),a[4]+Math.max(0,g,m,g+m),a[5]+Math.max(0,p,v,p+v))}d.setTransform(a[0]*b,a[1]*b,a[2]*b,a[3]*b,a[4]*b,a[5]*b),d.globalAlpha=Math.min(f,1),l==="add"&&(d.globalCompositeOperation="lighter"),d.drawImage(e,t,n,i,o,0,0,u,c),l==="add"&&(d.globalCompositeOperation="source-over"),this.quads++}nineQ(e,t,n,i,o,a,l){var p,m;let u=n[8]+n[9],c=i[8]+i[9],f=Math.ceil(u*Math.hypot(o[0],o[1])*this.scale-1e-6),d=Math.ceil(c*Math.hypot(o[2],o[3])*this.scale-1e-6);if(o[1]===0&&o[2]===0||f>4096||d>4096)return!1;if(!(f>0&&d>0&&B[2]>0)||this.mute)return!0;let b=this.kept(e,t,n,i,f,d,a),g=(b??(b=(p=this.scratch)[m=13*Math.ceil(Math.log2(f))+Math.ceil(Math.log2(d))]??(p[m]=document.createElement("canvas").getContext("2d")))).canvas;if(g.width<f&&(g.width=f),g.height<d&&(g.height=d),!this.hit){b.clearRect(0,0,f+2,d+2);for(let v=0;v<12;v+=4){let x=Math.round(i[v]*d/c),S=Math.round((i[v]+i[v+1])*d/c);for(let w=0;w<12;w+=4){let A=Math.round(n[w]*f/u),E=Math.round((n[w]+n[w+1])*f/u);se.x=t.x+n[w+2],se.y=t.y+i[v+2],se.w=n[w+3],se.h=i[v+3],!(E<=A||S<=x||se.w<=0||se.h<=0)&&(a===16777215?b.drawImage(e.source,se.x,se.y,se.w,se.h,A,x,E-A,S-x):b.drawImage(this.tint(e,se,a),0,0,se.w,se.h,A,x,E-A,S-x))}}}return B[0]=u,B[1]=c,this.blit(g,0,0,f,d,o,l),!0}kept(e,t,n,i,o,a,l){ne[0]=e.id,ne[1]=t.x,ne[2]=t.y,ne[3]=t.w,ne[4]=t.h,ne[5]=o,ne[6]=a,ne[7]=l,ne.set(n,8),ne.set(i,20);let u=ce(ne),c=this.nines.get(u);if(this.hit=!1,c)return nt(c.key,ne)?(c.used=this.frame,this.hit=!0,c.ctx):null;let f=this.missed,d=f.get(u);f.size>4096&&f.clear(),f.set(u,this.frame);let b=o*a;if(d!==this.frame-1||b>ys)return null;let g;for(;this.ninePx+b>ys;){let v;for(let w of this.nines.values())w.used<this.frame-1&&!(v&&v.used<=w.used)&&(v=w);if(!v)return null;let x=v.ctx.canvas,S=!g&&x.width>=o&&x.height>=a&&x.width*x.height<=2*b;this.dropNine(v,S),S&&(g=v.ctx)}let p=g??document.createElement("canvas").getContext("2d"),m=p.canvas;return g||(m.width=o,m.height=a),this.ninePx+=m.width*m.height,this.nines.set(u,{key:_t(ne),ctx:p,used:this.frame}),p}dropNine(e,t=!1){this.nines.delete(ce(e.key));let n=e.ctx.canvas;this.ninePx-=n.width*n.height,t||(n.width=0)}dropNines(){for(let e of this.nines.values())this.dropNine(e)}tint(e,t,n){let i=ke(n,ke(t.h,ke(t.w,ke(t.y,ke(t.x,ke(e.id)))))),o=this.tinted.get(i);if(o)for(let u=0;u<o.length;u++){let c=o[u];if(c.id===e.id&&c.x===t.x&&c.y===t.y&&c.w===t.w&&c.h===t.h&&c.color===n)return c.canvas}this.tintedN>=Vi&&(this.tinted.clear(),this.tintedN=0,o=void 0);let a=document.createElement("canvas");a.width=Math.ceil(t.w),a.height=Math.ceil(t.h);let l=a.getContext("2d");return l.drawImage(e.source,t.x,t.y,t.w,t.h,0,0,t.w,t.h),l.globalCompositeOperation="multiply",l.fillStyle=Ue(n),l.fillRect(0,0,t.w,t.h),l.globalCompositeOperation="destination-in",l.drawImage(e.source,t.x,t.y,t.w,t.h,0,0,t.w,t.h),o||this.tinted.set(i,o=[]),o.push({id:e.id,x:t.x,y:t.y,w:t.w,h:t.h,color:n,canvas:a}),this.tintedN++,a}paint(e,t){this.sync();let n=this.ctx,i=this.scale;return n.setTransform(i,0,0,i,0,0),n.globalAlpha=Math.min(t,1),Ue(e)}ellipse(e,t,n,i,o,a,l){if(l<=0||n<=0||i<=0||this.mute)return;let u=Math.max(n,i);this.grow(e-u,t-u,e+u,t+u);let c=this.ctx;c.fillStyle=this.paint(a,l),c.beginPath(),c.ellipse(e,t,n,i,o,0,Math.PI*2),c.fill(),this.quads++}trace(e,t,n=0){if(this.real)for(let o=0;o<t;o++)this.grow(e[o*2]-n,e[o*2+1]-n,e[o*2]+n,e[o*2+1]+n);let i=this.ctx;i.beginPath(),i.moveTo(e[0],e[1]);for(let o=1;o<t;o++)i.lineTo(e[o*2],e[o*2+1])}polygon(e,t,n,i){if(i<=0||t<3||this.mute)return;let o=this.ctx;o.fillStyle=this.paint(n,i),this.trace(e,t),o.closePath(),o.fill(),this.quads++}stroke(e,t,n,i,o,a){if(o<=0||n<=0||t<1||this.mute)return;let l=this.ctx;l.strokeStyle=this.paint(i,o),l.lineWidth=n,l.lineCap="round",l.lineJoin="round",this.trace(e,t,n/2),t===1&&l.lineTo(e[0],e[1]),a&&l.closePath(),l.stroke(),this.quads++}sync(){let e=this.top;if(e.ver===this.clipVer)return;let t=e.ctx;e.clipped&&t.restore(),e.clipped=this.cOn,e.ver=this.clipVer,this.cOn&&(t.save(),t.setTransform(1,0,0,1,0,0),t.beginPath(),t.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),t.clip())}pushLayer(){let e=this.canvas.width,t=this.canvas.height,n=this.layers[this.real];if(!n||n.ctx.canvas.width!==e||n.ctx.canvas.height!==t){let o=document.createElement("canvas");o.width=e,o.height=t;let a=o.getContext("2d");if(!a)return!1;n=this.layers[this.real]={ctx:a,clipped:!1,ver:-1}}let i=n.ctx;return n.clipped&&i.restore(),n.clipped=!1,n.ver=-1,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,e,t),this.top=n,this.ctx=i,!0}popLayer(){return this.top=this.real>0?this.layers[this.real-1]:this.base,this.ctx=this.top.ctx,this.layers[this.real].ctx.canvas}composite(e,t,n,i){let o=e,a="none",l=i&&te.c2d?this.fxr??(this.fxr=te.c2d(this)):null;l&&(o=l.chain(e,i),a=l.css),this.sync();let u=this.ctx,c=this.rx0,f=this.ry0,d=this.rx1-c,b=this.ry1-f;u.setTransform(1,0,0,1,0,0),u.globalAlpha=Math.min(n,1),u.globalCompositeOperation=t?"destination-in":"source-over",a!=="none"&&(u.filter=a),u.drawImage(o,c,f,d,b,c,f,d,b),a!=="none"&&(u.filter="none"),u.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();let e=this.stats;return e.drawCalls=e.quads=this.quads,e.filtersSkipped=this.skipped,e}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],this.fxr?.destroy(),this.fxr=null}};var Jt=class{constructor(r,e,t=8192){h(this,"instanced",r);h(this,"slots",e);h(this,"capacity",t);h(this,"f32");h(this,"u32");h(this,"quads",0);h(this,"textures");h(this,"bound",0);this.textures=new Array(e).fill(null);let n=t*(r?14:24),i=new ArrayBuffer(n*4);this.f32=new Float32Array(i),this.u32=new Uint32Array(i)}slot(r){let e=this.textures;for(let t=0;t<this.bound;t++)if(e[t]===r)return t;return this.bound>=this.slots?-1:(e[this.bound]=r,this.bound++)}has(r){for(let e=0;e<this.bound;e++)if(this.textures[e]===r)return!0;return!1}get full(){return this.quads>=this.capacity}get words(){return this.quads*(this.instanced?14:24)}reset(){this.quads=0;for(let r=0;r<this.bound;r++)this.textures[r]=null;this.bound=0}push(r,e,t,n,i,o,a,l,u,c,f,d,b,g){let p=this.f32;if(this.instanced){let m=this.quads*14;p[m++]=r,p[m++]=e,p[m++]=t,p[m++]=n,p[m++]=i,p[m++]=o,p[m++]=a,p[m++]=l,p[m++]=u,p[m++]=c,p[m++]=f,p[m++]=d,this.u32[m++]=b,p[m]=g}else{let m=this.quads*6*4;this.vertex(m,r,e,u,c,b,g),this.vertex(m+6,t,n,f,c,b,g),this.vertex(m+12,i,o,f,d,b,g),this.vertex(m+18,a,l,u,d,b,g)}this.quads++}pushQ(r,e){let t=this.f32;if(this.instanced){let n=this.quads*14;for(let i=0;i<12;i++)t[n+i]=r[i];this.u32[n+12]=r[12],t[n+13]=e}else{let n=this.quads*6*4,i=r[12];for(let o=0;o<4;o++,n+=6)t[n]=r[o*2],t[n+1]=r[o*2+1],t[n+2]=o===1||o===2?r[10]:r[8],t[n+3]=o>=2?r[11]:r[9],this.u32[n+4]=i,t[n+5]=e}this.quads++}vertex(r,e,t,n,i,o,a){let l=this.f32;l[r]=e,l[r+1]=t,l[r+2]=n,l[r+3]=i,this.u32[r+4]=o,l[r+5]=a}};function gs(s){let r=new Uint16Array(s*6);for(let e=0,t=0,n=0;e<s;e++,t+=6,n+=4)r[t]=n,r[t+1]=n+1,r[t+2]=n+2,r[t+3]=n,r[t+4]=n+2,r[t+5]=n+3;return r}var Z={M:0,L:1,Q:2,C:3,Z:4},Ms=[2,2,4,6,0],Xi={M:0,L:1,Q:2,C:3,Z:4};function ir(s,r){if(s.length>=r)return s;let e=new Float64Array(Math.max(r,s.length*2,16));return e.set(s),e}var er=new Map;function qi(s){if(typeof s!="string")return s;let r=er.get(s);if(r)return r;r=[];let e=s.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[],t=-1;for(let n=0;n<e.length;){let i=e[n],o=Xi[i.toUpperCase()];if(o!==void 0){t=o,n++,o===Z.Z&&r.push(Z.Z);continue}if(t<0||t===Z.Z){n++;continue}let a=Ms[t];r.push(t);for(let l=0;l<a;l++)r.push(Number(e[n+l]??0));n+=a,t===Z.M&&(t=Z.L)}return er.size>256&&er.clear(),er.set(s,r),r}var Ne={subs:[],count:0},Wr=null,Pe=null;function tr(s,r){let e=Pe;e||(e=Ne.subs[Ne.count]??null,e||Ne.subs.push(e={pts:new Float64Array(64),n:0,closed:!1}),e.n=0,e.closed=!1,Ne.count++,Pe=e);let t=e.n*2;t+2>e.pts.length&&(e.pts=ir(e.pts,t+2));let n=Wr;n?(e.pts[t]=n[0]*s+n[2]*r+n[4],e.pts[t+1]=n[1]*s+n[3]*r+n[5]):(e.pts[t]=s,e.pts[t+1]=r),e.n++}function or(s,r=null,e=1,t=6){let n=qi(s);Ne.count=0,Pe=null,Wr=r;let i=0,o=0,a=0,l=0,u=e/t;for(let c=0;c<n.length;){let f=n[c++],d=n;if(f===Z.M)Pe=null,i=a=d[c],o=l=d[c+1],tr(i,o);else if(f===Z.L)i=d[c],o=d[c+1],tr(i,o);else if(f===Z.Q){let b=d[c],g=d[c+1],p=d[c+2],m=d[c+3],v=xs((de(b-i,g-o)+de(p-b,m-g))*u);for(let x=1;x<=v;x++){let S=x/v,w=1-S;tr(w*w*i+2*w*S*b+S*S*p,w*w*o+2*w*S*g+S*S*m)}i=p,o=m}else if(f===Z.C){let b=d[c],g=d[c+1],p=d[c+2],m=d[c+3],v=d[c+4],x=d[c+5],S=xs((de(b-i,g-o)+de(p-b,m-g)+de(v-p,x-m))*u);for(let w=1;w<=S;w++){let A=w/S,E=1-A,R=E*E*E,C=3*E*E*A,I=3*E*A*A,H=A*A*A;tr(R*i+C*b+I*p+H*v,R*o+C*g+I*m+H*x)}i=v,o=x}else if(f===Z.Z){Pe&&(Pe.closed=!0),Pe=null,i=a,o=l;continue}else break;c+=Ms[f]}Pe=null,Wr=null;for(let c=0;c<Ne.count;c++){let f=Ne.subs[c],d=f.n*2;f.closed&&f.n>=2&&Math.abs(f.pts[0]-f.pts[d-2])<1e-6&&Math.abs(f.pts[1]-f.pts[d-1])<1e-6&&f.n--}return Ne}var de=(s,r)=>Math.sqrt(s*s+r*r),xs=s=>Math.min(Math.max(Math.ceil(s),2),24);function ji(s,r){let e=0;for(let t=0,n=r-1;t<r;n=t++)e+=(s[n*2]-s[t*2])*(s[n*2+1]+s[t*2+1]);return e}var rr=new Int32Array(64),nr=(s,r,e,t,n)=>((s[t*2]-s[e*2])*(s[n*2+1]-s[e*2+1])-(s[t*2+1]-s[e*2+1])*(s[n*2]-s[e*2]))*r;function Es(s,r,e){if(r<3)return 0;rr.length<r&&(rr=new Int32Array(Math.max(r,rr.length*2)));let t=rr,n=r,i=0;for(let u=0;u<r;u++)t[u]=u;let o=ji(s,r)>0?1:-1,a=r*r+8,l=0;for(;n>3&&a-- >0;){let u=t[(l+n-1)%n],c=t[l%n],f=t[(l+1)%n],d=nr(s,o,u,c,f)>0;if(d)for(let b=0;b<n;b++){let g=t[b];if(!(g===u||g===c||g===f)&&nr(s,o,u,c,g)>=0&&nr(s,o,c,f,g)>=0&&nr(s,o,f,u,g)>=0){d=!1;break}}d?(e[i++]=u,e[i++]=c,e[i++]=f,t.copyWithin(l%n,l%n+1,n),n--,l=Math.max(l-1,0)):l=(l+1)%n}if(n===3)e[i++]=t[0],e[i++]=t[1],e[i++]=t[2];else if(n>3)for(let u=1;u+1<n;u++)e[i++]=t[0],e[i++]=t[u],e[i++]=t[u+1];return i}var Ki=.85,sr=new Float64Array(64),vs=new Float64Array(64),ws=new Float64Array(64),ks=new Float64Array(64),As=new Float64Array(64),Ss=new Float64Array(64),Ts=new Uint8Array(64),Ct=new Float64Array(8);function Fs(s,r,e,t,n,i){let o=Ct;if(sr.length<r){let m=Math.max(r,sr.length*2);sr=new Float64Array(m),vs=new Float64Array(m),ws=new Float64Array(m),ks=new Float64Array(m),As=new Float64Array(m),Ss=new Float64Array(m),Ts=new Uint8Array(m)}let a=sr,l=vs,u=0;for(let m=0;m<r;m++){let v=s[m*2],x=s[m*2+1];!Number.isFinite(v)||!Number.isFinite(x)||u&&Math.abs(a[u-1]-v)<.001&&Math.abs(l[u-1]-x)<.001||(a[u]=v,l[u]=x,u++)}if(t&&u>2&&Math.abs(a[0]-a[u-1])<.001&&Math.abs(l[0]-l[u-1])<.001&&u--,u===0)return;if(u===1)return o[0]=a[0],o[1]=l[0],i();let c=t?u:u-1,f=ws,d=ks;for(let m=0;m<c;m++){let v=(m+1)%u,x=a[v]-a[m],S=l[v]-l[m],w=de(x,S)||1;f[m]=-S/w,d[m]=x/w}let b=As,g=Ss,p=Ts;for(let m=0;m<u;m++){let v=t?(m-1+c)%c:m-1,x=m<c?m:-1;if(p[m]=1,v<0||x<0||f[v]*f[x]+d[v]*d[x]<Ki)continue;let w=f[v]+f[x],A=d[v]+d[x],E=de(w,A)||1;w/=E,A/=E;let R=e/Math.max(w*f[x]+A*d[x],.5);b[m]=w*R,g[m]=A*R,p[m]=0}for(let m=0;m<c;m++){let v=(m+1)%u,x=p[m]?f[m]*e:b[m],S=p[m]?d[m]*e:g[m],w=p[v]?f[m]*e:b[v],A=p[v]?d[m]*e:g[v];o[0]=a[m]+x,o[1]=l[m]+S,o[2]=a[v]+w,o[3]=l[v]+A,o[4]=a[v]-w,o[5]=l[v]-A,o[6]=a[m]-x,o[7]=l[m]-S,n()}for(let m=0;m<u;m++)p[m]&&(o[0]=a[m],o[1]=l[m],i())}function Xr(s,r){let e=0,t=1/0;for(let n=0;n<r.length;n++){let i=Math.abs(Math.log(Math.max(s,.5)/r[n]));i<t&&(t=i,e=n)}return e}var ar=[{x:240,y:0,w:8,h:8,r:3},{x:224,y:0,w:16,h:16,r:7},{x:192,y:0,w:32,h:32,r:15},{x:128,y:0,w:64,h:64,r:31},{x:0,y:0,w:128,h:128,r:63}],lr=[4,8,16,32,64,128].map((s,r)=>({x:r*4,y:128,w:4,h:s,r:s/2-1})),Ae={x:248,y:248,w:8,h:8},_s=ar.map(s=>s.r*2),Cs=lr.map(s=>s.r*2),Rs=(s,r)=>Math.min(Math.max(s+.5-r,0),1);function Yi(){let s=new Uint8ClampedArray(262144),r=(e,t,n)=>{let i=(t*256+e)*4;s[i]=s[i+1]=s[i+2]=255,s[i+3]=Math.round(n*255)};for(let e of ar){let t=e.w/2;for(let n=0;n<e.h;n++)for(let i=0;i<e.w;i++)r(e.x+i,e.y+n,Rs(e.r,Math.hypot(i+.5-t,n+.5-t)))}for(let e of lr){let t=e.h/2;for(let n=0;n<e.h;n++)for(let i=0;i<e.w;i++)r(e.x+i,e.y+n,Rs(e.r,Math.abs(n+.5-t)))}for(let e=0;e<Ae.h;e++)for(let t=0;t<Ae.w;t++)r(Ae.x+t,Ae.y+e,1);return s}function Ls(){let s=document.createElement("canvas");return s.width=s.height=256,s.getContext("2d").putImageData(new ImageData(Yi(),256,256),0,0),s}var Ps=8,ur=`
1
+ "use strict";(()=>{var zn=Object.defineProperty;var Ci=(s,r,e)=>r in s?zn(s,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[r]=e;var Li=(s,r)=>{for(var e in r)zn(s,e,{get:r[e],enumerable:!0})};var h=(s,r,e)=>Ci(s,typeof r!="symbol"?r+"":r,e);var Fn={};Li(Fn,{AnimatedSprite:()=>ae,Atlas:()=>Le,AvatarPainter:()=>Ve,AvatarsNode:()=>Bt,BitmapFont:()=>ht,DEFAULT_FONT:()=>Kr,EASE:()=>_e,Group:()=>$e,HALO:()=>We,MAX_LAYERS:()=>St,NameTags:()=>Ie,Node:()=>oe,NodePool:()=>Dt,Particles:()=>et,STAGE_HEIGHT:()=>j,Shape:()=>fe,ShelfPacker:()=>Ft,Sound:()=>pt,Sprite:()=>re,TIERS:()=>be,Text:()=>me,Timeline:()=>dt,Tweens:()=>mt,avatarPortrait:()=>Ds,blur:()=>mi,brightness:()=>ai,colorMatrix:()=>di,contrast:()=>li,createAvatarRenderer:()=>Bs,createEngine:()=>ei,createRenderer:()=>lt,dropShadow:()=>bi,grayscale:()=>ci,handsOf:()=>pr,hits:()=>It,hueRotate:()=>fi,invert:()=>pi,nodePool:()=>wi,packColor:()=>Re,parseBMFont:()=>ft,parseColor:()=>K,pickTier:()=>br,playerColor:()=>Nt,rendererOrder:()=>qr,rng:()=>Qn,saturate:()=>ui,sepia:()=>hi,shader:()=>yi,shapeBounds:()=>hr,tier:()=>Se,tint:()=>oi,touching:()=>dr,wrists:()=>Jr});var Pi=33,Cr={nose:0,leftShoulder:11,rightShoulder:12,leftElbow:13,rightElbow:14,leftWrist:15,rightWrist:16,leftHip:23,rightHip:24,leftKnee:25,rightKnee:26,leftAnkle:27,rightAnkle:28};var Ni=4,vt=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"];var Ii={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},No=Ii["6-8"];var $n=(s,r)=>s?{x:s.x+r.x*s.w,y:s.y+r.y*s.h}:{x:r.x,y:r.y};var Io=16/9;var Oi=12,Bi=Pi*4,Di=s=>Oi+s*Bi,Oo=Di(Ni);var Gi=s=>s.startsWith("fabi-play.")?`fablee-play.${s.slice(10)}`:null;function Vn(s,r,e=Gi(r)){if(!(!s||!e))try{let t=s.getItem(e);if(t===null)return;s.getItem(r)===null&&s.setItem(r,t),s.removeItem(e)}catch{}}var Wn=globalThis.FabiPlay?.avatars;if(!Wn)throw new Error("[engine] fabi-play-engine.lite.js needs fabi-play.js (with FabiPlay.avatars) loaded before it");var{avatarById:Ke,avatarShapes:Xn,BAND_BODY:Uo,DEFAULT_AVATAR:Ye,drawShapes:Lr,frameOf:jn,iconShapes:qn}=Wn;var ve=()=>Float64Array.of(1,0,0,1,0,0);function ee(s,r,e,t,n,i,o){let a=n?Math.cos(n):1,l=n?Math.sin(n):0,u=a*i,c=l*i,f=-l*o,p=a*o;if(!r)return s[0]=u,s[1]=c,s[2]=f,s[3]=p,s[4]=e,s[5]=t,s;let b=r[0],g=r[1],m=r[2],d=r[3];return s[0]=b*u+m*c,s[1]=g*u+d*c,s[2]=b*f+m*p,s[3]=g*f+d*p,s[4]=b*e+m*t+r[4],s[5]=g*e+d*t+r[5],s}function Yn(s,r,e){let t=s[0]*s[3]-s[1]*s[2];if(Math.abs(t)<1e-12)return null;let n=r-s[4],i=e-s[5];return[(s[3]*n-s[2]*i)/t,(-s[1]*n+s[0]*i)/t]}var Kn={white:16777215,black:0,red:16711680,transparent:0},wt=new Map;function K(s){if(typeof s=="number")return[s&16777215,1];let r=wt.get(s);if(r)return r;let e=[16777215,1],t=s.trim().toLowerCase();if(t[0]==="#"){let n=t.slice(1),i=n.length<=4?[...n].map(a=>a+a).join(""):n,o=parseInt(i.slice(0,6),16);Number.isFinite(o)&&(e=[o,i.length===8?parseInt(i.slice(6,8),16)/255:1])}else if(t.startsWith("rgb")){let n=t.match(/-?\d*\.?\d+%?/g)?.map(u=>u.endsWith("%")?parseFloat(u)/100*255:parseFloat(u))??[],[i=255,o=255,a=255]=n,l=n[3]===void 0?1:t.match(/,\s*[\d.]+%\s*\)$/)?n[3]/255:n[3];e=[(Pr(i)<<16|Pr(o)<<8|Pr(a))>>>0,Math.min(Math.max(l,0),1)]}else if(t in Kn)e=[Kn[t],t==="transparent"?0:1];else if(typeof document<"u"){let n=document.createElement("canvas").getContext("2d");if(n){n.fillStyle="#ffffff",n.fillStyle=t;let i=n.fillStyle;if(i!==t)return wt.set(s,e=K(i)),e}}return wt.size>512&&wt.clear(),wt.set(s,e),e}var Pr=s=>Math.min(Math.max(Math.round(s),0),255);function Re(s,r,e=!1){let t=Math.min(Math.max(r,0),1),n=(s>>16&255)*t,i=(s>>8&255)*t,o=(s&255)*t,a=e?0:t*255;return(Math.round(a)<<24|Math.round(o)<<16|Math.round(i)<<8|Math.round(n))>>>0}var Ue=(s,r=1)=>`rgba(${s>>16&255},${s>>8&255},${s&255},${r})`;function Nr(s,r){if(s===16777215)return r;if(r===16777215)return s;let e=t=>Math.round((s>>t&255)*(r>>t&255)/255);return(e(16)<<16|e(8)<<8|e(0))>>>0}var _e={linear:s=>s,quadIn:s=>s*s,quadOut:s=>s*(2-s),quadInOut:s=>s<.5?2*s*s:-1+(4-2*s)*s,cubicOut:s=>1-(1-s)**3,sineInOut:s=>-(Math.cos(Math.PI*s)-1)/2,backOut:s=>1+(1.70158+1)*(s-1)**3+1.70158*(s-1)**2,elasticOut:s=>s===0||s===1?s:2**(-10*s)*Math.sin((s*10-.75)*(2*Math.PI/3))+1,bounceOut:s=>s<1/2.75?7.5625*s*s:s<2/2.75?7.5625*(s-=1.5/2.75)*s+.75:s<2.5/2.75?7.5625*(s-=2.25/2.75)*s+.9375:7.5625*(s-=2.625/2.75)*s+.984375};function Qn(s){let r=s>>>0;return()=>{r=r+1831565813>>>0;let e=r;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}var T={cap:0,epoch:0,x:new Float64Array(0),y:new Float64Array(0),rot:new Float64Array(0),sx:new Float64Array(0),sy:new Float64Array(0),alpha:new Float64Array(0),la:new Float64Array(0),lb:new Float64Array(0),lc:new Float64Array(0),ld:new Float64Array(0),world:new Float64Array(0),tint:new Uint32Array(0),flags:new Uint8Array(0),moved:new Uint8Array(0),dirty:new Uint8Array(0),gen:new Uint32Array(0),parent:new Int32Array(0),first:new Int32Array(0),next:new Int32Array(0),prev:new Int32Array(0),stamp:new Uint32Array(0),pass:0,free:new Int32Array(0),freeHead:0,freeCount:0,top:2},Ce=[],Ui="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function Zn(s){let r=T;for(let t of Ui){let n=r[t],i=new n.constructor(t==="world"?s*6:s);i.set(n),r[t]=i}let e=new Int32Array(s);for(let t=0;t<T.freeCount;t++)e[t]=T.free[(T.freeHead+t)%T.cap];for(T.free=e,T.freeHead=0,T.cap=s,T.epoch++;Ce.length<s;)Ce.push(null)}function Or(s){T.x[s]=T.y[s]=T.rot[s]=0,T.sx[s]=T.sy[s]=T.alpha[s]=1,T.la[s]=T.ld[s]=1,T.lb[s]=T.lc[s]=0;let r=s*6,e=T.world;e[r]=e[r+3]=1,e[r+1]=e[r+2]=e[r+4]=e[r+5]=0,T.tint[s]=16777215,T.flags[s]=3,T.moved[s]=1,T.dirty[s]=0,T.parent[s]=T.first[s]=T.next[s]=T.prev[s]=-1}Zn(256);Or(0);T.flags[0]=0;Or(1);T.flags[1]=0;function Jn(){let s;if(T.freeCount){s=T.free[T.freeHead],T.freeHead=(T.freeHead+1)%T.cap,T.freeCount--;let r=Ce[s];r&&(r._i=0,r._g=-1,Ce[s]=null)}else T.top===T.cap&&Zn(T.cap*2),s=T.top++;return Or(s),s}function Br(s,r){Yt(s);for(let t=T.first[s];t>=0;){let n=T.next[t];T.parent[t]=T.next[t]=T.prev[t]=-1,t=n}T.first[s]=-1,T.flags[s]=T.flags[s]&-3,T.moved[s]=0;let e=T.gen[s]+1;T.gen[s]=e,e!==4294967295&&(r&&(Ce[s]=r),T.free[(T.freeHead+T.freeCount)%T.cap]=s,T.freeCount++)}function es(s){for(let r=0;r<Ce.length;r++){let e=Ce[r];e&&s(e)&&(e._i=0,e._g=-1,Ce[r]=null)}}function ts(s,r){Yt(s);let e=T.first[r];T.parent[s]=r,T.next[s]=e,T.prev[s]=-1,e>=0&&(T.prev[e]=s),T.first[r]=s,T.moved[s]=1}function Yt(s){let r=T.parent[s];if(r<0)return;let e=T.next[s],t=T.prev[s];t>=0?T.next[t]=e:T.first[r]=e,e>=0&&(T.prev[e]=t),T.parent[s]=T.next[s]=T.prev[s]=-1}var kt={root:-1,gen:-1,world:new Float64Array(6)};function rs(s){let r=++T.pass,e=T.world,t=s*6,n=kt.world,i=kt.root!==s||kt.gen!==T.gen[s];for(let o=0;o<6;o++)n[o]!==e[t+o]&&(i=!0),n[o]=e[t+o];kt.root=s,kt.gen=T.gen[s],T.stamp[s]=i?r:r-1}function ns(s){T.stamp[s]=T.pass}function ss(s){for(let r=T.first[s];r>=0;){let e=T.next[r];ss(r),r=e}Br(s)}var Ir=typeof FinalizationRegistry=="function"?new FinalizationRegistry(s=>T.gen[s.i]===s.g&&ss(s.i)):null;function Dr(s){s._reg||!Ir||(s._reg=!0,Ir.register(s,{i:s._i,g:s._g},s))}function is(s){s._reg&&Ir.unregister(s)}function At(s){if(s){for(let r=0;r<s.length;r++)if(s[r].enabled)return!0}return!1}function os(s,r){let e=0;for(let t=0;t<s.length;t++){let n=s[t];n.enabled&&n.pad&&(e+=n.pad(r))}return e}var te={gl:null,c2d:null,live:null};var B=new Float64Array(3),St=4,Hi=1,Tt=()=>Hi++;var W=ve(),_=T,oe=class{constructor(r){h(this,"kernel",r);h(this,"_i",Jn());h(this,"_g",_.gen[this._i]);h(this,"_wv",null);h(this,"_wi",-1);h(this,"_we",-1);h(this,"blend","normal");h(this,"_data",null);h(this,"parent",null);h(this,"hitRadius",null);h(this,"clip",null);h(this,"mask",null);h(this,"filters",null);h(this,"_z",0);h(this,"anchorX",0);h(this,"anchorY",0);h(this,"_pool",null);h(this,"_free",!1);h(this,"_reg",!1)}get x(){return _.x[this._i]}set x(r){let e=this._i||1;_.x[e]=r,_.moved[e]=1}get y(){return _.y[this._i]}set y(r){let e=this._i||1;_.y[e]=r,_.moved[e]=1}get rotation(){return _.rot[this._i]}set rotation(r){let e=this._i||1;_.rot[e]=r,_.dirty[e]=_.moved[e]=1}get scaleX(){return _.sx[this._i]}set scaleX(r){let e=this._i||1;_.sx[e]=r,_.dirty[e]=_.moved[e]=1}get scaleY(){return _.sy[this._i]}set scaleY(r){let e=this._i||1;_.sy[e]=r,_.dirty[e]=_.moved[e]=1}get alpha(){return _.alpha[this._i]}set alpha(r){let e=this._i||1;_.alpha[e]=r,_.moved[e]=1}get visible(){return(_.flags[this._i]&1)!==0}set visible(r){let e=this._i||1;r?_.flags[e]=_.flags[e]|1:_.flags[e]=_.flags[e]&-2,_.moved[e]=1}get destroyed(){return _.gen[this._i]!==this._g}get world(){let r=this._i||1;return(this._wi!==r||this._we!==_.epoch)&&(this._wv=_.world.subarray(r*6,r*6+6),this._wi=r,this._we=_.epoch),this._wv}get data(){return this._data??(this._data={})}set data(r){this._data=r}get scale(){return this.scaleX}set scale(r){this.scaleX=this.scaleY=r}get z(){return this._z}set z(r){r!==this._z&&(this._z=r,this.parent&&(this.parent.sortDirty=!0))}get tint(){return _.tint[this._i]}set tint(r){_.tint[this._i||1]=typeof r=="number"?r&16777215:K(r)[0]}set anchor(r){typeof r=="number"?this.anchorX=this.anchorY=r:(this.anchorX=r.x,this.anchorY=r.y)}get width(){return 0}set width(r){}get height(){return 0}set height(r){}set(r){for(let e in r){let t=r[e];t!==void 0&&(this[e]=t)}return this}destroy(){this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),Br(this._i,this),is(this),this.kernel.tweens.stopAll(this),this._pool?.forget(this))}updateWorld(){let r=this.parent?this.parent.updateWorld():null;return ee(this.world,r,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(r,e,t){}};function cs(s){es(r=>r.kernel===s)}var Gr=!1,as=Object.freeze([]),$e=class s extends oe{constructor(e){super(e);h(this,"children",as);h(this,"sortDirty",!1);h(this,"dead",!1);Dr(this)}add(e,...t){this.adopt(e);for(let n=0;n<t.length;n++)this.adopt(t[n]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&ts(e._i,this._i),this.children===as&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||Dr(e)}detach(e){let t=this.children,n=t.indexOf(e);if(n>=0){for(let i=n+1;i<t.length;i++)t[i-1]=t[i];t.pop()}e.parent===this&&(e.parent=null,e.destroyed||Yt(e._i))}clear(){for(let e of this.children)e.destroy()}destroy(){for(let e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(let t of this.children)t.destroyed?t.parent===this&&(t.parent=null):this.children[e++]=t;this.children.length=e}for(let e of this.children)e instanceof s&&e.sweep()}draw(e,t,n){if(Gr)return _.parent[this._i]<0&&!this.destroyed&&ns(this._i),this.drawChildren(e,t,n);Gr=!0;try{this.destroyed||rs(this._i),this.drawChildren(e,t,n)}finally{Gr=!1}}drawChildren(e,t,n){if(this.sortDirty){let l=new Map(this.children.map((u,c)=>[u,c]));this.children.sort((u,c)=>u.z-c.z||l.get(u)-l.get(c)),this.sortDirty=!1}let i=this.children,o=this._i,a=_.stamp[o]===_.pass;for(let l=0;l<i.length;l++){let u=i[l],c=u._i,f=_.alpha[c];if(_.gen[c]!==u._g||!(_.flags[c]&1)||f<=0)continue;if(a||_.moved[c]){_.moved[c]=0,_.stamp[c]=_.pass;let g,m,d,v;if(_.dirty[c]){_.dirty[c]=0;let z=_.rot[c],G=z?Math.cos(z):1,U=z?Math.sin(z):0,ge=_.sx[c],Me=_.sy[c];_.la[c]=g=G*ge,_.lb[c]=m=U*ge,_.lc[c]=d=-U*Me,_.ld[c]=v=G*Me}else g=_.la[c],m=_.lb[c],d=_.lc[c],v=_.ld[c];let x=_.world,S=_.x[c],w=_.y[c],A=c*6,E=o*6,R=x[E],C=x[E+1],I=x[E+2],H=x[E+3];x[A]=R*g+I*m,x[A+1]=C*g+H*m,x[A+2]=R*d+I*v,x[A+3]=C*d+H*v,x[A+4]=R*S+I*w+x[E+4],x[A+5]=C*S+H*w+x[E+5]}let p=t*f,b=Nr(n,_.tint[c]);u.clip||u.mask||u.filters?hs(e,u,p,b):u.draw(e,p,b)}}},Q=new Float64Array(128),He=0,Ur=new Float64Array(8);function Hr(s,r,e,t){r.clip||r.mask||r.filters?hs(s,r,e,t):r.draw(s,e,t)}function hs(s,r,e,t){let n=s.r,i=r.world,o=r.clip,a=!1,l=!1;if(o)if(Math.abs(i[1])<1e-9&&Math.abs(i[2])<1e-9&&He<32){let f=i[0]*o.x+i[4],p=i[0]*(o.x+o.width)+i[4],b=i[3]*o.y+i[5],g=i[3]*(o.y+o.height)+i[5],m=Math.min(f,p),d=Math.max(f,p),v=Math.min(b,g),x=Math.max(b,g);if(He){let w=(He-1)*4;m=Math.max(m,Q[w]),v=Math.max(v,Q[w+1]),d=Math.min(d,Q[w+2]),x=Math.min(x,Q[w+3])}let S=He++*4;Q[S]=m,Q[S+1]=v,Q[S+2]=d,Q[S+3]=x,n.clip(m,v,Math.max(d-m,0),Math.max(x-v,0)),l=!0}else a=!0;let u=r.mask&&r.mask.visible?r.mask:null,c=At(r.filters)?r.filters:null;try{if(a&&n.beginLayer(),u&&n.beginLayer(),c?(r.draw(s,n.beginLayer()?1:e,t),n.endLayer(e,c)):r.draw(s,e,t),u&&(n.beginMask(),ee(u.world,i,u.x,u.y,u.rotation,u.scaleX,u.scaleY),Hr(s,u,u.alpha,16777215),n.endLayer(1)),a&&o){n.beginMask();for(let f=0;f<4;f++){let p=f===1||f===2?o.x+o.width:o.x,b=f>1?o.y+o.height:o.y;Ur[f*2]=i[0]*p+i[2]*b+i[4],Ur[f*2+1]=i[1]*p+i[3]*b+i[5]}n.polygon(Ur,4,16777215,1),n.endLayer(1)}}finally{if(l)if(He--,He){let f=(He-1)*4;n.clip(Q[f],Q[f+1],Q[f+2]-Q[f],Q[f+3]-Q[f+1])}else n.unclip()}}var re=class extends oe{constructor(e,t,n){super(e);h(this,"_frame",null);h(this,"_w",null);h(this,"_h",null);h(this,"slice",0);h(this,"autoAnchor",!0);h(this,"frameName",null);t&&(this.frame=t),n?.anchor===void 0&&this.useFrameAnchor(),n&&this.set(n)}get frame(){return this._frame}set frame(e){this.frameName=typeof e=="string"?e:null,this._frame=typeof e=="string"?this.kernel.frame(e):e,this.autoAnchor&&this.useFrameAnchor()}set anchor(e){this.autoAnchor=!1,super.anchor=e}get naturalWidth(){let e=this.frameNow();return e?(e.sw??e.w)/e.scale-e.margin*2:0}get naturalHeight(){let e=this.frameNow();return e?(e.sh??e.h)/e.scale-e.margin*2:0}get width(){return this._w??this.naturalWidth}set width(e){this._w=e}get height(){return this._h??this.naturalHeight}set height(e){this._h=e}sizeQ(e){Je[0]=this._w??(e.sw??e.w)/e.scale-e.margin*2,Je[1]=this._h??(e.sh??e.h)/e.scale-e.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){let e=this._frame;if(!e)return;let t=(e.sw??e.w)/e.scale-e.margin*2,n=(e.sh??e.h)/e.scale-e.margin*2;this.anchorX=t>0?(e.ox-e.margin)/t:0,this.anchorY=n>0?(e.oy-e.margin)/n:0}draw(e,t,n){let i=this.frameNow();if(!i)return;let o=Je;this.sizeQ(i),o[2]=this.anchorX,o[3]=this.anchorY,o[4]=t,zi(e,i,this.world,this.slice,n,this.blend)}},Qe=new Float64Array(12),Ze=new Float64Array(12),Mt={x:0,y:0,w:0,h:0};function ls(s,r,e,t,n,i){r=Math.max(r,0),e=Math.max(e,0),t=Math.max(t,0);let o=e+t>n?e*n/(e+t):e,a=e+t>n?t*n/(e+t):t,l=o/i,u=a/i;if(l+u>r){let c=r/(l+u);l*=c,u*=c}s[0]=0,s[1]=l,s[2]=0,s[3]=o,s[4]=l,s[5]=r-l-u,s[6]=o,s[7]=n-o-a,s[8]=r-u,s[9]=u,s[10]=n-a,s[11]=a}var Je=new Float64Array(5);function zi(s,r,e,t,n,i){let o=Je,a=o[0],l=o[1],u=o[2],c=o[3],f=o[4],p=s.tex(r.surface),b=t===0?r.slice??0:t;if(b===0){let w=(r.sw??r.w)/r.scale-r.margin*2,A=(r.sh??r.h)/r.scale-r.margin*2,E=w>0?a/w:1,R=A>0?l/A:1,C=-u*a+((r.tx??0)/r.scale-r.margin)*E,I=-c*l+((r.ty??0)/r.scale-r.margin)*R;Et(e,C,I),B[0]=r.w/r.scale*E,B[1]=r.h/r.scale*R,B[2]=f,s.r.quadQ(p,r,W,n,i);return}let g=r.tx??0,m=r.ty??0,d=(r.sw??r.w)-r.w-g,v=(r.sh??r.h)-r.h-m,x=-u*a-r.margin+g/r.scale,S=-c*l-r.margin+m/r.scale;if(ls(Qe,a+r.margin*2-(g+d)/r.scale,(typeof b=="number"?b:b[3])-g,(typeof b=="number"?b:b[1])-d,r.w,r.scale),ls(Ze,l+r.margin*2-(m+v)/r.scale,(typeof b=="number"?b:b[0])-m,(typeof b=="number"?b:b[2])-v,r.h,r.scale),Et(e,x,S),B[2]=f,!s.r.nineQ?.(p,r,Qe,Ze,W,n,i))for(let w=0;w<12;w+=4){let A=Ze[w+1],E=Ze[w+3];if(!(A<=0||E<=0))for(let R=0;R<12;R+=4){let C=Qe[R+1],I=Qe[R+3];C<=0||I<=0||(Mt.x=r.x+Qe[R+2],Mt.y=r.y+Ze[w+2],Mt.w=I,Mt.h=E,Et(e,x+Qe[R],S+Ze[w]),B[0]=C,B[1]=A,B[2]=f,s.r.quadQ(p,Mt,W,n,i))}}}function Et(s,r,e){W[0]=s[0],W[1]=s[1],W[2]=s[2],W[3]=s[3],W[4]=s[0]*r+s[2]*e+s[4],W[5]=s[1]*r+s[3]*e+s[5]}var fe=class extends re{constructor(e,t,n={}){super(e,null);h(this,"_spec");h(this,"baked",null);h(this,"bakedEffects",!0);this._spec=t,this.bake(),n.anchor===void 0&&this.useFrameAnchor(),this.set(n)}get spec(){return this._spec}set spec(e){this._spec=e,this.baked=null,this._w=this._h=null,this.bake()}bake(){let e=this.kernel;return this.baked&&e.atlas.valid(this.baked.frame)&&this.baked.frame.scale===e.pixelScale&&this.bakedEffects===e.effects?this.baked:(this.bakedEffects=e.effects,this.baked=e.shape(this._spec),this._frame=this.baked.frame,this.slice=this.baked.slice,this.baked)}frameNow(){return this.bake().frame}sizeQ(){let e=this.bake();Je[0]=this._w??e.w,Je[1]=this._h??e.h}get width(){return this._w??this.bake().w}set width(e){this._w=e}get height(){return this._h??this.bake().h}set height(e){this._h=e}},us=(s,r,e)=>s===void 0?r:typeof s=="number"?s:s[0]+(s[1]-s[0])*e(),ze=class ze extends oe{constructor(e,t,n={}){super(e);h(this,"max");h(this,"f");h(this,"tints");h(this,"count",0);h(this,"gravity");h(this,"drag");h(this,"frameRef");h(this,"random",Math.random);this.frameRef=t,this.max=Math.max(1,Math.floor(n.max??200)),this.f=new Float32Array(this.max*ze.W),this.tints=new Uint32Array(this.max),this.blend=n.blend??"normal",this.gravity=n.gravity??0,this.drag=n.drag??1}get alive(){return this.count}burst(e,t,n,i={}){let o=ze.W,a=this.random,l=i.tint===void 0?16777215:K(i.tint)[0];for(let u=0;u<n;u++){let c=this.count;if(c>=this.max){let d=0,v=1/0;for(let x=0;x<this.max;x++){let S=this.f[x*o+5]-this.f[x*o+4];S<v&&(v=S,d=x)}c=d}else this.count++;let f=(i.angle??0)+(i.spread===void 0?a()*Math.PI*2:(a()-.5)*i.spread),p=us(i.speed,200,a),b=Array.isArray(i.scale)?i.scale[0]:i.scale??1,g=Array.isArray(i.scale)?i.scale[1]:i.scale??1,m=c*o;this.f[m]=e,this.f[m+1]=t,this.f[m+2]=Math.cos(f)*p,this.f[m+3]=Math.sin(f)*p,this.f[m+4]=0,this.f[m+5]=Math.max(us(i.life,.8,a),.01),this.f[m+6]=a()*Math.PI*2,this.f[m+7]=(a()-.5)*2*(i.spin??0),this.f[m+8]=b,this.f[m+9]=g,this.f[m+10]=i.alpha??1,this.tints[c]=l}}update(e){let t=ze.W,n=this.f,i=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let o=0;o<this.count;){let a=o*t;if(n[a+4]=n[a+4]+e,n[a+4]>=n[a+5]){let l=--this.count;o!==l&&(n.copyWithin(a,l*t,l*t+t),this.tints[o]=this.tints[l]);continue}n[a+3]=(n[a+3]+this.gravity*e)*i,n[a+2]=n[a+2]*i,n[a]=n[a]+n[a+2]*e,n[a+1]=n[a+1]+n[a+3]*e,n[a+6]=n[a+6]+n[a+7]*e,o++}}clear(){this.count=0}draw(e,t,n){if(!this.count)return;let i=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,o=ze.W,a=this.f,l=this.world,u=i.w/i.scale,c=i.h/i.scale;for(let f=0;f<this.count;f++){let p=f*o,b=a[p+4]/a[p+5],g=a[p+8]+(a[p+9]-a[p+8])*b,m=t*a[p+10]*(1-b*b),d=a[p+6],v=Math.cos(d)*g,x=Math.sin(d)*g,S=a[p],w=a[p+1],A=l[0],E=l[1],R=l[2],C=l[3],I=A*v+R*x,H=E*v+C*x,z=R*v-A*x,G=C*v-E*x;W[0]=I,W[1]=H,W[2]=z,W[3]=G,W[4]=A*S+R*w+l[4]-(I*u+z*c)/2,W[5]=E*S+C*w+l[5]-(H*u+G*c)/2,B[0]=u,B[1]=c,B[2]=m,e.r.quadQ(e.tex(i.surface),i,W,Nr(n,this.tints[f]),this.blend)}}};h(ze,"W",11);var et=ze;var ae=class extends re{constructor(e,t,n={}){let{fps:i,loop:o,playing:a,speed:l,onComplete:u,...c}=n;if(!t.frames.length)throw new Error("[engine] an animation needs at least one frame");super(e,t.frames[0],c);h(this,"frames");h(this,"durations");h(this,"fps");h(this,"loop");h(this,"speed");h(this,"onComplete");h(this,"_playing");h(this,"index",0);h(this,"t",0);this.frames=t.frames,this.durations=t.durations&&i===void 0?t.durations:null,this.fps=i??12,this.loop=o!==!1,this.speed=l??1,this.onComplete=u??null,this._playing=a!==!1,this.speed<0&&this.show(t.frames.length-1)}get frameIndex(){return this.index}get frameCount(){return this.frames.length}get playing(){return this._playing}play(){return!this.loop&&!this._playing&&this.index===(this.speed<0?0:this.frames.length-1)&&this.show(this.speed<0?this.frames.length-1:0),this._playing=!0,this}stop(){return this._playing=!1,this}gotoFrame(e){let t=this.frames.length;return this.show((Math.floor(e)%t+t)%t),this.t=0,this}gotoAndPlay(e){return this._playing=!0,this.gotoFrame(e)}gotoAndStop(e){return this._playing=!1,this.gotoFrame(e)}show(e){e===this.index&&this._frame||(this.index=e,this.frame=this.frames[e])}secondsOf(e){let t=this.durations?.[e];return t!==void 0&&t>0?t:1/Math.max(this.fps,.001)}update(e){if(!this._playing||this.destroyed||this.speed===0)return;let t=this.frames.length,n=this.speed<0;this.t+=e*Math.abs(this.speed);let i=this.index;for(let o=0;o<1e3;o++){let a=this.secondsOf(i);if(this.t<a)break;this.t-=a;let l=n?i-1:i+1;if(l<0||l>=t){if(!this.loop){this.t=0,this._playing=!1,this.show(i),this.onComplete?.();return}i=n?t-1:0}else i=l}this.show(i)}},fs=(s,r)=>s.localeCompare(r,void 0,{numeric:!0});var Ft=class{constructor(r,e,t=2){h(this,"width",r);h(this,"height",e);h(this,"padding",t);h(this,"shelves",[]);h(this,"free",[]);h(this,"bottom",0)}alloc(r,e){let t=Math.ceil(r)+this.padding*2,n=Math.ceil(e)+this.padding*2;if(t>this.width||n>this.height)return null;for(let a=0;a<this.free.length;a++){let l=this.free[a];if(l.w>=t&&l.h>=n&&l.w*l.h<=t*n*2)return this.free.splice(a,1),this.inner(l.x,l.y,r,e)}let i=null;for(let a of this.shelves)a.h>=n&&a.h<=n*1.5+8&&this.width-a.x>=t&&(!i||a.h<i.h)&&(i=a);if(!i)if(this.bottom+n>this.height){for(let a of this.shelves)a.h>=n&&this.width-a.x>=t&&(i=a);if(!i)return null}else i={y:this.bottom,h:n,x:0},this.shelves.push(i),this.bottom+=n;let o=i.x;return i.x+=t,this.inner(o,i.y,r,e)}release(r){this.free.push({x:r.x-this.padding,y:r.y-this.padding,w:Math.ceil(r.w)+this.padding*2,h:Math.ceil(r.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(r,e,t,n){return{x:r+this.padding,y:e+this.padding,w:t,h:n}}},tt=s=>({source:s,texture:null,pending:[]}),Le=class{constructor(r=2048,e=4){h(this,"pageSize",r);h(this,"maxPages",e);h(this,"pages",[]);h(this,"gen",1);h(this,"onPage",()=>{});h(this,"onDrop",()=>{})}valid(r){return!!r&&(r.gen===this.gen||r.gen===0)}bake(r,e,t,n=1,i=0,o=0,a=0){let l=Math.max(1,Math.ceil(r)),u=Math.max(1,Math.ceil(e)),c=document.createElement("canvas");c.width=l,c.height=u;let f=c.getContext("2d");return t(f),this.put(c,l,u,n,i,o,a)}add(r,e=1,t=0,n=0){let i=document.createElement("canvas");return i.width=Math.max(1,r.width),i.height=Math.max(1,r.height),i.getContext("2d").drawImage(r,0,0),this.put(i,i.width,i.height,e,t,n,0)}release(r){if(r.gen!==this.gen)return;this.pages.find(t=>t.surface===r.surface)?.packer.release(r)}rebake(r,e,t,n,i=r.w,o=r.h){if(!this.valid(r)||e>i||t>o)return null;let a=Math.max(1,Math.ceil(e)),l=Math.max(1,Math.ceil(t)),u=this.pages.find(f=>f.surface===r.surface);if(!u)return null;let c=document.createElement("canvas");return c.width=Math.ceil(i),c.height=Math.ceil(o),n(c.getContext("2d")),u.ctx.clearRect(r.x,r.y,c.width,c.height),u.ctx.drawImage(c,r.x,r.y),r.surface.pending.push([c,r.x,r.y]),r.w=a,r.h=l,r}put(r,e,t,n,i,o,a){let l=null,u=this.pages.find(f=>(l=f.packer.alloc(e,t))!==null);if(u||(!(Math.max(e,t)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),u=this.pages[0],l=u?u.packer.alloc(e,t):null),(!u||!l)&&(u=this.newPage(Math.max(e,t)),l=u.packer.alloc(e,t))),!l)throw new Error(`[engine] ${e}\xD7${t} does not fit an atlas page`);let c=l;return u.ctx.drawImage(r,c.x,c.y),u.surface.pending.push([r,c.x,c.y]),{surface:u.surface,x:c.x,y:c.y,w:e,h:t,scale:n,gen:this.gen,ox:i,oy:o,margin:a}}newPage(r){let e=this.pageSize;for(;e<r+4;)e*=2;let t=document.createElement("canvas");t.width=t.height=e;let n=t.getContext("2d"),i=tt(t),o={surface:i,packer:new Ft(e,e),ctx:n};return this.pages.push(o),this.onPage(i),o}wipe(){this.gen++;let r=0;for(let e=0;e<this.pages.length;e++){let t=this.pages[e];if(r<this.maxPages&&t.surface.source.width===this.pageSize){this.pages[r++]=t;continue}t.surface.pending=[],this.onDrop(t.surface)}this.pages.length=r;for(let e of this.pages)e.packer.reset(),e.ctx.clearRect(0,0,e.surface.source.width,e.surface.source.height),e.surface.pending=[],e.surface.pending.push([e.surface.source,0,0])}};var $i=()=>globalThis.FabiPlay,Rt=class{posed(r,e,t,n=!0){let i={id:r,body:e};return $i()?.smoothedBody(i,{smooth:t<1?t:!1,interpolate:n})??e}};var ms=new Float64Array(1),ps=new Int32Array(ms.buffer),rt=(s,r)=>(s=Math.imul(s^r,1540483477),s^s>>>15);function ke(s,r=2538058380){return s!==s?rt(r,2146959360):(ms[0]=s===0?0:s,rt(rt(r,ps[0]),ps[1]))}function ds(s,r=2166136261){for(let e=0;e<s.length;e++)r=Math.imul(r^s.charCodeAt(e),16777619);return r}function ce(s){switch(typeof s){case"number":return ke(s);case"string":return ds(s);case"boolean":return s?1013904242:461845907;case"object":{if(s===null)return 625341585;if(Array.isArray(s)||s instanceof Float64Array){let t=1779033703^s.length;for(let n=0;n<s.length;n++){let i=s[n];t=rt(t,typeof i=="number"?ke(i):ce(i))}return t}let r=1359893119,e=s;for(let t in e){let n=e[t];n!==void 0&&(r=r+rt(ds(t),ce(n))|0)}return rt(r,2600822924)}default:return 0}}function nt(s,r){if(s===r)return!0;if(typeof s!="object"||typeof r!="object"||s===null||r===null)return typeof s=="number"&&typeof r=="number"&&s!==s&&r!==r;let e=Array.isArray(s)||s instanceof Float64Array;if(e!==(Array.isArray(r)||r instanceof Float64Array))return!1;if(e){let i=s,o=r;if(i.length!==o.length)return!1;for(let a=0;a<i.length;a++)if(i[a]!==o[a]&&!nt(i[a],o[a]))return!1;return!0}let t=s,n=r;for(let i in t)if(t[i]!==void 0&&!nt(t[i],n[i]))return!1;for(let i in n)if(n[i]!==void 0&&t[i]===void 0)return!1;return!0}function _t(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return s.map(_t);if(s instanceof Float64Array)return s.slice();let r={};for(let e in s)s[e]!==void 0&&(r[e]=_t(s[e]));return r}var st=class{constructor(r=1/0){h(this,"max",r);h(this,"buckets",new Map);h(this,"n",0)}get size(){return this.n}get(r,e=ce(r)){let t=this.buckets.get(e);if(t){for(let n=0;n<t.length;n++)if(nt(t[n].key,r))return t[n].value}}set(r,e,t=ce(r)){let n=this.buckets.get(t);if(n){for(let i of n)if(nt(i.key,r)){i.value=e;return}}this.n>=this.max&&this.clear(),(!n||!this.buckets.has(t))&&this.buckets.set(t,n=[]),n.push({key:_t(r),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}};var zr=0,bs=1,Zt=2,$r=3,it=class{constructor(){h(this,"scale",1);h(this,"cOn",!1);h(this,"px0",0);h(this,"py0",0);h(this,"px1",0);h(this,"py1",0);h(this,"clipVer",0);h(this,"stack",[]);h(this,"sp",0);h(this,"real",0);h(this,"mute",0);h(this,"bnd",new Float64Array(4*(St+1)));h(this,"rx0",0);h(this,"ry0",0);h(this,"rx1",0);h(this,"ry1",0);h(this,"maxBlur",1/0);h(this,"time",0);h(this,"skipped",0);h(this,"gq",new Float64Array(4))}resetLayers(r){this.scale=r,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){let r=this.gq;this.grow(r[0],r[1],r[2],r[3])}grow(r,e,t,n){if(!this.real)return;let i=this.bnd,o=(this.real-1)*4;r<i[o]&&(i[o]=r),e<i[o+1]&&(i[o+1]=e),t>i[o+2]&&(i[o+2]=t),n>i[o+3]&&(i[o+3]=n)}area(r,e){let t=this.bnd,n=r*4,i=this.scale;return this.rx0=Math.max(Math.floor((t[n]-e)*i)-1,0),this.ry0=Math.max(Math.floor((t[n+1]-e)*i)-1,0),this.rx1=Math.min(Math.ceil((t[n+2]+e)*i)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((t[n+3]+e)*i)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(r,e,t,n){let i=this.scale,o=this.canvas.width,a=this.canvas.height,l=Math.min(Math.max(Math.round(r*i),0),o),u=Math.min(Math.max(Math.round(e*i),0),a),c=Math.min(Math.max(Math.round((r+t)*i),l),o),f=Math.min(Math.max(Math.round((e+n)*i),u),a);this.cOn&&l===this.px0&&u===this.py0&&c===this.px1&&f===this.py1||(this.cOn=!0,this.px0=l,this.py0=u,this.px1=c,this.py1=f,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(r){if(r<Zt&&(this.mute||this.real>=St||!this.pushLayer())&&(r+=2),r===$r)this.mute++;else if(r!==Zt){let e=this.real*4;this.bnd[e]=this.bnd[e+1]=1/0,this.bnd[e+2]=this.bnd[e+3]=-1/0,this.real++}return this.stack[this.sp++]=r,r<Zt}beginLayer(){return this.push(zr)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===zr?bs:$r)}endLayer(r,e){if(!this.sp)return;let t=this.stack[--this.sp];if(t===$r){if(this.mute--,!this.sp)return;t=this.stack[--this.sp]}if(t===bs){let n=--this.real,i=this.popLayer();this.area(n-1,0)&&this.composite(i,!0,1,null);let o=this.bnd,a=(n-1)*4,l=n*4;o[a]=Math.max(o[a],o[l]),o[a+1]=Math.max(o[a+1],o[l+1]),o[a+2]=Math.min(o[a+2],o[l+2]),o[a+3]=Math.min(o[a+3],o[l+3]),t=this.stack[--this.sp]}if(t===Zt)At(e)&&(this.skipped+=e.length);else if(t===zr){let n=--this.real,i=At(e)?e:null,o=this.popLayer();if(this.area(n,i?os(i,this.maxBlur):0)){this.composite(o,!1,r,i);let a=this.scale;this.grow(this.rx0/a,this.ry0/a,this.rx1/a,this.ry1/a)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}};var Vi=256,ys=8<<20,ne=new Float64Array(32),se={x:0,y:0,w:0,h:0};function Wi(s){if(typeof s.filter!="string")return!1;s.filter="blur(1px)";let r=s.filter==="blur(1px)";return s.filter="none",r}function ot(s){let r=s.getContext("2d",{alpha:!0});return r?new Vr(s,r):null}var Vr=class extends it{constructor(e,t){super();h(this,"canvas",e);h(this,"ctx",t);h(this,"kind","canvas2d");h(this,"maxTextureSize",4096);h(this,"features",{});h(this,"info",{renderer:"canvas2d"});h(this,"support");h(this,"lost",!1);h(this,"fxr",null);h(this,"quads",0);h(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0});h(this,"tinted",new Map);h(this,"tintedN",0);h(this,"lostListeners",[]);h(this,"restoredListeners",[]);h(this,"base");h(this,"top");h(this,"layers",[]);h(this,"scratch",[]);h(this,"nines",new Map);h(this,"ninePx",0);h(this,"frame",0);h(this,"hit",!1);h(this,"missed",new Map);this.support={filters:Wi(t),shaders:!1},this.base=this.top={ctx:t,clipped:!1,ver:0},e.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(n=>n())}),e.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(n=>n())})}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){return{id:Tt(),width:e.width,height:e.height,source:e}}updateTexture(e,t,n=0,i=0){let o=t?n+t.width:1/0,a=t?i+t.height:1/0;for(let l of this.nines.values()){let u=l.key;u[0]===e.id&&u[1]<o&&u[1]+u[3]>n&&u[2]<a&&u[2]+u[4]>i&&this.dropNine(l)}for(let[l,u]of this.tinted){let c=u.filter(f=>f.id!==e.id);this.tintedN-=u.length-c.length,c.length?this.tinted.set(l,c):this.tinted.delete(l)}}destroyTexture(e){this.updateTexture(e)}begin(e,t,n){this.resetLayers(n),this.fxr?.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;let i=this.ctx;this.base.clipped&&i.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,this.canvas.width,this.canvas.height),t>0&&(i.fillStyle=Ue(e,t),i.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(e,t,n,i,o,a,l,u){B[0]=i,B[1]=o,B[2]=l,this.quadQ(e,t,n,a,u)}quadQ(e,t,n,i,o){t.w<=0||t.h<=0||(i===16777215?this.blit(e.source,t.x,t.y,t.w,t.h,n,o):this.blit(this.tint(e,t,i),0,0,t.w,t.h,n,o))}blit(e,t,n,i,o,a,l){let u=B[0],c=B[1],f=B[2];if(f<=0||this.mute)return;this.sync();let p=this.ctx,b=this.scale;if(this.real){let g=a[0]*u,m=a[1]*u,d=a[2]*c,v=a[3]*c;this.grow(a[4]+Math.min(0,g,d,g+d),a[5]+Math.min(0,m,v,m+v),a[4]+Math.max(0,g,d,g+d),a[5]+Math.max(0,m,v,m+v))}p.setTransform(a[0]*b,a[1]*b,a[2]*b,a[3]*b,a[4]*b,a[5]*b),p.globalAlpha=Math.min(f,1),l==="add"&&(p.globalCompositeOperation="lighter"),p.drawImage(e,t,n,i,o,0,0,u,c),l==="add"&&(p.globalCompositeOperation="source-over"),this.quads++}nineQ(e,t,n,i,o,a,l){var m,d;let u=n[8]+n[9],c=i[8]+i[9],f=Math.ceil(u*Math.hypot(o[0],o[1])*this.scale-1e-6),p=Math.ceil(c*Math.hypot(o[2],o[3])*this.scale-1e-6);if(o[1]===0&&o[2]===0||f>4096||p>4096)return!1;if(!(f>0&&p>0&&B[2]>0)||this.mute)return!0;let b=this.kept(e,t,n,i,f,p,a),g=(b??(b=(m=this.scratch)[d=13*Math.ceil(Math.log2(f))+Math.ceil(Math.log2(p))]??(m[d]=document.createElement("canvas").getContext("2d")))).canvas;if(g.width<f&&(g.width=f),g.height<p&&(g.height=p),!this.hit){b.clearRect(0,0,f+2,p+2);for(let v=0;v<12;v+=4){let x=Math.round(i[v]*p/c),S=Math.round((i[v]+i[v+1])*p/c);for(let w=0;w<12;w+=4){let A=Math.round(n[w]*f/u),E=Math.round((n[w]+n[w+1])*f/u);se.x=t.x+n[w+2],se.y=t.y+i[v+2],se.w=n[w+3],se.h=i[v+3],!(E<=A||S<=x||se.w<=0||se.h<=0)&&(a===16777215?b.drawImage(e.source,se.x,se.y,se.w,se.h,A,x,E-A,S-x):b.drawImage(this.tint(e,se,a),0,0,se.w,se.h,A,x,E-A,S-x))}}}return B[0]=u,B[1]=c,this.blit(g,0,0,f,p,o,l),!0}kept(e,t,n,i,o,a,l){ne[0]=e.id,ne[1]=t.x,ne[2]=t.y,ne[3]=t.w,ne[4]=t.h,ne[5]=o,ne[6]=a,ne[7]=l,ne.set(n,8),ne.set(i,20);let u=ce(ne),c=this.nines.get(u);if(this.hit=!1,c)return nt(c.key,ne)?(c.used=this.frame,this.hit=!0,c.ctx):null;let f=this.missed,p=f.get(u);f.size>4096&&f.clear(),f.set(u,this.frame);let b=o*a;if(p!==this.frame-1||b>ys)return null;let g;for(;this.ninePx+b>ys;){let v;for(let w of this.nines.values())w.used<this.frame-1&&!(v&&v.used<=w.used)&&(v=w);if(!v)return null;let x=v.ctx.canvas,S=!g&&x.width>=o&&x.height>=a&&x.width*x.height<=2*b;this.dropNine(v,S),S&&(g=v.ctx)}let m=g??document.createElement("canvas").getContext("2d"),d=m.canvas;return g||(d.width=o,d.height=a),this.ninePx+=d.width*d.height,this.nines.set(u,{key:_t(ne),ctx:m,used:this.frame}),m}dropNine(e,t=!1){this.nines.delete(ce(e.key));let n=e.ctx.canvas;this.ninePx-=n.width*n.height,t||(n.width=0)}dropNines(){for(let e of this.nines.values())this.dropNine(e)}tint(e,t,n){let i=ke(n,ke(t.h,ke(t.w,ke(t.y,ke(t.x,ke(e.id)))))),o=this.tinted.get(i);if(o)for(let u=0;u<o.length;u++){let c=o[u];if(c.id===e.id&&c.x===t.x&&c.y===t.y&&c.w===t.w&&c.h===t.h&&c.color===n)return c.canvas}this.tintedN>=Vi&&(this.tinted.clear(),this.tintedN=0,o=void 0);let a=document.createElement("canvas");a.width=Math.ceil(t.w),a.height=Math.ceil(t.h);let l=a.getContext("2d");return l.drawImage(e.source,t.x,t.y,t.w,t.h,0,0,t.w,t.h),l.globalCompositeOperation="multiply",l.fillStyle=Ue(n),l.fillRect(0,0,t.w,t.h),l.globalCompositeOperation="destination-in",l.drawImage(e.source,t.x,t.y,t.w,t.h,0,0,t.w,t.h),o||this.tinted.set(i,o=[]),o.push({id:e.id,x:t.x,y:t.y,w:t.w,h:t.h,color:n,canvas:a}),this.tintedN++,a}paint(e,t){this.sync();let n=this.ctx,i=this.scale;return n.setTransform(i,0,0,i,0,0),n.globalAlpha=Math.min(t,1),Ue(e)}ellipse(e,t,n,i,o,a,l){if(l<=0||n<=0||i<=0||this.mute)return;let u=Math.max(n,i);this.grow(e-u,t-u,e+u,t+u);let c=this.ctx;c.fillStyle=this.paint(a,l),c.beginPath(),c.ellipse(e,t,n,i,o,0,Math.PI*2),c.fill(),this.quads++}trace(e,t,n=0){if(this.real)for(let o=0;o<t;o++)this.grow(e[o*2]-n,e[o*2+1]-n,e[o*2]+n,e[o*2+1]+n);let i=this.ctx;i.beginPath(),i.moveTo(e[0],e[1]);for(let o=1;o<t;o++)i.lineTo(e[o*2],e[o*2+1])}polygon(e,t,n,i){if(i<=0||t<3||this.mute)return;let o=this.ctx;o.fillStyle=this.paint(n,i),this.trace(e,t),o.closePath(),o.fill(),this.quads++}stroke(e,t,n,i,o,a){if(o<=0||n<=0||t<1||this.mute)return;let l=this.ctx;l.strokeStyle=this.paint(i,o),l.lineWidth=n,l.lineCap="round",l.lineJoin="round",this.trace(e,t,n/2),t===1&&l.lineTo(e[0],e[1]),a&&l.closePath(),l.stroke(),this.quads++}sync(){let e=this.top;if(e.ver===this.clipVer)return;let t=e.ctx;e.clipped&&t.restore(),e.clipped=this.cOn,e.ver=this.clipVer,this.cOn&&(t.save(),t.setTransform(1,0,0,1,0,0),t.beginPath(),t.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),t.clip())}pushLayer(){let e=this.canvas.width,t=this.canvas.height,n=this.layers[this.real];if(!n||n.ctx.canvas.width!==e||n.ctx.canvas.height!==t){let o=document.createElement("canvas");o.width=e,o.height=t;let a=o.getContext("2d");if(!a)return!1;n=this.layers[this.real]={ctx:a,clipped:!1,ver:-1}}let i=n.ctx;return n.clipped&&i.restore(),n.clipped=!1,n.ver=-1,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,e,t),this.top=n,this.ctx=i,!0}popLayer(){return this.top=this.real>0?this.layers[this.real-1]:this.base,this.ctx=this.top.ctx,this.layers[this.real].ctx.canvas}composite(e,t,n,i){let o=e,a="none",l=i&&te.c2d?this.fxr??(this.fxr=te.c2d(this)):null;l&&(o=l.chain(e,i),a=l.css),this.sync();let u=this.ctx,c=this.rx0,f=this.ry0,p=this.rx1-c,b=this.ry1-f;u.setTransform(1,0,0,1,0,0),u.globalAlpha=Math.min(n,1),u.globalCompositeOperation=t?"destination-in":"source-over",a!=="none"&&(u.filter=a),u.drawImage(o,c,f,p,b,c,f,p,b),a!=="none"&&(u.filter="none"),u.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();let e=this.stats;return e.drawCalls=e.quads=this.quads,e.filtersSkipped=this.skipped,e}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],this.fxr?.destroy(),this.fxr=null}};var Jt=class{constructor(r,e,t=8192){h(this,"instanced",r);h(this,"slots",e);h(this,"capacity",t);h(this,"f32");h(this,"u32");h(this,"quads",0);h(this,"textures");h(this,"bound",0);this.textures=new Array(e).fill(null);let n=t*(r?14:24),i=new ArrayBuffer(n*4);this.f32=new Float32Array(i),this.u32=new Uint32Array(i)}slot(r){let e=this.textures;for(let t=0;t<this.bound;t++)if(e[t]===r)return t;return this.bound>=this.slots?-1:(e[this.bound]=r,this.bound++)}has(r){for(let e=0;e<this.bound;e++)if(this.textures[e]===r)return!0;return!1}get full(){return this.quads>=this.capacity}get words(){return this.quads*(this.instanced?14:24)}reset(){this.quads=0;for(let r=0;r<this.bound;r++)this.textures[r]=null;this.bound=0}push(r,e,t,n,i,o,a,l,u,c,f,p,b,g){let m=this.f32;if(this.instanced){let d=this.quads*14;m[d++]=r,m[d++]=e,m[d++]=t,m[d++]=n,m[d++]=i,m[d++]=o,m[d++]=a,m[d++]=l,m[d++]=u,m[d++]=c,m[d++]=f,m[d++]=p,this.u32[d++]=b,m[d]=g}else{let d=this.quads*6*4;this.vertex(d,r,e,u,c,b,g),this.vertex(d+6,t,n,f,c,b,g),this.vertex(d+12,i,o,f,p,b,g),this.vertex(d+18,a,l,u,p,b,g)}this.quads++}pushQ(r,e){let t=this.f32;if(this.instanced){let n=this.quads*14;for(let i=0;i<12;i++)t[n+i]=r[i];this.u32[n+12]=r[12],t[n+13]=e}else{let n=this.quads*6*4,i=r[12];for(let o=0;o<4;o++,n+=6)t[n]=r[o*2],t[n+1]=r[o*2+1],t[n+2]=o===1||o===2?r[10]:r[8],t[n+3]=o>=2?r[11]:r[9],this.u32[n+4]=i,t[n+5]=e}this.quads++}vertex(r,e,t,n,i,o,a){let l=this.f32;l[r]=e,l[r+1]=t,l[r+2]=n,l[r+3]=i,this.u32[r+4]=o,l[r+5]=a}};function gs(s){let r=new Uint16Array(s*6);for(let e=0,t=0,n=0;e<s;e++,t+=6,n+=4)r[t]=n,r[t+1]=n+1,r[t+2]=n+2,r[t+3]=n,r[t+4]=n+2,r[t+5]=n+3;return r}var Z={M:0,L:1,Q:2,C:3,Z:4},Ms=[2,2,4,6,0],Xi={M:0,L:1,Q:2,C:3,Z:4};function ir(s,r){if(s.length>=r)return s;let e=new Float64Array(Math.max(r,s.length*2,16));return e.set(s),e}var er=new Map;function ji(s){if(typeof s!="string")return s;let r=er.get(s);if(r)return r;r=[];let e=s.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[],t=-1;for(let n=0;n<e.length;){let i=e[n],o=Xi[i.toUpperCase()];if(o!==void 0){t=o,n++,o===Z.Z&&r.push(Z.Z);continue}if(t<0||t===Z.Z){n++;continue}let a=Ms[t];r.push(t);for(let l=0;l<a;l++)r.push(Number(e[n+l]??0));n+=a,t===Z.M&&(t=Z.L)}return er.size>256&&er.clear(),er.set(s,r),r}var Ne={subs:[],count:0},Wr=null,Pe=null;function tr(s,r){let e=Pe;e||(e=Ne.subs[Ne.count]??null,e||Ne.subs.push(e={pts:new Float64Array(64),n:0,closed:!1}),e.n=0,e.closed=!1,Ne.count++,Pe=e);let t=e.n*2;t+2>e.pts.length&&(e.pts=ir(e.pts,t+2));let n=Wr;n?(e.pts[t]=n[0]*s+n[2]*r+n[4],e.pts[t+1]=n[1]*s+n[3]*r+n[5]):(e.pts[t]=s,e.pts[t+1]=r),e.n++}function or(s,r=null,e=1,t=6){let n=ji(s);Ne.count=0,Pe=null,Wr=r;let i=0,o=0,a=0,l=0,u=e/t;for(let c=0;c<n.length;){let f=n[c++],p=n;if(f===Z.M)Pe=null,i=a=p[c],o=l=p[c+1],tr(i,o);else if(f===Z.L)i=p[c],o=p[c+1],tr(i,o);else if(f===Z.Q){let b=p[c],g=p[c+1],m=p[c+2],d=p[c+3],v=xs((pe(b-i,g-o)+pe(m-b,d-g))*u);for(let x=1;x<=v;x++){let S=x/v,w=1-S;tr(w*w*i+2*w*S*b+S*S*m,w*w*o+2*w*S*g+S*S*d)}i=m,o=d}else if(f===Z.C){let b=p[c],g=p[c+1],m=p[c+2],d=p[c+3],v=p[c+4],x=p[c+5],S=xs((pe(b-i,g-o)+pe(m-b,d-g)+pe(v-m,x-d))*u);for(let w=1;w<=S;w++){let A=w/S,E=1-A,R=E*E*E,C=3*E*E*A,I=3*E*A*A,H=A*A*A;tr(R*i+C*b+I*m+H*v,R*o+C*g+I*d+H*x)}i=v,o=x}else if(f===Z.Z){Pe&&(Pe.closed=!0),Pe=null,i=a,o=l;continue}else break;c+=Ms[f]}Pe=null,Wr=null;for(let c=0;c<Ne.count;c++){let f=Ne.subs[c],p=f.n*2;f.closed&&f.n>=2&&Math.abs(f.pts[0]-f.pts[p-2])<1e-6&&Math.abs(f.pts[1]-f.pts[p-1])<1e-6&&f.n--}return Ne}var pe=(s,r)=>Math.sqrt(s*s+r*r),xs=s=>Math.min(Math.max(Math.ceil(s),2),24);function qi(s,r){let e=0;for(let t=0,n=r-1;t<r;n=t++)e+=(s[n*2]-s[t*2])*(s[n*2+1]+s[t*2+1]);return e}var rr=new Int32Array(64),nr=(s,r,e,t,n)=>((s[t*2]-s[e*2])*(s[n*2+1]-s[e*2+1])-(s[t*2+1]-s[e*2+1])*(s[n*2]-s[e*2]))*r;function Es(s,r,e){if(r<3)return 0;rr.length<r&&(rr=new Int32Array(Math.max(r,rr.length*2)));let t=rr,n=r,i=0;for(let u=0;u<r;u++)t[u]=u;let o=qi(s,r)>0?1:-1,a=r*r+8,l=0;for(;n>3&&a-- >0;){let u=t[(l+n-1)%n],c=t[l%n],f=t[(l+1)%n],p=nr(s,o,u,c,f)>0;if(p)for(let b=0;b<n;b++){let g=t[b];if(!(g===u||g===c||g===f)&&nr(s,o,u,c,g)>=0&&nr(s,o,c,f,g)>=0&&nr(s,o,f,u,g)>=0){p=!1;break}}p?(e[i++]=u,e[i++]=c,e[i++]=f,t.copyWithin(l%n,l%n+1,n),n--,l=Math.max(l-1,0)):l=(l+1)%n}if(n===3)e[i++]=t[0],e[i++]=t[1],e[i++]=t[2];else if(n>3)for(let u=1;u+1<n;u++)e[i++]=t[0],e[i++]=t[u],e[i++]=t[u+1];return i}var Ki=.85,sr=new Float64Array(64),vs=new Float64Array(64),ws=new Float64Array(64),ks=new Float64Array(64),As=new Float64Array(64),Ss=new Float64Array(64),Ts=new Uint8Array(64),Ct=new Float64Array(8);function Fs(s,r,e,t,n,i){let o=Ct;if(sr.length<r){let d=Math.max(r,sr.length*2);sr=new Float64Array(d),vs=new Float64Array(d),ws=new Float64Array(d),ks=new Float64Array(d),As=new Float64Array(d),Ss=new Float64Array(d),Ts=new Uint8Array(d)}let a=sr,l=vs,u=0;for(let d=0;d<r;d++){let v=s[d*2],x=s[d*2+1];!Number.isFinite(v)||!Number.isFinite(x)||u&&Math.abs(a[u-1]-v)<.001&&Math.abs(l[u-1]-x)<.001||(a[u]=v,l[u]=x,u++)}if(t&&u>2&&Math.abs(a[0]-a[u-1])<.001&&Math.abs(l[0]-l[u-1])<.001&&u--,u===0)return;if(u===1)return o[0]=a[0],o[1]=l[0],i();let c=t?u:u-1,f=ws,p=ks;for(let d=0;d<c;d++){let v=(d+1)%u,x=a[v]-a[d],S=l[v]-l[d],w=pe(x,S)||1;f[d]=-S/w,p[d]=x/w}let b=As,g=Ss,m=Ts;for(let d=0;d<u;d++){let v=t?(d-1+c)%c:d-1,x=d<c?d:-1;if(m[d]=1,v<0||x<0||f[v]*f[x]+p[v]*p[x]<Ki)continue;let w=f[v]+f[x],A=p[v]+p[x],E=pe(w,A)||1;w/=E,A/=E;let R=e/Math.max(w*f[x]+A*p[x],.5);b[d]=w*R,g[d]=A*R,m[d]=0}for(let d=0;d<c;d++){let v=(d+1)%u,x=m[d]?f[d]*e:b[d],S=m[d]?p[d]*e:g[d],w=m[v]?f[d]*e:b[v],A=m[v]?p[d]*e:g[v];o[0]=a[d]+x,o[1]=l[d]+S,o[2]=a[v]+w,o[3]=l[v]+A,o[4]=a[v]-w,o[5]=l[v]-A,o[6]=a[d]-x,o[7]=l[d]-S,n()}for(let d=0;d<u;d++)m[d]&&(o[0]=a[d],o[1]=l[d],i())}function Xr(s,r){let e=0,t=1/0;for(let n=0;n<r.length;n++){let i=Math.abs(Math.log(Math.max(s,.5)/r[n]));i<t&&(t=i,e=n)}return e}var ar=[{x:240,y:0,w:8,h:8,r:3},{x:224,y:0,w:16,h:16,r:7},{x:192,y:0,w:32,h:32,r:15},{x:128,y:0,w:64,h:64,r:31},{x:0,y:0,w:128,h:128,r:63}],lr=[4,8,16,32,64,128].map((s,r)=>({x:r*4,y:128,w:4,h:s,r:s/2-1})),Ae={x:248,y:248,w:8,h:8},_s=ar.map(s=>s.r*2),Cs=lr.map(s=>s.r*2),Rs=(s,r)=>Math.min(Math.max(s+.5-r,0),1);function Yi(){let s=new Uint8ClampedArray(262144),r=(e,t,n)=>{let i=(t*256+e)*4;s[i]=s[i+1]=s[i+2]=255,s[i+3]=Math.round(n*255)};for(let e of ar){let t=e.w/2;for(let n=0;n<e.h;n++)for(let i=0;i<e.w;i++)r(e.x+i,e.y+n,Rs(e.r,Math.hypot(i+.5-t,n+.5-t)))}for(let e of lr){let t=e.h/2;for(let n=0;n<e.h;n++)for(let i=0;i<e.w;i++)r(e.x+i,e.y+n,Rs(e.r,Math.abs(n+.5-t)))}for(let e=0;e<Ae.h;e++)for(let t=0;t<Ae.w;t++)r(Ae.x+t,Ae.y+e,1);return s}function Ls(){let s=document.createElement("canvas");return s.width=s.height=256,s.getContext("2d").putImageData(new ImageData(Yi(),256,256),0,0),s}var Ps=8,ur=`
2
2
  #ifdef GL_FRAGMENT_PRECISION_HIGH
3
3
  precision highp float;
4
4
  #else
@@ -45,7 +45,7 @@ void main() {
45
45
  vColor = aColor;
46
46
  vSlot = aSlot;
47
47
  gl_Position = vec4(p * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
48
- }`,no={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},so=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],io=["aPos","aUv","aColor","aSlot"];function Is(s,r,e={}){let t={...no,failIfMajorPerformanceCaveat:e.failIfMajorPerformanceCaveat!==!1},n=r===2?s.getContext("webgl2",t):s.getContext("webgl",t)??s.getContext("experimental-webgl",t);if(!n||n.isContextLost())return null;try{return new qr(s,n,r,e)}catch(i){return console.warn("[engine] WebGL setup failed:",i),n.getExtension("WEBGL_lose_context")?.loseContext(),null}}var qr=class extends it{constructor(e,t,n,i){super();h(this,"canvas",e);h(this,"gl",t);h(this,"opts",i);h(this,"kind");h(this,"maxTextureSize");h(this,"support",{filters:!0,shaders:!0});h(this,"features",{});h(this,"info",{});h(this,"lost",!1);h(this,"main");h(this,"cur");h(this,"unit",-1);h(this,"onUnit",new Array(Ps).fill(void 0));h(this,"fbNow");h(this,"mapped",!0);h(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0});h(this,"vsrc","");h(this,"attrs",[]);h(this,"fxr",null);h(this,"batch");h(this,"dynamic");h(this,"staticBuf",null);h(this,"index");h(this,"vao",null);h(this,"inst",null);h(this,"vaoApi",null);h(this,"uScale",null);h(this,"textures",new Map);h(this,"kit");h(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0});h(this,"lostListeners",[]);h(this,"restoredListeners",[]);h(this,"tris",new Int32Array(192));h(this,"sU",0);h(this,"sV0",0);h(this,"sV1",0);h(this,"sColor",0);h(this,"sPacked",0);h(this,"sAlpha",0);h(this,"sHw",0);h(this,"strokeSeg",()=>{let e=this.q;e.set(Ct),e[8]=e[10]=this.sU,e[9]=this.sV0,e[11]=this.sV1,e[12]=this.sPacked,this.put(this.kit)});h(this,"strokeDisc",()=>this.ellipse(Ct[0],Ct[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha));h(this,"q",new Float64Array(13));h(this,"layers",[]);h(this,"layerTex",new Map);h(this,"bScis",!1);h(this,"bx0",0);h(this,"by0",0);h(this,"bx1",0);h(this,"by1",0);h(this,"onContextLost",e=>{e.preventDefault(),this.lost=!0;for(let t of this.lostListeners)t()});h(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(let e of this.textures.keys())this.textures.set(e,this.upload(e.source));this.lost=!1;for(let e of this.restoredListeners)e()}catch(e){console.warn("[engine] WebGL restore failed:",e)}});h(this,"views",new Map);this.kind=n===2?"webgl2":"webgl1",this.maxTextureSize=t.getParameter(t.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(Ls()),te.live=this,e.addEventListener("webglcontextlost",this.onContextLost,!1),e.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){let e=this.gl,t=this.kind==="webgl2"?e:null;if(this.inst=null,this.opts.instancing!==!1)if(t)this.inst={divisor:(f,d)=>t.vertexAttribDivisor(f,d),draw:(f,d)=>t.drawElementsInstanced(e.TRIANGLES,f,e.UNSIGNED_SHORT,0,d)};else{let f=e.getExtension("ANGLE_instanced_arrays");f&&(this.inst={divisor:(d,b)=>f.vertexAttribDivisorANGLE(d,b),draw:(d,b)=>f.drawElementsInstancedANGLE(e.TRIANGLES,d,e.UNSIGNED_SHORT,0,b)})}if(this.vaoApi=null,this.opts.vao!==!1)if(t)this.vaoApi={create:()=>t.createVertexArray(),bind:f=>t.bindVertexArray(f),remove:f=>t.deleteVertexArray(f)};else{let f=e.getExtension("OES_vertex_array_object");f&&(this.vaoApi={create:()=>f.createVertexArrayOES(),bind:d=>f.bindVertexArrayOES(d),remove:d=>f.deleteVertexArrayOES(d)})}let n=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),i=Math.max(1,Math.min(Ps,n)),o=this.inst!==null;this.vsrc=o?ro:to,this.attrs=o?so:io,this.main=this.cur=this.build(eo(i));let a=this.main.p;e.useProgram(a),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,e.uniform1iv(e.getUniformLocation(a,"uTex"),Int32Array.from({length:i},(f,d)=>d)),this.batch=new Jt(o,i),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic),e.bufferData(e.ARRAY_BUFFER,this.batch.f32.byteLength,e.DYNAMIC_DRAW),this.index=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.index),e.bufferData(e.ELEMENT_ARRAY_BUFFER,gs(o?1:8192),e.STATIC_DRAW);let l=f=>e.getAttribLocation(a,f),u=(f,d,b,g,p,m,v)=>{let x=l(f);x<0||(e.enableVertexAttribArray(x),e.vertexAttribPointer(x,d,b,g,p,m),this.inst&&this.inst.divisor(x,v))};if(o){let f=56;u("aP01",4,e.FLOAT,!1,f,0,1),u("aP23",4,e.FLOAT,!1,f,16,1),u("aUvRect",4,e.FLOAT,!1,f,32,1),u("aColor",4,e.UNSIGNED_BYTE,!0,f,48,1),u("aSlot",1,e.FLOAT,!1,f,52,1),this.staticBuf=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.staticBuf),e.bufferData(e.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),e.STATIC_DRAW),u("aCorner",4,e.FLOAT,!1,16,0,0),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic)}else{let f=24;u("aPos",2,e.FLOAT,!1,f,0,0),u("aUv",2,e.FLOAT,!1,f,8,0),u("aColor",4,e.UNSIGNED_BYTE,!0,f,16,0),u("aSlot",1,e.FLOAT,!1,f,20,0)}e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),e.disable(e.DEPTH_TEST),e.disable(e.CULL_FACE),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);let c=e.getExtension("WEBGL_debug_renderer_info");this.info={version:e.getParameter(e.VERSION),renderer:c?e.getParameter(c.UNMASKED_RENDERER_WEBGL):e.getParameter(e.RENDERER),vendor:c?e.getParameter(c.UNMASKED_VENDOR_WEBGL):e.getParameter(e.VENDOR)},this.features={instancing:o,vao:this.vaoApi!==null,textureSlots:i,maxTextureSize:this.maxTextureSize}}upload(e){let t=this.gl,n=t.createTexture();return this.bindTex(n),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),n}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){let t={id:Tt(),width:e.width,height:e.height,source:e};return this.textures.set(t,this.lost?null:this.upload(e)),t}updateTexture(e,t,n=0,i=0){if(this.lost)return;this.batch.has(e)&&this.flush();let o=this.gl,a=this.textures.get(e);a&&(this.bindTex(a),!t||t===e.source&&n===0&&i===0?o.texImage2D(o.TEXTURE_2D,0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,e.source):o.texSubImage2D(o.TEXTURE_2D,0,n,i,o.RGBA,o.UNSIGNED_BYTE,t))}destroyTexture(e){this.batch.has(e)&&this.flush();let t=this.textures.get(e);t&&!this.lost&&this.deleteTex(t),this.textures.delete(e)}begin(e,t,n){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(n),this.bScis=!1,this.lost)return;let i=this.gl;i.disable(i.SCISSOR_TEST),this.bindFb(null),i.viewport(0,0,this.canvas.width,this.canvas.height);let o=t;i.clearColor((e>>16&255)/255*o,(e>>8&255)/255*o,(e&255)/255*o,o),i.clear(i.COLOR_BUFFER_BIT),this.use(this.main),i.uniform2f(this.uScale,2*n/this.canvas.width,-2*n/this.canvas.height),this.mapped=!0}build(e){let t=this.gl,n=Ns(t,t.VERTEX_SHADER,this.vsrc),i;try{i=Ns(t,t.FRAGMENT_SHADER,e)}catch(a){throw t.deleteShader(n),a}let o=t.createProgram();if(t.attachShader(o,n),t.attachShader(o,i),this.attrs.forEach((a,l)=>t.bindAttribLocation(o,l,a)),t.linkProgram(o),t.deleteShader(n),t.deleteShader(i),!t.getProgramParameter(o,t.LINK_STATUS)){let a=t.getProgramInfoLog(o)??"?";throw t.deleteProgram(o),new Error(`link: ${a}`)}return{p:o,uScale:t.getUniformLocation(o,"uScale"),locs:new Map}}u(e,t){let n=e.locs.get(t);return n===void 0&&e.locs.set(t,n=this.gl.getUniformLocation(e.p,t)),n}use(e){this.cur!==e&&(this.cur=e,this.gl.useProgram(e.p),this.calls.useProgram++)}bindTex(e,t=this.unit<0?0:this.unit){let n=this.gl;this.onUnit[t]!==e&&(this.unit!==t&&(n.activeTexture(n.TEXTURE0+t),this.calls.activeTexture++,this.unit=t),n.bindTexture(n.TEXTURE_2D,e),this.calls.bindTexture++,this.onUnit[t]=e)}deleteTex(e){this.gl.deleteTexture(e);for(let t=0;t<this.onUnit.length;t++)this.onUnit[t]===e&&(this.onUnit[t]=null)}bindFb(e){if(e)for(let n=0;n<this.onUnit.length;n++)this.onUnit[n]===e.gl&&this.bindTex(null,n);let t=e?e.fb:null;this.fbNow!==t&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,t),this.calls.bindFramebuffer++,this.fbNow=t)}slotOf(e){this.batch.full&&this.flush();let t=this.batch.slot(e);return t<0&&(this.flush(),t=this.batch.slot(e)),t}quad(e,t,n,i,o,a,l,u){B[0]=i,B[1]=o,B[2]=l,this.quadQ(e,t,n,a,u)}quadQ(e,t,n,i,o){let a=B[2];if(this.lost||a<=0)return;let l=this.q,u=B[0],c=B[1],f=n[4],d=n[5],b=n[0]*u,g=n[1]*u,p=n[2]*c,m=n[3]*c;l[0]=f,l[1]=d,l[2]=b+f,l[3]=g+d,l[4]=b+p+f,l[5]=g+m+d,l[6]=p+f,l[7]=m+d;let v=1/e.width,x=1/e.height;l[8]=t.x*v,l[9]=t.y*x,l[10]=(t.x+t.w)*v,l[11]=(t.y+t.h)*x,l[12]=Re(i,a,o==="add"),this.put(e)}put(e){if(this.mute)return;let t=this.q,n=!1,i=Math.min(t[0],t[2],t[4],t[6]),o=Math.max(t[0],t[2],t[4],t[6]),a=Math.min(t[1],t[3],t[5],t[7]),l=Math.max(t[1],t[3],t[5],t[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;let c=this.scale,f=this.px0/c,d=this.py0/c,b=this.px1/c,g=this.py1/c;if(o<=f||i>=b||l<=d||a>=g)return;if(i<f||o>b||a<d||l>g){let p=t[0],m=t[1],v=t[2],x=t[5];if(m===t[3]&&v===t[4]&&x===t[7]&&t[6]===p){if(p!==v){let S=Math.min(Math.max(p,f),b),w=Math.min(Math.max(v,f),b),A=t[8],E=(t[10]-A)/(v-p);t[10]=A+(w-p)*E,t[8]=A+(S-p)*E,t[0]=t[6]=S,t[2]=t[4]=w}if(m!==x){let S=Math.min(Math.max(m,d),g),w=Math.min(Math.max(x,d),g),A=t[9],E=(t[11]-A)/(x-m);t[11]=A+(w-m)*E,t[9]=A+(S-m)*E,t[1]=t[3]=S,t[5]=t[7]=w}}else n=!0}}let u=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(n?(!this.bScis||!u)&&(this.flush(),this.bScis=!0,this.bx0=this.px0,this.by0=this.py0,this.bx1=this.px1,this.by1=this.py1):this.bScis&&!(this.cOn&&u)&&(this.flush(),this.bScis=!1),this.real){let c=this.gq;c[0]=i,c[1]=a,c[2]=o,c[3]=l,this.growQ()}this.batch.pushQ(t,this.slotOf(e))}ellipse(e,t,n,i,o,a,l){if(this.lost||l<=0||n<=0||i<=0)return;let u=ar[Xr(Math.max(n,i)*2*this.scale,_s)],c=u.w/2/u.r,f=n*c,d=i*c,b=Math.cos(o),g=Math.sin(o),p=b*f,m=g*f,v=-g*d,x=b*d,S=1/256,w=this.q;w[0]=e-p-v,w[1]=t-m-x,w[2]=e+p-v,w[3]=t+m-x,w[4]=e+p+v,w[5]=t+m+x,w[6]=e-p+v,w[7]=t-m+x,w[8]=u.x*S,w[9]=u.y*S,w[10]=(u.x+u.w)*S,w[11]=(u.y+u.h)*S,w[12]=Re(a,l),this.put(this.kit)}polygon(e,t,n,i){if(this.lost||i<=0||t<3)return;this.tris.length<t*3&&(this.tris=new Int32Array(Math.max(t*3,this.tris.length*2)));let o=this.tris,a=Es(e,t,o),l=Re(n,i),u=(Ae.x+Ae.w/2)/256,c=(Ae.y+Ae.h/2)/256;for(let f=0;f<a;f+=3){let d=o[f]*2,b=o[f+1]*2,g=o[f+2]*2,p=this.q;p[0]=e[d],p[1]=e[d+1],p[2]=e[b],p[3]=e[b+1],p[4]=p[6]=e[g],p[5]=p[7]=e[g+1],p[8]=p[10]=u,p[9]=p[11]=c,p[12]=l,this.put(this.kit)}}stroke(e,t,n,i,o,a){if(this.lost||o<=0||n<=0||t<1)return;let l=lr[Xr(n*this.scale,Cs)],u=n/2*(l.h/2/l.r);this.sPacked=Re(i,o),this.sColor=i,this.sAlpha=o,this.sU=(l.x+l.w/2)/256,this.sV0=l.y/256,this.sV1=(l.y+l.h)/256,this.sHw=n/2,Fs(e,t,u,a,this.strokeSeg,this.strokeDisc)}target(e,t,n,i){let o=this.gl,a=o.createTexture();this.bindTex(a),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,e,t,0,o.RGBA,o.UNSIGNED_BYTE,null);let l=i?o.LINEAR:o.NEAREST;o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,l),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,l),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),this.bindTex(null);let u=o.createFramebuffer();o.bindFramebuffer(o.FRAMEBUFFER,u),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,a,0);let c=o.checkFramebufferStatus(o.FRAMEBUFFER)===o.FRAMEBUFFER_COMPLETE;if(this.fbNow=u,this.bindFb(this.parent()),!c)return this.deleteTex(a),o.deleteFramebuffer(u),null;let f={tex:{id:Tt(),width:e,height:t,source:this.canvas},gl:a,fb:u,w:e,h:t,f:n};return this.layerTex.set(f.tex,a),f}drop(e){this.batch.has(e.tex)&&this.flush(),this.deleteTex(e.gl),this.gl.deleteFramebuffer(e.fb),this.layerTex.delete(e.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(e){let t=this.canvas.width,n=this.canvas.height,i=this.layers[e]??null;return i&&(i.w!==t||i.h!==n)&&(this.drop(i),i=this.layers[e]=null),i??(this.layers[e]=this.target(t,n,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();let e=this.layerAt(this.real);if(!e)return!1;let t=this.gl;return this.bindFb(e),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!te.gl?null:this.fxr??(this.fxr=te.gl(this))}composite(e,t,n,i){if(i&&this.filters()?.chain(e,n,i))return;let o=this.gl;t&&o.blendFunc(o.ZERO,o.SRC_ALPHA),this.final(this.main,e,1,n),t&&(this.flush(),o.blendFunc(o.ONE,o.ONE_MINUS_SRC_ALPHA))}final(e,t,n,i){let o=this.gl,a=this.canvas.width,l=this.canvas.height,u=this.scale;(e!==this.main||!this.mapped)&&(this.bindFb(this.parent()),o.viewport(0,0,a,l),this.use(e),o.uniform2f(e.uScale,2*u/a,-2*u/l),this.mapped=e===this.main);let c=this.rx0/u,f=this.ry0/u,d=this.rx1/u,b=this.ry1/u,g=1/(n*t.width),p=1/(n*t.height),m=this.q;m[0]=m[6]=c,m[1]=m[3]=f,m[2]=m[4]=d,m[5]=m[7]=b,m[8]=this.rx0*g,m[9]=1-this.ry0*p,m[10]=this.rx1*g,m[11]=1-this.ry1*p,m[12]=Re(16777215,i),this.put(t),e!==this.main&&this.flush()}remap(){let e=this.gl;this.bindFb(this.parent()),e.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),e.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(e){let t=this.gl,n=e.words;if(this.kind==="webgl2")return t.bufferSubData(t.ARRAY_BUFFER,0,e.f32,0,n);let i=this.views.get(n);i||(this.views.size>=256&&this.views.clear(),this.views.set(n,i=e.f32.subarray(0,n))),t.bufferSubData(t.ARRAY_BUFFER,0,i)}flush(){let e=this.batch;if(!e.quads||this.lost)return e.reset();let t=this.gl;this.bScis?(t.enable(t.SCISSOR_TEST),t.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):t.disable(t.SCISSOR_TEST),this.upload2(e);for(let n=0;n<e.bound;n++){let i=e.textures[n];this.bindTex(this.textures.get(i)??this.layerTex.get(i)??null,n)}this.inst?this.inst.draw(6,e.quads):t.drawElements(t.TRIANGLES,e.quads*6,t.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=e.quads,e.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){let e=this.gl;te.live===this&&(te.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(let t of this.textures.values())t&&e.deleteTexture(t);for(let t of this.layers)t&&(e.deleteTexture(t.gl),e.deleteFramebuffer(t.fb));this.fxr?.destroy(),this.fxr=null,e.deleteBuffer(this.dynamic),e.deleteBuffer(this.index),this.staticBuf&&e.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),e.deleteProgram(this.main.p),e.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function Ns(s,r,e){let t=s.createShader(r);if(s.shaderSource(t,e),s.compileShader(t),!s.getShaderParameter(t,s.COMPILE_STATUS)){let n=s.getShaderInfoLog(t)??"?";throw s.deleteShader(t),new Error(n)}return t}function jr(s="auto"){switch(s){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function lt(s,r={}){let e=s;for(let t of jr(r.renderer)){let n=t==="canvas2d"?ot(e):Is(e,t==="webgl2"?2:1,r);if(n)return n;e=Lt(e)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function Lt(s){let r=s.cloneNode(!1);return s.parentNode?.replaceChild(r,s),r}function Os(s=typeof location<"u"?location.search:""){let r=new URLSearchParams(s).get("renderer");return r==="canvas"?"canvas2d":r==="webgl2"||r==="webgl1"||r==="canvas2d"||r==="webgl"||r==="auto"?r:void 0}var Ie=class{constructor(r,e={}){h(this,"atlas",r);h(this,"tags",new Map);h(this,"count",0);h(this,"m",ve());h(this,"measure",null);h(this,"height");h(this,"font");this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(let r of this.tags.values())for(let e of r.values())for(let t of e.values())this.atlas.release(t);this.tags.clear(),this.count=0}get(r,e,t){let n=this.tags.get(r);n||this.tags.set(r,n=new Map);let i=n.get(e);i||n.set(e,i=new Map);let o=i.get(t);return o&&this.atlas.valid(o)?o:this.bake(r,e,t)}bake(r,e,t){let n=this.height,i=`700 ${Math.round(n*.65)}px ${this.font}`,o=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));o.font=i;let a=Math.round(n*.4),l=Math.ceil(o.measureText(r).width)+a*2,u=this.atlas.bake((l+2)*t,(n+2)*t,d=>{d.scale(t,t),d.translate(1,1);let b=n/2;d.beginPath(),d.moveTo(b,0),d.lineTo(l-b,0),d.arc(l-b,b,b,-Math.PI/2,Math.PI/2),d.lineTo(b,n),d.arc(b,b,b,Math.PI/2,Math.PI*3/2),d.closePath(),d.fillStyle=e,d.fill(),d.fillStyle="#fff",d.font=i,d.textAlign="center",d.textBaseline="middle",d.fillText(r,l/2,n/2+1)},t,1,1,1);++this.count>64&&(this.drop(),this.count=1);let c=this.tags.get(r);c||this.tags.set(r,c=new Map);let f=c.get(e);return f||c.set(e,f=new Map),f.set(t,u),u}draw(r,e,t,n,i,o,a,l,u,c,f){let d=qn(t,i,{band:oo(n)});if(!d)return;let b=this.height,g=this.get(o,a,u),p=g.w/g.scale-2,m=Math.min(Math.max(d.head.x-p/2,4),c-p-4),v=Math.min(Math.max(d.head.y-d.headR*2.2-b,4),f-b-4);ee(this.m,null,m-1,v-1,0,1,1),r.quad(e(g.surface),g,this.m,g.w/g.scale,g.h/g.scale,16777215,l,"normal")}},oo=s=>s.band==="3-5"||s.band==="9-12"?s.band:"6-8";var ao=(s,r=!1)=>r?Math.min(2**Math.round(Math.log2(Math.max(s,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(s,8))*2)/2),512);function hr(s,r=null){let e={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},t=(n,i,o)=>{let a=r?r[0]*n+r[2]*i+r[4]:n,l=r?r[1]*n+r[3]*i+r[5]:i,u=r?Math.hypot(r[0],r[1]):1;e.minX=Math.min(e.minX,a-o*u),e.minY=Math.min(e.minY,l-o*u),e.maxX=Math.max(e.maxX,a+o*u),e.maxY=Math.max(e.maxY,l+o*u)};for(let n of s){let i="lw"in n&&n.stroke?(n.lw??1)/2:0;switch(n.k){case"circle":t(n.x-n.r,n.y-n.r,i),t(n.x+n.r,n.y+n.r,i),t(n.x-n.r,n.y+n.r,i),t(n.x+n.r,n.y-n.r,i);break;case"ellipse":case"rect":{let o=n.k==="ellipse"?Math.max(n.rx,n.ry):Math.hypot(n.w,n.h)/2;t(n.x-o,n.y-o,i),t(n.x+o,n.y+o,i),t(n.x-o,n.y+o,i),t(n.x+o,n.y-o,i);break}case"path":{let o=or(n.d);for(let a=0;a<o.count;a++){let l=o.subs[a];for(let u=0;u<l.n;u++)t(l.pts[u*2],l.pts[u*2+1],i)}break}case"line":for(let o=0;o+1<n.pts.length;o+=2)t(n.pts[o],n.pts[o+1],i);break;case"group":{let o=ee(ve(),r,n.x,n.y,n.rot??0,n.s??1,n.s??1),a=hr(n.items,o);Number.isFinite(a.minX)&&(e.minX=Math.min(e.minX,a.minX),e.minY=Math.min(e.minY,a.minY),e.maxX=Math.max(e.maxX,a.maxX),e.maxY=Math.max(e.maxY,a.maxY));break}}}return e}var Ve=class{constructor(r){h(this,"atlas",r);h(this,"seen",new WeakSet);h(this,"baked",new WeakMap);h(this,"m",ve());h(this,"stack",[]);h(this,"local",ve());h(this,"pts",new Float64Array(128));h(this,"stats",{baked:0,vector:0});h(this,"bakeGroups",!0);h(this,"coarse",!1);h(this,"gen",0);h(this,"live",new Set)}setTier(r){let e=r==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(let t of this.live)this.atlas.release(t.frame);this.live.clear()}}draw(r,e,t,n,i,o,a){let l=typeof n=="string"?Ke(n)??Ye:n,u=Xn(t,l,i);return u.length?(o<=0||(o<1?(this.paint(r,e,u,null,r.beginLayer()?1:o,a),r.endLayer(o)):this.paint(r,e,u,null,o,a)),!0):!1}paint(r,e,t,n,i,o,a=0){var l;for(let u=0;u<t.length;u++){let c=t[u];if(c.k==="group"){let x=ee((l=this.stack)[a]??(l[a]=ve()),n,c.x,c.y,c.rot??0,c.s??1,c.s??1),S=i*(c.alpha??1);if(this.bakeGroups&&this.seen.has(c.items)){let w=de(x[0],x[1])*o,A=this.bake(c.items,w);if(A){let E=A.frame,R=this.m;R.set(x),R[4]=x[0]*-A.ox+x[2]*-A.oy+x[4],R[5]=x[1]*-A.ox+x[3]*-A.oy+x[5],r.quad(e(E.surface),E,R,E.w/A.k,E.h/A.k,16777215,S,"normal"),this.stats.baked++;continue}}this.seen.add(c.items),this.stats.vector++,this.paint(r,e,c.items,x,S,o,a+1);continue}let f=i*(c.alpha??1),d=n?de(n[0],n[1]):1,b=n?Math.atan2(n[1],n[0]):0,g=(c.lw??1)*d,p=c.stroke&&(c.lw??1)>0?K(c.stroke):null,m=c.fill&&c.k!=="line"?K(c.fill):null;if(c.k==="circle"||c.k==="ellipse"){let x=n?n[0]*c.x+n[2]*c.y+n[4]:c.x,S=n?n[1]*c.x+n[3]*c.y+n[5]:c.y,w=(c.k==="circle"?c.r:c.rx)*d,A=(c.k==="circle"?c.r:c.ry)*d,E=(c.k==="ellipse"?c.rot??0:0)+b;if(m&&p)r.ellipse(x,S,w+g/2,A+g/2,E,p[0],f*p[1]),r.ellipse(x,S,Math.max(w-g/2,0),Math.max(A-g/2,0),E,m[0],f*m[1]);else if(m)r.ellipse(x,S,w,A,E,m[0],f*m[1]);else if(p){let R=Math.min(Math.max(Math.ceil(Math.max(w,A)*o*.6),12),64),C=this.pts=ir(this.pts,R*2),I=Math.cos(E),H=Math.sin(E);for(let z=0;z<R;z++){let G=z/R*Math.PI*2,U=Math.cos(G)*w,ge=Math.sin(G)*A;C[z*2]=x+U*I-ge*H,C[z*2+1]=S+U*H+ge*I}r.stroke(C,R,g,p[0],f*p[1],!0)}continue}if(c.k==="line"){if(!p)continue;let x=c.pts.length>>1,S=this.pts=ir(this.pts,x*2);for(let w=0;w<x;w++){let A=c.pts[w*2],E=c.pts[w*2+1];S[w*2]=n?n[0]*A+n[2]*E+n[4]:A,S[w*2+1]=n?n[1]*A+n[3]*E+n[5]:E}r.stroke(S,x,g,p[0],f*p[1],!1);continue}let v=c.k==="path"?or(c.d,n,d*o):lo(c,ee(this.local,n,c.x,c.y,c.rot??0,1,1),o*d);for(let x=0;x<v.count;x++){let S=v.subs[x],w=S.n,A=c.k==="rect"||S.closed;m&&w>=3&&(r.polygon(S.pts,w,m[0],f*m[1]),p||r.stroke(S.pts,w,1/o,m[0],f*m[1],!0)),p&&r.stroke(S.pts,w,g,p[0],f*p[1],A)}}}bake(r,e){let t=ao(e,this.coarse),n=this.baked.get(r),i=n?.get(t);if(i&&i.gen===this.gen&&this.atlas.valid(i.frame))return i;i&&this.live.delete(i);let o=hr(r);if(!Number.isFinite(o.minX))return null;let a=2/t,l=(o.maxX-o.minX+a*2)*t,u=(o.maxY-o.minY+a*2)*t;if(l>1024||u>1024)return null;let c=-o.minX+a,f=-o.minY+a,b={frame:this.atlas.bake(l,u,g=>{g.scale(t,t),g.translate(c,f),Lr(g,r)}),k:t,ox:c,oy:f,gen:this.gen};return n||this.baked.set(r,n=new Map),n.set(t,b),this.live.add(b),b}},ut=new Array(36).fill(0),ct=0,me=(s,r=NaN,e=NaN,t=NaN,n=NaN)=>{ut[ct++]=s,s!==Z.Z&&(ut[ct++]=r,ut[ct++]=e,s===Z.Q&&(ut[ct++]=t,ut[ct++]=n))};function lo(s,r,e){let t=Math.max(0,Math.min(s.r,s.w/2,s.h/2)),n=-s.w/2,i=-s.h/2,{M:o,L:a,Q:l,Z:u}=Z;return ct=0,me(o,n+t,i),me(a,n+s.w-t,i),me(l,n+s.w,i,n+s.w,i+t),me(a,n+s.w,i+s.h-t),me(l,n+s.w,i+s.h,n+s.w-t,i+s.h),me(a,n+t,i+s.h),me(l,n,i+s.h,n,i+s.h-t),me(a,n,i+t),me(l,n,i,n+t,i),me(u),or(ut,r,e)}function Bs(s,r={}){let e=lt(s,r),t=new Le(Math.min(1024,e.maxTextureSize),2);t.onDrop=A=>{A.texture&&e.destroyTexture(A.texture),A.texture=null};let n=new Ve(t),i=new Rt,o=new Map,a=1e6,l=r.smooth===!1?1:typeof r.smooth=="number"?Math.min(Math.max(r.smooth,.05),1):.5,u=Pt(e),c=new Ie(t,r),f={w:1,h:1},d=1,b=0,g=!1,p=()=>c.drop(),m=typeof document<"u"?document.fonts:void 0;m?.ready?.then(()=>{g||p()}),m?.addEventListener?.("loadingdone",p);let v=()=>{let A=Lt(e.canvas),E=ot(A);if(E){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),e.destroy(),e=E;for(let R of t.pages)R.surface.texture=null;u=Pt(e),b=0}},x=()=>{if(!e.lost)return b=0,!0;let A=performance.now();return b||(b=A),A-b>3e3&&v(),!e.lost},S=()=>{let A=e.canvas;r.units?(d=r.pixelRatio??1,f.w=r.units.width,f.h=r.units.height):(d=r.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),f.w=A.clientWidth||A.width/d,f.h=A.clientHeight||A.height/d),e.resize(Math.max(1,Math.round(f.w*d)),Math.max(1,Math.round(f.h*d))),e.begin(0,0,d)},w=(A,E)=>{if(A.key===void 0)return A.id??E+1;let R=o.get(A.key);return R===void 0&&(o.size>256&&o.clear(),o.set(A.key,R=a++)),R};return{get renderer(){return e},get kind(){return e.kind},get lost(){return e.lost},get canvas(){return e.canvas},draw(A,E){if(x()){S();for(let R=0;R<A.length;R++){let C=A[R];if(!Array.isArray(C.body))continue;let I=w(C,R),H=l<1||r.interpolate!==!1?i.posed(I,C.body,l,r.interpolate!==!1):C.body,z=Ke(C.avatar??"")??Ye,G=C.alpha??1;!n.draw(e,u,H,z,E,G,d)||!C.name||c.draw(e,u,H,z,E,C.name,C.color??"#6FA0E0",G,d,f.w,f.h)}e.end()}},clear(){x()&&(S(),e.end())},reset(){i=new Rt,o.clear()},destroy(){g=!0,m?.removeEventListener?.("loadingdone",p),e.destroy()}}}var cr=new Map;function Ds(s,r,e=Math.min(globalThis.devicePixelRatio||1,2)){let t=`${s}|${r}|${e}`,n=cr.get(t);if(n)return n;n=document.createElement("canvas"),n.width=n.height=Math.round(r*e);let i=n.getContext("2d");return i.scale(e,e),i.beginPath(),i.rect(0,0,r,r),i.clip(),Lr(i,jn(Ke(s)??Ye,r)),cr.size>64&&cr.clear(),cr.set(t,n),n}function Pt(s){return r=>{if(r.texture||(r.texture=s.createTexture(r.source),r.pending.length=0),r.pending.length){for(let[e,t,n]of r.pending)s.updateTexture(r.texture,e,t,n);r.pending.length=0}return r.texture}}var Kr='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',We="rgba(10,16,30,0.75)";function Yr(s,r){let e=s.size??40,t=s.outline?s.outline===!0?We:s.outline:null,n=t?s.outlineWidth??Math.max(e*.12,3):0,i=s.shadow&&r?s.shadow===!0?We:s.shadow:null,o=i?s.shadowBlur??e*.25:0;return{size:e,font:s.font??Kr,weight:s.weight??700,color:s.color??"#FBEFE3",outline:t,ow:n,shadow:i,blur:o,pad:n/2+o*1.2+2,th:e*1.25}}var Gs=(s,r)=>`${s.weight} ${s.size*r}px ${s.font}`;function Qr(s,r,e,t,n,i){s.scale(t,t),s.font=Gs(e,1),s.textBaseline="middle",s.textAlign="left",s.lineJoin="round",e.shadow&&(s.shadowColor=e.shadow,s.shadowBlur=e.blur*t),e.outline&&(s.strokeStyle=e.outline,s.lineWidth=e.ow,s.strokeText(r,n,i),s.shadowColor="transparent"),s.fillStyle=e.color,s.fillText(r,n,i)}var fr=null;function Zr(s,r,e){return fr??(fr=document.createElement("canvas").getContext("2d")),fr.font=Gs(r,e),fr.measureText(s).width/e}var pe=class extends re{constructor(e,t,n={}){super(e,null);h(this,"_text");h(this,"_style");h(this,"dirty",!0);h(this,"bakedScale",0);h(this,"bakedFontGen",-1);h(this,"bakedEffects",!0);h(this,"capW",0);h(this,"capH",0);this._text=t;let{x:i,y:o,rotation:a,scale:l,scaleX:u,scaleY:c,alpha:f,visible:d,tint:b,blend:g,z:p,anchor:m,hitRadius:v,clip:x,mask:S,filters:w,...A}=n;this._style=A,this.bake(),this.set({x:i,y:o,rotation:a,scale:l,scaleX:u,scaleY:c,alpha:f,visible:d,tint:b,blend:g,z:p,hitRadius:v,clip:x,mask:S,filters:w}),m!==void 0&&(this.anchor=m)}get text(){return this._text}set text(e){let t=String(e);t!==this._text&&(this._text=t,this.dirty=!0)}get style(){return this._style}set style(e){this._style={...this._style,...e},this.dirty=!0}bitmap(){let e=this._style.bitmapFont;if(!e)return null;let t=typeof e=="string"?this.kernel.bitmapFont(e):e;if(this.autoAnchor){let n=this._style.align;this.anchorX=n==="left"?0:n==="right"?1:.5,this.anchorY=.5}return t}get naturalWidth(){let e=this.bitmap();return e?e.measure(this._text)*((this._style.size??e.size)/e.size):super.naturalWidth}get naturalHeight(){let e=this.bitmap();return e?e.lineHeight*((this._style.size??e.size)/e.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(e,t,n){let i=this.bitmap();if(!i)return super.draw(e,t,n);let o=(this._style.size??i.size)/i.size,a=i.measure(this._text)*o,l=i.lineHeight*o,u=this.width,c=this.height,f=a>0?u/a:1,d=l>0?c/l:1;i.run(this._text,e,this.world,-this.anchorX*u,-this.anchorY*c,o*f,o*d,n,t,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){let e=this.kernel;if(this._style.bitmapFont)return null;let t=e.pixelScale,n=e.effects;return!this.dirty&&t===this.bakedScale&&e.fontGen===this.bakedFontGen&&n===this.bakedEffects&&e.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){let e=this.kernel,t=e.pixelScale,n=e.effects;this.dirty=!1,this.bakedScale=t,this.bakedFontGen=e.fontGen,this.bakedEffects=n;let i=Yr(this._style,n),{pad:o,th:a}=i,l=Zr(this._text,i,t),u=(l+o*2)*t,c=(a+o*2)*t,f=this._style.align??"center",d=f==="left"?o:f==="right"?o+l:o+l/2,b=m=>Qr(m,this._text,i,t,o,o+a/2),g=this._frame,p=null;return g&&e.atlas.valid(g)&&g.scale===t&&(p=e.atlas.rebake(g,u,c,b,this.capW,this.capH),p?Object.assign(p,{ox:d,oy:o+a/2,margin:o}):e.atlas.release(g)),p||(this.capW=Math.ceil(u*1.25+16),this.capH=Math.ceil(c),p=e.atlas.bake(this.capW,this.capH,b,t,d,o+a/2,o),p.w=Math.ceil(u),p.h=Math.ceil(c)),this._frame=p,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,p}};var X=(s,r=0)=>{let e=Number(s);return Number.isFinite(e)?e:r};function ft(s){typeof s=="string"&&/^\s*[{[]/.test(s)&&(s=JSON.parse(s));let r={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},e=(t,n)=>{t==="info"?r.size=Math.abs(X(n.size)):t==="common"?(r.lineHeight=X(n.lineHeight),r.base=X(n.base)):t==="page"?r.pages[X(n.id)]=String(n.file??""):t==="char"?r.chars.push({id:X(n.id),x:X(n.x),y:X(n.y),width:X(n.width),height:X(n.height),xoffset:X(n.xoffset),yoffset:X(n.yoffset),xadvance:X(n.xadvance),page:X(n.page)}):r.kernings.push({first:X(n.first),second:X(n.second),amount:X(n.amount)})};if(typeof s=="object"){let t=s;e("info",t.info??{}),e("common",t.common??{});for(let[n,i]of(t.pages??[]).entries())e("page",{id:n,file:i});for(let n of t.chars??[])e("char",n);for(let n of t.kernings??[])e("kerning",n)}else{let t=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,n=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let i=t.exec(s);i;i=t.exec(s)){let o={};for(let a=n.exec(i[2]);a;a=n.exec(i[2]))o[a[1]]=a[2]??a[3];e(i[1],o)}}return r.size||(r.size=r.lineHeight),r}var ht=class{constructor(r,e,t,n=null,i=null){h(this,"baker",n);h(this,"host",i);h(this,"size");h(this,"lineHeight");h(this,"base");h(this,"ascii",new Array(128));h(this,"more",new Map);h(this,"kern",new Map);h(this,"bScale",0);h(this,"bFontGen",-1);h(this,"bEffects",!1);h(this,"bGen",-1);this.size=r,this.lineHeight=e,this.base=t}set(r,e){r<128?this.ascii[r]=e:this.more.set(r,e)}setKerning(r,e,t){this.kern.set(r*1114112+e,t)}prepare(){let r=this.host;if(!(!r||r.pixelScale===this.bScale&&r.fontGen===this.bFontGen&&r.effects===this.bEffects&&r.atlas.gen===this.bGen)){this.bScale=r.pixelScale,this.bFontGen=r.fontGen,this.bEffects=r.effects,this.bGen=r.atlas.gen;for(let e of this.ascii)e&&r.atlas.release(e.frame);for(let e of this.more.values())e&&r.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(r){let e=r<128?this.ascii[r]:this.more.get(r);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(r):null,this.set(r,e)),e}kerning(r,e){return this.kern.size?this.kern.get(r*1114112+e)??0:0}measure(r){return this.run(r)}run(r,e,t,n=0,i=0,o=1,a=1,l=0,u=1,c="normal"){this.prepare();let f=0,d=-1;for(let b=0;b<r.length;b++){let g=r.charCodeAt(b);g>=55296&&g<56320&&b+1<r.length&&(g=r.codePointAt(b),b++),d>=0&&(f+=this.kerning(d,g)),d=g;let p=this.glyph(g);p&&(e&&p.w>0&&p.h>0&&(Et(t,n+(f+p.x)*o,i+p.y*a),e.r.quad(e.tex(p.frame.surface),p.frame,W,p.w*o,p.h*a,l,u,c)),f+=p.advance)}return f}};function Us(s,r){let e=new ht(s.size,s.lineHeight,s.base);for(let t of s.chars){let n=r[t.page];if(!n)continue;let i={surface:n,x:t.x,y:t.y,w:t.width,h:t.height,scale:1,gen:0,ox:0,oy:0,margin:0};e.set(t.id,{frame:i,x:t.xoffset,y:t.yoffset,w:t.width,h:t.height,advance:t.xadvance})}for(let t of s.kernings)e.setKerning(t.first,t.second,t.amount);return e}function Hs(s,r){let e={...r},t=r.size??40,n=o=>{let a=String.fromCodePoint(o),l=s.pixelScale,u=Yr(e,s.effects),c=Zr(a,u,l),f=s.atlas.bake((c+u.pad*2)*l,(u.th+u.pad*2)*l,d=>Qr(d,a,u,l,u.pad,u.pad+u.th/2),l);return{frame:f,x:-u.pad,y:-u.pad,w:f.w/l,h:f.h/l,advance:c}},i=new ht(t,t*1.25,t,n,s);i.prepare();for(let o of r.chars??"0123456789")i.glyph(o.codePointAt(0));return i}var uo=.5;function Jr(s){let r=[];for(let[e,t]of[["left",Cr.leftWrist],["right",Cr.rightWrist]]){let n=s[t*3],i=s[t*3+1],o=s[t*3+2];n!==void 0&&i!==void 0&&Number.isFinite(n)&&Number.isFinite(i)&&(o??0)>=uo&&r.push({side:e,x:n,y:i})}return r}var Nt=s=>vt[((s-1)%vt.length+vt.length)%vt.length];function dr(s,r,e,t,n=()=>null){let i=[];for(let o of s){let a=n(o)??o.body;if(Array.isArray(a))for(let l of Jr(a)){let u=r(l);i.push({player:o.id,side:l.side,x:u.x*e,y:u.y*t,color:Nt(o.id)})}}return i}function It(s,r,e,t=0){let n=s.world,i=Yn(n,r,e);if(!i)return!1;let o=Math.hypot(n[0],n[1])||1,a=Math.hypot(n[2],n[3])||1,[l,u]=i;if(s.hitRadius!=null){let g=s.hitRadius+t/((o+a)/2);return l*l+u*u<=g*g}let c=-s.anchorX*s.width-t/o,f=-s.anchorY*s.height-t/a,d=(1-s.anchorX)*s.width+t/o,b=(1-s.anchorY)*s.height+t/a;return l>=c&&l<=d&&u>=f&&u<=b}function mr(s,r,e,t=0){for(let n of r)if((e===void 0||n.player===e)&&It(s,n.x,n.y,t))return n;return null}function co(s){switch(s.type){case"circle":case"ring":case"star":return[s.r*2,s.r*2];case"ellipse":return[s.rx*2,s.ry*2];case"roundRect":return[s.w,s.h];case"line":return[s.length,s.lw??4];case"path":return s.r?[s.r*2,s.r*2]:[s.size,s.size]}}function ho(s){let r=s.type==="line"?0:s.stroke?(s.lw??2)/2:0,e=s.shadow?s.shadow.blur*1.5+Math.max(Math.abs(s.shadow.x??0),Math.abs(s.shadow.y??0)):0;return Math.ceil(r+e+1)}var zs=(s,r)=>r||!s.shadow?s:{...s,shadow:void 0};function en(s,r,e){let t=ho(r),n=r.type==="roundRect",[i,o]=n?[Math.min(r.w,r.r*2+4/e),Math.min(r.h,r.r*2+4/e)]:co(r),a=(i+t*2)*e,l=(o+t*2)*e;return{frame:s.bake(a,l,c=>{c.scale(e,e),c.translate(t+i/2,t+o/2),fo(c,r,i,o)},e,t+i/2,t+o/2,t),slice:n?Math.ceil((r.r+t)*e):0,w:n?r.w:i,h:n?r.h:o}}function fo(s,r,e,t){s.lineJoin="round",s.lineCap="round";let n=new Path2D;switch(r.type){case"circle":case"ring":n.arc(0,0,r.r,0,Math.PI*2);break;case"ellipse":n.ellipse(0,0,r.rx,r.ry,0,0,Math.PI*2);break;case"roundRect":n.roundRect(-e/2,-t/2,e,t,Math.min(r.r,e/2,t/2));break;case"star":{let u=r.points??5,c=r.r*(r.inner??.5);for(let f=0;f<u*2;f++){let d=f%2?c:r.r,b=-Math.PI/2+f*Math.PI/u;f?n.lineTo(Math.cos(b)*d,Math.sin(b)*d):n.moveTo(Math.cos(b)*d,Math.sin(b)*d)}n.closePath();break}case"line":n.moveTo(-e/2+t/2,0),n.lineTo(e/2-t/2,0);break;case"path":{let u=r.r?r.r*2/r.size:1,c=new DOMMatrix([u,0,0,u,-r.size/2*u,-r.size/2*u]);n.addPath(new Path2D(r.d),c);break}}let i=r.shadow,o=()=>{if(!i)return;let u=s.getTransform();s.shadowColor=i.color,s.shadowBlur=i.blur*u.a,s.shadowOffsetX=(i.x??0)*u.a,s.shadowOffsetY=(i.y??0)*u.a},a=()=>{s.shadowColor="transparent",s.shadowBlur=0};if(r.type==="line"){o(),s.strokeStyle=r.stroke??r.fill??"#fff",s.lineWidth=t,s.stroke(n);return}let l=r.type==="ring";if(r.outlineBelow&&r.fill&&r.stroke&&!l){o(),s.strokeStyle=r.stroke,s.lineWidth=r.lw??2,s.stroke(n),a(),s.fillStyle=r.fill,s.fill(n);return}r.fill&&!l&&(o(),s.fillStyle=r.fill,s.fill(n),a()),(r.stroke||l)&&((!r.fill||l)&&o(),l&&r.fill&&(s.fillStyle=r.fill,s.fill(n)),s.strokeStyle=r.stroke??"#fff",s.lineWidth=r.lw??2,s.stroke(n),a())}var dt=class{constructor(){h(this,"ctx",null);h(this,"master",null);h(this,"buffers",new Map);h(this,"held",!1);h(this,"muted",!1);h(this,"volume",1);if(typeof addEventListener=="function"){let r=()=>{this.context()?.resume().catch(()=>{})};for(let e of["pointerdown","keydown","touchstart"])addEventListener(e,r,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;let r=globalThis.AudioContext??globalThis.webkitAudioContext;if(!r)return null;try{this.ctx=new r,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch{return null}return this.ctx}async load(r,e){let t=this.context();if(!t)return;let n=await(await fetch(e)).arrayBuffer();this.buffers.set(r,await t.decodeAudioData(n))}has(r){return this.buffers.has(r)}play(r,e={}){let t=this.context(),n=this.buffers.get(r);if(!t||!n||!this.audible)return()=>{};let i=t.createBufferSource();i.buffer=n,i.loop=e.loop??!1,i.playbackRate.value=e.rate??1;let o=t.createGain();return o.gain.value=(e.volume??1)*this.volume,i.connect(o).connect(this.master),i.start(),()=>{try{i.stop()}catch{}}}tone(r,e=.25,t={}){let n=this.context();if(!(!n||!this.audible))try{let i=n.createOscillator(),o=n.createGain();i.type=t.type??"sine",i.frequency.setValueAtTime(r,n.currentTime),t.to&&i.frequency.exponentialRampToValueAtTime(t.to,n.currentTime+e),o.gain.setValueAtTime((t.volume??.12)*this.volume,n.currentTime),o.gain.exponentialRampToValueAtTime(.001,n.currentTime+e),i.connect(o).connect(this.master),i.start(),i.stop(n.currentTime+e)}catch{}}get audible(){return!this.muted&&!this.held}hold(){this.held=!0,this.ctx?.suspend().catch(()=>{})}release(){this.held=!1,this.ctx?.resume().catch(()=>{})}destroy(){this.ctx?.close().catch(()=>{}),this.ctx=null}};var mo={high:{resolution:1.5,particles:1,effects:!0,maxBlur:32},medium:{resolution:1,particles:.5,effects:!1,maxBlur:16},low:{resolution:.75,particles:.2,effects:!1,maxBlur:0}},be=["high","medium","low"];function Se(s){let r=mo[s];return{name:s,...r,scale:e=>e<=0?0:Math.max(1,Math.round(e*r.particles))}}var $s=s=>be[Math.min(be.indexOf(s)+1,be.length-1)],pr=(s,r)=>{if(!s.length)return NaN;let e=[...s].sort((t,n)=>t-n);return e[Math.min(e.length-1,Math.max(0,Math.floor(r*(e.length-1)+.5)))]},Vs=12,Ws=s=>Ot(s,.5);function Ot(s,r=.1){let e=pr(s,r);if(!Number.isFinite(e))return 1e3/60;let t=[144,120,90,75,60,50,30],n=60;for(let i of t)Math.abs(1e3/i-e)<Math.abs(1e3/n-e)&&(n=i);return 1e3/n}function br(s,r){let e=r.refresh!==void 0&&Number.isFinite(r.refresh)&&r.refresh>0?r.refresh:Ot(r.intervals),t=pr(r.intervals,.5),n=pr(r.intervals,.9),i=pr(r.cpu,.5);if(!Number.isFinite(t))return s==="canvas2d"?"low":"medium";let o=l=>l<=e*1.25,a=l=>!Number.isFinite(i)||i<e*l;return s==="canvas2d"?o(n)&&a(.25)?"medium":"low":o(n)&&a(.5)?"high":o(t)?"medium":"low"}function Xs(s,r){return s.length<30?!1:s.filter(t=>t>r*1.5).length/s.length>.5}var qs="0.1.1",po=720*3600*1e3,js=(s,r,e)=>`fabi-play.engine-tier:${qs}:${s}:${r}:${e}`,Ks=(s,r,e)=>`fablee-engine-tier:${qs}:${s}:${r}:${e}`;function Ys(s,r,e=Date.now()){try{let t=JSON.parse(s?.getItem(r)??"null");if(t&&be.includes(t.tier)&&typeof t.at=="number"&&e-t.at<po)return typeof t.refresh=="number"&&t.refresh>0?{name:t.tier,refresh:t.refresh}:{name:t.tier}}catch{}return null}function tn(s,r,e,t,n=Date.now()){try{s?.setItem(r,JSON.stringify(t!==void 0&&Number.isFinite(t)?{tier:e,at:n,refresh:t}:{tier:e,at:n}))}catch{}}function Qs(s=typeof location<"u"?location.search:""){let r=new URLSearchParams(s).get("tier");return be.includes(r)?r:void 0}function rn(s,r){let e=r?.tier;if(be.includes(e))return s==="canvas2d"&&e==="high"?"medium":e}var nn=s=>typeof s?.hz=="number"&&s.hz>=20&&s.hz<=240?Ot([1e3/s.hz],.5):NaN,sn=(s,r)=>be.indexOf(s)>=be.indexOf(r)?s:r;function Zs(s,r,e){return s?{name:s,from:"forced"}:r?{name:e?sn(r,e):r,from:"hint"}:e?{name:e,from:"cache"}:null}var bo=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,mt=class{constructor(r={}){h(this,"steps",[]);h(this,"labels",new Map);h(this,"end",0);h(this,"prevStart",0);h(this,"elapsed",0);h(this,"iter",0);h(this,"last",0);h(this,"delayLeft");h(this,"_paused");h(this,"done",!1);h(this,"rewinding",!1);h(this,"promise");h(this,"resolve");h(this,"repeat");h(this,"yoyo");h(this,"onComplete");this.repeat=Math.floor(r.repeat??0),this.yoyo=!!r.yoyo,this.delayLeft=r.delay??0,this._paused=!!r.paused,this.onComplete=r.onComplete,this.promise=new Promise(e=>this.resolve=e)}get duration(){return this.end}get time(){return this.last}get paused(){return this._paused}get finished(){return this.done}at(r){if(r===void 0)return this.end;if(typeof r=="number")return Math.max(r,0);let e=bo.exec(r);if(!e)throw new Error(`[engine] timeline: bad position "${r}"`);let[,t,n,i]=e,o=i?(n==="-"?-1:1)*Number(i):0,a=this.end;if(t==="<")a=this.prevStart;else if(t&&t!==">"){let l=this.labels.get(t.trim());l===void 0?this.labels.set(t.trim(),this.end):a=l}return Math.max(a+o,0)}add(r){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>r.start;)e--;return this.steps.splice(e,0,r),this.prevStart=r.start,this.end=Math.max(this.end,r.start+r.dur),this}to(r,e,t,n="quadOut"){let i=typeof n=="object"?n:{ease:n},o=typeof i.ease=="function"?i.ease:_e[i.ease??"quadOut"];return this.add({target:r,to:e,from:null,fn:null,start:this.at(i.at)+(i.delay??0),dur:Math.max(t,0),ease:o,onUpdate:i.onUpdate,p:-1})}set(r,e,t){return this.add({target:r,to:e,from:null,fn:null,start:this.at(t),dur:0,ease:_e.linear,p:-1})}call(r,e){return this.add({target:null,to:null,from:null,fn:r,start:this.at(e),dur:0,ease:_e.linear,p:-1})}label(r,e){return this.labels.set(r,this.at(e)),this}wait(r){return this.end+=Math.max(r,0),this.prevStart=this.end,this}pause(){return this._paused=!0,this}resume(){return this._paused=!1,this}stop(){this.done||(this.done=!0,this.resolve())}seek(r){let e=Math.min(typeof r=="string"&&this.labels.has(r)?this.labels.get(r):this.at(r),this.end),t=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(t?this.end-e:e),this.render(e),this}then(r,e){return this.promise.then(r,e)}update(r){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=r,this.delayLeft>0)return;r=-this.delayLeft,this.delayLeft=0}let e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=r;let t=this.repeat<0?1/0:e*(this.repeat+1),n=Math.min(this.elapsed,t),i=n>=t?this.repeat:Math.floor(n/e);for(;this.iter<i;){let a=this.yoyo&&this.iter%2===1;this.render(a?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}let o=n-i*e;this.render(this.yoyo&&i%2===1?e-o:o),n>=t&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(r){let e=this.steps;if(r>=this.last)for(let t=0;t<e.length;t++){let n=e[t];r>=n.start&&this.apply(n,r)}else for(let t=e.length-1;t>=0;t--){let n=e[t];n.p>=0&&this.apply(n,r)}this.last=r}apply(r,e){let t=r.dur>0?Math.min(Math.max((e-r.start)/r.dur,0),1):e>r.start||e===r.start&&!this.rewinding?1:0;if(t===r.p)return;if(r.p=t,r.fn){this.rewinding||r.fn();return}let n=r.target;if(n.destroyed||n._free)return;let i=r.to;if(!r.from){r.from={};for(let a in i)r.from[a]=Number(n[a]??0)}let o=r.ease(t);for(let a in i)n[a]=r.from[a]+(i[a]-r.from[a])*o;r.onUpdate?.(o)}};var pt=class{constructor(){h(this,"list",[]);h(this,"timelines",[])}timeline(r){let e=new mt(r);return this.timelines.push(e),e}tween(r,e,t,n="quadOut"){let i=typeof n=="object"?n:{ease:n},o=typeof i.ease=="function"?i.ease:_e[i.ease??"quadOut"],a,l=new Promise(u=>{let c=Object.keys(e),f=new Float64Array(c.length);c.forEach((d,b)=>f[b]=Number(e[d])),a={target:r,keys:c,to:f,from:new Float64Array(c.length),started:!1,duration:Math.max(t,0),time:0,delay:i.delay??0,ease:o,onUpdate:i.onUpdate,done:u,dead:!1}});return this.list.push(a),Object.assign(l,{stop:()=>this.finish(a)})}stopAll(r){let e=this.list;for(let t=0;t<e.length;t++)e[t].target===r&&this.finish(e[t])}get size(){return this.list.length}update(r){if(this.timelines.length){let n=0,i=this.timelines;for(let o=0;o<i.length;o++){let a=i[o];a.update(r),a.finished||(i[n++]=a)}i.length=n}let e=this.list;if(!e.length)return;let t=0;for(let n=0;n<e.length;n++){let i=e[n];i.dead||this.step(i,r),i.dead||(e[t++]=i)}t!==e.length&&(e.length=t)}step(r,e){if(r.target.destroyed)return this.finish(r);let t=e;if(r.delay>0){if(r.delay-=e,r.delay>0)return;t=-r.delay}let n=r.keys;if(!r.started){r.started=!0;for(let a=0;a<n.length;a++)r.from[a]=Number(r.target[n[a]]??0)}r.time+=t;let i=r.duration>0?Math.min(r.time/r.duration,1):1,o=r.ease(i);for(let a=0;a<n.length;a++)r.target[n[a]]=r.from[a]+(r.to[a]-r.from[a])*o;r.onUpdate?.(o),i>=1&&this.finish(r)}finish(r){r.dead||(r.dead=!0,r.done())}clear(){for(let r of this.list)this.finish(r);this.list.length=0;for(let r of this.timelines)r.stop();this.timelines=[]}};var q=720,Bt=class extends oe{constructor(e,t){super(e);h(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},an=class extends oe{constructor(e,t){super(e);h(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},Oe=()=>performance.now();async function ei(s={}){let r=s.play??null,e=s.canvas??null;e||(e=document.createElement("canvas"),e.style.cssText="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(e));let t=lt(e,{renderer:s.renderer??Os(),failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat,instancing:s.instancing});e=t.canvas;let n=new Set,i=new Le(Math.min(2048,t.maxTextureSize),4);i.onPage=y=>n.add(y),i.onDrop=y=>{n.delete(y),y.texture&&t.destroyTexture(y.texture),y.texture=null};let o=Pt(t),a=new pt,l=new dt,u=new Ve(i),c=new Map,f=new Map,d=new Map,b=new Map,g=new Map,p=new Set,m=0,v=s.tier??Qs(),x=String(t.info.renderer??""),S=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),w=typeof screen<"u"?`${screen.width}x${screen.height}`:"",A=js(t.kind,x,w);Vn(S,A,Ks(t.kind,x,w));let E=Ys(S,A),R=Zs(v,rn(t.kind,r?.device),E?.name),C=R?.name??"medium",I=Se(C);u.setTier(C);let H=R?.from==="hint",z=E?.name,G=E?.refresh??nn(r?.device),U=1,ge=1,Me=1,Y={atlas:i,get pixelScale(){return U},get fontGen(){return m},get effects(){return I.effects},tweens:a,frame:y=>qt.frame(y),shape:y=>{let k=I.effects,F=k?U:-U,M=c.get(F);M||(c.size>=8&&c.clear(),c.set(F,M=new st(2e3)));let L=ce(y),$=M.get(y,L);return(!$||!i.valid($.frame))&&M.set(y,$=en(i,zs(y,k),U),L),$},bitmapFont:y=>qt.bitmapFont(y)},le=1280,Ee=null;class ki extends $e{get width(){return le}set width(k){}get height(){return q}set height(k){}get safe(){let k=Math.min(le,q*16/9);return{x:(le-k)/2,y:0,w:k,h:q}}}let ue=new ki(Y),Fe=()=>{let y=t.canvas,k=y.getBoundingClientRect();ge=Math.max(1,k.width||y.clientWidth||innerWidth),Me=Math.max(1,k.height||y.clientHeight||innerHeight),le=q*ge/Me;let F=Math.min(globalThis.devicePixelRatio||1,s.maxPixelRatio??2);if(Me*F/q<=I.resolution){let L=Math.max(1,Math.round(Me*F));U=L/q,t.resize(Math.max(1,Math.round(ge*F)),L)}else U=I.resolution,t.resize(Math.round(le*U),Math.round(q*U));Ee&&Ee.style.setProperty("--unit",`${Me/q}px`)};addEventListener("resize",Fe);let vr=y=>{C=y,I=Se(y),u.setTier(y),Fe()},Gt=typeof ResizeObserver<"u"?new ResizeObserver(Fe):null;Gt?.observe(e);let xe=r?.backdrop==="video"?"video":"none",V=r?.view??null,Rn=[],_n=-1/0,Ut=!1,bt=!1,wr=new Set,Cn=()=>{let y=xe==="video"?"transparent":"";document.documentElement.style.background=y,document.body.style.background=y},Ln=(y,k)=>{let F=y==="video"?"video":"none",M=k??null;if(!(F===xe&&(M===V||M&&V&&M.x===V.x&&M.y===V.y&&M.w===V.w&&M.h===V.h))){xe=F,V=M,Cn();for(let L of[...wr])L(xe,V)}},Pn=[];if(r){let y=M=>{Array.isArray(M)&&(Rn=M,_n=Oe())},k=M=>{Ut=M,Ht()},F=M=>{if(v||H)return;Number.isFinite(G)||(G=nn(M));let L=rn(t.kind,M);L&&(H=!0,vr(z?sn(L,z):L))};Pn.push(r.on("start",M=>F(M?.device)),r.on("frame",M=>y(M?.players)),r.on("players",M=>y(M?.players)),r.on("backdrop",M=>Ln(M?.backdrop,M?.view)),r.on("start",M=>Ln(M?.backdrop,M?.view??r.view)),r.on("pause",()=>k(!0)),r.on("resume",()=>k(!1)),r.on("break-start",()=>k(!0)),r.on("break-done",()=>k(!1)),r.on("break-end",()=>k(!1))),l.muted=r.muted===!0}Cn();let Ht=()=>Ut||bt||document.hidden?l.hold():l.release(),Nn=-1,kr=[],Ar=0,Sr=()=>Oe()-_n<1e3?Rn:[],Ai=y=>r?r.toScreen(y):$n(V,y),zt=()=>{if(Nn===Ar)return kr;Nn=Ar;let y=xe==="video"||!r?.smoothedBody?()=>null:k=>r.smoothedBody(k);return kr=dr(Sr(),Ai,le,q,y),kr},yt={x:0,y:0,w:1,h:1},Si=()=>(yt.x=V?V.x*le:0,yt.y=V?V.y*q:0,yt.w=V?V.w*le:le,yt.h=V?V.h*q:q,yt),Ti=y=>{let k=y.alpha??1,F=y.tags?new Ie(i,y):null;F&&p.add(F);let M=typeof y.tags=="function"?y.tags:L=>String(L);return(L,$)=>{if(xe==="video")return;let N=Si();for(let O of Sr()){let j=r?.smoothedBody?.(O)??O.body,D=Ke(r?.avatarOf?.(O)??O.avatar??"")??Ye;if(!u.draw(L.r,L.tex,j,D,N,k*$,U)||!F)continue;let ie=M(O.id);ie&&F.draw(L.r,L.tex,j,D,N,ie,Nt(O.id),k*$,U,le,q)}}},Tr=new Set,Mr=new Set,gt=new Set,$t=!1,Er=0,qe=0,Vt=0,Be={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0},Wt=0,Fr=0,Rr=Oe(),xt=[],Xt=0,In=()=>({r:t,kernel:Y,tex:o}),On=In(),Mi=()=>{if(t.lost)return;let[y,k]=xe==="video"||s.background===void 0?[0,0]:K(s.background);t.time=Vt,t.maxBlur=I.maxBlur,t.begin(y,k,U),ee(ue.world,null,ue.x,ue.y,ue.rotation,ue.scaleX,ue.scaleY),Hr(On,ue,ue.alpha,ue.tint);let F=t.end();Be.drawCalls=F.drawCalls,Be.quads=F.quads,Be.filtersSkipped=F.filtersSkipped},Bn=y=>{if(!$t)return;Er=requestAnimationFrame(Bn);let k=Math.min(Math.max((y-qe)/1e3,0),.1);qe&&xt.push(y-qe),qe=y,Ar++;let F=Oe(),M=Ut||bt;if(!M){Vt+=k,a.update(k);for(let L of gt)L.destroyed||L.update(k);for(let L of Tr)L(k,Vt)}for(let L of Mr)L(k);ue.sweep();for(let L of gt)L.destroyed&&gt.delete(L);if(t.lost?(Xt||(Xt=y),y-Xt>3e3&&Ei()):(Xt=0,Mi()),Wt++,Fr+=Oe()-F,F-Rr>=1e3&&(Be.fps=Math.round(Wt*1e3/(F-Rr)),Be.cpuMs=Math.round(Fr/Math.max(Wt,1)*100)/100,r?.reportStats?.({fps:Be.fps,renderer:t.kind,tier:C}),Wt=0,Fr=0,Rr=F),xt.length>=180){let L=Number.isFinite(G)?G:Ot(xt);!v&&!M&&Xs(xt,L)&&C!=="low"&&(vr($s(C)),z=C,tn(S,A,C,Number.isFinite(G)?G:void 0),console.info(`[engine] slow frames: tier ${C}`)),xt.length=0}},Ei=()=>{let y=Lt(t.canvas),k=ot(y);if(k){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),t.destroy(),t=k;for(let F of n)F.texture=null;for(let F of i.pages)n.add(F.surface);o=Pt(t),On=In(),Gt?.disconnect(),Gt?.observe(y),Fe()}},Dn=()=>{Ht(),document.hidden||(qe=0)};document.addEventListener("visibilitychange",Dn);let Gn=()=>{m++;for(let y of p)y.drop()};if(document.fonts?.addEventListener?.("loadingdone",Gn),Fe(),!R&&s.probe!==!1&&(Number.isFinite(G)||(G=Ws(await yo(Vs))),!H)){I=Se("high"),Fe();let y=await go(t,i,()=>o,()=>U,le,()=>H);if(y.refresh=G,!H){let k=br(t.kind,y);tn(S,A,k,G),z=k,vr(k)}}let qt={stage:ue,get tier(){return I},get renderer(){return t},get canvas(){return t.canvas},get pixelScale(){return U},get backdrop(){return xe},get view(){return V},get paused(){return Ut||bt},sound:l,stats:Be,get time(){return Vt},get supports(){let y=t.support;return{filters:y.filters,blur:y.filters&&I.maxBlur>0,shaders:y.shaders,maxBlur:y.filters?I.maxBlur:0,tiers:{high:{maxBlur:Se("high").maxBlur},medium:{maxBlur:Se("medium").maxBlur},low:{maxBlur:Se("low").maxBlur}}}},sprite:(y,k)=>new re(Y,y,k),shape:(y,k)=>new fe(Y,y,k),text:(y,k)=>new pe(Y,y,k),group:y=>new $e(Y).set(y??{}),particles(y,k={}){let F=typeof y=="object"&&"type"in y?Y.shape(y).frame:y,M=new et(Y,F,k),{max:L,blend:$,gravity:N,drag:O,...j}=k;return M.set(j),gt.add(M),M},tween:(y,k,F,M)=>a.tween(y,k,F,M),bake(y,k,F,M,L){return d.set(y,{w:k,h:F,draw:M,origin:L}),f.delete(y),qt.frame(y)},frame(y){let k=f.get(y);if(k&&i.valid(k)&&(k.gen===0||k.scale===U))return k;let F=d.get(y);if(F){let M=U,L=i.bake(F.w*M,F.h*M,$=>($.scale(M,M),F.draw($)),M,F.origin?.x??0,F.origin?.y??0);return f.set(y,L),L}if(k)return k;throw new Error(`[engine] no frame "${y}": load it or bake it first`)},async load(y){await Promise.all(Object.entries(y).map(([k,F])=>Ri(k,F)))},hands:y=>y===void 0?zt():zt().filter(k=>k.player===y),touched(y,k,F={}){return y.updateWorld(),mr(y,zt(),k,F.padding??0)},hits(y,k,F,M=0){return y.updateWorld(),It(y,k,F,M)},avatars:(y={})=>new Bt(Y,Ti(y)),handMarkers(y={}){let k=y.radius??36,F=y.look??"auto",M=new Float64Array(6),L=Math.max(k*.12,3),$={type:"ring",r:k,lw:L,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},N={type:"ring",r:k,lw:L*1.8,stroke:We,shadow:{color:We,blur:k*.2}},O=(De,J,je,_r,jt,Ge)=>{let Kt=J.w/J.scale;ee(M,null,je-Kt/2,_r-Kt/2,0,1,1),De.r.quad(De.tex(J.surface),J,M,Kt,Kt,jt,Ge,"normal")},j=De=>{let J=null,je=!1;return()=>(J&&i.valid(J.frame)&&J.frame.scale===U&&je===I.effects?J:(je=I.effects,J=Y.shape(De))).frame},D=j($),ie=j(N);return new an(Y,(De,J)=>{let je=F==="video"||F==="auto"&&xe==="video",_r=D(),jt=je?ie():null;for(let Ge of zt())jt&&O(De,jt,Ge.x,Ge.y,16777215,J),O(De,_r,Ge.x,Ge.y,K(Ge.color)[0],J)})},timeline:y=>a.timeline(y),animation(y,k){let F=typeof y=="string"?Fi(y):{frames:y},M=new ae(Y,F,k);return gt.add(M),M},bitmapFont(y,k){if(!k){let M=b.get(y);if(!M)throw new Error(`[engine] no bitmap font "${y}": load or make it first`);return M}let F="data"in k?Un(ft(k.data),k.pages):Hs(Y,k);return b.set(y,F),F},players:()=>Sr(),onFrame(y){return Tr.add(y),()=>{Tr.delete(y)}},onRender(y){return Mr.add(y),()=>{Mr.delete(y)}},onBackdrop(y){return wr.add(y),()=>{wr.delete(y)}},get hud(){return Ee||(Ee=document.createElement("div"),Ee.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(Ee),Fe()),Ee},random:(y=0,k=1)=>y+Math.random()*(k-y),start(){$t||($t=!0,qe=0,Er=requestAnimationFrame(Bn))},pause(){bt=!0,Ht()},resume(){bt=!1,Ht()},destroy(){$t=!1,cancelAnimationFrame(Er),Pn.forEach(y=>y()),removeEventListener("resize",Fe),Gt?.disconnect(),document.removeEventListener("visibilitychange",Dn),document.fonts?.removeEventListener?.("loadingdone",Gn),a.clear(),cs(Y),l.destroy(),t.destroy(),Ee?.remove()}};function Fi(y){let k=g.get(y);if(k)return k;let F=[...new Set([...f.keys(),...d.keys()])].filter(M=>M.startsWith(y)).sort(fs);if(!F.length)throw new Error(`[engine] no animation or frames "${y}\u2026"`);return{frames:F}}async function Ri(y,k){let F=k.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(F))return l.load(y,k);if(["woff","woff2","ttf","otf"].includes(F)){let N=new FontFace(y,`url(${k})`);document.fonts.add(await N.load()),m++;return}let M=new URL(k,location.href);if(F==="fnt")return Hn(y,ft(await(await fetch(k)).text()),M);if(F==="json"){let N=await(await fetch(k)).json();if(Array.isArray(N.chars)&&!N.frames)return Hn(y,ft(N),M);let O=await on(new URL(N.meta?.image??k.replace(/\.json$/,".png"),M).href);_i(y,N,tt(O));return}let L=await on(k),$=tt(L);n.add($),f.set(y,{surface:$,x:0,y:0,w:L.width,h:L.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function Un(y,k){return Us(y,k.map(F=>{let M=tt(F);return n.add(M),M}))}async function Hn(y,k,F){b.set(y,Un(k,await Promise.all(k.pages.map(M=>on(new URL(M,F).href)))))}function _i(y,k,F){n.add(F);let M=Array.isArray(k.frames)?k.frames:Object.entries(k.frames).map(([N,O])=>({...O,filename:N})),L=[],$=[];for(let N of M){let O=N.frame,j=N.filename.replace(Js,"");N.rotated&&console.warn(`[engine] ${y}/${j} is rotated: export without rotation`);let D={surface:F,x:O.x,y:O.y,w:O.w,h:O.h,scale:1,gen:0,ox:0,oy:0,margin:0};N.trimmed&&N.sourceSize&&N.spriteSourceSize&&(D.sw=N.sourceSize.w,D.sh=N.sourceSize.h,D.tx=N.spriteSourceSize.x,D.ty=N.spriteSourceSize.y);let ie=N.scale9Borders;ie&&(D.slice=[ie.y,(D.sw??O.w)-ie.x-ie.w,(D.sh??O.h)-ie.y-ie.h,ie.x]),f.set(`${y}/${j}`,D),L.push(`${y}/${j}`),$.push((N.duration??0)/1e3)}for(let[N,O]of Object.entries(k.animations??{}))g.set(`${y}/${N}`,{frames:O.map(j=>`${y}/${j.replace(Js,"")}`)});for(let N of k.meta?.frameTags??[]){let O=[];for(let D=N.from;D<=N.to;D++)O.push(D);N.direction==="reverse"&&O.reverse(),N.direction==="pingpong"&&O.push(...O.slice(1,-1).reverse());let j=O.every(D=>$[D]>0);g.set(`${y}/${N.name}`,{frames:O.map(D=>L[D]),...j?{durations:O.map(D=>$[D])}:{}})}}return qt}var Js=/\.(png|webp|jpe?g|gif|bmp)$/i;function on(s){return new Promise((r,e)=>{let t=new Image;t.onload=()=>r(t),t.onerror=()=>e(new Error(`[engine] image did not load: ${s}`)),t.src=s})}function yo(s){return new Promise(r=>{let e=[],t=0,n=i=>{t&&e.push(i-t),t=i,e.length<s?requestAnimationFrame(n):r(e)};requestAnimationFrame(n)})}async function go(s,r,e,t,n,i=()=>!1){let o=t(),a=en(r,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},o).frame,l=[],u=[],c=new Float64Array(6),f=.004,d=s.kind==="canvas2d"?s.canvas.getContext("2d"):null,b=Oe(),g=0;return await new Promise(p=>{let m=v=>{g&&v-b>250&&l.push(v-g),g=v;let x=Oe();s.begin(0,0,o);let S=e();for(let w=0;w<300;w++){let A=v/1e3+w;ee(c,null,w*37%n,w*53%q,A,1,1),s.quad(S(a.surface),a,c,a.w/o,a.h/o,16777215,f,"normal")}for(let w=0;w<40;w++)s.ellipse(100+w*20,300,20,14,w,16746496,f),s.stroke([100+w*20,400,120+w*20,460,100+w*20,520],3,18,3368703,f,!1);s.end(),d?.getImageData(0,0,1,1),v-b>250&&u.push(Oe()-x),v-b<750&&!i()?requestAnimationFrame(m):(s.begin(0,0,o),s.end(),p())};requestAnimationFrame(m)}),{intervals:l,cpu:u}}var xo=64,ti=32,vo=0,wo=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,ri=new Set,ni=(s,r)=>{ri.has(s)||(ri.add(s),console.warn(r))},si=s=>new ln(s),ln=class{constructor(r){h(this,"r",r);h(this,"css","none");h(this,"plans",new st(xo));h(this,"buf",new Float64Array(64));h(this,"keys",[]);h(this,"classes",new Map);h(this,"live",new Set);h(this,"svgs",new Map);h(this,"t",0);h(this,"cur",null);h(this,"svgFn",r=>this.svg(r));h(this,"scr",[]);h(this,"flip",0)}chain(r,e){var g;let t=this.r,n=this.buf;n[0]=t.scale,n[1]=t.maxBlur;let i=2;for(let p=0;p<e.length;p++){let m=e[p];if(i+22>n.length){let x=new Float64Array(n.length*2);x.set(n),n=this.buf=x}let v=this.classes.get(m.constructor);v===void 0&&this.classes.set(m.constructor,v=this.classes.size),n[i++]=v,n[i++]=m.enabled?1:0,m.params&&(i=m.params(n,i))}let o=(g=this.keys)[i]??(g[i]=new Float64Array(i));for(let p=0;p<i;p++)o[p]=n[p];let a=ce(o),l=this.plans.get(o,a);l||this.plans.set(o,l=this.plan(e),a);for(let p=0;p<l.svgs.length;p++){let m=l.svgs[p];m.used<0&&this.attach(m),m.used=this.t}t.skipped+=l.skip;let u=r,c=t.rx0,f=t.ry0,d=t.rx1-c,b=t.ry1-f;for(let p=0;p<l.paints.length;p++)l.parts[p]&&(u=this.bake(u,l.parts[p])),e[l.paints[p]].paint2d(u.getContext("2d"),c,f,d,b);return this.css=l.parts[l.paints.length]||"none",u}tick(){let r=++this.t;if(!(r%ti||!this.live.size))for(let e of this.live)r-e.used>ti&&this.detach(e)}destroy(){for(let r of this.live)this.detach(r);this.plans.clear()}svg(r){if(typeof document>"u"||!document.body)return null;let e=Array.from({length:20},(n,i)=>r[i]??0).join(" "),t=this.svgs.get(e);if(!t){let n="http://www.w3.org/2000/svg",i=document.createElementNS(n,"svg");i.setAttribute("width","0"),i.setAttribute("height","0"),i.setAttribute("aria-hidden","true"),i.style.position="absolute";let o=document.createElementNS(n,"filter"),a=wo+ ++vo;o.setAttribute("id",a),o.setAttribute("color-interpolation-filters","sRGB");let l=document.createElementNS(n,"feColorMatrix");l.setAttribute("type","matrix"),l.setAttribute("values",e),o.append(l),i.append(o),this.attach(t={key:e,id:a,el:i,used:this.t})}return this.cur.svgs.push(t),`url(#${t.id})`}attach(r){document.body.append(r.el),this.live.add(r),this.svgs.has(r.key)||this.svgs.set(r.key,r)}detach(r){r.el.remove(),r.used=-1,this.live.delete(r),this.svgs.get(r.key)===r&&this.svgs.delete(r.key)}plan(r){let e=this.r,t=this.cur={parts:[],paints:[],skip:0,svgs:[]},n="";for(let i=0;i<r.length;i++){let o=r[i];if(!o.enabled)continue;if(o.kind===4){t.skip++,ni("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}let a=e.support.filters&&o.css?o.css(e.scale,e.maxBlur,this.svgFn):null;a!==null?n+=n?` ${a}`:a:o.paint2d?(t.parts.push(n),t.paints.push(i),n=""):(t.skip++,ni("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return t.parts.push(n),t}bake(r,e){let t=this.r,n=this.flip^=1,i=this.scr[n];(!i||i.width!==t.canvas.width||i.height!==t.canvas.height)&&(i=this.scr[n]=document.createElement("canvas"),i.width=t.canvas.width,i.height=t.canvas.height);let o=i.getContext("2d"),a=t.rx0,l=t.ry0,u=t.rx1-a,c=t.ry1-l;return o.clearRect(a,l,u,c),o.filter=e,o.drawImage(r,a,l,u,c,a,l,u,c),o.filter="none",i}};var ko=64,yr=17,Ao=s=>`${ur}
48
+ }`,no={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},so=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],io=["aPos","aUv","aColor","aSlot"];function Is(s,r,e={}){let t={...no,failIfMajorPerformanceCaveat:e.failIfMajorPerformanceCaveat!==!1},n=r===2?s.getContext("webgl2",t):s.getContext("webgl",t)??s.getContext("experimental-webgl",t);if(!n||n.isContextLost())return null;try{return new jr(s,n,r,e)}catch(i){return console.warn("[engine] WebGL setup failed:",i),n.getExtension("WEBGL_lose_context")?.loseContext(),null}}var jr=class extends it{constructor(e,t,n,i){super();h(this,"canvas",e);h(this,"gl",t);h(this,"opts",i);h(this,"kind");h(this,"maxTextureSize");h(this,"support",{filters:!0,shaders:!0});h(this,"features",{});h(this,"info",{});h(this,"lost",!1);h(this,"main");h(this,"cur");h(this,"unit",-1);h(this,"onUnit",new Array(Ps).fill(void 0));h(this,"fbNow");h(this,"mapped",!0);h(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0});h(this,"vsrc","");h(this,"attrs",[]);h(this,"fxr",null);h(this,"batch");h(this,"dynamic");h(this,"staticBuf",null);h(this,"index");h(this,"vao",null);h(this,"inst",null);h(this,"vaoApi",null);h(this,"uScale",null);h(this,"textures",new Map);h(this,"kit");h(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0});h(this,"lostListeners",[]);h(this,"restoredListeners",[]);h(this,"tris",new Int32Array(192));h(this,"sU",0);h(this,"sV0",0);h(this,"sV1",0);h(this,"sColor",0);h(this,"sPacked",0);h(this,"sAlpha",0);h(this,"sHw",0);h(this,"strokeSeg",()=>{let e=this.q;e.set(Ct),e[8]=e[10]=this.sU,e[9]=this.sV0,e[11]=this.sV1,e[12]=this.sPacked,this.put(this.kit)});h(this,"strokeDisc",()=>this.ellipse(Ct[0],Ct[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha));h(this,"q",new Float64Array(13));h(this,"layers",[]);h(this,"layerTex",new Map);h(this,"bScis",!1);h(this,"bx0",0);h(this,"by0",0);h(this,"bx1",0);h(this,"by1",0);h(this,"onContextLost",e=>{e.preventDefault(),this.lost=!0;for(let t of this.lostListeners)t()});h(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(let e of this.textures.keys())this.textures.set(e,this.upload(e.source));this.lost=!1;for(let e of this.restoredListeners)e()}catch(e){console.warn("[engine] WebGL restore failed:",e)}});h(this,"views",new Map);this.kind=n===2?"webgl2":"webgl1",this.maxTextureSize=t.getParameter(t.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(Ls()),te.live=this,e.addEventListener("webglcontextlost",this.onContextLost,!1),e.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){let e=this.gl,t=this.kind==="webgl2"?e:null;if(this.inst=null,this.opts.instancing!==!1)if(t)this.inst={divisor:(f,p)=>t.vertexAttribDivisor(f,p),draw:(f,p)=>t.drawElementsInstanced(e.TRIANGLES,f,e.UNSIGNED_SHORT,0,p)};else{let f=e.getExtension("ANGLE_instanced_arrays");f&&(this.inst={divisor:(p,b)=>f.vertexAttribDivisorANGLE(p,b),draw:(p,b)=>f.drawElementsInstancedANGLE(e.TRIANGLES,p,e.UNSIGNED_SHORT,0,b)})}if(this.vaoApi=null,this.opts.vao!==!1)if(t)this.vaoApi={create:()=>t.createVertexArray(),bind:f=>t.bindVertexArray(f),remove:f=>t.deleteVertexArray(f)};else{let f=e.getExtension("OES_vertex_array_object");f&&(this.vaoApi={create:()=>f.createVertexArrayOES(),bind:p=>f.bindVertexArrayOES(p),remove:p=>f.deleteVertexArrayOES(p)})}let n=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),i=Math.max(1,Math.min(Ps,n)),o=this.inst!==null;this.vsrc=o?ro:to,this.attrs=o?so:io,this.main=this.cur=this.build(eo(i));let a=this.main.p;e.useProgram(a),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,e.uniform1iv(e.getUniformLocation(a,"uTex"),Int32Array.from({length:i},(f,p)=>p)),this.batch=new Jt(o,i),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic),e.bufferData(e.ARRAY_BUFFER,this.batch.f32.byteLength,e.DYNAMIC_DRAW),this.index=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.index),e.bufferData(e.ELEMENT_ARRAY_BUFFER,gs(o?1:8192),e.STATIC_DRAW);let l=f=>e.getAttribLocation(a,f),u=(f,p,b,g,m,d,v)=>{let x=l(f);x<0||(e.enableVertexAttribArray(x),e.vertexAttribPointer(x,p,b,g,m,d),this.inst&&this.inst.divisor(x,v))};if(o){let f=56;u("aP01",4,e.FLOAT,!1,f,0,1),u("aP23",4,e.FLOAT,!1,f,16,1),u("aUvRect",4,e.FLOAT,!1,f,32,1),u("aColor",4,e.UNSIGNED_BYTE,!0,f,48,1),u("aSlot",1,e.FLOAT,!1,f,52,1),this.staticBuf=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.staticBuf),e.bufferData(e.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),e.STATIC_DRAW),u("aCorner",4,e.FLOAT,!1,16,0,0),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic)}else{let f=24;u("aPos",2,e.FLOAT,!1,f,0,0),u("aUv",2,e.FLOAT,!1,f,8,0),u("aColor",4,e.UNSIGNED_BYTE,!0,f,16,0),u("aSlot",1,e.FLOAT,!1,f,20,0)}e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),e.disable(e.DEPTH_TEST),e.disable(e.CULL_FACE),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);let c=e.getExtension("WEBGL_debug_renderer_info");this.info={version:e.getParameter(e.VERSION),renderer:c?e.getParameter(c.UNMASKED_RENDERER_WEBGL):e.getParameter(e.RENDERER),vendor:c?e.getParameter(c.UNMASKED_VENDOR_WEBGL):e.getParameter(e.VENDOR)},this.features={instancing:o,vao:this.vaoApi!==null,textureSlots:i,maxTextureSize:this.maxTextureSize}}upload(e){let t=this.gl,n=t.createTexture();return this.bindTex(n),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),n}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){let t={id:Tt(),width:e.width,height:e.height,source:e};return this.textures.set(t,this.lost?null:this.upload(e)),t}updateTexture(e,t,n=0,i=0){if(this.lost)return;this.batch.has(e)&&this.flush();let o=this.gl,a=this.textures.get(e);a&&(this.bindTex(a),!t||t===e.source&&n===0&&i===0?o.texImage2D(o.TEXTURE_2D,0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,e.source):o.texSubImage2D(o.TEXTURE_2D,0,n,i,o.RGBA,o.UNSIGNED_BYTE,t))}destroyTexture(e){this.batch.has(e)&&this.flush();let t=this.textures.get(e);t&&!this.lost&&this.deleteTex(t),this.textures.delete(e)}begin(e,t,n){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(n),this.bScis=!1,this.lost)return;let i=this.gl;i.disable(i.SCISSOR_TEST),this.bindFb(null),i.viewport(0,0,this.canvas.width,this.canvas.height);let o=t;i.clearColor((e>>16&255)/255*o,(e>>8&255)/255*o,(e&255)/255*o,o),i.clear(i.COLOR_BUFFER_BIT),this.use(this.main),i.uniform2f(this.uScale,2*n/this.canvas.width,-2*n/this.canvas.height),this.mapped=!0}build(e){let t=this.gl,n=Ns(t,t.VERTEX_SHADER,this.vsrc),i;try{i=Ns(t,t.FRAGMENT_SHADER,e)}catch(a){throw t.deleteShader(n),a}let o=t.createProgram();if(t.attachShader(o,n),t.attachShader(o,i),this.attrs.forEach((a,l)=>t.bindAttribLocation(o,l,a)),t.linkProgram(o),t.deleteShader(n),t.deleteShader(i),!t.getProgramParameter(o,t.LINK_STATUS)){let a=t.getProgramInfoLog(o)??"?";throw t.deleteProgram(o),new Error(`link: ${a}`)}return{p:o,uScale:t.getUniformLocation(o,"uScale"),locs:new Map}}u(e,t){let n=e.locs.get(t);return n===void 0&&e.locs.set(t,n=this.gl.getUniformLocation(e.p,t)),n}use(e){this.cur!==e&&(this.cur=e,this.gl.useProgram(e.p),this.calls.useProgram++)}bindTex(e,t=this.unit<0?0:this.unit){let n=this.gl;this.onUnit[t]!==e&&(this.unit!==t&&(n.activeTexture(n.TEXTURE0+t),this.calls.activeTexture++,this.unit=t),n.bindTexture(n.TEXTURE_2D,e),this.calls.bindTexture++,this.onUnit[t]=e)}deleteTex(e){this.gl.deleteTexture(e);for(let t=0;t<this.onUnit.length;t++)this.onUnit[t]===e&&(this.onUnit[t]=null)}bindFb(e){if(e)for(let n=0;n<this.onUnit.length;n++)this.onUnit[n]===e.gl&&this.bindTex(null,n);let t=e?e.fb:null;this.fbNow!==t&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,t),this.calls.bindFramebuffer++,this.fbNow=t)}slotOf(e){this.batch.full&&this.flush();let t=this.batch.slot(e);return t<0&&(this.flush(),t=this.batch.slot(e)),t}quad(e,t,n,i,o,a,l,u){B[0]=i,B[1]=o,B[2]=l,this.quadQ(e,t,n,a,u)}quadQ(e,t,n,i,o){let a=B[2];if(this.lost||a<=0)return;let l=this.q,u=B[0],c=B[1],f=n[4],p=n[5],b=n[0]*u,g=n[1]*u,m=n[2]*c,d=n[3]*c;l[0]=f,l[1]=p,l[2]=b+f,l[3]=g+p,l[4]=b+m+f,l[5]=g+d+p,l[6]=m+f,l[7]=d+p;let v=1/e.width,x=1/e.height;l[8]=t.x*v,l[9]=t.y*x,l[10]=(t.x+t.w)*v,l[11]=(t.y+t.h)*x,l[12]=Re(i,a,o==="add"),this.put(e)}put(e){if(this.mute)return;let t=this.q,n=!1,i=Math.min(t[0],t[2],t[4],t[6]),o=Math.max(t[0],t[2],t[4],t[6]),a=Math.min(t[1],t[3],t[5],t[7]),l=Math.max(t[1],t[3],t[5],t[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;let c=this.scale,f=this.px0/c,p=this.py0/c,b=this.px1/c,g=this.py1/c;if(o<=f||i>=b||l<=p||a>=g)return;if(i<f||o>b||a<p||l>g){let m=t[0],d=t[1],v=t[2],x=t[5];if(d===t[3]&&v===t[4]&&x===t[7]&&t[6]===m){if(m!==v){let S=Math.min(Math.max(m,f),b),w=Math.min(Math.max(v,f),b),A=t[8],E=(t[10]-A)/(v-m);t[10]=A+(w-m)*E,t[8]=A+(S-m)*E,t[0]=t[6]=S,t[2]=t[4]=w}if(d!==x){let S=Math.min(Math.max(d,p),g),w=Math.min(Math.max(x,p),g),A=t[9],E=(t[11]-A)/(x-d);t[11]=A+(w-d)*E,t[9]=A+(S-d)*E,t[1]=t[3]=S,t[5]=t[7]=w}}else n=!0}}let u=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(n?(!this.bScis||!u)&&(this.flush(),this.bScis=!0,this.bx0=this.px0,this.by0=this.py0,this.bx1=this.px1,this.by1=this.py1):this.bScis&&!(this.cOn&&u)&&(this.flush(),this.bScis=!1),this.real){let c=this.gq;c[0]=i,c[1]=a,c[2]=o,c[3]=l,this.growQ()}this.batch.pushQ(t,this.slotOf(e))}ellipse(e,t,n,i,o,a,l){if(this.lost||l<=0||n<=0||i<=0)return;let u=ar[Xr(Math.max(n,i)*2*this.scale,_s)],c=u.w/2/u.r,f=n*c,p=i*c,b=Math.cos(o),g=Math.sin(o),m=b*f,d=g*f,v=-g*p,x=b*p,S=1/256,w=this.q;w[0]=e-m-v,w[1]=t-d-x,w[2]=e+m-v,w[3]=t+d-x,w[4]=e+m+v,w[5]=t+d+x,w[6]=e-m+v,w[7]=t-d+x,w[8]=u.x*S,w[9]=u.y*S,w[10]=(u.x+u.w)*S,w[11]=(u.y+u.h)*S,w[12]=Re(a,l),this.put(this.kit)}polygon(e,t,n,i){if(this.lost||i<=0||t<3)return;this.tris.length<t*3&&(this.tris=new Int32Array(Math.max(t*3,this.tris.length*2)));let o=this.tris,a=Es(e,t,o),l=Re(n,i),u=(Ae.x+Ae.w/2)/256,c=(Ae.y+Ae.h/2)/256;for(let f=0;f<a;f+=3){let p=o[f]*2,b=o[f+1]*2,g=o[f+2]*2,m=this.q;m[0]=e[p],m[1]=e[p+1],m[2]=e[b],m[3]=e[b+1],m[4]=m[6]=e[g],m[5]=m[7]=e[g+1],m[8]=m[10]=u,m[9]=m[11]=c,m[12]=l,this.put(this.kit)}}stroke(e,t,n,i,o,a){if(this.lost||o<=0||n<=0||t<1)return;let l=lr[Xr(n*this.scale,Cs)],u=n/2*(l.h/2/l.r);this.sPacked=Re(i,o),this.sColor=i,this.sAlpha=o,this.sU=(l.x+l.w/2)/256,this.sV0=l.y/256,this.sV1=(l.y+l.h)/256,this.sHw=n/2,Fs(e,t,u,a,this.strokeSeg,this.strokeDisc)}target(e,t,n,i){let o=this.gl,a=o.createTexture();this.bindTex(a),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,e,t,0,o.RGBA,o.UNSIGNED_BYTE,null);let l=i?o.LINEAR:o.NEAREST;o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,l),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,l),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),this.bindTex(null);let u=o.createFramebuffer();o.bindFramebuffer(o.FRAMEBUFFER,u),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,a,0);let c=o.checkFramebufferStatus(o.FRAMEBUFFER)===o.FRAMEBUFFER_COMPLETE;if(this.fbNow=u,this.bindFb(this.parent()),!c)return this.deleteTex(a),o.deleteFramebuffer(u),null;let f={tex:{id:Tt(),width:e,height:t,source:this.canvas},gl:a,fb:u,w:e,h:t,f:n};return this.layerTex.set(f.tex,a),f}drop(e){this.batch.has(e.tex)&&this.flush(),this.deleteTex(e.gl),this.gl.deleteFramebuffer(e.fb),this.layerTex.delete(e.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(e){let t=this.canvas.width,n=this.canvas.height,i=this.layers[e]??null;return i&&(i.w!==t||i.h!==n)&&(this.drop(i),i=this.layers[e]=null),i??(this.layers[e]=this.target(t,n,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();let e=this.layerAt(this.real);if(!e)return!1;let t=this.gl;return this.bindFb(e),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!te.gl?null:this.fxr??(this.fxr=te.gl(this))}composite(e,t,n,i){if(i&&this.filters()?.chain(e,n,i))return;let o=this.gl;t&&o.blendFunc(o.ZERO,o.SRC_ALPHA),this.final(this.main,e,1,n),t&&(this.flush(),o.blendFunc(o.ONE,o.ONE_MINUS_SRC_ALPHA))}final(e,t,n,i){let o=this.gl,a=this.canvas.width,l=this.canvas.height,u=this.scale;(e!==this.main||!this.mapped)&&(this.bindFb(this.parent()),o.viewport(0,0,a,l),this.use(e),o.uniform2f(e.uScale,2*u/a,-2*u/l),this.mapped=e===this.main);let c=this.rx0/u,f=this.ry0/u,p=this.rx1/u,b=this.ry1/u,g=1/(n*t.width),m=1/(n*t.height),d=this.q;d[0]=d[6]=c,d[1]=d[3]=f,d[2]=d[4]=p,d[5]=d[7]=b,d[8]=this.rx0*g,d[9]=1-this.ry0*m,d[10]=this.rx1*g,d[11]=1-this.ry1*m,d[12]=Re(16777215,i),this.put(t),e!==this.main&&this.flush()}remap(){let e=this.gl;this.bindFb(this.parent()),e.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),e.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(e){let t=this.gl,n=e.words;if(this.kind==="webgl2")return t.bufferSubData(t.ARRAY_BUFFER,0,e.f32,0,n);let i=this.views.get(n);i||(this.views.size>=256&&this.views.clear(),this.views.set(n,i=e.f32.subarray(0,n))),t.bufferSubData(t.ARRAY_BUFFER,0,i)}flush(){let e=this.batch;if(!e.quads||this.lost)return e.reset();let t=this.gl;this.bScis?(t.enable(t.SCISSOR_TEST),t.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):t.disable(t.SCISSOR_TEST),this.upload2(e);for(let n=0;n<e.bound;n++){let i=e.textures[n];this.bindTex(this.textures.get(i)??this.layerTex.get(i)??null,n)}this.inst?this.inst.draw(6,e.quads):t.drawElements(t.TRIANGLES,e.quads*6,t.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=e.quads,e.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){let e=this.gl;te.live===this&&(te.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(let t of this.textures.values())t&&e.deleteTexture(t);for(let t of this.layers)t&&(e.deleteTexture(t.gl),e.deleteFramebuffer(t.fb));this.fxr?.destroy(),this.fxr=null,e.deleteBuffer(this.dynamic),e.deleteBuffer(this.index),this.staticBuf&&e.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),e.deleteProgram(this.main.p),e.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function Ns(s,r,e){let t=s.createShader(r);if(s.shaderSource(t,e),s.compileShader(t),!s.getShaderParameter(t,s.COMPILE_STATUS)){let n=s.getShaderInfoLog(t)??"?";throw s.deleteShader(t),new Error(n)}return t}function qr(s="auto"){switch(s){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function lt(s,r={}){let e=s;for(let t of qr(r.renderer)){let n=t==="canvas2d"?ot(e):Is(e,t==="webgl2"?2:1,r);if(n)return n;e=Lt(e)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function Lt(s){let r=s.cloneNode(!1);return s.parentNode?.replaceChild(r,s),r}function Os(s=typeof location<"u"?location.search:""){let r=new URLSearchParams(s).get("renderer");return r==="canvas"?"canvas2d":r==="webgl2"||r==="webgl1"||r==="canvas2d"||r==="webgl"||r==="auto"?r:void 0}var Ie=class{constructor(r,e={}){h(this,"atlas",r);h(this,"tags",new Map);h(this,"count",0);h(this,"m",ve());h(this,"measure",null);h(this,"height");h(this,"font");this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(let r of this.tags.values())for(let e of r.values())for(let t of e.values())this.atlas.release(t);this.tags.clear(),this.count=0}get(r,e,t){let n=this.tags.get(r);n||this.tags.set(r,n=new Map);let i=n.get(e);i||n.set(e,i=new Map);let o=i.get(t);return o&&this.atlas.valid(o)?o:this.bake(r,e,t)}bake(r,e,t){let n=this.height,i=`700 ${Math.round(n*.65)}px ${this.font}`,o=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));o.font=i;let a=Math.round(n*.4),l=Math.ceil(o.measureText(r).width)+a*2,u=this.atlas.bake((l+2)*t,(n+2)*t,p=>{p.scale(t,t),p.translate(1,1);let b=n/2;p.beginPath(),p.moveTo(b,0),p.lineTo(l-b,0),p.arc(l-b,b,b,-Math.PI/2,Math.PI/2),p.lineTo(b,n),p.arc(b,b,b,Math.PI/2,Math.PI*3/2),p.closePath(),p.fillStyle=e,p.fill(),p.fillStyle="#fff",p.font=i,p.textAlign="center",p.textBaseline="middle",p.fillText(r,l/2,n/2+1)},t,1,1,1);++this.count>64&&(this.drop(),this.count=1);let c=this.tags.get(r);c||this.tags.set(r,c=new Map);let f=c.get(e);return f||c.set(e,f=new Map),f.set(t,u),u}draw(r,e,t,n,i,o,a,l,u,c,f){let p=jn(t,i,{band:oo(n)});if(!p)return;let b=this.height,g=this.get(o,a,u),m=g.w/g.scale-2,d=Math.min(Math.max(p.head.x-m/2,4),c-m-4),v=Math.min(Math.max(p.head.y-p.headR*2.2-b,4),f-b-4);ee(this.m,null,d-1,v-1,0,1,1),r.quad(e(g.surface),g,this.m,g.w/g.scale,g.h/g.scale,16777215,l,"normal")}},oo=s=>s.band==="3-5"||s.band==="9-12"?s.band:"6-8";var ao=(s,r=!1)=>r?Math.min(2**Math.round(Math.log2(Math.max(s,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(s,8))*2)/2),512);function hr(s,r=null){let e={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},t=(n,i,o)=>{let a=r?r[0]*n+r[2]*i+r[4]:n,l=r?r[1]*n+r[3]*i+r[5]:i,u=r?Math.hypot(r[0],r[1]):1;e.minX=Math.min(e.minX,a-o*u),e.minY=Math.min(e.minY,l-o*u),e.maxX=Math.max(e.maxX,a+o*u),e.maxY=Math.max(e.maxY,l+o*u)};for(let n of s){let i="lw"in n&&n.stroke?(n.lw??1)/2:0;switch(n.k){case"circle":t(n.x-n.r,n.y-n.r,i),t(n.x+n.r,n.y+n.r,i),t(n.x-n.r,n.y+n.r,i),t(n.x+n.r,n.y-n.r,i);break;case"ellipse":case"rect":{let o=n.k==="ellipse"?Math.max(n.rx,n.ry):Math.hypot(n.w,n.h)/2;t(n.x-o,n.y-o,i),t(n.x+o,n.y+o,i),t(n.x-o,n.y+o,i),t(n.x+o,n.y-o,i);break}case"path":{let o=or(n.d);for(let a=0;a<o.count;a++){let l=o.subs[a];for(let u=0;u<l.n;u++)t(l.pts[u*2],l.pts[u*2+1],i)}break}case"line":for(let o=0;o+1<n.pts.length;o+=2)t(n.pts[o],n.pts[o+1],i);break;case"group":{let o=ee(ve(),r,n.x,n.y,n.rot??0,n.s??1,n.s??1),a=hr(n.items,o);Number.isFinite(a.minX)&&(e.minX=Math.min(e.minX,a.minX),e.minY=Math.min(e.minY,a.minY),e.maxX=Math.max(e.maxX,a.maxX),e.maxY=Math.max(e.maxY,a.maxY));break}}}return e}var Ve=class{constructor(r){h(this,"atlas",r);h(this,"seen",new WeakSet);h(this,"baked",new WeakMap);h(this,"m",ve());h(this,"stack",[]);h(this,"local",ve());h(this,"pts",new Float64Array(128));h(this,"stats",{baked:0,vector:0});h(this,"bakeGroups",!0);h(this,"coarse",!1);h(this,"gen",0);h(this,"live",new Set)}setTier(r){let e=r==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(let t of this.live)this.atlas.release(t.frame);this.live.clear()}}draw(r,e,t,n,i,o,a){let l=typeof n=="string"?Ke(n)??Ye:n,u=Xn(t,l,i);return u.length?(o<=0||(o<1?(this.paint(r,e,u,null,r.beginLayer()?1:o,a),r.endLayer(o)):this.paint(r,e,u,null,o,a)),!0):!1}paint(r,e,t,n,i,o,a=0){var l;for(let u=0;u<t.length;u++){let c=t[u];if(c.k==="group"){let x=ee((l=this.stack)[a]??(l[a]=ve()),n,c.x,c.y,c.rot??0,c.s??1,c.s??1),S=i*(c.alpha??1);if(this.bakeGroups&&this.seen.has(c.items)){let w=pe(x[0],x[1])*o,A=this.bake(c.items,w);if(A){let E=A.frame,R=this.m;R.set(x),R[4]=x[0]*-A.ox+x[2]*-A.oy+x[4],R[5]=x[1]*-A.ox+x[3]*-A.oy+x[5],r.quad(e(E.surface),E,R,E.w/A.k,E.h/A.k,16777215,S,"normal"),this.stats.baked++;continue}}this.seen.add(c.items),this.stats.vector++,this.paint(r,e,c.items,x,S,o,a+1);continue}let f=i*(c.alpha??1),p=n?pe(n[0],n[1]):1,b=n?Math.atan2(n[1],n[0]):0,g=(c.lw??1)*p,m=c.stroke&&(c.lw??1)>0?K(c.stroke):null,d=c.fill&&c.k!=="line"?K(c.fill):null;if(c.k==="circle"||c.k==="ellipse"){let x=n?n[0]*c.x+n[2]*c.y+n[4]:c.x,S=n?n[1]*c.x+n[3]*c.y+n[5]:c.y,w=(c.k==="circle"?c.r:c.rx)*p,A=(c.k==="circle"?c.r:c.ry)*p,E=(c.k==="ellipse"?c.rot??0:0)+b;if(d&&m)r.ellipse(x,S,w+g/2,A+g/2,E,m[0],f*m[1]),r.ellipse(x,S,Math.max(w-g/2,0),Math.max(A-g/2,0),E,d[0],f*d[1]);else if(d)r.ellipse(x,S,w,A,E,d[0],f*d[1]);else if(m){let R=Math.min(Math.max(Math.ceil(Math.max(w,A)*o*.6),12),64),C=this.pts=ir(this.pts,R*2),I=Math.cos(E),H=Math.sin(E);for(let z=0;z<R;z++){let G=z/R*Math.PI*2,U=Math.cos(G)*w,ge=Math.sin(G)*A;C[z*2]=x+U*I-ge*H,C[z*2+1]=S+U*H+ge*I}r.stroke(C,R,g,m[0],f*m[1],!0)}continue}if(c.k==="line"){if(!m)continue;let x=c.pts.length>>1,S=this.pts=ir(this.pts,x*2);for(let w=0;w<x;w++){let A=c.pts[w*2],E=c.pts[w*2+1];S[w*2]=n?n[0]*A+n[2]*E+n[4]:A,S[w*2+1]=n?n[1]*A+n[3]*E+n[5]:E}r.stroke(S,x,g,m[0],f*m[1],!1);continue}let v=c.k==="path"?or(c.d,n,p*o):lo(c,ee(this.local,n,c.x,c.y,c.rot??0,1,1),o*p);for(let x=0;x<v.count;x++){let S=v.subs[x],w=S.n,A=c.k==="rect"||S.closed;d&&w>=3&&(r.polygon(S.pts,w,d[0],f*d[1]),m||r.stroke(S.pts,w,1/o,d[0],f*d[1],!0)),m&&r.stroke(S.pts,w,g,m[0],f*m[1],A)}}}bake(r,e){let t=ao(e,this.coarse),n=this.baked.get(r),i=n?.get(t);if(i&&i.gen===this.gen&&this.atlas.valid(i.frame))return i;i&&this.live.delete(i);let o=hr(r);if(!Number.isFinite(o.minX))return null;let a=2/t,l=(o.maxX-o.minX+a*2)*t,u=(o.maxY-o.minY+a*2)*t;if(l>1024||u>1024)return null;let c=-o.minX+a,f=-o.minY+a,b={frame:this.atlas.bake(l,u,g=>{g.scale(t,t),g.translate(c,f),Lr(g,r)}),k:t,ox:c,oy:f,gen:this.gen};return n||this.baked.set(r,n=new Map),n.set(t,b),this.live.add(b),b}},ut=new Array(36).fill(0),ct=0,de=(s,r=NaN,e=NaN,t=NaN,n=NaN)=>{ut[ct++]=s,s!==Z.Z&&(ut[ct++]=r,ut[ct++]=e,s===Z.Q&&(ut[ct++]=t,ut[ct++]=n))};function lo(s,r,e){let t=Math.max(0,Math.min(s.r,s.w/2,s.h/2)),n=-s.w/2,i=-s.h/2,{M:o,L:a,Q:l,Z:u}=Z;return ct=0,de(o,n+t,i),de(a,n+s.w-t,i),de(l,n+s.w,i,n+s.w,i+t),de(a,n+s.w,i+s.h-t),de(l,n+s.w,i+s.h,n+s.w-t,i+s.h),de(a,n+t,i+s.h),de(l,n,i+s.h,n,i+s.h-t),de(a,n,i+t),de(l,n,i,n+t,i),de(u),or(ut,r,e)}function Bs(s,r={}){let e=lt(s,r),t=new Le(Math.min(1024,e.maxTextureSize),2);t.onDrop=A=>{A.texture&&e.destroyTexture(A.texture),A.texture=null};let n=new Ve(t),i=new Rt,o=new Map,a=1e6,l=r.smooth===!1?1:typeof r.smooth=="number"?Math.min(Math.max(r.smooth,.05),1):.5,u=Pt(e),c=new Ie(t,r),f={w:1,h:1},p=1,b=0,g=!1,m=()=>c.drop(),d=typeof document<"u"?document.fonts:void 0;d?.ready?.then(()=>{g||m()}),d?.addEventListener?.("loadingdone",m);let v=()=>{let A=Lt(e.canvas),E=ot(A);if(E){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),e.destroy(),e=E;for(let R of t.pages)R.surface.texture=null;u=Pt(e),b=0}},x=()=>{if(!e.lost)return b=0,!0;let A=performance.now();return b||(b=A),A-b>3e3&&v(),!e.lost},S=()=>{let A=e.canvas;r.units?(p=r.pixelRatio??1,f.w=r.units.width,f.h=r.units.height):(p=r.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),f.w=A.clientWidth||A.width/p,f.h=A.clientHeight||A.height/p),e.resize(Math.max(1,Math.round(f.w*p)),Math.max(1,Math.round(f.h*p))),e.begin(0,0,p)},w=(A,E)=>{if(A.key===void 0)return A.id??E+1;let R=o.get(A.key);return R===void 0&&(o.size>256&&o.clear(),o.set(A.key,R=a++)),R};return{get renderer(){return e},get kind(){return e.kind},get lost(){return e.lost},get canvas(){return e.canvas},draw(A,E){if(x()){S();for(let R=0;R<A.length;R++){let C=A[R];if(!Array.isArray(C.body))continue;let I=w(C,R),H=l<1||r.interpolate!==!1?i.posed(I,C.body,l,r.interpolate!==!1):C.body,z=Ke(C.avatar??"")??Ye,G=C.alpha??1;!n.draw(e,u,H,z,E,G,p)||!C.name||c.draw(e,u,H,z,E,C.name,C.color??"#6FA0E0",G,p,f.w,f.h)}e.end()}},clear(){x()&&(S(),e.end())},reset(){i=new Rt,o.clear()},destroy(){g=!0,d?.removeEventListener?.("loadingdone",m),e.destroy()}}}var cr=new Map;function Ds(s,r,e=Math.min(globalThis.devicePixelRatio||1,2)){let t=`${s}|${r}|${e}`,n=cr.get(t);if(n)return n;n=document.createElement("canvas"),n.width=n.height=Math.round(r*e);let i=n.getContext("2d");return i.scale(e,e),i.beginPath(),i.rect(0,0,r,r),i.clip(),Lr(i,qn(Ke(s)??Ye,r)),cr.size>64&&cr.clear(),cr.set(t,n),n}function Pt(s){return r=>{if(r.texture||(r.texture=s.createTexture(r.source),r.pending.length=0),r.pending.length){for(let[e,t,n]of r.pending)s.updateTexture(r.texture,e,t,n);r.pending.length=0}return r.texture}}var Kr='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',We="rgba(10,16,30,0.75)";function Yr(s,r){let e=s.size??40,t=s.outline?s.outline===!0?We:s.outline:null,n=t?s.outlineWidth??Math.max(e*.12,3):0,i=s.shadow&&r?s.shadow===!0?We:s.shadow:null,o=i?s.shadowBlur??e*.25:0;return{size:e,font:s.font??Kr,weight:s.weight??700,color:s.color??"#FBEFE3",outline:t,ow:n,shadow:i,blur:o,pad:n/2+o*1.2+2,th:e*1.25}}var Gs=(s,r)=>`${s.weight} ${s.size*r}px ${s.font}`;function Qr(s,r,e,t,n,i){s.scale(t,t),s.font=Gs(e,1),s.textBaseline="middle",s.textAlign="left",s.lineJoin="round",e.shadow&&(s.shadowColor=e.shadow,s.shadowBlur=e.blur*t),e.outline&&(s.strokeStyle=e.outline,s.lineWidth=e.ow,s.strokeText(r,n,i),s.shadowColor="transparent"),s.fillStyle=e.color,s.fillText(r,n,i)}var fr=null;function Zr(s,r,e){return fr??(fr=document.createElement("canvas").getContext("2d")),fr.font=Gs(r,e),fr.measureText(s).width/e}var me=class extends re{constructor(e,t,n={}){super(e,null);h(this,"_text");h(this,"_style");h(this,"dirty",!0);h(this,"bakedScale",0);h(this,"bakedFontGen",-1);h(this,"bakedEffects",!0);h(this,"capW",0);h(this,"capH",0);this._text=t;let{x:i,y:o,rotation:a,scale:l,scaleX:u,scaleY:c,alpha:f,visible:p,tint:b,blend:g,z:m,anchor:d,hitRadius:v,clip:x,mask:S,filters:w,...A}=n;this._style=A,this.bake(),this.set({x:i,y:o,rotation:a,scale:l,scaleX:u,scaleY:c,alpha:f,visible:p,tint:b,blend:g,z:m,hitRadius:v,clip:x,mask:S,filters:w}),d!==void 0&&(this.anchor=d)}get text(){return this._text}set text(e){let t=String(e);t!==this._text&&(this._text=t,this.dirty=!0)}get style(){return this._style}set style(e){this._style={...this._style,...e},this.dirty=!0}bitmap(){let e=this._style.bitmapFont;if(!e)return null;let t=typeof e=="string"?this.kernel.bitmapFont(e):e;if(this.autoAnchor){let n=this._style.align;this.anchorX=n==="left"?0:n==="right"?1:.5,this.anchorY=.5}return t}get naturalWidth(){let e=this.bitmap();return e?e.measure(this._text)*((this._style.size??e.size)/e.size):super.naturalWidth}get naturalHeight(){let e=this.bitmap();return e?e.lineHeight*((this._style.size??e.size)/e.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(e,t,n){let i=this.bitmap();if(!i)return super.draw(e,t,n);let o=(this._style.size??i.size)/i.size,a=i.measure(this._text)*o,l=i.lineHeight*o,u=this.width,c=this.height,f=a>0?u/a:1,p=l>0?c/l:1;i.run(this._text,e,this.world,-this.anchorX*u,-this.anchorY*c,o*f,o*p,n,t,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){let e=this.kernel;if(this._style.bitmapFont)return null;let t=e.pixelScale,n=e.effects;return!this.dirty&&t===this.bakedScale&&e.fontGen===this.bakedFontGen&&n===this.bakedEffects&&e.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){let e=this.kernel,t=e.pixelScale,n=e.effects;this.dirty=!1,this.bakedScale=t,this.bakedFontGen=e.fontGen,this.bakedEffects=n;let i=Yr(this._style,n),{pad:o,th:a}=i,l=Zr(this._text,i,t),u=(l+o*2)*t,c=(a+o*2)*t,f=this._style.align??"center",p=f==="left"?o:f==="right"?o+l:o+l/2,b=d=>Qr(d,this._text,i,t,o,o+a/2),g=this._frame,m=null;return g&&e.atlas.valid(g)&&g.scale===t&&(m=e.atlas.rebake(g,u,c,b,this.capW,this.capH),m?Object.assign(m,{ox:p,oy:o+a/2,margin:o}):e.atlas.release(g)),m||(this.capW=Math.ceil(u*1.25+16),this.capH=Math.ceil(c),m=e.atlas.bake(this.capW,this.capH,b,t,p,o+a/2,o),m.w=Math.ceil(u),m.h=Math.ceil(c)),this._frame=m,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,m}};var X=(s,r=0)=>{let e=Number(s);return Number.isFinite(e)?e:r};function ft(s){typeof s=="string"&&/^\s*[{[]/.test(s)&&(s=JSON.parse(s));let r={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},e=(t,n)=>{t==="info"?r.size=Math.abs(X(n.size)):t==="common"?(r.lineHeight=X(n.lineHeight),r.base=X(n.base)):t==="page"?r.pages[X(n.id)]=String(n.file??""):t==="char"?r.chars.push({id:X(n.id),x:X(n.x),y:X(n.y),width:X(n.width),height:X(n.height),xoffset:X(n.xoffset),yoffset:X(n.yoffset),xadvance:X(n.xadvance),page:X(n.page)}):r.kernings.push({first:X(n.first),second:X(n.second),amount:X(n.amount)})};if(typeof s=="object"){let t=s;e("info",t.info??{}),e("common",t.common??{});for(let[n,i]of(t.pages??[]).entries())e("page",{id:n,file:i});for(let n of t.chars??[])e("char",n);for(let n of t.kernings??[])e("kerning",n)}else{let t=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,n=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let i=t.exec(s);i;i=t.exec(s)){let o={};for(let a=n.exec(i[2]);a;a=n.exec(i[2]))o[a[1]]=a[2]??a[3];e(i[1],o)}}return r.size||(r.size=r.lineHeight),r}var ht=class{constructor(r,e,t,n=null,i=null){h(this,"baker",n);h(this,"host",i);h(this,"size");h(this,"lineHeight");h(this,"base");h(this,"ascii",new Array(128));h(this,"more",new Map);h(this,"kern",new Map);h(this,"bScale",0);h(this,"bFontGen",-1);h(this,"bEffects",!1);h(this,"bGen",-1);this.size=r,this.lineHeight=e,this.base=t}set(r,e){r<128?this.ascii[r]=e:this.more.set(r,e)}setKerning(r,e,t){this.kern.set(r*1114112+e,t)}prepare(){let r=this.host;if(!(!r||r.pixelScale===this.bScale&&r.fontGen===this.bFontGen&&r.effects===this.bEffects&&r.atlas.gen===this.bGen)){this.bScale=r.pixelScale,this.bFontGen=r.fontGen,this.bEffects=r.effects,this.bGen=r.atlas.gen;for(let e of this.ascii)e&&r.atlas.release(e.frame);for(let e of this.more.values())e&&r.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(r){let e=r<128?this.ascii[r]:this.more.get(r);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(r):null,this.set(r,e)),e}kerning(r,e){return this.kern.size?this.kern.get(r*1114112+e)??0:0}measure(r){return this.run(r)}run(r,e,t,n=0,i=0,o=1,a=1,l=0,u=1,c="normal"){this.prepare();let f=0,p=-1;for(let b=0;b<r.length;b++){let g=r.charCodeAt(b);g>=55296&&g<56320&&b+1<r.length&&(g=r.codePointAt(b),b++),p>=0&&(f+=this.kerning(p,g)),p=g;let m=this.glyph(g);m&&(e&&m.w>0&&m.h>0&&(Et(t,n+(f+m.x)*o,i+m.y*a),e.r.quad(e.tex(m.frame.surface),m.frame,W,m.w*o,m.h*a,l,u,c)),f+=m.advance)}return f}};function Us(s,r){let e=new ht(s.size,s.lineHeight,s.base);for(let t of s.chars){let n=r[t.page];if(!n)continue;let i={surface:n,x:t.x,y:t.y,w:t.width,h:t.height,scale:1,gen:0,ox:0,oy:0,margin:0};e.set(t.id,{frame:i,x:t.xoffset,y:t.yoffset,w:t.width,h:t.height,advance:t.xadvance})}for(let t of s.kernings)e.setKerning(t.first,t.second,t.amount);return e}function Hs(s,r){let e={...r},t=r.size??40,n=o=>{let a=String.fromCodePoint(o),l=s.pixelScale,u=Yr(e,s.effects),c=Zr(a,u,l),f=s.atlas.bake((c+u.pad*2)*l,(u.th+u.pad*2)*l,p=>Qr(p,a,u,l,u.pad,u.pad+u.th/2),l);return{frame:f,x:-u.pad,y:-u.pad,w:f.w/l,h:f.h/l,advance:c}},i=new ht(t,t*1.25,t,n,s);i.prepare();for(let o of r.chars??"0123456789")i.glyph(o.codePointAt(0));return i}var uo=.5;function Jr(s){let r=[];for(let[e,t]of[["left",Cr.leftWrist],["right",Cr.rightWrist]]){let n=s[t*3],i=s[t*3+1],o=s[t*3+2];n!==void 0&&i!==void 0&&Number.isFinite(n)&&Number.isFinite(i)&&(o??0)>=uo&&r.push({side:e,x:n,y:i})}return r}var Nt=s=>vt[((s-1)%vt.length+vt.length)%vt.length];function pr(s,r,e,t,n=()=>null){let i=[];for(let o of s){let a=n(o)??o.body;if(Array.isArray(a))for(let l of Jr(a)){let u=r(l);i.push({player:o.id,side:l.side,x:u.x*e,y:u.y*t,color:Nt(o.id)})}}return i}function It(s,r,e,t=0){let n=s.world,i=Yn(n,r,e);if(!i)return!1;let o=Math.hypot(n[0],n[1])||1,a=Math.hypot(n[2],n[3])||1,[l,u]=i;if(s.hitRadius!=null){let g=s.hitRadius+t/((o+a)/2);return l*l+u*u<=g*g}let c=-s.anchorX*s.width-t/o,f=-s.anchorY*s.height-t/a,p=(1-s.anchorX)*s.width+t/o,b=(1-s.anchorY)*s.height+t/a;return l>=c&&l<=p&&u>=f&&u<=b}function dr(s,r,e,t=0){for(let n of r)if((e===void 0||n.player===e)&&It(s,n.x,n.y,t))return n;return null}function co(s){switch(s.type){case"circle":case"ring":case"star":return[s.r*2,s.r*2];case"ellipse":return[s.rx*2,s.ry*2];case"roundRect":return[s.w,s.h];case"line":return[s.length,s.lw??4];case"path":return s.r?[s.r*2,s.r*2]:[s.size,s.size]}}function ho(s){let r=s.type==="line"?0:s.stroke?(s.lw??2)/2:0,e=s.shadow?s.shadow.blur*1.5+Math.max(Math.abs(s.shadow.x??0),Math.abs(s.shadow.y??0)):0;return Math.ceil(r+e+1)}var zs=(s,r)=>r||!s.shadow?s:{...s,shadow:void 0};function en(s,r,e){let t=ho(r),n=r.type==="roundRect",[i,o]=n?[Math.min(r.w,r.r*2+4/e),Math.min(r.h,r.r*2+4/e)]:co(r),a=(i+t*2)*e,l=(o+t*2)*e;return{frame:s.bake(a,l,c=>{c.scale(e,e),c.translate(t+i/2,t+o/2),fo(c,r,i,o)},e,t+i/2,t+o/2,t),slice:n?Math.ceil((r.r+t)*e):0,w:n?r.w:i,h:n?r.h:o}}function fo(s,r,e,t){s.lineJoin="round",s.lineCap="round";let n=new Path2D;switch(r.type){case"circle":case"ring":n.arc(0,0,r.r,0,Math.PI*2);break;case"ellipse":n.ellipse(0,0,r.rx,r.ry,0,0,Math.PI*2);break;case"roundRect":n.roundRect(-e/2,-t/2,e,t,Math.min(r.r,e/2,t/2));break;case"star":{let u=r.points??5,c=r.r*(r.inner??.5);for(let f=0;f<u*2;f++){let p=f%2?c:r.r,b=-Math.PI/2+f*Math.PI/u;f?n.lineTo(Math.cos(b)*p,Math.sin(b)*p):n.moveTo(Math.cos(b)*p,Math.sin(b)*p)}n.closePath();break}case"line":n.moveTo(-e/2+t/2,0),n.lineTo(e/2-t/2,0);break;case"path":{let u=r.r?r.r*2/r.size:1,c=new DOMMatrix([u,0,0,u,-r.size/2*u,-r.size/2*u]);n.addPath(new Path2D(r.d),c);break}}let i=r.shadow,o=()=>{if(!i)return;let u=s.getTransform();s.shadowColor=i.color,s.shadowBlur=i.blur*u.a,s.shadowOffsetX=(i.x??0)*u.a,s.shadowOffsetY=(i.y??0)*u.a},a=()=>{s.shadowColor="transparent",s.shadowBlur=0};if(r.type==="line"){o(),s.strokeStyle=r.stroke??r.fill??"#fff",s.lineWidth=t,s.stroke(n);return}let l=r.type==="ring";if(r.outlineBelow&&r.fill&&r.stroke&&!l){o(),s.strokeStyle=r.stroke,s.lineWidth=r.lw??2,s.stroke(n),a(),s.fillStyle=r.fill,s.fill(n);return}r.fill&&!l&&(o(),s.fillStyle=r.fill,s.fill(n),a()),(r.stroke||l)&&((!r.fill||l)&&o(),l&&r.fill&&(s.fillStyle=r.fill,s.fill(n)),s.strokeStyle=r.stroke??"#fff",s.lineWidth=r.lw??2,s.stroke(n),a())}var pt=class{constructor(){h(this,"ctx",null);h(this,"master",null);h(this,"buffers",new Map);h(this,"held",!1);h(this,"muted",!1);h(this,"volume",1);if(typeof addEventListener=="function"){let r=()=>{this.context()?.resume().catch(()=>{})};for(let e of["pointerdown","keydown","touchstart"])addEventListener(e,r,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;let r=globalThis.AudioContext??globalThis.webkitAudioContext;if(!r)return null;try{this.ctx=new r,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch{return null}return this.ctx}async load(r,e){let t=this.context();if(!t)return;let n=await(await fetch(e)).arrayBuffer();this.buffers.set(r,await t.decodeAudioData(n))}has(r){return this.buffers.has(r)}play(r,e={}){let t=this.context(),n=this.buffers.get(r);if(!t||!n||!this.audible)return()=>{};let i=t.createBufferSource();i.buffer=n,i.loop=e.loop??!1,i.playbackRate.value=e.rate??1;let o=t.createGain();return o.gain.value=(e.volume??1)*this.volume,i.connect(o).connect(this.master),i.start(),()=>{try{i.stop()}catch{}}}tone(r,e=.25,t={}){let n=this.context();if(!(!n||!this.audible))try{let i=n.createOscillator(),o=n.createGain();i.type=t.type??"sine",i.frequency.setValueAtTime(r,n.currentTime),t.to&&i.frequency.exponentialRampToValueAtTime(t.to,n.currentTime+e),o.gain.setValueAtTime((t.volume??.12)*this.volume,n.currentTime),o.gain.exponentialRampToValueAtTime(.001,n.currentTime+e),i.connect(o).connect(this.master),i.start(),i.stop(n.currentTime+e)}catch{}}get audible(){return!this.muted&&!this.held}hold(){this.held=!0,this.ctx?.suspend().catch(()=>{})}release(){this.held=!1,this.ctx?.resume().catch(()=>{})}destroy(){this.ctx?.close().catch(()=>{}),this.ctx=null}};var po={high:{resolution:1.5,particles:1,effects:!0,maxBlur:32},medium:{resolution:1,particles:.5,effects:!1,maxBlur:16},low:{resolution:.75,particles:.2,effects:!1,maxBlur:0}},be=["high","medium","low"];function Se(s){let r=po[s];return{name:s,...r,scale:e=>e<=0?0:Math.max(1,Math.round(e*r.particles))}}var $s=s=>be[Math.min(be.indexOf(s)+1,be.length-1)],mr=(s,r)=>{if(!s.length)return NaN;let e=[...s].sort((t,n)=>t-n);return e[Math.min(e.length-1,Math.max(0,Math.floor(r*(e.length-1)+.5)))]},Vs=12,Ws=s=>Ot(s,.5);function Ot(s,r=.1){let e=mr(s,r);if(!Number.isFinite(e))return 1e3/60;let t=[144,120,90,75,60,50,30],n=60;for(let i of t)Math.abs(1e3/i-e)<Math.abs(1e3/n-e)&&(n=i);return 1e3/n}function br(s,r){let e=r.refresh!==void 0&&Number.isFinite(r.refresh)&&r.refresh>0?r.refresh:Ot(r.intervals),t=mr(r.intervals,.5),n=mr(r.intervals,.9),i=mr(r.cpu,.5);if(!Number.isFinite(t))return s==="canvas2d"?"low":"medium";let o=l=>l<=e*1.25,a=l=>!Number.isFinite(i)||i<e*l;return s==="canvas2d"?o(n)&&a(.25)?"medium":"low":o(n)&&a(.5)?"high":o(t)?"medium":"low"}function Xs(s,r){return s.length<30?!1:s.filter(t=>t>r*1.5).length/s.length>.5}var js="0.1.1",mo=720*3600*1e3,qs=(s,r,e)=>`fabi-play.engine-tier:${js}:${s}:${r}:${e}`,Ks=(s,r,e)=>`fablee-engine-tier:${js}:${s}:${r}:${e}`;function Ys(s,r,e=Date.now()){try{let t=JSON.parse(s?.getItem(r)??"null");if(t&&be.includes(t.tier)&&typeof t.at=="number"&&e-t.at<mo)return typeof t.refresh=="number"&&t.refresh>0?{name:t.tier,refresh:t.refresh}:{name:t.tier}}catch{}return null}function tn(s,r,e,t,n=Date.now()){try{s?.setItem(r,JSON.stringify(t!==void 0&&Number.isFinite(t)?{tier:e,at:n,refresh:t}:{tier:e,at:n}))}catch{}}function Qs(s=typeof location<"u"?location.search:""){let r=new URLSearchParams(s).get("tier");return be.includes(r)?r:void 0}function rn(s,r){let e=r?.tier;if(be.includes(e))return s==="canvas2d"&&e==="high"?"medium":e}var nn=s=>typeof s?.hz=="number"&&s.hz>=20&&s.hz<=240?Ot([1e3/s.hz],.5):NaN,sn=(s,r)=>be.indexOf(s)>=be.indexOf(r)?s:r;function Zs(s,r,e){return s?{name:s,from:"forced"}:r?{name:e?sn(r,e):r,from:"hint"}:e?{name:e,from:"cache"}:null}var bo=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,dt=class{constructor(r={}){h(this,"steps",[]);h(this,"labels",new Map);h(this,"end",0);h(this,"prevStart",0);h(this,"elapsed",0);h(this,"iter",0);h(this,"last",0);h(this,"delayLeft");h(this,"_paused");h(this,"done",!1);h(this,"rewinding",!1);h(this,"promise");h(this,"resolve");h(this,"repeat");h(this,"yoyo");h(this,"onComplete");this.repeat=Math.floor(r.repeat??0),this.yoyo=!!r.yoyo,this.delayLeft=r.delay??0,this._paused=!!r.paused,this.onComplete=r.onComplete,this.promise=new Promise(e=>this.resolve=e)}get duration(){return this.end}get time(){return this.last}get paused(){return this._paused}get finished(){return this.done}at(r){if(r===void 0)return this.end;if(typeof r=="number")return Math.max(r,0);let e=bo.exec(r);if(!e)throw new Error(`[engine] timeline: bad position "${r}"`);let[,t,n,i]=e,o=i?(n==="-"?-1:1)*Number(i):0,a=this.end;if(t==="<")a=this.prevStart;else if(t&&t!==">"){let l=this.labels.get(t.trim());l===void 0?this.labels.set(t.trim(),this.end):a=l}return Math.max(a+o,0)}add(r){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>r.start;)e--;return this.steps.splice(e,0,r),this.prevStart=r.start,this.end=Math.max(this.end,r.start+r.dur),this}to(r,e,t,n="quadOut"){let i=typeof n=="object"?n:{ease:n},o=typeof i.ease=="function"?i.ease:_e[i.ease??"quadOut"];return this.add({target:r,to:e,from:null,fn:null,start:this.at(i.at)+(i.delay??0),dur:Math.max(t,0),ease:o,onUpdate:i.onUpdate,p:-1})}set(r,e,t){return this.add({target:r,to:e,from:null,fn:null,start:this.at(t),dur:0,ease:_e.linear,p:-1})}call(r,e){return this.add({target:null,to:null,from:null,fn:r,start:this.at(e),dur:0,ease:_e.linear,p:-1})}label(r,e){return this.labels.set(r,this.at(e)),this}wait(r){return this.end+=Math.max(r,0),this.prevStart=this.end,this}pause(){return this._paused=!0,this}resume(){return this._paused=!1,this}stop(){this.done||(this.done=!0,this.resolve())}seek(r){let e=Math.min(typeof r=="string"&&this.labels.has(r)?this.labels.get(r):this.at(r),this.end),t=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(t?this.end-e:e),this.render(e),this}then(r,e){return this.promise.then(r,e)}update(r){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=r,this.delayLeft>0)return;r=-this.delayLeft,this.delayLeft=0}let e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=r;let t=this.repeat<0?1/0:e*(this.repeat+1),n=Math.min(this.elapsed,t),i=n>=t?this.repeat:Math.floor(n/e);for(;this.iter<i;){let a=this.yoyo&&this.iter%2===1;this.render(a?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}let o=n-i*e;this.render(this.yoyo&&i%2===1?e-o:o),n>=t&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(r){let e=this.steps;if(r>=this.last)for(let t=0;t<e.length;t++){let n=e[t];r>=n.start&&this.apply(n,r)}else for(let t=e.length-1;t>=0;t--){let n=e[t];n.p>=0&&this.apply(n,r)}this.last=r}apply(r,e){let t=r.dur>0?Math.min(Math.max((e-r.start)/r.dur,0),1):e>r.start||e===r.start&&!this.rewinding?1:0;if(t===r.p)return;if(r.p=t,r.fn){this.rewinding||r.fn();return}let n=r.target;if(n.destroyed||n._free)return;let i=r.to;if(!r.from){r.from={};for(let a in i)r.from[a]=Number(n[a]??0)}let o=r.ease(t);for(let a in i)n[a]=r.from[a]+(i[a]-r.from[a])*o;r.onUpdate?.(o)}};var mt=class{constructor(){h(this,"list",[]);h(this,"timelines",[])}timeline(r){let e=new dt(r);return this.timelines.push(e),e}tween(r,e,t,n="quadOut"){let i=typeof n=="object"?n:{ease:n},o=typeof i.ease=="function"?i.ease:_e[i.ease??"quadOut"],a,l=new Promise(u=>{let c=Object.keys(e),f=new Float64Array(c.length);c.forEach((p,b)=>f[b]=Number(e[p])),a={target:r,keys:c,to:f,from:new Float64Array(c.length),started:!1,duration:Math.max(t,0),time:0,delay:i.delay??0,ease:o,onUpdate:i.onUpdate,done:u,dead:!1}});return this.list.push(a),Object.assign(l,{stop:()=>this.finish(a)})}stopAll(r){let e=this.list;for(let t=0;t<e.length;t++)e[t].target===r&&this.finish(e[t])}get size(){return this.list.length}update(r){if(this.timelines.length){let n=0,i=this.timelines;for(let o=0;o<i.length;o++){let a=i[o];a.update(r),a.finished||(i[n++]=a)}i.length=n}let e=this.list;if(!e.length)return;let t=0;for(let n=0;n<e.length;n++){let i=e[n];i.dead||this.step(i,r),i.dead||(e[t++]=i)}t!==e.length&&(e.length=t)}step(r,e){if(r.target.destroyed)return this.finish(r);let t=e;if(r.delay>0){if(r.delay-=e,r.delay>0)return;t=-r.delay}let n=r.keys;if(!r.started){r.started=!0;for(let a=0;a<n.length;a++)r.from[a]=Number(r.target[n[a]]??0)}r.time+=t;let i=r.duration>0?Math.min(r.time/r.duration,1):1,o=r.ease(i);for(let a=0;a<n.length;a++)r.target[n[a]]=r.from[a]+(r.to[a]-r.from[a])*o;r.onUpdate?.(o),i>=1&&this.finish(r)}finish(r){r.dead||(r.dead=!0,r.done())}clear(){for(let r of this.list)this.finish(r);this.list.length=0;for(let r of this.timelines)r.stop();this.timelines=[]}};var j=720,Bt=class extends oe{constructor(e,t){super(e);h(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},an=class extends oe{constructor(e,t){super(e);h(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},Oe=()=>performance.now();async function ei(s={}){let r=s.play??null,e=s.canvas??null;e||(e=document.createElement("canvas"),e.style.cssText="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(e));let t=lt(e,{renderer:s.renderer??Os(),failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat,instancing:s.instancing});e=t.canvas;let n=new Set,i=new Le(Math.min(2048,t.maxTextureSize),4);i.onPage=y=>n.add(y),i.onDrop=y=>{n.delete(y),y.texture&&t.destroyTexture(y.texture),y.texture=null};let o=Pt(t),a=new mt,l=new pt,u=new Ve(i),c=new Map,f=new Map,p=new Map,b=new Map,g=new Map,m=new Set,d=0,v=s.tier??Qs(),x=String(t.info.renderer??""),S=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),w=typeof screen<"u"?`${screen.width}x${screen.height}`:"",A=qs(t.kind,x,w);Vn(S,A,Ks(t.kind,x,w));let E=Ys(S,A),R=Zs(v,rn(t.kind,r?.device),E?.name),C=R?.name??"medium",I=Se(C);u.setTier(C);let H=R?.from==="hint",z=E?.name,G=E?.refresh??nn(r?.device),U=1,ge=1,Me=1,Y={atlas:i,get pixelScale(){return U},get fontGen(){return d},get effects(){return I.effects},tweens:a,frame:y=>jt.frame(y),shape:y=>{let k=I.effects,F=k?U:-U,M=c.get(F);M||(c.size>=8&&c.clear(),c.set(F,M=new st(2e3)));let L=ce(y),$=M.get(y,L);return(!$||!i.valid($.frame))&&M.set(y,$=en(i,zs(y,k),U),L),$},bitmapFont:y=>jt.bitmapFont(y)},le=1280,Ee=null;class ki extends $e{get width(){return le}set width(k){}get height(){return j}set height(k){}get safe(){let k=Math.min(le,j*16/9);return{x:(le-k)/2,y:0,w:k,h:j}}}let ue=new ki(Y),Fe=()=>{let y=t.canvas,k=y.getBoundingClientRect();ge=Math.max(1,k.width||y.clientWidth||innerWidth),Me=Math.max(1,k.height||y.clientHeight||innerHeight),le=j*ge/Me;let F=Math.min(globalThis.devicePixelRatio||1,s.maxPixelRatio??2);if(Me*F/j<=I.resolution){let L=Math.max(1,Math.round(Me*F));U=L/j,t.resize(Math.max(1,Math.round(ge*F)),L)}else U=I.resolution,t.resize(Math.round(le*U),Math.round(j*U));Ee&&Ee.style.setProperty("--unit",`${Me/j}px`)};addEventListener("resize",Fe);let vr=y=>{C=y,I=Se(y),u.setTier(y),Fe()},Gt=typeof ResizeObserver<"u"?new ResizeObserver(Fe):null;Gt?.observe(e);let xe=r?.backdrop==="video"?"video":"none",V=r?.view??null,Rn=[],_n=-1/0,Ut=!1,bt=!1,wr=new Set,Cn=()=>{let y=xe==="video"?"transparent":"";document.documentElement.style.background=y,document.body.style.background=y},Ln=(y,k)=>{let F=y==="video"?"video":"none",M=k??null;if(!(F===xe&&(M===V||M&&V&&M.x===V.x&&M.y===V.y&&M.w===V.w&&M.h===V.h))){xe=F,V=M,Cn();for(let L of[...wr])L(xe,V)}},Pn=[];if(r){let y=M=>{Array.isArray(M)&&(Rn=M,_n=Oe())},k=M=>{Ut=M,Ht()},F=M=>{if(v||H)return;Number.isFinite(G)||(G=nn(M));let L=rn(t.kind,M);L&&(H=!0,vr(z?sn(L,z):L))};Pn.push(r.on("start",M=>F(M?.device)),r.on("start",M=>{typeof M?.muted=="boolean"&&(l.muted=M.muted)}),r.on("frame",M=>y(M?.players)),r.on("players",M=>y(M?.players)),r.on("backdrop",M=>Ln(M?.backdrop,M?.view)),r.on("start",M=>Ln(M?.backdrop,M?.view??r.view)),r.on("pause",()=>k(!0)),r.on("resume",()=>k(!1)),r.on("break-start",()=>k(!0)),r.on("break-done",()=>k(!1)),r.on("break-end",()=>k(!1))),l.muted=r.muted===!0}Cn();let Ht=()=>Ut||bt||document.hidden?l.hold():l.release(),Nn=-1,kr=[],Ar=0,Sr=()=>Oe()-_n<1e3?Rn:[],Ai=y=>r?r.toScreen(y):$n(V,y),zt=()=>{if(Nn===Ar)return kr;Nn=Ar;let y=xe==="video"||!r?.smoothedBody?()=>null:k=>r.smoothedBody(k);return kr=pr(Sr(),Ai,le,j,y),kr},yt={x:0,y:0,w:1,h:1},Si=()=>(yt.x=V?V.x*le:0,yt.y=V?V.y*j:0,yt.w=V?V.w*le:le,yt.h=V?V.h*j:j,yt),Ti=y=>{let k=y.alpha??1,F=y.tags?new Ie(i,y):null;F&&m.add(F);let M=typeof y.tags=="function"?y.tags:L=>String(L);return(L,$)=>{if(xe==="video")return;let N=Si();for(let O of Sr()){let q=r?.smoothedBody?.(O)??O.body,D=Ke(r?.avatarOf?.(O)??O.avatar??"")??Ye;if(!u.draw(L.r,L.tex,q,D,N,k*$,U)||!F)continue;let ie=M(O.id);ie&&F.draw(L.r,L.tex,q,D,N,ie,Nt(O.id),k*$,U,le,j)}}},Tr=new Set,Mr=new Set,gt=new Set,$t=!1,Er=0,je=0,Vt=0,Be={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0},Wt=0,Fr=0,Rr=Oe(),xt=[],Xt=0,In=()=>({r:t,kernel:Y,tex:o}),On=In(),Mi=()=>{if(t.lost)return;let[y,k]=xe==="video"||s.background===void 0?[0,0]:K(s.background);t.time=Vt,t.maxBlur=I.maxBlur,t.begin(y,k,U),ee(ue.world,null,ue.x,ue.y,ue.rotation,ue.scaleX,ue.scaleY),Hr(On,ue,ue.alpha,ue.tint);let F=t.end();Be.drawCalls=F.drawCalls,Be.quads=F.quads,Be.filtersSkipped=F.filtersSkipped},Bn=y=>{if(!$t)return;Er=requestAnimationFrame(Bn);let k=Math.min(Math.max((y-je)/1e3,0),.1);je&&xt.push(y-je),je=y,Ar++;let F=Oe(),M=Ut||bt;if(!M){Vt+=k,a.update(k);for(let L of gt)L.destroyed||L.update(k);for(let L of Tr)L(k,Vt)}for(let L of Mr)L(k);ue.sweep();for(let L of gt)L.destroyed&&gt.delete(L);if(t.lost?(Xt||(Xt=y),y-Xt>3e3&&Ei()):(Xt=0,Mi()),Wt++,Fr+=Oe()-F,F-Rr>=1e3&&(Be.fps=Math.round(Wt*1e3/(F-Rr)),Be.cpuMs=Math.round(Fr/Math.max(Wt,1)*100)/100,r?.reportStats?.({fps:Be.fps,renderer:t.kind,tier:C}),Wt=0,Fr=0,Rr=F),xt.length>=180){let L=Number.isFinite(G)?G:Ot(xt);!v&&!M&&Xs(xt,L)&&C!=="low"&&(vr($s(C)),z=C,tn(S,A,C,Number.isFinite(G)?G:void 0),console.info(`[engine] slow frames: tier ${C}`)),xt.length=0}},Ei=()=>{let y=Lt(t.canvas),k=ot(y);if(k){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),t.destroy(),t=k;for(let F of n)F.texture=null;for(let F of i.pages)n.add(F.surface);o=Pt(t),On=In(),Gt?.disconnect(),Gt?.observe(y),Fe()}},Dn=()=>{Ht(),document.hidden||(je=0)};document.addEventListener("visibilitychange",Dn);let Gn=()=>{d++;for(let y of m)y.drop()};if(document.fonts?.addEventListener?.("loadingdone",Gn),Fe(),!R&&s.probe!==!1&&(Number.isFinite(G)||(G=Ws(await yo(Vs))),!H)){I=Se("high"),Fe();let y=await go(t,i,()=>o,()=>U,le,()=>H);if(y.refresh=G,!H){let k=br(t.kind,y);tn(S,A,k,G),z=k,vr(k)}}let jt={stage:ue,get tier(){return I},get renderer(){return t},get canvas(){return t.canvas},get pixelScale(){return U},get backdrop(){return xe},get view(){return V},get paused(){return Ut||bt},sound:l,stats:Be,get time(){return Vt},get supports(){let y=t.support;return{filters:y.filters,blur:y.filters&&I.maxBlur>0,shaders:y.shaders,maxBlur:y.filters?I.maxBlur:0,tiers:{high:{maxBlur:Se("high").maxBlur},medium:{maxBlur:Se("medium").maxBlur},low:{maxBlur:Se("low").maxBlur}}}},sprite:(y,k)=>new re(Y,y,k),shape:(y,k)=>new fe(Y,y,k),text:(y,k)=>new me(Y,y,k),group:y=>new $e(Y).set(y??{}),particles(y,k={}){let F=typeof y=="object"&&"type"in y?Y.shape(y).frame:y,M=new et(Y,F,k),{max:L,blend:$,gravity:N,drag:O,...q}=k;return M.set(q),gt.add(M),M},tween:(y,k,F,M)=>a.tween(y,k,F,M),bake(y,k,F,M,L){return p.set(y,{w:k,h:F,draw:M,origin:L}),f.delete(y),jt.frame(y)},frame(y){let k=f.get(y);if(k&&i.valid(k)&&(k.gen===0||k.scale===U))return k;let F=p.get(y);if(F){let M=U,L=i.bake(F.w*M,F.h*M,$=>($.scale(M,M),F.draw($)),M,F.origin?.x??0,F.origin?.y??0);return f.set(y,L),L}if(k)return k;throw new Error(`[engine] no frame "${y}": load it or bake it first`)},async load(y){await Promise.all(Object.entries(y).map(([k,F])=>Ri(k,F)))},hands:y=>y===void 0?zt():zt().filter(k=>k.player===y),touched(y,k,F={}){return y.updateWorld(),dr(y,zt(),k,F.padding??0)},hits(y,k,F,M=0){return y.updateWorld(),It(y,k,F,M)},avatars:(y={})=>new Bt(Y,Ti(y)),handMarkers(y={}){let k=y.radius??36,F=y.look??"auto",M=new Float64Array(6),L=Math.max(k*.12,3),$={type:"ring",r:k,lw:L,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},N={type:"ring",r:k,lw:L*1.8,stroke:We,shadow:{color:We,blur:k*.2}},O=(De,J,qe,_r,qt,Ge)=>{let Kt=J.w/J.scale;ee(M,null,qe-Kt/2,_r-Kt/2,0,1,1),De.r.quad(De.tex(J.surface),J,M,Kt,Kt,qt,Ge,"normal")},q=De=>{let J=null,qe=!1;return()=>(J&&i.valid(J.frame)&&J.frame.scale===U&&qe===I.effects?J:(qe=I.effects,J=Y.shape(De))).frame},D=q($),ie=q(N);return new an(Y,(De,J)=>{let qe=F==="video"||F==="auto"&&xe==="video",_r=D(),qt=qe?ie():null;for(let Ge of zt())qt&&O(De,qt,Ge.x,Ge.y,16777215,J),O(De,_r,Ge.x,Ge.y,K(Ge.color)[0],J)})},timeline:y=>a.timeline(y),animation(y,k){let F=typeof y=="string"?Fi(y):{frames:y},M=new ae(Y,F,k);return gt.add(M),M},bitmapFont(y,k){if(!k){let M=b.get(y);if(!M)throw new Error(`[engine] no bitmap font "${y}": load or make it first`);return M}let F="data"in k?Un(ft(k.data),k.pages):Hs(Y,k);return b.set(y,F),F},players:()=>Sr(),onFrame(y){return Tr.add(y),()=>{Tr.delete(y)}},onRender(y){return Mr.add(y),()=>{Mr.delete(y)}},onBackdrop(y){return wr.add(y),()=>{wr.delete(y)}},get hud(){return Ee||(Ee=document.createElement("div"),Ee.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(Ee),Fe()),Ee},random:(y=0,k=1)=>y+Math.random()*(k-y),start(){$t||($t=!0,je=0,Er=requestAnimationFrame(Bn))},pause(){bt=!0,Ht()},resume(){bt=!1,Ht()},destroy(){$t=!1,cancelAnimationFrame(Er),Pn.forEach(y=>y()),removeEventListener("resize",Fe),Gt?.disconnect(),document.removeEventListener("visibilitychange",Dn),document.fonts?.removeEventListener?.("loadingdone",Gn),a.clear(),cs(Y),l.destroy(),t.destroy(),Ee?.remove()}};function Fi(y){let k=g.get(y);if(k)return k;let F=[...new Set([...f.keys(),...p.keys()])].filter(M=>M.startsWith(y)).sort(fs);if(!F.length)throw new Error(`[engine] no animation or frames "${y}\u2026"`);return{frames:F}}async function Ri(y,k){let F=k.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(F))return l.load(y,k);if(["woff","woff2","ttf","otf"].includes(F)){let N=new FontFace(y,`url(${k})`);document.fonts.add(await N.load()),d++;return}let M=new URL(k,location.href);if(F==="fnt")return Hn(y,ft(await(await fetch(k)).text()),M);if(F==="json"){let N=await(await fetch(k)).json();if(Array.isArray(N.chars)&&!N.frames)return Hn(y,ft(N),M);let O=await on(new URL(N.meta?.image??k.replace(/\.json$/,".png"),M).href);_i(y,N,tt(O));return}let L=await on(k),$=tt(L);n.add($),f.set(y,{surface:$,x:0,y:0,w:L.width,h:L.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function Un(y,k){return Us(y,k.map(F=>{let M=tt(F);return n.add(M),M}))}async function Hn(y,k,F){b.set(y,Un(k,await Promise.all(k.pages.map(M=>on(new URL(M,F).href)))))}function _i(y,k,F){n.add(F);let M=Array.isArray(k.frames)?k.frames:Object.entries(k.frames).map(([N,O])=>({...O,filename:N})),L=[],$=[];for(let N of M){let O=N.frame,q=N.filename.replace(Js,"");N.rotated&&console.warn(`[engine] ${y}/${q} is rotated: export without rotation`);let D={surface:F,x:O.x,y:O.y,w:O.w,h:O.h,scale:1,gen:0,ox:0,oy:0,margin:0};N.trimmed&&N.sourceSize&&N.spriteSourceSize&&(D.sw=N.sourceSize.w,D.sh=N.sourceSize.h,D.tx=N.spriteSourceSize.x,D.ty=N.spriteSourceSize.y);let ie=N.scale9Borders;ie&&(D.slice=[ie.y,(D.sw??O.w)-ie.x-ie.w,(D.sh??O.h)-ie.y-ie.h,ie.x]),f.set(`${y}/${q}`,D),L.push(`${y}/${q}`),$.push((N.duration??0)/1e3)}for(let[N,O]of Object.entries(k.animations??{}))g.set(`${y}/${N}`,{frames:O.map(q=>`${y}/${q.replace(Js,"")}`)});for(let N of k.meta?.frameTags??[]){let O=[];for(let D=N.from;D<=N.to;D++)O.push(D);N.direction==="reverse"&&O.reverse(),N.direction==="pingpong"&&O.push(...O.slice(1,-1).reverse());let q=O.every(D=>$[D]>0);g.set(`${y}/${N.name}`,{frames:O.map(D=>L[D]),...q?{durations:O.map(D=>$[D])}:{}})}}return jt}var Js=/\.(png|webp|jpe?g|gif|bmp)$/i;function on(s){return new Promise((r,e)=>{let t=new Image;t.onload=()=>r(t),t.onerror=()=>e(new Error(`[engine] image did not load: ${s}`)),t.src=s})}function yo(s){return new Promise(r=>{let e=[],t=0,n=i=>{t&&e.push(i-t),t=i,e.length<s?requestAnimationFrame(n):r(e)};requestAnimationFrame(n)})}async function go(s,r,e,t,n,i=()=>!1){let o=t(),a=en(r,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},o).frame,l=[],u=[],c=new Float64Array(6),f=.004,p=s.kind==="canvas2d"?s.canvas.getContext("2d"):null,b=Oe(),g=0;return await new Promise(m=>{let d=v=>{g&&v-b>250&&l.push(v-g),g=v;let x=Oe();s.begin(0,0,o);let S=e();for(let w=0;w<300;w++){let A=v/1e3+w;ee(c,null,w*37%n,w*53%j,A,1,1),s.quad(S(a.surface),a,c,a.w/o,a.h/o,16777215,f,"normal")}for(let w=0;w<40;w++)s.ellipse(100+w*20,300,20,14,w,16746496,f),s.stroke([100+w*20,400,120+w*20,460,100+w*20,520],3,18,3368703,f,!1);s.end(),p?.getImageData(0,0,1,1),v-b>250&&u.push(Oe()-x),v-b<750&&!i()?requestAnimationFrame(d):(s.begin(0,0,o),s.end(),m())};requestAnimationFrame(d)}),{intervals:l,cpu:u}}var xo=64,ti=32,vo=0,wo=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,ri=new Set,ni=(s,r)=>{ri.has(s)||(ri.add(s),console.warn(r))},si=s=>new ln(s),ln=class{constructor(r){h(this,"r",r);h(this,"css","none");h(this,"plans",new st(xo));h(this,"buf",new Float64Array(64));h(this,"keys",[]);h(this,"classes",new Map);h(this,"live",new Set);h(this,"svgs",new Map);h(this,"t",0);h(this,"cur",null);h(this,"svgFn",r=>this.svg(r));h(this,"scr",[]);h(this,"flip",0)}chain(r,e){var g;let t=this.r,n=this.buf;n[0]=t.scale,n[1]=t.maxBlur;let i=2;for(let m=0;m<e.length;m++){let d=e[m];if(i+22>n.length){let x=new Float64Array(n.length*2);x.set(n),n=this.buf=x}let v=this.classes.get(d.constructor);v===void 0&&this.classes.set(d.constructor,v=this.classes.size),n[i++]=v,n[i++]=d.enabled?1:0,d.params&&(i=d.params(n,i))}let o=(g=this.keys)[i]??(g[i]=new Float64Array(i));for(let m=0;m<i;m++)o[m]=n[m];let a=ce(o),l=this.plans.get(o,a);l||this.plans.set(o,l=this.plan(e),a);for(let m=0;m<l.svgs.length;m++){let d=l.svgs[m];d.used<0&&this.attach(d),d.used=this.t}t.skipped+=l.skip;let u=r,c=t.rx0,f=t.ry0,p=t.rx1-c,b=t.ry1-f;for(let m=0;m<l.paints.length;m++)l.parts[m]&&(u=this.bake(u,l.parts[m])),e[l.paints[m]].paint2d(u.getContext("2d"),c,f,p,b);return this.css=l.parts[l.paints.length]||"none",u}tick(){let r=++this.t;if(!(r%ti||!this.live.size))for(let e of this.live)r-e.used>ti&&this.detach(e)}destroy(){for(let r of this.live)this.detach(r);this.plans.clear()}svg(r){if(typeof document>"u"||!document.body)return null;let e=Array.from({length:20},(n,i)=>r[i]??0).join(" "),t=this.svgs.get(e);if(!t){let n="http://www.w3.org/2000/svg",i=document.createElementNS(n,"svg");i.setAttribute("width","0"),i.setAttribute("height","0"),i.setAttribute("aria-hidden","true"),i.style.position="absolute";let o=document.createElementNS(n,"filter"),a=wo+ ++vo;o.setAttribute("id",a),o.setAttribute("color-interpolation-filters","sRGB");let l=document.createElementNS(n,"feColorMatrix");l.setAttribute("type","matrix"),l.setAttribute("values",e),o.append(l),i.append(o),this.attach(t={key:e,id:a,el:i,used:this.t})}return this.cur.svgs.push(t),`url(#${t.id})`}attach(r){document.body.append(r.el),this.live.add(r),this.svgs.has(r.key)||this.svgs.set(r.key,r)}detach(r){r.el.remove(),r.used=-1,this.live.delete(r),this.svgs.get(r.key)===r&&this.svgs.delete(r.key)}plan(r){let e=this.r,t=this.cur={parts:[],paints:[],skip:0,svgs:[]},n="";for(let i=0;i<r.length;i++){let o=r[i];if(!o.enabled)continue;if(o.kind===4){t.skip++,ni("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}let a=e.support.filters&&o.css?o.css(e.scale,e.maxBlur,this.svgFn):null;a!==null?n+=n?` ${a}`:a:o.paint2d?(t.parts.push(n),t.paints.push(i),n=""):(t.skip++,ni("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return t.parts.push(n),t}bake(r,e){let t=this.r,n=this.flip^=1,i=this.scr[n];(!i||i.width!==t.canvas.width||i.height!==t.canvas.height)&&(i=this.scr[n]=document.createElement("canvas"),i.width=t.canvas.width,i.height=t.canvas.height);let o=i.getContext("2d"),a=t.rx0,l=t.ry0,u=t.rx1-a,c=t.ry1-l;return o.clearRect(a,l,u,c),o.filter=e,o.drawImage(r,a,l,u,c,a,l,u,c),o.filter="none",i}};var ko=64,yr=17,Ao=s=>`${ur}
49
49
  uniform sampler2D uTexture;
50
50
  uniform mat4 uM[${s}];
51
51
  uniform vec4 uO[${s}];
@@ -82,7 +82,7 @@ void main() {
82
82
  if (uMode > 0.5) c = uShadow * c.a;
83
83
  gl_FragColor = c * vColor;
84
84
  }`;function To(s,r,e=new Float32Array(20)){for(let t=0;t<4;t++)for(let n=0;n<5;n++){let i=n===4?r[t*5+4]:0;for(let o=0;o<4;o++)i+=r[t*5+o]*s[o*5+n];e[t*5+n]=i}return s.set(e),s}var ii=s=>new fn(s),fn=class{constructor(r){h(this,"r",r);h(this,"colorProg",null);h(this,"blurProg",null);h(this,"user",new Map);h(this,"uses",0);h(this,"userErr",new Map);h(this,"scratchT",new Map);h(this,"steps",[]);h(this,"mats",[]);h(this,"counts",[]);h(this,"colorN");h(this,"fm",new Float32Array(20));h(this,"fm2",new Float32Array(20));h(this,"fm3",new Float32Array(20));h(this,"m16");h(this,"o4");h(this,"taps",new Float32Array(yr*2));let e=r.gl;this.colorN=Math.max(1,Math.min(8,Math.floor((e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS)-4)/5))),this.m16=new Float32Array(16*this.colorN),this.o4=new Float32Array(4*this.colorN)}check(r){return this.r.lost?null:(this.userProg(r,!1),this.userErr.get(r)??null)}destroy(){let r=this.r.gl;for(let e of this.scratchT.values())r.deleteTexture(e.gl),r.deleteFramebuffer(e.fb);this.scratchT.clear();for(let e of[this.colorProg,this.blurProg])e&&r.deleteProgram(e.p);for(let e of this.user.values())e.p&&r.deleteProgram(e.p.p);this.user.clear()}userProg(r,e){let t=this.user,n=t.get(r);if(n)return n.t=++this.uses,n.p;if(this.r.lost)return null;if(t.size>=ko){let o="",a=1/0;for(let[u,c]of t)c.t<a&&(a=c.t,o=u);let l=t.get(o).p;l&&this.r.gl.deleteProgram(l.p),t.delete(o),this.userErr.delete(o)}let i;try{i=this.r.build(r)}catch(o){i=null;let a=o.message;this.userErr.set(r,a),e&&console.error(`[engine] a shader filter does not compile: it is skipped.
85
- ${a}`)}return t.set(r,{p:i,t:++this.uses}),i}scratch(r,e){let t=this.r,n=Math.ceil(t.canvas.width/r),i=Math.ceil(t.canvas.height/r),o=r*8+e,a=this.scratchT.get(o)??null;return a&&(a.w!==n||a.h!==i)&&(t.drop(a),a=null),a||(a=t.target(n,i,r,!0),a?this.scratchT.set(o,a):this.scratchT.delete(o)),a}pass(r,e,t,n,i=!1){let o=this.r,a=o.gl;o.flush(),o.mapped=!1,o.bindFb(n),a.viewport(0,0,n.w,n.h),i||(a.disable(a.SCISSOR_TEST),a.clearColor(0,0,0,0),a.clear(a.COLOR_BUFFER_BIT)),o.use(r);let l=n.f;a.uniform2f(r.uScale,2/(l*n.w),-2/(l*n.h));let u=Math.floor(o.rx0/l)*l,c=Math.floor(o.ry0/l)*l,f=Math.min(Math.ceil(o.rx1/l),n.w)*l,d=Math.min(Math.ceil(o.ry1/l),n.h)*l,b=1/(t*e.width),g=1/(t*e.height);o.bScis=!1,o.batch.push(u,c,f,c,f,d,u,d,u*b,1-c*g,f*b,1-d*g,4294967295,o.slotOf(e)),o.flush()}post(r){return r==="color"?this.colorProg??(this.colorProg=this.r.build(Ao(this.colorN))):this.blurProg??(this.blurProg=this.r.build(So()))}linear(r,e){let t=this.r,n=t.gl;t.bindTex(t.layerTex.get(r)??null,0);let i=e?n.LINEAR:n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,i),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,i)}chain(r,e,t){let n=this.r,i=this.steps,o=n.scale,a=n.maxBlur,l=0;for(let d=0;d<t.length;d++){let b=t[d];if(b.enabled)if(b.kind===1&&b.toMatrix){(!l||i[l-1]!==null)&&(i[l]=null,(!this.mats[l]||this.mats[l].length<20*this.colorN)&&(this.mats[l]=new Float32Array(20*this.colorN)),this.counts[l]=0,l++);let g=this.mats[l-1],p=this.counts[l-1];if(p<this.colorN)b.toMatrix(this.fm),g.set(this.fm,p*20),this.counts[l-1]=p+1;else{let m=(p-1)*20;for(let v=0;v<20;v++)this.fm2[v]=g[m+v];b.toMatrix(this.fm),To(this.fm2,this.fm,this.fm3),g.set(this.fm2,m)}}else b.kind===4?this.userProg(b.source,!0)?i[l++]=b:n.skipped++:b.kind===2?Math.min(b.radius,a)*o>=.25&&(i[l++]=b):b.kind===3?i[l++]=b:n.skipped++}if(!l)return!1;let u=n.gl,c=r,f=-1;for(let d=0;d<l;d++){let b=d===l-1,g=f===0?1:0,p=b?null:this.scratch(1,g);if(!b&&!p)break;let m=i[d];if(m===null){let v=this.post("color");n.use(v);let x=this.mats[d],S=this.counts[d],w=this.m16,A=this.o4;for(let E=0;E<S;E++)for(let R=0;R<4;R++){for(let C=0;C<4;C++)w[E*16+C*4+R]=x[E*20+R*5+C];A[E*4+R]=x[E*20+R*5+4]}u.uniformMatrix4fv(n.u(v,"uM"),!1,w),u.uniform4fv(n.u(v,"uO"),A),u.uniform1i(n.u(v,"uK"),S),p?this.pass(v,c,1,p):n.final(v,c,1,e)}else if(m.kind===2)this.blur(c,f<0,Math.min(m.radius,a)*o,p,e,null);else if(m.kind===3){let v=m,x=this.scratch(1,2);if(!x)break;this.blur(c,f<0,Math.max(Math.min(v.blur,a),0)*o,x,1,v);let S=p??(e<1?this.scratch(1,g):null);S?(this.pass(n.main,x.tex,1,S),this.pass(n.main,c,1,S,!0),p||n.final(n.main,S.tex,1,e)):(n.final(n.main,x.tex,1,1),n.final(n.main,c,1,1))}else{let v=m,x=this.userProg(v.source,!0);n.use(x);let S=n.canvas.width,w=n.canvas.height;u.uniform2f(n.u(x,"uResolution"),S,w),u.uniform1f(n.u(x,"uTime"),n.time),u.uniform4f(n.u(x,"uRect"),n.rx0/S,1-n.ry1/w,n.rx1/S,1-n.ry0/w);let A=v.uniforms;for(let E in A){let R=n.u(x,E);if(!R)continue;let C=A[E];typeof C=="number"?u.uniform1f(R,C):C.length===2?u.uniform2fv(R,C):C.length===3?u.uniform3fv(R,C):C.length===4?u.uniform4fv(R,C):C.length===1&&u.uniform1fv(R,C)}p?this.pass(x,c,1,p):n.final(x,c,1,e)}p&&(c=p.tex,f=g)}return n.remap(),!0}blur(r,e,t,n,i,o){let a=this.r,l=a.gl,u=this.post("blur"),c=1;for(;c<16&&t/c>8;)c*=2;e&&this.linear(r,!0);let f=r,d=1,b=Math.sqrt(Math.max(t*t-(c*c-1)/12,0))/c,g=t>=.25?this.tapsFor(b):this.tapsFor(0),p=!0;if(g>1){for(let v=2;v<=c&&p;v*=2){let x=this.scratch(v,0);x?(this.pass(a.main,f,d,x),f=x.tex,d=v):p=!1}let m=p?this.scratch(c,3):null;m&&(a.use(u),l.uniform2fv(a.u(u,"uTaps"),this.taps),l.uniform1i(a.u(u,"uN"),g),l.uniform2f(a.u(u,"uDir"),1/f.width,0),l.uniform2f(a.u(u,"uOff"),0,0),l.uniform1f(a.u(u,"uMode"),0),this.pass(u,f,d,m),f=m.tex)}if(a.use(u),l.uniform2fv(a.u(u,"uTaps"),this.taps),l.uniform1i(a.u(u,"uN"),g),l.uniform2f(a.u(u,"uDir"),0,1/f.height),o){let m=o.opacity,v=o.rgb;l.uniform4f(a.u(u,"uShadow"),(v>>16&255)/255*m,(v>>8&255)/255*m,(v&255)/255*m,m),l.uniform1f(a.u(u,"uMode"),1),l.uniform2f(a.u(u,"uOff"),-o.dx*a.scale/(d*f.width),o.dy*a.scale/(d*f.height))}else l.uniform1f(a.u(u,"uMode"),0),l.uniform2f(a.u(u,"uOff"),0,0);n?this.pass(u,f,d,n):a.final(u,f,d,i),e&&this.linear(r,!1)}tapsFor(r){let e=this.taps;if(e.fill(0),e[1]=1,r<.2)return 1;let t=Math.min(Math.ceil(3*r),(yr-1)*2),n=-1/(2*r*r),i=1,o=1;for(let a=1;a<=t;a+=2){let l=Math.exp(a*a*n),u=a+1<=t?Math.exp((a+1)*(a+1)*n):0,c=l+u;e[o*2]=(a*l+(a+1)*u)/c,e[o*2+1]=c,i+=2*c,o++}for(let a=0;a<o;a++)e[a*2+1]=e[a*2+1]/i;return o}};var Te=s=>Math.min(Math.max(s,0),1),he=s=>Math.max(s,0),Xe=class{constructor(){h(this,"enabled",!0);te.gl=ii,te.c2d=si}},ye=class extends Xe{constructor(e){super();h(this,"amount",e);h(this,"kind",1)}params(e,t){return e[t]=this.amount,t+1}};function gr(s,r,e){s.fill(0),s[0]=s[6]=s[12]=r,s[4]=s[9]=s[14]=e,s[18]=1}function xr(s,r){s.fill(0);for(let e=0;e<3;e++)for(let t=0;t<3;t++)s[e*5+t]=r[e*3+t];s[18]=1}var P=new Float64Array(9),mn=class extends ye{toMatrix(r){gr(r,he(this.amount),0)}css(){return`brightness(${he(this.amount)})`}},pn=class extends ye{toMatrix(r){let e=he(this.amount);gr(r,e,.5-.5*e)}css(){return`contrast(${he(this.amount)})`}},bn=class extends ye{toMatrix(r){let e=Te(this.amount);gr(r,1-2*e,e)}css(){return`invert(${Te(this.amount)})`}},yn=class extends ye{toMatrix(r){let e=he(this.amount);P[0]=.213+.787*e,P[1]=.715-.715*e,P[2]=.072-.072*e,P[3]=.213-.213*e,P[4]=.715+.285*e,P[5]=.072-.072*e,P[6]=.213-.213*e,P[7]=.715-.715*e,P[8]=.072+.928*e,xr(r,P)}css(){return`saturate(${he(this.amount)})`}},gn=class extends ye{toMatrix(r){let e=1-Te(this.amount);P[0]=.2126+.7874*e,P[1]=.7152-.7152*e,P[2]=.0722-.0722*e,P[3]=.2126-.2126*e,P[4]=.7152+.2848*e,P[5]=.0722-.0722*e,P[6]=.2126-.2126*e,P[7]=.7152-.7152*e,P[8]=.0722+.9278*e,xr(r,P)}css(){return`grayscale(${Te(this.amount)})`}},xn=class extends ye{toMatrix(r){let e=1-Te(this.amount);P[0]=.393+.607*e,P[1]=.769-.769*e,P[2]=.189-.189*e,P[3]=.349-.349*e,P[4]=.686+.314*e,P[5]=.168-.168*e,P[6]=.272-.272*e,P[7]=.534-.534*e,P[8]=.131+.869*e,xr(r,P)}css(){return`sepia(${Te(this.amount)})`}},vn=class extends ye{get angle(){return this.amount}set angle(r){this.amount=r}toMatrix(r){let e=this.amount*Math.PI/180,t=Math.cos(e),n=Math.sin(e);P[0]=.213+t*.787-n*.213,P[1]=.715-t*.715-n*.715,P[2]=.072-t*.072+n*.928,P[3]=.213-t*.213+n*.143,P[4]=.715+t*.285+n*.14,P[5]=.072-t*.072-n*.283,P[6]=.213-t*.213-n*.787,P[7]=.715-t*.715+n*.715,P[8]=.072+t*.928+n*.072,xr(r,P)}css(){return`hue-rotate(${this.amount}deg)`}},wn=class extends ye{constructor(e,t){super(t);h(this,"c",16777215);h(this,"cs","");this.color=e}get color(){return this.c}set color(e){this.c=K(e)[0],this.cs=Ue(this.c)}params(e,t){return e[t]=this.amount,e[t+1]=this.c,t+2}toMatrix(e){let t=Te(this.amount);gr(e,1-t,0),e[4]=(this.c>>16&255)/255*t,e[9]=(this.c>>8&255)/255*t,e[14]=(this.c&255)/255*t}css(){return null}paint2d(e,t,n,i,o){let a=Te(this.amount);a<=0||(e.save(),e.setTransform(1,0,0,1,0,0),e.globalAlpha=a,e.globalCompositeOperation="source-atop",e.fillStyle=this.cs,e.fillRect(t,n,i,o),e.restore())}},kn=class extends Xe{constructor(e){super();h(this,"kind",1);h(this,"values");if(e.length!==20)throw new Error(`colorMatrix: 20 numbers expected (4 rows of 5), got ${e.length}`);this.values=Array.from(e)}toMatrix(e){for(let t=0;t<20;t++)e[t]=this.values[t]??0}params(e,t){for(let n=0;n<20;n++)e[t+n]=this.values[n]??0;return t+20}css(e,t,n){return n?n(this.values):null}},An=class extends Xe{constructor(e){super();h(this,"radius",e);h(this,"kind",2)}params(e,t){return e[t]=this.radius,t+1}pad(e){return 3*Math.min(he(this.radius),e)}css(e,t){return`blur(${Math.min(he(this.radius),t)*e}px)`}},Sn=class extends Xe{constructor(e,t,n,i){super();h(this,"dx",e);h(this,"dy",t);h(this,"blur",n);h(this,"kind",3);h(this,"rgb",0);h(this,"a",1);this.color=i}get opacity(){return this.a}set opacity(e){this.a=Te(e)}get color(){return this.rgb}set color(e){let[t,n]=K(e);this.rgb=t,this.a=n}params(e,t){return e[t]=this.dx,e[t+1]=this.dy,e[t+2]=this.blur,e[t+3]=this.rgb,e[t+4]=this.a,t+5}pad(e){return 3*Math.min(he(this.blur),e)+Math.max(Math.abs(this.dx),Math.abs(this.dy))}css(e,t){return`drop-shadow(${this.dx*e}px ${this.dy*e}px ${2*Math.min(he(this.blur),t)*e}px ${Ue(this.rgb,this.opacity)})`}},Mo=`#ifdef GL_FRAGMENT_PRECISION_HIGH
85
+ ${a}`)}return t.set(r,{p:i,t:++this.uses}),i}scratch(r,e){let t=this.r,n=Math.ceil(t.canvas.width/r),i=Math.ceil(t.canvas.height/r),o=r*8+e,a=this.scratchT.get(o)??null;return a&&(a.w!==n||a.h!==i)&&(t.drop(a),a=null),a||(a=t.target(n,i,r,!0),a?this.scratchT.set(o,a):this.scratchT.delete(o)),a}pass(r,e,t,n,i=!1){let o=this.r,a=o.gl;o.flush(),o.mapped=!1,o.bindFb(n),a.viewport(0,0,n.w,n.h),i||(a.disable(a.SCISSOR_TEST),a.clearColor(0,0,0,0),a.clear(a.COLOR_BUFFER_BIT)),o.use(r);let l=n.f;a.uniform2f(r.uScale,2/(l*n.w),-2/(l*n.h));let u=Math.floor(o.rx0/l)*l,c=Math.floor(o.ry0/l)*l,f=Math.min(Math.ceil(o.rx1/l),n.w)*l,p=Math.min(Math.ceil(o.ry1/l),n.h)*l,b=1/(t*e.width),g=1/(t*e.height);o.bScis=!1,o.batch.push(u,c,f,c,f,p,u,p,u*b,1-c*g,f*b,1-p*g,4294967295,o.slotOf(e)),o.flush()}post(r){return r==="color"?this.colorProg??(this.colorProg=this.r.build(Ao(this.colorN))):this.blurProg??(this.blurProg=this.r.build(So()))}linear(r,e){let t=this.r,n=t.gl;t.bindTex(t.layerTex.get(r)??null,0);let i=e?n.LINEAR:n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,i),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,i)}chain(r,e,t){let n=this.r,i=this.steps,o=n.scale,a=n.maxBlur,l=0;for(let p=0;p<t.length;p++){let b=t[p];if(b.enabled)if(b.kind===1&&b.toMatrix){(!l||i[l-1]!==null)&&(i[l]=null,(!this.mats[l]||this.mats[l].length<20*this.colorN)&&(this.mats[l]=new Float32Array(20*this.colorN)),this.counts[l]=0,l++);let g=this.mats[l-1],m=this.counts[l-1];if(m<this.colorN)b.toMatrix(this.fm),g.set(this.fm,m*20),this.counts[l-1]=m+1;else{let d=(m-1)*20;for(let v=0;v<20;v++)this.fm2[v]=g[d+v];b.toMatrix(this.fm),To(this.fm2,this.fm,this.fm3),g.set(this.fm2,d)}}else b.kind===4?this.userProg(b.source,!0)?i[l++]=b:n.skipped++:b.kind===2?Math.min(b.radius,a)*o>=.25&&(i[l++]=b):b.kind===3?i[l++]=b:n.skipped++}if(!l)return!1;let u=n.gl,c=r,f=-1;for(let p=0;p<l;p++){let b=p===l-1,g=f===0?1:0,m=b?null:this.scratch(1,g);if(!b&&!m)break;let d=i[p];if(d===null){let v=this.post("color");n.use(v);let x=this.mats[p],S=this.counts[p],w=this.m16,A=this.o4;for(let E=0;E<S;E++)for(let R=0;R<4;R++){for(let C=0;C<4;C++)w[E*16+C*4+R]=x[E*20+R*5+C];A[E*4+R]=x[E*20+R*5+4]}u.uniformMatrix4fv(n.u(v,"uM"),!1,w),u.uniform4fv(n.u(v,"uO"),A),u.uniform1i(n.u(v,"uK"),S),m?this.pass(v,c,1,m):n.final(v,c,1,e)}else if(d.kind===2)this.blur(c,f<0,Math.min(d.radius,a)*o,m,e,null);else if(d.kind===3){let v=d,x=this.scratch(1,2);if(!x)break;this.blur(c,f<0,Math.max(Math.min(v.blur,a),0)*o,x,1,v);let S=m??(e<1?this.scratch(1,g):null);S?(this.pass(n.main,x.tex,1,S),this.pass(n.main,c,1,S,!0),m||n.final(n.main,S.tex,1,e)):(n.final(n.main,x.tex,1,1),n.final(n.main,c,1,1))}else{let v=d,x=this.userProg(v.source,!0);n.use(x);let S=n.canvas.width,w=n.canvas.height;u.uniform2f(n.u(x,"uResolution"),S,w),u.uniform1f(n.u(x,"uTime"),n.time),u.uniform4f(n.u(x,"uRect"),n.rx0/S,1-n.ry1/w,n.rx1/S,1-n.ry0/w);let A=v.uniforms;for(let E in A){let R=n.u(x,E);if(!R)continue;let C=A[E];typeof C=="number"?u.uniform1f(R,C):C.length===2?u.uniform2fv(R,C):C.length===3?u.uniform3fv(R,C):C.length===4?u.uniform4fv(R,C):C.length===1&&u.uniform1fv(R,C)}m?this.pass(x,c,1,m):n.final(x,c,1,e)}m&&(c=m.tex,f=g)}return n.remap(),!0}blur(r,e,t,n,i,o){let a=this.r,l=a.gl,u=this.post("blur"),c=1;for(;c<16&&t/c>8;)c*=2;e&&this.linear(r,!0);let f=r,p=1,b=Math.sqrt(Math.max(t*t-(c*c-1)/12,0))/c,g=t>=.25?this.tapsFor(b):this.tapsFor(0),m=!0;if(g>1){for(let v=2;v<=c&&m;v*=2){let x=this.scratch(v,0);x?(this.pass(a.main,f,p,x),f=x.tex,p=v):m=!1}let d=m?this.scratch(c,3):null;d&&(a.use(u),l.uniform2fv(a.u(u,"uTaps"),this.taps),l.uniform1i(a.u(u,"uN"),g),l.uniform2f(a.u(u,"uDir"),1/f.width,0),l.uniform2f(a.u(u,"uOff"),0,0),l.uniform1f(a.u(u,"uMode"),0),this.pass(u,f,p,d),f=d.tex)}if(a.use(u),l.uniform2fv(a.u(u,"uTaps"),this.taps),l.uniform1i(a.u(u,"uN"),g),l.uniform2f(a.u(u,"uDir"),0,1/f.height),o){let d=o.opacity,v=o.rgb;l.uniform4f(a.u(u,"uShadow"),(v>>16&255)/255*d,(v>>8&255)/255*d,(v&255)/255*d,d),l.uniform1f(a.u(u,"uMode"),1),l.uniform2f(a.u(u,"uOff"),-o.dx*a.scale/(p*f.width),o.dy*a.scale/(p*f.height))}else l.uniform1f(a.u(u,"uMode"),0),l.uniform2f(a.u(u,"uOff"),0,0);n?this.pass(u,f,p,n):a.final(u,f,p,i),e&&this.linear(r,!1)}tapsFor(r){let e=this.taps;if(e.fill(0),e[1]=1,r<.2)return 1;let t=Math.min(Math.ceil(3*r),(yr-1)*2),n=-1/(2*r*r),i=1,o=1;for(let a=1;a<=t;a+=2){let l=Math.exp(a*a*n),u=a+1<=t?Math.exp((a+1)*(a+1)*n):0,c=l+u;e[o*2]=(a*l+(a+1)*u)/c,e[o*2+1]=c,i+=2*c,o++}for(let a=0;a<o;a++)e[a*2+1]=e[a*2+1]/i;return o}};var Te=s=>Math.min(Math.max(s,0),1),he=s=>Math.max(s,0),Xe=class{constructor(){h(this,"enabled",!0);te.gl=ii,te.c2d=si}},ye=class extends Xe{constructor(e){super();h(this,"amount",e);h(this,"kind",1)}params(e,t){return e[t]=this.amount,t+1}};function gr(s,r,e){s.fill(0),s[0]=s[6]=s[12]=r,s[4]=s[9]=s[14]=e,s[18]=1}function xr(s,r){s.fill(0);for(let e=0;e<3;e++)for(let t=0;t<3;t++)s[e*5+t]=r[e*3+t];s[18]=1}var P=new Float64Array(9),dn=class extends ye{toMatrix(r){gr(r,he(this.amount),0)}css(){return`brightness(${he(this.amount)})`}},mn=class extends ye{toMatrix(r){let e=he(this.amount);gr(r,e,.5-.5*e)}css(){return`contrast(${he(this.amount)})`}},bn=class extends ye{toMatrix(r){let e=Te(this.amount);gr(r,1-2*e,e)}css(){return`invert(${Te(this.amount)})`}},yn=class extends ye{toMatrix(r){let e=he(this.amount);P[0]=.213+.787*e,P[1]=.715-.715*e,P[2]=.072-.072*e,P[3]=.213-.213*e,P[4]=.715+.285*e,P[5]=.072-.072*e,P[6]=.213-.213*e,P[7]=.715-.715*e,P[8]=.072+.928*e,xr(r,P)}css(){return`saturate(${he(this.amount)})`}},gn=class extends ye{toMatrix(r){let e=1-Te(this.amount);P[0]=.2126+.7874*e,P[1]=.7152-.7152*e,P[2]=.0722-.0722*e,P[3]=.2126-.2126*e,P[4]=.7152+.2848*e,P[5]=.0722-.0722*e,P[6]=.2126-.2126*e,P[7]=.7152-.7152*e,P[8]=.0722+.9278*e,xr(r,P)}css(){return`grayscale(${Te(this.amount)})`}},xn=class extends ye{toMatrix(r){let e=1-Te(this.amount);P[0]=.393+.607*e,P[1]=.769-.769*e,P[2]=.189-.189*e,P[3]=.349-.349*e,P[4]=.686+.314*e,P[5]=.168-.168*e,P[6]=.272-.272*e,P[7]=.534-.534*e,P[8]=.131+.869*e,xr(r,P)}css(){return`sepia(${Te(this.amount)})`}},vn=class extends ye{get angle(){return this.amount}set angle(r){this.amount=r}toMatrix(r){let e=this.amount*Math.PI/180,t=Math.cos(e),n=Math.sin(e);P[0]=.213+t*.787-n*.213,P[1]=.715-t*.715-n*.715,P[2]=.072-t*.072+n*.928,P[3]=.213-t*.213+n*.143,P[4]=.715+t*.285+n*.14,P[5]=.072-t*.072-n*.283,P[6]=.213-t*.213-n*.787,P[7]=.715-t*.715+n*.715,P[8]=.072+t*.928+n*.072,xr(r,P)}css(){return`hue-rotate(${this.amount}deg)`}},wn=class extends ye{constructor(e,t){super(t);h(this,"c",16777215);h(this,"cs","");this.color=e}get color(){return this.c}set color(e){this.c=K(e)[0],this.cs=Ue(this.c)}params(e,t){return e[t]=this.amount,e[t+1]=this.c,t+2}toMatrix(e){let t=Te(this.amount);gr(e,1-t,0),e[4]=(this.c>>16&255)/255*t,e[9]=(this.c>>8&255)/255*t,e[14]=(this.c&255)/255*t}css(){return null}paint2d(e,t,n,i,o){let a=Te(this.amount);a<=0||(e.save(),e.setTransform(1,0,0,1,0,0),e.globalAlpha=a,e.globalCompositeOperation="source-atop",e.fillStyle=this.cs,e.fillRect(t,n,i,o),e.restore())}},kn=class extends Xe{constructor(e){super();h(this,"kind",1);h(this,"values");if(e.length!==20)throw new Error(`colorMatrix: 20 numbers expected (4 rows of 5), got ${e.length}`);this.values=Array.from(e)}toMatrix(e){for(let t=0;t<20;t++)e[t]=this.values[t]??0}params(e,t){for(let n=0;n<20;n++)e[t+n]=this.values[n]??0;return t+20}css(e,t,n){return n?n(this.values):null}},An=class extends Xe{constructor(e){super();h(this,"radius",e);h(this,"kind",2)}params(e,t){return e[t]=this.radius,t+1}pad(e){return 3*Math.min(he(this.radius),e)}css(e,t){return`blur(${Math.min(he(this.radius),t)*e}px)`}},Sn=class extends Xe{constructor(e,t,n,i){super();h(this,"dx",e);h(this,"dy",t);h(this,"blur",n);h(this,"kind",3);h(this,"rgb",0);h(this,"a",1);this.color=i}get opacity(){return this.a}set opacity(e){this.a=Te(e)}get color(){return this.rgb}set color(e){let[t,n]=K(e);this.rgb=t,this.a=n}params(e,t){return e[t]=this.dx,e[t+1]=this.dy,e[t+2]=this.blur,e[t+3]=this.rgb,e[t+4]=this.a,t+5}pad(e){return 3*Math.min(he(this.blur),e)+Math.max(Math.abs(this.dx),Math.abs(this.dy))}css(e,t){return`drop-shadow(${this.dx*e}px ${this.dy*e}px ${2*Math.min(he(this.blur),t)*e}px ${Ue(this.rgb,this.opacity)})`}},Mo=`#ifdef GL_FRAGMENT_PRECISION_HIGH
86
86
  precision highp float;
87
87
  #else
88
88
  precision mediump float;
@@ -101,5 +101,5 @@ void main() {
101
101
  fabiUserMain();
102
102
  gl_FragColor *= vColor.a;
103
103
  }
104
- `,Tn=class extends Xe{constructor(e){super();h(this,"kind",4);h(this,"source");h(this,"uniforms",{});h(this,"padding");this.source=Eo(e.fragment),this.padding=e.padding??0;for(let t in e.uniforms??{}){let n=e.uniforms[t];this.uniforms[t]=typeof n=="number"?n:Float32Array.from(n)}}pad(){return he(this.padding)}},oi=(s,r=1)=>new wn(s,r),ai=s=>new mn(s),li=s=>new pn(s),ui=s=>new yn(s),ci=(s=1)=>new gn(s),hi=(s=1)=>new xn(s),fi=s=>new vn(s),di=(s=1)=>new bn(s),mi=s=>new kn(s),pi=s=>new An(s),bi=(s,r,e,t="rgba(0,0,0,0.5)")=>new Sn(s,r,e,t);function yi(s){let r=new Tn(s),e=te.live?.filters()?.check(r.source);if(e)throw new Error(`shader(): the fragment does not compile:
105
- ${e}`);return r}var Mn="x y rotation scaleX scaleY alpha visible blend tint z hitRadius clip mask filters".split(" "),xi="frameName _frame _w _h slice autoAnchor".split(" "),Fo="fps loop speed onComplete durations".split(" "),En=["anchorX","anchorY"],Ro=[...Mn,...xi,...Fo,...En],_o=[...Mn,...xi,...En],Co=[...Mn,...En],vi=s=>s instanceof ae?Ro:s instanceof re?_o:Co;function Lo(s){let r={},e=s;for(let t of vi(s))r[t]=e[t];return s instanceof fe&&(r.spec=s.spec),s instanceof pe&&(r.text=s.text,r.style=s.style),s instanceof ae&&(r.playing=s.playing),r}function gi(s,r){let e=s;s instanceof fe&&s.spec!==r.spec&&(s.spec=r.spec),s instanceof pe&&(s.text=r.text,s.style!==r.style&&(e._style=r.style,e.dirty=!0)),s instanceof ae&&s.gotoFrame(r.speed<0?s.frameCount-1:0);let t=s instanceof fe||s instanceof pe,n=vi(s);for(let i=0;i<n.length;i++){let o=n[i];(!t||o!=="_frame"&&o!=="frameName")&&(e[o]=r[o])}}var Dt=class{constructor(r,e={}){h(this,"factory",r);h(this,"opts",e);h(this,"stats",{live:0,free:0,created:0});h(this,"free",[]);h(this,"states",new Map);h(this,"dead",!1)}get(r){if(this.dead)throw new Error("[engine] nodePool.get() after destroy()");let e=this.free.pop();if(e){this.stats.free--,e._free=!1;let t=this.states.get(e);gi(e,t),e.visible=t.visible,e instanceof ae&&t.playing&&e.play()}else{if(e=this.factory(),!(e instanceof oe))throw new Error("[engine] a nodePool factory must return a node (engine.sprite, engine.shape, \u2026)");if(e._pool)throw new Error("[engine] a nodePool factory returned a node of another pool: make a new node in it");this.states.set(e,Lo(e)),e._pool=this,this.stats.created++}return this.stats.live++,r&&e.set(r),e}release(r){let e=this.states.get(r);if(!(!e||r.destroyed)&&!r._free){if(this.opts.max!==void 0&&this.free.length>=this.opts.max)return r.destroy();r.parent?.remove(r),r.kernel.tweens.stopAll(r),this.stats.live--,gi(r,e),r instanceof ae&&r.stop(),r.visible=!1,r._free=!0,this.opts.reset?.(r),this.free.push(r),this.stats.free++}}forget(r){let e=r;if(this.states.delete(e))if(e._free){let t=this.free.indexOf(e);t>=0&&(this.free[t]=this.free[this.free.length-1],this.free.pop()),this.stats.free--}else this.stats.live--}clear(){for(;this.free.length;)this.free[this.free.length-1].destroy()}destroy(){this.dead=!0;for(let r of[...this.states.keys()])r.destroy()}},wi=(s,r)=>new Dt(s,r);window.FabiEngine=Fn;})();
104
+ `,Tn=class extends Xe{constructor(e){super();h(this,"kind",4);h(this,"source");h(this,"uniforms",{});h(this,"padding");this.source=Eo(e.fragment),this.padding=e.padding??0;for(let t in e.uniforms??{}){let n=e.uniforms[t];this.uniforms[t]=typeof n=="number"?n:Float32Array.from(n)}}pad(){return he(this.padding)}},oi=(s,r=1)=>new wn(s,r),ai=s=>new dn(s),li=s=>new mn(s),ui=s=>new yn(s),ci=(s=1)=>new gn(s),hi=(s=1)=>new xn(s),fi=s=>new vn(s),pi=(s=1)=>new bn(s),di=s=>new kn(s),mi=s=>new An(s),bi=(s,r,e,t="rgba(0,0,0,0.5)")=>new Sn(s,r,e,t);function yi(s){let r=new Tn(s),e=te.live?.filters()?.check(r.source);if(e)throw new Error(`shader(): the fragment does not compile:
105
+ ${e}`);return r}var Mn="x y rotation scaleX scaleY alpha visible blend tint z hitRadius clip mask filters".split(" "),xi="frameName _frame _w _h slice autoAnchor".split(" "),Fo="fps loop speed onComplete durations".split(" "),En=["anchorX","anchorY"],Ro=[...Mn,...xi,...Fo,...En],_o=[...Mn,...xi,...En],Co=[...Mn,...En],vi=s=>s instanceof ae?Ro:s instanceof re?_o:Co;function Lo(s){let r={},e=s;for(let t of vi(s))r[t]=e[t];return s instanceof fe&&(r.spec=s.spec),s instanceof me&&(r.text=s.text,r.style=s.style),s instanceof ae&&(r.playing=s.playing),r}function gi(s,r){let e=s;s instanceof fe&&s.spec!==r.spec&&(s.spec=r.spec),s instanceof me&&(s.text=r.text,s.style!==r.style&&(e._style=r.style,e.dirty=!0)),s instanceof ae&&s.gotoFrame(r.speed<0?s.frameCount-1:0);let t=s instanceof fe||s instanceof me,n=vi(s);for(let i=0;i<n.length;i++){let o=n[i];(!t||o!=="_frame"&&o!=="frameName")&&(e[o]=r[o])}}var Dt=class{constructor(r,e={}){h(this,"factory",r);h(this,"opts",e);h(this,"stats",{live:0,free:0,created:0});h(this,"free",[]);h(this,"states",new Map);h(this,"dead",!1)}get(r){if(this.dead)throw new Error("[engine] nodePool.get() after destroy()");let e=this.free.pop();if(e){this.stats.free--,e._free=!1;let t=this.states.get(e);gi(e,t),e.visible=t.visible,e instanceof ae&&t.playing&&e.play()}else{if(e=this.factory(),!(e instanceof oe))throw new Error("[engine] a nodePool factory must return a node (engine.sprite, engine.shape, \u2026)");if(e._pool)throw new Error("[engine] a nodePool factory returned a node of another pool: make a new node in it");this.states.set(e,Lo(e)),e._pool=this,this.stats.created++}return this.stats.live++,r&&e.set(r),e}release(r){let e=this.states.get(r);if(!(!e||r.destroyed)&&!r._free){if(this.opts.max!==void 0&&this.free.length>=this.opts.max)return r.destroy();r.parent?.remove(r),r.kernel.tweens.stopAll(r),this.stats.live--,gi(r,e),r instanceof ae&&r.stop(),r.visible=!1,r._free=!0,this.opts.reset?.(r),this.free.push(r),this.stats.free++}}forget(r){let e=r;if(this.states.delete(e))if(e._free){let t=this.free.indexOf(e);t>=0&&(this.free[t]=this.free[this.free.length-1],this.free.pop()),this.stats.free--}else this.stats.live--}clear(){for(;this.free.length;)this.free[this.free.length-1].destroy()}destroy(){this.dead=!0;for(let r of[...this.states.keys()])r.destroy()}},wi=(s,r)=>new Dt(s,r);window.FabiEngine=Fn;})();