@rwth-pads/cpnsim 0.1.8 → 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/cpnsim.d.ts CHANGED
@@ -1,46 +1,93 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+
3
4
  export class WasmSimulator {
4
- free(): void;
5
- constructor(ocpn_json_string: string);
6
- setEventListener(listener: Function): void;
7
- run_step(): any;
5
+ free(): void;
6
+ [Symbol.dispose](): void;
7
+ /**
8
+ * Advance simulation time by a given delta in milliseconds
9
+ */
10
+ advanceTime(delta_ms: bigint): void;
11
+ /**
12
+ * Fire a specific transition by its ID.
13
+ * Returns the event data if the transition was successfully fired, null otherwise.
14
+ */
15
+ fireTransition(transition_id: string): any;
16
+ /**
17
+ * Get the current simulation time in milliseconds
18
+ */
19
+ getCurrentTime(): bigint;
20
+ /**
21
+ * Get the list of currently enabled transitions with their possible bindings.
22
+ * Returns an array of objects with transitionId and transitionName.
23
+ */
24
+ getEnabledTransitions(): any;
25
+ /**
26
+ * Get the simulation epoch as an ISO 8601 string (or null if not set)
27
+ */
28
+ getSimulationEpoch(): any;
29
+ constructor(ocpn_json_string: string);
30
+ /**
31
+ * Run multiple steps without calling the event listener for each step.
32
+ * Returns an array of all event data from the executed steps.
33
+ * Useful for fast-forward simulation without intermediate UI updates.
34
+ */
35
+ runMultipleSteps(steps: number): any;
36
+ run_step(): any;
37
+ /**
38
+ * Set the current simulation time in milliseconds
39
+ */
40
+ setCurrentTime(time: bigint): void;
41
+ setEventListener(listener: Function): void;
42
+ /**
43
+ * Set the simulation epoch (ISO 8601 string, or null to clear)
44
+ */
45
+ setSimulationEpoch(epoch?: string | null): void;
8
46
  }
9
47
 
10
48
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
11
49
 
12
50
  export interface InitOutput {
13
- readonly memory: WebAssembly.Memory;
14
- readonly wasmsimulator_new: (a: number, b: number) => [number, number, number];
15
- readonly wasmsimulator_setEventListener: (a: number, b: any) => void;
16
- readonly wasmsimulator_run_step: (a: number) => [number, number, number];
17
- readonly __wbg_wasmsimulator_free: (a: number, b: number) => void;
18
- readonly __wbindgen_malloc: (a: number, b: number) => number;
19
- readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
20
- readonly __wbindgen_exn_store: (a: number) => void;
21
- readonly __externref_table_alloc: () => number;
22
- readonly __wbindgen_export_4: WebAssembly.Table;
23
- readonly __externref_table_dealloc: (a: number) => void;
24
- readonly __wbindgen_start: () => void;
51
+ readonly memory: WebAssembly.Memory;
52
+ readonly __wbg_wasmsimulator_free: (a: number, b: number) => void;
53
+ readonly wasmsimulator_advanceTime: (a: number, b: bigint) => void;
54
+ readonly wasmsimulator_fireTransition: (a: number, b: number, c: number) => [number, number, number];
55
+ readonly wasmsimulator_getCurrentTime: (a: number) => bigint;
56
+ readonly wasmsimulator_getEnabledTransitions: (a: number) => [number, number, number];
57
+ readonly wasmsimulator_getSimulationEpoch: (a: number) => any;
58
+ readonly wasmsimulator_new: (a: number, b: number) => [number, number, number];
59
+ readonly wasmsimulator_runMultipleSteps: (a: number, b: number) => [number, number, number];
60
+ readonly wasmsimulator_run_step: (a: number) => [number, number, number];
61
+ readonly wasmsimulator_setCurrentTime: (a: number, b: bigint) => void;
62
+ readonly wasmsimulator_setEventListener: (a: number, b: any) => void;
63
+ readonly wasmsimulator_setSimulationEpoch: (a: number, b: number, c: number) => void;
64
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
65
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
66
+ readonly __wbindgen_exn_store: (a: number) => void;
67
+ readonly __externref_table_alloc: () => number;
68
+ readonly __wbindgen_externrefs: WebAssembly.Table;
69
+ readonly __externref_table_dealloc: (a: number) => void;
70
+ readonly __wbindgen_start: () => void;
25
71
  }
26
72
 
27
73
  export type SyncInitInput = BufferSource | WebAssembly.Module;
74
+
28
75
  /**
29
- * Instantiates the given `module`, which can either be bytes or
30
- * a precompiled `WebAssembly.Module`.
31
- *
32
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
33
- *
34
- * @returns {InitOutput}
35
- */
76
+ * Instantiates the given `module`, which can either be bytes or
77
+ * a precompiled `WebAssembly.Module`.
78
+ *
79
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
80
+ *
81
+ * @returns {InitOutput}
82
+ */
36
83
  export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
