@npaw/forge-web 10.0.4 → 10.2.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.
@@ -1,563 +1,163 @@
1
- /* @ts-self-types="./forge_kernel_wasm.d.ts" */
2
-
3
- /**
4
- * @param {any} config
5
- * @returns {any}
6
- */
7
- export function forgeRuntimeCreate(config) {
8
- const ret = wasm.forgeRuntimeCreate(config);
9
- return ret;
10
- }
11
-
12
- /**
13
- * @param {number} handle
14
- * @returns {any}
15
- */
16
- export function forgeRuntimeDestroy(handle) {
17
- const ret = wasm.forgeRuntimeDestroy(handle);
18
- return ret;
19
- }
20
-
21
- /**
22
- * @param {number} handle
23
- * @param {any} command
24
- * @returns {any}
25
- */
26
- export function forgeRuntimeProcess(handle, command) {
27
- const ret = wasm.forgeRuntimeProcess(handle, command);
28
- return ret;
29
- }
30
-
31
- /**
32
- * @param {number} handle
33
- * @returns {any}
34
- */
35
- export function forgeRuntimeRelease(handle) {
36
- const ret = wasm.forgeRuntimeRelease(handle);
37
- return ret;
38
- }
39
-
40
- /**
41
- * @returns {string}
42
- */
43
- export function forgeRuntimeVersion() {
44
- let deferred1_0;
45
- let deferred1_1;
1
+ // src/wasm-glue.ts
2
+ var LENGTH_PREFIX_BYTES = 4;
3
+ var wasmExports;
4
+ var initPromise;
5
+ var textEncoder;
6
+ var textDecoder;
7
+ function boundaryError(message) {
8
+ return {
9
+ ok: false,
10
+ error: {
11
+ code: "web_boundary",
12
+ message,
13
+ recoverable: true
14
+ }
15
+ };
16
+ }
17
+ function requireExports() {
18
+ if (!wasmExports) {
19
+ throw new Error("Forge wasm module is not initialized; await the loader default() export first");
20
+ }
21
+ return wasmExports;
22
+ }
23
+ function encodeUtf8(value) {
24
+ if (!textEncoder) {
25
+ textEncoder = new TextEncoder();
26
+ }
27
+ return textEncoder.encode(value);
28
+ }
29
+ function decodeUtf8(bytes) {
30
+ if (!textDecoder) {
31
+ textDecoder = new TextDecoder("utf-8");
32
+ }
33
+ return textDecoder.decode(bytes);
34
+ }
35
+ function writeInput(exports, bytes) {
36
+ const offset = exports.forge_web_alloc(bytes.length);
37
+ if (offset === 0) {
38
+ return 0;
39
+ }
40
+ new Uint8Array(exports.memory.buffer, offset, bytes.length).set(bytes);
41
+ return offset;
42
+ }
43
+ function readResponse(exports, offset) {
44
+ if (offset === 0) {
45
+ throw new Error("kernel returned a null response buffer");
46
+ }
47
+ try {
48
+ const length = new DataView(exports.memory.buffer).getUint32(offset, true);
49
+ const payload = new Uint8Array(exports.memory.buffer, offset + LENGTH_PREFIX_BYTES, length);
50
+ return decodeUtf8(payload);
51
+ } finally {
52
+ exports.forge_web_free(offset);
53
+ }
54
+ }
55
+ function callWithJson(input, invoke) {
56
+ let exports;
57
+ try {
58
+ exports = requireExports();
59
+ } catch (error) {
60
+ return boundaryError(error instanceof Error ? error.message : String(error));
61
+ }
62
+ const bytes = encodeUtf8(input);
63
+ const inputOffset = writeInput(exports, bytes);
64
+ if (inputOffset === 0) {
65
+ return boundaryError(`kernel rejected a ${bytes.length} byte payload allocation`);
66
+ }
67
+ try {
68
+ const responseOffset = invoke(exports, inputOffset, bytes.length);
69
+ const responseText = readResponse(exports, responseOffset);
70
+ return JSON.parse(responseText);
71
+ } catch (error) {
72
+ return boundaryError(error instanceof Error ? error.message : String(error));
73
+ } finally {
74
+ exports.forge_web_free(inputOffset);
75
+ }
76
+ }
77
+ function callWithoutInput(invoke) {
78
+ try {
79
+ const exports = requireExports();
80
+ const responseText = readResponse(exports, invoke(exports));
81
+ return JSON.parse(responseText);
82
+ } catch (error) {
83
+ return boundaryError(error instanceof Error ? error.message : String(error));
84
+ }
85
+ }
86
+ function forgeRuntimeCreate(config) {
87
+ let serialized;
88
+ try {
89
+ serialized = JSON.stringify(config);
90
+ } catch (error) {
91
+ return boundaryError(error instanceof Error ? error.message : String(error));
92
+ }
93
+ return callWithJson(serialized, (exports, offset, length) => exports.forge_web_create(offset, length));
94
+ }
95
+ function forgeRuntimeProcess(handle, command) {
96
+ let serialized;
97
+ try {
98
+ serialized = JSON.stringify(command);
99
+ } catch (error) {
100
+ return boundaryError(error instanceof Error ? error.message : String(error));
101
+ }
102
+ return callWithJson(serialized, (exports, offset, length) => exports.forge_web_process(handle, offset, length));
103
+ }
104
+ function forgeRuntimeDestroy(handle) {
105
+ return callWithoutInput((exports) => exports.forge_web_destroy(handle));
106
+ }
107
+ function forgeRuntimeRelease(handle) {
108
+ return callWithoutInput((exports) => exports.forge_web_release(handle));
109
+ }
110
+ function forgeRuntimeVersion() {
111
+ const exports = requireExports();
112
+ return readResponse(exports, exports.forge_web_version());
113
+ }
114
+ function hasExportedInterface(exports) {
115
+ return typeof exports["forge_web_alloc"] === "function" && typeof exports["forge_web_free"] === "function" && typeof exports["forge_web_version"] === "function" && typeof exports["forge_web_create"] === "function" && typeof exports["forge_web_process"] === "function" && typeof exports["forge_web_destroy"] === "function" && typeof exports["forge_web_release"] === "function" && exports["memory"] instanceof WebAssembly.Memory;
116
+ }
117
+ async function instantiateFromBytes(bytes) {
118
+ const result = await WebAssembly.instantiate(bytes, {});
119
+ return result.instance;
120
+ }
121
+ async function instantiateFromResponse(response) {
122
+ if (typeof WebAssembly.instantiateStreaming === "function") {
46
123
  try {
47
- const ret = wasm.forgeRuntimeVersion();
48
- deferred1_0 = ret[0];
49
- deferred1_1 = ret[1];
50
- return getStringFromWasm0(ret[0], ret[1]);
51
- } finally {
52
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
53
- }
54
- }
55
- function __wbg_get_imports() {
56
- const import0 = {
57
- __proto__: null,
58
- __wbg_Error_ef53bc310eb298a0: function(arg0, arg1) {
59
- const ret = Error(getStringFromWasm0(arg0, arg1));
60
- return ret;
61
- },
62
- __wbg_Number_6b506e6536831eaa: function(arg0) {
63
- const ret = Number(arg0);
64
- return ret;
65
- },
66
- __wbg_String_8564e559799eccda: function(arg0, arg1) {
67
- const ret = String(arg1);
68
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
69
- const len1 = WASM_VECTOR_LEN;
70
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
71
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
72
- },
73
- __wbg___wbindgen_bigint_get_as_i64_38130e98eecd467d: function(arg0, arg1) {
74
- const v = arg1;
75
- const ret = typeof(v) === 'bigint' ? v : undefined;
76
- getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
77
- getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
78
- },
79
- __wbg___wbindgen_boolean_get_1a45e2c38d4d41b9: function(arg0) {
80
- const v = arg0;
81
- const ret = typeof(v) === 'boolean' ? v : undefined;
82
- return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
83
- },
84
- __wbg___wbindgen_debug_string_0accd80f45e5faa2: function(arg0, arg1) {
85
- const ret = debugString(arg1);
86
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
87
- const len1 = WASM_VECTOR_LEN;
88
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
89
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
90
- },
91
- __wbg___wbindgen_in_70a403a56e771704: function(arg0, arg1) {
92
- const ret = arg0 in arg1;
93
- return ret;
94
- },
95
- __wbg___wbindgen_is_bigint_6ffd6468a9bc44b9: function(arg0) {
96
- const ret = typeof(arg0) === 'bigint';
97
- return ret;
98
- },
99
- __wbg___wbindgen_is_function_754e9f305ff6029e: function(arg0) {
100
- const ret = typeof(arg0) === 'function';
101
- return ret;
102
- },
103
- __wbg___wbindgen_is_object_56732c2bc353f41d: function(arg0) {
104
- const val = arg0;
105
- const ret = typeof(val) === 'object' && val !== null;
106
- return ret;
107
- },
108
- __wbg___wbindgen_is_string_c236cabd84a4d769: function(arg0) {
109
- const ret = typeof(arg0) === 'string';
110
- return ret;
111
- },
112
- __wbg___wbindgen_is_undefined_67b456be8673d3d7: function(arg0) {
113
- const ret = arg0 === undefined;
114
- return ret;
115
- },
116
- __wbg___wbindgen_jsval_eq_1068e624fa87f6ab: function(arg0, arg1) {
117
- const ret = arg0 === arg1;
118
- return ret;
119
- },
120
- __wbg___wbindgen_jsval_loose_eq_2c56564c75129511: function(arg0, arg1) {
121
- const ret = arg0 == arg1;
122
- return ret;
123
- },
124
- __wbg___wbindgen_number_get_9bb1761122181af2: function(arg0, arg1) {
125
- const obj = arg1;
126
- const ret = typeof(obj) === 'number' ? obj : undefined;
127
- getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
128
- getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
129
- },
130
- __wbg___wbindgen_string_get_72bdf95d3ae505b1: function(arg0, arg1) {
131
- const obj = arg1;
132
- const ret = typeof(obj) === 'string' ? obj : undefined;
133
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
134
- var len1 = WASM_VECTOR_LEN;
135
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
136
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
137
- },
138
- __wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
139
- throw new Error(getStringFromWasm0(arg0, arg1));
140
- },
141
- __wbg_call_8a89609d89f6608a: function() { return handleError(function (arg0, arg1) {
142
- const ret = arg0.call(arg1);
143
- return ret;
144
- }, arguments); },
145
- __wbg_done_60cf307fcc680536: function(arg0) {
146
- const ret = arg0.done;
147
- return ret;
148
- },
149
- __wbg_entries_04b37a02507f1713: function(arg0) {
150
- const ret = Object.entries(arg0);
151
- return ret;
152
- },
153
- __wbg_get_1f8f054ddbaa7db2: function() { return handleError(function (arg0, arg1) {
154
- const ret = Reflect.get(arg0, arg1);
155
- return ret;
156
- }, arguments); },
157
- __wbg_get_2b48c7d0d006a781: function(arg0, arg1) {
158
- const ret = arg0[arg1 >>> 0];
159
- return ret;
160
- },
161
- __wbg_get_unchecked_33f6e5c9e2f2d6b2: function(arg0, arg1) {
162
- const ret = arg0[arg1 >>> 0];
163
- return ret;
164
- },
165
- __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
166
- const ret = arg0[arg1];
167
- return ret;
168
- },
169
- __wbg_instanceof_ArrayBuffer_8f49811467741499: function(arg0) {
170
- let result;
171
- try {
172
- result = arg0 instanceof ArrayBuffer;
173
- } catch (_) {
174
- result = false;
175
- }
176
- const ret = result;
177
- return ret;
178
- },
179
- __wbg_instanceof_Map_9fc06d9a951bcee6: function(arg0) {
180
- let result;
181
- try {
182
- result = arg0 instanceof Map;
183
- } catch (_) {
184
- result = false;
185
- }
186
- const ret = result;
187
- return ret;
188
- },
189
- __wbg_instanceof_Uint8Array_86f30649f63ef9c2: function(arg0) {
190
- let result;
191
- try {
192
- result = arg0 instanceof Uint8Array;
193
- } catch (_) {
194
- result = false;
195
- }
196
- const ret = result;
197
- return ret;
198
- },
199
- __wbg_isArray_67c2c9c4313f4448: function(arg0) {
200
- const ret = Array.isArray(arg0);
201
- return ret;
202
- },
203
- __wbg_isSafeInteger_66acec27e09e99a7: function(arg0) {
204
- const ret = Number.isSafeInteger(arg0);
205
- return ret;
206
- },
207
- __wbg_iterator_8732428d309e270e: function() {
208
- const ret = Symbol.iterator;
209
- return ret;
210
- },
211
- __wbg_length_4a591ecaa01354d9: function(arg0) {
212
- const ret = arg0.length;
213
- return ret;
214
- },
215
- __wbg_length_66f1a4b2e9026940: function(arg0) {
216
- const ret = arg0.length;
217
- return ret;
218
- },
219
- __wbg_new_578aeef4b6b94378: function(arg0) {
220
- const ret = new Uint8Array(arg0);
221
- return ret;
222
- },
223
- __wbg_new_622fc80556be2e26: function() {
224
- const ret = new Map();
225
- return ret;
226
- },
227
- __wbg_new_ce1ab61c1c2b300d: function() {
228
- const ret = new Object();
229
- return ret;
230
- },
231
- __wbg_new_d90091b82fdf5b91: function() {
232
- const ret = new Array();
233
- return ret;
234
- },
235
- __wbg_next_9e03acdf51c4960d: function(arg0) {
236
- const ret = arg0.next;
237
- return ret;
238
- },
239
- __wbg_next_eb8ca7351fa27906: function() { return handleError(function (arg0) {
240
- const ret = arg0.next();
241
- return ret;
242
- }, arguments); },
243
- __wbg_prototypesetcall_3249fc62a0fafa30: function(arg0, arg1, arg2) {
244
- Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
245
- },
246
- __wbg_set_52b1e1eb5bed906a: function(arg0, arg1, arg2) {
247
- const ret = arg0.set(arg1, arg2);
248
- return ret;
249
- },
250
- __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
251
- arg0[arg1] = arg2;
252
- },
253
- __wbg_set_dca99999bba88a9a: function(arg0, arg1, arg2) {
254
- arg0[arg1 >>> 0] = arg2;
255
- },
256
- __wbg_value_f3625092ee4b37f4: function(arg0) {
257
- const ret = arg0.value;
258
- return ret;
259
- },
260
- __wbindgen_cast_0000000000000001: function(arg0) {
261
- // Cast intrinsic for `F64 -> Externref`.
262
- const ret = arg0;
263
- return ret;
264
- },
265
- __wbindgen_cast_0000000000000002: function(arg0) {
266
- // Cast intrinsic for `I64 -> Externref`.
267
- const ret = arg0;
268
- return ret;
269
- },
270
- __wbindgen_cast_0000000000000003: function(arg0, arg1) {
271
- // Cast intrinsic for `Ref(String) -> Externref`.
272
- const ret = getStringFromWasm0(arg0, arg1);
273
- return ret;
274
- },
275
- __wbindgen_cast_0000000000000004: function(arg0) {
276
- // Cast intrinsic for `U64 -> Externref`.
277
- const ret = BigInt.asUintN(64, arg0);
278
- return ret;
279
- },
280
- __wbindgen_init_externref_table: function() {
281
- const table = wasm.__wbindgen_externrefs;
282
- const offset = table.grow(4);
283
- table.set(0, undefined);
284
- table.set(offset + 0, undefined);
285
- table.set(offset + 1, null);
286
- table.set(offset + 2, true);
287
- table.set(offset + 3, false);
288
- },
289
- };
290
- return {
291
- __proto__: null,
292
- "./forge_kernel_wasm_bg.js": import0,
293
- };
294
- }
295
-
296
- function addToExternrefTable0(obj) {
297
- const idx = wasm.__externref_table_alloc();
298
- wasm.__wbindgen_externrefs.set(idx, obj);
299
- return idx;
300
- }
301
-
302
- function debugString(val) {
303
- // primitive types
304
- const type = typeof val;
305
- if (type == 'number' || type == 'boolean' || val == null) {
306
- return `${val}`;
307
- }
308
- if (type == 'string') {
309
- return `"${val}"`;
310
- }
311
- if (type == 'symbol') {
312
- const description = val.description;
313
- if (description == null) {
314
- return 'Symbol';
315
- } else {
316
- return `Symbol(${description})`;
317
- }
318
- }
319
- if (type == 'function') {
320
- const name = val.name;
321
- if (typeof name == 'string' && name.length > 0) {
322
- return `Function(${name})`;
323
- } else {
324
- return 'Function';
325
- }
326
- }
327
- // objects
328
- if (Array.isArray(val)) {
329
- const length = val.length;
330
- let debug = '[';
331
- if (length > 0) {
332
- debug += debugString(val[0]);
333
- }
334
- for(let i = 1; i < length; i++) {
335
- debug += ', ' + debugString(val[i]);
336
- }
337
- debug += ']';
338
- return debug;
339
- }
340
- // Test for built-in
341
- const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
342
- let className;
343
- if (builtInMatches && builtInMatches.length > 1) {
344
- className = builtInMatches[1];
345
- } else {
346
- // Failed to match the standard '[object ClassName]'
347
- return toString.call(val);
348
- }
349
- if (className == 'Object') {
350
- // we're a user defined class or Object
351
- // JSON.stringify avoids problems with cycles, and is generally much
352
- // easier than looping through ownProperties of `val`.
353
- try {
354
- return 'Object(' + JSON.stringify(val) + ')';
355
- } catch (_) {
356
- return 'Object';
357
- }
358
- }
359
- // errors
360
- if (val instanceof Error) {
361
- return `${val.name}: ${val.message}\n${val.stack}`;
362
- }
363
- // TODO we could test for more things here, like `Set`s and `Map`s.
364
- return className;
365
- }
366
-
367
- function getArrayU8FromWasm0(ptr, len) {
368
- ptr = ptr >>> 0;
369
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
370
- }
371
-
372
- let cachedDataViewMemory0 = null;
373
- function getDataViewMemory0() {
374
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
375
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
376
- }
377
- return cachedDataViewMemory0;
378
- }
379
-
380
- function getStringFromWasm0(ptr, len) {
381
- return decodeText(ptr >>> 0, len);
382
- }
383
-
384
- let cachedUint8ArrayMemory0 = null;
385
- function getUint8ArrayMemory0() {
386
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
387
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
388
- }
389
- return cachedUint8ArrayMemory0;
390
- }
391
-
392
- function handleError(f, args) {
393
- try {
394
- return f.apply(this, args);
395
- } catch (e) {
396
- const idx = addToExternrefTable0(e);
397
- wasm.__wbindgen_exn_store(idx);
398
- }
399
- }
400
-
401
- function isLikeNone(x) {
402
- return x === undefined || x === null;
403
- }
404
-
405
- function passStringToWasm0(arg, malloc, realloc) {
406
- if (realloc === undefined) {
407
- const buf = cachedTextEncoder.encode(arg);
408
- const ptr = malloc(buf.length, 1) >>> 0;
409
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
410
- WASM_VECTOR_LEN = buf.length;
411
- return ptr;
412
- }
413
-
414
- let len = arg.length;
415
- let ptr = malloc(len, 1) >>> 0;
416
-
417
- const mem = getUint8ArrayMemory0();
418
-
419
- let offset = 0;
420
-
421
- for (; offset < len; offset++) {
422
- const code = arg.charCodeAt(offset);
423
- if (code > 0x7F) break;
424
- mem[ptr + offset] = code;
425
- }
426
- if (offset !== len) {
427
- if (offset !== 0) {
428
- arg = arg.slice(offset);
429
- }
430
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
431
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
432
- const ret = cachedTextEncoder.encodeInto(arg, view);
433
-
434
- offset += ret.written;
435
- ptr = realloc(ptr, len, offset, 1) >>> 0;
436
- }
437
-
438
- WASM_VECTOR_LEN = offset;
439
- return ptr;
440
- }
441
-
442
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
443
- cachedTextDecoder.decode();
444
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
445
- let numBytesDecoded = 0;
446
- function decodeText(ptr, len) {
447
- numBytesDecoded += len;
448
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
449
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
450
- cachedTextDecoder.decode();
451
- numBytesDecoded = len;
452
- }
453
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
454
- }
455
-
456
- const cachedTextEncoder = new TextEncoder();
457
-
458
- if (!('encodeInto' in cachedTextEncoder)) {
459
- cachedTextEncoder.encodeInto = function (arg, view) {
460
- const buf = cachedTextEncoder.encode(arg);
461
- view.set(buf);
462
- return {
463
- read: arg.length,
464
- written: buf.length
465
- };
466
- };
467
- }
468
-
469
- let WASM_VECTOR_LEN = 0;
470
-
471
- let wasmModule, wasmInstance, wasm;
472
- function __wbg_finalize_init(instance, module) {
473
- wasmInstance = instance;
474
- wasm = instance.exports;
475
- wasmModule = module;
476
- cachedDataViewMemory0 = null;
477
- cachedUint8ArrayMemory0 = null;
478
- wasm.__wbindgen_start();
479
- return wasm;
480
- }
481
-
482
- async function __wbg_load(module, imports) {
483
- if (typeof Response === 'function' && module instanceof Response) {
484
- if (typeof WebAssembly.instantiateStreaming === 'function') {
485
- try {
486
- return await WebAssembly.instantiateStreaming(module, imports);
487
- } catch (e) {
488
- const validResponse = module.ok && expectedResponseType(module.type);
489
-
490
- if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
491
- 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);
492
-
493
- } else { throw e; }
494
- }
495
- }
496
-
497
- const bytes = await module.arrayBuffer();
498
- return await WebAssembly.instantiate(bytes, imports);
499
- } else {
500
- const instance = await WebAssembly.instantiate(module, imports);
501
-
502
- if (instance instanceof WebAssembly.Instance) {
503
- return { instance, module };
504
- } else {
505
- return instance;
506
- }
507
- }
508
-
509
- function expectedResponseType(type) {
510
- switch (type) {
511
- case 'basic': case 'cors': case 'default': return true;
512
- }
513
- return false;
514
- }
515
- }
516
-
517
- function initSync(module) {
518
- if (wasm !== undefined) return wasm;
519
-
520
-
521
- if (module !== undefined) {
522
- if (Object.getPrototypeOf(module) === Object.prototype) {
523
- ({module} = module)
524
- } else {
525
- console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
526
- }
527
- }
528
-
529
- const imports = __wbg_get_imports();
530
- if (!(module instanceof WebAssembly.Module)) {
531
- module = new WebAssembly.Module(module);
532
- }
533
- const instance = new WebAssembly.Instance(module, imports);
534
- return __wbg_finalize_init(instance, module);
535
- }
536
-
537
- async function __wbg_init(module_or_path) {
538
- if (wasm !== undefined) return wasm;
539
-
540
-
541
- if (module_or_path !== undefined) {
542
- if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
543
- ({module_or_path} = module_or_path)
544
- } else {
545
- console.warn('using deprecated parameters for the initialization function; pass a single object instead')
546
- }
547
- }
548
-
549
- if (module_or_path === undefined) {
550
- module_or_path = new URL('forge_kernel_wasm_bg.wasm', import.meta.url);
551
- }
552
- const imports = __wbg_get_imports();
553
-
554
- if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
555
- module_or_path = fetch(module_or_path);
556
- }
557
-
558
- const { instance, module } = await __wbg_load(await module_or_path, imports);
559
-
560
- return __wbg_finalize_init(instance, module);
561
- }
562
-
563
- export { initSync, __wbg_init as default };
124
+ const streamed = await WebAssembly.instantiateStreaming(response.clone(), {});
125
+ return streamed.instance;
126
+ } catch {
127
+ }
128
+ }
129
+ return instantiateFromBytes(await response.arrayBuffer());
130
+ }
131
+ async function resolveInstance(input) {
132
+ let source = input && typeof input === "object" && "module_or_path" in input ? input.module_or_path : input;
133
+ if (source === void 0) {
134
+ source = new URL("forge_kernel_wasm_bg.wasm", import.meta.url);
135
+ }
136
+ const resolved = await source;
137
+ if (typeof Response !== "undefined" && resolved instanceof Response) {
138
+ return instantiateFromResponse(resolved);
139
+ }
140
+ if (typeof resolved === "string" || typeof URL !== "undefined" && resolved instanceof URL) {
141
+ return instantiateFromResponse(await fetch(resolved));
142
+ }
143
+ return instantiateFromBytes(resolved);
144
+ }
145
+ function init(input) {
146
+ if (!initPromise) {
147
+ initPromise = resolveInstance(input).then((instance) => {
148
+ if (!hasExportedInterface(instance.exports)) {
149
+ throw new Error("Forge wasm module is missing the expected forge_web_* export interface");
150
+ }
151
+ wasmExports = instance.exports;
152
+ });
153
+ }
154
+ return initPromise;
155
+ }
156
+ export {
157
+ init as default,
158
+ forgeRuntimeCreate,
159
+ forgeRuntimeDestroy,
160
+ forgeRuntimeProcess,
161
+ forgeRuntimeRelease,
162
+ forgeRuntimeVersion
163
+ };