@arborium/arborium 2.13.0 → 2.16.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 +1 -1
- package/dist/arborium.iife.js +2 -2
- package/dist/arborium.iife.js.map +1 -1
- package/dist/arborium.js +97 -94
- package/dist/arborium.js.map +1 -1
- package/dist/arborium_host.d.ts +94 -0
- package/dist/arborium_host.js +300 -295
- package/dist/arborium_host_bg.wasm +0 -0
- package/dist/plugins-manifest.d.ts +1 -1
- package/dist/types.d.ts +10 -4
- package/package.json +9 -2
package/dist/arborium.js
CHANGED
|
@@ -11,7 +11,7 @@ const _ = [
|
|
|
11
11
|
[/^#!.*\bsh\b/, "bash"],
|
|
12
12
|
[/^#!.*\blua\b/, "lua"],
|
|
13
13
|
[/^#!.*\bawk\b/, "awk"]
|
|
14
|
-
],
|
|
14
|
+
], $ = [
|
|
15
15
|
// Rust - distinctive keywords
|
|
16
16
|
[/\b(fn|impl|trait|pub\s+fn|let\s+mut|&mut|->)\b/, "rust"],
|
|
17
17
|
// Go - distinctive keywords
|
|
@@ -71,23 +71,23 @@ const _ = [
|
|
|
71
71
|
// Zig
|
|
72
72
|
[/\b(pub\s+fn|const\s+\w+\s*=|@import\(|comptime)\b/, "zig"]
|
|
73
73
|
];
|
|
74
|
-
function
|
|
74
|
+
function M(e) {
|
|
75
75
|
const t = e.split(`
|
|
76
76
|
`)[0];
|
|
77
|
-
for (const [r,
|
|
77
|
+
for (const [r, s] of _)
|
|
78
78
|
if (r.test(t))
|
|
79
|
-
return
|
|
80
|
-
for (const [r,
|
|
79
|
+
return s;
|
|
80
|
+
for (const [r, s] of $)
|
|
81
81
|
if (r.test(e))
|
|
82
|
-
return
|
|
82
|
+
return s;
|
|
83
83
|
return null;
|
|
84
84
|
}
|
|
85
|
-
function
|
|
85
|
+
function R(e) {
|
|
86
86
|
const t = e.match(/\blanguage-(\w+)\b/);
|
|
87
87
|
if (t) return t[1];
|
|
88
88
|
const r = e.match(/\blang-(\w+)\b/);
|
|
89
89
|
if (r) return r[1];
|
|
90
|
-
const
|
|
90
|
+
const s = /* @__PURE__ */ new Set([
|
|
91
91
|
"rust",
|
|
92
92
|
"javascript",
|
|
93
93
|
"typescript",
|
|
@@ -124,7 +124,7 @@ function H(e) {
|
|
|
124
124
|
"sh"
|
|
125
125
|
]);
|
|
126
126
|
for (const a of e.split(/\s+/))
|
|
127
|
-
if (
|
|
127
|
+
if (s.has(a.toLowerCase()))
|
|
128
128
|
return a.toLowerCase();
|
|
129
129
|
return null;
|
|
130
130
|
}
|
|
@@ -152,7 +152,7 @@ function F(e) {
|
|
|
152
152
|
}, r = e.toLowerCase();
|
|
153
153
|
return t[r] || r;
|
|
154
154
|
}
|
|
155
|
-
const
|
|
155
|
+
const L = "2.16.0", U = [
|
|
156
156
|
"ada",
|
|
157
157
|
"agda",
|
|
158
158
|
"asciidoc",
|
|
@@ -220,6 +220,7 @@ const $ = "2.13.0", U = [
|
|
|
220
220
|
"python",
|
|
221
221
|
"query",
|
|
222
222
|
"r",
|
|
223
|
+
"rego",
|
|
223
224
|
"rescript",
|
|
224
225
|
"ron",
|
|
225
226
|
"ruby",
|
|
@@ -255,7 +256,7 @@ const $ = "2.13.0", U = [
|
|
|
255
256
|
"yuri",
|
|
256
257
|
"zig",
|
|
257
258
|
"zsh"
|
|
258
|
-
],
|
|
259
|
+
], J = [
|
|
259
260
|
{
|
|
260
261
|
name: "attribute",
|
|
261
262
|
tag: "at"
|
|
@@ -592,28 +593,33 @@ const $ = "2.13.0", U = [
|
|
|
592
593
|
function P(e) {
|
|
593
594
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
594
595
|
}
|
|
595
|
-
const
|
|
596
|
+
const j = {
|
|
596
597
|
manual: !1,
|
|
597
598
|
theme: "one-dark",
|
|
598
599
|
selector: "pre code",
|
|
599
600
|
cdn: "jsdelivr",
|
|
600
|
-
version:
|
|
601
|
+
version: L,
|
|
601
602
|
// Precise version from manifest
|
|
602
603
|
pluginsUrl: "",
|
|
603
604
|
// Empty means use bundled manifest
|
|
604
605
|
hostUrl: "",
|
|
605
606
|
// Empty means use CDN based on version
|
|
606
607
|
logger: console,
|
|
608
|
+
resolveHostJs: ({ baseUrl: e, path: t }) => import(
|
|
609
|
+
/* @vite-ignore */
|
|
610
|
+
`${e}/${t}`
|
|
611
|
+
),
|
|
612
|
+
resolveHostWasm: ({ baseUrl: e, path: t }) => fetch(`${e}/${t}`),
|
|
607
613
|
resolveJs: ({ baseUrl: e, path: t }) => import(
|
|
608
614
|
/* @vite-ignore */
|
|
609
615
|
`${e}/${t}`
|
|
610
616
|
),
|
|
611
617
|
resolveWasm: ({ baseUrl: e, path: t }) => fetch(`${e}/${t}`)
|
|
612
618
|
};
|
|
613
|
-
let m = null, d = null, f = { ...
|
|
619
|
+
let m = null, d = null, f = { ...j };
|
|
614
620
|
const h = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Map(), p = new Set(U);
|
|
615
621
|
let c = null, b = null;
|
|
616
|
-
async function
|
|
622
|
+
async function T(e) {
|
|
617
623
|
if (e.pluginsUrl)
|
|
618
624
|
return b || (b = (async () => {
|
|
619
625
|
e.logger.debug(`[arborium] Loading local plugins manifest from: ${e.pluginsUrl}`);
|
|
@@ -625,22 +631,22 @@ async function j(e) {
|
|
|
625
631
|
}
|
|
626
632
|
function E(e, t) {
|
|
627
633
|
if (c) {
|
|
628
|
-
const
|
|
629
|
-
if (
|
|
630
|
-
return
|
|
634
|
+
const n = c.entries.find((l) => l.language === e);
|
|
635
|
+
if (n)
|
|
636
|
+
return n.local_js.substring(0, n.local_js.lastIndexOf("/"));
|
|
631
637
|
}
|
|
632
|
-
const r = t.cdn,
|
|
638
|
+
const r = t.cdn, s = t.version;
|
|
633
639
|
let a;
|
|
634
|
-
return r === "jsdelivr" ? a = "https://cdn.jsdelivr.net/npm" : r === "unpkg" ? a = "https://unpkg.com" : a = r, `${a}/@arborium/${e}@${
|
|
640
|
+
return r === "jsdelivr" ? a = "https://cdn.jsdelivr.net/npm" : r === "unpkg" ? a = "https://unpkg.com" : a = r, `${a}/@arborium/${e}@${s}`;
|
|
635
641
|
}
|
|
636
642
|
async function x(e, t) {
|
|
637
643
|
const r = h.get(e);
|
|
638
644
|
if (r)
|
|
639
645
|
return t.logger.debug(`[arborium] Grammar '${e}' found in cache`), r;
|
|
640
|
-
const
|
|
641
|
-
if (
|
|
642
|
-
return t.logger.debug(`[arborium] Grammar '${e}' already loading, waiting...`),
|
|
643
|
-
const a =
|
|
646
|
+
const s = k.get(e);
|
|
647
|
+
if (s)
|
|
648
|
+
return t.logger.debug(`[arborium] Grammar '${e}' already loading, waiting...`), s;
|
|
649
|
+
const a = H(e, t);
|
|
644
650
|
k.set(e, a);
|
|
645
651
|
try {
|
|
646
652
|
return await a;
|
|
@@ -648,18 +654,18 @@ async function x(e, t) {
|
|
|
648
654
|
k.delete(e);
|
|
649
655
|
}
|
|
650
656
|
}
|
|
651
|
-
async function
|
|
652
|
-
if (await
|
|
657
|
+
async function H(e, t) {
|
|
658
|
+
if (await T(t), !p.has(e) && !c?.entries.some((r) => r.language === e))
|
|
653
659
|
return t.logger.debug(`[arborium] Grammar '${e}' not available`), null;
|
|
654
660
|
try {
|
|
655
|
-
const r = E(e, t),
|
|
656
|
-
t.logger.debug(`[arborium] Loading grammar '${e}'${
|
|
661
|
+
const r = E(e, t), s = t.resolveJs === j.resolveJs ? ` from ${r}/grammar.js` : "";
|
|
662
|
+
t.logger.debug(`[arborium] Loading grammar '${e}'${s}`);
|
|
657
663
|
const a = await t.resolveJs({
|
|
658
664
|
language: e,
|
|
659
665
|
baseUrl: r,
|
|
660
666
|
path: "grammar.js"
|
|
661
|
-
}),
|
|
662
|
-
await a.default({ module_or_path:
|
|
667
|
+
}), n = await t.resolveWasm({ language: e, baseUrl: r, path: "grammar_bg.wasm" });
|
|
668
|
+
await a.default({ module_or_path: n });
|
|
663
669
|
const l = a.language_id();
|
|
664
670
|
l !== e && t.logger.warn(`[arborium] Language ID mismatch: expected '${e}', got '${l}'`);
|
|
665
671
|
const w = a.injection_languages(), y = {
|
|
@@ -705,8 +711,8 @@ async function I(e, t) {
|
|
|
705
711
|
}
|
|
706
712
|
}
|
|
707
713
|
const v = /* @__PURE__ */ new Map();
|
|
708
|
-
let
|
|
709
|
-
function
|
|
714
|
+
let I = 1;
|
|
715
|
+
function q(e) {
|
|
710
716
|
globalThis.arboriumHost = {
|
|
711
717
|
/** Check if a language is available (sync) */
|
|
712
718
|
isLanguageAvailable(t) {
|
|
@@ -716,74 +722,71 @@ function C(e) {
|
|
|
716
722
|
async loadGrammar(t) {
|
|
717
723
|
const r = await x(t, e);
|
|
718
724
|
if (!r) return 0;
|
|
719
|
-
for (const [a,
|
|
720
|
-
if (
|
|
721
|
-
const
|
|
722
|
-
return v.set(
|
|
725
|
+
for (const [a, n] of v)
|
|
726
|
+
if (n === r) return a;
|
|
727
|
+
const s = I++;
|
|
728
|
+
return v.set(s, r), s;
|
|
723
729
|
},
|
|
724
730
|
/** Parse text using a grammar handle (sync) - returns UTF-8 offsets for Rust host */
|
|
725
731
|
parse(t, r) {
|
|
726
|
-
const
|
|
727
|
-
return
|
|
732
|
+
const s = v.get(t);
|
|
733
|
+
return s ? s.parseUtf8(r) : { spans: [], injections: [] };
|
|
728
734
|
}
|
|
729
735
|
};
|
|
730
736
|
}
|
|
731
|
-
function
|
|
737
|
+
function C(e) {
|
|
732
738
|
if (e.hostUrl)
|
|
733
739
|
return e.hostUrl;
|
|
734
740
|
const t = e.cdn, r = e.version;
|
|
735
|
-
let
|
|
736
|
-
t === "jsdelivr" ?
|
|
741
|
+
let s;
|
|
742
|
+
t === "jsdelivr" ? s = "https://cdn.jsdelivr.net/npm" : t === "unpkg" ? s = "https://unpkg.com" : s = t;
|
|
737
743
|
const a = r === "latest" ? "" : `@${r}`;
|
|
738
|
-
return `${
|
|
744
|
+
return `${s}/@arborium/arborium${a}/dist`;
|
|
739
745
|
}
|
|
740
|
-
async function
|
|
746
|
+
async function G(e) {
|
|
741
747
|
return m || d || (d = (async () => {
|
|
742
|
-
|
|
743
|
-
const t =
|
|
744
|
-
e.logger.debug(`[arborium] Loading host
|
|
748
|
+
q(e);
|
|
749
|
+
const t = C(e), r = e.resolveHostJs === j.resolveHostJs ? ` from ${t}/arborium_host.js` : "";
|
|
750
|
+
e.logger.debug(`[arborium] Loading host${r}`);
|
|
745
751
|
try {
|
|
746
|
-
const a = await
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
return await a.default(n), m = {
|
|
751
|
-
highlight: a.highlight,
|
|
752
|
-
isLanguageAvailable: a.isLanguageAvailable
|
|
752
|
+
const s = await e.resolveHostJs({ baseUrl: t, path: "arborium_host.js" }), a = await e.resolveHostWasm({ baseUrl: t, path: "arborium_host_bg.wasm" });
|
|
753
|
+
return await s.default({ module_or_path: a }), m = {
|
|
754
|
+
highlight: s.highlight,
|
|
755
|
+
isLanguageAvailable: s.isLanguageAvailable
|
|
753
756
|
}, e.logger.debug("[arborium] Host loaded successfully"), m;
|
|
754
|
-
} catch (
|
|
755
|
-
return e.logger.error("[arborium] Failed to load host:",
|
|
757
|
+
} catch (s) {
|
|
758
|
+
return e.logger.error("[arborium] Failed to load host:", s), null;
|
|
756
759
|
}
|
|
757
760
|
})(), d);
|
|
758
761
|
}
|
|
759
|
-
async function
|
|
760
|
-
const
|
|
762
|
+
async function S(e, t, r) {
|
|
763
|
+
const s = u(r), a = await G(s);
|
|
761
764
|
if (a)
|
|
762
765
|
try {
|
|
763
766
|
return a.highlight(e, t);
|
|
764
|
-
} catch (
|
|
765
|
-
|
|
767
|
+
} catch (n) {
|
|
768
|
+
s.logger.error("[arborium] Host highlight failed:", n);
|
|
766
769
|
}
|
|
767
770
|
return P(t);
|
|
768
771
|
}
|
|
769
|
-
async function
|
|
770
|
-
const r = u(t),
|
|
771
|
-
if (!
|
|
772
|
-
const { module: a } =
|
|
772
|
+
async function A(e, t) {
|
|
773
|
+
const r = u(t), s = await x(e, r);
|
|
774
|
+
if (!s) return null;
|
|
775
|
+
const { module: a } = s;
|
|
773
776
|
return {
|
|
774
|
-
languageId: () =>
|
|
775
|
-
injectionLanguages: () =>
|
|
776
|
-
highlight: async (
|
|
777
|
+
languageId: () => s.languageId,
|
|
778
|
+
injectionLanguages: () => s.injectionLanguages,
|
|
779
|
+
highlight: async (n) => S(e, n, t),
|
|
777
780
|
// Public API returns UTF-16 offsets for JavaScript compatibility
|
|
778
|
-
parse: (
|
|
781
|
+
parse: (n) => s.parseUtf16(n),
|
|
779
782
|
createSession: () => {
|
|
780
|
-
const
|
|
783
|
+
const n = a.create_session();
|
|
781
784
|
return {
|
|
782
|
-
setText: (l) => a.set_text(
|
|
785
|
+
setText: (l) => a.set_text(n, l),
|
|
783
786
|
// Session.parse() returns UTF-16 offsets for JavaScript compatibility
|
|
784
787
|
parse: () => {
|
|
785
788
|
try {
|
|
786
|
-
const l = a.parse_utf16(
|
|
789
|
+
const l = a.parse_utf16(n);
|
|
787
790
|
return {
|
|
788
791
|
spans: l.spans || [],
|
|
789
792
|
injections: l.injections || []
|
|
@@ -792,19 +795,19 @@ async function M(e, t) {
|
|
|
792
795
|
return r.logger.error("[arborium] Session parse error:", l), { spans: [], injections: [] };
|
|
793
796
|
}
|
|
794
797
|
},
|
|
795
|
-
cancel: () => a.cancel(
|
|
796
|
-
free: () => a.free_session(
|
|
798
|
+
cancel: () => a.cancel(n),
|
|
799
|
+
free: () => a.free_session(n)
|
|
797
800
|
};
|
|
798
801
|
},
|
|
799
802
|
dispose: () => {
|
|
800
803
|
}
|
|
801
804
|
};
|
|
802
805
|
}
|
|
803
|
-
async function
|
|
804
|
-
const
|
|
806
|
+
async function z(e, t, r) {
|
|
807
|
+
const s = u(r), a = e;
|
|
805
808
|
await a.default({ module_or_path: t });
|
|
806
|
-
const
|
|
807
|
-
languageId:
|
|
809
|
+
const n = a.language_id(), l = a.injection_languages(), w = {
|
|
810
|
+
languageId: n,
|
|
808
811
|
injectionLanguages: l,
|
|
809
812
|
module: a,
|
|
810
813
|
parseUtf8: (g) => {
|
|
@@ -817,7 +820,7 @@ async function N(e, t, r) {
|
|
|
817
820
|
injections: o.injections || []
|
|
818
821
|
};
|
|
819
822
|
} catch (o) {
|
|
820
|
-
return
|
|
823
|
+
return s.logger.error("[arborium] Parse error:", o), { spans: [], injections: [] };
|
|
821
824
|
} finally {
|
|
822
825
|
a.free_session(i);
|
|
823
826
|
}
|
|
@@ -832,41 +835,41 @@ async function N(e, t, r) {
|
|
|
832
835
|
injections: o.injections || []
|
|
833
836
|
};
|
|
834
837
|
} catch (o) {
|
|
835
|
-
return
|
|
838
|
+
return s.logger.error("[arborium] Parse error:", o), { spans: [], injections: [] };
|
|
836
839
|
} finally {
|
|
837
840
|
a.free_session(i);
|
|
838
841
|
}
|
|
839
842
|
}
|
|
840
843
|
};
|
|
841
|
-
return h.set(
|
|
844
|
+
return h.set(n, w), p.add(n), s.logger.debug(`[arborium] Grammar '${n}' registered`), await A(n, r);
|
|
842
845
|
}
|
|
843
846
|
function u(e) {
|
|
844
847
|
return e ? { ...f, ...e } : { ...f };
|
|
845
848
|
}
|
|
846
|
-
function
|
|
849
|
+
function N(e) {
|
|
847
850
|
f = { ...f, ...e };
|
|
848
851
|
}
|
|
849
|
-
async function
|
|
852
|
+
async function O(e, t) {
|
|
850
853
|
const r = u(t);
|
|
851
|
-
return await
|
|
854
|
+
return await T(r), p.has(e) || (c?.entries.some((s) => s.language === e) ?? !1);
|
|
852
855
|
}
|
|
853
|
-
async function
|
|
856
|
+
async function W(e) {
|
|
854
857
|
const t = u(e);
|
|
855
|
-
return await
|
|
858
|
+
return await T(t), c ? c.entries.map((r) => r.language) : Array.from(p);
|
|
856
859
|
}
|
|
857
860
|
export {
|
|
858
861
|
U as availableLanguages,
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
+
M as detectLanguage,
|
|
863
|
+
R as extractLanguageFromClass,
|
|
864
|
+
W as getAvailableLanguages,
|
|
862
865
|
u as getConfig,
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
866
|
+
S as highlight,
|
|
867
|
+
J as highlights,
|
|
868
|
+
O as isLanguageAvailable,
|
|
869
|
+
A as loadGrammar,
|
|
867
870
|
F as normalizeLanguage,
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
+
L as pluginVersion,
|
|
872
|
+
z as registerGrammar,
|
|
873
|
+
N as setConfig
|
|
871
874
|
};
|
|
872
875
|
//# sourceMappingURL=arborium.js.map
|