@miris-inc/core 0.0.8-e06e500 → 0.0.8-e5ca02c

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 CHANGED
@@ -1,2211 +1,2304 @@
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);
1
+ //#region packages/core/attributeCache.ts
2
+ var AttributeCache = class {
3
+ static #cache = /* @__PURE__ */ new Map();
4
+ static #nextId = 1;
5
+ static #checkSum = 0;
6
+ static #checkSumModulo = 2 ** 32;
7
+ static #lastReportedCheckSumDifference = 0;
8
+ static #addCheckSum(id) {
9
+ this.#checkSum = (this.#checkSum + id) % this.#checkSumModulo;
10
+ }
11
+ static #removeCheckSum(id) {
12
+ this.#checkSum = (this.#checkSum - id) % this.#checkSumModulo;
13
+ if (this.#checkSum < 0) this.#checkSum += this.#checkSumModulo;
14
+ }
15
+ static getCheckSum() {
16
+ return this.#checkSum;
17
+ }
18
+ static getConsecutiveIds(howMany) {
19
+ const result = this.#nextId;
20
+ this.#nextId += howMany;
21
+ return result;
22
+ }
23
+ static addWithId(data, id) {
24
+ this.#addCheckSum(id);
25
+ this.#cache.set(id, data);
26
+ }
27
+ static add(data) {
28
+ const id = this.#nextId++;
29
+ this.addWithId(data, id);
30
+ return id;
31
+ }
32
+ static get(id) {
33
+ const data = this.#cache.get(id);
34
+ if (data === void 0) throw new Error(`Attribute with id ${id} not found in cache`);
35
+ return data;
36
+ }
37
+ static remove(idOrIds) {
38
+ if (Array.isArray(idOrIds)) for (const id of idOrIds) {
39
+ this.#cache.delete(id);
40
+ this.#removeCheckSum(id);
41
+ }
42
+ else {
43
+ this.#cache.delete(idOrIds);
44
+ this.#removeCheckSum(idOrIds);
45
+ }
46
+ }
47
+ static validateCheckSum(checkSumWasm) {
48
+ if (checkSumWasm != this.getCheckSum()) {
49
+ let difference = checkSumWasm - this.getCheckSum();
50
+ if (difference < 0) difference += this.#checkSumModulo;
51
+ if (difference != this.#lastReportedCheckSumDifference) {
52
+ console.error(`ID checksum mismatch between WASM and TypeScript sides! ${checkSumWasm} ${this.getCheckSum()}`);
53
+ this.#lastReportedCheckSumDifference = difference;
54
+ }
55
+ }
56
+ }
57
+ };
58
+ //#endregion
59
+ //#region \0emscripten-lazy:AquaApi
60
+ var _factoryPromise;
61
+ var _wasmPromise;
62
+ var _wasmUrl = ((u) => u.includes("/.vite/") ? u.replace(/\.vite\/[^?#]*/, () => "@miris-inc/core/dist/AquaApi.wasm") : u)(new URL("AquaApi.wasm", import.meta.url).href);
63
+ var _glueSource = "async function cc($t={}){var Ye,l=$t,Sr=typeof window==\"object\",ge=typeof WorkerGlobalScope<\"u\",Dt=typeof process==\"object\"&&process.versions?.node&&process.type!=\"renderer\",uc=!Sr&&!Dt&&!ge,Rt=[],kr=\"./this.program\",Er=(e,r)=>{throw r},It=import.meta.url,Je=\"\";function Mt(e){return l.locateFile?l.locateFile(e,Je):Je+e}var Qe,Fe;if(Sr||ge){try{Je=new URL(\".\",It).href}catch{}ge&&(Fe=e=>{var r=new XMLHttpRequest;return r.open(\"GET\",e,!1),r.responseType=\"arraybuffer\",r.send(null),new Uint8Array(r.response)}),Qe=async e=>{var r=await fetch(e,{credentials:\"same-origin\"});if(r.ok)return r.arrayBuffer();throw new Error(r.status+\" : \"+r.url)}}var we=console.log.bind(console),ee=console.error.bind(console),be,Pe=!1,Ae;function lc(e,r){e||ce(r)}var fc=e=>e.startsWith(\"file://\"),Cr,Tr,$e,G,B,A,ve,C,m,De,Re,W,Fr,Pr=!1;function Ar(){var e=$e.buffer;l.HEAP8=G=new Int8Array(e),A=new Int16Array(e),l.HEAPU8=B=new Uint8Array(e),ve=new Uint16Array(e),l.HEAP32=C=new Int32Array(e),l.HEAPU32=m=new Uint32Array(e),l.HEAPF32=De=new Float32Array(e),l.HEAPF64=Re=new Float64Array(e),W=new BigInt64Array(e),Fr=new BigUint64Array(e)}function jt(){if(l.preRun)for(typeof l.preRun==\"function\"&&(l.preRun=[l.preRun]);l.preRun.length;)Ht(l.preRun.shift());Dr(Ir)}function Ot(){Pr=!0,!l.noFSInit&&!o.initialized&&o.init(),ae.init(),de.__wasm_call_ctors(),o.ignorePermissions=!1}function xt(){if(l.postRun)for(typeof l.postRun==\"function\"&&(l.postRun=[l.postRun]);l.postRun.length;)zt(l.postRun.shift());Dr(Rr)}function ce(e){l.onAbort?.(e),e=\"Aborted(\"+e+\")\",ee(e),Pe=!0,e+=\". Build with -sASSERTIONS for more info.\";var r=new WebAssembly.RuntimeError(e);throw Tr?.(r),r}var er;function Gt(){return l.locateFile?Mt(\"AquaApi.wasm\"):new URL(\"AquaApi.wasm\",import.meta.url).href}function Nt(e){if(e==er&&be)return new Uint8Array(be);if(Fe)return Fe(e);throw\"both async and sync fetching of the wasm failed\"}async function Bt(e){if(!be)try{var r=await Qe(e);return new Uint8Array(r)}catch{}return Nt(e)}async function Lt(e,r){try{var t=await Bt(e),n=await WebAssembly.instantiate(t,r);return n}catch(i){ee(`failed to asynchronously prepare wasm: ${i}`),ce(i)}}async function Wt(e,r,t){if(!e)try{var n=fetch(r,{credentials:\"same-origin\"}),i=await WebAssembly.instantiateStreaming(n,t);return i}catch(a){ee(`wasm streaming compile failed: ${a}`),ee(\"falling back to ArrayBuffer instantiation\")}return Lt(r,t)}function Ut(){return{env:At,wasi_snapshot_preview1:At}}async function Vt(){function e(a,s){return de=a.exports,$e=de.memory,Ar(),Yr=de.__indirect_function_table,as(de),de}function r(a){return e(a.instance)}var t=Ut();if(l.instantiateWasm)return new Promise((a,s)=>{l.instantiateWasm(t,(c,u)=>{a(e(c,u))})});er??=Gt();var n=await Wt(be,er,t),i=r(n);return i}class $r{name=\"ExitStatus\";constructor(r){this.message=`Program terminated with exit(${r})`,this.status=r}}var Dr=e=>{for(;e.length>0;)e.shift()(l)},Rr=[],zt=e=>Rr.push(e),Ir=[],Ht=e=>Ir.push(e);function dc(e,r=\"i8\"){switch(r.endsWith(\"*\")&&(r=\"*\"),r){case\"i1\":return G[e];case\"i8\":return G[e];case\"i16\":return A[e>>1];case\"i32\":return C[e>>2];case\"i64\":return W[e>>3];case\"float\":return De[e>>2];case\"double\":return Re[e>>3];case\"*\":return m[e>>2];default:ce(`invalid type for getValue: ${r}`)}}var rr=!0;function vc(e,r,t=\"i8\"){switch(t.endsWith(\"*\")&&(t=\"*\"),t){case\"i1\":G[e]=r;break;case\"i8\":G[e]=r;break;case\"i16\":A[e>>1]=r;break;case\"i32\":C[e>>2]=r;break;case\"i64\":W[e>>3]=BigInt(r);break;case\"float\":De[e>>2]=r;break;case\"double\":Re[e>>3]=r;break;case\"*\":m[e>>2]=r;break;default:ce(`invalid type for setValue: ${t}`)}}var w=e=>St(e),b=()=>Et(),Ie=[],Me=0,qt=e=>{var r=new tr(e);return r.get_caught()||(r.set_caught(!0),Me--),r.set_rethrown(!1),Ie.push(r),Tt(e),Pt(e)},re=0,Xt=()=>{g(0,0);var e=Ie.pop();Ct(e.excPtr),re=0};class tr{constructor(r){this.excPtr=r,this.ptr=r-24}set_type(r){m[this.ptr+4>>2]=r}get_type(){return m[this.ptr+4>>2]}set_destructor(r){m[this.ptr+8>>2]=r}get_destructor(){return m[this.ptr+8>>2]}set_caught(r){r=r?1:0,G[this.ptr+12]=r}get_caught(){return G[this.ptr+12]!=0}set_rethrown(r){r=r?1:0,G[this.ptr+13]=r}get_rethrown(){return G[this.ptr+13]!=0}init(r,t){this.set_adjusted_ptr(0),this.set_type(r),this.set_destructor(t)}set_adjusted_ptr(r){m[this.ptr+16>>2]=r}get_adjusted_ptr(){return m[this.ptr+16>>2]}}var je=e=>bt(e),nr=e=>{var r=re;if(!r)return je(0),0;var t=new tr(r);t.set_adjusted_ptr(r);var n=t.get_type();if(!n)return je(0),r;for(var i of e){if(i===0||i===n)break;var a=t.ptr+16;if(Ft(i,n,a))return je(i),r}return je(n),r},Zt=()=>nr([]),Kt=e=>nr([e]),Yt=(e,r)=>nr([e,r]),Jt=()=>{var e=Ie.pop();e||ce(\"no exception to throw\");var r=e.excPtr;throw e.get_rethrown()||(Ie.push(e),e.set_rethrown(!0),e.set_caught(!1),Me++),re=r,re},Qt=(e,r,t)=>{var n=new tr(e);throw n.init(r,t),re=e,Me++,re},en=()=>Me,rn=e=>{throw re||(re=e),re},Oe=()=>{var e=C[+R.varargs>>2];return R.varargs+=4,e},_e=Oe,D={isAbs:e=>e.charAt(0)===\"/\",splitPath:e=>{var r=/^(\\/?|)([\\s\\S]*?)((?:\\.{1,2}|[^\\/]+?|)(\\.[^.\\/]*|))(?:[\\/]*)$/;return r.exec(e).slice(1)},normalizeArray:(e,r)=>{for(var t=0,n=e.length-1;n>=0;n--){var i=e[n];i===\".\"?e.splice(n,1):i===\"..\"?(e.splice(n,1),t++):t&&(e.splice(n,1),t--)}if(r)for(;t;t--)e.unshift(\"..\");return e},normalize:e=>{var r=D.isAbs(e),t=e.slice(-1)===\"/\";return e=D.normalizeArray(e.split(\"/\").filter(n=>!!n),!r).join(\"/\"),!e&&!r&&(e=\".\"),e&&t&&(e+=\"/\"),(r?\"/\":\"\")+e},dirname:e=>{var r=D.splitPath(e),t=r[0],n=r[1];return!t&&!n?\".\":(n&&(n=n.slice(0,-1)),t+n)},basename:e=>e&&e.match(/([^\\/]+|\\/)\\/*$/)[1],join:(...e)=>D.normalize(e.join(\"/\")),join2:(e,r)=>D.normalize(e+\"/\"+r)},tn=()=>e=>crypto.getRandomValues(e),ir=e=>{(ir=tn())(e)},he={resolve:(...e)=>{for(var r=\"\",t=!1,n=e.length-1;n>=-1&&!t;n--){var i=n>=0?e[n]:o.cwd();if(typeof i!=\"string\")throw new TypeError(\"Arguments to path.resolve must be strings\");if(!i)return\"\";r=i+\"/\"+r,t=D.isAbs(i)}return r=D.normalizeArray(r.split(\"/\").filter(a=>!!a),!t).join(\"/\"),(t?\"/\":\"\")+r||\".\"},relative:(e,r)=>{e=he.resolve(e).slice(1),r=he.resolve(r).slice(1);function t(f){for(var d=0;d<f.length&&f[d]===\"\";d++);for(var _=f.length-1;_>=0&&f[_]===\"\";_--);return d>_?[]:f.slice(d,_-d+1)}for(var n=t(e.split(\"/\")),i=t(r.split(\"/\")),a=Math.min(n.length,i.length),s=a,c=0;c<a;c++)if(n[c]!==i[c]){s=c;break}for(var u=[],c=s;c<n.length;c++)u.push(\"..\");return u=u.concat(i.slice(s)),u.join(\"/\")}},Mr=typeof TextDecoder<\"u\"?new TextDecoder:void 0,jr=(e,r,t,n)=>{var i=r+t;if(n)return i;for(;e[r]&&!(r>=i);)++r;return r},me=(e,r=0,t,n)=>{var i=jr(e,r,t,n);if(i-r>16&&e.buffer&&Mr)return Mr.decode(e.subarray(r,i));for(var a=\"\";r<i;){var s=e[r++];if(!(s&128)){a+=String.fromCharCode(s);continue}var c=e[r++]&63;if((s&224)==192){a+=String.fromCharCode((s&31)<<6|c);continue}var u=e[r++]&63;if((s&240)==224?s=(s&15)<<12|c<<6|u:s=(s&7)<<18|c<<12|u<<6|e[r++]&63,s<65536)a+=String.fromCharCode(s);else{var f=s-65536;a+=String.fromCharCode(55296|f>>10,56320|f&1023)}}return a},ar=[],Y=e=>{for(var r=0,t=0;t<e.length;++t){var n=e.charCodeAt(t);n<=127?r++:n<=2047?r+=2:n>=55296&&n<=57343?(r+=4,++t):r+=3}return r},Or=(e,r,t,n)=>{if(!(n>0))return 0;for(var i=t,a=t+n-1,s=0;s<e.length;++s){var c=e.codePointAt(s);if(c<=127){if(t>=a)break;r[t++]=c}else if(c<=2047){if(t+1>=a)break;r[t++]=192|c>>6,r[t++]=128|c&63}else if(c<=65535){if(t+2>=a)break;r[t++]=224|c>>12,r[t++]=128|c>>6&63,r[t++]=128|c&63}else{if(t+3>=a)break;r[t++]=240|c>>18,r[t++]=128|c>>12&63,r[t++]=128|c>>6&63,r[t++]=128|c&63,s++}}return r[t]=0,t-i},or=(e,r,t)=>{var n=t>0?t:Y(e)+1,i=new Array(n),a=Or(e,i,0,i.length);return r&&(i.length=a),i},nn=()=>{if(!ar.length){var e=null;if(typeof window<\"u\"&&typeof window.prompt==\"function\"&&(e=window.prompt(\"Input: \"),e!==null&&(e+=`\n`)),!e)return null;ar=or(e,!0)}return ar.shift()},ae={ttys:[],init(){},shutdown(){},register(e,r){ae.ttys[e]={input:[],output:[],ops:r},o.registerDevice(e,ae.stream_ops)},stream_ops:{open(e){var r=ae.ttys[e.node.rdev];if(!r)throw new o.ErrnoError(43);e.tty=r,e.seekable=!1},close(e){e.tty.ops.fsync(e.tty)},fsync(e){e.tty.ops.fsync(e.tty)},read(e,r,t,n,i){if(!e.tty||!e.tty.ops.get_char)throw new o.ErrnoError(60);for(var a=0,s=0;s<n;s++){var c;try{c=e.tty.ops.get_char(e.tty)}catch{throw new o.ErrnoError(29)}if(c===void 0&&a===0)throw new o.ErrnoError(6);if(c==null)break;a++,r[t+s]=c}return a&&(e.node.atime=Date.now()),a},write(e,r,t,n,i){if(!e.tty||!e.tty.ops.put_char)throw new o.ErrnoError(60);try{for(var a=0;a<n;a++)e.tty.ops.put_char(e.tty,r[t+a])}catch{throw new o.ErrnoError(29)}return n&&(e.node.mtime=e.node.ctime=Date.now()),a}},default_tty_ops:{get_char(e){return nn()},put_char(e,r){r===null||r===10?(we(me(e.output)),e.output=[]):r!=0&&e.output.push(r)},fsync(e){e.output?.length>0&&(we(me(e.output)),e.output=[])},ioctl_tcgets(e){return{c_iflag:25856,c_oflag:5,c_cflag:191,c_lflag:35387,c_cc:[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},ioctl_tcsets(e,r,t){return 0},ioctl_tiocgwinsz(e){return[24,80]}},default_tty1_ops:{put_char(e,r){r===null||r===10?(ee(me(e.output)),e.output=[]):r!=0&&e.output.push(r)},fsync(e){e.output?.length>0&&(ee(me(e.output)),e.output=[])}}},xr=e=>{ce()},E={ops_table:null,mount(e){return E.createNode(null,\"/\",16895,0)},createNode(e,r,t,n){if(o.isBlkdev(t)||o.isFIFO(t))throw new o.ErrnoError(63);E.ops_table||={dir:{node:{getattr:E.node_ops.getattr,setattr:E.node_ops.setattr,lookup:E.node_ops.lookup,mknod:E.node_ops.mknod,rename:E.node_ops.rename,unlink:E.node_ops.unlink,rmdir:E.node_ops.rmdir,readdir:E.node_ops.readdir,symlink:E.node_ops.symlink},stream:{llseek:E.stream_ops.llseek}},file:{node:{getattr:E.node_ops.getattr,setattr:E.node_ops.setattr},stream:{llseek:E.stream_ops.llseek,read:E.stream_ops.read,write:E.stream_ops.write,mmap:E.stream_ops.mmap,msync:E.stream_ops.msync}},link:{node:{getattr:E.node_ops.getattr,setattr:E.node_ops.setattr,readlink:E.node_ops.readlink},stream:{}},chrdev:{node:{getattr:E.node_ops.getattr,setattr:E.node_ops.setattr},stream:o.chrdev_stream_ops}};var i=o.createNode(e,r,t,n);return o.isDir(i.mode)?(i.node_ops=E.ops_table.dir.node,i.stream_ops=E.ops_table.dir.stream,i.contents={}):o.isFile(i.mode)?(i.node_ops=E.ops_table.file.node,i.stream_ops=E.ops_table.file.stream,i.usedBytes=0,i.contents=null):o.isLink(i.mode)?(i.node_ops=E.ops_table.link.node,i.stream_ops=E.ops_table.link.stream):o.isChrdev(i.mode)&&(i.node_ops=E.ops_table.chrdev.node,i.stream_ops=E.ops_table.chrdev.stream),i.atime=i.mtime=i.ctime=Date.now(),e&&(e.contents[r]=i,e.atime=e.mtime=e.ctime=i.atime),i},getFileDataAsTypedArray(e){return e.contents?e.contents.subarray?e.contents.subarray(0,e.usedBytes):new Uint8Array(e.contents):new Uint8Array(0)},expandFileStorage(e,r){var t=e.contents?e.contents.length:0;if(!(t>=r)){var n=1024*1024;r=Math.max(r,t*(t<n?2:1.125)>>>0),t!=0&&(r=Math.max(r,256));var i=e.contents;e.contents=new Uint8Array(r),e.usedBytes>0&&e.contents.set(i.subarray(0,e.usedBytes),0)}},resizeFileStorage(e,r){if(e.usedBytes!=r)if(r==0)e.contents=null,e.usedBytes=0;else{var t=e.contents;e.contents=new Uint8Array(r),t&&e.contents.set(t.subarray(0,Math.min(r,e.usedBytes))),e.usedBytes=r}},node_ops:{getattr(e){var r={};return r.dev=o.isChrdev(e.mode)?e.id:1,r.ino=e.id,r.mode=e.mode,r.nlink=1,r.uid=0,r.gid=0,r.rdev=e.rdev,o.isDir(e.mode)?r.size=4096:o.isFile(e.mode)?r.size=e.usedBytes:o.isLink(e.mode)?r.size=e.link.length:r.size=0,r.atime=new Date(e.atime),r.mtime=new Date(e.mtime),r.ctime=new Date(e.ctime),r.blksize=4096,r.blocks=Math.ceil(r.size/r.blksize),r},setattr(e,r){for(const t of[\"mode\",\"atime\",\"mtime\",\"ctime\"])r[t]!=null&&(e[t]=r[t]);r.size!==void 0&&E.resizeFileStorage(e,r.size)},lookup(e,r){throw E.doesNotExistError||(E.doesNotExistError=new o.ErrnoError(44),E.doesNotExistError.stack=\"<generic error, no stack>\"),E.doesNotExistError},mknod(e,r,t,n){return E.createNode(e,r,t,n)},rename(e,r,t){var n;try{n=o.lookupNode(r,t)}catch{}if(n){if(o.isDir(e.mode))for(var i in n.contents)throw new o.ErrnoError(55);o.hashRemoveNode(n)}delete e.parent.contents[e.name],r.contents[t]=e,e.name=t,r.ctime=r.mtime=e.parent.ctime=e.parent.mtime=Date.now()},unlink(e,r){delete e.contents[r],e.ctime=e.mtime=Date.now()},rmdir(e,r){var t=o.lookupNode(e,r);for(var n in t.contents)throw new o.ErrnoError(55);delete e.contents[r],e.ctime=e.mtime=Date.now()},readdir(e){return[\".\",\"..\",...Object.keys(e.contents)]},symlink(e,r,t){var n=E.createNode(e,r,41471,0);return n.link=t,n},readlink(e){if(!o.isLink(e.mode))throw new o.ErrnoError(28);return e.link}},stream_ops:{read(e,r,t,n,i){var a=e.node.contents;if(i>=e.node.usedBytes)return 0;var s=Math.min(e.node.usedBytes-i,n);if(s>8&&a.subarray)r.set(a.subarray(i,i+s),t);else for(var c=0;c<s;c++)r[t+c]=a[i+c];return s},write(e,r,t,n,i,a){if(r.buffer===G.buffer&&(a=!1),!n)return 0;var s=e.node;if(s.mtime=s.ctime=Date.now(),r.subarray&&(!s.contents||s.contents.subarray)){if(a)return s.contents=r.subarray(t,t+n),s.usedBytes=n,n;if(s.usedBytes===0&&i===0)return s.contents=r.slice(t,t+n),s.usedBytes=n,n;if(i+n<=s.usedBytes)return s.contents.set(r.subarray(t,t+n),i),n}if(E.expandFileStorage(s,i+n),s.contents.subarray&&r.subarray)s.contents.set(r.subarray(t,t+n),i);else for(var c=0;c<n;c++)s.contents[i+c]=r[t+c];return s.usedBytes=Math.max(s.usedBytes,i+n),n},llseek(e,r,t){var n=r;if(t===1?n+=e.position:t===2&&o.isFile(e.node.mode)&&(n+=e.node.usedBytes),n<0)throw new o.ErrnoError(28);return n},mmap(e,r,t,n,i){if(!o.isFile(e.node.mode))throw new o.ErrnoError(43);var a,s,c=e.node.contents;if(!(i&2)&&c&&c.buffer===G.buffer)s=!1,a=c.byteOffset;else{if(s=!0,a=xr(r),!a)throw new o.ErrnoError(48);c&&((t>0||t+r<c.length)&&(c.subarray?c=c.subarray(t,t+r):c=Array.prototype.slice.call(c,t,t+r)),G.set(c,a))}return{ptr:a,allocated:s}},msync(e,r,t,n,i){return E.stream_ops.write(e,r,0,n,t,!1),0}}},an=e=>{var r={r:0,\"r+\":2,w:577,\"w+\":578,a:1089,\"a+\":1090},t=r[e];if(typeof t>\"u\")throw new Error(`Unknown file open mode: ${e}`);return t},sr=(e,r)=>{var t=0;return e&&(t|=365),r&&(t|=146),t},on=async e=>{var r=await Qe(e);return new Uint8Array(r)},sn=(...e)=>o.createDataFile(...e),cn=e=>e,ue=0,Se=null,Gr=e=>{if(ue--,l.monitorRunDependencies?.(ue),ue==0&&Se){var r=Se;Se=null,r()}},Nr=e=>{ue++,l.monitorRunDependencies?.(ue)},Br=[],un=async(e,r)=>{typeof Browser<\"u\"&&Browser.init();for(var t of Br)if(t.canHandle(r))return t.handle(e,r);return e},Lr=async(e,r,t,n,i,a,s,c)=>{var u=r?he.resolve(D.join2(e,r)):e,f=cn(`cp ${u}`);Nr(f);try{var d=t;typeof t==\"string\"&&(d=await on(t)),d=await un(d,u),c?.(),a||sn(e,r,d,n,i,s)}finally{Gr(f)}},ln=(e,r,t,n,i,a,s,c,u,f)=>{Lr(e,r,t,n,i,c,u,f).then(a).catch(s)},o={root:null,mounts:[],devices:{},streams:[],nextInode:1,nameTable:null,currentPath:\"/\",initialized:!1,ignorePermissions:!0,filesystems:null,syncFSRequests:0,readFiles:{},ErrnoError:class{name=\"ErrnoError\";constructor(e){this.errno=e}},FSStream:class{shared={};get object(){return this.node}set object(e){this.node=e}get isRead(){return(this.flags&2097155)!==1}get isWrite(){return(this.flags&2097155)!==0}get isAppend(){return this.flags&1024}get flags(){return this.shared.flags}set flags(e){this.shared.flags=e}get position(){return this.shared.position}set position(e){this.shared.position=e}},FSNode:class{node_ops={};stream_ops={};readMode=365;writeMode=146;mounted=null;constructor(e,r,t,n){e||(e=this),this.parent=e,this.mount=e.mount,this.id=o.nextInode++,this.name=r,this.mode=t,this.rdev=n,this.atime=this.mtime=this.ctime=Date.now()}get read(){return(this.mode&this.readMode)===this.readMode}set read(e){e?this.mode|=this.readMode:this.mode&=~this.readMode}get write(){return(this.mode&this.writeMode)===this.writeMode}set write(e){e?this.mode|=this.writeMode:this.mode&=~this.writeMode}get isFolder(){return o.isDir(this.mode)}get isDevice(){return o.isChrdev(this.mode)}},lookupPath(e,r={}){if(!e)throw new o.ErrnoError(44);r.follow_mount??=!0,D.isAbs(e)||(e=o.cwd()+\"/\"+e);e:for(var t=0;t<40;t++){for(var n=e.split(\"/\").filter(f=>!!f),i=o.root,a=\"/\",s=0;s<n.length;s++){var c=s===n.length-1;if(c&&r.parent)break;if(n[s]!==\".\"){if(n[s]===\"..\"){if(a=D.dirname(a),o.isRoot(i)){e=a+\"/\"+n.slice(s+1).join(\"/\"),t--;continue e}else i=i.parent;continue}a=D.join2(a,n[s]);try{i=o.lookupNode(i,n[s])}catch(f){if(f?.errno===44&&c&&r.noent_okay)return{path:a};throw f}if(o.isMountpoint(i)&&(!c||r.follow_mount)&&(i=i.mounted.root),o.isLink(i.mode)&&(!c||r.follow)){if(!i.node_ops.readlink)throw new o.ErrnoError(52);var u=i.node_ops.readlink(i);D.isAbs(u)||(u=D.dirname(a)+\"/\"+u),e=u+\"/\"+n.slice(s+1).join(\"/\");continue e}}}return{path:a,node:i}}throw new o.ErrnoError(32)},getPath(e){for(var r;;){if(o.isRoot(e)){var t=e.mount.mountpoint;return r?t[t.length-1]!==\"/\"?`${t}/${r}`:t+r:t}r=r?`${e.name}/${r}`:e.name,e=e.parent}},hashName(e,r){for(var t=0,n=0;n<r.length;n++)t=(t<<5)-t+r.charCodeAt(n)|0;return(e+t>>>0)%o.nameTable.length},hashAddNode(e){var r=o.hashName(e.parent.id,e.name);e.name_next=o.nameTable[r],o.nameTable[r]=e},hashRemoveNode(e){var r=o.hashName(e.parent.id,e.name);if(o.nameTable[r]===e)o.nameTable[r]=e.name_next;else for(var t=o.nameTable[r];t;){if(t.name_next===e){t.name_next=e.name_next;break}t=t.name_next}},lookupNode(e,r){var t=o.mayLookup(e);if(t)throw new o.ErrnoError(t);for(var n=o.hashName(e.id,r),i=o.nameTable[n];i;i=i.name_next){var a=i.name;if(i.parent.id===e.id&&a===r)return i}return o.lookup(e,r)},createNode(e,r,t,n){var i=new o.FSNode(e,r,t,n);return o.hashAddNode(i),i},destroyNode(e){o.hashRemoveNode(e)},isRoot(e){return e===e.parent},isMountpoint(e){return!!e.mounted},isFile(e){return(e&61440)===32768},isDir(e){return(e&61440)===16384},isLink(e){return(e&61440)===40960},isChrdev(e){return(e&61440)===8192},isBlkdev(e){return(e&61440)===24576},isFIFO(e){return(e&61440)===4096},isSocket(e){return(e&49152)===49152},flagsToPermissionString(e){var r=[\"r\",\"w\",\"rw\"][e&3];return e&512&&(r+=\"w\"),r},nodePermissions(e,r){return o.ignorePermissions?0:r.includes(\"r\")&&!(e.mode&292)||r.includes(\"w\")&&!(e.mode&146)||r.includes(\"x\")&&!(e.mode&73)?2:0},mayLookup(e){if(!o.isDir(e.mode))return 54;var r=o.nodePermissions(e,\"x\");return r||(e.node_ops.lookup?0:2)},mayCreate(e,r){if(!o.isDir(e.mode))return 54;try{var t=o.lookupNode(e,r);return 20}catch{}return o.nodePermissions(e,\"wx\")},mayDelete(e,r,t){var n;try{n=o.lookupNode(e,r)}catch(a){return a.errno}var i=o.nodePermissions(e,\"wx\");if(i)return i;if(t){if(!o.isDir(n.mode))return 54;if(o.isRoot(n)||o.getPath(n)===o.cwd())return 10}else if(o.isDir(n.mode))return 31;return 0},mayOpen(e,r){return e?o.isLink(e.mode)?32:o.isDir(e.mode)&&(o.flagsToPermissionString(r)!==\"r\"||r&576)?31:o.nodePermissions(e,o.flagsToPermissionString(r)):44},checkOpExists(e,r){if(!e)throw new o.ErrnoError(r);return e},MAX_OPEN_FDS:4096,nextfd(){for(var e=0;e<=o.MAX_OPEN_FDS;e++)if(!o.streams[e])return e;throw new o.ErrnoError(33)},getStreamChecked(e){var r=o.getStream(e);if(!r)throw new o.ErrnoError(8);return r},getStream:e=>o.streams[e],createStream(e,r=-1){return e=Object.assign(new o.FSStream,e),r==-1&&(r=o.nextfd()),e.fd=r,o.streams[r]=e,e},closeStream(e){o.streams[e]=null},dupStream(e,r=-1){var t=o.createStream(e,r);return t.stream_ops?.dup?.(t),t},doSetAttr(e,r,t){var n=e?.stream_ops.setattr,i=n?e:r;n??=r.node_ops.setattr,o.checkOpExists(n,63),n(i,t)},chrdev_stream_ops:{open(e){var r=o.getDevice(e.node.rdev);e.stream_ops=r.stream_ops,e.stream_ops.open?.(e)},llseek(){throw new o.ErrnoError(70)}},major:e=>e>>8,minor:e=>e&255,makedev:(e,r)=>e<<8|r,registerDevice(e,r){o.devices[e]={stream_ops:r}},getDevice:e=>o.devices[e],getMounts(e){for(var r=[],t=[e];t.length;){var n=t.pop();r.push(n),t.push(...n.mounts)}return r},syncfs(e,r){typeof e==\"function\"&&(r=e,e=!1),o.syncFSRequests++,o.syncFSRequests>1&&ee(`warning: ${o.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`);var t=o.getMounts(o.root.mount),n=0;function i(s){return o.syncFSRequests--,r(s)}function a(s){if(s)return a.errored?void 0:(a.errored=!0,i(s));++n>=t.length&&i(null)}t.forEach(s=>{if(!s.type.syncfs)return a(null);s.type.syncfs(s,e,a)})},mount(e,r,t){var n=t===\"/\",i=!t,a;if(n&&o.root)throw new o.ErrnoError(10);if(!n&&!i){var s=o.lookupPath(t,{follow_mount:!1});if(t=s.path,a=s.node,o.isMountpoint(a))throw new o.ErrnoError(10);if(!o.isDir(a.mode))throw new o.ErrnoError(54)}var c={type:e,opts:r,mountpoint:t,mounts:[]},u=e.mount(c);return u.mount=c,c.root=u,n?o.root=u:a&&(a.mounted=c,a.mount&&a.mount.mounts.push(c)),u},unmount(e){var r=o.lookupPath(e,{follow_mount:!1});if(!o.isMountpoint(r.node))throw new o.ErrnoError(28);var t=r.node,n=t.mounted,i=o.getMounts(n);Object.keys(o.nameTable).forEach(s=>{for(var c=o.nameTable[s];c;){var u=c.name_next;i.includes(c.mount)&&o.destroyNode(c),c=u}}),t.mounted=null;var a=t.mount.mounts.indexOf(n);t.mount.mounts.splice(a,1)},lookup(e,r){return e.node_ops.lookup(e,r)},mknod(e,r,t){var n=o.lookupPath(e,{parent:!0}),i=n.node,a=D.basename(e);if(!a)throw new o.ErrnoError(28);if(a===\".\"||a===\"..\")throw new o.ErrnoError(20);var s=o.mayCreate(i,a);if(s)throw new o.ErrnoError(s);if(!i.node_ops.mknod)throw new o.ErrnoError(63);return i.node_ops.mknod(i,a,r,t)},statfs(e){return o.statfsNode(o.lookupPath(e,{follow:!0}).node)},statfsStream(e){return o.statfsNode(e.node)},statfsNode(e){var r={bsize:4096,frsize:4096,blocks:1e6,bfree:5e5,bavail:5e5,files:o.nextInode,ffree:o.nextInode-1,fsid:42,flags:2,namelen:255};return e.node_ops.statfs&&Object.assign(r,e.node_ops.statfs(e.mount.opts.root)),r},create(e,r=438){return r&=4095,r|=32768,o.mknod(e,r,0)},mkdir(e,r=511){return r&=1023,r|=16384,o.mknod(e,r,0)},mkdirTree(e,r){var t=e.split(\"/\"),n=\"\";for(var i of t)if(i){(n||D.isAbs(e))&&(n+=\"/\"),n+=i;try{o.mkdir(n,r)}catch(a){if(a.errno!=20)throw a}}},mkdev(e,r,t){return typeof t>\"u\"&&(t=r,r=438),r|=8192,o.mknod(e,r,t)},symlink(e,r){if(!he.resolve(e))throw new o.ErrnoError(44);var t=o.lookupPath(r,{parent:!0}),n=t.node;if(!n)throw new o.ErrnoError(44);var i=D.basename(r),a=o.mayCreate(n,i);if(a)throw new o.ErrnoError(a);if(!n.node_ops.symlink)throw new o.ErrnoError(63);return n.node_ops.symlink(n,i,e)},rename(e,r){var t=D.dirname(e),n=D.dirname(r),i=D.basename(e),a=D.basename(r),s,c,u;if(s=o.lookupPath(e,{parent:!0}),c=s.node,s=o.lookupPath(r,{parent:!0}),u=s.node,!c||!u)throw new o.ErrnoError(44);if(c.mount!==u.mount)throw new o.ErrnoError(75);var f=o.lookupNode(c,i),d=he.relative(e,n);if(d.charAt(0)!==\".\")throw new o.ErrnoError(28);if(d=he.relative(r,t),d.charAt(0)!==\".\")throw new o.ErrnoError(55);var _;try{_=o.lookupNode(u,a)}catch{}if(f!==_){var p=o.isDir(f.mode),v=o.mayDelete(c,i,p);if(v)throw new o.ErrnoError(v);if(v=_?o.mayDelete(u,a,p):o.mayCreate(u,a),v)throw new o.ErrnoError(v);if(!c.node_ops.rename)throw new o.ErrnoError(63);if(o.isMountpoint(f)||_&&o.isMountpoint(_))throw new o.ErrnoError(10);if(u!==c&&(v=o.nodePermissions(c,\"w\"),v))throw new o.ErrnoError(v);o.hashRemoveNode(f);try{c.node_ops.rename(f,u,a),f.parent=u}catch(h){throw h}finally{o.hashAddNode(f)}}},rmdir(e){var r=o.lookupPath(e,{parent:!0}),t=r.node,n=D.basename(e),i=o.lookupNode(t,n),a=o.mayDelete(t,n,!0);if(a)throw new o.ErrnoError(a);if(!t.node_ops.rmdir)throw new o.ErrnoError(63);if(o.isMountpoint(i))throw new o.ErrnoError(10);t.node_ops.rmdir(t,n),o.destroyNode(i)},readdir(e){var r=o.lookupPath(e,{follow:!0}),t=r.node,n=o.checkOpExists(t.node_ops.readdir,54);return n(t)},unlink(e){var r=o.lookupPath(e,{parent:!0}),t=r.node;if(!t)throw new o.ErrnoError(44);var n=D.basename(e),i=o.lookupNode(t,n),a=o.mayDelete(t,n,!1);if(a)throw new o.ErrnoError(a);if(!t.node_ops.unlink)throw new o.ErrnoError(63);if(o.isMountpoint(i))throw new o.ErrnoError(10);t.node_ops.unlink(t,n),o.destroyNode(i)},readlink(e){var r=o.lookupPath(e),t=r.node;if(!t)throw new o.ErrnoError(44);if(!t.node_ops.readlink)throw new o.ErrnoError(28);return t.node_ops.readlink(t)},stat(e,r){var t=o.lookupPath(e,{follow:!r}),n=t.node,i=o.checkOpExists(n.node_ops.getattr,63);return i(n)},fstat(e){var r=o.getStreamChecked(e),t=r.node,n=r.stream_ops.getattr,i=n?r:t;return n??=t.node_ops.getattr,o.checkOpExists(n,63),n(i)},lstat(e){return o.stat(e,!0)},doChmod(e,r,t,n){o.doSetAttr(e,r,{mode:t&4095|r.mode&-4096,ctime:Date.now(),dontFollow:n})},chmod(e,r,t){var n;if(typeof e==\"string\"){var i=o.lookupPath(e,{follow:!t});n=i.node}else n=e;o.doChmod(null,n,r,t)},lchmod(e,r){o.chmod(e,r,!0)},fchmod(e,r){var t=o.getStreamChecked(e);o.doChmod(t,t.node,r,!1)},doChown(e,r,t){o.doSetAttr(e,r,{timestamp:Date.now(),dontFollow:t})},chown(e,r,t,n){var i;if(typeof e==\"string\"){var a=o.lookupPath(e,{follow:!n});i=a.node}else i=e;o.doChown(null,i,n)},lchown(e,r,t){o.chown(e,r,t,!0)},fchown(e,r,t){var n=o.getStreamChecked(e);o.doChown(n,n.node,!1)},doTruncate(e,r,t){if(o.isDir(r.mode))throw new o.ErrnoError(31);if(!o.isFile(r.mode))throw new o.ErrnoError(28);var n=o.nodePermissions(r,\"w\");if(n)throw new o.ErrnoError(n);o.doSetAttr(e,r,{size:t,timestamp:Date.now()})},truncate(e,r){if(r<0)throw new o.ErrnoError(28);var t;if(typeof e==\"string\"){var n=o.lookupPath(e,{follow:!0});t=n.node}else t=e;o.doTruncate(null,t,r)},ftruncate(e,r){var t=o.getStreamChecked(e);if(r<0||(t.flags&2097155)===0)throw new o.ErrnoError(28);o.doTruncate(t,t.node,r)},utime(e,r,t){var n=o.lookupPath(e,{follow:!0}),i=n.node,a=o.checkOpExists(i.node_ops.setattr,63);a(i,{atime:r,mtime:t})},open(e,r,t=438){if(e===\"\")throw new o.ErrnoError(44);r=typeof r==\"string\"?an(r):r,r&64?t=t&4095|32768:t=0;var n,i;if(typeof e==\"object\")n=e;else{i=e.endsWith(\"/\");var a=o.lookupPath(e,{follow:!(r&131072),noent_okay:!0});n=a.node,e=a.path}var s=!1;if(r&64)if(n){if(r&128)throw new o.ErrnoError(20)}else{if(i)throw new o.ErrnoError(31);n=o.mknod(e,t|511,0),s=!0}if(!n)throw new o.ErrnoError(44);if(o.isChrdev(n.mode)&&(r&=-513),r&65536&&!o.isDir(n.mode))throw new o.ErrnoError(54);if(!s){var c=o.mayOpen(n,r);if(c)throw new o.ErrnoError(c)}r&512&&!s&&o.truncate(n,0),r&=-131713;var u=o.createStream({node:n,path:o.getPath(n),flags:r,seekable:!0,position:0,stream_ops:n.stream_ops,ungotten:[],error:!1});return u.stream_ops.open&&u.stream_ops.open(u),s&&o.chmod(n,t&511),l.logReadFiles&&!(r&1)&&(e in o.readFiles||(o.readFiles[e]=1)),u},close(e){if(o.isClosed(e))throw new o.ErrnoError(8);e.getdents&&(e.getdents=null);try{e.stream_ops.close&&e.stream_ops.close(e)}catch(r){throw r}finally{o.closeStream(e.fd)}e.fd=null},isClosed(e){return e.fd===null},llseek(e,r,t){if(o.isClosed(e))throw new o.ErrnoError(8);if(!e.seekable||!e.stream_ops.llseek)throw new o.ErrnoError(70);if(t!=0&&t!=1&&t!=2)throw new o.ErrnoError(28);return e.position=e.stream_ops.llseek(e,r,t),e.ungotten=[],e.position},read(e,r,t,n,i){if(n<0||i<0)throw new o.ErrnoError(28);if(o.isClosed(e))throw new o.ErrnoError(8);if((e.flags&2097155)===1)throw new o.ErrnoError(8);if(o.isDir(e.node.mode))throw new o.ErrnoError(31);if(!e.stream_ops.read)throw new o.ErrnoError(28);var a=typeof i<\"u\";if(!a)i=e.position;else if(!e.seekable)throw new o.ErrnoError(70);var s=e.stream_ops.read(e,r,t,n,i);return a||(e.position+=s),s},write(e,r,t,n,i,a){if(n<0||i<0)throw new o.ErrnoError(28);if(o.isClosed(e))throw new o.ErrnoError(8);if((e.flags&2097155)===0)throw new o.ErrnoError(8);if(o.isDir(e.node.mode))throw new o.ErrnoError(31);if(!e.stream_ops.write)throw new o.ErrnoError(28);e.seekable&&e.flags&1024&&o.llseek(e,0,2);var s=typeof i<\"u\";if(!s)i=e.position;else if(!e.seekable)throw new o.ErrnoError(70);var c=e.stream_ops.write(e,r,t,n,i,a);return s||(e.position+=c),c},mmap(e,r,t,n,i){if((n&2)!==0&&(i&2)===0&&(e.flags&2097155)!==2)throw new o.ErrnoError(2);if((e.flags&2097155)===1)throw new o.ErrnoError(2);if(!e.stream_ops.mmap)throw new o.ErrnoError(43);if(!r)throw new o.ErrnoError(28);return e.stream_ops.mmap(e,r,t,n,i)},msync(e,r,t,n,i){return e.stream_ops.msync?e.stream_ops.msync(e,r,t,n,i):0},ioctl(e,r,t){if(!e.stream_ops.ioctl)throw new o.ErrnoError(59);return e.stream_ops.ioctl(e,r,t)},readFile(e,r={}){if(r.flags=r.flags||0,r.encoding=r.encoding||\"binary\",r.encoding!==\"utf8\"&&r.encoding!==\"binary\")throw new Error(`Invalid encoding type \"${r.encoding}\"`);var t=o.open(e,r.flags),n=o.stat(e),i=n.size,a=new Uint8Array(i);return o.read(t,a,0,i,0),r.encoding===\"utf8\"&&(a=me(a)),o.close(t),a},writeFile(e,r,t={}){t.flags=t.flags||577;var n=o.open(e,t.flags,t.mode);if(typeof r==\"string\"&&(r=new Uint8Array(or(r,!0))),ArrayBuffer.isView(r))o.write(n,r,0,r.byteLength,void 0,t.canOwn);else throw new Error(\"Unsupported data type\");o.close(n)},cwd:()=>o.currentPath,chdir(e){var r=o.lookupPath(e,{follow:!0});if(r.node===null)throw new o.ErrnoError(44);if(!o.isDir(r.node.mode))throw new o.ErrnoError(54);var t=o.nodePermissions(r.node,\"x\");if(t)throw new o.ErrnoError(t);o.currentPath=r.path},createDefaultDirectories(){o.mkdir(\"/tmp\"),o.mkdir(\"/home\"),o.mkdir(\"/home/web_user\")},createDefaultDevices(){o.mkdir(\"/dev\"),o.registerDevice(o.makedev(1,3),{read:()=>0,write:(n,i,a,s,c)=>s,llseek:()=>0}),o.mkdev(\"/dev/null\",o.makedev(1,3)),ae.register(o.makedev(5,0),ae.default_tty_ops),ae.register(o.makedev(6,0),ae.default_tty1_ops),o.mkdev(\"/dev/tty\",o.makedev(5,0)),o.mkdev(\"/dev/tty1\",o.makedev(6,0));var e=new Uint8Array(1024),r=0,t=()=>(r===0&&(ir(e),r=e.byteLength),e[--r]);o.createDevice(\"/dev\",\"random\",t),o.createDevice(\"/dev\",\"urandom\",t),o.mkdir(\"/dev/shm\"),o.mkdir(\"/dev/shm/tmp\")},createSpecialDirectories(){o.mkdir(\"/proc\");var e=o.mkdir(\"/proc/self\");o.mkdir(\"/proc/self/fd\"),o.mount({mount(){var r=o.createNode(e,\"fd\",16895,73);return r.stream_ops={llseek:E.stream_ops.llseek},r.node_ops={lookup(t,n){var i=+n,a=o.getStreamChecked(i),s={parent:null,mount:{mountpoint:\"fake\"},node_ops:{readlink:()=>a.path},id:i+1};return s.parent=s,s},readdir(){return Array.from(o.streams.entries()).filter(([t,n])=>n).map(([t,n])=>t.toString())}},r}},{},\"/proc/self/fd\")},createStandardStreams(e,r,t){e?o.createDevice(\"/dev\",\"stdin\",e):o.symlink(\"/dev/tty\",\"/dev/stdin\"),r?o.createDevice(\"/dev\",\"stdout\",null,r):o.symlink(\"/dev/tty\",\"/dev/stdout\"),t?o.createDevice(\"/dev\",\"stderr\",null,t):o.symlink(\"/dev/tty1\",\"/dev/stderr\");var n=o.open(\"/dev/stdin\",0),i=o.open(\"/dev/stdout\",1),a=o.open(\"/dev/stderr\",1)},staticInit(){o.nameTable=new Array(4096),o.mount(E,{},\"/\"),o.createDefaultDirectories(),o.createDefaultDevices(),o.createSpecialDirectories(),o.filesystems={MEMFS:E}},init(e,r,t){o.initialized=!0,e??=l.stdin,r??=l.stdout,t??=l.stderr,o.createStandardStreams(e,r,t)},quit(){o.initialized=!1;for(var e of o.streams)e&&o.close(e)},findObject(e,r){var t=o.analyzePath(e,r);return t.exists?t.object:null},analyzePath(e,r){try{var t=o.lookupPath(e,{follow:!r});e=t.path}catch{}var n={isRoot:!1,exists:!1,error:0,name:null,path:null,object:null,parentExists:!1,parentPath:null,parentObject:null};try{var t=o.lookupPath(e,{parent:!0});n.parentExists=!0,n.parentPath=t.path,n.parentObject=t.node,n.name=D.basename(e),t=o.lookupPath(e,{follow:!r}),n.exists=!0,n.path=t.path,n.object=t.node,n.name=t.node.name,n.isRoot=t.path===\"/\"}catch(i){n.error=i.errno}return n},createPath(e,r,t,n){e=typeof e==\"string\"?e:o.getPath(e);for(var i=r.split(\"/\").reverse();i.length;){var a=i.pop();if(a){var s=D.join2(e,a);try{o.mkdir(s)}catch(c){if(c.errno!=20)throw c}e=s}}return s},createFile(e,r,t,n,i){var a=D.join2(typeof e==\"string\"?e:o.getPath(e),r),s=sr(n,i);return o.create(a,s)},createDataFile(e,r,t,n,i,a){var s=r;e&&(e=typeof e==\"string\"?e:o.getPath(e),s=r?D.join2(e,r):e);var c=sr(n,i),u=o.create(s,c);if(t){if(typeof t==\"string\"){for(var f=new Array(t.length),d=0,_=t.length;d<_;++d)f[d]=t.charCodeAt(d);t=f}o.chmod(u,c|146);var p=o.open(u,577);o.write(p,t,0,t.length,0,a),o.close(p),o.chmod(u,c)}},createDevice(e,r,t,n){var i=D.join2(typeof e==\"string\"?e:o.getPath(e),r),a=sr(!!t,!!n);o.createDevice.major??=64;var s=o.makedev(o.createDevice.major++,0);return o.registerDevice(s,{open(c){c.seekable=!1},close(c){n?.buffer?.length&&n(10)},read(c,u,f,d,_){for(var p=0,v=0;v<d;v++){var h;try{h=t()}catch{throw new o.ErrnoError(29)}if(h===void 0&&p===0)throw new o.ErrnoError(6);if(h==null)break;p++,u[f+v]=h}return p&&(c.node.atime=Date.now()),p},write(c,u,f,d,_){for(var p=0;p<d;p++)try{n(u[f+p])}catch{throw new o.ErrnoError(29)}return d&&(c.node.mtime=c.node.ctime=Date.now()),p}}),o.mkdev(i,a,s)},forceLoadFile(e){if(e.isDevice||e.isFolder||e.link||e.contents)return!0;if(typeof XMLHttpRequest<\"u\")throw new Error(\"Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.\");try{e.contents=Fe(e.url)}catch{throw new o.ErrnoError(29)}},createLazyFile(e,r,t,n,i){class a{lengthKnown=!1;chunks=[];get(v){if(!(v>this.length-1||v<0)){var h=v%this.chunkSize,k=v/this.chunkSize|0;return this.getter(k)[h]}}setDataGetter(v){this.getter=v}cacheLength(){var v=new XMLHttpRequest;if(v.open(\"HEAD\",t,!1),v.send(null),!(v.status>=200&&v.status<300||v.status===304))throw new Error(\"Couldn't load \"+t+\". Status: \"+v.status);var h=Number(v.getResponseHeader(\"Content-length\")),k,$=(k=v.getResponseHeader(\"Accept-Ranges\"))&&k===\"bytes\",T=(k=v.getResponseHeader(\"Content-Encoding\"))&&k===\"gzip\",x=1024*1024;$||(x=h);var P=(z,S)=>{if(z>S)throw new Error(\"invalid range (\"+z+\", \"+S+\") or no bytes requested!\");if(S>h-1)throw new Error(\"only \"+h+\" bytes available! programmer error!\");var I=new XMLHttpRequest;if(I.open(\"GET\",t,!1),h!==x&&I.setRequestHeader(\"Range\",\"bytes=\"+z+\"-\"+S),I.responseType=\"arraybuffer\",I.overrideMimeType&&I.overrideMimeType(\"text/plain; charset=x-user-defined\"),I.send(null),!(I.status>=200&&I.status<300||I.status===304))throw new Error(\"Couldn't load \"+t+\". Status: \"+I.status);return I.response!==void 0?new Uint8Array(I.response||[]):or(I.responseText||\"\",!0)},K=this;K.setDataGetter(z=>{var S=z*x,I=(z+1)*x-1;if(I=Math.min(I,h-1),typeof K.chunks[z]>\"u\"&&(K.chunks[z]=P(S,I)),typeof K.chunks[z]>\"u\")throw new Error(\"doXHR failed!\");return K.chunks[z]}),(T||!h)&&(x=h=1,h=this.getter(0).length,x=h,we(\"LazyFiles on gzip forces download of the whole file when length is accessed\")),this._length=h,this._chunkSize=x,this.lengthKnown=!0}get length(){return this.lengthKnown||this.cacheLength(),this._length}get chunkSize(){return this.lengthKnown||this.cacheLength(),this._chunkSize}}if(typeof XMLHttpRequest<\"u\"){if(!ge)throw\"Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc\";var s=new a,c={isDevice:!1,contents:s}}else var c={isDevice:!1,url:t};var u=o.createFile(e,r,c,n,i);c.contents?u.contents=c.contents:c.url&&(u.contents=null,u.url=c.url),Object.defineProperties(u,{usedBytes:{get:function(){return this.contents.length}}});var f={},d=Object.keys(u.stream_ops);d.forEach(p=>{var v=u.stream_ops[p];f[p]=(...h)=>(o.forceLoadFile(u),v(...h))});function _(p,v,h,k,$){var T=p.node.contents;if($>=T.length)return 0;var x=Math.min(T.length-$,k);if(T.slice)for(var P=0;P<x;P++)v[h+P]=T[$+P];else for(var P=0;P<x;P++)v[h+P]=T.get($+P);return x}return f.read=(p,v,h,k,$)=>(o.forceLoadFile(u),_(p,v,h,k,$)),f.mmap=(p,v,h,k,$)=>{o.forceLoadFile(u);var T=xr(v);if(!T)throw new o.ErrnoError(48);return _(p,G,T,v,h),{ptr:T,allocated:!0}},u.stream_ops=f,u}},M=(e,r,t)=>e?me(B,e,r,t):\"\",R={DEFAULT_POLLMASK:5,calculateAt(e,r,t){if(D.isAbs(r))return r;var n;if(e===-100)n=o.cwd();else{var i=R.getStreamFromFD(e);n=i.path}if(r.length==0){if(!t)throw new o.ErrnoError(44);return n}return n+\"/\"+r},writeStat(e,r){m[e>>2]=r.dev,m[e+4>>2]=r.mode,m[e+8>>2]=r.nlink,m[e+12>>2]=r.uid,m[e+16>>2]=r.gid,m[e+20>>2]=r.rdev,W[e+24>>3]=BigInt(r.size),C[e+32>>2]=4096,C[e+36>>2]=r.blocks;var t=r.atime.getTime(),n=r.mtime.getTime(),i=r.ctime.getTime();return W[e+40>>3]=BigInt(Math.floor(t/1e3)),m[e+48>>2]=t%1e3*1e3*1e3,W[e+56>>3]=BigInt(Math.floor(n/1e3)),m[e+64>>2]=n%1e3*1e3*1e3,W[e+72>>3]=BigInt(Math.floor(i/1e3)),m[e+80>>2]=i%1e3*1e3*1e3,W[e+88>>3]=BigInt(r.ino),0},writeStatFs(e,r){m[e+4>>2]=r.bsize,m[e+60>>2]=r.bsize,W[e+8>>3]=BigInt(r.blocks),W[e+16>>3]=BigInt(r.bfree),W[e+24>>3]=BigInt(r.bavail),W[e+32>>3]=BigInt(r.files),W[e+40>>3]=BigInt(r.ffree),m[e+48>>2]=r.fsid,m[e+64>>2]=r.flags,m[e+56>>2]=r.namelen},doMsync(e,r,t,n,i){if(!o.isFile(r.node.mode))throw new o.ErrnoError(43);if(n&2)return 0;var a=B.slice(e,e+t);o.msync(r,a,i,t,n)},getStreamFromFD(e){var r=o.getStreamChecked(e);return r},varargs:void 0,getStr(e){var r=M(e);return r}};function fn(e,r,t){R.varargs=t;try{var n=R.getStreamFromFD(e);switch(r){case 0:{var i=Oe();if(i<0)return-28;for(;o.streams[i];)i++;var a;return a=o.dupStream(n,i),a.fd}case 1:case 2:return 0;case 3:return n.flags;case 4:{var i=Oe();return n.flags|=i,0}case 12:{var i=_e(),s=0;return A[i+s>>1]=2,0}case 13:case 14:return 0}return-28}catch(c){if(typeof o>\"u\"||c.name!==\"ErrnoError\")throw c;return-c.errno}}function dn(e,r){try{return R.writeStat(r,o.fstat(e))}catch(t){if(typeof o>\"u\"||t.name!==\"ErrnoError\")throw t;return-t.errno}}function vn(e,r,t){R.varargs=t;try{var n=R.getStreamFromFD(e);switch(r){case 21509:return n.tty?0:-59;case 21505:{if(!n.tty)return-59;if(n.tty.ops.ioctl_tcgets){var i=n.tty.ops.ioctl_tcgets(n),a=_e();C[a>>2]=i.c_iflag||0,C[a+4>>2]=i.c_oflag||0,C[a+8>>2]=i.c_cflag||0,C[a+12>>2]=i.c_lflag||0;for(var s=0;s<32;s++)G[a+s+17]=i.c_cc[s]||0;return 0}return 0}case 21510:case 21511:case 21512:return n.tty?0:-59;case 21506:case 21507:case 21508:{if(!n.tty)return-59;if(n.tty.ops.ioctl_tcsets){for(var a=_e(),c=C[a>>2],u=C[a+4>>2],f=C[a+8>>2],d=C[a+12>>2],_=[],s=0;s<32;s++)_.push(G[a+s+17]);return n.tty.ops.ioctl_tcsets(n.tty,r,{c_iflag:c,c_oflag:u,c_cflag:f,c_lflag:d,c_cc:_})}return 0}case 21519:{if(!n.tty)return-59;var a=_e();return C[a>>2]=0,0}case 21520:return n.tty?-28:-59;case 21537:case 21531:{var a=_e();return o.ioctl(n,r,a)}case 21523:{if(!n.tty)return-59;if(n.tty.ops.ioctl_tiocgwinsz){var p=n.tty.ops.ioctl_tiocgwinsz(n.tty),a=_e();A[a>>1]=p[0],A[a+2>>1]=p[1]}return 0}case 21524:return n.tty?0:-59;case 21515:return n.tty?0:-59;default:return-28}}catch(v){if(typeof o>\"u\"||v.name!==\"ErrnoError\")throw v;return-v.errno}}function _n(e,r){try{return e=R.getStr(e),R.writeStat(r,o.lstat(e))}catch(t){if(typeof o>\"u\"||t.name!==\"ErrnoError\")throw t;return-t.errno}}function hn(e,r,t,n){try{r=R.getStr(r);var i=n&256,a=n&4096;return n=n&-6401,r=R.calculateAt(e,r,a),R.writeStat(t,i?o.lstat(r):o.stat(r))}catch(s){if(typeof o>\"u\"||s.name!==\"ErrnoError\")throw s;return-s.errno}}function mn(e,r,t,n){R.varargs=n;try{r=R.getStr(r),r=R.calculateAt(e,r);var i=n?Oe():0;return o.open(r,t,i).fd}catch(a){if(typeof o>\"u\"||a.name!==\"ErrnoError\")throw a;return-a.errno}}function pn(e){try{return e=R.getStr(e),o.rmdir(e),0}catch(r){if(typeof o>\"u\"||r.name!==\"ErrnoError\")throw r;return-r.errno}}function yn(e,r){try{return e=R.getStr(e),R.writeStat(r,o.stat(e))}catch(t){if(typeof o>\"u\"||t.name!==\"ErrnoError\")throw t;return-t.errno}}function gn(e,r,t){try{if(r=R.getStr(r),r=R.calculateAt(e,r),!t)o.unlink(r);else if(t===512)o.rmdir(r);else return-28;return 0}catch(n){if(typeof o>\"u\"||n.name!==\"ErrnoError\")throw n;return-n.errno}}var wn=()=>ce(\"\"),V=e=>{for(var r=\"\";;){var t=B[e++];if(!t)return r;r+=String.fromCharCode(t)}},pe={},le={},xe={},ke=class extends Error{constructor(r){super(r),this.name=\"BindingError\"}},F=e=>{throw new ke(e)};function bn(e,r,t={}){var n=r.name;if(e||F(`type \"${n}\" must have a positive integer typeid pointer`),le.hasOwnProperty(e)){if(t.ignoreDuplicateRegistrations)return;F(`Cannot register type '${n}' twice`)}if(le[e]=r,delete xe[e],pe.hasOwnProperty(e)){var i=pe[e];delete pe[e],i.forEach(a=>a())}}function q(e,r,t={}){return bn(e,r,t)}var Wr=(e,r,t)=>{switch(r){case 1:return t?n=>G[n]:n=>B[n];case 2:return t?n=>A[n>>1]:n=>ve[n>>1];case 4:return t?n=>C[n>>2]:n=>m[n>>2];case 8:return t?n=>W[n>>3]:n=>Fr[n>>3];default:throw new TypeError(`invalid integer width (${r}): ${e}`)}},Sn=(e,r,t,n,i)=>{r=V(r);const a=n===0n;let s=c=>c;if(a){const c=t*8;s=u=>BigInt.asUintN(c,u),i=s(i)}q(e,{name:r,fromWireType:s,toWireType:(c,u)=>(typeof u==\"number\"&&(u=BigInt(u)),u),readValueFromPointer:Wr(r,t,!a),destructorFunction:null})},kn=(e,r,t,n)=>{r=V(r),q(e,{name:r,fromWireType:function(i){return!!i},toWireType:function(i,a){return a?t:n},readValueFromPointer:function(i){return this.fromWireType(B[i])},destructorFunction:null})},En=e=>({count:e.count,deleteScheduled:e.deleteScheduled,preservePointerOnDelete:e.preservePointerOnDelete,ptr:e.ptr,ptrType:e.ptrType,smartPtr:e.smartPtr,smartPtrType:e.smartPtrType}),cr=e=>{function r(t){return t.$$.ptrType.registeredClass.name}F(r(e)+\" instance already deleted\")},ur=!1,Ur=e=>{},Cn=e=>{e.smartPtr?e.smartPtrType.rawDestructor(e.smartPtr):e.ptrType.registeredClass.rawDestructor(e.ptr)},Vr=e=>{e.count.value-=1;var r=e.count.value===0;r&&Cn(e)},Ee=e=>typeof FinalizationRegistry>\"u\"?(Ee=r=>r,e):(ur=new FinalizationRegistry(r=>{Vr(r.$$)}),Ee=r=>{var t=r.$$,n=!!t.smartPtr;if(n){var i={$$:t};ur.register(r,i,r)}return r},Ur=r=>ur.unregister(r),Ee(e)),Ge=[],Tn=()=>{for(;Ge.length;){var e=Ge.pop();e.$$.deleteScheduled=!1,e.delete()}},zr,Fn=()=>{let e=Ne.prototype;Object.assign(e,{isAliasOf(t){if(!(this instanceof Ne)||!(t instanceof Ne))return!1;var n=this.$$.ptrType.registeredClass,i=this.$$.ptr;t.$$=t.$$;for(var a=t.$$.ptrType.registeredClass,s=t.$$.ptr;n.baseClass;)i=n.upcast(i),n=n.baseClass;for(;a.baseClass;)s=a.upcast(s),a=a.baseClass;return n===a&&i===s},clone(){if(this.$$.ptr||cr(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var t=Ee(Object.create(Object.getPrototypeOf(this),{$$:{value:En(this.$$)}}));return t.$$.count.value+=1,t.$$.deleteScheduled=!1,t},delete(){this.$$.ptr||cr(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&F(\"Object already scheduled for deletion\"),Ur(this),Vr(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)},isDeleted(){return!this.$$.ptr},deleteLater(){return this.$$.ptr||cr(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&F(\"Object already scheduled for deletion\"),Ge.push(this),Ge.length===1&&zr&&zr(Tn),this.$$.deleteScheduled=!0,this}});const r=Symbol.dispose;r&&(e[r]=e.delete)};function Ne(){}var Be=(e,r)=>Object.defineProperty(r,\"name\",{value:e}),Hr={},qr=(e,r,t)=>{if(e[r].overloadTable===void 0){var n=e[r];e[r]=function(...i){return e[r].overloadTable.hasOwnProperty(i.length)||F(`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)},e[r].overloadTable=[],e[r].overloadTable[n.argCount]=n}},lr=(e,r,t)=>{l.hasOwnProperty(e)?((t===void 0||l[e].overloadTable!==void 0&&l[e].overloadTable[t]!==void 0)&&F(`Cannot register public name '${e}' twice`),qr(l,e,e),l[e].overloadTable.hasOwnProperty(t)&&F(`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)},Pn=48,An=57,$n=e=>{e=e.replace(/[^a-zA-Z0-9_]/g,\"$\");var r=e.charCodeAt(0);return r>=Pn&&r<=An?`_${e}`:e};function Dn(e,r,t,n,i,a,s,c){this.name=e,this.constructor=r,this.instancePrototype=t,this.rawDestructor=n,this.baseClass=i,this.getActualType=a,this.upcast=s,this.downcast=c,this.pureVirtualFunctions=[]}var Le=(e,r,t)=>{for(;r!==t;)r.upcast||F(`Expected null or instance of ${t.name}, got an instance of ${r.name}`),e=r.upcast(e),r=r.baseClass;return e},fr=e=>{if(e===null)return\"null\";var r=typeof e;return r===\"object\"||r===\"array\"||r===\"function\"?e.toString():\"\"+e};function Rn(e,r){if(r===null)return this.isReference&&F(`null is not a valid ${this.name}`),0;r.$$||F(`Cannot pass \"${fr(r)}\" as a ${this.name}`),r.$$.ptr||F(`Cannot pass deleted object as a pointer of type ${this.name}`);var t=r.$$.ptrType.registeredClass,n=Le(r.$$.ptr,t,this.registeredClass);return n}function In(e,r){var t;if(r===null)return this.isReference&&F(`null is not a valid ${this.name}`),this.isSmartPointer?(t=this.rawConstructor(),e!==null&&e.push(this.rawDestructor,t),t):0;(!r||!r.$$)&&F(`Cannot pass \"${fr(r)}\" as a ${this.name}`),r.$$.ptr||F(`Cannot pass deleted object as a pointer of type ${this.name}`),!this.isConst&&r.$$.ptrType.isConst&&F(`Cannot convert argument of type ${r.$$.smartPtrType?r.$$.smartPtrType.name:r.$$.ptrType.name} to parameter type ${this.name}`);var n=r.$$.ptrType.registeredClass;if(t=Le(r.$$.ptr,n,this.registeredClass),this.isSmartPointer)switch(r.$$.smartPtr===void 0&&F(\"Passing raw pointer to smart pointer is illegal\"),this.sharingPolicy){case 0:r.$$.smartPtrType===this?t=r.$$.smartPtr:F(`Cannot convert argument of type ${r.$$.smartPtrType?r.$$.smartPtrType.name:r.$$.ptrType.name} to parameter type ${this.name}`);break;case 1:t=r.$$.smartPtr;break;case 2:if(r.$$.smartPtrType===this)t=r.$$.smartPtr;else{var i=r.clone();t=this.rawShare(t,L.toHandle(()=>i.delete())),e!==null&&e.push(this.rawDestructor,t)}break;default:F(\"Unsupporting sharing policy\")}return t}function Mn(e,r){if(r===null)return this.isReference&&F(`null is not a valid ${this.name}`),0;r.$$||F(`Cannot pass \"${fr(r)}\" as a ${this.name}`),r.$$.ptr||F(`Cannot pass deleted object as a pointer of type ${this.name}`),r.$$.ptrType.isConst&&F(`Cannot convert argument of type ${r.$$.ptrType.name} to parameter type ${this.name}`);var t=r.$$.ptrType.registeredClass,n=Le(r.$$.ptr,t,this.registeredClass);return n}function We(e){return this.fromWireType(m[e>>2])}var Xr=(e,r,t)=>{if(r===t)return e;if(t.baseClass===void 0)return null;var n=Xr(e,r,t.baseClass);return n===null?null:t.downcast(n)},jn={},On=(e,r)=>{for(r===void 0&&F(\"ptr should not be undefined\");e.baseClass;)r=e.upcast(r),e=e.baseClass;return r},xn=(e,r)=>(r=On(e,r),jn[r]),Gn=class extends Error{constructor(r){super(r),this.name=\"InternalError\"}},Ue=e=>{throw new Gn(e)},Ve=(e,r)=>{(!r.ptrType||!r.ptr)&&Ue(\"makeClassHandle requires ptr and ptrType\");var t=!!r.smartPtrType,n=!!r.smartPtr;return t!==n&&Ue(\"Both smartPtrType and smartPtr must be specified\"),r.count={value:1},Ee(Object.create(e,{$$:{value:r,writable:!0}}))};function Nn(e){var r=this.getPointee(e);if(!r)return this.destructor(e),null;var t=xn(this.registeredClass,r);if(t!==void 0){if(t.$$.count.value===0)return t.$$.ptr=r,t.$$.smartPtr=e,t.clone();var n=t.clone();return this.destructor(e),n}function i(){return this.isSmartPointer?Ve(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:r,smartPtrType:this,smartPtr:e}):Ve(this.registeredClass.instancePrototype,{ptrType:this,ptr:e})}var a=this.registeredClass.getActualType(r),s=Hr[a];if(!s)return i.call(this);var c;this.isConst?c=s.constPointerType:c=s.pointerType;var u=Xr(r,this.registeredClass,c.registeredClass);return u===null?i.call(this):this.isSmartPointer?Ve(c.registeredClass.instancePrototype,{ptrType:c,ptr:u,smartPtrType:this,smartPtr:e}):Ve(c.registeredClass.instancePrototype,{ptrType:c,ptr:u})}var Bn=()=>{Object.assign(ze.prototype,{getPointee(e){return this.rawGetPointee&&(e=this.rawGetPointee(e)),e},destructor(e){this.rawDestructor?.(e)},readValueFromPointer:We,fromWireType:Nn})};function ze(e,r,t,n,i,a,s,c,u,f,d){this.name=e,this.registeredClass=r,this.isReference=t,this.isConst=n,this.isSmartPointer=i,this.pointeeType=a,this.sharingPolicy=s,this.rawGetPointee=c,this.rawConstructor=u,this.rawShare=f,this.rawDestructor=d,!i&&r.baseClass===void 0?n?(this.toWireType=Rn,this.destructorFunction=null):(this.toWireType=Mn,this.destructorFunction=null):this.toWireType=In}var Zr=(e,r,t)=>{l.hasOwnProperty(e)||Ue(\"Replacing nonexistent public symbol\"),l[e].overloadTable!==void 0&&t!==void 0?l[e].overloadTable[t]=r:(l[e]=r,l[e].argCount=t)},Kr=[],Yr,y=e=>{var r=Kr[e];return r||(Kr[e]=r=Yr.get(e)),r},te=(e,r,t=!1)=>{e=V(e);function n(){var a=y(r);return a}var i=n();return typeof i!=\"function\"&&F(`unknown function pointer with signature ${e}: ${r}`),i};class Ln extends Error{}var Jr=e=>{var r=gt(e),t=V(r);return J(r),t},ye=(e,r)=>{var t=[],n={};function i(a){if(!n[a]&&!le[a]){if(xe[a]){xe[a].forEach(i);return}t.push(a),n[a]=!0}}throw r.forEach(i),new Ln(`${e}: `+t.map(Jr).join([\", \"]))},oe=(e,r,t)=>{e.forEach(c=>xe[c]=r);function n(c){var u=t(c);u.length!==e.length&&Ue(\"Mismatched type converter count\");for(var f=0;f<e.length;++f)q(e[f],u[f])}var i=new Array(r.length),a=[],s=0;r.forEach((c,u)=>{le.hasOwnProperty(c)?i[u]=le[c]:(a.push(c),pe.hasOwnProperty(c)||(pe[c]=[]),pe[c].push(()=>{i[u]=le[c],++s,s===a.length&&n(i)}))}),a.length===0&&n(i)},Wn=(e,r,t,n,i,a,s,c,u,f,d,_,p)=>{d=V(d),a=te(i,a),c&&=te(s,c),f&&=te(u,f),p=te(_,p);var v=$n(d);lr(v,function(){ye(`Cannot construct ${d} due to unbound types`,[n])}),oe([e,r,t],n?[n]:[],h=>{h=h[0];var k,$;n?(k=h.registeredClass,$=k.instancePrototype):$=Ne.prototype;var T=Be(d,function(...I){if(Object.getPrototypeOf(this)!==x)throw new ke(`Use 'new' to construct ${d}`);if(P.constructor_body===void 0)throw new ke(`${d} has no accessible constructor`);var se=P.constructor_body[I.length];if(se===void 0)throw new ke(`Tried to invoke ctor of ${d} with invalid number of parameters (${I.length}) - expected (${Object.keys(P.constructor_body).toString()}) parameters instead!`);return se.apply(this,I)}),x=Object.create($,{constructor:{value:T}});T.prototype=x;var P=new Dn(d,T,x,p,k,a,c,f);P.baseClass&&(P.baseClass.__derivedClasses??=[],P.baseClass.__derivedClasses.push(P));var K=new ze(d,P,!0,!1,!1),z=new ze(d+\"*\",P,!1,!1,!1),S=new ze(d+\" const*\",P,!1,!0,!1);return Hr[e]={pointerType:z,constPointerType:S},Zr(v,T),[K,z,S]})},dr=(e,r)=>{for(var t=[],n=0;n<e;n++)t.push(m[r+n*4>>2]);return t},vr=e=>{for(;e.length;){var r=e.pop(),t=e.pop();t(r)}};function Qr(e){for(var r=1;r<e.length;++r)if(e[r]!==null&&e[r].destructorFunction===void 0)return!0;return!1}function Un(e,r,t,n){var i=Qr(e),a=e.length-2,s=[],c=[\"fn\"];r&&c.push(\"thisWired\");for(var u=0;u<a;++u)s.push(`arg${u}`),c.push(`arg${u}Wired`);s=s.join(\",\"),c=c.join(\",\");var f=`return function (${s}) {\n`;i&&(f+=`var destructors = [];\n`);var d=i?\"destructors\":\"null\",_=[\"humanName\",\"throwBindingError\",\"invoker\",\"fn\",\"runDestructors\",\"fromRetWire\",\"toClassParamWire\"];r&&(f+=`var thisWired = toClassParamWire(${d}, this);\n`);for(var u=0;u<a;++u){var p=`toArg${u}Wire`;f+=`var arg${u}Wired = ${p}(${d}, arg${u});\n`,_.push(p)}f+=(t||n?\"var rv = \":\"\")+`invoker(${c});\n`;var v=t?\"rv\":\"\";if(i)f+=`runDestructors(destructors);\n`;else for(var u=r?1:2;u<e.length;++u){var h=u===1?\"thisWired\":\"arg\"+(u-2)+\"Wired\";e[u].destructorFunction!==null&&(f+=`${h}_dtor(${h});\n`,_.push(`${h}_dtor`))}return t&&(f+=`var ret = fromRetWire(rv);\nreturn ret;\n`),f+=`}\n`,new Function(_,f)}function _r(e,r,t,n,i,a){var s=r.length;s<2&&F(\"argTypes array size mismatch! Must at least get return value and 'this' types!\");for(var c=r[1]!==null&&t!==null,u=Qr(r),f=!r[0].isVoid,d=s-2,_=r[0],p=r[1],v=[e,F,n,i,vr,_.fromWireType.bind(_),p?.toWireType.bind(p)],h=2;h<s;++h){var k=r[h];v.push(k.toWireType.bind(k))}if(!u)for(var h=c?1:2;h<r.length;++h)r[h].destructorFunction!==null&&v.push(r[h].destructorFunction);var T=Un(r,c,f,a)(...v);return Be(e,T)}var Vn=(e,r,t,n,i,a)=>{var s=dr(r,t);i=te(n,i);var c=[a],u=[];oe([],[e],f=>{f=f[0];var d=`constructor ${f.name}`;if(f.registeredClass.constructor_body===void 0&&(f.registeredClass.constructor_body=[]),f.registeredClass.constructor_body[r-1]!==void 0)throw new ke(`Cannot register multiple constructors with identical number of parameters (${r-1}) for class '${f.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`);return f.registeredClass.constructor_body[r-1]=()=>{ye(`Cannot construct ${f.name} due to unbound types`,s)},oe([],s,_=>(_.splice(1,0,null),f.registeredClass.constructor_body[r-1]=_r(d,_,null,i,a),[])),[]})},et=e=>{e=e.trim();const r=e.indexOf(\"(\");return r===-1?e:e.slice(0,r)},zn=(e,r,t,n,i,a,s,c,u,f)=>{var d=dr(t,n);r=V(r),r=et(r),a=te(i,a,u),oe([],[e],_=>{_=_[0];var p=`${_.name}.${r}`;r.startsWith(\"@@\")&&(r=Symbol[r.substring(2)]),c&&_.registeredClass.pureVirtualFunctions.push(r);function v(){ye(`Cannot call ${p} due to unbound types`,d)}var h=_.registeredClass.instancePrototype,k=h[r];return k===void 0||k.overloadTable===void 0&&k.className!==_.name&&k.argCount===t-2?(v.argCount=t-2,v.className=_.name,h[r]=v):(qr(h,r,p),h[r].overloadTable[t-2]=v),oe([],d,$=>{var T=_r(p,$,_,a,s,u);return h[r].overloadTable===void 0?(T.argCount=t-2,h[r]=T):h[r].overloadTable[t-2]=T,[]}),[]})},rt=(e,r,t)=>(e instanceof Object||F(`${t} with invalid \"this\": ${e}`),e instanceof r.registeredClass.constructor||F(`${t} incompatible with \"this\" of type ${e.constructor.name}`),e.$$.ptr||F(`cannot call emscripten binding method ${t} on deleted object`),Le(e.$$.ptr,e.$$.ptrType.registeredClass,r.registeredClass)),Hn=(e,r,t,n,i,a,s,c,u,f)=>{r=V(r),i=te(n,i),oe([],[e],d=>{d=d[0];var _=`${d.name}.${r}`,p={get(){ye(`Cannot access ${_} due to unbound types`,[t,s])},enumerable:!0,configurable:!0};return u?p.set=()=>ye(`Cannot access ${_} due to unbound types`,[t,s]):p.set=v=>F(_+\" is a read-only property\"),Object.defineProperty(d.registeredClass.instancePrototype,r,p),oe([],u?[t,s]:[t],v=>{var h=v[0],k={get(){var T=rt(this,d,_+\" getter\");return h.fromWireType(i(a,T))},enumerable:!0};if(u){u=te(c,u);var $=v[1];k.set=function(T){var x=rt(this,d,_+\" setter\"),P=[];u(f,x,$.toWireType(P,T)),vr(P)}}return Object.defineProperty(d.registeredClass.instancePrototype,r,k),[]}),[]})},tt=[],fe=[0,1,,1,null,1,!0,1,!1,1],hr=e=>{e>9&&--fe[e+1]===0&&(fe[e]=void 0,tt.push(e))},L={toValue:e=>(e||F(`Cannot use deleted val. handle = ${e}`),fe[e]),toHandle:e=>{switch(e){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:{const r=tt.pop()||fe.length;return fe[r]=e,fe[r+1]=1,r}}}},nt={name:\"emscripten::val\",fromWireType:e=>{var r=L.toValue(e);return hr(e),r},toWireType:(e,r)=>L.toHandle(r),readValueFromPointer:We,destructorFunction:null},qn=e=>q(e,nt),Xn=(e,r,t)=>{switch(r){case 1:return t?function(n){return this.fromWireType(G[n])}:function(n){return this.fromWireType(B[n])};case 2:return t?function(n){return this.fromWireType(A[n>>1])}:function(n){return this.fromWireType(ve[n>>1])};case 4:return t?function(n){return this.fromWireType(C[n>>2])}:function(n){return this.fromWireType(m[n>>2])};default:throw new TypeError(`invalid integer width (${r}): ${e}`)}},Zn=(e,r,t,n)=>{r=V(r);function i(){}i.values={},q(e,{name:r,constructor:i,fromWireType:function(a){return this.constructor.values[a]},toWireType:(a,s)=>s.value,readValueFromPointer:Xn(r,t,n),destructorFunction:null}),lr(r,i)},it=(e,r)=>{var t=le[e];return t===void 0&&F(`${r} has unknown type ${Jr(e)}`),t},Kn=(e,r,t)=>{var n=it(e,\"enum\");r=V(r);var i=n.constructor,a=Object.create(n.constructor.prototype,{value:{value:t},constructor:{value:Be(`${n.name}_${r}`,function(){})}});i.values[t]=a,i[r]=a},Yn=(e,r)=>{switch(r){case 4:return function(t){return this.fromWireType(De[t>>2])};case 8:return function(t){return this.fromWireType(Re[t>>3])};default:throw new TypeError(`invalid float width (${r}): ${e}`)}},Jn=(e,r,t)=>{r=V(r),q(e,{name:r,fromWireType:n=>n,toWireType:(n,i)=>i,readValueFromPointer:Yn(r,t),destructorFunction:null})},Qn=(e,r,t,n,i,a,s,c)=>{var u=dr(r,t);e=V(e),e=et(e),i=te(n,i,s),lr(e,function(){ye(`Cannot call ${e} due to unbound types`,u)},r-1),oe([],u,f=>{var d=[f[0],null].concat(f.slice(1));return Zr(e,_r(e,d,null,i,a,s),r-1),[]})},ei=(e,r,t,n,i)=>{r=V(r);const a=n===0;let s=u=>u;if(a){var c=32-8*t;s=u=>u<<c>>>c,i=s(i)}q(e,{name:r,fromWireType:s,toWireType:(u,f)=>f,readValueFromPointer:Wr(r,t,n!==0),destructorFunction:null})},ri=(e,r,t)=>{var n=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array],i=n[r];function a(s){var c=m[s>>2],u=m[s+4>>2];return new i(G.buffer,u,c)}t=V(t),q(e,{name:t,fromWireType:a,readValueFromPointer:a},{ignoreDuplicateRegistrations:!0})},ti=Object.assign({optional:!0},nt),ni=(e,r)=>{q(e,ti)},O=(e,r,t)=>Or(e,B,r,t),ii=(e,r)=>{r=V(r);var t=!0;q(e,{name:r,fromWireType(n){var i=m[n>>2],a=n+4,s;if(t)s=M(a,i,!0);else{s=\"\";for(var c=0;c<i;++c)s+=String.fromCharCode(B[a+c])}return J(n),s},toWireType(n,i){i instanceof ArrayBuffer&&(i=new Uint8Array(i));var a,s=typeof i==\"string\";s||ArrayBuffer.isView(i)&&i.BYTES_PER_ELEMENT==1||F(\"Cannot pass non-string to std::string\"),t&&s?a=Y(i):a=i.length;var c=Z(4+a+1),u=c+4;if(m[c>>2]=a,s)if(t)O(i,u,a+1);else for(var f=0;f<a;++f){var d=i.charCodeAt(f);d>255&&(J(c),F(\"String has UTF-16 code units that do not fit in 8 bits\")),B[u+f]=d}else B.set(i,u);return n!==null&&n.push(J,c),c},readValueFromPointer:We,destructorFunction(n){J(n)}})},at=typeof TextDecoder<\"u\"?new TextDecoder(\"utf-16le\"):void 0,ai=(e,r,t)=>{var n=e>>1,i=jr(ve,n,r/2,t);if(i-n>16&&at)return at.decode(ve.subarray(n,i));for(var a=\"\",s=n;s<i;++s){var c=ve[s];a+=String.fromCharCode(c)}return a},oi=(e,r,t)=>{if(t??=2147483647,t<2)return 0;t-=2;for(var n=r,i=t<e.length*2?t/2:e.length,a=0;a<i;++a){var s=e.charCodeAt(a);A[r>>1]=s,r+=2}return A[r>>1]=0,r-n},si=e=>e.length*2,ci=(e,r,t)=>{for(var n=\"\",i=e>>2,a=0;!(a>=r/4);a++){var s=m[i+a];if(!s&&!t)break;n+=String.fromCodePoint(s)}return n},ui=(e,r,t)=>{if(t??=2147483647,t<4)return 0;for(var n=r,i=n+t-4,a=0;a<e.length;++a){var s=e.codePointAt(a);if(s>65535&&a++,C[r>>2]=s,r+=4,r+4>i)break}return C[r>>2]=0,r-n},li=e=>{for(var r=0,t=0;t<e.length;++t){var n=e.codePointAt(t);n>65535&&t++,r+=4}return r},fi=(e,r,t)=>{t=V(t);var n,i,a;r===2?(n=ai,i=oi,a=si):(n=ci,i=ui,a=li),q(e,{name:t,fromWireType:s=>{var c=m[s>>2],u=n(s+4,c*r,!0);return J(s),u},toWireType:(s,c)=>{typeof c!=\"string\"&&F(`Cannot pass non-string to C++ string type ${t}`);var u=a(c),f=Z(4+u+r);return m[f>>2]=u/r,i(c,f+4,u+r),s!==null&&s.push(J,f),f},readValueFromPointer:We,destructorFunction(s){J(s)}})},di=(e,r)=>{r=V(r),q(e,{isVoid:!0,name:r,fromWireType:()=>{},toWireType:(t,n)=>{}})},ot=0,vi=()=>{rr=!1,ot=0},mr=[],_i=e=>{var r=mr.length;return mr.push(e),r},hi=(e,r)=>{for(var t=new Array(e),n=0;n<e;++n)t[n]=it(m[r+n*4>>2],`parameter ${n}`);return t},mi=(e,r,t)=>{var n=[],i=e(n,t);return n.length&&(m[r>>2]=L.toHandle(n)),i},pi={},pr=e=>{var r=pi[e];return r===void 0?V(e):r},yi=(e,r,t)=>{var n=8,[i,...a]=hi(e,r),s=i.toWireType.bind(i),c=a.map(v=>v.readValueFromPointer.bind(v));e--;var u={toValue:L.toValue},f=c.map((v,h)=>{var k=`argFromPtr${h}`;return u[k]=v,`${k}(args${h?\"+\"+h*n:\"\"})`}),d;switch(t){case 0:d=\"toValue(handle)\";break;case 2:d=\"new (toValue(handle))\";break;case 3:d=\"\";break;case 1:u.getStringOrSymbol=pr,d=\"toValue(handle)[getStringOrSymbol(methodName)]\";break}d+=`(${f})`,i.isVoid||(u.toReturnWire=s,u.emval_returnValue=mi,d=`return emval_returnValue(toReturnWire, destructorsRef, ${d})`),d=`return function (handle, methodName, destructorsRef, args) {\n ${d}\n }`;var _=new Function(Object.keys(u),d)(...Object.values(u)),p=`methodCaller<(${a.map(v=>v.name)}) => ${i.name}>`;return _i(Be(p,_))},st=()=>globalThis,gi=e=>e===0?L.toHandle(st()):(e=pr(e),L.toHandle(st()[e])),wi=(e,r)=>(e=L.toValue(e),r=L.toValue(r),L.toHandle(e[r])),bi=e=>{e>9&&(fe[e+1]+=1)},Si=(e,r,t,n,i)=>mr[e](r,t,n,i),ki=()=>L.toHandle([]),Ei=e=>L.toHandle(pr(e)),Ci=e=>{var r=L.toValue(e);vr(r),hr(e)},Ti=(e,r,t)=>{e=L.toValue(e),r=L.toValue(r),t=L.toValue(t),e[r]=t},Fi=9007199254740992,Pi=-9007199254740992,He=e=>e<Pi||e>Fi?NaN:Number(e);function Ai(e,r){e=He(e);var t=new Date(e*1e3);C[r>>2]=t.getUTCSeconds(),C[r+4>>2]=t.getUTCMinutes(),C[r+8>>2]=t.getUTCHours(),C[r+12>>2]=t.getUTCDate(),C[r+16>>2]=t.getUTCMonth(),C[r+20>>2]=t.getUTCFullYear()-1900,C[r+24>>2]=t.getUTCDay();var n=Date.UTC(t.getUTCFullYear(),0,1,0,0,0,0),i=(t.getTime()-n)/(1e3*60*60*24)|0;C[r+28>>2]=i}var $i=e=>e%4===0&&(e%100!==0||e%400===0),Di=[0,31,60,91,121,152,182,213,244,274,305,335],Ri=[0,31,59,90,120,151,181,212,243,273,304,334],Ii=e=>{var r=$i(e.getFullYear()),t=r?Di:Ri,n=t[e.getMonth()]+e.getDate()-1;return n};function Mi(e,r){e=He(e);var t=new Date(e*1e3);C[r>>2]=t.getSeconds(),C[r+4>>2]=t.getMinutes(),C[r+8>>2]=t.getHours(),C[r+12>>2]=t.getDate(),C[r+16>>2]=t.getMonth(),C[r+20>>2]=t.getFullYear()-1900,C[r+24>>2]=t.getDay();var n=Ii(t)|0;C[r+28>>2]=n,C[r+36>>2]=-(t.getTimezoneOffset()*60);var i=new Date(t.getFullYear(),0,1),a=new Date(t.getFullYear(),6,1).getTimezoneOffset(),s=i.getTimezoneOffset(),c=(a!=s&&t.getTimezoneOffset()==Math.min(s,a))|0;C[r+32>>2]=c}var Ce={},ct=e=>{if(e instanceof $r||e==\"unwind\")return Ae;Er(1,e)},ut=()=>rr||ot>0,lt=e=>{Ae=e,ut()||(l.onExit?.(e),Pe=!0),Er(e,new $r(e))},ji=(e,r)=>{Ae=e,lt(e)},Oi=ji,xi=()=>{if(!ut())try{Oi(Ae)}catch(e){ct(e)}},ft=e=>{if(!Pe)try{e(),xi()}catch(r){ct(r)}},yr=()=>performance.now(),Gi=(e,r)=>{if(Ce[e]&&(clearTimeout(Ce[e].id),delete Ce[e]),!r)return 0;var t=setTimeout(()=>{delete Ce[e],ft(()=>wt(e,yr()))},r);return Ce[e]={id:t,timeout_ms:r},0},Ni=(e,r,t,n)=>{var i=new Date().getFullYear(),a=new Date(i,0,1),s=new Date(i,6,1),c=a.getTimezoneOffset(),u=s.getTimezoneOffset(),f=Math.max(c,u);m[e>>2]=f*60,C[r>>2]=+(c!=u);var d=v=>{var h=v>=0?\"-\":\"+\",k=Math.abs(v),$=String(Math.floor(k/60)).padStart(2,\"0\"),T=String(k%60).padStart(2,\"0\");return`UTC${h}${$}${T}`},_=d(c),p=d(u);u<c?(O(_,t,17),O(p,n,17)):(O(_,n,17),O(p,t,17))},dt=()=>Date.now(),Bi=1,Li=e=>e>=0&&e<=3;function Wi(e,r,t){if(r=He(r),!Li(e))return 28;var n;if(e===0)n=dt();else if(Bi)n=yr();else return 52;var i=Math.round(n*1e3*1e3);return W[t>>3]=BigInt(i),0}var Ui=e=>{console.warn(M(e))},Vi=(e,r)=>ee(M(e,r));function zi(e){if(U.xhrs.has(e)){var r=U.xhrs.get(e);U.xhrs.free(e),r.readyState>0&&r.readyState<4&&r.abort()}}var vt=()=>2147483648,Hi=()=>vt(),qi=()=>!ge,Xi=(e,r)=>we(M(e,r)),Zi=(e,r)=>Math.ceil(e/r)*r,Ki=e=>{var r=$e.buffer.byteLength,t=(e-r+65535)/65536|0;try{return $e.grow(t),Ar(),1}catch{}},Yi=e=>{var r=B.length;e>>>=0;var t=vt();if(e>t)return!1;for(var n=1;n<=4;n*=2){var i=r*(1+.2/n);i=Math.min(i,e+100663296);var a=Math.min(t,Zi(Math.max(e,i),65536)),s=Ki(a);if(s)return!0}return!1};class Ji{allocated=[void 0];freelist=[];get(r){return this.allocated[r]}has(r){return this.allocated[r]!==void 0}allocate(r){var t=this.freelist.pop()||this.allocated.length;return this.allocated[t]=r,t}free(r){this.allocated[r]=void 0,this.freelist.push(r)}}var U={async openDatabase(e,r){return new Promise((t,n)=>{try{var i=indexedDB.open(e,r)}catch(a){return n(a)}i.onupgradeneeded=a=>{var s=a.target.result;s.objectStoreNames.contains(\"FILES\")&&s.deleteObjectStore(\"FILES\"),s.createObjectStore(\"FILES\")},i.onsuccess=a=>t(a.target.result),i.onerror=n})},async init(){U.xhrs=new Ji,Nr(\"library_fetch_init\");try{var e=await U.openDatabase(\"emscripten_filesystem\",1);U.dbInstance=e}catch{U.dbInstance=!1}finally{Gr(\"library_fetch_init\")}}};function gr(e,r,t,n,i){var a=m[e+8>>2];if(!a){t(e,\"no url specified!\");return}var s=M(a),c=e+108,u=M(c+0);u||=\"GET\";var f=m[c+56>>2],d=m[c+68>>2],_=m[c+72>>2],p=m[c+76>>2],v=m[c+80>>2],h=m[c+84>>2],k=m[c+88>>2],$=m[c+52>>2],T=!!($&1),x=!!($&2),P=!!($&64),K=d?M(d):void 0,z=_?M(_):void 0,S=new XMLHttpRequest;if(S.withCredentials=!!B[c+60],S.open(u,s,!P,K,z),P||(S.timeout=f),S.url_=s,S.responseType=\"arraybuffer\",v){var I=M(v);S.overrideMimeType(I)}if(p)for(;;){var se=m[p>>2];if(!se)break;var Xe=m[p+4>>2];if(!Xe)break;p+=8;var N=M(se),ne=M(Xe);S.setRequestHeader(N,ne)}var Q=U.xhrs.allocate(S);m[e>>2]=Q;var br=h&&k?B.slice(h,h+k):null;function Ze(){var j=0,H=0;S.response&&T&&m[e+12>>2]===0&&(H=S.response.byteLength),H>0&&(j=Z(H),B.set(new Uint8Array(S.response),j)),m[e+12>>2]=j,X(e+16,H),X(e+24,0);var ie=S.response?S.response.byteLength:0;if(ie&&X(e+32,ie),A[e+40>>1]=S.readyState,A[e+42>>1]=S.status,S.statusText&&O(S.statusText,e+44,64),P){var Ke=_t(S.responseURL);m[e+200>>2]=Ke}}S.onload=j=>{U.xhrs.has(Q)&&(Ze(),S.status>=200&&S.status<300?r(e,S,j):t(e,j))},S.onerror=j=>{U.xhrs.has(Q)&&(Ze(),t(e,j))},S.ontimeout=j=>{U.xhrs.has(Q)&&t(e,j)},S.onprogress=j=>{if(U.xhrs.has(Q)){var H=T&&x&&S.response?S.response.byteLength:0,ie=0;H>0&&T&&x&&(ie=Z(H),B.set(new Uint8Array(S.response),ie)),m[e+12>>2]=ie,X(e+16,H),X(e+24,j.loaded-H),X(e+32,j.total),A[e+40>>1]=S.readyState;var Ke=S.status;S.readyState>=3&&S.status===0&&j.loaded>0&&(Ke=200),A[e+42>>1]=Ke,S.statusText&&O(S.statusText,e+44,64),n(e,j),J(ie)}},S.onreadystatechange=j=>{if(U.xhrs.has(Q)){if(A[e+40>>1]=S.readyState,S.readyState>=2&&(A[e+42>>1]=S.status),!P&&S.readyState===2&&S.responseURL.length>0){var H=_t(S.responseURL);m[e+200>>2]=H}i(e,j)}};try{S.send(br)}catch(j){t(e,j)}}var X=(e,r)=>{m[e>>2]=r;var t=m[e>>2];m[e+4>>2]=(r-t)/4294967296},_t=e=>{var r=Y(e)+1,t=Z(r);return t&&O(e,t,r),t};function ht(e,r,t,n,i){if(!e){i(r,0,\"IndexedDB not available!\");return}var a=r+108,s=m[a+64>>2];s||=m[r+8>>2];var c=M(s);try{var u=e.transaction([\"FILES\"],\"readwrite\"),f=u.objectStore(\"FILES\"),d=f.put(t,c);d.onsuccess=_=>{A[r+40>>1]=4,A[r+42>>1]=200,O(\"OK\",r+44,64),n(r,0,c)},d.onerror=_=>{A[r+40>>1]=4,A[r+42>>1]=413,O(\"Payload Too Large\",r+44,64),i(r,0,_)}}catch(_){i(r,0,_)}}function Qi(e,r,t,n){if(!e){n(r,0,\"IndexedDB not available!\");return}var i=r+108,a=m[i+64>>2];a||=m[r+8>>2];var s=M(a);try{var c=e.transaction([\"FILES\"],\"readonly\"),u=c.objectStore(\"FILES\"),f=u.get(s);f.onsuccess=d=>{if(d.target.result){var _=d.target.result,p=_.byteLength||_.length,v=Z(p);B.set(new Uint8Array(_),v),m[r+12>>2]=v,X(r+16,p),X(r+24,0),X(r+32,p),A[r+40>>1]=4,A[r+42>>1]=200,O(\"OK\",r+44,64),t(r,0,_)}else A[r+40>>1]=4,A[r+42>>1]=404,O(\"Not Found\",r+44,64),n(r,0,\"no data\")},f.onerror=d=>{A[r+40>>1]=4,A[r+42>>1]=404,O(\"Not Found\",r+44,64),n(r,0,d)}}catch(d){n(r,0,d)}}function ea(e,r,t,n){if(!e){n(r,0,\"IndexedDB not available!\");return}var i=r+108,a=m[i+64>>2];a||=m[r+8>>2];var s=M(a);try{var c=e.transaction([\"FILES\"],\"readwrite\"),u=c.objectStore(\"FILES\"),f=u.delete(s);f.onsuccess=d=>{var _=d.target.result;m[r+12>>2]=0,X(r+16,0),X(r+24,0),X(r+32,0),A[r+40>>1]=4,A[r+42>>1]=200,O(\"OK\",r+44,64),t(r,0,_)},f.onerror=d=>{A[r+40>>1]=4,A[r+42>>1]=404,O(\"Not Found\",r+44,64),n(r,0,d)}}catch(d){n(r,0,d)}}function ra(e,r,t,n,i){var a=e+108,s=m[a+36>>2],c=m[a+40>>2],u=m[a+44>>2],f=m[a+48>>2],d=m[a+52>>2],_=!!(d&64);function p(N){_?N():ft(N)}var v=(N,ne,Q)=>{p(()=>{s?y(s)(N):r?.(N)})},h=(N,ne)=>{p(()=>{u?y(u)(N):n?.(N)})},k=(N,ne)=>{p(()=>{c?y(c)(N):t?.(N)})},$=(N,ne)=>{p(()=>{f?y(f)(N):i?.(N)})},T=(N,ne,Q)=>{gr(N,v,k,h,$)},x=(N,ne,Q)=>{var br=(j,H,ie)=>{p(()=>{s?y(s)(j):r?.(j)})},Ze=(j,H,ie)=>{p(()=>{s?y(s)(j):r?.(j)})};ht(U.dbInstance,N,ne.response,br,Ze)},P=(N,ne,Q)=>{gr(N,x,k,h,$)},K=M(a+0),z=!!(d&16),S=!!(d&4),I=!!(d&32);if(K===\"EM_IDB_STORE\"){var se=m[a+84>>2],Xe=m[a+88>>2];ht(U.dbInstance,e,B.slice(se,se+Xe),v,k)}else if(K===\"EM_IDB_DELETE\")ea(U.dbInstance,e,v,k);else if(!z)Qi(U.dbInstance,e,v,I?k:S?P:T);else if(!I)gr(e,S?x:v,k,h,$);else return 0;return e}var qe={},ta=()=>kr||\"./this.program\",Te=()=>{if(!Te.strings){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,_:ta()};for(var t in qe)qe[t]===void 0?delete r[t]:r[t]=qe[t];var n=[];for(var t in r)n.push(`${t}=${r[t]}`);Te.strings=n}return Te.strings},na=(e,r)=>{var t=0,n=0;for(var i of Te()){var a=r+t;m[e+n>>2]=a,t+=O(i,a,1/0)+1,n+=4}return 0},ia=(e,r)=>{var t=Te();m[e>>2]=t.length;var n=0;for(var i of t)n+=Y(i)+1;return m[r>>2]=n,0};function aa(e){try{var r=R.getStreamFromFD(e);return o.close(r),0}catch(t){if(typeof o>\"u\"||t.name!==\"ErrnoError\")throw t;return t.errno}}function oa(e,r){try{var t=0,n=0,i=0,a=R.getStreamFromFD(e),s=a.tty?2:o.isDir(a.mode)?3:o.isLink(a.mode)?7:4;return G[r]=s,A[r+2>>1]=i,W[r+8>>3]=BigInt(t),W[r+16>>3]=BigInt(n),0}catch(c){if(typeof o>\"u\"||c.name!==\"ErrnoError\")throw c;return c.errno}}var sa=(e,r,t,n)=>{for(var i=0,a=0;a<t;a++){var s=m[r>>2],c=m[r+4>>2];r+=8;var u=o.read(e,G,s,c,n);if(u<0)return-1;if(i+=u,u<c)break;typeof n<\"u\"&&(n+=u)}return i};function ca(e,r,t,n){try{var i=R.getStreamFromFD(e),a=sa(i,r,t);return m[n>>2]=a,0}catch(s){if(typeof o>\"u\"||s.name!==\"ErrnoError\")throw s;return s.errno}}function ua(e,r,t,n){r=He(r);try{if(isNaN(r))return 61;var i=R.getStreamFromFD(e);return o.llseek(i,r,t),W[n>>3]=BigInt(i.position),i.getdents&&r===0&&t===0&&(i.getdents=null),0}catch(a){if(typeof o>\"u\"||a.name!==\"ErrnoError\")throw a;return a.errno}}var la=(e,r,t,n)=>{for(var i=0,a=0;a<t;a++){var s=m[r>>2],c=m[r+4>>2];r+=8;var u=o.write(e,G,s,c,n);if(u<0)return-1;if(i+=u,u<c)break;typeof n<\"u\"&&(n+=u)}return i};function fa(e,r,t,n){try{var i=R.getStreamFromFD(e),a=la(i,r,t);return m[n>>2]=a,0}catch(s){if(typeof o>\"u\"||s.name!==\"ErrnoError\")throw s;return s.errno}}var da=e=>e;function va(e,r){try{return ir(B.subarray(e,e+r)),0}catch(t){if(typeof o>\"u\"||t.name!==\"ErrnoError\")throw t;return t.errno}}var _c=e=>(e>>>=0,\"0x\"+e.toString(16).padStart(8,\"0\")),mt=e=>{var r=l[\"_\"+e];return r},_a=(e,r)=>{G.set(e,r)},pt=e=>kt(e),ha=e=>{var r=Y(e)+1,t=pt(r);return O(e,t,r),t},yt=(e,r,t,n,i)=>{var a={string:h=>{var k=0;return h!=null&&h!==0&&(k=ha(h)),k},array:h=>{var k=pt(h.length);return _a(h,k),k}};function s(h){return r===\"string\"?M(h):r===\"boolean\"?!!h:h}var c=mt(e),u=[],f=0;if(n)for(var d=0;d<n.length;d++){var _=a[t[d]];_?(f===0&&(f=b()),u[d]=_(n[d])):u[d]=n[d]}var p=c(...u);function v(h){return f!==0&&w(f),s(h)}return p=v(p),p},ma=(e,r,t,n)=>{var i=!t||t.every(s=>s===\"number\"||s===\"boolean\"),a=r!==\"string\";return a&&i&&!n?mt(e):(...s)=>yt(e,r,t,s,n)};if(o.createPreloadedFile=ln,o.preloadFile=Lr,o.staticInit(),Fn(),Bn(),U.init(),l.noExitRuntime&&(rr=l.noExitRuntime),l.preloadPlugins&&(Br=l.preloadPlugins),l.print&&(we=l.print),l.printErr&&(ee=l.printErr),l.wasmBinary&&(be=l.wasmBinary),l.arguments&&(Rt=l.arguments),l.thisProgram&&(kr=l.thisProgram),l.preInit)for(typeof l.preInit==\"function\"&&(l.preInit=[l.preInit]);l.preInit.length>0;)l.preInit.shift()();l.ENV=qe,l.ccall=yt,l.cwrap=ma,l.lengthBytesUTF8=Y,l.stringToUTF8=O;function pa(e){if(typeof l.locateFile==\"function\")try{const r=l.locateFile(M(e));if(r){const t=Y(r)+1,n=Z(t);if(n)return O(r,n,t),n}}catch(r){console.warn(\"Module.locateFile failed:\",r)}return 0}function ya(e){try{if(typeof l<\"u\"&&l.workerUrl){var r=l.workerUrl,t=Y(r)+1,n=Z(t);return O(r,n,t),n}}catch(i){console.warn(\"Failed to read Module.workerUrl:\",i)}if(e){var t=Y(M(e))+1,n=Z(t);return O(M(e),n,t),n}return 0}function ga(){return navigator.hardwareConcurrency||1}function wa(e){l._aquaLiveTransports||(l._aquaLiveTransports=new Set),l._aquaLiveTransports.add(e),queueMicrotask(function(){l._aquaLiveTransports&&l._aquaLiveTransports.has(e)&&l._aquaDrainDeferredCompletions(e)})}function ba(e){l._aquaLiveTransports&&l._aquaLiveTransports.delete(e)}function Sa(e,r){if(!l.createDeserializeWorker)return console.error(\"createDeserializeWorker not available - worker-bridge.ts not loaded\"),0;const t=M(e);return l.createDeserializeWorker(t,l,r)?1:0}function ka(e,r,t,n,i){if(!l.submitToWorker)return console.error(\"submitToWorker not available - worker-bridge.ts not loaded\"),0;try{const a=t,s=n,c=new ArrayBuffer(s);return new Uint8Array(c).set(l.HEAPU8.subarray(a,a+s)),l.submitToWorker(e,r,c,i)?1:0}catch(a){return console.error(\"submitToWorker failed:\",a),0}}function Ea(e,r){l.cancelRequest&&l.cancelRequest(e,r)}function hc(){return l.isWorkerReady&&l.isWorkerReady()?1:0}function Ca(){l.terminateWorker&&l.terminateWorker()}function Ta(e,r){typeof globalThis.Sentry<\"u\"&&typeof globalThis.Sentry.captureException==\"function\"&&globalThis.Sentry.captureException(new Error(M(e,r)))}function Fa(e){const r=M(e);try{const t=new URL(r)}catch{return 0}return 1}function Pa(e,r){const t=M(e);let n;try{n=new URL(t)}catch(c){return console.error(`Failed to parse URL ${t} due to error : ${c}`),0}function i(c){return c>>>0}function a(c){const u=Y(c)+1,f=Z(u);return O(c,f,u),i(f)}let s=i(r)>>2;return m[s]=a(n.origin),m[s+1]=a(n.pathname.substring(1)),m[s+2]=a(n.search.substring(1)),m[s+3]=a(n.hash.substring(1)),1}function Aa(e){const r=M(e),t=encodeURIComponent(r),n=Y(t)+1,i=Z(n);return O(t,i,n),i>>>0}function $a(e){l.__mirisPrivatePromiseTracker||(l.__mirisPrivatePromiseTracker=new Map);let r,t;const n=new Promise(function(i,a){r=i,t=a});return l.__mirisPrivatePromiseTracker.set(e,{resolve:r,reject:t}),L.toHandle(n)}function Da(e,r){const t=l.__mirisPrivatePromiseTracker;if(!t||!t.has(e)){console.error(\"[miris] No resolver for tracked promise ID:\",e);return}const{resolve:n}=t.get(e);if(!n){console.error(\"[miris] No resolver for tracked promise ID:\",e);return}t.delete(e),n(L.toValue(r))}function mc(e,r){const t=l.__mirisPrivatePromiseTracker;if(!t||!t.has(e)){console.error(\"[miris] No rejector for tracked promise ID:\",e);return}const{reject:n}=t.get(e);if(!n){console.error(\"[miris] No rejector for tracked promise ID:\",e);return}t.delete(e),n(L.toValue(r))}var gt,Ra,Ia,Ma,ja,Oa,xa,Ga,Na,Ba,La,Wa,Ua,Va,za,Ha,qa,Xa,Za,Ka,Ya,Ja,Qa,eo,ro,to,no,io,ao,oo,so,co,uo,lo,fo,vo,_o,ho,mo,po,yo,go,wo,bo,So,ko,Eo,Co,To,Fo,Po,Ao,$o,Do,Ro,Io,Mo,jo,Oo,xo,Go,No,Bo,Lo,Wo,Uo,Vo,zo,Ho,qo,Xo,Zo,Ko,Yo,Jo,Qo,es,rs,ts,Z,J,ns,is,wt,g,bt,St,kt,Et,Ct,Tt,Ft,Pt;function as(e){gt=e.__getTypeName,l._CreateAquaContext=Ra=e.CreateAquaContext,l._BeginFrame=Ia=e.BeginFrame,l._DestroyAquaContext=Ma=e.DestroyAquaContext,l._SetMaxRequestCacheSize=ja=e.SetMaxRequestCacheSize,l._TriggerTestError=Oa=e.TriggerTestError,l._CreateClientForContext=xa=e.CreateClientForContext,l._CreateClient=Ga=e.CreateClient,l._DestroyClient=Na=e.DestroyClient,l._ClearScene=Ba=e.ClearScene,l._WaitForSceneExecution=La=e.WaitForSceneExecution,l._SetPersistentDataDirectory=Wa=e.SetPersistentDataDirectory,l._SetClientSpatialFormat=Ua=e.SetClientSpatialFormat,l._SetAssetViewerKey=Va=e.SetAssetViewerKey,l._PrefetchContent=za=e.PrefetchContent,l._PrintSceneObjectHierarchy=Ha=e.PrintSceneObjectHierarchy,l._CancelAllSceneExecution=qa=e.CancelAllSceneExecution,l._AddStream=Xa=e.AddStream,l._AddStreamById=Za=e.AddStreamById,l._RemoveStream=Ka=e.RemoveStream,l._UpdateSceneExecution=Ya=e.UpdateSceneExecution,l._RecordFrameTime=Ja=e.RecordFrameTime,l._TakeRenderRequired=Qa=e.TakeRenderRequired,l._LockScene=eo=e.LockScene,l._UnlockScene=ro=e.UnlockScene,l._SetMainCameraTransform=to=e.SetMainCameraTransform,l._SetMainCameraViewFrustum=no=e.SetMainCameraViewFrustum,l._SetSceneObjectTransform=io=e.SetSceneObjectTransform,l._SetRuntimeSettings=ao=e.SetRuntimeSettings,l._SetOctreeSolverMode=oo=e.SetOctreeSolverMode,l._SetOctreeDepthFavor=so=e.SetOctreeDepthFavor,l._SetBudgetControllerType=co=e.SetBudgetControllerType,l._SetMaxCacheSize=uo=e.SetMaxCacheSize,l._SetPreferSharkEncodingProfiles=lo=e.SetPreferSharkEncodingProfiles,l._HasFeature=fo=e.HasFeature,l._GetFeatureVersion=vo=e.GetFeatureVersion,l._GetFeatureState=_o=e.GetFeatureState,l._GetAssetFormatVersion=ho=e.GetAssetFormatVersion,l._GetSceneChangesCounts=mo=e.GetSceneChangesCounts,l._GetSceneChanges=po=e.GetSceneChanges,l._GetSceneRootObjectId=yo=e.GetSceneRootObjectId,l._GetSceneObjectChildrenCount=go=e.GetSceneObjectChildrenCount,l._GetSceneObjectChildren=wo=e.GetSceneObjectChildren,l._GetSceneObjectType=bo=e.GetSceneObjectType,l._GetDrawnOctantMask=So=e.GetDrawnOctantMask,l._LogOctreeStats=ko=e.LogOctreeStats,l._GetSceneObjectParent=Eo=e.GetSceneObjectParent,l._IsSceneObjectAncestorOf=Co=e.IsSceneObjectAncestorOf,l._GetSceneObjectName=To=e.GetSceneObjectName,l._GetAttributeCount=Fo=e.GetAttributeCount,l._HasAttribute=Po=e.HasAttribute,l._GetMosaicDescriptors=Ao=e.GetMosaicDescriptors,l._GetEccLutData=$o=e.GetEccLutData,l._GetAttribute=Do=e.GetAttribute,l._TakeAttribute=Ro=e.TakeAttribute,l._GetBufferHash=Io=e.GetBufferHash,l._GetWorldBoundingBox=Mo=e.GetWorldBoundingBox,l._GetLocalBoundingBox=jo=e.GetLocalBoundingBox,l._MirisGetLocalTransform=Oo=e.MirisGetLocalTransform,l._MirisGetWorldTransform=xo=e.MirisGetWorldTransform,l._MirisGetTransformRelativeToAncestor=Go=e.MirisGetTransformRelativeToAncestor,l._GetBoundingBoxRelativeToAncestor=No=e.GetBoundingBoxRelativeToAncestor,l._GetMetadata=Bo=e.GetMetadata,l._GetLodIndex=Lo=e.GetLodIndex,l._GetLibAquaVersion=Wo=e.GetLibAquaVersion,l._GetLodMinMaxIndices=Uo=e.GetLodMinMaxIndices,l._GetCameraCount=Vo=e.GetCameraCount,l._GetCameraIds=zo=e.GetCameraIds,l._GetDefaultCameraId=Ho=e.GetDefaultCameraId,l._GetViewingVolumeId=qo=e.GetViewingVolumeId,l._GetSceneMetadata=Xo=e.GetSceneMetadata,l._GetSceneOperatorCount=Zo=e.GetSceneOperatorCount,l._SetVariantSelection=Ko=e.SetVariantSelection,l.__Z26GetSceneObjectNameAsStringP10AquaClienti=Yo=e._Z26GetSceneObjectNameAsStringP10AquaClienti,l.__Z14GetAssetsAsyncP10AquaClientRKNSt3__26vectorINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS6_IS8_EEEEiPN4aqua6v0_0_013ArrayCallbackINSE_9AssetInfoEEE=Jo=e._Z14GetAssetsAsyncP10AquaClientRKNSt3__26vectorINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS6_IS8_EEEEiPN4aqua6v0_0_013ArrayCallbackINSE_9AssetInfoEEE,l.__Z21GetAvailableTagsAsyncP10AquaClientPN4aqua6v0_0_013ArrayCallbackINSt3__212basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEEEE=Qo=e._Z21GetAvailableTagsAsyncP10AquaClientPN4aqua6v0_0_013ArrayCallbackINSt3__212basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEEEE,l.__Z33TakeEvictedClientSideAttributeIdsP10AquaClient=es=e._Z33TakeEvictedClientSideAttributeIdsP10AquaClient,l.__Z30GetActiveClientSideIdsCheckSumv=rs=e._Z30GetActiveClientSideIdsCheckSumv,ts=e.__cxa_free_exception,l._malloc=Z=e.malloc,l._free=J=e.free,l._aquaDrainDeferredCompletions=ns=e.aquaDrainDeferredCompletions,l._onWorkerResult=is=e.onWorkerResult,wt=e._emscripten_timeout,g=e.setThrew,bt=e._emscripten_tempret_set,St=e._emscripten_stack_restore,kt=e._emscripten_stack_alloc,Et=e.emscripten_stack_get_current,Ct=e.__cxa_decrement_exception_refcount,Tt=e.__cxa_increment_exception_refcount,Ft=e.__cxa_can_catch,Pt=e.__cxa_get_exception_ptr}var At={__cxa_begin_catch:qt,__cxa_end_catch:Xt,__cxa_find_matching_catch_2:Zt,__cxa_find_matching_catch_3:Kt,__cxa_find_matching_catch_4:Yt,__cxa_rethrow:Jt,__cxa_throw:Qt,__cxa_uncaught_exceptions:en,__resumeException:rn,__syscall_fcntl64:fn,__syscall_fstat64:dn,__syscall_ioctl:vn,__syscall_lstat64:_n,__syscall_newfstatat:hn,__syscall_openat:mn,__syscall_rmdir:pn,__syscall_stat64:yn,__syscall_unlinkat:gn,_abort_js:wn,_embind_register_bigint:Sn,_embind_register_bool:kn,_embind_register_class:Wn,_embind_register_class_constructor:Vn,_embind_register_class_function:zn,_embind_register_class_property:Hn,_embind_register_emval:qn,_embind_register_enum:Zn,_embind_register_enum_value:Kn,_embind_register_float:Jn,_embind_register_function:Qn,_embind_register_integer:ei,_embind_register_memory_view:ri,_embind_register_optional:ni,_embind_register_std_string:ii,_embind_register_std_wstring:fi,_embind_register_void:di,_emscripten_runtime_keepalive_clear:vi,_emval_create_invoker:yi,_emval_decref:hr,_emval_get_global:gi,_emval_get_property:wi,_emval_incref:bi,_emval_invoke:Si,_emval_new_array:ki,_emval_new_cstring:Ei,_emval_run_destructors:Ci,_emval_set_property:Ti,_gmtime_js:Ai,_localtime_js:Mi,_setitimer_js:Gi,_tzset_js:Ni,clock_time_get:Wi,emjsCreateTrackedPromise:$a,emjsEncodeUriComponent:Aa,emjsGetPartsFromUrl:Pa,emjsIsValidUrl:Fa,emjsResolveTrackedPromise:Da,emjsSentryCaptureException:Ta,emscripten_console_warn:Ui,emscripten_date_now:dt,emscripten_errn:Vi,emscripten_fetch_free:zi,emscripten_get_heap_max:Hi,emscripten_get_now:yr,emscripten_is_main_browser_thread:qi,emscripten_outn:Xi,emscripten_resize_heap:Yi,emscripten_start_fetch:ra,environ_get:na,environ_sizes_get:ia,fd_close:aa,fd_fdstat_get:oa,fd_read:ca,fd_seek:ua,fd_write:fa,getHardwareConcurrency:ga,getWorkerUrlFromModule:ya,impl_cancelRequest:Ea,impl_createDeserializeWorker:Sa,impl_submitToWorker:ka,impl_terminateWorker:Ca,invoke_diii:Qs,invoke_djj:Ls,invoke_fi:$s,invoke_fiii:Js,invoke_i:ms,invoke_ii:ss,invoke_iii:vs,invoke_iiii:Ss,invoke_iiiid:ec,invoke_iiiii:hs,invoke_iiiiid:Ks,invoke_iiiiii:ws,invoke_iiiiiii:zs,invoke_iiiiiiii:Ms,invoke_iiiiiiiii:Os,invoke_iiiiiiiiii:Ps,invoke_iiiiiiiiiii:ps,invoke_iiiiiiiiiiii:Fs,invoke_iiiiij:oc,invoke_iiiiijj:rc,invoke_iiiij:Gs,invoke_iiiijj:tc,invoke_iiij:ac,invoke_iij:gs,invoke_iiji:qs,invoke_iijiiii:bs,invoke_j:Rs,invoke_jii:Es,invoke_jiiii:Ys,invoke_v:_s,invoke_vi:cs,invoke_viddi:Ns,invoke_vif:Vs,invoke_vii:ls,invoke_viif:sc,invoke_viii:us,invoke_viiifi:Us,invoke_viiii:os,invoke_viiiiddi:Ws,invoke_viiiii:ds,invoke_viiiiii:fs,invoke_viiiiiii:Ts,invoke_viiiiiiii:Ds,invoke_viiiiiiiiii:nc,invoke_viiiiiiiiiii:ys,invoke_viiiiiiiiiiiiiii:ic,invoke_viiiij:xs,invoke_viiij:js,invoke_viij:Bs,invoke_viiji:Cs,invoke_viijii:As,invoke_viijiii:Hs,invoke_vij:Zs,invoke_viji:Xs,invoke_vijii:Is,invoke_vijiiii:ks,llvm_eh_typeid_for:da,proc_exit:lt,random_get:va,scheduleMicrotaskDrain:wa,tryLocateWorkerFile:pa,unregisterTransportInstance:ba};function os(e,r,t,n,i){var a=b();try{y(e)(r,t,n,i)}catch(s){if(w(a),s!==s+0)throw s;g(1,0)}}function ss(e,r){var t=b();try{return y(e)(r)}catch(n){if(w(t),n!==n+0)throw n;g(1,0)}}function cs(e,r){var t=b();try{y(e)(r)}catch(n){if(w(t),n!==n+0)throw n;g(1,0)}}function us(e,r,t,n){var i=b();try{y(e)(r,t,n)}catch(a){if(w(i),a!==a+0)throw a;g(1,0)}}function ls(e,r,t){var n=b();try{y(e)(r,t)}catch(i){if(w(n),i!==i+0)throw i;g(1,0)}}function fs(e,r,t,n,i,a,s){var c=b();try{y(e)(r,t,n,i,a,s)}catch(u){if(w(c),u!==u+0)throw u;g(1,0)}}function ds(e,r,t,n,i,a){var s=b();try{y(e)(r,t,n,i,a)}catch(c){if(w(s),c!==c+0)throw c;g(1,0)}}function vs(e,r,t){var n=b();try{return y(e)(r,t)}catch(i){if(w(n),i!==i+0)throw i;g(1,0)}}function _s(e){var r=b();try{y(e)()}catch(t){if(w(r),t!==t+0)throw t;g(1,0)}}function hs(e,r,t,n,i){var a=b();try{return y(e)(r,t,n,i)}catch(s){if(w(a),s!==s+0)throw s;g(1,0)}}function ms(e){var r=b();try{return y(e)()}catch(t){if(w(r),t!==t+0)throw t;g(1,0)}}function ps(e,r,t,n,i,a,s,c,u,f,d){var _=b();try{return y(e)(r,t,n,i,a,s,c,u,f,d)}catch(p){if(w(_),p!==p+0)throw p;g(1,0)}}function ys(e,r,t,n,i,a,s,c,u,f,d,_){var p=b();try{y(e)(r,t,n,i,a,s,c,u,f,d,_)}catch(v){if(w(p),v!==v+0)throw v;g(1,0)}}function gs(e,r,t){var n=b();try{return y(e)(r,t)}catch(i){if(w(n),i!==i+0)throw i;g(1,0)}}function ws(e,r,t,n,i,a){var s=b();try{return y(e)(r,t,n,i,a)}catch(c){if(w(s),c!==c+0)throw c;g(1,0)}}function bs(e,r,t,n,i,a,s){var c=b();try{return y(e)(r,t,n,i,a,s)}catch(u){if(w(c),u!==u+0)throw u;g(1,0)}}function Ss(e,r,t,n){var i=b();try{return y(e)(r,t,n)}catch(a){if(w(i),a!==a+0)throw a;g(1,0)}}function ks(e,r,t,n,i,a,s){var c=b();try{y(e)(r,t,n,i,a,s)}catch(u){if(w(c),u!==u+0)throw u;g(1,0)}}function Es(e,r,t){var n=b();try{return y(e)(r,t)}catch(i){if(w(n),i!==i+0)throw i;return g(1,0),0n}}function Cs(e,r,t,n,i){var a=b();try{y(e)(r,t,n,i)}catch(s){if(w(a),s!==s+0)throw s;g(1,0)}}function Ts(e,r,t,n,i,a,s,c){var u=b();try{y(e)(r,t,n,i,a,s,c)}catch(f){if(w(u),f!==f+0)throw f;g(1,0)}}function Fs(e,r,t,n,i,a,s,c,u,f,d,_){var p=b();try{return y(e)(r,t,n,i,a,s,c,u,f,d,_)}catch(v){if(w(p),v!==v+0)throw v;g(1,0)}}function Ps(e,r,t,n,i,a,s,c,u,f){var d=b();try{return y(e)(r,t,n,i,a,s,c,u,f)}catch(_){if(w(d),_!==_+0)throw _;g(1,0)}}function As(e,r,t,n,i,a){var s=b();try{y(e)(r,t,n,i,a)}catch(c){if(w(s),c!==c+0)throw c;g(1,0)}}function $s(e,r){var t=b();try{return y(e)(r)}catch(n){if(w(t),n!==n+0)throw n;g(1,0)}}function Ds(e,r,t,n,i,a,s,c,u){var f=b();try{y(e)(r,t,n,i,a,s,c,u)}catch(d){if(w(f),d!==d+0)throw d;g(1,0)}}function Rs(e){var r=b();try{return y(e)()}catch(t){if(w(r),t!==t+0)throw t;return g(1,0),0n}}function Is(e,r,t,n,i){var a=b();try{y(e)(r,t,n,i)}catch(s){if(w(a),s!==s+0)throw s;g(1,0)}}function Ms(e,r,t,n,i,a,s,c){var u=b();try{return y(e)(r,t,n,i,a,s,c)}catch(f){if(w(u),f!==f+0)throw f;g(1,0)}}function js(e,r,t,n,i){var a=b();try{y(e)(r,t,n,i)}catch(s){if(w(a),s!==s+0)throw s;g(1,0)}}function Os(e,r,t,n,i,a,s,c,u){var f=b();try{return y(e)(r,t,n,i,a,s,c,u)}catch(d){if(w(f),d!==d+0)throw d;g(1,0)}}function xs(e,r,t,n,i,a){var s=b();try{y(e)(r,t,n,i,a)}catch(c){if(w(s),c!==c+0)throw c;g(1,0)}}function Gs(e,r,t,n,i){var a=b();try{return y(e)(r,t,n,i)}catch(s){if(w(a),s!==s+0)throw s;g(1,0)}}function Ns(e,r,t,n,i){var a=b();try{y(e)(r,t,n,i)}catch(s){if(w(a),s!==s+0)throw s;g(1,0)}}function Bs(e,r,t,n){var i=b();try{y(e)(r,t,n)}catch(a){if(w(i),a!==a+0)throw a;g(1,0)}}function Ls(e,r,t){var n=b();try{return y(e)(r,t)}catch(i){if(w(n),i!==i+0)throw i;g(1,0)}}function Ws(e,r,t,n,i,a,s,c){var u=b();try{y(e)(r,t,n,i,a,s,c)}catch(f){if(w(u),f!==f+0)throw f;g(1,0)}}function Us(e,r,t,n,i,a){var s=b();try{y(e)(r,t,n,i,a)}catch(c){if(w(s),c!==c+0)throw c;g(1,0)}}function Vs(e,r,t){var n=b();try{y(e)(r,t)}catch(i){if(w(n),i!==i+0)throw i;g(1,0)}}function zs(e,r,t,n,i,a,s){var c=b();try{return y(e)(r,t,n,i,a,s)}catch(u){if(w(c),u!==u+0)throw u;g(1,0)}}function Hs(e,r,t,n,i,a,s){var c=b();try{y(e)(r,t,n,i,a,s)}catch(u){if(w(c),u!==u+0)throw u;g(1,0)}}function qs(e,r,t,n){var i=b();try{return y(e)(r,t,n)}catch(a){if(w(i),a!==a+0)throw a;g(1,0)}}function Xs(e,r,t,n){var i=b();try{y(e)(r,t,n)}catch(a){if(w(i),a!==a+0)throw a;g(1,0)}}function Zs(e,r,t){var n=b();try{y(e)(r,t)}catch(i){if(w(n),i!==i+0)throw i;g(1,0)}}function Ks(e,r,t,n,i,a){var s=b();try{return y(e)(r,t,n,i,a)}catch(c){if(w(s),c!==c+0)throw c;g(1,0)}}function Ys(e,r,t,n,i){var a=b();try{return y(e)(r,t,n,i)}catch(s){if(w(a),s!==s+0)throw s;return g(1,0),0n}}function Js(e,r,t,n){var i=b();try{return y(e)(r,t,n)}catch(a){if(w(i),a!==a+0)throw a;g(1,0)}}function Qs(e,r,t,n){var i=b();try{return y(e)(r,t,n)}catch(a){if(w(i),a!==a+0)throw a;g(1,0)}}function ec(e,r,t,n,i){var a=b();try{return y(e)(r,t,n,i)}catch(s){if(w(a),s!==s+0)throw s;g(1,0)}}function rc(e,r,t,n,i,a,s){var c=b();try{return y(e)(r,t,n,i,a,s)}catch(u){if(w(c),u!==u+0)throw u;g(1,0)}}function tc(e,r,t,n,i,a){var s=b();try{return y(e)(r,t,n,i,a)}catch(c){if(w(s),c!==c+0)throw c;g(1,0)}}function nc(e,r,t,n,i,a,s,c,u,f,d){var _=b();try{y(e)(r,t,n,i,a,s,c,u,f,d)}catch(p){if(w(_),p!==p+0)throw p;g(1,0)}}function ic(e,r,t,n,i,a,s,c,u,f,d,_,p,v,h,k){var $=b();try{y(e)(r,t,n,i,a,s,c,u,f,d,_,p,v,h,k)}catch(T){if(w($),T!==T+0)throw T;g(1,0)}}function ac(e,r,t,n){var i=b();try{return y(e)(r,t,n)}catch(a){if(w(i),a!==a+0)throw a;g(1,0)}}function oc(e,r,t,n,i,a){var s=b();try{return y(e)(r,t,n,i,a)}catch(c){if(w(s),c!==c+0)throw c;g(1,0)}}function sc(e,r,t,n){var i=b();try{y(e)(r,t,n)}catch(a){if(w(i),a!==a+0)throw a;g(1,0)}}function wr(){if(ue>0){Se=wr;return}if(jt(),ue>0){Se=wr;return}function e(){l.calledRun=!0,!Pe&&(Ot(),Cr?.(l),l.onRuntimeInitialized?.(),xt())}l.setStatus?(l.setStatus(\"Running...\"),setTimeout(()=>{setTimeout(()=>l.setStatus(\"\"),1),e()},1)):e()}var de;return de=await Vt(),wr(),Pr?Ye=l:Ye=new Promise((e,r)=>{Cr=e,Tr=r}),Ye}export default cc;\n\n";
480
64
  function _getExport(m) {
481
- return m.default || m;
65
+ return m.default || m;
482
66
  }
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
- }));
67
+ function _loadFactory() {
68
+ const blobUrl = URL.createObjectURL(new Blob([_glueSource], { type: "text/javascript" }));
69
+ return import(/* @vite-ignore */ /* webpackIgnore: true */ /* turbopackIgnore: true */ blobUrl).finally(() => URL.revokeObjectURL(blobUrl)).then((m) => {
70
+ const f = _getExport(m);
71
+ if (typeof f === "function") return f;
72
+ throw new Error("bad module");
73
+ });
498
74
  }
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
- });
75
+ function _emscripten_lazy_AquaApi_default(...args) {
76
+ if (!_factoryPromise) {
77
+ _wasmPromise = fetch(_wasmUrl).then((r) => {
78
+ if (!r.ok || (r.headers.get("content-type") || "").includes("text/html")) return null;
79
+ return r.arrayBuffer();
80
+ }).catch(() => null);
81
+ _factoryPromise = _loadFactory().catch((e) => {
82
+ _factoryPromise = _wasmPromise = void 0;
83
+ throw e;
84
+ });
85
+ }
86
+ return Promise.all([_factoryPromise, _wasmPromise]).then(([factory, wasmBinary]) => {
87
+ const [opts = {}, ...rest] = args;
88
+ const merged = _wasmUrl ? {
89
+ locateFile: (f, d) => f.endsWith(".wasm") ? _wasmUrl : d + f,
90
+ ...opts
91
+ } : { ...opts };
92
+ if (wasmBinary) merged.wasmBinary = wasmBinary;
93
+ return factory(merged, ...rest);
94
+ });
517
95
  }
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 // Splatter renderer format: pre-decoded ellipsoid + spherical harmonic\n // Will not be present unless the c++ was compiled with --enable-feature splatter\n splatterEllipsoids: { elementsPerSplat: 12, discard: false },\n splatterSphericalHarmonics: { elementsPerSplat: 16, 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" });
96
+ //#endregion
97
+ //#region packages/core/engine/factory.ts
98
+ var factory_default = _emscripten_lazy_AquaApi_default;
99
+ //#endregion
100
+ //#region packages/core/engine/threads/thread.ts
101
+ var Thread = class Thread {
102
+ static name = "thread";
103
+ static get Worker() {
104
+ throw new Error("Thread could not be initialized because no Worker was supplied. Do you forget to set `static Worker = Worker` on the child class?");
105
+ }
106
+ constructor({ engine }) {
107
+ Object.defineProperty(this, "engine", {
108
+ value: engine,
109
+ enumerable: true
110
+ });
111
+ Object.defineProperty(this, "ready", {
112
+ enumerable: true,
113
+ value: new Promise((resolve) => {
114
+ this.#resolvers.set(0, async () => {
115
+ this.#pending = false;
116
+ this.#resolvers.delete(0);
117
+ resolve(this);
118
+ });
119
+ })
120
+ });
121
+ this.#worker = new this.constructor.Worker({ name: `decoder-${Thread.#nextWorkerId()}` });
122
+ this.#worker.addEventListener("message", this.#message.bind(this));
123
+ }
124
+ static #latestWorkerId = 0;
125
+ static #nextWorkerId() {
126
+ return this.#latestWorkerId += 1;
127
+ }
128
+ #pending = true;
129
+ get pending() {
130
+ return this.#pending;
131
+ }
132
+ #worker;
133
+ #resolvers = /* @__PURE__ */ new Map();
134
+ get pendingRequests() {
135
+ return this.#resolvers.size;
136
+ }
137
+ get terminated() {
138
+ return !this.#worker;
139
+ }
140
+ #latestProcessId = 0;
141
+ #nextProcessId() {
142
+ return this.#latestProcessId += 1;
143
+ }
144
+ async _execute(action, ...args) {
145
+ if (this.pending) throw new Error(`Unable to execute ${action} because decoder has not yet been initialized`);
146
+ if (!this.#worker) throw new Error(`Unable to execute ${action} because decoder has already been terminated`);
147
+ return new Promise((resolve) => {
148
+ if (!this.#worker) throw new Error(`Unable to execute ${action} because decoder has already been terminated`);
149
+ const id = this.#nextProcessId();
150
+ this.#resolvers.set(id, async (result) => {
151
+ this.#resolvers.delete(id);
152
+ resolve(result);
153
+ });
154
+ const transfer = args.filter((arg) => arg instanceof ArrayBuffer);
155
+ this.#worker.postMessage({
156
+ id,
157
+ action,
158
+ args
159
+ }, transfer);
160
+ });
161
+ }
162
+ #message({ data }) {
163
+ if ("ready" === data) data = {
164
+ id: 0,
165
+ result: void 0
166
+ };
167
+ const { id, result } = data;
168
+ this.#resolvers.get(id)?.(result);
169
+ }
170
+ _postToWorker(data, transfer) {
171
+ this.#worker?.postMessage(data, transfer ?? []);
172
+ }
173
+ terminate() {
174
+ if (!this.#worker) return;
175
+ this.#worker.terminate();
176
+ this.#worker.removeEventListener("message", this.#message);
177
+ this.#worker = null;
178
+ }
179
+ };
180
+ //#endregion
181
+ //#region packages/core/engine/threads/decoder/worker.ts?worker&inline
182
+ var jsContent = "//#region packages/core/engine/threads/utils.ts\nconst 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(actions[action], void 0, [...args, id]);\n self.postMessage({\n id,\n result\n }, ...postMessageArgs);\n });\n return actions;\n};\n//#endregion\n//#region packages/core/attribute.ts\nconst sparkMinSplats = 2048;\nconst sparkAttributeList = {\n sparkPackedSplat: {\n elementsPerSplat: 4,\n discard: false\n },\n extendedPackedSplatLow: {\n elementsPerSplat: 4,\n discard: false\n },\n extendedPackedSplatHigh: {\n elementsPerSplat: 4,\n discard: false\n },\n packedSh1: {\n elementsPerSplat: 2,\n discard: false\n },\n packedSh2: {\n elementsPerSplat: 4,\n discard: false\n },\n packedSh3: {\n elementsPerSplat: 4,\n discard: false\n },\n sh1Extended: {\n elementsPerSplat: 4,\n discard: false\n },\n sh2Extended: {\n elementsPerSplat: 4,\n discard: false\n },\n sh3Extended_0: {\n elementsPerSplat: 4,\n discard: false\n },\n sh3Extended_1: {\n elementsPerSplat: 4,\n discard: false\n },\n sharkEllipsoid: {\n elementsPerSplat: 12,\n discard: false\n },\n sharkEllipsoidCompressed: {\n elementsPerSplat: 4,\n discard: false\n },\n sharkSphericalHarmonics: {\n elementsPerSplat: 16,\n discard: false\n },\n color: {\n elementsPerSplat: 2,\n discard: false\n }\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) throw new Error(\"attribute name\" + name + \" is unknown\");\n const originalSize = wasmView.length;\n const paddedSize = roundUpToMultipleOf(originalSize, attrib.elementsPerSplat * sparkMinSplats);\n const paddedData = new Uint32Array(paddedSize);\n paddedData.set(wasmView);\n return {\n paddedData,\n originalSizeInUints: originalSize,\n id\n };\n}\n//#endregion\n//#region packages/core/aqua-parser.js\nasync function Li(Le = {}) {\n var $r, l = Le, ze = !1, Br = !0, 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 if (ze || Br) {\n try {\n wr = new URL(\".\", Ne).href;\n } catch {}\n Br && (Tr = (e) => {\n var r = new XMLHttpRequest();\n return r.open(\"GET\", e, !1), 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 = !1, rr, Gr, qr, er, k, A, U, L, T, w, tr, nr, V, Xr, Jr = !1;\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 = !0, 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 = !0, 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 return Ze(e);\n }\n async function rt(e, r) {\n try {\n var t = await Qe(e);\n return await WebAssembly.instantiate(t, r);\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\" });\n return await WebAssembly.instantiateStreaming(n, t);\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 {\n env: Ie,\n wasi_snapshot_preview1: Ie\n };\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, u));\n });\n });\n Fr ??= Ke();\n return r(await et(G, Fr, t));\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 = !0;\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(!0), ar--), r.set_rethrown(!1), 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(!0), e.set_caught(!1), ar++), x = r, x;\n }, vt = (e, r, t) => {\n throw new Pr(e).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: return t ? (n) => k[n] : (n) => A[n];\n case 2: return t ? (n) => U[n >> 1] : (n) => L[n >> 1];\n case 4: return t ? (n) => T[n >> 2] : (n) => w[n >> 2];\n case 8: return t ? (n) => V[n >> 3] : (n) => Xr[n >> 3];\n default: 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, {\n name: r,\n fromWireType: s,\n toWireType: (o, u) => (typeof u == \"number\" && (u = BigInt(u)), u),\n readValueFromPointer: te(r, t, !a),\n destructorFunction: null\n });\n }, yt = (e, r, t, n) => {\n r = C(r), E(e, {\n name: r,\n fromWireType: function(i) {\n return !!i;\n },\n toWireType: function(i, a) {\n return a ? t : n;\n },\n readValueFromPointer: function(i) {\n return this.fromWireType(A[i]);\n },\n destructorFunction: null\n });\n }, mt = (e) => ({\n count: e.count,\n deleteScheduled: e.deleteScheduled,\n preservePointerOnDelete: e.preservePointerOnDelete,\n ptr: e.ptr,\n ptrType: e.ptrType,\n smartPtr: e.smartPtr,\n smartPtrType: e.smartPtrType\n }), Sr = (e) => {\n function r(t) {\n return t.$$.ptrType.registeredClass.name;\n }\n h(r(e) + \" instance already deleted\");\n }, Ar = !1, ne = (e) => {}, 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 e.count.value === 0 && 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 if (!!t.smartPtr) {\n var i = { $$: t };\n Ar.register(r, i, r);\n }\n return r;\n }, ne = (r) => Ar.unregister(r), X(e)), ur = [], $t = () => {\n for (; ur.length;) {\n var e = ur.pop();\n e.$$.deleteScheduled = !1, e.delete();\n }\n }, ae, wt = () => {\n let e = cr.prototype;\n Object.assign(e, {\n isAliasOf(t) {\n if (!(this instanceof cr) || !(t instanceof cr)) return !1;\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 },\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 = !1, t;\n },\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 },\n isDeleted() {\n return !this.$$.ptr;\n },\n deleteLater() {\n return this.$$.ptr || Sr(this), this.$$.deleteScheduled && !this.$$.preservePointerOnDelete && h(\"Object already scheduled for deletion\"), ur.push(this), ur.length === 1 && ae && ae($t), this.$$.deleteScheduled = !0, this;\n }\n });\n const r = Symbol.dispose;\n r && (e[r] = e.delete);\n };\n function cr() {}\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 return lr(r.$$.ptr, t, this.registeredClass);\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: 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 return lr(r.$$.ptr, t, this.registeredClass);\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 return !!r.smartPtrType !== !!r.smartPtr && _r(\"Both smartPtrType and smartPtr must be specified\"), r.count = { value: 1 }, X(Object.create(e, { $$: {\n value: r,\n writable: !0\n } }));\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, {\n ptrType: this.pointeeType,\n ptr: r,\n smartPtrType: this,\n smartPtr: e\n }) : dr(this.registeredClass.instancePrototype, {\n ptrType: this,\n ptr: e\n });\n }\n var s = se[this.registeredClass.getActualType(r)];\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, {\n ptrType: o,\n ptr: u,\n smartPtrType: this,\n smartPtr: e\n }) : dr(o.registeredClass.instancePrototype, {\n ptrType: o,\n ptr: u\n });\n }\n var Ot = () => {\n Object.assign(pr.prototype, {\n getPointee(e) {\n return this.rawGetPointee && (e = this.rawGetPointee(e)), e;\n },\n destructor(e) {\n this.rawDestructor?.(e);\n },\n readValueFromPointer: vr,\n fromWireType: xt\n });\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 = !1) => {\n e = C(e);\n function n() {\n return b(r);\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 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] = !0;\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([\n e,\n r,\n t\n ], 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, !0, !1, !1), Me = new pr(f + \"*\", S, !1, !1, !1), He = new pr(f + \" const*\", S, !1, !0, !1);\n return se[e] = {\n pointerType: Me,\n constPointerType: He\n }, ue(p, F), [\n Bi,\n Me,\n He\n ];\n });\n }, Wr = (e) => {\n for (; e.length;) {\n var r = e.pop();\n e.pop()(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 !0;\n return !1;\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\", _ = [\n \"humanName\",\n \"throwBindingError\",\n \"invoker\",\n \"fn\",\n \"runDestructors\",\n \"fromRetWire\",\n \"toClassParamWire\"\n ];\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 = [\n e,\n h,\n n,\n i,\n Wr,\n _.fromWireType.bind(_),\n d?.toWireType.bind(d)\n ], 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 return fr(e, jt(r, o, c, a)(...p));\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 P = hr(_, [v[0], null].concat(v.slice(1)), 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 = {\n get() {\n I(`Cannot access ${_} due to unbound types`, [t, s]);\n },\n enumerable: !0,\n configurable: !0\n };\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], $ = {\n get() {\n var F = _e(this, f, _ + \" getter\");\n return v.fromWireType(i(a, F));\n },\n enumerable: !0\n };\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 = [\n 0,\n 1,\n ,\n 1,\n null,\n 1,\n !0,\n 1,\n !1,\n 1\n ], Or = (e) => {\n e > 9 && --N[e + 1] === 0 && (N[e] = void 0, de.push(e));\n }, W = {\n toValue: (e) => (e || h(`Cannot use deleted val. handle = ${e}`), N[e]),\n toHandle: (e) => {\n switch (e) {\n case void 0: return 2;\n case null: return 4;\n case !0: return 6;\n case !1: return 8;\n default: {\n const r = de.pop() || N.length;\n return N[r] = e, N[r + 1] = 1, r;\n }\n }\n }\n }, Lt = {\n name: \"emscripten::val\",\n fromWireType: (e) => {\n var r = W.toValue(e);\n return Or(e), r;\n },\n toWireType: (e, r) => W.toHandle(r),\n readValueFromPointer: vr,\n destructorFunction: null\n }, zt = (e) => E(e, Lt), Yt = (e, r, t) => {\n switch (r) {\n case 1: return t ? function(n) {\n return this.fromWireType(k[n]);\n } : function(n) {\n return this.fromWireType(A[n]);\n };\n case 2: 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: return t ? function(n) {\n return this.fromWireType(T[n >> 2]);\n } : function(n) {\n return this.fromWireType(w[n >> 2]);\n };\n default: throw new TypeError(`invalid integer width (${r}): ${e}`);\n }\n }, Nt = (e, r, t, n) => {\n r = C(r);\n function i() {}\n i.values = {}, E(e, {\n name: r,\n constructor: i,\n fromWireType: function(a) {\n return this.constructor.values[a];\n },\n toWireType: (a, s) => s.value,\n readValueFromPointer: Yt(r, t, n),\n destructorFunction: null\n }), 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, {\n value: { value: t },\n 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: return function(t) {\n return this.fromWireType(tr[t >> 2]);\n };\n case 8: return function(t) {\n return this.fromWireType(nr[t >> 3]);\n };\n default: throw new TypeError(`invalid float width (${r}): ${e}`);\n }\n }, Xt = (e, r, t) => {\n r = C(r), E(e, {\n name: r,\n fromWireType: (n) => n,\n toWireType: (n, i) => i,\n readValueFromPointer: qt(r, t),\n destructorFunction: null\n });\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, {\n name: r,\n fromWireType: s,\n toWireType: (u, c) => c,\n readValueFromPointer: te(r, t, n !== 0),\n destructorFunction: null\n });\n }, Zt = (e, r, t) => {\n var i = [\n Int8Array,\n Uint8Array,\n Int16Array,\n Uint16Array,\n Int32Array,\n Uint32Array,\n Float32Array,\n Float64Array,\n BigInt64Array,\n BigUint64Array\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, {\n name: t,\n fromWireType: a,\n readValueFromPointer: a\n }, { ignoreDuplicateRegistrations: !0 });\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 var t = !0;\n E(e, {\n name: r,\n fromWireType(n) {\n var i = w[n >> 2], a = n + 4, s;\n if (t) s = yr(a, i, !0);\n else {\n s = \"\";\n for (var o = 0; o < i; ++o) s += String.fromCharCode(A[a + o]);\n }\n return O(n), s;\n },\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\"), t && s ? a = Ur(i) : a = i.length;\n var o = Mr(4 + a + 1), u = o + 4;\n if (w[o >> 2] = a, s) if (t) M(i, u, a + 1);\n else for (var c = 0; c < a; ++c) {\n var f = i.charCodeAt(c);\n f > 255 && (O(o), h(\"String has UTF-16 code units that do not fit in 8 bits\")), A[u + c] = f;\n }\n else A.set(i, u);\n return n !== null && n.push(O, o), o;\n },\n readValueFromPointer: vr,\n destructorFunction(n) {\n O(n);\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) e.codePointAt(t) > 65535 && t++, r += 4;\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, {\n name: t,\n fromWireType: (s) => {\n var o = w[s >> 2], u = n(s + 4, o * r, !0);\n return O(s), u;\n },\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 },\n readValueFromPointer: vr,\n destructorFunction(s) {\n O(s);\n }\n });\n }, cn = (e, r) => {\n r = C(r), E(e, {\n isVoid: !0,\n name: r,\n fromWireType: () => {},\n toWireType: (t, n) => {}\n });\n }, be = 0, fn = () => {\n Cr = !1, 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: u.getStringOrSymbol = pn, f = \"toValue(handle)[getStringOrSymbol(methodName)]\";\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));\n return ln(fr(`methodCaller<(${a.map((p) => p.name)}) => ${i.name}>`, _));\n }, gn = (e, r, t, n, i) => Vr[e](r, t, n, i), yn = () => W.toHandle({}), mn = (e) => {\n Wr(W.toValue(e)), 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 = /* @__PURE__ */ 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) / 864e5 | 0;\n T[r + 28 >> 2] = i;\n }\n var Fn = (e) => e % 4 === 0 && (e % 100 !== 0 || e % 400 === 0), Cn = [\n 0,\n 31,\n 60,\n 91,\n 121,\n 152,\n 182,\n 213,\n 244,\n 274,\n 305,\n 335\n ], Pn = [\n 0,\n 31,\n 59,\n 90,\n 120,\n 151,\n 181,\n 212,\n 243,\n 273,\n 304,\n 334\n ], kn = (e) => {\n return (Fn(e.getFullYear()) ? Cn : Pn)[e.getMonth()] + e.getDate() - 1;\n };\n function Sn(e, r) {\n e = mr(e);\n var t = /* @__PURE__ */ 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 = !0), 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 return J[e] = {\n id: setTimeout(() => {\n delete J[e], Dn(() => Ee(e, Fe()));\n }, r),\n timeout_ms: r\n }, 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);\n return `UTC${v}${String(Math.floor($ / 60)).padStart(2, \"0\")}${String($ % 60).padStart(2, \"0\")}`;\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(), Un = 1, Vn = (e) => e >= 0 && e <= 3;\n function jn(e, r, t) {\n if (r = mr(r), !Vn(e)) return 28;\n var n;\n if (e === 0) n = On();\n else if (Un) n = Fe();\n else return 52;\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 t = (e - er.buffer.byteLength + 65535) / 65536 | 0;\n try {\n return er.grow(t), Kr(), 1;\n } catch {}\n }, Bn = (e) => {\n var r = A.length;\n e >>>= 0;\n var t = Ce();\n if (e > t) return !1;\n for (var n = 1; n <= 4; n *= 2) {\n var i = r * (1 + .2 / n);\n i = Math.min(i, e + 100663296);\n if (Hn(Math.min(t, Mn(Math.max(e, i), 65536)))) return !0;\n }\n return !1;\n }, br = {}, Ln = () => Lr || \"./this.program\", K = () => {\n if (!K.strings) {\n var r = {\n USER: \"web_user\",\n LOGNAME: \"web_user\",\n PATH: \"/\",\n PWD: \"/\",\n HOME: \"/home/web_user\",\n LANG: (typeof navigator == \"object\" && navigator.language || \"C\").replace(\"-\", \"_\") + \".UTF-8\",\n _: Ln()\n };\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 var a = 2;\n e == 0 ? t = 2 : (e == 1 || e == 2) && (t = 64), i = 1;\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 r = mr(r), 70;\n }\n var jr = [\n null,\n [],\n []\n ], 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 return l[\"_\" + e];\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 = {\n string: (v) => {\n var $ = 0;\n return v != null && v !== 0 && ($ = Zn(v)), $;\n },\n array: (v) => {\n var $ = ke(v.length);\n return Kn(v, $), $;\n }\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\");\n return r !== \"string\" && i && !n ? Pe(e) : (...s) => Se(e, r, t, s, n);\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 = {\n __cxa_begin_catch: st,\n __cxa_end_catch: ot,\n __cxa_find_matching_catch_2: ut,\n __cxa_find_matching_catch_3: ct,\n __cxa_find_matching_catch_4: ft,\n __cxa_rethrow: lt,\n __cxa_throw: vt,\n __cxa_uncaught_exceptions: _t,\n __resumeException: dt,\n _abort_js: pt,\n _embind_register_bigint: gt,\n _embind_register_bool: yt,\n _embind_register_class: Vt,\n _embind_register_class_class_function: It,\n _embind_register_class_constructor: Mt,\n _embind_register_class_function: Ht,\n _embind_register_class_property: Bt,\n _embind_register_emval: zt,\n _embind_register_enum: Nt,\n _embind_register_enum_value: Gt,\n _embind_register_float: Xt,\n _embind_register_function: Jt,\n _embind_register_integer: Kt,\n _embind_register_memory_view: Zt,\n _embind_register_std_string: rn,\n _embind_register_std_wstring: un,\n _embind_register_void: cn,\n _emscripten_runtime_keepalive_clear: fn,\n _emval_create_invoker: hn,\n _emval_decref: Or,\n _emval_invoke: gn,\n _emval_new_object: yn,\n _emval_run_destructors: mn,\n _emval_set_property: bn,\n _gmtime_js: Tn,\n _localtime_js: Sn,\n _setitimer_js: Wn,\n _tzset_js: xn,\n clock_time_get: jn,\n emscripten_get_heap_max: In,\n emscripten_resize_heap: Bn,\n environ_get: zn,\n environ_sizes_get: Yn,\n fd_close: Nn,\n fd_fdstat_get: Gn,\n fd_seek: qn,\n fd_write: Xn,\n invoke_diii: Di,\n invoke_fi: Ti,\n invoke_fiii: Ri,\n invoke_i: Wi,\n invoke_ii: ui,\n invoke_iii: vi,\n invoke_iiii: mi,\n invoke_iiiid: Oi,\n invoke_iiiii: wi,\n invoke_iiiiid: Si,\n invoke_iiiiii: hi,\n invoke_iiiiiii: Ui,\n invoke_iiiiiiii: Ai,\n invoke_iiiiiiiiii: yi,\n invoke_iiiiiiiiiii: _i,\n invoke_iiiiiiiiiiii: di,\n invoke_iiiiijj: Vi,\n invoke_iiiijj: ji,\n invoke_iiij: Ci,\n invoke_j: Pi,\n invoke_jiiii: Ei,\n invoke_v: pi,\n invoke_vi: ci,\n invoke_vii: li,\n invoke_viii: fi,\n invoke_viiii: oi,\n invoke_viiiii: bi,\n invoke_viiiiii: gi,\n invoke_viiiiiii: xi,\n invoke_viiiiiiii: Fi,\n invoke_viiiiiiiiii: Ii,\n invoke_viiiiiiiiiiiiiii: Mi,\n invoke_viiji: ki,\n invoke_viijii: $i,\n llvm_eh_typeid_for: Jn,\n proc_exit: Te\n };\n function oi(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 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) {\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 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 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 _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, 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 Pi(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 ki(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 Si(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 Ai(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 Ei(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 Ri(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 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) {\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 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 = !0, !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}\n//#endregion\n//#region packages/core/engine/threads/decoder/worker.ts\nconst { wasmBinary } = await new Promise((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});\nif (!wasmBinary) throw new Error(\"Decoder worker did not receive WASM binary. The main thread failed to fetch aqua-parser.wasm.\");\nconst module = await Li({ wasmBinary });\nconst controllers = /* @__PURE__ */ new Map();\nconst decoder = {\n get AttributeInfo() {\n return module.AttributeInfo;\n },\n get AquaStatus() {\n return module.AquaStatus;\n },\n get heapU8() {\n return module.HEAPU8;\n },\n get heapU32() {\n return module.HEAPU32;\n },\n get SceneRequestDescriptor() {\n return module.SceneRequestDescriptor;\n },\n get WorkerDataType() {\n return module.WorkerDataType;\n },\n dataPtrView: (attributeInfo) => {\n return module.dataPtrView(attributeInfo);\n },\n free: (...args) => {\n return module.ccall(\"free\", \"number\", [\"number\"], args);\n },\n malloc: (...args) => {\n return module.ccall(\"malloc\", \"number\", [\"number\"], args);\n },\n parseDropFile: (bufferPtr, bufferSize) => {\n return module.parseDropFile(bufferPtr, bufferSize);\n },\n getAttributeFromDropFile: (handle, attributeName, attributeInfo) => {\n return module.getAttributeFromDropFile(handle, attributeName, attributeInfo);\n },\n takeAttributeFromDropFile: (handle, attributeName, clientSideId) => {\n return module.takeAttributeFromDropFile(handle, attributeName, clientSideId);\n },\n flattenDropFile: (handle, outPtr, outSize) => {\n return module.flattenDropFile(handle, outPtr, outSize);\n },\n destroyDropFileHandle: (handle) => {\n return module.destroyDropFileHandle(handle);\n }\n};\ndefineActions({\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.TakeHeapSnapshot !== \"function\") return [{ snapshotJson: null }];\n return [{ snapshotJson: module.TakeHeapSnapshot(topN) }];\n },\n async heapTrackingControl(enabled) {\n if (typeof module.SetHeapTrackingEnabled !== \"function\") return [{ success: false }];\n module.SetHeapTrackingEnabled(enabled);\n return [{ success: true }];\n },\n async heapTrackingReset() {\n if (typeof module.ResetHeapTracking !== \"function\") return [{ success: false }];\n module.ResetHeapTracking();\n return [{ success: true }];\n },\n async decode(requestIdLow, requestIdHigh, descriptorBuffer, contextPtr, consecutiveIdsStart, noJwt) {\n const key = `${requestIdHigh}-${requestIdLow}`;\n const controller = new AbortController();\n controllers.set(key, controller);\n try {\n const { free, malloc, parseDropFile, getAttributeFromDropFile, takeAttributeFromDropFile, flattenDropFile, destroyDropFileHandle } = decoder;\n const descriptorSize = descriptorBuffer.byteLength;\n const descriptorPointer = malloc(descriptorSize);\n decoder.heapU8.set(new Uint8Array(descriptorBuffer), descriptorPointer);\n const descriptor = module.SceneRequestDescriptor.deserializeFromBinary(descriptorPointer, descriptorSize);\n free(descriptorPointer);\n let url = descriptor.getUrl();\n if (noJwt) {\n const url_class = new URL(url);\n url_class.searchParams.delete(\"jwt\");\n url = url_class.toString();\n }\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({ \"x-cache\": response.headers.get(\"x-cache\") ?? \"\" });\n if (!response.ok) {\n const duration = performance.now() - startTime;\n return [{\n requestIdLow,\n requestIdHigh,\n resultBuffer: /* @__PURE__ */ new ArrayBuffer(0),\n success: false,\n parsed: false,\n error: `HTTP error! status: ${response.status}`,\n dataType: module.WorkerDataType.Raw.value,\n contextPtr,\n attributes: [],\n duration,\n ttfb: duration,\n httpStatus: response.status,\n responseHeadersJson\n }, { transfer: [] }];\n }\n const rtt = performance.now() - startTime;\n const responseBuffer = await response.arrayBuffer();\n const duration = performance.now() - startTime;\n const attributes = [];\n if (!url.split(/[?#]/, 1)[0].endsWith(\".drop\")) return [{\n requestIdLow,\n requestIdHigh,\n resultBuffer: responseBuffer,\n success: true,\n parsed: false,\n error: void 0,\n dataType: module.WorkerDataType.Raw.value,\n contextPtr,\n attributes,\n duration,\n ttfb: rtt,\n httpStatus: response.status,\n responseHeadersJson\n }, { transfer: [responseBuffer] }];\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) throw new Error(\"parseDropFile failed\");\n let index = consecutiveIdsStart;\n for (const [name, info] of Object.entries(sparkAttributeList)) {\n if (info.discard) takeAttributeFromDropFile(handle, name, index);\n else if (getAttributeFromDropFile(handle, name, attributeInfo) === decoder.AquaStatus.Success) {\n const wasmView = decoder.dataPtrView(attributeInfo);\n const splatData = sparkAttributeFromRaw(name, index, wasmView);\n if (takeAttributeFromDropFile(handle, name, index) === decoder.AquaStatus.Success) attributes.push(splatData);\n }\n index++;\n }\n if (flattenDropFile(handle, outputPointerPointer, outputSizePointer) !== decoder.AquaStatus.Success) throw new Error(\"flattenDropFile failed\");\n outputPointer = decoder.heapU32[outputPointerPointer / 4];\n const outputSize = decoder.heapU32[outputSizePointer / 4];\n if (outputPointer === 0) throw new Error(\"flattenDropFile gave nullptr\");\n const resultBuffer = decoder.heapU8.buffer.slice(outputPointer, outputPointer + outputSize);\n const transferList = attributes.map((attr) => attr.paddedData.buffer);\n return [{\n requestIdLow,\n requestIdHigh,\n resultBuffer,\n success: true,\n parsed: true,\n error: void 0,\n dataType: module.WorkerDataType.Drop.value,\n contextPtr,\n attributes,\n duration,\n ttfb: rtt,\n httpStatus: response.status,\n responseHeadersJson\n }, { transfer: [resultBuffer, ...transferList] }];\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 resultBuffer = (/* @__PURE__ */ new Uint8Array()).buffer;\n return [{\n requestIdLow,\n requestIdHigh,\n resultBuffer,\n success: false,\n parsed: false,\n error: errorMessage,\n dataType: module.WorkerDataType.Drop.value,\n contextPtr,\n attributes: void 0,\n duration,\n ttfb: rtt,\n httpStatus: response.status,\n responseHeadersJson\n }, { transfer: [resultBuffer] }];\n } finally {\n destroyDropFileHandle(handle);\n free(responsePointer);\n free(outputPointerPointer);\n free(outputSizePointer);\n if (outputPointer !== 0) free(outputPointer);\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 requestIdLow,\n requestIdHigh,\n resultBuffer: /* @__PURE__ */ new ArrayBuffer(0),\n success: false,\n parsed: false,\n error: isCancelled ? \"Cancelled\" : errorMsg,\n dataType: module.WorkerDataType.Raw.value,\n contextPtr,\n attributes: [],\n duration: 0,\n ttfb: 0,\n httpStatus: 0,\n responseHeadersJson: \"{}\"\n }, { transfer: [] }];\n } finally {\n controllers.delete(key);\n }\n }\n});\n//#endregion\n";
183
+ var blob = typeof self !== "undefined" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", jsContent], { type: "text/javascript;charset=utf-8" });
609
184
  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
