Skip to content

Instantly share code, notes, and snippets.

@blurymind
Last active September 13, 2024 19:28
Show Gist options
  • Save blurymind/2ff124dc94f936e8f7d96632f559aecb to your computer and use it in GitHub Desktop.
Save blurymind/2ff124dc94f936e8f7d96632f559aecb to your computer and use it in GitHub Desktop.
upload data from api
"use strict";var kaplay=(()=>{var bn=Object.defineProperty;var Ha=Object.getOwnPropertyDescriptor;var qa=Object.getOwnPropertyNames;var za=Object.prototype.hasOwnProperty;var i=(t,e)=>bn(t,"name",{value:e,configurable:!0});var Ya=(t,e)=>{for(var n in e)bn(t,n,{get:e[n],enumerable:!0})},Wa=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qa(e))!za.call(t,o)&&o!==n&&bn(t,o,{get:()=>e[o],enumerable:!(r=Ha(e,o))||r.enumerable});return t};var $a=t=>Wa(bn({},"__esModule",{value:!0}),t);var ao=(()=>{for(var t=new Uint8Array(128),e=0;e<64;e++)t[e<26?e+65:e<52?e+71:e<62?e-4:e*4-205]=e;return n=>{for(var r=n.length,o=new Uint8Array((r-(n[r-1]=="=")-(n[r-2]=="="))*3/4|0),s=0,a=0;s<r;){var l=t[n.charCodeAt(s++)],u=t[n.charCodeAt(s++)],m=t[n.charCodeAt(s++)],c=t[n.charCodeAt(s++)];o[a++]=l<<2|u>>4,o[a++]=u<<4|m>>2,o[a++]=m<<6|c}return o}})();var Yu={};Ya(Yu,{default:()=>zu});var H=class t{static{i(this,"Color")}r=255;g=255;b=255;constructor(e,n,r){this.r=Be(e,0,255),this.g=Be(n,0,255),this.b=Be(r,0,255)}static fromArray(e){return new t(e[0],e[1],e[2])}static fromHex(e){if(typeof e=="number")return new t(e>>16&255,e>>8&255,e>>0&255);if(typeof e=="string"){let n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(!n)throw new Error("Invalid hex color format");return new t(parseInt(n[1],16),parseInt(n[2],16),parseInt(n[3],16))}else throw new Error("Invalid hex color format")}static fromHSL(e,n,r){if(n==0)return new t(255*r,255*r,255*r);let o=i((c,p,d)=>(d<0&&(d+=1),d>1&&(d-=1),d<1/6?c+(p-c)*6*d:d<1/2?p:d<2/3?c+(p-c)*(2/3-d)*6:c),"hue2rgb"),s=r<.5?r*(1+n):r+n-r*n,a=2*r-s,l=o(a,s,e+1/3),u=o(a,s,e),m=o(a,s,e-1/3);return new t(Math.round(l*255),Math.round(u*255),Math.round(m*255))}static RED=new t(255,0,0);static GREEN=new t(0,255,0);static BLUE=new t(0,0,255);static YELLOW=new t(255,255,0);static MAGENTA=new t(255,0,255);static CYAN=new t(0,255,255);static WHITE=new t(255,255,255);static BLACK=new t(0,0,0);clone(){return new t(this.r,this.g,this.b)}lighten(e){return new t(this.r+e,this.g+e,this.b+e)}darken(e){return this.lighten(-e)}invert(){return new t(255-this.r,255-this.g,255-this.b)}mult(e){return new t(this.r*e.r/255,this.g*e.g/255,this.b*e.b/255)}lerp(e,n){return new t(Ee(this.r,e.r,n),Ee(this.g,e.g,n),Ee(this.b,e.b,n))}toHSL(){let e=this.r/255,n=this.g/255,r=this.b/255,o=Math.max(e,n,r),s=Math.min(e,n,r),a=(o+s)/2,l=a,u=a;if(o==s)a=l=0;else{let m=o-s;switch(l=u>.5?m/(2-o-s):m/(o+s),o){case e:a=(n-r)/m+(n<r?6:0);break;case n:a=(r-e)/m+2;break;case r:a=(e-n)/m+4;break}a/=6}return[a,l,u]}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)}toArray(){return[this.r,this.g,this.b]}};function W(...t){if(t.length===0)return new H(255,255,255);if(t.length===1){if(t[0]instanceof H)return t[0].clone();if(typeof t[0]=="string")return H.fromHex(t[0]);if(Array.isArray(t[0])&&t[0].length===3)return H.fromArray(t[0])}else if(t.length===2){if(t[0]instanceof H)return t[0].clone()}else if(t.length===3||t.length===4)return new H(t[0],t[1],t[2]);throw new Error("Invalid color arguments")}i(W,"rgb");var uo=i((t,e,n)=>H.fromHSL(t,e,n),"hsl2rgb");function ce(t){return t*Math.PI/180}i(ce,"deg2rad");function pt(t){return t*180/Math.PI}i(pt,"rad2deg");function Be(t,e,n){return e>n?Be(t,n,e):Math.min(Math.max(t,e),n)}i(Be,"clamp");function Ee(t,e,n){if(typeof t=="number"&&typeof e=="number")return t+(e-t)*n;if(t instanceof w&&e instanceof w)return t.lerp(e,n);if(t instanceof H&&e instanceof H)return t.lerp(e,n);throw new Error(`Bad value for lerp(): ${t}, ${e}. Only number, Vec2 and Color is supported.`)}i(Ee,"lerp");function De(t,e,n,r,o){return r+(t-e)/(n-e)*(o-r)}i(De,"map");function lo(t,e,n,r,o){return Be(De(t,e,n,r,o),r,o)}i(lo,"mapc");var w=class t{static{i(this,"Vec2")}x=0;y=0;constructor(e=0,n=e){this.x=e,this.y=n}static fromAngle(e){let n=ce(e);return new t(Math.cos(n),Math.sin(n))}static fromArray(e){return new t(e[0],e[1])}static LEFT=new t(-1,0);static RIGHT=new t(1,0);static UP=new t(0,-1);static DOWN=new t(0,1);clone(){return new t(this.x,this.y)}add(...e){let n=b(...e);return new t(this.x+n.x,this.y+n.y)}sub(...e){let n=b(...e);return new t(this.x-n.x,this.y-n.y)}scale(...e){let n=b(...e);return new t(this.x*n.x,this.y*n.y)}dist(...e){let n=b(...e);return this.sub(n).len()}sdist(...e){let n=b(...e);return this.sub(n).slen()}len(){return Math.sqrt(this.dot(this))}slen(){return this.dot(this)}unit(){let e=this.len();return e===0?new t(0):this.scale(1/e)}normal(){return new t(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 n=b(...e);return pt(Math.atan2(this.y-n.y,this.x-n.x))}angleBetween(...e){let n=b(...e);return pt(Math.atan2(this.cross(n),this.dot(n)))}lerp(e,n){return new t(Ee(this.x,e.x,n),Ee(this.y,e.y,n))}slerp(e,n){let r=this.dot(e),o=this.cross(e),s=Math.atan2(o,r);return this.scale(Math.sin((1-n)*s)).add(e.scale(Math.sin(n*s))).scale(1/o)}isZero(){return this.x===0&&this.y===0}toFixed(e){return new t(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 ee(this,0,0)}toString(){return`vec2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`}toArray(){return[this.x,this.y]}};function b(...t){if(t.length===1){if(t[0]instanceof w)return new w(t[0].x,t[0].y);if(Array.isArray(t[0])&&t[0].length===2)return new w(...t[0])}return new w(...t)}i(b,"vec2");var $=class t{static{i(this,"Quad")}x=0;y=0;w=1;h=1;constructor(e,n,r,o){this.x=e,this.y=n,this.w=r,this.h=o}scale(e){return new t(this.x+this.w*e.x,this.y+this.h*e.y,this.w*e.w,this.h*e.h)}pos(){return new w(this.x,this.y)}clone(){return new t(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 pe(t,e,n,r){return new $(t,e,n,r)}i(pe,"quad");var Dt=class t{static{i(this,"Mat2")}a;b;c;d;constructor(e,n,r,o){this.a=e,this.b=n,this.c=r,this.d=o}mul(e){return new t(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 b(this.a*e.x+this.b*e.y,this.c*e.x+this.d*e.y)}get inverse(){let e=this.det;return new t(this.d/e,-this.b/e,-this.c/e,this.a/e)}get transpose(){return new t(this.a,this.c,this.b,this.d)}get eigenvalues(){let e=this.trace/2,n=this.det,r=e+Math.sqrt(e*e-n),o=e-Math.sqrt(e*e-n);return[r,o]}eigenvectors(e,n){return this.c!=0?[[e-this.d,this.c],[n-this.d,this.c]]:this.b!=0?[[this.b,e-this.a],[this.b,n-this.a]]:Math.abs(this.transform(b(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 n=Math.cos(e),r=Math.sin(e);return new t(n,r,-r,n)}static scale(e,n){return new t(e,0,0,n)}};var yt=class t{static{i(this,"Mat3")}m11;m12;m13;m21;m22;m23;m31;m32;m33;constructor(e,n,r,o,s,a,l,u,m){this.m11=e,this.m12=n,this.m13=r,this.m21=o,this.m22=s,this.m23=a,this.m31=l,this.m32=u,this.m33=m}static fromMat2(e){return new t(e.a,e.b,0,e.c,e.d,0,0,0,1)}toMat2(){return new Dt(this.m11,this.m12,this.m21,this.m22)}mul(e){return new t(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}rotate(e){let n=Math.cos(e),r=Math.sin(e),o=this.m11,s=this.m12;return this.m11=n*this.m11+r*this.m21,this.m12=n*this.m12+r*this.m22,this.m21=n*this.m21-r*o,this.m22=n*this.m22-r*s,this}scale(e,n){return this.m11*=e,this.m12*=e,this.m21*=n,this.m22*=n,this}get inverse(){let e=this.det;return new t((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 t(this.m11,this.m21,this.m31,this.m12,this.m22,this.m32,this.m13,this.m23,this.m33)}},ge=class t{static{i(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 t([1,0,0,0,0,1,0,0,0,0,1,0,e.x,e.y,0,1])}static scale(e){return new t([e.x,0,0,0,0,e.y,0,0,0,0,1,0,0,0,0,1])}static rotateX(e){e=ce(-e);let n=Math.cos(e),r=Math.sin(e);return new t([1,0,0,0,0,n,-r,0,0,r,n,0,0,0,0,1])}static rotateY(e){e=ce(-e);let n=Math.cos(e),r=Math.sin(e);return new t([n,0,r,0,0,1,0,0,-r,0,n,0,0,0,0,1])}static rotateZ(e){e=ce(-e);let n=Math.cos(e),r=Math.sin(e);return new t([n,-r,0,0,r,n,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=ce(-e);let n=Math.cos(e),r=Math.sin(e),o=this.m[0],s=this.m[1],a=this.m[4],l=this.m[5];return this.m[0]=o*n+s*r,this.m[1]=-o*r+s*n,this.m[4]=a*n+l*r,this.m[5]=-a*r+l*n,this}mult(e){let n=[];for(let r=0;r<4;r++)for(let o=0;o<4;o++)n[r*4+o]=this.m[0*4+o]*e.m[r*4+0]+this.m[1*4+o]*e.m[r*4+1]+this.m[2*4+o]*e.m[r*4+2]+this.m[3*4+o]*e.m[r*4+3];return new t(n)}multVec2(e){return new w(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 w(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],n=Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]);return new w(n,e/n)}else if(this.m[4]!=0||this.m[5]!=0){let e=this.m[0]*this.m[5]-this.m[1]*this.m[4],n=Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]);return new w(e/n,n)}else return new w(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 pt(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 pt(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 w(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 w(0,Math.atan(this.m[0]*this.m[4]+this.m[1]*this.m[5])/(e*e))}else return new w(0,0)}invert(){let e=[],n=this.m[10]*this.m[15]-this.m[14]*this.m[11],r=this.m[9]*this.m[15]-this.m[13]*this.m[11],o=this.m[9]*this.m[14]-this.m[13]*this.m[10],s=this.m[8]*this.m[15]-this.m[12]*this.m[11],a=this.m[8]*this.m[14]-this.m[12]*this.m[10],l=this.m[8]*this.m[13]-this.m[12]*this.m[9],u=this.m[6]*this.m[15]-this.m[14]*this.m[7],m=this.m[5]*this.m[15]-this.m[13]*this.m[7],c=this.m[5]*this.m[14]-this.m[13]*this.m[6],p=this.m[4]*this.m[15]-this.m[12]*this.m[7],d=this.m[4]*this.m[14]-this.m[12]*this.m[6],x=this.m[5]*this.m[15]-this.m[13]*this.m[7],f=this.m[4]*this.m[13]-this.m[12]*this.m[5],y=this.m[6]*this.m[11]-this.m[10]*this.m[7],v=this.m[5]*this.m[11]-this.m[9]*this.m[7],A=this.m[5]*this.m[10]-this.m[9]*this.m[6],V=this.m[4]*this.m[11]-this.m[8]*this.m[7],M=this.m[4]*this.m[10]-this.m[8]*this.m[6],G=this.m[4]*this.m[9]-this.m[8]*this.m[5];e[0]=this.m[5]*n-this.m[6]*r+this.m[7]*o,e[4]=-(this.m[4]*n-this.m[6]*s+this.m[7]*a),e[8]=this.m[4]*r-this.m[5]*s+this.m[7]*l,e[12]=-(this.m[4]*o-this.m[5]*a+this.m[6]*l),e[1]=-(this.m[1]*n-this.m[2]*r+this.m[3]*o),e[5]=this.m[0]*n-this.m[2]*s+this.m[3]*a,e[9]=-(this.m[0]*r-this.m[1]*s+this.m[3]*l),e[13]=this.m[0]*o-this.m[1]*a+this.m[2]*l,e[2]=this.m[1]*u-this.m[2]*m+this.m[3]*c,e[6]=-(this.m[0]*u-this.m[2]*p+this.m[3]*d),e[10]=this.m[0]*x-this.m[1]*p+this.m[3]*f,e[14]=-(this.m[0]*c-this.m[1]*d+this.m[2]*f),e[3]=-(this.m[1]*y-this.m[2]*v+this.m[3]*A),e[7]=this.m[0]*y-this.m[2]*V+this.m[3]*M,e[11]=-(this.m[0]*v-this.m[1]*V+this.m[3]*G),e[15]=this.m[0]*A-this.m[1]*M+this.m[2]*G;let F=this.m[0]*e[0]+this.m[1]*e[4]+this.m[2]*e[8]+this.m[3]*e[12];for(let g=0;g<4;g++)for(let T=0;T<4;T++)e[g*4+T]*=1/F;return new t(e)}clone(){return new t([...this.m])}toString(){return this.m.toString()}};function vn(t,e,n,r=o=>-Math.cos(o)){return t+(r(n)+1)/2*(e-t)}i(vn,"wave");var Xa=1103515245,Qa=12345,co=2147483648,Wt=class{static{i(this,"RNG")}seed;constructor(e){this.seed=e}gen(){return this.seed=(Xa*this.seed+Qa)%co,this.seed/co}genNumber(e,n){return e+this.gen()*(n-e)}genVec2(e,n){return new w(this.genNumber(e.x,n.x),this.genNumber(e.y,n.y))}genColor(e,n){return new H(this.genNumber(e.r,n.r),this.genNumber(e.g,n.g),this.genNumber(e.b,n.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 w)return this.genVec2(b(0,0),e[0]);if(e[0]instanceof H)return this.genColor(W(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 w&&e[1]instanceof w)return this.genVec2(e[0],e[1]);if(e[0]instanceof H&&e[1]instanceof H)return this.genColor(e[0],e[1])}throw new Error("More than 2 arguments not supported")}},mr=new Wt(Date.now());function mo(t){return t!=null&&(mr.seed=t),mr.seed}i(mo,"randSeed");function be(...t){return mr.genAny(...t)}i(be,"rand");function pr(...t){return Math.floor(be(...t))}i(pr,"randi");function po(t){return be()<=t}i(po,"chance");function dr(t){for(let e=t.length-1;e>0;e--){let n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t}i(dr,"shuffle");function ho(t,e){return t.length<=e?t.slice():dr(t.slice()).slice(0,e)}i(ho,"chooseMultiple");function fo(t){return t[pr(t.length)]}i(fo,"choose");function hr(t,e){return t.pos.x+t.width>e.pos.x&&t.pos.x<e.pos.x+e.width&&t.pos.y+t.height>e.pos.y&&t.pos.y<e.pos.y+e.height}i(hr,"testRectRect");function Ja(t,e){if(t.p1.x===t.p2.x&&t.p1.y===t.p2.y||e.p1.x===e.p2.x&&e.p1.y===e.p2.y)return null;let n=(e.p2.y-e.p1.y)*(t.p2.x-t.p1.x)-(e.p2.x-e.p1.x)*(t.p2.y-t.p1.y);if(n===0)return null;let r=((e.p2.x-e.p1.x)*(t.p1.y-e.p1.y)-(e.p2.y-e.p1.y)*(t.p1.x-e.p1.x))/n,o=((t.p2.x-t.p1.x)*(t.p1.y-e.p1.y)-(t.p2.y-t.p1.y)*(t.p1.x-e.p1.x))/n;return r<0||r>1||o<0||o>1?null:r}i(Ja,"testLineLineT");function wn(t,e){let n=Ja(t,e);return n?b(t.p1.x+n*(t.p2.x-t.p1.x),t.p1.y+n*(t.p2.y-t.p1.y)):null}i(wn,"testLineLine");function Cn(t,e){let n=e.p2.sub(e.p1),r=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY;if(n.x!=0){let s=(t.pos.x-e.p1.x)/n.x,a=(t.pos.x+t.width-e.p1.x)/n.x;r=Math.max(r,Math.min(s,a)),o=Math.min(o,Math.max(s,a))}if(n.y!=0){let s=(t.pos.y-e.p1.y)/n.y,a=(t.pos.y+t.height-e.p1.y)/n.y;r=Math.max(r,Math.min(s,a)),o=Math.min(o,Math.max(s,a))}return o>=r&&o>=0&&r<=1}i(Cn,"testRectLine");function En(t,e){return e.x>t.pos.x&&e.x<t.pos.x+t.width&&e.y>t.pos.y&&e.y<t.pos.y+t.height}i(En,"testRectPoint");function go(t,e){let n=Math.max(t.pos.x,Math.min(e.center.x,t.pos.x+t.width)),r=Math.max(t.pos.y,Math.min(e.center.y,t.pos.y+t.height));return b(n,r).sdist(e.center)<=e.radius*e.radius}i(go,"testRectCircle");function bo(t,e){return yo(e,new Se(t.points()))}i(bo,"testRectPolygon");function Tn(t,e){let n=e.sub(t.p1),r=t.p2.sub(t.p1);if(Math.abs(n.cross(r))>Number.EPSILON)return!1;let o=n.dot(r)/r.dot(r);return o>=0&&o<=1}i(Tn,"testLinePoint");function Mt(t,e){let n=t.p2.sub(t.p1),r=n.dot(n),o=t.p1.sub(e.center),s=2*n.dot(o),a=o.dot(o)-e.radius*e.radius,l=s*s-4*r*a;if(r<=Number.EPSILON||l<0)return!1;if(l==0){let u=-s/(2*r);if(u>=0&&u<=1)return!0}else{let u=(-s+Math.sqrt(l))/(2*r),m=(-s-Math.sqrt(l))/(2*r);if(u>=0&&u<=1||m>=0&&m<=1)return!0}return On(e,t.p1)}i(Mt,"testLineCircle");function fr(t,e){if(rt(e,t.p1)||rt(e,t.p2))return!0;for(let n=0;n<e.pts.length;n++){let r=e.pts[n],o=e.pts[(n+1)%e.pts.length];if(wn(t,new Ae(r,o)))return!0}return!1}i(fr,"testLinePolygon");function On(t,e){return t.center.sdist(e)<t.radius*t.radius}i(On,"testCirclePoint");function Za(t,e){return t.center.sdist(e.center)<(t.radius+e.radius)*(t.radius+e.radius)}i(Za,"testCircleCircle");function $t(t,e){let n=e.pts[e.pts.length-1];for(let r of e.pts){if(Mt(new Ae(n,r),t))return!0;n=r}return On(t,e.pts[0])?!0:rt(e,t.center)}i($t,"testCirclePolygon");function yo(t,e){for(let n=0;n<t.pts.length;n++)if(fr(new Ae(t.pts[n],t.pts[(n+1)%t.pts.length]),e))return!0;return!!(t.pts.some(n=>rt(e,n))||e.pts.some(n=>rt(t,n)))}i(yo,"testPolygonPolygon");function rt(t,e){let n=!1,r=t.pts;for(let o=0,s=r.length-1;o<r.length;s=o++)r[o].y>e.y!=r[s].y>e.y&&e.x<(r[s].x-r[o].x)*(e.y-r[o].y)/(r[s].y-r[o].y)+r[o].x&&(n=!n);return n}i(rt,"testPolygonPoint");function gr(t,e){e=e.sub(t.center);let n=ce(t.angle),r=Math.cos(n),o=Math.sin(n),s=e.x*r+e.y*o,a=-e.x*o+e.y*r;return s*s/(t.radiusX*t.radiusX)+a*a/(t.radiusY*t.radiusY)<1}i(gr,"testEllipsePoint");function yn(t,e){let n=e.center.sub(t.center),r=ce(t.angle),o=Math.cos(r),s=Math.sin(r),a=n.x*o+n.y*s,l=-n.x*s+n.y*o;return gr(new _e(b(),t.radiusX+e.radius,t.radiusY+e.radius,0),b(a,l))}i(yn,"testEllipseCircle");function xo(t,e){let n=t.toMat2().inverse;return e=new Ae(n.transform(e.p1.sub(t.center)),n.transform(e.p2.sub(t.center))),Mt(e,new Ge(b(),1))}i(xo,"testEllipseLine");function eu(t,e){if(t.radiusX===t.radiusY)return yn(e,new Ge(t.center,t.radiusX));if(e.radiusX===e.radiusY)return yn(t,new Ge(e.center,e.radiusX));let n=new yt(1/t.radiusX**2,0,0,0,1/t.radiusY**2,0,0,0,-1),r=new yt(1/e.radiusX**2,0,0,0,1/e.radiusY**2,0,0,0,-1),o=t.center.x,s=t.center.y,a=e.center.x,l=e.center.y,u=ce(t.angle),m=ce(e.angle),c=new yt(Math.cos(u),-Math.sin(u),o,Math.sin(u),Math.cos(u),s,0,0,1),p=new yt(Math.cos(m),-Math.sin(m),a,Math.sin(m),Math.cos(m),l,0,0,1),d=c.inverse,x=p.inverse,f=d.transpose.mul(n).mul(d),y=x.transpose.mul(r).mul(x),v=f.m11,A=f.m12,V=f.m13,M=f.m21,G=f.m22,F=f.m23,g=f.m31,T=f.m32,S=f.m33,D=y.m11,B=y.m12,K=y.m13,k=y.m21,z=y.m22,X=y.m23,te=y.m31,Q=y.m32,q=y.m33,ae=v*G*S-v*F*T-A*M*S+A*F*g+V*M*T-V*G*g,U=(v*G*q-v*F*Q-v*T*X+v*S*z-A*M*q+A*F*te+A*g*X-A*S*k+V*M*Q-V*G*te-V*g*z+V*T*k+M*T*K-M*S*B-G*g*K+G*S*D+F*g*B-F*T*D)/ae,I=(v*z*q-v*X*Q-A*k*q+A*X*te+V*k*Q-V*z*te-M*B*q+M*K*Q+G*D*q-G*K*te-F*D*Q+F*B*te+g*B*X-g*K*z-T*D*X+T*K*k+S*D*z-S*B*k)/ae,Y=(D*z*q-D*X*Q-B*k*q+B*X*te+K*k*Q-K*z*te)/ae;if(U>=0){let j=-3*I+U**2,ue=3*U*Y+I*U**2-4*I**2,Z=-27*Y**2+18*Y*U*I+U**2*I**2-4*U**3*Y-4*I**3;return!(j>0&&ue<0&&Z>0)}else{let j=-3*I+U**2,ue=-27*Y**2+18*Y*U*I+U**2*I**2-4*U**3*Y-4*I**3;return!(j>0&&ue>0)}}i(eu,"testEllipseEllipse");function vo(t,e){return br(t,new Se(e.points()))}i(vo,"testEllipseRect");function br(t,e){let n=t.toMat2().inverse;return e=new Se(e.pts.map(r=>n.transform(r.sub(t.center)))),$t(new Ge(b(),1),e)}i(br,"testEllipsePolygon");function tu(t,e){return t.x===e.x&&t.y===e.y}i(tu,"testPointPoint");function nu(t,e){return e instanceof w?tu(e,t.pt):e instanceof Ge?On(e,t.pt):e instanceof Ae?Tn(e,t.pt):e instanceof ee?En(e,t.pt):e instanceof Se?rt(e,t.pt):e instanceof _e?gr(e,t.pt):!1}i(nu,"testPointShape");function ru(t,e){return e instanceof w?Tn(t,e):e instanceof Ge?Mt(t,e):e instanceof Ae?wn(t,e)!=null:e instanceof ee?Cn(e,t):e instanceof Se?fr(t,e):e instanceof _e?xo(e,t):!1}i(ru,"testLineShape");function ou(t,e){return e instanceof w?On(t,e):e instanceof Ge?Za(t,e):e instanceof Ae?Mt(e,t):e instanceof ee?go(e,t):e instanceof Se?$t(t,e):e instanceof _e?yn(e,t):!1}i(ou,"testCircleShape");function iu(t,e){return e instanceof w?En(t,e):e instanceof Ge?go(t,e):e instanceof Ae?Cn(t,e):e instanceof ee?hr(t,e):e instanceof Se?bo(t,e):e instanceof _e?vo(e,t):!1}i(iu,"testRectShape");function su(t,e){return e instanceof w?rt(t,e):e instanceof Ge?$t(e,t):e instanceof Ae?fr(e,t):e instanceof ee?bo(e,t):e instanceof Se?yo(e,t):e instanceof _e?br(e,t):!1}i(su,"testPolygonShape");function au(t,e){return e instanceof w?gr(t,e):e instanceof Ge?yn(t,e):e instanceof Ae?xo(t,e):e instanceof ee?vo(t,e):e instanceof Se?br(t,e):e instanceof _e?eu(e,t):!1}i(au,"testEllipseShape");function wo(t,e,n){let r=t,o=n.p1,s=n.p2,a=e,l=s.sub(o),u=a.cross(l);if(Math.abs(u)<Number.EPSILON)return null;let m=o.sub(r),c=m.cross(l)/u;if(c<=0||c>=1)return null;let p=m.cross(a)/u;if(p<=0||p>=1)return null;let d=l.normal().unit();return e.dot(d)>0&&(d.x*=-1,d.y*=-1),{point:r.add(a.scale(c)),normal:d,fraction:c}}i(wo,"raycastLine");function uu(t,e,n){let r=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,s;if(t.x!=0){let a=(n.pos.x-t.x)/e.x,l=(n.pos.x+n.width-t.x)/e.x;s=b(-Math.sign(e.x),0),r=Math.max(r,Math.min(a,l)),o=Math.min(o,Math.max(a,l))}if(t.y!=0){let a=(n.pos.y-t.y)/e.y,l=(n.pos.y+n.height-t.y)/e.y;Math.min(a,l)>r&&(s=b(0,-Math.sign(e.y))),r=Math.max(r,Math.min(a,l)),o=Math.min(o,Math.max(a,l))}return o>=r&&r>=0&&r<=1?{point:t.add(e.scale(r)),normal:s,fraction:r}:null}i(uu,"raycastRect");function Co(t,e,n){let r=t,o=n.center,s=e,a=s.dot(s),l=r.sub(o),u=2*s.dot(l),m=l.dot(l)-n.radius*n.radius,c=u*u-4*a*m;if(a<=Number.EPSILON||c<0)return null;if(c==0){let p=-u/(2*a);if(p>=0&&p<=1){let d=r.add(s.scale(p));return{point:d,normal:d.sub(o),fraction:p}}}else{let p=(-u+Math.sqrt(c))/(2*a),d=(-u-Math.sqrt(c))/(2*a),x=null;if(p>=0&&p<=1&&(x=p),d>=0&&d<=1&&(x=Math.min(d,x??d)),x!=null){let f=r.add(s.scale(x));return{point:f,normal:f.sub(o).unit(),fraction:x}}}return null}i(Co,"raycastCircle");function cu(t,e,n){let r=n.pts,o=null,s=r[r.length-1];for(let a=0;a<r.length;a++){let l=r[a],u=wo(t,e,new Ae(s,l));u&&(!o||o.fraction>u.fraction)&&(o=u),s=l}return o}i(cu,"raycastPolygon");function lu(t,e,n){let r=n.toMat2(),o=r.inverse,s=o.transform(t.sub(n.center)),a=o.transform(e),l=Co(s,a,new Ge(b(),1));if(l){let u=Dt.rotation(ce(-n.angle)),c=Dt.scale(n.radiusX,n.radiusY).transform(l.point),p=r.transform(l.point).add(n.center),d=p.dist(t)/e.len();return{point:p,normal:u.transform(b(n.radiusY**2*c.x,n.radiusX**2*c.y)).unit(),fraction:d}}return l}i(lu,"raycastEllipse");function Eo(t,e,n,r=64){let o=t,s=e.len(),a=e.scale(1/s),l=0,u=b(Math.floor(t.x),Math.floor(t.y)),m=b(a.x>0?1:-1,a.y>0?1:-1),c=b(Math.abs(1/a.x),Math.abs(1/a.y)),p=b(m.x>0?u.x+1-t.x:t.x-u.x,m.y>0?u.y+1-t.y:t.y-u.y),d=b(c.x<1/0?c.x*p.x:1/0,c.y<1/0?c.y*p.y:1/0),x=-1;for(;l<=r;){let f=n(u);if(f===!0)return{point:o.add(a.scale(l)),normal:b(x===0?-m.x:0,x===1?-m.y:0),fraction:l/s,gridPos:u};if(f)return f;d.x<d.y?(u.x+=m.x,l=d.x,d.x+=c.x,x=0):(u.y+=m.y,l=d.y,d.y+=c.y,x=1)}return null}i(Eo,"raycastGrid");var xn=class t{static{i(this,"Point")}pt;constructor(e){this.pt=e.clone()}transform(e){return new t(e.multVec2(this.pt))}bbox(){return new ee(this.pt,0,0)}area(){return 0}clone(){return new t(this.pt)}collides(e){return nu(this,e)}contains(e){return this.pt.eq(e)}raycast(e,n){return null}random(){return this.pt.clone()}},Ae=class t{static{i(this,"Line")}p1;p2;constructor(e,n){this.p1=e.clone(),this.p2=n.clone()}transform(e){return new t(e.multVec2(this.p1),e.multVec2(this.p2))}bbox(){return ee.fromPoints(this.p1,this.p2)}area(){return this.p1.dist(this.p2)}clone(){return new t(this.p1,this.p2)}collides(e){return ru(this,e)}contains(e){return this.collides(e)}raycast(e,n){return wo(e,n,this)}random(){return this.p1.add(this.p2.sub(this.p1).scale(be(1)))}},ee=class t{static{i(this,"Rect")}pos;width;height;constructor(e,n,r){this.pos=e.clone(),this.width=n,this.height=r}static fromPoints(e,n){return new t(e.clone(),n.x-e.x,n.y-e.y)}center(){return new w(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 Se(this.points().map(n=>e.multVec2(n)))}bbox(){return this.clone()}area(){return this.width*this.height}clone(){return new t(this.pos.clone(),this.width,this.height)}distToPoint(e){return Math.sqrt(this.sdistToPoint(e))}sdistToPoint(e){let n=this.pos,r=this.pos.add(this.width,this.height),o=Math.max(n.x-e.x,0,e.x-r.x),s=Math.max(n.y-e.y,0,e.y-r.y);return o*o+s*s}collides(e){return iu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return uu(e,n,this)}random(){return this.pos.add(be(this.width),be(this.height))}},Ge=class t{static{i(this,"Circle")}center;radius;constructor(e,n){this.center=e.clone(),this.radius=n}transform(e){return new _e(this.center,this.radius,this.radius).transform(e)}bbox(){return ee.fromPoints(this.center.sub(b(this.radius)),this.center.add(b(this.radius)))}area(){return this.radius*this.radius*Math.PI}clone(){return new t(this.center,this.radius)}collides(e){return ou(this,e)}contains(e){return this.collides(e)}raycast(e,n){return Co(e,n,this)}random(){return this.center.add(w.fromAngle(be(360)).scale(be(this.radius)))}},_e=class t{static{i(this,"Ellipse")}center;radiusX;radiusY;angle;constructor(e,n,r,o=0){this.center=e.clone(),this.radiusX=n,this.radiusY=r,this.angle=o}static fromMat2(e){let n=e.inverse,r=n.transpose.mul(n),[o,s]=r.eigenvalues,[a,l]=r.eigenvectors(o,s),[u,m]=[1/Math.sqrt(o),1/Math.sqrt(s)];return u>m?new t(b(),u,m,pt(Math.atan2(-a[1],a[0]))):new t(b(),m,u,pt(Math.atan2(-l[1],l[0])))}toMat2(){let e=ce(this.angle),n=Math.cos(e),r=Math.sin(e);return new Dt(n*this.radiusX,-r*this.radiusY,r*this.radiusX,n*this.radiusY)}transform(e){if(this.angle==0&&e.getRotation()==0)return new t(e.multVec2(this.center),e.m[0]*this.radiusX,e.m[5]*this.radiusY);{let n=this.toMat2(),r=e.getRotation(),o=e.getScale();n=yt.fromMat2(n).scale(o.x,o.y).rotate(r).toMat2();let a=t.fromMat2(n);return a.center=e.multVec2(this.center),a}}bbox(){if(this.angle==0)return ee.fromPoints(this.center.sub(b(this.radiusX,this.radiusY)),this.center.add(b(this.radiusX,this.radiusY)));{let e=ce(this.angle),n=Math.cos(e),r=Math.sin(e),o=this.radiusX*n,s=this.radiusX*r,a=this.radiusY*r,l=this.radiusY*n,u=Math.sqrt(o*o+a*a),m=Math.sqrt(s*s+l*l);return ee.fromPoints(this.center.sub(b(u,m)),this.center.add(b(u,m)))}}area(){return this.radiusX*this.radiusY*Math.PI}clone(){return new t(this.center,this.radiusX,this.radiusY,this.angle)}collides(e){return au(this,e)}contains(e){e=e.sub(this.center);let n=ce(this.angle),r=Math.cos(n),o=Math.sin(n),s=e.x*r+e.y*o,a=-e.x*o+e.y*r;return s*s/(this.radiusX*this.radiusX)+a*a/(this.radiusY*this.radiusY)<1}raycast(e,n){return lu(e,n,this)}random(){return this.center}};function mu(t,e,n,r){let o=e.sub(t),s=r.sub(n),a=o.cross(s);return a<1e-5&&a>-1e-5||(a=n.sub(t).cross(s)/a,a<0||a>1)?null:t.add(o.scale(a))}i(mu,"segmentLineIntersection");var Se=class t{static{i(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 t(this.pts.map(n=>e.multVec2(n)))}bbox(){let e=b(Number.MAX_VALUE),n=b(-Number.MAX_VALUE);for(let r of this.pts)e.x=Math.min(e.x,r.x),n.x=Math.max(n.x,r.x),e.y=Math.min(e.y,r.y),n.y=Math.max(n.y,r.y);return ee.fromPoints(e,n)}area(){let e=0,n=this.pts.length;for(let r=0;r<n;r++){let o=this.pts[r],s=this.pts[(r+1)%n];e+=o.x*s.y*.5,e-=s.x*o.y*.5}return Math.abs(e)}clone(){return new t(this.pts.map(e=>e.clone()))}collides(e){return su(this,e)}contains(e){return this.collides(e)}raycast(e,n){return cu(e,n,this)}random(){return b()}cut(e,n){let r=new Ae(e,n),o=[],s=[],a=n.sub(e),l=this.pts[this.pts.length-1],u=l.sub(e),m=a.cross(u)>0;return this.pts.forEach(c=>{u=c.sub(e);let p=a.cross(u)>0;if(m!=p){let d=mu(l,c,e,n);o.push(d),s.push(d),m=p}(p?o:s).push(c),l=c}),[o.length?new t(o):null,s.length?new t(s):null]}};function To(t,e,n,r){let o=r*r,s=1-r,a=s*s;return t.scale(a).add(e.scale(2*s*r)).add(n.scale(o))}i(To,"evaluateQuadratic");function Oo(t,e,n,r){let o=1-r;return e.sub(t).scale(2*o).add(n.sub(e).scale(2*r))}i(Oo,"evaluateQuadraticFirstDerivative");function Ao(t,e,n,r){return n.sub(e.scale(2)).add(t).scale(2)}i(Ao,"evaluateQuadraticSecondDerivative");function Xt(t,e,n,r,o){let s=o*o,a=s*o,l=1-o,u=l*l,m=u*l;return t.scale(m).add(e.scale(3*u*o)).add(n.scale(3*l*s)).add(r.scale(a))}i(Xt,"evaluateBezier");function So(t,e,n,r,o){let s=o*o,a=1-o,l=a*a;return e.sub(t).scale(3*l).add(n.sub(e).scale(6*a*o)).add(r.sub(n).scale(3*s))}i(So,"evaluateBezierFirstDerivative");function Vo(t,e,n,r,o){let s=1-o;return n.sub(e.scale(2)).add(t).scale(6*s).add(r.sub(n.scale(2)).add(e).scale(6*o))}i(Vo,"evaluateBezierSecondDerivative");function Po(t,e,n,r,o){let s=.5*(((-o+2)*o-1)*o),a=.5*((3*o-5)*o*o+2),l=.5*(((-3*o+4)*o+1)*o),u=.5*((o-1)*o*o);return t.scale(s).add(e.scale(a)).add(n.scale(l)).add(r.scale(u))}i(Po,"evaluateCatmullRom");function Ro(t,e,n,r,o){let s=.5*((-3*o+4)*o-1),a=.5*((9*o-10)*o),l=.5*((-9*o+8)*o+1),u=.5*((3*o-2)*o);return t.scale(s).add(e.scale(a)).add(n.scale(l)).add(r.scale(u))}i(Ro,"evaluateCatmullRomFirstDerivative");function Go(t){let e=yr(t),n=e(1);return r=>{let o=r*n,s=e(o,!0);return t(s)}}i(Go,"normalizedCurve");function yr(t,e=10,n=10){let r=[0],o=[0],a=1/(e-1)/n,l=0,u=t(0),m=0;for(let c=1;c<e;c++){for(let p=0;p<n;p++){m+=a;let d=t(m),x=d.dist(u);l+=x,u=d}r[c]=l,o[c]=m}return o[e-1]=1,(c,p=!1)=>{if(p){let d=c;if(d<=0)return 0;if(d>=l)return 1;let x=0;for(;r[x+1]<d;)x++;let f=o[x],y=o[x+1],v=r[x],A=r[x+1],V=(d-v)/(A-v);return f+(y-f)*V}else{if(c<=0)return 0;if(c>=1)return r[e-1];let d=0;for(;o[d+1]<c;)d++;let x=o[d],f=o[d+1],y=r[d],v=r[d+1],A=(c-x)/(f-x);return y+(v-y)*A}}}i(yr,"curveLengthApproximation");function Ut(t,e,n,r){let o=2*t+e-2*r+n,s=-3*t+3*r-2*e-n,a=e,l=t;return u=>{let m=u*u,c=m*u;return o*c+s*m+a*u+l}}i(Ut,"hermite");function xr(t,e,n,r,o,s=Ut){let a=s(e.x,(1-o)*(n.x-t.x),(1-o)*(r.x-e.x),n.x),l=s(e.y,(1-o)*(n.y-t.y),(1-o)*(r.y-e.y),n.y);return u=>new w(a(u),l(u))}i(xr,"cardinal");function Bt(t,e,n,r,o=Ut){return xr(t,e,n,r,.5,o)}i(Bt,"catmullRom");function Do(t,e,n,r,o=Ut){return Bt(r.add(t.sub(e).scale(6)),t,r,t.add(r.sub(n).scale(6)),o)}i(Do,"bezier");function Mo(t,e,n,r,o,s,a,l=Ut){let u=l(e.x,.5*(1-o)*(1+a)*(1+s)*(e.x-t.x)+.5*(1-o)*(1-a)*(1-s)*(n.x-e.x),.5*(1-o)*(1+a)*(1-s)*(n.x-e.x)+.5*(1-o)*(1-a)*(1+s)*(r.x-n.x),n.x),m=l(e.y,.5*(1-o)*(1+a)*(1+s)*(e.y-t.y)+.5*(1-o)*(1-a)*(1-s)*(n.y-e.y),.5*(1-o)*(1+a)*(1-s)*(n.y-e.y)+.5*(1-o)*(1-a)*(1+s)*(r.y-n.y),n.y);return c=>new w(u(c),m(c))}i(Mo,"kochanekBartels");function Uo(t,e,n,r){let o=2*t+e-2*r+n,s=-3*t+3*r-2*e+n,a=e;return l=>{let u=l*l;return 3*o*u+2*s*l+a}}i(Uo,"hermiteFirstDerivative");function zt(t){return 0<=t&&t<=1}i(zt,"inZeroOneDomain");function cr(t,e){return Math.abs(t-e)<=Number.EPSILON}i(cr,"approximately");function Yt(t){return t<0?-Math.pow(-t,1/3):Math.pow(t,1/3)}i(Yt,"cubeRoot");function pu(t,e,n,r){let o=3*t-6*e+3*n,s=-3*t+3*e,a=t,l=-t+3*e-3*n+r;if(cr(l,0)){if(cr(o,0))return cr(s,0)?[]:[-a/s].filter(zt);let A=Math.sqrt(s*s-4*o*a),V=2*o;return[(A-s)/V,(-s-A)/V].filter(zt)}o/=l,s/=l,a/=l;let u=(3*s-o*o)/3,m=u/3,c=(2*o*o*o-9*o*s+27*a)/27,p=c/2,d=p*p+m*m*m;if(d<0){let A=-u/3,V=A*A*A,M=Math.sqrt(V),G=-c/(2*M),F=G<-1?-1:G>1?1:G,g=Math.acos(F),S=2*Yt(M),D=S*Math.cos(g/3)-o/3,B=S*Math.cos((g+2*Math.PI)/3)-o/3,K=S*Math.cos((g+4*Math.PI)/3)-o/3;return[D,B,K].filter(zt)}if(d===0){let A=p<0?Yt(-p):-Yt(p),V=2*A-o/3,M=-A-o/3;return[V,M].filter(zt)}let x=Math.sqrt(d),f=Yt(x-p),y=Yt(x+p);return[f-y-o/3].filter(zt)}i(pu,"getCubicRoots");function du(t,e,n,r,o){let s=pu(t.x-o,e.x-o,n.x-o,r.x-o);return s.length>0?Xt(t,e,n,r,s[0]).y:NaN}i(du,"cubicBezierYforX");function Bo(t){if(!t||t.length==0)throw new Error("Need at least one point for easingLinear.");let e=t.length;return n=>{if(n<=0||t.length==1||n<=t[0].x)return t[0].y;for(let r=0;r<e;r++)if(t[r].x>=n)return De(n,t[r-1].x,t[r].x,t[r-1].y,t[r].y);return t[t.length-1].y}}i(Bo,"easingLinear");function Fo(t,e){return n=>du(b(0,0),t,e,b(1,1),n)}i(Fo,"easingCubicBezier");function Lo(t,e="jump-end"){let n=1/t,r=e=="jump-start"||e=="jump-both",o=e=="jump-end"||e=="jump-both",s=1/(t+(o?1:0)),a=r?s:0;return l=>{let u=Math.floor(l/n);return a+u*s}}i(Lo,"easingSteps");function Io(t,e){let n=Number.MAX_VALUE,r={normal:b(0),distance:0};for(let o of[t,e])for(let s=0;s<o.pts.length;s++){let a=o.pts[s],u=o.pts[(s+1)%o.pts.length].sub(a).normal().unit(),m=Number.MAX_VALUE,c=-Number.MAX_VALUE;for(let f=0;f<t.pts.length;f++){let y=t.pts[f].dot(u);m=Math.min(m,y),c=Math.max(c,y)}let p=Number.MAX_VALUE,d=-Number.MAX_VALUE;for(let f=0;f<e.pts.length;f++){let y=e.pts[f].dot(u);p=Math.min(p,y),d=Math.max(d,y)}let x=Math.min(c,d)-Math.max(m,p);if(x<0)return null;if(x<Math.abs(n)){let f=d-m,y=p-c;n=Math.abs(f)<Math.abs(y)?f:y,r.normal=u,r.distance=n}}return r}i(Io,"sat");function jo(t,e,n){return(e.x-t.x)*(n.y-t.y)-(e.y-t.y)*(n.x-t.x)>=0}i(jo,"isOrientedCcw");function hu(t){let e=0,n=t[t.length-1];for(let r=0;r<t.length;r++)e+=(t[r].x-n.x)*(t[r].y+n.y),n=t[r];return e<0}i(hu,"isOrientedCcwPolygon");function lr(t,e,n,r){let o=r.x-n.x,s=r.y-n.y,a=o*(t.y-n.y)-s*(t.x-n.x),l=o*(e.y-n.y)-s*(e.x-n.x);return a*l>=0}i(lr,"onSameSide");function fu(t,e,n,r){return lr(t,e,n,r)&&lr(t,n,e,r)&&lr(t,r,e,n)}i(fu,"pointInTriangle");function gu(t,e,n,r){for(let o of t)if(o!==e&&o!==n&&o!==r&&fu(o,e,n,r))return!0;return!1}i(gu,"someInTriangle");function bu(t,e,n,r){return jo(t,e,n)&&!gu(r,t,e,n)}i(bu,"isEar");function An(t){if(t.length<3)return[];if(t.length==3)return[t];let e=[],n=[],r=0;for(let p=0;p<t.length;p++){let d=t[r],x=t[p];(x.x<d.x||x.x==d.x&&x.y<d.y)&&(r=r),e[p]=p+1,n[p]=p-1}e[e.length-1]=0,n[0]=n.length-1,hu(t)||([e,n]=[n,e]);let o=[];for(let p=0;p<t.length;++p)jo(t[n[p]],t[p],t[e[p]])||o.push(t[p]);let s=[],a=t.length,l=1,u=0,m,c;for(;a>3;){m=e[l],c=n[l];let p=t[c],d=t[l],x=t[m];if(bu(p,d,x,o))s.push([p,d,x]),e[c]=m,n[m]=c,o.splice(o.indexOf(d),1),--a,u=0;else if(++u>a)return[];l=m}return m=e[l],c=n[l],s.push([t[c],t[l],t[m]]),s}i(An,"triangulate");function Ko(t){if(t.length<3)return!1;let e=t.length-2,n=t.length-1,r=0,o=t[n].sub(t[e]),s=t[r].sub(t[n]),a=o.cross(s);for(;r+1<t.length;)if(e=n,n=r,r++,o=t[n].sub(t[e]),s=t[r].sub(t[n]),o.cross(s)*a<0)return!1;return!0}i(Ko,"isConvex");var ko=i(t=>t[0]instanceof H,"arrayIsColor"),_o=i(t=>t[0]instanceof w,"arrayIsVec2"),No=i(t=>typeof t[0]=="number","arrayIsNumber");function Ho(t){return t?.prototype&&Object.getOwnPropertyDescriptor(t.prototype,"constructor")!==void 0}i(Ho,"isClass");var Ft=class{static{i(this,"BinaryHeap")}_items;_compareFn;constructor(e=(n,r)=>n<r){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],n=this._items.pop();return this._items.length!==0&&(this._items[0]=n,this.moveDown(0)),e}clear(){this._items.splice(0,this._items.length)}moveUp(e){for(;e>0;){let n=Math.floor((e-1)/2);if(!this._compareFn(this._items[e],this._items[n])&&this._items[e]>=this._items[n])break;this.swap(e,n),e=n}}moveDown(e){for(;e<Math.floor(this._items.length/2);){let n=2*e+1;if(n<this._items.length-1&&!this._compareFn(this._items[n],this._items[n+1])&&++n,this._compareFn(this._items[e],this._items[n]))break;this.swap(e,n),e=n}}swap(e,n){[this._items[e],this._items[n]]=[this._items[n],this._items[e]]}get length(){return this._items.length}};function yu(t){let e=window.atob(t),n=e.length,r=new Uint8Array(n);for(let o=0;o<n;o++)r[o]=e.charCodeAt(o);return r.buffer}i(yu,"base64ToArrayBuffer");function qo(t){return yu(t.split(",")[1])}i(qo,"dataURLToArrayBuffer");function Sn(t,e){let n=document.createElement("a");n.href=e,n.download=t,n.click()}i(Sn,"download");function vr(t,e){Sn(t,"data:text/plain;charset=utf-8,"+e)}i(vr,"downloadText");function zo(t,e){vr(t,JSON.stringify(e))}i(zo,"downloadJSON");function wr(t,e){let n=URL.createObjectURL(e);Sn(t,n),URL.revokeObjectURL(n)}i(wr,"downloadBlob");var Vn=i(t=>t.match(/^data:\w+\/\w+;base64,.+/),"isDataURL");var Yo=i(t=>t.split(".").slice(0,-1).join("."),"getFileName");function Pn(t,e){if(t===e)return!0;let n=typeof t,r=typeof e;if(n!==r)return!1;if(n==="object"&&r==="object"&&t!==null&&e!==null){if(Array.isArray(t)!==Array.isArray(e))return!1;let o=Object.keys(t),s=Object.keys(e);if(o.length!==s.length)return!1;for(let a of o){let l=t[a],u=e[a];if(!Pn(l,u))return!1}return!0}return!1}i(Pn,"deepEq");var Qt=class extends Map{static{i(this,"Registry")}lastID=0;push(e){let n=this.lastID;return this.set(n,e),this.lastID++,n}pushd(e){let n=this.push(e);return()=>this.delete(n)}},Ze=class t{static{i(this,"KEventController")}paused=!1;cancel;constructor(e){this.cancel=e}static join(e){let n=new t(()=>e.forEach(r=>r.cancel()));return Object.defineProperty(n,"paused",{get:i(()=>e[0].paused,"get"),set:i(r=>e.forEach(o=>o.paused=r),"set")}),n.paused=!1,n}},le=class{static{i(this,"KEvent")}handlers=new Qt;add(e){let n=this.handlers.pushd((...o)=>{r.paused||e(...o)}),r=new Ze(n);return r}addOnce(e){let n=this.add((...r)=>{n.cancel(),e(...r)});return n}next(){return new Promise(e=>this.addOnce(e))}trigger(...e){this.handlers.forEach(n=>n(...e))}numListeners(){return this.handlers.size}clear(){this.handlers.clear()}},$e=class{static{i(this,"KEventHandler")}handlers={};registers={};on(e,n){return this.handlers[e]||(this.handlers[e]=new le),this.handlers[e].add(n)}onOnce(e,n){let r=this.on(e,(...o)=>{r.cancel(),n(...o)});return r}next(e){return new Promise(n=>{this.onOnce(e,(...r)=>n(r[0]))})}trigger(e,...n){this.handlers[e]&&this.handlers[e].trigger(...n)}remove(e){delete this.handlers[e]}clear(){this.handlers={}}numListeners(e){return this.handlers[e]?.numListeners()??0}};var Wo=i(t=>t instanceof Error?t.message:String(t),"getErrorMessage");function Jt(t,e){return Number(t.toFixed(e))}i(Jt,"toFixed");function de(t,e){return(...n)=>{let r=n.length;if(r===t.length)return t(...n);if(r===e.length)return e(...n)}}i(de,"overload2");var xu=Object.freeze([776,2359,2367,2984,3007,3021,3633,3635,3648,3657,4352,4449,4520]);function Xo(t){if(typeof t!="string")throw new TypeError("string cannot be undefined or null");let e=[],n=0,r=0;for(;n<t.length;){if(r+=vu(n+r,t),Su(t[n+r])&&r++,Tu(t[n+r])&&r++,Ou(t[n+r])&&r++,Vu(t[n+r])){r++;continue}e.push(t.substring(n,n+r)),n+=r,r=0}return e}i(Xo,"runes");function vu(t,e){let n=e[t];if(!wu(n)||t===e.length-1)return 1;let r=n+e[t+1],o=e.substring(t+2,t+5);return $o(r)&&$o(o)?4:Cu(r)&&Au(o)?e.slice(t).indexOf(String.fromCodePoint(917631))+2:Eu(o)?4:2}i(vu,"nextUnits");function wu(t){return t&&xt(t[0].charCodeAt(0),55296,56319)}i(wu,"isFirstOfSurrogatePair");function $o(t){return xt(Cr(t),127462,127487)}i($o,"isRegionalIndicator");function Cu(t){return xt(Cr(t),127988,127988)}i(Cu,"isSubdivisionFlag");function Eu(t){return xt(Cr(t),127995,127999)}i(Eu,"isFitzpatrickModifier");function Tu(t){return typeof t=="string"&&xt(t.charCodeAt(0),65024,65039)}i(Tu,"isVariationSelector");function Ou(t){return typeof t=="string"&&xt(t.charCodeAt(0),8400,8447)}i(Ou,"isDiacriticalMark");function Au(t){let e=t.codePointAt(0);return typeof t=="string"&&typeof e=="number"&&xt(e,917504,917631)}i(Au,"isSupplementarySpecialpurposePlane");function Su(t){return typeof t=="string"&&xu.includes(t.charCodeAt(0))}i(Su,"isGrapheme");function Vu(t){return typeof t=="string"&&t.charCodeAt(0)===8205}i(Vu,"isZeroWidthJoiner");function Cr(t){let e=t.charCodeAt(0)-55296,n=t.charCodeAt(1)-56320;return(e<<10)+n+65536}i(Cr,"codePointFromSurrogatePair");function xt(t,e,n){return t>=e&&t<=n}i(xt,"betweenInclusive");var Fe=i((t,e)=>Array.isArray(t)?t?.includes(e):t===e,"isEqOrIncludes"),Xe=i((t,e)=>Array.isArray(e)?e.some(n=>t.has(n)):t.has(e),"setHasOrIncludes"),Rn=i((t,e,n)=>{t.has(e)?t.get(e)?.push(n):t.set(e,[n])},"mapAddOrPush");var Qo=(()=>{let t=0;return()=>t++})();var Er={"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 Jo=i(()=>vt.lastInputDevice,"getLastInputDeviceType"),Zo=i(()=>{let t=vt.buttons;for(let e in t){let n=t[e].keyboard&&[t[e].keyboard].flat(),r=t[e].gamepad&&[t[e].gamepad].flat(),o=t[e].mouse&&[t[e].mouse].flat();n&&n.forEach(s=>{Rn(vt.buttonsByKey,s,e)}),r&&r.forEach(s=>{Rn(vt.buttonsByGamepad,s,e)}),o&&o.forEach(s=>{Rn(vt.buttonsByMouse,s,e)})}},"parseButtonBindings");var wt=class{static{i(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)}},Tr=class{static{i(this,"GamepadState")}buttonState=new wt;stickState=new Map},Or=class{static{i(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((n,r)=>n+r)/this.dts.length)),this.dts=[])}},vt,Ru=i(t=>{let e=t.buttons??{};return{canvas:t.canvas,buttons:e,buttonsByKey:new Map,buttonsByMouse:new Map,buttonsByGamepad:new Map,loopID:null,stopped:!1,dt:0,fixedDt:1/50,restDt:0,time:0,realTime:0,fpsCounter:new Or,timeScale:1,skipTime:!1,isHidden:!1,numFrames:0,mousePos:new w(0),mouseDeltaPos:new w(0),keyState:new wt,mouseState:new wt,mergedGamepadState:new Tr,gamepadStates:new Map,lastInputDevice:null,buttonState:new wt,gamepads:[],charInputted:[],isMouseMoved:!1,lastWidth:t.canvas.offsetWidth,lastHeight:t.canvas.offsetHeight,events:new $e}},"initAppState"),ei=i(t=>{if(!t.canvas)throw new Error("Please provide a canvas");let e=Ru(t);vt=e,Zo();function n(){return e.dt*e.timeScale}i(n,"dt");function r(){return e.fixedDt*e.timeScale}i(r,"fixedDt");function o(){return e.restDt*e.timeScale}i(o,"restDt");function s(){return e.isHidden}i(s,"isHidden");function a(){return e.time}i(a,"time");function l(){return e.fpsCounter.fps}i(l,"fps");function u(){return e.numFrames}i(u,"numFrames");function m(){return e.canvas.toDataURL()}i(m,"screenshot");function c(h){e.canvas.style.cursor=h}i(c,"setCursor");function p(){return e.canvas.style.cursor}i(p,"getCursor");function d(h){if(h)try{let E=e.canvas.requestPointerLock();E.catch&&E.catch(R=>console.error(R))}catch(E){console.error(E)}else document.exitPointerLock()}i(d,"setCursorLocked");function x(){return!!document.pointerLockElement}i(x,"isCursorLocked");function f(h){h.requestFullscreen?h.requestFullscreen():h.webkitRequestFullscreen&&h.webkitRequestFullscreen()}i(f,"enterFullscreen");function y(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullScreen&&document.webkitExitFullScreen()}i(y,"exitFullscreen");function v(h=!0){h?f(e.canvas):y()}i(v,"setFullscreen");function A(){return document.fullscreenElement===e.canvas||document.webkitFullscreenElement===e.canvas}i(A,"isFullscreen");function V(){e.stopped=!0;let h=Object.entries(Ue),E=Object.entries(ar),R=Object.entries(gn);for(let[N,ie]of h)e.canvas.removeEventListener(N,ie);for(let[N,ie]of E)document.removeEventListener(N,ie);for(let[N,ie]of R)window.removeEventListener(N,ie);so.disconnect()}i(V,"quit");function M(h,E){e.loopID!==null&&cancelAnimationFrame(e.loopID);let R=0,N=0,ie=i(Re=>{if(e.stopped)return;if(document.visibilityState!=="visible"){e.loopID=requestAnimationFrame(ie);return}let se=Re/1e3,nt=Math.min(se-e.realTime,.25),bt=t.maxFPS?1/t.maxFPS:0;if(e.realTime=se,N+=nt,N>bt){if(!e.skipTime){for(R+=N,e.dt=e.fixedDt,e.restDt=0;R>e.fixedDt;)R-=e.fixedDt,R<e.fixedDt&&(e.restDt=R),h();e.restDt=R,e.dt=N,e.time+=n(),e.fpsCounter.tick(e.dt)}N=0,e.skipTime=!1,e.numFrames++,ja(),E(),Ka()}e.loopID=requestAnimationFrame(ie)},"frame");ie(0)}i(M,"run");function G(){return"ontouchstart"in window||navigator.maxTouchPoints>0}i(G,"isTouchscreen");function F(){return e.mousePos.clone()}i(F,"mousePos");function g(){return e.mouseDeltaPos.clone()}i(g,"mouseDeltaPos");function T(h="left"){return e.mouseState.pressed.has(h)}i(T,"isMousePressed");function S(h="left"){return e.mouseState.down.has(h)}i(S,"isMouseDown");function D(h="left"){return e.mouseState.released.has(h)}i(D,"isMouseReleased");function B(){return e.isMouseMoved}i(B,"isMouseMoved");function K(h){return h===void 0?e.keyState.pressed.size>0:Xe(e.keyState.pressed,h)}i(K,"isKeyPressed");function k(h){return h===void 0?e.keyState.pressedRepeat.size>0:Xe(e.keyState.pressedRepeat,h)}i(k,"isKeyPressedRepeat");function z(h){return h===void 0?e.keyState.down.size>0:Xe(e.keyState.down,h)}i(z,"isKeyDown");function X(h){return h===void 0?e.keyState.released.size>0:Xe(e.keyState.released,h)}i(X,"isKeyReleased");function te(h){return h===void 0?e.mergedGamepadState.buttonState.pressed.size>0:Xe(e.mergedGamepadState.buttonState.pressed,h)}i(te,"isGamepadButtonPressed");function Q(h){return h===void 0?e.mergedGamepadState.buttonState.down.size>0:Xe(e.mergedGamepadState.buttonState.down,h)}i(Q,"isGamepadButtonDown");function q(h){return h===void 0?e.mergedGamepadState.buttonState.released.size>0:Xe(e.mergedGamepadState.buttonState.released,h)}i(q,"isGamepadButtonReleased");function ae(h){return h===void 0?e.buttonState.pressed.size>0:Xe(e.buttonState.pressed,h)}i(ae,"isButtonPressed");function U(h){return h===void 0?e.buttonState.down.size>0:Xe(e.buttonState.down,h)}i(U,"isButtonDown");function I(h){return h===void 0?e.buttonState.released.size>0:Xe(e.buttonState.released,h)}i(I,"isButtonReleased");function Y(h){return e.buttons?.[h]}i(Y,"getButton");function j(h,E){e.buttons[h]={...e.buttons[h],...E}}i(j,"setButton");function ue(h){return e.events.on("resize",h)}i(ue,"onResize");let Z=de(h=>e.events.on("keyDown",h),(h,E)=>e.events.on("keyDown",R=>Fe(h,R)&&E(R))),Ce=de(h=>e.events.on("keyPress",E=>h(E)),(h,E)=>e.events.on("keyPress",R=>Fe(h,R)&&E(R))),Ht=de(h=>e.events.on("keyPressRepeat",h),(h,E)=>e.events.on("keyPressRepeat",R=>Fe(h,R)&&E(R))),lt=de(h=>e.events.on("keyRelease",h),(h,E)=>e.events.on("keyRelease",R=>Fe(h,R)&&E(R))),rr=de(h=>e.events.on("mouseDown",E=>h(E)),(h,E)=>e.events.on("mouseDown",R=>Fe(h,R)&&E(R))),or=de(h=>e.events.on("mousePress",E=>h(E)),(h,E)=>e.events.on("mousePress",R=>Fe(h,R)&&E(R))),ir=de(h=>e.events.on("mouseRelease",E=>h(E)),(h,E)=>e.events.on("mouseRelease",R=>R===h&&E(R)));function sr(h){return e.events.on("mouseMove",()=>h(F(),g()))}i(sr,"onMouseMove");function dn(h){return e.events.on("charInput",h)}i(dn,"onCharInput");function Je(h){return e.events.on("touchStart",h)}i(Je,"onTouchStart");function mt(h){return e.events.on("touchMove",h)}i(mt,"onTouchMove");function hn(h){return e.events.on("touchEnd",h)}i(hn,"onTouchEnd");function ke(h){return e.events.on("scroll",h)}i(ke,"onScroll");function qt(h){return e.events.on("hide",h)}i(qt,"onHide");function tt(h){return e.events.on("show",h)}i(tt,"onShow");let fn=de(h=>e.events.on("gamepadButtonPress",E=>h(E)),(h,E)=>e.events.on("gamepadButtonPress",R=>Fe(h,R)&&E(R))),Pa=de(h=>e.events.on("gamepadButtonDown",E=>h(E)),(h,E)=>e.events.on("gamepadButtonDown",R=>Fe(h,R)&&E(R))),Ra=de(h=>e.events.on("gamepadButtonRelease",E=>h(E)),(h,E)=>e.events.on("gamepadButtonRelease",R=>Fe(h,R)&&E(R)));function Ga(h,E){return e.events.on("gamepadStick",(R,N)=>R===h&&E(N))}i(Ga,"onGamepadStick");function Da(h){e.events.on("gamepadConnect",h)}i(Da,"onGamepadConnect");function Ma(h){e.events.on("gamepadDisconnect",h)}i(Ma,"onGamepadDisconnect");function Ua(h){return e.mergedGamepadState.stickState.get(h)||new w(0)}i(Ua,"getGamepadStick");function Ba(){return[...e.charInputted]}i(Ba,"charInputted");function to(){return[...e.gamepads]}i(to,"getGamepads");let Fa=de(h=>e.events.on("buttonPress",E=>h(E)),(h,E)=>e.events.on("buttonPress",R=>Fe(h,R)&&E(R))),La=de(h=>e.events.on("buttonDown",E=>h(E)),(h,E)=>e.events.on("buttonDown",R=>Fe(h,R)&&E(R))),Ia=de(h=>e.events.on("buttonRelease",E=>h(E)),(h,E)=>e.events.on("buttonRelease",R=>Fe(h,R)&&E(R)));function ja(){e.events.trigger("input"),e.keyState.down.forEach(h=>e.events.trigger("keyDown",h)),e.mouseState.down.forEach(h=>e.events.trigger("mouseDown",h)),e.buttonState.down.forEach(h=>e.events.trigger("buttonDown",h)),_a()}i(ja,"processInput");function Ka(){e.keyState.update(),e.mouseState.update(),e.buttonState.update(),e.mergedGamepadState.buttonState.update(),e.mergedGamepadState.stickState.forEach((h,E)=>{e.mergedGamepadState.stickState.set(E,new w(0))}),e.charInputted=[],e.isMouseMoved=!1,e.mouseDeltaPos=new w(0),e.gamepadStates.forEach(h=>{h.buttonState.update(),h.stickState.forEach((E,R)=>{h.stickState.set(R,new w(0))})})}i(Ka,"resetInput");function no(h){let E={index:h.index,isPressed:i(R=>e.gamepadStates.get(h.index)?.buttonState.pressed.has(R)||!1,"isPressed"),isDown:i(R=>e.gamepadStates.get(h.index)?.buttonState.down.has(R)||!1,"isDown"),isReleased:i(R=>e.gamepadStates.get(h.index)?.buttonState.released.has(R)||!1,"isReleased"),getStick:i(R=>e.gamepadStates.get(h.index)?.stickState.get(R)||b(),"getStick")};return e.gamepads.push(E),e.gamepadStates.set(h.index,{buttonState:new wt,stickState:new Map([["left",new w(0)],["right",new w(0)]])}),E}i(no,"registerGamepad");function ka(h){e.gamepads=e.gamepads.filter(E=>E.index!==h.index),e.gamepadStates.delete(h.index)}i(ka,"removeGamepad");function _a(){for(let h of navigator.getGamepads())h&&!e.gamepadStates.has(h.index)&&no(h);for(let h of e.gamepads){let E=navigator.getGamepads()[h.index];if(!E)continue;let N=(t.gamepads??{})[E.id]??Er[E.id]??Er.default,ie=e.gamepadStates.get(h.index);if(ie){for(let Re=0;Re<E.buttons.length;Re++){let se=N.buttons[Re],nt=E.buttons[Re],bt=e.buttonsByGamepad.has(se);nt.pressed?(ie.buttonState.down.has(se)||(e.lastInputDevice="gamepad",bt&&e.buttonsByGamepad.get(se)?.forEach(Oe=>{e.buttonState.press(Oe),e.events.trigger("buttonPress",Oe)}),e.mergedGamepadState.buttonState.press(se),ie.buttonState.press(se),e.events.trigger("gamepadButtonPress",se)),bt&&e.buttonsByGamepad.get(se)?.forEach(Oe=>{e.buttonState.press(Oe),e.events.trigger("buttonDown",Oe)}),e.events.trigger("gamepadButtonDown",se)):ie.buttonState.down.has(se)&&(bt&&e.buttonsByGamepad.get(se)?.forEach(Oe=>{e.buttonState.release(Oe),e.events.trigger("buttonRelease",Oe)}),e.mergedGamepadState.buttonState.release(se),ie.buttonState.release(se),e.events.trigger("gamepadButtonRelease",se))}for(let Re in N.sticks){let se=N.sticks[Re];if(!se)continue;let nt=new w(E.axes[se.x],E.axes[se.y]);ie.stickState.set(Re,nt),e.mergedGamepadState.stickState.set(Re,nt),e.events.trigger("gamepadStick",Re,nt)}}}}i(_a,"processGamepad");let Ue={},ar={},gn={},ro=t.pixelDensity||window.devicePixelRatio||1;Ue.mousemove=h=>{let E=new w(h.offsetX,h.offsetY),R=new w(h.movementX,h.movementY);if(A()){let N=e.canvas.width/ro,ie=e.canvas.height/ro,Re=window.innerWidth,se=window.innerHeight,nt=Re/se,bt=N/ie;if(nt>bt){let Oe=se/ie,ur=(Re-N*Oe)/2;E.x=De(h.offsetX-ur,0,N*Oe,0,N),E.y=De(h.offsetY,0,ie*Oe,0,ie)}else{let Oe=Re/N,ur=(se-ie*Oe)/2;E.x=De(h.offsetX,0,N*Oe,0,N),E.y=De(h.offsetY-ur,0,ie*Oe,0,ie)}}e.events.onOnce("input",()=>{e.isMouseMoved=!0,e.mousePos=E,e.mouseDeltaPos=R,e.events.trigger("mouseMove")})};let oo=["left","middle","right","back","forward"];Ue.mousedown=h=>{e.events.onOnce("input",()=>{let E=oo[h.button];E&&(e.lastInputDevice="mouse",e.buttonsByMouse.has(E)&&e.buttonsByMouse.get(E)?.forEach(R=>{e.buttonState.press(R),e.events.trigger("buttonPress",R)}),e.mouseState.press(E),e.events.trigger("mousePress",E))})},Ue.mouseup=h=>{e.events.onOnce("input",()=>{let E=oo[h.button];E&&(e.buttonsByMouse.has(E)&&e.buttonsByMouse.get(E)?.forEach(R=>{e.buttonState.release(R),e.events.trigger("buttonRelease",R)}),e.mouseState.release(E),e.events.trigger("mouseRelease",E))})};let Na=new Set([" ","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Tab"]),io={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down"," ":"space"};Ue.keydown=h=>{Na.has(h.key)&&h.preventDefault(),e.events.onOnce("input",()=>{let E=io[h.key]||h.key.toLowerCase();if(E===void 0)throw new Error(`Unknown key: ${h.key}`);E.length===1?(e.events.trigger("charInput",E),e.charInputted.push(E)):E==="space"&&(e.events.trigger("charInput"," "),e.charInputted.push(" ")),h.repeat?(e.keyState.pressRepeat(E),e.events.trigger("keyPressRepeat",E)):(e.lastInputDevice="keyboard",e.buttonsByKey.has(E)&&e.buttonsByKey.get(E)?.forEach(R=>{e.buttonState.press(R),e.events.trigger("buttonPress",R)}),e.keyState.press(E),e.events.trigger("keyPressRepeat",E),e.events.trigger("keyPress",E))})},Ue.keyup=h=>{e.events.onOnce("input",()=>{let E=io[h.key]||h.key.toLowerCase();e.buttonsByKey.has(E)&&e.buttonsByKey.get(E)?.forEach(R=>{e.buttonState.release(R),e.events.trigger("buttonRelease",R)}),e.keyState.release(E),e.events.trigger("keyRelease",E)})},Ue.touchstart=h=>{h.preventDefault(),e.events.onOnce("input",()=>{let E=[...h.changedTouches],R=e.canvas.getBoundingClientRect();t.touchToMouse!==!1&&(e.mousePos=new w(E[0].clientX-R.x,E[0].clientY-R.y),e.lastInputDevice="mouse",e.buttonsByMouse.has("left")&&e.buttonsByMouse.get("left")?.forEach(N=>{e.buttonState.press(N),e.events.trigger("buttonPress",N)}),e.mouseState.press("left"),e.events.trigger("mousePress","left")),E.forEach(N=>{e.events.trigger("touchStart",new w(N.clientX-R.x,N.clientY-R.y),N)})})},Ue.touchmove=h=>{h.preventDefault(),e.events.onOnce("input",()=>{let E=[...h.changedTouches],R=e.canvas.getBoundingClientRect();if(t.touchToMouse!==!1){let N=e.mousePos;e.mousePos=new w(E[0].clientX-R.x,E[0].clientY-R.y),e.mouseDeltaPos=e.mousePos.sub(N),e.events.trigger("mouseMove")}E.forEach(N=>{e.events.trigger("touchMove",new w(N.clientX-R.x,N.clientY-R.y),N)})})},Ue.touchend=h=>{e.events.onOnce("input",()=>{let E=[...h.changedTouches],R=e.canvas.getBoundingClientRect();t.touchToMouse!==!1&&(e.mousePos=new w(E[0].clientX-R.x,E[0].clientY-R.y),e.mouseDeltaPos=new w(0,0),e.buttonsByMouse.has("left")&&e.buttonsByMouse.get("left")?.forEach(N=>{e.buttonState.release(N),e.events.trigger("buttonRelease",N)}),e.mouseState.release("left"),e.events.trigger("mouseRelease","left")),E.forEach(N=>{e.events.trigger("touchEnd",new w(N.clientX-R.x,N.clientY-R.y),N)})})},Ue.touchcancel=h=>{e.events.onOnce("input",()=>{let E=[...h.changedTouches],R=e.canvas.getBoundingClientRect();t.touchToMouse!==!1&&(e.mousePos=new w(E[0].clientX-R.x,E[0].clientY-R.y),e.mouseState.release("left"),e.events.trigger("mouseRelease","left")),E.forEach(N=>{e.events.trigger("touchEnd",new w(N.clientX-R.x,N.clientY-R.y),N)})})},Ue.wheel=h=>{h.preventDefault(),e.events.onOnce("input",()=>{e.events.trigger("scroll",new w(h.deltaX,h.deltaY))})},Ue.contextmenu=h=>h.preventDefault(),ar.visibilitychange=()=>{document.visibilityState==="visible"?(e.skipTime=!0,e.isHidden=!1,e.events.trigger("show")):(e.isHidden=!0,e.events.trigger("hide"))},gn.gamepadconnected=h=>{let E=no(h.gamepad);e.events.onOnce("input",()=>{e.events.trigger("gamepadConnect",E)})},gn.gamepaddisconnected=h=>{let E=to().filter(R=>R.index===h.gamepad.index)[0];ka(h.gamepad),e.events.onOnce("input",()=>{e.events.trigger("gamepadDisconnect",E)})};for(let[h,E]of Object.entries(Ue))e.canvas.addEventListener(h,E);for(let[h,E]of Object.entries(ar))document.addEventListener(h,E);for(let[h,E]of Object.entries(gn))window.addEventListener(h,E);let so=new ResizeObserver(h=>{for(let E of h)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 so.observe(e.canvas),{dt:n,fixedDt:r,restDt:o,time:a,run:M,canvas:e.canvas,fps:l,numFrames:u,quit:V,isHidden:s,setFullscreen:v,isFullscreen:A,setCursor:c,screenshot:m,getGamepads:to,getCursor:p,setCursorLocked:d,isCursorLocked:x,isTouchscreen:G,mousePos:F,mouseDeltaPos:g,isKeyDown:z,isKeyPressed:K,isKeyPressedRepeat:k,isKeyReleased:X,isMouseDown:S,isMousePressed:T,isMouseReleased:D,isMouseMoved:B,isGamepadButtonPressed:te,isGamepadButtonDown:Q,isGamepadButtonReleased:q,getGamepadStick:Ua,isButtonPressed:ae,isButtonDown:U,isButtonReleased:I,setButton:j,getButton:Y,charInputted:Ba,onResize:ue,onKeyDown:Z,onKeyPress:Ce,onKeyPressRepeat:Ht,onKeyRelease:lt,onMouseDown:rr,onMousePress:or,onMouseRelease:ir,onMouseMove:sr,onCharInput:dn,onTouchStart:Je,onTouchMove:mt,onTouchEnd:hn,onScroll:ke,onHide:qt,onShow:tt,onGamepadButtonDown:Pa,onGamepadButtonPress:fn,onGamepadButtonRelease:Ra,onGamepadStick:Ga,onGamepadConnect:Da,onGamepadDisconnect:Ma,onButtonPress:Fa,onButtonDown:La,onButtonRelease:Ia,getLastInputDeviceType:Jo,events:e.events}},"initApp");function Ve(){return P.dt()*J.timeScale}i(Ve,"dt");function ti(){return P.fixedDt()*J.timeScale}i(ti,"fixedDt");function ni(){return P.restDt()*J.timeScale}i(ni,"restDt");function Ne(t){switch(t){case"topleft":return new w(-1,-1);case"top":return new w(0,-1);case"topright":return new w(1,-1);case"left":return new w(-1,0);case"center":return new w(0,0);case"right":return new w(1,0);case"botleft":return new w(-1,1);case"bot":return new w(0,1);case"botright":return new w(1,1);default:return t}}i(Ne,"anchorPt");function ri(t){switch(t){case"left":return 0;case"center":return .5;case"right":return 1;default:return 0}}i(ri,"alignPt");function oi(t){return t.createBuffer(1,1,44100)}i(oi,"createEmptyAudioBuffer");var Gn=2.5949095,ii=1.70158+1,si=2*Math.PI/3,ai=2*Math.PI/4.5,Dn={linear:i(t=>t,"linear"),easeInSine:i(t=>1-Math.cos(t*Math.PI/2),"easeInSine"),easeOutSine:i(t=>Math.sin(t*Math.PI/2),"easeOutSine"),easeInOutSine:i(t=>-(Math.cos(Math.PI*t)-1)/2,"easeInOutSine"),easeInQuad:i(t=>t*t,"easeInQuad"),easeOutQuad:i(t=>1-(1-t)*(1-t),"easeOutQuad"),easeInOutQuad:i(t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,"easeInOutQuad"),easeInCubic:i(t=>t*t*t,"easeInCubic"),easeOutCubic:i(t=>1-Math.pow(1-t,3),"easeOutCubic"),easeInOutCubic:i(t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,"easeInOutCubic"),easeInQuart:i(t=>t*t*t*t,"easeInQuart"),easeOutQuart:i(t=>1-Math.pow(1-t,4),"easeOutQuart"),easeInOutQuart:i(t=>t<.5?8*t*t*t*t:1-Math.pow(-2*t+2,4)/2,"easeInOutQuart"),easeInQuint:i(t=>t*t*t*t*t,"easeInQuint"),easeOutQuint:i(t=>1-Math.pow(1-t,5),"easeOutQuint"),easeInOutQuint:i(t=>t<.5?16*t*t*t*t*t:1-Math.pow(-2*t+2,5)/2,"easeInOutQuint"),easeInExpo:i(t=>t===0?0:Math.pow(2,10*t-10),"easeInExpo"),easeOutExpo:i(t=>t===1?1:1-Math.pow(2,-10*t),"easeOutExpo"),easeInOutExpo:i(t=>t===0?0:t===1?1:t<.5?Math.pow(2,20*t-10)/2:(2-Math.pow(2,-20*t+10))/2,"easeInOutExpo"),easeInCirc:i(t=>1-Math.sqrt(1-Math.pow(t,2)),"easeInCirc"),easeOutCirc:i(t=>Math.sqrt(1-Math.pow(t-1,2)),"easeOutCirc"),easeInOutCirc:i(t=>t<.5?(1-Math.sqrt(1-Math.pow(2*t,2)))/2:(Math.sqrt(1-Math.pow(-2*t+2,2))+1)/2,"easeInOutCirc"),easeInBack:i(t=>ii*t*t*t-1.70158*t*t,"easeInBack"),easeOutBack:i(t=>1+ii*Math.pow(t-1,3)+1.70158*Math.pow(t-1,2),"easeOutBack"),easeInOutBack:i(t=>t<.5?Math.pow(2*t,2)*((Gn+1)*2*t-Gn)/2:(Math.pow(2*t-2,2)*((Gn+1)*(t*2-2)+Gn)+2)/2,"easeInOutBack"),easeInElastic:i(t=>t===0?0:t===1?1:-Math.pow(2,10*t-10)*Math.sin((t*10-10.75)*si),"easeInElastic"),easeOutElastic:i(t=>t===0?0:t===1?1:Math.pow(2,-10*t)*Math.sin((t*10-.75)*si)+1,"easeOutElastic"),easeInOutElastic:i(t=>t===0?0:t===1?1:t<.5?-(Math.pow(2,20*t-10)*Math.sin((20*t-11.125)*ai))/2:Math.pow(2,-20*t+10)*Math.sin((20*t-11.125)*ai)/2+1,"easeInOutElastic"),easeInBounce:i(t=>1-Dn.easeOutBounce(1-t),"easeInBounce"),easeOutBounce:i(t=>t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375,"easeOutBounce"),easeInOutBounce:i(t=>t<.5?(1-Dn.easeOutBounce(1-2*t))/2:(1+Dn.easeOutBounce(2*t-1))/2,"easeInOutBounce")},ot=Dn;function Gu(t,e,n){let r=[],o=e;for(r.push(o);o!==t;){if(o=n.get(o),o==null)return null;r.push(o)}return r.reverse()}i(Gu,"buildPath");function Ar(t,e,n){let r=new Ft((a,l)=>a.cost<l.cost);r.insert({cost:0,node:e});let o=new Map;o.set(e,e);let s=new Map;for(s.set(e,0);r.length!==0;){let a=r.remove()?.node;if(a===n)break;let l=t.getNeighbours(a);for(let u of l){let m=(s.get(a)||0)+t.getCost(a,u)+t.getHeuristic(u,n);(!s.has(u)||m<s.get(u))&&(s.set(u,m),r.insert({cost:m,node:u}),o.set(u,a))}}return Gu(e,n,o)}i(Ar,"aStarSearch");var Sr=class{static{i(this,"NavEdge")}a;b;polygon;constructor(e,n,r){this.a=e,this.b=n,this.polygon=new WeakRef(r)}isLeft(e,n){return(this.b.x-this.a.x)*(n-this.a.y)-(e-this.a.x)*(this.b.y-this.a.y)}get middle(){return this.a.add(this.b).scale(.5)}},Vr=class{static{i(this,"NavPolygon")}_edges;_centroid;_id;constructor(e){this._id=e}get id(){return this._id}set edges(e){this._edges=e;let n=0,r=0,o=0;for(let s of this._edges){s.polygon=new WeakRef(this);let a=s.a.x*s.b.y-s.a.y*s.b.x;n+=(s.a.x+s.b.x)*a,r+=(s.a.y+s.b.y)*a,o+=a}o/=2,this._centroid=b(n/(6*o),r/(6*o))}get edges(){return this._edges}get centroid(){return this._centroid}contains(e){let n=!1;for(let r of this.edges)r.b.y>e.y!=r.a.y>e.y&&e.x<(r.a.x-r.b.x)*(e.y-r.b.y)/(r.a.y-r.b.y)+r.b.x&&(n=!n);return n}},Mn=class{static{i(this,"NavMesh")}_polygons;_pointCache;_edgeCache;constructor(){this._polygons=[],this._pointCache={},this._edgeCache={}}_addPoint(e){let n=this._pointCache[`${e.x}_${e.y}`];return n||(n=e.clone(),this._pointCache[`${e.x}_${e.y}`]=n,n)}_addEdge(e){let n=`${e.a.x}_${e.a.y}-${e.b.x}_${e.b.y}`;return this._edgeCache[n]=e,e}_findEdge(e,n){let r=`${e.x}_${e.y}-${n.x}_${n.y}`;return this._edgeCache[r]}_findCommonEdge(e,n){for(let r of e.edges){let o=this._findEdge(r.b,r.a);if(o&&o.polygon.deref().id===n.id)return o}return null}addPolygon(e){let n=new Vr(this._polygons.length),r=e.map((o,s)=>new Sr(o,e[(s+1)%e.length],n));n.edges=r,this._polygons.push(n);for(let o of n.edges)this._addEdge(o);return n}addRect(e,n){let r=this._addPoint(e),o=this._addPoint(e.add(n.x,0)),s=this._addPoint(e.add(n)),a=this._addPoint(e.add(0,n.y));return this.addPolygon([r,o,s,a])}_getLocation(e){for(let n of this._polygons)if(n.contains(e))return n;return null}getNeighbours(e){let n=[];for(let r of this._polygons[e].edges){let o=this._findEdge(r.b,r.a);if(o){let s=o.polygon.deref();s&&n.push(s.id)}}return n}getCost(e,n){return 1}getHeuristic(e,n){let r=this._polygons[e],o=this._polygons[n],s=r.centroid.x-o.centroid.x,a=r.centroid.y-o.centroid.y;return Math.sqrt(s*s+a*a)}getPath(e,n){return e===void 0||n===void 0?[]:e===n?[e,n]:Ar(this,e,n)}getWaypointPath(e,n,r){let o=r?.type||"centroids",s=this._getLocation(e),a=this._getLocation(n);if(s===void 0||a===void 0)return[];let l=this.getPath(s.id,a.id);if(!l)return[];if(o==="edges"){let u=[];for(let m=1;m<l.length;m++){let c=this._polygons[l[m-1]],p=this._polygons[l[m]],d=this._findCommonEdge(c,p);u.push(d.middle.add(p.centroid.sub(d.middle).unit().scale(4)))}return[e,...u,n]}else return[e,...l.slice(1,-1).map(u=>this._polygons[u].centroid),n]}};function Lt(t){let e=new ge;return t.pos&&e.translate(t.pos),t.scale&&e.scale(t.scale),t.angle&&e.rotate(t.angle),t.parent?e.mult(t.parent.transform):e}i(Lt,"calcTransform");function ui(t){return new w(t.x/he()*2-1,-t.y/ye()*2+1)}i(ui,"screen2ndc");function Ct(t,e,n,r,o,s=1){r=ce(r%360),o=ce(o%360),o<=r&&(o+=Math.PI*2);let a=[],l=Math.ceil((o-r)/ce(8)*s),u=(o-r)/l,m=b(Math.cos(r),Math.sin(r)),c=b(Math.cos(u),Math.sin(u));for(let p=0;p<=l;p++)a.push(t.add(e*m.x,n*m.y)),m=b(m.x*c.x-m.y*c.y,m.x*c.y+m.y*c.x);return a}i(Ct,"getArcPts");function ci(...t){let e=W(...t),n=t[3]??1;O.bgColor=e,O.bgAlpha=n,O.ggl.gl.clearColor(e.r/255,e.g/255,e.b/255,n)}i(ci,"setBackground");function li(){return O.bgColor?.clone?.()??null}i(li,"getBackground");function ne(...t){if(t[0]===void 0)return;let e=b(...t);e.x===0&&e.y===0||O.transform.translate(e)}i(ne,"pushTranslate");function we(){O.transformStack.push(O.transform.clone())}i(we,"pushTransform");function mi(t){O.transform=t.clone()}i(mi,"pushMatrix");function it(...t){if(t[0]===void 0)return;let e=b(...t);e.x===1&&e.y===1||O.transform.scale(e)}i(it,"pushScale");function Qe(t){t&&O.transform.rotate(t)}i(Qe,"pushRotate");function xe(){O.transformStack.length>0&&(O.transform=O.transformStack.pop())}i(xe,"popTransform");function Te(){O.renderer.flush()}i(Te,"flush");function he(){return O.width}i(he,"width");function ye(){return O.height}i(ye,"height");function Un(){return(O.viewport.width+O.viewport.height)/(O.width+O.height)}i(Un,"getViewportScale");function pi(t){return new w(t.x*O.viewport.width/O.width,t.y*O.viewport.height/O.height)}i(pi,"contentToView");function Du(t){return new w((t.x-O.viewport.x)*he()/O.viewport.width,(t.y-O.viewport.y)*ye()/O.viewport.height)}i(Du,"windowToContent");function Bn(){return Du(P.mousePos())}i(Bn,"mousePos");function Et(){return b(he()/2,ye()/2)}i(Et,"center");var Fn=" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",dt="topleft";var di="monospace",Tt="monospace";var Zt="linear";var en=[{name:"a_pos",size:2},{name:"a_uv",size:2},{name:"a_color",size:4}],Mu=en.reduce((t,e)=>t+e.size,0),hi=2048,fi=hi*4*Mu,gi=hi*6,bi=`
attribute vec2 a_pos;
attribute vec2 a_uv;
attribute vec4 a_color;
varying vec2 v_pos;
varying vec2 v_uv;
varying vec4 v_color;
vec4 def_vert() {
return vec4(a_pos, 0.0, 1.0);
}
{{user}}
void main() {
vec4 pos = vert(a_pos, a_uv, a_color);
v_pos = a_pos;
v_uv = a_uv;
v_color = a_color;
gl_Position = pos;
}
`,yi=`
precision mediump float;
varying vec2 v_pos;
varying vec2 v_uv;
varying vec4 v_color;
uniform sampler2D u_tex;
vec4 def_frag() {
return v_color * texture2D(u_tex, v_uv);
}
{{user}}
void main() {
gl_FragColor = frag(v_pos, v_uv, v_color, u_tex);
if (gl_FragColor.a == 0.0) {
discard;
}
}
`,tn=`
vec4 vert(vec2 pos, vec2 uv, vec4 color) {
return def_vert();
}
`,nn=`
vec4 frag(vec2 pos, vec2 uv, vec4 color, sampler2D tex) {
return def_frag();
}
`,xi=new Set(["id","require"]),vi=new Set(["add","fixedUpdate","update","draw","destroy","inspect","drawInspect"]),wi=/^\w+$/,Ci=200,Ei=640,Ti=65536;var rn=class{static{i(this,"TexPacker")}textures=[];bigTextures=[];canvas;c2d;x=0;y=0;curHeight=0;gfx;constructor(e,n,r){this.gfx=e,this.canvas=document.createElement("canvas"),this.canvas.width=n,this.canvas.height=r,this.textures=[Me.fromImage(e,this.canvas)],this.bigTextures=[];let o=this.canvas.getContext("2d");if(!o)throw new Error("Failed to get 2d context");this.c2d=o}add(e){if(e.width>this.canvas.width||e.height>this.canvas.height){let o=Me.fromImage(this.gfx,e);return this.bigTextures.push(o),[o,new $(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(Me.fromImage(this.gfx,this.canvas)),this.x=0,this.y=0,this.curHeight=0);let n=this.textures[this.textures.length-1],r=new w(this.x,this.y);return this.x+=e.width,e.height>this.curHeight&&(this.curHeight=e.height),e instanceof ImageData?this.c2d.putImageData(e,r.x,r.y):this.c2d.drawImage(e,r.x,r.y),n.update(this.canvas),[n,new $(r.x/this.canvas.width,r.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()}};function fe(t){return typeof t!="string"||Vn(t)?t:_.urlPrefix+t}i(fe,"fixURL");var me=class t{static{i(this,"Asset")}loaded=!1;data=null;error=null;onLoadEvents=new le;onErrorEvents=new le;onFinishEvents=new le;constructor(e){e.then(n=>{this.loaded=!0,this.data=n,this.onLoadEvents.trigger(n)}).catch(n=>{if(this.error=n,this.onErrorEvents.numListeners()>0)this.onErrorEvents.trigger(n);else throw n}).finally(()=>{this.onFinishEvents.trigger(),this.loaded=!0})}static loaded(e){let n=new t(Promise.resolve(e));return n.data=e,n.loaded=!0,n}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)}},ht=class{static{i(this,"AssetBucket")}assets=new Map;lastUID=0;add(e,n){let r=e??this.lastUID+++"",o=new me(n);return this.assets.set(r,o),o}addLoaded(e,n){let r=e??this.lastUID+++"",o=me.loaded(n);return this.assets.set(r,o),o}get(e){return this.assets.get(e)}progress(){if(this.assets.size===0)return 1;let e=0;return this.assets.forEach(n=>{n.loaded&&e++}),e/this.assets.size}};function Gr(t){return fetch(t).then(e=>{if(!e.ok)throw new Error(`Failed to fetch "${t}"`);return e})}i(Gr,"fetchURL");function Ot(t){return Gr(t).then(e=>e.json())}i(Ot,"fetchJSON");function Oi(t){return Gr(t).then(e=>e.text())}i(Oi,"fetchText");function Ai(t){return Gr(t).then(e=>e.arrayBuffer())}i(Ai,"fetchArrayBuffer");function Si(t){return t!==void 0&&(_.urlPrefix=t),_.urlPrefix}i(Si,"loadRoot");function Vi(t,e){return _.custom.add(t,Ot(fe(e)))}i(Vi,"loadJSON");function At(t){let e=new Image;return e.crossOrigin="anonymous",e.src=t,new Promise((n,r)=>{e.onload=()=>n(e),e.onerror=()=>r(new Error(`Failed to load image from "${t}"`))})}i(At,"loadImg");function Le(){let t=[_.sprites,_.sounds,_.shaders,_.fonts,_.bitmapFonts,_.custom];return t.reduce((e,n)=>e+n.progress(),0)/t.length}i(Le,"loadProgress");function Pi(t){return _.custom.get(t)??null}i(Pi,"getAsset");function on(t){return _.custom.add(null,t)}i(on,"load");var Ri=i(t=>({urlPrefix:"",sprites:new ht,fonts:new ht,bitmapFonts:new ht,sounds:new ht,shaders:new ht,custom:new ht,music:{},packer:new rn(t,2048,2048),loaded:!1}),"initAssets");var Gi="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD0AAAA1CAYAAADyMeOEAAAAAXNSR0IArs4c6QAAAoVJREFUaIHdm7txwkAQhheGAqACiCHzOKQDQrqgILpwSAeEDBnEUAF0gCMxZ7G72qce/mec2Lpf9+3unaS78wgSNZ8uX5729+d1FNWXUuGmXlBOUUEIMckEpeQJgBu6C+BSFngztBR2vd+ovY+7g+p6LbgaWgJrAeUkDYIUXgXdBBwNi6kpABJwMTQH3AZsXRR8GHTfgEth8E3gjdAUcNewpbTgY85sCMCUuOokozE0YM0YRzM9NGAAXd8+omAF5h4lnmBRvpSnZHyLoLEbaN+aKB9KWv/KWw0tAbbANnlG+UvB2dm77NxxdwgBpjrF/d7rW9cbmpvio2A5z8iAYpVU8pGZlo6/2+MSco2lHfd3rv9jAP038e1xef9o2mjvYb2OqpqKE81028/jeietlSEVO5FRWsxWsJit1G3aFpW8iWe5RwpiCZAk25QvV6nz6fIlynRGuTd5WqpJ4guAlDfVKBK87hXljflgv1ON6fV+4+5gVlA17SfeG0heKqQd4l4jI/wrmaA9N9R4ar+wpHJDZyrrfcH0nB66PqAzPi76pn+faSyJk/vzOorYhGurQrzj/P68jtBMawHaHBIR9xoD5O34dy0qQOSYHvqExq2TpT2nf76+w7y251OYF0CRaU+J920TwLUa6inx6OxE6g80lu2ux7Y2eJLF/rCXE6zEPdnenk9o+4ih9AEdnW2q81HXl5LuU6OTl2fXUhqganbXAGq3g6jJOWV/OnoesO6YqqEB/GdNsjf7uHtwj2DzmRNpp7iOZfm6D9oAxB6Yi1gC4oIYeo4MIPdopEQRB+cAko5J1tW386HpB2Kz1eop4Epdwls/kgZ1sh8gZsEjdcWkr//D8Qu3Z3l5Nl1NtAAAAABJRU5ErkJggg==";var Ie=class t{static{i(this,"SpriteData")}tex;frames=[new $(0,0,1,1)];anims={};slice9=null;constructor(e,n,r={},o=null){this.tex=e,n&&(this.frames=n),this.anims=r,this.slice9=o}get width(){return this.tex.width*this.frames[0].w}get height(){return this.tex.height*this.frames[0].h}static from(e,n={}){return typeof e=="string"?t.fromURL(e,n):Promise.resolve(t.fromImage(e,n))}static fromImage(e,n={}){let[r,o]=_.packer.add(e),s=n.frames?n.frames.map(a=>new $(o.x+a.x*o.w,o.y+a.y*o.h,a.w*o.w,a.h*o.h)):Mr(n.sliceX||1,n.sliceY||1,o.x,o.y,o.w,o.h);return new t(r,s,n.anims,n.slice9)}static fromURL(e,n={}){return At(e).then(r=>t.fromImage(r,n))}};function It(t){if(typeof t=="string"){let e=Dr(t);if(e)return e;if(Le()<1)return null;throw new Error(`Sprite not found: ${t}`)}else{if(t instanceof Ie)return me.loaded(t);if(t instanceof me)return t;throw new Error(`Invalid sprite: ${t}`)}}i(It,"resolveSprite");function Dr(t){return _.sprites.get(t)??null}i(Dr,"getSprite");function St(t,e,n={sliceX:1,sliceY:1,anims:{}}){return e=fe(e),Array.isArray(e)?e.some(r=>typeof r=="string")?_.sprites.add(t,Promise.all(e.map(r=>typeof r=="string"?At(r):Promise.resolve(r))).then(r=>Di(r,n))):_.sprites.addLoaded(t,Di(e,n)):typeof e=="string"?_.sprites.add(t,Ie.from(e,n)):_.sprites.addLoaded(t,Ie.fromImage(e,n))}i(St,"loadSprite");function Mr(t=1,e=1,n=0,r=0,o=1,s=1){let a=[],l=o/t,u=s/e;for(let m=0;m<e;m++)for(let c=0;c<t;c++)a.push(new $(n+c*l,r+m*u,l,u));return a}i(Mr,"slice");function Di(t,e={}){let n=document.createElement("canvas"),r=t[0].width,o=t[0].height;n.width=r*t.length,n.height=o;let s=n.getContext("2d");if(!s)throw new Error("Failed to create canvas context");t.forEach((l,u)=>{l instanceof ImageData?s.putImageData(l,u*r,0):s.drawImage(l,u*r,0)});let a=s.getImageData(0,0,t.length*r,o);return Ie.fromImage(a,{...e,sliceX:t.length,sliceY:1})}i(Di,"createSpriteSheet");function Mi(t="bean"){return St(t,Gi)}i(Mi,"loadBean");function Ui(t,e,n){e=fe(e),n=fe(n),typeof e=="string"&&!n&&(n=Yo(e)+".json");let r=typeof n=="string"?Ot(n):Promise.resolve(n);return _.sprites.add(t,r.then(o=>{let s=o.meta.size,a=o.frames.map(u=>new $(u.frame.x/s.w,u.frame.y/s.h,u.frame.w/s.w,u.frame.h/s.h)),l={};for(let u of o.meta.frameTags)u.from===u.to?l[u.name]=u.from:l[u.name]={from:u.from,to:u.to,speed:10,loop:!0,pingpong:u.direction==="pingpong"};return Ie.from(e,{frames:a,anims:l})}))}i(Ui,"loadAseprite");var Vt=class{static{i(this,"FontData")}fontface;filter=Zt;outline=null;size=64;constructor(e,n={}){if(this.fontface=e,this.filter=n.filter??Zt,this.size=n.size??64,this.size>256)throw new Error(`Max font size: ${256}`);n.outline&&(this.outline={width:1,color:W(0,0,0)},typeof n.outline=="number"?this.outline.width=n.outline:typeof n.outline=="object"&&(n.outline.width&&(this.outline.width=n.outline.width),n.outline.color&&(this.outline.color=n.outline.color)))}};function Ur(t){if(!t)return Ur(re.font??di);if(typeof t=="string"){let e=Ln(t),n=Br(t);if(e)return e.data??e;if(n)return n.data??n;if(document.fonts.check(`${64}px ${t}`))return t;if(Le()<1)return null;throw new Error(`Font not found: ${t}`)}else if(t instanceof me)return t.data?t.data:t;return t}i(Ur,"resolveFont");function Br(t){return _.fonts.get(t)??null}i(Br,"getFont");function Bi(t,e,n={}){let r=fe(e),o=new FontFace(t,typeof e=="string"?`url(${r})`:r);return document.fonts.add(o),_.fonts.add(t,o.load().catch(s=>{throw new Error(`Failed to load font from "${r}": ${s}`)}).then(s=>new Vt(s,n)))}i(Bi,"loadFont");function Fi(t,e,n,r){let o=t.width/e,s={},a=r.split("").entries();for(let[l,u]of a)s[u]=new $(l%o*e,Math.floor(l/o)*n,e,n);return{tex:t,map:s,size:n}}i(Fi,"makeFont");function Ln(t){return _.bitmapFonts.get(t)??null}i(Ln,"getBitmapFont");function Li(t,e,n,r,o={}){let s=fe(e);return _.bitmapFonts.add(t,At(s).then(a=>Fi(Me.fromImage(O.ggl,a,o),n,r,o.chars??Fn)))}i(Li,"loadBitmapFont");function Ii(t,e){return e=fe(e),_.sprites.add(t,new Promise(async n=>{let r=typeof e=="string"?await Ot(e):e,o=await Promise.all(r.frames.map(At)),s=document.createElement("canvas");s.width=r.width,s.height=r.height*r.frames.length;let a=s.getContext("2d");if(!a)throw new Error("Failed to create canvas context");o.forEach((u,m)=>{a.drawImage(u,0,m*r.height)});let l=await St(null,s,{sliceY:r.frames.length,anims:r.anims});n(l)}))}i(Ii,"loadPedit");var Fr=class{static{i(this,"Shader")}ctx;glProgram;constructor(e,n,r,o){this.ctx=e,e.onDestroy(()=>this.free());let s=e.gl,a=s.createShader(s.VERTEX_SHADER),l=s.createShader(s.FRAGMENT_SHADER);if(!a||!l)throw new Error("Failed to create shader");s.shaderSource(a,n),s.shaderSource(l,r),s.compileShader(a),s.compileShader(l);let u=s.createProgram();if(this.glProgram=u,s.attachShader(u,a),s.attachShader(u,l),o.forEach((m,c)=>s.bindAttribLocation(u,c,m)),s.linkProgram(u),!s.getProgramParameter(u,s.LINK_STATUS)){let m=s.getShaderInfoLog(a);if(m)throw new Error("VERTEX SHADER "+m);let c=s.getShaderInfoLog(l);if(c)throw new Error("FRAGMENT SHADER "+c)}s.deleteShader(a),s.deleteShader(l)}bind(){this.ctx.pushProgram(this.glProgram)}unbind(){this.ctx.popProgram()}send(e){let n=this.ctx.gl;for(let r in e){let o=e[r],s=n.getUniformLocation(this.glProgram,r);if(typeof o=="number")n.uniform1f(s,o);else if(o instanceof ge)n.uniformMatrix4fv(s,!1,new Float32Array(o.m));else if(o instanceof H)n.uniform3f(s,o.r,o.g,o.b);else if(o instanceof w)n.uniform2f(s,o.x,o.y);else if(Array.isArray(o)){let a=o[0];No(o)?n.uniform1fv(s,o):_o(o)?n.uniform2fv(s,o.map(l=>[l.x,l.y]).flat()):ko(o)&&n.uniform3fv(s,o.map(l=>[l.r,l.g,l.b]).flat())}else throw new Error("Unsupported uniform data type")}}free(){this.ctx.gl.deleteProgram(this.glProgram)}};function In(t,e=tn,n=nn){let r=bi.replace("{{user}}",e??tn),o=yi.replace("{{user}}",n??nn);try{return new Fr(t,r,o,en.map(s=>s.name))}catch(s){let l=/(?<type>^\w+) SHADER ERROR: 0:(?<line>\d+): (?<msg>.+)/,u=Wo(s).match(l);if(!u?.groups)throw s;let m=Number(u.groups.line)-14,c=u.groups.msg.trim(),p=u.groups.type.toLowerCase();throw new Error(`${p} shader line ${m}: ${c}`)}}i(In,"makeShader");function ji(t){if(!t)return O.defShader;if(typeof t=="string"){let e=Lr(t);if(e)return e.data??e;if(Le()<1)return null;throw new Error(`Shader not found: ${t}`)}else if(t instanceof me)return t.data?t.data:t;return t}i(ji,"resolveShader");function Lr(t){return _.shaders.get(t)??null}i(Lr,"getShader");function Ki(t,e,n){return _.shaders.addLoaded(t,In(O.ggl,e,n))}i(Ki,"loadShader");function ki(t,e,n){e=fe(e),n=fe(n);let r=i(s=>s?Oi(s):Promise.resolve(null),"resolveUrl"),o=Promise.all([r(e),r(n)]).then(([s,a])=>In(O.ggl,s,a));return _.shaders.add(t,o)}i(ki,"loadShaderURL");var st=class t{static{i(this,"SoundData")}buf;constructor(e){this.buf=e}static fromArrayBuffer(e){return new Promise((n,r)=>oe.ctx.decodeAudioData(e,n,r)).then(n=>new t(n))}static fromURL(e){return Vn(e)?t.fromArrayBuffer(qo(e)):Ai(e).then(n=>t.fromArrayBuffer(n))}};function _i(t){if(typeof t=="string"){let e=Ir(t);if(e)return e;if(Le()<1)return null;throw new Error(`Sound not found: ${t}`)}else{if(t instanceof st)return me.loaded(t);if(t instanceof me)return t;throw new Error(`Invalid sound: ${t}`)}}i(_i,"resolveSound");function Ir(t){return _.sounds.get(t)??null}i(Ir,"getSound");function Ni(t,e){return e=fe(e),_.sounds.add(t,typeof e=="string"?st.fromURL(e):st.fromArrayBuffer(e))}i(Ni,"loadSound");function Hi(t,e){let n=fe(e),r=new Audio(n);return r.preload="auto",_.music[t]=n}i(Hi,"loadMusic");function jr(t,e){return t=fe(t),typeof e=="string"?on(new Promise((n,r)=>{Ot(e).then(o=>{jr(t,o).then(n).catch(r)})})):on(Ie.from(t).then(n=>{let r={};for(let o in e){let s=e[o],a=n.frames[0],l=2048*a.w,u=2048*a.h,m=s.frames?s.frames.map(p=>new $(a.x+(s.x+p.x)/l*a.w,a.y+(s.y+p.y)/u*a.h,p.w/l*a.w,p.h/u*a.h)):Mr(s.sliceX||1,s.sliceY||1,a.x+s.x/l*a.w,a.y+s.y/u*a.h,s.width/l*a.w,s.height/u*a.h),c=new Ie(n.tex,m,s.anims);_.sprites.addLoaded(o,c),r[o]=c}return r}))}i(jr,"loadSpriteAtlas");function je(t,e,n=!1,r,o,s={}){let a=r??O.defTex,l=o??O.defShader,u=ji(l);if(!u||u instanceof me)return;let m=O.fixed||n?O.transform:C.cam.transform.mult(O.transform),c=[];for(let p of t){let d=ui(m.multVec2(p.pos));c.push(d.x,d.y,p.uv.x,p.uv.y,p.color.r/255,p.color.g/255,p.color.b/255,p.opacity)}O.renderer.push(O.ggl.gl.TRIANGLES,c,e,u,a,s)}i(je,"drawRaw");function He(t){if(!t.pts)throw new Error('drawPolygon() requires property "pts".');let e=t.pts.length;if(!(e<3)){if(we(),ne(t.pos),it(t.scale),Qe(t.angle),ne(t.offset),t.fill!==!1){let n=t.color??H.WHITE,r=t.pts.map((s,a)=>({pos:new w(s.x,s.y),uv:t.uv?t.uv[a]:new w(0,0),color:t.colors&&t.colors[a]?t.colors[a].mult(n):n,opacity:t.opacity??1})),o;t.triangulate?o=An(t.pts).map(a=>a.map(l=>t.pts.indexOf(l))).flat():o=[...Array(e-2).keys()].map(s=>[0,s+1,s+2]).flat(),je(r,t.indices??o,t.fixed,t.uv?t.tex:O.defTex,t.shader,t.uniform??void 0)}t.outline&&jt({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??t.outline.opacity}),xe()}}i(He,"drawPolygon");function jn(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 e=t.start??0,n=t.end??360,r=Ne(t.anchor??"center").scale(new w(-t.radiusX,-t.radiusY)),o=Ct(r,t.radiusX,t.radiusY,e,n,t.resolution);o.unshift(r);let s=Object.assign({},t,{pts:o,radius:0,...t.gradient?{colors:[t.gradient[0],...Array(o.length-1).fill(t.gradient[1])]}:{}});if(n-e>=360&&t.outline){t.fill!==!1&&He(Object.assign({},s,{outline:null})),He(Object.assign({},s,{pts:o.slice(1),fill:!1}));return}He(s)}i(jn,"drawEllipse");function ft(t){if(typeof t.radius!="number")throw new Error('drawCircle() requires property "radius".');t.radius!==0&&jn(Object.assign({},t,{radiusX:t.radius,radiusY:t.radius,angle:0}))}i(ft,"drawCircle");function Kt(t){let{p1:e,p2:n}=t;if(!e||!n)throw new Error('drawLine() requires properties "p1" and "p2".');let r=t.width||1,o=n.sub(e).unit().normal().scale(r*.5),s=[e.sub(o),e.add(o),n.add(o),n.sub(o)].map(a=>({pos:new w(a.x,a.y),uv:new w(0),color:t.color??H.WHITE,opacity:t.opacity??1}));je(s,[0,1,3,1,2,3],t.fixed,O.defTex,t.shader,t.uniform??void 0)}i(Kt,"drawLine");function Bu(t){let e=t.pts,n=[],r=(t.width||1)*.5,o=e[0]===e[e.length-1]||e[0].eq(e[e.length-1]),s=t.pos||b(0,0),a;o?a=e[0].sub(e[e.length-2]):a=e[1].sub(e[0]);let l=a.len(),u=a.normal().scale(-r/l),m,c=e[0];if(!o)switch(t.cap){case"square":{let f=a.scale(-r/l);n.push(c.add(f).add(u)),n.push(c.add(f).sub(u));break}case"round":{let f=Math.max(r,10),y=Math.PI/f,v=u.scale(-1),A=Math.cos(y),V=Math.sin(y);for(let M=0;M<f;M++)n.push(c),n.push(c.sub(v)),v=b(v.x*A-v.y*V,v.x*V+v.y*A)}}for(let f=1;f<e.length;f++){if(c===e[f]||c.eq(e[f]))continue;m=c,c=e[f];let y=c.sub(m),v=y.len(),A=y.normal().scale(-r/v),V=a.cross(y);if(Math.abs(V)/(l*v)<.05){n.push(m.add(u)),n.push(m.sub(u)),a.dot(y)<0&&(n.push(m.sub(u)),n.push(m.add(u))),a=y,l=v,u=A;continue}let M=A.sub(u).cross(y)/V,G=u.add(a.scale(M));V>0?(n.push(m.add(G)),n.push(m.sub(u)),n.push(m.add(G)),n.push(m.sub(A))):(n.push(m.add(u)),n.push(m.sub(G)),n.push(m.add(A)),n.push(m.sub(G))),a=y,l=v,u=A}if(!o)switch(n.push(c.add(u)),n.push(c.sub(u)),t.cap){case"square":{let f=a.scale(r/l);n.push(c.add(f).add(u)),n.push(c.add(f).sub(u));break}case"round":{let f=Math.max(r,10),y=Math.PI/f,v=u.scale(1),A=Math.cos(y),V=Math.sin(y);for(let M=0;M<f;M++)v=b(v.x*A-v.y*V,v.x*V+v.y*A),n.push(c),n.push(c.sub(v))}}if(n.length<4)return;let p=n.map(f=>({pos:s.add(f),uv:b(),color:t.color||H.WHITE,opacity:t.opacity??1})),d=[],x=0;for(let f=0;f<n.length-2;f+=2)d[x++]=f+1,d[x++]=f,d[x++]=f+2,d[x++]=f+2,d[x++]=f+3,d[x++]=f+1;o&&(d[x++]=n.length-1,d[x++]=n.length-2,d[x++]=0,d[x++]=0,d[x++]=1,d[x++]=n.length-1),je(p,d,t.fixed,O.defTex,t.shader,t.uniform??void 0)}i(Bu,"_drawLinesBevel");function Fu(t){let e=t.pts,n=[],r=(t.width||1)*.5,o=e[0]===e[e.length-1]||e[0].eq(e[e.length-1]),s=t.pos||b(0,0),a;o?a=e[0].sub(e[e.length-2]):a=e[1].sub(e[0]);let l=a.len(),u=a.normal().scale(-r/l),m,c=e[0];if(!o)switch(t.cap){case"square":{let f=a.scale(-r/l);n.push(c.add(f).add(u)),n.push(c.add(f).sub(u));break}case"round":{let f=Math.max(r,10),y=Math.PI/f,v=u.scale(-1),A=Math.cos(y),V=Math.sin(y);for(let M=0;M<f;M++)n.push(c),n.push(c.sub(v)),v=b(v.x*A-v.y*V,v.x*V+v.y*A)}}for(let f=1;f<e.length;f++){if(c===e[f]||c.eq(e[f]))continue;m=c,c=e[f];let y=c.sub(m),v=y.len(),A=y.normal().scale(-r/v),V=a.cross(y);if(Math.abs(V)/(l*v)<.05){n.push(m.add(u)),n.push(m.sub(u)),a.dot(y)<0&&(n.push(m.sub(u)),n.push(m.add(u))),a=y,l=v,u=A;continue}let M=A.sub(u).cross(y)/V,G=u.add(a.scale(M));if(V>0){let F=m.add(G),g=Math.max(r,10),T=ce(u.angleBetween(A)/g),S=u,D=Math.cos(T),B=Math.sin(T);for(let K=0;K<g;K++)n.push(F),n.push(m.sub(S)),S=b(S.x*D-S.y*B,S.x*B+S.y*D)}else{let F=m.sub(G),g=Math.max(r,10),T=ce(u.angleBetween(A)/g),S=u,D=Math.cos(T),B=Math.sin(T);for(let K=0;K<g;K++)n.push(m.add(S)),n.push(F),S=b(S.x*D-S.y*B,S.x*B+S.y*D)}a=y,l=v,u=A}if(!o)switch(n.push(c.add(u)),n.push(c.sub(u)),t.cap){case"square":{let f=a.scale(r/l);n.push(c.add(f).add(u)),n.push(c.add(f).sub(u));break}case"round":{let f=Math.max(r,10),y=Math.PI/f,v=u.scale(1),A=Math.cos(y),V=Math.sin(y);for(let M=0;M<f;M++)v=b(v.x*A-v.y*V,v.x*V+v.y*A),n.push(c),n.push(c.sub(v))}}if(n.length<4)return;let p=n.map(f=>({pos:s.add(f),uv:b(),color:t.color||H.WHITE,opacity:t.opacity??1})),d=[],x=0;for(let f=0;f<n.length-2;f+=2)d[x++]=f+1,d[x++]=f,d[x++]=f+2,d[x++]=f+2,d[x++]=f+3,d[x++]=f+1;o&&(d[x++]=n.length-1,d[x++]=n.length-2,d[x++]=0,d[x++]=0,d[x++]=1,d[x++]=n.length-1),je(p,d,t.fixed,O.defTex,t.shader,t.uniform??void 0)}i(Fu,"_drawLinesRound");function Lu(t){let e=t.pts,n=[],r=(t.width||1)*.5,o=e[0]===e[e.length-1]||e[0].eq(e[e.length-1]),s=t.pos||b(0,0),a;o?a=e[0].sub(e[e.length-2]):a=e[1].sub(e[0]);let l=a.len(),u=a.normal().scale(-r/l),m,c=e[0];if(!o)switch(t.cap){case"square":{let f=a.scale(-r/l);n.push(c.add(f).add(u)),n.push(c.add(f).sub(u));break}case"round":{let f=Math.max(r,10),y=Math.PI/f,v=u.scale(-1),A=Math.cos(y),V=Math.sin(y);for(let M=0;M<f;M++)n.push(c),n.push(c.sub(v)),v=b(v.x*A-v.y*V,v.x*V+v.y*A)}}for(let f=1;f<e.length;f++){if(c===e[f]||c.eq(e[f]))continue;m=c,c=e[f];let y=c.sub(m),v=y.len(),A=y.normal().scale(-r/v),V=a.cross(y);if(Math.abs(V)/(l*v)<.05){n.push(m.add(u)),n.push(m.sub(u)),a.dot(y)<0&&(n.push(m.sub(u)),n.push(m.add(u))),a=y,l=v,u=A;continue}let M=A.sub(u).cross(y)/V,G=u.add(a.scale(M));n.push(m.add(G)),n.push(m.sub(G)),a=y,l=v,u=A}if(!o)switch(n.push(c.add(u)),n.push(c.sub(u)),t.cap){case"square":{let f=a.scale(r/l);n.push(c.add(f).add(u)),n.push(c.add(f).sub(u));break}case"round":{let f=Math.max(r,10),y=Math.PI/f,v=u.scale(1),A=Math.cos(y),V=Math.sin(y);for(let M=0;M<f;M++)v=b(v.x*A-v.y*V,v.x*V+v.y*A),n.push(c),n.push(c.sub(v))}}if(n.length<4)return;let p=n.map(f=>({pos:s.add(f),uv:b(),color:t.color||H.WHITE,opacity:t.opacity??1})),d=[],x=0;for(let f=0;f<n.length-2;f+=2)d[x++]=f+1,d[x++]=f,d[x++]=f+2,d[x++]=f+2,d[x++]=f+3,d[x++]=f+1;o&&(d[x++]=n.length-1,d[x++]=n.length-2,d[x++]=0,d[x++]=0,d[x++]=1,d[x++]=n.length-1),je(p,d,t.fixed,O.defTex,t.shader,t.uniform??void 0)}i(Lu,"_drawLinesMiter");function jt(t){let e=t.pts,n=t.width??1;if(!e)throw new Error('drawLines() requires property "pts".');if(!(e.length<2)){if(e.length>2)switch(t.join){case"bevel":return Bu(t);case"round":return Fu(t);case"miter":return Lu(t)}if(t.radius&&e.length>=3){Kt(Object.assign({},t,{p1:e[0],p2:e[1]}));for(let r=1;r<e.length-2;r++){let o=e[r],s=e[r+1];Kt(Object.assign({},t,{p1:o,p2:s}))}Kt(Object.assign({},t,{p1:e[e.length-2],p2:e[e.length-1]}))}else for(let r=0;r<e.length-1;r++)Kt(Object.assign({},t,{p1:e[r],p2:e[r+1]})),t.join!=="none"&&ft(Object.assign({},t,{pos:e[r],radius:n/2}))}}i(jt,"drawLines");function Kn(t,e){let n=e.segments??16,r=[];for(let o=0;o<=n;o++)r.push(t(o/n));jt({pts:r,width:e.width||1,pos:e.pos,color:e.color,opacity:e.opacity})}i(Kn,"drawCurve");function qi(t){Kn(e=>Xt(t.pt1,t.pt2,t.pt3,t.pt4,e),t)}i(qi,"drawBezier");var Me=class t{static{i(this,"Texture")}ctx;src=null;glTex;width;height;constructor(e,n,r,o={}){this.ctx=e;let s=e.gl,a=e.gl.createTexture();if(!a)throw new Error("Failed to create texture");this.glTex=a,e.onDestroy(()=>this.free()),this.width=n,this.height=r;let l={linear:s.LINEAR,nearest:s.NEAREST}[o.filter??e.opts.texFilter??"nearest"],u={repeat:s.REPEAT,clampToEdge:s.CLAMP_TO_EDGE}[o.wrap??"clampToEdge"];this.bind(),n&&r&&s.texImage2D(s.TEXTURE_2D,0,s.RGBA,n,r,0,s.RGBA,s.UNSIGNED_BYTE,null),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,l),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,l),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,u),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,u),this.unbind()}static fromImage(e,n,r={}){let o=new t(e,n.width,n.height,r);return o.update(n),o.src=n,o}update(e,n=0,r=0){let o=this.ctx.gl;this.bind(),o.texSubImage2D(o.TEXTURE_2D,0,n,r,o.RGBA,o.UNSIGNED_BYTE,e),this.unbind()}bind(){this.ctx.pushTexture2D(this.glTex)}unbind(){this.ctx.popTexture2D()}free(){this.ctx.gl.deleteTexture(this.glTex)}},at=class{static{i(this,"FrameBuffer")}ctx;tex;glFramebuffer;glRenderbuffer;constructor(e,n,r,o={}){this.ctx=e;let s=e.gl;e.onDestroy(()=>this.free()),this.tex=new Me(e,n,r,o);let a=s.createFramebuffer(),l=s.createRenderbuffer();if(!a||!l)throw new Error("Failed to create framebuffer");this.glFramebuffer=a,this.glRenderbuffer=l,this.bind(),s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,n,r),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,this.tex.glTex,0),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,this.glRenderbuffer),this.unbind()}get width(){return this.tex.width}get height(){return this.tex.height}toImageData(){let e=this.ctx.gl,n=new Uint8ClampedArray(this.width*this.height*4);this.bind(),e.readPixels(0,0,this.width,this.height,e.RGBA,e.UNSIGNED_BYTE,n),this.unbind();let r=this.width*4,o=new Uint8Array(r);for(let s=0;s<(this.height/2|0);s++){let a=s*r,l=(this.height-s-1)*r;o.set(n.subarray(a,a+r)),n.copyWithin(a,l,l+r),n.set(o,l)}return new ImageData(n,this.width,this.height)}toDataURL(){let e=document.createElement("canvas"),n=e.getContext("2d");if(e.width=this.width,e.height=this.height,!n)throw new Error("Failed to get 2d context");return n.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()}},kn=class{static{i(this,"BatchRenderer")}ctx;glVBuf;glIBuf;vqueue=[];iqueue=[];stride;maxVertices;maxIndices;vertexFormat;numDraws=0;curPrimitive=null;curTex=null;curShader=null;curUniform={};constructor(e,n,r,o){let s=e.gl;this.vertexFormat=n,this.ctx=e,this.stride=n.reduce((l,u)=>l+u.size,0),this.maxVertices=r,this.maxIndices=o;let a=s.createBuffer();if(!a)throw new Error("Failed to create vertex buffer");this.glVBuf=a,e.pushArrayBuffer(this.glVBuf),s.bufferData(s.ARRAY_BUFFER,r*4,s.DYNAMIC_DRAW),e.popArrayBuffer(),this.glIBuf=s.createBuffer(),e.pushElementArrayBuffer(this.glIBuf),s.bufferData(s.ELEMENT_ARRAY_BUFFER,o*4,s.DYNAMIC_DRAW),e.popElementArrayBuffer()}push(e,n,r,o,s=null,a={}){(e!==this.curPrimitive||s!==this.curTex||o!==this.curShader||!Pn(this.curUniform,a)||this.vqueue.length+n.length*this.stride>this.maxVertices||this.iqueue.length+r.length>this.maxIndices)&&this.flush();let l=this.vqueue.length/this.stride;for(let u of n)this.vqueue.push(u);for(let u of r)this.iqueue.push(u+l);this.curPrimitive=e,this.curShader=o,this.curTex=s,this.curUniform=a}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 Pt(t){let e=[],n=i(s=>{e.push(s),t(s)},"push"),r=i(()=>{e.pop(),t(o()??null)},"pop"),o=i(()=>e[e.length-1],"cur");return[n,r,o]}i(Pt,"genStack");function zi(t,e={}){let n=[];function r(F){n.push(F)}i(r,"onDestroy");function o(){n.forEach(g=>g());let F=t.getExtension("WEBGL_lose_context");F&&F.loseContext()}i(o,"destroy");let s=null;function a(F){if(Pn(F,s))return;s=F;let g=F.reduce((T,S)=>T+S.size,0);F.reduce((T,S,D)=>(t.vertexAttribPointer(D,S.size,t.FLOAT,!1,g*4,T),t.enableVertexAttribArray(D),T+S.size*4),0)}i(a,"setVertexFormat");let[l,u]=Pt(F=>t.bindTexture(t.TEXTURE_2D,F)),[m,c]=Pt(F=>t.bindBuffer(t.ARRAY_BUFFER,F)),[p,d]=Pt(F=>t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,F)),[x,f]=Pt(F=>t.bindFramebuffer(t.FRAMEBUFFER,F)),[y,v]=Pt(F=>t.bindRenderbuffer(t.RENDERBUFFER,F)),[A,V]=Pt(F=>{if(!F)return;let{x:g,y:T,w:S,h:D}=F;t.viewport(g,T,S,D)}),[M,G]=Pt(F=>t.useProgram(F));return A({x:0,y:0,w:t.drawingBufferWidth,h:t.drawingBufferHeight}),{gl:t,opts:e,onDestroy:r,destroy:o,pushTexture2D:l,popTexture2D:u,pushArrayBuffer:m,popArrayBuffer:c,pushElementArrayBuffer:p,popElementArrayBuffer:d,pushFramebuffer:x,popFramebuffer:f,pushRenderbuffer:y,popRenderbuffer:v,pushViewport:A,popViewport:V,pushProgram:M,popProgram:G,setVertexFormat:a}}i(zi,"initGfx");var Kr={};function $i(t,e){e.pos&&(t.pos=t.pos.add(e.pos)),e.scale&&(t.scale=t.scale.scale(b(e.scale))),e.angle&&(t.angle+=e.angle),e.color&&t.ch.length===1&&(t.color=t.color.mult(e.color)),e.opacity&&(t.opacity*=e.opacity)}i($i,"applyCharTransform");function Xi(t){let e={},n="",r=[],o=0,s=0;for(let a=0;a<t.length;a++)if(a!==o+1&&(s+=a-o),o=a,!(t[a]==="\\"&&t[a+1]==="[")){if((a===0||t[a-1]!=="\\")&&t[a]==="["){let l=a;a++;let u=t[a]==="/",m="";for(u&&a++;a<t.length&&t[a]!=="]";)m+=t[a++];if(!wi.test(m)||a>=t.length||t[a]!=="]"||u&&(r.length===0||r[r.length-1][0]!==m))a=l;else{u?r.pop():r.push([m,l]);continue}}n+=t[a],r.length>0&&(e[a-s]=r.map(([l])=>l))}if(r.length>0){for(;r.length>0;){let[a,l]=r.pop();t=t.substring(0,l)+"\\"+t.substring(l)}return Xi(t)}return{charStyleMap:e,text:n}}i(Xi,"compileStyledText");function qe(t){if(t.text===void 0)throw new Error('formatText() requires property "text".');let e=Ur(t.font);if(t.text===""||e instanceof me||!e)return{width:0,height:0,chars:[],opt:t};let{charStyleMap:n,text:r}=Xi(t.text+""),o=Xo(r);if(e instanceof Vt||typeof e=="string"){let V=e instanceof Vt?e.fontface.family:e,M=e instanceof Vt?{outline:e.outline,filter:e.filter}:{outline:null,filter:Zt},G=Kr[V]??{font:{tex:new Me(O.ggl,2048,2048,{filter:M.filter}),map:{},size:64},cursor:new w(0),outline:M.outline};Kr[V]||(Kr[V]=G),e=G.font;for(let F of o)if(!G.font.map[F]){let g=kr;if(!g)throw new Error("fontCacheC2d is not defined.");if(!gt)throw new Error("fontCacheCanvas is not defined.");g.clearRect(0,0,gt.width,gt.height),g.font=`${e.size}px ${V}`,g.textBaseline="top",g.textAlign="left",g.fillStyle="#ffffff";let T=g.measureText(F),S=Math.ceil(T.width);if(!S)continue;let D=e.size;G.outline&&G.outline.width&&G.outline.color&&(g.lineJoin="round",g.lineWidth=G.outline.width*2,g.strokeStyle=G.outline.color.toHex(),g.strokeText(F,G.outline.width,G.outline.width),S+=G.outline.width*2,D+=G.outline.width*3),g.fillText(F,G.outline?.width??0,G.outline?.width??0);let B=g.getImageData(0,0,S,D);if(G.cursor.x+S>2048&&(G.cursor.x=0,G.cursor.y+=D,G.cursor.y>2048))throw new Error("Font atlas exceeds character limit");e.tex.update(B,G.cursor.x,G.cursor.y),e.map[F]=new $(G.cursor.x,G.cursor.y,S,D),G.cursor.x+=S}}let s=t.size||e.size,a=b(t.scale??1).scale(s/e.size),l=t.lineSpacing??0,u=t.letterSpacing??0,m=0,c=0,p=0,d=[],x=[],f=0,y=null,v=0;for(;f<o.length;){let V=o[f];if(V===`
`)p+=s+l,d.push({width:m-u,chars:x}),y=null,v=0,m=0,x=[];else{let M=e.map[V];if(M){let G=M.w*a.x;t.width&&m+G>t.width&&(p+=s+l,y!=null&&(f-=x.length-y,V=o[f],M=e.map[V],G=M.w*a.x,x=x.slice(0,y-1),m=v),y=null,v=0,d.push({width:m-u,chars:x}),m=0,x=[]),x.push({tex:e.tex,width:M.w,height:M.h,quad:new $(M.x/e.tex.width,M.y/e.tex.height,M.w/e.tex.width,M.h/e.tex.height),ch:V,pos:new w(m,p),opacity:t.opacity??1,color:t.color??H.WHITE,scale:b(a),angle:0}),V===" "&&(y=x.length,v=m),m+=G,c=Math.max(c,m),m+=u}}f++}d.push({width:m-u,chars:x}),p+=s,t.width&&(c=t.width);let A=[];for(let V=0;V<d.length;V++){let M=(c-d[V].width)*ri(t.align??"left");for(let G of d[V].chars){let F=e.map[G.ch],g=A.length+V;if(G.pos=G.pos.add(M,0).add(F.w*a.x*.5,F.h*a.y*.5),t.transform){let T=typeof t.transform=="function"?t.transform(g,G.ch):t.transform;T&&$i(G,T)}if(n[g]){let T=n[g];for(let S of T){let D=t.styles?.[S],B=typeof D=="function"?D(g,G.ch):D;B&&$i(G,B)}}A.push(G)}}return{width:c,height:p,chars:A,opt:t}}i(qe,"formatText");function ut(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 e=t.width,n=t.height,o=Ne(t.anchor||dt).scale(new w(e,n).scale(-.5)),s=t.quad||new $(0,0,1,1),a=t.color||W(255,255,255),l=t.opacity??1,u=t.tex?.1/t.tex.width:0,m=t.tex?.1/t.tex.height:0,c=s.x+u,p=s.y+m,d=s.w-u*2,x=s.h-m*2;we(),ne(t.pos),Qe(t.angle),it(t.scale),ne(o),je([{pos:new w(-e/2,n/2),uv:new w(t.flipX?c+d:c,t.flipY?p:p+x),color:a,opacity:l},{pos:new w(-e/2,-n/2),uv:new w(t.flipX?c+d:c,t.flipY?p+x:p),color:a,opacity:l},{pos:new w(e/2,-n/2),uv:new w(t.flipX?c:c+d,t.flipY?p+x:p),color:a,opacity:l},{pos:new w(e/2,n/2),uv:new w(t.flipX?c:c+d,t.flipY?p:p+x),color:a,opacity:l}],[0,1,3,1,2,3],t.fixed,t.tex,t.shader,t.uniform??void 0),xe()}i(ut,"drawUVQuad");function ze(t){we(),ne(t.opt.pos),Qe(t.opt.angle),ne(Ne(t.opt.anchor??"topleft").add(1,1).scale(t.width,t.height).scale(-.5)),t.chars.forEach(e=>{ut({tex:e.tex,width:e.width,height:e.height,pos:e.pos,scale:e.scale,angle:e.angle,color:e.color,opacity:e.opacity,quad:e.quad,anchor:"center",uniform:t.opt.uniform,shader:t.opt.shader,fixed:t.opt.fixed})}),xe()}i(ze,"drawFormattedText");function Pe(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 e=t.width,n=t.height,o=Ne(t.anchor||dt).add(1,1).scale(new w(e,n).scale(-.5)),s=[new w(0,0),new w(e,0),new w(e,n),new w(0,n)];if(t.radius){let a=Math.min(e,n)/2,l=Array.isArray(t.radius)?t.radius.map(u=>Math.min(a,u)):new Array(4).fill(Math.min(a,t.radius));s=[new w(l[0],0),...l[1]?Ct(new w(e-l[1],l[1]),l[1],l[1],270,360):[b(e,0)],...l[2]?Ct(new w(e-l[2],n-l[2]),l[2],l[2],0,90):[b(e,n)],...l[3]?Ct(new w(l[3],n-l[3]),l[3],l[3],90,180):[b(0,n)],...l[0]?Ct(new w(l[0],l[0]),l[0],l[0],180,270):[]]}He(Object.assign({},t,{offset:o,pts:s,...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]]}:{}}))}i(Pe,"drawRect");function Ye(t){Te();let e=O.width,n=O.height;O.width=O.viewport.width,O.height=O.viewport.height,t(),Te(),O.width=e,O.height=n}i(Ye,"drawUnscaled");function _r(t,e){Ye(()=>{let n=b(8);we(),ne(t);let r=qe({text:e,font:Tt,size:16,pos:n,color:W(255,255,255),fixed:!0}),o=r.width+n.x*2,s=r.height+n.x*2;t.x+o>=he()&&ne(b(-o,0)),t.y+s>=ye()&&ne(b(0,-s)),Pe({width:o,height:s,color:W(0,0,0),radius:4,opacity:.8,fixed:!0}),ze(r),xe()})}i(_r,"drawInspectText");function _n(t){if(!t.p1||!t.p2||!t.p3)throw new Error('drawTriangle() requires properties "p1", "p2" and "p3".');return He(Object.assign({},t,{pts:[t.p1,t.p2,t.p3]}))}i(_n,"drawTriangle");function Ji(){if(J.inspect){let t=null;for(let e of C.root.get("*",{recursive:!0}))if(e.c("area")&&e.isHovering()){t=e;break}if(C.root.drawInspect(),t){let e=[],n=t.inspect();for(let r in n)n[r]?e.push(`${n[r]}`):e.push(`${r}`);_r(pi(Bn()),e.join(`
`))}_r(b(8),`FPS: ${J.fps()}`)}J.paused&&Ye(()=>{we(),ne(he(),0),ne(-8,8);let t=32;Pe({width:t,height:t,anchor:"topright",color:W(0,0,0),opacity:.8,radius:4,fixed:!0});for(let e=1;e<=2;e++)Pe({width:4,height:t*.6,anchor:"center",pos:b(-t/3*e,t*.5),color:W(255,255,255),radius:2,fixed:!0});xe()}),J.timeScale!==1&&Ye(()=>{we(),ne(he(),ye()),ne(-8,-8);let t=8,e=qe({text:J.timeScale.toFixed(1),font:Tt,size:16,color:W(255,255,255),pos:b(-t),anchor:"botright",fixed:!0});Pe({width:e.width+t*2+t*4,height:e.height+t*2,anchor:"botright",color:W(0,0,0),opacity:.8,radius:4,fixed:!0});for(let n=0;n<2;n++){let r=J.timeScale<1;_n({p1:b(-e.width-t*(r?2:3.5),-t),p2:b(-e.width-t*(r?2:3.5),-t-e.height),p3:b(-e.width-t*(r?3.5:2),-t-e.height/2),pos:b(-n*t*1+(r?-t*.5:0),0),color:W(255,255,255),fixed:!0})}ze(e),xe()}),J.curRecording&&Ye(()=>{we(),ne(0,ye()),ne(24,-24),ft({radius:12,color:W(255,0,0),opacity:vn(0,1,P.time()*4),fixed:!0}),xe()}),J.showLog&&C.logs.length>0&&Ye(()=>{we(),ne(0,ye()),ne(8,-8);let t=8,e=[];for(let r of C.logs){let o="",s=r.msg instanceof Error?"error":"info";o+=`[time]${r.time.toFixed(2)}[/time]`,o+=" ",o+=`[${s}]${r.msg?.toString?r.msg.toString():r.msg}[/${s}]`,e.push(o)}C.logs=C.logs.filter(r=>P.time()-r.time<(re.logTime||4));let n=qe({text:e.join(`
`),font:Tt,pos:b(t,-t),anchor:"botleft",size:16,width:he()*.6,lineSpacing:t/2,fixed:!0,styles:{time:{color:W(127,127,127)},info:{color:W(255,255,255)},error:{color:W(255,0,127)}}});Pe({width:n.width+t*2,height:n.height+t*2,anchor:"botleft",color:W(0,0,0),radius:4,opacity:.8,fixed:!0}),ze(n),xe()})}i(Ji,"drawDebug");function Zi(){let t=C.cam,e=w.fromAngle(be(0,360)).scale(t.shake);t.shake=Ee(t.shake,0,5*Ve()),t.transform=new ge().translate(Et()).scale(t.scale).rotate(t.angle).translate((t.pos??Et()).scale(-1).add(e)),C.root.draw(),Te()}i(Zi,"drawFrame");function es(){let t=Le();C.events.numListeners("loading")>0?C.events.trigger("loading",t):Ye(()=>{let e=he()/2,n=24,r=b(he()/2,ye()/2).sub(b(e/2,n/2));Pe({pos:b(0),width:he(),height:ye(),color:W(0,0,0)}),Pe({pos:r,width:e,height:n,fill:!1,outline:{width:4}}),Pe({pos:r,width:e*t,height:n})})}i(es,"drawLoadScreen");function Nn(t,e,n){let r=O.ggl.gl;Te(),r.clear(r.STENCIL_BUFFER_BIT),r.enable(r.STENCIL_TEST),r.stencilFunc(r.NEVER,1,255),r.stencilOp(r.REPLACE,r.REPLACE,r.REPLACE),e(),Te(),r.stencilFunc(n,1,255),r.stencilOp(r.KEEP,r.KEEP,r.KEEP),t(),Te(),r.disable(r.STENCIL_TEST)}i(Nn,"drawStenciled");function ts(t,e){let n=O.ggl.gl;Nn(t,e,n.EQUAL)}i(ts,"drawMasked");function Rt(t){if(!t.tex)throw new Error('drawTexture() requires property "tex".');let e=t.quad??new $(0,0,1,1),n=t.tex.width*e.w,r=t.tex.height*e.h,o=new w(1);if(t.tiled){let a=Ne(t.anchor||dt).add(new w(1,1)).scale(.5).scale(t.width||n,t.height||r),l=(t.width||n)/n,u=(t.height||r)/r,m=Math.floor(l),c=Math.floor(u),p=l-m,d=u-c,x=(m+p?1:0)*(c+d?1:0),f=new Array(x*6),y=new Array(x*4),v=0,A=i((V,M,G,F,g)=>{f[v*6+0]=v*4+0,f[v*6+1]=v*4+1,f[v*6+2]=v*4+3,f[v*6+3]=v*4+1,f[v*6+4]=v*4+2,f[v*6+5]=v*4+3,y[v*4+0]={pos:new w(V-a.x,M-a.y),uv:new w(g.x,g.y),color:t.color||H.WHITE,opacity:t.opacity||1},y[v*4+1]={pos:new w(V+G-a.x,M-a.y),uv:new w(g.x+g.w,g.y),color:t.color||H.WHITE,opacity:t.opacity||1},y[v*4+2]={pos:new w(V+G-a.x,M+F-a.y),uv:new w(g.x+g.w,g.y+g.h),color:t.color||H.WHITE,opacity:t.opacity||1},y[v*4+3]={pos:new w(V-a.x,M+F-a.y),uv:new w(g.x,g.y+g.h),color:t.color||H.WHITE,opacity:t.opacity||1},v++},"addQuad");for(let V=0;V<c;V++){for(let M=0;M<m;M++)A(M*n,V*r,n,r,e);p&&A(m*n,V*r,n*p,r,new $(e.x,e.y,e.w*p,e.h))}if(d){for(let V=0;V<m;V++)A(V*n,c*r,n,r*d,new $(e.x,e.y,e.w,e.h*d));p&&A(m*n,c*r,n*p,r*d,new $(e.x,e.y,e.w*p,e.h*d))}je(y,f,t.fixed,t.tex,t.shader,t.uniform??void 0)}else t.width&&t.height?(o.x=t.width/n,o.y=t.height/r):t.width?(o.x=t.width/n,o.y=o.x):t.height&&(o.y=t.height/r,o.x=o.y),ut(Object.assign({},t,{scale:o.scale(t.scale||new w(1)),tex:t.tex,quad:e,width:n,height:r}))}i(Rt,"drawTexture");function ns(t){if(!t.sprite)throw new Error('drawSprite() requires property "sprite"');let e=It(t.sprite);if(!e||!e.data)return;let n=e.data.frames[t.frame??0];if(!n)throw new Error(`Frame not found: ${t.frame??0}`);Rt(Object.assign({},t,{tex:e.data.tex,quad:n.scale(t.quad??new $(0,0,1,1))}))}i(ns,"drawSprite");function rs(t,e){let n=O.ggl.gl;Nn(t,e,n.NOTEQUAL)}i(rs,"drawSubtracted");function Nr(t){ze(qe(t))}i(Nr,"drawText");var os=i((t,e)=>{let n=In(e,tn,nn),r=window.devicePixelRatio||window.devicePixelRatio,o=t.scale??1,{gl:s}=e,a=Me.fromImage(e,new ImageData(new Uint8ClampedArray([255,255,255,255]),1,1)),l=t.width&&t.height?new at(e,t.width*r*o,t.height*r*o):new at(e,s.drawingBufferWidth,s.drawingBufferHeight),u=null,m=1;t.background&&(typeof t.background=="string"?u=W(t.background):(u=W(...t.background),m=t.background[3]??1),s.clearColor(u.r/255,u.g/255,u.b/255,m??1)),s.enable(s.BLEND),s.blendFuncSeparate(s.SRC_ALPHA,s.ONE_MINUS_SRC_ALPHA,s.ONE,s.ONE_MINUS_SRC_ALPHA);let c=new kn(e,en,fi,gi),p=Me.fromImage(e,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,ggl:e,defShader:n,defTex:a,frameBuffer:l,postShader:null,postShaderUniform:null,renderer:c,transform:new ge,transformStack:[],bgTex:p,bgColor:u,bgAlpha:m,width:t.width??s.drawingBufferWidth/r/o,height:t.height??s.drawingBufferHeight/r/o,viewport:{x:0,y:0,width:s.drawingBufferWidth,height:s.drawingBufferHeight},fixed:!1}},"initAppGfx");function Hn(){let t=We,e=O.ggl.gl.drawingBufferWidth/t,n=O.ggl.gl.drawingBufferHeight/t;if(re.letterbox){if(!re.width||!re.height)throw new Error("Letterboxing requires width and height defined.");let r=e/n,o=re.width/re.height;if(r>o){let s=n*o,a=(e-s)/2;O.viewport={x:a,y:0,width:s,height:n}}else{let s=e/o,a=(n-s)/2;O.viewport={x:0,y:a,width:e,height:s}}return}if(re.stretch&&(!re.width||!re.height))throw new Error("Stretching requires width and height defined.");O.viewport={x:0,y:0,width:e,height:n}}i(Hn,"updateViewport");function ct(t){return t.fixed?!0:t.parent?ct(t.parent):!1}i(ct,"isFixed");function Ke(t){return{color:t.color,opacity:t.opacity,anchor:t.anchor,outline:t.outline,shader:t.shader,uniform:t.uniform}}i(Ke,"getRenderProps");function is(t,e={}){return{id:"circle",radius:t,draw(){ft(Object.assign(Ke(this),{radius:this.radius,fill:e.fill}))},renderArea(){return new ee(new w(this.anchor?0:-this.radius),this.radius*2,this.radius*2)},inspect(){return`radius: ${Math.ceil(this.radius)}`}}}i(is,"circle");function qn(...t){return{id:"color",color:W(...t),inspect(){return`color: ${this.color.toString()}`}}}i(qn,"color");function ss(t){return{add(){this.canvas=t}}}i(ss,"drawon");function as(t=1){let e,n=0,r=!1;return{require:["opacity"],add(){e=this.opacity,this.opacity=0},update(){r||(n+=Ve(),this.opacity=De(n,0,t,0,e),n>=t&&(this.opacity=e,r=!0))}}}i(as,"fadeIn");function us(t="intersect"){return{id:"mask",mask:t}}i(us,"mask");function zn(t){return{id:"opacity",opacity:t??1,fadeIn(e=1,n=L.easings.linear){return C.root.tween(0,this.opacity,e,r=>this.opacity=r,n)},fadeOut(e=1,n=L.easings.linear){return C.root.tween(this.opacity,0,e,r=>this.opacity=r,n)},inspect(){return`opacity: ${Jt(this.opacity,1)}`}}}i(zn,"opacity");function cs(t=1,e=W(0,0,0),n=1,r="miter",o=10,s="butt"){return{id:"outline",outline:{width:t,color:e,opacity:n,join:r,miterLimit:o,cap:s},inspect(){return`outline: ${this.outline.width}px, ${this.outline.color}`}}}i(cs,"outline");var Hr=class{static{i(this,"Particle")}pos=b(0);vel=b(0);acc=b(0);angle=0;angularVelocity=0;damping=0;t;lt=null;gc;constructor(){this.t=0,this.gc=!0}get progress(){return this.lt?this.t/this.lt:this.t}};function ls(t,e){let n=e.lifetime,r=[],o=t.colors||[H.WHITE],s=t.opacities||[1],a=t.quads||[new $(0,0,1,1)],l=t.scales||[1],u=t.lifeTime,m=e.direction,c=e.spread,p=t.speed||[0,0],d=t.angle||[0,0],x=t.angularVelocity||[0,0],f=t.acceleration||[b(0),b(0)],y=t.damping||[0,0],v=[],A=new Array(t.max),V=0,M=0;for(let g=0;g<t.max;g++){v[g*6+0]=g*4+0,v[g*6+1]=g*4+1,v[g*6+2]=g*4+3,v[g*6+3]=g*4+1,v[g*6+4]=g*4+2,v[g*6+5]=g*4+3;for(let T=0;T<4;T++)A[g*4+T]={pos:new w(0,0),uv:new w(0,0),color:W(255,255,255),opacity:1};r[g]=new Hr}let G=new le;function F(g=0){for(;g<t.max;){if(r[g].gc)return g;g++}return null}return i(F,"nextFree"),{id:"particles",emit(g){let T=0;for(let S=0;S<g;S++){if(T=F(T),T==null)return;let D=be(m-c,m+c),B=w.fromAngle(D).scale(be(p[0],p[1])),K=be(d[0],d[1]),k=be(x[0],x[1]),z=b(be(f[0].x,f[1].x),be(f[0].y,f[1].y)),X=be(y[0],y[1]),te=u?be(u[0],u[1]):null,Q=e.shape?e.shape.random():b(),q=r[T];q.lt=te,q.pos=Q,q.vel=B,q.acc=z,q.angle=K,q.angularVelocity=k,q.damping=X,q.angularVelocity=k,q.gc=!1}V+=g},update(){if(n!==void 0&&n<=0)return;let g=Ve();for(let T of r)if(!T.gc){if(T.t+=g,T.lt&&T.t>=T.lt){T.gc=!0,V--;continue}T.vel=T.vel.add(T.acc.scale(g)).scale(1-T.damping*g),T.pos=T.pos.add(T.vel.scale(g)),T.angle+=T.angularVelocity*g}for(n!==void 0&&(n-=g,n<=0&&G.trigger()),M+=g;V<t.max&&e.rate&&M>e.rate;)this.emit(1),V++,M-=e.rate},draw(){if(!(n!==void 0&&n<=0)){for(let g=0;g<r.length;g++){let T=r[g];if(T.gc)continue;let S=T.progress,D=Math.floor(T.progress*o.length),B=D<o.length-1?Ee(o[D],o[D+1],De(S,D/o.length,(D+1)/o.length,0,1)):o[D],K=Math.floor(T.progress*s.length),k=K<s.length-1?Ee(s[K],s[K+1],De(S,K/s.length,(K+1)/s.length,0,1)):s[K],z=Math.floor(T.progress*a.length),X=a[z],te=Math.floor(T.progress*l.length),Q=l[te],q=Math.cos(T.angle*Math.PI/180),ae=Math.sin(T.angle*Math.PI/180),U=(t.texture?t.texture.width:10)*X.w/2,I=(t.texture?t.texture.height:10)*X.h/2,Y=g*4,j=A[Y];j.pos.x=T.pos.x+-U*Q*q- -I*Q*ae,j.pos.y=T.pos.y+-U*Q*ae+-I*Q*q,j.uv.x=X.x,j.uv.y=X.y,j.color.r=B.r,j.color.g=B.g,j.color.b=B.b,j.opacity=k,j=A[Y+1],j.pos.x=T.pos.x+U*Q*q- -I*Q*ae,j.pos.y=T.pos.y+U*Q*ae+-I*Q*q,j.uv.x=X.x+X.w,j.uv.y=X.y,j.color.r=B.r,j.color.g=B.g,j.color.b=B.b,j.opacity=k,j=A[Y+2],j.pos.x=T.pos.x+U*Q*q-I*Q*ae,j.pos.y=T.pos.y+U*Q*ae+I*Q*q,j.uv.x=X.x+X.w,j.uv.y=X.y+X.h,j.color.r=B.r,j.color.g=B.g,j.color.b=B.b,j.opacity=k,j=A[Y+3],j.pos.x=T.pos.x+-U*Q*q-I*Q*ae,j.pos.y=T.pos.y+-U*Q*ae+I*Q*q,j.uv.x=X.x,j.uv.y=X.y+X.h,j.color.r=B.r,j.color.g=B.g,j.color.b=B.b,j.opacity=k}je(A,v,this.fixed,t.texture,this.shader,this.uniform)}},onEnd(g){return G.add(g)},inspect(){return`count: ${V}/${t.max}`}}}i(ls,"particles");function ms(t,e={}){if(t.length<3)throw new Error(`Polygon's need more than two points, ${t.length} points provided`);return{id:"polygon",pts:t,colors:e.colors,uv:e.uv,tex:e.tex,radius:e.radius,draw(){He(Object.assign(Ke(this),{pts:this.pts,colors:this.colors,uv:this.uv,tex:this.tex,radius:this.radius,fill:e.fill,triangulate:e.triangulate}))},renderArea(){return new Se(this.pts)},inspect(){return`polygon: ${this.pts.map(n=>`[${n.x},${n.y}]`).join(",")}`}}}i(ms,"polygon");function Yn(t,e,n){let r;return C.root.get("area").forEach(s=>{if(n&&n.some(u=>s.is(u)))return;let l=s.worldArea().raycast(t,e);l&&(r?l.fraction<r.fraction&&(r=l,r.object=s):(r=l,r.object=s))}),r}i(Yn,"raycast");function Wn(t,e,n={}){return{id:"rect",width:t,height:e,radius:n.radius||0,draw(){Pe(Object.assign(Ke(this),{width:this.width,height:this.height,radius:this.radius,fill:n.fill}))},renderArea(){return new ee(b(0),this.width,this.height)},inspect(){return`rect: (${Math.ceil(this.width)}w, ${Math.ceil(this.height)}h)`}}}i(Wn,"rect");function ps(t,e){return{id:"shader",shader:t,...typeof e=="function"?{uniform:e(),update(){this.uniform=e()}}:{uniform:e},inspect(){return`shader: ${t}`}}}i(ps,"shader");function ds(...t){return t.length>0&&(C.cam.pos=b(...t)),C.cam.pos?C.cam.pos.clone():Et()}i(ds,"camPos");function hs(...t){return t.length>0&&(C.cam.scale=b(...t)),C.cam.scale.clone()}i(hs,"camScale");function fs(t){return t!==void 0&&(C.cam.angle=t),C.cam.angle}i(fs,"camRot");function gs(t=W(255,255,255),e=1){let n=C.root.add([Wn(he(),ye()),qn(t),zn(1),Xn()]),r=n.fadeOut(e);return r.onEnd(()=>$n(n)),r}i(gs,"camFlash");function bs(){return C.cam.transform.clone()}i(bs,"camTransform");function ys(t=12){C.cam.shake+=t}i(ys,"shake");function xs(t){return C.cam.transform.multVec2(t)}i(xs,"toScreen");function vs(t){return C.cam.transform.invert().multVec2(t)}i(vs,"toWorld");function ws(t,e){if(!e.tileWidth||!e.tileHeight)throw new Error("Must provide tileWidth and tileHeight.");let n=C.root.add([Gt(e.pos??b(0))]),r=t.length,o=0,s=null,a=null,l=null,u=null,m=i(g=>g.x+g.y*o,"tile2Hash"),c=i(g=>b(Math.floor(g%o),Math.floor(g/o)),"hash2Tile"),p=i(()=>{s=[];for(let g of n.children)d(g)},"createSpatialMap"),d=i(g=>{let T=m(g.tilePos);s[T]?s[T].push(g):s[T]=[g]},"insertIntoSpatialMap"),x=i(g=>{let T=m(g.tilePos);if(s[T]){let S=s[T].indexOf(g);S>=0&&s[T].splice(S,1)}},"removeFromSpatialMap"),f=i(()=>{let g=!1;for(let T of n.children){let S=n.pos2Tile(T.pos);(T.tilePos.x!=S.x||T.tilePos.y!=S.y)&&(g=!0,x(T),T.tilePos.x=S.x,T.tilePos.y=S.y,d(T))}g&&n.trigger("spatialMapChanged")},"updateSpatialMap"),y=i(()=>{let g=n.getSpatialMap(),T=n.numRows()*n.numColumns();a?a.length=T:a=new Array(T),a.fill(1,0,T);for(let S=0;S<g.length;S++){let D=g[S];if(D){let B=0;for(let K of D)if(K.isObstacle){B=1/0;break}else B+=K.cost;a[S]=B||1}}},"createCostMap"),v=i(()=>{let g=n.getSpatialMap(),T=n.numRows()*n.numColumns();l?l.length=T:l=new Array(T),l.fill(15,0,T);for(let S=0;S<g.length;S++){let D=g[S];if(D){let B=D.length,K=15;for(let k=0;k<B;k++)K|=D[k].edgeMask;l[S]=K}}},"createEdgeMap"),A=i(()=>{let g=n.numRows()*n.numColumns(),T=i((D,B)=>{let K=[];for(K.push(D);K.length>0;){let k=K.pop();G(k).forEach(z=>{u[z]<0&&(u[z]=B,K.push(z))})}},"traverse");u?u.length=g:u=new Array(g),u.fill(-1,0,g);let S=0;for(let D=0;D<a.length;D++){if(u[D]>=0){S++;continue}T(D,S),S++}},"createConnectivityMap"),V=i((g,T)=>a[T],"getCost"),M=i((g,T)=>{let S=c(g),D=c(T);return S.dist(D)},"getHeuristic"),G=i((g,T)=>{let S=[],D=Math.floor(g%o),B=D>0&&l[g]&1&&a[g-1]!==1/0,K=g>=o&&l[g]&2&&a[g-o]!==1/0,k=D<o-1&&l[g]&4&&a[g+1]!==1/0,z=g<o*r-o-1&&l[g]&8&&a[g+o]!==1/0;return T?(B&&(K&&S.push(g-o-1),S.push(g-1),z&&S.push(g+o-1)),K&&S.push(g-o),k&&(K&&S.push(g-o+1),S.push(g+1),z&&S.push(g+o+1)),z&&S.push(g+o)):(B&&S.push(g-1),K&&S.push(g-o),k&&S.push(g+1),z&&S.push(g+o)),S},"getNeighbours"),F={id:"level",tileWidth(){return e.tileWidth},tileHeight(){return e.tileHeight},spawn(g,...T){let S=b(...T),D=(()=>{if(typeof g=="string"){if(e.tiles[g]){if(typeof e.tiles[g]!="function")throw new Error("Level symbol def must be a function returning a component list");return e.tiles[g](S)}else if(e.wildcardTile)return e.wildcardTile(g,S)}else{if(Array.isArray(g))return g;throw new Error("Expected a symbol or a component list")}})();if(!D)return null;let B=!1,K=!1;for(let z of D)z.id==="tile"&&(K=!0),z.id==="pos"&&(B=!0);B||D.push(Gt()),K||D.push(Qn());let k=n.add(D);return B&&(k.tilePosOffset=k.pos.clone()),k.tilePos=S,s&&(d(k),this.trigger("spatialMapChanged"),this.trigger("navigationMapInvalid")),k},numColumns(){return o},numRows(){return r},levelWidth(){return o*this.tileWidth()},levelHeight(){return r*this.tileHeight()},tile2Pos(...g){return b(...g).scale(this.tileWidth(),this.tileHeight())},pos2Tile(...g){let T=b(...g);return b(Math.floor(T.x/this.tileWidth()),Math.floor(T.y/this.tileHeight()))},getSpatialMap(){return s||p(),s},onSpatialMapChanged(g){return this.on("spatialMapChanged",g)},onNavigationMapInvalid(g){return this.on("navigationMapInvalid",g)},getAt(g){s||p();let T=m(g);return s[T]||[]},raycast(g,T){let S=g.scale(1/this.tileWidth(),1/this.tileHeight()),D=Eo(S,T,B=>{let K=this.getAt(B);if(K.some(z=>z.isObstacle))return!0;let k=null;for(let z of K)if(z.is("area")){let te=z.worldArea().raycast(g,T);te&&(k?te.fraction<k.fraction&&(k=te,k.object=z):(k=te,k.object=z))}return k||!1},64);return D&&(D.point=D.point.scale(this.tileWidth(),this.tileHeight())),D},update(){s&&f()},invalidateNavigationMap(){a=null,l=null,u=null},onNavigationMapChanged(g){return this.on("navigationMapChanged",g)},getTilePath(g,T,S={}){if(a||y(),l||v(),u||A(),g.x<0||g.x>=o||g.y<0||g.y>=r||T.x<0||T.x>=o||T.y<0||T.y>=r)return null;let D=m(g),B=m(T);if(a[B]===1/0)return null;if(D===B)return[];if(u[D]!=-1&&u[D]!==u[B])return null;let K=new Ft((q,ae)=>q.cost<ae.cost);K.insert({cost:0,node:D});let k=new Map;k.set(D,D);let z=new Map;for(z.set(D,0);K.length!==0;){let q=K.remove()?.node;if(q===B)break;let ae=G(q,S.allowDiagonals);for(let U of ae){let I=(z.get(q)||0)+V(q,U)+M(U,B);(!z.has(U)||I<z.get(U))&&(z.set(U,I),K.insert({cost:I,node:U}),k.set(U,q))}}let X=[],te=B,Q=c(te);for(X.push(Q);te!==D;){let q=k.get(te);if(!q)throw new Error("Bug in pathfinding algorithm");te=q;let ae=c(te);X.push(ae)}return X.reverse()},getPath(g,T,S={}){let D=this.tileWidth(),B=this.tileHeight(),K=this.getTilePath(this.pos2Tile(g),this.pos2Tile(T),S);return K?[g,...K.slice(1,-1).map(k=>k.scale(D,B).add(D/2,B/2)),T]:null}};return n.use(F),n.onNavigationMapInvalid(()=>{n.invalidateNavigationMap(),n.trigger("navigationMapChanged")}),t.forEach((g,T)=>{let S=g.split("");o=Math.max(S.length,o),S.forEach((D,B)=>{n.spawn(D,b(B,T))})}),n}i(ws,"addLevel");function et(t,e,n){return C.objEvents.registers[t]||(C.objEvents.registers[t]=new Qt),C.objEvents.on(t,(r,...o)=>{r.is(e)&&n(r,...o)})}i(et,"on");var Cs=de(t=>{let e=C.root.add([{update:t}]);return{get paused(){return e.paused},set paused(n){e.paused=n},cancel:i(()=>e.destroy(),"cancel")}},(t,e)=>et("fixedUpdate",t,e)),Es=de(t=>{let e=C.root.add([{update:t}]);return{get paused(){return e.paused},set paused(n){e.paused=n},cancel:i(()=>e.destroy(),"cancel")}},(t,e)=>et("update",t,e)),Ts=de(t=>{let e=C.root.add([{draw:t}]);return{get paused(){return e.hidden},set paused(n){e.hidden=n},cancel:i(()=>e.destroy(),"cancel")}},(t,e)=>et("draw",t,e)),qr=de(t=>C.events.on("add",t),(t,e)=>et("add",t,e)),Os=de(t=>C.events.on("destroy",t),(t,e)=>et("destroy",t,e));function As(t,e,n){return et("collide",t,(r,o,s)=>o.is(e)&&n(r,o,s))}i(As,"onCollide");function Ss(t,e,n){return et("collideUpdate",t,(r,o,s)=>o.is(e)&&n(r,o,s))}i(Ss,"onCollideUpdate");function Vs(t,e,n){return et("collideEnd",t,(r,o,s)=>o.is(e)&&n(r,o,s))}i(Vs,"onCollideEnd");function Jn(t,e){C.root.get(t,{recursive:!0}).forEach(e),qr(t,e)}i(Jn,"forAllCurrentAndFuture");var Ps=de(t=>P.onMousePress(t),(t,e)=>{let n=[];return Jn(t,r=>{if(!r.area)throw new Error("onClick() requires the object to have area() component");n.push(r.onClick(()=>e(r)))}),Ze.join(n)});function Rs(t,e){let n=[];return Jn(t,r=>{if(!r.area)throw new Error("onHover() requires the object to have area() component");n.push(r.onHover(()=>e(r)))}),Ze.join(n)}i(Rs,"onHover");function Gs(t,e){let n=[];return Jn(t,r=>{if(!r.area)throw new Error("onHoverUpdate() requires the object to have area() component");n.push(r.onHoverUpdate(()=>e(r)))}),Ze.join(n)}i(Gs,"onHoverUpdate");function Ds(t,e){let n=[];return Jn(t,r=>{if(!r.area)throw new Error("onHoverEnd() requires the object to have area() component");n.push(r.onHoverEnd(()=>e(r)))}),Ze.join(n)}i(Ds,"onHoverEnd");function Ms(t){C.events.on("loading",t)}i(Ms,"onLoading");function Us(t){P.onResize(t)}i(Us,"onResize");function Bs(t){C.events.on("error",t)}i(Bs,"onError");function kt(t){_.loaded?t():C.events.on("load",t)}i(kt,"onLoad");function un(t=[]){let e=new Map,n=[],r={},o=new $e,s=[],a=null,l=!1,u={id:Qo(),hidden:!1,transform:new ge,children:[],parent:null,set paused(c){if(c!==l){l=c;for(let p of s)p.paused=c}},get paused(){return l},get tags(){let c=[];for(let[p,d]of e.entries())Object.keys(d).length==1&&c.push(p);return c},add(c){let p=Array.isArray(c)?un(c):c;if(p.parent)throw new Error("Cannot add a game obj that already has a parent.");return p.parent=this,p.transform=Lt(p),this.children.push(p),p.trigger("add",p),C.events.trigger("add",p),p},readd(c){let p=this.children.indexOf(c);return p!==-1&&(this.children.splice(p,1),this.children.push(c)),c},remove(c){let p=this.children.indexOf(c);if(p!==-1){c.parent=null,this.children.splice(p,1);let d=i(x=>{x.trigger("destroy"),C.events.trigger("destroy",x),x.children.forEach(f=>d(f))},"trigger");d(c)}},removeAll(c){if(c)this.get(c).forEach(p=>this.remove(p));else for(let p of[...this.children])this.remove(p)},fixedUpdate(){this.paused||(this.children.forEach(c=>c.fixedUpdate()),this.trigger("fixedUpdate"))},update(){this.paused||(this.children.forEach(c=>c.update()),this.trigger("update"))},draw(){if(this.hidden)return;this.canvas&&(Te(),this.canvas.bind());let c=O.fixed;this.fixed&&(O.fixed=!0),we(),ne(this.pos),it(this.scale),Qe(this.angle);let p=this.children.sort((d,x)=>{let f=d.layerIndex??C.defaultLayerIndex,y=x.layerIndex??C.defaultLayerIndex;return f-y||(d.z??0)-(x.z??0)});if(this.mask){let d={intersect:L.drawMasked,subtract:L.drawSubtracted}[this.mask];if(!d)throw new Error(`Invalid mask func: "${this.mask}"`);d(()=>{p.forEach(x=>x.draw())},()=>{this.trigger("draw")})}else this.trigger("draw"),p.forEach(d=>d.draw());xe(),O.fixed=c,this.canvas&&(Te(),this.canvas.unbind())},drawInspect(){this.hidden||(we(),ne(this.pos),it(this.scale),Qe(this.angle),this.children.forEach(c=>c.drawInspect()),this.trigger("drawInspect"),xe())},use(c){if(!c)return;if(Ho(c)&&(c=new c(this)),typeof c=="function")return this.use(c(this));if(typeof c=="string")return this.use({id:c});let p=[];c.id?(this.unuse(c.id),r[c.id]=[],p=r[c.id],e.set(c.id,c)):n.push(c);for(let x in c){if(xi.has(x))continue;let f=Object.getOwnPropertyDescriptor(c,x);if(f)if(typeof f.value=="function"&&(c[x]=c[x].bind(this)),f.set&&Object.defineProperty(c,x,{set:f.set.bind(this)}),f.get&&Object.defineProperty(c,x,{get:f.get.bind(this)}),vi.has(x)){let y=x==="add"?()=>{a=i(v=>p.push(v),"onCurCompCleanup"),c[x]?.(),a=null}:c[x];p.push(this.on(x,y).cancel)}else if(this[x]===void 0)Object.defineProperty(this,x,{get:i(()=>c[x],"get"),set:i(y=>c[x]=y,"set"),configurable:!0,enumerable:!0}),p.push(()=>delete this[x]);else throw new Error(`Duplicate component property: "${x}"`)}let d=i(()=>{if(c.require){for(let x of c.require)if(!this.c(x))throw new Error(`Component "${c.id}" requires component "${x}"`)}},"checkDeps");c.destroy&&p.push(c.destroy.bind(this)),this.exists()?(d(),c.add&&(a=i(x=>p.push(x),"onCurCompCleanup"),c.add.call(this),a=null)):c.require&&p.push(this.on("add",d).cancel)},unuse(c){if(e.has(c)){for(let p of e.values())if(p.require&&p.require.includes(c))throw new Error(`Can't unuse. Component "${p.id}" requires component "${c}"`);e.delete(c)}r[c]&&(r[c].forEach(p=>p()),delete r[c])},c(c){return e.get(c)??null},get(c,p={}){let d=p.recursive?this.children.flatMap(i(function x(f){return[f,...f.children.flatMap(x)]},"recurse")):this.children;if(d=d.filter(x=>c?x.is(c):!0),p.liveUpdate){let x=i(y=>p.recursive?this.isAncestorOf(y):y.parent===this,"isChild"),f=[];f.push(L.onAdd(y=>{x(y)&&y.is(c)&&d.push(y)})),f.push(L.onDestroy(y=>{if(x(y)&&y.is(c)){let v=d.findIndex(A=>A.id===y.id);v!==-1&&d.splice(v,1)}})),this.onDestroy(()=>{for(let y of f)y.cancel()})}return d},query(c){let p=c.hierarchy||"children",d=c.include,x=c.exclude,f=[];switch(p){case"children":f=this.children;break;case"siblings":f=this.parent?this.parent.children.filter(v=>v!==this):[];break;case"ancestors":let y=this.parent;for(;y;)f.push(y),y=y.parent;break;case"descendants":f=this.children.flatMap(i(function v(A){return[A,...A.children.flatMap(v)]},"recurse"));break}if(d&&((c.includeOp||"and")==="and"||!Array.isArray(c.include)?f=f.filter(v=>v.is(d)):f=f.filter(v=>c.include.some(A=>v.is(A)))),x&&((c.includeOp||"and")==="and"||!Array.isArray(c.include)?f=f.filter(v=>!v.is(x)):f=f.filter(v=>!c.exclude.some(A=>v.is(A)))),c.visible===!0&&(f=f.filter(y=>y.visible)),c.distance){if(!this.pos)throw Error("Can't do a distance query from an object without pos");let y=c.distanceOp||"near",v=c.distance*c.distance;y==="near"?f=f.filter(A=>A.pos&&this.pos.sdist(A.pos)<=v):f=f.filter(A=>A.pos&&this.pos.sdist(A.pos)>v)}return c.name&&(f=f.filter(y=>y.name===c.name)),f},isAncestorOf(c){return c.parent?c.parent===this||this.isAncestorOf(c.parent):!1},exists(){return C.root.isAncestorOf(this)},is(c){if(c==="*")return!0;if(Array.isArray(c)){for(let p of c)if(!this.c(p))return!1;return!0}else return this.c(c)!=null},on(c,p){let d=o.on(c,p.bind(this));return a&&a(()=>d.cancel()),d},trigger(c,...p){o.trigger(c,...p),C.objEvents.trigger(c,this,...p)},destroy(){this.parent&&this.parent.remove(this)},inspect(){let c={};for(let[p,d]of e)c[p]=d.inspect?.()??null;for(let[p,d]of n.entries()){if(d.inspect){c[p]=d.inspect();continue}for(let[x,f]of Object.entries(d))typeof f!="function"&&(c[x]=`${x}: ${f}`)}return c},onAdd(c){return this.on("add",c)},onFixedUpdate(c){return this.on("fixedUpdate",c)},onUpdate(c){return this.on("update",c)},onDraw(c){return this.on("draw",c)},onDestroy(c){return this.on("destroy",c)},clearEvents(){o.clear()}},m=["onKeyPress","onKeyPressRepeat","onKeyDown","onKeyRelease","onMousePress","onMouseDown","onMouseRelease","onMouseMove","onCharInput","onMouseMove","onTouchStart","onTouchMove","onTouchEnd","onScroll","onGamepadButtonPress","onGamepadButtonDown","onGamepadButtonRelease","onGamepadStick","onButtonPress","onButtonDown","onButtonRelease"];for(let c of m)u[c]=(...p)=>{let d=P[c]?.(...p);return s.push(d),u.onDestroy(()=>d.cancel()),d};for(let c of t)u.use(c);return u}i(un,"make");var Fs=i(()=>({events:new $e,objEvents:new $e,root:un([]),gravity:null,scenes:{},currentScene:null,layers:null,defaultLayerIndex:0,logs:[],cam:{pos:null,scale:new w(1),angle:0,shake:0,transform:new ge}}),"initGame");function Ls(t){C.gravity=t?(C.gravity||b(0,1)).unit().scale(t):null}i(Ls,"setGravity");function Is(){return C.gravity?C.gravity.len():0}i(Is,"getGravity");function js(t){C.gravity=t.unit().scale(C.gravity?C.gravity.len():1)}i(js,"setGravityDirection");function zr(){return C.gravity?C.gravity.unit():b(0,1)}i(zr,"getGravityDirection");var Ks=ao("SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4Ljc2LjEwMAAAAAAAAAAAAAAA//tQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAASAAAeMwAUFBQUFCIiIiIiIjAwMDAwPj4+Pj4+TExMTExZWVlZWVlnZ2dnZ3V1dXV1dYODg4ODkZGRkZGRn5+fn5+frKysrKy6urq6urrIyMjIyNbW1tbW1uTk5OTk8vLy8vLy//////8AAAAATGF2YzU4LjEzAAAAAAAAAAAAAAAAJAQKAAAAAAAAHjOZTf9/AAAAAAAAAAAAAAAAAAAAAP/7kGQAAANUMEoFPeACNQV40KEYABEY41g5vAAA9RjpZxRwAImU+W8eshaFpAQgALAAYALATx/nYDYCMJ0HITQYYA7AH4c7MoGsnCMU5pnW+OQnBcDrQ9Xx7w37/D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VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV");var ks=i(()=>(()=>{let e=new(window.AudioContext||window.webkitAudioContext),n=e.createGain();n.connect(e.destination);let r=new st(oi(e));return e.decodeAudioData(Ks.buffer.slice(0)).then(o=>{r.buf=o}).catch(o=>{console.error("Failed to load burp: ",o)}),{ctx:e,masterNode:n,burpSnd:r}})(),"initAudio");function _s(t,e={}){let n=new le,r=new Audio(t);oe.ctx.createMediaElementSource(r).connect(oe.masterNode);function s(){J.paused||P.isHidden()&&!re.backgroundAudio||oe.ctx.resume()}i(s,"resumeAudioCtx");function a(){s(),r.play()}return i(a,"play"),e.paused||a(),r.onended=()=>n.trigger(),{play(){a()},seek(l){r.currentTime=l},stop(){r.pause(),this.seek(0)},set loop(l){r.loop=l},get loop(){return r.loop},set paused(l){l?r.pause():a()},get paused(){return r.paused},time(){return r.currentTime},duration(){return r.duration},set volume(l){r.volume=Be(l,0,1)},get volume(){return r.volume},set speed(l){r.playbackRate=Math.max(l,0)},get speed(){return r.playbackRate},set detune(l){},get detune(){return 0},onEnd(l){return n.add(l)},then(l){return this.onEnd(l)}}}i(_s,"playMusic");function Zn(t,e={}){if(typeof t=="string"&&_.music[t])return _s(_.music[t],e);let n=oe.ctx,r=e.paused??!1,o=n.createBufferSource(),s=new le,a=n.createGain(),l=e.seek??0,u=0,m=0,c=!1;o.loop=!!e.loop,o.detune.value=e.detune??0,o.playbackRate.value=e.speed??1,o.connect(a),o.onended=()=>{x()>=(o.buffer?.duration??Number.POSITIVE_INFINITY)&&s.trigger()},a.connect(oe.masterNode),a.gain.value=e.volume??1;let p=i(y=>{o.buffer=y.buf,r||(u=n.currentTime,o.start(0,l),c=!0)},"start"),d=_i(t);d instanceof me&&d.onLoad(p);let x=i(()=>{if(!o.buffer)return 0;let y=r?m-u:n.currentTime-u,v=o.buffer.duration;return o.loop?y%v:Math.min(y,v)},"getTime"),f=i(y=>{let v=n.createBufferSource();return v.buffer=y.buffer,v.loop=y.loop,v.playbackRate.value=y.playbackRate.value,v.detune.value=y.detune.value,v.onended=y.onended,v.connect(a),v},"cloneNode");return{stop(){this.paused=!0,this.seek(0)},set paused(y){if(r!==y)if(r=y,y)c&&(o.stop(),c=!1),m=n.currentTime;else{o=f(o);let v=m-u;o.start(0,v),c=!0,u=n.currentTime-v,m=0}},get paused(){return r},play(y=0){this.seek(y),this.paused=!1},seek(y){o.buffer?.duration&&(y>o.buffer.duration||(r?(o=f(o),u=m-y):(o.stop(),o=f(o),u=n.currentTime-y,o.start(0,y),c=!0,m=0)))},set speed(y){o.playbackRate.value=y},get speed(){return o.playbackRate.value},set detune(y){o.detune.value=y},get detune(){return o.detune.value},set volume(y){a.gain.value=Math.max(y,0)},get volume(){return a.gain.value},set loop(y){o.loop=y},get loop(){return o.loop},duration(){return o.buffer?.duration??0},time(){return x()%this.duration()},onEnd(y){return s.add(y)},then(y){return this.onEnd(y)}}}i(Zn,"play");function er(t){return Zn(oe.burpSnd,t)}i(er,"burp");function Ns(t){return t!==void 0&&(oe.masterNode.gain.value=t),oe.masterNode.gain.value}i(Ns,"volume");function tr(){P.onHide(()=>{re.backgroundAudio||oe.ctx.suspend()}),P.onShow(()=>{!re.backgroundAudio&&!J.paused&&oe.ctx.resume()}),P.onResize(()=>{if(P.isFullscreen())return;let t=re.width&&re.height;t&&!re.stretch&&!re.letterbox||(ve.width=ve.offsetWidth*We,ve.height=ve.offsetHeight*We,Hn(),t||(O.frameBuffer.free(),O.frameBuffer=new at(O.ggl,O.ggl.gl.drawingBufferWidth,O.ggl.gl.drawingBufferHeight),O.width=O.ggl.gl.drawingBufferWidth/We/_t,O.height=O.ggl.gl.drawingBufferHeight/We/_t))}),re.debug!==!1&&(P.onKeyPress(re.debugKey??"f1",()=>J.inspect=!J.inspect),P.onKeyPress("f2",()=>J.clearLog()),P.onKeyPress("f8",()=>J.paused=!J.paused),P.onKeyPress("f7",()=>{J.timeScale=Jt(Be(J.timeScale-.2,0,2),1)}),P.onKeyPress("f9",()=>{J.timeScale=Jt(Be(J.timeScale+.2,0,2),1)}),P.onKeyPress("f10",()=>J.stepFrame())),re.burp&&P.onKeyPress("b",()=>er())}i(tr,"initEvents");function Hs(t,e={}){let n=C.root.add([Gt(t),nr()]),r=(e.speed||1)*5,o=e.scale||1;n.add([cn($r),Nt(0),ln("center"),Yr(r,o),...e.comps??[]]);let s=n.add([cn(Wr),Nt(0),ln("center"),mn(),...e.comps??[]]);return s.wait(.4/r,()=>s.use(Yr(r,o))),s.onDestroy(()=>n.destroy()),n}i(Hs,"addKaboom");var qs=i(function(t,e){if(C.layers)throw Error("Layers can only be assigned once.");let n=t.indexOf(e);if(n==-1)throw Error("The default layer name should be present in the layers list.");C.layers=t,C.defaultLayerIndex=n},"layers");function $n(t){t.destroy()}i($n,"destroy");function zs(){return C.root}i(zs,"getTreeRoot");function Ys(t,e){C.scenes[t]=e}i(Ys,"scene");function Ws(t,...e){if(!C.scenes[t])throw new Error(`Scene not found: ${t}`);C.events.onOnce("frameEnd",()=>{C.events.trigger("sceneLeave",t),P.events.clear(),C.events.clear(),C.objEvents.clear(),[...C.root.children].forEach(n=>{(!n.stay||n.scenesToStay&&!n.scenesToStay.includes(t))&&C.root.remove(n)}),C.root.clearEvents(),tr(),C.cam={pos:null,scale:b(1),angle:0,shake:0,transform:new ge},C.scenes[t](...e)}),C.currentScene=t}i(Ws,"go");function $s(t){return C.events.on("sceneLeave",t)}i($s,"onSceneLeave");function Xs(){return C.currentScene}i(Xs,"getSceneName");function cn(t,e={}){let n=null,r=null,o=null,s=new le;if(!t)throw new Error("Please pass the resource name or data to sprite()");let a=i((u,m,c,p)=>{let d=b(1,1);return c&&p?(d.x=c/(u.width*m.w),d.y=p/(u.height*m.h)):c?(d.x=c/(u.width*m.w),d.y=d.x):p&&(d.y=p/(u.height*m.h),d.x=d.y),d},"calcTexScale"),l=i((u,m)=>{if(!m)return;let c=m.frames[0].clone();e.quad&&(c=c.scale(e.quad));let p=a(m.tex,c,e.width,e.height);u.width=m.tex.width*c.w*p.x,u.height=m.tex.height*c.h*p.y,e.anim&&u.play(e.anim),n=m,s.trigger(n)},"setSpriteData");return{id:"sprite",width:0,height:0,frame:e.frame||0,quad:e.quad||new $(0,0,1,1),animSpeed:e.animSpeed??1,flipX:e.flipX??!1,flipY:e.flipY??!1,get sprite(){return t.toString()},set sprite(u){let m=It(u);m&&m.onLoad(c=>l(this,c))},draw(){if(!n)return;let u=n.frames[this.frame??0];if(!u)throw new Error(`Frame not found: ${this.frame??0}`);if(n.slice9){let{left:m,right:c,top:p,bottom:d}=n.slice9,x=n.tex.width*u.w,f=n.tex.height*u.h,y=this.width-m-c,v=this.height-p-d,A=m/x,V=c/x,M=1-A-V,G=p/f,F=d/f,g=1-G-F,T=[pe(0,0,A,G),pe(A,0,M,G),pe(A+M,0,V,G),pe(0,G,A,g),pe(A,G,M,g),pe(A+M,G,V,g),pe(0,G+g,A,F),pe(A,G+g,M,F),pe(A+M,G+g,V,F),pe(0,0,m,p),pe(m,0,y,p),pe(m+y,0,c,p),pe(0,p,m,v),pe(m,p,y,v),pe(m+y,p,c,v),pe(0,p+v,m,d),pe(m,p+v,y,d),pe(m+y,p+v,c,d)];for(let S=0;S<9;S++){let D=T[S],B=T[S+9];Rt(Object.assign(Ke(this),{pos:B.pos(),tex:n.tex,quad:u.scale(D),flipX:this.flipX,flipY:this.flipY,tiled:e.tiled,width:B.w,height:B.h}))}}else Rt(Object.assign(Ke(this),{tex:n.tex,quad:u.scale(this.quad??new $(0,0,1,1)),flipX:this.flipX,flipY:this.flipY,tiled:e.tiled,width:this.width,height:this.height}))},add(){let u=It(t);u?u.onLoad(m=>l(this,m)):kt(()=>l(this,It(t).data))},update(){if(!n||!r||o===null)return;let u=n.anims[r.name];if(typeof u=="number"){this.frame=u;return}if(u.speed===0)throw new Error("Sprite anim speed cannot be 0");r.timer+=Ve()*this.animSpeed,r.timer>=1/r.speed&&(r.timer=0,this.frame+=o,(this.frame<Math.min(u.from,u.to)||this.frame>Math.max(u.from,u.to))&&(r.loop?r.pingpong?(this.frame-=o,o*=-1,this.frame+=o):this.frame=u.from:r.pingpong?o===Math.sign(u.to-u.from)?(this.frame=u.to,o*=-1,this.frame+=o):(this.frame=u.from,r.onEnd(),this.stop()):(this.frame=u.to,r.onEnd(),this.stop())))},play(u,m={}){if(!n){s.add(()=>this.play(u,m));return}let c=n.anims[u];if(c===void 0)throw new Error(`Anim not found: ${u}`);r&&this.stop(),r=typeof c=="number"?{name:u,timer:0,loop:!1,pingpong:!1,speed:0,onEnd:i(()=>{},"onEnd")}:{name:u,timer:0,loop:m.loop??c.loop??!1,pingpong:m.pingpong??c.pingpong??!1,speed:m.speed??c.speed??10,onEnd:m.onEnd??(()=>{})},o=typeof c=="number"?null:c.from<c.to?1:-1,this.frame=typeof c=="number"?c:c.from,this.trigger("animStart",u)},stop(){if(!r)return;let u=r.name;r=null,this.trigger("animEnd",u)},numFrames(){return n?.frames.length??0},getCurAnim(){return r},curAnim(){return r?.name},getAnim(u){return n?.anims[u]??null},hasAnim(u){return!!this.getAnim(u)},onAnimEnd(u){return this.on("animEnd",u)},onAnimStart(u){return this.on("animStart",u)},renderArea(){return new ee(b(0),this.width,this.height)},inspect(){return typeof t=="string"?`sprite: "${t}"`:null}}}i(cn,"sprite");function Qs(t,e={}){function n(o){let s=qe(Object.assign(Ke(o),{text:o.text+"",size:o.textSize,font:o.font,width:e.width&&o.width,align:o.align,letterSpacing:o.letterSpacing,lineSpacing:o.lineSpacing,transform:o.textTransform,styles:o.textStyles}));return e.width||(o.width=s.width/(o.scale?.x||1)),o.height=s.height/(o.scale?.y||1),s}i(n,"update");let r={id:"text",set text(o){t=o,n(this)},get text(){return t},textSize:e.size??36,font:e.font,width:e.width??0,height:0,align:e.align,lineSpacing:e.lineSpacing,letterSpacing:e.letterSpacing,textTransform:e.transform,textStyles:e.styles,add(){kt(()=>n(this))},draw(){ze(n(this))},renderArea(){return new ee(b(0),this.width,this.height)}};return n(r),r}i(Qs,"text");function Js(t,e){return{id:"rect",width:t,height:e,draw(){ut(Object.assign(Ke(this),{width:this.width,height:this.height}))},renderArea(){return new ee(b(0),this.width,this.height)},inspect(){return`uvquad: (${Math.ceil(this.width)}w, ${Math.ceil(this.height)})h`}}}i(Js,"uvquad");function Zs(t={}){let e=null,n=null,r=null,o=null;return{id:"agent",require:["pos","tile"],agentSpeed:t.speed??100,allowDiagonals:t.allowDiagonals??!0,getDistanceToTarget(){return e?this.pos.dist(e):0},getNextLocation(){return n&&r?n[r]:null},getPath(){return n?n.slice():null},getTarget(){return e},isNavigationFinished(){return n?r===null:!0},isTargetReachable(){return n!==null},isTargetReached(){return e?this.pos.eq(e):!0},setTarget(s){e=s,n=this.getLevel().getPath(this.pos,e,{allowDiagonals:this.allowDiagonals}),r=n?0:null,n&&r!==null?(o||(o=this.getLevel().onNavigationMapChanged(()=>{e&&n&&r!==null&&(n=this.getLevel().getPath(this.pos,e,{allowDiagonals:this.allowDiagonals}),n?(r=0,this.trigger("navigationNext",this,n[r])):(r=null,this.trigger("navigationEnded",this)))}),this.onDestroy(()=>o?.cancel())),this.trigger("navigationStarted",this),this.trigger("navigationNext",this,n[r])):this.trigger("navigationEnded",this)},update(){if(e&&n&&r!==null){if(this.pos.sdist(n[r])<2)if(r===n.length-1){this.pos=e.clone(),r=null,this.trigger("navigationEnded",this),this.trigger("targetReached",this);return}else r++,this.trigger("navigationNext",this,n[r]);this.moveTo(n[r],this.agentSpeed)}},onNavigationStarted(s){return this.on("navigationStarted",s)},onNavigationNext(s){return this.on("navigationNext",s)},onNavigationEnded(s){return this.on("navigationEnded",s)},onTargetReached(s){return this.on("targetReached",s)},inspect(){return"agent: "+JSON.stringify({target:JSON.stringify(e),path:JSON.stringify(n)})}}}i(Zs,"agent");function ea(t){let e=t.graph;return{id:"navigator",require:["pos"],navigateTo(n){return this.graph?.getWaypointPath(this.pos,n,t.navigationOpt)},get graph(){if(e)return e;let n=this.parent;for(;n;){if(n.is("navigatormap"))return n.graph;n=n.parent}},set graph(n){e=n}}}i(ea,"navigation");function ta(t={}){let e=t.waypoints,n=t.speed||100,r=t.endBehavior||"stop",o=0,s=e!=null;return{id:"patrol",require:["pos"],get patrolSpeed(){return n},set patrolSpeed(a){n=a},get waypoints(){return e},set waypoints(a){e=a,o=0,s=!1},get nextLocation(){return e?e[o]:void 0},update(){let a=this.nextLocation;if(!(!e||!a||s)&&(this.moveTo(a,n),this.pos.sdist(a)<9))switch(r){case"loop":o=(o+1)%e.length;break;case"ping-pong":o=o+1,o==e.length&&(e.reverse(),o=0);break;case"stop":o=Math.min(o+1,e.length-1),o==e.length-1&&(s=!0,this.trigger("patrolFinished"));break}},onPatrolFinished(a){return this.on("patrolFinished",a)}}}i(ta,"patrol");function na(t,e={}){let n=typeof t=="function"?t:()=>C.root.query(t),r=e.checkFrequency||1,o=typeof e.direction=="number"?w.fromAngle(e.direction):e.direction,s=0;return{id:"sentry",require:["pos"],direction:typeof e.direction=="number"?w.fromAngle(e.direction):e.direction,spotted:[],set directionAngle(a){this.direction=a!==void 0?w.fromAngle(a):void 0},get directionAngle(){return this.direction?this.direction.angle():void 0},fieldOfView:e.fieldOfView||200,isWithinFieldOfView(a,l,u){let m=(typeof l=="number"?w.fromAngle(l):l)||o,c=u||e.fieldOfView;if(!m||!c||c>=360)return!0;let p=c/2;return a.pos&&m.angleBetween(a.pos.sub(this.pos))<=p},hasLineOfSight(a){let l=Yn(this.pos,a.pos.sub(this.pos),e.raycastExclude);return l!=null&&l.object===a},update(){if(s+=Ve(),s>r){s-=r;let a=n();if(a.length&&o&&this.fieldOfView&&this.fieldOfView<360){let l=this.fieldOfView/2;a=a.filter(u=>u.pos&&o.angleBetween(u.pos.sub(this.pos))<=l)}a.length&&e.lineOfSight&&(a=a.filter(l=>l.pos&&this.hasLineOfSight(l))),a.length>0&&(this.spotted=a,this.trigger("objectSpotted",a))}},onObjectsSpotted(a){return this.on("objectSpotted",a)}}}i(na,"sentry");function Qn(t={}){let e=b(0),n=t.isObstacle??!1,r=t.cost??0,o=t.edges??[],s=i(()=>{let l={left:1,top:2,right:4,bottom:8};return o.map(u=>l[u]||0).reduce((u,m)=>u|m,0)},"getEdgeMask"),a=s();return{id:"tile",tilePosOffset:t.offset??b(0),set tilePos(l){let u=this.getLevel();e=l.clone(),this.pos=b(this.tilePos.x*u.tileWidth(),this.tilePos.y*u.tileHeight()).add(this.tilePosOffset)},get tilePos(){return e},set isObstacle(l){n!==l&&(n=l,this.getLevel().invalidateNavigationMap())},get isObstacle(){return n},set cost(l){r!==l&&(r=l,this.getLevel().invalidateNavigationMap())},get cost(){return r},set edges(l){o=l,a=s(),this.getLevel().invalidateNavigationMap()},get edges(){return o},get edgeMask(){return a},getLevel(){return this.parent},moveLeft(){this.tilePos=this.tilePos.add(b(-1,0))},moveRight(){this.tilePos=this.tilePos.add(b(1,0))},moveUp(){this.tilePos=this.tilePos.add(b(0,-1))},moveDown(){this.tilePos=this.tilePos.add(b(0,1))}}}i(Qn,"tile");var pn=class{static{i(this,"AnimateChannel")}name;duration;loops;direction;easing;interpolation;isFinished;timing;easings;relative;constructor(e,n,r){this.name=e,this.duration=n.duration,this.loops=n.loops||0,this.direction=n.direction||"forward",this.easing=n.easing||ot.linear,this.interpolation=n.interpolation||"linear",this.isFinished=!1,this.timing=n.timing,this.easings=n.easings,this.relative=r}update(e,n){return!0}getLowerKeyIndexAndRelativeTime(e,n,r){let o=n-1,s=e/this.duration;if(this.loops!==0&&s>=this.loops)return[o,0];let a=Math.trunc(s);if(s-=a,(this.direction=="reverse"||this.direction=="ping-pong"&&a&1)&&(s=1-s),r){let l=0;for(;r[l+1]!==void 0&&r[l+1]<s;)l++;return l>=o?[o,0]:[l,(s-r[l])/(r[l+1]-r[l])]}else{let l=Math.floor((n-1)*s);return[l,(s-l/o)*o]}}setValue(e,n,r){if(this.relative)switch(n){case"pos":e.pos=e.base.pos.add(r);break;case"angle":e.angle=e.base.angle+r;break;case"scale":e.scale=e.base.scale.scale(r);break;case"opacity":e.opacity=e.base.opacity*r;break;default:e[n]=r}else e[n]=r}serialize(){let e={duration:this.duration,keys:[]};return this.loops&&(e.loops=this.loops),this.direction!=="forward"&&(e.direction=this.direction),this.easing!=ot.linear&&(e.easing=this.easing.name),this.interpolation!=="linear"&&(e.interpolation=this.interpolation),this.timing&&(e.timing=this.timing),this.easings&&(e.easings=this.easings.map(n=>this.easing.name)),e}};function ra(t,e){return e.add(e.sub(t))}i(ra,"reflect");var Xr=class extends pn{static{i(this,"AnimateChannelNumber")}keys;constructor(e,n,r,o){super(e,r,o),this.keys=n}update(e,n){let[r,o]=this.getLowerKeyIndexAndRelativeTime(n,this.keys.length,this.timing);if(o==0||this.interpolation==="none")this.setValue(e,this.name,this.keys[r]);else{let s=this.easings?this.easings[r]:this.easing;this.setValue(e,this.name,Ee(this.keys[r],this.keys[r+1],s(o)))}return o==1}serialize(){return Object.assign(super.serialize(),{keys:this.keys})}},Qr=class extends pn{static{i(this,"AnimateChannelVec2")}keys;curves;dcurves;constructor(e,n,r,o,s){if(super(e,r,o),this.keys=n,this.interpolation==="spline"){this.curves=[],s&&(this.dcurves=[]);for(let a=0;a<this.keys.length-1;a++){let l=this.keys[a],u=a+1,m=this.keys[u],c=a>0?this.keys[a-1]:ra(m,l),p=u<this.keys.length-1?this.keys[u+1]:ra(l,m);this.curves.push(Bt(c,l,m,p)),s&&this.dcurves?.push(Bt(c,l,m,p,Uo))}}}update(e,n){let[r,o]=this.getLowerKeyIndexAndRelativeTime(n,this.keys.length,this.timing);if(o==0||this.interpolation==="none")this.setValue(e,this.name,this.keys[r]);else{let s=this.easings?this.easings[r]:this.easing;switch(this.interpolation){case"linear":this.setValue(e,this.name,this.keys[r].lerp(this.keys[r+1],s(o)));break;case"slerp":this.setValue(e,this.name,this.keys[r].slerp(this.keys[r+1],s(o)));break;case"spline":if(this.curves){this.setValue(e,this.name,this.curves[r](s(o))),this.dcurves&&this.setValue(e,"angle",this.dcurves[r](s(o)).angle());break}}}return o==1}serialize(){return Object.assign(super.serialize(),{keys:this.keys.map(e=>[e.x,e.y])})}},Jr=class extends pn{static{i(this,"AnimateChannelColor")}keys;constructor(e,n,r,o){super(e,r,o),this.keys=n}update(e,n){let[r,o]=this.getLowerKeyIndexAndRelativeTime(n,this.keys.length,this.timing);if(o==0||this.interpolation=="none")this.setValue(e,this.name,this.keys[r]);else{let s=this.easings?this.easings[r]:this.easing;this.setValue(e,this.name,this.keys[r].lerp(this.keys[r+1],s(o)))}return o==1}serialize(){return Object.assign(super.serialize(),{keys:this.keys})}};function oa(t={}){let e=[],n=0,r=!1;return{id:"animate",require:t.followMotion?["rotate"]:void 0,base:{pos:b(0,0),angle:0,scale:b(1,1),opacity:1},add(){t.relative&&(this.is("pos")&&(this.base.pos=this.pos.clone()),this.is("rotate")&&(this.base.angle=this.angle),this.is("scale")&&(this.base.scale=this.scale),this.is("opacity")&&(this.base.opacity=this.opacity))},update(){let o=!0,s;n+=Ve();for(let a of e)s=a.update(this,n),s&&!a.isFinished&&(a.isFinished=!0,this.trigger("animateChannelFinished",a.name)),o&&=s;o&&!r&&(r=!0,this.trigger("animateFinished"))},animate(o,s,a){r=!1,this.unanimate(o),typeof s[0]=="number"?e.push(new Xr(o,s,a,t.relative||!1)):s[0]instanceof w?e.push(new Qr(o,s,a,t.relative||!1,o==="pos"&&(t.followMotion||!1))):s[0]instanceof H&&e.push(new Jr(o,s,a,t.relative||!1))},unanimate(o){let s=e.findIndex(a=>a.name===o);s>=0&&e.splice(s,1)},unanimateAll(){e.splice(0,e.length)},onAnimateFinished(o){return this.on("animateFinished",o)},onAnimateChannelFinished(o){return this.on("animateChannelFinished",o)},serializeAnimationChannels(){return e.reduce((o,s)=>(o[s.name]=s.serialize(),o),{})},serializeAnimationOptions(){let o={};return t.followMotion&&(o.followMotion=!0),t.relative&&(o.relative=!0),o}}}i(oa,"animate");function Zr(t,e){let n={name:t.name};return t.is("animate")&&(n.channels=t.serializeAnimationChannels(),Object.assign(n,t.serializeAnimationOptions())),t.children.length>0&&(n.children=t.children.filter(r=>r.is("named")).map(r=>Zr(r,r.name))),n}i(Zr,"serializeAnimation");function Yr(t=2,e=1){let n=0;return{require:["scale"],update(){let r=Math.sin(n*t)*e;r<0&&this.destroy(),this.scale=b(r),n+=Ve()}}}i(Yr,"boom");function ia(t,e){if(t==null)throw new Error("health() requires the initial amount of hp");return{id:"health",hurt(n=1){this.setHP(t-n),this.trigger("hurt",n)},heal(n=1){let r=t;this.setHP(t+n),this.trigger("heal",t-r)},hp(){return t},maxHP(){return e??null},setMaxHP(n){e=n},setHP(n){t=e?Math.min(e,n):n,t<=0&&this.trigger("death")},onHurt(n){return this.on("hurt",n)},onHeal(n){return this.on("heal",n)},onDeath(n){return this.on("death",n)},inspect(){return`health: ${t}`}}}i(ia,"health");function sa(t,e={}){if(t==null)throw new Error("lifespan() requires time");let n=e.fade??0;return{id:"lifespan",require:["opacity"],async add(){await C.root.wait(t),this.opacity=this.opacity??1,n>0&&await C.root.tween(this.opacity,0,n,r=>this.opacity=r,ot.linear),this.destroy()}}}i(sa,"lifespan");function aa(t){return{id:"named",name:t}}i(aa,"named");function ua(t,e,n){if(!t)throw new Error("state() requires an initial state");let r={};function o(u){r[u]||(r[u]={enter:new le,end:new le,update:new le,draw:new le})}i(o,"initStateEvents");function s(u,m,c){return o(m),r[m][u].add(c)}i(s,"on");function a(u,m,...c){o(m),r[m][u].trigger(...c)}i(a,"trigger");let l=!1;return{id:"state",state:t,enterState(u,...m){if(l=!0,e&&!e.includes(u))throw new Error(`State not found: ${u}`);let c=this.state;if(n){if(!n?.[c])return;let p=typeof n[c]=="string"?[n[c]]:n[c];if(!p.includes(u))throw new Error(`Cannot transition state from "${c}" to "${u}". Available transitions: ${p.map(d=>`"${d}"`).join(", ")}`)}a("end",c,...m),this.state=u,a("enter",u,...m),a("enter",`${c} -> ${u}`,...m)},onStateTransition(u,m,c){return s("enter",`${u} -> ${m}`,c)},onStateEnter(u,m){return s("enter",u,m)},onStateUpdate(u,m){return s("update",u,m)},onStateDraw(u,m){return s("draw",u,m)},onStateEnd(u,m){return s("end",u,m)},update(){l||(a("enter",t),l=!0),a("update",this.state)},draw(){a("draw",this.state)},inspect(){return`state: ${this.state}`}}}i(ua,"state");function nr(t){return{id:"stay",stay:!0,scenesToStay:t}}i(nr,"stay");function ca(t=!0,e){let n,r;return{id:"textInput",hasFocus:t,require:["text"],add(){n=L.onCharInput(o=>{this.hasFocus&&(!e||this.text.length<e)&&(L.isKeyDown("shift")?this.text+=o.toUpperCase():this.text+=o)}),r=L.onKeyPress("backspace",()=>{this.hasFocus&&(this.text=this.text.slice(0,-1))})},destroy(){n.cancel(),r.cancel()}}}i(ca,"textInput");function mn(){return{id:"timer",wait(t,e){let n=[];e&&n.push(e);let r=0,o=this.onUpdate(()=>{r+=L.dt(),r>=t&&(n.forEach(s=>s()),o.cancel())});return{get paused(){return o.paused},set paused(s){o.paused=s},cancel:o.cancel,onEnd(s){n.push(s)},then(s){return this.onEnd(s),this}}},loop(t,e){let n=null,r=i(()=>{n=this.wait(t,r),e()},"newAction");return n=this.wait(0,r),{get paused(){return n?.paused??!1},set paused(o){n&&(n.paused=o)},cancel:i(()=>n?.cancel(),"cancel")}},tween(t,e,n,r,o=ot.linear){let s=0,a=[],l=this.onUpdate(()=>{s+=L.dt();let u=Math.min(s/n,1);r(Ee(t,e,o(u))),u===1&&(l.cancel(),r(e),a.forEach(m=>m()))});return{get paused(){return l.paused},set paused(u){l.paused=u},onEnd(u){a.push(u)},then(u){return this.onEnd(u),this},cancel(){l.cancel()},finish(){l.cancel(),r(e),a.forEach(u=>u())}}}}}i(mn,"timer");var eo=0;function la(){return eo>0}i(la,"usesArea");function ma(t={}){let e={},n=new Set;return{id:"area",collisionIgnore:t.collisionIgnore??[],add(){eo++,this.area.cursor&&this.onHover(()=>P.setCursor(this.area.cursor)),this.onCollideUpdate((r,o)=>{if(!r.id)throw new Error("area() requires the object to have an id");e[r.id]||this.trigger("collide",r,o),o&&(e[r.id]=o,n.add(r.id))})},destroy(){eo--},update(){for(let r in e)n.has(Number(r))||(this.trigger("collideEnd",e[r].target),delete e[r]);n.clear()},drawInspect(){let r=this.localArea();L.pushTransform(),L.pushScale(this.area.scale),L.pushTranslate(this.area.offset);let o={outline:{width:4/Un(),color:W(0,0,255)},anchor:this.anchor,fill:!1,fixed:ct(this)};r instanceof L.Rect?L.drawRect({...o,pos:r.pos,width:r.width,height:r.height}):r instanceof L.Polygon?L.drawPolygon({...o,pts:r.pts}):r instanceof L.Circle&&L.drawCircle({...o,pos:r.center,radius:r.radius}),L.popTransform()},area:{shape:t.shape??null,scale:t.scale?b(t.scale):b(1),offset:t.offset??b(0),cursor:t.cursor??null},isClicked(){return P.isMousePressed()&&this.isHovering()},isHovering(){let r=ct(this)?L.mousePos():L.toWorld(L.mousePos());return this.hasPoint(r)},checkCollision(r){if(!r.id)throw new Error("checkCollision() requires the object to have an id");return e[r.id]??null},getCollisions(){return Object.values(e)},isColliding(r){if(!r.id)throw new Error("isColliding() requires the object to have an id");return!!e[r.id]},isOverlapping(r){if(!r.id)throw new Error("isOverlapping() requires the object to have an id");let o=e[r.id];return o&&o.hasOverlap()},onClick(r,o="left"){let s=P.onMousePress(o,()=>{this.isHovering()&&r()});return this.onDestroy(()=>s.cancel()),s},onHover(r){let o=!1;return this.onUpdate(()=>{o?o=this.isHovering():this.isHovering()&&(o=!0,r())})},onHoverUpdate(r){return this.onUpdate(()=>{this.isHovering()&&r()})},onHoverEnd(r){let o=!1;return this.onUpdate(()=>{o?this.isHovering()||(o=!1,r()):o=this.isHovering()})},onCollide(r,o){if(typeof r=="function"&&o===void 0)return this.on("collide",r);if(typeof r=="string")return this.onCollide((s,a)=>{s.is(r)&&o?.(s,a)});throw new Error("onCollide() requires either a function or a tag")},onCollideUpdate(r,o){if(typeof r=="function"&&o===void 0)return this.on("collideUpdate",r);if(typeof r=="string")return this.on("collideUpdate",(s,a)=>s.is(r)&&o?.(s,a));throw new Error("onCollideUpdate() requires either a function or a tag")},onCollideEnd(r,o){if(typeof r=="function"&&o===void 0)return this.on("collideEnd",r);if(typeof r=="string")return this.on("collideEnd",s=>s.is(r)&&o?.(s));throw new Error("onCollideEnd() requires either a function or a tag")},hasPoint(r){return rt(this.worldArea(),r)},resolveCollision(r){let o=this.checkCollision(r);o&&!o.resolved&&(this.pos=this.pos.add(o.displacement),o.resolved=!0)},localArea(){return this.area.shape?this.area.shape:this.renderArea()},worldArea(){let r=this.localArea();if(!(r instanceof L.Polygon||r instanceof L.Rect))throw new Error("Only support polygon and rect shapes for now");let o=this.transform.clone().scale(b(this.area.scale??1)).translate(this.area.offset);if(r instanceof L.Rect){let s=Ne(this.anchor||dt).add(1,1).scale(-.5).scale(r.width,r.height);o.translate(s)}return r.transform(o)},screenArea(){let r=this.worldArea();return ct(this)?r:r.transform(C.cam.transform)},inspect(){return this.area.scale.x==this.area.scale.y?`area: ${this.area.scale.x.toFixed(1)}x`:`area: (${this.area.scale.x.toFixed(1)}x, ${this.area.scale.y.toFixed(1)}y)`}}}i(ma,"area");function pa(t={}){let e=null,n=null,r=!1,o=b(0),s=null,a=null,l;return{id:"body",require:["pos"],vel:b(0),drag:t.drag??0,jumpForce:t.jumpForce??Ei,gravityScale:t.gravityScale??1,isStatic:t.isStatic??!1,mass:t.mass??1,add(){if(s=this.pos.clone(),a=this.pos.clone(),l=this.pos.clone(),this.mass===0)throw new Error("Can't set body mass to 0");this.is("area")&&(this.onCollideUpdate((u,m)=>{if(!m||!u.is("body")||m.resolved)return;this.trigger("beforePhysicsResolve",m);let c=m.reverse();if(u.trigger("beforePhysicsResolve",c),!(m.resolved||c.resolved)&&!(this.isStatic&&u.isStatic)){if(!this.isStatic&&!u.isStatic){let p=this.mass+u.mass;this.pos=this.pos.add(m.displacement.scale(u.mass/p)),u.pos=u.pos.add(m.displacement.scale(-this.mass/p)),this.transform=Lt(this),u.transform=Lt(u)}else{let p=!this.isStatic&&u.isStatic?m:m.reverse();p.source.pos=p.source.pos.add(p.displacement),p.source.transform=Lt(p.source)}m.resolved=!0,this.trigger("physicsResolve",m),u.trigger("physicsResolve",m.reverse())}}),this.onPhysicsResolve(u=>{C.gravity&&(u.isBottom()&&this.isFalling()?(this.vel=this.vel.reject(C.gravity.unit()),e=u.target,n=u.target.pos,r?r=!1:(this.trigger("ground",e),u.target.trigger("land",this))):u.isTop()&&this.isJumping()&&(this.vel=this.vel.reject(C.gravity.unit()),this.trigger("headbutt",u.target),u.target.trigger("headbutted",this)))}))},update(){e&&(!this.isColliding(e)||!e.exists()||!e.is("body")?r=!0:(n&&!e.pos.eq(n)&&t.stickToPlatform!==!1&&this.moveBy(e.pos.sub(n)),n=e.pos));let u=L.restDt();u&&this.pos.eq(l)&&(this.pos=L.lerp(s,a,u/L.fixedDt()),l=this.pos.clone())},fixedUpdate(){if(s&&(this.pos.eq(l)&&(this.pos=s),s=null),C.gravity&&!this.isStatic){r&&(e=null,n=null,this.trigger("fallOff"),r=!1);let m=!0;if(e&&(m=!1),m){let c=this.vel.clone();this.vel=this.vel.add(C.gravity.scale(this.gravityScale*L.dt()));let p=t.maxVelocity??Ti;this.vel.slen()>p*p&&(this.vel=this.vel.unit().scale(p)),c.dot(C.gravity)<0&&this.vel.dot(C.gravity)>=0&&this.trigger("fall")}}if(this.vel.x+=o.x*L.dt(),this.vel.y+=o.y*L.dt(),this.vel.x*=1-this.drag*L.dt(),this.vel.y*=1-this.drag*L.dt(),this.move(this.vel),L.restDt()){s=this.pos.clone();let m=this.vel.add(o.scale(L.dt()));a=this.pos.add(m.scale(L.dt())),l=this.pos.clone()}o.x=0,o.y=0},onPhysicsResolve(u){return this.on("physicsResolve",u)},onBeforePhysicsResolve(u){return this.on("beforePhysicsResolve",u)},curPlatform(){return e},isGrounded(){return e!==null},isFalling(){return this.vel.dot(L.getGravityDirection())>0},isJumping(){return this.vel.dot(L.getGravityDirection())<0},applyImpulse(u){this.vel=this.vel.add(u)},addForce(u){o.x+=u.x/this.mass,o.y+=u.y/this.mass},jump(u){e=null,n=null,this.vel=L.getGravityDirection().scale(-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)},onLand(u){return this.on("land",u)},onHeadbutted(u){return this.on("headbutted",u)},inspect(){return`gravityScale: ${this.gravityScale}x`}}}i(pa,"body");function da(t=2){let e=t;return{id:"doubleJump",require:["body"],numJumps:t,add(){this.onGround(()=>{e=this.numJumps})},doubleJump(n){e<=0||(e<this.numJumps&&this.trigger("doubleJump"),e--,this.jump(n))},onDoubleJump(n){return this.on("doubleJump",n)},inspect(){return`jumpsLeft: ${e}`}}}i(da,"doubleJump");function ha(t){return{id:"surfaceEffector",require:["area"],speed:t.speed,speedVariation:t.speedVariation??0,forceScale:t.speedVariation??.9,add(){this.onCollideUpdate((e,n)=>{let r=n?.normal.normal(),o=e.vel.project(r),a=r?.scale(this.speed)?.sub(o);e.addForce(a?.scale(e.mass*this.forceScale))})}}}i(ha,"surfaceEffector");function fa(t){return{id:"areaEffector",require:["area"],useGlobalAngle:t.useGlobalAngle||!1,forceAngle:t.forceAngle,forceMagnitude:t.forceMagnitude,forceVariation:t.forceVariation??0,linearDrag:t.linearDrag??0,add(){this.onCollideUpdate((e,n)=>{let o=w.fromAngle(this.forceAngle).scale(this.forceMagnitude);e.addForce(o),this.linearDrag&&e.addForce(e.vel.scale(-this.linearDrag))})}}}i(fa,"areaEffector");function ga(t){return{id:"pointEffector",require:["area","pos"],forceMagnitude:t.forceMagnitude,forceVariation:t.forceVariation??0,distanceScale:t.distanceScale??1,forceMode:t.forceMode||"inverseLinear",linearDrag:t.linearDrag??0,add(){this.onCollideUpdate((e,n)=>{let r=this.pos.sub(e.pos),o=r.len(),s=o*this.distanceScale/10,a=this.forceMode==="constant"?1:this.forceMode==="inverseLinear"?1/s:1/s**2,l=r.scale(this.forceMagnitude*a/o);e.addForce(l),this.linearDrag&&e.addForce(e.vel.scale(-this.linearDrag))})}}}i(ga,"pointEffector");function ba(t){return{id:"constantForce",require:["body"],force:t.force,update(){this.force&&this.addForce(this.force)}}}i(ba,"constantForce");function ya(t){return{id:"buoyancyEffector",require:["area"],surfaceLevel:t.surfaceLevel,density:t.density??1,linearDrag:t.linearDrag??1,angularDrag:t.angularDrag??.2,flowAngle:t.flowAngle??0,flowMagnitude:t.flowMagnitude??0,flowVariation:t.flowVariation??0,add(){this.onCollideUpdate((e,n)=>{let r=e,o=r.worldArea(),[s,a]=o.cut(b(-100,this.surfaceLevel),b(100,this.surfaceLevel));s&&(this.applyBuoyancy(r,s),this.applyDrag(r,s)),this.flowMagnitude&&r.addForce(w.fromAngle(this.flowAngle).scale(this.flowMagnitude))})},applyBuoyancy(e,n){let r=this.density*n.area(),o=b(0,1).scale(-r);e.addForce(o)},applyDrag(e,n){let r=e.vel,o=this.density*this.linearDrag,s=r.scale(-o);e.addForce(s)}}}i(ya,"buoyancyEffector");function ln(t){if(!t)throw new Error("Please define an anchor");return{id:"anchor",anchor:t,inspect(){return typeof this.anchor=="string"?"anchor: "+this.anchor:"anchor: "+this.anchor.toString()}}}i(ln,"anchor");function Xn(){return{id:"fixed",fixed:!0}}i(Xn,"fixed");function xa(t,e){return{id:"follow",require:["pos"],follow:{obj:t,offset:e??b(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))}}}i(xa,"follow");function va(t){let e=C.layers?.indexOf(t);return{id:"layer",get layerIndex(){return e??null},get layer(){return e?C.layers?.[e]??null:null},set layer(n){if(e=C.layers?.indexOf(n),e==-1)throw Error("Invalid layer name")},inspect(){return`layer: ${this.layer}`}}}i(va,"layer");function wa(t,e){let n=typeof t=="number"?w.fromAngle(t):t.unit();return{id:"move",require:["pos"],update(){this.move(n.scale(e))}}}i(wa,"move");function Ca(t={}){let e=t.distance??Ci,n=!1;return{id:"offscreen",require:["pos"],isOffScreen(){let r=this.screenPos();if(!r)return!1;let o=new ee(b(0),L.width(),L.height());return!L.testRectPoint(o,r)&&o.sdistToPoint(r)>e*e},onExitScreen(r){return this.on("exitView",r)},onEnterScreen(r){return this.on("enterView",r)},update(){this.isOffScreen()?(n||(this.trigger("exitView"),n=!0),t.hide&&(this.hidden=!0),t.pause&&(this.paused=!0),t.destroy&&this.destroy()):(n&&(this.trigger("enterView"),n=!1),t.hide&&(this.hidden=!1),t.pause&&(this.paused=!1))}}}i(Ca,"offscreen");function Gt(...t){return{id:"pos",pos:b(...t),moveBy(...e){this.pos=this.pos.add(b(...e))},move(...e){this.moveBy(b(...e).scale(L.dt()))},moveTo(...e){if(typeof e[0]=="number"&&typeof e[1]=="number")return this.moveTo(b(e[0],e[1]),e[2]);let n=e[0],r=e[1];if(r===void 0){this.pos=b(n);return}let o=n.sub(this.pos);if(o.len()<=r*L.dt()){this.pos=b(n);return}this.move(o.unit().scale(r))},worldPos(e=null){return e?(this.pos=this.pos.add(this.fromWorld(e)),null):this.parent?this.parent.transform.multVec2(this.pos):this.pos},toWorld(e){return this.parent?this.parent.transform.multVec2(this.pos.add(e)):this.pos.add(e)},fromWorld(e){return this.parent?this.parent.transform.invert().multVec2(e).sub(this.pos):e.sub(this.pos)},screenPos(e=null){if(e)return this.pos=this.pos.add(this.fromScreen(e)),null;{let n=this.worldPos();return n?ct(this)?n:L.toScreen(n):null}},toScreen(e){let n=this.toWorld(e);return ct(this)?n:L.toScreen(n)},fromScreen(e){return ct(this)?this.fromWorld(e):this.fromWorld(L.toWorld(e))},toOther(e,n){return e.fromWorld(this.toWorld(n))},fromOther(e,n){return e.toOther(this,n)},inspect(){return`pos: (${Math.round(this.pos.x)}x, ${Math.round(this.pos.y)}y)`},drawInspect(){L.drawCircle({color:L.rgb(255,0,0),radius:4/Un()})}}}i(Gt,"pos");function Ea(t){return{id:"rotate",angle:t??0,rotateBy(e){this.angle+=e},rotateTo(e){this.angle=e},inspect(){return`angle: ${Math.round(this.angle)}`}}}i(Ea,"rotate");function Nt(...t){if(t.length===0)return Nt(1);let e=b(...t);return{id:"scale",set scale(n){if(!(n instanceof w))throw Error("The scale property on scale is a vector. Use scaleTo or scaleBy to set the scale with a number.");e=b(n)},get scale(){return e},scaleTo(...n){e=b(...n)},scaleBy(...n){e=e.scale(b(...n))},inspect(){return e.x==e.y?`scale: ${e.x.toFixed(1)}x`:`scale: (${e.x.toFixed(1)}x, ${e.y.toFixed(1)}y)`}}}i(Nt,"scale");function Ta(t){return{id:"z",z:t,inspect(){return`z: ${this.z}`}}}i(Ta,"z");var Oa="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOcAAACDCAYAAAB2kQxsAAAAAXNSR0IArs4c6QAABqxJREFUeJztnU1yFDkQRtMEB+AG7Fk6fBPO6ZsQLGc/N5gbMAtosJvqKv2kpPxS763A0W5XSXqVqZ+SngzgF58/fflx/7N///vnacW1gBkFD2Z2LOYNBF3Dx9UXAGs5kxLWwhNxU2qlJHrOhwLfkNZoiaBzIa3dCFJYLXgSboKXmETPeVDQyamR8vX55fe/v37/9vBzCDoH0tqktEpZ+t0IOh4KOBm16euZmETPtVDAiRgRLRF0HRRuEkrFrE1hzR4Lipxj+bD6AqCPz5++/Bgp5tXfdv1CeAdPPmFmSkn0nE+a0drdFm6XiOkdKWEuKRptTXqlLuqqFNaM6Dkb+T5nbb+npo8WjZVinqFantFJk9bWojaRThq7HzKN8wiPJ7aCoJHEZN5zHvJp7RE1DTV6SnZ1fa/PL1MjJtF5HmnT2tJF3GZ/BIj05I8ULUtR6ypER7ogjxpw61rRGxEal4KYjNyORzatbUlHSxr06tFcBTHPiN5NUEJWzlZKG/aKRqYk5tl1IKgPafucZ7w+vxSluLP6olHnL6MQQfYV6bpk/+BRZXm+cXHEiApSipZHlE6tRBDMkxmyysl5VsmtjXiFoJmiZU35ZWK0oNv1OY+omSv0GDDKJCaMI42cHg25dvFCi6QZxVS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J9QGcO/8ZV2YUqYVPN8dImXp3aJ/w1XTGGYfKZN+P7IXiXqO1uINLzFOm/Pz+BV4C03PNEqpZl//ELXP1ro8nhLyKLPHMyAiXyvh4cMFZ2uyAJXc62gzgJl1nhrSLMEzcLx+5qQnIhgqv6qhTHC2Zmus1tUuowCVDkRU6j0jgiJqhLPSSq2q7wMtMSBkdbcQWjNCq2nMlRrTnajAPP/t+c5Sj3K8VNueQ+pGzaa2MyOb2sZseW2dpL6ZnjMzfeQFt/Fe3XP2WIfGvRY6a569jCJ9TaIlcCS9KQE5p1TP2VrMbwLNDlZEvpE5AkGxh9f2nLO/QOetytIwAnMf6SfS2ns+jaZ6B4i2sWvSvF0HWOAj/aRGNFAaPXbw2rS2Rzr0T/ChshKNM3qd4135BCaqK9VAKy+lAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/4DBC0k0jFtF9wAAAAASUVORK5CYII=";var qu="3001.0.0",L,re,O,C,P,_,gt,kr,J,oe,We,ve,_t,Wr,$r,Va=i((t={})=>{re=t;let e=t.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%"),ve=t.canvas??e.appendChild(document.createElement("canvas")),_t=t.scale??1;let n=t.width&&t.height&&!t.stretch&&!t.letterbox;n?(ve.width=t.width*_t,ve.height=t.height*_t):(ve.width=ve.parentElement.offsetWidth,ve.height=ve.parentElement.offsetHeight);let r=["outline: none","cursor: default"];if(n){let U=ve.width,I=ve.height;r.push(`width: ${U}px`),r.push(`height: ${I}px`)}else r.push("width: 100%"),r.push("height: 100%");t.crisp&&(r.push("image-rendering: pixelated"),r.push("image-rendering: crisp-edges")),ve.style.cssText=r.join(";"),We=t.pixelDensity||window.devicePixelRatio,ve.width*=We,ve.height*=We,ve.tabIndex=0,gt=document.createElement("canvas"),gt.width=256,gt.height=256,kr=gt.getContext("2d",{willReadFrequently:!0}),P=ei({canvas:ve,touchToMouse:t.touchToMouse,gamepads:t.gamepads,pixelDensity:t.pixelDensity,maxFPS:t.maxFPS,buttons:t.buttons});let o=[],s=P.canvas.getContext("webgl",{antialias:!0,depth:!0,stencil:!0,alpha:!0,preserveDrawingBuffer:!0});if(!s)throw new Error("WebGL not supported");let a=s,l=zi(a,{texFilter:t.texFilter});O=os(t,l),oe=ks(),_=Ri(l),C=Fs(),C.root.use(mn());function u(U,I){let Y=new at(l,U,I);return{clear:i(()=>Y.clear(),"clear"),free:i(()=>Y.free(),"free"),toDataURL:i(()=>Y.toDataURL(),"toDataURL"),toImageData:i(()=>Y.toImageData(),"toImageData"),width:Y.width,height:Y.height,draw:i(j=>{Te(),Y.bind(),j(),Te(),Y.unbind()},"draw")}}i(u,"makeCanvas");function m(){a.clear(a.COLOR_BUFFER_BIT),O.frameBuffer.bind(),a.clear(a.COLOR_BUFFER_BIT),O.bgColor||Ye(()=>{ut({width:he(),height:ye(),quad:new $(0,0,he()/64,ye()/64),tex:O.bgTex,fixed:!0})}),O.renderer.numDraws=0,O.fixed=!1,O.transformStack.length=0,O.transform=new ge}i(m,"frameStart");function c(U,I){O.postShader=U,O.postShaderUniform=I??null}i(c,"usePostEffect");function p(){Te(),O.lastDrawCalls=O.renderer.numDraws,O.frameBuffer.unbind(),a.viewport(0,0,a.drawingBufferWidth,a.drawingBufferHeight);let U=O.width,I=O.height;O.width=a.drawingBufferWidth/We,O.height=a.drawingBufferHeight/We,Rt({flipY:!0,tex:O.frameBuffer.tex,pos:new w(O.viewport.x,O.viewport.y),width:O.viewport.width,height:O.viewport.height,shader:O.postShader,uniform:typeof O.postShaderUniform=="function"?O.postShaderUniform():O.postShaderUniform,fixed:!0}),Te(),O.width=U,O.height=I}i(p,"frameEnd");let d=!1;J={inspect:!1,timeScale:1,showLog:!0,fps:i(()=>P.fps(),"fps"),numFrames:i(()=>P.numFrames(),"numFrames"),stepFrame:K,drawCalls:i(()=>O.lastDrawCalls,"drawCalls"),clearLog:i(()=>C.logs=[],"clearLog"),log:i(U=>{let I=t.logMax??8;C.logs.unshift({msg:U,time:P.time()}),C.logs.length>I&&(C.logs=C.logs.slice(0,I))},"log"),error:i(U=>J.log(new Error(U.toString?U.toString():U)),"error"),curRecording:null,numObjects:i(()=>F("*",{recursive:!0}).length,"numObjects"),get paused(){return d},set paused(U){d=U,U?oe.ctx.suspend():oe.ctx.resume()}};function x(U,I){try{return JSON.parse(window.localStorage[U])}catch{return I?(f(U,I),I):null}}i(x,"getData");function f(U,I){window.localStorage[U]=JSON.stringify(I)}i(f,"setData");function y(U,...I){let Y=U(L),j;typeof Y=="function"?j=Y(...I)(L):j=Y;for(let ue in j)L[ue]=j[ue],t.global!==!1&&(window[ue]=j[ue]);return L}i(y,"plug");function v(U){let I=P.canvas.captureStream(U),Y=oe.ctx.createMediaStreamDestination();oe.masterNode.connect(Y);let j=new MediaRecorder(I),ue=[];return j.ondataavailable=Z=>{Z.data.size>0&&ue.push(Z.data)},j.onerror=()=>{oe.masterNode.disconnect(Y),I.getTracks().forEach(Z=>Z.stop())},j.start(),{resume(){j.resume()},pause(){j.pause()},stop(){return j.stop(),oe.masterNode.disconnect(Y),I.getTracks().forEach(Z=>Z.stop()),new Promise(Z=>{j.onstop=()=>{Z(new Blob(ue,{type:"video/mp4"}))}})},download(Z="kaboom.mp4"){this.stop().then(Ce=>wr(Z,Ce))}}}i(v,"record");function A(){return document.activeElement===P.canvas}i(A,"isFocused");let V=C.root.add.bind(C.root),M=C.root.readd.bind(C.root),G=C.root.removeAll.bind(C.root),F=C.root.get.bind(C.root),g=C.root.wait.bind(C.root),T=C.root.loop.bind(C.root),S=C.root.query.bind(C.root),D=C.root.tween.bind(C.root);Wr=St(null,Aa),$r=St(null,Oa);function B(){C.root.fixedUpdate()}i(B,"fixedUpdateFrame");function K(){C.root.update()}i(K,"updateFrame");class k{static{i(this,"Collision")}source;target;normal;distance;resolved=!1;constructor(I,Y,j,ue,Z=!1){this.source=I,this.target=Y,this.normal=j,this.distance=ue,this.resolved=Z}get displacement(){return this.normal.scale(this.distance)}reverse(){return new k(this.target,this.source,this.normal.scale(-1),this.distance,this.resolved)}hasOverlap(){return!this.displacement.isZero()}isLeft(){return this.displacement.cross(C.gravity||b(0,1))>0}isRight(){return this.displacement.cross(C.gravity||b(0,1))<0}isTop(){return this.displacement.dot(C.gravity||b(0,1))>0}isBottom(){return this.displacement.dot(C.gravity||b(0,1))<0}preventResolution(){this.resolved=!0}}function z(){if(!la())return;let U={},I=t.hashGridSize||64,Y=new ge,j=[];function ue(Z){if(j.push(Y.clone()),Z.pos&&Y.translate(Z.pos),Z.scale&&Y.scale(Z.scale),Z.angle&&Y.rotate(Z.angle),Z.transform=Y.clone(),Z.c("area")&&!Z.paused){let Ce=Z,lt=Ce.worldArea().bbox(),rr=Math.floor(lt.pos.x/I),or=Math.floor(lt.pos.y/I),ir=Math.ceil((lt.pos.x+lt.width)/I),sr=Math.ceil((lt.pos.y+lt.height)/I),dn=new Set;for(let Je=rr;Je<=ir;Je++)for(let mt=or;mt<=sr;mt++)if(!U[Je])U[Je]={},U[Je][mt]=[Ce];else if(!U[Je][mt])U[Je][mt]=[Ce];else{let hn=U[Je][mt];e:for(let ke of hn){if(ke.paused||!ke.exists()||dn.has(ke.id))continue;for(let tt of Ce.collisionIgnore)if(ke.is(tt))continue e;for(let tt of ke.collisionIgnore)if(Ce.is(tt))continue e;let qt=Io(Ce.worldArea(),ke.worldArea());if(qt){let tt=new k(Ce,ke,qt.normal,qt.distance);Ce.trigger("collideUpdate",ke,tt);let fn=tt.reverse();fn.resolved=tt.resolved,ke.trigger("collideUpdate",Ce,fn)}dn.add(ke.id)}hn.push(Ce)}}Z.children.forEach(ue),Y=j.pop()}i(ue,"checkObj"),ue(C.root)}i(z,"checkFrame");function X(U){console.error(U),oe.ctx.suspend();let I=U.message??String(U)??"Unknown error, check console for more info";P.run(()=>{},()=>{m(),Ye(()=>{let ue=he(),Z=ye(),Ce={size:36,width:ue-32*2,letterSpacing:4,lineSpacing:4,font:Tt,fixed:!0};Pe({width:ue,height:Z,color:W(0,0,255),fixed:!0});let Ht=qe({...Ce,text:"Error",pos:b(32),color:W(255,128,0),fixed:!0});ze(Ht),Nr({...Ce,text:I,pos:b(32,32+Ht.height+16),fixed:!0}),xe(),C.events.trigger("error",U)}),p()})}i(X,"handleErr");function te(U){o.push(U)}i(te,"onCleanup");function Q(){C.events.onOnce("frameEnd",()=>{P.quit(),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT|a.STENCIL_BUFFER_BIT);let U=a.getParameter(a.MAX_TEXTURE_IMAGE_UNITS);for(let I=0;I<U;I++)a.activeTexture(a.TEXTURE0+I),a.bindTexture(a.TEXTURE_2D,null),a.bindTexture(a.TEXTURE_CUBE_MAP,null);a.bindBuffer(a.ARRAY_BUFFER,null),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,null),a.bindRenderbuffer(a.RENDERBUFFER,null),a.bindFramebuffer(a.FRAMEBUFFER,null),l.destroy(),o.forEach(I=>I())})}i(Q,"quit");let q=!0;P.run(()=>{try{_.loaded&&(z(),J.paused||B())}catch(U){X(U)}},()=>{try{_.loaded||Le()===1&&!q&&(_.loaded=!0,C.events.trigger("load")),!_.loaded&&t.loadingScreen!==!1||q?(m(),es(),p()):(J.paused||K(),z(),m(),Zi(),t.debug!==!1&&Ji(),p()),q&&(q=!1),C.events.trigger("frameEnd")}catch(U){X(U)}}),Hn(),tr(),L={VERSION:qu,loadRoot:Si,loadProgress:Le,loadSprite:St,loadSpriteAtlas:jr,loadSound:Ni,loadMusic:Hi,loadBitmapFont:Li,loadFont:Bi,loadShader:Ki,loadShaderURL:ki,loadAseprite:Ui,loadPedit:Ii,loadBean:Mi,loadJSON:Vi,load:on,getSound:Ir,getFont:Br,getBitmapFont:Ln,getSprite:Dr,getShader:Lr,getAsset:Pi,Asset:me,SpriteData:Ie,SoundData:st,width:he,height:ye,center:Et,dt:Ve,fixedDt:ti,restDt:ni,time:P.time,screenshot:P.screenshot,record:v,isFocused:A,setCursor:P.setCursor,getCursor:P.getCursor,setCursorLocked:P.setCursorLocked,isCursorLocked:P.isCursorLocked,setFullscreen:P.setFullscreen,isFullscreen:P.isFullscreen,isTouchscreen:P.isTouchscreen,onLoad:kt,onLoading:Ms,onResize:Us,onGamepadConnect:P.onGamepadConnect,onGamepadDisconnect:P.onGamepadDisconnect,onError:Bs,onCleanup:te,camPos:ds,camScale:hs,camFlash:gs,camRot:fs,camTransform:bs,shake:ys,toScreen:xs,toWorld:vs,setGravity:Ls,getGravity:Is,setGravityDirection:js,getGravityDirection:zr,setBackground:ci,getBackground:li,getGamepads:P.getGamepads,getTreeRoot:zs,add:V,make:un,destroy:$n,destroyAll:G,get:F,query:S,readd:M,pos:Gt,scale:Nt,rotate:Ea,color:qn,opacity:zn,anchor:ln,area:ma,sprite:cn,text:Qs,polygon:ms,rect:Wn,circle:is,uvquad:Js,outline:cs,particles:ls,body:pa,surfaceEffector:ha,areaEffector:fa,pointEffector:ga,buoyancyEffector:ya,constantForce:ba,doubleJump:da,shader:ps,textInput:ca,timer:mn,fixed:Xn,stay:nr,health:ia,lifespan:sa,named:aa,state:ua,z:Ta,layer:va,move:wa,offscreen:Ca,follow:xa,fadeIn:as,mask:us,drawon:ss,raycast:Yn,tile:Qn,animate:oa,serializeAnimation:Zr,agent:Zs,sentry:na,patrol:ta,navigation:ea,on:et,onFixedUpdate:Cs,onUpdate:Es,onDraw:Ts,onAdd:qr,onDestroy:Os,onClick:Ps,onCollide:As,onCollideUpdate:Ss,onCollideEnd:Vs,onHover:Rs,onHoverUpdate:Gs,onHoverEnd:Ds,onKeyDown:P.onKeyDown,onKeyPress:P.onKeyPress,onKeyPressRepeat:P.onKeyPressRepeat,onKeyRelease:P.onKeyRelease,onMouseDown:P.onMouseDown,onMousePress:P.onMousePress,onMouseRelease:P.onMouseRelease,onMouseMove:P.onMouseMove,onCharInput:P.onCharInput,onTouchStart:P.onTouchStart,onTouchMove:P.onTouchMove,onTouchEnd:P.onTouchEnd,onScroll:P.onScroll,onHide:P.onHide,onShow:P.onShow,onGamepadButtonDown:P.onGamepadButtonDown,onGamepadButtonPress:P.onGamepadButtonPress,onGamepadButtonRelease:P.onGamepadButtonRelease,onGamepadStick:P.onGamepadStick,onButtonPress:P.onButtonPress,onButtonDown:P.onButtonDown,onButtonRelease:P.onButtonRelease,mousePos:Bn,mouseDeltaPos:P.mouseDeltaPos,isKeyDown:P.isKeyDown,isKeyPressed:P.isKeyPressed,isKeyPressedRepeat:P.isKeyPressedRepeat,isKeyReleased:P.isKeyReleased,isMouseDown:P.isMouseDown,isMousePressed:P.isMousePressed,isMouseReleased:P.isMouseReleased,isMouseMoved:P.isMouseMoved,isGamepadButtonPressed:P.isGamepadButtonPressed,isGamepadButtonDown:P.isGamepadButtonDown,isGamepadButtonReleased:P.isGamepadButtonReleased,getGamepadStick:P.getGamepadStick,isButtonPressed:P.isButtonPressed,isButtonDown:P.isButtonDown,isButtonReleased:P.isButtonReleased,setButton:P.setButton,getButton:P.getButton,getLastInputDeviceType:P.getLastInputDeviceType,charInputted:P.charInputted,loop:T,wait:g,play:Zn,volume:Ns,burp:er,audioCtx:oe.ctx,Line:Ae,Rect:ee,Circle:Ge,Ellipse:_e,Point:xn,Polygon:Se,Vec2:w,Color:H,Mat4:ge,Quad:$,RNG:Wt,rand:be,randi:pr,randSeed:mo,vec2:b,rgb:W,hsl2rgb:uo,quad:pe,choose:fo,chooseMultiple:ho,shuffle:dr,chance:po,lerp:Ee,tween:D,easings:ot,map:De,mapc:lo,wave:vn,deg2rad:ce,rad2deg:pt,clamp:Be,evaluateQuadratic:To,evaluateQuadraticFirstDerivative:Oo,evaluateQuadraticSecondDerivative:Ao,evaluateBezier:Xt,evaluateBezierFirstDerivative:So,evaluateBezierSecondDerivative:Vo,evaluateCatmullRom:Po,evaluateCatmullRomFirstDerivative:Ro,curveLengthApproximation:yr,normalizedCurve:Go,hermite:Ut,cardinal:xr,catmullRom:Bt,bezier:Do,kochanekBartels:Mo,easingSteps:Lo,easingLinear:Bo,easingCubicBezier:Fo,testLineLine:wn,testRectRect:hr,testRectLine:Cn,testRectPoint:En,testCirclePolygon:$t,testLinePoint:Tn,testLineCircle:Mt,isConvex:Ko,triangulate:An,NavMesh:Mn,drawSprite:ns,drawText:Nr,formatText:qe,drawRect:Pe,drawLine:Kt,drawLines:jt,drawTriangle:_n,drawCircle:ft,drawEllipse:jn,drawUVQuad:ut,drawPolygon:He,drawCurve:Kn,drawBezier:qi,drawFormattedText:ze,drawMasked:ts,drawSubtracted:rs,pushTransform:we,popTransform:xe,pushTranslate:ne,pushScale:it,pushRotate:Qe,pushMatrix:mi,usePostEffect:c,makeCanvas:u,debug:J,scene:Ys,getSceneName:Xs,go:Ws,onSceneLeave:$s,layers:qs,addLevel:ws,getData:x,setData:f,download:Sn,downloadJSON:zo,downloadText:vr,downloadBlob:wr,plug:y,ASCII_CHARS:Fn,canvas:P.canvas,addKaboom:Hs,LEFT:w.LEFT,RIGHT:w.RIGHT,UP:w.UP,DOWN:w.DOWN,RED:H.RED,GREEN:H.GREEN,BLUE:H.BLUE,YELLOW:H.YELLOW,MAGENTA:H.MAGENTA,CYAN:H.CYAN,WHITE:H.WHITE,BLACK:H.BLACK,quit:Q,KEvent:le,KEventHandler:$e,KEventController:Ze};let ae=t.plugins;if(ae&&ae.forEach(y),t.global!==!1)for(let U in L)window[U]=L[U];return t.focus!==!1&&P.canvas.focus(),L},"kaplay");var zu=Va;return $a(Yu);})();
window.kaboom = kaplay.default; window.kaplay = kaplay.default
//# sourceMappingURL=kaplay.js.map
() => {
return {
// use the modules option to import modules from addresses or from the plugins gist
modules: [
// if a module is a web address, it can be included this way
"https://unpkg.com/kaplay@3001.0.0-alpha.21/dist/kaplay.js",
// this is how you can include the contents of other files from the list
//'kaplay-dist.js', // <-- copy of kaplay.js can also be stored in the gist and imported like so
// you can host a module on the same gist
"test-local-module.js",
'test-includes-script.js'
],
// if passed, inkjs or bondagejs will be included in the output - can be ink or yarn
parser: 'ink',
// when this parameter is set to true - the Test tab will display an additional console logger
// console: true,
// Use the script option to write your code that uses any imported modules
script: () => {
// since we imported kaplayjs in the modules option, we can now use it like this to render to the Test tab
const k = kaplay();
const bean64 = y.getRes('images', 'bean.png');
k.loadSprite("bean", bean64);
k.scene("main", () => {
k.add([
k.pos(300, 200),
k.sprite("bean"),
]);
k.add([
k.text("ohhimark fdfg"),
])
});
k.go("main");
// inkjs becomes available because we used parser: 'ink' option
console.log({
inkjs
})
// see test-includes-script.js where this is declared
testMe(123);
// see test-local-module.js where this is declared
const myLocalModule = new TestLocalModule('works');
//myLocalModule.testCall()
}
}
}
() => {
return {
script: function Story({data, parser: inkjs}) {
console.log({data, inkjs})
this.data = data
this.story = undefined
this.parser = inkjs
this.advance = () => {
console.log({data: this.data})
alert(this.data)
if(!this.story) {
this.story = new inkjs.Story(this.data);
continueStory();
}
}
}
}
}
() => {
return {
//https://unpkg.com/kaplay@3000.1.17/dist/kaboom.cjs
// https://unpkg.com/kaplay@3001.0.0-alpha.21/dist/kaplay.js
modules: ["https://unpkg.com/kaplay@3001.0.0-alpha.21/dist/kaplay.js",
"story-api.js"],
parser: 'ink',
script: () => {
// import kaboom from "https://esm.sh/kaboom"; // works on type="module"
console.log(window)
const k = kaplay();
k.loadSprite("bean", "public/icon.png")
// define a scene
k.scene("main", () => {
k.add([
k.pos(200, 100),
k.sprite("bean"),
]);
k.add([
k.text("ohhimark fdfg"),
])
});
const story = new Story({
data: 123, parser: inkjs
})
story.advance()
//start the game
k.go("main");
}
}
}
() => {
return {
script: () => {
// the contents of this script can be included in another main file via includes: ['test-includes-script']
const testMe = (echo) => {
console.log("Echo from includes script", echo)
}
}
}
}
() => {
return {
script: function TestLocalModule(params) {
this.params = params
this.testCall = () => {
alert("called from test-local-module", this.params)
}
}
}
}
() => {
return {
modules: ["https://cdnjs.cloudflare.com/ajax/libs/three.js/105/three.js",
"https://cdn.jsdelivr.net/npm/panolens@0.11.0/build/panolens.min.js"
],
body: "<div id='container' style='width:100vw;height:100vh;'></div>",
console: true,
script: () => {
var panorama,
newPanorama,
viewer,
container,
infospot,
infospot2;
container = document.querySelector('#container');
panorama = new PANOLENS.ImagePanorama('https://i.imgur.com/wTCPouq.jpg');
newPanorama = new PANOLENS.ImagePanorama('https://i.imgur.com/i2eW0E4.jpeg')
viewer = new PANOLENS.Viewer({
container: container
});
infospot = new PANOLENS.Infospot();
infospot.position.set(1000, 100, -2000);
infospot.addHoverText('go elsewhere');
infospot.addEventListener('click', ()=> {
viewer.setPanorama(newPanorama)
})
infospot2 = new PANOLENS.Infospot();
infospot2.position.set(1000, 100, 2000);
infospot2.addHoverText('err');
panorama.add(infospot, infospot2);
viewer.add(panorama);
}
}
}
() => {
return {
modules: ['https://cdnjs.cloudflare.com/ajax/libs/three.js/84/three.min.js',
'https://cdn.rawgit.com/mrdoob/three.js/25bc88abaef7f2f9376b8bbdea28973aa4925629/examples/js/controls/OrbitControls.js',
'https://cdn.rawgit.com/mrdoob/three.js/6c7f000734f8579da37fb39e5c2e9e5e2dfb14f8/examples/js/Detector.js'
],
body: `
<div class="sphere_wrap" style='width: 100vw;height:100vh'>
<div id="sphere"></div>
<div class="controls clr">
<ul>
<li class="controls__switch-prev"></li>
<li class="controls__zoom-out"></li>
<li class="controls__zoom-in"></li>
<li class="controls__switch-next"></li>
</ul>
</div>
</div>
`,
console: true,
script: () => {
document.addEventListener("DOMContentLoaded", (e) => {
const webglEl = document.getElementById('sphere'),
width = window.innerWidth,
height = window.innerHeight,
panoramasArray = [
"https://res.cloudinary.com/dkcygpizo/image/upload/v1491862637/codepen/1_dtotv2.jpg",
"https://res.cloudinary.com/dkcygpizo/image/upload/v1491862643/codepen/4_yvn4cb.jpg",
"https://res.cloudinary.com/dkcygpizo/image/upload/v1491862642/codepen/5_ydhnc6.jpg"
];
let panoramaNumber = 0 /* Math.floor(Math.random()*panoramasArray.length)* /;
/* Creating the scene */
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, width / height, 1, 1100);
camera.position.x = 0.1;
const renderer = Detector.webgl ? new THREE.WebGLRenderer(): new THREE.CanvasRenderer();
renderer.setSize(width, height);
webglEl.appendChild(renderer.domElement);
const sphereMaterial = new THREE.MeshBasicMaterial();
sphereMaterial.map = new THREE.TextureLoader().setCrossOrigin("anonymous").load(panoramasArray[panoramaNumber]);
//sphereMaterial.map = new THREE.TextureLoader().load(panoramasArray[panoramaNumber]); // For local images
const sphereGeometry = new THREE.SphereGeometry(500, 60, 40);
const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
sphere.scale.x = -1;
scene.add(sphere);
/* Rendering & OrbitControls */
const controls = new THREE.OrbitControls(camera, webglEl);
controls.enablePan = false;
controls.enableZoom = false;
controls.autoRotate = true;
controls.autoRotateSpeed = 0.5;
controls.maxPolarAngle = 2; // Radians
controls.minPolarAngle = 1; // Radians
function render() {
controls.update();
requestAnimationFrame(render);
renderer.render(scene, camera);
}
render();
/* Add Controls */
let deltaCount = 0;
function onMouseWheel(e) {
e.preventDefault();
function mouseWheel() {
if (e.wheelDeltaY) {
// WebKit
camera.fov -= e.wheelDeltaY * 0.05;
} else if (e.wheelDelta) {
// Opera / IE9
camera.fov -= e.wheelDelta * 0.05;
} else if (e.detail) {
// Firefox
camera.fov += e.detail * 1.0;
}
camera.fov = Math.max(40, Math.min(100, camera.fov));
}
if (e.deltaY < 0) {
if (deltaCount < 6) {
mouseWheel();
deltaCount += 1;
}
} else {
if (deltaCount > 0) {
mouseWheel();
deltaCount -= 1;
}
}
camera.updateProjectionMatrix();
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
document.addEventListener('mousewheel', onMouseWheel, false);
document.addEventListener('DOMMouseScroll', onMouseWheel, false);
window.addEventListener('resize', onWindowResize, false);
/* Switch & Zoom */
const switchBtn = document.querySelectorAll('.controls li[class*="switch"]'),
zoomBtn = document.querySelectorAll('.controls li[class*="zoom"]');
for (let i = 0; i < switchBtn.length; i++) {
switchBtn[i].onclick = (e) => {
let j = panoramasArray.length;
panoramaNumber = ~e.target.className.indexOf("controls__switch-next") ? (panoramaNumber + 1) % j: (panoramaNumber - 1) % j;
sphereMaterial.map = new THREE.TextureLoader().setCrossOrigin("anonymous").load(panoramasArray[Math.abs(panoramaNumber)]);
//sphereMaterial.map = new THREE.TextureLoader().load(panoramasArray[Math.abs(panoramaNumber)]); // For local images
};
}
for (let i = 0; i < zoomBtn.length; i++) {
zoomBtn[i].onclick = (e) => {
if (~e.target.className.indexOf("controls__zoom-in")) {
if (deltaCount < 6) {
camera.fov = Math.max(40, Math.min(100, camera.fov - 6));
deltaCount += 1;
}
} else {
if (deltaCount > 0) {
camera.fov = Math.max(40, Math.min(100, camera.fov + 6));
deltaCount -= 1;
}
}
camera.updateProjectionMatrix();
}
}
});
}
}
}
() => {
return {
name: 'ExamplePlugin',
Constructor: function( {
app,
createButton,
createToggle,
getPluginStore,
setPluginStore,
addSettingsItem,
onYarnLoadedData,
onYarnEditorOpen,
onYarnInPreviewMode,
onYarnSavedNode,
onYarnSetLanguage,
onYarnLoadedStateFromLocalStorage,
onYarnSavedStateToLocalStorage,
onYarnSetDocumentType,
onKeyUp,
onKeyDown,
onLoad,
}) {
const self = this;
this.name = 'ExamplePlugin';
this.onOpenPluginEditor = ()=> {
alert("YAY!")
}
createButton(self.name, {
name: 'ExamplePlugin',
className: 'item',
attachTo: 'fileMenuDropdown',
onClick: 'onOpenPluginEditor()',
iconName: 'cog',
});
}
}
}
() => {
return {
modules: ['https://cdnjs.cloudflare.com/ajax/libs/pixi.js/8.1.0/pixi.min.js'],
body: `<div id="pixi"></div>`,
script: () => {
console.log("VOALA", PIXI)
const {
Application,
Assets,
Sprite,
Texture
} = PIXI;
(async () =>
{
const app = new Application();
await app.init({
background: '#1099bb', resizeTo: window
});
document.body.appendChild(app.canvas);
const texture = await Assets.load('https://pixijs.com/assets/bunny.png');
const bunny = new Sprite(texture);
bunny.anchor.set(0.5);
bunny.x = app.screen.width / 2;
bunny.y = app.screen.height / 2;
app.stage.addChild(bunny);
app.ticker.add((time) =>
{
// Just for fun, let's rotate mr rabbit a little.
// * Delta is 1 if running at 100% performance *
// * Creates frame-independent transformation *
bunny.rotation += 0.1 * time.deltaTime;
});
})();
}
}
}
() => {
return {
modules: ['https://cdnjs.cloudflare.com/ajax/libs/pixi.js/8.1.0/pixi.min.js'],
body: `<div id="pixi"></div>`,
console: true,
script: () => {
console.log("VOALA", PIXI)
const {
Application,
Assets,
Sprite,
Texture
} = PIXI;
const app = new Application();
// Initialize the application
app.init({
resizeTo: window
}).then(()=> {
// Append the application canvas to the document body
document.body.appendChild(app.canvas);
Assets.load([
'https://pixijs.com/assets/bg_button.jpg',
'https://pixijs.com/assets/button.png',
'https://pixijs.com/assets/button_down.png',
'https://pixijs.com/assets/button_over.png',
]).then(()=> {
const background = Sprite.from('https://pixijs.com/assets/bg_button.jpg');
background.width = app.screen.width;
background.height = app.screen.height;
app.stage.addChild(background);
// Create some textures from an image path
const textureButton = Texture.from('https://pixijs.com/assets/button.png');
const textureButtonDown = Texture.from('https://pixijs.com/assets/button_down.png');
const textureButtonOver = Texture.from('https://pixijs.com/assets/button_over.png');
const buttons = [];
const buttonPositions = [175, 75, 655, 75, 410, 325, 150, 465, 685, 445];
function onButtonDown() {
this.isdown = true;
this.texture = textureButtonDown;
this.alpha = 1;
console.log("Pressed button!")
}
function onButtonUp() {
this.isdown = false;
if (this.isOver) {
this.texture = textureButtonOver;
} else
{
this.texture = textureButton;
}
}
function onButtonOver() {
this.isOver = true;
if (this.isdown) {
return;
}
this.texture = textureButtonOver;
}
function onButtonOut() {
this.isOver = false;
if (this.isdown) {
return;
}
this.texture = textureButton;
}
for (let i = 0; i < 5; i++) {
const button = new Sprite(textureButton);
button.anchor.set(0.5);
button.x = buttonPositions[i * 2];
button.y = buttonPositions[i * 2 + 1];
button.eventMode = 'static';
button.cursor = 'pointer';
button
.on('pointerdown', onButtonDown)
.on('pointerup', onButtonUp)
.on('pointerupoutside', onButtonUp)
.on('pointerover', onButtonOver)
.on('pointerout', onButtonOut);
app.stage.addChild(button);
// Add button to array
buttons.push(button);
}
});
});
}
}
}
@blurymind
Copy link
Author

ideas for plugins:

  • add extra node colors (or a color selector)
  • custom previewers
  • custom autocompleters
  • custom menu options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment