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