37
84
 
38
85
  /**
39
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
40
- * for everything else, calls `WebAssembly.instantiate` directly.
41
- *
42
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
43
- *
44
- * @returns {Promise<InitOutput>}
45
- */
86
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
87
+ * for everything else, calls `WebAssembly.instantiate` directly.
88
+ *
89
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
90
+ *
91
+ * @returns {Promise<InitOutput>}
92
+ */
46
93
  export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/cpnsim.js CHANGED
@@ -1,9 +1,306 @@
1
- let wasm;
1
+ /* @ts-self-types="./cpnsim.d.ts" */
2
2
 
3
- let WASM_VECTOR_LEN = 0;
3
+ export class WasmSimulator {
4
+ __destroy_into_raw() {
5
+ const ptr = this.__wbg_ptr;
6
+ this.__wbg_ptr = 0;
7
+ WasmSimulatorFinalization.unregister(this);
8
+ return ptr;
9
+ }
10
+ free() {
11
+ const ptr = this.__destroy_into_raw();
12
+ wasm.__wbg_wasmsimulator_free(ptr, 0);
13
+ }
14
+ /**
15
+ * Advance simulation time by a given delta in milliseconds
16
+ * @param {bigint} delta_ms
17
+ */
18
+ advanceTime(delta_ms) {
19
+ wasm.wasmsimulator_advanceTime(this.__wbg_ptr, delta_ms);
20
+ }
21
+ /**
22
+ * Fire a specific transition by its ID.
23
+ * Returns the event data if the transition was successfully fired, null otherwise.
24
+ * @param {string} transition_id
25
+ * @returns {any}
26
+ */
27
+ fireTransition(transition_id) {
28
+ const ptr0 = passStringToWasm0(transition_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
29
+ const len0 = WASM_VECTOR_LEN;
30
+ const ret = wasm.wasmsimulator_fireTransition(this.__wbg_ptr, ptr0, len0);
31
+ if (ret[2]) {
32
+ throw takeFromExternrefTable0(ret[1]);
33
+ }
34
+ return takeFromExternrefTable0(ret[0]);
35
+ }
36
+ /**
37
+ * Get the current simulation time in milliseconds
38
+ * @returns {bigint}
39
+ */
40
+ getCurrentTime() {
41
+ const ret = wasm.wasmsimulator_getCurrentTime(this.__wbg_ptr);
42
+ return ret;
43
+ }
44
+ /**
45
+ * Get the list of currently enabled transitions with their possible bindings.
46
+ * Returns an array of objects with transitionId and transitionName.
47
+ * @returns {any}
48
+ */
49
+ getEnabledTransitions() {
50
+ const ret = wasm.wasmsimulator_getEnabledTransitions(this.__wbg_ptr);
51
+ if (ret[2]) {
52
+ throw takeFromExternrefTable0(ret[1]);
53
+ }
54
+ return takeFromExternrefTable0(ret[0]);
55
+ }
56
+ /**
57
+ * Get the simulation epoch as an ISO 8601 string (or null if not set)
58
+ * @returns {any}
59
+ */
60
+ getSimulationEpoch() {
61
+ const ret = wasm.wasmsimulator_getSimulationEpoch(this.__wbg_ptr);
62
+ return ret;
63
+ }
64
+ /**
65
+ * @param {string} ocpn_json_string
66
+ */
67
+ constructor(ocpn_json_string) {
68
+ const ptr0 = passStringToWasm0(ocpn_json_string, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
69
+ const len0 = WASM_VECTOR_LEN;
70
+ const ret = wasm.wasmsimulator_new(ptr0, len0);
71
+ if (ret[2]) {
72
+ throw takeFromExternrefTable0(ret[1]);
73
+ }
74
+ this.__wbg_ptr = ret[0] >>> 0;
75
+ WasmSimulatorFinalization.register(this, this.__wbg_ptr, this);
76
+ return this;
77
+ }
78
+ /**
79
+ * Run multiple steps without calling the event listener for each step.
80
+ * Returns an array of all event data from the executed steps.
81
+ * Useful for fast-forward simulation without intermediate UI updates.
82
+ * @param {number} steps
83
+ * @returns {any}
84
+ */
85
+ runMultipleSteps(steps) {
86
+ const ret = wasm.wasmsimulator_runMultipleSteps(this.__wbg_ptr, steps);
87
+ if (ret[2]) {
88
+ throw takeFromExternrefTable0(ret[1]);
89
+ }
90
+ return takeFromExternrefTable0(ret[0]);
91
+ }
92
+ /**
93
+ * @returns {any}
94
+ */
95
+ run_step() {
96
+ const ret = wasm.wasmsimulator_run_step(this.__wbg_ptr);
97
+ if (ret[2]) {
98
+ throw takeFromExternrefTable0(ret[1]);
99
+ }
100
+ return takeFromExternrefTable0(ret[0]);
101
+ }
102
+ /**
103
+ * Set the current simulation time in milliseconds
104
+ * @param {bigint} time
105
+ */
106
+ setCurrentTime(time) {
107
+ wasm.wasmsimulator_setCurrentTime(this.__wbg_ptr, time);
108
+ }
109
+ /**
110
+ * @param {Function} listener
111
+ */
112
+ setEventListener(listener) {
113
+ wasm.wasmsimulator_setEventListener(this.__wbg_ptr, listener);
114
+ }
115
+ /**
116
+ * Set the simulation epoch (ISO 8601 string, or null to clear)
117
+ * @param {string | null} [epoch]
118
+ */
119
+ setSimulationEpoch(epoch) {
120
+ var ptr0 = isLikeNone(epoch) ? 0 : passStringToWasm0(epoch, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
121
+ var len0 = WASM_VECTOR_LEN;
122
+ wasm.wasmsimulator_setSimulationEpoch(this.__wbg_ptr, ptr0, len0);
123
+ }
124
+ }
125
+ if (Symbol.dispose) WasmSimulator.prototype[Symbol.dispose] = WasmSimulator.prototype.free;
4
126
 
5
- let cachedUint8ArrayMemory0 = null;
127
+ function __wbg_get_imports() {
128
+ const import0 = {
129
+ __proto__: null,
130
+ __wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
131
+ const ret = Error(getStringFromWasm0(arg0, arg1));
132
+ return ret;
133
+ },
134
+ __wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
135
+ const ret = String(arg1);
136
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
137
+ const len1 = WASM_VECTOR_LEN;
138
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
139
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
140
+ },
141
+ __wbg___wbindgen_is_string_cd444516edc5b180: function(arg0) {
142
+ const ret = typeof(arg0) === 'string';
143
+ return ret;
144
+ },
145
+ __wbg___wbindgen_is_undefined_9e4d92534c42d778: function(arg0) {
146
+ const ret = arg0 === undefined;
147
+ return ret;
148
+ },
149
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
150
+ throw new Error(getStringFromWasm0(arg0, arg1));
151
+ },
152
+ __wbg_call_389efe28435a9388: function() { return handleError(function (arg0, arg1) {
153
+ const ret = arg0.call(arg1);
154
+ return ret;
155
+ }, arguments); },
156
+ __wbg_call_4708e0c13bdc8e95: function() { return handleError(function (arg0, arg1, arg2) {
157
+ const ret = arg0.call(arg1, arg2);
158
+ return ret;
159
+ }, arguments); },
160
+ __wbg_fromCodePoint_22365db7b7d6ac39: function() { return handleError(function (arg0) {
161
+ const ret = String.fromCodePoint(arg0 >>> 0);
162
+ return ret;
163
+ }, arguments); },
164
+ __wbg_from_bddd64e7d5ff6941: function(arg0) {
165
+ const ret = Array.from(arg0);
166
+ return ret;
167
+ },
168
+ __wbg_getRandomValues_1c61fac11405ffdc: function() { return handleError(function (arg0, arg1) {
169
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
170
+ }, arguments); },
171
+ __wbg_log_6b5ca2e6124b2808: function(arg0) {
172
+ console.log(arg0);
173
+ },
174
+ __wbg_log_8e6002fe4b368b1d: function(arg0, arg1) {
175
+ console.log(getStringFromWasm0(arg0, arg1));
176
+ },
177
+ __wbg_new_361308b2356cecd0: function() {
178
+ const ret = new Object();
179
+ return ret;
180
+ },
181
+ __wbg_new_3eb36ae241fe6f44: function() {
182
+ const ret = new Array();
183
+ return ret;
184
+ },
185
+ __wbg_new_dca287b076112a51: function() {
186
+ const ret = new Map();
187
+ return ret;
188
+ },
189
+ __wbg_new_dd2b680c8bf6ae29: function(arg0) {
190
+ const ret = new Uint8Array(arg0);
191
+ return ret;
192
+ },
193
+ __wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
194
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
195
+ return ret;
196
+ },
197
+ __wbg_now_2c95c9de01293173: function(arg0) {
198
+ const ret = arg0.now();
199
+ return ret;
200
+ },
201
+ __wbg_performance_7a3ffd0b17f663ad: function(arg0) {
202
+ const ret = arg0.performance;
203
+ return ret;
204
+ },
205
+ __wbg_push_8ffdcb2063340ba5: function(arg0, arg1) {
206
+ const ret = arg0.push(arg1);
207
+ return ret;
208
+ },
209
+ __wbg_set_1eb0999cf5d27fc8: function(arg0, arg1, arg2) {
210
+ const ret = arg0.set(arg1, arg2);
211
+ return ret;
212
+ },
213
+ __wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
214
+ arg0[arg1] = arg2;
215
+ },
216
+ __wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
217
+ const ret = Reflect.set(arg0, arg1, arg2);
218
+ return ret;
219
+ }, arguments); },
220
+ __wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
221
+ arg0[arg1 >>> 0] = arg2;
222
+ },
223
+ __wbg_static_accessor_GLOBAL_12837167ad935116: function() {
224
+ const ret = typeof global === 'undefined' ? null : global;
225
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
226
+ },
227
+ __wbg_static_accessor_GLOBAL_THIS_e628e89ab3b1c95f: function() {
228
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
229
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
230
+ },
231
+ __wbg_static_accessor_SELF_a621d3dfbb60d0ce: function() {
232
+ const ret = typeof self === 'undefined' ? null : self;
233
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
234
+ },
235
+ __wbg_static_accessor_WINDOW_f8727f0cf888e0bd: function() {
236
+ const ret = typeof window === 'undefined' ? null : window;
237
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
238
+ },
239
+ __wbindgen_cast_0000000000000001: function(arg0) {
240
+ // Cast intrinsic for `F64 -> Externref`.
241
+ const ret = arg0;
242
+ return ret;
243
+ },
244
+ __wbindgen_cast_0000000000000002: function(arg0) {
245
+ // Cast intrinsic for `I64 -> Externref`.
246
+ const ret = arg0;
247
+ return ret;
248
+ },
249
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
250
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
251
+ const ret = getArrayU8FromWasm0(arg0, arg1);
252
+ return ret;
253
+ },
254
+ __wbindgen_cast_0000000000000004: function(arg0, arg1) {
255
+ // Cast intrinsic for `Ref(String) -> Externref`.
256
+ const ret = getStringFromWasm0(arg0, arg1);
257
+ return ret;
258
+ },
259
+ __wbindgen_init_externref_table: function() {
260
+ const table = wasm.__wbindgen_externrefs;
261
+ const offset = table.grow(4);
262
+ table.set(0, undefined);
263
+ table.set(offset + 0, undefined);
264
+ table.set(offset + 1, null);
265
+ table.set(offset + 2, true);
266
+ table.set(offset + 3, false);
267
+ },
268
+ };
269
+ return {
270
+ __proto__: null,
271
+ "./cpnsim_bg.js": import0,
272
+ };
273
+ }
274
+
275
+ const WasmSimulatorFinalization = (typeof FinalizationRegistry === 'undefined')
276
+ ? { register: () => {}, unregister: () => {} }
277
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmsimulator_free(ptr >>> 0, 1));
6
278
 
