@fabiplay/engine 0.0.0-stage → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +78 -0
- package/README.md +113 -2
- package/dist/fabi-play-engine.d.ts +2423 -0
- package/dist/fabi-play-engine.js +1 -0
- package/dist/fabi-play-engine.lite.d.ts +2423 -0
- package/dist/fabi-play-engine.lite.js +1 -0
- package/dist/fabi-play-engine.lite.umd.js +6969 -0
- package/dist/fabi-play-engine.lite.umd.min.js +1 -0
- package/dist/fabi-play-engine.umd.js +9340 -0
- package/dist/fabi-play-engine.umd.min.js +1 -0
- package/dist/index.d.ts +2406 -0
- package/dist/index.development.js +6850 -0
- package/dist/index.js +105 -0
- package/dist/integrity.json +15 -0
- package/package.json +80 -3
|
@@ -0,0 +1 @@
|
|
|
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&<(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});
|