@arborium/arborium 2.11.0 → 2.12.1
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 +1 -1
- package/dist/arborium.iife.js.map +1 -1
- package/dist/arborium.js +265 -255
- package/dist/arborium.js.map +1 -1
- package/dist/arborium_host.js +3 -3
- package/dist/arborium_host_bg.wasm +0 -0
- package/dist/plugins-manifest.d.ts +1 -1
- package/package.json +1 -1
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.1", U = [
|
|
2
156
|
"ada",
|
|
3
157
|
"agda",
|
|
4
158
|
"asciidoc",
|
|
@@ -101,7 +255,7 @@ const x = "2.11.0", $ = [
|
|
|
101
255
|
"yuri",
|
|
102
256
|
"zig",
|
|
103
257
|
"zsh"
|
|
104
|
-
],
|
|
258
|
+
], F = [
|
|
105
259
|
{
|
|
106
260
|
name: "attribute",
|
|
107
261
|
tag: "at"
|
|
@@ -435,15 +589,15 @@ const x = "2.11.0", $ = [
|
|
|
435
589
|
tag: "cb"
|
|
436
590
|
}
|
|
437
591
|
];
|
|
438
|
-
function
|
|
592
|
+
function E(e) {
|
|
439
593
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
440
594
|
}
|
|
441
|
-
const
|
|
595
|
+
const T = {
|
|
442
596
|
manual: !1,
|
|
443
597
|
theme: "one-dark",
|
|
444
598
|
selector: "pre code",
|
|
445
599
|
cdn: "jsdelivr",
|
|
446
|
-
version:
|
|
600
|
+
version: _,
|
|
447
601
|
// Precise version from manifest
|
|
448
602
|
pluginsUrl: "",
|
|
449
603
|
// Empty means use bundled manifest
|
|
@@ -455,68 +609,68 @@ const y = {
|
|
|
455
609
|
),
|
|
456
610
|
resolveWasm: ({ baseUrl: e, path: t }) => fetch(`${e}/${t}`)
|
|
457
611
|
};
|
|
458
|
-
let p = null, m = null, g = { ...
|
|
459
|
-
const
|
|
460
|
-
let
|
|
461
|
-
async function
|
|
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) {
|
|
462
616
|
if (e.pluginsUrl)
|
|
463
617
|
return u || (u = (async () => {
|
|
464
618
|
console.debug(`[arborium] Loading local plugins manifest from: ${e.pluginsUrl}`);
|
|
465
619
|
const t = await fetch(e.pluginsUrl);
|
|
466
620
|
if (!t.ok)
|
|
467
621
|
throw new Error(`Failed to load plugins.json: ${t.status}`);
|
|
468
|
-
|
|
622
|
+
l = await t.json(), console.debug(`[arborium] Loaded local manifest with ${l?.entries.length} entries`);
|
|
469
623
|
})(), u);
|
|
470
624
|
}
|
|
471
|
-
function
|
|
472
|
-
if (
|
|
473
|
-
const r =
|
|
625
|
+
function P(e, t) {
|
|
626
|
+
if (l) {
|
|
627
|
+
const r = l.entries.find((o) => o.language === e);
|
|
474
628
|
if (r)
|
|
475
629
|
return r.local_js.substring(0, r.local_js.lastIndexOf("/"));
|
|
476
630
|
}
|
|
477
|
-
const
|
|
478
|
-
let
|
|
479
|
-
return
|
|
631
|
+
const a = t.cdn, s = t.version;
|
|
632
|
+
let n;
|
|
633
|
+
return a === "jsdelivr" ? n = "https://cdn.jsdelivr.net/npm" : a === "unpkg" ? n = "https://unpkg.com" : n = a, `${n}/@arborium/${e}@${s}`;
|
|
480
634
|
}
|
|
481
|
-
async function
|
|
482
|
-
const
|
|
483
|
-
if (
|
|
484
|
-
return console.debug(`[arborium] Grammar '${e}' found in cache`),
|
|
485
|
-
const s =
|
|
635
|
+
async function j(e, t) {
|
|
636
|
+
const a = y.get(e);
|
|
637
|
+
if (a)
|
|
638
|
+
return console.debug(`[arborium] Grammar '${e}' found in cache`), a;
|
|
639
|
+
const s = h.get(e);
|
|
486
640
|
if (s)
|
|
487
641
|
return console.debug(`[arborium] Grammar '${e}' already loading, waiting...`), s;
|
|
488
|
-
const
|
|
489
|
-
|
|
642
|
+
const n = q(e, t);
|
|
643
|
+
h.set(e, n);
|
|
490
644
|
try {
|
|
491
|
-
return await
|
|
645
|
+
return await n;
|
|
492
646
|
} finally {
|
|
493
|
-
|
|
647
|
+
h.delete(e);
|
|
494
648
|
}
|
|
495
649
|
}
|
|
496
|
-
async function
|
|
497
|
-
if (await
|
|
650
|
+
async function q(e, t) {
|
|
651
|
+
if (await k(t), !d.has(e) && !l?.entries.some((a) => a.language === e))
|
|
498
652
|
return console.debug(`[arborium] Grammar '${e}' not available`), null;
|
|
499
653
|
try {
|
|
500
|
-
const
|
|
654
|
+
const a = P(e, t), s = t.resolveJs === T.resolveJs ? ` from ${a}/grammar.js` : "";
|
|
501
655
|
console.debug(`[arborium] Loading grammar '${e}'${s}`);
|
|
502
|
-
const
|
|
656
|
+
const n = await t.resolveJs({
|
|
503
657
|
language: e,
|
|
504
|
-
baseUrl:
|
|
658
|
+
baseUrl: a,
|
|
505
659
|
path: "grammar.js"
|
|
506
|
-
}), r = await t.resolveWasm({ language: e, baseUrl:
|
|
507
|
-
await
|
|
508
|
-
const o =
|
|
660
|
+
}), r = await t.resolveWasm({ language: e, baseUrl: a, path: "grammar_bg.wasm" });
|
|
661
|
+
await n.default({ module_or_path: r });
|
|
662
|
+
const o = n.language_id();
|
|
509
663
|
o !== e && console.warn(`[arborium] Language ID mismatch: expected '${e}', got '${o}'`);
|
|
510
|
-
const
|
|
664
|
+
const x = n.injection_languages(), v = {
|
|
511
665
|
languageId: e,
|
|
512
|
-
injectionLanguages:
|
|
513
|
-
module:
|
|
666
|
+
injectionLanguages: x,
|
|
667
|
+
module: n,
|
|
514
668
|
// UTF-8 parsing for Rust host
|
|
515
|
-
parseUtf8: (
|
|
516
|
-
const
|
|
669
|
+
parseUtf8: (f) => {
|
|
670
|
+
const c = n.create_session();
|
|
517
671
|
try {
|
|
518
|
-
|
|
519
|
-
const i =
|
|
672
|
+
n.set_text(c, f);
|
|
673
|
+
const i = n.parse(c);
|
|
520
674
|
return {
|
|
521
675
|
spans: i.spans || [],
|
|
522
676
|
injections: i.injections || []
|
|
@@ -524,15 +678,15 @@ async function E(e, t) {
|
|
|
524
678
|
} catch (i) {
|
|
525
679
|
return console.error("[arborium] Parse error:", i), { spans: [], injections: [] };
|
|
526
680
|
} finally {
|
|
527
|
-
|
|
681
|
+
n.free_session(c);
|
|
528
682
|
}
|
|
529
683
|
},
|
|
530
684
|
// UTF-16 parsing for JavaScript public API
|
|
531
|
-
parseUtf16: (
|
|
532
|
-
const
|
|
685
|
+
parseUtf16: (f) => {
|
|
686
|
+
const c = n.create_session();
|
|
533
687
|
try {
|
|
534
|
-
|
|
535
|
-
const i =
|
|
688
|
+
n.set_text(c, f);
|
|
689
|
+
const i = n.parse_utf16(c);
|
|
536
690
|
return {
|
|
537
691
|
spans: i.spans || [],
|
|
538
692
|
injections: i.injections || []
|
|
@@ -540,95 +694,95 @@ async function E(e, t) {
|
|
|
540
694
|
} catch (i) {
|
|
541
695
|
return console.error("[arborium] Parse error:", i), { spans: [], injections: [] };
|
|
542
696
|
} finally {
|
|
543
|
-
|
|
697
|
+
n.free_session(c);
|
|
544
698
|
}
|
|
545
699
|
}
|
|
546
700
|
};
|
|
547
|
-
return
|
|
548
|
-
} catch (
|
|
549
|
-
return console.error(`[arborium] Failed to load grammar '${e}':`,
|
|
701
|
+
return y.set(e, v), console.debug(`[arborium] Grammar '${e}' loaded successfully`), v;
|
|
702
|
+
} catch (a) {
|
|
703
|
+
return console.error(`[arborium] Failed to load grammar '${e}':`, a), null;
|
|
550
704
|
}
|
|
551
705
|
}
|
|
552
|
-
const
|
|
553
|
-
let
|
|
554
|
-
function
|
|
706
|
+
const w = /* @__PURE__ */ new Map();
|
|
707
|
+
let C = 1;
|
|
708
|
+
function I(e) {
|
|
555
709
|
window.arboriumHost = {
|
|
556
710
|
/** Check if a language is available (sync) */
|
|
557
711
|
isLanguageAvailable(t) {
|
|
558
|
-
return
|
|
712
|
+
return d.has(t) || y.has(t);
|
|
559
713
|
},
|
|
560
714
|
/** Load a grammar and return a handle (async) */
|
|
561
715
|
async loadGrammar(t) {
|
|
562
|
-
const
|
|
563
|
-
if (!
|
|
564
|
-
for (const [
|
|
565
|
-
if (r ===
|
|
566
|
-
const s =
|
|
567
|
-
return
|
|
716
|
+
const a = await j(t, e);
|
|
717
|
+
if (!a) return 0;
|
|
718
|
+
for (const [n, r] of w)
|
|
719
|
+
if (r === a) return n;
|
|
720
|
+
const s = C++;
|
|
721
|
+
return w.set(s, a), s;
|
|
568
722
|
},
|
|
569
723
|
/** Parse text using a grammar handle (sync) - returns UTF-8 offsets for Rust host */
|
|
570
|
-
parse(t,
|
|
571
|
-
const s =
|
|
572
|
-
return s ? s.parseUtf8(
|
|
724
|
+
parse(t, a) {
|
|
725
|
+
const s = w.get(t);
|
|
726
|
+
return s ? s.parseUtf8(a) : { spans: [], injections: [] };
|
|
573
727
|
}
|
|
574
728
|
};
|
|
575
729
|
}
|
|
576
|
-
function
|
|
730
|
+
function S(e) {
|
|
577
731
|
if (e.hostUrl)
|
|
578
732
|
return e.hostUrl;
|
|
579
|
-
const t = e.cdn,
|
|
733
|
+
const t = e.cdn, a = e.version;
|
|
580
734
|
let s;
|
|
581
735
|
t === "jsdelivr" ? s = "https://cdn.jsdelivr.net/npm" : t === "unpkg" ? s = "https://unpkg.com" : s = t;
|
|
582
|
-
const
|
|
583
|
-
return `${s}/@arborium/arborium${
|
|
736
|
+
const n = a === "latest" ? "" : `@${a}`;
|
|
737
|
+
return `${s}/@arborium/arborium${n}/dist`;
|
|
584
738
|
}
|
|
585
|
-
async function
|
|
739
|
+
async function A(e) {
|
|
586
740
|
return p || m || (m = (async () => {
|
|
587
|
-
|
|
588
|
-
const t =
|
|
589
|
-
console.debug(`[arborium] Loading host from ${
|
|
741
|
+
I(e);
|
|
742
|
+
const t = S(e), a = `${t}/arborium_host.js`, s = `${t}/arborium_host_bg.wasm`;
|
|
743
|
+
console.debug(`[arborium] Loading host from ${a}`);
|
|
590
744
|
try {
|
|
591
|
-
const
|
|
745
|
+
const n = await import(
|
|
592
746
|
/* @vite-ignore */
|
|
593
|
-
|
|
747
|
+
a
|
|
594
748
|
);
|
|
595
|
-
return await
|
|
596
|
-
highlight:
|
|
597
|
-
isLanguageAvailable:
|
|
749
|
+
return await n.default(s), p = {
|
|
750
|
+
highlight: n.highlight,
|
|
751
|
+
isLanguageAvailable: n.isLanguageAvailable
|
|
598
752
|
}, console.debug("[arborium] Host loaded successfully"), p;
|
|
599
|
-
} catch (
|
|
600
|
-
return console.error("[arborium] Failed to load host:",
|
|
753
|
+
} catch (n) {
|
|
754
|
+
return console.error("[arborium] Failed to load host:", n), null;
|
|
601
755
|
}
|
|
602
756
|
})(), m);
|
|
603
757
|
}
|
|
604
|
-
async function
|
|
605
|
-
const s =
|
|
606
|
-
if (
|
|
758
|
+
async function G(e, t, a) {
|
|
759
|
+
const s = b(a), n = await A(s);
|
|
760
|
+
if (n)
|
|
607
761
|
try {
|
|
608
|
-
return
|
|
762
|
+
return n.highlight(e, t);
|
|
609
763
|
} catch (r) {
|
|
610
764
|
console.error("[arborium] Host highlight failed:", r);
|
|
611
765
|
}
|
|
612
|
-
return
|
|
766
|
+
return E(t);
|
|
613
767
|
}
|
|
614
|
-
async function
|
|
615
|
-
const
|
|
768
|
+
async function z(e, t) {
|
|
769
|
+
const a = b(t), s = await j(e, a);
|
|
616
770
|
if (!s) return null;
|
|
617
|
-
const { module:
|
|
771
|
+
const { module: n } = s;
|
|
618
772
|
return {
|
|
619
773
|
languageId: () => s.languageId,
|
|
620
774
|
injectionLanguages: () => s.injectionLanguages,
|
|
621
|
-
highlight: async (r) =>
|
|
775
|
+
highlight: async (r) => G(e, r, t),
|
|
622
776
|
// Public API returns UTF-16 offsets for JavaScript compatibility
|
|
623
777
|
parse: (r) => s.parseUtf16(r),
|
|
624
778
|
createSession: () => {
|
|
625
|
-
const r =
|
|
779
|
+
const r = n.create_session();
|
|
626
780
|
return {
|
|
627
|
-
setText: (o) =>
|
|
781
|
+
setText: (o) => n.set_text(r, o),
|
|
628
782
|
// Session.parse() returns UTF-16 offsets for JavaScript compatibility
|
|
629
783
|
parse: () => {
|
|
630
784
|
try {
|
|
631
|
-
const o =
|
|
785
|
+
const o = n.parse_utf16(r);
|
|
632
786
|
return {
|
|
633
787
|
spans: o.spans || [],
|
|
634
788
|
injections: o.injections || []
|
|
@@ -637,184 +791,40 @@ async function A(e, t) {
|
|
|
637
791
|
return console.error("[arborium] Session parse error:", o), { spans: [], injections: [] };
|
|
638
792
|
}
|
|
639
793
|
},
|
|
640
|
-
cancel: () =>
|
|
641
|
-
free: () =>
|
|
794
|
+
cancel: () => n.cancel(r),
|
|
795
|
+
free: () => n.free_session(r)
|
|
642
796
|
};
|
|
643
797
|
},
|
|
644
798
|
dispose: () => {
|
|
645
799
|
}
|
|
646
800
|
};
|
|
647
801
|
}
|
|
648
|
-
function
|
|
802
|
+
function b(e) {
|
|
649
803
|
return e ? { ...g, ...e } : { ...g };
|
|
650
804
|
}
|
|
651
|
-
function
|
|
805
|
+
function N(e) {
|
|
652
806
|
g = { ...g, ...e };
|
|
653
807
|
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
[/^#!.*\bdeno\b/, "typescript"],
|
|
658
|
-
[/^#!.*\bbun\b/, "typescript"],
|
|
659
|
-
[/^#!.*\bruby\b/, "ruby"],
|
|
660
|
-
[/^#!.*\bperl\b/, "perl"],
|
|
661
|
-
[/^#!.*\bphp\b/, "php"],
|
|
662
|
-
[/^#!.*\bbash\b/, "bash"],
|
|
663
|
-
[/^#!.*\bzsh\b/, "zsh"],
|
|
664
|
-
[/^#!.*\bsh\b/, "bash"],
|
|
665
|
-
[/^#!.*\blua\b/, "lua"],
|
|
666
|
-
[/^#!.*\bawk\b/, "awk"]
|
|
667
|
-
], M = [
|
|
668
|
-
// Rust - distinctive keywords
|
|
669
|
-
[/\b(fn|impl|trait|pub\s+fn|let\s+mut|&mut|->)\b/, "rust"],
|
|
670
|
-
// Go - distinctive keywords
|
|
671
|
-
[/\b(func|package\s+\w+|import\s+\(|go\s+func|chan\s+\w+)\b/, "go"],
|
|
672
|
-
// Python - distinctive patterns
|
|
673
|
-
[/\b(def\s+\w+\s*\(|import\s+\w+|from\s+\w+\s+import|class\s+\w+:)\b/, "python"],
|
|
674
|
-
// TypeScript - distinctive type annotations
|
|
675
|
-
[/:\s*(string|number|boolean|void)\b|\binterface\s+\w+\s*\{/, "typescript"],
|
|
676
|
-
// JavaScript - distinctive patterns (after TS check)
|
|
677
|
-
[/\b(const|let|var)\s+\w+\s*=|function\s+\w+\s*\(|=>\s*\{/, "javascript"],
|
|
678
|
-
// Ruby - distinctive keywords
|
|
679
|
-
[/\b(def\s+\w+|end\b|do\s*\|.*\||puts\s+|require\s+['"])\b/, "ruby"],
|
|
680
|
-
// Java - distinctive patterns
|
|
681
|
-
[/\b(public\s+class|private\s+\w+|System\.out\.println)\b/, "java"],
|
|
682
|
-
// C++ - distinctive patterns
|
|
683
|
-
[/\b(#include\s*<|std::|template\s*<|nullptr|cout\s*<<)\b/, "cpp"],
|
|
684
|
-
// C - distinctive patterns (after C++ check)
|
|
685
|
-
[/\b(#include\s*[<"]|printf\s*\(|int\s+main\s*\(|void\s+\w+\s*\()\b/, "c"],
|
|
686
|
-
// C# - distinctive patterns
|
|
687
|
-
[/\b(namespace\s+\w+|using\s+System|public\s+static\s+void)\b/, "c-sharp"],
|
|
688
|
-
// PHP - distinctive patterns
|
|
689
|
-
[/<\?php|\$\w+\s*=/, "php"],
|
|
690
|
-
// Swift - distinctive patterns
|
|
691
|
-
[/\b(func\s+\w+|var\s+\w+:\s*\w+|let\s+\w+:\s*\w+|@objc)\b/, "swift"],
|
|
692
|
-
// Kotlin - distinctive patterns
|
|
693
|
-
[/\b(fun\s+\w+|val\s+\w+|var\s+\w+:|data\s+class)\b/, "kotlin"],
|
|
694
|
-
// Scala - distinctive patterns
|
|
695
|
-
[/\b(def\s+\w+|val\s+\w+|var\s+\w+|object\s+\w+|case\s+class)\b/, "scala"],
|
|
696
|
-
// Haskell - distinctive patterns
|
|
697
|
-
[/\b(module\s+\w+|import\s+qualified|data\s+\w+\s*=|::\s*\w+\s*->)\b/, "haskell"],
|
|
698
|
-
// Elixir - distinctive patterns
|
|
699
|
-
[/\b(defmodule\s+\w+|def\s+\w+|defp\s+\w+|\|>)\b/, "elixir"],
|
|
700
|
-
// Lua - distinctive patterns
|
|
701
|
-
[/\b(local\s+\w+\s*=|function\s+\w+\.\w+|require\s*\()\b/, "lua"],
|
|
702
|
-
// SQL - distinctive patterns
|
|
703
|
-
[/\b(SELECT\s+.*\s+FROM|INSERT\s+INTO|CREATE\s+TABLE|ALTER\s+TABLE)\b/i, "sql"],
|
|
704
|
-
// Shell/Bash - distinctive patterns
|
|
705
|
-
[/\b(if\s+\[\s*|then\b|fi\b|echo\s+["']|export\s+\w+=)\b/, "bash"],
|
|
706
|
-
// YAML - distinctive patterns
|
|
707
|
-
[/^\s*[\w-]+:\s*[\w\-"'[{]|^---\s*$/, "yaml"],
|
|
708
|
-
// JSON - distinctive patterns
|
|
709
|
-
[/^\s*\{[\s\S]*"[\w-]+":\s*/, "json"],
|
|
710
|
-
// TOML - distinctive patterns
|
|
711
|
-
[/^\s*\[[\w.-]+\]\s*$|^\s*\w+\s*=\s*["'\d\[]/, "toml"],
|
|
712
|
-
// HTML - distinctive patterns
|
|
713
|
-
[/<(!DOCTYPE|html|head|body|div|span|p|a\s)/i, "html"],
|
|
714
|
-
// CSS - distinctive patterns
|
|
715
|
-
[/^\s*[\w.#@][\w\s,#.:>+~-]*\{[^}]*\}|@media\s|@import\s/, "css"],
|
|
716
|
-
// Markdown - distinctive patterns
|
|
717
|
-
[/^#{1,6}\s+\w|^\s*[-*+]\s+\w|^\s*\d+\.\s+\w|```\w*\n/, "markdown"],
|
|
718
|
-
// XML - distinctive patterns
|
|
719
|
-
[/<\?xml|<[\w:-]+\s+xmlns/, "xml"],
|
|
720
|
-
// Dockerfile
|
|
721
|
-
[/^FROM\s+\w+|^RUN\s+|^COPY\s+|^ENTRYPOINT\s+/m, "dockerfile"],
|
|
722
|
-
// Nginx config
|
|
723
|
-
[/\b(server\s*\{|location\s+[\/~]|proxy_pass\s+)\b/, "nginx"],
|
|
724
|
-
// Zig
|
|
725
|
-
[/\b(pub\s+fn|const\s+\w+\s*=|@import\(|comptime)\b/, "zig"]
|
|
726
|
-
];
|
|
727
|
-
function F(e) {
|
|
728
|
-
const t = e.split(`
|
|
729
|
-
`)[0];
|
|
730
|
-
for (const [n, s] of G)
|
|
731
|
-
if (n.test(t))
|
|
732
|
-
return s;
|
|
733
|
-
for (const [n, s] of M)
|
|
734
|
-
if (n.test(e))
|
|
735
|
-
return s;
|
|
736
|
-
return null;
|
|
737
|
-
}
|
|
738
|
-
function z(e) {
|
|
739
|
-
const t = e.match(/\blanguage-(\w+)\b/);
|
|
740
|
-
if (t) return t[1];
|
|
741
|
-
const n = e.match(/\blang-(\w+)\b/);
|
|
742
|
-
if (n) return n[1];
|
|
743
|
-
const s = /* @__PURE__ */ new Set([
|
|
744
|
-
"rust",
|
|
745
|
-
"javascript",
|
|
746
|
-
"typescript",
|
|
747
|
-
"python",
|
|
748
|
-
"ruby",
|
|
749
|
-
"go",
|
|
750
|
-
"java",
|
|
751
|
-
"c",
|
|
752
|
-
"cpp",
|
|
753
|
-
"csharp",
|
|
754
|
-
"php",
|
|
755
|
-
"swift",
|
|
756
|
-
"kotlin",
|
|
757
|
-
"scala",
|
|
758
|
-
"haskell",
|
|
759
|
-
"elixir",
|
|
760
|
-
"lua",
|
|
761
|
-
"sql",
|
|
762
|
-
"bash",
|
|
763
|
-
"shell",
|
|
764
|
-
"yaml",
|
|
765
|
-
"json",
|
|
766
|
-
"toml",
|
|
767
|
-
"html",
|
|
768
|
-
"css",
|
|
769
|
-
"xml",
|
|
770
|
-
"markdown",
|
|
771
|
-
"dockerfile",
|
|
772
|
-
"nginx",
|
|
773
|
-
"zig",
|
|
774
|
-
"text",
|
|
775
|
-
"plaintext",
|
|
776
|
-
"console",
|
|
777
|
-
"sh"
|
|
778
|
-
]);
|
|
779
|
-
for (const a of e.split(/\s+/))
|
|
780
|
-
if (s.has(a.toLowerCase()))
|
|
781
|
-
return a.toLowerCase();
|
|
782
|
-
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);
|
|
783
811
|
}
|
|
784
|
-
function
|
|
785
|
-
const t =
|
|
786
|
-
|
|
787
|
-
ts: "typescript",
|
|
788
|
-
py: "python",
|
|
789
|
-
rb: "ruby",
|
|
790
|
-
rs: "rust",
|
|
791
|
-
sh: "bash",
|
|
792
|
-
shell: "bash",
|
|
793
|
-
yml: "yaml",
|
|
794
|
-
cs: "c-sharp",
|
|
795
|
-
csharp: "c-sharp",
|
|
796
|
-
"c++": "cpp",
|
|
797
|
-
"c#": "c-sharp",
|
|
798
|
-
"f#": "fsharp",
|
|
799
|
-
dockerfile: "dockerfile",
|
|
800
|
-
docker: "dockerfile",
|
|
801
|
-
makefile: "make",
|
|
802
|
-
plaintext: "text",
|
|
803
|
-
plain: "text",
|
|
804
|
-
txt: "text"
|
|
805
|
-
}, n = e.toLowerCase();
|
|
806
|
-
return t[n] || n;
|
|
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);
|
|
807
815
|
}
|
|
808
816
|
export {
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
H as
|
|
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
|
|
819
829
|
};
|
|
820
830
|
//# sourceMappingURL=arborium.js.map
|