@arborium/arborium 2.4.7 → 2.6.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/dist/arborium.d.ts +3 -3
- package/dist/arborium.iife.js +2 -2
- package/dist/arborium.iife.js.map +1 -1
- package/dist/arborium.js +511 -168
- package/dist/arborium.js.map +1 -1
- package/dist/arborium_host.js +9 -9
- package/dist/arborium_host_bg.wasm +0 -0
- package/dist/loader.d.ts +6 -7
- package/dist/loader.test.d.ts +1 -0
- package/dist/plugins-manifest.d.ts +4 -1
- package/dist/types.d.ts +37 -2
- package/dist/utils.d.ts +5 -0
- package/package.json +5 -2
package/dist/arborium.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const L = "2.6.0", _ = [
|
|
2
2
|
"ada",
|
|
3
3
|
"agda",
|
|
4
4
|
"asciidoc",
|
|
@@ -71,6 +71,7 @@ const x = "2.4.7", $ = [
|
|
|
71
71
|
"scala",
|
|
72
72
|
"scheme",
|
|
73
73
|
"scss",
|
|
74
|
+
"solidity",
|
|
74
75
|
"sparql",
|
|
75
76
|
"sql",
|
|
76
77
|
"ssh-config",
|
|
@@ -97,204 +98,544 @@ const x = "2.4.7", $ = [
|
|
|
97
98
|
"yuri",
|
|
98
99
|
"zig",
|
|
99
100
|
"zsh"
|
|
100
|
-
],
|
|
101
|
+
], M = [
|
|
102
|
+
{
|
|
103
|
+
name: "attribute",
|
|
104
|
+
tag: "at"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "constant",
|
|
108
|
+
tag: "co"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "constant.builtin",
|
|
112
|
+
tag: "co",
|
|
113
|
+
parentTag: "co"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: "constructor",
|
|
117
|
+
tag: "cr"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "function.builtin",
|
|
121
|
+
tag: "fb",
|
|
122
|
+
parentTag: "f"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "function",
|
|
126
|
+
tag: "f"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: "function.method",
|
|
130
|
+
tag: "f",
|
|
131
|
+
parentTag: "f"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: "keyword",
|
|
135
|
+
tag: "k"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "keyword.conditional",
|
|
139
|
+
tag: "k",
|
|
140
|
+
parentTag: "k"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: "keyword.coroutine",
|
|
144
|
+
tag: "k",
|
|
145
|
+
parentTag: "k"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: "keyword.debug",
|
|
149
|
+
tag: "k",
|
|
150
|
+
parentTag: "k"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: "keyword.exception",
|
|
154
|
+
tag: "k",
|
|
155
|
+
parentTag: "k"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: "keyword.function",
|
|
159
|
+
tag: "k",
|
|
160
|
+
parentTag: "k"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: "keyword.import",
|
|
164
|
+
tag: "k",
|
|
165
|
+
parentTag: "k"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: "keyword.operator",
|
|
169
|
+
tag: "o",
|
|
170
|
+
parentTag: "k"
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: "keyword.repeat",
|
|
174
|
+
tag: "k",
|
|
175
|
+
parentTag: "k"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: "keyword.return",
|
|
179
|
+
tag: "k",
|
|
180
|
+
parentTag: "k"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: "keyword.type",
|
|
184
|
+
tag: "k",
|
|
185
|
+
parentTag: "k"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: "operator",
|
|
189
|
+
tag: "o"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: "property",
|
|
193
|
+
tag: "pr"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
name: "punctuation",
|
|
197
|
+
tag: "p"
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: "punctuation.bracket",
|
|
201
|
+
tag: "p",
|
|
202
|
+
parentTag: "p"
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: "punctuation.delimiter",
|
|
206
|
+
tag: "p",
|
|
207
|
+
parentTag: "p"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
name: "punctuation.special",
|
|
211
|
+
tag: "p",
|
|
212
|
+
parentTag: "p"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: "string",
|
|
216
|
+
tag: "s"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
name: "string.special",
|
|
220
|
+
tag: "s",
|
|
221
|
+
parentTag: "s"
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
name: "tag",
|
|
225
|
+
tag: "tg"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: "tag.delimiter",
|
|
229
|
+
tag: "tg",
|
|
230
|
+
parentTag: "tg"
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
name: "tag.error",
|
|
234
|
+
tag: "err",
|
|
235
|
+
parentTag: "tg"
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
name: "type",
|
|
239
|
+
tag: "t"
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
name: "type.builtin",
|
|
243
|
+
tag: "t",
|
|
244
|
+
parentTag: "t"
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: "type.qualifier",
|
|
248
|
+
tag: "t",
|
|
249
|
+
parentTag: "t"
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: "variable",
|
|
253
|
+
tag: "v"
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
name: "variable.builtin",
|
|
257
|
+
tag: "v",
|
|
258
|
+
parentTag: "v"
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: "variable.parameter",
|
|
262
|
+
tag: "v",
|
|
263
|
+
parentTag: "v"
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
name: "comment",
|
|
267
|
+
tag: "c"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
name: "comment.documentation",
|
|
271
|
+
tag: "c",
|
|
272
|
+
parentTag: "c"
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
name: "macro",
|
|
276
|
+
tag: "m"
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
name: "label",
|
|
280
|
+
tag: "l"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
name: "diff.addition",
|
|
284
|
+
tag: "da"
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
name: "diff.deletion",
|
|
288
|
+
tag: "dd"
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
name: "number",
|
|
292
|
+
tag: "n"
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
name: "text.literal",
|
|
296
|
+
tag: "tl"
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
name: "text.emphasis",
|
|
300
|
+
tag: "em"
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
name: "text.strong",
|
|
304
|
+
tag: "st"
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
name: "text.uri",
|
|
308
|
+
tag: "tu"
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
name: "text.reference",
|
|
312
|
+
tag: "tr"
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
name: "string.escape",
|
|
316
|
+
tag: "se",
|
|
317
|
+
parentTag: "s"
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
name: "text.title",
|
|
321
|
+
tag: "tt"
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
name: "text.strikethrough",
|
|
325
|
+
tag: "ts"
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
name: "spell",
|
|
329
|
+
tag: ""
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
name: "embedded",
|
|
333
|
+
tag: "eb"
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
name: "error",
|
|
337
|
+
tag: "err"
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
name: "namespace",
|
|
341
|
+
tag: "ns"
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
name: "include",
|
|
345
|
+
tag: "k",
|
|
346
|
+
parentTag: "k"
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
name: "storageclass",
|
|
350
|
+
tag: "k",
|
|
351
|
+
parentTag: "k"
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
name: "repeat",
|
|
355
|
+
tag: "k",
|
|
356
|
+
parentTag: "k"
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
name: "conditional",
|
|
360
|
+
tag: "k",
|
|
361
|
+
parentTag: "k"
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
name: "exception",
|
|
365
|
+
tag: "k",
|
|
366
|
+
parentTag: "k"
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
name: "preproc",
|
|
370
|
+
tag: "pp"
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
name: "none",
|
|
374
|
+
tag: ""
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
name: "character",
|
|
378
|
+
tag: "ch",
|
|
379
|
+
parentTag: "s"
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
name: "character.special",
|
|
383
|
+
tag: "ch",
|
|
384
|
+
parentTag: "ch"
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
name: "variable.member",
|
|
388
|
+
tag: "pr",
|
|
389
|
+
parentTag: "v"
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
name: "function.definition",
|
|
393
|
+
tag: "f",
|
|
394
|
+
parentTag: "f"
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
name: "type.definition",
|
|
398
|
+
tag: "t",
|
|
399
|
+
parentTag: "t"
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
name: "function.call",
|
|
403
|
+
tag: "f",
|
|
404
|
+
parentTag: "f"
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
name: "keyword.modifier",
|
|
408
|
+
tag: "k",
|
|
409
|
+
parentTag: "k"
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
name: "keyword.directive",
|
|
413
|
+
tag: "k",
|
|
414
|
+
parentTag: "k"
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
name: "string.regexp",
|
|
418
|
+
tag: "sr",
|
|
419
|
+
parentTag: "s"
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
name: "nospell",
|
|
423
|
+
tag: ""
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
name: "float",
|
|
427
|
+
tag: "n",
|
|
428
|
+
parentTag: "n"
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
name: "boolean",
|
|
432
|
+
tag: "bo",
|
|
433
|
+
parentTag: "co"
|
|
434
|
+
}
|
|
435
|
+
];
|
|
436
|
+
function y(t, a) {
|
|
437
|
+
const r = [...a].sort((n, o) => n.start - o.start);
|
|
438
|
+
let e = "", s = 0;
|
|
439
|
+
for (const n of r) {
|
|
440
|
+
if (n.start < s) continue;
|
|
441
|
+
n.start > s && (e += u(t.slice(s, n.start)));
|
|
442
|
+
const o = U(n.capture), i = u(t.slice(n.start, n.end));
|
|
443
|
+
o ? e += `<a-${o}>${i}</a-${o}>` : e += i, s = n.end;
|
|
444
|
+
}
|
|
445
|
+
return s < t.length && (e += u(t.slice(s))), e;
|
|
446
|
+
}
|
|
447
|
+
function U(t) {
|
|
448
|
+
return t.startsWith("keyword") || t === "include" || t === "conditional" ? "k" : t.startsWith("function") || t.startsWith("method") ? "f" : t.startsWith("string") || t === "character" ? "s" : t.startsWith("comment") ? "c" : t.startsWith("type") ? "t" : t.startsWith("variable") ? "v" : t.startsWith("number") || t === "float" ? "n" : t.startsWith("operator") ? "o" : t.startsWith("punctuation") ? "p" : t.startsWith("tag") ? "tg" : t.startsWith("attribute") ? "at" : null;
|
|
449
|
+
}
|
|
450
|
+
function u(t) {
|
|
451
|
+
return t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
452
|
+
}
|
|
453
|
+
const v = {
|
|
101
454
|
manual: !1,
|
|
102
455
|
theme: "one-dark",
|
|
103
456
|
selector: "pre code",
|
|
104
457
|
cdn: "jsdelivr",
|
|
105
|
-
version:
|
|
458
|
+
version: L,
|
|
106
459
|
// Precise version from manifest
|
|
107
460
|
pluginsUrl: "",
|
|
108
461
|
// Empty means use bundled manifest
|
|
109
|
-
hostUrl: ""
|
|
462
|
+
hostUrl: "",
|
|
110
463
|
// Empty means use CDN based on version
|
|
464
|
+
resolveJs: ({ baseUrl: t, path: a }) => import(
|
|
465
|
+
/* @vite-ignore */
|
|
466
|
+
`${t}/${a}`
|
|
467
|
+
),
|
|
468
|
+
resolveWasm: ({ baseUrl: t, path: a }) => fetch(`${t}/${a}`)
|
|
111
469
|
};
|
|
112
|
-
let p = null,
|
|
113
|
-
const
|
|
114
|
-
let l = null,
|
|
115
|
-
async function
|
|
116
|
-
if (
|
|
117
|
-
return
|
|
118
|
-
console.debug(`[arborium] Loading local plugins manifest from: ${
|
|
119
|
-
const
|
|
120
|
-
if (!
|
|
121
|
-
throw new Error(`Failed to load plugins.json: ${
|
|
122
|
-
l = await
|
|
123
|
-
})(),
|
|
470
|
+
let p = null, g = null, d = { ...v };
|
|
471
|
+
const h = /* @__PURE__ */ new Map(), T = new Set(_);
|
|
472
|
+
let l = null, m = null;
|
|
473
|
+
async function E(t) {
|
|
474
|
+
if (t.pluginsUrl)
|
|
475
|
+
return m || (m = (async () => {
|
|
476
|
+
console.debug(`[arborium] Loading local plugins manifest from: ${t.pluginsUrl}`);
|
|
477
|
+
const a = await fetch(t.pluginsUrl);
|
|
478
|
+
if (!a.ok)
|
|
479
|
+
throw new Error(`Failed to load plugins.json: ${a.status}`);
|
|
480
|
+
l = await a.json(), console.debug(`[arborium] Loaded local manifest with ${l?.entries.length} entries`);
|
|
481
|
+
})(), m);
|
|
124
482
|
}
|
|
125
|
-
function
|
|
483
|
+
function W(t, a) {
|
|
126
484
|
if (l) {
|
|
127
|
-
const
|
|
128
|
-
if (
|
|
129
|
-
return
|
|
485
|
+
const n = l.entries.find((o) => o.language === t);
|
|
486
|
+
if (n)
|
|
487
|
+
return n.local_js.substring(0, n.local_js.lastIndexOf("/"));
|
|
130
488
|
}
|
|
131
|
-
const
|
|
132
|
-
let
|
|
133
|
-
return
|
|
489
|
+
const r = a.cdn, e = a.version;
|
|
490
|
+
let s;
|
|
491
|
+
return r === "jsdelivr" ? s = "https://cdn.jsdelivr.net/npm" : r === "unpkg" ? s = "https://unpkg.com" : s = r, `${s}/@arborium/${t}@${e}`;
|
|
134
492
|
}
|
|
135
|
-
async function w(
|
|
136
|
-
const
|
|
137
|
-
if (
|
|
138
|
-
return console.debug(`[arborium] Grammar '${
|
|
139
|
-
if (await
|
|
140
|
-
return console.debug(`[arborium] Grammar '${
|
|
493
|
+
async function w(t, a) {
|
|
494
|
+
const r = h.get(t);
|
|
495
|
+
if (r)
|
|
496
|
+
return console.debug(`[arborium] Grammar '${t}' found in cache`), r;
|
|
497
|
+
if (await E(a), !T.has(t) && !l?.entries.some((e) => e.language === t))
|
|
498
|
+
return console.debug(`[arborium] Grammar '${t}' not available`), null;
|
|
141
499
|
try {
|
|
142
|
-
const
|
|
143
|
-
console.debug(`[arborium] Loading grammar '${
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
module: r,
|
|
155
|
-
parse: (k) => {
|
|
156
|
-
const m = r.create_session();
|
|
500
|
+
const e = W(t, a), s = a.resolveJs === v.resolveJs ? ` from ${e}/grammar.js` : "";
|
|
501
|
+
console.debug(`[arborium] Loading grammar '${t}'${s}`);
|
|
502
|
+
const n = await a.resolveJs({ language: t, baseUrl: e, path: "grammar.js" }), o = await a.resolveWasm({ language: t, baseUrl: e, path: "grammar_bg.wasm" });
|
|
503
|
+
await n.default({ module_or_path: o });
|
|
504
|
+
const i = n.language_id();
|
|
505
|
+
i !== t && console.warn(`[arborium] Language ID mismatch: expected '${t}', got '${i}'`);
|
|
506
|
+
const x = n.injection_languages(), k = {
|
|
507
|
+
languageId: t,
|
|
508
|
+
injectionLanguages: x,
|
|
509
|
+
module: n,
|
|
510
|
+
parse: ($) => {
|
|
511
|
+
const b = n.create_session();
|
|
157
512
|
try {
|
|
158
|
-
|
|
159
|
-
const
|
|
513
|
+
n.set_text(b, $);
|
|
514
|
+
const c = n.parse(b);
|
|
160
515
|
return {
|
|
161
|
-
spans:
|
|
162
|
-
injections:
|
|
516
|
+
spans: c.spans || [],
|
|
517
|
+
injections: c.injections || []
|
|
163
518
|
};
|
|
164
|
-
} catch (
|
|
165
|
-
return console.error("[arborium] Parse error:",
|
|
519
|
+
} catch (c) {
|
|
520
|
+
return console.error("[arborium] Parse error:", c), { spans: [], injections: [] };
|
|
166
521
|
} finally {
|
|
167
|
-
|
|
522
|
+
n.free_session(b);
|
|
168
523
|
}
|
|
169
524
|
}
|
|
170
525
|
};
|
|
171
|
-
return
|
|
172
|
-
} catch (
|
|
173
|
-
return console.error(`[arborium] Failed to load grammar '${
|
|
526
|
+
return h.set(t, k), console.debug(`[arborium] Grammar '${t}' loaded successfully`), k;
|
|
527
|
+
} catch (e) {
|
|
528
|
+
return console.error(`[arborium] Failed to load grammar '${t}':`, e), null;
|
|
174
529
|
}
|
|
175
530
|
}
|
|
176
|
-
const
|
|
177
|
-
let
|
|
178
|
-
function
|
|
531
|
+
const f = /* @__PURE__ */ new Map();
|
|
532
|
+
let C = 1;
|
|
533
|
+
function S(t) {
|
|
179
534
|
window.arboriumHost = {
|
|
180
535
|
/** Check if a language is available (sync) */
|
|
181
|
-
isLanguageAvailable(
|
|
182
|
-
return
|
|
536
|
+
isLanguageAvailable(a) {
|
|
537
|
+
return T.has(a) || h.has(a);
|
|
183
538
|
},
|
|
184
539
|
/** Load a grammar and return a handle (async) */
|
|
185
|
-
async loadGrammar(
|
|
186
|
-
const
|
|
187
|
-
if (!
|
|
188
|
-
for (const [
|
|
189
|
-
if (
|
|
190
|
-
const
|
|
191
|
-
return
|
|
540
|
+
async loadGrammar(a) {
|
|
541
|
+
const r = await w(a, t);
|
|
542
|
+
if (!r) return 0;
|
|
543
|
+
for (const [s, n] of f)
|
|
544
|
+
if (n === r) return s;
|
|
545
|
+
const e = C++;
|
|
546
|
+
return f.set(e, r), e;
|
|
192
547
|
},
|
|
193
548
|
/** Parse text using a grammar handle (sync) */
|
|
194
|
-
parse(
|
|
195
|
-
const
|
|
196
|
-
return
|
|
549
|
+
parse(a, r) {
|
|
550
|
+
const e = f.get(a);
|
|
551
|
+
return e ? e.parse(r) : { spans: [], injections: [] };
|
|
197
552
|
}
|
|
198
553
|
};
|
|
199
554
|
}
|
|
200
|
-
function
|
|
201
|
-
if (
|
|
202
|
-
return
|
|
203
|
-
const
|
|
204
|
-
let
|
|
205
|
-
|
|
206
|
-
const
|
|
207
|
-
return `${
|
|
555
|
+
function q(t) {
|
|
556
|
+
if (t.hostUrl)
|
|
557
|
+
return t.hostUrl;
|
|
558
|
+
const a = t.cdn, r = t.version;
|
|
559
|
+
let e;
|
|
560
|
+
a === "jsdelivr" ? e = "https://cdn.jsdelivr.net/npm" : a === "unpkg" ? e = "https://unpkg.com" : e = a;
|
|
561
|
+
const s = r === "latest" ? "" : `@${r}`;
|
|
562
|
+
return `${e}/@arborium/arborium${s}/dist`;
|
|
208
563
|
}
|
|
209
|
-
async function
|
|
210
|
-
return p ||
|
|
211
|
-
|
|
212
|
-
const
|
|
213
|
-
console.debug(`[arborium] Loading host from ${
|
|
564
|
+
async function I(t) {
|
|
565
|
+
return p || g || (g = (async () => {
|
|
566
|
+
S(t);
|
|
567
|
+
const a = q(t), r = `${a}/arborium_host.js`, e = `${a}/arborium_host_bg.wasm`;
|
|
568
|
+
console.debug(`[arborium] Loading host from ${r}`);
|
|
214
569
|
try {
|
|
215
|
-
const
|
|
570
|
+
const s = await import(
|
|
216
571
|
/* @vite-ignore */
|
|
217
|
-
|
|
572
|
+
r
|
|
218
573
|
);
|
|
219
|
-
return await
|
|
220
|
-
highlight:
|
|
221
|
-
isLanguageAvailable:
|
|
574
|
+
return await s.default(e), p = {
|
|
575
|
+
highlight: s.highlight,
|
|
576
|
+
isLanguageAvailable: s.isLanguageAvailable
|
|
222
577
|
}, console.debug("[arborium] Host loaded successfully"), p;
|
|
223
|
-
} catch (
|
|
224
|
-
return console.error("[arborium] Failed to load host:",
|
|
578
|
+
} catch (s) {
|
|
579
|
+
return console.error("[arborium] Failed to load host:", s), null;
|
|
225
580
|
}
|
|
226
|
-
})(),
|
|
581
|
+
})(), g);
|
|
227
582
|
}
|
|
228
|
-
async function
|
|
229
|
-
const
|
|
230
|
-
if (
|
|
583
|
+
async function P(t, a, r) {
|
|
584
|
+
const e = j(r), s = await I(e);
|
|
585
|
+
if (s)
|
|
231
586
|
try {
|
|
232
|
-
return
|
|
587
|
+
return s.highlight(t, a);
|
|
233
588
|
} catch (i) {
|
|
234
589
|
console.warn("Host highlight failed, falling back to JS:", i);
|
|
235
590
|
}
|
|
236
|
-
const
|
|
237
|
-
if (!
|
|
238
|
-
return
|
|
239
|
-
const
|
|
240
|
-
return
|
|
591
|
+
const n = await w(t, e);
|
|
592
|
+
if (!n)
|
|
593
|
+
return u(a);
|
|
594
|
+
const o = n.parse(a);
|
|
595
|
+
return y(a, o.spans);
|
|
241
596
|
}
|
|
242
|
-
async function
|
|
243
|
-
const
|
|
244
|
-
if (!
|
|
245
|
-
const { module:
|
|
597
|
+
async function A(t, a) {
|
|
598
|
+
const r = j(a), e = await w(t, r);
|
|
599
|
+
if (!e) return null;
|
|
600
|
+
const { module: s } = e;
|
|
246
601
|
return {
|
|
247
|
-
languageId: () =>
|
|
248
|
-
injectionLanguages: () =>
|
|
249
|
-
highlight: async (
|
|
250
|
-
const
|
|
251
|
-
return
|
|
602
|
+
languageId: () => e.languageId,
|
|
603
|
+
injectionLanguages: () => e.injectionLanguages,
|
|
604
|
+
highlight: async (n) => {
|
|
605
|
+
const o = e.parse(n);
|
|
606
|
+
return y(n, o.spans);
|
|
252
607
|
},
|
|
253
|
-
parse: (
|
|
608
|
+
parse: (n) => e.parse(n),
|
|
254
609
|
createSession: () => {
|
|
255
|
-
const
|
|
610
|
+
const n = s.create_session();
|
|
256
611
|
return {
|
|
257
|
-
setText: (
|
|
612
|
+
setText: (o) => s.set_text(n, o),
|
|
258
613
|
parse: () => {
|
|
259
614
|
try {
|
|
260
|
-
const
|
|
615
|
+
const o = s.parse(n);
|
|
261
616
|
return {
|
|
262
|
-
spans:
|
|
263
|
-
injections:
|
|
617
|
+
spans: o.spans || [],
|
|
618
|
+
injections: o.injections || []
|
|
264
619
|
};
|
|
265
|
-
} catch (
|
|
266
|
-
return console.error("[arborium] Session parse error:",
|
|
620
|
+
} catch (o) {
|
|
621
|
+
return console.error("[arborium] Session parse error:", o), { spans: [], injections: [] };
|
|
267
622
|
}
|
|
268
623
|
},
|
|
269
|
-
cancel: () =>
|
|
270
|
-
free: () =>
|
|
624
|
+
cancel: () => s.cancel(n),
|
|
625
|
+
free: () => s.free_session(n)
|
|
271
626
|
};
|
|
272
627
|
},
|
|
273
628
|
dispose: () => {
|
|
274
629
|
}
|
|
275
630
|
};
|
|
276
631
|
}
|
|
277
|
-
function
|
|
278
|
-
|
|
279
|
-
let n = "", a = 0;
|
|
280
|
-
for (const r of t) {
|
|
281
|
-
if (r.start < a) continue;
|
|
282
|
-
r.start > a && (n += h(s.slice(a, r.start)));
|
|
283
|
-
const i = C(r.capture), c = h(s.slice(r.start, r.end));
|
|
284
|
-
i ? n += `<a-${i}>${c}</a-${i}>` : n += c, a = r.end;
|
|
285
|
-
}
|
|
286
|
-
return a < s.length && (n += h(s.slice(a))), n;
|
|
287
|
-
}
|
|
288
|
-
function C(s) {
|
|
289
|
-
return s.startsWith("keyword") || s === "include" || s === "conditional" ? "k" : s.startsWith("function") || s.startsWith("method") ? "f" : s.startsWith("string") || s === "character" ? "s" : s.startsWith("comment") ? "c" : s.startsWith("type") ? "t" : s.startsWith("variable") ? "v" : s.startsWith("number") || s === "float" ? "n" : s.startsWith("operator") ? "o" : s.startsWith("punctuation") ? "p" : s.startsWith("tag") ? "tg" : s.startsWith("attribute") ? "at" : null;
|
|
290
|
-
}
|
|
291
|
-
function h(s) {
|
|
292
|
-
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
632
|
+
function j(t) {
|
|
633
|
+
return t ? { ...d, ...t } : { ...d };
|
|
293
634
|
}
|
|
294
|
-
function
|
|
295
|
-
|
|
635
|
+
function G(t) {
|
|
636
|
+
d = { ...d, ...t };
|
|
296
637
|
}
|
|
297
|
-
const
|
|
638
|
+
const R = [
|
|
298
639
|
[/^#!.*\bpython[23]?\b/, "python"],
|
|
299
640
|
[/^#!.*\bnode\b/, "javascript"],
|
|
300
641
|
[/^#!.*\bdeno\b/, "typescript"],
|
|
@@ -307,7 +648,7 @@ const I = [
|
|
|
307
648
|
[/^#!.*\bsh\b/, "bash"],
|
|
308
649
|
[/^#!.*\blua\b/, "lua"],
|
|
309
650
|
[/^#!.*\bawk\b/, "awk"]
|
|
310
|
-
],
|
|
651
|
+
], H = [
|
|
311
652
|
// Rust - distinctive keywords
|
|
312
653
|
[/\b(fn|impl|trait|pub\s+fn|let\s+mut|&mut|->)\b/, "rust"],
|
|
313
654
|
// Go - distinctive keywords
|
|
@@ -367,23 +708,23 @@ const I = [
|
|
|
367
708
|
// Zig
|
|
368
709
|
[/\b(pub\s+fn|const\s+\w+\s*=|@import\(|comptime)\b/, "zig"]
|
|
369
710
|
];
|
|
370
|
-
function
|
|
371
|
-
const
|
|
711
|
+
function F(t) {
|
|
712
|
+
const a = t.split(`
|
|
372
713
|
`)[0];
|
|
373
|
-
for (const [
|
|
374
|
-
if (
|
|
375
|
-
return
|
|
376
|
-
for (const [
|
|
377
|
-
if (
|
|
378
|
-
return
|
|
714
|
+
for (const [r, e] of R)
|
|
715
|
+
if (r.test(a))
|
|
716
|
+
return e;
|
|
717
|
+
for (const [r, e] of H)
|
|
718
|
+
if (r.test(t))
|
|
719
|
+
return e;
|
|
379
720
|
return null;
|
|
380
721
|
}
|
|
381
|
-
function
|
|
382
|
-
const
|
|
383
|
-
if (
|
|
384
|
-
const
|
|
385
|
-
if (
|
|
386
|
-
const
|
|
722
|
+
function O(t) {
|
|
723
|
+
const a = t.match(/\blanguage-(\w+)\b/);
|
|
724
|
+
if (a) return a[1];
|
|
725
|
+
const r = t.match(/\blang-(\w+)\b/);
|
|
726
|
+
if (r) return r[1];
|
|
727
|
+
const e = /* @__PURE__ */ new Set([
|
|
387
728
|
"rust",
|
|
388
729
|
"javascript",
|
|
389
730
|
"typescript",
|
|
@@ -419,13 +760,13 @@ function A(s) {
|
|
|
419
760
|
"console",
|
|
420
761
|
"sh"
|
|
421
762
|
]);
|
|
422
|
-
for (const
|
|
423
|
-
if (
|
|
424
|
-
return
|
|
763
|
+
for (const s of t.split(/\s+/))
|
|
764
|
+
if (e.has(s.toLowerCase()))
|
|
765
|
+
return s.toLowerCase();
|
|
425
766
|
return null;
|
|
426
767
|
}
|
|
427
|
-
function
|
|
428
|
-
const
|
|
768
|
+
function z(t) {
|
|
769
|
+
const a = {
|
|
429
770
|
js: "javascript",
|
|
430
771
|
ts: "typescript",
|
|
431
772
|
py: "python",
|
|
@@ -445,18 +786,20 @@ function G(s) {
|
|
|
445
786
|
plaintext: "text",
|
|
446
787
|
plain: "text",
|
|
447
788
|
txt: "text"
|
|
448
|
-
},
|
|
449
|
-
return
|
|
789
|
+
}, r = t.toLowerCase();
|
|
790
|
+
return a[r] || r;
|
|
450
791
|
}
|
|
451
792
|
export {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
793
|
+
_ as availableLanguages,
|
|
794
|
+
F as detectLanguage,
|
|
795
|
+
O as extractLanguageFromClass,
|
|
796
|
+
j as getConfig,
|
|
797
|
+
P as highlight,
|
|
798
|
+
M as highlights,
|
|
799
|
+
A as loadGrammar,
|
|
800
|
+
z as normalizeLanguage,
|
|
801
|
+
L as pluginVersion,
|
|
802
|
+
G as setConfig,
|
|
803
|
+
y as spansToHtml
|
|
461
804
|
};
|
|
462
805
|
//# sourceMappingURL=arborium.js.map
|