@stlite/browser
Version:
Browser Stlite
1,810 lines (1,809 loc) • 3.54 MB
JavaScript
import { $t as e, Ai as t, Dt as n, En as r, Gi as i, Ka as a, Kn as o, Mt as s, Nt as c, O as l, T as u, Ua as d, Ur as f, Ut as p, Va as m, Wt as h, _ as g, _n as _, ci as v, et as y, ft as b, ha as x, kr as S, ma as C, pr as w, rt as T, si as E, sr as D, ti as O, va as k, wi as A, z as j } from "./index-Dl4ETd_L-D2oMd1k2.js";
import { n as M, t as N } from "./withFullScreenWrapper-tGGSjEWy-DoekoEMQ.js";
import { t as P } from "./index-CVld_lKx-BpaiPOLH.js";
import { t as ee } from "./assertThisInitialized-C1dAyb4j-jFURGdZo.js";
import { a as F, i as te, n as ne, r as re, t as ie } from "./possibleConstructorReturn-BHiKHPYz-Bnf-j7Fb.js";
import { n as ae, r as oe, t as se } from "./toConsumableArray-8hd4ivs--BcltBJ_c.js";
import { g as ce, h as le } from "./threshold-F1JftlUw-Dpm01mWO.js";
import { t as ue } from "./useBasicWidgetState-D3zHnRUK-Dsaz4YO6.js";
//#region ../react/build/DeckGlJsonChart-3OvaJ57f.js
var I = /* @__PURE__ */ a(d(), 1);
function de(e, t) {
for (var n = 0; n < t.length; n++) {
let r = t[n];
if (typeof r != "string" && !Array.isArray(r)) {
for (let t in r) if (t !== "default" && !(t in e)) {
let n = Object.getOwnPropertyDescriptor(r, t);
n && Object.defineProperty(e, t, n.get ? n : {
enumerable: !0,
get: () => r[t]
});
}
}
}
return Object.freeze(Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }));
}
function fe() {
let e;
if (typeof window < "u" && window.performance) e = window.performance.now();
else if (typeof process < "u" && process.hrtime) {
let t = process.hrtime();
e = t[0] * 1e3 + t[1] / 1e6;
} else e = Date.now();
return e;
}
var pe = class {
constructor(e, t) {
this.sampleSize = 1, this.time = 0, this.count = 0, this.samples = 0, this.lastTiming = 0, this.lastSampleTime = 0, this.lastSampleCount = 0, this._count = 0, this._time = 0, this._samples = 0, this._startTime = 0, this._timerPending = !1, this.name = e, this.type = t, this.reset();
}
reset() {
return this.time = 0, this.count = 0, this.samples = 0, this.lastTiming = 0, this.lastSampleTime = 0, this.lastSampleCount = 0, this._count = 0, this._time = 0, this._samples = 0, this._startTime = 0, this._timerPending = !1, this;
}
setSampleSize(e) {
return this.sampleSize = e, this;
}
incrementCount() {
return this.addCount(1), this;
}
decrementCount() {
return this.subtractCount(1), this;
}
addCount(e) {
return this._count += e, this._samples++, this._checkSampling(), this;
}
subtractCount(e) {
return this._count -= e, this._samples++, this._checkSampling(), this;
}
addTime(e) {
return this._time += e, this.lastTiming = e, this._samples++, this._checkSampling(), this;
}
timeStart() {
return this._startTime = fe(), this._timerPending = !0, this;
}
timeEnd() {
return this._timerPending ? (this.addTime(fe() - this._startTime), this._timerPending = !1, this._checkSampling(), this) : this;
}
getSampleAverageCount() {
return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
}
getSampleAverageTime() {
return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
}
getSampleHz() {
return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1e3) : 0;
}
getAverageCount() {
return this.samples > 0 ? this.count / this.samples : 0;
}
getAverageTime() {
return this.samples > 0 ? this.time / this.samples : 0;
}
getHz() {
return this.time > 0 ? this.samples / (this.time / 1e3) : 0;
}
_checkSampling() {
this._samples === this.sampleSize && (this.lastSampleTime = this._time, this.lastSampleCount = this._count, this.count += this._count, this.time += this._time, this.samples += this._samples, this._time = 0, this._count = 0, this._samples = 0);
}
}, L = class {
constructor(e) {
this.stats = {}, this.id = e.id, this.stats = {}, this._initializeStats(e.stats), Object.seal(this);
}
get(e, t = "count") {
return this._getOrCreate({
name: e,
type: t
});
}
get size() {
return Object.keys(this.stats).length;
}
reset() {
for (let e of Object.values(this.stats)) e.reset();
return this;
}
forEach(e) {
for (let t of Object.values(this.stats)) e(t);
}
getTable() {
let e = {};
return this.forEach((t) => {
e[t.name] = {
time: t.time || 0,
count: t.count || 0,
average: t.getAverageTime() || 0,
hz: t.getHz() || 0
};
}), e;
}
_initializeStats(e = []) {
e.forEach((e) => this._getOrCreate(e));
}
_getOrCreate(e) {
let { name: t, type: n } = e, r = this.stats[t];
return r || (r = e instanceof pe ? e : new pe(t, n), this.stats[t] = r), r;
}
}, me = new class {
stats = /* @__PURE__ */ new Map();
getStats(e) {
return this.get(e);
}
get(e) {
return this.stats.has(e) || this.stats.set(e, new L({ id: e })), this.stats.get(e);
}
}(), R = globalThis, he = globalThis.process || {}, ge = globalThis.navigator || {};
function _e(e) {
if (typeof window < "u" && window.process?.type === "renderer" || typeof process < "u" && process.versions?.electron) return !0;
let t = typeof navigator < "u" && navigator.userAgent;
return !!(t && t.indexOf("Electron") >= 0);
}
function ve() {
return !(typeof process == "object" && String(process) === "[object process]" && !process?.browser) || _e();
}
function ye(e) {
return ve() ? _e() ? "Electron" : (ge.userAgent || "").indexOf("Edge") > -1 ? "Edge" : globalThis.chrome ? "Chrome" : globalThis.safari ? "Safari" : globalThis.mozInnerScreenX ? "Firefox" : "Unknown" : "Node";
}
var be = "4.1.0";
function xe(e) {
try {
let t = window[e], n = "__storage_test__";
return t.setItem(n, n), t.removeItem(n), t;
} catch {
return null;
}
}
var z = class {
constructor(e, t, n = "sessionStorage") {
this.storage = xe(n), this.id = e, this.config = t, this._loadConfiguration();
}
getConfiguration() {
return this.config;
}
setConfiguration(e) {
if (Object.assign(this.config, e), this.storage) {
let e = JSON.stringify(this.config);
this.storage.setItem(this.id, e);
}
}
_loadConfiguration() {
let e = {};
if (this.storage) {
let t = this.storage.getItem(this.id);
e = t ? JSON.parse(t) : {};
}
return Object.assign(this.config, e), this;
}
};
function B(e) {
let t;
return t = e < 10 ? `${e.toFixed(2)}ms` : e < 100 ? `${e.toFixed(1)}ms` : e < 1e3 ? `${e.toFixed(0)}ms` : `${(e / 1e3).toFixed(2)}s`, t;
}
function Se(e, t = 8) {
let n = Math.max(t - e.length, 0);
return `${" ".repeat(n)}${e}`;
}
var Ce;
(function(e) {
e[e.BLACK = 30] = "BLACK", e[e.RED = 31] = "RED", e[e.GREEN = 32] = "GREEN", e[e.YELLOW = 33] = "YELLOW", e[e.BLUE = 34] = "BLUE", e[e.MAGENTA = 35] = "MAGENTA", e[e.CYAN = 36] = "CYAN", e[e.WHITE = 37] = "WHITE", e[e.BRIGHT_BLACK = 90] = "BRIGHT_BLACK", e[e.BRIGHT_RED = 91] = "BRIGHT_RED", e[e.BRIGHT_GREEN = 92] = "BRIGHT_GREEN", e[e.BRIGHT_YELLOW = 93] = "BRIGHT_YELLOW", e[e.BRIGHT_BLUE = 94] = "BRIGHT_BLUE", e[e.BRIGHT_MAGENTA = 95] = "BRIGHT_MAGENTA", e[e.BRIGHT_CYAN = 96] = "BRIGHT_CYAN", e[e.BRIGHT_WHITE = 97] = "BRIGHT_WHITE";
})(Ce ||= {});
var we = 10;
function Te(e) {
return typeof e == "string" ? (e = e.toUpperCase(), Ce[e] || Ce.WHITE) : e;
}
function Ee(e, t, n) {
return !ve && typeof e == "string" && (t && (e = `\x1B[${Te(t)}m${e}\x1B[39m`), n && (e = `\x1B[${Te(n) + we}m${e}\x1B[49m`)), e;
}
function De(e, t = ["constructor"]) {
let n = Object.getOwnPropertyNames(Object.getPrototypeOf(e)), r = e;
for (let i of n) {
let n = r[i];
typeof n == "function" && (t.find((e) => i === e) || (r[i] = n.bind(e)));
}
}
function Oe(e, t) {
if (!e) throw Error("Assertion failed");
}
function ke() {
let e;
if (ve() && R.performance) e = R?.performance?.now?.();
else if ("hrtime" in he) {
let t = he?.hrtime?.();
e = t[0] * 1e3 + t[1] / 1e6;
} else e = Date.now();
return e;
}
var Ae = {
debug: ve() && console.debug || console.log,
log: console.log,
info: console.info,
warn: console.warn,
error: console.error
}, je = {
enabled: !0,
level: 0
};
function V() {}
var Me = {}, Ne = { once: !0 }, Pe = class {
constructor({ id: e } = { id: "" }) {
this.VERSION = be, this._startTs = ke(), this._deltaTs = ke(), this.userData = {}, this.LOG_THROTTLE_TIMEOUT = 0, this.id = e, this.userData = {}, this._storage = new z(`__probe-${this.id}__`, je), this.timeStamp(`${this.id} started`), De(this), Object.seal(this);
}
set level(e) {
this.setLevel(e);
}
get level() {
return this.getLevel();
}
isEnabled() {
return this._storage.config.enabled;
}
getLevel() {
return this._storage.config.level;
}
getTotal() {
return Number((ke() - this._startTs).toPrecision(10));
}
getDelta() {
return Number((ke() - this._deltaTs).toPrecision(10));
}
set priority(e) {
this.level = e;
}
get priority() {
return this.level;
}
getPriority() {
return this.level;
}
enable(e = !0) {
return this._storage.setConfiguration({ enabled: e }), this;
}
setLevel(e) {
return this._storage.setConfiguration({ level: e }), this;
}
get(e) {
return this._storage.config[e];
}
set(e, t) {
this._storage.setConfiguration({ [e]: t });
}
settings() {
console.table ? console.table(this._storage.config) : console.log(this._storage.config);
}
assert(e, t) {
if (!e) throw Error(t || "Assertion failed");
}
warn(e) {
return this._getLogFunction(0, e, Ae.warn, arguments, Ne);
}
error(e) {
return this._getLogFunction(0, e, Ae.error, arguments);
}
deprecated(e, t) {
return this.warn(`\`${e}\` is deprecated and will be removed in a later version. Use \`${t}\` instead`);
}
removed(e, t) {
return this.error(`\`${e}\` has been removed. Use \`${t}\` instead`);
}
probe(e, t) {
return this._getLogFunction(e, t, Ae.log, arguments, {
time: !0,
once: !0
});
}
log(e, t) {
return this._getLogFunction(e, t, Ae.debug, arguments);
}
info(e, t) {
return this._getLogFunction(e, t, console.info, arguments);
}
once(e, t) {
return this._getLogFunction(e, t, Ae.debug || Ae.info, arguments, Ne);
}
table(e, t, n) {
return t ? this._getLogFunction(e, t, console.table || V, n && [n], { tag: Re(t) }) : V;
}
time(e, t) {
return this._getLogFunction(e, t, console.time ? console.time : console.info);
}
timeEnd(e, t) {
return this._getLogFunction(e, t, console.timeEnd ? console.timeEnd : console.info);
}
timeStamp(e, t) {
return this._getLogFunction(e, t, console.timeStamp || V);
}
group(e, t, n = { collapsed: !1 }) {
let r = Ie({
logLevel: e,
message: t,
opts: n
}), { collapsed: i } = n;
return r.method = (i ? console.groupCollapsed : console.group) || console.info, this._getLogFunction(r);
}
groupCollapsed(e, t, n = {}) {
return this.group(e, t, Object.assign({}, n, { collapsed: !0 }));
}
groupEnd(e) {
return this._getLogFunction(e, "", console.groupEnd || V);
}
withGroup(e, t, n) {
this.group(e, t)();
try {
n();
} finally {
this.groupEnd(e)();
}
}
trace() {
console.trace && console.trace();
}
_shouldLog(e) {
return this.isEnabled() && this.getLevel() >= Fe(e);
}
_getLogFunction(e, t, n, r, i) {
if (this._shouldLog(e)) {
i = Ie({
logLevel: e,
message: t,
args: r,
opts: i
}), n ||= i.method, Oe(n), i.total = this.getTotal(), i.delta = this.getDelta(), this._deltaTs = ke();
let a = i.tag || i.message;
if (i.once && a) if (!Me[a]) Me[a] = ke();
else return V;
return t = Le(this.id, i.message, i), n.bind(console, t, ...i.args);
}
return V;
}
};
Pe.VERSION = be;
function Fe(e) {
if (!e) return 0;
let t;
switch (typeof e) {
case "number":
t = e;
break;
case "object":
t = e.logLevel || e.priority || 0;
break;
default: return 0;
}
return Oe(Number.isFinite(t) && t >= 0), t;
}
function Ie(e) {
let { logLevel: t, message: n } = e;
e.logLevel = Fe(t);
let r = e.args ? Array.from(e.args) : [];
for (; r.length && r.shift() !== n;);
switch (typeof t) {
case "string":
case "function":
n !== void 0 && r.unshift(n), e.message = t;
break;
case "object":
Object.assign(e, t);
break;
}
typeof e.message == "function" && (e.message = e.message());
let i = typeof e.message;
return Oe(i === "string" || i === "object"), Object.assign(e, { args: r }, e.opts);
}
function Le(e, t, n) {
if (typeof t == "string") {
let r = n.time ? Se(B(n.total)) : "";
t = n.time ? `${e}: ${r} ${t}` : `${e}: ${t}`, t = Ee(t, n.color, n.background);
}
return t;
}
function Re(e) {
for (let t in e) for (let n in e[t]) return n || "untitled";
return "empty";
}
globalThis.probe = {};
var ze = new Pe({ id: "@probe.gl/log" }), H = new Pe({ id: "luma.gl" }), U = {};
function Be(e = "id") {
return U[e] = U[e] || 1, `${e}-${U[e]++}`;
}
var Ve = class {
static defaultProps = {
id: "undefined",
handle: void 0,
userData: void 0
};
toString() {
return `${this[Symbol.toStringTag] || this.constructor.name}:"${this.id}"`;
}
id;
props;
userData = {};
_device;
destroyed = !1;
allocatedBytes = 0;
_attachedResources = /* @__PURE__ */ new Set();
constructor(e, t, n) {
if (!e) throw Error("no device");
this._device = e, this.props = He(t, n);
let r = this.props.id === "undefined" ? Be(this[Symbol.toStringTag]) : this.props.id;
this.props.id = r, this.id = r, this.userData = this.props.userData || {}, this.addStats();
}
destroy() {
this.destroyResource();
}
delete() {
return this.destroy(), this;
}
getProps() {
return this.props;
}
attachResource(e) {
this._attachedResources.add(e);
}
detachResource(e) {
this._attachedResources.delete(e);
}
destroyAttachedResource(e) {
this._attachedResources.delete(e) && e.destroy();
}
destroyAttachedResources() {
for (let e of Object.values(this._attachedResources)) e.destroy();
this._attachedResources = /* @__PURE__ */ new Set();
}
destroyResource() {
this.destroyAttachedResources(), this.removeStats(), this.destroyed = !0;
}
removeStats() {
let e = this._device.statsManager.getStats("Resource Counts"), t = this[Symbol.toStringTag];
e.get(`${t}s Active`).decrementCount();
}
trackAllocatedMemory(e, t = this[Symbol.toStringTag]) {
let n = this._device.statsManager.getStats("Resource Counts");
n.get("GPU Memory").addCount(e), n.get(`${t} Memory`).addCount(e), this.allocatedBytes = e;
}
trackDeallocatedMemory(e = this[Symbol.toStringTag]) {
let t = this._device.statsManager.getStats("Resource Counts");
t.get("GPU Memory").subtractCount(this.allocatedBytes), t.get(`${e} Memory`).subtractCount(this.allocatedBytes), this.allocatedBytes = 0;
}
addStats() {
let e = this._device.statsManager.getStats("Resource Counts"), t = this[Symbol.toStringTag];
e.get("Resources Created").incrementCount(), e.get(`${t}s Created`).incrementCount(), e.get(`${t}s Active`).incrementCount();
}
};
function He(e, t) {
let n = { ...t };
for (let t in e) e[t] !== void 0 && (n[t] = e[t]);
return n;
}
var Ue = class e extends Ve {
static INDEX = 16;
static VERTEX = 32;
static UNIFORM = 64;
static STORAGE = 128;
static INDIRECT = 256;
static QUERY_RESOLVE = 512;
static MAP_READ = 1;
static MAP_WRITE = 2;
static COPY_SRC = 4;
static COPY_DST = 8;
get [Symbol.toStringTag]() {
return "Buffer";
}
usage;
indexType;
updateTimestamp;
constructor(t, n) {
let r = { ...n };
(n.usage || 0) & e.INDEX && !n.indexType && (n.data instanceof Uint32Array ? r.indexType = "uint32" : n.data instanceof Uint16Array ? r.indexType = "uint16" : n.data instanceof Uint8Array && (r.indexType = "uint8")), delete r.data, super(t, r, e.defaultProps), this.usage = r.usage || 0, this.indexType = r.indexType, this.updateTimestamp = t.incrementTimestamp();
}
clone(e) {
return this.device.createBuffer({
...this.props,
...e
});
}
static DEBUG_DATA_MAX_LENGTH = 32;
debugData = /* @__PURE__ */ new ArrayBuffer(0);
_setDebugData(t, n, r) {
let i = ArrayBuffer.isView(t) ? t.buffer : t, a = Math.min(t ? t.byteLength : r, e.DEBUG_DATA_MAX_LENGTH);
i === null ? this.debugData = new ArrayBuffer(a) : n === 0 && r === i.byteLength ? this.debugData = i.slice(0, a) : this.debugData = i.slice(n, n + a);
}
static defaultProps = {
...Ve.defaultProps,
usage: 0,
byteLength: 0,
byteOffset: 0,
data: null,
indexType: "uint16",
onMapped: void 0
};
};
function We(e) {
let [t, n, r] = Ye[e], i = e.includes("norm");
return {
signedType: t,
primitiveType: n,
byteLength: r,
normalized: i,
integer: !i && !e.startsWith("float"),
signed: e.startsWith("s")
};
}
function Ge(e) {
let t = e;
switch (t) {
case "uint8": return "unorm8";
case "sint8": return "snorm8";
case "uint16": return "unorm16";
case "sint16": return "snorm16";
default: return t;
}
}
function Ke(e, t) {
switch (t) {
case 1: return e;
case 2: return e + e % 2;
default: return e + (4 - e % 4) % 4;
}
}
function qe(e) {
let t = ArrayBuffer.isView(e) ? e.constructor : e;
if (t === Uint8ClampedArray) return "uint8";
let n = Object.values(Ye).find((e) => t === e[4]);
if (!n) throw Error(t.name);
return n[0];
}
function Je(e) {
let [, , , , t] = Ye[e];
return t;
}
var Ye = {
uint8: [
"uint8",
"u32",
1,
!1,
Uint8Array
],
sint8: [
"sint8",
"i32",
1,
!1,
Int8Array
],
unorm8: [
"uint8",
"f32",
1,
!0,
Uint8Array
],
snorm8: [
"sint8",
"f32",
1,
!0,
Int8Array
],
uint16: [
"uint16",
"u32",
2,
!1,
Uint16Array
],
sint16: [
"sint16",
"i32",
2,
!1,
Int16Array
],
unorm16: [
"uint16",
"u32",
2,
!0,
Uint16Array
],
snorm16: [
"sint16",
"i32",
2,
!0,
Int16Array
],
float16: [
"float16",
"f16",
2,
!1,
Uint16Array
],
float32: [
"float32",
"f32",
4,
!1,
Float32Array
],
uint32: [
"uint32",
"u32",
4,
!1,
Uint32Array
],
sint32: [
"sint32",
"i32",
4,
!1,
Int32Array
]
};
function Xe(e) {
let t;
e.endsWith("-webgl") && (e.replace("-webgl", ""), t = !0);
let [n, r] = e.split("x"), i = n, a = r ? parseInt(r) : 1, o = We(i), s = {
type: i,
components: a,
byteLength: o.byteLength * a,
integer: o.integer,
signed: o.signed,
normalized: o.normalized
};
return t && (s.webglOnly = !0), s;
}
function Ze(e, t, n) {
let r = n ? Ge(e) : e;
switch (r) {
case "unorm8": return t === 1 ? "unorm8" : t === 3 ? "unorm8x3-webgl" : `${r}x${t}`;
case "snorm8":
case "uint8":
case "sint8":
case "uint16":
case "sint16":
case "unorm16":
case "snorm16":
case "float16":
if (t === 1 || t === 3) throw Error(`size: ${t}`);
return `${r}x${t}`;
default: return t === 1 ? r : `${r}x${t}`;
}
}
function Qe(e, t, n) {
if (!t || t > 4) throw Error(`size ${t}`);
let r = t;
return Ze(qe(e), r, n);
}
function $e(e) {
let t;
switch (e.primitiveType) {
case "f32":
t = "float32";
break;
case "i32":
t = "sint32";
break;
case "u32":
t = "uint32";
break;
case "f16": return e.components <= 2 ? "float16x2" : "float16x4";
}
return e.components === 1 ? t : `${t}x${e.components}`;
}
var et = "texture-compression-bc", tt = "texture-compression-astc", nt = "texture-compression-etc2", rt = "texture-compression-etc1-webgl", it = "texture-compression-pvrtc-webgl", at = "texture-compression-atc-webgl", ot = "float32-renderable-webgl", st = "float16-renderable-webgl", ct = "rgb9e5ufloat-renderable-webgl", lt = "snorm8-renderable-webgl", ut = "norm16-renderable-webgl", dt = "snorm16-renderable-webgl", ft = "float32-filterable", pt = "float16-filterable-webgl";
function mt(e) {
let t = _t[e];
if (!t) throw Error(`Unsupported texture format ${e}`);
return t;
}
var ht = {
r8unorm: {},
rg8unorm: {},
"rgb8unorm-webgl": {},
rgba8unorm: {},
"rgba8unorm-srgb": {},
r8snorm: { render: lt },
rg8snorm: { render: lt },
"rgb8snorm-webgl": {},
rgba8snorm: { render: lt },
r8uint: {},
rg8uint: {},
rgba8uint: {},
r8sint: {},
rg8sint: {},
rgba8sint: {},
bgra8unorm: {},
"bgra8unorm-srgb": {},
r16unorm: { f: ut },
rg16unorm: { render: ut },
"rgb16unorm-webgl": { f: ut },
rgba16unorm: { render: ut },
r16snorm: { f: dt },
rg16snorm: { render: dt },
"rgb16snorm-webgl": { f: ut },
rgba16snorm: { render: dt },
r16uint: {},
rg16uint: {},
rgba16uint: {},
r16sint: {},
rg16sint: {},
rgba16sint: {},
r16float: {
render: st,
filter: "float16-filterable-webgl"
},
rg16float: {
render: st,
filter: pt
},
rgba16float: {
render: st,
filter: pt
},
r32uint: {},
rg32uint: {},
rgba32uint: {},
r32sint: {},
rg32sint: {},
rgba32sint: {},
r32float: {
render: ot,
filter: ft
},
rg32float: {
render: !1,
filter: ft
},
"rgb32float-webgl": {
render: ot,
filter: ft
},
rgba32float: {
render: ot,
filter: ft
},
"rgba4unorm-webgl": {
channels: "rgba",
bitsPerChannel: [
4,
4,
4,
4
],
packed: !0
},
"rgb565unorm-webgl": {
channels: "rgb",
bitsPerChannel: [
5,
6,
5,
0
],
packed: !0
},
"rgb5a1unorm-webgl": {
channels: "rgba",
bitsPerChannel: [
5,
5,
5,
1
],
packed: !0
},
rgb9e5ufloat: {
channels: "rgb",
packed: !0,
render: ct
},
rg11b10ufloat: {
channels: "rgb",
bitsPerChannel: [
11,
11,
10,
0
],
packed: !0,
p: 1,
render: ot
},
rgb10a2unorm: {
channels: "rgba",
bitsPerChannel: [
10,
10,
10,
2
],
packed: !0,
p: 1
},
rgb10a2uint: {
channels: "rgba",
bitsPerChannel: [
10,
10,
10,
2
],
packed: !0,
p: 1
},
stencil8: {
attachment: "stencil",
bitsPerChannel: [
8,
0,
0,
0
],
dataType: "uint8"
},
depth16unorm: {
attachment: "depth",
bitsPerChannel: [
16,
0,
0,
0
],
dataType: "uint16"
},
depth24plus: {
attachment: "depth",
bitsPerChannel: [
24,
0,
0,
0
],
dataType: "uint32"
},
depth32float: {
attachment: "depth",
bitsPerChannel: [
32,
0,
0,
0
],
dataType: "float32"
},
"depth24plus-stencil8": {
attachment: "depth-stencil",
bitsPerChannel: [
24,
8,
0,
0
],
packed: !0
},
"depth32float-stencil8": {
attachment: "depth-stencil",
bitsPerChannel: [
32,
8,
0,
0
],
packed: !0
}
}, gt = {
"bc1-rgb-unorm-webgl": { f: et },
"bc1-rgb-unorm-srgb-webgl": { f: et },
"bc1-rgba-unorm": { f: et },
"bc1-rgba-unorm-srgb": { f: et },
"bc2-rgba-unorm": { f: et },
"bc2-rgba-unorm-srgb": { f: et },
"bc3-rgba-unorm": { f: et },
"bc3-rgba-unorm-srgb": { f: et },
"bc4-r-unorm": { f: et },
"bc4-r-snorm": { f: et },
"bc5-rg-unorm": { f: et },
"bc5-rg-snorm": { f: et },
"bc6h-rgb-ufloat": { f: et },
"bc6h-rgb-float": { f: et },
"bc7-rgba-unorm": { f: et },
"bc7-rgba-unorm-srgb": { f: et },
"etc2-rgb8unorm": { f: nt },
"etc2-rgb8unorm-srgb": { f: nt },
"etc2-rgb8a1unorm": { f: nt },
"etc2-rgb8a1unorm-srgb": { f: nt },
"etc2-rgba8unorm": { f: nt },
"etc2-rgba8unorm-srgb": { f: nt },
"eac-r11unorm": { f: nt },
"eac-r11snorm": { f: nt },
"eac-rg11unorm": { f: nt },
"eac-rg11snorm": { f: nt },
"astc-4x4-unorm": { f: tt },
"astc-4x4-unorm-srgb": { f: tt },
"astc-5x4-unorm": { f: tt },
"astc-5x4-unorm-srgb": { f: tt },
"astc-5x5-unorm": { f: tt },
"astc-5x5-unorm-srgb": { f: tt },
"astc-6x5-unorm": { f: tt },
"astc-6x5-unorm-srgb": { f: tt },
"astc-6x6-unorm": { f: tt },
"astc-6x6-unorm-srgb": { f: tt },
"astc-8x5-unorm": { f: tt },
"astc-8x5-unorm-srgb": { f: tt },
"astc-8x6-unorm": { f: tt },
"astc-8x6-unorm-srgb": { f: tt },
"astc-8x8-unorm": { f: tt },
"astc-8x8-unorm-srgb": { f: tt },
"astc-10x5-unorm": { f: tt },
"astc-10x5-unorm-srgb": { f: tt },
"astc-10x6-unorm": { f: tt },
"astc-10x6-unorm-srgb": { f: tt },
"astc-10x8-unorm": { f: tt },
"astc-10x8-unorm-srgb": { f: tt },
"astc-10x10-unorm": { f: tt },
"astc-10x10-unorm-srgb": { f: tt },
"astc-12x10-unorm": { f: tt },
"astc-12x10-unorm-srgb": { f: tt },
"astc-12x12-unorm": { f: tt },
"astc-12x12-unorm-srgb": { f: tt },
"pvrtc-rgb4unorm-webgl": { f: it },
"pvrtc-rgba4unorm-webgl": { f: it },
"pvrtc-rbg2unorm-webgl": { f: it },
"pvrtc-rgba2unorm-webgl": { f: it },
"etc1-rbg-unorm-webgl": { f: rt },
"atc-rgb-unorm-webgl": { f: at },
"atc-rgba-unorm-webgl": { f: at },
"atc-rgbai-unorm-webgl": { f: at }
}, _t = {
...ht,
...gt
}, vt = [
"bc1",
"bc2",
"bc3",
"bc4",
"bc5",
"bc6",
"bc7",
"etc1",
"etc2",
"eac",
"atc",
"astc",
"pvrtc"
], yt = /^(r|rg|rgb|rgba|bgra)([0-9]*)([a-z]*)(-srgb)?(-webgl)?$/, bt = new class {
getInfo(e) {
return xt(e);
}
isColor(e) {
return e.startsWith("rgba") || e.startsWith("bgra") || e.startsWith("rgb");
}
isDepthStencil(e) {
return e.startsWith("depth") || e.startsWith("stencil");
}
isCompressed(e) {
return vt.some((t) => e.startsWith(t));
}
getCapabilities(e) {
let t = mt(e), n = {
format: e,
create: t.f ?? !0,
render: t.render ?? !0,
filter: t.filter ?? !0,
blend: t.blend ?? !0,
store: t.store ?? !0
}, r = xt(e), i = e.startsWith("depth") || e.startsWith("stencil"), a = r?.signed, o = r?.integer, s = r?.webgl;
return n.render &&= !a, n.filter &&= !i && !a && !o && !s, n;
}
}();
function xt(e) {
let t = St(e);
if (bt.isCompressed(e)) {
t.channels = "rgb", t.components = 3, t.bytesPerPixel = 1, t.srgb = !1, t.compressed = !0;
let n = Ct(e);
n && (t.blockWidth = n.blockWidth, t.blockHeight = n.blockHeight);
}
let n = yt.exec(e);
if (n) {
let [, r, i, a, o, s] = n, c = We(`${a}${i}`), l = c.byteLength * 8, u = r.length, d = [
l,
u >= 2 ? l : 0,
u >= 3 ? l : 0,
u >= 4 ? l : 0
];
t = {
format: e,
attachment: t.attachment,
dataType: c.signedType,
components: u,
channels: r,
integer: c.integer,
signed: c.signed,
normalized: c.normalized,
bitsPerChannel: d,
bytesPerPixel: c.byteLength * r.length,
packed: t.packed,
srgb: t.srgb
}, s === "-webgl" && (t.webgl = !0), o === "-srgb" && (t.srgb = !0);
}
return e.endsWith("-webgl") && (t.webgl = !0), e.endsWith("-srgb") && (t.srgb = !0), t;
}
function St(e) {
let t = mt(e), n = t.bytesPerPixel || 1, r = t.bitsPerChannel || [
8,
8,
8,
8
];
return delete t.bitsPerChannel, delete t.bytesPerPixel, delete t.f, delete t.render, delete t.filter, delete t.blend, delete t.store, {
...t,
format: e,
attachment: t.attachment || "color",
channels: t.channels || "r",
components: t.components || t.channels?.length || 1,
bytesPerPixel: n,
bitsPerChannel: r,
dataType: t.dataType || "uint8",
srgb: t.srgb ?? !1,
packed: t.packed ?? !1,
webgl: t.webgl ?? !1,
integer: t.integer ?? !1,
signed: t.signed ?? !1,
normalized: t.normalized ?? !1,
compressed: t.compressed ?? !1
};
}
function Ct(e) {
let t = /.*-(\d+)x(\d+)-.*/.exec(e);
if (t) {
let [, e, n] = t;
return {
blockWidth: Number(e),
blockHeight: Number(n)
};
}
return null;
}
function wt(e) {
return typeof ImageData < "u" && e instanceof ImageData || typeof ImageBitmap < "u" && e instanceof ImageBitmap || typeof HTMLImageElement < "u" && e instanceof HTMLImageElement || typeof HTMLVideoElement < "u" && e instanceof HTMLVideoElement || typeof VideoFrame < "u" && e instanceof VideoFrame || typeof HTMLCanvasElement < "u" && e instanceof HTMLCanvasElement || typeof OffscreenCanvas < "u" && e instanceof OffscreenCanvas;
}
function Tt(e) {
if (typeof ImageData < "u" && e instanceof ImageData || typeof ImageBitmap < "u" && e instanceof ImageBitmap || typeof HTMLCanvasElement < "u" && e instanceof HTMLCanvasElement || typeof OffscreenCanvas < "u" && e instanceof OffscreenCanvas) return {
width: e.width,
height: e.height
};
if (typeof HTMLImageElement < "u" && e instanceof HTMLImageElement) return {
width: e.naturalWidth,
height: e.naturalHeight
};
if (typeof HTMLVideoElement < "u" && e instanceof HTMLVideoElement) return {
width: e.videoWidth,
height: e.videoHeight
};
if (typeof VideoFrame < "u" && e instanceof VideoFrame) return {
width: e.displayWidth,
height: e.displayHeight
};
throw Error("Unknown image type");
}
var Et = class {}, Dt = class {
features;
disabledFeatures;
constructor(e = [], t) {
this.features = new Set(e), this.disabledFeatures = t || {};
}
*[Symbol.iterator]() {
yield* this.features;
}
has(e) {
return !this.disabledFeatures?.[e] && this.features.has(e);
}
}, Ot = class e {
static defaultProps = {
id: null,
powerPreference: "high-performance",
failIfMajorPerformanceCaveat: !1,
createCanvasContext: void 0,
webgl: {},
onError: (e, t) => {},
onResize: (e, t) => {
let [n, r] = e.getDevicePixelSize();
H.log(1, `${e} resized => ${n}x${r}px`)();
},
onPositionChange: (e, t) => {
let [n, r] = e.getPosition();
H.log(1, `${e} repositioned => ${n},${r}`)();
},
onVisibilityChange: (e) => H.log(1, `${e} Visibility changed ${e.isVisible}`)(),
onDevicePixelRatioChange: (e, t) => H.log(1, `${e} DPR changed ${t.oldRatio} => ${e.devicePixelRatio}`)(),
debug: H.get("debug") || void 0,
debugShaders: H.get("debug-shaders") || void 0,
debugFramebuffers: !!H.get("debug-framebuffers"),
debugFactories: !!H.get("debug-factories"),
debugWebGL: !!H.get("debug-webgl"),
debugSpectorJS: void 0,
debugSpectorJSUrl: void 0,
_reuseDevices: !1,
_requestMaxLimits: !0,
_cacheShaders: !1,
_cachePipelines: !1,
_cacheDestroyPolicy: "unused",
_initializeFeatures: !0,
_disabledFeatures: { "compilation-status-async-webgl": !0 },
_handle: void 0
};
get [Symbol.toStringTag]() {
return "Device";
}
toString() {
return `Device(${this.id})`;
}
id;
props;
userData = {};
statsManager = me;
timestamp = 0;
_reused = !1;
_lumaData = {};
_textureCaps = {};
constructor(t) {
this.props = {
...e.defaultProps,
...t
}, this.id = this.props.id || Be(this[Symbol.toStringTag].toLowerCase());
}
getVertexFormatInfo(e) {
return Xe(e);
}
isVertexFormatSupported(e) {
return !0;
}
getTextureFormatInfo(e) {
return bt.getInfo(e);
}
getTextureFormatCapabilities(e) {
let t = this._textureCaps[e];
if (!t) {
let n = this._getDeviceTextureFormatCapabilities(e);
t = this._getDeviceSpecificTextureFormatCapabilities(n), this._textureCaps[e] = t;
}
return t;
}
getMipLevelCount(e, t, n = 1) {
return 1 + Math.floor(Math.log2(Math.max(e, t, n)));
}
isExternalImage(e) {
return wt(e);
}
getExternalImageSize(e) {
return Tt(e);
}
isTextureFormatSupported(e) {
return this.getTextureFormatCapabilities(e).create;
}
isTextureFormatFilterable(e) {
return this.getTextureFormatCapabilities(e).filter;
}
isTextureFormatRenderable(e) {
return this.getTextureFormatCapabilities(e).render;
}
isTextureFormatCompressed(e) {
return bt.isCompressed(e);
}
pushDebugGroup(e) {
this.commandEncoder.pushDebugGroup(e);
}
popDebugGroup() {
this.commandEncoder?.popDebugGroup();
}
insertDebugMarker(e) {
this.commandEncoder?.insertDebugMarker(e);
}
loseDevice() {
return !1;
}
incrementTimestamp() {
return this.timestamp++;
}
reportError(e, t, ...n) {
return this.props.onError(e, t) ? () => {} : H.error(e.message, t, ...n);
}
debug() {
if (this.props.debug) debugger;
else H.once(0, "'Type luma.log.set({debug: true}) in console to enable debug breakpoints',\nor create a device with the 'debug: true' prop.")();
}
getDefaultCanvasContext() {
if (!this.canvasContext) throw Error("Device has no default CanvasContext. See props.createCanvasContext");
return this.canvasContext;
}
beginRenderPass(e) {
return this.commandEncoder.beginRenderPass(e);
}
beginComputePass(e) {
return this.commandEncoder.beginComputePass(e);
}
getCanvasContext() {
return this.getDefaultCanvasContext();
}
readPixelsToArrayWebGL(e, t) {
throw Error("not implemented");
}
readPixelsToBufferWebGL(e, t) {
throw Error("not implemented");
}
setParametersWebGL(e) {
throw Error("not implemented");
}
getParametersWebGL(e) {
throw Error("not implemented");
}
withParametersWebGL(e, t) {
throw Error("not implemented");
}
clearWebGL(e) {
throw Error("not implemented");
}
resetWebGL() {
throw Error("not implemented");
}
static _getCanvasContextProps(e) {
return e.createCanvasContext === !0 ? {} : e.createCanvasContext;
}
_getDeviceTextureFormatCapabilities(e) {
let t = bt.getCapabilities(e), n = (e) => (typeof e == "string" ? this.features.has(e) : e) ?? !0, r = n(t.create);
return {
format: e,
create: r,
render: r && n(t.render),
filter: r && n(t.filter),
blend: r && n(t.blend),
store: r && n(t.store)
};
}
_normalizeBufferProps(e) {
(e instanceof ArrayBuffer || ArrayBuffer.isView(e)) && (e = { data: e });
let t = { ...e };
if ((e.usage || 0) & Ue.INDEX && (e.indexType || (e.data instanceof Uint32Array ? t.indexType = "uint32" : e.data instanceof Uint16Array ? t.indexType = "uint16" : e.data instanceof Uint8Array && (t.data = new Uint16Array(e.data), t.indexType = "uint16")), !t.indexType)) throw Error("indices buffer content must be of type uint16 or uint32");
return t;
}
}, kt = "set luma.log.level=1 (or higher) to trace rendering", At = "No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.", jt = new class e {
static defaultProps = {
...Ot.defaultProps,
type: "best-available",
adapters: void 0,
waitForPageLoad: !0
};
stats = me;
log = H;
VERSION = "9.2.6";
spector;
preregisteredAdapters = /* @__PURE__ */ new Map();
constructor() {
if (globalThis.luma) {
if (globalThis.luma.VERSION !== this.VERSION) throw H.error(`Found luma.gl ${globalThis.luma.VERSION} while initialzing ${this.VERSION}`)(), H.error("'yarn why @luma.gl/core' can help identify the source of the conflict")(), /* @__PURE__ */ Error("luma.gl - multiple versions detected: see console log");
H.error("This version of luma.gl has already been initialized")();
}
H.log(1, `${this.VERSION} - ${kt}`)(), globalThis.luma = this;
}
async createDevice(t = {}) {
let n = {
...e.defaultProps,
...t
}, r = this.selectAdapter(n.type, n.adapters);
if (!r) throw Error(At);
return n.waitForPageLoad && await r.pageLoaded, await r.create(n);
}
async attachDevice(e, t) {
let n = this._getTypeFromHandle(e, t.adapters), r = n && this.selectAdapter(n, t.adapters);
if (!r) throw Error(At);
return await r?.attach?.(e, t);
}
registerAdapters(e) {
for (let t of e) this.preregisteredAdapters.set(t.type, t);
}
getSupportedAdapters(e = []) {
let t = this._getAdapterMap(e);
return Array.from(t).map(([, e]) => e).filter((e) => e.isSupported?.()).map((e) => e.type);
}
getBestAvailableAdapterType(e = []) {
let t = [
"webgpu",
"webgl",
"null"
], n = this._getAdapterMap(e);
for (let e of t) if (n.get(e)?.isSupported?.()) return e;
return null;
}
selectAdapter(e, t = []) {
let n = e;
e === "best-available" && (n = this.getBestAvailableAdapterType(t));
let r = this._getAdapterMap(t);
return n && r.get(n) || null;
}
enforceWebGL2(e = !0, t = []) {
let n = this._getAdapterMap(t).get("webgl");
n || H.warn("enforceWebGL2: webgl adapter not found")(), n?.enforceWebGL2?.(e);
}
setDefaultDeviceProps(t) {
Object.assign(e.defaultProps, t);
}
_getAdapterMap(e = []) {
let t = new Map(this.preregisteredAdapters);
for (let n of e) t.set(n.type, n);
return t;
}
_getTypeFromHandle(e, t = []) {
return e instanceof WebGL2RenderingContext ? "webgl" : typeof GPUDevice < "u" && e instanceof GPUDevice || e?.queue ? "webgpu" : e === null ? "null" : (e instanceof WebGLRenderingContext ? H.warn("WebGL1 is not supported", e)() : H.warn("Unknown handle type", e)(), null);
}
}(), Mt = class {
get pageLoaded() {
return It();
}
}, Nt = ve() && typeof document < "u", Pt = () => Nt && document.readyState === "complete", Ft = null;
function It() {
return Ft ||= Pt() || typeof window > "u" ? Promise.resolve() : new Promise((e) => window.addEventListener("load", () => e())), Ft;
}
function Lt() {
let e, t;
return {
promise: new Promise((n, r) => {
e = n, t = r;
}),
resolve: e,
reject: t
};
}
var Rt = class e {
static isHTMLCanvas(e) {
return typeof HTMLCanvasElement < "u" && e instanceof HTMLCanvasElement;
}
static isOffscreenCanvas(e) {
return typeof OffscreenCanvas < "u" && e instanceof OffscreenCanvas;
}
static defaultProps = {
id: void 0,
canvas: null,
width: 800,
height: 600,
useDevicePixels: !0,
autoResize: !0,
container: null,
visible: !0,
alphaMode: "opaque",
colorSpace: "srgb",
trackPosition: !1
};
id;
props;
canvas;
htmlCanvas;
offscreenCanvas;
type;
initialized;
isInitialized = !1;
isVisible = !0;
cssWidth;
cssHeight;
devicePixelRatio;
devicePixelWidth;
devicePixelHeight;
drawingBufferWidth;
drawingBufferHeight;
_initializedResolvers = Lt();
_resizeObserver;
_intersectionObserver;
_position;
destroyed = !1;
toString() {
return `${this[Symbol.toStringTag]}(${this.id})`;
}
constructor(t) {
if (this.props = {
...e.defaultProps,
...t
}, t = this.props, this.initialized = this._initializedResolvers.promise, ve() ? t.canvas ? typeof t.canvas == "string" ? this.canvas = Bt(t.canvas) : this.canvas = t.canvas : this.canvas = Vt(t) : this.canvas = {
width: t.width || 1,
height: t.height || 1
}, e.isHTMLCanvas(this.canvas) ? (this.id = t.id || this.canvas.id, this.type = "html-canvas", this.htmlCanvas = this.canvas) : e.isOffscreenCanvas(this.canvas) ? (this.id = t.id || "offscreen-canvas", this.type = "offscreen-canvas", this.offscreenCanvas = this.canvas) : (this.id = t.id || "node-canvas-context", this.type = "node"), this.cssWidth = this.htmlCanvas?.clientWidth || this.canvas.width, this.cssHeight = this.htmlCanvas?.clientHeight || this.canvas.height, this.devicePixelWidth = this.canvas.width, this.devicePixelHeight = this.canvas.height, this.drawingBufferWidth = this.canvas.width, this.drawingBufferHeight = this.canvas.height, this.devicePixelRatio = globalThis.devicePixelRatio || 1, this._position = [0, 0], e.isHTMLCanvas(this.canvas)) {
this._intersectionObserver = new IntersectionObserver((e) => this._handleIntersection(e)), this._intersectionObserver.observe(this.canvas), this._resizeObserver = new ResizeObserver((e) => this._handleResize(e));
try {
this._resizeObserver.observe(this.canvas, { box: "device-pixel-content-box" });
} catch {
this._resizeObserver.observe(this.canvas, { box: "content-box" });
}
setTimeout(() => this._observeDevicePixelRatio(), 0), this.props.trackPosition && this._trackPosition();
}
}
destroy() {
this.destroyed = !0;
}
setProps(e) {
return "useDevicePixels" in e && (this.props.useDevicePixels = e.useDevicePixels || !1, this._updateDrawingBufferSize()), this;
}
getCSSSize() {
return [this.cssWidth, this.cssHeight];
}
getPosition() {
return this._position;
}
getDevicePixelSize() {
return [this.devicePixelWidth, this.devicePixelHeight];
}
getDrawingBufferSize() {
return [this.drawingBufferWidth, this.drawingBufferHeight];
}
getMaxDrawingBufferSize() {
let e = this.device.limits.maxTextureDimension2D;
return [e, e];
}
setDrawingBufferSize(e, t) {
this.canvas.width = e, this.canvas.height = t, this.drawingBufferWidth = e, this.drawingBufferHeight = t;
}
getDevicePixelRatio() {
return typeof window < "u" && window.devicePixelRatio || 1;
}
cssToDevicePixels(e, t = !0) {
let n = this.cssToDeviceRatio(), [r, i] = this.getDrawingBufferSize();
return Ht(e, n, r, i, t);
}
getPixelSize() {
return this.getDevicePixelSize();
}
getAspect() {
let [e, t] = this.getDevicePixelSize();
return e / t;
}
cssToDeviceRatio() {
try {
let [e] = this.getDrawingBufferSize(), [t] = this.getCSSSize();
return t ? e / t : 1;
} catch {
return 1;
}
}
resize(e) {
this.setDrawingBufferSize(e.width, e.height);
}
_setAutoCreatedCanvasId(e) {
this.htmlCanvas?.id === "lumagl-auto-created-canvas" && (this.htmlCanvas.id = e);
}
_handleIntersection(e) {
let t = e.find((e) => e.target === this.canvas);
if (!t) return;
let n = t.isIntersecting;
this.isVisible !== n && (this.isVisible = n, this.device.props.onVisibilityChange(this));
}
_handleResize(e) {
let t = e.find((e) => e.target === this.canvas);
if (!t) return;
this.cssWidth = t.contentBoxSize[0].inlineSize, this.cssHeight = t.contentBoxSize[0].blockSize;
let n = this.getDevicePixelSize(), r = t.devicePixelContentBoxSize?.[0].inlineSize || t.contentBoxSize[0].inlineSize * devicePixelRatio, i = t.devicePixelContentBoxSize?.[0].blockSize || t.contentBoxSize[0].blockSize * devicePixelRatio, [a, o] = this.getMaxDrawingBufferSize();
this.devicePixelWidth = Math.max(1, Math.min(r, a)), this.devicePixelHeight = Math.max(1, Math.min(i, o)), this._updateDrawingBufferSize(), this.device.props.onResize(this, { oldPixelSize: n });
}
_updateDrawingBufferSize() {
if (this.props.autoResize) {
if (typeof this.props.useDevicePixels == "number") {
let e = this.props.useDevicePixels;
this.setDrawingBufferSize(this.cssWidth * e, this.cssHeight * e);
} else this.props.useDevicePixels ? this.setDrawingBufferSize(this.devicePixelWidth, this.devicePixelHeight) : this.setDrawingBufferSize(this.cssWidth, this.cssHeight);
this._updateDevice();
}
this._initializedResolvers.resolve(), this.isInitialized = !0, this.updatePosition();
}
_observeDevicePixelRatio() {
let e = this.devicePixelRatio;
this.devicePixelRatio = window.devicePixelRatio, this.updatePosition(), this.device.props.onDevicePixelRatioChange(this, { oldRatio: e }), matchMedia(`(resolution: ${this.devicePixelRatio}dppx)`).addEventListener("change", () => this._observeDevicePixelRatio(), { once: !0 });
}
_trackPosition(e = 100) {
let t = setInterval(() => {
this.destroyed ? clearInterval(t) : this.updatePosition();
}, e);
}
updatePosition() {
let e = this.htmlCanvas?.getBoundingClientRect();
if (e) {
let t = [e.left, e.top];
if (this._position ??= t, t[0] !== this._position[0] || t[1] !== this._position[1]) {
let e = this._position;
this._position = t, this.device.props.onPositionChange?.(this, { oldPosition: e });
}
}
}
};
function zt(e) {
if (typeof e == "string") {
let t = document.getElementById(e);
if (!t) throw Error(`${e} is not an HTML element`);
return t;
}
return e || document.body;
}
function Bt(e) {
let t = document.getElementById(e);
if (!Rt.isHTMLCanvas(t)) throw Error("Object is not a canvas element");
return t;
}
function Vt(e) {
let { width: t, height: n } = e, r = document.createElement("canvas");
r.id = Be("lumagl-auto-created-canvas"), r.width = t || 1, r.height = n || 1, r.style.width = Number.isFinite(t) ? `${t}px` : "100%", r.style.height = Number.isFinite(n) ? `${n}px` : "100%", e?.visible || (r.style.visibility = "hidden");
let i = zt(e?.container || null);
return i.insertBefore(r, i.firstChild), r;
}
function Ht(e, t, n, r, i) {
let a = e, o = Ut(a[0], t, n), s = Wt(a[1], t, r, i), c = Ut(a[0] + 1, t, n), l = c === n - 1 ? c : c - 1;
c = Wt(a[1] + 1, t, r, i);
let u;
return i ? (c = c === 0 ? c : c + 1, u = s, s = c) : u = c === r - 1 ? c : c - 1, {
x: o,
y: s,
width: Math.max(l - o + 1, 1),
height: Math.max(u - s + 1, 1)
};
}
function Ut(e, t, n) {
return Math.min(Math.round(e * t), n - 1);
}
function Wt(e, t, n, r) {
return r ? Math.max(0, n - 1 - Math.round(e * t)) : Math.min(Math.round(e * t), n - 1);
}
var Gt = class e extends Ve {
static defaultProps = {
...Ve.defaultProps,
type: "color-sampler",
addressModeU: "clamp-to-edge",
addressModeV: "clamp-to-edge",
addressModeW: "clamp-to-edge",
magFilter: "nearest",
minFilter: "nearest",
mipmapFilter: "none",
lodMinClamp: 0,
lodMaxClamp: 32,
compare: "less-equal",
maxAnisotropy: 1
};
get [Symbol.toStringTag]() {
return "Sampler";
}
constructor(t, n) {
n = e.normalizeProps(t, n), super(t, n, e.defaultProps);
}
static normalizeProps(e, t) {
return t;
}
}, Kt = {
"1d": "1d",
"2d": "2d",
"2d-array": "2d",
cube: "2d",
"cube-array": "2d",
"3d": "3d"
}, qt = class e extends Ve {
static SAMPLE = 4;
static STORAGE = 8;
static RENDER = 16;
static COPY_SRC = 1;
static COPY_DST = 2;
static TEXTURE = 4;
static RENDER_ATTACHMENT = 16;
dimension;
baseDimension;
format;
width;
height;
depth;
mipLevels;
updateTimestamp;
get [Symbol.toStringTag]() {
return "Texture";
}
toString() {
return `Texture(${this.id},${this.format},${this.width}x${this.height})`;
}
constructor(t, n) {
if (n = e.normalizeProps(t, n), super(t, n, e.defaultProps), this.dimension = this.props.dimension, this.baseDimension = Kt[this.dimension], this.format = this.props.format, this.width = this.props.width, this.height = this.props.height, this.depth = this.props.depth, this.mipLevels = this.props.mipLevels, this.props.width === void 0 || this.props.height === void 0) if (t.isExternalImage(n.data)) {
let e = t.getExternalImageSize(n.data);
this.width = e?.width || 1, this.height = e?.height || 1;
} else this.width = 1, this.height = 1, (this.props.width === void 0 || this.props.height === void 0) && H.warn(`${this} created with undefined width or height. This is deprecated. Use AsyncTexture instead.`)();
this.updateTimestamp = t.incrementTimestamp();
}
setSampler(e) {
this.sampler = e instanceof Gt ? e : this.device.createSampler(e);
}
clone(e) {
return this.device.createTexture({
...this.props,
...e
});
}
static normalizeProps(e, t) {
let n = { ...t }, { width: r, height: i } = n;
return typeof r == "number" && (n.width = Math.max(1, Math.ceil(r))), typeof i == "number" && (n.height = Math.max(1, Math.ceil(i))), n;
}
_initializeData(e) {
this.device.isExternalImage(e) ? this.copyExternalImage({
image: e,
width: this.width,
height: this.height,
depth: this.depth,
mipLevel: 0,
x: 0,
y: 0,
z: 0,
aspect: "all",
colorSpace: "srgb",
premultipliedAlpha: !1,
flipY: !1
}) : e && this.copyImageData({
data: e,
mipLevel: 0,
x: 0,
y: 0,
z: 0,
aspect: "all"
});
}
_normalizeCopyImageDataOptions(t) {
let { width: n, height: r, depth: i } = this, a = {
...e.defaultCopyDataOptions,
width: n,
height: r,
depth: i,
...t
}, o = this.device.getTextureFormatInfo(this.format);
if (!t.bytesPerRow && !o.bytesPerPixel) throw Error(`bytesPerRow must be provided for texture format ${this.format}`);
return a.bytesPerRow = t.bytesPerRow || n * (o.bytesPerPixel || 4), a.rowsPerImage = t.rowsPerImage || r, a;
}
_normalizeCopyExternalImageOptions(t) {
let n = this.device.getExternalImageSize(t.image), r = {
...e.defaultCopyExternalImageOptions,
...n,
...t
};
return r.width = Math.min(r.width, this.width - r.x), r.height = Math.min(r.height, this.height - r.y), r;
}
static defaultProps = {
...Ve.defaultProps,
data: null,
dimension: "2d",
format: "rgba8unorm",
usage: e.TEXTURE | e.RENDER_ATTACHMENT | e.COPY_DST,
width: void 0,
height: void 0,
depth: 1,
mipLevels: 1,
samples: void 0,
sampler: {},
view: void 0
};
static defaultCopyDataOptions = {
data: void 0,
byteOffset: 0,
bytesPerRow: void 0,
rowsPerImage: void 0,
mipLevel: 0,
x: 0,
y: 0,
z: 0,
aspect: "all"
};
static defaultCopyExternalImageOptions = {
image: void 0,
sourceX: 0,
sourceY: 0,
width: void 0,
height: void 0,
depth: 1,
mipLevel: 0,
x: 0,
y: 0,
z: 0,
aspect: "all",
colorSpace: "srgb",
premultipliedAlpha: !1,
flipY: !1
};
}, Jt = class e extends Ve {
get [Symbol.toStringTag]() {
return "TextureView";
}
constructor(t, n) {
super(t, n, e.defaultProps);
}
static defaultProps = {
...Ve.defaultProps,
format: void 0,
dimension: void 0,
aspect: "all",
baseMipLevel: 0,
mipLevelCount: void 0,
baseArrayLayer: 0,
arrayLayerCount: void 0
};
};
function Yt(e, t, n) {
let r = "", i = t.split(/\r?\n/), a = e.slice().sort((e, t) => e.lineNum - t.lineNum);
switch (n?.showSourceCode || "no") {
case "all":
let t = 0;
for (let e = 1; e <= i.length; e++) for (r += Qt(i[e - 1], e, n); a.length > t && a[t].lineNum === e;) {
let e = a[t++];
r += Xt(e, i, e.lineNum, {
...n,
inlineSource: !1
});
}
for (; a.length > t;) {
let e = a[t++];
r += Xt(e, [], 0, {
...n,
inlineSource: !1
});
}
return r;
case "issues":
case "no":
for (let t of e) r += Xt(t, i, t.lineNum, { inlineSource: n?.showSourceCode !== "no" });
return r;
}
}
function Xt(e, t, n, r) {
if (r?.inlineSource) return `
${Zt(t, n)}${e.linePos > 0 ? `${" ".repeat(e.linePos + 5)}^^^
` : ""}${e.type.toUpperCase()}: ${e.message}
`;
let i = e.type === "error" ? "red" : "#8B4000";
return r?.html ? `<div class='luma-compiler-log-error' style="color:${i};"><b> ${e.type.toUpperCase()}: ${e.message}</b></div>` : `${e.type.toUpperCase()}: ${e.message}`;
}
function Zt(e, t, n) {
let r = "";
for (let i = t - 2; i <= t; i++) {
let a = e[i - 1];
a !== void 0 && (r += Qt(a, t, n));
}
return r;
}
function Qt(e, t, n) {
let r = n?.html ? en(e) : e;
return `${$t(String(t), 4)}: ${r}${n?.html ? "<br/>" : "\n"}`;
}
function $t(e, t) {
let n = "";
for (let r = e.length; r < t; ++r) n += " ";
return n + e;
}
function en(e) {
return e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
}
var tn = class e extends Ve {
get [Symbol.toStringTag]() {
return "Shader";
}
stage;
source;
compilationStatus = "pending";
constructor(t, n) {
n = {
...n,
debugShaders: n.debugShaders || t.props.debugShaders || "errors"
}, super(t, {
id: nn(n),
...n
}, e.defaultProps), this.stage = this.props.stage, this.source = this.props.source;
}
getCompilationInfoSync() {
return null;
}
getTranslatedSource() {
return null;
}
async debugShader() {
let e = this.props.debugShaders;
switch (e) {
case "never": return;
case "errors":
if (this.compilationStatus === "success") return;
break;
}
let t = await this.getCompilationInfo();
e === "warnings" && t?.length === 0 |