279
+ function addToExternrefTable0(obj) {
280
+ const idx = wasm.__externref_table_alloc();
281
+ wasm.__wbindgen_externrefs.set(idx, obj);
282
+ return idx;
283
+ }
284
+
285
+ function getArrayU8FromWasm0(ptr, len) {
286
+ ptr = ptr >>> 0;
287
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
288
+ }
289
+
290
+ let cachedDataViewMemory0 = null;
291
+ function getDataViewMemory0() {
292
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
293
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
294
+ }
295
+ return cachedDataViewMemory0;
296
+ }
297
+
298
+ function getStringFromWasm0(ptr, len) {
299
+ ptr = ptr >>> 0;
300
+ return decodeText(ptr, len);
301
+ }
302
+
303
+ let cachedUint8ArrayMemory0 = null;
7
304
  function getUint8ArrayMemory0() {
8
305
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
9
306
  cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
@@ -11,23 +308,20 @@ function getUint8ArrayMemory0() {
11
308
  return cachedUint8ArrayMemory0;
12
309
  }
13
310
 
14
- const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
311
+ function handleError(f, args) {
312
+ try {
313
+ return f.apply(this, args);
314
+ } catch (e) {
315
+ const idx = addToExternrefTable0(e);
316
+ wasm.__wbindgen_exn_store(idx);
317
+ }
318
+ }
15
319
 
16
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
17
- ? function (arg, view) {
18
- return cachedTextEncoder.encodeInto(arg, view);
320
+ function isLikeNone(x) {
321
+ return x === undefined || x === null;
19
322
  }
20
- : function (arg, view) {
21
- const buf = cachedTextEncoder.encode(arg);
22
- view.set(buf);
23
- return {
24
- read: arg.length,
25
- written: buf.length
26
- };
27
- });
28
323
 
29
324
  function passStringToWasm0(arg, malloc, realloc) {
30
-
31
325
  if (realloc === undefined) {
32
326
  const buf = cachedTextEncoder.encode(arg);
33
327
  const ptr = malloc(buf.length, 1) >>> 0;
@@ -48,14 +342,13 @@ function passStringToWasm0(arg, malloc, realloc) {
48
342
  if (code > 0x7F) break;
49
343
  mem[ptr + offset] = code;
50
344
  }
51
-
52
345
  if (offset !== len) {
53
346
  if (offset !== 0) {
54
347
  arg = arg.slice(offset);
55
348
  }
56
349
  ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
57
350
  const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
58
- const ret = encodeString(arg, view);
351
+ const ret = cachedTextEncoder.encodeInto(arg, view);
59
352
 
60
353
  offset += ret.written;
61
354
  ptr = realloc(ptr, len, offset, 1) >>> 0;
@@ -65,166 +358,49 @@ function passStringToWasm0(arg, malloc, realloc) {
65
358
  return ptr;
66
359
  }
67
360
 
68
- let cachedDataViewMemory0 = null;
69
-
70
- function getDataViewMemory0() {
71
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
72
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
73
- }
74
- return cachedDataViewMemory0;
75
- }
76
-
77
- function addToExternrefTable0(obj) {
78
- const idx = wasm.__externref_table_alloc();
79
- wasm.__wbindgen_export_4.set(idx, obj);
80
- return idx;
361
+ function takeFromExternrefTable0(idx) {
362
+ const value = wasm.__wbindgen_externrefs.get(idx);
363
+ wasm.__externref_table_dealloc(idx);
364
+ return value;
81
365
  }
82
366
 
83
- function handleError(f, args) {
84
- try {
85
- return f.apply(this, args);
86
- } catch (e) {
87
- const idx = addToExternrefTable0(e);
88
- wasm.__wbindgen_exn_store(idx);
367
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
368
+ cachedTextDecoder.decode();
369
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
370
+ let numBytesDecoded = 0;
371
+ function decodeText(ptr, len) {
372
+ numBytesDecoded += len;
373
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
374
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
375
+ cachedTextDecoder.decode();
376
+ numBytesDecoded = len;
89
377
  }
90
- }
91
-
92
- function getArrayU8FromWasm0(ptr, len) {
93
- ptr = ptr >>> 0;
94
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
95
- }
96
-
97
- const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
98
-
99
- if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
100
-
101
- function getStringFromWasm0(ptr, len) {
102
- ptr = ptr >>> 0;
103
378
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
104
379
  }
105
380
 
106
- function isLikeNone(x) {
107
- return x === undefined || x === null;
108
- }
381
+ const cachedTextEncoder = new TextEncoder();
109
382
 
110
- function debugString(val) {
111
- // primitive types
112
- const type = typeof val;
113
- if (type == 'number' || type == 'boolean' || val == null) {
114
- return `${val}`;
115
- }
116
- if (type == 'string') {
117
- return `"${val}"`;
118
- }
119
- if (type == 'symbol') {
120
- const description = val.description;
121
- if (description == null) {
122
- return 'Symbol';
123
- } else {
124
- return `Symbol(${description})`;
125
- }
126
- }
127
- if (type == 'function') {
128
- const name = val.name;
129
- if (typeof name == 'string' && name.length > 0) {
130
- return `Function(${name})`;
131
- } else {
132
- return 'Function';
133
- }
134
- }
135
- // objects
136
- if (Array.isArray(val)) {
137
- const length = val.length;
138
- let debug = '[';
139
- if (length > 0) {
140
- debug += debugString(val[0]);
141
- }
142
- for(let i = 1; i < length; i++) {
143
- debug += ', ' + debugString(val[i]);
144
- }
145
- debug += ']';
146
- return debug;
147
- }
148
- // Test for built-in
149
- const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
150
- let className;
151
- if (builtInMatches && builtInMatches.length > 1) {
152
- className = builtInMatches[1];
153
- } else {
154
- // Failed to match the standard '[object ClassName]'
155
- return toString.call(val);
156
- }
157
- if (className == 'Object') {
158
- // we're a user defined class or Object
159
- // JSON.stringify avoids problems with cycles, and is generally much
160
- // easier than looping through ownProperties of `val`.
161
- try {
162
- return 'Object(' + JSON.stringify(val) + ')';
163
- } catch (_) {
164
- return 'Object';
165
- }
166
- }
167
- // errors
168
- if (val instanceof Error) {
169
- return `${val.name}: ${val.message}\n${val.stack}`;
170
- }
171
- // TODO we could test for more things here, like `Set`s and `Map`s.
172
- return className;
173
- }
174
-
175
- function takeFromExternrefTable0(idx) {
176
- const value = wasm.__wbindgen_export_4.get(idx);
177
- wasm.__externref_table_dealloc(idx);
178
- return value;
383
+ if (!('encodeInto' in cachedTextEncoder)) {
384
+ cachedTextEncoder.encodeInto = function (arg, view) {
385
+ const buf = cachedTextEncoder.encode(arg);
386
+ view.set(buf);
387
+ return {
388
+ read: arg.length,
389
+ written: buf.length
390
+ };
391
+ };
179
392
  }
180
393
 
181
- const WasmSimulatorFinalization = (typeof FinalizationRegistry === 'undefined')
182
- ? { register: () => {}, unregister: () => {} }
183
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmsimulator_free(ptr >>> 0, 1));
184
-
185
- export class WasmSimulator {
186
-
187
- __destroy_into_raw() {
188
- const ptr = this.__wbg_ptr;
189
- this.__wbg_ptr = 0;
190
- WasmSimulatorFinalization.unregister(this);
191
- return ptr;
192
- }
394
+ let WASM_VECTOR_LEN = 0;
193
395
 
194
- free() {
195
- const ptr = this.__destroy_into_raw();
196
- wasm.__wbg_wasmsimulator_free(ptr, 0);
197
- }
198
- /**
199
- * @param {string} ocpn_json_string
200
- */
201
- constructor(ocpn_json_string) {
202
- const ptr0 = passStringToWasm0(ocpn_json_string, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
203
- const len0 = WASM_VECTOR_LEN;
204
- const ret = wasm.wasmsimulator_new(ptr0, len0);
205
- if (ret[2]) {
206
- throw takeFromExternrefTable0(ret[1]);
207
- }
208
- this.__wbg_ptr = ret[0] >>> 0;
209
- WasmSimulatorFinalization.register(this, this.__wbg_ptr, this);
210
- return this;
211
- }
212
- /**
213
- * @param {Function} listener
214
- */
215
- setEventListener(listener) {
216
- wasm.wasmsimulator_setEventListener(this.__wbg_ptr, listener);
217
- }
218
- /**
219
- * @returns {any}
220
- */
221
- run_step() {
222
- const ret = wasm.wasmsimulator_run_step(this.__wbg_ptr);
223
- if (ret[2]) {
224
- throw takeFromExternrefTable0(ret[1]);
225
- }
226
- return takeFromExternrefTable0(ret[0]);
227
- }
396
+ let wasmModule, wasm;
397
+ function __wbg_finalize_init(instance, module) {
398
+ wasm = instance.exports;
399
+ wasmModule = module;
400
+ cachedDataViewMemory0 = null;
401
+ cachedUint8ArrayMemory0 = null;
402
+ wasm.__wbindgen_start();
403
+ return wasm;
228
404
  }
229
405
 
230
406
  async function __wbg_load(module, imports) {
@@ -232,245 +408,41 @@ async function __wbg_load(module, imports) {
232
408
  if (typeof WebAssembly.instantiateStreaming === 'function') {
233
409
  try {
234
410
  return await WebAssembly.instantiateStreaming(module, imports);
235
-
236
411
  } catch (e) {
237
- if (module.headers.get('Content-Type') != 'application/wasm') {
412
+ const validResponse = module.ok && expectedResponseType(module.type);
413
+
414
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
238
415
  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);
239
416
 
240
- } else {
241
- throw e;
242
- }
417
+ } else { throw e; }
243
418
  }
244
419
  }
245
420
 
246
421
  const bytes = await module.arrayBuffer();
247
422
  return await WebAssembly.instantiate(bytes, imports);
248
-
249
423
  } else {
250
424
  const instance = await WebAssembly.instantiate(module, imports);
251
425
 
252
426
  if (instance instanceof WebAssembly.Instance) {
253
427
  return { instance, module };
254
-
255
428
  } else {
256
429
  return instance;
257
430
  }
258
431
  }
259
- }
260
432
 
261
- function __wbg_get_imports() {
262
- const imports = {};
263
- imports.wbg = {};
264
- imports.wbg.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
265
- const ret = String(arg1);
266
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
267
- const len1 = WASM_VECTOR_LEN;
268
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
269
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
270
- };
271
- imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
272
- const ret = arg0.buffer;
273
- return ret;
274
- };
275
- imports.wbg.__wbg_call_672a4d21634d4a24 = function() { return handleError(function (arg0, arg1) {
276
- const ret = arg0.call(arg1);
277
- return ret;
278
- }, arguments) };
279
- imports.wbg.__wbg_call_7cccdd69e0791ae2 = function() { return handleError(function (arg0, arg1, arg2) {
280
- const ret = arg0.call(arg1, arg2);
281
- return ret;
282
- }, arguments) };
283
- imports.wbg.__wbg_crypto_ed58b8e10a292839 = function(arg0) {
284
- const ret = arg0.crypto;
285
- return ret;
286
- };
287
- imports.wbg.__wbg_fromCodePoint_f37c25c172f2e8b5 = function() { return handleError(function (arg0) {
288
- const ret = String.fromCodePoint(arg0 >>> 0);
289
- return ret;
290
- }, arguments) };
291
- imports.wbg.__wbg_from_2a5d3e218e67aa85 = function(arg0) {
292
- const ret = Array.from(arg0);
293
- return ret;
294
- };
295
- imports.wbg.__wbg_getRandomValues_21a0191e74d0e1d3 = function() { return handleError(function (arg0, arg1) {
296
- globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
297
- }, arguments) };
298
- imports.wbg.__wbg_getRandomValues_bcb4912f16000dc4 = function() { return handleError(function (arg0, arg1) {
299
- arg0.getRandomValues(arg1);
300
- }, arguments) };
301
- imports.wbg.__wbg_get_67b2ba62fc30de12 = function() { return handleError(function (arg0, arg1) {
302
- const ret = Reflect.get(arg0, arg1);
303
- return ret;
304
- }, arguments) };
305
- imports.wbg.__wbg_msCrypto_0a36e2ec3a343d26 = function(arg0) {
306
- const ret = arg0.msCrypto;
307
- return ret;
308
- };
309
- imports.wbg.__wbg_new_405e22f390576ce2 = function() {
310
- const ret = new Object();
311
- return ret;
312
- };
313
- imports.wbg.__wbg_new_5e0be73521bc8c17 = function() {
314
- const ret = new Map();
315
- return ret;
316
- };
317
- imports.wbg.__wbg_new_78feb108b6472713 = function() {
318
- const ret = new Array();
319
- return ret;
320
- };
321
- imports.wbg.__wbg_new_a12002a7f91c75be = function(arg0) {
322
- const ret = new Uint8Array(arg0);
323
- return ret;
324
- };
325
- imports.wbg.__wbg_newnoargs_105ed471475aaf50 = function(arg0, arg1) {
326
- const ret = new Function(getStringFromWasm0(arg0, arg1));
327
- return ret;
328
- };
329
- imports.wbg.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
330
- const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
331
- return ret;
332
- };
333
- imports.wbg.__wbg_newwithlength_a381634e90c276d4 = function(arg0) {
334
- const ret = new Uint8Array(arg0 >>> 0);
335
- return ret;
336
- };
337
- imports.wbg.__wbg_node_02999533c4ea02e3 = function(arg0) {
338
- const ret = arg0.node;
339
- return ret;
340
- };
341
- imports.wbg.__wbg_now_d18023d54d4e5500 = function(arg0) {
342
- const ret = arg0.now();
343
- return ret;
344
- };
345
- imports.wbg.__wbg_process_5c1d670bc53614b8 = function(arg0) {
346
- const ret = arg0.process;
347
- return ret;
348
- };
349
- imports.wbg.__wbg_randomFillSync_ab2cfe79ebbf2740 = function() { return handleError(function (arg0, arg1) {
350
- arg0.randomFillSync(arg1);
351
- }, arguments) };
352
- imports.wbg.__wbg_require_79b1e9274cde3c87 = function() { return handleError(function () {
353
- const ret = module.require;
354
- return ret;
355
- }, arguments) };
356
- imports.wbg.__wbg_set_37837023f3d740e8 = function(arg0, arg1, arg2) {
357
- arg0[arg1 >>> 0] = arg2;
358
- };
359
- imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
360
- arg0[arg1] = arg2;
361
- };
362
- imports.wbg.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
363
- arg0.set(arg1, arg2 >>> 0);
364
- };
365
- imports.wbg.__wbg_set_8fc6bf8a5b1071d1 = function(arg0, arg1, arg2) {
366
- const ret = arg0.set(arg1, arg2);
367
- return ret;
368
- };
369
- imports.wbg.__wbg_static_accessor_GLOBAL_88a902d13a557d07 = function() {
370
- const ret = typeof global === 'undefined' ? null : global;
371
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
372
- };
373
- imports.wbg.__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0 = function() {
374
- const ret = typeof globalThis === 'undefined' ? null : globalThis;
375
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
376
- };
377
- imports.wbg.__wbg_static_accessor_SELF_37c5d418e4bf5819 = function() {
378
- const ret = typeof self === 'undefined' ? null : self;
379
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
380
- };
381
- imports.wbg.__wbg_static_accessor_WINDOW_5de37043a91a9c40 = function() {
382
- const ret = typeof window === 'undefined' ? null : window;
383
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
384
- };
385
- imports.wbg.__wbg_subarray_aa9065fa9dc5df96 = function(arg0, arg1, arg2) {
386
- const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
387
- return ret;
388
- };
389
- imports.wbg.__wbg_versions_c71aa1626a93e0a1 = function(arg0) {
390
- const ret = arg0.versions;
391
- return ret;
392
- };
393
- imports.wbg.__wbindgen_bigint_from_i64 = function(arg0) {
394
- const ret = arg0;
395
- return ret;
396
- };
397
- imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
398
- const ret = debugString(arg1);
399
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
400
- const len1 = WASM_VECTOR_LEN;
401
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
402
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
403
- };
404
- imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
405
- const ret = new Error(getStringFromWasm0(arg0, arg1));
406
- return ret;
407
- };
408
- imports.wbg.__wbindgen_init_externref_table = function() {
409
- const table = wasm.__wbindgen_export_4;
410
- const offset = table.grow(4);
411
- table.set(0, undefined);
412
- table.set(offset + 0, undefined);
413
- table.set(offset + 1, null);
414
- table.set(offset + 2, true);
415
- table.set(offset + 3, false);
416
- ;
417
- };
418
- imports.wbg.__wbindgen_is_function = function(arg0) {
419
- const ret = typeof(arg0) === 'function';
420
- return ret;
421
- };
422
- imports.wbg.__wbindgen_is_object = function(arg0) {
423
- const val = arg0;
424
- const ret = typeof(val) === 'object' && val !== null;
425
- return ret;
426
- };
427
- imports.wbg.__wbindgen_is_string = function(arg0) {
428
- const ret = typeof(arg0) === 'string';
429
- return ret;
430
- };
431
- imports.wbg.__wbindgen_is_undefined = function(arg0) {
432
- const ret = arg0 === undefined;
433
- return ret;
434
- };
435
- imports.wbg.__wbindgen_memory = function() {
436
- const ret = wasm.memory;
437
- return ret;
438
- };
439
- imports.wbg.__wbindgen_number_new = function(arg0) {
440
- const ret = arg0;
441
- return ret;
442
- };
443
- imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
444
- const ret = getStringFromWasm0(arg0, arg1);
445
- return ret;
446
- };
447
- imports.wbg.__wbindgen_throw = function(arg0, arg1) {
448
- throw new Error(getStringFromWasm0(arg0, arg1));
449
- };
450
-
451
- return imports;
452
- }
453
-
454
- function __wbg_init_memory(imports, memory) {
455
-
456
- }
457
-
458
- function __wbg_finalize_init(instance, module) {
459
- wasm = instance.exports;
460
- __wbg_init.__wbindgen_wasm_module = module;
461
- cachedDataViewMemory0 = null;
462
- cachedUint8ArrayMemory0 = null;
463
-
464
-
465
- wasm.__wbindgen_start();
466
- return wasm;
433
+ function expectedResponseType(type) {
434
+ switch (type) {
435
+ case 'basic': case 'cors': case 'default': return true;
436
+ }
437
+ return false;
438
+ }
467
439
  }
