@hypen-space/core 0.4.32 → 0.4.35

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.
Files changed (71) hide show
  1. package/dist/app.d.ts +73 -2
  2. package/dist/app.js +112 -9
  3. package/dist/app.js.map +6 -5
  4. package/dist/components/builtin.js +112 -9
  5. package/dist/components/builtin.js.map +6 -5
  6. package/dist/context.d.ts +8 -0
  7. package/dist/context.js +6 -2
  8. package/dist/context.js.map +3 -3
  9. package/dist/datasource.d.ts +168 -0
  10. package/dist/discovery.js +114 -9
  11. package/dist/discovery.js.map +7 -6
  12. package/dist/disposable.js +6 -2
  13. package/dist/disposable.js.map +2 -2
  14. package/dist/engine.browser.d.ts +15 -0
  15. package/dist/engine.browser.js +19 -2
  16. package/dist/engine.browser.js.map +3 -3
  17. package/dist/engine.d.ts +22 -0
  18. package/dist/engine.js +37 -3
  19. package/dist/engine.js.map +3 -3
  20. package/dist/events.js +6 -2
  21. package/dist/events.js.map +2 -2
  22. package/dist/index.browser.js +295 -179
  23. package/dist/index.browser.js.map +9 -8
  24. package/dist/index.d.ts +3 -1
  25. package/dist/index.js +298 -179
  26. package/dist/index.js.map +10 -9
  27. package/dist/loader.js +6 -2
  28. package/dist/loader.js.map +2 -2
  29. package/dist/logger.js +6 -2
  30. package/dist/logger.js.map +2 -2
  31. package/dist/plugin.js +6 -2
  32. package/dist/plugin.js.map +2 -2
  33. package/dist/remote/client.js +6 -2
  34. package/dist/remote/client.js.map +2 -2
  35. package/dist/remote/index.js +152 -11
  36. package/dist/remote/index.js.map +9 -8
  37. package/dist/remote/server.js +152 -11
  38. package/dist/remote/server.js.map +9 -8
  39. package/dist/renderer.js +6 -2
  40. package/dist/renderer.js.map +2 -2
  41. package/dist/resolver.js +6 -2
  42. package/dist/resolver.js.map +2 -2
  43. package/dist/router.d.ts +9 -0
  44. package/dist/router.js +186 -18
  45. package/dist/router.js.map +6 -5
  46. package/dist/state.js +13 -6
  47. package/dist/state.js.map +3 -3
  48. package/package.json +1 -1
  49. package/src/app.ts +121 -4
  50. package/src/context.ts +10 -2
  51. package/src/datasource.ts +252 -0
  52. package/src/discovery.ts +2 -0
  53. package/src/engine.browser.ts +30 -0
  54. package/src/engine.ts +56 -1
  55. package/src/index.ts +16 -0
  56. package/src/managed-router.ts +3 -0
  57. package/src/remote/server.ts +11 -2
  58. package/src/router.ts +36 -10
  59. package/src/state.ts +10 -3
  60. package/wasm-browser/README.md +10 -10
  61. package/wasm-browser/hypen_engine.d.ts +368 -131
  62. package/wasm-browser/hypen_engine.js +896 -645
  63. package/wasm-browser/hypen_engine_bg.wasm +0 -0
  64. package/wasm-browser/hypen_engine_bg.wasm.d.ts +20 -13
  65. package/wasm-browser/package.json +1 -1
  66. package/wasm-node/README.md +10 -10
  67. package/wasm-node/hypen_engine.d.ts +318 -89
  68. package/wasm-node/hypen_engine.js +832 -613
  69. package/wasm-node/hypen_engine_bg.wasm +0 -0
  70. package/wasm-node/hypen_engine_bg.wasm.d.ts +20 -13
  71. package/wasm-node/package.json +1 -1
@@ -1,310 +1,202 @@
1
+ /* @ts-self-types="./hypen_engine.d.ts" */
1
2
 
