kaplay 3001.0.13 → 3001.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # 🎮 KAPLAY.js — a JavaScript & TypeScript Game Library
1
+ # 🎮 KAPLAY.js — A JavaScript & TypeScript Game Library
2
2
 
3
3
  <div align="center">
4
4
  <img src="./kaplay.webp">
package/dist/kaboom.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var kaplay=(()=>{var yr=Object.defineProperty;var nu=Object.getOwnPropertyDescriptor;var ru=Object.getOwnPropertyNames;var ou=Object.prototype.hasOwnProperty;var su=(t,e)=>{for(var n in e)yr(t,n,{get:e[n],enumerable:!0})},iu=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ru(e))!ou.call(t,o)&&o!==n&&yr(t,o,{get:()=>e[o],enumerable:!(r=nu(e,o))||r.enumerable});return t};var au=t=>iu(yr({},"__esModule",{value:!0}),t);var Oo=(()=>{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,i=0;s<r;){var m=t[n.charCodeAt(s++)],u=t[n.charCodeAt(s++)],c=t[n.charCodeAt(s++)],p=t[n.charCodeAt(s++)];o[i++]=m<<2|u>>4,o[i++]=u<<4|c>>2,o[i++]=c<<6|p}return o}})();var hc={};su(hc,{_k:()=>a,default:()=>fc,kaplay:()=>Qa});var Ao={name:"kaplay",description:"KAPLAY is a JavaScript & TypeScript game library that helps you make games fast and fun!",version:"3001.0.13",license:"MIT",homepage:"https://kaplayjs.com/",bugs:{url:"https://github.com/kaplayjs/kaplay/issues"},funding:{type:"opencollective",url:"https://opencollective.com/kaplay"},repository:{type:"git",url:"git+https://github.com/kaplayjs/kaplay.git"},type:"module",main:"./dist/kaplay.cjs",module:"./dist/kaplay.mjs",types:"./dist/doc.d.ts",readme:"./README.md",exports:{".":{import:{types:"./dist/doc.d.ts",default:"./dist/kaplay.mjs"},require:{types:"./dist/doc.d.ts",default:"./dist/kaplay.cjs"}},"./global":"./dist/declaration/global.js"},typesVersions:{"*":{global:["./dist/declaration/global.d.ts"]}},keywords:["game development","javascript","typescript","game engine","2d games","physics engine","webgl","canvas","game library","kaplay"],files:["dist/","kaplay.webp","CHANGELOG.md"],scripts:{dev:"NODE_ENV=development node scripts/dev.js","win:dev":"set NODE_ENV=development && node scripts/dev.js",build:"node scripts/generateIndex.js && node scripts/build.js && npm run doc-dts",check:"tsc",fmt:"dprint fmt",test:"node scripts/test.js","doc-dts":"dts-bundle-generator -o dist/doc.d.ts src/index.ts","test:vite":"vitest --typecheck",desktop:"tauri dev",prepare:"npm run build","publish:next":"npm publish --tag next"},devDependencies:{"@kaplayjs/dprint-config":"^1.2.0","@types/jest":"^29.5.14",dprint:"^0.49.1","dts-bundle-generator":"^9.5.1",ejs:"^3.1.10",esbuild:"^0.25.2",express:"^5.1.0",puppeteer:"^22.15.0","tar-fs":"3.0.8",typescript:"5.6.3",vite:"5.4.16",vitest:"^3.1.1","vitest-environment-puppeteer":"^11.0.3","vitest-puppeteer":"^11.0.3"},engines:{node:">=20.0.0"},packageManager:"pnpm@9.9.0+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1"};function Te(t,e,n){return e>n?Te(t,n,e):Math.min(Math.max(t,e),n)}var j=class t{r=255;g=255;b=255;constructor(e,n,r){this.r=Te(e,0,255),this.g=Te(n,0,255),this.b=Te(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=(p,b,l)=>(l<0&&(l+=1),l>1&&(l-=1),l<1/6?p+(b-p)*6*l:l<1/2?b:l<2/3?p+(b-p)*(2/3-l)*6:p),s=r<.5?r*(1+n):r+n-r*n,i=2*r-s,m=o(i,s,e+1/3),u=o(i,s,e),c=o(i,s,e-1/3);return new t(Math.round(m*255),Math.round(u*255),Math.round(c*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(de(this.r,e.r,n),de(this.g,e.g,n),de(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),i=(o+s)/2,m=i,u=i;if(o==s)i=m=0;else{let c=o-s;switch(m=u>.5?c/(2-o-s):c/(o+s),o){case e:i=(n-r)/c+(n<r?6:0);break;case n:i=(r-e)/c+2;break;case r:i=(e-n)/c+4;break}i/=6}return[i,m,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 I(...t){if(t.length===0)return new j(255,255,255);if(t.length===1){if(t[0]instanceof j)return t[0].clone();if(typeof t[0]=="string")return j.fromHex(t[0]);if(Array.isArray(t[0])&&t[0].length===3)return j.fromArray(t[0])}else if(t.length===2){if(t[0]instanceof j)return t[0].clone()}else if(t.length===3||t.length===4)return new j(t[0],t[1],t[2]);throw new Error("Invalid color arguments")}var So=(t,e,n)=>j.fromHSL(t,e,n);function ae(t){return t*Math.PI/180}function ct(t){return t*180/Math.PI}function de(t,e,n){if(typeof t=="number"&&typeof e=="number")return t+(e-t)*n;if(t instanceof E&&e instanceof E)return t.lerp(e,n);if(t instanceof j&&e instanceof j)return t.lerp(e,n);throw new Error(`Bad value for lerp(): ${t}, ${e}. Only number, Vec2 and Color is supported.`)}function Se(t,e,n,r,o){return r+(t-e)/(n-e)*(o-r)}function Po(t,e,n,r,o){return Te(Se(t,e,n,r,o),r,o)}var E=class t{x=0;y=0;constructor(e=0,n=e){this.x=e,this.y=n}static fromAngle(e){let n=ae(e);return new t(Math.cos(n),Math.sin(n))}static fromArray(e){return new t(e[0],e[1])}static ZERO=new t(0,0);static ONE=new t(1,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=v(...e);return new t(this.x+n.x,this.y+n.y)}sub(...e){let n=v(...e);return new t(this.x-n.x,this.y-n.y)}scale(...e){let n=v(...e);return new t(this.x*n.x,this.y*n.y)}dist(...e){let n=v(...e);return this.sub(n).len()}sdist(...e){let n=v(...e);return this.sub(n).slen()}static sdist(e,n){let r=e.x-n.x,o=e.y-n.y;return r*r+o*o}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}static dot(e,n){return e.x*n.x+e.y*n.y}cross(e){return this.x*e.y-this.y*e.x}static cross(e,n){return e.x*n.y-e.y*n.x}angle(...e){let n=v(...e);return ct(Math.atan2(this.y-n.y,this.x-n.x))}angleBetween(...e){let n=v(...e);return ct(Math.atan2(this.cross(n),this.dot(n)))}lerp(e,n){return new t(de(this.x,e.x,n),de(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 W(this,0,0)}toString(){return`vec2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`}toArray(){return[this.x,this.y]}};function v(...t){if(t.length===1){if(t[0]instanceof E)return new E(t[0].x,t[0].y);if(Array.isArray(t[0])&&t[0].length===2)return new E(...t[0])}return new E(...t)}var q=class t{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 E(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 le(t,e,n,r){return new q(t,e,n,r)}var Rt=class t{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 v(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(v(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 gt=class t{m11;m12;m13;m21;m22;m23;m31;m32;m33;constructor(e,n,r,o,s,i,m,u,c){this.m11=e,this.m12=n,this.m13=r,this.m21=o,this.m22=s,this.m23=i,this.m31=m,this.m32=u,this.m33=c}static fromMat2(e){return new t(e.a,e.b,0,e.c,e.d,0,0,0,1)}toMat2(){return new Rt(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)}},fe=class t{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=ae(-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=ae(-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=ae(-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=ae(-e);let n=Math.cos(e),r=Math.sin(e),o=this.m[0],s=this.m[1],i=this.m[4],m=this.m[5];return this.m[0]=o*n+s*r,this.m[1]=-o*r+s*n,this.m[4]=i*n+m*r,this.m[5]=-i*r+m*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 E(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 E(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 E(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 E(e/n,n)}else return new E(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 ct(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 ct(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 E(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 E(0,Math.atan(this.m[0]*this.m[4]+this.m[1]*this.m[5])/(e*e))}else return new E(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],i=this.m[8]*this.m[14]-this.m[12]*this.m[10],m=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],c=this.m[5]*this.m[15]-this.m[13]*this.m[7],p=this.m[5]*this.m[14]-this.m[13]*this.m[6],b=this.m[4]*this.m[15]-this.m[12]*this.m[7],l=this.m[4]*this.m[14]-this.m[12]*this.m[6],h=this.m[5]*this.m[15]-this.m[13]*this.m[7],d=this.m[4]*this.m[13]-this.m[12]*this.m[5],C=this.m[6]*this.m[11]-this.m[10]*this.m[7],g=this.m[5]*this.m[11]-this.m[9]*this.m[7],y=this.m[5]*this.m[10]-this.m[9]*this.m[6],O=this.m[4]*this.m[11]-this.m[8]*this.m[7],A=this.m[4]*this.m[10]-this.m[8]*this.m[6],R=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]*i),e[8]=this.m[4]*r-this.m[5]*s+this.m[7]*m,e[12]=-(this.m[4]*o-this.m[5]*i+this.m[6]*m),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]*i,e[9]=-(this.m[0]*r-this.m[1]*s+this.m[3]*m),e[13]=this.m[0]*o-this.m[1]*i+this.m[2]*m,e[2]=this.m[1]*u-this.m[2]*c+this.m[3]*p,e[6]=-(this.m[0]*u-this.m[2]*b+this.m[3]*l),e[10]=this.m[0]*h-this.m[1]*b+this.m[3]*d,e[14]=-(this.m[0]*p-this.m[1]*l+this.m[2]*d),e[3]=-(this.m[1]*C-this.m[2]*g+this.m[3]*y),e[7]=this.m[0]*C-this.m[2]*O+this.m[3]*A,e[11]=-(this.m[0]*g-this.m[1]*O+this.m[3]*R),e[15]=this.m[0]*y-this.m[1]*A+this.m[2]*R;let V=this.m[0]*e[0]+this.m[1]*e[4]+this.m[2]*e[8]+this.m[3]*e[12];for(let x=0;x<4;x++)for(let w=0;w<4;w++)e[x*4+w]*=1/V;return new t(e)}clone(){return new t([...this.m])}toString(){return this.m.toString()}};function On(t,e,n,r=o=>-Math.cos(o)){return t+(r(n)+1)/2*(e-t)}var cu=1103515245,lu=12345,Vo=2147483648,$t=class{seed;constructor(e){this.seed=e}gen(){return this.seed=(cu*this.seed+lu)%Vo,this.seed/Vo}genNumber(e,n){return e+this.gen()*(n-e)}genVec2(e,n){return new E(this.genNumber(e.x,n.x),this.genNumber(e.y,n.y))}genColor(e,n){return new j(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 E)return this.genVec2(v(0,0),e[0]);if(e[0]instanceof j)return this.genColor(I(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 E&&e[1]instanceof E)return this.genVec2(e[0],e[1]);if(e[0]instanceof j&&e[1]instanceof j)return this.genColor(e[0],e[1])}throw new Error("More than 2 arguments not supported")}},wr=new $t(Date.now());function Go(t){return t!=null&&(wr.seed=t),wr.seed}function he(...t){return wr.genAny(...t)}function Cr(...t){return Math.floor(he(...t.length>0?t:[2]))}function Mo(t){return he()<=t}function Er(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}function Ro(t,e){return t.length<=e?t.slice():Er(t.slice()).slice(0,e)}function Do(t){return t[Cr(t.length)]}function Tr(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}function mu(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}function An(t,e){let n=mu(t,e);return n?v(t.p1.x+n*(t.p2.x-t.p1.x),t.p1.y+n*(t.p2.y-t.p1.y)):null}function Sn(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,i=(t.pos.x+t.width-e.p1.x)/n.x;r=Math.max(r,Math.min(s,i)),o=Math.min(o,Math.max(s,i))}if(n.y!=0){let s=(t.pos.y-e.p1.y)/n.y,i=(t.pos.y+t.height-e.p1.y)/n.y;r=Math.max(r,Math.min(s,i)),o=Math.min(o,Math.max(s,i))}return o>=r&&o>=0&&r<=1}function Dt(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}function Bo(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 v(n,r).sdist(e.center)<=e.radius*e.radius}function Fo(t,e){return Lo(e,new be(t.points()))}function Vn(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}function Bt(t,e){let n=t.p2.sub(t.p1),r=n.dot(n),o=t.p1.sub(e.center),s=2*n.dot(o),i=o.dot(o)-e.radius*e.radius,m=s*s-4*r*i;if(r<=Number.EPSILON||m<0)return!1;if(m==0){let u=-s/(2*r);if(u>=0&&u<=1)return!0}else{let u=(-s+Math.sqrt(m))/(2*r),c=(-s-Math.sqrt(m))/(2*r);if(u>=0&&u<=1||c>=0&&c<=1)return!0}return Pn(e,t.p1)}function Or(t,e){if(Ze(e,t.p1)||Ze(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(An(t,new Oe(r,o)))return!0}return!1}function Pn(t,e){return t.center.sdist(e)<t.radius*t.radius}function pu(t,e){return t.center.sdist(e.center)<(t.radius+e.radius)*(t.radius+e.radius)}function Xt(t,e){let n=e.pts[e.pts.length-1];for(let r of e.pts){if(Bt(new Oe(n,r),t))return!0;n=r}return Pn(t,e.pts[0])?!0:Ze(e,t.center)}function Lo(t,e){for(let n=0;n<t.pts.length;n++)if(Or(new Oe(t.pts[n],t.pts[(n+1)%t.pts.length]),e))return!0;return!!(t.pts.some(n=>Ze(e,n))||e.pts.some(n=>Ze(t,n)))}function Ze(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}function Ar(t,e){e=e.sub(t.center);let n=ae(t.angle),r=Math.cos(n),o=Math.sin(n),s=e.x*r+e.y*o,i=-e.x*o+e.y*r;return s*s/(t.radiusX*t.radiusX)+i*i/(t.radiusY*t.radiusY)<1}function En(t,e){let n=e.center.sub(t.center),r=ae(t.angle),o=Math.cos(r),s=Math.sin(r),i=n.x*o+n.y*s,m=-n.x*s+n.y*o;return Ar(new Ke(v(),t.radiusX+e.radius,t.radiusY+e.radius,0),v(i,m))}function jo(t,e){let n=t.toMat2().inverse;return e=new Oe(n.transform(e.p1.sub(t.center)),n.transform(e.p2.sub(t.center))),Bt(e,new we(v(),1))}function du(t,e){if(t.radiusX===t.radiusY)return En(e,new we(t.center,t.radiusX));if(e.radiusX===e.radiusY)return En(t,new we(e.center,e.radiusX));let n=new gt(1/t.radiusX**2,0,0,0,1/t.radiusY**2,0,0,0,-1),r=new gt(1/e.radiusX**2,0,0,0,1/e.radiusY**2,0,0,0,-1),o=t.center.x,s=t.center.y,i=e.center.x,m=e.center.y,u=ae(t.angle),c=ae(e.angle),p=new gt(Math.cos(u),-Math.sin(u),o,Math.sin(u),Math.cos(u),s,0,0,1),b=new gt(Math.cos(c),-Math.sin(c),i,Math.sin(c),Math.cos(c),m,0,0,1),l=p.inverse,h=b.inverse,d=l.transpose.mul(n).mul(l),C=h.transpose.mul(r).mul(h),g=d.m11,y=d.m12,O=d.m13,A=d.m21,R=d.m22,V=d.m23,x=d.m31,w=d.m32,S=d.m33,G=C.m11,M=C.m12,D=C.m13,L=C.m21,U=C.m22,H=C.m23,Y=C.m31,_=C.m32,K=C.m33,J=g*R*S-g*V*w-y*A*S+y*V*x+O*A*w-O*R*x,$=(g*R*K-g*V*_-g*w*H+g*S*U-y*A*K+y*V*Y+y*x*H-y*S*L+O*A*_-O*R*Y-O*x*U+O*w*L+A*w*D-A*S*M-R*x*D+R*S*G+V*x*M-V*w*G)/J,Z=(g*U*K-g*H*_-y*L*K+y*H*Y+O*L*_-O*U*Y-A*M*K+A*D*_+R*G*K-R*D*Y-V*G*_+V*M*Y+x*M*H-x*D*U-w*G*H+w*D*L+S*G*U-S*M*L)/J,Ee=(G*U*K-G*H*_-M*L*K+M*H*Y+D*L*_-D*U*Y)/J;if($>=0){let k=-3*Z+$**2,ht=3*$*Ee+Z*$**2-4*Z**2,Pt=-27*Ee**2+18*Ee*$*Z+$**2*Z**2-4*$**3*Ee-4*Z**3;return!(k>0&&ht<0&&Pt>0)}else{let k=-3*Z+$**2,ht=-27*Ee**2+18*Ee*$*Z+$**2*Z**2-4*$**3*Ee-4*Z**3;return!(k>0&&ht>0)}}function Io(t,e){return Sr(t,new be(e.points()))}function Sr(t,e){let n=t.toMat2().inverse;return e=new be(e.pts.map(r=>n.transform(r.sub(t.center)))),Xt(new we(v(),1),e)}function fu(t,e){return t.x===e.x&&t.y===e.y}function hu(t,e){return e instanceof E?fu(e,t.pt):e instanceof we?Pn(e,t.pt):e instanceof Oe?Vn(e,t.pt):e instanceof W?Dt(e,t.pt):e instanceof be?Ze(e,t.pt):e instanceof Ke?Ar(e,t.pt):!1}function gu(t,e){return e instanceof E?Vn(t,e):e instanceof we?Bt(t,e):e instanceof Oe?An(t,e)!=null:e instanceof W?Sn(e,t):e instanceof be?Or(t,e):e instanceof Ke?jo(e,t):!1}function bu(t,e){return e instanceof E?Pn(t,e):e instanceof we?pu(t,e):e instanceof Oe?Bt(e,t):e instanceof W?Bo(e,t):e instanceof be?Xt(t,e):e instanceof Ke?En(e,t):!1}function yu(t,e){return e instanceof E?Dt(t,e):e instanceof we?Bo(t,e):e instanceof Oe?Sn(t,e):e instanceof W?Tr(t,e):e instanceof be?Fo(t,e):e instanceof Ke?Io(e,t):!1}function xu(t,e){return e instanceof E?Ze(t,e):e instanceof we?Xt(e,t):e instanceof Oe?Or(e,t):e instanceof W?Fo(e,t):e instanceof be?Lo(e,t):e instanceof Ke?Sr(e,t):!1}function vu(t,e){return e instanceof E?Ar(t,e):e instanceof we?En(t,e):e instanceof Oe?jo(t,e):e instanceof W?Io(t,e):e instanceof be?Sr(t,e):e instanceof Ke?du(e,t):!1}function Ko(t,e,n){let r=t,o=n.p1,s=n.p2,i=e,m=s.sub(o),u=i.cross(m);if(Math.abs(u)<Number.EPSILON)return null;let c=o.sub(r),p=c.cross(m)/u;if(p<=0||p>=1)return null;let b=c.cross(i)/u;if(b<=0||b>=1)return null;let l=m.normal().unit();return e.dot(l)>0&&(l.x*=-1,l.y*=-1),{point:r.add(i.scale(p)),normal:l,fraction:p}}function wu(t,e,n){let r=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,s;if(t.x!=0){let i=(n.pos.x-t.x)/e.x,m=(n.pos.x+n.width-t.x)/e.x;s=v(-Math.sign(e.x),0),r=Math.max(r,Math.min(i,m)),o=Math.min(o,Math.max(i,m))}if(t.y!=0){let i=(n.pos.y-t.y)/e.y,m=(n.pos.y+n.height-t.y)/e.y;Math.min(i,m)>r&&(s=v(0,-Math.sign(e.y))),r=Math.max(r,Math.min(i,m)),o=Math.min(o,Math.max(i,m))}return o>=r&&r>=0&&r<=1?{point:t.add(e.scale(r)),normal:s,fraction:r}:null}function ko(t,e,n){let r=t,o=n.center,s=e,i=s.dot(s),m=r.sub(o),u=2*s.dot(m),c=m.dot(m)-n.radius*n.radius,p=u*u-4*i*c;if(i<=Number.EPSILON||p<0)return null;if(p==0){let b=-u/(2*i);if(b>=0&&b<=1){let l=r.add(s.scale(b));return{point:l,normal:l.sub(o),fraction:b}}}else{let b=(-u+Math.sqrt(p))/(2*i),l=(-u-Math.sqrt(p))/(2*i),h=null;if(b>=0&&b<=1&&(h=b),l>=0&&l<=1&&(h=Math.min(l,h??l)),h!=null){let d=r.add(s.scale(h));return{point:d,normal:d.sub(o).unit(),fraction:h}}}return null}function Cu(t,e,n){let r=n.pts,o=null,s=r[r.length-1];for(let i=0;i<r.length;i++){let m=r[i],u=Ko(t,e,new Oe(s,m));u&&(!o||o.fraction>u.fraction)&&(o=u),s=m}return o}function Eu(t,e,n){let r=n.toMat2(),o=r.inverse,s=o.transform(t.sub(n.center)),i=o.transform(e),m=ko(s,i,new we(v(),1));if(m){let u=Rt.rotation(ae(-n.angle)),p=Rt.scale(n.radiusX,n.radiusY).transform(m.point),b=r.transform(m.point).add(n.center),l=b.dist(t)/e.len();return{point:b,normal:u.transform(v(n.radiusY**2*p.x,n.radiusX**2*p.y)).unit(),fraction:l}}return m}function _o(t,e,n,r=64){let o=t,s=e.len(),i=e.scale(1/s),m=0,u=v(Math.floor(t.x),Math.floor(t.y)),c=v(i.x>0?1:-1,i.y>0?1:-1),p=v(Math.abs(1/i.x),Math.abs(1/i.y)),b=v(c.x>0?u.x+1-t.x:t.x-u.x,c.y>0?u.y+1-t.y:t.y-u.y),l=v(p.x<1/0?p.x*b.x:1/0,p.y<1/0?p.y*b.y:1/0),h=-1;for(;m<=r;){let d=n(u);if(d===!0)return{point:o.add(i.scale(m)),normal:v(h===0?-c.x:0,h===1?-c.y:0),fraction:m/s,gridPos:u};if(d)return d;l.x<l.y?(u.x+=c.x,m=l.x,l.x+=p.x,h=0):(u.y+=c.y,m=l.y,l.y+=p.y,h=1)}return null}var Tn=class t{pt;constructor(e){this.pt=e.clone()}transform(e){return new t(e.multVec2(this.pt))}bbox(){return new W(this.pt,0,0)}area(){return 0}clone(){return new t(this.pt)}collides(e){return hu(this,e)}contains(e){return this.pt.eq(e)}raycast(e,n){return null}random(){return this.pt.clone()}},Oe=class t{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 W.fromPoints(this.p1,this.p2)}area(){return this.p1.dist(this.p2)}clone(){return new t(this.p1,this.p2)}collides(e){return gu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return Ko(e,n,this)}random(){return this.p1.add(this.p2.sub(this.p1).scale(he(1)))}},W=class t{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 E(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 be(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 yu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return wu(e,n,this)}random(){return this.pos.add(he(this.width),he(this.height))}},we=class t{center;radius;constructor(e,n){this.center=e.clone(),this.radius=n}transform(e){return new Ke(this.center,this.radius,this.radius).transform(e)}bbox(){return W.fromPoints(this.center.sub(v(this.radius)),this.center.add(v(this.radius)))}area(){return this.radius*this.radius*Math.PI}clone(){return new t(this.center,this.radius)}collides(e){return bu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return ko(e,n,this)}random(){return this.center.add(E.fromAngle(he(360)).scale(he(this.radius)))}},Ke=class t{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,[i,m]=r.eigenvectors(o,s),[u,c]=[1/Math.sqrt(o),1/Math.sqrt(s)];return u>c?new t(v(),u,c,ct(Math.atan2(-i[1],i[0]))):new t(v(),c,u,ct(Math.atan2(-m[1],m[0])))}toMat2(){let e=ae(this.angle),n=Math.cos(e),r=Math.sin(e);return new Rt(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=gt.fromMat2(n).scale(o.x,o.y).rotate(r).toMat2();let i=t.fromMat2(n);return i.center=e.multVec2(this.center),i}}bbox(){if(this.angle==0)return W.fromPoints(this.center.sub(v(this.radiusX,this.radiusY)),this.center.add(v(this.radiusX,this.radiusY)));{let e=ae(this.angle),n=Math.cos(e),r=Math.sin(e),o=this.radiusX*n,s=this.radiusX*r,i=this.radiusY*r,m=this.radiusY*n,u=Math.sqrt(o*o+i*i),c=Math.sqrt(s*s+m*m);return W.fromPoints(this.center.sub(v(u,c)),this.center.add(v(u,c)))}}area(){return this.radiusX*this.radiusY*Math.PI}clone(){return new t(this.center,this.radiusX,this.radiusY,this.angle)}collides(e){return vu(this,e)}contains(e){e=e.sub(this.center);let n=ae(this.angle),r=Math.cos(n),o=Math.sin(n),s=e.x*r+e.y*o,i=-e.x*o+e.y*r;return s*s/(this.radiusX*this.radiusX)+i*i/(this.radiusY*this.radiusY)<1}raycast(e,n){return Eu(e,n,this)}random(){return this.center}};function Tu(t,e,n,r){let o=e.sub(t),s=r.sub(n),i=o.cross(s);return i<1e-5&&i>-1e-5||(i=n.sub(t).cross(s)/i,i<0||i>1)?null:t.add(o.scale(i))}var be=class t{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=v(Number.MAX_VALUE),n=v(-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 W.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 xu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return Cu(e,n,this)}random(){return v()}cut(e,n){let r=new Oe(e,n),o=[],s=[],i=n.sub(e),m=this.pts[this.pts.length-1],u=m.sub(e),c=i.cross(u)>0;return this.pts.forEach(p=>{u=p.sub(e);let b=i.cross(u)>0;if(c!=b){let l=Tu(m,p,e,n);o.push(l),s.push(l),c=b}(b?o:s).push(p),m=p}),[o.length?new t(o):null,s.length?new t(s):null]}};function No(t,e,n,r){let o=r*r,s=1-r,i=s*s;return t.scale(i).add(e.scale(2*s*r)).add(n.scale(o))}function Uo(t,e,n,r){let o=1-r;return e.sub(t).scale(2*o).add(n.sub(e).scale(2*r))}function Ho(t,e,n,r){return n.sub(e.scale(2)).add(t).scale(2)}function Qt(t,e,n,r,o){let s=o*o,i=s*o,m=1-o,u=m*m,c=u*m;return t.scale(c).add(e.scale(3*u*o)).add(n.scale(3*m*s)).add(r.scale(i))}function qo(t,e,n,r,o){let s=o*o,i=1-o,m=i*i;return e.sub(t).scale(3*m).add(n.sub(e).scale(6*i*o)).add(r.sub(n).scale(3*s))}function zo(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))}function Wo(t,e,n,r,o){let s=.5*(((-o+2)*o-1)*o),i=.5*((3*o-5)*o*o+2),m=.5*(((-3*o+4)*o+1)*o),u=.5*((o-1)*o*o);return t.scale(s).add(e.scale(i)).add(n.scale(m)).add(r.scale(u))}function Yo(t,e,n,r,o){let s=.5*((-3*o+4)*o-1),i=.5*((9*o-10)*o),m=.5*((-9*o+8)*o+1),u=.5*((3*o-2)*o);return t.scale(s).add(e.scale(i)).add(n.scale(m)).add(r.scale(u))}function $o(t){let e=Vr(t),n=e(1);return r=>{let o=r*n,s=e(o,!0);return t(s)}}function Vr(t,e=10,n=10){let r=[0],o=[0],i=1/(e-1)/n,m=0,u=t(0),c=0;for(let p=1;p<e;p++){for(let b=0;b<n;b++){c+=i;let l=t(c),h=l.dist(u);m+=h,u=l}r[p]=m,o[p]=c}return o[e-1]=1,(p,b=!1)=>{if(b){let l=p;if(l<=0)return 0;if(l>=m)return 1;let h=0;for(;r[h+1]<l;)h++;let d=o[h],C=o[h+1],g=r[h],y=r[h+1],O=(l-g)/(y-g);return d+(C-d)*O}else{if(p<=0)return 0;if(p>=1)return r[e-1];let l=0;for(;o[l+1]<p;)l++;let h=o[l],d=o[l+1],C=r[l],g=r[l+1],y=(p-h)/(d-h);return C+(g-C)*y}}}function Ft(t,e,n,r){let o=2*t+e-2*r+n,s=-3*t+3*r-2*e-n,i=e,m=t;return u=>{let c=u*u,p=c*u;return o*p+s*c+i*u+m}}function Pr(t,e,n,r,o,s=Ft){let i=s(e.x,(1-o)*(n.x-t.x),(1-o)*(r.x-e.x),n.x),m=s(e.y,(1-o)*(n.y-t.y),(1-o)*(r.y-e.y),n.y);return u=>new E(i(u),m(u))}function Lt(t,e,n,r,o=Ft){return Pr(t,e,n,r,.5,o)}function Xo(t,e,n,r,o=Ft){return Lt(r.add(t.sub(e).scale(6)),t,r,t.add(r.sub(n).scale(6)),o)}function Qo(t,e,n,r,o,s,i,m=Ft){let u=m(e.x,.5*(1-o)*(1+i)*(1+s)*(e.x-t.x)+.5*(1-o)*(1-i)*(1-s)*(n.x-e.x),.5*(1-o)*(1+i)*(1-s)*(n.x-e.x)+.5*(1-o)*(1-i)*(1+s)*(r.x-n.x),n.x),c=m(e.y,.5*(1-o)*(1+i)*(1+s)*(e.y-t.y)+.5*(1-o)*(1-i)*(1-s)*(n.y-e.y),.5*(1-o)*(1+i)*(1-s)*(n.y-e.y)+.5*(1-o)*(1-i)*(1+s)*(r.y-n.y),n.y);return p=>new E(u(p),c(p))}function Jo(t,e,n,r){let o=2*t+e-2*r+n,s=-3*t+3*r-2*e+n,i=e;return m=>{let u=m*m;return 3*o*u+2*s*m+i}}function Wt(t){return 0<=t&&t<=1}function xr(t,e){return Math.abs(t-e)<=Number.EPSILON}function Yt(t){return t<0?-Math.pow(-t,1/3):Math.pow(t,1/3)}function Ou(t,e,n,r){let o=3*t-6*e+3*n,s=-3*t+3*e,i=t,m=-t+3*e-3*n+r;if(xr(m,0)){if(xr(o,0))return xr(s,0)?[]:[-i/s].filter(Wt);let y=Math.sqrt(s*s-4*o*i),O=2*o;return[(y-s)/O,(-s-y)/O].filter(Wt)}o/=m,s/=m,i/=m;let u=(3*s-o*o)/3,c=u/3,p=(2*o*o*o-9*o*s+27*i)/27,b=p/2,l=b*b+c*c*c;if(l<0){let y=-u/3,O=y*y*y,A=Math.sqrt(O),R=-p/(2*A),V=R<-1?-1:R>1?1:R,x=Math.acos(V),S=2*Yt(A),G=S*Math.cos(x/3)-o/3,M=S*Math.cos((x+2*Math.PI)/3)-o/3,D=S*Math.cos((x+4*Math.PI)/3)-o/3;return[G,M,D].filter(Wt)}if(l===0){let y=b<0?Yt(-b):-Yt(b),O=2*y-o/3,A=-y-o/3;return[O,A].filter(Wt)}let h=Math.sqrt(l),d=Yt(h-b),C=Yt(h+b);return[d-C-o/3].filter(Wt)}function Au(t,e,n,r,o){let s=Ou(t.x-o,e.x-o,n.x-o,r.x-o);return s.length>0?Qt(t,e,n,r,s[0]).y:NaN}function Zo(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 Se(n,t[r-1].x,t[r].x,t[r-1].y,t[r].y);return t[t.length-1].y}}function es(t,e){return n=>Au(v(0,0),t,e,v(1,1),n)}function ts(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)),i=r?s:0;return m=>{let u=Math.floor(m/n);return i+u*s}}function ns(t,e){let n=Number.MAX_VALUE,r={normal:v(0),distance:0};for(let o of[t,e])for(let s=0;s<o.pts.length;s++){let i=o.pts[s],u=o.pts[(s+1)%o.pts.length].sub(i).normal().unit(),c=Number.MAX_VALUE,p=-Number.MAX_VALUE;for(let d=0;d<t.pts.length;d++){let C=t.pts[d].dot(u);c=Math.min(c,C),p=Math.max(p,C)}let b=Number.MAX_VALUE,l=-Number.MAX_VALUE;for(let d=0;d<e.pts.length;d++){let C=e.pts[d].dot(u);b=Math.min(b,C),l=Math.max(l,C)}let h=Math.min(p,l)-Math.max(c,b);if(h<0)return null;if(h<Math.abs(n)){let d=l-c,C=b-p;n=Math.abs(d)<Math.abs(C)?d:C,r.normal=u,r.distance=n}}return r}function rs(t,e,n){return(e.x-t.x)*(n.y-t.y)-(e.y-t.y)*(n.x-t.x)>=0}function Su(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}function vr(t,e,n,r){let o=r.x-n.x,s=r.y-n.y,i=o*(t.y-n.y)-s*(t.x-n.x),m=o*(e.y-n.y)-s*(e.x-n.x);return i*m>=0}function Vu(t,e,n,r){return vr(t,e,n,r)&&vr(t,n,e,r)&&vr(t,r,e,n)}function Pu(t,e,n,r){for(let o of t)if(o!==e&&o!==n&&o!==r&&Vu(o,e,n,r))return!0;return!1}function Gu(t,e,n,r){return rs(t,e,n)&&!Pu(r,t,e,n)}function Gn(t){if(t.length<3)return[];if(t.length==3)return[t];let e=[],n=[],r=0;for(let b=0;b<t.length;b++){let l=t[r],h=t[b];(h.x<l.x||h.x==l.x&&h.y<l.y)&&(r=r),e[b]=b+1,n[b]=b-1}e[e.length-1]=0,n[0]=n.length-1,Su(t)||([e,n]=[n,e]);let o=[];for(let b=0;b<t.length;++b)rs(t[n[b]],t[b],t[e[b]])||o.push(t[b]);let s=[],i=t.length,m=1,u=0,c,p;for(;i>3;){c=e[m],p=n[m];let b=t[p],l=t[m],h=t[c];if(Gu(b,l,h,o))s.push([b,l,h]),e[p]=c,n[c]=p,o.splice(o.indexOf(l),1),--i,u=0;else if(++u>i)return[];m=c}return c=e[m],p=n[m],s.push([t[p],t[m],t[c]]),s}function os(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]),i=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)*i<0)return!1;return!0}var Mn=" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",lt="topleft";var ss="monospace",bt="monospace";var Jt="linear";var Zt=[{name:"a_pos",size:2},{name:"a_uv",size:2},{name:"a_color",size:4}],Mu=Zt.reduce((t,e)=>t+e.size,0),is=2048,as=is*4*Mu,us=is*6,cs=`
1
+ "use strict";var kaplay=(()=>{var yr=Object.defineProperty;var nu=Object.getOwnPropertyDescriptor;var ru=Object.getOwnPropertyNames;var ou=Object.prototype.hasOwnProperty;var su=(t,e)=>{for(var n in e)yr(t,n,{get:e[n],enumerable:!0})},iu=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ru(e))!ou.call(t,o)&&o!==n&&yr(t,o,{get:()=>e[o],enumerable:!(r=nu(e,o))||r.enumerable});return t};var au=t=>iu(yr({},"__esModule",{value:!0}),t);var Oo=(()=>{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,i=0;s<r;){var m=t[n.charCodeAt(s++)],u=t[n.charCodeAt(s++)],c=t[n.charCodeAt(s++)],p=t[n.charCodeAt(s++)];o[i++]=m<<2|u>>4,o[i++]=u<<4|c>>2,o[i++]=c<<6|p}return o}})();var hc={};su(hc,{_k:()=>a,default:()=>fc,kaplay:()=>Qa});var Ao={name:"kaplay",description:"KAPLAY is a JavaScript & TypeScript game library that helps you make games fast and fun!",version:"3001.0.14",license:"MIT",homepage:"https://kaplayjs.com/",bugs:{url:"https://github.com/kaplayjs/kaplay/issues"},funding:{type:"opencollective",url:"https://opencollective.com/kaplay"},repository:{type:"git",url:"git+https://github.com/kaplayjs/kaplay.git"},type:"module",main:"./dist/kaplay.cjs",module:"./dist/kaplay.mjs",types:"./dist/doc.d.ts",readme:"./README.md",exports:{".":{import:{types:"./dist/doc.d.ts",default:"./dist/kaplay.mjs"},require:{types:"./dist/doc.d.ts",default:"./dist/kaplay.cjs"}},"./global":"./dist/declaration/global.js"},typesVersions:{"*":{global:["./dist/declaration/global.d.ts"]}},keywords:["game development","javascript","typescript","game engine","2d games","physics engine","webgl","canvas","game library","kaplay"],files:["dist/","kaplay.webp","CHANGELOG.md"],scripts:{dev:"NODE_ENV=development node scripts/dev.js","win:dev":"set NODE_ENV=development && node scripts/dev.js",build:"node scripts/generateIndex.js && node scripts/build.js && npm run doc-dts",check:"tsc",fmt:"dprint fmt",test:"node scripts/test.js","doc-dts":"dts-bundle-generator -o dist/doc.d.ts src/index.ts","test:vite":"vitest --typecheck",desktop:"tauri dev",prepare:"npm run build","publish:next":"npm publish --tag next"},devDependencies:{"@kaplayjs/dprint-config":"^1.2.0","@types/jest":"^29.5.14",dprint:"^0.49.1","dts-bundle-generator":"^9.5.1",ejs:"^3.1.10",esbuild:"^0.25.2",express:"^5.1.0",puppeteer:"^22.15.0","tar-fs":"3.0.8",typescript:"5.6.3",vite:"5.4.16",vitest:"^3.1.1","vitest-environment-puppeteer":"^11.0.3","vitest-puppeteer":"^11.0.3"},engines:{node:">=20.0.0"},packageManager:"pnpm@9.9.0+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1"};function Te(t,e,n){return e>n?Te(t,n,e):Math.min(Math.max(t,e),n)}var j=class t{r=255;g=255;b=255;constructor(e,n,r){this.r=Te(e,0,255),this.g=Te(n,0,255),this.b=Te(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=(p,b,l)=>(l<0&&(l+=1),l>1&&(l-=1),l<1/6?p+(b-p)*6*l:l<1/2?b:l<2/3?p+(b-p)*(2/3-l)*6:p),s=r<.5?r*(1+n):r+n-r*n,i=2*r-s,m=o(i,s,e+1/3),u=o(i,s,e),c=o(i,s,e-1/3);return new t(Math.round(m*255),Math.round(u*255),Math.round(c*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(de(this.r,e.r,n),de(this.g,e.g,n),de(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),i=(o+s)/2,m=i,u=i;if(o==s)i=m=0;else{let c=o-s;switch(m=u>.5?c/(2-o-s):c/(o+s),o){case e:i=(n-r)/c+(n<r?6:0);break;case n:i=(r-e)/c+2;break;case r:i=(e-n)/c+4;break}i/=6}return[i,m,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 I(...t){if(t.length===0)return new j(255,255,255);if(t.length===1){if(t[0]instanceof j)return t[0].clone();if(typeof t[0]=="string")return j.fromHex(t[0]);if(Array.isArray(t[0])&&t[0].length===3)return j.fromArray(t[0])}else if(t.length===2){if(t[0]instanceof j)return t[0].clone()}else if(t.length===3||t.length===4)return new j(t[0],t[1],t[2]);throw new Error("Invalid color arguments")}var So=(t,e,n)=>j.fromHSL(t,e,n);function ae(t){return t*Math.PI/180}function ct(t){return t*180/Math.PI}function de(t,e,n){if(typeof t=="number"&&typeof e=="number")return t+(e-t)*n;if(t instanceof E&&e instanceof E)return t.lerp(e,n);if(t instanceof j&&e instanceof j)return t.lerp(e,n);throw new Error(`Bad value for lerp(): ${t}, ${e}. Only number, Vec2 and Color is supported.`)}function Se(t,e,n,r,o){return r+(t-e)/(n-e)*(o-r)}function Po(t,e,n,r,o){return Te(Se(t,e,n,r,o),r,o)}var E=class t{x=0;y=0;constructor(e=0,n=e){this.x=e,this.y=n}static fromAngle(e){let n=ae(e);return new t(Math.cos(n),Math.sin(n))}static fromArray(e){return new t(e[0],e[1])}static ZERO=new t(0,0);static ONE=new t(1,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=v(...e);return new t(this.x+n.x,this.y+n.y)}sub(...e){let n=v(...e);return new t(this.x-n.x,this.y-n.y)}scale(...e){let n=v(...e);return new t(this.x*n.x,this.y*n.y)}dist(...e){let n=v(...e);return this.sub(n).len()}sdist(...e){let n=v(...e);return this.sub(n).slen()}static sdist(e,n){let r=e.x-n.x,o=e.y-n.y;return r*r+o*o}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}static dot(e,n){return e.x*n.x+e.y*n.y}cross(e){return this.x*e.y-this.y*e.x}static cross(e,n){return e.x*n.y-e.y*n.x}angle(...e){let n=v(...e);return ct(Math.atan2(this.y-n.y,this.x-n.x))}angleBetween(...e){let n=v(...e);return ct(Math.atan2(this.cross(n),this.dot(n)))}lerp(e,n){return new t(de(this.x,e.x,n),de(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 W(this,0,0)}toString(){return`vec2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`}toArray(){return[this.x,this.y]}};function v(...t){if(t.length===1){if(t[0]instanceof E)return new E(t[0].x,t[0].y);if(Array.isArray(t[0])&&t[0].length===2)return new E(...t[0])}return new E(...t)}var q=class t{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 E(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 le(t,e,n,r){return new q(t,e,n,r)}var Rt=class t{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 v(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(v(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 gt=class t{m11;m12;m13;m21;m22;m23;m31;m32;m33;constructor(e,n,r,o,s,i,m,u,c){this.m11=e,this.m12=n,this.m13=r,this.m21=o,this.m22=s,this.m23=i,this.m31=m,this.m32=u,this.m33=c}static fromMat2(e){return new t(e.a,e.b,0,e.c,e.d,0,0,0,1)}toMat2(){return new Rt(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)}},fe=class t{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=ae(-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=ae(-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=ae(-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=ae(-e);let n=Math.cos(e),r=Math.sin(e),o=this.m[0],s=this.m[1],i=this.m[4],m=this.m[5];return this.m[0]=o*n+s*r,this.m[1]=-o*r+s*n,this.m[4]=i*n+m*r,this.m[5]=-i*r+m*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 E(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 E(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 E(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 E(e/n,n)}else return new E(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 ct(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 ct(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 E(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 E(0,Math.atan(this.m[0]*this.m[4]+this.m[1]*this.m[5])/(e*e))}else return new E(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],i=this.m[8]*this.m[14]-this.m[12]*this.m[10],m=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],c=this.m[5]*this.m[15]-this.m[13]*this.m[7],p=this.m[5]*this.m[14]-this.m[13]*this.m[6],b=this.m[4]*this.m[15]-this.m[12]*this.m[7],l=this.m[4]*this.m[14]-this.m[12]*this.m[6],h=this.m[5]*this.m[15]-this.m[13]*this.m[7],d=this.m[4]*this.m[13]-this.m[12]*this.m[5],C=this.m[6]*this.m[11]-this.m[10]*this.m[7],g=this.m[5]*this.m[11]-this.m[9]*this.m[7],y=this.m[5]*this.m[10]-this.m[9]*this.m[6],O=this.m[4]*this.m[11]-this.m[8]*this.m[7],A=this.m[4]*this.m[10]-this.m[8]*this.m[6],R=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]*i),e[8]=this.m[4]*r-this.m[5]*s+this.m[7]*m,e[12]=-(this.m[4]*o-this.m[5]*i+this.m[6]*m),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]*i,e[9]=-(this.m[0]*r-this.m[1]*s+this.m[3]*m),e[13]=this.m[0]*o-this.m[1]*i+this.m[2]*m,e[2]=this.m[1]*u-this.m[2]*c+this.m[3]*p,e[6]=-(this.m[0]*u-this.m[2]*b+this.m[3]*l),e[10]=this.m[0]*h-this.m[1]*b+this.m[3]*d,e[14]=-(this.m[0]*p-this.m[1]*l+this.m[2]*d),e[3]=-(this.m[1]*C-this.m[2]*g+this.m[3]*y),e[7]=this.m[0]*C-this.m[2]*O+this.m[3]*A,e[11]=-(this.m[0]*g-this.m[1]*O+this.m[3]*R),e[15]=this.m[0]*y-this.m[1]*A+this.m[2]*R;let V=this.m[0]*e[0]+this.m[1]*e[4]+this.m[2]*e[8]+this.m[3]*e[12];for(let x=0;x<4;x++)for(let w=0;w<4;w++)e[x*4+w]*=1/V;return new t(e)}clone(){return new t([...this.m])}toString(){return this.m.toString()}};function On(t,e,n,r=o=>-Math.cos(o)){return t+(r(n)+1)/2*(e-t)}var cu=1103515245,lu=12345,Vo=2147483648,$t=class{seed;constructor(e){this.seed=e}gen(){return this.seed=(cu*this.seed+lu)%Vo,this.seed/Vo}genNumber(e,n){return e+this.gen()*(n-e)}genVec2(e,n){return new E(this.genNumber(e.x,n.x),this.genNumber(e.y,n.y))}genColor(e,n){return new j(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 E)return this.genVec2(v(0,0),e[0]);if(e[0]instanceof j)return this.genColor(I(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 E&&e[1]instanceof E)return this.genVec2(e[0],e[1]);if(e[0]instanceof j&&e[1]instanceof j)return this.genColor(e[0],e[1])}throw new Error("More than 2 arguments not supported")}},wr=new $t(Date.now());function Go(t){return t!=null&&(wr.seed=t),wr.seed}function he(...t){return wr.genAny(...t)}function Cr(...t){return Math.floor(he(...t.length>0?t:[2]))}function Mo(t){return he()<=t}function Er(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}function Ro(t,e){return t.length<=e?t.slice():Er(t.slice()).slice(0,e)}function Do(t){return t[Cr(t.length)]}function Tr(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}function mu(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}function An(t,e){let n=mu(t,e);return n?v(t.p1.x+n*(t.p2.x-t.p1.x),t.p1.y+n*(t.p2.y-t.p1.y)):null}function Sn(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,i=(t.pos.x+t.width-e.p1.x)/n.x;r=Math.max(r,Math.min(s,i)),o=Math.min(o,Math.max(s,i))}if(n.y!=0){let s=(t.pos.y-e.p1.y)/n.y,i=(t.pos.y+t.height-e.p1.y)/n.y;r=Math.max(r,Math.min(s,i)),o=Math.min(o,Math.max(s,i))}return o>=r&&o>=0&&r<=1}function Dt(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}function Bo(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 v(n,r).sdist(e.center)<=e.radius*e.radius}function Fo(t,e){return Lo(e,new be(t.points()))}function Vn(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}function Bt(t,e){let n=t.p2.sub(t.p1),r=n.dot(n),o=t.p1.sub(e.center),s=2*n.dot(o),i=o.dot(o)-e.radius*e.radius,m=s*s-4*r*i;if(r<=Number.EPSILON||m<0)return!1;if(m==0){let u=-s/(2*r);if(u>=0&&u<=1)return!0}else{let u=(-s+Math.sqrt(m))/(2*r),c=(-s-Math.sqrt(m))/(2*r);if(u>=0&&u<=1||c>=0&&c<=1)return!0}return Pn(e,t.p1)}function Or(t,e){if(Ze(e,t.p1)||Ze(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(An(t,new Oe(r,o)))return!0}return!1}function Pn(t,e){return t.center.sdist(e)<t.radius*t.radius}function pu(t,e){return t.center.sdist(e.center)<(t.radius+e.radius)*(t.radius+e.radius)}function Xt(t,e){let n=e.pts[e.pts.length-1];for(let r of e.pts){if(Bt(new Oe(n,r),t))return!0;n=r}return Pn(t,e.pts[0])?!0:Ze(e,t.center)}function Lo(t,e){for(let n=0;n<t.pts.length;n++)if(Or(new Oe(t.pts[n],t.pts[(n+1)%t.pts.length]),e))return!0;return!!(t.pts.some(n=>Ze(e,n))||e.pts.some(n=>Ze(t,n)))}function Ze(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}function Ar(t,e){e=e.sub(t.center);let n=ae(t.angle),r=Math.cos(n),o=Math.sin(n),s=e.x*r+e.y*o,i=-e.x*o+e.y*r;return s*s/(t.radiusX*t.radiusX)+i*i/(t.radiusY*t.radiusY)<1}function En(t,e){let n=e.center.sub(t.center),r=ae(t.angle),o=Math.cos(r),s=Math.sin(r),i=n.x*o+n.y*s,m=-n.x*s+n.y*o;return Ar(new Ke(v(),t.radiusX+e.radius,t.radiusY+e.radius,0),v(i,m))}function jo(t,e){let n=t.toMat2().inverse;return e=new Oe(n.transform(e.p1.sub(t.center)),n.transform(e.p2.sub(t.center))),Bt(e,new we(v(),1))}function du(t,e){if(t.radiusX===t.radiusY)return En(e,new we(t.center,t.radiusX));if(e.radiusX===e.radiusY)return En(t,new we(e.center,e.radiusX));let n=new gt(1/t.radiusX**2,0,0,0,1/t.radiusY**2,0,0,0,-1),r=new gt(1/e.radiusX**2,0,0,0,1/e.radiusY**2,0,0,0,-1),o=t.center.x,s=t.center.y,i=e.center.x,m=e.center.y,u=ae(t.angle),c=ae(e.angle),p=new gt(Math.cos(u),-Math.sin(u),o,Math.sin(u),Math.cos(u),s,0,0,1),b=new gt(Math.cos(c),-Math.sin(c),i,Math.sin(c),Math.cos(c),m,0,0,1),l=p.inverse,h=b.inverse,d=l.transpose.mul(n).mul(l),C=h.transpose.mul(r).mul(h),g=d.m11,y=d.m12,O=d.m13,A=d.m21,R=d.m22,V=d.m23,x=d.m31,w=d.m32,S=d.m33,G=C.m11,M=C.m12,D=C.m13,L=C.m21,U=C.m22,H=C.m23,Y=C.m31,_=C.m32,K=C.m33,J=g*R*S-g*V*w-y*A*S+y*V*x+O*A*w-O*R*x,$=(g*R*K-g*V*_-g*w*H+g*S*U-y*A*K+y*V*Y+y*x*H-y*S*L+O*A*_-O*R*Y-O*x*U+O*w*L+A*w*D-A*S*M-R*x*D+R*S*G+V*x*M-V*w*G)/J,Z=(g*U*K-g*H*_-y*L*K+y*H*Y+O*L*_-O*U*Y-A*M*K+A*D*_+R*G*K-R*D*Y-V*G*_+V*M*Y+x*M*H-x*D*U-w*G*H+w*D*L+S*G*U-S*M*L)/J,Ee=(G*U*K-G*H*_-M*L*K+M*H*Y+D*L*_-D*U*Y)/J;if($>=0){let k=-3*Z+$**2,ht=3*$*Ee+Z*$**2-4*Z**2,Pt=-27*Ee**2+18*Ee*$*Z+$**2*Z**2-4*$**3*Ee-4*Z**3;return!(k>0&&ht<0&&Pt>0)}else{let k=-3*Z+$**2,ht=-27*Ee**2+18*Ee*$*Z+$**2*Z**2-4*$**3*Ee-4*Z**3;return!(k>0&&ht>0)}}function Io(t,e){return Sr(t,new be(e.points()))}function Sr(t,e){let n=t.toMat2().inverse;return e=new be(e.pts.map(r=>n.transform(r.sub(t.center)))),Xt(new we(v(),1),e)}function fu(t,e){return t.x===e.x&&t.y===e.y}function hu(t,e){return e instanceof E?fu(e,t.pt):e instanceof we?Pn(e,t.pt):e instanceof Oe?Vn(e,t.pt):e instanceof W?Dt(e,t.pt):e instanceof be?Ze(e,t.pt):e instanceof Ke?Ar(e,t.pt):!1}function gu(t,e){return e instanceof E?Vn(t,e):e instanceof we?Bt(t,e):e instanceof Oe?An(t,e)!=null:e instanceof W?Sn(e,t):e instanceof be?Or(t,e):e instanceof Ke?jo(e,t):!1}function bu(t,e){return e instanceof E?Pn(t,e):e instanceof we?pu(t,e):e instanceof Oe?Bt(e,t):e instanceof W?Bo(e,t):e instanceof be?Xt(t,e):e instanceof Ke?En(e,t):!1}function yu(t,e){return e instanceof E?Dt(t,e):e instanceof we?Bo(t,e):e instanceof Oe?Sn(t,e):e instanceof W?Tr(t,e):e instanceof be?Fo(t,e):e instanceof Ke?Io(e,t):!1}function xu(t,e){return e instanceof E?Ze(t,e):e instanceof we?Xt(e,t):e instanceof Oe?Or(e,t):e instanceof W?Fo(e,t):e instanceof be?Lo(e,t):e instanceof Ke?Sr(e,t):!1}function vu(t,e){return e instanceof E?Ar(t,e):e instanceof we?En(t,e):e instanceof Oe?jo(t,e):e instanceof W?Io(t,e):e instanceof be?Sr(t,e):e instanceof Ke?du(e,t):!1}function Ko(t,e,n){let r=t,o=n.p1,s=n.p2,i=e,m=s.sub(o),u=i.cross(m);if(Math.abs(u)<Number.EPSILON)return null;let c=o.sub(r),p=c.cross(m)/u;if(p<=0||p>=1)return null;let b=c.cross(i)/u;if(b<=0||b>=1)return null;let l=m.normal().unit();return e.dot(l)>0&&(l.x*=-1,l.y*=-1),{point:r.add(i.scale(p)),normal:l,fraction:p}}function wu(t,e,n){let r=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,s;if(t.x!=0){let i=(n.pos.x-t.x)/e.x,m=(n.pos.x+n.width-t.x)/e.x;s=v(-Math.sign(e.x),0),r=Math.max(r,Math.min(i,m)),o=Math.min(o,Math.max(i,m))}if(t.y!=0){let i=(n.pos.y-t.y)/e.y,m=(n.pos.y+n.height-t.y)/e.y;Math.min(i,m)>r&&(s=v(0,-Math.sign(e.y))),r=Math.max(r,Math.min(i,m)),o=Math.min(o,Math.max(i,m))}return o>=r&&r>=0&&r<=1?{point:t.add(e.scale(r)),normal:s,fraction:r}:null}function ko(t,e,n){let r=t,o=n.center,s=e,i=s.dot(s),m=r.sub(o),u=2*s.dot(m),c=m.dot(m)-n.radius*n.radius,p=u*u-4*i*c;if(i<=Number.EPSILON||p<0)return null;if(p==0){let b=-u/(2*i);if(b>=0&&b<=1){let l=r.add(s.scale(b));return{point:l,normal:l.sub(o),fraction:b}}}else{let b=(-u+Math.sqrt(p))/(2*i),l=(-u-Math.sqrt(p))/(2*i),h=null;if(b>=0&&b<=1&&(h=b),l>=0&&l<=1&&(h=Math.min(l,h??l)),h!=null){let d=r.add(s.scale(h));return{point:d,normal:d.sub(o).unit(),fraction:h}}}return null}function Cu(t,e,n){let r=n.pts,o=null,s=r[r.length-1];for(let i=0;i<r.length;i++){let m=r[i],u=Ko(t,e,new Oe(s,m));u&&(!o||o.fraction>u.fraction)&&(o=u),s=m}return o}function Eu(t,e,n){let r=n.toMat2(),o=r.inverse,s=o.transform(t.sub(n.center)),i=o.transform(e),m=ko(s,i,new we(v(),1));if(m){let u=Rt.rotation(ae(-n.angle)),p=Rt.scale(n.radiusX,n.radiusY).transform(m.point),b=r.transform(m.point).add(n.center),l=b.dist(t)/e.len();return{point:b,normal:u.transform(v(n.radiusY**2*p.x,n.radiusX**2*p.y)).unit(),fraction:l}}return m}function _o(t,e,n,r=64){let o=t,s=e.len(),i=e.scale(1/s),m=0,u=v(Math.floor(t.x),Math.floor(t.y)),c=v(i.x>0?1:-1,i.y>0?1:-1),p=v(Math.abs(1/i.x),Math.abs(1/i.y)),b=v(c.x>0?u.x+1-t.x:t.x-u.x,c.y>0?u.y+1-t.y:t.y-u.y),l=v(p.x<1/0?p.x*b.x:1/0,p.y<1/0?p.y*b.y:1/0),h=-1;for(;m<=r;){let d=n(u);if(d===!0)return{point:o.add(i.scale(m)),normal:v(h===0?-c.x:0,h===1?-c.y:0),fraction:m/s,gridPos:u};if(d)return d;l.x<l.y?(u.x+=c.x,m=l.x,l.x+=p.x,h=0):(u.y+=c.y,m=l.y,l.y+=p.y,h=1)}return null}var Tn=class t{pt;constructor(e){this.pt=e.clone()}transform(e){return new t(e.multVec2(this.pt))}bbox(){return new W(this.pt,0,0)}area(){return 0}clone(){return new t(this.pt)}collides(e){return hu(this,e)}contains(e){return this.pt.eq(e)}raycast(e,n){return null}random(){return this.pt.clone()}},Oe=class t{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 W.fromPoints(this.p1,this.p2)}area(){return this.p1.dist(this.p2)}clone(){return new t(this.p1,this.p2)}collides(e){return gu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return Ko(e,n,this)}random(){return this.p1.add(this.p2.sub(this.p1).scale(he(1)))}},W=class t{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 E(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 be(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 yu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return wu(e,n,this)}random(){return this.pos.add(he(this.width),he(this.height))}},we=class t{center;radius;constructor(e,n){this.center=e.clone(),this.radius=n}transform(e){return new Ke(this.center,this.radius,this.radius).transform(e)}bbox(){return W.fromPoints(this.center.sub(v(this.radius)),this.center.add(v(this.radius)))}area(){return this.radius*this.radius*Math.PI}clone(){return new t(this.center,this.radius)}collides(e){return bu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return ko(e,n,this)}random(){return this.center.add(E.fromAngle(he(360)).scale(he(this.radius)))}},Ke=class t{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,[i,m]=r.eigenvectors(o,s),[u,c]=[1/Math.sqrt(o),1/Math.sqrt(s)];return u>c?new t(v(),u,c,ct(Math.atan2(-i[1],i[0]))):new t(v(),c,u,ct(Math.atan2(-m[1],m[0])))}toMat2(){let e=ae(this.angle),n=Math.cos(e),r=Math.sin(e);return new Rt(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=gt.fromMat2(n).scale(o.x,o.y).rotate(r).toMat2();let i=t.fromMat2(n);return i.center=e.multVec2(this.center),i}}bbox(){if(this.angle==0)return W.fromPoints(this.center.sub(v(this.radiusX,this.radiusY)),this.center.add(v(this.radiusX,this.radiusY)));{let e=ae(this.angle),n=Math.cos(e),r=Math.sin(e),o=this.radiusX*n,s=this.radiusX*r,i=this.radiusY*r,m=this.radiusY*n,u=Math.sqrt(o*o+i*i),c=Math.sqrt(s*s+m*m);return W.fromPoints(this.center.sub(v(u,c)),this.center.add(v(u,c)))}}area(){return this.radiusX*this.radiusY*Math.PI}clone(){return new t(this.center,this.radiusX,this.radiusY,this.angle)}collides(e){return vu(this,e)}contains(e){e=e.sub(this.center);let n=ae(this.angle),r=Math.cos(n),o=Math.sin(n),s=e.x*r+e.y*o,i=-e.x*o+e.y*r;return s*s/(this.radiusX*this.radiusX)+i*i/(this.radiusY*this.radiusY)<1}raycast(e,n){return Eu(e,n,this)}random(){return this.center}};function Tu(t,e,n,r){let o=e.sub(t),s=r.sub(n),i=o.cross(s);return i<1e-5&&i>-1e-5||(i=n.sub(t).cross(s)/i,i<0||i>1)?null:t.add(o.scale(i))}var be=class t{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=v(Number.MAX_VALUE),n=v(-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 W.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 xu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return Cu(e,n,this)}random(){return v()}cut(e,n){let r=new Oe(e,n),o=[],s=[],i=n.sub(e),m=this.pts[this.pts.length-1],u=m.sub(e),c=i.cross(u)>0;return this.pts.forEach(p=>{u=p.sub(e);let b=i.cross(u)>0;if(c!=b){let l=Tu(m,p,e,n);o.push(l),s.push(l),c=b}(b?o:s).push(p),m=p}),[o.length?new t(o):null,s.length?new t(s):null]}};function No(t,e,n,r){let o=r*r,s=1-r,i=s*s;return t.scale(i).add(e.scale(2*s*r)).add(n.scale(o))}function Uo(t,e,n,r){let o=1-r;return e.sub(t).scale(2*o).add(n.sub(e).scale(2*r))}function Ho(t,e,n,r){return n.sub(e.scale(2)).add(t).scale(2)}function Qt(t,e,n,r,o){let s=o*o,i=s*o,m=1-o,u=m*m,c=u*m;return t.scale(c).add(e.scale(3*u*o)).add(n.scale(3*m*s)).add(r.scale(i))}function qo(t,e,n,r,o){let s=o*o,i=1-o,m=i*i;return e.sub(t).scale(3*m).add(n.sub(e).scale(6*i*o)).add(r.sub(n).scale(3*s))}function zo(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))}function Wo(t,e,n,r,o){let s=.5*(((-o+2)*o-1)*o),i=.5*((3*o-5)*o*o+2),m=.5*(((-3*o+4)*o+1)*o),u=.5*((o-1)*o*o);return t.scale(s).add(e.scale(i)).add(n.scale(m)).add(r.scale(u))}function Yo(t,e,n,r,o){let s=.5*((-3*o+4)*o-1),i=.5*((9*o-10)*o),m=.5*((-9*o+8)*o+1),u=.5*((3*o-2)*o);return t.scale(s).add(e.scale(i)).add(n.scale(m)).add(r.scale(u))}function $o(t){let e=Vr(t),n=e(1);return r=>{let o=r*n,s=e(o,!0);return t(s)}}function Vr(t,e=10,n=10){let r=[0],o=[0],i=1/(e-1)/n,m=0,u=t(0),c=0;for(let p=1;p<e;p++){for(let b=0;b<n;b++){c+=i;let l=t(c),h=l.dist(u);m+=h,u=l}r[p]=m,o[p]=c}return o[e-1]=1,(p,b=!1)=>{if(b){let l=p;if(l<=0)return 0;if(l>=m)return 1;let h=0;for(;r[h+1]<l;)h++;let d=o[h],C=o[h+1],g=r[h],y=r[h+1],O=(l-g)/(y-g);return d+(C-d)*O}else{if(p<=0)return 0;if(p>=1)return r[e-1];let l=0;for(;o[l+1]<p;)l++;let h=o[l],d=o[l+1],C=r[l],g=r[l+1],y=(p-h)/(d-h);return C+(g-C)*y}}}function Ft(t,e,n,r){let o=2*t+e-2*r+n,s=-3*t+3*r-2*e-n,i=e,m=t;return u=>{let c=u*u,p=c*u;return o*p+s*c+i*u+m}}function Pr(t,e,n,r,o,s=Ft){let i=s(e.x,(1-o)*(n.x-t.x),(1-o)*(r.x-e.x),n.x),m=s(e.y,(1-o)*(n.y-t.y),(1-o)*(r.y-e.y),n.y);return u=>new E(i(u),m(u))}function Lt(t,e,n,r,o=Ft){return Pr(t,e,n,r,.5,o)}function Xo(t,e,n,r,o=Ft){return Lt(r.add(t.sub(e).scale(6)),t,r,t.add(r.sub(n).scale(6)),o)}function Qo(t,e,n,r,o,s,i,m=Ft){let u=m(e.x,.5*(1-o)*(1+i)*(1+s)*(e.x-t.x)+.5*(1-o)*(1-i)*(1-s)*(n.x-e.x),.5*(1-o)*(1+i)*(1-s)*(n.x-e.x)+.5*(1-o)*(1-i)*(1+s)*(r.x-n.x),n.x),c=m(e.y,.5*(1-o)*(1+i)*(1+s)*(e.y-t.y)+.5*(1-o)*(1-i)*(1-s)*(n.y-e.y),.5*(1-o)*(1+i)*(1-s)*(n.y-e.y)+.5*(1-o)*(1-i)*(1+s)*(r.y-n.y),n.y);return p=>new E(u(p),c(p))}function Jo(t,e,n,r){let o=2*t+e-2*r+n,s=-3*t+3*r-2*e+n,i=e;return m=>{let u=m*m;return 3*o*u+2*s*m+i}}function Wt(t){return 0<=t&&t<=1}function xr(t,e){return Math.abs(t-e)<=Number.EPSILON}function Yt(t){return t<0?-Math.pow(-t,1/3):Math.pow(t,1/3)}function Ou(t,e,n,r){let o=3*t-6*e+3*n,s=-3*t+3*e,i=t,m=-t+3*e-3*n+r;if(xr(m,0)){if(xr(o,0))return xr(s,0)?[]:[-i/s].filter(Wt);let y=Math.sqrt(s*s-4*o*i),O=2*o;return[(y-s)/O,(-s-y)/O].filter(Wt)}o/=m,s/=m,i/=m;let u=(3*s-o*o)/3,c=u/3,p=(2*o*o*o-9*o*s+27*i)/27,b=p/2,l=b*b+c*c*c;if(l<0){let y=-u/3,O=y*y*y,A=Math.sqrt(O),R=-p/(2*A),V=R<-1?-1:R>1?1:R,x=Math.acos(V),S=2*Yt(A),G=S*Math.cos(x/3)-o/3,M=S*Math.cos((x+2*Math.PI)/3)-o/3,D=S*Math.cos((x+4*Math.PI)/3)-o/3;return[G,M,D].filter(Wt)}if(l===0){let y=b<0?Yt(-b):-Yt(b),O=2*y-o/3,A=-y-o/3;return[O,A].filter(Wt)}let h=Math.sqrt(l),d=Yt(h-b),C=Yt(h+b);return[d-C-o/3].filter(Wt)}function Au(t,e,n,r,o){let s=Ou(t.x-o,e.x-o,n.x-o,r.x-o);return s.length>0?Qt(t,e,n,r,s[0]).y:NaN}function Zo(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 Se(n,t[r-1].x,t[r].x,t[r-1].y,t[r].y);return t[t.length-1].y}}function es(t,e){return n=>Au(v(0,0),t,e,v(1,1),n)}function ts(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)),i=r?s:0;return m=>{let u=Math.floor(m/n);return i+u*s}}function ns(t,e){let n=Number.MAX_VALUE,r={normal:v(0),distance:0};for(let o of[t,e])for(let s=0;s<o.pts.length;s++){let i=o.pts[s],u=o.pts[(s+1)%o.pts.length].sub(i).normal().unit(),c=Number.MAX_VALUE,p=-Number.MAX_VALUE;for(let d=0;d<t.pts.length;d++){let C=t.pts[d].dot(u);c=Math.min(c,C),p=Math.max(p,C)}let b=Number.MAX_VALUE,l=-Number.MAX_VALUE;for(let d=0;d<e.pts.length;d++){let C=e.pts[d].dot(u);b=Math.min(b,C),l=Math.max(l,C)}let h=Math.min(p,l)-Math.max(c,b);if(h<0)return null;if(h<Math.abs(n)){let d=l-c,C=b-p;n=Math.abs(d)<Math.abs(C)?d:C,r.normal=u,r.distance=n}}return r}function rs(t,e,n){return(e.x-t.x)*(n.y-t.y)-(e.y-t.y)*(n.x-t.x)>=0}function Su(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}function vr(t,e,n,r){let o=r.x-n.x,s=r.y-n.y,i=o*(t.y-n.y)-s*(t.x-n.x),m=o*(e.y-n.y)-s*(e.x-n.x);return i*m>=0}function Vu(t,e,n,r){return vr(t,e,n,r)&&vr(t,n,e,r)&&vr(t,r,e,n)}function Pu(t,e,n,r){for(let o of t)if(o!==e&&o!==n&&o!==r&&Vu(o,e,n,r))return!0;return!1}function Gu(t,e,n,r){return rs(t,e,n)&&!Pu(r,t,e,n)}function Gn(t){if(t.length<3)return[];if(t.length==3)return[t];let e=[],n=[],r=0;for(let b=0;b<t.length;b++){let l=t[r],h=t[b];(h.x<l.x||h.x==l.x&&h.y<l.y)&&(r=r),e[b]=b+1,n[b]=b-1}e[e.length-1]=0,n[0]=n.length-1,Su(t)||([e,n]=[n,e]);let o=[];for(let b=0;b<t.length;++b)rs(t[n[b]],t[b],t[e[b]])||o.push(t[b]);let s=[],i=t.length,m=1,u=0,c,p;for(;i>3;){c=e[m],p=n[m];let b=t[p],l=t[m],h=t[c];if(Gu(b,l,h,o))s.push([b,l,h]),e[p]=c,n[c]=p,o.splice(o.indexOf(l),1),--i,u=0;else if(++u>i)return[];m=c}return c=e[m],p=n[m],s.push([t[p],t[m],t[c]]),s}function os(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]),i=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)*i<0)return!1;return!0}var Mn=" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",lt="topleft";var ss="monospace",bt="monospace";var Jt="linear";var Zt=[{name:"a_pos",size:2},{name:"a_uv",size:2},{name:"a_color",size:4}],Mu=Zt.reduce((t,e)=>t+e.size,0),is=2048,as=is*4*Mu,us=is*6,cs=`
2
2
  attribute vec2 a_pos;
3
3
  attribute vec2 a_uv;
4
4
  attribute vec4 a_color;
package/dist/kaplay.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var yr=Object.defineProperty;var nu=Object.getOwnPropertyDescriptor;var ru=Object.getOwnPropertyNames;var ou=Object.prototype.hasOwnProperty;var su=(t,e)=>{for(var n in e)yr(t,n,{get:e[n],enumerable:!0})},iu=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ru(e))!ou.call(t,o)&&o!==n&&yr(t,o,{get:()=>e[o],enumerable:!(r=nu(e,o))||r.enumerable});return t};var au=t=>iu(yr({},"__esModule",{value:!0}),t);var Oo=(()=>{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,i=0;s<r;){var m=t[n.charCodeAt(s++)],u=t[n.charCodeAt(s++)],c=t[n.charCodeAt(s++)],p=t[n.charCodeAt(s++)];o[i++]=m<<2|u>>4,o[i++]=u<<4|c>>2,o[i++]=c<<6|p}return o}})();var hc={};su(hc,{_k:()=>a,default:()=>fc,kaplay:()=>Qa});module.exports=au(hc);var Ao={name:"kaplay",description:"KAPLAY is a JavaScript & TypeScript game library that helps you make games fast and fun!",version:"3001.0.13",license:"MIT",homepage:"https://kaplayjs.com/",bugs:{url:"https://github.com/kaplayjs/kaplay/issues"},funding:{type:"opencollective",url:"https://opencollective.com/kaplay"},repository:{type:"git",url:"git+https://github.com/kaplayjs/kaplay.git"},type:"module",main:"./dist/kaplay.cjs",module:"./dist/kaplay.mjs",types:"./dist/doc.d.ts",readme:"./README.md",exports:{".":{import:{types:"./dist/doc.d.ts",default:"./dist/kaplay.mjs"},require:{types:"./dist/doc.d.ts",default:"./dist/kaplay.cjs"}},"./global":"./dist/declaration/global.js"},typesVersions:{"*":{global:["./dist/declaration/global.d.ts"]}},keywords:["game development","javascript","typescript","game engine","2d games","physics engine","webgl","canvas","game library","kaplay"],files:["dist/","kaplay.webp","CHANGELOG.md"],scripts:{dev:"NODE_ENV=development node scripts/dev.js","win:dev":"set NODE_ENV=development && node scripts/dev.js",build:"node scripts/generateIndex.js && node scripts/build.js && npm run doc-dts",check:"tsc",fmt:"dprint fmt",test:"node scripts/test.js","doc-dts":"dts-bundle-generator -o dist/doc.d.ts src/index.ts","test:vite":"vitest --typecheck",desktop:"tauri dev",prepare:"npm run build","publish:next":"npm publish --tag next"},devDependencies:{"@kaplayjs/dprint-config":"^1.2.0","@types/jest":"^29.5.14",dprint:"^0.49.1","dts-bundle-generator":"^9.5.1",ejs:"^3.1.10",esbuild:"^0.25.2",express:"^5.1.0",puppeteer:"^22.15.0","tar-fs":"3.0.8",typescript:"5.6.3",vite:"5.4.16",vitest:"^3.1.1","vitest-environment-puppeteer":"^11.0.3","vitest-puppeteer":"^11.0.3"},engines:{node:">=20.0.0"},packageManager:"pnpm@9.9.0+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1"};function Te(t,e,n){return e>n?Te(t,n,e):Math.min(Math.max(t,e),n)}var j=class t{r=255;g=255;b=255;constructor(e,n,r){this.r=Te(e,0,255),this.g=Te(n,0,255),this.b=Te(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=(p,b,l)=>(l<0&&(l+=1),l>1&&(l-=1),l<1/6?p+(b-p)*6*l:l<1/2?b:l<2/3?p+(b-p)*(2/3-l)*6:p),s=r<.5?r*(1+n):r+n-r*n,i=2*r-s,m=o(i,s,e+1/3),u=o(i,s,e),c=o(i,s,e-1/3);return new t(Math.round(m*255),Math.round(u*255),Math.round(c*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(de(this.r,e.r,n),de(this.g,e.g,n),de(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),i=(o+s)/2,m=i,u=i;if(o==s)i=m=0;else{let c=o-s;switch(m=u>.5?c/(2-o-s):c/(o+s),o){case e:i=(n-r)/c+(n<r?6:0);break;case n:i=(r-e)/c+2;break;case r:i=(e-n)/c+4;break}i/=6}return[i,m,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 I(...t){if(t.length===0)return new j(255,255,255);if(t.length===1){if(t[0]instanceof j)return t[0].clone();if(typeof t[0]=="string")return j.fromHex(t[0]);if(Array.isArray(t[0])&&t[0].length===3)return j.fromArray(t[0])}else if(t.length===2){if(t[0]instanceof j)return t[0].clone()}else if(t.length===3||t.length===4)return new j(t[0],t[1],t[2]);throw new Error("Invalid color arguments")}var So=(t,e,n)=>j.fromHSL(t,e,n);function ae(t){return t*Math.PI/180}function ct(t){return t*180/Math.PI}function de(t,e,n){if(typeof t=="number"&&typeof e=="number")return t+(e-t)*n;if(t instanceof E&&e instanceof E)return t.lerp(e,n);if(t instanceof j&&e instanceof j)return t.lerp(e,n);throw new Error(`Bad value for lerp(): ${t}, ${e}. Only number, Vec2 and Color is supported.`)}function Se(t,e,n,r,o){return r+(t-e)/(n-e)*(o-r)}function Po(t,e,n,r,o){return Te(Se(t,e,n,r,o),r,o)}var E=class t{x=0;y=0;constructor(e=0,n=e){this.x=e,this.y=n}static fromAngle(e){let n=ae(e);return new t(Math.cos(n),Math.sin(n))}static fromArray(e){return new t(e[0],e[1])}static ZERO=new t(0,0);static ONE=new t(1,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=v(...e);return new t(this.x+n.x,this.y+n.y)}sub(...e){let n=v(...e);return new t(this.x-n.x,this.y-n.y)}scale(...e){let n=v(...e);return new t(this.x*n.x,this.y*n.y)}dist(...e){let n=v(...e);return this.sub(n).len()}sdist(...e){let n=v(...e);return this.sub(n).slen()}static sdist(e,n){let r=e.x-n.x,o=e.y-n.y;return r*r+o*o}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}static dot(e,n){return e.x*n.x+e.y*n.y}cross(e){return this.x*e.y-this.y*e.x}static cross(e,n){return e.x*n.y-e.y*n.x}angle(...e){let n=v(...e);return ct(Math.atan2(this.y-n.y,this.x-n.x))}angleBetween(...e){let n=v(...e);return ct(Math.atan2(this.cross(n),this.dot(n)))}lerp(e,n){return new t(de(this.x,e.x,n),de(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 W(this,0,0)}toString(){return`vec2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`}toArray(){return[this.x,this.y]}};function v(...t){if(t.length===1){if(t[0]instanceof E)return new E(t[0].x,t[0].y);if(Array.isArray(t[0])&&t[0].length===2)return new E(...t[0])}return new E(...t)}var q=class t{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 E(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 le(t,e,n,r){return new q(t,e,n,r)}var Rt=class t{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 v(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(v(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 gt=class t{m11;m12;m13;m21;m22;m23;m31;m32;m33;constructor(e,n,r,o,s,i,m,u,c){this.m11=e,this.m12=n,this.m13=r,this.m21=o,this.m22=s,this.m23=i,this.m31=m,this.m32=u,this.m33=c}static fromMat2(e){return new t(e.a,e.b,0,e.c,e.d,0,0,0,1)}toMat2(){return new Rt(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)}},fe=class t{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=ae(-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=ae(-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=ae(-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=ae(-e);let n=Math.cos(e),r=Math.sin(e),o=this.m[0],s=this.m[1],i=this.m[4],m=this.m[5];return this.m[0]=o*n+s*r,this.m[1]=-o*r+s*n,this.m[4]=i*n+m*r,this.m[5]=-i*r+m*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 E(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 E(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 E(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 E(e/n,n)}else return new E(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 ct(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 ct(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 E(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 E(0,Math.atan(this.m[0]*this.m[4]+this.m[1]*this.m[5])/(e*e))}else return new E(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],i=this.m[8]*this.m[14]-this.m[12]*this.m[10],m=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],c=this.m[5]*this.m[15]-this.m[13]*this.m[7],p=this.m[5]*this.m[14]-this.m[13]*this.m[6],b=this.m[4]*this.m[15]-this.m[12]*this.m[7],l=this.m[4]*this.m[14]-this.m[12]*this.m[6],h=this.m[5]*this.m[15]-this.m[13]*this.m[7],d=this.m[4]*this.m[13]-this.m[12]*this.m[5],C=this.m[6]*this.m[11]-this.m[10]*this.m[7],g=this.m[5]*this.m[11]-this.m[9]*this.m[7],y=this.m[5]*this.m[10]-this.m[9]*this.m[6],O=this.m[4]*this.m[11]-this.m[8]*this.m[7],A=this.m[4]*this.m[10]-this.m[8]*this.m[6],R=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]*i),e[8]=this.m[4]*r-this.m[5]*s+this.m[7]*m,e[12]=-(this.m[4]*o-this.m[5]*i+this.m[6]*m),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]*i,e[9]=-(this.m[0]*r-this.m[1]*s+this.m[3]*m),e[13]=this.m[0]*o-this.m[1]*i+this.m[2]*m,e[2]=this.m[1]*u-this.m[2]*c+this.m[3]*p,e[6]=-(this.m[0]*u-this.m[2]*b+this.m[3]*l),e[10]=this.m[0]*h-this.m[1]*b+this.m[3]*d,e[14]=-(this.m[0]*p-this.m[1]*l+this.m[2]*d),e[3]=-(this.m[1]*C-this.m[2]*g+this.m[3]*y),e[7]=this.m[0]*C-this.m[2]*O+this.m[3]*A,e[11]=-(this.m[0]*g-this.m[1]*O+this.m[3]*R),e[15]=this.m[0]*y-this.m[1]*A+this.m[2]*R;let V=this.m[0]*e[0]+this.m[1]*e[4]+this.m[2]*e[8]+this.m[3]*e[12];for(let x=0;x<4;x++)for(let w=0;w<4;w++)e[x*4+w]*=1/V;return new t(e)}clone(){return new t([...this.m])}toString(){return this.m.toString()}};function On(t,e,n,r=o=>-Math.cos(o)){return t+(r(n)+1)/2*(e-t)}var cu=1103515245,lu=12345,Vo=2147483648,$t=class{seed;constructor(e){this.seed=e}gen(){return this.seed=(cu*this.seed+lu)%Vo,this.seed/Vo}genNumber(e,n){return e+this.gen()*(n-e)}genVec2(e,n){return new E(this.genNumber(e.x,n.x),this.genNumber(e.y,n.y))}genColor(e,n){return new j(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 E)return this.genVec2(v(0,0),e[0]);if(e[0]instanceof j)return this.genColor(I(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 E&&e[1]instanceof E)return this.genVec2(e[0],e[1]);if(e[0]instanceof j&&e[1]instanceof j)return this.genColor(e[0],e[1])}throw new Error("More than 2 arguments not supported")}},wr=new $t(Date.now());function Go(t){return t!=null&&(wr.seed=t),wr.seed}function he(...t){return wr.genAny(...t)}function Cr(...t){return Math.floor(he(...t.length>0?t:[2]))}function Mo(t){return he()<=t}function Er(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}function Ro(t,e){return t.length<=e?t.slice():Er(t.slice()).slice(0,e)}function Do(t){return t[Cr(t.length)]}function Tr(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}function mu(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}function An(t,e){let n=mu(t,e);return n?v(t.p1.x+n*(t.p2.x-t.p1.x),t.p1.y+n*(t.p2.y-t.p1.y)):null}function Sn(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,i=(t.pos.x+t.width-e.p1.x)/n.x;r=Math.max(r,Math.min(s,i)),o=Math.min(o,Math.max(s,i))}if(n.y!=0){let s=(t.pos.y-e.p1.y)/n.y,i=(t.pos.y+t.height-e.p1.y)/n.y;r=Math.max(r,Math.min(s,i)),o=Math.min(o,Math.max(s,i))}return o>=r&&o>=0&&r<=1}function Dt(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}function Bo(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 v(n,r).sdist(e.center)<=e.radius*e.radius}function Fo(t,e){return Lo(e,new be(t.points()))}function Vn(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}function Bt(t,e){let n=t.p2.sub(t.p1),r=n.dot(n),o=t.p1.sub(e.center),s=2*n.dot(o),i=o.dot(o)-e.radius*e.radius,m=s*s-4*r*i;if(r<=Number.EPSILON||m<0)return!1;if(m==0){let u=-s/(2*r);if(u>=0&&u<=1)return!0}else{let u=(-s+Math.sqrt(m))/(2*r),c=(-s-Math.sqrt(m))/(2*r);if(u>=0&&u<=1||c>=0&&c<=1)return!0}return Pn(e,t.p1)}function Or(t,e){if(Ze(e,t.p1)||Ze(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(An(t,new Oe(r,o)))return!0}return!1}function Pn(t,e){return t.center.sdist(e)<t.radius*t.radius}function pu(t,e){return t.center.sdist(e.center)<(t.radius+e.radius)*(t.radius+e.radius)}function Xt(t,e){let n=e.pts[e.pts.length-1];for(let r of e.pts){if(Bt(new Oe(n,r),t))return!0;n=r}return Pn(t,e.pts[0])?!0:Ze(e,t.center)}function Lo(t,e){for(let n=0;n<t.pts.length;n++)if(Or(new Oe(t.pts[n],t.pts[(n+1)%t.pts.length]),e))return!0;return!!(t.pts.some(n=>Ze(e,n))||e.pts.some(n=>Ze(t,n)))}function Ze(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}function Ar(t,e){e=e.sub(t.center);let n=ae(t.angle),r=Math.cos(n),o=Math.sin(n),s=e.x*r+e.y*o,i=-e.x*o+e.y*r;return s*s/(t.radiusX*t.radiusX)+i*i/(t.radiusY*t.radiusY)<1}function En(t,e){let n=e.center.sub(t.center),r=ae(t.angle),o=Math.cos(r),s=Math.sin(r),i=n.x*o+n.y*s,m=-n.x*s+n.y*o;return Ar(new Ke(v(),t.radiusX+e.radius,t.radiusY+e.radius,0),v(i,m))}function jo(t,e){let n=t.toMat2().inverse;return e=new Oe(n.transform(e.p1.sub(t.center)),n.transform(e.p2.sub(t.center))),Bt(e,new we(v(),1))}function du(t,e){if(t.radiusX===t.radiusY)return En(e,new we(t.center,t.radiusX));if(e.radiusX===e.radiusY)return En(t,new we(e.center,e.radiusX));let n=new gt(1/t.radiusX**2,0,0,0,1/t.radiusY**2,0,0,0,-1),r=new gt(1/e.radiusX**2,0,0,0,1/e.radiusY**2,0,0,0,-1),o=t.center.x,s=t.center.y,i=e.center.x,m=e.center.y,u=ae(t.angle),c=ae(e.angle),p=new gt(Math.cos(u),-Math.sin(u),o,Math.sin(u),Math.cos(u),s,0,0,1),b=new gt(Math.cos(c),-Math.sin(c),i,Math.sin(c),Math.cos(c),m,0,0,1),l=p.inverse,h=b.inverse,d=l.transpose.mul(n).mul(l),C=h.transpose.mul(r).mul(h),g=d.m11,y=d.m12,O=d.m13,A=d.m21,R=d.m22,V=d.m23,x=d.m31,w=d.m32,S=d.m33,G=C.m11,M=C.m12,D=C.m13,L=C.m21,U=C.m22,H=C.m23,Y=C.m31,_=C.m32,K=C.m33,J=g*R*S-g*V*w-y*A*S+y*V*x+O*A*w-O*R*x,$=(g*R*K-g*V*_-g*w*H+g*S*U-y*A*K+y*V*Y+y*x*H-y*S*L+O*A*_-O*R*Y-O*x*U+O*w*L+A*w*D-A*S*M-R*x*D+R*S*G+V*x*M-V*w*G)/J,Z=(g*U*K-g*H*_-y*L*K+y*H*Y+O*L*_-O*U*Y-A*M*K+A*D*_+R*G*K-R*D*Y-V*G*_+V*M*Y+x*M*H-x*D*U-w*G*H+w*D*L+S*G*U-S*M*L)/J,Ee=(G*U*K-G*H*_-M*L*K+M*H*Y+D*L*_-D*U*Y)/J;if($>=0){let k=-3*Z+$**2,ht=3*$*Ee+Z*$**2-4*Z**2,Pt=-27*Ee**2+18*Ee*$*Z+$**2*Z**2-4*$**3*Ee-4*Z**3;return!(k>0&&ht<0&&Pt>0)}else{let k=-3*Z+$**2,ht=-27*Ee**2+18*Ee*$*Z+$**2*Z**2-4*$**3*Ee-4*Z**3;return!(k>0&&ht>0)}}function Io(t,e){return Sr(t,new be(e.points()))}function Sr(t,e){let n=t.toMat2().inverse;return e=new be(e.pts.map(r=>n.transform(r.sub(t.center)))),Xt(new we(v(),1),e)}function fu(t,e){return t.x===e.x&&t.y===e.y}function hu(t,e){return e instanceof E?fu(e,t.pt):e instanceof we?Pn(e,t.pt):e instanceof Oe?Vn(e,t.pt):e instanceof W?Dt(e,t.pt):e instanceof be?Ze(e,t.pt):e instanceof Ke?Ar(e,t.pt):!1}function gu(t,e){return e instanceof E?Vn(t,e):e instanceof we?Bt(t,e):e instanceof Oe?An(t,e)!=null:e instanceof W?Sn(e,t):e instanceof be?Or(t,e):e instanceof Ke?jo(e,t):!1}function bu(t,e){return e instanceof E?Pn(t,e):e instanceof we?pu(t,e):e instanceof Oe?Bt(e,t):e instanceof W?Bo(e,t):e instanceof be?Xt(t,e):e instanceof Ke?En(e,t):!1}function yu(t,e){return e instanceof E?Dt(t,e):e instanceof we?Bo(t,e):e instanceof Oe?Sn(t,e):e instanceof W?Tr(t,e):e instanceof be?Fo(t,e):e instanceof Ke?Io(e,t):!1}function xu(t,e){return e instanceof E?Ze(t,e):e instanceof we?Xt(e,t):e instanceof Oe?Or(e,t):e instanceof W?Fo(e,t):e instanceof be?Lo(e,t):e instanceof Ke?Sr(e,t):!1}function vu(t,e){return e instanceof E?Ar(t,e):e instanceof we?En(t,e):e instanceof Oe?jo(t,e):e instanceof W?Io(t,e):e instanceof be?Sr(t,e):e instanceof Ke?du(e,t):!1}function Ko(t,e,n){let r=t,o=n.p1,s=n.p2,i=e,m=s.sub(o),u=i.cross(m);if(Math.abs(u)<Number.EPSILON)return null;let c=o.sub(r),p=c.cross(m)/u;if(p<=0||p>=1)return null;let b=c.cross(i)/u;if(b<=0||b>=1)return null;let l=m.normal().unit();return e.dot(l)>0&&(l.x*=-1,l.y*=-1),{point:r.add(i.scale(p)),normal:l,fraction:p}}function wu(t,e,n){let r=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,s;if(t.x!=0){let i=(n.pos.x-t.x)/e.x,m=(n.pos.x+n.width-t.x)/e.x;s=v(-Math.sign(e.x),0),r=Math.max(r,Math.min(i,m)),o=Math.min(o,Math.max(i,m))}if(t.y!=0){let i=(n.pos.y-t.y)/e.y,m=(n.pos.y+n.height-t.y)/e.y;Math.min(i,m)>r&&(s=v(0,-Math.sign(e.y))),r=Math.max(r,Math.min(i,m)),o=Math.min(o,Math.max(i,m))}return o>=r&&r>=0&&r<=1?{point:t.add(e.scale(r)),normal:s,fraction:r}:null}function ko(t,e,n){let r=t,o=n.center,s=e,i=s.dot(s),m=r.sub(o),u=2*s.dot(m),c=m.dot(m)-n.radius*n.radius,p=u*u-4*i*c;if(i<=Number.EPSILON||p<0)return null;if(p==0){let b=-u/(2*i);if(b>=0&&b<=1){let l=r.add(s.scale(b));return{point:l,normal:l.sub(o),fraction:b}}}else{let b=(-u+Math.sqrt(p))/(2*i),l=(-u-Math.sqrt(p))/(2*i),h=null;if(b>=0&&b<=1&&(h=b),l>=0&&l<=1&&(h=Math.min(l,h??l)),h!=null){let d=r.add(s.scale(h));return{point:d,normal:d.sub(o).unit(),fraction:h}}}return null}function Cu(t,e,n){let r=n.pts,o=null,s=r[r.length-1];for(let i=0;i<r.length;i++){let m=r[i],u=Ko(t,e,new Oe(s,m));u&&(!o||o.fraction>u.fraction)&&(o=u),s=m}return o}function Eu(t,e,n){let r=n.toMat2(),o=r.inverse,s=o.transform(t.sub(n.center)),i=o.transform(e),m=ko(s,i,new we(v(),1));if(m){let u=Rt.rotation(ae(-n.angle)),p=Rt.scale(n.radiusX,n.radiusY).transform(m.point),b=r.transform(m.point).add(n.center),l=b.dist(t)/e.len();return{point:b,normal:u.transform(v(n.radiusY**2*p.x,n.radiusX**2*p.y)).unit(),fraction:l}}return m}function _o(t,e,n,r=64){let o=t,s=e.len(),i=e.scale(1/s),m=0,u=v(Math.floor(t.x),Math.floor(t.y)),c=v(i.x>0?1:-1,i.y>0?1:-1),p=v(Math.abs(1/i.x),Math.abs(1/i.y)),b=v(c.x>0?u.x+1-t.x:t.x-u.x,c.y>0?u.y+1-t.y:t.y-u.y),l=v(p.x<1/0?p.x*b.x:1/0,p.y<1/0?p.y*b.y:1/0),h=-1;for(;m<=r;){let d=n(u);if(d===!0)return{point:o.add(i.scale(m)),normal:v(h===0?-c.x:0,h===1?-c.y:0),fraction:m/s,gridPos:u};if(d)return d;l.x<l.y?(u.x+=c.x,m=l.x,l.x+=p.x,h=0):(u.y+=c.y,m=l.y,l.y+=p.y,h=1)}return null}var Tn=class t{pt;constructor(e){this.pt=e.clone()}transform(e){return new t(e.multVec2(this.pt))}bbox(){return new W(this.pt,0,0)}area(){return 0}clone(){return new t(this.pt)}collides(e){return hu(this,e)}contains(e){return this.pt.eq(e)}raycast(e,n){return null}random(){return this.pt.clone()}},Oe=class t{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 W.fromPoints(this.p1,this.p2)}area(){return this.p1.dist(this.p2)}clone(){return new t(this.p1,this.p2)}collides(e){return gu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return Ko(e,n,this)}random(){return this.p1.add(this.p2.sub(this.p1).scale(he(1)))}},W=class t{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 E(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 be(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 yu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return wu(e,n,this)}random(){return this.pos.add(he(this.width),he(this.height))}},we=class t{center;radius;constructor(e,n){this.center=e.clone(),this.radius=n}transform(e){return new Ke(this.center,this.radius,this.radius).transform(e)}bbox(){return W.fromPoints(this.center.sub(v(this.radius)),this.center.add(v(this.radius)))}area(){return this.radius*this.radius*Math.PI}clone(){return new t(this.center,this.radius)}collides(e){return bu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return ko(e,n,this)}random(){return this.center.add(E.fromAngle(he(360)).scale(he(this.radius)))}},Ke=class t{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,[i,m]=r.eigenvectors(o,s),[u,c]=[1/Math.sqrt(o),1/Math.sqrt(s)];return u>c?new t(v(),u,c,ct(Math.atan2(-i[1],i[0]))):new t(v(),c,u,ct(Math.atan2(-m[1],m[0])))}toMat2(){let e=ae(this.angle),n=Math.cos(e),r=Math.sin(e);return new Rt(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=gt.fromMat2(n).scale(o.x,o.y).rotate(r).toMat2();let i=t.fromMat2(n);return i.center=e.multVec2(this.center),i}}bbox(){if(this.angle==0)return W.fromPoints(this.center.sub(v(this.radiusX,this.radiusY)),this.center.add(v(this.radiusX,this.radiusY)));{let e=ae(this.angle),n=Math.cos(e),r=Math.sin(e),o=this.radiusX*n,s=this.radiusX*r,i=this.radiusY*r,m=this.radiusY*n,u=Math.sqrt(o*o+i*i),c=Math.sqrt(s*s+m*m);return W.fromPoints(this.center.sub(v(u,c)),this.center.add(v(u,c)))}}area(){return this.radiusX*this.radiusY*Math.PI}clone(){return new t(this.center,this.radiusX,this.radiusY,this.angle)}collides(e){return vu(this,e)}contains(e){e=e.sub(this.center);let n=ae(this.angle),r=Math.cos(n),o=Math.sin(n),s=e.x*r+e.y*o,i=-e.x*o+e.y*r;return s*s/(this.radiusX*this.radiusX)+i*i/(this.radiusY*this.radiusY)<1}raycast(e,n){return Eu(e,n,this)}random(){return this.center}};function Tu(t,e,n,r){let o=e.sub(t),s=r.sub(n),i=o.cross(s);return i<1e-5&&i>-1e-5||(i=n.sub(t).cross(s)/i,i<0||i>1)?null:t.add(o.scale(i))}var be=class t{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=v(Number.MAX_VALUE),n=v(-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 W.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 xu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return Cu(e,n,this)}random(){return v()}cut(e,n){let r=new Oe(e,n),o=[],s=[],i=n.sub(e),m=this.pts[this.pts.length-1],u=m.sub(e),c=i.cross(u)>0;return this.pts.forEach(p=>{u=p.sub(e);let b=i.cross(u)>0;if(c!=b){let l=Tu(m,p,e,n);o.push(l),s.push(l),c=b}(b?o:s).push(p),m=p}),[o.length?new t(o):null,s.length?new t(s):null]}};function No(t,e,n,r){let o=r*r,s=1-r,i=s*s;return t.scale(i).add(e.scale(2*s*r)).add(n.scale(o))}function Uo(t,e,n,r){let o=1-r;return e.sub(t).scale(2*o).add(n.sub(e).scale(2*r))}function Ho(t,e,n,r){return n.sub(e.scale(2)).add(t).scale(2)}function Qt(t,e,n,r,o){let s=o*o,i=s*o,m=1-o,u=m*m,c=u*m;return t.scale(c).add(e.scale(3*u*o)).add(n.scale(3*m*s)).add(r.scale(i))}function qo(t,e,n,r,o){let s=o*o,i=1-o,m=i*i;return e.sub(t).scale(3*m).add(n.sub(e).scale(6*i*o)).add(r.sub(n).scale(3*s))}function zo(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))}function Wo(t,e,n,r,o){let s=.5*(((-o+2)*o-1)*o),i=.5*((3*o-5)*o*o+2),m=.5*(((-3*o+4)*o+1)*o),u=.5*((o-1)*o*o);return t.scale(s).add(e.scale(i)).add(n.scale(m)).add(r.scale(u))}function Yo(t,e,n,r,o){let s=.5*((-3*o+4)*o-1),i=.5*((9*o-10)*o),m=.5*((-9*o+8)*o+1),u=.5*((3*o-2)*o);return t.scale(s).add(e.scale(i)).add(n.scale(m)).add(r.scale(u))}function $o(t){let e=Vr(t),n=e(1);return r=>{let o=r*n,s=e(o,!0);return t(s)}}function Vr(t,e=10,n=10){let r=[0],o=[0],i=1/(e-1)/n,m=0,u=t(0),c=0;for(let p=1;p<e;p++){for(let b=0;b<n;b++){c+=i;let l=t(c),h=l.dist(u);m+=h,u=l}r[p]=m,o[p]=c}return o[e-1]=1,(p,b=!1)=>{if(b){let l=p;if(l<=0)return 0;if(l>=m)return 1;let h=0;for(;r[h+1]<l;)h++;let d=o[h],C=o[h+1],g=r[h],y=r[h+1],O=(l-g)/(y-g);return d+(C-d)*O}else{if(p<=0)return 0;if(p>=1)return r[e-1];let l=0;for(;o[l+1]<p;)l++;let h=o[l],d=o[l+1],C=r[l],g=r[l+1],y=(p-h)/(d-h);return C+(g-C)*y}}}function Ft(t,e,n,r){let o=2*t+e-2*r+n,s=-3*t+3*r-2*e-n,i=e,m=t;return u=>{let c=u*u,p=c*u;return o*p+s*c+i*u+m}}function Pr(t,e,n,r,o,s=Ft){let i=s(e.x,(1-o)*(n.x-t.x),(1-o)*(r.x-e.x),n.x),m=s(e.y,(1-o)*(n.y-t.y),(1-o)*(r.y-e.y),n.y);return u=>new E(i(u),m(u))}function Lt(t,e,n,r,o=Ft){return Pr(t,e,n,r,.5,o)}function Xo(t,e,n,r,o=Ft){return Lt(r.add(t.sub(e).scale(6)),t,r,t.add(r.sub(n).scale(6)),o)}function Qo(t,e,n,r,o,s,i,m=Ft){let u=m(e.x,.5*(1-o)*(1+i)*(1+s)*(e.x-t.x)+.5*(1-o)*(1-i)*(1-s)*(n.x-e.x),.5*(1-o)*(1+i)*(1-s)*(n.x-e.x)+.5*(1-o)*(1-i)*(1+s)*(r.x-n.x),n.x),c=m(e.y,.5*(1-o)*(1+i)*(1+s)*(e.y-t.y)+.5*(1-o)*(1-i)*(1-s)*(n.y-e.y),.5*(1-o)*(1+i)*(1-s)*(n.y-e.y)+.5*(1-o)*(1-i)*(1+s)*(r.y-n.y),n.y);return p=>new E(u(p),c(p))}function Jo(t,e,n,r){let o=2*t+e-2*r+n,s=-3*t+3*r-2*e+n,i=e;return m=>{let u=m*m;return 3*o*u+2*s*m+i}}function Wt(t){return 0<=t&&t<=1}function xr(t,e){return Math.abs(t-e)<=Number.EPSILON}function Yt(t){return t<0?-Math.pow(-t,1/3):Math.pow(t,1/3)}function Ou(t,e,n,r){let o=3*t-6*e+3*n,s=-3*t+3*e,i=t,m=-t+3*e-3*n+r;if(xr(m,0)){if(xr(o,0))return xr(s,0)?[]:[-i/s].filter(Wt);let y=Math.sqrt(s*s-4*o*i),O=2*o;return[(y-s)/O,(-s-y)/O].filter(Wt)}o/=m,s/=m,i/=m;let u=(3*s-o*o)/3,c=u/3,p=(2*o*o*o-9*o*s+27*i)/27,b=p/2,l=b*b+c*c*c;if(l<0){let y=-u/3,O=y*y*y,A=Math.sqrt(O),R=-p/(2*A),V=R<-1?-1:R>1?1:R,x=Math.acos(V),S=2*Yt(A),G=S*Math.cos(x/3)-o/3,M=S*Math.cos((x+2*Math.PI)/3)-o/3,D=S*Math.cos((x+4*Math.PI)/3)-o/3;return[G,M,D].filter(Wt)}if(l===0){let y=b<0?Yt(-b):-Yt(b),O=2*y-o/3,A=-y-o/3;return[O,A].filter(Wt)}let h=Math.sqrt(l),d=Yt(h-b),C=Yt(h+b);return[d-C-o/3].filter(Wt)}function Au(t,e,n,r,o){let s=Ou(t.x-o,e.x-o,n.x-o,r.x-o);return s.length>0?Qt(t,e,n,r,s[0]).y:NaN}function Zo(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 Se(n,t[r-1].x,t[r].x,t[r-1].y,t[r].y);return t[t.length-1].y}}function es(t,e){return n=>Au(v(0,0),t,e,v(1,1),n)}function ts(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)),i=r?s:0;return m=>{let u=Math.floor(m/n);return i+u*s}}function ns(t,e){let n=Number.MAX_VALUE,r={normal:v(0),distance:0};for(let o of[t,e])for(let s=0;s<o.pts.length;s++){let i=o.pts[s],u=o.pts[(s+1)%o.pts.length].sub(i).normal().unit(),c=Number.MAX_VALUE,p=-Number.MAX_VALUE;for(let d=0;d<t.pts.length;d++){let C=t.pts[d].dot(u);c=Math.min(c,C),p=Math.max(p,C)}let b=Number.MAX_VALUE,l=-Number.MAX_VALUE;for(let d=0;d<e.pts.length;d++){let C=e.pts[d].dot(u);b=Math.min(b,C),l=Math.max(l,C)}let h=Math.min(p,l)-Math.max(c,b);if(h<0)return null;if(h<Math.abs(n)){let d=l-c,C=b-p;n=Math.abs(d)<Math.abs(C)?d:C,r.normal=u,r.distance=n}}return r}function rs(t,e,n){return(e.x-t.x)*(n.y-t.y)-(e.y-t.y)*(n.x-t.x)>=0}function Su(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}function vr(t,e,n,r){let o=r.x-n.x,s=r.y-n.y,i=o*(t.y-n.y)-s*(t.x-n.x),m=o*(e.y-n.y)-s*(e.x-n.x);return i*m>=0}function Vu(t,e,n,r){return vr(t,e,n,r)&&vr(t,n,e,r)&&vr(t,r,e,n)}function Pu(t,e,n,r){for(let o of t)if(o!==e&&o!==n&&o!==r&&Vu(o,e,n,r))return!0;return!1}function Gu(t,e,n,r){return rs(t,e,n)&&!Pu(r,t,e,n)}function Gn(t){if(t.length<3)return[];if(t.length==3)return[t];let e=[],n=[],r=0;for(let b=0;b<t.length;b++){let l=t[r],h=t[b];(h.x<l.x||h.x==l.x&&h.y<l.y)&&(r=r),e[b]=b+1,n[b]=b-1}e[e.length-1]=0,n[0]=n.length-1,Su(t)||([e,n]=[n,e]);let o=[];for(let b=0;b<t.length;++b)rs(t[n[b]],t[b],t[e[b]])||o.push(t[b]);let s=[],i=t.length,m=1,u=0,c,p;for(;i>3;){c=e[m],p=n[m];let b=t[p],l=t[m],h=t[c];if(Gu(b,l,h,o))s.push([b,l,h]),e[p]=c,n[c]=p,o.splice(o.indexOf(l),1),--i,u=0;else if(++u>i)return[];m=c}return c=e[m],p=n[m],s.push([t[p],t[m],t[c]]),s}function os(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]),i=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)*i<0)return!1;return!0}var Mn=" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",lt="topleft";var ss="monospace",bt="monospace";var Jt="linear";var Zt=[{name:"a_pos",size:2},{name:"a_uv",size:2},{name:"a_color",size:4}],Mu=Zt.reduce((t,e)=>t+e.size,0),is=2048,as=is*4*Mu,us=is*6,cs=`
1
+ "use strict";var yr=Object.defineProperty;var nu=Object.getOwnPropertyDescriptor;var ru=Object.getOwnPropertyNames;var ou=Object.prototype.hasOwnProperty;var su=(t,e)=>{for(var n in e)yr(t,n,{get:e[n],enumerable:!0})},iu=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ru(e))!ou.call(t,o)&&o!==n&&yr(t,o,{get:()=>e[o],enumerable:!(r=nu(e,o))||r.enumerable});return t};var au=t=>iu(yr({},"__esModule",{value:!0}),t);var Oo=(()=>{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,i=0;s<r;){var m=t[n.charCodeAt(s++)],u=t[n.charCodeAt(s++)],c=t[n.charCodeAt(s++)],p=t[n.charCodeAt(s++)];o[i++]=m<<2|u>>4,o[i++]=u<<4|c>>2,o[i++]=c<<6|p}return o}})();var hc={};su(hc,{_k:()=>a,default:()=>fc,kaplay:()=>Qa});module.exports=au(hc);var Ao={name:"kaplay",description:"KAPLAY is a JavaScript & TypeScript game library that helps you make games fast and fun!",version:"3001.0.14",license:"MIT",homepage:"https://kaplayjs.com/",bugs:{url:"https://github.com/kaplayjs/kaplay/issues"},funding:{type:"opencollective",url:"https://opencollective.com/kaplay"},repository:{type:"git",url:"git+https://github.com/kaplayjs/kaplay.git"},type:"module",main:"./dist/kaplay.cjs",module:"./dist/kaplay.mjs",types:"./dist/doc.d.ts",readme:"./README.md",exports:{".":{import:{types:"./dist/doc.d.ts",default:"./dist/kaplay.mjs"},require:{types:"./dist/doc.d.ts",default:"./dist/kaplay.cjs"}},"./global":"./dist/declaration/global.js"},typesVersions:{"*":{global:["./dist/declaration/global.d.ts"]}},keywords:["game development","javascript","typescript","game engine","2d games","physics engine","webgl","canvas","game library","kaplay"],files:["dist/","kaplay.webp","CHANGELOG.md"],scripts:{dev:"NODE_ENV=development node scripts/dev.js","win:dev":"set NODE_ENV=development && node scripts/dev.js",build:"node scripts/generateIndex.js && node scripts/build.js && npm run doc-dts",check:"tsc",fmt:"dprint fmt",test:"node scripts/test.js","doc-dts":"dts-bundle-generator -o dist/doc.d.ts src/index.ts","test:vite":"vitest --typecheck",desktop:"tauri dev",prepare:"npm run build","publish:next":"npm publish --tag next"},devDependencies:{"@kaplayjs/dprint-config":"^1.2.0","@types/jest":"^29.5.14",dprint:"^0.49.1","dts-bundle-generator":"^9.5.1",ejs:"^3.1.10",esbuild:"^0.25.2",express:"^5.1.0",puppeteer:"^22.15.0","tar-fs":"3.0.8",typescript:"5.6.3",vite:"5.4.16",vitest:"^3.1.1","vitest-environment-puppeteer":"^11.0.3","vitest-puppeteer":"^11.0.3"},engines:{node:">=20.0.0"},packageManager:"pnpm@9.9.0+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1"};function Te(t,e,n){return e>n?Te(t,n,e):Math.min(Math.max(t,e),n)}var j=class t{r=255;g=255;b=255;constructor(e,n,r){this.r=Te(e,0,255),this.g=Te(n,0,255),this.b=Te(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=(p,b,l)=>(l<0&&(l+=1),l>1&&(l-=1),l<1/6?p+(b-p)*6*l:l<1/2?b:l<2/3?p+(b-p)*(2/3-l)*6:p),s=r<.5?r*(1+n):r+n-r*n,i=2*r-s,m=o(i,s,e+1/3),u=o(i,s,e),c=o(i,s,e-1/3);return new t(Math.round(m*255),Math.round(u*255),Math.round(c*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(de(this.r,e.r,n),de(this.g,e.g,n),de(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),i=(o+s)/2,m=i,u=i;if(o==s)i=m=0;else{let c=o-s;switch(m=u>.5?c/(2-o-s):c/(o+s),o){case e:i=(n-r)/c+(n<r?6:0);break;case n:i=(r-e)/c+2;break;case r:i=(e-n)/c+4;break}i/=6}return[i,m,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 I(...t){if(t.length===0)return new j(255,255,255);if(t.length===1){if(t[0]instanceof j)return t[0].clone();if(typeof t[0]=="string")return j.fromHex(t[0]);if(Array.isArray(t[0])&&t[0].length===3)return j.fromArray(t[0])}else if(t.length===2){if(t[0]instanceof j)return t[0].clone()}else if(t.length===3||t.length===4)return new j(t[0],t[1],t[2]);throw new Error("Invalid color arguments")}var So=(t,e,n)=>j.fromHSL(t,e,n);function ae(t){return t*Math.PI/180}function ct(t){return t*180/Math.PI}function de(t,e,n){if(typeof t=="number"&&typeof e=="number")return t+(e-t)*n;if(t instanceof E&&e instanceof E)return t.lerp(e,n);if(t instanceof j&&e instanceof j)return t.lerp(e,n);throw new Error(`Bad value for lerp(): ${t}, ${e}. Only number, Vec2 and Color is supported.`)}function Se(t,e,n,r,o){return r+(t-e)/(n-e)*(o-r)}function Po(t,e,n,r,o){return Te(Se(t,e,n,r,o),r,o)}var E=class t{x=0;y=0;constructor(e=0,n=e){this.x=e,this.y=n}static fromAngle(e){let n=ae(e);return new t(Math.cos(n),Math.sin(n))}static fromArray(e){return new t(e[0],e[1])}static ZERO=new t(0,0);static ONE=new t(1,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=v(...e);return new t(this.x+n.x,this.y+n.y)}sub(...e){let n=v(...e);return new t(this.x-n.x,this.y-n.y)}scale(...e){let n=v(...e);return new t(this.x*n.x,this.y*n.y)}dist(...e){let n=v(...e);return this.sub(n).len()}sdist(...e){let n=v(...e);return this.sub(n).slen()}static sdist(e,n){let r=e.x-n.x,o=e.y-n.y;return r*r+o*o}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}static dot(e,n){return e.x*n.x+e.y*n.y}cross(e){return this.x*e.y-this.y*e.x}static cross(e,n){return e.x*n.y-e.y*n.x}angle(...e){let n=v(...e);return ct(Math.atan2(this.y-n.y,this.x-n.x))}angleBetween(...e){let n=v(...e);return ct(Math.atan2(this.cross(n),this.dot(n)))}lerp(e,n){return new t(de(this.x,e.x,n),de(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 W(this,0,0)}toString(){return`vec2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`}toArray(){return[this.x,this.y]}};function v(...t){if(t.length===1){if(t[0]instanceof E)return new E(t[0].x,t[0].y);if(Array.isArray(t[0])&&t[0].length===2)return new E(...t[0])}return new E(...t)}var q=class t{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 E(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 le(t,e,n,r){return new q(t,e,n,r)}var Rt=class t{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 v(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(v(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 gt=class t{m11;m12;m13;m21;m22;m23;m31;m32;m33;constructor(e,n,r,o,s,i,m,u,c){this.m11=e,this.m12=n,this.m13=r,this.m21=o,this.m22=s,this.m23=i,this.m31=m,this.m32=u,this.m33=c}static fromMat2(e){return new t(e.a,e.b,0,e.c,e.d,0,0,0,1)}toMat2(){return new Rt(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)}},fe=class t{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=ae(-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=ae(-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=ae(-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=ae(-e);let n=Math.cos(e),r=Math.sin(e),o=this.m[0],s=this.m[1],i=this.m[4],m=this.m[5];return this.m[0]=o*n+s*r,this.m[1]=-o*r+s*n,this.m[4]=i*n+m*r,this.m[5]=-i*r+m*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 E(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 E(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 E(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 E(e/n,n)}else return new E(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 ct(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 ct(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 E(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 E(0,Math.atan(this.m[0]*this.m[4]+this.m[1]*this.m[5])/(e*e))}else return new E(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],i=this.m[8]*this.m[14]-this.m[12]*this.m[10],m=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],c=this.m[5]*this.m[15]-this.m[13]*this.m[7],p=this.m[5]*this.m[14]-this.m[13]*this.m[6],b=this.m[4]*this.m[15]-this.m[12]*this.m[7],l=this.m[4]*this.m[14]-this.m[12]*this.m[6],h=this.m[5]*this.m[15]-this.m[13]*this.m[7],d=this.m[4]*this.m[13]-this.m[12]*this.m[5],C=this.m[6]*this.m[11]-this.m[10]*this.m[7],g=this.m[5]*this.m[11]-this.m[9]*this.m[7],y=this.m[5]*this.m[10]-this.m[9]*this.m[6],O=this.m[4]*this.m[11]-this.m[8]*this.m[7],A=this.m[4]*this.m[10]-this.m[8]*this.m[6],R=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]*i),e[8]=this.m[4]*r-this.m[5]*s+this.m[7]*m,e[12]=-(this.m[4]*o-this.m[5]*i+this.m[6]*m),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]*i,e[9]=-(this.m[0]*r-this.m[1]*s+this.m[3]*m),e[13]=this.m[0]*o-this.m[1]*i+this.m[2]*m,e[2]=this.m[1]*u-this.m[2]*c+this.m[3]*p,e[6]=-(this.m[0]*u-this.m[2]*b+this.m[3]*l),e[10]=this.m[0]*h-this.m[1]*b+this.m[3]*d,e[14]=-(this.m[0]*p-this.m[1]*l+this.m[2]*d),e[3]=-(this.m[1]*C-this.m[2]*g+this.m[3]*y),e[7]=this.m[0]*C-this.m[2]*O+this.m[3]*A,e[11]=-(this.m[0]*g-this.m[1]*O+this.m[3]*R),e[15]=this.m[0]*y-this.m[1]*A+this.m[2]*R;let V=this.m[0]*e[0]+this.m[1]*e[4]+this.m[2]*e[8]+this.m[3]*e[12];for(let x=0;x<4;x++)for(let w=0;w<4;w++)e[x*4+w]*=1/V;return new t(e)}clone(){return new t([...this.m])}toString(){return this.m.toString()}};function On(t,e,n,r=o=>-Math.cos(o)){return t+(r(n)+1)/2*(e-t)}var cu=1103515245,lu=12345,Vo=2147483648,$t=class{seed;constructor(e){this.seed=e}gen(){return this.seed=(cu*this.seed+lu)%Vo,this.seed/Vo}genNumber(e,n){return e+this.gen()*(n-e)}genVec2(e,n){return new E(this.genNumber(e.x,n.x),this.genNumber(e.y,n.y))}genColor(e,n){return new j(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 E)return this.genVec2(v(0,0),e[0]);if(e[0]instanceof j)return this.genColor(I(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 E&&e[1]instanceof E)return this.genVec2(e[0],e[1]);if(e[0]instanceof j&&e[1]instanceof j)return this.genColor(e[0],e[1])}throw new Error("More than 2 arguments not supported")}},wr=new $t(Date.now());function Go(t){return t!=null&&(wr.seed=t),wr.seed}function he(...t){return wr.genAny(...t)}function Cr(...t){return Math.floor(he(...t.length>0?t:[2]))}function Mo(t){return he()<=t}function Er(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}function Ro(t,e){return t.length<=e?t.slice():Er(t.slice()).slice(0,e)}function Do(t){return t[Cr(t.length)]}function Tr(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}function mu(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}function An(t,e){let n=mu(t,e);return n?v(t.p1.x+n*(t.p2.x-t.p1.x),t.p1.y+n*(t.p2.y-t.p1.y)):null}function Sn(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,i=(t.pos.x+t.width-e.p1.x)/n.x;r=Math.max(r,Math.min(s,i)),o=Math.min(o,Math.max(s,i))}if(n.y!=0){let s=(t.pos.y-e.p1.y)/n.y,i=(t.pos.y+t.height-e.p1.y)/n.y;r=Math.max(r,Math.min(s,i)),o=Math.min(o,Math.max(s,i))}return o>=r&&o>=0&&r<=1}function Dt(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}function Bo(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 v(n,r).sdist(e.center)<=e.radius*e.radius}function Fo(t,e){return Lo(e,new be(t.points()))}function Vn(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}function Bt(t,e){let n=t.p2.sub(t.p1),r=n.dot(n),o=t.p1.sub(e.center),s=2*n.dot(o),i=o.dot(o)-e.radius*e.radius,m=s*s-4*r*i;if(r<=Number.EPSILON||m<0)return!1;if(m==0){let u=-s/(2*r);if(u>=0&&u<=1)return!0}else{let u=(-s+Math.sqrt(m))/(2*r),c=(-s-Math.sqrt(m))/(2*r);if(u>=0&&u<=1||c>=0&&c<=1)return!0}return Pn(e,t.p1)}function Or(t,e){if(Ze(e,t.p1)||Ze(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(An(t,new Oe(r,o)))return!0}return!1}function Pn(t,e){return t.center.sdist(e)<t.radius*t.radius}function pu(t,e){return t.center.sdist(e.center)<(t.radius+e.radius)*(t.radius+e.radius)}function Xt(t,e){let n=e.pts[e.pts.length-1];for(let r of e.pts){if(Bt(new Oe(n,r),t))return!0;n=r}return Pn(t,e.pts[0])?!0:Ze(e,t.center)}function Lo(t,e){for(let n=0;n<t.pts.length;n++)if(Or(new Oe(t.pts[n],t.pts[(n+1)%t.pts.length]),e))return!0;return!!(t.pts.some(n=>Ze(e,n))||e.pts.some(n=>Ze(t,n)))}function Ze(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}function Ar(t,e){e=e.sub(t.center);let n=ae(t.angle),r=Math.cos(n),o=Math.sin(n),s=e.x*r+e.y*o,i=-e.x*o+e.y*r;return s*s/(t.radiusX*t.radiusX)+i*i/(t.radiusY*t.radiusY)<1}function En(t,e){let n=e.center.sub(t.center),r=ae(t.angle),o=Math.cos(r),s=Math.sin(r),i=n.x*o+n.y*s,m=-n.x*s+n.y*o;return Ar(new Ke(v(),t.radiusX+e.radius,t.radiusY+e.radius,0),v(i,m))}function jo(t,e){let n=t.toMat2().inverse;return e=new Oe(n.transform(e.p1.sub(t.center)),n.transform(e.p2.sub(t.center))),Bt(e,new we(v(),1))}function du(t,e){if(t.radiusX===t.radiusY)return En(e,new we(t.center,t.radiusX));if(e.radiusX===e.radiusY)return En(t,new we(e.center,e.radiusX));let n=new gt(1/t.radiusX**2,0,0,0,1/t.radiusY**2,0,0,0,-1),r=new gt(1/e.radiusX**2,0,0,0,1/e.radiusY**2,0,0,0,-1),o=t.center.x,s=t.center.y,i=e.center.x,m=e.center.y,u=ae(t.angle),c=ae(e.angle),p=new gt(Math.cos(u),-Math.sin(u),o,Math.sin(u),Math.cos(u),s,0,0,1),b=new gt(Math.cos(c),-Math.sin(c),i,Math.sin(c),Math.cos(c),m,0,0,1),l=p.inverse,h=b.inverse,d=l.transpose.mul(n).mul(l),C=h.transpose.mul(r).mul(h),g=d.m11,y=d.m12,O=d.m13,A=d.m21,R=d.m22,V=d.m23,x=d.m31,w=d.m32,S=d.m33,G=C.m11,M=C.m12,D=C.m13,L=C.m21,U=C.m22,H=C.m23,Y=C.m31,_=C.m32,K=C.m33,J=g*R*S-g*V*w-y*A*S+y*V*x+O*A*w-O*R*x,$=(g*R*K-g*V*_-g*w*H+g*S*U-y*A*K+y*V*Y+y*x*H-y*S*L+O*A*_-O*R*Y-O*x*U+O*w*L+A*w*D-A*S*M-R*x*D+R*S*G+V*x*M-V*w*G)/J,Z=(g*U*K-g*H*_-y*L*K+y*H*Y+O*L*_-O*U*Y-A*M*K+A*D*_+R*G*K-R*D*Y-V*G*_+V*M*Y+x*M*H-x*D*U-w*G*H+w*D*L+S*G*U-S*M*L)/J,Ee=(G*U*K-G*H*_-M*L*K+M*H*Y+D*L*_-D*U*Y)/J;if($>=0){let k=-3*Z+$**2,ht=3*$*Ee+Z*$**2-4*Z**2,Pt=-27*Ee**2+18*Ee*$*Z+$**2*Z**2-4*$**3*Ee-4*Z**3;return!(k>0&&ht<0&&Pt>0)}else{let k=-3*Z+$**2,ht=-27*Ee**2+18*Ee*$*Z+$**2*Z**2-4*$**3*Ee-4*Z**3;return!(k>0&&ht>0)}}function Io(t,e){return Sr(t,new be(e.points()))}function Sr(t,e){let n=t.toMat2().inverse;return e=new be(e.pts.map(r=>n.transform(r.sub(t.center)))),Xt(new we(v(),1),e)}function fu(t,e){return t.x===e.x&&t.y===e.y}function hu(t,e){return e instanceof E?fu(e,t.pt):e instanceof we?Pn(e,t.pt):e instanceof Oe?Vn(e,t.pt):e instanceof W?Dt(e,t.pt):e instanceof be?Ze(e,t.pt):e instanceof Ke?Ar(e,t.pt):!1}function gu(t,e){return e instanceof E?Vn(t,e):e instanceof we?Bt(t,e):e instanceof Oe?An(t,e)!=null:e instanceof W?Sn(e,t):e instanceof be?Or(t,e):e instanceof Ke?jo(e,t):!1}function bu(t,e){return e instanceof E?Pn(t,e):e instanceof we?pu(t,e):e instanceof Oe?Bt(e,t):e instanceof W?Bo(e,t):e instanceof be?Xt(t,e):e instanceof Ke?En(e,t):!1}function yu(t,e){return e instanceof E?Dt(t,e):e instanceof we?Bo(t,e):e instanceof Oe?Sn(t,e):e instanceof W?Tr(t,e):e instanceof be?Fo(t,e):e instanceof Ke?Io(e,t):!1}function xu(t,e){return e instanceof E?Ze(t,e):e instanceof we?Xt(e,t):e instanceof Oe?Or(e,t):e instanceof W?Fo(e,t):e instanceof be?Lo(e,t):e instanceof Ke?Sr(e,t):!1}function vu(t,e){return e instanceof E?Ar(t,e):e instanceof we?En(t,e):e instanceof Oe?jo(t,e):e instanceof W?Io(t,e):e instanceof be?Sr(t,e):e instanceof Ke?du(e,t):!1}function Ko(t,e,n){let r=t,o=n.p1,s=n.p2,i=e,m=s.sub(o),u=i.cross(m);if(Math.abs(u)<Number.EPSILON)return null;let c=o.sub(r),p=c.cross(m)/u;if(p<=0||p>=1)return null;let b=c.cross(i)/u;if(b<=0||b>=1)return null;let l=m.normal().unit();return e.dot(l)>0&&(l.x*=-1,l.y*=-1),{point:r.add(i.scale(p)),normal:l,fraction:p}}function wu(t,e,n){let r=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,s;if(t.x!=0){let i=(n.pos.x-t.x)/e.x,m=(n.pos.x+n.width-t.x)/e.x;s=v(-Math.sign(e.x),0),r=Math.max(r,Math.min(i,m)),o=Math.min(o,Math.max(i,m))}if(t.y!=0){let i=(n.pos.y-t.y)/e.y,m=(n.pos.y+n.height-t.y)/e.y;Math.min(i,m)>r&&(s=v(0,-Math.sign(e.y))),r=Math.max(r,Math.min(i,m)),o=Math.min(o,Math.max(i,m))}return o>=r&&r>=0&&r<=1?{point:t.add(e.scale(r)),normal:s,fraction:r}:null}function ko(t,e,n){let r=t,o=n.center,s=e,i=s.dot(s),m=r.sub(o),u=2*s.dot(m),c=m.dot(m)-n.radius*n.radius,p=u*u-4*i*c;if(i<=Number.EPSILON||p<0)return null;if(p==0){let b=-u/(2*i);if(b>=0&&b<=1){let l=r.add(s.scale(b));return{point:l,normal:l.sub(o),fraction:b}}}else{let b=(-u+Math.sqrt(p))/(2*i),l=(-u-Math.sqrt(p))/(2*i),h=null;if(b>=0&&b<=1&&(h=b),l>=0&&l<=1&&(h=Math.min(l,h??l)),h!=null){let d=r.add(s.scale(h));return{point:d,normal:d.sub(o).unit(),fraction:h}}}return null}function Cu(t,e,n){let r=n.pts,o=null,s=r[r.length-1];for(let i=0;i<r.length;i++){let m=r[i],u=Ko(t,e,new Oe(s,m));u&&(!o||o.fraction>u.fraction)&&(o=u),s=m}return o}function Eu(t,e,n){let r=n.toMat2(),o=r.inverse,s=o.transform(t.sub(n.center)),i=o.transform(e),m=ko(s,i,new we(v(),1));if(m){let u=Rt.rotation(ae(-n.angle)),p=Rt.scale(n.radiusX,n.radiusY).transform(m.point),b=r.transform(m.point).add(n.center),l=b.dist(t)/e.len();return{point:b,normal:u.transform(v(n.radiusY**2*p.x,n.radiusX**2*p.y)).unit(),fraction:l}}return m}function _o(t,e,n,r=64){let o=t,s=e.len(),i=e.scale(1/s),m=0,u=v(Math.floor(t.x),Math.floor(t.y)),c=v(i.x>0?1:-1,i.y>0?1:-1),p=v(Math.abs(1/i.x),Math.abs(1/i.y)),b=v(c.x>0?u.x+1-t.x:t.x-u.x,c.y>0?u.y+1-t.y:t.y-u.y),l=v(p.x<1/0?p.x*b.x:1/0,p.y<1/0?p.y*b.y:1/0),h=-1;for(;m<=r;){let d=n(u);if(d===!0)return{point:o.add(i.scale(m)),normal:v(h===0?-c.x:0,h===1?-c.y:0),fraction:m/s,gridPos:u};if(d)return d;l.x<l.y?(u.x+=c.x,m=l.x,l.x+=p.x,h=0):(u.y+=c.y,m=l.y,l.y+=p.y,h=1)}return null}var Tn=class t{pt;constructor(e){this.pt=e.clone()}transform(e){return new t(e.multVec2(this.pt))}bbox(){return new W(this.pt,0,0)}area(){return 0}clone(){return new t(this.pt)}collides(e){return hu(this,e)}contains(e){return this.pt.eq(e)}raycast(e,n){return null}random(){return this.pt.clone()}},Oe=class t{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 W.fromPoints(this.p1,this.p2)}area(){return this.p1.dist(this.p2)}clone(){return new t(this.p1,this.p2)}collides(e){return gu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return Ko(e,n,this)}random(){return this.p1.add(this.p2.sub(this.p1).scale(he(1)))}},W=class t{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 E(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 be(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 yu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return wu(e,n,this)}random(){return this.pos.add(he(this.width),he(this.height))}},we=class t{center;radius;constructor(e,n){this.center=e.clone(),this.radius=n}transform(e){return new Ke(this.center,this.radius,this.radius).transform(e)}bbox(){return W.fromPoints(this.center.sub(v(this.radius)),this.center.add(v(this.radius)))}area(){return this.radius*this.radius*Math.PI}clone(){return new t(this.center,this.radius)}collides(e){return bu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return ko(e,n,this)}random(){return this.center.add(E.fromAngle(he(360)).scale(he(this.radius)))}},Ke=class t{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,[i,m]=r.eigenvectors(o,s),[u,c]=[1/Math.sqrt(o),1/Math.sqrt(s)];return u>c?new t(v(),u,c,ct(Math.atan2(-i[1],i[0]))):new t(v(),c,u,ct(Math.atan2(-m[1],m[0])))}toMat2(){let e=ae(this.angle),n=Math.cos(e),r=Math.sin(e);return new Rt(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=gt.fromMat2(n).scale(o.x,o.y).rotate(r).toMat2();let i=t.fromMat2(n);return i.center=e.multVec2(this.center),i}}bbox(){if(this.angle==0)return W.fromPoints(this.center.sub(v(this.radiusX,this.radiusY)),this.center.add(v(this.radiusX,this.radiusY)));{let e=ae(this.angle),n=Math.cos(e),r=Math.sin(e),o=this.radiusX*n,s=this.radiusX*r,i=this.radiusY*r,m=this.radiusY*n,u=Math.sqrt(o*o+i*i),c=Math.sqrt(s*s+m*m);return W.fromPoints(this.center.sub(v(u,c)),this.center.add(v(u,c)))}}area(){return this.radiusX*this.radiusY*Math.PI}clone(){return new t(this.center,this.radiusX,this.radiusY,this.angle)}collides(e){return vu(this,e)}contains(e){e=e.sub(this.center);let n=ae(this.angle),r=Math.cos(n),o=Math.sin(n),s=e.x*r+e.y*o,i=-e.x*o+e.y*r;return s*s/(this.radiusX*this.radiusX)+i*i/(this.radiusY*this.radiusY)<1}raycast(e,n){return Eu(e,n,this)}random(){return this.center}};function Tu(t,e,n,r){let o=e.sub(t),s=r.sub(n),i=o.cross(s);return i<1e-5&&i>-1e-5||(i=n.sub(t).cross(s)/i,i<0||i>1)?null:t.add(o.scale(i))}var be=class t{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=v(Number.MAX_VALUE),n=v(-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 W.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 xu(this,e)}contains(e){return this.collides(e)}raycast(e,n){return Cu(e,n,this)}random(){return v()}cut(e,n){let r=new Oe(e,n),o=[],s=[],i=n.sub(e),m=this.pts[this.pts.length-1],u=m.sub(e),c=i.cross(u)>0;return this.pts.forEach(p=>{u=p.sub(e);let b=i.cross(u)>0;if(c!=b){let l=Tu(m,p,e,n);o.push(l),s.push(l),c=b}(b?o:s).push(p),m=p}),[o.length?new t(o):null,s.length?new t(s):null]}};function No(t,e,n,r){let o=r*r,s=1-r,i=s*s;return t.scale(i).add(e.scale(2*s*r)).add(n.scale(o))}function Uo(t,e,n,r){let o=1-r;return e.sub(t).scale(2*o).add(n.sub(e).scale(2*r))}function Ho(t,e,n,r){return n.sub(e.scale(2)).add(t).scale(2)}function Qt(t,e,n,r,o){let s=o*o,i=s*o,m=1-o,u=m*m,c=u*m;return t.scale(c).add(e.scale(3*u*o)).add(n.scale(3*m*s)).add(r.scale(i))}function qo(t,e,n,r,o){let s=o*o,i=1-o,m=i*i;return e.sub(t).scale(3*m).add(n.sub(e).scale(6*i*o)).add(r.sub(n).scale(3*s))}function zo(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))}function Wo(t,e,n,r,o){let s=.5*(((-o+2)*o-1)*o),i=.5*((3*o-5)*o*o+2),m=.5*(((-3*o+4)*o+1)*o),u=.5*((o-1)*o*o);return t.scale(s).add(e.scale(i)).add(n.scale(m)).add(r.scale(u))}function Yo(t,e,n,r,o){let s=.5*((-3*o+4)*o-1),i=.5*((9*o-10)*o),m=.5*((-9*o+8)*o+1),u=.5*((3*o-2)*o);return t.scale(s).add(e.scale(i)).add(n.scale(m)).add(r.scale(u))}function $o(t){let e=Vr(t),n=e(1);return r=>{let o=r*n,s=e(o,!0);return t(s)}}function Vr(t,e=10,n=10){let r=[0],o=[0],i=1/(e-1)/n,m=0,u=t(0),c=0;for(let p=1;p<e;p++){for(let b=0;b<n;b++){c+=i;let l=t(c),h=l.dist(u);m+=h,u=l}r[p]=m,o[p]=c}return o[e-1]=1,(p,b=!1)=>{if(b){let l=p;if(l<=0)return 0;if(l>=m)return 1;let h=0;for(;r[h+1]<l;)h++;let d=o[h],C=o[h+1],g=r[h],y=r[h+1],O=(l-g)/(y-g);return d+(C-d)*O}else{if(p<=0)return 0;if(p>=1)return r[e-1];let l=0;for(;o[l+1]<p;)l++;let h=o[l],d=o[l+1],C=r[l],g=r[l+1],y=(p-h)/(d-h);return C+(g-C)*y}}}function Ft(t,e,n,r){let o=2*t+e-2*r+n,s=-3*t+3*r-2*e-n,i=e,m=t;return u=>{let c=u*u,p=c*u;return o*p+s*c+i*u+m}}function Pr(t,e,n,r,o,s=Ft){let i=s(e.x,(1-o)*(n.x-t.x),(1-o)*(r.x-e.x),n.x),m=s(e.y,(1-o)*(n.y-t.y),(1-o)*(r.y-e.y),n.y);return u=>new E(i(u),m(u))}function Lt(t,e,n,r,o=Ft){return Pr(t,e,n,r,.5,o)}function Xo(t,e,n,r,o=Ft){return Lt(r.add(t.sub(e).scale(6)),t,r,t.add(r.sub(n).scale(6)),o)}function Qo(t,e,n,r,o,s,i,m=Ft){let u=m(e.x,.5*(1-o)*(1+i)*(1+s)*(e.x-t.x)+.5*(1-o)*(1-i)*(1-s)*(n.x-e.x),.5*(1-o)*(1+i)*(1-s)*(n.x-e.x)+.5*(1-o)*(1-i)*(1+s)*(r.x-n.x),n.x),c=m(e.y,.5*(1-o)*(1+i)*(1+s)*(e.y-t.y)+.5*(1-o)*(1-i)*(1-s)*(n.y-e.y),.5*(1-o)*(1+i)*(1-s)*(n.y-e.y)+.5*(1-o)*(1-i)*(1+s)*(r.y-n.y),n.y);return p=>new E(u(p),c(p))}function Jo(t,e,n,r){let o=2*t+e-2*r+n,s=-3*t+3*r-2*e+n,i=e;return m=>{let u=m*m;return 3*o*u+2*s*m+i}}function Wt(t){return 0<=t&&t<=1}function xr(t,e){return Math.abs(t-e)<=Number.EPSILON}function Yt(t){return t<0?-Math.pow(-t,1/3):Math.pow(t,1/3)}function Ou(t,e,n,r){let o=3*t-6*e+3*n,s=-3*t+3*e,i=t,m=-t+3*e-3*n+r;if(xr(m,0)){if(xr(o,0))return xr(s,0)?[]:[-i/s].filter(Wt);let y=Math.sqrt(s*s-4*o*i),O=2*o;return[(y-s)/O,(-s-y)/O].filter(Wt)}o/=m,s/=m,i/=m;let u=(3*s-o*o)/3,c=u/3,p=(2*o*o*o-9*o*s+27*i)/27,b=p/2,l=b*b+c*c*c;if(l<0){let y=-u/3,O=y*y*y,A=Math.sqrt(O),R=-p/(2*A),V=R<-1?-1:R>1?1:R,x=Math.acos(V),S=2*Yt(A),G=S*Math.cos(x/3)-o/3,M=S*Math.cos((x+2*Math.PI)/3)-o/3,D=S*Math.cos((x+4*Math.PI)/3)-o/3;return[G,M,D].filter(Wt)}if(l===0){let y=b<0?Yt(-b):-Yt(b),O=2*y-o/3,A=-y-o/3;return[O,A].filter(Wt)}let h=Math.sqrt(l),d=Yt(h-b),C=Yt(h+b);return[d-C-o/3].filter(Wt)}function Au(t,e,n,r,o){let s=Ou(t.x-o,e.x-o,n.x-o,r.x-o);return s.length>0?Qt(t,e,n,r,s[0]).y:NaN}function Zo(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 Se(n,t[r-1].x,t[r].x,t[r-1].y,t[r].y);return t[t.length-1].y}}function es(t,e){return n=>Au(v(0,0),t,e,v(1,1),n)}function ts(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)),i=r?s:0;return m=>{let u=Math.floor(m/n);return i+u*s}}function ns(t,e){let n=Number.MAX_VALUE,r={normal:v(0),distance:0};for(let o of[t,e])for(let s=0;s<o.pts.length;s++){let i=o.pts[s],u=o.pts[(s+1)%o.pts.length].sub(i).normal().unit(),c=Number.MAX_VALUE,p=-Number.MAX_VALUE;for(let d=0;d<t.pts.length;d++){let C=t.pts[d].dot(u);c=Math.min(c,C),p=Math.max(p,C)}let b=Number.MAX_VALUE,l=-Number.MAX_VALUE;for(let d=0;d<e.pts.length;d++){let C=e.pts[d].dot(u);b=Math.min(b,C),l=Math.max(l,C)}let h=Math.min(p,l)-Math.max(c,b);if(h<0)return null;if(h<Math.abs(n)){let d=l-c,C=b-p;n=Math.abs(d)<Math.abs(C)?d:C,r.normal=u,r.distance=n}}return r}function rs(t,e,n){return(e.x-t.x)*(n.y-t.y)-(e.y-t.y)*(n.x-t.x)>=0}function Su(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}function vr(t,e,n,r){let o=r.x-n.x,s=r.y-n.y,i=o*(t.y-n.y)-s*(t.x-n.x),m=o*(e.y-n.y)-s*(e.x-n.x);return i*m>=0}function Vu(t,e,n,r){return vr(t,e,n,r)&&vr(t,n,e,r)&&vr(t,r,e,n)}function Pu(t,e,n,r){for(let o of t)if(o!==e&&o!==n&&o!==r&&Vu(o,e,n,r))return!0;return!1}function Gu(t,e,n,r){return rs(t,e,n)&&!Pu(r,t,e,n)}function Gn(t){if(t.length<3)return[];if(t.length==3)return[t];let e=[],n=[],r=0;for(let b=0;b<t.length;b++){let l=t[r],h=t[b];(h.x<l.x||h.x==l.x&&h.y<l.y)&&(r=r),e[b]=b+1,n[b]=b-1}e[e.length-1]=0,n[0]=n.length-1,Su(t)||([e,n]=[n,e]);let o=[];for(let b=0;b<t.length;++b)rs(t[n[b]],t[b],t[e[b]])||o.push(t[b]);let s=[],i=t.length,m=1,u=0,c,p;for(;i>3;){c=e[m],p=n[m];let b=t[p],l=t[m],h=t[c];if(Gu(b,l,h,o))s.push([b,l,h]),e[p]=c,n[c]=p,o.splice(o.indexOf(l),1),--i,u=0;else if(++u>i)return[];m=c}return c=e[m],p=n[m],s.push([t[p],t[m],t[c]]),s}function os(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]),i=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)*i<0)return!1;return!0}var Mn=" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",lt="topleft";var ss="monospace",bt="monospace";var Jt="linear";var Zt=[{name:"a_pos",size:2},{name:"a_uv",size:2},{name:"a_color",size:4}],Mu=Zt.reduce((t,e)=>t+e.size,0),is=2048,as=is*4*Mu,us=is*6,cs=`
2
2
  attribute vec2 a_pos;
3
3
  attribute vec2 a_uv;
4
4
  attribute vec4 a_color;