diff --git a/README.md b/README.md index 7907990..044e1d9 100644 --- a/README.md +++ b/README.md @@ -4,97 +4,4 @@ EventMapper, a lightweight (hopefully), easily-deployable, nearly-static digital ## Specifications -### Data Folder Structure -``` -/events - [FLOOR].json -/rooms - [FLOOR].json -floors.json -tags.json -``` - -### Floor -Used to represent a floor in a building. It is a parent to both its [Rooms](#room) and [Events](#events). -This object gets represented in the app as a map poly, and in a set of buttons among other floors. -```json -{ - "id": "[FLOOR ID]", - "poly": [ - [x, y], // An array of vertex positions. - ... - ], - "lang": { - "[IETF LANGUAGE TAG]": { - "name": "[SHORT SINGLE-LINE STRING]", - "description": "[SINGLE-LINE STRING]" - } - } -} -``` -This will be stored in an array in `floors.json` to be accessed by clients. - -### Room -Used to represent a space in which events can happen. It is a child to a [Floor](#floor), and a parent to [Events](#event). -This object gets represented in the app as a map poly. -```json -{ - "id": "[FLOOR]_[ROOM ID]", - "poly": [ - [x, y], // An array of vertex positions. - ... - ], - "tags": ["[ARRAY", "OF", "TAG", "IDS]"], - "lang": { - "[IETF LANGUAGE TAG]": { - "name": "[SINGLE-LINE STRING]", - "shortName": "[INITIALS OF NAME]", - "description": "[SINGLE-LINE STRING]" - } - } -} -``` -This will be stored in an array in `rooms/[FLOOR].json` to be accessed by clients. - -### Event -Used to represent a point in time when an activity happens. It is a child to both a [Floor](#floor) and a [Room](#room), reflected in its ID. -```json -{ - "id": "[FLOOR]_[ROOM]_[EVENT ID]", - "when": { - "start": "[ISO 8601 DATE]", - "end": "[ISO 8601 DATE]" - }, - "tags": ["[ARRAY", "OF", "TAG", "IDS]"], - "lang": { - "[IETF LANGUAGE TAG]": { - "name": "[SINGLE-LINE STRING]", - "description": "[MULTI-LINE STRING]", - "host": "[HOST NAME (OPTIONAL)]" - } - } -} -``` -This will be stored in an array in `events/[FLOOR].json` to be accessed by clients. - -### Tag -Used to represent a tag that can be applied by ID to a Room or Event. -This object gets represented in the app as a searchable tag chip. - -`radiogroup` can be used to un-toggle other tags when this one is selected. -`show` can be used to hide the tag from search completely. -```json -{ - "id": "[FLOOR ID]", - "radiogroup": "[GROUP ID]", - "show": , - "lang": { - "[IETF LANGUAGE TAG]": { - "name": "[SHORT SINGLE-LINE STRING]", - "shortName": "[INITIALS OF NAME]", - "description": "[SINGLE-LINE STRING]" - } - } -} -``` -This will be stored in an array in `tags.json` to be accessed by clients. \ No newline at end of file +TO BE REDONE \ No newline at end of file diff --git a/assets/scripts/KaplayMap/gameobj.js b/assets/scripts/KaplayMap/gameobj.js index 0898773..0ea3e0b 100644 --- a/assets/scripts/KaplayMap/gameobj.js +++ b/assets/scripts/KaplayMap/gameobj.js @@ -1,20 +1,34 @@ export class GameObjManager { map; opts = { - textColor: "FFFFFF", - bgColor: "303030", - bgFocusColor: "505030", - bgHoverColor: "505050", - bgFocusHoverColor: "707050", - bgClickColor: "202020", - bgFocusClickColor: "404020", - borderColor: "000000", - borderFocusColor: "808000", - font: "monospace", - fontSize: 24, - maxFontWidth: 16, - floorOpacity: 0.75, - roomOpacity: 0.75, + styles: { + default: { + textColor: "FFFFFF", + backgroundColor: "303030", + borderColor: "000000", + actionColor: "000000", + textOpacity: 1, + backgroundOpacity: 0.75, + borderOpacity: 1, + borderWidth: 8, + font: "monospace", + fontSize: 24, + fontWidth: 16, + }, + defaultFocused: { + textColor: "FFFFFF", + backgroundColor: "505030", + borderColor: "808000", + actionColor: "000000", + textOpacity: 1, + backgroundOpacity: 0.75, + borderOpacity: 1, + borderWidth: 8, + font: "monospace", + fontSize: 24, + fontWidth: 16, + }, + }, }; mainmanager; @@ -30,45 +44,126 @@ export class GameObjManager { }; } + __getTopStyle(styles = [], focused = false) { + const defaultFocused = { + ...this.opts.styles.default, + ...this.opts.styles.defaultFocused, + }; + if (focused) { + return styles.reduce((lastStyle, style) => { + return { + ...lastStyle, + ...this.opts.styles[style], + ...this.opts.styles[style + "Focused"], + }; + }, defaultFocused); + } else { + return styles.reduce((lastStyle, style) => { + return { + ...lastStyle, + ...this.opts.styles[style], + }; + }, this.opts.styles.default); + } + } + + __getTopFloorStyle(styles = []) { + const defaultFloor = { + ...this.opts.styles.default, + ...this.opts.styles.default_floor, + }; + return styles.reduce((lastStyle, style) => { + return { + ...lastStyle, + ...this.opts.styles[style], + }; + }, defaultFloor); + } + generateFloor() { if (this.floorObject) this.floorObject.destroy(); const currentFloor = this.mainmanager.getCurrentFocusObject("floor"); + // Generate regular polygon for area() + if (currentFloor.polys && currentFloor.poly == null) + currentFloor.poly = currentFloor.polys.flat(1); + const polygon = new this.map.kp.Polygon( currentFloor.poly.map(([x, y]) => this.map.kp.vec2(x, y)) ); - this.floorObject = this.map.kp.make([ - this.map.kp.polygon(polygon.pts), - this.map.kp.color(this.map.kp.Color.fromHex(this.opts.bgColor)), - this.map.kp.opacity(this.opts.floorOpacity), - this.map.kp.pos(), - this.map.kp.z(5), - ]); - const bounds = polygon.bbox(); this.map.camBounds = bounds; + const curStyle = this.__getTopFloorStyle(currentFloor.styles); + + this.floorObject = this.map.kp.make([ + this.map.kp.polygon(polygon.pts, { + triangulate: true, + }), + this.map.kp.opacity(0), + this.map.kp.pos(), + this.map.kp.z(4), + ]); + + let polysgon; + if (currentFloor.polys) + polysgon = currentFloor.polys.map( + (poly) => + new this.map.kp.Polygon(poly.map(([x, y]) => this.map.kp.vec2(x, y))) + ); + this.floorObject.onDraw(() => { const camScale = 1 / this.map.kp.camScale().y; + if (polysgon) { + polysgon.forEach((poly) => { + this.map.kp.drawPolygon({ + pts: poly.pts, + pos: this.map.kp.vec2(0), + triangulate: true, + color: this.map.kp.Color.fromHex(curStyle.backgroundColor), + opacity: curStyle.backgroundOpacity, + }); + }); + } else { + this.map.kp.drawPolygon({ + pts: polygon.pts, + pos: this.map.kp.vec2(0), + triangulate: true, + color: this.map.kp.Color.fromHex(curStyle.backgroundColor), + opacity: curStyle.backgroundOpacity, + }); + } + this.map.kp.drawPolygon({ pts: polygon.pts, pos: this.map.kp.vec2(0), fill: false, + triangulate: true, outline: { - color: this.map.kp.Color.fromHex(this.opts.borderColor), - width: 8 * camScale, + color: this.map.kp.Color.fromHex(curStyle.borderColor), + opacity: curStyle.borderOpacity, + width: curStyle.borderWidth * camScale, }, }); + let text = currentFloor.name; + if (curStyle.textTransform == "uppercase") { + text = text.toUpperCase(); + } else if (curStyle.textTransform == "lowercase") { + text = text.toLowerCase(); + } + this.map.kp.drawText({ - text: currentFloor.name, - size: 24 * camScale, + text, + size: curStyle.fontSize * camScale, + font: curStyle.font, pos: this.map.kp.vec2(-4 * camScale, -8 * camScale), - color: this.map.kp.Color.fromHex(this.opts.textColor), + color: this.map.kp.Color.fromHex(curStyle.textColor), + opacity: curStyle.textOpacity, anchor: "botleft", }); }); @@ -76,14 +171,14 @@ export class GameObjManager { this.map.kp.add(this.floorObject); } - zoomToBounds(boundingBox) { + zoomToBounds(boundingBox, pos) { // Get screen size const width = this.map.kp.width(); const height = this.map.kp.height(); // Get bbox size - const bBoxWidth = boundingBox.width * 2; - const bBoxHeight = boundingBox.height * 2; + const bBoxWidth = boundingBox.width * 1.25; + const bBoxHeight = boundingBox.height * 1.25; // Compare bounds const scaledWidth = width / bBoxWidth; @@ -92,9 +187,12 @@ export class GameObjManager { // Whichever one is biggest const scale = Math.min(scaledWidth, scaledHeight); + let newPos = boundingBox.center(); + if (pos) newPos = newPos.add(pos); + this.map.zoomToAbs( Math.log2(scale), // log scale - boundingBox.center() + newPos ); } @@ -110,7 +208,7 @@ export class GameObjManager { const objectBounds = selectedObject.renderArea().bbox(); - this.zoomToBounds(objectBounds); + this.zoomToBounds(objectBounds, selectedObject.pos); } generateRooms() { @@ -122,17 +220,30 @@ export class GameObjManager { const currentRooms = this.mainmanager.getAllFocusObject("room"); currentRooms.forEach((room) => { + // Generate regular polygon for area() + if (room.polys && room.poly == null) room.poly = room.polys.flat(1); + const polygon = new this.map.kp.Polygon( room.poly.map(([x, y]) => this.map.kp.vec2(x, y)) ); + const polygonBbox = polygon.bbox(); + const polygonCenter = polygonBbox.center(); + + polygon.pts = polygon.pts.map((point) => point.sub(polygonCenter)); + + let roomFocused = this.mainmanager.getCurrentFocus("room") == room.id; + + let curStyle = this.__getTopStyle(room.styles, roomFocused); + const obj = this.map.kp.make([ - this.map.kp.polygon(polygon.pts), - this.map.kp.color(this.map.kp.Color.fromHex(this.opts.bgColor)), - this.map.kp.opacity(this.opts.roomOpacity), + this.map.kp.polygon(polygon.pts, { + triangulate: true, + }), + this.map.kp.opacity(0), this.map.kp.area(), - this.map.kp.pos(), - this.map.kp.z(6), + this.map.kp.pos(polygonCenter), + this.map.kp.z(room.empty ? 5 : 6), { clickForgiveness: 5, startClickPosition: null, @@ -141,8 +252,40 @@ export class GameObjManager { this.roomObjects.set(room.id, obj); - obj.onUpdate(() => { - const roomFocused = this.mainmanager.getCurrentFocus("room") == room.id; + let polysgon; + if (room.polys) + polysgon = room.polys.map( + (poly) => + new this.map.kp.Polygon( + poly.map(([x, y]) => this.map.kp.vec2(x, y).sub(polygonCenter)) + ) + ); + + let labelPos = this.map.kp.vec2(0); + let labelWidth = polygonBbox.width; + if (room.label?.pos) + labelPos = this.map.kp.vec2(room.label.pos).sub(polygonCenter); + if (room.label?.width) labelWidth = room.label.width; + + obj.onDraw(() => { + // Check if room is within bounds + const camScale = 1 / this.map.kp.camScale().y; + const camBounds = this.map.kp.vec2( + this.map.kp.width() * camScale, + this.map.kp.height() * camScale + ); + const camPos = this.map.kp.camPos().sub(camBounds.scale(0.5)); + + const rect = new this.map.kp.Rect(camPos, camBounds.x, camBounds.y); + + if (!rect.collides(polygonBbox)) return; + + const curRoomFocused = + this.mainmanager.getCurrentFocus("room") == room.id; + if (curRoomFocused != roomFocused) { + curStyle = this.__getTopStyle(room.styles, curRoomFocused); + roomFocused = curRoomFocused; + } if (roomFocused) { obj.z = 7; @@ -150,78 +293,145 @@ export class GameObjManager { obj.z = 6; } - if (obj.isHovering()) { - if (roomFocused) - obj.color = this.map.kp.Color.fromHex(this.opts.bgFocusHoverColor); - else obj.color = this.map.kp.Color.fromHex(this.opts.bgHoverColor); + if (polysgon) { + polysgon.forEach((poly) => { + this.map.kp.drawPolygon({ + pts: poly.pts, + pos: this.map.kp.vec2(0), + triangulate: true, + color: this.map.kp.Color.fromHex(curStyle.backgroundColor), + opacity: curStyle.backgroundOpacity, + }); + }); } else { - if (roomFocused) - obj.color = this.map.kp.Color.fromHex(this.opts.bgFocusColor); - else obj.color = this.map.kp.Color.fromHex(this.opts.bgColor); + this.map.kp.drawPolygon({ + pts: polygon.pts, + pos: this.map.kp.vec2(0), + triangulate: true, + color: this.map.kp.Color.fromHex(curStyle.backgroundColor), + opacity: curStyle.backgroundOpacity, + }); } - if (this.map.kp.isMousePressed() && obj.isHovering()) { - obj.startClickPosition = this.map.kp.mousePos(); - } + if (!room.empty) { + let opacity = 0; - if (this.map.kp.isMouseDown() && obj.isHovering()) { - if (roomFocused) - obj.color = this.map.kp.Color.fromHex(this.opts.bgFocusClickColor); - else obj.color = this.map.kp.Color.fromHex(this.opts.bgClickColor); - } - - if (this.map.kp.isMouseReleased() && obj.isHovering()) { - const endClickPosition = this.map.kp.mousePos(); - if ( - obj.startClickPosition && - obj.startClickPosition.dist(endClickPosition) < obj.clickForgiveness - ) { - window.location.hash = room.id; + if (obj.isHovering()) { + opacity = 0.25; } - if (roomFocused) - obj.color = this.map.kp.Color.fromHex(this.opts.bgFocusHoverColor); - this.map.clearMouseMode(); - } - }); - obj.onDraw(() => { - const camScale = 1 / this.map.kp.camScale().y; - const roomFocused = this.mainmanager.getCurrentFocus("room") == room.id; + if (this.map.kp.isMousePressed() && obj.isHovering()) { + obj.startClickPosition = this.map.kp.mousePos(); + } + + if (this.map.kp.isMouseDown() && obj.isHovering()) { + opacity = 0.5; + } + + if (this.map.kp.isMouseReleased() && obj.isHovering()) { + const endClickPosition = this.map.kp.mousePos(); + if ( + obj.startClickPosition && + obj.startClickPosition.dist(endClickPosition) < + obj.clickForgiveness + ) { + window.location.hash = room.id; + } + this.map.clearMouseMode(); + } + + if (polysgon) { + polysgon.forEach((poly) => { + this.map.kp.drawPolygon({ + pts: poly.pts, + pos: this.map.kp.vec2(0), + triangulate: true, + color: this.map.kp.Color.fromHex(curStyle.actionColor), + opacity, + }); + }); + } else { + this.map.kp.drawPolygon({ + pts: polygon.pts, + pos: this.map.kp.vec2(0), + triangulate: true, + color: this.map.kp.Color.fromHex(curStyle.actionColor), + opacity, + }); + } + } this.map.kp.drawPolygon({ pts: polygon.pts, pos: this.map.kp.vec2(0), fill: false, + triangulate: true, outline: { - color: this.map.kp.Color.fromHex( - roomFocused ? this.opts.borderFocusColor : this.opts.borderColor - ), - width: 8 * camScale, + color: this.map.kp.Color.fromHex(curStyle.borderColor), + opacity: curStyle.borderOpacity, + width: curStyle.borderWidth * camScale, }, }); - if ( - this.opts.maxFontWidth * camScale * room.name.length > - polygon.bbox().width - ) - this.map.kp.drawText({ - text: room.shortName + "…", - size: this.opts.fontSize * camScale, - pos: polygon.bbox().center(), - color: this.map.kp.Color.fromHex(this.opts.textColor), - align: "center", - anchor: "center", - }); - else - this.map.kp.drawText({ - text: room.name, - width: polygon.bbox().width, - size: this.opts.fontSize * camScale, - pos: polygon.bbox().center(), - color: this.map.kp.Color.fromHex(this.opts.textColor), - align: "center", - anchor: "center", - }); + // Easy optimization: Don't draw empty room names + if (room.name != "") { + if ( + room.shortName != "" && + curStyle.fontWidth * camScale * room.name.length > labelWidth + ) { + if ( + curStyle.shortNameCollapse && + curStyle.fontWidth * camScale * room.shortName.length > labelWidth + ) + return; + + let text = room.shortName + (curStyle.textCut ?? "…"); + if (curStyle.textTransform == "uppercase") { + text = text.toUpperCase(); + } else if (curStyle.textTransform == "lowercase") { + text = text.toLowerCase(); + } + + this.map.kp.drawText({ + text, + size: curStyle.shortNameMinScale + ? Math.min(curStyle.fontSize, curStyle.fontSize * camScale) + : curStyle.fontSize * camScale, + font: curStyle.font, + pos: labelPos, + color: this.map.kp.Color.fromHex(curStyle.textColor), + opacity: curStyle.textOpacity, + align: "center", + anchor: "center", + }); + } else { + if ( + curStyle.shortNameCollapse && + curStyle.fontWidth * camScale * room.name.length > labelWidth + ) + return; + + let text = room.name; + if (curStyle.textTransform == "uppercase") { + text = text.toUpperCase(); + } else if (curStyle.textTransform == "lowercase") { + text = text.toLowerCase(); + } + + this.map.kp.drawText({ + text, + size: curStyle.shortNameMinScale + ? Math.min(labelWidth, curStyle.fontSize * camScale) + : curStyle.fontSize * camScale, + font: curStyle.font, + pos: labelPos, + color: this.map.kp.Color.fromHex(curStyle.textColor), + opacity: curStyle.textOpacity, + align: "center", + anchor: "center", + }); + } + } }); this.floorObject.add(obj); diff --git a/assets/scripts/KaplayMap/localization.js b/assets/scripts/KaplayMap/localization.js index fdff0ea..4797d1c 100644 --- a/assets/scripts/KaplayMap/localization.js +++ b/assets/scripts/KaplayMap/localization.js @@ -48,7 +48,8 @@ See https://git.gay/MeowcaTheoRange/EventMapper for more info Thanks to: - Joe 2DCon @ https://2dcon.gg/ - KikiCraft @ https://kikicraft.com/ -- Captain Zach @ https://discord.gg/2dcon`, +- Captain Zach @ https://discord.gg/2dcon +- Jason @ https://discord.gg/2dcon`, search_dialog_close_button: "Close search", search_dialog_header_title: "Search Events", search_dialog_search_bar: "Type search query here...", diff --git a/assets/scripts/modules/kaplay.js b/assets/scripts/modules/kaplay.js index e0c91bf..7cda1b9 100644 --- a/assets/scripts/modules/kaplay.js +++ b/assets/scripts/modules/kaplay.js @@ -1,3392 +1,3542 @@ -var kaplay = (() => { - var sn = Object.defineProperty; - var mi = Object.getOwnPropertyDescriptor; - var di = Object.getOwnPropertyNames; - var hi = Object.prototype.hasOwnProperty; - var i = (t, e) => sn(t, "name", { value: e, configurable: !0 }); - var pi = (t, e) => { - for (var r in e) sn(t, r, { get: e[r], enumerable: !0 }); - }, - fi = (t, e, r, s) => { - if ((e && typeof e == "object") || typeof e == "function") - for (let a of di(e)) - !hi.call(t, a) && - a !== r && - sn(t, a, { - get: () => e[a], - enumerable: !(s = mi(e, a)) || s.enumerable, - }); - return t; - }; - var gi = (t) => fi(sn({}, "__esModule", { value: !0 }), t); - var Br = (() => { - 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 (r) => { - for ( - var s = r.length, - a = new Uint8Array( - (((s - (r[s - 1] == "=") - (r[s - 2] == "=")) * 3) / 4) | 0 - ), - l = 0, - u = 0; - l < s; +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[r.charCodeAt(l++)], - y = t[r.charCodeAt(l++)], - m = t[r.charCodeAt(l++)], - V = t[r.charCodeAt(l++)]; - (a[u++] = (f << 2) | (y >> 4)), - (a[u++] = (y << 4) | (m >> 2)), - (a[u++] = (m << 6) | V); - } - return a; - }; - })(); - var aa = {}; - pi(aa, { - anchorPt: () => ht, - default: () => ia, - getInternalContext: () => fe, - getKaboomContext: () => J, - isKaboomCtx: () => as, - }); - function ve(t) { - return (t * Math.PI) / 180; + ) { + 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"); } - i(ve, "deg2rad"); - function lt(t) { - return (t * 180) / Math.PI; + x = 0; + y = 0; + constructor(e = 0, n = e) { + (this.x = e), (this.y = n); } - i(lt, "rad2deg"); - function Qe(t, e, r) { - return e > r ? Qe(t, r, e) : Math.min(Math.max(t, e), r); + static fromAngle(e) { + let n = be(e); + return new t(Math.cos(n), Math.sin(n)); } - i(Qe, "clamp"); - function Je(t, e, r) { - if (typeof t == "number" && typeof e == "number") return t + (e - t) * r; - if (t instanceof T && e instanceof T) return t.lerp(e, r); - if (t instanceof ee && e instanceof ee) return t.lerp(e, r); - throw new Error( - `Bad value for lerp(): ${t}, ${e}. Only number, Vec2 and Color is supported.` + 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 ); } - i(Je, "lerp"); - function dt(t, e, r, s, a) { - return s + ((t - e) / (r - e)) * (a - s); + lerp(e, n) { + return new t(Je(this.r, e.r, n), Je(this.g, e.g, n), Je(this.b, e.b, n)); } - i(dt, "map"); - function Ir(t, e, r, s, a) { - return Qe(dt(t, e, r, s, a), s, a); + 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]; } - i(Ir, "mapc"); - var T = class t { + 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 { - i(this, "Vec2"); + s(this, "Quad"); } x = 0; y = 0; - constructor(e = 0, r = e) { - (this.x = e), (this.y = r); + w = 1; + h = 1; + constructor(e, n, o, a) { + (this.x = e), (this.y = n), (this.w = o), (this.h = a); } - static fromAngle(e) { - let r = ve(e); - return new t(Math.cos(r), Math.sin(r)); - } - 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 r = C(...e); - return new t(this.x + r.x, this.y + r.y); - } - sub(...e) { - let r = C(...e); - return new t(this.x - r.x, this.y - r.y); - } - scale(...e) { - let r = C(...e); - return new t(this.x * r.x, this.y * r.y); - } - dist(...e) { - let r = C(...e); - return this.sub(r).len(); - } - sdist(...e) { - let r = C(...e); - return this.sub(r).slen(); - } - len() { - return Math.sqrt(this.dot(this)); - } - slen() { - return this.dot(this); - } - unit() { - let e = this.len(); - return e === 0 ? new 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 r = C(...e); - return lt(Math.atan2(this.y - r.y, this.x - r.x)); - } - angleBetween(...e) { - let r = C(...e); - return lt(Math.atan2(this.cross(r), this.dot(r))); - } - lerp(e, r) { - return new t(Je(this.x, e.x, r), Je(this.y, e.y, r)); - } - slerp(e, r) { - let s = this.dot(e), - a = this.cross(e), - l = Math.atan2(a, s); - return this.scale(Math.sin((1 - r) * l)) - .add(e.scale(Math.sin(r * l))) - .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 ue(this, 0, 0); - } - toString() { - return `vec2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`; - } - }; - function C(...t) { - if (t.length === 1) { - if (t[0] instanceof T) return new T(t[0].x, t[0].y); - if (Array.isArray(t[0]) && t[0].length === 2) return new T(...t[0]); - } - return new T(...t); - } - i(C, "vec2"); - var ee = class t { - static { - i(this, "Color"); - } - r = 255; - g = 255; - b = 255; - constructor(e, r, s) { - (this.r = Qe(e, 0, 255)), - (this.g = Qe(r, 0, 255)), - (this.b = Qe(s, 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 r = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e); - return new t( - parseInt(r[1], 16), - parseInt(r[2], 16), - parseInt(r[3], 16) - ); - } else throw new Error("Invalid hex color format"); - } - static fromHSL(e, r, s) { - if (r == 0) return new t(255 * s, 255 * s, 255 * s); - let a = i( - (V, x, P) => ( - P < 0 && (P += 1), - P > 1 && (P -= 1), - P < 1 / 6 - ? V + (x - V) * 6 * P - : P < 1 / 2 - ? x - : P < 2 / 3 - ? V + (x - V) * (2 / 3 - P) * 6 - : V - ), - "hue2rgb" - ), - l = s < 0.5 ? s * (1 + r) : s + r - s * r, - u = 2 * s - l, - f = a(u, l, e + 1 / 3), - y = a(u, l, e), - m = a(u, l, e - 1 / 3); + scale(e) { return new t( - Math.round(f * 255), - Math.round(y * 255), - Math.round(m * 255) + this.x + this.w * e.x, + this.y + this.h * e.y, + this.w * e.w, + this.h * e.h ); } - 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); + pos() { + return new D(this.x, this.y); + } 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, r) { - return new t(Je(this.r, e.r, r), Je(this.g, e.g, r), Je(this.b, e.b, r)); - } - toHSL() { - let e = this.r / 255, - r = this.g / 255, - s = this.b / 255, - a = Math.max(e, r, s), - l = Math.min(e, r, s), - u = (a + l) / 2, - f = u, - y = u; - if (a == l) u = f = 0; - else { - let m = a - l; - switch (((f = y > 0.5 ? m / (2 - a - l) : m / (a + l)), a)) { - case e: - u = (r - s) / m + (r < s ? 6 : 0); - break; - case r: - u = (s - e) / m + 2; - break; - case s: - u = (e - r) / m + 4; - break; - } - u /= 6; - } - return [u, f, y]; + return new t(this.x, this.y, this.w, this.h); } 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) + this.x === e.x && this.y === e.y && this.w === e.w && this.h === e.h ); } - toArray() { - return [this.r, this.g, this.b]; + toString() { + return `quad(${this.x}, ${this.y}, ${this.w}, ${this.h})`; } }; - function oe(...t) { - if (t.length === 0) return new ee(255, 255, 255); - if (t.length === 1) { - if (t[0] instanceof ee) return t[0].clone(); - if (typeof t[0] == "string") return ee.fromHex(t[0]); - if (Array.isArray(t[0]) && t[0].length === 3) return ee.fromArray(t[0]); - } - return new ee(...t); +function ge(t, e, n, o) { + return new he(t, e, n, o); +} +s(ge, "quad"); +var Vt = class t { + static { + s(this, "Mat2"); } - i(oe, "rgb"); - var Lr = i((t, e, r) => ee.fromHSL(t, e, r), "hsl2rgb"), - me = class t { - static { - i(this, "Quad"); - } - x = 0; - y = 0; - w = 1; - h = 1; - constructor(e, r, s, a) { - (this.x = e), (this.y = r), (this.w = s), (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 T(this.x, this.y); - } - clone() { - return new t(this.x, this.y, this.w, this.h); - } - eq(e) { - return ( - this.x === e.x && this.y === e.y && this.w === e.w && this.h === e.h - ); - } - toString() { - return `quad(${this.x}, ${this.y}, ${this.w}, ${this.h})`; - } - }; - function pe(t, e, r, s) { - return new me(t, e, r, s); + a; + b; + c; + d; + constructor(e, n, o, a) { + (this.a = e), (this.b = n), (this.c = o), (this.d = a); } - i(pe, "quad"); - var Ot = class t { + 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 { - i(this, "Mat2"); + s(this, "Mat3"); } - a; - b; - c; - d; - constructor(e, r, s, a) { - (this.a = e), (this.b = r), (this.c = s), (this.d = a); + 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.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 + 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 ); } - transform(e) { - return C(this.a * e.x + this.b * e.y, this.c * e.x + this.d * e.y); + 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.d / e, -this.b / e, -this.c / e, this.a / e); + 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.a, this.c, this.b, this.d); + return new t( + this.m11, + this.m21, + this.m31, + this.m12, + this.m22, + this.m32, + this.m13, + this.m23, + this.m33 + ); } - get eigenvalues() { - let e = this.trace / 2, - r = this.det, - s = e + Math.sqrt(e * e - r), - a = e - Math.sqrt(e * e - r); - return [s, a]; + }, + De = class t { + static { + s(this, "Mat4"); } - eigenvectors(e, r) { - return this.c != 0 - ? [ - [e - this.d, this.c], - [r - this.d, this.c], - ] - : this.b != 0 - ? [ - [this.b, e - this.a], - [this.b, r - this.a], - ] - : Math.abs(this.transform(C(1, 0)).x - e) < Number.EPSILON - ? [ - [1, 0], - [0, 1], - ] - : [ - [0, 1], - [1, 0], - ]; + m = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; + constructor(e) { + e && (this.m = e); } - get det() { - return this.a * this.d - this.b * this.c; + static translate(e) { + return new t([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, e.x, e.y, 0, 1]); } - get trace() { - return this.a + this.d; + 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 rotation(e) { - let r = Math.cos(e), - s = Math.sin(e); - return new t(r, s, -s, r); + 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 scale(e, r) { - return new t(e, 0, 0, r); + 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(); } }; - var bt = class t { - static { - i(this, "Mat3"); - } - m11; - m12; - m13; - m21; - m22; - m23; - m31; - m32; - m33; - constructor(e, r, s, a, l, u, f, y, m) { - (this.m11 = e), - (this.m12 = r), - (this.m13 = s), - (this.m21 = a), - (this.m22 = l), - (this.m23 = u), - (this.m31 = f), - (this.m32 = y), - (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 Ot(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 r = Math.cos(e), - s = Math.sin(e), - a = this.m11, - l = this.m12; - return ( - (this.m11 = r * this.m11 + s * this.m21), - (this.m12 = r * this.m12 + s * this.m22), - (this.m21 = r * this.m21 - s * a), - (this.m22 = r * this.m22 - s * l), - this - ); - } - scale(e, r) { - return ( - (this.m11 *= e), - (this.m12 *= e), - (this.m21 *= r), - (this.m22 *= r), - this - ); - } - get inverse() { - let e = this.det; - return new t( - (this.m22 * this.m33 - this.m23 * this.m32) / e, - (this.m13 * this.m32 - this.m12 * this.m33) / e, - (this.m12 * this.m23 - this.m13 * this.m22) / e, - (this.m23 * this.m31 - this.m21 * this.m33) / e, - (this.m11 * this.m33 - this.m13 * this.m31) / e, - (this.m13 * this.m21 - this.m11 * this.m23) / e, - (this.m21 * this.m32 - this.m22 * this.m31) / e, - (this.m12 * this.m31 - this.m11 * this.m32) / e, - (this.m11 * this.m22 - this.m12 * this.m21) / e - ); - } - get transpose() { - return new t( - this.m11, - this.m21, - this.m31, - this.m12, - this.m22, - this.m32, - this.m13, - this.m23, - this.m33 - ); - } - }, - Ge = class t { - static { - i(this, "Mat4"); - } - m = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; - constructor(e) { - e && (this.m = e); - } - static translate(e) { - return new t([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, e.x, e.y, 0, 1]); - } - static scale(e) { - return new t([e.x, 0, 0, 0, 0, e.y, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); - } - static rotateX(e) { - e = ve(-e); - let r = Math.cos(e), - s = Math.sin(e); - return new t([1, 0, 0, 0, 0, r, -s, 0, 0, s, r, 0, 0, 0, 0, 1]); - } - static rotateY(e) { - e = ve(-e); - let r = Math.cos(e), - s = Math.sin(e); - return new t([r, 0, s, 0, 0, 1, 0, 0, -s, 0, r, 0, 0, 0, 0, 1]); - } - static rotateZ(e) { - e = ve(-e); - let r = Math.cos(e), - s = Math.sin(e); - return new t([r, -s, 0, 0, s, r, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); - } - translate(e) { - return ( - (this.m[12] += this.m[0] * e.x + this.m[4] * e.y), - (this.m[13] += this.m[1] * e.x + this.m[5] * e.y), - (this.m[14] += this.m[2] * e.x + this.m[6] * e.y), - (this.m[15] += this.m[3] * e.x + this.m[7] * e.y), - this - ); - } - scale(e) { - return ( - (this.m[0] *= e.x), - (this.m[4] *= e.y), - (this.m[1] *= e.x), - (this.m[5] *= e.y), - (this.m[2] *= e.x), - (this.m[6] *= e.y), - (this.m[3] *= e.x), - (this.m[7] *= e.y), - this - ); - } - rotate(e) { - e = ve(-e); - let r = Math.cos(e), - s = Math.sin(e), - a = this.m[0], - l = this.m[1], - u = this.m[4], - f = this.m[5]; - return ( - (this.m[0] = a * r + l * s), - (this.m[1] = -a * s + l * r), - (this.m[4] = u * r + f * s), - (this.m[5] = -u * s + f * r), - this - ); - } - mult(e) { - let r = []; - for (let s = 0; s < 4; s++) - for (let a = 0; a < 4; a++) - r[s * 4 + a] = - this.m[0 * 4 + a] * e.m[s * 4 + 0] + - this.m[1 * 4 + a] * e.m[s * 4 + 1] + - this.m[2 * 4 + a] * e.m[s * 4 + 2] + - this.m[3 * 4 + a] * e.m[s * 4 + 3]; - return new t(r); - } - multVec2(e) { - return new T( - 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 T(this.m[12], this.m[13]); - } - getScale() { - if (this.m[0] != 0 || this.m[1] != 0) { - let e = this.m[0] * this.m[5] - this.m[1] * this.m[4], - r = Math.sqrt(this.m[0] * this.m[0] + this.m[1] * this.m[1]); - return new T(r, e / r); - } else if (this.m[4] != 0 || this.m[5] != 0) { - let e = this.m[0] * this.m[5] - this.m[1] * this.m[4], - r = Math.sqrt(this.m[4] * this.m[4] + this.m[5] * this.m[5]); - return new T(e / r, r); - } else return new T(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 T( - 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 T( - 0, - Math.atan(this.m[0] * this.m[4] + this.m[1] * this.m[5]) / (e * e) - ); - } else return new T(0, 0); - } - invert() { - let e = [], - r = this.m[10] * this.m[15] - this.m[14] * this.m[11], - s = 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], - l = this.m[8] * this.m[15] - this.m[12] * this.m[11], - u = 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], - y = 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], - V = this.m[5] * this.m[14] - this.m[13] * this.m[6], - x = this.m[4] * this.m[15] - this.m[12] * this.m[7], - P = 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], - K = this.m[4] * this.m[13] - this.m[12] * this.m[5], - X = this.m[6] * this.m[11] - this.m[10] * this.m[7], - z = this.m[5] * this.m[11] - this.m[9] * this.m[7], - N = this.m[5] * this.m[10] - this.m[9] * this.m[6], - $ = 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], - se = this.m[4] * this.m[9] - this.m[8] * this.m[5]; - (e[0] = this.m[5] * r - this.m[6] * s + this.m[7] * a), - (e[4] = -(this.m[4] * r - this.m[6] * l + this.m[7] * u)), - (e[8] = this.m[4] * s - this.m[5] * l + this.m[7] * f), - (e[12] = -(this.m[4] * a - this.m[5] * u + this.m[6] * f)), - (e[1] = -(this.m[1] * r - this.m[2] * s + this.m[3] * a)), - (e[5] = this.m[0] * r - this.m[2] * l + this.m[3] * u), - (e[9] = -(this.m[0] * s - this.m[1] * l + this.m[3] * f)), - (e[13] = this.m[0] * a - this.m[1] * u + this.m[2] * f), - (e[2] = this.m[1] * y - this.m[2] * m + this.m[3] * V), - (e[6] = -(this.m[0] * y - this.m[2] * x + this.m[3] * P)), - (e[10] = this.m[0] * w - this.m[1] * x + this.m[3] * K), - (e[14] = -(this.m[0] * V - this.m[1] * P + this.m[2] * K)), - (e[3] = -(this.m[1] * X - this.m[2] * z + this.m[3] * N)), - (e[7] = this.m[0] * X - this.m[2] * $ + this.m[3] * O), - (e[11] = -(this.m[0] * z - this.m[1] * $ + this.m[3] * se)), - (e[15] = this.m[0] * N - this.m[1] * O + this.m[2] * se); - let _ = - this.m[0] * e[0] + - this.m[1] * e[4] + - this.m[2] * e[8] + - this.m[3] * e[12]; - for (let ae = 0; ae < 4; ae++) - for (let re = 0; re < 4; re++) e[ae * 4 + re] *= 1 / _; - return new t(e); - } - clone() { - return new t([...this.m]); - } - toString() { - return this.m.toString(); - } - }; - function Yn(t, e, r, s = (a) => -Math.cos(a)) { - return t + ((s(r) + 1) / 2) * (e - t); - } - i(Yn, "wave"); - var bi = 1103515245, - vi = 12345, - Fr = 2147483648, - It = class { - static { - i(this, "RNG"); - } - seed; - constructor(e) { - this.seed = e; - } - gen() { - return (this.seed = (bi * this.seed + vi) % Fr), this.seed / Fr; - } - genNumber(e, r) { - return e + this.gen() * (r - e); - } - genVec2(e, r) { - return new T(this.genNumber(e.x, r.x), this.genNumber(e.y, r.y)); - } - genColor(e, r) { - return new ee( - this.genNumber(e.r, r.r), - this.genNumber(e.g, r.g), - this.genNumber(e.b, r.b) - ); - } - genAny(...e) { - if (e.length === 0) return this.gen(); - if (e.length === 1) { - if (typeof e[0] == "number") return this.genNumber(0, e[0]); - if (e[0] instanceof T) return this.genVec2(C(0, 0), e[0]); - if (e[0] instanceof ee) return this.genColor(oe(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 T && e[1] instanceof T) - return this.genVec2(e[0], e[1]); - if (e[0] instanceof ee && e[1] instanceof ee) - return this.genColor(e[0], e[1]); - } - } - }, - zn = new It(Date.now()); - function jr(t) { - return t != null && (zn.seed = t), zn.seed; - } - i(jr, "randSeed"); - function Lt(...t) { - return zn.genAny(...t); - } - i(Lt, "rand"); - function Xn(...t) { - return Math.floor(Lt(...t)); - } - i(Xn, "randi"); - function kr(t) { - return Lt() <= t; - } - i(kr, "chance"); - function Wn(t) { - for (let e = t.length - 1; e > 0; e--) { - let r = Math.floor(Math.random() * (e + 1)); - [t[e], t[r]] = [t[r], t[e]]; +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"); } - return t; + 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]]; } - i(Wn, "shuffle"); - function Nr(t, e) { - return t.length <= e ? t.slice() : Wn(t.slice()).slice(0, 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))); } - i(Nr, "chooseMultiple"); - function _r(t) { - return t[Xn(t.length)]; + 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))); } - i(_r, "choose"); - function $n(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 - ); + 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; } - i($n, "testRectRect"); - function xi(t, e) { + 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 ( - (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 r = - (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 (r === 0) return null; - let s = - ((e.p2.x - e.p1.x) * (t.p1.y - e.p1.y) - - (e.p2.y - e.p1.y) * (t.p1.x - e.p1.x)) / - r, - 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)) / - r; - return s < 0 || s > 1 || a < 0 || a > 1 ? null : s; - } - i(xi, "testLineLineT"); - function cn(t, e) { - let r = xi(t, e); - return r - ? C(t.p1.x + r * (t.p2.x - t.p1.x), t.p1.y + r * (t.p2.y - t.p1.y)) - : null; - } - i(cn, "testLineLine"); - function un(t, e) { - let r = e.p2.sub(e.p1), - s = Number.NEGATIVE_INFINITY, - a = Number.POSITIVE_INFINITY; - if (r.x != 0) { - let l = (t.pos.x - e.p1.x) / r.x, - u = (t.pos.x + t.width - e.p1.x) / r.x; - (s = Math.max(s, Math.min(l, u))), (a = Math.min(a, Math.max(l, u))); - } - if (r.y != 0) { - let l = (t.pos.y - e.p1.y) / r.y, - u = (t.pos.y + t.height - e.p1.y) / r.y; - (s = Math.max(s, Math.min(l, u))), (a = Math.min(a, Math.max(l, u))); - } - return a >= s && a >= 0 && s <= 1; - } - i(un, "testRectLine"); - function Qn(t, e) { - return ( - e.x > t.pos.x && - e.x < t.pos.x + t.width && - e.y > t.pos.y && - e.y < t.pos.y + t.height - ); - } - i(Qn, "testRectPoint"); - function Hr(t, e) { - let r = Math.max(t.pos.x, Math.min(e.center.x, t.pos.x + t.width)), - s = Math.max(t.pos.y, Math.min(e.center.y, t.pos.y + t.height)); - return C(r, s).sdist(e.center) <= e.radius * e.radius; - } - i(Hr, "testRectCircle"); - function Kr(t, e) { - return qr(e, new Oe(t.points())); - } - i(Kr, "testRectPolygon"); - function Jn(t, e) { - let r = e.sub(t.p1), - s = t.p2.sub(t.p1); - if (Math.abs(r.cross(s)) > Number.EPSILON) return !1; - let a = r.dot(s) / s.dot(s); - return a >= 0 && a <= 1; - } - i(Jn, "testLinePoint"); - function Rt(t, e) { - let r = t.p2.sub(t.p1), - s = r.dot(r), - a = t.p1.sub(e.center), - l = 2 * r.dot(a), - u = a.dot(a) - e.radius * e.radius, - f = l * l - 4 * s * u; - if (s <= Number.EPSILON || f < 0) return !1; - if (f == 0) { - let y = -l / (2 * s); - if (y >= 0 && y <= 1) return !0; - } else { - let y = (-l + Math.sqrt(f)) / (2 * s), - m = (-l - Math.sqrt(f)) / (2 * s); - if ((y >= 0 && y <= 1) || (m >= 0 && m <= 1)) return !0; - } - return er(e, t.p1); - } - i(Rt, "testLineCircle"); - function Zn(t, e) { - if (mt(e, t.p1) || mt(e, t.p2)) return !0; - for (let r = 0; r < e.pts.length; r++) { - let s = e.pts[r], - a = e.pts[(r + 1) % e.pts.length]; - if (cn(t, new Be(s, a))) return !0; - } - return !1; - } - i(Zn, "testLinePolygon"); - function er(t, e) { - return t.center.sdist(e) < t.radius * t.radius; - } - i(er, "testCirclePoint"); - function yi(t, e) { - return ( - t.center.sdist(e.center) < (t.radius + e.radius) * (t.radius + e.radius) - ); - } - i(yi, "testCircleCircle"); - function jt(t, e) { - let r = e.pts[e.pts.length - 1]; - for (let s of e.pts) { - if (Rt(new Be(r, s), t)) return !0; - r = s; - } - return er(t, e.pts[0]) ? !0 : mt(e, t.center); - } - i(jt, "testCirclePolygon"); - function qr(t, e) { - for (let r = 0; r < t.pts.length; r++) - if (Zn(new Be(t.pts[r], t.pts[(r + 1) % t.pts.length]), e)) return !0; - return !!(t.pts.some((r) => mt(e, r)) || e.pts.some((r) => mt(t, r))); - } - i(qr, "testPolygonPolygon"); - function mt(t, e) { - let r = !1, - s = t.pts; - for (let a = 0, l = s.length - 1; a < s.length; l = a++) - s[a].y > e.y != s[l].y > e.y && - e.x < - ((s[l].x - s[a].x) * (e.y - s[a].y)) / (s[l].y - s[a].y) + s[a].x && - (r = !r); - return r; - } - i(mt, "testPolygonPoint"); - function zr(t, e) { - e = e.sub(t.center); - let r = ve(t.angle), - s = Math.cos(r), - a = Math.sin(r), - l = e.x * s + e.y * a, - u = -e.x * a + e.y * s; - return ( - (l * l) / (t.radiusX * t.radiusX) + (u * u) / (t.radiusY * t.radiusY) < 1 - ); - } - i(zr, "testEllipsePoint"); - function an(t, e) { - let r = e.center.sub(t.center), - s = ve(t.angle), - a = Math.cos(s), - l = Math.sin(s), - u = r.x * a + r.y * l, - f = -r.x * l + r.y * a; - return zr( - new We(C(), t.radiusX + e.radius, t.radiusY + e.radius, 0), - C(u, f) - ); - } - i(an, "testEllipseCircle"); - function Yr(t, e) { - let r = t.toMat2().inverse; - return ( - (e = new Be( - r.transform(e.p1.sub(t.center)), - r.transform(e.p2.sub(t.center)) - )), - Rt(e, new Fe(C(), 1)) - ); - } - i(Yr, "testEllipseLine"); - function wi(t, e) { - if (t.radiusX === t.radiusY) return an(e, new Fe(t.center, t.radiusX)); - if (e.radiusX === e.radiusY) return an(t, new Fe(e.center, e.radiusX)); - let r = new bt( - 1 / t.radiusX ** 2, - 0, - 0, - 0, - 1 / t.radiusY ** 2, - 0, - 0, - 0, - -1 - ), - s = new bt(1 / e.radiusX ** 2, 0, 0, 0, 1 / e.radiusY ** 2, 0, 0, 0, -1), - a = t.center.x, - l = t.center.y, - u = e.center.x, - f = e.center.y, - y = ve(t.angle), - m = ve(e.angle), - V = new bt( - Math.cos(y), - -Math.sin(y), - a, - Math.sin(y), - Math.cos(y), - l, - 0, - 0, - 1 - ), - x = new bt( - Math.cos(m), - -Math.sin(m), - u, - Math.sin(m), - Math.cos(m), - f, - 0, - 0, - 1 - ), - P = V.inverse, - w = x.inverse, - K = P.transpose.mul(r).mul(P), - X = w.transpose.mul(s).mul(w), - z = K.m11, - N = K.m12, - $ = K.m13, - O = K.m21, - se = K.m22, - _ = K.m23, - ae = K.m31, - re = K.m32, - ce = K.m33, - ge = X.m11, - Ue = X.m12, - Ce = X.m13, - Le = X.m21, - je = X.m22, - Ee = X.m23, - Ne = X.m31, - _e = X.m32, - He = X.m33, - pt = - z * se * ce - - z * _ * re - - N * O * ce + - N * _ * ae + - $ * O * re - - $ * se * ae, - Se = - (z * se * He - - z * _ * _e - - z * re * Ee + - z * ce * je - - N * O * He + - N * _ * Ne + - N * ae * Ee - - N * ce * Le + - $ * O * _e - - $ * se * Ne - - $ * ae * je + - $ * re * Le + - O * re * Ce - - O * ce * Ue - - se * ae * Ce + - se * ce * ge + - _ * ae * Ue - - _ * re * ge) / - pt, - Ve = - (z * je * He - - z * Ee * _e - - N * Le * He + - N * Ee * Ne + - $ * Le * _e - - $ * je * Ne - - O * Ue * He + - O * Ce * _e + - se * ge * He - - se * Ce * Ne - - _ * ge * _e + - _ * Ue * Ne + - ae * Ue * Ee - - ae * Ce * je - - re * ge * Ee + - re * Ce * Le + - ce * ge * je - - ce * Ue * Le) / - pt, - ze = - (ge * je * He - - ge * Ee * _e - - Ue * Le * He + - Ue * Ee * Ne + - Ce * Le * _e - - Ce * je * Ne) / - pt; - if (Se >= 0) { - let rt = -3 * Ve + Se ** 2, - ot = 3 * Se * ze + Ve * Se ** 2 - 4 * Ve ** 2, - wt = - -27 * ze ** 2 + - 18 * ze * Se * Ve + - Se ** 2 * Ve ** 2 - - 4 * Se ** 3 * ze - - 4 * Ve ** 3; - return !(rt > 0 && ot < 0 && wt > 0); - } else { - let rt = -3 * Ve + Se ** 2, - ot = - -27 * ze ** 2 + - 18 * ze * Se * Ve + - Se ** 2 * Ve ** 2 - - 4 * Se ** 3 * ze - - 4 * Ve ** 3; - return !(rt > 0 && ot > 0); + (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 }; } } - i(wi, "testEllipseEllipse"); - function Xr(t, e) { - return tr(t, new Oe(e.points())); + 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); } - i(Xr, "testEllipseRect"); - function tr(t, e) { - let r = t.toMat2().inverse; - return ( - (e = new Oe(e.pts.map((s) => r.transform(s.sub(t.center))))), - jt(new Fe(C(), 1), e) - ); - } - i(tr, "testEllipsePolygon"); - function Ci(t, e) { - return e instanceof T - ? Jn(t, e) - : e instanceof Fe - ? Rt(t, e) - : e instanceof Be - ? cn(t, e) != null - : e instanceof ue - ? un(e, t) - : e instanceof Oe - ? Zn(t, e) - : e instanceof We - ? Yr(e, t) - : !1; - } - i(Ci, "testLineShape"); - function Ti(t, e) { - return e instanceof T - ? er(t, e) - : e instanceof Fe - ? yi(t, e) - : e instanceof Be - ? Rt(e, t) - : e instanceof ue - ? Hr(e, t) - : e instanceof Oe - ? jt(t, e) - : e instanceof We - ? an(e, t) - : !1; - } - i(Ti, "testCircleShape"); - function Ei(t, e) { - return e instanceof T - ? Qn(t, e) - : e instanceof Fe - ? Hr(t, e) - : e instanceof Be - ? un(t, e) - : e instanceof ue - ? $n(t, e) - : e instanceof Oe - ? Kr(t, e) - : e instanceof We - ? Xr(e, t) - : !1; - } - i(Ei, "testRectShape"); - function Si(t, e) { - return e instanceof T - ? mt(t, e) - : e instanceof Fe - ? jt(e, t) - : e instanceof Be - ? Zn(e, t) - : e instanceof ue - ? Kr(e, t) - : e instanceof Oe - ? qr(e, t) - : e instanceof We - ? tr(e, t) - : !1; - } - i(Si, "testPolygonShape"); - function Ai(t, e) { - return e instanceof T - ? zr(t, e) - : e instanceof Fe - ? an(t, e) - : e instanceof Be - ? Yr(t, e) - : e instanceof ue - ? Xr(t, e) - : e instanceof Oe - ? tr(t, e) - : e instanceof We - ? wi(e, t) - : !1; - } - i(Ai, "testEllipseShape"); - function Wr(t, e, r) { - let s = t, - a = r.p1, - l = r.p2, - u = e, - f = l.sub(a), - y = u.cross(f); - if (Math.abs(y) < Number.EPSILON) return null; - let m = a.sub(s), - V = m.cross(f) / y; - if (V <= 0 || V >= 1) return null; - let x = m.cross(u) / y; - if (x <= 0 || x >= 1) return null; - let P = f.normal().unit(); - return ( - e.dot(P) > 0 && ((P.x *= -1), (P.y *= -1)), - { point: s.add(u.scale(V)), normal: P, fraction: V } - ); - } - i(Wr, "raycastLine"); - function Oi(t, e, r) { - let s = Number.NEGATIVE_INFINITY, - a = Number.POSITIVE_INFINITY, - l; - if (t.x != 0) { - let u = (r.pos.x - t.x) / e.x, - f = (r.pos.x + r.width - t.x) / e.x; - (l = C(-Math.sign(e.x), 0)), - (s = Math.max(s, Math.min(u, f))), - (a = Math.min(a, Math.max(u, f))); - } - if (t.y != 0) { - let u = (r.pos.y - t.y) / e.y, - f = (r.pos.y + r.height - t.y) / e.y; - Math.min(u, f) > s && (l = C(0, -Math.sign(e.y))), - (s = Math.max(s, Math.min(u, f))), - (a = Math.min(a, Math.max(u, f))); - } - return a >= s && s >= 0 && s <= 1 - ? { point: t.add(e.scale(s)), normal: l, fraction: s } - : null; - } - i(Oi, "raycastRect"); - function $r(t, e, r) { - let s = t, - a = r.center, - l = e, - u = l.dot(l), - f = s.sub(a), - y = 2 * l.dot(f), - m = f.dot(f) - r.radius * r.radius, - V = y * y - 4 * u * m; - if (u <= Number.EPSILON || V < 0) return null; - if (V == 0) { - let x = -y / (2 * u); - if (x >= 0 && x <= 1) { - let P = s.add(l.scale(x)); - return { point: P, normal: P.sub(a), fraction: x }; - } - } else { - let x = (-y + Math.sqrt(V)) / (2 * u), - P = (-y - Math.sqrt(V)) / (2 * u), - w = null; - if ( - (x >= 0 && x <= 1 && (w = x), - P >= 0 && P <= 1 && (w = Math.min(P, w ?? P)), - w != null) - ) { - let K = s.add(l.scale(w)); - return { point: K, normal: K.sub(a).unit(), fraction: w }; - } - } - return null; - } - i($r, "raycastCircle"); - function Ri(t, e, r) { - let s = r.pts, - a = null, - l = s[s.length - 1]; - for (let u = 0; u < s.length; u++) { - let f = s[u], - y = Wr(t, e, new Be(l, f)); - y && (!a || a.fraction > y.fraction) && (a = y), (l = f); - } - return a; - } - i(Ri, "raycastPolygon"); - function Ui(t, e, r) { - let s = r.toMat2(), - a = s.inverse, - l = a.transform(t.sub(r.center)), - u = a.transform(e), - f = $r(l, u, new Fe(C(), 1)); - if (f) { - let y = Ot.rotation(ve(-r.angle)), - V = Ot.scale(r.radiusX, r.radiusY).transform(f.point), - x = s.transform(f.point).add(r.center), - P = x.dist(t) / e.len(); - return { - point: x, - normal: y.transform(C(r.radiusY ** 2 * V.x, r.radiusX ** 2 * V.y)), - fraction: P, - }; - } - return f; - } - i(Ui, "raycastEllipse"); - function Qr(t, e, r, s = 64) { - let a = t, - l = e.len(), - u = e.scale(1 / l), - f = 0, - y = C(Math.floor(t.x), Math.floor(t.y)), - m = C(u.x > 0 ? 1 : -1, u.y > 0 ? 1 : -1), - V = C(Math.abs(1 / u.x), Math.abs(1 / u.y)), - x = C( - m.x > 0 ? y.x + 1 - t.x : t.x - y.x, - m.y > 0 ? y.y + 1 - t.y : t.y - y.y - ), - P = C(V.x < 1 / 0 ? V.x * x.x : 1 / 0, V.y < 1 / 0 ? V.y * x.y : 1 / 0), - w = -1; - for (; f <= s; ) { - let K = r(y); - if (K === !0) - return { - point: a.add(u.scale(f)), - normal: C(w === 0 ? -m.x : 0, w === 1 ? -m.y : 0), - fraction: f / l, - gridPos: y, - }; - if (K) return K; - P.x < P.y - ? ((y.x += m.x), (f = P.x), (P.x += V.x), (w = 0)) - : ((y.y += m.y), (f = P.y), (P.y += V.y), (w = 1)); - } - return null; - } - i(Qr, "raycastGrid"); - var Be = class t { - static { - i(this, "Line"); - } - p1; - p2; - constructor(e, r) { - (this.p1 = e.clone()), (this.p2 = r.clone()); - } - transform(e) { - return new t(e.multVec2(this.p1), e.multVec2(this.p2)); - } - bbox() { - return ue.fromPoints(this.p1, this.p2); - } - area() { - return this.p1.dist(this.p2); - } - clone() { - return new t(this.p1, this.p2); - } - collides(e) { - return Ci(this, e); - } - contains(e) { - return this.collides(e); - } - raycast(e, r) { - return Wr(e, r, this); - } - }, - ue = class t { - static { - i(this, "Rect"); - } - pos; - width; - height; - constructor(e, r, s) { - (this.pos = e.clone()), (this.width = r), (this.height = s); - } - static fromPoints(e, r) { - return new t(e.clone(), r.x - e.x, r.y - e.y); - } - center() { - return new T(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 Oe(this.points().map((r) => e.multVec2(r))); - } - 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 r = this.pos, - s = this.pos.add(this.width, this.height), - a = Math.max(r.x - e.x, 0, e.x - s.x), - l = Math.max(r.y - e.y, 0, e.y - s.y); - return a * a + l * l; - } - collides(e) { - return Ei(this, e); - } - contains(e) { - return this.collides(e); - } - raycast(e, r) { - return Oi(e, r, this); - } - }, - Fe = class t { - static { - i(this, "Circle"); - } - center; - radius; - constructor(e, r) { - (this.center = e.clone()), (this.radius = r); - } - transform(e) { - return new We(this.center, this.radius, this.radius).transform(e); - } - bbox() { - return ue.fromPoints( - this.center.sub(C(this.radius)), - this.center.add(C(this.radius)) - ); - } - area() { - return this.radius * this.radius * Math.PI; - } - clone() { - return new t(this.center, this.radius); - } - collides(e) { - return Ti(this, e); - } - contains(e) { - return this.collides(e); - } - raycast(e, r) { - return $r(e, r, this); - } - }, - We = class t { - static { - i(this, "Ellipse"); - } - center; - radiusX; - radiusY; - angle; - constructor(e, r, s, a = 0) { - (this.center = e.clone()), - (this.radiusX = r), - (this.radiusY = s), - (this.angle = a); - } - static fromMat2(e) { - let r = e.inverse, - s = r.transpose.mul(r), - [a, l] = s.eigenvalues, - [u, f] = s.eigenvectors(a, l), - [y, m] = [1 / Math.sqrt(a), 1 / Math.sqrt(l)]; - return y > m - ? new t(C(), y, m, lt(Math.atan2(-u[1], u[0]))) - : new t(C(), m, y, lt(Math.atan2(-f[1], f[0]))); - } - toMat2() { - let e = ve(this.angle), - r = Math.cos(e), - s = Math.sin(e); - return new Ot( - r * this.radiusX, - s * this.radiusY, - -s * this.radiusX, - r * 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 r = this.toMat2(), - s = e.getRotation(), - a = e.getScale(); - r = bt.fromMat2(r).scale(a.x, a.y).rotate(s).toMat2(); - let u = t.fromMat2(r); - return (u.center = e.multVec2(this.center)), u; - } - } - bbox() { - if (this.angle == 0) - return ue.fromPoints( - this.center.sub(C(this.radiusX, this.radiusY)), - this.center.add(C(this.radiusX, this.radiusY)) - ); - { - let e = ve(this.angle), - r = Math.cos(e), - s = Math.sin(e), - a = this.radiusX * r, - l = this.radiusX * s, - u = this.radiusY * s, - f = this.radiusY * r, - y = Math.sqrt(a * a + u * u), - m = Math.sqrt(l * l + f * f); - return ue.fromPoints( - this.center.sub(C(y, m)), - this.center.add(C(y, m)) - ); - } - } - area() { - return this.radiusX * this.radiusY * Math.PI; - } - clone() { - return new t(this.center, this.radiusX, this.radiusY, this.angle); - } - collides(e) { - return Ai(this, e); - } - contains(e) { - e = e.sub(this.center); - let r = ve(this.angle), - s = Math.cos(r), - a = Math.sin(r), - l = e.x * s + e.y * a, - u = -e.x * a + e.y * s; - return ( - (l * l) / (this.radiusX * this.radiusX) + - (u * u) / (this.radiusY * this.radiusY) < - 1 - ); - } - raycast(e, r) { - return Ui(e, r, this); - } - }, - Oe = class t { - static { - i(this, "Polygon"); - } - pts; - constructor(e) { - if (e.length < 3) - throw new Error("Polygons should have at least 3 vertices"); - this.pts = e; - } - transform(e) { - return new t(this.pts.map((r) => e.multVec2(r))); - } - bbox() { - let e = C(Number.MAX_VALUE), - r = C(-Number.MAX_VALUE); - for (let s of this.pts) - (e.x = Math.min(e.x, s.x)), - (r.x = Math.max(r.x, s.x)), - (e.y = Math.min(e.y, s.y)), - (r.y = Math.max(r.y, s.y)); - return ue.fromPoints(e, r); - } - area() { - let e = 0, - r = this.pts.length; - for (let s = 0; s < r; s++) { - let a = this.pts[s], - l = this.pts[(s + 1) % r]; - (e += a.x * l.y * 0.5), (e -= l.x * a.y * 0.5); - } - return Math.abs(e); - } - clone() { - return new t(this.pts.map((e) => e.clone())); - } - collides(e) { - return Si(this, e); - } - contains(e) { - return this.collides(e); - } - raycast(e, r) { - return Ri(e, r, this); - } + 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, }; - function nr(t, e, r, s, a) { - let l = a * a, - u = l * a, - f = 1 - a, - y = f * f, - m = y * f; - return t - .scale(m) - .add(e.scale(3 * y * a)) - .add(r.scale(3 * f * l)) - .add(s.scale(u)); } - i(nr, "evaluateBezier"); - function Jr(t, e) { - let r = Number.MAX_VALUE, - s = C(0); - for (let a of [t, e]) - for (let l = 0; l < a.pts.length; l++) { - let u = a.pts[l], - y = a.pts[(l + 1) % a.pts.length].sub(u).normal().unit(), - m = Number.MAX_VALUE, - V = -Number.MAX_VALUE; - for (let K = 0; K < t.pts.length; K++) { - let X = t.pts[K].dot(y); - (m = Math.min(m, X)), (V = Math.max(V, X)); - } - let x = Number.MAX_VALUE, - P = -Number.MAX_VALUE; - for (let K = 0; K < e.pts.length; K++) { - let X = e.pts[K].dot(y); - (x = Math.min(x, X)), (P = Math.max(P, X)); - } - let w = Math.min(V, P) - Math.max(m, x); - if (w < 0) return null; - if (w < Math.abs(r)) { - let K = P - m, - X = x - V; - (r = Math.abs(K) < Math.abs(X) ? K : X), (s = y.scale(r)); - } + 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; } - return s; - } - i(Jr, "sat"); - function Zr(t, e, r) { - return (e.x - t.x) * (r.y - t.y) - (e.y - t.y) * (r.x - t.x) >= 0; - } - i(Zr, "isOrientedCcw"); - function Vi(t) { - let e = 0, - r = t[t.length - 1]; - for (let s = 0; s < t.length; s++) - (e += (t[s].x - r.x) * (t[s].y + r.y)), (r = t[s]); - return e < 0; - } - i(Vi, "isOrientedCcwPolygon"); - function qn(t, e, r, s) { - let a = s.x - r.x, - l = s.y - r.y, - u = a * (t.y - r.y) - l * (t.x - r.x), - f = a * (e.y - r.y) - l * (e.x - r.x); - return u * f >= 0; - } - i(qn, "onSameSide"); - function Pi(t, e, r, s) { - return qn(t, e, r, s) && qn(t, r, e, s) && qn(t, s, e, r); - } - i(Pi, "pointInTriangle"); - function Di(t, e, r, s) { - for (let a of t) - if (a !== e && a !== r && a !== s && Pi(a, e, r, s)) return !0; - return !1; - } - i(Di, "someInTriangle"); - function Mi(t, e, r, s) { - return Zr(t, e, r) && !Di(s, t, e, r); - } - i(Mi, "isEar"); - function rr(t) { - if (t.length < 3) return []; - if (t.length == 3) return [t]; - let e = [], - r = [], - s = 0; - for (let x = 0; x < t.length; x++) { - let P = t[s], - w = t[x]; - (w.x < P.x || (w.x == P.x && w.y < P.y)) && (s = s), - (e[x] = x + 1), - (r[x] = x - 1); } - (e[e.length - 1] = 0), (r[0] = r.length - 1), Vi(t) || ([e, r] = [r, e]); - let a = []; - for (let x = 0; x < t.length; ++x) - Zr(t[r[x]], t[x], t[e[x]]) || a.push(t[x]); - let l = [], - u = t.length, - f = 1, - y = 0, - m, - V; - for (; u > 3; ) { - (m = e[f]), (V = r[f]); - let x = t[V], - P = t[f], - w = t[m]; - if (Mi(x, P, w, a)) - l.push([x, P, w]), - (e[V] = m), - (r[m] = V), - a.splice(a.indexOf(P), 1), - --u, - (y = 0); - else if (++y > u) return []; - f = m; + 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)) + ); + } } - return (m = e[f]), (V = r[f]), l.push([t[V], t[f], t[m]]), l; + 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); } - i(rr, "triangulate"); - function or(t) { - if (t.length < 3) return !1; - let e = t.length - 2, - r = t.length - 1, - s = 0, - a = t[r].sub(t[e]), - l = t[s].sub(t[r]), - u = a.cross(l); - for (; s + 1 < t.length; ) - if ( - ((e = r), - (r = s), - s++, - (a = t[r].sub(t[e])), - (l = t[s].sub(t[r])), - a.cross(l) * u < 0) - ) - return !1; + 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; } - i(or, "isConvex"); - var kt = class extends Map { - static { - i(this, "Registry"); - } - lastID = 0; - push(e) { - let r = this.lastID; - return this.set(r, e), this.lastID++, r; - } - pushd(e) { - let r = this.push(e); - return () => this.delete(r); - } - }, - et = class t { - static { - i(this, "EventController"); - } - paused = !1; - cancel; - constructor(e) { - this.cancel = e; - } - static join(e) { - let r = new t(() => e.forEach((s) => s.cancel())); - return ( - Object.defineProperty(r, "paused", { - get: () => e[0].paused, - set: (s) => e.forEach((a) => (a.paused = s)), - }), - (r.paused = !1), - r - ); - } - }, - we = class { - static { - i(this, "Event"); - } - handlers = new kt(); - add(e) { - let r = this.handlers.pushd((...a) => { - s.paused || e(...a); - }), - s = new et(r); - return s; - } - addOnce(e) { - let r = this.add((...s) => { - r.cancel(), e(...s); - }); - return r; - } - next() { - return new Promise((e) => this.addOnce(e)); - } - trigger(...e) { - this.handlers.forEach((r) => r(...e)); - } - numListeners() { - return this.handlers.size; - } - clear() { - this.handlers.clear(); - } - }, - tt = class { - static { - i(this, "EventHandler"); - } - handlers = {}; - on(e, r) { - return ( - this.handlers[e] || (this.handlers[e] = new we()), - this.handlers[e].add(r) - ); - } - onOnce(e, r) { - let s = this.on(e, (...a) => { - s.cancel(), r(...a); - }); - return s; - } - next(e) { - return new Promise((r) => { - this.onOnce(e, (...s) => r(s[0])); - }); - } - trigger(e, ...r) { - this.handlers[e] && this.handlers[e].trigger(...r); - } - remove(e) { - delete this.handlers[e]; - } - clear() { - this.handlers = {}; - } - numListeners(e) { - return this.handlers[e]?.numListeners() ?? 0; - } - }; - function mn(t, e) { - if (t === e) return !0; - let r = typeof t, - s = typeof e; - if (r !== s) return !1; - if (r === "object" && s === "object" && t !== null && e !== null) { - if (Array.isArray(t) !== Array.isArray(e)) return !1; - let a = Object.keys(t), - l = Object.keys(e); - if (a.length !== l.length) return !1; - for (let u of a) { - let f = t[u], - y = e[u]; - if (!mn(f, y)) return !1; - } - return !0; - } - return !1; + 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"); } - i(mn, "deepEq"); - function Gi(t) { - let e = window.atob(t), - r = e.length, - s = new Uint8Array(r); - for (let a = 0; a < r; a++) s[a] = e.charCodeAt(a); - return s.buffer; + _items; + _compareFn; + constructor(e = (n, o) => n < o) { + (this._compareFn = e), (this._items = []); } - i(Gi, "base64ToArrayBuffer"); - function to(t) { - return Gi(t.split(",")[1]); + insert(e) { + this._items.push(e), this.moveUp(this._items.length - 1); } - i(to, "dataURLToArrayBuffer"); - function dn(t, e) { - let r = document.createElement("a"); - (r.href = e), (r.download = t), r.click(); - } - i(dn, "download"); - function sr(t, e) { - dn(t, "data:text/plain;charset=utf-8," + e); - } - i(sr, "downloadText"); - function no(t, e) { - sr(t, JSON.stringify(e)); - } - i(no, "downloadJSON"); - function ir(t, e) { - let r = URL.createObjectURL(e); - dn(t, r), URL.revokeObjectURL(r); - } - i(ir, "downloadBlob"); - var ar = i((t) => t.match(/^data:\w+\/\w+;base64,.+/), "isDataURL"); - var ro = i((t) => t.split(".").slice(0, -1).join("."), "getFileName"); - function Ie(t, e) { - return (...r) => { - let s = r.length; - if (s === t.length) return t(...r); - if (s === e.length) return e(...r); - }; - } - i(Ie, "overload2"); - var oo = (() => { - let t = 0; - return () => t++; - })(), - so = i( - (t) => (t instanceof Error ? t.message : String(t)), - "getErrorMessage" + 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 ); - var ln = class { + } + 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 { - i(this, "BinaryHeap"); + s(this, "ButtonState"); } - _items; - _compareFn; - constructor(e = (r, s) => r < s) { - (this._compareFn = e), (this._items = []); + pressed = new Set([]); + pressedRepeat = new Set([]); + released = new Set([]); + down = new Set([]); + update() { + this.pressed.clear(), this.released.clear(), this.pressedRepeat.clear(); } - insert(e) { - this._items.push(e), this.moveUp(this._items.length - 1); + press(e) { + this.pressed.add(e), this.pressedRepeat.add(e), this.down.add(e); } - remove() { - if (this._items.length === 0) return null; - let e = this._items[0], - r = this._items.pop(); + 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 ( - this._items.length !== 0 && ((this._items[0] = r), this.moveDown(0)), e + 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() { - this._items.splice(0, this._items.length); + let e = this.ctx.gl; + e.clear(e.COLOR_BUFFER_BIT); } - moveUp(e) { - for (; e > 0; ) { - let r = Math.floor((e - 1) / 2); - if ( - !this._compareFn(this._items[e], this._items[r]) && - this._items[e] >= this._items[r] - ) - break; - this.swap(e, r), (e = r); - } + draw(e) { + this.bind(), e(), this.unbind(); } - moveDown(e) { - for (; e < Math.floor(this._items.length / 2); ) { - let r = 2 * e + 1; - if ( - (r < this._items.length - 1 && - !this._compareFn(this._items[r], this._items[r + 1]) && - ++r, - this._compareFn(this._items[e], this._items[r])) - ) - break; - this.swap(e, r), (e = r); - } + bind() { + this.ctx.pushFramebuffer(this.glFramebuffer), + this.ctx.pushRenderbuffer(this.glRenderbuffer), + this.ctx.pushViewport({ x: 0, y: 0, w: this.width, h: this.height }); } - swap(e, r) { - [this._items[e], this._items[r]] = [this._items[r], this._items[e]]; + unbind() { + this.ctx.popFramebuffer(), + this.ctx.popRenderbuffer(), + this.ctx.popViewport(); } - get length() { - return this._items.length; + free() { + let e = this.ctx.gl; + e.deleteFramebuffer(this.glFramebuffer), + e.deleteRenderbuffer(this.glRenderbuffer), + this.tex.free(); } - }; - var Bi = Object.freeze([ - 776, 2359, 2367, 2984, 3007, 3021, 3633, 3635, 3648, 3657, 4352, 4449, 4520, - ]); - function io(t) { - if (typeof t != "string") - throw new TypeError("string cannot be undefined or null"); - let e = [], - r = 0, - s = 0; - for (; r < t.length; ) { + }, + 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 ( - ((s += Fi(r + s, t)), - Hi(t[r + s]) && s++, - ki(t[r + s]) && s++, - Ni(t[r + s]) && s++, - Ki(t[r + s])) + ((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)) ) { - s++; - continue; + 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); } - e.push(t.substring(r, r + s)), (r += s), (s = 0); + 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); } - return e; - } - i(io, "runes"); - function Fi(t, e) { - let r = e[t]; - if (!Ii(r) || t === e.length - 1) return 1; - let s = r + e[t + 1], - a = e.substring(t + 2, t + 5); - return eo(s) && eo(a) - ? 4 - : Li(s) && _i(a) - ? e.slice(t).indexOf(String.fromCodePoint(917631)) + 2 - : ji(a) - ? 4 - : 2; - } - i(Fi, "nextUnits"); - function Ii(t) { - return t && vt(t[0].charCodeAt(0), 55296, 56319); - } - i(Ii, "isFirstOfSurrogatePair"); - function eo(t) { - return vt(cr(t), 127462, 127487); - } - i(eo, "isRegionalIndicator"); - function Li(t) { - return vt(cr(t), 127988, 127988); - } - i(Li, "isSubdivisionFlag"); - function ji(t) { - return vt(cr(t), 127995, 127999); - } - i(ji, "isFitzpatrickModifier"); - function ki(t) { - return typeof t == "string" && vt(t.charCodeAt(0), 65024, 65039); - } - i(ki, "isVariationSelector"); - function Ni(t) { - return typeof t == "string" && vt(t.charCodeAt(0), 8400, 8447); - } - i(Ni, "isDiacriticalMark"); - function _i(t) { - let e = t.codePointAt(0); - return ( - typeof t == "string" && typeof e == "number" && vt(e, 917504, 917631) - ); - } - i(_i, "isSupplementarySpecialpurposePlane"); - function Hi(t) { - return typeof t == "string" && Bi.includes(t.charCodeAt(0)); - } - i(Hi, "isGrapheme"); - function Ki(t) { - return typeof t == "string" && t.charCodeAt(0) === 8205; - } - i(Ki, "isZeroWidthJoiner"); - function cr(t) { - let e = t.charCodeAt(0) - 55296, - r = t.charCodeAt(1) - 56320; - return (e << 10) + r + 65536; - } - i(cr, "codePointFromSurrogatePair"); - function vt(t, e, r) { - return t >= e && t <= r; - } - i(vt, "betweenInclusive"); - var ur = { - "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 { - i(this, "ButtonState"); - } - pressed = new Set([]); - pressedRepeat = new Set([]); - released = new Set([]); - down = new Set([]); - update() { - this.pressed.clear(), this.released.clear(), this.pressedRepeat.clear(); - } - press(e) { - this.pressed.add(e), this.pressedRepeat.add(e), this.down.add(e); - } - pressRepeat(e) { - this.pressedRepeat.add(e); - } - release(e) { - this.down.delete(e), this.pressed.delete(e), this.released.add(e); - } - }, - lr = class { - static { - i(this, "GamepadState"); - } - buttonState = new Ut(); - stickState = new Map(); - }, - mr = class { - static { - i(this, "FPSCounter"); - } - dts = []; - timer = 0; - fps = 0; - tick(e) { - this.dts.push(e), - (this.timer += e), - this.timer >= 1 && - ((this.timer = 0), - (this.fps = Math.round( - 1 / (this.dts.reduce((r, s) => r + s) / this.dts.length) - )), - (this.dts = [])); - } - }, - ao = i((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 mr(), - timeScale: 1, - skipTime: !1, - isHidden: !1, - numFrames: 0, - mousePos: new T(0), - mouseDeltaPos: new T(0), - keyState: new Ut(), - mouseState: new Ut(), - mergedGamepadState: new lr(), - gamepadStates: new Map(), - gamepads: [], - charInputted: [], - isMouseMoved: !1, - lastWidth: t.canvas.offsetWidth, - lastHeight: t.canvas.offsetHeight, - events: new tt(), - }; - function r() { - return e.dt * e.timeScale; - } - i(r, "dt"); - function s() { - return e.isHidden; - } - i(s, "isHidden"); - function a() { - return e.time; - } - i(a, "time"); - function l() { - return e.fpsCounter.fps; - } - i(l, "fps"); - function u() { - return e.numFrames; - } - i(u, "numFrames"); - function f() { - return e.canvas.toDataURL(); - } - i(f, "screenshot"); - function y(p) { - e.canvas.style.cursor = p; - } - i(y, "setCursor"); - function m() { - return e.canvas.style.cursor; - } - i(m, "getCursor"); - function V(p) { - if (p) - try { - let S = e.canvas.requestPointerLock(); - S.catch && S.catch((L) => console.error(L)); - } catch (S) { - console.error(S); - } - else document.exitPointerLock(); - } - i(V, "setCursorLocked"); - function x() { - return !!document.pointerLockElement; - } - i(x, "isCursorLocked"); - function P(p) { - p.requestFullscreen - ? p.requestFullscreen() - : p.webkitRequestFullscreen && p.webkitRequestFullscreen(); - } - i(P, "enterFullscreen"); - function w() { - document.exitFullscreen - ? document.exitFullscreen() - : document.webkitExitFullScreen && document.webkitExitFullScreen(); - } - i(w, "exitFullscreen"); - function K() { - return document.fullscreenElement || document.webkitFullscreenElement; - } - i(K, "getFullscreenElement"); - function X(p = !0) { - p ? P(e.canvas) : w(); - } - i(X, "setFullscreen"); - function z() { - return !!K(); - } - i(z, "isFullscreen"); - function N() { - e.stopped = !0; - for (let p in he) e.canvas.removeEventListener(p, he[p]); - for (let p in Ke) document.removeEventListener(p, Ke[p]); - for (let p in xe) window.removeEventListener(p, xe[p]); - at.disconnect(); - } - i(N, "quit"); - function $(p) { - e.loopID !== null && cancelAnimationFrame(e.loopID); - let S = 0, - L = i((Y) => { - if (e.stopped) return; - if (document.visibilityState !== "visible") { - e.loopID = requestAnimationFrame(L); - return; - } - let ye = Y / 1e3, - ie = ye - e.realTime, - Ye = t.maxFPS ? 1 / t.maxFPS : 0; - (e.realTime = ye), - (S += ie), - S > Ye && - (e.skipTime || - ((e.dt = S), (e.time += r()), e.fpsCounter.tick(e.dt)), - (S = 0), - (e.skipTime = !1), - e.numFrames++, - Mn(), - p(), - Mt()), - (e.loopID = requestAnimationFrame(L)); - }, "frame"); - L(0); - } - i($, "run"); - function O() { - return "ontouchstart" in window || navigator.maxTouchPoints > 0; - } - i(O, "isTouchscreen"); - function se() { - return e.mousePos.clone(); - } - i(se, "mousePos"); - function _() { - return e.mouseDeltaPos.clone(); - } - i(_, "mouseDeltaPos"); - function ae(p = "left") { - return e.mouseState.pressed.has(p); - } - i(ae, "isMousePressed"); - function re(p = "left") { - return e.mouseState.down.has(p); - } - i(re, "isMouseDown"); - function ce(p = "left") { - return e.mouseState.released.has(p); - } - i(ce, "isMouseReleased"); - function ge() { - return e.isMouseMoved; - } - i(ge, "isMouseMoved"); - function Ue(p) { - return p === void 0 - ? e.keyState.pressed.size > 0 - : e.keyState.pressed.has(p); - } - i(Ue, "isKeyPressed"); - function Ce(p) { - return p === void 0 - ? e.keyState.pressedRepeat.size > 0 - : e.keyState.pressedRepeat.has(p); - } - i(Ce, "isKeyPressedRepeat"); - function Le(p) { - return p === void 0 ? e.keyState.down.size > 0 : e.keyState.down.has(p); - } - i(Le, "isKeyDown"); - function je(p) { - return p === void 0 - ? e.keyState.released.size > 0 - : e.keyState.released.has(p); - } - i(je, "isKeyReleased"); - function Ee(p) { - return p === void 0 - ? e.mergedGamepadState.buttonState.pressed.size > 0 - : e.mergedGamepadState.buttonState.pressed.has(p); - } - i(Ee, "isGamepadButtonPressed"); - function Ne(p) { - return p === void 0 - ? e.mergedGamepadState.buttonState.down.size > 0 - : e.mergedGamepadState.buttonState.down.has(p); - } - i(Ne, "isGamepadButtonDown"); - function _e(p) { - return p === void 0 - ? e.mergedGamepadState.buttonState.released.size > 0 - : e.mergedGamepadState.buttonState.released.has(p); - } - i(_e, "isGamepadButtonReleased"); - function He(p) { - return e.events.on("resize", p); - } - i(He, "onResize"); - let pt = Ie( - (p) => e.events.on("keyDown", p), - (p, S) => e.events.on("keyDown", (L) => L === p && S(p)) - ), - Se = Ie( - (p) => e.events.on("keyPress", p), - (p, S) => e.events.on("keyPress", (L) => L === p && S(p)) - ), - Ve = Ie( - (p) => e.events.on("keyPressRepeat", p), - (p, S) => e.events.on("keyPressRepeat", (L) => L === p && S(p)) - ), - ze = Ie( - (p) => e.events.on("keyRelease", p), - (p, S) => e.events.on("keyRelease", (L) => L === p && S(p)) - ), - rt = Ie( - (p) => e.events.on("mouseDown", (S) => p(S)), - (p, S) => e.events.on("mouseDown", (L) => L === p && S(L)) - ), - ot = Ie( - (p) => e.events.on("mousePress", (S) => p(S)), - (p, S) => e.events.on("mousePress", (L) => L === p && S(L)) - ), - wt = Ie( - (p) => e.events.on("mouseRelease", (S) => p(S)), - (p, S) => e.events.on("mouseRelease", (L) => L === p && S(L)) - ); - function Yt(p) { - return e.events.on("mouseMove", () => p(se(), _())); - } - i(Yt, "onMouseMove"); - function Xt(p) { - return e.events.on("charInput", p); - } - i(Xt, "onCharInput"); - function An(p) { - return e.events.on("touchStart", p); - } - i(An, "onTouchStart"); - function Wt(p) { - return e.events.on("touchMove", p); - } - i(Wt, "onTouchMove"); - function On(p) { - return e.events.on("touchEnd", p); - } - i(On, "onTouchEnd"); - function Rn(p) { - return e.events.on("scroll", p); - } - i(Rn, "onScroll"); - function $t(p) { - return e.events.on("hide", p); - } - i($t, "onHide"); - function Un(p) { - return e.events.on("show", p); - } - i(Un, "onShow"); - function Vn(p, S) { - if (typeof p == "function") return e.events.on("gamepadButtonDown", p); - if (typeof p == "string" && typeof S == "function") - return e.events.on("gamepadButtonDown", (L) => L === p && S(p)); - } - i(Vn, "onGamepadButtonDown"); - function Qt(p, S) { - if (typeof p == "function") return e.events.on("gamepadButtonPress", p); - if (typeof p == "string" && typeof S == "function") - return e.events.on("gamepadButtonPress", (L) => L === p && S(p)); - } - i(Qt, "onGamepadButtonPress"); - function Jt(p, S) { - if (typeof p == "function") - return e.events.on("gamepadButtonRelease", p); - if (typeof p == "string" && typeof S == "function") - return e.events.on("gamepadButtonRelease", (L) => L === p && S(p)); - } - i(Jt, "onGamepadButtonRelease"); - function Pn(p, S) { - return e.events.on("gamepadStick", (L, Y) => L === p && S(Y)); - } - i(Pn, "onGamepadStick"); - function Dt(p) { - e.events.on("gamepadConnect", p); - } - i(Dt, "onGamepadConnect"); - function Dn(p) { - e.events.on("gamepadDisconnect", p); - } - i(Dn, "onGamepadDisconnect"); - function st(p) { - return e.mergedGamepadState.stickState.get(p) || new T(0); - } - i(st, "getGamepadStick"); - function Pe() { - return [...e.charInputted]; - } - i(Pe, "charInputted"); - function Ct() { - return [...e.gamepads]; - } - i(Ct, "getGamepads"); - function Mn() { - e.events.trigger("input"), - e.keyState.down.forEach((p) => e.events.trigger("keyDown", p)), - e.mouseState.down.forEach((p) => e.events.trigger("mouseDown", p)), - de(); - } - i(Mn, "processInput"); - function Mt() { - e.keyState.update(), - e.mouseState.update(), - e.mergedGamepadState.buttonState.update(), - e.mergedGamepadState.stickState.forEach((p, S) => { - e.mergedGamepadState.stickState.set(S, new T(0)); - }), - (e.charInputted = []), - (e.isMouseMoved = !1), - e.gamepadStates.forEach((p) => { - p.buttonState.update(), - p.stickState.forEach((S, L) => { - p.stickState.set(L, new T(0)); - }); - }); - } - i(Mt, "resetInput"); - function Zt(p) { - let S = { - index: p.index, - isPressed: (L) => - e.gamepadStates.get(p.index).buttonState.pressed.has(L), - isDown: (L) => e.gamepadStates.get(p.index).buttonState.down.has(L), - isReleased: (L) => - e.gamepadStates.get(p.index).buttonState.released.has(L), - getStick: (L) => e.gamepadStates.get(p.index).stickState.get(L), - }; - return ( - e.gamepads.push(S), - e.gamepadStates.set(p.index, { - buttonState: new Ut(), - stickState: new Map([ - ["left", new T(0)], - ["right", new T(0)], - ]), - }), - S - ); - } - i(Zt, "registerGamepad"); - function Gn(p) { - (e.gamepads = e.gamepads.filter((S) => S.index !== p.index)), - e.gamepadStates.delete(p.index); - } - i(Gn, "removeGamepad"); - function de() { - for (let p of navigator.getGamepads()) - p && !e.gamepadStates.has(p.index) && Zt(p); - for (let p of e.gamepads) { - let S = navigator.getGamepads()[p.index], - Y = (t.gamepads ?? {})[S.id] ?? ur[S.id] ?? ur.default, - ye = e.gamepadStates.get(p.index); - for (let ie = 0; ie < S.buttons.length; ie++) - S.buttons[ie].pressed - ? (ye.buttonState.down.has(Y.buttons[ie]) || - (e.mergedGamepadState.buttonState.press(Y.buttons[ie]), - ye.buttonState.press(Y.buttons[ie]), - e.events.trigger("gamepadButtonPress", Y.buttons[ie])), - e.events.trigger("gamepadButtonDown", Y.buttons[ie])) - : ye.buttonState.down.has(Y.buttons[ie]) && - (e.mergedGamepadState.buttonState.release(Y.buttons[ie]), - ye.buttonState.release(Y.buttons[ie]), - e.events.trigger("gamepadButtonRelease", Y.buttons[ie])); - for (let ie in Y.sticks) { - let Ye = Y.sticks[ie], - ft = new T(S.axes[Ye.x], S.axes[Ye.y]); - ye.stickState.set(ie, ft), - e.mergedGamepadState.stickState.set(ie, ft), - e.events.trigger("gamepadStick", ie, ft); - } - } - } - i(de, "processGamepad"); - let he = {}, - Ke = {}, - xe = {}, - Ae = t.pixelDensity || window.devicePixelRatio || 1; - he.mousemove = (p) => { - let S = new T(p.offsetX, p.offsetY), - L = new T(p.movementX, p.movementY); - if (z()) { - let Y = e.canvas.width / Ae, - ye = e.canvas.height / Ae, - ie = window.innerWidth, - Ye = window.innerHeight, - ft = ie / Ye, - tn = Y / ye; - if (ft > tn) { - let Xe = Ye / ye, - Tt = (ie - Y * Xe) / 2; - (S.x = dt(p.offsetX - Tt, 0, Y * Xe, 0, Y)), - (S.y = dt(p.offsetY, 0, ye * Xe, 0, ye)); - } else { - let Xe = ie / Y, - Tt = (Ye - ye * Xe) / 2; - (S.x = dt(p.offsetX, 0, Y * Xe, 0, Y)), - (S.y = dt(p.offsetY - Tt, 0, ye * Xe, 0, ye)); - } - } - e.events.onOnce("input", () => { - (e.isMouseMoved = !0), - (e.mousePos = S), - (e.mouseDeltaPos = L), - e.events.trigger("mouseMove"); - }); - }; - let it = ["left", "middle", "right", "back", "forward"]; - (he.mousedown = (p) => { - e.events.onOnce("input", () => { - let S = it[p.button]; - S && (e.mouseState.press(S), e.events.trigger("mousePress", S)); - }); - }), - (he.mouseup = (p) => { - e.events.onOnce("input", () => { - let S = it[p.button]; - S && (e.mouseState.release(S), e.events.trigger("mouseRelease", S)); - }); - }); - let Gt = new Set([ - " ", - "ArrowLeft", - "ArrowRight", - "ArrowUp", - "ArrowDown", - "Tab", - ]), - en = { - ArrowLeft: "left", - ArrowRight: "right", - ArrowUp: "up", - ArrowDown: "down", - " ": "space", - }; - (he.keydown = (p) => { - Gt.has(p.key) && p.preventDefault(), - e.events.onOnce("input", () => { - let S = en[p.key] || p.key.toLowerCase(); - S.length === 1 - ? (e.events.trigger("charInput", S), e.charInputted.push(S)) - : S === "space" && - (e.events.trigger("charInput", " "), e.charInputted.push(" ")), - p.repeat - ? (e.keyState.pressRepeat(S), - e.events.trigger("keyPressRepeat", S)) - : (e.keyState.press(S), - e.events.trigger("keyPressRepeat", S), - e.events.trigger("keyPress", S)); - }); - }), - (he.keyup = (p) => { - e.events.onOnce("input", () => { - let S = en[p.key] || p.key.toLowerCase(); - e.keyState.release(S), e.events.trigger("keyRelease", S); - }); - }), - (he.touchstart = (p) => { - p.preventDefault(), - e.events.onOnce("input", () => { - let S = [...p.changedTouches], - L = e.canvas.getBoundingClientRect(); - t.touchToMouse !== !1 && - ((e.mousePos = new T(S[0].clientX - L.x, S[0].clientY - L.y)), - e.mouseState.press("left"), - e.events.trigger("mousePress", "left")), - S.forEach((Y) => { - e.events.trigger( - "touchStart", - new T(Y.clientX - L.x, Y.clientY - L.y), - Y - ); - }); - }); - }), - (he.touchmove = (p) => { - p.preventDefault(), - e.events.onOnce("input", () => { - let S = [...p.changedTouches], - L = e.canvas.getBoundingClientRect(); - if (t.touchToMouse !== !1) { - let Y = e.mousePos; - (e.mousePos = new T(S[0].clientX - L.x, S[0].clientY - L.y)), - (e.mouseDeltaPos = e.mousePos.sub(Y)), - e.events.trigger("mouseMove"); - } - S.forEach((Y) => { - e.events.trigger( - "touchMove", - new T(Y.clientX - L.x, Y.clientY - L.y), - Y - ); - }); - }); - }), - (he.touchend = (p) => { - e.events.onOnce("input", () => { - let S = [...p.changedTouches], - L = e.canvas.getBoundingClientRect(); - t.touchToMouse !== !1 && - ((e.mousePos = new T(S[0].clientX - L.x, S[0].clientY - L.y)), - (e.mouseDeltaPos = new T(0, 0)), - e.mouseState.release("left"), - e.events.trigger("mouseRelease", "left")), - S.forEach((Y) => { - e.events.trigger( - "touchEnd", - new T(Y.clientX - L.x, Y.clientY - L.y), - Y - ); - }); - }); - }), - (he.touchcancel = (p) => { - e.events.onOnce("input", () => { - let S = [...p.changedTouches], - L = e.canvas.getBoundingClientRect(); - t.touchToMouse !== !1 && - ((e.mousePos = new T(S[0].clientX - L.x, S[0].clientY - L.y)), - e.mouseState.release("left"), - e.events.trigger("mouseRelease", "left")), - S.forEach((Y) => { - e.events.trigger( - "touchEnd", - new T(Y.clientX - L.x, Y.clientY - L.y), - Y - ); - }); - }); - }), - (he.wheel = (p) => { - p.preventDefault(), - e.events.onOnce("input", () => { - e.events.trigger("scroll", new T(p.deltaX, p.deltaY)); - }); - }), - (he.contextmenu = (p) => p.preventDefault()), - (Ke.visibilitychange = () => { - document.visibilityState === "visible" - ? ((e.skipTime = !0), (e.isHidden = !1), e.events.trigger("show")) - : ((e.isHidden = !0), e.events.trigger("hide")); - }), - (xe.gamepadconnected = (p) => { - let S = Zt(p.gamepad); - e.events.onOnce("input", () => { - e.events.trigger("gamepadConnect", S); - }); - }), - (xe.gamepaddisconnected = (p) => { - let S = Ct().filter((L) => L.index === p.gamepad.index)[0]; - Gn(p.gamepad), - e.events.onOnce("input", () => { - e.events.trigger("gamepadDisconnect", S); - }); - }); - for (let p in he) e.canvas.addEventListener(p, he[p]); - for (let p in Ke) document.addEventListener(p, Ke[p]); - for (let p in xe) window.addEventListener(p, xe[p]); - let at = new ResizeObserver((p) => { - for (let S of p) - if (S.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 ( - at.observe(e.canvas), - { - dt: r, - time: a, - run: $, - canvas: e.canvas, - fps: l, - numFrames: u, - quit: N, - isHidden: s, - setFullscreen: X, - isFullscreen: z, - setCursor: y, - screenshot: f, - getGamepads: Ct, - getCursor: m, - setCursorLocked: V, - isCursorLocked: x, - isTouchscreen: O, - mousePos: se, - mouseDeltaPos: _, - isKeyDown: Le, - isKeyPressed: Ue, - isKeyPressedRepeat: Ce, - isKeyReleased: je, - isMouseDown: re, - isMousePressed: ae, - isMouseReleased: ce, - isMouseMoved: ge, - isGamepadButtonPressed: Ee, - isGamepadButtonDown: Ne, - isGamepadButtonReleased: _e, - getGamepadStick: st, - charInputted: Pe, - onResize: He, - onKeyDown: pt, - onKeyPress: Se, - onKeyPressRepeat: Ve, - onKeyRelease: ze, - onMouseDown: rt, - onMousePress: ot, - onMouseRelease: wt, - onMouseMove: Yt, - onCharInput: Xt, - onTouchStart: An, - onTouchMove: Wt, - onTouchEnd: On, - onScroll: Rn, - onHide: $t, - onShow: Un, - onGamepadButtonDown: Vn, - onGamepadButtonPress: Qt, - onGamepadButtonRelease: Jt, - onGamepadStick: Pn, - onGamepadConnect: Dt, - onGamepadDisconnect: Dn, - events: e.events, - } - ); - }, "default"); - var qe = class t { - static { - i(this, "Texture"); - } - ctx; - src = null; - glTex; - width; - height; - constructor(e, r, s, a = {}) { - this.ctx = e; - let l = e.gl; - (this.glTex = e.gl.createTexture()), - e.onDestroy(() => this.free()), - (this.width = r), - (this.height = s); - let u = - { linear: l.LINEAR, nearest: l.NEAREST }[ - a.filter ?? e.opts.texFilter - ] ?? l.NEAREST, - f = - { repeat: l.REPEAT, clampToEadge: l.CLAMP_TO_EDGE }[a.wrap] ?? - l.CLAMP_TO_EDGE; - this.bind(), - r && - s && - l.texImage2D( - l.TEXTURE_2D, - 0, - l.RGBA, - r, - s, - 0, - l.RGBA, - l.UNSIGNED_BYTE, - null - ), - l.texParameteri(l.TEXTURE_2D, l.TEXTURE_MIN_FILTER, u), - l.texParameteri(l.TEXTURE_2D, l.TEXTURE_MAG_FILTER, u), - l.texParameteri(l.TEXTURE_2D, l.TEXTURE_WRAP_S, f), - l.texParameteri(l.TEXTURE_2D, l.TEXTURE_WRAP_T, f), - this.unbind(); - } - static fromImage(e, r, s = {}) { - let a = new t(e, r.width, r.height, s); - return a.update(r), (a.src = r), a; - } - update(e, r = 0, s = 0) { - let a = this.ctx.gl; - this.bind(), - a.texSubImage2D(a.TEXTURE_2D, 0, r, s, 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 { - i(this, "FrameBuffer"); - } - ctx; - tex; - glFramebuffer; - glRenderbuffer; - constructor(e, r, s, a = {}) { - this.ctx = e; - let l = e.gl; - e.onDestroy(() => this.free()), - (this.tex = new qe(e, r, s, a)), - (this.glFramebuffer = l.createFramebuffer()), - (this.glRenderbuffer = l.createRenderbuffer()), - this.bind(), - l.renderbufferStorage(l.RENDERBUFFER, l.DEPTH_STENCIL, r, s), - l.framebufferTexture2D( - l.FRAMEBUFFER, - l.COLOR_ATTACHMENT0, - l.TEXTURE_2D, - this.tex.glTex, - 0 - ), - l.framebufferRenderbuffer( - l.FRAMEBUFFER, - l.DEPTH_STENCIL_ATTACHMENT, - l.RENDERBUFFER, - this.glRenderbuffer - ), - this.unbind(); - } - get width() { - return this.tex.width; - } - get height() { - return this.tex.height; - } - toImageData() { - let e = this.ctx.gl, - r = new Uint8ClampedArray(this.width * this.height * 4); - this.bind(), - e.readPixels( - 0, - 0, - this.width, - this.height, - e.RGBA, - e.UNSIGNED_BYTE, - r - ), - this.unbind(); - let s = this.width * 4, - a = new Uint8Array(s); - for (let l = 0; l < ((this.height / 2) | 0); l++) { - let u = l * s, - f = (this.height - l - 1) * s; - a.set(r.subarray(u, u + s)), r.copyWithin(u, f, f + s), r.set(a, f); - } - return new ImageData(r, this.width, this.height); - } - toDataURL() { - let e = document.createElement("canvas"), - r = e.getContext("2d"); - return ( - (e.width = this.width), - (e.height = this.height), - r.putImageData(this.toImageData(), 0, 0), - e.toDataURL() - ); - } - clear() { - let e = this.ctx.gl; - e.clear(e.COLOR_BUFFER_BIT); - } - draw(e) { - this.bind(), e(), this.unbind(); - } - bind() { - this.ctx.pushFramebuffer(this.glFramebuffer), - this.ctx.pushRenderbuffer(this.glRenderbuffer), - this.ctx.pushViewport({ x: 0, y: 0, w: this.width, h: this.height }); - } - unbind() { - this.ctx.popFramebuffer(), - this.ctx.popRenderbuffer(), - this.ctx.popViewport(); - } - free() { - let e = this.ctx.gl; - e.deleteFramebuffer(this.glFramebuffer), - e.deleteRenderbuffer(this.glRenderbuffer), - this.tex.free(); - } - }, - hn = class { - static { - i(this, "Shader"); - } - ctx; - glProgram; - constructor(e, r, s, a) { - (this.ctx = e), e.onDestroy(() => this.free()); - let l = e.gl, - u = l.createShader(l.VERTEX_SHADER), - f = l.createShader(l.FRAGMENT_SHADER); - l.shaderSource(u, r), - l.shaderSource(f, s), - l.compileShader(u), - l.compileShader(f); - let y = l.createProgram(); - if ( - ((this.glProgram = y), - l.attachShader(y, u), - l.attachShader(y, f), - a.forEach((m, V) => l.bindAttribLocation(y, V, m)), - l.linkProgram(y), - !l.getProgramParameter(y, l.LINK_STATUS)) - ) { - let m = l.getShaderInfoLog(u); - if (m) throw new Error("VERTEX SHADER " + m); - let V = l.getShaderInfoLog(f); - if (V) throw new Error("FRAGMENT SHADER " + V); - } - l.deleteShader(u), l.deleteShader(f); - } - bind() { - this.ctx.pushProgram(this.glProgram); - } - unbind() { - this.ctx.popProgram(); - } - send(e) { - let r = this.ctx.gl; - for (let s in e) { - let a = e[s], - l = r.getUniformLocation(this.glProgram, s); - if (typeof a == "number") r.uniform1f(l, a); - else if (a instanceof Ge) - r.uniformMatrix4fv(l, !1, new Float32Array(a.m)); - else if (a instanceof ee) r.uniform3f(l, a.r, a.g, a.b); - else if (a instanceof T) r.uniform2f(l, a.x, a.y); - else if (Array.isArray(a)) { - let u = a[0]; - typeof u == "number" - ? r.uniform1fv(l, a) - : u instanceof T - ? r.uniform2fv(l, a.map((f) => [f.x, f.y]).flat()) - : u instanceof ee && - r.uniform3fv(l, 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 { - i(this, "BatchRenderer"); - } - ctx; - glVBuf; - glIBuf; - vqueue = []; - iqueue = []; - stride; - maxVertices; - maxIndices; - vertexFormat; - numDraws = 0; - curPrimitive = null; - curTex = null; - curShader = null; - curUniform = {}; - constructor(e, r, s, a) { - let l = e.gl; - (this.vertexFormat = r), - (this.ctx = e), - (this.stride = r.reduce((u, f) => u + f.size, 0)), - (this.maxVertices = s), - (this.maxIndices = a), - (this.glVBuf = l.createBuffer()), - e.pushArrayBuffer(this.glVBuf), - l.bufferData(l.ARRAY_BUFFER, s * 4, l.DYNAMIC_DRAW), - e.popArrayBuffer(), - (this.glIBuf = l.createBuffer()), - e.pushElementArrayBuffer(this.glIBuf), - l.bufferData(l.ELEMENT_ARRAY_BUFFER, a * 4, l.DYNAMIC_DRAW), - e.popElementArrayBuffer(); - } - push(e, r, s, a, l = null, u = {}) { - (e !== this.curPrimitive || - l !== this.curTex || - a !== this.curShader || - !mn(this.curUniform, u) || - this.vqueue.length + r.length * this.stride > this.maxVertices || - this.iqueue.length + s.length > this.maxIndices) && - this.flush(); - let f = this.vqueue.length / this.stride; - for (let y of r) this.vqueue.push(y); - for (let y of s) this.iqueue.push(y + f); - (this.curPrimitive = e), - (this.curShader = a), - (this.curTex = l), - (this.curUniform = u); - } - 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 = [], - r = i((l) => { - e.push(l), t(l); - }, "push"), - s = i(() => { - e.pop(), t(a() ?? null); - }, "pop"), - a = i(() => e[e.length - 1], "cur"); - return [r, s, a]; +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); } - i(xt, "genStack"); - function dr(t, e = {}) { - let r = []; - function s(_) { - r.push(_); - } - i(s, "onDestroy"); - function a() { - r.forEach((_) => _()), t.getExtension("WEBGL_lose_context").loseContext(); - } - i(a, "destroy"); - let l = null; - function u(_) { - if (mn(_, l)) return; - l = _; - let ae = _.reduce((re, ce) => re + ce.size, 0); - _.reduce( - (re, ce, ge) => ( - t.vertexAttribPointer(ge, ce.size, t.FLOAT, !1, ae * 4, re), - t.enableVertexAttribArray(ge), - re + ce.size * 4 - ), - 0 - ); - } - i(u, "setVertexFormat"); - let [f, y] = xt((_) => t.bindTexture(t.TEXTURE_2D, _)), - [m, V] = xt((_) => t.bindBuffer(t.ARRAY_BUFFER, _)), - [x, P] = xt((_) => t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, _)), - [w, K] = xt((_) => t.bindFramebuffer(t.FRAMEBUFFER, _)), - [X, z] = xt((_) => t.bindRenderbuffer(t.RENDERBUFFER, _)), - [N, $] = xt(({ x: _, y: ae, w: re, h: ce }) => { - t.viewport(_, ae, re, ce); - }), - [O, se] = xt((_) => t.useProgram(_)); - return ( - N({ x: 0, y: 0, w: t.drawingBufferWidth, h: t.drawingBufferHeight }), - { - gl: t, - opts: e, - onDestroy: s, - destroy: a, - pushTexture2D: f, - popTexture2D: y, - pushArrayBuffer: m, - popArrayBuffer: V, - pushElementArrayBuffer: x, - popElementArrayBuffer: P, - pushFramebuffer: w, - popFramebuffer: K, - pushRenderbuffer: X, - popRenderbuffer: z, - pushViewport: N, - popViewport: $, - pushProgram: O, - popProgram: se, - setVertexFormat: u, - } + 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 ); } - i(dr, "initGfx"); - var Re = class t { - static { - i(this, "Asset"); - } - loaded = !1; - data = null; - error = null; - onLoadEvents = new we(); - onErrorEvents = new we(); - onFinishEvents = new we(); - constructor(e) { - e.then((r) => { - (this.loaded = !0), (this.data = r), this.onLoadEvents.trigger(r); - }) - .catch((r) => { - if (((this.error = r), this.onErrorEvents.numListeners() > 0)) - this.onErrorEvents.trigger(r); - else throw r; - }) - .finally(() => { - this.onFinishEvents.trigger(), (this.loaded = !0); - }); - } - static loaded(e) { - let r = new t(Promise.resolve(e)); - return (r.data = e), (r.loaded = !0), r; - } - onLoad(e) { - return ( - this.loaded && this.data ? e(this.data) : this.onLoadEvents.add(e), - this - ); - } - onError(e) { - return ( - this.loaded && this.error ? e(this.error) : this.onErrorEvents.add(e), - this - ); - } - onFinish(e) { - return this.loaded ? e() : this.onFinishEvents.add(e), this; - } - then(e) { - return this.onLoad(e); - } - catch(e) { - return this.onError(e); - } - finally(e) { - return this.onFinish(e); - } - }, - nt = class { - static { - i(this, "AssetBucket"); - } - assets = new Map(); - lastUID = 0; - add(e, r) { - let s = e ?? this.lastUID++ + "", - a = new Re(r); - return this.assets.set(s, a), a; - } - addLoaded(e, r) { - let s = e ?? this.lastUID++ + "", - a = Re.loaded(r); - return this.assets.set(s, a), a; - } - get(e) { - return this.assets.get(e); - } - progress() { - if (this.assets.size === 0) return 1; - let e = 0; - return ( - this.assets.forEach((r) => { - r.loaded && e++; - }), - e / this.assets.size - ); - } - }; - function hr(t) { - return fetch(t).then((e) => { - if (!e.ok) throw new Error(`Failed to fetch "${t}"`); - return e; - }); - } - i(hr, "fetchURL"); - function Nt(t) { - return hr(t).then((e) => e.json()); - } - i(Nt, "fetchJSON"); - function co(t) { - return hr(t).then((e) => e.text()); - } - i(co, "fetchText"); - function uo(t) { - return hr(t).then((e) => e.arrayBuffer()); - } - i(uo, "fetchArrayBuffer"); - function _t(t) { - let e = new Image(); - return ( - (e.crossOrigin = "anonymous"), - (e.src = t), - new Promise((r, s) => { - (e.onload = () => r(e)), - (e.onerror = () => s(new Error(`Failed to load image from "${t}"`))); + 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); }) - ); - } - i(_t, "loadImg"); - var pr = - " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", - Vt = "topleft"; - var lo = "monospace", - Ht = "monospace"; - var fn = "linear"; - var gn = [ - { name: "a_pos", size: 2 }, - { name: "a_uv", size: 2 }, - { name: "a_color", size: 4 }, - ], - zi = gn.reduce((t, e) => t + e.size, 0), - mo = 2048, - ho = mo * 4 * zi, - po = mo * 6, - fo = ` + .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; @@ -3409,7 +3559,7 @@ void main() { gl_Position = pos; } `, - go = ` + Mo = ` precision mediump float; varying vec2 v_pos; @@ -3431,4964 +3581,5144 @@ void main() { } } `, - bn = ` + bn = ` vec4 vert(vec2 pos, vec2 uv, vec4 color) { return def_vert(); } `, - vn = ` + vn = ` vec4 frag(vec2 pos, vec2 uv, vec4 color, sampler2D tex) { return def_frag(); } `, - bo = new Set(["id", "require"]), - vo = new Set([ - "add", - "update", - "draw", - "destroy", - "inspect", - "drawInspect", - ]), - fr = /\[(?