2
- let imports = {};
3
- imports['__wbindgen_placeholder__'] = module.exports;
4
-
5
- let cachedUint8ArrayMemory0 = null;
6
-
7
- function getUint8ArrayMemory0() {
8
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
9
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
10
- }
11
- return cachedUint8ArrayMemory0;
12
- }
13
-
14
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
15
-
16
- cachedTextDecoder.decode();
17
-
18
- function decodeText(ptr, len) {
19
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
20
- }
21
-
22
- function getStringFromWasm0(ptr, len) {
23
- ptr = ptr >>> 0;
24
- return decodeText(ptr, len);
25
- }
26
-
27
- let WASM_VECTOR_LEN = 0;
28
-
29
- const cachedTextEncoder = new TextEncoder();
30
-
31
- if (!('encodeInto' in cachedTextEncoder)) {
32
- cachedTextEncoder.encodeInto = function (arg, view) {
33
- const buf = cachedTextEncoder.encode(arg);
34
- view.set(buf);
35
- return {
36
- read: arg.length,
37
- written: buf.length
38
- };
39
- }
40
- }
41
-
42
- function passStringToWasm0(arg, malloc, realloc) {
43
-
44
- if (realloc === undefined) {
45
- const buf = cachedTextEncoder.encode(arg);
46
- const ptr = malloc(buf.length, 1) >>> 0;
47
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
48
- WASM_VECTOR_LEN = buf.length;
49
- return ptr;
50
- }
51
-
52
- let len = arg.length;
53
- let ptr = malloc(len, 1) >>> 0;
54
-
55
- const mem = getUint8ArrayMemory0();
56
-
57
- let offset = 0;
58
-
59
- for (; offset < len; offset++) {
60
- const code = arg.charCodeAt(offset);
61
- if (code > 0x7F) break;
62
- mem[ptr + offset] = code;
63
- }
64
-
65
- if (offset !== len) {
66
- if (offset !== 0) {
67
- arg = arg.slice(offset);
68
- }
69
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
70
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
71
- const ret = cachedTextEncoder.encodeInto(arg, view);
72
-
73
- offset += ret.written;
74
- ptr = realloc(ptr, len, offset, 1) >>> 0;
75
- }
76
-
77
- WASM_VECTOR_LEN = offset;
78
- return ptr;
79
- }
80
-
81
- let cachedDataViewMemory0 = null;
82
-
83
- function getDataViewMemory0() {
84
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
85
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
86
- }
87
- return cachedDataViewMemory0;
88
- }
89
-
90
- function addToExternrefTable0(obj) {
91
- const idx = wasm.__externref_table_alloc();
92
- wasm.__wbindgen_export_4.set(idx, obj);
93
- return idx;
94
- }
95
-
96
- function handleError(f, args) {
97
- try {
98
- return f.apply(this, args);
99
- } catch (e) {
100
- const idx = addToExternrefTable0(e);
101
- wasm.__wbindgen_exn_store(idx);
102
- }
103
- }
104
-
105
- function getArrayU8FromWasm0(ptr, len) {
106
- ptr = ptr >>> 0;
107
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
108
- }
109
-
110
- function isLikeNone(x) {
111
- return x === undefined || x === null;
112
- }
113
-
114
- function debugString(val) {
115
- // primitive types
116
- const type = typeof val;
117
- if (type == 'number' || type == 'boolean' || val == null) {
118
- return `${val}`;
119
- }
120
- if (type == 'string') {
121
- return `"${val}"`;
122
- }
123
- if (type == 'symbol') {
124
- const description = val.description;
125
- if (description == null) {
126
- return 'Symbol';
127
- } else {
128
- return `Symbol(${description})`;
129
- }
130
- }
131
- if (type == 'function') {
132
- const name = val.name;
133
- if (typeof name == 'string' && name.length > 0) {
134
- return `Function(${name})`;
135
- } else {
136
- return 'Function';
137
- }
138
- }
139
- // objects
140
- if (Array.isArray(val)) {
141
- const length = val.length;
142
- let debug = '[';
143
- if (length > 0) {
144
- debug += debugString(val[0]);
145
- }
146
- for(let i = 1; i < length; i++) {
147
- debug += ', ' + debugString(val[i]);
148
- }
149
- debug += ']';
150
- return debug;
151
- }
152
- // Test for built-in
153
- const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
154
- let className;
155
- if (builtInMatches && builtInMatches.length > 1) {
156
- className = builtInMatches[1];
157
- } else {
158
- // Failed to match the standard '[object ClassName]'
159
- return toString.call(val);
160
- }
161
- if (className == 'Object') {
162
- // we're a user defined class or Object
163
- // JSON.stringify avoids problems with cycles, and is generally much
164
- // easier than looping through ownProperties of `val`.
165
- try {
166
- return 'Object(' + JSON.stringify(val) + ')';
167
- } catch (_) {
168
- return 'Object';
169
- }
170
- }
171
- // errors
172
- if (val instanceof Error) {
173
- return `${val.name}: ${val.message}\n${val.stack}`;
174
- }
175
- // TODO we could test for more things here, like `Set`s and `Map`s.
176
- return className;
177
- }
178
-
179
- function takeFromExternrefTable0(idx) {
180
- const value = wasm.__wbindgen_export_4.get(idx);
181
- wasm.__externref_table_dealloc(idx);
182
- return value;
183
- }
184
-
185
- function passArrayJsValueToWasm0(array, malloc) {
186
- const ptr = malloc(array.length * 4, 4) >>> 0;
187
- for (let i = 0; i < array.length; i++) {
188
- const add = addToExternrefTable0(array[i]);
189
- getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
190
- }
191
- WASM_VECTOR_LEN = array.length;
192
- return ptr;
193
- }
194
- /**
195
- * Export patches as JSON string (for debugging)
196
- * @param {any} patches
197
- * @returns {string}
198
- */
199
- exports.patchesToJson = function(patches) {
200
- let deferred2_0;
201
- let deferred2_1;
202
- try {
203
- const ret = wasm.patchesToJson(patches);
204
- var ptr1 = ret[0];
205
- var len1 = ret[1];
206
- if (ret[3]) {
207
- ptr1 = 0; len1 = 0;
208
- throw takeFromExternrefTable0(ret[2]);
209
- }
210
- deferred2_0 = ptr1;
211
- deferred2_1 = len1;
212
- return getStringFromWasm0(ptr1, len1);
213
- } finally {
214
- wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
215
- }
216
- };
217
-
218
- /**
219
- * Parse Hypen DSL and return AST as JSON
220
- * @param {string} source
221
- * @returns {string}
222
- */
223
- exports.parseToJson = function(source) {
224
- let deferred3_0;
225
- let deferred3_1;
226
- try {
227
- const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
228
- const len0 = WASM_VECTOR_LEN;
229
- const ret = wasm.parseToJson(ptr0, len0);
230
- var ptr2 = ret[0];
231
- var len2 = ret[1];
232
- if (ret[3]) {
233
- ptr2 = 0; len2 = 0;
234
- throw takeFromExternrefTable0(ret[2]);
235
- }
236
- deferred3_0 = ptr2;
237
- deferred3_1 = len2;
238
- return getStringFromWasm0(ptr2, len2);
239
- } finally {
240
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
241
- }
242
- };
243
-
244
- exports.main = function() {
245
- wasm.main();
246
- };
247
-
248
- const WasmEngineFinalization = (typeof FinalizationRegistry === 'undefined')
249
- ? { register: () => {}, unregister: () => {} }
250
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmengine_free(ptr >>> 0, 1));
251
3
  /**
252
- * WASM-exported engine instance for JavaScript runtimes
253
- * Uses Rc<RefCell<>> instead of Send+Sync for WASM single-threaded environment
4
+ * The main Hypen engine interface for JavaScript/WASM runtimes.
5
+ *
6
+ * `WasmEngine` manages the full lifecycle of a Hypen UI: parsing DSL source,
7
+ * maintaining the virtual tree, tracking reactive dependencies, and emitting
8
+ * minimal patches when state changes. It runs in a single-threaded WASM
9
+ * environment (browsers, Node.js, Bun, Deno).
10
+ *
11
+ * # Quick Start
12
+ *
13
+ * ```js
14
+ * import { WasmEngine } from "@hypen-space/core";
15
+ *
16
+ * const engine = new WasmEngine();
17
+ *
18
+ * // 1. Register primitives so the engine doesn't try to resolve them as components
19
+ * engine.registerPrimitive("Text");
20
+ * engine.registerPrimitive("Column");
21
+ *
22
+ * // 2. Receive patches via callback
23
+ * engine.setRenderCallback((patches) => {
24
+ * for (const patch of patches) {
25
+ * applyPatch(patch); // Create, SetProp, Insert, Remove, etc.
26
+ * }
27
+ * });
28
+ *
29
+ * // 3. Optionally set up a module for stateful UI
30
+ * engine.setModule("Counter", ["increment"], ["count"], { count: 0 });
31
+ *
32
+ * // 4. Render DSL source — patches are emitted via the callback
33
+ * engine.renderSource('Column { Text("Count: ${state.count}") }');
34
+ *
35
+ * // 5. Update state — only affected nodes are re-rendered
36
+ * engine.updateState({ count: 1 });
37
+ * ```
38
+ *
39
+ * # Patch Protocol
40
+ *
41
+ * All UI mutations are expressed as [`Patch`] values emitted through the render
42
+ * callback. Patches use camelCase field names for direct JavaScript consumption.
43
+ * See [`Patch`] for the full variant list and field documentation.
44
+ *
45
+ * # Component Resolution
46
+ *
47
+ * Custom components (anything not registered as a primitive) are resolved lazily
48
+ * via the component resolver callback set with [`set_component_resolver`]. The
49
+ * resolver receives `(componentName, contextPath)` and should return
50
+ * `{ source: string, path: string }` or `null`.
51
+ *
52
+ * # Revision Tracking
53
+ *
54
+ * Every render cycle (initial render or state update that produces patches)
55
+ * increments the revision counter. Use [`get_revision`] to detect stale state
56
+ * in async workflows.
254
57
  */
