@arborium/kdl 2.6.1 → 2.17.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/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # @arborium/kdl
2
+
3
+ [![Part of Arborium](https://img.shields.io/badge/🌳_Arborium-grammar_collection-228B22)](https://github.com/bearcove/arborium)
4
+ [![npm](https://img.shields.io/npm/v/@arborium/kdl)](https://www.npmjs.com/package/@arborium/kdl)
5
+ [![license](https://img.shields.io/npm/l/@arborium/kdl)](https://github.com/bearcove/arborium)
6
+
7
+ Syntax highlighting for [KDL](https://kdl.dev/), powered by WebAssembly and [tree-sitter](https://tree-sitter.github.io/).
8
+
9
+ > A modern document language with the flexibility of XML and the simplicity of JSON and YAML. Your new favorite configuration language.
10
+
11
+
12
+ | | |
13
+ |---|---|
14
+ | **Inventor** | Kat Marchán |
15
+ | **Year** | 2020 |
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @arborium/kdl
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```javascript
26
+ import { createHighlighter } from '@arborium/arborium';
27
+ import * as grammar from '@arborium/kdl';
28
+
29
+ const highlighter = await createHighlighter();
30
+ await highlighter.loadGrammar(grammar);
31
+
32
+ const html = highlighter.highlight(code, 'kdl');
33
+ ```
34
+
35
+ ## What's included
36
+
37
+ This package contains:
38
+
39
+ - `grammar.js` - ES module that loads the WebAssembly grammar
40
+ - `grammar.d.ts` - TypeScript type definitions
41
+ - `grammar_bg.wasm` - The tree-sitter grammar compiled to WebAssembly
42
+
43
+ ## About Arborium
44
+
45
+ This package is part of [**Arborium**](https://github.com/bearcove/arborium), a collection of tree-sitter grammars for syntax highlighting, maintained by [Amos Wenger](https://fasterthanli.me).
46
+
47
+ Arborium provides:
48
+ - **98+ language grammars** compiled to WebAssembly
49
+ - **Browser and Node.js support** via ES modules
50
+ - **TypeScript definitions** for all packages
51
+ - **Consistent API** across all grammars
52
+
53
+ ## Related packages
54
+
55
+ - [`@arborium/arborium`](https://www.npmjs.com/package/@arborium/arborium) - Core highlighter library
56
+ - [All @arborium packages](https://www.npmjs.com/org/arborium)
57
+
58
+ ## License
59
+
60
+ MIT OR Apache-2.0
61
+
62
+ ## Links
63
+
64
+ - [GitHub](https://github.com/bearcove/arborium)
65
+ - [Issues](https://github.com/bearcove/arborium/issues)
package/grammar.js CHANGED
@@ -1,4 +1,172 @@
1
- let wasm;
1
+ /* @ts-self-types="./arborium_kdl_plugin.d.ts" */
2
+
3
+ /**
4
+ * Cancels an ongoing parse operation.
5
+ * @param {number} session
6
+ */
7
+ export function cancel(session) {
8
+ wasm.cancel(session);
9
+ }
10
+
11
+ /**
12
+ * Creates a new parser session and returns its ID.
13
+ * @returns {number}
14
+ */
15
+ export function create_session() {
16
+ const ret = wasm.create_session();
17
+ return ret >>> 0;
18
+ }
19
+
20
+ /**
21
+ * Frees a parser session.
22
+ * @param {number} session
23
+ */
24
+ export function free_session(session) {
25
+ wasm.free_session(session);
26
+ }
27
+
28
+ /**
29
+ * Returns the list of languages this grammar can inject into (e.g., for embedded languages).
30
+ * Most grammars return an empty array.
31
+ * @returns {string[]}
32
+ */
33
+ export function injection_languages() {
34
+ try {
35
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
36
+ wasm.injection_languages(retptr);
37
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
38
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
39
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
40
+ wasm.__wbindgen_export(r0, r1 * 4, 4);
41
+ return v1;
42
+ } finally {
43
+ wasm.__wbindgen_add_to_stack_pointer(16);
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Returns the language ID for this grammar plugin.
49
+ * @returns {string}
50
+ */
51
+ export function language_id() {
52
+ let deferred1_0;
53
+ let deferred1_1;
54
+ try {
55
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
56
+ wasm.language_id(retptr);
57
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
58
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
59
+ deferred1_0 = r0;
60
+ deferred1_1 = r1;
61
+ return getStringFromWasm0(r0, r1);
62
+ } finally {
63
+ wasm.__wbindgen_add_to_stack_pointer(16);
64
+ wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Parses the text in a session and returns spans with UTF-8 byte offsets.
70
+ *
71
+ * Use this for Rust code that needs to slice strings with `&source[start..end]`.
72
+ * For JavaScript interop, use `parse_utf16` instead.
73
+ * @param {number} session
74
+ * @returns {any}
75
+ */
76
+ export function parse(session) {
77
+ try {
78
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
79
+ wasm.parse(retptr, session);
80
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
81
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
82
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
83
+ if (r2) {
84
+ throw takeObject(r1);
85
+ }
86
+ return takeObject(r0);
87
+ } finally {
88
+ wasm.__wbindgen_add_to_stack_pointer(16);
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Parses the text in a session and returns spans with UTF-16 code unit indices.
94
+ *
95
+ * Use this for JavaScript code that needs to use `String.prototype.slice()`.
96
+ * The offsets are compatible with JavaScript string APIs.
97
+ * @param {number} session
98
+ * @returns {any}
99
+ */
100
+ export function parse_utf16(session) {
101
+ try {
102
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
103
+ wasm.parse_utf16(retptr, session);
104
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
105
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
106
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
107
+ if (r2) {
108
+ throw takeObject(r1);
109
+ }
110
+ return takeObject(r0);
111
+ } finally {
112
+ wasm.__wbindgen_add_to_stack_pointer(16);
113
+ }
114
+ }
115
+
116
+ /**
117
+ * Sets the text for a parser session.
118
+ * @param {number} session
119
+ * @param {string} text
120
+ */
121
+ export function set_text(session, text) {
122
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
123
+ const len0 = WASM_VECTOR_LEN;
124
+ wasm.set_text(session, ptr0, len0);
125
+ }
126
+
127
+ function __wbg_get_imports() {
128
+ const import0 = {
129
+ __proto__: null,
130
+ __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
131
+ throw new Error(getStringFromWasm0(arg0, arg1));
132
+ },
133
+ __wbg_new_a70fbab9066b301f: function() {
134
+ const ret = new Array();
135
+ return addHeapObject(ret);
136
+ },
137
+ __wbg_new_ab79df5bd7c26067: function() {
138
+ const ret = new Object();
139
+ return addHeapObject(ret);
140
+ },
141
+ __wbg_set_282384002438957f: function(arg0, arg1, arg2) {
142
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
143
+ },
144
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
145
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
146
+ },
147
+ __wbindgen_cast_0000000000000001: function(arg0) {
148
+ // Cast intrinsic for `F64 -> Externref`.
149
+ const ret = arg0;
150
+ return addHeapObject(ret);
151
+ },
152
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
153
+ // Cast intrinsic for `Ref(String) -> Externref`.
154
+ const ret = getStringFromWasm0(arg0, arg1);
155
+ return addHeapObject(ret);
156
+ },
157
+ __wbindgen_object_clone_ref: function(arg0) {
158
+ const ret = getObject(arg0);
159
+ return addHeapObject(ret);
160
+ },
161
+ __wbindgen_object_drop_ref: function(arg0) {
162
+ takeObject(arg0);
163
+ },
164
+ };
165
+ return {
166
+ __proto__: null,
167
+ "./arborium_kdl_plugin_bg.js": import0,
168
+ };
169
+ }
2
170
 
3
171
  function addHeapObject(obj) {
4
172
  if (heap_next === heap.length) heap.push(heap.length + 1);
@@ -10,7 +178,7 @@ function addHeapObject(obj) {
10
178
  }
11
179
 
12
180
  function dropObject(idx) {
13
- if (idx < 132) return;
181
+ if (idx < 1028) return;
14
182
  heap[idx] = heap_next;
15
183
  heap_next = idx;
16
184
  }
@@ -48,7 +216,7 @@ function getUint8ArrayMemory0() {
48
216
 
49
217
  function getObject(idx) { return heap[idx]; }
50
218
 
51
- let heap = new Array(128).fill(undefined);
219
+ let heap = new Array(1024).fill(undefined);
52
220
  heap.push(undefined, null, true, false);
53
221
 
54
222
  let heap_next = heap.length;
@@ -120,126 +288,32 @@ if (!('encodeInto' in cachedTextEncoder)) {
120
288
  read: arg.length,
121
289
  written: buf.length
122
290
  };
123
- }
291
+ };
124
292
  }
125
293
 
126
294
  let WASM_VECTOR_LEN = 0;
127
295
 
128
- /**
129
- * Cancels an ongoing parse operation.
130
- * @param {number} session
131
- */
132
- export function cancel(session) {
133
- wasm.cancel(session);
134
- }
135
-
136
- /**
137
- * Creates a new parser session and returns its ID.
138
- * @returns {number}
139
- */
140
- export function create_session() {
141
- const ret = wasm.create_session();
142
- return ret >>> 0;
143
- }
144
-
145
- /**
146
- * Frees a parser session.
147
- * @param {number} session
148
- */
149
- export function free_session(session) {
150
- wasm.free_session(session);
151
- }
152
-
153
- /**
154
- * Returns the list of languages this grammar can inject into (e.g., for embedded languages).
155
- * Most grammars return an empty array.
156
- * @returns {string[]}
157
- */
158
- export function injection_languages() {
159
- try {
160
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
161
- wasm.injection_languages(retptr);
162
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
163
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
164
- var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
165
- wasm.__wbindgen_export(r0, r1 * 4, 4);
166
- return v1;
167
- } finally {
168
- wasm.__wbindgen_add_to_stack_pointer(16);
169
- }
170
- }
171
-
172
- /**
173
- * Returns the language ID for this grammar plugin.
174
- * @returns {string}
175
- */
176
- export function language_id() {
177
- let deferred1_0;
178
- let deferred1_1;
179
- try {
180
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
181
- wasm.language_id(retptr);
182
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
183
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
184
- deferred1_0 = r0;
185
- deferred1_1 = r1;
186
- return getStringFromWasm0(r0, r1);
187
- } finally {
188
- wasm.__wbindgen_add_to_stack_pointer(16);
189
- wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
190
- }
191
- }
192
-
193
- /**
194
- * Parses the text in a session and returns the result as a JS value.
195
- *
196
- * The result is a JavaScript object representation of ParseResult containing spans and injections.
197
- * @param {number} session
198
- * @returns {any}
199
- */
200
- export function parse(session) {
201
- try {
202
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
203
- wasm.parse(retptr, session);
204
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
205
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
206
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
207
- if (r2) {
208
- throw takeObject(r1);
209
- }
210
- return takeObject(r0);
211
- } finally {
212
- wasm.__wbindgen_add_to_stack_pointer(16);
213
- }
214
- }
215
-
216
- /**
217
- * Sets the text for a parser session.
218
- * @param {number} session
219
- * @param {string} text
220
- */
221
- export function set_text(session, text) {
222
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
223
- const len0 = WASM_VECTOR_LEN;
224
- wasm.set_text(session, ptr0, len0);
296
+ let wasmModule, wasm;
297
+ function __wbg_finalize_init(instance, module) {
298
+ wasm = instance.exports;
299
+ wasmModule = module;
300
+ cachedDataViewMemory0 = null;
301
+ cachedUint8ArrayMemory0 = null;
302
+ return wasm;
225
303
  }
226
304
 
227
- const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
228
-
229
305
  async function __wbg_load(module, imports) {
230
306
  if (typeof Response === 'function' && module instanceof Response) {
231
307
  if (typeof WebAssembly.instantiateStreaming === 'function') {
232
308
  try {
233
309
  return await WebAssembly.instantiateStreaming(module, imports);
234
310
  } catch (e) {
235
- const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
311
+ const validResponse = module.ok && expectedResponseType(module.type);
236
312
 
237
313
  if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
238
314
  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
315
 
240
- } else {
241
- throw e;
242
- }
316
+ } else { throw e; }
243
317
  }
244
318
  }
245
319
 
@@ -254,65 +328,20 @@ async function __wbg_load(module, imports) {
254
328
  return instance;
255
329
  }
256
330
  }
257
- }
258
331
 
259
- function __wbg_get_imports() {
260
- const imports = {};
261
- imports.wbg = {};
262
- imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
263
- throw new Error(getStringFromWasm0(arg0, arg1));
264
- };
265
- imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
266
- const ret = new Object();
267
- return addHeapObject(ret);
268
- };
269
- imports.wbg.__wbg_new_25f239778d6112b9 = function() {
270
- const ret = new Array();
271
- return addHeapObject(ret);
272
- };
273
- imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
274
- getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
275
- };
276
- imports.wbg.__wbg_set_7df433eea03a5c14 = function(arg0, arg1, arg2) {
277
- getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
278
- };
279
- imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
280
- // Cast intrinsic for `Ref(String) -> Externref`.
281
- const ret = getStringFromWasm0(arg0, arg1);
282
- return addHeapObject(ret);
283
- };
284
- imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
285
- // Cast intrinsic for `F64 -> Externref`.
286
- const ret = arg0;
287
- return addHeapObject(ret);
288
- };
289
- imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
290
- const ret = getObject(arg0);
291
- return addHeapObject(ret);
292
- };
293
- imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
294
- takeObject(arg0);
295
- };
296
-
297
- return imports;
298
- }
299
-
300
- function __wbg_finalize_init(instance, module) {
301
- wasm = instance.exports;
302
- __wbg_init.__wbindgen_wasm_module = module;
303
- cachedDataViewMemory0 = null;
304
- cachedUint8ArrayMemory0 = null;
305
-
306
-
307
-
308
- return wasm;
332
+ function expectedResponseType(type) {
333
+ switch (type) {
334
+ case 'basic': case 'cors': case 'default': return true;
335
+ }
336
+ return false;
337
+ }
309
338
  }
310
339
 
311
340
  function initSync(module) {
312
341
  if (wasm !== undefined) return wasm;
313
342
 
314
343
 
315
- if (typeof module !== 'undefined') {
344
+ if (module !== undefined) {
316
345
  if (Object.getPrototypeOf(module) === Object.prototype) {
317
346
  ({module} = module)
318
347
  } else {
@@ -332,7 +361,7 @@ async function __wbg_init(module_or_path) {
332
361
  if (wasm !== undefined) return wasm;
333
362
 
334
363
 
335
- if (typeof module_or_path !== 'undefined') {
364
+ if (module_or_path !== undefined) {
336
365
  if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
337
366
  ({module_or_path} = module_or_path)
338
367
  } else {
@@ -340,7 +369,7 @@ async function __wbg_init(module_or_path) {
340
369
  }
341
370
  }
342
371
 
343
- if (typeof module_or_path === 'undefined') {
372
+ if (module_or_path === undefined) {
344
373
  module_or_path = new URL('arborium_kdl_plugin_bg.wasm', import.meta.url);
345
374
  }
346
375
  const imports = __wbg_get_imports();
@@ -354,5 +383,4 @@ async function __wbg_init(module_or_path) {
354
383
  return __wbg_finalize_init(instance, module);
355
384
  }
356
385
 
357
- export { initSync };
358
- export default __wbg_init;
386
+ export { initSync, __wbg_init as default };
package/grammar_bg.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,26 +1,17 @@
1
1
  {
2
- "author": "Amos Wenger <amos@bearcove.eu>",
3
- "bugs": {
4
- "url": "https://github.com/bearcove/arborium/issues"
5
- },
2
+ "name": "@arborium/kdl",
3
+ "version": "2.17.0",
6
4
  "description": "Syntax highlighting for KDL, powered by WebAssembly",
7
- "engines": {
8
- "node": ">=18"
9
- },
5
+ "type": "module",
6
+ "main": "./grammar.js",
7
+ "module": "./grammar.js",
10
8
  "exports": {
11
9
  ".": "./grammar.js",
12
10
  "./grammar.js": "./grammar.js",
13
11
  "./grammar_bg.wasm": "./grammar_bg.wasm"
14
12
  },
15
- "files": [
16
- "grammar.js",
17
- "grammar_bg.wasm"
18
- ],
19
- "funding": {
20
- "type": "github",
21
- "url": "https://github.com/sponsors/fasterthanlime"
22
- },
23
- "homepage": "https://github.com/bearcove/arborium",
13
+ "files": ["grammar.js", "grammar_bg.wasm"],
14
+ "sideEffects": false,
24
15
  "keywords": [
25
16
  "arborium",
26
17
  "syntax-highlighting",
@@ -29,18 +20,24 @@
29
20
  "KDL",
30
21
  "wasm"
31
22
  ],
32
- "license": "MIT OR Apache-2.0",
33
- "main": "./grammar.js",
34
- "module": "./grammar.js",
35
- "name": "@arborium/kdl",
36
- "publishConfig": {
37
- "access": "public"
38
- },
23
+ "author": "Amos Wenger <amos@bearcove.eu>",
24
+ "license": "MIT",
39
25
  "repository": {
40
26
  "type": "git",
41
27
  "url": "https://github.com/bearcove/arborium"
42
28
  },
43
- "sideEffects": false,
44
- "type": "module",
45
- "version": "2.6.1"
29
+ "homepage": "https://github.com/bearcove/arborium",
30
+ "bugs": {
31
+ "url": "https://github.com/bearcove/arborium/issues"
32
+ },
33
+ "funding": {
34
+ "type": "github",
35
+ "url": "https://github.com/sponsors/fasterthanlime"
36
+ },
37
+ "engines": {
38
+ "node": ">=18"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ }
46
43
  }