@fabiplay/engine 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5104,7 +5104,7 @@ async function createEngine(opts = {}) {
5104
5104
  let canvas = opts.canvas ?? null;
5105
5105
  if (!canvas) {
5106
5106
  canvas = document.createElement("canvas");
5107
- canvas.style.cssText = "position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none";
5107
+ canvas.style.cssText = "position:fixed;top:0;left:0;width:100%;height:100%;display:block;touch-action:none";
5108
5108
  document.body.appendChild(canvas);
5109
5109
  }
5110
5110
  let renderer = createRenderer(canvas, {
@@ -5603,7 +5603,7 @@ async function createEngine(opts = {}) {
5603
5603
  get hud() {
5604
5604
  if (!hudEl) {
5605
5605
  hudEl = document.createElement("div");
5606
- hudEl.style.cssText = "position:fixed;inset:0;pointer-events:none;overflow:hidden";
5606
+ hudEl.style.cssText = "position:fixed;top:0;right:0;bottom:0;left:0;pointer-events:none;overflow:hidden";
5607
5607
  document.body.appendChild(hudEl);
5608
5608
  resize();
5609
5609
  }
package/dist/index.js CHANGED
@@ -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
- }`,Ki={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},Yi=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],Qi=["aPos","aUv","aColor","aSlot"];function Ls(s,r,e={}){let t={...Ki,failIfMajorPerformanceCaveat:e.failIfMajorPerformanceCaveat!==!1},n=r===2?s.getContext("webgl2",t):s.getContext("webgl",t)??s.getContext("experimental-webgl",t);if(!n||n.isContextLost())return null;try{return new Vr(s,n,r,e)}catch(i){return console.warn("[engine] WebGL setup failed:",i),n.getExtension("WEBGL_lose_context")?.loseContext(),null}}var Vr=class extends rt{constructor(e,t,n,i){super();h(this,"canvas",e);h(this,"gl",t);h(this,"opts",i);h(this,"kind");h(this,"maxTextureSize");h(this,"support",{filters:!0,shaders:!0});h(this,"features",{});h(this,"info",{});h(this,"lost",!1);h(this,"main");h(this,"cur");h(this,"unit",-1);h(this,"onUnit",new Array(_s).fill(void 0));h(this,"fbNow");h(this,"mapped",!0);h(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0});h(this,"vsrc","");h(this,"attrs",[]);h(this,"fxr",null);h(this,"batch");h(this,"dynamic");h(this,"staticBuf",null);h(this,"index");h(this,"vao",null);h(this,"inst",null);h(this,"vaoApi",null);h(this,"uScale",null);h(this,"textures",new Map);h(this,"kit");h(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0});h(this,"lostListeners",[]);h(this,"restoredListeners",[]);h(this,"tris",new Int32Array(192));h(this,"sU",0);h(this,"sV0",0);h(this,"sV1",0);h(this,"sColor",0);h(this,"sPacked",0);h(this,"sAlpha",0);h(this,"sHw",0);h(this,"strokeSeg",()=>{let e=this.q;e.set(kt),e[8]=e[10]=this.sU,e[9]=this.sV0,e[11]=this.sV1,e[12]=this.sPacked,this.put(this.kit)});h(this,"strokeDisc",()=>this.ellipse(kt[0],kt[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha));h(this,"q",new Float64Array(13));h(this,"layers",[]);h(this,"layerTex",new Map);h(this,"bScis",!1);h(this,"bx0",0);h(this,"by0",0);h(this,"bx1",0);h(this,"by1",0);h(this,"onContextLost",e=>{e.preventDefault(),this.lost=!0;for(let t of this.lostListeners)t()});h(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(let e of this.textures.keys())this.textures.set(e,this.upload(e.source));this.lost=!1;for(let e of this.restoredListeners)e()}catch(e){console.warn("[engine] WebGL restore failed:",e)}});h(this,"views",new Map);this.kind=n===2?"webgl2":"webgl1",this.maxTextureSize=t.getParameter(t.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(Fs()),re.live=this,e.addEventListener("webglcontextlost",this.onContextLost,!1),e.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){let e=this.gl,t=this.kind==="webgl2"?e:null;if(this.inst=null,this.opts.instancing!==!1)if(t)this.inst={divisor:(f,p)=>t.vertexAttribDivisor(f,p),draw:(f,p)=>t.drawElementsInstanced(e.TRIANGLES,f,e.UNSIGNED_SHORT,0,p)};else{let f=e.getExtension("ANGLE_instanced_arrays");f&&(this.inst={divisor:(p,b)=>f.vertexAttribDivisorANGLE(p,b),draw:(p,b)=>f.drawElementsInstancedANGLE(e.TRIANGLES,p,e.UNSIGNED_SHORT,0,b)})}if(this.vaoApi=null,this.opts.vao!==!1)if(t)this.vaoApi={create:()=>t.createVertexArray(),bind:f=>t.bindVertexArray(f),remove:f=>t.deleteVertexArray(f)};else{let f=e.getExtension("OES_vertex_array_object");f&&(this.vaoApi={create:()=>f.createVertexArrayOES(),bind:p=>f.bindVertexArrayOES(p),remove:p=>f.deleteVertexArrayOES(p)})}let n=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),i=Math.max(1,Math.min(_s,n)),o=this.inst!==null;this.vsrc=o?qi:ji,this.attrs=o?Yi:Qi,this.main=this.cur=this.build(Xi(i));let a=this.main.p;e.useProgram(a),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,e.uniform1iv(e.getUniformLocation(a,"uTex"),Int32Array.from({length:i},(f,p)=>p)),this.batch=new Zt(o,i),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic),e.bufferData(e.ARRAY_BUFFER,this.batch.f32.byteLength,e.DYNAMIC_DRAW),this.index=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.index),e.bufferData(e.ELEMENT_ARRAY_BUFFER,ms(o?1:8192),e.STATIC_DRAW);let l=f=>e.getAttribLocation(a,f),u=(f,p,b,y,m,d,x)=>{let v=l(f);v<0||(e.enableVertexAttribArray(v),e.vertexAttribPointer(v,p,b,y,m,d),this.inst&&this.inst.divisor(v,x))};if(o){let f=56;u("aP01",4,e.FLOAT,!1,f,0,1),u("aP23",4,e.FLOAT,!1,f,16,1),u("aUvRect",4,e.FLOAT,!1,f,32,1),u("aColor",4,e.UNSIGNED_BYTE,!0,f,48,1),u("aSlot",1,e.FLOAT,!1,f,52,1),this.staticBuf=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.staticBuf),e.bufferData(e.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),e.STATIC_DRAW),u("aCorner",4,e.FLOAT,!1,16,0,0),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic)}else{let f=24;u("aPos",2,e.FLOAT,!1,f,0,0),u("aUv",2,e.FLOAT,!1,f,8,0),u("aColor",4,e.UNSIGNED_BYTE,!0,f,16,0),u("aSlot",1,e.FLOAT,!1,f,20,0)}e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),e.disable(e.DEPTH_TEST),e.disable(e.CULL_FACE),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);let c=e.getExtension("WEBGL_debug_renderer_info");this.info={version:e.getParameter(e.VERSION),renderer:c?e.getParameter(c.UNMASKED_RENDERER_WEBGL):e.getParameter(e.RENDERER),vendor:c?e.getParameter(c.UNMASKED_VENDOR_WEBGL):e.getParameter(e.VENDOR)},this.features={instancing:o,vao:this.vaoApi!==null,textureSlots:i,maxTextureSize:this.maxTextureSize}}upload(e){let t=this.gl,n=t.createTexture();return this.bindTex(n),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),n}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){let t={id:gt(),width:e.width,height:e.height,source:e};return this.textures.set(t,this.lost?null:this.upload(e)),t}updateTexture(e,t,n=0,i=0){if(this.lost)return;this.batch.has(e)&&this.flush();let o=this.gl,a=this.textures.get(e);a&&(this.bindTex(a),!t||t===e.source&&n===0&&i===0?o.texImage2D(o.TEXTURE_2D,0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,e.source):o.texSubImage2D(o.TEXTURE_2D,0,n,i,o.RGBA,o.UNSIGNED_BYTE,t))}destroyTexture(e){this.batch.has(e)&&this.flush();let t=this.textures.get(e);t&&!this.lost&&this.deleteTex(t),this.textures.delete(e)}begin(e,t,n){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(n),this.bScis=!1,this.lost)return;let i=this.gl;i.disable(i.SCISSOR_TEST),this.bindFb(null),i.viewport(0,0,this.canvas.width,this.canvas.height);let o=t;i.clearColor((e>>16&255)/255*o,(e>>8&255)/255*o,(e&255)/255*o,o),i.clear(i.COLOR_BUFFER_BIT),this.use(this.main),i.uniform2f(this.uScale,2*n/this.canvas.width,-2*n/this.canvas.height),this.mapped=!0}build(e){let t=this.gl,n=Cs(t,t.VERTEX_SHADER,this.vsrc),i;try{i=Cs(t,t.FRAGMENT_SHADER,e)}catch(a){throw t.deleteShader(n),a}let o=t.createProgram();if(t.attachShader(o,n),t.attachShader(o,i),this.attrs.forEach((a,l)=>t.bindAttribLocation(o,l,a)),t.linkProgram(o),t.deleteShader(n),t.deleteShader(i),!t.getProgramParameter(o,t.LINK_STATUS)){let a=t.getProgramInfoLog(o)??"?";throw t.deleteProgram(o),new Error(`link: ${a}`)}return{p:o,uScale:t.getUniformLocation(o,"uScale"),locs:new Map}}u(e,t){let n=e.locs.get(t);return n===void 0&&e.locs.set(t,n=this.gl.getUniformLocation(e.p,t)),n}use(e){this.cur!==e&&(this.cur=e,this.gl.useProgram(e.p),this.calls.useProgram++)}bindTex(e,t=this.unit<0?0:this.unit){let n=this.gl;this.onUnit[t]!==e&&(this.unit!==t&&(n.activeTexture(n.TEXTURE0+t),this.calls.activeTexture++,this.unit=t),n.bindTexture(n.TEXTURE_2D,e),this.calls.bindTexture++,this.onUnit[t]=e)}deleteTex(e){this.gl.deleteTexture(e);for(let t=0;t<this.onUnit.length;t++)this.onUnit[t]===e&&(this.onUnit[t]=null)}bindFb(e){if(e)for(let n=0;n<this.onUnit.length;n++)this.onUnit[n]===e.gl&&this.bindTex(null,n);let t=e?e.fb:null;this.fbNow!==t&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,t),this.calls.bindFramebuffer++,this.fbNow=t)}slotOf(e){this.batch.full&&this.flush();let t=this.batch.slot(e);return t<0&&(this.flush(),t=this.batch.slot(e)),t}quad(e,t,n,i,o,a,l,u){B[0]=i,B[1]=o,B[2]=l,this.quadQ(e,t,n,a,u)}quadQ(e,t,n,i,o){let a=B[2];if(this.lost||a<=0)return;let l=this.q,u=B[0],c=B[1],f=n[4],p=n[5],b=n[0]*u,y=n[1]*u,m=n[2]*c,d=n[3]*c;l[0]=f,l[1]=p,l[2]=b+f,l[3]=y+p,l[4]=b+m+f,l[5]=y+d+p,l[6]=m+f,l[7]=d+p;let x=1/e.width,v=1/e.height;l[8]=t.x*x,l[9]=t.y*v,l[10]=(t.x+t.w)*x,l[11]=(t.y+t.h)*v,l[12]=Be(i,a,o==="add"),this.put(e)}put(e){if(this.mute)return;let t=this.q,n=!1,i=Math.min(t[0],t[2],t[4],t[6]),o=Math.max(t[0],t[2],t[4],t[6]),a=Math.min(t[1],t[3],t[5],t[7]),l=Math.max(t[1],t[3],t[5],t[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;let c=this.scale,f=this.px0/c,p=this.py0/c,b=this.px1/c,y=this.py1/c;if(o<=f||i>=b||l<=p||a>=y)return;if(i<f||o>b||a<p||l>y){let m=t[0],d=t[1],x=t[2],v=t[5];if(d===t[3]&&x===t[4]&&v===t[7]&&t[6]===m){if(m!==x){let k=Math.min(Math.max(m,f),b),w=Math.min(Math.max(x,f),b),M=t[8],S=(t[10]-M)/(x-m);t[10]=M+(w-m)*S,t[8]=M+(k-m)*S,t[0]=t[6]=k,t[2]=t[4]=w}if(d!==v){let k=Math.min(Math.max(d,p),y),w=Math.min(Math.max(v,p),y),M=t[9],S=(t[11]-M)/(v-d);t[11]=M+(w-d)*S,t[9]=M+(k-d)*S,t[1]=t[3]=k,t[5]=t[7]=w}}else n=!0}}let u=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(n?(!this.bScis||!u)&&(this.flush(),this.bScis=!0,this.bx0=this.px0,this.by0=this.py0,this.bx1=this.px1,this.by1=this.py1):this.bScis&&!(this.cOn&&u)&&(this.flush(),this.bScis=!1),this.real){let c=this.gq;c[0]=i,c[1]=a,c[2]=o,c[3]=l,this.growQ()}this.batch.pushQ(t,this.slotOf(e))}ellipse(e,t,n,i,o,a,l){if(this.lost||l<=0||n<=0||i<=0)return;let u=or[$r(Math.max(n,i)*2*this.scale,Es)],c=u.w/2/u.r,f=n*c,p=i*c,b=Math.cos(o),y=Math.sin(o),m=b*f,d=y*f,x=-y*p,v=b*p,k=1/256,w=this.q;w[0]=e-m-x,w[1]=t-d-v,w[2]=e+m-x,w[3]=t+d-v,w[4]=e+m+x,w[5]=t+d+v,w[6]=e-m+x,w[7]=t-d+v,w[8]=u.x*k,w[9]=u.y*k,w[10]=(u.x+u.w)*k,w[11]=(u.y+u.h)*k,w[12]=Be(a,l),this.put(this.kit)}polygon(e,t,n,i){if(this.lost||i<=0||t<3)return;this.tris.length<t*3&&(this.tris=new Int32Array(Math.max(t*3,this.tris.length*2)));let o=this.tris,a=Ss(e,t,o),l=Be(n,i),u=(Ae.x+Ae.w/2)/256,c=(Ae.y+Ae.h/2)/256;for(let f=0;f<a;f+=3){let p=o[f]*2,b=o[f+1]*2,y=o[f+2]*2,m=this.q;m[0]=e[p],m[1]=e[p+1],m[2]=e[b],m[3]=e[b+1],m[4]=m[6]=e[y],m[5]=m[7]=e[y+1],m[8]=m[10]=u,m[9]=m[11]=c,m[12]=l,this.put(this.kit)}}stroke(e,t,n,i,o,a){if(this.lost||o<=0||n<=0||t<1)return;let l=ar[$r(n*this.scale,Rs)],u=n/2*(l.h/2/l.r);this.sPacked=Be(i,o),this.sColor=i,this.sAlpha=o,this.sU=(l.x+l.w/2)/256,this.sV0=l.y/256,this.sV1=(l.y+l.h)/256,this.sHw=n/2,Ts(e,t,u,a,this.strokeSeg,this.strokeDisc)}target(e,t,n,i){let o=this.gl,a=o.createTexture();this.bindTex(a),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,e,t,0,o.RGBA,o.UNSIGNED_BYTE,null);let l=i?o.LINEAR:o.NEAREST;o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,l),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,l),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),this.bindTex(null);let u=o.createFramebuffer();o.bindFramebuffer(o.FRAMEBUFFER,u),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,a,0);let c=o.checkFramebufferStatus(o.FRAMEBUFFER)===o.FRAMEBUFFER_COMPLETE;if(this.fbNow=u,this.bindFb(this.parent()),!c)return this.deleteTex(a),o.deleteFramebuffer(u),null;let f={tex:{id:gt(),width:e,height:t,source:this.canvas},gl:a,fb:u,w:e,h:t,f:n};return this.layerTex.set(f.tex,a),f}drop(e){this.batch.has(e.tex)&&this.flush(),this.deleteTex(e.gl),this.gl.deleteFramebuffer(e.fb),this.layerTex.delete(e.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(e){let t=this.canvas.width,n=this.canvas.height,i=this.layers[e]??null;return i&&(i.w!==t||i.h!==n)&&(this.drop(i),i=this.layers[e]=null),i??(this.layers[e]=this.target(t,n,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();let e=this.layerAt(this.real);if(!e)return!1;let t=this.gl;return this.bindFb(e),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!re.gl?null:this.fxr??(this.fxr=re.gl(this))}composite(e,t,n,i){if(i&&this.filters()?.chain(e,n,i))return;let o=this.gl;t&&o.blendFunc(o.ZERO,o.SRC_ALPHA),this.final(this.main,e,1,n),t&&(this.flush(),o.blendFunc(o.ONE,o.ONE_MINUS_SRC_ALPHA))}final(e,t,n,i){let o=this.gl,a=this.canvas.width,l=this.canvas.height,u=this.scale;(e!==this.main||!this.mapped)&&(this.bindFb(this.parent()),o.viewport(0,0,a,l),this.use(e),o.uniform2f(e.uScale,2*u/a,-2*u/l),this.mapped=e===this.main);let c=this.rx0/u,f=this.ry0/u,p=this.rx1/u,b=this.ry1/u,y=1/(n*t.width),m=1/(n*t.height),d=this.q;d[0]=d[6]=c,d[1]=d[3]=f,d[2]=d[4]=p,d[5]=d[7]=b,d[8]=this.rx0*y,d[9]=1-this.ry0*m,d[10]=this.rx1*y,d[11]=1-this.ry1*m,d[12]=Be(16777215,i),this.put(t),e!==this.main&&this.flush()}remap(){let e=this.gl;this.bindFb(this.parent()),e.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),e.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(e){let t=this.gl,n=e.words;if(this.kind==="webgl2")return t.bufferSubData(t.ARRAY_BUFFER,0,e.f32,0,n);let i=this.views.get(n);i||(this.views.size>=256&&this.views.clear(),this.views.set(n,i=e.f32.subarray(0,n))),t.bufferSubData(t.ARRAY_BUFFER,0,i)}flush(){let e=this.batch;if(!e.quads||this.lost)return e.reset();let t=this.gl;this.bScis?(t.enable(t.SCISSOR_TEST),t.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):t.disable(t.SCISSOR_TEST),this.upload2(e);for(let n=0;n<e.bound;n++){let i=e.textures[n];this.bindTex(this.textures.get(i)??this.layerTex.get(i)??null,n)}this.inst?this.inst.draw(6,e.quads):t.drawElements(t.TRIANGLES,e.quads*6,t.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=e.quads,e.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){let e=this.gl;re.live===this&&(re.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(let t of this.textures.values())t&&e.deleteTexture(t);for(let t of this.layers)t&&(e.deleteTexture(t.gl),e.deleteFramebuffer(t.fb));this.fxr?.destroy(),this.fxr=null,e.deleteBuffer(this.dynamic),e.deleteBuffer(this.index),this.staticBuf&&e.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),e.deleteProgram(this.main.p),e.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function Cs(s,r,e){let t=s.createShader(r);if(s.shaderSource(t,e),s.compileShader(t),!s.getShaderParameter(t,s.COMPILE_STATUS)){let n=s.getShaderInfoLog(t)??"?";throw s.deleteShader(t),new Error(n)}return t}function Ps(s="auto"){switch(s){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function St(s,r={}){let e=s;for(let t of Ps(r.renderer)){let n=t==="canvas2d"?nt(e):Ls(e,t==="webgl2"?2:1,r);if(n)return n;e=Tt(e)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function Tt(s){let r=s.cloneNode(!1);return s.parentNode?.replaceChild(r,s),r}function Ns(s=typeof location<"u"?location.search:""){let r=new URLSearchParams(s).get("renderer");return r==="canvas"?"canvas2d":r==="webgl2"||r==="webgl1"||r==="canvas2d"||r==="webgl"||r==="auto"?r:void 0}import{frameOf as Zi}from"@fabiplay/sdk/avatars";var $e=class{constructor(r,e={}){h(this,"atlas",r);h(this,"tags",new Map);h(this,"count",0);h(this,"m",ge());h(this,"measure",null);h(this,"height");h(this,"font");this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(let r of this.tags.values())for(let e of r.values())for(let t of e.values())this.atlas.release(t);this.tags.clear(),this.count=0}get(r,e,t){let n=this.tags.get(r);n||this.tags.set(r,n=new Map);let i=n.get(e);i||n.set(e,i=new Map);let o=i.get(t);return o&&this.atlas.valid(o)?o:this.bake(r,e,t)}bake(r,e,t){let n=this.height,i=`700 ${Math.round(n*.65)}px ${this.font}`,o=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));o.font=i;let a=Math.round(n*.4),l=Math.ceil(o.measureText(r).width)+a*2,u=this.atlas.bake((l+2)*t,(n+2)*t,p=>{p.scale(t,t),p.translate(1,1);let b=n/2;p.beginPath(),p.moveTo(b,0),p.lineTo(l-b,0),p.arc(l-b,b,b,-Math.PI/2,Math.PI/2),p.lineTo(b,n),p.arc(b,b,b,Math.PI/2,Math.PI*3/2),p.closePath(),p.fillStyle=e,p.fill(),p.fillStyle="#fff",p.font=i,p.textAlign="center",p.textBaseline="middle",p.fillText(r,l/2,n/2+1)},t,1,1,1);++this.count>64&&(this.drop(),this.count=1);let c=this.tags.get(r);c||this.tags.set(r,c=new Map);let f=c.get(e);return f||c.set(e,f=new Map),f.set(t,u),u}draw(r,e,t,n,i,o,a,l,u,c,f){let p=Zi(t,i,{band:Ji(n)});if(!p)return;let b=this.height,y=this.get(o,a,u),m=y.w/y.scale-2,d=Math.min(Math.max(p.head.x-m/2,4),c-m-4),x=Math.min(Math.max(p.head.y-p.headR*2.2-b,4),f-b-4);te(this.m,null,d-1,x-1,0,1,1),r.quad(e(y.surface),y,this.m,y.w/y.scale,y.h/y.scale,16777215,l,"normal")}},Ji=s=>s.band==="3-5"||s.band==="9-12"?s.band:"6-8";var no=(s,r=!1)=>r?Math.min(2**Math.round(Math.log2(Math.max(s,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(s,8))*2)/2),512);function jr(s,r=null){let e={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},t=(n,i,o)=>{let a=r?r[0]*n+r[2]*i+r[4]:n,l=r?r[1]*n+r[3]*i+r[5]:i,u=r?Math.hypot(r[0],r[1]):1;e.minX=Math.min(e.minX,a-o*u),e.minY=Math.min(e.minY,l-o*u),e.maxX=Math.max(e.maxX,a+o*u),e.maxY=Math.max(e.maxY,l+o*u)};for(let n of s){let i="lw"in n&&n.stroke?(n.lw??1)/2:0;switch(n.k){case"circle":t(n.x-n.r,n.y-n.r,i),t(n.x+n.r,n.y+n.r,i),t(n.x-n.r,n.y+n.r,i),t(n.x+n.r,n.y-n.r,i);break;case"ellipse":case"rect":{let o=n.k==="ellipse"?Math.max(n.rx,n.ry):Math.hypot(n.w,n.h)/2;t(n.x-o,n.y-o,i),t(n.x+o,n.y+o,i),t(n.x-o,n.y+o,i),t(n.x+o,n.y-o,i);break}case"path":{let o=ir(n.d);for(let a=0;a<o.count;a++){let l=o.subs[a];for(let u=0;u<l.n;u++)t(l.pts[u*2],l.pts[u*2+1],i)}break}case"line":for(let o=0;o+1<n.pts.length;o+=2)t(n.pts[o],n.pts[o+1],i);break;case"group":{let o=te(ge(),r,n.x,n.y,n.rot??0,n.s??1,n.s??1),a=jr(n.items,o);Number.isFinite(a.minX)&&(e.minX=Math.min(e.minX,a.minX),e.minY=Math.min(e.minY,a.minY),e.maxX=Math.max(e.maxX,a.maxX),e.maxY=Math.max(e.maxY,a.maxY));break}}}return e}var at=class{constructor(r){h(this,"atlas",r);h(this,"seen",new WeakSet);h(this,"baked",new WeakMap);h(this,"m",ge());h(this,"stack",[]);h(this,"local",ge());h(this,"pts",new Float64Array(128));h(this,"stats",{baked:0,vector:0});h(this,"bakeGroups",!0);h(this,"coarse",!1);h(this,"gen",0);h(this,"live",new Set)}setTier(r){let e=r==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(let t of this.live)this.atlas.release(t.frame);this.live.clear()}}draw(r,e,t,n,i,o,a){let l=typeof n=="string"?Wr(n)??Xr:n,u=eo(t,l,i);return u.length?(o<=0||(o<1?(this.paint(r,e,u,null,r.beginLayer()?1:o,a),r.endLayer(o)):this.paint(r,e,u,null,o,a)),!0):!1}paint(r,e,t,n,i,o,a=0){var l;for(let u=0;u<t.length;u++){let c=t[u];if(c.k==="group"){let v=te((l=this.stack)[a]??(l[a]=ge()),n,c.x,c.y,c.rot??0,c.s??1,c.s??1),k=i*(c.alpha??1);if(this.bakeGroups&&this.seen.has(c.items)){let w=pe(v[0],v[1])*o,M=this.bake(c.items,w);if(M){let S=M.frame,_=this.m;_.set(v),_[4]=v[0]*-M.ox+v[2]*-M.oy+v[4],_[5]=v[1]*-M.ox+v[3]*-M.oy+v[5],r.quad(e(S.surface),S,_,S.w/M.k,S.h/M.k,16777215,k,"normal"),this.stats.baked++;continue}}this.seen.add(c.items),this.stats.vector++,this.paint(r,e,c.items,v,k,o,a+1);continue}let f=i*(c.alpha??1),p=n?pe(n[0],n[1]):1,b=n?Math.atan2(n[1],n[0]):0,y=(c.lw??1)*p,m=c.stroke&&(c.lw??1)>0?Y(c.stroke):null,d=c.fill&&c.k!=="line"?Y(c.fill):null;if(c.k==="circle"||c.k==="ellipse"){let v=n?n[0]*c.x+n[2]*c.y+n[4]:c.x,k=n?n[1]*c.x+n[3]*c.y+n[5]:c.y,w=(c.k==="circle"?c.r:c.rx)*p,M=(c.k==="circle"?c.r:c.ry)*p,S=(c.k==="ellipse"?c.rot??0:0)+b;if(d&&m)r.ellipse(v,k,w+y/2,M+y/2,S,m[0],f*m[1]),r.ellipse(v,k,Math.max(w-y/2,0),Math.max(M-y/2,0),S,d[0],f*d[1]);else if(d)r.ellipse(v,k,w,M,S,d[0],f*d[1]);else if(m){let _=Math.min(Math.max(Math.ceil(Math.max(w,M)*o*.6),12),64),C=this.pts=sr(this.pts,_*2),P=Math.cos(S),z=Math.sin(S);for(let H=0;H<_;H++){let U=H/_*Math.PI*2,D=Math.cos(U)*w,be=Math.sin(U)*M;C[H*2]=v+D*P-be*z,C[H*2+1]=k+D*z+be*P}r.stroke(C,_,y,m[0],f*m[1],!0)}continue}if(c.k==="line"){if(!m)continue;let v=c.pts.length>>1,k=this.pts=sr(this.pts,v*2);for(let w=0;w<v;w++){let M=c.pts[w*2],S=c.pts[w*2+1];k[w*2]=n?n[0]*M+n[2]*S+n[4]:M,k[w*2+1]=n?n[1]*M+n[3]*S+n[5]:S}r.stroke(k,v,y,m[0],f*m[1],!1);continue}let x=c.k==="path"?ir(c.d,n,p*o):so(c,te(this.local,n,c.x,c.y,c.rot??0,1,1),o*p);for(let v=0;v<x.count;v++){let k=x.subs[v],w=k.n,M=c.k==="rect"||k.closed;d&&w>=3&&(r.polygon(k.pts,w,d[0],f*d[1]),m||r.stroke(k.pts,w,1/o,d[0],f*d[1],!0)),m&&r.stroke(k.pts,w,y,m[0],f*m[1],M)}}}bake(r,e){let t=no(e,this.coarse),n=this.baked.get(r),i=n?.get(t);if(i&&i.gen===this.gen&&this.atlas.valid(i.frame))return i;i&&this.live.delete(i);let o=jr(r);if(!Number.isFinite(o.minX))return null;let a=2/t,l=(o.maxX-o.minX+a*2)*t,u=(o.maxY-o.minY+a*2)*t;if(l>1024||u>1024)return null;let c=-o.minX+a,f=-o.minY+a,b={frame:this.atlas.bake(l,u,y=>{y.scale(t,t),y.translate(c,f),Os(y,r)}),k:t,ox:c,oy:f,gen:this.gen};return n||this.baked.set(r,n=new Map),n.set(t,b),this.live.add(b),b}},it=new Array(36).fill(0),ot=0,de=(s,r=NaN,e=NaN,t=NaN,n=NaN)=>{it[ot++]=s,s!==Z.Z&&(it[ot++]=r,it[ot++]=e,s===Z.Q&&(it[ot++]=t,it[ot++]=n))};function so(s,r,e){let t=Math.max(0,Math.min(s.r,s.w/2,s.h/2)),n=-s.w/2,i=-s.h/2,{M:o,L:a,Q:l,Z:u}=Z;return ot=0,de(o,n+t,i),de(a,n+s.w-t,i),de(l,n+s.w,i,n+s.w,i+t),de(a,n+s.w,i+s.h-t),de(l,n+s.w,i+s.h,n+s.w-t,i+s.h),de(a,n+t,i+s.h),de(l,n,i+s.h,n,i+s.h-t),de(a,n,i+t),de(l,n,i,n+t,i),de(u),ir(it,r,e)}function io(s,r={}){let e=St(s,r),t=new ze(Math.min(1024,e.maxTextureSize),2);t.onDrop=S=>{S.texture&&e.destroyTexture(S.texture),S.texture=null};let n=new at(t),i=()=>{let S=new ro;return r.local&&S.setLocal(!0),S},o=i(),a=new Map,l=1e6,u=r.smooth===!1?1:typeof r.smooth=="number"?Math.min(Math.max(r.smooth,.05),1):o.defaultAmount,c=Mt(e),f=new $e(t,r),p={w:1,h:1},b=1,y=0,m=!1,d=()=>f.drop(),x=typeof document<"u"?document.fonts:void 0;x?.ready?.then(()=>{m||d()}),x?.addEventListener?.("loadingdone",d);let v=()=>{let S=Tt(e.canvas),_=nt(S);if(_){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),e.destroy(),e=_;for(let C of t.pages)C.surface.texture=null;c=Mt(e),y=0}},k=()=>{if(!e.lost)return y=0,!0;let S=performance.now();return y||(y=S),S-y>3e3&&v(),!e.lost},w=()=>{let S=e.canvas;r.units?(b=r.pixelRatio??1,p.w=r.units.width,p.h=r.units.height):(b=r.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),p.w=S.clientWidth||S.width/b,p.h=S.clientHeight||S.height/b),e.resize(Math.max(1,Math.round(p.w*b)),Math.max(1,Math.round(p.h*b))),e.begin(0,0,b)},M=(S,_)=>{if(S.key===void 0)return S.id??_+1;let C=a.get(S.key);return C===void 0&&(a.size>256&&a.clear(),a.set(S.key,C=l++)),C};return{get renderer(){return e},get kind(){return e.kind},get lost(){return e.lost},get canvas(){return e.canvas},draw(S,_){if(k()){w();for(let C=0;C<S.length;C++){let P=S[C];if(!Array.isArray(P.body))continue;let z=M(P,C),H=u<1||r.interpolate!==!1?o.posed(z,P.body,u,r.interpolate!==!1):P.body,U=Wr(P.avatar??"")??Xr,D=P.alpha??1;!n.draw(e,c,H,U,_,D,b)||!P.name||f.draw(e,c,H,U,_,P.name,P.color??"#6FA0E0",D,b,p.w,p.h)}e.end()}},clear(){k()&&(w(),e.end())},reset(){o=i(),a.clear()},destroy(){m=!0,x?.removeEventListener?.("loadingdone",d),e.destroy()}}}var ur=new Map;function oo(s,r,e=Math.min(globalThis.devicePixelRatio||1,2)){let t=`${s}|${r}|${e}`,n=ur.get(t);if(n)return n;n=document.createElement("canvas"),n.width=n.height=Math.round(r*e);let i=n.getContext("2d");return i.scale(e,e),i.beginPath(),i.rect(0,0,r,r),i.clip(),Os(i,to(Wr(s)??Xr,r)),ur.size>64&&ur.clear(),ur.set(t,n),n}function Mt(s){return r=>{if(r.texture||(r.texture=s.createTexture(r.source),r.pending.length=0),r.pending.length){for(let[e,t,n]of r.pending)s.updateTexture(r.texture,e,t,n);r.pending.length=0}return r.texture}}var Is='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',lt="rgba(10,16,30,0.75)";function qr(s,r){let e=s.size??40,t=s.outline?s.outline===!0?lt:s.outline:null,n=t?s.outlineWidth??Math.max(e*.12,3):0,i=s.shadow&&r?s.shadow===!0?lt:s.shadow:null,o=i?s.shadowBlur??e*.25:0;return{size:e,font:s.font??Is,weight:s.weight??700,color:s.color??"#FBEFE3",outline:t,ow:n,shadow:i,blur:o,pad:n/2+o*1.2+2,th:e*1.25}}var Bs=(s,r)=>`${s.weight} ${s.size*r}px ${s.font}`;function Kr(s,r,e,t,n,i){s.scale(t,t),s.font=Bs(e,1),s.textBaseline="middle",s.textAlign="left",s.lineJoin="round",e.shadow&&(s.shadowColor=e.shadow,s.shadowBlur=e.blur*t),e.outline&&(s.strokeStyle=e.outline,s.lineWidth=e.ow,s.strokeText(r,n,i),s.shadowColor="transparent"),s.fillStyle=e.color,s.fillText(r,n,i)}var cr=null;function Yr(s,r,e){return cr??(cr=document.createElement("canvas").getContext("2d")),cr.font=Bs(r,e),cr.measureText(s).width/e}var ke=class extends oe{constructor(e,t,n={}){super(e,null);h(this,"_text");h(this,"_style");h(this,"dirty",!0);h(this,"bakedScale",0);h(this,"bakedFontGen",-1);h(this,"bakedEffects",!0);h(this,"capW",0);h(this,"capH",0);this._text=t;let{x:i,y:o,rotation:a,scale:l,scaleX:u,scaleY:c,alpha:f,visible:p,tint:b,blend:y,z:m,anchor:d,hitRadius:x,clip:v,mask:k,filters:w,...M}=n;this._style=M,this.bake(),this.set({x:i,y:o,rotation:a,scale:l,scaleX:u,scaleY:c,alpha:f,visible:p,tint:b,blend:y,z:m,hitRadius:x,clip:v,mask:k,filters:w}),d!==void 0&&(this.anchor=d)}get text(){return this._text}set text(e){let t=String(e);t!==this._text&&(this._text=t,this.dirty=!0)}get style(){return this._style}set style(e){this._style={...this._style,...e},this.dirty=!0}bitmap(){let e=this._style.bitmapFont;if(!e)return null;let t=typeof e=="string"?this.kernel.bitmapFont(e):e;if(this.autoAnchor){let n=this._style.align;this.anchorX=n==="left"?0:n==="right"?1:.5,this.anchorY=.5}return t}get naturalWidth(){let e=this.bitmap();return e?e.measure(this._text)*((this._style.size??e.size)/e.size):super.naturalWidth}get naturalHeight(){let e=this.bitmap();return e?e.lineHeight*((this._style.size??e.size)/e.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(e,t,n){let i=this.bitmap();if(!i)return super.draw(e,t,n);let o=(this._style.size??i.size)/i.size,a=i.measure(this._text)*o,l=i.lineHeight*o,u=this.width,c=this.height,f=a>0?u/a:1,p=l>0?c/l:1;i.run(this._text,e,this.world,-this.anchorX*u,-this.anchorY*c,o*f,o*p,n,t,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){let e=this.kernel;if(this._style.bitmapFont)return null;let t=e.pixelScale,n=e.effects;return!this.dirty&&t===this.bakedScale&&e.fontGen===this.bakedFontGen&&n===this.bakedEffects&&e.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){let e=this.kernel,t=e.pixelScale,n=e.effects;this.dirty=!1,this.bakedScale=t,this.bakedFontGen=e.fontGen,this.bakedEffects=n;let i=qr(this._style,n),{pad:o,th:a}=i,l=Yr(this._text,i,t),u=(l+o*2)*t,c=(a+o*2)*t,f=this._style.align??"center",p=f==="left"?o:f==="right"?o+l:o+l/2,b=d=>Kr(d,this._text,i,t,o,o+a/2),y=this._frame,m=null;return y&&e.atlas.valid(y)&&y.scale===t&&(m=e.atlas.rebake(y,u,c,b,this.capW,this.capH),m?Object.assign(m,{ox:p,oy:o+a/2,margin:o}):e.atlas.release(y)),m||(this.capW=Math.ceil(u*1.25+16),this.capH=Math.ceil(c),m=e.atlas.bake(this.capW,this.capH,b,t,p,o+a/2,o),m.w=Math.ceil(u),m.h=Math.ceil(c)),this._frame=m,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,m}};var X=(s,r=0)=>{let e=Number(s);return Number.isFinite(e)?e:r};function Rt(s){typeof s=="string"&&/^\s*[{[]/.test(s)&&(s=JSON.parse(s));let r={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},e=(t,n)=>{t==="info"?r.size=Math.abs(X(n.size)):t==="common"?(r.lineHeight=X(n.lineHeight),r.base=X(n.base)):t==="page"?r.pages[X(n.id)]=String(n.file??""):t==="char"?r.chars.push({id:X(n.id),x:X(n.x),y:X(n.y),width:X(n.width),height:X(n.height),xoffset:X(n.xoffset),yoffset:X(n.yoffset),xadvance:X(n.xadvance),page:X(n.page)}):r.kernings.push({first:X(n.first),second:X(n.second),amount:X(n.amount)})};if(typeof s=="object"){let t=s;e("info",t.info??{}),e("common",t.common??{});for(let[n,i]of(t.pages??[]).entries())e("page",{id:n,file:i});for(let n of t.chars??[])e("char",n);for(let n of t.kernings??[])e("kerning",n)}else{let t=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,n=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let i=t.exec(s);i;i=t.exec(s)){let o={};for(let a=n.exec(i[2]);a;a=n.exec(i[2]))o[a[1]]=a[2]??a[3];e(i[1],o)}}return r.size||(r.size=r.lineHeight),r}var Et=class{constructor(r,e,t,n=null,i=null){h(this,"baker",n);h(this,"host",i);h(this,"size");h(this,"lineHeight");h(this,"base");h(this,"ascii",new Array(128));h(this,"more",new Map);h(this,"kern",new Map);h(this,"bScale",0);h(this,"bFontGen",-1);h(this,"bEffects",!1);h(this,"bGen",-1);this.size=r,this.lineHeight=e,this.base=t}set(r,e){r<128?this.ascii[r]=e:this.more.set(r,e)}setKerning(r,e,t){this.kern.set(r*1114112+e,t)}prepare(){let r=this.host;if(!(!r||r.pixelScale===this.bScale&&r.fontGen===this.bFontGen&&r.effects===this.bEffects&&r.atlas.gen===this.bGen)){this.bScale=r.pixelScale,this.bFontGen=r.fontGen,this.bEffects=r.effects,this.bGen=r.atlas.gen;for(let e of this.ascii)e&&r.atlas.release(e.frame);for(let e of this.more.values())e&&r.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(r){let e=r<128?this.ascii[r]:this.more.get(r);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(r):null,this.set(r,e)),e}kerning(r,e){return this.kern.size?this.kern.get(r*1114112+e)??0:0}measure(r){return this.run(r)}run(r,e,t,n=0,i=0,o=1,a=1,l=0,u=1,c="normal"){this.prepare();let f=0,p=-1;for(let b=0;b<r.length;b++){let y=r.charCodeAt(b);y>=55296&&y<56320&&b+1<r.length&&(y=r.codePointAt(b),b++),p>=0&&(f+=this.kerning(p,y)),p=y;let m=this.glyph(y);m&&(e&&m.w>0&&m.h>0&&(vt(t,n+(f+m.x)*o,i+m.y*a),e.r.quad(e.tex(m.frame.surface),m.frame,W,m.w*o,m.h*a,l,u,c)),f+=m.advance)}return f}};function Ds(s,r){let e=new Et(s.size,s.lineHeight,s.base);for(let t of s.chars){let n=r[t.page];if(!n)continue;let i={surface:n,x:t.x,y:t.y,w:t.width,h:t.height,scale:1,gen:0,ox:0,oy:0,margin:0};e.set(t.id,{frame:i,x:t.xoffset,y:t.yoffset,w:t.width,h:t.height,advance:t.xadvance})}for(let t of s.kernings)e.setKerning(t.first,t.second,t.amount);return e}function Gs(s,r){let e={...r},t=r.size??40,n=o=>{let a=String.fromCodePoint(o),l=s.pixelScale,u=qr(e,s.effects),c=Yr(a,u,l),f=s.atlas.bake((c+u.pad*2)*l,(u.th+u.pad*2)*l,p=>Kr(p,a,u,l,u.pad,u.pad+u.th/2),l);return{frame:f,x:-u.pad,y:-u.pad,w:f.w/l,h:f.h/l,advance:c}},i=new Et(t,t*1.25,t,n,s);i.prepare();for(let o of r.chars??"0123456789")i.glyph(o.codePointAt(0));return i}var ao=.5;function Us(s){let r=[];for(let[e,t]of[["left",ee.leftWrist],["right",ee.rightWrist]]){let n=s[t*3],i=s[t*3+1],o=s[t*3+2];n!==void 0&&i!==void 0&&Number.isFinite(n)&&Number.isFinite(i)&&(o??0)>=ao&&r.push({side:e,x:n,y:i})}return r}var Ft=s=>dt[((s-1)%dt.length+dt.length)%dt.length],lo=["left","right"];function Qr(s,r,e,t,n=()=>null,i={}){let o=[];for(let a of s){let l=n(a)??a.body;if(Array.isArray(l)){if(i.orientation==="portrait"){for(let u of lo){let c=$n(l,u,{orientation:"portrait"});i.hold&&(c=i.hold.at(je.key(a.id,u),c,i.t??0)),c&&o.push({player:a.id,side:u,x:c.x*e,y:c.y*t,color:Ft(a.id)})}continue}for(let u of Us(l)){let c=r(u);o.push({player:a.id,side:u.side,x:c.x*e,y:c.y*t,color:Ft(a.id)})}}}return o}function hr(s,r,e,t=0){let n=s.world,i=qn(n,r,e);if(!i)return!1;let o=Math.hypot(n[0],n[1])||1,a=Math.hypot(n[2],n[3])||1,[l,u]=i;if(s.hitRadius!=null){let y=s.hitRadius+t/((o+a)/2);return l*l+u*u<=y*y}let c=-s.anchorX*s.width-t/o,f=-s.anchorY*s.height-t/a,p=(1-s.anchorX)*s.width+t/o,b=(1-s.anchorY)*s.height+t/a;return l>=c&&l<=p&&u>=f&&u<=b}function Zr(s,r,e,t=0){for(let n of r)if((e===void 0||n.player===e)&&hr(s,n.x,n.y,t))return n;return null}function uo(s){switch(s.type){case"circle":case"ring":case"star":return[s.r*2,s.r*2];case"ellipse":return[s.rx*2,s.ry*2];case"roundRect":return[s.w,s.h];case"line":return[s.length,s.lw??4];case"path":return s.r?[s.r*2,s.r*2]:[s.size,s.size]}}function co(s){let r=s.type==="line"?0:s.stroke?(s.lw??2)/2:0,e=s.shadow?s.shadow.blur*1.5+Math.max(Math.abs(s.shadow.x??0),Math.abs(s.shadow.y??0)):0;return Math.ceil(r+e+1)}var Hs=(s,r)=>r||!s.shadow?s:{...s,shadow:void 0};function Jr(s,r,e){let t=co(r),n=r.type==="roundRect",[i,o]=n?[Math.min(r.w,r.r*2+4/e),Math.min(r.h,r.r*2+4/e)]:uo(r),a=(i+t*2)*e,l=(o+t*2)*e;return{frame:s.bake(a,l,c=>{c.scale(e,e),c.translate(t+i/2,t+o/2),ho(c,r,i,o)},e,t+i/2,t+o/2,t),slice:n?Math.ceil((r.r+t)*e):0,w:n?r.w:i,h:n?r.h:o}}function ho(s,r,e,t){s.lineJoin="round",s.lineCap="round";let n=new Path2D;switch(r.type){case"circle":case"ring":n.arc(0,0,r.r,0,Math.PI*2);break;case"ellipse":n.ellipse(0,0,r.rx,r.ry,0,0,Math.PI*2);break;case"roundRect":n.roundRect(-e/2,-t/2,e,t,Math.min(r.r,e/2,t/2));break;case"star":{let u=r.points??5,c=r.r*(r.inner??.5);for(let f=0;f<u*2;f++){let p=f%2?c:r.r,b=-Math.PI/2+f*Math.PI/u;f?n.lineTo(Math.cos(b)*p,Math.sin(b)*p):n.moveTo(Math.cos(b)*p,Math.sin(b)*p)}n.closePath();break}case"line":n.moveTo(-e/2+t/2,0),n.lineTo(e/2-t/2,0);break;case"path":{let u=r.r?r.r*2/r.size:1,c=new DOMMatrix([u,0,0,u,-r.size/2*u,-r.size/2*u]);n.addPath(new Path2D(r.d),c);break}}let i=r.shadow,o=()=>{if(!i)return;let u=s.getTransform();s.shadowColor=i.color,s.shadowBlur=i.blur*u.a,s.shadowOffsetX=(i.x??0)*u.a,s.shadowOffsetY=(i.y??0)*u.a},a=()=>{s.shadowColor="transparent",s.shadowBlur=0};if(r.type==="line"){o(),s.strokeStyle=r.stroke??r.fill??"#fff",s.lineWidth=t,s.stroke(n);return}let l=r.type==="ring";if(r.outlineBelow&&r.fill&&r.stroke&&!l){o(),s.strokeStyle=r.stroke,s.lineWidth=r.lw??2,s.stroke(n),a(),s.fillStyle=r.fill,s.fill(n);return}r.fill&&!l&&(o(),s.fillStyle=r.fill,s.fill(n),a()),(r.stroke||l)&&((!r.fill||l)&&o(),l&&r.fill&&(s.fillStyle=r.fill,s.fill(n)),s.strokeStyle=r.stroke??"#fff",s.lineWidth=r.lw??2,s.stroke(n),a())}var _t=class{constructor(){h(this,"ctx",null);h(this,"master",null);h(this,"buffers",new Map);h(this,"held",!1);h(this,"muted",!1);h(this,"volume",1);if(typeof addEventListener=="function"){let r=()=>{this.context()?.resume().catch(()=>{})};for(let e of["pointerdown","keydown","touchstart"])addEventListener(e,r,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;let r=globalThis.AudioContext??globalThis.webkitAudioContext;if(!r)return null;try{this.ctx=new r,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch{return null}return this.ctx}async load(r,e){let t=this.context();if(!t)return;let n=await(await fetch(e)).arrayBuffer();this.buffers.set(r,await t.decodeAudioData(n))}has(r){return this.buffers.has(r)}play(r,e={}){let t=this.context(),n=this.buffers.get(r);if(!t||!n||!this.audible)return()=>{};let i=t.createBufferSource();i.buffer=n,i.loop=e.loop??!1,i.playbackRate.value=e.rate??1;let o=t.createGain();return o.gain.value=(e.volume??1)*this.volume,i.connect(o).connect(this.master),i.start(),()=>{try{i.stop()}catch{}}}tone(r,e=.25,t={}){let n=this.context();if(!(!n||!this.audible))try{let i=n.createOscillator(),o=n.createGain();i.type=t.type??"sine",i.frequency.setValueAtTime(r,n.currentTime),t.to&&i.frequency.exponentialRampToValueAtTime(t.to,n.currentTime+e),o.gain.setValueAtTime((t.volume??.12)*this.volume,n.currentTime),o.gain.exponentialRampToValueAtTime(.001,n.currentTime+e),i.connect(o).connect(this.master),i.start(),i.stop(n.currentTime+e)}catch{}}get audible(){return!this.muted&&!this.held}hold(){this.held=!0,this.ctx?.suspend().catch(()=>{})}release(){this.held=!1,this.ctx?.resume().catch(()=>{})}destroy(){this.ctx?.close().catch(()=>{}),this.ctx=null}};var fo={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}},Se=["high","medium","low"];function Pe(s){let r=fo[s];return{name:s,...r,scale:e=>e<=0?0:Math.max(1,Math.round(e*r.particles))}}var zs=s=>Se[Math.min(Se.indexOf(s)+1,Se.length-1)],fr=(s,r)=>{if(!s.length)return NaN;let e=[...s].sort((t,n)=>t-n);return e[Math.min(e.length-1,Math.max(0,Math.floor(r*(e.length-1)+.5)))]},$s=12,Vs=s=>Ct(s,.5);function Ct(s,r=.1){let e=fr(s,r);if(!Number.isFinite(e))return 1e3/60;let t=[144,120,90,75,60,50,30],n=60;for(let i of t)Math.abs(1e3/i-e)<Math.abs(1e3/n-e)&&(n=i);return 1e3/n}function en(s,r){let e=r.refresh!==void 0&&Number.isFinite(r.refresh)&&r.refresh>0?r.refresh:Ct(r.intervals),t=fr(r.intervals,.5),n=fr(r.intervals,.9),i=fr(r.cpu,.5);if(!Number.isFinite(t))return s==="canvas2d"?"low":"medium";let o=l=>l<=e*1.25,a=l=>!Number.isFinite(i)||i<e*l;return s==="canvas2d"?o(n)&&a(.25)?"medium":"low":o(n)&&a(.5)?"high":o(t)?"medium":"low"}function Ws(s,r){return s.length<30?!1:s.filter(t=>t>r*1.5).length/s.length>.5}var Xs="0.1.1",po=720*3600*1e3,js=(s,r,e)=>`fabi-play.engine-tier:${Xs}:${s}:${r}:${e}`,qs=(s,r,e)=>`fablee-engine-tier:${Xs}:${s}:${r}:${e}`;function Ks(s,r,e=Date.now()){try{let t=JSON.parse(s?.getItem(r)??"null");if(t&&Se.includes(t.tier)&&typeof t.at=="number"&&e-t.at<po)return typeof t.refresh=="number"&&t.refresh>0?{name:t.tier,refresh:t.refresh}:{name:t.tier}}catch{}return null}function tn(s,r,e,t,n=Date.now()){try{s?.setItem(r,JSON.stringify(t!==void 0&&Number.isFinite(t)?{tier:e,at:n,refresh:t}:{tier:e,at:n}))}catch{}}function Ys(s=typeof location<"u"?location.search:""){let r=new URLSearchParams(s).get("tier");return Se.includes(r)?r:void 0}function rn(s,r){let e=r?.tier;if(Se.includes(e))return s==="canvas2d"&&e==="high"?"medium":e}var nn=s=>typeof s?.hz=="number"&&s.hz>=20&&s.hz<=240?Ct([1e3/s.hz],.5):NaN,sn=(s,r)=>Se.indexOf(s)>=Se.indexOf(r)?s:r;function Qs(s,r,e){return s?{name:s,from:"forced"}:r?{name:e?sn(r,e):r,from:"hint"}:e?{name:e,from:"cache"}:null}var mo=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,Lt=class{constructor(r={}){h(this,"steps",[]);h(this,"labels",new Map);h(this,"end",0);h(this,"prevStart",0);h(this,"elapsed",0);h(this,"iter",0);h(this,"last",0);h(this,"delayLeft");h(this,"_paused");h(this,"done",!1);h(this,"rewinding",!1);h(this,"promise");h(this,"resolve");h(this,"repeat");h(this,"yoyo");h(this,"onComplete");this.repeat=Math.floor(r.repeat??0),this.yoyo=!!r.yoyo,this.delayLeft=r.delay??0,this._paused=!!r.paused,this.onComplete=r.onComplete,this.promise=new Promise(e=>this.resolve=e)}get duration(){return this.end}get time(){return this.last}get paused(){return this._paused}get finished(){return this.done}at(r){if(r===void 0)return this.end;if(typeof r=="number")return Math.max(r,0);let e=mo.exec(r);if(!e)throw new Error(`[engine] timeline: bad position "${r}"`);let[,t,n,i]=e,o=i?(n==="-"?-1:1)*Number(i):0,a=this.end;if(t==="<")a=this.prevStart;else if(t&&t!==">"){let l=this.labels.get(t.trim());l===void 0?this.labels.set(t.trim(),this.end):a=l}return Math.max(a+o,0)}add(r){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>r.start;)e--;return this.steps.splice(e,0,r),this.prevStart=r.start,this.end=Math.max(this.end,r.start+r.dur),this}to(r,e,t,n="quadOut"){let i=typeof n=="object"?n:{ease:n},o=typeof i.ease=="function"?i.ease:Ge[i.ease??"quadOut"];return this.add({target:r,to:e,from:null,fn:null,start:this.at(i.at)+(i.delay??0),dur:Math.max(t,0),ease:o,onUpdate:i.onUpdate,p:-1})}set(r,e,t){return this.add({target:r,to:e,from:null,fn:null,start:this.at(t),dur:0,ease:Ge.linear,p:-1})}call(r,e){return this.add({target:null,to:null,from:null,fn:r,start:this.at(e),dur:0,ease:Ge.linear,p:-1})}label(r,e){return this.labels.set(r,this.at(e)),this}wait(r){return this.end+=Math.max(r,0),this.prevStart=this.end,this}pause(){return this._paused=!0,this}resume(){return this._paused=!1,this}stop(){this.done||(this.done=!0,this.resolve())}seek(r){let e=Math.min(typeof r=="string"&&this.labels.has(r)?this.labels.get(r):this.at(r),this.end),t=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(t?this.end-e:e),this.render(e),this}then(r,e){return this.promise.then(r,e)}update(r){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=r,this.delayLeft>0)return;r=-this.delayLeft,this.delayLeft=0}let e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=r;let t=this.repeat<0?1/0:e*(this.repeat+1),n=Math.min(this.elapsed,t),i=n>=t?this.repeat:Math.floor(n/e);for(;this.iter<i;){let a=this.yoyo&&this.iter%2===1;this.render(a?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}let o=n-i*e;this.render(this.yoyo&&i%2===1?e-o:o),n>=t&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(r){let e=this.steps;if(r>=this.last)for(let t=0;t<e.length;t++){let n=e[t];r>=n.start&&this.apply(n,r)}else for(let t=e.length-1;t>=0;t--){let n=e[t];n.p>=0&&this.apply(n,r)}this.last=r}apply(r,e){let t=r.dur>0?Math.min(Math.max((e-r.start)/r.dur,0),1):e>r.start||e===r.start&&!this.rewinding?1:0;if(t===r.p)return;if(r.p=t,r.fn){this.rewinding||r.fn();return}let n=r.target;if(n.destroyed||n._free)return;let i=r.to;if(!r.from){r.from={};for(let a in i)r.from[a]=Number(n[a]??0)}let o=r.ease(t);for(let a in i)n[a]=r.from[a]+(i[a]-r.from[a])*o;r.onUpdate?.(o)}};var Pt=class{constructor(){h(this,"list",[]);h(this,"timelines",[])}timeline(r){let e=new Lt(r);return this.timelines.push(e),e}tween(r,e,t,n="quadOut"){let i=typeof n=="object"?n:{ease:n},o=typeof i.ease=="function"?i.ease:Ge[i.ease??"quadOut"],a,l=new Promise(u=>{let c=Object.keys(e),f=new Float64Array(c.length);c.forEach((p,b)=>f[b]=Number(e[p])),a={target:r,keys:c,to:f,from:new Float64Array(c.length),started:!1,duration:Math.max(t,0),time:0,delay:i.delay??0,ease:o,onUpdate:i.onUpdate,done:u,dead:!1}});return this.list.push(a),Object.assign(l,{stop:()=>this.finish(a)})}stopAll(r){let e=this.list;for(let t=0;t<e.length;t++)e[t].target===r&&this.finish(e[t])}get size(){return this.list.length}update(r){if(this.timelines.length){let n=0,i=this.timelines;for(let o=0;o<i.length;o++){let a=i[o];a.update(r),a.finished||(i[n++]=a)}i.length=n}let e=this.list;if(!e.length)return;let t=0;for(let n=0;n<e.length;n++){let i=e[n];i.dead||this.step(i,r),i.dead||(e[t++]=i)}t!==e.length&&(e.length=t)}step(r,e){if(r.target.destroyed)return this.finish(r);let t=e;if(r.delay>0){if(r.delay-=e,r.delay>0)return;t=-r.delay}let n=r.keys;if(!r.started){r.started=!0;for(let a=0;a<n.length;a++)r.from[a]=Number(r.target[n[a]]??0)}r.time+=t;let i=r.duration>0?Math.min(r.time/r.duration,1):1,o=r.ease(i);for(let a=0;a<n.length;a++)r.target[n[a]]=r.from[a]+(r.to[a]-r.from[a])*o;r.onUpdate?.(o),i>=1&&this.finish(r)}finish(r){r.dead||(r.dead=!0,r.done())}clear(){for(let r of this.list)this.finish(r);this.list.length=0;for(let r of this.timelines)r.stop();this.timelines=[]}};var q=720,pr=class extends ue{constructor(e,t){super(e);h(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},an=class extends ue{constructor(e,t){super(e);h(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},Te=()=>performance.now(),Zs=s=>{let r=Wn(s);return r&&Object.freeze(r)};async function go(s={}){let r=s.play??null,e=s.canvas??null;e||(e=document.createElement("canvas"),e.style.cssText="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(e));let t=St(e,{renderer:s.renderer??Ns(),failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat,instancing:s.instancing});e=t.canvas;let n=new Set,i=new ze(Math.min(2048,t.maxTextureSize),4);i.onPage=g=>n.add(g),i.onDrop=g=>{n.delete(g),g.texture&&t.destroyTexture(g.texture),g.texture=null};let o=Mt(t),a=new Pt,l=new _t,u=new at(i),c=new Map,f=new Map,p=new Map,b=new Map,y=new Map,m=new Set,d=0,x=s.tier??Ys(),v=String(t.info.renderer??""),k=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),w=typeof screen<"u"?`${screen.width}x${screen.height}`:"",M=js(t.kind,v,w);Xn(k,M,qs(t.kind,v,w));let S=Ks(k,M),_=Qs(x,rn(t.kind,r?.device),S?.name),C=_?.name??"medium",P=Pe(C);u.setTier(C);let z=_?.from==="hint",H=S?.name,U=S?.refresh??nn(r?.device),D=1,be=1,Ee=1,K={atlas:i,get pixelScale(){return D},get fontGen(){return d},get effects(){return P.effects},tweens:a,frame:g=>$t.frame(g),shape:g=>{let A=P.effects,R=A?D:-D,E=c.get(R);E||(c.size>=8&&c.clear(),c.set(R,E=new tt(2e3)));let L=he(g),$=E.get(g,L);return(!$||!i.valid($.frame))&&E.set(g,$=Jr(i,Hs(g,A),D),L),$},bitmapFont:g=>$t.bitmapFont(g)},ae=1280,Re=null;class li extends Qe{get width(){return ae}set width(A){}get height(){return q}set height(A){}get safe(){let A=Math.min(ae,q*16/9);return{x:(ae-A)/2,y:0,w:A,h:q}}}let le=new li(K),Fe=()=>{let g=t.canvas,A=g.getBoundingClientRect();be=Math.max(1,A.width||g.clientWidth||innerWidth),Ee=Math.max(1,A.height||g.clientHeight||innerHeight),ae=q*be/Ee;let R=Math.min(globalThis.devicePixelRatio||1,s.maxPixelRatio??2);if(Ee*R/q<=P.resolution){let L=Math.max(1,Math.round(Ee*R));D=L/q,t.resize(Math.max(1,Math.round(be*R)),L)}else D=P.resolution,t.resize(Math.round(ae*D),Math.round(q*D));Re&&Re.style.setProperty("--unit",`${Ee/q}px`)};addEventListener("resize",Fe);let gr=g=>{C=g,P=Pe(g),u.setTier(g),Fe()},Nt=typeof ResizeObserver<"u"?new ResizeObserver(Fe):null;Nt?.observe(e);let ye=r?.backdrop==="video"?"video":"none",V=r?.view??null,Ot=r?.orientation==="portrait"?"portrait":"landscape",Rn=Zs(r?.safeArea)??Vn,Fn=[],_n=-1/0,It=!1,ut=!1,xr=new Set,Cn=()=>{let g=ye==="video"?"transparent":"";document.documentElement.style.background=g,document.body.style.background=g},Ln=(g,A)=>{let R=g==="video"?"video":"none",E=A??null;if(!(R===ye&&(E===V||E&&V&&E.x===V.x&&E.y===V.y&&E.w===V.w&&E.h===V.h))){ye=R,V=E,Cn();for(let L of[...xr])L(ye,V)}},Pn=[];if(r){let g=E=>{Array.isArray(E)&&(Fn=E,_n=Te())},A=E=>{It=E,Bt()},R=E=>{if(x||z)return;Number.isFinite(U)||(U=nn(E));let L=rn(t.kind,E);L&&(z=!0,gr(H?sn(L,H):L))};Pn.push(r.on("start",E=>R(E?.device)),r.on("start",E=>{(E?.orientation==="portrait"||E?.orientation==="landscape")&&(Ot=E.orientation);let L=Zs(E?.safeArea);L&&(Rn=L)}),r.on("start",E=>{typeof E?.muted=="boolean"&&(l.muted=E.muted)}),r.on("frame",E=>g(E?.players)),r.on("players",E=>g(E?.players)),r.on("backdrop",E=>Ln(E?.backdrop,E?.view)),r.on("start",E=>Ln(E?.backdrop,E?.view??r.view)),r.on("pause",()=>A(!0)),r.on("resume",()=>A(!1)),r.on("break-start",()=>A(!0)),r.on("break-done",()=>A(!1)),r.on("break-end",()=>A(!1))),l.muted=r.muted===!0}Cn();let Bt=()=>It||ut||document.hidden?l.hold():l.release(),Nn=-1,vr=[],wr=0,Ar=()=>Te()-_n<1e3?Fn:[],ui=g=>r?r.toScreen(g):Fr(V,g),ci=new je,Dt=()=>{if(Nn===wr)return vr;Nn=wr;let g=Ot==="portrait",A=ye==="video"&&!g||!r?.smoothedBody?()=>null:R=>r.smoothedBody(R);return vr=Qr(Ar(),ui,ae,q,A,g?{orientation:Ot,hold:ci,t:Te()}:void 0),vr},ct={x:0,y:0,w:1,h:1},hi=()=>(ct.x=V?V.x*ae:0,ct.y=V?V.y*q:0,ct.w=V?V.w*ae:ae,ct.h=V?V.h*q:q,ct),fi=g=>{let A=g.alpha??1,R=g.tags?new $e(i,g):null;R&&m.add(R);let E=typeof g.tags=="function"?g.tags:L=>String(L);return(L,$)=>{if(ye==="video")return;let O=hi();for(let I of Ar()){let j=r?.smoothedBody?.(I)??I.body,G=bo(r?.avatarOf?.(I)??I.avatar??"")??yo;if(!u.draw(L.r,L.tex,j,G,O,A*$,D)||!R)continue;let ie=E(I.id);ie&&R.draw(L.r,L.tex,j,G,O,ie,Ft(I.id),A*$,D,ae,q)}}},kr=new Set,Sr=new Set,ht=new Set,Gt=!1,Tr=0,We=0,Ut=0,Ne={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0},Ht=0,Mr=0,Er=Te(),ft=[],zt=0,On=()=>({r:t,kernel:K,tex:o}),In=On(),pi=()=>{if(t.lost)return;let[g,A]=ye==="video"||s.background===void 0?[0,0]:Y(s.background);t.time=Ut,t.maxBlur=P.maxBlur,t.begin(g,A,D),te(le.world,null,le.x,le.y,le.rotation,le.scaleX,le.scaleY),Dr(In,le,le.alpha,le.tint);let R=t.end();Ne.drawCalls=R.drawCalls,Ne.quads=R.quads,Ne.filtersSkipped=R.filtersSkipped},Bn=g=>{if(!Gt)return;Tr=requestAnimationFrame(Bn);let A=Math.min(Math.max((g-We)/1e3,0),.1);We&&ft.push(g-We),We=g,wr++;let R=Te(),E=It||ut;if(!E){Ut+=A,a.update(A);for(let L of ht)L.destroyed||L.update(A);for(let L of kr)L(A,Ut)}for(let L of Sr)L(A);le.sweep();for(let L of ht)L.destroyed&&ht.delete(L);if(t.lost?(zt||(zt=g),g-zt>3e3&&di()):(zt=0,pi()),Ht++,Mr+=Te()-R,R-Er>=1e3&&(Ne.fps=Math.round(Ht*1e3/(R-Er)),Ne.cpuMs=Math.round(Mr/Math.max(Ht,1)*100)/100,r?.reportStats?.({fps:Ne.fps,renderer:t.kind,tier:C}),Ht=0,Mr=0,Er=R),ft.length>=180){let L=Number.isFinite(U)?U:Ct(ft);!x&&!E&&Ws(ft,L)&&C!=="low"&&(gr(zs(C)),H=C,tn(k,M,C,Number.isFinite(U)?U:void 0),console.info(`[engine] slow frames: tier ${C}`)),ft.length=0}},di=()=>{let g=Tt(t.canvas),A=nt(g);if(A){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),t.destroy(),t=A;for(let R of n)R.texture=null;for(let R of i.pages)n.add(R.surface);o=Mt(t),In=On(),Nt?.disconnect(),Nt?.observe(g),Fe()}},Dn=()=>{Bt(),document.hidden||(We=0)};document.addEventListener("visibilitychange",Dn);let Gn=()=>{d++;for(let g of m)g.drop()};if(document.fonts?.addEventListener?.("loadingdone",Gn),Fe(),!_&&s.probe!==!1&&(Number.isFinite(U)||(U=Vs(await xo($s))),!z)){P=Pe("high"),Fe();let g=await vo(t,i,()=>o,()=>D,ae,()=>z);if(g.refresh=U,!z){let A=en(t.kind,g);tn(k,M,A,U),H=A,gr(A)}}let $t={stage:le,get tier(){return P},get renderer(){return t},get canvas(){return t.canvas},get pixelScale(){return D},get backdrop(){return ye},get view(){return V},get orientation(){return Ot},get safeArea(){return Rn},get paused(){return It||ut},sound:l,stats:Ne,get time(){return Ut},get supports(){let g=t.support;return{filters:g.filters,blur:g.filters&&P.maxBlur>0,shaders:g.shaders,maxBlur:g.filters?P.maxBlur:0,tiers:{high:{maxBlur:Pe("high").maxBlur},medium:{maxBlur:Pe("medium").maxBlur},low:{maxBlur:Pe("low").maxBlur}}}},sprite:(g,A)=>new oe(K,g,A),shape:(g,A)=>new ve(K,g,A),text:(g,A)=>new ke(K,g,A),group:g=>new Qe(K).set(g??{}),particles(g,A={}){let R=typeof g=="object"&&"type"in g?K.shape(g).frame:g,E=new wt(K,R,A),{max:L,blend:$,gravity:O,drag:I,...j}=A;return E.set(j),ht.add(E),E},tween:(g,A,R,E)=>a.tween(g,A,R,E),bake(g,A,R,E,L){return p.set(g,{w:A,h:R,draw:E,origin:L}),f.delete(g),$t.frame(g)},frame(g){let A=f.get(g);if(A&&i.valid(A)&&(A.gen===0||A.scale===D))return A;let R=p.get(g);if(R){let E=D,L=i.bake(R.w*E,R.h*E,$=>($.scale(E,E),R.draw($)),E,R.origin?.x??0,R.origin?.y??0);return f.set(g,L),L}if(A)return A;throw new Error(`[engine] no frame "${g}": load it or bake it first`)},async load(g){await Promise.all(Object.entries(g).map(([A,R])=>bi(A,R)))},hands:g=>g===void 0?Dt():Dt().filter(A=>A.player===g),touched(g,A,R={}){return g.updateWorld(),Zr(g,Dt(),A,R.padding??0)},hits(g,A,R,E=0){return g.updateWorld(),hr(g,A,R,E)},avatars:(g={})=>new pr(K,fi(g)),handMarkers(g={}){let A=g.radius??36,R=g.look??"auto",E=new Float64Array(6),L=Math.max(A*.12,3),$={type:"ring",r:A,lw:L,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},O={type:"ring",r:A,lw:L*1.8,stroke:lt,shadow:{color:lt,blur:A*.2}},I=(Oe,J,Xe,Rr,Vt,Ie)=>{let Wt=J.w/J.scale;te(E,null,Xe-Wt/2,Rr-Wt/2,0,1,1),Oe.r.quad(Oe.tex(J.surface),J,E,Wt,Wt,Vt,Ie,"normal")},j=Oe=>{let J=null,Xe=!1;return()=>(J&&i.valid(J.frame)&&J.frame.scale===D&&Xe===P.effects?J:(Xe=P.effects,J=K.shape(Oe))).frame},G=j($),ie=j(O);return new an(K,(Oe,J)=>{let Xe=R==="video"||R==="auto"&&ye==="video",Rr=G(),Vt=Xe?ie():null;for(let Ie of Dt())Vt&&I(Oe,Vt,Ie.x,Ie.y,16777215,J),I(Oe,Rr,Ie.x,Ie.y,Y(Ie.color)[0],J)})},timeline:g=>a.timeline(g),animation(g,A){let R=typeof g=="string"?mi(g):{frames:g},E=new ce(K,R,A);return ht.add(E),E},bitmapFont(g,A){if(!A){let E=b.get(g);if(!E)throw new Error(`[engine] no bitmap font "${g}": load or make it first`);return E}let R="data"in A?Un(Rt(A.data),A.pages):Gs(K,A);return b.set(g,R),R},players:()=>Ar(),onFrame(g){return kr.add(g),()=>{kr.delete(g)}},onRender(g){return Sr.add(g),()=>{Sr.delete(g)}},onBackdrop(g){return xr.add(g),()=>{xr.delete(g)}},get hud(){return Re||(Re=document.createElement("div"),Re.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(Re),Fe()),Re},random:(g=0,A=1)=>g+Math.random()*(A-g),start(){Gt||(Gt=!0,We=0,Tr=requestAnimationFrame(Bn))},pause(){ut=!0,Bt()},resume(){ut=!1,Bt()},destroy(){Gt=!1,cancelAnimationFrame(Tr),Pn.forEach(g=>g()),removeEventListener("resize",Fe),Nt?.disconnect(),document.removeEventListener("visibilitychange",Dn),document.fonts?.removeEventListener?.("loadingdone",Gn),a.clear(),as(K),l.destroy(),t.destroy(),Re?.remove()}};function mi(g){let A=y.get(g);if(A)return A;let R=[...new Set([...f.keys(),...p.keys()])].filter(E=>E.startsWith(g)).sort(us);if(!R.length)throw new Error(`[engine] no animation or frames "${g}\u2026"`);return{frames:R}}async function bi(g,A){let R=A.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(R))return l.load(g,A);if(["woff","woff2","ttf","otf"].includes(R)){let O=new FontFace(g,`url(${A})`);document.fonts.add(await O.load()),d++;return}let E=new URL(A,location.href);if(R==="fnt")return Hn(g,Rt(await(await fetch(A)).text()),E);if(R==="json"){let O=await(await fetch(A)).json();if(Array.isArray(O.chars)&&!O.frames)return Hn(g,Rt(O),E);let I=await on(new URL(O.meta?.image??A.replace(/\.json$/,".png"),E).href);yi(g,O,Ze(I));return}let L=await on(A),$=Ze(L);n.add($),f.set(g,{surface:$,x:0,y:0,w:L.width,h:L.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function Un(g,A){return Ds(g,A.map(R=>{let E=Ze(R);return n.add(E),E}))}async function Hn(g,A,R){b.set(g,Un(A,await Promise.all(A.pages.map(E=>on(new URL(E,R).href)))))}function yi(g,A,R){n.add(R);let E=Array.isArray(A.frames)?A.frames:Object.entries(A.frames).map(([O,I])=>({...I,filename:O})),L=[],$=[];for(let O of E){let I=O.frame,j=O.filename.replace(Js,"");O.rotated&&console.warn(`[engine] ${g}/${j} is rotated: export without rotation`);let G={surface:R,x:I.x,y:I.y,w:I.w,h:I.h,scale:1,gen:0,ox:0,oy:0,margin:0};O.trimmed&&O.sourceSize&&O.spriteSourceSize&&(G.sw=O.sourceSize.w,G.sh=O.sourceSize.h,G.tx=O.spriteSourceSize.x,G.ty=O.spriteSourceSize.y);let ie=O.scale9Borders;ie&&(G.slice=[ie.y,(G.sw??I.w)-ie.x-ie.w,(G.sh??I.h)-ie.y-ie.h,ie.x]),f.set(`${g}/${j}`,G),L.push(`${g}/${j}`),$.push((O.duration??0)/1e3)}for(let[O,I]of Object.entries(A.animations??{}))y.set(`${g}/${O}`,{frames:I.map(j=>`${g}/${j.replace(Js,"")}`)});for(let O of A.meta?.frameTags??[]){let I=[];for(let G=O.from;G<=O.to;G++)I.push(G);O.direction==="reverse"&&I.reverse(),O.direction==="pingpong"&&I.push(...I.slice(1,-1).reverse());let j=I.every(G=>$[G]>0);y.set(`${g}/${O.name}`,{frames:I.map(G=>L[G]),...j?{durations:I.map(G=>$[G])}:{}})}}return $t}var Js=/\.(png|webp|jpe?g|gif|bmp)$/i;function on(s){return new Promise((r,e)=>{let t=new Image;t.onload=()=>r(t),t.onerror=()=>e(new Error(`[engine] image did not load: ${s}`)),t.src=s})}function xo(s){return new Promise(r=>{let e=[],t=0,n=i=>{t&&e.push(i-t),t=i,e.length<s?requestAnimationFrame(n):r(e)};requestAnimationFrame(n)})}async function vo(s,r,e,t,n,i=()=>!1){let o=t(),a=Jr(r,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},o).frame,l=[],u=[],c=new Float64Array(6),f=.004,p=s.kind==="canvas2d"?s.canvas.getContext("2d"):null,b=Te(),y=0;return await new Promise(m=>{let d=x=>{y&&x-b>250&&l.push(x-y),y=x;let v=Te();s.begin(0,0,o);let k=e();for(let w=0;w<300;w++){let M=x/1e3+w;te(c,null,w*37%n,w*53%q,M,1,1),s.quad(k(a.surface),a,c,a.w/o,a.h/o,16777215,f,"normal")}for(let w=0;w<40;w++)s.ellipse(100+w*20,300,20,14,w,16746496,f),s.stroke([100+w*20,400,120+w*20,460,100+w*20,520],3,18,3368703,f,!1);s.end(),p?.getImageData(0,0,1,1),x-b>250&&u.push(Te()-v),x-b<750&&!i()?requestAnimationFrame(d):(s.begin(0,0,o),s.end(),m())};requestAnimationFrame(d)}),{intervals:l,cpu:u}}var wo=64,ei=32,Ao=0,ko=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,ti=new Set,ri=(s,r)=>{ti.has(s)||(ti.add(s),console.warn(r))},ni=s=>new ln(s),ln=class{constructor(r){h(this,"r",r);h(this,"css","none");h(this,"plans",new tt(wo));h(this,"buf",new Float64Array(64));h(this,"keys",[]);h(this,"classes",new Map);h(this,"live",new Set);h(this,"svgs",new Map);h(this,"t",0);h(this,"cur",null);h(this,"svgFn",r=>this.svg(r));h(this,"scr",[]);h(this,"flip",0)}chain(r,e){var y;let t=this.r,n=this.buf;n[0]=t.scale,n[1]=t.maxBlur;let i=2;for(let m=0;m<e.length;m++){let d=e[m];if(i+22>n.length){let v=new Float64Array(n.length*2);v.set(n),n=this.buf=v}let x=this.classes.get(d.constructor);x===void 0&&this.classes.set(d.constructor,x=this.classes.size),n[i++]=x,n[i++]=d.enabled?1:0,d.params&&(i=d.params(n,i))}let o=(y=this.keys)[i]??(y[i]=new Float64Array(i));for(let m=0;m<i;m++)o[m]=n[m];let a=he(o),l=this.plans.get(o,a);l||this.plans.set(o,l=this.plan(e),a);for(let m=0;m<l.svgs.length;m++){let d=l.svgs[m];d.used<0&&this.attach(d),d.used=this.t}t.skipped+=l.skip;let u=r,c=t.rx0,f=t.ry0,p=t.rx1-c,b=t.ry1-f;for(let m=0;m<l.paints.length;m++)l.parts[m]&&(u=this.bake(u,l.parts[m])),e[l.paints[m]].paint2d(u.getContext("2d"),c,f,p,b);return this.css=l.parts[l.paints.length]||"none",u}tick(){let r=++this.t;if(!(r%ei||!this.live.size))for(let e of this.live)r-e.used>ei&&this.detach(e)}destroy(){for(let r of this.live)this.detach(r);this.plans.clear()}svg(r){if(typeof document>"u"||!document.body)return null;let e=Array.from({length:20},(n,i)=>r[i]??0).join(" "),t=this.svgs.get(e);if(!t){let n="http://www.w3.org/2000/svg",i=document.createElementNS(n,"svg");i.setAttribute("width","0"),i.setAttribute("height","0"),i.setAttribute("aria-hidden","true"),i.style.position="absolute";let o=document.createElementNS(n,"filter"),a=ko+ ++Ao;o.setAttribute("id",a),o.setAttribute("color-interpolation-filters","sRGB");let l=document.createElementNS(n,"feColorMatrix");l.setAttribute("type","matrix"),l.setAttribute("values",e),o.append(l),i.append(o),this.attach(t={key:e,id:a,el:i,used:this.t})}return this.cur.svgs.push(t),`url(#${t.id})`}attach(r){document.body.append(r.el),this.live.add(r),this.svgs.has(r.key)||this.svgs.set(r.key,r)}detach(r){r.el.remove(),r.used=-1,this.live.delete(r),this.svgs.get(r.key)===r&&this.svgs.delete(r.key)}plan(r){let e=this.r,t=this.cur={parts:[],paints:[],skip:0,svgs:[]},n="";for(let i=0;i<r.length;i++){let o=r[i];if(!o.enabled)continue;if(o.kind===4){t.skip++,ri("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}let a=e.support.filters&&o.css?o.css(e.scale,e.maxBlur,this.svgFn):null;a!==null?n+=n?` ${a}`:a:o.paint2d?(t.parts.push(n),t.paints.push(i),n=""):(t.skip++,ri("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return t.parts.push(n),t}bake(r,e){let t=this.r,n=this.flip^=1,i=this.scr[n];(!i||i.width!==t.canvas.width||i.height!==t.canvas.height)&&(i=this.scr[n]=document.createElement("canvas"),i.width=t.canvas.width,i.height=t.canvas.height);let o=i.getContext("2d"),a=t.rx0,l=t.ry0,u=t.rx1-a,c=t.ry1-l;return o.clearRect(a,l,u,c),o.filter=e,o.drawImage(r,a,l,u,c,a,l,u,c),o.filter="none",i}};var So=64,dr=17,To=s=>`${lr}
48
+ }`,Ki={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},Yi=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],Qi=["aPos","aUv","aColor","aSlot"];function Ls(s,r,e={}){let t={...Ki,failIfMajorPerformanceCaveat:e.failIfMajorPerformanceCaveat!==!1},n=r===2?s.getContext("webgl2",t):s.getContext("webgl",t)??s.getContext("experimental-webgl",t);if(!n||n.isContextLost())return null;try{return new Vr(s,n,r,e)}catch(i){return console.warn("[engine] WebGL setup failed:",i),n.getExtension("WEBGL_lose_context")?.loseContext(),null}}var Vr=class extends rt{constructor(e,t,n,i){super();h(this,"canvas",e);h(this,"gl",t);h(this,"opts",i);h(this,"kind");h(this,"maxTextureSize");h(this,"support",{filters:!0,shaders:!0});h(this,"features",{});h(this,"info",{});h(this,"lost",!1);h(this,"main");h(this,"cur");h(this,"unit",-1);h(this,"onUnit",new Array(_s).fill(void 0));h(this,"fbNow");h(this,"mapped",!0);h(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0});h(this,"vsrc","");h(this,"attrs",[]);h(this,"fxr",null);h(this,"batch");h(this,"dynamic");h(this,"staticBuf",null);h(this,"index");h(this,"vao",null);h(this,"inst",null);h(this,"vaoApi",null);h(this,"uScale",null);h(this,"textures",new Map);h(this,"kit");h(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0});h(this,"lostListeners",[]);h(this,"restoredListeners",[]);h(this,"tris",new Int32Array(192));h(this,"sU",0);h(this,"sV0",0);h(this,"sV1",0);h(this,"sColor",0);h(this,"sPacked",0);h(this,"sAlpha",0);h(this,"sHw",0);h(this,"strokeSeg",()=>{let e=this.q;e.set(kt),e[8]=e[10]=this.sU,e[9]=this.sV0,e[11]=this.sV1,e[12]=this.sPacked,this.put(this.kit)});h(this,"strokeDisc",()=>this.ellipse(kt[0],kt[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha));h(this,"q",new Float64Array(13));h(this,"layers",[]);h(this,"layerTex",new Map);h(this,"bScis",!1);h(this,"bx0",0);h(this,"by0",0);h(this,"bx1",0);h(this,"by1",0);h(this,"onContextLost",e=>{e.preventDefault(),this.lost=!0;for(let t of this.lostListeners)t()});h(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(let e of this.textures.keys())this.textures.set(e,this.upload(e.source));this.lost=!1;for(let e of this.restoredListeners)e()}catch(e){console.warn("[engine] WebGL restore failed:",e)}});h(this,"views",new Map);this.kind=n===2?"webgl2":"webgl1",this.maxTextureSize=t.getParameter(t.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(Fs()),re.live=this,e.addEventListener("webglcontextlost",this.onContextLost,!1),e.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){let e=this.gl,t=this.kind==="webgl2"?e:null;if(this.inst=null,this.opts.instancing!==!1)if(t)this.inst={divisor:(f,p)=>t.vertexAttribDivisor(f,p),draw:(f,p)=>t.drawElementsInstanced(e.TRIANGLES,f,e.UNSIGNED_SHORT,0,p)};else{let f=e.getExtension("ANGLE_instanced_arrays");f&&(this.inst={divisor:(p,b)=>f.vertexAttribDivisorANGLE(p,b),draw:(p,b)=>f.drawElementsInstancedANGLE(e.TRIANGLES,p,e.UNSIGNED_SHORT,0,b)})}if(this.vaoApi=null,this.opts.vao!==!1)if(t)this.vaoApi={create:()=>t.createVertexArray(),bind:f=>t.bindVertexArray(f),remove:f=>t.deleteVertexArray(f)};else{let f=e.getExtension("OES_vertex_array_object");f&&(this.vaoApi={create:()=>f.createVertexArrayOES(),bind:p=>f.bindVertexArrayOES(p),remove:p=>f.deleteVertexArrayOES(p)})}let n=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),i=Math.max(1,Math.min(_s,n)),o=this.inst!==null;this.vsrc=o?qi:ji,this.attrs=o?Yi:Qi,this.main=this.cur=this.build(Xi(i));let a=this.main.p;e.useProgram(a),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,e.uniform1iv(e.getUniformLocation(a,"uTex"),Int32Array.from({length:i},(f,p)=>p)),this.batch=new Zt(o,i),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic),e.bufferData(e.ARRAY_BUFFER,this.batch.f32.byteLength,e.DYNAMIC_DRAW),this.index=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.index),e.bufferData(e.ELEMENT_ARRAY_BUFFER,ms(o?1:8192),e.STATIC_DRAW);let l=f=>e.getAttribLocation(a,f),u=(f,p,b,y,m,d,x)=>{let v=l(f);v<0||(e.enableVertexAttribArray(v),e.vertexAttribPointer(v,p,b,y,m,d),this.inst&&this.inst.divisor(v,x))};if(o){let f=56;u("aP01",4,e.FLOAT,!1,f,0,1),u("aP23",4,e.FLOAT,!1,f,16,1),u("aUvRect",4,e.FLOAT,!1,f,32,1),u("aColor",4,e.UNSIGNED_BYTE,!0,f,48,1),u("aSlot",1,e.FLOAT,!1,f,52,1),this.staticBuf=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.staticBuf),e.bufferData(e.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),e.STATIC_DRAW),u("aCorner",4,e.FLOAT,!1,16,0,0),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic)}else{let f=24;u("aPos",2,e.FLOAT,!1,f,0,0),u("aUv",2,e.FLOAT,!1,f,8,0),u("aColor",4,e.UNSIGNED_BYTE,!0,f,16,0),u("aSlot",1,e.FLOAT,!1,f,20,0)}e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),e.disable(e.DEPTH_TEST),e.disable(e.CULL_FACE),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);let c=e.getExtension("WEBGL_debug_renderer_info");this.info={version:e.getParameter(e.VERSION),renderer:c?e.getParameter(c.UNMASKED_RENDERER_WEBGL):e.getParameter(e.RENDERER),vendor:c?e.getParameter(c.UNMASKED_VENDOR_WEBGL):e.getParameter(e.VENDOR)},this.features={instancing:o,vao:this.vaoApi!==null,textureSlots:i,maxTextureSize:this.maxTextureSize}}upload(e){let t=this.gl,n=t.createTexture();return this.bindTex(n),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),n}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){let t={id:gt(),width:e.width,height:e.height,source:e};return this.textures.set(t,this.lost?null:this.upload(e)),t}updateTexture(e,t,n=0,i=0){if(this.lost)return;this.batch.has(e)&&this.flush();let o=this.gl,a=this.textures.get(e);a&&(this.bindTex(a),!t||t===e.source&&n===0&&i===0?o.texImage2D(o.TEXTURE_2D,0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,e.source):o.texSubImage2D(o.TEXTURE_2D,0,n,i,o.RGBA,o.UNSIGNED_BYTE,t))}destroyTexture(e){this.batch.has(e)&&this.flush();let t=this.textures.get(e);t&&!this.lost&&this.deleteTex(t),this.textures.delete(e)}begin(e,t,n){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(n),this.bScis=!1,this.lost)return;let i=this.gl;i.disable(i.SCISSOR_TEST),this.bindFb(null),i.viewport(0,0,this.canvas.width,this.canvas.height);let o=t;i.clearColor((e>>16&255)/255*o,(e>>8&255)/255*o,(e&255)/255*o,o),i.clear(i.COLOR_BUFFER_BIT),this.use(this.main),i.uniform2f(this.uScale,2*n/this.canvas.width,-2*n/this.canvas.height),this.mapped=!0}build(e){let t=this.gl,n=Cs(t,t.VERTEX_SHADER,this.vsrc),i;try{i=Cs(t,t.FRAGMENT_SHADER,e)}catch(a){throw t.deleteShader(n),a}let o=t.createProgram();if(t.attachShader(o,n),t.attachShader(o,i),this.attrs.forEach((a,l)=>t.bindAttribLocation(o,l,a)),t.linkProgram(o),t.deleteShader(n),t.deleteShader(i),!t.getProgramParameter(o,t.LINK_STATUS)){let a=t.getProgramInfoLog(o)??"?";throw t.deleteProgram(o),new Error(`link: ${a}`)}return{p:o,uScale:t.getUniformLocation(o,"uScale"),locs:new Map}}u(e,t){let n=e.locs.get(t);return n===void 0&&e.locs.set(t,n=this.gl.getUniformLocation(e.p,t)),n}use(e){this.cur!==e&&(this.cur=e,this.gl.useProgram(e.p),this.calls.useProgram++)}bindTex(e,t=this.unit<0?0:this.unit){let n=this.gl;this.onUnit[t]!==e&&(this.unit!==t&&(n.activeTexture(n.TEXTURE0+t),this.calls.activeTexture++,this.unit=t),n.bindTexture(n.TEXTURE_2D,e),this.calls.bindTexture++,this.onUnit[t]=e)}deleteTex(e){this.gl.deleteTexture(e);for(let t=0;t<this.onUnit.length;t++)this.onUnit[t]===e&&(this.onUnit[t]=null)}bindFb(e){if(e)for(let n=0;n<this.onUnit.length;n++)this.onUnit[n]===e.gl&&this.bindTex(null,n);let t=e?e.fb:null;this.fbNow!==t&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,t),this.calls.bindFramebuffer++,this.fbNow=t)}slotOf(e){this.batch.full&&this.flush();let t=this.batch.slot(e);return t<0&&(this.flush(),t=this.batch.slot(e)),t}quad(e,t,n,i,o,a,l,u){B[0]=i,B[1]=o,B[2]=l,this.quadQ(e,t,n,a,u)}quadQ(e,t,n,i,o){let a=B[2];if(this.lost||a<=0)return;let l=this.q,u=B[0],c=B[1],f=n[4],p=n[5],b=n[0]*u,y=n[1]*u,m=n[2]*c,d=n[3]*c;l[0]=f,l[1]=p,l[2]=b+f,l[3]=y+p,l[4]=b+m+f,l[5]=y+d+p,l[6]=m+f,l[7]=d+p;let x=1/e.width,v=1/e.height;l[8]=t.x*x,l[9]=t.y*v,l[10]=(t.x+t.w)*x,l[11]=(t.y+t.h)*v,l[12]=Be(i,a,o==="add"),this.put(e)}put(e){if(this.mute)return;let t=this.q,n=!1,i=Math.min(t[0],t[2],t[4],t[6]),o=Math.max(t[0],t[2],t[4],t[6]),a=Math.min(t[1],t[3],t[5],t[7]),l=Math.max(t[1],t[3],t[5],t[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;let c=this.scale,f=this.px0/c,p=this.py0/c,b=this.px1/c,y=this.py1/c;if(o<=f||i>=b||l<=p||a>=y)return;if(i<f||o>b||a<p||l>y){let m=t[0],d=t[1],x=t[2],v=t[5];if(d===t[3]&&x===t[4]&&v===t[7]&&t[6]===m){if(m!==x){let k=Math.min(Math.max(m,f),b),w=Math.min(Math.max(x,f),b),M=t[8],S=(t[10]-M)/(x-m);t[10]=M+(w-m)*S,t[8]=M+(k-m)*S,t[0]=t[6]=k,t[2]=t[4]=w}if(d!==v){let k=Math.min(Math.max(d,p),y),w=Math.min(Math.max(v,p),y),M=t[9],S=(t[11]-M)/(v-d);t[11]=M+(w-d)*S,t[9]=M+(k-d)*S,t[1]=t[3]=k,t[5]=t[7]=w}}else n=!0}}let u=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(n?(!this.bScis||!u)&&(this.flush(),this.bScis=!0,this.bx0=this.px0,this.by0=this.py0,this.bx1=this.px1,this.by1=this.py1):this.bScis&&!(this.cOn&&u)&&(this.flush(),this.bScis=!1),this.real){let c=this.gq;c[0]=i,c[1]=a,c[2]=o,c[3]=l,this.growQ()}this.batch.pushQ(t,this.slotOf(e))}ellipse(e,t,n,i,o,a,l){if(this.lost||l<=0||n<=0||i<=0)return;let u=or[$r(Math.max(n,i)*2*this.scale,Es)],c=u.w/2/u.r,f=n*c,p=i*c,b=Math.cos(o),y=Math.sin(o),m=b*f,d=y*f,x=-y*p,v=b*p,k=1/256,w=this.q;w[0]=e-m-x,w[1]=t-d-v,w[2]=e+m-x,w[3]=t+d-v,w[4]=e+m+x,w[5]=t+d+v,w[6]=e-m+x,w[7]=t-d+v,w[8]=u.x*k,w[9]=u.y*k,w[10]=(u.x+u.w)*k,w[11]=(u.y+u.h)*k,w[12]=Be(a,l),this.put(this.kit)}polygon(e,t,n,i){if(this.lost||i<=0||t<3)return;this.tris.length<t*3&&(this.tris=new Int32Array(Math.max(t*3,this.tris.length*2)));let o=this.tris,a=Ss(e,t,o),l=Be(n,i),u=(Ae.x+Ae.w/2)/256,c=(Ae.y+Ae.h/2)/256;for(let f=0;f<a;f+=3){let p=o[f]*2,b=o[f+1]*2,y=o[f+2]*2,m=this.q;m[0]=e[p],m[1]=e[p+1],m[2]=e[b],m[3]=e[b+1],m[4]=m[6]=e[y],m[5]=m[7]=e[y+1],m[8]=m[10]=u,m[9]=m[11]=c,m[12]=l,this.put(this.kit)}}stroke(e,t,n,i,o,a){if(this.lost||o<=0||n<=0||t<1)return;let l=ar[$r(n*this.scale,Rs)],u=n/2*(l.h/2/l.r);this.sPacked=Be(i,o),this.sColor=i,this.sAlpha=o,this.sU=(l.x+l.w/2)/256,this.sV0=l.y/256,this.sV1=(l.y+l.h)/256,this.sHw=n/2,Ts(e,t,u,a,this.strokeSeg,this.strokeDisc)}target(e,t,n,i){let o=this.gl,a=o.createTexture();this.bindTex(a),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,e,t,0,o.RGBA,o.UNSIGNED_BYTE,null);let l=i?o.LINEAR:o.NEAREST;o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,l),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,l),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),this.bindTex(null);let u=o.createFramebuffer();o.bindFramebuffer(o.FRAMEBUFFER,u),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,a,0);let c=o.checkFramebufferStatus(o.FRAMEBUFFER)===o.FRAMEBUFFER_COMPLETE;if(this.fbNow=u,this.bindFb(this.parent()),!c)return this.deleteTex(a),o.deleteFramebuffer(u),null;let f={tex:{id:gt(),width:e,height:t,source:this.canvas},gl:a,fb:u,w:e,h:t,f:n};return this.layerTex.set(f.tex,a),f}drop(e){this.batch.has(e.tex)&&this.flush(),this.deleteTex(e.gl),this.gl.deleteFramebuffer(e.fb),this.layerTex.delete(e.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(e){let t=this.canvas.width,n=this.canvas.height,i=this.layers[e]??null;return i&&(i.w!==t||i.h!==n)&&(this.drop(i),i=this.layers[e]=null),i??(this.layers[e]=this.target(t,n,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();let e=this.layerAt(this.real);if(!e)return!1;let t=this.gl;return this.bindFb(e),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!re.gl?null:this.fxr??(this.fxr=re.gl(this))}composite(e,t,n,i){if(i&&this.filters()?.chain(e,n,i))return;let o=this.gl;t&&o.blendFunc(o.ZERO,o.SRC_ALPHA),this.final(this.main,e,1,n),t&&(this.flush(),o.blendFunc(o.ONE,o.ONE_MINUS_SRC_ALPHA))}final(e,t,n,i){let o=this.gl,a=this.canvas.width,l=this.canvas.height,u=this.scale;(e!==this.main||!this.mapped)&&(this.bindFb(this.parent()),o.viewport(0,0,a,l),this.use(e),o.uniform2f(e.uScale,2*u/a,-2*u/l),this.mapped=e===this.main);let c=this.rx0/u,f=this.ry0/u,p=this.rx1/u,b=this.ry1/u,y=1/(n*t.width),m=1/(n*t.height),d=this.q;d[0]=d[6]=c,d[1]=d[3]=f,d[2]=d[4]=p,d[5]=d[7]=b,d[8]=this.rx0*y,d[9]=1-this.ry0*m,d[10]=this.rx1*y,d[11]=1-this.ry1*m,d[12]=Be(16777215,i),this.put(t),e!==this.main&&this.flush()}remap(){let e=this.gl;this.bindFb(this.parent()),e.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),e.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(e){let t=this.gl,n=e.words;if(this.kind==="webgl2")return t.bufferSubData(t.ARRAY_BUFFER,0,e.f32,0,n);let i=this.views.get(n);i||(this.views.size>=256&&this.views.clear(),this.views.set(n,i=e.f32.subarray(0,n))),t.bufferSubData(t.ARRAY_BUFFER,0,i)}flush(){let e=this.batch;if(!e.quads||this.lost)return e.reset();let t=this.gl;this.bScis?(t.enable(t.SCISSOR_TEST),t.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):t.disable(t.SCISSOR_TEST),this.upload2(e);for(let n=0;n<e.bound;n++){let i=e.textures[n];this.bindTex(this.textures.get(i)??this.layerTex.get(i)??null,n)}this.inst?this.inst.draw(6,e.quads):t.drawElements(t.TRIANGLES,e.quads*6,t.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=e.quads,e.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){let e=this.gl;re.live===this&&(re.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(let t of this.textures.values())t&&e.deleteTexture(t);for(let t of this.layers)t&&(e.deleteTexture(t.gl),e.deleteFramebuffer(t.fb));this.fxr?.destroy(),this.fxr=null,e.deleteBuffer(this.dynamic),e.deleteBuffer(this.index),this.staticBuf&&e.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),e.deleteProgram(this.main.p),e.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function Cs(s,r,e){let t=s.createShader(r);if(s.shaderSource(t,e),s.compileShader(t),!s.getShaderParameter(t,s.COMPILE_STATUS)){let n=s.getShaderInfoLog(t)??"?";throw s.deleteShader(t),new Error(n)}return t}function Ps(s="auto"){switch(s){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function St(s,r={}){let e=s;for(let t of Ps(r.renderer)){let n=t==="canvas2d"?nt(e):Ls(e,t==="webgl2"?2:1,r);if(n)return n;e=Tt(e)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function Tt(s){let r=s.cloneNode(!1);return s.parentNode?.replaceChild(r,s),r}function Ns(s=typeof location<"u"?location.search:""){let r=new URLSearchParams(s).get("renderer");return r==="canvas"?"canvas2d":r==="webgl2"||r==="webgl1"||r==="canvas2d"||r==="webgl"||r==="auto"?r:void 0}import{frameOf as Zi}from"@fabiplay/sdk/avatars";var $e=class{constructor(r,e={}){h(this,"atlas",r);h(this,"tags",new Map);h(this,"count",0);h(this,"m",ge());h(this,"measure",null);h(this,"height");h(this,"font");this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(let r of this.tags.values())for(let e of r.values())for(let t of e.values())this.atlas.release(t);this.tags.clear(),this.count=0}get(r,e,t){let n=this.tags.get(r);n||this.tags.set(r,n=new Map);let i=n.get(e);i||n.set(e,i=new Map);let o=i.get(t);return o&&this.atlas.valid(o)?o:this.bake(r,e,t)}bake(r,e,t){let n=this.height,i=`700 ${Math.round(n*.65)}px ${this.font}`,o=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));o.font=i;let a=Math.round(n*.4),l=Math.ceil(o.measureText(r).width)+a*2,u=this.atlas.bake((l+2)*t,(n+2)*t,p=>{p.scale(t,t),p.translate(1,1);let b=n/2;p.beginPath(),p.moveTo(b,0),p.lineTo(l-b,0),p.arc(l-b,b,b,-Math.PI/2,Math.PI/2),p.lineTo(b,n),p.arc(b,b,b,Math.PI/2,Math.PI*3/2),p.closePath(),p.fillStyle=e,p.fill(),p.fillStyle="#fff",p.font=i,p.textAlign="center",p.textBaseline="middle",p.fillText(r,l/2,n/2+1)},t,1,1,1);++this.count>64&&(this.drop(),this.count=1);let c=this.tags.get(r);c||this.tags.set(r,c=new Map);let f=c.get(e);return f||c.set(e,f=new Map),f.set(t,u),u}draw(r,e,t,n,i,o,a,l,u,c,f){let p=Zi(t,i,{band:Ji(n)});if(!p)return;let b=this.height,y=this.get(o,a,u),m=y.w/y.scale-2,d=Math.min(Math.max(p.head.x-m/2,4),c-m-4),x=Math.min(Math.max(p.head.y-p.headR*2.2-b,4),f-b-4);te(this.m,null,d-1,x-1,0,1,1),r.quad(e(y.surface),y,this.m,y.w/y.scale,y.h/y.scale,16777215,l,"normal")}},Ji=s=>s.band==="3-5"||s.band==="9-12"?s.band:"6-8";var no=(s,r=!1)=>r?Math.min(2**Math.round(Math.log2(Math.max(s,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(s,8))*2)/2),512);function jr(s,r=null){let e={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},t=(n,i,o)=>{let a=r?r[0]*n+r[2]*i+r[4]:n,l=r?r[1]*n+r[3]*i+r[5]:i,u=r?Math.hypot(r[0],r[1]):1;e.minX=Math.min(e.minX,a-o*u),e.minY=Math.min(e.minY,l-o*u),e.maxX=Math.max(e.maxX,a+o*u),e.maxY=Math.max(e.maxY,l+o*u)};for(let n of s){let i="lw"in n&&n.stroke?(n.lw??1)/2:0;switch(n.k){case"circle":t(n.x-n.r,n.y-n.r,i),t(n.x+n.r,n.y+n.r,i),t(n.x-n.r,n.y+n.r,i),t(n.x+n.r,n.y-n.r,i);break;case"ellipse":case"rect":{let o=n.k==="ellipse"?Math.max(n.rx,n.ry):Math.hypot(n.w,n.h)/2;t(n.x-o,n.y-o,i),t(n.x+o,n.y+o,i),t(n.x-o,n.y+o,i),t(n.x+o,n.y-o,i);break}case"path":{let o=ir(n.d);for(let a=0;a<o.count;a++){let l=o.subs[a];for(let u=0;u<l.n;u++)t(l.pts[u*2],l.pts[u*2+1],i)}break}case"line":for(let o=0;o+1<n.pts.length;o+=2)t(n.pts[o],n.pts[o+1],i);break;case"group":{let o=te(ge(),r,n.x,n.y,n.rot??0,n.s??1,n.s??1),a=jr(n.items,o);Number.isFinite(a.minX)&&(e.minX=Math.min(e.minX,a.minX),e.minY=Math.min(e.minY,a.minY),e.maxX=Math.max(e.maxX,a.maxX),e.maxY=Math.max(e.maxY,a.maxY));break}}}return e}var at=class{constructor(r){h(this,"atlas",r);h(this,"seen",new WeakSet);h(this,"baked",new WeakMap);h(this,"m",ge());h(this,"stack",[]);h(this,"local",ge());h(this,"pts",new Float64Array(128));h(this,"stats",{baked:0,vector:0});h(this,"bakeGroups",!0);h(this,"coarse",!1);h(this,"gen",0);h(this,"live",new Set)}setTier(r){let e=r==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(let t of this.live)this.atlas.release(t.frame);this.live.clear()}}draw(r,e,t,n,i,o,a){let l=typeof n=="string"?Wr(n)??Xr:n,u=eo(t,l,i);return u.length?(o<=0||(o<1?(this.paint(r,e,u,null,r.beginLayer()?1:o,a),r.endLayer(o)):this.paint(r,e,u,null,o,a)),!0):!1}paint(r,e,t,n,i,o,a=0){var l;for(let u=0;u<t.length;u++){let c=t[u];if(c.k==="group"){let v=te((l=this.stack)[a]??(l[a]=ge()),n,c.x,c.y,c.rot??0,c.s??1,c.s??1),k=i*(c.alpha??1);if(this.bakeGroups&&this.seen.has(c.items)){let w=pe(v[0],v[1])*o,M=this.bake(c.items,w);if(M){let S=M.frame,_=this.m;_.set(v),_[4]=v[0]*-M.ox+v[2]*-M.oy+v[4],_[5]=v[1]*-M.ox+v[3]*-M.oy+v[5],r.quad(e(S.surface),S,_,S.w/M.k,S.h/M.k,16777215,k,"normal"),this.stats.baked++;continue}}this.seen.add(c.items),this.stats.vector++,this.paint(r,e,c.items,v,k,o,a+1);continue}let f=i*(c.alpha??1),p=n?pe(n[0],n[1]):1,b=n?Math.atan2(n[1],n[0]):0,y=(c.lw??1)*p,m=c.stroke&&(c.lw??1)>0?Y(c.stroke):null,d=c.fill&&c.k!=="line"?Y(c.fill):null;if(c.k==="circle"||c.k==="ellipse"){let v=n?n[0]*c.x+n[2]*c.y+n[4]:c.x,k=n?n[1]*c.x+n[3]*c.y+n[5]:c.y,w=(c.k==="circle"?c.r:c.rx)*p,M=(c.k==="circle"?c.r:c.ry)*p,S=(c.k==="ellipse"?c.rot??0:0)+b;if(d&&m)r.ellipse(v,k,w+y/2,M+y/2,S,m[0],f*m[1]),r.ellipse(v,k,Math.max(w-y/2,0),Math.max(M-y/2,0),S,d[0],f*d[1]);else if(d)r.ellipse(v,k,w,M,S,d[0],f*d[1]);else if(m){let _=Math.min(Math.max(Math.ceil(Math.max(w,M)*o*.6),12),64),C=this.pts=sr(this.pts,_*2),P=Math.cos(S),z=Math.sin(S);for(let H=0;H<_;H++){let U=H/_*Math.PI*2,D=Math.cos(U)*w,be=Math.sin(U)*M;C[H*2]=v+D*P-be*z,C[H*2+1]=k+D*z+be*P}r.stroke(C,_,y,m[0],f*m[1],!0)}continue}if(c.k==="line"){if(!m)continue;let v=c.pts.length>>1,k=this.pts=sr(this.pts,v*2);for(let w=0;w<v;w++){let M=c.pts[w*2],S=c.pts[w*2+1];k[w*2]=n?n[0]*M+n[2]*S+n[4]:M,k[w*2+1]=n?n[1]*M+n[3]*S+n[5]:S}r.stroke(k,v,y,m[0],f*m[1],!1);continue}let x=c.k==="path"?ir(c.d,n,p*o):so(c,te(this.local,n,c.x,c.y,c.rot??0,1,1),o*p);for(let v=0;v<x.count;v++){let k=x.subs[v],w=k.n,M=c.k==="rect"||k.closed;d&&w>=3&&(r.polygon(k.pts,w,d[0],f*d[1]),m||r.stroke(k.pts,w,1/o,d[0],f*d[1],!0)),m&&r.stroke(k.pts,w,y,m[0],f*m[1],M)}}}bake(r,e){let t=no(e,this.coarse),n=this.baked.get(r),i=n?.get(t);if(i&&i.gen===this.gen&&this.atlas.valid(i.frame))return i;i&&this.live.delete(i);let o=jr(r);if(!Number.isFinite(o.minX))return null;let a=2/t,l=(o.maxX-o.minX+a*2)*t,u=(o.maxY-o.minY+a*2)*t;if(l>1024||u>1024)return null;let c=-o.minX+a,f=-o.minY+a,b={frame:this.atlas.bake(l,u,y=>{y.scale(t,t),y.translate(c,f),Os(y,r)}),k:t,ox:c,oy:f,gen:this.gen};return n||this.baked.set(r,n=new Map),n.set(t,b),this.live.add(b),b}},it=new Array(36).fill(0),ot=0,de=(s,r=NaN,e=NaN,t=NaN,n=NaN)=>{it[ot++]=s,s!==Z.Z&&(it[ot++]=r,it[ot++]=e,s===Z.Q&&(it[ot++]=t,it[ot++]=n))};function so(s,r,e){let t=Math.max(0,Math.min(s.r,s.w/2,s.h/2)),n=-s.w/2,i=-s.h/2,{M:o,L:a,Q:l,Z:u}=Z;return ot=0,de(o,n+t,i),de(a,n+s.w-t,i),de(l,n+s.w,i,n+s.w,i+t),de(a,n+s.w,i+s.h-t),de(l,n+s.w,i+s.h,n+s.w-t,i+s.h),de(a,n+t,i+s.h),de(l,n,i+s.h,n,i+s.h-t),de(a,n,i+t),de(l,n,i,n+t,i),de(u),ir(it,r,e)}function io(s,r={}){let e=St(s,r),t=new ze(Math.min(1024,e.maxTextureSize),2);t.onDrop=S=>{S.texture&&e.destroyTexture(S.texture),S.texture=null};let n=new at(t),i=()=>{let S=new ro;return r.local&&S.setLocal(!0),S},o=i(),a=new Map,l=1e6,u=r.smooth===!1?1:typeof r.smooth=="number"?Math.min(Math.max(r.smooth,.05),1):o.defaultAmount,c=Mt(e),f=new $e(t,r),p={w:1,h:1},b=1,y=0,m=!1,d=()=>f.drop(),x=typeof document<"u"?document.fonts:void 0;x?.ready?.then(()=>{m||d()}),x?.addEventListener?.("loadingdone",d);let v=()=>{let S=Tt(e.canvas),_=nt(S);if(_){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),e.destroy(),e=_;for(let C of t.pages)C.surface.texture=null;c=Mt(e),y=0}},k=()=>{if(!e.lost)return y=0,!0;let S=performance.now();return y||(y=S),S-y>3e3&&v(),!e.lost},w=()=>{let S=e.canvas;r.units?(b=r.pixelRatio??1,p.w=r.units.width,p.h=r.units.height):(b=r.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),p.w=S.clientWidth||S.width/b,p.h=S.clientHeight||S.height/b),e.resize(Math.max(1,Math.round(p.w*b)),Math.max(1,Math.round(p.h*b))),e.begin(0,0,b)},M=(S,_)=>{if(S.key===void 0)return S.id??_+1;let C=a.get(S.key);return C===void 0&&(a.size>256&&a.clear(),a.set(S.key,C=l++)),C};return{get renderer(){return e},get kind(){return e.kind},get lost(){return e.lost},get canvas(){return e.canvas},draw(S,_){if(k()){w();for(let C=0;C<S.length;C++){let P=S[C];if(!Array.isArray(P.body))continue;let z=M(P,C),H=u<1||r.interpolate!==!1?o.posed(z,P.body,u,r.interpolate!==!1):P.body,U=Wr(P.avatar??"")??Xr,D=P.alpha??1;!n.draw(e,c,H,U,_,D,b)||!P.name||f.draw(e,c,H,U,_,P.name,P.color??"#6FA0E0",D,b,p.w,p.h)}e.end()}},clear(){k()&&(w(),e.end())},reset(){o=i(),a.clear()},destroy(){m=!0,x?.removeEventListener?.("loadingdone",d),e.destroy()}}}var ur=new Map;function oo(s,r,e=Math.min(globalThis.devicePixelRatio||1,2)){let t=`${s}|${r}|${e}`,n=ur.get(t);if(n)return n;n=document.createElement("canvas"),n.width=n.height=Math.round(r*e);let i=n.getContext("2d");return i.scale(e,e),i.beginPath(),i.rect(0,0,r,r),i.clip(),Os(i,to(Wr(s)??Xr,r)),ur.size>64&&ur.clear(),ur.set(t,n),n}function Mt(s){return r=>{if(r.texture||(r.texture=s.createTexture(r.source),r.pending.length=0),r.pending.length){for(let[e,t,n]of r.pending)s.updateTexture(r.texture,e,t,n);r.pending.length=0}return r.texture}}var Is='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',lt="rgba(10,16,30,0.75)";function qr(s,r){let e=s.size??40,t=s.outline?s.outline===!0?lt:s.outline:null,n=t?s.outlineWidth??Math.max(e*.12,3):0,i=s.shadow&&r?s.shadow===!0?lt:s.shadow:null,o=i?s.shadowBlur??e*.25:0;return{size:e,font:s.font??Is,weight:s.weight??700,color:s.color??"#FBEFE3",outline:t,ow:n,shadow:i,blur:o,pad:n/2+o*1.2+2,th:e*1.25}}var Bs=(s,r)=>`${s.weight} ${s.size*r}px ${s.font}`;function Kr(s,r,e,t,n,i){s.scale(t,t),s.font=Bs(e,1),s.textBaseline="middle",s.textAlign="left",s.lineJoin="round",e.shadow&&(s.shadowColor=e.shadow,s.shadowBlur=e.blur*t),e.outline&&(s.strokeStyle=e.outline,s.lineWidth=e.ow,s.strokeText(r,n,i),s.shadowColor="transparent"),s.fillStyle=e.color,s.fillText(r,n,i)}var cr=null;function Yr(s,r,e){return cr??(cr=document.createElement("canvas").getContext("2d")),cr.font=Bs(r,e),cr.measureText(s).width/e}var ke=class extends oe{constructor(e,t,n={}){super(e,null);h(this,"_text");h(this,"_style");h(this,"dirty",!0);h(this,"bakedScale",0);h(this,"bakedFontGen",-1);h(this,"bakedEffects",!0);h(this,"capW",0);h(this,"capH",0);this._text=t;let{x:i,y:o,rotation:a,scale:l,scaleX:u,scaleY:c,alpha:f,visible:p,tint:b,blend:y,z:m,anchor:d,hitRadius:x,clip:v,mask:k,filters:w,...M}=n;this._style=M,this.bake(),this.set({x:i,y:o,rotation:a,scale:l,scaleX:u,scaleY:c,alpha:f,visible:p,tint:b,blend:y,z:m,hitRadius:x,clip:v,mask:k,filters:w}),d!==void 0&&(this.anchor=d)}get text(){return this._text}set text(e){let t=String(e);t!==this._text&&(this._text=t,this.dirty=!0)}get style(){return this._style}set style(e){this._style={...this._style,...e},this.dirty=!0}bitmap(){let e=this._style.bitmapFont;if(!e)return null;let t=typeof e=="string"?this.kernel.bitmapFont(e):e;if(this.autoAnchor){let n=this._style.align;this.anchorX=n==="left"?0:n==="right"?1:.5,this.anchorY=.5}return t}get naturalWidth(){let e=this.bitmap();return e?e.measure(this._text)*((this._style.size??e.size)/e.size):super.naturalWidth}get naturalHeight(){let e=this.bitmap();return e?e.lineHeight*((this._style.size??e.size)/e.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(e,t,n){let i=this.bitmap();if(!i)return super.draw(e,t,n);let o=(this._style.size??i.size)/i.size,a=i.measure(this._text)*o,l=i.lineHeight*o,u=this.width,c=this.height,f=a>0?u/a:1,p=l>0?c/l:1;i.run(this._text,e,this.world,-this.anchorX*u,-this.anchorY*c,o*f,o*p,n,t,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){let e=this.kernel;if(this._style.bitmapFont)return null;let t=e.pixelScale,n=e.effects;return!this.dirty&&t===this.bakedScale&&e.fontGen===this.bakedFontGen&&n===this.bakedEffects&&e.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){let e=this.kernel,t=e.pixelScale,n=e.effects;this.dirty=!1,this.bakedScale=t,this.bakedFontGen=e.fontGen,this.bakedEffects=n;let i=qr(this._style,n),{pad:o,th:a}=i,l=Yr(this._text,i,t),u=(l+o*2)*t,c=(a+o*2)*t,f=this._style.align??"center",p=f==="left"?o:f==="right"?o+l:o+l/2,b=d=>Kr(d,this._text,i,t,o,o+a/2),y=this._frame,m=null;return y&&e.atlas.valid(y)&&y.scale===t&&(m=e.atlas.rebake(y,u,c,b,this.capW,this.capH),m?Object.assign(m,{ox:p,oy:o+a/2,margin:o}):e.atlas.release(y)),m||(this.capW=Math.ceil(u*1.25+16),this.capH=Math.ceil(c),m=e.atlas.bake(this.capW,this.capH,b,t,p,o+a/2,o),m.w=Math.ceil(u),m.h=Math.ceil(c)),this._frame=m,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,m}};var X=(s,r=0)=>{let e=Number(s);return Number.isFinite(e)?e:r};function Rt(s){typeof s=="string"&&/^\s*[{[]/.test(s)&&(s=JSON.parse(s));let r={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},e=(t,n)=>{t==="info"?r.size=Math.abs(X(n.size)):t==="common"?(r.lineHeight=X(n.lineHeight),r.base=X(n.base)):t==="page"?r.pages[X(n.id)]=String(n.file??""):t==="char"?r.chars.push({id:X(n.id),x:X(n.x),y:X(n.y),width:X(n.width),height:X(n.height),xoffset:X(n.xoffset),yoffset:X(n.yoffset),xadvance:X(n.xadvance),page:X(n.page)}):r.kernings.push({first:X(n.first),second:X(n.second),amount:X(n.amount)})};if(typeof s=="object"){let t=s;e("info",t.info??{}),e("common",t.common??{});for(let[n,i]of(t.pages??[]).entries())e("page",{id:n,file:i});for(let n of t.chars??[])e("char",n);for(let n of t.kernings??[])e("kerning",n)}else{let t=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,n=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let i=t.exec(s);i;i=t.exec(s)){let o={};for(let a=n.exec(i[2]);a;a=n.exec(i[2]))o[a[1]]=a[2]??a[3];e(i[1],o)}}return r.size||(r.size=r.lineHeight),r}var Et=class{constructor(r,e,t,n=null,i=null){h(this,"baker",n);h(this,"host",i);h(this,"size");h(this,"lineHeight");h(this,"base");h(this,"ascii",new Array(128));h(this,"more",new Map);h(this,"kern",new Map);h(this,"bScale",0);h(this,"bFontGen",-1);h(this,"bEffects",!1);h(this,"bGen",-1);this.size=r,this.lineHeight=e,this.base=t}set(r,e){r<128?this.ascii[r]=e:this.more.set(r,e)}setKerning(r,e,t){this.kern.set(r*1114112+e,t)}prepare(){let r=this.host;if(!(!r||r.pixelScale===this.bScale&&r.fontGen===this.bFontGen&&r.effects===this.bEffects&&r.atlas.gen===this.bGen)){this.bScale=r.pixelScale,this.bFontGen=r.fontGen,this.bEffects=r.effects,this.bGen=r.atlas.gen;for(let e of this.ascii)e&&r.atlas.release(e.frame);for(let e of this.more.values())e&&r.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(r){let e=r<128?this.ascii[r]:this.more.get(r);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(r):null,this.set(r,e)),e}kerning(r,e){return this.kern.size?this.kern.get(r*1114112+e)??0:0}measure(r){return this.run(r)}run(r,e,t,n=0,i=0,o=1,a=1,l=0,u=1,c="normal"){this.prepare();let f=0,p=-1;for(let b=0;b<r.length;b++){let y=r.charCodeAt(b);y>=55296&&y<56320&&b+1<r.length&&(y=r.codePointAt(b),b++),p>=0&&(f+=this.kerning(p,y)),p=y;let m=this.glyph(y);m&&(e&&m.w>0&&m.h>0&&(vt(t,n+(f+m.x)*o,i+m.y*a),e.r.quad(e.tex(m.frame.surface),m.frame,W,m.w*o,m.h*a,l,u,c)),f+=m.advance)}return f}};function Ds(s,r){let e=new Et(s.size,s.lineHeight,s.base);for(let t of s.chars){let n=r[t.page];if(!n)continue;let i={surface:n,x:t.x,y:t.y,w:t.width,h:t.height,scale:1,gen:0,ox:0,oy:0,margin:0};e.set(t.id,{frame:i,x:t.xoffset,y:t.yoffset,w:t.width,h:t.height,advance:t.xadvance})}for(let t of s.kernings)e.setKerning(t.first,t.second,t.amount);return e}function Gs(s,r){let e={...r},t=r.size??40,n=o=>{let a=String.fromCodePoint(o),l=s.pixelScale,u=qr(e,s.effects),c=Yr(a,u,l),f=s.atlas.bake((c+u.pad*2)*l,(u.th+u.pad*2)*l,p=>Kr(p,a,u,l,u.pad,u.pad+u.th/2),l);return{frame:f,x:-u.pad,y:-u.pad,w:f.w/l,h:f.h/l,advance:c}},i=new Et(t,t*1.25,t,n,s);i.prepare();for(let o of r.chars??"0123456789")i.glyph(o.codePointAt(0));return i}var ao=.5;function Us(s){let r=[];for(let[e,t]of[["left",ee.leftWrist],["right",ee.rightWrist]]){let n=s[t*3],i=s[t*3+1],o=s[t*3+2];n!==void 0&&i!==void 0&&Number.isFinite(n)&&Number.isFinite(i)&&(o??0)>=ao&&r.push({side:e,x:n,y:i})}return r}var Ft=s=>dt[((s-1)%dt.length+dt.length)%dt.length],lo=["left","right"];function Qr(s,r,e,t,n=()=>null,i={}){let o=[];for(let a of s){let l=n(a)??a.body;if(Array.isArray(l)){if(i.orientation==="portrait"){for(let u of lo){let c=$n(l,u,{orientation:"portrait"});i.hold&&(c=i.hold.at(je.key(a.id,u),c,i.t??0)),c&&o.push({player:a.id,side:u,x:c.x*e,y:c.y*t,color:Ft(a.id)})}continue}for(let u of Us(l)){let c=r(u);o.push({player:a.id,side:u.side,x:c.x*e,y:c.y*t,color:Ft(a.id)})}}}return o}function hr(s,r,e,t=0){let n=s.world,i=qn(n,r,e);if(!i)return!1;let o=Math.hypot(n[0],n[1])||1,a=Math.hypot(n[2],n[3])||1,[l,u]=i;if(s.hitRadius!=null){let y=s.hitRadius+t/((o+a)/2);return l*l+u*u<=y*y}let c=-s.anchorX*s.width-t/o,f=-s.anchorY*s.height-t/a,p=(1-s.anchorX)*s.width+t/o,b=(1-s.anchorY)*s.height+t/a;return l>=c&&l<=p&&u>=f&&u<=b}function Zr(s,r,e,t=0){for(let n of r)if((e===void 0||n.player===e)&&hr(s,n.x,n.y,t))return n;return null}function uo(s){switch(s.type){case"circle":case"ring":case"star":return[s.r*2,s.r*2];case"ellipse":return[s.rx*2,s.ry*2];case"roundRect":return[s.w,s.h];case"line":return[s.length,s.lw??4];case"path":return s.r?[s.r*2,s.r*2]:[s.size,s.size]}}function co(s){let r=s.type==="line"?0:s.stroke?(s.lw??2)/2:0,e=s.shadow?s.shadow.blur*1.5+Math.max(Math.abs(s.shadow.x??0),Math.abs(s.shadow.y??0)):0;return Math.ceil(r+e+1)}var Hs=(s,r)=>r||!s.shadow?s:{...s,shadow:void 0};function Jr(s,r,e){let t=co(r),n=r.type==="roundRect",[i,o]=n?[Math.min(r.w,r.r*2+4/e),Math.min(r.h,r.r*2+4/e)]:uo(r),a=(i+t*2)*e,l=(o+t*2)*e;return{frame:s.bake(a,l,c=>{c.scale(e,e),c.translate(t+i/2,t+o/2),ho(c,r,i,o)},e,t+i/2,t+o/2,t),slice:n?Math.ceil((r.r+t)*e):0,w:n?r.w:i,h:n?r.h:o}}function ho(s,r,e,t){s.lineJoin="round",s.lineCap="round";let n=new Path2D;switch(r.type){case"circle":case"ring":n.arc(0,0,r.r,0,Math.PI*2);break;case"ellipse":n.ellipse(0,0,r.rx,r.ry,0,0,Math.PI*2);break;case"roundRect":n.roundRect(-e/2,-t/2,e,t,Math.min(r.r,e/2,t/2));break;case"star":{let u=r.points??5,c=r.r*(r.inner??.5);for(let f=0;f<u*2;f++){let p=f%2?c:r.r,b=-Math.PI/2+f*Math.PI/u;f?n.lineTo(Math.cos(b)*p,Math.sin(b)*p):n.moveTo(Math.cos(b)*p,Math.sin(b)*p)}n.closePath();break}case"line":n.moveTo(-e/2+t/2,0),n.lineTo(e/2-t/2,0);break;case"path":{let u=r.r?r.r*2/r.size:1,c=new DOMMatrix([u,0,0,u,-r.size/2*u,-r.size/2*u]);n.addPath(new Path2D(r.d),c);break}}let i=r.shadow,o=()=>{if(!i)return;let u=s.getTransform();s.shadowColor=i.color,s.shadowBlur=i.blur*u.a,s.shadowOffsetX=(i.x??0)*u.a,s.shadowOffsetY=(i.y??0)*u.a},a=()=>{s.shadowColor="transparent",s.shadowBlur=0};if(r.type==="line"){o(),s.strokeStyle=r.stroke??r.fill??"#fff",s.lineWidth=t,s.stroke(n);return}let l=r.type==="ring";if(r.outlineBelow&&r.fill&&r.stroke&&!l){o(),s.strokeStyle=r.stroke,s.lineWidth=r.lw??2,s.stroke(n),a(),s.fillStyle=r.fill,s.fill(n);return}r.fill&&!l&&(o(),s.fillStyle=r.fill,s.fill(n),a()),(r.stroke||l)&&((!r.fill||l)&&o(),l&&r.fill&&(s.fillStyle=r.fill,s.fill(n)),s.strokeStyle=r.stroke??"#fff",s.lineWidth=r.lw??2,s.stroke(n),a())}var _t=class{constructor(){h(this,"ctx",null);h(this,"master",null);h(this,"buffers",new Map);h(this,"held",!1);h(this,"muted",!1);h(this,"volume",1);if(typeof addEventListener=="function"){let r=()=>{this.context()?.resume().catch(()=>{})};for(let e of["pointerdown","keydown","touchstart"])addEventListener(e,r,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;let r=globalThis.AudioContext??globalThis.webkitAudioContext;if(!r)return null;try{this.ctx=new r,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch{return null}return this.ctx}async load(r,e){let t=this.context();if(!t)return;let n=await(await fetch(e)).arrayBuffer();this.buffers.set(r,await t.decodeAudioData(n))}has(r){return this.buffers.has(r)}play(r,e={}){let t=this.context(),n=this.buffers.get(r);if(!t||!n||!this.audible)return()=>{};let i=t.createBufferSource();i.buffer=n,i.loop=e.loop??!1,i.playbackRate.value=e.rate??1;let o=t.createGain();return o.gain.value=(e.volume??1)*this.volume,i.connect(o).connect(this.master),i.start(),()=>{try{i.stop()}catch{}}}tone(r,e=.25,t={}){let n=this.context();if(!(!n||!this.audible))try{let i=n.createOscillator(),o=n.createGain();i.type=t.type??"sine",i.frequency.setValueAtTime(r,n.currentTime),t.to&&i.frequency.exponentialRampToValueAtTime(t.to,n.currentTime+e),o.gain.setValueAtTime((t.volume??.12)*this.volume,n.currentTime),o.gain.exponentialRampToValueAtTime(.001,n.currentTime+e),i.connect(o).connect(this.master),i.start(),i.stop(n.currentTime+e)}catch{}}get audible(){return!this.muted&&!this.held}hold(){this.held=!0,this.ctx?.suspend().catch(()=>{})}release(){this.held=!1,this.ctx?.resume().catch(()=>{})}destroy(){this.ctx?.close().catch(()=>{}),this.ctx=null}};var fo={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}},Se=["high","medium","low"];function Pe(s){let r=fo[s];return{name:s,...r,scale:e=>e<=0?0:Math.max(1,Math.round(e*r.particles))}}var zs=s=>Se[Math.min(Se.indexOf(s)+1,Se.length-1)],fr=(s,r)=>{if(!s.length)return NaN;let e=[...s].sort((t,n)=>t-n);return e[Math.min(e.length-1,Math.max(0,Math.floor(r*(e.length-1)+.5)))]},$s=12,Vs=s=>Ct(s,.5);function Ct(s,r=.1){let e=fr(s,r);if(!Number.isFinite(e))return 1e3/60;let t=[144,120,90,75,60,50,30],n=60;for(let i of t)Math.abs(1e3/i-e)<Math.abs(1e3/n-e)&&(n=i);return 1e3/n}function en(s,r){let e=r.refresh!==void 0&&Number.isFinite(r.refresh)&&r.refresh>0?r.refresh:Ct(r.intervals),t=fr(r.intervals,.5),n=fr(r.intervals,.9),i=fr(r.cpu,.5);if(!Number.isFinite(t))return s==="canvas2d"?"low":"medium";let o=l=>l<=e*1.25,a=l=>!Number.isFinite(i)||i<e*l;return s==="canvas2d"?o(n)&&a(.25)?"medium":"low":o(n)&&a(.5)?"high":o(t)?"medium":"low"}function Ws(s,r){return s.length<30?!1:s.filter(t=>t>r*1.5).length/s.length>.5}var Xs="0.1.1",po=720*3600*1e3,js=(s,r,e)=>`fabi-play.engine-tier:${Xs}:${s}:${r}:${e}`,qs=(s,r,e)=>`fablee-engine-tier:${Xs}:${s}:${r}:${e}`;function Ks(s,r,e=Date.now()){try{let t=JSON.parse(s?.getItem(r)??"null");if(t&&Se.includes(t.tier)&&typeof t.at=="number"&&e-t.at<po)return typeof t.refresh=="number"&&t.refresh>0?{name:t.tier,refresh:t.refresh}:{name:t.tier}}catch{}return null}function tn(s,r,e,t,n=Date.now()){try{s?.setItem(r,JSON.stringify(t!==void 0&&Number.isFinite(t)?{tier:e,at:n,refresh:t}:{tier:e,at:n}))}catch{}}function Ys(s=typeof location<"u"?location.search:""){let r=new URLSearchParams(s).get("tier");return Se.includes(r)?r:void 0}function rn(s,r){let e=r?.tier;if(Se.includes(e))return s==="canvas2d"&&e==="high"?"medium":e}var nn=s=>typeof s?.hz=="number"&&s.hz>=20&&s.hz<=240?Ct([1e3/s.hz],.5):NaN,sn=(s,r)=>Se.indexOf(s)>=Se.indexOf(r)?s:r;function Qs(s,r,e){return s?{name:s,from:"forced"}:r?{name:e?sn(r,e):r,from:"hint"}:e?{name:e,from:"cache"}:null}var mo=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,Lt=class{constructor(r={}){h(this,"steps",[]);h(this,"labels",new Map);h(this,"end",0);h(this,"prevStart",0);h(this,"elapsed",0);h(this,"iter",0);h(this,"last",0);h(this,"delayLeft");h(this,"_paused");h(this,"done",!1);h(this,"rewinding",!1);h(this,"promise");h(this,"resolve");h(this,"repeat");h(this,"yoyo");h(this,"onComplete");this.repeat=Math.floor(r.repeat??0),this.yoyo=!!r.yoyo,this.delayLeft=r.delay??0,this._paused=!!r.paused,this.onComplete=r.onComplete,this.promise=new Promise(e=>this.resolve=e)}get duration(){return this.end}get time(){return this.last}get paused(){return this._paused}get finished(){return this.done}at(r){if(r===void 0)return this.end;if(typeof r=="number")return Math.max(r,0);let e=mo.exec(r);if(!e)throw new Error(`[engine] timeline: bad position "${r}"`);let[,t,n,i]=e,o=i?(n==="-"?-1:1)*Number(i):0,a=this.end;if(t==="<")a=this.prevStart;else if(t&&t!==">"){let l=this.labels.get(t.trim());l===void 0?this.labels.set(t.trim(),this.end):a=l}return Math.max(a+o,0)}add(r){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>r.start;)e--;return this.steps.splice(e,0,r),this.prevStart=r.start,this.end=Math.max(this.end,r.start+r.dur),this}to(r,e,t,n="quadOut"){let i=typeof n=="object"?n:{ease:n},o=typeof i.ease=="function"?i.ease:Ge[i.ease??"quadOut"];return this.add({target:r,to:e,from:null,fn:null,start:this.at(i.at)+(i.delay??0),dur:Math.max(t,0),ease:o,onUpdate:i.onUpdate,p:-1})}set(r,e,t){return this.add({target:r,to:e,from:null,fn:null,start:this.at(t),dur:0,ease:Ge.linear,p:-1})}call(r,e){return this.add({target:null,to:null,from:null,fn:r,start:this.at(e),dur:0,ease:Ge.linear,p:-1})}label(r,e){return this.labels.set(r,this.at(e)),this}wait(r){return this.end+=Math.max(r,0),this.prevStart=this.end,this}pause(){return this._paused=!0,this}resume(){return this._paused=!1,this}stop(){this.done||(this.done=!0,this.resolve())}seek(r){let e=Math.min(typeof r=="string"&&this.labels.has(r)?this.labels.get(r):this.at(r),this.end),t=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(t?this.end-e:e),this.render(e),this}then(r,e){return this.promise.then(r,e)}update(r){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=r,this.delayLeft>0)return;r=-this.delayLeft,this.delayLeft=0}let e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=r;let t=this.repeat<0?1/0:e*(this.repeat+1),n=Math.min(this.elapsed,t),i=n>=t?this.repeat:Math.floor(n/e);for(;this.iter<i;){let a=this.yoyo&&this.iter%2===1;this.render(a?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}let o=n-i*e;this.render(this.yoyo&&i%2===1?e-o:o),n>=t&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(r){let e=this.steps;if(r>=this.last)for(let t=0;t<e.length;t++){let n=e[t];r>=n.start&&this.apply(n,r)}else for(let t=e.length-1;t>=0;t--){let n=e[t];n.p>=0&&this.apply(n,r)}this.last=r}apply(r,e){let t=r.dur>0?Math.min(Math.max((e-r.start)/r.dur,0),1):e>r.start||e===r.start&&!this.rewinding?1:0;if(t===r.p)return;if(r.p=t,r.fn){this.rewinding||r.fn();return}let n=r.target;if(n.destroyed||n._free)return;let i=r.to;if(!r.from){r.from={};for(let a in i)r.from[a]=Number(n[a]??0)}let o=r.ease(t);for(let a in i)n[a]=r.from[a]+(i[a]-r.from[a])*o;r.onUpdate?.(o)}};var Pt=class{constructor(){h(this,"list",[]);h(this,"timelines",[])}timeline(r){let e=new Lt(r);return this.timelines.push(e),e}tween(r,e,t,n="quadOut"){let i=typeof n=="object"?n:{ease:n},o=typeof i.ease=="function"?i.ease:Ge[i.ease??"quadOut"],a,l=new Promise(u=>{let c=Object.keys(e),f=new Float64Array(c.length);c.forEach((p,b)=>f[b]=Number(e[p])),a={target:r,keys:c,to:f,from:new Float64Array(c.length),started:!1,duration:Math.max(t,0),time:0,delay:i.delay??0,ease:o,onUpdate:i.onUpdate,done:u,dead:!1}});return this.list.push(a),Object.assign(l,{stop:()=>this.finish(a)})}stopAll(r){let e=this.list;for(let t=0;t<e.length;t++)e[t].target===r&&this.finish(e[t])}get size(){return this.list.length}update(r){if(this.timelines.length){let n=0,i=this.timelines;for(let o=0;o<i.length;o++){let a=i[o];a.update(r),a.finished||(i[n++]=a)}i.length=n}let e=this.list;if(!e.length)return;let t=0;for(let n=0;n<e.length;n++){let i=e[n];i.dead||this.step(i,r),i.dead||(e[t++]=i)}t!==e.length&&(e.length=t)}step(r,e){if(r.target.destroyed)return this.finish(r);let t=e;if(r.delay>0){if(r.delay-=e,r.delay>0)return;t=-r.delay}let n=r.keys;if(!r.started){r.started=!0;for(let a=0;a<n.length;a++)r.from[a]=Number(r.target[n[a]]??0)}r.time+=t;let i=r.duration>0?Math.min(r.time/r.duration,1):1,o=r.ease(i);for(let a=0;a<n.length;a++)r.target[n[a]]=r.from[a]+(r.to[a]-r.from[a])*o;r.onUpdate?.(o),i>=1&&this.finish(r)}finish(r){r.dead||(r.dead=!0,r.done())}clear(){for(let r of this.list)this.finish(r);this.list.length=0;for(let r of this.timelines)r.stop();this.timelines=[]}};var q=720,pr=class extends ue{constructor(e,t){super(e);h(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},an=class extends ue{constructor(e,t){super(e);h(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},Te=()=>performance.now(),Zs=s=>{let r=Wn(s);return r&&Object.freeze(r)};async function go(s={}){let r=s.play??null,e=s.canvas??null;e||(e=document.createElement("canvas"),e.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(e));let t=St(e,{renderer:s.renderer??Ns(),failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat,instancing:s.instancing});e=t.canvas;let n=new Set,i=new ze(Math.min(2048,t.maxTextureSize),4);i.onPage=g=>n.add(g),i.onDrop=g=>{n.delete(g),g.texture&&t.destroyTexture(g.texture),g.texture=null};let o=Mt(t),a=new Pt,l=new _t,u=new at(i),c=new Map,f=new Map,p=new Map,b=new Map,y=new Map,m=new Set,d=0,x=s.tier??Ys(),v=String(t.info.renderer??""),k=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),w=typeof screen<"u"?`${screen.width}x${screen.height}`:"",M=js(t.kind,v,w);Xn(k,M,qs(t.kind,v,w));let S=Ks(k,M),_=Qs(x,rn(t.kind,r?.device),S?.name),C=_?.name??"medium",P=Pe(C);u.setTier(C);let z=_?.from==="hint",H=S?.name,U=S?.refresh??nn(r?.device),D=1,be=1,Ee=1,K={atlas:i,get pixelScale(){return D},get fontGen(){return d},get effects(){return P.effects},tweens:a,frame:g=>$t.frame(g),shape:g=>{let A=P.effects,R=A?D:-D,E=c.get(R);E||(c.size>=8&&c.clear(),c.set(R,E=new tt(2e3)));let L=he(g),$=E.get(g,L);return(!$||!i.valid($.frame))&&E.set(g,$=Jr(i,Hs(g,A),D),L),$},bitmapFont:g=>$t.bitmapFont(g)},ae=1280,Re=null;class li extends Qe{get width(){return ae}set width(A){}get height(){return q}set height(A){}get safe(){let A=Math.min(ae,q*16/9);return{x:(ae-A)/2,y:0,w:A,h:q}}}let le=new li(K),Fe=()=>{let g=t.canvas,A=g.getBoundingClientRect();be=Math.max(1,A.width||g.clientWidth||innerWidth),Ee=Math.max(1,A.height||g.clientHeight||innerHeight),ae=q*be/Ee;let R=Math.min(globalThis.devicePixelRatio||1,s.maxPixelRatio??2);if(Ee*R/q<=P.resolution){let L=Math.max(1,Math.round(Ee*R));D=L/q,t.resize(Math.max(1,Math.round(be*R)),L)}else D=P.resolution,t.resize(Math.round(ae*D),Math.round(q*D));Re&&Re.style.setProperty("--unit",`${Ee/q}px`)};addEventListener("resize",Fe);let gr=g=>{C=g,P=Pe(g),u.setTier(g),Fe()},Nt=typeof ResizeObserver<"u"?new ResizeObserver(Fe):null;Nt?.observe(e);let ye=r?.backdrop==="video"?"video":"none",V=r?.view??null,Ot=r?.orientation==="portrait"?"portrait":"landscape",Rn=Zs(r?.safeArea)??Vn,Fn=[],_n=-1/0,It=!1,ut=!1,xr=new Set,Cn=()=>{let g=ye==="video"?"transparent":"";document.documentElement.style.background=g,document.body.style.background=g},Ln=(g,A)=>{let R=g==="video"?"video":"none",E=A??null;if(!(R===ye&&(E===V||E&&V&&E.x===V.x&&E.y===V.y&&E.w===V.w&&E.h===V.h))){ye=R,V=E,Cn();for(let L of[...xr])L(ye,V)}},Pn=[];if(r){let g=E=>{Array.isArray(E)&&(Fn=E,_n=Te())},A=E=>{It=E,Bt()},R=E=>{if(x||z)return;Number.isFinite(U)||(U=nn(E));let L=rn(t.kind,E);L&&(z=!0,gr(H?sn(L,H):L))};Pn.push(r.on("start",E=>R(E?.device)),r.on("start",E=>{(E?.orientation==="portrait"||E?.orientation==="landscape")&&(Ot=E.orientation);let L=Zs(E?.safeArea);L&&(Rn=L)}),r.on("start",E=>{typeof E?.muted=="boolean"&&(l.muted=E.muted)}),r.on("frame",E=>g(E?.players)),r.on("players",E=>g(E?.players)),r.on("backdrop",E=>Ln(E?.backdrop,E?.view)),r.on("start",E=>Ln(E?.backdrop,E?.view??r.view)),r.on("pause",()=>A(!0)),r.on("resume",()=>A(!1)),r.on("break-start",()=>A(!0)),r.on("break-done",()=>A(!1)),r.on("break-end",()=>A(!1))),l.muted=r.muted===!0}Cn();let Bt=()=>It||ut||document.hidden?l.hold():l.release(),Nn=-1,vr=[],wr=0,Ar=()=>Te()-_n<1e3?Fn:[],ui=g=>r?r.toScreen(g):Fr(V,g),ci=new je,Dt=()=>{if(Nn===wr)return vr;Nn=wr;let g=Ot==="portrait",A=ye==="video"&&!g||!r?.smoothedBody?()=>null:R=>r.smoothedBody(R);return vr=Qr(Ar(),ui,ae,q,A,g?{orientation:Ot,hold:ci,t:Te()}:void 0),vr},ct={x:0,y:0,w:1,h:1},hi=()=>(ct.x=V?V.x*ae:0,ct.y=V?V.y*q:0,ct.w=V?V.w*ae:ae,ct.h=V?V.h*q:q,ct),fi=g=>{let A=g.alpha??1,R=g.tags?new $e(i,g):null;R&&m.add(R);let E=typeof g.tags=="function"?g.tags:L=>String(L);return(L,$)=>{if(ye==="video")return;let O=hi();for(let I of Ar()){let j=r?.smoothedBody?.(I)??I.body,G=bo(r?.avatarOf?.(I)??I.avatar??"")??yo;if(!u.draw(L.r,L.tex,j,G,O,A*$,D)||!R)continue;let ie=E(I.id);ie&&R.draw(L.r,L.tex,j,G,O,ie,Ft(I.id),A*$,D,ae,q)}}},kr=new Set,Sr=new Set,ht=new Set,Gt=!1,Tr=0,We=0,Ut=0,Ne={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0},Ht=0,Mr=0,Er=Te(),ft=[],zt=0,On=()=>({r:t,kernel:K,tex:o}),In=On(),pi=()=>{if(t.lost)return;let[g,A]=ye==="video"||s.background===void 0?[0,0]:Y(s.background);t.time=Ut,t.maxBlur=P.maxBlur,t.begin(g,A,D),te(le.world,null,le.x,le.y,le.rotation,le.scaleX,le.scaleY),Dr(In,le,le.alpha,le.tint);let R=t.end();Ne.drawCalls=R.drawCalls,Ne.quads=R.quads,Ne.filtersSkipped=R.filtersSkipped},Bn=g=>{if(!Gt)return;Tr=requestAnimationFrame(Bn);let A=Math.min(Math.max((g-We)/1e3,0),.1);We&&ft.push(g-We),We=g,wr++;let R=Te(),E=It||ut;if(!E){Ut+=A,a.update(A);for(let L of ht)L.destroyed||L.update(A);for(let L of kr)L(A,Ut)}for(let L of Sr)L(A);le.sweep();for(let L of ht)L.destroyed&&ht.delete(L);if(t.lost?(zt||(zt=g),g-zt>3e3&&di()):(zt=0,pi()),Ht++,Mr+=Te()-R,R-Er>=1e3&&(Ne.fps=Math.round(Ht*1e3/(R-Er)),Ne.cpuMs=Math.round(Mr/Math.max(Ht,1)*100)/100,r?.reportStats?.({fps:Ne.fps,renderer:t.kind,tier:C}),Ht=0,Mr=0,Er=R),ft.length>=180){let L=Number.isFinite(U)?U:Ct(ft);!x&&!E&&Ws(ft,L)&&C!=="low"&&(gr(zs(C)),H=C,tn(k,M,C,Number.isFinite(U)?U:void 0),console.info(`[engine] slow frames: tier ${C}`)),ft.length=0}},di=()=>{let g=Tt(t.canvas),A=nt(g);if(A){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),t.destroy(),t=A;for(let R of n)R.texture=null;for(let R of i.pages)n.add(R.surface);o=Mt(t),In=On(),Nt?.disconnect(),Nt?.observe(g),Fe()}},Dn=()=>{Bt(),document.hidden||(We=0)};document.addEventListener("visibilitychange",Dn);let Gn=()=>{d++;for(let g of m)g.drop()};if(document.fonts?.addEventListener?.("loadingdone",Gn),Fe(),!_&&s.probe!==!1&&(Number.isFinite(U)||(U=Vs(await xo($s))),!z)){P=Pe("high"),Fe();let g=await vo(t,i,()=>o,()=>D,ae,()=>z);if(g.refresh=U,!z){let A=en(t.kind,g);tn(k,M,A,U),H=A,gr(A)}}let $t={stage:le,get tier(){return P},get renderer(){return t},get canvas(){return t.canvas},get pixelScale(){return D},get backdrop(){return ye},get view(){return V},get orientation(){return Ot},get safeArea(){return Rn},get paused(){return It||ut},sound:l,stats:Ne,get time(){return Ut},get supports(){let g=t.support;return{filters:g.filters,blur:g.filters&&P.maxBlur>0,shaders:g.shaders,maxBlur:g.filters?P.maxBlur:0,tiers:{high:{maxBlur:Pe("high").maxBlur},medium:{maxBlur:Pe("medium").maxBlur},low:{maxBlur:Pe("low").maxBlur}}}},sprite:(g,A)=>new oe(K,g,A),shape:(g,A)=>new ve(K,g,A),text:(g,A)=>new ke(K,g,A),group:g=>new Qe(K).set(g??{}),particles(g,A={}){let R=typeof g=="object"&&"type"in g?K.shape(g).frame:g,E=new wt(K,R,A),{max:L,blend:$,gravity:O,drag:I,...j}=A;return E.set(j),ht.add(E),E},tween:(g,A,R,E)=>a.tween(g,A,R,E),bake(g,A,R,E,L){return p.set(g,{w:A,h:R,draw:E,origin:L}),f.delete(g),$t.frame(g)},frame(g){let A=f.get(g);if(A&&i.valid(A)&&(A.gen===0||A.scale===D))return A;let R=p.get(g);if(R){let E=D,L=i.bake(R.w*E,R.h*E,$=>($.scale(E,E),R.draw($)),E,R.origin?.x??0,R.origin?.y??0);return f.set(g,L),L}if(A)return A;throw new Error(`[engine] no frame "${g}": load it or bake it first`)},async load(g){await Promise.all(Object.entries(g).map(([A,R])=>bi(A,R)))},hands:g=>g===void 0?Dt():Dt().filter(A=>A.player===g),touched(g,A,R={}){return g.updateWorld(),Zr(g,Dt(),A,R.padding??0)},hits(g,A,R,E=0){return g.updateWorld(),hr(g,A,R,E)},avatars:(g={})=>new pr(K,fi(g)),handMarkers(g={}){let A=g.radius??36,R=g.look??"auto",E=new Float64Array(6),L=Math.max(A*.12,3),$={type:"ring",r:A,lw:L,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},O={type:"ring",r:A,lw:L*1.8,stroke:lt,shadow:{color:lt,blur:A*.2}},I=(Oe,J,Xe,Rr,Vt,Ie)=>{let Wt=J.w/J.scale;te(E,null,Xe-Wt/2,Rr-Wt/2,0,1,1),Oe.r.quad(Oe.tex(J.surface),J,E,Wt,Wt,Vt,Ie,"normal")},j=Oe=>{let J=null,Xe=!1;return()=>(J&&i.valid(J.frame)&&J.frame.scale===D&&Xe===P.effects?J:(Xe=P.effects,J=K.shape(Oe))).frame},G=j($),ie=j(O);return new an(K,(Oe,J)=>{let Xe=R==="video"||R==="auto"&&ye==="video",Rr=G(),Vt=Xe?ie():null;for(let Ie of Dt())Vt&&I(Oe,Vt,Ie.x,Ie.y,16777215,J),I(Oe,Rr,Ie.x,Ie.y,Y(Ie.color)[0],J)})},timeline:g=>a.timeline(g),animation(g,A){let R=typeof g=="string"?mi(g):{frames:g},E=new ce(K,R,A);return ht.add(E),E},bitmapFont(g,A){if(!A){let E=b.get(g);if(!E)throw new Error(`[engine] no bitmap font "${g}": load or make it first`);return E}let R="data"in A?Un(Rt(A.data),A.pages):Gs(K,A);return b.set(g,R),R},players:()=>Ar(),onFrame(g){return kr.add(g),()=>{kr.delete(g)}},onRender(g){return Sr.add(g),()=>{Sr.delete(g)}},onBackdrop(g){return xr.add(g),()=>{xr.delete(g)}},get hud(){return Re||(Re=document.createElement("div"),Re.style.cssText="position:fixed;top:0;right:0;bottom:0;left:0;pointer-events:none;overflow:hidden",document.body.appendChild(Re),Fe()),Re},random:(g=0,A=1)=>g+Math.random()*(A-g),start(){Gt||(Gt=!0,We=0,Tr=requestAnimationFrame(Bn))},pause(){ut=!0,Bt()},resume(){ut=!1,Bt()},destroy(){Gt=!1,cancelAnimationFrame(Tr),Pn.forEach(g=>g()),removeEventListener("resize",Fe),Nt?.disconnect(),document.removeEventListener("visibilitychange",Dn),document.fonts?.removeEventListener?.("loadingdone",Gn),a.clear(),as(K),l.destroy(),t.destroy(),Re?.remove()}};function mi(g){let A=y.get(g);if(A)return A;let R=[...new Set([...f.keys(),...p.keys()])].filter(E=>E.startsWith(g)).sort(us);if(!R.length)throw new Error(`[engine] no animation or frames "${g}\u2026"`);return{frames:R}}async function bi(g,A){let R=A.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(R))return l.load(g,A);if(["woff","woff2","ttf","otf"].includes(R)){let O=new FontFace(g,`url(${A})`);document.fonts.add(await O.load()),d++;return}let E=new URL(A,location.href);if(R==="fnt")return Hn(g,Rt(await(await fetch(A)).text()),E);if(R==="json"){let O=await(await fetch(A)).json();if(Array.isArray(O.chars)&&!O.frames)return Hn(g,Rt(O),E);let I=await on(new URL(O.meta?.image??A.replace(/\.json$/,".png"),E).href);yi(g,O,Ze(I));return}let L=await on(A),$=Ze(L);n.add($),f.set(g,{surface:$,x:0,y:0,w:L.width,h:L.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function Un(g,A){return Ds(g,A.map(R=>{let E=Ze(R);return n.add(E),E}))}async function Hn(g,A,R){b.set(g,Un(A,await Promise.all(A.pages.map(E=>on(new URL(E,R).href)))))}function yi(g,A,R){n.add(R);let E=Array.isArray(A.frames)?A.frames:Object.entries(A.frames).map(([O,I])=>({...I,filename:O})),L=[],$=[];for(let O of E){let I=O.frame,j=O.filename.replace(Js,"");O.rotated&&console.warn(`[engine] ${g}/${j} is rotated: export without rotation`);let G={surface:R,x:I.x,y:I.y,w:I.w,h:I.h,scale:1,gen:0,ox:0,oy:0,margin:0};O.trimmed&&O.sourceSize&&O.spriteSourceSize&&(G.sw=O.sourceSize.w,G.sh=O.sourceSize.h,G.tx=O.spriteSourceSize.x,G.ty=O.spriteSourceSize.y);let ie=O.scale9Borders;ie&&(G.slice=[ie.y,(G.sw??I.w)-ie.x-ie.w,(G.sh??I.h)-ie.y-ie.h,ie.x]),f.set(`${g}/${j}`,G),L.push(`${g}/${j}`),$.push((O.duration??0)/1e3)}for(let[O,I]of Object.entries(A.animations??{}))y.set(`${g}/${O}`,{frames:I.map(j=>`${g}/${j.replace(Js,"")}`)});for(let O of A.meta?.frameTags??[]){let I=[];for(let G=O.from;G<=O.to;G++)I.push(G);O.direction==="reverse"&&I.reverse(),O.direction==="pingpong"&&I.push(...I.slice(1,-1).reverse());let j=I.every(G=>$[G]>0);y.set(`${g}/${O.name}`,{frames:I.map(G=>L[G]),...j?{durations:I.map(G=>$[G])}:{}})}}return $t}var Js=/\.(png|webp|jpe?g|gif|bmp)$/i;function on(s){return new Promise((r,e)=>{let t=new Image;t.onload=()=>r(t),t.onerror=()=>e(new Error(`[engine] image did not load: ${s}`)),t.src=s})}function xo(s){return new Promise(r=>{let e=[],t=0,n=i=>{t&&e.push(i-t),t=i,e.length<s?requestAnimationFrame(n):r(e)};requestAnimationFrame(n)})}async function vo(s,r,e,t,n,i=()=>!1){let o=t(),a=Jr(r,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},o).frame,l=[],u=[],c=new Float64Array(6),f=.004,p=s.kind==="canvas2d"?s.canvas.getContext("2d"):null,b=Te(),y=0;return await new Promise(m=>{let d=x=>{y&&x-b>250&&l.push(x-y),y=x;let v=Te();s.begin(0,0,o);let k=e();for(let w=0;w<300;w++){let M=x/1e3+w;te(c,null,w*37%n,w*53%q,M,1,1),s.quad(k(a.surface),a,c,a.w/o,a.h/o,16777215,f,"normal")}for(let w=0;w<40;w++)s.ellipse(100+w*20,300,20,14,w,16746496,f),s.stroke([100+w*20,400,120+w*20,460,100+w*20,520],3,18,3368703,f,!1);s.end(),p?.getImageData(0,0,1,1),x-b>250&&u.push(Te()-v),x-b<750&&!i()?requestAnimationFrame(d):(s.begin(0,0,o),s.end(),m())};requestAnimationFrame(d)}),{intervals:l,cpu:u}}var wo=64,ei=32,Ao=0,ko=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,ti=new Set,ri=(s,r)=>{ti.has(s)||(ti.add(s),console.warn(r))},ni=s=>new ln(s),ln=class{constructor(r){h(this,"r",r);h(this,"css","none");h(this,"plans",new tt(wo));h(this,"buf",new Float64Array(64));h(this,"keys",[]);h(this,"classes",new Map);h(this,"live",new Set);h(this,"svgs",new Map);h(this,"t",0);h(this,"cur",null);h(this,"svgFn",r=>this.svg(r));h(this,"scr",[]);h(this,"flip",0)}chain(r,e){var y;let t=this.r,n=this.buf;n[0]=t.scale,n[1]=t.maxBlur;let i=2;for(let m=0;m<e.length;m++){let d=e[m];if(i+22>n.length){let v=new Float64Array(n.length*2);v.set(n),n=this.buf=v}let x=this.classes.get(d.constructor);x===void 0&&this.classes.set(d.constructor,x=this.classes.size),n[i++]=x,n[i++]=d.enabled?1:0,d.params&&(i=d.params(n,i))}let o=(y=this.keys)[i]??(y[i]=new Float64Array(i));for(let m=0;m<i;m++)o[m]=n[m];let a=he(o),l=this.plans.get(o,a);l||this.plans.set(o,l=this.plan(e),a);for(let m=0;m<l.svgs.length;m++){let d=l.svgs[m];d.used<0&&this.attach(d),d.used=this.t}t.skipped+=l.skip;let u=r,c=t.rx0,f=t.ry0,p=t.rx1-c,b=t.ry1-f;for(let m=0;m<l.paints.length;m++)l.parts[m]&&(u=this.bake(u,l.parts[m])),e[l.paints[m]].paint2d(u.getContext("2d"),c,f,p,b);return this.css=l.parts[l.paints.length]||"none",u}tick(){let r=++this.t;if(!(r%ei||!this.live.size))for(let e of this.live)r-e.used>ei&&this.detach(e)}destroy(){for(let r of this.live)this.detach(r);this.plans.clear()}svg(r){if(typeof document>"u"||!document.body)return null;let e=Array.from({length:20},(n,i)=>r[i]??0).join(" "),t=this.svgs.get(e);if(!t){let n="http://www.w3.org/2000/svg",i=document.createElementNS(n,"svg");i.setAttribute("width","0"),i.setAttribute("height","0"),i.setAttribute("aria-hidden","true"),i.style.position="absolute";let o=document.createElementNS(n,"filter"),a=ko+ ++Ao;o.setAttribute("id",a),o.setAttribute("color-interpolation-filters","sRGB");let l=document.createElementNS(n,"feColorMatrix");l.setAttribute("type","matrix"),l.setAttribute("values",e),o.append(l),i.append(o),this.attach(t={key:e,id:a,el:i,used:this.t})}return this.cur.svgs.push(t),`url(#${t.id})`}attach(r){document.body.append(r.el),this.live.add(r),this.svgs.has(r.key)||this.svgs.set(r.key,r)}detach(r){r.el.remove(),r.used=-1,this.live.delete(r),this.svgs.get(r.key)===r&&this.svgs.delete(r.key)}plan(r){let e=this.r,t=this.cur={parts:[],paints:[],skip:0,svgs:[]},n="";for(let i=0;i<r.length;i++){let o=r[i];if(!o.enabled)continue;if(o.kind===4){t.skip++,ri("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}let a=e.support.filters&&o.css?o.css(e.scale,e.maxBlur,this.svgFn):null;a!==null?n+=n?` ${a}`:a:o.paint2d?(t.parts.push(n),t.paints.push(i),n=""):(t.skip++,ri("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return t.parts.push(n),t}bake(r,e){let t=this.r,n=this.flip^=1,i=this.scr[n];(!i||i.width!==t.canvas.width||i.height!==t.canvas.height)&&(i=this.scr[n]=document.createElement("canvas"),i.width=t.canvas.width,i.height=t.canvas.height);let o=i.getContext("2d"),a=t.rx0,l=t.ry0,u=t.rx1-a,c=t.ry1-l;return o.clearRect(a,l,u,c),o.filter=e,o.drawImage(r,a,l,u,c,a,l,u,c),o.filter="none",i}};var So=64,dr=17,To=s=>`${lr}
49
49
  uniform sampler2D uTexture;
50
50
  uniform mat4 uM[${s}];
51
51
  uniform vec4 uO[${s}];
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "package": "@fabiplay/engine",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "algorithm": "sha384",
5
5
  "files": {
6
- "fabi-play-engine.js": "sha384-2vvjuhSm5dG6Zj4QUAnv5rdsFB/VPfOlLOiBvCMOHaz2NM6qBo+N/hyCxM2gK5BV",
7
- "fabi-play-engine.umd.js": "sha384-NhPro651KMBtZPh45ukv3SX4Ij+qzVOmZehxrkptNJwmkPCBYXs+JBTB1TPlZhkH",
8
- "fabi-play-engine.umd.min.js": "sha384-SrzuG2TzHVSBAPVuVYjMlXUf4yYOvq3I+DcfrFGe0hNQ0BsqXYmXigDGsohsRNrm",
6
+ "fabi-play-engine.js": "sha384-Vhj92c8WNaclS6xUZ3o7EhWhj1bWlwBpWSe3ktyEx7brRnqvXPkWNx44rthva9iK",
7
+ "fabi-play-engine.umd.js": "sha384-yHwQX7bZSkg1/Jbam+4GuYhOw2DNliL4KiLSfAZpHLLmQRYhcuBjyZLOQMgBZvxk",
8
+ "fabi-play-engine.umd.min.js": "sha384-Mw0efo5ZH11eePhHa3E4zmZihyDnn2LcPoGodmzTnbmkfgNIh1HgkM8voLxoj4TZ",
9
9
  "fabi-play-engine.d.ts": "sha384-aYQCGGMd/FHNYQMN3m8TX8piUCx5dENMuSJNEKnR8oSvuAhaYhaKw4P08JzQqY5R",
10
- "fabi-play-engine.lite.js": "sha384-LSFGNswLHP7Ow2zKKD4rnxPKgQ+SPmIKhq0C70dlmzd4ytp+YNF81rff3lFbw29E",
11
- "fabi-play-engine.lite.umd.js": "sha384-e9aNM3qA+JzJRBw0bc+tTBZ0voYpdNfKQJmmDcZ5NjYuAWdvEeaBgWnLKqg3QOh8",
12
- "fabi-play-engine.lite.umd.min.js": "sha384-iZO2BWHoVjY8k1bvxZEC8uepGYIorExZcdoXJFSPXWXLujmc8RYLsPYP0fMB+j1H",
10
+ "fabi-play-engine.lite.js": "sha384-pI88Z6xSUnFQLFp2NsWUTb+5EPpWDzzLPMDOFlKS4S/qoLBPYcwPjOLz0fJazyIl",
11
+ "fabi-play-engine.lite.umd.js": "sha384-m1H6DynB7fS/cE5IOg5TsSPwqZFFi7cQ2RGA13QCBqr2VakxyBOk8NVpm/AW576j",
12
+ "fabi-play-engine.lite.umd.min.js": "sha384-Vqq19dCJZEXjmlWhhA8irJLGFbKMJYK18a8ROndyA/feAW7XaIdWtBlx92QhH8IL",
13
13
  "fabi-play-engine.lite.d.ts": "sha384-ENySZiC9ReG0dXWlGWWaFfAs0Gt8brneyLRHF4/+uNzFL0sfE7Ld6bUNUpxNXUcz"
14
14
  }
15
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabiplay/engine",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "A small 2D engine for Fabi Play games: a 720-unit stage, sprites, shapes, text, particles, tweens, sound, the players' hands and avatars, on WebGL (1 or 2) or Canvas 2D.",
5
5
  "keywords": [
6
6
  "fabi-play",
@@ -40,12 +40,12 @@
40
40
  "access": "public"
41
41
  },
42
42
  "peerDependencies": {
43
- "@fabiplay/sdk": "^0.9.0"
43
+ "@fabiplay/sdk": "^0.9.1"
44
44
  },
45
45
  "devDependencies": {
46
- "@fabiplay/avatars": "^0.9.0",
47
- "@fabiplay/protocol": "^0.9.0",
48
- "@fabiplay/sdk": "^0.9.0",
46
+ "@fabiplay/avatars": "^0.9.1",
47
+ "@fabiplay/protocol": "^0.9.1",
48
+ "@fabiplay/sdk": "^0.9.1",
49
49
  "@types/node": "24.10.1",
50
50
  "dts-bundle-generator": "9.5.1",
51
51
  "esbuild": "0.28.2",