UNPKG

modern-canvas

Version:

A JavaScript WebGL rendering engine. only the ESM.

1,760 lines 334 kB
import { defineProperty as ts, Observable as ue, Reactivable as rs, parseColor as oi, property as h, isGradient as ni, isColorFillObject as Gr, clearUndef as ss, idGenerator as is, normalizeFill as li, isNone as V, normalizeBackground as ci, normalizeForeground as hi, normalizeOutline as ui, normalizeShadow as di, normalizeShape as pi, getDefaultStyle as fi, normalizeText as _i, normalizeTextContent as mi, getDefaultTextStyle as gi, getDefaultLayoutStyle as vi, RawWeakMap as bi } from "modern-idoc"; import { fonts as yi } from "modern-font"; import { extend as xi } from "colord"; import wi from "colord/plugins/names"; import { Path2D as Ct, Path2DSet as Pi, svgToDom as Ei, svgToPath2DSet as Si, Matrix3 as Vr, BoundingBox as Jt } from "modern-path2d"; import { Text as Ti, Character as Ri } from "modern-text"; const br = /* @__PURE__ */ new Map(); function b(r, e) { return function(t) { Object.defineProperty(t.prototype, "is", { value: r, enumerable: !0, configurable: !0 }), e && Object.keys(e).forEach((s) => { ts(t, s, { fallback: e[s] }); }), br.set(r, t); }; } function nc(r = "node", e = {}) { const t = br.get(r); if (!t) throw new Error(`Failed to createNode, tag: ${r}`); return new t().setProperties(e); } class B { static _queue = []; static _currentTime = 0; static _elapsed = 0; static _requestId; static get currentTime() { return this._currentTime; } static get elapsed() { return this._elapsed; } static on(e, t = {}) { const { sort: s = 0, once: i = !1 } = t; this._queue[s] || (this._queue[s] = []), this._queue[s].push({ cb: e, once: i }); } static off(e, t = {}) { const { sort: s = 0 } = t, i = this._queue[s]; if (!i) return; const a = []; for (let o = i.length, n = 0; n < o; n++) { const l = i[n]; l.cb !== e && a.push(l); } a.length ? this._queue[s] = a : this._queue.splice(s, 1); } static start() { "requestAnimationFrame" in globalThis && (this._currentTime = performance.now(), this._requestId = requestAnimationFrame((e) => this._update(e))); } static stop() { this._requestId && (cancelAnimationFrame(this._requestId), this._requestId = void 0); } static _update(e) { this._elapsed = e - this._currentTime, this._currentTime = e, this._requestId = requestAnimationFrame((t) => this._update(t)), this._performUpdate(); } static _performUpdate() { const e = this._queue, t = []; for (let s = e.length, i = s; i >= 0; i--) { const a = e[i]; if (!a) continue; const o = []; for (let n = a.length, l = 0; l < n; l++) { const c = a[l]; try { c.cb(); } catch (u) { console.warn(u); } c.once || o.push(c); } o.length && (t[i] = o); } this._queue = t; } } B.start(); async function as(r) { return new Promise((e) => { B.on( () => { r?.(), e(); }, { sort: 1, once: !0 } ); }); } const yr = Math.PI, z = yr * 2; function $r(r) { return !(r & r - 1) && !!r; } const Ai = /([\w-]+)\((.+?)\)/g, Ci = /[^,]+/g, Oi = /([-e.\d]+)(.*)/; function Hr(r) { return Array.isArray(r) ? r.map((e) => ({ name: e.name, args: e.args.map((t) => ({ ...t, normalizedIntValue: t.normalizedDefaultIntValue })) })) : { ...r, normalizedIntValue: r.normalizedDefaultIntValue }; } function Et(r, e, t = {}) { const s = zt(e, t); return s.length ? s : os(r, e, t); } function zt(r, e = {}) { const t = []; let s; for (; (s = Ai.exec(r)) !== null; ) { const [, i, a] = s; i && t.push({ name: i, args: Di(i, a, e) }); } return t; } function Di(r, e, t = {}) { const s = []; let i, a = 0; for (; (i = Ci.exec(e)) !== null; ) s.push( os(r, i[0], { ...t, index: a++ }) ); return s; } function os(r, e, t = {}) { const { width: s = 1, height: i = 1, index: a = 0 } = t, o = e.match(Oi), n = { unit: o?.[2] ?? null, value: e, intValue: Number(o?.[1]), normalizedIntValue: 0, normalizedDefaultIntValue: 0 }; switch (r) { case "scale": case "scaleX": case "scaleY": case "scale3d": n.normalizedDefaultIntValue = 1; break; } switch (n.unit) { case "%": n.normalizedIntValue = n.intValue / 100; break; case "rad": n.normalizedIntValue = n.intValue / z; break; case "deg": n.normalizedIntValue = n.intValue / 360; break; case "px": switch (a) { case 0: n.normalizedIntValue = n.intValue / s; break; case 1: n.normalizedIntValue = n.intValue / i; break; } break; // div fontSize default: n.normalizedIntValue = n.intValue; break; } return n; } const Ii = "WebGL2RenderingContext" in globalThis, Mi = "ImageBitmap" in globalThis, Ni = "ResizeObserver" in globalThis, Qe = "PointerEvent" in globalThis, ki = "WheelEvent" in globalThis, lc = "MouseEvent" in globalThis, ve = "ontouchstart" in globalThis, Ui = "onclick" in globalThis, cc = "createImageBitmap" in globalThis, ns = "AudioContext" in globalThis, ls = "webkitAudioContext" in globalThis, cs = "OfflineAudioContext" in globalThis, Bi = "webkitOfflineAudioContext" in globalThis, Li = ns || ls, xr = typeof window < "u", Fi = typeof navigator < "u" && navigator?.userAgent?.indexOf("Mac") >= 0, hs = globalThis.devicePixelRatio || 1, us = (r) => r !== null && typeof r == "object" && r.nodeType === 1, zi = (r) => us(r) && r.tagName === "VIDEO", hc = (r) => us(r) && r.tagName === "IMG"; function Gi(r) { return typeof r == "object" && r !== null && r.nodeType === 1 && r.tagName === "CANVAS"; } function Vi(r) { return Ii && r instanceof globalThis.WebGL2RenderingContext; } function $i() { if (xr) return globalThis.document.createElement("canvas"); } function Hi(r, e = globalThis.location) { if (r.startsWith("data:")) return ""; e = e || globalThis.location; const t = new URL(r, document.baseURI); return t.hostname !== e.hostname || t.port !== e.port || t.protocol !== e.protocol ? "anonymous" : ""; } function Xi(r, e, t) { t === null && !e.startsWith("data:") ? r.crossOrigin = Hi(e) : t !== !1 && (r.crossOrigin = typeof t == "string" ? t : "anonymous"); } let ji = 0; function tt() { return ++ji; } class Gt { cursor; // Event bubbles = !1; cancelBubble = !1; cancelable = !1; composed = !1; defaultPrevented = !1; eventPhase = Gt.prototype.NONE; isTrusted = !1; timeStamp = 0; type = ""; composedPath() { return this.path; } initEvent(...e) { throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API."); } preventDefault() { "preventDefault" in this.nativeEvent && this.nativeEvent.cancelable && this.nativeEvent.preventDefault(), this.defaultPrevented = !0; } propagationImmediatelyStopped = !1; stopImmediatePropagation() { this.propagationImmediatelyStopped = !0; } propagationStopped = !1; stopPropagation() { "stopPropagation" in this.nativeEvent && this.nativeEvent.stopPropagation(), this.propagationStopped = !0; } NONE = 0; CAPTURING_PHASE = 1; AT_TARGET = 2; BUBBLING_PHASE = 3; initUIEvent(...e) { throw new Error("initUIEvent() is a legacy DOM API. It is not implemented in the Federated Events API."); } } class Wi extends Gt { getModifierState(...e) { throw new Error("getModifierState() is a legacy DOM API. It is not implemented in the Federated Events API."); } initKeyboardEvent(...e) { throw new Error("initKeyboardEvent() is a legacy DOM API. It is not implemented in the Federated Events API."); } } class ds extends Gt { client = { x: 0, y: 0 }; get clientX() { return this.client.x; } get clientY() { return this.client.y; } layer = { x: 0, y: 0 }; get layerX() { return this.layer.x; } get layerY() { return this.layer.y; } movement = { x: 0, y: 0 }; get movementX() { return this.movement.x; } get movementY() { return this.movement.y; } offset = { x: 0, y: 0 }; get offsetX() { return this.offset.x; } get offsetY() { return this.offset.y; } page = { x: 0, y: 0 }; get pageX() { return this.page.x; } get pageY() { return this.page.y; } screen = { x: 0, y: 0 }; get screenX() { return this.screen.x; } get screenY() { return this.screen.y; } get x() { return this.clientX; } get y() { return this.clientY; } getModifierState(e) { return "getModifierState" in this.nativeEvent && this.nativeEvent.getModifierState(e); } initMouseEvent(...e) { throw new Error("Method not implemented."); } global = { x: 0, y: 0 }; get globalX() { return this.global.x; } get globalY() { return this.global.y; } } class qi extends ds { width = 0; height = 0; isPrimary = !1; getCoalescedEvents() { return this.type === "pointermove" || this.type === "mousemove" || this.type === "touchmove" ? [this] : []; } getPredictedEvents() { throw new Error("getPredictedEvents is not supported!"); } } class Yi extends ds { static DOM_DELTA_PIXEL = 0; DOM_DELTA_PIXEL = 0; static DOM_DELTA_LINE = 1; DOM_DELTA_LINE = 1; static DOM_DELTA_PAGE = 2; DOM_DELTA_PAGE = 2; } const Ki = { touchstart: "pointerdown", touchend: "pointerup", touchendoutside: "pointerupoutside", touchmove: "pointermove", touchcancel: "pointercancel" }; class Zi extends ue { /** * Current event */ event; target; cursor = "default"; cursorStyles = { default: "inherit", pointer: "pointer" }; setuped = !1; enableMoveEvent = !0; enableWheelEvent = !0; enableClickEvent = !0; setTarget(e) { this.removeEventListeners(), this.target = e, this.addEventListeners(); } removeEventListeners() { if (!this.setuped || !this.target) return; const e = this.target.style; globalThis.navigator.msPointerEnabled ? (e.msContentZooming = "", e.msTouchAction = "") : Qe && (e.touchAction = ""), Qe ? (this.target.removeEventListener("pointerdown", this._onPointerDown), this.target.removeEventListener("pointerleave", this._onPointerOver), this.target.removeEventListener("pointerover", this._onPointerOver), this.target.removeEventListener("pointermove", this._onPointerMove), this.target.removeEventListener("pointerup", this._onPointerUp)) : (this.target.removeEventListener("mousedown", this._onPointerDown), this.target.removeEventListener("mouseout", this._onPointerOver), this.target.removeEventListener("mouseover", this._onPointerOver), this.target.removeEventListener("mousemove", this._onPointerMove), this.target.removeEventListener("mouseup", this._onPointerUp)), ve && (this.target.removeEventListener("touchstart", this._onPointerDown), this.target.removeEventListener("touchmove", this._onPointerMove), this.target.removeEventListener("touchend", this._onPointerUp)), this.target.removeEventListener("wheel", this._onWheel), document.removeEventListener("keydown", this._onKeyDown), document.removeEventListener("keypress", this._onKeyPress), document.removeEventListener("keyup", this._onKeyUp), this.target = void 0, this.setuped = !1; } addEventListeners() { if (this.setuped || !this.target) return; const e = this.target.style; e && (globalThis.navigator.msPointerEnabled ? (e.msContentZooming = "none", e.msTouchAction = "none") : Qe && (e.touchAction = "none")), Qe ? (this.target.addEventListener("pointerdown", this._onPointerDown), this.target.addEventListener("pointerleave", this._onPointerOver), this.target.addEventListener("pointerover", this._onPointerOver), this.target.addEventListener("pointermove", this._onPointerMove), this.target.addEventListener("pointerup", this._onPointerUp)) : (this.target.addEventListener("mousedown", this._onPointerDown), this.target.addEventListener("mouseout", this._onPointerOver), this.target.addEventListener("mouseover", this._onPointerOver), this.target.addEventListener("mousemove", this._onPointerMove), this.target.addEventListener("mouseup", this._onPointerUp)), ve && (this.target.addEventListener("touchstart", this._onPointerDown), this.target.addEventListener("touchmove", this._onPointerMove), this.target.addEventListener("touchend", this._onPointerUp)), this.target.addEventListener("wheel", this._onWheel), document.addEventListener("keydown", this._onKeyDown), document.addEventListener("keypress", this._onKeyPress), document.addEventListener("keyup", this._onKeyUp), this.setuped = !0; } normalize(e) { const t = []; if (ve && e instanceof globalThis.TouchEvent) for (let s = 0, i = e.changedTouches.length; s < i; s++) { const a = e.changedTouches[s]; typeof a.button > "u" && (a.button = 0), typeof a.buttons > "u" && (a.buttons = 1), typeof a.isPrimary > "u" && (a.isPrimary = e.touches.length === 1 && e.type === "touchstart"), typeof a.width > "u" && (a.width = a.radiusX || 1), typeof a.height > "u" && (a.height = a.radiusY || 1), typeof a.tiltX > "u" && (a.tiltX = 0), typeof a.tiltY > "u" && (a.tiltY = 0), typeof a.pointerType > "u" && (a.pointerType = "touch"), typeof a.pointerId > "u" && (a.pointerId = a.identifier || 0), typeof a.pressure > "u" && (a.pressure = a.force || 0.5), typeof a.twist > "u" && (a.twist = 0), typeof a.tangentialPressure > "u" && (a.tangentialPressure = 0), typeof a.layerX > "u" && (a.layerX = a.offsetX = a.clientX), typeof a.layerY > "u" && (a.layerY = a.offsetY = a.clientY), a.type = e.type, t.push(a); } else if (ki && e instanceof globalThis.WheelEvent) t.push(e); else if (Qe && e instanceof globalThis.PointerEvent) t.push(e); else { const s = e; typeof s.isPrimary > "u" && (s.isPrimary = !0), typeof s.width > "u" && (s.width = 1), typeof s.height > "u" && (s.height = 1), typeof s.tiltX > "u" && (s.tiltX = 0), typeof s.tiltY > "u" && (s.tiltY = 0), typeof s.pointerType > "u" && (s.pointerType = "mouse"), typeof s.pointerId > "u" && (s.pointerId = 1), typeof s.pressure > "u" && (s.pressure = 0.5), typeof s.twist > "u" && (s.twist = 0), typeof s.tangentialPressure > "u" && (s.tangentialPressure = 0), t.push(s); } return t; } _clonePointerEvent(e) { const t = new qi(); return t.nativeEvent = e, t.pointerId = e.pointerId, t.width = e.width, t.height = e.height, t.isPrimary = e.isPrimary, t.pointerType = e.pointerType, t.pressure = e.pressure, t.tangentialPressure = e.tangentialPressure, t.tiltX = e.tiltX, t.tiltY = e.tiltY, t.twist = e.twist, t.isTrusted = e.isTrusted, this._copyMouseEvent(t, e), this.mapPositionToPoint(t.screen, e.clientX, e.clientY), t.global.x = t.screen.x, t.global.y = t.screen.y, t.offset.x = t.screen.x, t.offset.y = t.screen.y, t.type === "pointerleave" ? t.type = "pointerout" : t.type.startsWith("mouse") ? t.type = t.type.replace("mouse", "pointer") : t.type.startsWith("touch") && (t.type = Ki[t.type] || t.type), t; } _copyInputEvent(e, t) { e.nativeEvent = t, e.bubbles = t.bubbles, e.cancelBubble = t.cancelBubble, e.cancelable = t.cancelable, e.composed = t.composed, e.currentTarget = t.currentTarget, e.defaultPrevented = t.defaultPrevented, e.eventPhase = t.eventPhase, e.isTrusted = t.isTrusted, e.returnValue = t.returnValue, e.srcElement = t.srcElement, e.timeStamp = t.timeStamp, e.type = t.type; } _copyMouseEvent(e, t) { this._copyInputEvent(e, t), e.altKey = t.altKey, e.button = t.button, e.buttons = t.buttons, e.client.x = t.clientX, e.client.y = t.clientY, e.ctrlKey = t.ctrlKey, e.metaKey = t.metaKey, e.movement.x = t.movementX, e.movement.y = t.movementY, e.page.x = t.pageX, e.page.y = t.pageY, e.relatedTarget = null, e.shiftKey = t.shiftKey; } _cloneWheelEvent(e) { const t = new Yi(); return this._copyMouseEvent(t, e), t.wheelDeltaY = e.wheelDeltaY, t.deltaX = e.deltaX, t.deltaY = e.deltaY, t.deltaZ = e.deltaZ, t.deltaMode = e.deltaMode, this.mapPositionToPoint(t.screen, e.clientX, e.clientY), t.global.x = t.screen.x, t.global.y = t.screen.y, t.offset.x = t.screen.x, t.offset.y = t.screen.y, t; } _cloneKeyboardEvent(e) { const t = new Wi(); return this._copyInputEvent(t, e), t.altKey = e.altKey, t.charCode = e.charCode, t.code = e.code, t.ctrlKey = e.ctrlKey, t.isComposing = e.isComposing, t.key = e.key, t.keyCode = e.keyCode, t.location = e.location, t.metaKey = e.metaKey, t.repeat = e.repeat, t.shiftKey = e.shiftKey, t; } setCursor(e = "default") { if (!this.target || this.cursor === e) return; this.cursor = e; const t = !(globalThis.OffscreenCanvas && this.target instanceof OffscreenCanvas), s = this.cursorStyles[e]; if (s) switch (typeof s) { case "string": t && (this.target.style.cursor = s); break; case "function": s(e); break; case "object": t && Object.assign(this.target.style, s); break; } else t && typeof e == "string" && !Object.prototype.hasOwnProperty.call(this.cursorStyles, e) && (this.target.style.cursor = e); } mapPositionToPoint(e, t, s) { if (!this.target) return; const i = this.target.isConnected ? this.target.getBoundingClientRect() : void 0, a = Number(this.target.getAttribute("data-pixel-ratio")) || 1, o = Number(this.target.getAttribute("width")) || (i ? i.width * a : 0), n = Number(this.target.getAttribute("height")) || (i ? i.height * a : 0), l = i ?? { width: o, height: n, left: 0, top: 0 }, c = 1 / a; e.x = (t - l.left) * (o / l.width) * c, e.y = (s - l.top) * (n / l.height) * c; } _onKeyDown = (e) => { const t = this.normalize(e); for (let s = 0, i = t.length; s < i; s++) this.emit("keydown", this.event = this._cloneKeyboardEvent(t[s])); this.event?.cursor && this.setCursor(this.event.cursor); }; _onKeyPress = (e) => { const t = this.normalize(e); for (let s = 0, i = t.length; s < i; s++) this.emit("keypress", this.event = this._cloneKeyboardEvent(t[s])); this.event?.cursor && this.setCursor(this.event.cursor); }; _onKeyUp = (e) => { const t = this.normalize(e); for (let s = 0, i = t.length; s < i; s++) this.emit("keyup", this.event = this._cloneKeyboardEvent(t[s])); this.event?.cursor && this.setCursor(this.event.cursor); }; _onPointerDown = (e) => { if (ve && e.pointerType === "touch") return; const t = this.normalize(e); for (let s = 0, i = t.length; s < i; s++) this.emit("pointerdown", this.event = this._clonePointerEvent(t[s])); this.event?.cursor && this.setCursor(this.event.cursor); }; _onPointerOver = (e) => { if (!this.enableClickEvent || ve && e.pointerType === "touch") return; const t = this.normalize(e); for (let s = 0, i = t.length; s < i; s++) this.emit("pointerover", this.event = this._clonePointerEvent(t[s])); this.event?.cursor && this.setCursor(this.event.cursor); }; _onPointerMove = (e) => { if (!this.enableMoveEvent || ve && e.pointerType === "touch") return; const t = this.normalize(e); for (let s = 0, i = t.length; s < i; s++) this.emit("pointermove", this.event = this._clonePointerEvent(t[s])); this.event?.cursor && this.setCursor(this.event.cursor); }; _onPointerUp = (e) => { if (!this.enableClickEvent || ve && e.pointerType === "touch") return; let t = e.target; e.composedPath && e.composedPath().length > 0 && (t = e.composedPath()[0]); const s = t !== this.target ? "outside" : "", i = this.normalize(e); for (let a = 0, o = i.length; a < o; a++) { const n = this._clonePointerEvent(i[a]); n.type += s, this.emit("pointerup", this.event = n); } this.event?.cursor && this.setCursor(this.event.cursor); }; _onWheel = (e) => { if (!this.enableWheelEvent) return; const t = this.normalize(e); for (let s = 0, i = t.length; s < i; s++) this.emit("wheel", this.event = this._cloneWheelEvent(t[s])); this.event?.cursor && this.setCursor(this.event.cursor); }; destroy() { this.removeEventListeners(), super.destroy(); } } class Ee extends rs { instanceId = tt(); get json() { return this.toJSON(); } set json(e) { this.setProperties(e); } _nextTick() { return as(); } equal(e) { return !!(e && this.instanceId === e.instanceId); } } class Ji extends Ee { // } class de extends Ji { // } class le extends ue { constructor(e, t, s) { super(), this.rows = e, this.cols = t, s ? this.set(s) : this.identity(); } _array = []; dirtyId = 0; get length() { return this.cols * this.rows; } operate(e, t, s) { const { cols: i, rows: a, length: o, _array: n } = this; let l; typeof t == "number" ? l = Array.from({ length: o }, () => t) : t instanceof Q || t instanceof le ? l = t.toArray() : l = t; let c, u = []; if (s ? s instanceof Q || s instanceof le ? c = s : u = s : t instanceof Q ? c = new t.constructor() : c = this, t instanceof Q) { const { dim: d } = t; switch (e) { case "*": for (let p = 0; p < d; p++) { let m = 0; for (let f = 0; f < i; f++) f < d && (m += n[p * i + f] * (l[f] ?? 0)); u[p] = m; } break; default: throw new Error(`Not support operator in '${this.toName()} ${e} ${t.toName()}'`); } } else switch (e) { case "*": for (let d = 0; d < i; d++) for (let p = 0; p < a; p++) { const m = p * i; let f = 0; for (let _ = 0; _ < a; _++) { const g = m + _, v = _ * i + d; f += n[g] * (l[v] ?? 0); } u[m + d] = f; } break; case "=": for (let d = 0; d < o; d++) { const p = l[d]; p !== void 0 && (n[d] = p); } return this._onUpdate(n), this.emit("update", n), this; default: throw new Error(`Not support operator in '${this.toName()} ${e} Matrix2'`); } return c?.set(u) ?? u; } identity() { const { cols: e, rows: t } = this, s = []; for (let i = 0; i < e; i++) for (let a = 0; a < t; a++) { const o = a * e, n = i + o; s[n] = a + o === n ? 1 : 0; } return this.set(s); } set(e) { return this.operate("=", e); } copy(e) { return this.set(e); } clone() { const e = new this.constructor(); return e.set(this.toArray()), e; } multiply(e, t) { return this.operate("*", e, t); } _onUpdate(e) { this.dirtyId++; } toArray(e = !1) { const { cols: t, rows: s, _array: i } = this; if (e) { const a = []; for (let o = 0; o < s; o++) for (let n = 0; n < t; n++) a[o + n * t] = i[n + o * t]; return a; } return i.slice(); } toFloat32Array(e) { return new Float32Array(this.toArray(e)); } toName() { return `Matrix${this.rows}(${this.rows}x${this.cols})`; } toJSON() { return this._array.slice(); } } class Q extends ue { constructor(e) { super(), this.dim = e; } _array = []; get length() { return this.dim; } operate(e, t, s) { const { dim: i, _array: a } = this; let o; typeof t == "number" ? o = Array.from({ length: i }, () => t) : t instanceof le || t instanceof Q ? o = t.toArray() : o = t; let n, l = []; if (s ? s instanceof Q ? n = s : l = s : n = this, t instanceof le) { const { cols: c } = t; switch (e) { case "*": for (let u = 0; u < i; u++) { let d = 0; for (let p = 0; p < i; p++) d += a[u] * o[p * c + u]; l[u] = d; } break; default: throw new Error(`Not support operator in '${this.toName()} ${e} ${t.toName()}'`); } } else switch (e) { case "+": for (let c = 0; c < i; c++) l[c] = a[c] + o[c]; break; case "-": for (let c = 0; c < i; c++) l[c] = a[c] - o[c]; break; case "*": for (let c = 0; c < i; c++) l[c] = a[c] * o[c]; break; case "/": for (let c = 0; c < i; c++) l[c] = a[c] / o[c]; break; case "rot": { const c = Math.cos(o[0]), u = Math.sin(o[0]); l[0] = a[0] * c - a[1] * u, l[1] = a[1] * c + a[0] * u; break; } case "==": { let c = !0; for (let u = 0; u < i; u++) c = c && a[u] === o[u]; return c; } case "=": for (let c = 0; c < i; c++) { const u = o[c]; u !== void 0 && (a[c] = u); } return this._onUpdate(a), this.emit("update", a), this; default: throw new Error(`Not support operator in '${this.toName()} ${e} Vector'`); } return n?.set(l) ?? l; } add(e, ...t) { return t.length && typeof e == "number" && (e = [e, ...t]), this.operate("+", e); } sub(e, ...t) { return t.length && typeof e == "number" && (e = [e, ...t]), this.operate("-", e); } multiply(e, ...t) { return t.length && typeof e == "number" && (e = [e, ...t]), this.operate("*", e); } divide(e, ...t) { return t.length && typeof e == "number" && (e = [e, ...t]), this.operate("/", e); } rotate(e) { return this.operate("rot", e); } set(e, ...t) { return t.length && typeof e == "number" && (e = [e, ...t]), this.operate("=", e); } equals(e) { return this.operate("==", e); } copy(e) { return this.set(e); } clone() { const e = new this.constructor(); return e.set(this.toArray()), e; } _onUpdate(e) { } toName() { return `Vector${this.dim}`; } toArray() { return this._array.slice(); } toFloat32Array() { return new Float32Array(this._array); } toJSON() { return this.toArray(); } } class O extends Q { get x() { return this._array[0]; } set x(e) { const [t, s] = this._array; t !== e && this.set(e, s); } get y() { return this._array[1]; } set y(e) { const [t, s] = this._array; s !== e && this.set(t, e); } get width() { return this.x; } set width(e) { this.x = e; } get height() { return this.y; } set height(e) { this.y = e; } get left() { return this.x; } set left(e) { this.x = e; } get top() { return this.y; } set top(e) { this.y = e; } constructor(e = 0, t) { super(2), this.set(typeof e == "number" ? [e, t ?? e] : e); } update(e, t) { const [s, i] = this._array; return (s !== e || i !== t) && this.set(e, t), this; } getLength() { const [e, t] = this._array; return Math.sqrt(e * e + t * t); } getAngle() { const [e, t] = this._array; return Math.atan2(-e, -t) + Math.PI; } distanceTo(e) { return Math.hypot(e.x - this.x, e.y - this.y); } normalize() { const [e, t] = this._array, s = 1 / (this.getLength() || 1); return this.set(e * s, t * s), this; } static lerp(e, t, s) { return new O(t).clone().sub(e).multiply(s).add(e); } } class ee { get x() { return this.min.x; } set x(e) { this.min.x = e; } get y() { return this.min.y; } set y(e) { this.min.y = e; } get left() { return this.min.x; } set left(e) { this.min.x = e; } get top() { return this.min.y; } set top(e) { this.min.y = e; } get right() { return this.x + this.width; } set right(e) { this.size.x = Math.max(0, e - this.min.x); } get bottom() { return this.y + this.height; } set bottom(e) { this.size.y = Math.max(0, e - this.min.y); } get width() { return this.size.x; } set width(e) { this.size.x = Math.max(0, e); } get height() { return this.size.y; } set height(e) { this.size.y = Math.max(0, e); } max = new O(); min; size; constructor(...e) { const t = new O(), s = new O(); switch (e.length) { case 0: break; case 1: { const i = e[0]; if (Array.isArray(i)) { const a = i.map((d) => d.x), o = i.map((d) => d.y), n = Math.min(...a), l = Math.max(...a), c = Math.min(...o), u = Math.max(...o); t.set(n, c), s.set(l - n, u - c); } else t.set(i.x, i.y), s.set(Math.max(0, i.width), Math.max(0, i.height)); break; } case 2: t.set(e[0]), s.set(Math.max(0, e[1])); break; default: t.set(e[0], e[1]), s.set(Math.max(0, e[2]), Math.max(0, e[3])); break; } this.update = this.update.bind(this), this.min = t.on("update", this.update), this.size = s.on("update", this.update), this.update(); } update() { return this.max.set( this.min.x + this.size.x, this.min.y + this.size.y ), this; } overlapsOnAxis(e, t) { switch (t) { case "horizontal": return this.max.x >= e.min.x && e.max.x >= this.min.x; case "vertical": return this.max.y >= e.min.y && e.max.y >= this.min.y; default: return this.overlapsOnAxis(e, "horizontal") && this.overlapsOnAxis(e, "vertical"); } } containsPoint(e) { return e.x >= this.min.x && e.x <= this.max.x && e.y >= this.min.y && e.y <= this.max.y; } getIntersectionRect(e) { const t = this.toMinmax(), s = e.toMinmax(), i = Math.max(t.min.x, s.min.x), a = Math.max(t.min.y, s.min.y), o = Math.min(t.max.x, s.max.x), n = Math.min(t.max.y, s.max.y); return o <= i || n <= a ? new ee() : new ee( i, a, Math.max(0, o - i), Math.max(0, n - a) ); } getArea() { return this.width * this.height; } toMinmax() { return { min: this.min.clone(), max: this.max.clone() }; } toCssStyle() { return { left: `${this.left}px`, top: `${this.top}px`, width: `${this.width}px`, height: `${this.height}px` }; } toArray() { return [this.x, this.y, this.width, this.height]; } toJSON() { return { x: this.x, y: this.y, width: this.width, height: this.height }; } clone() { return new ee(this.toJSON()); } } xi([wi]); class ne { get value() { return this._value; } set value(e) { this._colord = oi(e ?? "none"); } get r8() { return this._colord.rgba.r; } get g8() { return this._colord.rgba.g; } get b8() { return this._colord.rgba.b; } get a8() { return this._colord.rgba.a * 255 & 255; } get r() { return this.r8 / 255; } get g() { return this.g8 / 255; } get b() { return this.b8 / 255; } get a() { return this._colord.rgba.a; } get rgb() { return (this.r8 << 16) + (this.g8 << 8) + this.b8; } get bgr() { return (this.b8 << 16) + (this.g8 << 8) + this.r8; } get abgr() { return (this.a8 << 24) + this.bgr; } constructor(e = 0) { this.value = e; } toHex() { return this._colord.toHex(); } toRgb() { return this._colord.toRgb(); } toRgbString() { return this._colord.toRgbString(); } toHsl() { return this._colord.toHsl(); } toHslString() { return this._colord.toHslString(); } toHsv() { return this._colord.toHsv(); } toArgb(e = this.a, t = !0) { if (e === 1) return (255 << 24) + this.rgb; if (e === 0) return t ? 0 : this.rgb; let s = this.r8, i = this.g8, a = this.b8; return t && (s = s * e + 0.5 | 0, i = i * e + 0.5 | 0, a = a * e + 0.5 | 0), (e * 255 << 24) + (s << 16) + (i << 8) + a; } toInt8Array() { return [this.r8, this.g8, this.b8, this.a8]; } toArray() { return [this.r, this.g, this.b, this.a]; } } class Qi extends le { constructor(e) { super(4, 4, e); } } const pr = yr / 180, uc = 180 / yr; function ce(r, e, t) { return Math.max(e, Math.min(r, t)); } function A(r, e, t) { return (1 - t) * r + t * e; } const dc = { adaptive: !0, maxLength: 10, minSegments: 8, maxSegments: 2048, epsilon: 1e-4, _segmentsCount(r, e = 20) { if (!this.adaptive || !r || Number.isNaN(r)) return e; let t = Math.ceil(r / this.maxLength); return t < this.minSegments ? t = this.minSegments : t > this.maxSegments && (t = this.maxSegments), t; } }; class ea extends Q { constructor(e = 0, t = 0, s = 0, i = 0) { super(4), this.set(e, t, s, i); } } class ps extends le { constructor(e) { super(4, 5, e); } hueRotate(e = 0) { const t = Math.sin(e), s = Math.cos(e), i = 0.213, a = 0.715, o = 0.072; return this.multiply([ i + s * (1 - i) + t * -i, a + s * -a + t * -a, o + s * -o + t * (1 - o), 0, 0, i + s * -i + t * 0.143, a + s * (1 - a) + t * 0.14, o + s * -o + t * -0.283, 0, 0, i + s * -i + t * -0.787, a + s * -a + t * a, o + s * (1 - o) + t * o, 0, 0, 0, 0, 0, 1, 0 ]); } saturate(e = 1) { const t = (e - 1) * 2 / 3 + 1, s = (t - 1) * -0.5; return this.multiply([ t, s, s, 0, 0, s, t, s, 0, 0, s, s, t, 0, 0, 0, 0, 0, 1, 0 ]); } brightness(e = 1) { const t = e; return this.multiply([ t, 0, 0, 0, 0, 0, t, 0, 0, 0, 0, 0, t, 0, 0, 0, 0, 0, 1, 0 ]); } contrast(e = 1) { const t = e, s = -128 * (t - 1); return this.multiply([ t, 0, 0, 0, s, 0, t, 0, 0, s, 0, 0, t, 0, s, 0, 0, 0, 1, 0 ]); } invert(e = 1) { const t = A(1, -1, e), s = A(0, 255, e); return this.multiply([ t, 0, 0, 0, s, 0, t, 0, 0, s, 0, 0, t, 0, s, 0, 0, 0, 1, 0 ]); } sepia(e = 1) { const t = ce(e, 0, 1); return this.multiply([ A(1, 0.393, t), A(0, 0.7689999, t), A(0, 0.18899999, t), 0, 0, A(0, 0.349, t), A(1, 0.6859999, t), A(0, 0.16799999, t), 0, 0, A(0, 0.272, t), A(0, 0.5339999, t), A(1, 0.13099999, t), 0, 0, 0, 0, 0, 1, 0 ]); } opacity(e = 1) { return this.multiply([ 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, e, 0 ]); } grayscale(e = 1) { const t = ce(e, 0, 1), s = A(1, 0.3, t), i = A(0, 0.3, t), a = A(1, 0.59, t), o = A(0, 0.59, t), n = A(1, 0.11, t), l = A(0, 0.11, t); return this.multiply([ s, o, l, 0, 0, i, a, l, 0, 0, i, o, n, 0, 0, 0, 0, 0, 1, 0 ]); } multiply(e) { const t = e, s = this._array; return this.set([ // Red Channel s[0] * t[0] + s[1] * t[5] + s[2] * t[10] + s[3] * t[15], s[0] * t[1] + s[1] * t[6] + s[2] * t[11] + s[3] * t[16], s[0] * t[2] + s[1] * t[7] + s[2] * t[12] + s[3] * t[17], s[0] * t[3] + s[1] * t[8] + s[2] * t[13] + s[3] * t[18], s[0] * t[4] + s[1] * t[9] + s[2] * t[14] + s[3] * t[19] + s[4], // Green Channel s[5] * t[0] + s[6] * t[5] + s[7] * t[10] + s[8] * t[15], s[5] * t[1] + s[6] * t[6] + s[7] * t[11] + s[8] * t[16], s[5] * t[2] + s[6] * t[7] + s[7] * t[12] + s[8] * t[17], s[5] * t[3] + s[6] * t[8] + s[7] * t[13] + s[8] * t[18], s[5] * t[4] + s[6] * t[9] + s[7] * t[14] + s[8] * t[19] + s[9], // Blue Channel s[10] * t[0] + s[11] * t[5] + s[12] * t[10] + s[13] * t[15], s[10] * t[1] + s[11] * t[6] + s[12] * t[11] + s[13] * t[16], s[10] * t[2] + s[11] * t[7] + s[12] * t[12] + s[13] * t[17], s[10] * t[3] + s[11] * t[8] + s[12] * t[13] + s[13] * t[18], s[10] * t[4] + s[11] * t[9] + s[12] * t[14] + s[13] * t[19] + s[14], // Alpha Channel s[15] * t[0] + s[16] * t[5] + s[17] * t[10] + s[18] * t[15], s[15] * t[1] + s[16] * t[6] + s[17] * t[11] + s[18] * t[16], s[15] * t[2] + s[16] * t[7] + s[17] * t[12] + s[18] * t[17], s[15] * t[3] + s[16] * t[8] + s[17] * t[13] + s[18] * t[18], s[15] * t[4] + s[16] * t[9] + s[17] * t[14] + s[18] * t[19] + s[19] ]); } toMatrix4() { const e = this._array; return new Qi([ e[0], e[1], e[2], e[3], e[5], e[6], e[7], e[8], e[10], e[11], e[12], e[13], e[15], e[16], e[17], e[18] ]); } toVector4() { const e = this._array; return new ea(e[4] / 255, e[9] / 255, e[14] / 255, e[19] / 255); } } class pc extends le { constructor(e) { super(2, 2, e); } } class fs extends le { constructor(e) { super(3, 3, e); } affineInvert() { const [ e, t, s, i, a, o, n, l, c ] = this._array, u = c * a - o * l, d = o * n - c * i, p = l * i - a * n, m = e * u + t * d + s * p; if (m === 0) return this.set([ 0, 0, 0, 0, 0, 0, 0, 0, 0 ]); const f = 1 / m; return this.set([ u * f, (s * l - c * t) * f, (o * t - s * a) * f, d * f, (c * e - s * n) * f, (s * i - o * e) * f, p * f, (t * n - l * e) * f, (a * e - t * i) * f ]); } } class Dt extends ee { /** * Rotation radians */ rotation; get rotationDegrees() { return this.rotation / pr; } constructor(...e) { let t, s; e.length === 0 || (e.length === 1 ? (s = e[0], t = e[0].rotation) : e.length === 2 && (s = e[0], t = e[1])), s ? super(s) : super(), this.rotation = t ?? 0; } overlapsOnAxis(e, t) { if (!this.rotation && (!("rotation" in e) || !e.rotation)) return super.overlapsOnAxis(e, t); { const s = (l, c) => Math.abs(l.x * c.x + l.y * c.y), i = (l) => { const { width: c, height: u, rotation: d = 0 } = l; let p = d / pr; p = -p % 180; const m = p / 180 * Math.PI, f = { x: Math.cos(m), y: -Math.sin(m) }, _ = { x: Math.sin(m), y: Math.cos(m) }; return { axis: [f, _], projectionRadius: (g) => c / 2 * s(g, f) + u / 2 * s(g, _) }; }, a = i(this), o = i(e), n = { x: this.left + this.width / 2 - (e.left + e.width / 2), y: this.top + this.height / 2 - (e.top + e.height / 2) }; for (const l of [...a.axis, ...o.axis]) if (a.projectionRadius(l) + o.projectionRadius(l) < s(l, n)) return !1; return !0; } } toCssStyle() { return { ...super.toCssStyle(), transform: `rotate(${this.rotationDegrees}deg)` }; } toArray() { return [...super.toArray(), this.rotation]; } toJSON() { return { x: this.x, y: this.y, width: this.width, height: this.height, rotation: this.rotation }; } clone() { return new Dt(this.toJSON()); } } class ta extends fs { constructor(e = 0, t = 0, s = 0, i = 0, a = !1) { super(), this._x = e, this._y = t, this._width = s, this._height = i, this._flipY = a, this._performUpdateArray(); } flipY(e) { return this._flipY !== e && (this._flipY = e, this._performUpdateArray()), this; } translate(e, t) { return (this._x !== e || this._y !== t) && (this._x = e, this._y = t, this._performUpdateArray()), this; } resize(e, t) { return (this._width !== e || this._height !== t) && (this._width = e, this._height = t, this._performUpdateArray()), this; } _performUpdateArray() { const e = this._width, t = this._height; if (!e || !t) return; const s = this._x, i = this._y, a = this._flipY ? -1 : 1, o = 1 / e * 2, n = a * (1 / t * 2), l = -1 - s * o, c = -a - i * n; this.set([ o, 0, l, 0, n, c, 0, 0, 1 ]); } } class M extends fs { static _t2d = /* @__PURE__ */ new M(); premultiply(e) { return e.multiply(this, this); } skewX(e) { return this.skew(e, 0); } skewY(e) { return this.skew(0, e); } skew(e, t) { return this.premultiply(M._t2d.makeSkew(e, t)); } makeSkew(e, t) { const s = Math.tan(e), i = Math.tan(t); return this.set([ 1, i, 0, s, 1, 0, 0, 0, 1 ]), this; } translateX(e) { return this.translate(e, 0); } translateY(e) { return this.translate(0, e); } translateZ(e) { return this.translate(0, 0, e); } translate3d(e, t, s) { return this.translate(e, t, s); } translate(e, t, s = 0) { return this.premultiply(M._t2d.makeTranslation(e, t, s)); } makeTranslation(e, t, s = 0) { return this.set([ 1, 0, e, 0, 1, t, 0, 0, 1 ]), this; } scaleX(e) { return this.scale(e, 1); } scaleY(e) { return this.scale(1, e); } scale3d(e, t, s = 1) { return this.scale(e, t, s); } scale(e, t, s = 1) { return this.premultiply(M._t2d.makeScale(e, t, s)); } makeScale(e, t, s = 1) { return this.set([ e, 0, 0, 0, t, 0, 0, 0, 1 ]), this; } rotateX(e) { return this.scaleY(this._rotateToScale(e)); } rotateY(e) { return this.scaleX(this._rotateToScale(e)); } rotateZ(e) { return this.rotate(e); } rotate(e) { return this.premultiply(M._t2d.makeRotation(e)); } rotate3d(e, t, s, i) { const [a, o, n] = this._rotate3d(e, t, s, i); return a && this.rotateX(a), o && this.rotateY(o), n && this.rotateZ(n), this; } _rotateToScale(e) { const t = e / z; return t <= 0.5 ? t * -4 + 1 : (t - 1) * 4 + 1; } _rotate3d(e, t, s, i) { if (e === 1 && t === 0 && s === 0) return [i, 0, 0]; if (e === 0 && t === 1 && s === 0) return [0, i, 0]; if (e === 0 && t === 0) return [0, 0, i]; { const a = Math.cos(i), o = Math.sin(i), n = a + e * e * (1 - a), l = e * t * (1 - a) - s * o, c = e * s * (1 - a) + t * o, u = a + t * t * (1 - a), d = t * s * (1 - a) - e * o, p = a + s * s * (1 - a), m = -Math.atan2(-d, u), f = -Math.atan2(c, Math.sqrt(d * d + p * p)), _ = -Math.atan2(-l, n); return [m, f, _]; } } makeRotation(e) { const t = Math.cos(e), s = Math.sin(e); return this.set([ t, -s, 0, s, t, 0, 0, 0, 1 ]), this; } decompose(e = { x: 0, y: 0 }, t = { position: { x: 0, y: 0 }, scale: { x: 0, y: 0 }, skew: { x: 0, y: 0 }, rotation: 0 }) { const { a: s, b: i, c: a, d: o, tx: n, ty: l } = this.toObject(), c = -Math.atan2(-a, o), u = Math.atan2(i, s), d = Math.abs(c + u); return d < 1e-5 || Math.abs(z - d) < 1e-5 ? (t.rotation = u, t.skew.x = t.skew.y = 0) : (t.rotation = 0, t.skew.x = c, t.skew.y = u), t.scale.x = Math.sqrt(s * s + i * i), t.scale.y = Math.sqrt(a * a + o * o), t.position.x = n + (e.x * s + e.y * a), t.position.y = l + (e.x * i + e.y * o), t; } apply(e, t) { t = t || new O(); const { a: s, c: i, tx: a, b: o, d: n, ty: l } = this.toObject(), { x: c, y: u } = e; return t.x = s * c + i * u + a, t.y = o * c + n * u + l, t; } affineInverse() { return this.clone().affineInvert(); } applyAffineInverse(e, t) { t = t || new O(); const { a: s, b: i, c: a, d: o, tx: n, ty: l } = this.toObject(), c = 1 / (s * o + a * -i), u = e.x, d = e.y; return t.x = o * c * u + -a * c * d + (l * a - n * o) * c, t.y = s * c * d + -i * c * u + (-l * s + n * i) * c, t; } isIdentity() { const { a: e, b: t, c: s, d: i, tx: a, ty: o } = this.toObject(); return e === 1 && t === 0 && s === 0 && i === 1 && a === 0 && o === 0; } toObject() { const [ e, t, s, i, a, o, , , n ] = this._array; return { a: e, c: t, tx: s, b: i, d: a, ty: o, tz: n }; } } class fc extends Q { constructor() { super(3); } } var ra = Object.defineProperty, _s = (r, e, t, s) => { for (var i = void 0, a = r.length - 1, o; a >= 0; a--) (o = r[a]) && (i = o(e, t, i) || i); return i && ra(e, t, i), i; }; class wr extends Ee { _starting = !1; _nextDeltaTime = 0; _startedProcess; get starting() { return this._starting; } get spf() { return this.fps ? Math.floor(1e3 / this.fps) : 0; } constructor(e) { super(), this._onTicker = this._onTicker.bind(this), this.setProperties(e); } start(e) { this._starting || (this._starting = !0, this._startedProcess && this.off("process", this._startedProcess), this._startedProcess = e, this.on("process", e), B.on(this._onTicker, { sort: 0 })); } stop() { this._starting && (this._starting = !1, B.off(this._onTicker, { sort: 0 })); } _onTicker() { const e = B.elapsed * this.speed; if ((this._nextDeltaTime -= e) <= 0) { const s = (this._nextDeltaTime = this.spf) || e; this.emit("process", s); } } destroy() { this.stop(), super.destroy(); } } _s([ h({ fallback: 60 }) ], wr.prototype, "fps"); _s([ h({ fallback: 1 }) ], wr.prototype, "speed"); var st = /* @__PURE__ */ ((r) => (r[r.elementArrayBuffer = 34963] = "elementArrayBuffer", r[r.arrayBuffer = 34962] = "arrayBuffer", r[r.uniformBuffer = 35345] = "uniformBuffer", r))(st || {}); class sa { constructor(e) { this.native = e; } target = st.arrayBuffer; byteLength = 0; dirty = !0; } var be = /* @__PURE__ */ ((r) => (r[r.mapRead = 1] = "mapRead", r[r.mapWrite = 2] = "mapWrite", r[r.copySrc = 4] = "copySrc", r[r.copyDst = 8] = "copyDst", r[r.index = 16] = "index", r[r.vertex = 32] = "vertex", r[r.uniform = 64] = "uniform", r[r.storage = 128] = "storage", r[r.indirect = 256] = "indirect", r[r.queryResolve = 512] = "queryResolve", r[r.static = 1024] = "static", r))(be || {}), ia = Object.defineProperty, ms = (r, e, t, s) => { for (var i = void 0, a = r.length - 1, o; a >= 0; a--) (o = r[a]) && (i = o(e, t, i) || i); return i && ia(e, t, i), i; }; class Pr extends rs { screen = { x: 0, y: 0, width: 0, height: 0 }; _updateProperty(e, t, s) { switch (super._updateProperty(e, t, s), e) { case "view": case "pixelRatio": this.view && (this.view.dataset.pixelRatio = String(this.pixelRatio)); break; } } resize(e, t, s = !0) { this.view && (this.view.width = Math.floor(e * this.pixelRatio), this.view.height = Math.floor(t * this.pixelRatio)), this.screen.width = e, this.screen.height = t, s && this.view && (this.view.style.width = `${e}px`, this.view.style.height = `${t}px`); } } ms([ h({ fallback: hs }) ], Pr.prototype, "pixelRatio"); ms([ h({ internal: !0 }) ], Pr.prototype, "view"); const Qt = /* @__PURE__ */ Object.create(null), Xr = /* @__PURE__ */ Object.create(null); function aa(r, e) { let t = Xr[r]; return t === void 0 && (Qt[e] === void 0 && (Qt[e] = 1), Xr[r] = t = Qt[e]++), t; } class W extends ue { get _gl() { return this._renderer.gl; } constructor() { super(), this.on("updateContext", this._updateContext.bind(this)), this.on("setup", this._setup.bind(this)); } install(e) { this._renderer = e; } // eslint-disable-next-line unused-imports/no-unused-vars _updateContext(e) { } _setup() { } flush() { } reset() { } } class oa extends W { install(e) { super.install(e), e.buffer = this; } buffers = /* @__PURE__ */ new Map(); glBuffers = /* @__PURE__ */ new Map(); getGlBuffer(e) { return this.glBuffers.get(e.instanceId) || this._createGlBuffer(e); } _createGlBuffer(e) { const t = this._gl, s = new sa(t.createBuffer()); let i = st.arrayBuffer; return e.usage & be.index ? i = st.elementArrayBuffer : e.usage & be.uniform && (i = st.uniformBuffer), s.target = i, this.glBuffers.set(e.instanceId, s), this.buffers.get(e.instanceId) || ("on" in e && (e.on("updateProperty", (a) => { switch (a) { case "usage": case "data": s.dirty = !0; break; } }), e.on("destroy", () => { this.buffers.delete(e.instanceId); })), this.buffers.set(e.instanceId, e)), s; } bind(e) { const t = this._gl, s = this.getGlBuffer(e); t.bindBuffer(s.target, s.native); } update(e, t = !1) { const s = this.getGlBuffer(e); if (!t && !s.dirty) return s; s.dirty = !1; const { _gl: i } = this, { usage: a, data: o } = e; i.bindBuffer(s.target, s.native); const n = a & be.static ? i.STATIC_DRAW : i.DYNAMIC_DRAW; if (o) if (s.byteLength >= o.byteLength) { const l = o.length * o.BYTES_PER_ELEMENT; i.bufferSubData(s.target, 0, o, 0, l / o.BYTES_PER_ELEMENT); } else s.byteLength = o.byteLength, i.bufferData(s.target, o, n); else s.byteLength = 0, i.bufferData(s.target, s.byteLength, n); return s; } reset() { super.reset(), this.buffers.clear(), this.glBuffers.clear(); } } let er; function na() { return er || (er = "mediump"), er; } function la(r, e, t) { return e ? r : t ? (r = r.replace("out vec4 finalColor;", ""), `#ifdef GL_ES #define in varying #define finalColor gl_FragColor #define texture texture2D #endif ${r}`) : `#ifdef GL_ES #de