@arborium/arborium 2.10.0 → 2.12.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 +293 -297
- package/dist/arborium.js.map +1 -1
- package/dist/arborium_host.js +3 -3
- package/dist/arborium_host_bg.wasm +0 -0
- package/dist/loader.d.ts +0 -1
- package/dist/plugins-manifest.d.ts +1 -1
- package/dist/types.d.ts +80 -15
- package/dist/utils.d.ts +0 -14
- package/package.json +1 -1
- /package/dist/{loader.test.d.ts → highlight.test.d.ts} +0 -0
package/dist/arborium.js
CHANGED
|
@@ -1,4 +1,158 @@
|
|
|
1
|
-
const
|
|
1
|
+
const L = [
|
|
2
|
+
[/^#!.*\bpython[23]?\b/, "python"],
|
|
3
|
+
[/^#!.*\bnode\b/, "javascript"],
|
|
4
|
+
[/^#!.*\bdeno\b/, "typescript"],
|
|
5
|
+
[/^#!.*\bbun\b/, "typescript"],
|
|
6
|
+
[/^#!.*\bruby\b/, "ruby"],
|
|
7
|
+
[/^#!.*\bperl\b/, "perl"],
|
|
8
|
+
[/^#!.*\bphp\b/, "php"],
|
|
9
|
+
[/^#!.*\bbash\b/, "bash"],
|
|
10
|
+
[/^#!.*\bzsh\b/, "zsh"],
|
|
11
|
+
[/^#!.*\bsh\b/, "bash"],
|
|
12
|
+
[/^#!.*\blua\b/, "lua"],
|
|
13
|
+
[/^#!.*\bawk\b/, "awk"]
|
|
14
|
+
], $ = [
|
|
15
|
+
// Rust - distinctive keywords
|
|
16
|
+
[/\b(fn|impl|trait|pub\s+fn|let\s+mut|&mut|->)\b/, "rust"],
|
|
17
|
+
// Go - distinctive keywords
|
|
18
|
+
[/\b(func|package\s+\w+|import\s+\(|go\s+func|chan\s+\w+)\b/, "go"],
|
|
19
|
+
// Python - distinctive patterns
|
|
20
|
+
[/\b(def\s+\w+\s*\(|import\s+\w+|from\s+\w+\s+import|class\s+\w+:)\b/, "python"],
|
|
21
|
+
// TypeScript - distinctive type annotations
|
|
22
|
+
[/:\s*(string|number|boolean|void)\b|\binterface\s+\w+\s*\{/, "typescript"],
|
|
23
|
+
// JavaScript - distinctive patterns (after TS check)
|
|
24
|
+
[/\b(const|let|var)\s+\w+\s*=|function\s+\w+\s*\(|=>\s*\{/, "javascript"],
|
|
25
|
+
// Ruby - distinctive keywords
|
|
26
|
+
[/\b(def\s+\w+|end\b|do\s*\|.*\||puts\s+|require\s+['"])\b/, "ruby"],
|
|
27
|
+
// Java - distinctive patterns
|
|
28
|
+
[/\b(public\s+class|private\s+\w+|System\.out\.println)\b/, "java"],
|
|
29
|
+
// C++ - distinctive patterns
|
|
30
|
+
[/\b(#include\s*<|std::|template\s*<|nullptr|cout\s*<<)\b/, "cpp"],
|
|
31
|
+
// C - distinctive patterns (after C++ check)
|
|
32
|
+
[/\b(#include\s*[<"]|printf\s*\(|int\s+main\s*\(|void\s+\w+\s*\()\b/, "c"],
|
|
33
|
+
// C# - distinctive patterns
|
|
34
|
+
[/\b(namespace\s+\w+|using\s+System|public\s+static\s+void)\b/, "c-sharp"],
|
|
35
|
+
// PHP - distinctive patterns
|
|
36
|
+
[/<\?php|\$\w+\s*=/, "php"],
|
|
37
|
+
// Swift - distinctive patterns
|
|
38
|
+
[/\b(func\s+\w+|var\s+\w+:\s*\w+|let\s+\w+:\s*\w+|@objc)\b/, "swift"],
|
|
39
|
+
// Kotlin - distinctive patterns
|
|
40
|
+
[/\b(fun\s+\w+|val\s+\w+|var\s+\w+:|data\s+class)\b/, "kotlin"],
|
|
41
|
+
// Scala - distinctive patterns
|
|
42
|
+
[/\b(def\s+\w+|val\s+\w+|var\s+\w+|object\s+\w+|case\s+class)\b/, "scala"],
|
|
43
|
+
// Haskell - distinctive patterns
|
|
44
|
+
[/\b(module\s+\w+|import\s+qualified|data\s+\w+\s*=|::\s*\w+\s*->)\b/, "haskell"],
|
|
45
|
+
// Elixir - distinctive patterns
|
|
46
|
+
[/\b(defmodule\s+\w+|def\s+\w+|defp\s+\w+|\|>)\b/, "elixir"],
|
|
47
|
+
// Lua - distinctive patterns
|
|
48
|
+
[/\b(local\s+\w+\s*=|function\s+\w+\.\w+|require\s*\()\b/, "lua"],
|
|
49
|
+
// SQL - distinctive patterns
|
|
50
|
+
[/\b(SELECT\s+.*\s+FROM|INSERT\s+INTO|CREATE\s+TABLE|ALTER\s+TABLE)\b/i, "sql"],
|
|
51
|
+
// Shell/Bash - distinctive patterns
|
|
52
|
+
[/\b(if\s+\[\s*|then\b|fi\b|echo\s+["']|export\s+\w+=)\b/, "bash"],
|
|
53
|
+
// YAML - distinctive patterns
|
|
54
|
+
[/^\s*[\w-]+:\s*[\w\-"'[{]|^---\s*$/, "yaml"],
|
|
55
|
+
// JSON - distinctive patterns
|
|
56
|
+
[/^\s*\{[\s\S]*"[\w-]+":\s*/, "json"],
|
|
57
|
+
// TOML - distinctive patterns
|
|
58
|
+
[/^\s*\[[\w.-]+\]\s*$|^\s*\w+\s*=\s*["'\d\[]/, "toml"],
|
|
59
|
+
// HTML - distinctive patterns
|
|
60
|
+
[/<(!DOCTYPE|html|head|body|div|span|p|a\s)/i, "html"],
|
|
61
|
+
// CSS - distinctive patterns
|
|
62
|
+
[/^\s*[\w.#@][\w\s,#.:>+~-]*\{[^}]*\}|@media\s|@import\s/, "css"],
|
|
63
|
+
// Markdown - distinctive patterns
|
|
64
|
+
[/^#{1,6}\s+\w|^\s*[-*+]\s+\w|^\s*\d+\.\s+\w|```\w*\n/, "markdown"],
|
|
65
|
+
// XML - distinctive patterns
|
|
66
|
+
[/<\?xml|<[\w:-]+\s+xmlns/, "xml"],
|
|
67
|
+
// Dockerfile
|
|
68
|
+
[/^FROM\s+\w+|^RUN\s+|^COPY\s+|^ENTRYPOINT\s+/m, "dockerfile"],
|
|
69
|
+
// Nginx config
|
|
70
|
+
[/\b(server\s*\{|location\s+[\/~]|proxy_pass\s+)\b/, "nginx"],
|
|
71
|
+
// Zig
|
|
72
|
+
[/\b(pub\s+fn|const\s+\w+\s*=|@import\(|comptime)\b/, "zig"]
|
|
73
|
+
];
|
|
74
|
+
function M(e) {
|
|
75
|
+
const t = e.split(`
|
|
76
|
+
`)[0];
|
|
77
|
+
for (const [a, s] of L)
|
|
78
|
+
if (a.test(t))
|
|
79
|
+
return s;
|
|
80
|
+
for (const [a, s] of $)
|
|
81
|
+
if (a.test(e))
|
|
82
|
+
return s;
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
function R(e) {
|
|
86
|
+
const t = e.match(/\blanguage-(\w+)\b/);
|
|
87
|
+
if (t) return t[1];
|
|
88
|
+
const a = e.match(/\blang-(\w+)\b/);
|
|
89
|
+
if (a) return a[1];
|
|
90
|
+
const s = /* @__PURE__ */ new Set([
|
|
91
|
+
"rust",
|
|
92
|
+
"javascript",
|
|
93
|
+
"typescript",
|
|
94
|
+
"python",
|
|
95
|
+
"ruby",
|
|
96
|
+
"go",
|
|
97
|
+
"java",
|
|
98
|
+
"c",
|
|
99
|
+
"cpp",
|
|
100
|
+
"csharp",
|
|
101
|
+
"php",
|
|
102
|
+
"swift",
|
|
103
|
+
"kotlin",
|
|
104
|
+
"scala",
|
|
105
|
+
"haskell",
|
|
106
|
+
"elixir",
|
|
107
|
+
"lua",
|
|
108
|
+
"sql",
|
|
109
|
+
"bash",
|
|
110
|
+
"shell",
|
|
111
|
+
"yaml",
|
|
112
|
+
"json",
|
|
113
|
+
"toml",
|
|
114
|
+
"html",
|
|
115
|
+
"css",
|
|
116
|
+
"xml",
|
|
117
|
+
"markdown",
|
|
118
|
+
"dockerfile",
|
|
119
|
+
"nginx",
|
|
120
|
+
"zig",
|
|
121
|
+
"text",
|
|
122
|
+
"plaintext",
|
|
123
|
+
"console",
|
|
124
|
+
"sh"
|
|
125
|
+
]);
|
|
126
|
+
for (const n of e.split(/\s+/))
|
|
127
|
+
if (s.has(n.toLowerCase()))
|
|
128
|
+
return n.toLowerCase();
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
function H(e) {
|
|
132
|
+
const t = {
|
|
133
|
+
js: "javascript",
|
|
134
|
+
ts: "typescript",
|
|
135
|
+
py: "python",
|
|
136
|
+
rb: "ruby",
|
|
137
|
+
rs: "rust",
|
|
138
|
+
sh: "bash",
|
|
139
|
+
shell: "bash",
|
|
140
|
+
yml: "yaml",
|
|
141
|
+
cs: "c-sharp",
|
|
142
|
+
csharp: "c-sharp",
|
|
143
|
+
"c++": "cpp",
|
|
144
|
+
"c#": "c-sharp",
|
|
145
|
+
"f#": "fsharp",
|
|
146
|
+
dockerfile: "dockerfile",
|
|
147
|
+
docker: "dockerfile",
|
|
148
|
+
makefile: "make",
|
|
149
|
+
plaintext: "text",
|
|
150
|
+
plain: "text",
|
|
151
|
+
txt: "text"
|
|
152
|
+
}, a = e.toLowerCase();
|
|
153
|
+
return t[a] || a;
|
|
154
|
+
}
|
|
155
|
+
const _ = "2.12.0", U = [
|
|
2
156
|
"ada",
|
|
3
157
|
"agda",
|
|
4
158
|
"asciidoc",
|
|
@@ -78,6 +232,7 @@ const U = "2.10.0", _ = [
|
|
|
78
232
|
"sql",
|
|
79
233
|
"ssh-config",
|
|
80
234
|
"starlark",
|
|
235
|
+
"styx",
|
|
81
236
|
"svelte",
|
|
82
237
|
"swift",
|
|
83
238
|
"textproto",
|
|
@@ -100,7 +255,7 @@ const U = "2.10.0", _ = [
|
|
|
100
255
|
"yuri",
|
|
101
256
|
"zig",
|
|
102
257
|
"zsh"
|
|
103
|
-
],
|
|
258
|
+
], F = [
|
|
104
259
|
{
|
|
105
260
|
name: "attribute",
|
|
106
261
|
tag: "at"
|
|
@@ -433,215 +588,201 @@ const U = "2.10.0", _ = [
|
|
|
433
588
|
name: "boolean",
|
|
434
589
|
tag: "cb"
|
|
435
590
|
}
|
|
436
|
-
]
|
|
437
|
-
function E(
|
|
438
|
-
|
|
439
|
-
let s = 0, n = 0;
|
|
440
|
-
for (const r of t) {
|
|
441
|
-
a[s] = n;
|
|
442
|
-
const o = T.encode(r).length;
|
|
443
|
-
for (let i = 1; i < o; i++)
|
|
444
|
-
a[s + i] = n;
|
|
445
|
-
s += o, n += r.codePointAt(0) >= 65536 ? 2 : 1;
|
|
446
|
-
}
|
|
447
|
-
return a[s] = n, a;
|
|
448
|
-
}
|
|
449
|
-
function x(t, e) {
|
|
450
|
-
const a = E(t), n = [...e.map((i) => ({
|
|
451
|
-
...i,
|
|
452
|
-
start: a[i.start] ?? i.start,
|
|
453
|
-
end: a[i.end] ?? i.end
|
|
454
|
-
}))].sort((i, l) => i.start - l.start);
|
|
455
|
-
let r = "", o = 0;
|
|
456
|
-
for (const i of n) {
|
|
457
|
-
if (i.start < o) continue;
|
|
458
|
-
i.start > o && (r += f(t.slice(o, i.start)));
|
|
459
|
-
const l = S(i.capture), m = f(t.slice(i.start, i.end));
|
|
460
|
-
l ? r += `<a-${l}>${m}</a-${l}>` : r += m, o = i.end;
|
|
461
|
-
}
|
|
462
|
-
return o < t.length && (r += f(t.slice(o))), r;
|
|
463
|
-
}
|
|
464
|
-
function S(t) {
|
|
465
|
-
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;
|
|
466
|
-
}
|
|
467
|
-
function f(t) {
|
|
468
|
-
return t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
591
|
+
];
|
|
592
|
+
function E(e) {
|
|
593
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
469
594
|
}
|
|
470
|
-
const
|
|
595
|
+
const T = {
|
|
471
596
|
manual: !1,
|
|
472
597
|
theme: "one-dark",
|
|
473
598
|
selector: "pre code",
|
|
474
599
|
cdn: "jsdelivr",
|
|
475
|
-
version:
|
|
600
|
+
version: _,
|
|
476
601
|
// Precise version from manifest
|
|
477
602
|
pluginsUrl: "",
|
|
478
603
|
// Empty means use bundled manifest
|
|
479
604
|
hostUrl: "",
|
|
480
605
|
// Empty means use CDN based on version
|
|
481
|
-
resolveJs: ({ baseUrl:
|
|
606
|
+
resolveJs: ({ baseUrl: e, path: t }) => import(
|
|
482
607
|
/* @vite-ignore */
|
|
483
|
-
`${
|
|
608
|
+
`${e}/${t}`
|
|
484
609
|
),
|
|
485
|
-
resolveWasm: ({ baseUrl:
|
|
610
|
+
resolveWasm: ({ baseUrl: e, path: t }) => fetch(`${e}/${t}`)
|
|
486
611
|
};
|
|
487
|
-
let
|
|
488
|
-
const
|
|
489
|
-
let
|
|
490
|
-
async function
|
|
491
|
-
if (
|
|
492
|
-
return
|
|
493
|
-
console.debug(`[arborium] Loading local plugins manifest from: ${
|
|
494
|
-
const
|
|
495
|
-
if (!
|
|
496
|
-
throw new Error(`Failed to load plugins.json: ${
|
|
497
|
-
|
|
498
|
-
})(),
|
|
612
|
+
let p = null, m = null, g = { ...T };
|
|
613
|
+
const y = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), d = new Set(U);
|
|
614
|
+
let l = null, u = null;
|
|
615
|
+
async function k(e) {
|
|
616
|
+
if (e.pluginsUrl)
|
|
617
|
+
return u || (u = (async () => {
|
|
618
|
+
console.debug(`[arborium] Loading local plugins manifest from: ${e.pluginsUrl}`);
|
|
619
|
+
const t = await fetch(e.pluginsUrl);
|
|
620
|
+
if (!t.ok)
|
|
621
|
+
throw new Error(`Failed to load plugins.json: ${t.status}`);
|
|
622
|
+
l = await t.json(), console.debug(`[arborium] Loaded local manifest with ${l?.entries.length} entries`);
|
|
623
|
+
})(), u);
|
|
499
624
|
}
|
|
500
|
-
function
|
|
501
|
-
if (
|
|
502
|
-
const r =
|
|
625
|
+
function P(e, t) {
|
|
626
|
+
if (l) {
|
|
627
|
+
const r = l.entries.find((o) => o.language === e);
|
|
503
628
|
if (r)
|
|
504
629
|
return r.local_js.substring(0, r.local_js.lastIndexOf("/"));
|
|
505
630
|
}
|
|
506
|
-
const a =
|
|
631
|
+
const a = t.cdn, s = t.version;
|
|
507
632
|
let n;
|
|
508
|
-
return a === "jsdelivr" ? n = "https://cdn.jsdelivr.net/npm" : a === "unpkg" ? n = "https://unpkg.com" : n = a, `${n}/@arborium/${
|
|
633
|
+
return a === "jsdelivr" ? n = "https://cdn.jsdelivr.net/npm" : a === "unpkg" ? n = "https://unpkg.com" : n = a, `${n}/@arborium/${e}@${s}`;
|
|
509
634
|
}
|
|
510
|
-
async function
|
|
511
|
-
const a =
|
|
635
|
+
async function j(e, t) {
|
|
636
|
+
const a = y.get(e);
|
|
512
637
|
if (a)
|
|
513
|
-
return console.debug(`[arborium] Grammar '${
|
|
514
|
-
const s =
|
|
638
|
+
return console.debug(`[arborium] Grammar '${e}' found in cache`), a;
|
|
639
|
+
const s = h.get(e);
|
|
515
640
|
if (s)
|
|
516
|
-
return console.debug(`[arborium] Grammar '${
|
|
517
|
-
const n =
|
|
518
|
-
|
|
641
|
+
return console.debug(`[arborium] Grammar '${e}' already loading, waiting...`), s;
|
|
642
|
+
const n = q(e, t);
|
|
643
|
+
h.set(e, n);
|
|
519
644
|
try {
|
|
520
645
|
return await n;
|
|
521
646
|
} finally {
|
|
522
|
-
|
|
647
|
+
h.delete(e);
|
|
523
648
|
}
|
|
524
649
|
}
|
|
525
|
-
async function
|
|
526
|
-
if (await
|
|
527
|
-
return console.debug(`[arborium] Grammar '${
|
|
650
|
+
async function q(e, t) {
|
|
651
|
+
if (await k(t), !d.has(e) && !l?.entries.some((a) => a.language === e))
|
|
652
|
+
return console.debug(`[arborium] Grammar '${e}' not available`), null;
|
|
528
653
|
try {
|
|
529
|
-
const a =
|
|
530
|
-
console.debug(`[arborium] Loading grammar '${
|
|
531
|
-
const n = await
|
|
654
|
+
const a = P(e, t), s = t.resolveJs === T.resolveJs ? ` from ${a}/grammar.js` : "";
|
|
655
|
+
console.debug(`[arborium] Loading grammar '${e}'${s}`);
|
|
656
|
+
const n = await t.resolveJs({
|
|
657
|
+
language: e,
|
|
658
|
+
baseUrl: a,
|
|
659
|
+
path: "grammar.js"
|
|
660
|
+
}), r = await t.resolveWasm({ language: e, baseUrl: a, path: "grammar_bg.wasm" });
|
|
532
661
|
await n.default({ module_or_path: r });
|
|
533
662
|
const o = n.language_id();
|
|
534
|
-
o !==
|
|
535
|
-
const
|
|
536
|
-
languageId:
|
|
537
|
-
injectionLanguages:
|
|
663
|
+
o !== e && console.warn(`[arborium] Language ID mismatch: expected '${e}', got '${o}'`);
|
|
664
|
+
const x = n.injection_languages(), v = {
|
|
665
|
+
languageId: e,
|
|
666
|
+
injectionLanguages: x,
|
|
538
667
|
module: n,
|
|
539
|
-
|
|
540
|
-
|
|
668
|
+
// UTF-8 parsing for Rust host
|
|
669
|
+
parseUtf8: (f) => {
|
|
670
|
+
const c = n.create_session();
|
|
541
671
|
try {
|
|
542
|
-
n.set_text(
|
|
543
|
-
const
|
|
672
|
+
n.set_text(c, f);
|
|
673
|
+
const i = n.parse(c);
|
|
544
674
|
return {
|
|
545
|
-
spans:
|
|
546
|
-
injections:
|
|
675
|
+
spans: i.spans || [],
|
|
676
|
+
injections: i.injections || []
|
|
547
677
|
};
|
|
548
|
-
} catch (
|
|
549
|
-
return console.error("[arborium] Parse error:",
|
|
678
|
+
} catch (i) {
|
|
679
|
+
return console.error("[arborium] Parse error:", i), { spans: [], injections: [] };
|
|
550
680
|
} finally {
|
|
551
|
-
n.free_session(
|
|
681
|
+
n.free_session(c);
|
|
682
|
+
}
|
|
683
|
+
},
|
|
684
|
+
// UTF-16 parsing for JavaScript public API
|
|
685
|
+
parseUtf16: (f) => {
|
|
686
|
+
const c = n.create_session();
|
|
687
|
+
try {
|
|
688
|
+
n.set_text(c, f);
|
|
689
|
+
const i = n.parse_utf16(c);
|
|
690
|
+
return {
|
|
691
|
+
spans: i.spans || [],
|
|
692
|
+
injections: i.injections || []
|
|
693
|
+
};
|
|
694
|
+
} catch (i) {
|
|
695
|
+
return console.error("[arborium] Parse error:", i), { spans: [], injections: [] };
|
|
696
|
+
} finally {
|
|
697
|
+
n.free_session(c);
|
|
552
698
|
}
|
|
553
699
|
}
|
|
554
700
|
};
|
|
555
|
-
return
|
|
701
|
+
return y.set(e, v), console.debug(`[arborium] Grammar '${e}' loaded successfully`), v;
|
|
556
702
|
} catch (a) {
|
|
557
|
-
return console.error(`[arborium] Failed to load grammar '${
|
|
703
|
+
return console.error(`[arborium] Failed to load grammar '${e}':`, a), null;
|
|
558
704
|
}
|
|
559
705
|
}
|
|
560
|
-
const
|
|
561
|
-
let
|
|
562
|
-
function
|
|
706
|
+
const w = /* @__PURE__ */ new Map();
|
|
707
|
+
let C = 1;
|
|
708
|
+
function I(e) {
|
|
563
709
|
window.arboriumHost = {
|
|
564
710
|
/** Check if a language is available (sync) */
|
|
565
|
-
isLanguageAvailable(
|
|
566
|
-
return
|
|
711
|
+
isLanguageAvailable(t) {
|
|
712
|
+
return d.has(t) || y.has(t);
|
|
567
713
|
},
|
|
568
714
|
/** Load a grammar and return a handle (async) */
|
|
569
|
-
async loadGrammar(
|
|
570
|
-
const a = await
|
|
715
|
+
async loadGrammar(t) {
|
|
716
|
+
const a = await j(t, e);
|
|
571
717
|
if (!a) return 0;
|
|
572
|
-
for (const [n, r] of
|
|
718
|
+
for (const [n, r] of w)
|
|
573
719
|
if (r === a) return n;
|
|
574
|
-
const s =
|
|
575
|
-
return
|
|
720
|
+
const s = C++;
|
|
721
|
+
return w.set(s, a), s;
|
|
576
722
|
},
|
|
577
|
-
/** Parse text using a grammar handle (sync) */
|
|
578
|
-
parse(
|
|
579
|
-
const s =
|
|
580
|
-
return s ? s.
|
|
723
|
+
/** Parse text using a grammar handle (sync) - returns UTF-8 offsets for Rust host */
|
|
724
|
+
parse(t, a) {
|
|
725
|
+
const s = w.get(t);
|
|
726
|
+
return s ? s.parseUtf8(a) : { spans: [], injections: [] };
|
|
581
727
|
}
|
|
582
728
|
};
|
|
583
729
|
}
|
|
584
|
-
function
|
|
585
|
-
if (
|
|
586
|
-
return
|
|
587
|
-
const
|
|
730
|
+
function S(e) {
|
|
731
|
+
if (e.hostUrl)
|
|
732
|
+
return e.hostUrl;
|
|
733
|
+
const t = e.cdn, a = e.version;
|
|
588
734
|
let s;
|
|
589
|
-
|
|
735
|
+
t === "jsdelivr" ? s = "https://cdn.jsdelivr.net/npm" : t === "unpkg" ? s = "https://unpkg.com" : s = t;
|
|
590
736
|
const n = a === "latest" ? "" : `@${a}`;
|
|
591
737
|
return `${s}/@arborium/arborium${n}/dist`;
|
|
592
738
|
}
|
|
593
|
-
async function A(
|
|
594
|
-
return
|
|
595
|
-
|
|
596
|
-
const
|
|
739
|
+
async function A(e) {
|
|
740
|
+
return p || m || (m = (async () => {
|
|
741
|
+
I(e);
|
|
742
|
+
const t = S(e), a = `${t}/arborium_host.js`, s = `${t}/arborium_host_bg.wasm`;
|
|
597
743
|
console.debug(`[arborium] Loading host from ${a}`);
|
|
598
744
|
try {
|
|
599
745
|
const n = await import(
|
|
600
746
|
/* @vite-ignore */
|
|
601
747
|
a
|
|
602
748
|
);
|
|
603
|
-
return await n.default(s),
|
|
749
|
+
return await n.default(s), p = {
|
|
604
750
|
highlight: n.highlight,
|
|
605
751
|
isLanguageAvailable: n.isLanguageAvailable
|
|
606
|
-
}, console.debug("[arborium] Host loaded successfully"),
|
|
752
|
+
}, console.debug("[arborium] Host loaded successfully"), p;
|
|
607
753
|
} catch (n) {
|
|
608
754
|
return console.error("[arborium] Failed to load host:", n), null;
|
|
609
755
|
}
|
|
610
|
-
})(),
|
|
756
|
+
})(), m);
|
|
611
757
|
}
|
|
612
|
-
async function
|
|
613
|
-
const s =
|
|
758
|
+
async function G(e, t, a) {
|
|
759
|
+
const s = b(a), n = await A(s);
|
|
614
760
|
if (n)
|
|
615
761
|
try {
|
|
616
|
-
return n.highlight(
|
|
617
|
-
} catch (
|
|
618
|
-
console.
|
|
762
|
+
return n.highlight(e, t);
|
|
763
|
+
} catch (r) {
|
|
764
|
+
console.error("[arborium] Host highlight failed:", r);
|
|
619
765
|
}
|
|
620
|
-
|
|
621
|
-
if (!r)
|
|
622
|
-
return f(e);
|
|
623
|
-
const o = r.parse(e);
|
|
624
|
-
return x(e, o.spans);
|
|
766
|
+
return E(t);
|
|
625
767
|
}
|
|
626
|
-
async function
|
|
627
|
-
const a =
|
|
768
|
+
async function z(e, t) {
|
|
769
|
+
const a = b(t), s = await j(e, a);
|
|
628
770
|
if (!s) return null;
|
|
629
771
|
const { module: n } = s;
|
|
630
772
|
return {
|
|
631
773
|
languageId: () => s.languageId,
|
|
632
774
|
injectionLanguages: () => s.injectionLanguages,
|
|
633
|
-
highlight: async (r) =>
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
},
|
|
637
|
-
parse: (r) => s.parse(r),
|
|
775
|
+
highlight: async (r) => G(e, r, t),
|
|
776
|
+
// Public API returns UTF-16 offsets for JavaScript compatibility
|
|
777
|
+
parse: (r) => s.parseUtf16(r),
|
|
638
778
|
createSession: () => {
|
|
639
779
|
const r = n.create_session();
|
|
640
780
|
return {
|
|
641
781
|
setText: (o) => n.set_text(r, o),
|
|
782
|
+
// Session.parse() returns UTF-16 offsets for JavaScript compatibility
|
|
642
783
|
parse: () => {
|
|
643
784
|
try {
|
|
644
|
-
const o = n.
|
|
785
|
+
const o = n.parse_utf16(r);
|
|
645
786
|
return {
|
|
646
787
|
spans: o.spans || [],
|
|
647
788
|
injections: o.injections || []
|
|
@@ -658,177 +799,32 @@ async function O(t, e) {
|
|
|
658
799
|
}
|
|
659
800
|
};
|
|
660
801
|
}
|
|
661
|
-
function
|
|
662
|
-
return
|
|
802
|
+
function b(e) {
|
|
803
|
+
return e ? { ...g, ...e } : { ...g };
|
|
663
804
|
}
|
|
664
|
-
function
|
|
665
|
-
|
|
666
|
-
}
|
|
667
|
-
const G = [
|
|
668
|
-
[/^#!.*\bpython[23]?\b/, "python"],
|
|
669
|
-
[/^#!.*\bnode\b/, "javascript"],
|
|
670
|
-
[/^#!.*\bdeno\b/, "typescript"],
|
|
671
|
-
[/^#!.*\bbun\b/, "typescript"],
|
|
672
|
-
[/^#!.*\bruby\b/, "ruby"],
|
|
673
|
-
[/^#!.*\bperl\b/, "perl"],
|
|
674
|
-
[/^#!.*\bphp\b/, "php"],
|
|
675
|
-
[/^#!.*\bbash\b/, "bash"],
|
|
676
|
-
[/^#!.*\bzsh\b/, "zsh"],
|
|
677
|
-
[/^#!.*\bsh\b/, "bash"],
|
|
678
|
-
[/^#!.*\blua\b/, "lua"],
|
|
679
|
-
[/^#!.*\bawk\b/, "awk"]
|
|
680
|
-
], R = [
|
|
681
|
-
// Rust - distinctive keywords
|
|
682
|
-
[/\b(fn|impl|trait|pub\s+fn|let\s+mut|&mut|->)\b/, "rust"],
|
|
683
|
-
// Go - distinctive keywords
|
|
684
|
-
[/\b(func|package\s+\w+|import\s+\(|go\s+func|chan\s+\w+)\b/, "go"],
|
|
685
|
-
// Python - distinctive patterns
|
|
686
|
-
[/\b(def\s+\w+\s*\(|import\s+\w+|from\s+\w+\s+import|class\s+\w+:)\b/, "python"],
|
|
687
|
-
// TypeScript - distinctive type annotations
|
|
688
|
-
[/:\s*(string|number|boolean|void)\b|\binterface\s+\w+\s*\{/, "typescript"],
|
|
689
|
-
// JavaScript - distinctive patterns (after TS check)
|
|
690
|
-
[/\b(const|let|var)\s+\w+\s*=|function\s+\w+\s*\(|=>\s*\{/, "javascript"],
|
|
691
|
-
// Ruby - distinctive keywords
|
|
692
|
-
[/\b(def\s+\w+|end\b|do\s*\|.*\||puts\s+|require\s+['"])\b/, "ruby"],
|
|
693
|
-
// Java - distinctive patterns
|
|
694
|
-
[/\b(public\s+class|private\s+\w+|System\.out\.println)\b/, "java"],
|
|
695
|
-
// C++ - distinctive patterns
|
|
696
|
-
[/\b(#include\s*<|std::|template\s*<|nullptr|cout\s*<<)\b/, "cpp"],
|
|
697
|
-
// C - distinctive patterns (after C++ check)
|
|
698
|
-
[/\b(#include\s*[<"]|printf\s*\(|int\s+main\s*\(|void\s+\w+\s*\()\b/, "c"],
|
|
699
|
-
// C# - distinctive patterns
|
|
700
|
-
[/\b(namespace\s+\w+|using\s+System|public\s+static\s+void)\b/, "c-sharp"],
|
|
701
|
-
// PHP - distinctive patterns
|
|
702
|
-
[/<\?php|\$\w+\s*=/, "php"],
|
|
703
|
-
// Swift - distinctive patterns
|
|
704
|
-
[/\b(func\s+\w+|var\s+\w+:\s*\w+|let\s+\w+:\s*\w+|@objc)\b/, "swift"],
|
|
705
|
-
// Kotlin - distinctive patterns
|
|
706
|
-
[/\b(fun\s+\w+|val\s+\w+|var\s+\w+:|data\s+class)\b/, "kotlin"],
|
|
707
|
-
// Scala - distinctive patterns
|
|
708
|
-
[/\b(def\s+\w+|val\s+\w+|var\s+\w+|object\s+\w+|case\s+class)\b/, "scala"],
|
|
709
|
-
// Haskell - distinctive patterns
|
|
710
|
-
[/\b(module\s+\w+|import\s+qualified|data\s+\w+\s*=|::\s*\w+\s*->)\b/, "haskell"],
|
|
711
|
-
// Elixir - distinctive patterns
|
|
712
|
-
[/\b(defmodule\s+\w+|def\s+\w+|defp\s+\w+|\|>)\b/, "elixir"],
|
|
713
|
-
// Lua - distinctive patterns
|
|
714
|
-
[/\b(local\s+\w+\s*=|function\s+\w+\.\w+|require\s*\()\b/, "lua"],
|
|
715
|
-
// SQL - distinctive patterns
|
|
716
|
-
[/\b(SELECT\s+.*\s+FROM|INSERT\s+INTO|CREATE\s+TABLE|ALTER\s+TABLE)\b/i, "sql"],
|
|
717
|
-
// Shell/Bash - distinctive patterns
|
|
718
|
-
[/\b(if\s+\[\s*|then\b|fi\b|echo\s+["']|export\s+\w+=)\b/, "bash"],
|
|
719
|
-
// YAML - distinctive patterns
|
|
720
|
-
[/^\s*[\w-]+:\s*[\w\-"'[{]|^---\s*$/, "yaml"],
|
|
721
|
-
// JSON - distinctive patterns
|
|
722
|
-
[/^\s*\{[\s\S]*"[\w-]+":\s*/, "json"],
|
|
723
|
-
// TOML - distinctive patterns
|
|
724
|
-
[/^\s*\[[\w.-]+\]\s*$|^\s*\w+\s*=\s*["'\d\[]/, "toml"],
|
|
725
|
-
// HTML - distinctive patterns
|
|
726
|
-
[/<(!DOCTYPE|html|head|body|div|span|p|a\s)/i, "html"],
|
|
727
|
-
// CSS - distinctive patterns
|
|
728
|
-
[/^\s*[\w.#@][\w\s,#.:>+~-]*\{[^}]*\}|@media\s|@import\s/, "css"],
|
|
729
|
-
// Markdown - distinctive patterns
|
|
730
|
-
[/^#{1,6}\s+\w|^\s*[-*+]\s+\w|^\s*\d+\.\s+\w|```\w*\n/, "markdown"],
|
|
731
|
-
// XML - distinctive patterns
|
|
732
|
-
[/<\?xml|<[\w:-]+\s+xmlns/, "xml"],
|
|
733
|
-
// Dockerfile
|
|
734
|
-
[/^FROM\s+\w+|^RUN\s+|^COPY\s+|^ENTRYPOINT\s+/m, "dockerfile"],
|
|
735
|
-
// Nginx config
|
|
736
|
-
[/\b(server\s*\{|location\s+[\/~]|proxy_pass\s+)\b/, "nginx"],
|
|
737
|
-
// Zig
|
|
738
|
-
[/\b(pub\s+fn|const\s+\w+\s*=|@import\(|comptime)\b/, "zig"]
|
|
739
|
-
];
|
|
740
|
-
function N(t) {
|
|
741
|
-
const e = t.split(`
|
|
742
|
-
`)[0];
|
|
743
|
-
for (const [a, s] of G)
|
|
744
|
-
if (a.test(e))
|
|
745
|
-
return s;
|
|
746
|
-
for (const [a, s] of R)
|
|
747
|
-
if (a.test(t))
|
|
748
|
-
return s;
|
|
749
|
-
return null;
|
|
805
|
+
function N(e) {
|
|
806
|
+
g = { ...g, ...e };
|
|
750
807
|
}
|
|
751
|
-
function
|
|
752
|
-
const
|
|
753
|
-
|
|
754
|
-
const a = t.match(/\blang-(\w+)\b/);
|
|
755
|
-
if (a) return a[1];
|
|
756
|
-
const s = /* @__PURE__ */ new Set([
|
|
757
|
-
"rust",
|
|
758
|
-
"javascript",
|
|
759
|
-
"typescript",
|
|
760
|
-
"python",
|
|
761
|
-
"ruby",
|
|
762
|
-
"go",
|
|
763
|
-
"java",
|
|
764
|
-
"c",
|
|
765
|
-
"cpp",
|
|
766
|
-
"csharp",
|
|
767
|
-
"php",
|
|
768
|
-
"swift",
|
|
769
|
-
"kotlin",
|
|
770
|
-
"scala",
|
|
771
|
-
"haskell",
|
|
772
|
-
"elixir",
|
|
773
|
-
"lua",
|
|
774
|
-
"sql",
|
|
775
|
-
"bash",
|
|
776
|
-
"shell",
|
|
777
|
-
"yaml",
|
|
778
|
-
"json",
|
|
779
|
-
"toml",
|
|
780
|
-
"html",
|
|
781
|
-
"css",
|
|
782
|
-
"xml",
|
|
783
|
-
"markdown",
|
|
784
|
-
"dockerfile",
|
|
785
|
-
"nginx",
|
|
786
|
-
"zig",
|
|
787
|
-
"text",
|
|
788
|
-
"plaintext",
|
|
789
|
-
"console",
|
|
790
|
-
"sh"
|
|
791
|
-
]);
|
|
792
|
-
for (const n of t.split(/\s+/))
|
|
793
|
-
if (s.has(n.toLowerCase()))
|
|
794
|
-
return n.toLowerCase();
|
|
795
|
-
return null;
|
|
808
|
+
async function O(e, t) {
|
|
809
|
+
const a = b(t);
|
|
810
|
+
return await k(a), d.has(e) || (l?.entries.some((s) => s.language === e) ?? !1);
|
|
796
811
|
}
|
|
797
|
-
function
|
|
798
|
-
const
|
|
799
|
-
|
|
800
|
-
ts: "typescript",
|
|
801
|
-
py: "python",
|
|
802
|
-
rb: "ruby",
|
|
803
|
-
rs: "rust",
|
|
804
|
-
sh: "bash",
|
|
805
|
-
shell: "bash",
|
|
806
|
-
yml: "yaml",
|
|
807
|
-
cs: "c-sharp",
|
|
808
|
-
csharp: "c-sharp",
|
|
809
|
-
"c++": "cpp",
|
|
810
|
-
"c#": "c-sharp",
|
|
811
|
-
"f#": "fsharp",
|
|
812
|
-
dockerfile: "dockerfile",
|
|
813
|
-
docker: "dockerfile",
|
|
814
|
-
makefile: "make",
|
|
815
|
-
plaintext: "text",
|
|
816
|
-
plain: "text",
|
|
817
|
-
txt: "text"
|
|
818
|
-
}, a = t.toLowerCase();
|
|
819
|
-
return e[a] || a;
|
|
812
|
+
async function B(e) {
|
|
813
|
+
const t = b(e);
|
|
814
|
+
return await k(t), l ? l.entries.map((a) => a.language) : Array.from(d);
|
|
820
815
|
}
|
|
821
816
|
export {
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
817
|
+
U as availableLanguages,
|
|
818
|
+
M as detectLanguage,
|
|
819
|
+
R as extractLanguageFromClass,
|
|
820
|
+
B as getAvailableLanguages,
|
|
821
|
+
b as getConfig,
|
|
822
|
+
G as highlight,
|
|
823
|
+
F as highlights,
|
|
824
|
+
O as isLanguageAvailable,
|
|
825
|
+
z as loadGrammar,
|
|
826
|
+
H as normalizeLanguage,
|
|
827
|
+
_ as pluginVersion,
|
|
828
|
+
N as setConfig
|
|
833
829
|
};
|
|
834
830
|
//# sourceMappingURL=arborium.js.map
|