var Ri = Object.defineProperty; var s = (t, e) => Ri(t, "name", { value: e, configurable: !0 }); var jr = (() => { 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 o = n.length, a = new Uint8Array( (((o - (n[o - 1] == "=") - (n[o - 2] == "=")) * 3) / 4) | 0 ), u = 0, l = 0; u < o; ) { var f = t[n.charCodeAt(u++)], v = t[n.charCodeAt(u++)], m = t[n.charCodeAt(u++)], P = t[n.charCodeAt(u++)]; (a[l++] = (f << 2) | (v >> 4)), (a[l++] = (v << 4) | (m >> 2)), (a[l++] = (m << 6) | P); } return a; }; })(); function be(t) { return (t * Math.PI) / 180; } s(be, "deg2rad"); function lt(t) { return (t * 180) / Math.PI; } s(lt, "rad2deg"); function Qe(t, e, n) { return e > n ? Qe(t, n, e) : Math.min(Math.max(t, e), n); } s(Qe, "clamp"); function Je(t, e, n) { if (typeof t == "number" && typeof e == "number") return t + (e - t) * n; if (t instanceof D && e instanceof D) return t.lerp(e, n); if (t instanceof re && e instanceof re) return t.lerp(e, n); throw new Error( `Bad value for lerp(): ${t}, ${e}. Only number, Vec2 and Color is supported.` ); } s(Je, "lerp"); function et(t, e, n, o, a) { return o + ((t - e) / (n - e)) * (a - o); } s(et, "map"); function Nr(t, e, n, o, a) { return Qe(et(t, e, n, o, a), o, a); } s(Nr, "mapc"); var D = class t { static { s(this, "Vec2"); } x = 0; y = 0; constructor(e = 0, n = e) { (this.x = e), (this.y = n); } static fromAngle(e) { let n = be(e); return new t(Math.cos(n), Math.sin(n)); } 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 = T(...e); return new t(this.x + n.x, this.y + n.y); } sub(...e) { let n = T(...e); return new t(this.x - n.x, this.y - n.y); } scale(...e) { let n = T(...e); return new t(this.x * n.x, this.y * n.y); } dist(...e) { let n = T(...e); return this.sub(n).len(); } sdist(...e) { let n = T(...e); return this.sub(n).slen(); } len() { return Math.sqrt(this.dot(this)); } slen() { return this.dot(this); } unit() { let e = this.len(); return e === 0 ? new t(0) : this.scale(1 / e); } normal() { return new t(this.y, -this.x); } reflect(e) { return this.sub(e.scale(2 * this.dot(e))); } project(e) { return e.scale(e.dot(this) / e.len()); } reject(e) { return this.sub(this.project(e)); } dot(e) { return this.x * e.x + this.y * e.y; } cross(e) { return this.x * e.y - this.y * e.x; } angle(...e) { let n = T(...e); return lt(Math.atan2(this.y - n.y, this.x - n.x)); } angleBetween(...e) { let n = T(...e); return lt(Math.atan2(this.cross(n), this.dot(n))); } lerp(e, n) { return new t(Je(this.x, e.x, n), Je(this.y, e.y, n)); } slerp(e, n) { let o = this.dot(e), a = this.cross(e), u = Math.atan2(a, o); return this.scale(Math.sin((1 - n) * u)) .add(e.scale(Math.sin(n * u))) .scale(1 / a); } 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 me(this, 0, 0); } toString() { return `vec2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`; } }; function T(...t) { if (t.length === 1) { if (t[0] instanceof D) return new D(t[0].x, t[0].y); if (Array.isArray(t[0]) && t[0].length === 2) return new D(...t[0]); } return new D(...t); } s(T, "vec2"); var re = class t { static { s(this, "Color"); } r = 255; g = 255; b = 255; constructor(e, n, o) { (this.r = Qe(e, 0, 255)), (this.g = Qe(n, 0, 255)), (this.b = Qe(o, 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); 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, o) { if (n == 0) return new t(255 * o, 255 * o, 255 * o); let a = s( (P, b, M) => ( M < 0 && (M += 1), M > 1 && (M -= 1), M < 1 / 6 ? P + (b - P) * 6 * M : M < 1 / 2 ? b : M < 2 / 3 ? P + (b - P) * (2 / 3 - M) * 6 : P ), "hue2rgb" ), u = o < 0.5 ? o * (1 + n) : o + n - o * n, l = 2 * o - u, f = a(l, u, e + 1 / 3), v = a(l, u, e), m = a(l, u, e - 1 / 3); return new t(Math.round(f * 255), Math.round(v * 255), Math.round(m * 255)); } static RED = new t(255, 0, 0); static GREEN = new t(0, 255, 0); static BLUE = new t(0, 0, 255); static YELLOW = new t(255, 255, 0); static MAGENTA = new t(255, 0, 255); static CYAN = new t(0, 255, 255); static WHITE = new t(255, 255, 255); static BLACK = new t(0, 0, 0); clone() { return new t(this.r, this.g, this.b); } lighten(e) { return new t(this.r + e, this.g + e, this.b + e); } darken(e) { return this.lighten(-e); } invert() { return new t(255 - this.r, 255 - this.g, 255 - this.b); } mult(e) { return new t( (this.r * e.r) / 255, (this.g * e.g) / 255, (this.b * e.b) / 255 ); } lerp(e, n) { return new t(Je(this.r, e.r, n), Je(this.g, e.g, n), Je(this.b, e.b, n)); } toHSL() { let e = this.r / 255, n = this.g / 255, o = this.b / 255, a = Math.max(e, n, o), u = Math.min(e, n, o), l = (a + u) / 2, f = l, v = l; if (a == u) l = f = 0; else { let m = a - u; switch (((f = v > 0.5 ? m / (2 - a - u) : m / (a + u)), a)) { case e: l = (n - o) / m + (n < o ? 6 : 0); break; case n: l = (o - e) / m + 2; break; case o: l = (e - n) / m + 4; break; } l /= 6; } return [l, f, v]; } 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 ce(...t) { if (t.length === 0) return new re(255, 255, 255); if (t.length === 1) { if (t[0] instanceof re) return t[0].clone(); if (typeof t[0] == "string") return re.fromHex(t[0]); if (Array.isArray(t[0]) && t[0].length === 3) return re.fromArray(t[0]); } return new re(...t); } s(ce, "rgb"); var _r = s((t, e, n) => re.fromHSL(t, e, n), "hsl2rgb"), he = class t { static { s(this, "Quad"); } x = 0; y = 0; w = 1; h = 1; constructor(e, n, o, a) { (this.x = e), (this.y = n), (this.w = o), (this.h = a); } 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 D(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 ge(t, e, n, o) { return new he(t, e, n, o); } s(ge, "quad"); var Vt = class t { static { s(this, "Mat2"); } a; b; c; d; constructor(e, n, o, a) { (this.a = e), (this.b = n), (this.c = o), (this.d = a); } 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 T(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, o = e + Math.sqrt(e * e - n), a = e - Math.sqrt(e * e - n); return [o, a]; } 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(T(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), o = Math.sin(e); return new t(n, o, -o, n); } static scale(e, n) { return new t(e, 0, 0, n); } }; var bt = class t { static { s(this, "Mat3"); } m11; m12; m13; m21; m22; m23; m31; m32; m33; constructor(e, n, o, a, u, l, f, v, m) { (this.m11 = e), (this.m12 = n), (this.m13 = o), (this.m21 = a), (this.m22 = u), (this.m23 = l), (this.m31 = f), (this.m32 = v), (this.m33 = m); } static fromMat2(e) { return new t(e.a, e.b, 0, e.c, e.d, 0, 0, 0, 1); } toMat2() { return new Vt(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), o = Math.sin(e), a = this.m11, u = this.m12; return ( (this.m11 = n * this.m11 + o * this.m21), (this.m12 = n * this.m12 + o * this.m22), (this.m21 = n * this.m21 - o * a), (this.m22 = n * this.m22 - o * u), 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 ); } }, De = class t { static { s(this, "Mat4"); } m = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; constructor(e) { e && (this.m = e); } static translate(e) { return new t([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, e.x, e.y, 0, 1]); } static scale(e) { return new t([e.x, 0, 0, 0, 0, e.y, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); } static rotateX(e) { e = be(-e); let n = Math.cos(e), o = Math.sin(e); return new t([1, 0, 0, 0, 0, n, -o, 0, 0, o, n, 0, 0, 0, 0, 1]); } static rotateY(e) { e = be(-e); let n = Math.cos(e), o = Math.sin(e); return new t([n, 0, o, 0, 0, 1, 0, 0, -o, 0, n, 0, 0, 0, 0, 1]); } static rotateZ(e) { e = be(-e); let n = Math.cos(e), o = Math.sin(e); return new t([n, -o, 0, 0, o, 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 = be(-e); let n = Math.cos(e), o = Math.sin(e), a = this.m[0], u = this.m[1], l = this.m[4], f = this.m[5]; return ( (this.m[0] = a * n + u * o), (this.m[1] = -a * o + u * n), (this.m[4] = l * n + f * o), (this.m[5] = -l * o + f * n), this ); } mult(e) { let n = []; for (let o = 0; o < 4; o++) for (let a = 0; a < 4; a++) n[o * 4 + a] = this.m[0 * 4 + a] * e.m[o * 4 + 0] + this.m[1 * 4 + a] * e.m[o * 4 + 1] + this.m[2 * 4 + a] * e.m[o * 4 + 2] + this.m[3 * 4 + a] * e.m[o * 4 + 3]; return new t(n); } multVec2(e) { return new D( 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 D(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 D(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 D(e / n, n); } else return new D(0, 0); } getRotation() { if (this.m[0] != 0 || this.m[1] != 0) { let e = Math.sqrt(this.m[0] * this.m[0] + this.m[1] * this.m[1]); return lt( this.m[1] > 0 ? Math.acos(this.m[0] / e) : -Math.acos(this.m[0] / e) ); } else if (this.m[4] != 0 || this.m[5] != 0) { let e = Math.sqrt(this.m[4] * this.m[4] + this.m[5] * this.m[5]); return lt( Math.PI / 2 - (this.m[5] > 0 ? Math.acos(-this.m[4] / e) : -Math.acos(this.m[4] / e)) ); } else return 0; } getSkew() { if (this.m[0] != 0 || this.m[1] != 0) { let e = Math.sqrt(this.m[0] * this.m[0] + this.m[1] * this.m[1]); return new D( 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 D( 0, Math.atan(this.m[0] * this.m[4] + this.m[1] * this.m[5]) / (e * e) ); } else return new D(0, 0); } invert() { let e = [], n = this.m[10] * this.m[15] - this.m[14] * this.m[11], o = this.m[9] * this.m[15] - this.m[13] * this.m[11], a = this.m[9] * this.m[14] - this.m[13] * this.m[10], u = this.m[8] * this.m[15] - this.m[12] * this.m[11], l = this.m[8] * this.m[14] - this.m[12] * this.m[10], f = this.m[8] * this.m[13] - this.m[12] * this.m[9], v = this.m[6] * this.m[15] - this.m[14] * this.m[7], m = this.m[5] * this.m[15] - this.m[13] * this.m[7], 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], M = this.m[4] * this.m[14] - this.m[12] * this.m[6], w = this.m[5] * this.m[15] - this.m[13] * this.m[7], _ = this.m[4] * this.m[13] - this.m[12] * this.m[5], $ = this.m[6] * this.m[11] - this.m[10] * this.m[7], X = this.m[5] * this.m[11] - this.m[9] * this.m[7], L = this.m[5] * this.m[10] - this.m[9] * this.m[6], Q = this.m[4] * this.m[11] - this.m[8] * this.m[7], O = this.m[4] * this.m[10] - this.m[8] * this.m[6], oe = this.m[4] * this.m[9] - this.m[8] * this.m[5]; (e[0] = this.m[5] * n - this.m[6] * o + this.m[7] * a), (e[4] = -(this.m[4] * n - this.m[6] * u + this.m[7] * l)), (e[8] = this.m[4] * o - this.m[5] * u + this.m[7] * f), (e[12] = -(this.m[4] * a - this.m[5] * l + this.m[6] * f)), (e[1] = -(this.m[1] * n - this.m[2] * o + this.m[3] * a)), (e[5] = this.m[0] * n - this.m[2] * u + this.m[3] * l), (e[9] = -(this.m[0] * o - this.m[1] * u + this.m[3] * f)), (e[13] = this.m[0] * a - this.m[1] * l + this.m[2] * f), (e[2] = this.m[1] * v - this.m[2] * m + this.m[3] * P), (e[6] = -(this.m[0] * v - this.m[2] * b + this.m[3] * M)), (e[10] = this.m[0] * w - this.m[1] * b + this.m[3] * _), (e[14] = -(this.m[0] * P - this.m[1] * M + this.m[2] * _)), (e[3] = -(this.m[1] * $ - this.m[2] * X + this.m[3] * L)), (e[7] = this.m[0] * $ - this.m[2] * Q + this.m[3] * O), (e[11] = -(this.m[0] * X - this.m[1] * Q + this.m[3] * oe)), (e[15] = this.m[0] * L - this.m[1] * O + this.m[2] * oe); let H = this.m[0] * e[0] + this.m[1] * e[4] + this.m[2] * e[8] + this.m[3] * e[12]; for (let ie = 0; ie < 4; ie++) for (let se = 0; se < 4; se++) e[ie * 4 + se] *= 1 / H; return new t(e); } clone() { return new t([...this.m]); } toString() { return this.m.toString(); } }; function $n(t, e, n, o = (a) => -Math.cos(a)) { return t + ((o(n) + 1) / 2) * (e - t); } s($n, "wave"); var Ui = 1103515245, Pi = 12345, kr = 2147483648, jt = class { static { s(this, "RNG"); } seed; constructor(e) { this.seed = e; } gen() { return (this.seed = (Ui * this.seed + Pi) % kr), this.seed / kr; } genNumber(e, n) { return e + this.gen() * (n - e); } genVec2(e, n) { return new D(this.genNumber(e.x, n.x), this.genNumber(e.y, n.y)); } genColor(e, n) { return new re( 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 D) return this.genVec2(T(0, 0), e[0]); if (e[0] instanceof re) return this.genColor(ce(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 D && e[1] instanceof D) return this.genVec2(e[0], e[1]); if (e[0] instanceof re && e[1] instanceof re) return this.genColor(e[0], e[1]); } } }, Xn = new jt(Date.now()); function Hr(t) { return t != null && (Xn.seed = t), Xn.seed; } s(Hr, "randSeed"); function kt(...t) { return Xn.genAny(...t); } s(kt, "rand"); function Qn(...t) { return Math.floor(kt(...t)); } s(Qn, "randi"); function Kr(t) { return kt() <= t; } s(Kr, "chance"); function Jn(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; } s(Jn, "shuffle"); function qr(t, e) { return t.length <= e ? t.slice() : Jn(t.slice()).slice(0, e); } s(qr, "chooseMultiple"); function zr(t) { return t[Qn(t.length)]; } s(zr, "choose"); function Zn(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 ); } s(Zn, "testRectRect"); function Mi(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 o = ((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, a = ((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 o < 0 || o > 1 || a < 0 || a > 1 ? null : o; } s(Mi, "testLineLineT"); function an(t, e) { let n = Mi(t, e); return n ? T(t.p1.x + n * (t.p2.x - t.p1.x), t.p1.y + n * (t.p2.y - t.p1.y)) : null; } s(an, "testLineLine"); function cn(t, e) { let n = e.p2.sub(e.p1), o = Number.NEGATIVE_INFINITY, a = Number.POSITIVE_INFINITY; if (n.x != 0) { let u = (t.pos.x - e.p1.x) / n.x, l = (t.pos.x + t.width - e.p1.x) / n.x; (o = Math.max(o, Math.min(u, l))), (a = Math.min(a, Math.max(u, l))); } if (n.y != 0) { let u = (t.pos.y - e.p1.y) / n.y, l = (t.pos.y + t.height - e.p1.y) / n.y; (o = Math.max(o, Math.min(u, l))), (a = Math.min(a, Math.max(u, l))); } return a >= o && a >= 0 && o <= 1; } s(cn, "testRectLine"); function er(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 ); } s(er, "testRectPoint"); function Wr(t, e) { let n = Math.max(t.pos.x, Math.min(e.center.x, t.pos.x + t.width)), o = Math.max(t.pos.y, Math.min(e.center.y, t.pos.y + t.height)); return T(n, o).sdist(e.center) <= e.radius * e.radius; } s(Wr, "testRectCircle"); function Yr(t, e) { return Xr(e, new Ae(t.points())); } s(Yr, "testRectPolygon"); function tr(t, e) { let n = e.sub(t.p1), o = t.p2.sub(t.p1); if (Math.abs(n.cross(o)) > Number.EPSILON) return !1; let a = n.dot(o) / o.dot(o); return a >= 0 && a <= 1; } s(tr, "testLinePoint"); function Rt(t, e) { let n = t.p2.sub(t.p1), o = n.dot(n), a = t.p1.sub(e.center), u = 2 * n.dot(a), l = a.dot(a) - e.radius * e.radius, f = u * u - 4 * o * l; if (o <= Number.EPSILON || f < 0) return !1; if (f == 0) { let v = -u / (2 * o); if (v >= 0 && v <= 1) return !0; } else { let v = (-u + Math.sqrt(f)) / (2 * o), m = (-u - Math.sqrt(f)) / (2 * o); if ((v >= 0 && v <= 1) || (m >= 0 && m <= 1)) return !0; } return rr(e, t.p1); } s(Rt, "testLineCircle"); function nr(t, e) { if (mt(e, t.p1) || mt(e, t.p2)) return !0; for (let n = 0; n < e.pts.length; n++) { let o = e.pts[n], a = e.pts[(n + 1) % e.pts.length]; if (an(t, new Ge(o, a))) return !0; } return !1; } s(nr, "testLinePolygon"); function rr(t, e) { return t.center.sdist(e) < t.radius * t.radius; } s(rr, "testCirclePoint"); function Di(t, e) { return ( t.center.sdist(e.center) < (t.radius + e.radius) * (t.radius + e.radius) ); } s(Di, "testCircleCircle"); function Nt(t, e) { let n = e.pts[e.pts.length - 1]; for (let o of e.pts) { if (Rt(new Ge(n, o), t)) return !0; n = o; } return rr(t, e.pts[0]) ? !0 : mt(e, t.center); } s(Nt, "testCirclePolygon"); function Xr(t, e) { for (let n = 0; n < t.pts.length; n++) if (nr(new Ge(t.pts[n], t.pts[(n + 1) % t.pts.length]), e)) return !0; return !!(t.pts.some((n) => mt(e, n)) || e.pts.some((n) => mt(t, n))); } s(Xr, "testPolygonPolygon"); function mt(t, e) { let n = !1, o = t.pts; for (let a = 0, u = o.length - 1; a < o.length; u = a++) o[a].y > e.y != o[u].y > e.y && e.x < ((o[u].x - o[a].x) * (e.y - o[a].y)) / (o[u].y - o[a].y) + o[a].x && (n = !n); return n; } s(mt, "testPolygonPoint"); function $r(t, e) { e = e.sub(t.center); let n = be(t.angle), o = Math.cos(n), a = Math.sin(n), u = e.x * o + e.y * a, l = -e.x * a + e.y * o; return ( (u * u) / (t.radiusX * t.radiusX) + (l * l) / (t.radiusY * t.radiusY) < 1 ); } s($r, "testEllipsePoint"); function sn(t, e) { let n = e.center.sub(t.center), o = be(t.angle), a = Math.cos(o), u = Math.sin(o), l = n.x * a + n.y * u, f = -n.x * u + n.y * a; return $r( new Ye(T(), t.radiusX + e.radius, t.radiusY + e.radius, 0), T(l, f) ); } s(sn, "testEllipseCircle"); function Qr(t, e) { let n = t.toMat2().inverse; return ( (e = new Ge( n.transform(e.p1.sub(t.center)), n.transform(e.p2.sub(t.center)) )), Rt(e, new Be(T(), 1)) ); } s(Qr, "testEllipseLine"); function Gi(t, e) { if (t.radiusX === t.radiusY) return sn(e, new Be(t.center, t.radiusX)); if (e.radiusX === e.radiusY) return sn(t, new Be(e.center, e.radiusX)); let n = new bt(1 / t.radiusX ** 2, 0, 0, 0, 1 / t.radiusY ** 2, 0, 0, 0, -1), o = new bt(1 / e.radiusX ** 2, 0, 0, 0, 1 / e.radiusY ** 2, 0, 0, 0, -1), a = t.center.x, u = t.center.y, l = e.center.x, f = e.center.y, v = be(t.angle), m = be(e.angle), P = new bt( Math.cos(v), -Math.sin(v), a, Math.sin(v), Math.cos(v), u, 0, 0, 1 ), b = new bt( Math.cos(m), -Math.sin(m), l, Math.sin(m), Math.cos(m), f, 0, 0, 1 ), M = P.inverse, w = b.inverse, _ = M.transpose.mul(n).mul(M), $ = w.transpose.mul(o).mul(w), X = _.m11, L = _.m12, Q = _.m13, O = _.m21, oe = _.m22, H = _.m23, ie = _.m31, se = _.m32, ae = _.m33, pe = $.m11, Ce = $.m12, ve = $.m13, Ie = $.m21, Le = $.m22, Te = $.m23, Ne = $.m31, _e = $.m32, He = $.m33, dt = X * oe * ae - X * H * se - L * O * ae + L * H * ie + Q * O * se - Q * oe * ie, Ee = (X * oe * He - X * H * _e - X * se * Te + X * ae * Le - L * O * He + L * H * Ne + L * ie * Te - L * ae * Ie + Q * O * _e - Q * oe * Ne - Q * ie * Le + Q * se * Ie + O * se * ve - O * ae * Ce - oe * ie * ve + oe * ae * pe + H * ie * Ce - H * se * pe) / dt, Re = (X * Le * He - X * Te * _e - L * Ie * He + L * Te * Ne + Q * Ie * _e - Q * Le * Ne - O * Ce * He + O * ve * _e + oe * pe * He - oe * ve * Ne - H * pe * _e + H * Ce * Ne + ie * Ce * Te - ie * ve * Le - se * pe * Te + se * ve * Ie + ae * pe * Le - ae * Ce * Ie) / dt, ze = (pe * Le * He - pe * Te * _e - Ce * Ie * He + Ce * Te * Ne + ve * Ie * _e - ve * Le * Ne) / dt; if (Ee >= 0) { let ot = -3 * Re + Ee ** 2, st = 3 * Ee * ze + Re * Ee ** 2 - 4 * Re ** 2, Ct = -27 * ze ** 2 + 18 * ze * Ee * Re + Ee ** 2 * Re ** 2 - 4 * Ee ** 3 * ze - 4 * Re ** 3; return !(ot > 0 && st < 0 && Ct > 0); } else { let ot = -3 * Re + Ee ** 2, st = -27 * ze ** 2 + 18 * ze * Ee * Re + Ee ** 2 * Re ** 2 - 4 * Ee ** 3 * ze - 4 * Re ** 3; return !(ot > 0 && st > 0); } } s(Gi, "testEllipseEllipse"); function Jr(t, e) { return or(t, new Ae(e.points())); } s(Jr, "testEllipseRect"); function or(t, e) { let n = t.toMat2().inverse; return ( (e = new Ae(e.pts.map((o) => n.transform(o.sub(t.center))))), Nt(new Be(T(), 1), e) ); } s(or, "testEllipsePolygon"); function Bi(t, e) { return e instanceof D ? tr(t, e) : e instanceof Be ? Rt(t, e) : e instanceof Ge ? an(t, e) != null : e instanceof me ? cn(e, t) : e instanceof Ae ? nr(t, e) : e instanceof Ye ? Qr(e, t) : !1; } s(Bi, "testLineShape"); function Fi(t, e) { return e instanceof D ? rr(t, e) : e instanceof Be ? Di(t, e) : e instanceof Ge ? Rt(e, t) : e instanceof me ? Wr(e, t) : e instanceof Ae ? Nt(t, e) : e instanceof Ye ? sn(e, t) : !1; } s(Fi, "testCircleShape"); function Ii(t, e) { return e instanceof D ? er(t, e) : e instanceof Be ? Wr(t, e) : e instanceof Ge ? cn(t, e) : e instanceof me ? Zn(t, e) : e instanceof Ae ? Yr(t, e) : e instanceof Ye ? Jr(e, t) : !1; } s(Ii, "testRectShape"); function Li(t, e) { return e instanceof D ? mt(t, e) : e instanceof Be ? Nt(e, t) : e instanceof Ge ? nr(e, t) : e instanceof me ? Yr(e, t) : e instanceof Ae ? Xr(e, t) : e instanceof Ye ? or(e, t) : !1; } s(Li, "testPolygonShape"); function ji(t, e) { return e instanceof D ? $r(t, e) : e instanceof Be ? sn(t, e) : e instanceof Ge ? Qr(t, e) : e instanceof me ? Jr(t, e) : e instanceof Ae ? or(t, e) : e instanceof Ye ? Gi(e, t) : !1; } s(ji, "testEllipseShape"); function Zr(t, e, n) { let o = t, a = n.p1, u = n.p2, l = e, f = u.sub(a), v = l.cross(f); if (Math.abs(v) < Number.EPSILON) return null; let m = a.sub(o), P = m.cross(f) / v; if (P <= 0 || P >= 1) return null; let b = m.cross(l) / v; if (b <= 0 || b >= 1) return null; let M = f.normal().unit(); return ( e.dot(M) > 0 && ((M.x *= -1), (M.y *= -1)), { point: o.add(l.scale(P)), normal: M, fraction: P } ); } s(Zr, "raycastLine"); function ki(t, e, n) { let o = Number.NEGATIVE_INFINITY, a = Number.POSITIVE_INFINITY, u; if (t.x != 0) { let l = (n.pos.x - t.x) / e.x, f = (n.pos.x + n.width - t.x) / e.x; (u = T(-Math.sign(e.x), 0)), (o = Math.max(o, Math.min(l, f))), (a = Math.min(a, Math.max(l, f))); } if (t.y != 0) { let l = (n.pos.y - t.y) / e.y, f = (n.pos.y + n.height - t.y) / e.y; Math.min(l, f) > o && (u = T(0, -Math.sign(e.y))), (o = Math.max(o, Math.min(l, f))), (a = Math.min(a, Math.max(l, f))); } return a >= o && o >= 0 && o <= 1 ? { point: t.add(e.scale(o)), normal: u, fraction: o } : null; } s(ki, "raycastRect"); function eo(t, e, n) { let o = t, a = n.center, u = e, l = u.dot(u), f = o.sub(a), v = 2 * u.dot(f), m = f.dot(f) - n.radius * n.radius, P = v * v - 4 * l * m; if (l <= Number.EPSILON || P < 0) return null; if (P == 0) { let b = -v / (2 * l); if (b >= 0 && b <= 1) { let M = o.add(u.scale(b)); return { point: M, normal: M.sub(a), fraction: b }; } } else { let b = (-v + Math.sqrt(P)) / (2 * l), M = (-v - Math.sqrt(P)) / (2 * l), w = null; if ( (b >= 0 && b <= 1 && (w = b), M >= 0 && M <= 1 && (w = Math.min(M, w ?? M)), w != null) ) { let _ = o.add(u.scale(w)); return { point: _, normal: _.sub(a).unit(), fraction: w }; } } return null; } s(eo, "raycastCircle"); function Ni(t, e, n) { let o = n.pts, a = null, u = o[o.length - 1]; for (let l = 0; l < o.length; l++) { let f = o[l], v = Zr(t, e, new Ge(u, f)); v && (!a || a.fraction > v.fraction) && (a = v), (u = f); } return a; } s(Ni, "raycastPolygon"); function _i(t, e, n) { let o = n.toMat2(), a = o.inverse, u = a.transform(t.sub(n.center)), l = a.transform(e), f = eo(u, l, new Be(T(), 1)); if (f) { let v = Vt.rotation(be(-n.angle)), P = Vt.scale(n.radiusX, n.radiusY).transform(f.point), b = o.transform(f.point).add(n.center), M = b.dist(t) / e.len(); return { point: b, normal: v.transform(T(n.radiusY ** 2 * P.x, n.radiusX ** 2 * P.y)), fraction: M, }; } return f; } s(_i, "raycastEllipse"); function to(t, e, n, o = 64) { let a = t, u = e.len(), l = e.scale(1 / u), f = 0, v = T(Math.floor(t.x), Math.floor(t.y)), m = T(l.x > 0 ? 1 : -1, l.y > 0 ? 1 : -1), P = T(Math.abs(1 / l.x), Math.abs(1 / l.y)), b = T( m.x > 0 ? v.x + 1 - t.x : t.x - v.x, m.y > 0 ? v.y + 1 - t.y : t.y - v.y ), M = T(P.x < 1 / 0 ? P.x * b.x : 1 / 0, P.y < 1 / 0 ? P.y * b.y : 1 / 0), w = -1; for (; f <= o; ) { let _ = n(v); if (_ === !0) return { point: a.add(l.scale(f)), normal: T(w === 0 ? -m.x : 0, w === 1 ? -m.y : 0), fraction: f / u, gridPos: v, }; if (_) return _; M.x < M.y ? ((v.x += m.x), (f = M.x), (M.x += P.x), (w = 0)) : ((v.y += m.y), (f = M.y), (M.y += P.y), (w = 1)); } return null; } s(to, "raycastGrid"); var Ge = class t { static { s(this, "Line"); } p1; p2; constructor(e, n) { (this.p1 = e.clone()), (this.p2 = n.clone()); } transform(e) { return new t(e.multVec2(this.p1), e.multVec2(this.p2)); } bbox() { return me.fromPoints(this.p1, this.p2); } area() { return this.p1.dist(this.p2); } clone() { return new t(this.p1, this.p2); } collides(e) { return Bi(this, e); } contains(e) { return this.collides(e); } raycast(e, n) { return Zr(e, n, this); } }, me = class t { static { s(this, "Rect"); } pos; width; height; constructor(e, n, o) { (this.pos = e.clone()), (this.width = n), (this.height = o); } static fromPoints(e, n) { return new t(e.clone(), n.x - e.x, n.y - e.y); } center() { return new D(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 Ae(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, o = this.pos.add(this.width, this.height), a = Math.max(n.x - e.x, 0, e.x - o.x), u = Math.max(n.y - e.y, 0, e.y - o.y); return a * a + u * u; } collides(e) { return Ii(this, e); } contains(e) { return this.collides(e); } raycast(e, n) { return ki(e, n, this); } }, Be = class t { static { s(this, "Circle"); } center; radius; constructor(e, n) { (this.center = e.clone()), (this.radius = n); } transform(e) { return new Ye(this.center, this.radius, this.radius).transform(e); } bbox() { return me.fromPoints( this.center.sub(T(this.radius)), this.center.add(T(this.radius)) ); } area() { return this.radius * this.radius * Math.PI; } clone() { return new t(this.center, this.radius); } collides(e) { return Fi(this, e); } contains(e) { return this.collides(e); } raycast(e, n) { return eo(e, n, this); } }, Ye = class t { static { s(this, "Ellipse"); } center; radiusX; radiusY; angle; constructor(e, n, o, a = 0) { (this.center = e.clone()), (this.radiusX = n), (this.radiusY = o), (this.angle = a); } static fromMat2(e) { let n = e.inverse, o = n.transpose.mul(n), [a, u] = o.eigenvalues, [l, f] = o.eigenvectors(a, u), [v, m] = [1 / Math.sqrt(a), 1 / Math.sqrt(u)]; return v > m ? new t(T(), v, m, lt(Math.atan2(-l[1], l[0]))) : new t(T(), m, v, lt(Math.atan2(-f[1], f[0]))); } toMat2() { let e = be(this.angle), n = Math.cos(e), o = Math.sin(e); return new Vt( n * this.radiusX, o * this.radiusY, -o * 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(), o = e.getRotation(), a = e.getScale(); n = bt.fromMat2(n).scale(a.x, a.y).rotate(o).toMat2(); let l = t.fromMat2(n); return (l.center = e.multVec2(this.center)), l; } } bbox() { if (this.angle == 0) return me.fromPoints( this.center.sub(T(this.radiusX, this.radiusY)), this.center.add(T(this.radiusX, this.radiusY)) ); { let e = be(this.angle), n = Math.cos(e), o = Math.sin(e), a = this.radiusX * n, u = this.radiusX * o, l = this.radiusY * o, f = this.radiusY * n, v = Math.sqrt(a * a + l * l), m = Math.sqrt(u * u + f * f); return me.fromPoints( this.center.sub(T(v, m)), this.center.add(T(v, m)) ); } } area() { return this.radiusX * this.radiusY * Math.PI; } clone() { return new t(this.center, this.radiusX, this.radiusY, this.angle); } collides(e) { return ji(this, e); } contains(e) { e = e.sub(this.center); let n = be(this.angle), o = Math.cos(n), a = Math.sin(n), u = e.x * o + e.y * a, l = -e.x * a + e.y * o; return ( (u * u) / (this.radiusX * this.radiusX) + (l * l) / (this.radiusY * this.radiusY) < 1 ); } raycast(e, n) { return _i(e, n, this); } }, Ae = class t { static { s(this, "Polygon"); } pts; constructor(e) { if (e.length < 3) throw new Error("Polygons should have at least 3 vertices"); this.pts = e; } transform(e) { return new t(this.pts.map((n) => e.multVec2(n))); } bbox() { let e = T(Number.MAX_VALUE), n = T(-Number.MAX_VALUE); for (let o of this.pts) (e.x = Math.min(e.x, o.x)), (n.x = Math.max(n.x, o.x)), (e.y = Math.min(e.y, o.y)), (n.y = Math.max(n.y, o.y)); return me.fromPoints(e, n); } area() { let e = 0, n = this.pts.length; for (let o = 0; o < n; o++) { let a = this.pts[o], u = this.pts[(o + 1) % n]; (e += a.x * u.y * 0.5), (e -= u.x * a.y * 0.5); } return Math.abs(e); } clone() { return new t(this.pts.map((e) => e.clone())); } collides(e) { return Li(this, e); } contains(e) { return this.collides(e); } raycast(e, n) { return Ni(e, n, this); } }; function no(t, e, n, o) { let a = o * o, u = 1 - o, l = u * u; return t .scale(l) .add(e.scale(2 * u * o)) .add(n.scale(a)); } s(no, "evaluateQuadratic"); function ro(t, e, n, o) { let a = 1 - o; return e .sub(t) .scale(2 * a) .add(n.sub(e).scale(2 * o)); } s(ro, "evaluateQuadraticFirstDerivative"); function oo(t, e, n, o) { return n.sub(e.scale(2)).add(t).scale(2); } s(oo, "evaluateQuadraticSecondDerivative"); function un(t, e, n, o, a) { let u = a * a, l = u * a, f = 1 - a, v = f * f, m = v * f; return t .scale(m) .add(e.scale(3 * v * a)) .add(n.scale(3 * f * u)) .add(o.scale(l)); } s(un, "evaluateBezier"); function so(t, e, n, o, a) { let u = a * a, l = 1 - a, f = l * l; return e .sub(t) .scale(3 * f) .add(n.sub(e).scale(6 * l * a)) .add(o.sub(n).scale(3 * u)); } s(so, "evaluateBezierFirstDerivative"); function io(t, e, n, o, a) { let u = 1 - a; return n .sub(e.scale(2)) .add(t) .scale(6 * u) .add( o .sub(n.scale(2)) .add(e) .scale(6 * a) ); } s(io, "evaluateBezierSecondDerivative"); function ao(t, e, n, o, a) { let u = 0.5 * (((-a + 2) * a - 1) * a), l = 0.5 * ((3 * a - 5) * a * a + 2), f = 0.5 * (((-3 * a + 4) * a + 1) * a), v = 0.5 * ((a - 1) * a * a); return t.scale(u).add(e.scale(l)).add(n.scale(f)).add(o.scale(v)); } s(ao, "evaluateCatmullRom"); function co(t, e, n, o, a) { let u = 0.5 * ((-3 * a + 4) * a - 1), l = 0.5 * ((9 * a - 10) * a), f = 0.5 * ((-9 * a + 8) * a + 1), v = 0.5 * ((3 * a - 2) * a); return t.scale(u).add(e.scale(l)).add(n.scale(f)).add(o.scale(v)); } s(co, "evaluateCatmullRomFirstDerivative"); function uo(t) { let e = sr(t), n = e(1); return (o) => { let a = o * n, u = e(a, !0); return t(u); }; } s(uo, "normalizedCurve"); function sr(t, e = 10, n = 10) { let o = [0], a = [0], l = 1 / (e - 1) / n, f = 0, v = t(0), m = 0; for (let P = 1; P < e; P++) { for (let b = 0; b < n; b++) { m += l; let M = t(m), w = M.dist(v); (f += w), (v = M); } (o[P] = f), (a[P] = m); } return ( (a[e - 1] = 1), (P, b = !1) => { if (b) { let M = P; if (M <= 0) return 0; if (M >= f) return 1; let w = 0; for (; o[w + 1] < M; ) w++; let _ = a[w], $ = a[w + 1], X = o[w], L = o[w + 1], Q = (M - X) / (L - X); return _ + ($ - _) * Q; } else { if (P <= 0) return 0; if (P >= 1) return o[e - 1]; let M = 0; for (; a[M + 1] < P; ) M++; let w = a[M], _ = a[M + 1], $ = o[M], X = o[M + 1], L = (P - w) / (_ - w); return $ + (X - $) * L; } } ); } s(sr, "curveLengthApproximation"); function It(t) { return 0 <= t && t <= 1; } s(It, "inZeroOneDomain"); function Wn(t, e) { return Math.abs(t - e) <= Number.EPSILON; } s(Wn, "approximately"); function Lt(t) { return t < 0 ? -Math.pow(-t, 1 / 3) : Math.pow(t, 1 / 3); } s(Lt, "cubeRoot"); function Hi(t, e, n, o) { let a = 3 * t - 6 * e + 3 * n, u = -3 * t + 3 * e, l = t, f = -t + 3 * e - 3 * n + o; if (Wn(f, 0)) { if (Wn(a, 0)) return Wn(u, 0) ? [] : [-l / u].filter(It); let L = Math.sqrt(u * u - 4 * a * l), Q = 2 * a; return [(L - u) / Q, (-u - L) / Q].filter(It); } (a /= f), (u /= f), (l /= f); let v = (3 * u - a * a) / 3, m = v / 3, P = (2 * a * a * a - 9 * a * u + 27 * l) / 27, b = P / 2, M = b * b + m * m * m; if (M < 0) { let L = -v / 3, Q = L * L * L, O = Math.sqrt(Q), oe = -P / (2 * O), H = oe < -1 ? -1 : oe > 1 ? 1 : oe, ie = Math.acos(H), ae = 2 * Lt(O), pe = ae * Math.cos(ie / 3) - a / 3, Ce = ae * Math.cos((ie + 2 * Math.PI) / 3) - a / 3, ve = ae * Math.cos((ie + 4 * Math.PI) / 3) - a / 3; return [pe, Ce, ve].filter(It); } if (M === 0) { let L = b < 0 ? Lt(-b) : -Lt(b), Q = 2 * L - a / 3, O = -L - a / 3; return [Q, O].filter(It); } let w = Math.sqrt(M), _ = Lt(w - b), $ = Lt(w + b); return [_ - $ - a / 3].filter(It); } s(Hi, "getCubicRoots"); function Ki(t, e, n, o, a) { let u = Hi(t.x - a, e.x - a, n.x - a, o.x - a); return u.length > 0 ? un(t, e, n, o, u[0]).y : NaN; } s(Ki, "cubicBezierYforX"); function lo(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 o = 0; o < e; o++) if (t[o].x >= n) return et(n, t[o - 1].x, t[o].x, t[o - 1].y, t[o].y); return t[t.length - 1].y; }; } s(lo, "easingLinear"); function mo(t, e) { return (n) => Ki(T(0, 0), t, e, T(1, 1), n); } s(mo, "easingCubicBezier"); function ho(t, e = "jump-end") { let n = 1 / t, o = e == "jump-start" || e == "jump-both", a = e == "jump-end" || e == "jump-both", u = 1 / (t + (a ? 1 : 0)), l = o ? u : 0; return (f) => { let v = Math.floor(f / n); return l + v * u; }; } s(ho, "easingSteps"); function po(t, e) { let n = Number.MAX_VALUE, o = T(0); for (let a of [t, e]) for (let u = 0; u < a.pts.length; u++) { let l = a.pts[u], v = a.pts[(u + 1) % a.pts.length].sub(l).normal().unit(), m = Number.MAX_VALUE, P = -Number.MAX_VALUE; for (let _ = 0; _ < t.pts.length; _++) { let $ = t.pts[_].dot(v); (m = Math.min(m, $)), (P = Math.max(P, $)); } let b = Number.MAX_VALUE, M = -Number.MAX_VALUE; for (let _ = 0; _ < e.pts.length; _++) { let $ = e.pts[_].dot(v); (b = Math.min(b, $)), (M = Math.max(M, $)); } let w = Math.min(P, M) - Math.max(m, b); if (w < 0) return null; if (w < Math.abs(n)) { let _ = M - m, $ = b - P; (n = Math.abs(_) < Math.abs($) ? _ : $), (o = v.scale(n)); } } return o; } s(po, "sat"); function fo(t, e, n) { return (e.x - t.x) * (n.y - t.y) - (e.y - t.y) * (n.x - t.x) >= 0; } s(fo, "isOrientedCcw"); function qi(t) { let e = 0, n = t[t.length - 1]; for (let o = 0; o < t.length; o++) (e += (t[o].x - n.x) * (t[o].y + n.y)), (n = t[o]); return e < 0; } s(qi, "isOrientedCcwPolygon"); function Yn(t, e, n, o) { let a = o.x - n.x, u = o.y - n.y, l = a * (t.y - n.y) - u * (t.x - n.x), f = a * (e.y - n.y) - u * (e.x - n.x); return l * f >= 0; } s(Yn, "onSameSide"); function zi(t, e, n, o) { return Yn(t, e, n, o) && Yn(t, n, e, o) && Yn(t, o, e, n); } s(zi, "pointInTriangle"); function Wi(t, e, n, o) { for (let a of t) if (a !== e && a !== n && a !== o && zi(a, e, n, o)) return !0; return !1; } s(Wi, "someInTriangle"); function Yi(t, e, n, o) { return fo(t, e, n) && !Wi(o, t, e, n); } s(Yi, "isEar"); function ir(t) { if (t.length < 3) return []; if (t.length == 3) return [t]; let e = [], n = [], o = 0; for (let b = 0; b < t.length; b++) { let M = t[o], w = t[b]; (w.x < M.x || (w.x == M.x && w.y < M.y)) && (o = o), (e[b] = b + 1), (n[b] = b - 1); } (e[e.length - 1] = 0), (n[0] = n.length - 1), qi(t) || ([e, n] = [n, e]); let a = []; for (let b = 0; b < t.length; ++b) fo(t[n[b]], t[b], t[e[b]]) || a.push(t[b]); let u = [], l = t.length, f = 1, v = 0, m, P; for (; l > 3; ) { (m = e[f]), (P = n[f]); let b = t[P], M = t[f], w = t[m]; if (Yi(b, M, w, a)) u.push([b, M, w]), (e[P] = m), (n[m] = P), a.splice(a.indexOf(M), 1), --l, (v = 0); else if (++v > l) return []; f = m; } return (m = e[f]), (P = n[f]), u.push([t[P], t[f], t[m]]), u; } s(ir, "triangulate"); function ar(t) { if (t.length < 3) return !1; let e = t.length - 2, n = t.length - 1, o = 0, a = t[n].sub(t[e]), u = t[o].sub(t[n]), l = a.cross(u); for (; o + 1 < t.length; ) if ( ((e = n), (n = o), o++, (a = t[n].sub(t[e])), (u = t[o].sub(t[n])), a.cross(u) * l < 0) ) return !1; return !0; } s(ar, "isConvex"); var _t = class extends Map { static { s(this, "Registry"); } lastID = 0; push(e) { let n = this.lastID; return this.set(n, e), this.lastID++, n; } pushd(e) { let n = this.push(e); return () => this.delete(n); } }, tt = class t { static { s(this, "EventController"); } paused = !1; cancel; constructor(e) { this.cancel = e; } static join(e) { let n = new t(() => e.forEach((o) => o.cancel())); return ( Object.defineProperty(n, "paused", { get: () => e[0].paused, set: (o) => e.forEach((a) => (a.paused = o)), }), (n.paused = !1), n ); } }, we = class { static { s(this, "Event"); } handlers = new _t(); add(e) { let n = this.handlers.pushd((...a) => { o.paused || e(...a); }), o = new tt(n); return o; } addOnce(e) { let n = this.add((...o) => { n.cancel(), e(...o); }); return n; } next() { return new Promise((e) => this.addOnce(e)); } trigger(...e) { this.handlers.forEach((n) => n(...e)); } numListeners() { return this.handlers.size; } clear() { this.handlers.clear(); } }, nt = class { static { s(this, "EventHandler"); } handlers = {}; on(e, n) { return ( this.handlers[e] || (this.handlers[e] = new we()), this.handlers[e].add(n) ); } onOnce(e, n) { let o = this.on(e, (...a) => { o.cancel(), n(...a); }); return o; } next(e) { return new Promise((n) => { this.onOnce(e, (...o) => n(o[0])); }); } trigger(e, ...n) { this.handlers[e] && this.handlers[e].trigger(...n); } remove(e) { delete this.handlers[e]; } clear() { this.handlers = {}; } numListeners(e) { return this.handlers[e]?.numListeners() ?? 0; } }; function mn(t, e) { if (t === e) return !0; let n = typeof t, o = typeof e; if (n !== o) return !1; if (n === "object" && o === "object" && t !== null && e !== null) { if (Array.isArray(t) !== Array.isArray(e)) return !1; let a = Object.keys(t), u = Object.keys(e); if (a.length !== u.length) return !1; for (let l of a) { let f = t[l], v = e[l]; if (!mn(f, v)) return !1; } return !0; } return !1; } s(mn, "deepEq"); function Xi(t) { let e = window.atob(t), n = e.length, o = new Uint8Array(n); for (let a = 0; a < n; a++) o[a] = e.charCodeAt(a); return o.buffer; } s(Xi, "base64ToArrayBuffer"); function bo(t) { return Xi(t.split(",")[1]); } s(bo, "dataURLToArrayBuffer"); function dn(t, e) { let n = document.createElement("a"); (n.href = e), (n.download = t), n.click(); } s(dn, "download"); function cr(t, e) { dn(t, "data:text/plain;charset=utf-8," + e); } s(cr, "downloadText"); function vo(t, e) { cr(t, JSON.stringify(e)); } s(vo, "downloadJSON"); function ur(t, e) { let n = URL.createObjectURL(e); dn(t, n), URL.revokeObjectURL(n); } s(ur, "downloadBlob"); var lr = s((t) => t.match(/^data:\w+\/\w+;base64,.+/), "isDataURL"); var xo = s((t) => t.split(".").slice(0, -1).join("."), "getFileName"); function Fe(t, e) { return (...n) => { let o = n.length; if (o === t.length) return t(...n); if (o === e.length) return e(...n); }; } s(Fe, "overload2"); var yo = (() => { let t = 0; return () => t++; })(), wo = s( (t) => (t instanceof Error ? t.message : String(t)), "getErrorMessage" ); var ln = class { static { s(this, "BinaryHeap"); } _items; _compareFn; constructor(e = (n, o) => n < o) { (this._compareFn = e), (this._items = []); } insert(e) { this._items.push(e), this.moveUp(this._items.length - 1); } remove() { if (this._items.length === 0) return null; let e = this._items[0], n = this._items.pop(); return ( this._items.length !== 0 && ((this._items[0] = n), this.moveDown(0)), e ); } clear() { this._items.splice(0, this._items.length); } moveUp(e) { for (; e > 0; ) { let n = Math.floor((e - 1) / 2); if ( !this._compareFn(this._items[e], this._items[n]) && this._items[e] >= this._items[n] ) break; this.swap(e, n), (e = n); } } moveDown(e) { for (; e < Math.floor(this._items.length / 2); ) { let n = 2 * e + 1; if ( (n < this._items.length - 1 && !this._compareFn(this._items[n], this._items[n + 1]) && ++n, this._compareFn(this._items[e], this._items[n])) ) break; this.swap(e, n), (e = n); } } swap(e, n) { [this._items[e], this._items[n]] = [this._items[n], this._items[e]]; } get length() { return this._items.length; } }; var $i = Object.freeze([ 776, 2359, 2367, 2984, 3007, 3021, 3633, 3635, 3648, 3657, 4352, 4449, 4520, ]); function Co(t) { if (typeof t != "string") throw new TypeError("string cannot be undefined or null"); let e = [], n = 0, o = 0; for (; n < t.length; ) { if ( ((o += Qi(n + o, t)), oa(t[n + o]) && o++, ta(t[n + o]) && o++, na(t[n + o]) && o++, sa(t[n + o])) ) { o++; continue; } e.push(t.substring(n, n + o)), (n += o), (o = 0); } return e; } s(Co, "runes"); function Qi(t, e) { let n = e[t]; if (!Ji(n) || t === e.length - 1) return 1; let o = n + e[t + 1], a = e.substring(t + 2, t + 5); return go(o) && go(a) ? 4 : Zi(o) && ra(a) ? e.slice(t).indexOf(String.fromCodePoint(917631)) + 2 : ea(a) ? 4 : 2; } s(Qi, "nextUnits"); function Ji(t) { return t && vt(t[0].charCodeAt(0), 55296, 56319); } s(Ji, "isFirstOfSurrogatePair"); function go(t) { return vt(mr(t), 127462, 127487); } s(go, "isRegionalIndicator"); function Zi(t) { return vt(mr(t), 127988, 127988); } s(Zi, "isSubdivisionFlag"); function ea(t) { return vt(mr(t), 127995, 127999); } s(ea, "isFitzpatrickModifier"); function ta(t) { return typeof t == "string" && vt(t.charCodeAt(0), 65024, 65039); } s(ta, "isVariationSelector"); function na(t) { return typeof t == "string" && vt(t.charCodeAt(0), 8400, 8447); } s(na, "isDiacriticalMark"); function ra(t) { let e = t.codePointAt(0); return typeof t == "string" && typeof e == "number" && vt(e, 917504, 917631); } s(ra, "isSupplementarySpecialpurposePlane"); function oa(t) { return typeof t == "string" && $i.includes(t.charCodeAt(0)); } s(oa, "isGrapheme"); function sa(t) { return typeof t == "string" && t.charCodeAt(0) === 8205; } s(sa, "isZeroWidthJoiner"); function mr(t) { let e = t.charCodeAt(0) - 55296, n = t.charCodeAt(1) - 56320; return (e << 10) + n + 65536; } s(mr, "codePointFromSurrogatePair"); function vt(t, e, n) { return t >= e && t <= n; } s(vt, "betweenInclusive"); function To(t) { return ( t?.prototype && Object.getOwnPropertyDescriptor(t.prototype, "constructor") !== void 0 ); } s(To, "isClass"); var dr = { "Joy-Con L+R (STANDARD GAMEPAD Vendor: 057e Product: 200e)": { buttons: { 0: "south", 1: "east", 2: "west", 3: "north", 4: "lshoulder", 5: "rshoulder", 6: "ltrigger", 7: "rtrigger", 8: "select", 9: "start", 10: "lstick", 11: "rstick", 12: "dpad-up", 13: "dpad-down", 14: "dpad-left", 15: "dpad-right", 16: "home", 17: "capture", }, sticks: { left: { x: 0, y: 1 }, right: { x: 2, y: 3 } }, }, "Joy-Con (L) (STANDARD GAMEPAD Vendor: 057e Product: 2006)": { buttons: { 0: "south", 1: "east", 2: "west", 3: "north", 4: "lshoulder", 5: "rshoulder", 9: "select", 10: "lstick", 16: "start", }, sticks: { left: { x: 0, y: 1 } }, }, "Joy-Con (R) (STANDARD GAMEPAD Vendor: 057e Product: 2007)": { buttons: { 0: "south", 1: "east", 2: "west", 3: "north", 4: "lshoulder", 5: "rshoulder", 9: "start", 10: "lstick", 16: "select", }, sticks: { left: { x: 0, y: 1 } }, }, "Pro Controller (STANDARD GAMEPAD Vendor: 057e Product: 2009)": { buttons: { 0: "south", 1: "east", 2: "west", 3: "north", 4: "lshoulder", 5: "rshoulder", 6: "ltrigger", 7: "rtrigger", 8: "select", 9: "start", 10: "lstick", 11: "rstick", 12: "dpad-up", 13: "dpad-down", 14: "dpad-left", 15: "dpad-right", 16: "home", 17: "capture", }, sticks: { left: { x: 0, y: 1 }, right: { x: 2, y: 3 } }, }, default: { buttons: { 0: "south", 1: "east", 2: "west", 3: "north", 4: "lshoulder", 5: "rshoulder", 6: "ltrigger", 7: "rtrigger", 8: "select", 9: "start", 10: "lstick", 11: "rstick", 12: "dpad-up", 13: "dpad-down", 14: "dpad-left", 15: "dpad-right", 16: "home", }, sticks: { left: { x: 0, y: 1 }, right: { x: 2, y: 3 } }, }, }; var Ut = class { static { s(this, "ButtonState"); } pressed = new Set([]); pressedRepeat = new Set([]); released = new Set([]); down = new Set([]); update() { this.pressed.clear(), this.released.clear(), this.pressedRepeat.clear(); } press(e) { this.pressed.add(e), this.pressedRepeat.add(e), this.down.add(e); } pressRepeat(e) { this.pressedRepeat.add(e); } release(e) { this.down.delete(e), this.pressed.delete(e), this.released.add(e); } }, hr = class { static { s(this, "GamepadState"); } buttonState = new Ut(); stickState = new Map(); }, pr = class { static { s(this, "FPSCounter"); } dts = []; timer = 0; fps = 0; tick(e) { this.dts.push(e), (this.timer += e), this.timer >= 1 && ((this.timer = 0), (this.fps = Math.round( 1 / (this.dts.reduce((n, o) => n + o) / this.dts.length) )), (this.dts = [])); } }, Eo = s((t) => { if (!t.canvas) throw new Error("Please provide a canvas"); let e = { canvas: t.canvas, loopID: null, stopped: !1, dt: 0, time: 0, realTime: 0, fpsCounter: new pr(), timeScale: 1, skipTime: !1, isHidden: !1, numFrames: 0, mousePos: new D(0), mouseDeltaPos: new D(0), keyState: new Ut(), mouseState: new Ut(), mergedGamepadState: new hr(), gamepadStates: new Map(), gamepads: [], charInputted: [], isMouseMoved: !1, lastWidth: t.canvas.offsetWidth, lastHeight: t.canvas.offsetHeight, events: new nt(), }; function n() { return e.dt * e.timeScale; } s(n, "dt"); function o() { return e.isHidden; } s(o, "isHidden"); function a() { return e.time; } s(a, "time"); function u() { return e.fpsCounter.fps; } s(u, "fps"); function l() { return e.numFrames; } s(l, "numFrames"); function f() { return e.canvas.toDataURL(); } s(f, "screenshot"); function v(p) { e.canvas.style.cursor = p; } s(v, "setCursor"); function m() { return e.canvas.style.cursor; } s(m, "getCursor"); function P(p) { if (p) try { let V = e.canvas.requestPointerLock(); V.catch && V.catch((j) => console.error(j)); } catch (V) { console.error(V); } else document.exitPointerLock(); } s(P, "setCursorLocked"); function b() { return !!document.pointerLockElement; } s(b, "isCursorLocked"); function M(p) { p.requestFullscreen ? p.requestFullscreen() : p.webkitRequestFullscreen && p.webkitRequestFullscreen(); } s(M, "enterFullscreen"); function w() { document.exitFullscreen ? document.exitFullscreen() : document.webkitExitFullScreen && document.webkitExitFullScreen(); } s(w, "exitFullscreen"); function _(p = !0) { p ? M(e.canvas) : w(); } s(_, "setFullscreen"); function $() { return ( document.fullscreenElement === e.canvas || document.webkitFullscreenElement === e.canvas ); } s($, "isFullscreen"); function X() { e.stopped = !0; for (let p in te) e.canvas.removeEventListener(p, te[p]); for (let p in We) document.removeEventListener(p, We[p]); for (let p in je) window.removeEventListener(p, je[p]); tn.disconnect(); } s(X, "quit"); function L(p) { e.loopID !== null && cancelAnimationFrame(e.loopID); let V = 0, j = s((J) => { if (e.stopped) return; if (document.visibilityState !== "visible") { e.loopID = requestAnimationFrame(j); return; } let xe = J / 1e3, le = xe - e.realTime, Ke = t.maxFPS ? 1 / t.maxFPS : 0; (e.realTime = xe), (V += le), V > Ke && (e.skipTime || ((e.dt = V), (e.time += n()), e.fpsCounter.tick(e.dt)), (V = 0), (e.skipTime = !1), e.numFrames++, Gt(), p(), Gn()), (e.loopID = requestAnimationFrame(j)); }, "frame"); j(0); } s(L, "run"); function Q() { return "ontouchstart" in window || navigator.maxTouchPoints > 0; } s(Q, "isTouchscreen"); function O() { return e.mousePos.clone(); } s(O, "mousePos"); function oe() { return e.mouseDeltaPos.clone(); } s(oe, "mouseDeltaPos"); function H(p = "left") { return e.mouseState.pressed.has(p); } s(H, "isMousePressed"); function ie(p = "left") { return e.mouseState.down.has(p); } s(ie, "isMouseDown"); function se(p = "left") { return e.mouseState.released.has(p); } s(se, "isMouseReleased"); function ae() { return e.isMouseMoved; } s(ae, "isMouseMoved"); function pe(p) { return p === void 0 ? e.keyState.pressed.size > 0 : e.keyState.pressed.has(p); } s(pe, "isKeyPressed"); function Ce(p) { return p === void 0 ? e.keyState.pressedRepeat.size > 0 : e.keyState.pressedRepeat.has(p); } s(Ce, "isKeyPressedRepeat"); function ve(p) { return p === void 0 ? e.keyState.down.size > 0 : e.keyState.down.has(p); } s(ve, "isKeyDown"); function Ie(p) { return p === void 0 ? e.keyState.released.size > 0 : e.keyState.released.has(p); } s(Ie, "isKeyReleased"); function Le(p) { return p === void 0 ? e.mergedGamepadState.buttonState.pressed.size > 0 : e.mergedGamepadState.buttonState.pressed.has(p); } s(Le, "isGamepadButtonPressed"); function Te(p) { return p === void 0 ? e.mergedGamepadState.buttonState.down.size > 0 : e.mergedGamepadState.buttonState.down.has(p); } s(Te, "isGamepadButtonDown"); function Ne(p) { return p === void 0 ? e.mergedGamepadState.buttonState.released.size > 0 : e.mergedGamepadState.buttonState.released.has(p); } s(Ne, "isGamepadButtonReleased"); function _e(p) { return e.events.on("resize", p); } s(_e, "onResize"); let He = Fe( (p) => e.events.on("keyDown", p), (p, V) => e.events.on("keyDown", (j) => j === p && V(p)) ), dt = Fe( (p) => e.events.on("keyPress", p), (p, V) => e.events.on("keyPress", (j) => j === p && V(p)) ), Ee = Fe( (p) => e.events.on("keyPressRepeat", p), (p, V) => e.events.on("keyPressRepeat", (j) => j === p && V(p)) ), Re = Fe( (p) => e.events.on("keyRelease", p), (p, V) => e.events.on("keyRelease", (j) => j === p && V(p)) ), ze = Fe( (p) => e.events.on("mouseDown", (V) => p(V)), (p, V) => e.events.on("mouseDown", (j) => j === p && V(j)) ), ot = Fe( (p) => e.events.on("mousePress", (V) => p(V)), (p, V) => e.events.on("mousePress", (j) => j === p && V(j)) ), st = Fe( (p) => e.events.on("mouseRelease", (V) => p(V)), (p, V) => e.events.on("mouseRelease", (j) => j === p && V(j)) ); function Ct(p) { return e.events.on("mouseMove", () => p(O(), oe())); } s(Ct, "onMouseMove"); function Xt(p) { return e.events.on("charInput", p); } s(Xt, "onCharInput"); function $t(p) { return e.events.on("touchStart", p); } s($t, "onTouchStart"); function An(p) { return e.events.on("touchMove", p); } s(An, "onTouchMove"); function Qt(p) { return e.events.on("touchEnd", p); } s(Qt, "onTouchEnd"); function Vn(p) { return e.events.on("scroll", p); } s(Vn, "onScroll"); function Rn(p) { return e.events.on("hide", p); } s(Rn, "onHide"); function Jt(p) { return e.events.on("show", p); } s(Jt, "onShow"); function Un(p, V) { if (typeof p == "function") return e.events.on("gamepadButtonDown", p); if (typeof p == "string" && typeof V == "function") return e.events.on("gamepadButtonDown", (j) => j === p && V(p)); } s(Un, "onGamepadButtonDown"); function Pn(p, V) { if (typeof p == "function") return e.events.on("gamepadButtonPress", p); if (typeof p == "string" && typeof V == "function") return e.events.on("gamepadButtonPress", (j) => j === p && V(p)); } s(Pn, "onGamepadButtonPress"); function Zt(p, V) { if (typeof p == "function") return e.events.on("gamepadButtonRelease", p); if (typeof p == "string" && typeof V == "function") return e.events.on("gamepadButtonRelease", (j) => j === p && V(p)); } s(Zt, "onGamepadButtonRelease"); function en(p, V) { return e.events.on("gamepadStick", (j, J) => j === p && V(J)); } s(en, "onGamepadStick"); function Mn(p) { e.events.on("gamepadConnect", p); } s(Mn, "onGamepadConnect"); function Dt(p) { e.events.on("gamepadDisconnect", p); } s(Dt, "onGamepadDisconnect"); function Dn(p) { return e.mergedGamepadState.stickState.get(p) || new D(0); } s(Dn, "getGamepadStick"); function it() { return [...e.charInputted]; } s(it, "charInputted"); function Se() { return [...e.gamepads]; } s(Se, "getGamepads"); function Gt() { e.events.trigger("input"), e.keyState.down.forEach((p) => e.events.trigger("keyDown", p)), e.mouseState.down.forEach((p) => e.events.trigger("mouseDown", p)), Fn(); } s(Gt, "processInput"); function Gn() { e.keyState.update(), e.mouseState.update(), e.mergedGamepadState.buttonState.update(), e.mergedGamepadState.stickState.forEach((p, V) => { e.mergedGamepadState.stickState.set(V, new D(0)); }), (e.charInputted = []), (e.isMouseMoved = !1), e.gamepadStates.forEach((p) => { p.buttonState.update(), p.stickState.forEach((V, j) => { p.stickState.set(j, new D(0)); }); }); } s(Gn, "resetInput"); function Tt(p) { let V = { index: p.index, isPressed: (j) => e.gamepadStates.get(p.index).buttonState.pressed.has(j), isDown: (j) => e.gamepadStates.get(p.index).buttonState.down.has(j), isReleased: (j) => e.gamepadStates.get(p.index).buttonState.released.has(j), getStick: (j) => e.gamepadStates.get(p.index).stickState.get(j), }; return ( e.gamepads.push(V), e.gamepadStates.set(p.index, { buttonState: new Ut(), stickState: new Map([ ["left", new D(0)], ["right", new D(0)], ]), }), V ); } s(Tt, "registerGamepad"); function Bn(p) { (e.gamepads = e.gamepads.filter((V) => V.index !== p.index)), e.gamepadStates.delete(p.index); } s(Bn, "removeGamepad"); function Fn() { for (let p of navigator.getGamepads()) p && !e.gamepadStates.has(p.index) && Tt(p); for (let p of e.gamepads) { let V = navigator.getGamepads()[p.index], J = (t.gamepads ?? {})[V.id] ?? dr[V.id] ?? dr.default, xe = e.gamepadStates.get(p.index); for (let le = 0; le < V.buttons.length; le++) V.buttons[le].pressed ? (xe.buttonState.down.has(J.buttons[le]) || (e.mergedGamepadState.buttonState.press(J.buttons[le]), xe.buttonState.press(J.buttons[le]), e.events.trigger("gamepadButtonPress", J.buttons[le])), e.events.trigger("gamepadButtonDown", J.buttons[le])) : xe.buttonState.down.has(J.buttons[le]) && (e.mergedGamepadState.buttonState.release(J.buttons[le]), xe.buttonState.release(J.buttons[le]), e.events.trigger("gamepadButtonRelease", J.buttons[le])); for (let le in J.sticks) { let Ke = J.sticks[le], at = new D(V.axes[Ke.x], V.axes[Ke.y]); xe.stickState.set(le, at), e.mergedGamepadState.stickState.set(le, at), e.events.trigger("gamepadStick", le, at); } } } s(Fn, "processGamepad"); let te = {}, We = {}, je = {}, Ue = t.pixelDensity || window.devicePixelRatio || 1; te.mousemove = (p) => { let V = new D(p.offsetX, p.offsetY), j = new D(p.movementX, p.movementY); if ($()) { let J = e.canvas.width / Ue, xe = e.canvas.height / Ue, le = window.innerWidth, Ke = window.innerHeight, at = le / Ke, In = J / xe; if (at > In) { let $e = Ke / xe, pt = (le - J * $e) / 2; (V.x = et(p.offsetX - pt, 0, J * $e, 0, J)), (V.y = et(p.offsetY, 0, xe * $e, 0, xe)); } else { let $e = le / J, pt = (Ke - xe * $e) / 2; (V.x = et(p.offsetX, 0, J * $e, 0, J)), (V.y = et(p.offsetY - pt, 0, xe * $e, 0, xe)); } } e.events.onOnce("input", () => { (e.isMouseMoved = !0), (e.mousePos = V), (e.mouseDeltaPos = j), e.events.trigger("mouseMove"); }); }; let Oe = ["left", "middle", "right", "back", "forward"]; (te.mousedown = (p) => { e.events.onOnce("input", () => { let V = Oe[p.button]; V && (e.mouseState.press(V), e.events.trigger("mousePress", V)); }); }), (te.mouseup = (p) => { e.events.onOnce("input", () => { let V = Oe[p.button]; V && (e.mouseState.release(V), e.events.trigger("mouseRelease", V)); }); }); let ht = new Set([ " ", "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Tab", ]), Et = { ArrowLeft: "left", ArrowRight: "right", ArrowUp: "up", ArrowDown: "down", " ": "space", }; (te.keydown = (p) => { ht.has(p.key) && p.preventDefault(), e.events.onOnce("input", () => { let V = Et[p.key] || p.key.toLowerCase(); V.length === 1 ? (e.events.trigger("charInput", V), e.charInputted.push(V)) : V === "space" && (e.events.trigger("charInput", " "), e.charInputted.push(" ")), p.repeat ? (e.keyState.pressRepeat(V), e.events.trigger("keyPressRepeat", V)) : (e.keyState.press(V), e.events.trigger("keyPressRepeat", V), e.events.trigger("keyPress", V)); }); }), (te.keyup = (p) => { e.events.onOnce("input", () => { let V = Et[p.key] || p.key.toLowerCase(); e.keyState.release(V), e.events.trigger("keyRelease", V); }); }), (te.touchstart = (p) => { p.preventDefault(), e.events.onOnce("input", () => { let V = [...p.changedTouches], j = e.canvas.getBoundingClientRect(); t.touchToMouse !== !1 && ((e.mousePos = new D(V[0].clientX - j.x, V[0].clientY - j.y)), e.mouseState.press("left"), e.events.trigger("mousePress", "left")), V.forEach((J) => { e.events.trigger( "touchStart", new D(J.clientX - j.x, J.clientY - j.y), J ); }); }); }), (te.touchmove = (p) => { p.preventDefault(), e.events.onOnce("input", () => { let V = [...p.changedTouches], j = e.canvas.getBoundingClientRect(); if (t.touchToMouse !== !1) { let J = e.mousePos; (e.mousePos = new D(V[0].clientX - j.x, V[0].clientY - j.y)), (e.mouseDeltaPos = e.mousePos.sub(J)), e.events.trigger("mouseMove"); } V.forEach((J) => { e.events.trigger( "touchMove", new D(J.clientX - j.x, J.clientY - j.y), J ); }); }); }), (te.touchend = (p) => { e.events.onOnce("input", () => { let V = [...p.changedTouches], j = e.canvas.getBoundingClientRect(); t.touchToMouse !== !1 && ((e.mousePos = new D(V[0].clientX - j.x, V[0].clientY - j.y)), (e.mouseDeltaPos = new D(0, 0)), e.mouseState.release("left"), e.events.trigger("mouseRelease", "left")), V.forEach((J) => { e.events.trigger( "touchEnd", new D(J.clientX - j.x, J.clientY - j.y), J ); }); }); }), (te.touchcancel = (p) => { e.events.onOnce("input", () => { let V = [...p.changedTouches], j = e.canvas.getBoundingClientRect(); t.touchToMouse !== !1 && ((e.mousePos = new D(V[0].clientX - j.x, V[0].clientY - j.y)), e.mouseState.release("left"), e.events.trigger("mouseRelease", "left")), V.forEach((J) => { e.events.trigger( "touchEnd", new D(J.clientX - j.x, J.clientY - j.y), J ); }); }); }), (te.wheel = (p) => { p.preventDefault(), e.events.onOnce("input", () => { e.events.trigger("scroll", new D(p.deltaX, p.deltaY)); }); }), (te.contextmenu = (p) => p.preventDefault()), (We.visibilitychange = () => { document.visibilityState === "visible" ? ((e.skipTime = !0), (e.isHidden = !1), e.events.trigger("show")) : ((e.isHidden = !0), e.events.trigger("hide")); }), (je.gamepadconnected = (p) => { let V = Tt(p.gamepad); e.events.onOnce("input", () => { e.events.trigger("gamepadConnect", V); }); }), (je.gamepaddisconnected = (p) => { let V = Se().filter((j) => j.index === p.gamepad.index)[0]; Bn(p.gamepad), e.events.onOnce("input", () => { e.events.trigger("gamepadDisconnect", V); }); }); for (let p in te) e.canvas.addEventListener(p, te[p]); for (let p in We) document.addEventListener(p, We[p]); for (let p in je) window.addEventListener(p, je[p]); let tn = new ResizeObserver((p) => { for (let V of p) if (V.target === e.canvas) { if ( e.lastWidth === e.canvas.offsetWidth && e.lastHeight === e.canvas.offsetHeight ) return; (e.lastWidth = e.canvas.offsetWidth), (e.lastHeight = e.canvas.offsetHeight), e.events.onOnce("input", () => { e.events.trigger("resize"); }); } }); return ( tn.observe(e.canvas), { dt: n, time: a, run: L, canvas: e.canvas, fps: u, numFrames: l, quit: X, isHidden: o, setFullscreen: _, isFullscreen: $, setCursor: v, screenshot: f, getGamepads: Se, getCursor: m, setCursorLocked: P, isCursorLocked: b, isTouchscreen: Q, mousePos: O, mouseDeltaPos: oe, isKeyDown: ve, isKeyPressed: pe, isKeyPressedRepeat: Ce, isKeyReleased: Ie, isMouseDown: ie, isMousePressed: H, isMouseReleased: se, isMouseMoved: ae, isGamepadButtonPressed: Le, isGamepadButtonDown: Te, isGamepadButtonReleased: Ne, getGamepadStick: Dn, charInputted: it, onResize: _e, onKeyDown: He, onKeyPress: dt, onKeyPressRepeat: Ee, onKeyRelease: Re, onMouseDown: ze, onMousePress: ot, onMouseRelease: st, onMouseMove: Ct, onCharInput: Xt, onTouchStart: $t, onTouchMove: An, onTouchEnd: Qt, onScroll: Vn, onHide: Rn, onShow: Jt, onGamepadButtonDown: Un, onGamepadButtonPress: Pn, onGamepadButtonRelease: Zt, onGamepadStick: en, onGamepadConnect: Mn, onGamepadDisconnect: Dt, events: e.events, } ); }, "default"); var qe = class t { static { s(this, "Texture"); } ctx; src = null; glTex; width; height; constructor(e, n, o, a = {}) { this.ctx = e; let u = e.gl; (this.glTex = e.gl.createTexture()), e.onDestroy(() => this.free()), (this.width = n), (this.height = o); let l = { linear: u.LINEAR, nearest: u.NEAREST }[ a.filter ?? e.opts.texFilter ] ?? u.NEAREST, f = { repeat: u.REPEAT, clampToEadge: u.CLAMP_TO_EDGE }[a.wrap] ?? u.CLAMP_TO_EDGE; this.bind(), n && o && u.texImage2D( u.TEXTURE_2D, 0, u.RGBA, n, o, 0, u.RGBA, u.UNSIGNED_BYTE, null ), u.texParameteri(u.TEXTURE_2D, u.TEXTURE_MIN_FILTER, l), u.texParameteri(u.TEXTURE_2D, u.TEXTURE_MAG_FILTER, l), u.texParameteri(u.TEXTURE_2D, u.TEXTURE_WRAP_S, f), u.texParameteri(u.TEXTURE_2D, u.TEXTURE_WRAP_T, f), this.unbind(); } static fromImage(e, n, o = {}) { let a = new t(e, n.width, n.height, o); return a.update(n), (a.src = n), a; } update(e, n = 0, o = 0) { let a = this.ctx.gl; this.bind(), a.texSubImage2D(a.TEXTURE_2D, 0, n, o, a.RGBA, a.UNSIGNED_BYTE, e), this.unbind(); } bind() { this.ctx.pushTexture2D(this.glTex); } unbind() { this.ctx.popTexture2D(); } free() { this.ctx.gl.deleteTexture(this.glTex); } }, yt = class { static { s(this, "FrameBuffer"); } ctx; tex; glFramebuffer; glRenderbuffer; constructor(e, n, o, a = {}) { this.ctx = e; let u = e.gl; e.onDestroy(() => this.free()), (this.tex = new qe(e, n, o, a)), (this.glFramebuffer = u.createFramebuffer()), (this.glRenderbuffer = u.createRenderbuffer()), this.bind(), u.renderbufferStorage(u.RENDERBUFFER, u.DEPTH_STENCIL, n, o), u.framebufferTexture2D( u.FRAMEBUFFER, u.COLOR_ATTACHMENT0, u.TEXTURE_2D, this.tex.glTex, 0 ), u.framebufferRenderbuffer( u.FRAMEBUFFER, u.DEPTH_STENCIL_ATTACHMENT, u.RENDERBUFFER, this.glRenderbuffer ), this.unbind(); } get width() { return this.tex.width; } get height() { return this.tex.height; } toImageData() { let e = this.ctx.gl, n = new Uint8ClampedArray(this.width * this.height * 4); this.bind(), e.readPixels(0, 0, this.width, this.height, e.RGBA, e.UNSIGNED_BYTE, n), this.unbind(); let o = this.width * 4, a = new Uint8Array(o); for (let u = 0; u < ((this.height / 2) | 0); u++) { let l = u * o, f = (this.height - u - 1) * o; a.set(n.subarray(l, l + o)), n.copyWithin(l, f, f + o), n.set(a, f); } return new ImageData(n, this.width, this.height); } toDataURL() { let e = document.createElement("canvas"), n = e.getContext("2d"); return ( (e.width = this.width), (e.height = this.height), n.putImageData(this.toImageData(), 0, 0), e.toDataURL() ); } clear() { let e = this.ctx.gl; e.clear(e.COLOR_BUFFER_BIT); } draw(e) { this.bind(), e(), this.unbind(); } bind() { this.ctx.pushFramebuffer(this.glFramebuffer), this.ctx.pushRenderbuffer(this.glRenderbuffer), this.ctx.pushViewport({ x: 0, y: 0, w: this.width, h: this.height }); } unbind() { this.ctx.popFramebuffer(), this.ctx.popRenderbuffer(), this.ctx.popViewport(); } free() { let e = this.ctx.gl; e.deleteFramebuffer(this.glFramebuffer), e.deleteRenderbuffer(this.glRenderbuffer), this.tex.free(); } }, hn = class { static { s(this, "Shader"); } ctx; glProgram; constructor(e, n, o, a) { (this.ctx = e), e.onDestroy(() => this.free()); let u = e.gl, l = u.createShader(u.VERTEX_SHADER), f = u.createShader(u.FRAGMENT_SHADER); u.shaderSource(l, n), u.shaderSource(f, o), u.compileShader(l), u.compileShader(f); let v = u.createProgram(); if ( ((this.glProgram = v), u.attachShader(v, l), u.attachShader(v, f), a.forEach((m, P) => u.bindAttribLocation(v, P, m)), u.linkProgram(v), !u.getProgramParameter(v, u.LINK_STATUS)) ) { let m = u.getShaderInfoLog(l); if (m) throw new Error("VERTEX SHADER " + m); let P = u.getShaderInfoLog(f); if (P) throw new Error("FRAGMENT SHADER " + P); } u.deleteShader(l), u.deleteShader(f); } bind() { this.ctx.pushProgram(this.glProgram); } unbind() { this.ctx.popProgram(); } send(e) { let n = this.ctx.gl; for (let o in e) { let a = e[o], u = n.getUniformLocation(this.glProgram, o); if (typeof a == "number") n.uniform1f(u, a); else if (a instanceof De) n.uniformMatrix4fv(u, !1, new Float32Array(a.m)); else if (a instanceof re) n.uniform3f(u, a.r, a.g, a.b); else if (a instanceof D) n.uniform2f(u, a.x, a.y); else if (Array.isArray(a)) { let l = a[0]; typeof l == "number" ? n.uniform1fv(u, a) : l instanceof D ? n.uniform2fv(u, a.map((f) => [f.x, f.y]).flat()) : l instanceof re && n.uniform3fv(u, a.map((f) => [f.r, f.g, f.b]).flat()); } else throw new Error("Unsupported uniform data type"); } } free() { this.ctx.gl.deleteProgram(this.glProgram); } }, pn = class { static { s(this, "BatchRenderer"); } ctx; glVBuf; glIBuf; vqueue = []; iqueue = []; stride; maxVertices; maxIndices; vertexFormat; numDraws = 0; curPrimitive = null; curTex = null; curShader = null; curUniform = {}; constructor(e, n, o, a) { let u = e.gl; (this.vertexFormat = n), (this.ctx = e), (this.stride = n.reduce((l, f) => l + f.size, 0)), (this.maxVertices = o), (this.maxIndices = a), (this.glVBuf = u.createBuffer()), e.pushArrayBuffer(this.glVBuf), u.bufferData(u.ARRAY_BUFFER, o * 4, u.DYNAMIC_DRAW), e.popArrayBuffer(), (this.glIBuf = u.createBuffer()), e.pushElementArrayBuffer(this.glIBuf), u.bufferData(u.ELEMENT_ARRAY_BUFFER, a * 4, u.DYNAMIC_DRAW), e.popElementArrayBuffer(); } push(e, n, o, a, u = null, l = {}) { (e !== this.curPrimitive || u !== this.curTex || a !== this.curShader || !mn(this.curUniform, l) || this.vqueue.length + n.length * this.stride > this.maxVertices || this.iqueue.length + o.length > this.maxIndices) && this.flush(); let f = this.vqueue.length / this.stride; for (let v of n) this.vqueue.push(v); for (let v of o) this.iqueue.push(v + f); (this.curPrimitive = e), (this.curShader = a), (this.curTex = u), (this.curUniform = l); } flush() { if ( !this.curPrimitive || !this.curShader || this.vqueue.length === 0 || this.iqueue.length === 0 ) return; let e = this.ctx.gl; this.ctx.pushArrayBuffer(this.glVBuf), e.bufferSubData(e.ARRAY_BUFFER, 0, new Float32Array(this.vqueue)), this.ctx.pushElementArrayBuffer(this.glIBuf), e.bufferSubData( e.ELEMENT_ARRAY_BUFFER, 0, new Uint16Array(this.iqueue) ), this.ctx.setVertexFormat(this.vertexFormat), this.curShader.bind(), this.curShader.send(this.curUniform), this.curTex?.bind(), e.drawElements( this.curPrimitive, this.iqueue.length, e.UNSIGNED_SHORT, 0 ), this.curTex?.unbind(), this.curShader.unbind(), this.ctx.popArrayBuffer(), this.ctx.popElementArrayBuffer(), (this.vqueue = []), (this.iqueue = []), this.numDraws++; } free() { let e = this.ctx.gl; e.deleteBuffer(this.glVBuf), e.deleteBuffer(this.glIBuf); } }; function xt(t) { let e = [], n = s((u) => { e.push(u), t(u); }, "push"), o = s(() => { e.pop(), t(a() ?? null); }, "pop"), a = s(() => e[e.length - 1], "cur"); return [n, o, a]; } s(xt, "genStack"); function fr(t, e = {}) { let n = []; function o(H) { n.push(H); } s(o, "onDestroy"); function a() { n.forEach((H) => H()), t.getExtension("WEBGL_lose_context").loseContext(); } s(a, "destroy"); let u = null; function l(H) { if (mn(H, u)) return; u = H; let ie = H.reduce((se, ae) => se + ae.size, 0); H.reduce( (se, ae, pe) => ( t.vertexAttribPointer(pe, ae.size, t.FLOAT, !1, ie * 4, se), t.enableVertexAttribArray(pe), se + ae.size * 4 ), 0 ); } s(l, "setVertexFormat"); let [f, v] = xt((H) => t.bindTexture(t.TEXTURE_2D, H)), [m, P] = xt((H) => t.bindBuffer(t.ARRAY_BUFFER, H)), [b, M] = xt((H) => t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, H)), [w, _] = xt((H) => t.bindFramebuffer(t.FRAMEBUFFER, H)), [$, X] = xt((H) => t.bindRenderbuffer(t.RENDERBUFFER, H)), [L, Q] = xt(({ x: H, y: ie, w: se, h: ae }) => { t.viewport(H, ie, se, ae); }), [O, oe] = xt((H) => t.useProgram(H)); return ( L({ x: 0, y: 0, w: t.drawingBufferWidth, h: t.drawingBufferHeight }), { gl: t, opts: e, onDestroy: o, destroy: a, pushTexture2D: f, popTexture2D: v, pushArrayBuffer: m, popArrayBuffer: P, pushElementArrayBuffer: b, popElementArrayBuffer: M, pushFramebuffer: w, popFramebuffer: _, pushRenderbuffer: $, popRenderbuffer: X, pushViewport: L, popViewport: Q, pushProgram: O, popProgram: oe, setVertexFormat: l, } ); } s(fr, "initGfx"); var Ve = class t { static { s(this, "Asset"); } loaded = !1; data = null; error = null; onLoadEvents = new we(); onErrorEvents = new we(); onFinishEvents = new we(); constructor(e) { e.then((n) => { (this.loaded = !0), (this.data = n), this.onLoadEvents.trigger(n); }) .catch((n) => { if (((this.error = n), this.onErrorEvents.numListeners() > 0)) this.onErrorEvents.trigger(n); else throw n; }) .finally(() => { this.onFinishEvents.trigger(), (this.loaded = !0); }); } static loaded(e) { let n = new t(Promise.resolve(e)); return (n.data = e), (n.loaded = !0), n; } onLoad(e) { return ( this.loaded && this.data ? e(this.data) : this.onLoadEvents.add(e), this ); } onError(e) { return ( this.loaded && this.error ? e(this.error) : this.onErrorEvents.add(e), this ); } onFinish(e) { return this.loaded ? e() : this.onFinishEvents.add(e), this; } then(e) { return this.onLoad(e); } catch(e) { return this.onError(e); } finally(e) { return this.onFinish(e); } }, rt = class { static { s(this, "AssetBucket"); } assets = new Map(); lastUID = 0; add(e, n) { let o = e ?? this.lastUID++ + "", a = new Ve(n); return this.assets.set(o, a), a; } addLoaded(e, n) { let o = e ?? this.lastUID++ + "", a = Ve.loaded(n); return this.assets.set(o, a), a; } get(e) { return this.assets.get(e); } progress() { if (this.assets.size === 0) return 1; let e = 0; return ( this.assets.forEach((n) => { n.loaded && e++; }), e / this.assets.size ); } }; function gr(t) { return fetch(t).then((e) => { if (!e.ok) throw new Error(`Failed to fetch "${t}"`); return e; }); } s(gr, "fetchURL"); function Ht(t) { return gr(t).then((e) => e.json()); } s(Ht, "fetchJSON"); function So(t) { return gr(t).then((e) => e.text()); } s(So, "fetchText"); function Oo(t) { return gr(t).then((e) => e.arrayBuffer()); } s(Oo, "fetchArrayBuffer"); function Kt(t) { let e = new Image(); return ( (e.crossOrigin = "anonymous"), (e.src = t), new Promise((n, o) => { (e.onload = () => n(e)), (e.onerror = () => o(new Error(`Failed to load image from "${t}"`))); }) ); } s(Kt, "loadImg"); var br = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", Pt = "topleft"; var Ao = "monospace", qt = "monospace"; var fn = "linear"; var gn = [ { name: "a_pos", size: 2 }, { name: "a_uv", size: 2 }, { name: "a_color", size: 4 }, ], aa = gn.reduce((t, e) => t + e.size, 0), Vo = 2048, Ro = Vo * 4 * aa, Uo = Vo * 6, Po = ` attribute vec2 a_pos; attribute vec2 a_uv; attribute vec4 a_color; varying vec2 v_pos; varying vec2 v_uv; varying vec4 v_color; vec4 def_vert() { return vec4(a_pos, 0.0, 1.0); } {{user}} void main() { vec4 pos = vert(a_pos, a_uv, a_color); v_pos = a_pos; v_uv = a_uv; v_color = a_color; gl_Position = pos; } `, Mo = ` precision mediump float; varying vec2 v_pos; varying vec2 v_uv; varying vec4 v_color; uniform sampler2D u_tex; vec4 def_frag() { return v_color * texture2D(u_tex, v_uv); } {{user}} void main() { gl_FragColor = frag(v_pos, v_uv, v_color, u_tex); if (gl_FragColor.a == 0.0) { discard; } } `, bn = ` vec4 vert(vec2 pos, vec2 uv, vec4 color) { return def_vert(); } `, vn = ` vec4 frag(vec2 pos, vec2 uv, vec4 color, sampler2D tex) { return def_frag(); } `, Do = new Set(["id", "require"]), Go = new Set(["add", "update", "draw", "destroy", "inspect", "drawInspect"]), vr = /\[(?