@miris-inc/core 0.0.7-test-4bee4e41 → 0.0.8-358231b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.js ADDED
@@ -0,0 +1,2180 @@
1
+ class LodStore {
2
+ #keyMap = /* @__PURE__ */ new Map();
3
+ #idMap = /* @__PURE__ */ new Map();
4
+ forKey(key) {
5
+ return this.#keyMap.get(key);
6
+ }
7
+ forId(id) {
8
+ return this.#idMap.get(id);
9
+ }
10
+ setKey(key, lod) {
11
+ this.#keyMap.set(key, lod);
12
+ }
13
+ setId(id, lod) {
14
+ return this.#idMap.set(id, lod);
15
+ }
16
+ delete(lod) {
17
+ this.#keyMap.delete(lod.key);
18
+ this.#idMap.delete(lod.id);
19
+ }
20
+ deleteKey(key) {
21
+ this.#keyMap.delete(key);
22
+ }
23
+ deleteId(id) {
24
+ this.#idMap.delete(id);
25
+ }
26
+ }
27
+ class Lod {
28
+ /// three/Lod object that this core/Lod object represents. We use unknown to avoid a circular dependency.
29
+ #key;
30
+ /// flag that tells us whether this Lod uses the original spark packedsplats data format (false) or uses the newer extsplats format (true)
31
+ useExtSplats = false;
32
+ /// if useExtSplats is false, this contains the PackedSplats data. if that flag is true, then this contains bytes 0 - 15 of ExtSplats
33
+ #splats = null;
34
+ /// is useExtSplats is false, this is null. if that flag is true, this contains bytes 16 - 31
35
+ splatsExtendedData = null;
36
+ #bounds = null;
37
+ #boundsStreamSpace = new Float32Array(6);
38
+ #transform = null;
39
+ #lodIndex = null;
40
+ #paddingCount = 0;
41
+ sh1Data = null;
42
+ sh1Max = 1;
43
+ sh2Data = null;
44
+ sh2Max = 1;
45
+ sh3Data = null;
46
+ sh3Max = 1;
47
+ sh3ExtendedData = null;
48
+ get key() {
49
+ return this.#key ?? null;
50
+ }
51
+ set key(key) {
52
+ this.store.deleteKey(this.key);
53
+ if (key || 0 === key) {
54
+ this.store.setKey(key, this);
55
+ }
56
+ this.#key = key;
57
+ }
58
+ set splats(splats) {
59
+ this.#splats = splats;
60
+ }
61
+ get splats() {
62
+ return this.#splats;
63
+ }
64
+ set bounds(bounds) {
65
+ this.#bounds = bounds;
66
+ }
67
+ get bounds() {
68
+ return this.#bounds;
69
+ }
70
+ /**
71
+ * @internal
72
+ */
73
+ set _boundsStreamSpace(bounds) {
74
+ this.#boundsStreamSpace = bounds;
75
+ }
76
+ /**
77
+ * @internal
78
+ */
79
+ get _boundsStreamSpace() {
80
+ return this.#boundsStreamSpace;
81
+ }
82
+ set lodIndex(index) {
83
+ this.#lodIndex = index;
84
+ }
85
+ get lodIndex() {
86
+ return this.#lodIndex;
87
+ }
88
+ set paddingCount(count) {
89
+ this.#paddingCount = count;
90
+ }
91
+ get paddingCount() {
92
+ return this.#paddingCount;
93
+ }
94
+ set transform(transform) {
95
+ this.#transform = transform;
96
+ }
97
+ get transform() {
98
+ return this.#transform;
99
+ }
100
+ setSh1(sh1Data, sh1Max) {
101
+ this.sh1Data = sh1Data;
102
+ this.sh1Max = sh1Max;
103
+ }
104
+ setSh2(sh2Data, sh2Max) {
105
+ this.sh2Data = sh2Data;
106
+ this.sh2Max = sh2Max;
107
+ }
108
+ setSh3(sh3Data, sh3Max) {
109
+ this.sh3Data = sh3Data;
110
+ this.sh3Max = sh3Max;
111
+ }
112
+ dispose() {
113
+ const key = this.#key;
114
+ this.store.delete(this);
115
+ this.#key = null;
116
+ key?.dispose?.();
117
+ this.#splats = null;
118
+ this.splatsExtendedData = null;
119
+ this.#bounds = null;
120
+ this.#transform = null;
121
+ this.sh1Data = null;
122
+ this.sh2Data = null;
123
+ this.sh3Data = null;
124
+ this.sh3ExtendedData = null;
125
+ this.modelRoot?.lods?.delete(this);
126
+ }
127
+ constructor({ id, modelRoot, lodStore }) {
128
+ Object.defineProperties(this, {
129
+ id: { value: id },
130
+ modelRoot: { value: modelRoot },
131
+ store: { value: lodStore }
132
+ });
133
+ lodStore.setId(id, this);
134
+ modelRoot.add(this);
135
+ }
136
+ }
137
+ class Change {
138
+ constructor({ type, lod }) {
139
+ Object.defineProperties(this, {
140
+ type: { value: type },
141
+ lod: { value: lod }
142
+ });
143
+ }
144
+ }
145
+ class ModelRoot {
146
+ static #keyMap = /* @__PURE__ */ new Map();
147
+ static #idMap = /* @__PURE__ */ new Map();
148
+ static forKey(key) {
149
+ return this.#keyMap.get(key);
150
+ }
151
+ static forId(id) {
152
+ return this.#idMap.get(id);
153
+ }
154
+ #key;
155
+ get key() {
156
+ return this.#key ?? null;
157
+ }
158
+ set key(key) {
159
+ ModelRoot.#keyMap.delete(this.key);
160
+ if (key || 0 === key) {
161
+ ModelRoot.#keyMap.set(key, this);
162
+ }
163
+ this.#key = key;
164
+ }
165
+ #lods = /* @__PURE__ */ new Set();
166
+ get lods() {
167
+ return this.#lods;
168
+ }
169
+ #transform;
170
+ set transform(transform) {
171
+ this.#transform = transform;
172
+ }
173
+ get transform() {
174
+ return this.#transform;
175
+ }
176
+ constructor({ id, stream }) {
177
+ Object.defineProperties(this, {
178
+ id: { value: id },
179
+ stream: { value: stream }
180
+ });
181
+ ModelRoot.#idMap.set(id, this);
182
+ stream.add(this);
183
+ }
184
+ add(lod) {
185
+ this.#lods.add(lod);
186
+ }
187
+ dispose() {
188
+ const lods = [...this.#lods];
189
+ this.#lods.clear();
190
+ for (const lod of lods) {
191
+ lod.dispose();
192
+ }
193
+ ModelRoot.#keyMap.delete(this.key);
194
+ ModelRoot.#idMap.delete(this.id);
195
+ this.#key = null;
196
+ }
197
+ }
198
+ class AttributeCache {
199
+ static #cache = /* @__PURE__ */ new Map();
200
+ static #nextId = 1;
201
+ // checkSum is important for early detection of critical regressions
202
+ // in lifetime management of cache entries. Note that such regressions
203
+ // cause OOM kills (crashes) on iOS
204
+ // Do not remove, especially not in response to checksum mismatch errors.
205
+ static #checkSum = 0;
206
+ static #checkSumModulo = 2 ** 32;
207
+ static #lastReportedCheckSumDifference = 0;
208
+ static #addCheckSum(id) {
209
+ this.#checkSum = (this.#checkSum + id) % this.#checkSumModulo;
210
+ }
211
+ static #removeCheckSum(id) {
212
+ this.#checkSum = (this.#checkSum - id) % this.#checkSumModulo;
213
+ if (this.#checkSum < 0) this.#checkSum += this.#checkSumModulo;
214
+ }
215
+ static getCheckSum() {
216
+ return this.#checkSum;
217
+ }
218
+ static getConsecutiveIds(howMany) {
219
+ const result = this.#nextId;
220
+ this.#nextId += howMany;
221
+ return result;
222
+ }
223
+ static addWithId(data, id) {
224
+ this.#addCheckSum(id);
225
+ this.#cache.set(id, data);
226
+ }
227
+ static add(data) {
228
+ const id = this.#nextId++;
229
+ this.addWithId(data, id);
230
+ return id;
231
+ }
232
+ static get(id) {
233
+ const data = this.#cache.get(id);
234
+ if (data === void 0) {
235
+ throw new Error(`Attribute with id ${id} not found in cache`);
236
+ }
237
+ return data;
238
+ }
239
+ static remove(idOrIds) {
240
+ if (Array.isArray(idOrIds)) {
241
+ for (const id of idOrIds) {
242
+ this.#cache.delete(id);
243
+ this.#removeCheckSum(id);
244
+ }
245
+ } else {
246
+ this.#cache.delete(idOrIds);
247
+ this.#removeCheckSum(idOrIds);
248
+ }
249
+ }
250
+ static validateCheckSum(checkSumWasm) {
251
+ if (checkSumWasm != this.getCheckSum()) {
252
+ let difference = checkSumWasm - this.getCheckSum();
253
+ if (difference < 0) difference += this.#checkSumModulo;
254
+ if (difference != this.#lastReportedCheckSumDifference) {
255
+ console.error(
256
+ `ID checksum mismatch between WASM and TypeScript sides! ${checkSumWasm} ${this.getCheckSum()}`
257
+ );
258
+ this.#lastReportedCheckSumDifference = difference;
259
+ }
260
+ }
261
+ }
262
+ }
263
+ class Stream extends EventTarget {
264
+ static _idMap = /* @__PURE__ */ new Map();
265
+ static _keyMap = /* @__PURE__ */ new Map();
266
+ static forId(id) {
267
+ if (!id) return;
268
+ return this._idMap.get(id);
269
+ }
270
+ static forKey(key) {
271
+ return this._keyMap.get(key);
272
+ }
273
+ #key;
274
+ #loadedRenderableData = false;
275
+ #variantHierarchies = {};
276
+ /**
277
+ * @internal
278
+ */
279
+ _addVariantCollection(hierarchyId) {
280
+ if (!this.#variantHierarchies[hierarchyId]) {
281
+ this.#variantHierarchies[hierarchyId] = { id: hierarchyId, children: [] };
282
+ }
283
+ }
284
+ /**
285
+ * @internal
286
+ */
287
+ _findAndAddToVariantSet(parentId, variant) {
288
+ const addToNode = (node) => {
289
+ if (!node) return false;
290
+ if (node.id === parentId) {
291
+ if (node.children) {
292
+ node.children.push(variant);
293
+ } else if (variant.type === "option") {
294
+ if (!node.options) node.options = [];
295
+ node.options.push(variant);
296
+ } else {
297
+ if (!node.nestedSets) node.nestedSets = [];
298
+ node.nestedSets.push(variant);
299
+ }
300
+ return true;
301
+ }
302
+ if (Array.isArray(node.children)) {
303
+ for (const child of node.children) {
304
+ if (addToNode(child)) return true;
305
+ }
306
+ }
307
+ if (Array.isArray(node.nestedSets)) {
308
+ for (const nested of node.nestedSets) {
309
+ if (addToNode(nested)) return true;
310
+ }
311
+ }
312
+ if (Array.isArray(node.options)) {
313
+ for (const option of node.options) {
314
+ if (addToNode(option)) return true;
315
+ }
316
+ }
317
+ return false;
318
+ };
319
+ for (const hierarchy of Object.values(this.#variantHierarchies)) {
320
+ if (addToNode(hierarchy)) return;
321
+ }
322
+ }
323
+ /**
324
+ * @internal
325
+ */
326
+ _addVariant(parentId, variant) {
327
+ this._findAndAddToVariantSet(parentId, variant);
328
+ }
329
+ /**
330
+ * @internal
331
+ */
332
+ _exportVariantHierarchies() {
333
+ return Object.entries(this.#variantHierarchies).map(
334
+ ([hierarchyId, hierarchy]) => ({
335
+ hierarchyId: Number(hierarchyId),
336
+ hierarchy
337
+ })
338
+ );
339
+ }
340
+ /**
341
+ * @internal
342
+ */
343
+ _setVariantSelection(variantId) {
344
+ this.client.setVariantSelection(variantId);
345
+ }
346
+ get key() {
347
+ return this.#key ?? null;
348
+ }
349
+ set key(key) {
350
+ Stream._keyMap.delete(this.key);
351
+ if (key || 0 === key) {
352
+ Stream._keyMap.set(key, this);
353
+ }
354
+ this.#key = key;
355
+ }
356
+ // prettier-ignore
357
+ #matrix = [
358
+ 1,
359
+ 0,
360
+ 0,
361
+ 0,
362
+ 0,
363
+ 1,
364
+ 0,
365
+ 0,
366
+ 0,
367
+ 0,
368
+ 1,
369
+ 0,
370
+ 0,
371
+ 0,
372
+ 0,
373
+ 1
374
+ ];
375
+ get matrix() {
376
+ return this.#matrix;
377
+ }
378
+ set matrix(matrix) {
379
+ this.#matrix = matrix;
380
+ const { engine, client } = this;
381
+ const matrixBuffer = engine.malloc(this.#matrix.length * 4);
382
+ engine.heapF32.set(Float32Array.from(this.#matrix), matrixBuffer / 4);
383
+ client.setSceneObjectTransform(this.id, matrixBuffer);
384
+ engine.free(matrixBuffer);
385
+ }
386
+ get boundingBox() {
387
+ const { engine, client } = this;
388
+ const boxBuffer = engine.malloc(6 * 4);
389
+ client.getWorldBoundingBox(this.id, boxBuffer);
390
+ const [cX, cY, cZ, dX, dY, dZ] = Float32Array.from(
391
+ engine.heapF32.subarray(boxBuffer / 4, boxBuffer / 4 + 6)
392
+ );
393
+ if (cX === void 0 || cY === void 0 || cZ === void 0 || dX === void 0 || dY === void 0 || dZ === void 0) return;
394
+ const box = {
395
+ min: {
396
+ x: cX - dX / 2,
397
+ y: cY - dY / 2,
398
+ z: cZ - dZ / 2
399
+ },
400
+ max: {
401
+ x: cX + dX / 2,
402
+ y: cY + dY / 2,
403
+ z: cZ + dZ / 2
404
+ },
405
+ size: {
406
+ x: dX,
407
+ y: dY,
408
+ z: dZ
409
+ },
410
+ center: {
411
+ x: cX,
412
+ y: cY,
413
+ z: cZ
414
+ }
415
+ };
416
+ Object.freeze(box);
417
+ return box;
418
+ }
419
+ #modelRoots = /* @__PURE__ */ new Set();
420
+ get modelRoots() {
421
+ return new Set(this.#modelRoots);
422
+ }
423
+ /**
424
+ * @deprecated Use `modelRoots` instead.
425
+ */
426
+ get chunks() {
427
+ return this.modelRoots;
428
+ }
429
+ constructor(options) {
430
+ super();
431
+ const { scene, uuid } = options;
432
+ Object.defineProperties(this, {
433
+ uuid: { value: uuid, enumerable: true },
434
+ scene: { value: scene, enumerable: true },
435
+ client: { value: scene.client, enumerable: true },
436
+ miris: { value: scene.miris, enumerable: true },
437
+ engine: { value: scene.miris.engine, enumerable: true }
438
+ });
439
+ this._initStream(options);
440
+ Stream._idMap.set(this.id, this);
441
+ scene.add(this);
442
+ }
443
+ _initStream({ uuid }) {
444
+ const id = this.client.addStreamById(uuid, uuid, false);
445
+ Object.defineProperty(this, "id", { value: id });
446
+ }
447
+ /**
448
+ * @internal
449
+ */
450
+ async _onStreamLoaded() {
451
+ if (this.#loadedRenderableData) return;
452
+ this.dispatchEvent(new Event("streamloaded"));
453
+ this.scene._onSceneLoaded();
454
+ this.#loadedRenderableData = true;
455
+ }
456
+ /**
457
+ * @internal
458
+ */
459
+ _onRootLoaded() {
460
+ this.dispatchEvent(new Event("rootloaded"));
461
+ }
462
+ add(modelRoot) {
463
+ this.#modelRoots.add(modelRoot);
464
+ }
465
+ end() {
466
+ this.client.removeStream(this.id);
467
+ for (const modelRoot of this.#modelRoots) {
468
+ modelRoot.dispose();
469
+ }
470
+ this.#modelRoots.clear();
471
+ Stream._idMap.delete(this.id);
472
+ Stream._keyMap.delete(this.key);
473
+ if (this.scene.streams.has(this)) {
474
+ this.scene.delete(this);
475
+ }
476
+ }
477
+ }
478
+ let _jsPromise, _wasmPromise;
479
+ const _wasmUrl = ((u) => u.includes("/.vite/") ? u.replace(/\.vite\/[^?#]*/, () => "node_modules/@miris-inc/core/dist/AquaApi.wasm") : u)(new URL("AquaApi.wasm", import.meta.url).href);
480
+ function _getExport(m) {
481
+ return m.default || m;
482
+ }
483
+ function _loadModule(url) {
484
+ return import(/* @vite-ignore */ /* webpackIgnore: true */ /* turbopackIgnore: true */ url).then((m) => {
485
+ const f = _getExport(m);
486
+ if (typeof f === "function") return f;
487
+ throw new Error("bad module");
488
+ }).catch(() => fetch(url).then((r) => {
489
+ if (!r.ok) throw new Error(r.status + " " + url);
490
+ return r.text();
491
+ }).then((text) => {
492
+ const blobUrl = URL.createObjectURL(new Blob([text], { type: "text/javascript" }));
493
+ return import(/* @vite-ignore */ /* webpackIgnore: true */ /* turbopackIgnore: true */ blobUrl).then((m) => {
494
+ URL.revokeObjectURL(blobUrl);
495
+ return _getExport(m);
496
+ });
497
+ }));
498
+ }
499
+ function _factory(...args) {
500
+ if (!_jsPromise) {
501
+ _wasmPromise = fetch(_wasmUrl).then((r) => {
502
+ if (!r.ok || (r.headers.get("content-type") || "").includes("text/html")) return null;
503
+ return r.arrayBuffer();
504
+ }).catch(() => null);
505
+ _jsPromise = _loadModule(((u) => u.includes("/.vite/") ? new URL("/node_modules/@miris-inc/core/dist/AquaApi.js", u).href : u)(new URL("./AquaApi.js", import.meta.url).href)).catch((e) => {
506
+ _jsPromise = _wasmPromise = void 0;
507
+ throw e;
508
+ });
509
+ }
510
+ return Promise.all([_jsPromise, _wasmPromise]).then(([factory, wasmBinary]) => {
511
+ if (wasmBinary) {
512
+ const [opts = {}, ...rest] = args;
513
+ return factory({ ...opts, wasmBinary }, ...rest);
514
+ }
515
+ return factory(...args);
516
+ });
517
+ }
518
+ class Thread {
519
+ static name = "thread";
520
+ static get Worker() {
521
+ throw new Error(
522
+ "Thread could not be initialized because no Worker was supplied. Do you forget to set `static Worker = Worker` on the child class?"
523
+ );
524
+ }
525
+ constructor({ engine }) {
526
+ Object.defineProperty(this, "engine", { value: engine, enumerable: true });
527
+ Object.defineProperty(this, "ready", {
528
+ enumerable: true,
529
+ value: new Promise((resolve) => {
530
+ this.#resolvers.set(0, async () => {
531
+ this.#pending = false;
532
+ this.#resolvers.delete(0);
533
+ resolve(this);
534
+ });
535
+ })
536
+ });
537
+ this.#worker = new this.constructor.Worker({
538
+ name: `decoder-${Thread.#nextWorkerId()}`
539
+ });
540
+ this.#worker.addEventListener("message", this.#message.bind(this));
541
+ }
542
+ static #latestWorkerId = 0;
543
+ static #nextWorkerId() {
544
+ return this.#latestWorkerId += 1;
545
+ }
546
+ #pending = true;
547
+ get pending() {
548
+ return this.#pending;
549
+ }
550
+ #worker;
551
+ #resolvers = /* @__PURE__ */ new Map();
552
+ get pendingRequests() {
553
+ return this.#resolvers.size;
554
+ }
555
+ get terminated() {
556
+ return !this.#worker;
557
+ }
558
+ #latestProcessId = 0;
559
+ #nextProcessId() {
560
+ return this.#latestProcessId += 1;
561
+ }
562
+ async _execute(action, ...args) {
563
+ if (this.pending) {
564
+ throw new Error(
565
+ `Unable to execute ${action} because decoder has not yet been initialized`
566
+ );
567
+ }
568
+ if (!this.#worker) {
569
+ throw new Error(
570
+ `Unable to execute ${action} because decoder has already been terminated`
571
+ );
572
+ }
573
+ return new Promise((resolve) => {
574
+ if (!this.#worker) {
575
+ throw new Error(
576
+ `Unable to execute ${action} because decoder has already been terminated`
577
+ );
578
+ }
579
+ const id = this.#nextProcessId();
580
+ this.#resolvers.set(id, async (result) => {
581
+ this.#resolvers.delete(id);
582
+ resolve(result);
583
+ });
584
+ const transfer = args.filter(
585
+ (arg) => arg instanceof ArrayBuffer
586
+ );
587
+ this.#worker.postMessage({ id, action, args }, transfer);
588
+ });
589
+ }
590
+ #message({
591
+ data
592
+ }) {
593
+ if ("ready" === data) data = { id: 0, result: void 0 };
594
+ const { id, result } = data;
595
+ this.#resolvers.get(id)?.(result);
596
+ }
597
+ _postToWorker(data, transfer) {
598
+ this.#worker?.postMessage(data, transfer ?? []);
599
+ }
600
+ terminate() {
601
+ if (!this.#worker) return;
602
+ this.#worker.terminate();
603
+ this.#worker.removeEventListener("message", this.#message);
604
+ this.#worker = null;
605
+ }
606
+ }
607
+ const jsContent = 'const defineActions = (actions) => {\n self.postMessage("ready");\n self.addEventListener("message", async ({ data }) => {\n if ("ready" === data) return;\n const { id, action, args } = data;\n const [result, ...postMessageArgs] = await Reflect.apply(\n actions[action],\n void 0,\n [...args, id]\n );\n self.postMessage({ id, result }, ...postMessageArgs);\n });\n return actions;\n};\nconst sparkMinSplats = 2048;\nconst sparkAttributeList = {\n sparkPackedSplat: { elementsPerSplat: 4, discard: false },\n extendedPackedSplatLow: { elementsPerSplat: 4, discard: false },\n extendedPackedSplatHigh: { elementsPerSplat: 4, discard: false },\n packedSh1: { elementsPerSplat: 2, discard: false },\n packedSh2: { elementsPerSplat: 4, discard: false },\n packedSh3: { elementsPerSplat: 4, discard: false },\n sh1Extended: { elementsPerSplat: 4, discard: false },\n sh2Extended: { elementsPerSplat: 4, discard: false },\n sh3Extended_0: { elementsPerSplat: 4, discard: false },\n sh3Extended_1: { elementsPerSplat: 4, discard: false }\n};\nfunction roundUpToMultipleOf(a, multiple) {\n return Math.ceil(a / multiple) * multiple;\n}\nfunction sparkAttributeFromRaw(name, id, wasmView) {\n const attrib = sparkAttributeList[name];\n if (attrib === void 0)\n throw new Error("attribute name" + name + " is unknown");\n const originalSize = wasmView.length;\n const paddedSize = roundUpToMultipleOf(\n originalSize,\n attrib.elementsPerSplat * sparkMinSplats\n );\n const paddedData = new Uint32Array(paddedSize);\n paddedData.set(wasmView);\n return { paddedData, originalSize, id };\n}\nasync function Li(Le = {}) {\n var $r, l = Le, Lr = "./this.program", zr = (e, r) => {\n throw r;\n }, Ne = import.meta.url, wr = "";\n function Ge(e) {\n return l.locateFile ? l.locateFile(e, wr) : wr + e;\n }\n var Yr, Tr;\n {\n try {\n wr = new URL(".", Ne).href;\n } catch {\n }\n Tr = (e) => {\n var r = new XMLHttpRequest();\n return r.open("GET", e, false), r.responseType = "arraybuffer", r.send(null), new Uint8Array(r.response);\n }, Yr = async (e) => {\n var r = await fetch(e, { credentials: "same-origin" });\n if (r.ok) return r.arrayBuffer();\n throw new Error(r.status + " : " + r.url);\n };\n }\n var Nr = console.log.bind(console), B = console.error.bind(console), G, Q = false, rr;\n var Gr, qr, er, k, A, U, L, T, w, tr, nr, V, Xr, Jr = false;\n function Kr() {\n var e = er.buffer;\n l.HEAP8 = k = new Int8Array(e), U = new Int16Array(e), l.HEAPU8 = A = new Uint8Array(e), L = new Uint16Array(e), l.HEAP32 = T = new Int32Array(e), l.HEAPU32 = w = new Uint32Array(e), l.HEAPF32 = tr = new Float32Array(e), l.HEAPF64 = nr = new Float64Array(e), V = new BigInt64Array(e), Xr = new BigUint64Array(e);\n }\n function qe() {\n if (l.preRun) for (typeof l.preRun == "function" && (l.preRun = [l.preRun]); l.preRun.length; ) at(l.preRun.shift());\n Qr(ee);\n }\n function Xe() {\n Jr = true, H.__wasm_call_ctors();\n }\n function Je() {\n if (l.postRun) for (typeof l.postRun == "function" && (l.postRun = [l.postRun]); l.postRun.length; ) it(l.postRun.shift());\n Qr(re);\n }\n function z(e) {\n l.onAbort?.(e), e = "Aborted(" + e + ")", B(e), Q = true, e += ". Build with -sASSERTIONS for more info.";\n var r = new WebAssembly.RuntimeError(e);\n throw qr?.(r), r;\n }\n var Fr;\n function Ke() {\n return l.locateFile ? Ge("aqua-parser.wasm") : "";\n }\n function Ze(e) {\n if (e == Fr && G) return new Uint8Array(G);\n if (Tr) return Tr(e);\n throw "both async and sync fetching of the wasm failed";\n }\n async function Qe(e) {\n if (!G) try {\n var r = await Yr(e);\n return new Uint8Array(r);\n } catch {\n }\n return Ze(e);\n }\n async function rt(e, r) {\n try {\n var t = await Qe(e), n = await WebAssembly.instantiate(t, r);\n return n;\n } catch (i) {\n B(`failed to asynchronously prepare wasm: ${i}`), z(i);\n }\n }\n async function et(e, r, t) {\n if (!e) try {\n var n = fetch(r, { credentials: "same-origin" }), i = await WebAssembly.instantiateStreaming(n, t);\n return i;\n } catch (a) {\n B(`wasm streaming compile failed: ${a}`), B("falling back to ArrayBuffer instantiation");\n }\n return rt(r, t);\n }\n function tt() {\n return { env: Ie, wasi_snapshot_preview1: Ie };\n }\n async function nt() {\n function e(a, s) {\n return H = a.exports, er = H.memory, Kr(), fe = H.__indirect_function_table, si(H), H;\n }\n function r(a) {\n return e(a.instance);\n }\n var t = tt();\n if (l.instantiateWasm) return new Promise((a, s) => {\n l.instantiateWasm(t, (o, u) => {\n a(e(o));\n });\n });\n Fr ??= Ke();\n var n = await et(G, Fr, t), i = r(n);\n return i;\n }\n class Zr {\n name = "ExitStatus";\n constructor(r) {\n this.message = `Program terminated with exit(${r})`, this.status = r;\n }\n }\n var Qr = (e) => {\n for (; e.length > 0; ) e.shift()(l);\n }, re = [], it = (e) => re.push(e), ee = [], at = (e) => ee.push(e);\n var Cr = true;\n var y = (e) => De(e), m = () => xe(), ir = [], ar = 0, st = (e) => {\n var r = new Pr(e);\n return r.get_caught() || (r.set_caught(true), ar--), r.set_rethrown(false), ir.push(r), Ue(e), je(e);\n }, x = 0, ot = () => {\n g(0, 0);\n var e = ir.pop();\n Oe(e.excPtr), x = 0;\n };\n class Pr {\n constructor(r) {\n this.excPtr = r, this.ptr = r - 24;\n }\n set_type(r) {\n w[this.ptr + 4 >> 2] = r;\n }\n get_type() {\n return w[this.ptr + 4 >> 2];\n }\n set_destructor(r) {\n w[this.ptr + 8 >> 2] = r;\n }\n get_destructor() {\n return w[this.ptr + 8 >> 2];\n }\n set_caught(r) {\n r = r ? 1 : 0, k[this.ptr + 12] = r;\n }\n get_caught() {\n return k[this.ptr + 12] != 0;\n }\n set_rethrown(r) {\n r = r ? 1 : 0, k[this.ptr + 13] = r;\n }\n get_rethrown() {\n return k[this.ptr + 13] != 0;\n }\n init(r, t) {\n this.set_adjusted_ptr(0), this.set_type(r), this.set_destructor(t);\n }\n set_adjusted_ptr(r) {\n w[this.ptr + 16 >> 2] = r;\n }\n get_adjusted_ptr() {\n return w[this.ptr + 16 >> 2];\n }\n }\n var sr = (e) => Re(e), kr = (e) => {\n var r = x;\n if (!r) return sr(0), 0;\n var t = new Pr(r);\n t.set_adjusted_ptr(r);\n var n = t.get_type();\n if (!n) return sr(0), r;\n for (var i of e) {\n if (i === 0 || i === n) break;\n var a = t.ptr + 16;\n if (Ve(i, n, a)) return sr(i), r;\n }\n return sr(n), r;\n }, ut = () => kr([]), ct = (e) => kr([e]), ft = (e, r) => kr([e, r]), lt = () => {\n var e = ir.pop();\n e || z("no exception to throw");\n var r = e.excPtr;\n throw e.get_rethrown() || (ir.push(e), e.set_rethrown(true), e.set_caught(false), ar++), x = r, x;\n }, vt = (e, r, t) => {\n var n = new Pr(e);\n throw n.init(r, t), x = e, ar++, x;\n }, _t = () => ar, dt = (e) => {\n throw x || (x = e), x;\n }, pt = () => z(""), C = (e) => {\n for (var r = ""; ; ) {\n var t = A[e++];\n if (!t) return r;\n r += String.fromCharCode(t);\n }\n }, Y = {}, j = {}, or = {}, q = class extends Error {\n constructor(r) {\n super(r), this.name = "BindingError";\n }\n }, h = (e) => {\n throw new q(e);\n };\n function ht(e, r, t = {}) {\n var n = r.name;\n if (e || h(`type "${n}" must have a positive integer typeid pointer`), j.hasOwnProperty(e)) {\n if (t.ignoreDuplicateRegistrations) return;\n h(`Cannot register type \'${n}\' twice`);\n }\n if (j[e] = r, delete or[e], Y.hasOwnProperty(e)) {\n var i = Y[e];\n delete Y[e], i.forEach((a) => a());\n }\n }\n function E(e, r, t = {}) {\n return ht(e, r, t);\n }\n var te = (e, r, t) => {\n switch (r) {\n case 1:\n return t ? (n) => k[n] : (n) => A[n];\n case 2:\n return t ? (n) => U[n >> 1] : (n) => L[n >> 1];\n case 4:\n return t ? (n) => T[n >> 2] : (n) => w[n >> 2];\n case 8:\n return t ? (n) => V[n >> 3] : (n) => Xr[n >> 3];\n default:\n throw new TypeError(`invalid integer width (${r}): ${e}`);\n }\n }, gt = (e, r, t, n, i) => {\n r = C(r);\n const a = n === 0n;\n let s = (o) => o;\n if (a) {\n const o = t * 8;\n s = (u) => BigInt.asUintN(o, u), i = s(i);\n }\n E(e, { name: r, fromWireType: s, toWireType: (o, u) => (typeof u == "number" && (u = BigInt(u)), u), readValueFromPointer: te(r, t, !a), destructorFunction: null });\n }, yt = (e, r, t, n) => {\n r = C(r), E(e, { name: r, fromWireType: function(i) {\n return !!i;\n }, toWireType: function(i, a) {\n return a ? t : n;\n }, readValueFromPointer: function(i) {\n return this.fromWireType(A[i]);\n }, destructorFunction: null });\n }, mt = (e) => ({ count: e.count, deleteScheduled: e.deleteScheduled, preservePointerOnDelete: e.preservePointerOnDelete, ptr: e.ptr, ptrType: e.ptrType, smartPtr: e.smartPtr, smartPtrType: e.smartPtrType }), Sr = (e) => {\n function r(t) {\n return t.$$.ptrType.registeredClass.name;\n }\n h(r(e) + " instance already deleted");\n }, Ar = false, ne = (e) => {\n }, bt = (e) => {\n e.smartPtr ? e.smartPtrType.rawDestructor(e.smartPtr) : e.ptrType.registeredClass.rawDestructor(e.ptr);\n }, ie = (e) => {\n e.count.value -= 1;\n var r = e.count.value === 0;\n r && bt(e);\n }, X = (e) => typeof FinalizationRegistry > "u" ? (X = (r) => r, e) : (Ar = new FinalizationRegistry((r) => {\n ie(r.$$);\n }), X = (r) => {\n var t = r.$$, n = !!t.smartPtr;\n if (n) {\n var i = { $$: t };\n Ar.register(r, i, r);\n }\n return r;\n }, ne = (r) => Ar.unregister(r), X(e)), wt = () => {\n let e = cr.prototype;\n Object.assign(e, { isAliasOf(t) {\n if (!(this instanceof cr) || !(t instanceof cr)) return false;\n var n = this.$$.ptrType.registeredClass, i = this.$$.ptr;\n t.$$ = t.$$;\n for (var a = t.$$.ptrType.registeredClass, s = t.$$.ptr; n.baseClass; ) i = n.upcast(i), n = n.baseClass;\n for (; a.baseClass; ) s = a.upcast(s), a = a.baseClass;\n return n === a && i === s;\n }, clone() {\n if (this.$$.ptr || Sr(this), this.$$.preservePointerOnDelete) return this.$$.count.value += 1, this;\n var t = X(Object.create(Object.getPrototypeOf(this), { $$: { value: mt(this.$$) } }));\n return t.$$.count.value += 1, t.$$.deleteScheduled = false, t;\n }, delete() {\n this.$$.ptr || Sr(this), this.$$.deleteScheduled && !this.$$.preservePointerOnDelete && h("Object already scheduled for deletion"), ne(this), ie(this.$$), this.$$.preservePointerOnDelete || (this.$$.smartPtr = void 0, this.$$.ptr = void 0);\n }, isDeleted() {\n return !this.$$.ptr;\n }, deleteLater() {\n return this.$$.ptr || Sr(this), this.$$.deleteScheduled && !this.$$.preservePointerOnDelete && h("Object already scheduled for deletion"), this.$$.deleteScheduled = true, this;\n } });\n const r = Symbol.dispose;\n r && (e[r] = e.delete);\n };\n function cr() {\n }\n var fr = (e, r) => Object.defineProperty(r, "name", { value: e }), se = {}, Er = (e, r, t) => {\n if (e[r].overloadTable === void 0) {\n var n = e[r];\n e[r] = function(...i) {\n return e[r].overloadTable.hasOwnProperty(i.length) || h(`Function \'${t}\' called with an invalid number of arguments (${i.length}) - expects one of (${e[r].overloadTable})!`), e[r].overloadTable[i.length].apply(this, i);\n }, e[r].overloadTable = [], e[r].overloadTable[n.argCount] = n;\n }\n }, Rr = (e, r, t) => {\n l.hasOwnProperty(e) ? ((t === void 0 || l[e].overloadTable !== void 0 && l[e].overloadTable[t] !== void 0) && h(`Cannot register public name \'${e}\' twice`), Er(l, e, e), l[e].overloadTable.hasOwnProperty(t) && h(`Cannot register multiple overloads of a function with the same number of arguments (${t})!`), l[e].overloadTable[t] = r) : (l[e] = r, l[e].argCount = t);\n }, Tt = 48, Ft = 57, Ct = (e) => {\n e = e.replace(/[^a-zA-Z0-9_]/g, "$");\n var r = e.charCodeAt(0);\n return r >= Tt && r <= Ft ? `_${e}` : e;\n };\n function Pt(e, r, t, n, i, a, s, o) {\n this.name = e, this.constructor = r, this.instancePrototype = t, this.rawDestructor = n, this.baseClass = i, this.getActualType = a, this.upcast = s, this.downcast = o, this.pureVirtualFunctions = [];\n }\n var lr = (e, r, t) => {\n for (; r !== t; ) r.upcast || h(`Expected null or instance of ${t.name}, got an instance of ${r.name}`), e = r.upcast(e), r = r.baseClass;\n return e;\n }, Dr = (e) => {\n if (e === null) return "null";\n var r = typeof e;\n return r === "object" || r === "array" || r === "function" ? e.toString() : "" + e;\n };\n function kt(e, r) {\n if (r === null) return this.isReference && h(`null is not a valid ${this.name}`), 0;\n r.$$ || h(`Cannot pass "${Dr(r)}" as a ${this.name}`), r.$$.ptr || h(`Cannot pass deleted object as a pointer of type ${this.name}`);\n var t = r.$$.ptrType.registeredClass, n = lr(r.$$.ptr, t, this.registeredClass);\n return n;\n }\n function St(e, r) {\n var t;\n if (r === null) return this.isReference && h(`null is not a valid ${this.name}`), this.isSmartPointer ? (t = this.rawConstructor(), e !== null && e.push(this.rawDestructor, t), t) : 0;\n (!r || !r.$$) && h(`Cannot pass "${Dr(r)}" as a ${this.name}`), r.$$.ptr || h(`Cannot pass deleted object as a pointer of type ${this.name}`), !this.isConst && r.$$.ptrType.isConst && h(`Cannot convert argument of type ${r.$$.smartPtrType ? r.$$.smartPtrType.name : r.$$.ptrType.name} to parameter type ${this.name}`);\n var n = r.$$.ptrType.registeredClass;\n if (t = lr(r.$$.ptr, n, this.registeredClass), this.isSmartPointer) switch (r.$$.smartPtr === void 0 && h("Passing raw pointer to smart pointer is illegal"), this.sharingPolicy) {\n case 0:\n r.$$.smartPtrType === this ? t = r.$$.smartPtr : h(`Cannot convert argument of type ${r.$$.smartPtrType ? r.$$.smartPtrType.name : r.$$.ptrType.name} to parameter type ${this.name}`);\n break;\n case 1:\n t = r.$$.smartPtr;\n break;\n case 2:\n if (r.$$.smartPtrType === this) t = r.$$.smartPtr;\n else {\n var i = r.clone();\n t = this.rawShare(t, W.toHandle(() => i.delete())), e !== null && e.push(this.rawDestructor, t);\n }\n break;\n default:\n h("Unsupporting sharing policy");\n }\n return t;\n }\n function At(e, r) {\n if (r === null) return this.isReference && h(`null is not a valid ${this.name}`), 0;\n r.$$ || h(`Cannot pass "${Dr(r)}" as a ${this.name}`), r.$$.ptr || h(`Cannot pass deleted object as a pointer of type ${this.name}`), r.$$.ptrType.isConst && h(`Cannot convert argument of type ${r.$$.ptrType.name} to parameter type ${this.name}`);\n var t = r.$$.ptrType.registeredClass, n = lr(r.$$.ptr, t, this.registeredClass);\n return n;\n }\n function vr(e) {\n return this.fromWireType(w[e >> 2]);\n }\n var oe = (e, r, t) => {\n if (r === t) return e;\n if (t.baseClass === void 0) return null;\n var n = oe(e, r, t.baseClass);\n return n === null ? null : t.downcast(n);\n }, Et = {}, Rt = (e, r) => {\n for (r === void 0 && h("ptr should not be undefined"); e.baseClass; ) r = e.upcast(r), e = e.baseClass;\n return r;\n }, Dt = (e, r) => (r = Rt(e, r), Et[r]), Wt = class extends Error {\n constructor(r) {\n super(r), this.name = "InternalError";\n }\n }, _r = (e) => {\n throw new Wt(e);\n }, dr = (e, r) => {\n (!r.ptrType || !r.ptr) && _r("makeClassHandle requires ptr and ptrType");\n var t = !!r.smartPtrType, n = !!r.smartPtr;\n return t !== n && _r("Both smartPtrType and smartPtr must be specified"), r.count = { value: 1 }, X(Object.create(e, { $$: { value: r, writable: true } }));\n };\n function xt(e) {\n var r = this.getPointee(e);\n if (!r) return this.destructor(e), null;\n var t = Dt(this.registeredClass, r);\n if (t !== void 0) {\n if (t.$$.count.value === 0) return t.$$.ptr = r, t.$$.smartPtr = e, t.clone();\n var n = t.clone();\n return this.destructor(e), n;\n }\n function i() {\n return this.isSmartPointer ? dr(this.registeredClass.instancePrototype, { ptrType: this.pointeeType, ptr: r, smartPtrType: this, smartPtr: e }) : dr(this.registeredClass.instancePrototype, { ptrType: this, ptr: e });\n }\n var a = this.registeredClass.getActualType(r), s = se[a];\n if (!s) return i.call(this);\n var o;\n this.isConst ? o = s.constPointerType : o = s.pointerType;\n var u = oe(r, this.registeredClass, o.registeredClass);\n return u === null ? i.call(this) : this.isSmartPointer ? dr(o.registeredClass.instancePrototype, { ptrType: o, ptr: u, smartPtrType: this, smartPtr: e }) : dr(o.registeredClass.instancePrototype, { ptrType: o, ptr: u });\n }\n var Ot = () => {\n Object.assign(pr.prototype, { getPointee(e) {\n return this.rawGetPointee && (e = this.rawGetPointee(e)), e;\n }, destructor(e) {\n this.rawDestructor?.(e);\n }, readValueFromPointer: vr, fromWireType: xt });\n };\n function pr(e, r, t, n, i, a, s, o, u, c, f) {\n this.name = e, this.registeredClass = r, this.isReference = t, this.isConst = n, this.isSmartPointer = i, this.pointeeType = a, this.sharingPolicy = s, this.rawGetPointee = o, this.rawConstructor = u, this.rawShare = c, this.rawDestructor = f, !i && r.baseClass === void 0 ? n ? (this.toWireType = kt, this.destructorFunction = null) : (this.toWireType = At, this.destructorFunction = null) : this.toWireType = St;\n }\n var ue = (e, r, t) => {\n l.hasOwnProperty(e) || _r("Replacing nonexistent public symbol"), l[e].overloadTable !== void 0 && t !== void 0 ? l[e].overloadTable[t] = r : (l[e] = r, l[e].argCount = t);\n }, ce = [], fe, b = (e) => {\n var r = ce[e];\n return r || (ce[e] = r = fe.get(e)), r;\n }, R = (e, r, t = false) => {\n e = C(e);\n function n() {\n var a = b(r);\n return a;\n }\n var i = n();\n return typeof i != "function" && h(`unknown function pointer with signature ${e}: ${r}`), i;\n };\n class Ut extends Error {\n }\n var le = (e) => {\n var r = Ae(e), t = C(r);\n return O(r), t;\n }, I = (e, r) => {\n var t = [], n = {};\n function i(a) {\n if (!n[a] && !j[a]) {\n if (or[a]) {\n or[a].forEach(i);\n return;\n }\n t.push(a), n[a] = true;\n }\n }\n throw r.forEach(i), new Ut(`${e}: ` + t.map(le).join([", "]));\n }, D = (e, r, t) => {\n e.forEach((o) => or[o] = r);\n function n(o) {\n var u = t(o);\n u.length !== e.length && _r("Mismatched type converter count");\n for (var c = 0; c < e.length; ++c) E(e[c], u[c]);\n }\n var i = new Array(r.length), a = [], s = 0;\n r.forEach((o, u) => {\n j.hasOwnProperty(o) ? i[u] = j[o] : (a.push(o), Y.hasOwnProperty(o) || (Y[o] = []), Y[o].push(() => {\n i[u] = j[o], ++s, s === a.length && n(i);\n }));\n }), a.length === 0 && n(i);\n }, Vt = (e, r, t, n, i, a, s, o, u, c, f, _, d) => {\n f = C(f), a = R(i, a), o &&= R(s, o), c &&= R(u, c), d = R(_, d);\n var p = Ct(f);\n Rr(p, function() {\n I(`Cannot construct ${f} due to unbound types`, [n]);\n }), D([e, r, t], n ? [n] : [], (v) => {\n v = v[0];\n var $, P;\n n ? ($ = v.registeredClass, P = $.instancePrototype) : P = cr.prototype;\n var F = fr(f, function(...Hr) {\n if (Object.getPrototypeOf(this) !== Z) throw new q(`Use \'new\' to construct ${f}`);\n if (S.constructor_body === void 0) throw new q(`${f} has no accessible constructor`);\n var Be = S.constructor_body[Hr.length];\n if (Be === void 0) throw new q(`Tried to invoke ctor of ${f} with invalid number of parameters (${Hr.length}) - expected (${Object.keys(S.constructor_body).toString()}) parameters instead!`);\n return Be.apply(this, Hr);\n }), Z = Object.create(P, { constructor: { value: F } });\n F.prototype = Z;\n var S = new Pt(f, F, Z, d, $, a, o, c);\n S.baseClass && (S.baseClass.__derivedClasses ??= [], S.baseClass.__derivedClasses.push(S));\n var Bi = new pr(f, S, true, false, false), Me = new pr(f + "*", S, false, false, false), He = new pr(f + " const*", S, false, true, false);\n return se[e] = { pointerType: Me, constPointerType: He }, ue(p, F), [Bi, Me, He];\n });\n }, Wr = (e) => {\n for (; e.length; ) {\n var r = e.pop(), t = e.pop();\n t(r);\n }\n };\n function ve(e) {\n for (var r = 1; r < e.length; ++r) if (e[r] !== null && e[r].destructorFunction === void 0) return true;\n return false;\n }\n function jt(e, r, t, n) {\n var i = ve(e), a = e.length - 2, s = [], o = ["fn"];\n r && o.push("thisWired");\n for (var u = 0; u < a; ++u) s.push(`arg${u}`), o.push(`arg${u}Wired`);\n s = s.join(","), o = o.join(",");\n var c = `return function (${s}) {\n`;\n i && (c += `var destructors = [];\n`);\n var f = i ? "destructors" : "null", _ = ["humanName", "throwBindingError", "invoker", "fn", "runDestructors", "fromRetWire", "toClassParamWire"];\n r && (c += `var thisWired = toClassParamWire(${f}, this);\n`);\n for (var u = 0; u < a; ++u) {\n var d = `toArg${u}Wire`;\n c += `var arg${u}Wired = ${d}(${f}, arg${u});\n`, _.push(d);\n }\n c += (t || n ? "var rv = " : "") + `invoker(${o});\n`;\n if (i) c += `runDestructors(destructors);\n`;\n else for (var u = r ? 1 : 2; u < e.length; ++u) {\n var v = u === 1 ? "thisWired" : "arg" + (u - 2) + "Wired";\n e[u].destructorFunction !== null && (c += `${v}_dtor(${v});\n`, _.push(`${v}_dtor`));\n }\n return t && (c += `var ret = fromRetWire(rv);\nreturn ret;\n`), c += `}\n`, new Function(_, c);\n }\n function hr(e, r, t, n, i, a) {\n var s = r.length;\n s < 2 && h("argTypes array size mismatch! Must at least get return value and \'this\' types!");\n for (var o = r[1] !== null && t !== null, u = ve(r), c = !r[0].isVoid, f = s - 2, _ = r[0], d = r[1], p = [e, h, n, i, Wr, _.fromWireType.bind(_), d?.toWireType.bind(d)], v = 2; v < s; ++v) {\n var $ = r[v];\n p.push($.toWireType.bind($));\n }\n if (!u) for (var v = o ? 1 : 2; v < r.length; ++v) r[v].destructorFunction !== null && p.push(r[v].destructorFunction);\n var F = jt(r, o, c, a)(...p);\n return fr(e, F);\n }\n var gr = (e, r) => {\n for (var t = [], n = 0; n < e; n++) t.push(w[r + n * 4 >> 2]);\n return t;\n }, xr = (e) => {\n e = e.trim();\n const r = e.indexOf("(");\n return r === -1 ? e : e.slice(0, r);\n }, It = (e, r, t, n, i, a, s, o, u) => {\n var c = gr(t, n);\n r = C(r), r = xr(r), a = R(i, a, o), D([], [e], (f) => {\n f = f[0];\n var _ = `${f.name}.${r}`;\n function d() {\n I(`Cannot call ${_} due to unbound types`, c);\n }\n r.startsWith("@@") && (r = Symbol[r.substring(2)]);\n var p = f.registeredClass.constructor;\n return p[r] === void 0 ? (d.argCount = t - 1, p[r] = d) : (Er(p, r, _), p[r].overloadTable[t - 1] = d), D([], c, (v) => {\n var $ = [v[0], null].concat(v.slice(1)), P = hr(_, $, null, a, s, o);\n if (p[r].overloadTable === void 0 ? (P.argCount = t - 1, p[r] = P) : p[r].overloadTable[t - 1] = P, f.registeredClass.__derivedClasses) for (const F of f.registeredClass.__derivedClasses) F.constructor.hasOwnProperty(r) || (F.constructor[r] = P);\n return [];\n }), [];\n });\n }, Mt = (e, r, t, n, i, a) => {\n var s = gr(r, t);\n i = R(n, i);\n D([], [e], (c) => {\n c = c[0];\n var f = `constructor ${c.name}`;\n if (c.registeredClass.constructor_body === void 0 && (c.registeredClass.constructor_body = []), c.registeredClass.constructor_body[r - 1] !== void 0) throw new q(`Cannot register multiple constructors with identical number of parameters (${r - 1}) for class \'${c.name}\'! Overload resolution is currently only performed using the parameter count, not actual type info!`);\n return c.registeredClass.constructor_body[r - 1] = () => {\n I(`Cannot construct ${c.name} due to unbound types`, s);\n }, D([], s, (_) => (_.splice(1, 0, null), c.registeredClass.constructor_body[r - 1] = hr(f, _, null, i, a), [])), [];\n });\n }, Ht = (e, r, t, n, i, a, s, o, u, c) => {\n var f = gr(t, n);\n r = C(r), r = xr(r), a = R(i, a, u), D([], [e], (_) => {\n _ = _[0];\n var d = `${_.name}.${r}`;\n r.startsWith("@@") && (r = Symbol[r.substring(2)]), o && _.registeredClass.pureVirtualFunctions.push(r);\n function p() {\n I(`Cannot call ${d} due to unbound types`, f);\n }\n var v = _.registeredClass.instancePrototype, $ = v[r];\n return $ === void 0 || $.overloadTable === void 0 && $.className !== _.name && $.argCount === t - 2 ? (p.argCount = t - 2, p.className = _.name, v[r] = p) : (Er(v, r, d), v[r].overloadTable[t - 2] = p), D([], f, (P) => {\n var F = hr(d, P, _, a, s, u);\n return v[r].overloadTable === void 0 ? (F.argCount = t - 2, v[r] = F) : v[r].overloadTable[t - 2] = F, [];\n }), [];\n });\n }, _e = (e, r, t) => (e instanceof Object || h(`${t} with invalid "this": ${e}`), e instanceof r.registeredClass.constructor || h(`${t} incompatible with "this" of type ${e.constructor.name}`), e.$$.ptr || h(`cannot call emscripten binding method ${t} on deleted object`), lr(e.$$.ptr, e.$$.ptrType.registeredClass, r.registeredClass)), Bt = (e, r, t, n, i, a, s, o, u, c) => {\n r = C(r), i = R(n, i), D([], [e], (f) => {\n f = f[0];\n var _ = `${f.name}.${r}`, d = { get() {\n I(`Cannot access ${_} due to unbound types`, [t, s]);\n }, enumerable: true, configurable: true };\n return u ? d.set = () => I(`Cannot access ${_} due to unbound types`, [t, s]) : d.set = (p) => h(_ + " is a read-only property"), Object.defineProperty(f.registeredClass.instancePrototype, r, d), D([], u ? [t, s] : [t], (p) => {\n var v = p[0], $ = { get() {\n var F = _e(this, f, _ + " getter");\n return v.fromWireType(i(a, F));\n }, enumerable: true };\n if (u) {\n u = R(o, u);\n var P = p[1];\n $.set = function(F) {\n var Z = _e(this, f, _ + " setter"), S = [];\n u(c, Z, P.toWireType(S, F)), Wr(S);\n };\n }\n return Object.defineProperty(f.registeredClass.instancePrototype, r, $), [];\n }), [];\n });\n }, de = [], N = [0, 1, , 1, null, 1, true, 1, false, 1], Or = (e) => {\n e > 9 && --N[e + 1] === 0 && (N[e] = void 0, de.push(e));\n }, W = { toValue: (e) => (e || h(`Cannot use deleted val. handle = ${e}`), N[e]), toHandle: (e) => {\n switch (e) {\n case void 0:\n return 2;\n case null:\n return 4;\n case true:\n return 6;\n case false:\n return 8;\n default: {\n const r = de.pop() || N.length;\n return N[r] = e, N[r + 1] = 1, r;\n }\n }\n } }, Lt = { name: "emscripten::val", fromWireType: (e) => {\n var r = W.toValue(e);\n return Or(e), r;\n }, toWireType: (e, r) => W.toHandle(r), readValueFromPointer: vr, destructorFunction: null }, zt = (e) => E(e, Lt), Yt = (e, r, t) => {\n switch (r) {\n case 1:\n return t ? function(n) {\n return this.fromWireType(k[n]);\n } : function(n) {\n return this.fromWireType(A[n]);\n };\n case 2:\n return t ? function(n) {\n return this.fromWireType(U[n >> 1]);\n } : function(n) {\n return this.fromWireType(L[n >> 1]);\n };\n case 4:\n return t ? function(n) {\n return this.fromWireType(T[n >> 2]);\n } : function(n) {\n return this.fromWireType(w[n >> 2]);\n };\n default:\n throw new TypeError(`invalid integer width (${r}): ${e}`);\n }\n }, Nt = (e, r, t, n) => {\n r = C(r);\n function i() {\n }\n i.values = {}, E(e, { name: r, constructor: i, fromWireType: function(a) {\n return this.constructor.values[a];\n }, toWireType: (a, s) => s.value, readValueFromPointer: Yt(r, t, n), destructorFunction: null }), Rr(r, i);\n }, pe = (e, r) => {\n var t = j[e];\n return t === void 0 && h(`${r} has unknown type ${le(e)}`), t;\n }, Gt = (e, r, t) => {\n var n = pe(e, "enum");\n r = C(r);\n var i = n.constructor, a = Object.create(n.constructor.prototype, { value: { value: t }, constructor: { value: fr(`${n.name}_${r}`, function() {\n }) } });\n i.values[t] = a, i[r] = a;\n }, qt = (e, r) => {\n switch (r) {\n case 4:\n return function(t) {\n return this.fromWireType(tr[t >> 2]);\n };\n case 8:\n return function(t) {\n return this.fromWireType(nr[t >> 3]);\n };\n default:\n throw new TypeError(`invalid float width (${r}): ${e}`);\n }\n }, Xt = (e, r, t) => {\n r = C(r), E(e, { name: r, fromWireType: (n) => n, toWireType: (n, i) => i, readValueFromPointer: qt(r, t), destructorFunction: null });\n }, Jt = (e, r, t, n, i, a, s, o) => {\n var u = gr(r, t);\n e = C(e), e = xr(e), i = R(n, i, s), Rr(e, function() {\n I(`Cannot call ${e} due to unbound types`, u);\n }, r - 1), D([], u, (c) => {\n var f = [c[0], null].concat(c.slice(1));\n return ue(e, hr(e, f, null, i, a, s), r - 1), [];\n });\n }, Kt = (e, r, t, n, i) => {\n r = C(r);\n const a = n === 0;\n let s = (u) => u;\n if (a) {\n var o = 32 - 8 * t;\n s = (u) => u << o >>> o, i = s(i);\n }\n E(e, { name: r, fromWireType: s, toWireType: (u, c) => c, readValueFromPointer: te(r, t, n !== 0), destructorFunction: null });\n }, Zt = (e, r, t) => {\n var n = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, BigInt64Array, BigUint64Array], i = n[r];\n function a(s) {\n var o = w[s >> 2], u = w[s + 4 >> 2];\n return new i(k.buffer, u, o);\n }\n t = C(t), E(e, { name: t, fromWireType: a, readValueFromPointer: a }, { ignoreDuplicateRegistrations: true });\n }, Qt = (e, r, t, n) => {\n if (!(n > 0)) return 0;\n for (var i = t, a = t + n - 1, s = 0; s < e.length; ++s) {\n var o = e.codePointAt(s);\n if (o <= 127) {\n if (t >= a) break;\n r[t++] = o;\n } else if (o <= 2047) {\n if (t + 1 >= a) break;\n r[t++] = 192 | o >> 6, r[t++] = 128 | o & 63;\n } else if (o <= 65535) {\n if (t + 2 >= a) break;\n r[t++] = 224 | o >> 12, r[t++] = 128 | o >> 6 & 63, r[t++] = 128 | o & 63;\n } else {\n if (t + 3 >= a) break;\n r[t++] = 240 | o >> 18, r[t++] = 128 | o >> 12 & 63, r[t++] = 128 | o >> 6 & 63, r[t++] = 128 | o & 63, s++;\n }\n }\n return r[t] = 0, t - i;\n }, M = (e, r, t) => Qt(e, A, r, t), Ur = (e) => {\n for (var r = 0, t = 0; t < e.length; ++t) {\n var n = e.charCodeAt(t);\n n <= 127 ? r++ : n <= 2047 ? r += 2 : n >= 55296 && n <= 57343 ? (r += 4, ++t) : r += 3;\n }\n return r;\n }, he = typeof TextDecoder < "u" ? new TextDecoder() : void 0, ge = (e, r, t, n) => {\n var i = r + t;\n if (n) return i;\n for (; e[r] && !(r >= i); ) ++r;\n return r;\n }, ye = (e, r = 0, t, n) => {\n var i = ge(e, r, t, n);\n if (i - r > 16 && e.buffer && he) return he.decode(e.subarray(r, i));\n for (var a = ""; r < i; ) {\n var s = e[r++];\n if (!(s & 128)) {\n a += String.fromCharCode(s);\n continue;\n }\n var o = e[r++] & 63;\n if ((s & 224) == 192) {\n a += String.fromCharCode((s & 31) << 6 | o);\n continue;\n }\n var u = e[r++] & 63;\n if ((s & 240) == 224 ? s = (s & 15) << 12 | o << 6 | u : s = (s & 7) << 18 | o << 12 | u << 6 | e[r++] & 63, s < 65536) a += String.fromCharCode(s);\n else {\n var c = s - 65536;\n a += String.fromCharCode(55296 | c >> 10, 56320 | c & 1023);\n }\n }\n return a;\n }, yr = (e, r, t) => e ? ye(A, e, r, t) : "", rn = (e, r) => {\n r = C(r);\n E(e, { name: r, fromWireType(n) {\n var i = w[n >> 2], a = n + 4, s;\n s = yr(a, i, true);\n return O(n), s;\n }, toWireType(n, i) {\n i instanceof ArrayBuffer && (i = new Uint8Array(i));\n var a, s = typeof i == "string";\n s || ArrayBuffer.isView(i) && i.BYTES_PER_ELEMENT == 1 || h("Cannot pass non-string to std::string"), s ? a = Ur(i) : a = i.length;\n var o = Mr(4 + a + 1), u = o + 4;\n if (w[o >> 2] = a, s) M(i, u, a + 1);\n else A.set(i, u);\n return n !== null && n.push(O, o), o;\n }, readValueFromPointer: vr, destructorFunction(n) {\n O(n);\n } });\n }, me = typeof TextDecoder < "u" ? new TextDecoder("utf-16le") : void 0, en = (e, r, t) => {\n var n = e >> 1, i = ge(L, n, r / 2, t);\n if (i - n > 16 && me) return me.decode(L.subarray(n, i));\n for (var a = "", s = n; s < i; ++s) {\n var o = L[s];\n a += String.fromCharCode(o);\n }\n return a;\n }, tn = (e, r, t) => {\n if (t ??= 2147483647, t < 2) return 0;\n t -= 2;\n for (var n = r, i = t < e.length * 2 ? t / 2 : e.length, a = 0; a < i; ++a) {\n var s = e.charCodeAt(a);\n U[r >> 1] = s, r += 2;\n }\n return U[r >> 1] = 0, r - n;\n }, nn = (e) => e.length * 2, an = (e, r, t) => {\n for (var n = "", i = e >> 2, a = 0; !(a >= r / 4); a++) {\n var s = w[i + a];\n if (!s && !t) break;\n n += String.fromCodePoint(s);\n }\n return n;\n }, sn = (e, r, t) => {\n if (t ??= 2147483647, t < 4) return 0;\n for (var n = r, i = n + t - 4, a = 0; a < e.length; ++a) {\n var s = e.codePointAt(a);\n if (s > 65535 && a++, T[r >> 2] = s, r += 4, r + 4 > i) break;\n }\n return T[r >> 2] = 0, r - n;\n }, on = (e) => {\n for (var r = 0, t = 0; t < e.length; ++t) {\n var n = e.codePointAt(t);\n n > 65535 && t++, r += 4;\n }\n return r;\n }, un = (e, r, t) => {\n t = C(t);\n var n, i, a;\n r === 2 ? (n = en, i = tn, a = nn) : (n = an, i = sn, a = on), E(e, { name: t, fromWireType: (s) => {\n var o = w[s >> 2], u = n(s + 4, o * r, true);\n return O(s), u;\n }, toWireType: (s, o) => {\n typeof o != "string" && h(`Cannot pass non-string to C++ string type ${t}`);\n var u = a(o), c = Mr(4 + u + r);\n return w[c >> 2] = u / r, i(o, c + 4, u + r), s !== null && s.push(O, c), c;\n }, readValueFromPointer: vr, destructorFunction(s) {\n O(s);\n } });\n }, cn = (e, r) => {\n r = C(r), E(e, { isVoid: true, name: r, fromWireType: () => {\n }, toWireType: (t, n) => {\n } });\n }, be = 0, fn = () => {\n Cr = false, be = 0;\n }, Vr = [], ln = (e) => {\n var r = Vr.length;\n return Vr.push(e), r;\n }, vn = (e, r) => {\n for (var t = new Array(e), n = 0; n < e; ++n) t[n] = pe(w[r + n * 4 >> 2], `parameter ${n}`);\n return t;\n }, _n = (e, r, t) => {\n var n = [], i = e(n, t);\n return n.length && (w[r >> 2] = W.toHandle(n)), i;\n }, dn = {}, pn = (e) => {\n var r = dn[e];\n return r === void 0 ? C(e) : r;\n }, hn = (e, r, t) => {\n var n = 8, [i, ...a] = vn(e, r), s = i.toWireType.bind(i), o = a.map((p) => p.readValueFromPointer.bind(p));\n e--;\n var u = { toValue: W.toValue }, c = o.map((p, v) => {\n var $ = `argFromPtr${v}`;\n return u[$] = p, `${$}(args${v ? "+" + v * n : ""})`;\n }), f;\n switch (t) {\n case 0:\n f = "toValue(handle)";\n break;\n case 2:\n f = "new (toValue(handle))";\n break;\n case 3:\n f = "";\n break;\n case 1:\n u.getStringOrSymbol = pn, f = "toValue(handle)[getStringOrSymbol(methodName)]";\n break;\n }\n f += `(${c})`, i.isVoid || (u.toReturnWire = s, u.emval_returnValue = _n, f = `return emval_returnValue(toReturnWire, destructorsRef, ${f})`), f = `return function (handle, methodName, destructorsRef, args) {\n ${f}\n }`;\n var _ = new Function(Object.keys(u), f)(...Object.values(u)), d = `methodCaller<(${a.map((p) => p.name)}) => ${i.name}>`;\n return ln(fr(d, _));\n }, gn = (e, r, t, n, i) => Vr[e](r, t, n, i), yn = () => W.toHandle({}), mn = (e) => {\n var r = W.toValue(e);\n Wr(r), Or(e);\n }, bn = (e, r, t) => {\n e = W.toValue(e), r = W.toValue(r), t = W.toValue(t), e[r] = t;\n }, $n = 9007199254740992, wn = -9007199254740992, mr = (e) => e < wn || e > $n ? NaN : Number(e);\n function Tn(e, r) {\n e = mr(e);\n var t = new Date(e * 1e3);\n T[r >> 2] = t.getUTCSeconds(), T[r + 4 >> 2] = t.getUTCMinutes(), T[r + 8 >> 2] = t.getUTCHours(), T[r + 12 >> 2] = t.getUTCDate(), T[r + 16 >> 2] = t.getUTCMonth(), T[r + 20 >> 2] = t.getUTCFullYear() - 1900, T[r + 24 >> 2] = t.getUTCDay();\n var n = Date.UTC(t.getUTCFullYear(), 0, 1, 0, 0, 0, 0), i = (t.getTime() - n) / (1e3 * 60 * 60 * 24) | 0;\n T[r + 28 >> 2] = i;\n }\n var Fn = (e) => e % 4 === 0 && (e % 100 !== 0 || e % 400 === 0), Cn = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335], Pn = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334], kn = (e) => {\n var r = Fn(e.getFullYear()), t = r ? Cn : Pn, n = t[e.getMonth()] + e.getDate() - 1;\n return n;\n };\n function Sn(e, r) {\n e = mr(e);\n var t = new Date(e * 1e3);\n T[r >> 2] = t.getSeconds(), T[r + 4 >> 2] = t.getMinutes(), T[r + 8 >> 2] = t.getHours(), T[r + 12 >> 2] = t.getDate(), T[r + 16 >> 2] = t.getMonth(), T[r + 20 >> 2] = t.getFullYear() - 1900, T[r + 24 >> 2] = t.getDay();\n var n = kn(t) | 0;\n T[r + 28 >> 2] = n, T[r + 36 >> 2] = -(t.getTimezoneOffset() * 60);\n var i = new Date(t.getFullYear(), 0, 1), a = new Date(t.getFullYear(), 6, 1).getTimezoneOffset(), s = i.getTimezoneOffset(), o = (a != s && t.getTimezoneOffset() == Math.min(s, a)) | 0;\n T[r + 32 >> 2] = o;\n }\n var J = {}, $e = (e) => {\n if (e instanceof Zr || e == "unwind") return rr;\n zr(1, e);\n }, we = () => Cr || be > 0, Te = (e) => {\n rr = e, we() || (l.onExit?.(e), Q = true), zr(e, new Zr(e));\n }, An = (e, r) => {\n rr = e, Te(e);\n }, En = An, Rn = () => {\n if (!we()) try {\n En(rr);\n } catch (e) {\n $e(e);\n }\n }, Dn = (e) => {\n if (!Q) try {\n e(), Rn();\n } catch (r) {\n $e(r);\n }\n }, Fe = () => performance.now(), Wn = (e, r) => {\n if (J[e] && (clearTimeout(J[e].id), delete J[e]), !r) return 0;\n var t = setTimeout(() => {\n delete J[e], Dn(() => Ee(e, Fe()));\n }, r);\n return J[e] = { id: t, timeout_ms: r }, 0;\n }, xn = (e, r, t, n) => {\n var i = (/* @__PURE__ */ new Date()).getFullYear(), a = new Date(i, 0, 1), s = new Date(i, 6, 1), o = a.getTimezoneOffset(), u = s.getTimezoneOffset(), c = Math.max(o, u);\n w[e >> 2] = c * 60, T[r >> 2] = +(o != u);\n var f = (p) => {\n var v = p >= 0 ? "-" : "+", $ = Math.abs(p), P = String(Math.floor($ / 60)).padStart(2, "0"), F = String($ % 60).padStart(2, "0");\n return `UTC${v}${P}${F}`;\n }, _ = f(o), d = f(u);\n u < o ? (M(_, t, 17), M(d, n, 17)) : (M(_, n, 17), M(d, t, 17));\n }, On = () => Date.now(), Vn = (e) => e >= 0 && e <= 3;\n function jn(e, r, t) {\n if (!Vn(e)) return 28;\n var n;\n if (e === 0) n = On();\n else n = Fe();\n var i = Math.round(n * 1e3 * 1e3);\n return V[t >> 3] = BigInt(i), 0;\n }\n var Ce = () => 2147483648, In = () => Ce(), Mn = (e, r) => Math.ceil(e / r) * r, Hn = (e) => {\n var r = er.buffer.byteLength, t = (e - r + 65535) / 65536 | 0;\n try {\n return er.grow(t), Kr(), 1;\n } catch {\n }\n }, Bn = (e) => {\n var r = A.length;\n e >>>= 0;\n var t = Ce();\n if (e > t) return false;\n for (var n = 1; n <= 4; n *= 2) {\n var i = r * (1 + 0.2 / n);\n i = Math.min(i, e + 100663296);\n var a = Math.min(t, Mn(Math.max(e, i), 65536)), s = Hn(a);\n if (s) return true;\n }\n return false;\n }, br = {}, Ln = () => Lr || "./this.program", K = () => {\n if (!K.strings) {\n var e = (typeof navigator == "object" && navigator.language || "C").replace("-", "_") + ".UTF-8", r = { USER: "web_user", LOGNAME: "web_user", PATH: "/", PWD: "/", HOME: "/home/web_user", LANG: e, _: Ln() };\n for (var t in br) br[t] === void 0 ? delete r[t] : r[t] = br[t];\n var n = [];\n for (var t in r) n.push(`${t}=${r[t]}`);\n K.strings = n;\n }\n return K.strings;\n }, zn = (e, r) => {\n var t = 0, n = 0;\n for (var i of K()) {\n var a = r + t;\n w[e + n >> 2] = a, t += M(i, a, 1 / 0) + 1, n += 4;\n }\n return 0;\n }, Yn = (e, r) => {\n var t = K();\n w[e >> 2] = t.length;\n var n = 0;\n for (var i of t) n += Ur(i) + 1;\n return w[r >> 2] = n, 0;\n }, Nn = (e) => 52, Gn = (e, r) => {\n var t = 0, n = 0, i = 0;\n {\n var a = 2;\n e == 0 ? t = 2 : (e == 1 || e == 2) && (t = 64), i = 1;\n }\n return k[r] = a, U[r + 2 >> 1] = i, V[r + 8 >> 3] = BigInt(t), V[r + 16 >> 3] = BigInt(n), 0;\n };\n function qn(e, r, t, n) {\n return 70;\n }\n var jr = [null, [], []], Ir = (e, r) => {\n var t = jr[e];\n r === 0 || r === 10 ? ((e === 1 ? Nr : B)(ye(t)), t.length = 0) : t.push(r);\n }, Xn = (e, r, t, n) => {\n for (var i = 0, a = 0; a < t; a++) {\n var s = w[r >> 2], o = w[r + 4 >> 2];\n r += 8;\n for (var u = 0; u < o; u++) Ir(e, A[s + u]);\n i += o;\n }\n return w[n >> 2] = i, 0;\n }, Jn = (e) => e, Pe = (e) => {\n var r = l["_" + e];\n return r;\n }, Kn = (e, r) => {\n k.set(e, r);\n }, ke = (e) => We(e), Zn = (e) => {\n var r = Ur(e) + 1, t = ke(r);\n return M(e, t, r), t;\n }, Se = (e, r, t, n, i) => {\n var a = { string: (v) => {\n var $ = 0;\n return v != null && v !== 0 && ($ = Zn(v)), $;\n }, array: (v) => {\n var $ = ke(v.length);\n return Kn(v, $), $;\n } };\n function s(v) {\n return r === "string" ? yr(v) : r === "boolean" ? !!v : v;\n }\n var o = Pe(e), u = [], c = 0;\n if (n) for (var f = 0; f < n.length; f++) {\n var _ = a[t[f]];\n _ ? (c === 0 && (c = m()), u[f] = _(n[f])) : u[f] = n[f];\n }\n var d = o(...u);\n function p(v) {\n return c !== 0 && y(c), s(v);\n }\n return d = p(d), d;\n }, Qn = (e, r, t, n) => {\n var i = !t || t.every((s) => s === "number" || s === "boolean"), a = r !== "string";\n return a && i && !n ? Pe(e) : (...s) => Se(e, r, t, s);\n };\n if (wt(), Ot(), l.noExitRuntime && (Cr = l.noExitRuntime), l.print && (Nr = l.print), l.printErr && (B = l.printErr), l.wasmBinary && (G = l.wasmBinary), l.arguments && l.arguments, l.thisProgram && (Lr = l.thisProgram), l.preInit) for (typeof l.preInit == "function" && (l.preInit = [l.preInit]); l.preInit.length > 0; ) l.preInit.shift()();\n l.ENV = br, l.ccall = Se, l.cwrap = Qn;\n var Ae, Mr, O, Ee, g, Re, De, We, xe, Oe, Ue, Ve, je;\n function si(e) {\n Ae = e.__getTypeName, l._malloc = Mr = e.malloc, l._parseDropFile = e.parseDropFile, l._getAttributeFromDropFile = e.getAttributeFromDropFile, l._takeAttributeFromDropFile = e.takeAttributeFromDropFile, l._flattenDropFile = e.flattenDropFile, l._destroyDropFileHandle = e.destroyDropFileHandle, e.__cxa_free_exception, l._free = O = e.free, Ee = e._emscripten_timeout, g = e.setThrew, Re = e._emscripten_tempret_set, De = e._emscripten_stack_restore, We = e._emscripten_stack_alloc, xe = e.emscripten_stack_get_current, Oe = e.__cxa_decrement_exception_refcount, Ue = e.__cxa_increment_exception_refcount, Ve = e.__cxa_can_catch, je = e.__cxa_get_exception_ptr;\n }\n var Ie = { __cxa_begin_catch: st, __cxa_end_catch: ot, __cxa_find_matching_catch_2: ut, __cxa_find_matching_catch_3: ct, __cxa_find_matching_catch_4: ft, __cxa_rethrow: lt, __cxa_throw: vt, __cxa_uncaught_exceptions: _t, __resumeException: dt, _abort_js: pt, _embind_register_bigint: gt, _embind_register_bool: yt, _embind_register_class: Vt, _embind_register_class_class_function: It, _embind_register_class_constructor: Mt, _embind_register_class_function: Ht, _embind_register_class_property: Bt, _embind_register_emval: zt, _embind_register_enum: Nt, _embind_register_enum_value: Gt, _embind_register_float: Xt, _embind_register_function: Jt, _embind_register_integer: Kt, _embind_register_memory_view: Zt, _embind_register_std_string: rn, _embind_register_std_wstring: un, _embind_register_void: cn, _emscripten_runtime_keepalive_clear: fn, _emval_create_invoker: hn, _emval_decref: Or, _emval_invoke: gn, _emval_new_object: yn, _emval_run_destructors: mn, _emval_set_property: bn, _gmtime_js: Tn, _localtime_js: Sn, _setitimer_js: Wn, _tzset_js: xn, clock_time_get: jn, emscripten_get_heap_max: In, emscripten_resize_heap: Bn, environ_get: zn, environ_sizes_get: Yn, fd_close: Nn, fd_fdstat_get: Gn, fd_seek: qn, fd_write: Xn, invoke_diii: Wi, invoke_fi: Ti, invoke_fiii: Di, invoke_i: Ci, invoke_ii: ui, invoke_iii: ci, invoke_iiii: mi, invoke_iiiid: Oi, invoke_iiiii: wi, invoke_iiiiid: Ai, invoke_iiiiii: hi, invoke_iiiiiii: Ui, invoke_iiiiiiii: Ei, invoke_iiiiiiiiii: yi, invoke_iiiiiiiiiii: _i, invoke_iiiiiiiiiiii: di, invoke_iiiiijj: Vi, invoke_iiiijj: ji, invoke_iiij: Pi, invoke_j: ki, invoke_jiiii: Ri, invoke_v: pi, invoke_vi: oi, invoke_vii: li, invoke_viii: fi, invoke_viiii: vi, invoke_viiiii: bi, invoke_viiiiii: gi, invoke_viiiiiii: xi, invoke_viiiiiiii: Fi, invoke_viiiiiiiiii: Ii, invoke_viiiiiiiiiiiiiii: Mi, invoke_viiji: Si, invoke_viijii: $i, llvm_eh_typeid_for: Jn, proc_exit: Te };\n function oi(e, r) {\n var t = m();\n try {\n b(e)(r);\n } catch (n) {\n if (y(t), n !== n + 0) throw n;\n g(1, 0);\n }\n }\n function ui(e, r) {\n var t = m();\n try {\n return b(e)(r);\n } catch (n) {\n if (y(t), n !== n + 0) throw n;\n g(1, 0);\n }\n }\n function ci(e, r, t) {\n var n = m();\n try {\n return b(e)(r, t);\n } catch (i) {\n if (y(n), i !== i + 0) throw i;\n g(1, 0);\n }\n }\n function fi(e, r, t, n) {\n var i = m();\n try {\n b(e)(r, t, n);\n } catch (a) {\n if (y(i), a !== a + 0) throw a;\n g(1, 0);\n }\n }\n function li(e, r, t) {\n var n = m();\n try {\n b(e)(r, t);\n } catch (i) {\n if (y(n), i !== i + 0) throw i;\n g(1, 0);\n }\n }\n function vi(e, r, t, n, i) {\n var a = m();\n try {\n b(e)(r, t, n, i);\n } catch (s) {\n if (y(a), s !== s + 0) throw s;\n g(1, 0);\n }\n }\n function _i(e, r, t, n, i, a, s, o, u, c, f) {\n var _ = m();\n try {\n return b(e)(r, t, n, i, a, s, o, u, c, f);\n } catch (d) {\n if (y(_), d !== d + 0) throw d;\n g(1, 0);\n }\n }\n function di(e, r, t, n, i, a, s, o, u, c, f, _) {\n var d = m();\n try {\n return b(e)(r, t, n, i, a, s, o, u, c, f, _);\n } catch (p) {\n if (y(d), p !== p + 0) throw p;\n g(1, 0);\n }\n }\n function pi(e) {\n var r = m();\n try {\n b(e)();\n } catch (t) {\n if (y(r), t !== t + 0) throw t;\n g(1, 0);\n }\n }\n function hi(e, r, t, n, i, a) {\n var s = m();\n try {\n return b(e)(r, t, n, i, a);\n } catch (o) {\n if (y(s), o !== o + 0) throw o;\n g(1, 0);\n }\n }\n function gi(e, r, t, n, i, a, s) {\n var o = m();\n try {\n b(e)(r, t, n, i, a, s);\n } catch (u) {\n if (y(o), u !== u + 0) throw u;\n g(1, 0);\n }\n }\n function yi(e, r, t, n, i, a, s, o, u, c) {\n var f = m();\n try {\n return b(e)(r, t, n, i, a, s, o, u, c);\n } catch (_) {\n if (y(f), _ !== _ + 0) throw _;\n g(1, 0);\n }\n }\n function mi(e, r, t, n) {\n var i = m();\n try {\n return b(e)(r, t, n);\n } catch (a) {\n if (y(i), a !== a + 0) throw a;\n g(1, 0);\n }\n }\n function bi(e, r, t, n, i, a) {\n var s = m();\n try {\n b(e)(r, t, n, i, a);\n } catch (o) {\n if (y(s), o !== o + 0) throw o;\n g(1, 0);\n }\n }\n function $i(e, r, t, n, i, a) {\n var s = m();\n try {\n b(e)(r, t, n, i, a);\n } catch (o) {\n if (y(s), o !== o + 0) throw o;\n g(1, 0);\n }\n }\n function wi(e, r, t, n, i) {\n var a = m();\n try {\n return b(e)(r, t, n, i);\n } catch (s) {\n if (y(a), s !== s + 0) throw s;\n g(1, 0);\n }\n }\n function Ti(e, r) {\n var t = m();\n try {\n return b(e)(r);\n } catch (n) {\n if (y(t), n !== n + 0) throw n;\n g(1, 0);\n }\n }\n function Fi(e, r, t, n, i, a, s, o, u) {\n var c = m();\n try {\n b(e)(r, t, n, i, a, s, o, u);\n } catch (f) {\n if (y(c), f !== f + 0) throw f;\n g(1, 0);\n }\n }\n function Ci(e) {\n var r = m();\n try {\n return b(e)();\n } catch (t) {\n if (y(r), t !== t + 0) throw t;\n g(1, 0);\n }\n }\n function Pi(e, r, t, n) {\n var i = m();\n try {\n return b(e)(r, t, n);\n } catch (a) {\n if (y(i), a !== a + 0) throw a;\n g(1, 0);\n }\n }\n function ki(e) {\n var r = m();\n try {\n return b(e)();\n } catch (t) {\n if (y(r), t !== t + 0) throw t;\n return g(1, 0), 0n;\n }\n }\n function Si(e, r, t, n, i) {\n var a = m();\n try {\n b(e)(r, t, n, i);\n } catch (s) {\n if (y(a), s !== s + 0) throw s;\n g(1, 0);\n }\n }\n function Ai(e, r, t, n, i, a) {\n var s = m();\n try {\n return b(e)(r, t, n, i, a);\n } catch (o) {\n if (y(s), o !== o + 0) throw o;\n g(1, 0);\n }\n }\n function Ei(e, r, t, n, i, a, s, o) {\n var u = m();\n try {\n return b(e)(r, t, n, i, a, s, o);\n } catch (c) {\n if (y(u), c !== c + 0) throw c;\n g(1, 0);\n }\n }\n function Ri(e, r, t, n, i) {\n var a = m();\n try {\n return b(e)(r, t, n, i);\n } catch (s) {\n if (y(a), s !== s + 0) throw s;\n return g(1, 0), 0n;\n }\n }\n function Di(e, r, t, n) {\n var i = m();\n try {\n return b(e)(r, t, n);\n } catch (a) {\n if (y(i), a !== a + 0) throw a;\n g(1, 0);\n }\n }\n function Wi(e, r, t, n) {\n var i = m();\n try {\n return b(e)(r, t, n);\n } catch (a) {\n if (y(i), a !== a + 0) throw a;\n g(1, 0);\n }\n }\n function xi(e, r, t, n, i, a, s, o) {\n var u = m();\n try {\n b(e)(r, t, n, i, a, s, o);\n } catch (c) {\n if (y(u), c !== c + 0) throw c;\n g(1, 0);\n }\n }\n function Oi(e, r, t, n, i) {\n var a = m();\n try {\n return b(e)(r, t, n, i);\n } catch (s) {\n if (y(a), s !== s + 0) throw s;\n g(1, 0);\n }\n }\n function Ui(e, r, t, n, i, a, s) {\n var o = m();\n try {\n return b(e)(r, t, n, i, a, s);\n } catch (u) {\n if (y(o), u !== u + 0) throw u;\n g(1, 0);\n }\n }\n function Vi(e, r, t, n, i, a, s) {\n var o = m();\n try {\n return b(e)(r, t, n, i, a, s);\n } catch (u) {\n if (y(o), u !== u + 0) throw u;\n g(1, 0);\n }\n }\n function ji(e, r, t, n, i, a) {\n var s = m();\n try {\n return b(e)(r, t, n, i, a);\n } catch (o) {\n if (y(s), o !== o + 0) throw o;\n g(1, 0);\n }\n }\n function Ii(e, r, t, n, i, a, s, o, u, c, f) {\n var _ = m();\n try {\n b(e)(r, t, n, i, a, s, o, u, c, f);\n } catch (d) {\n if (y(_), d !== d + 0) throw d;\n g(1, 0);\n }\n }\n function Mi(e, r, t, n, i, a, s, o, u, c, f, _, d, p, v, $) {\n var P = m();\n try {\n b(e)(r, t, n, i, a, s, o, u, c, f, _, d, p, v, $);\n } catch (F) {\n if (y(P), F !== F + 0) throw F;\n g(1, 0);\n }\n }\n function Hi() {\n qe();\n function e() {\n l.calledRun = true, !Q && (Xe(), Gr?.(l), l.onRuntimeInitialized?.(), Je());\n }\n l.setStatus ? (l.setStatus("Running..."), setTimeout(() => {\n setTimeout(() => l.setStatus(""), 1), e();\n }, 1)) : e();\n }\n var H;\n return H = await nt(), Hi(), Jr ? $r = l : $r = new Promise((e, r) => {\n Gr = e, qr = r;\n }), $r;\n}\nconst { wasmBinary } = await new Promise(\n (resolve) => {\n self.addEventListener("message", function onInit(e) {\n if (e.data?.type === "wasm-init") {\n self.removeEventListener("message", onInit);\n resolve(e.data);\n }\n });\n }\n);\nif (!wasmBinary) {\n throw new Error(\n "Decoder worker did not receive WASM binary. The main thread failed to fetch aqua-parser.wasm."\n );\n}\nconst module$1 = await Li({ wasmBinary });\nconst controllers = /* @__PURE__ */ new Map();\nconst decoder = {\n get AttributeInfo() {\n return module$1.AttributeInfo;\n },\n get AquaStatus() {\n return module$1.AquaStatus;\n },\n get heapU8() {\n return module$1.HEAPU8;\n },\n get heapU32() {\n return module$1.HEAPU32;\n },\n get SceneRequestDescriptor() {\n return module$1.SceneRequestDescriptor;\n },\n get WorkerDataType() {\n return module$1.WorkerDataType;\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n dataPtrView: (attributeInfo) => {\n return module$1.dataPtrView(attributeInfo);\n },\n free: (...args) => {\n return module$1.ccall("free", "number", ["number"], args);\n },\n malloc: (...args) => {\n return module$1.ccall("malloc", "number", ["number"], args);\n },\n parseDropFile: (bufferPtr, bufferSize) => {\n return module$1.parseDropFile(bufferPtr, bufferSize);\n },\n getAttributeFromDropFile: (handle, attributeName, attributeInfo) => {\n return module$1.getAttributeFromDropFile(\n handle,\n attributeName,\n attributeInfo\n );\n },\n takeAttributeFromDropFile: (handle, attributeName, clientSideId) => {\n return module$1.takeAttributeFromDropFile(\n handle,\n attributeName,\n clientSideId\n );\n },\n flattenDropFile: (handle, outPtr, outSize) => {\n return module$1.flattenDropFile(handle, outPtr, outSize);\n },\n destroyDropFileHandle: (handle) => {\n return module$1.destroyDropFileHandle(handle);\n }\n};\ndefineActions({\n // eslint-disable-line @typescript-eslint/no-unused-vars\n async cancel(requestIdLow, requestIdHigh) {\n const key = `${requestIdHigh}-${requestIdLow}`;\n const controller = controllers.get(key);\n if (controller) {\n controller.abort();\n controllers.delete(key);\n }\n return [{ cancelled: !!controller }];\n },\n async heapSnapshot(topN) {\n if (typeof module$1.TakeHeapSnapshot !== "function") {\n return [{ snapshotJson: null }];\n }\n const snapshotJson = module$1.TakeHeapSnapshot(topN);\n return [{ snapshotJson }];\n },\n async heapTrackingControl(enabled) {\n if (typeof module$1.SetHeapTrackingEnabled !== "function") {\n return [{ success: false }];\n }\n module$1.SetHeapTrackingEnabled(enabled);\n return [{ success: true }];\n },\n async heapTrackingReset() {\n if (typeof module$1.ResetHeapTracking !== "function") {\n return [{ success: false }];\n }\n module$1.ResetHeapTracking();\n return [{ success: true }];\n },\n async decode(requestIdLow, requestIdHigh, descriptorBuffer, contextPtr, consecutiveIdsStart) {\n const key = `${requestIdHigh}-${requestIdLow}`;\n const controller = new AbortController();\n controllers.set(key, controller);\n try {\n const {\n free,\n malloc,\n parseDropFile,\n getAttributeFromDropFile,\n takeAttributeFromDropFile,\n flattenDropFile,\n destroyDropFileHandle\n } = decoder;\n const descriptorSize = descriptorBuffer.byteLength;\n const descriptorPointer = malloc(descriptorSize);\n decoder.heapU8.set(new Uint8Array(descriptorBuffer), descriptorPointer);\n const descriptor = module$1.SceneRequestDescriptor.deserializeFromBinary(\n descriptorPointer,\n descriptorSize\n );\n free(descriptorPointer);\n const url = descriptor.getUrl();\n const body = descriptor.getBody() || null;\n const method = body ? "POST" : "GET";\n const headers = descriptor.getHeaders();\n descriptor.delete();\n const startTime = performance.now();\n const response = await fetch(url, {\n method,\n headers,\n body,\n signal: controller.signal\n });\n const responseHeadersJson = JSON.stringify({\n "x-cache": response.headers.get("x-cache") ?? ""\n });\n if (!response.ok) {\n const duration2 = performance.now() - startTime;\n return [\n {\n requestIdLow,\n requestIdHigh,\n resultBuffer: new ArrayBuffer(0),\n success: false,\n parsed: false,\n error: `HTTP error! status: ${response.status}`,\n dataType: module$1.WorkerDataType.Raw.value,\n contextPtr,\n attributes: [],\n duration: duration2,\n ttfb: duration2,\n httpStatus: response.status,\n responseHeadersJson\n },\n { transfer: [] }\n ];\n }\n const rtt = performance.now() - startTime;\n const responseBuffer = await response.arrayBuffer();\n const endTime = performance.now();\n const duration = endTime - startTime;\n const attributes = [];\n const path = url.split(/[?#]/, 1)[0];\n if (!path.endsWith(".drop")) {\n return [\n {\n requestIdLow,\n requestIdHigh,\n resultBuffer: responseBuffer,\n success: true,\n parsed: false,\n error: void 0,\n dataType: module$1.WorkerDataType.Raw.value,\n contextPtr,\n attributes,\n duration,\n ttfb: rtt,\n httpStatus: response.status,\n responseHeadersJson\n },\n { transfer: [responseBuffer] }\n ];\n }\n const responseSize = responseBuffer.byteLength;\n const responsePointer = malloc(responseSize);\n decoder.heapU8.set(new Uint8Array(responseBuffer), responsePointer);\n const outputPointerPointer = malloc(4);\n const outputSizePointer = malloc(4);\n decoder.heapU32[outputPointerPointer / 4] = 0;\n decoder.heapU32[outputSizePointer / 4] = 0;\n let handle = 0;\n let outputPointer = 0;\n const attributeInfo = new decoder.AttributeInfo();\n try {\n handle = parseDropFile(responsePointer, responseSize);\n if (handle === 0) {\n throw new Error("parseDropFile failed");\n }\n let index = consecutiveIdsStart;\n for (const [name, info] of Object.entries(sparkAttributeList)) {\n if (info.discard) {\n takeAttributeFromDropFile(handle, name, index);\n } else {\n const status2 = getAttributeFromDropFile(\n handle,\n name,\n attributeInfo\n );\n if (status2 === decoder.AquaStatus.Success) {\n const wasmView = decoder.dataPtrView(attributeInfo);\n const splatData = sparkAttributeFromRaw(name, index, wasmView);\n const takeStatus = takeAttributeFromDropFile(handle, name, index);\n if (takeStatus === decoder.AquaStatus.Success) {\n attributes.push(splatData);\n }\n }\n }\n index++;\n }\n const status = flattenDropFile(\n handle,\n outputPointerPointer,\n outputSizePointer\n );\n if (status !== decoder.AquaStatus.Success) {\n throw new Error("flattenDropFile failed");\n }\n outputPointer = decoder.heapU32[outputPointerPointer / 4];\n const outputSize = decoder.heapU32[outputSizePointer / 4];\n if (outputPointer === 0) {\n throw new Error("flattenDropFile gave nullptr");\n }\n const resultBuffer = decoder.heapU8.buffer.slice(\n outputPointer,\n outputPointer + outputSize\n );\n const transferList = attributes.map((attr) => attr.paddedData.buffer);\n return [\n {\n requestIdLow,\n requestIdHigh,\n resultBuffer,\n success: true,\n parsed: true,\n error: void 0,\n dataType: module$1.WorkerDataType.Drop.value,\n contextPtr,\n attributes,\n duration,\n ttfb: rtt,\n httpStatus: response.status,\n responseHeadersJson\n },\n { transfer: [resultBuffer, ...transferList] }\n ];\n } catch (error) {\n console.error("Exception when parsing dropfile", error);\n const errorMessage = error instanceof Error ? error.stack ?? error.message : String(error);\n const empty = new Uint8Array();\n const resultBuffer = empty.buffer;\n return [\n {\n requestIdLow,\n requestIdHigh,\n resultBuffer,\n success: false,\n parsed: false,\n error: errorMessage,\n dataType: module$1.WorkerDataType.Drop.value,\n contextPtr,\n attributes: void 0,\n // Important: the main thread must not cache attributes if there\'s a failure here\n duration,\n ttfb: rtt,\n httpStatus: response.status,\n responseHeadersJson\n },\n { transfer: [resultBuffer] }\n ];\n } finally {\n destroyDropFileHandle(handle);\n free(responsePointer);\n free(outputPointerPointer);\n free(outputSizePointer);\n if (outputPointer !== 0) {\n free(outputPointer);\n }\n attributeInfo.delete();\n }\n } catch (error) {\n const errorMsg = error instanceof Error ? error.message : String(error);\n const isCancelled = error instanceof Error && error.name === "AbortError";\n return [\n {\n requestIdLow,\n requestIdHigh,\n resultBuffer: new ArrayBuffer(0),\n success: false,\n parsed: false,\n error: isCancelled ? "Cancelled" : errorMsg,\n dataType: module$1.WorkerDataType.Raw.value,\n contextPtr,\n attributes: [],\n duration: 0,\n ttfb: 0,\n httpStatus: 0,\n responseHeadersJson: "{}"\n },\n { transfer: [] }\n ];\n } finally {\n controllers.delete(key);\n }\n }\n});\n';
608
+ const blob = typeof self !== "undefined" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", jsContent], { type: "text/javascript;charset=utf-8" });
609
+ function WorkerWrapper(options) {
610
+ let objURL;
611
+ try {
612
+ objURL = blob && (self.URL || self.webkitURL).createObjectURL(blob);
613
+ if (!objURL) throw "";
614
+ const worker = new Worker(objURL, {
615
+ type: "module",
616
+ name: options?.name
617
+ });
618
+ worker.addEventListener("error", () => {
619
+ (self.URL || self.webkitURL).revokeObjectURL(objURL);
620
+ });
621
+ return worker;
622
+ } catch (e) {
623
+ return new Worker(
624
+ "data:text/javascript;charset=utf-8," + encodeURIComponent(jsContent),
625
+ {
626
+ type: "module",
627
+ name: options?.name
628
+ }
629
+ );
630
+ }
631
+ }
632
+ const parserWasmUrl = ((u) => u.includes("/.vite/") ? u.replace(/\.vite\/[^?#]*/, () => "@miris-inc/core/dist/aqua-parser.wasm") : u)(new URL("aqua-parser.wasm", import.meta.url).href);
633
+ class Decoder extends Thread {
634
+ static name = "decoder";
635
+ static Worker = WorkerWrapper;
636
+ constructor(init) {
637
+ super(init);
638
+ this.#sendParserWasm();
639
+ }
640
+ async #sendParserWasm() {
641
+ try {
642
+ const response = await fetch(parserWasmUrl);
643
+ if (!response.ok) {
644
+ throw new Error(`HTTP ${response.status} fetching aqua-parser.wasm`);
645
+ }
646
+ const wasmBinary = await response.arrayBuffer();
647
+ this._postToWorker({ type: "wasm-init", wasmBinary }, [wasmBinary]);
648
+ } catch (e) {
649
+ console.error("Failed to load aqua-parser.wasm for decoder worker", e);
650
+ this._postToWorker({ type: "wasm-init" });
651
+ }
652
+ }
653
+ get AttributeInfo() {
654
+ return this.module.AttributeInfo;
655
+ }
656
+ async heapSnapshot(topN) {
657
+ return this._execute("heapSnapshot", topN);
658
+ }
659
+ async heapTrackingControl(enabled) {
660
+ return this._execute("heapTrackingControl", enabled);
661
+ }
662
+ async heapTrackingReset() {
663
+ return this._execute("heapTrackingReset");
664
+ }
665
+ async cancel(requestIdLow, requestIdHigh) {
666
+ await this.ready;
667
+ this._execute("cancel", requestIdLow, requestIdHigh).catch(() => {
668
+ });
669
+ }
670
+ async decode(...args) {
671
+ const {
672
+ requestIdLow,
673
+ requestIdHigh,
674
+ resultBuffer,
675
+ success,
676
+ dataType,
677
+ contextPtr,
678
+ attributes,
679
+ duration,
680
+ ttfb,
681
+ httpStatus,
682
+ responseHeadersJson
683
+ } = await this._execute("decode", ...args);
684
+ if (attributes !== void 0) {
685
+ for (const { paddedData, originalSize, id } of attributes) {
686
+ AttributeCache.addWithId({ paddedData, originalSize }, id);
687
+ }
688
+ }
689
+ const { engine } = this;
690
+ const bufferSize = resultBuffer.byteLength;
691
+ const bufferPointer = engine.malloc(bufferSize);
692
+ engine.heapU8.set(new Uint8Array(resultBuffer), bufferPointer);
693
+ engine.onWorkerResult(
694
+ requestIdLow,
695
+ requestIdHigh,
696
+ bufferPointer,
697
+ bufferSize,
698
+ httpStatus,
699
+ duration,
700
+ ttfb,
701
+ success,
702
+ dataType,
703
+ "",
704
+ responseHeadersJson,
705
+ contextPtr
706
+ );
707
+ }
708
+ }
709
+ const sparkMinSplats = 2048;
710
+ const sparkAttributeList = {
711
+ sparkPackedSplat: { elementsPerSplat: 4, discard: false },
712
+ extendedPackedSplatLow: { elementsPerSplat: 4, discard: false },
713
+ extendedPackedSplatHigh: { elementsPerSplat: 4, discard: false },
714
+ packedSh1: { elementsPerSplat: 2, discard: false },
715
+ packedSh2: { elementsPerSplat: 4, discard: false },
716
+ packedSh3: { elementsPerSplat: 4, discard: false },
717
+ sh1Extended: { elementsPerSplat: 4, discard: false },
718
+ sh2Extended: { elementsPerSplat: 4, discard: false },
719
+ sh3Extended_0: { elementsPerSplat: 4, discard: false },
720
+ sh3Extended_1: { elementsPerSplat: 4, discard: false }
721
+ };
722
+ function roundUpToMultipleOf(a, multiple) {
723
+ return Math.ceil(a / multiple) * multiple;
724
+ }
725
+ function sparkAttributeFromRaw(name, id, wasmView) {
726
+ const attrib = sparkAttributeList[name];
727
+ if (attrib === void 0)
728
+ throw new Error("attribute name" + name + " is unknown");
729
+ const originalSize = wasmView.length;
730
+ const paddedSize = roundUpToMultipleOf(
731
+ originalSize,
732
+ attrib.elementsPerSplat * sparkMinSplats
733
+ );
734
+ const paddedData = new Uint32Array(paddedSize);
735
+ paddedData.set(wasmView);
736
+ return { paddedData, originalSize, id };
737
+ }
738
+ class AttributeNames {
739
+ static SPARK_PACKED_SPLAT = "sparkPackedSplat";
740
+ static SPARK_EXTENDED_SPLAT_LOW = "extendedPackedSplatLow";
741
+ static SPARK_EXTENDED_SPLAT_HIGH = "extendedPackedSplatHigh";
742
+ static SPARK_PACKED_SH1 = "packedSh1";
743
+ static SPARK_PACKED_SH2 = "packedSh2";
744
+ static SPARK_PACKED_SH3 = "packedSh3";
745
+ static SPARK_EXTENDED_SH1 = "sh1Extended";
746
+ static SPARK_EXTENDED_SH2 = "sh2Extended";
747
+ static SPARK_EXTENDED_SH3_A = "sh3Extended_0";
748
+ static SPARK_EXTENDED_SH3_B = "sh3Extended_1";
749
+ static UNUSED = "unused";
750
+ }
751
+ class Engine {
752
+ static AquaStatus = {
753
+ Success: 0,
754
+ Failure: 1
755
+ };
756
+ static SceneObjectType = {
757
+ ModelRoot: 0,
758
+ SceneObject: 1,
759
+ StreamObject: 2,
760
+ GaussianSplats: 3,
761
+ PointsObject: 4,
762
+ Camera: 5,
763
+ LodOctree: 6,
764
+ VariantSetCollection: 7,
765
+ VariantSet: 8,
766
+ VariantSetOption: 9
767
+ };
768
+ static Feature = {
769
+ DrMap: 0
770
+ };
771
+ static FeatureState = {
772
+ NotLoaded: 0,
773
+ Pending: 1,
774
+ Loaded: 2,
775
+ Failed: 3
776
+ };
777
+ #module;
778
+ get module() {
779
+ if (!this.#module) {
780
+ throw new Error(
781
+ "Engine has not yet been initialized. Did you forget to `await engine.ready()?`"
782
+ );
783
+ }
784
+ return this.#module;
785
+ }
786
+ #decoders = /* @__PURE__ */ new Set();
787
+ #requestMap = /* @__PURE__ */ new Map();
788
+ constructor(moduleOptions = {}) {
789
+ Object.defineProperty(this, "pending", {
790
+ value: true,
791
+ configurable: true,
792
+ enumerable: true
793
+ });
794
+ Object.defineProperty(this, "ready", {
795
+ enumerable: true,
796
+ value: this.#initialize(moduleOptions)
797
+ });
798
+ }
799
+ async #initialize(moduleOptions) {
800
+ this.#module = await _factory({
801
+ createDeserializeWorker: this.createDeserializeWorker.bind(this),
802
+ submitToWorker: this.submitToWorker.bind(this),
803
+ cancelRequest: this.cancelRequest.bind(this),
804
+ terminateWorker: this.terminateWorker.bind(this),
805
+ // TODO: remove this possibly
806
+ workerUrl: "aqua-parser",
807
+ ...moduleOptions,
808
+ // preRun fires after Emscripten replaces Module.ENV with its internal
809
+ // ENV object, but before initRuntime() caches getEnvStrings(). This is
810
+ // the only window where mutations to Module.ENV reach C getenv().
811
+ preRun: [(mod) => Object.assign(mod.ENV, Engine.#env())]
812
+ });
813
+ Object.defineProperty(this, "pending", {
814
+ value: false,
815
+ configurable: false
816
+ });
817
+ return this;
818
+ }
819
+ /*
820
+ |----------------------------------------------------------------------------
821
+ | Wasm Exports
822
+ |----------------------------------------------------------------------------
823
+ |
824
+ | All exported Wasm functions should be wrapped here. A wrapper is just a
825
+ | getter property for classes, or a wrapper method for functions. Some
826
+ | methods call module exports directly and others exports use cwap.
827
+ |
828
+ */
829
+ get AttributeInfo() {
830
+ return this.module.AttributeInfo;
831
+ }
832
+ get Handedness() {
833
+ return this.module.Handedness;
834
+ }
835
+ get heapF32() {
836
+ return this.module.HEAPF32;
837
+ }
838
+ get heapU8() {
839
+ return this.module.HEAPU8;
840
+ }
841
+ get MatrixOrder() {
842
+ return this.module.MatrixOrder;
843
+ }
844
+ get SceneChangeIds() {
845
+ return this.module.SceneChangeIds;
846
+ }
847
+ get SceneMetadata() {
848
+ return this.module.SceneMetadata;
849
+ }
850
+ get RuntimeSettings() {
851
+ return this.module.RuntimeSettings;
852
+ }
853
+ get SpatialFormat() {
854
+ return this.module.SpatialFormat;
855
+ }
856
+ get StringVector() {
857
+ return this.module.StringVector;
858
+ }
859
+ get UpAxis() {
860
+ return this.module.UpAxis;
861
+ }
862
+ activatedObjectIdsView(...args) {
863
+ return this.module.activatedObjectIdsView(...args);
864
+ }
865
+ addStreamById(...args) {
866
+ return this.module.ccall(
867
+ "AddStreamById",
868
+ "number",
869
+ ["number", "string", "string", "number"],
870
+ args
871
+ );
872
+ }
873
+ allocateSceneChangesArrays(...args) {
874
+ return this.module.AllocateSceneChangesArrays(...args);
875
+ }
876
+ createContext(...args) {
877
+ return this.module.ccall("CreateAquaContext", "number", [], args);
878
+ }
879
+ destroyContext(...args) {
880
+ return this.module.ccall("DestroyAquaContext", "number", ["number"], args);
881
+ }
882
+ createClient(context, ...args) {
883
+ if (context) {
884
+ return this.module.ccall("CreateClientForContext", "number", ["number"], [context, ...args]);
885
+ }
886
+ return this.module.ccall("CreateClient", "number", [], args);
887
+ }
888
+ createdObjectIdsView(...args) {
889
+ return this.module.createdObjectIdsView(...args);
890
+ }
891
+ deletedObjectIdsView(...args) {
892
+ return this.module.deletedObjectIdsView(...args);
893
+ }
894
+ dataPtrView(...args) {
895
+ return this.module.dataPtrView(...args);
896
+ }
897
+ deactivatedObjectIdsView(...args) {
898
+ return this.module.deactivatedObjectIdsView(...args);
899
+ }
900
+ destroyClient(...args) {
901
+ return this.module.ccall("DestroyClient", "number", ["number"], args);
902
+ }
903
+ free(...args) {
904
+ return this.module.ccall("free", "number", ["number"], args);
905
+ }
906
+ getAssetsAsync(...args) {
907
+ return this.module.GetAssetsAsync(...args);
908
+ }
909
+ getAttribute(...args) {
910
+ return this.module.ccall(
911
+ "GetAttribute",
912
+ "number",
913
+ ["number", "number", "string", "number"],
914
+ args
915
+ );
916
+ }
917
+ getDefaultCameraId(...args) {
918
+ return this.module.ccall("GetDefaultCameraId", "number", ["number"], args);
919
+ }
920
+ getLocalBoundingBox(...args) {
921
+ return this.module.ccall(
922
+ "GetLocalBoundingBox",
923
+ "number",
924
+ ["number", "number", "number"],
925
+ args
926
+ );
927
+ }
928
+ getWorldBoundingBox(...args) {
929
+ return this.module.ccall(
930
+ "GetWorldBoundingBox",
931
+ "number",
932
+ ["number", "number", "number"],
933
+ args
934
+ );
935
+ }
936
+ getLodIndex(...args) {
937
+ return this.module.ccall(
938
+ "GetLodIndex",
939
+ "number",
940
+ ["number", "number"],
941
+ args
942
+ );
943
+ }
944
+ getSceneChanges(...args) {
945
+ return this.module.GetSceneChanges(...args);
946
+ }
947
+ getSceneChangesCounts(...args) {
948
+ return this.module.GetSceneChangesCounts(...args);
949
+ }
950
+ getSceneMetadata(...args) {
951
+ return this.module.GetSceneMetadata(...args).value;
952
+ }
953
+ getSceneObjectParent(...args) {
954
+ return this.module.ccall(
955
+ "GetSceneObjectParent",
956
+ "number",
957
+ ["number", "number"],
958
+ args
959
+ );
960
+ }
961
+ getSceneObjectType(...args) {
962
+ return this.module.ccall(
963
+ "GetSceneObjectType",
964
+ "number",
965
+ ["number", "number"],
966
+ args
967
+ );
968
+ }
969
+ getLocalTransform(...args) {
970
+ return this.module.ccall(
971
+ "MirisGetLocalTransform",
972
+ "number",
973
+ ["number", "number", "number"],
974
+ args
975
+ );
976
+ }
977
+ getWorldTransform(...args) {
978
+ return this.module.ccall(
979
+ "MirisGetWorldTransform",
980
+ "number",
981
+ ["number", "number", "number"],
982
+ args
983
+ );
984
+ }
985
+ hasAttribute(...args) {
986
+ return this.module.ccall(
987
+ "HasAttribute",
988
+ "boolean",
989
+ ["number", "number", "string"],
990
+ args
991
+ );
992
+ }
993
+ isSceneObjectAncestorOf(...args) {
994
+ return this.module.ccall(
995
+ "IsSceneObjectAncestorOf",
996
+ "boolean",
997
+ ["number", "number", "number"],
998
+ args
999
+ );
1000
+ }
1001
+ lockScene(...args) {
1002
+ return this.module.ccall("LockScene", "number", ["number"], args);
1003
+ }
1004
+ malloc(...args) {
1005
+ return this.module.ccall("malloc", "number", ["number"], args);
1006
+ }
1007
+ modifiedObjectIdsView(...args) {
1008
+ return this.module.modifiedObjectIdsView(...args);
1009
+ }
1010
+ onWorkerResult(...args) {
1011
+ const requestKey = `${args[1]}-${args[0]}`;
1012
+ this.#requestMap.delete(requestKey);
1013
+ return this.module.ccall(
1014
+ "onWorkerResult",
1015
+ null,
1016
+ [
1017
+ "number",
1018
+ // requestIdLow
1019
+ "number",
1020
+ // requestIdHigh
1021
+ "number",
1022
+ // bufferPtr
1023
+ "number",
1024
+ // bufferSize
1025
+ "number",
1026
+ // httpStatus
1027
+ "number",
1028
+ // durationMs (C++ arg 6)
1029
+ "number",
1030
+ // ttfbMs (C++ arg 7)
1031
+ "number",
1032
+ // success (C++ arg 8)
1033
+ "number",
1034
+ // dataType (C++ arg 9)
1035
+ "string",
1036
+ // errorPtr (C++ arg 10)
1037
+ "string",
1038
+ // responseHeadersJson (C++ arg 11)
1039
+ "number"
1040
+ // contextPtr (C++ arg 12)
1041
+ ],
1042
+ args
1043
+ );
1044
+ }
1045
+ removeStream(...args) {
1046
+ return this.module.ccall(
1047
+ "RemoveStream",
1048
+ "boolean",
1049
+ ["pointer", "number"],
1050
+ args
1051
+ );
1052
+ }
1053
+ setAssetViewerKey(...args) {
1054
+ return this.module.ccall(
1055
+ "SetAssetViewerKey",
1056
+ "number",
1057
+ ["number", "string"],
1058
+ args
1059
+ );
1060
+ }
1061
+ setClientSpatialFormat(...args) {
1062
+ return this.module.SetClientSpatialFormat(...args).value;
1063
+ }
1064
+ setRuntimeSettings(...args) {
1065
+ return this.module.SetRuntimeSettings(...args).value;
1066
+ }
1067
+ setMainCameraTransform(...args) {
1068
+ return this.module.ccall(
1069
+ "SetMainCameraTransform",
1070
+ "number",
1071
+ ["number", "number"],
1072
+ args
1073
+ );
1074
+ }
1075
+ setMainCameraViewFrustum(...args) {
1076
+ return this.module.ccall(
1077
+ "SetMainCameraViewFrustum",
1078
+ "number",
1079
+ ["number", "number", "number", "number", "number"],
1080
+ args
1081
+ );
1082
+ }
1083
+ setMaxCacheSize(...args) {
1084
+ return this.module.setMaxCacheSize(...args);
1085
+ }
1086
+ setSceneObjectTransform(...args) {
1087
+ return this.module.ccall(
1088
+ "SetSceneObjectTransform",
1089
+ "number",
1090
+ ["number", "number", "number"],
1091
+ args
1092
+ );
1093
+ }
1094
+ // Feature API
1095
+ hasFeature(...args) {
1096
+ return this.module.HasFeature(...args);
1097
+ }
1098
+ getFeatureVersion(...args) {
1099
+ return this.module.GetFeatureVersion(...args);
1100
+ }
1101
+ getFeatureState(...args) {
1102
+ return this.module.GetFeatureState(...args);
1103
+ }
1104
+ // Object Name API
1105
+ getName(...args) {
1106
+ return this.module.GetName(...args);
1107
+ }
1108
+ setVariantSelection(...args) {
1109
+ return this.module.ccall(
1110
+ "SetVariantSelection",
1111
+ "number",
1112
+ ["number", "number"],
1113
+ args
1114
+ );
1115
+ }
1116
+ takeAttribute(...args) {
1117
+ return this.module.ccall(
1118
+ "TakeAttribute",
1119
+ "number",
1120
+ ["number", "number", "string", "bigint"],
1121
+ args
1122
+ );
1123
+ }
1124
+ takeEvictedClientSideAttributeIds(...args) {
1125
+ return this.module.TakeEvictedClientSideAttributeIds(...args);
1126
+ }
1127
+ getActiveClientSideIdsCheckSum() {
1128
+ return this.module.GetActiveClientSideIdsCheckSum();
1129
+ }
1130
+ unlockScene(...args) {
1131
+ return this.module.ccall("UnlockScene", "number", ["number"], args);
1132
+ }
1133
+ updateSceneExecution(...args) {
1134
+ return this.module.ccall(
1135
+ "UpdateSceneExecution",
1136
+ "number",
1137
+ ["number", "boolean"],
1138
+ args
1139
+ );
1140
+ }
1141
+ takeRenderRequired(...args) {
1142
+ return this.module.TakeRenderRequired(...args);
1143
+ }
1144
+ /*
1145
+ |----------------------------------------------------------------------------
1146
+ | Decoder helpers
1147
+ |----------------------------------------------------------------------------
1148
+ */
1149
+ createDeserializeWorker(_url, _workerUrl, poolSize) {
1150
+ for (let index = 1; index < poolSize; index += 1) {
1151
+ this.#decoders.add(new Decoder({ engine: this }));
1152
+ }
1153
+ return true;
1154
+ }
1155
+ cancelRequest(requestIdLow, requestIdHigh) {
1156
+ const requestKey = `${requestIdHigh}-${requestIdLow}`;
1157
+ const decoder = this.#requestMap.get(requestKey);
1158
+ if (decoder) {
1159
+ decoder.cancel(requestIdLow, requestIdHigh);
1160
+ this.#requestMap.delete(requestKey);
1161
+ }
1162
+ return true;
1163
+ }
1164
+ submitToWorker(requestIdLow, requestIdHigh, descriptorBuffer, contextPtr) {
1165
+ const decoder = [...this.#decoders.values()].reduce((previous, current) => {
1166
+ if (!previous) return current;
1167
+ return current.pendingRequests < previous.pendingRequests ? current : previous;
1168
+ });
1169
+ const requestKey = `${requestIdHigh}-${requestIdLow}`;
1170
+ this.#requestMap.set(requestKey, decoder);
1171
+ const firstId = AttributeCache.getConsecutiveIds(
1172
+ Object.keys(sparkAttributeList).length
1173
+ );
1174
+ decoder.ready.then(
1175
+ () => decoder.decode(
1176
+ requestIdLow,
1177
+ requestIdHigh,
1178
+ descriptorBuffer,
1179
+ contextPtr,
1180
+ firstId
1181
+ )
1182
+ );
1183
+ return true;
1184
+ }
1185
+ terminateWorker() {
1186
+ for (const decoder of this.#decoders) {
1187
+ decoder.terminate();
1188
+ }
1189
+ this.#decoders.clear();
1190
+ }
1191
+ /*
1192
+ |----------------------------------------------------------------------------
1193
+ | Heap profiler helpers (fan-out to all decoder workers)
1194
+ |----------------------------------------------------------------------------
1195
+ */
1196
+ async requestWorkerHeapSnapshots(topN) {
1197
+ const decoders = [...this.#decoders];
1198
+ const results = await Promise.allSettled(
1199
+ decoders.map(
1200
+ (d) => d.ready.then(() => {
1201
+ let timer;
1202
+ const timeout = new Promise((resolve) => {
1203
+ timer = setTimeout(() => resolve(null), 5e3);
1204
+ });
1205
+ return Promise.race([
1206
+ d.heapSnapshot(topN).then((r) => r.snapshotJson),
1207
+ timeout
1208
+ ]).finally(() => clearTimeout(timer));
1209
+ })
1210
+ )
1211
+ );
1212
+ return results.map((r) => r.status === "fulfilled" ? r.value : null);
1213
+ }
1214
+ async setWorkerHeapTrackingEnabled(enabled) {
1215
+ await Promise.allSettled(
1216
+ [...this.#decoders].map(
1217
+ (d) => d.ready.then(() => d.heapTrackingControl(enabled))
1218
+ )
1219
+ );
1220
+ }
1221
+ async resetWorkerHeapTracking() {
1222
+ await Promise.allSettled(
1223
+ [...this.#decoders].map((d) => d.ready.then(() => d.heapTrackingReset()))
1224
+ );
1225
+ }
1226
+ static #env() {
1227
+ const url = "https://app.miris.com/viewer/v1";
1228
+ return {
1229
+ AQUA_USE_SINGLETON_NETWORK_TRANSPORT: "true",
1230
+ ...{ AQUA_SERVER_BASE_URL: url }
1231
+ };
1232
+ }
1233
+ }
1234
+ const RATES = [30, 60, 72, 90, 120, 144, 165, 240];
1235
+ function createRefreshRateDetector() {
1236
+ let samples = [], last = null, hz = 0;
1237
+ screen.addEventListener?.("change", () => {
1238
+ samples = [];
1239
+ hz = 0;
1240
+ last = null;
1241
+ });
1242
+ return {
1243
+ update(ts) {
1244
+ if (hz)
1245
+ return;
1246
+ if (last !== null) {
1247
+ samples.push(ts - last);
1248
+ if (samples.length > 60)
1249
+ samples.shift();
1250
+ if (!hz && samples.length === 60) {
1251
+ const avg = samples.reduce((a, b) => a + b, 0) / samples.length;
1252
+ const meanHz = 1e3 / avg;
1253
+ hz = RATES.reduce((a, b) => Math.abs(b - meanHz) < Math.abs(a - meanHz) ? b : a);
1254
+ }
1255
+ }
1256
+ last = ts;
1257
+ },
1258
+ get nativeHz() {
1259
+ return hz;
1260
+ }
1261
+ };
1262
+ }
1263
+ class Miris {
1264
+ static _instance;
1265
+ static async instance() {
1266
+ const miris = this._instance ??= new this();
1267
+ await miris.ready;
1268
+ return miris;
1269
+ }
1270
+ #sharedContext;
1271
+ get sharedContext() {
1272
+ return this.#sharedContext;
1273
+ }
1274
+ #viewerKey;
1275
+ get viewerKey() {
1276
+ return this.#viewerKey;
1277
+ }
1278
+ set viewerKey(viewerKey) {
1279
+ this.#viewerKey = viewerKey;
1280
+ }
1281
+ #scenes = /* @__PURE__ */ new Set();
1282
+ get scenes() {
1283
+ return new Set(this.#scenes);
1284
+ }
1285
+ #changes = [];
1286
+ #changeIds = null;
1287
+ #pendingActivations = /* @__PURE__ */ new Set();
1288
+ #pendingDeactivations = /* @__PURE__ */ new Map();
1289
+ constructor() {
1290
+ if (!this.constructor.prototype._instance) {
1291
+ this.constructor.prototype._instance = this;
1292
+ }
1293
+ Object.defineProperties(this, {
1294
+ pending: { value: true, configurable: true, enumerable: true },
1295
+ engine: { value: new Engine(), enumerable: true }
1296
+ });
1297
+ Object.defineProperty(this, "ready", {
1298
+ enumerable: true,
1299
+ value: this.#initializeMiris()
1300
+ });
1301
+ }
1302
+ async #initializeMiris() {
1303
+ const { engine } = this;
1304
+ await engine.ready;
1305
+ this.#sharedContext = this.engine.createContext();
1306
+ const mb = 1024 * 1024;
1307
+ const urlParams = new URLSearchParams(window.location.search);
1308
+ const maxCacheSizeParam = urlParams.get("aquaMaxCacheSize");
1309
+ let maxCacheSizeMB = 0;
1310
+ if (maxCacheSizeParam) {
1311
+ const parsedSize = parseInt(maxCacheSizeParam, 10);
1312
+ if (!isNaN(parsedSize) && parsedSize > 0) {
1313
+ maxCacheSizeMB = parsedSize;
1314
+ }
1315
+ }
1316
+ if (maxCacheSizeMB > 0) {
1317
+ this.engine.setMaxCacheSize(maxCacheSizeMB * mb);
1318
+ } else if (navigator.userAgent.includes("iPhone")) {
1319
+ this.engine.setMaxCacheSize(128 * mb);
1320
+ } else if (navigator.userAgent.includes("Android")) {
1321
+ this.engine.setMaxCacheSize(256 * mb);
1322
+ }
1323
+ this.#browserUpdate();
1324
+ Object.defineProperty(this, "pending", {
1325
+ value: false,
1326
+ configurable: false
1327
+ });
1328
+ return this;
1329
+ }
1330
+ dispose() {
1331
+ if (this.#sharedContext) {
1332
+ if (this.engine.destroyContext(this.#sharedContext) !== Engine.AquaStatus.Success) {
1333
+ console.error(
1334
+ `Failed to destroy aqua context with handle '${this.#sharedContext}'`
1335
+ );
1336
+ }
1337
+ this.#sharedContext = 0;
1338
+ }
1339
+ }
1340
+ updateParentedTransform(_modelTransform, _parentTransform) {
1341
+ return void 0;
1342
+ }
1343
+ #detector = createRefreshRateDetector();
1344
+ #boundUpdate = this.#browserUpdate.bind(this);
1345
+ #firstInSequence = false;
1346
+ #targetFramesPerSecond = 72;
1347
+ #xrModeActive = false;
1348
+ #applyDisplaySettings() {
1349
+ const settings = new this.engine.RuntimeSettings();
1350
+ settings.targetFramesPerSecond = this.#targetFramesPerSecond;
1351
+ settings.xrModeActive = this.#xrModeActive;
1352
+ for (const scene of this.#scenes) {
1353
+ scene.client.setRuntimeSettings(settings);
1354
+ }
1355
+ settings.delete();
1356
+ }
1357
+ /**
1358
+ * @internal
1359
+ */
1360
+ _setXRModeActive(active, frameRate) {
1361
+ this.#xrModeActive = active;
1362
+ if (frameRate !== void 0) {
1363
+ this.#targetFramesPerSecond = frameRate;
1364
+ }
1365
+ this.#applyDisplaySettings();
1366
+ }
1367
+ #browserUpdate() {
1368
+ this._update();
1369
+ requestAnimationFrame(this.#boundUpdate);
1370
+ }
1371
+ /**
1372
+ * @internal
1373
+ *
1374
+ * Shared update function being driven by browser's update loop or an XR session
1375
+ */
1376
+ _update() {
1377
+ if (this.#detector) {
1378
+ this.#detector.update(performance.now());
1379
+ if (this.#detector.nativeHz > 0) {
1380
+ this.#targetFramesPerSecond = this.#detector.nativeHz;
1381
+ this.#applyDisplaySettings();
1382
+ this.#detector = null;
1383
+ }
1384
+ }
1385
+ for (const scene of this.#scenes) {
1386
+ const { client } = scene;
1387
+ client.updateSceneExecution(this.#firstInSequence);
1388
+ this.#firstInSequence = false;
1389
+ const evicted = client.takeEvictedClientSideAttributeIds();
1390
+ try {
1391
+ const evictedSize = evicted.size();
1392
+ if (evictedSize > 0) {
1393
+ const evictedArray = [];
1394
+ for (let i = 0; i < evictedSize; i++) {
1395
+ evictedArray.push(Number(evicted.get(i)));
1396
+ }
1397
+ AttributeCache.remove(evictedArray);
1398
+ }
1399
+ } finally {
1400
+ evicted.delete();
1401
+ }
1402
+ const checkSumWasm = this.engine.getActiveClientSideIdsCheckSum();
1403
+ AttributeCache.validateCheckSum(checkSumWasm);
1404
+ const locked = client.lockScene();
1405
+ if (!locked) {
1406
+ return;
1407
+ }
1408
+ try {
1409
+ this.#updateScene(scene);
1410
+ } finally {
1411
+ client.unlockScene();
1412
+ }
1413
+ }
1414
+ if (this.#changes.length) {
1415
+ this.applyChanges(this.#changes);
1416
+ this.#changes.length = 0;
1417
+ }
1418
+ }
1419
+ #retrieveFloatArray(objectId, arraySize, fn) {
1420
+ const sizeOfFloat = 4;
1421
+ const arrayPtr = this.engine.malloc(arraySize * sizeOfFloat);
1422
+ fn(objectId, arrayPtr);
1423
+ const floatArray = this.engine.heapF32.subarray(arrayPtr >> 2, (arrayPtr >> 2) + arraySize).slice();
1424
+ this.engine.free(arrayPtr);
1425
+ return floatArray;
1426
+ }
1427
+ getLocalTransform(client, sceneObjectId) {
1428
+ if (Number.isInteger(sceneObjectId) && sceneObjectId >= 0) {
1429
+ return this.#retrieveFloatArray(
1430
+ sceneObjectId,
1431
+ 16,
1432
+ client.getLocalTransform.bind(client)
1433
+ );
1434
+ }
1435
+ }
1436
+ getWorldTransform(client, sceneObjectId) {
1437
+ if (Number.isInteger(sceneObjectId) && sceneObjectId >= 0) {
1438
+ return this.#retrieveFloatArray(
1439
+ sceneObjectId,
1440
+ 16,
1441
+ client.getWorldTransform.bind(client)
1442
+ );
1443
+ }
1444
+ }
1445
+ #shouldUpdateSceneChanges() {
1446
+ if (!this.#changeIds) {
1447
+ return false;
1448
+ }
1449
+ if (this.#changeIds.createdObjectsCount > 0) {
1450
+ return true;
1451
+ }
1452
+ if (this.#changeIds.activatedObjectsCount > 0) {
1453
+ return true;
1454
+ }
1455
+ if (this.#changeIds.deactivatedObjectsCount > 0) {
1456
+ return true;
1457
+ }
1458
+ if (this.#changeIds.modifiedObjectsCount > 0) {
1459
+ return true;
1460
+ }
1461
+ if (this.#changeIds.deletedObjectsCount > 0) {
1462
+ return true;
1463
+ }
1464
+ return false;
1465
+ }
1466
+ #getDataFromAttribute(client, sceneObjectId, attributeName, outAttributeInfo) {
1467
+ const { engine } = this;
1468
+ if (!client.hasAttribute(sceneObjectId, attributeName)) {
1469
+ return null;
1470
+ }
1471
+ const { ptr } = outAttributeInfo.$$;
1472
+ const status = client.getAttribute(sceneObjectId, attributeName, ptr);
1473
+ if (status !== Engine.AquaStatus.Success) {
1474
+ console.warn(
1475
+ `GetAttribute failed for object id ${sceneObjectId} and attribute name ${attributeName}: status ${status}`
1476
+ );
1477
+ return null;
1478
+ }
1479
+ let paddedData;
1480
+ let originalSize;
1481
+ if (outAttributeInfo.clientSideId != 0n) {
1482
+ ({ paddedData, originalSize } = AttributeCache.get(
1483
+ Number(outAttributeInfo.clientSideId)
1484
+ ));
1485
+ } else {
1486
+ const wasmView = engine.dataPtrView(outAttributeInfo);
1487
+ const result = sparkAttributeFromRaw(attributeName, 0, wasmView);
1488
+ paddedData = result.paddedData;
1489
+ originalSize = result.originalSize;
1490
+ const myCacheEntry = AttributeCache.add({
1491
+ paddedData: result.paddedData,
1492
+ originalSize: result.originalSize
1493
+ });
1494
+ const takeStatus = client.takeAttribute(
1495
+ sceneObjectId,
1496
+ attributeName,
1497
+ BigInt(myCacheEntry)
1498
+ );
1499
+ if (takeStatus !== Engine.AquaStatus.Success) {
1500
+ AttributeCache.remove(myCacheEntry);
1501
+ console.warn(
1502
+ `Failed to take attribute ${attributeName} for scene object ${sceneObjectId}: status ${takeStatus}`
1503
+ );
1504
+ return null;
1505
+ }
1506
+ }
1507
+ return { paddedData, originalSize };
1508
+ }
1509
+ #updateScene(scene) {
1510
+ const { engine } = this;
1511
+ const { client, camera, lods } = scene;
1512
+ if (camera) {
1513
+ camera.update();
1514
+ }
1515
+ if (this.#changeIds === null) {
1516
+ this.#changeIds = new engine.SceneChangeIds();
1517
+ }
1518
+ client.getSceneChangesCounts(this.#changeIds);
1519
+ if (!this.#shouldUpdateSceneChanges()) {
1520
+ return;
1521
+ }
1522
+ engine.allocateSceneChangesArrays(this.#changeIds);
1523
+ client.getSceneChanges(this.#changeIds);
1524
+ const createdLodIds = /* @__PURE__ */ new Set();
1525
+ for (const sceneObjectId of engine.createdObjectIdsView(this.#changeIds)) {
1526
+ const sceneObjectType = client.getSceneObjectType(sceneObjectId);
1527
+ if (sceneObjectType === Engine.SceneObjectType.StreamObject) {
1528
+ Stream.forId(sceneObjectId);
1529
+ continue;
1530
+ } else if (sceneObjectType === Engine.SceneObjectType.ModelRoot) {
1531
+ const stream = scene.getStreamForDescendentId(sceneObjectId);
1532
+ if (!stream) continue;
1533
+ const modelRoot = new ModelRoot({ id: sceneObjectId, stream });
1534
+ const modelRootTransform = this.getLocalTransform(
1535
+ client,
1536
+ sceneObjectId
1537
+ );
1538
+ if (!modelRootTransform) continue;
1539
+ const parentId = client.getSceneObjectParent(sceneObjectId);
1540
+ const parentTransform = this.getLocalTransform(client, parentId);
1541
+ if (!parentTransform) continue;
1542
+ const updatedTransform = this.updateParentedTransform(
1543
+ modelRootTransform,
1544
+ parentTransform
1545
+ );
1546
+ if (!updatedTransform) continue;
1547
+ modelRoot.transform = updatedTransform;
1548
+ } else if (sceneObjectType == Engine.SceneObjectType.GaussianSplats) {
1549
+ const modelRoot = scene.getModelRootForDescendentId(sceneObjectId);
1550
+ if (!modelRoot) continue;
1551
+ const lod = new Lod({ id: sceneObjectId, modelRoot, lodStore: lods });
1552
+ lod.transform = this.getLocalTransform(client, sceneObjectId);
1553
+ createdLodIds.add(sceneObjectId);
1554
+ const entry = new Change({ type: "created", lod });
1555
+ this.#changes.push(entry);
1556
+ } else if (sceneObjectType == Engine.SceneObjectType.VariantSetCollection) {
1557
+ const stream = scene.getStreamForDescendentId(sceneObjectId);
1558
+ stream?._addVariantCollection(sceneObjectId);
1559
+ } else if (sceneObjectType == Engine.SceneObjectType.VariantSet) {
1560
+ const stream = scene.getStreamForDescendentId(sceneObjectId);
1561
+ const name = client.getName(sceneObjectId);
1562
+ const parentId = client.getSceneObjectParent(sceneObjectId);
1563
+ stream?._addVariant(parentId, {
1564
+ id: sceneObjectId,
1565
+ name,
1566
+ options: [],
1567
+ nestedSets: []
1568
+ });
1569
+ } else if (sceneObjectType == Engine.SceneObjectType.VariantSetOption) {
1570
+ const stream = scene.getStreamForDescendentId(sceneObjectId);
1571
+ const name = client.getName(sceneObjectId);
1572
+ const parentId = client.getSceneObjectParent(sceneObjectId);
1573
+ stream?._addVariant(parentId, {
1574
+ id: sceneObjectId,
1575
+ name,
1576
+ type: "option"
1577
+ });
1578
+ }
1579
+ }
1580
+ for (const sceneObjectId of engine.deletedObjectIdsView(this.#changeIds)) {
1581
+ const lod = lods.forId(sceneObjectId);
1582
+ if (!lod) {
1583
+ continue;
1584
+ }
1585
+ const entry = new Change({ type: "deleted", lod });
1586
+ this.#changes.push(entry);
1587
+ }
1588
+ for (const sceneObjectId of engine.modifiedObjectIdsView(this.#changeIds)) {
1589
+ const sceneObjectType = client.getSceneObjectType(sceneObjectId);
1590
+ if (sceneObjectType === Engine.SceneObjectType.LodOctree) {
1591
+ scene._onFeatureData(sceneObjectId);
1592
+ } else if (sceneObjectType === Engine.SceneObjectType.GaussianSplats) {
1593
+ const bounds = this.#retrieveFloatArray(
1594
+ sceneObjectId,
1595
+ 6,
1596
+ client.getWorldBoundingBox.bind(client)
1597
+ );
1598
+ const lodIndex = client.getLodIndex(sceneObjectId);
1599
+ const attributeInfo = new engine.AttributeInfo();
1600
+ const attributeInfoHigh = new engine.AttributeInfo();
1601
+ try {
1602
+ let attribute = this.#getDataFromAttribute(
1603
+ client,
1604
+ sceneObjectId,
1605
+ AttributeNames.SPARK_EXTENDED_SPLAT_LOW,
1606
+ attributeInfo
1607
+ );
1608
+ let attributeHigh = null;
1609
+ let useExtSplats = true;
1610
+ if (attribute === null) {
1611
+ attribute = this.#getDataFromAttribute(
1612
+ client,
1613
+ sceneObjectId,
1614
+ AttributeNames.SPARK_PACKED_SPLAT,
1615
+ attributeInfo
1616
+ );
1617
+ useExtSplats = false;
1618
+ } else {
1619
+ attributeHigh = this.#getDataFromAttribute(
1620
+ client,
1621
+ sceneObjectId,
1622
+ AttributeNames.SPARK_EXTENDED_SPLAT_HIGH,
1623
+ attributeInfoHigh
1624
+ );
1625
+ }
1626
+ if (attribute === null) {
1627
+ console.error(
1628
+ `Could not retrieve primary splats attribute for scene object ${sceneObjectId}! skipping scene object`
1629
+ );
1630
+ continue;
1631
+ }
1632
+ const lod = lods.forId(sceneObjectId);
1633
+ if (!lod) {
1634
+ console.warn(
1635
+ `Received modified event for LOD ${sceneObjectId} which does not exist.`
1636
+ );
1637
+ continue;
1638
+ }
1639
+ lod.splats = attribute?.paddedData;
1640
+ lod.splatsExtendedData = attributeHigh?.paddedData ?? null;
1641
+ lod.useExtSplats = useExtSplats;
1642
+ lod.bounds = bounds;
1643
+ lod.lodIndex = lodIndex;
1644
+ lod.paddingCount = (attribute?.paddedData.length - attribute.originalSize) / 4;
1645
+ this.#addSphericalHarmonicsToLod(scene, sceneObjectId, lod);
1646
+ const entry = new Change({ type: "modified", lod });
1647
+ this.#changes.push(entry);
1648
+ if (this.#pendingActivations.delete(sceneObjectId)) {
1649
+ this.#changes.push(new Change({ type: "activated", lod }));
1650
+ for (const [, deactLod] of this.#pendingDeactivations) {
1651
+ this.#changes.push(
1652
+ new Change({ type: "deactivated", lod: deactLod })
1653
+ );
1654
+ }
1655
+ this.#pendingDeactivations.clear();
1656
+ }
1657
+ } finally {
1658
+ attributeInfo.delete();
1659
+ attributeInfoHigh.delete();
1660
+ }
1661
+ }
1662
+ }
1663
+ if (this.#changes.some((c) => c.type === "created")) {
1664
+ try {
1665
+ const metadata = new engine.SceneMetadata();
1666
+ client.getSceneMetadata(metadata);
1667
+ this.onColorSpaceDetected(metadata.inputColorSpace === "linear");
1668
+ metadata.delete();
1669
+ } catch (e) {
1670
+ console.warn("Failed to read scene metadata:", e);
1671
+ }
1672
+ }
1673
+ let deferredActivationsThisFrame = false;
1674
+ for (const sceneObjectId of engine.activatedObjectIdsView(
1675
+ this.#changeIds
1676
+ )) {
1677
+ const sceneObjectType = client.getSceneObjectType(sceneObjectId);
1678
+ if (sceneObjectType == Engine.SceneObjectType.GaussianSplats) {
1679
+ const lod = lods.forId(sceneObjectId);
1680
+ if (lod && lod.splats) {
1681
+ const entry = new Change({ type: "activated", lod });
1682
+ this.#changes.push(entry);
1683
+ } else if (lod) {
1684
+ this.#pendingActivations.add(sceneObjectId);
1685
+ deferredActivationsThisFrame = true;
1686
+ }
1687
+ }
1688
+ }
1689
+ for (const sceneObjectId of engine.deactivatedObjectIdsView(
1690
+ this.#changeIds
1691
+ )) {
1692
+ const sceneObjectType = client.getSceneObjectType(sceneObjectId);
1693
+ if (sceneObjectType == Engine.SceneObjectType.GaussianSplats) {
1694
+ this.#pendingActivations.delete(sceneObjectId);
1695
+ if (!createdLodIds.has(sceneObjectId)) {
1696
+ const lod = lods.forId(sceneObjectId);
1697
+ if (lod && lod.splats) {
1698
+ if (deferredActivationsThisFrame) {
1699
+ this.#pendingDeactivations.set(sceneObjectId, lod);
1700
+ } else {
1701
+ const entry = new Change({ type: "deactivated", lod });
1702
+ this.#changes.push(entry);
1703
+ }
1704
+ }
1705
+ }
1706
+ }
1707
+ }
1708
+ }
1709
+ #addSphericalHarmonicsToLod(scene, sceneObjectId, outLod) {
1710
+ const { engine } = this;
1711
+ const { client } = scene;
1712
+ const getAndAssignSh = (packedName, extName, setter) => {
1713
+ const attributeName = outLod.useExtSplats ? extName : packedName;
1714
+ if (client.hasAttribute(sceneObjectId, attributeName)) {
1715
+ const attributeInfo = new engine.AttributeInfo();
1716
+ try {
1717
+ const attribute = this.#getDataFromAttribute(
1718
+ client,
1719
+ sceneObjectId,
1720
+ attributeName,
1721
+ attributeInfo
1722
+ );
1723
+ if (attribute !== null) {
1724
+ setter(attribute.paddedData, attributeInfo.maxValue.x);
1725
+ }
1726
+ } finally {
1727
+ attributeInfo.delete();
1728
+ }
1729
+ }
1730
+ };
1731
+ getAndAssignSh(
1732
+ AttributeNames.SPARK_PACKED_SH1,
1733
+ AttributeNames.SPARK_EXTENDED_SH1,
1734
+ (data, max) => outLod.setSh1(data, max)
1735
+ );
1736
+ getAndAssignSh(
1737
+ AttributeNames.SPARK_PACKED_SH2,
1738
+ AttributeNames.SPARK_EXTENDED_SH2,
1739
+ (data, max) => outLod.setSh2(data, max)
1740
+ );
1741
+ getAndAssignSh(
1742
+ AttributeNames.SPARK_PACKED_SH3,
1743
+ AttributeNames.SPARK_EXTENDED_SH3_A,
1744
+ (data, max) => outLod.setSh3(data, max)
1745
+ );
1746
+ getAndAssignSh(
1747
+ AttributeNames.UNUSED,
1748
+ AttributeNames.SPARK_EXTENDED_SH3_B,
1749
+ (data, _max) => outLod.sh3ExtendedData = data
1750
+ );
1751
+ }
1752
+ update() {
1753
+ this._update();
1754
+ let needsRender = false;
1755
+ for (const scene of this.#scenes) {
1756
+ if (scene.client.takeRenderRequired()) {
1757
+ needsRender = true;
1758
+ }
1759
+ }
1760
+ return needsRender || this._computeAdditionalRenderNeeded();
1761
+ }
1762
+ applyChanges(_entries) {
1763
+ }
1764
+ _computeAdditionalRenderNeeded() {
1765
+ return false;
1766
+ }
1767
+ onColorSpaceDetected(_isLinear) {
1768
+ }
1769
+ // prettier-ignore
1770
+ add(scene) {
1771
+ this.#scenes.add(scene);
1772
+ }
1773
+ delete(scene) {
1774
+ this.#scenes.delete(scene);
1775
+ if (scene.miris) scene.close();
1776
+ if (this.#scenes.size === 0 && this.#changeIds !== null) {
1777
+ this.#changeIds.delete();
1778
+ this.#changeIds = null;
1779
+ }
1780
+ }
1781
+ }
1782
+ class Camera {
1783
+ update() {
1784
+ const { engine } = this;
1785
+ const { client } = this.scene;
1786
+ const matrixBuffer = engine.malloc(this.#matrix.length * 4);
1787
+ engine.heapF32.set(Float32Array.from(this.#matrix), matrixBuffer / 4);
1788
+ client.setMainCameraTransform(matrixBuffer);
1789
+ engine.free(matrixBuffer);
1790
+ client.setMainCameraViewFrustum(
1791
+ this.#aspect,
1792
+ this.#fov,
1793
+ this.#near,
1794
+ this.#far
1795
+ );
1796
+ }
1797
+ #aspect;
1798
+ get aspect() {
1799
+ return this.#aspect;
1800
+ }
1801
+ set aspect(aspect) {
1802
+ this.#aspect = aspect;
1803
+ }
1804
+ #fov;
1805
+ get fov() {
1806
+ return this.#fov;
1807
+ }
1808
+ set fov(fov) {
1809
+ this.#fov = fov;
1810
+ }
1811
+ #near;
1812
+ get near() {
1813
+ return this.#near;
1814
+ }
1815
+ set near(near) {
1816
+ this.#near = near;
1817
+ }
1818
+ #far;
1819
+ get far() {
1820
+ return this.#far;
1821
+ }
1822
+ set far(far) {
1823
+ this.#far = far;
1824
+ }
1825
+ #matrix;
1826
+ get matrix() {
1827
+ return this.#matrix;
1828
+ }
1829
+ set matrix(matrix) {
1830
+ this.#matrix = matrix;
1831
+ }
1832
+ constructor({ aspect, fov, near, far, matrix, scene }) {
1833
+ this.#aspect = aspect;
1834
+ this.#fov = fov;
1835
+ this.#near = near;
1836
+ this.#far = far;
1837
+ this.#matrix = matrix;
1838
+ Object.defineProperties(this, {
1839
+ scene: { value: scene },
1840
+ miris: { value: scene.miris },
1841
+ engine: { value: scene.miris.engine }
1842
+ });
1843
+ }
1844
+ }
1845
+ class Client {
1846
+ #viewerKey = null;
1847
+ get viewerKey() {
1848
+ return this.#viewerKey;
1849
+ }
1850
+ set viewerKey(key) {
1851
+ if (key) {
1852
+ this.setAssetViewerKey(key);
1853
+ }
1854
+ this.#viewerKey = key;
1855
+ }
1856
+ constructor({ engine, context }) {
1857
+ Object.defineProperties(this, {
1858
+ engine: { value: engine, enumerable: true },
1859
+ handle: { value: engine.createClient(context), enumerable: true }
1860
+ });
1861
+ }
1862
+ dispose() {
1863
+ if (this.engine.destroyClient(this.handle) !== Engine.AquaStatus.Success) {
1864
+ console.error(`Failed to destroy client with handle '${this.handle}'`);
1865
+ }
1866
+ }
1867
+ addStreamById(...args) {
1868
+ return this.engine.addStreamById(this.handle, ...args);
1869
+ }
1870
+ destroyClient(...args) {
1871
+ return this.engine.destroyClient(this.handle, ...args);
1872
+ }
1873
+ getAssetsAsync(...args) {
1874
+ return this.engine.getAssetsAsync(this.handle, ...args);
1875
+ }
1876
+ getAttribute(...args) {
1877
+ return this.engine.getAttribute(this.handle, ...args);
1878
+ }
1879
+ getDefaultCameraId(...args) {
1880
+ return this.engine.getDefaultCameraId(this.handle, ...args);
1881
+ }
1882
+ getLocalBoundingBox(...args) {
1883
+ return this.engine.getLocalBoundingBox(this.handle, ...args);
1884
+ }
1885
+ getWorldBoundingBox(...args) {
1886
+ return this.engine.getWorldBoundingBox(this.handle, ...args);
1887
+ }
1888
+ getLodIndex(...args) {
1889
+ return this.engine.getLodIndex(this.handle, ...args);
1890
+ }
1891
+ getSceneChanges(...args) {
1892
+ return this.engine.getSceneChanges(this.handle, ...args);
1893
+ }
1894
+ getSceneChangesCounts(...args) {
1895
+ return this.engine.getSceneChangesCounts(this.handle, ...args);
1896
+ }
1897
+ getSceneMetadata(...args) {
1898
+ return this.engine.getSceneMetadata(this.handle, ...args);
1899
+ }
1900
+ getSceneObjectParent(...args) {
1901
+ return this.engine.getSceneObjectParent(this.handle, ...args);
1902
+ }
1903
+ getSceneObjectType(...args) {
1904
+ return this.engine.getSceneObjectType(this.handle, ...args);
1905
+ }
1906
+ getLocalTransform(...args) {
1907
+ return this.engine.getLocalTransform(this.handle, ...args);
1908
+ }
1909
+ getWorldTransform(...args) {
1910
+ return this.engine.getWorldTransform(this.handle, ...args);
1911
+ }
1912
+ hasAttribute(...args) {
1913
+ return this.engine.hasAttribute(this.handle, ...args);
1914
+ }
1915
+ isSceneObjectAncestorOf(...args) {
1916
+ return this.engine.isSceneObjectAncestorOf(this.handle, ...args);
1917
+ }
1918
+ lockScene(...args) {
1919
+ return this.engine.lockScene(this.handle, ...args);
1920
+ }
1921
+ removeStream(...args) {
1922
+ return this.engine.removeStream(this.handle, ...args);
1923
+ }
1924
+ setAssetViewerKey(...args) {
1925
+ return this.engine.setAssetViewerKey(this.handle, ...args);
1926
+ }
1927
+ setClientSpatialFormat(...args) {
1928
+ return this.engine.setClientSpatialFormat(this.handle, ...args);
1929
+ }
1930
+ setRuntimeSettings(...args) {
1931
+ return this.engine.setRuntimeSettings(this.handle, ...args);
1932
+ }
1933
+ setMainCameraTransform(...args) {
1934
+ return this.engine.setMainCameraTransform(this.handle, ...args);
1935
+ }
1936
+ setMainCameraViewFrustum(...args) {
1937
+ return this.engine.setMainCameraViewFrustum(this.handle, ...args);
1938
+ }
1939
+ setSceneObjectTransform(...args) {
1940
+ return this.engine.setSceneObjectTransform(this.handle, ...args);
1941
+ }
1942
+ hasFeature(...args) {
1943
+ return this.engine.hasFeature(this.handle, ...args);
1944
+ }
1945
+ getFeatureVersion(...args) {
1946
+ return this.engine.getFeatureVersion(this.handle, ...args);
1947
+ }
1948
+ getFeatureState(...args) {
1949
+ return this.engine.getFeatureState(this.handle, ...args);
1950
+ }
1951
+ getName(...args) {
1952
+ return this.engine.getName(this.handle, ...args);
1953
+ }
1954
+ setVariantSelection(...args) {
1955
+ return this.engine.setVariantSelection(this.handle, ...args);
1956
+ }
1957
+ takeAttribute(...args) {
1958
+ return this.engine.takeAttribute(this.handle, ...args);
1959
+ }
1960
+ takeEvictedClientSideAttributeIds(...args) {
1961
+ return this.engine.takeEvictedClientSideAttributeIds(this.handle, ...args);
1962
+ }
1963
+ takeRenderRequired(...args) {
1964
+ return this.engine.takeRenderRequired(this.handle, ...args);
1965
+ }
1966
+ unlockScene(...args) {
1967
+ return this.engine.unlockScene(this.handle, ...args);
1968
+ }
1969
+ updateSceneExecution(...args) {
1970
+ return this.engine.updateSceneExecution(this.handle, ...args);
1971
+ }
1972
+ }
1973
+ class Scene extends EventTarget {
1974
+ static #idMap = /* @__PURE__ */ new Map();
1975
+ static #keyMap = /* @__PURE__ */ new Map();
1976
+ // Associated camera
1977
+ #camera = null;
1978
+ get camera() {
1979
+ return this.#camera;
1980
+ }
1981
+ set camera(camera) {
1982
+ this.#camera = camera;
1983
+ }
1984
+ #defaultCameraId = null;
1985
+ static forId(id) {
1986
+ return Scene.#idMap.get(id);
1987
+ }
1988
+ static forKey(key) {
1989
+ return Scene.#keyMap.get(key);
1990
+ }
1991
+ #key;
1992
+ get key() {
1993
+ return this.#key ?? null;
1994
+ }
1995
+ set key(key) {
1996
+ Scene.#keyMap.delete(this.key);
1997
+ if (key || 0 === key) Scene.#keyMap.set(key, this);
1998
+ this.#key = key;
1999
+ }
2000
+ #streams = /* @__PURE__ */ new Set();
2001
+ #streamObjectIdToStream = /* @__PURE__ */ new Map();
2002
+ get viewerKey() {
2003
+ return this.client.viewerKey;
2004
+ }
2005
+ set viewerKey(viewerKey) {
2006
+ if (viewerKey) this.client.viewerKey = viewerKey;
2007
+ }
2008
+ get streams() {
2009
+ return new Set(this.#streams);
2010
+ }
2011
+ #lods = new LodStore();
2012
+ get lods() {
2013
+ return this.#lods;
2014
+ }
2015
+ constructor({ miris, viewerKey }) {
2016
+ super();
2017
+ Object.defineProperties(this, {
2018
+ miris: { value: miris, enumerable: true },
2019
+ engine: { value: miris.engine, enumerable: true },
2020
+ client: {
2021
+ value: new Client({
2022
+ engine: miris.engine,
2023
+ context: miris.sharedContext
2024
+ })
2025
+ }
2026
+ });
2027
+ if (viewerKey) this.viewerKey = viewerKey;
2028
+ const spatialFormat = new this.engine.SpatialFormat();
2029
+ spatialFormat.metersPerUnit = 1;
2030
+ spatialFormat.upAxis = this.engine.UpAxis.Y;
2031
+ spatialFormat.matrixOrder = this.engine.MatrixOrder.ColumnMajor;
2032
+ spatialFormat.handedness = this.engine.Handedness.Right;
2033
+ this.client.setClientSpatialFormat(spatialFormat);
2034
+ spatialFormat.delete();
2035
+ Scene.#idMap.set(this.id, this);
2036
+ miris.add(this);
2037
+ }
2038
+ dispose() {
2039
+ this.close();
2040
+ this.client.dispose();
2041
+ }
2042
+ #updateSceneCameraData() {
2043
+ const defaultCameraId = this.client.getDefaultCameraId();
2044
+ this.#defaultCameraId = defaultCameraId >= 0 ? defaultCameraId : null;
2045
+ }
2046
+ async fetchAssets(tags) {
2047
+ if (!this.viewerKey) {
2048
+ throw new Error("Could not fetch assets because there is no viewer key");
2049
+ }
2050
+ const vector = new this.engine.StringVector();
2051
+ let _tags = [];
2052
+ if (typeof tags === "string") _tags = tags.split(",");
2053
+ else if (tags?.[Symbol.iterator]) _tags = [...tags];
2054
+ for (const tag of _tags) vector.push_back(tag);
2055
+ const _assets = await this.client.getAssetsAsync(vector);
2056
+ const assets = [];
2057
+ const decoder = new TextDecoder();
2058
+ for (const { name, tags: tags2, thumbnailUrl, uuid } of _assets) {
2059
+ const asset = {
2060
+ name,
2061
+ thumbnailUrl,
2062
+ uuid,
2063
+ tags: []
2064
+ };
2065
+ const size = tags2.size();
2066
+ for (let index = 0; index < size; index += 1) {
2067
+ let tag = tags2.get(index);
2068
+ if (tag) {
2069
+ if (typeof tag !== "string") tag = decoder.decode(tag);
2070
+ asset.tags.push(tag);
2071
+ }
2072
+ }
2073
+ assets.push(asset);
2074
+ }
2075
+ vector.delete();
2076
+ return assets;
2077
+ }
2078
+ getDefaultCameraTransform() {
2079
+ if (this.#defaultCameraId === null) return null;
2080
+ return this.miris.getWorldTransform(this.client, this.#defaultCameraId);
2081
+ }
2082
+ add(stream) {
2083
+ this.#streams.add(stream);
2084
+ this.#streamObjectIdToStream.set(stream.id, stream);
2085
+ }
2086
+ getStreamForId(streamObjectId) {
2087
+ return this.#streamObjectIdToStream.get(streamObjectId);
2088
+ }
2089
+ getStreamForDescendentId(descendentObjectId) {
2090
+ for (const [streamObjectId, stream] of this.#streamObjectIdToStream) {
2091
+ if (this.client.isSceneObjectAncestorOf(streamObjectId, descendentObjectId)) {
2092
+ return stream;
2093
+ }
2094
+ }
2095
+ return null;
2096
+ }
2097
+ getModelRootForDescendentId(descendentObjectId) {
2098
+ for (const [, stream] of this.#streamObjectIdToStream) {
2099
+ for (const modelRoot of stream.modelRoots) {
2100
+ if (this.client.isSceneObjectAncestorOf(modelRoot.id, descendentObjectId)) {
2101
+ return modelRoot;
2102
+ }
2103
+ }
2104
+ }
2105
+ return null;
2106
+ }
2107
+ /**
2108
+ * @internal
2109
+ */
2110
+ async _getDrMap(sceneObjectId) {
2111
+ if (!this.client.hasFeature(sceneObjectId, Engine.Feature.DrMap)) return null;
2112
+ if (this.client.getFeatureState(sceneObjectId, Engine.Feature.DrMap) !== Engine.FeatureState.Loaded)
2113
+ return null;
2114
+ const version = this.client.getFeatureVersion(
2115
+ sceneObjectId,
2116
+ Engine.Feature.DrMap
2117
+ );
2118
+ if (version === 1) {
2119
+ const attrName = `drMap_v${version}`;
2120
+ const attrInfo = new this.engine.AttributeInfo();
2121
+ try {
2122
+ const status = this.client.getAttribute(
2123
+ sceneObjectId,
2124
+ attrName,
2125
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2126
+ attrInfo.$$.ptr
2127
+ // embind $$.ptr — typed at build time by binding post-processor
2128
+ );
2129
+ if (status !== Engine.AquaStatus.Success) return null;
2130
+ const wasmView = this.engine.dataPtrView(attrInfo);
2131
+ const pngBytes = new Uint8Array(wasmView.buffer).subarray(
2132
+ wasmView.byteOffset,
2133
+ wasmView.byteOffset + wasmView.byteLength
2134
+ ).slice();
2135
+ const blob2 = new Blob([pngBytes], { type: "image/png" });
2136
+ return await createImageBitmap(blob2);
2137
+ } finally {
2138
+ attrInfo.delete();
2139
+ }
2140
+ }
2141
+ console.warn(`getDrMap: unsupported DR map version ${version}`);
2142
+ return null;
2143
+ }
2144
+ /**
2145
+ * @internal
2146
+ */
2147
+ async _onFeatureData(sceneObjectId) {
2148
+ const bitmap = await this._getDrMap(sceneObjectId);
2149
+ this.dispatchEvent(new CustomEvent("drmaploaded", { detail: { bitmap, sceneObjectId } }));
2150
+ }
2151
+ /**
2152
+ * @internal
2153
+ */
2154
+ _onSceneLoaded() {
2155
+ this.#updateSceneCameraData();
2156
+ this.dispatchEvent(new Event("sceneloaded"));
2157
+ }
2158
+ delete(stream) {
2159
+ this.#streams.delete(stream);
2160
+ this.#streamObjectIdToStream.delete(stream.id);
2161
+ if (Stream.forId(stream.id)) stream.end();
2162
+ }
2163
+ close() {
2164
+ for (const stream of this.streams) {
2165
+ stream.end();
2166
+ }
2167
+ Scene.#idMap.delete(this.id);
2168
+ Scene.#keyMap.delete(this.key);
2169
+ if (this.miris.scenes.has(this)) this.miris.delete(this);
2170
+ }
2171
+ }
2172
+ export {
2173
+ Camera,
2174
+ Lod,
2175
+ LodStore,
2176
+ Miris,
2177
+ ModelRoot,
2178
+ Scene,
2179
+ Stream
2180
+ };