@arborium/arborium 2.10.0 → 2.11.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.js CHANGED
@@ -1,4 +1,4 @@
1
- const U = "2.10.0", _ = [
1
+ const x = "2.11.0", $ = [
2
2
  "ada",
3
3
  "agda",
4
4
  "asciidoc",
@@ -78,6 +78,7 @@ const U = "2.10.0", _ = [
78
78
  "sql",
79
79
  "ssh-config",
80
80
  "starlark",
81
+ "styx",
81
82
  "svelte",
82
83
  "swift",
83
84
  "textproto",
@@ -100,7 +101,7 @@ const U = "2.10.0", _ = [
100
101
  "yuri",
101
102
  "zig",
102
103
  "zsh"
103
- ], H = [
104
+ ], R = [
104
105
  {
105
106
  name: "attribute",
106
107
  tag: "at"
@@ -433,215 +434,201 @@ const U = "2.10.0", _ = [
433
434
  name: "boolean",
434
435
  tag: "cb"
435
436
  }
436
- ], T = new TextEncoder();
437
- function E(t) {
438
- const e = T.encode(t), a = new Uint32Array(e.length + 1);
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, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
437
+ ];
438
+ function L(e) {
439
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
469
440
  }
470
- const j = {
441
+ const y = {
471
442
  manual: !1,
472
443
  theme: "one-dark",
473
444
  selector: "pre code",
474
445
  cdn: "jsdelivr",
475
- version: U,
446
+ version: x,
476
447
  // Precise version from manifest
477
448
  pluginsUrl: "",
478
449
  // Empty means use bundled manifest
479
450
  hostUrl: "",
480
451
  // Empty means use CDN based on version
481
- resolveJs: ({ baseUrl: t, path: e }) => import(
452
+ resolveJs: ({ baseUrl: e, path: t }) => import(
482
453
  /* @vite-ignore */
483
- `${t}/${e}`
454
+ `${e}/${t}`
484
455
  ),
485
- resolveWasm: ({ baseUrl: t, path: e }) => fetch(`${t}/${e}`)
456
+ resolveWasm: ({ baseUrl: e, path: t }) => fetch(`${e}/${t}`)
486
457
  };
487
- let u = null, g = null, b = { ...j };
488
- const k = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map(), $ = new Set(_);
489
- let c = null, d = null;
490
- async function W(t) {
491
- if (t.pluginsUrl)
492
- return d || (d = (async () => {
493
- console.debug(`[arborium] Loading local plugins manifest from: ${t.pluginsUrl}`);
494
- const e = await fetch(t.pluginsUrl);
495
- if (!e.ok)
496
- throw new Error(`Failed to load plugins.json: ${e.status}`);
497
- c = await e.json(), console.debug(`[arborium] Loaded local manifest with ${c?.entries.length} entries`);
498
- })(), d);
458
+ let p = null, m = null, g = { ...y };
459
+ const h = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Map(), k = new Set($);
460
+ let c = null, u = null;
461
+ async function _(e) {
462
+ if (e.pluginsUrl)
463
+ return u || (u = (async () => {
464
+ console.debug(`[arborium] Loading local plugins manifest from: ${e.pluginsUrl}`);
465
+ const t = await fetch(e.pluginsUrl);
466
+ if (!t.ok)
467
+ throw new Error(`Failed to load plugins.json: ${t.status}`);
468
+ c = await t.json(), console.debug(`[arborium] Loaded local manifest with ${c?.entries.length} entries`);
469
+ })(), u);
499
470
  }
500
- function C(t, e) {
471
+ function U(e, t) {
501
472
  if (c) {
502
- const r = c.entries.find((o) => o.language === t);
473
+ const r = c.entries.find((o) => o.language === e);
503
474
  if (r)
504
475
  return r.local_js.substring(0, r.local_js.lastIndexOf("/"));
505
476
  }
506
- const a = e.cdn, s = e.version;
507
- let n;
508
- return a === "jsdelivr" ? n = "https://cdn.jsdelivr.net/npm" : a === "unpkg" ? n = "https://unpkg.com" : n = a, `${n}/@arborium/${t}@${s}`;
477
+ const n = t.cdn, s = t.version;
478
+ let a;
479
+ return n === "jsdelivr" ? a = "https://cdn.jsdelivr.net/npm" : n === "unpkg" ? a = "https://unpkg.com" : a = n, `${a}/@arborium/${e}@${s}`;
509
480
  }
510
- async function v(t, e) {
511
- const a = k.get(t);
512
- if (a)
513
- return console.debug(`[arborium] Grammar '${t}' found in cache`), a;
514
- const s = w.get(t);
481
+ async function v(e, t) {
482
+ const n = h.get(e);
483
+ if (n)
484
+ return console.debug(`[arborium] Grammar '${e}' found in cache`), n;
485
+ const s = b.get(e);
515
486
  if (s)
516
- return console.debug(`[arborium] Grammar '${t}' already loading, waiting...`), s;
517
- const n = I(t, e);
518
- w.set(t, n);
487
+ return console.debug(`[arborium] Grammar '${e}' already loading, waiting...`), s;
488
+ const a = E(e, t);
489
+ b.set(e, a);
519
490
  try {
520
- return await n;
491
+ return await a;
521
492
  } finally {
522
- w.delete(t);
493
+ b.delete(e);
523
494
  }
524
495
  }
525
- async function I(t, e) {
526
- if (await W(e), !$.has(t) && !c?.entries.some((a) => a.language === t))
527
- return console.debug(`[arborium] Grammar '${t}' not available`), null;
496
+ async function E(e, t) {
497
+ if (await _(t), !k.has(e) && !c?.entries.some((n) => n.language === e))
498
+ return console.debug(`[arborium] Grammar '${e}' not available`), null;
528
499
  try {
529
- const a = C(t, e), s = e.resolveJs === j.resolveJs ? ` from ${a}/grammar.js` : "";
530
- console.debug(`[arborium] Loading grammar '${t}'${s}`);
531
- const n = await e.resolveJs({ language: t, baseUrl: a, path: "grammar.js" }), r = await e.resolveWasm({ language: t, baseUrl: a, path: "grammar_bg.wasm" });
532
- await n.default({ module_or_path: r });
533
- const o = n.language_id();
534
- o !== t && console.warn(`[arborium] Language ID mismatch: expected '${t}', got '${o}'`);
535
- const i = n.injection_languages(), l = {
536
- languageId: t,
537
- injectionLanguages: i,
538
- module: n,
539
- parse: (m) => {
540
- const h = n.create_session();
500
+ const n = U(e, t), s = t.resolveJs === y.resolveJs ? ` from ${n}/grammar.js` : "";
501
+ console.debug(`[arborium] Loading grammar '${e}'${s}`);
502
+ const a = await t.resolveJs({
503
+ language: e,
504
+ baseUrl: n,
505
+ path: "grammar.js"
506
+ }), r = await t.resolveWasm({ language: e, baseUrl: n, path: "grammar_bg.wasm" });
507
+ await a.default({ module_or_path: r });
508
+ const o = a.language_id();
509
+ o !== e && console.warn(`[arborium] Language ID mismatch: expected '${e}', got '${o}'`);
510
+ const j = a.injection_languages(), w = {
511
+ languageId: e,
512
+ injectionLanguages: j,
513
+ module: a,
514
+ // UTF-8 parsing for Rust host
515
+ parseUtf8: (d) => {
516
+ const l = a.create_session();
541
517
  try {
542
- n.set_text(h, m);
543
- const p = n.parse(h);
518
+ a.set_text(l, d);
519
+ const i = a.parse(l);
544
520
  return {
545
- spans: p.spans || [],
546
- injections: p.injections || []
521
+ spans: i.spans || [],
522
+ injections: i.injections || []
547
523
  };
548
- } catch (p) {
549
- return console.error("[arborium] Parse error:", p), { spans: [], injections: [] };
524
+ } catch (i) {
525
+ return console.error("[arborium] Parse error:", i), { spans: [], injections: [] };
550
526
  } finally {
551
- n.free_session(h);
527
+ a.free_session(l);
528
+ }
529
+ },
530
+ // UTF-16 parsing for JavaScript public API
531
+ parseUtf16: (d) => {
532
+ const l = a.create_session();
533
+ try {
534
+ a.set_text(l, d);
535
+ const i = a.parse_utf16(l);
536
+ return {
537
+ spans: i.spans || [],
538
+ injections: i.injections || []
539
+ };
540
+ } catch (i) {
541
+ return console.error("[arborium] Parse error:", i), { spans: [], injections: [] };
542
+ } finally {
543
+ a.free_session(l);
552
544
  }
553
545
  }
554
546
  };
555
- return k.set(t, l), console.debug(`[arborium] Grammar '${t}' loaded successfully`), l;
556
- } catch (a) {
557
- return console.error(`[arborium] Failed to load grammar '${t}':`, a), null;
547
+ return h.set(e, w), console.debug(`[arborium] Grammar '${e}' loaded successfully`), w;
548
+ } catch (n) {
549
+ return console.error(`[arborium] Failed to load grammar '${e}':`, n), null;
558
550
  }
559
551
  }
560
- const y = /* @__PURE__ */ new Map();
552
+ const f = /* @__PURE__ */ new Map();
561
553
  let P = 1;
562
- function q(t) {
554
+ function q(e) {
563
555
  window.arboriumHost = {
564
556
  /** Check if a language is available (sync) */
565
- isLanguageAvailable(e) {
566
- return $.has(e) || k.has(e);
557
+ isLanguageAvailable(t) {
558
+ return k.has(t) || h.has(t);
567
559
  },
568
560
  /** Load a grammar and return a handle (async) */
569
- async loadGrammar(e) {
570
- const a = await v(e, t);
571
- if (!a) return 0;
572
- for (const [n, r] of y)
573
- if (r === a) return n;
561
+ async loadGrammar(t) {
562
+ const n = await v(t, e);
563
+ if (!n) return 0;
564
+ for (const [a, r] of f)
565
+ if (r === n) return a;
574
566
  const s = P++;
575
- return y.set(s, a), s;
567
+ return f.set(s, n), s;
576
568
  },
577
- /** Parse text using a grammar handle (sync) */
578
- parse(e, a) {
579
- const s = y.get(e);
580
- return s ? s.parse(a) : { spans: [], injections: [] };
569
+ /** Parse text using a grammar handle (sync) - returns UTF-8 offsets for Rust host */
570
+ parse(t, n) {
571
+ const s = f.get(t);
572
+ return s ? s.parseUtf8(n) : { spans: [], injections: [] };
581
573
  }
582
574
  };
583
575
  }
584
- function M(t) {
585
- if (t.hostUrl)
586
- return t.hostUrl;
587
- const e = t.cdn, a = t.version;
576
+ function C(e) {
577
+ if (e.hostUrl)
578
+ return e.hostUrl;
579
+ const t = e.cdn, n = e.version;
588
580
  let s;
589
- e === "jsdelivr" ? s = "https://cdn.jsdelivr.net/npm" : e === "unpkg" ? s = "https://unpkg.com" : s = e;
590
- const n = a === "latest" ? "" : `@${a}`;
591
- return `${s}/@arborium/arborium${n}/dist`;
581
+ t === "jsdelivr" ? s = "https://cdn.jsdelivr.net/npm" : t === "unpkg" ? s = "https://unpkg.com" : s = t;
582
+ const a = n === "latest" ? "" : `@${n}`;
583
+ return `${s}/@arborium/arborium${a}/dist`;
592
584
  }
593
- async function A(t) {
594
- return u || g || (g = (async () => {
595
- q(t);
596
- const e = M(t), a = `${e}/arborium_host.js`, s = `${e}/arborium_host_bg.wasm`;
597
- console.debug(`[arborium] Loading host from ${a}`);
585
+ async function I(e) {
586
+ return p || m || (m = (async () => {
587
+ q(e);
588
+ const t = C(e), n = `${t}/arborium_host.js`, s = `${t}/arborium_host_bg.wasm`;
589
+ console.debug(`[arborium] Loading host from ${n}`);
598
590
  try {
599
- const n = await import(
591
+ const a = await import(
600
592
  /* @vite-ignore */
601
- a
593
+ n
602
594
  );
603
- return await n.default(s), u = {
604
- highlight: n.highlight,
605
- isLanguageAvailable: n.isLanguageAvailable
606
- }, console.debug("[arborium] Host loaded successfully"), u;
607
- } catch (n) {
608
- return console.error("[arborium] Failed to load host:", n), null;
595
+ return await a.default(s), p = {
596
+ highlight: a.highlight,
597
+ isLanguageAvailable: a.isLanguageAvailable
598
+ }, console.debug("[arborium] Host loaded successfully"), p;
599
+ } catch (a) {
600
+ return console.error("[arborium] Failed to load host:", a), null;
609
601
  }
610
- })(), g);
602
+ })(), m);
611
603
  }
612
- async function F(t, e, a) {
613
- const s = L(a), n = await A(s);
614
- if (n)
604
+ async function S(e, t, n) {
605
+ const s = T(n), a = await I(s);
606
+ if (a)
615
607
  try {
616
- return n.highlight(t, e);
617
- } catch (i) {
618
- console.warn("Host highlight failed, falling back to JS:", i);
608
+ return a.highlight(e, t);
609
+ } catch (r) {
610
+ console.error("[arborium] Host highlight failed:", r);
619
611
  }
620
- const r = await v(t, s);
621
- if (!r)
622
- return f(e);
623
- const o = r.parse(e);
624
- return x(e, o.spans);
612
+ return L(t);
625
613
  }
626
- async function O(t, e) {
627
- const a = L(e), s = await v(t, a);
614
+ async function A(e, t) {
615
+ const n = T(t), s = await v(e, n);
628
616
  if (!s) return null;
629
- const { module: n } = s;
617
+ const { module: a } = s;
630
618
  return {
631
619
  languageId: () => s.languageId,
632
620
  injectionLanguages: () => s.injectionLanguages,
633
- highlight: async (r) => {
634
- const o = s.parse(r);
635
- return x(r, o.spans);
636
- },
637
- parse: (r) => s.parse(r),
621
+ highlight: async (r) => S(e, r, t),
622
+ // Public API returns UTF-16 offsets for JavaScript compatibility
623
+ parse: (r) => s.parseUtf16(r),
638
624
  createSession: () => {
639
- const r = n.create_session();
625
+ const r = a.create_session();
640
626
  return {
641
- setText: (o) => n.set_text(r, o),
627
+ setText: (o) => a.set_text(r, o),
628
+ // Session.parse() returns UTF-16 offsets for JavaScript compatibility
642
629
  parse: () => {
643
630
  try {
644
- const o = n.parse(r);
631
+ const o = a.parse_utf16(r);
645
632
  return {
646
633
  spans: o.spans || [],
647
634
  injections: o.injections || []
@@ -650,19 +637,19 @@ async function O(t, e) {
650
637
  return console.error("[arborium] Session parse error:", o), { spans: [], injections: [] };
651
638
  }
652
639
  },
653
- cancel: () => n.cancel(r),
654
- free: () => n.free_session(r)
640
+ cancel: () => a.cancel(r),
641
+ free: () => a.free_session(r)
655
642
  };
656
643
  },
657
644
  dispose: () => {
658
645
  }
659
646
  };
660
647
  }
661
- function L(t) {
662
- return t ? { ...b, ...t } : { ...b };
648
+ function T(e) {
649
+ return e ? { ...g, ...e } : { ...g };
663
650
  }
664
- function z(t) {
665
- b = { ...b, ...t };
651
+ function H(e) {
652
+ g = { ...g, ...e };
666
653
  }
667
654
  const G = [
668
655
  [/^#!.*\bpython[23]?\b/, "python"],
@@ -677,7 +664,7 @@ const G = [
677
664
  [/^#!.*\bsh\b/, "bash"],
678
665
  [/^#!.*\blua\b/, "lua"],
679
666
  [/^#!.*\bawk\b/, "awk"]
680
- ], R = [
667
+ ], M = [
681
668
  // Rust - distinctive keywords
682
669
  [/\b(fn|impl|trait|pub\s+fn|let\s+mut|&mut|->)\b/, "rust"],
683
670
  // Go - distinctive keywords
@@ -737,22 +724,22 @@ const G = [
737
724
  // Zig
738
725
  [/\b(pub\s+fn|const\s+\w+\s*=|@import\(|comptime)\b/, "zig"]
739
726
  ];
740
- function N(t) {
741
- const e = t.split(`
727
+ function F(e) {
728
+ const t = e.split(`
742
729
  `)[0];
743
- for (const [a, s] of G)
744
- if (a.test(e))
730
+ for (const [n, s] of G)
731
+ if (n.test(t))
745
732
  return s;
746
- for (const [a, s] of R)
747
- if (a.test(t))
733
+ for (const [n, s] of M)
734
+ if (n.test(e))
748
735
  return s;
749
736
  return null;
750
737
  }
751
- function B(t) {
752
- const e = t.match(/\blanguage-(\w+)\b/);
753
- if (e) return e[1];
754
- const a = t.match(/\blang-(\w+)\b/);
755
- if (a) return a[1];
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];
756
743
  const s = /* @__PURE__ */ new Set([
757
744
  "rust",
758
745
  "javascript",
@@ -789,13 +776,13 @@ function B(t) {
789
776
  "console",
790
777
  "sh"
791
778
  ]);
792
- for (const n of t.split(/\s+/))
793
- if (s.has(n.toLowerCase()))
794
- return n.toLowerCase();
779
+ for (const a of e.split(/\s+/))
780
+ if (s.has(a.toLowerCase()))
781
+ return a.toLowerCase();
795
782
  return null;
796
783
  }
797
- function J(t) {
798
- const e = {
784
+ function N(e) {
785
+ const t = {
799
786
  js: "javascript",
800
787
  ts: "typescript",
801
788
  py: "python",
@@ -815,20 +802,19 @@ function J(t) {
815
802
  plaintext: "text",
816
803
  plain: "text",
817
804
  txt: "text"
818
- }, a = t.toLowerCase();
819
- return e[a] || a;
805
+ }, n = e.toLowerCase();
806
+ return t[n] || n;
820
807
  }
821
808
  export {
822
- _ as availableLanguages,
823
- N as detectLanguage,
824
- B as extractLanguageFromClass,
825
- L as getConfig,
826
- F as highlight,
827
- H as highlights,
828
- O as loadGrammar,
829
- J as normalizeLanguage,
830
- U as pluginVersion,
831
- z as setConfig,
832
- x as spansToHtml
809
+ $ as availableLanguages,
810
+ F as detectLanguage,
811
+ z as extractLanguageFromClass,
812
+ T as getConfig,
813
+ S as highlight,
814
+ R as highlights,
815
+ A as loadGrammar,
816
+ N as normalizeLanguage,
817
+ x as pluginVersion,
818
+ H as setConfig
833
819
  };
834
820
  //# sourceMappingURL=arborium.js.map