@fabi-play/engine 0.2.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fabi-play-engine.d.ts +19 -11
- package/dist/fabi-play-engine.js +13 -13
- package/dist/fabi-play-engine.lite.d.ts +19 -11
- package/dist/fabi-play-engine.lite.js +5 -5
- package/dist/fabi-play-engine.lite.umd.js +6 -1
- package/dist/fabi-play-engine.lite.umd.min.js +2 -2
- package/dist/fabi-play-engine.umd.js +268 -25
- package/dist/fabi-play-engine.umd.min.js +13 -13
- package/dist/index.d.ts +19 -11
- package/dist/index.development.js +5 -0
- package/dist/index.js +5 -5
- package/dist/integrity.json +9 -9
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @fabi-play/engine 0.
|
|
1
|
+
/*! @fabi-play/engine 0.5.0 (lite: load fabi-play.js first) | Fabi Play Kit License | https://docs.fabiplay.app */
|
|
2
2
|
(function (root, factory) {
|
|
3
3
|
var script = typeof document !== 'undefined' ? document.currentScript : null;
|
|
4
4
|
if (typeof define === 'function' && define.amd) define([], function () { return factory(script); });
|
|
@@ -113,6 +113,7 @@ var DEFAULT_AVATARS_BY_AGE = {
|
|
|
113
113
|
};
|
|
114
114
|
var DEFAULT_AVATARS = DEFAULT_AVATARS_BY_AGE["6-8"];
|
|
115
115
|
var toScreen = (view, p) => view ? { x: view.x + p.x * view.w, y: view.y + p.y * view.h } : { x: p.x, y: p.y };
|
|
116
|
+
var COVER_ASPECT = 16 / 9;
|
|
116
117
|
var POSE_HEADER = 12;
|
|
117
118
|
var POSE_BODY_BYTES = LANDMARKS * 4;
|
|
118
119
|
var poseBytes = (bodies) => POSE_HEADER + bodies * POSE_BODY_BYTES;
|
|
@@ -5268,6 +5269,10 @@ async function createEngine(opts = {}) {
|
|
|
5268
5269
|
};
|
|
5269
5270
|
unlisten.push(
|
|
5270
5271
|
play.on("start", (m) => lateHint(m?.device)),
|
|
5272
|
+
// The simple API knows muted only from the start (its getter is false before): read it again then.
|
|
5273
|
+
play.on("start", (m) => {
|
|
5274
|
+
if (typeof m?.muted === "boolean") sound.muted = m.muted;
|
|
5275
|
+
}),
|
|
5271
5276
|
play.on("frame", (m) => setPlayers(m?.players)),
|
|
5272
5277
|
play.on("players", (m) => setPlayers(m?.players)),
|
|
5273
5278
|
play.on("backdrop", (m) => setBackdrop(m?.backdrop, m?.view)),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @fabi-play/engine 0.2.0 (lite: load fabi-play.js first) | Fabi Play Kit License | https://docs.fabiplay.app */(function(Ds,_t){var ce=typeof document<"u"?document.currentScript:null;typeof define=="function"&&define.amd?define([],function(){return _t(ce)}):typeof module=="object"&&module&&module.exports?module.exports=_t(ce):Ds.FabiEngine=_t(ce)})(typeof globalThis<"u"?globalThis:typeof self<"u"?self:this,function(Ds){"use strict";var _t={exports:{}},ce=_t.exports,fe=Object.defineProperty,pn=Object.getOwnPropertyDescriptor,gn=Object.getOwnPropertyNames,mn=Object.prototype.hasOwnProperty,yn=(t,e,s)=>e in t?fe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,vn=(t,e)=>{for(var s in e)fe(t,s,{get:e[s],enumerable:!0})},wn=(t,e,s,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of gn(e))!mn.call(t,n)&&n!==s&&fe(t,n,{get:()=>e[n],enumerable:!(i=pn(e,n))||i.enumerable});return t},xn=t=>wn(fe({},"__esModule",{value:!0}),t),c=(t,e,s)=>yn(t,typeof e!="symbol"?e+"":e,s),Bs={};vn(Bs,{AnimatedSprite:()=>St,Atlas:()=>as,AvatarPainter:()=>xs,AvatarsNode:()=>qi,BitmapFont:()=>bs,DEFAULT_FONT:()=>Ei,EASE:()=>jt,Group:()=>ns,HALO:()=>ee,MAX_LAYERS:()=>es,NameTags:()=>vs,Node:()=>Et,NodePool:()=>Zi,Particles:()=>si,STAGE_HEIGHT:()=>Y,Shape:()=>Zt,ShelfPacker:()=>ii,Sound:()=>Ii,Sprite:()=>It,TIERS:()=>ut,Text:()=>se,Timeline:()=>Xi,Tweens:()=>$i,avatarPortrait:()=>kr,blur:()=>Ta,brightness:()=>wa,colorMatrix:()=>Ea,contrast:()=>xa,createAvatarRenderer:()=>Mr,createEngine:()=>qr,createRenderer:()=>ms,dropShadow:()=>Sa,grayscale:()=>Ma,handsOf:()=>Pi,hits:()=>ks,hueRotate:()=>Aa,invert:()=>_a,nodePool:()=>Ia,packColor:()=>Lt,parseBMFont:()=>Fe,parseColor:()=>ot,pickTier:()=>Oi,playerColor:()=>Ms,rendererOrder:()=>_i,rng:()=>Ln,saturate:()=>ba,sepia:()=>ka,shader:()=>Fa,shapeBounds:()=>ws,tier:()=>Ft,tint:()=>va,touching:()=>Ni,wrists:()=>Ci}),_t.exports=xn(Bs);var bn=33,zs={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},Mn=4,ue=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"],kn={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},Ha=kn["6-8"],An=(t,e)=>t?{x:t.x+e.x*t.w,y:t.y+e.y*t.h}:{x:e.x,y:e.y},_n=12,En=bn*4,Tn=t=>_n+t*En,Wa=Tn(Mn),Sn=t=>t.startsWith("fabi-play.")?`fablee-play.${t.slice(10)}`:null;function Fn(t,e,s=Sn(e)){if(!(!t||!s))try{const i=t.getItem(s);if(i===null)return;t.getItem(e)===null&&t.setItem(e,i),t.removeItem(s)}catch{}}var Gs=globalThis.FabiPlay?.avatars;if(!Gs)throw new Error("[engine] fabi-play-engine.lite.js needs fabi-play.js (with FabiPlay.avatars) loaded before it");var{avatarById:de,avatarShapes:Rn,BAND_BODY:Ya,DEFAULT_AVATAR:pe,drawShapes:Xs,frameOf:Cn,iconShapes:Pn}=Gs,Nt=()=>Float64Array.of(1,0,0,1,0,0);function ct(t,e,s,i,n,r,a){const h=n?Math.cos(n):1,l=n?Math.sin(n):0,o=h*r,u=l*r,f=-l*a,p=h*a;if(!e)return t[0]=o,t[1]=u,t[2]=f,t[3]=p,t[4]=s,t[5]=i,t;const g=e[0],d=e[1],y=e[2],m=e[3];return t[0]=g*o+y*u,t[1]=d*o+m*u,t[2]=g*f+y*p,t[3]=d*f+m*p,t[4]=g*s+y*i+e[4],t[5]=d*s+m*i+e[5],t}function Nn(t,e,s){const i=t[0]*t[3]-t[1]*t[2];if(Math.abs(i)<1e-12)return null;const n=e-t[4],r=s-t[5];return[(t[3]*n-t[2]*r)/i,(-t[1]*n+t[0]*r)/i]}var $s={white:16777215,black:0,red:16711680,transparent:0},Wt=new Map;function ot(t){if(typeof t=="number")return[t&16777215,1];const e=Wt.get(t);if(e)return e;let s=[16777215,1];const i=t.trim().toLowerCase();if(i[0]==="#"){const n=i.slice(1),r=n.length<=4?[...n].map(h=>h+h).join(""):n,a=parseInt(r.slice(0,6),16);Number.isFinite(a)&&(s=[a,r.length===8?parseInt(r.slice(6,8),16)/255:1])}else if(i.startsWith("rgb")){const n=i.match(/-?\d*\.?\d+%?/g)?.map(o=>o.endsWith("%")?parseFloat(o)/100*255:parseFloat(o))??[],[r=255,a=255,h=255]=n,l=n[3]===void 0?1:i.match(/,\s*[\d.]+%\s*\)$/)?n[3]/255:n[3];s=[(We(r)<<16|We(a)<<8|We(h))>>>0,Math.min(Math.max(l,0),1)]}else if(i in $s)s=[$s[i],i==="transparent"?0:1];else if(typeof document<"u"){const n=document.createElement("canvas").getContext("2d");if(n){n.fillStyle="#ffffff",n.fillStyle=i;const r=n.fillStyle;if(r!==i)return Wt.set(t,s=ot(r)),s}}return Wt.size>512&&Wt.clear(),Wt.set(t,s),s}var We=t=>Math.min(Math.max(Math.round(t),0),255);function Lt(t,e,s=!1){const i=Math.min(Math.max(e,0),1),n=(t>>16&255)*i,r=(t>>8&255)*i,a=(t&255)*i,h=s?0:i*255;return(Math.round(h)<<24|Math.round(a)<<16|Math.round(r)<<8|Math.round(n))>>>0}var Yt=(t,e=1)=>`rgba(${t>>16&255},${t>>8&255},${t&255},${e})`;function qs(t,e){if(t===16777215)return e;if(e===16777215)return t;const s=i=>Math.round((t>>i&255)*(e>>i&255)/255);return(s(16)<<16|s(8)<<8|s(0))>>>0}var jt={linear:t=>t,quadIn:t=>t*t,quadOut:t=>t*(2-t),quadInOut:t=>t<.5?2*t*t:-1+(4-2*t)*t,cubicOut:t=>1-(1-t)**3,sineInOut:t=>-(Math.cos(Math.PI*t)-1)/2,backOut:t=>1+(1.70158+1)*(t-1)**3+1.70158*(t-1)**2,elasticOut:t=>t===0||t===1?t:2**(-10*t)*Math.sin((t*10-.75)*(2*Math.PI/3))+1,bounceOut:t=>t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375};function Ln(t){let e=t>>>0;return()=>{e=e+1831565813>>>0;let s=e;return s=Math.imul(s^s>>>15,s|1),s^=s+Math.imul(s^s>>>7,s|61),((s^s>>>14)>>>0)/4294967296}}var Vt=1,Hs=2,ge=0,it=1,In=4294967295,A={cap:0,epoch:0,x:new Float64Array(0),y:new Float64Array(0),rot:new Float64Array(0),sx:new Float64Array(0),sy:new Float64Array(0),alpha:new Float64Array(0),la:new Float64Array(0),lb:new Float64Array(0),lc:new Float64Array(0),ld:new Float64Array(0),world:new Float64Array(0),tint:new Uint32Array(0),flags:new Uint8Array(0),moved:new Uint8Array(0),dirty:new Uint8Array(0),gen:new Uint32Array(0),parent:new Int32Array(0),first:new Int32Array(0),next:new Int32Array(0),prev:new Int32Array(0),stamp:new Uint32Array(0),pass:0,free:new Int32Array(0),freeHead:0,freeCount:0,top:2},gt=[],On="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function Ws(t){const e=A;for(const i of On){const n=e[i],r=new n.constructor(i==="world"?t*6:t);r.set(n),e[i]=r}const s=new Int32Array(t);for(let i=0;i<A.freeCount;i++)s[i]=A.free[(A.freeHead+i)%A.cap];for(A.free=s,A.freeHead=0,A.cap=t,A.epoch++;gt.length<t;)gt.push(null)}function Ye(t){A.x[t]=A.y[t]=A.rot[t]=0,A.sx[t]=A.sy[t]=A.alpha[t]=1,A.la[t]=A.ld[t]=1,A.lb[t]=A.lc[t]=0;const e=t*6,s=A.world;s[e]=s[e+3]=1,s[e+1]=s[e+2]=s[e+4]=s[e+5]=0,A.tint[t]=16777215,A.flags[t]=Vt|Hs,A.moved[t]=1,A.dirty[t]=0,A.parent[t]=A.first[t]=A.next[t]=A.prev[t]=-1}Ws(256),Ye(ge),A.flags[ge]=0,Ye(it),A.flags[it]=0;function Un(){let t;if(A.freeCount){t=A.free[A.freeHead],A.freeHead=(A.freeHead+1)%A.cap,A.freeCount--;const e=gt[t];e&&(e._i=ge,e._g=-1,gt[t]=null)}else A.top===A.cap&&Ws(A.cap*2),t=A.top++;return Ye(t),t}function Ys(t,e){je(t);for(let i=A.first[t];i>=0;){const n=A.next[i];A.parent[i]=A.next[i]=A.prev[i]=-1,i=n}A.first[t]=-1,A.flags[t]=A.flags[t]&~Hs,A.moved[t]=0;const s=A.gen[t]+1;A.gen[t]=s,s!==In&&(e&&(gt[t]=e),A.free[(A.freeHead+A.freeCount)%A.cap]=t,A.freeCount++)}function Dn(t){for(let e=0;e<gt.length;e++){const s=gt[e];s&&t(s)&&(s._i=ge,s._g=-1,gt[e]=null)}}function Bn(t,e){je(t);const s=A.first[e];A.parent[t]=e,A.next[t]=s,A.prev[t]=-1,s>=0&&(A.prev[s]=t),A.first[e]=t,A.moved[t]=1}function je(t){const e=A.parent[t];if(e<0)return;const s=A.next[t],i=A.prev[t];i>=0?A.next[i]=s:A.first[e]=s,s>=0&&(A.prev[s]=i),A.parent[t]=A.next[t]=A.prev[t]=-1}var Qt={root:-1,gen:-1,world:new Float64Array(6)};function zn(t){const e=++A.pass,s=A.world,i=t*6,n=Qt.world;let r=Qt.root!==t||Qt.gen!==A.gen[t];for(let a=0;a<6;a++)n[a]!==s[i+a]&&(r=!0),n[a]=s[i+a];Qt.root=t,Qt.gen=A.gen[t],A.stamp[t]=r?e:e-1}function Gn(t){A.stamp[t]=A.pass}function js(t){for(let e=A.first[t];e>=0;){const s=A.next[e];js(e),e=s}Ys(t)}var Ve=typeof FinalizationRegistry=="function"?new FinalizationRegistry(t=>A.gen[t.i]===t.g&&js(t.i)):null;function Vs(t){t._reg||!Ve||(t._reg=!0,Ve.register(t,{i:t._i,g:t._g},t))}function Xn(t){t._reg&&Ve.unregister(t)}var Qe=1,Ke=2,Ze=3,Je=4;function ts(t){if(t){for(let e=0;e<t.length;e++)if(t[e].enabled)return!0}return!1}function $n(t,e){let s=0;for(let i=0;i<t.length;i++){const n=t[i];n.enabled&&n.pad&&(s+=n.pad(e))}return s}var ht={gl:null,c2d:null,live:null},U=new Float64Array(3),es=4,qn=1,ss=()=>qn++,q=Nt(),S=A,Et=class{constructor(t){c(this,"kernel",t),c(this,"_i",Un()),c(this,"_g",S.gen[this._i]),c(this,"_wv",null),c(this,"_wi",-1),c(this,"_we",-1),c(this,"blend","normal"),c(this,"_data",null),c(this,"parent",null),c(this,"hitRadius",null),c(this,"clip",null),c(this,"mask",null),c(this,"filters",null),c(this,"_z",0),c(this,"anchorX",0),c(this,"anchorY",0),c(this,"_pool",null),c(this,"_free",!1),c(this,"_reg",!1)}get x(){return S.x[this._i]}set x(t){const e=this._i||it;S.x[e]=t,S.moved[e]=1}get y(){return S.y[this._i]}set y(t){const e=this._i||it;S.y[e]=t,S.moved[e]=1}get rotation(){return S.rot[this._i]}set rotation(t){const e=this._i||it;S.rot[e]=t,S.dirty[e]=S.moved[e]=1}get scaleX(){return S.sx[this._i]}set scaleX(t){const e=this._i||it;S.sx[e]=t,S.dirty[e]=S.moved[e]=1}get scaleY(){return S.sy[this._i]}set scaleY(t){const e=this._i||it;S.sy[e]=t,S.dirty[e]=S.moved[e]=1}get alpha(){return S.alpha[this._i]}set alpha(t){const e=this._i||it;S.alpha[e]=t,S.moved[e]=1}get visible(){return(S.flags[this._i]&Vt)!==0}set visible(t){const e=this._i||it;t?S.flags[e]=S.flags[e]|Vt:S.flags[e]=S.flags[e]&~Vt,S.moved[e]=1}get destroyed(){return S.gen[this._i]!==this._g}get world(){const t=this._i||it;return(this._wi!==t||this._we!==S.epoch)&&(this._wv=S.world.subarray(t*6,t*6+6),this._wi=t,this._we=S.epoch),this._wv}get data(){return this._data??(this._data={})}set data(t){this._data=t}get scale(){return this.scaleX}set scale(t){this.scaleX=this.scaleY=t}get z(){return this._z}set z(t){t!==this._z&&(this._z=t,this.parent&&(this.parent.sortDirty=!0))}get tint(){return S.tint[this._i]}set tint(t){S.tint[this._i||it]=typeof t=="number"?t&16777215:ot(t)[0]}set anchor(t){typeof t=="number"?this.anchorX=this.anchorY=t:(this.anchorX=t.x,this.anchorY=t.y)}get width(){return 0}set width(t){}get height(){return 0}set height(t){}set(t){for(const e in t){const s=t[e];s!==void 0&&(this[e]=s)}return this}destroy(){this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),Ys(this._i,this),Xn(this),this.kernel.tweens.stopAll(this),this._pool?.forget(this))}updateWorld(){const t=this.parent?this.parent.updateWorld():null;return ct(this.world,t,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(t,e,s){}};function Hn(t){Dn(e=>e.kernel===t)}var is=!1,Qs=Object.freeze([]),ns=class dn extends Et{constructor(e){super(e),c(this,"children",Qs),c(this,"sortDirty",!1),c(this,"dead",!1),Vs(this)}add(e,...s){this.adopt(e);for(let i=0;i<s.length;i++)this.adopt(s[i]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&Bn(e._i,this._i),this.children===Qs&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||Vs(e)}detach(e){const s=this.children,i=s.indexOf(e);if(i>=0){for(let n=i+1;n<s.length;n++)s[n-1]=s[n];s.pop()}e.parent===this&&(e.parent=null,e.destroyed||je(e._i))}clear(){for(const e of this.children)e.destroy()}destroy(){for(const e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(const s of this.children)s.destroyed?s.parent===this&&(s.parent=null):this.children[e++]=s;this.children.length=e}for(const e of this.children)e instanceof dn&&e.sweep()}draw(e,s,i){if(is)return S.parent[this._i]<0&&!this.destroyed&&Gn(this._i),this.drawChildren(e,s,i);is=!0;try{this.destroyed||zn(this._i),this.drawChildren(e,s,i)}finally{is=!1}}drawChildren(e,s,i){if(this.sortDirty){const h=new Map(this.children.map((l,o)=>[l,o]));this.children.sort((l,o)=>l.z-o.z||h.get(l)-h.get(o)),this.sortDirty=!1}const n=this.children,r=this._i,a=S.stamp[r]===S.pass;for(let h=0;h<n.length;h++){const l=n[h],o=l._i,u=S.alpha[o];if(S.gen[o]!==l._g||!(S.flags[o]&Vt)||u<=0)continue;if(a||S.moved[o]){S.moved[o]=0,S.stamp[o]=S.pass;let g,d,y,m;if(S.dirty[o]){S.dirty[o]=0;const D=S.rot[o],W=D?Math.cos(D):1,X=D?Math.sin(D):0,z=S.sx[o],$t=S.sy[o];S.la[o]=g=W*z,S.lb[o]=d=X*z,S.lc[o]=y=-X*$t,S.ld[o]=m=W*$t}else g=S.la[o],d=S.lb[o],y=S.lc[o],m=S.ld[o];const w=S.world,x=S.x[o],_=S.y[o],M=o*6,k=r*6,F=w[k],R=w[k+1],N=w[k+2],I=w[k+3];w[M]=F*g+N*d,w[M+1]=R*g+I*d,w[M+2]=F*y+N*m,w[M+3]=R*y+I*m,w[M+4]=F*x+N*_+w[k+4],w[M+5]=R*x+I*_+w[k+5]}const f=s*u,p=qs(i,S.tint[o]);l.clip||l.mask||l.filters?Zs(e,l,f,p):l.draw(e,f,p)}}},V=new Float64Array(128),Tt=0,rs=new Float64Array(8);function Ks(t,e,s,i){e.clip||e.mask||e.filters?Zs(t,e,s,i):e.draw(t,s,i)}function Zs(t,e,s,i){const n=t.r,r=e.world,a=e.clip;let h=!1,l=!1;if(a)if(Math.abs(r[1])<1e-9&&Math.abs(r[2])<1e-9&&Tt<32){const f=r[0]*a.x+r[4],p=r[0]*(a.x+a.width)+r[4],g=r[3]*a.y+r[5],d=r[3]*(a.y+a.height)+r[5];let y=Math.min(f,p),m=Math.max(f,p),w=Math.min(g,d),x=Math.max(g,d);if(Tt){const M=(Tt-1)*4;y=Math.max(y,V[M]),w=Math.max(w,V[M+1]),m=Math.min(m,V[M+2]),x=Math.min(x,V[M+3])}const _=Tt++*4;V[_]=y,V[_+1]=w,V[_+2]=m,V[_+3]=x,n.clip(y,w,Math.max(m-y,0),Math.max(x-w,0)),l=!0}else h=!0;const o=e.mask&&e.mask.visible?e.mask:null,u=ts(e.filters)?e.filters:null;try{if(h&&n.beginLayer(),o&&n.beginLayer(),u?(e.draw(t,n.beginLayer()?1:s,i),n.endLayer(s,u)):e.draw(t,s,i),o&&(n.beginMask(),ct(o.world,r,o.x,o.y,o.rotation,o.scaleX,o.scaleY),Ks(t,o,o.alpha,16777215),n.endLayer(1)),h&&a){n.beginMask();for(let f=0;f<4;f++){const p=f===1||f===2?a.x+a.width:a.x,g=f>1?a.y+a.height:a.y;rs[f*2]=r[0]*p+r[2]*g+r[4],rs[f*2+1]=r[1]*p+r[3]*g+r[5]}n.polygon(rs,4,16777215,1),n.endLayer(1)}}finally{if(l)if(Tt--,Tt){const f=(Tt-1)*4;n.clip(V[f],V[f+1],V[f+2]-V[f],V[f+3]-V[f+1])}else n.unclip()}}var It=class extends Et{constructor(t,e,s){super(t),c(this,"_frame",null),c(this,"_w",null),c(this,"_h",null),c(this,"slice",0),c(this,"autoAnchor",!0),c(this,"frameName",null),e&&(this.frame=e),s?.anchor===void 0&&this.useFrameAnchor(),s&&this.set(s)}get frame(){return this._frame}set frame(t){this.frameName=typeof t=="string"?t:null,this._frame=typeof t=="string"?this.kernel.frame(t):t,this.autoAnchor&&this.useFrameAnchor()}set anchor(t){this.autoAnchor=!1,super.anchor=t}get naturalWidth(){const t=this.frameNow();return t?(t.sw??t.w)/t.scale-t.margin*2:0}get naturalHeight(){const t=this.frameNow();return t?(t.sh??t.h)/t.scale-t.margin*2:0}get width(){return this._w??this.naturalWidth}set width(t){this._w=t}get height(){return this._h??this.naturalHeight}set height(t){this._h=t}sizeQ(t){Dt[0]=this._w??(t.sw??t.w)/t.scale-t.margin*2,Dt[1]=this._h??(t.sh??t.h)/t.scale-t.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){const t=this._frame;if(!t)return;const e=(t.sw??t.w)/t.scale-t.margin*2,s=(t.sh??t.h)/t.scale-t.margin*2;this.anchorX=e>0?(t.ox-t.margin)/e:0,this.anchorY=s>0?(t.oy-t.margin)/s:0}draw(t,e,s){const i=this.frameNow();if(!i)return;const n=Dt;this.sizeQ(i),n[2]=this.anchorX,n[3]=this.anchorY,n[4]=e,Wn(t,i,this.world,this.slice,s,this.blend)}},Ot=new Float64Array(12),Ut=new Float64Array(12),Kt={x:0,y:0,w:0,h:0};function Js(t,e,s,i,n,r){e=Math.max(e,0),s=Math.max(s,0),i=Math.max(i,0);const a=s+i>n?s*n/(s+i):s,h=s+i>n?i*n/(s+i):i;let l=a/r,o=h/r;if(l+o>e){const u=e/(l+o);l*=u,o*=u}t[0]=0,t[1]=l,t[2]=0,t[3]=a,t[4]=l,t[5]=e-l-o,t[6]=a,t[7]=n-a-h,t[8]=e-o,t[9]=o,t[10]=n-h,t[11]=h}var Dt=new Float64Array(5);function Wn(t,e,s,i,n,r){const a=Dt,h=a[0],l=a[1],o=a[2],u=a[3],f=a[4],p=t.tex(e.surface),g=i===0?e.slice??0:i;if(g===0){const M=(e.sw??e.w)/e.scale-e.margin*2,k=(e.sh??e.h)/e.scale-e.margin*2,F=M>0?h/M:1,R=k>0?l/k:1,N=-o*h+((e.tx??0)/e.scale-e.margin)*F,I=-u*l+((e.ty??0)/e.scale-e.margin)*R;me(s,N,I),U[0]=e.w/e.scale*F,U[1]=e.h/e.scale*R,U[2]=f,t.r.quadQ(p,e,q,n,r);return}const d=e.tx??0,y=e.ty??0,m=(e.sw??e.w)-e.w-d,w=(e.sh??e.h)-e.h-y,x=-o*h-e.margin+d/e.scale,_=-u*l-e.margin+y/e.scale;if(Js(Ot,h+e.margin*2-(d+m)/e.scale,(typeof g=="number"?g:g[3])-d,(typeof g=="number"?g:g[1])-m,e.w,e.scale),Js(Ut,l+e.margin*2-(y+w)/e.scale,(typeof g=="number"?g:g[0])-y,(typeof g=="number"?g:g[2])-w,e.h,e.scale),me(s,x,_),U[2]=f,!t.r.nineQ?.(p,e,Ot,Ut,q,n,r))for(let M=0;M<12;M+=4){const k=Ut[M+1],F=Ut[M+3];if(!(k<=0||F<=0))for(let R=0;R<12;R+=4){const N=Ot[R+1],I=Ot[R+3];N<=0||I<=0||(Kt.x=e.x+Ot[R+2],Kt.y=e.y+Ut[M+2],Kt.w=I,Kt.h=F,me(s,x+Ot[R],_+Ut[M]),U[0]=N,U[1]=k,U[2]=f,t.r.quadQ(p,Kt,q,n,r))}}}function me(t,e,s){q[0]=t[0],q[1]=t[1],q[2]=t[2],q[3]=t[3],q[4]=t[0]*e+t[2]*s+t[4],q[5]=t[1]*e+t[3]*s+t[5]}var Zt=class extends It{constructor(t,e,s={}){super(t,null),c(this,"_spec"),c(this,"baked",null),c(this,"bakedEffects",!0),this._spec=e,this.bake(),s.anchor===void 0&&this.useFrameAnchor(),this.set(s)}get spec(){return this._spec}set spec(t){this._spec=t,this.baked=null,this._w=this._h=null,this.bake()}bake(){const t=this.kernel;return this.baked&&t.atlas.valid(this.baked.frame)&&this.baked.frame.scale===t.pixelScale&&this.bakedEffects===t.effects?this.baked:(this.bakedEffects=t.effects,this.baked=t.shape(this._spec),this._frame=this.baked.frame,this.slice=this.baked.slice,this.baked)}frameNow(){return this.bake().frame}sizeQ(){const t=this.bake();Dt[0]=this._w??t.w,Dt[1]=this._h??t.h}get width(){return this._w??this.bake().w}set width(t){this._w=t}get height(){return this._h??this.bake().h}set height(t){this._h=t}},ti=(t,e,s)=>t===void 0?e:typeof t=="number"?t:t[0]+(t[1]-t[0])*s(),ei=class le extends Et{constructor(e,s,i={}){super(e),c(this,"max"),c(this,"f"),c(this,"tints"),c(this,"count",0),c(this,"gravity"),c(this,"drag"),c(this,"frameRef"),c(this,"random",Math.random),this.frameRef=s,this.max=Math.max(1,Math.floor(i.max??200)),this.f=new Float32Array(this.max*le.W),this.tints=new Uint32Array(this.max),this.blend=i.blend??"normal",this.gravity=i.gravity??0,this.drag=i.drag??1}get alive(){return this.count}burst(e,s,i,n={}){const r=le.W,a=this.random,h=n.tint===void 0?16777215:ot(n.tint)[0];for(let l=0;l<i;l++){let o=this.count;if(o>=this.max){let y=0,m=1/0;for(let w=0;w<this.max;w++){const x=this.f[w*r+5]-this.f[w*r+4];x<m&&(m=x,y=w)}o=y}else this.count++;const u=(n.angle??0)+(n.spread===void 0?a()*Math.PI*2:(a()-.5)*n.spread),f=ti(n.speed,200,a),p=Array.isArray(n.scale)?n.scale[0]:n.scale??1,g=Array.isArray(n.scale)?n.scale[1]:n.scale??1,d=o*r;this.f[d]=e,this.f[d+1]=s,this.f[d+2]=Math.cos(u)*f,this.f[d+3]=Math.sin(u)*f,this.f[d+4]=0,this.f[d+5]=Math.max(ti(n.life,.8,a),.01),this.f[d+6]=a()*Math.PI*2,this.f[d+7]=(a()-.5)*2*(n.spin??0),this.f[d+8]=p,this.f[d+9]=g,this.f[d+10]=n.alpha??1,this.tints[o]=h}}update(e){const s=le.W,i=this.f,n=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let r=0;r<this.count;){const a=r*s;if(i[a+4]=i[a+4]+e,i[a+4]>=i[a+5]){const h=--this.count;r!==h&&(i.copyWithin(a,h*s,h*s+s),this.tints[r]=this.tints[h]);continue}i[a+3]=(i[a+3]+this.gravity*e)*n,i[a+2]=i[a+2]*n,i[a]=i[a]+i[a+2]*e,i[a+1]=i[a+1]+i[a+3]*e,i[a+6]=i[a+6]+i[a+7]*e,r++}}clear(){this.count=0}draw(e,s,i){if(!this.count)return;const n=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,r=le.W,a=this.f,h=this.world,l=n.w/n.scale,o=n.h/n.scale;for(let u=0;u<this.count;u++){const f=u*r,p=a[f+4]/a[f+5],g=a[f+8]+(a[f+9]-a[f+8])*p,d=s*a[f+10]*(1-p*p),y=a[f+6],m=Math.cos(y)*g,w=Math.sin(y)*g,x=a[f],_=a[f+1],M=h[0],k=h[1],F=h[2],R=h[3],N=M*m+F*w,I=k*m+R*w,D=F*m-M*w,W=R*m-k*w;q[0]=N,q[1]=I,q[2]=D,q[3]=W,q[4]=M*x+F*_+h[4]-(N*l+D*o)/2,q[5]=k*x+R*_+h[5]-(I*l+W*o)/2,U[0]=l,U[1]=o,U[2]=d,e.r.quadQ(e.tex(n.surface),n,q,qs(i,this.tints[u]),this.blend)}}};c(ei,"W",11);var si=ei,St=class extends It{constructor(t,e,s={}){const{fps:i,loop:n,playing:r,speed:a,onComplete:h,...l}=s;if(!e.frames.length)throw new Error("[engine] an animation needs at least one frame");super(t,e.frames[0],l),c(this,"frames"),c(this,"durations"),c(this,"fps"),c(this,"loop"),c(this,"speed"),c(this,"onComplete"),c(this,"_playing"),c(this,"index",0),c(this,"t",0),this.frames=e.frames,this.durations=e.durations&&i===void 0?e.durations:null,this.fps=i??12,this.loop=n!==!1,this.speed=a??1,this.onComplete=h??null,this._playing=r!==!1,this.speed<0&&this.show(e.frames.length-1)}get frameIndex(){return this.index}get frameCount(){return this.frames.length}get playing(){return this._playing}play(){return!this.loop&&!this._playing&&this.index===(this.speed<0?0:this.frames.length-1)&&this.show(this.speed<0?this.frames.length-1:0),this._playing=!0,this}stop(){return this._playing=!1,this}gotoFrame(t){const e=this.frames.length;return this.show((Math.floor(t)%e+e)%e),this.t=0,this}gotoAndPlay(t){return this._playing=!0,this.gotoFrame(t)}gotoAndStop(t){return this._playing=!1,this.gotoFrame(t)}show(t){t===this.index&&this._frame||(this.index=t,this.frame=this.frames[t])}secondsOf(t){const e=this.durations?.[t];return e!==void 0&&e>0?e:1/Math.max(this.fps,.001)}update(t){if(!this._playing||this.destroyed||this.speed===0)return;const e=this.frames.length,s=this.speed<0;this.t+=t*Math.abs(this.speed);let i=this.index;for(let n=0;n<1e3;n++){const r=this.secondsOf(i);if(this.t<r)break;this.t-=r;const a=s?i-1:i+1;if(a<0||a>=e){if(!this.loop){this.t=0,this._playing=!1,this.show(i),this.onComplete?.();return}i=s?e-1:0}else i=a}this.show(i)}},Yn=(t,e)=>t.localeCompare(e,void 0,{numeric:!0}),ii=class{constructor(t,e,s=2){c(this,"width",t),c(this,"height",e),c(this,"padding",s),c(this,"shelves",[]),c(this,"free",[]),c(this,"bottom",0)}alloc(t,e){const s=Math.ceil(t)+this.padding*2,i=Math.ceil(e)+this.padding*2;if(s>this.width||i>this.height)return null;for(let a=0;a<this.free.length;a++){const h=this.free[a];if(h.w>=s&&h.h>=i&&h.w*h.h<=s*i*2)return this.free.splice(a,1),this.inner(h.x,h.y,t,e)}let n=null;for(const a of this.shelves)a.h>=i&&a.h<=i*1.5+8&&this.width-a.x>=s&&(!n||a.h<n.h)&&(n=a);if(!n)if(this.bottom+i>this.height){for(const a of this.shelves)a.h>=i&&this.width-a.x>=s&&(n=a);if(!n)return null}else n={y:this.bottom,h:i,x:0},this.shelves.push(n),this.bottom+=i;const r=n.x;return n.x+=s,this.inner(r,n.y,t,e)}release(t){this.free.push({x:t.x-this.padding,y:t.y-this.padding,w:Math.ceil(t.w)+this.padding*2,h:Math.ceil(t.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(t,e,s,i){return{x:t+this.padding,y:e+this.padding,w:s,h:i}}},ye=t=>({source:t,texture:null,pending:[]}),as=class{constructor(t=2048,e=4){c(this,"pageSize",t),c(this,"maxPages",e),c(this,"pages",[]),c(this,"gen",1),c(this,"onPage",()=>{}),c(this,"onDrop",()=>{})}valid(t){return!!t&&(t.gen===this.gen||t.gen===0)}bake(t,e,s,i=1,n=0,r=0,a=0){const h=Math.max(1,Math.ceil(t)),l=Math.max(1,Math.ceil(e)),o=document.createElement("canvas");o.width=h,o.height=l;const u=o.getContext("2d");return s(u),this.put(o,h,l,i,n,r,a)}add(t,e=1,s=0,i=0){const n=document.createElement("canvas");return n.width=Math.max(1,t.width),n.height=Math.max(1,t.height),n.getContext("2d").drawImage(t,0,0),this.put(n,n.width,n.height,e,s,i,0)}release(t){if(t.gen!==this.gen)return;this.pages.find(s=>s.surface===t.surface)?.packer.release(t)}rebake(t,e,s,i,n=t.w,r=t.h){if(!this.valid(t)||e>n||s>r)return null;const a=Math.max(1,Math.ceil(e)),h=Math.max(1,Math.ceil(s)),l=this.pages.find(u=>u.surface===t.surface);if(!l)return null;const o=document.createElement("canvas");return o.width=Math.ceil(n),o.height=Math.ceil(r),i(o.getContext("2d")),l.ctx.clearRect(t.x,t.y,o.width,o.height),l.ctx.drawImage(o,t.x,t.y),t.surface.pending.push([o,t.x,t.y]),t.w=a,t.h=h,t}put(t,e,s,i,n,r,a){let h=null,l=this.pages.find(u=>(h=u.packer.alloc(e,s))!==null);if(l||(!(Math.max(e,s)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),l=this.pages[0],h=l?l.packer.alloc(e,s):null),(!l||!h)&&(l=this.newPage(Math.max(e,s)),h=l.packer.alloc(e,s))),!h)throw new Error(`[engine] ${e}\xD7${s} does not fit an atlas page`);const o=h;return l.ctx.drawImage(t,o.x,o.y),l.surface.pending.push([t,o.x,o.y]),{surface:l.surface,x:o.x,y:o.y,w:e,h:s,scale:i,gen:this.gen,ox:n,oy:r,margin:a}}newPage(t){let e=this.pageSize;for(;e<t+4;)e*=2;const s=document.createElement("canvas");s.width=s.height=e;const i=s.getContext("2d"),n=ye(s),r={surface:n,packer:new ii(e,e),ctx:i};return this.pages.push(r),this.onPage(n),r}wipe(){this.gen++;let t=0;for(let e=0;e<this.pages.length;e++){const s=this.pages[e];if(t<this.maxPages&&s.surface.source.width===this.pageSize){this.pages[t++]=s;continue}s.surface.pending=[],this.onDrop(s.surface)}this.pages.length=t;for(const e of this.pages)e.packer.reset(),e.ctx.clearRect(0,0,e.surface.source.width,e.surface.source.height),e.surface.pending=[],e.surface.pending.push([e.surface.source,0,0])}},jn=()=>globalThis.FabiPlay,ni=class{posed(t,e,s,i=!0){const n={id:t,body:e};return jn()?.smoothedBody(n,{smooth:s<1?s:!1,interpolate:i})??e}},ri=new Float64Array(1),ai=new Int32Array(ri.buffer),Bt=(t,e)=>(t=Math.imul(t^e,1540483477),t^t>>>15);function mt(t,e=2538058380){return t!==t?Bt(e,2146959360):(ri[0]=t===0?0:t,Bt(Bt(e,ai[0]),ai[1]))}function oi(t,e=2166136261){for(let s=0;s<t.length;s++)e=Math.imul(e^t.charCodeAt(s),16777619);return e}function yt(t){switch(typeof t){case"number":return mt(t);case"string":return oi(t);case"boolean":return t?1013904242:461845907;case"object":{if(t===null)return 625341585;if(Array.isArray(t)||t instanceof Float64Array){let i=1779033703^t.length;for(let n=0;n<t.length;n++){const r=t[n];i=Bt(i,typeof r=="number"?mt(r):yt(r))}return i}let e=1359893119;const s=t;for(const i in s){const n=s[i];n!==void 0&&(e=e+Bt(oi(i),yt(n))|0)}return Bt(e,2600822924)}default:return 0}}function Jt(t,e){if(t===e)return!0;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return typeof t=="number"&&typeof e=="number"&&t!==t&&e!==e;const s=Array.isArray(t)||t instanceof Float64Array;if(s!==(Array.isArray(e)||e instanceof Float64Array))return!1;if(s){const r=t,a=e;if(r.length!==a.length)return!1;for(let h=0;h<r.length;h++)if(r[h]!==a[h]&&!Jt(r[h],a[h]))return!1;return!0}const i=t,n=e;for(const r in i)if(i[r]!==void 0&&!Jt(i[r],n[r]))return!1;for(const r in n)if(n[r]!==void 0&&i[r]===void 0)return!1;return!0}function ve(t){if(typeof t!="object"||t===null)return t;if(Array.isArray(t))return t.map(ve);if(t instanceof Float64Array)return t.slice();const e={};for(const s in t)t[s]!==void 0&&(e[s]=ve(t[s]));return e}var hi=class{constructor(t=1/0){c(this,"max",t),c(this,"buckets",new Map),c(this,"n",0)}get size(){return this.n}get(t,e=yt(t)){const s=this.buckets.get(e);if(s){for(let i=0;i<s.length;i++)if(Jt(s[i].key,t))return s[i].value}}set(t,e,s=yt(t)){let i=this.buckets.get(s);if(i){for(const n of i)if(Jt(n.key,t)){n.value=e;return}}this.n>=this.max&&this.clear(),(!i||!this.buckets.has(s))&&this.buckets.set(s,i=[]),i.push({key:ve(t),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}},os=0,li=1,we=2,hs=3,ci=class{constructor(){c(this,"scale",1),c(this,"cOn",!1),c(this,"px0",0),c(this,"py0",0),c(this,"px1",0),c(this,"py1",0),c(this,"clipVer",0),c(this,"stack",[]),c(this,"sp",0),c(this,"real",0),c(this,"mute",0),c(this,"bnd",new Float64Array(4*(es+1))),c(this,"rx0",0),c(this,"ry0",0),c(this,"rx1",0),c(this,"ry1",0),c(this,"maxBlur",1/0),c(this,"time",0),c(this,"skipped",0),c(this,"gq",new Float64Array(4))}resetLayers(t){this.scale=t,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){const t=this.gq;this.grow(t[0],t[1],t[2],t[3])}grow(t,e,s,i){if(!this.real)return;const n=this.bnd,r=(this.real-1)*4;t<n[r]&&(n[r]=t),e<n[r+1]&&(n[r+1]=e),s>n[r+2]&&(n[r+2]=s),i>n[r+3]&&(n[r+3]=i)}area(t,e){const s=this.bnd,i=t*4,n=this.scale;return this.rx0=Math.max(Math.floor((s[i]-e)*n)-1,0),this.ry0=Math.max(Math.floor((s[i+1]-e)*n)-1,0),this.rx1=Math.min(Math.ceil((s[i+2]+e)*n)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((s[i+3]+e)*n)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(t,e,s,i){const n=this.scale,r=this.canvas.width,a=this.canvas.height,h=Math.min(Math.max(Math.round(t*n),0),r),l=Math.min(Math.max(Math.round(e*n),0),a),o=Math.min(Math.max(Math.round((t+s)*n),h),r),u=Math.min(Math.max(Math.round((e+i)*n),l),a);this.cOn&&h===this.px0&&l===this.py0&&o===this.px1&&u===this.py1||(this.cOn=!0,this.px0=h,this.py0=l,this.px1=o,this.py1=u,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(t){if(t<we&&(this.mute||this.real>=es||!this.pushLayer())&&(t+=2),t===hs)this.mute++;else if(t!==we){const e=this.real*4;this.bnd[e]=this.bnd[e+1]=1/0,this.bnd[e+2]=this.bnd[e+3]=-1/0,this.real++}return this.stack[this.sp++]=t,t<we}beginLayer(){return this.push(os)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===os?li:hs)}endLayer(t,e){if(!this.sp)return;let s=this.stack[--this.sp];if(s===hs){if(this.mute--,!this.sp)return;s=this.stack[--this.sp]}if(s===li){const i=--this.real,n=this.popLayer();this.area(i-1,0)&&this.composite(n,!0,1,null);const r=this.bnd,a=(i-1)*4,h=i*4;r[a]=Math.max(r[a],r[h]),r[a+1]=Math.max(r[a+1],r[h+1]),r[a+2]=Math.min(r[a+2],r[h+2]),r[a+3]=Math.min(r[a+3],r[h+3]),s=this.stack[--this.sp]}if(s===we)ts(e)&&(this.skipped+=e.length);else if(s===os){const i=--this.real,n=ts(e)?e:null,r=this.popLayer();if(this.area(i,n?$n(n,this.maxBlur):0)){this.composite(r,!1,t,n);const a=this.scale;this.grow(this.rx0/a,this.ry0/a,this.rx1/a,this.ry1/a)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}},Vn=256,fi=8<<20,K=new Float64Array(32),Z={x:0,y:0,w:0,h:0};function Qn(t){if(typeof t.filter!="string")return!1;t.filter="blur(1px)";const e=t.filter==="blur(1px)";return t.filter="none",e}function ls(t){const e=t.getContext("2d",{alpha:!0});return e?new Kn(t,e):null}var Kn=class extends ci{constructor(t,e){super(),c(this,"canvas",t),c(this,"ctx",e),c(this,"kind","canvas2d"),c(this,"maxTextureSize",4096),c(this,"features",{}),c(this,"info",{renderer:"canvas2d"}),c(this,"support"),c(this,"lost",!1),c(this,"fxr",null),c(this,"quads",0),c(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),c(this,"tinted",new Map),c(this,"tintedN",0),c(this,"lostListeners",[]),c(this,"restoredListeners",[]),c(this,"base"),c(this,"top"),c(this,"layers",[]),c(this,"scratch",[]),c(this,"nines",new Map),c(this,"ninePx",0),c(this,"frame",0),c(this,"hit",!1),c(this,"missed",new Map),this.support={filters:Qn(e),shaders:!1},this.base=this.top={ctx:e,clipped:!1,ver:0},t.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(s=>s())}),t.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(s=>s())})}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){return{id:ss(),width:t.width,height:t.height,source:t}}updateTexture(t,e,s=0,i=0){const n=e?s+e.width:1/0,r=e?i+e.height:1/0;for(const a of this.nines.values()){const h=a.key;h[0]===t.id&&h[1]<n&&h[1]+h[3]>s&&h[2]<r&&h[2]+h[4]>i&&this.dropNine(a)}for(const[a,h]of this.tinted){const l=h.filter(o=>o.id!==t.id);this.tintedN-=h.length-l.length,l.length?this.tinted.set(a,l):this.tinted.delete(a)}}destroyTexture(t){this.updateTexture(t)}begin(t,e,s){this.resetLayers(s),this.fxr?.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;const i=this.ctx;this.base.clipped&&i.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,this.canvas.width,this.canvas.height),e>0&&(i.fillStyle=Yt(t,e),i.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(t,e,s,i,n,r,a,h){U[0]=i,U[1]=n,U[2]=a,this.quadQ(t,e,s,r,h)}quadQ(t,e,s,i,n){e.w<=0||e.h<=0||(i===16777215?this.blit(t.source,e.x,e.y,e.w,e.h,s,n):this.blit(this.tint(t,e,i),0,0,e.w,e.h,s,n))}blit(t,e,s,i,n,r,a){const h=U[0],l=U[1],o=U[2];if(o<=0||this.mute)return;this.sync();const u=this.ctx,f=this.scale;if(this.real){const p=r[0]*h,g=r[1]*h,d=r[2]*l,y=r[3]*l;this.grow(r[4]+Math.min(0,p,d,p+d),r[5]+Math.min(0,g,y,g+y),r[4]+Math.max(0,p,d,p+d),r[5]+Math.max(0,g,y,g+y))}u.setTransform(r[0]*f,r[1]*f,r[2]*f,r[3]*f,r[4]*f,r[5]*f),u.globalAlpha=Math.min(o,1),a==="add"&&(u.globalCompositeOperation="lighter"),u.drawImage(t,e,s,i,n,0,0,h,l),a==="add"&&(u.globalCompositeOperation="source-over"),this.quads++}nineQ(t,e,s,i,n,r,a){var h,l;const o=s[8]+s[9],u=i[8]+i[9],f=Math.ceil(o*Math.hypot(n[0],n[1])*this.scale-1e-6),p=Math.ceil(u*Math.hypot(n[2],n[3])*this.scale-1e-6);if(n[1]===0&&n[2]===0||f>4096||p>4096)return!1;if(!(f>0&&p>0&&U[2]>0)||this.mute)return!0;let g=this.kept(t,e,s,i,f,p,r);const d=(g??(g=(h=this.scratch)[l=13*Math.ceil(Math.log2(f))+Math.ceil(Math.log2(p))]??(h[l]=document.createElement("canvas").getContext("2d")))).canvas;if(d.width<f&&(d.width=f),d.height<p&&(d.height=p),!this.hit){g.clearRect(0,0,f+2,p+2);for(let y=0;y<12;y+=4){const m=Math.round(i[y]*p/u),w=Math.round((i[y]+i[y+1])*p/u);for(let x=0;x<12;x+=4){const _=Math.round(s[x]*f/o),M=Math.round((s[x]+s[x+1])*f/o);Z.x=e.x+s[x+2],Z.y=e.y+i[y+2],Z.w=s[x+3],Z.h=i[y+3],!(M<=_||w<=m||Z.w<=0||Z.h<=0)&&(r===16777215?g.drawImage(t.source,Z.x,Z.y,Z.w,Z.h,_,m,M-_,w-m):g.drawImage(this.tint(t,Z,r),0,0,Z.w,Z.h,_,m,M-_,w-m))}}}return U[0]=o,U[1]=u,this.blit(d,0,0,f,p,n,a),!0}kept(t,e,s,i,n,r,a){K[0]=t.id,K[1]=e.x,K[2]=e.y,K[3]=e.w,K[4]=e.h,K[5]=n,K[6]=r,K[7]=a,K.set(s,8),K.set(i,20);const h=yt(K),l=this.nines.get(h);if(this.hit=!1,l)return Jt(l.key,K)?(l.used=this.frame,this.hit=!0,l.ctx):null;const o=this.missed,u=o.get(h);o.size>4096&&o.clear(),o.set(h,this.frame);const f=n*r;if(u!==this.frame-1||f>fi)return null;let p;for(;this.ninePx+f>fi;){let y;for(const x of this.nines.values())x.used<this.frame-1&&!(y&&y.used<=x.used)&&(y=x);if(!y)return null;const m=y.ctx.canvas,w=!p&&m.width>=n&&m.height>=r&&m.width*m.height<=2*f;this.dropNine(y,w),w&&(p=y.ctx)}const g=p??document.createElement("canvas").getContext("2d"),d=g.canvas;return p||(d.width=n,d.height=r),this.ninePx+=d.width*d.height,this.nines.set(h,{key:ve(K),ctx:g,used:this.frame}),g}dropNine(t,e=!1){this.nines.delete(yt(t.key));const s=t.ctx.canvas;this.ninePx-=s.width*s.height,e||(s.width=0)}dropNines(){for(const t of this.nines.values())this.dropNine(t)}tint(t,e,s){const i=mt(s,mt(e.h,mt(e.w,mt(e.y,mt(e.x,mt(t.id))))));let n=this.tinted.get(i);if(n)for(let h=0;h<n.length;h++){const l=n[h];if(l.id===t.id&&l.x===e.x&&l.y===e.y&&l.w===e.w&&l.h===e.h&&l.color===s)return l.canvas}this.tintedN>=Vn&&(this.tinted.clear(),this.tintedN=0,n=void 0);const r=document.createElement("canvas");r.width=Math.ceil(e.w),r.height=Math.ceil(e.h);const a=r.getContext("2d");return a.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),a.globalCompositeOperation="multiply",a.fillStyle=Yt(s),a.fillRect(0,0,e.w,e.h),a.globalCompositeOperation="destination-in",a.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),n||this.tinted.set(i,n=[]),n.push({id:t.id,x:e.x,y:e.y,w:e.w,h:e.h,color:s,canvas:r}),this.tintedN++,r}paint(t,e){this.sync();const s=this.ctx,i=this.scale;return s.setTransform(i,0,0,i,0,0),s.globalAlpha=Math.min(e,1),Yt(t)}ellipse(t,e,s,i,n,r,a){if(a<=0||s<=0||i<=0||this.mute)return;const h=Math.max(s,i);this.grow(t-h,e-h,t+h,e+h);const l=this.ctx;l.fillStyle=this.paint(r,a),l.beginPath(),l.ellipse(t,e,s,i,n,0,Math.PI*2),l.fill(),this.quads++}trace(t,e,s=0){if(this.real)for(let n=0;n<e;n++)this.grow(t[n*2]-s,t[n*2+1]-s,t[n*2]+s,t[n*2+1]+s);const i=this.ctx;i.beginPath(),i.moveTo(t[0],t[1]);for(let n=1;n<e;n++)i.lineTo(t[n*2],t[n*2+1])}polygon(t,e,s,i){if(i<=0||e<3||this.mute)return;const n=this.ctx;n.fillStyle=this.paint(s,i),this.trace(t,e),n.closePath(),n.fill(),this.quads++}stroke(t,e,s,i,n,r){if(n<=0||s<=0||e<1||this.mute)return;const a=this.ctx;a.strokeStyle=this.paint(i,n),a.lineWidth=s,a.lineCap="round",a.lineJoin="round",this.trace(t,e,s/2),e===1&&a.lineTo(t[0],t[1]),r&&a.closePath(),a.stroke(),this.quads++}sync(){const t=this.top;if(t.ver===this.clipVer)return;const e=t.ctx;t.clipped&&e.restore(),t.clipped=this.cOn,t.ver=this.clipVer,this.cOn&&(e.save(),e.setTransform(1,0,0,1,0,0),e.beginPath(),e.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),e.clip())}pushLayer(){const t=this.canvas.width,e=this.canvas.height;let s=this.layers[this.real];if(!s||s.ctx.canvas.width!==t||s.ctx.canvas.height!==e){const n=document.createElement("canvas");n.width=t,n.height=e;const r=n.getContext("2d");if(!r)return!1;s=this.layers[this.real]={ctx:r,clipped:!1,ver:-1}}const i=s.ctx;return s.clipped&&i.restore(),s.clipped=!1,s.ver=-1,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,t,e),this.top=s,this.ctx=i,!0}popLayer(){return this.top=this.real>0?this.layers[this.real-1]:this.base,this.ctx=this.top.ctx,this.layers[this.real].ctx.canvas}composite(t,e,s,i){let n=t,r="none";const a=i&&ht.c2d?this.fxr??(this.fxr=ht.c2d(this)):null;a&&(n=a.chain(t,i),r=a.css),this.sync();const h=this.ctx,l=this.rx0,o=this.ry0,u=this.rx1-l,f=this.ry1-o;h.setTransform(1,0,0,1,0,0),h.globalAlpha=Math.min(s,1),h.globalCompositeOperation=e?"destination-in":"source-over",r!=="none"&&(h.filter=r),h.drawImage(n,l,o,u,f,l,o,u,f),r!=="none"&&(h.filter="none"),h.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();const t=this.stats;return t.drawCalls=t.quads=this.quads,t.filtersSkipped=this.skipped,t}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],this.fxr?.destroy(),this.fxr=null}},te=14,zt=6,ui=8192,Zn=class{constructor(t,e,s=ui){c(this,"instanced",t),c(this,"slots",e),c(this,"capacity",s),c(this,"f32"),c(this,"u32"),c(this,"quads",0),c(this,"textures"),c(this,"bound",0),this.textures=new Array(e).fill(null);const i=s*(t?te:zt*4),n=new ArrayBuffer(i*4);this.f32=new Float32Array(n),this.u32=new Uint32Array(n)}slot(t){const e=this.textures;for(let s=0;s<this.bound;s++)if(e[s]===t)return s;return this.bound>=this.slots?-1:(e[this.bound]=t,this.bound++)}has(t){for(let e=0;e<this.bound;e++)if(this.textures[e]===t)return!0;return!1}get full(){return this.quads>=this.capacity}get words(){return this.quads*(this.instanced?te:zt*4)}reset(){this.quads=0;for(let t=0;t<this.bound;t++)this.textures[t]=null;this.bound=0}push(t,e,s,i,n,r,a,h,l,o,u,f,p,g){const d=this.f32;if(this.instanced){let y=this.quads*te;d[y++]=t,d[y++]=e,d[y++]=s,d[y++]=i,d[y++]=n,d[y++]=r,d[y++]=a,d[y++]=h,d[y++]=l,d[y++]=o,d[y++]=u,d[y++]=f,this.u32[y++]=p,d[y]=g}else{const y=this.quads*zt*4;this.vertex(y,t,e,l,o,p,g),this.vertex(y+6,s,i,u,o,p,g),this.vertex(y+12,n,r,u,f,p,g),this.vertex(y+18,a,h,l,f,p,g)}this.quads++}pushQ(t,e){const s=this.f32;if(this.instanced){const i=this.quads*te;for(let n=0;n<12;n++)s[i+n]=t[n];this.u32[i+12]=t[12],s[i+13]=e}else{let i=this.quads*zt*4;const n=t[12];for(let r=0;r<4;r++,i+=zt)s[i]=t[r*2],s[i+1]=t[r*2+1],s[i+2]=r===1||r===2?t[10]:t[8],s[i+3]=r>=2?t[11]:t[9],this.u32[i+4]=n,s[i+5]=e}this.quads++}vertex(t,e,s,i,n,r,a){const h=this.f32;h[t]=e,h[t+1]=s,h[t+2]=i,h[t+3]=n,this.u32[t+4]=r,h[t+5]=a}};function Jn(t){const e=new Uint16Array(t*6);for(let s=0,i=0,n=0;s<t;s++,i+=6,n+=4)e[i]=n,e[i+1]=n+1,e[i+2]=n+2,e[i+3]=n,e[i+4]=n+2,e[i+5]=n+3;return e}var J={M:0,L:1,Q:2,C:3,Z:4},di=[2,2,4,6,0],tr={M:0,L:1,Q:2,C:3,Z:4};function cs(t,e){if(t.length>=e)return t;const s=new Float64Array(Math.max(e,t.length*2,16));return s.set(t),s}var xe=new Map;function er(t){if(typeof t!="string")return t;let e=xe.get(t);if(e)return e;e=[];const s=t.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[];let i=-1;for(let n=0;n<s.length;){const r=s[n],a=tr[r.toUpperCase()];if(a!==void 0){i=a,n++,a===J.Z&&e.push(J.Z);continue}if(i<0||i===J.Z){n++;continue}const h=di[i];e.push(i);for(let l=0;l<h;l++)e.push(Number(s[n+l]??0));n+=h,i===J.M&&(i=J.L)}return xe.size>256&&xe.clear(),xe.set(t,e),e}var vt={subs:[],count:0},fs=null,wt=null;function be(t,e){let s=wt;s||(s=vt.subs[vt.count]??null,s||vt.subs.push(s={pts:new Float64Array(64),n:0,closed:!1}),s.n=0,s.closed=!1,vt.count++,wt=s);const i=s.n*2;i+2>s.pts.length&&(s.pts=cs(s.pts,i+2));const n=fs;n?(s.pts[i]=n[0]*t+n[2]*e+n[4],s.pts[i+1]=n[1]*t+n[3]*e+n[5]):(s.pts[i]=t,s.pts[i+1]=e),s.n++}function us(t,e=null,s=1,i=6){const n=er(t);vt.count=0,wt=null,fs=e;let r=0,a=0,h=0,l=0;const o=s/i;for(let u=0;u<n.length;){const f=n[u++],p=n;if(f===J.M)wt=null,r=h=p[u],a=l=p[u+1],be(r,a);else if(f===J.L)r=p[u],a=p[u+1],be(r,a);else if(f===J.Q){const g=p[u],d=p[u+1],y=p[u+2],m=p[u+3],w=pi((ft(g-r,d-a)+ft(y-g,m-d))*o);for(let x=1;x<=w;x++){const _=x/w,M=1-_;be(M*M*r+2*M*_*g+_*_*y,M*M*a+2*M*_*d+_*_*m)}r=y,a=m}else if(f===J.C){const g=p[u],d=p[u+1],y=p[u+2],m=p[u+3],w=p[u+4],x=p[u+5],_=pi((ft(g-r,d-a)+ft(y-g,m-d)+ft(w-y,x-m))*o);for(let M=1;M<=_;M++){const k=M/_,F=1-k,R=F*F*F,N=3*F*F*k,I=3*F*k*k,D=k*k*k;be(R*r+N*g+I*y+D*w,R*a+N*d+I*m+D*x)}r=w,a=x}else if(f===J.Z){wt&&(wt.closed=!0),wt=null,r=h,a=l;continue}else break;u+=di[f]}wt=null,fs=null;for(let u=0;u<vt.count;u++){const f=vt.subs[u],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 vt}var ft=(t,e)=>Math.sqrt(t*t+e*e),pi=t=>Math.min(Math.max(Math.ceil(t),2),24);function sr(t,e){let s=0;for(let i=0,n=e-1;i<e;n=i++)s+=(t[n*2]-t[i*2])*(t[n*2+1]+t[i*2+1]);return s}var Me=new Int32Array(64),ke=(t,e,s,i,n)=>((t[i*2]-t[s*2])*(t[n*2+1]-t[s*2+1])-(t[i*2+1]-t[s*2+1])*(t[n*2]-t[s*2]))*e;function ir(t,e,s){if(e<3)return 0;Me.length<e&&(Me=new Int32Array(Math.max(e,Me.length*2)));const i=Me;let n=e,r=0;for(let o=0;o<e;o++)i[o]=o;const a=sr(t,e)>0?1:-1;let h=e*e+8,l=0;for(;n>3&&h-- >0;){const o=i[(l+n-1)%n],u=i[l%n],f=i[(l+1)%n];let p=ke(t,a,o,u,f)>0;if(p)for(let g=0;g<n;g++){const d=i[g];if(!(d===o||d===u||d===f)&&ke(t,a,o,u,d)>=0&&ke(t,a,u,f,d)>=0&&ke(t,a,f,o,d)>=0){p=!1;break}}p?(s[r++]=o,s[r++]=u,s[r++]=f,i.copyWithin(l%n,l%n+1,n),n--,l=Math.max(l-1,0)):l=(l+1)%n}if(n===3)s[r++]=i[0],s[r++]=i[1],s[r++]=i[2];else if(n>3)for(let o=1;o+1<n;o++)s[r++]=i[0],s[r++]=i[o],s[r++]=i[o+1];return r}var nr=.85,Ae=new Float64Array(64),gi=new Float64Array(64),mi=new Float64Array(64),yi=new Float64Array(64),vi=new Float64Array(64),wi=new Float64Array(64),xi=new Uint8Array(64),_e=new Float64Array(8);function rr(t,e,s,i,n,r){const a=_e;if(Ae.length<e){const m=Math.max(e,Ae.length*2);Ae=new Float64Array(m),gi=new Float64Array(m),mi=new Float64Array(m),yi=new Float64Array(m),vi=new Float64Array(m),wi=new Float64Array(m),xi=new Uint8Array(m)}const h=Ae,l=gi;let o=0;for(let m=0;m<e;m++){const w=t[m*2],x=t[m*2+1];!Number.isFinite(w)||!Number.isFinite(x)||o&&Math.abs(h[o-1]-w)<.001&&Math.abs(l[o-1]-x)<.001||(h[o]=w,l[o]=x,o++)}if(i&&o>2&&Math.abs(h[0]-h[o-1])<.001&&Math.abs(l[0]-l[o-1])<.001&&o--,o===0)return;if(o===1)return a[0]=h[0],a[1]=l[0],r();const u=i?o:o-1,f=mi,p=yi;for(let m=0;m<u;m++){const w=(m+1)%o,x=h[w]-h[m],_=l[w]-l[m],M=ft(x,_)||1;f[m]=-_/M,p[m]=x/M}const g=vi,d=wi,y=xi;for(let m=0;m<o;m++){const w=i?(m-1+u)%u:m-1,x=m<u?m:-1;if(y[m]=1,w<0||x<0||f[w]*f[x]+p[w]*p[x]<nr)continue;let M=f[w]+f[x],k=p[w]+p[x];const F=ft(M,k)||1;M/=F,k/=F;const R=s/Math.max(M*f[x]+k*p[x],.5);g[m]=M*R,d[m]=k*R,y[m]=0}for(let m=0;m<u;m++){const w=(m+1)%o,x=y[m]?f[m]*s:g[m],_=y[m]?p[m]*s:d[m],M=y[w]?f[m]*s:g[w],k=y[w]?p[m]*s:d[w];a[0]=h[m]+x,a[1]=l[m]+_,a[2]=h[w]+M,a[3]=l[w]+k,a[4]=h[w]-M,a[5]=l[w]-k,a[6]=h[m]-x,a[7]=l[m]-_,n()}for(let m=0;m<o;m++)y[m]&&(a[0]=h[m],a[1]=l[m],r())}function bi(t,e){let s=0,i=1/0;for(let n=0;n<e.length;n++){const r=Math.abs(Math.log(Math.max(t,.5)/e[n]));r<i&&(i=r,s=n)}return s}var et=256,ds=[{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}],ps=[4,8,16,32,64,128].map((t,e)=>({x:e*4,y:128,w:4,h:t,r:t/2-1})),xt={x:248,y:248,w:8,h:8},ar=ds.map(t=>t.r*2),or=ps.map(t=>t.r*2),Mi=(t,e)=>Math.min(Math.max(t+.5-e,0),1);function hr(){const t=new Uint8ClampedArray(et*et*4),e=(s,i,n)=>{const r=(i*et+s)*4;t[r]=t[r+1]=t[r+2]=255,t[r+3]=Math.round(n*255)};for(const s of ds){const i=s.w/2;for(let n=0;n<s.h;n++)for(let r=0;r<s.w;r++)e(s.x+r,s.y+n,Mi(s.r,Math.hypot(r+.5-i,n+.5-i)))}for(const s of ps){const i=s.h/2;for(let n=0;n<s.h;n++)for(let r=0;r<s.w;r++)e(s.x+r,s.y+n,Mi(s.r,Math.abs(n+.5-i)))}for(let s=0;s<xt.h;s++)for(let i=0;i<xt.w;i++)e(xt.x+i,xt.y+s,1);return t}function lr(){const t=document.createElement("canvas");return t.width=t.height=et,t.getContext("2d").putImageData(new ImageData(hr(),et,et),0,0),t}var ki=8,gs=`
|
|
1
|
+
/*! @fabi-play/engine 0.5.0 (lite: load fabi-play.js first) | Fabi Play Kit License | https://docs.fabiplay.app */(function(Ds,_t){var ce=typeof document<"u"?document.currentScript:null;typeof define=="function"&&define.amd?define([],function(){return _t(ce)}):typeof module=="object"&&module&&module.exports?module.exports=_t(ce):Ds.FabiEngine=_t(ce)})(typeof globalThis<"u"?globalThis:typeof self<"u"?self:this,function(Ds){"use strict";var _t={exports:{}},ce=_t.exports,fe=Object.defineProperty,pn=Object.getOwnPropertyDescriptor,gn=Object.getOwnPropertyNames,mn=Object.prototype.hasOwnProperty,yn=(t,e,s)=>e in t?fe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,vn=(t,e)=>{for(var s in e)fe(t,s,{get:e[s],enumerable:!0})},wn=(t,e,s,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of gn(e))!mn.call(t,n)&&n!==s&&fe(t,n,{get:()=>e[n],enumerable:!(i=pn(e,n))||i.enumerable});return t},xn=t=>wn(fe({},"__esModule",{value:!0}),t),c=(t,e,s)=>yn(t,typeof e!="symbol"?e+"":e,s),Bs={};vn(Bs,{AnimatedSprite:()=>St,Atlas:()=>as,AvatarPainter:()=>xs,AvatarsNode:()=>qi,BitmapFont:()=>bs,DEFAULT_FONT:()=>Ei,EASE:()=>jt,Group:()=>ns,HALO:()=>ee,MAX_LAYERS:()=>es,NameTags:()=>vs,Node:()=>Et,NodePool:()=>Zi,Particles:()=>si,STAGE_HEIGHT:()=>Y,Shape:()=>Zt,ShelfPacker:()=>ii,Sound:()=>Ii,Sprite:()=>It,TIERS:()=>ut,Text:()=>se,Timeline:()=>Xi,Tweens:()=>$i,avatarPortrait:()=>kr,blur:()=>Ta,brightness:()=>wa,colorMatrix:()=>Ea,contrast:()=>xa,createAvatarRenderer:()=>Mr,createEngine:()=>qr,createRenderer:()=>ms,dropShadow:()=>Sa,grayscale:()=>Ma,handsOf:()=>Pi,hits:()=>ks,hueRotate:()=>Aa,invert:()=>_a,nodePool:()=>Ia,packColor:()=>Lt,parseBMFont:()=>Fe,parseColor:()=>ot,pickTier:()=>Oi,playerColor:()=>Ms,rendererOrder:()=>_i,rng:()=>Ln,saturate:()=>ba,sepia:()=>ka,shader:()=>Fa,shapeBounds:()=>ws,tier:()=>Ft,tint:()=>va,touching:()=>Ni,wrists:()=>Ci}),_t.exports=xn(Bs);var bn=33,zs={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},Mn=4,ue=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"],kn={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},Ha=kn["6-8"],An=(t,e)=>t?{x:t.x+e.x*t.w,y:t.y+e.y*t.h}:{x:e.x,y:e.y},Wa=16/9,_n=12,En=bn*4,Tn=t=>_n+t*En,Ya=Tn(Mn),Sn=t=>t.startsWith("fabi-play.")?`fablee-play.${t.slice(10)}`:null;function Fn(t,e,s=Sn(e)){if(!(!t||!s))try{const i=t.getItem(s);if(i===null)return;t.getItem(e)===null&&t.setItem(e,i),t.removeItem(s)}catch{}}var Gs=globalThis.FabiPlay?.avatars;if(!Gs)throw new Error("[engine] fabi-play-engine.lite.js needs fabi-play.js (with FabiPlay.avatars) loaded before it");var{avatarById:de,avatarShapes:Rn,BAND_BODY:ja,DEFAULT_AVATAR:pe,drawShapes:Xs,frameOf:Cn,iconShapes:Pn}=Gs,Nt=()=>Float64Array.of(1,0,0,1,0,0);function ct(t,e,s,i,n,r,a){const h=n?Math.cos(n):1,l=n?Math.sin(n):0,o=h*r,u=l*r,f=-l*a,p=h*a;if(!e)return t[0]=o,t[1]=u,t[2]=f,t[3]=p,t[4]=s,t[5]=i,t;const g=e[0],d=e[1],y=e[2],m=e[3];return t[0]=g*o+y*u,t[1]=d*o+m*u,t[2]=g*f+y*p,t[3]=d*f+m*p,t[4]=g*s+y*i+e[4],t[5]=d*s+m*i+e[5],t}function Nn(t,e,s){const i=t[0]*t[3]-t[1]*t[2];if(Math.abs(i)<1e-12)return null;const n=e-t[4],r=s-t[5];return[(t[3]*n-t[2]*r)/i,(-t[1]*n+t[0]*r)/i]}var $s={white:16777215,black:0,red:16711680,transparent:0},Wt=new Map;function ot(t){if(typeof t=="number")return[t&16777215,1];const e=Wt.get(t);if(e)return e;let s=[16777215,1];const i=t.trim().toLowerCase();if(i[0]==="#"){const n=i.slice(1),r=n.length<=4?[...n].map(h=>h+h).join(""):n,a=parseInt(r.slice(0,6),16);Number.isFinite(a)&&(s=[a,r.length===8?parseInt(r.slice(6,8),16)/255:1])}else if(i.startsWith("rgb")){const n=i.match(/-?\d*\.?\d+%?/g)?.map(o=>o.endsWith("%")?parseFloat(o)/100*255:parseFloat(o))??[],[r=255,a=255,h=255]=n,l=n[3]===void 0?1:i.match(/,\s*[\d.]+%\s*\)$/)?n[3]/255:n[3];s=[(We(r)<<16|We(a)<<8|We(h))>>>0,Math.min(Math.max(l,0),1)]}else if(i in $s)s=[$s[i],i==="transparent"?0:1];else if(typeof document<"u"){const n=document.createElement("canvas").getContext("2d");if(n){n.fillStyle="#ffffff",n.fillStyle=i;const r=n.fillStyle;if(r!==i)return Wt.set(t,s=ot(r)),s}}return Wt.size>512&&Wt.clear(),Wt.set(t,s),s}var We=t=>Math.min(Math.max(Math.round(t),0),255);function Lt(t,e,s=!1){const i=Math.min(Math.max(e,0),1),n=(t>>16&255)*i,r=(t>>8&255)*i,a=(t&255)*i,h=s?0:i*255;return(Math.round(h)<<24|Math.round(a)<<16|Math.round(r)<<8|Math.round(n))>>>0}var Yt=(t,e=1)=>`rgba(${t>>16&255},${t>>8&255},${t&255},${e})`;function qs(t,e){if(t===16777215)return e;if(e===16777215)return t;const s=i=>Math.round((t>>i&255)*(e>>i&255)/255);return(s(16)<<16|s(8)<<8|s(0))>>>0}var jt={linear:t=>t,quadIn:t=>t*t,quadOut:t=>t*(2-t),quadInOut:t=>t<.5?2*t*t:-1+(4-2*t)*t,cubicOut:t=>1-(1-t)**3,sineInOut:t=>-(Math.cos(Math.PI*t)-1)/2,backOut:t=>1+(1.70158+1)*(t-1)**3+1.70158*(t-1)**2,elasticOut:t=>t===0||t===1?t:2**(-10*t)*Math.sin((t*10-.75)*(2*Math.PI/3))+1,bounceOut:t=>t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375};function Ln(t){let e=t>>>0;return()=>{e=e+1831565813>>>0;let s=e;return s=Math.imul(s^s>>>15,s|1),s^=s+Math.imul(s^s>>>7,s|61),((s^s>>>14)>>>0)/4294967296}}var Vt=1,Hs=2,ge=0,it=1,In=4294967295,A={cap:0,epoch:0,x:new Float64Array(0),y:new Float64Array(0),rot:new Float64Array(0),sx:new Float64Array(0),sy:new Float64Array(0),alpha:new Float64Array(0),la:new Float64Array(0),lb:new Float64Array(0),lc:new Float64Array(0),ld:new Float64Array(0),world:new Float64Array(0),tint:new Uint32Array(0),flags:new Uint8Array(0),moved:new Uint8Array(0),dirty:new Uint8Array(0),gen:new Uint32Array(0),parent:new Int32Array(0),first:new Int32Array(0),next:new Int32Array(0),prev:new Int32Array(0),stamp:new Uint32Array(0),pass:0,free:new Int32Array(0),freeHead:0,freeCount:0,top:2},gt=[],On="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function Ws(t){const e=A;for(const i of On){const n=e[i],r=new n.constructor(i==="world"?t*6:t);r.set(n),e[i]=r}const s=new Int32Array(t);for(let i=0;i<A.freeCount;i++)s[i]=A.free[(A.freeHead+i)%A.cap];for(A.free=s,A.freeHead=0,A.cap=t,A.epoch++;gt.length<t;)gt.push(null)}function Ye(t){A.x[t]=A.y[t]=A.rot[t]=0,A.sx[t]=A.sy[t]=A.alpha[t]=1,A.la[t]=A.ld[t]=1,A.lb[t]=A.lc[t]=0;const e=t*6,s=A.world;s[e]=s[e+3]=1,s[e+1]=s[e+2]=s[e+4]=s[e+5]=0,A.tint[t]=16777215,A.flags[t]=Vt|Hs,A.moved[t]=1,A.dirty[t]=0,A.parent[t]=A.first[t]=A.next[t]=A.prev[t]=-1}Ws(256),Ye(ge),A.flags[ge]=0,Ye(it),A.flags[it]=0;function Un(){let t;if(A.freeCount){t=A.free[A.freeHead],A.freeHead=(A.freeHead+1)%A.cap,A.freeCount--;const e=gt[t];e&&(e._i=ge,e._g=-1,gt[t]=null)}else A.top===A.cap&&Ws(A.cap*2),t=A.top++;return Ye(t),t}function Ys(t,e){je(t);for(let i=A.first[t];i>=0;){const n=A.next[i];A.parent[i]=A.next[i]=A.prev[i]=-1,i=n}A.first[t]=-1,A.flags[t]=A.flags[t]&~Hs,A.moved[t]=0;const s=A.gen[t]+1;A.gen[t]=s,s!==In&&(e&&(gt[t]=e),A.free[(A.freeHead+A.freeCount)%A.cap]=t,A.freeCount++)}function Dn(t){for(let e=0;e<gt.length;e++){const s=gt[e];s&&t(s)&&(s._i=ge,s._g=-1,gt[e]=null)}}function Bn(t,e){je(t);const s=A.first[e];A.parent[t]=e,A.next[t]=s,A.prev[t]=-1,s>=0&&(A.prev[s]=t),A.first[e]=t,A.moved[t]=1}function je(t){const e=A.parent[t];if(e<0)return;const s=A.next[t],i=A.prev[t];i>=0?A.next[i]=s:A.first[e]=s,s>=0&&(A.prev[s]=i),A.parent[t]=A.next[t]=A.prev[t]=-1}var Qt={root:-1,gen:-1,world:new Float64Array(6)};function zn(t){const e=++A.pass,s=A.world,i=t*6,n=Qt.world;let r=Qt.root!==t||Qt.gen!==A.gen[t];for(let a=0;a<6;a++)n[a]!==s[i+a]&&(r=!0),n[a]=s[i+a];Qt.root=t,Qt.gen=A.gen[t],A.stamp[t]=r?e:e-1}function Gn(t){A.stamp[t]=A.pass}function js(t){for(let e=A.first[t];e>=0;){const s=A.next[e];js(e),e=s}Ys(t)}var Ve=typeof FinalizationRegistry=="function"?new FinalizationRegistry(t=>A.gen[t.i]===t.g&&js(t.i)):null;function Vs(t){t._reg||!Ve||(t._reg=!0,Ve.register(t,{i:t._i,g:t._g},t))}function Xn(t){t._reg&&Ve.unregister(t)}var Qe=1,Ke=2,Ze=3,Je=4;function ts(t){if(t){for(let e=0;e<t.length;e++)if(t[e].enabled)return!0}return!1}function $n(t,e){let s=0;for(let i=0;i<t.length;i++){const n=t[i];n.enabled&&n.pad&&(s+=n.pad(e))}return s}var ht={gl:null,c2d:null,live:null},U=new Float64Array(3),es=4,qn=1,ss=()=>qn++,q=Nt(),S=A,Et=class{constructor(t){c(this,"kernel",t),c(this,"_i",Un()),c(this,"_g",S.gen[this._i]),c(this,"_wv",null),c(this,"_wi",-1),c(this,"_we",-1),c(this,"blend","normal"),c(this,"_data",null),c(this,"parent",null),c(this,"hitRadius",null),c(this,"clip",null),c(this,"mask",null),c(this,"filters",null),c(this,"_z",0),c(this,"anchorX",0),c(this,"anchorY",0),c(this,"_pool",null),c(this,"_free",!1),c(this,"_reg",!1)}get x(){return S.x[this._i]}set x(t){const e=this._i||it;S.x[e]=t,S.moved[e]=1}get y(){return S.y[this._i]}set y(t){const e=this._i||it;S.y[e]=t,S.moved[e]=1}get rotation(){return S.rot[this._i]}set rotation(t){const e=this._i||it;S.rot[e]=t,S.dirty[e]=S.moved[e]=1}get scaleX(){return S.sx[this._i]}set scaleX(t){const e=this._i||it;S.sx[e]=t,S.dirty[e]=S.moved[e]=1}get scaleY(){return S.sy[this._i]}set scaleY(t){const e=this._i||it;S.sy[e]=t,S.dirty[e]=S.moved[e]=1}get alpha(){return S.alpha[this._i]}set alpha(t){const e=this._i||it;S.alpha[e]=t,S.moved[e]=1}get visible(){return(S.flags[this._i]&Vt)!==0}set visible(t){const e=this._i||it;t?S.flags[e]=S.flags[e]|Vt:S.flags[e]=S.flags[e]&~Vt,S.moved[e]=1}get destroyed(){return S.gen[this._i]!==this._g}get world(){const t=this._i||it;return(this._wi!==t||this._we!==S.epoch)&&(this._wv=S.world.subarray(t*6,t*6+6),this._wi=t,this._we=S.epoch),this._wv}get data(){return this._data??(this._data={})}set data(t){this._data=t}get scale(){return this.scaleX}set scale(t){this.scaleX=this.scaleY=t}get z(){return this._z}set z(t){t!==this._z&&(this._z=t,this.parent&&(this.parent.sortDirty=!0))}get tint(){return S.tint[this._i]}set tint(t){S.tint[this._i||it]=typeof t=="number"?t&16777215:ot(t)[0]}set anchor(t){typeof t=="number"?this.anchorX=this.anchorY=t:(this.anchorX=t.x,this.anchorY=t.y)}get width(){return 0}set width(t){}get height(){return 0}set height(t){}set(t){for(const e in t){const s=t[e];s!==void 0&&(this[e]=s)}return this}destroy(){this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),Ys(this._i,this),Xn(this),this.kernel.tweens.stopAll(this),this._pool?.forget(this))}updateWorld(){const t=this.parent?this.parent.updateWorld():null;return ct(this.world,t,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(t,e,s){}};function Hn(t){Dn(e=>e.kernel===t)}var is=!1,Qs=Object.freeze([]),ns=class dn extends Et{constructor(e){super(e),c(this,"children",Qs),c(this,"sortDirty",!1),c(this,"dead",!1),Vs(this)}add(e,...s){this.adopt(e);for(let i=0;i<s.length;i++)this.adopt(s[i]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&Bn(e._i,this._i),this.children===Qs&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||Vs(e)}detach(e){const s=this.children,i=s.indexOf(e);if(i>=0){for(let n=i+1;n<s.length;n++)s[n-1]=s[n];s.pop()}e.parent===this&&(e.parent=null,e.destroyed||je(e._i))}clear(){for(const e of this.children)e.destroy()}destroy(){for(const e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(const s of this.children)s.destroyed?s.parent===this&&(s.parent=null):this.children[e++]=s;this.children.length=e}for(const e of this.children)e instanceof dn&&e.sweep()}draw(e,s,i){if(is)return S.parent[this._i]<0&&!this.destroyed&&Gn(this._i),this.drawChildren(e,s,i);is=!0;try{this.destroyed||zn(this._i),this.drawChildren(e,s,i)}finally{is=!1}}drawChildren(e,s,i){if(this.sortDirty){const h=new Map(this.children.map((l,o)=>[l,o]));this.children.sort((l,o)=>l.z-o.z||h.get(l)-h.get(o)),this.sortDirty=!1}const n=this.children,r=this._i,a=S.stamp[r]===S.pass;for(let h=0;h<n.length;h++){const l=n[h],o=l._i,u=S.alpha[o];if(S.gen[o]!==l._g||!(S.flags[o]&Vt)||u<=0)continue;if(a||S.moved[o]){S.moved[o]=0,S.stamp[o]=S.pass;let g,d,y,m;if(S.dirty[o]){S.dirty[o]=0;const D=S.rot[o],W=D?Math.cos(D):1,X=D?Math.sin(D):0,z=S.sx[o],$t=S.sy[o];S.la[o]=g=W*z,S.lb[o]=d=X*z,S.lc[o]=y=-X*$t,S.ld[o]=m=W*$t}else g=S.la[o],d=S.lb[o],y=S.lc[o],m=S.ld[o];const w=S.world,x=S.x[o],_=S.y[o],M=o*6,k=r*6,F=w[k],R=w[k+1],N=w[k+2],I=w[k+3];w[M]=F*g+N*d,w[M+1]=R*g+I*d,w[M+2]=F*y+N*m,w[M+3]=R*y+I*m,w[M+4]=F*x+N*_+w[k+4],w[M+5]=R*x+I*_+w[k+5]}const f=s*u,p=qs(i,S.tint[o]);l.clip||l.mask||l.filters?Zs(e,l,f,p):l.draw(e,f,p)}}},V=new Float64Array(128),Tt=0,rs=new Float64Array(8);function Ks(t,e,s,i){e.clip||e.mask||e.filters?Zs(t,e,s,i):e.draw(t,s,i)}function Zs(t,e,s,i){const n=t.r,r=e.world,a=e.clip;let h=!1,l=!1;if(a)if(Math.abs(r[1])<1e-9&&Math.abs(r[2])<1e-9&&Tt<32){const f=r[0]*a.x+r[4],p=r[0]*(a.x+a.width)+r[4],g=r[3]*a.y+r[5],d=r[3]*(a.y+a.height)+r[5];let y=Math.min(f,p),m=Math.max(f,p),w=Math.min(g,d),x=Math.max(g,d);if(Tt){const M=(Tt-1)*4;y=Math.max(y,V[M]),w=Math.max(w,V[M+1]),m=Math.min(m,V[M+2]),x=Math.min(x,V[M+3])}const _=Tt++*4;V[_]=y,V[_+1]=w,V[_+2]=m,V[_+3]=x,n.clip(y,w,Math.max(m-y,0),Math.max(x-w,0)),l=!0}else h=!0;const o=e.mask&&e.mask.visible?e.mask:null,u=ts(e.filters)?e.filters:null;try{if(h&&n.beginLayer(),o&&n.beginLayer(),u?(e.draw(t,n.beginLayer()?1:s,i),n.endLayer(s,u)):e.draw(t,s,i),o&&(n.beginMask(),ct(o.world,r,o.x,o.y,o.rotation,o.scaleX,o.scaleY),Ks(t,o,o.alpha,16777215),n.endLayer(1)),h&&a){n.beginMask();for(let f=0;f<4;f++){const p=f===1||f===2?a.x+a.width:a.x,g=f>1?a.y+a.height:a.y;rs[f*2]=r[0]*p+r[2]*g+r[4],rs[f*2+1]=r[1]*p+r[3]*g+r[5]}n.polygon(rs,4,16777215,1),n.endLayer(1)}}finally{if(l)if(Tt--,Tt){const f=(Tt-1)*4;n.clip(V[f],V[f+1],V[f+2]-V[f],V[f+3]-V[f+1])}else n.unclip()}}var It=class extends Et{constructor(t,e,s){super(t),c(this,"_frame",null),c(this,"_w",null),c(this,"_h",null),c(this,"slice",0),c(this,"autoAnchor",!0),c(this,"frameName",null),e&&(this.frame=e),s?.anchor===void 0&&this.useFrameAnchor(),s&&this.set(s)}get frame(){return this._frame}set frame(t){this.frameName=typeof t=="string"?t:null,this._frame=typeof t=="string"?this.kernel.frame(t):t,this.autoAnchor&&this.useFrameAnchor()}set anchor(t){this.autoAnchor=!1,super.anchor=t}get naturalWidth(){const t=this.frameNow();return t?(t.sw??t.w)/t.scale-t.margin*2:0}get naturalHeight(){const t=this.frameNow();return t?(t.sh??t.h)/t.scale-t.margin*2:0}get width(){return this._w??this.naturalWidth}set width(t){this._w=t}get height(){return this._h??this.naturalHeight}set height(t){this._h=t}sizeQ(t){Dt[0]=this._w??(t.sw??t.w)/t.scale-t.margin*2,Dt[1]=this._h??(t.sh??t.h)/t.scale-t.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){const t=this._frame;if(!t)return;const e=(t.sw??t.w)/t.scale-t.margin*2,s=(t.sh??t.h)/t.scale-t.margin*2;this.anchorX=e>0?(t.ox-t.margin)/e:0,this.anchorY=s>0?(t.oy-t.margin)/s:0}draw(t,e,s){const i=this.frameNow();if(!i)return;const n=Dt;this.sizeQ(i),n[2]=this.anchorX,n[3]=this.anchorY,n[4]=e,Wn(t,i,this.world,this.slice,s,this.blend)}},Ot=new Float64Array(12),Ut=new Float64Array(12),Kt={x:0,y:0,w:0,h:0};function Js(t,e,s,i,n,r){e=Math.max(e,0),s=Math.max(s,0),i=Math.max(i,0);const a=s+i>n?s*n/(s+i):s,h=s+i>n?i*n/(s+i):i;let l=a/r,o=h/r;if(l+o>e){const u=e/(l+o);l*=u,o*=u}t[0]=0,t[1]=l,t[2]=0,t[3]=a,t[4]=l,t[5]=e-l-o,t[6]=a,t[7]=n-a-h,t[8]=e-o,t[9]=o,t[10]=n-h,t[11]=h}var Dt=new Float64Array(5);function Wn(t,e,s,i,n,r){const a=Dt,h=a[0],l=a[1],o=a[2],u=a[3],f=a[4],p=t.tex(e.surface),g=i===0?e.slice??0:i;if(g===0){const M=(e.sw??e.w)/e.scale-e.margin*2,k=(e.sh??e.h)/e.scale-e.margin*2,F=M>0?h/M:1,R=k>0?l/k:1,N=-o*h+((e.tx??0)/e.scale-e.margin)*F,I=-u*l+((e.ty??0)/e.scale-e.margin)*R;me(s,N,I),U[0]=e.w/e.scale*F,U[1]=e.h/e.scale*R,U[2]=f,t.r.quadQ(p,e,q,n,r);return}const d=e.tx??0,y=e.ty??0,m=(e.sw??e.w)-e.w-d,w=(e.sh??e.h)-e.h-y,x=-o*h-e.margin+d/e.scale,_=-u*l-e.margin+y/e.scale;if(Js(Ot,h+e.margin*2-(d+m)/e.scale,(typeof g=="number"?g:g[3])-d,(typeof g=="number"?g:g[1])-m,e.w,e.scale),Js(Ut,l+e.margin*2-(y+w)/e.scale,(typeof g=="number"?g:g[0])-y,(typeof g=="number"?g:g[2])-w,e.h,e.scale),me(s,x,_),U[2]=f,!t.r.nineQ?.(p,e,Ot,Ut,q,n,r))for(let M=0;M<12;M+=4){const k=Ut[M+1],F=Ut[M+3];if(!(k<=0||F<=0))for(let R=0;R<12;R+=4){const N=Ot[R+1],I=Ot[R+3];N<=0||I<=0||(Kt.x=e.x+Ot[R+2],Kt.y=e.y+Ut[M+2],Kt.w=I,Kt.h=F,me(s,x+Ot[R],_+Ut[M]),U[0]=N,U[1]=k,U[2]=f,t.r.quadQ(p,Kt,q,n,r))}}}function me(t,e,s){q[0]=t[0],q[1]=t[1],q[2]=t[2],q[3]=t[3],q[4]=t[0]*e+t[2]*s+t[4],q[5]=t[1]*e+t[3]*s+t[5]}var Zt=class extends It{constructor(t,e,s={}){super(t,null),c(this,"_spec"),c(this,"baked",null),c(this,"bakedEffects",!0),this._spec=e,this.bake(),s.anchor===void 0&&this.useFrameAnchor(),this.set(s)}get spec(){return this._spec}set spec(t){this._spec=t,this.baked=null,this._w=this._h=null,this.bake()}bake(){const t=this.kernel;return this.baked&&t.atlas.valid(this.baked.frame)&&this.baked.frame.scale===t.pixelScale&&this.bakedEffects===t.effects?this.baked:(this.bakedEffects=t.effects,this.baked=t.shape(this._spec),this._frame=this.baked.frame,this.slice=this.baked.slice,this.baked)}frameNow(){return this.bake().frame}sizeQ(){const t=this.bake();Dt[0]=this._w??t.w,Dt[1]=this._h??t.h}get width(){return this._w??this.bake().w}set width(t){this._w=t}get height(){return this._h??this.bake().h}set height(t){this._h=t}},ti=(t,e,s)=>t===void 0?e:typeof t=="number"?t:t[0]+(t[1]-t[0])*s(),ei=class le extends Et{constructor(e,s,i={}){super(e),c(this,"max"),c(this,"f"),c(this,"tints"),c(this,"count",0),c(this,"gravity"),c(this,"drag"),c(this,"frameRef"),c(this,"random",Math.random),this.frameRef=s,this.max=Math.max(1,Math.floor(i.max??200)),this.f=new Float32Array(this.max*le.W),this.tints=new Uint32Array(this.max),this.blend=i.blend??"normal",this.gravity=i.gravity??0,this.drag=i.drag??1}get alive(){return this.count}burst(e,s,i,n={}){const r=le.W,a=this.random,h=n.tint===void 0?16777215:ot(n.tint)[0];for(let l=0;l<i;l++){let o=this.count;if(o>=this.max){let y=0,m=1/0;for(let w=0;w<this.max;w++){const x=this.f[w*r+5]-this.f[w*r+4];x<m&&(m=x,y=w)}o=y}else this.count++;const u=(n.angle??0)+(n.spread===void 0?a()*Math.PI*2:(a()-.5)*n.spread),f=ti(n.speed,200,a),p=Array.isArray(n.scale)?n.scale[0]:n.scale??1,g=Array.isArray(n.scale)?n.scale[1]:n.scale??1,d=o*r;this.f[d]=e,this.f[d+1]=s,this.f[d+2]=Math.cos(u)*f,this.f[d+3]=Math.sin(u)*f,this.f[d+4]=0,this.f[d+5]=Math.max(ti(n.life,.8,a),.01),this.f[d+6]=a()*Math.PI*2,this.f[d+7]=(a()-.5)*2*(n.spin??0),this.f[d+8]=p,this.f[d+9]=g,this.f[d+10]=n.alpha??1,this.tints[o]=h}}update(e){const s=le.W,i=this.f,n=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let r=0;r<this.count;){const a=r*s;if(i[a+4]=i[a+4]+e,i[a+4]>=i[a+5]){const h=--this.count;r!==h&&(i.copyWithin(a,h*s,h*s+s),this.tints[r]=this.tints[h]);continue}i[a+3]=(i[a+3]+this.gravity*e)*n,i[a+2]=i[a+2]*n,i[a]=i[a]+i[a+2]*e,i[a+1]=i[a+1]+i[a+3]*e,i[a+6]=i[a+6]+i[a+7]*e,r++}}clear(){this.count=0}draw(e,s,i){if(!this.count)return;const n=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,r=le.W,a=this.f,h=this.world,l=n.w/n.scale,o=n.h/n.scale;for(let u=0;u<this.count;u++){const f=u*r,p=a[f+4]/a[f+5],g=a[f+8]+(a[f+9]-a[f+8])*p,d=s*a[f+10]*(1-p*p),y=a[f+6],m=Math.cos(y)*g,w=Math.sin(y)*g,x=a[f],_=a[f+1],M=h[0],k=h[1],F=h[2],R=h[3],N=M*m+F*w,I=k*m+R*w,D=F*m-M*w,W=R*m-k*w;q[0]=N,q[1]=I,q[2]=D,q[3]=W,q[4]=M*x+F*_+h[4]-(N*l+D*o)/2,q[5]=k*x+R*_+h[5]-(I*l+W*o)/2,U[0]=l,U[1]=o,U[2]=d,e.r.quadQ(e.tex(n.surface),n,q,qs(i,this.tints[u]),this.blend)}}};c(ei,"W",11);var si=ei,St=class extends It{constructor(t,e,s={}){const{fps:i,loop:n,playing:r,speed:a,onComplete:h,...l}=s;if(!e.frames.length)throw new Error("[engine] an animation needs at least one frame");super(t,e.frames[0],l),c(this,"frames"),c(this,"durations"),c(this,"fps"),c(this,"loop"),c(this,"speed"),c(this,"onComplete"),c(this,"_playing"),c(this,"index",0),c(this,"t",0),this.frames=e.frames,this.durations=e.durations&&i===void 0?e.durations:null,this.fps=i??12,this.loop=n!==!1,this.speed=a??1,this.onComplete=h??null,this._playing=r!==!1,this.speed<0&&this.show(e.frames.length-1)}get frameIndex(){return this.index}get frameCount(){return this.frames.length}get playing(){return this._playing}play(){return!this.loop&&!this._playing&&this.index===(this.speed<0?0:this.frames.length-1)&&this.show(this.speed<0?this.frames.length-1:0),this._playing=!0,this}stop(){return this._playing=!1,this}gotoFrame(t){const e=this.frames.length;return this.show((Math.floor(t)%e+e)%e),this.t=0,this}gotoAndPlay(t){return this._playing=!0,this.gotoFrame(t)}gotoAndStop(t){return this._playing=!1,this.gotoFrame(t)}show(t){t===this.index&&this._frame||(this.index=t,this.frame=this.frames[t])}secondsOf(t){const e=this.durations?.[t];return e!==void 0&&e>0?e:1/Math.max(this.fps,.001)}update(t){if(!this._playing||this.destroyed||this.speed===0)return;const e=this.frames.length,s=this.speed<0;this.t+=t*Math.abs(this.speed);let i=this.index;for(let n=0;n<1e3;n++){const r=this.secondsOf(i);if(this.t<r)break;this.t-=r;const a=s?i-1:i+1;if(a<0||a>=e){if(!this.loop){this.t=0,this._playing=!1,this.show(i),this.onComplete?.();return}i=s?e-1:0}else i=a}this.show(i)}},Yn=(t,e)=>t.localeCompare(e,void 0,{numeric:!0}),ii=class{constructor(t,e,s=2){c(this,"width",t),c(this,"height",e),c(this,"padding",s),c(this,"shelves",[]),c(this,"free",[]),c(this,"bottom",0)}alloc(t,e){const s=Math.ceil(t)+this.padding*2,i=Math.ceil(e)+this.padding*2;if(s>this.width||i>this.height)return null;for(let a=0;a<this.free.length;a++){const h=this.free[a];if(h.w>=s&&h.h>=i&&h.w*h.h<=s*i*2)return this.free.splice(a,1),this.inner(h.x,h.y,t,e)}let n=null;for(const a of this.shelves)a.h>=i&&a.h<=i*1.5+8&&this.width-a.x>=s&&(!n||a.h<n.h)&&(n=a);if(!n)if(this.bottom+i>this.height){for(const a of this.shelves)a.h>=i&&this.width-a.x>=s&&(n=a);if(!n)return null}else n={y:this.bottom,h:i,x:0},this.shelves.push(n),this.bottom+=i;const r=n.x;return n.x+=s,this.inner(r,n.y,t,e)}release(t){this.free.push({x:t.x-this.padding,y:t.y-this.padding,w:Math.ceil(t.w)+this.padding*2,h:Math.ceil(t.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(t,e,s,i){return{x:t+this.padding,y:e+this.padding,w:s,h:i}}},ye=t=>({source:t,texture:null,pending:[]}),as=class{constructor(t=2048,e=4){c(this,"pageSize",t),c(this,"maxPages",e),c(this,"pages",[]),c(this,"gen",1),c(this,"onPage",()=>{}),c(this,"onDrop",()=>{})}valid(t){return!!t&&(t.gen===this.gen||t.gen===0)}bake(t,e,s,i=1,n=0,r=0,a=0){const h=Math.max(1,Math.ceil(t)),l=Math.max(1,Math.ceil(e)),o=document.createElement("canvas");o.width=h,o.height=l;const u=o.getContext("2d");return s(u),this.put(o,h,l,i,n,r,a)}add(t,e=1,s=0,i=0){const n=document.createElement("canvas");return n.width=Math.max(1,t.width),n.height=Math.max(1,t.height),n.getContext("2d").drawImage(t,0,0),this.put(n,n.width,n.height,e,s,i,0)}release(t){if(t.gen!==this.gen)return;this.pages.find(s=>s.surface===t.surface)?.packer.release(t)}rebake(t,e,s,i,n=t.w,r=t.h){if(!this.valid(t)||e>n||s>r)return null;const a=Math.max(1,Math.ceil(e)),h=Math.max(1,Math.ceil(s)),l=this.pages.find(u=>u.surface===t.surface);if(!l)return null;const o=document.createElement("canvas");return o.width=Math.ceil(n),o.height=Math.ceil(r),i(o.getContext("2d")),l.ctx.clearRect(t.x,t.y,o.width,o.height),l.ctx.drawImage(o,t.x,t.y),t.surface.pending.push([o,t.x,t.y]),t.w=a,t.h=h,t}put(t,e,s,i,n,r,a){let h=null,l=this.pages.find(u=>(h=u.packer.alloc(e,s))!==null);if(l||(!(Math.max(e,s)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),l=this.pages[0],h=l?l.packer.alloc(e,s):null),(!l||!h)&&(l=this.newPage(Math.max(e,s)),h=l.packer.alloc(e,s))),!h)throw new Error(`[engine] ${e}\xD7${s} does not fit an atlas page`);const o=h;return l.ctx.drawImage(t,o.x,o.y),l.surface.pending.push([t,o.x,o.y]),{surface:l.surface,x:o.x,y:o.y,w:e,h:s,scale:i,gen:this.gen,ox:n,oy:r,margin:a}}newPage(t){let e=this.pageSize;for(;e<t+4;)e*=2;const s=document.createElement("canvas");s.width=s.height=e;const i=s.getContext("2d"),n=ye(s),r={surface:n,packer:new ii(e,e),ctx:i};return this.pages.push(r),this.onPage(n),r}wipe(){this.gen++;let t=0;for(let e=0;e<this.pages.length;e++){const s=this.pages[e];if(t<this.maxPages&&s.surface.source.width===this.pageSize){this.pages[t++]=s;continue}s.surface.pending=[],this.onDrop(s.surface)}this.pages.length=t;for(const e of this.pages)e.packer.reset(),e.ctx.clearRect(0,0,e.surface.source.width,e.surface.source.height),e.surface.pending=[],e.surface.pending.push([e.surface.source,0,0])}},jn=()=>globalThis.FabiPlay,ni=class{posed(t,e,s,i=!0){const n={id:t,body:e};return jn()?.smoothedBody(n,{smooth:s<1?s:!1,interpolate:i})??e}},ri=new Float64Array(1),ai=new Int32Array(ri.buffer),Bt=(t,e)=>(t=Math.imul(t^e,1540483477),t^t>>>15);function mt(t,e=2538058380){return t!==t?Bt(e,2146959360):(ri[0]=t===0?0:t,Bt(Bt(e,ai[0]),ai[1]))}function oi(t,e=2166136261){for(let s=0;s<t.length;s++)e=Math.imul(e^t.charCodeAt(s),16777619);return e}function yt(t){switch(typeof t){case"number":return mt(t);case"string":return oi(t);case"boolean":return t?1013904242:461845907;case"object":{if(t===null)return 625341585;if(Array.isArray(t)||t instanceof Float64Array){let i=1779033703^t.length;for(let n=0;n<t.length;n++){const r=t[n];i=Bt(i,typeof r=="number"?mt(r):yt(r))}return i}let e=1359893119;const s=t;for(const i in s){const n=s[i];n!==void 0&&(e=e+Bt(oi(i),yt(n))|0)}return Bt(e,2600822924)}default:return 0}}function Jt(t,e){if(t===e)return!0;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return typeof t=="number"&&typeof e=="number"&&t!==t&&e!==e;const s=Array.isArray(t)||t instanceof Float64Array;if(s!==(Array.isArray(e)||e instanceof Float64Array))return!1;if(s){const r=t,a=e;if(r.length!==a.length)return!1;for(let h=0;h<r.length;h++)if(r[h]!==a[h]&&!Jt(r[h],a[h]))return!1;return!0}const i=t,n=e;for(const r in i)if(i[r]!==void 0&&!Jt(i[r],n[r]))return!1;for(const r in n)if(n[r]!==void 0&&i[r]===void 0)return!1;return!0}function ve(t){if(typeof t!="object"||t===null)return t;if(Array.isArray(t))return t.map(ve);if(t instanceof Float64Array)return t.slice();const e={};for(const s in t)t[s]!==void 0&&(e[s]=ve(t[s]));return e}var hi=class{constructor(t=1/0){c(this,"max",t),c(this,"buckets",new Map),c(this,"n",0)}get size(){return this.n}get(t,e=yt(t)){const s=this.buckets.get(e);if(s){for(let i=0;i<s.length;i++)if(Jt(s[i].key,t))return s[i].value}}set(t,e,s=yt(t)){let i=this.buckets.get(s);if(i){for(const n of i)if(Jt(n.key,t)){n.value=e;return}}this.n>=this.max&&this.clear(),(!i||!this.buckets.has(s))&&this.buckets.set(s,i=[]),i.push({key:ve(t),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}},os=0,li=1,we=2,hs=3,ci=class{constructor(){c(this,"scale",1),c(this,"cOn",!1),c(this,"px0",0),c(this,"py0",0),c(this,"px1",0),c(this,"py1",0),c(this,"clipVer",0),c(this,"stack",[]),c(this,"sp",0),c(this,"real",0),c(this,"mute",0),c(this,"bnd",new Float64Array(4*(es+1))),c(this,"rx0",0),c(this,"ry0",0),c(this,"rx1",0),c(this,"ry1",0),c(this,"maxBlur",1/0),c(this,"time",0),c(this,"skipped",0),c(this,"gq",new Float64Array(4))}resetLayers(t){this.scale=t,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){const t=this.gq;this.grow(t[0],t[1],t[2],t[3])}grow(t,e,s,i){if(!this.real)return;const n=this.bnd,r=(this.real-1)*4;t<n[r]&&(n[r]=t),e<n[r+1]&&(n[r+1]=e),s>n[r+2]&&(n[r+2]=s),i>n[r+3]&&(n[r+3]=i)}area(t,e){const s=this.bnd,i=t*4,n=this.scale;return this.rx0=Math.max(Math.floor((s[i]-e)*n)-1,0),this.ry0=Math.max(Math.floor((s[i+1]-e)*n)-1,0),this.rx1=Math.min(Math.ceil((s[i+2]+e)*n)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((s[i+3]+e)*n)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(t,e,s,i){const n=this.scale,r=this.canvas.width,a=this.canvas.height,h=Math.min(Math.max(Math.round(t*n),0),r),l=Math.min(Math.max(Math.round(e*n),0),a),o=Math.min(Math.max(Math.round((t+s)*n),h),r),u=Math.min(Math.max(Math.round((e+i)*n),l),a);this.cOn&&h===this.px0&&l===this.py0&&o===this.px1&&u===this.py1||(this.cOn=!0,this.px0=h,this.py0=l,this.px1=o,this.py1=u,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(t){if(t<we&&(this.mute||this.real>=es||!this.pushLayer())&&(t+=2),t===hs)this.mute++;else if(t!==we){const e=this.real*4;this.bnd[e]=this.bnd[e+1]=1/0,this.bnd[e+2]=this.bnd[e+3]=-1/0,this.real++}return this.stack[this.sp++]=t,t<we}beginLayer(){return this.push(os)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===os?li:hs)}endLayer(t,e){if(!this.sp)return;let s=this.stack[--this.sp];if(s===hs){if(this.mute--,!this.sp)return;s=this.stack[--this.sp]}if(s===li){const i=--this.real,n=this.popLayer();this.area(i-1,0)&&this.composite(n,!0,1,null);const r=this.bnd,a=(i-1)*4,h=i*4;r[a]=Math.max(r[a],r[h]),r[a+1]=Math.max(r[a+1],r[h+1]),r[a+2]=Math.min(r[a+2],r[h+2]),r[a+3]=Math.min(r[a+3],r[h+3]),s=this.stack[--this.sp]}if(s===we)ts(e)&&(this.skipped+=e.length);else if(s===os){const i=--this.real,n=ts(e)?e:null,r=this.popLayer();if(this.area(i,n?$n(n,this.maxBlur):0)){this.composite(r,!1,t,n);const a=this.scale;this.grow(this.rx0/a,this.ry0/a,this.rx1/a,this.ry1/a)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}},Vn=256,fi=8<<20,K=new Float64Array(32),Z={x:0,y:0,w:0,h:0};function Qn(t){if(typeof t.filter!="string")return!1;t.filter="blur(1px)";const e=t.filter==="blur(1px)";return t.filter="none",e}function ls(t){const e=t.getContext("2d",{alpha:!0});return e?new Kn(t,e):null}var Kn=class extends ci{constructor(t,e){super(),c(this,"canvas",t),c(this,"ctx",e),c(this,"kind","canvas2d"),c(this,"maxTextureSize",4096),c(this,"features",{}),c(this,"info",{renderer:"canvas2d"}),c(this,"support"),c(this,"lost",!1),c(this,"fxr",null),c(this,"quads",0),c(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),c(this,"tinted",new Map),c(this,"tintedN",0),c(this,"lostListeners",[]),c(this,"restoredListeners",[]),c(this,"base"),c(this,"top"),c(this,"layers",[]),c(this,"scratch",[]),c(this,"nines",new Map),c(this,"ninePx",0),c(this,"frame",0),c(this,"hit",!1),c(this,"missed",new Map),this.support={filters:Qn(e),shaders:!1},this.base=this.top={ctx:e,clipped:!1,ver:0},t.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(s=>s())}),t.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(s=>s())})}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){return{id:ss(),width:t.width,height:t.height,source:t}}updateTexture(t,e,s=0,i=0){const n=e?s+e.width:1/0,r=e?i+e.height:1/0;for(const a of this.nines.values()){const h=a.key;h[0]===t.id&&h[1]<n&&h[1]+h[3]>s&&h[2]<r&&h[2]+h[4]>i&&this.dropNine(a)}for(const[a,h]of this.tinted){const l=h.filter(o=>o.id!==t.id);this.tintedN-=h.length-l.length,l.length?this.tinted.set(a,l):this.tinted.delete(a)}}destroyTexture(t){this.updateTexture(t)}begin(t,e,s){this.resetLayers(s),this.fxr?.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;const i=this.ctx;this.base.clipped&&i.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,this.canvas.width,this.canvas.height),e>0&&(i.fillStyle=Yt(t,e),i.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(t,e,s,i,n,r,a,h){U[0]=i,U[1]=n,U[2]=a,this.quadQ(t,e,s,r,h)}quadQ(t,e,s,i,n){e.w<=0||e.h<=0||(i===16777215?this.blit(t.source,e.x,e.y,e.w,e.h,s,n):this.blit(this.tint(t,e,i),0,0,e.w,e.h,s,n))}blit(t,e,s,i,n,r,a){const h=U[0],l=U[1],o=U[2];if(o<=0||this.mute)return;this.sync();const u=this.ctx,f=this.scale;if(this.real){const p=r[0]*h,g=r[1]*h,d=r[2]*l,y=r[3]*l;this.grow(r[4]+Math.min(0,p,d,p+d),r[5]+Math.min(0,g,y,g+y),r[4]+Math.max(0,p,d,p+d),r[5]+Math.max(0,g,y,g+y))}u.setTransform(r[0]*f,r[1]*f,r[2]*f,r[3]*f,r[4]*f,r[5]*f),u.globalAlpha=Math.min(o,1),a==="add"&&(u.globalCompositeOperation="lighter"),u.drawImage(t,e,s,i,n,0,0,h,l),a==="add"&&(u.globalCompositeOperation="source-over"),this.quads++}nineQ(t,e,s,i,n,r,a){var h,l;const o=s[8]+s[9],u=i[8]+i[9],f=Math.ceil(o*Math.hypot(n[0],n[1])*this.scale-1e-6),p=Math.ceil(u*Math.hypot(n[2],n[3])*this.scale-1e-6);if(n[1]===0&&n[2]===0||f>4096||p>4096)return!1;if(!(f>0&&p>0&&U[2]>0)||this.mute)return!0;let g=this.kept(t,e,s,i,f,p,r);const d=(g??(g=(h=this.scratch)[l=13*Math.ceil(Math.log2(f))+Math.ceil(Math.log2(p))]??(h[l]=document.createElement("canvas").getContext("2d")))).canvas;if(d.width<f&&(d.width=f),d.height<p&&(d.height=p),!this.hit){g.clearRect(0,0,f+2,p+2);for(let y=0;y<12;y+=4){const m=Math.round(i[y]*p/u),w=Math.round((i[y]+i[y+1])*p/u);for(let x=0;x<12;x+=4){const _=Math.round(s[x]*f/o),M=Math.round((s[x]+s[x+1])*f/o);Z.x=e.x+s[x+2],Z.y=e.y+i[y+2],Z.w=s[x+3],Z.h=i[y+3],!(M<=_||w<=m||Z.w<=0||Z.h<=0)&&(r===16777215?g.drawImage(t.source,Z.x,Z.y,Z.w,Z.h,_,m,M-_,w-m):g.drawImage(this.tint(t,Z,r),0,0,Z.w,Z.h,_,m,M-_,w-m))}}}return U[0]=o,U[1]=u,this.blit(d,0,0,f,p,n,a),!0}kept(t,e,s,i,n,r,a){K[0]=t.id,K[1]=e.x,K[2]=e.y,K[3]=e.w,K[4]=e.h,K[5]=n,K[6]=r,K[7]=a,K.set(s,8),K.set(i,20);const h=yt(K),l=this.nines.get(h);if(this.hit=!1,l)return Jt(l.key,K)?(l.used=this.frame,this.hit=!0,l.ctx):null;const o=this.missed,u=o.get(h);o.size>4096&&o.clear(),o.set(h,this.frame);const f=n*r;if(u!==this.frame-1||f>fi)return null;let p;for(;this.ninePx+f>fi;){let y;for(const x of this.nines.values())x.used<this.frame-1&&!(y&&y.used<=x.used)&&(y=x);if(!y)return null;const m=y.ctx.canvas,w=!p&&m.width>=n&&m.height>=r&&m.width*m.height<=2*f;this.dropNine(y,w),w&&(p=y.ctx)}const g=p??document.createElement("canvas").getContext("2d"),d=g.canvas;return p||(d.width=n,d.height=r),this.ninePx+=d.width*d.height,this.nines.set(h,{key:ve(K),ctx:g,used:this.frame}),g}dropNine(t,e=!1){this.nines.delete(yt(t.key));const s=t.ctx.canvas;this.ninePx-=s.width*s.height,e||(s.width=0)}dropNines(){for(const t of this.nines.values())this.dropNine(t)}tint(t,e,s){const i=mt(s,mt(e.h,mt(e.w,mt(e.y,mt(e.x,mt(t.id))))));let n=this.tinted.get(i);if(n)for(let h=0;h<n.length;h++){const l=n[h];if(l.id===t.id&&l.x===e.x&&l.y===e.y&&l.w===e.w&&l.h===e.h&&l.color===s)return l.canvas}this.tintedN>=Vn&&(this.tinted.clear(),this.tintedN=0,n=void 0);const r=document.createElement("canvas");r.width=Math.ceil(e.w),r.height=Math.ceil(e.h);const a=r.getContext("2d");return a.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),a.globalCompositeOperation="multiply",a.fillStyle=Yt(s),a.fillRect(0,0,e.w,e.h),a.globalCompositeOperation="destination-in",a.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),n||this.tinted.set(i,n=[]),n.push({id:t.id,x:e.x,y:e.y,w:e.w,h:e.h,color:s,canvas:r}),this.tintedN++,r}paint(t,e){this.sync();const s=this.ctx,i=this.scale;return s.setTransform(i,0,0,i,0,0),s.globalAlpha=Math.min(e,1),Yt(t)}ellipse(t,e,s,i,n,r,a){if(a<=0||s<=0||i<=0||this.mute)return;const h=Math.max(s,i);this.grow(t-h,e-h,t+h,e+h);const l=this.ctx;l.fillStyle=this.paint(r,a),l.beginPath(),l.ellipse(t,e,s,i,n,0,Math.PI*2),l.fill(),this.quads++}trace(t,e,s=0){if(this.real)for(let n=0;n<e;n++)this.grow(t[n*2]-s,t[n*2+1]-s,t[n*2]+s,t[n*2+1]+s);const i=this.ctx;i.beginPath(),i.moveTo(t[0],t[1]);for(let n=1;n<e;n++)i.lineTo(t[n*2],t[n*2+1])}polygon(t,e,s,i){if(i<=0||e<3||this.mute)return;const n=this.ctx;n.fillStyle=this.paint(s,i),this.trace(t,e),n.closePath(),n.fill(),this.quads++}stroke(t,e,s,i,n,r){if(n<=0||s<=0||e<1||this.mute)return;const a=this.ctx;a.strokeStyle=this.paint(i,n),a.lineWidth=s,a.lineCap="round",a.lineJoin="round",this.trace(t,e,s/2),e===1&&a.lineTo(t[0],t[1]),r&&a.closePath(),a.stroke(),this.quads++}sync(){const t=this.top;if(t.ver===this.clipVer)return;const e=t.ctx;t.clipped&&e.restore(),t.clipped=this.cOn,t.ver=this.clipVer,this.cOn&&(e.save(),e.setTransform(1,0,0,1,0,0),e.beginPath(),e.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),e.clip())}pushLayer(){const t=this.canvas.width,e=this.canvas.height;let s=this.layers[this.real];if(!s||s.ctx.canvas.width!==t||s.ctx.canvas.height!==e){const n=document.createElement("canvas");n.width=t,n.height=e;const r=n.getContext("2d");if(!r)return!1;s=this.layers[this.real]={ctx:r,clipped:!1,ver:-1}}const i=s.ctx;return s.clipped&&i.restore(),s.clipped=!1,s.ver=-1,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,t,e),this.top=s,this.ctx=i,!0}popLayer(){return this.top=this.real>0?this.layers[this.real-1]:this.base,this.ctx=this.top.ctx,this.layers[this.real].ctx.canvas}composite(t,e,s,i){let n=t,r="none";const a=i&&ht.c2d?this.fxr??(this.fxr=ht.c2d(this)):null;a&&(n=a.chain(t,i),r=a.css),this.sync();const h=this.ctx,l=this.rx0,o=this.ry0,u=this.rx1-l,f=this.ry1-o;h.setTransform(1,0,0,1,0,0),h.globalAlpha=Math.min(s,1),h.globalCompositeOperation=e?"destination-in":"source-over",r!=="none"&&(h.filter=r),h.drawImage(n,l,o,u,f,l,o,u,f),r!=="none"&&(h.filter="none"),h.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();const t=this.stats;return t.drawCalls=t.quads=this.quads,t.filtersSkipped=this.skipped,t}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],this.fxr?.destroy(),this.fxr=null}},te=14,zt=6,ui=8192,Zn=class{constructor(t,e,s=ui){c(this,"instanced",t),c(this,"slots",e),c(this,"capacity",s),c(this,"f32"),c(this,"u32"),c(this,"quads",0),c(this,"textures"),c(this,"bound",0),this.textures=new Array(e).fill(null);const i=s*(t?te:zt*4),n=new ArrayBuffer(i*4);this.f32=new Float32Array(n),this.u32=new Uint32Array(n)}slot(t){const e=this.textures;for(let s=0;s<this.bound;s++)if(e[s]===t)return s;return this.bound>=this.slots?-1:(e[this.bound]=t,this.bound++)}has(t){for(let e=0;e<this.bound;e++)if(this.textures[e]===t)return!0;return!1}get full(){return this.quads>=this.capacity}get words(){return this.quads*(this.instanced?te:zt*4)}reset(){this.quads=0;for(let t=0;t<this.bound;t++)this.textures[t]=null;this.bound=0}push(t,e,s,i,n,r,a,h,l,o,u,f,p,g){const d=this.f32;if(this.instanced){let y=this.quads*te;d[y++]=t,d[y++]=e,d[y++]=s,d[y++]=i,d[y++]=n,d[y++]=r,d[y++]=a,d[y++]=h,d[y++]=l,d[y++]=o,d[y++]=u,d[y++]=f,this.u32[y++]=p,d[y]=g}else{const y=this.quads*zt*4;this.vertex(y,t,e,l,o,p,g),this.vertex(y+6,s,i,u,o,p,g),this.vertex(y+12,n,r,u,f,p,g),this.vertex(y+18,a,h,l,f,p,g)}this.quads++}pushQ(t,e){const s=this.f32;if(this.instanced){const i=this.quads*te;for(let n=0;n<12;n++)s[i+n]=t[n];this.u32[i+12]=t[12],s[i+13]=e}else{let i=this.quads*zt*4;const n=t[12];for(let r=0;r<4;r++,i+=zt)s[i]=t[r*2],s[i+1]=t[r*2+1],s[i+2]=r===1||r===2?t[10]:t[8],s[i+3]=r>=2?t[11]:t[9],this.u32[i+4]=n,s[i+5]=e}this.quads++}vertex(t,e,s,i,n,r,a){const h=this.f32;h[t]=e,h[t+1]=s,h[t+2]=i,h[t+3]=n,this.u32[t+4]=r,h[t+5]=a}};function Jn(t){const e=new Uint16Array(t*6);for(let s=0,i=0,n=0;s<t;s++,i+=6,n+=4)e[i]=n,e[i+1]=n+1,e[i+2]=n+2,e[i+3]=n,e[i+4]=n+2,e[i+5]=n+3;return e}var J={M:0,L:1,Q:2,C:3,Z:4},di=[2,2,4,6,0],tr={M:0,L:1,Q:2,C:3,Z:4};function cs(t,e){if(t.length>=e)return t;const s=new Float64Array(Math.max(e,t.length*2,16));return s.set(t),s}var xe=new Map;function er(t){if(typeof t!="string")return t;let e=xe.get(t);if(e)return e;e=[];const s=t.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[];let i=-1;for(let n=0;n<s.length;){const r=s[n],a=tr[r.toUpperCase()];if(a!==void 0){i=a,n++,a===J.Z&&e.push(J.Z);continue}if(i<0||i===J.Z){n++;continue}const h=di[i];e.push(i);for(let l=0;l<h;l++)e.push(Number(s[n+l]??0));n+=h,i===J.M&&(i=J.L)}return xe.size>256&&xe.clear(),xe.set(t,e),e}var vt={subs:[],count:0},fs=null,wt=null;function be(t,e){let s=wt;s||(s=vt.subs[vt.count]??null,s||vt.subs.push(s={pts:new Float64Array(64),n:0,closed:!1}),s.n=0,s.closed=!1,vt.count++,wt=s);const i=s.n*2;i+2>s.pts.length&&(s.pts=cs(s.pts,i+2));const n=fs;n?(s.pts[i]=n[0]*t+n[2]*e+n[4],s.pts[i+1]=n[1]*t+n[3]*e+n[5]):(s.pts[i]=t,s.pts[i+1]=e),s.n++}function us(t,e=null,s=1,i=6){const n=er(t);vt.count=0,wt=null,fs=e;let r=0,a=0,h=0,l=0;const o=s/i;for(let u=0;u<n.length;){const f=n[u++],p=n;if(f===J.M)wt=null,r=h=p[u],a=l=p[u+1],be(r,a);else if(f===J.L)r=p[u],a=p[u+1],be(r,a);else if(f===J.Q){const g=p[u],d=p[u+1],y=p[u+2],m=p[u+3],w=pi((ft(g-r,d-a)+ft(y-g,m-d))*o);for(let x=1;x<=w;x++){const _=x/w,M=1-_;be(M*M*r+2*M*_*g+_*_*y,M*M*a+2*M*_*d+_*_*m)}r=y,a=m}else if(f===J.C){const g=p[u],d=p[u+1],y=p[u+2],m=p[u+3],w=p[u+4],x=p[u+5],_=pi((ft(g-r,d-a)+ft(y-g,m-d)+ft(w-y,x-m))*o);for(let M=1;M<=_;M++){const k=M/_,F=1-k,R=F*F*F,N=3*F*F*k,I=3*F*k*k,D=k*k*k;be(R*r+N*g+I*y+D*w,R*a+N*d+I*m+D*x)}r=w,a=x}else if(f===J.Z){wt&&(wt.closed=!0),wt=null,r=h,a=l;continue}else break;u+=di[f]}wt=null,fs=null;for(let u=0;u<vt.count;u++){const f=vt.subs[u],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 vt}var ft=(t,e)=>Math.sqrt(t*t+e*e),pi=t=>Math.min(Math.max(Math.ceil(t),2),24);function sr(t,e){let s=0;for(let i=0,n=e-1;i<e;n=i++)s+=(t[n*2]-t[i*2])*(t[n*2+1]+t[i*2+1]);return s}var Me=new Int32Array(64),ke=(t,e,s,i,n)=>((t[i*2]-t[s*2])*(t[n*2+1]-t[s*2+1])-(t[i*2+1]-t[s*2+1])*(t[n*2]-t[s*2]))*e;function ir(t,e,s){if(e<3)return 0;Me.length<e&&(Me=new Int32Array(Math.max(e,Me.length*2)));const i=Me;let n=e,r=0;for(let o=0;o<e;o++)i[o]=o;const a=sr(t,e)>0?1:-1;let h=e*e+8,l=0;for(;n>3&&h-- >0;){const o=i[(l+n-1)%n],u=i[l%n],f=i[(l+1)%n];let p=ke(t,a,o,u,f)>0;if(p)for(let g=0;g<n;g++){const d=i[g];if(!(d===o||d===u||d===f)&&ke(t,a,o,u,d)>=0&&ke(t,a,u,f,d)>=0&&ke(t,a,f,o,d)>=0){p=!1;break}}p?(s[r++]=o,s[r++]=u,s[r++]=f,i.copyWithin(l%n,l%n+1,n),n--,l=Math.max(l-1,0)):l=(l+1)%n}if(n===3)s[r++]=i[0],s[r++]=i[1],s[r++]=i[2];else if(n>3)for(let o=1;o+1<n;o++)s[r++]=i[0],s[r++]=i[o],s[r++]=i[o+1];return r}var nr=.85,Ae=new Float64Array(64),gi=new Float64Array(64),mi=new Float64Array(64),yi=new Float64Array(64),vi=new Float64Array(64),wi=new Float64Array(64),xi=new Uint8Array(64),_e=new Float64Array(8);function rr(t,e,s,i,n,r){const a=_e;if(Ae.length<e){const m=Math.max(e,Ae.length*2);Ae=new Float64Array(m),gi=new Float64Array(m),mi=new Float64Array(m),yi=new Float64Array(m),vi=new Float64Array(m),wi=new Float64Array(m),xi=new Uint8Array(m)}const h=Ae,l=gi;let o=0;for(let m=0;m<e;m++){const w=t[m*2],x=t[m*2+1];!Number.isFinite(w)||!Number.isFinite(x)||o&&Math.abs(h[o-1]-w)<.001&&Math.abs(l[o-1]-x)<.001||(h[o]=w,l[o]=x,o++)}if(i&&o>2&&Math.abs(h[0]-h[o-1])<.001&&Math.abs(l[0]-l[o-1])<.001&&o--,o===0)return;if(o===1)return a[0]=h[0],a[1]=l[0],r();const u=i?o:o-1,f=mi,p=yi;for(let m=0;m<u;m++){const w=(m+1)%o,x=h[w]-h[m],_=l[w]-l[m],M=ft(x,_)||1;f[m]=-_/M,p[m]=x/M}const g=vi,d=wi,y=xi;for(let m=0;m<o;m++){const w=i?(m-1+u)%u:m-1,x=m<u?m:-1;if(y[m]=1,w<0||x<0||f[w]*f[x]+p[w]*p[x]<nr)continue;let M=f[w]+f[x],k=p[w]+p[x];const F=ft(M,k)||1;M/=F,k/=F;const R=s/Math.max(M*f[x]+k*p[x],.5);g[m]=M*R,d[m]=k*R,y[m]=0}for(let m=0;m<u;m++){const w=(m+1)%o,x=y[m]?f[m]*s:g[m],_=y[m]?p[m]*s:d[m],M=y[w]?f[m]*s:g[w],k=y[w]?p[m]*s:d[w];a[0]=h[m]+x,a[1]=l[m]+_,a[2]=h[w]+M,a[3]=l[w]+k,a[4]=h[w]-M,a[5]=l[w]-k,a[6]=h[m]-x,a[7]=l[m]-_,n()}for(let m=0;m<o;m++)y[m]&&(a[0]=h[m],a[1]=l[m],r())}function bi(t,e){let s=0,i=1/0;for(let n=0;n<e.length;n++){const r=Math.abs(Math.log(Math.max(t,.5)/e[n]));r<i&&(i=r,s=n)}return s}var et=256,ds=[{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}],ps=[4,8,16,32,64,128].map((t,e)=>({x:e*4,y:128,w:4,h:t,r:t/2-1})),xt={x:248,y:248,w:8,h:8},ar=ds.map(t=>t.r*2),or=ps.map(t=>t.r*2),Mi=(t,e)=>Math.min(Math.max(t+.5-e,0),1);function hr(){const t=new Uint8ClampedArray(et*et*4),e=(s,i,n)=>{const r=(i*et+s)*4;t[r]=t[r+1]=t[r+2]=255,t[r+3]=Math.round(n*255)};for(const s of ds){const i=s.w/2;for(let n=0;n<s.h;n++)for(let r=0;r<s.w;r++)e(s.x+r,s.y+n,Mi(s.r,Math.hypot(r+.5-i,n+.5-i)))}for(const s of ps){const i=s.h/2;for(let n=0;n<s.h;n++)for(let r=0;r<s.w;r++)e(s.x+r,s.y+n,Mi(s.r,Math.abs(n+.5-i)))}for(let s=0;s<xt.h;s++)for(let i=0;i<xt.w;i++)e(xt.x+i,xt.y+s,1);return t}function lr(){const t=document.createElement("canvas");return t.width=t.height=et,t.getContext("2d").putImageData(new ImageData(hr(),et,et),0,0),t}var ki=8,gs=`
|
|
2
2
|
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
3
3
|
precision highp float;
|
|
4
4
|
#else
|
|
@@ -45,7 +45,7 @@ void main() {
|
|
|
45
45
|
vColor = aColor;
|
|
46
46
|
vSlot = aSlot;
|
|
47
47
|
gl_Position = vec4(p * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
|
|
48
|
-
}`,dr={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},pr=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],gr=["aPos","aUv","aColor","aSlot"];function mr(t,e,s={}){const i={...dr,failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat!==!1},n=e===2?t.getContext("webgl2",i):t.getContext("webgl",i)??t.getContext("experimental-webgl",i);if(!n||n.isContextLost())return null;try{return new yr(t,n,e,s)}catch(r){return console.warn("[engine] WebGL setup failed:",r),n.getExtension("WEBGL_lose_context")?.loseContext(),null}}var yr=class extends ci{constructor(t,e,s,i){super(),c(this,"canvas",t),c(this,"gl",e),c(this,"opts",i),c(this,"kind"),c(this,"maxTextureSize"),c(this,"support",{filters:!0,shaders:!0}),c(this,"features",{}),c(this,"info",{}),c(this,"lost",!1),c(this,"main"),c(this,"cur"),c(this,"unit",-1),c(this,"onUnit",new Array(ki).fill(void 0)),c(this,"fbNow"),c(this,"mapped",!0),c(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0}),c(this,"vsrc",""),c(this,"attrs",[]),c(this,"fxr",null),c(this,"batch"),c(this,"dynamic"),c(this,"staticBuf",null),c(this,"index"),c(this,"vao",null),c(this,"inst",null),c(this,"vaoApi",null),c(this,"uScale",null),c(this,"textures",new Map),c(this,"kit"),c(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),c(this,"lostListeners",[]),c(this,"restoredListeners",[]),c(this,"tris",new Int32Array(192)),c(this,"sU",0),c(this,"sV0",0),c(this,"sV1",0),c(this,"sColor",0),c(this,"sPacked",0),c(this,"sAlpha",0),c(this,"sHw",0),c(this,"strokeSeg",()=>{const n=this.q;n.set(_e),n[8]=n[10]=this.sU,n[9]=this.sV0,n[11]=this.sV1,n[12]=this.sPacked,this.put(this.kit)}),c(this,"strokeDisc",()=>this.ellipse(_e[0],_e[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha)),c(this,"q",new Float64Array(13)),c(this,"layers",[]),c(this,"layerTex",new Map),c(this,"bScis",!1),c(this,"bx0",0),c(this,"by0",0),c(this,"bx1",0),c(this,"by1",0),c(this,"onContextLost",n=>{n.preventDefault(),this.lost=!0;for(const r of this.lostListeners)r()}),c(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(const n of this.textures.keys())this.textures.set(n,this.upload(n.source));this.lost=!1;for(const n of this.restoredListeners)n()}catch(n){console.warn("[engine] WebGL restore failed:",n)}}),c(this,"views",new Map),this.kind=s===2?"webgl2":"webgl1",this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(lr()),ht.live=this,t.addEventListener("webglcontextlost",this.onContextLost,!1),t.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){const t=this.gl,e=this.kind==="webgl2"?t:null;if(this.inst=null,this.opts.instancing!==!1)if(e)this.inst={divisor:(o,u)=>e.vertexAttribDivisor(o,u),draw:(o,u)=>e.drawElementsInstanced(t.TRIANGLES,o,t.UNSIGNED_SHORT,0,u)};else{const o=t.getExtension("ANGLE_instanced_arrays");o&&(this.inst={divisor:(u,f)=>o.vertexAttribDivisorANGLE(u,f),draw:(u,f)=>o.drawElementsInstancedANGLE(t.TRIANGLES,u,t.UNSIGNED_SHORT,0,f)})}if(this.vaoApi=null,this.opts.vao!==!1)if(e)this.vaoApi={create:()=>e.createVertexArray(),bind:o=>e.bindVertexArray(o),remove:o=>e.deleteVertexArray(o)};else{const o=t.getExtension("OES_vertex_array_object");o&&(this.vaoApi={create:()=>o.createVertexArrayOES(),bind:u=>o.bindVertexArrayOES(u),remove:u=>o.deleteVertexArrayOES(u)})}const s=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),i=Math.max(1,Math.min(ki,s)),n=this.inst!==null;this.vsrc=n?ur:fr,this.attrs=n?pr:gr,this.main=this.cur=this.build(cr(i));const r=this.main.p;t.useProgram(r),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,t.uniform1iv(t.getUniformLocation(r,"uTex"),Int32Array.from({length:i},(o,u)=>u)),this.batch=new Zn(n,i),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic),t.bufferData(t.ARRAY_BUFFER,this.batch.f32.byteLength,t.DYNAMIC_DRAW),this.index=t.createBuffer(),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.index),t.bufferData(t.ELEMENT_ARRAY_BUFFER,Jn(n?1:ui),t.STATIC_DRAW);const a=o=>t.getAttribLocation(r,o),h=(o,u,f,p,g,d,y)=>{const m=a(o);m<0||(t.enableVertexAttribArray(m),t.vertexAttribPointer(m,u,f,p,g,d),this.inst&&this.inst.divisor(m,y))};if(n){const o=te*4;h("aP01",4,t.FLOAT,!1,o,0,1),h("aP23",4,t.FLOAT,!1,o,16,1),h("aUvRect",4,t.FLOAT,!1,o,32,1),h("aColor",4,t.UNSIGNED_BYTE,!0,o,48,1),h("aSlot",1,t.FLOAT,!1,o,52,1),this.staticBuf=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.staticBuf),t.bufferData(t.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t.STATIC_DRAW),h("aCorner",4,t.FLOAT,!1,16,0,0),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic)}else{const o=zt*4;h("aPos",2,t.FLOAT,!1,o,0,0),h("aUv",2,t.FLOAT,!1,o,8,0),h("aColor",4,t.UNSIGNED_BYTE,!0,o,16,0),h("aSlot",1,t.FLOAT,!1,o,20,0)}t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.disable(t.DEPTH_TEST),t.disable(t.CULL_FACE),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);const l=t.getExtension("WEBGL_debug_renderer_info");this.info={version:t.getParameter(t.VERSION),renderer:l?t.getParameter(l.UNMASKED_RENDERER_WEBGL):t.getParameter(t.RENDERER),vendor:l?t.getParameter(l.UNMASKED_VENDOR_WEBGL):t.getParameter(t.VENDOR)},this.features={instancing:n,vao:this.vaoApi!==null,textureSlots:i,maxTextureSize:this.maxTextureSize}}upload(t){const e=this.gl,s=e.createTexture();return this.bindTex(s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),s}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){const e={id:ss(),width:t.width,height:t.height,source:t};return this.textures.set(e,this.lost?null:this.upload(t)),e}updateTexture(t,e,s=0,i=0){if(this.lost)return;this.batch.has(t)&&this.flush();const n=this.gl,r=this.textures.get(t);r&&(this.bindTex(r),!e||e===t.source&&s===0&&i===0?n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t.source):n.texSubImage2D(n.TEXTURE_2D,0,s,i,n.RGBA,n.UNSIGNED_BYTE,e))}destroyTexture(t){this.batch.has(t)&&this.flush();const e=this.textures.get(t);e&&!this.lost&&this.deleteTex(e),this.textures.delete(t)}begin(t,e,s){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(s),this.bScis=!1,this.lost)return;const i=this.gl;i.disable(i.SCISSOR_TEST),this.bindFb(null),i.viewport(0,0,this.canvas.width,this.canvas.height);const n=e;i.clearColor((t>>16&255)/255*n,(t>>8&255)/255*n,(t&255)/255*n,n),i.clear(i.COLOR_BUFFER_BIT),this.use(this.main),i.uniform2f(this.uScale,2*s/this.canvas.width,-2*s/this.canvas.height),this.mapped=!0}build(t){const e=this.gl,s=Ai(e,e.VERTEX_SHADER,this.vsrc);let i;try{i=Ai(e,e.FRAGMENT_SHADER,t)}catch(r){throw e.deleteShader(s),r}const n=e.createProgram();if(e.attachShader(n,s),e.attachShader(n,i),this.attrs.forEach((r,a)=>e.bindAttribLocation(n,a,r)),e.linkProgram(n),e.deleteShader(s),e.deleteShader(i),!e.getProgramParameter(n,e.LINK_STATUS)){const r=e.getProgramInfoLog(n)??"?";throw e.deleteProgram(n),new Error(`link: ${r}`)}return{p:n,uScale:e.getUniformLocation(n,"uScale"),locs:new Map}}u(t,e){let s=t.locs.get(e);return s===void 0&&t.locs.set(e,s=this.gl.getUniformLocation(t.p,e)),s}use(t){this.cur!==t&&(this.cur=t,this.gl.useProgram(t.p),this.calls.useProgram++)}bindTex(t,e=this.unit<0?0:this.unit){const s=this.gl;this.onUnit[e]!==t&&(this.unit!==e&&(s.activeTexture(s.TEXTURE0+e),this.calls.activeTexture++,this.unit=e),s.bindTexture(s.TEXTURE_2D,t),this.calls.bindTexture++,this.onUnit[e]=t)}deleteTex(t){this.gl.deleteTexture(t);for(let e=0;e<this.onUnit.length;e++)this.onUnit[e]===t&&(this.onUnit[e]=null)}bindFb(t){if(t)for(let s=0;s<this.onUnit.length;s++)this.onUnit[s]===t.gl&&this.bindTex(null,s);const e=t?t.fb:null;this.fbNow!==e&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,e),this.calls.bindFramebuffer++,this.fbNow=e)}slotOf(t){this.batch.full&&this.flush();let e=this.batch.slot(t);return e<0&&(this.flush(),e=this.batch.slot(t)),e}quad(t,e,s,i,n,r,a,h){U[0]=i,U[1]=n,U[2]=a,this.quadQ(t,e,s,r,h)}quadQ(t,e,s,i,n){const r=U[2];if(this.lost||r<=0)return;const a=this.q,h=U[0],l=U[1],o=s[4],u=s[5],f=s[0]*h,p=s[1]*h,g=s[2]*l,d=s[3]*l;a[0]=o,a[1]=u,a[2]=f+o,a[3]=p+u,a[4]=f+g+o,a[5]=p+d+u,a[6]=g+o,a[7]=d+u;const y=1/t.width,m=1/t.height;a[8]=e.x*y,a[9]=e.y*m,a[10]=(e.x+e.w)*y,a[11]=(e.y+e.h)*m,a[12]=Lt(i,r,n==="add"),this.put(t)}put(t){if(this.mute)return;const e=this.q;let s=!1;const i=Math.min(e[0],e[2],e[4],e[6]),n=Math.max(e[0],e[2],e[4],e[6]),r=Math.min(e[1],e[3],e[5],e[7]),a=Math.max(e[1],e[3],e[5],e[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;const l=this.scale,o=this.px0/l,u=this.py0/l,f=this.px1/l,p=this.py1/l;if(n<=o||i>=f||a<=u||r>=p)return;if(i<o||n>f||r<u||a>p){const g=e[0],d=e[1],y=e[2],m=e[5];if(d===e[3]&&y===e[4]&&m===e[7]&&e[6]===g){if(g!==y){const w=Math.min(Math.max(g,o),f),x=Math.min(Math.max(y,o),f),_=e[8],M=(e[10]-_)/(y-g);e[10]=_+(x-g)*M,e[8]=_+(w-g)*M,e[0]=e[6]=w,e[2]=e[4]=x}if(d!==m){const w=Math.min(Math.max(d,u),p),x=Math.min(Math.max(m,u),p),_=e[9],M=(e[11]-_)/(m-d);e[11]=_+(x-d)*M,e[9]=_+(w-d)*M,e[1]=e[3]=w,e[5]=e[7]=x}}else s=!0}}const h=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(s?(!this.bScis||!h)&&(this.flush(),this.bScis=!0,this.bx0=this.px0,this.by0=this.py0,this.bx1=this.px1,this.by1=this.py1):this.bScis&&!(this.cOn&&h)&&(this.flush(),this.bScis=!1),this.real){const l=this.gq;l[0]=i,l[1]=r,l[2]=n,l[3]=a,this.growQ()}this.batch.pushQ(e,this.slotOf(t))}ellipse(t,e,s,i,n,r,a){if(this.lost||a<=0||s<=0||i<=0)return;const h=ds[bi(Math.max(s,i)*2*this.scale,ar)],l=h.w/2/h.r,o=s*l,u=i*l,f=Math.cos(n),p=Math.sin(n),g=f*o,d=p*o,y=-p*u,m=f*u,w=1/et,x=this.q;x[0]=t-g-y,x[1]=e-d-m,x[2]=t+g-y,x[3]=e+d-m,x[4]=t+g+y,x[5]=e+d+m,x[6]=t-g+y,x[7]=e-d+m,x[8]=h.x*w,x[9]=h.y*w,x[10]=(h.x+h.w)*w,x[11]=(h.y+h.h)*w,x[12]=Lt(r,a),this.put(this.kit)}polygon(t,e,s,i){if(this.lost||i<=0||e<3)return;this.tris.length<e*3&&(this.tris=new Int32Array(Math.max(e*3,this.tris.length*2)));const n=this.tris,r=ir(t,e,n),a=Lt(s,i),h=(xt.x+xt.w/2)/et,l=(xt.y+xt.h/2)/et;for(let o=0;o<r;o+=3){const u=n[o]*2,f=n[o+1]*2,p=n[o+2]*2,g=this.q;g[0]=t[u],g[1]=t[u+1],g[2]=t[f],g[3]=t[f+1],g[4]=g[6]=t[p],g[5]=g[7]=t[p+1],g[8]=g[10]=h,g[9]=g[11]=l,g[12]=a,this.put(this.kit)}}stroke(t,e,s,i,n,r){if(this.lost||n<=0||s<=0||e<1)return;const a=ps[bi(s*this.scale,or)],h=s/2*(a.h/2/a.r);this.sPacked=Lt(i,n),this.sColor=i,this.sAlpha=n,this.sU=(a.x+a.w/2)/et,this.sV0=a.y/et,this.sV1=(a.y+a.h)/et,this.sHw=s/2,rr(t,e,h,r,this.strokeSeg,this.strokeDisc)}target(t,e,s,i){const n=this.gl,r=n.createTexture();this.bindTex(r),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,e,0,n.RGBA,n.UNSIGNED_BYTE,null);const a=i?n.LINEAR:n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),this.bindTex(null);const h=n.createFramebuffer();n.bindFramebuffer(n.FRAMEBUFFER,h),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,r,0);const l=n.checkFramebufferStatus(n.FRAMEBUFFER)===n.FRAMEBUFFER_COMPLETE;if(this.fbNow=h,this.bindFb(this.parent()),!l)return this.deleteTex(r),n.deleteFramebuffer(h),null;const o={tex:{id:ss(),width:t,height:e,source:this.canvas},gl:r,fb:h,w:t,h:e,f:s};return this.layerTex.set(o.tex,r),o}drop(t){this.batch.has(t.tex)&&this.flush(),this.deleteTex(t.gl),this.gl.deleteFramebuffer(t.fb),this.layerTex.delete(t.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(t){const e=this.canvas.width,s=this.canvas.height;let i=this.layers[t]??null;return i&&(i.w!==e||i.h!==s)&&(this.drop(i),i=this.layers[t]=null),i??(this.layers[t]=this.target(e,s,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();const t=this.layerAt(this.real);if(!t)return!1;const e=this.gl;return this.bindFb(t),e.disable(e.SCISSOR_TEST),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!ht.gl?null:this.fxr??(this.fxr=ht.gl(this))}composite(t,e,s,i){if(i&&this.filters()?.chain(t,s,i))return;const n=this.gl;e&&n.blendFunc(n.ZERO,n.SRC_ALPHA),this.final(this.main,t,1,s),e&&(this.flush(),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA))}final(t,e,s,i){const n=this.gl,r=this.canvas.width,a=this.canvas.height,h=this.scale;(t!==this.main||!this.mapped)&&(this.bindFb(this.parent()),n.viewport(0,0,r,a),this.use(t),n.uniform2f(t.uScale,2*h/r,-2*h/a),this.mapped=t===this.main);const l=this.rx0/h,o=this.ry0/h,u=this.rx1/h,f=this.ry1/h,p=1/(s*e.width),g=1/(s*e.height),d=this.q;d[0]=d[6]=l,d[1]=d[3]=o,d[2]=d[4]=u,d[5]=d[7]=f,d[8]=this.rx0*p,d[9]=1-this.ry0*g,d[10]=this.rx1*p,d[11]=1-this.ry1*g,d[12]=Lt(16777215,i),this.put(e),t!==this.main&&this.flush()}remap(){const t=this.gl;this.bindFb(this.parent()),t.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),t.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(t){const e=this.gl,s=t.words;if(this.kind==="webgl2")return e.bufferSubData(e.ARRAY_BUFFER,0,t.f32,0,s);let i=this.views.get(s);i||(this.views.size>=256&&this.views.clear(),this.views.set(s,i=t.f32.subarray(0,s))),e.bufferSubData(e.ARRAY_BUFFER,0,i)}flush(){const t=this.batch;if(!t.quads||this.lost)return t.reset();const e=this.gl;this.bScis?(e.enable(e.SCISSOR_TEST),e.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):e.disable(e.SCISSOR_TEST),this.upload2(t);for(let s=0;s<t.bound;s++){const i=t.textures[s];this.bindTex(this.textures.get(i)??this.layerTex.get(i)??null,s)}this.inst?this.inst.draw(6,t.quads):e.drawElements(e.TRIANGLES,t.quads*6,e.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=t.quads,t.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){const t=this.gl;ht.live===this&&(ht.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(const e of this.textures.values())e&&t.deleteTexture(e);for(const e of this.layers)e&&(t.deleteTexture(e.gl),t.deleteFramebuffer(e.fb));this.fxr?.destroy(),this.fxr=null,t.deleteBuffer(this.dynamic),t.deleteBuffer(this.index),this.staticBuf&&t.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),t.deleteProgram(this.main.p),t.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function Ai(t,e,s){const i=t.createShader(e);if(t.shaderSource(i,s),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS)){const n=t.getShaderInfoLog(i)??"?";throw t.deleteShader(i),new Error(n)}return i}function _i(t="auto"){switch(t){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function ms(t,e={}){let s=t;for(const i of _i(e.renderer)){const n=i==="canvas2d"?ls(s):mr(s,i==="webgl2"?2:1,e);if(n)return n;s=ys(s)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function ys(t){const e=t.cloneNode(!1);return t.parentNode?.replaceChild(e,t),e}function vr(t=typeof location<"u"?location.search:""){const e=new URLSearchParams(t).get("renderer");return e==="canvas"?"canvas2d":e==="webgl2"||e==="webgl1"||e==="canvas2d"||e==="webgl"||e==="auto"?e:void 0}var vs=class{constructor(t,e={}){c(this,"atlas",t),c(this,"tags",new Map),c(this,"count",0),c(this,"m",Nt()),c(this,"measure",null),c(this,"height"),c(this,"font"),this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(const t of this.tags.values())for(const e of t.values())for(const s of e.values())this.atlas.release(s);this.tags.clear(),this.count=0}get(t,e,s){let i=this.tags.get(t);i||this.tags.set(t,i=new Map);let n=i.get(e);n||i.set(e,n=new Map);const r=n.get(s);return r&&this.atlas.valid(r)?r:this.bake(t,e,s)}bake(t,e,s){const i=this.height,n=`700 ${Math.round(i*.65)}px ${this.font}`,r=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));r.font=n;const a=Math.round(i*.4),h=Math.ceil(r.measureText(t).width)+a*2,l=this.atlas.bake((h+2)*s,(i+2)*s,f=>{f.scale(s,s),f.translate(1,1);const p=i/2;f.beginPath(),f.moveTo(p,0),f.lineTo(h-p,0),f.arc(h-p,p,p,-Math.PI/2,Math.PI/2),f.lineTo(p,i),f.arc(p,p,p,Math.PI/2,Math.PI*3/2),f.closePath(),f.fillStyle=e,f.fill(),f.fillStyle="#fff",f.font=n,f.textAlign="center",f.textBaseline="middle",f.fillText(t,h/2,i/2+1)},s,1,1,1);++this.count>64&&(this.drop(),this.count=1);let o=this.tags.get(t);o||this.tags.set(t,o=new Map);let u=o.get(e);return u||o.set(e,u=new Map),u.set(s,l),l}draw(t,e,s,i,n,r,a,h,l,o,u){const f=Cn(s,n,{band:wr(i)});if(!f)return;const p=this.height,g=this.get(r,a,l),d=g.w/g.scale-2,y=Math.min(Math.max(f.head.x-d/2,4),o-d-4),m=Math.min(Math.max(f.head.y-f.headR*2.2-p,4),u-p-4);ct(this.m,null,y-1,m-1,0,1,1),t.quad(e(g.surface),g,this.m,g.w/g.scale,g.h/g.scale,16777215,h,"normal")}},wr=t=>t.band==="3-5"||t.band==="9-12"?t.band:"6-8",xr=(t,e=!1)=>e?Math.min(2**Math.round(Math.log2(Math.max(t,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(t,8))*2)/2),512);function ws(t,e=null){const s={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},i=(n,r,a)=>{const h=e?e[0]*n+e[2]*r+e[4]:n,l=e?e[1]*n+e[3]*r+e[5]:r,o=e?Math.hypot(e[0],e[1]):1;s.minX=Math.min(s.minX,h-a*o),s.minY=Math.min(s.minY,l-a*o),s.maxX=Math.max(s.maxX,h+a*o),s.maxY=Math.max(s.maxY,l+a*o)};for(const n of t){const r="lw"in n&&n.stroke?(n.lw??1)/2:0;switch(n.k){case"circle":i(n.x-n.r,n.y-n.r,r),i(n.x+n.r,n.y+n.r,r),i(n.x-n.r,n.y+n.r,r),i(n.x+n.r,n.y-n.r,r);break;case"ellipse":case"rect":{const a=n.k==="ellipse"?Math.max(n.rx,n.ry):Math.hypot(n.w,n.h)/2;i(n.x-a,n.y-a,r),i(n.x+a,n.y+a,r),i(n.x-a,n.y+a,r),i(n.x+a,n.y-a,r);break}case"path":{const a=us(n.d);for(let h=0;h<a.count;h++){const l=a.subs[h];for(let o=0;o<l.n;o++)i(l.pts[o*2],l.pts[o*2+1],r)}break}case"line":for(let a=0;a+1<n.pts.length;a+=2)i(n.pts[a],n.pts[a+1],r);break;case"group":{const a=ct(Nt(),e,n.x,n.y,n.rot??0,n.s??1,n.s??1),h=ws(n.items,a);Number.isFinite(h.minX)&&(s.minX=Math.min(s.minX,h.minX),s.minY=Math.min(s.minY,h.minY),s.maxX=Math.max(s.maxX,h.maxX),s.maxY=Math.max(s.maxY,h.maxY));break}}}return s}var xs=class{constructor(t){c(this,"atlas",t),c(this,"seen",new WeakSet),c(this,"baked",new WeakMap),c(this,"m",Nt()),c(this,"stack",[]),c(this,"local",Nt()),c(this,"pts",new Float64Array(128)),c(this,"stats",{baked:0,vector:0}),c(this,"bakeGroups",!0),c(this,"coarse",!1),c(this,"gen",0),c(this,"live",new Set)}setTier(t){const e=t==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(const s of this.live)this.atlas.release(s.frame);this.live.clear()}}draw(t,e,s,i,n,r,a){const h=typeof i=="string"?de(i)??pe:i,l=Rn(s,h,n);return l.length?(r<=0||(r<1?(this.paint(t,e,l,null,t.beginLayer()?1:r,a),t.endLayer(r)):this.paint(t,e,l,null,r,a)),!0):!1}paint(t,e,s,i,n,r,a=0){var h;for(let l=0;l<s.length;l++){const o=s[l];if(o.k==="group"){const w=ct((h=this.stack)[a]??(h[a]=Nt()),i,o.x,o.y,o.rot??0,o.s??1,o.s??1),x=n*(o.alpha??1);if(this.bakeGroups&&this.seen.has(o.items)){const _=ft(w[0],w[1])*r,M=this.bake(o.items,_);if(M){const k=M.frame,F=this.m;F.set(w),F[4]=w[0]*-M.ox+w[2]*-M.oy+w[4],F[5]=w[1]*-M.ox+w[3]*-M.oy+w[5],t.quad(e(k.surface),k,F,k.w/M.k,k.h/M.k,16777215,x,"normal"),this.stats.baked++;continue}}this.seen.add(o.items),this.stats.vector++,this.paint(t,e,o.items,w,x,r,a+1);continue}const u=n*(o.alpha??1),f=i?ft(i[0],i[1]):1,p=i?Math.atan2(i[1],i[0]):0,g=(o.lw??1)*f,d=o.stroke&&(o.lw??1)>0?ot(o.stroke):null,y=o.fill&&o.k!=="line"?ot(o.fill):null;if(o.k==="circle"||o.k==="ellipse"){const w=i?i[0]*o.x+i[2]*o.y+i[4]:o.x,x=i?i[1]*o.x+i[3]*o.y+i[5]:o.y,_=(o.k==="circle"?o.r:o.rx)*f,M=(o.k==="circle"?o.r:o.ry)*f,k=(o.k==="ellipse"?o.rot??0:0)+p;if(y&&d)t.ellipse(w,x,_+g/2,M+g/2,k,d[0],u*d[1]),t.ellipse(w,x,Math.max(_-g/2,0),Math.max(M-g/2,0),k,y[0],u*y[1]);else if(y)t.ellipse(w,x,_,M,k,y[0],u*y[1]);else if(d){const F=Math.min(Math.max(Math.ceil(Math.max(_,M)*r*.6),12),64),R=this.pts=cs(this.pts,F*2),N=Math.cos(k),I=Math.sin(k);for(let D=0;D<F;D++){const W=D/F*Math.PI*2,X=Math.cos(W)*_,z=Math.sin(W)*M;R[D*2]=w+X*N-z*I,R[D*2+1]=x+X*I+z*N}t.stroke(R,F,g,d[0],u*d[1],!0)}continue}if(o.k==="line"){if(!d)continue;const w=o.pts.length>>1,x=this.pts=cs(this.pts,w*2);for(let _=0;_<w;_++){const M=o.pts[_*2],k=o.pts[_*2+1];x[_*2]=i?i[0]*M+i[2]*k+i[4]:M,x[_*2+1]=i?i[1]*M+i[3]*k+i[5]:k}t.stroke(x,w,g,d[0],u*d[1],!1);continue}const m=o.k==="path"?us(o.d,i,f*r):br(o,ct(this.local,i,o.x,o.y,o.rot??0,1,1),r*f);for(let w=0;w<m.count;w++){const x=m.subs[w],_=x.n,M=o.k==="rect"||x.closed;y&&_>=3&&(t.polygon(x.pts,_,y[0],u*y[1]),d||t.stroke(x.pts,_,1/r,y[0],u*y[1],!0)),d&&t.stroke(x.pts,_,g,d[0],u*d[1],M)}}}bake(t,e){const s=xr(e,this.coarse);let i=this.baked.get(t);const n=i?.get(s);if(n&&n.gen===this.gen&&this.atlas.valid(n.frame))return n;n&&this.live.delete(n);const r=ws(t);if(!Number.isFinite(r.minX))return null;const a=2/s,h=(r.maxX-r.minX+a*2)*s,l=(r.maxY-r.minY+a*2)*s;if(h>1024||l>1024)return null;const o=-r.minX+a,u=-r.minY+a,p={frame:this.atlas.bake(h,l,g=>{g.scale(s,s),g.translate(o,u),Xs(g,t)}),k:s,ox:o,oy:u,gen:this.gen};return i||this.baked.set(t,i=new Map),i.set(s,p),this.live.add(p),p}},Gt=new Array(36).fill(0),Xt=0,lt=(t,e=NaN,s=NaN,i=NaN,n=NaN)=>{Gt[Xt++]=t,t!==J.Z&&(Gt[Xt++]=e,Gt[Xt++]=s,t===J.Q&&(Gt[Xt++]=i,Gt[Xt++]=n))};function br(t,e,s){const i=Math.max(0,Math.min(t.r,t.w/2,t.h/2)),n=-t.w/2,r=-t.h/2,{M:a,L:h,Q:l,Z:o}=J;return Xt=0,lt(a,n+i,r),lt(h,n+t.w-i,r),lt(l,n+t.w,r,n+t.w,r+i),lt(h,n+t.w,r+t.h-i),lt(l,n+t.w,r+t.h,n+t.w-i,r+t.h),lt(h,n+i,r+t.h),lt(l,n,r+t.h,n,r+t.h-i),lt(h,n,r+i),lt(l,n,r,n+i,r),lt(o),us(Gt,e,s)}function Mr(t,e={}){let s=ms(t,e);const i=new as(Math.min(1024,s.maxTextureSize),2);i.onDrop=k=>{k.texture&&s.destroyTexture(k.texture),k.texture=null};const n=new xs(i);let r=new ni;const a=new Map;let h=1e6;const l=e.smooth===!1?1:typeof e.smooth=="number"?Math.min(Math.max(e.smooth,.05),1):.5;let o=Te(s);const u=new vs(i,e),f={w:1,h:1};let p=1,g=0,d=!1;const y=()=>u.drop(),m=typeof document<"u"?document.fonts:void 0;m?.ready?.then(()=>{d||y()}),m?.addEventListener?.("loadingdone",y);const w=()=>{const k=ys(s.canvas),F=ls(k);if(F){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),s.destroy(),s=F;for(const R of i.pages)R.surface.texture=null;o=Te(s),g=0}},x=()=>{if(!s.lost)return g=0,!0;const k=performance.now();return g||(g=k),k-g>3e3&&w(),!s.lost},_=()=>{const k=s.canvas;e.units?(p=e.pixelRatio??1,f.w=e.units.width,f.h=e.units.height):(p=e.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),f.w=k.clientWidth||k.width/p,f.h=k.clientHeight||k.height/p),s.resize(Math.max(1,Math.round(f.w*p)),Math.max(1,Math.round(f.h*p))),s.begin(0,0,p)},M=(k,F)=>{if(k.key===void 0)return k.id??F+1;let R=a.get(k.key);return R===void 0&&(a.size>256&&a.clear(),a.set(k.key,R=h++)),R};return{get renderer(){return s},get kind(){return s.kind},get lost(){return s.lost},get canvas(){return s.canvas},draw(k,F){if(x()){_();for(let R=0;R<k.length;R++){const N=k[R];if(!Array.isArray(N.body))continue;const I=M(N,R),D=l<1||e.interpolate!==!1?r.posed(I,N.body,l,e.interpolate!==!1):N.body,W=de(N.avatar??"")??pe,X=N.alpha??1;!n.draw(s,o,D,W,F,X,p)||!N.name||u.draw(s,o,D,W,F,N.name,N.color??"#6FA0E0",X,p,f.w,f.h)}s.end()}},clear(){x()&&(_(),s.end())},reset(){r=new ni,a.clear()},destroy(){d=!0,m?.removeEventListener?.("loadingdone",y),s.destroy()}}}var Ee=new Map;function kr(t,e,s=Math.min(globalThis.devicePixelRatio||1,2)){const i=`${t}|${e}|${s}`;let n=Ee.get(i);if(n)return n;n=document.createElement("canvas"),n.width=n.height=Math.round(e*s);const r=n.getContext("2d");return r.scale(s,s),r.beginPath(),r.rect(0,0,e,e),r.clip(),Xs(r,Pn(de(t)??pe,e)),Ee.size>64&&Ee.clear(),Ee.set(i,n),n}function Te(t){return e=>{if(e.texture||(e.texture=t.createTexture(e.source),e.pending.length=0),e.pending.length){for(const[s,i,n]of e.pending)t.updateTexture(e.texture,s,i,n);e.pending.length=0}return e.texture}}var Ei='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',ee="rgba(10,16,30,0.75)";function Ti(t,e){const s=t.size??40,i=t.outline?t.outline===!0?ee:t.outline:null,n=i?t.outlineWidth??Math.max(s*.12,3):0,r=t.shadow&&e?t.shadow===!0?ee:t.shadow:null,a=r?t.shadowBlur??s*.25:0;return{size:s,font:t.font??Ei,weight:t.weight??700,color:t.color??"#FBEFE3",outline:i,ow:n,shadow:r,blur:a,pad:n/2+a*1.2+2,th:s*1.25}}var Si=(t,e)=>`${t.weight} ${t.size*e}px ${t.font}`;function Fi(t,e,s,i,n,r){t.scale(i,i),t.font=Si(s,1),t.textBaseline="middle",t.textAlign="left",t.lineJoin="round",s.shadow&&(t.shadowColor=s.shadow,t.shadowBlur=s.blur*i),s.outline&&(t.strokeStyle=s.outline,t.lineWidth=s.ow,t.strokeText(e,n,r),t.shadowColor="transparent"),t.fillStyle=s.color,t.fillText(e,n,r)}var Se=null;function Ri(t,e,s){return Se??(Se=document.createElement("canvas").getContext("2d")),Se.font=Si(e,s),Se.measureText(t).width/s}var se=class extends It{constructor(t,e,s={}){super(t,null),c(this,"_text"),c(this,"_style"),c(this,"dirty",!0),c(this,"bakedScale",0),c(this,"bakedFontGen",-1),c(this,"bakedEffects",!0),c(this,"capW",0),c(this,"capH",0),this._text=e;const{x:i,y:n,rotation:r,scale:a,scaleX:h,scaleY:l,alpha:o,visible:u,tint:f,blend:p,z:g,anchor:d,hitRadius:y,clip:m,mask:w,filters:x,..._}=s;this._style=_,this.bake(),this.set({x:i,y:n,rotation:r,scale:a,scaleX:h,scaleY:l,alpha:o,visible:u,tint:f,blend:p,z:g,hitRadius:y,clip:m,mask:w,filters:x}),d!==void 0&&(this.anchor=d)}get text(){return this._text}set text(t){const e=String(t);e!==this._text&&(this._text=e,this.dirty=!0)}get style(){return this._style}set style(t){this._style={...this._style,...t},this.dirty=!0}bitmap(){const t=this._style.bitmapFont;if(!t)return null;const e=typeof t=="string"?this.kernel.bitmapFont(t):t;if(this.autoAnchor){const s=this._style.align;this.anchorX=s==="left"?0:s==="right"?1:.5,this.anchorY=.5}return e}get naturalWidth(){const t=this.bitmap();return t?t.measure(this._text)*((this._style.size??t.size)/t.size):super.naturalWidth}get naturalHeight(){const t=this.bitmap();return t?t.lineHeight*((this._style.size??t.size)/t.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(t,e,s){const i=this.bitmap();if(!i)return super.draw(t,e,s);const n=(this._style.size??i.size)/i.size,r=i.measure(this._text)*n,a=i.lineHeight*n,h=this.width,l=this.height,o=r>0?h/r:1,u=a>0?l/a:1;i.run(this._text,t,this.world,-this.anchorX*h,-this.anchorY*l,n*o,n*u,s,e,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){const t=this.kernel;if(this._style.bitmapFont)return null;const e=t.pixelScale,s=t.effects;return!this.dirty&&e===this.bakedScale&&t.fontGen===this.bakedFontGen&&s===this.bakedEffects&&t.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){const t=this.kernel,e=t.pixelScale,s=t.effects;this.dirty=!1,this.bakedScale=e,this.bakedFontGen=t.fontGen,this.bakedEffects=s;const i=Ti(this._style,s),{pad:n,th:r}=i,a=Ri(this._text,i,e),h=(a+n*2)*e,l=(r+n*2)*e,o=this._style.align??"center",u=o==="left"?n:o==="right"?n+a:n+a/2,f=d=>Fi(d,this._text,i,e,n,n+r/2),p=this._frame;let g=null;return p&&t.atlas.valid(p)&&p.scale===e&&(g=t.atlas.rebake(p,h,l,f,this.capW,this.capH),g?Object.assign(g,{ox:u,oy:n+r/2,margin:n}):t.atlas.release(p)),g||(this.capW=Math.ceil(h*1.25+16),this.capH=Math.ceil(l),g=t.atlas.bake(this.capW,this.capH,f,e,u,n+r/2,n),g.w=Math.ceil(h),g.h=Math.ceil(l)),this._frame=g,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,g}},H=(t,e=0)=>{const s=Number(t);return Number.isFinite(s)?s:e};function Fe(t){typeof t=="string"&&/^\s*[{[]/.test(t)&&(t=JSON.parse(t));const e={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},s=(i,n)=>{i==="info"?e.size=Math.abs(H(n.size)):i==="common"?(e.lineHeight=H(n.lineHeight),e.base=H(n.base)):i==="page"?e.pages[H(n.id)]=String(n.file??""):i==="char"?e.chars.push({id:H(n.id),x:H(n.x),y:H(n.y),width:H(n.width),height:H(n.height),xoffset:H(n.xoffset),yoffset:H(n.yoffset),xadvance:H(n.xadvance),page:H(n.page)}):e.kernings.push({first:H(n.first),second:H(n.second),amount:H(n.amount)})};if(typeof t=="object"){const i=t;s("info",i.info??{}),s("common",i.common??{});for(const[n,r]of(i.pages??[]).entries())s("page",{id:n,file:r});for(const n of i.chars??[])s("char",n);for(const n of i.kernings??[])s("kerning",n)}else{const i=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,n=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let r=i.exec(t);r;r=i.exec(t)){const a={};for(let h=n.exec(r[2]);h;h=n.exec(r[2]))a[h[1]]=h[2]??h[3];s(r[1],a)}}return e.size||(e.size=e.lineHeight),e}var bs=class{constructor(t,e,s,i=null,n=null){c(this,"baker",i),c(this,"host",n),c(this,"size"),c(this,"lineHeight"),c(this,"base"),c(this,"ascii",new Array(128)),c(this,"more",new Map),c(this,"kern",new Map),c(this,"bScale",0),c(this,"bFontGen",-1),c(this,"bEffects",!1),c(this,"bGen",-1),this.size=t,this.lineHeight=e,this.base=s}set(t,e){t<128?this.ascii[t]=e:this.more.set(t,e)}setKerning(t,e,s){this.kern.set(t*1114112+e,s)}prepare(){const t=this.host;if(!(!t||t.pixelScale===this.bScale&&t.fontGen===this.bFontGen&&t.effects===this.bEffects&&t.atlas.gen===this.bGen)){this.bScale=t.pixelScale,this.bFontGen=t.fontGen,this.bEffects=t.effects,this.bGen=t.atlas.gen;for(const e of this.ascii)e&&t.atlas.release(e.frame);for(const e of this.more.values())e&&t.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(t){let e=t<128?this.ascii[t]:this.more.get(t);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(t):null,this.set(t,e)),e}kerning(t,e){return this.kern.size?this.kern.get(t*1114112+e)??0:0}measure(t){return this.run(t)}run(t,e,s,i=0,n=0,r=1,a=1,h=0,l=1,o="normal"){this.prepare();let u=0,f=-1;for(let p=0;p<t.length;p++){let g=t.charCodeAt(p);g>=55296&&g<56320&&p+1<t.length&&(g=t.codePointAt(p),p++),f>=0&&(u+=this.kerning(f,g)),f=g;const d=this.glyph(g);d&&(e&&d.w>0&&d.h>0&&(me(s,i+(u+d.x)*r,n+d.y*a),e.r.quad(e.tex(d.frame.surface),d.frame,q,d.w*r,d.h*a,h,l,o)),u+=d.advance)}return u}};function Ar(t,e){const s=new bs(t.size,t.lineHeight,t.base);for(const i of t.chars){const n=e[i.page];if(!n)continue;const r={surface:n,x:i.x,y:i.y,w:i.width,h:i.height,scale:1,gen:0,ox:0,oy:0,margin:0};s.set(i.id,{frame:r,x:i.xoffset,y:i.yoffset,w:i.width,h:i.height,advance:i.xadvance})}for(const i of t.kernings)s.setKerning(i.first,i.second,i.amount);return s}function _r(t,e){const s={...e},i=e.size??40,n=a=>{const h=String.fromCodePoint(a),l=t.pixelScale,o=Ti(s,t.effects),u=Ri(h,o,l),f=t.atlas.bake((u+o.pad*2)*l,(o.th+o.pad*2)*l,p=>Fi(p,h,o,l,o.pad,o.pad+o.th/2),l);return{frame:f,x:-o.pad,y:-o.pad,w:f.w/l,h:f.h/l,advance:u}},r=new bs(i,i*1.25,i,n,t);r.prepare();for(const a of e.chars??"0123456789")r.glyph(a.codePointAt(0));return r}var Er=.5;function Ci(t){const e=[];for(const[s,i]of[["left",zs.leftWrist],["right",zs.rightWrist]]){const n=t[i*3],r=t[i*3+1],a=t[i*3+2];n!==void 0&&r!==void 0&&Number.isFinite(n)&&Number.isFinite(r)&&(a??0)>=Er&&e.push({side:s,x:n,y:r})}return e}var Ms=t=>ue[((t-1)%ue.length+ue.length)%ue.length];function Pi(t,e,s,i,n=()=>null){const r=[];for(const a of t){const h=n(a)??a.body;if(Array.isArray(h))for(const l of Ci(h)){const o=e(l);r.push({player:a.id,side:l.side,x:o.x*s,y:o.y*i,color:Ms(a.id)})}}return r}function ks(t,e,s,i=0){const n=t.world,r=Nn(n,e,s);if(!r)return!1;const a=Math.hypot(n[0],n[1])||1,h=Math.hypot(n[2],n[3])||1,[l,o]=r;if(t.hitRadius!=null){const d=t.hitRadius+i/((a+h)/2);return l*l+o*o<=d*d}const u=-t.anchorX*t.width-i/a,f=-t.anchorY*t.height-i/h,p=(1-t.anchorX)*t.width+i/a,g=(1-t.anchorY)*t.height+i/h;return l>=u&&l<=p&&o>=f&&o<=g}function Ni(t,e,s,i=0){for(const n of e)if((s===void 0||n.player===s)&&ks(t,n.x,n.y,i))return n;return null}function Tr(t){switch(t.type){case"circle":case"ring":case"star":return[t.r*2,t.r*2];case"ellipse":return[t.rx*2,t.ry*2];case"roundRect":return[t.w,t.h];case"line":return[t.length,t.lw??4];case"path":return t.r?[t.r*2,t.r*2]:[t.size,t.size]}}function Sr(t){const e=t.type==="line"?0:t.stroke?(t.lw??2)/2:0,s=t.shadow?t.shadow.blur*1.5+Math.max(Math.abs(t.shadow.x??0),Math.abs(t.shadow.y??0)):0;return Math.ceil(e+s+1)}var Fr=(t,e)=>e||!t.shadow?t:{...t,shadow:void 0};function Li(t,e,s){const i=Sr(e),n=e.type==="roundRect",[r,a]=n?[Math.min(e.w,e.r*2+4/s),Math.min(e.h,e.r*2+4/s)]:Tr(e),h=(r+i*2)*s,l=(a+i*2)*s;return{frame:t.bake(h,l,u=>{u.scale(s,s),u.translate(i+r/2,i+a/2),Rr(u,e,r,a)},s,i+r/2,i+a/2,i),slice:n?Math.ceil((e.r+i)*s):0,w:n?e.w:r,h:n?e.h:a}}function Rr(t,e,s,i){t.lineJoin="round",t.lineCap="round";const n=new Path2D;switch(e.type){case"circle":case"ring":n.arc(0,0,e.r,0,Math.PI*2);break;case"ellipse":n.ellipse(0,0,e.rx,e.ry,0,0,Math.PI*2);break;case"roundRect":n.roundRect(-s/2,-i/2,s,i,Math.min(e.r,s/2,i/2));break;case"star":{const o=e.points??5,u=e.r*(e.inner??.5);for(let f=0;f<o*2;f++){const p=f%2?u:e.r,g=-Math.PI/2+f*Math.PI/o;f?n.lineTo(Math.cos(g)*p,Math.sin(g)*p):n.moveTo(Math.cos(g)*p,Math.sin(g)*p)}n.closePath();break}case"line":n.moveTo(-s/2+i/2,0),n.lineTo(s/2-i/2,0);break;case"path":{const o=e.r?e.r*2/e.size:1,u=new DOMMatrix([o,0,0,o,-e.size/2*o,-e.size/2*o]);n.addPath(new Path2D(e.d),u);break}}const r=e.shadow,a=()=>{if(!r)return;const o=t.getTransform();t.shadowColor=r.color,t.shadowBlur=r.blur*o.a,t.shadowOffsetX=(r.x??0)*o.a,t.shadowOffsetY=(r.y??0)*o.a},h=()=>{t.shadowColor="transparent",t.shadowBlur=0};if(e.type==="line"){a(),t.strokeStyle=e.stroke??e.fill??"#fff",t.lineWidth=i,t.stroke(n);return}const l=e.type==="ring";if(e.outlineBelow&&e.fill&&e.stroke&&!l){a(),t.strokeStyle=e.stroke,t.lineWidth=e.lw??2,t.stroke(n),h(),t.fillStyle=e.fill,t.fill(n);return}e.fill&&!l&&(a(),t.fillStyle=e.fill,t.fill(n),h()),(e.stroke||l)&&((!e.fill||l)&&a(),l&&e.fill&&(t.fillStyle=e.fill,t.fill(n)),t.strokeStyle=e.stroke??"#fff",t.lineWidth=e.lw??2,t.stroke(n),h())}var Ii=class{constructor(){if(c(this,"ctx",null),c(this,"master",null),c(this,"buffers",new Map),c(this,"held",!1),c(this,"muted",!1),c(this,"volume",1),typeof addEventListener=="function"){const t=()=>{this.context()?.resume().catch(()=>{})};for(const e of["pointerdown","keydown","touchstart"])addEventListener(e,t,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;const t=globalThis.AudioContext??globalThis.webkitAudioContext;if(!t)return null;try{this.ctx=new t,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch{return null}return this.ctx}async load(t,e){const s=this.context();if(!s)return;const i=await(await fetch(e)).arrayBuffer();this.buffers.set(t,await s.decodeAudioData(i))}has(t){return this.buffers.has(t)}play(t,e={}){const s=this.context(),i=this.buffers.get(t);if(!s||!i||!this.audible)return()=>{};const n=s.createBufferSource();n.buffer=i,n.loop=e.loop??!1,n.playbackRate.value=e.rate??1;const r=s.createGain();return r.gain.value=(e.volume??1)*this.volume,n.connect(r).connect(this.master),n.start(),()=>{try{n.stop()}catch{}}}tone(t,e=.25,s={}){const i=this.context();if(!(!i||!this.audible))try{const n=i.createOscillator(),r=i.createGain();n.type=s.type??"sine",n.frequency.setValueAtTime(t,i.currentTime),s.to&&n.frequency.exponentialRampToValueAtTime(s.to,i.currentTime+e),r.gain.setValueAtTime((s.volume??.12)*this.volume,i.currentTime),r.gain.exponentialRampToValueAtTime(.001,i.currentTime+e),n.connect(r).connect(this.master),n.start(),n.stop(i.currentTime+e)}catch{}}get audible(){return!this.muted&&!this.held}hold(){this.held=!0,this.ctx?.suspend().catch(()=>{})}release(){this.held=!1,this.ctx?.resume().catch(()=>{})}destroy(){this.ctx?.close().catch(()=>{}),this.ctx=null}},Cr={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}},ut=["high","medium","low"];function Ft(t){const e=Cr[t];return{name:t,...e,scale:s=>s<=0?0:Math.max(1,Math.round(s*e.particles))}}var Pr=t=>ut[Math.min(ut.indexOf(t)+1,ut.length-1)],Re=(t,e)=>{if(!t.length)return NaN;const s=[...t].sort((i,n)=>i-n);return s[Math.min(s.length-1,Math.max(0,Math.floor(e*(s.length-1)+.5)))]},Nr=12,Lr=t=>Ce(t,.5);function Ce(t,e=.1){const s=Re(t,e);if(!Number.isFinite(s))return 1e3/60;const i=[144,120,90,75,60,50,30];let n=60;for(const r of i)Math.abs(1e3/r-s)<Math.abs(1e3/n-s)&&(n=r);return 1e3/n}function Oi(t,e){const s=e.refresh!==void 0&&Number.isFinite(e.refresh)&&e.refresh>0?e.refresh:Ce(e.intervals),i=Re(e.intervals,.5),n=Re(e.intervals,.9),r=Re(e.cpu,.5);if(!Number.isFinite(i))return t==="canvas2d"?"low":"medium";const a=l=>l<=s*1.25,h=l=>!Number.isFinite(r)||r<s*l;return t==="canvas2d"?a(n)&&h(.25)?"medium":"low":a(n)&&h(.5)?"high":a(i)?"medium":"low"}function Ir(t,e){return t.length<30?!1:t.filter(i=>i>e*1.5).length/t.length>.5}var Ui="0.1.1",Or=720*3600*1e3,Ur=(t,e,s)=>`fabi-play.engine-tier:${Ui}:${t}:${e}:${s}`,Dr=(t,e,s)=>`fablee-engine-tier:${Ui}:${t}:${e}:${s}`;function Br(t,e,s=Date.now()){try{const i=JSON.parse(t?.getItem(e)??"null");if(i&&ut.includes(i.tier)&&typeof i.at=="number"&&s-i.at<Or)return typeof i.refresh=="number"&&i.refresh>0?{name:i.tier,refresh:i.refresh}:{name:i.tier}}catch{}return null}function Di(t,e,s,i,n=Date.now()){try{t?.setItem(e,JSON.stringify(i!==void 0&&Number.isFinite(i)?{tier:s,at:n,refresh:i}:{tier:s,at:n}))}catch{}}function zr(t=typeof location<"u"?location.search:""){const e=new URLSearchParams(t).get("tier");return ut.includes(e)?e:void 0}function Bi(t,e){const s=e?.tier;if(ut.includes(s))return t==="canvas2d"&&s==="high"?"medium":s}var zi=t=>typeof t?.hz=="number"&&t.hz>=20&&t.hz<=240?Ce([1e3/t.hz],.5):NaN,Gi=(t,e)=>ut.indexOf(t)>=ut.indexOf(e)?t:e;function Gr(t,e,s){return t?{name:t,from:"forced"}:e?{name:s?Gi(e,s):e,from:"hint"}:s?{name:s,from:"cache"}:null}var Xr=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,Xi=class{constructor(t={}){c(this,"steps",[]),c(this,"labels",new Map),c(this,"end",0),c(this,"prevStart",0),c(this,"elapsed",0),c(this,"iter",0),c(this,"last",0),c(this,"delayLeft"),c(this,"_paused"),c(this,"done",!1),c(this,"rewinding",!1),c(this,"promise"),c(this,"resolve"),c(this,"repeat"),c(this,"yoyo"),c(this,"onComplete"),this.repeat=Math.floor(t.repeat??0),this.yoyo=!!t.yoyo,this.delayLeft=t.delay??0,this._paused=!!t.paused,this.onComplete=t.onComplete,this.promise=new Promise(e=>this.resolve=e)}get duration(){return this.end}get time(){return this.last}get paused(){return this._paused}get finished(){return this.done}at(t){if(t===void 0)return this.end;if(typeof t=="number")return Math.max(t,0);const e=Xr.exec(t);if(!e)throw new Error(`[engine] timeline: bad position "${t}"`);const[,s,i,n]=e,r=n?(i==="-"?-1:1)*Number(n):0;let a=this.end;if(s==="<")a=this.prevStart;else if(s&&s!==">"){const h=this.labels.get(s.trim());h===void 0?this.labels.set(s.trim(),this.end):a=h}return Math.max(a+r,0)}add(t){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>t.start;)e--;return this.steps.splice(e,0,t),this.prevStart=t.start,this.end=Math.max(this.end,t.start+t.dur),this}to(t,e,s,i="quadOut"){const n=typeof i=="object"?i:{ease:i},r=typeof n.ease=="function"?n.ease:jt[n.ease??"quadOut"];return this.add({target:t,to:e,from:null,fn:null,start:this.at(n.at)+(n.delay??0),dur:Math.max(s,0),ease:r,onUpdate:n.onUpdate,p:-1})}set(t,e,s){return this.add({target:t,to:e,from:null,fn:null,start:this.at(s),dur:0,ease:jt.linear,p:-1})}call(t,e){return this.add({target:null,to:null,from:null,fn:t,start:this.at(e),dur:0,ease:jt.linear,p:-1})}label(t,e){return this.labels.set(t,this.at(e)),this}wait(t){return this.end+=Math.max(t,0),this.prevStart=this.end,this}pause(){return this._paused=!0,this}resume(){return this._paused=!1,this}stop(){this.done||(this.done=!0,this.resolve())}seek(t){const e=Math.min(typeof t=="string"&&this.labels.has(t)?this.labels.get(t):this.at(t),this.end),s=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(s?this.end-e:e),this.render(e),this}then(t,e){return this.promise.then(t,e)}update(t){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=t,this.delayLeft>0)return;t=-this.delayLeft,this.delayLeft=0}const e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=t;const s=this.repeat<0?1/0:e*(this.repeat+1),i=Math.min(this.elapsed,s),n=i>=s?this.repeat:Math.floor(i/e);for(;this.iter<n;){const a=this.yoyo&&this.iter%2===1;this.render(a?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}const r=i-n*e;this.render(this.yoyo&&n%2===1?e-r:r),i>=s&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(t){const e=this.steps;if(t>=this.last)for(let s=0;s<e.length;s++){const i=e[s];t>=i.start&&this.apply(i,t)}else for(let s=e.length-1;s>=0;s--){const i=e[s];i.p>=0&&this.apply(i,t)}this.last=t}apply(t,e){const s=t.dur>0?Math.min(Math.max((e-t.start)/t.dur,0),1):e>t.start||e===t.start&&!this.rewinding?1:0;if(s===t.p)return;if(t.p=s,t.fn){this.rewinding||t.fn();return}const i=t.target;if(i.destroyed||i._free)return;const n=t.to;if(!t.from){t.from={};for(const a in n)t.from[a]=Number(i[a]??0)}const r=t.ease(s);for(const a in n)i[a]=t.from[a]+(n[a]-t.from[a])*r;t.onUpdate?.(r)}},$i=class{constructor(){c(this,"list",[]),c(this,"timelines",[])}timeline(t){const e=new Xi(t);return this.timelines.push(e),e}tween(t,e,s,i="quadOut"){const n=typeof i=="object"?i:{ease:i},r=typeof n.ease=="function"?n.ease:jt[n.ease??"quadOut"];let a;const h=new Promise(l=>{const o=Object.keys(e),u=new Float64Array(o.length);o.forEach((f,p)=>u[p]=Number(e[f])),a={target:t,keys:o,to:u,from:new Float64Array(o.length),started:!1,duration:Math.max(s,0),time:0,delay:n.delay??0,ease:r,onUpdate:n.onUpdate,done:l,dead:!1}});return this.list.push(a),Object.assign(h,{stop:()=>this.finish(a)})}stopAll(t){const e=this.list;for(let s=0;s<e.length;s++)e[s].target===t&&this.finish(e[s])}get size(){return this.list.length}update(t){if(this.timelines.length){let i=0;const n=this.timelines;for(let r=0;r<n.length;r++){const a=n[r];a.update(t),a.finished||(n[i++]=a)}n.length=i}const e=this.list;if(!e.length)return;let s=0;for(let i=0;i<e.length;i++){const n=e[i];n.dead||this.step(n,t),n.dead||(e[s++]=n)}s!==e.length&&(e.length=s)}step(t,e){if(t.target.destroyed)return this.finish(t);let s=e;if(t.delay>0){if(t.delay-=e,t.delay>0)return;s=-t.delay}const i=t.keys;if(!t.started){t.started=!0;for(let a=0;a<i.length;a++)t.from[a]=Number(t.target[i[a]]??0)}t.time+=s;const n=t.duration>0?Math.min(t.time/t.duration,1):1,r=t.ease(n);for(let a=0;a<i.length;a++)t.target[i[a]]=t.from[a]+(t.to[a]-t.from[a])*r;t.onUpdate?.(r),n>=1&&this.finish(t)}finish(t){t.dead||(t.dead=!0,t.done())}clear(){for(const t of this.list)this.finish(t);this.list.length=0;for(const t of this.timelines)t.stop();this.timelines=[]}},Y=720,qi=class extends Et{constructor(t,e){super(t),c(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},$r=class extends Et{constructor(t,e){super(t),c(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},bt=()=>performance.now();async function qr(t={}){const e=t.play??null;let s=t.canvas??null;s||(s=document.createElement("canvas"),s.style.cssText="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(s));let i=ms(s,{renderer:t.renderer??vr(),failIfMajorPerformanceCaveat:t.failIfMajorPerformanceCaveat,instancing:t.instancing});s=i.canvas;const n=new Set,r=new as(Math.min(2048,i.maxTextureSize),4);r.onPage=v=>n.add(v),r.onDrop=v=>{n.delete(v),v.texture&&i.destroyTexture(v.texture),v.texture=null};let a=Te(i);const h=new $i,l=new Ii,o=new xs(r),u=new Map,f=new Map,p=new Map,g=new Map,d=new Map,y=new Set;let m=0;const w=t.tier??zr(),x=String(i.info.renderer??""),_=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),M=typeof screen<"u"?`${screen.width}x${screen.height}`:"",k=Ur(i.kind,x,M);Fn(_,k,Dr(i.kind,x,M));const F=Br(_,k),R=Gr(w,Bi(i.kind,e?.device),F?.name);let N=R?.name??"medium",I=Ft(N);o.setTier(N);let D=R?.from==="hint",W=F?.name,X=F?.refresh??zi(e?.device),z=1,$t=1,ne=1;const Q={atlas:r,get pixelScale(){return z},get fontGen(){return m},get effects(){return I.effects},tweens:h,frame:v=>$e.frame(v),shape:v=>{const b=I.effects,T=b?z:-z;let E=u.get(T);E||(u.size>=8&&u.clear(),u.set(T,E=new hi(2e3)));const C=yt(v);let G=E.get(v,C);return(!G||!r.valid(G.frame))&&E.set(v,G=Li(r,Fr(v,b),z),C),G},bitmapFont:v=>$e.bitmapFont(v)};let rt=1280,kt=null;class Oa extends ns{get width(){return rt}set width(b){}get height(){return Y}set height(b){}get safe(){const b=Math.min(rt,Y*16/9);return{x:(rt-b)/2,y:0,w:b,h:Y}}}const at=new Oa(Q),At=()=>{const v=i.canvas,b=v.getBoundingClientRect();$t=Math.max(1,b.width||v.clientWidth||innerWidth),ne=Math.max(1,b.height||v.clientHeight||innerHeight),rt=Y*$t/ne;const T=Math.min(globalThis.devicePixelRatio||1,t.maxPixelRatio??2);if(ne*T/Y<=I.resolution){const C=Math.max(1,Math.round(ne*T));z=C/Y,i.resize(Math.max(1,Math.round($t*T)),C)}else z=I.resolution,i.resize(Math.round(rt*z),Math.round(Y*z));kt&&kt.style.setProperty("--unit",`${ne/Y}px`)};addEventListener("resize",At);const Ts=v=>{N=v,I=Ft(v),o.setTier(v),At()},Ie=typeof ResizeObserver<"u"?new ResizeObserver(At):null;Ie?.observe(s);let pt=e?.backdrop==="video"?"video":"none",$=e?.view??null,Ji=[],tn=-1/0,Oe=!1,re=!1;const Ss=new Set,en=()=>{const v=pt==="video"?"transparent":"";document.documentElement.style.background=v,document.body.style.background=v},sn=(v,b)=>{const T=v==="video"?"video":"none",E=b??null;if(!(T===pt&&(E===$||E&&$&&E.x===$.x&&E.y===$.y&&E.w===$.w&&E.h===$.h))){pt=T,$=E,en();for(const C of[...Ss])C(pt,$)}},nn=[];if(e){const v=E=>{Array.isArray(E)&&(Ji=E,tn=bt())},b=E=>{Oe=E,Ue()},T=E=>{if(w||D)return;Number.isFinite(X)||(X=zi(E));const C=Bi(i.kind,E);C&&(D=!0,Ts(W?Gi(C,W):C))};nn.push(e.on("start",E=>T(E?.device)),e.on("frame",E=>v(E?.players)),e.on("players",E=>v(E?.players)),e.on("backdrop",E=>sn(E?.backdrop,E?.view)),e.on("start",E=>sn(E?.backdrop,E?.view??e.view)),e.on("pause",()=>b(!0)),e.on("resume",()=>b(!1)),e.on("break-start",()=>b(!0)),e.on("break-done",()=>b(!1)),e.on("break-end",()=>b(!1))),l.muted=e.muted===!0}en();const Ue=()=>Oe||re||document.hidden?l.hold():l.release();let rn=-1,Fs=[],Rs=0;const Cs=()=>bt()-tn<1e3?Ji:[],Ua=v=>e?e.toScreen(v):An($,v),De=()=>{if(rn===Rs)return Fs;rn=Rs;const v=pt==="video"||!e?.smoothedBody?()=>null:b=>e.smoothedBody(b);return Fs=Pi(Cs(),Ua,rt,Y,v),Fs},ae={x:0,y:0,w:1,h:1},Da=()=>(ae.x=$?$.x*rt:0,ae.y=$?$.y*Y:0,ae.w=$?$.w*rt:rt,ae.h=$?$.h*Y:Y,ae),Ba=v=>{const b=v.alpha??1,T=v.tags?new vs(r,v):null;T&&y.add(T);const E=typeof v.tags=="function"?v.tags:C=>String(C);return(C,G)=>{if(pt==="video")return;const L=Da();for(const O of Cs()){const j=e?.smoothedBody?.(O)??O.body,B=de(e?.avatarOf?.(O)??O.avatar??"")??pe;if(!o.draw(C.r,C.tex,j,B,L,b*G,z)||!T)continue;const st=E(O.id);st&&T.draw(C.r,C.tex,j,B,L,st,Ms(O.id),b*G,z,rt,Y)}}},Ps=new Set,Ns=new Set,oe=new Set;let Be=!1,Ls=0,qt=0,ze=0;const Rt={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0};let Ge=0,Is=0,Os=bt();const he=[];let Xe=0;const an=()=>({r:i,kernel:Q,tex:a});let on=an();const za=()=>{if(i.lost)return;const[v,b]=pt==="video"||t.background===void 0?[0,0]:ot(t.background);i.time=ze,i.maxBlur=I.maxBlur,i.begin(v,b,z),ct(at.world,null,at.x,at.y,at.rotation,at.scaleX,at.scaleY),Ks(on,at,at.alpha,at.tint);const T=i.end();Rt.drawCalls=T.drawCalls,Rt.quads=T.quads,Rt.filtersSkipped=T.filtersSkipped},hn=v=>{if(!Be)return;Ls=requestAnimationFrame(hn);const b=Math.min(Math.max((v-qt)/1e3,0),.1);qt&&he.push(v-qt),qt=v,Rs++;const T=bt(),E=Oe||re;if(!E){ze+=b,h.update(b);for(const C of oe)C.destroyed||C.update(b);for(const C of Ps)C(b,ze)}for(const C of Ns)C(b);at.sweep();for(const C of oe)C.destroyed&&oe.delete(C);if(i.lost?(Xe||(Xe=v),v-Xe>3e3&&Ga()):(Xe=0,za()),Ge++,Is+=bt()-T,T-Os>=1e3&&(Rt.fps=Math.round(Ge*1e3/(T-Os)),Rt.cpuMs=Math.round(Is/Math.max(Ge,1)*100)/100,e?.reportStats?.({fps:Rt.fps,renderer:i.kind,tier:N}),Ge=0,Is=0,Os=T),he.length>=180){const C=Number.isFinite(X)?X:Ce(he);!w&&!E&&Ir(he,C)&&N!=="low"&&(Ts(Pr(N)),W=N,Di(_,k,N,Number.isFinite(X)?X:void 0),console.info(`[engine] slow frames: tier ${N}`)),he.length=0}},Ga=()=>{const v=ys(i.canvas),b=ls(v);if(b){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),i.destroy(),i=b;for(const T of n)T.texture=null;for(const T of r.pages)n.add(T.surface);a=Te(i),on=an(),Ie?.disconnect(),Ie?.observe(v),At()}},ln=()=>{Ue(),document.hidden||(qt=0)};document.addEventListener("visibilitychange",ln);const cn=()=>{m++;for(const v of y)v.drop()};if(document.fonts?.addEventListener?.("loadingdone",cn),At(),!R&&t.probe!==!1&&(Number.isFinite(X)||(X=Lr(await Hr(Nr))),!D)){I=Ft("high"),At();const v=await Wr(i,r,()=>a,()=>z,rt,()=>D);if(v.refresh=X,!D){const b=Oi(i.kind,v);Di(_,k,b,X),W=b,Ts(b)}}const $e={stage:at,get tier(){return I},get renderer(){return i},get canvas(){return i.canvas},get pixelScale(){return z},get backdrop(){return pt},get view(){return $},get paused(){return Oe||re},sound:l,stats:Rt,get time(){return ze},get supports(){const v=i.support;return{filters:v.filters,blur:v.filters&&I.maxBlur>0,shaders:v.shaders,maxBlur:v.filters?I.maxBlur:0,tiers:{high:{maxBlur:Ft("high").maxBlur},medium:{maxBlur:Ft("medium").maxBlur},low:{maxBlur:Ft("low").maxBlur}}}},sprite:(v,b)=>new It(Q,v,b),shape:(v,b)=>new Zt(Q,v,b),text:(v,b)=>new se(Q,v,b),group:v=>new ns(Q).set(v??{}),particles(v,b={}){const T=typeof v=="object"&&"type"in v?Q.shape(v).frame:v,E=new si(Q,T,b),{max:C,blend:G,gravity:L,drag:O,...j}=b;return E.set(j),oe.add(E),E},tween:(v,b,T,E)=>h.tween(v,b,T,E),bake(v,b,T,E,C){return p.set(v,{w:b,h:T,draw:E,origin:C}),f.delete(v),$e.frame(v)},frame(v){const b=f.get(v);if(b&&r.valid(b)&&(b.gen===0||b.scale===z))return b;const T=p.get(v);if(T){const E=z,C=r.bake(T.w*E,T.h*E,G=>(G.scale(E,E),T.draw(G)),E,T.origin?.x??0,T.origin?.y??0);return f.set(v,C),C}if(b)return b;throw new Error(`[engine] no frame "${v}": load it or bake it first`)},async load(v){await Promise.all(Object.entries(v).map(([b,T])=>$a(b,T)))},hands:v=>v===void 0?De():De().filter(b=>b.player===v),touched(v,b,T={}){return v.updateWorld(),Ni(v,De(),b,T.padding??0)},hits(v,b,T,E=0){return v.updateWorld(),ks(v,b,T,E)},avatars:(v={})=>new qi(Q,Ba(v)),handMarkers(v={}){const b=v.radius??36,T=v.look??"auto",E=new Float64Array(6),C=Math.max(b*.12,3),G={type:"ring",r:b,lw:C,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},L={type:"ring",r:b,lw:C*1.8,stroke:ee,shadow:{color:ee,blur:b*.2}},O=(Ct,tt,Ht,Us,qe,Pt)=>{const He=tt.w/tt.scale;ct(E,null,Ht-He/2,Us-He/2,0,1,1),Ct.r.quad(Ct.tex(tt.surface),tt,E,He,He,qe,Pt,"normal")},j=Ct=>{let tt=null,Ht=!1;return()=>(tt&&r.valid(tt.frame)&&tt.frame.scale===z&&Ht===I.effects?tt:(Ht=I.effects,tt=Q.shape(Ct))).frame},B=j(G),st=j(L);return new $r(Q,(Ct,tt)=>{const Ht=T==="video"||T==="auto"&&pt==="video",Us=B(),qe=Ht?st():null;for(const Pt of De())qe&&O(Ct,qe,Pt.x,Pt.y,16777215,tt),O(Ct,Us,Pt.x,Pt.y,ot(Pt.color)[0],tt)})},timeline:v=>h.timeline(v),animation(v,b){const T=typeof v=="string"?Xa(v):{frames:v},E=new St(Q,T,b);return oe.add(E),E},bitmapFont(v,b){if(!b){const E=g.get(v);if(!E)throw new Error(`[engine] no bitmap font "${v}": load or make it first`);return E}const T="data"in b?fn(Fe(b.data),b.pages):_r(Q,b);return g.set(v,T),T},players:()=>Cs(),onFrame(v){return Ps.add(v),()=>{Ps.delete(v)}},onRender(v){return Ns.add(v),()=>{Ns.delete(v)}},onBackdrop(v){return Ss.add(v),()=>{Ss.delete(v)}},get hud(){return kt||(kt=document.createElement("div"),kt.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(kt),At()),kt},random:(v=0,b=1)=>v+Math.random()*(b-v),start(){Be||(Be=!0,qt=0,Ls=requestAnimationFrame(hn))},pause(){re=!0,Ue()},resume(){re=!1,Ue()},destroy(){Be=!1,cancelAnimationFrame(Ls),nn.forEach(v=>v()),removeEventListener("resize",At),Ie?.disconnect(),document.removeEventListener("visibilitychange",ln),document.fonts?.removeEventListener?.("loadingdone",cn),h.clear(),Hn(Q),l.destroy(),i.destroy(),kt?.remove()}};function Xa(v){const b=d.get(v);if(b)return b;const T=[...new Set([...f.keys(),...p.keys()])].filter(E=>E.startsWith(v)).sort(Yn);if(!T.length)throw new Error(`[engine] no animation or frames "${v}\u2026"`);return{frames:T}}async function $a(v,b){const T=b.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(T))return l.load(v,b);if(["woff","woff2","ttf","otf"].includes(T)){const L=new FontFace(v,`url(${b})`);document.fonts.add(await L.load()),m++;return}const E=new URL(b,location.href);if(T==="fnt")return un(v,Fe(await(await fetch(b)).text()),E);if(T==="json"){const L=await(await fetch(b)).json();if(Array.isArray(L.chars)&&!L.frames)return un(v,Fe(L),E);const O=await As(new URL(L.meta?.image??b.replace(/\.json$/,".png"),E).href);qa(v,L,ye(O));return}const C=await As(b),G=ye(C);n.add(G),f.set(v,{surface:G,x:0,y:0,w:C.width,h:C.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function fn(v,b){return Ar(v,b.map(T=>{const E=ye(T);return n.add(E),E}))}async function un(v,b,T){g.set(v,fn(b,await Promise.all(b.pages.map(E=>As(new URL(E,T).href)))))}function qa(v,b,T){n.add(T);const E=Array.isArray(b.frames)?b.frames:Object.entries(b.frames).map(([L,O])=>({...O,filename:L})),C=[],G=[];for(const L of E){const O=L.frame,j=L.filename.replace(Hi,"");L.rotated&&console.warn(`[engine] ${v}/${j} is rotated: export without rotation`);const B={surface:T,x:O.x,y:O.y,w:O.w,h:O.h,scale:1,gen:0,ox:0,oy:0,margin:0};L.trimmed&&L.sourceSize&&L.spriteSourceSize&&(B.sw=L.sourceSize.w,B.sh=L.sourceSize.h,B.tx=L.spriteSourceSize.x,B.ty=L.spriteSourceSize.y);const st=L.scale9Borders;st&&(B.slice=[st.y,(B.sw??O.w)-st.x-st.w,(B.sh??O.h)-st.y-st.h,st.x]),f.set(`${v}/${j}`,B),C.push(`${v}/${j}`),G.push((L.duration??0)/1e3)}for(const[L,O]of Object.entries(b.animations??{}))d.set(`${v}/${L}`,{frames:O.map(j=>`${v}/${j.replace(Hi,"")}`)});for(const L of b.meta?.frameTags??[]){const O=[];for(let B=L.from;B<=L.to;B++)O.push(B);L.direction==="reverse"&&O.reverse(),L.direction==="pingpong"&&O.push(...O.slice(1,-1).reverse());const j=O.every(B=>G[B]>0);d.set(`${v}/${L.name}`,{frames:O.map(B=>C[B]),...j?{durations:O.map(B=>G[B])}:{}})}}return $e}var Hi=/\.(png|webp|jpe?g|gif|bmp)$/i;function As(t){return new Promise((e,s)=>{const i=new Image;i.onload=()=>e(i),i.onerror=()=>s(new Error(`[engine] image did not load: ${t}`)),i.src=t})}function Hr(t){return new Promise(e=>{const s=[];let i=0;const n=r=>{i&&s.push(r-i),i=r,s.length<t?requestAnimationFrame(n):e(s)};requestAnimationFrame(n)})}async function Wr(t,e,s,i,n,r=()=>!1){const a=i(),h=Li(e,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},a).frame,l=[],o=[],u=new Float64Array(6),f=.004,p=t.kind==="canvas2d"?t.canvas.getContext("2d"):null,g=bt();let d=0;return await new Promise(y=>{const m=w=>{d&&w-g>250&&l.push(w-d),d=w;const x=bt();t.begin(0,0,a);const _=s();for(let M=0;M<300;M++){const k=w/1e3+M;ct(u,null,M*37%n,M*53%Y,k,1,1),t.quad(_(h.surface),h,u,h.w/a,h.h/a,16777215,f,"normal")}for(let M=0;M<40;M++)t.ellipse(100+M*20,300,20,14,M,16746496,f),t.stroke([100+M*20,400,120+M*20,460,100+M*20,520],3,18,3368703,f,!1);t.end(),p?.getImageData(0,0,1,1),w-g>250&&o.push(bt()-x),w-g<750&&!r()?requestAnimationFrame(m):(t.begin(0,0,a),t.end(),y())};requestAnimationFrame(m)}),{intervals:l,cpu:o}}var Yr=64,Wi=32,jr=0,Vr=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,Yi=new Set,ji=(t,e)=>{Yi.has(t)||(Yi.add(t),console.warn(e))},Qr=t=>new Kr(t),Kr=class{constructor(t){c(this,"r",t),c(this,"css","none"),c(this,"plans",new hi(Yr)),c(this,"buf",new Float64Array(64)),c(this,"keys",[]),c(this,"classes",new Map),c(this,"live",new Set),c(this,"svgs",new Map),c(this,"t",0),c(this,"cur",null),c(this,"svgFn",e=>this.svg(e)),c(this,"scr",[]),c(this,"flip",0)}chain(t,e){var s;const i=this.r;let n=this.buf;n[0]=i.scale,n[1]=i.maxBlur;let r=2;for(let d=0;d<e.length;d++){const y=e[d];if(r+22>n.length){const w=new Float64Array(n.length*2);w.set(n),n=this.buf=w}let m=this.classes.get(y.constructor);m===void 0&&this.classes.set(y.constructor,m=this.classes.size),n[r++]=m,n[r++]=y.enabled?1:0,y.params&&(r=y.params(n,r))}const a=(s=this.keys)[r]??(s[r]=new Float64Array(r));for(let d=0;d<r;d++)a[d]=n[d];const h=yt(a);let l=this.plans.get(a,h);l||this.plans.set(a,l=this.plan(e),h);for(let d=0;d<l.svgs.length;d++){const y=l.svgs[d];y.used<0&&this.attach(y),y.used=this.t}i.skipped+=l.skip;let o=t;const u=i.rx0,f=i.ry0,p=i.rx1-u,g=i.ry1-f;for(let d=0;d<l.paints.length;d++)l.parts[d]&&(o=this.bake(o,l.parts[d])),e[l.paints[d]].paint2d(o.getContext("2d"),u,f,p,g);return this.css=l.parts[l.paints.length]||"none",o}tick(){const t=++this.t;if(!(t%Wi||!this.live.size))for(const e of this.live)t-e.used>Wi&&this.detach(e)}destroy(){for(const t of this.live)this.detach(t);this.plans.clear()}svg(t){if(typeof document>"u"||!document.body)return null;const e=Array.from({length:20},(i,n)=>t[n]??0).join(" ");let s=this.svgs.get(e);if(!s){const i="http://www.w3.org/2000/svg",n=document.createElementNS(i,"svg");n.setAttribute("width","0"),n.setAttribute("height","0"),n.setAttribute("aria-hidden","true"),n.style.position="absolute";const r=document.createElementNS(i,"filter"),a=Vr+ ++jr;r.setAttribute("id",a),r.setAttribute("color-interpolation-filters","sRGB");const h=document.createElementNS(i,"feColorMatrix");h.setAttribute("type","matrix"),h.setAttribute("values",e),r.append(h),n.append(r),this.attach(s={key:e,id:a,el:n,used:this.t})}return this.cur.svgs.push(s),`url(#${s.id})`}attach(t){document.body.append(t.el),this.live.add(t),this.svgs.has(t.key)||this.svgs.set(t.key,t)}detach(t){t.el.remove(),t.used=-1,this.live.delete(t),this.svgs.get(t.key)===t&&this.svgs.delete(t.key)}plan(t){const e=this.r,s=this.cur={parts:[],paints:[],skip:0,svgs:[]};let i="";for(let n=0;n<t.length;n++){const r=t[n];if(!r.enabled)continue;if(r.kind===Je){s.skip++,ji("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}const a=e.support.filters&&r.css?r.css(e.scale,e.maxBlur,this.svgFn):null;a!==null?i+=i?` ${a}`:a:r.paint2d?(s.parts.push(i),s.paints.push(n),i=""):(s.skip++,ji("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return s.parts.push(i),s}bake(t,e){const s=this.r,i=this.flip^=1;let n=this.scr[i];(!n||n.width!==s.canvas.width||n.height!==s.canvas.height)&&(n=this.scr[i]=document.createElement("canvas"),n.width=s.canvas.width,n.height=s.canvas.height);const r=n.getContext("2d"),a=s.rx0,h=s.ry0,l=s.rx1-a,o=s.ry1-h;return r.clearRect(a,h,l,o),r.filter=e,r.drawImage(t,a,h,l,o,a,h,l,o),r.filter="none",n}},Zr=64,Pe=17,Jr=t=>`${gs}
|
|
48
|
+
}`,dr={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},pr=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],gr=["aPos","aUv","aColor","aSlot"];function mr(t,e,s={}){const i={...dr,failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat!==!1},n=e===2?t.getContext("webgl2",i):t.getContext("webgl",i)??t.getContext("experimental-webgl",i);if(!n||n.isContextLost())return null;try{return new yr(t,n,e,s)}catch(r){return console.warn("[engine] WebGL setup failed:",r),n.getExtension("WEBGL_lose_context")?.loseContext(),null}}var yr=class extends ci{constructor(t,e,s,i){super(),c(this,"canvas",t),c(this,"gl",e),c(this,"opts",i),c(this,"kind"),c(this,"maxTextureSize"),c(this,"support",{filters:!0,shaders:!0}),c(this,"features",{}),c(this,"info",{}),c(this,"lost",!1),c(this,"main"),c(this,"cur"),c(this,"unit",-1),c(this,"onUnit",new Array(ki).fill(void 0)),c(this,"fbNow"),c(this,"mapped",!0),c(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0}),c(this,"vsrc",""),c(this,"attrs",[]),c(this,"fxr",null),c(this,"batch"),c(this,"dynamic"),c(this,"staticBuf",null),c(this,"index"),c(this,"vao",null),c(this,"inst",null),c(this,"vaoApi",null),c(this,"uScale",null),c(this,"textures",new Map),c(this,"kit"),c(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),c(this,"lostListeners",[]),c(this,"restoredListeners",[]),c(this,"tris",new Int32Array(192)),c(this,"sU",0),c(this,"sV0",0),c(this,"sV1",0),c(this,"sColor",0),c(this,"sPacked",0),c(this,"sAlpha",0),c(this,"sHw",0),c(this,"strokeSeg",()=>{const n=this.q;n.set(_e),n[8]=n[10]=this.sU,n[9]=this.sV0,n[11]=this.sV1,n[12]=this.sPacked,this.put(this.kit)}),c(this,"strokeDisc",()=>this.ellipse(_e[0],_e[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha)),c(this,"q",new Float64Array(13)),c(this,"layers",[]),c(this,"layerTex",new Map),c(this,"bScis",!1),c(this,"bx0",0),c(this,"by0",0),c(this,"bx1",0),c(this,"by1",0),c(this,"onContextLost",n=>{n.preventDefault(),this.lost=!0;for(const r of this.lostListeners)r()}),c(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(const n of this.textures.keys())this.textures.set(n,this.upload(n.source));this.lost=!1;for(const n of this.restoredListeners)n()}catch(n){console.warn("[engine] WebGL restore failed:",n)}}),c(this,"views",new Map),this.kind=s===2?"webgl2":"webgl1",this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(lr()),ht.live=this,t.addEventListener("webglcontextlost",this.onContextLost,!1),t.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){const t=this.gl,e=this.kind==="webgl2"?t:null;if(this.inst=null,this.opts.instancing!==!1)if(e)this.inst={divisor:(o,u)=>e.vertexAttribDivisor(o,u),draw:(o,u)=>e.drawElementsInstanced(t.TRIANGLES,o,t.UNSIGNED_SHORT,0,u)};else{const o=t.getExtension("ANGLE_instanced_arrays");o&&(this.inst={divisor:(u,f)=>o.vertexAttribDivisorANGLE(u,f),draw:(u,f)=>o.drawElementsInstancedANGLE(t.TRIANGLES,u,t.UNSIGNED_SHORT,0,f)})}if(this.vaoApi=null,this.opts.vao!==!1)if(e)this.vaoApi={create:()=>e.createVertexArray(),bind:o=>e.bindVertexArray(o),remove:o=>e.deleteVertexArray(o)};else{const o=t.getExtension("OES_vertex_array_object");o&&(this.vaoApi={create:()=>o.createVertexArrayOES(),bind:u=>o.bindVertexArrayOES(u),remove:u=>o.deleteVertexArrayOES(u)})}const s=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),i=Math.max(1,Math.min(ki,s)),n=this.inst!==null;this.vsrc=n?ur:fr,this.attrs=n?pr:gr,this.main=this.cur=this.build(cr(i));const r=this.main.p;t.useProgram(r),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,t.uniform1iv(t.getUniformLocation(r,"uTex"),Int32Array.from({length:i},(o,u)=>u)),this.batch=new Zn(n,i),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic),t.bufferData(t.ARRAY_BUFFER,this.batch.f32.byteLength,t.DYNAMIC_DRAW),this.index=t.createBuffer(),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.index),t.bufferData(t.ELEMENT_ARRAY_BUFFER,Jn(n?1:ui),t.STATIC_DRAW);const a=o=>t.getAttribLocation(r,o),h=(o,u,f,p,g,d,y)=>{const m=a(o);m<0||(t.enableVertexAttribArray(m),t.vertexAttribPointer(m,u,f,p,g,d),this.inst&&this.inst.divisor(m,y))};if(n){const o=te*4;h("aP01",4,t.FLOAT,!1,o,0,1),h("aP23",4,t.FLOAT,!1,o,16,1),h("aUvRect",4,t.FLOAT,!1,o,32,1),h("aColor",4,t.UNSIGNED_BYTE,!0,o,48,1),h("aSlot",1,t.FLOAT,!1,o,52,1),this.staticBuf=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.staticBuf),t.bufferData(t.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t.STATIC_DRAW),h("aCorner",4,t.FLOAT,!1,16,0,0),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic)}else{const o=zt*4;h("aPos",2,t.FLOAT,!1,o,0,0),h("aUv",2,t.FLOAT,!1,o,8,0),h("aColor",4,t.UNSIGNED_BYTE,!0,o,16,0),h("aSlot",1,t.FLOAT,!1,o,20,0)}t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.disable(t.DEPTH_TEST),t.disable(t.CULL_FACE),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);const l=t.getExtension("WEBGL_debug_renderer_info");this.info={version:t.getParameter(t.VERSION),renderer:l?t.getParameter(l.UNMASKED_RENDERER_WEBGL):t.getParameter(t.RENDERER),vendor:l?t.getParameter(l.UNMASKED_VENDOR_WEBGL):t.getParameter(t.VENDOR)},this.features={instancing:n,vao:this.vaoApi!==null,textureSlots:i,maxTextureSize:this.maxTextureSize}}upload(t){const e=this.gl,s=e.createTexture();return this.bindTex(s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),s}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){const e={id:ss(),width:t.width,height:t.height,source:t};return this.textures.set(e,this.lost?null:this.upload(t)),e}updateTexture(t,e,s=0,i=0){if(this.lost)return;this.batch.has(t)&&this.flush();const n=this.gl,r=this.textures.get(t);r&&(this.bindTex(r),!e||e===t.source&&s===0&&i===0?n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t.source):n.texSubImage2D(n.TEXTURE_2D,0,s,i,n.RGBA,n.UNSIGNED_BYTE,e))}destroyTexture(t){this.batch.has(t)&&this.flush();const e=this.textures.get(t);e&&!this.lost&&this.deleteTex(e),this.textures.delete(t)}begin(t,e,s){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(s),this.bScis=!1,this.lost)return;const i=this.gl;i.disable(i.SCISSOR_TEST),this.bindFb(null),i.viewport(0,0,this.canvas.width,this.canvas.height);const n=e;i.clearColor((t>>16&255)/255*n,(t>>8&255)/255*n,(t&255)/255*n,n),i.clear(i.COLOR_BUFFER_BIT),this.use(this.main),i.uniform2f(this.uScale,2*s/this.canvas.width,-2*s/this.canvas.height),this.mapped=!0}build(t){const e=this.gl,s=Ai(e,e.VERTEX_SHADER,this.vsrc);let i;try{i=Ai(e,e.FRAGMENT_SHADER,t)}catch(r){throw e.deleteShader(s),r}const n=e.createProgram();if(e.attachShader(n,s),e.attachShader(n,i),this.attrs.forEach((r,a)=>e.bindAttribLocation(n,a,r)),e.linkProgram(n),e.deleteShader(s),e.deleteShader(i),!e.getProgramParameter(n,e.LINK_STATUS)){const r=e.getProgramInfoLog(n)??"?";throw e.deleteProgram(n),new Error(`link: ${r}`)}return{p:n,uScale:e.getUniformLocation(n,"uScale"),locs:new Map}}u(t,e){let s=t.locs.get(e);return s===void 0&&t.locs.set(e,s=this.gl.getUniformLocation(t.p,e)),s}use(t){this.cur!==t&&(this.cur=t,this.gl.useProgram(t.p),this.calls.useProgram++)}bindTex(t,e=this.unit<0?0:this.unit){const s=this.gl;this.onUnit[e]!==t&&(this.unit!==e&&(s.activeTexture(s.TEXTURE0+e),this.calls.activeTexture++,this.unit=e),s.bindTexture(s.TEXTURE_2D,t),this.calls.bindTexture++,this.onUnit[e]=t)}deleteTex(t){this.gl.deleteTexture(t);for(let e=0;e<this.onUnit.length;e++)this.onUnit[e]===t&&(this.onUnit[e]=null)}bindFb(t){if(t)for(let s=0;s<this.onUnit.length;s++)this.onUnit[s]===t.gl&&this.bindTex(null,s);const e=t?t.fb:null;this.fbNow!==e&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,e),this.calls.bindFramebuffer++,this.fbNow=e)}slotOf(t){this.batch.full&&this.flush();let e=this.batch.slot(t);return e<0&&(this.flush(),e=this.batch.slot(t)),e}quad(t,e,s,i,n,r,a,h){U[0]=i,U[1]=n,U[2]=a,this.quadQ(t,e,s,r,h)}quadQ(t,e,s,i,n){const r=U[2];if(this.lost||r<=0)return;const a=this.q,h=U[0],l=U[1],o=s[4],u=s[5],f=s[0]*h,p=s[1]*h,g=s[2]*l,d=s[3]*l;a[0]=o,a[1]=u,a[2]=f+o,a[3]=p+u,a[4]=f+g+o,a[5]=p+d+u,a[6]=g+o,a[7]=d+u;const y=1/t.width,m=1/t.height;a[8]=e.x*y,a[9]=e.y*m,a[10]=(e.x+e.w)*y,a[11]=(e.y+e.h)*m,a[12]=Lt(i,r,n==="add"),this.put(t)}put(t){if(this.mute)return;const e=this.q;let s=!1;const i=Math.min(e[0],e[2],e[4],e[6]),n=Math.max(e[0],e[2],e[4],e[6]),r=Math.min(e[1],e[3],e[5],e[7]),a=Math.max(e[1],e[3],e[5],e[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;const l=this.scale,o=this.px0/l,u=this.py0/l,f=this.px1/l,p=this.py1/l;if(n<=o||i>=f||a<=u||r>=p)return;if(i<o||n>f||r<u||a>p){const g=e[0],d=e[1],y=e[2],m=e[5];if(d===e[3]&&y===e[4]&&m===e[7]&&e[6]===g){if(g!==y){const w=Math.min(Math.max(g,o),f),x=Math.min(Math.max(y,o),f),_=e[8],M=(e[10]-_)/(y-g);e[10]=_+(x-g)*M,e[8]=_+(w-g)*M,e[0]=e[6]=w,e[2]=e[4]=x}if(d!==m){const w=Math.min(Math.max(d,u),p),x=Math.min(Math.max(m,u),p),_=e[9],M=(e[11]-_)/(m-d);e[11]=_+(x-d)*M,e[9]=_+(w-d)*M,e[1]=e[3]=w,e[5]=e[7]=x}}else s=!0}}const h=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(s?(!this.bScis||!h)&&(this.flush(),this.bScis=!0,this.bx0=this.px0,this.by0=this.py0,this.bx1=this.px1,this.by1=this.py1):this.bScis&&!(this.cOn&&h)&&(this.flush(),this.bScis=!1),this.real){const l=this.gq;l[0]=i,l[1]=r,l[2]=n,l[3]=a,this.growQ()}this.batch.pushQ(e,this.slotOf(t))}ellipse(t,e,s,i,n,r,a){if(this.lost||a<=0||s<=0||i<=0)return;const h=ds[bi(Math.max(s,i)*2*this.scale,ar)],l=h.w/2/h.r,o=s*l,u=i*l,f=Math.cos(n),p=Math.sin(n),g=f*o,d=p*o,y=-p*u,m=f*u,w=1/et,x=this.q;x[0]=t-g-y,x[1]=e-d-m,x[2]=t+g-y,x[3]=e+d-m,x[4]=t+g+y,x[5]=e+d+m,x[6]=t-g+y,x[7]=e-d+m,x[8]=h.x*w,x[9]=h.y*w,x[10]=(h.x+h.w)*w,x[11]=(h.y+h.h)*w,x[12]=Lt(r,a),this.put(this.kit)}polygon(t,e,s,i){if(this.lost||i<=0||e<3)return;this.tris.length<e*3&&(this.tris=new Int32Array(Math.max(e*3,this.tris.length*2)));const n=this.tris,r=ir(t,e,n),a=Lt(s,i),h=(xt.x+xt.w/2)/et,l=(xt.y+xt.h/2)/et;for(let o=0;o<r;o+=3){const u=n[o]*2,f=n[o+1]*2,p=n[o+2]*2,g=this.q;g[0]=t[u],g[1]=t[u+1],g[2]=t[f],g[3]=t[f+1],g[4]=g[6]=t[p],g[5]=g[7]=t[p+1],g[8]=g[10]=h,g[9]=g[11]=l,g[12]=a,this.put(this.kit)}}stroke(t,e,s,i,n,r){if(this.lost||n<=0||s<=0||e<1)return;const a=ps[bi(s*this.scale,or)],h=s/2*(a.h/2/a.r);this.sPacked=Lt(i,n),this.sColor=i,this.sAlpha=n,this.sU=(a.x+a.w/2)/et,this.sV0=a.y/et,this.sV1=(a.y+a.h)/et,this.sHw=s/2,rr(t,e,h,r,this.strokeSeg,this.strokeDisc)}target(t,e,s,i){const n=this.gl,r=n.createTexture();this.bindTex(r),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,e,0,n.RGBA,n.UNSIGNED_BYTE,null);const a=i?n.LINEAR:n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),this.bindTex(null);const h=n.createFramebuffer();n.bindFramebuffer(n.FRAMEBUFFER,h),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,r,0);const l=n.checkFramebufferStatus(n.FRAMEBUFFER)===n.FRAMEBUFFER_COMPLETE;if(this.fbNow=h,this.bindFb(this.parent()),!l)return this.deleteTex(r),n.deleteFramebuffer(h),null;const o={tex:{id:ss(),width:t,height:e,source:this.canvas},gl:r,fb:h,w:t,h:e,f:s};return this.layerTex.set(o.tex,r),o}drop(t){this.batch.has(t.tex)&&this.flush(),this.deleteTex(t.gl),this.gl.deleteFramebuffer(t.fb),this.layerTex.delete(t.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(t){const e=this.canvas.width,s=this.canvas.height;let i=this.layers[t]??null;return i&&(i.w!==e||i.h!==s)&&(this.drop(i),i=this.layers[t]=null),i??(this.layers[t]=this.target(e,s,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();const t=this.layerAt(this.real);if(!t)return!1;const e=this.gl;return this.bindFb(t),e.disable(e.SCISSOR_TEST),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!ht.gl?null:this.fxr??(this.fxr=ht.gl(this))}composite(t,e,s,i){if(i&&this.filters()?.chain(t,s,i))return;const n=this.gl;e&&n.blendFunc(n.ZERO,n.SRC_ALPHA),this.final(this.main,t,1,s),e&&(this.flush(),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA))}final(t,e,s,i){const n=this.gl,r=this.canvas.width,a=this.canvas.height,h=this.scale;(t!==this.main||!this.mapped)&&(this.bindFb(this.parent()),n.viewport(0,0,r,a),this.use(t),n.uniform2f(t.uScale,2*h/r,-2*h/a),this.mapped=t===this.main);const l=this.rx0/h,o=this.ry0/h,u=this.rx1/h,f=this.ry1/h,p=1/(s*e.width),g=1/(s*e.height),d=this.q;d[0]=d[6]=l,d[1]=d[3]=o,d[2]=d[4]=u,d[5]=d[7]=f,d[8]=this.rx0*p,d[9]=1-this.ry0*g,d[10]=this.rx1*p,d[11]=1-this.ry1*g,d[12]=Lt(16777215,i),this.put(e),t!==this.main&&this.flush()}remap(){const t=this.gl;this.bindFb(this.parent()),t.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),t.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(t){const e=this.gl,s=t.words;if(this.kind==="webgl2")return e.bufferSubData(e.ARRAY_BUFFER,0,t.f32,0,s);let i=this.views.get(s);i||(this.views.size>=256&&this.views.clear(),this.views.set(s,i=t.f32.subarray(0,s))),e.bufferSubData(e.ARRAY_BUFFER,0,i)}flush(){const t=this.batch;if(!t.quads||this.lost)return t.reset();const e=this.gl;this.bScis?(e.enable(e.SCISSOR_TEST),e.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):e.disable(e.SCISSOR_TEST),this.upload2(t);for(let s=0;s<t.bound;s++){const i=t.textures[s];this.bindTex(this.textures.get(i)??this.layerTex.get(i)??null,s)}this.inst?this.inst.draw(6,t.quads):e.drawElements(e.TRIANGLES,t.quads*6,e.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=t.quads,t.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){const t=this.gl;ht.live===this&&(ht.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(const e of this.textures.values())e&&t.deleteTexture(e);for(const e of this.layers)e&&(t.deleteTexture(e.gl),t.deleteFramebuffer(e.fb));this.fxr?.destroy(),this.fxr=null,t.deleteBuffer(this.dynamic),t.deleteBuffer(this.index),this.staticBuf&&t.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),t.deleteProgram(this.main.p),t.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function Ai(t,e,s){const i=t.createShader(e);if(t.shaderSource(i,s),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS)){const n=t.getShaderInfoLog(i)??"?";throw t.deleteShader(i),new Error(n)}return i}function _i(t="auto"){switch(t){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function ms(t,e={}){let s=t;for(const i of _i(e.renderer)){const n=i==="canvas2d"?ls(s):mr(s,i==="webgl2"?2:1,e);if(n)return n;s=ys(s)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function ys(t){const e=t.cloneNode(!1);return t.parentNode?.replaceChild(e,t),e}function vr(t=typeof location<"u"?location.search:""){const e=new URLSearchParams(t).get("renderer");return e==="canvas"?"canvas2d":e==="webgl2"||e==="webgl1"||e==="canvas2d"||e==="webgl"||e==="auto"?e:void 0}var vs=class{constructor(t,e={}){c(this,"atlas",t),c(this,"tags",new Map),c(this,"count",0),c(this,"m",Nt()),c(this,"measure",null),c(this,"height"),c(this,"font"),this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(const t of this.tags.values())for(const e of t.values())for(const s of e.values())this.atlas.release(s);this.tags.clear(),this.count=0}get(t,e,s){let i=this.tags.get(t);i||this.tags.set(t,i=new Map);let n=i.get(e);n||i.set(e,n=new Map);const r=n.get(s);return r&&this.atlas.valid(r)?r:this.bake(t,e,s)}bake(t,e,s){const i=this.height,n=`700 ${Math.round(i*.65)}px ${this.font}`,r=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));r.font=n;const a=Math.round(i*.4),h=Math.ceil(r.measureText(t).width)+a*2,l=this.atlas.bake((h+2)*s,(i+2)*s,f=>{f.scale(s,s),f.translate(1,1);const p=i/2;f.beginPath(),f.moveTo(p,0),f.lineTo(h-p,0),f.arc(h-p,p,p,-Math.PI/2,Math.PI/2),f.lineTo(p,i),f.arc(p,p,p,Math.PI/2,Math.PI*3/2),f.closePath(),f.fillStyle=e,f.fill(),f.fillStyle="#fff",f.font=n,f.textAlign="center",f.textBaseline="middle",f.fillText(t,h/2,i/2+1)},s,1,1,1);++this.count>64&&(this.drop(),this.count=1);let o=this.tags.get(t);o||this.tags.set(t,o=new Map);let u=o.get(e);return u||o.set(e,u=new Map),u.set(s,l),l}draw(t,e,s,i,n,r,a,h,l,o,u){const f=Cn(s,n,{band:wr(i)});if(!f)return;const p=this.height,g=this.get(r,a,l),d=g.w/g.scale-2,y=Math.min(Math.max(f.head.x-d/2,4),o-d-4),m=Math.min(Math.max(f.head.y-f.headR*2.2-p,4),u-p-4);ct(this.m,null,y-1,m-1,0,1,1),t.quad(e(g.surface),g,this.m,g.w/g.scale,g.h/g.scale,16777215,h,"normal")}},wr=t=>t.band==="3-5"||t.band==="9-12"?t.band:"6-8",xr=(t,e=!1)=>e?Math.min(2**Math.round(Math.log2(Math.max(t,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(t,8))*2)/2),512);function ws(t,e=null){const s={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},i=(n,r,a)=>{const h=e?e[0]*n+e[2]*r+e[4]:n,l=e?e[1]*n+e[3]*r+e[5]:r,o=e?Math.hypot(e[0],e[1]):1;s.minX=Math.min(s.minX,h-a*o),s.minY=Math.min(s.minY,l-a*o),s.maxX=Math.max(s.maxX,h+a*o),s.maxY=Math.max(s.maxY,l+a*o)};for(const n of t){const r="lw"in n&&n.stroke?(n.lw??1)/2:0;switch(n.k){case"circle":i(n.x-n.r,n.y-n.r,r),i(n.x+n.r,n.y+n.r,r),i(n.x-n.r,n.y+n.r,r),i(n.x+n.r,n.y-n.r,r);break;case"ellipse":case"rect":{const a=n.k==="ellipse"?Math.max(n.rx,n.ry):Math.hypot(n.w,n.h)/2;i(n.x-a,n.y-a,r),i(n.x+a,n.y+a,r),i(n.x-a,n.y+a,r),i(n.x+a,n.y-a,r);break}case"path":{const a=us(n.d);for(let h=0;h<a.count;h++){const l=a.subs[h];for(let o=0;o<l.n;o++)i(l.pts[o*2],l.pts[o*2+1],r)}break}case"line":for(let a=0;a+1<n.pts.length;a+=2)i(n.pts[a],n.pts[a+1],r);break;case"group":{const a=ct(Nt(),e,n.x,n.y,n.rot??0,n.s??1,n.s??1),h=ws(n.items,a);Number.isFinite(h.minX)&&(s.minX=Math.min(s.minX,h.minX),s.minY=Math.min(s.minY,h.minY),s.maxX=Math.max(s.maxX,h.maxX),s.maxY=Math.max(s.maxY,h.maxY));break}}}return s}var xs=class{constructor(t){c(this,"atlas",t),c(this,"seen",new WeakSet),c(this,"baked",new WeakMap),c(this,"m",Nt()),c(this,"stack",[]),c(this,"local",Nt()),c(this,"pts",new Float64Array(128)),c(this,"stats",{baked:0,vector:0}),c(this,"bakeGroups",!0),c(this,"coarse",!1),c(this,"gen",0),c(this,"live",new Set)}setTier(t){const e=t==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(const s of this.live)this.atlas.release(s.frame);this.live.clear()}}draw(t,e,s,i,n,r,a){const h=typeof i=="string"?de(i)??pe:i,l=Rn(s,h,n);return l.length?(r<=0||(r<1?(this.paint(t,e,l,null,t.beginLayer()?1:r,a),t.endLayer(r)):this.paint(t,e,l,null,r,a)),!0):!1}paint(t,e,s,i,n,r,a=0){var h;for(let l=0;l<s.length;l++){const o=s[l];if(o.k==="group"){const w=ct((h=this.stack)[a]??(h[a]=Nt()),i,o.x,o.y,o.rot??0,o.s??1,o.s??1),x=n*(o.alpha??1);if(this.bakeGroups&&this.seen.has(o.items)){const _=ft(w[0],w[1])*r,M=this.bake(o.items,_);if(M){const k=M.frame,F=this.m;F.set(w),F[4]=w[0]*-M.ox+w[2]*-M.oy+w[4],F[5]=w[1]*-M.ox+w[3]*-M.oy+w[5],t.quad(e(k.surface),k,F,k.w/M.k,k.h/M.k,16777215,x,"normal"),this.stats.baked++;continue}}this.seen.add(o.items),this.stats.vector++,this.paint(t,e,o.items,w,x,r,a+1);continue}const u=n*(o.alpha??1),f=i?ft(i[0],i[1]):1,p=i?Math.atan2(i[1],i[0]):0,g=(o.lw??1)*f,d=o.stroke&&(o.lw??1)>0?ot(o.stroke):null,y=o.fill&&o.k!=="line"?ot(o.fill):null;if(o.k==="circle"||o.k==="ellipse"){const w=i?i[0]*o.x+i[2]*o.y+i[4]:o.x,x=i?i[1]*o.x+i[3]*o.y+i[5]:o.y,_=(o.k==="circle"?o.r:o.rx)*f,M=(o.k==="circle"?o.r:o.ry)*f,k=(o.k==="ellipse"?o.rot??0:0)+p;if(y&&d)t.ellipse(w,x,_+g/2,M+g/2,k,d[0],u*d[1]),t.ellipse(w,x,Math.max(_-g/2,0),Math.max(M-g/2,0),k,y[0],u*y[1]);else if(y)t.ellipse(w,x,_,M,k,y[0],u*y[1]);else if(d){const F=Math.min(Math.max(Math.ceil(Math.max(_,M)*r*.6),12),64),R=this.pts=cs(this.pts,F*2),N=Math.cos(k),I=Math.sin(k);for(let D=0;D<F;D++){const W=D/F*Math.PI*2,X=Math.cos(W)*_,z=Math.sin(W)*M;R[D*2]=w+X*N-z*I,R[D*2+1]=x+X*I+z*N}t.stroke(R,F,g,d[0],u*d[1],!0)}continue}if(o.k==="line"){if(!d)continue;const w=o.pts.length>>1,x=this.pts=cs(this.pts,w*2);for(let _=0;_<w;_++){const M=o.pts[_*2],k=o.pts[_*2+1];x[_*2]=i?i[0]*M+i[2]*k+i[4]:M,x[_*2+1]=i?i[1]*M+i[3]*k+i[5]:k}t.stroke(x,w,g,d[0],u*d[1],!1);continue}const m=o.k==="path"?us(o.d,i,f*r):br(o,ct(this.local,i,o.x,o.y,o.rot??0,1,1),r*f);for(let w=0;w<m.count;w++){const x=m.subs[w],_=x.n,M=o.k==="rect"||x.closed;y&&_>=3&&(t.polygon(x.pts,_,y[0],u*y[1]),d||t.stroke(x.pts,_,1/r,y[0],u*y[1],!0)),d&&t.stroke(x.pts,_,g,d[0],u*d[1],M)}}}bake(t,e){const s=xr(e,this.coarse);let i=this.baked.get(t);const n=i?.get(s);if(n&&n.gen===this.gen&&this.atlas.valid(n.frame))return n;n&&this.live.delete(n);const r=ws(t);if(!Number.isFinite(r.minX))return null;const a=2/s,h=(r.maxX-r.minX+a*2)*s,l=(r.maxY-r.minY+a*2)*s;if(h>1024||l>1024)return null;const o=-r.minX+a,u=-r.minY+a,p={frame:this.atlas.bake(h,l,g=>{g.scale(s,s),g.translate(o,u),Xs(g,t)}),k:s,ox:o,oy:u,gen:this.gen};return i||this.baked.set(t,i=new Map),i.set(s,p),this.live.add(p),p}},Gt=new Array(36).fill(0),Xt=0,lt=(t,e=NaN,s=NaN,i=NaN,n=NaN)=>{Gt[Xt++]=t,t!==J.Z&&(Gt[Xt++]=e,Gt[Xt++]=s,t===J.Q&&(Gt[Xt++]=i,Gt[Xt++]=n))};function br(t,e,s){const i=Math.max(0,Math.min(t.r,t.w/2,t.h/2)),n=-t.w/2,r=-t.h/2,{M:a,L:h,Q:l,Z:o}=J;return Xt=0,lt(a,n+i,r),lt(h,n+t.w-i,r),lt(l,n+t.w,r,n+t.w,r+i),lt(h,n+t.w,r+t.h-i),lt(l,n+t.w,r+t.h,n+t.w-i,r+t.h),lt(h,n+i,r+t.h),lt(l,n,r+t.h,n,r+t.h-i),lt(h,n,r+i),lt(l,n,r,n+i,r),lt(o),us(Gt,e,s)}function Mr(t,e={}){let s=ms(t,e);const i=new as(Math.min(1024,s.maxTextureSize),2);i.onDrop=k=>{k.texture&&s.destroyTexture(k.texture),k.texture=null};const n=new xs(i);let r=new ni;const a=new Map;let h=1e6;const l=e.smooth===!1?1:typeof e.smooth=="number"?Math.min(Math.max(e.smooth,.05),1):.5;let o=Te(s);const u=new vs(i,e),f={w:1,h:1};let p=1,g=0,d=!1;const y=()=>u.drop(),m=typeof document<"u"?document.fonts:void 0;m?.ready?.then(()=>{d||y()}),m?.addEventListener?.("loadingdone",y);const w=()=>{const k=ys(s.canvas),F=ls(k);if(F){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),s.destroy(),s=F;for(const R of i.pages)R.surface.texture=null;o=Te(s),g=0}},x=()=>{if(!s.lost)return g=0,!0;const k=performance.now();return g||(g=k),k-g>3e3&&w(),!s.lost},_=()=>{const k=s.canvas;e.units?(p=e.pixelRatio??1,f.w=e.units.width,f.h=e.units.height):(p=e.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),f.w=k.clientWidth||k.width/p,f.h=k.clientHeight||k.height/p),s.resize(Math.max(1,Math.round(f.w*p)),Math.max(1,Math.round(f.h*p))),s.begin(0,0,p)},M=(k,F)=>{if(k.key===void 0)return k.id??F+1;let R=a.get(k.key);return R===void 0&&(a.size>256&&a.clear(),a.set(k.key,R=h++)),R};return{get renderer(){return s},get kind(){return s.kind},get lost(){return s.lost},get canvas(){return s.canvas},draw(k,F){if(x()){_();for(let R=0;R<k.length;R++){const N=k[R];if(!Array.isArray(N.body))continue;const I=M(N,R),D=l<1||e.interpolate!==!1?r.posed(I,N.body,l,e.interpolate!==!1):N.body,W=de(N.avatar??"")??pe,X=N.alpha??1;!n.draw(s,o,D,W,F,X,p)||!N.name||u.draw(s,o,D,W,F,N.name,N.color??"#6FA0E0",X,p,f.w,f.h)}s.end()}},clear(){x()&&(_(),s.end())},reset(){r=new ni,a.clear()},destroy(){d=!0,m?.removeEventListener?.("loadingdone",y),s.destroy()}}}var Ee=new Map;function kr(t,e,s=Math.min(globalThis.devicePixelRatio||1,2)){const i=`${t}|${e}|${s}`;let n=Ee.get(i);if(n)return n;n=document.createElement("canvas"),n.width=n.height=Math.round(e*s);const r=n.getContext("2d");return r.scale(s,s),r.beginPath(),r.rect(0,0,e,e),r.clip(),Xs(r,Pn(de(t)??pe,e)),Ee.size>64&&Ee.clear(),Ee.set(i,n),n}function Te(t){return e=>{if(e.texture||(e.texture=t.createTexture(e.source),e.pending.length=0),e.pending.length){for(const[s,i,n]of e.pending)t.updateTexture(e.texture,s,i,n);e.pending.length=0}return e.texture}}var Ei='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',ee="rgba(10,16,30,0.75)";function Ti(t,e){const s=t.size??40,i=t.outline?t.outline===!0?ee:t.outline:null,n=i?t.outlineWidth??Math.max(s*.12,3):0,r=t.shadow&&e?t.shadow===!0?ee:t.shadow:null,a=r?t.shadowBlur??s*.25:0;return{size:s,font:t.font??Ei,weight:t.weight??700,color:t.color??"#FBEFE3",outline:i,ow:n,shadow:r,blur:a,pad:n/2+a*1.2+2,th:s*1.25}}var Si=(t,e)=>`${t.weight} ${t.size*e}px ${t.font}`;function Fi(t,e,s,i,n,r){t.scale(i,i),t.font=Si(s,1),t.textBaseline="middle",t.textAlign="left",t.lineJoin="round",s.shadow&&(t.shadowColor=s.shadow,t.shadowBlur=s.blur*i),s.outline&&(t.strokeStyle=s.outline,t.lineWidth=s.ow,t.strokeText(e,n,r),t.shadowColor="transparent"),t.fillStyle=s.color,t.fillText(e,n,r)}var Se=null;function Ri(t,e,s){return Se??(Se=document.createElement("canvas").getContext("2d")),Se.font=Si(e,s),Se.measureText(t).width/s}var se=class extends It{constructor(t,e,s={}){super(t,null),c(this,"_text"),c(this,"_style"),c(this,"dirty",!0),c(this,"bakedScale",0),c(this,"bakedFontGen",-1),c(this,"bakedEffects",!0),c(this,"capW",0),c(this,"capH",0),this._text=e;const{x:i,y:n,rotation:r,scale:a,scaleX:h,scaleY:l,alpha:o,visible:u,tint:f,blend:p,z:g,anchor:d,hitRadius:y,clip:m,mask:w,filters:x,..._}=s;this._style=_,this.bake(),this.set({x:i,y:n,rotation:r,scale:a,scaleX:h,scaleY:l,alpha:o,visible:u,tint:f,blend:p,z:g,hitRadius:y,clip:m,mask:w,filters:x}),d!==void 0&&(this.anchor=d)}get text(){return this._text}set text(t){const e=String(t);e!==this._text&&(this._text=e,this.dirty=!0)}get style(){return this._style}set style(t){this._style={...this._style,...t},this.dirty=!0}bitmap(){const t=this._style.bitmapFont;if(!t)return null;const e=typeof t=="string"?this.kernel.bitmapFont(t):t;if(this.autoAnchor){const s=this._style.align;this.anchorX=s==="left"?0:s==="right"?1:.5,this.anchorY=.5}return e}get naturalWidth(){const t=this.bitmap();return t?t.measure(this._text)*((this._style.size??t.size)/t.size):super.naturalWidth}get naturalHeight(){const t=this.bitmap();return t?t.lineHeight*((this._style.size??t.size)/t.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(t,e,s){const i=this.bitmap();if(!i)return super.draw(t,e,s);const n=(this._style.size??i.size)/i.size,r=i.measure(this._text)*n,a=i.lineHeight*n,h=this.width,l=this.height,o=r>0?h/r:1,u=a>0?l/a:1;i.run(this._text,t,this.world,-this.anchorX*h,-this.anchorY*l,n*o,n*u,s,e,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){const t=this.kernel;if(this._style.bitmapFont)return null;const e=t.pixelScale,s=t.effects;return!this.dirty&&e===this.bakedScale&&t.fontGen===this.bakedFontGen&&s===this.bakedEffects&&t.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){const t=this.kernel,e=t.pixelScale,s=t.effects;this.dirty=!1,this.bakedScale=e,this.bakedFontGen=t.fontGen,this.bakedEffects=s;const i=Ti(this._style,s),{pad:n,th:r}=i,a=Ri(this._text,i,e),h=(a+n*2)*e,l=(r+n*2)*e,o=this._style.align??"center",u=o==="left"?n:o==="right"?n+a:n+a/2,f=d=>Fi(d,this._text,i,e,n,n+r/2),p=this._frame;let g=null;return p&&t.atlas.valid(p)&&p.scale===e&&(g=t.atlas.rebake(p,h,l,f,this.capW,this.capH),g?Object.assign(g,{ox:u,oy:n+r/2,margin:n}):t.atlas.release(p)),g||(this.capW=Math.ceil(h*1.25+16),this.capH=Math.ceil(l),g=t.atlas.bake(this.capW,this.capH,f,e,u,n+r/2,n),g.w=Math.ceil(h),g.h=Math.ceil(l)),this._frame=g,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,g}},H=(t,e=0)=>{const s=Number(t);return Number.isFinite(s)?s:e};function Fe(t){typeof t=="string"&&/^\s*[{[]/.test(t)&&(t=JSON.parse(t));const e={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},s=(i,n)=>{i==="info"?e.size=Math.abs(H(n.size)):i==="common"?(e.lineHeight=H(n.lineHeight),e.base=H(n.base)):i==="page"?e.pages[H(n.id)]=String(n.file??""):i==="char"?e.chars.push({id:H(n.id),x:H(n.x),y:H(n.y),width:H(n.width),height:H(n.height),xoffset:H(n.xoffset),yoffset:H(n.yoffset),xadvance:H(n.xadvance),page:H(n.page)}):e.kernings.push({first:H(n.first),second:H(n.second),amount:H(n.amount)})};if(typeof t=="object"){const i=t;s("info",i.info??{}),s("common",i.common??{});for(const[n,r]of(i.pages??[]).entries())s("page",{id:n,file:r});for(const n of i.chars??[])s("char",n);for(const n of i.kernings??[])s("kerning",n)}else{const i=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,n=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let r=i.exec(t);r;r=i.exec(t)){const a={};for(let h=n.exec(r[2]);h;h=n.exec(r[2]))a[h[1]]=h[2]??h[3];s(r[1],a)}}return e.size||(e.size=e.lineHeight),e}var bs=class{constructor(t,e,s,i=null,n=null){c(this,"baker",i),c(this,"host",n),c(this,"size"),c(this,"lineHeight"),c(this,"base"),c(this,"ascii",new Array(128)),c(this,"more",new Map),c(this,"kern",new Map),c(this,"bScale",0),c(this,"bFontGen",-1),c(this,"bEffects",!1),c(this,"bGen",-1),this.size=t,this.lineHeight=e,this.base=s}set(t,e){t<128?this.ascii[t]=e:this.more.set(t,e)}setKerning(t,e,s){this.kern.set(t*1114112+e,s)}prepare(){const t=this.host;if(!(!t||t.pixelScale===this.bScale&&t.fontGen===this.bFontGen&&t.effects===this.bEffects&&t.atlas.gen===this.bGen)){this.bScale=t.pixelScale,this.bFontGen=t.fontGen,this.bEffects=t.effects,this.bGen=t.atlas.gen;for(const e of this.ascii)e&&t.atlas.release(e.frame);for(const e of this.more.values())e&&t.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(t){let e=t<128?this.ascii[t]:this.more.get(t);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(t):null,this.set(t,e)),e}kerning(t,e){return this.kern.size?this.kern.get(t*1114112+e)??0:0}measure(t){return this.run(t)}run(t,e,s,i=0,n=0,r=1,a=1,h=0,l=1,o="normal"){this.prepare();let u=0,f=-1;for(let p=0;p<t.length;p++){let g=t.charCodeAt(p);g>=55296&&g<56320&&p+1<t.length&&(g=t.codePointAt(p),p++),f>=0&&(u+=this.kerning(f,g)),f=g;const d=this.glyph(g);d&&(e&&d.w>0&&d.h>0&&(me(s,i+(u+d.x)*r,n+d.y*a),e.r.quad(e.tex(d.frame.surface),d.frame,q,d.w*r,d.h*a,h,l,o)),u+=d.advance)}return u}};function Ar(t,e){const s=new bs(t.size,t.lineHeight,t.base);for(const i of t.chars){const n=e[i.page];if(!n)continue;const r={surface:n,x:i.x,y:i.y,w:i.width,h:i.height,scale:1,gen:0,ox:0,oy:0,margin:0};s.set(i.id,{frame:r,x:i.xoffset,y:i.yoffset,w:i.width,h:i.height,advance:i.xadvance})}for(const i of t.kernings)s.setKerning(i.first,i.second,i.amount);return s}function _r(t,e){const s={...e},i=e.size??40,n=a=>{const h=String.fromCodePoint(a),l=t.pixelScale,o=Ti(s,t.effects),u=Ri(h,o,l),f=t.atlas.bake((u+o.pad*2)*l,(o.th+o.pad*2)*l,p=>Fi(p,h,o,l,o.pad,o.pad+o.th/2),l);return{frame:f,x:-o.pad,y:-o.pad,w:f.w/l,h:f.h/l,advance:u}},r=new bs(i,i*1.25,i,n,t);r.prepare();for(const a of e.chars??"0123456789")r.glyph(a.codePointAt(0));return r}var Er=.5;function Ci(t){const e=[];for(const[s,i]of[["left",zs.leftWrist],["right",zs.rightWrist]]){const n=t[i*3],r=t[i*3+1],a=t[i*3+2];n!==void 0&&r!==void 0&&Number.isFinite(n)&&Number.isFinite(r)&&(a??0)>=Er&&e.push({side:s,x:n,y:r})}return e}var Ms=t=>ue[((t-1)%ue.length+ue.length)%ue.length];function Pi(t,e,s,i,n=()=>null){const r=[];for(const a of t){const h=n(a)??a.body;if(Array.isArray(h))for(const l of Ci(h)){const o=e(l);r.push({player:a.id,side:l.side,x:o.x*s,y:o.y*i,color:Ms(a.id)})}}return r}function ks(t,e,s,i=0){const n=t.world,r=Nn(n,e,s);if(!r)return!1;const a=Math.hypot(n[0],n[1])||1,h=Math.hypot(n[2],n[3])||1,[l,o]=r;if(t.hitRadius!=null){const d=t.hitRadius+i/((a+h)/2);return l*l+o*o<=d*d}const u=-t.anchorX*t.width-i/a,f=-t.anchorY*t.height-i/h,p=(1-t.anchorX)*t.width+i/a,g=(1-t.anchorY)*t.height+i/h;return l>=u&&l<=p&&o>=f&&o<=g}function Ni(t,e,s,i=0){for(const n of e)if((s===void 0||n.player===s)&&ks(t,n.x,n.y,i))return n;return null}function Tr(t){switch(t.type){case"circle":case"ring":case"star":return[t.r*2,t.r*2];case"ellipse":return[t.rx*2,t.ry*2];case"roundRect":return[t.w,t.h];case"line":return[t.length,t.lw??4];case"path":return t.r?[t.r*2,t.r*2]:[t.size,t.size]}}function Sr(t){const e=t.type==="line"?0:t.stroke?(t.lw??2)/2:0,s=t.shadow?t.shadow.blur*1.5+Math.max(Math.abs(t.shadow.x??0),Math.abs(t.shadow.y??0)):0;return Math.ceil(e+s+1)}var Fr=(t,e)=>e||!t.shadow?t:{...t,shadow:void 0};function Li(t,e,s){const i=Sr(e),n=e.type==="roundRect",[r,a]=n?[Math.min(e.w,e.r*2+4/s),Math.min(e.h,e.r*2+4/s)]:Tr(e),h=(r+i*2)*s,l=(a+i*2)*s;return{frame:t.bake(h,l,u=>{u.scale(s,s),u.translate(i+r/2,i+a/2),Rr(u,e,r,a)},s,i+r/2,i+a/2,i),slice:n?Math.ceil((e.r+i)*s):0,w:n?e.w:r,h:n?e.h:a}}function Rr(t,e,s,i){t.lineJoin="round",t.lineCap="round";const n=new Path2D;switch(e.type){case"circle":case"ring":n.arc(0,0,e.r,0,Math.PI*2);break;case"ellipse":n.ellipse(0,0,e.rx,e.ry,0,0,Math.PI*2);break;case"roundRect":n.roundRect(-s/2,-i/2,s,i,Math.min(e.r,s/2,i/2));break;case"star":{const o=e.points??5,u=e.r*(e.inner??.5);for(let f=0;f<o*2;f++){const p=f%2?u:e.r,g=-Math.PI/2+f*Math.PI/o;f?n.lineTo(Math.cos(g)*p,Math.sin(g)*p):n.moveTo(Math.cos(g)*p,Math.sin(g)*p)}n.closePath();break}case"line":n.moveTo(-s/2+i/2,0),n.lineTo(s/2-i/2,0);break;case"path":{const o=e.r?e.r*2/e.size:1,u=new DOMMatrix([o,0,0,o,-e.size/2*o,-e.size/2*o]);n.addPath(new Path2D(e.d),u);break}}const r=e.shadow,a=()=>{if(!r)return;const o=t.getTransform();t.shadowColor=r.color,t.shadowBlur=r.blur*o.a,t.shadowOffsetX=(r.x??0)*o.a,t.shadowOffsetY=(r.y??0)*o.a},h=()=>{t.shadowColor="transparent",t.shadowBlur=0};if(e.type==="line"){a(),t.strokeStyle=e.stroke??e.fill??"#fff",t.lineWidth=i,t.stroke(n);return}const l=e.type==="ring";if(e.outlineBelow&&e.fill&&e.stroke&&!l){a(),t.strokeStyle=e.stroke,t.lineWidth=e.lw??2,t.stroke(n),h(),t.fillStyle=e.fill,t.fill(n);return}e.fill&&!l&&(a(),t.fillStyle=e.fill,t.fill(n),h()),(e.stroke||l)&&((!e.fill||l)&&a(),l&&e.fill&&(t.fillStyle=e.fill,t.fill(n)),t.strokeStyle=e.stroke??"#fff",t.lineWidth=e.lw??2,t.stroke(n),h())}var Ii=class{constructor(){if(c(this,"ctx",null),c(this,"master",null),c(this,"buffers",new Map),c(this,"held",!1),c(this,"muted",!1),c(this,"volume",1),typeof addEventListener=="function"){const t=()=>{this.context()?.resume().catch(()=>{})};for(const e of["pointerdown","keydown","touchstart"])addEventListener(e,t,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;const t=globalThis.AudioContext??globalThis.webkitAudioContext;if(!t)return null;try{this.ctx=new t,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch{return null}return this.ctx}async load(t,e){const s=this.context();if(!s)return;const i=await(await fetch(e)).arrayBuffer();this.buffers.set(t,await s.decodeAudioData(i))}has(t){return this.buffers.has(t)}play(t,e={}){const s=this.context(),i=this.buffers.get(t);if(!s||!i||!this.audible)return()=>{};const n=s.createBufferSource();n.buffer=i,n.loop=e.loop??!1,n.playbackRate.value=e.rate??1;const r=s.createGain();return r.gain.value=(e.volume??1)*this.volume,n.connect(r).connect(this.master),n.start(),()=>{try{n.stop()}catch{}}}tone(t,e=.25,s={}){const i=this.context();if(!(!i||!this.audible))try{const n=i.createOscillator(),r=i.createGain();n.type=s.type??"sine",n.frequency.setValueAtTime(t,i.currentTime),s.to&&n.frequency.exponentialRampToValueAtTime(s.to,i.currentTime+e),r.gain.setValueAtTime((s.volume??.12)*this.volume,i.currentTime),r.gain.exponentialRampToValueAtTime(.001,i.currentTime+e),n.connect(r).connect(this.master),n.start(),n.stop(i.currentTime+e)}catch{}}get audible(){return!this.muted&&!this.held}hold(){this.held=!0,this.ctx?.suspend().catch(()=>{})}release(){this.held=!1,this.ctx?.resume().catch(()=>{})}destroy(){this.ctx?.close().catch(()=>{}),this.ctx=null}},Cr={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}},ut=["high","medium","low"];function Ft(t){const e=Cr[t];return{name:t,...e,scale:s=>s<=0?0:Math.max(1,Math.round(s*e.particles))}}var Pr=t=>ut[Math.min(ut.indexOf(t)+1,ut.length-1)],Re=(t,e)=>{if(!t.length)return NaN;const s=[...t].sort((i,n)=>i-n);return s[Math.min(s.length-1,Math.max(0,Math.floor(e*(s.length-1)+.5)))]},Nr=12,Lr=t=>Ce(t,.5);function Ce(t,e=.1){const s=Re(t,e);if(!Number.isFinite(s))return 1e3/60;const i=[144,120,90,75,60,50,30];let n=60;for(const r of i)Math.abs(1e3/r-s)<Math.abs(1e3/n-s)&&(n=r);return 1e3/n}function Oi(t,e){const s=e.refresh!==void 0&&Number.isFinite(e.refresh)&&e.refresh>0?e.refresh:Ce(e.intervals),i=Re(e.intervals,.5),n=Re(e.intervals,.9),r=Re(e.cpu,.5);if(!Number.isFinite(i))return t==="canvas2d"?"low":"medium";const a=l=>l<=s*1.25,h=l=>!Number.isFinite(r)||r<s*l;return t==="canvas2d"?a(n)&&h(.25)?"medium":"low":a(n)&&h(.5)?"high":a(i)?"medium":"low"}function Ir(t,e){return t.length<30?!1:t.filter(i=>i>e*1.5).length/t.length>.5}var Ui="0.1.1",Or=720*3600*1e3,Ur=(t,e,s)=>`fabi-play.engine-tier:${Ui}:${t}:${e}:${s}`,Dr=(t,e,s)=>`fablee-engine-tier:${Ui}:${t}:${e}:${s}`;function Br(t,e,s=Date.now()){try{const i=JSON.parse(t?.getItem(e)??"null");if(i&&ut.includes(i.tier)&&typeof i.at=="number"&&s-i.at<Or)return typeof i.refresh=="number"&&i.refresh>0?{name:i.tier,refresh:i.refresh}:{name:i.tier}}catch{}return null}function Di(t,e,s,i,n=Date.now()){try{t?.setItem(e,JSON.stringify(i!==void 0&&Number.isFinite(i)?{tier:s,at:n,refresh:i}:{tier:s,at:n}))}catch{}}function zr(t=typeof location<"u"?location.search:""){const e=new URLSearchParams(t).get("tier");return ut.includes(e)?e:void 0}function Bi(t,e){const s=e?.tier;if(ut.includes(s))return t==="canvas2d"&&s==="high"?"medium":s}var zi=t=>typeof t?.hz=="number"&&t.hz>=20&&t.hz<=240?Ce([1e3/t.hz],.5):NaN,Gi=(t,e)=>ut.indexOf(t)>=ut.indexOf(e)?t:e;function Gr(t,e,s){return t?{name:t,from:"forced"}:e?{name:s?Gi(e,s):e,from:"hint"}:s?{name:s,from:"cache"}:null}var Xr=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,Xi=class{constructor(t={}){c(this,"steps",[]),c(this,"labels",new Map),c(this,"end",0),c(this,"prevStart",0),c(this,"elapsed",0),c(this,"iter",0),c(this,"last",0),c(this,"delayLeft"),c(this,"_paused"),c(this,"done",!1),c(this,"rewinding",!1),c(this,"promise"),c(this,"resolve"),c(this,"repeat"),c(this,"yoyo"),c(this,"onComplete"),this.repeat=Math.floor(t.repeat??0),this.yoyo=!!t.yoyo,this.delayLeft=t.delay??0,this._paused=!!t.paused,this.onComplete=t.onComplete,this.promise=new Promise(e=>this.resolve=e)}get duration(){return this.end}get time(){return this.last}get paused(){return this._paused}get finished(){return this.done}at(t){if(t===void 0)return this.end;if(typeof t=="number")return Math.max(t,0);const e=Xr.exec(t);if(!e)throw new Error(`[engine] timeline: bad position "${t}"`);const[,s,i,n]=e,r=n?(i==="-"?-1:1)*Number(n):0;let a=this.end;if(s==="<")a=this.prevStart;else if(s&&s!==">"){const h=this.labels.get(s.trim());h===void 0?this.labels.set(s.trim(),this.end):a=h}return Math.max(a+r,0)}add(t){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>t.start;)e--;return this.steps.splice(e,0,t),this.prevStart=t.start,this.end=Math.max(this.end,t.start+t.dur),this}to(t,e,s,i="quadOut"){const n=typeof i=="object"?i:{ease:i},r=typeof n.ease=="function"?n.ease:jt[n.ease??"quadOut"];return this.add({target:t,to:e,from:null,fn:null,start:this.at(n.at)+(n.delay??0),dur:Math.max(s,0),ease:r,onUpdate:n.onUpdate,p:-1})}set(t,e,s){return this.add({target:t,to:e,from:null,fn:null,start:this.at(s),dur:0,ease:jt.linear,p:-1})}call(t,e){return this.add({target:null,to:null,from:null,fn:t,start:this.at(e),dur:0,ease:jt.linear,p:-1})}label(t,e){return this.labels.set(t,this.at(e)),this}wait(t){return this.end+=Math.max(t,0),this.prevStart=this.end,this}pause(){return this._paused=!0,this}resume(){return this._paused=!1,this}stop(){this.done||(this.done=!0,this.resolve())}seek(t){const e=Math.min(typeof t=="string"&&this.labels.has(t)?this.labels.get(t):this.at(t),this.end),s=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(s?this.end-e:e),this.render(e),this}then(t,e){return this.promise.then(t,e)}update(t){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=t,this.delayLeft>0)return;t=-this.delayLeft,this.delayLeft=0}const e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=t;const s=this.repeat<0?1/0:e*(this.repeat+1),i=Math.min(this.elapsed,s),n=i>=s?this.repeat:Math.floor(i/e);for(;this.iter<n;){const a=this.yoyo&&this.iter%2===1;this.render(a?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}const r=i-n*e;this.render(this.yoyo&&n%2===1?e-r:r),i>=s&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(t){const e=this.steps;if(t>=this.last)for(let s=0;s<e.length;s++){const i=e[s];t>=i.start&&this.apply(i,t)}else for(let s=e.length-1;s>=0;s--){const i=e[s];i.p>=0&&this.apply(i,t)}this.last=t}apply(t,e){const s=t.dur>0?Math.min(Math.max((e-t.start)/t.dur,0),1):e>t.start||e===t.start&&!this.rewinding?1:0;if(s===t.p)return;if(t.p=s,t.fn){this.rewinding||t.fn();return}const i=t.target;if(i.destroyed||i._free)return;const n=t.to;if(!t.from){t.from={};for(const a in n)t.from[a]=Number(i[a]??0)}const r=t.ease(s);for(const a in n)i[a]=t.from[a]+(n[a]-t.from[a])*r;t.onUpdate?.(r)}},$i=class{constructor(){c(this,"list",[]),c(this,"timelines",[])}timeline(t){const e=new Xi(t);return this.timelines.push(e),e}tween(t,e,s,i="quadOut"){const n=typeof i=="object"?i:{ease:i},r=typeof n.ease=="function"?n.ease:jt[n.ease??"quadOut"];let a;const h=new Promise(l=>{const o=Object.keys(e),u=new Float64Array(o.length);o.forEach((f,p)=>u[p]=Number(e[f])),a={target:t,keys:o,to:u,from:new Float64Array(o.length),started:!1,duration:Math.max(s,0),time:0,delay:n.delay??0,ease:r,onUpdate:n.onUpdate,done:l,dead:!1}});return this.list.push(a),Object.assign(h,{stop:()=>this.finish(a)})}stopAll(t){const e=this.list;for(let s=0;s<e.length;s++)e[s].target===t&&this.finish(e[s])}get size(){return this.list.length}update(t){if(this.timelines.length){let i=0;const n=this.timelines;for(let r=0;r<n.length;r++){const a=n[r];a.update(t),a.finished||(n[i++]=a)}n.length=i}const e=this.list;if(!e.length)return;let s=0;for(let i=0;i<e.length;i++){const n=e[i];n.dead||this.step(n,t),n.dead||(e[s++]=n)}s!==e.length&&(e.length=s)}step(t,e){if(t.target.destroyed)return this.finish(t);let s=e;if(t.delay>0){if(t.delay-=e,t.delay>0)return;s=-t.delay}const i=t.keys;if(!t.started){t.started=!0;for(let a=0;a<i.length;a++)t.from[a]=Number(t.target[i[a]]??0)}t.time+=s;const n=t.duration>0?Math.min(t.time/t.duration,1):1,r=t.ease(n);for(let a=0;a<i.length;a++)t.target[i[a]]=t.from[a]+(t.to[a]-t.from[a])*r;t.onUpdate?.(r),n>=1&&this.finish(t)}finish(t){t.dead||(t.dead=!0,t.done())}clear(){for(const t of this.list)this.finish(t);this.list.length=0;for(const t of this.timelines)t.stop();this.timelines=[]}},Y=720,qi=class extends Et{constructor(t,e){super(t),c(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},$r=class extends Et{constructor(t,e){super(t),c(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},bt=()=>performance.now();async function qr(t={}){const e=t.play??null;let s=t.canvas??null;s||(s=document.createElement("canvas"),s.style.cssText="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(s));let i=ms(s,{renderer:t.renderer??vr(),failIfMajorPerformanceCaveat:t.failIfMajorPerformanceCaveat,instancing:t.instancing});s=i.canvas;const n=new Set,r=new as(Math.min(2048,i.maxTextureSize),4);r.onPage=v=>n.add(v),r.onDrop=v=>{n.delete(v),v.texture&&i.destroyTexture(v.texture),v.texture=null};let a=Te(i);const h=new $i,l=new Ii,o=new xs(r),u=new Map,f=new Map,p=new Map,g=new Map,d=new Map,y=new Set;let m=0;const w=t.tier??zr(),x=String(i.info.renderer??""),_=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),M=typeof screen<"u"?`${screen.width}x${screen.height}`:"",k=Ur(i.kind,x,M);Fn(_,k,Dr(i.kind,x,M));const F=Br(_,k),R=Gr(w,Bi(i.kind,e?.device),F?.name);let N=R?.name??"medium",I=Ft(N);o.setTier(N);let D=R?.from==="hint",W=F?.name,X=F?.refresh??zi(e?.device),z=1,$t=1,ne=1;const Q={atlas:r,get pixelScale(){return z},get fontGen(){return m},get effects(){return I.effects},tweens:h,frame:v=>$e.frame(v),shape:v=>{const b=I.effects,T=b?z:-z;let E=u.get(T);E||(u.size>=8&&u.clear(),u.set(T,E=new hi(2e3)));const C=yt(v);let G=E.get(v,C);return(!G||!r.valid(G.frame))&&E.set(v,G=Li(r,Fr(v,b),z),C),G},bitmapFont:v=>$e.bitmapFont(v)};let rt=1280,kt=null;class Oa extends ns{get width(){return rt}set width(b){}get height(){return Y}set height(b){}get safe(){const b=Math.min(rt,Y*16/9);return{x:(rt-b)/2,y:0,w:b,h:Y}}}const at=new Oa(Q),At=()=>{const v=i.canvas,b=v.getBoundingClientRect();$t=Math.max(1,b.width||v.clientWidth||innerWidth),ne=Math.max(1,b.height||v.clientHeight||innerHeight),rt=Y*$t/ne;const T=Math.min(globalThis.devicePixelRatio||1,t.maxPixelRatio??2);if(ne*T/Y<=I.resolution){const C=Math.max(1,Math.round(ne*T));z=C/Y,i.resize(Math.max(1,Math.round($t*T)),C)}else z=I.resolution,i.resize(Math.round(rt*z),Math.round(Y*z));kt&&kt.style.setProperty("--unit",`${ne/Y}px`)};addEventListener("resize",At);const Ts=v=>{N=v,I=Ft(v),o.setTier(v),At()},Ie=typeof ResizeObserver<"u"?new ResizeObserver(At):null;Ie?.observe(s);let pt=e?.backdrop==="video"?"video":"none",$=e?.view??null,Ji=[],tn=-1/0,Oe=!1,re=!1;const Ss=new Set,en=()=>{const v=pt==="video"?"transparent":"";document.documentElement.style.background=v,document.body.style.background=v},sn=(v,b)=>{const T=v==="video"?"video":"none",E=b??null;if(!(T===pt&&(E===$||E&&$&&E.x===$.x&&E.y===$.y&&E.w===$.w&&E.h===$.h))){pt=T,$=E,en();for(const C of[...Ss])C(pt,$)}},nn=[];if(e){const v=E=>{Array.isArray(E)&&(Ji=E,tn=bt())},b=E=>{Oe=E,Ue()},T=E=>{if(w||D)return;Number.isFinite(X)||(X=zi(E));const C=Bi(i.kind,E);C&&(D=!0,Ts(W?Gi(C,W):C))};nn.push(e.on("start",E=>T(E?.device)),e.on("start",E=>{typeof E?.muted=="boolean"&&(l.muted=E.muted)}),e.on("frame",E=>v(E?.players)),e.on("players",E=>v(E?.players)),e.on("backdrop",E=>sn(E?.backdrop,E?.view)),e.on("start",E=>sn(E?.backdrop,E?.view??e.view)),e.on("pause",()=>b(!0)),e.on("resume",()=>b(!1)),e.on("break-start",()=>b(!0)),e.on("break-done",()=>b(!1)),e.on("break-end",()=>b(!1))),l.muted=e.muted===!0}en();const Ue=()=>Oe||re||document.hidden?l.hold():l.release();let rn=-1,Fs=[],Rs=0;const Cs=()=>bt()-tn<1e3?Ji:[],Ua=v=>e?e.toScreen(v):An($,v),De=()=>{if(rn===Rs)return Fs;rn=Rs;const v=pt==="video"||!e?.smoothedBody?()=>null:b=>e.smoothedBody(b);return Fs=Pi(Cs(),Ua,rt,Y,v),Fs},ae={x:0,y:0,w:1,h:1},Da=()=>(ae.x=$?$.x*rt:0,ae.y=$?$.y*Y:0,ae.w=$?$.w*rt:rt,ae.h=$?$.h*Y:Y,ae),Ba=v=>{const b=v.alpha??1,T=v.tags?new vs(r,v):null;T&&y.add(T);const E=typeof v.tags=="function"?v.tags:C=>String(C);return(C,G)=>{if(pt==="video")return;const L=Da();for(const O of Cs()){const j=e?.smoothedBody?.(O)??O.body,B=de(e?.avatarOf?.(O)??O.avatar??"")??pe;if(!o.draw(C.r,C.tex,j,B,L,b*G,z)||!T)continue;const st=E(O.id);st&&T.draw(C.r,C.tex,j,B,L,st,Ms(O.id),b*G,z,rt,Y)}}},Ps=new Set,Ns=new Set,oe=new Set;let Be=!1,Ls=0,qt=0,ze=0;const Rt={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0};let Ge=0,Is=0,Os=bt();const he=[];let Xe=0;const an=()=>({r:i,kernel:Q,tex:a});let on=an();const za=()=>{if(i.lost)return;const[v,b]=pt==="video"||t.background===void 0?[0,0]:ot(t.background);i.time=ze,i.maxBlur=I.maxBlur,i.begin(v,b,z),ct(at.world,null,at.x,at.y,at.rotation,at.scaleX,at.scaleY),Ks(on,at,at.alpha,at.tint);const T=i.end();Rt.drawCalls=T.drawCalls,Rt.quads=T.quads,Rt.filtersSkipped=T.filtersSkipped},hn=v=>{if(!Be)return;Ls=requestAnimationFrame(hn);const b=Math.min(Math.max((v-qt)/1e3,0),.1);qt&&he.push(v-qt),qt=v,Rs++;const T=bt(),E=Oe||re;if(!E){ze+=b,h.update(b);for(const C of oe)C.destroyed||C.update(b);for(const C of Ps)C(b,ze)}for(const C of Ns)C(b);at.sweep();for(const C of oe)C.destroyed&&oe.delete(C);if(i.lost?(Xe||(Xe=v),v-Xe>3e3&&Ga()):(Xe=0,za()),Ge++,Is+=bt()-T,T-Os>=1e3&&(Rt.fps=Math.round(Ge*1e3/(T-Os)),Rt.cpuMs=Math.round(Is/Math.max(Ge,1)*100)/100,e?.reportStats?.({fps:Rt.fps,renderer:i.kind,tier:N}),Ge=0,Is=0,Os=T),he.length>=180){const C=Number.isFinite(X)?X:Ce(he);!w&&!E&&Ir(he,C)&&N!=="low"&&(Ts(Pr(N)),W=N,Di(_,k,N,Number.isFinite(X)?X:void 0),console.info(`[engine] slow frames: tier ${N}`)),he.length=0}},Ga=()=>{const v=ys(i.canvas),b=ls(v);if(b){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),i.destroy(),i=b;for(const T of n)T.texture=null;for(const T of r.pages)n.add(T.surface);a=Te(i),on=an(),Ie?.disconnect(),Ie?.observe(v),At()}},ln=()=>{Ue(),document.hidden||(qt=0)};document.addEventListener("visibilitychange",ln);const cn=()=>{m++;for(const v of y)v.drop()};if(document.fonts?.addEventListener?.("loadingdone",cn),At(),!R&&t.probe!==!1&&(Number.isFinite(X)||(X=Lr(await Hr(Nr))),!D)){I=Ft("high"),At();const v=await Wr(i,r,()=>a,()=>z,rt,()=>D);if(v.refresh=X,!D){const b=Oi(i.kind,v);Di(_,k,b,X),W=b,Ts(b)}}const $e={stage:at,get tier(){return I},get renderer(){return i},get canvas(){return i.canvas},get pixelScale(){return z},get backdrop(){return pt},get view(){return $},get paused(){return Oe||re},sound:l,stats:Rt,get time(){return ze},get supports(){const v=i.support;return{filters:v.filters,blur:v.filters&&I.maxBlur>0,shaders:v.shaders,maxBlur:v.filters?I.maxBlur:0,tiers:{high:{maxBlur:Ft("high").maxBlur},medium:{maxBlur:Ft("medium").maxBlur},low:{maxBlur:Ft("low").maxBlur}}}},sprite:(v,b)=>new It(Q,v,b),shape:(v,b)=>new Zt(Q,v,b),text:(v,b)=>new se(Q,v,b),group:v=>new ns(Q).set(v??{}),particles(v,b={}){const T=typeof v=="object"&&"type"in v?Q.shape(v).frame:v,E=new si(Q,T,b),{max:C,blend:G,gravity:L,drag:O,...j}=b;return E.set(j),oe.add(E),E},tween:(v,b,T,E)=>h.tween(v,b,T,E),bake(v,b,T,E,C){return p.set(v,{w:b,h:T,draw:E,origin:C}),f.delete(v),$e.frame(v)},frame(v){const b=f.get(v);if(b&&r.valid(b)&&(b.gen===0||b.scale===z))return b;const T=p.get(v);if(T){const E=z,C=r.bake(T.w*E,T.h*E,G=>(G.scale(E,E),T.draw(G)),E,T.origin?.x??0,T.origin?.y??0);return f.set(v,C),C}if(b)return b;throw new Error(`[engine] no frame "${v}": load it or bake it first`)},async load(v){await Promise.all(Object.entries(v).map(([b,T])=>$a(b,T)))},hands:v=>v===void 0?De():De().filter(b=>b.player===v),touched(v,b,T={}){return v.updateWorld(),Ni(v,De(),b,T.padding??0)},hits(v,b,T,E=0){return v.updateWorld(),ks(v,b,T,E)},avatars:(v={})=>new qi(Q,Ba(v)),handMarkers(v={}){const b=v.radius??36,T=v.look??"auto",E=new Float64Array(6),C=Math.max(b*.12,3),G={type:"ring",r:b,lw:C,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},L={type:"ring",r:b,lw:C*1.8,stroke:ee,shadow:{color:ee,blur:b*.2}},O=(Ct,tt,Ht,Us,qe,Pt)=>{const He=tt.w/tt.scale;ct(E,null,Ht-He/2,Us-He/2,0,1,1),Ct.r.quad(Ct.tex(tt.surface),tt,E,He,He,qe,Pt,"normal")},j=Ct=>{let tt=null,Ht=!1;return()=>(tt&&r.valid(tt.frame)&&tt.frame.scale===z&&Ht===I.effects?tt:(Ht=I.effects,tt=Q.shape(Ct))).frame},B=j(G),st=j(L);return new $r(Q,(Ct,tt)=>{const Ht=T==="video"||T==="auto"&&pt==="video",Us=B(),qe=Ht?st():null;for(const Pt of De())qe&&O(Ct,qe,Pt.x,Pt.y,16777215,tt),O(Ct,Us,Pt.x,Pt.y,ot(Pt.color)[0],tt)})},timeline:v=>h.timeline(v),animation(v,b){const T=typeof v=="string"?Xa(v):{frames:v},E=new St(Q,T,b);return oe.add(E),E},bitmapFont(v,b){if(!b){const E=g.get(v);if(!E)throw new Error(`[engine] no bitmap font "${v}": load or make it first`);return E}const T="data"in b?fn(Fe(b.data),b.pages):_r(Q,b);return g.set(v,T),T},players:()=>Cs(),onFrame(v){return Ps.add(v),()=>{Ps.delete(v)}},onRender(v){return Ns.add(v),()=>{Ns.delete(v)}},onBackdrop(v){return Ss.add(v),()=>{Ss.delete(v)}},get hud(){return kt||(kt=document.createElement("div"),kt.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(kt),At()),kt},random:(v=0,b=1)=>v+Math.random()*(b-v),start(){Be||(Be=!0,qt=0,Ls=requestAnimationFrame(hn))},pause(){re=!0,Ue()},resume(){re=!1,Ue()},destroy(){Be=!1,cancelAnimationFrame(Ls),nn.forEach(v=>v()),removeEventListener("resize",At),Ie?.disconnect(),document.removeEventListener("visibilitychange",ln),document.fonts?.removeEventListener?.("loadingdone",cn),h.clear(),Hn(Q),l.destroy(),i.destroy(),kt?.remove()}};function Xa(v){const b=d.get(v);if(b)return b;const T=[...new Set([...f.keys(),...p.keys()])].filter(E=>E.startsWith(v)).sort(Yn);if(!T.length)throw new Error(`[engine] no animation or frames "${v}\u2026"`);return{frames:T}}async function $a(v,b){const T=b.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(T))return l.load(v,b);if(["woff","woff2","ttf","otf"].includes(T)){const L=new FontFace(v,`url(${b})`);document.fonts.add(await L.load()),m++;return}const E=new URL(b,location.href);if(T==="fnt")return un(v,Fe(await(await fetch(b)).text()),E);if(T==="json"){const L=await(await fetch(b)).json();if(Array.isArray(L.chars)&&!L.frames)return un(v,Fe(L),E);const O=await As(new URL(L.meta?.image??b.replace(/\.json$/,".png"),E).href);qa(v,L,ye(O));return}const C=await As(b),G=ye(C);n.add(G),f.set(v,{surface:G,x:0,y:0,w:C.width,h:C.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function fn(v,b){return Ar(v,b.map(T=>{const E=ye(T);return n.add(E),E}))}async function un(v,b,T){g.set(v,fn(b,await Promise.all(b.pages.map(E=>As(new URL(E,T).href)))))}function qa(v,b,T){n.add(T);const E=Array.isArray(b.frames)?b.frames:Object.entries(b.frames).map(([L,O])=>({...O,filename:L})),C=[],G=[];for(const L of E){const O=L.frame,j=L.filename.replace(Hi,"");L.rotated&&console.warn(`[engine] ${v}/${j} is rotated: export without rotation`);const B={surface:T,x:O.x,y:O.y,w:O.w,h:O.h,scale:1,gen:0,ox:0,oy:0,margin:0};L.trimmed&&L.sourceSize&&L.spriteSourceSize&&(B.sw=L.sourceSize.w,B.sh=L.sourceSize.h,B.tx=L.spriteSourceSize.x,B.ty=L.spriteSourceSize.y);const st=L.scale9Borders;st&&(B.slice=[st.y,(B.sw??O.w)-st.x-st.w,(B.sh??O.h)-st.y-st.h,st.x]),f.set(`${v}/${j}`,B),C.push(`${v}/${j}`),G.push((L.duration??0)/1e3)}for(const[L,O]of Object.entries(b.animations??{}))d.set(`${v}/${L}`,{frames:O.map(j=>`${v}/${j.replace(Hi,"")}`)});for(const L of b.meta?.frameTags??[]){const O=[];for(let B=L.from;B<=L.to;B++)O.push(B);L.direction==="reverse"&&O.reverse(),L.direction==="pingpong"&&O.push(...O.slice(1,-1).reverse());const j=O.every(B=>G[B]>0);d.set(`${v}/${L.name}`,{frames:O.map(B=>C[B]),...j?{durations:O.map(B=>G[B])}:{}})}}return $e}var Hi=/\.(png|webp|jpe?g|gif|bmp)$/i;function As(t){return new Promise((e,s)=>{const i=new Image;i.onload=()=>e(i),i.onerror=()=>s(new Error(`[engine] image did not load: ${t}`)),i.src=t})}function Hr(t){return new Promise(e=>{const s=[];let i=0;const n=r=>{i&&s.push(r-i),i=r,s.length<t?requestAnimationFrame(n):e(s)};requestAnimationFrame(n)})}async function Wr(t,e,s,i,n,r=()=>!1){const a=i(),h=Li(e,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},a).frame,l=[],o=[],u=new Float64Array(6),f=.004,p=t.kind==="canvas2d"?t.canvas.getContext("2d"):null,g=bt();let d=0;return await new Promise(y=>{const m=w=>{d&&w-g>250&&l.push(w-d),d=w;const x=bt();t.begin(0,0,a);const _=s();for(let M=0;M<300;M++){const k=w/1e3+M;ct(u,null,M*37%n,M*53%Y,k,1,1),t.quad(_(h.surface),h,u,h.w/a,h.h/a,16777215,f,"normal")}for(let M=0;M<40;M++)t.ellipse(100+M*20,300,20,14,M,16746496,f),t.stroke([100+M*20,400,120+M*20,460,100+M*20,520],3,18,3368703,f,!1);t.end(),p?.getImageData(0,0,1,1),w-g>250&&o.push(bt()-x),w-g<750&&!r()?requestAnimationFrame(m):(t.begin(0,0,a),t.end(),y())};requestAnimationFrame(m)}),{intervals:l,cpu:o}}var Yr=64,Wi=32,jr=0,Vr=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,Yi=new Set,ji=(t,e)=>{Yi.has(t)||(Yi.add(t),console.warn(e))},Qr=t=>new Kr(t),Kr=class{constructor(t){c(this,"r",t),c(this,"css","none"),c(this,"plans",new hi(Yr)),c(this,"buf",new Float64Array(64)),c(this,"keys",[]),c(this,"classes",new Map),c(this,"live",new Set),c(this,"svgs",new Map),c(this,"t",0),c(this,"cur",null),c(this,"svgFn",e=>this.svg(e)),c(this,"scr",[]),c(this,"flip",0)}chain(t,e){var s;const i=this.r;let n=this.buf;n[0]=i.scale,n[1]=i.maxBlur;let r=2;for(let d=0;d<e.length;d++){const y=e[d];if(r+22>n.length){const w=new Float64Array(n.length*2);w.set(n),n=this.buf=w}let m=this.classes.get(y.constructor);m===void 0&&this.classes.set(y.constructor,m=this.classes.size),n[r++]=m,n[r++]=y.enabled?1:0,y.params&&(r=y.params(n,r))}const a=(s=this.keys)[r]??(s[r]=new Float64Array(r));for(let d=0;d<r;d++)a[d]=n[d];const h=yt(a);let l=this.plans.get(a,h);l||this.plans.set(a,l=this.plan(e),h);for(let d=0;d<l.svgs.length;d++){const y=l.svgs[d];y.used<0&&this.attach(y),y.used=this.t}i.skipped+=l.skip;let o=t;const u=i.rx0,f=i.ry0,p=i.rx1-u,g=i.ry1-f;for(let d=0;d<l.paints.length;d++)l.parts[d]&&(o=this.bake(o,l.parts[d])),e[l.paints[d]].paint2d(o.getContext("2d"),u,f,p,g);return this.css=l.parts[l.paints.length]||"none",o}tick(){const t=++this.t;if(!(t%Wi||!this.live.size))for(const e of this.live)t-e.used>Wi&&this.detach(e)}destroy(){for(const t of this.live)this.detach(t);this.plans.clear()}svg(t){if(typeof document>"u"||!document.body)return null;const e=Array.from({length:20},(i,n)=>t[n]??0).join(" ");let s=this.svgs.get(e);if(!s){const i="http://www.w3.org/2000/svg",n=document.createElementNS(i,"svg");n.setAttribute("width","0"),n.setAttribute("height","0"),n.setAttribute("aria-hidden","true"),n.style.position="absolute";const r=document.createElementNS(i,"filter"),a=Vr+ ++jr;r.setAttribute("id",a),r.setAttribute("color-interpolation-filters","sRGB");const h=document.createElementNS(i,"feColorMatrix");h.setAttribute("type","matrix"),h.setAttribute("values",e),r.append(h),n.append(r),this.attach(s={key:e,id:a,el:n,used:this.t})}return this.cur.svgs.push(s),`url(#${s.id})`}attach(t){document.body.append(t.el),this.live.add(t),this.svgs.has(t.key)||this.svgs.set(t.key,t)}detach(t){t.el.remove(),t.used=-1,this.live.delete(t),this.svgs.get(t.key)===t&&this.svgs.delete(t.key)}plan(t){const e=this.r,s=this.cur={parts:[],paints:[],skip:0,svgs:[]};let i="";for(let n=0;n<t.length;n++){const r=t[n];if(!r.enabled)continue;if(r.kind===Je){s.skip++,ji("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}const a=e.support.filters&&r.css?r.css(e.scale,e.maxBlur,this.svgFn):null;a!==null?i+=i?` ${a}`:a:r.paint2d?(s.parts.push(i),s.paints.push(n),i=""):(s.skip++,ji("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return s.parts.push(i),s}bake(t,e){const s=this.r,i=this.flip^=1;let n=this.scr[i];(!n||n.width!==s.canvas.width||n.height!==s.canvas.height)&&(n=this.scr[i]=document.createElement("canvas"),n.width=s.canvas.width,n.height=s.canvas.height);const r=n.getContext("2d"),a=s.rx0,h=s.ry0,l=s.rx1-a,o=s.ry1-h;return r.clearRect(a,h,l,o),r.filter=e,r.drawImage(t,a,h,l,o,a,h,l,o),r.filter="none",n}},Zr=64,Pe=17,Jr=t=>`${gs}
|
|
49
49
|
uniform sampler2D uTexture;
|
|
50
50
|
uniform mat4 uM[${t}];
|
|
51
51
|
uniform vec4 uO[${t}];
|