@fabiplay/engine 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fabi-play-engine.js +1 -105
- package/dist/fabi-play-engine.lite.js +1 -105
- package/dist/fabi-play-engine.lite.umd.js +1038 -972
- package/dist/fabi-play-engine.lite.umd.min.js +1 -105
- package/dist/fabi-play-engine.umd.js +1225 -1131
- package/dist/fabi-play-engine.umd.min.js +1 -105
- package/dist/index.development.js +2 -2
- package/dist/index.js +1 -1
- package/dist/integrity.json +7 -7
- package/package.json +5 -5
|
@@ -1,105 +1 @@
|
|
|
1
|
-
"use strict";(()=>{var qn=Object.defineProperty;var zi=(s,r,e)=>r in s?qn(s,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[r]=e;var $i=(s,r)=>{for(var e in r)qn(s,e,{get:r[e],enumerable:!0})};var h=(s,r,e)=>zi(s,typeof r!="symbol"?r+"":r,e);var Pn={};$i(Pn,{AnimatedSprite:()=>le,Atlas:()=>Ne,AvatarPainter:()=>We,AvatarsNode:()=>Gt,BitmapFont:()=>pt,DEFAULT_FONT:()=>en,EASE:()=>Le,Group:()=>Ve,HALO:()=>Xe,MAX_LAYERS:()=>Ft,NameTags:()=>Be,Node:()=>ae,NodePool:()=>Ut,Particles:()=>rt,STAGE_HEIGHT:()=>j,Shape:()=>pe,ShelfPacker:()=>Lt,Sound:()=>bt,Sprite:()=>ne,TIERS:()=>ye,Text:()=>be,Timeline:()=>yt,Tweens:()=>gt,avatarPortrait:()=>js,blur:()=>Ti,brightness:()=>yi,colorMatrix:()=>Si,contrast:()=>gi,createAvatarRenderer:()=>Xs,createEngine:()=>ci,createRenderer:()=>ct,dropShadow:()=>Mi,grayscale:()=>vi,handsOf:()=>gr,hits:()=>Bt,hueRotate:()=>Ai,invert:()=>ki,nodePool:()=>Ci,packColor:()=>Ce,parseBMFont:()=>dt,parseColor:()=>K,pickTier:()=>wr,playerColor:()=>mt,rendererOrder:()=>Jr,rng:()=>os,saturate:()=>xi,sepia:()=>wi,shader:()=>Ei,shapeBounds:()=>br,tier:()=>Te,tint:()=>bi,touching:()=>xr,wrists:()=>sn});var Vi=33,ee={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 Wi=4,St=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"];var Xi={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},Qo=Xi["6-8"];var Ir=(s,r)=>s?{x:s.x+r.x*s.w,y:s.y+r.y*s.h}:{x:r.x,y:r.y},ji=.5,Jt={left:1.6,top:1.6,w:3.2,h:3},qi=1.2;function Yn(s,r,e={}){let t=Array.isArray(s)?s:s.body;if(!Array.isArray(t))return null;let n=r==="left"?ee.leftWrist:ee.rightWrist,i=x=>kt(t[x*3])&&kt(t[x*3+1])&&(t[x*3+2]??0)>=ji?x:-1;if(i(n)<0)return null;let o=t[n*3],a=t[n*3+1];if(e.orientation!=="portrait")return Ir(e.view,{x:o,y:a});if(i(ee.leftShoulder)<0||i(ee.rightShoulder)<0)return null;let l=ee.leftShoulder*3,u=ee.rightShoulder*3,c=(t[l]+t[u])/2,f=(t[l+1]+t[u+1])/2,p=ee.leftHip*3,b=ee.rightHip*3,y=(t[p]+t[b])/2,m=(t[p+1]+t[b+1])/2,d=kt(y)&&kt(m)?Math.hypot(y-c,m-f):0;return(i(ee.leftHip)<0||i(ee.rightHip)<0)&&(d=Math.max(d,qi*Math.hypot(t[l]-t[u],t[l+1]-t[u+1]))),d=Math.max(d,.01),{x:Kn((o-c+Jt.left*d)/(Jt.w*d)),y:Kn((a-f+Jt.top*d)/(Jt.h*d))}}var Ki=300,Ye=class{constructor(r=Ki){h(this,"holdMs",r);h(this,"last",new Map)}static key(r,e){return r*2+(e==="right"?1:0)}at(r,e,t){let n=this.last.get(r);return e?(n?(n.x=e.x,n.y=e.y,n.t=t):this.last.set(r,{x:e.x,y:e.y,t}),e):n?t-n.t<=this.holdMs?{x:n.x,y:n.y}:(this.last.delete(r),null):null}clear(){this.last.clear()}},Yi=.25,Qn=Object.freeze({top:0,bottom:0,left:0,right:0});function Zn(s){if(!Qi(s))return;let r=e=>kt(e)?Math.min(Math.max(e,0),Yi):0;return{top:r(s.top),bottom:r(s.bottom),left:r(s.left),right:r(s.right)}}var Zo=16/9;var Qi=s=>typeof s=="object"&&s!==null&&!Array.isArray(s),kt=s=>typeof s=="number"&&Number.isFinite(s),Kn=s=>Math.min(Math.max(s,0),1);var Zi=12,Ji=Vi*4,eo=s=>Zi+s*Ji,Jo=eo(Wi);var to=s=>s.startsWith("fabi-play.")?`fablee-play.${s.slice(10)}`:null;function Jn(s,r,e=to(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 es=globalThis.FabiPlay?.avatars;if(!es)throw new Error("[engine] fabi-play-engine.lite.js needs fabi-play.js (with FabiPlay.avatars) loaded before it");var{avatarById:Qe,avatarShapes:ts,BAND_BODY:sa,DEFAULT_AVATAR:Ze,drawShapes:Br,frameOf:rs,iconShapes:ns}=es;var we=()=>Float64Array.of(1,0,0,1,0,0);function te(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],y=r[1],m=r[2],d=r[3];return s[0]=b*u+m*c,s[1]=y*u+d*c,s[2]=b*f+m*p,s[3]=y*f+d*p,s[4]=b*e+m*t+r[4],s[5]=y*e+d*t+r[5],s}function is(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 ss={white:16777215,black:0,red:16711680,transparent:0},Tt=new Map;function K(s){if(typeof s=="number")return[s&16777215,1];let r=Tt.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=[(Dr(i)<<16|Dr(o)<<8|Dr(a))>>>0,Math.min(Math.max(l,0),1)]}else if(t in ss)e=[ss[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 Tt.set(s,e=K(i)),e}}return Tt.size>512&&Tt.clear(),Tt.set(s,e),e}var Dr=s=>Math.min(Math.max(Math.round(s),0),255);function Ce(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 He=(s,r=1)=>`rgba(${s>>16&255},${s>>8&255},${s&255},${r})`;function Gr(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 Le={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 os(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},Pe=[],ro="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function as(s){let r=T;for(let t of ro){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++;Pe.length<s;)Pe.push(null)}function Hr(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}as(256);Hr(0);T.flags[0]=0;Hr(1);T.flags[1]=0;function ls(){let s;if(T.freeCount){s=T.free[T.freeHead],T.freeHead=(T.freeHead+1)%T.cap,T.freeCount--;let r=Pe[s];r&&(r._i=0,r._g=-1,Pe[s]=null)}else T.top===T.cap&&as(T.cap*2),s=T.top++;return Hr(s),s}function zr(s,r){er(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&&(Pe[s]=r),T.free[(T.freeHead+T.freeCount)%T.cap]=s,T.freeCount++)}function us(s){for(let r=0;r<Pe.length;r++){let e=Pe[r];e&&s(e)&&(e._i=0,e._g=-1,Pe[r]=null)}}function cs(s,r){er(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 er(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 Mt={root:-1,gen:-1,world:new Float64Array(6)};function hs(s){let r=++T.pass,e=T.world,t=s*6,n=Mt.world,i=Mt.root!==s||Mt.gen!==T.gen[s];for(let o=0;o<6;o++)n[o]!==e[t+o]&&(i=!0),n[o]=e[t+o];Mt.root=s,Mt.gen=T.gen[s],T.stamp[s]=i?r:r-1}function fs(s){T.stamp[s]=T.pass}function ps(s){for(let r=T.first[s];r>=0;){let e=T.next[r];ps(r),r=e}zr(s)}var Ur=typeof FinalizationRegistry=="function"?new FinalizationRegistry(s=>T.gen[s.i]===s.g&&ps(s.i)):null;function $r(s){s._reg||!Ur||(s._reg=!0,Ur.register(s,{i:s._i,g:s._g},s))}function ds(s){s._reg&&Ur.unregister(s)}function Et(s){if(s){for(let r=0;r<s.length;r++)if(s[r].enabled)return!0}return!1}function ms(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 re={gl:null,c2d:null,live:null};var B=new Float64Array(3),Ft=4,no=1,Rt=()=>no++;var W=we(),R=T,ae=class{constructor(r){h(this,"kernel",r);h(this,"_i",ls());h(this,"_g",R.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 R.x[this._i]}set x(r){let e=this._i||1;R.x[e]=r,R.moved[e]=1}get y(){return R.y[this._i]}set y(r){let e=this._i||1;R.y[e]=r,R.moved[e]=1}get rotation(){return R.rot[this._i]}set rotation(r){let e=this._i||1;R.rot[e]=r,R.dirty[e]=R.moved[e]=1}get scaleX(){return R.sx[this._i]}set scaleX(r){let e=this._i||1;R.sx[e]=r,R.dirty[e]=R.moved[e]=1}get scaleY(){return R.sy[this._i]}set scaleY(r){let e=this._i||1;R.sy[e]=r,R.dirty[e]=R.moved[e]=1}get alpha(){return R.alpha[this._i]}set alpha(r){let e=this._i||1;R.alpha[e]=r,R.moved[e]=1}get visible(){return(R.flags[this._i]&1)!==0}set visible(r){let e=this._i||1;r?R.flags[e]=R.flags[e]|1:R.flags[e]=R.flags[e]&-2,R.moved[e]=1}get destroyed(){return R.gen[this._i]!==this._g}get world(){let r=this._i||1;return(this._wi!==r||this._we!==R.epoch)&&(this._wv=R.world.subarray(r*6,r*6+6),this._wi=r,this._we=R.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 R.tint[this._i]}set tint(r){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),zr(this._i,this),ds(this),this.kernel.tweens.stopAll(this),this._pool?.forget(this))}updateWorld(){let r=this.parent?this.parent.updateWorld():null;return te(this.world,r,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(r,e,t){}};function xs(s){us(r=>r.kernel===s)}var Vr=!1,bs=Object.freeze([]),Ve=class s extends ae{constructor(e){super(e);h(this,"children",bs);h(this,"sortDirty",!1);h(this,"dead",!1);$r(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&&cs(e._i,this._i),this.children===bs&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||$r(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||er(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(Vr)return R.parent[this._i]<0&&!this.destroyed&&fs(this._i),this.drawChildren(e,t,n);Vr=!0;try{this.destroyed||hs(this._i),this.drawChildren(e,t,n)}finally{Vr=!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=R.stamp[o]===R.pass;for(let l=0;l<i.length;l++){let u=i[l],c=u._i,f=R.alpha[c];if(R.gen[c]!==u._g||!(R.flags[c]&1)||f<=0)continue;if(a||R.moved[c]){R.moved[c]=0,R.stamp[c]=R.pass;let y,m,d,x;if(R.dirty[c]){R.dirty[c]=0;let H=R.rot[c],U=H?Math.cos(H):1,D=H?Math.sin(H):0,xe=R.sx[c],Fe=R.sy[c];R.la[c]=y=U*xe,R.lb[c]=m=D*xe,R.lc[c]=d=-D*Fe,R.ld[c]=x=U*Fe}else y=R.la[c],m=R.lb[c],d=R.lc[c],x=R.ld[c];let v=R.world,k=R.x[c],w=R.y[c],M=c*6,S=o*6,_=v[S],C=v[S+1],P=v[S+2],z=v[S+3];v[M]=_*y+P*m,v[M+1]=C*y+z*m,v[M+2]=_*d+P*x,v[M+3]=C*d+z*x,v[M+4]=_*k+P*w+v[S+4],v[M+5]=C*k+z*w+v[S+5]}let p=t*f,b=Gr(n,R.tint[c]);u.clip||u.mask||u.filters?vs(e,u,p,b):u.draw(e,p,b)}}},Q=new Float64Array(128),ze=0,Wr=new Float64Array(8);function Xr(s,r,e,t){r.clip||r.mask||r.filters?vs(s,r,e,t):r.draw(s,e,t)}function vs(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&&ze<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],y=i[3]*(o.y+o.height)+i[5],m=Math.min(f,p),d=Math.max(f,p),x=Math.min(b,y),v=Math.max(b,y);if(ze){let w=(ze-1)*4;m=Math.max(m,Q[w]),x=Math.max(x,Q[w+1]),d=Math.min(d,Q[w+2]),v=Math.min(v,Q[w+3])}let k=ze++*4;Q[k]=m,Q[k+1]=x,Q[k+2]=d,Q[k+3]=v,n.clip(m,x,Math.max(d-m,0),Math.max(v-x,0)),l=!0}else a=!0;let u=r.mask&&r.mask.visible?r.mask:null,c=Et(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(),te(u.world,i,u.x,u.y,u.rotation,u.scaleX,u.scaleY),Xr(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;Wr[f*2]=i[0]*p+i[2]*b+i[4],Wr[f*2+1]=i[1]*p+i[3]*b+i[5]}n.polygon(Wr,4,16777215,1),n.endLayer(1)}}finally{if(l)if(ze--,ze){let f=(ze-1)*4;n.clip(Q[f],Q[f+1],Q[f+2]-Q[f],Q[f+3]-Q[f+1])}else n.unclip()}}var ne=class extends ae{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){tt[0]=this._w??(e.sw??e.w)/e.scale-e.margin*2,tt[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=tt;this.sizeQ(i),o[2]=this.anchorX,o[3]=this.anchorY,o[4]=t,so(e,i,this.world,this.slice,n,this.blend)}},Je=new Float64Array(12),et=new Float64Array(12),_t={x:0,y:0,w:0,h:0};function ys(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 tt=new Float64Array(5);function so(s,r,e,t,n,i){let o=tt,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,M=(r.sh??r.h)/r.scale-r.margin*2,S=w>0?a/w:1,_=M>0?l/M:1,C=-u*a+((r.tx??0)/r.scale-r.margin)*S,P=-c*l+((r.ty??0)/r.scale-r.margin)*_;Ct(e,C,P),B[0]=r.w/r.scale*S,B[1]=r.h/r.scale*_,B[2]=f,s.r.quadQ(p,r,W,n,i);return}let y=r.tx??0,m=r.ty??0,d=(r.sw??r.w)-r.w-y,x=(r.sh??r.h)-r.h-m,v=-u*a-r.margin+y/r.scale,k=-c*l-r.margin+m/r.scale;if(ys(Je,a+r.margin*2-(y+d)/r.scale,(typeof b=="number"?b:b[3])-y,(typeof b=="number"?b:b[1])-d,r.w,r.scale),ys(et,l+r.margin*2-(m+x)/r.scale,(typeof b=="number"?b:b[0])-m,(typeof b=="number"?b:b[2])-x,r.h,r.scale),Ct(e,v,k),B[2]=f,!s.r.nineQ?.(p,r,Je,et,W,n,i))for(let w=0;w<12;w+=4){let M=et[w+1],S=et[w+3];if(!(M<=0||S<=0))for(let _=0;_<12;_+=4){let C=Je[_+1],P=Je[_+3];C<=0||P<=0||(_t.x=r.x+Je[_+2],_t.y=r.y+et[w+2],_t.w=P,_t.h=S,Ct(e,v+Je[_],k+et[w]),B[0]=C,B[1]=M,B[2]=f,s.r.quadQ(p,_t,W,n,i))}}}function Ct(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 pe=class extends ne{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.autoAnchor&&this.useFrameAnchor(),this.baked)}frameNow(){return this.bake().frame}sizeQ(){let e=this.bake();tt[0]=this._w??e.w,tt[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}},gs=(s,r,e)=>s===void 0?r:typeof s=="number"?s:s[0]+(s[1]-s[0])*e(),$e=class $e extends ae{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*$e.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=$e.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,x=1/0;for(let v=0;v<this.max;v++){let k=this.f[v*o+5]-this.f[v*o+4];k<x&&(x=k,d=v)}c=d}else this.count++;let f=(i.angle??0)+(i.spread===void 0?a()*Math.PI*2:(a()-.5)*i.spread),p=gs(i.speed,200,a),b=Array.isArray(i.scale)?i.scale[0]:i.scale??1,y=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(gs(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]=y,this.f[m+10]=i.alpha??1,this.tints[c]=l}}update(e){let t=$e.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=$e.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],y=a[p+8]+(a[p+9]-a[p+8])*b,m=t*a[p+10]*(1-b*b),d=a[p+6],x=Math.cos(d)*y,v=Math.sin(d)*y,k=a[p],w=a[p+1],M=l[0],S=l[1],_=l[2],C=l[3],P=M*x+_*v,z=S*x+C*v,H=_*x-M*v,U=C*x-S*v;W[0]=P,W[1]=z,W[2]=H,W[3]=U,W[4]=M*k+_*w+l[4]-(P*u+H*c)/2,W[5]=S*k+C*w+l[5]-(z*u+U*c)/2,B[0]=u,B[1]=c,B[2]=m,e.r.quadQ(e.tex(i.surface),i,W,Gr(n,this.tints[f]),this.blend)}}};h($e,"W",11);var rt=$e;var le=class extends ne{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)}},ws=(s,r)=>s.localeCompare(r,void 0,{numeric:!0});var Lt=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),slot:l}}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}}},nt=s=>({source:s,texture:null,pending:[]}),Ne=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;if(c.slot){let f=c.slot;u.ctx.clearRect(f.x,f.y,f.w,f.h);let p=document.createElement("canvas");p.width=f.w,p.height=f.h,p.getContext("2d").drawImage(r,c.x-f.x,c.y-f.y),u.surface.pending.push([p,f.x,f.y])}else u.surface.pending.push([r,c.x,c.y]);return u.ctx.drawImage(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=nt(t),o={surface:i,packer:new Lt(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 io=()=>globalThis.FabiPlay,rr=class{constructor(){h(this,"amount",.5)}setLocal(r){this.amount=r?.8:.5}get defaultAmount(){return this.amount}posed(r,e,t,n=!0){let i={id:r,body:e};return io()?.smoothedBody(i,{smooth:t<1?t:!1,interpolate:n})??e}};var Ss=new Float64Array(1),As=new Int32Array(Ss.buffer),st=(s,r)=>(s=Math.imul(s^r,1540483477),s^s>>>15);function ke(s,r=2538058380){return s!==s?st(r,2146959360):(Ss[0]=s===0?0:s,st(st(r,As[0]),As[1]))}function ks(s,r=2166136261){for(let e=0;e<s.length;e++)r=Math.imul(r^s.charCodeAt(e),16777619);return r}function he(s){switch(typeof s){case"number":return ke(s);case"string":return ks(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=st(t,typeof i=="number"?ke(i):he(i))}return t}let r=1359893119,e=s;for(let t in e){let n=e[t];n!==void 0&&(r=r+st(ks(t),he(n))|0)}return st(r,2600822924)}default:return 0}}function it(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]&&!it(i[a],o[a]))return!1;return!0}let t=s,n=r;for(let i in t)if(t[i]!==void 0&&!it(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 Pt(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return s.map(Pt);if(s instanceof Float64Array)return s.slice();let r={};for(let e in s)s[e]!==void 0&&(r[e]=Pt(s[e]));return r}var ot=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=he(r)){let t=this.buckets.get(e);if(t){for(let n=0;n<t.length;n++)if(it(t[n].key,r))return t[n].value}}set(r,e,t=he(r)){let n=this.buckets.get(t);if(n){for(let i of n)if(it(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:Pt(r),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}};var jr=0,Ts=1,nr=2,qr=3,at=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*(Ft+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<nr&&(this.mute||this.real>=Ft||!this.pushLayer())&&(r+=2),r===qr)this.mute++;else if(r!==nr){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<nr}beginLayer(){return this.push(jr)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===jr?Ts:qr)}endLayer(r,e){if(!this.sp)return;let t=this.stack[--this.sp];if(t===qr){if(this.mute--,!this.sp)return;t=this.stack[--this.sp]}if(t===Ts){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===nr)Et(e)&&(this.skipped+=e.length);else if(t===jr){let n=--this.real,i=Et(e)?e:null,o=this.popLayer();if(this.area(n,i?ms(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 oo=256,Ms=8<<20,se=new Float64Array(32),ie={x:0,y:0,w:0,h:0};function ao(s){if(typeof s.filter!="string")return!1;s.filter="blur(1px)";let r=s.filter==="blur(1px)";return s.filter="none",r}function lt(s){let r=s.getContext("2d",{alpha:!0});return r?new Kr(s,r):null}var Kr=class extends at{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:ao(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:Rt(),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=He(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 y=a[0]*u,m=a[1]*u,d=a[2]*c,x=a[3]*c;this.grow(a[4]+Math.min(0,y,d,y+d),a[5]+Math.min(0,m,x,m+x),a[4]+Math.max(0,y,d,y+d),a[5]+Math.max(0,m,x,m+x))}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),y=(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(y.width<f&&(y.width=f),y.height<p&&(y.height=p),!this.hit){b.clearRect(0,0,f+2,p+2);for(let x=0;x<12;x+=4){let v=Math.round(i[x]*p/c),k=Math.round((i[x]+i[x+1])*p/c);for(let w=0;w<12;w+=4){let M=Math.round(n[w]*f/u),S=Math.round((n[w]+n[w+1])*f/u);ie.x=t.x+n[w+2],ie.y=t.y+i[x+2],ie.w=n[w+3],ie.h=i[x+3],!(S<=M||k<=v||ie.w<=0||ie.h<=0)&&(a===16777215?b.drawImage(e.source,ie.x,ie.y,ie.w,ie.h,M,v,S-M,k-v):b.drawImage(this.tint(e,ie,a),0,0,ie.w,ie.h,M,v,S-M,k-v))}}}return B[0]=u,B[1]=c,this.blit(y,0,0,f,p,o,l),!0}kept(e,t,n,i,o,a,l){se[0]=e.id,se[1]=t.x,se[2]=t.y,se[3]=t.w,se[4]=t.h,se[5]=o,se[6]=a,se[7]=l,se.set(n,8),se.set(i,20);let u=he(se),c=this.nines.get(u);if(this.hit=!1,c)return it(c.key,se)?(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>Ms)return null;let y;for(;this.ninePx+b>Ms;){let x;for(let w of this.nines.values())w.used<this.frame-1&&!(x&&x.used<=w.used)&&(x=w);if(!x)return null;let v=x.ctx.canvas,k=!y&&v.width>=o&&v.height>=a&&v.width*v.height<=2*b;this.dropNine(x,k),k&&(y=x.ctx)}let m=y??document.createElement("canvas").getContext("2d"),d=m.canvas;return y||(d.width=o,d.height=a),this.ninePx+=d.width*d.height,this.nines.set(u,{key:Pt(se),ctx:m,used:this.frame}),m}dropNine(e,t=!1){this.nines.delete(he(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>=oo&&(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=He(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),He(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&&re.c2d?this.fxr??(this.fxr=re.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 sr=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,y){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]=y}else{let d=this.quads*6*4;this.vertex(d,r,e,u,c,b,y),this.vertex(d+6,t,n,f,c,b,y),this.vertex(d+12,i,o,f,p,b,y),this.vertex(d+18,a,l,u,p,b,y)}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 Es(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},Os=[2,2,4,6,0],lo={M:0,L:1,Q:2,C:3,Z:4};function cr(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 ir=new Map;function uo(s){if(typeof s!="string")return s;let r=ir.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=lo[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=Os[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 ir.size>256&&ir.clear(),ir.set(s,r),r}var Ie={subs:[],count:0},Yr=null,Oe=null;function or(s,r){let e=Oe;e||(e=Ie.subs[Ie.count]??null,e||Ie.subs.push(e={pts:new Float64Array(64),n:0,closed:!1}),e.n=0,e.closed=!1,Ie.count++,Oe=e);let t=e.n*2;t+2>e.pts.length&&(e.pts=cr(e.pts,t+2));let n=Yr;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 hr(s,r=null,e=1,t=6){let n=uo(s);Ie.count=0,Oe=null,Yr=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)Oe=null,i=a=p[c],o=l=p[c+1],or(i,o);else if(f===Z.L)i=p[c],o=p[c+1],or(i,o);else if(f===Z.Q){let b=p[c],y=p[c+1],m=p[c+2],d=p[c+3],x=Fs((de(b-i,y-o)+de(m-b,d-y))*u);for(let v=1;v<=x;v++){let k=v/x,w=1-k;or(w*w*i+2*w*k*b+k*k*m,w*w*o+2*w*k*y+k*k*d)}i=m,o=d}else if(f===Z.C){let b=p[c],y=p[c+1],m=p[c+2],d=p[c+3],x=p[c+4],v=p[c+5],k=Fs((de(b-i,y-o)+de(m-b,d-y)+de(x-m,v-d))*u);for(let w=1;w<=k;w++){let M=w/k,S=1-M,_=S*S*S,C=3*S*S*M,P=3*S*M*M,z=M*M*M;or(_*i+C*b+P*m+z*x,_*o+C*y+P*d+z*v)}i=x,o=v}else if(f===Z.Z){Oe&&(Oe.closed=!0),Oe=null,i=a,o=l;continue}else break;c+=Os[f]}Oe=null,Yr=null;for(let c=0;c<Ie.count;c++){let f=Ie.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 Ie}var de=(s,r)=>Math.sqrt(s*s+r*r),Fs=s=>Math.min(Math.max(Math.ceil(s),2),24);function co(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 ar=new Int32Array(64),lr=(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 Is(s,r,e){if(r<3)return 0;ar.length<r&&(ar=new Int32Array(Math.max(r,ar.length*2)));let t=ar,n=r,i=0;for(let u=0;u<r;u++)t[u]=u;let o=co(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=lr(s,o,u,c,f)>0;if(p)for(let b=0;b<n;b++){let y=t[b];if(!(y===u||y===c||y===f)&&lr(s,o,u,c,y)>=0&&lr(s,o,c,f,y)>=0&&lr(s,o,f,u,y)>=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 ho=.85,ur=new Float64Array(64),Rs=new Float64Array(64),_s=new Float64Array(64),Cs=new Float64Array(64),Ls=new Float64Array(64),Ps=new Float64Array(64),Ns=new Uint8Array(64),Nt=new Float64Array(8);function Bs(s,r,e,t,n,i){let o=Nt;if(ur.length<r){let d=Math.max(r,ur.length*2);ur=new Float64Array(d),Rs=new Float64Array(d),_s=new Float64Array(d),Cs=new Float64Array(d),Ls=new Float64Array(d),Ps=new Float64Array(d),Ns=new Uint8Array(d)}let a=ur,l=Rs,u=0;for(let d=0;d<r;d++){let x=s[d*2],v=s[d*2+1];!Number.isFinite(x)||!Number.isFinite(v)||u&&Math.abs(a[u-1]-x)<.001&&Math.abs(l[u-1]-v)<.001||(a[u]=x,l[u]=v,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=_s,p=Cs;for(let d=0;d<c;d++){let x=(d+1)%u,v=a[x]-a[d],k=l[x]-l[d],w=de(v,k)||1;f[d]=-k/w,p[d]=v/w}let b=Ls,y=Ps,m=Ns;for(let d=0;d<u;d++){let x=t?(d-1+c)%c:d-1,v=d<c?d:-1;if(m[d]=1,x<0||v<0||f[x]*f[v]+p[x]*p[v]<ho)continue;let w=f[x]+f[v],M=p[x]+p[v],S=de(w,M)||1;w/=S,M/=S;let _=e/Math.max(w*f[v]+M*p[v],.5);b[d]=w*_,y[d]=M*_,m[d]=0}for(let d=0;d<c;d++){let x=(d+1)%u,v=m[d]?f[d]*e:b[d],k=m[d]?p[d]*e:y[d],w=m[x]?f[d]*e:b[x],M=m[x]?p[d]*e:y[x];o[0]=a[d]+v,o[1]=l[d]+k,o[2]=a[x]+w,o[3]=l[x]+M,o[4]=a[x]-w,o[5]=l[x]-M,o[6]=a[d]-v,o[7]=l[d]-k,n()}for(let d=0;d<u;d++)m[d]&&(o[0]=a[d],o[1]=l[d],i())}function Qr(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 fr=[{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}],pr=[4,8,16,32,64,128].map((s,r)=>({x:r*4,y:128,w:4,h:s,r:s/2-1})),Se={x:248,y:248,w:8,h:8},Gs=fr.map(s=>s.r*2),Us=pr.map(s=>s.r*2),Ds=(s,r)=>Math.min(Math.max(s+.5-r,0),1);function fo(){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 fr){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,Ds(e.r,Math.hypot(i+.5-t,n+.5-t)))}for(let e of pr){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,Ds(e.r,Math.abs(n+.5-t)))}for(let e=0;e<Se.h;e++)for(let t=0;t<Se.w;t++)r(Se.x+t,Se.y+e,1);return s}function Hs(){let s=document.createElement("canvas");return s.width=s.height=256,s.getContext("2d").putImageData(new ImageData(fo(),256,256),0,0),s}var zs=8,dr=`
|
|
2
|
-
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
3
|
-
precision highp float;
|
|
4
|
-
#else
|
|
5
|
-
precision mediump float;
|
|
6
|
-
#endif
|
|
7
|
-
`,yo=s=>`${dr}
|
|
8
|
-
uniform sampler2D uTex[${s}];
|
|
9
|
-
varying vec2 vUv;
|
|
10
|
-
varying vec4 vColor;
|
|
11
|
-
varying float vSlot;
|
|
12
|
-
void main() {
|
|
13
|
-
vec4 c;
|
|
14
|
-
${Array.from({length:s},(r,e)=>e===s-1?`c = texture2D(uTex[${e}], vUv);`:`if (vSlot < ${e}.5) c = texture2D(uTex[${e}], vUv); else `).join(`
|
|
15
|
-
`)}
|
|
16
|
-
gl_FragColor = c * vColor;
|
|
17
|
-
}`,go=`
|
|
18
|
-
attribute vec2 aPos;
|
|
19
|
-
attribute vec2 aUv;
|
|
20
|
-
attribute vec4 aColor;
|
|
21
|
-
attribute float aSlot;
|
|
22
|
-
uniform vec2 uScale;
|
|
23
|
-
varying vec2 vUv;
|
|
24
|
-
varying vec4 vColor;
|
|
25
|
-
varying float vSlot;
|
|
26
|
-
void main() {
|
|
27
|
-
vUv = aUv;
|
|
28
|
-
vColor = aColor;
|
|
29
|
-
vSlot = aSlot;
|
|
30
|
-
gl_Position = vec4(aPos * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
|
|
31
|
-
}`,xo=`
|
|
32
|
-
attribute vec4 aCorner;
|
|
33
|
-
attribute vec4 aP01;
|
|
34
|
-
attribute vec4 aP23;
|
|
35
|
-
attribute vec4 aUvRect;
|
|
36
|
-
attribute vec4 aColor;
|
|
37
|
-
attribute float aSlot;
|
|
38
|
-
uniform vec2 uScale;
|
|
39
|
-
varying vec2 vUv;
|
|
40
|
-
varying vec4 vColor;
|
|
41
|
-
varying float vSlot;
|
|
42
|
-
void main() {
|
|
43
|
-
vec2 p = aP01.xy * aCorner.x + aP01.zw * aCorner.y + aP23.xy * aCorner.z + aP23.zw * aCorner.w;
|
|
44
|
-
vUv = vec2(mix(aUvRect.x, aUvRect.z, aCorner.y + aCorner.z), mix(aUvRect.y, aUvRect.w, aCorner.z + aCorner.w));
|
|
45
|
-
vColor = aColor;
|
|
46
|
-
vSlot = aSlot;
|
|
47
|
-
gl_Position = vec4(p * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
|
|
48
|
-
}`,vo={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},wo=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],Ao=["aPos","aUv","aColor","aSlot"];function Vs(s,r,e={}){let t={...vo,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 Zr(s,n,r,e)}catch(i){return console.warn("[engine] WebGL setup failed:",i),n.getExtension("WEBGL_lose_context")?.loseContext(),null}}var Zr=class extends at{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(zs).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(Nt),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(Nt[0],Nt[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(Hs()),re.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(zs,n)),o=this.inst!==null;this.vsrc=o?xo:go,this.attrs=o?wo:Ao,this.main=this.cur=this.build(yo(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 sr(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,Es(o?1:8192),e.STATIC_DRAW);let l=f=>e.getAttribLocation(a,f),u=(f,p,b,y,m,d,x)=>{let v=l(f);v<0||(e.enableVertexAttribArray(v),e.vertexAttribPointer(v,p,b,y,m,d),this.inst&&this.inst.divisor(v,x))};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:Rt(),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=$s(t,t.VERTEX_SHADER,this.vsrc),i;try{i=$s(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,y=n[1]*u,m=n[2]*c,d=n[3]*c;l[0]=f,l[1]=p,l[2]=b+f,l[3]=y+p,l[4]=b+m+f,l[5]=y+d+p,l[6]=m+f,l[7]=d+p;let x=1/e.width,v=1/e.height;l[8]=t.x*x,l[9]=t.y*v,l[10]=(t.x+t.w)*x,l[11]=(t.y+t.h)*v,l[12]=Ce(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,y=this.py1/c;if(o<=f||i>=b||l<=p||a>=y)return;if(i<f||o>b||a<p||l>y){let m=t[0],d=t[1],x=t[2],v=t[5];if(d===t[3]&&x===t[4]&&v===t[7]&&t[6]===m){if(m!==x){let k=Math.min(Math.max(m,f),b),w=Math.min(Math.max(x,f),b),M=t[8],S=(t[10]-M)/(x-m);t[10]=M+(w-m)*S,t[8]=M+(k-m)*S,t[0]=t[6]=k,t[2]=t[4]=w}if(d!==v){let k=Math.min(Math.max(d,p),y),w=Math.min(Math.max(v,p),y),M=t[9],S=(t[11]-M)/(v-d);t[11]=M+(w-d)*S,t[9]=M+(k-d)*S,t[1]=t[3]=k,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=fr[Qr(Math.max(n,i)*2*this.scale,Gs)],c=u.w/2/u.r,f=n*c,p=i*c,b=Math.cos(o),y=Math.sin(o),m=b*f,d=y*f,x=-y*p,v=b*p,k=1/256,w=this.q;w[0]=e-m-x,w[1]=t-d-v,w[2]=e+m-x,w[3]=t+d-v,w[4]=e+m+x,w[5]=t+d+v,w[6]=e-m+x,w[7]=t-d+v,w[8]=u.x*k,w[9]=u.y*k,w[10]=(u.x+u.w)*k,w[11]=(u.y+u.h)*k,w[12]=Ce(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=Is(e,t,o),l=Ce(n,i),u=(Se.x+Se.w/2)/256,c=(Se.y+Se.h/2)/256;for(let f=0;f<a;f+=3){let p=o[f]*2,b=o[f+1]*2,y=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[y],m[5]=m[7]=e[y+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=pr[Qr(n*this.scale,Us)],u=n/2*(l.h/2/l.r);this.sPacked=Ce(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,Bs(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:Rt(),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||!re.gl?null:this.fxr??(this.fxr=re.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,y=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*y,d[9]=1-this.ry0*m,d[10]=this.rx1*y,d[11]=1-this.ry1*m,d[12]=Ce(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;re.live===this&&(re.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 $s(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 ct(s,r={}){let e=s;for(let t of Jr(r.renderer)){let n=t==="canvas2d"?lt(e):Vs(e,t==="webgl2"?2:1,r);if(n)return n;e=Ot(e)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function Ot(s){let r=s.cloneNode(!1);return s.parentNode?.replaceChild(r,s),r}function Ws(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 Be=class{constructor(r,e={}){h(this,"atlas",r);h(this,"tags",new Map);h(this,"count",0);h(this,"m",we());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=rs(t,i,{band:ko(n)});if(!p)return;let b=this.height,y=this.get(o,a,u),m=y.w/y.scale-2,d=Math.min(Math.max(p.head.x-m/2,4),c-m-4),x=Math.min(Math.max(p.head.y-p.headR*2.2-b,4),f-b-4);te(this.m,null,d-1,x-1,0,1,1),r.quad(e(y.surface),y,this.m,y.w/y.scale,y.h/y.scale,16777215,l,"normal")}},ko=s=>s.band==="3-5"||s.band==="9-12"?s.band:"6-8";var So=(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 br(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=hr(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=te(we(),r,n.x,n.y,n.rot??0,n.s??1,n.s??1),a=br(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 We=class{constructor(r){h(this,"atlas",r);h(this,"seen",new WeakSet);h(this,"baked",new WeakMap);h(this,"m",we());h(this,"stack",[]);h(this,"local",we());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"?Qe(n)??Ze:n,u=ts(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 v=te((l=this.stack)[a]??(l[a]=we()),n,c.x,c.y,c.rot??0,c.s??1,c.s??1),k=i*(c.alpha??1);if(this.bakeGroups&&this.seen.has(c.items)){let w=de(v[0],v[1])*o,M=this.bake(c.items,w);if(M){let S=M.frame,_=this.m;_.set(v),_[4]=v[0]*-M.ox+v[2]*-M.oy+v[4],_[5]=v[1]*-M.ox+v[3]*-M.oy+v[5],r.quad(e(S.surface),S,_,S.w/M.k,S.h/M.k,16777215,k,"normal"),this.stats.baked++;continue}}this.seen.add(c.items),this.stats.vector++,this.paint(r,e,c.items,v,k,o,a+1);continue}let f=i*(c.alpha??1),p=n?de(n[0],n[1]):1,b=n?Math.atan2(n[1],n[0]):0,y=(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 v=n?n[0]*c.x+n[2]*c.y+n[4]:c.x,k=n?n[1]*c.x+n[3]*c.y+n[5]:c.y,w=(c.k==="circle"?c.r:c.rx)*p,M=(c.k==="circle"?c.r:c.ry)*p,S=(c.k==="ellipse"?c.rot??0:0)+b;if(d&&m)r.ellipse(v,k,w+y/2,M+y/2,S,m[0],f*m[1]),r.ellipse(v,k,Math.max(w-y/2,0),Math.max(M-y/2,0),S,d[0],f*d[1]);else if(d)r.ellipse(v,k,w,M,S,d[0],f*d[1]);else if(m){let _=Math.min(Math.max(Math.ceil(Math.max(w,M)*o*.6),12),64),C=this.pts=cr(this.pts,_*2),P=Math.cos(S),z=Math.sin(S);for(let H=0;H<_;H++){let U=H/_*Math.PI*2,D=Math.cos(U)*w,xe=Math.sin(U)*M;C[H*2]=v+D*P-xe*z,C[H*2+1]=k+D*z+xe*P}r.stroke(C,_,y,m[0],f*m[1],!0)}continue}if(c.k==="line"){if(!m)continue;let v=c.pts.length>>1,k=this.pts=cr(this.pts,v*2);for(let w=0;w<v;w++){let M=c.pts[w*2],S=c.pts[w*2+1];k[w*2]=n?n[0]*M+n[2]*S+n[4]:M,k[w*2+1]=n?n[1]*M+n[3]*S+n[5]:S}r.stroke(k,v,y,m[0],f*m[1],!1);continue}let x=c.k==="path"?hr(c.d,n,p*o):To(c,te(this.local,n,c.x,c.y,c.rot??0,1,1),o*p);for(let v=0;v<x.count;v++){let k=x.subs[v],w=k.n,M=c.k==="rect"||k.closed;d&&w>=3&&(r.polygon(k.pts,w,d[0],f*d[1]),m||r.stroke(k.pts,w,1/o,d[0],f*d[1],!0)),m&&r.stroke(k.pts,w,y,m[0],f*m[1],M)}}}bake(r,e){let t=So(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=br(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,y=>{y.scale(t,t),y.translate(c,f),Br(y,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}},ht=new Array(36).fill(0),ft=0,me=(s,r=NaN,e=NaN,t=NaN,n=NaN)=>{ht[ft++]=s,s!==Z.Z&&(ht[ft++]=r,ht[ft++]=e,s===Z.Q&&(ht[ft++]=t,ht[ft++]=n))};function To(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 ft=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),hr(ht,r,e)}function Xs(s,r={}){let e=ct(s,r),t=new Ne(Math.min(1024,e.maxTextureSize),2);t.onDrop=S=>{S.texture&&e.destroyTexture(S.texture),S.texture=null};let n=new We(t),i=()=>{let S=new rr;return r.local&&S.setLocal(!0),S},o=i(),a=new Map,l=1e6,u=r.smooth===!1?1:typeof r.smooth=="number"?Math.min(Math.max(r.smooth,.05),1):o.defaultAmount,c=It(e),f=new Be(t,r),p={w:1,h:1},b=1,y=0,m=!1,d=()=>f.drop(),x=typeof document<"u"?document.fonts:void 0;x?.ready?.then(()=>{m||d()}),x?.addEventListener?.("loadingdone",d);let v=()=>{let S=Ot(e.canvas),_=lt(S);if(_){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),e.destroy(),e=_;for(let C of t.pages)C.surface.texture=null;c=It(e),y=0}},k=()=>{if(!e.lost)return y=0,!0;let S=performance.now();return y||(y=S),S-y>3e3&&v(),!e.lost},w=()=>{let S=e.canvas;r.units?(b=r.pixelRatio??1,p.w=r.units.width,p.h=r.units.height):(b=r.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),p.w=S.clientWidth||S.width/b,p.h=S.clientHeight||S.height/b),e.resize(Math.max(1,Math.round(p.w*b)),Math.max(1,Math.round(p.h*b))),e.begin(0,0,b)},M=(S,_)=>{if(S.key===void 0)return S.id??_+1;let C=a.get(S.key);return C===void 0&&(a.size>256&&a.clear(),a.set(S.key,C=l++)),C};return{get renderer(){return e},get kind(){return e.kind},get lost(){return e.lost},get canvas(){return e.canvas},draw(S,_){if(k()){w();for(let C=0;C<S.length;C++){let P=S[C];if(!Array.isArray(P.body))continue;let z=M(P,C),H=u<1||r.interpolate!==!1?o.posed(z,P.body,u,r.interpolate!==!1):P.body,U=Qe(P.avatar??"")??Ze,D=P.alpha??1;!n.draw(e,c,H,U,_,D,b)||!P.name||f.draw(e,c,H,U,_,P.name,P.color??"#6FA0E0",D,b,p.w,p.h)}e.end()}},clear(){k()&&(w(),e.end())},reset(){o=i(),a.clear()},destroy(){m=!0,x?.removeEventListener?.("loadingdone",d),e.destroy()}}}var mr=new Map;function js(s,r,e=Math.min(globalThis.devicePixelRatio||1,2)){let t=`${s}|${r}|${e}`,n=mr.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(),Br(i,ns(Qe(s)??Ze,r)),mr.size>64&&mr.clear(),mr.set(t,n),n}function It(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 en='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',Xe="rgba(10,16,30,0.75)";function tn(s,r){let e=s.size??40,t=s.outline?s.outline===!0?Xe:s.outline:null,n=t?s.outlineWidth??Math.max(e*.12,3):0,i=s.shadow&&r?s.shadow===!0?Xe:s.shadow:null,o=i?s.shadowBlur??e*.25:0;return{size:e,font:s.font??en,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 qs=(s,r)=>`${s.weight} ${s.size*r}px ${s.font}`;function rn(s,r,e,t,n,i){s.scale(t,t),s.font=qs(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 yr=null;function nn(s,r,e){return yr??(yr=document.createElement("canvas").getContext("2d")),yr.font=qs(r,e),yr.measureText(s).width/e}var be=class extends ne{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:y,z:m,anchor:d,hitRadius:x,clip:v,mask:k,filters:w,...M}=n;this._style=M,this.bake(),this.set({x:i,y:o,rotation:a,scale:l,scaleX:u,scaleY:c,alpha:f,visible:p,tint:b,blend:y,z:m,hitRadius:x,clip:v,mask:k,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=tn(this._style,n),{pad:o,th:a}=i,l=nn(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=>rn(d,this._text,i,t,o,o+a/2),y=this._frame,m=null;return y&&e.atlas.valid(y)&&y.scale===t&&(m=e.atlas.rebake(y,u,c,b,this.capW,this.capH),m?Object.assign(m,{ox:p,oy:o+a/2,margin:o}):e.atlas.release(y)),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 dt(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 pt=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 y=r.charCodeAt(b);y>=55296&&y<56320&&b+1<r.length&&(y=r.codePointAt(b),b++),p>=0&&(f+=this.kerning(p,y)),p=y;let m=this.glyph(y);m&&(e&&m.w>0&&m.h>0&&(Ct(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 Ks(s,r){let e=new pt(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 Ys(s,r){let e={...r},t=r.size??40,n=o=>{let a=String.fromCodePoint(o),l=s.pixelScale,u=tn(e,s.effects),c=nn(a,u,l),f=s.atlas.bake((c+u.pad*2)*l,(u.th+u.pad*2)*l,p=>rn(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 pt(t,t*1.25,t,n,s);i.prepare();for(let o of r.chars??"0123456789")i.glyph(o.codePointAt(0));return i}var Mo=.5;function sn(s){let r=[];for(let[e,t]of[["left",ee.leftWrist],["right",ee.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)>=Mo&&r.push({side:e,x:n,y:i})}return r}var mt=s=>St[((s-1)%St.length+St.length)%St.length],Eo=["left","right"];function gr(s,r,e,t,n=()=>null,i={}){let o=[];for(let a of s){let l=n(a)??a.body;if(Array.isArray(l)){if(i.orientation==="portrait"){for(let u of Eo){let c=Yn(l,u,{orientation:"portrait"});i.hold&&(c=i.hold.at(Ye.key(a.id,u),c,i.t??0)),c&&o.push({player:a.id,side:u,x:c.x*e,y:c.y*t,color:mt(a.id)})}continue}for(let u of sn(l)){let c=r(u);o.push({player:a.id,side:u.side,x:c.x*e,y:c.y*t,color:mt(a.id)})}}}return o}function Bt(s,r,e,t=0){let n=s.world,i=is(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 y=s.hitRadius+t/((o+a)/2);return l*l+u*u<=y*y}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 xr(s,r,e,t=0){for(let n of r)if((e===void 0||n.player===e)&&Bt(s,n.x,n.y,t))return n;return null}function Fo(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 Ro(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 Qs=(s,r)=>r||!s.shadow?s:{...s,shadow:void 0};function on(s,r,e){let t=Ro(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)]:Fo(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),_o(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 _o(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 bt=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 Co={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}},ye=["high","medium","low"];function Te(s){let r=Co[s];return{name:s,...r,scale:e=>e<=0?0:Math.max(1,Math.round(e*r.particles))}}var Zs=s=>ye[Math.min(ye.indexOf(s)+1,ye.length-1)],vr=(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)))]},Js=12,ei=s=>Dt(s,.5);function Dt(s,r=.1){let e=vr(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 wr(s,r){let e=r.refresh!==void 0&&Number.isFinite(r.refresh)&&r.refresh>0?r.refresh:Dt(r.intervals),t=vr(r.intervals,.5),n=vr(r.intervals,.9),i=vr(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 ti(s,r){return s.length<30?!1:s.filter(t=>t>r*1.5).length/s.length>.5}var ri="0.1.1",Lo=720*3600*1e3,ni=(s,r,e)=>`fabi-play.engine-tier:${ri}:${s}:${r}:${e}`,si=(s,r,e)=>`fablee-engine-tier:${ri}:${s}:${r}:${e}`;function ii(s,r,e=Date.now()){try{let t=JSON.parse(s?.getItem(r)??"null");if(t&&ye.includes(t.tier)&&typeof t.at=="number"&&e-t.at<Lo)return typeof t.refresh=="number"&&t.refresh>0?{name:t.tier,refresh:t.refresh}:{name:t.tier}}catch{}return null}function an(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 oi(s=typeof location<"u"?location.search:""){let r=new URLSearchParams(s).get("tier");return ye.includes(r)?r:void 0}function ln(s,r){let e=r?.tier;if(ye.includes(e))return s==="canvas2d"&&e==="high"?"medium":e}var un=s=>typeof s?.hz=="number"&&s.hz>=20&&s.hz<=240?Dt([1e3/s.hz],.5):NaN,cn=(s,r)=>ye.indexOf(s)>=ye.indexOf(r)?s:r;function ai(s,r,e){return s?{name:s,from:"forced"}:r?{name:e?cn(r,e):r,from:"hint"}:e?{name:e,from:"cache"}:null}var Po=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,yt=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=Po.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:Le[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:Le.linear,p:-1})}call(r,e){return this.add({target:null,to:null,from:null,fn:r,start:this.at(e),dur:0,ease:Le.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 gt=class{constructor(){h(this,"list",[]);h(this,"timelines",[])}timeline(r){let e=new yt(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:Le[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,Gt=class extends ae{constructor(e,t){super(e);h(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},fn=class extends ae{constructor(e,t){super(e);h(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},Me=()=>performance.now(),li=s=>{let r=Zn(s);return r&&Object.freeze(r)};async function ci(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=ct(e,{renderer:s.renderer??Ws(),failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat,instancing:s.instancing});e=t.canvas;let n=new Set,i=new Ne(Math.min(2048,t.maxTextureSize),4);i.onPage=g=>n.add(g),i.onDrop=g=>{n.delete(g),g.texture&&t.destroyTexture(g.texture),g.texture=null};let o=It(t),a=new gt,l=new bt,u=new We(i),c=new Map,f=new Map,p=new Map,b=new Map,y=new Map,m=new Set,d=0,x=s.tier??oi(),v=String(t.info.renderer??""),k=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),w=typeof screen<"u"?`${screen.width}x${screen.height}`:"",M=ni(t.kind,v,w);Jn(k,M,si(t.kind,v,w));let S=ii(k,M),_=ai(x,ln(t.kind,r?.device),S?.name),C=_?.name??"medium",P=Te(C);u.setTier(C);let z=_?.from==="hint",H=S?.name,U=S?.refresh??un(r?.device),D=1,xe=1,Fe=1,Y={atlas:i,get pixelScale(){return D},get fontGen(){return d},get effects(){return P.effects},tweens:a,frame:g=>Yt.frame(g),shape:g=>{let A=P.effects,F=A?D:-D,E=c.get(F);E||(c.size>=8&&c.clear(),c.set(F,E=new ot(2e3)));let L=he(g),$=E.get(g,L);return(!$||!i.valid($.frame))&&E.set(g,$=on(i,Qs(g,A),D),L),$},bitmapFont:g=>Yt.bitmapFont(g)},ue=1280,Re=null;class Li extends Ve{get width(){return ue}set width(A){}get height(){return j}set height(A){}get safe(){let A=Math.min(ue,j*16/9);return{x:(ue-A)/2,y:0,w:A,h:j}}}let ce=new Li(Y),_e=()=>{let g=t.canvas,A=g.getBoundingClientRect();xe=Math.max(1,A.width||g.clientWidth||innerWidth),Fe=Math.max(1,A.height||g.clientHeight||innerHeight),ue=j*xe/Fe;let F=Math.min(globalThis.devicePixelRatio||1,s.maxPixelRatio??2);if(Fe*F/j<=P.resolution){let L=Math.max(1,Math.round(Fe*F));D=L/j,t.resize(Math.max(1,Math.round(xe*F)),L)}else D=P.resolution,t.resize(Math.round(ue*D),Math.round(j*D));Re&&Re.style.setProperty("--unit",`${Fe/j}px`)};addEventListener("resize",_e);let Tr=g=>{C=g,P=Te(g),u.setTier(g),_e()},Ht=typeof ResizeObserver<"u"?new ResizeObserver(_e):null;Ht?.observe(e);let ve=r?.backdrop==="video"?"video":"none",V=r?.view??null,zt=r?.orientation==="portrait"?"portrait":"landscape",Nn=li(r?.safeArea)??Qn,On=[],In=-1/0,$t=!1,xt=!1,Mr=new Set,Bn=()=>{let g=ve==="video"?"transparent":"";document.documentElement.style.background=g,document.body.style.background=g},Dn=(g,A)=>{let F=g==="video"?"video":"none",E=A??null;if(!(F===ve&&(E===V||E&&V&&E.x===V.x&&E.y===V.y&&E.w===V.w&&E.h===V.h))){ve=F,V=E,Bn();for(let L of[...Mr])L(ve,V)}},Gn=[];if(r){let g=E=>{Array.isArray(E)&&(On=E,In=Me())},A=E=>{$t=E,Vt()},F=E=>{if(x||z)return;Number.isFinite(U)||(U=un(E));let L=ln(t.kind,E);L&&(z=!0,Tr(H?cn(L,H):L))};Gn.push(r.on("start",E=>F(E?.device)),r.on("start",E=>{(E?.orientation==="portrait"||E?.orientation==="landscape")&&(zt=E.orientation);let L=li(E?.safeArea);L&&(Nn=L)}),r.on("start",E=>{typeof E?.muted=="boolean"&&(l.muted=E.muted)}),r.on("frame",E=>g(E?.players)),r.on("players",E=>g(E?.players)),r.on("backdrop",E=>Dn(E?.backdrop,E?.view)),r.on("start",E=>Dn(E?.backdrop,E?.view??r.view)),r.on("pause",()=>A(!0)),r.on("resume",()=>A(!1)),r.on("break-start",()=>A(!0)),r.on("break-done",()=>A(!1)),r.on("break-end",()=>A(!1))),l.muted=r.muted===!0}Bn();let Vt=()=>$t||xt||document.hidden?l.hold():l.release(),Un=-1,Er=[],Fr=0,Rr=()=>Me()-In<1e3?On:[],Pi=g=>r?r.toScreen(g):Ir(V,g),Ni=new Ye,Wt=()=>{if(Un===Fr)return Er;Un=Fr;let g=zt==="portrait",A=ve==="video"&&!g||!r?.smoothedBody?()=>null:F=>r.smoothedBody(F);return Er=gr(Rr(),Pi,ue,j,A,g?{orientation:zt,hold:Ni,t:Me()}:void 0),Er},vt={x:0,y:0,w:1,h:1},Oi=()=>(vt.x=V?V.x*ue:0,vt.y=V?V.y*j:0,vt.w=V?V.w*ue:ue,vt.h=V?V.h*j:j,vt),Ii=g=>{let A=g.alpha??1,F=g.tags?new Be(i,g):null;F&&m.add(F);let E=typeof g.tags=="function"?g.tags:L=>String(L);return(L,$)=>{if(ve==="video")return;let O=Oi();for(let I of Rr()){let q=r?.smoothedBody?.(I)??I.body,G=Qe(r?.avatarOf?.(I)??I.avatar??"")??Ze;if(!u.draw(L.r,L.tex,q,G,O,A*$,D)||!F)continue;let oe=E(I.id);oe&&F.draw(L.r,L.tex,q,G,O,oe,mt(I.id),A*$,D,ue,j)}}},_r=new Set,Cr=new Set,wt=new Set,Xt=!1,Lr=0,qe=0,jt=0,De={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0},qt=0,Pr=0,Nr=Me(),At=[],Kt=0,Hn=()=>({r:t,kernel:Y,tex:o}),zn=Hn(),Bi=()=>{if(t.lost)return;let[g,A]=ve==="video"||s.background===void 0?[0,0]:K(s.background);t.time=jt,t.maxBlur=P.maxBlur,t.begin(g,A,D),te(ce.world,null,ce.x,ce.y,ce.rotation,ce.scaleX,ce.scaleY),Xr(zn,ce,ce.alpha,ce.tint);let F=t.end();De.drawCalls=F.drawCalls,De.quads=F.quads,De.filtersSkipped=F.filtersSkipped},$n=g=>{if(!Xt)return;Lr=requestAnimationFrame($n);let A=Math.min(Math.max((g-qe)/1e3,0),.1);qe&&At.push(g-qe),qe=g,Fr++;let F=Me(),E=$t||xt;if(!E){jt+=A,a.update(A);for(let L of wt)L.destroyed||L.update(A);for(let L of _r)L(A,jt)}for(let L of Cr)L(A);ce.sweep();for(let L of wt)L.destroyed&&wt.delete(L);if(t.lost?(Kt||(Kt=g),g-Kt>3e3&&Di()):(Kt=0,Bi()),qt++,Pr+=Me()-F,F-Nr>=1e3&&(De.fps=Math.round(qt*1e3/(F-Nr)),De.cpuMs=Math.round(Pr/Math.max(qt,1)*100)/100,r?.reportStats?.({fps:De.fps,renderer:t.kind,tier:C}),qt=0,Pr=0,Nr=F),At.length>=180){let L=Number.isFinite(U)?U:Dt(At);!x&&!E&&ti(At,L)&&C!=="low"&&(Tr(Zs(C)),H=C,an(k,M,C,Number.isFinite(U)?U:void 0),console.info(`[engine] slow frames: tier ${C}`)),At.length=0}},Di=()=>{let g=Ot(t.canvas),A=lt(g);if(A){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),t.destroy(),t=A;for(let F of n)F.texture=null;for(let F of i.pages)n.add(F.surface);o=It(t),zn=Hn(),Ht?.disconnect(),Ht?.observe(g),_e()}},Vn=()=>{Vt(),document.hidden||(qe=0)};document.addEventListener("visibilitychange",Vn);let Wn=()=>{d++;for(let g of m)g.drop()};if(document.fonts?.addEventListener?.("loadingdone",Wn),_e(),!_&&s.probe!==!1&&(Number.isFinite(U)||(U=ei(await No(Js))),!z)){P=Te("high"),_e();let g=await Oo(t,i,()=>o,()=>D,ue,()=>z);if(g.refresh=U,!z){let A=wr(t.kind,g);an(k,M,A,U),H=A,Tr(A)}}let Yt={stage:ce,get tier(){return P},get renderer(){return t},get canvas(){return t.canvas},get pixelScale(){return D},get backdrop(){return ve},get view(){return V},get orientation(){return zt},get safeArea(){return Nn},get paused(){return $t||xt},sound:l,stats:De,get time(){return jt},get supports(){let g=t.support;return{filters:g.filters,blur:g.filters&&P.maxBlur>0,shaders:g.shaders,maxBlur:g.filters?P.maxBlur:0,tiers:{high:{maxBlur:Te("high").maxBlur},medium:{maxBlur:Te("medium").maxBlur},low:{maxBlur:Te("low").maxBlur}}}},sprite:(g,A)=>new ne(Y,g,A),shape:(g,A)=>new pe(Y,g,A),text:(g,A)=>new be(Y,g,A),group:g=>new Ve(Y).set(g??{}),particles(g,A={}){let F=typeof g=="object"&&"type"in g?Y.shape(g).frame:g,E=new rt(Y,F,A),{max:L,blend:$,gravity:O,drag:I,...q}=A;return E.set(q),wt.add(E),E},tween:(g,A,F,E)=>a.tween(g,A,F,E),bake(g,A,F,E,L){return p.set(g,{w:A,h:F,draw:E,origin:L}),f.delete(g),Yt.frame(g)},frame(g){let A=f.get(g);if(A&&i.valid(A)&&(A.gen===0||A.scale===D))return A;let F=p.get(g);if(F){let E=D,L=i.bake(F.w*E,F.h*E,$=>($.scale(E,E),F.draw($)),E,F.origin?.x??0,F.origin?.y??0);return f.set(g,L),L}if(A)return A;throw new Error(`[engine] no frame "${g}": load it or bake it first`)},async load(g){await Promise.all(Object.entries(g).map(([A,F])=>Ui(A,F)))},hands:g=>g===void 0?Wt():Wt().filter(A=>A.player===g),touched(g,A,F={}){return g.updateWorld(),xr(g,Wt(),A,F.padding??0)},hits(g,A,F,E=0){return g.updateWorld(),Bt(g,A,F,E)},avatars:(g={})=>new Gt(Y,Ii(g)),handMarkers(g={}){let A=g.radius??36,F=g.look??"auto",E=new Float64Array(6),L=Math.max(A*.12,3),$={type:"ring",r:A,lw:L,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},O={type:"ring",r:A,lw:L*1.8,stroke:Xe,shadow:{color:Xe,blur:A*.2}},I=(Ge,J,Ke,Or,Qt,Ue)=>{let Zt=J.w/J.scale;te(E,null,Ke-Zt/2,Or-Zt/2,0,1,1),Ge.r.quad(Ge.tex(J.surface),J,E,Zt,Zt,Qt,Ue,"normal")},q=Ge=>{let J=null,Ke=!1;return()=>(J&&i.valid(J.frame)&&J.frame.scale===D&&Ke===P.effects?J:(Ke=P.effects,J=Y.shape(Ge))).frame},G=q($),oe=q(O);return new fn(Y,(Ge,J)=>{let Ke=F==="video"||F==="auto"&&ve==="video",Or=G(),Qt=Ke?oe():null;for(let Ue of Wt())Qt&&I(Ge,Qt,Ue.x,Ue.y,16777215,J),I(Ge,Or,Ue.x,Ue.y,K(Ue.color)[0],J)})},timeline:g=>a.timeline(g),animation(g,A){let F=typeof g=="string"?Gi(g):{frames:g},E=new le(Y,F,A);return wt.add(E),E},bitmapFont(g,A){if(!A){let E=b.get(g);if(!E)throw new Error(`[engine] no bitmap font "${g}": load or make it first`);return E}let F="data"in A?Xn(dt(A.data),A.pages):Ys(Y,A);return b.set(g,F),F},players:()=>Rr(),onFrame(g){return _r.add(g),()=>{_r.delete(g)}},onRender(g){return Cr.add(g),()=>{Cr.delete(g)}},onBackdrop(g){return Mr.add(g),()=>{Mr.delete(g)}},get hud(){return Re||(Re=document.createElement("div"),Re.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(Re),_e()),Re},random:(g=0,A=1)=>g+Math.random()*(A-g),start(){Xt||(Xt=!0,qe=0,Lr=requestAnimationFrame($n))},pause(){xt=!0,Vt()},resume(){xt=!1,Vt()},destroy(){Xt=!1,cancelAnimationFrame(Lr),Gn.forEach(g=>g()),removeEventListener("resize",_e),Ht?.disconnect(),document.removeEventListener("visibilitychange",Vn),document.fonts?.removeEventListener?.("loadingdone",Wn),a.clear(),xs(Y),l.destroy(),t.destroy(),Re?.remove()}};function Gi(g){let A=y.get(g);if(A)return A;let F=[...new Set([...f.keys(),...p.keys()])].filter(E=>E.startsWith(g)).sort(ws);if(!F.length)throw new Error(`[engine] no animation or frames "${g}\u2026"`);return{frames:F}}async function Ui(g,A){let F=A.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(F))return l.load(g,A);if(["woff","woff2","ttf","otf"].includes(F)){let O=new FontFace(g,`url(${A})`);document.fonts.add(await O.load()),d++;return}let E=new URL(A,location.href);if(F==="fnt")return jn(g,dt(await(await fetch(A)).text()),E);if(F==="json"){let O=await(await fetch(A)).json();if(Array.isArray(O.chars)&&!O.frames)return jn(g,dt(O),E);let I=await hn(new URL(O.meta?.image??A.replace(/\.json$/,".png"),E).href);Hi(g,O,nt(I));return}let L=await hn(A),$=nt(L);n.add($),f.set(g,{surface:$,x:0,y:0,w:L.width,h:L.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function Xn(g,A){return Ks(g,A.map(F=>{let E=nt(F);return n.add(E),E}))}async function jn(g,A,F){b.set(g,Xn(A,await Promise.all(A.pages.map(E=>hn(new URL(E,F).href)))))}function Hi(g,A,F){n.add(F);let E=Array.isArray(A.frames)?A.frames:Object.entries(A.frames).map(([O,I])=>({...I,filename:O})),L=[],$=[];for(let O of E){let I=O.frame,q=O.filename.replace(ui,"");O.rotated&&console.warn(`[engine] ${g}/${q} is rotated: export without rotation`);let G={surface:F,x:I.x,y:I.y,w:I.w,h:I.h,scale:1,gen:0,ox:0,oy:0,margin:0};O.trimmed&&O.sourceSize&&O.spriteSourceSize&&(G.sw=O.sourceSize.w,G.sh=O.sourceSize.h,G.tx=O.spriteSourceSize.x,G.ty=O.spriteSourceSize.y);let oe=O.scale9Borders;oe&&(G.slice=[oe.y,(G.sw??I.w)-oe.x-oe.w,(G.sh??I.h)-oe.y-oe.h,oe.x]),f.set(`${g}/${q}`,G),L.push(`${g}/${q}`),$.push((O.duration??0)/1e3)}for(let[O,I]of Object.entries(A.animations??{}))y.set(`${g}/${O}`,{frames:I.map(q=>`${g}/${q.replace(ui,"")}`)});for(let O of A.meta?.frameTags??[]){let I=[];for(let G=O.from;G<=O.to;G++)I.push(G);O.direction==="reverse"&&I.reverse(),O.direction==="pingpong"&&I.push(...I.slice(1,-1).reverse());let q=I.every(G=>$[G]>0);y.set(`${g}/${O.name}`,{frames:I.map(G=>L[G]),...q?{durations:I.map(G=>$[G])}:{}})}}return Yt}var ui=/\.(png|webp|jpe?g|gif|bmp)$/i;function hn(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 No(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 Oo(s,r,e,t,n,i=()=>!1){let o=t(),a=on(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=Me(),y=0;return await new Promise(m=>{let d=x=>{y&&x-b>250&&l.push(x-y),y=x;let v=Me();s.begin(0,0,o);let k=e();for(let w=0;w<300;w++){let M=x/1e3+w;te(c,null,w*37%n,w*53%j,M,1,1),s.quad(k(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),x-b>250&&u.push(Me()-v),x-b<750&&!i()?requestAnimationFrame(d):(s.begin(0,0,o),s.end(),m())};requestAnimationFrame(d)}),{intervals:l,cpu:u}}var Io=64,hi=32,Bo=0,Do=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,fi=new Set,pi=(s,r)=>{fi.has(s)||(fi.add(s),console.warn(r))},di=s=>new pn(s),pn=class{constructor(r){h(this,"r",r);h(this,"css","none");h(this,"plans",new ot(Io));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 y;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 v=new Float64Array(n.length*2);v.set(n),n=this.buf=v}let x=this.classes.get(d.constructor);x===void 0&&this.classes.set(d.constructor,x=this.classes.size),n[i++]=x,n[i++]=d.enabled?1:0,d.params&&(i=d.params(n,i))}let o=(y=this.keys)[i]??(y[i]=new Float64Array(i));for(let m=0;m<i;m++)o[m]=n[m];let a=he(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%hi||!this.live.size))for(let e of this.live)r-e.used>hi&&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=Do+ ++Bo;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++,pi("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++,pi("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 Go=64,Ar=17,Uo=s=>`${dr}
|
|
49
|
-
uniform sampler2D uTexture;
|
|
50
|
-
uniform mat4 uM[${s}];
|
|
51
|
-
uniform vec4 uO[${s}];
|
|
52
|
-
uniform int uK;
|
|
53
|
-
varying vec2 vUv;
|
|
54
|
-
varying vec4 vColor;
|
|
55
|
-
void main() {
|
|
56
|
-
vec4 c = texture2D(uTexture, vUv);
|
|
57
|
-
if (c.a > 0.0) c.rgb /= c.a;
|
|
58
|
-
for (int i = 0; i < ${s}; i++) {
|
|
59
|
-
if (i >= uK) break;
|
|
60
|
-
c = clamp(uM[i] * c + uO[i], 0.0, 1.0);
|
|
61
|
-
}
|
|
62
|
-
c.rgb *= c.a;
|
|
63
|
-
gl_FragColor = c * vColor;
|
|
64
|
-
}`,Ho=()=>`${dr}
|
|
65
|
-
uniform sampler2D uTexture;
|
|
66
|
-
uniform vec2 uDir;
|
|
67
|
-
uniform vec2 uOff;
|
|
68
|
-
uniform vec2 uTaps[${Ar}];
|
|
69
|
-
uniform int uN;
|
|
70
|
-
uniform float uMode;
|
|
71
|
-
uniform vec4 uShadow;
|
|
72
|
-
varying vec2 vUv;
|
|
73
|
-
varying vec4 vColor;
|
|
74
|
-
void main() {
|
|
75
|
-
vec2 p = vUv + uOff;
|
|
76
|
-
vec4 c = texture2D(uTexture, p) * uTaps[0].y;
|
|
77
|
-
for (int i = 1; i < ${Ar}; i++) {
|
|
78
|
-
if (i >= uN) break;
|
|
79
|
-
vec2 d = uDir * uTaps[i].x;
|
|
80
|
-
c += (texture2D(uTexture, p + d) + texture2D(uTexture, p - d)) * uTaps[i].y;
|
|
81
|
-
}
|
|
82
|
-
if (uMode > 0.5) c = uShadow * c.a;
|
|
83
|
-
gl_FragColor = c * vColor;
|
|
84
|
-
}`;function zo(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 mi=s=>new yn(s),yn=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(Ar*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>=Go){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,p=Math.min(Math.ceil(o.ry1/l),n.h)*l,b=1/(t*e.width),y=1/(t*e.height);o.bScis=!1,o.batch.push(u,c,f,c,f,p,u,p,u*b,1-c*y,f*b,1-p*y,4294967295,o.slotOf(e)),o.flush()}post(r){return r==="color"?this.colorProg??(this.colorProg=this.r.build(Uo(this.colorN))):this.blurProg??(this.blurProg=this.r.build(Ho()))}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 y=this.mats[l-1],m=this.counts[l-1];if(m<this.colorN)b.toMatrix(this.fm),y.set(this.fm,m*20),this.counts[l-1]=m+1;else{let d=(m-1)*20;for(let x=0;x<20;x++)this.fm2[x]=y[d+x];b.toMatrix(this.fm),zo(this.fm2,this.fm,this.fm3),y.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,y=f===0?1:0,m=b?null:this.scratch(1,y);if(!b&&!m)break;let d=i[p];if(d===null){let x=this.post("color");n.use(x);let v=this.mats[p],k=this.counts[p],w=this.m16,M=this.o4;for(let S=0;S<k;S++)for(let _=0;_<4;_++){for(let C=0;C<4;C++)w[S*16+C*4+_]=v[S*20+_*5+C];M[S*4+_]=v[S*20+_*5+4]}u.uniformMatrix4fv(n.u(x,"uM"),!1,w),u.uniform4fv(n.u(x,"uO"),M),u.uniform1i(n.u(x,"uK"),k),m?this.pass(x,c,1,m):n.final(x,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 x=d,v=this.scratch(1,2);if(!v)break;this.blur(c,f<0,Math.max(Math.min(x.blur,a),0)*o,v,1,x);let k=m??(e<1?this.scratch(1,y):null);k?(this.pass(n.main,v.tex,1,k),this.pass(n.main,c,1,k,!0),m||n.final(n.main,k.tex,1,e)):(n.final(n.main,v.tex,1,1),n.final(n.main,c,1,1))}else{let x=d,v=this.userProg(x.source,!0);n.use(v);let k=n.canvas.width,w=n.canvas.height;u.uniform2f(n.u(v,"uResolution"),k,w),u.uniform1f(n.u(v,"uTime"),n.time),u.uniform4f(n.u(v,"uRect"),n.rx0/k,1-n.ry1/w,n.rx1/k,1-n.ry0/w);let M=x.uniforms;for(let S in M){let _=n.u(v,S);if(!_)continue;let C=M[S];typeof C=="number"?u.uniform1f(_,C):C.length===2?u.uniform2fv(_,C):C.length===3?u.uniform3fv(_,C):C.length===4?u.uniform4fv(_,C):C.length===1&&u.uniform1fv(_,C)}m?this.pass(v,c,1,m):n.final(v,c,1,e)}m&&(c=m.tex,f=y)}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,y=t>=.25?this.tapsFor(b):this.tapsFor(0),m=!0;if(y>1){for(let x=2;x<=c&&m;x*=2){let v=this.scratch(x,0);v?(this.pass(a.main,f,p,v),f=v.tex,p=x):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"),y),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"),y),l.uniform2f(a.u(u,"uDir"),0,1/f.height),o){let d=o.opacity,x=o.rgb;l.uniform4f(a.u(u,"uShadow"),(x>>16&255)/255*d,(x>>8&255)/255*d,(x&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),(Ar-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 Ee=s=>Math.min(Math.max(s,0),1),fe=s=>Math.max(s,0),je=class{constructor(){h(this,"enabled",!0);re.gl=mi,re.c2d=di}},ge=class extends je{constructor(e){super();h(this,"amount",e);h(this,"kind",1)}params(e,t){return e[t]=this.amount,t+1}};function kr(s,r,e){s.fill(0),s[0]=s[6]=s[12]=r,s[4]=s[9]=s[14]=e,s[18]=1}function Sr(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 N=new Float64Array(9),xn=class extends ge{toMatrix(r){kr(r,fe(this.amount),0)}css(){return`brightness(${fe(this.amount)})`}},vn=class extends ge{toMatrix(r){let e=fe(this.amount);kr(r,e,.5-.5*e)}css(){return`contrast(${fe(this.amount)})`}},wn=class extends ge{toMatrix(r){let e=Ee(this.amount);kr(r,1-2*e,e)}css(){return`invert(${Ee(this.amount)})`}},An=class extends ge{toMatrix(r){let e=fe(this.amount);N[0]=.213+.787*e,N[1]=.715-.715*e,N[2]=.072-.072*e,N[3]=.213-.213*e,N[4]=.715+.285*e,N[5]=.072-.072*e,N[6]=.213-.213*e,N[7]=.715-.715*e,N[8]=.072+.928*e,Sr(r,N)}css(){return`saturate(${fe(this.amount)})`}},kn=class extends ge{toMatrix(r){let e=1-Ee(this.amount);N[0]=.2126+.7874*e,N[1]=.7152-.7152*e,N[2]=.0722-.0722*e,N[3]=.2126-.2126*e,N[4]=.7152+.2848*e,N[5]=.0722-.0722*e,N[6]=.2126-.2126*e,N[7]=.7152-.7152*e,N[8]=.0722+.9278*e,Sr(r,N)}css(){return`grayscale(${Ee(this.amount)})`}},Sn=class extends ge{toMatrix(r){let e=1-Ee(this.amount);N[0]=.393+.607*e,N[1]=.769-.769*e,N[2]=.189-.189*e,N[3]=.349-.349*e,N[4]=.686+.314*e,N[5]=.168-.168*e,N[6]=.272-.272*e,N[7]=.534-.534*e,N[8]=.131+.869*e,Sr(r,N)}css(){return`sepia(${Ee(this.amount)})`}},Tn=class extends ge{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);N[0]=.213+t*.787-n*.213,N[1]=.715-t*.715-n*.715,N[2]=.072-t*.072+n*.928,N[3]=.213-t*.213+n*.143,N[4]=.715+t*.285+n*.14,N[5]=.072-t*.072-n*.283,N[6]=.213-t*.213-n*.787,N[7]=.715-t*.715+n*.715,N[8]=.072+t*.928+n*.072,Sr(r,N)}css(){return`hue-rotate(${this.amount}deg)`}},Mn=class extends ge{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=He(this.c)}params(e,t){return e[t]=this.amount,e[t+1]=this.c,t+2}toMatrix(e){let t=Ee(this.amount);kr(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=Ee(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())}},En=class extends je{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}},Fn=class extends je{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(fe(this.radius),e)}css(e,t){return`blur(${Math.min(fe(this.radius),t)*e}px)`}},Rn=class extends je{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=Ee(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(fe(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(fe(this.blur),t)*e}px ${He(this.rgb,this.opacity)})`}},$o=`#ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
86
|
-
precision highp float;
|
|
87
|
-
#else
|
|
88
|
-
precision mediump float;
|
|
89
|
-
#endif
|
|
90
|
-
uniform sampler2D uTexture;
|
|
91
|
-
uniform vec2 uResolution;
|
|
92
|
-
uniform float uTime;
|
|
93
|
-
uniform vec4 uRect;
|
|
94
|
-
varying vec2 vUv;
|
|
95
|
-
varying vec4 vColor;
|
|
96
|
-
#define main fabiUserMain
|
|
97
|
-
#line 1
|
|
98
|
-
`,Vo=s=>`${$o}${s}
|
|
99
|
-
#undef main
|
|
100
|
-
void main() {
|
|
101
|
-
fabiUserMain();
|
|
102
|
-
gl_FragColor *= vColor.a;
|
|
103
|
-
}
|
|
104
|
-
`,_n=class extends je{constructor(e){super();h(this,"kind",4);h(this,"source");h(this,"uniforms",{});h(this,"padding");this.source=Vo(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 fe(this.padding)}},bi=(s,r=1)=>new Mn(s,r),yi=s=>new xn(s),gi=s=>new vn(s),xi=s=>new An(s),vi=(s=1)=>new kn(s),wi=(s=1)=>new Sn(s),Ai=s=>new Tn(s),ki=(s=1)=>new wn(s),Si=s=>new En(s),Ti=s=>new Fn(s),Mi=(s,r,e,t="rgba(0,0,0,0.5)")=>new Rn(s,r,e,t);function Ei(s){let r=new _n(s),e=re.live?.filters()?.check(r.source);if(e)throw new Error(`shader(): the fragment does not compile:
|
|
105
|
-
${e}`);return r}var Cn="x y rotation scaleX scaleY alpha visible blend tint z hitRadius clip mask filters".split(" "),Ri="frameName _frame _w _h slice autoAnchor".split(" "),Wo="fps loop speed onComplete durations".split(" "),Ln=["anchorX","anchorY"],Xo=[...Cn,...Ri,...Wo,...Ln],jo=[...Cn,...Ri,...Ln],qo=[...Cn,...Ln],_i=s=>s instanceof le?Xo:s instanceof ne?jo:qo;function Ko(s){let r={},e=s;for(let t of _i(s))r[t]=e[t];return s instanceof pe&&(r.spec=s.spec),s instanceof be&&(r.text=s.text,r.style=s.style),s instanceof le&&(r.playing=s.playing),r}function Fi(s,r){let e=s;s instanceof pe&&s.spec!==r.spec&&(s.spec=r.spec),s instanceof be&&(s.text=r.text,s.style!==r.style&&(e._style=r.style,e.dirty=!0)),s instanceof le&&s.gotoFrame(r.speed<0?s.frameCount-1:0);let t=s instanceof pe||s instanceof be,n=_i(s);for(let i=0;i<n.length;i++){let o=n[i];(!t||o!=="_frame"&&o!=="frameName")&&(e[o]=r[o])}}var Ut=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);Fi(e,t),e.visible=t.visible,e instanceof le&&t.playing&&e.play()}else{if(e=this.factory(),!(e instanceof ae))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,Ko(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--,Fi(r,e),r instanceof le&&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()}},Ci=(s,r)=>new Ut(s,r);window.FabiEngine=Pn;})();
|
|
1
|
+
"use strict";(()=>{var bs=Object.defineProperty,fo=Object.defineProperties;var po=Object.getOwnPropertyDescriptors;var fr=Object.getOwnPropertySymbols;var ys=Object.prototype.hasOwnProperty,gs=Object.prototype.propertyIsEnumerable;var Ge=Math.pow,jr=(n,t,e)=>t in n?bs(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,re=(n,t)=>{for(var e in t||(t={}))ys.call(t,e)&&jr(n,e,t[e]);if(fr)for(var e of fr(t))gs.call(t,e)&&jr(n,e,t[e]);return n},ke=(n,t)=>fo(n,po(t));var lt=(n,t)=>{var e={};for(var r in n)ys.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(n!=null&&fr)for(var r of fr(n))t.indexOf(r)<0&&gs.call(n,r)&&(e[r]=n[r]);return e};var mo=(n,t)=>{for(var e in t)bs(n,e,{get:t[e],enumerable:!0})};var h=(n,t,e)=>jr(n,typeof t!="symbol"?t+"":t,e);var Pe=(n,t,e)=>new Promise((r,s)=>{var i=l=>{try{a(e.next(l))}catch(u){s(u)}},o=l=>{try{a(e.throw(l))}catch(u){s(u)}},a=l=>l.done?r(l.value):Promise.resolve(l.value).then(i,o);a((e=e.apply(n,t)).next())});var I=typeof self!="undefined"?self:typeof window!="undefined"?window:typeof global!="undefined"?global:{};var Wn={};mo(Wn,{AnimatedSprite:()=>Ae,Atlas:()=>We,AvatarPainter:()=>nt,AvatarsNode:()=>Jt,BitmapFont:()=>Et,DEFAULT_FONT:()=>dn,EASE:()=>$e,Group:()=>rt,HALO:()=>st,MAX_LAYERS:()=>zt,NameTags:()=>qe,Node:()=>we,NodePool:()=>er,Particles:()=>mt,STAGE_HEIGHT:()=>se,Shape:()=>Me,ShelfPacker:()=>Xt,Sound:()=>_t,Sprite:()=>be,TIERS:()=>_e,Text:()=>Re,Timeline:()=>Ct,Tweens:()=>Pt,avatarPortrait:()=>gi,blur:()=>Yi,brightness:()=>zi,colorMatrix:()=>Ki,contrast:()=>$i,createAvatarRenderer:()=>yi,createEngine:()=>Oi,createRenderer:()=>kt,dropShadow:()=>Qi,grayscale:()=>Wi,handsOf:()=>Cr,hits:()=>Qt,hueRotate:()=>ji,invert:()=>qi,nodePool:()=>ro,packColor:()=>ze,parseBMFont:()=>Ft,parseColor:()=>ae,pickTier:()=>Nr,playerColor:()=>Rt,rendererOrder:()=>fn,rng:()=>Cs,saturate:()=>Vi,sepia:()=>Xi,shader:()=>Zi,shapeBounds:()=>_r,tier:()=>Be,tint:()=>Gi,touching:()=>Pr,wrists:()=>yn});var bo=33,de={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 yo=4,Dt=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"];var go={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},ka=go["6-8"];var qr=(n,t)=>n?{x:n.x+t.x*n.w,y:n.y+t.y*n.h}:{x:t.x,y:t.y},xo=.5,dr={left:1.6,top:1.6,w:3.2,h:3},vo=1.2;function vs(n,t,e={}){let r=Array.isArray(n)?n:n.body;if(!Array.isArray(r))return null;let s=t==="left"?de.leftWrist:de.rightWrist,i=g=>{var w;return Bt(r[g*3])&&Bt(r[g*3+1])&&((w=r[g*3+2])!=null?w:0)>=xo?g:-1};if(i(s)<0)return null;let o=r[s*3],a=r[s*3+1];if(e.orientation!=="portrait")return qr(e.view,{x:o,y:a});if(i(de.leftShoulder)<0||i(de.rightShoulder)<0)return null;let l=de.leftShoulder*3,u=de.rightShoulder*3,c=(r[l]+r[u])/2,f=(r[l+1]+r[u+1])/2,p=de.leftHip*3,m=de.rightHip*3,b=(r[p]+r[m])/2,y=(r[p+1]+r[m+1])/2,d=Bt(b)&&Bt(y)?Math.hypot(b-c,y-f):0;return(i(de.leftHip)<0||i(de.rightHip)<0)&&(d=Math.max(d,vo*Math.hypot(r[l]-r[u],r[l+1]-r[u+1]))),d=Math.max(d,.01),{x:xs((o-c+dr.left*d)/(dr.w*d)),y:xs((a-f+dr.top*d)/(dr.h*d))}}var wo=300,ut=class{constructor(t=wo){h(this,"holdMs",t);h(this,"last",new Map)}static key(t,e){return t*2+(e==="right"?1:0)}at(t,e,r){let s=this.last.get(t);return e?(s?(s.x=e.x,s.y=e.y,s.t=r):this.last.set(t,{x:e.x,y:e.y,t:r}),e):s?r-s.t<=this.holdMs?{x:s.x,y:s.y}:(this.last.delete(t),null):null}clear(){this.last.clear()}},Ao=.25,ws=Object.freeze({top:0,bottom:0,left:0,right:0});function As(n){if(!ko(n))return;let t=e=>Bt(e)?Math.min(Math.max(e,0),Ao):0;return{top:t(n.top),bottom:t(n.bottom),left:t(n.left),right:t(n.right)}}var Sa=16/9;var ko=n=>typeof n=="object"&&n!==null&&!Array.isArray(n),Bt=n=>typeof n=="number"&&Number.isFinite(n),xs=n=>Math.min(Math.max(n,0),1);var So=12,To=bo*4,Mo=n=>So+n*To,Ta=Mo(yo);var Eo=n=>n.startsWith("fabi-play.")?"fablee-play.".concat(n.slice(10)):null;function ks(n,t,e=Eo(t)){if(!(!n||!e))try{let r=n.getItem(e);if(r===null)return;n.getItem(t)===null&&n.setItem(t,r),n.removeItem(e)}catch(r){}}var Ss,Ts=(Ss=I.FabiPlay)==null?void 0:Ss.avatars;if(!Ts)throw new Error("[engine] fabi-play-engine.lite.js needs fabi-play.js (with FabiPlay.avatars) loaded before it");var{avatarById:ct,avatarShapes:Ms,BAND_BODY:Ca,DEFAULT_AVATAR:ht,drawShapes:Kr,frameOf:Es,iconShapes:Fs}=Ts;var Le=()=>Float64Array.of(1,0,0,1,0,0);function pe(n,t,e,r,s,i,o){let a=s?Math.cos(s):1,l=s?Math.sin(s):0,u=a*i,c=l*i,f=-l*o,p=a*o;if(!t)return n[0]=u,n[1]=c,n[2]=f,n[3]=p,n[4]=e,n[5]=r,n;let m=t[0],b=t[1],y=t[2],d=t[3];return n[0]=m*u+y*c,n[1]=b*u+d*c,n[2]=m*f+y*p,n[3]=b*f+d*p,n[4]=m*e+y*r+t[4],n[5]=b*e+d*r+t[5],n}function _s(n,t,e){let r=n[0]*n[3]-n[1]*n[2];if(Math.abs(r)<1e-12)return null;let s=t-n[4],i=e-n[5];return[(n[3]*s-n[2]*i)/r,(-n[1]*s+n[0]*i)/r]}var Rs={white:16777215,black:0,red:16711680,transparent:0},Ut=new Map;function ae(n){var s,i;if(typeof n=="number")return[n&16777215,1];let t=Ut.get(n);if(t)return t;let e=[16777215,1],r=n.trim().toLowerCase();if(r[0]==="#"){let o=r.slice(1),a=o.length<=4?[...o].map(u=>u+u).join(""):o,l=parseInt(a.slice(0,6),16);Number.isFinite(l)&&(e=[l,a.length===8?parseInt(a.slice(6,8),16)/255:1])}else if(r.startsWith("rgb")){let o=(i=(s=r.match(/-?\d*\.?\d+%?/g))==null?void 0:s.map(f=>f.endsWith("%")?parseFloat(f)/100*255:parseFloat(f)))!=null?i:[],[a=255,l=255,u=255]=o,c=o[3]===void 0?1:r.match(/,\s*[\d.]+%\s*\)$/)?o[3]/255:o[3];e=[(Yr(a)<<16|Yr(l)<<8|Yr(u))>>>0,Math.min(Math.max(c,0),1)]}else if(r in Rs)e=[Rs[r],r==="transparent"?0:1];else if(typeof document!="undefined"){let o=document.createElement("canvas").getContext("2d");if(o){o.fillStyle="#ffffff",o.fillStyle=r;let a=o.fillStyle;if(a!==r)return Ut.set(n,e=ae(a)),e}}return Ut.size>512&&Ut.clear(),Ut.set(n,e),e}var Yr=n=>Math.min(Math.max(Math.round(n),0),255);function ze(n,t,e=!1){let r=Math.min(Math.max(t,0),1),s=(n>>16&255)*r,i=(n>>8&255)*r,o=(n&255)*r,a=e?0:r*255;return(Math.round(a)<<24|Math.round(o)<<16|Math.round(i)<<8|Math.round(s))>>>0}var Je=(n,t=1)=>"rgba(".concat(n>>16&255,",").concat(n>>8&255,",").concat(n&255,",").concat(t,")");function Qr(n,t){if(n===16777215)return t;if(t===16777215)return n;let e=r=>Math.round((n>>r&255)*(t>>r&255)/255);return(e(16)<<16|e(8)<<8|e(0))>>>0}var $e={linear:n=>n,quadIn:n=>n*n,quadOut:n=>n*(2-n),quadInOut:n=>n<.5?2*n*n:-1+(4-2*n)*n,cubicOut:n=>1-Ge(1-n,3),sineInOut:n=>-(Math.cos(Math.PI*n)-1)/2,backOut:n=>1+(1.70158+1)*Ge(n-1,3)+1.70158*Ge(n-1,2),elasticOut:n=>n===0||n===1?n:Ge(2,-10*n)*Math.sin((n*10-.75)*(2*Math.PI/3))+1,bounceOut:n=>n<1/2.75?7.5625*n*n:n<2/2.75?7.5625*(n-=1.5/2.75)*n+.75:n<2.5/2.75?7.5625*(n-=2.25/2.75)*n+.9375:7.5625*(n-=2.625/2.75)*n+.984375};function Cs(n){let t=n>>>0;return()=>{t=t+1831565813>>>0;let e=t;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},Ve=[],Fo="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function Ps(n){let t=T;for(let r of Fo){let s=t[r],i=new s.constructor(r==="world"?n*6:n);i.set(s),t[r]=i}let e=new Int32Array(n);for(let r=0;r<T.freeCount;r++)e[r]=T.free[(T.freeHead+r)%T.cap];for(T.free=e,T.freeHead=0,T.cap=n,T.epoch++;Ve.length<n;)Ve.push(null)}function Jr(n){T.x[n]=T.y[n]=T.rot[n]=0,T.sx[n]=T.sy[n]=T.alpha[n]=1,T.la[n]=T.ld[n]=1,T.lb[n]=T.lc[n]=0;let t=n*6,e=T.world;e[t]=e[t+3]=1,e[t+1]=e[t+2]=e[t+4]=e[t+5]=0,T.tint[n]=16777215,T.flags[n]=3,T.moved[n]=1,T.dirty[n]=0,T.parent[n]=T.first[n]=T.next[n]=T.prev[n]=-1}Ps(256);Jr(0);T.flags[0]=0;Jr(1);T.flags[1]=0;function Ls(){let n;if(T.freeCount){n=T.free[T.freeHead],T.freeHead=(T.freeHead+1)%T.cap,T.freeCount--;let t=Ve[n];t&&(t._i=0,t._g=-1,Ve[n]=null)}else T.top===T.cap&&Ps(T.cap*2),n=T.top++;return Jr(n),n}function en(n,t){pr(n);for(let r=T.first[n];r>=0;){let s=T.next[r];T.parent[r]=T.next[r]=T.prev[r]=-1,r=s}T.first[n]=-1,T.flags[n]=T.flags[n]&-3,T.moved[n]=0;let e=T.gen[n]+1;T.gen[n]=e,e!==4294967295&&(t&&(Ve[n]=t),T.free[(T.freeHead+T.freeCount)%T.cap]=n,T.freeCount++)}function Ns(n){for(let t=0;t<Ve.length;t++){let e=Ve[t];e&&n(e)&&(e._i=0,e._g=-1,Ve[t]=null)}}function Os(n,t){pr(n);let e=T.first[t];T.parent[n]=t,T.next[n]=e,T.prev[n]=-1,e>=0&&(T.prev[e]=n),T.first[t]=n,T.moved[n]=1}function pr(n){let t=T.parent[n];if(t<0)return;let e=T.next[n],r=T.prev[n];r>=0?T.next[r]=e:T.first[t]=e,e>=0&&(T.prev[e]=r),T.parent[n]=T.next[n]=T.prev[n]=-1}var Ht={root:-1,gen:-1,world:new Float64Array(6)};function Is(n){let t=++T.pass,e=T.world,r=n*6,s=Ht.world,i=Ht.root!==n||Ht.gen!==T.gen[n];for(let o=0;o<6;o++)s[o]!==e[r+o]&&(i=!0),s[o]=e[r+o];Ht.root=n,Ht.gen=T.gen[n],T.stamp[n]=i?t:t-1}function Bs(n){T.stamp[n]=T.pass}function Ds(n){for(let t=T.first[n];t>=0;){let e=T.next[t];Ds(t),t=e}en(n)}var Zr=typeof FinalizationRegistry=="function"?new FinalizationRegistry(n=>T.gen[n.i]===n.g&&Ds(n.i)):null;function tn(n){n._reg||!Zr||(n._reg=!0,Zr.register(n,{i:n._i,g:n._g},n))}function Us(n){n._reg&&Zr.unregister(n)}function Gt(n){if(n){for(let t=0;t<n.length;t++)if(n[t].enabled)return!0}return!1}function Hs(n,t){let e=0;for(let r=0;r<n.length;r++){let s=n[r];s.enabled&&s.pad&&(e+=s.pad(t))}return e}var me={gl:null,c2d:null,live:null};var q=new Float64Array(3),zt=4,Ro=1,$t=()=>Ro++;var te=Le(),_=T,we=class{constructor(t){h(this,"kernel",t);h(this,"_i",Ls());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(t){let e=this._i||1;_.x[e]=t,_.moved[e]=1}get y(){return _.y[this._i]}set y(t){let e=this._i||1;_.y[e]=t,_.moved[e]=1}get rotation(){return _.rot[this._i]}set rotation(t){let e=this._i||1;_.rot[e]=t,_.dirty[e]=_.moved[e]=1}get scaleX(){return _.sx[this._i]}set scaleX(t){let e=this._i||1;_.sx[e]=t,_.dirty[e]=_.moved[e]=1}get scaleY(){return _.sy[this._i]}set scaleY(t){let e=this._i||1;_.sy[e]=t,_.dirty[e]=_.moved[e]=1}get alpha(){return _.alpha[this._i]}set alpha(t){let e=this._i||1;_.alpha[e]=t,_.moved[e]=1}get visible(){return(_.flags[this._i]&1)!==0}set visible(t){let e=this._i||1;t?_.flags[e]=_.flags[e]|1:_.flags[e]=_.flags[e]&-2,_.moved[e]=1}get destroyed(){return _.gen[this._i]!==this._g}get world(){let t=this._i||1;return(this._wi!==t||this._we!==_.epoch)&&(this._wv=_.world.subarray(t*6,t*6+6),this._wi=t,this._we=_.epoch),this._wv}get data(){var t;return(t=this._data)!=null?t:this._data={}}set data(t){this._data=t}get scale(){return this.scaleX}set scale(t){this.scaleX=this.scaleY=t}get z(){return this._z}set z(t){t!==this._z&&(this._z=t,this.parent&&(this.parent.sortDirty=!0))}get tint(){return _.tint[this._i]}set tint(t){_.tint[this._i||1]=typeof t=="number"?t&16777215:ae(t)[0]}set anchor(t){typeof t=="number"?this.anchorX=this.anchorY=t:(this.anchorX=t.x,this.anchorY=t.y)}get width(){return 0}set width(t){}get height(){return 0}set height(t){}set(t){for(let e in t){let r=t[e];r!==void 0&&(this[e]=r)}return this}destroy(){var t;this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),en(this._i,this),Us(this),this.kernel.tweens.stopAll(this),(t=this._pool)==null||t.forget(this))}updateWorld(){let t=this.parent?this.parent.updateWorld():null;return pe(this.world,t,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(t,e,r){}};function Vs(n){Ns(t=>t.kernel===n)}var rn=!1,Gs=Object.freeze([]),rt=class n extends we{constructor(e){super(e);h(this,"children",Gs);h(this,"sortDirty",!1);h(this,"dead",!1);tn(this)}add(e,...r){this.adopt(e);for(let s=0;s<r.length;s++)this.adopt(r[s]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&Os(e._i,this._i),this.children===Gs&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||tn(e)}detach(e){let r=this.children,s=r.indexOf(e);if(s>=0){for(let i=s+1;i<r.length;i++)r[i-1]=r[i];r.pop()}e.parent===this&&(e.parent=null,e.destroyed||pr(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 r of this.children)r.destroyed?r.parent===this&&(r.parent=null):this.children[e++]=r;this.children.length=e}for(let e of this.children)e instanceof n&&e.sweep()}draw(e,r,s){if(rn)return _.parent[this._i]<0&&!this.destroyed&&Bs(this._i),this.drawChildren(e,r,s);rn=!0;try{this.destroyed||Is(this._i),this.drawChildren(e,r,s)}finally{rn=!1}}drawChildren(e,r,s){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 b,y,d,g;if(_.dirty[c]){_.dirty[c]=0;let Y=_.rot[c],N=Y?Math.cos(Y):1,O=Y?Math.sin(Y):0,z=_.sx[c],L=_.sy[c];_.la[c]=b=N*z,_.lb[c]=y=O*z,_.lc[c]=d=-O*L,_.ld[c]=g=N*L}else b=_.la[c],y=_.lb[c],d=_.lc[c],g=_.ld[c];let w=_.world,S=_.x[c],v=_.y[c],F=c*6,R=o*6,C=w[R],M=w[R+1],P=w[R+2],B=w[R+3];w[F]=C*b+P*y,w[F+1]=M*b+B*y,w[F+2]=C*d+P*g,w[F+3]=M*d+B*g,w[F+4]=C*S+P*v+w[R+4],w[F+5]=M*S+B*v+w[R+5]}let p=r*f,m=Qr(s,_.tint[c]);u.clip||u.mask||u.filters?Ws(e,u,p,m):u.draw(e,p,m)}}},he=new Float64Array(128),et=0,nn=new Float64Array(8);function sn(n,t,e,r){t.clip||t.mask||t.filters?Ws(n,t,e,r):t.draw(n,e,r)}function Ws(n,t,e,r){let s=n.r,i=t.world,o=t.clip,a=!1,l=!1;if(o)if(Math.abs(i[1])<1e-9&&Math.abs(i[2])<1e-9&&et<32){let f=i[0]*o.x+i[4],p=i[0]*(o.x+o.width)+i[4],m=i[3]*o.y+i[5],b=i[3]*(o.y+o.height)+i[5],y=Math.min(f,p),d=Math.max(f,p),g=Math.min(m,b),w=Math.max(m,b);if(et){let v=(et-1)*4;y=Math.max(y,he[v]),g=Math.max(g,he[v+1]),d=Math.min(d,he[v+2]),w=Math.min(w,he[v+3])}let S=et++*4;he[S]=y,he[S+1]=g,he[S+2]=d,he[S+3]=w,s.clip(y,g,Math.max(d-y,0),Math.max(w-g,0)),l=!0}else a=!0;let u=t.mask&&t.mask.visible?t.mask:null,c=Gt(t.filters)?t.filters:null;try{if(a&&s.beginLayer(),u&&s.beginLayer(),c?(t.draw(n,s.beginLayer()?1:e,r),s.endLayer(e,c)):t.draw(n,e,r),u&&(s.beginMask(),pe(u.world,i,u.x,u.y,u.rotation,u.scaleX,u.scaleY),sn(n,u,u.alpha,16777215),s.endLayer(1)),a&&o){s.beginMask();for(let f=0;f<4;f++){let p=f===1||f===2?o.x+o.width:o.x,m=f>1?o.y+o.height:o.y;nn[f*2]=i[0]*p+i[2]*m+i[4],nn[f*2+1]=i[1]*p+i[3]*m+i[5]}s.polygon(nn,4,16777215,1),s.endLayer(1)}}finally{if(l)if(et--,et){let f=(et-1)*4;s.clip(he[f],he[f+1],he[f+2]-he[f],he[f+3]-he[f+1])}else s.unclip()}}var be=class extends we{constructor(e,r,s){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);r&&(this.frame=r),(s==null?void 0:s.anchor)===void 0&&this.useFrameAnchor(),s&&this.set(s)}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(){var r;let e=this.frameNow();return e?((r=e.sw)!=null?r:e.w)/e.scale-e.margin*2:0}get naturalHeight(){var r;let e=this.frameNow();return e?((r=e.sh)!=null?r:e.h)/e.scale-e.margin*2:0}get width(){var e;return(e=this._w)!=null?e:this.naturalWidth}set width(e){this._w=e}get height(){var e;return(e=this._h)!=null?e:this.naturalHeight}set height(e){this._h=e}sizeQ(e){var r,s,i,o;pt[0]=(s=this._w)!=null?s:((r=e.sw)!=null?r:e.w)/e.scale-e.margin*2,pt[1]=(o=this._h)!=null?o:((i=e.sh)!=null?i: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(){var i,o;let e=this._frame;if(!e)return;let r=((i=e.sw)!=null?i:e.w)/e.scale-e.margin*2,s=((o=e.sh)!=null?o:e.h)/e.scale-e.margin*2;this.anchorX=r>0?(e.ox-e.margin)/r:0,this.anchorY=s>0?(e.oy-e.margin)/s:0}draw(e,r,s){let i=this.frameNow();if(!i)return;let o=pt;this.sizeQ(i),o[2]=this.anchorX,o[3]=this.anchorY,o[4]=r,_o(e,i,this.world,this.slice,s,this.blend)}},ft=new Float64Array(12),dt=new Float64Array(12),Vt={x:0,y:0,w:0,h:0};function zs(n,t,e,r,s,i){t=Math.max(t,0),e=Math.max(e,0),r=Math.max(r,0);let o=e+r>s?e*s/(e+r):e,a=e+r>s?r*s/(e+r):r,l=o/i,u=a/i;if(l+u>t){let c=t/(l+u);l*=c,u*=c}n[0]=0,n[1]=l,n[2]=0,n[3]=o,n[4]=l,n[5]=t-l-u,n[6]=o,n[7]=s-o-a,n[8]=t-u,n[9]=u,n[10]=s-a,n[11]=a}var pt=new Float64Array(5);function _o(n,t,e,r,s,i){var v,F,R,C,M,P,B,Y,N,O,z;let o=pt,a=o[0],l=o[1],u=o[2],c=o[3],f=o[4],p=n.tex(t.surface),m=r===0?(v=t.slice)!=null?v:0:r;if(m===0){let L=((F=t.sw)!=null?F:t.w)/t.scale-t.margin*2,G=((R=t.sh)!=null?R:t.h)/t.scale-t.margin*2,$=L>0?a/L:1,K=G>0?l/G:1,xe=-u*a+(((C=t.tx)!=null?C:0)/t.scale-t.margin)*$,Z=-c*l+(((M=t.ty)!=null?M:0)/t.scale-t.margin)*K;Wt(e,xe,Z),q[0]=t.w/t.scale*$,q[1]=t.h/t.scale*K,q[2]=f,n.r.quadQ(p,t,te,s,i);return}let b=(P=t.tx)!=null?P:0,y=(B=t.ty)!=null?B:0,d=((Y=t.sw)!=null?Y:t.w)-t.w-b,g=((N=t.sh)!=null?N:t.h)-t.h-y,w=-u*a-t.margin+b/t.scale,S=-c*l-t.margin+y/t.scale;if(zs(ft,a+t.margin*2-(b+d)/t.scale,(typeof m=="number"?m:m[3])-b,(typeof m=="number"?m:m[1])-d,t.w,t.scale),zs(dt,l+t.margin*2-(y+g)/t.scale,(typeof m=="number"?m:m[0])-y,(typeof m=="number"?m:m[2])-g,t.h,t.scale),Wt(e,w,S),q[2]=f,!((z=(O=n.r).nineQ)!=null&&z.call(O,p,t,ft,dt,te,s,i)))for(let L=0;L<12;L+=4){let G=dt[L+1],$=dt[L+3];if(!(G<=0||$<=0))for(let K=0;K<12;K+=4){let xe=ft[K+1],Z=ft[K+3];xe<=0||Z<=0||(Vt.x=t.x+ft[K+2],Vt.y=t.y+dt[L+2],Vt.w=Z,Vt.h=$,Wt(e,w+ft[K],S+dt[L]),q[0]=xe,q[1]=G,q[2]=f,n.r.quadQ(p,Vt,te,s,i))}}}function Wt(n,t,e){te[0]=n[0],te[1]=n[1],te[2]=n[2],te[3]=n[3],te[4]=n[0]*t+n[2]*e+n[4],te[5]=n[1]*t+n[3]*e+n[5]}var Me=class extends be{constructor(e,r,s={}){super(e,null);h(this,"_spec");h(this,"baked",null);h(this,"bakedEffects",!0);this._spec=r,this.bake(),s.anchor===void 0&&this.useFrameAnchor(),this.set(s)}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.autoAnchor&&this.useFrameAnchor(),this.baked)}frameNow(){return this.bake().frame}sizeQ(){var r,s;let e=this.bake();pt[0]=(r=this._w)!=null?r:e.w,pt[1]=(s=this._h)!=null?s:e.h}get width(){var e;return(e=this._w)!=null?e:this.bake().w}set width(e){this._w=e}get height(){var e;return(e=this._h)!=null?e:this.bake().h}set height(e){this._h=e}},$s=(n,t,e)=>n===void 0?t:typeof n=="number"?n:n[0]+(n[1]-n[0])*e(),tt=class tt extends we{constructor(e,r,s={}){var i,o,a,l;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=r,this.max=Math.max(1,Math.floor((i=s.max)!=null?i:200)),this.f=new Float32Array(this.max*tt.W),this.tints=new Uint32Array(this.max),this.blend=(o=s.blend)!=null?o:"normal",this.gravity=(a=s.gravity)!=null?a:0,this.drag=(l=s.drag)!=null?l:1}get alive(){return this.count}burst(e,r,s,i={}){var u,c,f,p,m;let o=tt.W,a=this.random,l=i.tint===void 0?16777215:ae(i.tint)[0];for(let b=0;b<s;b++){let y=this.count;if(y>=this.max){let F=0,R=1/0;for(let C=0;C<this.max;C++){let M=this.f[C*o+5]-this.f[C*o+4];M<R&&(R=M,F=C)}y=F}else this.count++;let d=((u=i.angle)!=null?u:0)+(i.spread===void 0?a()*Math.PI*2:(a()-.5)*i.spread),g=$s(i.speed,200,a),w=Array.isArray(i.scale)?i.scale[0]:(c=i.scale)!=null?c:1,S=Array.isArray(i.scale)?i.scale[1]:(f=i.scale)!=null?f:1,v=y*o;this.f[v]=e,this.f[v+1]=r,this.f[v+2]=Math.cos(d)*g,this.f[v+3]=Math.sin(d)*g,this.f[v+4]=0,this.f[v+5]=Math.max($s(i.life,.8,a),.01),this.f[v+6]=a()*Math.PI*2,this.f[v+7]=(a()-.5)*2*((p=i.spin)!=null?p:0),this.f[v+8]=w,this.f[v+9]=S,this.f[v+10]=(m=i.alpha)!=null?m:1,this.tints[y]=l}}update(e){let r=tt.W,s=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*r;if(s[a+4]=s[a+4]+e,s[a+4]>=s[a+5]){let l=--this.count;o!==l&&(s.copyWithin(a,l*r,l*r+r),this.tints[o]=this.tints[l]);continue}s[a+3]=(s[a+3]+this.gravity*e)*i,s[a+2]=s[a+2]*i,s[a]=s[a]+s[a+2]*e,s[a+1]=s[a+1]+s[a+3]*e,s[a+6]=s[a+6]+s[a+7]*e,o++}}clear(){this.count=0}draw(e,r,s){if(!this.count)return;let i=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,o=tt.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,m=a[p+4]/a[p+5],b=a[p+8]+(a[p+9]-a[p+8])*m,y=r*a[p+10]*(1-m*m),d=a[p+6],g=Math.cos(d)*b,w=Math.sin(d)*b,S=a[p],v=a[p+1],F=l[0],R=l[1],C=l[2],M=l[3],P=F*g+C*w,B=R*g+M*w,Y=C*g-F*w,N=M*g-R*w;te[0]=P,te[1]=B,te[2]=Y,te[3]=N,te[4]=F*S+C*v+l[4]-(P*u+Y*c)/2,te[5]=R*S+M*v+l[5]-(B*u+N*c)/2,q[0]=u,q[1]=c,q[2]=y,e.r.quadQ(e.tex(i.surface),i,te,Qr(s,this.tints[f]),this.blend)}}};h(tt,"W",11);var mt=tt;var Ae=class extends be{constructor(e,r,s={}){let f=s,{fps:i,loop:o,playing:a,speed:l,onComplete:u}=f,c=lt(f,["fps","loop","playing","speed","onComplete"]);if(!r.frames.length)throw new Error("[engine] an animation needs at least one frame");super(e,r.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=r.frames,this.durations=r.durations&&i===void 0?r.durations:null,this.fps=i!=null?i:12,this.loop=o!==!1,this.speed=l!=null?l:1,this.onComplete=u!=null?u:null,this._playing=a!==!1,this.speed<0&&this.show(r.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 r=this.frames.length;return this.show((Math.floor(e)%r+r)%r),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){var s;let r=(s=this.durations)==null?void 0:s[e];return r!==void 0&&r>0?r:1/Math.max(this.fps,.001)}update(e){var o;if(!this._playing||this.destroyed||this.speed===0)return;let r=this.frames.length,s=this.speed<0;this.t+=e*Math.abs(this.speed);let i=this.index;for(let a=0;a<1e3;a++){let l=this.secondsOf(i);if(this.t<l)break;this.t-=l;let u=s?i-1:i+1;if(u<0||u>=r){if(!this.loop){this.t=0,this._playing=!1,this.show(i),(o=this.onComplete)==null||o.call(this);return}i=s?r-1:0}else i=u}this.show(i)}},Xs=(n,t)=>n.localeCompare(t,void 0,{numeric:!0});var Xt=class{constructor(t,e,r=2){h(this,"width",t);h(this,"height",e);h(this,"padding",r);h(this,"shelves",[]);h(this,"free",[]);h(this,"bottom",0)}alloc(t,e){let r=Math.ceil(t)+this.padding*2,s=Math.ceil(e)+this.padding*2;if(r>this.width||s>this.height)return null;for(let a=0;a<this.free.length;a++){let l=this.free[a];if(l.w>=r&&l.h>=s&&l.w*l.h<=r*s*2)return this.free.splice(a,1),ke(re({},this.inner(l.x,l.y,t,e)),{slot:l})}let i=null;for(let a of this.shelves)a.h>=s&&a.h<=s*1.5+8&&this.width-a.x>=r&&(!i||a.h<i.h)&&(i=a);if(!i)if(this.bottom+s>this.height){for(let a of this.shelves)a.h>=s&&this.width-a.x>=r&&(i=a);if(!i)return null}else i={y:this.bottom,h:s,x:0},this.shelves.push(i),this.bottom+=s;let o=i.x;return i.x+=r,this.inner(o,i.y,t,e)}release(t){this.free.push({x:t.x-this.padding,y:t.y-this.padding,w:Math.ceil(t.w)+this.padding*2,h:Math.ceil(t.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(t,e,r,s){return{x:t+this.padding,y:e+this.padding,w:r,h:s}}},bt=n=>({source:n,texture:null,pending:[]}),We=class{constructor(t=2048,e=4){h(this,"pageSize",t);h(this,"maxPages",e);h(this,"pages",[]);h(this,"gen",1);h(this,"onPage",()=>{});h(this,"onDrop",()=>{})}valid(t){return!!t&&(t.gen===this.gen||t.gen===0)}bake(t,e,r,s=1,i=0,o=0,a=0){let l=Math.max(1,Math.ceil(t)),u=Math.max(1,Math.ceil(e)),c=document.createElement("canvas");c.width=l,c.height=u;let f=c.getContext("2d");return r(f),this.put(c,l,u,s,i,o,a)}add(t,e=1,r=0,s=0){let i=document.createElement("canvas");return i.width=Math.max(1,t.width),i.height=Math.max(1,t.height),i.getContext("2d").drawImage(t,0,0),this.put(i,i.width,i.height,e,r,s,0)}release(t){if(t.gen!==this.gen)return;let e=this.pages.find(r=>r.surface===t.surface);e==null||e.packer.release(t)}rebake(t,e,r,s,i=t.w,o=t.h){if(!this.valid(t)||e>i||r>o)return null;let a=Math.max(1,Math.ceil(e)),l=Math.max(1,Math.ceil(r)),u=this.pages.find(f=>f.surface===t.surface);if(!u)return null;let c=document.createElement("canvas");return c.width=Math.ceil(i),c.height=Math.ceil(o),s(c.getContext("2d")),u.ctx.clearRect(t.x,t.y,c.width,c.height),u.ctx.drawImage(c,t.x,t.y),t.surface.pending.push([c,t.x,t.y]),t.w=a,t.h=l,t}put(t,e,r,s,i,o,a){let l=null,u=this.pages.find(f=>(l=f.packer.alloc(e,r))!==null);if(u||(!(Math.max(e,r)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),u=this.pages[0],l=u?u.packer.alloc(e,r):null),(!u||!l)&&(u=this.newPage(Math.max(e,r)),l=u.packer.alloc(e,r))),!l)throw new Error("[engine] ".concat(e,"\xD7").concat(r," does not fit an atlas page"));let c=l;if(c.slot){let f=c.slot;u.ctx.clearRect(f.x,f.y,f.w,f.h);let p=document.createElement("canvas");p.width=f.w,p.height=f.h,p.getContext("2d").drawImage(t,c.x-f.x,c.y-f.y),u.surface.pending.push([p,f.x,f.y])}else u.surface.pending.push([t,c.x,c.y]);return u.ctx.drawImage(t,c.x,c.y),{surface:u.surface,x:c.x,y:c.y,w:e,h:r,scale:s,gen:this.gen,ox:i,oy:o,margin:a}}newPage(t){let e=this.pageSize;for(;e<t+4;)e*=2;let r=document.createElement("canvas");r.width=r.height=e;let s=r.getContext("2d"),i=bt(r),o={surface:i,packer:new Xt(e,e),ctx:s};return this.pages.push(o),this.onPage(i),o}wipe(){this.gen++;let t=0;for(let e=0;e<this.pages.length;e++){let r=this.pages[e];if(t<this.maxPages&&r.surface.source.width===this.pageSize){this.pages[t++]=r;continue}r.surface.pending=[],this.onDrop(r.surface)}this.pages.length=t;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 Co=()=>I.FabiPlay,br=class{constructor(){h(this,"amount",.5)}setLocal(t){this.amount=t?.8:.5}get defaultAmount(){return this.amount}posed(t,e,r,s=!0){var o,a;let i={id:t,body:e};return(a=(o=Co())==null?void 0:o.smoothedBody(i,{smooth:r<1?r:!1,interpolate:s}))!=null?a:e}};var Ks=new Float64Array(1),js=new Int32Array(Ks.buffer),yt=(n,t)=>(n=Math.imul(n^t,1540483477),n^n>>>15);function Oe(n,t=2538058380){return n!==n?yt(t,2146959360):(Ks[0]=n===0?0:n,yt(yt(t,js[0]),js[1]))}function qs(n,t=2166136261){for(let e=0;e<n.length;e++)t=Math.imul(t^n.charCodeAt(e),16777619);return t}function Se(n){switch(typeof n){case"number":return Oe(n);case"string":return qs(n);case"boolean":return n?1013904242:461845907;case"object":{if(n===null)return 625341585;if(Array.isArray(n)||n instanceof Float64Array){let r=1779033703^n.length;for(let s=0;s<n.length;s++){let i=n[s];r=yt(r,typeof i=="number"?Oe(i):Se(i))}return r}let t=1359893119,e=n;for(let r in e){let s=e[r];s!==void 0&&(t=t+yt(qs(r),Se(s))|0)}return yt(t,2600822924)}default:return 0}}function gt(n,t){if(n===t)return!0;if(typeof n!="object"||typeof t!="object"||n===null||t===null)return typeof n=="number"&&typeof t=="number"&&n!==n&&t!==t;let e=Array.isArray(n)||n instanceof Float64Array;if(e!==(Array.isArray(t)||t instanceof Float64Array))return!1;if(e){let i=n,o=t;if(i.length!==o.length)return!1;for(let a=0;a<i.length;a++)if(i[a]!==o[a]&&!gt(i[a],o[a]))return!1;return!0}let r=n,s=t;for(let i in r)if(r[i]!==void 0&&!gt(r[i],s[i]))return!1;for(let i in s)if(s[i]!==void 0&&r[i]===void 0)return!1;return!0}function jt(n){if(typeof n!="object"||n===null)return n;if(Array.isArray(n))return n.map(jt);if(n instanceof Float64Array)return n.slice();let t={};for(let e in n)n[e]!==void 0&&(t[e]=jt(n[e]));return t}var xt=class{constructor(t=1/0){h(this,"max",t);h(this,"buckets",new Map);h(this,"n",0)}get size(){return this.n}get(t,e=Se(t)){let r=this.buckets.get(e);if(r){for(let s=0;s<r.length;s++)if(gt(r[s].key,t))return r[s].value}}set(t,e,r=Se(t)){let s=this.buckets.get(r);if(s){for(let i of s)if(gt(i.key,t)){i.value=e;return}}this.n>=this.max&&this.clear(),(!s||!this.buckets.has(r))&&this.buckets.set(r,s=[]),s.push({key:jt(t),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}};var on=0,Ys=1,yr=2,an=3,vt=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*(zt+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(t){this.scale=t,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){let t=this.gq;this.grow(t[0],t[1],t[2],t[3])}grow(t,e,r,s){if(!this.real)return;let i=this.bnd,o=(this.real-1)*4;t<i[o]&&(i[o]=t),e<i[o+1]&&(i[o+1]=e),r>i[o+2]&&(i[o+2]=r),s>i[o+3]&&(i[o+3]=s)}area(t,e){let r=this.bnd,s=t*4,i=this.scale;return this.rx0=Math.max(Math.floor((r[s]-e)*i)-1,0),this.ry0=Math.max(Math.floor((r[s+1]-e)*i)-1,0),this.rx1=Math.min(Math.ceil((r[s+2]+e)*i)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((r[s+3]+e)*i)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(t,e,r,s){let i=this.scale,o=this.canvas.width,a=this.canvas.height,l=Math.min(Math.max(Math.round(t*i),0),o),u=Math.min(Math.max(Math.round(e*i),0),a),c=Math.min(Math.max(Math.round((t+r)*i),l),o),f=Math.min(Math.max(Math.round((e+s)*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(t){if(t<yr&&(this.mute||this.real>=zt||!this.pushLayer())&&(t+=2),t===an)this.mute++;else if(t!==yr){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++]=t,t<yr}beginLayer(){return this.push(on)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===on?Ys:an)}endLayer(t,e){if(!this.sp)return;let r=this.stack[--this.sp];if(r===an){if(this.mute--,!this.sp)return;r=this.stack[--this.sp]}if(r===Ys){let s=--this.real,i=this.popLayer();this.area(s-1,0)&&this.composite(i,!0,1,null);let o=this.bnd,a=(s-1)*4,l=s*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]),r=this.stack[--this.sp]}if(r===yr)Gt(e)&&(this.skipped+=e.length);else if(r===on){let s=--this.real,i=Gt(e)?e:null,o=this.popLayer();if(this.area(s,i?Hs(i,this.maxBlur):0)){this.composite(o,!1,t,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 Po=256,Qs=8<<20,ye=new Float64Array(32),ge={x:0,y:0,w:0,h:0};function Lo(n){if(typeof n.filter!="string")return!1;n.filter="blur(1px)";let t=n.filter==="blur(1px)";return n.filter="none",t}function wt(n){let t=n.getContext("2d",{alpha:!0});return t?new ln(n,t):null}var ln=class extends vt{constructor(e,r){super();h(this,"canvas",e);h(this,"ctx",r);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:Lo(r),shaders:!1},this.base=this.top={ctx:r,clipped:!1,ver:0},e.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(s=>s())}),e.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(s=>s())})}resize(e,r){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==r&&(this.canvas.height=r)}createTexture(e){return{id:$t(),width:e.width,height:e.height,source:e}}updateTexture(e,r,s=0,i=0){let o=r?s+r.width:1/0,a=r?i+r.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]>s&&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,r,s){var o;this.resetLayers(s),(o=this.fxr)==null||o.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),r>0&&(i.fillStyle=Je(e,r),i.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(e,r,s,i,o,a,l,u){q[0]=i,q[1]=o,q[2]=l,this.quadQ(e,r,s,a,u)}quadQ(e,r,s,i,o){r.w<=0||r.h<=0||(i===16777215?this.blit(e.source,r.x,r.y,r.w,r.h,s,o):this.blit(this.tint(e,r,i),0,0,r.w,r.h,s,o))}blit(e,r,s,i,o,a,l){let u=q[0],c=q[1],f=q[2];if(f<=0||this.mute)return;this.sync();let p=this.ctx,m=this.scale;if(this.real){let b=a[0]*u,y=a[1]*u,d=a[2]*c,g=a[3]*c;this.grow(a[4]+Math.min(0,b,d,b+d),a[5]+Math.min(0,y,g,y+g),a[4]+Math.max(0,b,d,b+d),a[5]+Math.max(0,y,g,y+g))}p.setTransform(a[0]*m,a[1]*m,a[2]*m,a[3]*m,a[4]*m,a[5]*m),p.globalAlpha=Math.min(f,1),l==="add"&&(p.globalCompositeOperation="lighter"),p.drawImage(e,r,s,i,o,0,0,u,c),l==="add"&&(p.globalCompositeOperation="source-over"),this.quads++}nineQ(e,r,s,i,o,a,l){var y,d,g;let u=s[8]+s[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&&q[2]>0)||this.mute)return!0;let m=this.kept(e,r,s,i,f,p,a),b=(m!=null?m:m=(g=(y=this.scratch)[d=13*Math.ceil(Math.log2(f))+Math.ceil(Math.log2(p))])!=null?g:y[d]=document.createElement("canvas").getContext("2d")).canvas;if(b.width<f&&(b.width=f),b.height<p&&(b.height=p),!this.hit){m.clearRect(0,0,f+2,p+2);for(let w=0;w<12;w+=4){let S=Math.round(i[w]*p/c),v=Math.round((i[w]+i[w+1])*p/c);for(let F=0;F<12;F+=4){let R=Math.round(s[F]*f/u),C=Math.round((s[F]+s[F+1])*f/u);ge.x=r.x+s[F+2],ge.y=r.y+i[w+2],ge.w=s[F+3],ge.h=i[w+3],!(C<=R||v<=S||ge.w<=0||ge.h<=0)&&(a===16777215?m.drawImage(e.source,ge.x,ge.y,ge.w,ge.h,R,S,C-R,v-S):m.drawImage(this.tint(e,ge,a),0,0,ge.w,ge.h,R,S,C-R,v-S))}}}return q[0]=u,q[1]=c,this.blit(b,0,0,f,p,o,l),!0}kept(e,r,s,i,o,a,l){ye[0]=e.id,ye[1]=r.x,ye[2]=r.y,ye[3]=r.w,ye[4]=r.h,ye[5]=o,ye[6]=a,ye[7]=l,ye.set(s,8),ye.set(i,20);let u=Se(ye),c=this.nines.get(u);if(this.hit=!1,c)return gt(c.key,ye)?(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 m=o*a;if(p!==this.frame-1||m>Qs)return null;let b;for(;this.ninePx+m>Qs;){let g;for(let v of this.nines.values())v.used<this.frame-1&&!(g&&g.used<=v.used)&&(g=v);if(!g)return null;let w=g.ctx.canvas,S=!b&&w.width>=o&&w.height>=a&&w.width*w.height<=2*m;this.dropNine(g,S),S&&(b=g.ctx)}let y=b!=null?b:document.createElement("canvas").getContext("2d"),d=y.canvas;return b||(d.width=o,d.height=a),this.ninePx+=d.width*d.height,this.nines.set(u,{key:jt(ye),ctx:y,used:this.frame}),y}dropNine(e,r=!1){this.nines.delete(Se(e.key));let s=e.ctx.canvas;this.ninePx-=s.width*s.height,r||(s.width=0)}dropNines(){for(let e of this.nines.values())this.dropNine(e)}tint(e,r,s){let i=Oe(s,Oe(r.h,Oe(r.w,Oe(r.y,Oe(r.x,Oe(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===r.x&&c.y===r.y&&c.w===r.w&&c.h===r.h&&c.color===s)return c.canvas}this.tintedN>=Po&&(this.tinted.clear(),this.tintedN=0,o=void 0);let a=document.createElement("canvas");a.width=Math.ceil(r.w),a.height=Math.ceil(r.h);let l=a.getContext("2d");return l.drawImage(e.source,r.x,r.y,r.w,r.h,0,0,r.w,r.h),l.globalCompositeOperation="multiply",l.fillStyle=Je(s),l.fillRect(0,0,r.w,r.h),l.globalCompositeOperation="destination-in",l.drawImage(e.source,r.x,r.y,r.w,r.h,0,0,r.w,r.h),o||this.tinted.set(i,o=[]),o.push({id:e.id,x:r.x,y:r.y,w:r.w,h:r.h,color:s,canvas:a}),this.tintedN++,a}paint(e,r){this.sync();let s=this.ctx,i=this.scale;return s.setTransform(i,0,0,i,0,0),s.globalAlpha=Math.min(r,1),Je(e)}ellipse(e,r,s,i,o,a,l){if(l<=0||s<=0||i<=0||this.mute)return;let u=Math.max(s,i);this.grow(e-u,r-u,e+u,r+u);let c=this.ctx;c.fillStyle=this.paint(a,l),c.beginPath(),c.ellipse(e,r,s,i,o,0,Math.PI*2),c.fill(),this.quads++}trace(e,r,s=0){if(this.real)for(let o=0;o<r;o++)this.grow(e[o*2]-s,e[o*2+1]-s,e[o*2]+s,e[o*2+1]+s);let i=this.ctx;i.beginPath(),i.moveTo(e[0],e[1]);for(let o=1;o<r;o++)i.lineTo(e[o*2],e[o*2+1])}polygon(e,r,s,i){if(i<=0||r<3||this.mute)return;let o=this.ctx;o.fillStyle=this.paint(s,i),this.trace(e,r),o.closePath(),o.fill(),this.quads++}stroke(e,r,s,i,o,a){if(o<=0||s<=0||r<1||this.mute)return;let l=this.ctx;l.strokeStyle=this.paint(i,o),l.lineWidth=s,l.lineCap="round",l.lineJoin="round",this.trace(e,r,s/2),r===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 r=e.ctx;e.clipped&&r.restore(),e.clipped=this.cOn,e.ver=this.clipVer,this.cOn&&(r.save(),r.setTransform(1,0,0,1,0,0),r.beginPath(),r.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),r.clip())}pushLayer(){let e=this.canvas.width,r=this.canvas.height,s=this.layers[this.real];if(!s||s.ctx.canvas.width!==e||s.ctx.canvas.height!==r){let o=document.createElement("canvas");o.width=e,o.height=r;let a=o.getContext("2d");if(!a)return!1;s=this.layers[this.real]={ctx:a,clipped:!1,ver:-1}}let i=s.ctx;return s.clipped&&i.restore(),s.clipped=!1,s.ver=-1,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,e,r),this.top=s,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,r,s,i){var b;let o=e,a="none",l=i&&me.c2d?(b=this.fxr)!=null?b:this.fxr=me.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,m=this.ry1-f;u.setTransform(1,0,0,1,0,0),u.globalAlpha=Math.min(s,1),u.globalCompositeOperation=r?"destination-in":"source-over",a!=="none"&&(u.filter=a),u.drawImage(o,c,f,p,m,c,f,p,m),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(){var e;this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],(e=this.fxr)==null||e.destroy(),this.fxr=null}};var gr=class{constructor(t,e,r=8192){h(this,"instanced",t);h(this,"slots",e);h(this,"capacity",r);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 s=r*(t?14:24),i=new ArrayBuffer(s*4);this.f32=new Float32Array(i),this.u32=new Uint32Array(i)}slot(t){let e=this.textures;for(let r=0;r<this.bound;r++)if(e[r]===t)return r;return this.bound>=this.slots?-1:(e[this.bound]=t,this.bound++)}has(t){for(let e=0;e<this.bound;e++)if(this.textures[e]===t)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 t=0;t<this.bound;t++)this.textures[t]=null;this.bound=0}push(t,e,r,s,i,o,a,l,u,c,f,p,m,b){let y=this.f32;if(this.instanced){let d=this.quads*14;y[d++]=t,y[d++]=e,y[d++]=r,y[d++]=s,y[d++]=i,y[d++]=o,y[d++]=a,y[d++]=l,y[d++]=u,y[d++]=c,y[d++]=f,y[d++]=p,this.u32[d++]=m,y[d]=b}else{let d=this.quads*6*4;this.vertex(d,t,e,u,c,m,b),this.vertex(d+6,r,s,f,c,m,b),this.vertex(d+12,i,o,f,p,m,b),this.vertex(d+18,a,l,u,p,m,b)}this.quads++}pushQ(t,e){let r=this.f32;if(this.instanced){let s=this.quads*14;for(let i=0;i<12;i++)r[s+i]=t[i];this.u32[s+12]=t[12],r[s+13]=e}else{let s=this.quads*6*4,i=t[12];for(let o=0;o<4;o++,s+=6)r[s]=t[o*2],r[s+1]=t[o*2+1],r[s+2]=o===1||o===2?t[10]:t[8],r[s+3]=o>=2?t[11]:t[9],this.u32[s+4]=i,r[s+5]=e}this.quads++}vertex(t,e,r,s,i,o,a){let l=this.f32;l[t]=e,l[t+1]=r,l[t+2]=s,l[t+3]=i,this.u32[t+4]=o,l[t+5]=a}};function Zs(n){let t=new Uint16Array(n*6);for(let e=0,r=0,s=0;e<n;e++,r+=6,s+=4)t[r]=s,t[r+1]=s+1,t[r+2]=s+2,t[r+3]=s,t[r+4]=s+2,t[r+5]=s+3;return t}var fe={M:0,L:1,Q:2,C:3,Z:4},oi=[2,2,4,6,0],No={M:0,L:1,Q:2,C:3,Z:4};function Sr(n,t){if(n.length>=t)return n;let e=new Float64Array(Math.max(t,n.length*2,16));return e.set(n),e}var xr=new Map;function Oo(n){var s,i;if(typeof n!="string")return n;let t=xr.get(n);if(t)return t;t=[];let e=(s=n.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi))!=null?s:[],r=-1;for(let o=0;o<e.length;){let a=e[o],l=No[a.toUpperCase()];if(l!==void 0){r=l,o++,l===fe.Z&&t.push(fe.Z);continue}if(r<0||r===fe.Z){o++;continue}let u=oi[r];t.push(r);for(let c=0;c<u;c++)t.push(Number((i=e[o+c])!=null?i:0));o+=u,r===fe.M&&(r=fe.L)}return xr.size>256&&xr.clear(),xr.set(n,t),t}var je={subs:[],count:0},un=null,Xe=null;function vr(n,t){var i;let e=Xe;e||(e=(i=je.subs[je.count])!=null?i:null,e||je.subs.push(e={pts:new Float64Array(64),n:0,closed:!1}),e.n=0,e.closed=!1,je.count++,Xe=e);let r=e.n*2;r+2>e.pts.length&&(e.pts=Sr(e.pts,r+2));let s=un;s?(e.pts[r]=s[0]*n+s[2]*t+s[4],e.pts[r+1]=s[1]*n+s[3]*t+s[5]):(e.pts[r]=n,e.pts[r+1]=t),e.n++}function Tr(n,t=null,e=1,r=6){let s=Oo(n);je.count=0,Xe=null,un=t;let i=0,o=0,a=0,l=0,u=e/r;for(let c=0;c<s.length;){let f=s[c++],p=s;if(f===fe.M)Xe=null,i=a=p[c],o=l=p[c+1],vr(i,o);else if(f===fe.L)i=p[c],o=p[c+1],vr(i,o);else if(f===fe.Q){let m=p[c],b=p[c+1],y=p[c+2],d=p[c+3],g=Js((Ee(m-i,b-o)+Ee(y-m,d-b))*u);for(let w=1;w<=g;w++){let S=w/g,v=1-S;vr(v*v*i+2*v*S*m+S*S*y,v*v*o+2*v*S*b+S*S*d)}i=y,o=d}else if(f===fe.C){let m=p[c],b=p[c+1],y=p[c+2],d=p[c+3],g=p[c+4],w=p[c+5],S=Js((Ee(m-i,b-o)+Ee(y-m,d-b)+Ee(g-y,w-d))*u);for(let v=1;v<=S;v++){let F=v/S,R=1-F,C=R*R*R,M=3*R*R*F,P=3*R*F*F,B=F*F*F;vr(C*i+M*m+P*y+B*g,C*o+M*b+P*d+B*w)}i=g,o=w}else if(f===fe.Z){Xe&&(Xe.closed=!0),Xe=null,i=a,o=l;continue}else break;c+=oi[f]}Xe=null,un=null;for(let c=0;c<je.count;c++){let f=je.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 je}var Ee=(n,t)=>Math.sqrt(n*n+t*t),Js=n=>Math.min(Math.max(Math.ceil(n),2),24);function Io(n,t){let e=0;for(let r=0,s=t-1;r<t;s=r++)e+=(n[s*2]-n[r*2])*(n[s*2+1]+n[r*2+1]);return e}var wr=new Int32Array(64),Ar=(n,t,e,r,s)=>((n[r*2]-n[e*2])*(n[s*2+1]-n[e*2+1])-(n[r*2+1]-n[e*2+1])*(n[s*2]-n[e*2]))*t;function ai(n,t,e){if(t<3)return 0;wr.length<t&&(wr=new Int32Array(Math.max(t,wr.length*2)));let r=wr,s=t,i=0;for(let u=0;u<t;u++)r[u]=u;let o=Io(n,t)>0?1:-1,a=t*t+8,l=0;for(;s>3&&a-- >0;){let u=r[(l+s-1)%s],c=r[l%s],f=r[(l+1)%s],p=Ar(n,o,u,c,f)>0;if(p)for(let m=0;m<s;m++){let b=r[m];if(!(b===u||b===c||b===f)&&Ar(n,o,u,c,b)>=0&&Ar(n,o,c,f,b)>=0&&Ar(n,o,f,u,b)>=0){p=!1;break}}p?(e[i++]=u,e[i++]=c,e[i++]=f,r.copyWithin(l%s,l%s+1,s),s--,l=Math.max(l-1,0)):l=(l+1)%s}if(s===3)e[i++]=r[0],e[i++]=r[1],e[i++]=r[2];else if(s>3)for(let u=1;u+1<s;u++)e[i++]=r[0],e[i++]=r[u],e[i++]=r[u+1];return i}var Bo=.85,kr=new Float64Array(64),ei=new Float64Array(64),ti=new Float64Array(64),ri=new Float64Array(64),ni=new Float64Array(64),si=new Float64Array(64),ii=new Uint8Array(64),qt=new Float64Array(8);function li(n,t,e,r,s,i){let o=qt;if(kr.length<t){let d=Math.max(t,kr.length*2);kr=new Float64Array(d),ei=new Float64Array(d),ti=new Float64Array(d),ri=new Float64Array(d),ni=new Float64Array(d),si=new Float64Array(d),ii=new Uint8Array(d)}let a=kr,l=ei,u=0;for(let d=0;d<t;d++){let g=n[d*2],w=n[d*2+1];!Number.isFinite(g)||!Number.isFinite(w)||u&&Math.abs(a[u-1]-g)<.001&&Math.abs(l[u-1]-w)<.001||(a[u]=g,l[u]=w,u++)}if(r&&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=r?u:u-1,f=ti,p=ri;for(let d=0;d<c;d++){let g=(d+1)%u,w=a[g]-a[d],S=l[g]-l[d],v=Ee(w,S)||1;f[d]=-S/v,p[d]=w/v}let m=ni,b=si,y=ii;for(let d=0;d<u;d++){let g=r?(d-1+c)%c:d-1,w=d<c?d:-1;if(y[d]=1,g<0||w<0||f[g]*f[w]+p[g]*p[w]<Bo)continue;let v=f[g]+f[w],F=p[g]+p[w],R=Ee(v,F)||1;v/=R,F/=R;let C=e/Math.max(v*f[w]+F*p[w],.5);m[d]=v*C,b[d]=F*C,y[d]=0}for(let d=0;d<c;d++){let g=(d+1)%u,w=y[d]?f[d]*e:m[d],S=y[d]?p[d]*e:b[d],v=y[g]?f[d]*e:m[g],F=y[g]?p[d]*e:b[g];o[0]=a[d]+w,o[1]=l[d]+S,o[2]=a[g]+v,o[3]=l[g]+F,o[4]=a[g]-v,o[5]=l[g]-F,o[6]=a[d]-w,o[7]=l[d]-S,s()}for(let d=0;d<u;d++)y[d]&&(o[0]=a[d],o[1]=l[d],i())}function cn(n,t){let e=0,r=1/0;for(let s=0;s<t.length;s++){let i=Math.abs(Math.log(Math.max(n,.5)/t[s]));i<r&&(r=i,e=s)}return e}var Mr=[{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}],Er=[4,8,16,32,64,128].map((n,t)=>({x:t*4,y:128,w:4,h:n,r:n/2-1})),Ie={x:248,y:248,w:8,h:8},ci=Mr.map(n=>n.r*2),hi=Er.map(n=>n.r*2),ui=(n,t)=>Math.min(Math.max(n+.5-t,0),1);function Do(){let n=new Uint8ClampedArray(262144),t=(e,r,s)=>{let i=(r*256+e)*4;n[i]=n[i+1]=n[i+2]=255,n[i+3]=Math.round(s*255)};for(let e of Mr){let r=e.w/2;for(let s=0;s<e.h;s++)for(let i=0;i<e.w;i++)t(e.x+i,e.y+s,ui(e.r,Math.hypot(i+.5-r,s+.5-r)))}for(let e of Er){let r=e.h/2;for(let s=0;s<e.h;s++)for(let i=0;i<e.w;i++)t(e.x+i,e.y+s,ui(e.r,Math.abs(s+.5-r)))}for(let e=0;e<Ie.h;e++)for(let r=0;r<Ie.w;r++)t(Ie.x+r,Ie.y+e,1);return n}function fi(){let n=document.createElement("canvas");return n.width=n.height=256,n.getContext("2d").putImageData(new ImageData(Do(),256,256),0,0),n}var di=8,Fr="\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n",zo=n=>"".concat(Fr,"\nuniform sampler2D uTex[").concat(n,"];\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSlot;\nvoid main() {\n vec4 c;\n ").concat(Array.from({length:n},(t,e)=>e===n-1?"c = texture2D(uTex[".concat(e,"], vUv);"):"if (vSlot < ".concat(e,".5) c = texture2D(uTex[").concat(e,"], vUv); else ")).join("\n "),"\n gl_FragColor = c * vColor;\n}"),$o="\nattribute vec2 aPos;\nattribute vec2 aUv;\nattribute vec4 aColor;\nattribute float aSlot;\nuniform vec2 uScale;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSlot;\nvoid main() {\n vUv = aUv;\n vColor = aColor;\n vSlot = aSlot;\n gl_Position = vec4(aPos * uScale + vec2(-1.0, 1.0), 0.0, 1.0);\n}",Vo="\nattribute vec4 aCorner;\nattribute vec4 aP01;\nattribute vec4 aP23;\nattribute vec4 aUvRect;\nattribute vec4 aColor;\nattribute float aSlot;\nuniform vec2 uScale;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSlot;\nvoid main() {\n vec2 p = aP01.xy * aCorner.x + aP01.zw * aCorner.y + aP23.xy * aCorner.z + aP23.zw * aCorner.w;\n vUv = vec2(mix(aUvRect.x, aUvRect.z, aCorner.y + aCorner.z), mix(aUvRect.y, aUvRect.w, aCorner.z + aCorner.w));\n vColor = aColor;\n vSlot = aSlot;\n gl_Position = vec4(p * uScale + vec2(-1.0, 1.0), 0.0, 1.0);\n}",Wo={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},Xo=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],jo=["aPos","aUv","aColor","aSlot"];function mi(n,t,e={}){var i,o;let r=ke(re({},Wo),{failIfMajorPerformanceCaveat:e.failIfMajorPerformanceCaveat!==!1}),s=t===2?n.getContext("webgl2",r):(i=n.getContext("webgl",r))!=null?i:n.getContext("experimental-webgl",r);if(!s||s.isContextLost())return null;try{return new hn(n,s,t,e)}catch(a){return console.warn("[engine] WebGL setup failed:",a),(o=s.getExtension("WEBGL_lose_context"))==null||o.loseContext(),null}}var hn=class extends vt{constructor(e,r,s,i){super();h(this,"canvas",e);h(this,"gl",r);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(di).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(qt),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(qt[0],qt[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 r of this.lostListeners)r()});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=s===2?"webgl2":"webgl1",this.maxTextureSize=r.getParameter(r.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(fi()),me.live=this,e.addEventListener("webglcontextlost",this.onContextLost,!1),e.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){let e=this.gl,r=this.kind==="webgl2"?e:null;if(this.inst=null,this.opts.instancing!==!1)if(r)this.inst={divisor:(f,p)=>r.vertexAttribDivisor(f,p),draw:(f,p)=>r.drawElementsInstanced(e.TRIANGLES,f,e.UNSIGNED_SHORT,0,p)};else{let f=e.getExtension("ANGLE_instanced_arrays");f&&(this.inst={divisor:(p,m)=>f.vertexAttribDivisorANGLE(p,m),draw:(p,m)=>f.drawElementsInstancedANGLE(e.TRIANGLES,p,e.UNSIGNED_SHORT,0,m)})}if(this.vaoApi=null,this.opts.vao!==!1)if(r)this.vaoApi={create:()=>r.createVertexArray(),bind:f=>r.bindVertexArray(f),remove:f=>r.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 s=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),i=Math.max(1,Math.min(di,s)),o=this.inst!==null;this.vsrc=o?Vo:$o,this.attrs=o?Xo:jo,this.main=this.cur=this.build(zo(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 gr(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,Zs(o?1:8192),e.STATIC_DRAW);let l=f=>e.getAttribLocation(a,f),u=(f,p,m,b,y,d,g)=>{let w=l(f);w<0||(e.enableVertexAttribArray(w),e.vertexAttribPointer(w,p,m,b,y,d),this.inst&&this.inst.divisor(w,g))};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 r=this.gl,s=r.createTexture();return this.bindTex(s),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),s}resize(e,r){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==r&&(this.canvas.height=r)}createTexture(e){let r={id:$t(),width:e.width,height:e.height,source:e};return this.textures.set(r,this.lost?null:this.upload(e)),r}updateTexture(e,r,s=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),!r||r===e.source&&s===0&&i===0?o.texImage2D(o.TEXTURE_2D,0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,e.source):o.texSubImage2D(o.TEXTURE_2D,0,s,i,o.RGBA,o.UNSIGNED_BYTE,r))}destroyTexture(e){this.batch.has(e)&&this.flush();let r=this.textures.get(e);r&&!this.lost&&this.deleteTex(r),this.textures.delete(e)}begin(e,r,s){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(s),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=r;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*s/this.canvas.width,-2*s/this.canvas.height),this.mapped=!0}build(e){var a;let r=this.gl,s=pi(r,r.VERTEX_SHADER,this.vsrc),i;try{i=pi(r,r.FRAGMENT_SHADER,e)}catch(l){throw r.deleteShader(s),l}let o=r.createProgram();if(r.attachShader(o,s),r.attachShader(o,i),this.attrs.forEach((l,u)=>r.bindAttribLocation(o,u,l)),r.linkProgram(o),r.deleteShader(s),r.deleteShader(i),!r.getProgramParameter(o,r.LINK_STATUS)){let l=(a=r.getProgramInfoLog(o))!=null?a:"?";throw r.deleteProgram(o),new Error("link: ".concat(l))}return{p:o,uScale:r.getUniformLocation(o,"uScale"),locs:new Map}}u(e,r){let s=e.locs.get(r);return s===void 0&&e.locs.set(r,s=this.gl.getUniformLocation(e.p,r)),s}use(e){this.cur!==e&&(this.cur=e,this.gl.useProgram(e.p),this.calls.useProgram++)}bindTex(e,r=this.unit<0?0:this.unit){let s=this.gl;this.onUnit[r]!==e&&(this.unit!==r&&(s.activeTexture(s.TEXTURE0+r),this.calls.activeTexture++,this.unit=r),s.bindTexture(s.TEXTURE_2D,e),this.calls.bindTexture++,this.onUnit[r]=e)}deleteTex(e){this.gl.deleteTexture(e);for(let r=0;r<this.onUnit.length;r++)this.onUnit[r]===e&&(this.onUnit[r]=null)}bindFb(e){if(e)for(let s=0;s<this.onUnit.length;s++)this.onUnit[s]===e.gl&&this.bindTex(null,s);let r=e?e.fb:null;this.fbNow!==r&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,r),this.calls.bindFramebuffer++,this.fbNow=r)}slotOf(e){this.batch.full&&this.flush();let r=this.batch.slot(e);return r<0&&(this.flush(),r=this.batch.slot(e)),r}quad(e,r,s,i,o,a,l,u){q[0]=i,q[1]=o,q[2]=l,this.quadQ(e,r,s,a,u)}quadQ(e,r,s,i,o){let a=q[2];if(this.lost||a<=0)return;let l=this.q,u=q[0],c=q[1],f=s[4],p=s[5],m=s[0]*u,b=s[1]*u,y=s[2]*c,d=s[3]*c;l[0]=f,l[1]=p,l[2]=m+f,l[3]=b+p,l[4]=m+y+f,l[5]=b+d+p,l[6]=y+f,l[7]=d+p;let g=1/e.width,w=1/e.height;l[8]=r.x*g,l[9]=r.y*w,l[10]=(r.x+r.w)*g,l[11]=(r.y+r.h)*w,l[12]=ze(i,a,o==="add"),this.put(e)}put(e){if(this.mute)return;let r=this.q,s=!1,i=Math.min(r[0],r[2],r[4],r[6]),o=Math.max(r[0],r[2],r[4],r[6]),a=Math.min(r[1],r[3],r[5],r[7]),l=Math.max(r[1],r[3],r[5],r[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,m=this.px1/c,b=this.py1/c;if(o<=f||i>=m||l<=p||a>=b)return;if(i<f||o>m||a<p||l>b){let y=r[0],d=r[1],g=r[2],w=r[5];if(d===r[3]&&g===r[4]&&w===r[7]&&r[6]===y){if(y!==g){let S=Math.min(Math.max(y,f),m),v=Math.min(Math.max(g,f),m),F=r[8],R=(r[10]-F)/(g-y);r[10]=F+(v-y)*R,r[8]=F+(S-y)*R,r[0]=r[6]=S,r[2]=r[4]=v}if(d!==w){let S=Math.min(Math.max(d,p),b),v=Math.min(Math.max(w,p),b),F=r[9],R=(r[11]-F)/(w-d);r[11]=F+(v-d)*R,r[9]=F+(S-d)*R,r[1]=r[3]=S,r[5]=r[7]=v}}else s=!0}}let u=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(s?(!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(r,this.slotOf(e))}ellipse(e,r,s,i,o,a,l){if(this.lost||l<=0||s<=0||i<=0)return;let u=Mr[cn(Math.max(s,i)*2*this.scale,ci)],c=u.w/2/u.r,f=s*c,p=i*c,m=Math.cos(o),b=Math.sin(o),y=m*f,d=b*f,g=-b*p,w=m*p,S=1/256,v=this.q;v[0]=e-y-g,v[1]=r-d-w,v[2]=e+y-g,v[3]=r+d-w,v[4]=e+y+g,v[5]=r+d+w,v[6]=e-y+g,v[7]=r-d+w,v[8]=u.x*S,v[9]=u.y*S,v[10]=(u.x+u.w)*S,v[11]=(u.y+u.h)*S,v[12]=ze(a,l),this.put(this.kit)}polygon(e,r,s,i){if(this.lost||i<=0||r<3)return;this.tris.length<r*3&&(this.tris=new Int32Array(Math.max(r*3,this.tris.length*2)));let o=this.tris,a=ai(e,r,o),l=ze(s,i),u=(Ie.x+Ie.w/2)/256,c=(Ie.y+Ie.h/2)/256;for(let f=0;f<a;f+=3){let p=o[f]*2,m=o[f+1]*2,b=o[f+2]*2,y=this.q;y[0]=e[p],y[1]=e[p+1],y[2]=e[m],y[3]=e[m+1],y[4]=y[6]=e[b],y[5]=y[7]=e[b+1],y[8]=y[10]=u,y[9]=y[11]=c,y[12]=l,this.put(this.kit)}}stroke(e,r,s,i,o,a){if(this.lost||o<=0||s<=0||r<1)return;let l=Er[cn(s*this.scale,hi)],u=s/2*(l.h/2/l.r);this.sPacked=ze(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=s/2,li(e,r,u,a,this.strokeSeg,this.strokeDisc)}target(e,r,s,i){let o=this.gl,a=o.createTexture();this.bindTex(a),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,e,r,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:$t(),width:e,height:r,source:this.canvas},gl:a,fb:u,w:e,h:r,f:s};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){var o;let r=this.canvas.width,s=this.canvas.height,i=(o=this.layers[e])!=null?o:null;return i&&(i.w!==r||i.h!==s)&&(this.drop(i),i=this.layers[e]=null),i!=null?i:this.layers[e]=this.target(r,s,1,!1)}pushLayer(){if(this.lost)return!1;this.flush();let e=this.layerAt(this.real);if(!e)return!1;let r=this.gl;return this.bindFb(e),r.disable(r.SCISSOR_TEST),r.clearColor(0,0,0,0),r.clear(r.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){var e;return this.lost||!me.gl?null:(e=this.fxr)!=null?e:this.fxr=me.gl(this)}composite(e,r,s,i){var a;if(i&&((a=this.filters())!=null&&a.chain(e,s,i)))return;let o=this.gl;r&&o.blendFunc(o.ZERO,o.SRC_ALPHA),this.final(this.main,e,1,s),r&&(this.flush(),o.blendFunc(o.ONE,o.ONE_MINUS_SRC_ALPHA))}final(e,r,s,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,m=this.ry1/u,b=1/(s*r.width),y=1/(s*r.height),d=this.q;d[0]=d[6]=c,d[1]=d[3]=f,d[2]=d[4]=p,d[5]=d[7]=m,d[8]=this.rx0*b,d[9]=1-this.ry0*y,d[10]=this.rx1*b,d[11]=1-this.ry1*y,d[12]=ze(16777215,i),this.put(r),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 r=this.gl,s=e.words;if(this.kind==="webgl2")return r.bufferSubData(r.ARRAY_BUFFER,0,e.f32,0,s);let i=this.views.get(s);i||(this.views.size>=256&&this.views.clear(),this.views.set(s,i=e.f32.subarray(0,s))),r.bufferSubData(r.ARRAY_BUFFER,0,i)}flush(){var s,i;let e=this.batch;if(!e.quads||this.lost)return e.reset();let r=this.gl;this.bScis?(r.enable(r.SCISSOR_TEST),r.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):r.disable(r.SCISSOR_TEST),this.upload2(e);for(let o=0;o<e.bound;o++){let a=e.textures[o];this.bindTex((i=(s=this.textures.get(a))!=null?s:this.layerTex.get(a))!=null?i:null,o)}this.inst?this.inst.draw(6,e.quads):r.drawElements(r.TRIANGLES,e.quads*6,r.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(){var r,s;let e=this.gl;me.live===this&&(me.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(let i of this.textures.values())i&&e.deleteTexture(i);for(let i of this.layers)i&&(e.deleteTexture(i.gl),e.deleteFramebuffer(i.fb));(r=this.fxr)==null||r.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),(s=e.getExtension("WEBGL_lose_context"))==null||s.loseContext()}catch(i){}this.textures.clear()}};function pi(n,t,e){var s;let r=n.createShader(t);if(n.shaderSource(r,e),n.compileShader(r),!n.getShaderParameter(r,n.COMPILE_STATUS)){let i=(s=n.getShaderInfoLog(r))!=null?s:"?";throw n.deleteShader(r),new Error(i)}return r}function fn(n="auto"){switch(n){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function kt(n,t={}){let e=n;for(let r of fn(t.renderer)){let s=r==="canvas2d"?wt(e):mi(e,r==="webgl2"?2:1,t);if(s)return s;e=Kt(e)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function Kt(n){var e;let t=n.cloneNode(!1);return(e=n.parentNode)==null||e.replaceChild(t,n),t}function bi(n=typeof location!="undefined"?location.search:""){let t=new URLSearchParams(n).get("renderer");return t==="canvas"?"canvas2d":t==="webgl2"||t==="webgl1"||t==="canvas2d"||t==="webgl"||t==="auto"?t:void 0}var qe=class{constructor(t,e={}){h(this,"atlas",t);h(this,"tags",new Map);h(this,"count",0);h(this,"m",Le());h(this,"measure",null);h(this,"height");h(this,"font");var r,s;this.height=(r=e.tagHeight)!=null?r:34,this.font=(s=e.tagFont)!=null?s:"Nunito, sans-serif"}drop(){for(let t of this.tags.values())for(let e of t.values())for(let r of e.values())this.atlas.release(r);this.tags.clear(),this.count=0}get(t,e,r){let s=this.tags.get(t);s||this.tags.set(t,s=new Map);let i=s.get(e);i||s.set(e,i=new Map);let o=i.get(r);return o&&this.atlas.valid(o)?o:this.bake(t,e,r)}bake(t,e,r){var p;let s=this.height,i="700 ".concat(Math.round(s*.65),"px ").concat(this.font),o=(p=this.measure)!=null?p:this.measure=document.createElement("canvas").getContext("2d");o.font=i;let a=Math.round(s*.4),l=Math.ceil(o.measureText(t).width)+a*2,u=this.atlas.bake((l+2)*r,(s+2)*r,m=>{m.scale(r,r),m.translate(1,1);let b=s/2;m.beginPath(),m.moveTo(b,0),m.lineTo(l-b,0),m.arc(l-b,b,b,-Math.PI/2,Math.PI/2),m.lineTo(b,s),m.arc(b,b,b,Math.PI/2,Math.PI*3/2),m.closePath(),m.fillStyle=e,m.fill(),m.fillStyle="#fff",m.font=i,m.textAlign="center",m.textBaseline="middle",m.fillText(t,l/2,s/2+1)},r,1,1,1);++this.count>64&&(this.drop(),this.count=1);let c=this.tags.get(t);c||this.tags.set(t,c=new Map);let f=c.get(e);return f||c.set(e,f=new Map),f.set(r,u),u}draw(t,e,r,s,i,o,a,l,u,c,f){let p=Es(r,i,{band:qo(s)});if(!p)return;let m=this.height,b=this.get(o,a,u),y=b.w/b.scale-2,d=Math.min(Math.max(p.head.x-y/2,4),c-y-4),g=Math.min(Math.max(p.head.y-p.headR*2.2-m,4),f-m-4);pe(this.m,null,d-1,g-1,0,1,1),t.quad(e(b.surface),b,this.m,b.w/b.scale,b.h/b.scale,16777215,l,"normal")}},qo=n=>n.band==="3-5"||n.band==="9-12"?n.band:"6-8";var Ko=(n,t=!1)=>t?Math.min(Ge(2,Math.round(Math.log2(Math.max(n,8)))),256):Math.min(Ge(2,Math.ceil(Math.log2(Math.max(n,8))*2)/2),512);function _r(n,t=null){var s,i,o,a;let e={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},r=(l,u,c)=>{let f=t?t[0]*l+t[2]*u+t[4]:l,p=t?t[1]*l+t[3]*u+t[5]:u,m=t?Math.hypot(t[0],t[1]):1;e.minX=Math.min(e.minX,f-c*m),e.minY=Math.min(e.minY,p-c*m),e.maxX=Math.max(e.maxX,f+c*m),e.maxY=Math.max(e.maxY,p+c*m)};for(let l of n){let u="lw"in l&&l.stroke?((s=l.lw)!=null?s:1)/2:0;switch(l.k){case"circle":r(l.x-l.r,l.y-l.r,u),r(l.x+l.r,l.y+l.r,u),r(l.x-l.r,l.y+l.r,u),r(l.x+l.r,l.y-l.r,u);break;case"ellipse":case"rect":{let c=l.k==="ellipse"?Math.max(l.rx,l.ry):Math.hypot(l.w,l.h)/2;r(l.x-c,l.y-c,u),r(l.x+c,l.y+c,u),r(l.x-c,l.y+c,u),r(l.x+c,l.y-c,u);break}case"path":{let c=Tr(l.d);for(let f=0;f<c.count;f++){let p=c.subs[f];for(let m=0;m<p.n;m++)r(p.pts[m*2],p.pts[m*2+1],u)}break}case"line":for(let c=0;c+1<l.pts.length;c+=2)r(l.pts[c],l.pts[c+1],u);break;case"group":{let c=pe(Le(),t,l.x,l.y,(i=l.rot)!=null?i:0,(o=l.s)!=null?o:1,(a=l.s)!=null?a:1),f=_r(l.items,c);Number.isFinite(f.minX)&&(e.minX=Math.min(e.minX,f.minX),e.minY=Math.min(e.minY,f.minY),e.maxX=Math.max(e.maxX,f.maxX),e.maxY=Math.max(e.maxY,f.maxY));break}}}return e}var nt=class{constructor(t){h(this,"atlas",t);h(this,"seen",new WeakSet);h(this,"baked",new WeakMap);h(this,"m",Le());h(this,"stack",[]);h(this,"local",Le());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(t){let e=t==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(let r of this.live)this.atlas.release(r.frame);this.live.clear()}}draw(t,e,r,s,i,o,a){var c;let l=typeof s=="string"?(c=ct(s))!=null?c:ht:s,u=Ms(r,l,i);return u.length?(o<=0||(o<1?(this.paint(t,e,u,null,t.beginLayer()?1:o,a),t.endLayer(o)):this.paint(t,e,u,null,o,a)),!0):!1}paint(t,e,r,s,i,o,a=0){var l,u,c,f,p,m,b,y,d,g,w;for(let S=0;S<r.length;S++){let v=r[S];if(v.k==="group"){let N=pe((u=(l=this.stack)[a])!=null?u:l[a]=Le(),s,v.x,v.y,(c=v.rot)!=null?c:0,(f=v.s)!=null?f:1,(p=v.s)!=null?p:1),O=i*((m=v.alpha)!=null?m:1);if(this.bakeGroups&&this.seen.has(v.items)){let z=Ee(N[0],N[1])*o,L=this.bake(v.items,z);if(L){let G=L.frame,$=this.m;$.set(N),$[4]=N[0]*-L.ox+N[2]*-L.oy+N[4],$[5]=N[1]*-L.ox+N[3]*-L.oy+N[5],t.quad(e(G.surface),G,$,G.w/L.k,G.h/L.k,16777215,O,"normal"),this.stats.baked++;continue}}this.seen.add(v.items),this.stats.vector++,this.paint(t,e,v.items,N,O,o,a+1);continue}let F=i*((b=v.alpha)!=null?b:1),R=s?Ee(s[0],s[1]):1,C=s?Math.atan2(s[1],s[0]):0,M=((y=v.lw)!=null?y:1)*R,P=v.stroke&&((d=v.lw)!=null?d:1)>0?ae(v.stroke):null,B=v.fill&&v.k!=="line"?ae(v.fill):null;if(v.k==="circle"||v.k==="ellipse"){let N=s?s[0]*v.x+s[2]*v.y+s[4]:v.x,O=s?s[1]*v.x+s[3]*v.y+s[5]:v.y,z=(v.k==="circle"?v.r:v.rx)*R,L=(v.k==="circle"?v.r:v.ry)*R,G=(v.k==="ellipse"&&(g=v.rot)!=null?g:0)+C;if(B&&P)t.ellipse(N,O,z+M/2,L+M/2,G,P[0],F*P[1]),t.ellipse(N,O,Math.max(z-M/2,0),Math.max(L-M/2,0),G,B[0],F*B[1]);else if(B)t.ellipse(N,O,z,L,G,B[0],F*B[1]);else if(P){let $=Math.min(Math.max(Math.ceil(Math.max(z,L)*o*.6),12),64),K=this.pts=Sr(this.pts,$*2),xe=Math.cos(G),Z=Math.sin(G);for(let le=0;le<$;le++){let ot=le/$*Math.PI*2,ie=Math.cos(ot)*z,ve=Math.sin(ot)*L;K[le*2]=N+ie*xe-ve*Z,K[le*2+1]=O+ie*Z+ve*xe}t.stroke(K,$,M,P[0],F*P[1],!0)}continue}if(v.k==="line"){if(!P)continue;let N=v.pts.length>>1,O=this.pts=Sr(this.pts,N*2);for(let z=0;z<N;z++){let L=v.pts[z*2],G=v.pts[z*2+1];O[z*2]=s?s[0]*L+s[2]*G+s[4]:L,O[z*2+1]=s?s[1]*L+s[3]*G+s[5]:G}t.stroke(O,N,M,P[0],F*P[1],!1);continue}let Y=v.k==="path"?Tr(v.d,s,R*o):Yo(v,pe(this.local,s,v.x,v.y,(w=v.rot)!=null?w:0,1,1),o*R);for(let N=0;N<Y.count;N++){let O=Y.subs[N],z=O.n,L=v.k==="rect"||O.closed;B&&z>=3&&(t.polygon(O.pts,z,B[0],F*B[1]),P||t.stroke(O.pts,z,1/o,B[0],F*B[1],!0)),P&&t.stroke(O.pts,z,M,P[0],F*P[1],L)}}}bake(t,e){let r=Ko(e,this.coarse),s=this.baked.get(t),i=s==null?void 0:s.get(r);if(i&&i.gen===this.gen&&this.atlas.valid(i.frame))return i;i&&this.live.delete(i);let o=_r(t);if(!Number.isFinite(o.minX))return null;let a=2/r,l=(o.maxX-o.minX+a*2)*r,u=(o.maxY-o.minY+a*2)*r;if(l>1024||u>1024)return null;let c=-o.minX+a,f=-o.minY+a,m={frame:this.atlas.bake(l,u,b=>{b.scale(r,r),b.translate(c,f),Kr(b,t)}),k:r,ox:c,oy:f,gen:this.gen};return s||this.baked.set(t,s=new Map),s.set(r,m),this.live.add(m),m}},St=new Array(36).fill(0),Tt=0,Fe=(n,t=NaN,e=NaN,r=NaN,s=NaN)=>{St[Tt++]=n,n!==fe.Z&&(St[Tt++]=t,St[Tt++]=e,n===fe.Q&&(St[Tt++]=r,St[Tt++]=s))};function Yo(n,t,e){let r=Math.max(0,Math.min(n.r,n.w/2,n.h/2)),s=-n.w/2,i=-n.h/2,{M:o,L:a,Q:l,Z:u}=fe;return Tt=0,Fe(o,s+r,i),Fe(a,s+n.w-r,i),Fe(l,s+n.w,i,s+n.w,i+r),Fe(a,s+n.w,i+n.h-r),Fe(l,s+n.w,i+n.h,s+n.w-r,i+n.h),Fe(a,s+r,i+n.h),Fe(l,s,i+n.h,s,i+n.h-r),Fe(a,s,i+r),Fe(l,s,i,s+r,i),Fe(u),Tr(St,t,e)}function yi(n,t={}){var R,C;let e=kt(n,t),r=new We(Math.min(1024,e.maxTextureSize),2);r.onDrop=M=>{M.texture&&e.destroyTexture(M.texture),M.texture=null};let s=new nt(r),i=()=>{let M=new br;return t.local&&M.setLocal(!0),M},o=i(),a=new Map,l=1e6,u=t.smooth===!1?1:typeof t.smooth=="number"?Math.min(Math.max(t.smooth,.05),1):o.defaultAmount,c=Yt(e),f=new qe(r,t),p={w:1,h:1},m=1,b=0,y=!1,d=()=>f.drop(),g=typeof document!="undefined"?document.fonts:void 0;(R=g==null?void 0:g.ready)==null||R.then(()=>{y||d()}),(C=g==null?void 0:g.addEventListener)==null||C.call(g,"loadingdone",d);let w=()=>{let M=Kt(e.canvas),P=wt(M);if(P){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),e.destroy(),e=P;for(let B of r.pages)B.surface.texture=null;c=Yt(e),b=0}},S=()=>{if(!e.lost)return b=0,!0;let M=performance.now();return b||(b=M),M-b>3e3&&w(),!e.lost},v=()=>{var P,B;let M=e.canvas;t.units?(m=(P=t.pixelRatio)!=null?P:1,p.w=t.units.width,p.h=t.units.height):(m=(B=t.pixelRatio)!=null?B:Math.min(I.devicePixelRatio||1,2),p.w=M.clientWidth||M.width/m,p.h=M.clientHeight||M.height/m),e.resize(Math.max(1,Math.round(p.w*m)),Math.max(1,Math.round(p.h*m))),e.begin(0,0,m)},F=(M,P)=>{var Y;if(M.key===void 0)return(Y=M.id)!=null?Y:P+1;let B=a.get(M.key);return B===void 0&&(a.size>256&&a.clear(),a.set(M.key,B=l++)),B};return{get renderer(){return e},get kind(){return e.kind},get lost(){return e.lost},get canvas(){return e.canvas},draw(M,P){var B,Y,N,O;if(S()){v();for(let z=0;z<M.length;z++){let L=M[z];if(!Array.isArray(L.body))continue;let G=F(L,z),$=u<1||t.interpolate!==!1?o.posed(G,L.body,u,t.interpolate!==!1):L.body,K=(Y=ct((B=L.avatar)!=null?B:""))!=null?Y:ht,xe=(N=L.alpha)!=null?N:1;!s.draw(e,c,$,K,P,xe,m)||!L.name||f.draw(e,c,$,K,P,L.name,(O=L.color)!=null?O:"#6FA0E0",xe,m,p.w,p.h)}e.end()}},clear(){S()&&(v(),e.end())},reset(){o=i(),a.clear()},destroy(){var M;y=!0,(M=g==null?void 0:g.removeEventListener)==null||M.call(g,"loadingdone",d),e.destroy()}}}var Rr=new Map;function gi(n,t,e=Math.min(I.devicePixelRatio||1,2)){var o;let r="".concat(n,"|").concat(t,"|").concat(e),s=Rr.get(r);if(s)return s;s=document.createElement("canvas"),s.width=s.height=Math.round(t*e);let i=s.getContext("2d");return i.scale(e,e),i.beginPath(),i.rect(0,0,t,t),i.clip(),Kr(i,Fs((o=ct(n))!=null?o:ht,t)),Rr.size>64&&Rr.clear(),Rr.set(r,s),s}function Yt(n){return t=>{if(t.texture||(t.texture=n.createTexture(t.source),t.pending.length=0),t.pending.length){for(let[e,r,s]of t.pending)n.updateTexture(t.texture,e,r,s);t.pending.length=0}return t.texture}}var dn='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',st="rgba(10,16,30,0.75)";function pn(n,t){var a,l,u,c,f,p;let e=(a=n.size)!=null?a:40,r=n.outline?n.outline===!0?st:n.outline:null,s=r?(l=n.outlineWidth)!=null?l:Math.max(e*.12,3):0,i=n.shadow&&t?n.shadow===!0?st:n.shadow:null,o=i?(u=n.shadowBlur)!=null?u:e*.25:0;return{size:e,font:(c=n.font)!=null?c:dn,weight:(f=n.weight)!=null?f:700,color:(p=n.color)!=null?p:"#FBEFE3",outline:r,ow:s,shadow:i,blur:o,pad:s/2+o*1.2+2,th:e*1.25}}var xi=(n,t)=>"".concat(n.weight," ").concat(n.size*t,"px ").concat(n.font);function mn(n,t,e,r,s,i){n.scale(r,r),n.font=xi(e,1),n.textBaseline="middle",n.textAlign="left",n.lineJoin="round",e.shadow&&(n.shadowColor=e.shadow,n.shadowBlur=e.blur*r),e.outline&&(n.strokeStyle=e.outline,n.lineWidth=e.ow,n.strokeText(t,s,i),n.shadowColor="transparent"),n.fillStyle=e.color,n.fillText(t,s,i)}var Mt=null;function bn(n,t,e){return Mt!=null||(Mt=document.createElement("canvas").getContext("2d")),Mt.font=xi(t,e),Mt.measureText(n).width/e}var Re=class extends be{constructor(e,r,s={}){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=r;let R=s,{x:i,y:o,rotation:a,scale:l,scaleX:u,scaleY:c,alpha:f,visible:p,tint:m,blend:b,z:y,anchor:d,hitRadius:g,clip:w,mask:S,filters:v}=R,F=lt(R,["x","y","rotation","scale","scaleX","scaleY","alpha","visible","tint","blend","z","anchor","hitRadius","clip","mask","filters"]);this._style=F,this.bake(),this.set({x:i,y:o,rotation:a,scale:l,scaleX:u,scaleY:c,alpha:f,visible:p,tint:m,blend:b,z:y,hitRadius:g,clip:w,mask:S,filters:v}),d!==void 0&&(this.anchor=d)}get text(){return this._text}set text(e){let r=String(e);r!==this._text&&(this._text=r,this.dirty=!0)}get style(){return this._style}set style(e){this._style=re(re({},this._style),e),this.dirty=!0}bitmap(){let e=this._style.bitmapFont;if(!e)return null;let r=typeof e=="string"?this.kernel.bitmapFont(e):e;if(this.autoAnchor){let s=this._style.align;this.anchorX=s==="left"?0:s==="right"?1:.5,this.anchorY=.5}return r}get naturalWidth(){var r;let e=this.bitmap();return e?e.measure(this._text)*(((r=this._style.size)!=null?r:e.size)/e.size):super.naturalWidth}get naturalHeight(){var r;let e=this.bitmap();return e?e.lineHeight*(((r=this._style.size)!=null?r:e.size)/e.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(e,r,s){var m;let i=this.bitmap();if(!i)return super.draw(e,r,s);let o=((m=this._style.size)!=null?m: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,s,r,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 r=e.pixelScale,s=e.effects;return!this.dirty&&r===this.bakedScale&&e.fontGen===this.bakedFontGen&&s===this.bakedEffects&&e.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){var d;let e=this.kernel,r=e.pixelScale,s=e.effects;this.dirty=!1,this.bakedScale=r,this.bakedFontGen=e.fontGen,this.bakedEffects=s;let i=pn(this._style,s),{pad:o,th:a}=i,l=bn(this._text,i,r),u=(l+o*2)*r,c=(a+o*2)*r,f=(d=this._style.align)!=null?d:"center",p=f==="left"?o:f==="right"?o+l:o+l/2,m=g=>mn(g,this._text,i,r,o,o+a/2),b=this._frame,y=null;return b&&e.atlas.valid(b)&&b.scale===r&&(y=e.atlas.rebake(b,u,c,m,this.capW,this.capH),y?Object.assign(y,{ox:p,oy:o+a/2,margin:o}):e.atlas.release(b)),y||(this.capW=Math.ceil(u*1.25+16),this.capH=Math.ceil(c),y=e.atlas.bake(this.capW,this.capH,m,r,p,o+a/2,o),y.w=Math.ceil(u),y.h=Math.ceil(c)),this._frame=y,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,y}};var ne=(n,t=0)=>{let e=Number(n);return Number.isFinite(e)?e:t};function Ft(n){var r,s,i,o,a,l;typeof n=="string"&&/^\s*[{[]/.test(n)&&(n=JSON.parse(n));let t={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},e=(u,c)=>{var f;u==="info"?t.size=Math.abs(ne(c.size)):u==="common"?(t.lineHeight=ne(c.lineHeight),t.base=ne(c.base)):u==="page"?t.pages[ne(c.id)]=String((f=c.file)!=null?f:""):u==="char"?t.chars.push({id:ne(c.id),x:ne(c.x),y:ne(c.y),width:ne(c.width),height:ne(c.height),xoffset:ne(c.xoffset),yoffset:ne(c.yoffset),xadvance:ne(c.xadvance),page:ne(c.page)}):t.kernings.push({first:ne(c.first),second:ne(c.second),amount:ne(c.amount)})};if(typeof n=="object"){let u=n;e("info",(r=u.info)!=null?r:{}),e("common",(s=u.common)!=null?s:{});for(let[c,f]of((i=u.pages)!=null?i:[]).entries())e("page",{id:c,file:f});for(let c of(o=u.chars)!=null?o:[])e("char",c);for(let c of(a=u.kernings)!=null?a:[])e("kerning",c)}else{let u=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,c=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let f=u.exec(n);f;f=u.exec(n)){let p={};for(let m=c.exec(f[2]);m;m=c.exec(f[2]))p[m[1]]=(l=m[2])!=null?l:m[3];e(f[1],p)}}return t.size||(t.size=t.lineHeight),t}var Et=class{constructor(t,e,r,s=null,i=null){h(this,"baker",s);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=t,this.lineHeight=e,this.base=r}set(t,e){t<128?this.ascii[t]=e:this.more.set(t,e)}setKerning(t,e,r){this.kern.set(t*1114112+e,r)}prepare(){let t=this.host;if(!(!t||t.pixelScale===this.bScale&&t.fontGen===this.bFontGen&&t.effects===this.bEffects&&t.atlas.gen===this.bGen)){this.bScale=t.pixelScale,this.bFontGen=t.fontGen,this.bEffects=t.effects,this.bGen=t.atlas.gen;for(let e of this.ascii)e&&t.atlas.release(e.frame);for(let e of this.more.values())e&&t.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(t){let e=t<128?this.ascii[t]:this.more.get(t);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(t):null,this.set(t,e)),e}kerning(t,e){var r;return this.kern.size&&(r=this.kern.get(t*1114112+e))!=null?r:0}measure(t){return this.run(t)}run(t,e,r,s=0,i=0,o=1,a=1,l=0,u=1,c="normal"){this.prepare();let f=0,p=-1;for(let m=0;m<t.length;m++){let b=t.charCodeAt(m);b>=55296&&b<56320&&m+1<t.length&&(b=t.codePointAt(m),m++),p>=0&&(f+=this.kerning(p,b)),p=b;let y=this.glyph(b);y&&(e&&y.w>0&&y.h>0&&(Wt(r,s+(f+y.x)*o,i+y.y*a),e.r.quad(e.tex(y.frame.surface),y.frame,te,y.w*o,y.h*a,l,u,c)),f+=y.advance)}return f}};function vi(n,t){let e=new Et(n.size,n.lineHeight,n.base);for(let r of n.chars){let s=t[r.page];if(!s)continue;let i={surface:s,x:r.x,y:r.y,w:r.width,h:r.height,scale:1,gen:0,ox:0,oy:0,margin:0};e.set(r.id,{frame:i,x:r.xoffset,y:r.yoffset,w:r.width,h:r.height,advance:r.xadvance})}for(let r of n.kernings)e.setKerning(r.first,r.second,r.amount);return e}function wi(n,t){var o,a;let e=re({},t),r=(o=t.size)!=null?o:40,s=l=>{let u=String.fromCodePoint(l),c=n.pixelScale,f=pn(e,n.effects),p=bn(u,f,c),m=n.atlas.bake((p+f.pad*2)*c,(f.th+f.pad*2)*c,b=>mn(b,u,f,c,f.pad,f.pad+f.th/2),c);return{frame:m,x:-f.pad,y:-f.pad,w:m.w/c,h:m.h/c,advance:p}},i=new Et(r,r*1.25,r,s,n);i.prepare();for(let l of(a=t.chars)!=null?a:"0123456789")i.glyph(l.codePointAt(0));return i}var Qo=.5;function yn(n){let t=[];for(let[e,r]of[["left",de.leftWrist],["right",de.rightWrist]]){let s=n[r*3],i=n[r*3+1],o=n[r*3+2];s!==void 0&&i!==void 0&&Number.isFinite(s)&&Number.isFinite(i)&&(o!=null?o:0)>=Qo&&t.push({side:e,x:s,y:i})}return t}var Rt=n=>Dt[((n-1)%Dt.length+Dt.length)%Dt.length],Zo=["left","right"];function Cr(n,t,e,r,s=()=>null,i={}){var a,l;let o=[];for(let u of n){let c=(a=s(u))!=null?a:u.body;if(Array.isArray(c)){if(i.orientation==="portrait"){for(let f of Zo){let p=vs(c,f,{orientation:"portrait"});i.hold&&(p=i.hold.at(ut.key(u.id,f),p,(l=i.t)!=null?l:0)),p&&o.push({player:u.id,side:f,x:p.x*e,y:p.y*r,color:Rt(u.id)})}continue}for(let f of yn(c)){let p=t(f);o.push({player:u.id,side:f.side,x:p.x*e,y:p.y*r,color:Rt(u.id)})}}}return o}function Qt(n,t,e,r=0){let s=n.world,i=_s(s,t,e);if(!i)return!1;let o=Math.hypot(s[0],s[1])||1,a=Math.hypot(s[2],s[3])||1,[l,u]=i;if(n.hitRadius!=null){let b=n.hitRadius+r/((o+a)/2);return l*l+u*u<=b*b}let c=-n.anchorX*n.width-r/o,f=-n.anchorY*n.height-r/a,p=(1-n.anchorX)*n.width+r/o,m=(1-n.anchorY)*n.height+r/a;return l>=c&&l<=p&&u>=f&&u<=m}function Pr(n,t,e,r=0){for(let s of t)if((e===void 0||s.player===e)&&Qt(n,s.x,s.y,r))return s;return null}function Jo(n){var t;switch(n.type){case"circle":case"ring":case"star":return[n.r*2,n.r*2];case"ellipse":return[n.rx*2,n.ry*2];case"roundRect":return[n.w,n.h];case"line":return[n.length,(t=n.lw)!=null?t:4];case"path":return n.r?[n.r*2,n.r*2]:[n.size,n.size]}}function ea(n){var r,s,i;let t=n.type==="line"?0:n.stroke?((r=n.lw)!=null?r:2)/2:0,e=n.shadow?n.shadow.blur*1.5+Math.max(Math.abs((s=n.shadow.x)!=null?s:0),Math.abs((i=n.shadow.y)!=null?i:0)):0;return Math.ceil(t+e+1)}var Ai=(n,t)=>t||!n.shadow?n:ke(re({},n),{shadow:void 0});function gn(n,t,e){let r=ea(t),s=t.type==="roundRect",[i,o]=s?[Math.min(t.w,t.r*2+4/e),Math.min(t.h,t.r*2+4/e)]:Jo(t),a=(i+r*2)*e,l=(o+r*2)*e;return{frame:n.bake(a,l,c=>{c.scale(e,e),c.translate(r+i/2,r+o/2),ta(c,t,i,o)},e,r+i/2,r+o/2,r),slice:s?Math.ceil((t.r+r)*e):0,w:s?t.w:i,h:s?t.h:o}}function ta(n,t,e,r){var u,c,f,p,m,b,y;n.lineJoin="round",n.lineCap="round";let s=new Path2D;switch(t.type){case"circle":case"ring":s.arc(0,0,t.r,0,Math.PI*2);break;case"ellipse":s.ellipse(0,0,t.rx,t.ry,0,0,Math.PI*2);break;case"roundRect":s.roundRect(-e/2,-r/2,e,r,Math.min(t.r,e/2,r/2));break;case"star":{let d=(u=t.points)!=null?u:5,g=t.r*((c=t.inner)!=null?c:.5);for(let w=0;w<d*2;w++){let S=w%2?g:t.r,v=-Math.PI/2+w*Math.PI/d;w?s.lineTo(Math.cos(v)*S,Math.sin(v)*S):s.moveTo(Math.cos(v)*S,Math.sin(v)*S)}s.closePath();break}case"line":s.moveTo(-e/2+r/2,0),s.lineTo(e/2-r/2,0);break;case"path":{let d=t.r?t.r*2/t.size:1,g=new DOMMatrix([d,0,0,d,-t.size/2*d,-t.size/2*d]);s.addPath(new Path2D(t.d),g);break}}let i=t.shadow,o=()=>{var g,w;if(!i)return;let d=n.getTransform();n.shadowColor=i.color,n.shadowBlur=i.blur*d.a,n.shadowOffsetX=((g=i.x)!=null?g:0)*d.a,n.shadowOffsetY=((w=i.y)!=null?w:0)*d.a},a=()=>{n.shadowColor="transparent",n.shadowBlur=0};if(t.type==="line"){o(),n.strokeStyle=(p=(f=t.stroke)!=null?f:t.fill)!=null?p:"#fff",n.lineWidth=r,n.stroke(s);return}let l=t.type==="ring";if(t.outlineBelow&&t.fill&&t.stroke&&!l){o(),n.strokeStyle=t.stroke,n.lineWidth=(m=t.lw)!=null?m:2,n.stroke(s),a(),n.fillStyle=t.fill,n.fill(s);return}t.fill&&!l&&(o(),n.fillStyle=t.fill,n.fill(s),a()),(t.stroke||l)&&((!t.fill||l)&&o(),l&&t.fill&&(n.fillStyle=t.fill,n.fill(s)),n.strokeStyle=(b=t.stroke)!=null?b:"#fff",n.lineWidth=(y=t.lw)!=null?y:2,n.stroke(s),a())}var _t=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 t=()=>{var e;(e=this.context())==null?void 0:e.resume().catch(()=>{})};for(let e of["pointerdown","keydown","touchstart"])addEventListener(e,t,{once:!0,capture:!0})}}context(){var e;if(this.ctx)return this.ctx;let t=(e=I.AudioContext)!=null?e:I.webkitAudioContext;if(!t)return null;try{this.ctx=new t,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch(r){return null}return this.ctx}load(t,e){return Pe(this,null,function*(){let r=this.context();if(!r)return;let s=yield(yield fetch(e)).arrayBuffer();this.buffers.set(t,yield r.decodeAudioData(s))})}has(t){return this.buffers.has(t)}play(t,e={}){var a,l,u;let r=this.context(),s=this.buffers.get(t);if(!r||!s||!this.audible)return()=>{};let i=r.createBufferSource();i.buffer=s,i.loop=(a=e.loop)!=null?a:!1,i.playbackRate.value=(l=e.rate)!=null?l:1;let o=r.createGain();return o.gain.value=((u=e.volume)!=null?u:1)*this.volume,i.connect(o).connect(this.master),i.start(),()=>{try{i.stop()}catch(c){}}}tone(t,e=.25,r={}){var i,o;let s=this.context();if(!(!s||!this.audible))try{let a=s.createOscillator(),l=s.createGain();a.type=(i=r.type)!=null?i:"sine",a.frequency.setValueAtTime(t,s.currentTime),r.to&&a.frequency.exponentialRampToValueAtTime(r.to,s.currentTime+e),l.gain.setValueAtTime(((o=r.volume)!=null?o:.12)*this.volume,s.currentTime),l.gain.exponentialRampToValueAtTime(.001,s.currentTime+e),a.connect(l).connect(this.master),a.start(),a.stop(s.currentTime+e)}catch(a){}}get audible(){return!this.muted&&!this.held}hold(){var t;this.held=!0,(t=this.ctx)==null||t.suspend().catch(()=>{})}release(){var t;this.held=!1,(t=this.ctx)==null||t.resume().catch(()=>{})}destroy(){var t;(t=this.ctx)==null||t.close().catch(()=>{}),this.ctx=null}};var ra={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}},_e=["high","medium","low"];function Be(n){let t=ra[n];return ke(re({name:n},t),{scale:e=>e<=0?0:Math.max(1,Math.round(e*t.particles))})}var ki=n=>_e[Math.min(_e.indexOf(n)+1,_e.length-1)],Lr=(n,t)=>{if(!n.length)return NaN;let e=[...n].sort((r,s)=>r-s);return e[Math.min(e.length-1,Math.max(0,Math.floor(t*(e.length-1)+.5)))]},Si=12,Ti=n=>Zt(n,.5);function Zt(n,t=.1){let e=Lr(n,t);if(!Number.isFinite(e))return 1e3/60;let r=[144,120,90,75,60,50,30],s=60;for(let i of r)Math.abs(1e3/i-e)<Math.abs(1e3/s-e)&&(s=i);return 1e3/s}function Nr(n,t){let e=t.refresh!==void 0&&Number.isFinite(t.refresh)&&t.refresh>0?t.refresh:Zt(t.intervals),r=Lr(t.intervals,.5),s=Lr(t.intervals,.9),i=Lr(t.cpu,.5);if(!Number.isFinite(r))return n==="canvas2d"?"low":"medium";let o=l=>l<=e*1.25,a=l=>!Number.isFinite(i)||i<e*l;return n==="canvas2d"?o(s)&&a(.25)?"medium":"low":o(s)&&a(.5)?"high":o(r)?"medium":"low"}function Mi(n,t){return n.length<30?!1:n.filter(r=>r>t*1.5).length/n.length>.5}var Ei="0.1.1",na=720*3600*1e3,Fi=(n,t,e)=>"fabi-play.engine-tier:".concat(Ei,":").concat(n,":").concat(t,":").concat(e),Ri=(n,t,e)=>"fablee-engine-tier:".concat(Ei,":").concat(n,":").concat(t,":").concat(e);function _i(n,t,e=Date.now()){var r;try{let s=JSON.parse((r=n==null?void 0:n.getItem(t))!=null?r:"null");if(s&&_e.includes(s.tier)&&typeof s.at=="number"&&e-s.at<na)return typeof s.refresh=="number"&&s.refresh>0?{name:s.tier,refresh:s.refresh}:{name:s.tier}}catch(s){}return null}function xn(n,t,e,r,s=Date.now()){try{n==null||n.setItem(t,JSON.stringify(r!==void 0&&Number.isFinite(r)?{tier:e,at:s,refresh:r}:{tier:e,at:s}))}catch(i){}}function Ci(n=typeof location!="undefined"?location.search:""){let t=new URLSearchParams(n).get("tier");return _e.includes(t)?t:void 0}function vn(n,t){let e=t==null?void 0:t.tier;if(_e.includes(e))return n==="canvas2d"&&e==="high"?"medium":e}var wn=n=>typeof(n==null?void 0:n.hz)=="number"&&n.hz>=20&&n.hz<=240?Zt([1e3/n.hz],.5):NaN,An=(n,t)=>_e.indexOf(n)>=_e.indexOf(t)?n:t;function Pi(n,t,e){return n?{name:n,from:"forced"}:t?{name:e?An(t,e):t,from:"hint"}:e?{name:e,from:"cache"}:null}var sa=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,Ct=class{constructor(t={}){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");var e,r;this.repeat=Math.floor((e=t.repeat)!=null?e:0),this.yoyo=!!t.yoyo,this.delayLeft=(r=t.delay)!=null?r:0,this._paused=!!t.paused,this.onComplete=t.onComplete,this.promise=new Promise(s=>this.resolve=s)}get duration(){return this.end}get time(){return this.last}get paused(){return this._paused}get finished(){return this.done}at(t){if(t===void 0)return this.end;if(typeof t=="number")return Math.max(t,0);let e=sa.exec(t);if(!e)throw new Error('[engine] timeline: bad position "'.concat(t,'"'));let[,r,s,i]=e,o=i?(s==="-"?-1:1)*Number(i):0,a=this.end;if(r==="<")a=this.prevStart;else if(r&&r!==">"){let l=this.labels.get(r.trim());l===void 0?this.labels.set(r.trim(),this.end):a=l}return Math.max(a+o,0)}add(t){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>t.start;)e--;return this.steps.splice(e,0,t),this.prevStart=t.start,this.end=Math.max(this.end,t.start+t.dur),this}to(t,e,r,s="quadOut"){var a,l;let i=typeof s=="object"?s:{ease:s},o=typeof i.ease=="function"?i.ease:$e[(a=i.ease)!=null?a:"quadOut"];return this.add({target:t,to:e,from:null,fn:null,start:this.at(i.at)+((l=i.delay)!=null?l:0),dur:Math.max(r,0),ease:o,onUpdate:i.onUpdate,p:-1})}set(t,e,r){return this.add({target:t,to:e,from:null,fn:null,start:this.at(r),dur:0,ease:$e.linear,p:-1})}call(t,e){return this.add({target:null,to:null,from:null,fn:t,start:this.at(e),dur:0,ease:$e.linear,p:-1})}label(t,e){return this.labels.set(t,this.at(e)),this}wait(t){return this.end+=Math.max(t,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(t){let e=Math.min(typeof t=="string"&&this.labels.has(t)?this.labels.get(t):this.at(t),this.end),r=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(r?this.end-e:e),this.render(e),this}then(t,e){return this.promise.then(t,e)}update(t){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=t,this.delayLeft>0)return;t=-this.delayLeft,this.delayLeft=0}let e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=t;let r=this.repeat<0?1/0:e*(this.repeat+1),s=Math.min(this.elapsed,r),i=s>=r?this.repeat:Math.floor(s/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=s-i*e;this.render(this.yoyo&&i%2===1?e-o:o),s>=r&&this.complete()}complete(){var t;this.done||(this.done=!0,(t=this.onComplete)==null||t.call(this),this.resolve())}render(t){let e=this.steps;if(t>=this.last)for(let r=0;r<e.length;r++){let s=e[r];t>=s.start&&this.apply(s,t)}else for(let r=e.length-1;r>=0;r--){let s=e[r];s.p>=0&&this.apply(s,t)}this.last=t}apply(t,e){var a,l;let r=t.dur>0?Math.min(Math.max((e-t.start)/t.dur,0),1):e>t.start||e===t.start&&!this.rewinding?1:0;if(r===t.p)return;if(t.p=r,t.fn){this.rewinding||t.fn();return}let s=t.target;if(s.destroyed||s._free)return;let i=t.to;if(!t.from){t.from={};for(let u in i)t.from[u]=Number((a=s[u])!=null?a:0)}let o=t.ease(r);for(let u in i)s[u]=t.from[u]+(i[u]-t.from[u])*o;(l=t.onUpdate)==null||l.call(t,o)}};var Pt=class{constructor(){h(this,"list",[]);h(this,"timelines",[])}timeline(t){let e=new Ct(t);return this.timelines.push(e),e}tween(t,e,r,s="quadOut"){var u;let i=typeof s=="object"?s:{ease:s},o=typeof i.ease=="function"?i.ease:$e[(u=i.ease)!=null?u:"quadOut"],a,l=new Promise(c=>{var m;let f=Object.keys(e),p=new Float64Array(f.length);f.forEach((b,y)=>p[y]=Number(e[b])),a={target:t,keys:f,to:p,from:new Float64Array(f.length),started:!1,duration:Math.max(r,0),time:0,delay:(m=i.delay)!=null?m:0,ease:o,onUpdate:i.onUpdate,done:c,dead:!1}});return this.list.push(a),Object.assign(l,{stop:()=>this.finish(a)})}stopAll(t){let e=this.list;for(let r=0;r<e.length;r++)e[r].target===t&&this.finish(e[r])}get size(){return this.list.length}update(t){if(this.timelines.length){let s=0,i=this.timelines;for(let o=0;o<i.length;o++){let a=i[o];a.update(t),a.finished||(i[s++]=a)}i.length=s}let e=this.list;if(!e.length)return;let r=0;for(let s=0;s<e.length;s++){let i=e[s];i.dead||this.step(i,t),i.dead||(e[r++]=i)}r!==e.length&&(e.length=r)}step(t,e){var a,l;if(t.target.destroyed)return this.finish(t);let r=e;if(t.delay>0){if(t.delay-=e,t.delay>0)return;r=-t.delay}let s=t.keys;if(!t.started){t.started=!0;for(let u=0;u<s.length;u++)t.from[u]=Number((a=t.target[s[u]])!=null?a:0)}t.time+=r;let i=t.duration>0?Math.min(t.time/t.duration,1):1,o=t.ease(i);for(let u=0;u<s.length;u++)t.target[s[u]]=t.from[u]+(t.to[u]-t.from[u])*o;(l=t.onUpdate)==null||l.call(t,o),i>=1&&this.finish(t)}finish(t){t.dead||(t.dead=!0,t.done())}clear(){for(let t of this.list)this.finish(t);this.list.length=0;for(let t of this.timelines)t.stop();this.timelines=[]}};var se=720,Jt=class extends we{constructor(e,r){super(e);h(this,"paintAll",r)}draw(e,r){this.paintAll(e,r)}},Sn=class extends we{constructor(e,r){super(e);h(this,"paintAll",r)}draw(e,r){this.paintAll(e,r)}},De=()=>performance.now(),Li=n=>{let t=As(n);return t&&Object.freeze(t)};function Oi(){return Pe(this,arguments,function*(n={}){var os,as,ls,us,cs,hs,fs,ds,ps,cr,ms;let t=(os=n.play)!=null?os:null,e=(as=n.canvas)!=null?as:null;e||(e=document.createElement("canvas"),e.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(e));let r=kt(e,{renderer:(ls=n.renderer)!=null?ls:bi(),failIfMajorPerformanceCaveat:n.failIfMajorPerformanceCaveat,instancing:n.instancing});e=r.canvas;let s=new Set,i=new We(Math.min(2048,r.maxTextureSize),4);i.onPage=x=>s.add(x),i.onDrop=x=>{s.delete(x),x.texture&&r.destroyTexture(x.texture),x.texture=null};let o=Yt(r),a=new Pt,l=new _t,u=new nt(i),c=new Map,f=new Map,p=new Map,m=new Map,b=new Map,y=new Set,d=0,g=(us=n.tier)!=null?us:Ci(),w=String((cs=r.info.renderer)!=null?cs:""),S=(()=>{var x;try{return(x=I.localStorage)!=null?x:null}catch(A){return null}})(),v=typeof screen!="undefined"?"".concat(screen.width,"x").concat(screen.height):"",F=Fi(r.kind,w,v);ks(S,F,Ri(r.kind,w,v));let R=_i(S,F),C=Pi(g,vn(r.kind,t==null?void 0:t.device),R==null?void 0:R.name),M=(hs=C==null?void 0:C.name)!=null?hs:"medium",P=Be(M);u.setTier(M);let B=(C==null?void 0:C.from)==="hint",Y=R==null?void 0:R.name,N=(fs=R==null?void 0:R.refresh)!=null?fs:wn(t==null?void 0:t.device),O=1,z=1,L=1,G={atlas:i,get pixelScale(){return O},get fontGen(){return d},get effects(){return P.effects},tweens:a,frame:x=>ur.frame(x),shape:x=>{let A=P.effects,E=A?O:-O,k=c.get(E);k||(c.size>=8&&c.clear(),c.set(E,k=new xt(2e3)));let U=Se(x),H=k.get(x,U);return(!H||!i.valid(H.frame))&&k.set(x,H=gn(i,Ai(x,A),O),U),H},bitmapFont:x=>ur.bitmapFont(x)},$=1280,K=null;class xe extends rt{get width(){return $}set width(A){}get height(){return se}set height(A){}get safe(){let A=Math.min($,se*16/9);return{x:($-A)/2,y:0,w:A,h:se}}}let Z=new xe(G),le=()=>{var U;let x=r.canvas,A=x.getBoundingClientRect();z=Math.max(1,A.width||x.clientWidth||innerWidth),L=Math.max(1,A.height||x.clientHeight||innerHeight),$=se*z/L;let E=Math.min(I.devicePixelRatio||1,(U=n.maxPixelRatio)!=null?U:2);if(L*E/se<=P.resolution){let H=Math.max(1,Math.round(L*E));O=H/se,r.resize(Math.max(1,Math.round(z*E)),H)}else O=P.resolution,r.resize(Math.round($*O),Math.round(se*O));K&&K.style.setProperty("--unit","".concat(L/se,"px"))};addEventListener("resize",le);let ot=x=>{M=x,P=Be(x),u.setTier(x),le()},ie=typeof ResizeObserver!="undefined"?new ResizeObserver(le):null;ie==null||ie.observe(e);let ve=(t==null?void 0:t.backdrop)==="video"?"video":"none",J=(ds=t==null?void 0:t.view)!=null?ds:null,tr=(t==null?void 0:t.orientation)==="portrait"?"portrait":"landscape",Xn=(ps=Li(t==null?void 0:t.safeArea))!=null?ps:ws,jn=[],qn=-1/0,rr=!1,Lt=!1,Dr=new Set,Kn=()=>{let x=ve==="video"?"transparent":"";document.documentElement.style.background=x,document.body.style.background=x},Yn=(x,A)=>{let E=x==="video"?"video":"none",k=A!=null?A:null;if(!(E===ve&&(k===J||k&&J&&k.x===J.x&&k.y===J.y&&k.w===J.w&&k.h===J.h))){ve=E,J=k,Kn();for(let U of[...Dr])U(ve,J)}},Qn=[];if(t){let x=k=>{Array.isArray(k)&&(jn=k,qn=De())},A=k=>{rr=k,nr()},E=k=>{if(g||B)return;Number.isFinite(N)||(N=wn(k));let U=vn(r.kind,k);U&&(B=!0,ot(Y?An(U,Y):U))};Qn.push(t.on("start",k=>E(k==null?void 0:k.device)),t.on("start",k=>{((k==null?void 0:k.orientation)==="portrait"||(k==null?void 0:k.orientation)==="landscape")&&(tr=k.orientation);let U=Li(k==null?void 0:k.safeArea);U&&(Xn=U)}),t.on("start",k=>{typeof(k==null?void 0:k.muted)=="boolean"&&(l.muted=k.muted)}),t.on("frame",k=>x(k==null?void 0:k.players)),t.on("players",k=>x(k==null?void 0:k.players)),t.on("backdrop",k=>Yn(k==null?void 0:k.backdrop,k==null?void 0:k.view)),t.on("start",k=>{var U;return Yn(k==null?void 0:k.backdrop,(U=k==null?void 0:k.view)!=null?U:t.view)}),t.on("pause",()=>A(!0)),t.on("resume",()=>A(!1)),t.on("break-start",()=>A(!0)),t.on("break-done",()=>A(!1)),t.on("break-end",()=>A(!1))),l.muted=t.muted===!0}Kn();let nr=()=>rr||Lt||document.hidden?l.hold():l.release(),Zn=-1,Ur=[],Hr=0,Gr=()=>De()-qn<1e3?jn:[],no=x=>t?t.toScreen(x):qr(J,x),so=new ut,sr=()=>{if(Zn===Hr)return Ur;Zn=Hr;let x=tr==="portrait",A=ve==="video"&&!x||!(t!=null&&t.smoothedBody)?()=>null:E=>t.smoothedBody(E);return Ur=Cr(Gr(),no,$,se,A,x?{orientation:tr,hold:so,t:De()}:void 0),Ur},Nt={x:0,y:0,w:1,h:1},io=()=>(Nt.x=J?J.x*$:0,Nt.y=J?J.y*se:0,Nt.w=J?J.w*$:$,Nt.h=J?J.h*se:se,Nt),oo=x=>{var U;let A=(U=x.alpha)!=null?U:1,E=x.tags?new qe(i,x):null;E&&y.add(E);let k=typeof x.tags=="function"?x.tags:H=>String(H);return(H,ue)=>{var Q,oe,Ye,He,W,V;if(ve==="video")return;let ee=io();for(let X of Gr()){let j=(oe=(Q=t==null?void 0:t.smoothedBody)==null?void 0:Q.call(t,X))!=null?oe:X.body,ce=(V=ct((W=(He=(Ye=t==null?void 0:t.avatarOf)==null?void 0:Ye.call(t,X))!=null?He:X.avatar)!=null?W:""))!=null?V:ht;if(!u.draw(H.r,H.tex,j,ce,ee,A*ue,O)||!E)continue;let Qe=k(X.id);Qe&&E.draw(H.r,H.tex,j,ce,ee,Qe,Rt(X.id),A*ue,O,$,se)}}},zr=new Set,$r=new Set,Ot=new Set,ir=!1,Vr=0,at=0,or=0,Ke={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0},ar=0,Wr=0,Xr=De(),It=[],lr=0,Jn=()=>({r,kernel:G,tex:o}),es=Jn(),ao=()=>{if(r.lost)return;let[x,A]=ve==="video"||n.background===void 0?[0,0]:ae(n.background);r.time=or,r.maxBlur=P.maxBlur,r.begin(x,A,O),pe(Z.world,null,Z.x,Z.y,Z.rotation,Z.scaleX,Z.scaleY),sn(es,Z,Z.alpha,Z.tint);let E=r.end();Ke.drawCalls=E.drawCalls,Ke.quads=E.quads,Ke.filtersSkipped=E.filtersSkipped},ts=x=>{var U;if(!ir)return;Vr=requestAnimationFrame(ts);let A=Math.min(Math.max((x-at)/1e3,0),.1);at&&It.push(x-at),at=x,Hr++;let E=De(),k=rr||Lt;if(!k){or+=A,a.update(A);for(let H of Ot)H.destroyed||H.update(A);for(let H of zr)H(A,or)}for(let H of $r)H(A);Z.sweep();for(let H of Ot)H.destroyed&&Ot.delete(H);if(r.lost?(lr||(lr=x),x-lr>3e3&&lo()):(lr=0,ao()),ar++,Wr+=De()-E,E-Xr>=1e3&&(Ke.fps=Math.round(ar*1e3/(E-Xr)),Ke.cpuMs=Math.round(Wr/Math.max(ar,1)*100)/100,(U=t==null?void 0:t.reportStats)==null||U.call(t,{fps:Ke.fps,renderer:r.kind,tier:M}),ar=0,Wr=0,Xr=E),It.length>=180){let H=Number.isFinite(N)?N:Zt(It);!g&&!k&&Mi(It,H)&&M!=="low"&&(ot(ki(M)),Y=M,xn(S,F,M,Number.isFinite(N)?N:void 0),console.info("[engine] slow frames: tier ".concat(M))),It.length=0}},lo=()=>{let x=Kt(r.canvas),A=wt(x);if(A){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),r.destroy(),r=A;for(let E of s)E.texture=null;for(let E of i.pages)s.add(E.surface);o=Yt(r),es=Jn(),ie==null||ie.disconnect(),ie==null||ie.observe(x),le()}},rs=()=>{nr(),document.hidden||(at=0)};document.addEventListener("visibilitychange",rs);let ns=()=>{d++;for(let x of y)x.drop()};if((ms=(cr=document.fonts)==null?void 0:cr.addEventListener)==null||ms.call(cr,"loadingdone",ns),le(),!C&&n.probe!==!1&&(Number.isFinite(N)||(N=Ti(yield ia(Si))),!B)){P=Be("high"),le();let x=yield oa(r,i,()=>o,()=>O,$,()=>B);if(x.refresh=N,!B){let A=Nr(r.kind,x);xn(S,F,A,N),Y=A,ot(A)}}let ur={stage:Z,get tier(){return P},get renderer(){return r},get canvas(){return r.canvas},get pixelScale(){return O},get backdrop(){return ve},get view(){return J},get orientation(){return tr},get safeArea(){return Xn},get paused(){return rr||Lt},sound:l,stats:Ke,get time(){return or},get supports(){let x=r.support;return{filters:x.filters,blur:x.filters&&P.maxBlur>0,shaders:x.shaders,maxBlur:x.filters?P.maxBlur:0,tiers:{high:{maxBlur:Be("high").maxBlur},medium:{maxBlur:Be("medium").maxBlur},low:{maxBlur:Be("low").maxBlur}}}},sprite:(x,A)=>new be(G,x,A),shape:(x,A)=>new Me(G,x,A),text:(x,A)=>new Re(G,x,A),group:x=>new rt(G).set(x!=null?x:{}),particles(x,A={}){let E=typeof x=="object"&&"type"in x?G.shape(x).frame:x,k=new mt(G,E,A),oe=A,{max:U,blend:H,gravity:ue,drag:ee}=oe,Q=lt(oe,["max","blend","gravity","drag"]);return k.set(Q),Ot.add(k),k},tween:(x,A,E,k)=>a.tween(x,A,E,k),bake(x,A,E,k,U){return p.set(x,{w:A,h:E,draw:k,origin:U}),f.delete(x),ur.frame(x)},frame(x){var k,U,H,ue;let A=f.get(x);if(A&&i.valid(A)&&(A.gen===0||A.scale===O))return A;let E=p.get(x);if(E){let ee=O,Q=i.bake(E.w*ee,E.h*ee,oe=>(oe.scale(ee,ee),E.draw(oe)),ee,(U=(k=E.origin)==null?void 0:k.x)!=null?U:0,(ue=(H=E.origin)==null?void 0:H.y)!=null?ue:0);return f.set(x,Q),Q}if(A)return A;throw new Error('[engine] no frame "'.concat(x,'": load it or bake it first'))},load(x){return Pe(this,null,function*(){yield Promise.all(Object.entries(x).map(([A,E])=>co(A,E)))})},hands:x=>x===void 0?sr():sr().filter(A=>A.player===x),touched(x,A,E={}){var k;return x.updateWorld(),Pr(x,sr(),A,(k=E.padding)!=null?k:0)},hits(x,A,E,k=0){return x.updateWorld(),Qt(x,A,E,k)},avatars:(x={})=>new Jt(G,oo(x)),handMarkers(x={}){var He,W;let A=(He=x.radius)!=null?He:36,E=(W=x.look)!=null?W:"auto",k=new Float64Array(6),U=Math.max(A*.12,3),H={type:"ring",r:A,lw:U,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},ue={type:"ring",r:A,lw:U*1.8,stroke:st,shadow:{color:st,blur:A*.2}},ee=(V,X,j,ce,Qe,Ze)=>{let hr=X.w/X.scale;pe(k,null,j-hr/2,ce-hr/2,0,1,1),V.r.quad(V.tex(X.surface),X,k,hr,hr,Qe,Ze,"normal")},Q=V=>{let X=null,j=!1;return()=>(X&&i.valid(X.frame)&&X.frame.scale===O&&j===P.effects?X:(j=P.effects,X=G.shape(V))).frame},oe=Q(H),Ye=Q(ue);return new Sn(G,(V,X)=>{let j=E==="video"||E==="auto"&&ve==="video",ce=oe(),Qe=j?Ye():null;for(let Ze of sr())Qe&&ee(V,Qe,Ze.x,Ze.y,16777215,X),ee(V,ce,Ze.x,Ze.y,ae(Ze.color)[0],X)})},timeline:x=>a.timeline(x),animation(x,A){let E=typeof x=="string"?uo(x):{frames:x},k=new Ae(G,E,A);return Ot.add(k),k},bitmapFont(x,A){if(!A){let k=m.get(x);if(!k)throw new Error('[engine] no bitmap font "'.concat(x,'": load or make it first'));return k}let E="data"in A?ss(Ft(A.data),A.pages):wi(G,A);return m.set(x,E),E},players:()=>Gr(),onFrame(x){return zr.add(x),()=>{zr.delete(x)}},onRender(x){return $r.add(x),()=>{$r.delete(x)}},onBackdrop(x){return Dr.add(x),()=>{Dr.delete(x)}},get hud(){return K||(K=document.createElement("div"),K.style.cssText="position:fixed;top:0;right:0;bottom:0;left:0;pointer-events:none;overflow:hidden",document.body.appendChild(K),le()),K},random:(x=0,A=1)=>x+Math.random()*(A-x),start(){ir||(ir=!0,at=0,Vr=requestAnimationFrame(ts))},pause(){Lt=!0,nr()},resume(){Lt=!1,nr()},destroy(){var x,A;ir=!1,cancelAnimationFrame(Vr),Qn.forEach(E=>E()),removeEventListener("resize",le),ie==null||ie.disconnect(),document.removeEventListener("visibilitychange",rs),(A=(x=document.fonts)==null?void 0:x.removeEventListener)==null||A.call(x,"loadingdone",ns),a.clear(),Vs(G),l.destroy(),r.destroy(),K==null||K.remove()}};function uo(x){let A=b.get(x);if(A)return A;let E=[...new Set([...f.keys(),...p.keys()])].filter(k=>k.startsWith(x)).sort(Xs);if(!E.length)throw new Error('[engine] no animation or frames "'.concat(x,'\u2026"'));return{frames:E}}function co(x,A){return Pe(this,null,function*(){var ue,ee;let E=A.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(E))return l.load(x,A);if(["woff","woff2","ttf","otf"].includes(E)){let Q=new FontFace(x,"url(".concat(A,")"));document.fonts.add(yield Q.load()),d++;return}let k=new URL(A,location.href);if(E==="fnt")return is(x,Ft(yield(yield fetch(A)).text()),k);if(E==="json"){let Q=yield(yield fetch(A)).json();if(Array.isArray(Q.chars)&&!Q.frames)return is(x,Ft(Q),k);let oe=yield kn(new URL((ee=(ue=Q.meta)==null?void 0:ue.image)!=null?ee:A.replace(/\.json$/,".png"),k).href);ho(x,Q,bt(oe));return}let U=yield kn(A),H=bt(U);s.add(H),f.set(x,{surface:H,x:0,y:0,w:U.width,h:U.height,scale:1,gen:0,ox:0,oy:0,margin:0})})}function ss(x,A){return vi(x,A.map(E=>{let k=bt(E);return s.add(k),k}))}function is(x,A,E){return Pe(this,null,function*(){m.set(x,ss(A,yield Promise.all(A.pages.map(k=>kn(new URL(k,E).href)))))})}function ho(x,A,E){var ue,ee,Q,oe,Ye,He;s.add(E);let k=Array.isArray(A.frames)?A.frames:Object.entries(A.frames).map(([W,V])=>ke(re({},V),{filename:W})),U=[],H=[];for(let W of k){let V=W.frame,X=W.filename.replace(Ni,"");W.rotated&&console.warn("[engine] ".concat(x,"/").concat(X," is rotated: export without rotation"));let j={surface:E,x:V.x,y:V.y,w:V.w,h:V.h,scale:1,gen:0,ox:0,oy:0,margin:0};W.trimmed&&W.sourceSize&&W.spriteSourceSize&&(j.sw=W.sourceSize.w,j.sh=W.sourceSize.h,j.tx=W.spriteSourceSize.x,j.ty=W.spriteSourceSize.y);let ce=W.scale9Borders;ce&&(j.slice=[ce.y,((ue=j.sw)!=null?ue:V.w)-ce.x-ce.w,((ee=j.sh)!=null?ee:V.h)-ce.y-ce.h,ce.x]),f.set("".concat(x,"/").concat(X),j),U.push("".concat(x,"/").concat(X)),H.push(((Q=W.duration)!=null?Q:0)/1e3)}for(let[W,V]of Object.entries((oe=A.animations)!=null?oe:{}))b.set("".concat(x,"/").concat(W),{frames:V.map(X=>"".concat(x,"/").concat(X.replace(Ni,"")))});for(let W of(He=(Ye=A.meta)==null?void 0:Ye.frameTags)!=null?He:[]){let V=[];for(let j=W.from;j<=W.to;j++)V.push(j);W.direction==="reverse"&&V.reverse(),W.direction==="pingpong"&&V.push(...V.slice(1,-1).reverse());let X=V.every(j=>H[j]>0);b.set("".concat(x,"/").concat(W.name),re({frames:V.map(j=>U[j])},X?{durations:V.map(j=>H[j])}:{}))}}return ur})}var Ni=/\.(png|webp|jpe?g|gif|bmp)$/i;function kn(n){return new Promise((t,e)=>{let r=new Image;r.onload=()=>t(r),r.onerror=()=>e(new Error("[engine] image did not load: ".concat(n))),r.src=n})}function ia(n){return new Promise(t=>{let e=[],r=0,s=i=>{r&&e.push(i-r),r=i,e.length<n?requestAnimationFrame(s):t(e)};requestAnimationFrame(s)})}function oa(n,t,e,r,s,i=()=>!1){return Pe(this,null,function*(){let o=r(),a=gn(t,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},o).frame,l=[],u=[],c=new Float64Array(6),f=.004,p=n.kind==="canvas2d"?n.canvas.getContext("2d"):null,m=De(),b=0;return yield new Promise(y=>{let d=g=>{b&&g-m>250&&l.push(g-b),b=g;let w=De();n.begin(0,0,o);let S=e();for(let v=0;v<300;v++){let F=g/1e3+v;pe(c,null,v*37%s,v*53%se,F,1,1),n.quad(S(a.surface),a,c,a.w/o,a.h/o,16777215,f,"normal")}for(let v=0;v<40;v++)n.ellipse(100+v*20,300,20,14,v,16746496,f),n.stroke([100+v*20,400,120+v*20,460,100+v*20,520],3,18,3368703,f,!1);n.end(),p==null||p.getImageData(0,0,1,1),g-m>250&&u.push(De()-w),g-m<750&&!i()?requestAnimationFrame(d):(n.begin(0,0,o),n.end(),y())};requestAnimationFrame(d)}),{intervals:l,cpu:u}})}var aa=64,Ii=32,la=0,ua="fabi-cm-".concat(Math.random().toString(36).slice(2,7),"-"),Bi=new Set,Di=(n,t)=>{Bi.has(n)||(Bi.add(n),console.warn(t))},Ui=n=>new Tn(n),Tn=class{constructor(t){h(this,"r",t);h(this,"css","none");h(this,"plans",new xt(aa));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",t=>this.svg(t));h(this,"scr",[]);h(this,"flip",0)}chain(t,e){var b,y;let r=this.r,s=this.buf;s[0]=r.scale,s[1]=r.maxBlur;let i=2;for(let d=0;d<e.length;d++){let g=e[d];if(i+22>s.length){let S=new Float64Array(s.length*2);S.set(s),s=this.buf=S}let w=this.classes.get(g.constructor);w===void 0&&this.classes.set(g.constructor,w=this.classes.size),s[i++]=w,s[i++]=g.enabled?1:0,g.params&&(i=g.params(s,i))}let o=(y=(b=this.keys)[i])!=null?y:b[i]=new Float64Array(i);for(let d=0;d<i;d++)o[d]=s[d];let a=Se(o),l=this.plans.get(o,a);l||this.plans.set(o,l=this.plan(e),a);for(let d=0;d<l.svgs.length;d++){let g=l.svgs[d];g.used<0&&this.attach(g),g.used=this.t}r.skipped+=l.skip;let u=t,c=r.rx0,f=r.ry0,p=r.rx1-c,m=r.ry1-f;for(let d=0;d<l.paints.length;d++)l.parts[d]&&(u=this.bake(u,l.parts[d])),e[l.paints[d]].paint2d(u.getContext("2d"),c,f,p,m);return this.css=l.parts[l.paints.length]||"none",u}tick(){let t=++this.t;if(!(t%Ii||!this.live.size))for(let e of this.live)t-e.used>Ii&&this.detach(e)}destroy(){for(let t of this.live)this.detach(t);this.plans.clear()}svg(t){if(typeof document=="undefined"||!document.body)return null;let e=Array.from({length:20},(s,i)=>{var o;return(o=t[i])!=null?o:0}).join(" "),r=this.svgs.get(e);if(!r){let s="http://www.w3.org/2000/svg",i=document.createElementNS(s,"svg");i.setAttribute("width","0"),i.setAttribute("height","0"),i.setAttribute("aria-hidden","true"),i.style.position="absolute";let o=document.createElementNS(s,"filter"),a=ua+ ++la;o.setAttribute("id",a),o.setAttribute("color-interpolation-filters","sRGB");let l=document.createElementNS(s,"feColorMatrix");l.setAttribute("type","matrix"),l.setAttribute("values",e),o.append(l),i.append(o),this.attach(r={key:e,id:a,el:i,used:this.t})}return this.cur.svgs.push(r),"url(#".concat(r.id,")")}attach(t){document.body.append(t.el),this.live.add(t),this.svgs.has(t.key)||this.svgs.set(t.key,t)}detach(t){t.el.remove(),t.used=-1,this.live.delete(t),this.svgs.get(t.key)===t&&this.svgs.delete(t.key)}plan(t){let e=this.r,r=this.cur={parts:[],paints:[],skip:0,svgs:[]},s="";for(let i=0;i<t.length;i++){let o=t[i];if(!o.enabled)continue;if(o.kind===4){r.skip++,Di("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?s+=s?" ".concat(a):a:o.paint2d?(r.parts.push(s),r.paints.push(i),s=""):(r.skip++,Di("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 r.parts.push(s),r}bake(t,e){let r=this.r,s=this.flip^=1,i=this.scr[s];(!i||i.width!==r.canvas.width||i.height!==r.canvas.height)&&(i=this.scr[s]=document.createElement("canvas"),i.width=r.canvas.width,i.height=r.canvas.height);let o=i.getContext("2d"),a=r.rx0,l=r.ry0,u=r.rx1-a,c=r.ry1-l;return o.clearRect(a,l,u,c),o.filter=e,o.drawImage(t,a,l,u,c,a,l,u,c),o.filter="none",i}};var ca=64,Or=17,ha=n=>"".concat(Fr,"\nuniform sampler2D uTexture;\nuniform mat4 uM[").concat(n,"];\nuniform vec4 uO[").concat(n,"];\nuniform int uK;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvoid main() {\n vec4 c = texture2D(uTexture, vUv);\n if (c.a > 0.0) c.rgb /= c.a;\n for (int i = 0; i < ").concat(n,"; i++) {\n if (i >= uK) break;\n c = clamp(uM[i] * c + uO[i], 0.0, 1.0);\n }\n c.rgb *= c.a;\n gl_FragColor = c * vColor;\n}"),fa=()=>"".concat(Fr,"\nuniform sampler2D uTexture;\nuniform vec2 uDir;\nuniform vec2 uOff;\nuniform vec2 uTaps[").concat(Or,"];\nuniform int uN;\nuniform float uMode;\nuniform vec4 uShadow;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvoid main() {\n vec2 p = vUv + uOff;\n vec4 c = texture2D(uTexture, p) * uTaps[0].y;\n for (int i = 1; i < ").concat(Or,"; i++) {\n if (i >= uN) break;\n vec2 d = uDir * uTaps[i].x;\n c += (texture2D(uTexture, p + d) + texture2D(uTexture, p - d)) * uTaps[i].y;\n }\n if (uMode > 0.5) c = uShadow * c.a;\n gl_FragColor = c * vColor;\n}");function da(n,t,e=new Float32Array(20)){for(let r=0;r<4;r++)for(let s=0;s<5;s++){let i=s===4?t[r*5+4]:0;for(let o=0;o<4;o++)i+=t[r*5+o]*n[o*5+s];e[r*5+s]=i}return n.set(e),n}var Hi=n=>new Rn(n),Rn=class{constructor(t){h(this,"r",t);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(Or*2));let e=t.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(t){var e;return this.r.lost?null:(this.userProg(t,!1),(e=this.userErr.get(t))!=null?e:null)}destroy(){let t=this.r.gl;for(let e of this.scratchT.values())t.deleteTexture(e.gl),t.deleteFramebuffer(e.fb);this.scratchT.clear();for(let e of[this.colorProg,this.blurProg])e&&t.deleteProgram(e.p);for(let e of this.user.values())e.p&&t.deleteProgram(e.p.p);this.user.clear()}userProg(t,e){let r=this.user,s=r.get(t);if(s)return s.t=++this.uses,s.p;if(this.r.lost)return null;if(r.size>=ca){let o="",a=1/0;for(let[u,c]of r)c.t<a&&(a=c.t,o=u);let l=r.get(o).p;l&&this.r.gl.deleteProgram(l.p),r.delete(o),this.userErr.delete(o)}let i;try{i=this.r.build(t)}catch(o){i=null;let a=o.message;this.userErr.set(t,a),e&&console.error("[engine] a shader filter does not compile: it is skipped.\n".concat(a))}return r.set(t,{p:i,t:++this.uses}),i}scratch(t,e){var l;let r=this.r,s=Math.ceil(r.canvas.width/t),i=Math.ceil(r.canvas.height/t),o=t*8+e,a=(l=this.scratchT.get(o))!=null?l:null;return a&&(a.w!==s||a.h!==i)&&(r.drop(a),a=null),a||(a=r.target(s,i,t,!0),a?this.scratchT.set(o,a):this.scratchT.delete(o)),a}pass(t,e,r,s,i=!1){let o=this.r,a=o.gl;o.flush(),o.mapped=!1,o.bindFb(s),a.viewport(0,0,s.w,s.h),i||(a.disable(a.SCISSOR_TEST),a.clearColor(0,0,0,0),a.clear(a.COLOR_BUFFER_BIT)),o.use(t);let l=s.f;a.uniform2f(t.uScale,2/(l*s.w),-2/(l*s.h));let u=Math.floor(o.rx0/l)*l,c=Math.floor(o.ry0/l)*l,f=Math.min(Math.ceil(o.rx1/l),s.w)*l,p=Math.min(Math.ceil(o.ry1/l),s.h)*l,m=1/(r*e.width),b=1/(r*e.height);o.bScis=!1,o.batch.push(u,c,f,c,f,p,u,p,u*m,1-c*b,f*m,1-p*b,4294967295,o.slotOf(e)),o.flush()}post(t){var e,r;return t==="color"?(e=this.colorProg)!=null?e:this.colorProg=this.r.build(ha(this.colorN)):(r=this.blurProg)!=null?r:this.blurProg=this.r.build(fa())}linear(t,e){var o;let r=this.r,s=r.gl;r.bindTex((o=r.layerTex.get(t))!=null?o:null,0);let i=e?s.LINEAR:s.NEAREST;s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,i),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,i)}chain(t,e,r){let s=this.r,i=this.steps,o=s.scale,a=s.maxBlur,l=0;for(let p=0;p<r.length;p++){let m=r[p];if(m.enabled)if(m.kind===1&&m.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 b=this.mats[l-1],y=this.counts[l-1];if(y<this.colorN)m.toMatrix(this.fm),b.set(this.fm,y*20),this.counts[l-1]=y+1;else{let d=(y-1)*20;for(let g=0;g<20;g++)this.fm2[g]=b[d+g];m.toMatrix(this.fm),da(this.fm2,this.fm,this.fm3),b.set(this.fm2,d)}}else m.kind===4?this.userProg(m.source,!0)?i[l++]=m:s.skipped++:m.kind===2?Math.min(m.radius,a)*o>=.25&&(i[l++]=m):m.kind===3?i[l++]=m:s.skipped++}if(!l)return!1;let u=s.gl,c=t,f=-1;for(let p=0;p<l;p++){let m=p===l-1,b=f===0?1:0,y=m?null:this.scratch(1,b);if(!m&&!y)break;let d=i[p];if(d===null){let g=this.post("color");s.use(g);let w=this.mats[p],S=this.counts[p],v=this.m16,F=this.o4;for(let R=0;R<S;R++)for(let C=0;C<4;C++){for(let M=0;M<4;M++)v[R*16+M*4+C]=w[R*20+C*5+M];F[R*4+C]=w[R*20+C*5+4]}u.uniformMatrix4fv(s.u(g,"uM"),!1,v),u.uniform4fv(s.u(g,"uO"),F),u.uniform1i(s.u(g,"uK"),S),y?this.pass(g,c,1,y):s.final(g,c,1,e)}else if(d.kind===2)this.blur(c,f<0,Math.min(d.radius,a)*o,y,e,null);else if(d.kind===3){let g=d,w=this.scratch(1,2);if(!w)break;this.blur(c,f<0,Math.max(Math.min(g.blur,a),0)*o,w,1,g);let S=y!=null?y:e<1?this.scratch(1,b):null;S?(this.pass(s.main,w.tex,1,S),this.pass(s.main,c,1,S,!0),y||s.final(s.main,S.tex,1,e)):(s.final(s.main,w.tex,1,1),s.final(s.main,c,1,1))}else{let g=d,w=this.userProg(g.source,!0);s.use(w);let S=s.canvas.width,v=s.canvas.height;u.uniform2f(s.u(w,"uResolution"),S,v),u.uniform1f(s.u(w,"uTime"),s.time),u.uniform4f(s.u(w,"uRect"),s.rx0/S,1-s.ry1/v,s.rx1/S,1-s.ry0/v);let F=g.uniforms;for(let R in F){let C=s.u(w,R);if(!C)continue;let M=F[R];typeof M=="number"?u.uniform1f(C,M):M.length===2?u.uniform2fv(C,M):M.length===3?u.uniform3fv(C,M):M.length===4?u.uniform4fv(C,M):M.length===1&&u.uniform1fv(C,M)}y?this.pass(w,c,1,y):s.final(w,c,1,e)}y&&(c=y.tex,f=b)}return s.remap(),!0}blur(t,e,r,s,i,o){let a=this.r,l=a.gl,u=this.post("blur"),c=1;for(;c<16&&r/c>8;)c*=2;e&&this.linear(t,!0);let f=t,p=1,m=Math.sqrt(Math.max(r*r-(c*c-1)/12,0))/c,b=r>=.25?this.tapsFor(m):this.tapsFor(0),y=!0;if(b>1){for(let g=2;g<=c&&y;g*=2){let w=this.scratch(g,0);w?(this.pass(a.main,f,p,w),f=w.tex,p=g):y=!1}let d=y?this.scratch(c,3):null;d&&(a.use(u),l.uniform2fv(a.u(u,"uTaps"),this.taps),l.uniform1i(a.u(u,"uN"),b),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"),b),l.uniform2f(a.u(u,"uDir"),0,1/f.height),o){let d=o.opacity,g=o.rgb;l.uniform4f(a.u(u,"uShadow"),(g>>16&255)/255*d,(g>>8&255)/255*d,(g&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);s?this.pass(u,f,p,s):a.final(u,f,p,i),e&&this.linear(t,!1)}tapsFor(t){let e=this.taps;if(e.fill(0),e[1]=1,t<.2)return 1;let r=Math.min(Math.ceil(3*t),(Or-1)*2),s=-1/(2*t*t),i=1,o=1;for(let a=1;a<=r;a+=2){let l=Math.exp(a*a*s),u=a+1<=r?Math.exp((a+1)*(a+1)*s):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 Ue=n=>Math.min(Math.max(n,0),1),Te=n=>Math.max(n,0),it=class{constructor(){h(this,"enabled",!0);me.gl=Hi,me.c2d=Ui}},Ce=class extends it{constructor(e){super();h(this,"amount",e);h(this,"kind",1)}params(e,r){return e[r]=this.amount,r+1}};function Ir(n,t,e){n.fill(0),n[0]=n[6]=n[12]=t,n[4]=n[9]=n[14]=e,n[18]=1}function Br(n,t){n.fill(0);for(let e=0;e<3;e++)for(let r=0;r<3;r++)n[e*5+r]=t[e*3+r];n[18]=1}var D=new Float64Array(9),Cn=class extends Ce{toMatrix(t){Ir(t,Te(this.amount),0)}css(){return"brightness(".concat(Te(this.amount),")")}},Pn=class extends Ce{toMatrix(t){let e=Te(this.amount);Ir(t,e,.5-.5*e)}css(){return"contrast(".concat(Te(this.amount),")")}},Ln=class extends Ce{toMatrix(t){let e=Ue(this.amount);Ir(t,1-2*e,e)}css(){return"invert(".concat(Ue(this.amount),")")}},Nn=class extends Ce{toMatrix(t){let e=Te(this.amount);D[0]=.213+.787*e,D[1]=.715-.715*e,D[2]=.072-.072*e,D[3]=.213-.213*e,D[4]=.715+.285*e,D[5]=.072-.072*e,D[6]=.213-.213*e,D[7]=.715-.715*e,D[8]=.072+.928*e,Br(t,D)}css(){return"saturate(".concat(Te(this.amount),")")}},On=class extends Ce{toMatrix(t){let e=1-Ue(this.amount);D[0]=.2126+.7874*e,D[1]=.7152-.7152*e,D[2]=.0722-.0722*e,D[3]=.2126-.2126*e,D[4]=.7152+.2848*e,D[5]=.0722-.0722*e,D[6]=.2126-.2126*e,D[7]=.7152-.7152*e,D[8]=.0722+.9278*e,Br(t,D)}css(){return"grayscale(".concat(Ue(this.amount),")")}},In=class extends Ce{toMatrix(t){let e=1-Ue(this.amount);D[0]=.393+.607*e,D[1]=.769-.769*e,D[2]=.189-.189*e,D[3]=.349-.349*e,D[4]=.686+.314*e,D[5]=.168-.168*e,D[6]=.272-.272*e,D[7]=.534-.534*e,D[8]=.131+.869*e,Br(t,D)}css(){return"sepia(".concat(Ue(this.amount),")")}},Bn=class extends Ce{get angle(){return this.amount}set angle(t){this.amount=t}toMatrix(t){let e=this.amount*Math.PI/180,r=Math.cos(e),s=Math.sin(e);D[0]=.213+r*.787-s*.213,D[1]=.715-r*.715-s*.715,D[2]=.072-r*.072+s*.928,D[3]=.213-r*.213+s*.143,D[4]=.715+r*.285+s*.14,D[5]=.072-r*.072-s*.283,D[6]=.213-r*.213-s*.787,D[7]=.715-r*.715+s*.715,D[8]=.072+r*.928+s*.072,Br(t,D)}css(){return"hue-rotate(".concat(this.amount,"deg)")}},Dn=class extends Ce{constructor(e,r){super(r);h(this,"c",16777215);h(this,"cs","");this.color=e}get color(){return this.c}set color(e){this.c=ae(e)[0],this.cs=Je(this.c)}params(e,r){return e[r]=this.amount,e[r+1]=this.c,r+2}toMatrix(e){let r=Ue(this.amount);Ir(e,1-r,0),e[4]=(this.c>>16&255)/255*r,e[9]=(this.c>>8&255)/255*r,e[14]=(this.c&255)/255*r}css(){return null}paint2d(e,r,s,i,o){let a=Ue(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(r,s,i,o),e.restore())}},Un=class extends it{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 ".concat(e.length));this.values=Array.from(e)}toMatrix(e){var r;for(let s=0;s<20;s++)e[s]=(r=this.values[s])!=null?r:0}params(e,r){var s;for(let i=0;i<20;i++)e[r+i]=(s=this.values[i])!=null?s:0;return r+20}css(e,r,s){return s?s(this.values):null}},Hn=class extends it{constructor(e){super();h(this,"radius",e);h(this,"kind",2)}params(e,r){return e[r]=this.radius,r+1}pad(e){return 3*Math.min(Te(this.radius),e)}css(e,r){return"blur(".concat(Math.min(Te(this.radius),r)*e,"px)")}},Gn=class extends it{constructor(e,r,s,i){super();h(this,"dx",e);h(this,"dy",r);h(this,"blur",s);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=Ue(e)}get color(){return this.rgb}set color(e){let[r,s]=ae(e);this.rgb=r,this.a=s}params(e,r){return e[r]=this.dx,e[r+1]=this.dy,e[r+2]=this.blur,e[r+3]=this.rgb,e[r+4]=this.a,r+5}pad(e){return 3*Math.min(Te(this.blur),e)+Math.max(Math.abs(this.dx),Math.abs(this.dy))}css(e,r){return"drop-shadow(".concat(this.dx*e,"px ").concat(this.dy*e,"px ").concat(2*Math.min(Te(this.blur),r)*e,"px ").concat(Je(this.rgb,this.opacity),")")}},pa="#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nuniform sampler2D uTexture;\nuniform vec2 uResolution;\nuniform float uTime;\nuniform vec4 uRect;\nvarying vec2 vUv;\nvarying vec4 vColor;\n#define main fabiUserMain\n#line 1\n",ma=n=>"".concat(pa).concat(n,"\n#undef main\nvoid main() {\n fabiUserMain();\n gl_FragColor *= vColor.a;\n}\n"),zn=class extends it{constructor(e){var r,s;super();h(this,"kind",4);h(this,"source");h(this,"uniforms",{});h(this,"padding");this.source=ma(e.fragment),this.padding=(r=e.padding)!=null?r:0;for(let i in(s=e.uniforms)!=null?s:{}){let o=e.uniforms[i];this.uniforms[i]=typeof o=="number"?o:Float32Array.from(o)}}pad(){return Te(this.padding)}},Gi=(n,t=1)=>new Dn(n,t),zi=n=>new Cn(n),$i=n=>new Pn(n),Vi=n=>new Nn(n),Wi=(n=1)=>new On(n),Xi=(n=1)=>new In(n),ji=n=>new Bn(n),qi=(n=1)=>new Ln(n),Ki=n=>new Un(n),Yi=n=>new Hn(n),Qi=(n,t,e,r="rgba(0,0,0,0.5)")=>new Gn(n,t,e,r);function Zi(n){var r,s;let t=new zn(n),e=(s=(r=me.live)==null?void 0:r.filters())==null?void 0:s.check(t.source);if(e)throw new Error("shader(): the fragment does not compile:\n".concat(e));return t}var $n="x y rotation scaleX scaleY alpha visible blend tint z hitRadius clip mask filters".split(" "),eo="frameName _frame _w _h slice autoAnchor".split(" "),ba="fps loop speed onComplete durations".split(" "),Vn=["anchorX","anchorY"],ya=[...$n,...eo,...ba,...Vn],ga=[...$n,...eo,...Vn],xa=[...$n,...Vn],to=n=>n instanceof Ae?ya:n instanceof be?ga:xa;function va(n){let t={},e=n;for(let r of to(n))t[r]=e[r];return n instanceof Me&&(t.spec=n.spec),n instanceof Re&&(t.text=n.text,t.style=n.style),n instanceof Ae&&(t.playing=n.playing),t}function Ji(n,t){let e=n;n instanceof Me&&n.spec!==t.spec&&(n.spec=t.spec),n instanceof Re&&(n.text=t.text,n.style!==t.style&&(e._style=t.style,e.dirty=!0)),n instanceof Ae&&n.gotoFrame(t.speed<0?n.frameCount-1:0);let r=n instanceof Me||n instanceof Re,s=to(n);for(let i=0;i<s.length;i++){let o=s[i];(!r||o!=="_frame"&&o!=="frameName")&&(e[o]=t[o])}}var er=class{constructor(t,e={}){h(this,"factory",t);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(t){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 r=this.states.get(e);Ji(e,r),e.visible=r.visible,e instanceof Ae&&r.playing&&e.play()}else{if(e=this.factory(),!(e instanceof we))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,va(e)),e._pool=this,this.stats.created++}return this.stats.live++,t&&e.set(t),e}release(t){var r,s,i;let e=this.states.get(t);if(!(!e||t.destroyed)&&!t._free){if(this.opts.max!==void 0&&this.free.length>=this.opts.max)return t.destroy();(r=t.parent)==null||r.remove(t),t.kernel.tweens.stopAll(t),this.stats.live--,Ji(t,e),t instanceof Ae&&t.stop(),t.visible=!1,t._free=!0,(i=(s=this.opts).reset)==null||i.call(s,t),this.free.push(t),this.stats.free++}}forget(t){let e=t;if(this.states.delete(e))if(e._free){let r=this.free.indexOf(e);r>=0&&(this.free[r]=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 t of[...this.states.keys()])t.destroy()}},ro=(n,t)=>new er(n,t);window.FabiEngine=Wn;})();
|