@onimaxxing/worldgen-node 0.15.0

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/oni_wasm.js ADDED
@@ -0,0 +1,1047 @@
1
+ /* @ts-self-types="./oni_wasm.d.ts" */
2
+
3
+ /**
4
+ * Drop the cached cluster. Snapshot edits persist.
5
+ */
6
+ function clear_cluster_cache() {
7
+ wasm.clear_cluster_cache();
8
+ }
9
+ exports.clear_cluster_cache = clear_cluster_cache;
10
+
11
+ /**
12
+ * Evaluate a noise tree over a `width × height` 2D grid and return
13
+ * one `f32` per cell, row-major (`y * width + x`). Values are
14
+ * unnormalised; the consumer applies any colour ramp.
15
+ *
16
+ * `tree_kind`:
17
+ * - `"named"`: look up `tree_value` in the live `SettingsCache.noise`
18
+ * map (the same map the editor mutates).
19
+ * - `"inline"`: parse `tree_value` as a YAML document in isolation.
20
+ *
21
+ * Output is bit-identical to the engine's own evaluation at the
22
+ * given seed. Sample coords map `width × height` linearly onto the
23
+ * tree's `settings.lowerBound..upperBound` rectangle (cell-centred),
24
+ * at `z = 0` (worldgen samples the XZ plane at y = 0).
25
+ * @param {string} tree_kind
26
+ * @param {string} tree_value
27
+ * @param {number} width
28
+ * @param {number} height
29
+ * @param {number} seed
30
+ * @returns {Float32Array}
31
+ */
32
+ function evaluate_noise(tree_kind, tree_value, width, height, seed) {
33
+ const ptr0 = passStringToWasm0(tree_kind, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
34
+ const len0 = WASM_VECTOR_LEN;
35
+ const ptr1 = passStringToWasm0(tree_value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
36
+ const len1 = WASM_VECTOR_LEN;
37
+ const ret = wasm.evaluate_noise(ptr0, len0, ptr1, len1, width, height, seed);
38
+ if (ret[3]) {
39
+ throw takeFromExternrefTable0(ret[2]);
40
+ }
41
+ var v3 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
42
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
43
+ return v3;
44
+ }
45
+ exports.evaluate_noise = evaluate_noise;
46
+
47
+ /**
48
+ * The ONI game build this WASM was parity-baselined against (e.g.
49
+ * `"737195"`).
50
+ * @returns {string}
51
+ */
52
+ function game_version() {
53
+ let deferred1_0;
54
+ let deferred1_1;
55
+ try {
56
+ const ret = wasm.game_version();
57
+ deferred1_0 = ret[0];
58
+ deferred1_1 = ret[1];
59
+ return getStringFromWasm0(ret[0], ret[1]);
60
+ } finally {
61
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
62
+ }
63
+ }
64
+ exports.game_version = game_version;
65
+
66
+ /**
67
+ * Generate a cluster by cluster id + seed. Returns a `ClusterResult`
68
+ * JSON envelope. For the coordinate-string form (story traits +
69
+ * mixing) use `generate_from_coordinate`.
70
+ * @param {number} seed
71
+ * @param {string} cluster_id
72
+ * @returns {string}
73
+ */
74
+ function generate_cluster(seed, cluster_id) {
75
+ let deferred2_0;
76
+ let deferred2_1;
77
+ try {
78
+ const ptr0 = passStringToWasm0(cluster_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
79
+ const len0 = WASM_VECTOR_LEN;
80
+ const ret = wasm.generate_cluster(seed, ptr0, len0);
81
+ deferred2_0 = ret[0];
82
+ deferred2_1 = ret[1];
83
+ return getStringFromWasm0(ret[0], ret[1]);
84
+ } finally {
85
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
86
+ }
87
+ }
88
+ exports.generate_cluster = generate_cluster;
89
+
90
+ /**
91
+ * Generate all worlds in a cluster and return per-cell polygon data for each.
92
+ *
93
+ * Returns JSON: `{ "cluster_id", "seed", "worlds": [{ "name", "width", "height", "is_starting", "cells": [...] }] }`
94
+ * @param {number} seed
95
+ * @param {string} cluster_id
96
+ * @returns {string}
97
+ */
98
+ function generate_cluster_cells(seed, cluster_id) {
99
+ let deferred2_0;
100
+ let deferred2_1;
101
+ try {
102
+ const ptr0 = passStringToWasm0(cluster_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
103
+ const len0 = WASM_VECTOR_LEN;
104
+ const ret = wasm.generate_cluster_cells(seed, ptr0, len0);
105
+ deferred2_0 = ret[0];
106
+ deferred2_1 = ret[1];
107
+ return getStringFromWasm0(ret[0], ret[1]);
108
+ } finally {
109
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
110
+ }
111
+ }
112
+ exports.generate_cluster_cells = generate_cluster_cells;
113
+
114
+ /**
115
+ * Generate a cluster with provided cluster YAML config override.
116
+ * @param {number} seed
117
+ * @param {string} cluster_id
118
+ * @param {string} cluster_yaml
119
+ * @param {string} _world_yamls
120
+ * @returns {string}
121
+ */
122
+ function generate_cluster_with_configs(seed, cluster_id, cluster_yaml, _world_yamls) {
123
+ let deferred4_0;
124
+ let deferred4_1;
125
+ try {
126
+ const ptr0 = passStringToWasm0(cluster_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
127
+ const len0 = WASM_VECTOR_LEN;
128
+ const ptr1 = passStringToWasm0(cluster_yaml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
129
+ const len1 = WASM_VECTOR_LEN;
130
+ const ptr2 = passStringToWasm0(_world_yamls, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
131
+ const len2 = WASM_VECTOR_LEN;
132
+ const ret = wasm.generate_cluster_with_configs(seed, ptr0, len0, ptr1, len1, ptr2, len2);
133
+ deferred4_0 = ret[0];
134
+ deferred4_1 = ret[1];
135
+ return getStringFromWasm0(ret[0], ret[1]);
136
+ } finally {
137
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
138
+ }
139
+ }
140
+ exports.generate_cluster_with_configs = generate_cluster_with_configs;
141
+
142
+ /**
143
+ * Generate a cluster from a game coordinate string (e.g.
144
+ * `"SNDST-A-42-0-4A-MUWF1"`). Returns a `ClusterResult` JSON
145
+ * envelope; for the typed-array `MapData` shape use
146
+ * `generate_map_data`.
147
+ * @param {string} coordinate
148
+ * @returns {string}
149
+ */
150
+ function generate_from_coordinate(coordinate) {
151
+ let deferred2_0;
152
+ let deferred2_1;
153
+ try {
154
+ const ptr0 = passStringToWasm0(coordinate, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
155
+ const len0 = WASM_VECTOR_LEN;
156
+ const ret = wasm.generate_from_coordinate(ptr0, len0);
157
+ deferred2_0 = ret[0];
158
+ deferred2_1 = ret[1];
159
+ return getStringFromWasm0(ret[0], ret[1]);
160
+ } finally {
161
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
162
+ }
163
+ }
164
+ exports.generate_from_coordinate = generate_from_coordinate;
165
+
166
+ /**
167
+ * Generate the layout for a cluster's starting world and return
168
+ * per-cell data as JSON: `{ cells: [{ site_id, x, y, type }, ...] }`.
169
+ * Used for cell-level comparison against C# reference snapshots.
170
+ * @param {number} seed
171
+ * @param {string} cluster_id
172
+ * @returns {string}
173
+ */
174
+ function generate_layout_cells(seed, cluster_id) {
175
+ let deferred2_0;
176
+ let deferred2_1;
177
+ try {
178
+ const ptr0 = passStringToWasm0(cluster_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
179
+ const len0 = WASM_VECTOR_LEN;
180
+ const ret = wasm.generate_layout_cells(seed, ptr0, len0);
181
+ deferred2_0 = ret[0];
182
+ deferred2_1 = ret[1];
183
+ return getStringFromWasm0(ret[0], ret[1]);
184
+ } finally {
185
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
186
+ }
187
+ }
188
+ exports.generate_layout_cells = generate_layout_cells;
189
+
190
+ /**
191
+ * Generate a cluster from a game coordinate and return a `MapData`
192
+ * value: per-world element grids, biome cell polygons, entity spawns,
193
+ * and starmap locations. Caches the cluster for the two-phase API
194
+ * (`settle_cluster_advance`, `get_entity_spawners`).
195
+ *
196
+ * Per-cell grids ship as typed arrays (`Uint16Array`, `Float32Array`,
197
+ * etc.) on `JsValue` so JS consumers don't pay a JSON parse.
198
+ * @param {string} coordinate
199
+ * @returns {any}
200
+ */
201
+ function generate_map_data(coordinate) {
202
+ const ptr0 = passStringToWasm0(coordinate, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
203
+ const len0 = WASM_VECTOR_LEN;
204
+ const ret = wasm.generate_map_data(ptr0, len0);
205
+ return ret;
206
+ }
207
+ exports.generate_map_data = generate_map_data;
208
+
209
+ /**
210
+ * Re-run ambient mob spawning against the cached cluster's current
211
+ * cell state and return the refreshed entity lists. Call after
212
+ * `settle_cluster_advance` chunks when settled liquid/gas flow may
213
+ * have invalidated earlier mob placements. Requires a prior
214
+ * `generate_map_data`. Template-placed entities (geysers, oil wells,
215
+ * props) persist across calls.
216
+ * @returns {string}
217
+ */
218
+ function get_entity_spawners() {
219
+ let deferred1_0;
220
+ let deferred1_1;
221
+ try {
222
+ const ret = wasm.get_entity_spawners();
223
+ deferred1_0 = ret[0];
224
+ deferred1_1 = ret[1];
225
+ return getStringFromWasm0(ret[0], ret[1]);
226
+ } finally {
227
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
228
+ }
229
+ }
230
+ exports.get_entity_spawners = get_entity_spawners;
231
+
232
+ /**
233
+ * Returns a JSON-encoded `NoiseNodeKindSpec[]` enumerating every
234
+ * noise node variant the engine recognises (primitives, filters,
235
+ * modifiers, transformers, selectors, combiners) plus its param
236
+ * schema. Static across the lifetime of the build.
237
+ * @returns {string}
238
+ */
239
+ function noise_node_kinds() {
240
+ let deferred1_0;
241
+ let deferred1_1;
242
+ try {
243
+ const ret = wasm.noise_node_kinds();
244
+ deferred1_0 = ret[0];
245
+ deferred1_1 = ret[1];
246
+ return getStringFromWasm0(ret[0], ret[1]);
247
+ } finally {
248
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
249
+ }
250
+ }
251
+ exports.noise_node_kinds = noise_node_kinds;
252
+
253
+ /**
254
+ * Toggle template placement. WASM-side counterpart of the native
255
+ * `SKIP_TEMPLATES` env var.
256
+ * @param {boolean} skip
257
+ */
258
+ function set_skip_templates(skip) {
259
+ wasm.set_skip_templates(skip);
260
+ }
261
+ exports.set_skip_templates = set_skip_templates;
262
+
263
+ /**
264
+ * Drop both the SettingsCache and the cluster cache. The next
265
+ * `generate_*` call reloads the embedded stock defaults.
266
+ */
267
+ function settings_reset() {
268
+ wasm.settings_reset();
269
+ }
270
+ exports.settings_reset = settings_reset;
271
+
272
+ /**
273
+ * Advance the cached cluster's settle sim to `target_tick` and
274
+ * return a binary snapshot at that tick covering every world. Call
275
+ * repeatedly with increasing ticks to paint intermediate frames;
276
+ * `target_tick = 499` finalises the cluster.
277
+ *
278
+ * `target_tick` must be in `1..=499`. A tick `<=` the current cached
279
+ * tick re-emits the current frame. Returns an empty buffer on
280
+ * out-of-range tick or empty/stale cache; call `generate_map_data`
281
+ * first to populate.
282
+ *
283
+ * Binary format (all little-endian, v5):
284
+ * - `u32` version tag (= 5)
285
+ * - `u32` tick
286
+ * - `u32` world count
287
+ * - per world: `u32` width, `u32` height, then `width * height`
288
+ * cells of 25 bytes each: `u16 elem, f32 mass, f32 temp, u8 dis,
289
+ * i32 dis_count, u16 bw_elem, f32 bw_mass, f32 bw_temp`. Worlds
290
+ * without `backwallNoise` emit Vacuum + 0 mass + 0 temp.
291
+ * @param {number} target_tick
292
+ * @returns {Uint8Array}
293
+ */
294
+ function settle_cluster_advance(target_tick) {
295
+ const ret = wasm.settle_cluster_advance(target_tick);
296
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
297
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
298
+ return v1;
299
+ }
300
+ exports.settle_cluster_advance = settle_cluster_advance;
301
+
302
+ /**
303
+ * Drain the in-memory log buffer for `channel` (e.g. `"ppc_prng"`).
304
+ * WASM-side stand-in for native diag sites that would write to
305
+ * `std::fs::*`.
306
+ * @param {string} channel
307
+ * @returns {string}
308
+ */
309
+ function sim_env_drain_log(channel) {
310
+ let deferred2_0;
311
+ let deferred2_1;
312
+ try {
313
+ const ptr0 = passStringToWasm0(channel, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
314
+ const len0 = WASM_VECTOR_LEN;
315
+ const ret = wasm.sim_env_drain_log(ptr0, len0);
316
+ deferred2_0 = ret[0];
317
+ deferred2_1 = ret[1];
318
+ return getStringFromWasm0(ret[0], ret[1]);
319
+ } finally {
320
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
321
+ }
322
+ }
323
+ exports.sim_env_drain_log = sim_env_drain_log;
324
+
325
+ /**
326
+ * Set a `(key, value)` in the cross-target env overlay read by
327
+ * `oni_sim::sim_env::var`. WASM-side stand-in for the `SIM_*_PATH` /
328
+ * `SIM_*_TICK` env vars used by native diag sites.
329
+ * @param {string} key
330
+ * @param {string} value
331
+ */
332
+ function sim_env_set(key, value) {
333
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
334
+ const len0 = WASM_VECTOR_LEN;
335
+ const ptr1 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
336
+ const len1 = WASM_VECTOR_LEN;
337
+ wasm.sim_env_set(ptr0, len0, ptr1, len1);
338
+ }
339
+ exports.sim_env_set = sim_env_set;
340
+
341
+ /**
342
+ * Stable hex hash of a snapshot JSON. Alias of
343
+ * `snapshot_checksum_canonical`; same content always hashes to the
344
+ * same value regardless of HashMap/IndexMap iteration order.
345
+ * @param {string} snapshot_json
346
+ * @returns {string}
347
+ */
348
+ function snapshot_checksum(snapshot_json) {
349
+ let deferred3_0;
350
+ let deferred3_1;
351
+ try {
352
+ const ptr0 = passStringToWasm0(snapshot_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
353
+ const len0 = WASM_VECTOR_LEN;
354
+ const ret = wasm.snapshot_checksum(ptr0, len0);
355
+ var ptr2 = ret[0];
356
+ var len2 = ret[1];
357
+ if (ret[3]) {
358
+ ptr2 = 0; len2 = 0;
359
+ throw takeFromExternrefTable0(ret[2]);
360
+ }
361
+ deferred3_0 = ptr2;
362
+ deferred3_1 = len2;
363
+ return getStringFromWasm0(ptr2, len2);
364
+ } finally {
365
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
366
+ }
367
+ }
368
+ exports.snapshot_checksum = snapshot_checksum;
369
+
370
+ /**
371
+ * Byte-hash variant: FNV-1a-64 over the raw input bytes. Weak
372
+ * contract; same logical content with different HashMap/IndexMap
373
+ * iteration orders produces different hashes. Only safe when the
374
+ * consumer caches the exact bytes it hashed.
375
+ * @param {string} snapshot_json
376
+ * @returns {string}
377
+ */
378
+ function snapshot_checksum_bytes(snapshot_json) {
379
+ let deferred2_0;
380
+ let deferred2_1;
381
+ try {
382
+ const ptr0 = passStringToWasm0(snapshot_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
383
+ const len0 = WASM_VECTOR_LEN;
384
+ const ret = wasm.snapshot_checksum_bytes(ptr0, len0);
385
+ deferred2_0 = ret[0];
386
+ deferred2_1 = ret[1];
387
+ return getStringFromWasm0(ret[0], ret[1]);
388
+ } finally {
389
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
390
+ }
391
+ }
392
+ exports.snapshot_checksum_bytes = snapshot_checksum_bytes;
393
+
394
+ /**
395
+ * Canonical-form variant: parses to a `serde_json::Value` (sorted
396
+ * keys at every level), then FNV-1a-64 with type tags + length
397
+ * prefixes. Same logical content always produces the same hash;
398
+ * what `snapshot_checksum` (the default) and `snapshot_state_checksum`
399
+ * route through.
400
+ * @param {string} snapshot_json
401
+ * @returns {string}
402
+ */
403
+ function snapshot_checksum_canonical(snapshot_json) {
404
+ let deferred3_0;
405
+ let deferred3_1;
406
+ try {
407
+ const ptr0 = passStringToWasm0(snapshot_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
408
+ const len0 = WASM_VECTOR_LEN;
409
+ const ret = wasm.snapshot_checksum_canonical(ptr0, len0);
410
+ var ptr2 = ret[0];
411
+ var len2 = ret[1];
412
+ if (ret[3]) {
413
+ ptr2 = 0; len2 = 0;
414
+ throw takeFromExternrefTable0(ret[2]);
415
+ }
416
+ deferred3_0 = ptr2;
417
+ deferred3_1 = len2;
418
+ return getStringFromWasm0(ptr2, len2);
419
+ } finally {
420
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
421
+ }
422
+ }
423
+ exports.snapshot_checksum_canonical = snapshot_checksum_canonical;
424
+
425
+ /**
426
+ * Build a `WorldgenSnapshot` from a `{path: JSON-string}` files map,
427
+ * apply it to SETTINGS, and return the resulting snapshot JSON.
428
+ * Strict mode.
429
+ * @param {string} files_json
430
+ * @returns {string}
431
+ */
432
+ function snapshot_from_files(files_json) {
433
+ let deferred3_0;
434
+ let deferred3_1;
435
+ try {
436
+ const ptr0 = passStringToWasm0(files_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
437
+ const len0 = WASM_VECTOR_LEN;
438
+ const ret = wasm.snapshot_from_files(ptr0, len0);
439
+ var ptr2 = ret[0];
440
+ var len2 = ret[1];
441
+ if (ret[3]) {
442
+ ptr2 = 0; len2 = 0;
443
+ throw takeFromExternrefTable0(ret[2]);
444
+ }
445
+ deferred3_0 = ptr2;
446
+ deferred3_1 = len2;
447
+ return getStringFromWasm0(ptr2, len2);
448
+ } finally {
449
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
450
+ }
451
+ }
452
+ exports.snapshot_from_files = snapshot_from_files;
453
+
454
+ /**
455
+ * Extensions-mode counterpart of `snapshot_from_files`.
456
+ * @param {string} files_json
457
+ * @returns {string}
458
+ */
459
+ function snapshot_from_files_extensions(files_json) {
460
+ let deferred3_0;
461
+ let deferred3_1;
462
+ try {
463
+ const ptr0 = passStringToWasm0(files_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
464
+ const len0 = WASM_VECTOR_LEN;
465
+ const ret = wasm.snapshot_from_files_extensions(ptr0, len0);
466
+ var ptr2 = ret[0];
467
+ var len2 = ret[1];
468
+ if (ret[3]) {
469
+ ptr2 = 0; len2 = 0;
470
+ throw takeFromExternrefTable0(ret[2]);
471
+ }
472
+ deferred3_0 = ptr2;
473
+ deferred3_1 = len2;
474
+ return getStringFromWasm0(ptr2, len2);
475
+ } finally {
476
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
477
+ }
478
+ }
479
+ exports.snapshot_from_files_extensions = snapshot_from_files_extensions;
480
+
481
+ /**
482
+ * Reset SETTINGS to the embedded U59 vanilla baseline and return the
483
+ * vanilla snapshot as a JSON string. Strict mode.
484
+ * @returns {string}
485
+ */
486
+ function snapshot_load_vanilla() {
487
+ let deferred2_0;
488
+ let deferred2_1;
489
+ try {
490
+ const ret = wasm.snapshot_load_vanilla();
491
+ var ptr1 = ret[0];
492
+ var len1 = ret[1];
493
+ if (ret[3]) {
494
+ ptr1 = 0; len1 = 0;
495
+ throw takeFromExternrefTable0(ret[2]);
496
+ }
497
+ deferred2_0 = ptr1;
498
+ deferred2_1 = len1;
499
+ return getStringFromWasm0(ptr1, len1);
500
+ } finally {
501
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
502
+ }
503
+ }
504
+ exports.snapshot_load_vanilla = snapshot_load_vanilla;
505
+
506
+ /**
507
+ * Extensions-mode counterpart of `snapshot_load_vanilla`. Subsequent
508
+ * `merge_files` calls accept mod-defined enum extensions.
509
+ * @returns {string}
510
+ */
511
+ function snapshot_load_vanilla_extensions() {
512
+ let deferred2_0;
513
+ let deferred2_1;
514
+ try {
515
+ const ret = wasm.snapshot_load_vanilla_extensions();
516
+ var ptr1 = ret[0];
517
+ var len1 = ret[1];
518
+ if (ret[3]) {
519
+ ptr1 = 0; len1 = 0;
520
+ throw takeFromExternrefTable0(ret[2]);
521
+ }
522
+ deferred2_0 = ptr1;
523
+ deferred2_1 = len1;
524
+ return getStringFromWasm0(ptr1, len1);
525
+ } finally {
526
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
527
+ }
528
+ }
529
+ exports.snapshot_load_vanilla_extensions = snapshot_load_vanilla_extensions;
530
+
531
+ /**
532
+ * Merge a `{path: JSON-string}` files map into an existing snapshot
533
+ * JSON. Last-wins on duplicate paths. Applies the merged snapshot to
534
+ * SETTINGS as a side effect.
535
+ * @param {string} snapshot_json
536
+ * @param {string} files_json
537
+ * @returns {string}
538
+ */
539
+ function snapshot_merge_files(snapshot_json, files_json) {
540
+ let deferred4_0;
541
+ let deferred4_1;
542
+ try {
543
+ const ptr0 = passStringToWasm0(snapshot_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
544
+ const len0 = WASM_VECTOR_LEN;
545
+ const ptr1 = passStringToWasm0(files_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
546
+ const len1 = WASM_VECTOR_LEN;
547
+ const ret = wasm.snapshot_merge_files(ptr0, len0, ptr1, len1);
548
+ var ptr3 = ret[0];
549
+ var len3 = ret[1];
550
+ if (ret[3]) {
551
+ ptr3 = 0; len3 = 0;
552
+ throw takeFromExternrefTable0(ret[2]);
553
+ }
554
+ deferred4_0 = ptr3;
555
+ deferred4_1 = len3;
556
+ return getStringFromWasm0(ptr3, len3);
557
+ } finally {
558
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
559
+ }
560
+ }
561
+ exports.snapshot_merge_files = snapshot_merge_files;
562
+
563
+ /**
564
+ * Drop `paths_json` (a JSON array of path strings) from a snapshot
565
+ * JSON, apply the result to SETTINGS, and return the updated
566
+ * snapshot JSON. Paths not present are silently ignored; mode and
567
+ * element overrides are preserved.
568
+ * @param {string} snapshot_json
569
+ * @param {string} paths_json
570
+ * @returns {string}
571
+ */
572
+ function snapshot_remove_paths(snapshot_json, paths_json) {
573
+ let deferred4_0;
574
+ let deferred4_1;
575
+ try {
576
+ const ptr0 = passStringToWasm0(snapshot_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
577
+ const len0 = WASM_VECTOR_LEN;
578
+ const ptr1 = passStringToWasm0(paths_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
579
+ const len1 = WASM_VECTOR_LEN;
580
+ const ret = wasm.snapshot_remove_paths(ptr0, len0, ptr1, len1);
581
+ var ptr3 = ret[0];
582
+ var len3 = ret[1];
583
+ if (ret[3]) {
584
+ ptr3 = 0; len3 = 0;
585
+ throw takeFromExternrefTable0(ret[2]);
586
+ }
587
+ deferred4_0 = ptr3;
588
+ deferred4_1 = len3;
589
+ return getStringFromWasm0(ptr3, len3);
590
+ } finally {
591
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
592
+ }
593
+ }
594
+ exports.snapshot_remove_paths = snapshot_remove_paths;
595
+
596
+ /**
597
+ * Stable hex hash of the resident snapshot. Same content produces
598
+ * the same hash regardless of HashMap/IndexMap iteration order or
599
+ * load history. Auto-loads vanilla if empty.
600
+ * @returns {string}
601
+ */
602
+ function snapshot_state_checksum() {
603
+ let deferred2_0;
604
+ let deferred2_1;
605
+ try {
606
+ const ret = wasm.snapshot_state_checksum();
607
+ var ptr1 = ret[0];
608
+ var len1 = ret[1];
609
+ if (ret[3]) {
610
+ ptr1 = 0; len1 = 0;
611
+ throw takeFromExternrefTable0(ret[2]);
612
+ }
613
+ deferred2_0 = ptr1;
614
+ deferred2_1 = len1;
615
+ return getStringFromWasm0(ptr1, len1);
616
+ } finally {
617
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
618
+ }
619
+ }
620
+ exports.snapshot_state_checksum = snapshot_state_checksum;
621
+
622
+ /**
623
+ * Drop the listed paths from the resident snapshot. `paths_json` is
624
+ * a JSON array of path strings; paths not present are silently
625
+ * ignored.
626
+ * @param {string} paths_json
627
+ * @returns {number}
628
+ */
629
+ function snapshot_state_drop_paths(paths_json) {
630
+ const ptr0 = passStringToWasm0(paths_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
631
+ const len0 = WASM_VECTOR_LEN;
632
+ const ret = wasm.snapshot_state_drop_paths(ptr0, len0);
633
+ if (ret[2]) {
634
+ throw takeFromExternrefTable0(ret[1]);
635
+ }
636
+ return ret[0];
637
+ }
638
+ exports.snapshot_state_drop_paths = snapshot_state_drop_paths;
639
+
640
+ /**
641
+ * Return the resident snapshot as a JSON-encoded
642
+ * `{path: JSON-string}` files map. Auto-loads vanilla if empty.
643
+ * @returns {string}
644
+ */
645
+ function snapshot_state_files() {
646
+ let deferred2_0;
647
+ let deferred2_1;
648
+ try {
649
+ const ret = wasm.snapshot_state_files();
650
+ var ptr1 = ret[0];
651
+ var len1 = ret[1];
652
+ if (ret[3]) {
653
+ ptr1 = 0; len1 = 0;
654
+ throw takeFromExternrefTable0(ret[2]);
655
+ }
656
+ deferred2_0 = ptr1;
657
+ deferred2_1 = len1;
658
+ return getStringFromWasm0(ptr1, len1);
659
+ } finally {
660
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
661
+ }
662
+ }
663
+ exports.snapshot_state_files = snapshot_state_files;
664
+
665
+ /**
666
+ * Replace the resident snapshot from a `{path: JSON-string}` files
667
+ * map. Strict; atomic. Throws and leaves the snapshot untouched on
668
+ * invalid input.
669
+ * @param {string} files_json
670
+ * @returns {number}
671
+ */
672
+ function snapshot_state_load(files_json) {
673
+ const ptr0 = passStringToWasm0(files_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
674
+ const len0 = WASM_VECTOR_LEN;
675
+ const ret = wasm.snapshot_state_load(ptr0, len0);
676
+ if (ret[2]) {
677
+ throw takeFromExternrefTable0(ret[1]);
678
+ }
679
+ return ret[0];
680
+ }
681
+ exports.snapshot_state_load = snapshot_state_load;
682
+
683
+ /**
684
+ * Extensions-mode counterpart of `snapshot_state_load`. Subsequent
685
+ * merges inherit the Extensions mode from the loaded snapshot.
686
+ * @param {string} files_json
687
+ * @returns {number}
688
+ */
689
+ function snapshot_state_load_extensions(files_json) {
690
+ const ptr0 = passStringToWasm0(files_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
691
+ const len0 = WASM_VECTOR_LEN;
692
+ const ret = wasm.snapshot_state_load_extensions(ptr0, len0);
693
+ if (ret[2]) {
694
+ throw takeFromExternrefTable0(ret[1]);
695
+ }
696
+ return ret[0];
697
+ }
698
+ exports.snapshot_state_load_extensions = snapshot_state_load_extensions;
699
+
700
+ /**
701
+ * Merge a `{path: JSON-string}` files map into the resident snapshot.
702
+ * Last-wins on duplicate paths. Auto-loads vanilla if empty; atomic
703
+ * on parse failure. Mode is inherited from the resident snapshot.
704
+ * @param {string} files_json
705
+ * @returns {number}
706
+ */
707
+ function snapshot_state_merge(files_json) {
708
+ const ptr0 = passStringToWasm0(files_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
709
+ const len0 = WASM_VECTOR_LEN;
710
+ const ret = wasm.snapshot_state_merge(ptr0, len0);
711
+ if (ret[2]) {
712
+ throw takeFromExternrefTable0(ret[1]);
713
+ }
714
+ return ret[0];
715
+ }
716
+ exports.snapshot_state_merge = snapshot_state_merge;
717
+
718
+ /**
719
+ * Clear the resident snapshot and bump the version. The next
720
+ * `snapshot_state_*` call auto-loads vanilla.
721
+ */
722
+ function snapshot_state_reset() {
723
+ wasm.snapshot_state_reset();
724
+ }
725
+ exports.snapshot_state_reset = snapshot_state_reset;
726
+
727
+ /**
728
+ * Reset the resident snapshot to the embedded vanilla baseline.
729
+ * Strict mode.
730
+ * @returns {number}
731
+ */
732
+ function snapshot_state_vanilla() {
733
+ const ret = wasm.snapshot_state_vanilla();
734
+ return ret;
735
+ }
736
+ exports.snapshot_state_vanilla = snapshot_state_vanilla;
737
+
738
+ /**
739
+ * Same as `snapshot_state_vanilla`, Extensions mode. Subsequent
740
+ * merges accept mod-defined enum extensions.
741
+ * @returns {number}
742
+ */
743
+ function snapshot_state_vanilla_extensions() {
744
+ const ret = wasm.snapshot_state_vanilla_extensions();
745
+ return ret;
746
+ }
747
+ exports.snapshot_state_vanilla_extensions = snapshot_state_vanilla_extensions;
748
+
749
+ /**
750
+ * Monotonic mutation counter. Bumps on every successful mutation;
751
+ * 0 if the slot has never been touched.
752
+ * @returns {number}
753
+ */
754
+ function snapshot_state_version() {
755
+ const ret = wasm.snapshot_state_version();
756
+ return ret;
757
+ }
758
+ exports.snapshot_state_version = snapshot_state_version;
759
+
760
+ /**
761
+ * Convert a snapshot JSON into a `{path: JSON-string}` files map.
762
+ * Round-trips back through `snapshot_from_files`.
763
+ * @param {string} snapshot_json
764
+ * @returns {string}
765
+ */
766
+ function snapshot_to_files(snapshot_json) {
767
+ let deferred3_0;
768
+ let deferred3_1;
769
+ try {
770
+ const ptr0 = passStringToWasm0(snapshot_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
771
+ const len0 = WASM_VECTOR_LEN;
772
+ const ret = wasm.snapshot_to_files(ptr0, len0);
773
+ var ptr2 = ret[0];
774
+ var len2 = ret[1];
775
+ if (ret[3]) {
776
+ ptr2 = 0; len2 = 0;
777
+ throw takeFromExternrefTable0(ret[2]);
778
+ }
779
+ deferred3_0 = ptr2;
780
+ deferred3_1 = len2;
781
+ return getStringFromWasm0(ptr2, len2);
782
+ } finally {
783
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
784
+ }
785
+ }
786
+ exports.snapshot_to_files = snapshot_to_files;
787
+
788
+ function __wbg_get_imports() {
789
+ const import0 = {
790
+ __proto__: null,
791
+ __wbg_Error_83742b46f01ce22d: function(arg0, arg1) {
792
+ const ret = Error(getStringFromWasm0(arg0, arg1));
793
+ return ret;
794
+ },
795
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
796
+ const ret = String(arg1);
797
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
798
+ const len1 = WASM_VECTOR_LEN;
799
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
800
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
801
+ },
802
+ __wbg___wbindgen_is_string_7ef6b97b02428fae: function(arg0) {
803
+ const ret = typeof(arg0) === 'string';
804
+ return ret;
805
+ },
806
+ __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
807
+ throw new Error(getStringFromWasm0(arg0, arg1));
808
+ },
809
+ __wbg_get_3ef1eba1850ade27: function() { return handleError(function (arg0, arg1) {
810
+ const ret = Reflect.get(arg0, arg1);
811
+ return ret;
812
+ }, arguments); },
813
+ __wbg_get_a8ee5c45dabc1b3b: function(arg0, arg1) {
814
+ const ret = arg0[arg1 >>> 0];
815
+ return ret;
816
+ },
817
+ __wbg_new_49d5571bd3f0c4d4: function() {
818
+ const ret = new Map();
819
+ return ret;
820
+ },
821
+ __wbg_new_a70fbab9066b301f: function() {
822
+ const ret = new Array();
823
+ return ret;
824
+ },
825
+ __wbg_new_ab79df5bd7c26067: function() {
826
+ const ret = new Object();
827
+ return ret;
828
+ },
829
+ __wbg_new_from_slice_22da9388ac046e50: function(arg0, arg1) {
830
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
831
+ return ret;
832
+ },
833
+ __wbg_new_from_slice_c62f8165d6102476: function(arg0, arg1) {
834
+ const ret = new Int32Array(getArrayI32FromWasm0(arg0, arg1));
835
+ return ret;
836
+ },
837
+ __wbg_new_from_slice_dddccc7a7dc2cc04: function(arg0, arg1) {
838
+ const ret = new Uint16Array(getArrayU16FromWasm0(arg0, arg1));
839
+ return ret;
840
+ },
841
+ __wbg_new_from_slice_ff2c15e8e05ffdfc: function(arg0, arg1) {
842
+ const ret = new Float32Array(getArrayF32FromWasm0(arg0, arg1));
843
+ return ret;
844
+ },
845
+ __wbg_now_16f0c993d5dd6c27: function() {
846
+ const ret = Date.now();
847
+ return ret;
848
+ },
849
+ __wbg_set_282384002438957f: function(arg0, arg1, arg2) {
850
+ arg0[arg1 >>> 0] = arg2;
851
+ },
852
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
853
+ arg0[arg1] = arg2;
854
+ },
855
+ __wbg_set_7eaa4f96924fd6b3: function() { return handleError(function (arg0, arg1, arg2) {
856
+ const ret = Reflect.set(arg0, arg1, arg2);
857
+ return ret;
858
+ }, arguments); },
859
+ __wbg_set_bf7251625df30a02: function(arg0, arg1, arg2) {
860
+ const ret = arg0.set(arg1, arg2);
861
+ return ret;
862
+ },
863
+ __wbindgen_cast_0000000000000001: function(arg0) {
864
+ // Cast intrinsic for `F64 -> Externref`.
865
+ const ret = arg0;
866
+ return ret;
867
+ },
868
+ __wbindgen_cast_0000000000000002: function(arg0) {
869
+ // Cast intrinsic for `I64 -> Externref`.
870
+ const ret = arg0;
871
+ return ret;
872
+ },
873
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
874
+ // Cast intrinsic for `Ref(String) -> Externref`.
875
+ const ret = getStringFromWasm0(arg0, arg1);
876
+ return ret;
877
+ },
878
+ __wbindgen_cast_0000000000000004: function(arg0) {
879
+ // Cast intrinsic for `U64 -> Externref`.
880
+ const ret = BigInt.asUintN(64, arg0);
881
+ return ret;
882
+ },
883
+ __wbindgen_init_externref_table: function() {
884
+ const table = wasm.__wbindgen_externrefs;
885
+ const offset = table.grow(4);
886
+ table.set(0, undefined);
887
+ table.set(offset + 0, undefined);
888
+ table.set(offset + 1, null);
889
+ table.set(offset + 2, true);
890
+ table.set(offset + 3, false);
891
+ },
892
+ };
893
+ return {
894
+ __proto__: null,
895
+ "./oni_wasm_bg.js": import0,
896
+ };
897
+ }
898
+
899
+ function addToExternrefTable0(obj) {
900
+ const idx = wasm.__externref_table_alloc();
901
+ wasm.__wbindgen_externrefs.set(idx, obj);
902
+ return idx;
903
+ }
904
+
905
+ function getArrayF32FromWasm0(ptr, len) {
906
+ ptr = ptr >>> 0;
907
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
908
+ }
909
+
910
+ function getArrayI32FromWasm0(ptr, len) {
911
+ ptr = ptr >>> 0;
912
+ return getInt32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
913
+ }
914
+
915
+ function getArrayU16FromWasm0(ptr, len) {
916
+ ptr = ptr >>> 0;
917
+ return getUint16ArrayMemory0().subarray(ptr / 2, ptr / 2 + len);
918
+ }
919
+
920
+ function getArrayU8FromWasm0(ptr, len) {
921
+ ptr = ptr >>> 0;
922
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
923
+ }
924
+
925
+ let cachedDataViewMemory0 = null;
926
+ function getDataViewMemory0() {
927
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
928
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
929
+ }
930
+ return cachedDataViewMemory0;
931
+ }
932
+
933
+ let cachedFloat32ArrayMemory0 = null;
934
+ function getFloat32ArrayMemory0() {
935
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
936
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
937
+ }
938
+ return cachedFloat32ArrayMemory0;
939
+ }
940
+
941
+ let cachedInt32ArrayMemory0 = null;
942
+ function getInt32ArrayMemory0() {
943
+ if (cachedInt32ArrayMemory0 === null || cachedInt32ArrayMemory0.byteLength === 0) {
944
+ cachedInt32ArrayMemory0 = new Int32Array(wasm.memory.buffer);
945
+ }
946
+ return cachedInt32ArrayMemory0;
947
+ }
948
+
949
+ function getStringFromWasm0(ptr, len) {
950
+ ptr = ptr >>> 0;
951
+ return decodeText(ptr, len);
952
+ }
953
+
954
+ let cachedUint16ArrayMemory0 = null;
955
+ function getUint16ArrayMemory0() {
956
+ if (cachedUint16ArrayMemory0 === null || cachedUint16ArrayMemory0.byteLength === 0) {
957
+ cachedUint16ArrayMemory0 = new Uint16Array(wasm.memory.buffer);
958
+ }
959
+ return cachedUint16ArrayMemory0;
960
+ }
961
+
962
+ let cachedUint8ArrayMemory0 = null;
963
+ function getUint8ArrayMemory0() {
964
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
965
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
966
+ }
967
+ return cachedUint8ArrayMemory0;
968
+ }
969
+
970
+ function handleError(f, args) {
971
+ try {
972
+ return f.apply(this, args);
973
+ } catch (e) {
974
+ const idx = addToExternrefTable0(e);
975
+ wasm.__wbindgen_exn_store(idx);
976
+ }
977
+ }
978
+
979
+ function passStringToWasm0(arg, malloc, realloc) {
980
+ if (realloc === undefined) {
981
+ const buf = cachedTextEncoder.encode(arg);
982
+ const ptr = malloc(buf.length, 1) >>> 0;
983
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
984
+ WASM_VECTOR_LEN = buf.length;
985
+ return ptr;
986
+ }
987
+
988
+ let len = arg.length;
989
+ let ptr = malloc(len, 1) >>> 0;
990
+
991
+ const mem = getUint8ArrayMemory0();
992
+
993
+ let offset = 0;
994
+
995
+ for (; offset < len; offset++) {
996
+ const code = arg.charCodeAt(offset);
997
+ if (code > 0x7F) break;
998
+ mem[ptr + offset] = code;
999
+ }
1000
+ if (offset !== len) {
1001
+ if (offset !== 0) {
1002
+ arg = arg.slice(offset);
1003
+ }
1004
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
1005
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
1006
+ const ret = cachedTextEncoder.encodeInto(arg, view);
1007
+
1008
+ offset += ret.written;
1009
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
1010
+ }
1011
+
1012
+ WASM_VECTOR_LEN = offset;
1013
+ return ptr;
1014
+ }
1015
+
1016
+ function takeFromExternrefTable0(idx) {
1017
+ const value = wasm.__wbindgen_externrefs.get(idx);
1018
+ wasm.__externref_table_dealloc(idx);
1019
+ return value;
1020
+ }
1021
+
1022
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1023
+ cachedTextDecoder.decode();
1024
+ function decodeText(ptr, len) {
1025
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
1026
+ }
1027
+
1028
+ const cachedTextEncoder = new TextEncoder();
1029
+
1030
+ if (!('encodeInto' in cachedTextEncoder)) {
1031
+ cachedTextEncoder.encodeInto = function (arg, view) {
1032
+ const buf = cachedTextEncoder.encode(arg);
1033
+ view.set(buf);
1034
+ return {
1035
+ read: arg.length,
1036
+ written: buf.length
1037
+ };
1038
+ };
1039
+ }
1040
+
1041
+ let WASM_VECTOR_LEN = 0;
1042
+
1043
+ const wasmPath = `${__dirname}/oni_wasm_bg.wasm`;
1044
+ const wasmBytes = require('fs').readFileSync(wasmPath);
1045
+ const wasmModule = new WebAssembly.Module(wasmBytes);
1046
+ let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
1047
+ wasm.__wbindgen_start();