@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.
@@ -1,105 +1 @@
1
- /*! @fabiplay/engine 0.9.0 (lite: load fabi-play.js first) | Fabi Play Kit License | https://docs.fabiplay.app */(function(Xs,Et){var ue=typeof document<"u"?document.currentScript:null;typeof define=="function"&&define.amd?define([],function(){return Et(ue)}):typeof module=="object"&&module&&module.exports?module.exports=Et(ue):Xs.FabiEngine=Et(ue)})(typeof globalThis<"u"?globalThis:typeof self<"u"?self:this,function(Xs){"use strict";var Et={exports:{}},ue=Et.exports,de=Object.defineProperty,bn=Object.getOwnPropertyDescriptor,Mn=Object.getOwnPropertyNames,An=Object.prototype.hasOwnProperty,kn=(t,e,s)=>e in t?de(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,_n=(t,e)=>{for(var s in e)de(t,s,{get:e[s],enumerable:!0})},En=(t,e,s,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Mn(e))!An.call(t,n)&&n!==s&&de(t,n,{get:()=>e[n],enumerable:!(i=bn(e,n))||i.enumerable});return t},Sn=t=>En(de({},"__esModule",{value:!0}),t),c=(t,e,s)=>kn(t,typeof e!="symbol"?e+"":e,s),$s={};_n($s,{AnimatedSprite:()=>Rt,Atlas:()=>fs,AvatarPainter:()=>_s,AvatarsNode:()=>Vi,BitmapFont:()=>Es,DEFAULT_FONT:()=>Ci,EASE:()=>Qt,Group:()=>ls,HALO:()=>ie,MAX_LAYERS:()=>as,NameTags:()=>As,Node:()=>St,NodePool:()=>rn,Particles:()=>hi,STAGE_HEIGHT:()=>Y,Shape:()=>te,ShelfPacker:()=>li,Sound:()=>zi,Sprite:()=>Ot,TIERS:()=>dt,Text:()=>ne,Timeline:()=>Yi,Tweens:()=>ji,avatarPortrait:()=>Dr,blur:()=>$a,brightness:()=>Ia,colorMatrix:()=>Xa,contrast:()=>Oa,createAvatarRenderer:()=>Ur,createEngine:()=>aa,createRenderer:()=>bs,dropShadow:()=>Ha,grayscale:()=>Da,handsOf:()=>Ui,hits:()=>Ss,hueRotate:()=>za,invert:()=>Ga,nodePool:()=>Ka,packColor:()=>It,parseBMFont:()=>Pe,parseColor:()=>ht,pickTier:()=>Gi,playerColor:()=>Ne,rendererOrder:()=>Fi,rng:()=>jn,saturate:()=>Ua,sepia:()=>Ba,shader:()=>qa,shapeBounds:()=>ks,tier:()=>Ft,tint:()=>La,touching:()=>Di,wrists:()=>Oi}),Et.exports=Sn($s);var Tn=33,et={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},Rn=4,pe=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"],Fn={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},ho=Fn["6-8"],Hs=(t,e)=>t?{x:t.x+e.x*t.w,y:t.y+e.y*t.h}:{x:e.x,y:e.y},Cn=.5,ge={left:1.6,top:1.6,w:3.2,h:3},Pn=1.2;function Nn(t,e,s={}){const i=Array.isArray(t)?t:t.body;if(!Array.isArray(i))return null;const n=e==="left"?et.leftWrist:et.rightWrist,r=w=>Yt(i[w*3])&&Yt(i[w*3+1])&&(i[w*3+2]??0)>=Cn?w:-1;if(r(n)<0)return null;const a=i[n*3],h=i[n*3+1];if(s.orientation!=="portrait")return Hs(s.view,{x:a,y:h});if(r(et.leftShoulder)<0||r(et.rightShoulder)<0)return null;const l=et.leftShoulder*3,o=et.rightShoulder*3,f=(i[l]+i[o])/2,u=(i[l+1]+i[o+1])/2,g=et.leftHip*3,p=et.rightHip*3,d=(i[g]+i[p])/2,y=(i[g+1]+i[p+1])/2;let m=Yt(d)&&Yt(y)?Math.hypot(d-f,y-u):0;return(r(et.leftHip)<0||r(et.rightHip)<0)&&(m=Math.max(m,Pn*Math.hypot(i[l]-i[o],i[l+1]-i[o+1]))),m=Math.max(m,.01),{x:Ws((a-f+ge.left*m)/(ge.w*m)),y:Ws((h-u+ge.top*m)/(ge.h*m))}}var Ln=300,qs=class{constructor(t=Ln){c(this,"holdMs",t),c(this,"last",new Map)}static key(t,e){return t*2+(e==="right"?1:0)}at(t,e,s){const i=this.last.get(t);return e?(i?(i.x=e.x,i.y=e.y,i.t=s):this.last.set(t,{x:e.x,y:e.y,t:s}),e):i?s-i.t<=this.holdMs?{x:i.x,y:i.y}:(this.last.delete(t),null):null}clear(){this.last.clear()}},In=.25,On=Object.freeze({top:0,bottom:0,left:0,right:0});function Un(t){if(!Dn(t))return;const e=s=>Yt(s)?Math.min(Math.max(s,0),In):0;return{top:e(t.top),bottom:e(t.bottom),left:e(t.left),right:e(t.right)}}var lo=16/9,Dn=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Yt=t=>typeof t=="number"&&Number.isFinite(t),Ws=t=>Math.min(Math.max(t,0),1),Bn=12,zn=Tn*4,Gn=t=>Bn+t*zn,co=Gn(Rn),Xn=t=>t.startsWith("fabi-play.")?`fablee-play.${t.slice(10)}`:null;function $n(t,e,s=Xn(e)){if(!(!t||!s))try{const i=t.getItem(s);if(i===null)return;t.getItem(e)===null&&t.setItem(e,i),t.removeItem(s)}catch{}}var Ys=globalThis.FabiPlay?.avatars;if(!Ys)throw new Error("[engine] fabi-play-engine.lite.js needs fabi-play.js (with FabiPlay.avatars) loaded before it");var{avatarById:me,avatarShapes:Hn,BAND_BODY:fo,DEFAULT_AVATAR:ye,drawShapes:js,frameOf:qn,iconShapes:Wn}=Ys,Lt=()=>Float64Array.of(1,0,0,1,0,0);function ft(t,e,s,i,n,r,a){const h=n?Math.cos(n):1,l=n?Math.sin(n):0,o=h*r,f=l*r,u=-l*a,g=h*a;if(!e)return t[0]=o,t[1]=f,t[2]=u,t[3]=g,t[4]=s,t[5]=i,t;const p=e[0],d=e[1],y=e[2],m=e[3];return t[0]=p*o+y*f,t[1]=d*o+m*f,t[2]=p*u+y*g,t[3]=d*u+m*g,t[4]=p*s+y*i+e[4],t[5]=d*s+m*i+e[5],t}function Yn(t,e,s){const i=t[0]*t[3]-t[1]*t[2];if(Math.abs(i)<1e-12)return null;const n=e-t[4],r=s-t[5];return[(t[3]*n-t[2]*r)/i,(-t[1]*n+t[0]*r)/i]}var Vs={white:16777215,black:0,red:16711680,transparent:0},jt=new Map;function ht(t){if(typeof t=="number")return[t&16777215,1];const e=jt.get(t);if(e)return e;let s=[16777215,1];const i=t.trim().toLowerCase();if(i[0]==="#"){const n=i.slice(1),r=n.length<=4?[...n].map(h=>h+h).join(""):n,a=parseInt(r.slice(0,6),16);Number.isFinite(a)&&(s=[a,r.length===8?parseInt(r.slice(6,8),16)/255:1])}else if(i.startsWith("rgb")){const n=i.match(/-?\d*\.?\d+%?/g)?.map(o=>o.endsWith("%")?parseFloat(o)/100*255:parseFloat(o))??[],[r=255,a=255,h=255]=n,l=n[3]===void 0?1:i.match(/,\s*[\d.]+%\s*\)$/)?n[3]/255:n[3];s=[(Ke(r)<<16|Ke(a)<<8|Ke(h))>>>0,Math.min(Math.max(l,0),1)]}else if(i in Vs)s=[Vs[i],i==="transparent"?0:1];else if(typeof document<"u"){const n=document.createElement("canvas").getContext("2d");if(n){n.fillStyle="#ffffff",n.fillStyle=i;const r=n.fillStyle;if(r!==i)return jt.set(t,s=ht(r)),s}}return jt.size>512&&jt.clear(),jt.set(t,s),s}var Ke=t=>Math.min(Math.max(Math.round(t),0),255);function It(t,e,s=!1){const i=Math.min(Math.max(e,0),1),n=(t>>16&255)*i,r=(t>>8&255)*i,a=(t&255)*i,h=s?0:i*255;return(Math.round(h)<<24|Math.round(a)<<16|Math.round(r)<<8|Math.round(n))>>>0}var Vt=(t,e=1)=>`rgba(${t>>16&255},${t>>8&255},${t&255},${e})`;function Qs(t,e){if(t===16777215)return e;if(e===16777215)return t;const s=i=>Math.round((t>>i&255)*(e>>i&255)/255);return(s(16)<<16|s(8)<<8|s(0))>>>0}var Qt={linear:t=>t,quadIn:t=>t*t,quadOut:t=>t*(2-t),quadInOut:t=>t<.5?2*t*t:-1+(4-2*t)*t,cubicOut:t=>1-(1-t)**3,sineInOut:t=>-(Math.cos(Math.PI*t)-1)/2,backOut:t=>1+(1.70158+1)*(t-1)**3+1.70158*(t-1)**2,elasticOut:t=>t===0||t===1?t:2**(-10*t)*Math.sin((t*10-.75)*(2*Math.PI/3))+1,bounceOut:t=>t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375};function jn(t){let e=t>>>0;return()=>{e=e+1831565813>>>0;let s=e;return s=Math.imul(s^s>>>15,s|1),s^=s+Math.imul(s^s>>>7,s|61),((s^s>>>14)>>>0)/4294967296}}var Kt=1,Ks=2,ve=0,nt=1,Vn=4294967295,A={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},yt=[],Qn="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function Zs(t){const e=A;for(const i of Qn){const n=e[i],r=new n.constructor(i==="world"?t*6:t);r.set(n),e[i]=r}const s=new Int32Array(t);for(let i=0;i<A.freeCount;i++)s[i]=A.free[(A.freeHead+i)%A.cap];for(A.free=s,A.freeHead=0,A.cap=t,A.epoch++;yt.length<t;)yt.push(null)}function Ze(t){A.x[t]=A.y[t]=A.rot[t]=0,A.sx[t]=A.sy[t]=A.alpha[t]=1,A.la[t]=A.ld[t]=1,A.lb[t]=A.lc[t]=0;const e=t*6,s=A.world;s[e]=s[e+3]=1,s[e+1]=s[e+2]=s[e+4]=s[e+5]=0,A.tint[t]=16777215,A.flags[t]=Kt|Ks,A.moved[t]=1,A.dirty[t]=0,A.parent[t]=A.first[t]=A.next[t]=A.prev[t]=-1}Zs(256),Ze(ve),A.flags[ve]=0,Ze(nt),A.flags[nt]=0;function Kn(){let t;if(A.freeCount){t=A.free[A.freeHead],A.freeHead=(A.freeHead+1)%A.cap,A.freeCount--;const e=yt[t];e&&(e._i=ve,e._g=-1,yt[t]=null)}else A.top===A.cap&&Zs(A.cap*2),t=A.top++;return Ze(t),t}function Js(t,e){Je(t);for(let i=A.first[t];i>=0;){const n=A.next[i];A.parent[i]=A.next[i]=A.prev[i]=-1,i=n}A.first[t]=-1,A.flags[t]=A.flags[t]&~Ks,A.moved[t]=0;const s=A.gen[t]+1;A.gen[t]=s,s!==Vn&&(e&&(yt[t]=e),A.free[(A.freeHead+A.freeCount)%A.cap]=t,A.freeCount++)}function Zn(t){for(let e=0;e<yt.length;e++){const s=yt[e];s&&t(s)&&(s._i=ve,s._g=-1,yt[e]=null)}}function Jn(t,e){Je(t);const s=A.first[e];A.parent[t]=e,A.next[t]=s,A.prev[t]=-1,s>=0&&(A.prev[s]=t),A.first[e]=t,A.moved[t]=1}function Je(t){const e=A.parent[t];if(e<0)return;const s=A.next[t],i=A.prev[t];i>=0?A.next[i]=s:A.first[e]=s,s>=0&&(A.prev[s]=i),A.parent[t]=A.next[t]=A.prev[t]=-1}var Zt={root:-1,gen:-1,world:new Float64Array(6)};function tr(t){const e=++A.pass,s=A.world,i=t*6,n=Zt.world;let r=Zt.root!==t||Zt.gen!==A.gen[t];for(let a=0;a<6;a++)n[a]!==s[i+a]&&(r=!0),n[a]=s[i+a];Zt.root=t,Zt.gen=A.gen[t],A.stamp[t]=r?e:e-1}function er(t){A.stamp[t]=A.pass}function ti(t){for(let e=A.first[t];e>=0;){const s=A.next[e];ti(e),e=s}Js(t)}var ts=typeof FinalizationRegistry=="function"?new FinalizationRegistry(t=>A.gen[t.i]===t.g&&ti(t.i)):null;function ei(t){t._reg||!ts||(t._reg=!0,ts.register(t,{i:t._i,g:t._g},t))}function sr(t){t._reg&&ts.unregister(t)}var es=1,ss=2,is=3,ns=4;function rs(t){if(t){for(let e=0;e<t.length;e++)if(t[e].enabled)return!0}return!1}function ir(t,e){let s=0;for(let i=0;i<t.length;i++){const n=t[i];n.enabled&&n.pad&&(s+=n.pad(e))}return s}var lt={gl:null,c2d:null,live:null},U=new Float64Array(3),as=4,nr=1,os=()=>nr++,H=Lt(),R=A,St=class{constructor(t){c(this,"kernel",t),c(this,"_i",Kn()),c(this,"_g",R.gen[this._i]),c(this,"_wv",null),c(this,"_wi",-1),c(this,"_we",-1),c(this,"blend","normal"),c(this,"_data",null),c(this,"parent",null),c(this,"hitRadius",null),c(this,"clip",null),c(this,"mask",null),c(this,"filters",null),c(this,"_z",0),c(this,"anchorX",0),c(this,"anchorY",0),c(this,"_pool",null),c(this,"_free",!1),c(this,"_reg",!1)}get x(){return R.x[this._i]}set x(t){const e=this._i||nt;R.x[e]=t,R.moved[e]=1}get y(){return R.y[this._i]}set y(t){const e=this._i||nt;R.y[e]=t,R.moved[e]=1}get rotation(){return R.rot[this._i]}set rotation(t){const e=this._i||nt;R.rot[e]=t,R.dirty[e]=R.moved[e]=1}get scaleX(){return R.sx[this._i]}set scaleX(t){const e=this._i||nt;R.sx[e]=t,R.dirty[e]=R.moved[e]=1}get scaleY(){return R.sy[this._i]}set scaleY(t){const e=this._i||nt;R.sy[e]=t,R.dirty[e]=R.moved[e]=1}get alpha(){return R.alpha[this._i]}set alpha(t){const e=this._i||nt;R.alpha[e]=t,R.moved[e]=1}get visible(){return(R.flags[this._i]&Kt)!==0}set visible(t){const e=this._i||nt;t?R.flags[e]=R.flags[e]|Kt:R.flags[e]=R.flags[e]&~Kt,R.moved[e]=1}get destroyed(){return R.gen[this._i]!==this._g}get world(){const t=this._i||nt;return(this._wi!==t||this._we!==R.epoch)&&(this._wv=R.world.subarray(t*6,t*6+6),this._wi=t,this._we=R.epoch),this._wv}get data(){return this._data??(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 R.tint[this._i]}set tint(t){R.tint[this._i||nt]=typeof t=="number"?t&16777215:ht(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(const e in t){const s=t[e];s!==void 0&&(this[e]=s)}return this}destroy(){this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),Js(this._i,this),sr(this),this.kernel.tweens.stopAll(this),this._pool?.forget(this))}updateWorld(){const t=this.parent?this.parent.updateWorld():null;return ft(this.world,t,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(t,e,s){}};function rr(t){Zn(e=>e.kernel===t)}var hs=!1,si=Object.freeze([]),ls=class xn extends St{constructor(e){super(e),c(this,"children",si),c(this,"sortDirty",!1),c(this,"dead",!1),ei(this)}add(e,...s){this.adopt(e);for(let i=0;i<s.length;i++)this.adopt(s[i]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&Jn(e._i,this._i),this.children===si&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||ei(e)}detach(e){const s=this.children,i=s.indexOf(e);if(i>=0){for(let n=i+1;n<s.length;n++)s[n-1]=s[n];s.pop()}e.parent===this&&(e.parent=null,e.destroyed||Je(e._i))}clear(){for(const e of this.children)e.destroy()}destroy(){for(const e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(const s of this.children)s.destroyed?s.parent===this&&(s.parent=null):this.children[e++]=s;this.children.length=e}for(const e of this.children)e instanceof xn&&e.sweep()}draw(e,s,i){if(hs)return R.parent[this._i]<0&&!this.destroyed&&er(this._i),this.drawChildren(e,s,i);hs=!0;try{this.destroyed||tr(this._i),this.drawChildren(e,s,i)}finally{hs=!1}}drawChildren(e,s,i){if(this.sortDirty){const h=new Map(this.children.map((l,o)=>[l,o]));this.children.sort((l,o)=>l.z-o.z||h.get(l)-h.get(o)),this.sortDirty=!1}const n=this.children,r=this._i,a=R.stamp[r]===R.pass;for(let h=0;h<n.length;h++){const l=n[h],o=l._i,f=R.alpha[o];if(R.gen[o]!==l._g||!(R.flags[o]&Kt)||f<=0)continue;if(a||R.moved[o]){R.moved[o]=0,R.stamp[o]=R.pass;let p,d,y,m;if(R.dirty[o]){R.dirty[o]=0;const B=R.rot[o],W=B?Math.cos(B):1,X=B?Math.sin(B):0,D=R.sx[o],Ht=R.sy[o];R.la[o]=p=W*D,R.lb[o]=d=X*D,R.lc[o]=y=-X*Ht,R.ld[o]=m=W*Ht}else p=R.la[o],d=R.lb[o],y=R.lc[o],m=R.ld[o];const w=R.world,x=R.x[o],k=R.y[o],M=o*6,T=r*6,E=w[T],F=w[T+1],L=w[T+2],N=w[T+3];w[M]=E*p+L*d,w[M+1]=F*p+N*d,w[M+2]=E*y+L*m,w[M+3]=F*y+N*m,w[M+4]=E*x+L*k+w[T+4],w[M+5]=F*x+N*k+w[T+5]}const u=s*f,g=Qs(i,R.tint[o]);l.clip||l.mask||l.filters?ni(e,l,u,g):l.draw(e,u,g)}}},V=new Float64Array(128),Tt=0,cs=new Float64Array(8);function ii(t,e,s,i){e.clip||e.mask||e.filters?ni(t,e,s,i):e.draw(t,s,i)}function ni(t,e,s,i){const n=t.r,r=e.world,a=e.clip;let h=!1,l=!1;if(a)if(Math.abs(r[1])<1e-9&&Math.abs(r[2])<1e-9&&Tt<32){const u=r[0]*a.x+r[4],g=r[0]*(a.x+a.width)+r[4],p=r[3]*a.y+r[5],d=r[3]*(a.y+a.height)+r[5];let y=Math.min(u,g),m=Math.max(u,g),w=Math.min(p,d),x=Math.max(p,d);if(Tt){const M=(Tt-1)*4;y=Math.max(y,V[M]),w=Math.max(w,V[M+1]),m=Math.min(m,V[M+2]),x=Math.min(x,V[M+3])}const k=Tt++*4;V[k]=y,V[k+1]=w,V[k+2]=m,V[k+3]=x,n.clip(y,w,Math.max(m-y,0),Math.max(x-w,0)),l=!0}else h=!0;const o=e.mask&&e.mask.visible?e.mask:null,f=rs(e.filters)?e.filters:null;try{if(h&&n.beginLayer(),o&&n.beginLayer(),f?(e.draw(t,n.beginLayer()?1:s,i),n.endLayer(s,f)):e.draw(t,s,i),o&&(n.beginMask(),ft(o.world,r,o.x,o.y,o.rotation,o.scaleX,o.scaleY),ii(t,o,o.alpha,16777215),n.endLayer(1)),h&&a){n.beginMask();for(let u=0;u<4;u++){const g=u===1||u===2?a.x+a.width:a.x,p=u>1?a.y+a.height:a.y;cs[u*2]=r[0]*g+r[2]*p+r[4],cs[u*2+1]=r[1]*g+r[3]*p+r[5]}n.polygon(cs,4,16777215,1),n.endLayer(1)}}finally{if(l)if(Tt--,Tt){const u=(Tt-1)*4;n.clip(V[u],V[u+1],V[u+2]-V[u],V[u+3]-V[u+1])}else n.unclip()}}var Ot=class extends St{constructor(t,e,s){super(t),c(this,"_frame",null),c(this,"_w",null),c(this,"_h",null),c(this,"slice",0),c(this,"autoAnchor",!0),c(this,"frameName",null),e&&(this.frame=e),s?.anchor===void 0&&this.useFrameAnchor(),s&&this.set(s)}get frame(){return this._frame}set frame(t){this.frameName=typeof t=="string"?t:null,this._frame=typeof t=="string"?this.kernel.frame(t):t,this.autoAnchor&&this.useFrameAnchor()}set anchor(t){this.autoAnchor=!1,super.anchor=t}get naturalWidth(){const t=this.frameNow();return t?(t.sw??t.w)/t.scale-t.margin*2:0}get naturalHeight(){const t=this.frameNow();return t?(t.sh??t.h)/t.scale-t.margin*2:0}get width(){return this._w??this.naturalWidth}set width(t){this._w=t}get height(){return this._h??this.naturalHeight}set height(t){this._h=t}sizeQ(t){Bt[0]=this._w??(t.sw??t.w)/t.scale-t.margin*2,Bt[1]=this._h??(t.sh??t.h)/t.scale-t.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){const t=this._frame;if(!t)return;const e=(t.sw??t.w)/t.scale-t.margin*2,s=(t.sh??t.h)/t.scale-t.margin*2;this.anchorX=e>0?(t.ox-t.margin)/e:0,this.anchorY=s>0?(t.oy-t.margin)/s:0}draw(t,e,s){const i=this.frameNow();if(!i)return;const n=Bt;this.sizeQ(i),n[2]=this.anchorX,n[3]=this.anchorY,n[4]=e,ar(t,i,this.world,this.slice,s,this.blend)}},Ut=new Float64Array(12),Dt=new Float64Array(12),Jt={x:0,y:0,w:0,h:0};function ri(t,e,s,i,n,r){e=Math.max(e,0),s=Math.max(s,0),i=Math.max(i,0);const a=s+i>n?s*n/(s+i):s,h=s+i>n?i*n/(s+i):i;let l=a/r,o=h/r;if(l+o>e){const f=e/(l+o);l*=f,o*=f}t[0]=0,t[1]=l,t[2]=0,t[3]=a,t[4]=l,t[5]=e-l-o,t[6]=a,t[7]=n-a-h,t[8]=e-o,t[9]=o,t[10]=n-h,t[11]=h}var Bt=new Float64Array(5);function ar(t,e,s,i,n,r){const a=Bt,h=a[0],l=a[1],o=a[2],f=a[3],u=a[4],g=t.tex(e.surface),p=i===0?e.slice??0:i;if(p===0){const M=(e.sw??e.w)/e.scale-e.margin*2,T=(e.sh??e.h)/e.scale-e.margin*2,E=M>0?h/M:1,F=T>0?l/T:1,L=-o*h+((e.tx??0)/e.scale-e.margin)*E,N=-f*l+((e.ty??0)/e.scale-e.margin)*F;we(s,L,N),U[0]=e.w/e.scale*E,U[1]=e.h/e.scale*F,U[2]=u,t.r.quadQ(g,e,H,n,r);return}const d=e.tx??0,y=e.ty??0,m=(e.sw??e.w)-e.w-d,w=(e.sh??e.h)-e.h-y,x=-o*h-e.margin+d/e.scale,k=-f*l-e.margin+y/e.scale;if(ri(Ut,h+e.margin*2-(d+m)/e.scale,(typeof p=="number"?p:p[3])-d,(typeof p=="number"?p:p[1])-m,e.w,e.scale),ri(Dt,l+e.margin*2-(y+w)/e.scale,(typeof p=="number"?p:p[0])-y,(typeof p=="number"?p:p[2])-w,e.h,e.scale),we(s,x,k),U[2]=u,!t.r.nineQ?.(g,e,Ut,Dt,H,n,r))for(let M=0;M<12;M+=4){const T=Dt[M+1],E=Dt[M+3];if(!(T<=0||E<=0))for(let F=0;F<12;F+=4){const L=Ut[F+1],N=Ut[F+3];L<=0||N<=0||(Jt.x=e.x+Ut[F+2],Jt.y=e.y+Dt[M+2],Jt.w=N,Jt.h=E,we(s,x+Ut[F],k+Dt[M]),U[0]=L,U[1]=T,U[2]=u,t.r.quadQ(g,Jt,H,n,r))}}}function we(t,e,s){H[0]=t[0],H[1]=t[1],H[2]=t[2],H[3]=t[3],H[4]=t[0]*e+t[2]*s+t[4],H[5]=t[1]*e+t[3]*s+t[5]}var te=class extends Ot{constructor(t,e,s={}){super(t,null),c(this,"_spec"),c(this,"baked",null),c(this,"bakedEffects",!0),this._spec=e,this.bake(),s.anchor===void 0&&this.useFrameAnchor(),this.set(s)}get spec(){return this._spec}set spec(t){this._spec=t,this.baked=null,this._w=this._h=null,this.bake()}bake(){const t=this.kernel;return this.baked&&t.atlas.valid(this.baked.frame)&&this.baked.frame.scale===t.pixelScale&&this.bakedEffects===t.effects?this.baked:(this.bakedEffects=t.effects,this.baked=t.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(){const t=this.bake();Bt[0]=this._w??t.w,Bt[1]=this._h??t.h}get width(){return this._w??this.bake().w}set width(t){this._w=t}get height(){return this._h??this.bake().h}set height(t){this._h=t}},ai=(t,e,s)=>t===void 0?e:typeof t=="number"?t:t[0]+(t[1]-t[0])*s(),oi=class fe extends St{constructor(e,s,i={}){super(e),c(this,"max"),c(this,"f"),c(this,"tints"),c(this,"count",0),c(this,"gravity"),c(this,"drag"),c(this,"frameRef"),c(this,"random",Math.random),this.frameRef=s,this.max=Math.max(1,Math.floor(i.max??200)),this.f=new Float32Array(this.max*fe.W),this.tints=new Uint32Array(this.max),this.blend=i.blend??"normal",this.gravity=i.gravity??0,this.drag=i.drag??1}get alive(){return this.count}burst(e,s,i,n={}){const r=fe.W,a=this.random,h=n.tint===void 0?16777215:ht(n.tint)[0];for(let l=0;l<i;l++){let o=this.count;if(o>=this.max){let y=0,m=1/0;for(let w=0;w<this.max;w++){const x=this.f[w*r+5]-this.f[w*r+4];x<m&&(m=x,y=w)}o=y}else this.count++;const f=(n.angle??0)+(n.spread===void 0?a()*Math.PI*2:(a()-.5)*n.spread),u=ai(n.speed,200,a),g=Array.isArray(n.scale)?n.scale[0]:n.scale??1,p=Array.isArray(n.scale)?n.scale[1]:n.scale??1,d=o*r;this.f[d]=e,this.f[d+1]=s,this.f[d+2]=Math.cos(f)*u,this.f[d+3]=Math.sin(f)*u,this.f[d+4]=0,this.f[d+5]=Math.max(ai(n.life,.8,a),.01),this.f[d+6]=a()*Math.PI*2,this.f[d+7]=(a()-.5)*2*(n.spin??0),this.f[d+8]=g,this.f[d+9]=p,this.f[d+10]=n.alpha??1,this.tints[o]=h}}update(e){const s=fe.W,i=this.f,n=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let r=0;r<this.count;){const a=r*s;if(i[a+4]=i[a+4]+e,i[a+4]>=i[a+5]){const h=--this.count;r!==h&&(i.copyWithin(a,h*s,h*s+s),this.tints[r]=this.tints[h]);continue}i[a+3]=(i[a+3]+this.gravity*e)*n,i[a+2]=i[a+2]*n,i[a]=i[a]+i[a+2]*e,i[a+1]=i[a+1]+i[a+3]*e,i[a+6]=i[a+6]+i[a+7]*e,r++}}clear(){this.count=0}draw(e,s,i){if(!this.count)return;const n=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,r=fe.W,a=this.f,h=this.world,l=n.w/n.scale,o=n.h/n.scale;for(let f=0;f<this.count;f++){const u=f*r,g=a[u+4]/a[u+5],p=a[u+8]+(a[u+9]-a[u+8])*g,d=s*a[u+10]*(1-g*g),y=a[u+6],m=Math.cos(y)*p,w=Math.sin(y)*p,x=a[u],k=a[u+1],M=h[0],T=h[1],E=h[2],F=h[3],L=M*m+E*w,N=T*m+F*w,B=E*m-M*w,W=F*m-T*w;H[0]=L,H[1]=N,H[2]=B,H[3]=W,H[4]=M*x+E*k+h[4]-(L*l+B*o)/2,H[5]=T*x+F*k+h[5]-(N*l+W*o)/2,U[0]=l,U[1]=o,U[2]=d,e.r.quadQ(e.tex(n.surface),n,H,Qs(i,this.tints[f]),this.blend)}}};c(oi,"W",11);var hi=oi,Rt=class extends Ot{constructor(t,e,s={}){const{fps:i,loop:n,playing:r,speed:a,onComplete:h,...l}=s;if(!e.frames.length)throw new Error("[engine] an animation needs at least one frame");super(t,e.frames[0],l),c(this,"frames"),c(this,"durations"),c(this,"fps"),c(this,"loop"),c(this,"speed"),c(this,"onComplete"),c(this,"_playing"),c(this,"index",0),c(this,"t",0),this.frames=e.frames,this.durations=e.durations&&i===void 0?e.durations:null,this.fps=i??12,this.loop=n!==!1,this.speed=a??1,this.onComplete=h??null,this._playing=r!==!1,this.speed<0&&this.show(e.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(t){const e=this.frames.length;return this.show((Math.floor(t)%e+e)%e),this.t=0,this}gotoAndPlay(t){return this._playing=!0,this.gotoFrame(t)}gotoAndStop(t){return this._playing=!1,this.gotoFrame(t)}show(t){t===this.index&&this._frame||(this.index=t,this.frame=this.frames[t])}secondsOf(t){const e=this.durations?.[t];return e!==void 0&&e>0?e:1/Math.max(this.fps,.001)}update(t){if(!this._playing||this.destroyed||this.speed===0)return;const e=this.frames.length,s=this.speed<0;this.t+=t*Math.abs(this.speed);let i=this.index;for(let n=0;n<1e3;n++){const r=this.secondsOf(i);if(this.t<r)break;this.t-=r;const a=s?i-1:i+1;if(a<0||a>=e){if(!this.loop){this.t=0,this._playing=!1,this.show(i),this.onComplete?.();return}i=s?e-1:0}else i=a}this.show(i)}},or=(t,e)=>t.localeCompare(e,void 0,{numeric:!0}),li=class{constructor(t,e,s=2){c(this,"width",t),c(this,"height",e),c(this,"padding",s),c(this,"shelves",[]),c(this,"free",[]),c(this,"bottom",0)}alloc(t,e){const s=Math.ceil(t)+this.padding*2,i=Math.ceil(e)+this.padding*2;if(s>this.width||i>this.height)return null;for(let a=0;a<this.free.length;a++){const h=this.free[a];if(h.w>=s&&h.h>=i&&h.w*h.h<=s*i*2)return this.free.splice(a,1),{...this.inner(h.x,h.y,t,e),slot:h}}let n=null;for(const a of this.shelves)a.h>=i&&a.h<=i*1.5+8&&this.width-a.x>=s&&(!n||a.h<n.h)&&(n=a);if(!n)if(this.bottom+i>this.height){for(const a of this.shelves)a.h>=i&&this.width-a.x>=s&&(n=a);if(!n)return null}else n={y:this.bottom,h:i,x:0},this.shelves.push(n),this.bottom+=i;const r=n.x;return n.x+=s,this.inner(r,n.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,s,i){return{x:t+this.padding,y:e+this.padding,w:s,h:i}}},xe=t=>({source:t,texture:null,pending:[]}),fs=class{constructor(t=2048,e=4){c(this,"pageSize",t),c(this,"maxPages",e),c(this,"pages",[]),c(this,"gen",1),c(this,"onPage",()=>{}),c(this,"onDrop",()=>{})}valid(t){return!!t&&(t.gen===this.gen||t.gen===0)}bake(t,e,s,i=1,n=0,r=0,a=0){const h=Math.max(1,Math.ceil(t)),l=Math.max(1,Math.ceil(e)),o=document.createElement("canvas");o.width=h,o.height=l;const f=o.getContext("2d");return s(f),this.put(o,h,l,i,n,r,a)}add(t,e=1,s=0,i=0){const n=document.createElement("canvas");return n.width=Math.max(1,t.width),n.height=Math.max(1,t.height),n.getContext("2d").drawImage(t,0,0),this.put(n,n.width,n.height,e,s,i,0)}release(t){if(t.gen!==this.gen)return;this.pages.find(s=>s.surface===t.surface)?.packer.release(t)}rebake(t,e,s,i,n=t.w,r=t.h){if(!this.valid(t)||e>n||s>r)return null;const a=Math.max(1,Math.ceil(e)),h=Math.max(1,Math.ceil(s)),l=this.pages.find(f=>f.surface===t.surface);if(!l)return null;const o=document.createElement("canvas");return o.width=Math.ceil(n),o.height=Math.ceil(r),i(o.getContext("2d")),l.ctx.clearRect(t.x,t.y,o.width,o.height),l.ctx.drawImage(o,t.x,t.y),t.surface.pending.push([o,t.x,t.y]),t.w=a,t.h=h,t}put(t,e,s,i,n,r,a){let h=null,l=this.pages.find(f=>(h=f.packer.alloc(e,s))!==null);if(l||(!(Math.max(e,s)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),l=this.pages[0],h=l?l.packer.alloc(e,s):null),(!l||!h)&&(l=this.newPage(Math.max(e,s)),h=l.packer.alloc(e,s))),!h)throw new Error(`[engine] ${e}\xD7${s} does not fit an atlas page`);const o=h;if(o.slot){const f=o.slot;l.ctx.clearRect(f.x,f.y,f.w,f.h);const u=document.createElement("canvas");u.width=f.w,u.height=f.h,u.getContext("2d").drawImage(t,o.x-f.x,o.y-f.y),l.surface.pending.push([u,f.x,f.y])}else l.surface.pending.push([t,o.x,o.y]);return l.ctx.drawImage(t,o.x,o.y),{surface:l.surface,x:o.x,y:o.y,w:e,h:s,scale:i,gen:this.gen,ox:n,oy:r,margin:a}}newPage(t){let e=this.pageSize;for(;e<t+4;)e*=2;const s=document.createElement("canvas");s.width=s.height=e;const i=s.getContext("2d"),n=xe(s),r={surface:n,packer:new li(e,e),ctx:i};return this.pages.push(r),this.onPage(n),r}wipe(){this.gen++;let t=0;for(let e=0;e<this.pages.length;e++){const s=this.pages[e];if(t<this.maxPages&&s.surface.source.width===this.pageSize){this.pages[t++]=s;continue}s.surface.pending=[],this.onDrop(s.surface)}this.pages.length=t;for(const 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])}},hr=()=>globalThis.FabiPlay,lr=class{constructor(){c(this,"amount",.5)}setLocal(t){this.amount=t?.8:.5}get defaultAmount(){return this.amount}posed(t,e,s,i=!0){const n={id:t,body:e};return hr()?.smoothedBody(n,{smooth:s<1?s:!1,interpolate:i})??e}},ci=new Float64Array(1),fi=new Int32Array(ci.buffer),zt=(t,e)=>(t=Math.imul(t^e,1540483477),t^t>>>15);function vt(t,e=2538058380){return t!==t?zt(e,2146959360):(ci[0]=t===0?0:t,zt(zt(e,fi[0]),fi[1]))}function ui(t,e=2166136261){for(let s=0;s<t.length;s++)e=Math.imul(e^t.charCodeAt(s),16777619);return e}function wt(t){switch(typeof t){case"number":return vt(t);case"string":return ui(t);case"boolean":return t?1013904242:461845907;case"object":{if(t===null)return 625341585;if(Array.isArray(t)||t instanceof Float64Array){let i=1779033703^t.length;for(let n=0;n<t.length;n++){const r=t[n];i=zt(i,typeof r=="number"?vt(r):wt(r))}return i}let e=1359893119;const s=t;for(const i in s){const n=s[i];n!==void 0&&(e=e+zt(ui(i),wt(n))|0)}return zt(e,2600822924)}default:return 0}}function ee(t,e){if(t===e)return!0;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return typeof t=="number"&&typeof e=="number"&&t!==t&&e!==e;const s=Array.isArray(t)||t instanceof Float64Array;if(s!==(Array.isArray(e)||e instanceof Float64Array))return!1;if(s){const r=t,a=e;if(r.length!==a.length)return!1;for(let h=0;h<r.length;h++)if(r[h]!==a[h]&&!ee(r[h],a[h]))return!1;return!0}const i=t,n=e;for(const r in i)if(i[r]!==void 0&&!ee(i[r],n[r]))return!1;for(const r in n)if(n[r]!==void 0&&i[r]===void 0)return!1;return!0}function be(t){if(typeof t!="object"||t===null)return t;if(Array.isArray(t))return t.map(be);if(t instanceof Float64Array)return t.slice();const e={};for(const s in t)t[s]!==void 0&&(e[s]=be(t[s]));return e}var di=class{constructor(t=1/0){c(this,"max",t),c(this,"buckets",new Map),c(this,"n",0)}get size(){return this.n}get(t,e=wt(t)){const s=this.buckets.get(e);if(s){for(let i=0;i<s.length;i++)if(ee(s[i].key,t))return s[i].value}}set(t,e,s=wt(t)){let i=this.buckets.get(s);if(i){for(const n of i)if(ee(n.key,t)){n.value=e;return}}this.n>=this.max&&this.clear(),(!i||!this.buckets.has(s))&&this.buckets.set(s,i=[]),i.push({key:be(t),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}},us=0,pi=1,Me=2,ds=3,gi=class{constructor(){c(this,"scale",1),c(this,"cOn",!1),c(this,"px0",0),c(this,"py0",0),c(this,"px1",0),c(this,"py1",0),c(this,"clipVer",0),c(this,"stack",[]),c(this,"sp",0),c(this,"real",0),c(this,"mute",0),c(this,"bnd",new Float64Array(4*(as+1))),c(this,"rx0",0),c(this,"ry0",0),c(this,"rx1",0),c(this,"ry1",0),c(this,"maxBlur",1/0),c(this,"time",0),c(this,"skipped",0),c(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(){const t=this.gq;this.grow(t[0],t[1],t[2],t[3])}grow(t,e,s,i){if(!this.real)return;const n=this.bnd,r=(this.real-1)*4;t<n[r]&&(n[r]=t),e<n[r+1]&&(n[r+1]=e),s>n[r+2]&&(n[r+2]=s),i>n[r+3]&&(n[r+3]=i)}area(t,e){const s=this.bnd,i=t*4,n=this.scale;return this.rx0=Math.max(Math.floor((s[i]-e)*n)-1,0),this.ry0=Math.max(Math.floor((s[i+1]-e)*n)-1,0),this.rx1=Math.min(Math.ceil((s[i+2]+e)*n)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((s[i+3]+e)*n)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(t,e,s,i){const n=this.scale,r=this.canvas.width,a=this.canvas.height,h=Math.min(Math.max(Math.round(t*n),0),r),l=Math.min(Math.max(Math.round(e*n),0),a),o=Math.min(Math.max(Math.round((t+s)*n),h),r),f=Math.min(Math.max(Math.round((e+i)*n),l),a);this.cOn&&h===this.px0&&l===this.py0&&o===this.px1&&f===this.py1||(this.cOn=!0,this.px0=h,this.py0=l,this.px1=o,this.py1=f,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(t){if(t<Me&&(this.mute||this.real>=as||!this.pushLayer())&&(t+=2),t===ds)this.mute++;else if(t!==Me){const 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<Me}beginLayer(){return this.push(us)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===us?pi:ds)}endLayer(t,e){if(!this.sp)return;let s=this.stack[--this.sp];if(s===ds){if(this.mute--,!this.sp)return;s=this.stack[--this.sp]}if(s===pi){const i=--this.real,n=this.popLayer();this.area(i-1,0)&&this.composite(n,!0,1,null);const r=this.bnd,a=(i-1)*4,h=i*4;r[a]=Math.max(r[a],r[h]),r[a+1]=Math.max(r[a+1],r[h+1]),r[a+2]=Math.min(r[a+2],r[h+2]),r[a+3]=Math.min(r[a+3],r[h+3]),s=this.stack[--this.sp]}if(s===Me)rs(e)&&(this.skipped+=e.length);else if(s===us){const i=--this.real,n=rs(e)?e:null,r=this.popLayer();if(this.area(i,n?ir(n,this.maxBlur):0)){this.composite(r,!1,t,n);const a=this.scale;this.grow(this.rx0/a,this.ry0/a,this.rx1/a,this.ry1/a)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}},cr=256,mi=8<<20,K=new Float64Array(32),Z={x:0,y:0,w:0,h:0};function fr(t){if(typeof t.filter!="string")return!1;t.filter="blur(1px)";const e=t.filter==="blur(1px)";return t.filter="none",e}function ps(t){const e=t.getContext("2d",{alpha:!0});return e?new ur(t,e):null}var ur=class extends gi{constructor(t,e){super(),c(this,"canvas",t),c(this,"ctx",e),c(this,"kind","canvas2d"),c(this,"maxTextureSize",4096),c(this,"features",{}),c(this,"info",{renderer:"canvas2d"}),c(this,"support"),c(this,"lost",!1),c(this,"fxr",null),c(this,"quads",0),c(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),c(this,"tinted",new Map),c(this,"tintedN",0),c(this,"lostListeners",[]),c(this,"restoredListeners",[]),c(this,"base"),c(this,"top"),c(this,"layers",[]),c(this,"scratch",[]),c(this,"nines",new Map),c(this,"ninePx",0),c(this,"frame",0),c(this,"hit",!1),c(this,"missed",new Map),this.support={filters:fr(e),shaders:!1},this.base=this.top={ctx:e,clipped:!1,ver:0},t.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(s=>s())}),t.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(s=>s())})}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){return{id:os(),width:t.width,height:t.height,source:t}}updateTexture(t,e,s=0,i=0){const n=e?s+e.width:1/0,r=e?i+e.height:1/0;for(const a of this.nines.values()){const h=a.key;h[0]===t.id&&h[1]<n&&h[1]+h[3]>s&&h[2]<r&&h[2]+h[4]>i&&this.dropNine(a)}for(const[a,h]of this.tinted){const l=h.filter(o=>o.id!==t.id);this.tintedN-=h.length-l.length,l.length?this.tinted.set(a,l):this.tinted.delete(a)}}destroyTexture(t){this.updateTexture(t)}begin(t,e,s){this.resetLayers(s),this.fxr?.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;const 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),e>0&&(i.fillStyle=Vt(t,e),i.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(t,e,s,i,n,r,a,h){U[0]=i,U[1]=n,U[2]=a,this.quadQ(t,e,s,r,h)}quadQ(t,e,s,i,n){e.w<=0||e.h<=0||(i===16777215?this.blit(t.source,e.x,e.y,e.w,e.h,s,n):this.blit(this.tint(t,e,i),0,0,e.w,e.h,s,n))}blit(t,e,s,i,n,r,a){const h=U[0],l=U[1],o=U[2];if(o<=0||this.mute)return;this.sync();const f=this.ctx,u=this.scale;if(this.real){const g=r[0]*h,p=r[1]*h,d=r[2]*l,y=r[3]*l;this.grow(r[4]+Math.min(0,g,d,g+d),r[5]+Math.min(0,p,y,p+y),r[4]+Math.max(0,g,d,g+d),r[5]+Math.max(0,p,y,p+y))}f.setTransform(r[0]*u,r[1]*u,r[2]*u,r[3]*u,r[4]*u,r[5]*u),f.globalAlpha=Math.min(o,1),a==="add"&&(f.globalCompositeOperation="lighter"),f.drawImage(t,e,s,i,n,0,0,h,l),a==="add"&&(f.globalCompositeOperation="source-over"),this.quads++}nineQ(t,e,s,i,n,r,a){var h,l;const o=s[8]+s[9],f=i[8]+i[9],u=Math.ceil(o*Math.hypot(n[0],n[1])*this.scale-1e-6),g=Math.ceil(f*Math.hypot(n[2],n[3])*this.scale-1e-6);if(n[1]===0&&n[2]===0||u>4096||g>4096)return!1;if(!(u>0&&g>0&&U[2]>0)||this.mute)return!0;let p=this.kept(t,e,s,i,u,g,r);const d=(p??(p=(h=this.scratch)[l=13*Math.ceil(Math.log2(u))+Math.ceil(Math.log2(g))]??(h[l]=document.createElement("canvas").getContext("2d")))).canvas;if(d.width<u&&(d.width=u),d.height<g&&(d.height=g),!this.hit){p.clearRect(0,0,u+2,g+2);for(let y=0;y<12;y+=4){const m=Math.round(i[y]*g/f),w=Math.round((i[y]+i[y+1])*g/f);for(let x=0;x<12;x+=4){const k=Math.round(s[x]*u/o),M=Math.round((s[x]+s[x+1])*u/o);Z.x=e.x+s[x+2],Z.y=e.y+i[y+2],Z.w=s[x+3],Z.h=i[y+3],!(M<=k||w<=m||Z.w<=0||Z.h<=0)&&(r===16777215?p.drawImage(t.source,Z.x,Z.y,Z.w,Z.h,k,m,M-k,w-m):p.drawImage(this.tint(t,Z,r),0,0,Z.w,Z.h,k,m,M-k,w-m))}}}return U[0]=o,U[1]=f,this.blit(d,0,0,u,g,n,a),!0}kept(t,e,s,i,n,r,a){K[0]=t.id,K[1]=e.x,K[2]=e.y,K[3]=e.w,K[4]=e.h,K[5]=n,K[6]=r,K[7]=a,K.set(s,8),K.set(i,20);const h=wt(K),l=this.nines.get(h);if(this.hit=!1,l)return ee(l.key,K)?(l.used=this.frame,this.hit=!0,l.ctx):null;const o=this.missed,f=o.get(h);o.size>4096&&o.clear(),o.set(h,this.frame);const u=n*r;if(f!==this.frame-1||u>mi)return null;let g;for(;this.ninePx+u>mi;){let y;for(const x of this.nines.values())x.used<this.frame-1&&!(y&&y.used<=x.used)&&(y=x);if(!y)return null;const m=y.ctx.canvas,w=!g&&m.width>=n&&m.height>=r&&m.width*m.height<=2*u;this.dropNine(y,w),w&&(g=y.ctx)}const p=g??document.createElement("canvas").getContext("2d"),d=p.canvas;return g||(d.width=n,d.height=r),this.ninePx+=d.width*d.height,this.nines.set(h,{key:be(K),ctx:p,used:this.frame}),p}dropNine(t,e=!1){this.nines.delete(wt(t.key));const s=t.ctx.canvas;this.ninePx-=s.width*s.height,e||(s.width=0)}dropNines(){for(const t of this.nines.values())this.dropNine(t)}tint(t,e,s){const i=vt(s,vt(e.h,vt(e.w,vt(e.y,vt(e.x,vt(t.id))))));let n=this.tinted.get(i);if(n)for(let h=0;h<n.length;h++){const l=n[h];if(l.id===t.id&&l.x===e.x&&l.y===e.y&&l.w===e.w&&l.h===e.h&&l.color===s)return l.canvas}this.tintedN>=cr&&(this.tinted.clear(),this.tintedN=0,n=void 0);const r=document.createElement("canvas");r.width=Math.ceil(e.w),r.height=Math.ceil(e.h);const a=r.getContext("2d");return a.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),a.globalCompositeOperation="multiply",a.fillStyle=Vt(s),a.fillRect(0,0,e.w,e.h),a.globalCompositeOperation="destination-in",a.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),n||this.tinted.set(i,n=[]),n.push({id:t.id,x:e.x,y:e.y,w:e.w,h:e.h,color:s,canvas:r}),this.tintedN++,r}paint(t,e){this.sync();const s=this.ctx,i=this.scale;return s.setTransform(i,0,0,i,0,0),s.globalAlpha=Math.min(e,1),Vt(t)}ellipse(t,e,s,i,n,r,a){if(a<=0||s<=0||i<=0||this.mute)return;const h=Math.max(s,i);this.grow(t-h,e-h,t+h,e+h);const l=this.ctx;l.fillStyle=this.paint(r,a),l.beginPath(),l.ellipse(t,e,s,i,n,0,Math.PI*2),l.fill(),this.quads++}trace(t,e,s=0){if(this.real)for(let n=0;n<e;n++)this.grow(t[n*2]-s,t[n*2+1]-s,t[n*2]+s,t[n*2+1]+s);const i=this.ctx;i.beginPath(),i.moveTo(t[0],t[1]);for(let n=1;n<e;n++)i.lineTo(t[n*2],t[n*2+1])}polygon(t,e,s,i){if(i<=0||e<3||this.mute)return;const n=this.ctx;n.fillStyle=this.paint(s,i),this.trace(t,e),n.closePath(),n.fill(),this.quads++}stroke(t,e,s,i,n,r){if(n<=0||s<=0||e<1||this.mute)return;const a=this.ctx;a.strokeStyle=this.paint(i,n),a.lineWidth=s,a.lineCap="round",a.lineJoin="round",this.trace(t,e,s/2),e===1&&a.lineTo(t[0],t[1]),r&&a.closePath(),a.stroke(),this.quads++}sync(){const t=this.top;if(t.ver===this.clipVer)return;const e=t.ctx;t.clipped&&e.restore(),t.clipped=this.cOn,t.ver=this.clipVer,this.cOn&&(e.save(),e.setTransform(1,0,0,1,0,0),e.beginPath(),e.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),e.clip())}pushLayer(){const t=this.canvas.width,e=this.canvas.height;let s=this.layers[this.real];if(!s||s.ctx.canvas.width!==t||s.ctx.canvas.height!==e){const n=document.createElement("canvas");n.width=t,n.height=e;const r=n.getContext("2d");if(!r)return!1;s=this.layers[this.real]={ctx:r,clipped:!1,ver:-1}}const 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,t,e),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(t,e,s,i){let n=t,r="none";const a=i&&lt.c2d?this.fxr??(this.fxr=lt.c2d(this)):null;a&&(n=a.chain(t,i),r=a.css),this.sync();const h=this.ctx,l=this.rx0,o=this.ry0,f=this.rx1-l,u=this.ry1-o;h.setTransform(1,0,0,1,0,0),h.globalAlpha=Math.min(s,1),h.globalCompositeOperation=e?"destination-in":"source-over",r!=="none"&&(h.filter=r),h.drawImage(n,l,o,f,u,l,o,f,u),r!=="none"&&(h.filter="none"),h.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();const t=this.stats;return t.drawCalls=t.quads=this.quads,t.filtersSkipped=this.skipped,t}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],this.fxr?.destroy(),this.fxr=null}},se=14,Gt=6,yi=8192,dr=class{constructor(t,e,s=yi){c(this,"instanced",t),c(this,"slots",e),c(this,"capacity",s),c(this,"f32"),c(this,"u32"),c(this,"quads",0),c(this,"textures"),c(this,"bound",0),this.textures=new Array(e).fill(null);const i=s*(t?se:Gt*4),n=new ArrayBuffer(i*4);this.f32=new Float32Array(n),this.u32=new Uint32Array(n)}slot(t){const e=this.textures;for(let s=0;s<this.bound;s++)if(e[s]===t)return s;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?se:Gt*4)}reset(){this.quads=0;for(let t=0;t<this.bound;t++)this.textures[t]=null;this.bound=0}push(t,e,s,i,n,r,a,h,l,o,f,u,g,p){const d=this.f32;if(this.instanced){let y=this.quads*se;d[y++]=t,d[y++]=e,d[y++]=s,d[y++]=i,d[y++]=n,d[y++]=r,d[y++]=a,d[y++]=h,d[y++]=l,d[y++]=o,d[y++]=f,d[y++]=u,this.u32[y++]=g,d[y]=p}else{const y=this.quads*Gt*4;this.vertex(y,t,e,l,o,g,p),this.vertex(y+6,s,i,f,o,g,p),this.vertex(y+12,n,r,f,u,g,p),this.vertex(y+18,a,h,l,u,g,p)}this.quads++}pushQ(t,e){const s=this.f32;if(this.instanced){const i=this.quads*se;for(let n=0;n<12;n++)s[i+n]=t[n];this.u32[i+12]=t[12],s[i+13]=e}else{let i=this.quads*Gt*4;const n=t[12];for(let r=0;r<4;r++,i+=Gt)s[i]=t[r*2],s[i+1]=t[r*2+1],s[i+2]=r===1||r===2?t[10]:t[8],s[i+3]=r>=2?t[11]:t[9],this.u32[i+4]=n,s[i+5]=e}this.quads++}vertex(t,e,s,i,n,r,a){const h=this.f32;h[t]=e,h[t+1]=s,h[t+2]=i,h[t+3]=n,this.u32[t+4]=r,h[t+5]=a}};function pr(t){const e=new Uint16Array(t*6);for(let s=0,i=0,n=0;s<t;s++,i+=6,n+=4)e[i]=n,e[i+1]=n+1,e[i+2]=n+2,e[i+3]=n,e[i+4]=n+2,e[i+5]=n+3;return e}var J={M:0,L:1,Q:2,C:3,Z:4},vi=[2,2,4,6,0],gr={M:0,L:1,Q:2,C:3,Z:4};function gs(t,e){if(t.length>=e)return t;const s=new Float64Array(Math.max(e,t.length*2,16));return s.set(t),s}var Ae=new Map;function mr(t){if(typeof t!="string")return t;let e=Ae.get(t);if(e)return e;e=[];const s=t.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[];let i=-1;for(let n=0;n<s.length;){const r=s[n],a=gr[r.toUpperCase()];if(a!==void 0){i=a,n++,a===J.Z&&e.push(J.Z);continue}if(i<0||i===J.Z){n++;continue}const h=vi[i];e.push(i);for(let l=0;l<h;l++)e.push(Number(s[n+l]??0));n+=h,i===J.M&&(i=J.L)}return Ae.size>256&&Ae.clear(),Ae.set(t,e),e}var xt={subs:[],count:0},ms=null,bt=null;function ke(t,e){let s=bt;s||(s=xt.subs[xt.count]??null,s||xt.subs.push(s={pts:new Float64Array(64),n:0,closed:!1}),s.n=0,s.closed=!1,xt.count++,bt=s);const i=s.n*2;i+2>s.pts.length&&(s.pts=gs(s.pts,i+2));const n=ms;n?(s.pts[i]=n[0]*t+n[2]*e+n[4],s.pts[i+1]=n[1]*t+n[3]*e+n[5]):(s.pts[i]=t,s.pts[i+1]=e),s.n++}function ys(t,e=null,s=1,i=6){const n=mr(t);xt.count=0,bt=null,ms=e;let r=0,a=0,h=0,l=0;const o=s/i;for(let f=0;f<n.length;){const u=n[f++],g=n;if(u===J.M)bt=null,r=h=g[f],a=l=g[f+1],ke(r,a);else if(u===J.L)r=g[f],a=g[f+1],ke(r,a);else if(u===J.Q){const p=g[f],d=g[f+1],y=g[f+2],m=g[f+3],w=wi((ut(p-r,d-a)+ut(y-p,m-d))*o);for(let x=1;x<=w;x++){const k=x/w,M=1-k;ke(M*M*r+2*M*k*p+k*k*y,M*M*a+2*M*k*d+k*k*m)}r=y,a=m}else if(u===J.C){const p=g[f],d=g[f+1],y=g[f+2],m=g[f+3],w=g[f+4],x=g[f+5],k=wi((ut(p-r,d-a)+ut(y-p,m-d)+ut(w-y,x-m))*o);for(let M=1;M<=k;M++){const T=M/k,E=1-T,F=E*E*E,L=3*E*E*T,N=3*E*T*T,B=T*T*T;ke(F*r+L*p+N*y+B*w,F*a+L*d+N*m+B*x)}r=w,a=x}else if(u===J.Z){bt&&(bt.closed=!0),bt=null,r=h,a=l;continue}else break;f+=vi[u]}bt=null,ms=null;for(let f=0;f<xt.count;f++){const u=xt.subs[f],g=u.n*2;u.closed&&u.n>=2&&Math.abs(u.pts[0]-u.pts[g-2])<1e-6&&Math.abs(u.pts[1]-u.pts[g-1])<1e-6&&u.n--}return xt}var ut=(t,e)=>Math.sqrt(t*t+e*e),wi=t=>Math.min(Math.max(Math.ceil(t),2),24);function yr(t,e){let s=0;for(let i=0,n=e-1;i<e;n=i++)s+=(t[n*2]-t[i*2])*(t[n*2+1]+t[i*2+1]);return s}var _e=new Int32Array(64),Ee=(t,e,s,i,n)=>((t[i*2]-t[s*2])*(t[n*2+1]-t[s*2+1])-(t[i*2+1]-t[s*2+1])*(t[n*2]-t[s*2]))*e;function vr(t,e,s){if(e<3)return 0;_e.length<e&&(_e=new Int32Array(Math.max(e,_e.length*2)));const i=_e;let n=e,r=0;for(let o=0;o<e;o++)i[o]=o;const a=yr(t,e)>0?1:-1;let h=e*e+8,l=0;for(;n>3&&h-- >0;){const o=i[(l+n-1)%n],f=i[l%n],u=i[(l+1)%n];let g=Ee(t,a,o,f,u)>0;if(g)for(let p=0;p<n;p++){const d=i[p];if(!(d===o||d===f||d===u)&&Ee(t,a,o,f,d)>=0&&Ee(t,a,f,u,d)>=0&&Ee(t,a,u,o,d)>=0){g=!1;break}}g?(s[r++]=o,s[r++]=f,s[r++]=u,i.copyWithin(l%n,l%n+1,n),n--,l=Math.max(l-1,0)):l=(l+1)%n}if(n===3)s[r++]=i[0],s[r++]=i[1],s[r++]=i[2];else if(n>3)for(let o=1;o+1<n;o++)s[r++]=i[0],s[r++]=i[o],s[r++]=i[o+1];return r}var wr=.85,Se=new Float64Array(64),xi=new Float64Array(64),bi=new Float64Array(64),Mi=new Float64Array(64),Ai=new Float64Array(64),ki=new Float64Array(64),_i=new Uint8Array(64),Te=new Float64Array(8);function xr(t,e,s,i,n,r){const a=Te;if(Se.length<e){const m=Math.max(e,Se.length*2);Se=new Float64Array(m),xi=new Float64Array(m),bi=new Float64Array(m),Mi=new Float64Array(m),Ai=new Float64Array(m),ki=new Float64Array(m),_i=new Uint8Array(m)}const h=Se,l=xi;let o=0;for(let m=0;m<e;m++){const w=t[m*2],x=t[m*2+1];!Number.isFinite(w)||!Number.isFinite(x)||o&&Math.abs(h[o-1]-w)<.001&&Math.abs(l[o-1]-x)<.001||(h[o]=w,l[o]=x,o++)}if(i&&o>2&&Math.abs(h[0]-h[o-1])<.001&&Math.abs(l[0]-l[o-1])<.001&&o--,o===0)return;if(o===1)return a[0]=h[0],a[1]=l[0],r();const f=i?o:o-1,u=bi,g=Mi;for(let m=0;m<f;m++){const w=(m+1)%o,x=h[w]-h[m],k=l[w]-l[m],M=ut(x,k)||1;u[m]=-k/M,g[m]=x/M}const p=Ai,d=ki,y=_i;for(let m=0;m<o;m++){const w=i?(m-1+f)%f:m-1,x=m<f?m:-1;if(y[m]=1,w<0||x<0||u[w]*u[x]+g[w]*g[x]<wr)continue;let M=u[w]+u[x],T=g[w]+g[x];const E=ut(M,T)||1;M/=E,T/=E;const F=s/Math.max(M*u[x]+T*g[x],.5);p[m]=M*F,d[m]=T*F,y[m]=0}for(let m=0;m<f;m++){const w=(m+1)%o,x=y[m]?u[m]*s:p[m],k=y[m]?g[m]*s:d[m],M=y[w]?u[m]*s:p[w],T=y[w]?g[m]*s:d[w];a[0]=h[m]+x,a[1]=l[m]+k,a[2]=h[w]+M,a[3]=l[w]+T,a[4]=h[w]-M,a[5]=l[w]-T,a[6]=h[m]-x,a[7]=l[m]-k,n()}for(let m=0;m<o;m++)y[m]&&(a[0]=h[m],a[1]=l[m],r())}function Ei(t,e){let s=0,i=1/0;for(let n=0;n<e.length;n++){const r=Math.abs(Math.log(Math.max(t,.5)/e[n]));r<i&&(i=r,s=n)}return s}var st=256,vs=[{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}],ws=[4,8,16,32,64,128].map((t,e)=>({x:e*4,y:128,w:4,h:t,r:t/2-1})),Mt={x:248,y:248,w:8,h:8},br=vs.map(t=>t.r*2),Mr=ws.map(t=>t.r*2),Si=(t,e)=>Math.min(Math.max(t+.5-e,0),1);function Ar(){const t=new Uint8ClampedArray(st*st*4),e=(s,i,n)=>{const r=(i*st+s)*4;t[r]=t[r+1]=t[r+2]=255,t[r+3]=Math.round(n*255)};for(const s of vs){const i=s.w/2;for(let n=0;n<s.h;n++)for(let r=0;r<s.w;r++)e(s.x+r,s.y+n,Si(s.r,Math.hypot(r+.5-i,n+.5-i)))}for(const s of ws){const i=s.h/2;for(let n=0;n<s.h;n++)for(let r=0;r<s.w;r++)e(s.x+r,s.y+n,Si(s.r,Math.abs(n+.5-i)))}for(let s=0;s<Mt.h;s++)for(let i=0;i<Mt.w;i++)e(Mt.x+i,Mt.y+s,1);return t}function kr(){const t=document.createElement("canvas");return t.width=t.height=st,t.getContext("2d").putImageData(new ImageData(Ar(),st,st),0,0),t}var Ti=8,xs=`
2
- #ifdef GL_FRAGMENT_PRECISION_HIGH
3
- precision highp float;
4
- #else
5
- precision mediump float;
6
- #endif
7
- `,_r=t=>`${xs}
8
- uniform sampler2D uTex[${t}];
9
- varying vec2 vUv;
10
- varying vec4 vColor;
11
- varying float vSlot;
12
- void main() {
13
- vec4 c;
14
- ${Array.from({length:t},(e,s)=>s===t-1?`c = texture2D(uTex[${s}], vUv);`:`if (vSlot < ${s}.5) c = texture2D(uTex[${s}], vUv); else `).join(`
15
- `)}
16
- gl_FragColor = c * vColor;
17
- }`,Er=`
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
- }`,Sr=`
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
- }`,Tr={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},Rr=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],Fr=["aPos","aUv","aColor","aSlot"];function Cr(t,e,s={}){const i={...Tr,failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat!==!1},n=e===2?t.getContext("webgl2",i):t.getContext("webgl",i)??t.getContext("experimental-webgl",i);if(!n||n.isContextLost())return null;try{return new Pr(t,n,e,s)}catch(r){return console.warn("[engine] WebGL setup failed:",r),n.getExtension("WEBGL_lose_context")?.loseContext(),null}}var Pr=class extends gi{constructor(t,e,s,i){super(),c(this,"canvas",t),c(this,"gl",e),c(this,"opts",i),c(this,"kind"),c(this,"maxTextureSize"),c(this,"support",{filters:!0,shaders:!0}),c(this,"features",{}),c(this,"info",{}),c(this,"lost",!1),c(this,"main"),c(this,"cur"),c(this,"unit",-1),c(this,"onUnit",new Array(Ti).fill(void 0)),c(this,"fbNow"),c(this,"mapped",!0),c(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0}),c(this,"vsrc",""),c(this,"attrs",[]),c(this,"fxr",null),c(this,"batch"),c(this,"dynamic"),c(this,"staticBuf",null),c(this,"index"),c(this,"vao",null),c(this,"inst",null),c(this,"vaoApi",null),c(this,"uScale",null),c(this,"textures",new Map),c(this,"kit"),c(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),c(this,"lostListeners",[]),c(this,"restoredListeners",[]),c(this,"tris",new Int32Array(192)),c(this,"sU",0),c(this,"sV0",0),c(this,"sV1",0),c(this,"sColor",0),c(this,"sPacked",0),c(this,"sAlpha",0),c(this,"sHw",0),c(this,"strokeSeg",()=>{const n=this.q;n.set(Te),n[8]=n[10]=this.sU,n[9]=this.sV0,n[11]=this.sV1,n[12]=this.sPacked,this.put(this.kit)}),c(this,"strokeDisc",()=>this.ellipse(Te[0],Te[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha)),c(this,"q",new Float64Array(13)),c(this,"layers",[]),c(this,"layerTex",new Map),c(this,"bScis",!1),c(this,"bx0",0),c(this,"by0",0),c(this,"bx1",0),c(this,"by1",0),c(this,"onContextLost",n=>{n.preventDefault(),this.lost=!0;for(const r of this.lostListeners)r()}),c(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(const n of this.textures.keys())this.textures.set(n,this.upload(n.source));this.lost=!1;for(const n of this.restoredListeners)n()}catch(n){console.warn("[engine] WebGL restore failed:",n)}}),c(this,"views",new Map),this.kind=s===2?"webgl2":"webgl1",this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(kr()),lt.live=this,t.addEventListener("webglcontextlost",this.onContextLost,!1),t.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){const t=this.gl,e=this.kind==="webgl2"?t:null;if(this.inst=null,this.opts.instancing!==!1)if(e)this.inst={divisor:(o,f)=>e.vertexAttribDivisor(o,f),draw:(o,f)=>e.drawElementsInstanced(t.TRIANGLES,o,t.UNSIGNED_SHORT,0,f)};else{const o=t.getExtension("ANGLE_instanced_arrays");o&&(this.inst={divisor:(f,u)=>o.vertexAttribDivisorANGLE(f,u),draw:(f,u)=>o.drawElementsInstancedANGLE(t.TRIANGLES,f,t.UNSIGNED_SHORT,0,u)})}if(this.vaoApi=null,this.opts.vao!==!1)if(e)this.vaoApi={create:()=>e.createVertexArray(),bind:o=>e.bindVertexArray(o),remove:o=>e.deleteVertexArray(o)};else{const o=t.getExtension("OES_vertex_array_object");o&&(this.vaoApi={create:()=>o.createVertexArrayOES(),bind:f=>o.bindVertexArrayOES(f),remove:f=>o.deleteVertexArrayOES(f)})}const s=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),i=Math.max(1,Math.min(Ti,s)),n=this.inst!==null;this.vsrc=n?Sr:Er,this.attrs=n?Rr:Fr,this.main=this.cur=this.build(_r(i));const r=this.main.p;t.useProgram(r),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,t.uniform1iv(t.getUniformLocation(r,"uTex"),Int32Array.from({length:i},(o,f)=>f)),this.batch=new dr(n,i),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic),t.bufferData(t.ARRAY_BUFFER,this.batch.f32.byteLength,t.DYNAMIC_DRAW),this.index=t.createBuffer(),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.index),t.bufferData(t.ELEMENT_ARRAY_BUFFER,pr(n?1:yi),t.STATIC_DRAW);const a=o=>t.getAttribLocation(r,o),h=(o,f,u,g,p,d,y)=>{const m=a(o);m<0||(t.enableVertexAttribArray(m),t.vertexAttribPointer(m,f,u,g,p,d),this.inst&&this.inst.divisor(m,y))};if(n){const o=se*4;h("aP01",4,t.FLOAT,!1,o,0,1),h("aP23",4,t.FLOAT,!1,o,16,1),h("aUvRect",4,t.FLOAT,!1,o,32,1),h("aColor",4,t.UNSIGNED_BYTE,!0,o,48,1),h("aSlot",1,t.FLOAT,!1,o,52,1),this.staticBuf=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.staticBuf),t.bufferData(t.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t.STATIC_DRAW),h("aCorner",4,t.FLOAT,!1,16,0,0),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic)}else{const o=Gt*4;h("aPos",2,t.FLOAT,!1,o,0,0),h("aUv",2,t.FLOAT,!1,o,8,0),h("aColor",4,t.UNSIGNED_BYTE,!0,o,16,0),h("aSlot",1,t.FLOAT,!1,o,20,0)}t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.disable(t.DEPTH_TEST),t.disable(t.CULL_FACE),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);const l=t.getExtension("WEBGL_debug_renderer_info");this.info={version:t.getParameter(t.VERSION),renderer:l?t.getParameter(l.UNMASKED_RENDERER_WEBGL):t.getParameter(t.RENDERER),vendor:l?t.getParameter(l.UNMASKED_VENDOR_WEBGL):t.getParameter(t.VENDOR)},this.features={instancing:n,vao:this.vaoApi!==null,textureSlots:i,maxTextureSize:this.maxTextureSize}}upload(t){const e=this.gl,s=e.createTexture();return this.bindTex(s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),s}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){const e={id:os(),width:t.width,height:t.height,source:t};return this.textures.set(e,this.lost?null:this.upload(t)),e}updateTexture(t,e,s=0,i=0){if(this.lost)return;this.batch.has(t)&&this.flush();const n=this.gl,r=this.textures.get(t);r&&(this.bindTex(r),!e||e===t.source&&s===0&&i===0?n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t.source):n.texSubImage2D(n.TEXTURE_2D,0,s,i,n.RGBA,n.UNSIGNED_BYTE,e))}destroyTexture(t){this.batch.has(t)&&this.flush();const e=this.textures.get(t);e&&!this.lost&&this.deleteTex(e),this.textures.delete(t)}begin(t,e,s){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(s),this.bScis=!1,this.lost)return;const i=this.gl;i.disable(i.SCISSOR_TEST),this.bindFb(null),i.viewport(0,0,this.canvas.width,this.canvas.height);const n=e;i.clearColor((t>>16&255)/255*n,(t>>8&255)/255*n,(t&255)/255*n,n),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(t){const e=this.gl,s=Ri(e,e.VERTEX_SHADER,this.vsrc);let i;try{i=Ri(e,e.FRAGMENT_SHADER,t)}catch(r){throw e.deleteShader(s),r}const n=e.createProgram();if(e.attachShader(n,s),e.attachShader(n,i),this.attrs.forEach((r,a)=>e.bindAttribLocation(n,a,r)),e.linkProgram(n),e.deleteShader(s),e.deleteShader(i),!e.getProgramParameter(n,e.LINK_STATUS)){const r=e.getProgramInfoLog(n)??"?";throw e.deleteProgram(n),new Error(`link: ${r}`)}return{p:n,uScale:e.getUniformLocation(n,"uScale"),locs:new Map}}u(t,e){let s=t.locs.get(e);return s===void 0&&t.locs.set(e,s=this.gl.getUniformLocation(t.p,e)),s}use(t){this.cur!==t&&(this.cur=t,this.gl.useProgram(t.p),this.calls.useProgram++)}bindTex(t,e=this.unit<0?0:this.unit){const s=this.gl;this.onUnit[e]!==t&&(this.unit!==e&&(s.activeTexture(s.TEXTURE0+e),this.calls.activeTexture++,this.unit=e),s.bindTexture(s.TEXTURE_2D,t),this.calls.bindTexture++,this.onUnit[e]=t)}deleteTex(t){this.gl.deleteTexture(t);for(let e=0;e<this.onUnit.length;e++)this.onUnit[e]===t&&(this.onUnit[e]=null)}bindFb(t){if(t)for(let s=0;s<this.onUnit.length;s++)this.onUnit[s]===t.gl&&this.bindTex(null,s);const e=t?t.fb:null;this.fbNow!==e&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,e),this.calls.bindFramebuffer++,this.fbNow=e)}slotOf(t){this.batch.full&&this.flush();let e=this.batch.slot(t);return e<0&&(this.flush(),e=this.batch.slot(t)),e}quad(t,e,s,i,n,r,a,h){U[0]=i,U[1]=n,U[2]=a,this.quadQ(t,e,s,r,h)}quadQ(t,e,s,i,n){const r=U[2];if(this.lost||r<=0)return;const a=this.q,h=U[0],l=U[1],o=s[4],f=s[5],u=s[0]*h,g=s[1]*h,p=s[2]*l,d=s[3]*l;a[0]=o,a[1]=f,a[2]=u+o,a[3]=g+f,a[4]=u+p+o,a[5]=g+d+f,a[6]=p+o,a[7]=d+f;const y=1/t.width,m=1/t.height;a[8]=e.x*y,a[9]=e.y*m,a[10]=(e.x+e.w)*y,a[11]=(e.y+e.h)*m,a[12]=It(i,r,n==="add"),this.put(t)}put(t){if(this.mute)return;const e=this.q;let s=!1;const i=Math.min(e[0],e[2],e[4],e[6]),n=Math.max(e[0],e[2],e[4],e[6]),r=Math.min(e[1],e[3],e[5],e[7]),a=Math.max(e[1],e[3],e[5],e[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;const l=this.scale,o=this.px0/l,f=this.py0/l,u=this.px1/l,g=this.py1/l;if(n<=o||i>=u||a<=f||r>=g)return;if(i<o||n>u||r<f||a>g){const p=e[0],d=e[1],y=e[2],m=e[5];if(d===e[3]&&y===e[4]&&m===e[7]&&e[6]===p){if(p!==y){const w=Math.min(Math.max(p,o),u),x=Math.min(Math.max(y,o),u),k=e[8],M=(e[10]-k)/(y-p);e[10]=k+(x-p)*M,e[8]=k+(w-p)*M,e[0]=e[6]=w,e[2]=e[4]=x}if(d!==m){const w=Math.min(Math.max(d,f),g),x=Math.min(Math.max(m,f),g),k=e[9],M=(e[11]-k)/(m-d);e[11]=k+(x-d)*M,e[9]=k+(w-d)*M,e[1]=e[3]=w,e[5]=e[7]=x}}else s=!0}}const h=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(s?(!this.bScis||!h)&&(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&&h)&&(this.flush(),this.bScis=!1),this.real){const l=this.gq;l[0]=i,l[1]=r,l[2]=n,l[3]=a,this.growQ()}this.batch.pushQ(e,this.slotOf(t))}ellipse(t,e,s,i,n,r,a){if(this.lost||a<=0||s<=0||i<=0)return;const h=vs[Ei(Math.max(s,i)*2*this.scale,br)],l=h.w/2/h.r,o=s*l,f=i*l,u=Math.cos(n),g=Math.sin(n),p=u*o,d=g*o,y=-g*f,m=u*f,w=1/st,x=this.q;x[0]=t-p-y,x[1]=e-d-m,x[2]=t+p-y,x[3]=e+d-m,x[4]=t+p+y,x[5]=e+d+m,x[6]=t-p+y,x[7]=e-d+m,x[8]=h.x*w,x[9]=h.y*w,x[10]=(h.x+h.w)*w,x[11]=(h.y+h.h)*w,x[12]=It(r,a),this.put(this.kit)}polygon(t,e,s,i){if(this.lost||i<=0||e<3)return;this.tris.length<e*3&&(this.tris=new Int32Array(Math.max(e*3,this.tris.length*2)));const n=this.tris,r=vr(t,e,n),a=It(s,i),h=(Mt.x+Mt.w/2)/st,l=(Mt.y+Mt.h/2)/st;for(let o=0;o<r;o+=3){const f=n[o]*2,u=n[o+1]*2,g=n[o+2]*2,p=this.q;p[0]=t[f],p[1]=t[f+1],p[2]=t[u],p[3]=t[u+1],p[4]=p[6]=t[g],p[5]=p[7]=t[g+1],p[8]=p[10]=h,p[9]=p[11]=l,p[12]=a,this.put(this.kit)}}stroke(t,e,s,i,n,r){if(this.lost||n<=0||s<=0||e<1)return;const a=ws[Ei(s*this.scale,Mr)],h=s/2*(a.h/2/a.r);this.sPacked=It(i,n),this.sColor=i,this.sAlpha=n,this.sU=(a.x+a.w/2)/st,this.sV0=a.y/st,this.sV1=(a.y+a.h)/st,this.sHw=s/2,xr(t,e,h,r,this.strokeSeg,this.strokeDisc)}target(t,e,s,i){const n=this.gl,r=n.createTexture();this.bindTex(r),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,e,0,n.RGBA,n.UNSIGNED_BYTE,null);const a=i?n.LINEAR:n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),this.bindTex(null);const h=n.createFramebuffer();n.bindFramebuffer(n.FRAMEBUFFER,h),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,r,0);const l=n.checkFramebufferStatus(n.FRAMEBUFFER)===n.FRAMEBUFFER_COMPLETE;if(this.fbNow=h,this.bindFb(this.parent()),!l)return this.deleteTex(r),n.deleteFramebuffer(h),null;const o={tex:{id:os(),width:t,height:e,source:this.canvas},gl:r,fb:h,w:t,h:e,f:s};return this.layerTex.set(o.tex,r),o}drop(t){this.batch.has(t.tex)&&this.flush(),this.deleteTex(t.gl),this.gl.deleteFramebuffer(t.fb),this.layerTex.delete(t.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(t){const e=this.canvas.width,s=this.canvas.height;let i=this.layers[t]??null;return i&&(i.w!==e||i.h!==s)&&(this.drop(i),i=this.layers[t]=null),i??(this.layers[t]=this.target(e,s,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();const t=this.layerAt(this.real);if(!t)return!1;const e=this.gl;return this.bindFb(t),e.disable(e.SCISSOR_TEST),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!lt.gl?null:this.fxr??(this.fxr=lt.gl(this))}composite(t,e,s,i){if(i&&this.filters()?.chain(t,s,i))return;const n=this.gl;e&&n.blendFunc(n.ZERO,n.SRC_ALPHA),this.final(this.main,t,1,s),e&&(this.flush(),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA))}final(t,e,s,i){const n=this.gl,r=this.canvas.width,a=this.canvas.height,h=this.scale;(t!==this.main||!this.mapped)&&(this.bindFb(this.parent()),n.viewport(0,0,r,a),this.use(t),n.uniform2f(t.uScale,2*h/r,-2*h/a),this.mapped=t===this.main);const l=this.rx0/h,o=this.ry0/h,f=this.rx1/h,u=this.ry1/h,g=1/(s*e.width),p=1/(s*e.height),d=this.q;d[0]=d[6]=l,d[1]=d[3]=o,d[2]=d[4]=f,d[5]=d[7]=u,d[8]=this.rx0*g,d[9]=1-this.ry0*p,d[10]=this.rx1*g,d[11]=1-this.ry1*p,d[12]=It(16777215,i),this.put(e),t!==this.main&&this.flush()}remap(){const t=this.gl;this.bindFb(this.parent()),t.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),t.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(t){const e=this.gl,s=t.words;if(this.kind==="webgl2")return e.bufferSubData(e.ARRAY_BUFFER,0,t.f32,0,s);let i=this.views.get(s);i||(this.views.size>=256&&this.views.clear(),this.views.set(s,i=t.f32.subarray(0,s))),e.bufferSubData(e.ARRAY_BUFFER,0,i)}flush(){const t=this.batch;if(!t.quads||this.lost)return t.reset();const e=this.gl;this.bScis?(e.enable(e.SCISSOR_TEST),e.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):e.disable(e.SCISSOR_TEST),this.upload2(t);for(let s=0;s<t.bound;s++){const i=t.textures[s];this.bindTex(this.textures.get(i)??this.layerTex.get(i)??null,s)}this.inst?this.inst.draw(6,t.quads):e.drawElements(e.TRIANGLES,t.quads*6,e.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=t.quads,t.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){const t=this.gl;lt.live===this&&(lt.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(const e of this.textures.values())e&&t.deleteTexture(e);for(const e of this.layers)e&&(t.deleteTexture(e.gl),t.deleteFramebuffer(e.fb));this.fxr?.destroy(),this.fxr=null,t.deleteBuffer(this.dynamic),t.deleteBuffer(this.index),this.staticBuf&&t.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),t.deleteProgram(this.main.p),t.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function Ri(t,e,s){const i=t.createShader(e);if(t.shaderSource(i,s),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS)){const n=t.getShaderInfoLog(i)??"?";throw t.deleteShader(i),new Error(n)}return i}function Fi(t="auto"){switch(t){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function bs(t,e={}){let s=t;for(const i of Fi(e.renderer)){const n=i==="canvas2d"?ps(s):Cr(s,i==="webgl2"?2:1,e);if(n)return n;s=Ms(s)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function Ms(t){const e=t.cloneNode(!1);return t.parentNode?.replaceChild(e,t),e}function Nr(t=typeof location<"u"?location.search:""){const e=new URLSearchParams(t).get("renderer");return e==="canvas"?"canvas2d":e==="webgl2"||e==="webgl1"||e==="canvas2d"||e==="webgl"||e==="auto"?e:void 0}var As=class{constructor(t,e={}){c(this,"atlas",t),c(this,"tags",new Map),c(this,"count",0),c(this,"m",Lt()),c(this,"measure",null),c(this,"height"),c(this,"font"),this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(const t of this.tags.values())for(const e of t.values())for(const s of e.values())this.atlas.release(s);this.tags.clear(),this.count=0}get(t,e,s){let i=this.tags.get(t);i||this.tags.set(t,i=new Map);let n=i.get(e);n||i.set(e,n=new Map);const r=n.get(s);return r&&this.atlas.valid(r)?r:this.bake(t,e,s)}bake(t,e,s){const i=this.height,n=`700 ${Math.round(i*.65)}px ${this.font}`,r=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));r.font=n;const a=Math.round(i*.4),h=Math.ceil(r.measureText(t).width)+a*2,l=this.atlas.bake((h+2)*s,(i+2)*s,u=>{u.scale(s,s),u.translate(1,1);const g=i/2;u.beginPath(),u.moveTo(g,0),u.lineTo(h-g,0),u.arc(h-g,g,g,-Math.PI/2,Math.PI/2),u.lineTo(g,i),u.arc(g,g,g,Math.PI/2,Math.PI*3/2),u.closePath(),u.fillStyle=e,u.fill(),u.fillStyle="#fff",u.font=n,u.textAlign="center",u.textBaseline="middle",u.fillText(t,h/2,i/2+1)},s,1,1,1);++this.count>64&&(this.drop(),this.count=1);let o=this.tags.get(t);o||this.tags.set(t,o=new Map);let f=o.get(e);return f||o.set(e,f=new Map),f.set(s,l),l}draw(t,e,s,i,n,r,a,h,l,o,f){const u=qn(s,n,{band:Lr(i)});if(!u)return;const g=this.height,p=this.get(r,a,l),d=p.w/p.scale-2,y=Math.min(Math.max(u.head.x-d/2,4),o-d-4),m=Math.min(Math.max(u.head.y-u.headR*2.2-g,4),f-g-4);ft(this.m,null,y-1,m-1,0,1,1),t.quad(e(p.surface),p,this.m,p.w/p.scale,p.h/p.scale,16777215,h,"normal")}},Lr=t=>t.band==="3-5"||t.band==="9-12"?t.band:"6-8",Ir=(t,e=!1)=>e?Math.min(2**Math.round(Math.log2(Math.max(t,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(t,8))*2)/2),512);function ks(t,e=null){const s={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},i=(n,r,a)=>{const h=e?e[0]*n+e[2]*r+e[4]:n,l=e?e[1]*n+e[3]*r+e[5]:r,o=e?Math.hypot(e[0],e[1]):1;s.minX=Math.min(s.minX,h-a*o),s.minY=Math.min(s.minY,l-a*o),s.maxX=Math.max(s.maxX,h+a*o),s.maxY=Math.max(s.maxY,l+a*o)};for(const n of t){const r="lw"in n&&n.stroke?(n.lw??1)/2:0;switch(n.k){case"circle":i(n.x-n.r,n.y-n.r,r),i(n.x+n.r,n.y+n.r,r),i(n.x-n.r,n.y+n.r,r),i(n.x+n.r,n.y-n.r,r);break;case"ellipse":case"rect":{const a=n.k==="ellipse"?Math.max(n.rx,n.ry):Math.hypot(n.w,n.h)/2;i(n.x-a,n.y-a,r),i(n.x+a,n.y+a,r),i(n.x-a,n.y+a,r),i(n.x+a,n.y-a,r);break}case"path":{const a=ys(n.d);for(let h=0;h<a.count;h++){const l=a.subs[h];for(let o=0;o<l.n;o++)i(l.pts[o*2],l.pts[o*2+1],r)}break}case"line":for(let a=0;a+1<n.pts.length;a+=2)i(n.pts[a],n.pts[a+1],r);break;case"group":{const a=ft(Lt(),e,n.x,n.y,n.rot??0,n.s??1,n.s??1),h=ks(n.items,a);Number.isFinite(h.minX)&&(s.minX=Math.min(s.minX,h.minX),s.minY=Math.min(s.minY,h.minY),s.maxX=Math.max(s.maxX,h.maxX),s.maxY=Math.max(s.maxY,h.maxY));break}}}return s}var _s=class{constructor(t){c(this,"atlas",t),c(this,"seen",new WeakSet),c(this,"baked",new WeakMap),c(this,"m",Lt()),c(this,"stack",[]),c(this,"local",Lt()),c(this,"pts",new Float64Array(128)),c(this,"stats",{baked:0,vector:0}),c(this,"bakeGroups",!0),c(this,"coarse",!1),c(this,"gen",0),c(this,"live",new Set)}setTier(t){const e=t==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(const s of this.live)this.atlas.release(s.frame);this.live.clear()}}draw(t,e,s,i,n,r,a){const h=typeof i=="string"?me(i)??ye:i,l=Hn(s,h,n);return l.length?(r<=0||(r<1?(this.paint(t,e,l,null,t.beginLayer()?1:r,a),t.endLayer(r)):this.paint(t,e,l,null,r,a)),!0):!1}paint(t,e,s,i,n,r,a=0){var h;for(let l=0;l<s.length;l++){const o=s[l];if(o.k==="group"){const w=ft((h=this.stack)[a]??(h[a]=Lt()),i,o.x,o.y,o.rot??0,o.s??1,o.s??1),x=n*(o.alpha??1);if(this.bakeGroups&&this.seen.has(o.items)){const k=ut(w[0],w[1])*r,M=this.bake(o.items,k);if(M){const T=M.frame,E=this.m;E.set(w),E[4]=w[0]*-M.ox+w[2]*-M.oy+w[4],E[5]=w[1]*-M.ox+w[3]*-M.oy+w[5],t.quad(e(T.surface),T,E,T.w/M.k,T.h/M.k,16777215,x,"normal"),this.stats.baked++;continue}}this.seen.add(o.items),this.stats.vector++,this.paint(t,e,o.items,w,x,r,a+1);continue}const f=n*(o.alpha??1),u=i?ut(i[0],i[1]):1,g=i?Math.atan2(i[1],i[0]):0,p=(o.lw??1)*u,d=o.stroke&&(o.lw??1)>0?ht(o.stroke):null,y=o.fill&&o.k!=="line"?ht(o.fill):null;if(o.k==="circle"||o.k==="ellipse"){const w=i?i[0]*o.x+i[2]*o.y+i[4]:o.x,x=i?i[1]*o.x+i[3]*o.y+i[5]:o.y,k=(o.k==="circle"?o.r:o.rx)*u,M=(o.k==="circle"?o.r:o.ry)*u,T=(o.k==="ellipse"?o.rot??0:0)+g;if(y&&d)t.ellipse(w,x,k+p/2,M+p/2,T,d[0],f*d[1]),t.ellipse(w,x,Math.max(k-p/2,0),Math.max(M-p/2,0),T,y[0],f*y[1]);else if(y)t.ellipse(w,x,k,M,T,y[0],f*y[1]);else if(d){const E=Math.min(Math.max(Math.ceil(Math.max(k,M)*r*.6),12),64),F=this.pts=gs(this.pts,E*2),L=Math.cos(T),N=Math.sin(T);for(let B=0;B<E;B++){const W=B/E*Math.PI*2,X=Math.cos(W)*k,D=Math.sin(W)*M;F[B*2]=w+X*L-D*N,F[B*2+1]=x+X*N+D*L}t.stroke(F,E,p,d[0],f*d[1],!0)}continue}if(o.k==="line"){if(!d)continue;const w=o.pts.length>>1,x=this.pts=gs(this.pts,w*2);for(let k=0;k<w;k++){const M=o.pts[k*2],T=o.pts[k*2+1];x[k*2]=i?i[0]*M+i[2]*T+i[4]:M,x[k*2+1]=i?i[1]*M+i[3]*T+i[5]:T}t.stroke(x,w,p,d[0],f*d[1],!1);continue}const m=o.k==="path"?ys(o.d,i,u*r):Or(o,ft(this.local,i,o.x,o.y,o.rot??0,1,1),r*u);for(let w=0;w<m.count;w++){const x=m.subs[w],k=x.n,M=o.k==="rect"||x.closed;y&&k>=3&&(t.polygon(x.pts,k,y[0],f*y[1]),d||t.stroke(x.pts,k,1/r,y[0],f*y[1],!0)),d&&t.stroke(x.pts,k,p,d[0],f*d[1],M)}}}bake(t,e){const s=Ir(e,this.coarse);let i=this.baked.get(t);const n=i?.get(s);if(n&&n.gen===this.gen&&this.atlas.valid(n.frame))return n;n&&this.live.delete(n);const r=ks(t);if(!Number.isFinite(r.minX))return null;const a=2/s,h=(r.maxX-r.minX+a*2)*s,l=(r.maxY-r.minY+a*2)*s;if(h>1024||l>1024)return null;const o=-r.minX+a,f=-r.minY+a,g={frame:this.atlas.bake(h,l,p=>{p.scale(s,s),p.translate(o,f),js(p,t)}),k:s,ox:o,oy:f,gen:this.gen};return i||this.baked.set(t,i=new Map),i.set(s,g),this.live.add(g),g}},Xt=new Array(36).fill(0),$t=0,ct=(t,e=NaN,s=NaN,i=NaN,n=NaN)=>{Xt[$t++]=t,t!==J.Z&&(Xt[$t++]=e,Xt[$t++]=s,t===J.Q&&(Xt[$t++]=i,Xt[$t++]=n))};function Or(t,e,s){const i=Math.max(0,Math.min(t.r,t.w/2,t.h/2)),n=-t.w/2,r=-t.h/2,{M:a,L:h,Q:l,Z:o}=J;return $t=0,ct(a,n+i,r),ct(h,n+t.w-i,r),ct(l,n+t.w,r,n+t.w,r+i),ct(h,n+t.w,r+t.h-i),ct(l,n+t.w,r+t.h,n+t.w-i,r+t.h),ct(h,n+i,r+t.h),ct(l,n,r+t.h,n,r+t.h-i),ct(h,n,r+i),ct(l,n,r,n+i,r),ct(o),ys(Xt,e,s)}function Ur(t,e={}){let s=bs(t,e);const i=new fs(Math.min(1024,s.maxTextureSize),2);i.onDrop=E=>{E.texture&&s.destroyTexture(E.texture),E.texture=null};const n=new _s(i),r=()=>{const E=new lr;return e.local&&E.setLocal(!0),E};let a=r();const h=new Map;let l=1e6;const o=e.smooth===!1?1:typeof e.smooth=="number"?Math.min(Math.max(e.smooth,.05),1):a.defaultAmount;let f=Fe(s);const u=new As(i,e),g={w:1,h:1};let p=1,d=0,y=!1;const m=()=>u.drop(),w=typeof document<"u"?document.fonts:void 0;w?.ready?.then(()=>{y||m()}),w?.addEventListener?.("loadingdone",m);const x=()=>{const E=Ms(s.canvas),F=ps(E);if(F){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),s.destroy(),s=F;for(const L of i.pages)L.surface.texture=null;f=Fe(s),d=0}},k=()=>{if(!s.lost)return d=0,!0;const E=performance.now();return d||(d=E),E-d>3e3&&x(),!s.lost},M=()=>{const E=s.canvas;e.units?(p=e.pixelRatio??1,g.w=e.units.width,g.h=e.units.height):(p=e.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),g.w=E.clientWidth||E.width/p,g.h=E.clientHeight||E.height/p),s.resize(Math.max(1,Math.round(g.w*p)),Math.max(1,Math.round(g.h*p))),s.begin(0,0,p)},T=(E,F)=>{if(E.key===void 0)return E.id??F+1;let L=h.get(E.key);return L===void 0&&(h.size>256&&h.clear(),h.set(E.key,L=l++)),L};return{get renderer(){return s},get kind(){return s.kind},get lost(){return s.lost},get canvas(){return s.canvas},draw(E,F){if(k()){M();for(let L=0;L<E.length;L++){const N=E[L];if(!Array.isArray(N.body))continue;const B=T(N,L),W=o<1||e.interpolate!==!1?a.posed(B,N.body,o,e.interpolate!==!1):N.body,X=me(N.avatar??"")??ye,D=N.alpha??1;!n.draw(s,f,W,X,F,D,p)||!N.name||u.draw(s,f,W,X,F,N.name,N.color??"#6FA0E0",D,p,g.w,g.h)}s.end()}},clear(){k()&&(M(),s.end())},reset(){a=r(),h.clear()},destroy(){y=!0,w?.removeEventListener?.("loadingdone",m),s.destroy()}}}var Re=new Map;function Dr(t,e,s=Math.min(globalThis.devicePixelRatio||1,2)){const i=`${t}|${e}|${s}`;let n=Re.get(i);if(n)return n;n=document.createElement("canvas"),n.width=n.height=Math.round(e*s);const r=n.getContext("2d");return r.scale(s,s),r.beginPath(),r.rect(0,0,e,e),r.clip(),js(r,Wn(me(t)??ye,e)),Re.size>64&&Re.clear(),Re.set(i,n),n}function Fe(t){return e=>{if(e.texture||(e.texture=t.createTexture(e.source),e.pending.length=0),e.pending.length){for(const[s,i,n]of e.pending)t.updateTexture(e.texture,s,i,n);e.pending.length=0}return e.texture}}var Ci='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',ie="rgba(10,16,30,0.75)";function Pi(t,e){const s=t.size??40,i=t.outline?t.outline===!0?ie:t.outline:null,n=i?t.outlineWidth??Math.max(s*.12,3):0,r=t.shadow&&e?t.shadow===!0?ie:t.shadow:null,a=r?t.shadowBlur??s*.25:0;return{size:s,font:t.font??Ci,weight:t.weight??700,color:t.color??"#FBEFE3",outline:i,ow:n,shadow:r,blur:a,pad:n/2+a*1.2+2,th:s*1.25}}var Ni=(t,e)=>`${t.weight} ${t.size*e}px ${t.font}`;function Li(t,e,s,i,n,r){t.scale(i,i),t.font=Ni(s,1),t.textBaseline="middle",t.textAlign="left",t.lineJoin="round",s.shadow&&(t.shadowColor=s.shadow,t.shadowBlur=s.blur*i),s.outline&&(t.strokeStyle=s.outline,t.lineWidth=s.ow,t.strokeText(e,n,r),t.shadowColor="transparent"),t.fillStyle=s.color,t.fillText(e,n,r)}var Ce=null;function Ii(t,e,s){return Ce??(Ce=document.createElement("canvas").getContext("2d")),Ce.font=Ni(e,s),Ce.measureText(t).width/s}var ne=class extends Ot{constructor(t,e,s={}){super(t,null),c(this,"_text"),c(this,"_style"),c(this,"dirty",!0),c(this,"bakedScale",0),c(this,"bakedFontGen",-1),c(this,"bakedEffects",!0),c(this,"capW",0),c(this,"capH",0),this._text=e;const{x:i,y:n,rotation:r,scale:a,scaleX:h,scaleY:l,alpha:o,visible:f,tint:u,blend:g,z:p,anchor:d,hitRadius:y,clip:m,mask:w,filters:x,...k}=s;this._style=k,this.bake(),this.set({x:i,y:n,rotation:r,scale:a,scaleX:h,scaleY:l,alpha:o,visible:f,tint:u,blend:g,z:p,hitRadius:y,clip:m,mask:w,filters:x}),d!==void 0&&(this.anchor=d)}get text(){return this._text}set text(t){const e=String(t);e!==this._text&&(this._text=e,this.dirty=!0)}get style(){return this._style}set style(t){this._style={...this._style,...t},this.dirty=!0}bitmap(){const t=this._style.bitmapFont;if(!t)return null;const e=typeof t=="string"?this.kernel.bitmapFont(t):t;if(this.autoAnchor){const s=this._style.align;this.anchorX=s==="left"?0:s==="right"?1:.5,this.anchorY=.5}return e}get naturalWidth(){const t=this.bitmap();return t?t.measure(this._text)*((this._style.size??t.size)/t.size):super.naturalWidth}get naturalHeight(){const t=this.bitmap();return t?t.lineHeight*((this._style.size??t.size)/t.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(t,e,s){const i=this.bitmap();if(!i)return super.draw(t,e,s);const n=(this._style.size??i.size)/i.size,r=i.measure(this._text)*n,a=i.lineHeight*n,h=this.width,l=this.height,o=r>0?h/r:1,f=a>0?l/a:1;i.run(this._text,t,this.world,-this.anchorX*h,-this.anchorY*l,n*o,n*f,s,e,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){const t=this.kernel;if(this._style.bitmapFont)return null;const e=t.pixelScale,s=t.effects;return!this.dirty&&e===this.bakedScale&&t.fontGen===this.bakedFontGen&&s===this.bakedEffects&&t.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){const t=this.kernel,e=t.pixelScale,s=t.effects;this.dirty=!1,this.bakedScale=e,this.bakedFontGen=t.fontGen,this.bakedEffects=s;const i=Pi(this._style,s),{pad:n,th:r}=i,a=Ii(this._text,i,e),h=(a+n*2)*e,l=(r+n*2)*e,o=this._style.align??"center",f=o==="left"?n:o==="right"?n+a:n+a/2,u=d=>Li(d,this._text,i,e,n,n+r/2),g=this._frame;let p=null;return g&&t.atlas.valid(g)&&g.scale===e&&(p=t.atlas.rebake(g,h,l,u,this.capW,this.capH),p?Object.assign(p,{ox:f,oy:n+r/2,margin:n}):t.atlas.release(g)),p||(this.capW=Math.ceil(h*1.25+16),this.capH=Math.ceil(l),p=t.atlas.bake(this.capW,this.capH,u,e,f,n+r/2,n),p.w=Math.ceil(h),p.h=Math.ceil(l)),this._frame=p,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,p}},q=(t,e=0)=>{const s=Number(t);return Number.isFinite(s)?s:e};function Pe(t){typeof t=="string"&&/^\s*[{[]/.test(t)&&(t=JSON.parse(t));const e={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},s=(i,n)=>{i==="info"?e.size=Math.abs(q(n.size)):i==="common"?(e.lineHeight=q(n.lineHeight),e.base=q(n.base)):i==="page"?e.pages[q(n.id)]=String(n.file??""):i==="char"?e.chars.push({id:q(n.id),x:q(n.x),y:q(n.y),width:q(n.width),height:q(n.height),xoffset:q(n.xoffset),yoffset:q(n.yoffset),xadvance:q(n.xadvance),page:q(n.page)}):e.kernings.push({first:q(n.first),second:q(n.second),amount:q(n.amount)})};if(typeof t=="object"){const i=t;s("info",i.info??{}),s("common",i.common??{});for(const[n,r]of(i.pages??[]).entries())s("page",{id:n,file:r});for(const n of i.chars??[])s("char",n);for(const n of i.kernings??[])s("kerning",n)}else{const i=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,n=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let r=i.exec(t);r;r=i.exec(t)){const a={};for(let h=n.exec(r[2]);h;h=n.exec(r[2]))a[h[1]]=h[2]??h[3];s(r[1],a)}}return e.size||(e.size=e.lineHeight),e}var Es=class{constructor(t,e,s,i=null,n=null){c(this,"baker",i),c(this,"host",n),c(this,"size"),c(this,"lineHeight"),c(this,"base"),c(this,"ascii",new Array(128)),c(this,"more",new Map),c(this,"kern",new Map),c(this,"bScale",0),c(this,"bFontGen",-1),c(this,"bEffects",!1),c(this,"bGen",-1),this.size=t,this.lineHeight=e,this.base=s}set(t,e){t<128?this.ascii[t]=e:this.more.set(t,e)}setKerning(t,e,s){this.kern.set(t*1114112+e,s)}prepare(){const 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(const e of this.ascii)e&&t.atlas.release(e.frame);for(const 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){return this.kern.size?this.kern.get(t*1114112+e)??0:0}measure(t){return this.run(t)}run(t,e,s,i=0,n=0,r=1,a=1,h=0,l=1,o="normal"){this.prepare();let f=0,u=-1;for(let g=0;g<t.length;g++){let p=t.charCodeAt(g);p>=55296&&p<56320&&g+1<t.length&&(p=t.codePointAt(g),g++),u>=0&&(f+=this.kerning(u,p)),u=p;const d=this.glyph(p);d&&(e&&d.w>0&&d.h>0&&(we(s,i+(f+d.x)*r,n+d.y*a),e.r.quad(e.tex(d.frame.surface),d.frame,H,d.w*r,d.h*a,h,l,o)),f+=d.advance)}return f}};function Br(t,e){const s=new Es(t.size,t.lineHeight,t.base);for(const i of t.chars){const n=e[i.page];if(!n)continue;const r={surface:n,x:i.x,y:i.y,w:i.width,h:i.height,scale:1,gen:0,ox:0,oy:0,margin:0};s.set(i.id,{frame:r,x:i.xoffset,y:i.yoffset,w:i.width,h:i.height,advance:i.xadvance})}for(const i of t.kernings)s.setKerning(i.first,i.second,i.amount);return s}function zr(t,e){const s={...e},i=e.size??40,n=a=>{const h=String.fromCodePoint(a),l=t.pixelScale,o=Pi(s,t.effects),f=Ii(h,o,l),u=t.atlas.bake((f+o.pad*2)*l,(o.th+o.pad*2)*l,g=>Li(g,h,o,l,o.pad,o.pad+o.th/2),l);return{frame:u,x:-o.pad,y:-o.pad,w:u.w/l,h:u.h/l,advance:f}},r=new Es(i,i*1.25,i,n,t);r.prepare();for(const a of e.chars??"0123456789")r.glyph(a.codePointAt(0));return r}var Gr=.5;function Oi(t){const e=[];for(const[s,i]of[["left",et.leftWrist],["right",et.rightWrist]]){const n=t[i*3],r=t[i*3+1],a=t[i*3+2];n!==void 0&&r!==void 0&&Number.isFinite(n)&&Number.isFinite(r)&&(a??0)>=Gr&&e.push({side:s,x:n,y:r})}return e}var Ne=t=>pe[((t-1)%pe.length+pe.length)%pe.length],Xr=["left","right"];function Ui(t,e,s,i,n=()=>null,r={}){const a=[];for(const h of t){const l=n(h)??h.body;if(Array.isArray(l)){if(r.orientation==="portrait"){for(const o of Xr){let f=Nn(l,o,{orientation:"portrait"});r.hold&&(f=r.hold.at(qs.key(h.id,o),f,r.t??0)),f&&a.push({player:h.id,side:o,x:f.x*s,y:f.y*i,color:Ne(h.id)})}continue}for(const o of Oi(l)){const f=e(o);a.push({player:h.id,side:o.side,x:f.x*s,y:f.y*i,color:Ne(h.id)})}}}return a}function Ss(t,e,s,i=0){const n=t.world,r=Yn(n,e,s);if(!r)return!1;const a=Math.hypot(n[0],n[1])||1,h=Math.hypot(n[2],n[3])||1,[l,o]=r;if(t.hitRadius!=null){const d=t.hitRadius+i/((a+h)/2);return l*l+o*o<=d*d}const f=-t.anchorX*t.width-i/a,u=-t.anchorY*t.height-i/h,g=(1-t.anchorX)*t.width+i/a,p=(1-t.anchorY)*t.height+i/h;return l>=f&&l<=g&&o>=u&&o<=p}function Di(t,e,s,i=0){for(const n of e)if((s===void 0||n.player===s)&&Ss(t,n.x,n.y,i))return n;return null}function $r(t){switch(t.type){case"circle":case"ring":case"star":return[t.r*2,t.r*2];case"ellipse":return[t.rx*2,t.ry*2];case"roundRect":return[t.w,t.h];case"line":return[t.length,t.lw??4];case"path":return t.r?[t.r*2,t.r*2]:[t.size,t.size]}}function Hr(t){const e=t.type==="line"?0:t.stroke?(t.lw??2)/2:0,s=t.shadow?t.shadow.blur*1.5+Math.max(Math.abs(t.shadow.x??0),Math.abs(t.shadow.y??0)):0;return Math.ceil(e+s+1)}var qr=(t,e)=>e||!t.shadow?t:{...t,shadow:void 0};function Bi(t,e,s){const i=Hr(e),n=e.type==="roundRect",[r,a]=n?[Math.min(e.w,e.r*2+4/s),Math.min(e.h,e.r*2+4/s)]:$r(e),h=(r+i*2)*s,l=(a+i*2)*s;return{frame:t.bake(h,l,f=>{f.scale(s,s),f.translate(i+r/2,i+a/2),Wr(f,e,r,a)},s,i+r/2,i+a/2,i),slice:n?Math.ceil((e.r+i)*s):0,w:n?e.w:r,h:n?e.h:a}}function Wr(t,e,s,i){t.lineJoin="round",t.lineCap="round";const n=new Path2D;switch(e.type){case"circle":case"ring":n.arc(0,0,e.r,0,Math.PI*2);break;case"ellipse":n.ellipse(0,0,e.rx,e.ry,0,0,Math.PI*2);break;case"roundRect":n.roundRect(-s/2,-i/2,s,i,Math.min(e.r,s/2,i/2));break;case"star":{const o=e.points??5,f=e.r*(e.inner??.5);for(let u=0;u<o*2;u++){const g=u%2?f:e.r,p=-Math.PI/2+u*Math.PI/o;u?n.lineTo(Math.cos(p)*g,Math.sin(p)*g):n.moveTo(Math.cos(p)*g,Math.sin(p)*g)}n.closePath();break}case"line":n.moveTo(-s/2+i/2,0),n.lineTo(s/2-i/2,0);break;case"path":{const o=e.r?e.r*2/e.size:1,f=new DOMMatrix([o,0,0,o,-e.size/2*o,-e.size/2*o]);n.addPath(new Path2D(e.d),f);break}}const r=e.shadow,a=()=>{if(!r)return;const o=t.getTransform();t.shadowColor=r.color,t.shadowBlur=r.blur*o.a,t.shadowOffsetX=(r.x??0)*o.a,t.shadowOffsetY=(r.y??0)*o.a},h=()=>{t.shadowColor="transparent",t.shadowBlur=0};if(e.type==="line"){a(),t.strokeStyle=e.stroke??e.fill??"#fff",t.lineWidth=i,t.stroke(n);return}const l=e.type==="ring";if(e.outlineBelow&&e.fill&&e.stroke&&!l){a(),t.strokeStyle=e.stroke,t.lineWidth=e.lw??2,t.stroke(n),h(),t.fillStyle=e.fill,t.fill(n);return}e.fill&&!l&&(a(),t.fillStyle=e.fill,t.fill(n),h()),(e.stroke||l)&&((!e.fill||l)&&a(),l&&e.fill&&(t.fillStyle=e.fill,t.fill(n)),t.strokeStyle=e.stroke??"#fff",t.lineWidth=e.lw??2,t.stroke(n),h())}var zi=class{constructor(){if(c(this,"ctx",null),c(this,"master",null),c(this,"buffers",new Map),c(this,"held",!1),c(this,"muted",!1),c(this,"volume",1),typeof addEventListener=="function"){const t=()=>{this.context()?.resume().catch(()=>{})};for(const e of["pointerdown","keydown","touchstart"])addEventListener(e,t,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;const t=globalThis.AudioContext??globalThis.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{return null}return this.ctx}async load(t,e){const s=this.context();if(!s)return;const i=await(await fetch(e)).arrayBuffer();this.buffers.set(t,await s.decodeAudioData(i))}has(t){return this.buffers.has(t)}play(t,e={}){const s=this.context(),i=this.buffers.get(t);if(!s||!i||!this.audible)return()=>{};const n=s.createBufferSource();n.buffer=i,n.loop=e.loop??!1,n.playbackRate.value=e.rate??1;const r=s.createGain();return r.gain.value=(e.volume??1)*this.volume,n.connect(r).connect(this.master),n.start(),()=>{try{n.stop()}catch{}}}tone(t,e=.25,s={}){const i=this.context();if(!(!i||!this.audible))try{const n=i.createOscillator(),r=i.createGain();n.type=s.type??"sine",n.frequency.setValueAtTime(t,i.currentTime),s.to&&n.frequency.exponentialRampToValueAtTime(s.to,i.currentTime+e),r.gain.setValueAtTime((s.volume??.12)*this.volume,i.currentTime),r.gain.exponentialRampToValueAtTime(.001,i.currentTime+e),n.connect(r).connect(this.master),n.start(),n.stop(i.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}},Yr={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}},dt=["high","medium","low"];function Ft(t){const e=Yr[t];return{name:t,...e,scale:s=>s<=0?0:Math.max(1,Math.round(s*e.particles))}}var jr=t=>dt[Math.min(dt.indexOf(t)+1,dt.length-1)],Le=(t,e)=>{if(!t.length)return NaN;const s=[...t].sort((i,n)=>i-n);return s[Math.min(s.length-1,Math.max(0,Math.floor(e*(s.length-1)+.5)))]},Vr=12,Qr=t=>Ie(t,.5);function Ie(t,e=.1){const s=Le(t,e);if(!Number.isFinite(s))return 1e3/60;const i=[144,120,90,75,60,50,30];let n=60;for(const r of i)Math.abs(1e3/r-s)<Math.abs(1e3/n-s)&&(n=r);return 1e3/n}function Gi(t,e){const s=e.refresh!==void 0&&Number.isFinite(e.refresh)&&e.refresh>0?e.refresh:Ie(e.intervals),i=Le(e.intervals,.5),n=Le(e.intervals,.9),r=Le(e.cpu,.5);if(!Number.isFinite(i))return t==="canvas2d"?"low":"medium";const a=l=>l<=s*1.25,h=l=>!Number.isFinite(r)||r<s*l;return t==="canvas2d"?a(n)&&h(.25)?"medium":"low":a(n)&&h(.5)?"high":a(i)?"medium":"low"}function Kr(t,e){return t.length<30?!1:t.filter(i=>i>e*1.5).length/t.length>.5}var Xi="0.1.1",Zr=720*3600*1e3,Jr=(t,e,s)=>`fabi-play.engine-tier:${Xi}:${t}:${e}:${s}`,ta=(t,e,s)=>`fablee-engine-tier:${Xi}:${t}:${e}:${s}`;function ea(t,e,s=Date.now()){try{const i=JSON.parse(t?.getItem(e)??"null");if(i&&dt.includes(i.tier)&&typeof i.at=="number"&&s-i.at<Zr)return typeof i.refresh=="number"&&i.refresh>0?{name:i.tier,refresh:i.refresh}:{name:i.tier}}catch{}return null}function $i(t,e,s,i,n=Date.now()){try{t?.setItem(e,JSON.stringify(i!==void 0&&Number.isFinite(i)?{tier:s,at:n,refresh:i}:{tier:s,at:n}))}catch{}}function sa(t=typeof location<"u"?location.search:""){const e=new URLSearchParams(t).get("tier");return dt.includes(e)?e:void 0}function Hi(t,e){const s=e?.tier;if(dt.includes(s))return t==="canvas2d"&&s==="high"?"medium":s}var qi=t=>typeof t?.hz=="number"&&t.hz>=20&&t.hz<=240?Ie([1e3/t.hz],.5):NaN,Wi=(t,e)=>dt.indexOf(t)>=dt.indexOf(e)?t:e;function ia(t,e,s){return t?{name:t,from:"forced"}:e?{name:s?Wi(e,s):e,from:"hint"}:s?{name:s,from:"cache"}:null}var na=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,Yi=class{constructor(t={}){c(this,"steps",[]),c(this,"labels",new Map),c(this,"end",0),c(this,"prevStart",0),c(this,"elapsed",0),c(this,"iter",0),c(this,"last",0),c(this,"delayLeft"),c(this,"_paused"),c(this,"done",!1),c(this,"rewinding",!1),c(this,"promise"),c(this,"resolve"),c(this,"repeat"),c(this,"yoyo"),c(this,"onComplete"),this.repeat=Math.floor(t.repeat??0),this.yoyo=!!t.yoyo,this.delayLeft=t.delay??0,this._paused=!!t.paused,this.onComplete=t.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(t){if(t===void 0)return this.end;if(typeof t=="number")return Math.max(t,0);const e=na.exec(t);if(!e)throw new Error(`[engine] timeline: bad position "${t}"`);const[,s,i,n]=e,r=n?(i==="-"?-1:1)*Number(n):0;let a=this.end;if(s==="<")a=this.prevStart;else if(s&&s!==">"){const h=this.labels.get(s.trim());h===void 0?this.labels.set(s.trim(),this.end):a=h}return Math.max(a+r,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,s,i="quadOut"){const n=typeof i=="object"?i:{ease:i},r=typeof n.ease=="function"?n.ease:Qt[n.ease??"quadOut"];return this.add({target:t,to:e,from:null,fn:null,start:this.at(n.at)+(n.delay??0),dur:Math.max(s,0),ease:r,onUpdate:n.onUpdate,p:-1})}set(t,e,s){return this.add({target:t,to:e,from:null,fn:null,start:this.at(s),dur:0,ease:Qt.linear,p:-1})}call(t,e){return this.add({target:null,to:null,from:null,fn:t,start:this.at(e),dur:0,ease:Qt.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){const e=Math.min(typeof t=="string"&&this.labels.has(t)?this.labels.get(t):this.at(t),this.end),s=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(s?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}const e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=t;const s=this.repeat<0?1/0:e*(this.repeat+1),i=Math.min(this.elapsed,s),n=i>=s?this.repeat:Math.floor(i/e);for(;this.iter<n;){const 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)}const r=i-n*e;this.render(this.yoyo&&n%2===1?e-r:r),i>=s&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(t){const e=this.steps;if(t>=this.last)for(let s=0;s<e.length;s++){const i=e[s];t>=i.start&&this.apply(i,t)}else for(let s=e.length-1;s>=0;s--){const i=e[s];i.p>=0&&this.apply(i,t)}this.last=t}apply(t,e){const s=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(s===t.p)return;if(t.p=s,t.fn){this.rewinding||t.fn();return}const i=t.target;if(i.destroyed||i._free)return;const n=t.to;if(!t.from){t.from={};for(const a in n)t.from[a]=Number(i[a]??0)}const r=t.ease(s);for(const a in n)i[a]=t.from[a]+(n[a]-t.from[a])*r;t.onUpdate?.(r)}},ji=class{constructor(){c(this,"list",[]),c(this,"timelines",[])}timeline(t){const e=new Yi(t);return this.timelines.push(e),e}tween(t,e,s,i="quadOut"){const n=typeof i=="object"?i:{ease:i},r=typeof n.ease=="function"?n.ease:Qt[n.ease??"quadOut"];let a;const h=new Promise(l=>{const o=Object.keys(e),f=new Float64Array(o.length);o.forEach((u,g)=>f[g]=Number(e[u])),a={target:t,keys:o,to:f,from:new Float64Array(o.length),started:!1,duration:Math.max(s,0),time:0,delay:n.delay??0,ease:r,onUpdate:n.onUpdate,done:l,dead:!1}});return this.list.push(a),Object.assign(h,{stop:()=>this.finish(a)})}stopAll(t){const e=this.list;for(let s=0;s<e.length;s++)e[s].target===t&&this.finish(e[s])}get size(){return this.list.length}update(t){if(this.timelines.length){let i=0;const n=this.timelines;for(let r=0;r<n.length;r++){const a=n[r];a.update(t),a.finished||(n[i++]=a)}n.length=i}const e=this.list;if(!e.length)return;let s=0;for(let i=0;i<e.length;i++){const n=e[i];n.dead||this.step(n,t),n.dead||(e[s++]=n)}s!==e.length&&(e.length=s)}step(t,e){if(t.target.destroyed)return this.finish(t);let s=e;if(t.delay>0){if(t.delay-=e,t.delay>0)return;s=-t.delay}const i=t.keys;if(!t.started){t.started=!0;for(let a=0;a<i.length;a++)t.from[a]=Number(t.target[i[a]]??0)}t.time+=s;const n=t.duration>0?Math.min(t.time/t.duration,1):1,r=t.ease(n);for(let a=0;a<i.length;a++)t.target[i[a]]=t.from[a]+(t.to[a]-t.from[a])*r;t.onUpdate?.(r),n>=1&&this.finish(t)}finish(t){t.dead||(t.dead=!0,t.done())}clear(){for(const t of this.list)this.finish(t);this.list.length=0;for(const t of this.timelines)t.stop();this.timelines=[]}},Y=720,Vi=class extends St{constructor(t,e){super(t),c(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},ra=class extends St{constructor(t,e){super(t),c(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},pt=()=>performance.now(),Qi=t=>{const e=Un(t);return e&&Object.freeze(e)};async function aa(t={}){const e=t.play??null;let s=t.canvas??null;s||(s=document.createElement("canvas"),s.style.cssText="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(s));let i=bs(s,{renderer:t.renderer??Nr(),failIfMajorPerformanceCaveat:t.failIfMajorPerformanceCaveat,instancing:t.instancing});s=i.canvas;const n=new Set,r=new fs(Math.min(2048,i.maxTextureSize),4);r.onPage=v=>n.add(v),r.onDrop=v=>{n.delete(v),v.texture&&i.destroyTexture(v.texture),v.texture=null};let a=Fe(i);const h=new ji,l=new zi,o=new _s(r),f=new Map,u=new Map,g=new Map,p=new Map,d=new Map,y=new Set;let m=0;const w=t.tier??sa(),x=String(i.info.renderer??""),k=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),M=typeof screen<"u"?`${screen.width}x${screen.height}`:"",T=Jr(i.kind,x,M);$n(k,T,ta(i.kind,x,M));const E=ea(k,T),F=ia(w,Hi(i.kind,e?.device),E?.name);let L=F?.name??"medium",N=Ft(L);o.setTier(L);let B=F?.from==="hint",W=E?.name,X=E?.refresh??qi(e?.device),D=1,Ht=1,ae=1;const Q={atlas:r,get pixelScale(){return D},get fontGen(){return m},get effects(){return N.effects},tweens:h,frame:v=>je.frame(v),shape:v=>{const b=N.effects,S=b?D:-D;let _=f.get(S);_||(f.size>=8&&f.clear(),f.set(S,_=new di(2e3)));const C=wt(v);let G=_.get(v,C);return(!G||!r.valid(G.frame))&&_.set(v,G=Bi(r,qr(v,b),D),C),G},bitmapFont:v=>je.bitmapFont(v)};let at=1280,kt=null;class Za extends ls{get width(){return at}set width(b){}get height(){return Y}set height(b){}get safe(){const b=Math.min(at,Y*16/9);return{x:(at-b)/2,y:0,w:b,h:Y}}}const ot=new Za(Q),_t=()=>{const v=i.canvas,b=v.getBoundingClientRect();Ht=Math.max(1,b.width||v.clientWidth||innerWidth),ae=Math.max(1,b.height||v.clientHeight||innerHeight),at=Y*Ht/ae;const S=Math.min(globalThis.devicePixelRatio||1,t.maxPixelRatio??2);if(ae*S/Y<=N.resolution){const C=Math.max(1,Math.round(ae*S));D=C/Y,i.resize(Math.max(1,Math.round(Ht*S)),C)}else D=N.resolution,i.resize(Math.round(at*D),Math.round(Y*D));kt&&kt.style.setProperty("--unit",`${ae/Y}px`)};addEventListener("resize",_t);const Cs=v=>{L=v,N=Ft(v),o.setTier(v),_t()},Be=typeof ResizeObserver<"u"?new ResizeObserver(_t):null;Be?.observe(s);let mt=e?.backdrop==="video"?"video":"none",$=e?.view??null,ze=e?.orientation==="portrait"?"portrait":"landscape",an=Qi(e?.safeArea)??On,on=[],hn=-1/0,Ge=!1,oe=!1;const Ps=new Set,ln=()=>{const v=mt==="video"?"transparent":"";document.documentElement.style.background=v,document.body.style.background=v},cn=(v,b)=>{const S=v==="video"?"video":"none",_=b??null;if(!(S===mt&&(_===$||_&&$&&_.x===$.x&&_.y===$.y&&_.w===$.w&&_.h===$.h))){mt=S,$=_,ln();for(const C of[...Ps])C(mt,$)}},fn=[];if(e){const v=_=>{Array.isArray(_)&&(on=_,hn=pt())},b=_=>{Ge=_,Xe()},S=_=>{if(w||B)return;Number.isFinite(X)||(X=qi(_));const C=Hi(i.kind,_);C&&(B=!0,Cs(W?Wi(C,W):C))};fn.push(e.on("start",_=>S(_?.device)),e.on("start",_=>{(_?.orientation==="portrait"||_?.orientation==="landscape")&&(ze=_.orientation);const C=Qi(_?.safeArea);C&&(an=C)}),e.on("start",_=>{typeof _?.muted=="boolean"&&(l.muted=_.muted)}),e.on("frame",_=>v(_?.players)),e.on("players",_=>v(_?.players)),e.on("backdrop",_=>cn(_?.backdrop,_?.view)),e.on("start",_=>cn(_?.backdrop,_?.view??e.view)),e.on("pause",()=>b(!0)),e.on("resume",()=>b(!1)),e.on("break-start",()=>b(!0)),e.on("break-done",()=>b(!1)),e.on("break-end",()=>b(!1))),l.muted=e.muted===!0}ln();const Xe=()=>Ge||oe||document.hidden?l.hold():l.release();let un=-1,Ns=[],Ls=0;const Is=()=>pt()-hn<1e3?on:[],Ja=v=>e?e.toScreen(v):Hs($,v),to=new qs,$e=()=>{if(un===Ls)return Ns;un=Ls;const v=ze==="portrait",b=mt==="video"&&!v||!e?.smoothedBody?()=>null:S=>e.smoothedBody(S);return Ns=Ui(Is(),Ja,at,Y,b,v?{orientation:ze,hold:to,t:pt()}:void 0),Ns},he={x:0,y:0,w:1,h:1},eo=()=>(he.x=$?$.x*at:0,he.y=$?$.y*Y:0,he.w=$?$.w*at:at,he.h=$?$.h*Y:Y,he),so=v=>{const b=v.alpha??1,S=v.tags?new As(r,v):null;S&&y.add(S);const _=typeof v.tags=="function"?v.tags:C=>String(C);return(C,G)=>{if(mt==="video")return;const I=eo();for(const O of Is()){const j=e?.smoothedBody?.(O)??O.body,z=me(e?.avatarOf?.(O)??O.avatar??"")??ye;if(!o.draw(C.r,C.tex,j,z,I,b*G,D)||!S)continue;const it=_(O.id);it&&S.draw(C.r,C.tex,j,z,I,it,Ne(O.id),b*G,D,at,Y)}}},Os=new Set,Us=new Set,le=new Set;let He=!1,Ds=0,qt=0,qe=0;const Ct={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0};let We=0,Bs=0,zs=pt();const ce=[];let Ye=0;const dn=()=>({r:i,kernel:Q,tex:a});let pn=dn();const io=()=>{if(i.lost)return;const[v,b]=mt==="video"||t.background===void 0?[0,0]:ht(t.background);i.time=qe,i.maxBlur=N.maxBlur,i.begin(v,b,D),ft(ot.world,null,ot.x,ot.y,ot.rotation,ot.scaleX,ot.scaleY),ii(pn,ot,ot.alpha,ot.tint);const S=i.end();Ct.drawCalls=S.drawCalls,Ct.quads=S.quads,Ct.filtersSkipped=S.filtersSkipped},gn=v=>{if(!He)return;Ds=requestAnimationFrame(gn);const b=Math.min(Math.max((v-qt)/1e3,0),.1);qt&&ce.push(v-qt),qt=v,Ls++;const S=pt(),_=Ge||oe;if(!_){qe+=b,h.update(b);for(const C of le)C.destroyed||C.update(b);for(const C of Os)C(b,qe)}for(const C of Us)C(b);ot.sweep();for(const C of le)C.destroyed&&le.delete(C);if(i.lost?(Ye||(Ye=v),v-Ye>3e3&&no()):(Ye=0,io()),We++,Bs+=pt()-S,S-zs>=1e3&&(Ct.fps=Math.round(We*1e3/(S-zs)),Ct.cpuMs=Math.round(Bs/Math.max(We,1)*100)/100,e?.reportStats?.({fps:Ct.fps,renderer:i.kind,tier:L}),We=0,Bs=0,zs=S),ce.length>=180){const C=Number.isFinite(X)?X:Ie(ce);!w&&!_&&Kr(ce,C)&&L!=="low"&&(Cs(jr(L)),W=L,$i(k,T,L,Number.isFinite(X)?X:void 0),console.info(`[engine] slow frames: tier ${L}`)),ce.length=0}},no=()=>{const v=Ms(i.canvas),b=ps(v);if(b){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),i.destroy(),i=b;for(const S of n)S.texture=null;for(const S of r.pages)n.add(S.surface);a=Fe(i),pn=dn(),Be?.disconnect(),Be?.observe(v),_t()}},mn=()=>{Xe(),document.hidden||(qt=0)};document.addEventListener("visibilitychange",mn);const yn=()=>{m++;for(const v of y)v.drop()};if(document.fonts?.addEventListener?.("loadingdone",yn),_t(),!F&&t.probe!==!1&&(Number.isFinite(X)||(X=Qr(await oa(Vr))),!B)){N=Ft("high"),_t();const v=await ha(i,r,()=>a,()=>D,at,()=>B);if(v.refresh=X,!B){const b=Gi(i.kind,v);$i(k,T,b,X),W=b,Cs(b)}}const je={stage:ot,get tier(){return N},get renderer(){return i},get canvas(){return i.canvas},get pixelScale(){return D},get backdrop(){return mt},get view(){return $},get orientation(){return ze},get safeArea(){return an},get paused(){return Ge||oe},sound:l,stats:Ct,get time(){return qe},get supports(){const v=i.support;return{filters:v.filters,blur:v.filters&&N.maxBlur>0,shaders:v.shaders,maxBlur:v.filters?N.maxBlur:0,tiers:{high:{maxBlur:Ft("high").maxBlur},medium:{maxBlur:Ft("medium").maxBlur},low:{maxBlur:Ft("low").maxBlur}}}},sprite:(v,b)=>new Ot(Q,v,b),shape:(v,b)=>new te(Q,v,b),text:(v,b)=>new ne(Q,v,b),group:v=>new ls(Q).set(v??{}),particles(v,b={}){const S=typeof v=="object"&&"type"in v?Q.shape(v).frame:v,_=new hi(Q,S,b),{max:C,blend:G,gravity:I,drag:O,...j}=b;return _.set(j),le.add(_),_},tween:(v,b,S,_)=>h.tween(v,b,S,_),bake(v,b,S,_,C){return g.set(v,{w:b,h:S,draw:_,origin:C}),u.delete(v),je.frame(v)},frame(v){const b=u.get(v);if(b&&r.valid(b)&&(b.gen===0||b.scale===D))return b;const S=g.get(v);if(S){const _=D,C=r.bake(S.w*_,S.h*_,G=>(G.scale(_,_),S.draw(G)),_,S.origin?.x??0,S.origin?.y??0);return u.set(v,C),C}if(b)return b;throw new Error(`[engine] no frame "${v}": load it or bake it first`)},async load(v){await Promise.all(Object.entries(v).map(([b,S])=>ao(b,S)))},hands:v=>v===void 0?$e():$e().filter(b=>b.player===v),touched(v,b,S={}){return v.updateWorld(),Di(v,$e(),b,S.padding??0)},hits(v,b,S,_=0){return v.updateWorld(),Ss(v,b,S,_)},avatars:(v={})=>new Vi(Q,so(v)),handMarkers(v={}){const b=v.radius??36,S=v.look??"auto",_=new Float64Array(6),C=Math.max(b*.12,3),G={type:"ring",r:b,lw:C,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},I={type:"ring",r:b,lw:C*1.8,stroke:ie,shadow:{color:ie,blur:b*.2}},O=(Pt,tt,Wt,Gs,Ve,Nt)=>{const Qe=tt.w/tt.scale;ft(_,null,Wt-Qe/2,Gs-Qe/2,0,1,1),Pt.r.quad(Pt.tex(tt.surface),tt,_,Qe,Qe,Ve,Nt,"normal")},j=Pt=>{let tt=null,Wt=!1;return()=>(tt&&r.valid(tt.frame)&&tt.frame.scale===D&&Wt===N.effects?tt:(Wt=N.effects,tt=Q.shape(Pt))).frame},z=j(G),it=j(I);return new ra(Q,(Pt,tt)=>{const Wt=S==="video"||S==="auto"&&mt==="video",Gs=z(),Ve=Wt?it():null;for(const Nt of $e())Ve&&O(Pt,Ve,Nt.x,Nt.y,16777215,tt),O(Pt,Gs,Nt.x,Nt.y,ht(Nt.color)[0],tt)})},timeline:v=>h.timeline(v),animation(v,b){const S=typeof v=="string"?ro(v):{frames:v},_=new Rt(Q,S,b);return le.add(_),_},bitmapFont(v,b){if(!b){const _=p.get(v);if(!_)throw new Error(`[engine] no bitmap font "${v}": load or make it first`);return _}const S="data"in b?vn(Pe(b.data),b.pages):zr(Q,b);return p.set(v,S),S},players:()=>Is(),onFrame(v){return Os.add(v),()=>{Os.delete(v)}},onRender(v){return Us.add(v),()=>{Us.delete(v)}},onBackdrop(v){return Ps.add(v),()=>{Ps.delete(v)}},get hud(){return kt||(kt=document.createElement("div"),kt.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(kt),_t()),kt},random:(v=0,b=1)=>v+Math.random()*(b-v),start(){He||(He=!0,qt=0,Ds=requestAnimationFrame(gn))},pause(){oe=!0,Xe()},resume(){oe=!1,Xe()},destroy(){He=!1,cancelAnimationFrame(Ds),fn.forEach(v=>v()),removeEventListener("resize",_t),Be?.disconnect(),document.removeEventListener("visibilitychange",mn),document.fonts?.removeEventListener?.("loadingdone",yn),h.clear(),rr(Q),l.destroy(),i.destroy(),kt?.remove()}};function ro(v){const b=d.get(v);if(b)return b;const S=[...new Set([...u.keys(),...g.keys()])].filter(_=>_.startsWith(v)).sort(or);if(!S.length)throw new Error(`[engine] no animation or frames "${v}\u2026"`);return{frames:S}}async function ao(v,b){const S=b.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(S))return l.load(v,b);if(["woff","woff2","ttf","otf"].includes(S)){const I=new FontFace(v,`url(${b})`);document.fonts.add(await I.load()),m++;return}const _=new URL(b,location.href);if(S==="fnt")return wn(v,Pe(await(await fetch(b)).text()),_);if(S==="json"){const I=await(await fetch(b)).json();if(Array.isArray(I.chars)&&!I.frames)return wn(v,Pe(I),_);const O=await Ts(new URL(I.meta?.image??b.replace(/\.json$/,".png"),_).href);oo(v,I,xe(O));return}const C=await Ts(b),G=xe(C);n.add(G),u.set(v,{surface:G,x:0,y:0,w:C.width,h:C.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function vn(v,b){return Br(v,b.map(S=>{const _=xe(S);return n.add(_),_}))}async function wn(v,b,S){p.set(v,vn(b,await Promise.all(b.pages.map(_=>Ts(new URL(_,S).href)))))}function oo(v,b,S){n.add(S);const _=Array.isArray(b.frames)?b.frames:Object.entries(b.frames).map(([I,O])=>({...O,filename:I})),C=[],G=[];for(const I of _){const O=I.frame,j=I.filename.replace(Ki,"");I.rotated&&console.warn(`[engine] ${v}/${j} is rotated: export without rotation`);const z={surface:S,x:O.x,y:O.y,w:O.w,h:O.h,scale:1,gen:0,ox:0,oy:0,margin:0};I.trimmed&&I.sourceSize&&I.spriteSourceSize&&(z.sw=I.sourceSize.w,z.sh=I.sourceSize.h,z.tx=I.spriteSourceSize.x,z.ty=I.spriteSourceSize.y);const it=I.scale9Borders;it&&(z.slice=[it.y,(z.sw??O.w)-it.x-it.w,(z.sh??O.h)-it.y-it.h,it.x]),u.set(`${v}/${j}`,z),C.push(`${v}/${j}`),G.push((I.duration??0)/1e3)}for(const[I,O]of Object.entries(b.animations??{}))d.set(`${v}/${I}`,{frames:O.map(j=>`${v}/${j.replace(Ki,"")}`)});for(const I of b.meta?.frameTags??[]){const O=[];for(let z=I.from;z<=I.to;z++)O.push(z);I.direction==="reverse"&&O.reverse(),I.direction==="pingpong"&&O.push(...O.slice(1,-1).reverse());const j=O.every(z=>G[z]>0);d.set(`${v}/${I.name}`,{frames:O.map(z=>C[z]),...j?{durations:O.map(z=>G[z])}:{}})}}return je}var Ki=/\.(png|webp|jpe?g|gif|bmp)$/i;function Ts(t){return new Promise((e,s)=>{const i=new Image;i.onload=()=>e(i),i.onerror=()=>s(new Error(`[engine] image did not load: ${t}`)),i.src=t})}function oa(t){return new Promise(e=>{const s=[];let i=0;const n=r=>{i&&s.push(r-i),i=r,s.length<t?requestAnimationFrame(n):e(s)};requestAnimationFrame(n)})}async function ha(t,e,s,i,n,r=()=>!1){const a=i(),h=Bi(e,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},a).frame,l=[],o=[],f=new Float64Array(6),u=.004,g=t.kind==="canvas2d"?t.canvas.getContext("2d"):null,p=pt();let d=0;return await new Promise(y=>{const m=w=>{d&&w-p>250&&l.push(w-d),d=w;const x=pt();t.begin(0,0,a);const k=s();for(let M=0;M<300;M++){const T=w/1e3+M;ft(f,null,M*37%n,M*53%Y,T,1,1),t.quad(k(h.surface),h,f,h.w/a,h.h/a,16777215,u,"normal")}for(let M=0;M<40;M++)t.ellipse(100+M*20,300,20,14,M,16746496,u),t.stroke([100+M*20,400,120+M*20,460,100+M*20,520],3,18,3368703,u,!1);t.end(),g?.getImageData(0,0,1,1),w-p>250&&o.push(pt()-x),w-p<750&&!r()?requestAnimationFrame(m):(t.begin(0,0,a),t.end(),y())};requestAnimationFrame(m)}),{intervals:l,cpu:o}}var la=64,Zi=32,ca=0,fa=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,Ji=new Set,tn=(t,e)=>{Ji.has(t)||(Ji.add(t),console.warn(e))},ua=t=>new da(t),da=class{constructor(t){c(this,"r",t),c(this,"css","none"),c(this,"plans",new di(la)),c(this,"buf",new Float64Array(64)),c(this,"keys",[]),c(this,"classes",new Map),c(this,"live",new Set),c(this,"svgs",new Map),c(this,"t",0),c(this,"cur",null),c(this,"svgFn",e=>this.svg(e)),c(this,"scr",[]),c(this,"flip",0)}chain(t,e){var s;const i=this.r;let n=this.buf;n[0]=i.scale,n[1]=i.maxBlur;let r=2;for(let d=0;d<e.length;d++){const y=e[d];if(r+22>n.length){const w=new Float64Array(n.length*2);w.set(n),n=this.buf=w}let m=this.classes.get(y.constructor);m===void 0&&this.classes.set(y.constructor,m=this.classes.size),n[r++]=m,n[r++]=y.enabled?1:0,y.params&&(r=y.params(n,r))}const a=(s=this.keys)[r]??(s[r]=new Float64Array(r));for(let d=0;d<r;d++)a[d]=n[d];const h=wt(a);let l=this.plans.get(a,h);l||this.plans.set(a,l=this.plan(e),h);for(let d=0;d<l.svgs.length;d++){const y=l.svgs[d];y.used<0&&this.attach(y),y.used=this.t}i.skipped+=l.skip;let o=t;const f=i.rx0,u=i.ry0,g=i.rx1-f,p=i.ry1-u;for(let d=0;d<l.paints.length;d++)l.parts[d]&&(o=this.bake(o,l.parts[d])),e[l.paints[d]].paint2d(o.getContext("2d"),f,u,g,p);return this.css=l.parts[l.paints.length]||"none",o}tick(){const t=++this.t;if(!(t%Zi||!this.live.size))for(const e of this.live)t-e.used>Zi&&this.detach(e)}destroy(){for(const t of this.live)this.detach(t);this.plans.clear()}svg(t){if(typeof document>"u"||!document.body)return null;const e=Array.from({length:20},(i,n)=>t[n]??0).join(" ");let s=this.svgs.get(e);if(!s){const i="http://www.w3.org/2000/svg",n=document.createElementNS(i,"svg");n.setAttribute("width","0"),n.setAttribute("height","0"),n.setAttribute("aria-hidden","true"),n.style.position="absolute";const r=document.createElementNS(i,"filter"),a=fa+ ++ca;r.setAttribute("id",a),r.setAttribute("color-interpolation-filters","sRGB");const h=document.createElementNS(i,"feColorMatrix");h.setAttribute("type","matrix"),h.setAttribute("values",e),r.append(h),n.append(r),this.attach(s={key:e,id:a,el:n,used:this.t})}return this.cur.svgs.push(s),`url(#${s.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){const e=this.r,s=this.cur={parts:[],paints:[],skip:0,svgs:[]};let i="";for(let n=0;n<t.length;n++){const r=t[n];if(!r.enabled)continue;if(r.kind===ns){s.skip++,tn("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}const a=e.support.filters&&r.css?r.css(e.scale,e.maxBlur,this.svgFn):null;a!==null?i+=i?` ${a}`:a:r.paint2d?(s.parts.push(i),s.paints.push(n),i=""):(s.skip++,tn("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 s.parts.push(i),s}bake(t,e){const s=this.r,i=this.flip^=1;let n=this.scr[i];(!n||n.width!==s.canvas.width||n.height!==s.canvas.height)&&(n=this.scr[i]=document.createElement("canvas"),n.width=s.canvas.width,n.height=s.canvas.height);const r=n.getContext("2d"),a=s.rx0,h=s.ry0,l=s.rx1-a,o=s.ry1-h;return r.clearRect(a,h,l,o),r.filter=e,r.drawImage(t,a,h,l,o,a,h,l,o),r.filter="none",n}},pa=64,Oe=17,ga=t=>`${xs}
49
- uniform sampler2D uTexture;
50
- uniform mat4 uM[${t}];
51
- uniform vec4 uO[${t}];
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 < ${t}; 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
- }`,ma=()=>`${xs}
65
- uniform sampler2D uTexture;
66
- uniform vec2 uDir;
67
- uniform vec2 uOff;
68
- uniform vec2 uTaps[${Oe}];
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 < ${Oe}; 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 ya(t,e,s=new Float32Array(20)){for(let i=0;i<4;i++)for(let n=0;n<5;n++){let r=n===4?e[i*5+4]:0;for(let a=0;a<4;a++)r+=e[i*5+a]*t[a*5+n];s[i*5+n]=r}return t.set(s),t}var va=t=>new wa(t),wa=class{constructor(t){c(this,"r",t),c(this,"colorProg",null),c(this,"blurProg",null),c(this,"user",new Map),c(this,"uses",0),c(this,"userErr",new Map),c(this,"scratchT",new Map),c(this,"steps",[]),c(this,"mats",[]),c(this,"counts",[]),c(this,"colorN"),c(this,"fm",new Float32Array(20)),c(this,"fm2",new Float32Array(20)),c(this,"fm3",new Float32Array(20)),c(this,"m16"),c(this,"o4"),c(this,"taps",new Float32Array(Oe*2));const 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){return this.r.lost?null:(this.userProg(t,!1),this.userErr.get(t)??null)}destroy(){const t=this.r.gl;for(const e of this.scratchT.values())t.deleteTexture(e.gl),t.deleteFramebuffer(e.fb);this.scratchT.clear();for(const e of[this.colorProg,this.blurProg])e&&t.deleteProgram(e.p);for(const e of this.user.values())e.p&&t.deleteProgram(e.p.p);this.user.clear()}userProg(t,e){const s=this.user,i=s.get(t);if(i)return i.t=++this.uses,i.p;if(this.r.lost)return null;if(s.size>=pa){let r="",a=1/0;for(const[l,o]of s)o.t<a&&(a=o.t,r=l);const h=s.get(r).p;h&&this.r.gl.deleteProgram(h.p),s.delete(r),this.userErr.delete(r)}let n;try{n=this.r.build(t)}catch(r){n=null;const a=r.message;this.userErr.set(t,a),e&&console.error(`[engine] a shader filter does not compile: it is skipped.
85
- ${a}`)}return s.set(t,{p:n,t:++this.uses}),n}scratch(t,e){const s=this.r,i=Math.ceil(s.canvas.width/t),n=Math.ceil(s.canvas.height/t),r=t*8+e;let a=this.scratchT.get(r)??null;return a&&(a.w!==i||a.h!==n)&&(s.drop(a),a=null),a||(a=s.target(i,n,t,!0),a?this.scratchT.set(r,a):this.scratchT.delete(r)),a}pass(t,e,s,i,n=!1){const r=this.r,a=r.gl;r.flush(),r.mapped=!1,r.bindFb(i),a.viewport(0,0,i.w,i.h),n||(a.disable(a.SCISSOR_TEST),a.clearColor(0,0,0,0),a.clear(a.COLOR_BUFFER_BIT)),r.use(t);const h=i.f;a.uniform2f(t.uScale,2/(h*i.w),-2/(h*i.h));const l=Math.floor(r.rx0/h)*h,o=Math.floor(r.ry0/h)*h,f=Math.min(Math.ceil(r.rx1/h),i.w)*h,u=Math.min(Math.ceil(r.ry1/h),i.h)*h,g=1/(s*e.width),p=1/(s*e.height);r.bScis=!1,r.batch.push(l,o,f,o,f,u,l,u,l*g,1-o*p,f*g,1-u*p,4294967295,r.slotOf(e)),r.flush()}post(t){return t==="color"?this.colorProg??(this.colorProg=this.r.build(ga(this.colorN))):this.blurProg??(this.blurProg=this.r.build(ma()))}linear(t,e){const s=this.r,i=s.gl;s.bindTex(s.layerTex.get(t)??null,0);const n=e?i.LINEAR:i.NEAREST;i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,n),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,n)}chain(t,e,s){const i=this.r,n=this.steps,r=i.scale,a=i.maxBlur;let h=0;for(let u=0;u<s.length;u++){const g=s[u];if(g.enabled)if(g.kind===es&&g.toMatrix){(!h||n[h-1]!==null)&&(n[h]=null,(!this.mats[h]||this.mats[h].length<20*this.colorN)&&(this.mats[h]=new Float32Array(20*this.colorN)),this.counts[h]=0,h++);const p=this.mats[h-1],d=this.counts[h-1];if(d<this.colorN)g.toMatrix(this.fm),p.set(this.fm,d*20),this.counts[h-1]=d+1;else{const y=(d-1)*20;for(let m=0;m<20;m++)this.fm2[m]=p[y+m];g.toMatrix(this.fm),ya(this.fm2,this.fm,this.fm3),p.set(this.fm2,y)}}else g.kind===ns?this.userProg(g.source,!0)?n[h++]=g:i.skipped++:g.kind===ss?Math.min(g.radius,a)*r>=.25&&(n[h++]=g):g.kind===is?n[h++]=g:i.skipped++}if(!h)return!1;const l=i.gl;let o=t,f=-1;for(let u=0;u<h;u++){const g=u===h-1,p=f===0?1:0,d=g?null:this.scratch(1,p);if(!g&&!d)break;const y=n[u];if(y===null){const m=this.post("color");i.use(m);const w=this.mats[u],x=this.counts[u],k=this.m16,M=this.o4;for(let T=0;T<x;T++)for(let E=0;E<4;E++){for(let F=0;F<4;F++)k[T*16+F*4+E]=w[T*20+E*5+F];M[T*4+E]=w[T*20+E*5+4]}l.uniformMatrix4fv(i.u(m,"uM"),!1,k),l.uniform4fv(i.u(m,"uO"),M),l.uniform1i(i.u(m,"uK"),x),d?this.pass(m,o,1,d):i.final(m,o,1,e)}else if(y.kind===ss)this.blur(o,f<0,Math.min(y.radius,a)*r,d,e,null);else if(y.kind===is){const m=y,w=this.scratch(1,2);if(!w)break;this.blur(o,f<0,Math.max(Math.min(m.blur,a),0)*r,w,1,m);const x=d??(e<1?this.scratch(1,p):null);x?(this.pass(i.main,w.tex,1,x),this.pass(i.main,o,1,x,!0),d||i.final(i.main,x.tex,1,e)):(i.final(i.main,w.tex,1,1),i.final(i.main,o,1,1))}else{const m=y,w=this.userProg(m.source,!0);i.use(w);const x=i.canvas.width,k=i.canvas.height;l.uniform2f(i.u(w,"uResolution"),x,k),l.uniform1f(i.u(w,"uTime"),i.time),l.uniform4f(i.u(w,"uRect"),i.rx0/x,1-i.ry1/k,i.rx1/x,1-i.ry0/k);const M=m.uniforms;for(const T in M){const E=i.u(w,T);if(!E)continue;const F=M[T];typeof F=="number"?l.uniform1f(E,F):F.length===2?l.uniform2fv(E,F):F.length===3?l.uniform3fv(E,F):F.length===4?l.uniform4fv(E,F):F.length===1&&l.uniform1fv(E,F)}d?this.pass(w,o,1,d):i.final(w,o,1,e)}d&&(o=d.tex,f=p)}return i.remap(),!0}blur(t,e,s,i,n,r){const a=this.r,h=a.gl,l=this.post("blur");let o=1;for(;o<16&&s/o>8;)o*=2;e&&this.linear(t,!0);let f=t,u=1;const g=Math.sqrt(Math.max(s*s-(o*o-1)/12,0))/o,p=s>=.25?this.tapsFor(g):this.tapsFor(0);let d=!0;if(p>1){for(let m=2;m<=o&&d;m*=2){const w=this.scratch(m,0);w?(this.pass(a.main,f,u,w),f=w.tex,u=m):d=!1}const y=d?this.scratch(o,3):null;y&&(a.use(l),h.uniform2fv(a.u(l,"uTaps"),this.taps),h.uniform1i(a.u(l,"uN"),p),h.uniform2f(a.u(l,"uDir"),1/f.width,0),h.uniform2f(a.u(l,"uOff"),0,0),h.uniform1f(a.u(l,"uMode"),0),this.pass(l,f,u,y),f=y.tex)}if(a.use(l),h.uniform2fv(a.u(l,"uTaps"),this.taps),h.uniform1i(a.u(l,"uN"),p),h.uniform2f(a.u(l,"uDir"),0,1/f.height),r){const y=r.opacity,m=r.rgb;h.uniform4f(a.u(l,"uShadow"),(m>>16&255)/255*y,(m>>8&255)/255*y,(m&255)/255*y,y),h.uniform1f(a.u(l,"uMode"),1),h.uniform2f(a.u(l,"uOff"),-r.dx*a.scale/(u*f.width),r.dy*a.scale/(u*f.height))}else h.uniform1f(a.u(l,"uMode"),0),h.uniform2f(a.u(l,"uOff"),0,0);i?this.pass(l,f,u,i):a.final(l,f,u,n),e&&this.linear(t,!1)}tapsFor(t){const e=this.taps;if(e.fill(0),e[1]=1,t<.2)return 1;const s=Math.min(Math.ceil(3*t),(Oe-1)*2),i=-1/(2*t*t);let n=1,r=1;for(let a=1;a<=s;a+=2){const h=Math.exp(a*a*i),l=a+1<=s?Math.exp((a+1)*(a+1)*i):0,o=h+l;e[r*2]=(a*h+(a+1)*l)/o,e[r*2+1]=o,n+=2*o,r++}for(let a=0;a<r;a++)e[a*2+1]=e[a*2+1]/n;return r}},gt=t=>Math.min(Math.max(t,0),1),rt=t=>Math.max(t,0),re=class{constructor(){c(this,"enabled",!0),lt.gl=va,lt.c2d=ua}},At=class extends re{constructor(t){super(),c(this,"amount",t),c(this,"kind",es)}params(t,e){return t[e]=this.amount,e+1}};function Ue(t,e,s){t.fill(0),t[0]=t[6]=t[12]=e,t[4]=t[9]=t[14]=s,t[18]=1}function De(t,e){t.fill(0);for(let s=0;s<3;s++)for(let i=0;i<3;i++)t[s*5+i]=e[s*3+i];t[18]=1}var P=new Float64Array(9),xa=class extends At{toMatrix(t){Ue(t,rt(this.amount),0)}css(){return`brightness(${rt(this.amount)})`}},ba=class extends At{toMatrix(t){const e=rt(this.amount);Ue(t,e,.5-.5*e)}css(){return`contrast(${rt(this.amount)})`}},Ma=class extends At{toMatrix(t){const e=gt(this.amount);Ue(t,1-2*e,e)}css(){return`invert(${gt(this.amount)})`}},Aa=class extends At{toMatrix(t){const e=rt(this.amount);P[0]=.213+.787*e,P[1]=.715-.715*e,P[2]=.072-.072*e,P[3]=.213-.213*e,P[4]=.715+.285*e,P[5]=.072-.072*e,P[6]=.213-.213*e,P[7]=.715-.715*e,P[8]=.072+.928*e,De(t,P)}css(){return`saturate(${rt(this.amount)})`}},ka=class extends At{toMatrix(t){const e=1-gt(this.amount);P[0]=.2126+.7874*e,P[1]=.7152-.7152*e,P[2]=.0722-.0722*e,P[3]=.2126-.2126*e,P[4]=.7152+.2848*e,P[5]=.0722-.0722*e,P[6]=.2126-.2126*e,P[7]=.7152-.7152*e,P[8]=.0722+.9278*e,De(t,P)}css(){return`grayscale(${gt(this.amount)})`}},_a=class extends At{toMatrix(t){const e=1-gt(this.amount);P[0]=.393+.607*e,P[1]=.769-.769*e,P[2]=.189-.189*e,P[3]=.349-.349*e,P[4]=.686+.314*e,P[5]=.168-.168*e,P[6]=.272-.272*e,P[7]=.534-.534*e,P[8]=.131+.869*e,De(t,P)}css(){return`sepia(${gt(this.amount)})`}},Ea=class extends At{get angle(){return this.amount}set angle(t){this.amount=t}toMatrix(t){const e=this.amount*Math.PI/180,s=Math.cos(e),i=Math.sin(e);P[0]=.213+s*.787-i*.213,P[1]=.715-s*.715-i*.715,P[2]=.072-s*.072+i*.928,P[3]=.213-s*.213+i*.143,P[4]=.715+s*.285+i*.14,P[5]=.072-s*.072-i*.283,P[6]=.213-s*.213-i*.787,P[7]=.715-s*.715+i*.715,P[8]=.072+s*.928+i*.072,De(t,P)}css(){return`hue-rotate(${this.amount}deg)`}},Sa=class extends At{constructor(t,e){super(e),c(this,"c",16777215),c(this,"cs",""),this.color=t}get color(){return this.c}set color(t){this.c=ht(t)[0],this.cs=Vt(this.c)}params(t,e){return t[e]=this.amount,t[e+1]=this.c,e+2}toMatrix(t){const e=gt(this.amount);Ue(t,1-e,0),t[4]=(this.c>>16&255)/255*e,t[9]=(this.c>>8&255)/255*e,t[14]=(this.c&255)/255*e}css(){return null}paint2d(t,e,s,i,n){const r=gt(this.amount);r<=0||(t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=r,t.globalCompositeOperation="source-atop",t.fillStyle=this.cs,t.fillRect(e,s,i,n),t.restore())}},Ta=class extends re{constructor(t){if(super(),c(this,"kind",es),c(this,"values"),t.length!==20)throw new Error(`colorMatrix: 20 numbers expected (4 rows of 5), got ${t.length}`);this.values=Array.from(t)}toMatrix(t){for(let e=0;e<20;e++)t[e]=this.values[e]??0}params(t,e){for(let s=0;s<20;s++)t[e+s]=this.values[s]??0;return e+20}css(t,e,s){return s?s(this.values):null}},Ra=class extends re{constructor(t){super(),c(this,"radius",t),c(this,"kind",ss)}params(t,e){return t[e]=this.radius,e+1}pad(t){return 3*Math.min(rt(this.radius),t)}css(t,e){return`blur(${Math.min(rt(this.radius),e)*t}px)`}},Fa=class extends re{constructor(t,e,s,i){super(),c(this,"dx",t),c(this,"dy",e),c(this,"blur",s),c(this,"kind",is),c(this,"rgb",0),c(this,"a",1),this.color=i}get opacity(){return this.a}set opacity(t){this.a=gt(t)}get color(){return this.rgb}set color(t){const[e,s]=ht(t);this.rgb=e,this.a=s}params(t,e){return t[e]=this.dx,t[e+1]=this.dy,t[e+2]=this.blur,t[e+3]=this.rgb,t[e+4]=this.a,e+5}pad(t){return 3*Math.min(rt(this.blur),t)+Math.max(Math.abs(this.dx),Math.abs(this.dy))}css(t,e){return`drop-shadow(${this.dx*t}px ${this.dy*t}px ${2*Math.min(rt(this.blur),e)*t}px ${Vt(this.rgb,this.opacity)})`}},Ca=`#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
- `,Pa=t=>`${Ca}${t}
99
- #undef main
100
- void main() {
101
- fabiUserMain();
102
- gl_FragColor *= vColor.a;
103
- }
104
- `,Na=class extends re{constructor(t){super(),c(this,"kind",ns),c(this,"source"),c(this,"uniforms",{}),c(this,"padding"),this.source=Pa(t.fragment),this.padding=t.padding??0;for(const e in t.uniforms??{}){const s=t.uniforms[e];this.uniforms[e]=typeof s=="number"?s:Float32Array.from(s)}}pad(){return rt(this.padding)}},La=(t,e=1)=>new Sa(t,e),Ia=t=>new xa(t),Oa=t=>new ba(t),Ua=t=>new Aa(t),Da=(t=1)=>new ka(t),Ba=(t=1)=>new _a(t),za=t=>new Ea(t),Ga=(t=1)=>new Ma(t),Xa=t=>new Ta(t),$a=t=>new Ra(t),Ha=(t,e,s,i="rgba(0,0,0,0.5)")=>new Fa(t,e,s,i);function qa(t){const e=new Na(t),s=lt.live?.filters()?.check(e.source);if(s)throw new Error(`shader(): the fragment does not compile:
105
- ${s}`);return e}var Rs="x y rotation scaleX scaleY alpha visible blend tint z hitRadius clip mask filters".split(" "),en="frameName _frame _w _h slice autoAnchor".split(" "),Wa="fps loop speed onComplete durations".split(" "),Fs=["anchorX","anchorY"],Ya=[...Rs,...en,...Wa,...Fs],ja=[...Rs,...en,...Fs],Va=[...Rs,...Fs],sn=t=>t instanceof Rt?Ya:t instanceof Ot?ja:Va;function Qa(t){const e={},s=t;for(const i of sn(t))e[i]=s[i];return t instanceof te&&(e.spec=t.spec),t instanceof ne&&(e.text=t.text,e.style=t.style),t instanceof Rt&&(e.playing=t.playing),e}function nn(t,e){const s=t;t instanceof te&&t.spec!==e.spec&&(t.spec=e.spec),t instanceof ne&&(t.text=e.text,t.style!==e.style&&(s._style=e.style,s.dirty=!0)),t instanceof Rt&&t.gotoFrame(e.speed<0?t.frameCount-1:0);const i=t instanceof te||t instanceof ne,n=sn(t);for(let r=0;r<n.length;r++){const a=n[r];(!i||a!=="_frame"&&a!=="frameName")&&(s[a]=e[a])}}var rn=class{constructor(t,e={}){c(this,"factory",t),c(this,"opts",e),c(this,"stats",{live:0,free:0,created:0}),c(this,"free",[]),c(this,"states",new Map),c(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;const s=this.states.get(e);nn(e,s),e.visible=s.visible,e instanceof Rt&&s.playing&&e.play()}else{if(e=this.factory(),!(e instanceof St))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,Qa(e)),e._pool=this,this.stats.created++}return this.stats.live++,t&&e.set(t),e}release(t){const 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();t.parent?.remove(t),t.kernel.tweens.stopAll(t),this.stats.live--,nn(t,e),t instanceof Rt&&t.stop(),t.visible=!1,t._free=!0,this.opts.reset?.(t),this.free.push(t),this.stats.free++}}forget(t){const e=t;if(this.states.delete(e))if(e._free){const s=this.free.indexOf(e);s>=0&&(this.free[s]=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(const t of[...this.states.keys()])t.destroy()}},Ka=(t,e)=>new rn(t,e);return Et.exports});
1
+ /*! @fabiplay/engine 0.9.1 (lite: load fabi-play.js first) | Fabi Play Kit License | https://docs.fabiplay.app */(function(ci,qt){var Ne=typeof document!="undefined"?document.currentScript:null;typeof define=="function"&&define.amd?define([],function(){return qt(Ne)}):typeof module=="object"&&module&&module.exports?module.exports=qt(Ne):ci.FabiEngine=qt(Ne)})(typeof globalThis!="undefined"?globalThis:typeof self!="undefined"?self:this,function(ci){"use strict";var qt={exports:{}},Ne=qt.exports,Ie=Object.defineProperty,Wn=Object.defineProperties,jn=Object.getOwnPropertyDescriptor,Yn=Object.getOwnPropertyDescriptors,Vn=Object.getOwnPropertyNames,Le=Object.getOwnPropertySymbols,ms=Object.prototype.hasOwnProperty,ui=Object.prototype.propertyIsEnumerable,$t=Math.pow,vs=(t,e,s)=>e in t?Ie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,Mt=(t,e)=>{for(var s in e||(e={}))ms.call(e,s)&&vs(t,s,e[s]);if(Le)for(var s of Le(e))ui.call(e,s)&&vs(t,s,e[s]);return t},fe=(t,e)=>Wn(t,Yn(e)),ys=(t,e)=>{var s={};for(var i in t)ms.call(t,i)&&e.indexOf(i)<0&&(s[i]=t[i]);if(t!=null&&Le)for(var i of Le(t))e.indexOf(i)<0&&ui.call(t,i)&&(s[i]=t[i]);return s},Qn=(t,e)=>{for(var s in e)Ie(t,s,{get:e[s],enumerable:!0})},Kn=(t,e,s,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Vn(e))!ms.call(t,n)&&n!==s&&Ie(t,n,{get:()=>e[n],enumerable:!(i=jn(e,n))||i.enumerable});return t},Zn=t=>Kn(Ie({},"__esModule",{value:!0}),t),c=(t,e,s)=>vs(t,typeof e!="symbol"?e+"":e,s),te=(t,e,s)=>new Promise((i,n)=>{var r=l=>{try{o(s.next(l))}catch(h){n(h)}},a=l=>{try{o(s.throw(l))}catch(h){n(h)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(r,a);o((s=s.apply(t,e)).next())}),fi={};Qn(fi,{AnimatedSprite:()=>Yt,Atlas:()=>Ns,AvatarPainter:()=>Ys,AvatarsNode:()=>xn,BitmapFont:()=>Vs,DEFAULT_FONT:()=>en,EASE:()=>me,Group:()=>Ps,HALO:()=>Me,MAX_LAYERS:()=>Ts,NameTags:()=>Ws,Node:()=>Wt,NodePool:()=>Rn,Particles:()=>Ci,STAGE_HEIGHT:()=>rt,Shape:()=>xe,ShelfPacker:()=>Ni,Sound:()=>un,Sprite:()=>ie,TIERS:()=>Et,Text:()=>ke,Timeline:()=>yn,Tweens:()=>wn,avatarPortrait:()=>la,blur:()=>po,brightness:()=>ro,colorMatrix:()=>fo,contrast:()=>ao,createAvatarRenderer:()=>oa,createEngine:()=>Fa,createRenderer:()=>Hs,dropShadow:()=>go,grayscale:()=>lo,handsOf:()=>ln,hits:()=>Qs,hueRotate:()=>co,invert:()=>uo,nodePool:()=>_o,packColor:()=>se,parseBMFont:()=>$e,parseColor:()=>xt,pickTier:()=>fn,playerColor:()=>ts,rendererOrder:()=>tn,rng:()=>yr,saturate:()=>oo,sepia:()=>ho,shader:()=>mo,shapeBounds:()=>js,tier:()=>Vt,tint:()=>no,touching:()=>hn,wrists:()=>on}),qt.exports=Zn(fi);var Pt=typeof self!="undefined"?self:typeof window!="undefined"?window:typeof global!="undefined"?global:{},Jn=33,pt={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},$n=4,Oe=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"],tr={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},No=tr["6-8"],di=(t,e)=>t?{x:t.x+e.x*t.w,y:t.y+e.y*t.h}:{x:e.x,y:e.y},er=.5,De={left:1.6,top:1.6,w:3.2,h:3},sr=1.2;function ir(t,e,s={}){const i=Array.isArray(t)?t:t.body;if(!Array.isArray(i))return null;const n=e==="left"?pt.leftWrist:pt.rightWrist,r=x=>{var b;return de(i[x*3])&&de(i[x*3+1])&&((b=i[x*3+2])!=null?b:0)>=er?x:-1};if(r(n)<0)return null;const a=i[n*3],o=i[n*3+1];if(s.orientation!=="portrait")return di(s.view,{x:a,y:o});if(r(pt.leftShoulder)<0||r(pt.rightShoulder)<0)return null;const l=pt.leftShoulder*3,h=pt.rightShoulder*3,u=(i[l]+i[h])/2,f=(i[l+1]+i[h+1])/2,d=pt.leftHip*3,g=pt.rightHip*3,p=(i[d]+i[g])/2,v=(i[d+1]+i[g+1])/2;let m=de(p)&&de(v)?Math.hypot(p-u,v-f):0;return(r(pt.leftHip)<0||r(pt.rightHip)<0)&&(m=Math.max(m,sr*Math.hypot(i[l]-i[h],i[l+1]-i[h+1]))),m=Math.max(m,.01),{x:gi((a-u+De.left*m)/(De.w*m)),y:gi((o-f+De.top*m)/(De.h*m))}}var nr=300,pi=class{constructor(t=nr){c(this,"holdMs",t),c(this,"last",new Map)}static key(t,e){return t*2+(e==="right"?1:0)}at(t,e,s){const i=this.last.get(t);return e?(i?(i.x=e.x,i.y=e.y,i.t=s):this.last.set(t,{x:e.x,y:e.y,t:s}),e):i?s-i.t<=this.holdMs?{x:i.x,y:i.y}:(this.last.delete(t),null):null}clear(){this.last.clear()}},rr=.25,ar=Object.freeze({top:0,bottom:0,left:0,right:0});function or(t){if(!lr(t))return;const e=s=>de(s)?Math.min(Math.max(s,0),rr):0;return{top:e(t.top),bottom:e(t.bottom),left:e(t.left),right:e(t.right)}}var Io=16/9,lr=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),de=t=>typeof t=="number"&&Number.isFinite(t),gi=t=>Math.min(Math.max(t,0),1),hr=12,cr=Jn*4,ur=t=>hr+t*cr,Lo=ur($n),fr=t=>t.startsWith("fabi-play.")?"fablee-play.".concat(t.slice(10)):null;function dr(t,e,s=fr(e)){if(!(!t||!s))try{const i=t.getItem(s);if(i===null)return;t.getItem(e)===null&&t.setItem(e,i),t.removeItem(s)}catch(i){}}var mi,vi=(mi=Pt.FabiPlay)==null?void 0:mi.avatars;if(!vi)throw new Error("[engine] fabi-play-engine.lite.js needs fabi-play.js (with FabiPlay.avatars) loaded before it");var{avatarById:Ue,avatarShapes:pr,BAND_BODY:Oo,DEFAULT_AVATAR:Be,drawShapes:yi,frameOf:gr,iconShapes:mr}=vi,ee=()=>Float64Array.of(1,0,0,1,0,0);function At(t,e,s,i,n,r,a){const o=n?Math.cos(n):1,l=n?Math.sin(n):0,h=o*r,u=l*r,f=-l*a,d=o*a;if(!e)return t[0]=h,t[1]=u,t[2]=f,t[3]=d,t[4]=s,t[5]=i,t;const g=e[0],p=e[1],v=e[2],m=e[3];return t[0]=g*h+v*u,t[1]=p*h+m*u,t[2]=g*f+v*d,t[3]=p*f+m*d,t[4]=g*s+v*i+e[4],t[5]=p*s+m*i+e[5],t}function vr(t,e,s){const i=t[0]*t[3]-t[1]*t[2];if(Math.abs(i)<1e-12)return null;const n=e-t[4],r=s-t[5];return[(t[3]*n-t[2]*r)/i,(-t[1]*n+t[0]*r)/i]}var wi={white:16777215,black:0,red:16711680,transparent:0},pe=new Map;function xt(t){var e,s;if(typeof t=="number")return[t&16777215,1];const i=pe.get(t);if(i)return i;let n=[16777215,1];const r=t.trim().toLowerCase();if(r[0]==="#"){const a=r.slice(1),o=a.length<=4?[...a].map(h=>h+h).join(""):a,l=parseInt(o.slice(0,6),16);Number.isFinite(l)&&(n=[l,o.length===8?parseInt(o.slice(6,8),16)/255:1])}else if(r.startsWith("rgb")){const a=(s=(e=r.match(/-?\d*\.?\d+%?/g))==null?void 0:e.map(f=>f.endsWith("%")?parseFloat(f)/100*255:parseFloat(f)))!=null?s:[],[o=255,l=255,h=255]=a,u=a[3]===void 0?1:r.match(/,\s*[\d.]+%\s*\)$/)?a[3]/255:a[3];n=[(ws(o)<<16|ws(l)<<8|ws(h))>>>0,Math.min(Math.max(u,0),1)]}else if(r in wi)n=[wi[r],r==="transparent"?0:1];else if(typeof document!="undefined"){const a=document.createElement("canvas").getContext("2d");if(a){a.fillStyle="#ffffff",a.fillStyle=r;const o=a.fillStyle;if(o!==r)return pe.set(t,n=xt(o)),n}}return pe.size>512&&pe.clear(),pe.set(t,n),n}var ws=t=>Math.min(Math.max(Math.round(t),0),255);function se(t,e,s=!1){const i=Math.min(Math.max(e,0),1),n=(t>>16&255)*i,r=(t>>8&255)*i,a=(t&255)*i,o=s?0:i*255;return(Math.round(o)<<24|Math.round(a)<<16|Math.round(r)<<8|Math.round(n))>>>0}var ge=(t,e=1)=>"rgba(".concat(t>>16&255,",").concat(t>>8&255,",").concat(t&255,",").concat(e,")");function xi(t,e){if(t===16777215)return e;if(e===16777215)return t;const s=i=>Math.round((t>>i&255)*(e>>i&255)/255);return(s(16)<<16|s(8)<<8|s(0))>>>0}var me={linear:t=>t,quadIn:t=>t*t,quadOut:t=>t*(2-t),quadInOut:t=>t<.5?2*t*t:-1+(4-2*t)*t,cubicOut:t=>1-$t(1-t,3),sineInOut:t=>-(Math.cos(Math.PI*t)-1)/2,backOut:t=>1+(1.70158+1)*$t(t-1,3)+1.70158*$t(t-1,2),elasticOut:t=>t===0||t===1?t:$t(2,-10*t)*Math.sin((t*10-.75)*(2*Math.PI/3))+1,bounceOut:t=>t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375};function yr(t){let e=t>>>0;return()=>{e=e+1831565813>>>0;let s=e;return s=Math.imul(s^s>>>15,s|1),s^=s+Math.imul(s^s>>>7,s|61),((s^s>>>14)>>>0)/4294967296}}var ve=1,bi=2,ze=0,mt=1,wr=4294967295,k={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},Ct=[],xr="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function _i(t){const e=k;for(const i of xr){const n=e[i],r=new n.constructor(i==="world"?t*6:t);r.set(n),e[i]=r}const s=new Int32Array(t);for(let i=0;i<k.freeCount;i++)s[i]=k.free[(k.freeHead+i)%k.cap];for(k.free=s,k.freeHead=0,k.cap=t,k.epoch++;Ct.length<t;)Ct.push(null)}function xs(t){k.x[t]=k.y[t]=k.rot[t]=0,k.sx[t]=k.sy[t]=k.alpha[t]=1,k.la[t]=k.ld[t]=1,k.lb[t]=k.lc[t]=0;const e=t*6,s=k.world;s[e]=s[e+3]=1,s[e+1]=s[e+2]=s[e+4]=s[e+5]=0,k.tint[t]=16777215,k.flags[t]=ve|bi,k.moved[t]=1,k.dirty[t]=0,k.parent[t]=k.first[t]=k.next[t]=k.prev[t]=-1}_i(256),xs(ze),k.flags[ze]=0,xs(mt),k.flags[mt]=0;function br(){let t;if(k.freeCount){t=k.free[k.freeHead],k.freeHead=(k.freeHead+1)%k.cap,k.freeCount--;const e=Ct[t];e&&(e._i=ze,e._g=-1,Ct[t]=null)}else k.top===k.cap&&_i(k.cap*2),t=k.top++;return xs(t),t}function Mi(t,e){bs(t);for(let i=k.first[t];i>=0;){const n=k.next[i];k.parent[i]=k.next[i]=k.prev[i]=-1,i=n}k.first[t]=-1,k.flags[t]=k.flags[t]&~bi,k.moved[t]=0;const s=k.gen[t]+1;k.gen[t]=s,s!==wr&&(e&&(Ct[t]=e),k.free[(k.freeHead+k.freeCount)%k.cap]=t,k.freeCount++)}function _r(t){for(let e=0;e<Ct.length;e++){const s=Ct[e];s&&t(s)&&(s._i=ze,s._g=-1,Ct[e]=null)}}function Mr(t,e){bs(t);const s=k.first[e];k.parent[t]=e,k.next[t]=s,k.prev[t]=-1,s>=0&&(k.prev[s]=t),k.first[e]=t,k.moved[t]=1}function bs(t){const e=k.parent[t];if(e<0)return;const s=k.next[t],i=k.prev[t];i>=0?k.next[i]=s:k.first[e]=s,s>=0&&(k.prev[s]=i),k.parent[t]=k.next[t]=k.prev[t]=-1}var ye={root:-1,gen:-1,world:new Float64Array(6)};function Ar(t){const e=++k.pass,s=k.world,i=t*6,n=ye.world;let r=ye.root!==t||ye.gen!==k.gen[t];for(let a=0;a<6;a++)n[a]!==s[i+a]&&(r=!0),n[a]=s[i+a];ye.root=t,ye.gen=k.gen[t],k.stamp[t]=r?e:e-1}function kr(t){k.stamp[t]=k.pass}function Ai(t){for(let e=k.first[t];e>=0;){const s=k.next[e];Ai(e),e=s}Mi(t)}var _s=typeof FinalizationRegistry=="function"?new FinalizationRegistry(t=>k.gen[t.i]===t.g&&Ai(t.i)):null;function ki(t){t._reg||!_s||(t._reg=!0,_s.register(t,{i:t._i,g:t._g},t))}function Er(t){t._reg&&_s.unregister(t)}var Ms=1,As=2,ks=3,Es=4;function Ss(t){if(t){for(let e=0;e<t.length;e++)if(t[e].enabled)return!0}return!1}function Sr(t,e){let s=0;for(let i=0;i<t.length;i++){const n=t[i];n.enabled&&n.pad&&(s+=n.pad(e))}return s}var bt={gl:null,c2d:null,live:null},j=new Float64Array(3),Ts=4,Tr=1,Rs=()=>Tr++,et=ee(),R=k,Wt=class{constructor(t){c(this,"kernel",t),c(this,"_i",br()),c(this,"_g",R.gen[this._i]),c(this,"_wv",null),c(this,"_wi",-1),c(this,"_we",-1),c(this,"blend","normal"),c(this,"_data",null),c(this,"parent",null),c(this,"hitRadius",null),c(this,"clip",null),c(this,"mask",null),c(this,"filters",null),c(this,"_z",0),c(this,"anchorX",0),c(this,"anchorY",0),c(this,"_pool",null),c(this,"_free",!1),c(this,"_reg",!1)}get x(){return R.x[this._i]}set x(t){const e=this._i||mt;R.x[e]=t,R.moved[e]=1}get y(){return R.y[this._i]}set y(t){const e=this._i||mt;R.y[e]=t,R.moved[e]=1}get rotation(){return R.rot[this._i]}set rotation(t){const e=this._i||mt;R.rot[e]=t,R.dirty[e]=R.moved[e]=1}get scaleX(){return R.sx[this._i]}set scaleX(t){const e=this._i||mt;R.sx[e]=t,R.dirty[e]=R.moved[e]=1}get scaleY(){return R.sy[this._i]}set scaleY(t){const e=this._i||mt;R.sy[e]=t,R.dirty[e]=R.moved[e]=1}get alpha(){return R.alpha[this._i]}set alpha(t){const e=this._i||mt;R.alpha[e]=t,R.moved[e]=1}get visible(){return(R.flags[this._i]&ve)!==0}set visible(t){const e=this._i||mt;t?R.flags[e]=R.flags[e]|ve:R.flags[e]=R.flags[e]&~ve,R.moved[e]=1}get destroyed(){return R.gen[this._i]!==this._g}get world(){const t=this._i||mt;return(this._wi!==t||this._we!==R.epoch)&&(this._wv=R.world.subarray(t*6,t*6+6),this._wi=t,this._we=R.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 R.tint[this._i]}set tint(t){R.tint[this._i||mt]=typeof t=="number"?t&16777215:xt(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(const e in t){const s=t[e];s!==void 0&&(this[e]=s)}return this}destroy(){var t;this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),Mi(this._i,this),Er(this),this.kernel.tweens.stopAll(this),(t=this._pool)==null||t.forget(this))}updateWorld(){const t=this.parent?this.parent.updateWorld():null;return At(this.world,t,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(t,e,s){}};function Rr(t){_r(e=>e.kernel===t)}var Fs=!1,Ei=Object.freeze([]),Ps=class qn extends Wt{constructor(e){super(e),c(this,"children",Ei),c(this,"sortDirty",!1),c(this,"dead",!1),ki(this)}add(e,...s){this.adopt(e);for(let i=0;i<s.length;i++)this.adopt(s[i]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&Mr(e._i,this._i),this.children===Ei&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||ki(e)}detach(e){const s=this.children,i=s.indexOf(e);if(i>=0){for(let n=i+1;n<s.length;n++)s[n-1]=s[n];s.pop()}e.parent===this&&(e.parent=null,e.destroyed||bs(e._i))}clear(){for(const e of this.children)e.destroy()}destroy(){for(const e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(const s of this.children)s.destroyed?s.parent===this&&(s.parent=null):this.children[e++]=s;this.children.length=e}for(const e of this.children)e instanceof qn&&e.sweep()}draw(e,s,i){if(Fs)return R.parent[this._i]<0&&!this.destroyed&&kr(this._i),this.drawChildren(e,s,i);Fs=!0;try{this.destroyed||Ar(this._i),this.drawChildren(e,s,i)}finally{Fs=!1}}drawChildren(e,s,i){if(this.sortDirty){const o=new Map(this.children.map((l,h)=>[l,h]));this.children.sort((l,h)=>l.z-h.z||o.get(l)-o.get(h)),this.sortDirty=!1}const n=this.children,r=this._i,a=R.stamp[r]===R.pass;for(let o=0;o<n.length;o++){const l=n[o],h=l._i,u=R.alpha[h];if(R.gen[h]!==l._g||!(R.flags[h]&ve)||u<=0)continue;if(a||R.moved[h]){R.moved[h]=0,R.stamp[h]=R.pass;let g,p,v,m;if(R.dirty[h]){R.dirty[h]=0;const B=R.rot[h],N=B?Math.cos(B):1,G=B?Math.sin(B):0,z=R.sx[h],U=R.sy[h];R.la[h]=g=N*z,R.lb[h]=p=G*z,R.lc[h]=v=-G*U,R.ld[h]=m=N*U}else g=R.la[h],p=R.lb[h],v=R.lc[h],m=R.ld[h];const x=R.world,b=R.x[h],w=R.y[h],A=h*6,T=r*6,F=x[T],P=x[T+1],E=x[T+2],I=x[T+3];x[A]=F*g+E*p,x[A+1]=P*g+I*p,x[A+2]=F*v+E*m,x[A+3]=P*v+I*m,x[A+4]=F*b+E*w+x[T+4],x[A+5]=P*b+I*w+x[T+5]}const f=s*u,d=xi(i,R.tint[h]);l.clip||l.mask||l.filters?Ti(e,l,f,d):l.draw(e,f,d)}}},at=new Float64Array(128),jt=0,Cs=new Float64Array(8);function Si(t,e,s,i){e.clip||e.mask||e.filters?Ti(t,e,s,i):e.draw(t,s,i)}function Ti(t,e,s,i){const n=t.r,r=e.world,a=e.clip;let o=!1,l=!1;if(a)if(Math.abs(r[1])<1e-9&&Math.abs(r[2])<1e-9&&jt<32){const f=r[0]*a.x+r[4],d=r[0]*(a.x+a.width)+r[4],g=r[3]*a.y+r[5],p=r[3]*(a.y+a.height)+r[5];let v=Math.min(f,d),m=Math.max(f,d),x=Math.min(g,p),b=Math.max(g,p);if(jt){const A=(jt-1)*4;v=Math.max(v,at[A]),x=Math.max(x,at[A+1]),m=Math.min(m,at[A+2]),b=Math.min(b,at[A+3])}const w=jt++*4;at[w]=v,at[w+1]=x,at[w+2]=m,at[w+3]=b,n.clip(v,x,Math.max(m-v,0),Math.max(b-x,0)),l=!0}else o=!0;const h=e.mask&&e.mask.visible?e.mask:null,u=Ss(e.filters)?e.filters:null;try{if(o&&n.beginLayer(),h&&n.beginLayer(),u?(e.draw(t,n.beginLayer()?1:s,i),n.endLayer(s,u)):e.draw(t,s,i),h&&(n.beginMask(),At(h.world,r,h.x,h.y,h.rotation,h.scaleX,h.scaleY),Si(t,h,h.alpha,16777215),n.endLayer(1)),o&&a){n.beginMask();for(let f=0;f<4;f++){const d=f===1||f===2?a.x+a.width:a.x,g=f>1?a.y+a.height:a.y;Cs[f*2]=r[0]*d+r[2]*g+r[4],Cs[f*2+1]=r[1]*d+r[3]*g+r[5]}n.polygon(Cs,4,16777215,1),n.endLayer(1)}}finally{if(l)if(jt--,jt){const f=(jt-1)*4;n.clip(at[f],at[f+1],at[f+2]-at[f],at[f+3]-at[f+1])}else n.unclip()}}var ie=class extends Wt{constructor(t,e,s){super(t),c(this,"_frame",null),c(this,"_w",null),c(this,"_h",null),c(this,"slice",0),c(this,"autoAnchor",!0),c(this,"frameName",null),e&&(this.frame=e),(s==null?void 0:s.anchor)===void 0&&this.useFrameAnchor(),s&&this.set(s)}get frame(){return this._frame}set frame(t){this.frameName=typeof t=="string"?t:null,this._frame=typeof t=="string"?this.kernel.frame(t):t,this.autoAnchor&&this.useFrameAnchor()}set anchor(t){this.autoAnchor=!1,super.anchor=t}get naturalWidth(){var t;const e=this.frameNow();return e?((t=e.sw)!=null?t:e.w)/e.scale-e.margin*2:0}get naturalHeight(){var t;const e=this.frameNow();return e?((t=e.sh)!=null?t:e.h)/e.scale-e.margin*2:0}get width(){var t;return(t=this._w)!=null?t:this.naturalWidth}set width(t){this._w=t}get height(){var t;return(t=this._h)!=null?t:this.naturalHeight}set height(t){this._h=t}sizeQ(t){var e,s,i,n;ae[0]=(s=this._w)!=null?s:((e=t.sw)!=null?e:t.w)/t.scale-t.margin*2,ae[1]=(n=this._h)!=null?n:((i=t.sh)!=null?i:t.h)/t.scale-t.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){var t,e;const s=this._frame;if(!s)return;const i=((t=s.sw)!=null?t:s.w)/s.scale-s.margin*2,n=((e=s.sh)!=null?e:s.h)/s.scale-s.margin*2;this.anchorX=i>0?(s.ox-s.margin)/i:0,this.anchorY=n>0?(s.oy-s.margin)/n:0}draw(t,e,s){const i=this.frameNow();if(!i)return;const n=ae;this.sizeQ(i),n[2]=this.anchorX,n[3]=this.anchorY,n[4]=e,Fr(t,i,this.world,this.slice,s,this.blend)}},ne=new Float64Array(12),re=new Float64Array(12),we={x:0,y:0,w:0,h:0};function Ri(t,e,s,i,n,r){e=Math.max(e,0),s=Math.max(s,0),i=Math.max(i,0);const a=s+i>n?s*n/(s+i):s,o=s+i>n?i*n/(s+i):i;let l=a/r,h=o/r;if(l+h>e){const u=e/(l+h);l*=u,h*=u}t[0]=0,t[1]=l,t[2]=0,t[3]=a,t[4]=l,t[5]=e-l-h,t[6]=a,t[7]=n-a-o,t[8]=e-h,t[9]=h,t[10]=n-o,t[11]=o}var ae=new Float64Array(5);function Fr(t,e,s,i,n,r){var a,o,l,h,u,f,d,g,p,v,m;const x=ae,b=x[0],w=x[1],A=x[2],T=x[3],F=x[4],P=t.tex(e.surface),E=i===0?(a=e.slice)!=null?a:0:i;if(E===0){const D=((o=e.sw)!=null?o:e.w)/e.scale-e.margin*2,V=((l=e.sh)!=null?l:e.h)/e.scale-e.margin*2,J=D>0?b/D:1,Q=V>0?w/V:1,K=-A*b+(((h=e.tx)!=null?h:0)/e.scale-e.margin)*J,Y=-T*w+(((u=e.ty)!=null?u:0)/e.scale-e.margin)*Q;Ge(s,K,Y),j[0]=e.w/e.scale*J,j[1]=e.h/e.scale*Q,j[2]=F,t.r.quadQ(P,e,et,n,r);return}const I=(f=e.tx)!=null?f:0,B=(d=e.ty)!=null?d:0,N=((g=e.sw)!=null?g:e.w)-e.w-I,G=((p=e.sh)!=null?p:e.h)-e.h-B,z=-A*b-e.margin+I/e.scale,U=-T*w-e.margin+B/e.scale;if(Ri(ne,b+e.margin*2-(I+N)/e.scale,(typeof E=="number"?E:E[3])-I,(typeof E=="number"?E:E[1])-N,e.w,e.scale),Ri(re,w+e.margin*2-(B+G)/e.scale,(typeof E=="number"?E:E[0])-B,(typeof E=="number"?E:E[2])-G,e.h,e.scale),Ge(s,z,U),j[2]=F,!((m=(v=t.r).nineQ)!=null&&m.call(v,P,e,ne,re,et,n,r)))for(let D=0;D<12;D+=4){const V=re[D+1],J=re[D+3];if(!(V<=0||J<=0))for(let Q=0;Q<12;Q+=4){const K=ne[Q+1],Y=ne[Q+3];K<=0||Y<=0||(we.x=e.x+ne[Q+2],we.y=e.y+re[D+2],we.w=Y,we.h=J,Ge(s,z+ne[Q],U+re[D]),j[0]=K,j[1]=V,j[2]=F,t.r.quadQ(P,we,et,n,r))}}}function Ge(t,e,s){et[0]=t[0],et[1]=t[1],et[2]=t[2],et[3]=t[3],et[4]=t[0]*e+t[2]*s+t[4],et[5]=t[1]*e+t[3]*s+t[5]}var xe=class extends ie{constructor(t,e,s={}){super(t,null),c(this,"_spec"),c(this,"baked",null),c(this,"bakedEffects",!0),this._spec=e,this.bake(),s.anchor===void 0&&this.useFrameAnchor(),this.set(s)}get spec(){return this._spec}set spec(t){this._spec=t,this.baked=null,this._w=this._h=null,this.bake()}bake(){const t=this.kernel;return this.baked&&t.atlas.valid(this.baked.frame)&&this.baked.frame.scale===t.pixelScale&&this.bakedEffects===t.effects?this.baked:(this.bakedEffects=t.effects,this.baked=t.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 t,e;const s=this.bake();ae[0]=(t=this._w)!=null?t:s.w,ae[1]=(e=this._h)!=null?e:s.h}get width(){var t;return(t=this._w)!=null?t:this.bake().w}set width(t){this._w=t}get height(){var t;return(t=this._h)!=null?t:this.bake().h}set height(t){this._h=t}},Fi=(t,e,s)=>t===void 0?e:typeof t=="number"?t:t[0]+(t[1]-t[0])*s(),Pi=class Ce extends Wt{constructor(e,s,i={}){var n,r,a,o;super(e),c(this,"max"),c(this,"f"),c(this,"tints"),c(this,"count",0),c(this,"gravity"),c(this,"drag"),c(this,"frameRef"),c(this,"random",Math.random),this.frameRef=s,this.max=Math.max(1,Math.floor((n=i.max)!=null?n:200)),this.f=new Float32Array(this.max*Ce.W),this.tints=new Uint32Array(this.max),this.blend=(r=i.blend)!=null?r:"normal",this.gravity=(a=i.gravity)!=null?a:0,this.drag=(o=i.drag)!=null?o:1}get alive(){return this.count}burst(e,s,i,n={}){var r,a,o,l,h;const u=Ce.W,f=this.random,d=n.tint===void 0?16777215:xt(n.tint)[0];for(let g=0;g<i;g++){let p=this.count;if(p>=this.max){let A=0,T=1/0;for(let F=0;F<this.max;F++){const P=this.f[F*u+5]-this.f[F*u+4];P<T&&(T=P,A=F)}p=A}else this.count++;const v=((r=n.angle)!=null?r:0)+(n.spread===void 0?f()*Math.PI*2:(f()-.5)*n.spread),m=Fi(n.speed,200,f),x=Array.isArray(n.scale)?n.scale[0]:(a=n.scale)!=null?a:1,b=Array.isArray(n.scale)?n.scale[1]:(o=n.scale)!=null?o:1,w=p*u;this.f[w]=e,this.f[w+1]=s,this.f[w+2]=Math.cos(v)*m,this.f[w+3]=Math.sin(v)*m,this.f[w+4]=0,this.f[w+5]=Math.max(Fi(n.life,.8,f),.01),this.f[w+6]=f()*Math.PI*2,this.f[w+7]=(f()-.5)*2*((l=n.spin)!=null?l:0),this.f[w+8]=x,this.f[w+9]=b,this.f[w+10]=(h=n.alpha)!=null?h:1,this.tints[p]=d}}update(e){const s=Ce.W,i=this.f,n=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let r=0;r<this.count;){const a=r*s;if(i[a+4]=i[a+4]+e,i[a+4]>=i[a+5]){const o=--this.count;r!==o&&(i.copyWithin(a,o*s,o*s+s),this.tints[r]=this.tints[o]);continue}i[a+3]=(i[a+3]+this.gravity*e)*n,i[a+2]=i[a+2]*n,i[a]=i[a]+i[a+2]*e,i[a+1]=i[a+1]+i[a+3]*e,i[a+6]=i[a+6]+i[a+7]*e,r++}}clear(){this.count=0}draw(e,s,i){if(!this.count)return;const n=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,r=Ce.W,a=this.f,o=this.world,l=n.w/n.scale,h=n.h/n.scale;for(let u=0;u<this.count;u++){const f=u*r,d=a[f+4]/a[f+5],g=a[f+8]+(a[f+9]-a[f+8])*d,p=s*a[f+10]*(1-d*d),v=a[f+6],m=Math.cos(v)*g,x=Math.sin(v)*g,b=a[f],w=a[f+1],A=o[0],T=o[1],F=o[2],P=o[3],E=A*m+F*x,I=T*m+P*x,B=F*m-A*x,N=P*m-T*x;et[0]=E,et[1]=I,et[2]=B,et[3]=N,et[4]=A*b+F*w+o[4]-(E*l+B*h)/2,et[5]=T*b+P*w+o[5]-(I*l+N*h)/2,j[0]=l,j[1]=h,j[2]=p,e.r.quadQ(e.tex(n.surface),n,et,xi(i,this.tints[u]),this.blend)}}};c(Pi,"W",11);var Ci=Pi,Yt=class extends ie{constructor(t,e,s={}){const i=s,{fps:n,loop:r,playing:a,speed:o,onComplete:l}=i,h=ys(i,["fps","loop","playing","speed","onComplete"]);if(!e.frames.length)throw new Error("[engine] an animation needs at least one frame");super(t,e.frames[0],h),c(this,"frames"),c(this,"durations"),c(this,"fps"),c(this,"loop"),c(this,"speed"),c(this,"onComplete"),c(this,"_playing"),c(this,"index",0),c(this,"t",0),this.frames=e.frames,this.durations=e.durations&&n===void 0?e.durations:null,this.fps=n!=null?n:12,this.loop=r!==!1,this.speed=o!=null?o:1,this.onComplete=l!=null?l:null,this._playing=a!==!1,this.speed<0&&this.show(e.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(t){const e=this.frames.length;return this.show((Math.floor(t)%e+e)%e),this.t=0,this}gotoAndPlay(t){return this._playing=!0,this.gotoFrame(t)}gotoAndStop(t){return this._playing=!1,this.gotoFrame(t)}show(t){t===this.index&&this._frame||(this.index=t,this.frame=this.frames[t])}secondsOf(t){var e;const s=(e=this.durations)==null?void 0:e[t];return s!==void 0&&s>0?s:1/Math.max(this.fps,.001)}update(t){var e;if(!this._playing||this.destroyed||this.speed===0)return;const s=this.frames.length,i=this.speed<0;this.t+=t*Math.abs(this.speed);let n=this.index;for(let r=0;r<1e3;r++){const a=this.secondsOf(n);if(this.t<a)break;this.t-=a;const o=i?n-1:n+1;if(o<0||o>=s){if(!this.loop){this.t=0,this._playing=!1,this.show(n),(e=this.onComplete)==null||e.call(this);return}n=i?s-1:0}else n=o}this.show(n)}},Pr=(t,e)=>t.localeCompare(e,void 0,{numeric:!0}),Ni=class{constructor(t,e,s=2){c(this,"width",t),c(this,"height",e),c(this,"padding",s),c(this,"shelves",[]),c(this,"free",[]),c(this,"bottom",0)}alloc(t,e){const s=Math.ceil(t)+this.padding*2,i=Math.ceil(e)+this.padding*2;if(s>this.width||i>this.height)return null;for(let a=0;a<this.free.length;a++){const o=this.free[a];if(o.w>=s&&o.h>=i&&o.w*o.h<=s*i*2)return this.free.splice(a,1),fe(Mt({},this.inner(o.x,o.y,t,e)),{slot:o})}let n=null;for(const a of this.shelves)a.h>=i&&a.h<=i*1.5+8&&this.width-a.x>=s&&(!n||a.h<n.h)&&(n=a);if(!n)if(this.bottom+i>this.height){for(const a of this.shelves)a.h>=i&&this.width-a.x>=s&&(n=a);if(!n)return null}else n={y:this.bottom,h:i,x:0},this.shelves.push(n),this.bottom+=i;const r=n.x;return n.x+=s,this.inner(r,n.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,s,i){return{x:t+this.padding,y:e+this.padding,w:s,h:i}}},Xe=t=>({source:t,texture:null,pending:[]}),Ns=class{constructor(t=2048,e=4){c(this,"pageSize",t),c(this,"maxPages",e),c(this,"pages",[]),c(this,"gen",1),c(this,"onPage",()=>{}),c(this,"onDrop",()=>{})}valid(t){return!!t&&(t.gen===this.gen||t.gen===0)}bake(t,e,s,i=1,n=0,r=0,a=0){const o=Math.max(1,Math.ceil(t)),l=Math.max(1,Math.ceil(e)),h=document.createElement("canvas");h.width=o,h.height=l;const u=h.getContext("2d");return s(u),this.put(h,o,l,i,n,r,a)}add(t,e=1,s=0,i=0){const n=document.createElement("canvas");return n.width=Math.max(1,t.width),n.height=Math.max(1,t.height),n.getContext("2d").drawImage(t,0,0),this.put(n,n.width,n.height,e,s,i,0)}release(t){if(t.gen!==this.gen)return;const e=this.pages.find(s=>s.surface===t.surface);e==null||e.packer.release(t)}rebake(t,e,s,i,n=t.w,r=t.h){if(!this.valid(t)||e>n||s>r)return null;const a=Math.max(1,Math.ceil(e)),o=Math.max(1,Math.ceil(s)),l=this.pages.find(u=>u.surface===t.surface);if(!l)return null;const h=document.createElement("canvas");return h.width=Math.ceil(n),h.height=Math.ceil(r),i(h.getContext("2d")),l.ctx.clearRect(t.x,t.y,h.width,h.height),l.ctx.drawImage(h,t.x,t.y),t.surface.pending.push([h,t.x,t.y]),t.w=a,t.h=o,t}put(t,e,s,i,n,r,a){let o=null,l=this.pages.find(u=>(o=u.packer.alloc(e,s))!==null);if(l||(!(Math.max(e,s)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),l=this.pages[0],o=l?l.packer.alloc(e,s):null),(!l||!o)&&(l=this.newPage(Math.max(e,s)),o=l.packer.alloc(e,s))),!o)throw new Error("[engine] ".concat(e,"\xD7").concat(s," does not fit an atlas page"));const h=o;if(h.slot){const u=h.slot;l.ctx.clearRect(u.x,u.y,u.w,u.h);const f=document.createElement("canvas");f.width=u.w,f.height=u.h,f.getContext("2d").drawImage(t,h.x-u.x,h.y-u.y),l.surface.pending.push([f,u.x,u.y])}else l.surface.pending.push([t,h.x,h.y]);return l.ctx.drawImage(t,h.x,h.y),{surface:l.surface,x:h.x,y:h.y,w:e,h:s,scale:i,gen:this.gen,ox:n,oy:r,margin:a}}newPage(t){let e=this.pageSize;for(;e<t+4;)e*=2;const s=document.createElement("canvas");s.width=s.height=e;const i=s.getContext("2d"),n=Xe(s),r={surface:n,packer:new Ni(e,e),ctx:i};return this.pages.push(r),this.onPage(n),r}wipe(){this.gen++;let t=0;for(let e=0;e<this.pages.length;e++){const s=this.pages[e];if(t<this.maxPages&&s.surface.source.width===this.pageSize){this.pages[t++]=s;continue}s.surface.pending=[],this.onDrop(s.surface)}this.pages.length=t;for(const 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])}},Cr=()=>Pt.FabiPlay,Nr=class{constructor(){c(this,"amount",.5)}setLocal(t){this.amount=t?.8:.5}get defaultAmount(){return this.amount}posed(t,e,s,i=!0){var n,r;const a={id:t,body:e};return(r=(n=Cr())==null?void 0:n.smoothedBody(a,{smooth:s<1?s:!1,interpolate:i}))!=null?r:e}},Ii=new Float64Array(1),Li=new Int32Array(Ii.buffer),oe=(t,e)=>(t=Math.imul(t^e,1540483477),t^t>>>15);function Nt(t,e=2538058380){return t!==t?oe(e,2146959360):(Ii[0]=t===0?0:t,oe(oe(e,Li[0]),Li[1]))}function Oi(t,e=2166136261){for(let s=0;s<t.length;s++)e=Math.imul(e^t.charCodeAt(s),16777619);return e}function It(t){switch(typeof t){case"number":return Nt(t);case"string":return Oi(t);case"boolean":return t?1013904242:461845907;case"object":{if(t===null)return 625341585;if(Array.isArray(t)||t instanceof Float64Array){let i=1779033703^t.length;for(let n=0;n<t.length;n++){const r=t[n];i=oe(i,typeof r=="number"?Nt(r):It(r))}return i}let e=1359893119;const s=t;for(const i in s){const n=s[i];n!==void 0&&(e=e+oe(Oi(i),It(n))|0)}return oe(e,2600822924)}default:return 0}}function be(t,e){if(t===e)return!0;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return typeof t=="number"&&typeof e=="number"&&t!==t&&e!==e;const s=Array.isArray(t)||t instanceof Float64Array;if(s!==(Array.isArray(e)||e instanceof Float64Array))return!1;if(s){const r=t,a=e;if(r.length!==a.length)return!1;for(let o=0;o<r.length;o++)if(r[o]!==a[o]&&!be(r[o],a[o]))return!1;return!0}const i=t,n=e;for(const r in i)if(i[r]!==void 0&&!be(i[r],n[r]))return!1;for(const r in n)if(n[r]!==void 0&&i[r]===void 0)return!1;return!0}function He(t){if(typeof t!="object"||t===null)return t;if(Array.isArray(t))return t.map(He);if(t instanceof Float64Array)return t.slice();const e={};for(const s in t)t[s]!==void 0&&(e[s]=He(t[s]));return e}var Di=class{constructor(t=1/0){c(this,"max",t),c(this,"buckets",new Map),c(this,"n",0)}get size(){return this.n}get(t,e=It(t)){const s=this.buckets.get(e);if(s){for(let i=0;i<s.length;i++)if(be(s[i].key,t))return s[i].value}}set(t,e,s=It(t)){let i=this.buckets.get(s);if(i){for(const n of i)if(be(n.key,t)){n.value=e;return}}this.n>=this.max&&this.clear(),(!i||!this.buckets.has(s))&&this.buckets.set(s,i=[]),i.push({key:He(t),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}},Is=0,Ui=1,qe=2,Ls=3,Bi=class{constructor(){c(this,"scale",1),c(this,"cOn",!1),c(this,"px0",0),c(this,"py0",0),c(this,"px1",0),c(this,"py1",0),c(this,"clipVer",0),c(this,"stack",[]),c(this,"sp",0),c(this,"real",0),c(this,"mute",0),c(this,"bnd",new Float64Array(4*(Ts+1))),c(this,"rx0",0),c(this,"ry0",0),c(this,"rx1",0),c(this,"ry1",0),c(this,"maxBlur",1/0),c(this,"time",0),c(this,"skipped",0),c(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(){const t=this.gq;this.grow(t[0],t[1],t[2],t[3])}grow(t,e,s,i){if(!this.real)return;const n=this.bnd,r=(this.real-1)*4;t<n[r]&&(n[r]=t),e<n[r+1]&&(n[r+1]=e),s>n[r+2]&&(n[r+2]=s),i>n[r+3]&&(n[r+3]=i)}area(t,e){const s=this.bnd,i=t*4,n=this.scale;return this.rx0=Math.max(Math.floor((s[i]-e)*n)-1,0),this.ry0=Math.max(Math.floor((s[i+1]-e)*n)-1,0),this.rx1=Math.min(Math.ceil((s[i+2]+e)*n)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((s[i+3]+e)*n)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(t,e,s,i){const n=this.scale,r=this.canvas.width,a=this.canvas.height,o=Math.min(Math.max(Math.round(t*n),0),r),l=Math.min(Math.max(Math.round(e*n),0),a),h=Math.min(Math.max(Math.round((t+s)*n),o),r),u=Math.min(Math.max(Math.round((e+i)*n),l),a);this.cOn&&o===this.px0&&l===this.py0&&h===this.px1&&u===this.py1||(this.cOn=!0,this.px0=o,this.py0=l,this.px1=h,this.py1=u,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(t){if(t<qe&&(this.mute||this.real>=Ts||!this.pushLayer())&&(t+=2),t===Ls)this.mute++;else if(t!==qe){const 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<qe}beginLayer(){return this.push(Is)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===Is?Ui:Ls)}endLayer(t,e){if(!this.sp)return;let s=this.stack[--this.sp];if(s===Ls){if(this.mute--,!this.sp)return;s=this.stack[--this.sp]}if(s===Ui){const i=--this.real,n=this.popLayer();this.area(i-1,0)&&this.composite(n,!0,1,null);const r=this.bnd,a=(i-1)*4,o=i*4;r[a]=Math.max(r[a],r[o]),r[a+1]=Math.max(r[a+1],r[o+1]),r[a+2]=Math.min(r[a+2],r[o+2]),r[a+3]=Math.min(r[a+3],r[o+3]),s=this.stack[--this.sp]}if(s===qe)Ss(e)&&(this.skipped+=e.length);else if(s===Is){const i=--this.real,n=Ss(e)?e:null,r=this.popLayer();if(this.area(i,n?Sr(n,this.maxBlur):0)){this.composite(r,!1,t,n);const a=this.scale;this.grow(this.rx0/a,this.ry0/a,this.rx1/a,this.ry1/a)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}},Ir=256,zi=8<<20,ct=new Float64Array(32),ut={x:0,y:0,w:0,h:0};function Lr(t){if(typeof t.filter!="string")return!1;t.filter="blur(1px)";const e=t.filter==="blur(1px)";return t.filter="none",e}function Os(t){const e=t.getContext("2d",{alpha:!0});return e?new Or(t,e):null}var Or=class extends Bi{constructor(t,e){super(),c(this,"canvas",t),c(this,"ctx",e),c(this,"kind","canvas2d"),c(this,"maxTextureSize",4096),c(this,"features",{}),c(this,"info",{renderer:"canvas2d"}),c(this,"support"),c(this,"lost",!1),c(this,"fxr",null),c(this,"quads",0),c(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),c(this,"tinted",new Map),c(this,"tintedN",0),c(this,"lostListeners",[]),c(this,"restoredListeners",[]),c(this,"base"),c(this,"top"),c(this,"layers",[]),c(this,"scratch",[]),c(this,"nines",new Map),c(this,"ninePx",0),c(this,"frame",0),c(this,"hit",!1),c(this,"missed",new Map),this.support={filters:Lr(e),shaders:!1},this.base=this.top={ctx:e,clipped:!1,ver:0},t.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(s=>s())}),t.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(s=>s())})}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){return{id:Rs(),width:t.width,height:t.height,source:t}}updateTexture(t,e,s=0,i=0){const n=e?s+e.width:1/0,r=e?i+e.height:1/0;for(const a of this.nines.values()){const o=a.key;o[0]===t.id&&o[1]<n&&o[1]+o[3]>s&&o[2]<r&&o[2]+o[4]>i&&this.dropNine(a)}for(const[a,o]of this.tinted){const l=o.filter(h=>h.id!==t.id);this.tintedN-=o.length-l.length,l.length?this.tinted.set(a,l):this.tinted.delete(a)}}destroyTexture(t){this.updateTexture(t)}begin(t,e,s){var i;this.resetLayers(s),(i=this.fxr)==null||i.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;const n=this.ctx;this.base.clipped&&n.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,n.setTransform(1,0,0,1,0,0),n.globalAlpha=1,n.globalCompositeOperation="source-over",n.clearRect(0,0,this.canvas.width,this.canvas.height),e>0&&(n.fillStyle=ge(t,e),n.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(t,e,s,i,n,r,a,o){j[0]=i,j[1]=n,j[2]=a,this.quadQ(t,e,s,r,o)}quadQ(t,e,s,i,n){e.w<=0||e.h<=0||(i===16777215?this.blit(t.source,e.x,e.y,e.w,e.h,s,n):this.blit(this.tint(t,e,i),0,0,e.w,e.h,s,n))}blit(t,e,s,i,n,r,a){const o=j[0],l=j[1],h=j[2];if(h<=0||this.mute)return;this.sync();const u=this.ctx,f=this.scale;if(this.real){const d=r[0]*o,g=r[1]*o,p=r[2]*l,v=r[3]*l;this.grow(r[4]+Math.min(0,d,p,d+p),r[5]+Math.min(0,g,v,g+v),r[4]+Math.max(0,d,p,d+p),r[5]+Math.max(0,g,v,g+v))}u.setTransform(r[0]*f,r[1]*f,r[2]*f,r[3]*f,r[4]*f,r[5]*f),u.globalAlpha=Math.min(h,1),a==="add"&&(u.globalCompositeOperation="lighter"),u.drawImage(t,e,s,i,n,0,0,o,l),a==="add"&&(u.globalCompositeOperation="source-over"),this.quads++}nineQ(t,e,s,i,n,r,a){var o,l,h;const u=s[8]+s[9],f=i[8]+i[9],d=Math.ceil(u*Math.hypot(n[0],n[1])*this.scale-1e-6),g=Math.ceil(f*Math.hypot(n[2],n[3])*this.scale-1e-6);if(n[1]===0&&n[2]===0||d>4096||g>4096)return!1;if(!(d>0&&g>0&&j[2]>0)||this.mute)return!0;let p=this.kept(t,e,s,i,d,g,r);const v=(p!=null?p:p=(h=(o=this.scratch)[l=13*Math.ceil(Math.log2(d))+Math.ceil(Math.log2(g))])!=null?h:o[l]=document.createElement("canvas").getContext("2d")).canvas;if(v.width<d&&(v.width=d),v.height<g&&(v.height=g),!this.hit){p.clearRect(0,0,d+2,g+2);for(let m=0;m<12;m+=4){const x=Math.round(i[m]*g/f),b=Math.round((i[m]+i[m+1])*g/f);for(let w=0;w<12;w+=4){const A=Math.round(s[w]*d/u),T=Math.round((s[w]+s[w+1])*d/u);ut.x=e.x+s[w+2],ut.y=e.y+i[m+2],ut.w=s[w+3],ut.h=i[m+3],!(T<=A||b<=x||ut.w<=0||ut.h<=0)&&(r===16777215?p.drawImage(t.source,ut.x,ut.y,ut.w,ut.h,A,x,T-A,b-x):p.drawImage(this.tint(t,ut,r),0,0,ut.w,ut.h,A,x,T-A,b-x))}}}return j[0]=u,j[1]=f,this.blit(v,0,0,d,g,n,a),!0}kept(t,e,s,i,n,r,a){ct[0]=t.id,ct[1]=e.x,ct[2]=e.y,ct[3]=e.w,ct[4]=e.h,ct[5]=n,ct[6]=r,ct[7]=a,ct.set(s,8),ct.set(i,20);const o=It(ct),l=this.nines.get(o);if(this.hit=!1,l)return be(l.key,ct)?(l.used=this.frame,this.hit=!0,l.ctx):null;const h=this.missed,u=h.get(o);h.size>4096&&h.clear(),h.set(o,this.frame);const f=n*r;if(u!==this.frame-1||f>zi)return null;let d;for(;this.ninePx+f>zi;){let v;for(const b of this.nines.values())b.used<this.frame-1&&!(v&&v.used<=b.used)&&(v=b);if(!v)return null;const m=v.ctx.canvas,x=!d&&m.width>=n&&m.height>=r&&m.width*m.height<=2*f;this.dropNine(v,x),x&&(d=v.ctx)}const g=d!=null?d:document.createElement("canvas").getContext("2d"),p=g.canvas;return d||(p.width=n,p.height=r),this.ninePx+=p.width*p.height,this.nines.set(o,{key:He(ct),ctx:g,used:this.frame}),g}dropNine(t,e=!1){this.nines.delete(It(t.key));const s=t.ctx.canvas;this.ninePx-=s.width*s.height,e||(s.width=0)}dropNines(){for(const t of this.nines.values())this.dropNine(t)}tint(t,e,s){const i=Nt(s,Nt(e.h,Nt(e.w,Nt(e.y,Nt(e.x,Nt(t.id))))));let n=this.tinted.get(i);if(n)for(let o=0;o<n.length;o++){const l=n[o];if(l.id===t.id&&l.x===e.x&&l.y===e.y&&l.w===e.w&&l.h===e.h&&l.color===s)return l.canvas}this.tintedN>=Ir&&(this.tinted.clear(),this.tintedN=0,n=void 0);const r=document.createElement("canvas");r.width=Math.ceil(e.w),r.height=Math.ceil(e.h);const a=r.getContext("2d");return a.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),a.globalCompositeOperation="multiply",a.fillStyle=ge(s),a.fillRect(0,0,e.w,e.h),a.globalCompositeOperation="destination-in",a.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),n||this.tinted.set(i,n=[]),n.push({id:t.id,x:e.x,y:e.y,w:e.w,h:e.h,color:s,canvas:r}),this.tintedN++,r}paint(t,e){this.sync();const s=this.ctx,i=this.scale;return s.setTransform(i,0,0,i,0,0),s.globalAlpha=Math.min(e,1),ge(t)}ellipse(t,e,s,i,n,r,a){if(a<=0||s<=0||i<=0||this.mute)return;const o=Math.max(s,i);this.grow(t-o,e-o,t+o,e+o);const l=this.ctx;l.fillStyle=this.paint(r,a),l.beginPath(),l.ellipse(t,e,s,i,n,0,Math.PI*2),l.fill(),this.quads++}trace(t,e,s=0){if(this.real)for(let n=0;n<e;n++)this.grow(t[n*2]-s,t[n*2+1]-s,t[n*2]+s,t[n*2+1]+s);const i=this.ctx;i.beginPath(),i.moveTo(t[0],t[1]);for(let n=1;n<e;n++)i.lineTo(t[n*2],t[n*2+1])}polygon(t,e,s,i){if(i<=0||e<3||this.mute)return;const n=this.ctx;n.fillStyle=this.paint(s,i),this.trace(t,e),n.closePath(),n.fill(),this.quads++}stroke(t,e,s,i,n,r){if(n<=0||s<=0||e<1||this.mute)return;const a=this.ctx;a.strokeStyle=this.paint(i,n),a.lineWidth=s,a.lineCap="round",a.lineJoin="round",this.trace(t,e,s/2),e===1&&a.lineTo(t[0],t[1]),r&&a.closePath(),a.stroke(),this.quads++}sync(){const t=this.top;if(t.ver===this.clipVer)return;const e=t.ctx;t.clipped&&e.restore(),t.clipped=this.cOn,t.ver=this.clipVer,this.cOn&&(e.save(),e.setTransform(1,0,0,1,0,0),e.beginPath(),e.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),e.clip())}pushLayer(){const t=this.canvas.width,e=this.canvas.height;let s=this.layers[this.real];if(!s||s.ctx.canvas.width!==t||s.ctx.canvas.height!==e){const n=document.createElement("canvas");n.width=t,n.height=e;const r=n.getContext("2d");if(!r)return!1;s=this.layers[this.real]={ctx:r,clipped:!1,ver:-1}}const 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,t,e),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(t,e,s,i){var n;let r=t,a="none";const o=i&&bt.c2d?(n=this.fxr)!=null?n:this.fxr=bt.c2d(this):null;o&&(r=o.chain(t,i),a=o.css),this.sync();const l=this.ctx,h=this.rx0,u=this.ry0,f=this.rx1-h,d=this.ry1-u;l.setTransform(1,0,0,1,0,0),l.globalAlpha=Math.min(s,1),l.globalCompositeOperation=e?"destination-in":"source-over",a!=="none"&&(l.filter=a),l.drawImage(r,h,u,f,d,h,u,f,d),a!=="none"&&(l.filter="none"),l.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();const t=this.stats;return t.drawCalls=t.quads=this.quads,t.filtersSkipped=this.skipped,t}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){var t;this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],(t=this.fxr)==null||t.destroy(),this.fxr=null}},_e=14,le=6,Gi=8192,Dr=class{constructor(t,e,s=Gi){c(this,"instanced",t),c(this,"slots",e),c(this,"capacity",s),c(this,"f32"),c(this,"u32"),c(this,"quads",0),c(this,"textures"),c(this,"bound",0),this.textures=new Array(e).fill(null);const i=s*(t?_e:le*4),n=new ArrayBuffer(i*4);this.f32=new Float32Array(n),this.u32=new Uint32Array(n)}slot(t){const e=this.textures;for(let s=0;s<this.bound;s++)if(e[s]===t)return s;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?_e:le*4)}reset(){this.quads=0;for(let t=0;t<this.bound;t++)this.textures[t]=null;this.bound=0}push(t,e,s,i,n,r,a,o,l,h,u,f,d,g){const p=this.f32;if(this.instanced){let v=this.quads*_e;p[v++]=t,p[v++]=e,p[v++]=s,p[v++]=i,p[v++]=n,p[v++]=r,p[v++]=a,p[v++]=o,p[v++]=l,p[v++]=h,p[v++]=u,p[v++]=f,this.u32[v++]=d,p[v]=g}else{const v=this.quads*le*4;this.vertex(v,t,e,l,h,d,g),this.vertex(v+6,s,i,u,h,d,g),this.vertex(v+12,n,r,u,f,d,g),this.vertex(v+18,a,o,l,f,d,g)}this.quads++}pushQ(t,e){const s=this.f32;if(this.instanced){const i=this.quads*_e;for(let n=0;n<12;n++)s[i+n]=t[n];this.u32[i+12]=t[12],s[i+13]=e}else{let i=this.quads*le*4;const n=t[12];for(let r=0;r<4;r++,i+=le)s[i]=t[r*2],s[i+1]=t[r*2+1],s[i+2]=r===1||r===2?t[10]:t[8],s[i+3]=r>=2?t[11]:t[9],this.u32[i+4]=n,s[i+5]=e}this.quads++}vertex(t,e,s,i,n,r,a){const o=this.f32;o[t]=e,o[t+1]=s,o[t+2]=i,o[t+3]=n,this.u32[t+4]=r,o[t+5]=a}};function Ur(t){const e=new Uint16Array(t*6);for(let s=0,i=0,n=0;s<t;s++,i+=6,n+=4)e[i]=n,e[i+1]=n+1,e[i+2]=n+2,e[i+3]=n,e[i+4]=n+2,e[i+5]=n+3;return e}var ft={M:0,L:1,Q:2,C:3,Z:4},Xi=[2,2,4,6,0],Br={M:0,L:1,Q:2,C:3,Z:4};function Ds(t,e){if(t.length>=e)return t;const s=new Float64Array(Math.max(e,t.length*2,16));return s.set(t),s}var We=new Map;function zr(t){var e,s;if(typeof t!="string")return t;let i=We.get(t);if(i)return i;i=[];const n=(e=t.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi))!=null?e:[];let r=-1;for(let a=0;a<n.length;){const o=n[a],l=Br[o.toUpperCase()];if(l!==void 0){r=l,a++,l===ft.Z&&i.push(ft.Z);continue}if(r<0||r===ft.Z){a++;continue}const h=Xi[r];i.push(r);for(let u=0;u<h;u++)i.push(Number((s=n[a+u])!=null?s:0));a+=h,r===ft.M&&(r=ft.L)}return We.size>256&&We.clear(),We.set(t,i),i}var Lt={subs:[],count:0},Us=null,Ot=null;function je(t,e){var s;let i=Ot;i||(i=(s=Lt.subs[Lt.count])!=null?s:null,i||Lt.subs.push(i={pts:new Float64Array(64),n:0,closed:!1}),i.n=0,i.closed=!1,Lt.count++,Ot=i);const n=i.n*2;n+2>i.pts.length&&(i.pts=Ds(i.pts,n+2));const r=Us;r?(i.pts[n]=r[0]*t+r[2]*e+r[4],i.pts[n+1]=r[1]*t+r[3]*e+r[5]):(i.pts[n]=t,i.pts[n+1]=e),i.n++}function Bs(t,e=null,s=1,i=6){const n=zr(t);Lt.count=0,Ot=null,Us=e;let r=0,a=0,o=0,l=0;const h=s/i;for(let u=0;u<n.length;){const f=n[u++],d=n;if(f===ft.M)Ot=null,r=o=d[u],a=l=d[u+1],je(r,a);else if(f===ft.L)r=d[u],a=d[u+1],je(r,a);else if(f===ft.Q){const g=d[u],p=d[u+1],v=d[u+2],m=d[u+3],x=Hi((kt(g-r,p-a)+kt(v-g,m-p))*h);for(let b=1;b<=x;b++){const w=b/x,A=1-w;je(A*A*r+2*A*w*g+w*w*v,A*A*a+2*A*w*p+w*w*m)}r=v,a=m}else if(f===ft.C){const g=d[u],p=d[u+1],v=d[u+2],m=d[u+3],x=d[u+4],b=d[u+5],w=Hi((kt(g-r,p-a)+kt(v-g,m-p)+kt(x-v,b-m))*h);for(let A=1;A<=w;A++){const T=A/w,F=1-T,P=F*F*F,E=3*F*F*T,I=3*F*T*T,B=T*T*T;je(P*r+E*g+I*v+B*x,P*a+E*p+I*m+B*b)}r=x,a=b}else if(f===ft.Z){Ot&&(Ot.closed=!0),Ot=null,r=o,a=l;continue}else break;u+=Xi[f]}Ot=null,Us=null;for(let u=0;u<Lt.count;u++){const f=Lt.subs[u],d=f.n*2;f.closed&&f.n>=2&&Math.abs(f.pts[0]-f.pts[d-2])<1e-6&&Math.abs(f.pts[1]-f.pts[d-1])<1e-6&&f.n--}return Lt}var kt=(t,e)=>Math.sqrt(t*t+e*e),Hi=t=>Math.min(Math.max(Math.ceil(t),2),24);function Gr(t,e){let s=0;for(let i=0,n=e-1;i<e;n=i++)s+=(t[n*2]-t[i*2])*(t[n*2+1]+t[i*2+1]);return s}var Ye=new Int32Array(64),Ve=(t,e,s,i,n)=>((t[i*2]-t[s*2])*(t[n*2+1]-t[s*2+1])-(t[i*2+1]-t[s*2+1])*(t[n*2]-t[s*2]))*e;function Xr(t,e,s){if(e<3)return 0;Ye.length<e&&(Ye=new Int32Array(Math.max(e,Ye.length*2)));const i=Ye;let n=e,r=0;for(let h=0;h<e;h++)i[h]=h;const a=Gr(t,e)>0?1:-1;let o=e*e+8,l=0;for(;n>3&&o-- >0;){const h=i[(l+n-1)%n],u=i[l%n],f=i[(l+1)%n];let d=Ve(t,a,h,u,f)>0;if(d)for(let g=0;g<n;g++){const p=i[g];if(!(p===h||p===u||p===f)&&Ve(t,a,h,u,p)>=0&&Ve(t,a,u,f,p)>=0&&Ve(t,a,f,h,p)>=0){d=!1;break}}d?(s[r++]=h,s[r++]=u,s[r++]=f,i.copyWithin(l%n,l%n+1,n),n--,l=Math.max(l-1,0)):l=(l+1)%n}if(n===3)s[r++]=i[0],s[r++]=i[1],s[r++]=i[2];else if(n>3)for(let h=1;h+1<n;h++)s[r++]=i[0],s[r++]=i[h],s[r++]=i[h+1];return r}var Hr=.85,Qe=new Float64Array(64),qi=new Float64Array(64),Wi=new Float64Array(64),ji=new Float64Array(64),Yi=new Float64Array(64),Vi=new Float64Array(64),Qi=new Uint8Array(64),Ke=new Float64Array(8);function qr(t,e,s,i,n,r){const a=Ke;if(Qe.length<e){const m=Math.max(e,Qe.length*2);Qe=new Float64Array(m),qi=new Float64Array(m),Wi=new Float64Array(m),ji=new Float64Array(m),Yi=new Float64Array(m),Vi=new Float64Array(m),Qi=new Uint8Array(m)}const o=Qe,l=qi;let h=0;for(let m=0;m<e;m++){const x=t[m*2],b=t[m*2+1];!Number.isFinite(x)||!Number.isFinite(b)||h&&Math.abs(o[h-1]-x)<.001&&Math.abs(l[h-1]-b)<.001||(o[h]=x,l[h]=b,h++)}if(i&&h>2&&Math.abs(o[0]-o[h-1])<.001&&Math.abs(l[0]-l[h-1])<.001&&h--,h===0)return;if(h===1)return a[0]=o[0],a[1]=l[0],r();const u=i?h:h-1,f=Wi,d=ji;for(let m=0;m<u;m++){const x=(m+1)%h,b=o[x]-o[m],w=l[x]-l[m],A=kt(b,w)||1;f[m]=-w/A,d[m]=b/A}const g=Yi,p=Vi,v=Qi;for(let m=0;m<h;m++){const x=i?(m-1+u)%u:m-1,b=m<u?m:-1;if(v[m]=1,x<0||b<0||f[x]*f[b]+d[x]*d[b]<Hr)continue;let A=f[x]+f[b],T=d[x]+d[b];const F=kt(A,T)||1;A/=F,T/=F;const P=s/Math.max(A*f[b]+T*d[b],.5);g[m]=A*P,p[m]=T*P,v[m]=0}for(let m=0;m<u;m++){const x=(m+1)%h,b=v[m]?f[m]*s:g[m],w=v[m]?d[m]*s:p[m],A=v[x]?f[m]*s:g[x],T=v[x]?d[m]*s:p[x];a[0]=o[m]+b,a[1]=l[m]+w,a[2]=o[x]+A,a[3]=l[x]+T,a[4]=o[x]-A,a[5]=l[x]-T,a[6]=o[m]-b,a[7]=l[m]-w,n()}for(let m=0;m<h;m++)v[m]&&(a[0]=o[m],a[1]=l[m],r())}function Ki(t,e){let s=0,i=1/0;for(let n=0;n<e.length;n++){const r=Math.abs(Math.log(Math.max(t,.5)/e[n]));r<i&&(i=r,s=n)}return s}var gt=256,zs=[{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}],Gs=[4,8,16,32,64,128].map((t,e)=>({x:e*4,y:128,w:4,h:t,r:t/2-1})),Dt={x:248,y:248,w:8,h:8},Wr=zs.map(t=>t.r*2),jr=Gs.map(t=>t.r*2),Zi=(t,e)=>Math.min(Math.max(t+.5-e,0),1);function Yr(){const t=new Uint8ClampedArray(gt*gt*4),e=(s,i,n)=>{const r=(i*gt+s)*4;t[r]=t[r+1]=t[r+2]=255,t[r+3]=Math.round(n*255)};for(const s of zs){const i=s.w/2;for(let n=0;n<s.h;n++)for(let r=0;r<s.w;r++)e(s.x+r,s.y+n,Zi(s.r,Math.hypot(r+.5-i,n+.5-i)))}for(const s of Gs){const i=s.h/2;for(let n=0;n<s.h;n++)for(let r=0;r<s.w;r++)e(s.x+r,s.y+n,Zi(s.r,Math.abs(n+.5-i)))}for(let s=0;s<Dt.h;s++)for(let i=0;i<Dt.w;i++)e(Dt.x+i,Dt.y+s,1);return t}function Vr(){const t=document.createElement("canvas");return t.width=t.height=gt,t.getContext("2d").putImageData(new ImageData(Yr(),gt,gt),0,0),t}var Ji=8,Xs="\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n",Qr=t=>"".concat(Xs,"\nuniform sampler2D uTex[").concat(t,"];\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSlot;\nvoid main() {\n vec4 c;\n ").concat(Array.from({length:t},(e,s)=>s===t-1?"c = texture2D(uTex[".concat(s,"], vUv);"):"if (vSlot < ".concat(s,".5) c = texture2D(uTex[").concat(s,"], vUv); else ")).join("\n "),"\n gl_FragColor = c * vColor;\n}"),Kr="\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}",Zr="\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}",Jr={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},$r=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],ta=["aPos","aUv","aColor","aSlot"];function ea(t,e,s={}){var i,n;const r=fe(Mt({},Jr),{failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat!==!1}),a=e===2?t.getContext("webgl2",r):(i=t.getContext("webgl",r))!=null?i:t.getContext("experimental-webgl",r);if(!a||a.isContextLost())return null;try{return new sa(t,a,e,s)}catch(o){return console.warn("[engine] WebGL setup failed:",o),(n=a.getExtension("WEBGL_lose_context"))==null||n.loseContext(),null}}var sa=class extends Bi{constructor(t,e,s,i){super(),c(this,"canvas",t),c(this,"gl",e),c(this,"opts",i),c(this,"kind"),c(this,"maxTextureSize"),c(this,"support",{filters:!0,shaders:!0}),c(this,"features",{}),c(this,"info",{}),c(this,"lost",!1),c(this,"main"),c(this,"cur"),c(this,"unit",-1),c(this,"onUnit",new Array(Ji).fill(void 0)),c(this,"fbNow"),c(this,"mapped",!0),c(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0}),c(this,"vsrc",""),c(this,"attrs",[]),c(this,"fxr",null),c(this,"batch"),c(this,"dynamic"),c(this,"staticBuf",null),c(this,"index"),c(this,"vao",null),c(this,"inst",null),c(this,"vaoApi",null),c(this,"uScale",null),c(this,"textures",new Map),c(this,"kit"),c(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),c(this,"lostListeners",[]),c(this,"restoredListeners",[]),c(this,"tris",new Int32Array(192)),c(this,"sU",0),c(this,"sV0",0),c(this,"sV1",0),c(this,"sColor",0),c(this,"sPacked",0),c(this,"sAlpha",0),c(this,"sHw",0),c(this,"strokeSeg",()=>{const n=this.q;n.set(Ke),n[8]=n[10]=this.sU,n[9]=this.sV0,n[11]=this.sV1,n[12]=this.sPacked,this.put(this.kit)}),c(this,"strokeDisc",()=>this.ellipse(Ke[0],Ke[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha)),c(this,"q",new Float64Array(13)),c(this,"layers",[]),c(this,"layerTex",new Map),c(this,"bScis",!1),c(this,"bx0",0),c(this,"by0",0),c(this,"bx1",0),c(this,"by1",0),c(this,"onContextLost",n=>{n.preventDefault(),this.lost=!0;for(const r of this.lostListeners)r()}),c(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(const n of this.textures.keys())this.textures.set(n,this.upload(n.source));this.lost=!1;for(const n of this.restoredListeners)n()}catch(n){console.warn("[engine] WebGL restore failed:",n)}}),c(this,"views",new Map),this.kind=s===2?"webgl2":"webgl1",this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(Vr()),bt.live=this,t.addEventListener("webglcontextlost",this.onContextLost,!1),t.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){const t=this.gl,e=this.kind==="webgl2"?t:null;if(this.inst=null,this.opts.instancing!==!1)if(e)this.inst={divisor:(h,u)=>e.vertexAttribDivisor(h,u),draw:(h,u)=>e.drawElementsInstanced(t.TRIANGLES,h,t.UNSIGNED_SHORT,0,u)};else{const h=t.getExtension("ANGLE_instanced_arrays");h&&(this.inst={divisor:(u,f)=>h.vertexAttribDivisorANGLE(u,f),draw:(u,f)=>h.drawElementsInstancedANGLE(t.TRIANGLES,u,t.UNSIGNED_SHORT,0,f)})}if(this.vaoApi=null,this.opts.vao!==!1)if(e)this.vaoApi={create:()=>e.createVertexArray(),bind:h=>e.bindVertexArray(h),remove:h=>e.deleteVertexArray(h)};else{const h=t.getExtension("OES_vertex_array_object");h&&(this.vaoApi={create:()=>h.createVertexArrayOES(),bind:u=>h.bindVertexArrayOES(u),remove:u=>h.deleteVertexArrayOES(u)})}const s=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),i=Math.max(1,Math.min(Ji,s)),n=this.inst!==null;this.vsrc=n?Zr:Kr,this.attrs=n?$r:ta,this.main=this.cur=this.build(Qr(i));const r=this.main.p;t.useProgram(r),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,t.uniform1iv(t.getUniformLocation(r,"uTex"),Int32Array.from({length:i},(h,u)=>u)),this.batch=new Dr(n,i),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic),t.bufferData(t.ARRAY_BUFFER,this.batch.f32.byteLength,t.DYNAMIC_DRAW),this.index=t.createBuffer(),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.index),t.bufferData(t.ELEMENT_ARRAY_BUFFER,Ur(n?1:Gi),t.STATIC_DRAW);const a=h=>t.getAttribLocation(r,h),o=(h,u,f,d,g,p,v)=>{const m=a(h);m<0||(t.enableVertexAttribArray(m),t.vertexAttribPointer(m,u,f,d,g,p),this.inst&&this.inst.divisor(m,v))};if(n){const h=_e*4;o("aP01",4,t.FLOAT,!1,h,0,1),o("aP23",4,t.FLOAT,!1,h,16,1),o("aUvRect",4,t.FLOAT,!1,h,32,1),o("aColor",4,t.UNSIGNED_BYTE,!0,h,48,1),o("aSlot",1,t.FLOAT,!1,h,52,1),this.staticBuf=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.staticBuf),t.bufferData(t.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t.STATIC_DRAW),o("aCorner",4,t.FLOAT,!1,16,0,0),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic)}else{const h=le*4;o("aPos",2,t.FLOAT,!1,h,0,0),o("aUv",2,t.FLOAT,!1,h,8,0),o("aColor",4,t.UNSIGNED_BYTE,!0,h,16,0),o("aSlot",1,t.FLOAT,!1,h,20,0)}t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.disable(t.DEPTH_TEST),t.disable(t.CULL_FACE),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);const l=t.getExtension("WEBGL_debug_renderer_info");this.info={version:t.getParameter(t.VERSION),renderer:l?t.getParameter(l.UNMASKED_RENDERER_WEBGL):t.getParameter(t.RENDERER),vendor:l?t.getParameter(l.UNMASKED_VENDOR_WEBGL):t.getParameter(t.VENDOR)},this.features={instancing:n,vao:this.vaoApi!==null,textureSlots:i,maxTextureSize:this.maxTextureSize}}upload(t){const e=this.gl,s=e.createTexture();return this.bindTex(s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),s}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){const e={id:Rs(),width:t.width,height:t.height,source:t};return this.textures.set(e,this.lost?null:this.upload(t)),e}updateTexture(t,e,s=0,i=0){if(this.lost)return;this.batch.has(t)&&this.flush();const n=this.gl,r=this.textures.get(t);r&&(this.bindTex(r),!e||e===t.source&&s===0&&i===0?n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t.source):n.texSubImage2D(n.TEXTURE_2D,0,s,i,n.RGBA,n.UNSIGNED_BYTE,e))}destroyTexture(t){this.batch.has(t)&&this.flush();const e=this.textures.get(t);e&&!this.lost&&this.deleteTex(e),this.textures.delete(t)}begin(t,e,s){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(s),this.bScis=!1,this.lost)return;const i=this.gl;i.disable(i.SCISSOR_TEST),this.bindFb(null),i.viewport(0,0,this.canvas.width,this.canvas.height);const n=e;i.clearColor((t>>16&255)/255*n,(t>>8&255)/255*n,(t&255)/255*n,n),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(t){var e;const s=this.gl,i=$i(s,s.VERTEX_SHADER,this.vsrc);let n;try{n=$i(s,s.FRAGMENT_SHADER,t)}catch(a){throw s.deleteShader(i),a}const r=s.createProgram();if(s.attachShader(r,i),s.attachShader(r,n),this.attrs.forEach((a,o)=>s.bindAttribLocation(r,o,a)),s.linkProgram(r),s.deleteShader(i),s.deleteShader(n),!s.getProgramParameter(r,s.LINK_STATUS)){const a=(e=s.getProgramInfoLog(r))!=null?e:"?";throw s.deleteProgram(r),new Error("link: ".concat(a))}return{p:r,uScale:s.getUniformLocation(r,"uScale"),locs:new Map}}u(t,e){let s=t.locs.get(e);return s===void 0&&t.locs.set(e,s=this.gl.getUniformLocation(t.p,e)),s}use(t){this.cur!==t&&(this.cur=t,this.gl.useProgram(t.p),this.calls.useProgram++)}bindTex(t,e=this.unit<0?0:this.unit){const s=this.gl;this.onUnit[e]!==t&&(this.unit!==e&&(s.activeTexture(s.TEXTURE0+e),this.calls.activeTexture++,this.unit=e),s.bindTexture(s.TEXTURE_2D,t),this.calls.bindTexture++,this.onUnit[e]=t)}deleteTex(t){this.gl.deleteTexture(t);for(let e=0;e<this.onUnit.length;e++)this.onUnit[e]===t&&(this.onUnit[e]=null)}bindFb(t){if(t)for(let s=0;s<this.onUnit.length;s++)this.onUnit[s]===t.gl&&this.bindTex(null,s);const e=t?t.fb:null;this.fbNow!==e&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,e),this.calls.bindFramebuffer++,this.fbNow=e)}slotOf(t){this.batch.full&&this.flush();let e=this.batch.slot(t);return e<0&&(this.flush(),e=this.batch.slot(t)),e}quad(t,e,s,i,n,r,a,o){j[0]=i,j[1]=n,j[2]=a,this.quadQ(t,e,s,r,o)}quadQ(t,e,s,i,n){const r=j[2];if(this.lost||r<=0)return;const a=this.q,o=j[0],l=j[1],h=s[4],u=s[5],f=s[0]*o,d=s[1]*o,g=s[2]*l,p=s[3]*l;a[0]=h,a[1]=u,a[2]=f+h,a[3]=d+u,a[4]=f+g+h,a[5]=d+p+u,a[6]=g+h,a[7]=p+u;const v=1/t.width,m=1/t.height;a[8]=e.x*v,a[9]=e.y*m,a[10]=(e.x+e.w)*v,a[11]=(e.y+e.h)*m,a[12]=se(i,r,n==="add"),this.put(t)}put(t){if(this.mute)return;const e=this.q;let s=!1;const i=Math.min(e[0],e[2],e[4],e[6]),n=Math.max(e[0],e[2],e[4],e[6]),r=Math.min(e[1],e[3],e[5],e[7]),a=Math.max(e[1],e[3],e[5],e[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;const l=this.scale,h=this.px0/l,u=this.py0/l,f=this.px1/l,d=this.py1/l;if(n<=h||i>=f||a<=u||r>=d)return;if(i<h||n>f||r<u||a>d){const g=e[0],p=e[1],v=e[2],m=e[5];if(p===e[3]&&v===e[4]&&m===e[7]&&e[6]===g){if(g!==v){const x=Math.min(Math.max(g,h),f),b=Math.min(Math.max(v,h),f),w=e[8],A=(e[10]-w)/(v-g);e[10]=w+(b-g)*A,e[8]=w+(x-g)*A,e[0]=e[6]=x,e[2]=e[4]=b}if(p!==m){const x=Math.min(Math.max(p,u),d),b=Math.min(Math.max(m,u),d),w=e[9],A=(e[11]-w)/(m-p);e[11]=w+(b-p)*A,e[9]=w+(x-p)*A,e[1]=e[3]=x,e[5]=e[7]=b}}else s=!0}}const o=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(s?(!this.bScis||!o)&&(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&&o)&&(this.flush(),this.bScis=!1),this.real){const l=this.gq;l[0]=i,l[1]=r,l[2]=n,l[3]=a,this.growQ()}this.batch.pushQ(e,this.slotOf(t))}ellipse(t,e,s,i,n,r,a){if(this.lost||a<=0||s<=0||i<=0)return;const o=zs[Ki(Math.max(s,i)*2*this.scale,Wr)],l=o.w/2/o.r,h=s*l,u=i*l,f=Math.cos(n),d=Math.sin(n),g=f*h,p=d*h,v=-d*u,m=f*u,x=1/gt,b=this.q;b[0]=t-g-v,b[1]=e-p-m,b[2]=t+g-v,b[3]=e+p-m,b[4]=t+g+v,b[5]=e+p+m,b[6]=t-g+v,b[7]=e-p+m,b[8]=o.x*x,b[9]=o.y*x,b[10]=(o.x+o.w)*x,b[11]=(o.y+o.h)*x,b[12]=se(r,a),this.put(this.kit)}polygon(t,e,s,i){if(this.lost||i<=0||e<3)return;this.tris.length<e*3&&(this.tris=new Int32Array(Math.max(e*3,this.tris.length*2)));const n=this.tris,r=Xr(t,e,n),a=se(s,i),o=(Dt.x+Dt.w/2)/gt,l=(Dt.y+Dt.h/2)/gt;for(let h=0;h<r;h+=3){const u=n[h]*2,f=n[h+1]*2,d=n[h+2]*2,g=this.q;g[0]=t[u],g[1]=t[u+1],g[2]=t[f],g[3]=t[f+1],g[4]=g[6]=t[d],g[5]=g[7]=t[d+1],g[8]=g[10]=o,g[9]=g[11]=l,g[12]=a,this.put(this.kit)}}stroke(t,e,s,i,n,r){if(this.lost||n<=0||s<=0||e<1)return;const a=Gs[Ki(s*this.scale,jr)],o=s/2*(a.h/2/a.r);this.sPacked=se(i,n),this.sColor=i,this.sAlpha=n,this.sU=(a.x+a.w/2)/gt,this.sV0=a.y/gt,this.sV1=(a.y+a.h)/gt,this.sHw=s/2,qr(t,e,o,r,this.strokeSeg,this.strokeDisc)}target(t,e,s,i){const n=this.gl,r=n.createTexture();this.bindTex(r),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,e,0,n.RGBA,n.UNSIGNED_BYTE,null);const a=i?n.LINEAR:n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),this.bindTex(null);const o=n.createFramebuffer();n.bindFramebuffer(n.FRAMEBUFFER,o),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,r,0);const l=n.checkFramebufferStatus(n.FRAMEBUFFER)===n.FRAMEBUFFER_COMPLETE;if(this.fbNow=o,this.bindFb(this.parent()),!l)return this.deleteTex(r),n.deleteFramebuffer(o),null;const h={tex:{id:Rs(),width:t,height:e,source:this.canvas},gl:r,fb:o,w:t,h:e,f:s};return this.layerTex.set(h.tex,r),h}drop(t){this.batch.has(t.tex)&&this.flush(),this.deleteTex(t.gl),this.gl.deleteFramebuffer(t.fb),this.layerTex.delete(t.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(t){var e;const s=this.canvas.width,i=this.canvas.height;let n=(e=this.layers[t])!=null?e:null;return n&&(n.w!==s||n.h!==i)&&(this.drop(n),n=this.layers[t]=null),n!=null?n:this.layers[t]=this.target(s,i,1,!1)}pushLayer(){if(this.lost)return!1;this.flush();const t=this.layerAt(this.real);if(!t)return!1;const e=this.gl;return this.bindFb(t),e.disable(e.SCISSOR_TEST),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){var t;return this.lost||!bt.gl?null:(t=this.fxr)!=null?t:this.fxr=bt.gl(this)}composite(t,e,s,i){var n;if(i&&((n=this.filters())!=null&&n.chain(t,s,i)))return;const r=this.gl;e&&r.blendFunc(r.ZERO,r.SRC_ALPHA),this.final(this.main,t,1,s),e&&(this.flush(),r.blendFunc(r.ONE,r.ONE_MINUS_SRC_ALPHA))}final(t,e,s,i){const n=this.gl,r=this.canvas.width,a=this.canvas.height,o=this.scale;(t!==this.main||!this.mapped)&&(this.bindFb(this.parent()),n.viewport(0,0,r,a),this.use(t),n.uniform2f(t.uScale,2*o/r,-2*o/a),this.mapped=t===this.main);const l=this.rx0/o,h=this.ry0/o,u=this.rx1/o,f=this.ry1/o,d=1/(s*e.width),g=1/(s*e.height),p=this.q;p[0]=p[6]=l,p[1]=p[3]=h,p[2]=p[4]=u,p[5]=p[7]=f,p[8]=this.rx0*d,p[9]=1-this.ry0*g,p[10]=this.rx1*d,p[11]=1-this.ry1*g,p[12]=se(16777215,i),this.put(e),t!==this.main&&this.flush()}remap(){const t=this.gl;this.bindFb(this.parent()),t.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),t.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(t){const e=this.gl,s=t.words;if(this.kind==="webgl2")return e.bufferSubData(e.ARRAY_BUFFER,0,t.f32,0,s);let i=this.views.get(s);i||(this.views.size>=256&&this.views.clear(),this.views.set(s,i=t.f32.subarray(0,s))),e.bufferSubData(e.ARRAY_BUFFER,0,i)}flush(){var t,e;const s=this.batch;if(!s.quads||this.lost)return s.reset();const i=this.gl;this.bScis?(i.enable(i.SCISSOR_TEST),i.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):i.disable(i.SCISSOR_TEST),this.upload2(s);for(let n=0;n<s.bound;n++){const r=s.textures[n];this.bindTex((e=(t=this.textures.get(r))!=null?t:this.layerTex.get(r))!=null?e:null,n)}this.inst?this.inst.draw(6,s.quads):i.drawElements(i.TRIANGLES,s.quads*6,i.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=s.quads,s.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){var t,e;const s=this.gl;bt.live===this&&(bt.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(const i of this.textures.values())i&&s.deleteTexture(i);for(const i of this.layers)i&&(s.deleteTexture(i.gl),s.deleteFramebuffer(i.fb));(t=this.fxr)==null||t.destroy(),this.fxr=null,s.deleteBuffer(this.dynamic),s.deleteBuffer(this.index),this.staticBuf&&s.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),s.deleteProgram(this.main.p),(e=s.getExtension("WEBGL_lose_context"))==null||e.loseContext()}catch(i){}this.textures.clear()}};function $i(t,e,s){var i;const n=t.createShader(e);if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){const r=(i=t.getShaderInfoLog(n))!=null?i:"?";throw t.deleteShader(n),new Error(r)}return n}function tn(t="auto"){switch(t){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function Hs(t,e={}){let s=t;for(const i of tn(e.renderer)){const n=i==="canvas2d"?Os(s):ea(s,i==="webgl2"?2:1,e);if(n)return n;s=qs(s)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function qs(t){var e;const s=t.cloneNode(!1);return(e=t.parentNode)==null||e.replaceChild(s,t),s}function ia(t=typeof location!="undefined"?location.search:""){const e=new URLSearchParams(t).get("renderer");return e==="canvas"?"canvas2d":e==="webgl2"||e==="webgl1"||e==="canvas2d"||e==="webgl"||e==="auto"?e:void 0}var Ws=class{constructor(t,e={}){c(this,"atlas",t),c(this,"tags",new Map),c(this,"count",0),c(this,"m",ee()),c(this,"measure",null),c(this,"height"),c(this,"font");var s,i;this.height=(s=e.tagHeight)!=null?s:34,this.font=(i=e.tagFont)!=null?i:"Nunito, sans-serif"}drop(){for(const t of this.tags.values())for(const e of t.values())for(const s of e.values())this.atlas.release(s);this.tags.clear(),this.count=0}get(t,e,s){let i=this.tags.get(t);i||this.tags.set(t,i=new Map);let n=i.get(e);n||i.set(e,n=new Map);const r=n.get(s);return r&&this.atlas.valid(r)?r:this.bake(t,e,s)}bake(t,e,s){var i;const n=this.height,r="700 ".concat(Math.round(n*.65),"px ").concat(this.font),a=(i=this.measure)!=null?i:this.measure=document.createElement("canvas").getContext("2d");a.font=r;const o=Math.round(n*.4),l=Math.ceil(a.measureText(t).width)+o*2,h=this.atlas.bake((l+2)*s,(n+2)*s,d=>{d.scale(s,s),d.translate(1,1);const g=n/2;d.beginPath(),d.moveTo(g,0),d.lineTo(l-g,0),d.arc(l-g,g,g,-Math.PI/2,Math.PI/2),d.lineTo(g,n),d.arc(g,g,g,Math.PI/2,Math.PI*3/2),d.closePath(),d.fillStyle=e,d.fill(),d.fillStyle="#fff",d.font=r,d.textAlign="center",d.textBaseline="middle",d.fillText(t,l/2,n/2+1)},s,1,1,1);++this.count>64&&(this.drop(),this.count=1);let u=this.tags.get(t);u||this.tags.set(t,u=new Map);let f=u.get(e);return f||u.set(e,f=new Map),f.set(s,h),h}draw(t,e,s,i,n,r,a,o,l,h,u){const f=gr(s,n,{band:na(i)});if(!f)return;const d=this.height,g=this.get(r,a,l),p=g.w/g.scale-2,v=Math.min(Math.max(f.head.x-p/2,4),h-p-4),m=Math.min(Math.max(f.head.y-f.headR*2.2-d,4),u-d-4);At(this.m,null,v-1,m-1,0,1,1),t.quad(e(g.surface),g,this.m,g.w/g.scale,g.h/g.scale,16777215,o,"normal")}},na=t=>t.band==="3-5"||t.band==="9-12"?t.band:"6-8",ra=(t,e=!1)=>e?Math.min($t(2,Math.round(Math.log2(Math.max(t,8)))),256):Math.min($t(2,Math.ceil(Math.log2(Math.max(t,8))*2)/2),512);function js(t,e=null){var s,i,n,r;const a={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},o=(l,h,u)=>{const f=e?e[0]*l+e[2]*h+e[4]:l,d=e?e[1]*l+e[3]*h+e[5]:h,g=e?Math.hypot(e[0],e[1]):1;a.minX=Math.min(a.minX,f-u*g),a.minY=Math.min(a.minY,d-u*g),a.maxX=Math.max(a.maxX,f+u*g),a.maxY=Math.max(a.maxY,d+u*g)};for(const l of t){const h="lw"in l&&l.stroke?((s=l.lw)!=null?s:1)/2:0;switch(l.k){case"circle":o(l.x-l.r,l.y-l.r,h),o(l.x+l.r,l.y+l.r,h),o(l.x-l.r,l.y+l.r,h),o(l.x+l.r,l.y-l.r,h);break;case"ellipse":case"rect":{const u=l.k==="ellipse"?Math.max(l.rx,l.ry):Math.hypot(l.w,l.h)/2;o(l.x-u,l.y-u,h),o(l.x+u,l.y+u,h),o(l.x-u,l.y+u,h),o(l.x+u,l.y-u,h);break}case"path":{const u=Bs(l.d);for(let f=0;f<u.count;f++){const d=u.subs[f];for(let g=0;g<d.n;g++)o(d.pts[g*2],d.pts[g*2+1],h)}break}case"line":for(let u=0;u+1<l.pts.length;u+=2)o(l.pts[u],l.pts[u+1],h);break;case"group":{const u=At(ee(),e,l.x,l.y,(i=l.rot)!=null?i:0,(n=l.s)!=null?n:1,(r=l.s)!=null?r:1),f=js(l.items,u);Number.isFinite(f.minX)&&(a.minX=Math.min(a.minX,f.minX),a.minY=Math.min(a.minY,f.minY),a.maxX=Math.max(a.maxX,f.maxX),a.maxY=Math.max(a.maxY,f.maxY));break}}}return a}var Ys=class{constructor(t){c(this,"atlas",t),c(this,"seen",new WeakSet),c(this,"baked",new WeakMap),c(this,"m",ee()),c(this,"stack",[]),c(this,"local",ee()),c(this,"pts",new Float64Array(128)),c(this,"stats",{baked:0,vector:0}),c(this,"bakeGroups",!0),c(this,"coarse",!1),c(this,"gen",0),c(this,"live",new Set)}setTier(t){const e=t==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(const s of this.live)this.atlas.release(s.frame);this.live.clear()}}draw(t,e,s,i,n,r,a){var o;const l=typeof i=="string"?(o=Ue(i))!=null?o:Be:i,h=pr(s,l,n);return h.length?(r<=0||(r<1?(this.paint(t,e,h,null,t.beginLayer()?1:r,a),t.endLayer(r)):this.paint(t,e,h,null,r,a)),!0):!1}paint(t,e,s,i,n,r,a=0){var o,l,h,u,f,d,g,p,v,m,x;for(let b=0;b<s.length;b++){const w=s[b];if(w.k==="group"){const N=At((l=(o=this.stack)[a])!=null?l:o[a]=ee(),i,w.x,w.y,(h=w.rot)!=null?h:0,(u=w.s)!=null?u:1,(f=w.s)!=null?f:1),G=n*((d=w.alpha)!=null?d:1);if(this.bakeGroups&&this.seen.has(w.items)){const z=kt(N[0],N[1])*r,U=this.bake(w.items,z);if(U){const D=U.frame,V=this.m;V.set(N),V[4]=N[0]*-U.ox+N[2]*-U.oy+N[4],V[5]=N[1]*-U.ox+N[3]*-U.oy+N[5],t.quad(e(D.surface),D,V,D.w/U.k,D.h/U.k,16777215,G,"normal"),this.stats.baked++;continue}}this.seen.add(w.items),this.stats.vector++,this.paint(t,e,w.items,N,G,r,a+1);continue}const A=n*((g=w.alpha)!=null?g:1),T=i?kt(i[0],i[1]):1,F=i?Math.atan2(i[1],i[0]):0,P=((p=w.lw)!=null?p:1)*T,E=w.stroke&&((v=w.lw)!=null?v:1)>0?xt(w.stroke):null,I=w.fill&&w.k!=="line"?xt(w.fill):null;if(w.k==="circle"||w.k==="ellipse"){const N=i?i[0]*w.x+i[2]*w.y+i[4]:w.x,G=i?i[1]*w.x+i[3]*w.y+i[5]:w.y,z=(w.k==="circle"?w.r:w.rx)*T,U=(w.k==="circle"?w.r:w.ry)*T,D=(w.k==="ellipse"&&(m=w.rot)!=null?m:0)+F;if(I&&E)t.ellipse(N,G,z+P/2,U+P/2,D,E[0],A*E[1]),t.ellipse(N,G,Math.max(z-P/2,0),Math.max(U-P/2,0),D,I[0],A*I[1]);else if(I)t.ellipse(N,G,z,U,D,I[0],A*I[1]);else if(E){const V=Math.min(Math.max(Math.ceil(Math.max(z,U)*r*.6),12),64),J=this.pts=Ds(this.pts,V*2),Q=Math.cos(D),K=Math.sin(D);for(let Y=0;Y<V;Y++){const Bt=Y/V*Math.PI*2,Qt=Math.cos(Bt)*z,dt=Math.sin(Bt)*U;J[Y*2]=N+Qt*Q-dt*K,J[Y*2+1]=G+Qt*K+dt*Q}t.stroke(J,V,P,E[0],A*E[1],!0)}continue}if(w.k==="line"){if(!E)continue;const N=w.pts.length>>1,G=this.pts=Ds(this.pts,N*2);for(let z=0;z<N;z++){const U=w.pts[z*2],D=w.pts[z*2+1];G[z*2]=i?i[0]*U+i[2]*D+i[4]:U,G[z*2+1]=i?i[1]*U+i[3]*D+i[5]:D}t.stroke(G,N,P,E[0],A*E[1],!1);continue}const B=w.k==="path"?Bs(w.d,i,T*r):aa(w,At(this.local,i,w.x,w.y,(x=w.rot)!=null?x:0,1,1),r*T);for(let N=0;N<B.count;N++){const G=B.subs[N],z=G.n,U=w.k==="rect"||G.closed;I&&z>=3&&(t.polygon(G.pts,z,I[0],A*I[1]),E||t.stroke(G.pts,z,1/r,I[0],A*I[1],!0)),E&&t.stroke(G.pts,z,P,E[0],A*E[1],U)}}}bake(t,e){const s=ra(e,this.coarse);let i=this.baked.get(t);const n=i==null?void 0:i.get(s);if(n&&n.gen===this.gen&&this.atlas.valid(n.frame))return n;n&&this.live.delete(n);const r=js(t);if(!Number.isFinite(r.minX))return null;const a=2/s,o=(r.maxX-r.minX+a*2)*s,l=(r.maxY-r.minY+a*2)*s;if(o>1024||l>1024)return null;const h=-r.minX+a,u=-r.minY+a,d={frame:this.atlas.bake(o,l,g=>{g.scale(s,s),g.translate(h,u),yi(g,t)}),k:s,ox:h,oy:u,gen:this.gen};return i||this.baked.set(t,i=new Map),i.set(s,d),this.live.add(d),d}},he=new Array(36).fill(0),ce=0,_t=(t,e=NaN,s=NaN,i=NaN,n=NaN)=>{he[ce++]=t,t!==ft.Z&&(he[ce++]=e,he[ce++]=s,t===ft.Q&&(he[ce++]=i,he[ce++]=n))};function aa(t,e,s){const i=Math.max(0,Math.min(t.r,t.w/2,t.h/2)),n=-t.w/2,r=-t.h/2,{M:a,L:o,Q:l,Z:h}=ft;return ce=0,_t(a,n+i,r),_t(o,n+t.w-i,r),_t(l,n+t.w,r,n+t.w,r+i),_t(o,n+t.w,r+t.h-i),_t(l,n+t.w,r+t.h,n+t.w-i,r+t.h),_t(o,n+i,r+t.h),_t(l,n,r+t.h,n,r+t.h-i),_t(o,n,r+i),_t(l,n,r,n+i,r),_t(h),Bs(he,e,s)}function oa(t,e={}){var s,i;let n=Hs(t,e);const r=new Ns(Math.min(1024,n.maxTextureSize),2);r.onDrop=E=>{E.texture&&n.destroyTexture(E.texture),E.texture=null};const a=new Ys(r),o=()=>{const E=new Nr;return e.local&&E.setLocal(!0),E};let l=o();const h=new Map;let u=1e6;const f=e.smooth===!1?1:typeof e.smooth=="number"?Math.min(Math.max(e.smooth,.05),1):l.defaultAmount;let d=Je(n);const g=new Ws(r,e),p={w:1,h:1};let v=1,m=0,x=!1;const b=()=>g.drop(),w=typeof document!="undefined"?document.fonts:void 0;(s=w==null?void 0:w.ready)==null||s.then(()=>{x||b()}),(i=w==null?void 0:w.addEventListener)==null||i.call(w,"loadingdone",b);const A=()=>{const E=qs(n.canvas),I=Os(E);if(I){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),n.destroy(),n=I;for(const B of r.pages)B.surface.texture=null;d=Je(n),m=0}},T=()=>{if(!n.lost)return m=0,!0;const E=performance.now();return m||(m=E),E-m>3e3&&A(),!n.lost},F=()=>{var E,I;const B=n.canvas;e.units?(v=(E=e.pixelRatio)!=null?E:1,p.w=e.units.width,p.h=e.units.height):(v=(I=e.pixelRatio)!=null?I:Math.min(Pt.devicePixelRatio||1,2),p.w=B.clientWidth||B.width/v,p.h=B.clientHeight||B.height/v),n.resize(Math.max(1,Math.round(p.w*v)),Math.max(1,Math.round(p.h*v))),n.begin(0,0,v)},P=(E,I)=>{var B;if(E.key===void 0)return(B=E.id)!=null?B:I+1;let N=h.get(E.key);return N===void 0&&(h.size>256&&h.clear(),h.set(E.key,N=u++)),N};return{get renderer(){return n},get kind(){return n.kind},get lost(){return n.lost},get canvas(){return n.canvas},draw(E,I){var B,N,G,z;if(T()){F();for(let U=0;U<E.length;U++){const D=E[U];if(!Array.isArray(D.body))continue;const V=P(D,U),J=f<1||e.interpolate!==!1?l.posed(V,D.body,f,e.interpolate!==!1):D.body,Q=(N=Ue((B=D.avatar)!=null?B:""))!=null?N:Be,K=(G=D.alpha)!=null?G:1;!a.draw(n,d,J,Q,I,K,v)||!D.name||g.draw(n,d,J,Q,I,D.name,(z=D.color)!=null?z:"#6FA0E0",K,v,p.w,p.h)}n.end()}},clear(){T()&&(F(),n.end())},reset(){l=o(),h.clear()},destroy(){var E;x=!0,(E=w==null?void 0:w.removeEventListener)==null||E.call(w,"loadingdone",b),n.destroy()}}}var Ze=new Map;function la(t,e,s=Math.min(Pt.devicePixelRatio||1,2)){var i;const n="".concat(t,"|").concat(e,"|").concat(s);let r=Ze.get(n);if(r)return r;r=document.createElement("canvas"),r.width=r.height=Math.round(e*s);const a=r.getContext("2d");return a.scale(s,s),a.beginPath(),a.rect(0,0,e,e),a.clip(),yi(a,mr((i=Ue(t))!=null?i:Be,e)),Ze.size>64&&Ze.clear(),Ze.set(n,r),r}function Je(t){return e=>{if(e.texture||(e.texture=t.createTexture(e.source),e.pending.length=0),e.pending.length){for(const[s,i,n]of e.pending)t.updateTexture(e.texture,s,i,n);e.pending.length=0}return e.texture}}var en='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',Me="rgba(10,16,30,0.75)";function sn(t,e){var s,i,n,r,a,o;const l=(s=t.size)!=null?s:40,h=t.outline?t.outline===!0?Me:t.outline:null,u=h?(i=t.outlineWidth)!=null?i:Math.max(l*.12,3):0,f=t.shadow&&e?t.shadow===!0?Me:t.shadow:null,d=f?(n=t.shadowBlur)!=null?n:l*.25:0;return{size:l,font:(r=t.font)!=null?r:en,weight:(a=t.weight)!=null?a:700,color:(o=t.color)!=null?o:"#FBEFE3",outline:h,ow:u,shadow:f,blur:d,pad:u/2+d*1.2+2,th:l*1.25}}var nn=(t,e)=>"".concat(t.weight," ").concat(t.size*e,"px ").concat(t.font);function rn(t,e,s,i,n,r){t.scale(i,i),t.font=nn(s,1),t.textBaseline="middle",t.textAlign="left",t.lineJoin="round",s.shadow&&(t.shadowColor=s.shadow,t.shadowBlur=s.blur*i),s.outline&&(t.strokeStyle=s.outline,t.lineWidth=s.ow,t.strokeText(e,n,r),t.shadowColor="transparent"),t.fillStyle=s.color,t.fillText(e,n,r)}var Ae=null;function an(t,e,s){return Ae!=null||(Ae=document.createElement("canvas").getContext("2d")),Ae.font=nn(e,s),Ae.measureText(t).width/s}var ke=class extends ie{constructor(t,e,s={}){super(t,null),c(this,"_text"),c(this,"_style"),c(this,"dirty",!0),c(this,"bakedScale",0),c(this,"bakedFontGen",-1),c(this,"bakedEffects",!0),c(this,"capW",0),c(this,"capH",0),this._text=e;const i=s,{x:n,y:r,rotation:a,scale:o,scaleX:l,scaleY:h,alpha:u,visible:f,tint:d,blend:g,z:p,anchor:v,hitRadius:m,clip:x,mask:b,filters:w}=i,A=ys(i,["x","y","rotation","scale","scaleX","scaleY","alpha","visible","tint","blend","z","anchor","hitRadius","clip","mask","filters"]);this._style=A,this.bake(),this.set({x:n,y:r,rotation:a,scale:o,scaleX:l,scaleY:h,alpha:u,visible:f,tint:d,blend:g,z:p,hitRadius:m,clip:x,mask:b,filters:w}),v!==void 0&&(this.anchor=v)}get text(){return this._text}set text(t){const e=String(t);e!==this._text&&(this._text=e,this.dirty=!0)}get style(){return this._style}set style(t){this._style=Mt(Mt({},this._style),t),this.dirty=!0}bitmap(){const t=this._style.bitmapFont;if(!t)return null;const e=typeof t=="string"?this.kernel.bitmapFont(t):t;if(this.autoAnchor){const s=this._style.align;this.anchorX=s==="left"?0:s==="right"?1:.5,this.anchorY=.5}return e}get naturalWidth(){var t;const e=this.bitmap();return e?e.measure(this._text)*(((t=this._style.size)!=null?t:e.size)/e.size):super.naturalWidth}get naturalHeight(){var t;const e=this.bitmap();return e?e.lineHeight*(((t=this._style.size)!=null?t:e.size)/e.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(t,e,s){var i;const n=this.bitmap();if(!n)return super.draw(t,e,s);const r=((i=this._style.size)!=null?i:n.size)/n.size,a=n.measure(this._text)*r,o=n.lineHeight*r,l=this.width,h=this.height,u=a>0?l/a:1,f=o>0?h/o:1;n.run(this._text,t,this.world,-this.anchorX*l,-this.anchorY*h,r*u,r*f,s,e,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){const t=this.kernel;if(this._style.bitmapFont)return null;const e=t.pixelScale,s=t.effects;return!this.dirty&&e===this.bakedScale&&t.fontGen===this.bakedFontGen&&s===this.bakedEffects&&t.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){var t;const e=this.kernel,s=e.pixelScale,i=e.effects;this.dirty=!1,this.bakedScale=s,this.bakedFontGen=e.fontGen,this.bakedEffects=i;const n=sn(this._style,i),{pad:r,th:a}=n,o=an(this._text,n,s),l=(o+r*2)*s,h=(a+r*2)*s,u=(t=this._style.align)!=null?t:"center",f=u==="left"?r:u==="right"?r+o:r+o/2,d=v=>rn(v,this._text,n,s,r,r+a/2),g=this._frame;let p=null;return g&&e.atlas.valid(g)&&g.scale===s&&(p=e.atlas.rebake(g,l,h,d,this.capW,this.capH),p?Object.assign(p,{ox:f,oy:r+a/2,margin:r}):e.atlas.release(g)),p||(this.capW=Math.ceil(l*1.25+16),this.capH=Math.ceil(h),p=e.atlas.bake(this.capW,this.capH,d,s,f,r+a/2,r),p.w=Math.ceil(l),p.h=Math.ceil(h)),this._frame=p,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,p}},it=(t,e=0)=>{const s=Number(t);return Number.isFinite(s)?s:e};function $e(t){var e,s,i,n,r,a;typeof t=="string"&&/^\s*[{[]/.test(t)&&(t=JSON.parse(t));const o={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},l=(h,u)=>{var f;h==="info"?o.size=Math.abs(it(u.size)):h==="common"?(o.lineHeight=it(u.lineHeight),o.base=it(u.base)):h==="page"?o.pages[it(u.id)]=String((f=u.file)!=null?f:""):h==="char"?o.chars.push({id:it(u.id),x:it(u.x),y:it(u.y),width:it(u.width),height:it(u.height),xoffset:it(u.xoffset),yoffset:it(u.yoffset),xadvance:it(u.xadvance),page:it(u.page)}):o.kernings.push({first:it(u.first),second:it(u.second),amount:it(u.amount)})};if(typeof t=="object"){const h=t;l("info",(e=h.info)!=null?e:{}),l("common",(s=h.common)!=null?s:{});for(const[u,f]of((i=h.pages)!=null?i:[]).entries())l("page",{id:u,file:f});for(const u of(n=h.chars)!=null?n:[])l("char",u);for(const u of(r=h.kernings)!=null?r:[])l("kerning",u)}else{const h=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,u=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let f=h.exec(t);f;f=h.exec(t)){const d={};for(let g=u.exec(f[2]);g;g=u.exec(f[2]))d[g[1]]=(a=g[2])!=null?a:g[3];l(f[1],d)}}return o.size||(o.size=o.lineHeight),o}var Vs=class{constructor(t,e,s,i=null,n=null){c(this,"baker",i),c(this,"host",n),c(this,"size"),c(this,"lineHeight"),c(this,"base"),c(this,"ascii",new Array(128)),c(this,"more",new Map),c(this,"kern",new Map),c(this,"bScale",0),c(this,"bFontGen",-1),c(this,"bEffects",!1),c(this,"bGen",-1),this.size=t,this.lineHeight=e,this.base=s}set(t,e){t<128?this.ascii[t]=e:this.more.set(t,e)}setKerning(t,e,s){this.kern.set(t*1114112+e,s)}prepare(){const 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(const e of this.ascii)e&&t.atlas.release(e.frame);for(const 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 s;return this.kern.size&&(s=this.kern.get(t*1114112+e))!=null?s:0}measure(t){return this.run(t)}run(t,e,s,i=0,n=0,r=1,a=1,o=0,l=1,h="normal"){this.prepare();let u=0,f=-1;for(let d=0;d<t.length;d++){let g=t.charCodeAt(d);g>=55296&&g<56320&&d+1<t.length&&(g=t.codePointAt(d),d++),f>=0&&(u+=this.kerning(f,g)),f=g;const p=this.glyph(g);p&&(e&&p.w>0&&p.h>0&&(Ge(s,i+(u+p.x)*r,n+p.y*a),e.r.quad(e.tex(p.frame.surface),p.frame,et,p.w*r,p.h*a,o,l,h)),u+=p.advance)}return u}};function ha(t,e){const s=new Vs(t.size,t.lineHeight,t.base);for(const i of t.chars){const n=e[i.page];if(!n)continue;const r={surface:n,x:i.x,y:i.y,w:i.width,h:i.height,scale:1,gen:0,ox:0,oy:0,margin:0};s.set(i.id,{frame:r,x:i.xoffset,y:i.yoffset,w:i.width,h:i.height,advance:i.xadvance})}for(const i of t.kernings)s.setKerning(i.first,i.second,i.amount);return s}function ca(t,e){var s,i;const n=Mt({},e),r=(s=e.size)!=null?s:40,a=l=>{const h=String.fromCodePoint(l),u=t.pixelScale,f=sn(n,t.effects),d=an(h,f,u),g=t.atlas.bake((d+f.pad*2)*u,(f.th+f.pad*2)*u,p=>rn(p,h,f,u,f.pad,f.pad+f.th/2),u);return{frame:g,x:-f.pad,y:-f.pad,w:g.w/u,h:g.h/u,advance:d}},o=new Vs(r,r*1.25,r,a,t);o.prepare();for(const l of(i=e.chars)!=null?i:"0123456789")o.glyph(l.codePointAt(0));return o}var ua=.5;function on(t){const e=[];for(const[s,i]of[["left",pt.leftWrist],["right",pt.rightWrist]]){const n=t[i*3],r=t[i*3+1],a=t[i*3+2];n!==void 0&&r!==void 0&&Number.isFinite(n)&&Number.isFinite(r)&&(a!=null?a:0)>=ua&&e.push({side:s,x:n,y:r})}return e}var ts=t=>Oe[((t-1)%Oe.length+Oe.length)%Oe.length],fa=["left","right"];function ln(t,e,s,i,n=()=>null,r={}){var a,o;const l=[];for(const h of t){const u=(a=n(h))!=null?a:h.body;if(Array.isArray(u)){if(r.orientation==="portrait"){for(const f of fa){let d=ir(u,f,{orientation:"portrait"});r.hold&&(d=r.hold.at(pi.key(h.id,f),d,(o=r.t)!=null?o:0)),d&&l.push({player:h.id,side:f,x:d.x*s,y:d.y*i,color:ts(h.id)})}continue}for(const f of on(u)){const d=e(f);l.push({player:h.id,side:f.side,x:d.x*s,y:d.y*i,color:ts(h.id)})}}}return l}function Qs(t,e,s,i=0){const n=t.world,r=vr(n,e,s);if(!r)return!1;const a=Math.hypot(n[0],n[1])||1,o=Math.hypot(n[2],n[3])||1,[l,h]=r;if(t.hitRadius!=null){const p=t.hitRadius+i/((a+o)/2);return l*l+h*h<=p*p}const u=-t.anchorX*t.width-i/a,f=-t.anchorY*t.height-i/o,d=(1-t.anchorX)*t.width+i/a,g=(1-t.anchorY)*t.height+i/o;return l>=u&&l<=d&&h>=f&&h<=g}function hn(t,e,s,i=0){for(const n of e)if((s===void 0||n.player===s)&&Qs(t,n.x,n.y,i))return n;return null}function da(t){var e;switch(t.type){case"circle":case"ring":case"star":return[t.r*2,t.r*2];case"ellipse":return[t.rx*2,t.ry*2];case"roundRect":return[t.w,t.h];case"line":return[t.length,(e=t.lw)!=null?e:4];case"path":return t.r?[t.r*2,t.r*2]:[t.size,t.size]}}function pa(t){var e,s,i;const n=t.type==="line"?0:t.stroke?((e=t.lw)!=null?e:2)/2:0,r=t.shadow?t.shadow.blur*1.5+Math.max(Math.abs((s=t.shadow.x)!=null?s:0),Math.abs((i=t.shadow.y)!=null?i:0)):0;return Math.ceil(n+r+1)}var ga=(t,e)=>e||!t.shadow?t:fe(Mt({},t),{shadow:void 0});function cn(t,e,s){const i=pa(e),n=e.type==="roundRect",[r,a]=n?[Math.min(e.w,e.r*2+4/s),Math.min(e.h,e.r*2+4/s)]:da(e),o=(r+i*2)*s,l=(a+i*2)*s;return{frame:t.bake(o,l,u=>{u.scale(s,s),u.translate(i+r/2,i+a/2),ma(u,e,r,a)},s,i+r/2,i+a/2,i),slice:n?Math.ceil((e.r+i)*s):0,w:n?e.w:r,h:n?e.h:a}}function ma(t,e,s,i){var n,r,a,o,l,h,u;t.lineJoin="round",t.lineCap="round";const f=new Path2D;switch(e.type){case"circle":case"ring":f.arc(0,0,e.r,0,Math.PI*2);break;case"ellipse":f.ellipse(0,0,e.rx,e.ry,0,0,Math.PI*2);break;case"roundRect":f.roundRect(-s/2,-i/2,s,i,Math.min(e.r,s/2,i/2));break;case"star":{const m=(n=e.points)!=null?n:5,x=e.r*((r=e.inner)!=null?r:.5);for(let b=0;b<m*2;b++){const w=b%2?x:e.r,A=-Math.PI/2+b*Math.PI/m;b?f.lineTo(Math.cos(A)*w,Math.sin(A)*w):f.moveTo(Math.cos(A)*w,Math.sin(A)*w)}f.closePath();break}case"line":f.moveTo(-s/2+i/2,0),f.lineTo(s/2-i/2,0);break;case"path":{const m=e.r?e.r*2/e.size:1,x=new DOMMatrix([m,0,0,m,-e.size/2*m,-e.size/2*m]);f.addPath(new Path2D(e.d),x);break}}const d=e.shadow,g=()=>{var m,x;if(!d)return;const b=t.getTransform();t.shadowColor=d.color,t.shadowBlur=d.blur*b.a,t.shadowOffsetX=((m=d.x)!=null?m:0)*b.a,t.shadowOffsetY=((x=d.y)!=null?x:0)*b.a},p=()=>{t.shadowColor="transparent",t.shadowBlur=0};if(e.type==="line"){g(),t.strokeStyle=(o=(a=e.stroke)!=null?a:e.fill)!=null?o:"#fff",t.lineWidth=i,t.stroke(f);return}const v=e.type==="ring";if(e.outlineBelow&&e.fill&&e.stroke&&!v){g(),t.strokeStyle=e.stroke,t.lineWidth=(l=e.lw)!=null?l:2,t.stroke(f),p(),t.fillStyle=e.fill,t.fill(f);return}e.fill&&!v&&(g(),t.fillStyle=e.fill,t.fill(f),p()),(e.stroke||v)&&((!e.fill||v)&&g(),v&&e.fill&&(t.fillStyle=e.fill,t.fill(f)),t.strokeStyle=(h=e.stroke)!=null?h:"#fff",t.lineWidth=(u=e.lw)!=null?u:2,t.stroke(f),p())}var un=class{constructor(){if(c(this,"ctx",null),c(this,"master",null),c(this,"buffers",new Map),c(this,"held",!1),c(this,"muted",!1),c(this,"volume",1),typeof addEventListener=="function"){const t=()=>{var e;(e=this.context())==null?void 0:e.resume().catch(()=>{})};for(const e of["pointerdown","keydown","touchstart"])addEventListener(e,t,{once:!0,capture:!0})}}context(){var t;if(this.ctx)return this.ctx;const e=(t=Pt.AudioContext)!=null?t:Pt.webkitAudioContext;if(!e)return null;try{this.ctx=new e,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch(s){return null}return this.ctx}load(t,e){return te(this,null,function*(){const s=this.context();if(!s)return;const i=yield(yield fetch(e)).arrayBuffer();this.buffers.set(t,yield s.decodeAudioData(i))})}has(t){return this.buffers.has(t)}play(t,e={}){var s,i,n;const r=this.context(),a=this.buffers.get(t);if(!r||!a||!this.audible)return()=>{};const o=r.createBufferSource();o.buffer=a,o.loop=(s=e.loop)!=null?s:!1,o.playbackRate.value=(i=e.rate)!=null?i:1;const l=r.createGain();return l.gain.value=((n=e.volume)!=null?n:1)*this.volume,o.connect(l).connect(this.master),o.start(),()=>{try{o.stop()}catch(h){}}}tone(t,e=.25,s={}){var i,n;const r=this.context();if(!(!r||!this.audible))try{const a=r.createOscillator(),o=r.createGain();a.type=(i=s.type)!=null?i:"sine",a.frequency.setValueAtTime(t,r.currentTime),s.to&&a.frequency.exponentialRampToValueAtTime(s.to,r.currentTime+e),o.gain.setValueAtTime(((n=s.volume)!=null?n:.12)*this.volume,r.currentTime),o.gain.exponentialRampToValueAtTime(.001,r.currentTime+e),a.connect(o).connect(this.master),a.start(),a.stop(r.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}},va={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}},Et=["high","medium","low"];function Vt(t){const e=va[t];return fe(Mt({name:t},e),{scale:s=>s<=0?0:Math.max(1,Math.round(s*e.particles))})}var ya=t=>Et[Math.min(Et.indexOf(t)+1,Et.length-1)],es=(t,e)=>{if(!t.length)return NaN;const s=[...t].sort((i,n)=>i-n);return s[Math.min(s.length-1,Math.max(0,Math.floor(e*(s.length-1)+.5)))]},wa=12,xa=t=>ss(t,.5);function ss(t,e=.1){const s=es(t,e);if(!Number.isFinite(s))return 1e3/60;const i=[144,120,90,75,60,50,30];let n=60;for(const r of i)Math.abs(1e3/r-s)<Math.abs(1e3/n-s)&&(n=r);return 1e3/n}function fn(t,e){const s=e.refresh!==void 0&&Number.isFinite(e.refresh)&&e.refresh>0?e.refresh:ss(e.intervals),i=es(e.intervals,.5),n=es(e.intervals,.9),r=es(e.cpu,.5);if(!Number.isFinite(i))return t==="canvas2d"?"low":"medium";const a=l=>l<=s*1.25,o=l=>!Number.isFinite(r)||r<s*l;return t==="canvas2d"?a(n)&&o(.25)?"medium":"low":a(n)&&o(.5)?"high":a(i)?"medium":"low"}function ba(t,e){return t.length<30?!1:t.filter(i=>i>e*1.5).length/t.length>.5}var dn="0.1.1",_a=720*3600*1e3,Ma=(t,e,s)=>"fabi-play.engine-tier:".concat(dn,":").concat(t,":").concat(e,":").concat(s),Aa=(t,e,s)=>"fablee-engine-tier:".concat(dn,":").concat(t,":").concat(e,":").concat(s);function ka(t,e,s=Date.now()){var i;try{const n=JSON.parse((i=t==null?void 0:t.getItem(e))!=null?i:"null");if(n&&Et.includes(n.tier)&&typeof n.at=="number"&&s-n.at<_a)return typeof n.refresh=="number"&&n.refresh>0?{name:n.tier,refresh:n.refresh}:{name:n.tier}}catch(n){}return null}function pn(t,e,s,i,n=Date.now()){try{t==null||t.setItem(e,JSON.stringify(i!==void 0&&Number.isFinite(i)?{tier:s,at:n,refresh:i}:{tier:s,at:n}))}catch(r){}}function Ea(t=typeof location!="undefined"?location.search:""){const e=new URLSearchParams(t).get("tier");return Et.includes(e)?e:void 0}function gn(t,e){const s=e==null?void 0:e.tier;if(Et.includes(s))return t==="canvas2d"&&s==="high"?"medium":s}var mn=t=>typeof(t==null?void 0:t.hz)=="number"&&t.hz>=20&&t.hz<=240?ss([1e3/t.hz],.5):NaN,vn=(t,e)=>Et.indexOf(t)>=Et.indexOf(e)?t:e;function Sa(t,e,s){return t?{name:t,from:"forced"}:e?{name:s?vn(e,s):e,from:"hint"}:s?{name:s,from:"cache"}:null}var Ta=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,yn=class{constructor(t={}){c(this,"steps",[]),c(this,"labels",new Map),c(this,"end",0),c(this,"prevStart",0),c(this,"elapsed",0),c(this,"iter",0),c(this,"last",0),c(this,"delayLeft"),c(this,"_paused"),c(this,"done",!1),c(this,"rewinding",!1),c(this,"promise"),c(this,"resolve"),c(this,"repeat"),c(this,"yoyo"),c(this,"onComplete");var e,s;this.repeat=Math.floor((e=t.repeat)!=null?e:0),this.yoyo=!!t.yoyo,this.delayLeft=(s=t.delay)!=null?s:0,this._paused=!!t.paused,this.onComplete=t.onComplete,this.promise=new Promise(i=>this.resolve=i)}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);const e=Ta.exec(t);if(!e)throw new Error('[engine] timeline: bad position "'.concat(t,'"'));const[,s,i,n]=e,r=n?(i==="-"?-1:1)*Number(n):0;let a=this.end;if(s==="<")a=this.prevStart;else if(s&&s!==">"){const o=this.labels.get(s.trim());o===void 0?this.labels.set(s.trim(),this.end):a=o}return Math.max(a+r,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,s,i="quadOut"){var n,r;const a=typeof i=="object"?i:{ease:i},o=typeof a.ease=="function"?a.ease:me[(n=a.ease)!=null?n:"quadOut"];return this.add({target:t,to:e,from:null,fn:null,start:this.at(a.at)+((r=a.delay)!=null?r:0),dur:Math.max(s,0),ease:o,onUpdate:a.onUpdate,p:-1})}set(t,e,s){return this.add({target:t,to:e,from:null,fn:null,start:this.at(s),dur:0,ease:me.linear,p:-1})}call(t,e){return this.add({target:null,to:null,from:null,fn:t,start:this.at(e),dur:0,ease:me.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){const e=Math.min(typeof t=="string"&&this.labels.has(t)?this.labels.get(t):this.at(t),this.end),s=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(s?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}const e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=t;const s=this.repeat<0?1/0:e*(this.repeat+1),i=Math.min(this.elapsed,s),n=i>=s?this.repeat:Math.floor(i/e);for(;this.iter<n;){const 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)}const r=i-n*e;this.render(this.yoyo&&n%2===1?e-r:r),i>=s&&this.complete()}complete(){var t;this.done||(this.done=!0,(t=this.onComplete)==null||t.call(this),this.resolve())}render(t){const e=this.steps;if(t>=this.last)for(let s=0;s<e.length;s++){const i=e[s];t>=i.start&&this.apply(i,t)}else for(let s=e.length-1;s>=0;s--){const i=e[s];i.p>=0&&this.apply(i,t)}this.last=t}apply(t,e){var s,i;const n=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(n===t.p)return;if(t.p=n,t.fn){this.rewinding||t.fn();return}const r=t.target;if(r.destroyed||r._free)return;const a=t.to;if(!t.from){t.from={};for(const l in a)t.from[l]=Number((s=r[l])!=null?s:0)}const o=t.ease(n);for(const l in a)r[l]=t.from[l]+(a[l]-t.from[l])*o;(i=t.onUpdate)==null||i.call(t,o)}},wn=class{constructor(){c(this,"list",[]),c(this,"timelines",[])}timeline(t){const e=new yn(t);return this.timelines.push(e),e}tween(t,e,s,i="quadOut"){var n;const r=typeof i=="object"?i:{ease:i},a=typeof r.ease=="function"?r.ease:me[(n=r.ease)!=null?n:"quadOut"];let o;const l=new Promise(h=>{var u;const f=Object.keys(e),d=new Float64Array(f.length);f.forEach((g,p)=>d[p]=Number(e[g])),o={target:t,keys:f,to:d,from:new Float64Array(f.length),started:!1,duration:Math.max(s,0),time:0,delay:(u=r.delay)!=null?u:0,ease:a,onUpdate:r.onUpdate,done:h,dead:!1}});return this.list.push(o),Object.assign(l,{stop:()=>this.finish(o)})}stopAll(t){const e=this.list;for(let s=0;s<e.length;s++)e[s].target===t&&this.finish(e[s])}get size(){return this.list.length}update(t){if(this.timelines.length){let i=0;const n=this.timelines;for(let r=0;r<n.length;r++){const a=n[r];a.update(t),a.finished||(n[i++]=a)}n.length=i}const e=this.list;if(!e.length)return;let s=0;for(let i=0;i<e.length;i++){const n=e[i];n.dead||this.step(n,t),n.dead||(e[s++]=n)}s!==e.length&&(e.length=s)}step(t,e){var s,i;if(t.target.destroyed)return this.finish(t);let n=e;if(t.delay>0){if(t.delay-=e,t.delay>0)return;n=-t.delay}const r=t.keys;if(!t.started){t.started=!0;for(let l=0;l<r.length;l++)t.from[l]=Number((s=t.target[r[l]])!=null?s:0)}t.time+=n;const a=t.duration>0?Math.min(t.time/t.duration,1):1,o=t.ease(a);for(let l=0;l<r.length;l++)t.target[r[l]]=t.from[l]+(t.to[l]-t.from[l])*o;(i=t.onUpdate)==null||i.call(t,o),a>=1&&this.finish(t)}finish(t){t.dead||(t.dead=!0,t.done())}clear(){for(const t of this.list)this.finish(t);this.list.length=0;for(const t of this.timelines)t.stop();this.timelines=[]}},rt=720,xn=class extends Wt{constructor(t,e){super(t),c(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},Ra=class extends Wt{constructor(t,e){super(t),c(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},St=()=>performance.now(),bn=t=>{const e=or(t);return e&&Object.freeze(e)};function Fa(){return te(this,arguments,function*(t={}){var e,s,i,n,r,a,o,l,h,u,f;const d=(e=t.play)!=null?e:null;let g=(s=t.canvas)!=null?s:null;g||(g=document.createElement("canvas"),g.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(g));let p=Hs(g,{renderer:(i=t.renderer)!=null?i:ia(),failIfMajorPerformanceCaveat:t.failIfMajorPerformanceCaveat,instancing:t.instancing});g=p.canvas;const v=new Set,m=new Ns(Math.min(2048,p.maxTextureSize),4);m.onPage=y=>v.add(y),m.onDrop=y=>{v.delete(y),y.texture&&p.destroyTexture(y.texture),y.texture=null};let x=Je(p);const b=new wn,w=new un,A=new Ys(m),T=new Map,F=new Map,P=new Map,E=new Map,I=new Map,B=new Set;let N=0;const G=(n=t.tier)!=null?n:Ea(),z=String((r=p.info.renderer)!=null?r:""),U=(()=>{var y;try{return(y=Pt.localStorage)!=null?y:null}catch(M){return null}})(),D=typeof screen!="undefined"?"".concat(screen.width,"x").concat(screen.height):"",V=Ma(p.kind,z,D);dr(U,V,Aa(p.kind,z,D));const J=ka(U,V),Q=Sa(G,gn(p.kind,d==null?void 0:d.device),J==null?void 0:J.name);let K=(a=Q==null?void 0:Q.name)!=null?a:"medium",Y=Vt(K);A.setTier(K);let Bt=(Q==null?void 0:Q.from)==="hint",Qt=J==null?void 0:J.name,dt=(o=J==null?void 0:J.refresh)!=null?o:mn(d==null?void 0:d.device),nt=1,$s=1,Se=1;const ot={atlas:m,get pixelScale(){return nt},get fontGen(){return N},get effects(){return Y.effects},tweens:b,frame:y=>ps.frame(y),shape:y=>{const M=Y.effects,S=M?nt:-nt;let _=T.get(S);_||(T.size>=8&&T.clear(),T.set(S,_=new Di(2e3)));const O=It(y);let C=_.get(y,O);return(!C||!m.valid(C.frame))&&_.set(y,C=cn(m,ga(y,M),nt),O),C},bitmapFont:y=>ps.bitmapFont(y)};let yt=1280,Rt=null;class Mo extends Ps{get width(){return yt}set width(M){}get height(){return rt}set height(M){}get safe(){const M=Math.min(yt,rt*16/9);return{x:(yt-M)/2,y:0,w:M,h:rt}}}const wt=new Mo(ot),zt=()=>{var y;const M=p.canvas,S=M.getBoundingClientRect();$s=Math.max(1,S.width||M.clientWidth||innerWidth),Se=Math.max(1,S.height||M.clientHeight||innerHeight),yt=rt*$s/Se;const _=Math.min(Pt.devicePixelRatio||1,(y=t.maxPixelRatio)!=null?y:2);if(Se*_/rt<=Y.resolution){const C=Math.max(1,Math.round(Se*_));nt=C/rt,p.resize(Math.max(1,Math.round($s*_)),C)}else nt=Y.resolution,p.resize(Math.round(yt*nt),Math.round(rt*nt));Rt&&Rt.style.setProperty("--unit","".concat(Se/rt,"px"))};addEventListener("resize",zt);const ti=y=>{K=y,Y=Vt(y),A.setTier(y),zt()},Gt=typeof ResizeObserver!="undefined"?new ResizeObserver(zt):null;Gt==null||Gt.observe(g);let Ft=(d==null?void 0:d.backdrop)==="video"?"video":"none",tt=(l=d==null?void 0:d.view)!=null?l:null,as=(d==null?void 0:d.orientation)==="portrait"?"portrait":"landscape",Fn=(h=bn(d==null?void 0:d.safeArea))!=null?h:ar,Pn=[],Cn=-1/0,os=!1,Te=!1;const ei=new Set,Nn=()=>{const y=Ft==="video"?"transparent":"";document.documentElement.style.background=y,document.body.style.background=y},In=(y,M)=>{const S=y==="video"?"video":"none",_=M!=null?M:null;if(!(S===Ft&&(_===tt||_&&tt&&_.x===tt.x&&_.y===tt.y&&_.w===tt.w&&_.h===tt.h))){Ft=S,tt=_,Nn();for(const O of[...ei])O(Ft,tt)}},Ln=[];if(d){const y=_=>{Array.isArray(_)&&(Pn=_,Cn=St())},M=_=>{os=_,ls()},S=_=>{if(G||Bt)return;Number.isFinite(dt)||(dt=mn(_));const O=gn(p.kind,_);O&&(Bt=!0,ti(Qt?vn(O,Qt):O))};Ln.push(d.on("start",_=>S(_==null?void 0:_.device)),d.on("start",_=>{((_==null?void 0:_.orientation)==="portrait"||(_==null?void 0:_.orientation)==="landscape")&&(as=_.orientation);const O=bn(_==null?void 0:_.safeArea);O&&(Fn=O)}),d.on("start",_=>{typeof(_==null?void 0:_.muted)=="boolean"&&(w.muted=_.muted)}),d.on("frame",_=>y(_==null?void 0:_.players)),d.on("players",_=>y(_==null?void 0:_.players)),d.on("backdrop",_=>In(_==null?void 0:_.backdrop,_==null?void 0:_.view)),d.on("start",_=>{var O;return In(_==null?void 0:_.backdrop,(O=_==null?void 0:_.view)!=null?O:d.view)}),d.on("pause",()=>M(!0)),d.on("resume",()=>M(!1)),d.on("break-start",()=>M(!0)),d.on("break-done",()=>M(!1)),d.on("break-end",()=>M(!1))),w.muted=d.muted===!0}Nn();const ls=()=>os||Te||document.hidden?w.hold():w.release();let On=-1,si=[],ii=0;const ni=()=>St()-Cn<1e3?Pn:[],Ao=y=>d?d.toScreen(y):di(tt,y),ko=new pi,hs=()=>{if(On===ii)return si;On=ii;const y=as==="portrait",M=Ft==="video"&&!y||!(d!=null&&d.smoothedBody)?()=>null:S=>d.smoothedBody(S);return si=ln(ni(),Ao,yt,rt,M,y?{orientation:as,hold:ko,t:St()}:void 0),si},Re={x:0,y:0,w:1,h:1},Eo=()=>(Re.x=tt?tt.x*yt:0,Re.y=tt?tt.y*rt:0,Re.w=tt?tt.w*yt:yt,Re.h=tt?tt.h*rt:rt,Re),So=y=>{var M;const S=(M=y.alpha)!=null?M:1,_=y.tags?new Ws(m,y):null;_&&B.add(_);const O=typeof y.tags=="function"?y.tags:C=>String(C);return(C,Z)=>{var st,$,lt,Xt,Ht,W;if(Ft==="video")return;const X=Eo();for(const H of ni()){const q=($=(st=d==null?void 0:d.smoothedBody)==null?void 0:st.call(d,H))!=null?$:H.body,ht=(W=Ue((Ht=(Xt=(lt=d==null?void 0:d.avatarOf)==null?void 0:lt.call(d,H))!=null?Xt:H.avatar)!=null?Ht:""))!=null?W:Be;if(!A.draw(C.r,C.tex,q,ht,X,S*Z,nt)||!_)continue;const Zt=O(H.id);Zt&&_.draw(C.r,C.tex,q,ht,X,Zt,ts(H.id),S*Z,nt,yt,rt)}}},ri=new Set,ai=new Set,Fe=new Set;let cs=!1,oi=0,ue=0,us=0;const Kt={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0};let fs=0,li=0,hi=St();const Pe=[];let ds=0;const Dn=()=>({r:p,kernel:ot,tex:x});let Un=Dn();const To=()=>{if(p.lost)return;const[y,M]=Ft==="video"||t.background===void 0?[0,0]:xt(t.background);p.time=us,p.maxBlur=Y.maxBlur,p.begin(y,M,nt),At(wt.world,null,wt.x,wt.y,wt.rotation,wt.scaleX,wt.scaleY),Si(Un,wt,wt.alpha,wt.tint);const S=p.end();Kt.drawCalls=S.drawCalls,Kt.quads=S.quads,Kt.filtersSkipped=S.filtersSkipped},Bn=y=>{var M;if(!cs)return;oi=requestAnimationFrame(Bn);const S=Math.min(Math.max((y-ue)/1e3,0),.1);ue&&Pe.push(y-ue),ue=y,ii++;const _=St(),O=os||Te;if(!O){us+=S,b.update(S);for(const C of Fe)C.destroyed||C.update(S);for(const C of ri)C(S,us)}for(const C of ai)C(S);wt.sweep();for(const C of Fe)C.destroyed&&Fe.delete(C);if(p.lost?(ds||(ds=y),y-ds>3e3&&Ro()):(ds=0,To()),fs++,li+=St()-_,_-hi>=1e3&&(Kt.fps=Math.round(fs*1e3/(_-hi)),Kt.cpuMs=Math.round(li/Math.max(fs,1)*100)/100,(M=d==null?void 0:d.reportStats)==null||M.call(d,{fps:Kt.fps,renderer:p.kind,tier:K}),fs=0,li=0,hi=_),Pe.length>=180){const C=Number.isFinite(dt)?dt:ss(Pe);!G&&!O&&ba(Pe,C)&&K!=="low"&&(ti(ya(K)),Qt=K,pn(U,V,K,Number.isFinite(dt)?dt:void 0),console.info("[engine] slow frames: tier ".concat(K))),Pe.length=0}},Ro=()=>{const y=qs(p.canvas),M=Os(y);if(M){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),p.destroy(),p=M;for(const S of v)S.texture=null;for(const S of m.pages)v.add(S.surface);x=Je(p),Un=Dn(),Gt==null||Gt.disconnect(),Gt==null||Gt.observe(y),zt()}},zn=()=>{ls(),document.hidden||(ue=0)};document.addEventListener("visibilitychange",zn);const Gn=()=>{N++;for(const y of B)y.drop()};if((f=(u=document.fonts)==null?void 0:u.addEventListener)==null||f.call(u,"loadingdone",Gn),zt(),!Q&&t.probe!==!1&&(Number.isFinite(dt)||(dt=xa(yield Pa(wa))),!Bt)){Y=Vt("high"),zt();const y=yield Ca(p,m,()=>x,()=>nt,yt,()=>Bt);if(y.refresh=dt,!Bt){const M=fn(p.kind,y);pn(U,V,M,dt),Qt=M,ti(M)}}const ps={stage:wt,get tier(){return Y},get renderer(){return p},get canvas(){return p.canvas},get pixelScale(){return nt},get backdrop(){return Ft},get view(){return tt},get orientation(){return as},get safeArea(){return Fn},get paused(){return os||Te},sound:w,stats:Kt,get time(){return us},get supports(){const y=p.support;return{filters:y.filters,blur:y.filters&&Y.maxBlur>0,shaders:y.shaders,maxBlur:y.filters?Y.maxBlur:0,tiers:{high:{maxBlur:Vt("high").maxBlur},medium:{maxBlur:Vt("medium").maxBlur},low:{maxBlur:Vt("low").maxBlur}}}},sprite:(y,M)=>new ie(ot,y,M),shape:(y,M)=>new xe(ot,y,M),text:(y,M)=>new ke(ot,y,M),group:y=>new Ps(ot).set(y!=null?y:{}),particles(y,M={}){const S=typeof y=="object"&&"type"in y?ot.shape(y).frame:y,_=new Ci(ot,S,M),O=M,{max:C,blend:Z,gravity:st,drag:$}=O,lt=ys(O,["max","blend","gravity","drag"]);return _.set(lt),Fe.add(_),_},tween:(y,M,S,_)=>b.tween(y,M,S,_),bake(y,M,S,_,O){return P.set(y,{w:M,h:S,draw:_,origin:O}),F.delete(y),ps.frame(y)},frame(y){var M,S,_,O;const C=F.get(y);if(C&&m.valid(C)&&(C.gen===0||C.scale===nt))return C;const Z=P.get(y);if(Z){const st=nt,$=m.bake(Z.w*st,Z.h*st,lt=>(lt.scale(st,st),Z.draw(lt)),st,(S=(M=Z.origin)==null?void 0:M.x)!=null?S:0,(O=(_=Z.origin)==null?void 0:_.y)!=null?O:0);return F.set(y,$),$}if(C)return C;throw new Error('[engine] no frame "'.concat(y,'": load it or bake it first'))},load(y){return te(this,null,function*(){yield Promise.all(Object.entries(y).map(([M,S])=>Po(M,S)))})},hands:y=>y===void 0?hs():hs().filter(M=>M.player===y),touched(y,M,S={}){var _;return y.updateWorld(),hn(y,hs(),M,(_=S.padding)!=null?_:0)},hits(y,M,S,_=0){return y.updateWorld(),Qs(y,M,S,_)},avatars:(y={})=>new xn(ot,So(y)),handMarkers(y={}){var M,S;const _=(M=y.radius)!=null?M:36,O=(S=y.look)!=null?S:"auto",C=new Float64Array(6),Z=Math.max(_*.12,3),st={type:"ring",r:_,lw:Z,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},$={type:"ring",r:_,lw:Z*1.8,stroke:Me,shadow:{color:Me,blur:_*.2}},lt=(X,H,q,ht,Zt,Jt)=>{const gs=H.w/H.scale;At(C,null,q-gs/2,ht-gs/2,0,1,1),X.r.quad(X.tex(H.surface),H,C,gs,gs,Zt,Jt,"normal")},Xt=X=>{let H=null,q=!1;return()=>(H&&m.valid(H.frame)&&H.frame.scale===nt&&q===Y.effects?H:(q=Y.effects,H=ot.shape(X))).frame},Ht=Xt(st),W=Xt($);return new Ra(ot,(X,H)=>{const q=O==="video"||O==="auto"&&Ft==="video",ht=Ht(),Zt=q?W():null;for(const Jt of hs())Zt&&lt(X,Zt,Jt.x,Jt.y,16777215,H),lt(X,ht,Jt.x,Jt.y,xt(Jt.color)[0],H)})},timeline:y=>b.timeline(y),animation(y,M){const S=typeof y=="string"?Fo(y):{frames:y},_=new Yt(ot,S,M);return Fe.add(_),_},bitmapFont(y,M){if(!M){const _=E.get(y);if(!_)throw new Error('[engine] no bitmap font "'.concat(y,'": load or make it first'));return _}const S="data"in M?Xn($e(M.data),M.pages):ca(ot,M);return E.set(y,S),S},players:()=>ni(),onFrame(y){return ri.add(y),()=>{ri.delete(y)}},onRender(y){return ai.add(y),()=>{ai.delete(y)}},onBackdrop(y){return ei.add(y),()=>{ei.delete(y)}},get hud(){return Rt||(Rt=document.createElement("div"),Rt.style.cssText="position:fixed;top:0;right:0;bottom:0;left:0;pointer-events:none;overflow:hidden",document.body.appendChild(Rt),zt()),Rt},random:(y=0,M=1)=>y+Math.random()*(M-y),start(){cs||(cs=!0,ue=0,oi=requestAnimationFrame(Bn))},pause(){Te=!0,ls()},resume(){Te=!1,ls()},destroy(){var y,M;cs=!1,cancelAnimationFrame(oi),Ln.forEach(S=>S()),removeEventListener("resize",zt),Gt==null||Gt.disconnect(),document.removeEventListener("visibilitychange",zn),(M=(y=document.fonts)==null?void 0:y.removeEventListener)==null||M.call(y,"loadingdone",Gn),b.clear(),Rr(ot),w.destroy(),p.destroy(),Rt==null||Rt.remove()}};function Fo(y){const M=I.get(y);if(M)return M;const S=[...new Set([...F.keys(),...P.keys()])].filter(_=>_.startsWith(y)).sort(Pr);if(!S.length)throw new Error('[engine] no animation or frames "'.concat(y,'\u2026"'));return{frames:S}}function Po(y,M){return te(this,null,function*(){var S,_;const O=M.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(O))return w.load(y,M);if(["woff","woff2","ttf","otf"].includes(O)){const $=new FontFace(y,"url(".concat(M,")"));document.fonts.add(yield $.load()),N++;return}const C=new URL(M,location.href);if(O==="fnt")return Hn(y,$e(yield(yield fetch(M)).text()),C);if(O==="json"){const $=yield(yield fetch(M)).json();if(Array.isArray($.chars)&&!$.frames)return Hn(y,$e($),C);const lt=yield Ks(new URL((_=(S=$.meta)==null?void 0:S.image)!=null?_:M.replace(/\.json$/,".png"),C).href);Co(y,$,Xe(lt));return}const Z=yield Ks(M),st=Xe(Z);v.add(st),F.set(y,{surface:st,x:0,y:0,w:Z.width,h:Z.height,scale:1,gen:0,ox:0,oy:0,margin:0})})}function Xn(y,M){return ha(y,M.map(S=>{const _=Xe(S);return v.add(_),_}))}function Hn(y,M,S){return te(this,null,function*(){E.set(y,Xn(M,yield Promise.all(M.pages.map(_=>Ks(new URL(_,S).href)))))})}function Co(y,M,S){var _,O,C,Z,st,$;v.add(S);const lt=Array.isArray(M.frames)?M.frames:Object.entries(M.frames).map(([W,X])=>fe(Mt({},X),{filename:W})),Xt=[],Ht=[];for(const W of lt){const X=W.frame,H=W.filename.replace(_n,"");W.rotated&&console.warn("[engine] ".concat(y,"/").concat(H," is rotated: export without rotation"));const q={surface:S,x:X.x,y:X.y,w:X.w,h:X.h,scale:1,gen:0,ox:0,oy:0,margin:0};W.trimmed&&W.sourceSize&&W.spriteSourceSize&&(q.sw=W.sourceSize.w,q.sh=W.sourceSize.h,q.tx=W.spriteSourceSize.x,q.ty=W.spriteSourceSize.y);const ht=W.scale9Borders;ht&&(q.slice=[ht.y,((_=q.sw)!=null?_:X.w)-ht.x-ht.w,((O=q.sh)!=null?O:X.h)-ht.y-ht.h,ht.x]),F.set("".concat(y,"/").concat(H),q),Xt.push("".concat(y,"/").concat(H)),Ht.push(((C=W.duration)!=null?C:0)/1e3)}for(const[W,X]of Object.entries((Z=M.animations)!=null?Z:{}))I.set("".concat(y,"/").concat(W),{frames:X.map(H=>"".concat(y,"/").concat(H.replace(_n,"")))});for(const W of($=(st=M.meta)==null?void 0:st.frameTags)!=null?$:[]){const X=[];for(let q=W.from;q<=W.to;q++)X.push(q);W.direction==="reverse"&&X.reverse(),W.direction==="pingpong"&&X.push(...X.slice(1,-1).reverse());const H=X.every(q=>Ht[q]>0);I.set("".concat(y,"/").concat(W.name),Mt({frames:X.map(q=>Xt[q])},H?{durations:X.map(q=>Ht[q])}:{}))}}return ps})}var _n=/\.(png|webp|jpe?g|gif|bmp)$/i;function Ks(t){return new Promise((e,s)=>{const i=new Image;i.onload=()=>e(i),i.onerror=()=>s(new Error("[engine] image did not load: ".concat(t))),i.src=t})}function Pa(t){return new Promise(e=>{const s=[];let i=0;const n=r=>{i&&s.push(r-i),i=r,s.length<t?requestAnimationFrame(n):e(s)};requestAnimationFrame(n)})}function Ca(t,e,s,i,n,r=()=>!1){return te(this,null,function*(){const a=i(),o=cn(e,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},a).frame,l=[],h=[],u=new Float64Array(6),f=.004,d=t.kind==="canvas2d"?t.canvas.getContext("2d"):null,g=St();let p=0;return yield new Promise(v=>{const m=x=>{p&&x-g>250&&l.push(x-p),p=x;const b=St();t.begin(0,0,a);const w=s();for(let A=0;A<300;A++){const T=x/1e3+A;At(u,null,A*37%n,A*53%rt,T,1,1),t.quad(w(o.surface),o,u,o.w/a,o.h/a,16777215,f,"normal")}for(let A=0;A<40;A++)t.ellipse(100+A*20,300,20,14,A,16746496,f),t.stroke([100+A*20,400,120+A*20,460,100+A*20,520],3,18,3368703,f,!1);t.end(),d==null||d.getImageData(0,0,1,1),x-g>250&&h.push(St()-b),x-g<750&&!r()?requestAnimationFrame(m):(t.begin(0,0,a),t.end(),v())};requestAnimationFrame(m)}),{intervals:l,cpu:h}})}var Na=64,Mn=32,Ia=0,La="fabi-cm-".concat(Math.random().toString(36).slice(2,7),"-"),An=new Set,kn=(t,e)=>{An.has(t)||(An.add(t),console.warn(e))},Oa=t=>new Da(t),Da=class{constructor(t){c(this,"r",t),c(this,"css","none"),c(this,"plans",new Di(Na)),c(this,"buf",new Float64Array(64)),c(this,"keys",[]),c(this,"classes",new Map),c(this,"live",new Set),c(this,"svgs",new Map),c(this,"t",0),c(this,"cur",null),c(this,"svgFn",e=>this.svg(e)),c(this,"scr",[]),c(this,"flip",0)}chain(t,e){var s,i;const n=this.r;let r=this.buf;r[0]=n.scale,r[1]=n.maxBlur;let a=2;for(let v=0;v<e.length;v++){const m=e[v];if(a+22>r.length){const b=new Float64Array(r.length*2);b.set(r),r=this.buf=b}let x=this.classes.get(m.constructor);x===void 0&&this.classes.set(m.constructor,x=this.classes.size),r[a++]=x,r[a++]=m.enabled?1:0,m.params&&(a=m.params(r,a))}const o=(i=(s=this.keys)[a])!=null?i:s[a]=new Float64Array(a);for(let v=0;v<a;v++)o[v]=r[v];const l=It(o);let h=this.plans.get(o,l);h||this.plans.set(o,h=this.plan(e),l);for(let v=0;v<h.svgs.length;v++){const m=h.svgs[v];m.used<0&&this.attach(m),m.used=this.t}n.skipped+=h.skip;let u=t;const f=n.rx0,d=n.ry0,g=n.rx1-f,p=n.ry1-d;for(let v=0;v<h.paints.length;v++)h.parts[v]&&(u=this.bake(u,h.parts[v])),e[h.paints[v]].paint2d(u.getContext("2d"),f,d,g,p);return this.css=h.parts[h.paints.length]||"none",u}tick(){const t=++this.t;if(!(t%Mn||!this.live.size))for(const e of this.live)t-e.used>Mn&&this.detach(e)}destroy(){for(const t of this.live)this.detach(t);this.plans.clear()}svg(t){if(typeof document=="undefined"||!document.body)return null;const e=Array.from({length:20},(i,n)=>{var r;return(r=t[n])!=null?r:0}).join(" ");let s=this.svgs.get(e);if(!s){const i="http://www.w3.org/2000/svg",n=document.createElementNS(i,"svg");n.setAttribute("width","0"),n.setAttribute("height","0"),n.setAttribute("aria-hidden","true"),n.style.position="absolute";const r=document.createElementNS(i,"filter"),a=La+ ++Ia;r.setAttribute("id",a),r.setAttribute("color-interpolation-filters","sRGB");const o=document.createElementNS(i,"feColorMatrix");o.setAttribute("type","matrix"),o.setAttribute("values",e),r.append(o),n.append(r),this.attach(s={key:e,id:a,el:n,used:this.t})}return this.cur.svgs.push(s),"url(#".concat(s.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){const e=this.r,s=this.cur={parts:[],paints:[],skip:0,svgs:[]};let i="";for(let n=0;n<t.length;n++){const r=t[n];if(!r.enabled)continue;if(r.kind===Es){s.skip++,kn("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}const a=e.support.filters&&r.css?r.css(e.scale,e.maxBlur,this.svgFn):null;a!==null?i+=i?" ".concat(a):a:r.paint2d?(s.parts.push(i),s.paints.push(n),i=""):(s.skip++,kn("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 s.parts.push(i),s}bake(t,e){const s=this.r,i=this.flip^=1;let n=this.scr[i];(!n||n.width!==s.canvas.width||n.height!==s.canvas.height)&&(n=this.scr[i]=document.createElement("canvas"),n.width=s.canvas.width,n.height=s.canvas.height);const r=n.getContext("2d"),a=s.rx0,o=s.ry0,l=s.rx1-a,h=s.ry1-o;return r.clearRect(a,o,l,h),r.filter=e,r.drawImage(t,a,o,l,h,a,o,l,h),r.filter="none",n}},Ua=64,is=17,Ba=t=>"".concat(Xs,"\nuniform sampler2D uTexture;\nuniform mat4 uM[").concat(t,"];\nuniform vec4 uO[").concat(t,"];\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(t,"; 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}"),za=()=>"".concat(Xs,"\nuniform sampler2D uTexture;\nuniform vec2 uDir;\nuniform vec2 uOff;\nuniform vec2 uTaps[").concat(is,"];\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(is,"; 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 Ga(t,e,s=new Float32Array(20)){for(let i=0;i<4;i++)for(let n=0;n<5;n++){let r=n===4?e[i*5+4]:0;for(let a=0;a<4;a++)r+=e[i*5+a]*t[a*5+n];s[i*5+n]=r}return t.set(s),t}var Xa=t=>new Ha(t),Ha=class{constructor(t){c(this,"r",t),c(this,"colorProg",null),c(this,"blurProg",null),c(this,"user",new Map),c(this,"uses",0),c(this,"userErr",new Map),c(this,"scratchT",new Map),c(this,"steps",[]),c(this,"mats",[]),c(this,"counts",[]),c(this,"colorN"),c(this,"fm",new Float32Array(20)),c(this,"fm2",new Float32Array(20)),c(this,"fm3",new Float32Array(20)),c(this,"m16"),c(this,"o4"),c(this,"taps",new Float32Array(is*2));const 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(){const t=this.r.gl;for(const e of this.scratchT.values())t.deleteTexture(e.gl),t.deleteFramebuffer(e.fb);this.scratchT.clear();for(const e of[this.colorProg,this.blurProg])e&&t.deleteProgram(e.p);for(const e of this.user.values())e.p&&t.deleteProgram(e.p.p);this.user.clear()}userProg(t,e){const s=this.user,i=s.get(t);if(i)return i.t=++this.uses,i.p;if(this.r.lost)return null;if(s.size>=Ua){let r="",a=1/0;for(const[l,h]of s)h.t<a&&(a=h.t,r=l);const o=s.get(r).p;o&&this.r.gl.deleteProgram(o.p),s.delete(r),this.userErr.delete(r)}let n;try{n=this.r.build(t)}catch(r){n=null;const a=r.message;this.userErr.set(t,a),e&&console.error("[engine] a shader filter does not compile: it is skipped.\n".concat(a))}return s.set(t,{p:n,t:++this.uses}),n}scratch(t,e){var s;const i=this.r,n=Math.ceil(i.canvas.width/t),r=Math.ceil(i.canvas.height/t),a=t*8+e;let o=(s=this.scratchT.get(a))!=null?s:null;return o&&(o.w!==n||o.h!==r)&&(i.drop(o),o=null),o||(o=i.target(n,r,t,!0),o?this.scratchT.set(a,o):this.scratchT.delete(a)),o}pass(t,e,s,i,n=!1){const r=this.r,a=r.gl;r.flush(),r.mapped=!1,r.bindFb(i),a.viewport(0,0,i.w,i.h),n||(a.disable(a.SCISSOR_TEST),a.clearColor(0,0,0,0),a.clear(a.COLOR_BUFFER_BIT)),r.use(t);const o=i.f;a.uniform2f(t.uScale,2/(o*i.w),-2/(o*i.h));const l=Math.floor(r.rx0/o)*o,h=Math.floor(r.ry0/o)*o,u=Math.min(Math.ceil(r.rx1/o),i.w)*o,f=Math.min(Math.ceil(r.ry1/o),i.h)*o,d=1/(s*e.width),g=1/(s*e.height);r.bScis=!1,r.batch.push(l,h,u,h,u,f,l,f,l*d,1-h*g,u*d,1-f*g,4294967295,r.slotOf(e)),r.flush()}post(t){var e,s;return t==="color"?(e=this.colorProg)!=null?e:this.colorProg=this.r.build(Ba(this.colorN)):(s=this.blurProg)!=null?s:this.blurProg=this.r.build(za())}linear(t,e){var s;const i=this.r,n=i.gl;i.bindTex((s=i.layerTex.get(t))!=null?s:null,0);const r=e?n.LINEAR:n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,r),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,r)}chain(t,e,s){const i=this.r,n=this.steps,r=i.scale,a=i.maxBlur;let o=0;for(let f=0;f<s.length;f++){const d=s[f];if(d.enabled)if(d.kind===Ms&&d.toMatrix){(!o||n[o-1]!==null)&&(n[o]=null,(!this.mats[o]||this.mats[o].length<20*this.colorN)&&(this.mats[o]=new Float32Array(20*this.colorN)),this.counts[o]=0,o++);const g=this.mats[o-1],p=this.counts[o-1];if(p<this.colorN)d.toMatrix(this.fm),g.set(this.fm,p*20),this.counts[o-1]=p+1;else{const v=(p-1)*20;for(let m=0;m<20;m++)this.fm2[m]=g[v+m];d.toMatrix(this.fm),Ga(this.fm2,this.fm,this.fm3),g.set(this.fm2,v)}}else d.kind===Es?this.userProg(d.source,!0)?n[o++]=d:i.skipped++:d.kind===As?Math.min(d.radius,a)*r>=.25&&(n[o++]=d):d.kind===ks?n[o++]=d:i.skipped++}if(!o)return!1;const l=i.gl;let h=t,u=-1;for(let f=0;f<o;f++){const d=f===o-1,g=u===0?1:0,p=d?null:this.scratch(1,g);if(!d&&!p)break;const v=n[f];if(v===null){const m=this.post("color");i.use(m);const x=this.mats[f],b=this.counts[f],w=this.m16,A=this.o4;for(let T=0;T<b;T++)for(let F=0;F<4;F++){for(let P=0;P<4;P++)w[T*16+P*4+F]=x[T*20+F*5+P];A[T*4+F]=x[T*20+F*5+4]}l.uniformMatrix4fv(i.u(m,"uM"),!1,w),l.uniform4fv(i.u(m,"uO"),A),l.uniform1i(i.u(m,"uK"),b),p?this.pass(m,h,1,p):i.final(m,h,1,e)}else if(v.kind===As)this.blur(h,u<0,Math.min(v.radius,a)*r,p,e,null);else if(v.kind===ks){const m=v,x=this.scratch(1,2);if(!x)break;this.blur(h,u<0,Math.max(Math.min(m.blur,a),0)*r,x,1,m);const b=p!=null?p:e<1?this.scratch(1,g):null;b?(this.pass(i.main,x.tex,1,b),this.pass(i.main,h,1,b,!0),p||i.final(i.main,b.tex,1,e)):(i.final(i.main,x.tex,1,1),i.final(i.main,h,1,1))}else{const m=v,x=this.userProg(m.source,!0);i.use(x);const b=i.canvas.width,w=i.canvas.height;l.uniform2f(i.u(x,"uResolution"),b,w),l.uniform1f(i.u(x,"uTime"),i.time),l.uniform4f(i.u(x,"uRect"),i.rx0/b,1-i.ry1/w,i.rx1/b,1-i.ry0/w);const A=m.uniforms;for(const T in A){const F=i.u(x,T);if(!F)continue;const P=A[T];typeof P=="number"?l.uniform1f(F,P):P.length===2?l.uniform2fv(F,P):P.length===3?l.uniform3fv(F,P):P.length===4?l.uniform4fv(F,P):P.length===1&&l.uniform1fv(F,P)}p?this.pass(x,h,1,p):i.final(x,h,1,e)}p&&(h=p.tex,u=g)}return i.remap(),!0}blur(t,e,s,i,n,r){const a=this.r,o=a.gl,l=this.post("blur");let h=1;for(;h<16&&s/h>8;)h*=2;e&&this.linear(t,!0);let u=t,f=1;const d=Math.sqrt(Math.max(s*s-(h*h-1)/12,0))/h,g=s>=.25?this.tapsFor(d):this.tapsFor(0);let p=!0;if(g>1){for(let m=2;m<=h&&p;m*=2){const x=this.scratch(m,0);x?(this.pass(a.main,u,f,x),u=x.tex,f=m):p=!1}const v=p?this.scratch(h,3):null;v&&(a.use(l),o.uniform2fv(a.u(l,"uTaps"),this.taps),o.uniform1i(a.u(l,"uN"),g),o.uniform2f(a.u(l,"uDir"),1/u.width,0),o.uniform2f(a.u(l,"uOff"),0,0),o.uniform1f(a.u(l,"uMode"),0),this.pass(l,u,f,v),u=v.tex)}if(a.use(l),o.uniform2fv(a.u(l,"uTaps"),this.taps),o.uniform1i(a.u(l,"uN"),g),o.uniform2f(a.u(l,"uDir"),0,1/u.height),r){const v=r.opacity,m=r.rgb;o.uniform4f(a.u(l,"uShadow"),(m>>16&255)/255*v,(m>>8&255)/255*v,(m&255)/255*v,v),o.uniform1f(a.u(l,"uMode"),1),o.uniform2f(a.u(l,"uOff"),-r.dx*a.scale/(f*u.width),r.dy*a.scale/(f*u.height))}else o.uniform1f(a.u(l,"uMode"),0),o.uniform2f(a.u(l,"uOff"),0,0);i?this.pass(l,u,f,i):a.final(l,u,f,n),e&&this.linear(t,!1)}tapsFor(t){const e=this.taps;if(e.fill(0),e[1]=1,t<.2)return 1;const s=Math.min(Math.ceil(3*t),(is-1)*2),i=-1/(2*t*t);let n=1,r=1;for(let a=1;a<=s;a+=2){const o=Math.exp(a*a*i),l=a+1<=s?Math.exp((a+1)*(a+1)*i):0,h=o+l;e[r*2]=(a*o+(a+1)*l)/h,e[r*2+1]=h,n+=2*h,r++}for(let a=0;a<r;a++)e[a*2+1]=e[a*2+1]/n;return r}},Tt=t=>Math.min(Math.max(t,0),1),vt=t=>Math.max(t,0),Ee=class{constructor(){c(this,"enabled",!0),bt.gl=Xa,bt.c2d=Oa}},Ut=class extends Ee{constructor(t){super(),c(this,"amount",t),c(this,"kind",Ms)}params(t,e){return t[e]=this.amount,e+1}};function ns(t,e,s){t.fill(0),t[0]=t[6]=t[12]=e,t[4]=t[9]=t[14]=s,t[18]=1}function rs(t,e){t.fill(0);for(let s=0;s<3;s++)for(let i=0;i<3;i++)t[s*5+i]=e[s*3+i];t[18]=1}var L=new Float64Array(9),qa=class extends Ut{toMatrix(t){ns(t,vt(this.amount),0)}css(){return"brightness(".concat(vt(this.amount),")")}},Wa=class extends Ut{toMatrix(t){const e=vt(this.amount);ns(t,e,.5-.5*e)}css(){return"contrast(".concat(vt(this.amount),")")}},ja=class extends Ut{toMatrix(t){const e=Tt(this.amount);ns(t,1-2*e,e)}css(){return"invert(".concat(Tt(this.amount),")")}},Ya=class extends Ut{toMatrix(t){const e=vt(this.amount);L[0]=.213+.787*e,L[1]=.715-.715*e,L[2]=.072-.072*e,L[3]=.213-.213*e,L[4]=.715+.285*e,L[5]=.072-.072*e,L[6]=.213-.213*e,L[7]=.715-.715*e,L[8]=.072+.928*e,rs(t,L)}css(){return"saturate(".concat(vt(this.amount),")")}},Va=class extends Ut{toMatrix(t){const e=1-Tt(this.amount);L[0]=.2126+.7874*e,L[1]=.7152-.7152*e,L[2]=.0722-.0722*e,L[3]=.2126-.2126*e,L[4]=.7152+.2848*e,L[5]=.0722-.0722*e,L[6]=.2126-.2126*e,L[7]=.7152-.7152*e,L[8]=.0722+.9278*e,rs(t,L)}css(){return"grayscale(".concat(Tt(this.amount),")")}},Qa=class extends Ut{toMatrix(t){const e=1-Tt(this.amount);L[0]=.393+.607*e,L[1]=.769-.769*e,L[2]=.189-.189*e,L[3]=.349-.349*e,L[4]=.686+.314*e,L[5]=.168-.168*e,L[6]=.272-.272*e,L[7]=.534-.534*e,L[8]=.131+.869*e,rs(t,L)}css(){return"sepia(".concat(Tt(this.amount),")")}},Ka=class extends Ut{get angle(){return this.amount}set angle(t){this.amount=t}toMatrix(t){const e=this.amount*Math.PI/180,s=Math.cos(e),i=Math.sin(e);L[0]=.213+s*.787-i*.213,L[1]=.715-s*.715-i*.715,L[2]=.072-s*.072+i*.928,L[3]=.213-s*.213+i*.143,L[4]=.715+s*.285+i*.14,L[5]=.072-s*.072-i*.283,L[6]=.213-s*.213-i*.787,L[7]=.715-s*.715+i*.715,L[8]=.072+s*.928+i*.072,rs(t,L)}css(){return"hue-rotate(".concat(this.amount,"deg)")}},Za=class extends Ut{constructor(t,e){super(e),c(this,"c",16777215),c(this,"cs",""),this.color=t}get color(){return this.c}set color(t){this.c=xt(t)[0],this.cs=ge(this.c)}params(t,e){return t[e]=this.amount,t[e+1]=this.c,e+2}toMatrix(t){const e=Tt(this.amount);ns(t,1-e,0),t[4]=(this.c>>16&255)/255*e,t[9]=(this.c>>8&255)/255*e,t[14]=(this.c&255)/255*e}css(){return null}paint2d(t,e,s,i,n){const r=Tt(this.amount);r<=0||(t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=r,t.globalCompositeOperation="source-atop",t.fillStyle=this.cs,t.fillRect(e,s,i,n),t.restore())}},Ja=class extends Ee{constructor(t){if(super(),c(this,"kind",Ms),c(this,"values"),t.length!==20)throw new Error("colorMatrix: 20 numbers expected (4 rows of 5), got ".concat(t.length));this.values=Array.from(t)}toMatrix(t){var e;for(let s=0;s<20;s++)t[s]=(e=this.values[s])!=null?e:0}params(t,e){var s;for(let i=0;i<20;i++)t[e+i]=(s=this.values[i])!=null?s:0;return e+20}css(t,e,s){return s?s(this.values):null}},$a=class extends Ee{constructor(t){super(),c(this,"radius",t),c(this,"kind",As)}params(t,e){return t[e]=this.radius,e+1}pad(t){return 3*Math.min(vt(this.radius),t)}css(t,e){return"blur(".concat(Math.min(vt(this.radius),e)*t,"px)")}},to=class extends Ee{constructor(t,e,s,i){super(),c(this,"dx",t),c(this,"dy",e),c(this,"blur",s),c(this,"kind",ks),c(this,"rgb",0),c(this,"a",1),this.color=i}get opacity(){return this.a}set opacity(t){this.a=Tt(t)}get color(){return this.rgb}set color(t){const[e,s]=xt(t);this.rgb=e,this.a=s}params(t,e){return t[e]=this.dx,t[e+1]=this.dy,t[e+2]=this.blur,t[e+3]=this.rgb,t[e+4]=this.a,e+5}pad(t){return 3*Math.min(vt(this.blur),t)+Math.max(Math.abs(this.dx),Math.abs(this.dy))}css(t,e){return"drop-shadow(".concat(this.dx*t,"px ").concat(this.dy*t,"px ").concat(2*Math.min(vt(this.blur),e)*t,"px ").concat(ge(this.rgb,this.opacity),")")}},eo="#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",so=t=>"".concat(eo).concat(t,"\n#undef main\nvoid main() {\n fabiUserMain();\n gl_FragColor *= vColor.a;\n}\n"),io=class extends Ee{constructor(t){var e,s;super(),c(this,"kind",Es),c(this,"source"),c(this,"uniforms",{}),c(this,"padding"),this.source=so(t.fragment),this.padding=(e=t.padding)!=null?e:0;for(const i in(s=t.uniforms)!=null?s:{}){const n=t.uniforms[i];this.uniforms[i]=typeof n=="number"?n:Float32Array.from(n)}}pad(){return vt(this.padding)}},no=(t,e=1)=>new Za(t,e),ro=t=>new qa(t),ao=t=>new Wa(t),oo=t=>new Ya(t),lo=(t=1)=>new Va(t),ho=(t=1)=>new Qa(t),co=t=>new Ka(t),uo=(t=1)=>new ja(t),fo=t=>new Ja(t),po=t=>new $a(t),go=(t,e,s,i="rgba(0,0,0,0.5)")=>new to(t,e,s,i);function mo(t){var e,s;const i=new io(t),n=(s=(e=bt.live)==null?void 0:e.filters())==null?void 0:s.check(i.source);if(n)throw new Error("shader(): the fragment does not compile:\n".concat(n));return i}var Zs="x y rotation scaleX scaleY alpha visible blend tint z hitRadius clip mask filters".split(" "),En="frameName _frame _w _h slice autoAnchor".split(" "),vo="fps loop speed onComplete durations".split(" "),Js=["anchorX","anchorY"],yo=[...Zs,...En,...vo,...Js],wo=[...Zs,...En,...Js],xo=[...Zs,...Js],Sn=t=>t instanceof Yt?yo:t instanceof ie?wo:xo;function bo(t){const e={},s=t;for(const i of Sn(t))e[i]=s[i];return t instanceof xe&&(e.spec=t.spec),t instanceof ke&&(e.text=t.text,e.style=t.style),t instanceof Yt&&(e.playing=t.playing),e}function Tn(t,e){const s=t;t instanceof xe&&t.spec!==e.spec&&(t.spec=e.spec),t instanceof ke&&(t.text=e.text,t.style!==e.style&&(s._style=e.style,s.dirty=!0)),t instanceof Yt&&t.gotoFrame(e.speed<0?t.frameCount-1:0);const i=t instanceof xe||t instanceof ke,n=Sn(t);for(let r=0;r<n.length;r++){const a=n[r];(!i||a!=="_frame"&&a!=="frameName")&&(s[a]=e[a])}}var Rn=class{constructor(t,e={}){c(this,"factory",t),c(this,"opts",e),c(this,"stats",{live:0,free:0,created:0}),c(this,"free",[]),c(this,"states",new Map),c(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;const s=this.states.get(e);Tn(e,s),e.visible=s.visible,e instanceof Yt&&s.playing&&e.play()}else{if(e=this.factory(),!(e instanceof Wt))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,bo(e)),e._pool=this,this.stats.created++}return this.stats.live++,t&&e.set(t),e}release(t){var e,s,i;const n=this.states.get(t);if(!(!n||t.destroyed)&&!t._free){if(this.opts.max!==void 0&&this.free.length>=this.opts.max)return t.destroy();(e=t.parent)==null||e.remove(t),t.kernel.tweens.stopAll(t),this.stats.live--,Tn(t,n),t instanceof Yt&&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){const e=t;if(this.states.delete(e))if(e._free){const s=this.free.indexOf(e);s>=0&&(this.free[s]=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(const t of[...this.states.keys()])t.destroy()}},_o=(t,e)=>new Rn(t,e);return qt.exports});