- }
185
+ let objURL;
186
+ try {
187
+ objURL = blob && (self.URL || self.webkitURL).createObjectURL(blob);
188
+ if (!objURL) throw "";
189
+ const worker = new Worker(objURL, {
190
+ type: "module",
191
+ name: options?.name
192
+ });
193
+ worker.addEventListener("error", () => {
194
+ (self.URL || self.webkitURL).revokeObjectURL(objURL);
195
+ });
196
+ return worker;
197
+ } catch (e) {
198
+ return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(jsContent), {
199
+ type: "module",
200
+ name: options?.name
201
+ });
202
+ }
631
203
  }
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
- // Splatter renderer format: pre-decoded ellipsoid + spherical harmonic
722
- // Will not be present unless the c++ was compiled with --enable-feature splatter
723
- splatterEllipsoids: { elementsPerSplat: 12, discard: false },
724
- splatterSphericalHarmonics: { elementsPerSplat: 16, discard: false }
204
+ //#endregion
205
+ //#region packages/core/engine/threads/decoder/wasmFetch.ts
206
+ var createSharedWasmFetch = (url) => {
207
+ let cached;
208
+ return async () => {
209
+ cached ??= fetch(url).then((response) => {
210
+ if (!response.ok) throw new Error(`HTTP ${response.status} fetching ${url}`);
211
+ return response.arrayBuffer();
212
+ });
213
+ try {
214
+ return (await cached).slice(0);
215
+ } catch (error) {
216
+ cached = void 0;
217
+ throw error;
218
+ }
219
+ };
220
+ };
221
+ var fetchParserWasm = createSharedWasmFetch(((u) => u.includes("/.vite/") ? u.replace(/\.vite\/[^?#]*/, () => "@miris-inc/core/dist/aqua-parser.wasm") : u)(new URL("aqua-parser.wasm", import.meta.url).href));
222
+ var Decoder = class extends Thread {
223
+ static name = "decoder";
224
+ static Worker = WorkerWrapper;
225
+ constructor(init) {
226
+ super(init);
227
+ this.#sendParserWasm();
228
+ }
229
+ async #sendParserWasm() {
230
+ try {
231
+ const wasmBinary = await fetchParserWasm();
232
+ this._postToWorker({
233
+ type: "wasm-init",
234
+ wasmBinary
235
+ }, [wasmBinary]);
236
+ } catch (e) {
237
+ console.error("Failed to load aqua-parser.wasm for decoder worker", e);
238
+ this._postToWorker({ type: "wasm-init" });
239
+ }
240
+ }
241
+ get AttributeInfo() {
242
+ return this.module.AttributeInfo;
243
+ }
244
+ async heapSnapshot(topN) {
245
+ return this._execute("heapSnapshot", topN);
246
+ }
247
+ async heapTrackingControl(enabled) {
248
+ return this._execute("heapTrackingControl", enabled);
249
+ }
250
+ async heapTrackingReset() {
251
+ return this._execute("heapTrackingReset");
252
+ }
253
+ async cancel(requestIdLow, requestIdHigh) {
254
+ await this.ready;
255
+ this._execute("cancel", requestIdLow, requestIdHigh).catch(() => {});
256
+ }
257
+ async decode(...args) {
258
+ const { requestIdLow, requestIdHigh, resultBuffer, success, dataType, contextPtr, attributes, duration, ttfb, httpStatus, responseHeadersJson } = await this._execute("decode", ...args);
259
+ if (attributes !== void 0) for (const { paddedData, originalSizeInUints, id } of attributes) AttributeCache.addWithId({
260
+ paddedData,
261
+ originalSizeInUints
262
+ }, id);
263
+ const { engine } = this;
264
+ const bufferSize = resultBuffer.byteLength;
265
+ const bufferPointer = engine.malloc(bufferSize);
266
+ engine.heapU8.set(new Uint8Array(resultBuffer), bufferPointer);
267
+ engine.onWorkerResult(requestIdLow, requestIdHigh, bufferPointer, bufferSize, httpStatus, duration, ttfb, success, dataType, "", responseHeadersJson, contextPtr);
268
+ }
269
+ };
270
+ //#endregion
271
+ //#region packages/core/engine/index.ts
272
+ /**
273
+ * The main Aqua wrapper.
274
+ *
275
+ * @remarks
276
+ * The engine is asynchronously initialized, meaning synchronous operations may
277
+ * fail if is not ready. To ensure the engine is ready, await `engine.ready`
278
+ * or check `engine.pending`.
279
+ */
280
+ var Engine = class Engine {
281
+ static AquaStatus = {
282
+ Success: 0,
283
+ Failure: 1
284
+ };
285
+ static SceneObjectType = {
286
+ ModelRoot: 0,
287
+ SceneObject: 1,
288
+ StreamObject: 2,
289
+ GaussianSplats: 3,
290
+ PointsObject: 4,
291
+ Camera: 5,
292
+ LodOctree: 6,
293
+ VariantSetCollection: 7,
294
+ VariantSet: 8,
295
+ VariantSetOption: 9
296
+ };
297
+ static Feature = {
298
+ DrMap: 0,
299
+ ReflMesh: 1,
300
+ GlassMesh: 2
301
+ };
302
+ static FeatureState = {
303
+ NotLoaded: 0,
304
+ Pending: 1,
305
+ Loaded: 2,
306
+ Failed: 3
307
+ };
308
+ #module;
309
+ get module() {
310
+ if (!this.#module) throw new Error("Engine has not yet been initialized. Did you forget to `await engine.ready()?`");
311
+ return this.#module;
312
+ }
313
+ #decoders = /* @__PURE__ */ new Set();
314
+ #requestMap = /* @__PURE__ */ new Map();
315
+ #noJwt = new URL(location.href).searchParams.has("nojwt");
316
+ constructor(moduleOptions = {}) {
317
+ Object.defineProperty(this, "pending", {
318
+ value: true,
319
+ configurable: true,
320
+ enumerable: true
321
+ });
322
+ Object.defineProperty(this, "ready", {
323
+ enumerable: true,
324
+ value: this.#initialize(moduleOptions)
325
+ });
326
+ }
327
+ async #initialize(moduleOptions) {
328
+ this.#module = await factory_default({
329
+ createDeserializeWorker: this.createDeserializeWorker.bind(this),
330
+ submitToWorker: this.submitToWorker.bind(this),
331
+ cancelRequest: this.cancelRequest.bind(this),
332
+ terminateWorker: this.terminateWorker.bind(this),
333
+ workerUrl: "aqua-parser",
334
+ ...moduleOptions,
335
+ preRun: [(mod) => Object.assign(mod.ENV, Engine.#env())]
336
+ });
337
+ Object.defineProperty(this, "pending", {
338
+ value: false,
339
+ configurable: false
340
+ });
341
+ return this;
342
+ }
343
+ get AttributeInfo() {
344
+ return this.module.AttributeInfo;
345
+ }
346
+ get Handedness() {
347
+ return this.module.Handedness;
348
+ }
349
+ get heapF32() {
350
+ return this.module.HEAPF32;
351
+ }
352
+ get heapU8() {
353
+ return this.module.HEAPU8;
354
+ }
355
+ get MatrixOrder() {
356
+ return this.module.MatrixOrder;
357
+ }
358
+ get SceneChangeIds() {
359
+ return this.module.SceneChangeIds;
360
+ }
361
+ get SceneMetadata() {
362
+ return this.module.SceneMetadata;
363
+ }
364
+ get RuntimeSettings() {
365
+ return this.module.RuntimeSettings;
366
+ }
367
+ get SpatialFormat() {
368
+ return this.module.SpatialFormat;
369
+ }
370
+ get StringVector() {
371
+ return this.module.StringVector;
372
+ }
373
+ get UpAxis() {
374
+ return this.module.UpAxis;
375
+ }
376
+ activatedObjectIdsView(...args) {
377
+ return this.module.activatedObjectIdsView(...args);
378
+ }
379
+ addStreamById(...args) {
380
+ return this.module.ccall("AddStreamById", "number", [
381
+ "number",
382
+ "string",
383
+ "string",
384
+ "number"
385
+ ], args);
386
+ }
387
+ allocateSceneChangesArrays(...args) {
388
+ return this.module.AllocateSceneChangesArrays(...args);
389
+ }
390
+ createContext(...args) {
391
+ return this.module.ccall("CreateAquaContext", "number", [], args);
392
+ }
393
+ destroyContext(...args) {
394
+ return this.module.ccall("DestroyAquaContext", "number", ["number"], args);
395
+ }
396
+ createClient(context, ...args) {
397
+ if (context) return this.module.ccall("CreateClientForContext", "number", ["number"], [context, ...args]);
398
+ return this.module.ccall("CreateClient", "number", [], args);
399
+ }
400
+ createdObjectIdsView(...args) {
401
+ return this.module.createdObjectIdsView(...args);
402
+ }
403
+ deletedObjectIdsView(...args) {
404
+ return this.module.deletedObjectIdsView(...args);
405
+ }
406
+ dataPtrView(...args) {
407
+ return this.module.dataPtrView(...args);
408
+ }
409
+ deactivatedObjectIdsView(...args) {
410
+ return this.module.deactivatedObjectIdsView(...args);
411
+ }
412
+ remaskedObjectIdsView(...args) {
413
+ return this.module.remaskedObjectIdsView(...args);
414
+ }
415
+ getDrawnOctantMask(...args) {
416
+ return this.module.GetDrawnOctantMask(...args);
417
+ }
418
+ destroyClient(...args) {
419
+ return this.module.ccall("DestroyClient", "number", ["number"], args);
420
+ }
421
+ free(...args) {
422
+ return this.module.ccall("free", "number", ["number"], args);
423
+ }
424
+ getAssetsAsync(...args) {
425
+ return this.module.GetAssetsAsync(...args);
426
+ }
427
+ getAttribute(...args) {
428
+ return this.module.ccall("GetAttribute", "number", [
429
+ "number",
430
+ "number",
431
+ "string",
432
+ "number"
433
+ ], args);
434
+ }
435
+ getDefaultCameraId(...args) {
436
+ return this.module.ccall("GetDefaultCameraId", "number", ["number", "number"], args);
437
+ }
438
+ getViewingVolumeId(...args) {
439
+ return this.module.ccall("GetViewingVolumeId", "number", ["number", "number"], args);
440
+ }
441
+ getLocalBoundingBox(...args) {
442
+ return this.module.ccall("GetLocalBoundingBox", "number", [
443
+ "number",
444
+ "number",
445
+ "number"
446
+ ], args);
447
+ }
448
+ getWorldBoundingBox(...args) {
449
+ return this.module.ccall("GetWorldBoundingBox", "number", [
450
+ "number",
451
+ "number",
452
+ "number"
453
+ ], args);
454
+ }
455
+ getLodIndex(...args) {
456
+ return this.module.ccall("GetLodIndex", "number", ["number", "number"], args);
457
+ }
458
+ getSceneChanges(...args) {
459
+ return this.module.GetSceneChanges(...args);
460
+ }
461
+ getSceneChangesCounts(...args) {
462
+ return this.module.GetSceneChangesCounts(...args);
463
+ }
464
+ getSceneMetadata(...args) {
465
+ return this.module.GetSceneMetadata(...args).value;
466
+ }
467
+ getSceneObjectParent(...args) {
468
+ return this.module.ccall("GetSceneObjectParent", "number", ["number", "number"], args);
469
+ }
470
+ getSceneObjectType(...args) {
471
+ return this.module.ccall("GetSceneObjectType", "number", ["number", "number"], args);
472
+ }
473
+ getLocalTransform(...args) {
474
+ return this.module.ccall("MirisGetLocalTransform", "number", [
475
+ "number",
476
+ "number",
477
+ "number"
478
+ ], args);
479
+ }
480
+ getWorldTransform(...args) {
481
+ return this.module.ccall("MirisGetWorldTransform", "number", [
482
+ "number",
483
+ "number",
484
+ "number"
485
+ ], args);
486
+ }
487
+ hasAttribute(...args) {
488
+ return this.module.ccall("HasAttribute", "boolean", [
489
+ "number",
490
+ "number",
491
+ "string"
492
+ ], args);
493
+ }
494
+ isSceneObjectAncestorOf(...args) {
495
+ return this.module.ccall("IsSceneObjectAncestorOf", "boolean", [
496
+ "number",
497
+ "number",
498
+ "number"
499
+ ], args);
500
+ }
501
+ lockScene(...args) {
502
+ return this.module.ccall("LockScene", "number", ["number"], args);
503
+ }
504
+ malloc(...args) {
505
+ return this.module.ccall("malloc", "number", ["number"], args);
506
+ }
507
+ modifiedObjectIdsView(...args) {
508
+ return this.module.modifiedObjectIdsView(...args);
509
+ }
510
+ onWorkerResult(...args) {
511
+ const requestKey = `${args[1]}-${args[0]}`;
512
+ this.#requestMap.delete(requestKey);
513
+ return this.module.ccall("onWorkerResult", null, [
514
+ "number",
515
+ "number",
516
+ "number",
517
+ "number",
518
+ "number",
519
+ "number",
520
+ "number",
521
+ "number",
522
+ "number",
523
+ "string",
524
+ "string",
525
+ "number"
526
+ ], args);
527
+ }
528
+ removeStream(...args) {
529
+ return this.module.ccall("RemoveStream", "boolean", ["pointer", "number"], args);
530
+ }
531
+ setAssetViewerKey(...args) {
532
+ return this.module.ccall("SetAssetViewerKey", "number", ["number", "string"], args);
533
+ }
534
+ setClientSpatialFormat(...args) {
535
+ return this.module.SetClientSpatialFormat(...args).value;
536
+ }
537
+ setRuntimeSettings(...args) {
538
+ return this.module.SetRuntimeSettings(...args).value;
539
+ }
540
+ setMainCameraTransform(...args) {
541
+ return this.module.ccall("SetMainCameraTransform", "number", ["number", "number"], args);
542
+ }
543
+ setMainCameraViewFrustum(...args) {
544
+ return this.module.ccall("SetMainCameraViewFrustum", "number", [
545
+ "number",
546
+ "number",
547
+ "number",
548
+ "number",
549
+ "number",
550
+ "number"
551
+ ], args);
552
+ }
553
+ setMaxCacheSize(...args) {
554
+ return this.module.setMaxCacheSize(...args);
555
+ }
556
+ setPreferSharkEncodingProfiles(...args) {
557
+ return this.module.SetPreferSharkEncodingProfiles(...args);
558
+ }
559
+ setSceneObjectTransform(...args) {
560
+ return this.module.ccall("SetSceneObjectTransform", "number", [
561
+ "number",
562
+ "number",
563
+ "number"
564
+ ], args);
565
+ }
566
+ hasFeature(...args) {
567
+ return this.module.HasFeature(...args);
568
+ }
569
+ getFeatureVersion(...args) {
570
+ return this.module.GetFeatureVersion(...args);
571
+ }
572
+ getFeatureState(...args) {
573
+ return this.module.GetFeatureState(...args);
574
+ }
575
+ getAssetFormatVersion(...args) {
576
+ return this.module.GetAssetFormatVersion(...args);
577
+ }
578
+ getName(...args) {
579
+ return this.module.GetName(...args);
580
+ }
581
+ setVariantSelection(...args) {
582
+ return this.module.ccall("SetVariantSelection", "number", ["number", "number"], args);
583
+ }
584
+ takeAttribute(...args) {
585
+ return this.module.ccall("TakeAttribute", "number", [
586
+ "number",
587
+ "number",
588
+ "string",
589
+ "bigint"
590
+ ], args);
591
+ }
592
+ takeEvictedClientSideAttributeIds(...args) {
593
+ return this.module.TakeEvictedClientSideAttributeIds(...args);
594
+ }
595
+ getActiveClientSideIdsCheckSum() {
596
+ return this.module.GetActiveClientSideIdsCheckSum();
597
+ }
598
+ unlockScene(...args) {
599
+ return this.module.ccall("UnlockScene", "number", ["number"], args);
600
+ }
601
+ updateSceneExecution(...args) {
602
+ return this.module.ccall("UpdateSceneExecution", "number", ["number"], args);
603
+ }
604
+ takeRenderRequired(...args) {
605
+ return this.module.TakeRenderRequired(...args);
606
+ }
607
+ /**
608
+ * Advances the runtime by one frame and recomputes the streaming budget. Call once per
609
+ * displayed frame per context, before the per-client updateSceneExecution() calls.
610
+ * `previousFrameTimeMs` is how long the previous frame took; pass 0 when there is no plausible
611
+ * measurement (first frame, or a resume from a stall) and the frame advances without recording
612
+ * one.
613
+ */
614
+ beginFrame(...args) {
615
+ return this.module.BeginFrame(...args);
616
+ }
617
+ createDeserializeWorker(_url, _workerUrl, poolSize) {
618
+ for (let index = 1; index < poolSize; index += 1) this.#decoders.add(new Decoder({ engine: this }));
619
+ return true;
620
+ }
621
+ cancelRequest(requestIdLow, requestIdHigh) {
622
+ const requestKey = `${requestIdHigh}-${requestIdLow}`;
623
+ const decoder = this.#requestMap.get(requestKey);
624
+ if (decoder) {
625
+ decoder.cancel(requestIdLow, requestIdHigh);
626
+ this.#requestMap.delete(requestKey);
627
+ }
628
+ return true;
629
+ }
630
+ submitToWorker(requestIdLow, requestIdHigh, descriptorBuffer, contextPtr) {
631
+ const decoder = [...this.#decoders.values()].reduce((previous, current) => {
632
+ if (!previous) return current;
633
+ return current.pendingRequests < previous.pendingRequests ? current : previous;
634
+ });
635
+ const requestKey = `${requestIdHigh}-${requestIdLow}`;
636
+ this.#requestMap.set(requestKey, decoder);
637
+ const firstId = AttributeCache.getConsecutiveIds(Object.keys(sparkAttributeList).length);
638
+ decoder.ready.then(() => decoder.decode(requestIdLow, requestIdHigh, descriptorBuffer, contextPtr, firstId, this.#noJwt));
639
+ return true;
640
+ }
641
+ terminateWorker() {
642
+ for (const decoder of this.#decoders) decoder.terminate();
643
+ this.#decoders.clear();
644
+ }
645
+ async requestWorkerHeapSnapshots(topN) {
646
+ const decoders = [...this.#decoders];
647
+ return (await Promise.allSettled(decoders.map((d) => d.ready.then(() => {
648
+ let timer;
649
+ const timeout = new Promise((resolve) => {
650
+ timer = setTimeout(() => resolve(null), 5e3);
651
+ });
652
+ return Promise.race([d.heapSnapshot(topN).then((r) => r.snapshotJson), timeout]).finally(() => clearTimeout(timer));
653
+ })))).map((r) => r.status === "fulfilled" ? r.value : null);
654
+ }
655
+ async setWorkerHeapTrackingEnabled(enabled) {
656
+ await Promise.allSettled([...this.#decoders].map((d) => d.ready.then(() => d.heapTrackingControl(enabled))));
657
+ }
658
+ async resetWorkerHeapTracking() {
659
+ await Promise.allSettled([...this.#decoders].map((d) => d.ready.then(() => d.heapTrackingReset())));
660
+ }
661
+ static #env() {
662
+ return {
663
+ AQUA_USE_SINGLETON_NETWORK_TRANSPORT: "true",
664
+ AQUA_SERVER_BASE_URL: "https://app.miris.com/viewer/v1"
665
+ };
666
+ }
667
+ };
668
+ //#endregion
669
+ //#region packages/core/attribute.ts
670
+ var sparkMinSplats = 2048;
671
+ var sparkAttributeList = {
672
+ sparkPackedSplat: {
673
+ elementsPerSplat: 4,
674
+ discard: false
675
+ },
676
+ extendedPackedSplatLow: {
677
+ elementsPerSplat: 4,
678
+ discard: false
679
+ },
680
+ extendedPackedSplatHigh: {
681
+ elementsPerSplat: 4,
682
+ discard: false
683
+ },
684
+ packedSh1: {
685
+ elementsPerSplat: 2,
686
+ discard: false
687
+ },
688
+ packedSh2: {
689
+ elementsPerSplat: 4,
690
+ discard: false
691
+ },
692
+ packedSh3: {
693
+ elementsPerSplat: 4,
694
+ discard: false
695
+ },
696
+ sh1Extended: {
697
+ elementsPerSplat: 4,
698
+ discard: false
699
+ },
700
+ sh2Extended: {
701
+ elementsPerSplat: 4,
702
+ discard: false
703
+ },
704
+ sh3Extended_0: {
705
+ elementsPerSplat: 4,
706
+ discard: false
707
+ },
708
+ sh3Extended_1: {
709
+ elementsPerSplat: 4,
710
+ discard: false
711
+ },
712
+ sharkEllipsoid: {
713
+ elementsPerSplat: 12,
714
+ discard: false
715
+ },
716
+ sharkEllipsoidCompressed: {
717
+ elementsPerSplat: 4,
718
+ discard: false
719
+ },
720
+ sharkSphericalHarmonics: {
721
+ elementsPerSplat: 16,
722
+ discard: false
723
+ },
724
+ color: {
725
+ elementsPerSplat: 2,
726
+ discard: false
727
+ }
725
728
  };
726
729
  function roundUpToMultipleOf(a, multiple) {
727
- return Math.ceil(a / multiple) * multiple;
730
+ return Math.ceil(a / multiple) * multiple;
728
731
  }
729
732
  function sparkAttributeFromRaw(name, id, wasmView) {
730
- const attrib = sparkAttributeList[name];
731
- if (attrib === void 0)
732
- throw new Error("attribute name" + name + " is unknown");
733
- const originalSize = wasmView.length;
734
- const paddedSize = roundUpToMultipleOf(
735
- originalSize,
736
- attrib.elementsPerSplat * sparkMinSplats
737
- );
738
- const paddedData = new Uint32Array(paddedSize);
739
- paddedData.set(wasmView);
740
- return { paddedData, originalSize, id };
741
- }
742
- class AttributeNames {
743
- static SPARK_PACKED_SPLAT = "sparkPackedSplat";
744
- static SPARK_EXTENDED_SPLAT_LOW = "extendedPackedSplatLow";
745
- static SPARK_EXTENDED_SPLAT_HIGH = "extendedPackedSplatHigh";
746
- static SPARK_PACKED_SH1 = "packedSh1";
747
- static SPARK_PACKED_SH2 = "packedSh2";
748
- static SPARK_PACKED_SH3 = "packedSh3";
749
- static SPARK_EXTENDED_SH1 = "sh1Extended";
750
- static SPARK_EXTENDED_SH2 = "sh2Extended";
751
- static SPARK_EXTENDED_SH3_A = "sh3Extended_0";
752
- static SPARK_EXTENDED_SH3_B = "sh3Extended_1";
753
- static UNUSED = "unused";
754
- static SPLATTER_ELLIPSOIDS = "splatterEllipsoids";
755
- static SPLATTER_SPHERICAL_HARMONICS = "splatterSphericalHarmonics";
733
+ const attrib = sparkAttributeList[name];
734
+ if (attrib === void 0) throw new Error("attribute name" + name + " is unknown");
735
+ const originalSize = wasmView.length;
736
+ const paddedSize = roundUpToMultipleOf(originalSize, attrib.elementsPerSplat * sparkMinSplats);
737
+ const paddedData = new Uint32Array(paddedSize);
738
+ paddedData.set(wasmView);
739
+ return {
740
+ paddedData,
741
+ originalSizeInUints: originalSize,
742
+ id
743
+ };
756
744
  }
757
- class Engine {
758
- static AquaStatus = {
759
- Success: 0,
760
- Failure: 1
761
- };
762
- static SceneObjectType = {
763
- ModelRoot: 0,
764
- SceneObject: 1,
765
- StreamObject: 2,
766
- GaussianSplats: 3,
767
- PointsObject: 4,
768
- Camera: 5,
769
- LodOctree: 6,
770
- VariantSetCollection: 7,
771
- VariantSet: 8,
772
- VariantSetOption: 9
773
- };
774
- static Feature = {
775
- DrMap: 0
776
- };
777
- static FeatureState = {
778
- NotLoaded: 0,
779
- Pending: 1,
780
- Loaded: 2,
781
- Failed: 3
782
- };
783
- #module;
784
- get module() {
785
- if (!this.#module) {
786
- throw new Error(
787
- "Engine has not yet been initialized. Did you forget to `await engine.ready()?`"
788
- );
789
- }
790
- return this.#module;
791
- }
792
- #decoders = /* @__PURE__ */ new Set();
793
- #requestMap = /* @__PURE__ */ new Map();
794
- constructor(moduleOptions = {}) {
795
- Object.defineProperty(this, "pending", {
796
- value: true,
797
- configurable: true,
798
- enumerable: true
799
- });
800
- Object.defineProperty(this, "ready", {
801
- enumerable: true,
802
- value: this.#initialize(moduleOptions)
803
- });
804
- }
805
- async #initialize(moduleOptions) {
806
- this.#module = await _factory({
807
- createDeserializeWorker: this.createDeserializeWorker.bind(this),
808
- submitToWorker: this.submitToWorker.bind(this),
809
- cancelRequest: this.cancelRequest.bind(this),
810
- terminateWorker: this.terminateWorker.bind(this),
811
- // TODO: remove this possibly
812
- workerUrl: "aqua-parser",
813
- ...moduleOptions,
814
- // preRun fires after Emscripten replaces Module.ENV with its internal
815
- // ENV object, but before initRuntime() caches getEnvStrings(). This is
816
- // the only window where mutations to Module.ENV reach C getenv().
817
- preRun: [(mod) => Object.assign(mod.ENV, Engine.#env())]
818
- });
819
- Object.defineProperty(this, "pending", {
820
- value: false,
821
- configurable: false
822
- });
823
- return this;
824
- }
825
- /*
826
- |----------------------------------------------------------------------------
827
- | Wasm Exports
828
- |----------------------------------------------------------------------------
829
- |
830
- | All exported Wasm functions should be wrapped here. A wrapper is just a
831
- | getter property for classes, or a wrapper method for functions. Some
832
- | methods call module exports directly and others exports use cwap.
833
- |
834
- */
835
- get AttributeInfo() {
836
- return this.module.AttributeInfo;
837
- }
838
- get Handedness() {
839
- return this.module.Handedness;
840
- }
841
- get heapF32() {
842
- return this.module.HEAPF32;
843
- }
844
- get heapU8() {
845
- return this.module.HEAPU8;
846
- }
847
- get MatrixOrder() {
848
- return this.module.MatrixOrder;
849
- }
850
- get SceneChangeIds() {
851
- return this.module.SceneChangeIds;
852
- }
853
- get SceneMetadata() {
854
- return this.module.SceneMetadata;
855
- }
856
- get RuntimeSettings() {
857
- return this.module.RuntimeSettings;
858
- }
859
- get SpatialFormat() {
860
- return this.module.SpatialFormat;
861
- }
862
- get StringVector() {
863
- return this.module.StringVector;
864
- }
865
- get UpAxis() {
866
- return this.module.UpAxis;
867
- }
868
- activatedObjectIdsView(...args) {
869
- return this.module.activatedObjectIdsView(...args);
870
- }
871
- addStreamById(...args) {
872
- return this.module.ccall(
873
- "AddStreamById",
874
- "number",
875
- ["number", "string", "string", "number"],
876
- args
877
- );
878
- }
879
- allocateSceneChangesArrays(...args) {
880
- return this.module.AllocateSceneChangesArrays(...args);
881
- }
882
- createContext(...args) {
883
- return this.module.ccall("CreateAquaContext", "number", [], args);
884
- }
885
- destroyContext(...args) {
886
- return this.module.ccall("DestroyAquaContext", "number", ["number"], args);
887
- }
888
- createClient(context, ...args) {
889
- if (context) {
890
- return this.module.ccall("CreateClientForContext", "number", ["number"], [context, ...args]);
891
- }
892
- return this.module.ccall("CreateClient", "number", [], args);
893
- }
894
- createdObjectIdsView(...args) {
895
- return this.module.createdObjectIdsView(...args);
896
- }
897
- deletedObjectIdsView(...args) {
898
- return this.module.deletedObjectIdsView(...args);
899
- }
900
- dataPtrView(...args) {
901
- return this.module.dataPtrView(...args);
902
- }
903
- deactivatedObjectIdsView(...args) {
904
- return this.module.deactivatedObjectIdsView(...args);
905
- }
906
- destroyClient(...args) {
907
- return this.module.ccall("DestroyClient", "number", ["number"], args);
908
- }
909
- free(...args) {
910
- return this.module.ccall("free", "number", ["number"], args);
911
- }
912
- getAssetsAsync(...args) {
913
- return this.module.GetAssetsAsync(...args);
914
- }
915
- getAttribute(...args) {
916
- return this.module.ccall(
917
- "GetAttribute",
918
- "number",
919
- ["number", "number", "string", "number"],
920
- args
921
- );
922
- }
923
- getDefaultCameraId(...args) {
924
- return this.module.ccall("GetDefaultCameraId", "number", ["number"], args);
925
- }
926
- getLocalBoundingBox(...args) {
927
- return this.module.ccall(
928
- "GetLocalBoundingBox",
929
- "number",
930
- ["number", "number", "number"],
931
- args
932
- );
933
- }
934
- getWorldBoundingBox(...args) {
935
- return this.module.ccall(
936
- "GetWorldBoundingBox",
937
- "number",
938
- ["number", "number", "number"],
939
- args
940
- );
941
- }
942
- getLodIndex(...args) {
943
- return this.module.ccall(
944
- "GetLodIndex",
945
- "number",
946
- ["number", "number"],
947
- args
948
- );
949
- }
950
- getSceneChanges(...args) {
951
- return this.module.GetSceneChanges(...args);
952
- }
953
- getSceneChangesCounts(...args) {
954
- return this.module.GetSceneChangesCounts(...args);
955
- }
956
- getSceneMetadata(...args) {
957
- return this.module.GetSceneMetadata(...args).value;
958
- }
959
- getSceneObjectParent(...args) {
960
- return this.module.ccall(
961
- "GetSceneObjectParent",
962
- "number",
963
- ["number", "number"],
964
- args
965
- );
966
- }
967
- getSceneObjectType(...args) {
968
- return this.module.ccall(
969
- "GetSceneObjectType",
970
- "number",
971
- ["number", "number"],
972
- args
973
- );
974
- }
975
- getLocalTransform(...args) {
976
- return this.module.ccall(
977
- "MirisGetLocalTransform",
978
- "number",
979
- ["number", "number", "number"],
980
- args
981
- );
982
- }
983
- getWorldTransform(...args) {
984
- return this.module.ccall(
985
- "MirisGetWorldTransform",
986
- "number",
987
- ["number", "number", "number"],
988
- args
989
- );
990
- }
991
- hasAttribute(...args) {
992
- return this.module.ccall(
993
- "HasAttribute",
994
- "boolean",
995
- ["number", "number", "string"],
996
- args
997
- );
998
- }
999
- isSceneObjectAncestorOf(...args) {
1000
- return this.module.ccall(
1001
- "IsSceneObjectAncestorOf",
1002
- "boolean",
1003
- ["number", "number", "number"],
1004
- args
1005
- );
1006
- }
1007
- lockScene(...args) {
1008
- return this.module.ccall("LockScene", "number", ["number"], args);
1009
- }
1010
- malloc(...args) {
1011
- return this.module.ccall("malloc", "number", ["number"], args);
1012
- }
1013
- modifiedObjectIdsView(...args) {
1014
- return this.module.modifiedObjectIdsView(...args);
1015
- }
1016
- onWorkerResult(...args) {
1017
- const requestKey = `${args[1]}-${args[0]}`;
1018
- this.#requestMap.delete(requestKey);
1019
- return this.module.ccall(
1020
- "onWorkerResult",
1021
- null,
1022
- [
1023
- "number",
1024
- // requestIdLow
1025
- "number",
1026
- // requestIdHigh
1027
- "number",
1028
- // bufferPtr
1029
- "number",
1030
- // bufferSize
1031
- "number",
1032
- // httpStatus
1033
- "number",
1034
- // durationMs (C++ arg 6)
1035
- "number",
1036
- // ttfbMs (C++ arg 7)
1037
- "number",
1038
- // success (C++ arg 8)
1039
- "number",
1040
- // dataType (C++ arg 9)
1041
- "string",
1042
- // errorPtr (C++ arg 10)
1043
- "string",
1044
- // responseHeadersJson (C++ arg 11)
1045
- "number"
1046
- // contextPtr (C++ arg 12)
1047
- ],
1048
- args
1049
- );
1050
- }
1051
- removeStream(...args) {
1052
- return this.module.ccall(
1053
- "RemoveStream",
1054
- "boolean",
1055
- ["pointer", "number"],
1056
- args
1057
- );
1058
- }
1059
- setAssetViewerKey(...args) {
1060
- return this.module.ccall(
1061
- "SetAssetViewerKey",
1062
- "number",
1063
- ["number", "string"],
1064
- args
1065
- );
1066
- }
1067
- setClientSpatialFormat(...args) {
1068
- return this.module.SetClientSpatialFormat(...args).value;
1069
- }
1070
- setRuntimeSettings(...args) {
1071
- return this.module.SetRuntimeSettings(...args).value;
1072
- }
1073
- setMainCameraTransform(...args) {
1074
- return this.module.ccall(
1075
- "SetMainCameraTransform",
1076
- "number",
1077
- ["number", "number"],
1078
- args
1079
- );
1080
- }
1081
- setMainCameraViewFrustum(...args) {
1082
- return this.module.ccall(
1083
- "SetMainCameraViewFrustum",
1084
- "number",
1085
- ["number", "number", "number", "number", "number"],
1086
- args
1087
- );
1088
- }
1089
- setMaxCacheSize(...args) {
1090
- return this.module.setMaxCacheSize(...args);
1091
- }
1092
- setSceneObjectTransform(...args) {
1093
- return this.module.ccall(
1094
- "SetSceneObjectTransform",
1095
- "number",
1096
- ["number", "number", "number"],
1097
- args
1098
- );
1099
- }
1100
- // Feature API
1101
- hasFeature(...args) {
1102
- return this.module.HasFeature(...args);
1103
- }
1104
- getFeatureVersion(...args) {
1105
- return this.module.GetFeatureVersion(...args);
1106
- }
1107
- getFeatureState(...args) {
1108
- return this.module.GetFeatureState(...args);
1109
- }
1110
- // Object Name API
1111
- getName(...args) {
1112
- return this.module.GetName(...args);
1113
- }
1114
- setVariantSelection(...args) {
1115
- return this.module.ccall(
1116
- "SetVariantSelection",
1117
- "number",
1118
- ["number", "number"],
1119
- args
1120
- );
1121
- }
1122
- takeAttribute(...args) {
1123
- return this.module.ccall(
1124
- "TakeAttribute",
1125
- "number",
1126
- ["number", "number", "string", "bigint"],
1127
- args
1128
- );
1129
- }
1130
- takeEvictedClientSideAttributeIds(...args) {
1131
- return this.module.TakeEvictedClientSideAttributeIds(...args);
1132
- }
1133
- getActiveClientSideIdsCheckSum() {
1134
- return this.module.GetActiveClientSideIdsCheckSum();
1135
- }
1136
- unlockScene(...args) {
1137
- return this.module.ccall("UnlockScene", "number", ["number"], args);
1138
- }
1139
- updateSceneExecution(...args) {
1140
- return this.module.ccall(
1141
- "UpdateSceneExecution",
1142
- "number",
1143
- ["number"],
1144
- args
1145
- );
1146
- }
1147
- recordFrameTime(...args) {
1148
- return this.module.ccall(
1149
- "RecordFrameTime",
1150
- "number",
1151
- ["number", "number"],
1152
- args
1153
- );
1154
- }
1155
- takeRenderRequired(...args) {
1156
- return this.module.TakeRenderRequired(...args);
1157
- }
1158
- /*
1159
- |----------------------------------------------------------------------------
1160
- | Decoder helpers
1161
- |----------------------------------------------------------------------------
1162
- */
1163
- createDeserializeWorker(_url, _workerUrl, poolSize) {
1164
- for (let index = 1; index < poolSize; index += 1) {
1165
- this.#decoders.add(new Decoder({ engine: this }));
1166
- }
1167
- return true;
1168
- }
1169
- cancelRequest(requestIdLow, requestIdHigh) {
1170
- const requestKey = `${requestIdHigh}-${requestIdLow}`;
1171
- const decoder = this.#requestMap.get(requestKey);
1172
- if (decoder) {
1173
- decoder.cancel(requestIdLow, requestIdHigh);
1174
- this.#requestMap.delete(requestKey);
1175
- }
1176
- return true;
1177
- }
1178
- submitToWorker(requestIdLow, requestIdHigh, descriptorBuffer, contextPtr) {
1179
- const decoder = [...this.#decoders.values()].reduce((previous, current) => {
1180
- if (!previous) return current;
1181
- return current.pendingRequests < previous.pendingRequests ? current : previous;
1182
- });
1183
- const requestKey = `${requestIdHigh}-${requestIdLow}`;
1184
- this.#requestMap.set(requestKey, decoder);
1185
- const firstId = AttributeCache.getConsecutiveIds(
1186
- Object.keys(sparkAttributeList).length
1187
- );
1188
- decoder.ready.then(
1189
- () => decoder.decode(
1190
- requestIdLow,
1191
- requestIdHigh,
1192
- descriptorBuffer,
1193
- contextPtr,
1194
- firstId
1195
- )
1196
- );
1197
- return true;
1198
- }
1199
- terminateWorker() {
1200
- for (const decoder of this.#decoders) {
1201
- decoder.terminate();
1202
- }
1203
- this.#decoders.clear();
1204
- }
1205
- /*
1206
- |----------------------------------------------------------------------------
1207
- | Heap profiler helpers (fan-out to all decoder workers)
1208
- |----------------------------------------------------------------------------
1209
- */
1210
- async requestWorkerHeapSnapshots(topN) {
1211
- const decoders = [...this.#decoders];
1212
- const results = await Promise.allSettled(
1213
- decoders.map(
1214
- (d) => d.ready.then(() => {
1215
- let timer;
1216
- const timeout = new Promise((resolve) => {
1217
- timer = setTimeout(() => resolve(null), 5e3);
1218
- });
1219
- return Promise.race([
1220
- d.heapSnapshot(topN).then((r) => r.snapshotJson),
1221
- timeout
1222
- ]).finally(() => clearTimeout(timer));
1223
- })
1224
- )
1225
- );
1226
- return results.map((r) => r.status === "fulfilled" ? r.value : null);
1227
- }
1228
- async setWorkerHeapTrackingEnabled(enabled) {
1229
- await Promise.allSettled(
1230
- [...this.#decoders].map(
1231
- (d) => d.ready.then(() => d.heapTrackingControl(enabled))
1232
- )
1233
- );
1234
- }
1235
- async resetWorkerHeapTracking() {
1236
- await Promise.allSettled(
1237
- [...this.#decoders].map((d) => d.ready.then(() => d.heapTrackingReset()))
1238
- );
1239
- }
1240
- static #env() {
1241
- const url = "https://app.miris.com/viewer/v1";
1242
- return {
1243
- AQUA_USE_SINGLETON_NETWORK_TRANSPORT: "true",
1244
- ...{ AQUA_SERVER_BASE_URL: url }
1245
- };
1246
- }
1247
- }
1248
- const RATES = [30, 60, 72, 90, 120, 144, 165, 240];
1249
- function createRefreshRateDetector() {
1250
- let samples = [], last = null, hz = 0;
1251
- screen.addEventListener?.("change", () => {
1252
- samples = [];
1253
- hz = 0;
1254
- last = null;
1255
- });
1256
- return {
1257
- update(ts) {
1258
- if (hz)
1259
- return;
1260
- if (last !== null) {
1261
- samples.push(ts - last);
1262
- if (samples.length > 60)
1263
- samples.shift();
1264
- if (!hz && samples.length === 60) {
1265
- const avg = samples.reduce((a, b) => a + b, 0) / samples.length;
1266
- const meanHz = 1e3 / avg;
1267
- hz = RATES.reduce((a, b) => Math.abs(b - meanHz) < Math.abs(a - meanHz) ? b : a);
1268
- }
1269
- }
1270
- last = ts;
1271
- },
1272
- get nativeHz() {
1273
- return hz;
1274
- }
1275
- };
745
+ var AttributeNames = class {
746
+ static SPARK_PACKED_SPLAT = "sparkPackedSplat";
747
+ static SPARK_EXTENDED_SPLAT_LOW = "extendedPackedSplatLow";
748
+ static SPARK_EXTENDED_SPLAT_HIGH = "extendedPackedSplatHigh";
749
+ static SPARK_PACKED_SH1 = "packedSh1";
750
+ static SPARK_PACKED_SH2 = "packedSh2";
751
+ static SPARK_PACKED_SH3 = "packedSh3";
752
+ static SPARK_EXTENDED_SH1 = "sh1Extended";
753
+ static SPARK_EXTENDED_SH2 = "sh2Extended";
754
+ static SPARK_EXTENDED_SH3_A = "sh3Extended_0";
755
+ static SPARK_EXTENDED_SH3_B = "sh3Extended_1";
756
+ static UNUSED = "unused";
757
+ static SHARK_ELLIPSOIDS = "sharkEllipsoid";
758
+ static SHARK_ELLIPSOIDS_COMPRESSED = "sharkEllipsoidCompressed";
759
+ static SHARK_SPHERICAL_HARMONICS = "sharkSphericalHarmonics";
760
+ static COLOR = "color";
761
+ static OCTANT_OFFSETS = "childOctantOffsets";
762
+ };
763
+ function retrieveFloatArray(engine, objectId, arraySize, fn) {
764
+ const arrayPtr = engine.malloc(arraySize * 4);
765
+ fn(objectId, arrayPtr);
766
+ const floatArray = engine.heapF32.subarray(arrayPtr >> 2, (arrayPtr >> 2) + arraySize).slice();
767
+ engine.free(arrayPtr);
768
+ return floatArray;
1276
769
  }
1277
- class Miris {
1278
- static _instance;
1279
- static async instance() {
1280
- const miris = this._instance ??= new this();
1281
- await miris.ready;
1282
- return miris;
1283
- }
1284
- #sharedContext;
1285
- get sharedContext() {
1286
- return this.#sharedContext;
1287
- }
1288
- #viewerKey;
1289
- get viewerKey() {
1290
- return this.#viewerKey;
1291
- }
1292
- set viewerKey(viewerKey) {
1293
- this.#viewerKey = viewerKey;
1294
- }
1295
- #scenes = /* @__PURE__ */ new Set();
1296
- get scenes() {
1297
- return new Set(this.#scenes);
1298
- }
1299
- #changes = [];
1300
- #changeIds = null;
1301
- #pendingActivations = /* @__PURE__ */ new Set();
1302
- #pendingDeactivations = /* @__PURE__ */ new Map();
1303
- constructor() {
1304
- if (!this.constructor.prototype._instance) {
1305
- this.constructor.prototype._instance = this;
1306
- }
1307
- Object.defineProperties(this, {
1308
- pending: { value: true, configurable: true, enumerable: true },
1309
- engine: { value: new Engine(), enumerable: true }
1310
- });
1311
- Object.defineProperty(this, "ready", {
1312
- enumerable: true,
1313
- value: this.#initializeMiris()
1314
- });
1315
- }
1316
- async #initializeMiris() {
1317
- const { engine } = this;
1318
- await engine.ready;
1319
- this.#sharedContext = this.engine.createContext();
1320
- const mb = 1024 * 1024;
1321
- const urlParams = new URLSearchParams(window.location.search);
1322
- const maxCacheSizeParam = urlParams.get("aquaMaxCacheSize");
1323
- let maxCacheSizeMB = 0;
1324
- if (maxCacheSizeParam) {
1325
- const parsedSize = parseInt(maxCacheSizeParam, 10);
1326
- if (!isNaN(parsedSize) && parsedSize > 0) {
1327
- maxCacheSizeMB = parsedSize;
1328
- }
1329
- }
1330
- if (maxCacheSizeMB > 0) {
1331
- this.engine.setMaxCacheSize(maxCacheSizeMB * mb);
1332
- } else if (navigator.userAgent.includes("iPhone")) {
1333
- this.engine.setMaxCacheSize(128 * mb);
1334
- } else if (navigator.userAgent.includes("Android")) {
1335
- this.engine.setMaxCacheSize(256 * mb);
1336
- }
1337
- this.#browserUpdate();
1338
- Object.defineProperty(this, "pending", {
1339
- value: false,
1340
- configurable: false
1341
- });
1342
- return this;
1343
- }
1344
- dispose() {
1345
- if (this.#sharedContext) {
1346
- if (this.engine.destroyContext(this.#sharedContext) !== Engine.AquaStatus.Success) {
1347
- console.error(
1348
- `Failed to destroy aqua context with handle '${this.#sharedContext}'`
1349
- );
1350
- }
1351
- this.#sharedContext = 0;
1352
- }
1353
- }
1354
- updateParentedTransform(_modelTransform, _parentTransform) {
1355
- return void 0;
1356
- }
1357
- #detector = createRefreshRateDetector();
1358
- #boundUpdate = this.#browserUpdate.bind(this);
1359
- // Set once a host drives update() from its own render loop; the internal RAF loop then stops so
1360
- // _update() runs exactly once per displayed frame (renderer-driven hosts otherwise tick twice).
1361
- #hostDriven = false;
1362
- // Timestamp of the previous _update() tick, for the per-frame render time fed to the
1363
- // budget controller. null = no prior frame (first tick / post-stall).
1364
- #lastFrameTimestamp = null;
1365
- #targetFramesPerSecond = 72;
1366
- #xrModeActive = false;
1367
- #applyDisplaySettings() {
1368
- const settings = new this.engine.RuntimeSettings();
1369
- settings.targetFramesPerSecond = this.#targetFramesPerSecond;
1370
- settings.xrModeActive = this.#xrModeActive;
1371
- for (const scene of this.#scenes) {
1372
- scene.client.setRuntimeSettings(settings);
1373
- }
1374
- settings.delete();
1375
- }
1376
- /**
1377
- * @internal
1378
- */
1379
- _setXRModeActive(active, frameRate) {
1380
- this.#xrModeActive = active;
1381
- if (frameRate !== void 0) {
1382
- this.#targetFramesPerSecond = frameRate;
1383
- }
1384
- this.#applyDisplaySettings();
1385
- }
1386
- #browserUpdate() {
1387
- if (this.#hostDriven) return;
1388
- this._update();
1389
- requestAnimationFrame(this.#boundUpdate);
1390
- }
1391
- /**
1392
- * @internal
1393
- *
1394
- * Shared update function being driven by browser's update loop or an XR session
1395
- */
1396
- _update() {
1397
- if (this.#detector) {
1398
- this.#detector.update(performance.now());
1399
- if (this.#detector.nativeHz > 0) {
1400
- this.#targetFramesPerSecond = this.#detector.nativeHz;
1401
- this.#applyDisplaySettings();
1402
- this.#detector = null;
1403
- }
1404
- }
1405
- const now = performance.now();
1406
- const elapsed = this.#lastFrameTimestamp === null ? null : now - this.#lastFrameTimestamp;
1407
- this.#lastFrameTimestamp = now;
1408
- const MAX_PLAUSIBLE_FRAME_MS = 1e3;
1409
- const frameTimeMs = elapsed !== null && elapsed <= MAX_PLAUSIBLE_FRAME_MS ? elapsed : null;
1410
- for (const scene of this.#scenes) {
1411
- const { client } = scene;
1412
- if (frameTimeMs !== null) {
1413
- client.recordFrameTime(frameTimeMs);
1414
- }
1415
- client.updateSceneExecution();
1416
- const evicted = client.takeEvictedClientSideAttributeIds();
1417
- try {
1418
- const evictedSize = evicted.size();
1419
- if (evictedSize > 0) {
1420
- const evictedArray = [];
1421
- for (let i = 0; i < evictedSize; i++) {
1422
- evictedArray.push(Number(evicted.get(i)));
1423
- }
1424
- AttributeCache.remove(evictedArray);
1425
- }
1426
- } finally {
1427
- evicted.delete();
1428
- }
1429
- const checkSumWasm = this.engine.getActiveClientSideIdsCheckSum();
1430
- AttributeCache.validateCheckSum(checkSumWasm);
1431
- const locked = client.lockScene();
1432
- if (!locked) {
1433
- return;
1434
- }
1435
- try {
1436
- this.#updateScene(scene);
1437
- } finally {
1438
- client.unlockScene();
1439
- }
1440
- }
1441
- if (this.#changes.length) {
1442
- this.applyChanges(this.#changes);
1443
- this.#changes.length = 0;
1444
- }
1445
- }
1446
- #retrieveFloatArray(objectId, arraySize, fn) {
1447
- const sizeOfFloat = 4;
1448
- const arrayPtr = this.engine.malloc(arraySize * sizeOfFloat);
1449
- fn(objectId, arrayPtr);
1450
- const floatArray = this.engine.heapF32.subarray(arrayPtr >> 2, (arrayPtr >> 2) + arraySize).slice();
1451
- this.engine.free(arrayPtr);
1452
- return floatArray;
1453
- }
1454
- getLocalTransform(client, sceneObjectId) {
1455
- if (Number.isInteger(sceneObjectId) && sceneObjectId >= 0) {
1456
- return this.#retrieveFloatArray(
1457
- sceneObjectId,
1458
- 16,
1459
- client.getLocalTransform.bind(client)
1460
- );
1461
- }
1462
- }
1463
- getWorldTransform(client, sceneObjectId) {
1464
- if (Number.isInteger(sceneObjectId) && sceneObjectId >= 0) {
1465
- return this.#retrieveFloatArray(
1466
- sceneObjectId,
1467
- 16,
1468
- client.getWorldTransform.bind(client)
1469
- );
1470
- }
1471
- }
1472
- #shouldUpdateSceneChanges() {
1473
- if (!this.#changeIds) {
1474
- return false;
1475
- }
1476
- if (this.#changeIds.createdObjectsCount > 0) {
1477
- return true;
1478
- }
1479
- if (this.#changeIds.activatedObjectsCount > 0) {
1480
- return true;
1481
- }
1482
- if (this.#changeIds.deactivatedObjectsCount > 0) {
1483
- return true;
1484
- }
1485
- if (this.#changeIds.modifiedObjectsCount > 0) {
1486
- return true;
1487
- }
1488
- if (this.#changeIds.deletedObjectsCount > 0) {
1489
- return true;
1490
- }
1491
- return false;
1492
- }
1493
- #getDataFromAttribute(client, sceneObjectId, attributeName, outAttributeInfo) {
1494
- const { engine } = this;
1495
- if (!client.hasAttribute(sceneObjectId, attributeName)) {
1496
- return null;
1497
- }
1498
- const { ptr } = outAttributeInfo.$$;
1499
- const status = client.getAttribute(sceneObjectId, attributeName, ptr);
1500
- if (status !== Engine.AquaStatus.Success) {
1501
- console.warn(
1502
- `GetAttribute failed for object id ${sceneObjectId} and attribute name ${attributeName}: status ${status}`
1503
- );
1504
- return null;
1505
- }
1506
- let paddedData;
1507
- let originalSize;
1508
- if (outAttributeInfo.clientSideId != 0n) {
1509
- ({ paddedData, originalSize } = AttributeCache.get(
1510
- Number(outAttributeInfo.clientSideId)
1511
- ));
1512
- } else {
1513
- const wasmView = engine.dataPtrView(outAttributeInfo);
1514
- const result = sparkAttributeFromRaw(attributeName, 0, wasmView);
1515
- paddedData = result.paddedData;
1516
- originalSize = result.originalSize;
1517
- const myCacheEntry = AttributeCache.add({
1518
- paddedData: result.paddedData,
1519
- originalSize: result.originalSize
1520
- });
1521
- const takeStatus = client.takeAttribute(
1522
- sceneObjectId,
1523
- attributeName,
1524
- BigInt(myCacheEntry)
1525
- );
1526
- if (takeStatus !== Engine.AquaStatus.Success) {
1527
- AttributeCache.remove(myCacheEntry);
1528
- console.warn(
1529
- `Failed to take attribute ${attributeName} for scene object ${sceneObjectId}: status ${takeStatus}`
1530
- );
1531
- return null;
1532
- }
1533
- }
1534
- return { paddedData, originalSize };
1535
- }
1536
- #updateScene(scene) {
1537
- const { engine } = this;
1538
- const { client, camera, lods } = scene;
1539
- if (camera) {
1540
- camera.update();
1541
- }
1542
- if (this.#changeIds === null) {
1543
- this.#changeIds = new engine.SceneChangeIds();
1544
- }
1545
- client.getSceneChangesCounts(this.#changeIds);
1546
- if (!this.#shouldUpdateSceneChanges()) {
1547
- return;
1548
- }
1549
- engine.allocateSceneChangesArrays(this.#changeIds);
1550
- client.getSceneChanges(this.#changeIds);
1551
- const createdLodIds = /* @__PURE__ */ new Set();
1552
- for (const sceneObjectId of engine.createdObjectIdsView(this.#changeIds)) {
1553
- const sceneObjectType = client.getSceneObjectType(sceneObjectId);
1554
- if (sceneObjectType === Engine.SceneObjectType.StreamObject) {
1555
- Stream.forId(sceneObjectId);
1556
- continue;
1557
- } else if (sceneObjectType === Engine.SceneObjectType.ModelRoot) {
1558
- const stream = scene.getStreamForDescendentId(sceneObjectId);
1559
- if (!stream) continue;
1560
- const modelRoot = new ModelRoot({ id: sceneObjectId, stream });
1561
- const modelRootTransform = this.getLocalTransform(
1562
- client,
1563
- sceneObjectId
1564
- );
1565
- if (!modelRootTransform) continue;
1566
- const parentId = client.getSceneObjectParent(sceneObjectId);
1567
- const parentTransform = this.getLocalTransform(client, parentId);
1568
- if (!parentTransform) continue;
1569
- const updatedTransform = this.updateParentedTransform(
1570
- modelRootTransform,
1571
- parentTransform
1572
- );
1573
- if (!updatedTransform) continue;
1574
- modelRoot.transform = updatedTransform;
1575
- } else if (sceneObjectType == Engine.SceneObjectType.GaussianSplats) {
1576
- const modelRoot = scene.getModelRootForDescendentId(sceneObjectId);
1577
- if (!modelRoot) continue;
1578
- const lod = new Lod({ id: sceneObjectId, modelRoot, lodStore: lods });
1579
- lod.transform = this.getLocalTransform(client, sceneObjectId);
1580
- createdLodIds.add(sceneObjectId);
1581
- const entry = new Change({ type: "created", lod });
1582
- this.#changes.push(entry);
1583
- } else if (sceneObjectType == Engine.SceneObjectType.VariantSetCollection) {
1584
- const stream = scene.getStreamForDescendentId(sceneObjectId);
1585
- stream?._addVariantCollection(sceneObjectId);
1586
- } else if (sceneObjectType == Engine.SceneObjectType.VariantSet) {
1587
- const stream = scene.getStreamForDescendentId(sceneObjectId);
1588
- const name = client.getName(sceneObjectId);
1589
- const parentId = client.getSceneObjectParent(sceneObjectId);
1590
- stream?._addVariant(parentId, {
1591
- id: sceneObjectId,
1592
- name,
1593
- options: [],
1594
- nestedSets: []
1595
- });
1596
- } else if (sceneObjectType == Engine.SceneObjectType.VariantSetOption) {
1597
- const stream = scene.getStreamForDescendentId(sceneObjectId);
1598
- const name = client.getName(sceneObjectId);
1599
- const parentId = client.getSceneObjectParent(sceneObjectId);
1600
- stream?._addVariant(parentId, {
1601
- id: sceneObjectId,
1602
- name,
1603
- type: "option"
1604
- });
1605
- }
1606
- }
1607
- for (const sceneObjectId of engine.deletedObjectIdsView(this.#changeIds)) {
1608
- const lod = lods.forId(sceneObjectId);
1609
- if (!lod) {
1610
- continue;
1611
- }
1612
- const entry = new Change({ type: "deleted", lod });
1613
- this.#changes.push(entry);
1614
- }
1615
- for (const sceneObjectId of engine.modifiedObjectIdsView(this.#changeIds)) {
1616
- const sceneObjectType = client.getSceneObjectType(sceneObjectId);
1617
- if (sceneObjectType === Engine.SceneObjectType.LodOctree) {
1618
- scene._onFeatureData(sceneObjectId);
1619
- } else if (sceneObjectType === Engine.SceneObjectType.GaussianSplats) {
1620
- const bounds = this.#retrieveFloatArray(
1621
- sceneObjectId,
1622
- 6,
1623
- client.getWorldBoundingBox.bind(client)
1624
- );
1625
- const lodIndex = client.getLodIndex(sceneObjectId);
1626
- const attributeInfo = new engine.AttributeInfo();
1627
- const attributeInfoHigh = new engine.AttributeInfo();
1628
- try {
1629
- let attribute = this.#getDataFromAttribute(
1630
- client,
1631
- sceneObjectId,
1632
- AttributeNames.SPARK_EXTENDED_SPLAT_LOW,
1633
- attributeInfo
1634
- );
1635
- let attributeHigh = null;
1636
- let useExtSplats = true;
1637
- if (attribute === null) {
1638
- attribute = this.#getDataFromAttribute(
1639
- client,
1640
- sceneObjectId,
1641
- AttributeNames.SPARK_PACKED_SPLAT,
1642
- attributeInfo
1643
- );
1644
- useExtSplats = false;
1645
- } else {
1646
- attributeHigh = this.#getDataFromAttribute(
1647
- client,
1648
- sceneObjectId,
1649
- AttributeNames.SPARK_EXTENDED_SPLAT_HIGH,
1650
- attributeInfoHigh
1651
- );
1652
- }
1653
- if (attribute === null) {
1654
- console.error(
1655
- `Could not retrieve primary splats attribute for scene object ${sceneObjectId}! skipping scene object`
1656
- );
1657
- continue;
1658
- }
1659
- const lod = lods.forId(sceneObjectId);
1660
- if (!lod) {
1661
- console.warn(
1662
- `Received modified event for LOD ${sceneObjectId} which does not exist.`
1663
- );
1664
- continue;
1665
- }
1666
- lod.splats = attribute?.paddedData;
1667
- lod.splatsExtendedData = attributeHigh?.paddedData ?? null;
1668
- lod.useExtSplats = useExtSplats;
1669
- lod.bounds = bounds;
1670
- lod.lodIndex = lodIndex;
1671
- lod.paddingCount = (attribute?.paddedData.length - attribute.originalSize) / 4;
1672
- this.#addSphericalHarmonicsToLod(scene, sceneObjectId, lod);
1673
- const entry = new Change({ type: "modified", lod });
1674
- this.#changes.push(entry);
1675
- if (this.#pendingActivations.delete(sceneObjectId)) {
1676
- this.#changes.push(new Change({ type: "activated", lod }));
1677
- for (const [, deactLod] of this.#pendingDeactivations) {
1678
- this.#changes.push(
1679
- new Change({ type: "deactivated", lod: deactLod })
1680
- );
1681
- }
1682
- this.#pendingDeactivations.clear();
1683
- }
1684
- } finally {
1685
- attributeInfo.delete();
1686
- attributeInfoHigh.delete();
1687
- }
1688
- }
1689
- }
1690
- if (this.#changes.some((c) => c.type === "created")) {
1691
- try {
1692
- const metadata = new engine.SceneMetadata();
1693
- client.getSceneMetadata(metadata);
1694
- this.onColorSpaceDetected(metadata.inputColorSpace === "linear");
1695
- metadata.delete();
1696
- } catch (e) {
1697
- console.warn("Failed to read scene metadata:", e);
1698
- }
1699
- }
1700
- let deferredActivationsThisFrame = false;
1701
- for (const sceneObjectId of engine.activatedObjectIdsView(
1702
- this.#changeIds
1703
- )) {
1704
- const sceneObjectType = client.getSceneObjectType(sceneObjectId);
1705
- if (sceneObjectType == Engine.SceneObjectType.GaussianSplats) {
1706
- const lod = lods.forId(sceneObjectId);
1707
- if (lod && lod.splats) {
1708
- const entry = new Change({ type: "activated", lod });
1709
- this.#changes.push(entry);
1710
- } else if (lod) {
1711
- this.#pendingActivations.add(sceneObjectId);
1712
- deferredActivationsThisFrame = true;
1713
- }
1714
- }
1715
- }
1716
- for (const sceneObjectId of engine.deactivatedObjectIdsView(
1717
- this.#changeIds
1718
- )) {
1719
- const sceneObjectType = client.getSceneObjectType(sceneObjectId);
1720
- if (sceneObjectType == Engine.SceneObjectType.GaussianSplats) {
1721
- this.#pendingActivations.delete(sceneObjectId);
1722
- if (!createdLodIds.has(sceneObjectId)) {
1723
- const lod = lods.forId(sceneObjectId);
1724
- if (lod && lod.splats) {
1725
- if (deferredActivationsThisFrame) {
1726
- this.#pendingDeactivations.set(sceneObjectId, lod);
1727
- } else {
1728
- const entry = new Change({ type: "deactivated", lod });
1729
- this.#changes.push(entry);
1730
- }
1731
- }
1732
- }
1733
- }
1734
- }
1735
- }
1736
- #addSphericalHarmonicsToLod(scene, sceneObjectId, outLod) {
1737
- const { engine } = this;
1738
- const { client } = scene;
1739
- const getAndAssignSh = (packedName, extName, setter) => {
1740
- const attributeName = outLod.useExtSplats ? extName : packedName;
1741
- if (client.hasAttribute(sceneObjectId, attributeName)) {
1742
- const attributeInfo = new engine.AttributeInfo();
1743
- try {
1744
- const attribute = this.#getDataFromAttribute(
1745
- client,
1746
- sceneObjectId,
1747
- attributeName,
1748
- attributeInfo
1749
- );
1750
- if (attribute !== null) {
1751
- setter(attribute.paddedData, attributeInfo.maxValue.x);
1752
- }
1753
- } finally {
1754
- attributeInfo.delete();
1755
- }
1756
- }
1757
- };
1758
- getAndAssignSh(
1759
- AttributeNames.SPARK_PACKED_SH1,
1760
- AttributeNames.SPARK_EXTENDED_SH1,
1761
- (data, max) => outLod.setSh1(data, max)
1762
- );
1763
- getAndAssignSh(
1764
- AttributeNames.SPARK_PACKED_SH2,
1765
- AttributeNames.SPARK_EXTENDED_SH2,
1766
- (data, max) => outLod.setSh2(data, max)
1767
- );
1768
- getAndAssignSh(
1769
- AttributeNames.SPARK_PACKED_SH3,
1770
- AttributeNames.SPARK_EXTENDED_SH3_A,
1771
- (data, max) => outLod.setSh3(data, max)
1772
- );
1773
- getAndAssignSh(
1774
- AttributeNames.UNUSED,
1775
- AttributeNames.SPARK_EXTENDED_SH3_B,
1776
- (data, _max) => outLod.sh3ExtendedData = data
1777
- );
1778
- }
1779
- update() {
1780
- this.#hostDriven = true;
1781
- this._update();
1782
- let needsRender = false;
1783
- for (const scene of this.#scenes) {
1784
- if (scene.client.takeRenderRequired()) {
1785
- needsRender = true;
1786
- }
1787
- }
1788
- return needsRender || this._computeAdditionalRenderNeeded();
1789
- }
1790
- applyChanges(_entries) {
1791
- }
1792
- _computeAdditionalRenderNeeded() {
1793
- return false;
1794
- }
1795
- onColorSpaceDetected(_isLinear) {
1796
- }
1797
- // prettier-ignore
1798
- add(scene) {
1799
- this.#scenes.add(scene);
1800
- }
1801
- delete(scene) {
1802
- this.#scenes.delete(scene);
1803
- if (scene.miris) scene.close();
1804
- if (this.#scenes.size === 0 && this.#changeIds !== null) {
1805
- this.#changeIds.delete();
1806
- this.#changeIds = null;
1807
- }
1808
- }
770
+ /**
771
+ * Reads a small raw uint32 attribute (e.g. sparse-octant childOctantOffsets) directly, without the
772
+ * spark per-splat padding applied by getDataFromAttribute. Returns a copy of the values, or null if
773
+ * the attribute is absent or empty. Ownership stays with the C++ client (no takeAttribute).
774
+ */
775
+ function getRawUint32Attribute(engine, client, sceneObjectId, attributeName) {
776
+ if (!client.hasAttribute(sceneObjectId, attributeName)) return null;
777
+ const attributeInfo = new engine.AttributeInfo();
778
+ try {
779
+ const { ptr } = attributeInfo.$$;
780
+ if (client.getAttribute(sceneObjectId, attributeName, ptr) !== Engine.AquaStatus.Success) return null;
781
+ const view = engine.dataPtrView(attributeInfo);
782
+ if (view.length === 0) return null;
783
+ return view.slice();
784
+ } finally {
785
+ attributeInfo.delete();
786
+ }
1809
787
  }
1810
- class Camera {
1811
- update() {
1812
- const { engine } = this;
1813
- const { client } = this.scene;
1814
- const matrixBuffer = engine.malloc(this.#matrix.length * 4);
1815
- engine.heapF32.set(Float32Array.from(this.#matrix), matrixBuffer / 4);
1816
- client.setMainCameraTransform(matrixBuffer);
1817
- engine.free(matrixBuffer);
1818
- client.setMainCameraViewFrustum(
1819
- this.#aspect,
1820
- this.#fov,
1821
- this.#near,
1822
- this.#far
1823
- );
1824
- }
1825
- #aspect;
1826
- get aspect() {
1827
- return this.#aspect;
1828
- }
1829
- set aspect(aspect) {
1830
- this.#aspect = aspect;
1831
- }
1832
- #fov;
1833
- get fov() {
1834
- return this.#fov;
1835
- }
1836
- set fov(fov) {
1837
- this.#fov = fov;
1838
- }
1839
- #near;
1840
- get near() {
1841
- return this.#near;
1842
- }
1843
- set near(near) {
1844
- this.#near = near;
1845
- }
1846
- #far;
1847
- get far() {
1848
- return this.#far;
1849
- }
1850
- set far(far) {
1851
- this.#far = far;
1852
- }
1853
- #matrix;
1854
- get matrix() {
1855
- return this.#matrix;
1856
- }
1857
- set matrix(matrix) {
1858
- this.#matrix = matrix;
1859
- }
1860
- constructor({ aspect, fov, near, far, matrix, scene }) {
1861
- this.#aspect = aspect;
1862
- this.#fov = fov;
1863
- this.#near = near;
1864
- this.#far = far;
1865
- this.#matrix = matrix;
1866
- Object.defineProperties(this, {
1867
- scene: { value: scene },
1868
- miris: { value: scene.miris },
1869
- engine: { value: scene.miris.engine }
1870
- });
1871
- }
788
+ function getDataFromAttribute(engine, client, sceneObjectId, attributeName, outAttributeInfo) {
789
+ if (!client.hasAttribute(sceneObjectId, attributeName)) return null;
790
+ const { ptr } = outAttributeInfo.$$;
791
+ const status = client.getAttribute(sceneObjectId, attributeName, ptr);
792
+ if (status !== Engine.AquaStatus.Success) {
793
+ console.warn(`GetAttribute failed for object id ${sceneObjectId} and attribute name ${attributeName}: status ${status}`);
794
+ return null;
795
+ }
796
+ let paddedData;
797
+ let originalSizeInUints;
798
+ if (outAttributeInfo.clientSideId != 0n) ({paddedData: paddedData, originalSizeInUints: originalSizeInUints} = AttributeCache.get(Number(outAttributeInfo.clientSideId)));
799
+ else {
800
+ const result = sparkAttributeFromRaw(attributeName, 0, engine.dataPtrView(outAttributeInfo));
801
+ paddedData = result.paddedData;
802
+ originalSizeInUints = result.originalSizeInUints;
803
+ console.log(`retrieved a attribute ${attributeName} with size ${result.originalSizeInUints} for chunk ${sceneObjectId}`);
804
+ const myCacheEntry = AttributeCache.add({
805
+ paddedData: result.paddedData,
806
+ originalSizeInUints: result.originalSizeInUints
807
+ });
808
+ const takeStatus = client.takeAttribute(sceneObjectId, attributeName, BigInt(myCacheEntry));
809
+ if (takeStatus !== Engine.AquaStatus.Success) {
810
+ AttributeCache.remove(myCacheEntry);
811
+ console.warn(`Failed to take attribute ${attributeName} for scene object ${sceneObjectId}: status ${takeStatus}`);
812
+ return null;
813
+ }
814
+ }
815
+ return {
816
+ paddedData,
817
+ originalSizeInUints
818
+ };
1872
819
  }
1873
- class Client {
1874
- #viewerKey = null;
1875
- get viewerKey() {
1876
- return this.#viewerKey;
1877
- }
1878
- set viewerKey(key) {
1879
- if (key) {
1880
- this.setAssetViewerKey(key);
1881
- }
1882
- this.#viewerKey = key;
1883
- }
1884
- constructor({ engine, context }) {
1885
- Object.defineProperties(this, {
1886
- engine: { value: engine, enumerable: true },
1887
- handle: { value: engine.createClient(context), enumerable: true }
1888
- });
1889
- }
1890
- dispose() {
1891
- if (this.engine.destroyClient(this.handle) !== Engine.AquaStatus.Success) {
1892
- console.error(`Failed to destroy client with handle '${this.handle}'`);
1893
- }
1894
- }
1895
- addStreamById(...args) {
1896
- return this.engine.addStreamById(this.handle, ...args);
1897
- }
1898
- destroyClient(...args) {
1899
- return this.engine.destroyClient(this.handle, ...args);
1900
- }
1901
- getAssetsAsync(...args) {
1902
- return this.engine.getAssetsAsync(this.handle, ...args);
1903
- }
1904
- getAttribute(...args) {
1905
- return this.engine.getAttribute(this.handle, ...args);
1906
- }
1907
- getDefaultCameraId(...args) {
1908
- return this.engine.getDefaultCameraId(this.handle, ...args);
1909
- }
1910
- getLocalBoundingBox(...args) {
1911
- return this.engine.getLocalBoundingBox(this.handle, ...args);
1912
- }
1913
- getWorldBoundingBox(...args) {
1914
- return this.engine.getWorldBoundingBox(this.handle, ...args);
1915
- }
1916
- getLodIndex(...args) {
1917
- return this.engine.getLodIndex(this.handle, ...args);
1918
- }
1919
- getSceneChanges(...args) {
1920
- return this.engine.getSceneChanges(this.handle, ...args);
1921
- }
1922
- getSceneChangesCounts(...args) {
1923
- return this.engine.getSceneChangesCounts(this.handle, ...args);
1924
- }
1925
- getSceneMetadata(...args) {
1926
- return this.engine.getSceneMetadata(this.handle, ...args);
1927
- }
1928
- getSceneObjectParent(...args) {
1929
- return this.engine.getSceneObjectParent(this.handle, ...args);
1930
- }
1931
- getSceneObjectType(...args) {
1932
- return this.engine.getSceneObjectType(this.handle, ...args);
1933
- }
1934
- getLocalTransform(...args) {
1935
- return this.engine.getLocalTransform(this.handle, ...args);
1936
- }
1937
- getWorldTransform(...args) {
1938
- return this.engine.getWorldTransform(this.handle, ...args);
1939
- }
1940
- hasAttribute(...args) {
1941
- return this.engine.hasAttribute(this.handle, ...args);
1942
- }
1943
- isSceneObjectAncestorOf(...args) {
1944
- return this.engine.isSceneObjectAncestorOf(this.handle, ...args);
1945
- }
1946
- lockScene(...args) {
1947
- return this.engine.lockScene(this.handle, ...args);
1948
- }
1949
- removeStream(...args) {
1950
- return this.engine.removeStream(this.handle, ...args);
1951
- }
1952
- setAssetViewerKey(...args) {
1953
- return this.engine.setAssetViewerKey(this.handle, ...args);
1954
- }
1955
- setClientSpatialFormat(...args) {
1956
- return this.engine.setClientSpatialFormat(this.handle, ...args);
1957
- }
1958
- setRuntimeSettings(...args) {
1959
- return this.engine.setRuntimeSettings(this.handle, ...args);
1960
- }
1961
- setMainCameraTransform(...args) {
1962
- return this.engine.setMainCameraTransform(this.handle, ...args);
1963
- }
1964
- setMainCameraViewFrustum(...args) {
1965
- return this.engine.setMainCameraViewFrustum(this.handle, ...args);
1966
- }
1967
- setSceneObjectTransform(...args) {
1968
- return this.engine.setSceneObjectTransform(this.handle, ...args);
1969
- }
1970
- hasFeature(...args) {
1971
- return this.engine.hasFeature(this.handle, ...args);
1972
- }
1973
- getFeatureVersion(...args) {
1974
- return this.engine.getFeatureVersion(this.handle, ...args);
1975
- }
1976
- getFeatureState(...args) {
1977
- return this.engine.getFeatureState(this.handle, ...args);
1978
- }
1979
- getName(...args) {
1980
- return this.engine.getName(this.handle, ...args);
1981
- }
1982
- setVariantSelection(...args) {
1983
- return this.engine.setVariantSelection(this.handle, ...args);
1984
- }
1985
- takeAttribute(...args) {
1986
- return this.engine.takeAttribute(this.handle, ...args);
1987
- }
1988
- takeEvictedClientSideAttributeIds(...args) {
1989
- return this.engine.takeEvictedClientSideAttributeIds(this.handle, ...args);
1990
- }
1991
- takeRenderRequired(...args) {
1992
- return this.engine.takeRenderRequired(this.handle, ...args);
1993
- }
1994
- unlockScene(...args) {
1995
- return this.engine.unlockScene(this.handle, ...args);
1996
- }
1997
- updateSceneExecution(...args) {
1998
- return this.engine.updateSceneExecution(this.handle, ...args);
1999
- }
2000
- recordFrameTime(...args) {
2001
- return this.engine.recordFrameTime(this.handle, ...args);
2002
- }
820
+ //#endregion
821
+ //#region packages/core/lod.ts
822
+ var LodStore = class {
823
+ #keyMap = /* @__PURE__ */ new Map();
824
+ #idMap = /* @__PURE__ */ new Map();
825
+ forKey(key) {
826
+ return this.#keyMap.get(key);
827
+ }
828
+ forId(id) {
829
+ return this.#idMap.get(id);
830
+ }
831
+ setKey(key, lod) {
832
+ this.#keyMap.set(key, lod);
833
+ }
834
+ setId(id, lod) {
835
+ return this.#idMap.set(id, lod);
836
+ }
837
+ delete(lod) {
838
+ this.#keyMap.delete(lod.key);
839
+ this.#idMap.delete(lod.id);
840
+ }
841
+ deleteKey(key) {
842
+ this.#keyMap.delete(key);
843
+ }
844
+ deleteId(id) {
845
+ this.#idMap.delete(id);
846
+ }
847
+ };
848
+ var Lod = class {
849
+ #client;
850
+ #key;
851
+ #cachedWorldBounds = null;
852
+ #localBounds = null;
853
+ #transform = null;
854
+ #lodIndex = null;
855
+ #paddingSplatsCount = 0;
856
+ #drawnOctantMask = 255;
857
+ #octantOffsets = null;
858
+ #octantOffsetsRead = false;
859
+ get key() {
860
+ return this.#key ?? null;
861
+ }
862
+ set key(key) {
863
+ this.store.deleteKey(this.key);
864
+ if (key || 0 === key) this.store.setKey(key, this);
865
+ this.#key = key;
866
+ }
867
+ set bounds(bounds) {
868
+ this.#cachedWorldBounds = bounds;
869
+ }
870
+ /**
871
+ * Retrieves the cached world bounds of this object
872
+ *
873
+ * @deprecated Retrieve the local bounds and transform as needed
874
+ */
875
+ get bounds() {
876
+ console.warn("`bounds` is deprecated, use `localBounds` instead");
877
+ return this.#cachedWorldBounds;
878
+ }
879
+ /**
880
+ * Sets the local bounds of this lod
881
+ */
882
+ set localBounds(bounds) {
883
+ this.#localBounds = bounds;
884
+ }
885
+ /**
886
+ * Retrieves the local bounds of this lod
887
+ */
888
+ get localBounds() {
889
+ return this.#localBounds;
890
+ }
891
+ set lodIndex(index) {
892
+ this.#lodIndex = index;
893
+ }
894
+ get lodIndex() {
895
+ return this.#lodIndex;
896
+ }
897
+ set paddingSplatsCount(count) {
898
+ this.#paddingSplatsCount = count;
899
+ }
900
+ get paddingSplatsCount() {
901
+ return this.#paddingSplatsCount;
902
+ }
903
+ set transform(transform) {
904
+ this.#transform = transform;
905
+ }
906
+ get transform() {
907
+ return this.#transform;
908
+ }
909
+ get _drawnOctantMask() {
910
+ return this.#drawnOctantMask;
911
+ }
912
+ set _drawnOctantMask(mask) {
913
+ this.#drawnOctantMask = mask;
914
+ }
915
+ get _octantOffsets() {
916
+ return this.#octantOffsets;
917
+ }
918
+ get _hasOctantOffsets() {
919
+ return this.#octantOffsets !== null;
920
+ }
921
+ _readOctantOffsets(engine) {
922
+ if (this.#octantOffsetsRead) return;
923
+ this.#octantOffsetsRead = true;
924
+ const offsets = getRawUint32Attribute(engine, this.#client, this.id, AttributeNames.OCTANT_OFFSETS);
925
+ if (offsets && offsets.length === 7) this.#octantOffsets = offsets;
926
+ }
927
+ hasAttribute(attributeName) {
928
+ return this.#client.hasAttribute(this.id, attributeName);
929
+ }
930
+ getDataFromAttribute(engine, attributeName, attributeInfo) {
931
+ return getDataFromAttribute(engine, this.#client, this.id, attributeName, attributeInfo);
932
+ }
933
+ dispose() {
934
+ const key = this.#key;
935
+ key?.dispose?.();
936
+ this.store.delete(this);
937
+ this.#key = null;
938
+ key?.dispose?.();
939
+ this.#cachedWorldBounds = null;
940
+ this.#localBounds = null;
941
+ this.#transform = null;
942
+ this.modelRoot?.lods?.delete(this);
943
+ }
944
+ constructor({ id, modelRoot, lodStore, client }) {
945
+ Object.defineProperties(this, {
946
+ id: { value: id },
947
+ modelRoot: { value: modelRoot },
948
+ store: { value: lodStore }
949
+ });
950
+ this.#client = client;
951
+ lodStore.setId(id, this);
952
+ modelRoot.add(this);
953
+ }
954
+ };
955
+ //#endregion
956
+ //#region packages/core/change.ts
957
+ var Change = class {
958
+ constructor({ type, lod }) {
959
+ Object.defineProperties(this, {
960
+ type: { value: type },
961
+ lod: { value: lod }
962
+ });
963
+ }
964
+ };
965
+ //#endregion
966
+ //#region packages/core/modelRoot.ts
967
+ var ModelRoot = class ModelRoot {
968
+ static #keyMap = /* @__PURE__ */ new Map();
969
+ static #idMap = /* @__PURE__ */ new Map();
970
+ static forKey(key) {
971
+ return this.#keyMap.get(key);
972
+ }
973
+ static forId(id) {
974
+ return this.#idMap.get(id);
975
+ }
976
+ #key;
977
+ get key() {
978
+ return this.#key ?? null;
979
+ }
980
+ set key(key) {
981
+ ModelRoot.#keyMap.delete(this.key);
982
+ if (key || 0 === key) ModelRoot.#keyMap.set(key, this);
983
+ this.#key = key;
984
+ }
985
+ #lods = /* @__PURE__ */ new Set();
986
+ get lods() {
987
+ return this.#lods;
988
+ }
989
+ #transform;
990
+ set transform(transform) {
991
+ this.#transform = transform;
992
+ }
993
+ get transform() {
994
+ return this.#transform;
995
+ }
996
+ constructor({ id, stream }) {
997
+ Object.defineProperties(this, {
998
+ id: { value: id },
999
+ stream: { value: stream }
1000
+ });
1001
+ ModelRoot.#idMap.set(id, this);
1002
+ stream.add(this);
1003
+ }
1004
+ add(lod) {
1005
+ this.#lods.add(lod);
1006
+ }
1007
+ dispose() {
1008
+ const lods = [...this.#lods];
1009
+ this.#lods.clear();
1010
+ for (const lod of lods) lod.dispose();
1011
+ ModelRoot.#keyMap.delete(this.key);
1012
+ ModelRoot.#idMap.delete(this.id);
1013
+ this.#key = null;
1014
+ }
1015
+ };
1016
+ //#endregion
1017
+ //#region packages/core/stream.ts
1018
+ var Stream = class Stream extends EventTarget {
1019
+ static _idMap = /* @__PURE__ */ new Map();
1020
+ static _keyMap = /* @__PURE__ */ new Map();
1021
+ static forId(id) {
1022
+ if (!id) return;
1023
+ return this._idMap.get(id);
1024
+ }
1025
+ static forKey(key) {
1026
+ return this._keyMap.get(key);
1027
+ }
1028
+ #key;
1029
+ #loadedRenderableData = false;
1030
+ #variantHierarchies = {};
1031
+ #defaultCameraId = null;
1032
+ /**
1033
+ * @internal
1034
+ */
1035
+ _addVariantCollection(hierarchyId) {
1036
+ if (!this.#variantHierarchies[hierarchyId]) this.#variantHierarchies[hierarchyId] = {
1037
+ id: hierarchyId,
1038
+ children: []
1039
+ };
1040
+ }
1041
+ /**
1042
+ * @internal
1043
+ */
1044
+ _findAndAddToVariantSet(parentId, variant) {
1045
+ const addToNode = (node) => {
1046
+ if (!node) return false;
1047
+ if (node.id === parentId) {
1048
+ if (node.children) node.children.push(variant);
1049
+ else if (variant.type === "option") {
1050
+ if (!node.options) node.options = [];
1051
+ node.options.push(variant);
1052
+ } else {
1053
+ if (!node.nestedSets) node.nestedSets = [];
1054
+ node.nestedSets.push(variant);
1055
+ }
1056
+ return true;
1057
+ }
1058
+ if (Array.isArray(node.children)) {
1059
+ for (const child of node.children) if (addToNode(child)) return true;
1060
+ }
1061
+ if (Array.isArray(node.nestedSets)) {
1062
+ for (const nested of node.nestedSets) if (addToNode(nested)) return true;
1063
+ }
1064
+ if (Array.isArray(node.options)) {
1065
+ for (const option of node.options) if (addToNode(option)) return true;
1066
+ }
1067
+ return false;
1068
+ };
1069
+ for (const hierarchy of Object.values(this.#variantHierarchies)) if (addToNode(hierarchy)) return;
1070
+ }
1071
+ /**
1072
+ * @internal
1073
+ */
1074
+ _addVariant(parentId, variant) {
1075
+ this._findAndAddToVariantSet(parentId, variant);
1076
+ }
1077
+ /**
1078
+ * @internal
1079
+ */
1080
+ _exportVariantHierarchies() {
1081
+ return Object.entries(this.#variantHierarchies).map(([hierarchyId, hierarchy]) => ({
1082
+ hierarchyId: Number(hierarchyId),
1083
+ hierarchy
1084
+ }));
1085
+ }
1086
+ /**
1087
+ * @internal
1088
+ */
1089
+ _setVariantSelection(variantId) {
1090
+ this.client.setVariantSelection(variantId);
1091
+ }
1092
+ get key() {
1093
+ return this.#key ?? null;
1094
+ }
1095
+ set key(key) {
1096
+ Stream._keyMap.delete(this.key);
1097
+ if (key || 0 === key) Stream._keyMap.set(key, this);
1098
+ this.#key = key;
1099
+ }
1100
+ #matrix = [
1101
+ 1,
1102
+ 0,
1103
+ 0,
1104
+ 0,
1105
+ 0,
1106
+ 1,
1107
+ 0,
1108
+ 0,
1109
+ 0,
1110
+ 0,
1111
+ 1,
1112
+ 0,
1113
+ 0,
1114
+ 0,
1115
+ 0,
1116
+ 1
1117
+ ];
1118
+ get matrix() {
1119
+ return this.#matrix;
1120
+ }
1121
+ set matrix(matrix) {
1122
+ this.#matrix = matrix;
1123
+ const { engine, client } = this;
1124
+ const matrixBuffer = engine.malloc(this.#matrix.length * 4);
1125
+ engine.heapF32.set(Float32Array.from(this.#matrix), matrixBuffer / 4);
1126
+ client.setSceneObjectTransform(this.id, matrixBuffer);
1127
+ engine.free(matrixBuffer);
1128
+ }
1129
+ #opacity = 1;
1130
+ get opacity() {
1131
+ return this.#opacity;
1132
+ }
1133
+ set opacity(opacity) {
1134
+ this.#opacity = Math.min(1, Math.max(0, opacity));
1135
+ }
1136
+ get boundingBox() {
1137
+ const { engine, client } = this;
1138
+ const boxBuffer = engine.malloc(24);
1139
+ client.getWorldBoundingBox(this.id, boxBuffer);
1140
+ const [cX, cY, cZ, dX, dY, dZ] = Float32Array.from(engine.heapF32.subarray(boxBuffer / 4, boxBuffer / 4 + 6));
1141
+ if (cX === void 0 || cY === void 0 || cZ === void 0 || dX === void 0 || dY === void 0 || dZ === void 0) return;
1142
+ const box = {
1143
+ min: {
1144
+ x: cX - dX / 2,
1145
+ y: cY - dY / 2,
1146
+ z: cZ - dZ / 2
1147
+ },
1148
+ max: {
1149
+ x: cX + dX / 2,
1150
+ y: cY + dY / 2,
1151
+ z: cZ + dZ / 2
1152
+ },
1153
+ size: {
1154
+ x: dX,
1155
+ y: dY,
1156
+ z: dZ
1157
+ },
1158
+ center: {
1159
+ x: cX,
1160
+ y: cY,
1161
+ z: cZ
1162
+ }
1163
+ };
1164
+ Object.freeze(box);
1165
+ return box;
1166
+ }
1167
+ #modelRoots = /* @__PURE__ */ new Set();
1168
+ get modelRoots() {
1169
+ return new Set(this.#modelRoots);
1170
+ }
1171
+ /**
1172
+ * @deprecated Use `modelRoots` instead.
1173
+ */
1174
+ get chunks() {
1175
+ return this.modelRoots;
1176
+ }
1177
+ constructor(options) {
1178
+ super();
1179
+ const { scene, uuid } = options;
1180
+ Object.defineProperties(this, {
1181
+ uuid: {
1182
+ value: uuid,
1183
+ enumerable: true
1184
+ },
1185
+ scene: {
1186
+ value: scene,
1187
+ enumerable: true
1188
+ },
1189
+ client: {
1190
+ value: scene.client,
1191
+ enumerable: true
1192
+ },
1193
+ miris: {
1194
+ value: scene.miris,
1195
+ enumerable: true
1196
+ },
1197
+ engine: {
1198
+ value: scene.miris.engine,
1199
+ enumerable: true
1200
+ }
1201
+ });
1202
+ this._initStream(options);
1203
+ Stream._idMap.set(this.id, this);
1204
+ scene.add(this);
1205
+ }
1206
+ _initStream({ uuid }) {
1207
+ const id = this.client.addStreamById(uuid, uuid, false);
1208
+ Object.defineProperty(this, "id", { value: id });
1209
+ }
1210
+ /**
1211
+ * @internal
1212
+ */
1213
+ async _onStreamLoaded() {
1214
+ if (this.#loadedRenderableData) return;
1215
+ const defaultCameraId = this.client.getDefaultCameraId(this.id);
1216
+ this.#defaultCameraId = defaultCameraId >= 0 ? defaultCameraId : null;
1217
+ this.dispatchEvent(new Event("streamloaded"));
1218
+ this.scene._onSceneLoaded(this);
1219
+ this.#loadedRenderableData = true;
1220
+ }
1221
+ getDefaultCameraTransform() {
1222
+ if (this.#defaultCameraId === null) return null;
1223
+ return this.miris.getWorldTransform(this.client, this.#defaultCameraId);
1224
+ }
1225
+ /**
1226
+ * Returns the oriented bounding box of this stream's authored /Miris/ViewingVolume
1227
+ * prim, or null if no viewing volume is present in this stream's loaded structure.
1228
+ *
1229
+ * `min`/`max` are in the prim's local space and `matrix` is its
1230
+ * local-to-world transform, so the box stays oriented instead of collapsing
1231
+ * to a world AABB. This matches how the asset pipeline places cameras in the
1232
+ * volume (see ViewingVolumeCameraGenerator).
1233
+ * @internal
1234
+ */
1235
+ _getViewingVolumeObb() {
1236
+ const viewingVolumeId = this.client.getViewingVolumeId(this.id);
1237
+ if (viewingVolumeId < 0) return null;
1238
+ const matrix = this.miris.getWorldTransform(this.client, viewingVolumeId);
1239
+ if (!matrix) return null;
1240
+ const { engine, client } = this;
1241
+ const boxBuffer = engine.malloc(24);
1242
+ try {
1243
+ client.getLocalBoundingBox(viewingVolumeId, boxBuffer);
1244
+ const box = Float32Array.from(engine.heapF32.subarray(boxBuffer / 4, boxBuffer / 4 + 6));
1245
+ if (box.length < 6 || !box.every((value) => Number.isFinite(value))) return null;
1246
+ const [cX = 0, cY = 0, cZ = 0, dX = 0, dY = 0, dZ = 0] = box;
1247
+ return {
1248
+ min: [
1249
+ cX - dX / 2,
1250
+ cY - dY / 2,
1251
+ cZ - dZ / 2
1252
+ ],
1253
+ max: [
1254
+ cX + dX / 2,
1255
+ cY + dY / 2,
1256
+ cZ + dZ / 2
1257
+ ],
1258
+ matrix
1259
+ };
1260
+ } finally {
1261
+ engine.free(boxBuffer);
1262
+ }
1263
+ }
1264
+ /**
1265
+ * @internal
1266
+ */
1267
+ _onRootLoaded() {
1268
+ this.dispatchEvent(new Event("rootloaded"));
1269
+ }
1270
+ add(modelRoot) {
1271
+ this.#modelRoots.add(modelRoot);
1272
+ }
1273
+ end() {
1274
+ console.log("ending the stream");
1275
+ this.client.removeStream(this.id);
1276
+ for (const modelRoot of this.#modelRoots) modelRoot.dispose();
1277
+ this.#modelRoots.clear();
1278
+ Stream._idMap.delete(this.id);
1279
+ Stream._keyMap.delete(this.key);
1280
+ if (this.scene.streams.has(this)) this.scene.delete(this);
1281
+ }
1282
+ };
1283
+ //#endregion
1284
+ //#region packages/core/rate.ts
1285
+ var RATES = [
1286
+ 30,
1287
+ 60,
1288
+ 72,
1289
+ 90,
1290
+ 120,
1291
+ 144,
1292
+ 165,
1293
+ 240
1294
+ ];
1295
+ function createRefreshRateDetector() {
1296
+ let samples = [], last = null, hz = 0;
1297
+ screen.addEventListener?.("change", () => {
1298
+ samples = [];
1299
+ hz = 0;
1300
+ last = null;
1301
+ });
1302
+ return {
1303
+ update(ts) {
1304
+ if (hz) return;
1305
+ if (last !== null) {
1306
+ samples.push(ts - last);
1307
+ if (samples.length > 60) samples.shift();
1308
+ if (!hz && samples.length === 60) {
1309
+ const meanHz = 1e3 / (samples.reduce((a, b) => a + b, 0) / samples.length);
1310
+ hz = RATES.reduce((a, b) => Math.abs(b - meanHz) < Math.abs(a - meanHz) ? b : a);
1311
+ }
1312
+ }
1313
+ last = ts;
1314
+ },
1315
+ get nativeHz() {
1316
+ return hz;
1317
+ }
1318
+ };
2003
1319
  }
2004
- class Scene extends EventTarget {
2005
- static #idMap = /* @__PURE__ */ new Map();
2006
- static #keyMap = /* @__PURE__ */ new Map();
2007
- // Associated camera
2008
- #camera = null;
2009
- get camera() {
2010
- return this.#camera;
2011
- }
2012
- set camera(camera) {
2013
- this.#camera = camera;
2014
- }
2015
- #defaultCameraId = null;
2016
- static forId(id) {
2017
- return Scene.#idMap.get(id);
2018
- }
2019
- static forKey(key) {
2020
- return Scene.#keyMap.get(key);
2021
- }
2022
- #key;
2023
- get key() {
2024
- return this.#key ?? null;
2025
- }
2026
- set key(key) {
2027
- Scene.#keyMap.delete(this.key);
2028
- if (key || 0 === key) Scene.#keyMap.set(key, this);
2029
- this.#key = key;
2030
- }
2031
- #streams = /* @__PURE__ */ new Set();
2032
- #streamObjectIdToStream = /* @__PURE__ */ new Map();
2033
- get viewerKey() {
2034
- return this.client.viewerKey;
2035
- }
2036
- set viewerKey(viewerKey) {
2037
- if (viewerKey) this.client.viewerKey = viewerKey;
2038
- }
2039
- get streams() {
2040
- return new Set(this.#streams);
2041
- }
2042
- #lods = new LodStore();
2043
- get lods() {
2044
- return this.#lods;
2045
- }
2046
- constructor({ miris, viewerKey }) {
2047
- super();
2048
- Object.defineProperties(this, {
2049
- miris: { value: miris, enumerable: true },
2050
- engine: { value: miris.engine, enumerable: true },
2051
- client: {
2052
- value: new Client({
2053
- engine: miris.engine,
2054
- context: miris.sharedContext
2055
- })
2056
- }
2057
- });
2058
- if (viewerKey) this.viewerKey = viewerKey;
2059
- const spatialFormat = new this.engine.SpatialFormat();
2060
- spatialFormat.metersPerUnit = 1;
2061
- spatialFormat.upAxis = this.engine.UpAxis.Y;
2062
- spatialFormat.matrixOrder = this.engine.MatrixOrder.ColumnMajor;
2063
- spatialFormat.handedness = this.engine.Handedness.Right;
2064
- this.client.setClientSpatialFormat(spatialFormat);
2065
- spatialFormat.delete();
2066
- Scene.#idMap.set(this.id, this);
2067
- miris.add(this);
2068
- }
2069
- dispose() {
2070
- this.close();
2071
- this.client.dispose();
2072
- }
2073
- #updateSceneCameraData() {
2074
- const defaultCameraId = this.client.getDefaultCameraId();
2075
- this.#defaultCameraId = defaultCameraId >= 0 ? defaultCameraId : null;
2076
- }
2077
- async fetchAssets(tags) {
2078
- if (!this.viewerKey) {
2079
- throw new Error("Could not fetch assets because there is no viewer key");
2080
- }
2081
- const vector = new this.engine.StringVector();
2082
- let _tags = [];
2083
- if (typeof tags === "string") _tags = tags.split(",");
2084
- else if (tags?.[Symbol.iterator]) _tags = [...tags];
2085
- for (const tag of _tags) vector.push_back(tag);
2086
- const _assets = await this.client.getAssetsAsync(vector);
2087
- const assets = [];
2088
- const decoder = new TextDecoder();
2089
- for (const { name, tags: tags2, thumbnailUrl, uuid } of _assets) {
2090
- const asset = {
2091
- name,
2092
- thumbnailUrl,
2093
- uuid,
2094
- tags: []
2095
- };
2096
- const size = tags2.size();
2097
- for (let index = 0; index < size; index += 1) {
2098
- let tag = tags2.get(index);
2099
- if (tag) {
2100
- if (typeof tag !== "string") tag = decoder.decode(tag);
2101
- asset.tags.push(tag);
2102
- }
2103
- }
2104
- assets.push(asset);
2105
- }
2106
- vector.delete();
2107
- return assets;
2108
- }
2109
- getDefaultCameraTransform() {
2110
- if (this.#defaultCameraId === null) return null;
2111
- return this.miris.getWorldTransform(this.client, this.#defaultCameraId);
2112
- }
2113
- add(stream) {
2114
- this.#streams.add(stream);
2115
- this.#streamObjectIdToStream.set(stream.id, stream);
2116
- }
2117
- getStreamForId(streamObjectId) {
2118
- return this.#streamObjectIdToStream.get(streamObjectId);
2119
- }
2120
- getStreamForDescendentId(descendentObjectId) {
2121
- for (const [streamObjectId, stream] of this.#streamObjectIdToStream) {
2122
- if (this.client.isSceneObjectAncestorOf(streamObjectId, descendentObjectId)) {
2123
- return stream;
2124
- }
2125
- }
2126
- return null;
2127
- }
2128
- getModelRootForDescendentId(descendentObjectId) {
2129
- for (const [, stream] of this.#streamObjectIdToStream) {
2130
- for (const modelRoot of stream.modelRoots) {
2131
- if (this.client.isSceneObjectAncestorOf(modelRoot.id, descendentObjectId)) {
2132
- return modelRoot;
2133
- }
2134
- }
2135
- }
2136
- return null;
2137
- }
2138
- /**
2139
- * @internal
2140
- */
2141
- async _getDrMap(sceneObjectId) {
2142
- if (!this.client.hasFeature(sceneObjectId, Engine.Feature.DrMap)) return null;
2143
- if (this.client.getFeatureState(sceneObjectId, Engine.Feature.DrMap) !== Engine.FeatureState.Loaded)
2144
- return null;
2145
- const version = this.client.getFeatureVersion(
2146
- sceneObjectId,
2147
- Engine.Feature.DrMap
2148
- );
2149
- if (version === 1) {
2150
- const attrName = `drMap_v${version}`;
2151
- const attrInfo = new this.engine.AttributeInfo();
2152
- try {
2153
- const status = this.client.getAttribute(
2154
- sceneObjectId,
2155
- attrName,
2156
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2157
- attrInfo.$$.ptr
2158
- // embind $$.ptr typed at build time by binding post-processor
2159
- );
2160
- if (status !== Engine.AquaStatus.Success) return null;
2161
- const wasmView = this.engine.dataPtrView(attrInfo);
2162
- const pngBytes = new Uint8Array(wasmView.buffer).subarray(
2163
- wasmView.byteOffset,
2164
- wasmView.byteOffset + wasmView.byteLength
2165
- ).slice();
2166
- const blob2 = new Blob([pngBytes], { type: "image/png" });
2167
- return await createImageBitmap(blob2);
2168
- } finally {
2169
- attrInfo.delete();
2170
- }
2171
- }
2172
- console.warn(`getDrMap: unsupported DR map version ${version}`);
2173
- return null;
2174
- }
2175
- /**
2176
- * @internal
2177
- */
2178
- async _onFeatureData(sceneObjectId) {
2179
- const bitmap = await this._getDrMap(sceneObjectId);
2180
- this.dispatchEvent(new CustomEvent("drmaploaded", { detail: { bitmap, sceneObjectId } }));
2181
- }
2182
- /**
2183
- * @internal
2184
- */
2185
- _onSceneLoaded() {
2186
- this.#updateSceneCameraData();
2187
- this.dispatchEvent(new Event("sceneloaded"));
2188
- }
2189
- delete(stream) {
2190
- this.#streams.delete(stream);
2191
- this.#streamObjectIdToStream.delete(stream.id);
2192
- if (Stream.forId(stream.id)) stream.end();
2193
- }
2194
- close() {
2195
- for (const stream of this.streams) {
2196
- stream.end();
2197
- }
2198
- Scene.#idMap.delete(this.id);
2199
- Scene.#keyMap.delete(this.key);
2200
- if (this.miris.scenes.has(this)) this.miris.delete(this);
2201
- }
1320
+ //#endregion
1321
+ //#region packages/core/miris.ts
1322
+ /**
1323
+ * The main Miris application.
1324
+ *
1325
+ * @remarks
1326
+ * This class is initialized asynchronously, so synchronous operations may
1327
+ * fail if Miris is not ready. To ensure Miris is ready, await `miris.ready`
1328
+ * or get `miris.pending`.
1329
+ */
1330
+ var Miris = class Miris {
1331
+ static tryUseShark = typeof window !== "undefined" && new URLSearchParams(window.location.search).get("shark") === "1";
1332
+ static _instance;
1333
+ static async instance() {
1334
+ const miris = this._instance ??= new this();
1335
+ await miris.ready;
1336
+ return miris;
1337
+ }
1338
+ #sharedContext;
1339
+ get sharedContext() {
1340
+ return this.#sharedContext;
1341
+ }
1342
+ #viewerKey;
1343
+ get viewerKey() {
1344
+ return this.#viewerKey;
1345
+ }
1346
+ set viewerKey(viewerKey) {
1347
+ this.#viewerKey = viewerKey;
1348
+ }
1349
+ #scenes = /* @__PURE__ */ new Set();
1350
+ get scenes() {
1351
+ return new Set(this.#scenes);
1352
+ }
1353
+ #changes = [];
1354
+ #changeIds = null;
1355
+ #pendingActivations = /* @__PURE__ */ new Set();
1356
+ #pendingDeactivations = /* @__PURE__ */ new Map();
1357
+ #useSphericalHarmonics = true;
1358
+ get useSphericalHarmonics() {
1359
+ return this.#useSphericalHarmonics;
1360
+ }
1361
+ set useSphericalHarmonics(value) {
1362
+ this.#useSphericalHarmonics = value;
1363
+ }
1364
+ constructor() {
1365
+ if (!this.constructor.prototype._instance) this.constructor.prototype._instance = this;
1366
+ Object.defineProperties(this, {
1367
+ pending: {
1368
+ value: true,
1369
+ configurable: true,
1370
+ enumerable: true
1371
+ },
1372
+ engine: {
1373
+ value: new Engine(),
1374
+ enumerable: true
1375
+ }
1376
+ });
1377
+ Object.defineProperty(this, "ready", {
1378
+ enumerable: true,
1379
+ value: this.#initializeMiris()
1380
+ });
1381
+ console.assert?.(this._xrModeActive === false);
1382
+ this.#bindRequestAnimationFrame();
1383
+ }
1384
+ async #initializeMiris() {
1385
+ const { engine } = this;
1386
+ await engine.ready;
1387
+ this.#sharedContext = this.engine.createContext();
1388
+ const mb = 1048576;
1389
+ const maxCacheSizeParam = new URLSearchParams(window.location.search).get("aquaMaxCacheSize");
1390
+ let maxCacheSizeMB = 0;
1391
+ if (maxCacheSizeParam) {
1392
+ const parsedSize = parseInt(maxCacheSizeParam, 10);
1393
+ if (!isNaN(parsedSize) && parsedSize > 0) maxCacheSizeMB = parsedSize;
1394
+ }
1395
+ if (maxCacheSizeMB > 0) this.engine.setMaxCacheSize(maxCacheSizeMB * mb);
1396
+ else if (navigator.userAgent.includes("iPhone")) this.engine.setMaxCacheSize(128 * mb);
1397
+ else if (navigator.userAgent.includes("Android")) this.engine.setMaxCacheSize(256 * mb);
1398
+ this.#browserUpdate();
1399
+ Object.defineProperty(this, "pending", {
1400
+ value: false,
1401
+ configurable: false
1402
+ });
1403
+ return this;
1404
+ }
1405
+ dispose() {
1406
+ if (this.#sharedContext) {
1407
+ if (this.engine.destroyContext(this.#sharedContext) !== Engine.AquaStatus.Success) console.error(`Failed to destroy aqua context with handle '${this.#sharedContext}'`);
1408
+ this.#sharedContext = 0;
1409
+ }
1410
+ }
1411
+ updateParentedTransform(_modelTransform, _parentTransform) {}
1412
+ #detector = createRefreshRateDetector();
1413
+ #boundUpdate = this.#browserUpdate.bind(this);
1414
+ #hostDriven = false;
1415
+ #lastFrameTimestamp = null;
1416
+ #lastUpdateTs = -1;
1417
+ #targetFramesPerSecond = 72;
1418
+ #splatCountBudgetOverride = null;
1419
+ _xrModeActive = false;
1420
+ _xrSession = null;
1421
+ _requestAnimationFrame = null;
1422
+ signalResumeFromIdle() {}
1423
+ #buildRuntimeSettings() {
1424
+ const settings = new this.engine.RuntimeSettings();
1425
+ settings.targetFramesPerSecond = this.#targetFramesPerSecond;
1426
+ settings.xrModeActive = this._xrModeActive;
1427
+ if (this.#splatCountBudgetOverride !== null) settings.splatCountBudget = this.#splatCountBudgetOverride;
1428
+ else if (this._xrModeActive) settings.splatCountBudget = Miris._XR_SPLAT_COUNT_BUDGET;
1429
+ if (Miris.tryUseShark) settings.splatCountBudgetCap = Miris._sharkSplatBudgetCap();
1430
+ return settings;
1431
+ }
1432
+ #applyDisplaySettings() {
1433
+ const settings = this.#buildRuntimeSettings();
1434
+ for (const scene of this.#scenes) scene.client.setRuntimeSettings(settings);
1435
+ settings.delete();
1436
+ }
1437
+ get _splatCountBudget() {
1438
+ const settings = this.#buildRuntimeSettings();
1439
+ const budget = settings.splatCountBudget;
1440
+ settings.delete();
1441
+ return budget;
1442
+ }
1443
+ /**
1444
+ * Why 43? Because the AVP throttles down to 45Hz :(
1445
+ */
1446
+ static _XR_TARGET_FRAME_RATE = 43;
1447
+ /**
1448
+ * @internal
1449
+ * The splat budget an XR session runs at unless overridden.
1450
+ */
1451
+ static _XR_SPLAT_COUNT_BUDGET = 2e5;
1452
+ /**
1453
+ * @internal
1454
+ * Shark's GPU splat capacity. A lower limit on mobile to avoid excessive memory allocations in
1455
+ * case we occasionally budget over a million prims (most phones can't do this).
1456
+ */
1457
+ static _SHARK_SPLAT_CAPACITY_MOBILE = 1048576;
1458
+ static _SHARK_SPLAT_CAPACITY_DESKTOP = 3e6;
1459
+ /**
1460
+ * @internal
1461
+ * The cap on what the solver may budget, held ~20% under the GPU capacity above (the same
1462
+ * margin Unity's SharkSplatRenderSystem uses). Leaves headroom for un-garbage collected splats.
1463
+ */
1464
+ static _SHARK_SPLAT_BUDGET_CAP_MOBILE = 85e4;
1465
+ static _SHARK_SPLAT_BUDGET_CAP_DESKTOP = 25e5;
1466
+ /**
1467
+ * @internal
1468
+ * Copied from spork so the dependency is not introduced to core.
1469
+ * iPad OS 13+ Safari defaults to desktop-class browsing and sends a
1470
+ * Macintosh UA carrying no iPad token, so use the touchPoints.
1471
+ */
1472
+ static _isMobileDevice() {
1473
+ if (navigator.platform.toLowerCase().startsWith("win")) return false;
1474
+ if (navigator.maxTouchPoints > 0) return true;
1475
+ return /Mobi|Android|iPhone|iPad|iPod|Opera Mini|IEMobile/.test(navigator.userAgent);
1476
+ }
1477
+ /**
1478
+ * @internal
1479
+ */
1480
+ static _sharkSplatCapacity() {
1481
+ return Miris._isMobileDevice() ? Miris._SHARK_SPLAT_CAPACITY_MOBILE : Miris._SHARK_SPLAT_CAPACITY_DESKTOP;
1482
+ }
1483
+ /**
1484
+ * @internal
1485
+ */
1486
+ static _sharkSplatBudgetCap() {
1487
+ return Miris._isMobileDevice() ? Miris._SHARK_SPLAT_BUDGET_CAP_MOBILE : Miris._SHARK_SPLAT_BUDGET_CAP_DESKTOP;
1488
+ }
1489
+ #bindRequestAnimationFrame() {
1490
+ this._requestAnimationFrame = this._xrModeActive ? this._xrSession.requestAnimationFrame.bind(this._xrSession) : window.requestAnimationFrame.bind(window);
1491
+ }
1492
+ /**
1493
+ * @internal
1494
+ */
1495
+ _setTargetFrameRate(frameRate) {
1496
+ this.#targetFramesPerSecond = frameRate;
1497
+ this.#detector = null;
1498
+ this.#applyDisplaySettings();
1499
+ }
1500
+ /**
1501
+ * @internal
1502
+ */
1503
+ _setXRModeActive(active, frameRate, xrSession) {
1504
+ this._xrModeActive = active;
1505
+ this._xrSession = xrSession ?? null;
1506
+ if (frameRate !== void 0) this.#targetFramesPerSecond = frameRate;
1507
+ this.#applyDisplaySettings();
1508
+ this.#bindRequestAnimationFrame();
1509
+ }
1510
+ /**
1511
+ * @internal
1512
+ */
1513
+ _setSplatCountBudgetOverride(budget) {
1514
+ this.#splatCountBudgetOverride = budget;
1515
+ this.#applyDisplaySettings();
1516
+ }
1517
+ #browserUpdate(ts = 0) {
1518
+ if (this.#hostDriven) return;
1519
+ this._update(ts);
1520
+ if (this._xrModeActive) return;
1521
+ requestAnimationFrame(this.#boundUpdate);
1522
+ }
1523
+ /**
1524
+ * @internal
1525
+ *
1526
+ * Shared update function being driven by browser's update loop or an XR session
1527
+ */
1528
+ _update(ts = 0) {
1529
+ if (ts !== 0 && ts === this.#lastUpdateTs) return;
1530
+ this.#lastUpdateTs = ts;
1531
+ if (this.#detector) {
1532
+ this.#detector.update(performance.now());
1533
+ if (this.#detector.nativeHz > 0) {
1534
+ const hz = this.#detector.nativeHz;
1535
+ this.#targetFramesPerSecond = hz <= 40 ? hz : 40;
1536
+ this.#applyDisplaySettings();
1537
+ this.#detector = null;
1538
+ }
1539
+ }
1540
+ const now = performance.now();
1541
+ const elapsed = this.#lastFrameTimestamp === null ? null : now - this.#lastFrameTimestamp;
1542
+ this.#lastFrameTimestamp = now;
1543
+ const frameTimeMs = elapsed !== null && elapsed <= 1e3 ? elapsed : null;
1544
+ if (this.#sharedContext) this.engine.beginFrame(this.#sharedContext, frameTimeMs ?? 0);
1545
+ for (const scene of this.#scenes) {
1546
+ const { client } = scene;
1547
+ client.updateSceneExecution();
1548
+ const evicted = client.takeEvictedClientSideAttributeIds();
1549
+ try {
1550
+ const evictedSize = evicted.size();
1551
+ if (evictedSize > 0) {
1552
+ const evictedArray = [];
1553
+ for (let i = 0; i < evictedSize; i++) evictedArray.push(Number(evicted.get(i)));
1554
+ AttributeCache.remove(evictedArray);
1555
+ }
1556
+ } finally {
1557
+ evicted.delete();
1558
+ }
1559
+ const checkSumWasm = this.engine.getActiveClientSideIdsCheckSum();
1560
+ AttributeCache.validateCheckSum(checkSumWasm);
1561
+ if (!client.lockScene()) return;
1562
+ try {
1563
+ this.#updateScene(scene);
1564
+ } finally {
1565
+ client.unlockScene();
1566
+ }
1567
+ }
1568
+ if (this.#changes.length) {
1569
+ this.applyChanges(this.#changes);
1570
+ this.#changes.length = 0;
1571
+ }
1572
+ }
1573
+ getLocalTransform(client, sceneObjectId) {
1574
+ if (Number.isInteger(sceneObjectId) && sceneObjectId >= 0) return retrieveFloatArray(this.engine, sceneObjectId, 16, client.getLocalTransform.bind(client));
1575
+ }
1576
+ getWorldTransform(client, sceneObjectId) {
1577
+ if (Number.isInteger(sceneObjectId) && sceneObjectId >= 0) return retrieveFloatArray(this.engine, sceneObjectId, 16, client.getWorldTransform.bind(client));
1578
+ }
1579
+ #shouldUpdateSceneChanges() {
1580
+ if (!this.#changeIds) return false;
1581
+ if (this.#changeIds.createdObjectsCount > 0) return true;
1582
+ if (this.#changeIds.activatedObjectsCount > 0) return true;
1583
+ if (this.#changeIds.deactivatedObjectsCount > 0) return true;
1584
+ if (this.#changeIds.modifiedObjectsCount > 0) return true;
1585
+ if (this.#changeIds.deletedObjectsCount > 0) return true;
1586
+ if (this.#changeIds.remaskedObjectsCount > 0) return true;
1587
+ return false;
1588
+ }
1589
+ #updateScene(scene) {
1590
+ const { engine } = this;
1591
+ const { client, camera, lods } = scene;
1592
+ if (camera) camera.update();
1593
+ if (this.#changeIds === null) this.#changeIds = new engine.SceneChangeIds();
1594
+ client.getSceneChangesCounts(this.#changeIds);
1595
+ if (!this.#shouldUpdateSceneChanges()) return;
1596
+ engine.allocateSceneChangesArrays(this.#changeIds);
1597
+ client.getSceneChanges(this.#changeIds);
1598
+ const createdLodIds = /* @__PURE__ */ new Set();
1599
+ for (const sceneObjectId of engine.createdObjectIdsView(this.#changeIds)) {
1600
+ const sceneObjectType = client.getSceneObjectType(sceneObjectId);
1601
+ if (sceneObjectType === Engine.SceneObjectType.StreamObject) {
1602
+ Stream.forId(sceneObjectId);
1603
+ continue;
1604
+ } else if (sceneObjectType === Engine.SceneObjectType.ModelRoot) {
1605
+ const stream = scene.getStreamForDescendentId(sceneObjectId);
1606
+ if (!stream) continue;
1607
+ const modelRoot = new ModelRoot({
1608
+ id: sceneObjectId,
1609
+ stream
1610
+ });
1611
+ const modelRootTransform = this.getLocalTransform(client, sceneObjectId);
1612
+ if (!modelRootTransform) continue;
1613
+ const parentId = client.getSceneObjectParent(sceneObjectId);
1614
+ const parentTransform = this.getLocalTransform(client, parentId);
1615
+ if (!parentTransform) continue;
1616
+ const updatedTransform = this.updateParentedTransform(modelRootTransform, parentTransform);
1617
+ if (!updatedTransform) continue;
1618
+ modelRoot.transform = updatedTransform;
1619
+ } else if (sceneObjectType === Engine.SceneObjectType.LodOctree) {
1620
+ const modelRoot = ModelRoot.forId(client.getSceneObjectParent(sceneObjectId));
1621
+ if (!modelRoot) continue;
1622
+ const formatVersion = client.getAssetFormatVersion(sceneObjectId);
1623
+ scene._recordAssetFormat(modelRoot, formatVersion);
1624
+ } else if (sceneObjectType == Engine.SceneObjectType.GaussianSplats) {
1625
+ const modelRoot = scene.getModelRootForDescendentId(sceneObjectId);
1626
+ if (!modelRoot) continue;
1627
+ const lod = new Lod({
1628
+ id: sceneObjectId,
1629
+ modelRoot,
1630
+ lodStore: lods,
1631
+ client
1632
+ });
1633
+ lod.transform = this.getLocalTransform(client, sceneObjectId);
1634
+ createdLodIds.add(sceneObjectId);
1635
+ const entry = new Change({
1636
+ type: "created",
1637
+ lod
1638
+ });
1639
+ this.#changes.push(entry);
1640
+ } else if (sceneObjectType == Engine.SceneObjectType.VariantSetCollection) scene.getStreamForDescendentId(sceneObjectId)?._addVariantCollection(sceneObjectId);
1641
+ else if (sceneObjectType == Engine.SceneObjectType.VariantSet) {
1642
+ const stream = scene.getStreamForDescendentId(sceneObjectId);
1643
+ const name = client.getName(sceneObjectId);
1644
+ const parentId = client.getSceneObjectParent(sceneObjectId);
1645
+ stream?._addVariant(parentId, {
1646
+ id: sceneObjectId,
1647
+ name,
1648
+ options: [],
1649
+ nestedSets: []
1650
+ });
1651
+ } else if (sceneObjectType == Engine.SceneObjectType.VariantSetOption) {
1652
+ const stream = scene.getStreamForDescendentId(sceneObjectId);
1653
+ const name = client.getName(sceneObjectId);
1654
+ const parentId = client.getSceneObjectParent(sceneObjectId);
1655
+ stream?._addVariant(parentId, {
1656
+ id: sceneObjectId,
1657
+ name,
1658
+ type: "option"
1659
+ });
1660
+ }
1661
+ }
1662
+ for (const sceneObjectId of engine.deletedObjectIdsView(this.#changeIds)) {
1663
+ const lod = lods.forId(sceneObjectId);
1664
+ if (!lod) continue;
1665
+ const entry = new Change({
1666
+ type: "deleted",
1667
+ lod
1668
+ });
1669
+ this.#changes.push(entry);
1670
+ }
1671
+ for (const sceneObjectId of engine.modifiedObjectIdsView(this.#changeIds)) {
1672
+ const sceneObjectType = client.getSceneObjectType(sceneObjectId);
1673
+ if (sceneObjectType === Engine.SceneObjectType.LodOctree) scene._onFeatureData(sceneObjectId);
1674
+ else if (sceneObjectType === Engine.SceneObjectType.GaussianSplats) {
1675
+ const lodIndex = client.getLodIndex(sceneObjectId);
1676
+ const lod = lods.forId(sceneObjectId);
1677
+ if (!lod) {
1678
+ console.warn(`Received modified event for LOD ${sceneObjectId} which does not exist.`);
1679
+ continue;
1680
+ }
1681
+ const worldBounds = retrieveFloatArray(this.engine, lod.id, 6, client.getWorldBoundingBox.bind(client));
1682
+ const localBounds = retrieveFloatArray(this.engine, lod.id, 6, client.getLocalBoundingBox.bind(client));
1683
+ lod.bounds = worldBounds;
1684
+ lod.localBounds = localBounds;
1685
+ lod.lodIndex = lodIndex;
1686
+ const entry = new Change({
1687
+ type: "modified",
1688
+ lod
1689
+ });
1690
+ this.#changes.push(entry);
1691
+ if (this.#pendingActivations.delete(sceneObjectId)) {
1692
+ this.#changes.push(new Change({
1693
+ type: "activated",
1694
+ lod
1695
+ }));
1696
+ for (const [, deactLod] of this.#pendingDeactivations) this.#changes.push(new Change({
1697
+ type: "deactivated",
1698
+ lod: deactLod
1699
+ }));
1700
+ this.#pendingDeactivations.clear();
1701
+ }
1702
+ }
1703
+ }
1704
+ if (this.#changes.some((c) => c.type === "created")) try {
1705
+ const metadata = new engine.SceneMetadata();
1706
+ client.getSceneMetadata(metadata);
1707
+ this.onColorSpaceDetected(metadata.inputColorSpace === "linear");
1708
+ metadata.delete();
1709
+ } catch (e) {
1710
+ console.warn("Failed to read scene metadata:", e);
1711
+ }
1712
+ for (const sceneObjectId of engine.activatedObjectIdsView(this.#changeIds)) if (client.getSceneObjectType(sceneObjectId) == Engine.SceneObjectType.GaussianSplats) {
1713
+ const lod = lods.forId(sceneObjectId);
1714
+ if (lod) {
1715
+ const entry = new Change({
1716
+ type: "activated",
1717
+ lod
1718
+ });
1719
+ this.#changes.push(entry);
1720
+ }
1721
+ }
1722
+ for (const sceneObjectId of engine.deactivatedObjectIdsView(this.#changeIds)) if (client.getSceneObjectType(sceneObjectId) == Engine.SceneObjectType.GaussianSplats) {
1723
+ this.#pendingActivations.delete(sceneObjectId);
1724
+ if (!createdLodIds.has(sceneObjectId)) {
1725
+ const lod = lods.forId(sceneObjectId);
1726
+ if (lod) {
1727
+ const entry = new Change({
1728
+ type: "deactivated",
1729
+ lod
1730
+ });
1731
+ this.#changes.push(entry);
1732
+ }
1733
+ }
1734
+ }
1735
+ for (const sceneObjectId of engine.remaskedObjectIdsView(this.#changeIds)) if (client.getSceneObjectType(sceneObjectId) == Engine.SceneObjectType.GaussianSplats) {
1736
+ const lod = lods.forId(sceneObjectId);
1737
+ if (lod) {
1738
+ lod._drawnOctantMask = client.getDrawnOctantMask(sceneObjectId);
1739
+ this.#changes.push(new Change({
1740
+ type: "remasked",
1741
+ lod
1742
+ }));
1743
+ }
1744
+ }
1745
+ }
1746
+ /**
1747
+ * @internal
1748
+ *
1749
+ * Drives one host's frame. Returns whether *that host's* canvas needs repainting.
1750
+ *
1751
+ * Both flags consulted here are consuming reads, and every scene on the page calls this once
1752
+ * per displayed frame from its own animation loop.
1753
+ *
1754
+ * @param scene the caller's scene - only its client's render flag is consumed.
1755
+ * @param ts the host's frame timestamp. If omitted, the document timeline supplies one.
1756
+ */
1757
+ _updateForScene(scene, ts) {
1758
+ this.#hostDriven = true;
1759
+ const frameToken = ts ?? Miris.#frameToken();
1760
+ this._update(frameToken);
1761
+ return scene.client.takeRenderRequired() || this.#additionalRenderNeededThisFrame(frameToken);
1762
+ }
1763
+ static #warnedWithoutFrameToken = false;
1764
+ /**
1765
+ * The token that tells one displayed frame from the next, for a host that did not supply one.
1766
+ *
1767
+ * document.timeline.currentTime is the clock requestAnimationFrame reports, and it holds still
1768
+ * for the whole frame - so every scene on the page reads the same value without the host
1769
+ * passing anything. An immersive XR session is the exception: XRFrame runs its own clock, and
1770
+ * that host has to pass its own timestamp.
1771
+ *
1772
+ * TODO: none of this should be necessary. Every <miris-scene> runs its own
1773
+ * renderer.setAnimationLoop, so a page of N scenes has N requestAnimationFrame loops, and a
1774
+ * frame token is only needed because those N callers have to agree on which frame they are in.
1775
+ * One loop for the page - Miris driving a single rAF, scenes reading their own render flag from
1776
+ * it - would make the frame boundary a fact rather than something inferred, and this helper,
1777
+ * #lastUpdateTs and #additionalRenderFrameTs would all go away with it.
1778
+ */
1779
+ static #frameToken() {
1780
+ const currentTime = Number(globalThis.document?.timeline?.currentTime);
1781
+ if (Number.isFinite(currentTime) && currentTime > 0) return currentTime;
1782
+ if (!Miris.#warnedWithoutFrameToken) {
1783
+ Miris.#warnedWithoutFrameToken = true;
1784
+ console.warn("Miris: no frame token available from document.timeline, so every update() counts as a new frame. Pass the host's frame timestamp to scene.update(ts) if this page holds more than one scene.");
1785
+ }
1786
+ return 0;
1787
+ }
1788
+ #additionalRenderFrameTs = -1;
1789
+ #additionalRenderNeeded = false;
1790
+ #additionalRenderNeededThisFrame(ts) {
1791
+ if (ts === 0 || ts !== this.#additionalRenderFrameTs) {
1792
+ this.#additionalRenderFrameTs = ts;
1793
+ this.#additionalRenderNeeded = this._computeAdditionalRenderNeeded();
1794
+ }
1795
+ return this.#additionalRenderNeeded;
1796
+ }
1797
+ applyChanges(_entries) {}
1798
+ _computeAdditionalRenderNeeded() {
1799
+ return false;
1800
+ }
1801
+ onColorSpaceDetected(_isLinear) {}
1802
+ add(scene) {
1803
+ this.#scenes.add(scene);
1804
+ const settings = this.#buildRuntimeSettings();
1805
+ scene.client.setRuntimeSettings(settings);
1806
+ settings.delete();
1807
+ }
1808
+ delete(scene) {
1809
+ this.#scenes.delete(scene);
1810
+ if (scene.miris) scene.close();
1811
+ if (this.#scenes.size === 0 && this.#changeIds !== null) {
1812
+ this.#changeIds.delete();
1813
+ this.#changeIds = null;
1814
+ }
1815
+ }
1816
+ };
1817
+ //#endregion
1818
+ //#region packages/core/camera.ts
1819
+ var Camera = class {
1820
+ update() {
1821
+ const { engine } = this;
1822
+ const { client } = this.scene;
1823
+ const matrixBuffer = engine.malloc(this.#matrix.length * 4);
1824
+ engine.heapF32.set(Float32Array.from(this.#matrix), matrixBuffer / 4);
1825
+ client.setMainCameraTransform(matrixBuffer);
1826
+ engine.free(matrixBuffer);
1827
+ client.setMainCameraViewFrustum(this.#aspect, this.#fov, this.#near, this.#far, this.#viewportHeight);
1828
+ }
1829
+ #viewportHeight = 0;
1830
+ get viewportHeight() {
1831
+ return this.#viewportHeight;
1832
+ }
1833
+ set viewportHeight(viewportHeight) {
1834
+ this.#viewportHeight = viewportHeight;
1835
+ }
1836
+ #aspect;
1837
+ get aspect() {
1838
+ return this.#aspect;
1839
+ }
1840
+ set aspect(aspect) {
1841
+ this.#aspect = aspect;
1842
+ }
1843
+ #fov;
1844
+ get fov() {
1845
+ return this.#fov;
1846
+ }
1847
+ set fov(fov) {
1848
+ this.#fov = fov;
1849
+ }
1850
+ #near;
1851
+ get near() {
1852
+ return this.#near;
1853
+ }
1854
+ set near(near) {
1855
+ this.#near = near;
1856
+ }
1857
+ #far;
1858
+ get far() {
1859
+ return this.#far;
1860
+ }
1861
+ set far(far) {
1862
+ this.#far = far;
1863
+ }
1864
+ #matrix;
1865
+ get matrix() {
1866
+ return this.#matrix;
1867
+ }
1868
+ set matrix(matrix) {
1869
+ this.#matrix = matrix;
1870
+ }
1871
+ constructor({ aspect, fov, near, far, matrix, scene, viewportHeight }) {
1872
+ this.#viewportHeight = viewportHeight ?? 0;
1873
+ this.#aspect = aspect;
1874
+ this.#fov = fov;
1875
+ this.#near = near;
1876
+ this.#far = far;
1877
+ this.#matrix = matrix;
1878
+ Object.defineProperties(this, {
1879
+ scene: { value: scene },
1880
+ miris: { value: scene.miris },
1881
+ engine: { value: scene.miris.engine }
1882
+ });
1883
+ }
1884
+ };
1885
+ //#endregion
1886
+ //#region packages/core/engine/client.ts
1887
+ var Client = class {
1888
+ #viewerKey = null;
1889
+ get viewerKey() {
1890
+ return this.#viewerKey;
1891
+ }
1892
+ set viewerKey(key) {
1893
+ if (key) this.setAssetViewerKey(key);
1894
+ this.#viewerKey = key;
1895
+ }
1896
+ constructor({ engine, context }) {
1897
+ Object.defineProperties(this, {
1898
+ engine: {
1899
+ value: engine,
1900
+ enumerable: true
1901
+ },
1902
+ handle: {
1903
+ value: engine.createClient(context),
1904
+ enumerable: true
1905
+ }
1906
+ });
1907
+ }
1908
+ dispose() {
1909
+ if (this.engine.destroyClient(this.handle) !== Engine.AquaStatus.Success) console.error(`Failed to destroy client with handle '${this.handle}'`);
1910
+ }
1911
+ addStreamById(...args) {
1912
+ return this.engine.addStreamById(this.handle, ...args);
1913
+ }
1914
+ destroyClient(...args) {
1915
+ return this.engine.destroyClient(this.handle, ...args);
1916
+ }
1917
+ getAssetsAsync(...args) {
1918
+ return this.engine.getAssetsAsync(this.handle, ...args);
1919
+ }
1920
+ getAttribute(...args) {
1921
+ return this.engine.getAttribute(this.handle, ...args);
1922
+ }
1923
+ getDefaultCameraId(...args) {
1924
+ return this.engine.getDefaultCameraId(this.handle, ...args);
1925
+ }
1926
+ getViewingVolumeId(...args) {
1927
+ return this.engine.getViewingVolumeId(this.handle, ...args);
1928
+ }
1929
+ getLocalBoundingBox(...args) {
1930
+ return this.engine.getLocalBoundingBox(this.handle, ...args);
1931
+ }
1932
+ getWorldBoundingBox(...args) {
1933
+ return this.engine.getWorldBoundingBox(this.handle, ...args);
1934
+ }
1935
+ getLodIndex(...args) {
1936
+ return this.engine.getLodIndex(this.handle, ...args);
1937
+ }
1938
+ getSceneChanges(...args) {
1939
+ return this.engine.getSceneChanges(this.handle, ...args);
1940
+ }
1941
+ getSceneChangesCounts(...args) {
1942
+ return this.engine.getSceneChangesCounts(this.handle, ...args);
1943
+ }
1944
+ getSceneMetadata(...args) {
1945
+ return this.engine.getSceneMetadata(this.handle, ...args);
1946
+ }
1947
+ getSceneObjectParent(...args) {
1948
+ return this.engine.getSceneObjectParent(this.handle, ...args);
1949
+ }
1950
+ getSceneObjectType(...args) {
1951
+ return this.engine.getSceneObjectType(this.handle, ...args);
1952
+ }
1953
+ getDrawnOctantMask(...args) {
1954
+ return this.engine.getDrawnOctantMask(this.handle, ...args);
1955
+ }
1956
+ getLocalTransform(...args) {
1957
+ return this.engine.getLocalTransform(this.handle, ...args);
1958
+ }
1959
+ getWorldTransform(...args) {
1960
+ return this.engine.getWorldTransform(this.handle, ...args);
1961
+ }
1962
+ hasAttribute(...args) {
1963
+ return this.engine.hasAttribute(this.handle, ...args);
1964
+ }
1965
+ isSceneObjectAncestorOf(...args) {
1966
+ return this.engine.isSceneObjectAncestorOf(this.handle, ...args);
1967
+ }
1968
+ lockScene(...args) {
1969
+ return this.engine.lockScene(this.handle, ...args);
1970
+ }
1971
+ removeStream(...args) {
1972
+ return this.engine.removeStream(this.handle, ...args);
1973
+ }
1974
+ setAssetViewerKey(...args) {
1975
+ return this.engine.setAssetViewerKey(this.handle, ...args);
1976
+ }
1977
+ setClientSpatialFormat(...args) {
1978
+ return this.engine.setClientSpatialFormat(this.handle, ...args);
1979
+ }
1980
+ setRuntimeSettings(...args) {
1981
+ return this.engine.setRuntimeSettings(this.handle, ...args);
1982
+ }
1983
+ setMainCameraTransform(...args) {
1984
+ return this.engine.setMainCameraTransform(this.handle, ...args);
1985
+ }
1986
+ setMainCameraViewFrustum(...args) {
1987
+ return this.engine.setMainCameraViewFrustum(this.handle, ...args);
1988
+ }
1989
+ setSceneObjectTransform(...args) {
1990
+ return this.engine.setSceneObjectTransform(this.handle, ...args);
1991
+ }
1992
+ hasFeature(...args) {
1993
+ return this.engine.hasFeature(this.handle, ...args);
1994
+ }
1995
+ getFeatureVersion(...args) {
1996
+ return this.engine.getFeatureVersion(this.handle, ...args);
1997
+ }
1998
+ getFeatureState(...args) {
1999
+ return this.engine.getFeatureState(this.handle, ...args);
2000
+ }
2001
+ getAssetFormatVersion(...args) {
2002
+ return this.engine.getAssetFormatVersion(this.handle, ...args);
2003
+ }
2004
+ getName(...args) {
2005
+ return this.engine.getName(this.handle, ...args);
2006
+ }
2007
+ setVariantSelection(...args) {
2008
+ return this.engine.setVariantSelection(this.handle, ...args);
2009
+ }
2010
+ takeAttribute(...args) {
2011
+ return this.engine.takeAttribute(this.handle, ...args);
2012
+ }
2013
+ takeEvictedClientSideAttributeIds(...args) {
2014
+ return this.engine.takeEvictedClientSideAttributeIds(this.handle, ...args);
2015
+ }
2016
+ takeRenderRequired(...args) {
2017
+ return this.engine.takeRenderRequired(this.handle, ...args);
2018
+ }
2019
+ unlockScene(...args) {
2020
+ return this.engine.unlockScene(this.handle, ...args);
2021
+ }
2022
+ updateSceneExecution(...args) {
2023
+ return this.engine.updateSceneExecution(this.handle, ...args);
2024
+ }
2025
+ };
2026
+ //#endregion
2027
+ //#region packages/core/assetFormat.ts
2028
+ var AssetFormat = {
2029
+ GaussianSplats: 1,
2030
+ GES: 2
2031
+ };
2032
+ var ASSET_FORMAT_NAMES = {
2033
+ [AssetFormat.GaussianSplats]: "gaussian splats",
2034
+ [AssetFormat.GES]: "GES"
2035
+ };
2036
+ function assetFormatName(formatVersion) {
2037
+ return ASSET_FORMAT_NAMES[formatVersion] ?? `unknown format ${formatVersion}`;
2202
2038
  }
2203
- export {
2204
- Camera,
2205
- Lod,
2206
- LodStore,
2207
- Miris,
2208
- ModelRoot,
2209
- Scene,
2210
- Stream
2039
+ //#endregion
2040
+ //#region packages/core/scene.ts
2041
+ var Scene = class Scene extends EventTarget {
2042
+ static #idMap = /* @__PURE__ */ new Map();
2043
+ static #keyMap = /* @__PURE__ */ new Map();
2044
+ #camera = null;
2045
+ get camera() {
2046
+ return this.#camera;
2047
+ }
2048
+ set camera(camera) {
2049
+ this.#camera = camera;
2050
+ }
2051
+ static forId(id) {
2052
+ return Scene.#idMap.get(id);
2053
+ }
2054
+ static forKey(key) {
2055
+ return Scene.#keyMap.get(key);
2056
+ }
2057
+ #key;
2058
+ get key() {
2059
+ return this.#key ?? null;
2060
+ }
2061
+ set key(key) {
2062
+ Scene.#keyMap.delete(this.key);
2063
+ if (key || 0 === key) Scene.#keyMap.set(key, this);
2064
+ this.#key = key;
2065
+ }
2066
+ #streams = /* @__PURE__ */ new Set();
2067
+ #streamObjectIdToStream = /* @__PURE__ */ new Map();
2068
+ #assetFormat = void 0;
2069
+ /**
2070
+ * @internal
2071
+ */
2072
+ get _assetFormat() {
2073
+ return this.#assetFormat;
2074
+ }
2075
+ get viewerKey() {
2076
+ return this.client.viewerKey;
2077
+ }
2078
+ set viewerKey(viewerKey) {
2079
+ if (viewerKey) this.client.viewerKey = viewerKey;
2080
+ }
2081
+ get streams() {
2082
+ return new Set(this.#streams);
2083
+ }
2084
+ #lods = new LodStore();
2085
+ get lods() {
2086
+ return this.#lods;
2087
+ }
2088
+ constructor({ miris, viewerKey }) {
2089
+ super();
2090
+ Object.defineProperties(this, {
2091
+ miris: {
2092
+ value: miris,
2093
+ enumerable: true
2094
+ },
2095
+ engine: {
2096
+ value: miris.engine,
2097
+ enumerable: true
2098
+ },
2099
+ client: { value: new Client({
2100
+ engine: miris.engine,
2101
+ context: miris.sharedContext
2102
+ }) }
2103
+ });
2104
+ if (viewerKey) this.viewerKey = viewerKey;
2105
+ const spatialFormat = new this.engine.SpatialFormat();
2106
+ spatialFormat.metersPerUnit = 1;
2107
+ spatialFormat.upAxis = this.engine.UpAxis.Y;
2108
+ spatialFormat.matrixOrder = this.engine.MatrixOrder.ColumnMajor;
2109
+ spatialFormat.handedness = this.engine.Handedness.Right;
2110
+ this.client.setClientSpatialFormat(spatialFormat);
2111
+ spatialFormat.delete();
2112
+ Scene.#idMap.set(this.id, this);
2113
+ miris.add(this);
2114
+ }
2115
+ /**
2116
+ * Drives a frame and answers whether *this* scene's canvas needs repainting. Call it once per
2117
+ * displayed frame from the host's animation loop, and render when it returns true.
2118
+ *
2119
+ * Every scene on the page calls this from its own loop. The first call in a displayed frame
2120
+ * drives one engine tick for all of them; the rest recognise the frame and reuse it.
2121
+ *
2122
+ * @param ts the host's frame timestamp. Optional - the document timeline supplies one, and it
2123
+ * reads the same for every scene in a displayed frame. Pass it when the host runs its own
2124
+ * clock, as an immersive XR session does, because XRFrame time is not the document timeline.
2125
+ */
2126
+ update(ts) {
2127
+ return this.miris._updateForScene(this, ts);
2128
+ }
2129
+ dispose() {
2130
+ this.close();
2131
+ this.client.dispose();
2132
+ }
2133
+ async fetchAssets(tags) {
2134
+ if (!this.viewerKey) throw new Error("Could not fetch assets because there is no viewer key");
2135
+ const vector = new this.engine.StringVector();
2136
+ let _tags = [];
2137
+ if (typeof tags === "string") _tags = tags.split(",");
2138
+ else if (tags?.[Symbol.iterator]) _tags = [...tags];
2139
+ for (const tag of _tags) vector.push_back(tag);
2140
+ const _assets = await this.client.getAssetsAsync(vector);
2141
+ const assets = [];
2142
+ const decoder = new TextDecoder();
2143
+ for (const { name, tags, thumbnailUrl, uuid } of _assets) {
2144
+ const asset = {
2145
+ name,
2146
+ thumbnailUrl,
2147
+ uuid,
2148
+ tags: []
2149
+ };
2150
+ const size = tags.size();
2151
+ for (let index = 0; index < size; index += 1) {
2152
+ let tag = tags.get(index);
2153
+ if (tag) {
2154
+ if (typeof tag !== "string") tag = decoder.decode(tag);
2155
+ asset.tags.push(tag);
2156
+ }
2157
+ }
2158
+ assets.push(asset);
2159
+ }
2160
+ vector.delete();
2161
+ return assets;
2162
+ }
2163
+ add(stream) {
2164
+ this.#streams.add(stream);
2165
+ this.#streamObjectIdToStream.set(stream.id, stream);
2166
+ }
2167
+ getStreamForId(streamObjectId) {
2168
+ return this.#streamObjectIdToStream.get(streamObjectId);
2169
+ }
2170
+ getStreamForDescendentId(descendentObjectId) {
2171
+ for (const [streamObjectId, stream] of this.#streamObjectIdToStream) if (this.client.isSceneObjectAncestorOf(streamObjectId, descendentObjectId)) return stream;
2172
+ return null;
2173
+ }
2174
+ getModelRootForDescendentId(descendentObjectId) {
2175
+ for (const [, stream] of this.#streamObjectIdToStream) for (const modelRoot of stream.modelRoots) if (this.client.isSceneObjectAncestorOf(modelRoot.id, descendentObjectId)) return modelRoot;
2176
+ return null;
2177
+ }
2178
+ _recordAssetFormat(modelRoot, formatVersion) {
2179
+ if (this.#assetFormat === void 0) {
2180
+ this.#assetFormat = formatVersion;
2181
+ return;
2182
+ }
2183
+ if (this.#assetFormat === formatVersion) return;
2184
+ console.error(`We don't yet support two or more assets with different format versions in the same scene: this one is rendering ${assetFormatName(this.#assetFormat)} and "${this.client.getName(modelRoot.id)}" is ${assetFormatName(formatVersion)}, so it will be drawn with the wrong pipeline.`);
2185
+ }
2186
+ /**
2187
+ * @internal
2188
+ */
2189
+ async _getFeatureMesh(sceneObjectId, feature, attrBase) {
2190
+ if (!this.client.hasFeature(sceneObjectId, feature)) return null;
2191
+ if (this.client.getFeatureState(sceneObjectId, feature) !== Engine.FeatureState.Loaded) return null;
2192
+ const version = this.client.getFeatureVersion(sceneObjectId, feature);
2193
+ if (version === 1) {
2194
+ const attrName = `${attrBase}_v${version}`;
2195
+ const attrInfo = new this.engine.AttributeInfo();
2196
+ try {
2197
+ if (this.client.getAttribute(sceneObjectId, attrName, attrInfo.$$.ptr) !== Engine.AquaStatus.Success) return null;
2198
+ if (attrInfo.clientSideId !== 0n) return AttributeCache.get(Number(attrInfo.clientSideId));
2199
+ const wasmView = this.engine.dataPtrView(attrInfo);
2200
+ const buffer = new Uint8Array(wasmView.buffer).subarray(wasmView.byteOffset, wasmView.byteOffset + wasmView.byteLength).slice().buffer;
2201
+ const cacheId = AttributeCache.add(buffer);
2202
+ const takeStatus = this.client.takeAttribute(sceneObjectId, attrName, BigInt(cacheId));
2203
+ if (takeStatus !== Engine.AquaStatus.Success) {
2204
+ AttributeCache.remove(cacheId);
2205
+ console.warn(`Failed to take attribute ${attrName} for scene object ${sceneObjectId}: status ${takeStatus}`);
2206
+ return null;
2207
+ }
2208
+ return buffer;
2209
+ } finally {
2210
+ attrInfo.delete();
2211
+ }
2212
+ }
2213
+ console.warn(`getFeatureMesh: unsupported version ${version} for feature ${feature}`);
2214
+ return null;
2215
+ }
2216
+ /**
2217
+ * @internal
2218
+ */
2219
+ async _getDrMap(sceneObjectId) {
2220
+ if (!this.client.hasFeature(sceneObjectId, Engine.Feature.DrMap)) return null;
2221
+ if (this.client.getFeatureState(sceneObjectId, Engine.Feature.DrMap) !== Engine.FeatureState.Loaded) return null;
2222
+ const version = this.client.getFeatureVersion(sceneObjectId, Engine.Feature.DrMap);
2223
+ if (version === 1 || version === 2) {
2224
+ const attrName = `drMap_v${version}`;
2225
+ const attrInfo = new this.engine.AttributeInfo();
2226
+ try {
2227
+ if (this.client.getAttribute(sceneObjectId, attrName, attrInfo.$$.ptr) !== Engine.AquaStatus.Success) return null;
2228
+ if (attrInfo.clientSideId !== 0n) {
2229
+ const cached = AttributeCache.get(Number(attrInfo.clientSideId));
2230
+ return cached !== void 0 ? {
2231
+ bytes: cached,
2232
+ version
2233
+ } : null;
2234
+ }
2235
+ const wasmView = this.engine.dataPtrView(attrInfo);
2236
+ const bytes = new Uint8Array(wasmView.buffer).subarray(wasmView.byteOffset, wasmView.byteOffset + wasmView.byteLength).slice();
2237
+ const cacheId = AttributeCache.add(bytes);
2238
+ console.log(`_getDrMap is calling takeAttribute for ${attrName} with id ${cacheId}`);
2239
+ const takeStatus = this.client.takeAttribute(sceneObjectId, attrName, BigInt(cacheId));
2240
+ if (takeStatus !== Engine.AquaStatus.Success) {
2241
+ AttributeCache.remove(cacheId);
2242
+ if (this.client.getAttribute(sceneObjectId, attrName, attrInfo.$$.ptr) === Engine.AquaStatus.Success && attrInfo.clientSideId !== 0n) {
2243
+ const cached = AttributeCache.get(Number(attrInfo.clientSideId));
2244
+ return cached !== void 0 ? {
2245
+ bytes: cached,
2246
+ version
2247
+ } : null;
2248
+ }
2249
+ console.warn(`getDrMap: failed to take attribute ${attrName} for scene object ${sceneObjectId}: status ${takeStatus}`);
2250
+ return null;
2251
+ }
2252
+ return {
2253
+ bytes,
2254
+ version
2255
+ };
2256
+ } finally {
2257
+ attrInfo.delete();
2258
+ }
2259
+ }
2260
+ console.warn(`getDrMap: unsupported DR map version ${version}`);
2261
+ return null;
2262
+ }
2263
+ /**
2264
+ * @internal
2265
+ */
2266
+ async _onFeatureData(sceneObjectId) {
2267
+ const drMapData = await this._getDrMap(sceneObjectId);
2268
+ if (drMapData !== null) this.dispatchEvent(new CustomEvent("drmaploaded", { detail: {
2269
+ bytes: drMapData.bytes,
2270
+ version: drMapData.version,
2271
+ sceneObjectId
2272
+ } }));
2273
+ const reflBuffer = await this._getFeatureMesh(sceneObjectId, Engine.Feature.ReflMesh, "reflMesh");
2274
+ if (reflBuffer !== null) this.dispatchEvent(new CustomEvent("reflmeshloaded", { detail: {
2275
+ buffer: reflBuffer,
2276
+ sceneObjectId
2277
+ } }));
2278
+ const glassBuffer = await this._getFeatureMesh(sceneObjectId, Engine.Feature.GlassMesh, "glassMesh");
2279
+ if (glassBuffer !== null) this.dispatchEvent(new CustomEvent("glassmeshloaded", { detail: {
2280
+ buffer: glassBuffer,
2281
+ sceneObjectId
2282
+ } }));
2283
+ }
2284
+ /**
2285
+ * @internal
2286
+ */
2287
+ _onSceneLoaded(stream) {
2288
+ this.dispatchEvent(new CustomEvent("sceneloaded", { detail: { stream } }));
2289
+ }
2290
+ delete(stream) {
2291
+ this.#streams.delete(stream);
2292
+ this.#streamObjectIdToStream.delete(stream.id);
2293
+ if (this.#streams.size === 0) this.#assetFormat = void 0;
2294
+ if (Stream.forId(stream.id)) stream.end();
2295
+ }
2296
+ close() {
2297
+ for (const stream of this.streams) stream.end();
2298
+ Scene.#idMap.delete(this.id);
2299
+ Scene.#keyMap.delete(this.key);
2300
+ if (this.miris.scenes.has(this)) this.miris.delete(this);
2301
+ }
2211
2302
  };
2303
+ //#endregion
2304
+ export { AssetFormat, AttributeNames, Camera, Lod, LodStore, Miris, ModelRoot, Scene, Stream, sparkAttributeList };