@meritt/gsx-wasm 0.0.0-stage → 0.1.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/gsx.js ADDED
@@ -0,0 +1,727 @@
1
+ export const load = (() => {
2
+ const VERSION = '0.1.0';
3
+
4
+ class ParseError extends Error {
5
+ constructor({ code, range, details }) {
6
+ super(range === null ? code : `${code} at ${range[0]}..${range[1]}`);
7
+ this.name = 'ParseError';
8
+ this.code = code;
9
+ this.range = range;
10
+ this.details = details;
11
+ }
12
+ }
13
+
14
+ class VersionError extends Error {
15
+ constructor(found) {
16
+ super(
17
+ `gsx.wasm is ${found === undefined ? 'from another build' : `version ${found}`}, gsx.js is version ${VERSION}`
18
+ );
19
+ this.name = 'VersionError';
20
+ this.expected = VERSION;
21
+ this.found = found;
22
+ }
23
+ }
24
+
25
+ function firstLoneSurrogate(text) {
26
+ for (let i = 0; i < text.length; i++) {
27
+ const unit = text.charCodeAt(i);
28
+
29
+ if (unit >= 0xd800 && unit <= 0xdbff) {
30
+ const next = text.charCodeAt(i + 1);
31
+
32
+ if (next >= 0xdc00 && next <= 0xdfff) {
33
+ i++;
34
+ continue;
35
+ }
36
+
37
+ return i;
38
+ }
39
+
40
+ if (unit >= 0xdc00 && unit <= 0xdfff) {
41
+ return i;
42
+ }
43
+ }
44
+
45
+ return text.length;
46
+ }
47
+
48
+ function invalid(text) {
49
+ if (typeof text !== 'string') {
50
+ throw new TypeError('text must be a string');
51
+ }
52
+
53
+ if (text.isWellFormed()) return null;
54
+
55
+ const at = firstLoneSurrogate(text);
56
+ return [at, text.charCodeAt(at)];
57
+ }
58
+
59
+ function split(media) {
60
+ const ids = [];
61
+ const covers = [];
62
+
63
+ for (const { id, cover } of media) {
64
+ if (typeof id !== 'string' || !id.isWellFormed()) {
65
+ throw new TypeError('media id must be a well-formed string');
66
+ }
67
+
68
+ if (cover != null && (typeof cover !== 'string' || !cover.isWellFormed())) {
69
+ throw new TypeError('media cover must be a well-formed string, null or undefined');
70
+ }
71
+
72
+ ids.push(id);
73
+ covers.push(cover ?? undefined);
74
+ }
75
+
76
+ return [ids, covers];
77
+ }
78
+
79
+ const KINDS = { image: 1, video: 2 };
80
+ const FORMATS = { image: 0, gif: 1, video: 2, audio: 3 };
81
+
82
+ function mediaFacts(items) {
83
+ const ids = [];
84
+ const formats = [];
85
+ const alts = [];
86
+ const flags = [];
87
+
88
+ for (const { id, format, alt = null, spoiler = false, inline = false } of items) {
89
+ if (typeof id !== 'string' || !id.isWellFormed()) {
90
+ throw new TypeError('facts.items id must be a well-formed string');
91
+ }
92
+
93
+ if (!Object.hasOwn(FORMATS, format)) {
94
+ throw new TypeError("facts.items format must be 'image', 'gif', 'video' or 'audio'");
95
+ }
96
+
97
+ if (alt !== null && (typeof alt !== 'string' || !alt.isWellFormed())) {
98
+ throw new TypeError('facts.items alt must be a well-formed string or null');
99
+ }
100
+
101
+ if (typeof spoiler !== 'boolean' || typeof inline !== 'boolean') {
102
+ throw new TypeError('facts.items spoiler and inline must be booleans');
103
+ }
104
+
105
+ ids.push(id);
106
+ formats.push(FORMATS[format]);
107
+ alts.push(alt ?? undefined);
108
+ flags.push(Number(spoiler) | (Number(inline) << 1));
109
+ }
110
+
111
+ return [ids, Uint8Array.from(formats), alts, Uint8Array.from(flags)];
112
+ }
113
+
114
+ function count(value, name) {
115
+ if (value == null) return undefined;
116
+
117
+ if (!Number.isInteger(value) || value < 0 || value > 0xffffffff) {
118
+ throw new RangeError(`${name} must be an integer from 0 to 2^32 - 1`);
119
+ }
120
+
121
+ return value;
122
+ }
123
+
124
+ function unwrap(json, key) {
125
+ const result = JSON.parse(json);
126
+
127
+ if (result.error) {
128
+ throw new ParseError(result.error);
129
+ }
130
+
131
+ return result[key];
132
+ }
133
+
134
+ function bind(wasm, memory) {
135
+ const encoder = new TextEncoder();
136
+ let bytes = new Uint8Array(0);
137
+
138
+ function pass(text) {
139
+ const capacity = text.length * 3;
140
+ const at = wasm.input(capacity);
141
+ if (bytes.buffer !== memory.buffer) bytes = new Uint8Array(memory.buffer);
142
+ return encoder.encodeInto(text, bytes.subarray(at, at + capacity)).written;
143
+ }
144
+
145
+ function parseJSON(text, media = []) {
146
+ const entries = split(media);
147
+ const at = invalid(text);
148
+ if (at) return wasm.invalidText(...at);
149
+
150
+ return wasm.parse(pass(text), ...entries);
151
+ }
152
+
153
+ function serializeJSON(text, media = []) {
154
+ const entries = split(media);
155
+ const at = invalid(text);
156
+ if (at) return wasm.invalidText(...at);
157
+
158
+ return wasm.serialize(pass(text), ...entries);
159
+ }
160
+
161
+ function projectJSON(text, target, facts = {}, media = []) {
162
+ if (typeof target !== 'string') {
163
+ throw new TypeError('target must be a string');
164
+ }
165
+
166
+ const { title = null, entitiesAllowed = false, items = [] } = facts;
167
+ const kind = facts.media == null ? 0 : KINDS[facts.media];
168
+
169
+ if (kind === undefined) {
170
+ throw new TypeError("facts.media must be 'image', 'video', null or undefined");
171
+ }
172
+
173
+ if (title !== null && (typeof title !== 'string' || !title.isWellFormed())) {
174
+ throw new TypeError('facts.title must be a well-formed string or null');
175
+ }
176
+
177
+ if (typeof entitiesAllowed !== 'boolean') {
178
+ throw new TypeError('facts.entitiesAllowed must be a boolean');
179
+ }
180
+
181
+ const entries = split(media);
182
+ const described = mediaFacts(items);
183
+ const at = invalid(text);
184
+ if (at) return wasm.invalidText(...at);
185
+
186
+ return wasm.project(
187
+ pass(text),
188
+ ...entries,
189
+ target,
190
+ kind,
191
+ count(facts.mediaCount, 'facts.mediaCount') ?? 0,
192
+ title ?? undefined,
193
+ count(facts.maxCharacters, 'facts.maxCharacters'),
194
+ count(facts.charactersReservedPerUrl, 'facts.charactersReservedPerUrl'),
195
+ count(facts.captionLimit, 'facts.captionLimit'),
196
+ entitiesAllowed,
197
+ ...described
198
+ );
199
+ }
200
+
201
+ let listed;
202
+
203
+ return {
204
+ parse: (text, media) => unwrap(parseJSON(text, media), 'document'),
205
+ parseJSON,
206
+ serialize: (text, media) => unwrap(serializeJSON(text, media), 'serialized'),
207
+ serializeJSON,
208
+ project: (text, target, facts, media) => unwrap(projectJSON(text, target, facts, media), 'projection'),
209
+ projectJSON,
210
+ targets: () => (listed ??= Object.freeze(JSON.parse(wasm.targets()).targets.map(Object.freeze))),
211
+ };
212
+ }
213
+
214
+ function glue() {
215
+ let wasm_bindgen = (function(exports) {
216
+ let script_src;
217
+ if (typeof document !== 'undefined' && document.currentScript !== null) {
218
+ script_src = new URL(document.currentScript.src, location.href).toString();
219
+ }
220
+
221
+ /**
222
+ * @param {number} capacity
223
+ * @returns {number}
224
+ */
225
+ function input(capacity) {
226
+ const ret = wasm.input(capacity);
227
+ return ret >>> 0;
228
+ }
229
+ exports.input = input;
230
+
231
+ /**
232
+ * @param {number} offset
233
+ * @param {number} unit
234
+ * @returns {string}
235
+ */
236
+ function invalidText(offset, unit) {
237
+ let deferred1_0;
238
+ let deferred1_1;
239
+ try {
240
+ const ret = wasm.invalidText(offset, unit);
241
+ deferred1_0 = ret[0];
242
+ deferred1_1 = ret[1];
243
+ return getStringFromWasm0(ret[0], ret[1]);
244
+ } finally {
245
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
246
+ }
247
+ }
248
+ exports.invalidText = invalidText;
249
+
250
+ /**
251
+ * @param {number} len
252
+ * @param {string[]} ids
253
+ * @param {any[]} covers
254
+ * @returns {string}
255
+ */
256
+ function parse(len, ids, covers) {
257
+ let deferred5_0;
258
+ let deferred5_1;
259
+ try {
260
+ const val3 = +len;
261
+ let ptr0, len0, ptr1, len1;
262
+ try {
263
+ ptr0 = passArrayJsValueToWasm0(ids, wasm.__wbindgen_malloc);
264
+ len0 = WASM_VECTOR_LEN;
265
+ ptr1 = passArrayJsValueToWasm0(covers, wasm.__wbindgen_malloc);
266
+ len1 = WASM_VECTOR_LEN;
267
+ } catch (e) {
268
+ if (ptr1) { wasm.__externref_drop_slice(ptr1, len1); wasm.__wbindgen_free(ptr1, len1 * 4, 4); }
269
+ if (ptr0) { wasm.__externref_drop_slice(ptr0, len0); wasm.__wbindgen_free(ptr0, len0 * 4, 4); }
270
+ throw e;
271
+ }
272
+ const ret = wasm.parse(val3, ptr0, len0, ptr1, len1);
273
+ var ptr4 = ret[0];
274
+ var len4 = ret[1];
275
+ if (ret[3]) {
276
+ ptr4 = 0; len4 = 0;
277
+ throw takeFromExternrefTable0(ret[2]);
278
+ }
279
+ deferred5_0 = ptr4;
280
+ deferred5_1 = len4;
281
+ return getStringFromWasm0(ptr4, len4);
282
+ } finally {
283
+ wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
284
+ }
285
+ }
286
+ exports.parse = parse;
287
+
288
+ /**
289
+ * @param {number} len
290
+ * @param {string[]} ids
291
+ * @param {any[]} covers
292
+ * @param {string} target
293
+ * @param {number} kind
294
+ * @param {number} count
295
+ * @param {string | null | undefined} title
296
+ * @param {number | null | undefined} max_characters
297
+ * @param {number | null | undefined} characters_reserved_per_url
298
+ * @param {number | null | undefined} caption_limit
299
+ * @param {boolean} entities_allowed
300
+ * @param {string[]} item_ids
301
+ * @param {Uint8Array | number[]} item_formats
302
+ * @param {any[]} item_alts
303
+ * @param {Uint8Array | number[]} item_flags
304
+ * @returns {string}
305
+ */
306
+ function project(len, ids, covers, target, kind, count, title, max_characters, characters_reserved_per_url, caption_limit, entities_allowed, item_ids, item_formats, item_alts, item_flags) {
307
+ let deferred17_0;
308
+ let deferred17_1;
309
+ try {
310
+ const val9 = +len;
311
+ const val10 = +kind;
312
+ const val11 = +count;
313
+ const val12 = +(isLikeNone(max_characters) ? Number.MAX_SAFE_INTEGER : (max_characters) >>> 0);
314
+ const val13 = +(isLikeNone(characters_reserved_per_url) ? Number.MAX_SAFE_INTEGER : (characters_reserved_per_url) >>> 0);
315
+ const val14 = +(isLikeNone(caption_limit) ? Number.MAX_SAFE_INTEGER : (caption_limit) >>> 0);
316
+ const val15 = +entities_allowed;
317
+ let ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6, ptr7, len7;
318
+ try {
319
+ ptr0 = passArrayJsValueToWasm0(ids, wasm.__wbindgen_malloc);
320
+ len0 = WASM_VECTOR_LEN;
321
+ ptr1 = passArrayJsValueToWasm0(covers, wasm.__wbindgen_malloc);
322
+ len1 = WASM_VECTOR_LEN;
323
+ ptr2 = passStringToWasm0(target, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
324
+ len2 = WASM_VECTOR_LEN;
325
+ ptr3 = isLikeNone(title) ? 0 : passStringToWasm0(title, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
326
+ len3 = WASM_VECTOR_LEN;
327
+ ptr4 = passArrayJsValueToWasm0(item_ids, wasm.__wbindgen_malloc);
328
+ len4 = WASM_VECTOR_LEN;
329
+ ptr5 = passArray8ToWasm0(item_formats, wasm.__wbindgen_malloc);
330
+ len5 = WASM_VECTOR_LEN;
331
+ ptr6 = passArrayJsValueToWasm0(item_alts, wasm.__wbindgen_malloc);
332
+ len6 = WASM_VECTOR_LEN;
333
+ ptr7 = passArray8ToWasm0(item_flags, wasm.__wbindgen_malloc);
334
+ len7 = WASM_VECTOR_LEN;
335
+ } catch (e) {
336
+ if (ptr7) { wasm.__wbindgen_free(ptr7, len7 * 1, 1); }
337
+ if (ptr6) { wasm.__externref_drop_slice(ptr6, len6); wasm.__wbindgen_free(ptr6, len6 * 4, 4); }
338
+ if (ptr5) { wasm.__wbindgen_free(ptr5, len5 * 1, 1); }
339
+ if (ptr4) { wasm.__externref_drop_slice(ptr4, len4); wasm.__wbindgen_free(ptr4, len4 * 4, 4); }
340
+ if (ptr3) { wasm.__wbindgen_free(ptr3, len3 * 1, 1); }
341
+ if (ptr2) { wasm.__wbindgen_free(ptr2, len2 * 1, 1); }
342
+ if (ptr1) { wasm.__externref_drop_slice(ptr1, len1); wasm.__wbindgen_free(ptr1, len1 * 4, 4); }
343
+ if (ptr0) { wasm.__externref_drop_slice(ptr0, len0); wasm.__wbindgen_free(ptr0, len0 * 4, 4); }
344
+ throw e;
345
+ }
346
+ const ret = wasm.project(val9, ptr0, len0, ptr1, len1, ptr2, len2, val10, val11, ptr3, len3, val12, val13, val14, val15, ptr4, len4, ptr5, len5, ptr6, len6, ptr7, len7);
347
+ var ptr16 = ret[0];
348
+ var len16 = ret[1];
349
+ if (ret[3]) {
350
+ ptr16 = 0; len16 = 0;
351
+ throw takeFromExternrefTable0(ret[2]);
352
+ }
353
+ deferred17_0 = ptr16;
354
+ deferred17_1 = len16;
355
+ return getStringFromWasm0(ptr16, len16);
356
+ } finally {
357
+ wasm.__wbindgen_free(deferred17_0, deferred17_1, 1);
358
+ }
359
+ }
360
+ exports.project = project;
361
+
362
+ /**
363
+ * @param {number} len
364
+ * @param {string[]} ids
365
+ * @param {any[]} covers
366
+ * @returns {string}
367
+ */
368
+ function serialize(len, ids, covers) {
369
+ let deferred5_0;
370
+ let deferred5_1;
371
+ try {
372
+ const val3 = +len;
373
+ let ptr0, len0, ptr1, len1;
374
+ try {
375
+ ptr0 = passArrayJsValueToWasm0(ids, wasm.__wbindgen_malloc);
376
+ len0 = WASM_VECTOR_LEN;
377
+ ptr1 = passArrayJsValueToWasm0(covers, wasm.__wbindgen_malloc);
378
+ len1 = WASM_VECTOR_LEN;
379
+ } catch (e) {
380
+ if (ptr1) { wasm.__externref_drop_slice(ptr1, len1); wasm.__wbindgen_free(ptr1, len1 * 4, 4); }
381
+ if (ptr0) { wasm.__externref_drop_slice(ptr0, len0); wasm.__wbindgen_free(ptr0, len0 * 4, 4); }
382
+ throw e;
383
+ }
384
+ const ret = wasm.serialize(val3, ptr0, len0, ptr1, len1);
385
+ var ptr4 = ret[0];
386
+ var len4 = ret[1];
387
+ if (ret[3]) {
388
+ ptr4 = 0; len4 = 0;
389
+ throw takeFromExternrefTable0(ret[2]);
390
+ }
391
+ deferred5_0 = ptr4;
392
+ deferred5_1 = len4;
393
+ return getStringFromWasm0(ptr4, len4);
394
+ } finally {
395
+ wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
396
+ }
397
+ }
398
+ exports.serialize = serialize;
399
+
400
+ /**
401
+ * @returns {string}
402
+ */
403
+ function targets() {
404
+ let deferred1_0;
405
+ let deferred1_1;
406
+ try {
407
+ const ret = wasm.targets();
408
+ deferred1_0 = ret[0];
409
+ deferred1_1 = ret[1];
410
+ return getStringFromWasm0(ret[0], ret[1]);
411
+ } finally {
412
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
413
+ }
414
+ }
415
+ exports.targets = targets;
416
+
417
+ /**
418
+ * @returns {string}
419
+ */
420
+ function version() {
421
+ let deferred1_0;
422
+ let deferred1_1;
423
+ try {
424
+ const ret = wasm.version();
425
+ deferred1_0 = ret[0];
426
+ deferred1_1 = ret[1];
427
+ return getStringFromWasm0(ret[0], ret[1]);
428
+ } finally {
429
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
430
+ }
431
+ }
432
+ exports.version = version;
433
+ function __wbg_get_imports() {
434
+ const import0 = {
435
+ __proto__: null,
436
+ __wbg_Error_208446807d0d1e30: function(arg0, arg1) {
437
+ const ret = Error(getStringFromWasm0(arg0, arg1));
438
+ return ret;
439
+ },
440
+ __wbg___wbindgen_string_get_7ce8eee7fd327545: function(arg0, arg1) {
441
+ const obj = arg1;
442
+ const ret = typeof(obj) === 'string' ? obj : undefined;
443
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
444
+ var len1 = WASM_VECTOR_LEN;
445
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 1, len1, true);
446
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 0, ptr1, true);
447
+ },
448
+ __wbg___wbindgen_throw_4c88d8bf264fd984: function(arg0, arg1) {
449
+ throw new Error(getStringFromWasm0(arg0, arg1));
450
+ },
451
+ __wbindgen_init_externref_table: function() {
452
+ const table = wasm.__wbindgen_externrefs;
453
+ table.set(0, undefined);
454
+ table.set(1024, undefined);
455
+ table.set(1025, null);
456
+ table.set(1026, true);
457
+ table.set(1027, false);
458
+ },
459
+ };
460
+ return {
461
+ __proto__: null,
462
+ "./gsx_wasm_bg.js": import0,
463
+ };
464
+ }
465
+
466
+ function addToExternrefTable0(obj) {
467
+ const idx = wasm.__externref_table_alloc();
468
+ wasm.__wbindgen_externrefs.set(idx, obj);
469
+ return idx;
470
+ }
471
+
472
+ let cachedDataViewMemory0 = null;
473
+ function getDataViewMemory0() {
474
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
475
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
476
+ }
477
+ return cachedDataViewMemory0;
478
+ }
479
+
480
+ function getStringFromWasm0(ptr, len) {
481
+ ptr = ptr >>> 0;
482
+ return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
483
+ }
484
+
485
+ let cachedUint8ArrayMemory0 = null;
486
+ function getUint8ArrayMemory0() {
487
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
488
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
489
+ }
490
+ return cachedUint8ArrayMemory0;
491
+ }
492
+
493
+ function isLikeNone(x) {
494
+ return x === undefined || x === null;
495
+ }
496
+
497
+ function passArray8ToWasm0(arg, malloc) {
498
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
499
+ getUint8ArrayMemory0().set(arg, ptr / 1);
500
+ WASM_VECTOR_LEN = arg.length;
501
+ return ptr;
502
+ }
503
+
504
+ function passArrayJsValueToWasm0(array, malloc) {
505
+ const ptr = malloc(array.length * 4, 4) >>> 0;
506
+ for (let i = 0; i < array.length; i++) {
507
+ const add = addToExternrefTable0(array[i]);
508
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
509
+ }
510
+ WASM_VECTOR_LEN = array.length;
511
+ return ptr;
512
+ }
513
+
514
+ function passStringToWasm0(arg, malloc, realloc) {
515
+ if (realloc === undefined) {
516
+ const buf = cachedTextEncoder.encode(arg);
517
+ const ptr = malloc(buf.length, 1) >>> 0;
518
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
519
+ WASM_VECTOR_LEN = buf.length;
520
+ return ptr;
521
+ }
522
+
523
+ let len = arg.length;
524
+ let ptr = malloc(len, 1) >>> 0;
525
+
526
+ const mem = getUint8ArrayMemory0();
527
+
528
+ let offset = 0;
529
+
530
+ for (; offset < len; offset++) {
531
+ const code = arg.charCodeAt(offset);
532
+ if (code > 0x7F) break;
533
+ mem[ptr + offset] = code;
534
+ }
535
+ if (offset !== len) {
536
+ if (offset !== 0) {
537
+ arg = arg.slice(offset);
538
+ }
539
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
540
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
541
+ const ret = cachedTextEncoder.encodeInto(arg, view);
542
+
543
+ offset += ret.written;
544
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
545
+ }
546
+
547
+ WASM_VECTOR_LEN = offset;
548
+ return ptr;
549
+ }
550
+
551
+ function takeFromExternrefTable0(idx) {
552
+ const value = wasm.__wbindgen_externrefs.get(idx);
553
+ wasm.__externref_table_dealloc(idx);
554
+ return value;
555
+ }
556
+
557
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
558
+ cachedTextDecoder.decode();
559
+ function decodeText(bytes) {
560
+ return cachedTextDecoder.decode(bytes);
561
+ }
562
+
563
+ const cachedTextEncoder = new TextEncoder();
564
+
565
+ if (!('encodeInto' in cachedTextEncoder)) {
566
+ cachedTextEncoder.encodeInto = function (arg, view) {
567
+ const buf = cachedTextEncoder.encode(arg);
568
+ view.set(buf);
569
+ return {
570
+ read: arg.length,
571
+ written: buf.length
572
+ };
573
+ };
574
+ }
575
+
576
+ let WASM_VECTOR_LEN = 0;
577
+
578
+ let wasmModule, wasmInstance, wasm;
579
+ function __wbg_finalize_init(instance, module) {
580
+ wasmInstance = instance;
581
+ wasm = instance.exports;
582
+ wasmModule = module;
583
+ cachedDataViewMemory0 = null;
584
+ cachedUint8ArrayMemory0 = null;
585
+ wasm.__wbindgen_start();
586
+ return wasm;
587
+ }
588
+
589
+ async function __wbg_load(module, imports) {
590
+ if (typeof Response === 'function' && module instanceof Response) {
591
+ if (!module.ok) {
592
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
593
+ }
594
+
595
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
596
+ try {
597
+ return await WebAssembly.instantiateStreaming(module, imports);
598
+ } catch (e) {
599
+ const validResponse = expectedResponseType(module.type);
600
+
601
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
602
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
603
+
604
+ } else { throw e; }
605
+ }
606
+ }
607
+
608
+ const bytes = await module.arrayBuffer();
609
+ return await WebAssembly.instantiate(bytes, imports);
610
+ } else {
611
+ const instance = await WebAssembly.instantiate(module, imports);
612
+
613
+ if (instance instanceof WebAssembly.Instance) {
614
+ return { instance, module };
615
+ } else {
616
+ return instance;
617
+ }
618
+ }
619
+
620
+ function expectedResponseType(type) {
621
+ switch (type) {
622
+ case 'basic': case 'cors': case 'default': return true;
623
+ }
624
+ return false;
625
+ }
626
+ }
627
+
628
+ function initSync(module) {
629
+ if (wasm !== undefined) return wasm;
630
+
631
+
632
+ if (module !== undefined) {
633
+ if (Object.getPrototypeOf(module) === Object.prototype) {
634
+ ({module} = module)
635
+ } else {
636
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
637
+ }
638
+ }
639
+
640
+ const imports = __wbg_get_imports();
641
+ if (!(module instanceof WebAssembly.Module)) {
642
+ module = new WebAssembly.Module(module);
643
+ }
644
+ const instance = new WebAssembly.Instance(module, imports);
645
+ return __wbg_finalize_init(instance, module);
646
+ }
647
+
648
+ let __wbg_init_promise;
649
+ async function __wbg_init(module_or_path) {
650
+ if (wasm !== undefined) return wasm;
651
+ if (__wbg_init_promise === undefined) {
652
+ __wbg_init_promise = __wbg_init_once(module_or_path);
653
+ __wbg_init_promise.catch(() => { __wbg_init_promise = undefined; });
654
+ }
655
+ return __wbg_init_promise;
656
+ }
657
+
658
+ async function __wbg_init_once(module_or_path) {
659
+
660
+ if (module_or_path !== undefined) {
661
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
662
+ ({module_or_path} = module_or_path)
663
+ } else {
664
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
665
+ }
666
+ }
667
+
668
+ if (module_or_path === undefined && script_src !== undefined) {
669
+ module_or_path = script_src.replace(/\.js$/, "_bg.wasm");
670
+ }
671
+ const imports = __wbg_get_imports();
672
+
673
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
674
+ module_or_path = fetch(module_or_path);
675
+ }
676
+
677
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
678
+
679
+ return __wbg_finalize_init(instance, module);
680
+ }
681
+
682
+ return Object.assign(__wbg_init, { initSync }, exports);
683
+ })({ __proto__: null });
684
+ return wasm_bindgen;
685
+ }
686
+
687
+ async function compile(source) {
688
+ if (source instanceof WebAssembly.Module) return source;
689
+ if (typeof source === 'string') source = new URL(source, import.meta.url);
690
+ if (source instanceof URL) {
691
+ if (source.protocol === 'file:') {
692
+ const { readFile } = await import('node:fs/promises');
693
+ return WebAssembly.compile(await readFile(source));
694
+ }
695
+ source = fetch(source);
696
+ }
697
+ if (source instanceof Promise || (typeof Response === 'function' && source instanceof Response)) {
698
+ return WebAssembly.compileStreaming(source);
699
+ }
700
+ return WebAssembly.compile(source);
701
+ }
702
+
703
+ return async function load(source = new URL('./gsx.wasm', import.meta.url)) {
704
+ const module = await compile(source);
705
+ const wasm = glue();
706
+
707
+ if (!WebAssembly.Module.exports(module).some(({ name }) => name === 'version')) {
708
+ throw new VersionError(undefined);
709
+ }
710
+
711
+ let exports;
712
+
713
+ try {
714
+ exports = wasm.initSync({ module });
715
+ } catch (error) {
716
+ throw error instanceof WebAssembly.LinkError ? new VersionError(undefined) : error;
717
+ }
718
+
719
+ const found = wasm.version();
720
+
721
+ if (found !== VERSION) {
722
+ throw new VersionError(found);
723
+ }
724
+
725
+ return Object.freeze({ ...bind(wasm, exports.memory), VERSION, ParseError, VersionError });
726
+ };
727
+ })();