@keroway/tdsl-wasm 1.11.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/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@keroway/tdsl-wasm",
3
+ "type": "module",
4
+ "description": "WebAssembly bindings for the Timeline DSL compiler (static compile + SVG/HTML render)",
5
+ "version": "1.11.0",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/keroway/timeline-dsl"
10
+ },
11
+ "files": [
12
+ "tdsl_wasm_bg.wasm",
13
+ "tdsl_wasm.js",
14
+ "tdsl_wasm.d.ts"
15
+ ],
16
+ "main": "tdsl_wasm.js",
17
+ "homepage": "https://github.com/keroway/timeline-dsl",
18
+ "types": "tdsl_wasm.d.ts",
19
+ "sideEffects": [
20
+ "./snippets/*"
21
+ ],
22
+ "keywords": [
23
+ "timeline",
24
+ "wasm",
25
+ "dsl",
26
+ "svg",
27
+ "visualization"
28
+ ]
29
+ }
package/tdsl_wasm.d.ts ADDED
@@ -0,0 +1,92 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Check TDSL source and return diagnostics as JSON.
6
+ *
7
+ * Returns a JSON array of diagnostic objects: `[{severity, message, line, col}]`.
8
+ * `severity` is `"error"` or `"warning"`. `line`/`col` are 0-indexed.
9
+ *
10
+ * **Note on `import` blocks**: `import wikidata` blocks are not resolved in the browser
11
+ * (no network access). Unresolved imports are **silently skipped** — they produce no
12
+ * diagnostics, but the resulting IR / SVG will omit those items. Use static `span`,
13
+ * `event`, and `event_range` statements for content that must render in the browser.
14
+ */
15
+ export function check_source(source: string): string;
16
+
17
+ /**
18
+ * Compile TDSL source to IR (JSON string), without Wikidata resolution.
19
+ * `source_span` fields are populated for each static item (for bidirectional jump).
20
+ * Returns Ok(json_string) or Err(error_message).
21
+ */
22
+ export function compile_to_ir(source: string): string;
23
+
24
+ /**
25
+ * Format TDSL source by re-emitting from the AST.
26
+ *
27
+ * Parses `source` and re-emits a normalized form (2-space indent, single blank line
28
+ * between top-level statements). Comments in the original source are **not preserved**
29
+ * because they are skipped at the PEG layer.
30
+ * Returns Ok(formatted_source) on success, Err(parse_error_message) on parse failure.
31
+ */
32
+ export function format_source(source: string): string;
33
+
34
+ /**
35
+ * Initialize the panic hook for better error messages in the browser console.
36
+ */
37
+ export function main(): void;
38
+
39
+ /**
40
+ * Render standalone HTML from TDSL source (static items only).
41
+ * Returns Ok(html_string) or Err(error_message).
42
+ */
43
+ export function render_html_from_source(source: string): string;
44
+
45
+ /**
46
+ * Render SVG from TDSL source (static items only).
47
+ * `scale` controls pixels-per-year. Pass `0.0` (or negative) to auto-calculate
48
+ * from the IR's `meta.range` (clamped to `0.5..=50.0`).
49
+ * `source_span` (line numbers) are embedded as `data-line` attributes in the SVG
50
+ * for bidirectional editor↔preview jump.
51
+ * Returns Ok(svg_string) or Err(error_message).
52
+ */
53
+ export function render_svg_from_source(source: string, scale: number): string;
54
+
55
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
56
+
57
+ export interface InitOutput {
58
+ readonly memory: WebAssembly.Memory;
59
+ readonly check_source: (a: number, b: number, c: number) => void;
60
+ readonly compile_to_ir: (a: number, b: number, c: number) => void;
61
+ readonly format_source: (a: number, b: number, c: number) => void;
62
+ readonly render_html_from_source: (a: number, b: number, c: number) => void;
63
+ readonly render_svg_from_source: (a: number, b: number, c: number, d: number) => void;
64
+ readonly main: () => void;
65
+ readonly __wbindgen_export: (a: number, b: number, c: number) => void;
66
+ readonly __wbindgen_export2: (a: number, b: number) => number;
67
+ readonly __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
68
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
69
+ readonly __wbindgen_start: () => void;
70
+ }
71
+
72
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
73
+
74
+ /**
75
+ * Instantiates the given `module`, which can either be bytes or
76
+ * a precompiled `WebAssembly.Module`.
77
+ *
78
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
79
+ *
80
+ * @returns {InitOutput}
81
+ */
82
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
83
+
84
+ /**
85
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
86
+ * for everything else, calls `WebAssembly.instantiate` directly.
87
+ *
88
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
89
+ *
90
+ * @returns {Promise<InitOutput>}
91
+ */
92
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/tdsl_wasm.js ADDED
@@ -0,0 +1,429 @@
1
+ /* @ts-self-types="./tdsl_wasm.d.ts" */
2
+
3
+ /**
4
+ * Check TDSL source and return diagnostics as JSON.
5
+ *
6
+ * Returns a JSON array of diagnostic objects: `[{severity, message, line, col}]`.
7
+ * `severity` is `"error"` or `"warning"`. `line`/`col` are 0-indexed.
8
+ *
9
+ * **Note on `import` blocks**: `import wikidata` blocks are not resolved in the browser
10
+ * (no network access). Unresolved imports are **silently skipped** — they produce no
11
+ * diagnostics, but the resulting IR / SVG will omit those items. Use static `span`,
12
+ * `event`, and `event_range` statements for content that must render in the browser.
13
+ * @param {string} source
14
+ * @returns {string}
15
+ */
16
+ export function check_source(source) {
17
+ let deferred2_0;
18
+ let deferred2_1;
19
+ try {
20
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
21
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
22
+ const len0 = WASM_VECTOR_LEN;
23
+ wasm.check_source(retptr, ptr0, len0);
24
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
25
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
26
+ deferred2_0 = r0;
27
+ deferred2_1 = r1;
28
+ return getStringFromWasm0(r0, r1);
29
+ } finally {
30
+ wasm.__wbindgen_add_to_stack_pointer(16);
31
+ wasm.__wbindgen_export(deferred2_0, deferred2_1, 1);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Compile TDSL source to IR (JSON string), without Wikidata resolution.
37
+ * `source_span` fields are populated for each static item (for bidirectional jump).
38
+ * Returns Ok(json_string) or Err(error_message).
39
+ * @param {string} source
40
+ * @returns {string}
41
+ */
42
+ export function compile_to_ir(source) {
43
+ let deferred3_0;
44
+ let deferred3_1;
45
+ try {
46
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
47
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
48
+ const len0 = WASM_VECTOR_LEN;
49
+ wasm.compile_to_ir(retptr, ptr0, len0);
50
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
51
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
52
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
53
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
54
+ var ptr2 = r0;
55
+ var len2 = r1;
56
+ if (r3) {
57
+ ptr2 = 0; len2 = 0;
58
+ throw takeObject(r2);
59
+ }
60
+ deferred3_0 = ptr2;
61
+ deferred3_1 = len2;
62
+ return getStringFromWasm0(ptr2, len2);
63
+ } finally {
64
+ wasm.__wbindgen_add_to_stack_pointer(16);
65
+ wasm.__wbindgen_export(deferred3_0, deferred3_1, 1);
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Format TDSL source by re-emitting from the AST.
71
+ *
72
+ * Parses `source` and re-emits a normalized form (2-space indent, single blank line
73
+ * between top-level statements). Comments in the original source are **not preserved**
74
+ * because they are skipped at the PEG layer.
75
+ * Returns Ok(formatted_source) on success, Err(parse_error_message) on parse failure.
76
+ * @param {string} source
77
+ * @returns {string}
78
+ */
79
+ export function format_source(source) {
80
+ let deferred3_0;
81
+ let deferred3_1;
82
+ try {
83
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
84
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
85
+ const len0 = WASM_VECTOR_LEN;
86
+ wasm.format_source(retptr, ptr0, len0);
87
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
88
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
89
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
90
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
91
+ var ptr2 = r0;
92
+ var len2 = r1;
93
+ if (r3) {
94
+ ptr2 = 0; len2 = 0;
95
+ throw takeObject(r2);
96
+ }
97
+ deferred3_0 = ptr2;
98
+ deferred3_1 = len2;
99
+ return getStringFromWasm0(ptr2, len2);
100
+ } finally {
101
+ wasm.__wbindgen_add_to_stack_pointer(16);
102
+ wasm.__wbindgen_export(deferred3_0, deferred3_1, 1);
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Initialize the panic hook for better error messages in the browser console.
108
+ */
109
+ export function main() {
110
+ wasm.main();
111
+ }
112
+
113
+ /**
114
+ * Render standalone HTML from TDSL source (static items only).
115
+ * Returns Ok(html_string) or Err(error_message).
116
+ * @param {string} source
117
+ * @returns {string}
118
+ */
119
+ export function render_html_from_source(source) {
120
+ let deferred3_0;
121
+ let deferred3_1;
122
+ try {
123
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
124
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
125
+ const len0 = WASM_VECTOR_LEN;
126
+ wasm.render_html_from_source(retptr, ptr0, len0);
127
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
128
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
129
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
130
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
131
+ var ptr2 = r0;
132
+ var len2 = r1;
133
+ if (r3) {
134
+ ptr2 = 0; len2 = 0;
135
+ throw takeObject(r2);
136
+ }
137
+ deferred3_0 = ptr2;
138
+ deferred3_1 = len2;
139
+ return getStringFromWasm0(ptr2, len2);
140
+ } finally {
141
+ wasm.__wbindgen_add_to_stack_pointer(16);
142
+ wasm.__wbindgen_export(deferred3_0, deferred3_1, 1);
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Render SVG from TDSL source (static items only).
148
+ * `scale` controls pixels-per-year. Pass `0.0` (or negative) to auto-calculate
149
+ * from the IR's `meta.range` (clamped to `0.5..=50.0`).
150
+ * `source_span` (line numbers) are embedded as `data-line` attributes in the SVG
151
+ * for bidirectional editor↔preview jump.
152
+ * Returns Ok(svg_string) or Err(error_message).
153
+ * @param {string} source
154
+ * @param {number} scale
155
+ * @returns {string}
156
+ */
157
+ export function render_svg_from_source(source, scale) {
158
+ let deferred3_0;
159
+ let deferred3_1;
160
+ try {
161
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
162
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
163
+ const len0 = WASM_VECTOR_LEN;
164
+ wasm.render_svg_from_source(retptr, ptr0, len0, scale);
165
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
166
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
167
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
168
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
169
+ var ptr2 = r0;
170
+ var len2 = r1;
171
+ if (r3) {
172
+ ptr2 = 0; len2 = 0;
173
+ throw takeObject(r2);
174
+ }
175
+ deferred3_0 = ptr2;
176
+ deferred3_1 = len2;
177
+ return getStringFromWasm0(ptr2, len2);
178
+ } finally {
179
+ wasm.__wbindgen_add_to_stack_pointer(16);
180
+ wasm.__wbindgen_export(deferred3_0, deferred3_1, 1);
181
+ }
182
+ }
183
+ function __wbg_get_imports() {
184
+ const import0 = {
185
+ __proto__: null,
186
+ __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
187
+ let deferred0_0;
188
+ let deferred0_1;
189
+ try {
190
+ deferred0_0 = arg0;
191
+ deferred0_1 = arg1;
192
+ console.error(getStringFromWasm0(arg0, arg1));
193
+ } finally {
194
+ wasm.__wbindgen_export(deferred0_0, deferred0_1, 1);
195
+ }
196
+ },
197
+ __wbg_new_227d7c05414eb861: function() {
198
+ const ret = new Error();
199
+ return addHeapObject(ret);
200
+ },
201
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
202
+ const ret = getObject(arg1).stack;
203
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
204
+ const len1 = WASM_VECTOR_LEN;
205
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
206
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
207
+ },
208
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
209
+ // Cast intrinsic for `Ref(String) -> Externref`.
210
+ const ret = getStringFromWasm0(arg0, arg1);
211
+ return addHeapObject(ret);
212
+ },
213
+ __wbindgen_object_drop_ref: function(arg0) {
214
+ takeObject(arg0);
215
+ },
216
+ };
217
+ return {
218
+ __proto__: null,
219
+ "./tdsl_wasm_bg.js": import0,
220
+ };
221
+ }
222
+
223
+ function addHeapObject(obj) {
224
+ if (heap_next === heap.length) heap.push(heap.length + 1);
225
+ const idx = heap_next;
226
+ heap_next = heap[idx];
227
+
228
+ heap[idx] = obj;
229
+ return idx;
230
+ }
231
+
232
+ function dropObject(idx) {
233
+ if (idx < 1028) return;
234
+ heap[idx] = heap_next;
235
+ heap_next = idx;
236
+ }
237
+
238
+ let cachedDataViewMemory0 = null;
239
+ function getDataViewMemory0() {
240
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
241
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
242
+ }
243
+ return cachedDataViewMemory0;
244
+ }
245
+
246
+ function getStringFromWasm0(ptr, len) {
247
+ ptr = ptr >>> 0;
248
+ return decodeText(ptr, len);
249
+ }
250
+
251
+ let cachedUint8ArrayMemory0 = null;
252
+ function getUint8ArrayMemory0() {
253
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
254
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
255
+ }
256
+ return cachedUint8ArrayMemory0;
257
+ }
258
+
259
+ function getObject(idx) { return heap[idx]; }
260
+
261
+ let heap = new Array(1024).fill(undefined);
262
+ heap.push(undefined, null, true, false);
263
+
264
+ let heap_next = heap.length;
265
+
266
+ function passStringToWasm0(arg, malloc, realloc) {
267
+ if (realloc === undefined) {
268
+ const buf = cachedTextEncoder.encode(arg);
269
+ const ptr = malloc(buf.length, 1) >>> 0;
270
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
271
+ WASM_VECTOR_LEN = buf.length;
272
+ return ptr;
273
+ }
274
+
275
+ let len = arg.length;
276
+ let ptr = malloc(len, 1) >>> 0;
277
+
278
+ const mem = getUint8ArrayMemory0();
279
+
280
+ let offset = 0;
281
+
282
+ for (; offset < len; offset++) {
283
+ const code = arg.charCodeAt(offset);
284
+ if (code > 0x7F) break;
285
+ mem[ptr + offset] = code;
286
+ }
287
+ if (offset !== len) {
288
+ if (offset !== 0) {
289
+ arg = arg.slice(offset);
290
+ }
291
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
292
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
293
+ const ret = cachedTextEncoder.encodeInto(arg, view);
294
+
295
+ offset += ret.written;
296
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
297
+ }
298
+
299
+ WASM_VECTOR_LEN = offset;
300
+ return ptr;
301
+ }
302
+
303
+ function takeObject(idx) {
304
+ const ret = getObject(idx);
305
+ dropObject(idx);
306
+ return ret;
307
+ }
308
+
309
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
310
+ cachedTextDecoder.decode();
311
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
312
+ let numBytesDecoded = 0;
313
+ function decodeText(ptr, len) {
314
+ numBytesDecoded += len;
315
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
316
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
317
+ cachedTextDecoder.decode();
318
+ numBytesDecoded = len;
319
+ }
320
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
321
+ }
322
+
323
+ const cachedTextEncoder = new TextEncoder();
324
+
325
+ if (!('encodeInto' in cachedTextEncoder)) {
326
+ cachedTextEncoder.encodeInto = function (arg, view) {
327
+ const buf = cachedTextEncoder.encode(arg);
328
+ view.set(buf);
329
+ return {
330
+ read: arg.length,
331
+ written: buf.length
332
+ };
333
+ };
334
+ }
335
+
336
+ let WASM_VECTOR_LEN = 0;
337
+
338
+ let wasmModule, wasm;
339
+ function __wbg_finalize_init(instance, module) {
340
+ wasm = instance.exports;
341
+ wasmModule = module;
342
+ cachedDataViewMemory0 = null;
343
+ cachedUint8ArrayMemory0 = null;
344
+ wasm.__wbindgen_start();
345
+ return wasm;
346
+ }
347
+
348
+ async function __wbg_load(module, imports) {
349
+ if (typeof Response === 'function' && module instanceof Response) {
350
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
351
+ try {
352
+ return await WebAssembly.instantiateStreaming(module, imports);
353
+ } catch (e) {
354
+ const validResponse = module.ok && expectedResponseType(module.type);
355
+
356
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
357
+ 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);
358
+
359
+ } else { throw e; }
360
+ }
361
+ }
362
+
363
+ const bytes = await module.arrayBuffer();
364
+ return await WebAssembly.instantiate(bytes, imports);
365
+ } else {
366
+ const instance = await WebAssembly.instantiate(module, imports);
367
+
368
+ if (instance instanceof WebAssembly.Instance) {
369
+ return { instance, module };
370
+ } else {
371
+ return instance;
372
+ }
373
+ }
374
+
375
+ function expectedResponseType(type) {
376
+ switch (type) {
377
+ case 'basic': case 'cors': case 'default': return true;
378
+ }
379
+ return false;
380
+ }
381
+ }
382
+
383
+ function initSync(module) {
384
+ if (wasm !== undefined) return wasm;
385
+
386
+
387
+ if (module !== undefined) {
388
+ if (Object.getPrototypeOf(module) === Object.prototype) {
389
+ ({module} = module)
390
+ } else {
391
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
392
+ }
393
+ }
394
+
395
+ const imports = __wbg_get_imports();
396
+ if (!(module instanceof WebAssembly.Module)) {
397
+ module = new WebAssembly.Module(module);
398
+ }
399
+ const instance = new WebAssembly.Instance(module, imports);
400
+ return __wbg_finalize_init(instance, module);
401
+ }
402
+
403
+ async function __wbg_init(module_or_path) {
404
+ if (wasm !== undefined) return wasm;
405
+
406
+
407
+ if (module_or_path !== undefined) {
408
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
409
+ ({module_or_path} = module_or_path)
410
+ } else {
411
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
412
+ }
413
+ }
414
+
415
+ if (module_or_path === undefined) {
416
+ module_or_path = new URL('tdsl_wasm_bg.wasm', import.meta.url);
417
+ }
418
+ const imports = __wbg_get_imports();
419
+
420
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
421
+ module_or_path = fetch(module_or_path);
422
+ }
423
+
424
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
425
+
426
+ return __wbg_finalize_init(instance, module);
427
+ }
428
+
429
+ export { initSync, __wbg_init as default };
Binary file