tunelet 0.1.0 → 0.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.
package/pkg/tunelet.js DELETED
@@ -1,870 +0,0 @@
1
- /* @ts-self-types="./tunelet.d.ts" */
2
-
3
- /**
4
- * A stateful PCM processor that JavaScript uses as the `Tunelet` class.
5
- *
6
- * The input is signed 16-bit mono PCM. The output is planar stereo or an
7
- * in-place mono downmix. The quantization, latency and configuration behavior
8
- * are the same as in the native processor. Buffer lengths count frames, not
9
- * bytes.
10
- *
11
- * These rules apply to the buffers:
12
- *
13
- * - Separate stereo output arrays must not overlap.
14
- * - The input can overlap an output, because the class copies the input
15
- * first.
16
- * - All buffers must stay attached until each call is complete.
17
- *
18
- * If a call that processes audio fails, it throws a JavaScript `Error` before
19
- * the audio state or the output changes. The class rejects malformed
20
- * configuration objects and malformed event objects. It also rejects values
21
- * that are out of range. The class decodes objects inside the methods that
22
- * can fail. Thus, if a conversion fails, Rust releases the temporary values
23
- * as usual.
24
- */
25
- export class Tunelet {
26
- __destroy_into_raw() {
27
- const ptr = this.__wbg_ptr;
28
- this.__wbg_ptr = 0;
29
- TuneletFinalization.unregister(this);
30
- return ptr;
31
- }
32
- free() {
33
- const ptr = this.__destroy_into_raw();
34
- wasm.__wbg_tunelet_free(ptr, 0);
35
- }
36
- /**
37
- * Starts a finite tail budget and returns its frame count as a number.
38
- *
39
- * Call this method one time after the final input block. Another call
40
- * starts the full budget again, but it does not clear the histories. See
41
- * `beginDrain` for completion.
42
- * @returns {number}
43
- */
44
- beginDrain() {
45
- const ret = wasm.tunelet_beginDrain(this.__wbg_ptr);
46
- return ret >>> 0;
47
- }
48
- /**
49
- * Returns a copy of the active configuration as a new JavaScript object.
50
- *
51
- * A change to the object has no effect until `setConfig` or a timed event
52
- * applies it.
53
- *
54
- * # Errors
55
- *
56
- * If the conversion to a JavaScript object fails, this method throws.
57
- * @returns {ProcessorConfig}
58
- */
59
- config() {
60
- const ret = wasm.tunelet_config(this.__wbg_ptr);
61
- if (ret[2]) {
62
- throw takeFromExternrefTable0(ret[1]);
63
- }
64
- return takeFromExternrefTable0(ret[0]);
65
- }
66
- /**
67
- * Renders a mono tail block and returns its frame count.
68
- *
69
- * The method fills the unused output with zeros. The downmix, completion
70
- * and feedback behavior are the same as for `drainMono`.
71
- *
72
- * # Errors
73
- *
74
- * If the block is larger than `maxBlockFrames`, this method throws before
75
- * the output or the state changes.
76
- * @param {Int16Array} audio
77
- * @returns {number}
78
- */
79
- drainMono(audio) {
80
- const ret = wasm.tunelet_drainMono(this.__wbg_ptr, audio);
81
- if (ret[2]) {
82
- throw takeFromExternrefTable0(ret[1]);
83
- }
84
- return ret[0] >>> 0;
85
- }
86
- /**
87
- * Renders stereo tail frames into `Int16Array` buffers of equal length.
88
- *
89
- * The method returns the number of rendered frames and fills the unused
90
- * output with zeros. If the drain is not active or is complete, the method
91
- * returns zero. Empty arrays do not use the budget. Completion resets the
92
- * histories and the feedback in the final drain call, also when that call
93
- * returns audio.
94
- *
95
- * # Errors
96
- *
97
- * The method throws if the channel lengths are not equal or if a block is
98
- * larger than `maxBlockFrames`. After an error, both output arrays and the
99
- * drain state do not change.
100
- * @param {Int16Array} left
101
- * @param {Int16Array} right
102
- * @returns {number}
103
- */
104
- drain(left, right) {
105
- const ret = wasm.tunelet_drain(this.__wbg_ptr, left, right);
106
- if (ret[2]) {
107
- throw takeFromExternrefTable0(ret[1]);
108
- }
109
- return ret[0] >>> 0;
110
- }
111
- /**
112
- * Returns a new feedback object and does not clear the peak window.
113
- *
114
- * `processedFrames` is a `bigint`, so its 64-bit count stays exact.
115
- * `latencyFrames` is a number. See `Feedback` for each measurement.
116
- *
117
- * `targetMidiNote` is `undefined` in these cases, which are also the
118
- * cases where `voiced` is `false`:
119
- *
120
- * - The kept pitch estimate is unvoiced. This includes the time before
121
- * the first detection and after a reset or a drain completion.
122
- * - The estimated frequency is outside the inclusive reporting bounds
123
- * `minFrequencyHz` and `maxFrequencyHz` of the pitch configuration.
124
- *
125
- * # Errors
126
- *
127
- * If the conversion to a JavaScript object fails, this method throws.
128
- * @returns {Feedback}
129
- */
130
- feedback() {
131
- const ret = wasm.tunelet_feedback(this.__wbg_ptr);
132
- if (ret[2]) {
133
- throw takeFromExternrefTable0(ret[1]);
134
- }
135
- return takeFromExternrefTable0(ret[0]);
136
- }
137
- /**
138
- * The nominal resynthesis delay in frames.
139
- *
140
- * Other signal paths have different timing. See the `latencyFrames`
141
- * property for the timing of the dry path and the voices.
142
- * @returns {number}
143
- */
144
- get latencyFrames() {
145
- const ret = wasm.tunelet_latencyFrames(this.__wbg_ptr);
146
- return ret >>> 0;
147
- }
148
- /**
149
- * The maximum frame count for each call that processes or drains audio.
150
- *
151
- * The constructor sets this value, and the value does not change.
152
- * @returns {number}
153
- */
154
- get maxBlockFrames() {
155
- const ret = wasm.tunelet_maxBlockFrames(this.__wbg_ptr);
156
- return ret >>> 0;
157
- }
158
- /**
159
- * Prepares a processor and its reusable PCM buffers.
160
- *
161
- * `sample_rate` must be 44100 or 48000. `max_block_frames` must be an
162
- * integer in 1..=4294967295. It is a limit for each call, and smaller
163
- * blocks and empty blocks are also valid. If you omit `config`, the
164
- * processor uses the default configuration. The constructor validates
165
- * the settings before it allocates the processor or the PCM buffers. In
166
- * TypeScript, use `new Tunelet(sampleRate, maxBlockFrames, config)`.
167
- *
168
- * # Errors
169
- *
170
- * The constructor throws if one of these conditions occurs:
171
- *
172
- * - The rate is not 44100 or 48000.
173
- * - The block limit is not an integer or is out of range.
174
- * - The configuration object is malformed or a field is missing.
175
- * - The configuration is not valid.
176
- * - The reservation of a PCM buffer fails.
177
- *
178
- * The available Wasm memory must also have sufficient space for the DSP
179
- * histories.
180
- * @param {number} sample_rate
181
- * @param {number} max_block_frames
182
- * @param {ProcessorConfig | null} [config]
183
- */
184
- constructor(sample_rate, max_block_frames, config) {
185
- const ret = wasm.tunelet_new(sample_rate, max_block_frames, isLikeNone(config) ? 0 : addToExternrefTable0(config));
186
- if (ret[2]) {
187
- throw takeFromExternrefTable0(ret[1]);
188
- }
189
- this.__wbg_ptr = ret[0];
190
- TuneletFinalization.register(this, this.__wbg_ptr, this);
191
- return this;
192
- }
193
- /**
194
- * Replaces the audio in a mono `Int16Array` with the stereo downmix.
195
- *
196
- * The timing, the events and the drain cancellation are the same as for
197
- * `process`. Peak feedback measures the stereo output before the downmix,
198
- * as in the native processor.
199
- *
200
- * # Errors
201
- *
202
- * The method throws if the block is too large or an event is not valid.
203
- * It throws before the audio of the caller or the DSP state changes.
204
- * @param {Int16Array} audio
205
- * @param {BlockEvents | null} [events]
206
- */
207
- processMono(audio, events) {
208
- const ret = wasm.tunelet_processMono(this.__wbg_ptr, audio, isLikeNone(events) ? 0 : addToExternrefTable0(events));
209
- if (ret[1]) {
210
- throw takeFromExternrefTable0(ret[0]);
211
- }
212
- }
213
- /**
214
- * Processes mono input into left and right `Int16Array` buffers of equal
215
- * length.
216
- *
217
- * If the call is successful, it writes every output sample. Optional
218
- * events apply before their frame, and their offsets obey the rules of
219
- * `TimedEvent[]`. An empty block must have no events. A successful call
220
- * cancels a drain, also for an empty block. The call uses the existing
221
- * JavaScript and Rust PCM buffers again.
222
- *
223
- * # Errors
224
- *
225
- * The method throws if the channel lengths are not equal. It also throws
226
- * if the block is larger than `maxBlockFrames` or an event is not valid.
227
- * The call checks the lengths and the block size before it decodes and
228
- * validates the events. If an error occurs, the output buffers and the DSP
229
- * state do not change.
230
- * @param {Int16Array} input
231
- * @param {Int16Array} left
232
- * @param {Int16Array} right
233
- * @param {BlockEvents | null} [events]
234
- */
235
- process(input, left, right, events) {
236
- const ret = wasm.tunelet_process(this.__wbg_ptr, input, left, right, isLikeNone(events) ? 0 : addToExternrefTable0(events));
237
- if (ret[1]) {
238
- throw takeFromExternrefTable0(ret[0]);
239
- }
240
- }
241
- /**
242
- * Resets the audio histories and feedback, as the native processor does.
243
- *
244
- * The configuration, the random stream and some controller and filter
245
- * state do not change. This method cancels any active drain. For a fully
246
- * new instance, construct a new `Tunelet`.
247
- */
248
- reset() {
249
- wasm.tunelet_reset(this.__wbg_ptr);
250
- }
251
- /**
252
- * The sample rate of the input and the output in hertz.
253
- *
254
- * The constructor sets this value, and the value does not change.
255
- * @returns {number}
256
- */
257
- get sampleRate() {
258
- const ret = wasm.tunelet_sampleRate(this.__wbg_ptr);
259
- return ret >>> 0;
260
- }
261
- /**
262
- * Decodes and validates a configuration, then replaces the complete
263
- * configuration with it.
264
- *
265
- * State retention and drain cancellation follow the native processor.
266
- * The conversion ignores additional properties of the JavaScript object.
267
- *
268
- * # Errors
269
- *
270
- * The method throws if an object is not valid or a field is missing.
271
- * After an error, all processor state and any active drain stay the same.
272
- * @param {ProcessorConfig} config
273
- */
274
- setConfig(config) {
275
- const ret = wasm.tunelet_setConfig(this.__wbg_ptr, config);
276
- if (ret[1]) {
277
- throw takeFromExternrefTable0(ret[0]);
278
- }
279
- }
280
- /**
281
- * Returns the tail budget of the current configuration, not the remaining
282
- * drain count.
283
- * @returns {number}
284
- */
285
- tailFrames() {
286
- const ret = wasm.tunelet_tailFrames(this.__wbg_ptr);
287
- return ret >>> 0;
288
- }
289
- /**
290
- * Returns the feedback and clears only the stereo peak window.
291
- *
292
- * The other feedback fields and all audio histories do not change.
293
- *
294
- * # Errors
295
- *
296
- * If the conversion to a JavaScript object fails, this method throws. The
297
- * method clears the peak only after it successfully makes a feedback
298
- * object.
299
- * @returns {Feedback}
300
- */
301
- takeFeedback() {
302
- const ret = wasm.tunelet_takeFeedback(this.__wbg_ptr);
303
- if (ret[2]) {
304
- throw takeFromExternrefTable0(ret[1]);
305
- }
306
- return takeFromExternrefTable0(ret[0]);
307
- }
308
- }
309
- if (Symbol.dispose) Tunelet.prototype[Symbol.dispose] = Tunelet.prototype.free;
310
-
311
- /**
312
- * Returns a complete, independent default configuration for JavaScript.
313
- *
314
- * Change its fields and give it to `Tunelet` or to `setConfig`. The
315
- * `randomSeed` field is a JavaScript `bigint`, so it keeps all 64 bits. After
316
- * the binding decodes them, floating-point controls have the precision of the
317
- * Rust `f32` type.
318
- *
319
- * # Errors
320
- *
321
- * If the conversion to a JavaScript object fails, this function returns a
322
- * JavaScript `Error`.
323
- * @returns {ProcessorConfig}
324
- */
325
- export function defaultConfig() {
326
- const ret = wasm.defaultConfig();
327
- if (ret[2]) {
328
- throw takeFromExternrefTable0(ret[1]);
329
- }
330
- return takeFromExternrefTable0(ret[0]);
331
- }
332
- function __wbg_get_imports() {
333
- const import0 = {
334
- __proto__: null,
335
- __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
336
- const ret = Error(getStringFromWasm0(arg0, arg1));
337
- return ret;
338
- },
339
- __wbg_Number_14af1003b8dd5ead: function(arg0) {
340
- const ret = Number(arg0);
341
- return ret;
342
- },
343
- __wbg_String_8564e559799eccda: function(arg0, arg1) {
344
- const ret = String(arg1);
345
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
346
- const len1 = WASM_VECTOR_LEN;
347
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
348
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
349
- },
350
- __wbg___wbindgen_bigint_get_as_i64_a2383202b9353e4c: function(arg0, arg1) {
351
- const v = arg1;
352
- const ret = typeof(v) === 'bigint' ? v : undefined;
353
- getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
354
- getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
355
- },
356
- __wbg___wbindgen_boolean_get_5b446f51afd21013: function(arg0) {
357
- const v = arg0;
358
- const ret = typeof(v) === 'boolean' ? v : undefined;
359
- return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
360
- },
361
- __wbg___wbindgen_debug_string_4687d8d8c2017d52: function(arg0, arg1) {
362
- const ret = debugString(arg1);
363
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
364
- const len1 = WASM_VECTOR_LEN;
365
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
366
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
367
- },
368
- __wbg___wbindgen_in_92f62ee1427d9e49: function(arg0, arg1) {
369
- const ret = arg0 in arg1;
370
- return ret;
371
- },
372
- __wbg___wbindgen_is_bigint_b123553bed3bb382: function(arg0) {
373
- const ret = typeof(arg0) === 'bigint';
374
- return ret;
375
- },
376
- __wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
377
- const ret = typeof(arg0) === 'function';
378
- return ret;
379
- },
380
- __wbg___wbindgen_is_object_3c45d4f2dde4e749: function(arg0) {
381
- const val = arg0;
382
- const ret = typeof(val) === 'object' && val !== null;
383
- return ret;
384
- },
385
- __wbg___wbindgen_is_string_90b56bc79aad6f6c: function(arg0) {
386
- const ret = typeof(arg0) === 'string';
387
- return ret;
388
- },
389
- __wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
390
- const ret = arg0 === undefined;
391
- return ret;
392
- },
393
- __wbg___wbindgen_jsval_eq_02babf21faa37971: function(arg0, arg1) {
394
- const ret = arg0 === arg1;
395
- return ret;
396
- },
397
- __wbg___wbindgen_jsval_loose_eq_677f21e468d6b461: function(arg0, arg1) {
398
- const ret = arg0 == arg1;
399
- return ret;
400
- },
401
- __wbg___wbindgen_number_get_2e0e7dee9f701a71: function(arg0, arg1) {
402
- const obj = arg1;
403
- const ret = typeof(obj) === 'number' ? obj : undefined;
404
- getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
405
- getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
406
- },
407
- __wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
408
- const obj = arg1;
409
- const ret = typeof(obj) === 'string' ? obj : undefined;
410
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
411
- var len1 = WASM_VECTOR_LEN;
412
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
413
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
414
- },
415
- __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
416
- throw new Error(getStringFromWasm0(arg0, arg1));
417
- },
418
- __wbg_call_6137034ef55c9d0f: function() { return handleError(function (arg0, arg1) {
419
- const ret = arg0.call(arg1);
420
- return ret;
421
- }, arguments); },
422
- __wbg_done_b41a1d26cdb37fb6: function(arg0) {
423
- const ret = arg0.done;
424
- return ret;
425
- },
426
- __wbg_entries_fb6397112b1de25f: function(arg0) {
427
- const ret = Object.entries(arg0);
428
- return ret;
429
- },
430
- __wbg_get_658f6698067d9515: function() { return handleError(function (arg0, arg1) {
431
- const ret = Reflect.get(arg0, arg1);
432
- return ret;
433
- }, arguments); },
434
- __wbg_get_6c896e0571ddae51: function(arg0, arg1) {
435
- const ret = arg0[arg1 >>> 0];
436
- return ret;
437
- },
438
- __wbg_get_unchecked_288889d017702237: function(arg0, arg1) {
439
- const ret = arg0[arg1 >>> 0];
440
- return ret;
441
- },
442
- __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
443
- const ret = arg0[arg1];
444
- return ret;
445
- },
446
- __wbg_instanceof_ArrayBuffer_a99f175873e5d9b8: function(arg0) {
447
- let result;
448
- try {
449
- result = arg0 instanceof ArrayBuffer;
450
- } catch (_) {
451
- result = false;
452
- }
453
- const ret = result;
454
- return ret;
455
- },
456
- __wbg_instanceof_Map_b2611749102d7ba3: function(arg0) {
457
- let result;
458
- try {
459
- result = arg0 instanceof Map;
460
- } catch (_) {
461
- result = false;
462
- }
463
- const ret = result;
464
- return ret;
465
- },
466
- __wbg_instanceof_Uint8Array_828cef2aaacafc31: function(arg0) {
467
- let result;
468
- try {
469
- result = arg0 instanceof Uint8Array;
470
- } catch (_) {
471
- result = false;
472
- }
473
- const ret = result;
474
- return ret;
475
- },
476
- __wbg_isArray_e15a2ff68ffdbef2: function(arg0) {
477
- const ret = Array.isArray(arg0);
478
- return ret;
479
- },
480
- __wbg_isSafeInteger_717808ad6a54bd9e: function(arg0) {
481
- const ret = Number.isSafeInteger(arg0);
482
- return ret;
483
- },
484
- __wbg_iterator_e3c31c892080e444: function() {
485
- const ret = Symbol.iterator;
486
- return ret;
487
- },
488
- __wbg_length_7f3c00c40364105e: function(arg0) {
489
- const ret = arg0.length;
490
- return ret;
491
- },
492
- __wbg_length_d4bdea10311bd9cf: function(arg0) {
493
- const ret = arg0.length;
494
- return ret;
495
- },
496
- __wbg_length_e5fdd54468b9e6ed: function(arg0) {
497
- const ret = arg0.length;
498
- return ret;
499
- },
500
- __wbg_new_1dbf7428bba60a42: function(arg0) {
501
- const ret = new Uint8Array(arg0);
502
- return ret;
503
- },
504
- __wbg_new_617a8cdb8bb1130e: function() {
505
- const ret = new Object();
506
- return ret;
507
- },
508
- __wbg_new_ee2291f50781bf1d: function() {
509
- const ret = new Array();
510
- return ret;
511
- },
512
- __wbg_next_33784799010f1bbe: function(arg0) {
513
- const ret = arg0.next;
514
- return ret;
515
- },
516
- __wbg_next_f4aac29c42af995c: function() { return handleError(function (arg0) {
517
- const ret = arg0.next();
518
- return ret;
519
- }, arguments); },
520
- __wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
521
- Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
522
- },
523
- __wbg_prototypesetcall_f8d32a400a944612: function(arg0, arg1, arg2) {
524
- Int16Array.prototype.set.call(getArrayI16FromWasm0(arg0, arg1), arg2);
525
- },
526
- __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
527
- arg0[arg1] = arg2;
528
- },
529
- __wbg_set_bb34845a21af7f64: function(arg0, arg1, arg2) {
530
- arg0.set(getArrayI16FromWasm0(arg1, arg2));
531
- },
532
- __wbg_set_bea140a88be9b277: function(arg0, arg1, arg2) {
533
- arg0[arg1 >>> 0] = arg2;
534
- },
535
- __wbg_value_f3c585ee8f5ba40c: function(arg0) {
536
- const ret = arg0.value;
537
- return ret;
538
- },
539
- __wbindgen_generic_0000000000000001: function(arg0) {
540
- // Cast intrinsic for `F64 -> Externref`.
541
- const ret = arg0;
542
- return ret;
543
- },
544
- __wbindgen_generic_0000000000000002: function(arg0) {
545
- // Cast intrinsic for `I64 -> Externref`.
546
- const ret = arg0;
547
- return ret;
548
- },
549
- __wbindgen_generic_0000000000000003: function(arg0, arg1) {
550
- // Cast intrinsic for `Ref(String) -> Externref`.
551
- const ret = getStringFromWasm0(arg0, arg1);
552
- return ret;
553
- },
554
- __wbindgen_generic_0000000000000004: function(arg0) {
555
- // Cast intrinsic for `U64 -> Externref`.
556
- const ret = BigInt.asUintN(64, arg0);
557
- return ret;
558
- },
559
- __wbindgen_init_externref_table: function() {
560
- const table = wasm.__wbindgen_externrefs;
561
- const offset = table.grow(4);
562
- table.set(0, undefined);
563
- table.set(offset + 0, undefined);
564
- table.set(offset + 1, null);
565
- table.set(offset + 2, true);
566
- table.set(offset + 3, false);
567
- },
568
- };
569
- return {
570
- __proto__: null,
571
- "./tunelet_bg.js": import0,
572
- };
573
- }
574
-
575
- const TuneletFinalization = (typeof FinalizationRegistry === 'undefined')
576
- ? { register: () => {}, unregister: () => {} }
577
- : new FinalizationRegistry(ptr => wasm.__wbg_tunelet_free(ptr, 1));
578
-
579
- function addToExternrefTable0(obj) {
580
- const idx = wasm.__externref_table_alloc();
581
- wasm.__wbindgen_externrefs.set(idx, obj);
582
- return idx;
583
- }
584
-
585
- function debugString(val) {
586
- // primitive types
587
- const type = typeof val;
588
- if (type == 'number' || type == 'boolean' || val == null) {
589
- return `${val}`;
590
- }
591
- if (type == 'string') {
592
- return `"${val}"`;
593
- }
594
- if (type == 'symbol') {
595
- const description = val.description;
596
- if (description == null) {
597
- return 'Symbol';
598
- } else {
599
- return `Symbol(${description})`;
600
- }
601
- }
602
- if (type == 'function') {
603
- const name = val.name;
604
- if (typeof name == 'string' && name.length > 0) {
605
- return `Function(${name})`;
606
- } else {
607
- return 'Function';
608
- }
609
- }
610
- // objects
611
- if (Array.isArray(val)) {
612
- const length = val.length;
613
- let debug = '[';
614
- if (length > 0) {
615
- debug += debugString(val[0]);
616
- }
617
- for(let i = 1; i < length; i++) {
618
- debug += ', ' + debugString(val[i]);
619
- }
620
- debug += ']';
621
- return debug;
622
- }
623
- // Test for built-in
624
- const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
625
- let className;
626
- if (builtInMatches && builtInMatches.length > 1) {
627
- className = builtInMatches[1];
628
- } else {
629
- // Failed to match the standard '[object ClassName]'
630
- return toString.call(val);
631
- }
632
- if (className == 'Object') {
633
- // we're a user defined class or Object
634
- // JSON.stringify avoids problems with cycles, and is generally much
635
- // easier than looping through ownProperties of `val`.
636
- try {
637
- return 'Object(' + JSON.stringify(val) + ')';
638
- } catch (_) {
639
- return 'Object';
640
- }
641
- }
642
- // errors
643
- if (val instanceof Error) {
644
- return `${val.name}: ${val.message}\n${val.stack}`;
645
- }
646
- // TODO we could test for more things here, like `Set`s and `Map`s.
647
- return className;
648
- }
649
-
650
- function getArrayI16FromWasm0(ptr, len) {
651
- ptr = ptr >>> 0;
652
- return getInt16ArrayMemory0().subarray(ptr / 2, ptr / 2 + len);
653
- }
654
-
655
- function getArrayU8FromWasm0(ptr, len) {
656
- ptr = ptr >>> 0;
657
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
658
- }
659
-
660
- let cachedDataViewMemory0 = null;
661
- function getDataViewMemory0() {
662
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
663
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
664
- }
665
- return cachedDataViewMemory0;
666
- }
667
-
668
- let cachedInt16ArrayMemory0 = null;
669
- function getInt16ArrayMemory0() {
670
- if (cachedInt16ArrayMemory0 === null || cachedInt16ArrayMemory0.byteLength === 0) {
671
- cachedInt16ArrayMemory0 = new Int16Array(wasm.memory.buffer);
672
- }
673
- return cachedInt16ArrayMemory0;
674
- }
675
-
676
- function getStringFromWasm0(ptr, len) {
677
- return decodeText(ptr >>> 0, len);
678
- }
679
-
680
- let cachedUint8ArrayMemory0 = null;
681
- function getUint8ArrayMemory0() {
682
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
683
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
684
- }
685
- return cachedUint8ArrayMemory0;
686
- }
687
-
688
- function handleError(f, args) {
689
- try {
690
- return f.apply(this, args);
691
- } catch (e) {
692
- const idx = addToExternrefTable0(e);
693
- wasm.__wbindgen_exn_store(idx);
694
- }
695
- }
696
-
697
- function isLikeNone(x) {
698
- return x === undefined || x === null;
699
- }
700
-
701
- function passStringToWasm0(arg, malloc, realloc) {
702
- if (realloc === undefined) {
703
- const buf = cachedTextEncoder.encode(arg);
704
- const ptr = malloc(buf.length, 1) >>> 0;
705
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
706
- WASM_VECTOR_LEN = buf.length;
707
- return ptr;
708
- }
709
-
710
- let len = arg.length;
711
- let ptr = malloc(len, 1) >>> 0;
712
-
713
- const mem = getUint8ArrayMemory0();
714
-
715
- let offset = 0;
716
-
717
- for (; offset < len; offset++) {
718
- const code = arg.charCodeAt(offset);
719
- if (code > 0x7F) break;
720
- mem[ptr + offset] = code;
721
- }
722
- if (offset !== len) {
723
- if (offset !== 0) {
724
- arg = arg.slice(offset);
725
- }
726
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
727
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
728
- const ret = cachedTextEncoder.encodeInto(arg, view);
729
-
730
- offset += ret.written;
731
- ptr = realloc(ptr, len, offset, 1) >>> 0;
732
- }
733
-
734
- WASM_VECTOR_LEN = offset;
735
- return ptr;
736
- }
737
-
738
- function takeFromExternrefTable0(idx) {
739
- const value = wasm.__wbindgen_externrefs.get(idx);
740
- wasm.__externref_table_dealloc(idx);
741
- return value;
742
- }
743
-
744
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
745
- cachedTextDecoder.decode();
746
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
747
- let numBytesDecoded = 0;
748
- function decodeText(ptr, len) {
749
- numBytesDecoded += len;
750
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
751
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
752
- cachedTextDecoder.decode();
753
- numBytesDecoded = len;
754
- }
755
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
756
- }
757
-
758
- const cachedTextEncoder = new TextEncoder();
759
-
760
- if (!('encodeInto' in cachedTextEncoder)) {
761
- cachedTextEncoder.encodeInto = function (arg, view) {
762
- const buf = cachedTextEncoder.encode(arg);
763
- view.set(buf);
764
- return {
765
- read: arg.length,
766
- written: buf.length
767
- };
768
- };
769
- }
770
-
771
- let WASM_VECTOR_LEN = 0;
772
-
773
- let wasmModule, wasmInstance, wasm;
774
- function __wbg_finalize_init(instance, module) {
775
- wasmInstance = instance;
776
- wasm = instance.exports;
777
- wasmModule = module;
778
- cachedDataViewMemory0 = null;
779
- cachedInt16ArrayMemory0 = null;
780
- cachedUint8ArrayMemory0 = null;
781
- wasm.__wbindgen_start();
782
- return wasm;
783
- }
784
-
785
- async function __wbg_load(module, imports) {
786
- if (typeof Response === 'function' && module instanceof Response) {
787
- if (!module.ok) {
788
- throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
789
- }
790
-
791
- if (typeof WebAssembly.instantiateStreaming === 'function') {
792
- try {
793
- return await WebAssembly.instantiateStreaming(module, imports);
794
- } catch (e) {
795
- const validResponse = expectedResponseType(module.type);
796
-
797
- if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
798
- 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);
799
-
800
- } else { throw e; }
801
- }
802
- }
803
-
804
- const bytes = await module.arrayBuffer();
805
- return await WebAssembly.instantiate(bytes, imports);
806
- } else {
807
- const instance = await WebAssembly.instantiate(module, imports);
808
-
809
- if (instance instanceof WebAssembly.Instance) {
810
- return { instance, module };
811
- } else {
812
- return instance;
813
- }
814
- }
815
-
816
- function expectedResponseType(type) {
817
- switch (type) {
818
- case 'basic': case 'cors': case 'default': return true;
819
- }
820
- return false;
821
- }
822
- }
823
-
824
- function initSync(module) {
825
- if (wasm !== undefined) return wasm;
826
-
827
-
828
- if (module !== undefined) {
829
- if (Object.getPrototypeOf(module) === Object.prototype) {
830
- ({module} = module)
831
- } else {
832
- console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
833
- }
834
- }
835
-
836
- const imports = __wbg_get_imports();
837
- if (!(module instanceof WebAssembly.Module)) {
838
- module = new WebAssembly.Module(module);
839
- }
840
- const instance = new WebAssembly.Instance(module, imports);
841
- return __wbg_finalize_init(instance, module);
842
- }
843
-
844
- async function __wbg_init(module_or_path) {
845
- if (wasm !== undefined) return wasm;
846
-
847
-
848
- if (module_or_path !== undefined) {
849
- if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
850
- ({module_or_path} = module_or_path)
851
- } else {
852
- console.warn('using deprecated parameters for the initialization function; pass a single object instead')
853
- }
854
- }
855
-
856
- if (module_or_path === undefined) {
857
- module_or_path = new URL('tunelet_bg.wasm', import.meta.url);
858
- }
859
- const imports = __wbg_get_imports();
860
-
861
- if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
862
- module_or_path = fetch(module_or_path);
863
- }
864
-
865
- const { instance, module } = await __wbg_load(await module_or_path, imports);
866
-
867
- return __wbg_finalize_init(instance, module);
868
- }
869
-
870
- export { initSync, __wbg_init as default };