468
440
 
469
441
  function initSync(module) {
470
442
  if (wasm !== undefined) return wasm;
471
443
 
472
444
 
473
- if (typeof module !== 'undefined') {
445
+ if (module !== undefined) {
474
446
  if (Object.getPrototypeOf(module) === Object.prototype) {
475
447
  ({module} = module)
476
448
  } else {
@@ -479,15 +451,10 @@ function initSync(module) {
479
451
  }
480
452
 
481
453
  const imports = __wbg_get_imports();
482
-
483
- __wbg_init_memory(imports);
484
-
485
454
  if (!(module instanceof WebAssembly.Module)) {
486
455
  module = new WebAssembly.Module(module);
487
456
  }
488
-
489
457
  const instance = new WebAssembly.Instance(module, imports);
490
-
491
458
  return __wbg_finalize_init(instance, module);
492
459
  }
493
460
 
@@ -495,7 +462,7 @@ async function __wbg_init(module_or_path) {
495
462
  if (wasm !== undefined) return wasm;
496
463
 
497
464
 
498
- if (typeof module_or_path !== 'undefined') {
465
+ if (module_or_path !== undefined) {
499
466
  if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
500
467
  ({module_or_path} = module_or_path)
501
468
  } else {
@@ -503,7 +470,7 @@ async function __wbg_init(module_or_path) {
503
470
  }
504
471
  }
505
472
 
506
- if (typeof module_or_path === 'undefined') {
473
+ if (module_or_path === undefined) {
507
474
  module_or_path = new URL('cpnsim_bg.wasm', import.meta.url);
508
475
  }
509
476
  const imports = __wbg_get_imports();
@@ -512,12 +479,9 @@ async function __wbg_init(module_or_path) {
512
479
  module_or_path = fetch(module_or_path);
513
480
  }
514
481
 
515
- __wbg_init_memory(imports);
516
-
517
482
  const { instance, module } = await __wbg_load(await module_or_path, imports);
518
483
 
519
484
  return __wbg_finalize_init(instance, module);
520
485
  }
521
486
 
522
- export { initSync };
523
- export default __wbg_init;
487
+ export { initSync, __wbg_init as default };
package/cpnsim_bg.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "István Koren"
6
6
  ],
7
7
  "description": "CPNsim is a Rust library and command-line tool with WebAssembly target for simulating Colored Petri Nets (CPNs)",
8
- "version": "0.1.8",
8
+ "version": "0.2.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",