@r4ai/typst-ast-node 0.0.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,18 @@
1
+ {
2
+ "name": "@r4ai/typst-ast-node",
3
+ "collaborators": [
4
+ "r4ai"
5
+ ],
6
+ "version": "0.0.0",
7
+ "license": "MIT",
8
+ "files": [
9
+ "typst_ast_bg.wasm",
10
+ "typst_ast.js",
11
+ "typst_ast.d.ts"
12
+ ],
13
+ "main": "typst_ast.js",
14
+ "types": "typst_ast.d.ts",
15
+ "keywords": [
16
+ "typst"
17
+ ]
18
+ }
package/typst_ast.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export function parse(text: string, options: any): any;
5
+
6
+ export function start(): void;
package/typst_ast.js ADDED
@@ -0,0 +1,347 @@
1
+ /* @ts-self-types="./typst_ast.d.ts" */
2
+
3
+ /**
4
+ * @param {string} text
5
+ * @param {any} options
6
+ * @returns {any}
7
+ */
8
+ function parse(text, options) {
9
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
10
+ const len0 = WASM_VECTOR_LEN;
11
+ const ret = wasm.parse(ptr0, len0, options);
12
+ if (ret[2]) {
13
+ throw takeFromExternrefTable0(ret[1]);
14
+ }
15
+ return takeFromExternrefTable0(ret[0]);
16
+ }
17
+ exports.parse = parse;
18
+
19
+ function start() {
20
+ wasm.start();
21
+ }
22
+ exports.start = start;
23
+
24
+ function __wbg_get_imports() {
25
+ const import0 = {
26
+ __proto__: null,
27
+ __wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
28
+ const ret = Error(getStringFromWasm0(arg0, arg1));
29
+ return ret;
30
+ },
31
+ __wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
32
+ const ret = String(arg1);
33
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
34
+ const len1 = WASM_VECTOR_LEN;
35
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
36
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
37
+ },
38
+ __wbg___wbindgen_boolean_get_bbbb1c18aa2f5e25: function(arg0) {
39
+ const v = arg0;
40
+ const ret = typeof(v) === 'boolean' ? v : undefined;
41
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
42
+ },
43
+ __wbg___wbindgen_debug_string_0bc8482c6e3508ae: function(arg0, arg1) {
44
+ const ret = debugString(arg1);
45
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
46
+ const len1 = WASM_VECTOR_LEN;
47
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
48
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
49
+ },
50
+ __wbg___wbindgen_in_47fa6863be6f2f25: function(arg0, arg1) {
51
+ const ret = arg0 in arg1;
52
+ return ret;
53
+ },
54
+ __wbg___wbindgen_is_null_ac34f5003991759a: function(arg0) {
55
+ const ret = arg0 === null;
56
+ return ret;
57
+ },
58
+ __wbg___wbindgen_is_object_5ae8e5880f2c1fbd: function(arg0) {
59
+ const val = arg0;
60
+ const ret = typeof(val) === 'object' && val !== null;
61
+ return ret;
62
+ },
63
+ __wbg___wbindgen_is_string_cd444516edc5b180: function(arg0) {
64
+ const ret = typeof(arg0) === 'string';
65
+ return ret;
66
+ },
67
+ __wbg___wbindgen_is_undefined_9e4d92534c42d778: function(arg0) {
68
+ const ret = arg0 === undefined;
69
+ return ret;
70
+ },
71
+ __wbg___wbindgen_jsval_loose_eq_9dd77d8cd6671811: function(arg0, arg1) {
72
+ const ret = arg0 == arg1;
73
+ return ret;
74
+ },
75
+ __wbg___wbindgen_number_get_8ff4255516ccad3e: function(arg0, arg1) {
76
+ const obj = arg1;
77
+ const ret = typeof(obj) === 'number' ? obj : undefined;
78
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
79
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
80
+ },
81
+ __wbg___wbindgen_string_get_72fb696202c56729: function(arg0, arg1) {
82
+ const obj = arg1;
83
+ const ret = typeof(obj) === 'string' ? obj : undefined;
84
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
85
+ var len1 = WASM_VECTOR_LEN;
86
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
87
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
88
+ },
89
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
90
+ throw new Error(getStringFromWasm0(arg0, arg1));
91
+ },
92
+ __wbg_entries_58c7934c745daac7: function(arg0) {
93
+ const ret = Object.entries(arg0);
94
+ return ret;
95
+ },
96
+ __wbg_get_9b94d73e6221f75c: function(arg0, arg1) {
97
+ const ret = arg0[arg1 >>> 0];
98
+ return ret;
99
+ },
100
+ __wbg_get_with_ref_key_1dc361bd10053bfe: function(arg0, arg1) {
101
+ const ret = arg0[arg1];
102
+ return ret;
103
+ },
104
+ __wbg_instanceof_ArrayBuffer_c367199e2fa2aa04: function(arg0) {
105
+ let result;
106
+ try {
107
+ result = arg0 instanceof ArrayBuffer;
108
+ } catch (_) {
109
+ result = false;
110
+ }
111
+ const ret = result;
112
+ return ret;
113
+ },
114
+ __wbg_instanceof_Uint8Array_9b9075935c74707c: function(arg0) {
115
+ let result;
116
+ try {
117
+ result = arg0 instanceof Uint8Array;
118
+ } catch (_) {
119
+ result = false;
120
+ }
121
+ const ret = result;
122
+ return ret;
123
+ },
124
+ __wbg_length_32ed9a279acd054c: function(arg0) {
125
+ const ret = arg0.length;
126
+ return ret;
127
+ },
128
+ __wbg_length_35a7bace40f36eac: function(arg0) {
129
+ const ret = arg0.length;
130
+ return ret;
131
+ },
132
+ __wbg_new_361308b2356cecd0: function() {
133
+ const ret = new Object();
134
+ return ret;
135
+ },
136
+ __wbg_new_3eb36ae241fe6f44: function() {
137
+ const ret = new Array();
138
+ return ret;
139
+ },
140
+ __wbg_new_dd2b680c8bf6ae29: function(arg0) {
141
+ const ret = new Uint8Array(arg0);
142
+ return ret;
143
+ },
144
+ __wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
145
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
146
+ },
147
+ __wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
148
+ arg0[arg1] = arg2;
149
+ },
150
+ __wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
151
+ arg0[arg1 >>> 0] = arg2;
152
+ },
153
+ __wbindgen_cast_0000000000000001: function(arg0) {
154
+ // Cast intrinsic for `F64 -> Externref`.
155
+ const ret = arg0;
156
+ return ret;
157
+ },
158
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
159
+ // Cast intrinsic for `Ref(String) -> Externref`.
160
+ const ret = getStringFromWasm0(arg0, arg1);
161
+ return ret;
162
+ },
163
+ __wbindgen_cast_0000000000000003: function(arg0) {
164
+ // Cast intrinsic for `U64 -> Externref`.
165
+ const ret = BigInt.asUintN(64, arg0);
166
+ return ret;
167
+ },
168
+ __wbindgen_init_externref_table: function() {
169
+ const table = wasm.__wbindgen_externrefs;
170
+ const offset = table.grow(4);
171
+ table.set(0, undefined);
172
+ table.set(offset + 0, undefined);
173
+ table.set(offset + 1, null);
174
+ table.set(offset + 2, true);
175
+ table.set(offset + 3, false);
176
+ },
177
+ };
178
+ return {
179
+ __proto__: null,
180
+ "./typst_ast_bg.js": import0,
181
+ };
182
+ }
183
+
184
+ function debugString(val) {
185
+ // primitive types
186
+ const type = typeof val;
187
+ if (type == 'number' || type == 'boolean' || val == null) {
188
+ return `${val}`;
189
+ }
190
+ if (type == 'string') {
191
+ return `"${val}"`;
192
+ }
193
+ if (type == 'symbol') {
194
+ const description = val.description;
195
+ if (description == null) {
196
+ return 'Symbol';
197
+ } else {
198
+ return `Symbol(${description})`;
199
+ }
200
+ }
201
+ if (type == 'function') {
202
+ const name = val.name;
203
+ if (typeof name == 'string' && name.length > 0) {
204
+ return `Function(${name})`;
205
+ } else {
206
+ return 'Function';
207
+ }
208
+ }
209
+ // objects
210
+ if (Array.isArray(val)) {
211
+ const length = val.length;
212
+ let debug = '[';
213
+ if (length > 0) {
214
+ debug += debugString(val[0]);
215
+ }
216
+ for(let i = 1; i < length; i++) {
217
+ debug += ', ' + debugString(val[i]);
218
+ }
219
+ debug += ']';
220
+ return debug;
221
+ }
222
+ // Test for built-in
223
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
224
+ let className;
225
+ if (builtInMatches && builtInMatches.length > 1) {
226
+ className = builtInMatches[1];
227
+ } else {
228
+ // Failed to match the standard '[object ClassName]'
229
+ return toString.call(val);
230
+ }
231
+ if (className == 'Object') {
232
+ // we're a user defined class or Object
233
+ // JSON.stringify avoids problems with cycles, and is generally much
234
+ // easier than looping through ownProperties of `val`.
235
+ try {
236
+ return 'Object(' + JSON.stringify(val) + ')';
237
+ } catch (_) {
238
+ return 'Object';
239
+ }
240
+ }
241
+ // errors
242
+ if (val instanceof Error) {
243
+ return `${val.name}: ${val.message}\n${val.stack}`;
244
+ }
245
+ // TODO we could test for more things here, like `Set`s and `Map`s.
246
+ return className;
247
+ }
248
+
249
+ function getArrayU8FromWasm0(ptr, len) {
250
+ ptr = ptr >>> 0;
251
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
252
+ }
253
+
254
+ let cachedDataViewMemory0 = null;
255
+ function getDataViewMemory0() {
256
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
257
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
258
+ }
259
+ return cachedDataViewMemory0;
260
+ }
261
+
262
+ function getStringFromWasm0(ptr, len) {
263
+ ptr = ptr >>> 0;
264
+ return decodeText(ptr, len);
265
+ }
266
+
267
+ let cachedUint8ArrayMemory0 = null;
268
+ function getUint8ArrayMemory0() {
269
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
270
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
271
+ }
272
+ return cachedUint8ArrayMemory0;
273
+ }
274
+
275
+ function isLikeNone(x) {
276
+ return x === undefined || x === null;
277
+ }
278
+
279
+ function passStringToWasm0(arg, malloc, realloc) {
280
+ if (realloc === undefined) {
281
+ const buf = cachedTextEncoder.encode(arg);
282
+ const ptr = malloc(buf.length, 1) >>> 0;
283
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
284
+ WASM_VECTOR_LEN = buf.length;
285
+ return ptr;
286
+ }
287
+
288
+ let len = arg.length;
289
+ let ptr = malloc(len, 1) >>> 0;
290
+
291
+ const mem = getUint8ArrayMemory0();
292
+
293
+ let offset = 0;
294
+
295
+ for (; offset < len; offset++) {
296
+ const code = arg.charCodeAt(offset);
297
+ if (code > 0x7F) break;
298
+ mem[ptr + offset] = code;
299
+ }
300
+ if (offset !== len) {
301
+ if (offset !== 0) {
302
+ arg = arg.slice(offset);
303
+ }
304
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
305
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
306
+ const ret = cachedTextEncoder.encodeInto(arg, view);
307
+
308
+ offset += ret.written;
309
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
310
+ }
311
+
312
+ WASM_VECTOR_LEN = offset;
313
+ return ptr;
314
+ }
315
+
316
+ function takeFromExternrefTable0(idx) {
317
+ const value = wasm.__wbindgen_externrefs.get(idx);
318
+ wasm.__externref_table_dealloc(idx);
319
+ return value;
320
+ }
321
+
322
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
323
+ cachedTextDecoder.decode();
324
+ function decodeText(ptr, len) {
325
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
326
+ }
327
+
328
+ const cachedTextEncoder = new TextEncoder();
329
+
330
+ if (!('encodeInto' in cachedTextEncoder)) {
331
+ cachedTextEncoder.encodeInto = function (arg, view) {
332
+ const buf = cachedTextEncoder.encode(arg);
333
+ view.set(buf);
334
+ return {
335
+ read: arg.length,
336
+ written: buf.length
337
+ };
338
+ };
339
+ }
340
+
341
+ let WASM_VECTOR_LEN = 0;
342
+
343
+ const wasmPath = `${__dirname}/typst_ast_bg.wasm`;
344
+ const wasmBytes = require('fs').readFileSync(wasmPath);
345
+ const wasmModule = new WebAssembly.Module(wasmBytes);
346
+ const wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
347
+ wasm.__wbindgen_start();
Binary file