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