kaplay 3001.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1056 -0
- package/LICENSE +19 -0
- package/README.md +208 -0
- package/dist/global.d.ts +244 -0
- package/dist/global.js +0 -0
- package/dist/kaboom.cjs +56 -0
- package/dist/kaboom.cjs.map +7 -0
- package/dist/kaboom.d.ts +5589 -0
- package/dist/kaboom.js +57 -0
- package/dist/kaboom.js.map +7 -0
- package/dist/kaboom.mjs +56 -0
- package/dist/kaboom.mjs.map +7 -0
- package/package.json +63 -0
- package/src/app.ts +917 -0
- package/src/assets/bean.png +0 -0
- package/src/assets/boom.png +0 -0
- package/src/assets/burp.mp3 +0 -0
- package/src/assets/index.d.ts +9 -0
- package/src/assets/ka.png +0 -0
- package/src/assets.ts +132 -0
- package/src/easings.ts +94 -0
- package/src/gamepad.json +111 -0
- package/src/gfx.ts +541 -0
- package/src/kaboom.ts +6730 -0
- package/src/math.ts +2035 -0
- package/src/texPacker.ts +80 -0
- package/src/types.ts +5589 -0
- package/src/utils.ts +521 -0
package/dist/kaboom.cjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var an=Object.defineProperty;var _i=Object.getOwnPropertyDescriptor;var ji=Object.getOwnPropertyNames;var Hi=Object.prototype.hasOwnProperty;var o=(n,e)=>an(n,"name",{value:e,configurable:!0});var qi=(n,e)=>{for(var r in e)an(n,r,{get:e[r],enumerable:!0})},zi=(n,e,r,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let h of ji(e))!Hi.call(n,h)&&h!==r&&an(n,h,{get:()=>e[h],enumerable:!(c=_i(e,h))||c.enumerable});return n};var Yi=n=>zi(an({},"__esModule",{value:!0}),n);var Gs=(()=>{for(var n=new Uint8Array(128),e=0;e<64;e++)n[e<26?e+65:e<52?e+71:e<62?e-4:e*4-205]=e;return r=>{for(var c=r.length,h=new Uint8Array((c-(r[c-1]=="=")-(r[c-2]=="="))*3/4|0),m=0,y=0;m<c;){var C=n[r.charCodeAt(m++)],O=n[r.charCodeAt(m++)],v=n[r.charCodeAt(m++)],z=n[r.charCodeAt(m++)];h[y++]=C<<2|O>>4,h[y++]=O<<4|v>>2,h[y++]=v<<6|z}return h}})();var No={};qi(No,{default:()=>Vo});module.exports=Yi(No);function we(n){return n*Math.PI/180}o(we,"deg2rad");function lt(n){return n*180/Math.PI}o(lt,"rad2deg");function We(n,e,r){return e>r?We(n,r,e):Math.min(Math.max(n,e),r)}o(We,"clamp");function Ze(n,e,r){if(typeof n=="number"&&typeof e=="number")return n+(e-n)*r;if(n instanceof x&&e instanceof x)return n.lerp(e,r);if(n instanceof J&&e instanceof J)return n.lerp(e,r);throw new Error(`Bad value for lerp(): ${n}, ${e}. Only number, Vec2 and Color is supported.`)}o(Ze,"lerp");function et(n,e,r,c,h){return c+(n-e)/(r-e)*(h-c)}o(et,"map");function Bs(n,e,r,c,h){return We(et(n,e,r,c,h),c,h)}o(Bs,"mapc");var x=class n{static{o(this,"Vec2")}x=0;y=0;constructor(e=0,r=e){this.x=e,this.y=r}static fromAngle(e){let r=we(e);return new n(Math.cos(r),Math.sin(r))}static LEFT=new n(-1,0);static RIGHT=new n(1,0);static UP=new n(0,-1);static DOWN=new n(0,1);clone(){return new n(this.x,this.y)}add(...e){let r=M(...e);return new n(this.x+r.x,this.y+r.y)}sub(...e){let r=M(...e);return new n(this.x-r.x,this.y-r.y)}scale(...e){let r=M(...e);return new n(this.x*r.x,this.y*r.y)}dist(...e){let r=M(...e);return this.sub(r).len()}sdist(...e){let r=M(...e);return this.sub(r).slen()}len(){return Math.sqrt(this.dot(this))}slen(){return this.dot(this)}unit(){let e=this.len();return e===0?new n(0):this.scale(1/e)}normal(){return new n(this.y,-this.x)}reflect(e){return this.sub(e.scale(2*this.dot(e)))}project(e){return e.scale(e.dot(this)/e.len())}reject(e){return this.sub(this.project(e))}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}angle(...e){let r=M(...e);return lt(Math.atan2(this.y-r.y,this.x-r.x))}angleBetween(...e){let r=M(...e);return lt(Math.atan2(this.cross(r),this.dot(r)))}lerp(e,r){return new n(Ze(this.x,e.x,r),Ze(this.y,e.y,r))}slerp(e,r){let c=this.dot(e),h=this.cross(e),m=Math.atan2(h,c);return this.scale(Math.sin((1-r)*m)).add(e.scale(Math.sin(r*m))).scale(1/h)}isZero(){return this.x===0&&this.y===0}toFixed(e){return new n(Number(this.x.toFixed(e)),Number(this.y.toFixed(e)))}transform(e){return e.multVec2(this)}eq(e){return this.x===e.x&&this.y===e.y}bbox(){return new re(this,0,0)}toString(){return`vec2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`}};function M(...n){if(n.length===1){if(n[0]instanceof x)return new x(n[0].x,n[0].y);if(Array.isArray(n[0])&&n[0].length===2)return new x(...n[0])}return new x(...n)}o(M,"vec2");var J=class n{static{o(this,"Color")}r=255;g=255;b=255;constructor(e,r,c){this.r=We(e,0,255),this.g=We(r,0,255),this.b=We(c,0,255)}static fromArray(e){return new n(e[0],e[1],e[2])}static fromHex(e){if(typeof e=="number")return new n(e>>16&255,e>>8&255,e>>0&255);if(typeof e=="string"){let r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return new n(parseInt(r[1],16),parseInt(r[2],16),parseInt(r[3],16))}else throw new Error("Invalid hex color format")}static fromHSL(e,r,c){if(r==0)return new n(255*c,255*c,255*c);let h=o((z,T,V)=>(V<0&&(V+=1),V>1&&(V-=1),V<1/6?z+(T-z)*6*V:V<1/2?T:V<2/3?z+(T-z)*(2/3-V)*6:z),"hue2rgb"),m=c<.5?c*(1+r):c+r-c*r,y=2*c-m,C=h(y,m,e+1/3),O=h(y,m,e),v=h(y,m,e-1/3);return new n(Math.round(C*255),Math.round(O*255),Math.round(v*255))}static RED=new n(255,0,0);static GREEN=new n(0,255,0);static BLUE=new n(0,0,255);static YELLOW=new n(255,255,0);static MAGENTA=new n(255,0,255);static CYAN=new n(0,255,255);static WHITE=new n(255,255,255);static BLACK=new n(0,0,0);clone(){return new n(this.r,this.g,this.b)}lighten(e){return new n(this.r+e,this.g+e,this.b+e)}darken(e){return this.lighten(-e)}invert(){return new n(255-this.r,255-this.g,255-this.b)}mult(e){return new n(this.r*e.r/255,this.g*e.g/255,this.b*e.b/255)}lerp(e,r){return new n(Ze(this.r,e.r,r),Ze(this.g,e.g,r),Ze(this.b,e.b,r))}toHSL(){let e=this.r/255,r=this.g/255,c=this.b/255,h=Math.max(e,r,c),m=Math.min(e,r,c),y=(h+m)/2,C=y,O=y;if(h==m)y=C=0;else{let v=h-m;switch(C=O>.5?v/(2-h-m):v/(h+m),h){case e:y=(r-c)/v+(r<c?6:0);break;case r:y=(c-e)/v+2;break;case c:y=(e-r)/v+4;break}y/=6}return[y,C,O]}eq(e){return this.r===e.r&&this.g===e.g&&this.b===e.b}toString(){return`rgb(${this.r}, ${this.g}, ${this.b})`}toHex(){return"#"+((1<<24)+(this.r<<16)+(this.g<<8)+this.b).toString(16).slice(1)}};function Z(...n){if(n.length===0)return new J(255,255,255);if(n.length===1){if(n[0]instanceof J)return n[0].clone();if(typeof n[0]=="string")return J.fromHex(n[0]);if(Array.isArray(n[0])&&n[0].length===3)return J.fromArray(n[0])}return new J(...n)}o(Z,"rgb");var Fs=o((n,e,r)=>J.fromHSL(n,e,r),"hsl2rgb"),ce=class n{static{o(this,"Quad")}x=0;y=0;w=1;h=1;constructor(e,r,c,h){this.x=e,this.y=r,this.w=c,this.h=h}scale(e){return new n(this.x+this.w*e.x,this.y+this.h*e.y,this.w*e.w,this.h*e.h)}pos(){return new x(this.x,this.y)}clone(){return new n(this.x,this.y,this.w,this.h)}eq(e){return this.x===e.x&&this.y===e.y&&this.w===e.w&&this.h===e.h}toString(){return`quad(${this.x}, ${this.y}, ${this.w}, ${this.h})`}};function me(n,e,r,c){return new ce(n,e,r,c)}o(me,"quad");var Ct=class n{static{o(this,"Mat2")}a;b;c;d;constructor(e,r,c,h){this.a=e,this.b=r,this.c=c,this.d=h}mul(e){return new n(this.a*e.a+this.b*e.c,this.a*e.b+this.b*e.d,this.c*e.a+this.d*e.c,this.c*e.b+this.d*e.d)}transform(e){return M(this.a*e.x+this.b*e.y,this.c*e.x+this.d*e.y)}get inverse(){let e=this.det;return new n(this.d/e,-this.b/e,-this.c/e,this.a/e)}get transpose(){return new n(this.a,this.c,this.b,this.d)}get eigenvalues(){let e=this.trace/2,r=this.det,c=e+Math.sqrt(e*e-r),h=e-Math.sqrt(e*e-r);return[c,h]}eigenvectors(e,r){return this.c!=0?[[e-this.d,this.c],[r-this.d,this.c]]:this.b!=0?[[this.b,e-this.a],[this.b,r-this.a]]:Math.abs(this.transform(M(1,0)).x-e)<Number.EPSILON?[[1,0],[0,1]]:[[0,1],[1,0]]}get det(){return this.a*this.d-this.b*this.c}get trace(){return this.a+this.d}static rotation(e){let r=Math.cos(e),c=Math.sin(e);return new n(r,c,-c,r)}static scale(e,r){return new n(e,0,0,r)}};var ht=class n{static{o(this,"Mat3")}m11;m12;m13;m21;m22;m23;m31;m32;m33;constructor(e,r,c,h,m,y,C,O,v){this.m11=e,this.m12=r,this.m13=c,this.m21=h,this.m22=m,this.m23=y,this.m31=C,this.m32=O,this.m33=v}static fromMat2(e){return new n(e.a,e.b,0,e.c,e.d,0,0,0,1)}toMat2(){return new Ct(this.m11,this.m12,this.m21,this.m22)}mul(e){return new n(this.m11*e.m11+this.m12*e.m21+this.m13*e.m31,this.m11*e.m12+this.m12*e.m22+this.m13*e.m32,this.m11*e.m13+this.m12*e.m23+this.m13*e.m33,this.m21*e.m11+this.m22*e.m21+this.m23*e.m31,this.m21*e.m12+this.m22*e.m22+this.m23*e.m32,this.m21*e.m13+this.m22*e.m23+this.m23*e.m33,this.m31*e.m11+this.m32*e.m21+this.m33*e.m31,this.m31*e.m12+this.m32*e.m22+this.m33*e.m32,this.m31*e.m13+this.m32*e.m23+this.m33*e.m33)}get det(){return this.m11*this.m22*this.m33+this.m12*this.m23*this.m31+this.m13*this.m21*this.m32-this.m13*this.m22*this.m31-this.m12*this.m21*this.m33-this.m11*this.m23*this.m32}get inverse(){let e=this.det;return new n((this.m22*this.m33-this.m23*this.m32)/e,(this.m13*this.m32-this.m12*this.m33)/e,(this.m12*this.m23-this.m13*this.m22)/e,(this.m23*this.m31-this.m21*this.m33)/e,(this.m11*this.m33-this.m13*this.m31)/e,(this.m13*this.m21-this.m11*this.m23)/e,(this.m21*this.m32-this.m22*this.m31)/e,(this.m12*this.m31-this.m11*this.m32)/e,(this.m11*this.m22-this.m12*this.m21)/e)}get transpose(){return new n(this.m11,this.m21,this.m31,this.m12,this.m22,this.m32,this.m13,this.m23,this.m33)}},Ge=class n{static{o(this,"Mat4")}m=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];constructor(e){e&&(this.m=e)}static translate(e){return new n([1,0,0,0,0,1,0,0,0,0,1,0,e.x,e.y,0,1])}static scale(e){return new n([e.x,0,0,0,0,e.y,0,0,0,0,1,0,0,0,0,1])}static rotateX(e){e=we(-e);let r=Math.cos(e),c=Math.sin(e);return new n([1,0,0,0,0,r,-c,0,0,c,r,0,0,0,0,1])}static rotateY(e){e=we(-e);let r=Math.cos(e),c=Math.sin(e);return new n([r,0,c,0,0,1,0,0,-c,0,r,0,0,0,0,1])}static rotateZ(e){e=we(-e);let r=Math.cos(e),c=Math.sin(e);return new n([r,-c,0,0,c,r,0,0,0,0,1,0,0,0,0,1])}translate(e){return this.m[12]+=this.m[0]*e.x+this.m[4]*e.y,this.m[13]+=this.m[1]*e.x+this.m[5]*e.y,this.m[14]+=this.m[2]*e.x+this.m[6]*e.y,this.m[15]+=this.m[3]*e.x+this.m[7]*e.y,this}scale(e){return this.m[0]*=e.x,this.m[4]*=e.y,this.m[1]*=e.x,this.m[5]*=e.y,this.m[2]*=e.x,this.m[6]*=e.y,this.m[3]*=e.x,this.m[7]*=e.y,this}rotate(e){e=we(-e);let r=Math.cos(e),c=Math.sin(e),h=this.m[0],m=this.m[1],y=this.m[4],C=this.m[5];return this.m[0]=h*r+m*c,this.m[1]=-h*c+m*r,this.m[4]=y*r+C*c,this.m[5]=-y*c+C*r,this}mult(e){let r=[];for(let c=0;c<4;c++)for(let h=0;h<4;h++)r[c*4+h]=this.m[0*4+h]*e.m[c*4+0]+this.m[1*4+h]*e.m[c*4+1]+this.m[2*4+h]*e.m[c*4+2]+this.m[3*4+h]*e.m[c*4+3];return new n(r)}multVec2(e){return new x(e.x*this.m[0]+e.y*this.m[4]+this.m[12],e.x*this.m[1]+e.y*this.m[5]+this.m[13])}getTranslation(){return new x(this.m[12],this.m[13])}getScale(){if(this.m[0]!=0||this.m[1]!=0){let e=this.m[0]*this.m[5]-this.m[1]*this.m[4],r=Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]);return new x(r,e/r)}else if(this.m[4]!=0||this.m[5]!=0){let e=this.m[0]*this.m[5]-this.m[1]*this.m[4],r=Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]);return new x(e/r,r)}else return new x(0,0)}getRotation(){if(this.m[0]!=0||this.m[1]!=0){let e=Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]);return lt(this.m[1]>0?Math.acos(this.m[0]/e):-Math.acos(this.m[0]/e))}else if(this.m[4]!=0||this.m[5]!=0){let e=Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]);return lt(Math.PI/2-(this.m[5]>0?Math.acos(-this.m[4]/e):-Math.acos(this.m[4]/e)))}else return 0}getSkew(){if(this.m[0]!=0||this.m[1]!=0){let e=Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]);return new x(Math.atan(this.m[0]*this.m[4]+this.m[1]*this.m[5])/(e*e),0)}else if(this.m[4]!=0||this.m[5]!=0){let e=Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]);return new x(0,Math.atan(this.m[0]*this.m[4]+this.m[1]*this.m[5])/(e*e))}else return new x(0,0)}invert(){let e=[],r=this.m[10]*this.m[15]-this.m[14]*this.m[11],c=this.m[9]*this.m[15]-this.m[13]*this.m[11],h=this.m[9]*this.m[14]-this.m[13]*this.m[10],m=this.m[8]*this.m[15]-this.m[12]*this.m[11],y=this.m[8]*this.m[14]-this.m[12]*this.m[10],C=this.m[8]*this.m[13]-this.m[12]*this.m[9],O=this.m[6]*this.m[15]-this.m[14]*this.m[7],v=this.m[5]*this.m[15]-this.m[13]*this.m[7],z=this.m[5]*this.m[14]-this.m[13]*this.m[6],T=this.m[4]*this.m[15]-this.m[12]*this.m[7],V=this.m[4]*this.m[14]-this.m[12]*this.m[6],U=this.m[5]*this.m[15]-this.m[13]*this.m[7],_=this.m[4]*this.m[13]-this.m[12]*this.m[5],K=this.m[6]*this.m[11]-this.m[10]*this.m[7],$=this.m[5]*this.m[11]-this.m[9]*this.m[7],L=this.m[5]*this.m[10]-this.m[9]*this.m[6],ne=this.m[4]*this.m[11]-this.m[8]*this.m[7],A=this.m[4]*this.m[10]-this.m[8]*this.m[6],le=this.m[4]*this.m[9]-this.m[8]*this.m[5];e[0]=this.m[5]*r-this.m[6]*c+this.m[7]*h,e[4]=-(this.m[4]*r-this.m[6]*m+this.m[7]*y),e[8]=this.m[4]*c-this.m[5]*m+this.m[7]*C,e[12]=-(this.m[4]*h-this.m[5]*y+this.m[6]*C),e[1]=-(this.m[1]*r-this.m[2]*c+this.m[3]*h),e[5]=this.m[0]*r-this.m[2]*m+this.m[3]*y,e[9]=-(this.m[0]*c-this.m[1]*m+this.m[3]*C),e[13]=this.m[0]*h-this.m[1]*y+this.m[2]*C,e[2]=this.m[1]*O-this.m[2]*v+this.m[3]*z,e[6]=-(this.m[0]*O-this.m[2]*T+this.m[3]*V),e[10]=this.m[0]*U-this.m[1]*T+this.m[3]*_,e[14]=-(this.m[0]*z-this.m[1]*V+this.m[2]*_),e[3]=-(this.m[1]*K-this.m[2]*$+this.m[3]*L),e[7]=this.m[0]*K-this.m[2]*ne+this.m[3]*A,e[11]=-(this.m[0]*$-this.m[1]*ne+this.m[3]*le),e[15]=this.m[0]*L-this.m[1]*A+this.m[2]*le;let j=this.m[0]*e[0]+this.m[1]*e[4]+this.m[2]*e[8]+this.m[3]*e[12];for(let de=0;de<4;de++)for(let ie=0;ie<4;ie++)e[de*4+ie]*=1/j;return new n(e)}clone(){return new n([...this.m])}toString(){return this.m.toString()}};function Yn(n,e,r,c=h=>-Math.cos(h)){return n+(c(r)+1)/2*(e-n)}o(Yn,"wave");var $i=1103515245,Xi=12345,Is=2147483648,Vt=class{static{o(this,"RNG")}seed;constructor(e){this.seed=e}gen(){return this.seed=($i*this.seed+Xi)%Is,this.seed/Is}genNumber(e,r){return e+this.gen()*(r-e)}genVec2(e,r){return new x(this.genNumber(e.x,r.x),this.genNumber(e.y,r.y))}genColor(e,r){return new J(this.genNumber(e.r,r.r),this.genNumber(e.g,r.g),this.genNumber(e.b,r.b))}genAny(...e){if(e.length===0)return this.gen();if(e.length===1){if(typeof e[0]=="number")return this.genNumber(0,e[0]);if(e[0]instanceof x)return this.genVec2(M(0,0),e[0]);if(e[0]instanceof J)return this.genColor(Z(0,0,0),e[0])}else if(e.length===2){if(typeof e[0]=="number"&&typeof e[1]=="number")return this.genNumber(e[0],e[1]);if(e[0]instanceof x&&e[1]instanceof x)return this.genVec2(e[0],e[1]);if(e[0]instanceof J&&e[1]instanceof J)return this.genColor(e[0],e[1])}}},zn=new Vt(Date.now());function Ls(n){return n!=null&&(zn.seed=n),zn.seed}o(Ls,"randSeed");function Nt(...n){return zn.genAny(...n)}o(Nt,"rand");function $n(...n){return Math.floor(Nt(...n))}o($n,"randi");function Vs(n){return Nt()<=n}o(Vs,"chance");function Xn(n){for(let e=n.length-1;e>0;e--){let r=Math.floor(Math.random()*(e+1));[n[e],n[r]]=[n[r],n[e]]}return n}o(Xn,"shuffle");function Ns(n,e){return n.length<=e?n.slice():Xn(n.slice()).slice(0,e)}o(Ns,"chooseMultiple");function ks(n){return n[$n(n.length)]}o(ks,"choose");function Kn(n,e){return n.pos.x+n.width>e.pos.x&&n.pos.x<e.pos.x+e.width&&n.pos.y+n.height>e.pos.y&&n.pos.y<e.pos.y+e.height}o(Kn,"testRectRect");function Ki(n,e){if(n.p1.x===n.p2.x&&n.p1.y===n.p2.y||e.p1.x===e.p2.x&&e.p1.y===e.p2.y)return null;let r=(e.p2.y-e.p1.y)*(n.p2.x-n.p1.x)-(e.p2.x-e.p1.x)*(n.p2.y-n.p1.y);if(r===0)return null;let c=((e.p2.x-e.p1.x)*(n.p1.y-e.p1.y)-(e.p2.y-e.p1.y)*(n.p1.x-e.p1.x))/r,h=((n.p2.x-n.p1.x)*(n.p1.y-e.p1.y)-(n.p2.y-n.p1.y)*(n.p1.x-e.p1.x))/r;return c<0||c>1||h<0||h>1?null:c}o(Ki,"testLineLineT");function cn(n,e){let r=Ki(n,e);return r?M(n.p1.x+r*(n.p2.x-n.p1.x),n.p1.y+r*(n.p2.y-n.p1.y)):null}o(cn,"testLineLine");function hn(n,e){let r=e.p2.sub(e.p1),c=Number.NEGATIVE_INFINITY,h=Number.POSITIVE_INFINITY;if(r.x!=0){let m=(n.pos.x-e.p1.x)/r.x,y=(n.pos.x+n.width-e.p1.x)/r.x;c=Math.max(c,Math.min(m,y)),h=Math.min(h,Math.max(m,y))}if(r.y!=0){let m=(n.pos.y-e.p1.y)/r.y,y=(n.pos.y+n.height-e.p1.y)/r.y;c=Math.max(c,Math.min(m,y)),h=Math.min(h,Math.max(m,y))}return h>=c&&h>=0&&c<=1}o(hn,"testRectLine");function ln(n,e){return e.x>n.pos.x&&e.x<n.pos.x+n.width&&e.y>n.pos.y&&e.y<n.pos.y+n.height}o(ln,"testRectPoint");function _s(n,e){let r=Math.max(n.pos.x,Math.min(e.center.x,n.pos.x+n.width)),c=Math.max(n.pos.y,Math.min(e.center.y,n.pos.y+n.height));return M(r,c).sdist(e.center)<=e.radius*e.radius}o(_s,"testRectCircle");function js(n,e){return Hs(e,new Ee(n.points()))}o(js,"testRectPolygon");function Wn(n,e){let r=e.sub(n.p1),c=n.p2.sub(n.p1);if(Math.abs(r.cross(c))>Number.EPSILON)return!1;let h=r.dot(c)/c.dot(c);return h>=0&&h<=1}o(Wn,"testLinePoint");function At(n,e){let r=n.p2.sub(n.p1),c=r.dot(r),h=n.p1.sub(e.center),m=2*r.dot(h),y=h.dot(h)-e.radius*e.radius,C=m*m-4*c*y;if(c<=Number.EPSILON||C<0)return!1;if(C==0){let O=-m/(2*c);if(O>=0&&O<=1)return!0}else{let O=(-m+Math.sqrt(C))/(2*c),v=(-m-Math.sqrt(C))/(2*c);if(O>=0&&O<=1||v>=0&&v<=1)return!0}return Qn(e,n.p1)}o(At,"testLineCircle");function Jn(n,e){if(dt(e,n.p1)||dt(e,n.p2))return!0;for(let r=0;r<e.pts.length;r++){let c=e.pts[r],h=e.pts[(r+1)%e.pts.length];if(cn(n,new Ie(c,h)))return!0}return!1}o(Jn,"testLinePolygon");function Qn(n,e){return n.center.sdist(e)<n.radius*n.radius}o(Qn,"testCirclePoint");function Wi(n,e){return n.center.sdist(e.center)<(n.radius+e.radius)*(n.radius+e.radius)}o(Wi,"testCircleCircle");function kt(n,e){let r=e.pts[e.pts.length-1];for(let c of e.pts){if(At(new Ie(r,c),n))return!0;r=c}return Qn(n,e.pts[0])?!0:dt(e,n.center)}o(kt,"testCirclePolygon");function Hs(n,e){for(let r=0;r<n.pts.length;r++)if(Jn(new Ie(n.pts[r],n.pts[(r+1)%n.pts.length]),e))return!0;return!!(n.pts.some(r=>dt(e,r))||e.pts.some(r=>dt(n,r)))}o(Hs,"testPolygonPolygon");function dt(n,e){let r=!1,c=n.pts;for(let h=0,m=c.length-1;h<c.length;m=h++)c[h].y>e.y!=c[m].y>e.y&&e.x<(c[m].x-c[h].x)*(e.y-c[h].y)/(c[m].y-c[h].y)+c[h].x&&(r=!r);return r}o(dt,"testPolygonPoint");function qs(n,e){e=e.sub(n.center);let r=we(n.angle),c=Math.cos(r),h=Math.sin(r),m=e.x*c+e.y*h,y=-e.x*h+e.y*c;return m*m/(n.radiusX*n.radiusX)+y*y/(n.radiusY*n.radiusY)<1}o(qs,"testEllipsePoint");function un(n,e){let r=e.center.sub(n.center),c=we(n.angle),h=Math.cos(c),m=Math.sin(c),y=r.x*h+r.y*m,C=-r.x*m+r.y*h;return qs(new Ye(M(),n.radiusX+e.radius,n.radiusY+e.radius,0),M(y,C))}o(un,"testEllipseCircle");function zs(n,e){let r=n.toMat2().inverse;return e=new Ie(r.transform(e.p1.sub(n.center)),r.transform(e.p2.sub(n.center))),At(e,new Me(M(),1))}o(zs,"testEllipseLine");function Ji(n,e){if(n.radiusX===n.radiusY)return un(e,new Me(n.center,n.radiusX));if(e.radiusX===e.radiusY)return un(n,new Me(e.center,e.radiusX));let r=new ht(1/n.radiusX**2,0,0,0,1/n.radiusY**2,0,0,0,-1),c=new ht(1/e.radiusX**2,0,0,0,1/e.radiusY**2,0,0,0,-1),h=n.center.x,m=n.center.y,y=e.center.x,C=e.center.y,O=we(n.angle),v=we(e.angle),z=new ht(Math.cos(O),-Math.sin(O),h,Math.sin(O),Math.cos(O),m,0,0,1),T=new ht(Math.cos(v),-Math.sin(v),y,Math.sin(v),Math.cos(v),C,0,0,1),V=z.inverse,U=T.inverse,_=V.transpose.mul(r).mul(V),K=U.transpose.mul(c).mul(U),$=_.m11,L=_.m12,ne=_.m13,A=_.m21,le=_.m22,j=_.m23,de=_.m31,ie=_.m32,ae=_.m33,Se=K.m11,Ne=K.m12,Fe=K.m13,Le=K.m21,Ve=K.m22,ye=K.m23,ke=K.m31,_e=K.m32,je=K.m33,ft=$*le*ae-$*j*ie-L*A*ae+L*j*de+ne*A*ie-ne*le*de,Te=($*le*je-$*j*_e-$*ie*ye+$*ae*Ve-L*A*je+L*j*ke+L*de*ye-L*ae*Le+ne*A*_e-ne*le*ke-ne*de*Ve+ne*ie*Le+A*ie*Fe-A*ae*Ne-le*de*Fe+le*ae*Se+j*de*Ne-j*ie*Se)/ft,Oe=($*Ve*je-$*ye*_e-L*Le*je+L*ye*ke+ne*Le*_e-ne*Ve*ke-A*Ne*je+A*Fe*_e+le*Se*je-le*Fe*ke-j*Se*_e+j*Ne*ke+de*Ne*ye-de*Fe*Ve-ie*Se*ye+ie*Fe*Le+ae*Se*Ve-ae*Ne*Le)/ft,ze=(Se*Ve*je-Se*ye*_e-Ne*Le*je+Ne*ye*ke+Fe*Le*_e-Fe*Ve*ke)/ft;if(Te>=0){let rt=-3*Oe+Te**2,it=3*Te*ze+Oe*Te**2-4*Oe**2,Et=-27*ze**2+18*ze*Te*Oe+Te**2*Oe**2-4*Te**3*ze-4*Oe**3;return!(rt>0&&it<0&&Et>0)}else{let rt=-3*Oe+Te**2,it=-27*ze**2+18*ze*Te*Oe+Te**2*Oe**2-4*Te**3*ze-4*Oe**3;return!(rt>0&&it>0)}}o(Ji,"testEllipseEllipse");function Ys(n,e){return Zn(n,new Ee(e.points()))}o(Ys,"testEllipseRect");function Zn(n,e){let r=n.toMat2().inverse;return e=new Ee(e.pts.map(c=>r.transform(c.sub(n.center)))),kt(new Me(M(),1),e)}o(Zn,"testEllipsePolygon");function Qi(n,e){return e instanceof x?Wn(n,e):e instanceof Me?At(n,e):e instanceof Ie?cn(n,e)!=null:e instanceof re?hn(e,n):e instanceof Ee?Jn(n,e):e instanceof Ye?zs(e,n):!1}o(Qi,"testLineShape");function Zi(n,e){return e instanceof x?Qn(n,e):e instanceof Me?Wi(n,e):e instanceof Ie?At(e,n):e instanceof re?_s(e,n):e instanceof Ee?kt(n,e):e instanceof Ye?un(e,n):!1}o(Zi,"testCircleShape");function eo(n,e){return e instanceof x?ln(n,e):e instanceof Me?_s(n,e):e instanceof Ie?hn(n,e):e instanceof re?Kn(n,e):e instanceof Ee?js(n,e):e instanceof Ye?Ys(e,n):!1}o(eo,"testRectShape");function to(n,e){return e instanceof x?dt(n,e):e instanceof Me?kt(e,n):e instanceof Ie?Jn(e,n):e instanceof re?js(e,n):e instanceof Ee?Hs(e,n):e instanceof Ye?Zn(e,n):!1}o(to,"testPolygonShape");function no(n,e){return e instanceof x?qs(n,e):e instanceof Me?un(n,e):e instanceof Ie?zs(n,e):e instanceof re?Ys(n,e):e instanceof Ee?Zn(n,e):e instanceof Ye?Ji(e,n):!1}o(no,"testEllipseShape");function $s(n,e,r){let c=n,h=r.p1,m=r.p2,y=e,C=m.sub(h),O=y.cross(C);if(Math.abs(O)<Number.EPSILON)return null;let v=h.sub(c),z=v.cross(C)/O;if(z<=0||z>=1)return null;let T=v.cross(y)/O;if(T<=0||T>=1)return null;let V=C.normal().unit();return e.dot(V)>0&&(V.x*=-1,V.y*=-1),{point:c.add(y.scale(z)),normal:V,fraction:z}}o($s,"raycastLine");function so(n,e,r){let c=Number.NEGATIVE_INFINITY,h=Number.POSITIVE_INFINITY,m;if(n.x!=0){let y=(r.pos.x-n.x)/e.x,C=(r.pos.x+r.width-n.x)/e.x;m=M(-Math.sign(e.x),0),c=Math.max(c,Math.min(y,C)),h=Math.min(h,Math.max(y,C))}if(n.y!=0){let y=(r.pos.y-n.y)/e.y,C=(r.pos.y+r.height-n.y)/e.y;Math.min(y,C)>c&&(m=M(0,-Math.sign(e.y))),c=Math.max(c,Math.min(y,C)),h=Math.min(h,Math.max(y,C))}return h>=c&&c>=0&&c<=1?{point:n.add(e.scale(c)),normal:m,fraction:c}:null}o(so,"raycastRect");function Xs(n,e,r){let c=n,h=r.center,m=e,y=m.dot(m),C=c.sub(h),O=2*m.dot(C),v=C.dot(C)-r.radius*r.radius,z=O*O-4*y*v;if(y<=Number.EPSILON||z<0)return null;if(z==0){let T=-O/(2*y);if(T>=0&&T<=1){let V=c.add(m.scale(T));return{point:V,normal:V.sub(h),fraction:T}}}else{let T=(-O+Math.sqrt(z))/(2*y),V=(-O-Math.sqrt(z))/(2*y),U=null;if(T>=0&&T<=1&&(U=T),V>=0&&V<=1&&(U=Math.min(V,U??V)),U!=null){let _=c.add(m.scale(U));return{point:_,normal:_.sub(h).unit(),fraction:U}}}return null}o(Xs,"raycastCircle");function ro(n,e,r){let c=r.pts,h=null,m=c[c.length-1];for(let y=0;y<c.length;y++){let C=c[y],O=$s(n,e,new Ie(m,C));O&&(!h||h.fraction>O.fraction)&&(h=O),m=C}return h}o(ro,"raycastPolygon");function io(n,e,r){let c=r.toMat2(),h=c.inverse,m=h.transform(n.sub(r.center)),y=h.transform(e),C=Xs(m,y,new Me(M(),1));if(C){let O=Ct.rotation(we(-r.angle)),z=Ct.scale(r.radiusX,r.radiusY).transform(C.point),T=c.transform(C.point).add(r.center),V=T.dist(n)/e.len();return{point:T,normal:O.transform(M(r.radiusY**2*z.x,r.radiusX**2*z.y)),fraction:V}}return C}o(io,"raycastEllipse");var Ie=class n{static{o(this,"Line")}p1;p2;constructor(e,r){this.p1=e.clone(),this.p2=r.clone()}transform(e){return new n(e.multVec2(this.p1),e.multVec2(this.p2))}bbox(){return re.fromPoints(this.p1,this.p2)}area(){return this.p1.dist(this.p2)}clone(){return new n(this.p1,this.p2)}collides(e){return Qi(this,e)}contains(e){return this.collides(e)}raycast(e,r){return $s(e,r,this)}},re=class n{static{o(this,"Rect")}pos;width;height;constructor(e,r,c){this.pos=e.clone(),this.width=r,this.height=c}static fromPoints(e,r){return new n(e.clone(),r.x-e.x,r.y-e.y)}center(){return new x(this.pos.x+this.width/2,this.pos.y+this.height/2)}points(){return[this.pos,this.pos.add(this.width,0),this.pos.add(this.width,this.height),this.pos.add(0,this.height)]}transform(e){return new Ee(this.points().map(r=>e.multVec2(r)))}bbox(){return this.clone()}area(){return this.width*this.height}clone(){return new n(this.pos.clone(),this.width,this.height)}distToPoint(e){return Math.sqrt(this.sdistToPoint(e))}sdistToPoint(e){let r=this.pos,c=this.pos.add(this.width,this.height),h=Math.max(r.x-e.x,0,e.x-c.x),m=Math.max(r.y-e.y,0,e.y-c.y);return h*h+m*m}collides(e){return eo(this,e)}contains(e){return this.collides(e)}raycast(e,r){return so(e,r,this)}},Me=class n{static{o(this,"Circle")}center;radius;constructor(e,r){this.center=e.clone(),this.radius=r}transform(e){return new Ye(this.center,this.radius,this.radius).transform(e)}bbox(){return re.fromPoints(this.center.sub(M(this.radius)),this.center.add(M(this.radius)))}area(){return this.radius*this.radius*Math.PI}clone(){return new n(this.center,this.radius)}collides(e){return Zi(this,e)}contains(e){return this.collides(e)}raycast(e,r){return Xs(e,r,this)}},Ye=class n{static{o(this,"Ellipse")}center;radiusX;radiusY;angle;constructor(e,r,c,h=0){this.center=e.clone(),this.radiusX=r,this.radiusY=c,this.angle=h}static fromMat2(e){let r=e.inverse,c=r.transpose.mul(r),[h,m]=c.eigenvalues,[y,C]=c.eigenvectors(h,m),[O,v]=[1/Math.sqrt(h),1/Math.sqrt(m)];return O>v?new n(M(),O,v,lt(Math.atan2(-y[1],y[0]))):new n(M(),v,O,lt(Math.atan2(-C[1],C[0])))}toMat2(){let e=we(-this.angle),r=Math.cos(e),c=Math.sin(e);return new Ct(r*this.radiusX,c*this.radiusY,-c*this.radiusX,r*this.radiusY)}transform(e){if(this.angle==0&&e.getRotation()==0)return new n(e.multVec2(this.center),e.m[0]*this.radiusX,e.m[5]*this.radiusY);{let r=this.toMat2(),c=new ht(e.m[0],e.m[1],0,e.m[4],e.m[5],0,e.m[12],e.m[13],1);r=c.transpose.mul(ht.fromMat2(r)).mul(c).toMat2();let m=n.fromMat2(r);return m.center=e.multVec2(this.center),m}}bbox(){if(this.angle==0)return re.fromPoints(this.center.sub(M(this.radiusX,this.radiusY)),this.center.add(M(this.radiusX,this.radiusY)));{let e=we(this.angle),r=Math.cos(e),c=Math.sin(e),h=this.radiusX*r,m=this.radiusX*c,y=this.radiusY*c,C=this.radiusY*r,O=Math.sqrt(h*h+y*y),v=Math.sqrt(m*m+C*C);return re.fromPoints(this.center.sub(M(O,v)),this.center.add(M(O,v)))}}area(){return this.radiusX*this.radiusY*Math.PI}clone(){return new n(this.center,this.radiusX,this.radiusY,this.angle)}collides(e){return no(this,e)}contains(e){e=e.sub(this.center);let r=we(this.angle),c=Math.cos(r),h=Math.sin(r),m=e.x*c+e.y*h,y=-e.x*h+e.y*c;return m*m/(this.radiusX*this.radiusX)+y*y/(this.radiusY*this.radiusY)<1}raycast(e,r){return io(e,r,this)}},Ee=class n{static{o(this,"Polygon")}pts;constructor(e){if(e.length<3)throw new Error("Polygons should have at least 3 vertices");this.pts=e}transform(e){return new n(this.pts.map(r=>e.multVec2(r)))}bbox(){let e=M(Number.MAX_VALUE),r=M(-Number.MAX_VALUE);for(let c of this.pts)e.x=Math.min(e.x,c.x),r.x=Math.max(r.x,c.x),e.y=Math.min(e.y,c.y),r.y=Math.max(r.y,c.y);return re.fromPoints(e,r)}area(){let e=0,r=this.pts.length;for(let c=0;c<r;c++){let h=this.pts[c],m=this.pts[(c+1)%r];e+=h.x*m.y*.5,e-=m.x*h.y*.5}return Math.abs(e)}clone(){return new n(this.pts.map(e=>e.clone()))}collides(e){return to(this,e)}contains(e){return this.collides(e)}raycast(e,r){return ro(e,r,this)}};function es(n,e,r,c,h){let m=h*h,y=m*h,C=1-h,O=C*C,v=O*C;return n.scale(v).add(e.scale(3*O*h)).add(r.scale(3*C*m)).add(c.scale(y))}o(es,"evaluateBezier");function Ks(n,e){let r=Number.MAX_VALUE,c=M(0);for(let h of[n,e])for(let m=0;m<h.pts.length;m++){let y=h.pts[m],O=h.pts[(m+1)%h.pts.length].sub(y).normal().unit(),v=Number.MAX_VALUE,z=-Number.MAX_VALUE;for(let _=0;_<n.pts.length;_++){let K=n.pts[_].dot(O);v=Math.min(v,K),z=Math.max(z,K)}let T=Number.MAX_VALUE,V=-Number.MAX_VALUE;for(let _=0;_<e.pts.length;_++){let K=e.pts[_].dot(O);T=Math.min(T,K),V=Math.max(V,K)}let U=Math.min(z,V)-Math.max(v,T);if(U<0)return null;if(U<Math.abs(r)){let _=V-v,K=T-z;r=Math.abs(_)<Math.abs(K)?_:K,c=O.scale(r)}}return c}o(Ks,"sat");var _t=class extends Map{static{o(this,"Registry")}lastID=0;push(e){let r=this.lastID;return this.set(r,e),this.lastID++,r}pushd(e){let r=this.push(e);return()=>this.delete(r)}},tt=class n{static{o(this,"EventController")}paused=!1;cancel;constructor(e){this.cancel=e}static join(e){let r=new n(()=>e.forEach(c=>c.cancel()));return Object.defineProperty(r,"paused",{get:()=>e[0].paused,set:c=>e.forEach(h=>h.paused=c)}),r.paused=!1,r}},Ue=class{static{o(this,"Event")}handlers=new _t;add(e){let r=this.handlers.pushd((...h)=>{c.paused||e(...h)}),c=new tt(r);return c}addOnce(e){let r=this.add((...c)=>{r.cancel(),e(...c)});return r}next(){return new Promise(e=>this.addOnce(e))}trigger(...e){this.handlers.forEach(r=>r(...e))}numListeners(){return this.handlers.size}clear(){this.handlers.clear()}},nt=class{static{o(this,"EventHandler")}handlers={};on(e,r){return this.handlers[e]||(this.handlers[e]=new Ue),this.handlers[e].add(r)}onOnce(e,r){let c=this.on(e,(...h)=>{c.cancel(),r(...h)});return c}next(e){return new Promise(r=>{this.onOnce(e,(...c)=>r(c[0]))})}trigger(e,...r){this.handlers[e]&&this.handlers[e].trigger(...r)}remove(e){delete this.handlers[e]}clear(){this.handlers={}}numListeners(e){return this.handlers[e]?.numListeners()??0}};function fn(n,e){if(n===e)return!0;let r=typeof n,c=typeof e;if(r!==c)return!1;if(r==="object"&&c==="object"&&n!==null&&e!==null){if(Array.isArray(n)!==Array.isArray(e))return!1;let h=Object.keys(n),m=Object.keys(e);if(h.length!==m.length)return!1;for(let y of h){let C=n[y],O=e[y];if(!fn(C,O))return!1}return!0}return!1}o(fn,"deepEq");function oo(n){let e=window.atob(n),r=e.length,c=new Uint8Array(r);for(let h=0;h<r;h++)c[h]=e.charCodeAt(h);return c.buffer}o(oo,"base64ToArrayBuffer");function Js(n){return oo(n.split(",")[1])}o(Js,"dataURLToArrayBuffer");function mn(n,e){let r=document.createElement("a");r.href=e,r.download=n,r.click()}o(mn,"download");function ts(n,e){mn(n,"data:text/plain;charset=utf-8,"+e)}o(ts,"downloadText");function Qs(n,e){ts(n,JSON.stringify(e))}o(Qs,"downloadJSON");function ns(n,e){let r=URL.createObjectURL(e);mn(n,r),URL.revokeObjectURL(r)}o(ns,"downloadBlob");var ss=o(n=>n.match(/^data:\w+\/\w+;base64,.+/),"isDataURL");var Zs=o(n=>n.split(".").slice(0,-1).join("."),"getFileName");function Be(n,e){return(...r)=>{let c=r.length;if(c===n.length)return n(...r);if(c===e.length)return e(...r)}}o(Be,"overload2");var er=(()=>{let n=0;return()=>n++})(),tr=o(n=>n instanceof Error?n.message:String(n),"getErrorMessage");var dn=class{static{o(this,"BinaryHeap")}_items;_compareFn;constructor(e=(r,c)=>r<c){this._compareFn=e,this._items=[]}insert(e){this._items.push(e),this.moveUp(this._items.length-1)}remove(){if(this._items.length===0)return null;let e=this._items[0],r=this._items.pop();return this._items.length!==0&&(this._items[0]=r,this.moveDown(0)),e}clear(){this._items.splice(0,this._items.length)}moveUp(e){for(;e>0;){let r=Math.floor((e-1)/2);if(!this._compareFn(this._items[e],this._items[r])&&this._items[e]>=this._items[r])break;this.swap(e,r),e=r}}moveDown(e){for(;e<Math.floor(this._items.length/2);){let r=2*e+1;if(r<this._items.length-1&&!this._compareFn(this._items[r],this._items[r+1])&&++r,this._compareFn(this._items[e],this._items[r]))break;this.swap(e,r),e=r}}swap(e,r){[this._items[e],this._items[r]]=[this._items[r],this._items[e]]}get length(){return this._items.length}};var ao=Object.freeze([776,2359,2367,2984,3007,3021,3633,3635,3648,3657,4352,4449,4520]);function nr(n){if(typeof n!="string")throw new TypeError("string cannot be undefined or null");let e=[],r=0,c=0;for(;r<n.length;){if(c+=uo(r+c,n),go(n[r+c])&&c++,fo(n[r+c])&&c++,mo(n[r+c])&&c++,wo(n[r+c])){c++;continue}e.push(n.substring(r,r+c)),r+=c,c=0}return e}o(nr,"runes");function uo(n,e){let r=e[n];if(!co(r)||n===e.length-1)return 1;let c=r+e[n+1],h=e.substring(n+2,n+5);return Ws(c)&&Ws(h)?4:ho(c)&&po(h)?e.slice(n).indexOf(String.fromCodePoint(917631))+2:lo(h)?4:2}o(uo,"nextUnits");function co(n){return n&&vt(n[0].charCodeAt(0),55296,56319)}o(co,"isFirstOfSurrogatePair");function Ws(n){return vt(rs(n),127462,127487)}o(Ws,"isRegionalIndicator");function ho(n){return vt(rs(n),127988,127988)}o(ho,"isSubdivisionFlag");function lo(n){return vt(rs(n),127995,127999)}o(lo,"isFitzpatrickModifier");function fo(n){return typeof n=="string"&&vt(n.charCodeAt(0),65024,65039)}o(fo,"isVariationSelector");function mo(n){return typeof n=="string"&&vt(n.charCodeAt(0),8400,8447)}o(mo,"isDiacriticalMark");function po(n){let e=n.codePointAt(0);return typeof n=="string"&&typeof e=="number"&&vt(e,917504,917631)}o(po,"isSupplementarySpecialpurposePlane");function go(n){return typeof n=="string"&&ao.includes(n.charCodeAt(0))}o(go,"isGrapheme");function wo(n){return typeof n=="string"&&n.charCodeAt(0)===8205}o(wo,"isZeroWidthJoiner");function rs(n){let e=n.charCodeAt(0)-55296,r=n.charCodeAt(1)-56320;return(e<<10)+r+65536}o(rs,"codePointFromSurrogatePair");function vt(n,e,r){return n>=e&&n<=r}o(vt,"betweenInclusive");var is={"Joy-Con L+R (STANDARD GAMEPAD Vendor: 057e Product: 200e)":{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","6":"ltrigger","7":"rtrigger","8":"select","9":"start","10":"lstick","11":"rstick","12":"dpad-up","13":"dpad-down","14":"dpad-left","15":"dpad-right","16":"home","17":"capture"},sticks:{left:{x:0,y:1},right:{x:2,y:3}}},"Joy-Con (L) (STANDARD GAMEPAD Vendor: 057e Product: 2006)":{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","9":"select","10":"lstick","16":"start"},sticks:{left:{x:0,y:1}}},"Joy-Con (R) (STANDARD GAMEPAD Vendor: 057e Product: 2007)":{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","9":"start","10":"lstick","16":"select"},sticks:{left:{x:0,y:1}}},"Pro Controller (STANDARD GAMEPAD Vendor: 057e Product: 2009)":{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","6":"ltrigger","7":"rtrigger","8":"select","9":"start","10":"lstick","11":"rstick","12":"dpad-up","13":"dpad-down","14":"dpad-left","15":"dpad-right","16":"home","17":"capture"},sticks:{left:{x:0,y:1},right:{x:2,y:3}}},default:{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","6":"ltrigger","7":"rtrigger","8":"select","9":"start","10":"lstick","11":"rstick","12":"dpad-up","13":"dpad-down","14":"dpad-left","15":"dpad-right","16":"home"},sticks:{left:{x:0,y:1},right:{x:2,y:3}}}};var Mt=class{static{o(this,"ButtonState")}pressed=new Set([]);pressedRepeat=new Set([]);released=new Set([]);down=new Set([]);update(){this.pressed.clear(),this.released.clear(),this.pressedRepeat.clear()}press(e){this.pressed.add(e),this.pressedRepeat.add(e),this.down.add(e)}pressRepeat(e){this.pressedRepeat.add(e)}release(e){this.down.delete(e),this.pressed.delete(e),this.released.add(e)}},os=class{static{o(this,"GamepadState")}buttonState=new Mt;stickState=new Map},as=class{static{o(this,"FPSCounter")}dts=[];timer=0;fps=0;tick(e){this.dts.push(e),this.timer+=e,this.timer>=1&&(this.timer=0,this.fps=Math.round(1/(this.dts.reduce((r,c)=>r+c)/this.dts.length)),this.dts=[])}},sr=o(n=>{if(!n.canvas)throw new Error("Please provide a canvas");let e={canvas:n.canvas,loopID:null,stopped:!1,dt:0,time:0,realTime:0,fpsCounter:new as,timeScale:1,skipTime:!1,isHidden:!1,numFrames:0,mousePos:new x(0),mouseDeltaPos:new x(0),keyState:new Mt,mouseState:new Mt,mergedGamepadState:new os,gamepadStates:new Map,gamepads:[],charInputted:[],isMouseMoved:!1,lastWidth:n.canvas.offsetWidth,lastHeight:n.canvas.offsetHeight,events:new nt};function r(){return e.dt*e.timeScale}o(r,"dt");function c(){return e.isHidden}o(c,"isHidden");function h(){return e.time}o(h,"time");function m(){return e.fpsCounter.fps}o(m,"fps");function y(){return e.numFrames}o(y,"numFrames");function C(){return e.canvas.toDataURL()}o(C,"screenshot");function O(l){e.canvas.style.cursor=l}o(O,"setCursor");function v(){return e.canvas.style.cursor}o(v,"getCursor");function z(l){if(l)try{let E=e.canvas.requestPointerLock();E.catch&&E.catch(P=>console.error(P))}catch(E){console.error(E)}else document.exitPointerLock()}o(z,"setCursorLocked");function T(){return!!document.pointerLockElement}o(T,"isCursorLocked");function V(l){l.requestFullscreen?l.requestFullscreen():l.webkitRequestFullscreen&&l.webkitRequestFullscreen()}o(V,"enterFullscreen");function U(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullScreen&&document.webkitExitFullScreen()}o(U,"exitFullscreen");function _(){return document.fullscreenElement||document.webkitFullscreenElement}o(_,"getFullscreenElement");function K(l=!0){l?V(e.canvas):U()}o(K,"setFullscreen");function $(){return!!_()}o($,"isFullscreen");function L(){e.stopped=!0;for(let l in ue)e.canvas.removeEventListener(l,ue[l]);for(let l in He)document.removeEventListener(l,He[l]);for(let l in pe)window.removeEventListener(l,pe[l]);ot.disconnect()}o(L,"quit");function ne(l){e.loopID!==null&&cancelAnimationFrame(e.loopID);let E=0,P=o(H=>{if(e.stopped)return;if(document.visibilityState!=="visible"){e.loopID=requestAnimationFrame(P);return}let ge=H/1e3,ee=ge-e.realTime,Ce=n.maxFPS?1/n.maxFPS:0;e.realTime=ge,E+=ee,E>Ce&&(e.skipTime||(e.dt=E,e.time+=r(),e.fpsCounter.tick(e.dt)),E=0,e.skipTime=!1,e.numFrames++,On(),l(),Gt()),e.loopID=requestAnimationFrame(P)},"frame");P(0)}o(ne,"run");function A(){return"ontouchstart"in window||navigator.maxTouchPoints>0}o(A,"isTouchscreen");function le(){return e.mousePos.clone()}o(le,"mousePos");function j(){return e.mouseDeltaPos.clone()}o(j,"mouseDeltaPos");function de(l="left"){return e.mouseState.pressed.has(l)}o(de,"isMousePressed");function ie(l="left"){return e.mouseState.down.has(l)}o(ie,"isMouseDown");function ae(l="left"){return e.mouseState.released.has(l)}o(ae,"isMouseReleased");function Se(){return e.isMouseMoved}o(Se,"isMouseMoved");function Ne(l){return l===void 0?e.keyState.pressed.size>0:e.keyState.pressed.has(l)}o(Ne,"isKeyPressed");function Fe(l){return l===void 0?e.keyState.pressedRepeat.size>0:e.keyState.pressedRepeat.has(l)}o(Fe,"isKeyPressedRepeat");function Le(l){return l===void 0?e.keyState.down.size>0:e.keyState.down.has(l)}o(Le,"isKeyDown");function Ve(l){return l===void 0?e.keyState.released.size>0:e.keyState.released.has(l)}o(Ve,"isKeyReleased");function ye(l){return l===void 0?e.mergedGamepadState.buttonState.pressed.size>0:e.mergedGamepadState.buttonState.pressed.has(l)}o(ye,"isGamepadButtonPressed");function ke(l){return l===void 0?e.mergedGamepadState.buttonState.down.size>0:e.mergedGamepadState.buttonState.down.has(l)}o(ke,"isGamepadButtonDown");function _e(l){return l===void 0?e.mergedGamepadState.buttonState.released.size>0:e.mergedGamepadState.buttonState.released.has(l)}o(_e,"isGamepadButtonReleased");function je(l){return e.events.on("resize",l)}o(je,"onResize");let ft=Be(l=>e.events.on("keyDown",l),(l,E)=>e.events.on("keyDown",P=>P===l&&E(l))),Te=Be(l=>e.events.on("keyPress",l),(l,E)=>e.events.on("keyPress",P=>P===l&&E(l))),Oe=Be(l=>e.events.on("keyPressRepeat",l),(l,E)=>e.events.on("keyPressRepeat",P=>P===l&&E(l))),ze=Be(l=>e.events.on("keyRelease",l),(l,E)=>e.events.on("keyRelease",P=>P===l&&E(l))),rt=Be(l=>e.events.on("mouseDown",E=>l(E)),(l,E)=>e.events.on("mouseDown",P=>P===l&&E(P))),it=Be(l=>e.events.on("mousePress",E=>l(E)),(l,E)=>e.events.on("mousePress",P=>P===l&&E(P))),Et=Be(l=>e.events.on("mouseRelease",E=>l(E)),(l,E)=>e.events.on("mouseRelease",P=>P===l&&E(P)));function Yt(l){return e.events.on("mouseMove",()=>l(le(),j()))}o(Yt,"onMouseMove");function $t(l){return e.events.on("charInput",l)}o($t,"onCharInput");function Un(l){return e.events.on("touchStart",l)}o(Un,"onTouchStart");function Ot(l){return e.events.on("touchMove",l)}o(Ot,"onTouchMove");function Sn(l){return e.events.on("touchEnd",l)}o(Sn,"onTouchEnd");function Tn(l){return e.events.on("scroll",l)}o(Tn,"onScroll");function Xt(l){return e.events.on("hide",l)}o(Xt,"onHide");function Cn(l){return e.events.on("show",l)}o(Cn,"onShow");function An(l,E){if(typeof l=="function")return e.events.on("gamepadButtonDown",l);if(typeof l=="string"&&typeof E=="function")return e.events.on("gamepadButtonDown",P=>P===l&&E(l))}o(An,"onGamepadButtonDown");function Kt(l,E){if(typeof l=="function")return e.events.on("gamepadButtonPress",l);if(typeof l=="string"&&typeof E=="function")return e.events.on("gamepadButtonPress",P=>P===l&&E(l))}o(Kt,"onGamepadButtonPress");function Wt(l,E){if(typeof l=="function")return e.events.on("gamepadButtonRelease",l);if(typeof l=="string"&&typeof E=="function")return e.events.on("gamepadButtonRelease",P=>P===l&&E(l))}o(Wt,"onGamepadButtonRelease");function Mn(l,E){return e.events.on("gamepadStick",(P,H)=>P===l&&E(H))}o(Mn,"onGamepadStick");function Pt(l){e.events.on("gamepadConnect",l)}o(Pt,"onGamepadConnect");function Rn(l){e.events.on("gamepadDisconnect",l)}o(Rn,"onGamepadDisconnect");function Dt(l){return e.mergedGamepadState.stickState.get(l)||new x(0)}o(Dt,"getGamepadStick");function Pe(){return[...e.charInputted]}o(Pe,"charInputted");function Ut(){return[...e.gamepads]}o(Ut,"getGamepads");function On(){e.events.trigger("input"),e.keyState.down.forEach(l=>e.events.trigger("keyDown",l)),e.mouseState.down.forEach(l=>e.events.trigger("mouseDown",l)),oe()}o(On,"processInput");function Gt(){e.keyState.update(),e.mouseState.update(),e.mergedGamepadState.buttonState.update(),e.mergedGamepadState.stickState.forEach((l,E)=>{e.mergedGamepadState.stickState.set(E,new x(0))}),e.charInputted=[],e.isMouseMoved=!1,e.gamepadStates.forEach(l=>{l.buttonState.update(),l.stickState.forEach((E,P)=>{l.stickState.set(P,new x(0))})})}o(Gt,"resetInput");function Jt(l){let E={index:l.index,isPressed:P=>e.gamepadStates.get(l.index).buttonState.pressed.has(P),isDown:P=>e.gamepadStates.get(l.index).buttonState.down.has(P),isReleased:P=>e.gamepadStates.get(l.index).buttonState.released.has(P),getStick:P=>e.gamepadStates.get(l.index).stickState.get(P)};return e.gamepads.push(E),e.gamepadStates.set(l.index,{buttonState:new Mt,stickState:new Map([["left",new x(0)],["right",new x(0)]])}),E}o(Jt,"registerGamepad");function Pn(l){e.gamepads=e.gamepads.filter(E=>E.index!==l.index),e.gamepadStates.delete(l.index)}o(Pn,"removeGamepad");function oe(){for(let l of navigator.getGamepads())l&&!e.gamepadStates.has(l.index)&&Jt(l);for(let l of e.gamepads){let E=navigator.getGamepads()[l.index],H=(n.gamepads??{})[E.id]??is[E.id]??is.default,ge=e.gamepadStates.get(l.index);for(let ee=0;ee<E.buttons.length;ee++)E.buttons[ee].pressed?(ge.buttonState.down.has(H.buttons[ee])||(e.mergedGamepadState.buttonState.press(H.buttons[ee]),ge.buttonState.press(H.buttons[ee]),e.events.trigger("gamepadButtonPress",H.buttons[ee])),e.events.trigger("gamepadButtonDown",H.buttons[ee])):ge.buttonState.down.has(H.buttons[ee])&&(e.mergedGamepadState.buttonState.release(H.buttons[ee]),ge.buttonState.release(H.buttons[ee]),e.events.trigger("gamepadButtonRelease",H.buttons[ee]));for(let ee in H.sticks){let Ce=H.sticks[ee],at=new x(E.axes[Ce.x],E.axes[Ce.y]);ge.stickState.set(ee,at),e.mergedGamepadState.stickState.set(ee,at),e.events.trigger("gamepadStick",ee,at)}}}o(oe,"processGamepad");let ue={},He={},pe={},xe=n.pixelDensity||window.devicePixelRatio||1;ue.mousemove=l=>{let E=new x(l.offsetX,l.offsetY),P=new x(l.movementX,l.movementY);if($()){let H=e.canvas.width/xe,ge=e.canvas.height/xe,ee=window.innerWidth,Ce=window.innerHeight,at=ee/Ce,$e=H/ge;if(at>$e){let Xe=Ce/ge,Tt=(ee-H*Xe)/2;E.x=et(l.offsetX-Tt,0,H*Xe,0,H),E.y=et(l.offsetY,0,ge*Xe,0,ge)}else{let Xe=ee/H,Tt=(Ce-ge*Xe)/2;E.x=et(l.offsetX,0,H*Xe,0,H),E.y=et(l.offsetY-Tt,0,ge*Xe,0,ge)}}e.events.onOnce("input",()=>{e.isMouseMoved=!0,e.mousePos=E,e.mouseDeltaPos=P,e.events.trigger("mouseMove")})};let Je=["left","middle","right","back","forward"];ue.mousedown=l=>{e.events.onOnce("input",()=>{let E=Je[l.button];E&&(e.mouseState.press(E),e.events.trigger("mousePress",E))})},ue.mouseup=l=>{e.events.onOnce("input",()=>{let E=Je[l.button];E&&(e.mouseState.release(E),e.events.trigger("mouseRelease",E))})};let St=new Set([" ","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Tab"]),Qt={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down"," ":"space"};ue.keydown=l=>{St.has(l.key)&&l.preventDefault(),e.events.onOnce("input",()=>{let E=Qt[l.key]||l.key.toLowerCase();E.length===1?(e.events.trigger("charInput",E),e.charInputted.push(E)):E==="space"&&(e.events.trigger("charInput"," "),e.charInputted.push(" ")),l.repeat?(e.keyState.pressRepeat(E),e.events.trigger("keyPressRepeat",E)):(e.keyState.press(E),e.events.trigger("keyPressRepeat",E),e.events.trigger("keyPress",E))})},ue.keyup=l=>{e.events.onOnce("input",()=>{let E=Qt[l.key]||l.key.toLowerCase();e.keyState.release(E),e.events.trigger("keyRelease",E)})},ue.touchstart=l=>{l.preventDefault(),e.events.onOnce("input",()=>{let E=[...l.changedTouches],P=e.canvas.getBoundingClientRect();n.touchToMouse!==!1&&(e.mousePos=new x(E[0].clientX-P.x,E[0].clientY-P.y),e.mouseState.press("left"),e.events.trigger("mousePress","left")),E.forEach(H=>{e.events.trigger("touchStart",new x(H.clientX-P.x,H.clientY-P.y),H)})})},ue.touchmove=l=>{l.preventDefault(),e.events.onOnce("input",()=>{let E=[...l.changedTouches],P=e.canvas.getBoundingClientRect();if(n.touchToMouse!==!1){let H=e.mousePos;e.mousePos=new x(E[0].clientX-P.x,E[0].clientY-P.y),e.mouseDeltaPos=e.mousePos.sub(H),e.events.trigger("mouseMove")}E.forEach(H=>{e.events.trigger("touchMove",new x(H.clientX-P.x,H.clientY-P.y),H)})})},ue.touchend=l=>{e.events.onOnce("input",()=>{let E=[...l.changedTouches],P=e.canvas.getBoundingClientRect();n.touchToMouse!==!1&&(e.mousePos=new x(E[0].clientX-P.x,E[0].clientY-P.y),e.mouseDeltaPos=new x(0,0),e.mouseState.release("left"),e.events.trigger("mouseRelease","left")),E.forEach(H=>{e.events.trigger("touchEnd",new x(H.clientX-P.x,H.clientY-P.y),H)})})},ue.touchcancel=l=>{e.events.onOnce("input",()=>{let E=[...l.changedTouches],P=e.canvas.getBoundingClientRect();n.touchToMouse!==!1&&(e.mousePos=new x(E[0].clientX-P.x,E[0].clientY-P.y),e.mouseState.release("left"),e.events.trigger("mouseRelease","left")),E.forEach(H=>{e.events.trigger("touchEnd",new x(H.clientX-P.x,H.clientY-P.y),H)})})},ue.wheel=l=>{l.preventDefault(),e.events.onOnce("input",()=>{e.events.trigger("scroll",new x(l.deltaX,l.deltaY))})},ue.contextmenu=l=>l.preventDefault(),He.visibilitychange=()=>{document.visibilityState==="visible"?(e.skipTime=!0,e.isHidden=!1,e.events.trigger("show")):(e.isHidden=!0,e.events.trigger("hide"))},pe.gamepadconnected=l=>{let E=Jt(l.gamepad);e.events.onOnce("input",()=>{e.events.trigger("gamepadConnect",E)})},pe.gamepaddisconnected=l=>{let E=Ut().filter(P=>P.index===l.gamepad.index)[0];Pn(l.gamepad),e.events.onOnce("input",()=>{e.events.trigger("gamepadDisconnect",E)})};for(let l in ue)e.canvas.addEventListener(l,ue[l]);for(let l in He)document.addEventListener(l,He[l]);for(let l in pe)window.addEventListener(l,pe[l]);let ot=new ResizeObserver(l=>{for(let E of l)if(E.target===e.canvas){if(e.lastWidth===e.canvas.offsetWidth&&e.lastHeight===e.canvas.offsetHeight)return;e.lastWidth=e.canvas.offsetWidth,e.lastHeight=e.canvas.offsetHeight,e.events.onOnce("input",()=>{e.events.trigger("resize")})}});return ot.observe(e.canvas),{dt:r,time:h,run:ne,canvas:e.canvas,fps:m,numFrames:y,quit:L,isHidden:c,setFullscreen:K,isFullscreen:$,setCursor:O,screenshot:C,getGamepads:Ut,getCursor:v,setCursorLocked:z,isCursorLocked:T,isTouchscreen:A,mousePos:le,mouseDeltaPos:j,isKeyDown:Le,isKeyPressed:Ne,isKeyPressedRepeat:Fe,isKeyReleased:Ve,isMouseDown:ie,isMousePressed:de,isMouseReleased:ae,isMouseMoved:Se,isGamepadButtonPressed:ye,isGamepadButtonDown:ke,isGamepadButtonReleased:_e,getGamepadStick:Dt,charInputted:Pe,onResize:je,onKeyDown:ft,onKeyPress:Te,onKeyPressRepeat:Oe,onKeyRelease:ze,onMouseDown:rt,onMousePress:it,onMouseRelease:Et,onMouseMove:Yt,onCharInput:$t,onTouchStart:Un,onTouchMove:Ot,onTouchEnd:Sn,onScroll:Tn,onHide:Xt,onShow:Cn,onGamepadButtonDown:An,onGamepadButtonPress:Kt,onGamepadButtonRelease:Wt,onGamepadStick:Mn,onGamepadConnect:Pt,onGamepadDisconnect:Rn,events:e.events}},"default");var qe=class n{static{o(this,"Texture")}ctx;src=null;glTex;width;height;constructor(e,r,c,h={}){this.ctx=e;let m=e.gl;this.glTex=e.gl.createTexture(),e.onDestroy(()=>this.free()),this.width=r,this.height=c;let y={linear:m.LINEAR,nearest:m.NEAREST}[h.filter??e.opts.texFilter]??m.NEAREST,C={repeat:m.REPEAT,clampToEadge:m.CLAMP_TO_EDGE}[h.wrap]??m.CLAMP_TO_EDGE;this.bind(),r&&c&&m.texImage2D(m.TEXTURE_2D,0,m.RGBA,r,c,0,m.RGBA,m.UNSIGNED_BYTE,null),m.texParameteri(m.TEXTURE_2D,m.TEXTURE_MIN_FILTER,y),m.texParameteri(m.TEXTURE_2D,m.TEXTURE_MAG_FILTER,y),m.texParameteri(m.TEXTURE_2D,m.TEXTURE_WRAP_S,C),m.texParameteri(m.TEXTURE_2D,m.TEXTURE_WRAP_T,C),this.unbind()}static fromImage(e,r,c={}){let h=new n(e,r.width,r.height,c);return h.update(r),h.src=r,h}update(e,r=0,c=0){let h=this.ctx.gl;this.bind(),h.texSubImage2D(h.TEXTURE_2D,0,r,c,h.RGBA,h.UNSIGNED_BYTE,e),this.unbind()}bind(){this.ctx.pushTexture2D(this.glTex)}unbind(){this.ctx.popTexture2D()}free(){this.ctx.gl.deleteTexture(this.glTex)}},xt=class{static{o(this,"FrameBuffer")}ctx;tex;glFramebuffer;glRenderbuffer;constructor(e,r,c,h={}){this.ctx=e;let m=e.gl;e.onDestroy(()=>this.free()),this.tex=new qe(e,r,c,h),this.glFramebuffer=m.createFramebuffer(),this.glRenderbuffer=m.createRenderbuffer(),this.bind(),m.renderbufferStorage(m.RENDERBUFFER,m.DEPTH_STENCIL,r,c),m.framebufferTexture2D(m.FRAMEBUFFER,m.COLOR_ATTACHMENT0,m.TEXTURE_2D,this.tex.glTex,0),m.framebufferRenderbuffer(m.FRAMEBUFFER,m.DEPTH_STENCIL_ATTACHMENT,m.RENDERBUFFER,this.glRenderbuffer),this.unbind()}get width(){return this.tex.width}get height(){return this.tex.height}toImageData(){let e=this.ctx.gl,r=new Uint8ClampedArray(this.width*this.height*4);this.bind(),e.readPixels(0,0,this.width,this.height,e.RGBA,e.UNSIGNED_BYTE,r),this.unbind();let c=this.width*4,h=new Uint8Array(c);for(let m=0;m<(this.height/2|0);m++){let y=m*c,C=(this.height-m-1)*c;h.set(r.subarray(y,y+c)),r.copyWithin(y,C,C+c),r.set(h,C)}return new ImageData(r,this.width,this.height)}toDataURL(){let e=document.createElement("canvas"),r=e.getContext("2d");return e.width=this.width,e.height=this.height,r.putImageData(this.toImageData(),0,0),e.toDataURL()}clear(){let e=this.ctx.gl;e.clear(e.COLOR_BUFFER_BIT)}draw(e){this.bind(),e(),this.unbind()}bind(){this.ctx.pushFramebuffer(this.glFramebuffer),this.ctx.pushRenderbuffer(this.glRenderbuffer),this.ctx.pushViewport({x:0,y:0,w:this.width,h:this.height})}unbind(){this.ctx.popFramebuffer(),this.ctx.popRenderbuffer(),this.ctx.popViewport()}free(){let e=this.ctx.gl;e.deleteFramebuffer(this.glFramebuffer),e.deleteRenderbuffer(this.glRenderbuffer),this.tex.free()}},pn=class{static{o(this,"Shader")}ctx;glProgram;constructor(e,r,c,h){this.ctx=e,e.onDestroy(()=>this.free());let m=e.gl,y=m.createShader(m.VERTEX_SHADER),C=m.createShader(m.FRAGMENT_SHADER);m.shaderSource(y,r),m.shaderSource(C,c),m.compileShader(y),m.compileShader(C);let O=m.createProgram();if(this.glProgram=O,m.attachShader(O,y),m.attachShader(O,C),h.forEach((v,z)=>m.bindAttribLocation(O,z,v)),m.linkProgram(O),!m.getProgramParameter(O,m.LINK_STATUS)){let v=m.getShaderInfoLog(y);if(v)throw new Error("VERTEX SHADER "+v);let z=m.getShaderInfoLog(C);if(z)throw new Error("FRAGMENT SHADER "+z)}m.deleteShader(y),m.deleteShader(C)}bind(){this.ctx.pushProgram(this.glProgram)}unbind(){this.ctx.popProgram()}send(e){let r=this.ctx.gl;for(let c in e){let h=e[c],m=r.getUniformLocation(this.glProgram,c);if(typeof h=="number")r.uniform1f(m,h);else if(h instanceof Ge)r.uniformMatrix4fv(m,!1,new Float32Array(h.m));else if(h instanceof J)r.uniform3f(m,h.r,h.g,h.b);else if(h instanceof x)r.uniform2f(m,h.x,h.y);else if(Array.isArray(h)){let y=h[0];typeof y=="number"?r.uniform1fv(m,h):y instanceof x?r.uniform2fv(m,h.map(C=>[C.x,C.y]).flat()):y instanceof J&&r.uniform3fv(m,h.map(C=>[C.r,C.g,C.b]).flat())}else throw new Error("Unsupported uniform data type")}}free(){this.ctx.gl.deleteProgram(this.glProgram)}},gn=class{static{o(this,"BatchRenderer")}ctx;glVBuf;glIBuf;vqueue=[];iqueue=[];stride;maxVertices;maxIndices;vertexFormat;numDraws=0;curPrimitive=null;curTex=null;curShader=null;curUniform={};constructor(e,r,c,h){let m=e.gl;this.vertexFormat=r,this.ctx=e,this.stride=r.reduce((y,C)=>y+C.size,0),this.maxVertices=c,this.maxIndices=h,this.glVBuf=m.createBuffer(),e.pushArrayBuffer(this.glVBuf),m.bufferData(m.ARRAY_BUFFER,c*4,m.DYNAMIC_DRAW),e.popArrayBuffer(),this.glIBuf=m.createBuffer(),e.pushElementArrayBuffer(this.glIBuf),m.bufferData(m.ELEMENT_ARRAY_BUFFER,h*4,m.DYNAMIC_DRAW),e.popElementArrayBuffer()}push(e,r,c,h,m=null,y={}){(e!==this.curPrimitive||m!==this.curTex||h!==this.curShader||!fn(this.curUniform,y)||this.vqueue.length+r.length*this.stride>this.maxVertices||this.iqueue.length+c.length>this.maxIndices)&&this.flush();let C=this.vqueue.length/this.stride;for(let O of r)this.vqueue.push(O);for(let O of c)this.iqueue.push(O+C);this.curPrimitive=e,this.curShader=h,this.curTex=m,this.curUniform=y}flush(){if(!this.curPrimitive||!this.curShader||this.vqueue.length===0||this.iqueue.length===0)return;let e=this.ctx.gl;this.ctx.pushArrayBuffer(this.glVBuf),e.bufferSubData(e.ARRAY_BUFFER,0,new Float32Array(this.vqueue)),this.ctx.pushElementArrayBuffer(this.glIBuf),e.bufferSubData(e.ELEMENT_ARRAY_BUFFER,0,new Uint16Array(this.iqueue)),this.ctx.setVertexFormat(this.vertexFormat),this.curShader.bind(),this.curShader.send(this.curUniform),this.curTex?.bind(),e.drawElements(this.curPrimitive,this.iqueue.length,e.UNSIGNED_SHORT,0),this.curTex?.unbind(),this.curShader.unbind(),this.ctx.popArrayBuffer(),this.ctx.popElementArrayBuffer(),this.vqueue=[],this.iqueue=[],this.numDraws++}free(){let e=this.ctx.gl;e.deleteBuffer(this.glVBuf),e.deleteBuffer(this.glIBuf)}};function yt(n){let e=[],r=o(m=>{e.push(m),n(m)},"push"),c=o(()=>{e.pop(),n(h()??null)},"pop"),h=o(()=>e[e.length-1],"cur");return[r,c,h]}o(yt,"genStack");function us(n,e={}){let r=[];function c(j){r.push(j)}o(c,"onDestroy");function h(){r.forEach(j=>j()),n.getExtension("WEBGL_lose_context").loseContext()}o(h,"destroy");let m=null;function y(j){if(fn(j,m))return;m=j;let de=j.reduce((ie,ae)=>ie+ae.size,0);j.reduce((ie,ae,Se)=>(n.vertexAttribPointer(Se,ae.size,n.FLOAT,!1,de*4,ie),n.enableVertexAttribArray(Se),ie+ae.size*4),0)}o(y,"setVertexFormat");let[C,O]=yt(j=>n.bindTexture(n.TEXTURE_2D,j)),[v,z]=yt(j=>n.bindBuffer(n.ARRAY_BUFFER,j)),[T,V]=yt(j=>n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,j)),[U,_]=yt(j=>n.bindFramebuffer(n.FRAMEBUFFER,j)),[K,$]=yt(j=>n.bindRenderbuffer(n.RENDERBUFFER,j)),[L,ne]=yt(({x:j,y:de,w:ie,h:ae})=>{n.viewport(j,de,ie,ae)}),[A,le]=yt(j=>n.useProgram(j));return L({x:0,y:0,w:n.drawingBufferWidth,h:n.drawingBufferHeight}),{gl:n,opts:e,onDestroy:c,destroy:h,pushTexture2D:C,popTexture2D:O,pushArrayBuffer:v,popArrayBuffer:z,pushElementArrayBuffer:T,popElementArrayBuffer:V,pushFramebuffer:U,popFramebuffer:_,pushRenderbuffer:K,popRenderbuffer:$,pushViewport:L,popViewport:ne,pushProgram:A,popProgram:le,setVertexFormat:y}}o(us,"initGfx");var Re=class n{static{o(this,"Asset")}loaded=!1;data=null;error=null;onLoadEvents=new Ue;onErrorEvents=new Ue;onFinishEvents=new Ue;constructor(e){e.then(r=>{this.loaded=!0,this.data=r,this.onLoadEvents.trigger(r)}).catch(r=>{if(this.error=r,this.onErrorEvents.numListeners()>0)this.onErrorEvents.trigger(r);else throw r}).finally(()=>{this.onFinishEvents.trigger(),this.loaded=!0})}static loaded(e){let r=new n(Promise.resolve(e));return r.data=e,r.loaded=!0,r}onLoad(e){return this.loaded&&this.data?e(this.data):this.onLoadEvents.add(e),this}onError(e){return this.loaded&&this.error?e(this.error):this.onErrorEvents.add(e),this}onFinish(e){return this.loaded?e():this.onFinishEvents.add(e),this}then(e){return this.onLoad(e)}catch(e){return this.onError(e)}finally(e){return this.onFinish(e)}},st=class{static{o(this,"AssetBucket")}assets=new Map;lastUID=0;add(e,r){let c=e??this.lastUID+++"",h=new Re(r);return this.assets.set(c,h),h}addLoaded(e,r){let c=e??this.lastUID+++"",h=Re.loaded(r);return this.assets.set(c,h),h}get(e){return this.assets.get(e)}progress(){if(this.assets.size===0)return 1;let e=0;return this.assets.forEach(r=>{r.loaded&&e++}),e/this.assets.size}};function cs(n){return fetch(n).then(e=>{if(!e.ok)throw new Error(`Failed to fetch "${n}"`);return e})}o(cs,"fetchURL");function jt(n){return cs(n).then(e=>e.json())}o(jt,"fetchJSON");function rr(n){return cs(n).then(e=>e.text())}o(rr,"fetchText");function ir(n){return cs(n).then(e=>e.arrayBuffer())}o(ir,"fetchArrayBuffer");function Ht(n){let e=new Image;return e.crossOrigin="anonymous",e.src=n,new Promise((r,c)=>{e.onload=()=>r(e),e.onerror=()=>c(new Error(`Failed to load image from "${n}"`))})}o(Ht,"loadImg");var wn=2.5949095,or=1.70158+1,ar=2*Math.PI/3,ur=2*Math.PI/4.5,bn={linear:n=>n,easeInSine:n=>1-Math.cos(n*Math.PI/2),easeOutSine:n=>Math.sin(n*Math.PI/2),easeInOutSine:n=>-(Math.cos(Math.PI*n)-1)/2,easeInQuad:n=>n*n,easeOutQuad:n=>1-(1-n)*(1-n),easeInOutQuad:n=>n<.5?2*n*n:1-Math.pow(-2*n+2,2)/2,easeInCubic:n=>n*n*n,easeOutCubic:n=>1-Math.pow(1-n,3),easeInOutCubic:n=>n<.5?4*n*n*n:1-Math.pow(-2*n+2,3)/2,easeInQuart:n=>n*n*n*n,easeOutQuart:n=>1-Math.pow(1-n,4),easeInOutQuart:n=>n<.5?8*n*n*n*n:1-Math.pow(-2*n+2,4)/2,easeInQuint:n=>n*n*n*n*n,easeOutQuint:n=>1-Math.pow(1-n,5),easeInOutQuint:n=>n<.5?16*n*n*n*n*n:1-Math.pow(-2*n+2,5)/2,easeInExpo:n=>n===0?0:Math.pow(2,10*n-10),easeOutExpo:n=>n===1?1:1-Math.pow(2,-10*n),easeInOutExpo:n=>n===0?0:n===1?1:n<.5?Math.pow(2,20*n-10)/2:(2-Math.pow(2,-20*n+10))/2,easeInCirc:n=>1-Math.sqrt(1-Math.pow(n,2)),easeOutCirc:n=>Math.sqrt(1-Math.pow(n-1,2)),easeInOutCirc:n=>n<.5?(1-Math.sqrt(1-Math.pow(2*n,2)))/2:(Math.sqrt(1-Math.pow(-2*n+2,2))+1)/2,easeInBack:n=>or*n*n*n-1.70158*n*n,easeOutBack:n=>1+or*Math.pow(n-1,3)+1.70158*Math.pow(n-1,2),easeInOutBack:n=>n<.5?Math.pow(2*n,2)*((wn+1)*2*n-wn)/2:(Math.pow(2*n-2,2)*((wn+1)*(n*2-2)+wn)+2)/2,easeInElastic:n=>n===0?0:n===1?1:-Math.pow(2,10*n-10)*Math.sin((n*10-10.75)*ar),easeOutElastic:n=>n===0?0:n===1?1:Math.pow(2,-10*n)*Math.sin((n*10-.75)*ar)+1,easeInOutElastic:n=>n===0?0:n===1?1:n<.5?-(Math.pow(2,20*n-10)*Math.sin((20*n-11.125)*ur))/2:Math.pow(2,-20*n+10)*Math.sin((20*n-11.125)*ur)/2+1,easeInBounce:n=>1-bn.easeOutBounce(1-n),easeOutBounce:n=>n<1/2.75?7.5625*n*n:n<2/2.75?7.5625*(n-=1.5/2.75)*n+.75:n<2.5/2.75?7.5625*(n-=2.25/2.75)*n+.9375:7.5625*(n-=2.625/2.75)*n+.984375,easeInOutBounce:n=>n<.5?(1-bn.easeOutBounce(1-2*n))/2:(1+bn.easeOutBounce(2*n-1))/2},qt=bn;var zt=class{static{o(this,"TexPacker")}textures=[];bigTextures=[];canvas;c2d;x=0;y=0;curHeight=0;gfx;constructor(e,r,c){this.gfx=e,this.canvas=document.createElement("canvas"),this.canvas.width=r,this.canvas.height=c,this.textures=[qe.fromImage(e,this.canvas)],this.bigTextures=[],this.c2d=this.canvas.getContext("2d")}add(e){if(e.width>this.canvas.width||e.height>this.canvas.height){let h=qe.fromImage(this.gfx,e);return this.bigTextures.push(h),[h,new ce(0,0,1,1)]}this.x+e.width>this.canvas.width&&(this.x=0,this.y+=this.curHeight,this.curHeight=0),this.y+e.height>this.canvas.height&&(this.c2d.clearRect(0,0,this.canvas.width,this.canvas.height),this.textures.push(qe.fromImage(this.gfx,this.canvas)),this.x=0,this.y=0,this.curHeight=0);let r=this.textures[this.textures.length-1],c=new x(this.x,this.y);return this.x+=e.width,e.height>this.curHeight&&(this.curHeight=e.height),e instanceof ImageData?this.c2d.putImageData(e,c.x,c.y):this.c2d.drawImage(e,c.x,c.y),r.update(this.canvas),[r,new ce(c.x/this.canvas.width,c.y/this.canvas.height,e.width/this.canvas.width,e.height/this.canvas.height)]}free(){for(let e of this.textures)e.free();for(let e of this.bigTextures)e.free()}};var cr="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD0AAAA1CAYAAADyMeOEAAAAAXNSR0IArs4c6QAAAoVJREFUaIHdm7txwkAQhheGAqACiCHzOKQDQrqgILpwSAeEDBnEUAF0gCMxZ7G72qce/mec2Lpf9+3unaS78wgSNZ8uX5729+d1FNWXUuGmXlBOUUEIMckEpeQJgBu6C+BSFngztBR2vd+ovY+7g+p6LbgaWgJrAeUkDYIUXgXdBBwNi6kpABJwMTQH3AZsXRR8GHTfgEth8E3gjdAUcNewpbTgY85sCMCUuOokozE0YM0YRzM9NGAAXd8+omAF5h4lnmBRvpSnZHyLoLEbaN+aKB9KWv/KWw0tAbbANnlG+UvB2dm77NxxdwgBpjrF/d7rW9cbmpvio2A5z8iAYpVU8pGZlo6/2+MSco2lHfd3rv9jAP038e1xef9o2mjvYb2OqpqKE81028/jeietlSEVO5F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Hl3KnReA4UIaU+y+WkcbzHQ1DEzMGQ9aJH0BDK6RE0y9wlTDp2HuppERQxc0FFBaZGUMTMB5UlQG/fHyk1odJEaBUUMXWh4oSoFRQxtaHyxMi2uBseQwUKciUoYuaAShTlkaCImQcqUph7QREzF/8DSS/2GZ2/N/sAAAAASUVORK5CYII=";var Uo="3000.1.17",fr=" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",vn="topleft",mr=64,So="monospace",yn="monospace",To=36,xn=64,En=256,pr=2048,gr=2048,wr=2048,br=2048,vr=.1,Co=64,hs="linear",Ao=8,Mo=4,fs=[{name:"a_pos",size:2},{name:"a_uv",size:2},{name:"a_color",size:4}],Ro=fs.reduce((n,e)=>n+e.size,0),yr=2048,Oo=yr*4*Ro,Po=yr*6,Do=`
|
|
2
|
+
attribute vec2 a_pos;
|
|
3
|
+
attribute vec2 a_uv;
|
|
4
|
+
attribute vec4 a_color;
|
|
5
|
+
|
|
6
|
+
varying vec2 v_pos;
|
|
7
|
+
varying vec2 v_uv;
|
|
8
|
+
varying vec4 v_color;
|
|
9
|
+
|
|
10
|
+
vec4 def_vert() {
|
|
11
|
+
return vec4(a_pos, 0.0, 1.0);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
{{user}}
|
|
15
|
+
|
|
16
|
+
void main() {
|
|
17
|
+
vec4 pos = vert(a_pos, a_uv, a_color);
|
|
18
|
+
v_pos = a_pos;
|
|
19
|
+
v_uv = a_uv;
|
|
20
|
+
v_color = a_color;
|
|
21
|
+
gl_Position = pos;
|
|
22
|
+
}
|
|
23
|
+
`,Go=`
|
|
24
|
+
precision mediump float;
|
|
25
|
+
|
|
26
|
+
varying vec2 v_pos;
|
|
27
|
+
varying vec2 v_uv;
|
|
28
|
+
varying vec4 v_color;
|
|
29
|
+
|
|
30
|
+
uniform sampler2D u_tex;
|
|
31
|
+
|
|
32
|
+
vec4 def_frag() {
|
|
33
|
+
return v_color * texture2D(u_tex, v_uv);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
{{user}}
|
|
37
|
+
|
|
38
|
+
void main() {
|
|
39
|
+
gl_FragColor = frag(v_pos, v_uv, v_color, u_tex);
|
|
40
|
+
if (gl_FragColor.a == 0.0) {
|
|
41
|
+
discard;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`,ls=`
|
|
45
|
+
vec4 vert(vec2 pos, vec2 uv, vec4 color) {
|
|
46
|
+
return def_vert();
|
|
47
|
+
}
|
|
48
|
+
`,ds=`
|
|
49
|
+
vec4 frag(vec2 pos, vec2 uv, vec4 color, sampler2D tex) {
|
|
50
|
+
return def_frag();
|
|
51
|
+
}
|
|
52
|
+
`,Io=new Set(["id","require"]),Bo=new Set(["add","update","draw","destroy","inspect","drawInspect"]);function Rt(n){switch(n){case"topleft":return new x(-1,-1);case"top":return new x(0,-1);case"topright":return new x(1,-1);case"left":return new x(-1,0);case"center":return new x(0,0);case"right":return new x(1,0);case"botleft":return new x(-1,1);case"bot":return new x(0,1);case"botright":return new x(1,1);default:return n}}o(Rt,"anchorPt");function Fo(n){switch(n){case"left":return 0;case"center":return .5;case"right":return 1;default:return 0}}o(Fo,"alignPt");function Lo(n){return n.createBuffer(1,1,44100)}o(Lo,"createEmptyAudioBuffer");var Vo=o((n={})=>{let e=n.root??document.body;e===document.body&&(document.body.style.width="100%",document.body.style.height="100%",document.body.style.margin="0px",document.documentElement.style.width="100%",document.documentElement.style.height="100%");let r=n.canvas??(()=>{let t=document.createElement("canvas");return e.appendChild(t),t})(),c=n.scale??1,h=n.width&&n.height&&!n.stretch&&!n.letterbox;h?(r.width=n.width*c,r.height=n.height*c):(r.width=r.parentElement.offsetWidth,r.height=r.parentElement.offsetHeight);let m=["outline: none","cursor: default"];if(h){let t=r.width,s=r.height;m.push(`width: ${t}px`),m.push(`height: ${s}px`)}else m.push("width: 100%"),m.push("height: 100%");n.crisp&&(m.push("image-rendering: pixelated"),m.push("image-rendering: crisp-edges")),r.style.cssText=m.join(";");let y=n.pixelDensity||window.devicePixelRatio;r.width*=y,r.height*=y,r.tabIndex=0;let C=document.createElement("canvas");C.width=En,C.height=En;let O=C.getContext("2d",{willReadFrequently:!0}),v=sr({canvas:r,touchToMouse:n.touchToMouse,gamepads:n.gamepads,pixelDensity:n.pixelDensity,maxFPS:n.maxFPS}),z=[],T=v.canvas.getContext("webgl",{antialias:!0,depth:!0,stencil:!0,alpha:!0,preserveDrawingBuffer:!0}),V=us(T,{texFilter:n.texFilter}),U=(()=>{let t=Pt(ls,ds),s=qe.fromImage(V,new ImageData(new Uint8ClampedArray([255,255,255,255]),1,1)),i=n.width&&n.height?new xt(V,n.width*y*c,n.height*y*c):new xt(V,T.drawingBufferWidth,T.drawingBufferHeight),a=null,u=1;n.background&&(a=Z(n.background),u=Array.isArray(n.background)?n.background[3]:1,T.clearColor(a.r/255,a.g/255,a.b/255,u??1)),T.enable(T.BLEND),T.blendFuncSeparate(T.SRC_ALPHA,T.ONE_MINUS_SRC_ALPHA,T.ONE,T.ONE_MINUS_SRC_ALPHA);let d=new gn(V,fs,Oo,Po),p=qe.fromImage(V,new ImageData(new Uint8ClampedArray([128,128,128,255,190,190,190,255,190,190,190,255,128,128,128,255]),2,2),{wrap:"repeat",filter:"nearest"});return{lastDrawCalls:0,defShader:t,defTex:s,frameBuffer:i,postShader:null,postShaderUniform:null,renderer:d,transform:new Ge,transformStack:[],bgTex:p,bgColor:a,bgAlpha:u,width:n.width??T.drawingBufferWidth/y/c,height:n.height??T.drawingBufferHeight/y/c,viewport:{x:0,y:0,width:T.drawingBufferWidth,height:T.drawingBufferHeight},fixed:!1}})();class _{static{o(this,"SpriteData")}tex;frames=[new ce(0,0,1,1)];anims={};slice9=null;constructor(s,i,a={},u=null){this.tex=s,i&&(this.frames=i),this.anims=a,this.slice9=u}get width(){return this.tex.width*this.frames[0].w}get height(){return this.tex.height*this.frames[0].h}static from(s,i={}){return typeof s=="string"?_.fromURL(s,i):Promise.resolve(_.fromImage(s,i))}static fromImage(s,i={}){let[a,u]=L.packer.add(s),d=i.frames?i.frames.map(p=>new ce(u.x+p.x*u.w,u.y+p.y*u.h,p.w*u.w,p.h*u.h)):Fe(i.sliceX||1,i.sliceY||1,u.x,u.y,u.w,u.h);return new _(a,d,i.anims,i.slice9)}static fromURL(s,i={}){return Ht(s).then(a=>_.fromImage(a,i))}}class K{static{o(this,"SoundData")}buf;constructor(s){this.buf=s}static fromArrayBuffer(s){return new Promise((i,a)=>$.ctx.decodeAudioData(s,i,a)).then(i=>new K(i))}static fromURL(s){return ss(s)?K.fromArrayBuffer(Js(s)):ir(s).then(i=>K.fromArrayBuffer(i))}}let $=(()=>{let t=new(window.AudioContext||window.webkitAudioContext),s=t.createGain();s.connect(t.destination);let i=new K(Lo(t));return t.decodeAudioData(hr.buffer.slice(0)).then(a=>{i.buf=a}).catch(a=>{console.error("Failed to load burp: ",a)}),{ctx:t,masterNode:s,burpSnd:i}})(),L={urlPrefix:"",sprites:new st,fonts:new st,bitmapFonts:new st,sounds:new st,shaders:new st,custom:new st,music:{},packer:new zt(V,wr,br),loaded:!1};function ne(t){return typeof t!="string"||ss(t)?t:L.urlPrefix+t}o(ne,"fixURL");let A={events:new nt,objEvents:new nt,root:Gn([]),gravity:0,scenes:{},logs:[],cam:{pos:null,scale:new x(1),angle:0,shake:0,transform:new Ge}};A.root.use(Ln());function le(t){return L.custom.add(null,t)}o(le,"load");function j(){let t=[L.sprites,L.sounds,L.shaders,L.fonts,L.bitmapFonts,L.custom];return t.reduce((s,i)=>s+i.progress(),0)/t.length}o(j,"loadProgress");function de(t){return t!==void 0&&(L.urlPrefix=t),L.urlPrefix}o(de,"loadRoot");function ie(t,s){return L.custom.add(t,jt(s))}o(ie,"loadJSON");class ae{static{o(this,"FontData")}fontface;filter=hs;outline=null;size=xn;constructor(s,i={}){if(this.fontface=s,this.filter=i.filter??hs,this.size=i.size??xn,this.size>En)throw new Error(`Max font size: ${En}`);i.outline&&(this.outline={width:1,color:Z(0,0,0)},typeof i.outline=="number"?this.outline.width=i.outline:typeof i.outline=="object"&&(i.outline.width&&(this.outline.width=i.outline.width),i.outline.color&&(this.outline.color=i.outline.color)))}}function Se(t,s,i={}){let a=new FontFace(t,typeof s=="string"?`url(${s})`:s);return document.fonts.add(a),L.fonts.add(t,a.load().catch(u=>{throw new Error(`Failed to load font from "${s}": ${u}`)}).then(u=>new ae(u,i)))}o(Se,"loadFont");function Ne(t,s,i,a,u={}){return L.bitmapFonts.add(t,Ht(s).then(d=>Rn(qe.fromImage(V,d,u),i,a,u.chars??fr)))}o(Ne,"loadBitmapFont");function Fe(t=1,s=1,i=0,a=0,u=1,d=1){let p=[],w=u/t,g=d/s;for(let f=0;f<s;f++)for(let b=0;b<t;b++)p.push(new ce(i+b*w,a+f*g,w,g));return p}o(Fe,"slice");function Le(t,s){return t=ne(t),le(typeof s=="string"?new Promise((i,a)=>{jt(s).then(u=>{Le(t,u).then(i).catch(a)})}):_.from(t).then(i=>{let a={};for(let u in s){let d=s[u],p=i.frames[0],w=wr*p.w,g=br*p.h,f=d.frames?d.frames.map(R=>new ce(p.x+(d.x+R.x)/w*p.w,p.y+(d.y+R.y)/g*p.h,R.w/w*p.w,R.h/g*p.h)):Fe(d.sliceX||1,d.sliceY||1,p.x+d.x/w*p.w,p.y+d.y/g*p.h,d.width/w*p.w,d.height/g*p.h),b=new _(i.tex,f,d.anims);L.sprites.addLoaded(u,b),a[u]=b}return a}))}o(Le,"loadSpriteAtlas");function Ve(t,s={}){let i=document.createElement("canvas"),a=t[0].width,u=t[0].height;i.width=a*t.length,i.height=u;let d=i.getContext("2d");t.forEach((w,g)=>{w instanceof ImageData?d.putImageData(w,g*a,0):d.drawImage(w,g*a,0)});let p=d.getImageData(0,0,t.length*a,u);return _.fromImage(p,{...s,sliceX:t.length,sliceY:1})}o(Ve,"createSpriteSheet");function ye(t,s,i={sliceX:1,sliceY:1,anims:{}}){return s=ne(s),Array.isArray(s)?s.some(a=>typeof a=="string")?L.sprites.add(t,Promise.all(s.map(a=>typeof a=="string"?Ht(a):Promise.resolve(a))).then(a=>Ve(a,i))):L.sprites.addLoaded(t,Ve(s,i)):typeof s=="string"?L.sprites.add(t,_.from(s,i)):L.sprites.addLoaded(t,_.fromImage(s,i))}o(ye,"loadSprite");function ke(t,s){return s=ne(s),L.sprites.add(t,new Promise(async i=>{let a=typeof s=="string"?await jt(s):s,u=await Promise.all(a.frames.map(Ht)),d=document.createElement("canvas");d.width=a.width,d.height=a.height*a.frames.length;let p=d.getContext("2d");u.forEach((g,f)=>{p.drawImage(g,0,f*a.height)});let w=await ye(null,d,{sliceY:a.frames.length,anims:a.anims});i(w)}))}o(ke,"loadPedit");function _e(t,s,i){s=ne(s),i=ne(i),typeof s=="string"&&!i&&(i=Zs(s)+".json");let a=typeof i=="string"?jt(i):Promise.resolve(i);return L.sprites.add(t,a.then(u=>{let d=u.meta.size,p=u.frames.map(g=>new ce(g.frame.x/d.w,g.frame.y/d.h,g.frame.w/d.w,g.frame.h/d.h)),w={};for(let g of u.meta.frameTags)g.from===g.to?w[g.name]=g.from:w[g.name]={from:g.from,to:g.to,speed:10,loop:!0,pingpong:g.direction==="pingpong"};return _.from(s,{frames:p,anims:w})}))}o(_e,"loadAseprite");function je(t,s,i){return L.shaders.addLoaded(t,Pt(s,i))}o(je,"loadShader");function ft(t,s,i){s=ne(s),i=ne(i);let a=o(d=>d?rr(d):Promise.resolve(null),"resolveUrl"),u=Promise.all([a(s),a(i)]).then(([d,p])=>Pt(d,p));return L.shaders.add(t,u)}o(ft,"loadShaderURL");function Te(t,s){return s=ne(s),L.sounds.add(t,typeof s=="string"?K.fromURL(s):K.fromArrayBuffer(s))}o(Te,"loadSound");function Oe(t,s){let i=new Audio(s);return i.preload="auto",L.music[t]=ne(s)}o(Oe,"loadMusic");function ze(t="bean"){return ye(t,cr)}o(ze,"loadBean");function rt(t){return L.sprites.get(t)}o(rt,"getSprite");function it(t){return L.sounds.get(t)}o(it,"getSound");function Et(t){return L.fonts.get(t)}o(Et,"getFont");function Yt(t){return L.bitmapFonts.get(t)}o(Yt,"getBitmapFont");function $t(t){return L.shaders.get(t)}o($t,"getShader");function Un(t){return L.custom.get(t)}o(Un,"getAsset");function Ot(t){if(typeof t=="string"){let s=rt(t);if(s)return s;if(j()<1)return null;throw new Error(`Sprite not found: ${t}`)}else{if(t instanceof _)return Re.loaded(t);if(t instanceof Re)return t;throw new Error(`Invalid sprite: ${t}`)}}o(Ot,"resolveSprite");function Sn(t){if(typeof t=="string"){let s=it(t);if(s)return s;if(j()<1)return null;throw new Error(`Sound not found: ${t}`)}else{if(t instanceof K)return Re.loaded(t);if(t instanceof Re)return t;throw new Error(`Invalid sound: ${t}`)}}o(Sn,"resolveSound");function Tn(t){if(!t)return U.defShader;if(typeof t=="string"){let s=$t(t);if(s)return s.data??s;if(j()<1)return null;throw new Error(`Shader not found: ${t}`)}else if(t instanceof Re)return t.data?t.data:t;return t}o(Tn,"resolveShader");function Xt(t){if(!t)return Xt(n.font??So);if(typeof t=="string"){let s=Yt(t),i=Et(t);if(s)return s.data??s;if(i)return i.data??i;if(document.fonts.check(`${xn}px ${t}`))return t;if(j()<1)return null;throw new Error(`Font not found: ${t}`)}else if(t instanceof Re)return t.data?t.data:t;return t}o(Xt,"resolveFont");function Cn(t){return t!==void 0&&($.masterNode.gain.value=t),$.masterNode.gain.value}o(Cn,"volume");function An(t,s={}){let i=new Ue,a=new Audio(t);$.ctx.createMediaElementSource(a).connect($.masterNode);function d(){se.paused||v.isHidden()&&!n.backgroundAudio||$.ctx.resume()}o(d,"resumeAudioCtx");function p(){d(),a.play()}return o(p,"play"),s.paused||p(),a.onended=()=>i.trigger(),{play(){p()},seek(w){a.currentTime=w},stop(){a.pause(),this.seek(0)},set loop(w){a.loop=w},get loop(){return a.loop},set paused(w){w?a.pause():p()},get paused(){return a.paused},time(){return a.currentTime},duration(){return a.duration},set volume(w){a.volume=We(w,0,1)},get volume(){return a.volume},set speed(w){a.playbackRate=Math.max(w,0)},get speed(){return a.playbackRate},set detune(w){},get detune(){return 0},onEnd(w){return i.add(w)},then(w){return this.onEnd(w)}}}o(An,"playMusic");function Kt(t,s={}){if(typeof t=="string"&&L.music[t])return An(L.music[t],s);let i=$.ctx,a=s.paused??!1,u=i.createBufferSource(),d=new Ue,p=i.createGain(),w=s.seek??0,g=0,f=0,b=!1;u.loop=!!s.loop,u.detune.value=s.detune??0,u.playbackRate.value=s.speed??1,u.connect(p),u.onended=()=>{Y()>=(u.buffer?.duration??Number.POSITIVE_INFINITY)&&d.trigger()},p.connect($.masterNode),p.gain.value=s.volume??1;let R=o(I=>{u.buffer=I.buf,a||(g=i.currentTime,u.start(0,w),b=!0)},"start"),G=Sn(t);G instanceof Re&&G.onLoad(R);let Y=o(()=>{if(!u.buffer)return 0;let I=a?f-g:i.currentTime-g,D=u.buffer.duration;return u.loop?I%D:Math.min(I,D)},"getTime"),q=o(I=>{let D=i.createBufferSource();return D.buffer=I.buffer,D.loop=I.loop,D.playbackRate.value=I.playbackRate.value,D.detune.value=I.detune.value,D.onended=I.onended,D.connect(p),D},"cloneNode");return{stop(){this.paused=!0,this.seek(0)},set paused(I){if(a!==I)if(a=I,I)b&&(u.stop(),b=!1),f=i.currentTime;else{u=q(u);let D=f-g;u.start(0,D),b=!0,g=i.currentTime-D,f=0}},get paused(){return a},play(I=0){this.seek(I),this.paused=!1},seek(I){u.buffer?.duration&&(I>u.buffer.duration||(a?(u=q(u),g=f-I):(u.stop(),u=q(u),g=i.currentTime-I,u.start(0,I),b=!0,f=0)))},set speed(I){u.playbackRate.value=I},get speed(){return u.playbackRate.value},set detune(I){u.detune.value=I},get detune(){return u.detune.value},set volume(I){p.gain.value=Math.max(I,0)},get volume(){return p.gain.value},set loop(I){u.loop=I},get loop(){return u.loop},duration(){return u.buffer?.duration??0},time(){return Y()%this.duration()},onEnd(I){return d.add(I)},then(I){return this.onEnd(I)}}}o(Kt,"play");function Wt(t){return Kt($.burpSnd,t)}o(Wt,"burp");function Mn(t,s){let i=new xt(V,t,s);return{clear:()=>i.clear(),free:()=>i.free(),toDataURL:()=>i.toDataURL(),toImageData:()=>i.toImageData(),width:i.width,height:i.height,draw:a=>{Pe(),i.bind(),a(),Pe(),i.unbind()}}}o(Mn,"makeCanvas");function Pt(t=ls,s=ds){let i=Do.replace("{{user}}",t??ls),a=Go.replace("{{user}}",s??ds);try{return new pn(V,i,a,fs.map(u=>u.name))}catch(u){let p=/(?<type>^\w+) SHADER ERROR: 0:(?<line>\d+): (?<msg>.+)/,w=tr(u).match(p),g=Number(w.groups.line)-14,f=w.groups.msg.trim(),b=w.groups.type.toLowerCase();throw new Error(`${b} shader line ${g}: ${f}`)}}o(Pt,"makeShader");function Rn(t,s,i,a){let u=t.width/s,d={},p=a.split("").entries();for(let[w,g]of p)d[g]=new ce(w%u*s,Math.floor(w/u)*i,s,i);return{tex:t,map:d,size:i}}o(Rn,"makeFont");function Dt(t,s,i,a=U.defTex,u=U.defShader,d={}){let p=Tn(u);if(!p||p instanceof Re)return;let w=U.fixed||i?U.transform:A.cam.transform.mult(U.transform),g=[];for(let f of t){let b=Jt(w.multVec2(f.pos));g.push(b.x,b.y,f.uv.x,f.uv.y,f.color.r/255,f.color.g/255,f.color.b/255,f.opacity)}U.renderer.push(T.TRIANGLES,g,s,p,a,d)}o(Dt,"drawRaw");function Pe(){U.renderer.flush()}o(Pe,"flush");function Ut(){T.clear(T.COLOR_BUFFER_BIT),U.frameBuffer.bind(),T.clear(T.COLOR_BUFFER_BIT),U.bgColor||ut(()=>{Je({width:Ae(),height:De(),quad:new ce(0,0,Ae()/mr,De()/mr),tex:U.bgTex,fixed:!0})}),U.renderer.numDraws=0,U.fixed=!1,U.transformStack.length=0,U.transform=new Ge}o(Ut,"frameStart");function On(t,s){U.postShader=t,U.postShaderUniform=s??null}o(On,"usePostEffect");function Gt(){Pe(),U.lastDrawCalls=U.renderer.numDraws,U.frameBuffer.unbind(),T.viewport(0,0,T.drawingBufferWidth,T.drawingBufferHeight);let t=U.width,s=U.height;U.width=T.drawingBufferWidth/y,U.height=T.drawingBufferHeight/y,St({flipY:!0,tex:U.frameBuffer.tex,pos:new x(U.viewport.x,U.viewport.y),width:U.viewport.width,height:U.viewport.height,shader:U.postShader,uniform:typeof U.postShaderUniform=="function"?U.postShaderUniform():U.postShaderUniform,fixed:!0}),Pe(),U.width=t,U.height=s}o(Gt,"frameEnd");function Jt(t){return new x(t.x/Ae()*2-1,-t.y/De()*2+1)}o(Jt,"screen2ndc");function Pn(t){U.transform=t.clone()}o(Pn,"pushMatrix");function oe(...t){if(t[0]===void 0)return;let s=M(...t);s.x===0&&s.y===0||U.transform.translate(s)}o(oe,"pushTranslate");function ue(...t){if(t[0]===void 0)return;let s=M(...t);s.x===1&&s.y===1||U.transform.scale(s)}o(ue,"pushScale");function He(t){t&&U.transform.rotate(t)}o(He,"pushRotate");function pe(){U.transformStack.push(U.transform.clone())}o(pe,"pushTransform");function xe(){U.transformStack.length>0&&(U.transform=U.transformStack.pop())}o(xe,"popTransform");function Je(t){if(t.width===void 0||t.height===void 0)throw new Error('drawUVQuad() requires property "width" and "height".');if(t.width<=0||t.height<=0)return;let s=t.width,i=t.height,u=Rt(t.anchor||vn).scale(new x(s,i).scale(-.5)),d=t.quad||new ce(0,0,1,1),p=t.color||Z(255,255,255),w=t.opacity??1,g=t.tex?vr/t.tex.width:0,f=t.tex?vr/t.tex.height:0,b=d.x+g,R=d.y+f,G=d.w-g*2,Y=d.h-f*2;pe(),oe(t.pos),He(t.angle),ue(t.scale),oe(u),Dt([{pos:new x(-s/2,i/2),uv:new x(t.flipX?b+G:b,t.flipY?R:R+Y),color:p,opacity:w},{pos:new x(-s/2,-i/2),uv:new x(t.flipX?b+G:b,t.flipY?R+Y:R),color:p,opacity:w},{pos:new x(s/2,-i/2),uv:new x(t.flipX?b:b+G,t.flipY?R+Y:R),color:p,opacity:w},{pos:new x(s/2,i/2),uv:new x(t.flipX?b:b+G,t.flipY?R:R+Y),color:p,opacity:w}],[0,1,3,1,2,3],t.fixed,t.tex,t.shader,t.uniform),xe()}o(Je,"drawUVQuad");function St(t){if(!t.tex)throw new Error('drawTexture() requires property "tex".');let s=t.quad??new ce(0,0,1,1),i=t.tex.width*s.w,a=t.tex.height*s.h,u=new x(1);if(t.tiled){let d=Math.ceil((t.width||i)/i),p=Math.ceil((t.height||a)/a),g=Rt(t.anchor||vn).add(new x(1,1)).scale(.5).scale(d*i,p*a);for(let f=0;f<d;f++)for(let b=0;b<p;b++)Je(Object.assign({},t,{pos:(t.pos||new x(0)).add(new x(i*f,a*b)).sub(g),scale:u.scale(t.scale||new x(1)),tex:t.tex,quad:s,width:i,height:a,anchor:"topleft"}))}else t.width&&t.height?(u.x=t.width/i,u.y=t.height/a):t.width?(u.x=t.width/i,u.y=u.x):t.height&&(u.y=t.height/a,u.x=u.y),Je(Object.assign({},t,{scale:u.scale(t.scale||new x(1)),tex:t.tex,quad:s,width:i,height:a}))}o(St,"drawTexture");function Qt(t){if(!t.sprite)throw new Error('drawSprite() requires property "sprite"');let s=Ot(t.sprite);if(!s||!s.data)return;let i=s.data.frames[t.frame??0];if(!i)throw new Error(`Frame not found: ${t.frame??0}`);St(Object.assign({},t,{tex:s.data.tex,quad:i.scale(t.quad??new ce(0,0,1,1))}))}o(Qt,"drawSprite");function ot(t,s,i,a,u,d=1){a=we(a%360),u=we(u%360),u<=a&&(u+=Math.PI*2);let p=[],w=Math.ceil((u-a)/we(8)*d),g=(u-a)/w;for(let f=a;f<u;f+=g)p.push(t.add(s*Math.cos(f),i*Math.sin(f)));return p.push(t.add(s*Math.cos(u),i*Math.sin(u))),p}o(ot,"getArcPts");function l(t){if(t.width===void 0||t.height===void 0)throw new Error('drawRect() requires property "width" and "height".');if(t.width<=0||t.height<=0)return;let s=t.width,i=t.height,u=Rt(t.anchor||vn).add(1,1).scale(new x(s,i).scale(-.5)),d=[new x(0,0),new x(s,0),new x(s,i),new x(0,i)];if(t.radius){let p=Math.min(Math.min(s,i)/2,t.radius);d=[new x(p,0),new x(s-p,0),...ot(new x(s-p,p),p,p,270,360),new x(s,p),new x(s,i-p),...ot(new x(s-p,i-p),p,p,0,90),new x(s-p,i),new x(p,i),...ot(new x(p,i-p),p,p,90,180),new x(0,i-p),new x(0,p),...ot(new x(p,p),p,p,180,270)]}$e(Object.assign({},t,{offset:u,pts:d,...t.gradient?{colors:t.horizontal?[t.gradient[0],t.gradient[1],t.gradient[1],t.gradient[0]]:[t.gradient[0],t.gradient[0],t.gradient[1],t.gradient[1]]}:{}}))}o(l,"drawRect");function E(t){let{p1:s,p2:i}=t;if(!s||!i)throw new Error('drawLine() requires properties "p1" and "p2".');let a=t.width||1,u=i.sub(s).unit().normal().scale(a*.5),d=[s.sub(u),s.add(u),i.add(u),i.sub(u)].map(p=>({pos:new x(p.x,p.y),uv:new x(0),color:t.color??J.WHITE,opacity:t.opacity??1}));Dt(d,[0,1,3,1,2,3],t.fixed,U.defTex,t.shader,t.uniform)}o(E,"drawLine");function P(t){let s=t.pts;if(!s)throw new Error('drawLines() requires property "pts".');if(!(s.length<2))if(t.radius&&s.length>=3){let i=s[0].sdist(s[1]);for(let u=1;u<s.length-1;u++)i=Math.min(s[u].sdist(s[u+1]),i);let a=Math.min(t.radius,Math.sqrt(i)/2);E(Object.assign({},t,{p1:s[0],p2:s[1]}));for(let u=1;u<s.length-2;u++){let d=s[u],p=s[u+1];E(Object.assign({},t,{p1:d,p2:p}))}E(Object.assign({},t,{p1:s[s.length-2],p2:s[s.length-1]}))}else for(let i=0;i<s.length-1;i++)E(Object.assign({},t,{p1:s[i],p2:s[i+1]})),t.join!=="none"&&Ce(Object.assign({},t,{pos:s[i],radius:t.width/2}))}o(P,"drawLines");function H(t,s){let i=s.segments??16,a=[];for(let u=0;u<=i;u++)a.push(t(u/i));P({pts:a,width:s.width||1,pos:s.pos,color:s.color})}o(H,"drawCurve");function ge(t){H(s=>es(t.pt1,t.pt2,t.pt3,t.pt4,s),t)}o(ge,"drawBezier");function ee(t){if(!t.p1||!t.p2||!t.p3)throw new Error('drawTriangle() requires properties "p1", "p2" and "p3".');return $e(Object.assign({},t,{pts:[t.p1,t.p2,t.p3]}))}o(ee,"drawTriangle");function Ce(t){if(typeof t.radius!="number")throw new Error('drawCircle() requires property "radius".');t.radius!==0&&at(Object.assign({},t,{radiusX:t.radius,radiusY:t.radius,angle:0}))}o(Ce,"drawCircle");function at(t){if(t.radiusX===void 0||t.radiusY===void 0)throw new Error('drawEllipse() requires properties "radiusX" and "radiusY".');if(t.radiusX===0||t.radiusY===0)return;let s=t.start??0,i=t.end??360,a=Rt(t.anchor??"center").scale(new x(-t.radiusX,-t.radiusY)),u=ot(a,t.radiusX,t.radiusY,s,i,t.resolution);u.unshift(a);let d=Object.assign({},t,{pts:u,radius:0,...t.gradient?{colors:[t.gradient[0],...Array(u.length-1).fill(t.gradient[1])]}:{}});if(i-s>=360&&t.outline){t.fill!==!1&&$e(Object.assign({},d,{outline:null})),$e(Object.assign({},d,{pts:u.slice(1),fill:!1}));return}$e(d)}o(at,"drawEllipse");function $e(t){if(!t.pts)throw new Error('drawPolygon() requires property "pts".');let s=t.pts.length;if(!(s<3)){if(pe(),oe(t.pos),ue(t.scale),He(t.angle),oe(t.offset),t.fill!==!1){let i=t.color??J.WHITE,a=t.pts.map((d,p)=>({pos:new x(d.x,d.y),uv:new x(0,0),color:t.colors&&t.colors[p]?t.colors[p].mult(i):i,opacity:t.opacity??1})),u=[...Array(s-2).keys()].map(d=>[0,d+1,d+2]).flat();Dt(a,t.indices??u,t.fixed,U.defTex,t.shader,t.uniform)}t.outline&&P({pts:[...t.pts,t.pts[0]],radius:t.radius,width:t.outline.width,color:t.outline.color,join:t.outline.join,uniform:t.uniform,fixed:t.fixed,opacity:t.opacity}),xe()}}o($e,"drawPolygon");function Xe(t,s,i){Pe(),T.clear(T.STENCIL_BUFFER_BIT),T.enable(T.STENCIL_TEST),T.stencilFunc(T.NEVER,1,255),T.stencilOp(T.REPLACE,T.REPLACE,T.REPLACE),s(),Pe(),T.stencilFunc(i,1,255),T.stencilOp(T.KEEP,T.KEEP,T.KEEP),t(),Pe(),T.disable(T.STENCIL_TEST)}o(Xe,"drawStenciled");function Tt(t,s){Xe(t,s,T.EQUAL)}o(Tt,"drawMasked");function ms(t,s){Xe(t,s,T.NOTEQUAL)}o(ms,"drawSubtracted");function ps(){return(U.viewport.width+U.viewport.height)/(U.width+U.height)}o(ps,"getViewportScale");function ut(t){Pe();let s=U.width,i=U.height;U.width=U.viewport.width,U.height=U.viewport.height,t(),Pe(),U.width=s,U.height=i}o(ut,"drawUnscaled");function gs(t,s){s.pos&&(t.pos=t.pos.add(s.pos)),s.scale&&(t.scale=t.scale.scale(M(s.scale))),s.angle&&(t.angle+=s.angle),s.color&&t.ch.length===1&&(t.color=t.color.mult(s.color)),s.opacity&&(t.opacity*=s.opacity)}o(gs,"applyCharTransform");let ws=/\[(?<style>\w+)\](?<text>.*?)\[\/\k<style>\]/g;function xr(t){let s={},i=t.replace(ws,"$2"),a=0;for(let u of t.matchAll(ws)){let d=u.index-a;for(let p=0;p<u.groups.text.length;p++)s[p+d]=[u.groups.style];a+=u[0].length-u.groups.text.length}return{charStyleMap:s,text:i}}o(xr,"compileStyledText");let Dn={};function mt(t){if(t.text===void 0)throw new Error('formatText() requires property "text".');let s=Xt(t.font);if(t.text===""||s instanceof Re||!s)return{width:0,height:0,chars:[],opt:t};let{charStyleMap:i,text:a}=xr(t.text+""),u=nr(a);if(s instanceof ae||typeof s=="string"){let Q=s instanceof ae?s.fontface.family:s,X=s instanceof ae?{outline:s.outline,filter:s.filter}:{outline:null,filter:hs},k=Dn[Q]??{font:{tex:new qe(V,pr,gr,{filter:X.filter}),map:{},size:xn},cursor:new x(0),outline:X.outline};Dn[Q]||(Dn[Q]=k),s=k.font;for(let be of u)if(!k.font.map[be]){let S=O;S.clearRect(0,0,C.width,C.height),S.font=`${s.size}px ${Q}`,S.textBaseline="top",S.textAlign="left",S.fillStyle="#ffffff";let B=S.measureText(be),F=Math.ceil(B.width);if(!F)continue;let N=s.size;k.outline&&(S.lineJoin="round",S.lineWidth=k.outline.width*2,S.strokeStyle=k.outline.color.toHex(),S.strokeText(be,k.outline.width,k.outline.width),F+=k.outline.width*2,N+=k.outline.width*3),S.fillText(be,k.outline?.width??0,k.outline?.width??0);let W=S.getImageData(0,0,F,N);if(k.cursor.x+F>pr&&(k.cursor.x=0,k.cursor.y+=N,k.cursor.y>gr))throw new Error("Font atlas exceeds character limit");s.tex.update(W,k.cursor.x,k.cursor.y),s.map[be]=new ce(k.cursor.x,k.cursor.y,F,N),k.cursor.x+=F}}let d=t.size||s.size,p=M(t.scale??1).scale(d/s.size),w=t.lineSpacing??0,g=t.letterSpacing??0,f=0,b=0,R=0,G=[],Y=[],q=0,I=null,D=null;for(;q<u.length;){let Q=u[q];if(Q===`
|
|
53
|
+
`)R+=d+w,G.push({width:f-g,chars:Y}),I=null,D=null,f=0,Y=[];else{let X=s.map[Q];if(X){let k=X.w*p.x;t.width&&f+k>t.width&&(R+=d+w,I!=null&&(q-=Y.length-I,Q=u[q],X=s.map[Q],k=X.w*p.x,Y=Y.slice(0,I-1),f=D),I=null,D=null,G.push({width:f-g,chars:Y}),f=0,Y=[]),Y.push({tex:s.tex,width:X.w,height:X.h,quad:new ce(X.x/s.tex.width,X.y/s.tex.height,X.w/s.tex.width,X.h/s.tex.height),ch:Q,pos:new x(f,R),opacity:t.opacity??1,color:t.color??J.WHITE,scale:M(p),angle:0}),Q===" "&&(I=Y.length,D=f),f+=k,b=Math.max(b,f),f+=g}}q++}G.push({width:f-g,chars:Y}),R+=d,t.width&&(b=t.width);let he=[];for(let Q=0;Q<G.length;Q++){let X=(b-G[Q].width)*Fo(t.align??"left");for(let k of G[Q].chars){let be=s.map[k.ch],S=he.length+Q;if(k.pos=k.pos.add(X,0).add(be.w*p.x*.5,be.h*p.y*.5),t.transform){let B=typeof t.transform=="function"?t.transform(S,k.ch):t.transform;B&&gs(k,B)}if(i[S]){let B=i[S];for(let F of B){let N=t.styles[F],W=typeof N=="function"?N(S,k.ch):N;W&&gs(k,W)}}he.push(k)}}return{width:b,height:R,chars:he,opt:t}}o(mt,"formatText");function bs(t){pt(mt(t))}o(bs,"drawText");function pt(t){pe(),oe(t.opt.pos),He(t.opt.angle),oe(Rt(t.opt.anchor??"topleft").add(1,1).scale(t.width,t.height).scale(-.5)),t.chars.forEach(s=>{Je({tex:s.tex,width:s.width,height:s.height,pos:s.pos,scale:s.scale,angle:s.angle,color:s.color,opacity:s.opacity,quad:s.quad,anchor:"center",uniform:t.opt.uniform,shader:t.opt.shader,fixed:t.opt.fixed})}),xe()}o(pt,"drawFormattedText");function Ae(){return U.width}o(Ae,"width");function De(){return U.height}o(De,"height");function Er(t){return new x((t.x-U.viewport.x)*Ae()/U.viewport.width,(t.y-U.viewport.y)*De()/U.viewport.height)}o(Er,"windowToContent");function Ur(t){return new x(t.x*U.viewport.width/U.width,t.y*U.viewport.height/U.height)}o(Ur,"contentToView");function Zt(){return Er(v.mousePos())}o(Zt,"mousePos");let vs=!1,se={inspect:!1,timeScale:1,showLog:!0,fps:()=>v.fps(),numFrames:()=>v.numFrames(),stepFrame:Rs,drawCalls:()=>U.lastDrawCalls,clearLog:()=>A.logs=[],log:t=>{let s=n.logMax??Ao;A.logs.unshift({msg:t,time:v.time()}),A.logs.length>s&&(A.logs=A.logs.slice(0,s))},error:t=>se.log(new Error(t.toString?t.toString():t)),curRecording:null,numObjects:()=>Nn("*",{recursive:!0}).length,get paused(){return vs},set paused(t){vs=t,t?$.ctx.suspend():$.ctx.resume()}};function Ke(){return v.dt()*se.timeScale}o(Ke,"dt");function Sr(...t){return t.length>0&&(A.cam.pos=M(...t)),A.cam.pos?A.cam.pos.clone():rn()}o(Sr,"camPos");function Tr(...t){return t.length>0&&(A.cam.scale=M(...t)),A.cam.scale.clone()}o(Tr,"camScale");function Cr(t){return t!==void 0&&(A.cam.angle=t),A.cam.angle}o(Cr,"camRot");function Ar(t=12){A.cam.shake+=t}o(Ar,"shake");function ys(t){return A.cam.transform.multVec2(t)}o(ys,"toScreen");function xs(t){return A.cam.transform.invert().multVec2(t)}o(xs,"toWorld");function en(t){let s=new Ge;return t.pos&&s.translate(t.pos),t.scale&&s.scale(t.scale),t.angle&&s.rotate(t.angle),t.parent?s.mult(t.parent.transform):s}o(en,"calcTransform");function Gn(t=[]){let s=new Map,i={},a=new nt,u=[],d=null,p=!1,w={id:er(),hidden:!1,transform:new Ge,children:[],parent:null,set paused(f){if(f!==p){p=f;for(let b of u)b.paused=f}},get paused(){return p},add(f=[]){let b=Array.isArray(f)?Gn(f):f;if(b.parent)throw new Error("Cannot add a game obj that already has a parent.");return b.parent=this,b.transform=en(b),this.children.push(b),b.trigger("add",b),A.events.trigger("add",b),b},readd(f){let b=this.children.indexOf(f);return b!==-1&&(this.children.splice(b,1),this.children.push(f)),f},remove(f){let b=this.children.indexOf(f);if(b!==-1){f.parent=null,this.children.splice(b,1);let R=o(G=>{G.trigger("destroy"),A.events.trigger("destroy",G),G.children.forEach(Y=>R(Y))},"trigger");R(f)}},removeAll(f){if(f)this.get(f).forEach(b=>this.remove(b));else for(let b of[...this.children])this.remove(b)},update(){this.paused||(this.children.sort((f,b)=>(f.z??0)-(b.z??0)).forEach(f=>f.update()),this.trigger("update"))},draw(){if(this.hidden)return;this.canvas&&(Pe(),this.canvas.bind());let f=U.fixed;this.fixed&&(U.fixed=!0),pe(),oe(this.pos),ue(this.scale),He(this.angle);let b=this.children.sort((R,G)=>(R.z??0)-(G.z??0));if(this.mask){let R={intersect:Tt,subtract:ms}[this.mask];if(!R)throw new Error(`Invalid mask func: "${this.mask}"`);R(()=>{b.forEach(G=>G.draw())},()=>{this.trigger("draw")})}else this.trigger("draw"),b.forEach(R=>R.draw());xe(),U.fixed=f,this.canvas&&(Pe(),this.canvas.unbind())},drawInspect(){this.hidden||(pe(),oe(this.pos),ue(this.scale),He(this.angle),this.children.sort((f,b)=>(f.z??0)-(b.z??0)).forEach(f=>f.drawInspect()),this.trigger("drawInspect"),xe())},use(f){if(!f)return;if(typeof f=="string")return this.use({id:f});let b=[];f.id&&(this.unuse(f.id),i[f.id]=[],b=i[f.id],s.set(f.id,f));for(let G in f){if(Io.has(G))continue;let Y=Object.getOwnPropertyDescriptor(f,G);if(typeof Y.value=="function"&&(f[G]=f[G].bind(this)),Y.set&&Object.defineProperty(f,G,{set:Y.set.bind(this)}),Y.get&&Object.defineProperty(f,G,{get:Y.get.bind(this)}),Bo.has(G)){let q=G==="add"?()=>{d=o(I=>b.push(I),"onCurCompCleanup"),f[G](),d=null}:f[G];b.push(this.on(G,q).cancel)}else if(this[G]===void 0)Object.defineProperty(this,G,{get:()=>f[G],set:q=>f[G]=q,configurable:!0,enumerable:!0}),b.push(()=>delete this[G]);else throw new Error(`Duplicate component property: "${G}"`)}let R=o(()=>{if(f.require){for(let G of f.require)if(!this.c(G))throw new Error(`Component "${f.id}" requires component "${G}"`)}},"checkDeps");f.destroy&&b.push(f.destroy.bind(this)),this.exists()?(R(),f.add&&(d=o(G=>b.push(G),"onCurCompCleanup"),f.add.call(this),d=null)):f.require&&b.push(this.on("add",R).cancel)},unuse(f){i[f]&&(i[f].forEach(b=>b()),delete i[f]),s.has(f)&&s.delete(f)},c(f){return s.get(f)},get(f,b={}){let R=b.recursive?this.children.flatMap(o(function G(Y){return[Y,...Y.children.flatMap(G)]},"recurse")):this.children;if(R=R.filter(G=>f?G.is(f):!0),b.liveUpdate){let G=o(q=>b.recursive?this.isAncestorOf(q):q.parent===this,"isChild"),Y=[];Y.push(In(q=>{G(q)&&q.is(f)&&R.push(q)})),Y.push(Es(q=>{if(G(q)&&q.is(f)){let I=R.findIndex(D=>D.id===q.id);I!==-1&&R.splice(I,1)}})),this.onDestroy(()=>{for(let q of Y)q.cancel()})}return R},isAncestorOf(f){return f.parent?f.parent===this||this.isAncestorOf(f.parent):!1},exists(){return A.root.isAncestorOf(this)},is(f){if(f==="*")return!0;if(Array.isArray(f)){for(let b of f)if(!this.c(b))return!1;return!0}else return this.c(f)!=null},on(f,b){let R=a.on(f,b.bind(this));return d&&d(()=>R.cancel()),R},trigger(f,...b){a.trigger(f,...b),A.objEvents.trigger(f,this,...b)},destroy(){this.parent&&this.parent.remove(this)},inspect(){let f={};for(let[b,R]of s)f[b]=R.inspect?R.inspect():null;return f},onAdd(f){return this.on("add",f)},onUpdate(f){return this.on("update",f)},onDraw(f){return this.on("draw",f)},onDestroy(f){return this.on("destroy",f)},clearEvents(){a.clear()}},g=["onKeyPress","onKeyPressRepeat","onKeyDown","onKeyRelease","onMousePress","onMouseDown","onMouseRelease","onMouseMove","onCharInput","onMouseMove","onTouchStart","onTouchMove","onTouchEnd","onScroll","onGamepadButtonPress","onGamepadButtonDown","onGamepadButtonRelease","onGamepadStick"];for(let f of g)w[f]=(...b)=>{let R=v[f](...b);return u.push(R),w.onDestroy(()=>R.cancel()),R};for(let f of t)w.use(f);return w}o(Gn,"make");function ct(t,s,i){return A.objEvents[t]||(A.objEvents[t]=new _t),A.objEvents.on(t,(a,...u)=>{a.is(s)&&i(a,...u)})}o(ct,"on");let Mr=Be(t=>{let s=Ft([{update:t}]);return{get paused(){return s.paused},set paused(i){s.paused=i},cancel:()=>s.destroy()}},(t,s)=>ct("update",t,s)),Rr=Be(t=>{let s=Ft([{draw:t}]);return{get paused(){return s.hidden},set paused(i){s.hidden=i},cancel:()=>s.destroy()}},(t,s)=>ct("draw",t,s)),In=Be(t=>A.events.on("add",t),(t,s)=>ct("add",t,s)),Es=Be(t=>A.events.on("destroy",t),(t,s)=>ct("destroy",t,s));function Or(t,s,i){return ct("collide",t,(a,u,d)=>u.is(s)&&i(a,u,d))}o(Or,"onCollide");function Pr(t,s,i){return ct("collideUpdate",t,(a,u,d)=>u.is(s)&&i(a,u,d))}o(Pr,"onCollideUpdate");function Dr(t,s,i){return ct("collideEnd",t,(a,u,d)=>u.is(s)&&i(a,u,d))}o(Dr,"onCollideEnd");function tn(t,s){Nn(t,{recursive:!0}).forEach(s),In(t,s)}o(tn,"forAllCurrentAndFuture");let Gr=Be(t=>v.onMousePress(t),(t,s)=>{let i=[];return tn(t,a=>{if(!a.area)throw new Error("onClick() requires the object to have area() component");i.push(a.onClick(()=>s(a)))}),tt.join(i)});function Ir(t,s){let i=[];return tn(t,a=>{if(!a.area)throw new Error("onHover() requires the object to have area() component");i.push(a.onHover(()=>s(a)))}),tt.join(i)}o(Ir,"onHover");function Br(t,s){let i=[];return tn(t,a=>{if(!a.area)throw new Error("onHoverUpdate() requires the object to have area() component");i.push(a.onHoverUpdate(()=>s(a)))}),tt.join(i)}o(Br,"onHoverUpdate");function Fr(t,s){let i=[];return tn(t,a=>{if(!a.area)throw new Error("onHoverEnd() requires the object to have area() component");i.push(a.onHoverEnd(()=>s(a)))}),tt.join(i)}o(Fr,"onHoverEnd");function Lr(t){A.gravity=t}o(Lr,"setGravity");function Vr(){return A.gravity}o(Vr,"getGravity");function Nr(...t){t.length===1||t.length===2?(U.bgColor=Z(t[0]),t[1]&&(U.bgAlpha=t[1])):(t.length===3||t.length===4)&&(U.bgColor=Z(t[0],t[1],t[2]),t[3]&&(U.bgAlpha=t[3])),T.clearColor(U.bgColor.r/255,U.bgColor.g/255,U.bgColor.b/255,U.bgAlpha)}o(Nr,"setBackground");function kr(){return U.bgColor.clone()}o(kr,"getBackground");function nn(...t){return{id:"pos",pos:M(...t),moveBy(...s){this.pos=this.pos.add(M(...s))},move(...s){this.moveBy(M(...s).scale(Ke()))},moveTo(...s){if(typeof s[0]=="number"&&typeof s[1]=="number")return this.moveTo(M(s[0],s[1]),s[2]);let i=s[0],a=s[1];if(a===void 0){this.pos=M(i);return}let u=i.sub(this.pos);if(u.len()<=a*Ke()){this.pos=M(i);return}this.move(u.unit().scale(a))},worldPos(){return this.parent?this.parent.transform.multVec2(this.pos):this.pos},screenPos(){let s=this.worldPos();return Bt(this)?s:ys(s)},inspect(){return`(${Math.round(this.pos.x)}, ${Math.round(this.pos.y)})`},drawInspect(){Ce({color:Z(255,0,0),radius:4/ps()})}}}o(nn,"pos");function sn(...t){return t.length===0?sn(1):{id:"scale",scale:M(...t),scaleTo(...s){this.scale=M(...s)},scaleBy(...s){this.scale.scale(M(...s))},inspect(){return`(${It(this.scale.x,2)}, ${It(this.scale.y,2)})`}}}o(sn,"scale");function _r(t){return{id:"rotate",angle:t??0,rotateBy(s){this.angle+=s},rotateTo(s){this.angle=s},inspect(){return`${Math.round(this.angle)}`}}}o(_r,"rotate");function jr(...t){return{id:"color",color:Z(...t),inspect(){return this.color.toString()}}}o(jr,"color");function It(t,s){return Number(t.toFixed(s))}o(It,"toFixed");function Hr(t){return{id:"opacity",opacity:t??1,inspect(){return`${It(this.opacity,1)}`},fadeOut(s=1,i=qt.linear){return kn(this.opacity,0,s,a=>this.opacity=a,i)}}}o(Hr,"opacity");function Bn(t){if(!t)throw new Error("Please define an anchor");return{id:"anchor",anchor:t,inspect(){return typeof this.anchor=="string"?this.anchor:this.anchor.toString()}}}o(Bn,"anchor");function qr(t){return{id:"z",z:t,inspect(){return`${this.z}`}}}o(qr,"z");function zr(t,s){return{id:"follow",require:["pos"],follow:{obj:t,offset:s??M(0)},add(){t.exists()&&(this.pos=this.follow.obj.pos.add(this.follow.offset))},update(){t.exists()&&(this.pos=this.follow.obj.pos.add(this.follow.offset))}}}o(zr,"follow");function Yr(t,s){let i=typeof t=="number"?x.fromAngle(t):t.unit();return{id:"move",require:["pos"],update(){this.move(i.scale(s))}}}o(Yr,"move");let $r=200;function Xr(t={}){let s=t.distance??$r,i=!1;return{id:"offscreen",require:["pos"],isOffScreen(){let a=this.screenPos(),u=new re(M(0),Ae(),De());return!ln(u,a)&&u.sdistToPoint(a)>s*s},onExitScreen(a){return this.on("exitView",a)},onEnterScreen(a){return this.on("enterView",a)},update(){this.isOffScreen()?(i||(this.trigger("exitView"),i=!0),t.hide&&(this.hidden=!0),t.pause&&(this.paused=!0),t.destroy&&this.destroy()):(i&&(this.trigger("enterView"),i=!1),t.hide&&(this.hidden=!1),t.pause&&(this.paused=!1))}}}o(Xr,"offscreen");function Bt(t){return t.fixed?!0:t.parent?Bt(t.parent):!1}o(Bt,"isFixed");function Kr(t={}){let s={},i=new Set;return{id:"area",collisionIgnore:t.collisionIgnore??[],add(){this.area.cursor&&this.onHover(()=>v.setCursor(this.area.cursor)),this.onCollideUpdate((a,u)=>{s[a.id]||this.trigger("collide",a,u),s[a.id]=u,i.add(a.id)})},update(){for(let a in s)i.has(Number(a))||(this.trigger("collideEnd",s[a].target),delete s[a]);i.clear()},drawInspect(){let a=this.localArea();pe(),ue(this.area.scale),oe(this.area.offset);let u={outline:{width:4/ps(),color:Z(0,0,255)},anchor:this.anchor,fill:!1,fixed:Bt(this)};a instanceof re?l({...u,pos:a.pos,width:a.width,height:a.height}):a instanceof Ee?$e({...u,pts:a.pts}):a instanceof Me&&Ce({...u,pos:a.center,radius:a.radius}),xe()},area:{shape:t.shape??null,scale:t.scale?M(t.scale):M(1),offset:t.offset??M(0),cursor:t.cursor??null},isClicked(){return v.isMousePressed()&&this.isHovering()},isHovering(){let a=Bt(this)?Zt():xs(Zt());return this.hasPoint(a)},checkCollision(a){return s[a.id]??null},getCollisions(){return Object.values(s)},isColliding(a){return!!s[a.id]},isOverlapping(a){let u=s[a.id];return u&&u.hasOverlap()},onClick(a){let u=v.onMousePress("left",()=>{this.isHovering()&&a()});return this.onDestroy(()=>u.cancel()),u},onHover(a){let u=!1;return this.onUpdate(()=>{u?u=this.isHovering():this.isHovering()&&(u=!0,a())})},onHoverUpdate(a){return this.onUpdate(()=>{this.isHovering()&&a()})},onHoverEnd(a){let u=!1;return this.onUpdate(()=>{u?this.isHovering()||(u=!1,a()):u=this.isHovering()})},onCollide(a,u){if(typeof a=="function"&&u===void 0)return this.on("collide",a);if(typeof a=="string")return this.onCollide((d,p)=>{d.is(a)&&u(d,p)})},onCollideUpdate(a,u){if(typeof a=="function"&&u===void 0)return this.on("collideUpdate",a);if(typeof a=="string")return this.on("collideUpdate",(d,p)=>d.is(a)&&u(d,p))},onCollideEnd(a,u){if(typeof a=="function"&&u===void 0)return this.on("collideEnd",a);if(typeof a=="string")return this.on("collideEnd",d=>d.is(a)&&u(d))},hasPoint(a){return dt(this.worldArea(),a)},resolveCollision(a){let u=this.checkCollision(a);u&&!u.resolved&&(this.pos=this.pos.add(u.displacement),u.resolved=!0)},localArea(){return this.area.shape?this.area.shape:this.renderArea()},worldArea(){let a=this.localArea();if(!(a instanceof Ee||a instanceof re))throw new Error("Only support polygon and rect shapes for now");let u=this.transform.clone().scale(M(this.area.scale??1)).translate(this.area.offset);if(a instanceof re){let d=Rt(this.anchor||vn).add(1,1).scale(-.5).scale(a.width,a.height);u.translate(d)}return a.transform(u)},screenArea(){let a=this.worldArea();return Bt(this)?a:a.transform(A.cam.transform)}}}o(Kr,"area");function gt(t){return{color:t.color,opacity:t.opacity,anchor:t.anchor,outline:t.outline,shader:t.shader,uniform:t.uniform}}o(gt,"getRenderProps");function Fn(t,s={}){let i=null,a=null,u=null,d=new Ue;if(!t)throw new Error("Please pass the resource name or data to sprite()");let p=o((w,g,f,b)=>{let R=M(1,1);return f&&b?(R.x=f/(w.width*g.w),R.y=b/(w.height*g.h)):f?(R.x=f/(w.width*g.w),R.y=R.x):b&&(R.y=b/(w.height*g.h),R.x=R.y),R},"calcTexScale");return{id:"sprite",width:0,height:0,frame:s.frame||0,quad:s.quad||new ce(0,0,1,1),animSpeed:s.animSpeed??1,flipX:s.flipX??!1,flipY:s.flipY??!1,draw(){if(!i)return;let w=i.frames[this.frame??0];if(!w)throw new Error(`Frame not found: ${this.frame??0}`);if(i.slice9){let{left:g,right:f,top:b,bottom:R}=i.slice9,G=i.tex.width*w.w,Y=i.tex.height*w.h,q=this.width-g-f,I=this.height-b-R,D=g/G,he=f/G,Q=1-D-he,X=b/Y,k=R/Y,be=1-X-k,S=[me(0,0,D,X),me(D,0,Q,X),me(D+Q,0,he,X),me(0,X,D,be),me(D,X,Q,be),me(D+Q,X,he,be),me(0,X+be,D,k),me(D,X+be,Q,k),me(D+Q,X+be,he,k),me(0,0,g,b),me(g,0,q,b),me(g+q,0,f,b),me(0,b,g,I),me(g,b,q,I),me(g+q,b,f,I),me(0,b+I,g,R),me(g,b+I,q,R),me(g+q,b+I,f,R)];for(let B=0;B<9;B++){let F=S[B],N=S[B+9];St(Object.assign(gt(this),{pos:N.pos(),tex:i.tex,quad:w.scale(F),flipX:this.flipX,flipY:this.flipY,tiled:s.tiled,width:N.w,height:N.h}))}}else St(Object.assign(gt(this),{tex:i.tex,quad:w.scale(this.quad??new ce(0,0,1,1)),flipX:this.flipX,flipY:this.flipY,tiled:s.tiled,width:this.width,height:this.height}))},add(){let w=o(f=>{let b=f.frames[0].clone();s.quad&&(b=b.scale(s.quad));let R=p(f.tex,b,s.width,s.height);this.width=f.tex.width*b.w*R.x,this.height=f.tex.height*b.h*R.y,s.anim&&this.play(s.anim),i=f,d.trigger(i)},"setSpriteData"),g=Ot(t);g?g.onLoad(w):Vn(()=>w(Ot(t).data))},update(){if(!a)return;let w=i.anims[a.name];if(typeof w=="number"){this.frame=w;return}if(w.speed===0)throw new Error("Sprite anim speed cannot be 0");a.timer+=Ke()*this.animSpeed,a.timer>=1/a.speed&&(a.timer=0,this.frame+=u,(this.frame<Math.min(w.from,w.to)||this.frame>Math.max(w.from,w.to))&&(a.loop?a.pingpong?(this.frame-=u,u*=-1,this.frame+=u):this.frame=w.from:a.pingpong?u===Math.sign(w.to-w.from)?(this.frame=w.to,u*=-1,this.frame+=u):(this.frame=w.from,a.onEnd(),this.stop()):(this.frame=w.to,a.onEnd(),this.stop())))},play(w,g={}){if(!i){d.add(()=>this.play(w,g));return}let f=i.anims[w];if(f===void 0)throw new Error(`Anim not found: ${w}`);a&&this.stop(),a=typeof f=="number"?{name:w,timer:0,loop:!1,pingpong:!1,speed:0,onEnd:()=>{}}:{name:w,timer:0,loop:g.loop??f.loop??!1,pingpong:g.pingpong??f.pingpong??!1,speed:g.speed??f.speed??10,onEnd:g.onEnd??(()=>{})},u=typeof f=="number"?null:f.from<f.to?1:-1,this.frame=typeof f=="number"?f:f.from,this.trigger("animStart",w)},stop(){if(!a)return;let w=a.name;a=null,this.trigger("animEnd",w)},numFrames(){return i?.frames.length??0},curAnim(){return a?.name},onAnimEnd(w){return this.on("animEnd",w)},onAnimStart(w){return this.on("animStart",w)},renderArea(){return new re(M(0),this.width,this.height)},inspect(){if(typeof t=="string")return`"${t}"`}}}o(Fn,"sprite");function Wr(t,s={}){function i(u){let d=mt(Object.assign(gt(u),{text:u.text+"",size:u.textSize,font:u.font,width:s.width&&u.width,align:u.align,letterSpacing:u.letterSpacing,lineSpacing:u.lineSpacing,transform:u.textTransform,styles:u.textStyles}));return s.width||(u.width=d.width/(u.scale?.x||1)),u.height=d.height/(u.scale?.y||1),d}o(i,"update");let a={id:"text",set text(u){t=u,i(this)},get text(){return t},textSize:s.size??To,font:s.font,width:s.width??0,height:0,align:s.align,lineSpacing:s.lineSpacing,letterSpacing:s.letterSpacing,textTransform:s.transform,textStyles:s.styles,add(){Vn(()=>i(this))},draw(){pt(i(this))},renderArea(){return new re(M(0),this.width,this.height)}};return i(a),a}o(Wr,"text");function Jr(t,s={}){if(t.length<3)throw new Error(`Polygon's need more than two points, ${t.length} points provided`);return{id:"polygon",pts:t,colors:s.colors,radius:s.radius,draw(){$e(Object.assign(gt(this),{pts:this.pts,colors:this.colors,radius:this.radius,fill:s.fill}))},renderArea(){return new Ee(this.pts)},inspect(){return this.pts.map(i=>`[${i.x},${i.y}]`).join(",")}}}o(Jr,"polygon");function Qr(t,s,i={}){return{id:"rect",width:t,height:s,radius:i.radius||0,draw(){l(Object.assign(gt(this),{width:this.width,height:this.height,radius:this.radius,fill:i.fill}))},renderArea(){return new re(M(0),this.width,this.height)},inspect(){return`${Math.ceil(this.width)}, ${Math.ceil(this.height)}`}}}o(Qr,"rect");function Zr(t,s){return{id:"rect",width:t,height:s,draw(){Je(Object.assign(gt(this),{width:this.width,height:this.height}))},renderArea(){return new re(M(0),this.width,this.height)},inspect(){return`${Math.ceil(this.width)}, ${Math.ceil(this.height)}`}}}o(Zr,"uvquad");function ei(t,s={}){return{id:"circle",radius:t,draw(){Ce(Object.assign(gt(this),{radius:this.radius,fill:s.fill}))},renderArea(){return new re(new x(this.anchor?0:-this.radius),this.radius*2,this.radius*2)},inspect(){return`${Math.ceil(this.radius)}`}}}o(ei,"circle");function ti(t=1,s=Z(0,0,0)){return{id:"outline",outline:{width:t,color:s}}}o(ti,"outline");function Ln(){return{id:"timer",wait(t,s){let i=[];s&&i.push(s);let a=0,u=this.onUpdate(()=>{a+=Ke(),a>=t&&(i.forEach(d=>d()),u.cancel())});return{get paused(){return u.paused},set paused(d){u.paused=d},cancel:u.cancel,onEnd(d){i.push(d)},then(d){return this.onEnd(d),this}}},loop(t,s){let i=null,a=o(()=>{i=this.wait(t,a),s()},"newAction");return i=this.wait(0,a),{get paused(){return i.paused},set paused(u){i.paused=u},cancel:()=>i.cancel()}},tween(t,s,i,a,u=qt.linear){let d=0,p=[],w=this.onUpdate(()=>{d+=Ke();let g=Math.min(d/i,1);a(Ze(t,s,u(g))),g===1&&(w.cancel(),a(s),p.forEach(f=>f()))});return{get paused(){return w.paused},set paused(g){w.paused=g},onEnd(g){p.push(g)},then(g){return this.onEnd(g),this},cancel(){w.cancel()},finish(){w.cancel(),a(s),p.forEach(g=>g())}}}}}o(Ln,"timer");let ni=640,si=65536;function ri(t={}){let s=null,i=null,a=!1;return{id:"body",require:["pos"],vel:new x(0),drag:t.drag??0,jumpForce:t.jumpForce??ni,gravityScale:t.gravityScale??1,isStatic:t.isStatic??!1,mass:t.mass??1,add(){if(this.mass===0)throw new Error("Can't set body mass to 0");this.is("area")&&(this.onCollideUpdate((u,d)=>{if(!u.is("body")||d.resolved)return;this.trigger("beforePhysicsResolve",d);let p=d.reverse();if(u.trigger("beforePhysicsResolve",p),!(d.resolved||p.resolved)&&!(this.isStatic&&u.isStatic)){if(!this.isStatic&&!u.isStatic){let w=this.mass+u.mass;this.pos=this.pos.add(d.displacement.scale(u.mass/w)),u.pos=u.pos.add(d.displacement.scale(-this.mass/w)),this.transform=en(this),u.transform=en(u)}else{let w=!this.isStatic&&u.isStatic?d:d.reverse();w.source.pos=w.source.pos.add(w.displacement),w.source.transform=en(w.source)}d.resolved=!0,this.trigger("physicsResolve",d),u.trigger("physicsResolve",d.reverse())}}),this.onPhysicsResolve(u=>{A.gravity&&(u.isBottom()&&this.isFalling()?(this.vel.y=0,s=u.target,i=u.target.pos,a?a=!1:this.trigger("ground",s)):u.isTop()&&this.isJumping()&&(this.vel.y=0,this.trigger("headbutt",u.target)))}))},update(){if(A.gravity&&!this.isStatic){if(a&&(s=null,i=null,this.trigger("fallOff"),a=!1),s)if(!this.isColliding(s)||!s.exists()||!s.is("body"))a=!0;else{!s.pos.eq(i)&&t.stickToPlatform!==!1&&this.moveBy(s.pos.sub(i)),i=s.pos;return}let u=this.vel.y;this.vel.y+=A.gravity*this.gravityScale*Ke(),this.vel.y=Math.min(this.vel.y,t.maxVelocity??si),u<0&&this.vel.y>=0&&this.trigger("fall")}this.vel.x*=1-this.drag,this.vel.y*=1-this.drag,this.move(this.vel)},onPhysicsResolve(u){return this.on("physicsResolve",u)},onBeforePhysicsResolve(u){return this.on("beforePhysicsResolve",u)},curPlatform(){return s},isGrounded(){return s!==null},isFalling(){return this.vel.y>0},isJumping(){return this.vel.y<0},jump(u){s=null,i=null,this.vel.y=-u||-this.jumpForce},onGround(u){return this.on("ground",u)},onFall(u){return this.on("fall",u)},onFallOff(u){return this.on("fallOff",u)},onHeadbutt(u){return this.on("headbutt",u)}}}o(ri,"body");function ii(t=2){let s=t;return{id:"doubleJump",require:["body"],numJumps:t,add(){this.onGround(()=>{s=this.numJumps})},doubleJump(i){s<=0||(s<this.numJumps&&this.trigger("doubleJump"),s--,this.jump(i))},onDoubleJump(i){return this.on("doubleJump",i)},inspect(){return`${s}`}}}o(ii,"doubleJump");function oi(t,s){return{id:"shader",shader:t,...typeof s=="function"?{uniform:s(),update(){this.uniform=s()}}:{uniform:s}}}o(oi,"shader");function ai(){return{id:"fixed",fixed:!0}}o(ai,"fixed");function Us(t){return{id:"stay",stay:!0,scenesToStay:t}}o(Us,"stay");function ui(t,s){if(t==null)throw new Error("health() requires the initial amount of hp");return{id:"health",hurt(i=1){this.setHP(t-i),this.trigger("hurt",i)},heal(i=1){let a=t;this.setHP(t+i),this.trigger("heal",t-a)},hp(){return t},maxHP(){return s??null},setMaxHP(i){s=i},setHP(i){t=s?Math.min(s,i):i,t<=0&&this.trigger("death")},onHurt(i){return this.on("hurt",i)},onHeal(i){return this.on("heal",i)},onDeath(i){return this.on("death",i)},inspect(){return`${t}`}}}o(ui,"health");function ci(t,s={}){if(t==null)throw new Error("lifespan() requires time");let i=s.fade??0;return{id:"lifespan",async add(){await As(t),i>0&&this.opacity&&await kn(this.opacity,0,i,a=>this.opacity=a,qt.linear),this.destroy()}}}o(ci,"lifespan");function hi(t,s,i){if(!t)throw new Error("state() requires an initial state");let a={};function u(g){a[g]||(a[g]={enter:new Ue,end:new Ue,update:new Ue,draw:new Ue})}o(u,"initStateEvents");function d(g,f,b){return u(f),a[f][g].add(b)}o(d,"on");function p(g,f,...b){u(f),a[f][g].trigger(...b)}o(p,"trigger");let w=!1;return{id:"state",state:t,enterState(g,...f){if(w=!0,s&&!s.includes(g))throw new Error(`State not found: ${g}`);let b=this.state;if(i){if(!i?.[b])return;let R=typeof i[b]=="string"?[i[b]]:i[b];if(!R.includes(g))throw new Error(`Cannot transition state from "${b}" to "${g}". Available transitions: ${R.map(G=>`"${G}"`).join(", ")}`)}p("end",b,...f),this.state=g,p("enter",g,...f),p("enter",`${b} -> ${g}`,...f)},onStateTransition(g,f,b){return d("enter",`${g} -> ${f}`,b)},onStateEnter(g,f){return d("enter",g,f)},onStateUpdate(g,f){return d("update",g,f)},onStateDraw(g,f){return d("draw",g,f)},onStateEnd(g,f){return d("end",g,f)},update(){w||(p("enter",t),w=!0),p("update",this.state)},draw(){p("draw",this.state)},inspect(){return this.state}}}o(hi,"state");function li(t=1){let s,i=0,a=!1;return{require:["opacity"],add(){s=this.opacity,this.opacity=0},update(){a||(i+=Ke(),this.opacity=et(i,0,t,0,s),i>=t&&(this.opacity=s,a=!0))}}}o(li,"fadeIn");function di(t="intersect"){return{id:"mask",mask:t}}o(di,"mask");function fi(t){return{add(){this.canvas=t}}}o(fi,"drawon");function Vn(t){L.loaded?t():A.events.on("load",t)}o(Vn,"onLoad");function mi(t,s){A.scenes[t]=s}o(mi,"scene");function pi(t,...s){if(!A.scenes[t])throw new Error(`Scene not found: ${t}`);A.events.onOnce("frameEnd",()=>{A.events.trigger("sceneLeave",t),v.events.clear(),A.events.clear(),A.objEvents.clear(),[...A.root.children].forEach(i=>{(!i.stay||i.scenesToStay&&!i.scenesToStay.includes(t))&&A.root.remove(i)}),A.root.clearEvents(),Ds(),A.cam={pos:null,scale:M(1),angle:0,shake:0,transform:new Ge},A.scenes[t](...s)})}o(pi,"go");function gi(t){return A.events.on("sceneLeave",t)}o(gi,"onSceneLeave");function wi(t,s){try{return JSON.parse(window.localStorage[t])}catch{return s?(Ss(t,s),s):null}}o(wi,"getData");function Ss(t,s){window.localStorage[t]=JSON.stringify(s)}o(Ss,"setData");function Ts(t,...s){let i=t(wt),a;typeof i=="function"?a=i(...s)(wt):a=i;for(let u in a)wt[u]=a[u],n.global!==!1&&(window[u]=a[u]);return wt}o(Ts,"plug");function rn(){return M(Ae()/2,De()/2)}o(rn,"center");let bi;(D=>(D[D.None=0]="None",D[D.Left=1]="Left",D[D.Top=2]="Top",D[D.LeftTop=3]="LeftTop",D[D.Right=4]="Right",D[D.Horizontal=5]="Horizontal",D[D.RightTop=6]="RightTop",D[D.HorizontalTop=7]="HorizontalTop",D[D.Bottom=8]="Bottom",D[D.LeftBottom=9]="LeftBottom",D[D.Vertical=10]="Vertical",D[D.LeftVertical=11]="LeftVertical",D[D.RightBottom=12]="RightBottom",D[D.HorizontalBottom=13]="HorizontalBottom",D[D.RightVertical=14]="RightVertical",D[D.All=15]="All"))(bi||={});function Cs(t={}){let s=M(0),i=t.isObstacle??!1,a=t.cost??0,u=t.edges??[],d=o(()=>{let w={left:1,top:2,right:4,bottom:8};return u.map(g=>w[g]||0).reduce((g,f)=>g|f,0)},"getEdgeMask"),p=d();return{id:"tile",tilePosOffset:t.offset??M(0),set tilePos(w){let g=this.getLevel();s=w.clone(),this.pos=M(this.tilePos.x*g.tileWidth(),this.tilePos.y*g.tileHeight()).add(this.tilePosOffset)},get tilePos(){return s},set isObstacle(w){i!==w&&(i=w,this.getLevel().invalidateNavigationMap())},get isObstacle(){return i},set cost(w){a!==w&&(a=w,this.getLevel().invalidateNavigationMap())},get cost(){return a},set edges(w){u=w,p=d(),this.getLevel().invalidateNavigationMap()},get edges(){return u},get edgeMask(){return p},getLevel(){return this.parent},moveLeft(){this.tilePos=this.tilePos.add(M(-1,0))},moveRight(){this.tilePos=this.tilePos.add(M(1,0))},moveUp(){this.tilePos=this.tilePos.add(M(0,-1))},moveDown(){this.tilePos=this.tilePos.add(M(0,1))}}}o(Cs,"tile");function vi(t,s){if(!s.tileWidth||!s.tileHeight)throw new Error("Must provide tileWidth and tileHeight.");let i=Ft([nn(s.pos??M(0))]),a=t.length,u=0,d=null,p=null,w=null,g=null,f=o(S=>S.x+S.y*u,"tile2Hash"),b=o(S=>M(Math.floor(S%u),Math.floor(S/u)),"hash2Tile"),R=o(()=>{d=[];for(let S of i.children)G(S)},"createSpatialMap"),G=o(S=>{let B=f(S.tilePos);d[B]?d[B].push(S):d[B]=[S]},"insertIntoSpatialMap"),Y=o(S=>{let B=f(S.tilePos);if(d[B]){let F=d[B].indexOf(S);F>=0&&d[B].splice(F,1)}},"removeFromSpatialMap"),q=o(()=>{let S=!1;for(let B of i.children){let F=i.pos2Tile(B.pos);(B.tilePos.x!=F.x||B.tilePos.y!=F.y)&&(S=!0,Y(B),B.tilePos.x=F.x,B.tilePos.y=F.y,G(B))}S&&i.trigger("spatial_map_changed")},"updateSpatialMap"),I=o(()=>{let S=i.getSpatialMap(),B=i.numRows()*i.numColumns();p?p.length=B:p=new Array(B),p.fill(1,0,B);for(let F=0;F<S.length;F++){let N=S[F];if(N){let W=0;for(let te of N)if(te.isObstacle){W=1/0;break}else W+=te.cost;p[F]=W||1}}},"createCostMap"),D=o(()=>{let S=i.getSpatialMap(),B=i.numRows()*i.numColumns();w?w.length=B:w=new Array(B),w.fill(15,0,B);for(let F=0;F<S.length;F++){let N=S[F];if(N){let W=N.length,te=15;for(let fe=0;fe<W;fe++)te|=N[fe].edgeMask;w[F]=te}}},"createEdgeMap"),he=o(()=>{let S=i.numRows()*i.numColumns(),B=o((N,W)=>{let te=[];for(te.push(N);te.length>0;){let fe=te.pop();k(fe).forEach(ve=>{g[ve]<0&&(g[ve]=W,te.push(ve))})}},"traverse");g?g.length=S:g=new Array(S),g.fill(-1,0,S);let F=0;for(let N=0;N<p.length;N++){if(g[N]>=0){F++;continue}B(N,F),F++}},"createConnectivityMap"),Q=o((S,B)=>p[B],"getCost"),X=o((S,B)=>{let F=b(S),N=b(B);return F.dist(N)},"getHeuristic"),k=o((S,B)=>{let F=[],N=Math.floor(S%u),W=N>0&&w[S]&1&&p[S-1]!==1/0,te=S>=u&&w[S]&2&&p[S-u]!==1/0,fe=N<u-1&&w[S]&4&&p[S+1]!==1/0,ve=S<u*a-u-1&&w[S]&8&&p[S+u]!==1/0;return B?(W&&(te&&F.push(S-u-1),F.push(S-1),ve&&F.push(S+u-1)),te&&F.push(S-u),fe&&(te&&F.push(S-u+1),F.push(S+1),ve&&F.push(S+u+1)),ve&&F.push(S+u)):(W&&F.push(S-1),te&&F.push(S-u),fe&&F.push(S+1),ve&&F.push(S+u)),F},"getNeighbours"),be={id:"level",tileWidth(){return s.tileWidth},tileHeight(){return s.tileHeight},spawn(S,...B){let F=M(...B),N=(()=>{if(typeof S=="string"){if(s.tiles[S]){if(typeof s.tiles[S]!="function")throw new Error("Level symbol def must be a function returning a component list");return s.tiles[S](F)}else if(s.wildcardTile)return s.wildcardTile(S,F)}else{if(Array.isArray(S))return S;throw new Error("Expected a symbol or a component list")}})();if(!N)return null;let W=!1,te=!1;for(let ve of N)ve.id==="tile"&&(te=!0),ve.id==="pos"&&(W=!0);W||N.push(nn()),te||N.push(Cs());let fe=i.add(N);return W&&(fe.tilePosOffset=fe.pos.clone()),fe.tilePos=F,d&&(G(fe),this.trigger("spatial_map_changed"),this.trigger("navigation_map_invalid")),fe},numColumns(){return u},numRows(){return a},levelWidth(){return u*this.tileWidth()},levelHeight(){return a*this.tileHeight()},tile2Pos(...S){return M(...S).scale(this.tileWidth(),this.tileHeight())},pos2Tile(...S){let B=M(...S);return M(Math.floor(B.x/this.tileWidth()),Math.floor(B.y/this.tileHeight()))},getSpatialMap(){return d||R(),d},onSpatialMapChanged(S){return this.on("spatial_map_changed",S)},onNavigationMapInvalid(S){return this.on("navigation_map_invalid",S)},getAt(S){d||R();let B=f(S);return d[B]||[]},update(){d&&q()},invalidateNavigationMap(){p=null,w=null,g=null},onNavigationMapChanged(S){return this.on("navigation_map_changed",S)},getTilePath(S,B,F={}){if(p||I(),w||D(),g||he(),S.x<0||S.x>=u||S.y<0||S.y>=a||B.x<0||B.x>=u||B.y<0||B.y>=a)return null;let N=f(S),W=f(B);if(p[W]===1/0)return null;if(N===W)return[];if(g[N]!=-1&&g[N]!==g[W])return null;let te=new dn((Qe,Hn)=>Qe.cost<Hn.cost);te.insert({cost:0,node:N});let fe=new Map;fe.set(N,N);let ve=new Map;for(ve.set(N,0);te.length!==0;){let Qe=te.remove()?.node;if(Qe===W)break;let Hn=k(Qe,F.allowDiagonals);for(let bt of Hn){let qn=(ve.get(Qe)||0)+Q(Qe,bt)+X(bt,W);(!ve.has(bt)||qn<ve.get(bt))&&(ve.set(bt,qn),te.insert({cost:qn,node:bt}),fe.set(bt,Qe))}}let jn=[],Lt=W,ki=b(Lt);for(jn.push(ki);Lt!==N;){Lt=fe.get(Lt);let Qe=b(Lt);jn.push(Qe)}return jn.reverse()},getPath(S,B,F={}){let N=this.tileWidth(),W=this.tileHeight(),te=this.getTilePath(this.pos2Tile(S),this.pos2Tile(B),F);return te?[S,...te.slice(1,-1).map(fe=>fe.scale(N,W).add(N/2,W/2)),B]:null}};return i.use(be),i.onNavigationMapInvalid(()=>{i.invalidateNavigationMap(),i.trigger("navigation_map_changed")}),t.forEach((S,B)=>{let F=S.split("");u=Math.max(F.length,u),F.forEach((N,W)=>{i.spawn(N,M(W,B))})}),i}o(vi,"addLevel");function yi(t={}){let s=null,i=null,a=null,u=null;return{id:"agent",require:["pos","tile"],agentSpeed:t.speed??100,allowDiagonals:t.allowDiagonals??!0,getDistanceToTarget(){return s?this.pos.dist(s):0},getNextLocation(){return i&&a?i[a]:null},getPath(){return i?i.slice():null},getTarget(){return s},isNavigationFinished(){return i?a===null:!0},isTargetReachable(){return i!==null},isTargetReached(){return s?this.pos.eq(s):!0},setTarget(d){s=d,i=this.getLevel().getPath(this.pos,s,{allowDiagonals:this.allowDiagonals}),a=i?0:null,i?(u||(u=this.getLevel().onNavigationMapChanged(()=>{i&&a!==null&&(i=this.getLevel().getPath(this.pos,s,{allowDiagonals:this.allowDiagonals}),a=i?0:null,i?this.trigger("navigation-next",this,i[a]):this.trigger("navigation-ended",this))}),this.onDestroy(()=>u.cancel())),this.trigger("navigation-started",this),this.trigger("navigation-next",this,i[a])):this.trigger("navigation-ended",this)},update(){if(i&&a!==null){if(this.pos.sdist(i[a])<2)if(a===i.length-1){this.pos=s.clone(),a=null,this.trigger("navigation-ended",this),this.trigger("target-reached",this);return}else a++,this.trigger("navigation-next",this,i[a]);this.moveTo(i[a],this.agentSpeed)}},onNavigationStarted(d){return this.on("navigation-started",d)},onNavigationNext(d){return this.on("navigation-next",d)},onNavigationEnded(d){return this.on("navigation-ended",d)},onTargetReached(d){return this.on("target-reached",d)},inspect(){return JSON.stringify({target:JSON.stringify(s),path:JSON.stringify(i)})}}}o(yi,"agent");function xi(t){let s=v.canvas.captureStream(t),i=$.ctx.createMediaStreamDestination();$.masterNode.connect(i);let a=new MediaRecorder(s),u=[];return a.ondataavailable=d=>{d.data.size>0&&u.push(d.data)},a.onerror=()=>{$.masterNode.disconnect(i),s.getTracks().forEach(d=>d.stop())},a.start(),{resume(){a.resume()},pause(){a.pause()},stop(){return a.stop(),$.masterNode.disconnect(i),s.getTracks().forEach(d=>d.stop()),new Promise(d=>{a.onstop=()=>{d(new Blob(u,{type:"video/mp4"}))}})},download(d="kaboom.mp4"){this.stop().then(p=>ns(d,p))}}}o(xi,"record");function Ei(){return document.activeElement===v.canvas}o(Ei,"isFocused");function Ui(t){t.destroy()}o(Ui,"destroy");let Ft=A.root.add.bind(A.root),Si=A.root.readd.bind(A.root),Ti=A.root.removeAll.bind(A.root),Nn=A.root.get.bind(A.root),As=A.root.wait.bind(A.root),Ci=A.root.loop.bind(A.root),kn=A.root.tween.bind(A.root);function Ms(t=2,s=1){let i=0;return{require:["scale"],update(){let a=Math.sin(i*t)*s;a<0&&this.destroy(),this.scale=M(a),i+=Ke()}}}o(Ms,"boom");let Ai=ye(null,lr),Mi=ye(null,dr);function Ri(t,s={}){let i=Ft([nn(t),Us()]),a=(s.speed||1)*5,u=s.scale||1;i.add([Fn(Mi),sn(0),Bn("center"),Ms(a,u),...s.comps??[]]);let d=i.add([Fn(Ai),sn(0),Bn("center"),Ln(),...s.comps??[]]);return d.wait(.4/a,()=>d.use(Ms(a,u))),d.onDestroy(()=>i.destroy()),i}o(Ri,"addKaboom");function Rs(){A.root.update()}o(Rs,"updateFrame");class _n{static{o(this,"Collision")}source;target;displacement;resolved=!1;constructor(s,i,a,u=!1){this.source=s,this.target=i,this.displacement=a,this.resolved=u}reverse(){return new _n(this.target,this.source,this.displacement.scale(-1),this.resolved)}hasOverlap(){return!this.displacement.isZero()}isLeft(){return this.displacement.x>0}isRight(){return this.displacement.x<0}isTop(){return this.displacement.y>0}isBottom(){return this.displacement.y<0}preventResolution(){this.resolved=!0}}function Oi(){let t={},s=n.hashGridSize||Co,i=new Ge,a=[];function u(d){if(a.push(i.clone()),d.pos&&i.translate(d.pos),d.scale&&i.scale(d.scale),d.angle&&i.rotate(d.angle),d.transform=i.clone(),d.c("area")&&!d.paused){let p=d,g=p.worldArea().bbox(),f=Math.floor(g.pos.x/s),b=Math.floor(g.pos.y/s),R=Math.ceil((g.pos.x+g.width)/s),G=Math.ceil((g.pos.y+g.height)/s),Y=new Set;for(let q=f;q<=R;q++)for(let I=b;I<=G;I++)if(!t[q])t[q]={},t[q][I]=[p];else if(!t[q][I])t[q][I]=[p];else{let D=t[q][I];e:for(let he of D){if(he.paused||!he.exists()||Y.has(he.id))continue;for(let X of p.collisionIgnore)if(he.is(X))continue e;for(let X of he.collisionIgnore)if(p.is(X))continue e;let Q=Ks(p.worldArea(),he.worldArea());if(Q){let X=new _n(p,he,Q);p.trigger("collideUpdate",he,X);let k=X.reverse();k.resolved=X.resolved,he.trigger("collideUpdate",p,k)}Y.add(he.id)}D.push(p)}}d.children.forEach(u),i=a.pop()}o(u,"checkObj"),u(A.root)}o(Oi,"checkFrame");function Pi(){let t=A.cam,s=x.fromAngle(Nt(0,360)).scale(t.shake);t.shake=Ze(t.shake,0,5*Ke()),t.transform=new Ge().translate(rn()).scale(t.scale).rotate(t.angle).translate((t.pos??rn()).scale(-1).add(s)),A.root.draw(),Pe()}o(Pi,"drawFrame");function Di(){let t=j();A.events.numListeners("loading")>0?A.events.trigger("loading",t):ut(()=>{let s=Ae()/2,i=24,a=M(Ae()/2,De()/2).sub(M(s/2,i/2));l({pos:M(0),width:Ae(),height:De(),color:Z(0,0,0)}),l({pos:a,width:s,height:i,fill:!1,outline:{width:4}}),l({pos:a,width:s*t,height:i})})}o(Di,"drawLoadScreen");function Os(t,s){ut(()=>{let i=M(8);pe(),oe(t);let a=mt({text:s,font:yn,size:16,pos:i,color:Z(255,255,255),fixed:!0}),u=a.width+i.x*2,d=a.height+i.x*2;t.x+u>=Ae()&&oe(M(-u,0)),t.y+d>=De()&&oe(M(0,-d)),l({width:u,height:d,color:Z(0,0,0),radius:4,opacity:.8,fixed:!0}),pt(a),xe()})}o(Os,"drawInspectText");function Gi(){if(se.inspect){let t=null;for(let s of A.root.get("*",{recursive:!0}))if(s.c("area")&&s.isHovering()){t=s;break}if(A.root.drawInspect(),t){let s=[],i=t.inspect();for(let a in i)i[a]?s.push(`${a}: ${i[a]}`):s.push(`${a}`);Os(Ur(Zt()),s.join(`
|
|
54
|
+
`))}Os(M(8),`FPS: ${se.fps()}`)}se.paused&&ut(()=>{pe(),oe(Ae(),0),oe(-8,8);let t=32;l({width:t,height:t,anchor:"topright",color:Z(0,0,0),opacity:.8,radius:4,fixed:!0});for(let s=1;s<=2;s++)l({width:4,height:t*.6,anchor:"center",pos:M(-t/3*s,t*.5),color:Z(255,255,255),radius:2,fixed:!0});xe()}),se.timeScale!==1&&ut(()=>{pe(),oe(Ae(),De()),oe(-8,-8);let t=8,s=mt({text:se.timeScale.toFixed(1),font:yn,size:16,color:Z(255,255,255),pos:M(-t),anchor:"botright",fixed:!0});l({width:s.width+t*2+t*4,height:s.height+t*2,anchor:"botright",color:Z(0,0,0),opacity:.8,radius:4,fixed:!0});for(let i=0;i<2;i++){let a=se.timeScale<1;ee({p1:M(-s.width-t*(a?2:3.5),-t),p2:M(-s.width-t*(a?2:3.5),-t-s.height),p3:M(-s.width-t*(a?3.5:2),-t-s.height/2),pos:M(-i*t*1+(a?-t*.5:0),0),color:Z(255,255,255),fixed:!0})}pt(s),xe()}),se.curRecording&&ut(()=>{pe(),oe(0,De()),oe(24,-24),Ce({radius:12,color:Z(255,0,0),opacity:Yn(0,1,v.time()*4),fixed:!0}),xe()}),se.showLog&&A.logs.length>0&&ut(()=>{pe(),oe(0,De()),oe(8,-8);let t=8,s=[];for(let a of A.logs){let u="",d=a.msg instanceof Error?"error":"info";u+=`[time]${a.time.toFixed(2)}[/time]`,u+=" ",u+=`[${d}]${a.msg?.toString?a.msg.toString():a.msg}[/${d}]`,s.push(u)}A.logs=A.logs.filter(a=>v.time()-a.time<(n.logTime||Mo));let i=mt({text:s.join(`
|
|
55
|
+
`),font:yn,pos:M(t,-t),anchor:"botleft",size:16,width:Ae()*.6,lineSpacing:t/2,fixed:!0,styles:{time:{color:Z(127,127,127)},info:{color:Z(255,255,255)},error:{color:Z(255,0,127)}}});l({width:i.width+t*2,height:i.height+t*2,anchor:"botleft",color:Z(0,0,0),radius:4,opacity:.8,fixed:!0}),pt(i),xe()})}o(Gi,"drawDebug");function Ii(t){A.events.on("loading",t)}o(Ii,"onLoading");function Bi(t){v.onResize(t)}o(Bi,"onResize");function Fi(t){A.events.on("error",t)}o(Fi,"onError");function Li(t){console.error(t),$.ctx.suspend(),v.run(()=>{Ut(),ut(()=>{let a=Ae(),u=De(),d={size:36,width:a-32*2,letterSpacing:4,lineSpacing:4,font:yn,fixed:!0};l({width:a,height:u,color:Z(0,0,255),fixed:!0});let p=mt({...d,text:"Error",pos:M(32),color:Z(255,128,0),fixed:!0});pt(p),bs({...d,text:t.message,pos:M(32,32+p.height+16),fixed:!0}),xe(),A.events.trigger("error",t)}),Gt()})}o(Li,"handleErr");function Vi(t){z.push(t)}o(Vi,"onCleanup");function Ni(){A.events.onOnce("frameEnd",()=>{v.quit(),T.clear(T.COLOR_BUFFER_BIT|T.DEPTH_BUFFER_BIT|T.STENCIL_BUFFER_BIT);let t=T.getParameter(T.MAX_TEXTURE_IMAGE_UNITS);for(let s=0;s<t;s++)T.activeTexture(T.TEXTURE0+s),T.bindTexture(T.TEXTURE_2D,null),T.bindTexture(T.TEXTURE_CUBE_MAP,null);T.bindBuffer(T.ARRAY_BUFFER,null),T.bindBuffer(T.ELEMENT_ARRAY_BUFFER,null),T.bindRenderbuffer(T.RENDERBUFFER,null),T.bindFramebuffer(T.FRAMEBUFFER,null),V.destroy(),z.forEach(s=>s())})}o(Ni,"quit");let on=!0;v.run(()=>{try{L.loaded||j()===1&&!on&&(L.loaded=!0,A.events.trigger("load")),!L.loaded&&n.loadingScreen!==!1||on?(Ut(),Di(),Gt()):(se.paused||Rs(),Oi(),Ut(),Pi(),n.debug!==!1&&Gi(),Gt()),on&&(on=!1),A.events.trigger("frameEnd")}catch(t){Li(t)}});function Ps(){let t=y,s=T.drawingBufferWidth/t,i=T.drawingBufferHeight/t;if(n.letterbox){if(!n.width||!n.height)throw new Error("Letterboxing requires width and height defined.");let a=s/i,u=n.width/n.height;if(a>u){let d=i*u,p=(s-d)/2;U.viewport={x:p,y:0,width:d,height:i}}else{let d=s/u,p=(i-d)/2;U.viewport={x:0,y:p,width:s,height:d}}return}if(n.stretch&&(!n.width||!n.height))throw new Error("Stretching requires width and height defined.");U.viewport={x:0,y:0,width:s,height:i}}o(Ps,"updateViewport");function Ds(){v.onHide(()=>{n.backgroundAudio||$.ctx.suspend()}),v.onShow(()=>{!n.backgroundAudio&&!se.paused&&$.ctx.resume()}),v.onResize(()=>{if(v.isFullscreen())return;let t=n.width&&n.height;t&&!n.stretch&&!n.letterbox||(r.width=r.offsetWidth*y,r.height=r.offsetHeight*y,Ps(),t||(U.frameBuffer.free(),U.frameBuffer=new xt(V,T.drawingBufferWidth,T.drawingBufferHeight),U.width=T.drawingBufferWidth/y/c,U.height=T.drawingBufferHeight/y/c))}),n.debug!==!1&&(v.onKeyPress("f1",()=>se.inspect=!se.inspect),v.onKeyPress("f2",()=>se.clearLog()),v.onKeyPress("f8",()=>se.paused=!se.paused),v.onKeyPress("f7",()=>{se.timeScale=It(We(se.timeScale-.2,0,2),1)}),v.onKeyPress("f9",()=>{se.timeScale=It(We(se.timeScale+.2,0,2),1)}),v.onKeyPress("f10",()=>se.stepFrame())),n.burp&&v.onKeyPress("b",()=>Wt())}o(Ds,"initEvents"),Ps(),Ds();let wt={VERSION:Uo,loadRoot:de,loadProgress:j,loadSprite:ye,loadSpriteAtlas:Le,loadSound:Te,loadMusic:Oe,loadBitmapFont:Ne,loadFont:Se,loadShader:je,loadShaderURL:ft,loadAseprite:_e,loadPedit:ke,loadBean:ze,loadJSON:ie,load:le,getSprite:rt,getSound:it,getFont:Et,getBitmapFont:Yt,getShader:$t,getAsset:Un,Asset:Re,SpriteData:_,SoundData:K,width:Ae,height:De,center:rn,dt:Ke,time:v.time,screenshot:v.screenshot,record:xi,isFocused:Ei,setCursor:v.setCursor,getCursor:v.getCursor,setCursorLocked:v.setCursorLocked,isCursorLocked:v.isCursorLocked,setFullscreen:v.setFullscreen,isFullscreen:v.isFullscreen,isTouchscreen:v.isTouchscreen,onLoad:Vn,onLoading:Ii,onResize:Bi,onGamepadConnect:v.onGamepadConnect,onGamepadDisconnect:v.onGamepadDisconnect,onError:Fi,onCleanup:Vi,camPos:Sr,camScale:Tr,camRot:Cr,shake:Ar,toScreen:ys,toWorld:xs,setGravity:Lr,getGravity:Vr,setBackground:Nr,getBackground:kr,getGamepads:v.getGamepads,add:Ft,make:Gn,destroy:Ui,destroyAll:Ti,get:Nn,readd:Si,pos:nn,scale:sn,rotate:_r,color:jr,opacity:Hr,anchor:Bn,area:Kr,sprite:Fn,text:Wr,polygon:Jr,rect:Qr,circle:ei,uvquad:Zr,outline:ti,body:ri,doubleJump:ii,shader:oi,timer:Ln,fixed:ai,stay:Us,health:ui,lifespan:ci,z:qr,move:Yr,offscreen:Xr,follow:zr,state:hi,fadeIn:li,mask:di,drawon:fi,tile:Cs,agent:yi,on:ct,onUpdate:Mr,onDraw:Rr,onAdd:In,onDestroy:Es,onClick:Gr,onCollide:Or,onCollideUpdate:Pr,onCollideEnd:Dr,onHover:Ir,onHoverUpdate:Br,onHoverEnd:Fr,onKeyDown:v.onKeyDown,onKeyPress:v.onKeyPress,onKeyPressRepeat:v.onKeyPressRepeat,onKeyRelease:v.onKeyRelease,onMouseDown:v.onMouseDown,onMousePress:v.onMousePress,onMouseRelease:v.onMouseRelease,onMouseMove:v.onMouseMove,onCharInput:v.onCharInput,onTouchStart:v.onTouchStart,onTouchMove:v.onTouchMove,onTouchEnd:v.onTouchEnd,onScroll:v.onScroll,onHide:v.onHide,onShow:v.onShow,onGamepadButtonDown:v.onGamepadButtonDown,onGamepadButtonPress:v.onGamepadButtonPress,onGamepadButtonRelease:v.onGamepadButtonRelease,onGamepadStick:v.onGamepadStick,mousePos:Zt,mouseDeltaPos:v.mouseDeltaPos,isKeyDown:v.isKeyDown,isKeyPressed:v.isKeyPressed,isKeyPressedRepeat:v.isKeyPressedRepeat,isKeyReleased:v.isKeyReleased,isMouseDown:v.isMouseDown,isMousePressed:v.isMousePressed,isMouseReleased:v.isMouseReleased,isMouseMoved:v.isMouseMoved,isGamepadButtonPressed:v.isGamepadButtonPressed,isGamepadButtonDown:v.isGamepadButtonDown,isGamepadButtonReleased:v.isGamepadButtonReleased,getGamepadStick:v.getGamepadStick,charInputted:v.charInputted,loop:Ci,wait:As,play:Kt,volume:Cn,burp:Wt,audioCtx:$.ctx,Line:Ie,Rect:re,Circle:Me,Ellipse:Ye,Polygon:Ee,Vec2:x,Color:J,Mat4:Ge,Quad:ce,RNG:Vt,rand:Nt,randi:$n,randSeed:Ls,vec2:M,rgb:Z,hsl2rgb:Fs,quad:me,choose:ks,chooseMultiple:Ns,shuffle:Xn,chance:Vs,lerp:Ze,tween:kn,easings:qt,map:et,mapc:Bs,wave:Yn,deg2rad:we,rad2deg:lt,clamp:We,evaluateBezier:es,testLineLine:cn,testRectRect:Kn,testRectLine:hn,testRectPoint:ln,testCirclePolygon:kt,testLinePoint:Wn,testLineCircle:At,drawSprite:Qt,drawText:bs,formatText:mt,drawRect:l,drawLine:E,drawLines:P,drawTriangle:ee,drawCircle:Ce,drawEllipse:at,drawUVQuad:Je,drawPolygon:$e,drawCurve:H,drawBezier:ge,drawFormattedText:pt,drawMasked:Tt,drawSubtracted:ms,pushTransform:pe,popTransform:xe,pushTranslate:oe,pushScale:ue,pushRotate:He,pushMatrix:Pn,usePostEffect:On,makeCanvas:Mn,debug:se,scene:mi,go:pi,onSceneLeave:gi,addLevel:vi,getData:wi,setData:Ss,download:mn,downloadJSON:Qs,downloadText:ts,downloadBlob:ns,plug:Ts,ASCII_CHARS:fr,canvas:v.canvas,addKaboom:Ri,LEFT:x.LEFT,RIGHT:x.RIGHT,UP:x.UP,DOWN:x.DOWN,RED:J.RED,GREEN:J.GREEN,BLUE:J.BLUE,YELLOW:J.YELLOW,MAGENTA:J.MAGENTA,CYAN:J.CYAN,WHITE:J.WHITE,BLACK:J.BLACK,quit:Ni,Event:Ue,EventHandler:nt,EventController:tt};if(n.plugins&&n.plugins.forEach(Ts),n.global!==!1)for(let t in wt)window[t]=wt[t];return n.focus!==!1&&v.canvas.focus(),wt},"default");
|
|
56
|
+
//# sourceMappingURL=kaboom.cjs.map
|