255
58
  class WasmEngine {
256
-
257
59
  __destroy_into_raw() {
258
60
  const ptr = this.__wbg_ptr;
259
61
  this.__wbg_ptr = 0;
260
62
  WasmEngineFinalization.unregister(this);
261
63
  return ptr;
262
64
  }
263
-
264
65
  free() {
265
66
  const ptr = this.__destroy_into_raw();
266
67
  wasm.__wbg_wasmengine_free(ptr, 0);
267
68
  }
268
69
  /**
269
- * Create a new engine instance
70
+ * Remove all nodes from the instance tree without emitting Remove patches.
71
+ *
72
+ * Use this when tearing down the UI entirely (e.g. navigating away or
73
+ * switching samples). The renderer is responsible for clearing its own
74
+ * DOM/canvas state separately.
270
75
  */
271
- constructor() {
272
- const ret = wasm.wasmengine_new();
273
- this.__wbg_ptr = ret >>> 0;
274
- WasmEngineFinalization.register(this, this.__wbg_ptr, this);
275
- return this;
76
+ clearTree() {
77
+ wasm.wasmengine_clearTree(this.__wbg_ptr);
78
+ }
79
+ /**
80
+ * Return a JSON snapshot of the active module's current state.
81
+ *
82
+ * Returns `null` (as a `JsValue`) if no module is set.
83
+ * Useful for debugging and DevTools integration.
84
+ * @returns {any}
85
+ */
86
+ currentState() {
87
+ const ret = wasm.wasmengine_currentState(this.__wbg_ptr);
88
+ return ret;
276
89
  }
277
90
  /**
278
- * Parse and render Hypen DSL source code
279
- * Supports documents with import statements - imports are resolved via the component resolver
91
+ * Parse a component and return a human-readable debug string.
92
+ *
93
+ * Intended for development tooling only — the output format is not stable.
280
94
  * @param {string} source
95
+ * @returns {string}
281
96
  */
282
- renderSource(source) {
283
- const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
97
+ debugParseComponent(source) {
98
+ let deferred3_0;
99
+ let deferred3_1;
100
+ try {
101
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
102
+ const len0 = WASM_VECTOR_LEN;
103
+ const ret = wasm.wasmengine_debugParseComponent(this.__wbg_ptr, ptr0, len0);
104
+ var ptr2 = ret[0];
105
+ var len2 = ret[1];
106
+ if (ret[3]) {
107
+ ptr2 = 0; len2 = 0;
108
+ throw takeFromExternrefTable0(ret[2]);
109
+ }
110
+ deferred3_0 = ptr2;
111
+ deferred3_1 = len2;
112
+ return getStringFromWasm0(ptr2, len2);
113
+ } finally {
114
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
115
+ }
116
+ }
117
+ /**
118
+ * Dispatch a named action, invoking the registered handler (if any).
119
+ *
120
+ * Actions are the primary way UI events flow from the renderer back to
121
+ * application logic. In Hypen DSL, buttons reference actions like
122
+ * `Button("@actions.submit")` — the renderer maps clicks to
123
+ * `engine.dispatchAction("submit", payload)`.
124
+ *
125
+ * # Arguments
126
+ * * `name` — Action name (e.g. `"submit"`, `"increment"`)
127
+ * * `payload` — Optional JS value passed to the handler. `null`/`undefined` are treated as no payload.
128
+ *
129
+ * # Errors
130
+ *
131
+ * Returns an error if the payload cannot be deserialized. Does **not** error
132
+ * if no handler is registered (the action is silently dropped).
133
+ * @param {string} name
134
+ * @param {any} payload
135
+ */
136
+ dispatchAction(name, payload) {
137
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
284
138
  const len0 = WASM_VECTOR_LEN;
285
- const ret = wasm.wasmengine_renderSource(this.__wbg_ptr, ptr0, len0);
139
+ const ret = wasm.wasmengine_dispatchAction(this.__wbg_ptr, ptr0, len0, payload);
286
140
  if (ret[1]) {
287
141
  throw takeFromExternrefTable0(ret[0]);
288
142
  }
289
143
  }
290
144
  /**
291
- * Set the render callback that receives patches
292
- * @param {Function} callback
145
+ * Get the current revision number.
146
+ *
147
+ * Starts at 0 and increments by 1 for each render cycle that produces
148
+ * patches. Useful for cache invalidation and detecting stale async results.
149
+ * @returns {bigint}
293
150
  */
294
- setRenderCallback(callback) {
295
- wasm.wasmengine_setRenderCallback(this.__wbg_ptr, callback);
151
+ getRevision() {
152
+ const ret = wasm.wasmengine_getRevision(this.__wbg_ptr);
153
+ return BigInt.asUintN(64, ret);
296
154
  }
297
155
  /**
298
- * Set the component resolver callback
299
- * The resolver receives (componentName, contextPath) and should return
300
- * { source: string, path: string } or null
156
+ * Create a new engine instance with an empty tree and no module.
301
157
  *
302
- * contextPath is the path of the component that's referencing this component
303
- * The returned path should be the resolved absolute path to the component file
304
- * @param {Function} resolver
158
+ * After construction, you typically:
159
+ * 1. Register primitives with [`register_primitive`]
160
+ * 2. Set a render callback with [`set_render_callback`]
161
+ * 3. Optionally set a component resolver with [`set_component_resolver`]
162
+ * 4. Optionally initialize a module with [`set_module`]
163
+ * 5. Render source with [`render_source`]
305
164
  */
306
- setComponentResolver(resolver) {
307
- wasm.wasmengine_setComponentResolver(this.__wbg_ptr, resolver);
165
+ constructor() {
166
+ const ret = wasm.wasmengine_new();
167
+ this.__wbg_ptr = ret >>> 0;
168
+ WasmEngineFinalization.register(this, this.__wbg_ptr, this);
169
+ return this;
170
+ }
171
+ /**
172
+ * Register a JavaScript function as the handler for a named action.
173
+ *
174
+ * When [`dispatch_action`] is called with a matching name, the handler
175
+ * receives a serialized [`Action`] object with `{ name, payload }`.
176
+ *
177
+ * Registering a handler for the same name replaces the previous one.
178
+ * @param {string} action_name
179
+ * @param {Function} handler
180
+ */
181
+ onAction(action_name, handler) {
182
+ const ptr0 = passStringToWasm0(action_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
183
+ const len0 = WASM_VECTOR_LEN;
184
+ wasm.wasmengine_onAction(this.__wbg_ptr, ptr0, len0, handler);
185
+ }
186
+ /**
187
+ * Register a handler for data source actions.
188
+ *
189
+ * When [`dispatch_action`] is called with a name like `"spacetime.sendMessage"`
190
+ * and no explicit action handler is registered for that name, the engine checks
191
+ * if the prefix (`"spacetime"`) is a registered data source. If so, it calls
192
+ * this handler with `{ provider, method, payload }`.
193
+ *
194
+ * This enables `@actions.spacetime.sendMessage` in DSL to automatically route
195
+ * to the appropriate data source plugin without manual handler registration.
196
+ * @param {Function} handler
197
+ */
198
+ onDataSourceAction(handler) {
199
+ wasm.wasmengine_onDataSourceAction(this.__wbg_ptr, handler);
308
200
  }
309
201
  /**
310
202
  * Register a primitive element (like Text, Button, etc.) to skip component resolution
@@ -317,17 +209,15 @@ class WasmEngine {
317
209
  wasm.wasmengine_registerPrimitive(this.__wbg_ptr, ptr0, len0);
318
210
  }
319
211
  /**
320
- * Render a component source (for lazy loading routes)
321
- * This allows rendering a component on-demand
322
- * @param {string} source
212
+ * Remove a data source context entirely.
213
+ *
214
+ * Drops the provider's state and re-renders bound nodes (they resolve to `null`).
215
+ * @param {string} name
323
216
  */
324
- renderLazyComponent(source) {
325
- const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
217
+ removeContext(name) {
218
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
326
219
  const len0 = WASM_VECTOR_LEN;
327
- const ret = wasm.wasmengine_renderLazyComponent(this.__wbg_ptr, ptr0, len0);
328
- if (ret[1]) {
329
- throw takeFromExternrefTable0(ret[0]);
330
- }
220
+ wasm.wasmengine_removeContext(this.__wbg_ptr, ptr0, len0);
331
221
  }
332
222
  /**
333
223
  * Render a component into a specific parent node (subtree rendering)
@@ -352,409 +242,738 @@ class WasmEngine {
352
242
  }
353
243
  }
354
244
  /**
355
- * Update state from JavaScript
356
- * @param {any} state_patch
245
+ * Render a component source on-demand (for lazy-loaded routes).
246
+ *
247
+ * Equivalent to calling [`render_source`] — the source is parsed as a full
248
+ * document and replaces the current tree.
249
+ * @param {string} source
357
250
  */
358
- updateState(state_patch) {
359
- const ret = wasm.wasmengine_updateState(this.__wbg_ptr, state_patch);
251
+ renderLazyComponent(source) {
252
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
253
+ const len0 = WASM_VECTOR_LEN;
254
+ const ret = wasm.wasmengine_renderLazyComponent(this.__wbg_ptr, ptr0, len0);
360
255
  if (ret[1]) {
361
256
  throw takeFromExternrefTable0(ret[0]);
362
257
  }
363
258
  }
364
259
  /**
365
- * Update state using sparse path-value pairs
366
- * More efficient than updateState for large state objects when only a few paths changed
260
+ * Parse and render Hypen DSL source code, emitting patches via the render callback.
367
261
  *
368
- * # Arguments
369
- * * `paths_js` - Array of changed paths (e.g., ["user.name", "count"])
370
- * * `values_js` - Object mapping paths to their new values (e.g., { "user.name": "Bob", "count": 42 })
371
- * @param {any} paths_js
372
- * @param {any} values_js
262
+ * Supports full document syntax including `import` statements. Imports are
263
+ * resolved synchronously through the component resolver callback (if set).
264
+ *
265
+ * This performs a **full reconciliation** — the existing tree is diffed against
266
+ * the new IR and minimal patches are emitted. Calling this multiple times with
267
+ * different source replaces the previous UI.
268
+ *
269
+ * # Errors
270
+ *
271
+ * Returns a `JsValue` string error if the source fails to parse.
272
+ * @param {string} source
373
273
  */
374
- updateStateSparse(paths_js, values_js) {
375
- const ret = wasm.wasmengine_updateStateSparse(this.__wbg_ptr, paths_js, values_js);
274
+ renderSource(source) {
275
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
276
+ const len0 = WASM_VECTOR_LEN;
277
+ const ret = wasm.wasmengine_renderSource(this.__wbg_ptr, ptr0, len0);
376
278
  if (ret[1]) {
377
279
  throw takeFromExternrefTable0(ret[0]);
378
280
  }
379
281
  }
380
282
  /**
381
- * Dispatch an action
283
+ * Fully reset the engine to its initial empty state.
284
+ *
285
+ * Clears the tree, module, dependencies, scheduler, action handlers,
286
+ * component registry, and resets the revision to 0. The render callback
287
+ * and component resolver are preserved.
288
+ */
289
+ reset() {
290
+ wasm.wasmengine_reset(this.__wbg_ptr);
291
+ }
292
+ /**
293
+ * Set the component resolver callback
294
+ * The resolver receives (componentName, contextPath) and should return
295
+ * { source: string, path: string } or null
296
+ *
297
+ * contextPath is the path of the component that's referencing this component
298
+ * The returned path should be the resolved absolute path to the component file
299
+ * @param {Function} resolver
300
+ */
301
+ setComponentResolver(resolver) {
302
+ wasm.wasmengine_setComponentResolver(this.__wbg_ptr, resolver);
303
+ }
304
+ /**
305
+ * Set (or replace) a named data source context.
306
+ *
307
+ * Registers the provider in the dependency graph (if not already known),
308
+ * stores the data, and re-renders every node bound to `$name.*`.
309
+ * Sparse merging (if needed) should happen at the SDK layer before
310
+ * calling this method with the merged object.
311
+ *
312
+ * # Example (JS)
313
+ * ```js
314
+ * engine.setContext("spacetime", {
315
+ * message: [{ id: 1, text: "Hello" }, { id: 2, text: "World" }],
316
+ * user: [{ id: 1, name: "Alice", online: true }]
317
+ * });
318
+ * ```
382
319
  * @param {string} name
383
- * @param {any} payload
320
+ * @param {any} data_js
384
321
  */
385
- dispatchAction(name, payload) {
322
+ setContext(name, data_js) {
386
323
  const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
387
324
  const len0 = WASM_VECTOR_LEN;
388
- const ret = wasm.wasmengine_dispatchAction(this.__wbg_ptr, ptr0, len0, payload);
325
+ const ret = wasm.wasmengine_setContext(this.__wbg_ptr, ptr0, len0, data_js);
389
326
  if (ret[1]) {
390
327
  throw takeFromExternrefTable0(ret[0]);
391
328
  }
392
329
  }
393
330
  /**
394
- * Register an action handler
395
- * @param {string} action_name
396
- * @param {Function} handler
331
+ * Initialize (or replace) the active module with the given configuration.
332
+ *
333
+ * A module provides stateful context for `${state.xxx}` bindings in the DSL.
334
+ * Only one module is active at a time — calling this again replaces it.
335
+ *
336
+ * # Arguments
337
+ * * `name` — Module identifier (e.g. `"Counter"`, `"ProfilePage"`)
338
+ * * `actions` — List of action names this module handles
339
+ * * `state_keys` — List of top-level state keys (used for validation)
340
+ * * `initial_state` — The starting state as a JS object
341
+ *
342
+ * # Errors
343
+ *
344
+ * Returns an error if `initial_state` cannot be deserialized as JSON.
345
+ * @param {string} name
346
+ * @param {string[]} actions
347
+ * @param {string[]} state_keys
348
+ * @param {any} initial_state
397
349
  */
398
- onAction(action_name, handler) {
399
- const ptr0 = passStringToWasm0(action_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
350
+ setModule(name, actions, state_keys, initial_state) {
351
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
400
352
  const len0 = WASM_VECTOR_LEN;
401
- wasm.wasmengine_onAction(this.__wbg_ptr, ptr0, len0, handler);
353
+ const ptr1 = passArrayJsValueToWasm0(actions, wasm.__wbindgen_malloc);
354
+ const len1 = WASM_VECTOR_LEN;
355
+ const ptr2 = passArrayJsValueToWasm0(state_keys, wasm.__wbindgen_malloc);
356
+ const len2 = WASM_VECTOR_LEN;
357
+ const ret = wasm.wasmengine_setModule(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, initial_state);
358
+ if (ret[1]) {
359
+ throw takeFromExternrefTable0(ret[0]);
360
+ }
402
361
  }
403
362
  /**
404
- * Clear the engine tree (useful when switching samples)
363
+ * Set the callback that receives UI patches after each render cycle.
364
+ *
365
+ * The callback is invoked with a single argument: a JavaScript array of
366
+ * [`Patch`] objects. Each patch describes one atomic DOM operation (Create,
367
+ * SetProp, SetText, Insert, Move, Remove, RemoveProp).
368
+ *
369
+ * The callback is called synchronously during `renderSource()`, `updateState()`,
370
+ * `updateStateSparse()`, and `renderInto()`.
371
+ *
372
+ * # Example (JS)
373
+ * ```js
374
+ * engine.setRenderCallback((patches) => {
375
+ * for (const p of patches) {
376
+ * switch (p.type) {
377
+ * case "create": createElement(p.id, p.elementType, p.props); break;
378
+ * case "setProp": setProperty(p.id, p.name, p.value); break;
379
+ * case "insert": insertChild(p.parentId, p.id, p.beforeId); break;
380
+ * // ...
381
+ * }
382
+ * }
383
+ * });
384
+ * ```
385
+ * @param {Function} callback
405
386
  */
406
- clearTree() {
407
- wasm.wasmengine_clearTree(this.__wbg_ptr);
387
+ setRenderCallback(callback) {
388
+ wasm.wasmengine_setRenderCallback(this.__wbg_ptr, callback);
408
389
  }
409
390
  /**
410
- * Debug method to inspect parsed components
411
- * @param {string} source
412
- * @returns {string}
391
+ * Return the total number of nodes currently in the instance tree.
392
+ *
393
+ * Useful for debugging, performance monitoring, and DevTools.
394
+ * @returns {number}
413
395
  */
414
- debugParseComponent(source) {
415
- let deferred3_0;
416
- let deferred3_1;
417
- try {
418
- const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
419
- const len0 = WASM_VECTOR_LEN;
420
- const ret = wasm.wasmengine_debugParseComponent(this.__wbg_ptr, ptr0, len0);
421
- var ptr2 = ret[0];
422
- var len2 = ret[1];
423
- if (ret[3]) {
424
- ptr2 = 0; len2 = 0;
425
- throw takeFromExternrefTable0(ret[2]);
426
- }
427
- deferred3_0 = ptr2;
428
- deferred3_1 = len2;
429
- return getStringFromWasm0(ptr2, len2);
430
- } finally {
431
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
396
+ treeSize() {
397
+ const ret = wasm.wasmengine_treeSize(this.__wbg_ptr);
398
+ return ret >>> 0;
399
+ }
400
+ /**
401
+ * Apply a state patch and re-render affected nodes.
402
+ *
403
+ * The `state_patch` is a JavaScript object whose keys are merged into the
404
+ * current module state (deep merge). Only nodes whose bindings reference
405
+ * changed paths are re-rendered, producing minimal patches.
406
+ *
407
+ * # Example (JS)
408
+ * ```js
409
+ * // Updates state.user.name and state.count, re-renders bound nodes
410
+ * engine.updateState({ user: { name: "Bob" }, count: 42 });
411
+ * ```
412
+ *
413
+ * # Errors
414
+ *
415
+ * Returns an error if `state_patch` cannot be deserialized as JSON.
416
+ * @param {any} state_patch
417
+ */
418
+ updateState(state_patch) {
419
+ const ret = wasm.wasmengine_updateState(this.__wbg_ptr, state_patch);
420
+ if (ret[1]) {
421
+ throw takeFromExternrefTable0(ret[0]);
432
422
  }
433
423
  }
434
424
  /**
435
- * Initialize a module
436
- * @param {string} name
437
- * @param {string[]} actions
438
- * @param {string[]} state_keys
439
- * @param {any} initial_state
425
+ * Apply a sparse state update using explicit path-value pairs.
426
+ *
427
+ * More efficient than [`update_state`] for large state objects when only a
428
+ * few deeply-nested paths changed, because it avoids a full deep-merge.
429
+ *
430
+ * # Arguments
431
+ * * `paths_js` — JS array of dot-separated paths that changed (e.g. `["user.name", "count"]`)
432
+ * * `values_js` — JS object mapping each path to its new value (e.g. `{ "user.name": "Bob", "count": 42 }`)
433
+ *
434
+ * # Errors
435
+ *
436
+ * Returns an error if either argument cannot be deserialized.
437
+ * @param {any} paths_js
438
+ * @param {any} values_js
440
439
  */
441
- setModule(name, actions, state_keys, initial_state) {
442
- const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
443
- const len0 = WASM_VECTOR_LEN;
444
- const ptr1 = passArrayJsValueToWasm0(actions, wasm.__wbindgen_malloc);
445
- const len1 = WASM_VECTOR_LEN;
446
- const ptr2 = passArrayJsValueToWasm0(state_keys, wasm.__wbindgen_malloc);
447
- const len2 = WASM_VECTOR_LEN;
448
- const ret = wasm.wasmengine_setModule(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, initial_state);
440
+ updateStateSparse(paths_js, values_js) {
441
+ const ret = wasm.wasmengine_updateStateSparse(this.__wbg_ptr, paths_js, values_js);
449
442
  if (ret[1]) {
450
443
  throw takeFromExternrefTable0(ret[0]);
451
444
  }
452
445
  }
453
446
  /**
454
- * Get the current revision number
455
- * @returns {bigint}
447
+ * Validate that the engine is in a consistent state.
448
+ *
449
+ * Checks that:
450
+ * - All child references point to existing nodes
451
+ * - All parent back-references are correct
452
+ * - The root node (if any) exists in the tree
453
+ *
454
+ * Returns `null` if valid, or a string describing the first inconsistency found.
455
+ * Intended for testing and debugging only — not for production hot paths.
456
+ * @returns {any}
456
457
  */
457
- getRevision() {
458
- const ret = wasm.wasmengine_getRevision(this.__wbg_ptr);
459
- return BigInt.asUintN(64, ret);
458
+ validate() {
459
+ const ret = wasm.wasmengine_validate(this.__wbg_ptr);
460
+ return ret;
460
461
  }
461
462
  }
462
463
  if (Symbol.dispose) WasmEngine.prototype[Symbol.dispose] = WasmEngine.prototype.free;
463
-
464
464
  exports.WasmEngine = WasmEngine;
465
465
 
466
- exports.__wbg_Error_e17e777aac105295 = function(arg0, arg1) {
467
- const ret = Error(getStringFromWasm0(arg0, arg1));
468
- return ret;
469
- };
470
-
471
- exports.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
472
- const ret = String(arg1);
473
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
474
- const len1 = WASM_VECTOR_LEN;
475
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
476
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
477
- };
478
-
479
- exports.__wbg_call_13410aac570ffff7 = function() { return handleError(function (arg0, arg1) {
480
- const ret = arg0.call(arg1);
481
- return ret;
482
- }, arguments) };
483
-
484
- exports.__wbg_call_641db1bb5db5a579 = function() { return handleError(function (arg0, arg1, arg2, arg3) {
485
- const ret = arg0.call(arg1, arg2, arg3);
486
- return ret;
487
- }, arguments) };
488
-
489
- exports.__wbg_call_a5400b25a865cfd8 = function() { return handleError(function (arg0, arg1, arg2) {
490
- const ret = arg0.call(arg1, arg2);
491
- return ret;
492
- }, arguments) };
493
-
494
- exports.__wbg_done_75ed0ee6dd243d9d = function(arg0) {
495
- const ret = arg0.done;
496
- return ret;
497
- };
498
-
499
- exports.__wbg_entries_2be2f15bd5554996 = function(arg0) {
500
- const ret = Object.entries(arg0);
501
- return ret;
502
- };
503
-
504
- exports.__wbg_error_99981e16d476aa5c = function(arg0) {
505
- console.error(arg0);
506
- };
507
-
508
- exports.__wbg_get_0da715ceaecea5c8 = function(arg0, arg1) {
509
- const ret = arg0[arg1 >>> 0];
510
- return ret;
511
- };
512
-
513
- exports.__wbg_get_458e874b43b18b25 = function() { return handleError(function (arg0, arg1) {
514
- const ret = Reflect.get(arg0, arg1);
515
- return ret;
516
- }, arguments) };
517
-
518
- exports.__wbg_instanceof_ArrayBuffer_67f3012529f6a2dd = function(arg0) {
519
- let result;
520
- try {
521
- result = arg0 instanceof ArrayBuffer;
522
- } catch (_) {
523
- result = false;
524
- }
525
- const ret = result;
526
- return ret;
527
- };
466
+ function main() {
467
+ wasm.main();
468
+ }
469
+ exports.main = main;
528
470
 
529
- exports.__wbg_instanceof_Map_ebb01a5b6b5ffd0b = function(arg0) {
530
- let result;
471
+ /**
472
+ * Parse Hypen DSL source and return the AST as a pretty-printed JSON string.
473
+ *
474
+ * Useful for tooling, syntax highlighting, and debugging the parser output.
475
+ * @param {string} source
476
+ * @returns {string}
477
+ */
478
+ function parseToJson(source) {
479
+ let deferred3_0;
480
+ let deferred3_1;
531
481
  try {
532
- result = arg0 instanceof Map;
533
- } catch (_) {
534
- result = false;
482
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
483
+ const len0 = WASM_VECTOR_LEN;
484
+ const ret = wasm.parseToJson(ptr0, len0);
485
+ var ptr2 = ret[0];
486
+ var len2 = ret[1];
487
+ if (ret[3]) {
488
+ ptr2 = 0; len2 = 0;
489
+ throw takeFromExternrefTable0(ret[2]);
490
+ }
491
+ deferred3_0 = ptr2;
492
+ deferred3_1 = len2;
493
+ return getStringFromWasm0(ptr2, len2);
494
+ } finally {
495
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
535
496
  }
536
- const ret = result;
537
- return ret;
538
- };
497
+ }
498
+ exports.parseToJson = parseToJson;
539
499
 
540
- exports.__wbg_instanceof_Uint8Array_9a8378d955933db7 = function(arg0) {
541
- let result;
500
+ /**
501
+ * Serialize a patches array to a pretty-printed JSON string.
502
+ *
503
+ * Intended for debugging and logging — not for production use.
504
+ * Accepts a JS array of patch objects and returns formatted JSON.
505
+ * @param {any} patches
506
+ * @returns {string}
507
+ */
508
+ function patchesToJson(patches) {
509
+ let deferred2_0;
510
+ let deferred2_1;
542
511
  try {
543
- result = arg0 instanceof Uint8Array;
544
- } catch (_) {
545
- result = false;
512
+ const ret = wasm.patchesToJson(patches);
513
+ var ptr1 = ret[0];
514
+ var len1 = ret[1];
515
+ if (ret[3]) {
516
+ ptr1 = 0; len1 = 0;
517
+ throw takeFromExternrefTable0(ret[2]);
518
+ }
519
+ deferred2_0 = ptr1;
520
+ deferred2_1 = len1;
521
+ return getStringFromWasm0(ptr1, len1);
522
+ } finally {
523
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
546
524
  }
547
- const ret = result;
548
- return ret;
549
- };
550
-
551
- exports.__wbg_isArray_030cce220591fb41 = function(arg0) {
552
- const ret = Array.isArray(arg0);
553
- return ret;
554
- };
555
-
556
- exports.__wbg_isSafeInteger_1c0d1af5542e102a = function(arg0) {
557
- const ret = Number.isSafeInteger(arg0);
558
- return ret;
559
- };
560
-
561
- exports.__wbg_iterator_f370b34483c71a1c = function() {
562
- const ret = Symbol.iterator;
563
- return ret;
564
- };
565
-
566
- exports.__wbg_length_186546c51cd61acd = function(arg0) {
567
- const ret = arg0.length;
568
- return ret;
569
- };
570
-
571
- exports.__wbg_length_6bb7e81f9d7713e4 = function(arg0) {
572
- const ret = arg0.length;
573
- return ret;
574
- };
575
-
576
- exports.__wbg_log_6c7b5f4f00b8ce3f = function(arg0) {
577
- console.log(arg0);
578
- };
579
-
580
- exports.__wbg_new_19c25a3f2fa63a02 = function() {
581
- const ret = new Object();
582
- return ret;
583
- };
584
-
585
- exports.__wbg_new_1f3a344cf3123716 = function() {
586
- const ret = new Array();
587
- return ret;
588
- };
589
-
590
- exports.__wbg_new_2ff1f68f3676ea53 = function() {
591
- const ret = new Map();
592
- return ret;
593
- };
594
-
595
- exports.__wbg_new_638ebfaedbf32a5e = function(arg0) {
596
- const ret = new Uint8Array(arg0);
597
- return ret;
598
- };
599
-
600
- exports.__wbg_next_5b3530e612fde77d = function(arg0) {
601
- const ret = arg0.next;
602
- return ret;
603
- };
604
-
605
- exports.__wbg_next_692e82279131b03c = function() { return handleError(function (arg0) {
606
- const ret = arg0.next();
607
- return ret;
608
- }, arguments) };
609
-
610
- exports.__wbg_prototypesetcall_3d4a26c1ed734349 = function(arg0, arg1, arg2) {
611
- Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
612
- };
613
-
614
- exports.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
615
- arg0[arg1] = arg2;
616
- };
617
-
618
- exports.__wbg_set_90f6c0f7bd8c0415 = function(arg0, arg1, arg2) {
619
- arg0[arg1 >>> 0] = arg2;
620
- };
525
+ }
526
+ exports.patchesToJson = patchesToJson;
527
+
528
+ function __wbg_get_imports() {
529
+ const import0 = {
530
+ __proto__: null,
531
+ __wbg_Error_ecbf49c1b9d07c30: function(arg0, arg1) {
532
+ const ret = Error(getStringFromWasm0(arg0, arg1));
533
+ return ret;
534
+ },
535
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
536
+ const ret = String(arg1);
537
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
538
+ const len1 = WASM_VECTOR_LEN;
539
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
540
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
541
+ },
542
+ __wbg___wbindgen_bigint_get_as_i64_a4925bc53b16f3d6: function(arg0, arg1) {
543
+ const v = arg1;
544
+ const ret = typeof(v) === 'bigint' ? v : undefined;
545
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
546
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
547
+ },
548
+ __wbg___wbindgen_boolean_get_4a348b369b009243: function(arg0) {
549
+ const v = arg0;
550
+ const ret = typeof(v) === 'boolean' ? v : undefined;
551
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
552
+ },
553
+ __wbg___wbindgen_debug_string_43c7ccb034739216: function(arg0, arg1) {
554
+ const ret = debugString(arg1);
555
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
556
+ const len1 = WASM_VECTOR_LEN;
557
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
558
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
559
+ },
560
+ __wbg___wbindgen_in_035107858ad0083e: function(arg0, arg1) {
561
+ const ret = arg0 in arg1;
562
+ return ret;
563
+ },
564
+ __wbg___wbindgen_is_bigint_15e2d080220c7748: function(arg0) {
565
+ const ret = typeof(arg0) === 'bigint';
566
+ return ret;
567
+ },
568
+ __wbg___wbindgen_is_function_18bea6e84080c016: function(arg0) {
569
+ const ret = typeof(arg0) === 'function';
570
+ return ret;
571
+ },
572
+ __wbg___wbindgen_is_null_c5f5bb76436a9ab1: function(arg0) {
573
+ const ret = arg0 === null;
574
+ return ret;
575
+ },
576
+ __wbg___wbindgen_is_object_8d3fac158b36498d: function(arg0) {
577
+ const val = arg0;
578
+ const ret = typeof(val) === 'object' && val !== null;
579
+ return ret;
580
+ },
581
+ __wbg___wbindgen_is_string_4d5f2c5b2acf65b0: function(arg0) {
582
+ const ret = typeof(arg0) === 'string';
583
+ return ret;
584
+ },
585
+ __wbg___wbindgen_is_undefined_4a711ea9d2e1ef93: function(arg0) {
586
+ const ret = arg0 === undefined;
587
+ return ret;
588
+ },
589
+ __wbg___wbindgen_jsval_eq_65f99081d9ee8f4d: function(arg0, arg1) {
590
+ const ret = arg0 === arg1;
591
+ return ret;
592
+ },
593
+ __wbg___wbindgen_jsval_loose_eq_1a2067dfb025b5ec: function(arg0, arg1) {
594
+ const ret = arg0 == arg1;
595
+ return ret;
596
+ },
597
+ __wbg___wbindgen_number_get_eed4462ef92e1bed: function(arg0, arg1) {
598
+ const obj = arg1;
599
+ const ret = typeof(obj) === 'number' ? obj : undefined;
600
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
601
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
602
+ },
603
+ __wbg___wbindgen_string_get_d09f733449cbf7a2: function(arg0, arg1) {
604
+ const obj = arg1;
605
+ const ret = typeof(obj) === 'string' ? obj : undefined;
606
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
607
+ var len1 = WASM_VECTOR_LEN;
608
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
609
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
610
+ },
611
+ __wbg___wbindgen_throw_df03e93053e0f4bc: function(arg0, arg1) {
612
+ throw new Error(getStringFromWasm0(arg0, arg1));
613
+ },
614
+ __wbg_call_2989817bf2a245b5: function() { return handleError(function (arg0, arg1, arg2, arg3) {
615
+ const ret = arg0.call(arg1, arg2, arg3);
616
+ return ret;
617
+ }, arguments); },
618
+ __wbg_call_85e5437fa1ab109d: function() { return handleError(function (arg0, arg1, arg2) {
619
+ const ret = arg0.call(arg1, arg2);
620
+ return ret;
621
+ }, arguments); },
622
+ __wbg_call_df7a43aecab856a8: function() { return handleError(function (arg0, arg1) {
623
+ const ret = arg0.call(arg1);
624
+ return ret;
625
+ }, arguments); },
626
+ __wbg_done_0ad70482cae88a68: function(arg0) {
627
+ const ret = arg0.done;
628
+ return ret;
629
+ },
630
+ __wbg_entries_d58050057c0390ac: function(arg0) {
631
+ const ret = Object.entries(arg0);
632
+ return ret;
633
+ },
634
+ __wbg_error_51679600615c775d: function(arg0) {
635
+ console.error(arg0);
636
+ },
637
+ __wbg_get_6f5cf69c8f3f094a: function() { return handleError(function (arg0, arg1) {
638
+ const ret = Reflect.get(arg0, arg1);
639
+ return ret;
640
+ }, arguments); },
641
+ __wbg_get_c40e2c3262995a8e: function(arg0, arg1) {
642
+ const ret = arg0[arg1 >>> 0];
643
+ return ret;
644
+ },
645
+ __wbg_get_d0e1306db90b68d9: function() { return handleError(function (arg0, arg1) {
646
+ const ret = Reflect.get(arg0, arg1);
647
+ return ret;
648
+ }, arguments); },
649
+ __wbg_get_unchecked_3de5bfaaea65f86b: function(arg0, arg1) {
650
+ const ret = arg0[arg1 >>> 0];
651
+ return ret;
652
+ },
653
+ __wbg_instanceof_ArrayBuffer_d8e4e51f1cf7287a: function(arg0) {
654
+ let result;
655
+ try {
656
+ result = arg0 instanceof ArrayBuffer;
657
+ } catch (_) {
658
+ result = false;
659
+ }
660
+ const ret = result;
661
+ return ret;
662
+ },
663
+ __wbg_instanceof_Map_53b6790994271123: function(arg0) {
664
+ let result;
665
+ try {
666
+ result = arg0 instanceof Map;
667
+ } catch (_) {
668
+ result = false;
669
+ }
670
+ const ret = result;
671
+ return ret;
672
+ },
673
+ __wbg_instanceof_Uint8Array_6e48d83da6091cc8: function(arg0) {
674
+ let result;
675
+ try {
676
+ result = arg0 instanceof Uint8Array;
677
+ } catch (_) {
678
+ result = false;
679
+ }
680
+ const ret = result;
681
+ return ret;
682
+ },
683
+ __wbg_isArray_2efa5973cef6ec32: function(arg0) {
684
+ const ret = Array.isArray(arg0);
685
+ return ret;
686
+ },
687
+ __wbg_isSafeInteger_6709fb28be12d738: function(arg0) {
688
+ const ret = Number.isSafeInteger(arg0);
689
+ return ret;
690
+ },
691
+ __wbg_iterator_e77d2b7575cca5a7: function() {
692
+ const ret = Symbol.iterator;
693
+ return ret;
694
+ },
695
+ __wbg_length_00dd7227fd4626ad: function(arg0) {
696
+ const ret = arg0.length;
697
+ return ret;
698
+ },
699
+ __wbg_length_5e07cf181b2745fb: function(arg0) {
700
+ const ret = arg0.length;
701
+ return ret;
702
+ },
703
+ __wbg_log_91f1dd1dfd5a4ae8: function(arg0) {
704
+ console.log(arg0);
705
+ },
706
+ __wbg_new_62f131e968c83d75: function() {
707
+ const ret = new Object();
708
+ return ret;
709
+ },
710
+ __wbg_new_66075f8c2ea6575e: function() {
711
+ const ret = new Array();
712
+ return ret;
713
+ },
714
+ __wbg_new_74eb411a4d7bd3f1: function() {
715
+ const ret = new Map();
716
+ return ret;
717
+ },
718
+ __wbg_new_a0479da6258a0d71: function(arg0) {
719
+ const ret = new Uint8Array(arg0);
720
+ return ret;
721
+ },
722
+ __wbg_next_5428439dfc1d0362: function() { return handleError(function (arg0) {
723
+ const ret = arg0.next();
724
+ return ret;
725
+ }, arguments); },
726
+ __wbg_next_d314789a105729f3: function(arg0) {
727
+ const ret = arg0.next;
728
+ return ret;
729
+ },
730
+ __wbg_prototypesetcall_d1a7133bc8d83aa9: function(arg0, arg1, arg2) {
731
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
732
+ },
733
+ __wbg_set_3ba5af57f57f831c: function(arg0, arg1, arg2) {
734
+ const ret = arg0.set(arg1, arg2);
735
+ return ret;
736
+ },
737
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
738
+ arg0[arg1] = arg2;
739
+ },
740
+ __wbg_set_7bf9e2df46e7632c: function(arg0, arg1, arg2) {
741
+ arg0[arg1 >>> 0] = arg2;
742
+ },
743
+ __wbg_set_8326741805409e83: function() { return handleError(function (arg0, arg1, arg2) {
744
+ const ret = Reflect.set(arg0, arg1, arg2);
745
+ return ret;
746
+ }, arguments); },
747
+ __wbg_value_414b42ce7b3eca22: function(arg0) {
748
+ const ret = arg0.value;
749
+ return ret;
750
+ },
751
+ __wbindgen_cast_0000000000000001: function(arg0) {
752
+ // Cast intrinsic for `F64 -> Externref`.
753
+ const ret = arg0;
754
+ return ret;
755
+ },
756
+ __wbindgen_cast_0000000000000002: function(arg0) {
757
+ // Cast intrinsic for `I64 -> Externref`.
758
+ const ret = arg0;
759
+ return ret;
760
+ },
761
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
762
+ // Cast intrinsic for `Ref(String) -> Externref`.
763
+ const ret = getStringFromWasm0(arg0, arg1);
764
+ return ret;
765
+ },
766
+ __wbindgen_cast_0000000000000004: function(arg0) {
767
+ // Cast intrinsic for `U64 -> Externref`.
768
+ const ret = BigInt.asUintN(64, arg0);
769
+ return ret;
770
+ },
771
+ __wbindgen_init_externref_table: function() {
772
+ const table = wasm.__wbindgen_externrefs;
773
+ const offset = table.grow(4);
774
+ table.set(0, undefined);
775
+ table.set(offset + 0, undefined);
776
+ table.set(offset + 1, null);
777
+ table.set(offset + 2, true);
778
+ table.set(offset + 3, false);
779
+ },
780
+ };
781
+ return {
782
+ __proto__: null,
783
+ "./hypen_engine_bg.js": import0,
784
+ };
785
+ }
621
786
 
622
- exports.__wbg_set_b7f1cf4fae26fe2a = function(arg0, arg1, arg2) {
623
- const ret = arg0.set(arg1, arg2);
624
- return ret;
625
- };
787
+ const WasmEngineFinalization = (typeof FinalizationRegistry === 'undefined')
788
+ ? { register: () => {}, unregister: () => {} }
789
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmengine_free(ptr >>> 0, 1));
626
790
 
627
- exports.__wbg_value_dd9372230531eade = function(arg0) {
628
- const ret = arg0.value;
629
- return ret;
630
- };
791
+ function addToExternrefTable0(obj) {
792
+ const idx = wasm.__externref_table_alloc();
793
+ wasm.__wbindgen_externrefs.set(idx, obj);
794
+ return idx;
795
+ }
631
796
 
632
- exports.__wbg_wbindgenbigintgetasi64_ac743ece6ab9bba1 = function(arg0, arg1) {
633
- const v = arg1;
634
- const ret = typeof(v) === 'bigint' ? v : undefined;
635
- getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
636
- getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
637
- };
797
+ function debugString(val) {
798
+ // primitive types
799
+ const type = typeof val;
800
+ if (type == 'number' || type == 'boolean' || val == null) {
801
+ return `${val}`;
802
+ }
803
+ if (type == 'string') {
804
+ return `"${val}"`;
805
+ }
806
+ if (type == 'symbol') {
807
+ const description = val.description;
808
+ if (description == null) {
809
+ return 'Symbol';
810
+ } else {
811
+ return `Symbol(${description})`;
812
+ }
813
+ }
814
+ if (type == 'function') {
815
+ const name = val.name;
816
+ if (typeof name == 'string' && name.length > 0) {
817
+ return `Function(${name})`;
818
+ } else {
819
+ return 'Function';
820
+ }
821
+ }
822
+ // objects
823
+ if (Array.isArray(val)) {
824
+ const length = val.length;
825
+ let debug = '[';
826
+ if (length > 0) {
827
+ debug += debugString(val[0]);
828
+ }
829
+ for(let i = 1; i < length; i++) {
830
+ debug += ', ' + debugString(val[i]);
831
+ }
832
+ debug += ']';
833
+ return debug;
834
+ }
835
+ // Test for built-in
836
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
837
+ let className;
838
+ if (builtInMatches && builtInMatches.length > 1) {
839
+ className = builtInMatches[1];
840
+ } else {
841
+ // Failed to match the standard '[object ClassName]'
842
+ return toString.call(val);
843
+ }
844
+ if (className == 'Object') {
845
+ // we're a user defined class or Object
846
+ // JSON.stringify avoids problems with cycles, and is generally much
847
+ // easier than looping through ownProperties of `val`.
848
+ try {
849
+ return 'Object(' + JSON.stringify(val) + ')';
850
+ } catch (_) {
851
+ return 'Object';
852
+ }
853
+ }
854
+ // errors
855
+ if (val instanceof Error) {
856
+ return `${val.name}: ${val.message}\n${val.stack}`;
857
+ }
858
+ // TODO we could test for more things here, like `Set`s and `Map`s.
859
+ return className;
860
+ }
638
861
 
639
- exports.__wbg_wbindgenbooleanget_3fe6f642c7d97746 = function(arg0) {
640
- const v = arg0;
641
- const ret = typeof(v) === 'boolean' ? v : undefined;
642
- return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
643
- };
862
+ function getArrayU8FromWasm0(ptr, len) {
863
+ ptr = ptr >>> 0;
864
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
865
+ }
644
866
 
645
- exports.__wbg_wbindgendebugstring_99ef257a3ddda34d = function(arg0, arg1) {
646
- const ret = debugString(arg1);
647
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
648
- const len1 = WASM_VECTOR_LEN;
649
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
650
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
651
- };
867
+ let cachedDataViewMemory0 = null;
868
+ function getDataViewMemory0() {
869
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
870
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
871
+ }
872
+ return cachedDataViewMemory0;
873
+ }
652
874
 
653
- exports.__wbg_wbindgenin_d7a1ee10933d2d55 = function(arg0, arg1) {
654
- const ret = arg0 in arg1;
655
- return ret;
656
- };
875
+ function getStringFromWasm0(ptr, len) {
876
+ ptr = ptr >>> 0;
877
+ return decodeText(ptr, len);
878
+ }
657
879
 
658
- exports.__wbg_wbindgenisbigint_ecb90cc08a5a9154 = function(arg0) {
659
- const ret = typeof(arg0) === 'bigint';
660
- return ret;
661
- };
880
+ let cachedUint8ArrayMemory0 = null;
881
+ function getUint8ArrayMemory0() {
882
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
883
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
884
+ }
885
+ return cachedUint8ArrayMemory0;
886
+ }
662
887
 
663
- exports.__wbg_wbindgenisfunction_8cee7dce3725ae74 = function(arg0) {
664
- const ret = typeof(arg0) === 'function';
665
- return ret;
666
- };
888
+ function handleError(f, args) {
889
+ try {
890
+ return f.apply(this, args);
891
+ } catch (e) {
892
+ const idx = addToExternrefTable0(e);
893
+ wasm.__wbindgen_exn_store(idx);
894
+ }
895
+ }
667
896
 
668
- exports.__wbg_wbindgenisnull_f3037694abe4d97a = function(arg0) {
669
- const ret = arg0 === null;
670
- return ret;
671
- };
897
+ function isLikeNone(x) {
898
+ return x === undefined || x === null;
899
+ }
672
900
 
673
- exports.__wbg_wbindgenisobject_307a53c6bd97fbf8 = function(arg0) {
674
- const val = arg0;
675
- const ret = typeof(val) === 'object' && val !== null;
676
- return ret;
677
- };
901
+ function passArrayJsValueToWasm0(array, malloc) {
902
+ const ptr = malloc(array.length * 4, 4) >>> 0;
903
+ for (let i = 0; i < array.length; i++) {
904
+ const add = addToExternrefTable0(array[i]);
905
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
906
+ }
907
+ WASM_VECTOR_LEN = array.length;
908
+ return ptr;
909
+ }
678
910
 
679
- exports.__wbg_wbindgenisstring_d4fa939789f003b0 = function(arg0) {
680
- const ret = typeof(arg0) === 'string';
681
- return ret;
682
- };
911
+ function passStringToWasm0(arg, malloc, realloc) {
912
+ if (realloc === undefined) {
913
+ const buf = cachedTextEncoder.encode(arg);
914
+ const ptr = malloc(buf.length, 1) >>> 0;
915
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
916
+ WASM_VECTOR_LEN = buf.length;
917
+ return ptr;
918
+ }
683
919
 
684
- exports.__wbg_wbindgenisundefined_c4b71d073b92f3c5 = function(arg0) {
685
- const ret = arg0 === undefined;
686
- return ret;
687
- };
920
+ let len = arg.length;
921
+ let ptr = malloc(len, 1) >>> 0;
688
922
 
689
- exports.__wbg_wbindgenjsvaleq_e6f2ad59ccae1b58 = function(arg0, arg1) {
690
- const ret = arg0 === arg1;
691
- return ret;
692
- };
923
+ const mem = getUint8ArrayMemory0();
693
924
 
694
- exports.__wbg_wbindgenjsvallooseeq_9bec8c9be826bed1 = function(arg0, arg1) {
695
- const ret = arg0 == arg1;
696
- return ret;
697
- };
925
+ let offset = 0;
698
926
 
699
- exports.__wbg_wbindgennumberget_f74b4c7525ac05cb = function(arg0, arg1) {
700
- const obj = arg1;
701
- const ret = typeof(obj) === 'number' ? obj : undefined;
702
- getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
703
- getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
704
- };
927
+ for (; offset < len; offset++) {
928
+ const code = arg.charCodeAt(offset);
929
+ if (code > 0x7F) break;
930
+ mem[ptr + offset] = code;
931
+ }
932
+ if (offset !== len) {
933
+ if (offset !== 0) {
934
+ arg = arg.slice(offset);
935
+ }
936
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
937
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
938
+ const ret = cachedTextEncoder.encodeInto(arg, view);
705
939
 
706
- exports.__wbg_wbindgenstringget_0f16a6ddddef376f = function(arg0, arg1) {
707
- const obj = arg1;
708
- const ret = typeof(obj) === 'string' ? obj : undefined;
709
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
710
- var len1 = WASM_VECTOR_LEN;
711
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
712
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
713
- };
940
+ offset += ret.written;
941
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
942
+ }
714
943
 
715
- exports.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function(arg0, arg1) {
716
- throw new Error(getStringFromWasm0(arg0, arg1));
717
- };
944
+ WASM_VECTOR_LEN = offset;
945
+ return ptr;
946
+ }
718
947
 
719
- exports.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
720
- // Cast intrinsic for `Ref(String) -> Externref`.
721
- const ret = getStringFromWasm0(arg0, arg1);
722
- return ret;
723
- };
948
+ function takeFromExternrefTable0(idx) {
949
+ const value = wasm.__wbindgen_externrefs.get(idx);
950
+ wasm.__externref_table_dealloc(idx);
951
+ return value;
952
+ }
724
953
 
725
- exports.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
726
- // Cast intrinsic for `U64 -> Externref`.
727
- const ret = BigInt.asUintN(64, arg0);
728
- return ret;
729
- };
954
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
955
+ cachedTextDecoder.decode();
956
+ function decodeText(ptr, len) {
957
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
958
+ }
730
959
 
731
- exports.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
732
- // Cast intrinsic for `I64 -> Externref`.
733
- const ret = arg0;
734
- return ret;
735
- };
960
+ const cachedTextEncoder = new TextEncoder();
736
961
 
737
- exports.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
738
- // Cast intrinsic for `F64 -> Externref`.
739
- const ret = arg0;
740
- return ret;
741
- };
962
+ if (!('encodeInto' in cachedTextEncoder)) {
963
+ cachedTextEncoder.encodeInto = function (arg, view) {
964
+ const buf = cachedTextEncoder.encode(arg);
965
+ view.set(buf);
966
+ return {
967
+ read: arg.length,
968
+ written: buf.length
969
+ };
970
+ };
971
+ }
742
972
 
743
- exports.__wbindgen_init_externref_table = function() {
744
- const table = wasm.__wbindgen_export_4;
745
- const offset = table.grow(4);
746
- table.set(0, undefined);
747
- table.set(offset + 0, undefined);
748
- table.set(offset + 1, null);
749
- table.set(offset + 2, true);
750
- table.set(offset + 3, false);
751
- ;
752
- };
973
+ let WASM_VECTOR_LEN = 0;
753
974
 
754
975
  const wasmPath = `${__dirname}/hypen_engine_bg.wasm`;
755
976
  const wasmBytes = require('fs').readFileSync(wasmPath);
756
977
  const wasmModule = new WebAssembly.Module(wasmBytes);
757
- const wasm = exports.__wasm = new WebAssembly.Instance(wasmModule, imports).exports;
758
-
978
+ let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
759
979
  wasm.__wbindgen_start();
760
-