From bb0991ef216aa89463750d18ce06a11cfec3ae8b Mon Sep 17 00:00:00 2001 From: MeowcaTheoRange Date: Sun, 2 Jun 2024 00:39:23 -0500 Subject: [PATCH] I forgot to do rolling commits --- assets/images/grid.png | Bin 9178 -> 9362 bytes assets/scripts/KaplayMap/events.js | 35 + assets/scripts/KaplayMap/floors.js | 84 + assets/scripts/KaplayMap/gameobj.js | 132 + assets/scripts/KaplayMap/index.js | 157 +- assets/scripts/KaplayMap/ui.js | 158 + assets/scripts/KaplayMap/zoom.js | 60 - assets/scripts/modules/kaplay.js | 12829 ++++++++++++++------------ assets/scripts/script.js | 21 +- assets/styles/style.css | 209 + nodemon.json | 2 +- pages/index.html | 35 + scripts/server.js | 7 +- 13 files changed, 7866 insertions(+), 5863 deletions(-) create mode 100644 assets/scripts/KaplayMap/events.js create mode 100644 assets/scripts/KaplayMap/floors.js create mode 100644 assets/scripts/KaplayMap/gameobj.js create mode 100644 assets/scripts/KaplayMap/ui.js delete mode 100644 assets/scripts/KaplayMap/zoom.js diff --git a/assets/images/grid.png b/assets/images/grid.png index 04da9eb2c7dff448d7c61b91dedb5d36bd3bd95a..34e5f03ccdedeaa7df54eadc0b29437aaff48c50 100644 GIT binary patch delta 587 zcmccRKFM=Kuu?sfrl*TzNJZS+IhJ|M4g!bg)SQX`e!fWLlUY19g&Sr66>p?6ibh+aZv0Dw_Q8IDk*G%z_Hcy!aQUR>$L+o9*6pCFX@{h zir2iR{-d+iwq5$~Yd`<|Kl%Lv|MX<-ro66~FKphgC=vO+!D&~`$CB2Bl)KDaFFzf< zEZQ`&lwV`XX>tE>4!3Kz3nu8r+r(l~SWmP{B!%A>%D7##e&B3*pzNc>`Sv1*6I!qG zPjr>sSUf@Ciq^6TqAxeND=MxC^-d%4{li96KIuDF36G1?{Ml9 zwAj|?Z0@3XoI@u1xb&h4$t-K?@8kUWgTe~DWM4fP(};T delta 402 zcmbQ_dCPr6uu?r^p{I*uNJZS+%Z$7Y4gyCU4(wl1`b}lUjFx##%l7VF*JrrltqqT_ z!u-ajg#LgDO$lrUbHsuK&M>rHcH(N1JWvqj;b_1t;m57Xk;ZU1Q<3!`PlAQ+5``Iz zJj+`}Sd1GUZo#Lio-AF|(^OB$fz-1KXw#kBe8;|I&k;Xf%Ir>mdK II;Vst0Lf{JVE_OC diff --git a/assets/scripts/KaplayMap/events.js b/assets/scripts/KaplayMap/events.js new file mode 100644 index 0000000..a30dbf4 --- /dev/null +++ b/assets/scripts/KaplayMap/events.js @@ -0,0 +1,35 @@ +export class EventManager { + map; + ui; + gameobj; + floormanager; + + events = new Map([]); + + constructor(map, ui, gameobj) { + this.map = map; + this.ui = ui; + this.ui.eventmanager = this; + this.gameobj = gameobj; + } + + async getFloorEvents() { + let floorEventsReqSend = fetch( + `/data/${this.floormanager.lang}/events/${this.floormanager.currentFloor}` + ); + + this.ui.setLoading(true); + + let floorEventsReq = await floorEventsReqSend; + let floorEvents; + if (floorEventsReq.ok) floorEvents = await floorEventsReq.json(); + + this.events.clear(); + + floorEvents.forEach((event) => this.events.set(event.id, event)); + + this.ui.setLoading(false); + + return this.events; + } +} diff --git a/assets/scripts/KaplayMap/floors.js b/assets/scripts/KaplayMap/floors.js new file mode 100644 index 0000000..ce585b9 --- /dev/null +++ b/assets/scripts/KaplayMap/floors.js @@ -0,0 +1,84 @@ +export class FloorManager { + map; + ui; + gameobj; + events; + lang; + + floors = new Map([]); + rooms = new Map([]); + currentFloor = ""; + + constructor(map, ui, gameobj, events, lang) { + this.map = map; + this.ui = ui; + this.ui.floormanager = this; + this.gameobj = gameobj; + this.gameobj.floormanager = this; + this.events = events; + this.events.floormanager = this; + this.lang = lang; + } + + async getFloors() { + let allFloorsReqSend = fetch(`/data/${this.lang}/map`); + + this.ui.setLoading(true); + + let allFloorsReq = await allFloorsReqSend; + let allFloors; + if (allFloorsReq.ok) allFloors = await allFloorsReq.json(); + + allFloors.forEach((floor) => this.floors.set(floor.id, floor)); + + this.changeFloor(allFloors[0].id); + + this.ui.setLoading(false); + + return this.floors; + } + + async getRooms(id) { + const curRoom = this.rooms.get(id); + + if (curRoom != null) return curRoom; + + let allRoomsReqSend = fetch(`/data/${this.lang}/map/${id}`); + + this.ui.setLoading(true); + + let allRoomsReq = await allRoomsReqSend; + let allRooms; + if (allRoomsReq.ok) allRooms = await allRoomsReq.json(); + + this.rooms.set(id, allRooms); + + this.ui.setLoading(false); + + return this.rooms; + } + + async changeFloor(id) { + const floor = this.floors.get(id); + if (floor != null) this.currentFloor = id; + + if (this.ui.floorsEmpty) this.ui.__updateFloorsHard(); + else this.ui.__updateFloorsSoft(); + + this.ui.setLoading(true); + + this.gameobj.generateFloor(); + + await this.getRooms(id); + + this.gameobj.generateRooms(); + + await this.events.getFloorEvents(); + + this.ui.__updateEvents(); + + this.ui.setLoading(false); + + return floor; + } +} diff --git a/assets/scripts/KaplayMap/gameobj.js b/assets/scripts/KaplayMap/gameobj.js new file mode 100644 index 0000000..e70e30a --- /dev/null +++ b/assets/scripts/KaplayMap/gameobj.js @@ -0,0 +1,132 @@ +export class GameObjManager { + map; + floormanager; + + floorObject; + roomObjects = new Map([]); + currentRoom; + + constructor(map) { + this.map = map; + } + + generateFloor() { + if (this.floorObject) this.floorObject.destroy(); + + const currentFloor = this.floormanager.floors.get( + this.floormanager.currentFloor + ); + + 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.outline(1, this.map.kp.BLACK), + this.map.kp.color(this.map.kp.Color.fromHex("303030")), + // this.map.kp.area(), + this.map.kp.pos(), + this.map.kp.z(5), + ]); + + const bounds = polygon.bbox(); + + this.map.camBounds = bounds; + + this.floorObject.onUpdate(() => { + const camScale = 1 / this.map.kp.camScale().y; + this.floorObject.outline.width = 8 * camScale; + }); + + this.floorObject.onDraw(() => { + const camScale = 1 / this.map.kp.camScale().y; + this.map.kp.drawText({ + text: currentFloor.name, + size: 24 * camScale, + pos: this.map.kp.vec2(-4 * camScale, -8 * camScale), + color: this.map.kp.WHITE, + anchor: "botleft", + }); + }); + + this.map.kp.add(this.floorObject); + + this.map.zoomToAbs(this.map.opts.minZoomLevel, bounds.center()); + } + + generateRooms() { + if (this.roomObjects.size > 0) { + this.roomObjects.forEach((x) => x.destroy()); + this.roomObjects.clear(); + } + + const currentRooms = this.floormanager.rooms.get( + this.floormanager.currentFloor + ); + + currentRooms.forEach((room) => { + const polygon = new this.map.kp.Polygon( + room.poly.map(([x, y]) => this.map.kp.vec2(x, y)) + ); + + const obj = this.map.kp.make([ + this.map.kp.polygon(polygon.pts), + this.map.kp.outline(1, this.map.kp.BLACK), + this.map.kp.color(this.map.kp.Color.fromHex("303030")), + this.map.kp.area(), + this.map.kp.pos(), + this.map.kp.z(6), + { + clickForgiveness: 1, + startClickPosition: null, + }, + ]); + + obj.onHover(() => { + obj.color = this.map.kp.Color.fromHex("505050"); + }); + + obj.onHoverEnd(() => { + obj.color = this.map.kp.Color.fromHex("303030"); + }); + + this.roomObjects.set(room.id, obj); + + obj.onUpdate(() => { + const camScale = 1 / this.map.kp.camScale().y; + obj.outline.width = 8 * camScale; + + if (this.map.kp.isMousePressed() && obj.isHovering()) { + obj.startClickPosition = this.map.kp.mousePos(); + obj.color = this.map.kp.Color.fromHex("202020"); + } + + if (this.map.kp.isMouseReleased() && obj.isHovering()) { + const endClickPosition = this.map.kp.mousePos(); + if ( + obj.startClickPosition && + obj.startClickPosition.dist(endClickPosition) < obj.clickForgiveness + ) { + this.currentRoom = room.id; + } + obj.color = this.map.kp.Color.fromHex("505050"); + this.map.clearMouseMode(); + } + }); + + obj.onDraw(() => { + const camScale = 1 / this.map.kp.camScale().y; + this.map.kp.drawText({ + text: room.name, + size: 24 * camScale, + pos: polygon.bbox().center(), + color: this.map.kp.WHITE, + anchor: "center", + }); + }); + + this.floorObject.add(obj); + }); + } +} diff --git a/assets/scripts/KaplayMap/index.js b/assets/scripts/KaplayMap/index.js index 888111a..c2db368 100644 --- a/assets/scripts/KaplayMap/index.js +++ b/assets/scripts/KaplayMap/index.js @@ -1,26 +1,27 @@ export class KaplayMap { kp; opts = { - minZoomLevel: 0, - maxZoomLevel: 3, + minZoomLevel: 2, + maxZoomLevel: 5, dblClickDuration: 0.2, // s dblClickForgiveness: 30, // px }; uiLayer; - #zoomLevel = 0; + #zoomLevel = this.opts.minZoomLevel; #scaleTween = null; startMousePos = null; startCamPos = null; startZoomLevel = null; prevCamPos = null; - moveVelocity = null; moveFriction = 0.25; moveDead = 1; #moveTween = null; + camBounds = null; + lastReleaseTime; lastReleasePos; lastPressTime; @@ -39,9 +40,8 @@ export class KaplayMap { ...opts, }; - this.uiLayer = this.initUI(); - - this.kp.add(this.uiLayer); + this.zoomLevel_NoTween = this.opts.minZoomLevel; + this.kp.camPos(0); this.kp.onScroll((delta) => { const scrollDist = -delta.y / 120; @@ -80,6 +80,10 @@ export class KaplayMap { this.fingers.delete(touch.identifier); + if (this.fingers.size < 1) { + this.checkBounds(); + } + if (this.fingers.size < 2) { const fingerArr = Array.from(this.fingers.values()); this.startFingerCenterPos = fingerArr[0]; @@ -118,26 +122,10 @@ export class KaplayMap { } }); - const size = 16; - this.kp.onDraw(() => { - this.fingers.forEach((pos) => { - this.kp.drawRect({ - width: size, - height: size, - pos: pos.sub(size / 2), - color: this.kp.RED, - fixed: true, - }); - }); - }); - this.kp.onUpdate(() => { const curCamPos = this.kp.camPos(); const camScale = 1 / this.kp.camScale().y; - // ||| Completely unintelligible to the average person ||| - // vvv Sorry y'all xwx vvv - if (this.kp.isMousePressed()) { // ignore if no double click if (this.lastPressTime != null && this.lastPressPos != null) { @@ -185,10 +173,9 @@ export class KaplayMap { this.lastReleaseTime = this.kp.time(); this.lastReleasePos = this.kp.mousePos(); - // if (this.prevCamPos != null) - // this.moveVelocity = this.prevCamPos - // .sub(curCamPos) - // .scale(1 / camScale); + // Check bounds + + this.checkBounds(); } if (this.kp.isMouseDown()) { @@ -208,52 +195,9 @@ export class KaplayMap { ); } } - - if ( - this.moveVelocity != null && - this.moveVelocity?.x != 0 && - this.moveVelocity?.y != 0 - ) - this.kp.camPos(curCamPos.sub(this.moveVelocity?.scale(camScale) ?? 0)); - - this.kp.camPos( - Math.round(this.kp.camPos().x * this.kp.camScale().y) / - this.kp.camScale().y, - Math.round(this.kp.camPos().y * this.kp.camScale().y) / - this.kp.camScale().y - ); - - // ^^^ Completely unintelligible to the average person ^^^ - // ||| Sorry y'all xwx ||| - - if (this.moveVelocity == null) return; - - if ( - this.moveVelocity.x <= this.moveDead && - this.moveVelocity.x >= -this.moveDead - ) - this.moveVelocity.x = 0; - if ( - this.moveVelocity.y <= this.moveDead && - this.moveVelocity.y >= -this.moveDead - ) - this.moveVelocity.y = 0; - - this.moveVelocity = this.moveVelocity.scale(1 - this.moveFriction); }); } - initUI() { - const uiLayer = this.kp.make([ - this.kp.pos(0), - this.kp.fixed(), - this.kp.stay(), - this.kp.z(1000), - ]); - - return uiLayer; - } - initGrid() { const grid = this.kp.loadSprite(null, "/assets/images/grid.png"); @@ -262,11 +206,12 @@ export class KaplayMap { sprite: grid, tiled: true, opacity: 0.25, - width: this.kp.width() + 100, - height: this.kp.height() + 100, + width: this.kp.width() + 200, + height: this.kp.height() + 200, + anchor: "center", pos: this.kp.vec2( - Math.floor(this.kp.camPos().x / 100) * 100 - this.kp.width() * 0.5, - Math.floor(this.kp.camPos().y / 100) * 100 - this.kp.height() * 0.5 + Math.floor(this.kp.camPos().x / 100) * 100 + 50.5, + Math.floor(this.kp.camPos().y / 100) * 100 + 0.5 ), }); }); @@ -282,6 +227,37 @@ export class KaplayMap { this.prevCamPos = null; } + checkBounds() { + const camPos = this.kp.camPos(); + + if (this.camBounds == null) return; + + if (this.kp.testRectPoint(this.camBounds, camPos)) return; + + const boundsCenter = this.camBounds.center(); + const cast = this.camBounds.raycast( + camPos, + this.kp.Vec2.fromAngle(camPos.angle(boundsCenter) + 180).scale(40000) + ); + + if (cast == null) return; + + if (this.#moveTween != null) { + this.#moveTween.finish(); + } + + this.#moveTween = this.kp.tween( + camPos, + cast.point, + 0.25, + this.kp.camPos, + this.kp.easings.easeOutQuad + ); + this.#moveTween.then(() => { + this.#moveTween = null; + }); + } + get zoomLevelLimit() { if (this.#zoomLevel == this.opts.minZoomLevel) return -1; if (this.#zoomLevel == this.opts.maxZoomLevel) return 1; @@ -342,8 +318,8 @@ export class KaplayMap { const newDiff = this.kp.center().sub(position).scale(newZoomLog); - if (newZoom <= this.opts.minZoomLevel) return; - if (newZoom >= this.opts.maxZoomLevel) return; + if (newZoom < this.opts.minZoomLevel) return; + if (newZoom > this.opts.maxZoomLevel) return; if (this.#moveTween != null) { this.#moveTween.finish(); @@ -358,6 +334,29 @@ export class KaplayMap { ); this.#moveTween.then(() => { this.#moveTween = null; + this.checkBounds(); + }); + } + + zoomToAbs(newZoom, position) { + const curCamPos = this.kp.camPos(); + + this.zoomLevel = newZoom; + + if (this.#moveTween != null) { + this.#moveTween.finish(); + } + + this.#moveTween = this.kp.tween( + curCamPos, + position, + 0.25, + this.kp.camPos, + this.kp.easings.easeOutQuad + ); + this.#moveTween.then(() => { + this.#moveTween = null; + this.checkBounds(); }); } @@ -372,14 +371,16 @@ export class KaplayMap { const newDiff = this.kp.center().sub(position).scale(newZoomLog); - if (newZoom <= this.opts.minZoomLevel) return; - if (newZoom >= this.opts.maxZoomLevel) return; + if (newZoom < this.opts.minZoomLevel) return; + if (newZoom > this.opts.maxZoomLevel) return; this.kp.camPos(curCamPos.sub(diff).add(newDiff)); + this.checkBounds(); } zoomToNoTweenAbs(newZoom, position) { this.zoomLevel_NoTween = newZoom; this.kp.camPos(position); + this.checkBounds(); } } diff --git a/assets/scripts/KaplayMap/ui.js b/assets/scripts/KaplayMap/ui.js new file mode 100644 index 0000000..7fbc210 --- /dev/null +++ b/assets/scripts/KaplayMap/ui.js @@ -0,0 +1,158 @@ +export class UIManager { + ui; + map; + floormanager; + eventmanager; + + uiElements = {}; + floorsEmpty = true; + eventsEmpty = true; + + constructor(ui, map) { + this.ui = ui; + this.map = map; + + // Zoom + this.uiElements.zoomButtons = this.ui.querySelector("#zoom"); + this.uiElements.zoomIn = + this.uiElements.zoomButtons.querySelector("#zoom-in"); + this.uiElements.zoomOut = + this.uiElements.zoomButtons.querySelector("#zoom-out"); + + // Floors + this.uiElements.floors = this.ui.querySelector("#floors"); + this.uiElements.floorButtons = + this.uiElements.floors.querySelector("#floor-buttons"); + + // Events + this.uiElements.eventsContainer = + this.ui.querySelector("#events-container"); + this.uiElements.events = + this.uiElements.eventsContainer.querySelector("#events"); + this.uiElements.eventList = + this.uiElements.events.querySelector("#event-list"); + this.uiElements.eventsMinimized = + this.uiElements.eventsContainer.querySelector("#events-minimized"); + + // Loading + this.uiElements.loading = this.ui.querySelector("#loading"); + + // Zoom buttons + this.__initZoom(); + + this.__initEvents(); + } + + __initZoom() { + this.uiElements.zoomIn.addEventListener("click", () => { + this.map.zoomLevel += 1; + }); + this.uiElements.zoomOut.addEventListener("click", () => { + this.map.zoomLevel -= 1; + }); + this.map.kp.onUpdate(() => { + if (this.map.zoomLevelLimit > 0) { + this.uiElements.zoomIn.disabled = true; + this.uiElements.zoomOut.disabled = false; + } else if (this.map.zoomLevelLimit < 0) { + this.uiElements.zoomIn.disabled = false; + this.uiElements.zoomOut.disabled = true; + } else { + this.uiElements.zoomIn.disabled = false; + this.uiElements.zoomOut.disabled = false; + } + }); + } + + __initEvents() { + const minimizeButton = this.uiElements.events.querySelector( + "#footer #footer-buttons #minimize" + ); + minimizeButton.addEventListener("click", () => { + this.uiElements.eventsContainer.classList.add("minimized"); + }); + const maximizeButton = + this.uiElements.eventsMinimized.querySelector("#maximize"); + maximizeButton.addEventListener("click", () => { + this.uiElements.eventsContainer.classList.remove("minimized"); + }); + } + + __updateEvents() { + // Remove all children + this.uiElements.eventList.replaceChildren(); + + console.log(this.eventmanager.events); + // Put them back + this.eventmanager.events.forEach((event, id) => { + const eventListContainer = document.createElement("details"); + eventListContainer.classList.add("event-list-container"); + eventListContainer.id = "event-" + id; + + const eventListContainerSummary = document.createElement("summary"); + eventListContainerSummary.textContent = event.name; + + eventListContainer.appendChild(eventListContainerSummary); + + const eventListContainerDescription = document.createElement("p"); + eventListContainerDescription.textContent = event.description; + + eventListContainer.appendChild(eventListContainerDescription); + + this.uiElements.eventList.appendChild(eventListContainer); + }); + + if (this.eventmanager.events.size < 1) { + this.uiElements.eventList.classList.add("empty"); + this.eventsEmpty = true; + } else { + this.uiElements.eventList.classList.remove("empty"); + this.eventsEmpty = false; + } + } + + setLoading(state) { + if (state) { + this.ui.classList.add("loading"); + } else { + this.ui.classList.remove("loading"); + } + } + + __updateFloorsHard() { + // Remove all children + this.uiElements.floorButtons.replaceChildren(); + + // Put them back + this.floormanager.floors.forEach(({ name }, id) => { + const floorButton = document.createElement("button"); + floorButton.textContent = name; + floorButton.classList.add("floor-button"); + floorButton.id = "floor-" + id; + if (id === this.floormanager.currentFloor) + floorButton.classList.add("selected"); + floorButton.addEventListener("click", () => + this.floormanager.changeFloor(id) + ); + + this.uiElements.floorButtons.appendChild(floorButton); + }); + + if (this.floormanager.floors.size < 1) { + this.uiElements.floors.classList.add("empty"); + this.floorsEmpty = true; + } else { + this.uiElements.floors.classList.remove("empty"); + this.floorsEmpty = false; + } + } + + __updateFloorsSoft() { + this.floormanager.floors.forEach(({ name }, id) => { + const child = this.uiElements.floorButtons.querySelector("#floor-" + id); + if (id === this.floormanager.currentFloor) + child.classList.add("selected"); + else child.classList.remove("selected"); + }); + } +} diff --git a/assets/scripts/KaplayMap/zoom.js b/assets/scripts/KaplayMap/zoom.js deleted file mode 100644 index 0b4404e..0000000 --- a/assets/scripts/KaplayMap/zoom.js +++ /dev/null @@ -1,60 +0,0 @@ -export function addZoomButtons(map) { - // Zoom buttons - const plus = map.kp.loadSprite(null, "/assets/images/plus.png", { - sliceX: 2, - }); - - const minus = map.kp.loadSprite(null, "/assets/images/minus.png", { - sliceX: 2, - }); - - const zoomIn = map.kp.make([ - map.kp.sprite(plus), - map.kp.pos(16), - map.kp.scale(2), - map.kp.area(), - map.kp.opacity(1), - "ui", - ]); - const zoomOut = map.kp.make([ - map.kp.sprite(minus), - map.kp.pos(16, 42), - map.kp.scale(2), - map.kp.area(), - map.kp.opacity(1), - "ui", - ]); - - let ziw; - zoomIn.onClick(() => { - map.mouseMode = "ui"; - map.zoomLevel += 1; - zoomIn.frame = 1; - if (ziw?.finish) ziw.finish(); - ziw = map.kp.wait(0.25, () => (zoomIn.frame = 0)); - - map.clearMouseMode(); - }); - - zoomIn.onUpdate(() => { - zoomIn.opacity = map.zoomLevelLimit > 0 ? 0.25 : 1; - }); - - let zow; - zoomOut.onClick(() => { - map.mouseMode = "ui"; - map.zoomLevel -= 1; - zoomOut.frame = 1; - if (zow?.finish) zow.finish(); - zow = map.kp.wait(0.25, () => (zoomOut.frame = 0)); - - map.clearMouseMode(); - }); - - zoomOut.onUpdate(() => { - zoomOut.opacity = map.zoomLevelLimit < 0 ? 0.25 : 1; - }); - - map.uiLayer.add(zoomIn); - map.uiLayer.add(zoomOut); -} diff --git a/assets/scripts/modules/kaplay.js b/assets/scripts/modules/kaplay.js index 2546432..e0c91bf 100644 --- a/assets/scripts/modules/kaplay.js +++ b/assets/scripts/modules/kaplay.js @@ -1,119 +1,125 @@ var kaplay = (() => { - var Yt = Object.defineProperty; - var xi = Object.getOwnPropertyDescriptor; - var Ui = Object.getOwnPropertyNames; - var Ei = Object.prototype.hasOwnProperty; - var o = (n, e) => Yt(n, "name", { value: e, configurable: !0 }); - var Si = (n, e) => { - for (var i in e) Yt(n, i, { get: e[i], enumerable: !0 }); + 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 }); }, - Ci = (n, e, i, c) => { + fi = (t, e, r, s) => { if ((e && typeof e == "object") || typeof e == "function") - for (let m of Ui(e)) - !Ei.call(n, m) && - m !== i && - Yt(n, m, { - get: () => e[m], - enumerable: !(c = xi(e, m)) || c.enumerable, + 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 n; + return t; }; - var Ai = (n) => Ci(Yt({}, "__esModule", { value: !0 }), n); - var wr = (() => { - for (var n = new Uint8Array(128), e = 0; e < 64; e++) - n[e < 26 ? e + 65 : e < 52 ? e + 71 : e < 62 ? e - 4 : e * 4 - 205] = e; - return (i) => { + 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 c = i.length, - m = new Uint8Array( - (((c - (i[c - 1] == "=") - (i[c - 2] == "=")) * 3) / 4) | 0 + var s = r.length, + a = new Uint8Array( + (((s - (r[s - 1] == "=") - (r[s - 2] == "=")) * 3) / 4) | 0 ), - p = 0, - P = 0; - p < c; + l = 0, + u = 0; + l < s; ) { - var I = n[i.charCodeAt(p++)], - j = n[i.charCodeAt(p++)], - y = n[i.charCodeAt(p++)], - X = n[i.charCodeAt(p++)]; - (m[P++] = (I << 2) | (j >> 4)), - (m[P++] = (j << 4) | (y >> 2)), - (m[P++] = (y << 6) | X); + 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 m; + return a; }; })(); - var uo = {}; - Si(uo, { default: () => ao }); - function Ge(n) { - return (n * Math.PI) / 180; + var aa = {}; + pi(aa, { + anchorPt: () => ht, + default: () => ia, + getInternalContext: () => fe, + getKaboomContext: () => J, + isKaboomCtx: () => as, + }); + function ve(t) { + return (t * Math.PI) / 180; } - o(Ge, "deg2rad"); - function ot(n) { - return (n * 180) / Math.PI; + i(ve, "deg2rad"); + function lt(t) { + return (t * 180) / Math.PI; } - o(ot, "rad2deg"); - function Le(n, e, i) { - return e > i ? Le(n, i, e) : Math.min(Math.max(n, e), i); + i(lt, "rad2deg"); + function Qe(t, e, r) { + return e > r ? Qe(t, r, e) : Math.min(Math.max(t, e), r); } - o(Le, "clamp"); - function Ve(n, e, i) { - if (typeof n == "number" && typeof e == "number") return n + (e - n) * i; - if (n instanceof v && e instanceof v) return n.lerp(e, i); - if (n instanceof W && e instanceof W) return n.lerp(e, i); + 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(): ${n}, ${e}. Only number, Vec2 and Color is supported.` + `Bad value for lerp(): ${t}, ${e}. Only number, Vec2 and Color is supported.` ); } - o(Ve, "lerp"); - function _e(n, e, i, c, m) { - return c + ((n - e) / (i - e)) * (m - c); + i(Je, "lerp"); + function dt(t, e, r, s, a) { + return s + ((t - e) / (r - e)) * (a - s); } - o(_e, "map"); - function vr(n, e, i, c, m) { - return Le(_e(n, e, i, c, m), c, m); + i(dt, "map"); + function Ir(t, e, r, s, a) { + return Qe(dt(t, e, r, s, a), s, a); } - o(vr, "mapc"); - var v = class n { + i(Ir, "mapc"); + var T = class t { static { - o(this, "Vec2"); + i(this, "Vec2"); } x = 0; y = 0; - constructor(e = 0, i = e) { - (this.x = e), (this.y = i); + constructor(e = 0, r = e) { + (this.x = e), (this.y = r); } static fromAngle(e) { - let i = Ge(e); - return new n(Math.cos(i), Math.sin(i)); + let r = ve(e); + return new t(Math.cos(r), Math.sin(r)); } - static LEFT = new n(-1, 0); - static RIGHT = new n(1, 0); - static UP = new n(0, -1); - static DOWN = new n(0, 1); + 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 n(this.x, this.y); + return new t(this.x, this.y); } add(...e) { - let i = T(...e); - return new n(this.x + i.x, this.y + i.y); + let r = C(...e); + return new t(this.x + r.x, this.y + r.y); } sub(...e) { - let i = T(...e); - return new n(this.x - i.x, this.y - i.y); + let r = C(...e); + return new t(this.x - r.x, this.y - r.y); } scale(...e) { - let i = T(...e); - return new n(this.x * i.x, this.y * i.y); + let r = C(...e); + return new t(this.x * r.x, this.y * r.y); } dist(...e) { - let i = T(...e); - return this.sub(i).len(); + let r = C(...e); + return this.sub(r).len(); } sdist(...e) { - let i = T(...e); - return this.sub(i).slen(); + let r = C(...e); + return this.sub(r).slen(); } len() { return Math.sqrt(this.dot(this)); @@ -123,10 +129,10 @@ var kaplay = (() => { } unit() { let e = this.len(); - return e === 0 ? new n(0) : this.scale(1 / e); + return e === 0 ? new t(0) : this.scale(1 / e); } normal() { - return new n(this.y, -this.x); + return new t(this.y, -this.x); } reflect(e) { return this.sub(e.scale(2 * this.dot(e))); @@ -144,29 +150,29 @@ var kaplay = (() => { return this.x * e.y - this.y * e.x; } angle(...e) { - let i = T(...e); - return ot(Math.atan2(this.y - i.y, this.x - i.x)); + let r = C(...e); + return lt(Math.atan2(this.y - r.y, this.x - r.x)); } angleBetween(...e) { - let i = T(...e); - return ot(Math.atan2(this.cross(i), this.dot(i))); + let r = C(...e); + return lt(Math.atan2(this.cross(r), this.dot(r))); } - lerp(e, i) { - return new n(Ve(this.x, e.x, i), Ve(this.y, e.y, i)); + lerp(e, r) { + return new t(Je(this.x, e.x, r), Je(this.y, e.y, r)); } - slerp(e, i) { - let c = this.dot(e), - m = this.cross(e), - p = Math.atan2(m, c); - return this.scale(Math.sin((1 - i) * p)) - .add(e.scale(Math.sin(i * p))) - .scale(1 / m); + 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 n(Number(this.x.toFixed(e)), Number(this.y.toFixed(e))); + return new t(Number(this.x.toFixed(e)), Number(this.y.toFixed(e))); } transform(e) { return e.multVec2(this); @@ -175,130 +181,130 @@ var kaplay = (() => { return this.x === e.x && this.y === e.y; } bbox() { - return new de(this, 0, 0); + return new ue(this, 0, 0); } toString() { return `vec2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`; } }; - function T(...n) { - if (n.length === 1) { - if (n[0] instanceof v) return new v(n[0].x, n[0].y); - if (Array.isArray(n[0]) && n[0].length === 2) return new v(...n[0]); + 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 v(...n); + return new T(...t); } - o(T, "vec2"); - var W = class n { + i(C, "vec2"); + var ee = class t { static { - o(this, "Color"); + i(this, "Color"); } r = 255; g = 255; b = 255; - constructor(e, i, c) { - (this.r = Le(e, 0, 255)), - (this.g = Le(i, 0, 255)), - (this.b = Le(c, 0, 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 n(e[0], e[1], e[2]); + return new t(e[0], e[1], e[2]); } static fromHex(e) { if (typeof e == "number") - return new n((e >> 16) & 255, (e >> 8) & 255, (e >> 0) & 255); + return new t((e >> 16) & 255, (e >> 8) & 255, (e >> 0) & 255); if (typeof e == "string") { - let i = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e); - return new n( - parseInt(i[1], 16), - parseInt(i[2], 16), - parseInt(i[3], 16) + 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, i, c) { - if (i == 0) return new n(255 * c, 255 * c, 255 * c); - let m = o( - (X, S, q) => ( - q < 0 && (q += 1), - q > 1 && (q -= 1), - q < 1 / 6 - ? X + (S - X) * 6 * q - : q < 1 / 2 - ? S - : q < 2 / 3 - ? X + (S - X) * (2 / 3 - q) * 6 - : X + 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" ), - p = c < 0.5 ? c * (1 + i) : c + i - c * i, - P = 2 * c - p, - I = m(P, p, e + 1 / 3), - j = m(P, p, e), - y = m(P, p, e - 1 / 3); - return new n( - Math.round(I * 255), - Math.round(j * 255), - Math.round(y * 255) + 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); + return new t( + Math.round(f * 255), + Math.round(y * 255), + Math.round(m * 255) ); } - static RED = new n(255, 0, 0); - static GREEN = new n(0, 255, 0); - static BLUE = new n(0, 0, 255); - static YELLOW = new n(255, 255, 0); - static MAGENTA = new n(255, 0, 255); - static CYAN = new n(0, 255, 255); - static WHITE = new n(255, 255, 255); - static BLACK = new n(0, 0, 0); + 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 n(this.r, this.g, this.b); + return new t(this.r, this.g, this.b); } lighten(e) { - return new n(this.r + e, this.g + e, this.b + e); + return new t(this.r + e, this.g + e, this.b + e); } darken(e) { return this.lighten(-e); } invert() { - return new n(255 - this.r, 255 - this.g, 255 - this.b); + return new t(255 - this.r, 255 - this.g, 255 - this.b); } mult(e) { - return new n( + return new t( (this.r * e.r) / 255, (this.g * e.g) / 255, (this.b * e.b) / 255 ); } - lerp(e, i) { - return new n(Ve(this.r, e.r, i), Ve(this.g, e.g, i), Ve(this.b, e.b, i)); + 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, - i = this.g / 255, - c = this.b / 255, - m = Math.max(e, i, c), - p = Math.min(e, i, c), - P = (m + p) / 2, - I = P, - j = P; - if (m == p) P = I = 0; + 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 y = m - p; - switch (((I = j > 0.5 ? y / (2 - m - p) : y / (m + p)), m)) { + let m = a - l; + switch (((f = y > 0.5 ? m / (2 - a - l) : m / (a + l)), a)) { case e: - P = (i - c) / y + (i < c ? 6 : 0); + u = (r - s) / m + (r < s ? 6 : 0); break; - case i: - P = (c - e) / y + 2; + case r: + u = (s - e) / m + 2; break; - case c: - P = (e - i) / y + 4; + case s: + u = (e - r) / m + 4; break; } - P /= 6; + u /= 6; } - return [P, I, j]; + return [u, f, y]; } eq(e) { return this.r === e.r && this.g === e.g && this.b === e.b; @@ -314,31 +320,34 @@ var kaplay = (() => { .slice(1) ); } - }; - function J(...n) { - if (n.length === 0) return new W(255, 255, 255); - if (n.length === 1) { - if (n[0] instanceof W) return n[0].clone(); - if (typeof n[0] == "string") return W.fromHex(n[0]); - if (Array.isArray(n[0]) && n[0].length === 3) return W.fromArray(n[0]); + toArray() { + return [this.r, this.g, this.b]; } - return new W(...n); + }; + 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); } - o(J, "rgb"); - var yr = o((n, e, i) => W.fromHSL(n, e, i), "hsl2rgb"), - oe = class n { + i(oe, "rgb"); + var Lr = i((t, e, r) => ee.fromHSL(t, e, r), "hsl2rgb"), + me = class t { static { - o(this, "Quad"); + i(this, "Quad"); } x = 0; y = 0; w = 1; h = 1; - constructor(e, i, c, m) { - (this.x = e), (this.y = i), (this.w = c), (this.h = m); + constructor(e, r, s, a) { + (this.x = e), (this.y = r), (this.w = s), (this.h = a); } scale(e) { - return new n( + return new t( this.x + this.w * e.x, this.y + this.h * e.y, this.w * e.w, @@ -346,10 +355,10 @@ var kaplay = (() => { ); } pos() { - return new v(this.x, this.y); + return new T(this.x, this.y); } clone() { - return new n(this.x, this.y, this.w, this.h); + return new t(this.x, this.y, this.w, this.h); } eq(e) { return ( @@ -360,408 +369,1050 @@ var kaplay = (() => { return `quad(${this.x}, ${this.y}, ${this.w}, ${this.h})`; } }; - function ce(n, e, i, c) { - return new oe(n, e, i, c); + function pe(t, e, r, s) { + return new me(t, e, r, s); } - o(ce, "quad"); - var Ue = class n { + i(pe, "quad"); + var Ot = class t { static { - o(this, "Mat4"); + i(this, "Mat2"); } - m = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; - constructor(e) { - e && (this.m = e); + a; + b; + c; + d; + constructor(e, r, s, a) { + (this.a = e), (this.b = r), (this.c = s), (this.d = a); } - static translate(e) { - return new n([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, e.x, e.y, 0, 1]); - } - static scale(e) { - return new n([e.x, 0, 0, 0, 0, e.y, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); - } - static rotateX(e) { - e = Ge(-e); - let i = Math.cos(e), - c = Math.sin(e); - return new n([1, 0, 0, 0, 0, i, -c, 0, 0, c, i, 0, 0, 0, 0, 1]); - } - static rotateY(e) { - e = Ge(-e); - let i = Math.cos(e), - c = Math.sin(e); - return new n([i, 0, c, 0, 0, 1, 0, 0, -c, 0, i, 0, 0, 0, 0, 1]); - } - static rotateZ(e) { - e = Ge(-e); - let i = Math.cos(e), - c = Math.sin(e); - return new n([i, -c, 0, 0, c, i, 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 + 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 ); } - 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 - ); + transform(e) { + return C(this.a * e.x + this.b * e.y, this.c * e.x + this.d * e.y); } - rotate(e) { - e = Ge(-e); - let i = Math.cos(e), - c = Math.sin(e), - m = this.m[0], - p = this.m[1], - P = this.m[4], - I = this.m[5]; - return ( - (this.m[0] = m * i + p * c), - (this.m[1] = -m * c + p * i), - (this.m[4] = P * i + I * c), - (this.m[5] = -P * c + I * i), - this - ); + get inverse() { + let e = this.det; + return new t(this.d / e, -this.b / e, -this.c / e, this.a / e); } - mult(e) { - let i = []; - for (let c = 0; c < 4; c++) - for (let m = 0; m < 4; m++) - i[c * 4 + m] = - this.m[0 * 4 + m] * e.m[c * 4 + 0] + - this.m[1 * 4 + m] * e.m[c * 4 + 1] + - this.m[2 * 4 + m] * e.m[c * 4 + 2] + - this.m[3 * 4 + m] * e.m[c * 4 + 3]; - return new n(i); + get transpose() { + return new t(this.a, this.c, this.b, this.d); } - multVec2(e) { - return new v( - 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] - ); + 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]; } - getTranslation() { - return new v(this.m[12], this.m[13]); + 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], + ]; } - getScale() { - if (this.m[0] != 0 || this.m[1] != 0) { - let e = this.m[0] * this.m[5] - this.m[1] * this.m[4], - i = Math.sqrt(this.m[0] * this.m[0] + this.m[1] * this.m[1]); - return new v(i, e / i); - } else if (this.m[4] != 0 || this.m[5] != 0) { - let e = this.m[0] * this.m[5] - this.m[1] * this.m[4], - i = Math.sqrt(this.m[4] * this.m[4] + this.m[5] * this.m[5]); - return new v(e / i, i); - } else return new v(0, 0); + get det() { + return this.a * this.d - this.b * this.c; } - 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 ot( - 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 ot( - Math.PI / 2 - - (this.m[5] > 0 - ? Math.acos(-this.m[4] / e) - : -Math.acos(this.m[4] / e)) - ); - } else return 0; + get trace() { + return this.a + this.d; } - 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 v( - 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 v( - 0, - Math.atan(this.m[0] * this.m[4] + this.m[1] * this.m[5]) / (e * e) - ); - } else return new v(0, 0); + static rotation(e) { + let r = Math.cos(e), + s = Math.sin(e); + return new t(r, s, -s, r); } - invert() { - let e = [], - i = this.m[10] * this.m[15] - this.m[14] * this.m[11], - c = this.m[9] * this.m[15] - this.m[13] * this.m[11], - m = this.m[9] * this.m[14] - this.m[13] * this.m[10], - p = this.m[8] * this.m[15] - this.m[12] * this.m[11], - P = this.m[8] * this.m[14] - this.m[12] * this.m[10], - I = this.m[8] * this.m[13] - this.m[12] * this.m[9], - j = this.m[6] * this.m[15] - this.m[14] * this.m[7], - y = this.m[5] * this.m[15] - this.m[13] * this.m[7], - X = this.m[5] * this.m[14] - this.m[13] * this.m[6], - S = this.m[4] * this.m[15] - this.m[12] * this.m[7], - q = this.m[4] * this.m[14] - this.m[12] * this.m[6], - E = 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], - Q = this.m[6] * this.m[11] - this.m[10] * this.m[7], - te = this.m[5] * this.m[11] - this.m[9] * this.m[7], - k = this.m[5] * this.m[10] - this.m[9] * this.m[6], - pe = this.m[4] * this.m[11] - this.m[8] * this.m[7], - C = this.m[4] * this.m[10] - this.m[8] * this.m[6], - Ae = this.m[4] * this.m[9] - this.m[8] * this.m[5]; - (e[0] = this.m[5] * i - this.m[6] * c + this.m[7] * m), - (e[4] = -(this.m[4] * i - this.m[6] * p + this.m[7] * P)), - (e[8] = this.m[4] * c - this.m[5] * p + this.m[7] * I), - (e[12] = -(this.m[4] * m - this.m[5] * P + this.m[6] * I)), - (e[1] = -(this.m[1] * i - this.m[2] * c + this.m[3] * m)), - (e[5] = this.m[0] * i - this.m[2] * p + this.m[3] * P), - (e[9] = -(this.m[0] * c - this.m[1] * p + this.m[3] * I)), - (e[13] = this.m[0] * m - this.m[1] * P + this.m[2] * I), - (e[2] = this.m[1] * j - this.m[2] * y + this.m[3] * X), - (e[6] = -(this.m[0] * j - this.m[2] * S + this.m[3] * q)), - (e[10] = this.m[0] * E - this.m[1] * S + this.m[3] * K), - (e[14] = -(this.m[0] * X - this.m[1] * q + this.m[2] * K)), - (e[3] = -(this.m[1] * Q - this.m[2] * te + this.m[3] * k)), - (e[7] = this.m[0] * Q - this.m[2] * pe + this.m[3] * C), - (e[11] = -(this.m[0] * te - this.m[1] * pe + this.m[3] * Ae)), - (e[15] = this.m[0] * k - this.m[1] * C + this.m[2] * Ae); - let $ = - this.m[0] * e[0] + - this.m[1] * e[4] + - this.m[2] * e[8] + - this.m[3] * e[12]; - for (let Te = 0; Te < 4; Te++) - for (let ye = 0; ye < 4; ye++) e[Te * 4 + ye] *= 1 / $; - return new n(e); - } - clone() { - return new n([...this.m]); - } - toString() { - return this.m.toString(); + static scale(e, r) { + return new t(e, 0, 0, r); } }; - function Ln(n, e, i, c = (m) => -Math.cos(m)) { - return n + ((c(i) + 1) / 2) * (e - n); - } - o(Ln, "wave"); - var Ti = 1103515245, - Oi = 12345, - br = 2147483648, - bt = class { + var bt = class t { static { - o(this, "RNG"); + 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 = (Ti * this.seed + Oi) % br), this.seed / br; + return (this.seed = (bi * this.seed + vi) % Fr), this.seed / Fr; } - genNumber(e, i) { - return e + this.gen() * (i - e); + genNumber(e, r) { + return e + this.gen() * (r - e); } - genVec2(e, i) { - return new v(this.genNumber(e.x, i.x), this.genNumber(e.y, i.y)); + genVec2(e, r) { + return new T(this.genNumber(e.x, r.x), this.genNumber(e.y, r.y)); } - genColor(e, i) { - return new W( - this.genNumber(e.r, i.r), - this.genNumber(e.g, i.g), - this.genNumber(e.b, i.b) + 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 v) return this.genVec2(T(0, 0), e[0]); - if (e[0] instanceof W) return this.genColor(J(0, 0, 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 v && e[1] instanceof v) + if (e[0] instanceof T && e[1] instanceof T) return this.genVec2(e[0], e[1]); - if (e[0] instanceof W && e[1] instanceof W) + if (e[0] instanceof ee && e[1] instanceof ee) return this.genColor(e[0], e[1]); } } }, - Fn = new bt(Date.now()); - function xr(n) { - return n != null && (Fn.seed = n), Fn.seed; + zn = new It(Date.now()); + function jr(t) { + return t != null && (zn.seed = t), zn.seed; } - o(xr, "randSeed"); - function xt(...n) { - return Fn.genAny(...n); + i(jr, "randSeed"); + function Lt(...t) { + return zn.genAny(...t); } - o(xt, "rand"); - function Vn(...n) { - return Math.floor(xt(...n)); + i(Lt, "rand"); + function Xn(...t) { + return Math.floor(Lt(...t)); } - o(Vn, "randi"); - function Ur(n) { - return xt() <= n; + i(Xn, "randi"); + function kr(t) { + return Lt() <= t; } - o(Ur, "chance"); - function Er(n) { - return n[Vn(n.length)]; + 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]]; + } + return t; } - o(Er, "choose"); - function Sr(n, e) { + i(Wn, "shuffle"); + function Nr(t, e) { + return t.length <= e ? t.slice() : Wn(t.slice()).slice(0, e); + } + i(Nr, "chooseMultiple"); + function _r(t) { + return t[Xn(t.length)]; + } + i(_r, "choose"); + function $n(t, e) { return ( - n.pos.x + n.width > e.pos.x && - n.pos.x < e.pos.x + e.width && - n.pos.y + n.height > e.pos.y && - n.pos.y < e.pos.y + e.height + 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 ); } - o(Sr, "testRectRect"); - function Ri(n, e) { + i($n, "testRectRect"); + function xi(t, e) { if ( - (n.p1.x === n.p2.x && n.p1.y === n.p2.y) || + (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 i = - (e.p2.y - e.p1.y) * (n.p2.x - n.p1.x) - - (e.p2.x - e.p1.x) * (n.p2.y - n.p1.y); - if (i === 0) return null; - let c = - ((e.p2.x - e.p1.x) * (n.p1.y - e.p1.y) - - (e.p2.y - e.p1.y) * (n.p1.x - e.p1.x)) / - i, - m = - ((n.p2.x - n.p1.x) * (n.p1.y - e.p1.y) - - (n.p2.y - n.p1.y) * (n.p1.x - e.p1.x)) / - i; - return c < 0 || c > 1 || m < 0 || m > 1 ? null : c; + 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; } - o(Ri, "testLineLineT"); - function it(n, e) { - let i = Ri(n, e); - return i - ? T(n.p1.x + i * (n.p2.x - n.p1.x), n.p1.y + i * (n.p2.y - n.p1.y)) + 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; } - o(it, "testLineLine"); - function Cr(n, e) { - if (vt(n, e.p1) || vt(n, e.p2)) return !0; - let i = n.points(); + 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 ( - !!it(e, new Ie(i[0], i[1])) || - !!it(e, new Ie(i[1], i[2])) || - !!it(e, new Ie(i[2], i[3])) || - !!it(e, new Ie(i[3], i[0])) + e.x > t.pos.x && + e.x < t.pos.x + t.width && + e.y > t.pos.y && + e.y < t.pos.y + t.height ); } - o(Cr, "testRectLine"); - function vt(n, e) { - return ( - e.x > n.pos.x && - e.x < n.pos.x + n.width && - e.y > n.pos.y && - e.y < n.pos.y + n.height - ); + 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; } - o(vt, "testRectPoint"); - function Ar(n, e) { - let i = e.sub(n.p1), - c = n.p2.sub(n.p1); - if (Math.abs(i.cross(c)) > Number.EPSILON) return !1; - let m = i.dot(c) / c.dot(c); - return m >= 0 && m <= 1; + i(Hr, "testRectCircle"); + function Kr(t, e) { + return qr(e, new Oe(t.points())); } - o(Ar, "testLinePoint"); - function _n(n, e) { - let i = n.p2.sub(n.p1), - c = i.dot(i), - m = n.p1.sub(e.center), - p = 2 * i.dot(m), - P = m.dot(m) - e.radius * e.radius, - I = p * p - 4 * c * P; - if (c <= Number.EPSILON || I < 0) return !1; - if (I == 0) { - let j = -p / (2 * c); - if (j >= 0 && j <= 1) return !0; + 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 j = (-p + Math.sqrt(I)) / (2 * c), - y = (-p - Math.sqrt(I)) / (2 * c); - if ((j >= 0 && j <= 1) || (y >= 0 && y <= 1)) return !0; + 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 Tr(e, n.p1); + return er(e, t.p1); } - o(_n, "testLineCircle"); - function Tr(n, e) { - return n.center.sdist(e) < n.radius * n.radius; - } - o(Tr, "testCirclePoint"); - function Or(n, e) { - let i = e.pts[e.pts.length - 1]; - for (let c of e.pts) { - if (_n(new Ie(i, c), n)) return !0; - i = c; + 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 Tr(n, e.pts[0]) ? !0 : kn(e, n.center); + return !1; } - o(Or, "testCirclePolygon"); - function kn(n, e) { - let i = !1, - c = n.pts; - for (let m = 0, p = c.length - 1; m < c.length; p = m++) - c[m].y > e.y != c[p].y > e.y && + 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 < - ((c[p].x - c[m].x) * (e.y - c[m].y)) / (c[p].y - c[m].y) + c[m].x && - (i = !i); - return i; + ((s[l].x - s[a].x) * (e.y - s[a].y)) / (s[l].y - s[a].y) + s[a].x && + (r = !r); + return r; } - o(kn, "testPolygonPoint"); - var Ie = class n { + 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); + } + } + i(wi, "testEllipseEllipse"); + function Xr(t, e) { + return tr(t, new Oe(e.points())); + } + 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 { - o(this, "Line"); + i(this, "Line"); } p1; p2; - constructor(e, i) { - (this.p1 = e.clone()), (this.p2 = i.clone()); + constructor(e, r) { + (this.p1 = e.clone()), (this.p2 = r.clone()); } transform(e) { - return new n(e.multVec2(this.p1), e.multVec2(this.p2)); + return new t(e.multVec2(this.p1), e.multVec2(this.p2)); } bbox() { - return de.fromPoints(this.p1, this.p2); + return ue.fromPoints(this.p1, this.p2); } area() { return this.p1.dist(this.p2); } clone() { - return new n(this.p1, this.p2); + 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); } }, - de = class n { + ue = class t { static { - o(this, "Rect"); + i(this, "Rect"); } pos; width; height; - constructor(e, i, c) { - (this.pos = e.clone()), (this.width = i), (this.height = c); + constructor(e, r, s) { + (this.pos = e.clone()), (this.width = r), (this.height = s); } - static fromPoints(e, i) { - return new n(e.clone(), i.x - e.x, i.y - e.y); + static fromPoints(e, r) { + return new t(e.clone(), r.x - e.x, r.y - e.y); } center() { - return new v(this.pos.x + this.width / 2, this.pos.y + this.height / 2); + return new T(this.pos.x + this.width / 2, this.pos.y + this.height / 2); } points() { return [ @@ -772,7 +1423,7 @@ var kaplay = (() => { ]; } transform(e) { - return new Ke(this.points().map((i) => e.multVec2(i))); + return new Oe(this.points().map((r) => e.multVec2(r))); } bbox() { return this.clone(); @@ -781,77 +1432,164 @@ var kaplay = (() => { return this.width * this.height; } clone() { - return new n(this.pos.clone(), this.width, this.height); + return new t(this.pos.clone(), this.width, this.height); } distToPoint(e) { return Math.sqrt(this.sdistToPoint(e)); } sdistToPoint(e) { - let i = this.pos, - c = this.pos.add(this.width, this.height), - m = Math.max(i.x - e.x, 0, e.x - c.x), - p = Math.max(i.y - e.y, 0, e.y - c.y); - return m * m + p * p; + 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); } }, - yt = class n { + Fe = class t { static { - o(this, "Circle"); + i(this, "Circle"); } center; radius; - constructor(e, i) { - (this.center = e.clone()), (this.radius = i); + constructor(e, r) { + (this.center = e.clone()), (this.radius = r); } transform(e) { - return new In(this.center, this.radius, this.radius).transform(e); + return new We(this.center, this.radius, this.radius).transform(e); } bbox() { - return de.fromPoints( - this.center.sub(T(this.radius)), - this.center.add(T(this.radius)) + 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 n(this.center, this.radius); + 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); } }, - In = class n { + We = class t { static { - o(this, "Ellipse"); + i(this, "Ellipse"); } center; radiusX; radiusY; - constructor(e, i, c) { - (this.center = e.clone()), (this.radiusX = i), (this.radiusY = c); + 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) { - return new n( - e.multVec2(this.center), - e.m[0] * this.radiusX, - e.m[5] * this.radiusY - ); + 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() { - return de.fromPoints( - this.center.sub(T(this.radiusX, this.radiusY)), - this.center.add(T(this.radiusX, this.radiusY)) - ); + 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 n(this.center, this.radiusX, this.radiusY); + 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); } }, - Ke = class n { + Oe = class t { static { - o(this, "Polygon"); + i(this, "Polygon"); } pts; constructor(e) { @@ -860,82 +1598,197 @@ var kaplay = (() => { this.pts = e; } transform(e) { - return new n(this.pts.map((i) => e.multVec2(i))); + return new t(this.pts.map((r) => e.multVec2(r))); } bbox() { - let e = T(Number.MAX_VALUE), - i = T(-Number.MAX_VALUE); - for (let c of this.pts) - (e.x = Math.min(e.x, c.x)), - (i.x = Math.max(i.x, c.x)), - (e.y = Math.min(e.y, c.y)), - (i.y = Math.max(i.y, c.y)); - return de.fromPoints(e, i); + 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, - i = this.pts.length; - for (let c = 0; c < i; c++) { - let m = this.pts[c], - p = this.pts[(c + 1) % i]; - (e += m.x * p.y * 0.5), (e -= p.x * m.y * 0.5); + 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 n(this.pts.map((e) => 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); } }; - function Rr(n, e) { - let i = Number.MAX_VALUE, - c = T(0); - for (let m of [n, e]) - for (let p = 0; p < m.pts.length; p++) { - let P = m.pts[p], - j = m.pts[(p + 1) % m.pts.length].sub(P).normal().unit(), - y = Number.MAX_VALUE, - X = -Number.MAX_VALUE; - for (let K = 0; K < n.pts.length; K++) { - let Q = n.pts[K].dot(j); - (y = Math.min(y, Q)), (X = Math.max(X, Q)); - } - let S = Number.MAX_VALUE, - q = -Number.MAX_VALUE; - for (let K = 0; K < e.pts.length; K++) { - let Q = e.pts[K].dot(j); - (S = Math.min(S, Q)), (q = Math.max(q, Q)); - } - let E = Math.min(X, q) - Math.max(y, S); - if (E < 0) return null; - if (E < Math.abs(i)) { - let K = q - y, - Q = S - X; - (i = Math.abs(K) < Math.abs(Q) ? K : Q), (c = j.scale(i)); - } - } - return c; + 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)); } - o(Rr, "sat"); - var Ut = class extends Map { + 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 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; + } + return (m = e[f]), (V = r[f]), l.push([t[V], t[f], t[m]]), l; + } + 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 !0; + } + i(or, "isConvex"); + var kt = class extends Map { static { - o(this, "Registry"); - } - lastID; - constructor(...e) { - super(...e), (this.lastID = 0); + i(this, "Registry"); } + lastID = 0; push(e) { - let i = this.lastID; - return this.set(i, e), this.lastID++, i; + let r = this.lastID; + return this.set(r, e), this.lastID++, r; } pushd(e) { - let i = this.push(e); - return () => this.delete(i); + let r = this.push(e); + return () => this.delete(r); } }, - ke = class n { + et = class t { static { - o(this, "EventController"); + i(this, "EventController"); } paused = !1; cancel; @@ -943,40 +1796,40 @@ var kaplay = (() => { this.cancel = e; } static join(e) { - let i = new n(() => e.forEach((c) => c.cancel())); + let r = new t(() => e.forEach((s) => s.cancel())); return ( - Object.defineProperty(i, "paused", { + Object.defineProperty(r, "paused", { get: () => e[0].paused, - set: (c) => e.forEach((m) => (m.paused = c)), + set: (s) => e.forEach((a) => (a.paused = s)), }), - (i.paused = !1), - i + (r.paused = !1), + r ); } }, - be = class { + we = class { static { - o(this, "Event"); + i(this, "Event"); } - handlers = new Ut(); + handlers = new kt(); add(e) { - let i = this.handlers.pushd((...m) => { - c.paused || e(...m); + let r = this.handlers.pushd((...a) => { + s.paused || e(...a); }), - c = new ke(i); - return c; + s = new et(r); + return s; } addOnce(e) { - let i = this.add((...c) => { - i.cancel(), e(...c); + let r = this.add((...s) => { + r.cancel(), e(...s); }); - return i; + return r; } next() { return new Promise((e) => this.addOnce(e)); } trigger(...e) { - this.handlers.forEach((i) => i(...e)); + this.handlers.forEach((r) => r(...e)); } numListeners() { return this.handlers.size; @@ -985,30 +1838,30 @@ var kaplay = (() => { this.handlers.clear(); } }, - Ne = class { + tt = class { static { - o(this, "EventHandler"); + i(this, "EventHandler"); } handlers = {}; - on(e, i) { + on(e, r) { return ( - this.handlers[e] || (this.handlers[e] = new be()), - this.handlers[e].add(i) + this.handlers[e] || (this.handlers[e] = new we()), + this.handlers[e].add(r) ); } - onOnce(e, i) { - let c = this.on(e, (...m) => { - c.cancel(), i(...m); + onOnce(e, r) { + let s = this.on(e, (...a) => { + s.cancel(), r(...a); }); - return c; + return s; } next(e) { - return new Promise((i) => { - this.onOnce(e, (...c) => i(c[0])); + return new Promise((r) => { + this.onOnce(e, (...s) => r(s[0])); }); } - trigger(e, ...i) { - this.handlers[e] && this.handlers[e].trigger(...i); + trigger(e, ...r) { + this.handlers[e] && this.handlers[e].trigger(...r); } remove(e) { delete this.handlers[e]; @@ -1020,81 +1873,81 @@ var kaplay = (() => { return this.handlers[e]?.numListeners() ?? 0; } }; - function Xt(n, e) { - if (n === e) return !0; - let i = typeof n, - c = typeof e; - if (i !== c) return !1; - if (i === "object" && c === "object" && n !== null && e !== null) { - if (Array.isArray(n) !== Array.isArray(e)) return !1; - let m = Object.keys(n), - p = Object.keys(e); - if (m.length !== p.length) return !1; - for (let P of m) { - let I = n[P], - j = e[P]; - if (!Xt(I, j)) return !1; + 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; } - o(Xt, "deepEq"); - function Pi(n) { - let e = window.atob(n), - i = e.length, - c = new Uint8Array(i); - for (let m = 0; m < i; m++) c[m] = e.charCodeAt(m); - return c.buffer; + 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; } - o(Pi, "base64ToArrayBuffer"); - function Dr(n) { - return Pi(n.split(",")[1]); + i(Gi, "base64ToArrayBuffer"); + function to(t) { + return Gi(t.split(",")[1]); } - o(Dr, "dataURLToArrayBuffer"); - function Jt(n, e) { - let i = document.createElement("a"); - (i.href = e), (i.download = n), i.click(); + i(to, "dataURLToArrayBuffer"); + function dn(t, e) { + let r = document.createElement("a"); + (r.href = e), (r.download = t), r.click(); } - o(Jt, "download"); - function Nn(n, e) { - Jt(n, "data:text/plain;charset=utf-8," + e); + i(dn, "download"); + function sr(t, e) { + dn(t, "data:text/plain;charset=utf-8," + e); } - o(Nn, "downloadText"); - function Mr(n, e) { - Nn(n, JSON.stringify(e)); + i(sr, "downloadText"); + function no(t, e) { + sr(t, JSON.stringify(e)); } - o(Mr, "downloadJSON"); - function jn(n, e) { - let i = URL.createObjectURL(e); - Jt(n, i), URL.revokeObjectURL(i); + i(no, "downloadJSON"); + function ir(t, e) { + let r = URL.createObjectURL(e); + dn(t, r), URL.revokeObjectURL(r); } - o(jn, "downloadBlob"); - var Hn = o((n) => n.match(/^data:\w+\/\w+;base64,.+/), "isDataURL"); - var Gr = o((n) => n.split(".").slice(0, -1).join("."), "getFileName"); - function Ee(n, e) { - return (...i) => { - let c = i.length; - if (c === n.length) return n(...i); - if (c === e.length) return e(...i); + 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); }; } - o(Ee, "overload2"); - var Br = (() => { - let n = 0; - return () => n++; + i(Ie, "overload2"); + var oo = (() => { + let t = 0; + return () => t++; })(), - Fr = o( - (n) => (n instanceof Error ? n.message : String(n)), + so = i( + (t) => (t instanceof Error ? t.message : String(t)), "getErrorMessage" ); - var Wt = class { + var ln = class { static { - o(this, "BinaryHeap"); + i(this, "BinaryHeap"); } _items; _compareFn; - constructor(e = (i, c) => i < c) { + constructor(e = (r, s) => r < s) { (this._compareFn = e), (this._items = []); } insert(e) { @@ -1103,9 +1956,9 @@ var kaplay = (() => { remove() { if (this._items.length === 0) return null; let e = this._items[0], - i = this._items.pop(); + r = this._items.pop(); return ( - this._items.length !== 0 && ((this._items[0] = i), this.moveDown(0)), e + this._items.length !== 0 && ((this._items[0] = r), this.moveDown(0)), e ); } clear() { @@ -1113,124 +1966,124 @@ var kaplay = (() => { } moveUp(e) { for (; e > 0; ) { - let i = Math.floor((e - 1) / 2); + let r = Math.floor((e - 1) / 2); if ( - !this._compareFn(this._items[e], this._items[i]) && - this._items[e] >= this._items[i] + !this._compareFn(this._items[e], this._items[r]) && + this._items[e] >= this._items[r] ) break; - this.swap(e, i), (e = i); + this.swap(e, r), (e = r); } } moveDown(e) { for (; e < Math.floor(this._items.length / 2); ) { - let i = 2 * e + 1; + let r = 2 * e + 1; if ( - (i < this._items.length - 1 && - !this._compareFn(this._items[i], this._items[i + 1]) && - ++i, - this._compareFn(this._items[e], this._items[i])) + (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, i), (e = i); + this.swap(e, r), (e = r); } } - swap(e, i) { - [this._items[e], this._items[i]] = [this._items[i], this._items[e]]; + swap(e, r) { + [this._items[e], this._items[r]] = [this._items[r], this._items[e]]; } get length() { return this._items.length; } }; - var Di = Object.freeze([ + var Bi = Object.freeze([ 776, 2359, 2367, 2984, 3007, 3021, 3633, 3635, 3648, 3657, 4352, 4449, 4520, ]); - function Ir(n) { - if (typeof n != "string") + function io(t) { + if (typeof t != "string") throw new TypeError("string cannot be undefined or null"); let e = [], - i = 0, - c = 0; - for (; i < n.length; ) { + r = 0, + s = 0; + for (; r < t.length; ) { if ( - ((c += Mi(i + c, n)), - _i(n[i + c]) && c++, - Ii(n[i + c]) && c++, - Li(n[i + c]) && c++, - ki(n[i + c])) + ((s += Fi(r + s, t)), + Hi(t[r + s]) && s++, + ki(t[r + s]) && s++, + Ni(t[r + s]) && s++, + Ki(t[r + s])) ) { - c++; + s++; continue; } - e.push(n.substring(i, i + c)), (i += c), (c = 0); + e.push(t.substring(r, r + s)), (r += s), (s = 0); } return e; } - o(Ir, "runes"); - function Mi(n, e) { - let i = e[n]; - if (!Gi(i) || n === e.length - 1) return 1; - let c = i + e[n + 1], - m = e.substring(n + 2, n + 5); - return Pr(c) && Pr(m) + 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 - : Bi(c) && Vi(m) - ? e.slice(n).indexOf(String.fromCodePoint(917631)) + 2 - : Fi(m) + : Li(s) && _i(a) + ? e.slice(t).indexOf(String.fromCodePoint(917631)) + 2 + : ji(a) ? 4 : 2; } - o(Mi, "nextUnits"); - function Gi(n) { - return n && tt(n[0].charCodeAt(0), 55296, 56319); + i(Fi, "nextUnits"); + function Ii(t) { + return t && vt(t[0].charCodeAt(0), 55296, 56319); } - o(Gi, "isFirstOfSurrogatePair"); - function Pr(n) { - return tt(qn(n), 127462, 127487); + i(Ii, "isFirstOfSurrogatePair"); + function eo(t) { + return vt(cr(t), 127462, 127487); } - o(Pr, "isRegionalIndicator"); - function Bi(n) { - return tt(qn(n), 127988, 127988); + i(eo, "isRegionalIndicator"); + function Li(t) { + return vt(cr(t), 127988, 127988); } - o(Bi, "isSubdivisionFlag"); - function Fi(n) { - return tt(qn(n), 127995, 127999); + i(Li, "isSubdivisionFlag"); + function ji(t) { + return vt(cr(t), 127995, 127999); } - o(Fi, "isFitzpatrickModifier"); - function Ii(n) { - return typeof n == "string" && tt(n.charCodeAt(0), 65024, 65039); + i(ji, "isFitzpatrickModifier"); + function ki(t) { + return typeof t == "string" && vt(t.charCodeAt(0), 65024, 65039); } - o(Ii, "isVariationSelector"); - function Li(n) { - return typeof n == "string" && tt(n.charCodeAt(0), 8400, 8447); + i(ki, "isVariationSelector"); + function Ni(t) { + return typeof t == "string" && vt(t.charCodeAt(0), 8400, 8447); } - o(Li, "isDiacriticalMark"); - function Vi(n) { - let e = n.codePointAt(0); + i(Ni, "isDiacriticalMark"); + function _i(t) { + let e = t.codePointAt(0); return ( - typeof n == "string" && typeof e == "number" && tt(e, 917504, 917631) + typeof t == "string" && typeof e == "number" && vt(e, 917504, 917631) ); } - o(Vi, "isSupplementarySpecialpurposePlane"); - function _i(n) { - return typeof n == "string" && Di.includes(n.charCodeAt(0)); + i(_i, "isSupplementarySpecialpurposePlane"); + function Hi(t) { + return typeof t == "string" && Bi.includes(t.charCodeAt(0)); } - o(_i, "isGrapheme"); - function ki(n) { - return typeof n == "string" && n.charCodeAt(0) === 8205; + i(Hi, "isGrapheme"); + function Ki(t) { + return typeof t == "string" && t.charCodeAt(0) === 8205; } - o(ki, "isZeroWidthJoiner"); - function qn(n) { - let e = n.charCodeAt(0) - 55296, - i = n.charCodeAt(1) - 56320; - return (e << 10) + i + 65536; + i(Ki, "isZeroWidthJoiner"); + function cr(t) { + let e = t.charCodeAt(0) - 55296, + r = t.charCodeAt(1) - 56320; + return (e << 10) + r + 65536; } - o(qn, "codePointFromSurrogatePair"); - function tt(n, e, i) { - return n >= e && n <= i; + i(cr, "codePointFromSurrogatePair"); + function vt(t, e, r) { + return t >= e && t <= r; } - o(tt, "betweenInclusive"); - var $n = { + i(vt, "betweenInclusive"); + var ur = { "Joy-Con L+R (STANDARD GAMEPAD Vendor: 057e Product: 200e)": { buttons: { 0: "south", @@ -1328,9 +2181,9 @@ var kaplay = (() => { sticks: { left: { x: 0, y: 1 }, right: { x: 2, y: 3 } }, }, }; - var at = class { + var Ut = class { static { - o(this, "ButtonState"); + i(this, "ButtonState"); } pressed = new Set([]); pressedRepeat = new Set([]); @@ -1349,16 +2202,16 @@ var kaplay = (() => { this.down.delete(e), this.pressed.delete(e), this.released.add(e); } }, - zn = class { + lr = class { static { - o(this, "GamepadState"); + i(this, "GamepadState"); } - buttonState = new at(); + buttonState = new Ut(); stickState = new Map(); }, - Kn = class { + mr = class { static { - o(this, "FPSCounter"); + i(this, "FPSCounter"); } dts = []; timer = 0; @@ -1369,442 +2222,447 @@ var kaplay = (() => { this.timer >= 1 && ((this.timer = 0), (this.fps = Math.round( - 1 / (this.dts.reduce((i, c) => i + c) / this.dts.length) + 1 / (this.dts.reduce((r, s) => r + s) / this.dts.length) )), (this.dts = [])); } }, - Lr = o((n) => { - if (!n.canvas) throw new Error("Please provide a canvas"); + ao = i((t) => { + if (!t.canvas) throw new Error("Please provide a canvas"); let e = { - canvas: n.canvas, + canvas: t.canvas, loopID: null, stopped: !1, dt: 0, time: 0, realTime: 0, - fpsCounter: new Kn(), + fpsCounter: new mr(), timeScale: 1, skipTime: !1, + isHidden: !1, numFrames: 0, - mousePos: new v(0), - mouseDeltaPos: new v(0), - keyState: new at(), - mouseState: new at(), - mergedGamepadState: new zn(), + 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: n.canvas.offsetWidth, - lastHeight: n.canvas.offsetHeight, - events: new Ne(), + lastWidth: t.canvas.offsetWidth, + lastHeight: t.canvas.offsetHeight, + events: new tt(), }; - function i() { + function r() { return e.dt * e.timeScale; } - o(i, "dt"); - function c() { + i(r, "dt"); + function s() { + return e.isHidden; + } + i(s, "isHidden"); + function a() { return e.time; } - o(c, "time"); - function m() { + i(a, "time"); + function l() { return e.fpsCounter.fps; } - o(m, "fps"); - function p() { + i(l, "fps"); + function u() { return e.numFrames; } - o(p, "numFrames"); - function P() { + i(u, "numFrames"); + function f() { return e.canvas.toDataURL(); } - o(P, "screenshot"); - function I(l) { - e.canvas.style.cursor = l; + i(f, "screenshot"); + function y(p) { + e.canvas.style.cursor = p; } - o(I, "setCursor"); - function j() { + i(y, "setCursor"); + function m() { return e.canvas.style.cursor; } - o(j, "getCursor"); - function y(l) { - if (l) + i(m, "getCursor"); + function V(p) { + if (p) try { - let x = e.canvas.requestPointerLock(); - x.catch && x.catch((R) => console.error(R)); - } catch (x) { - console.error(x); + let S = e.canvas.requestPointerLock(); + S.catch && S.catch((L) => console.error(L)); + } catch (S) { + console.error(S); } else document.exitPointerLock(); } - o(y, "setCursorLocked"); - function X() { + i(V, "setCursorLocked"); + function x() { return !!document.pointerLockElement; } - o(X, "isCursorLocked"); - function S(l) { - l.requestFullscreen - ? l.requestFullscreen() - : l.webkitRequestFullscreen && l.webkitRequestFullscreen(); + i(x, "isCursorLocked"); + function P(p) { + p.requestFullscreen + ? p.requestFullscreen() + : p.webkitRequestFullscreen && p.webkitRequestFullscreen(); } - o(S, "enterFullscreen"); - function q() { + i(P, "enterFullscreen"); + function w() { document.exitFullscreen ? document.exitFullscreen() : document.webkitExitFullScreen && document.webkitExitFullScreen(); } - o(q, "exitFullscreen"); - function E() { + i(w, "exitFullscreen"); + function K() { return document.fullscreenElement || document.webkitFullscreenElement; } - o(E, "getFullscreenElement"); - function K(l = !0) { - l ? S(e.canvas) : q(); + i(K, "getFullscreenElement"); + function X(p = !0) { + p ? P(e.canvas) : w(); } - o(K, "setFullscreen"); - function Q() { - return !!E(); + i(X, "setFullscreen"); + function z() { + return !!K(); } - o(Q, "isFullscreen"); - function te() { + i(z, "isFullscreen"); + function N() { e.stopped = !0; - for (let l in se) e.canvas.removeEventListener(l, se[l]); - for (let l in le) document.removeEventListener(l, le[l]); - for (let l in ae) window.removeEventListener(l, ae[l]); - ge.disconnect(); + 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(); } - o(te, "quit"); - function k(l) { + i(N, "quit"); + function $(p) { e.loopID !== null && cancelAnimationFrame(e.loopID); - let x = 0, - R = o((L) => { + let S = 0, + L = i((Y) => { if (e.stopped) return; if (document.visibilityState !== "visible") { - e.loopID = requestAnimationFrame(R); + e.loopID = requestAnimationFrame(L); return; } - let he = L / 1e3, - z = he - e.realTime, - Oe = n.maxFPS ? 1 / n.maxFPS : 0; - (e.realTime = he), - (x += z), - x > Oe && + 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 = x), (e.time += i()), e.fpsCounter.tick(e.dt)), - (x = 0), + ((e.dt = S), (e.time += r()), e.fpsCounter.tick(e.dt)), + (S = 0), (e.skipTime = !1), e.numFrames++, - ft(), - l(), - yn()), - (e.loopID = requestAnimationFrame(R)); + Mn(), + p(), + Mt()), + (e.loopID = requestAnimationFrame(L)); }, "frame"); - R(0); + L(0); } - o(k, "run"); - function pe() { + i($, "run"); + function O() { return "ontouchstart" in window || navigator.maxTouchPoints > 0; } - o(pe, "isTouchscreen"); - function C() { + i(O, "isTouchscreen"); + function se() { return e.mousePos.clone(); } - o(C, "mousePos"); - function Ae() { + i(se, "mousePos"); + function _() { return e.mouseDeltaPos.clone(); } - o(Ae, "mouseDeltaPos"); - function $(l = "left") { - return e.mouseState.pressed.has(l); + i(_, "mouseDeltaPos"); + function ae(p = "left") { + return e.mouseState.pressed.has(p); } - o($, "isMousePressed"); - function Te(l = "left") { - return e.mouseState.down.has(l); + i(ae, "isMousePressed"); + function re(p = "left") { + return e.mouseState.down.has(p); } - o(Te, "isMouseDown"); - function ye(l = "left") { - return e.mouseState.released.has(l); + i(re, "isMouseDown"); + function ce(p = "left") { + return e.mouseState.released.has(p); } - o(ye, "isMouseReleased"); - function Se() { + i(ce, "isMouseReleased"); + function ge() { return e.isMouseMoved; } - o(Se, "isMouseMoved"); - function st(l) { - return l === void 0 + i(ge, "isMouseMoved"); + function Ue(p) { + return p === void 0 ? e.keyState.pressed.size > 0 - : e.keyState.pressed.has(l); + : e.keyState.pressed.has(p); } - o(st, "isKeyPressed"); - function an(l) { - return l === void 0 + i(Ue, "isKeyPressed"); + function Ce(p) { + return p === void 0 ? e.keyState.pressedRepeat.size > 0 - : e.keyState.pressedRepeat.has(l); + : e.keyState.pressedRepeat.has(p); } - o(an, "isKeyPressedRepeat"); - function Tt(l) { - return l === void 0 ? e.keyState.down.size > 0 : e.keyState.down.has(l); + i(Ce, "isKeyPressedRepeat"); + function Le(p) { + return p === void 0 ? e.keyState.down.size > 0 : e.keyState.down.has(p); } - o(Tt, "isKeyDown"); - function Ot(l) { - return l === void 0 + i(Le, "isKeyDown"); + function je(p) { + return p === void 0 ? e.keyState.released.size > 0 - : e.keyState.released.has(l); + : e.keyState.released.has(p); } - o(Ot, "isKeyReleased"); - function Rt(l) { - return l === void 0 + i(je, "isKeyReleased"); + function Ee(p) { + return p === void 0 ? e.mergedGamepadState.buttonState.pressed.size > 0 - : e.mergedGamepadState.buttonState.pressed.has(l); + : e.mergedGamepadState.buttonState.pressed.has(p); } - o(Rt, "isGamepadButtonPressed"); - function Ye(l) { - return l === void 0 + i(Ee, "isGamepadButtonPressed"); + function Ne(p) { + return p === void 0 ? e.mergedGamepadState.buttonState.down.size > 0 - : e.mergedGamepadState.buttonState.down.has(l); + : e.mergedGamepadState.buttonState.down.has(p); } - o(Ye, "isGamepadButtonDown"); - function un(l) { - return l === void 0 + i(Ne, "isGamepadButtonDown"); + function _e(p) { + return p === void 0 ? e.mergedGamepadState.buttonState.released.size > 0 - : e.mergedGamepadState.buttonState.released.has(l); + : e.mergedGamepadState.buttonState.released.has(p); } - o(un, "isGamepadButtonReleased"); - function cn(l) { - return e.events.on("resize", l); + i(_e, "isGamepadButtonReleased"); + function He(p) { + return e.events.on("resize", p); } - o(cn, "onResize"); - let hn = Ee( - (l) => e.events.on("keyDown", l), - (l, x) => e.events.on("keyDown", (R) => R === l && x(l)) + i(He, "onResize"); + let pt = Ie( + (p) => e.events.on("keyDown", p), + (p, S) => e.events.on("keyDown", (L) => L === p && S(p)) ), - ln = Ee( - (l) => e.events.on("keyPress", l), - (l, x) => e.events.on("keyPress", (R) => R === l && x(l)) + Se = Ie( + (p) => e.events.on("keyPress", p), + (p, S) => e.events.on("keyPress", (L) => L === p && S(p)) ), - dn = Ee( - (l) => e.events.on("keyPressRepeat", l), - (l, x) => e.events.on("keyPressRepeat", (R) => R === l && x(l)) + Ve = Ie( + (p) => e.events.on("keyPressRepeat", p), + (p, S) => e.events.on("keyPressRepeat", (L) => L === p && S(p)) ), - fn = Ee( - (l) => e.events.on("keyRelease", l), - (l, x) => e.events.on("keyRelease", (R) => R === l && x(l)) + ze = Ie( + (p) => e.events.on("keyRelease", p), + (p, S) => e.events.on("keyRelease", (L) => L === p && S(p)) ), - Pt = Ee( - (l) => e.events.on("mouseDown", (x) => l(x)), - (l, x) => e.events.on("mouseDown", (R) => R === l && x(R)) + rt = Ie( + (p) => e.events.on("mouseDown", (S) => p(S)), + (p, S) => e.events.on("mouseDown", (L) => L === p && S(L)) ), - Dt = Ee( - (l) => e.events.on("mousePress", (x) => l(x)), - (l, x) => e.events.on("mousePress", (R) => R === l && x(R)) + ot = Ie( + (p) => e.events.on("mousePress", (S) => p(S)), + (p, S) => e.events.on("mousePress", (L) => L === p && S(L)) ), - Mt = Ee( - (l) => e.events.on("mouseRelease", (x) => l(x)), - (l, x) => e.events.on("mouseRelease", (R) => R === l && x(R)) + wt = Ie( + (p) => e.events.on("mouseRelease", (S) => p(S)), + (p, S) => e.events.on("mouseRelease", (L) => L === p && S(L)) ); - function Gt(l) { - return e.events.on("mouseMove", () => l(C(), Ae())); + function Yt(p) { + return e.events.on("mouseMove", () => p(se(), _())); } - o(Gt, "onMouseMove"); - function Bt(l) { - return e.events.on("charInput", l); + i(Yt, "onMouseMove"); + function Xt(p) { + return e.events.on("charInput", p); } - o(Bt, "onCharInput"); - function mn(l) { - return e.events.on("touchStart", l); + i(Xt, "onCharInput"); + function An(p) { + return e.events.on("touchStart", p); } - o(mn, "onTouchStart"); - function ct(l) { - return e.events.on("touchMove", l); + i(An, "onTouchStart"); + function Wt(p) { + return e.events.on("touchMove", p); } - o(ct, "onTouchMove"); - function pn(l) { - return e.events.on("touchEnd", l); + i(Wt, "onTouchMove"); + function On(p) { + return e.events.on("touchEnd", p); } - o(pn, "onTouchEnd"); - function gn(l) { - return e.events.on("scroll", l); + i(On, "onTouchEnd"); + function Rn(p) { + return e.events.on("scroll", p); } - o(gn, "onScroll"); - function Ft(l) { - return e.events.on("hide", l); + i(Rn, "onScroll"); + function $t(p) { + return e.events.on("hide", p); } - o(Ft, "onHide"); - function wn(l) { - return e.events.on("show", l); + i($t, "onHide"); + function Un(p) { + return e.events.on("show", p); } - o(wn, "onShow"); - function It(l, x) { - if (typeof l == "function") return e.events.on("gamepadButtonDown", l); - if (typeof l == "string" && typeof x == "function") - return e.events.on("gamepadButtonDown", (R) => R === l && x(l)); + 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)); } - o(It, "onGamepadButtonDown"); - function Lt(l, x) { - if (typeof l == "function") return e.events.on("gamepadButtonPress", l); - if (typeof l == "string" && typeof x == "function") - return e.events.on("gamepadButtonPress", (R) => R === l && x(l)); + 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)); } - o(Lt, "onGamepadButtonPress"); - function bn(l, x) { - if (typeof l == "function") - return e.events.on("gamepadButtonRelease", l); - if (typeof l == "string" && typeof x == "function") - return e.events.on("gamepadButtonRelease", (R) => R === l && x(l)); + 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)); } - o(bn, "onGamepadButtonRelease"); - function ht(l, x) { - return e.events.on("gamepadStick", (R, L) => R === l && x(L)); + i(Jt, "onGamepadButtonRelease"); + function Pn(p, S) { + return e.events.on("gamepadStick", (L, Y) => L === p && S(Y)); } - o(ht, "onGamepadStick"); - function vn(l) { - e.events.on("gamepadConnect", l); + i(Pn, "onGamepadStick"); + function Dt(p) { + e.events.on("gamepadConnect", p); } - o(vn, "onGamepadConnect"); - function lt(l) { - e.events.on("gamepadDisconnect", l); + i(Dt, "onGamepadConnect"); + function Dn(p) { + e.events.on("gamepadDisconnect", p); } - o(lt, "onGamepadDisconnect"); - function Pe(l) { - return e.mergedGamepadState.stickState.get(l) || new v(0); + i(Dn, "onGamepadDisconnect"); + function st(p) { + return e.mergedGamepadState.stickState.get(p) || new T(0); } - o(Pe, "getGamepadStick"); - function dt() { + i(st, "getGamepadStick"); + function Pe() { return [...e.charInputted]; } - o(dt, "charInputted"); - function Vt() { + i(Pe, "charInputted"); + function Ct() { return [...e.gamepads]; } - o(Vt, "getGamepads"); - function ft() { + i(Ct, "getGamepads"); + function Mn() { e.events.trigger("input"), - e.keyState.down.forEach((l) => e.events.trigger("keyDown", l)), - e.mouseState.down.forEach((l) => e.events.trigger("mouseDown", l)), - He(); + e.keyState.down.forEach((p) => e.events.trigger("keyDown", p)), + e.mouseState.down.forEach((p) => e.events.trigger("mouseDown", p)), + de(); } - o(ft, "processInput"); - function yn() { + i(Mn, "processInput"); + function Mt() { e.keyState.update(), e.mouseState.update(), e.mergedGamepadState.buttonState.update(), - e.mergedGamepadState.stickState.forEach((l, x) => { - e.mergedGamepadState.stickState.set(x, new v(0)); + e.mergedGamepadState.stickState.forEach((p, S) => { + e.mergedGamepadState.stickState.set(S, new T(0)); }), (e.charInputted = []), (e.isMouseMoved = !1), - e.gamepadStates.forEach((l) => { - l.buttonState.update(), - l.stickState.forEach((x, R) => { - l.stickState.set(R, new v(0)); + e.gamepadStates.forEach((p) => { + p.buttonState.update(), + p.stickState.forEach((S, L) => { + p.stickState.set(L, new T(0)); }); }); } - o(yn, "resetInput"); - function _t(l) { - let x = { - index: l.index, - isPressed: (R) => - e.gamepadStates.get(l.index).buttonState.pressed.has(R), - isDown: (R) => e.gamepadStates.get(l.index).buttonState.down.has(R), - isReleased: (R) => - e.gamepadStates.get(l.index).buttonState.released.has(R), - getStick: (R) => e.gamepadStates.get(l.index).stickState.get(R), + 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(x), - e.gamepadStates.set(l.index, { - buttonState: new at(), + e.gamepads.push(S), + e.gamepadStates.set(p.index, { + buttonState: new Ut(), stickState: new Map([ - ["left", new v(0)], - ["right", new v(0)], + ["left", new T(0)], + ["right", new T(0)], ]), }), - x + S ); } - o(_t, "registerGamepad"); - function ne(l) { - (e.gamepads = e.gamepads.filter((x) => x.index !== l.index)), - e.gamepadStates.delete(l.index); + i(Zt, "registerGamepad"); + function Gn(p) { + (e.gamepads = e.gamepads.filter((S) => S.index !== p.index)), + e.gamepadStates.delete(p.index); } - o(ne, "removeGamepad"); - function He() { - for (let l of navigator.getGamepads()) - l && !e.gamepadStates.has(l.index) && _t(l); - for (let l of e.gamepads) { - let x = navigator.getGamepads()[l.index], - L = (n.gamepads ?? {})[x.id] ?? $n[x.id] ?? $n.default, - he = e.gamepadStates.get(l.index); - for (let z = 0; z < x.buttons.length; z++) - x.buttons[z].pressed - ? (he.buttonState.down.has(L.buttons[z]) || - (e.mergedGamepadState.buttonState.press(L.buttons[z]), - he.buttonState.press(L.buttons[z]), - e.events.trigger("gamepadButtonPress", L.buttons[z])), - e.events.trigger("gamepadButtonDown", L.buttons[z])) - : he.buttonState.down.has(L.buttons[z]) && - (e.mergedGamepadState.buttonState.release(L.buttons[z]), - he.buttonState.release(L.buttons[z]), - e.events.trigger("gamepadButtonRelease", L.buttons[z])); - for (let z in L.sticks) { - let Oe = L.sticks[z], - $e = new v(x.axes[Oe.x], x.axes[Oe.y]); - he.stickState.set(z, $e), - e.mergedGamepadState.stickState.set(z, $e), - e.events.trigger("gamepadStick", z, $e); + 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); } } } - o(He, "processGamepad"); - let se = {}, - le = {}, - ae = {}, - Be = n.pixelDensity || window.devicePixelRatio || 1; - se.mousemove = (l) => { - let x = new v(l.offsetX, l.offsetY), - R = new v(l.movementX, l.movementY); - if (Q()) { - let L = e.canvas.width / Be, - he = e.canvas.height / Be, - z = window.innerWidth, - Oe = window.innerHeight, - $e = z / Oe, - kt = L / he; - if ($e > kt) { - let De = Oe / he, - Ce = (z - L * De) / 2; - (x.x = _e(l.offsetX - Ce, 0, L * De, 0, L)), - (x.y = _e(l.offsetY, 0, he * De, 0, he)); + 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 De = z / L, - Ce = (Oe - he * De) / 2; - (x.x = _e(l.offsetX, 0, L * De, 0, L)), - (x.y = _e(l.offsetY - Ce, 0, he * De, 0, he)); + 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 = x), - (e.mouseDeltaPos = R), + (e.mousePos = S), + (e.mouseDeltaPos = L), e.events.trigger("mouseMove"); }); }; - let We = ["left", "middle", "right", "back", "forward"]; - (se.mousedown = (l) => { + let it = ["left", "middle", "right", "back", "forward"]; + (he.mousedown = (p) => { e.events.onOnce("input", () => { - let x = We[l.button]; - x && (e.mouseState.press(x), e.events.trigger("mousePress", x)); + let S = it[p.button]; + S && (e.mouseState.press(S), e.events.trigger("mousePress", S)); }); }), - (se.mouseup = (l) => { + (he.mouseup = (p) => { e.events.onOnce("input", () => { - let x = We[l.button]; - x && (e.mouseState.release(x), e.events.trigger("mouseRelease", x)); + let S = it[p.button]; + S && (e.mouseState.release(S), e.events.trigger("mouseRelease", S)); }); }); - let xn = new Set([ + let Gt = new Set([ " ", "ArrowLeft", "ArrowRight", @@ -1812,135 +2670,139 @@ var kaplay = (() => { "ArrowDown", "Tab", ]), - qe = { + en = { ArrowLeft: "left", ArrowRight: "right", ArrowUp: "up", ArrowDown: "down", " ": "space", }; - (se.keydown = (l) => { - xn.has(l.key) && l.preventDefault(), + (he.keydown = (p) => { + Gt.has(p.key) && p.preventDefault(), e.events.onOnce("input", () => { - let x = qe[l.key] || l.key.toLowerCase(); - x.length === 1 - ? (e.events.trigger("charInput", x), e.charInputted.push(x)) - : x === "space" && + 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(" ")), - l.repeat - ? (e.keyState.pressRepeat(x), - e.events.trigger("keyPressRepeat", x)) - : (e.keyState.press(x), - e.events.trigger("keyPressRepeat", x), - e.events.trigger("keyPress", x)); + 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)); }); }), - (se.keyup = (l) => { + (he.keyup = (p) => { e.events.onOnce("input", () => { - let x = qe[l.key] || l.key.toLowerCase(); - e.keyState.release(x), e.events.trigger("keyRelease", x); + let S = en[p.key] || p.key.toLowerCase(); + e.keyState.release(S), e.events.trigger("keyRelease", S); }); }), - (se.touchstart = (l) => { - l.preventDefault(), + (he.touchstart = (p) => { + p.preventDefault(), e.events.onOnce("input", () => { - let x = [...l.changedTouches], - R = e.canvas.getBoundingClientRect(); - n.touchToMouse !== !1 && - ((e.mousePos = new v(x[0].clientX - R.x, x[0].clientY - R.y)), + 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")), - x.forEach((L) => { + S.forEach((Y) => { e.events.trigger( "touchStart", - new v(L.clientX - R.x, L.clientY - R.y), - L + new T(Y.clientX - L.x, Y.clientY - L.y), + Y ); }); }); }), - (se.touchmove = (l) => { - l.preventDefault(), + (he.touchmove = (p) => { + p.preventDefault(), e.events.onOnce("input", () => { - let x = [...l.changedTouches], - R = e.canvas.getBoundingClientRect(); - n.touchToMouse !== !1 && - ((e.mousePos = new v(x[0].clientX - R.x, x[0].clientY - R.y)), - e.events.trigger("mouseMove")), - x.forEach((L) => { - e.events.trigger( - "touchMove", - new v(L.clientX - R.x, L.clientY - R.y), - L - ); - }); + 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 + ); + }); }); }), - (se.touchend = (l) => { + (he.touchend = (p) => { e.events.onOnce("input", () => { - let x = [...l.changedTouches], - R = e.canvas.getBoundingClientRect(); - n.touchToMouse !== !1 && - ((e.mousePos = new v(x[0].clientX - R.x, x[0].clientY - R.y)), + 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")), - x.forEach((L) => { + S.forEach((Y) => { e.events.trigger( "touchEnd", - new v(L.clientX - R.x, L.clientY - R.y), - L + new T(Y.clientX - L.x, Y.clientY - L.y), + Y ); }); }); }), - (se.touchcancel = (l) => { + (he.touchcancel = (p) => { e.events.onOnce("input", () => { - let x = [...l.changedTouches], - R = e.canvas.getBoundingClientRect(); - n.touchToMouse !== !1 && - ((e.mousePos = new v(x[0].clientX - R.x, x[0].clientY - R.y)), + 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")), - x.forEach((L) => { + S.forEach((Y) => { e.events.trigger( "touchEnd", - new v(L.clientX - R.x, L.clientY - R.y), - L + new T(Y.clientX - L.x, Y.clientY - L.y), + Y ); }); }); }), - (se.wheel = (l) => { - l.preventDefault(), + (he.wheel = (p) => { + p.preventDefault(), e.events.onOnce("input", () => { - e.events.trigger("scroll", new v(l.deltaX, l.deltaY)); + e.events.trigger("scroll", new T(p.deltaX, p.deltaY)); }); }), - (se.contextmenu = (l) => l.preventDefault()), - (le.visibilitychange = () => { + (he.contextmenu = (p) => p.preventDefault()), + (Ke.visibilitychange = () => { document.visibilityState === "visible" - ? ((e.skipTime = !0), e.events.trigger("show")) - : e.events.trigger("hide"); + ? ((e.skipTime = !0), (e.isHidden = !1), e.events.trigger("show")) + : ((e.isHidden = !0), e.events.trigger("hide")); }), - (ae.gamepadconnected = (l) => { - let x = _t(l.gamepad); + (xe.gamepadconnected = (p) => { + let S = Zt(p.gamepad); e.events.onOnce("input", () => { - e.events.trigger("gamepadConnect", x); + e.events.trigger("gamepadConnect", S); }); }), - (ae.gamepaddisconnected = (l) => { - let x = Vt().filter((R) => R.index === l.gamepad.index)[0]; - ne(l.gamepad), + (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", x); + e.events.trigger("gamepadDisconnect", S); }); }); - for (let l in se) e.canvas.addEventListener(l, se[l]); - for (let l in le) document.addEventListener(l, le[l]); - for (let l in ae) window.addEventListener(l, ae[l]); - let ge = new ResizeObserver((l) => { - for (let x of l) - if (x.target === e.canvas) { + 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 @@ -1954,116 +2816,117 @@ var kaplay = (() => { } }); return ( - ge.observe(e.canvas), + at.observe(e.canvas), { - dt: i, - time: c, - run: k, + dt: r, + time: a, + run: $, canvas: e.canvas, - fps: m, - numFrames: p, - quit: te, - setFullscreen: K, - isFullscreen: Q, - setCursor: I, - screenshot: P, - getGamepads: Vt, - getCursor: j, - setCursorLocked: y, - isCursorLocked: X, - isTouchscreen: pe, - mousePos: C, - mouseDeltaPos: Ae, - isKeyDown: Tt, - isKeyPressed: st, - isKeyPressedRepeat: an, - isKeyReleased: Ot, - isMouseDown: Te, - isMousePressed: $, - isMouseReleased: ye, - isMouseMoved: Se, - isGamepadButtonPressed: Rt, - isGamepadButtonDown: Ye, - isGamepadButtonReleased: un, - getGamepadStick: Pe, - charInputted: dt, - onResize: cn, - onKeyDown: hn, - onKeyPress: ln, - onKeyPressRepeat: dn, - onKeyRelease: fn, - onMouseDown: Pt, - onMousePress: Dt, - onMouseRelease: Mt, - onMouseMove: Gt, - onCharInput: Bt, - onTouchStart: mn, - onTouchMove: ct, - onTouchEnd: pn, - onScroll: gn, - onHide: Ft, - onShow: wn, - onGamepadButtonDown: It, - onGamepadButtonPress: Lt, - onGamepadButtonRelease: bn, - onGamepadStick: ht, - onGamepadConnect: vn, - onGamepadDisconnect: lt, + 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 Re = class n { + var qe = class t { static { - o(this, "Texture"); + i(this, "Texture"); } ctx; src = null; glTex; width; height; - constructor(e, i, c, m = {}) { + constructor(e, r, s, a = {}) { this.ctx = e; - let p = e.gl; + let l = e.gl; (this.glTex = e.gl.createTexture()), e.onDestroy(() => this.free()), - (this.width = i), - (this.height = c); - let P = - { linear: p.LINEAR, nearest: p.NEAREST }[ - m.filter ?? e.opts.texFilter - ] ?? p.NEAREST, - I = - { repeat: p.REPEAT, clampToEadge: p.CLAMP_TO_EDGE }[m.wrap] ?? - p.CLAMP_TO_EDGE; + (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(), - i && - c && - p.texImage2D( - p.TEXTURE_2D, + r && + s && + l.texImage2D( + l.TEXTURE_2D, 0, - p.RGBA, - i, - c, + l.RGBA, + r, + s, 0, - p.RGBA, - p.UNSIGNED_BYTE, + l.RGBA, + l.UNSIGNED_BYTE, null ), - p.texParameteri(p.TEXTURE_2D, p.TEXTURE_MIN_FILTER, P), - p.texParameteri(p.TEXTURE_2D, p.TEXTURE_MAG_FILTER, P), - p.texParameteri(p.TEXTURE_2D, p.TEXTURE_WRAP_S, I), - p.texParameteri(p.TEXTURE_2D, p.TEXTURE_WRAP_T, I), + 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, i, c = {}) { - let m = new n(e, i.width, i.height, c); - return m.update(i), (m.src = i), m; + 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, i = 0, c = 0) { - let m = this.ctx.gl; + update(e, r = 0, s = 0) { + let a = this.ctx.gl; this.bind(), - m.texSubImage2D(m.TEXTURE_2D, 0, i, c, m.RGBA, m.UNSIGNED_BYTE, e), + a.texSubImage2D(a.TEXTURE_2D, 0, r, s, a.RGBA, a.UNSIGNED_BYTE, e), this.unbind(); } bind() { @@ -2076,34 +2939,34 @@ var kaplay = (() => { this.ctx.gl.deleteTexture(this.glTex); } }, - rt = class { + yt = class { static { - o(this, "FrameBuffer"); + i(this, "FrameBuffer"); } ctx; tex; glFramebuffer; glRenderbuffer; - constructor(e, i, c, m = {}) { + constructor(e, r, s, a = {}) { this.ctx = e; - let p = e.gl; + let l = e.gl; e.onDestroy(() => this.free()), - (this.tex = new Re(e, i, c, m)), - (this.glFramebuffer = p.createFramebuffer()), - (this.glRenderbuffer = p.createRenderbuffer()), + (this.tex = new qe(e, r, s, a)), + (this.glFramebuffer = l.createFramebuffer()), + (this.glRenderbuffer = l.createRenderbuffer()), this.bind(), - p.renderbufferStorage(p.RENDERBUFFER, p.DEPTH_STENCIL, i, c), - p.framebufferTexture2D( - p.FRAMEBUFFER, - p.COLOR_ATTACHMENT0, - p.TEXTURE_2D, + l.renderbufferStorage(l.RENDERBUFFER, l.DEPTH_STENCIL, r, s), + l.framebufferTexture2D( + l.FRAMEBUFFER, + l.COLOR_ATTACHMENT0, + l.TEXTURE_2D, this.tex.glTex, 0 ), - p.framebufferRenderbuffer( - p.FRAMEBUFFER, - p.DEPTH_STENCIL_ATTACHMENT, - p.RENDERBUFFER, + l.framebufferRenderbuffer( + l.FRAMEBUFFER, + l.DEPTH_STENCIL_ATTACHMENT, + l.RENDERBUFFER, this.glRenderbuffer ), this.unbind(); @@ -2116,7 +2979,7 @@ var kaplay = (() => { } toImageData() { let e = this.ctx.gl, - i = new Uint8ClampedArray(this.width * this.height * 4); + r = new Uint8ClampedArray(this.width * this.height * 4); this.bind(), e.readPixels( 0, @@ -2125,28 +2988,32 @@ var kaplay = (() => { this.height, e.RGBA, e.UNSIGNED_BYTE, - i + r ), this.unbind(); - let c = this.width * 4, - m = new Uint8Array(c); - for (let p = 0; p < ((this.height / 2) | 0); p++) { - let P = p * c, - I = (this.height - p - 1) * c; - m.set(i.subarray(P, P + c)), i.copyWithin(P, I, I + c), i.set(m, I); + 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(i, this.width, this.height); + return new ImageData(r, this.width, this.height); } toDataURL() { let e = document.createElement("canvas"), - i = e.getContext("2d"); + r = e.getContext("2d"); return ( (e.width = this.width), (e.height = this.height), - i.putImageData(this.toImageData(), 0, 0), + 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(); } @@ -2167,36 +3034,36 @@ var kaplay = (() => { this.tex.free(); } }, - Qt = class { + hn = class { static { - o(this, "Shader"); + i(this, "Shader"); } ctx; glProgram; - constructor(e, i, c, m) { + constructor(e, r, s, a) { (this.ctx = e), e.onDestroy(() => this.free()); - let p = e.gl, - P = p.createShader(p.VERTEX_SHADER), - I = p.createShader(p.FRAGMENT_SHADER); - p.shaderSource(P, i), - p.shaderSource(I, c), - p.compileShader(P), - p.compileShader(I); - let j = p.createProgram(); + 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 = j), - p.attachShader(j, P), - p.attachShader(j, I), - m.forEach((y, X) => p.bindAttribLocation(j, X, y)), - p.linkProgram(j), - !p.getProgramParameter(j, p.LINK_STATUS)) + ((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 y = p.getShaderInfoLog(P); - if (y) throw new Error("VERTEX SHADER " + y); - let X = p.getShaderInfoLog(I); - if (X) throw new Error("FRAGMENT SHADER " + X); + 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); } - p.deleteShader(P), p.deleteShader(I); + l.deleteShader(u), l.deleteShader(f); } bind() { this.ctx.pushProgram(this.glProgram); @@ -2205,26 +3072,33 @@ var kaplay = (() => { this.ctx.popProgram(); } send(e) { - let i = this.ctx.gl; - for (let c in e) { - let m = e[c], - p = i.getUniformLocation(this.glProgram, c); - typeof m == "number" - ? i.uniform1f(p, m) - : m instanceof Ue - ? i.uniformMatrix4fv(p, !1, new Float32Array(m.m)) - : m instanceof W - ? i.uniform3f(p, m.r, m.g, m.b) - : m instanceof v && i.uniform2f(p, m.x, m.y); + 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); } }, - Zt = class { + pn = class { static { - o(this, "BatchRenderer"); + i(this, "BatchRenderer"); } ctx; glVBuf; @@ -2240,37 +3114,37 @@ var kaplay = (() => { curTex = null; curShader = null; curUniform = {}; - constructor(e, i, c, m) { - let p = e.gl; - (this.vertexFormat = i), + constructor(e, r, s, a) { + let l = e.gl; + (this.vertexFormat = r), (this.ctx = e), - (this.stride = i.reduce((P, I) => P + I.size, 0)), - (this.maxVertices = c), - (this.maxIndices = m), - (this.glVBuf = p.createBuffer()), + (this.stride = r.reduce((u, f) => u + f.size, 0)), + (this.maxVertices = s), + (this.maxIndices = a), + (this.glVBuf = l.createBuffer()), e.pushArrayBuffer(this.glVBuf), - p.bufferData(p.ARRAY_BUFFER, c * 4, p.DYNAMIC_DRAW), + l.bufferData(l.ARRAY_BUFFER, s * 4, l.DYNAMIC_DRAW), e.popArrayBuffer(), - (this.glIBuf = p.createBuffer()), + (this.glIBuf = l.createBuffer()), e.pushElementArrayBuffer(this.glIBuf), - p.bufferData(p.ELEMENT_ARRAY_BUFFER, m * 4, p.DYNAMIC_DRAW), + l.bufferData(l.ELEMENT_ARRAY_BUFFER, a * 4, l.DYNAMIC_DRAW), e.popElementArrayBuffer(); } - push(e, i, c, m, p = null, P = {}) { + push(e, r, s, a, l = null, u = {}) { (e !== this.curPrimitive || - p !== this.curTex || - m !== this.curShader || - !Xt(this.curUniform, P) || - this.vqueue.length + i.length * this.stride > this.maxVertices || - this.iqueue.length + c.length > this.maxIndices) && + 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 I = this.vqueue.length / this.stride; - for (let j of i) this.vqueue.push(j); - for (let j of c) this.iqueue.push(j + I); + 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 = m), - (this.curTex = p), - (this.curUniform = P); + (this.curShader = a), + (this.curTex = l), + (this.curUniform = u); } flush() { if ( @@ -2312,104 +3186,104 @@ var kaplay = (() => { e.deleteBuffer(this.glVBuf), e.deleteBuffer(this.glIBuf); } }; - function nt(n) { + function xt(t) { let e = [], - i = o((p) => { - e.push(p), n(p); + r = i((l) => { + e.push(l), t(l); }, "push"), - c = o(() => { - e.pop(), n(m() ?? null); + s = i(() => { + e.pop(), t(a() ?? null); }, "pop"), - m = o(() => e[e.length - 1], "cur"); - return [i, c, m]; + a = i(() => e[e.length - 1], "cur"); + return [r, s, a]; } - o(nt, "genStack"); - function Yn(n, e = {}) { - let i = []; - function c($) { - i.push($); + i(xt, "genStack"); + function dr(t, e = {}) { + let r = []; + function s(_) { + r.push(_); } - o(c, "onDestroy"); - function m() { - i.forEach(($) => $()), n.getExtension("WEBGL_lose_context").loseContext(); + i(s, "onDestroy"); + function a() { + r.forEach((_) => _()), t.getExtension("WEBGL_lose_context").loseContext(); } - o(m, "destroy"); - let p = null; - function P($) { - if (Xt($, p)) return; - p = $; - let Te = $.reduce((ye, Se) => ye + Se.size, 0); - $.reduce( - (ye, Se, st) => ( - n.vertexAttribPointer(st, Se.size, n.FLOAT, !1, Te * 4, ye), - n.enableVertexAttribArray(st), - ye + Se.size * 4 + 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 ); } - o(P, "setVertexFormat"); - let [I, j] = nt(($) => n.bindTexture(n.TEXTURE_2D, $)), - [y, X] = nt(($) => n.bindBuffer(n.ARRAY_BUFFER, $)), - [S, q] = nt(($) => n.bindBuffer(n.ELEMENT_ARRAY_BUFFER, $)), - [E, K] = nt(($) => n.bindFramebuffer(n.FRAMEBUFFER, $)), - [Q, te] = nt(($) => n.bindRenderbuffer(n.RENDERBUFFER, $)), - [k, pe] = nt(({ x: $, y: Te, w: ye, h: Se }) => { - n.viewport($, Te, ye, Se); + 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); }), - [C, Ae] = nt(($) => n.useProgram($)); + [O, se] = xt((_) => t.useProgram(_)); return ( - k({ x: 0, y: 0, w: n.drawingBufferWidth, h: n.drawingBufferHeight }), + N({ x: 0, y: 0, w: t.drawingBufferWidth, h: t.drawingBufferHeight }), { - gl: n, + gl: t, opts: e, - onDestroy: c, - destroy: m, - pushTexture2D: I, - popTexture2D: j, - pushArrayBuffer: y, - popArrayBuffer: X, - pushElementArrayBuffer: S, - popElementArrayBuffer: q, - pushFramebuffer: E, + onDestroy: s, + destroy: a, + pushTexture2D: f, + popTexture2D: y, + pushArrayBuffer: m, + popArrayBuffer: V, + pushElementArrayBuffer: x, + popElementArrayBuffer: P, + pushFramebuffer: w, popFramebuffer: K, - pushRenderbuffer: Q, - popRenderbuffer: te, - pushViewport: k, - popViewport: pe, - pushProgram: C, - popProgram: Ae, - setVertexFormat: P, + pushRenderbuffer: X, + popRenderbuffer: z, + pushViewport: N, + popViewport: $, + pushProgram: O, + popProgram: se, + setVertexFormat: u, } ); } - o(Yn, "initGfx"); - var ve = class n { + i(dr, "initGfx"); + var Re = class t { static { - o(this, "Asset"); + i(this, "Asset"); } loaded = !1; data = null; error = null; - onLoadEvents = new be(); - onErrorEvents = new be(); - onFinishEvents = new be(); + onLoadEvents = new we(); + onErrorEvents = new we(); + onFinishEvents = new we(); constructor(e) { - e.then((i) => { - (this.data = i), this.onLoadEvents.trigger(i); + e.then((r) => { + (this.loaded = !0), (this.data = r), this.onLoadEvents.trigger(r); }) - .catch((i) => { - if (((this.error = i), this.onErrorEvents.numListeners() > 0)) - this.onErrorEvents.trigger(i); - else throw i; + .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 i = new n(Promise.resolve(e)); - return (i.data = e), (i.loaded = !0), i; + let r = new t(Promise.resolve(e)); + return (r.data = e), (r.loaded = !0), r; } onLoad(e) { return ( @@ -2436,21 +3310,21 @@ var kaplay = (() => { return this.onFinish(e); } }, - je = class { + nt = class { static { - o(this, "AssetBucket"); + i(this, "AssetBucket"); } assets = new Map(); lastUID = 0; - add(e, i) { - let c = e ?? this.lastUID++ + "", - m = new ve(i); - return this.assets.set(c, m), m; + add(e, r) { + let s = e ?? this.lastUID++ + "", + a = new Re(r); + return this.assets.set(s, a), a; } - addLoaded(e, i) { - let c = e ?? this.lastUID++ + "", - m = ve.loaded(i); - return this.assets.set(c, m), m; + 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); @@ -2459,222 +3333,60 @@ var kaplay = (() => { if (this.assets.size === 0) return 1; let e = 0; return ( - this.assets.forEach((i) => { - i.loaded && e++; + this.assets.forEach((r) => { + r.loaded && e++; }), e / this.assets.size ); } }; - function Wn(n) { - return fetch(n).then((e) => { - if (!e.ok) throw new Error(`Failed to fetch "${n}"`); + function hr(t) { + return fetch(t).then((e) => { + if (!e.ok) throw new Error(`Failed to fetch "${t}"`); return e; }); } - o(Wn, "fetchURL"); - function Et(n) { - return Wn(n).then((e) => e.json()); + i(hr, "fetchURL"); + function Nt(t) { + return hr(t).then((e) => e.json()); } - o(Et, "fetchJSON"); - function Vr(n) { - return Wn(n).then((e) => e.text()); + i(Nt, "fetchJSON"); + function co(t) { + return hr(t).then((e) => e.text()); } - o(Vr, "fetchText"); - function _r(n) { - return Wn(n).then((e) => e.arrayBuffer()); + i(co, "fetchText"); + function uo(t) { + return hr(t).then((e) => e.arrayBuffer()); } - o(_r, "fetchArrayBuffer"); - function St(n) { + i(uo, "fetchArrayBuffer"); + function _t(t) { let e = new Image(); return ( (e.crossOrigin = "anonymous"), - (e.src = n), - new Promise((i, c) => { - (e.onload = () => i(e)), - (e.onerror = () => c(new Error(`Failed to load image from "${n}"`))); + (e.src = t), + new Promise((r, s) => { + (e.onload = () => r(e)), + (e.onerror = () => s(new Error(`Failed to load image from "${t}"`))); }) ); } - o(St, "loadImg"); - var en = 2.5949095, - kr = 1.70158 + 1, - Nr = (2 * Math.PI) / 3, - jr = (2 * Math.PI) / 4.5, - tn = { - linear: (n) => n, - easeInSine: (n) => 1 - Math.cos((n * Math.PI) / 2), - easeOutSine: (n) => Math.sin((n * Math.PI) / 2), - easeInOutSine: (n) => -(Math.cos(Math.PI * n) - 1) / 2, - easeInQuad: (n) => n * n, - easeOutQuad: (n) => 1 - (1 - n) * (1 - n), - easeInOutQuad: (n) => - n < 0.5 ? 2 * n * n : 1 - Math.pow(-2 * n + 2, 2) / 2, - easeInCubic: (n) => n * n * n, - easeOutCubic: (n) => 1 - Math.pow(1 - n, 3), - easeInOutCubic: (n) => - n < 0.5 ? 4 * n * n * n : 1 - Math.pow(-2 * n + 2, 3) / 2, - easeInQuart: (n) => n * n * n * n, - easeOutQuart: (n) => 1 - Math.pow(1 - n, 4), - easeInOutQuart: (n) => - n < 0.5 ? 8 * n * n * n * n : 1 - Math.pow(-2 * n + 2, 4) / 2, - easeInQuint: (n) => n * n * n * n * n, - easeOutQuint: (n) => 1 - Math.pow(1 - n, 5), - easeInOutQuint: (n) => - n < 0.5 ? 16 * n * n * n * n * n : 1 - Math.pow(-2 * n + 2, 5) / 2, - easeInExpo: (n) => (n === 0 ? 0 : Math.pow(2, 10 * n - 10)), - easeOutExpo: (n) => (n === 1 ? 1 : 1 - Math.pow(2, -10 * n)), - easeInOutExpo: (n) => - n === 0 - ? 0 - : n === 1 - ? 1 - : n < 0.5 - ? Math.pow(2, 20 * n - 10) / 2 - : (2 - Math.pow(2, -20 * n + 10)) / 2, - easeInCirc: (n) => 1 - Math.sqrt(1 - Math.pow(n, 2)), - easeOutCirc: (n) => Math.sqrt(1 - Math.pow(n - 1, 2)), - easeInOutCirc: (n) => - n < 0.5 - ? (1 - Math.sqrt(1 - Math.pow(2 * n, 2))) / 2 - : (Math.sqrt(1 - Math.pow(-2 * n + 2, 2)) + 1) / 2, - easeInBack: (n) => kr * n * n * n - 1.70158 * n * n, - easeOutBack: (n) => - 1 + kr * Math.pow(n - 1, 3) + 1.70158 * Math.pow(n - 1, 2), - easeInOutBack: (n) => - n < 0.5 - ? (Math.pow(2 * n, 2) * ((en + 1) * 2 * n - en)) / 2 - : (Math.pow(2 * n - 2, 2) * ((en + 1) * (n * 2 - 2) + en) + 2) / 2, - easeInElastic: (n) => - n === 0 - ? 0 - : n === 1 - ? 1 - : -Math.pow(2, 10 * n - 10) * Math.sin((n * 10 - 10.75) * Nr), - easeOutElastic: (n) => - n === 0 - ? 0 - : n === 1 - ? 1 - : Math.pow(2, -10 * n) * Math.sin((n * 10 - 0.75) * Nr) + 1, - easeInOutElastic: (n) => - n === 0 - ? 0 - : n === 1 - ? 1 - : n < 0.5 - ? -(Math.pow(2, 20 * n - 10) * Math.sin((20 * n - 11.125) * jr)) / 2 - : (Math.pow(2, -20 * n + 10) * Math.sin((20 * n - 11.125) * jr)) / 2 + - 1, - easeInBounce: (n) => 1 - tn.easeOutBounce(1 - n), - easeOutBounce: (n) => - n < 1 / 2.75 - ? 7.5625 * n * n - : n < 2 / 2.75 - ? 7.5625 * (n -= 1.5 / 2.75) * n + 0.75 - : n < 2.5 / 2.75 - ? 7.5625 * (n -= 2.25 / 2.75) * n + 0.9375 - : 7.5625 * (n -= 2.625 / 2.75) * n + 0.984375, - easeInOutBounce: (n) => - n < 0.5 - ? (1 - tn.easeOutBounce(1 - 2 * n)) / 2 - : (1 + tn.easeOutBounce(2 * n - 1)) / 2, - }, - Ct = tn; - var At = class { - static { - o(this, "TexPacker"); - } - textures = []; - canvas; - c2d; - x = 0; - y = 0; - curHeight = 0; - gfx; - constructor(e, i, c) { - (this.gfx = e), - (this.canvas = document.createElement("canvas")), - (this.canvas.width = i), - (this.canvas.height = c), - (this.textures = [Re.fromImage(e, this.canvas)]), - (this.c2d = this.canvas.getContext("2d")); - } - add(e) { - if (e.width > this.canvas.width || e.height > this.canvas.height) - throw new Error( - `Texture size (${e.width} x ${e.height}) exceeds limit (${this.canvas.width} x ${this.canvas.height})` - ); - this.x + e.width > this.canvas.width && - ((this.x = 0), (this.y += this.curHeight), (this.curHeight = 0)), - this.y + e.height > this.canvas.height && - (this.c2d.clearRect(0, 0, this.canvas.width, this.canvas.height), - this.textures.push(Re.fromImage(this.gfx, this.canvas)), - (this.x = 0), - (this.y = 0), - (this.curHeight = 0)); - let i = this.textures[this.textures.length - 1], - c = new v(this.x, this.y); - return ( - (this.x += e.width), - e.height > this.curHeight && (this.curHeight = e.height), - e instanceof ImageData - ? this.c2d.putImageData(e, c.x, c.y) - : this.c2d.drawImage(e, c.x, c.y), - i.update(this.canvas), - [ - i, - new oe( - c.x / this.canvas.width, - c.y / this.canvas.height, - e.width / this.canvas.width, - e.height / this.canvas.height - ), - ] - ); - } - free() { - for (let e of this.textures) e.free(); - } - }; - var Hr = - "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD0AAAA1CAYAAADyMeOEAAAAAXNSR0IArs4c6QAAAoVJREFUaIHdm7txwkAQhheGAqACiCHzOKQDQrqgILpwSAeEDBnEUAF0gCMxZ7G72qce/mec2Lpf9+3unaS78wgSNZ8uX5729+d1FNWXUuGmXlBOUUEIMckEpeQJgBu6C+BSFngztBR2vd+ovY+7g+p6LbgaWgJrAeUkDYIUXgXdBBwNi6kpABJwMTQH3AZsXRR8GHTfgEth8E3gjdAUcNewpbTgY85sCMCUuOokozE0YM0YRzM9NGAAXd8+omAF5h4lnmBRvpSnZHyLoLEbaN+aKB9KWv/KWw0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e4QkzF6FhCJEFbBn4i0iKswn11yenZiLLKeMRqQdWiZSmlkqrcV9d0gPfksAcqBW+2ZqAoq5gZGSrnTtGwlVmCIqUepxWxerj7iIyNZ7SgiKmJhJw7NJpRgiKmLuHl3KnReA4UIaU+y+WkcbzHQ1DEzMGQ9aJH0BDK6RE0y9wlTDp2HuppERQxc0FFBaZGUMTMB5UlQG/fHyk1odJEaBUUMXWh4oSoFRQxtaHyxMi2uBseQwUKciUoYuaAShTlkaCImQcqUph7QREzF/8DSS/2GZ2/N/sAAAAASUVORK5CYII="; - var zi = "3000.1.17", - Kr = + i(_t, "loadImg"); + var pr = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", - nn = "topleft", - Yr = 64, - Ki = "monospace", - rn = "monospace", - Yi = 36, - sn = 64, - on = 256, - Wr = 2048, - Xr = 2048, - Jr = 2048, - Qr = 2048, - Zr = 0.1, - Wi = 64, - Xn = "linear", - Xi = 8, - Ji = 4, - Zn = [ + 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 }, ], - Qi = Zn.reduce((n, e) => n + e.size, 0), - es = 2048, - Zi = es * 4 * Qi, - eo = es * 6, - to = ` + zi = gn.reduce((t, e) => t + e.size, 0), + mo = 2048, + ho = mo * 4 * zi, + po = mo * 6, + fo = ` attribute vec2 a_pos; attribute vec2 a_uv; attribute vec4 a_color; @@ -2697,7 +3409,7 @@ void main() { gl_Position = pos; } `, - no = ` + go = ` precision mediump float; varying vec2 v_pos; @@ -2719,52 +3431,1500 @@ void main() { } } `, - Jn = ` + bn = ` vec4 vert(vec2 pos, vec2 uv, vec4 color) { return def_vert(); } `, - Qn = ` + vn = ` vec4 frag(vec2 pos, vec2 uv, vec4 color, sampler2D tex) { return def_frag(); } `, - ro = new Set(["id", "require"]), - so = new Set([ + bo = new Set(["id", "require"]), + vo = new Set([ "add", "update", "draw", "destroy", "inspect", "drawInspect", - ]); - function ut(n) { - switch (n) { + ]), + fr = /\[(?