@pie-element/shared-math-rendering-mathjax 0.1.2-next.20261003161149 → 0.1.2-next.20261006070837

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.
@@ -389,73 +389,116 @@ function me(e) {
389
389
  for (let t of [...e.querySelectorAll("mstack, mlongdiv")]) !t.closest("math") || t.closest("mjx-container") || t.replaceWith(t.localName === "mstack" ? ue(t) : fe(t));
390
390
  }
391
391
  //#endregion
392
+ //#region src/explorer-styles.ts
393
+ var he = "PIE-MJX-explorer-styles", R = "var(--pie-text, black)", ge = "var(--pie-background, #ffffff)", _e = "var(--pie-border-dark, #66686A)", z = "var(--pie-focus-outline, var(--pie-button-focus-outline, var(--pie-focus-checked-border, #1565C0)))", B = `color-mix(in srgb, ${z} 15%, transparent)`, ve = `
394
+ :root mjx-container [data-sre-highlight-1]:not([data-mjx-collapsed], rect) {
395
+ color: ${R} !important;
396
+ fill: ${R} !important;
397
+ }
398
+ :root mjx-container:not([data-mjx-clone-container]) [data-sre-highlight-1]:not([data-sre-enclosed], rect) {
399
+ background-color: ${B} !important;
400
+ }
401
+ :root mjx-container rect[data-sre-highlight-1]:not([data-sre-enclosed]) {
402
+ fill: ${B} !important;
403
+ }
404
+ :root mjx-container .mjx-selected {
405
+ outline: 2px solid ${z} !important;
406
+ }
407
+ :root mjx-container [data-sre-highlight-2] {
408
+ color: ${R} !important;
409
+ background-color: transparent !important;
410
+ fill: ${R} !important;
411
+ outline: 2px dashed ${z} !important;
412
+ }
413
+ :root mjx-container rect[data-sre-highlight-2] {
414
+ fill: transparent !important;
415
+ stroke: ${z} !important;
416
+ stroke-width: 2px !important;
417
+ vector-effect: non-scaling-stroke;
418
+ }
419
+ :root .MJX_LiveRegion, :root .MJX_HoverRegion, :root .MJX_ToolTip {
420
+ color: ${R} !important;
421
+ background-color: ${ge} !important;
422
+ border-color: ${_e} !important;
423
+ }
424
+ :root .MJX_LiveRegion > div, :root .MJX_HoverRegion > div {
425
+ color: ${R} !important;
426
+ background-color: ${B} !important;
427
+ }
428
+ `;
429
+ function ye(e = document) {
430
+ if (e.getElementById("PIE-MJX-explorer-styles")) return;
431
+ let t = e.createElement("style");
432
+ t.id = he, t.textContent = ve, e.head.appendChild(t);
433
+ }
434
+ //#endregion
392
435
  //#region src/unsupported-page.ts
393
- var R = "https://github.com/pie-framework/pie-players/blob/develop/docs/item-player/loading-strategies.md#one-mathjax-version-per-page", z = "pie-mathjax-version-conflict", B = Symbol.for("@pie-element/shared-math-rendering-mathjax/unsupported-page");
394
- function he(e, t) {
436
+ var V = "https://github.com/pie-framework/pie-players/blob/develop/docs/item-player/loading-strategies.md#one-mathjax-version-per-page", H = "pie-mathjax-version-conflict", U = Symbol.for("@pie-element/shared-math-rendering-mathjax/unsupported-page");
437
+ function be(e, t) {
395
438
  if (typeof window > "u") return;
396
439
  let n = globalThis;
397
- n[B] ??= {
440
+ n[U] ??= {
398
441
  logged: !1,
399
442
  conditions: []
400
443
  };
401
- let r = n[B];
444
+ let r = n[U];
402
445
  if (r.conditions.includes(e)) return;
403
446
  r.conditions.push(e);
404
- let i = `[math-rendering] Unsupported page (${e}): ${t}. PIE supports one MathJax major version per page; with MathJax 3 and 4 on one page, math rendering is best effort and may break. See ${R}`;
405
- r.logged || (r.logged = !0, console.error(i)), window.dispatchEvent(new CustomEvent(z, { detail: {
447
+ let i = `[math-rendering] Unsupported page (${e}): ${t}. PIE supports one MathJax major version per page; with MathJax 3 and 4 on one page, math rendering is best effort and may break. See ${V}`;
448
+ r.logged || (r.logged = !0, console.error(i)), window.dispatchEvent(new CustomEvent(H, { detail: {
406
449
  condition: e,
407
450
  message: i,
408
- docsUrl: R
451
+ docsUrl: V
409
452
  } }));
410
453
  }
411
454
  //#endregion
412
455
  //#region src/adapter.ts
413
- var ge = "https://cdn.jsdelivr.net/npm/mathjax@4.1.3/tex-mml-chtml.js", _e = {
456
+ var xe = "https://cdn.jsdelivr.net/npm/mathjax@4.1.3/tex-mml-chtml.js", Se = {
414
457
  parallelogram: "\\lower.2em{\\Huge\\unicode{x25B1}}",
415
458
  overarc: "\\overparen",
416
459
  napprox: "\\not\\approx",
417
460
  longdiv: "\\enclose{longdiv}",
418
461
  abs: ["\\left|#1\\right|", 1]
419
- }, ve = "[math-rendering] using $ is not advisable, please use $$..$$ or \\(...\\)", ye = /\\\(|\\\[|\$\$|\\\$|\\begin\{|\\(?:eq)?ref\{/, be = /\\\(|\\\[|\$|\\begin\{|\\(?:eq)?ref\{/, xe = /\\embed\{newLine\}\[\]/g, Se = [
462
+ }, Ce = "[math-rendering] using $ is not advisable, please use $$..$$ or \\(...\\)", we = /\\\(|\\\[|\$\$|\\\$|\\begin\{|\\(?:eq)?ref\{/, Te = /\\\(|\\\[|\$|\\begin\{|\\(?:eq)?ref\{/, Ee = /\\embed\{newLine\}\[\]/g, De = [
420
463
  ["$$", "$$"],
421
464
  ["$", "$"],
422
465
  ["\\[", "\\]"],
423
466
  ["\\(", "\\)"]
424
- ], V = Symbol.for("@pie-element/shared-math-rendering-mathjax/loading"), Ce = "MJX-CHTML-styles", we = "PIE-MJX-SVG-styles", H = "PIE-MathJax-Menu-Settings", Te = { "mjx-container[overflow=\"linebreak\"][display]": {
467
+ ], W = Symbol.for("@pie-element/shared-math-rendering-mathjax/loading"), Oe = "MJX-CHTML-styles", ke = "PIE-MJX-SVG-styles", G = "PIE-MathJax-Menu-Settings", Ae = { "mjx-container[overflow=\"linebreak\"][display]": {
425
468
  overflow: "auto clip",
426
469
  "min-width": "initial !important"
427
- } }, Ee = 200, De = 201;
428
- function U(e) {
470
+ } }, je = 200, Me = 201;
471
+ function K(e) {
429
472
  let t = [...e.matches("mjx-container") ? [e] : [], ...e.querySelectorAll("mjx-container")];
430
473
  for (let e of t) for (let t of [e, ...e.querySelectorAll("[data-latex],[data-latex-item]")]) t.removeAttribute("data-latex"), t.removeAttribute("data-latex-item");
431
474
  }
432
- function W(e) {
433
- for (let [t, n] of Se) if (e.startsWith(t) && e.endsWith(n)) return e.substring(t.length, e.length - n.length);
475
+ function q(e) {
476
+ for (let [t, n] of De) if (e.startsWith(t) && e.endsWith(n)) return e.substring(t.length, e.length - n.length);
434
477
  return e;
435
478
  }
436
- function Oe(e) {
437
- return W(e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e);
479
+ function Ne(e) {
480
+ return q(e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e);
438
481
  }
439
- var ke = "mathjax_ignore", G = "mathjax_process";
440
- function Ae(e, t) {
441
- let n = e.closest(`.${ke}, .${G}`);
442
- return n !== null && t.contains(n) && !n.classList.contains(G);
482
+ var Pe = "mathjax_ignore", J = "mathjax_process";
483
+ function Fe(e, t) {
484
+ let n = e.closest(`.${Pe}, .${J}`);
485
+ return n !== null && t.contains(n) && !n.classList.contains(J);
443
486
  }
444
- function je(e) {
487
+ function Ie(e) {
445
488
  for (let t of e.querySelectorAll("[data-latex]")) {
446
- if (t.dataset.mathHandled || t.closest("mjx-container") || Ae(t, e)) continue;
489
+ if (t.dataset.mathHandled || t.closest("mjx-container") || Fe(t, e)) continue;
447
490
  let n = t.textContent;
448
- n && (t.textContent = `\\(${Oe(n)}\\)`.replace(xe, "\\newline "), t.dataset.mathHandled = "true");
491
+ n && (t.textContent = `\\(${Ne(n)}\\)`.replace(Ee, "\\newline "), t.dataset.mathHandled = "true");
449
492
  }
450
493
  }
451
- function Me(e) {
494
+ function Le(e) {
452
495
  for (let t of e.querySelectorAll("math")) t.closest("mjx-container") || t.setAttribute("displaystyle", "true");
453
496
  }
454
- function Ne(e, t) {
497
+ function Re(e, t) {
455
498
  for (let t of e.querySelectorAll("math")) if (!t.closest("mjx-assistive-mml")) return !0;
456
- return (t ? be : ye).test(e.textContent ?? "");
499
+ return (t ? Te : we).test(e.textContent ?? "");
457
500
  }
458
- function Pe(e) {
501
+ function ze(e) {
459
502
  return new Promise((n, i) => {
460
503
  let { useSingleDollar: a = !1, accessibility: o = !0, loadFonts: s = !0, srcUrl: c } = e, l = {
461
504
  loader: {
@@ -463,17 +506,17 @@ function Pe(e) {
463
506
  failed: (e) => i(e),
464
507
  "output/svg": { ready: (e) => {
465
508
  let n = t();
466
- return K(n) && q(n), e;
509
+ return Y(n) && X(n), e;
467
510
  } }
468
511
  },
469
512
  startup: {
470
513
  typeset: !1,
471
514
  ready: () => {
472
- let e = t(), r = e?.startup, a = K(e);
473
- a && (q(e), Fe(e)), r?.defaultReady?.(), a && (Ie(r?.document), r?.document?.addStyles?.(Te)), Promise.resolve(r?.promise).then(() => n(), i);
515
+ let e = t(), r = e?.startup, a = Y(e);
516
+ a && (X(e), Be(e)), r?.defaultReady?.(), a && (Ve(r?.document), r?.document?.addStyles?.(Ae)), Promise.resolve(r?.promise).then(() => n(), i);
474
517
  }
475
518
  },
476
- tex: { macros: { ..._e } },
519
+ tex: { macros: { ...Se } },
477
520
  output: { displayOverflow: "linebreak" },
478
521
  options: {
479
522
  enableMenu: o,
@@ -485,80 +528,80 @@ function Pe(e) {
485
528
  a11y: { inTabOrder: !1 }
486
529
  }
487
530
  };
488
- a && l.tex && (console.warn(ve), l.tex.inlineMath = [["$", "$"], ["\\(", "\\)"]], l.tex.processEscapes = !0), s || (l.chtml = { fontURL: "" }), r(l, c || ge).catch(i);
531
+ a && l.tex && (console.warn(Ce), l.tex.inlineMath = [["$", "$"], ["\\(", "\\)"]], l.tex.processEscapes = !0), s || (l.chtml = { fontURL: "" }), r(l, c || xe).catch(i);
489
532
  });
490
533
  }
491
- function K(e) {
534
+ function Y(e) {
492
535
  return !!e?.version?.startsWith("4.");
493
536
  }
494
- function q(e) {
537
+ function X(e) {
495
538
  let t = e?._?.output, n = t?.chtml_ts?.CHTML;
496
539
  n && (n.STYLESHEETID = s);
497
540
  let r = t?.svg_ts?.SVG;
498
- r && (r.STYLESHEETID = we);
541
+ r && (r.STYLESHEETID = ke);
499
542
  }
500
- function Fe(e) {
543
+ function Be(e) {
501
544
  let t = e?._?.ui?.menu?.Menu?.Menu;
502
545
  if (t) {
503
- t.MENU_STORAGE = H;
546
+ t.MENU_STORAGE = G;
504
547
  try {
505
- let e = localStorage.getItem(H);
548
+ let e = localStorage.getItem(G);
506
549
  if (!e) return;
507
550
  let { assistiveMml: t, ...n } = JSON.parse(e);
508
551
  if (t === void 0) return;
509
- Object.keys(n).length ? localStorage.setItem(H, JSON.stringify(n)) : localStorage.removeItem(H);
552
+ Object.keys(n).length ? localStorage.setItem(G, JSON.stringify(n)) : localStorage.removeItem(G);
510
553
  } catch {}
511
554
  }
512
555
  }
513
- function Ie(e) {
556
+ function Ve(e) {
514
557
  if (!e) return;
515
558
  let t = /* @__PURE__ */ new WeakSet(), n = (e) => {
516
559
  let n = e.typesetRoot;
517
- !n || t.has(n) || (U(n), t.add(n));
560
+ !n || t.has(n) || (K(n), t.add(n));
518
561
  };
519
- e.addRenderAction?.("pie-strip-latex", De, (e) => {
562
+ e.addRenderAction?.("pie-strip-latex", Me, (e) => {
520
563
  for (let t of e.math ?? []) n(t);
521
564
  return !1;
522
565
  }, (e) => {
523
566
  let t = e.typesetRoot;
524
- return t && U(t), !1;
567
+ return t && K(t), !1;
525
568
  });
526
569
  let r = e.outputJax?.chtmlStyles;
527
- r?.id === Ce && (r.id = s), Le();
570
+ r?.id === Oe && (r.id = s), Ue();
528
571
  }
529
- function J(e) {
572
+ function Z(e) {
530
573
  return e instanceof HTMLStyleElement && c.includes(e.id);
531
574
  }
532
- function Y(e) {
533
- he("foreign-output-stylesheet", `another MathJax added <style id="${e.id}"> to <head>`);
575
+ function He(e) {
576
+ be("foreign-output-stylesheet", `another MathJax added <style id="${e.id}"> to <head>`);
534
577
  }
535
- function Le() {
536
- let e = document.head, t = [...e.children].find(J);
578
+ function Ue() {
579
+ let e = document.head, t = [...e.children].find(Z);
537
580
  if (t) {
538
- Y(t);
581
+ He(t);
539
582
  return;
540
583
  }
541
584
  let n = new MutationObserver((e) => {
542
585
  for (let t of e) {
543
- let e = [...t.addedNodes].find(J);
586
+ let e = [...t.addedNodes].find(Z);
544
587
  if (e) {
545
- Y(e), n.disconnect();
588
+ He(e), n.disconnect();
546
589
  return;
547
590
  }
548
591
  }
549
592
  });
550
593
  n.observe(e, { childList: !0 });
551
594
  }
552
- function Re(e) {
595
+ function We(e) {
553
596
  let t = e?.math;
554
597
  if (!t?.remove) return;
555
- let n = [...t].filter((e) => (e.state?.() ?? 0) >= Ee && e.typesetRoot?.isConnected === !1);
598
+ let n = [...t].filter((e) => (e.state?.() ?? 0) >= je && e.typesetRoot?.isConnected === !1);
556
599
  if (n.length !== 0) {
557
600
  for (let e of [...n].reverse()) e.clear?.();
558
601
  t.remove(...n);
559
602
  }
560
603
  }
561
- function ze(e) {
604
+ function Ge(e) {
562
605
  return new Promise((n, r) => {
563
606
  let i = e.startup ?? {};
564
607
  e.startup = i;
@@ -569,80 +612,80 @@ function ze(e) {
569
612
  };
570
613
  });
571
614
  }
572
- function Be(e) {
615
+ function Ke(e) {
573
616
  let n = t();
574
- return n ? n.version ? n.startup?.promise ? Promise.resolve(n.startup.promise).then(() => void 0) : Promise.resolve() : ze(n) : Pe(e);
617
+ return n ? n.version ? n.startup?.promise ? Promise.resolve(n.startup.promise).then(() => void 0) : Promise.resolve() : Ge(n) : ze(e);
575
618
  }
576
- function Ve(e) {
577
- return Be(e).then(() => {
619
+ function qe(e) {
620
+ return Ke(e).then(() => {
578
621
  typeof t()?.typesetPromise != "function" && console.warn("[mathjax-renderer] MathJax on this page has no typesetPromise; math stays untypeset.");
579
622
  });
580
623
  }
581
- function He(e) {
582
- let t = i, n = t[V];
583
- return n || (n = Ve(e), t[V] = n), n;
624
+ function Je(e) {
625
+ let t = i, n = t[W];
626
+ return n || (n = qe(e), t[W] = n), n;
584
627
  }
585
- function X(e = {}) {
628
+ function Ye(e = {}) {
586
629
  let n = e.useSingleDollar ?? !1;
587
630
  return async (r) => {
588
631
  if (typeof window > "u") return;
589
- je(r), f(r), Me(r), me(r);
590
- let i = He(e);
591
- if (!Ne(r, n)) {
632
+ Ie(r), f(r), Le(r), me(r);
633
+ let i = Je(e);
634
+ if (!Re(r, n)) {
592
635
  i.catch(() => {});
593
636
  return;
594
637
  }
595
638
  await i;
596
639
  let a = t();
597
640
  if (await a?.startup?.promise, typeof a?.typesetPromise == "function") {
598
- Re(a.startup?.document);
641
+ ye(), We(a.startup?.document);
599
642
  try {
600
643
  await a.typesetPromise([r]);
601
644
  } catch (e) {
602
645
  throw a.typesetClear?.([r]), e;
603
646
  }
604
- U(r);
647
+ K(r);
605
648
  }
606
649
  };
607
650
  }
608
- function Ue() {
651
+ function Xe() {
609
652
  return [];
610
653
  }
611
654
  //#endregion
612
655
  //#region src/render-math.ts
613
- var We = "@pie-lib/math-rendering", Ge = "@pie-lib/math-rendering@2", Ke = "pie-print", qe = 50, Je = 1e4, Z = null;
614
- function Ye() {
615
- return !!window[Ge]?.opts?.useSingleDollar;
656
+ var Ze = "@pie-lib/math-rendering", Qe = "@pie-lib/math-rendering@2", $e = "pie-print", et = 50, tt = 1e4, nt = null;
657
+ function rt() {
658
+ return !!window[Qe]?.opts?.useSingleDollar;
616
659
  }
617
- function Xe() {
618
- return Z ||= X({ useSingleDollar: Ye() }), Z;
660
+ function it() {
661
+ return nt ||= Ye({ useSingleDollar: rt() }), nt;
619
662
  }
620
663
  function Q() {
621
664
  if (typeof window > "u") return null;
622
- let e = window[We];
665
+ let e = window[Ze];
623
666
  return typeof e?.renderMath == "function" && e.renderMath !== $ ? e : null;
624
667
  }
625
- function Ze(e) {
668
+ function at(e) {
626
669
  let t = e;
627
670
  for (; t;) {
628
- if (t instanceof Element && t.localName === Ke) return t;
671
+ if (t instanceof Element && t.localName === $e) return t;
629
672
  t = t instanceof ShadowRoot ? t.host : t.parentNode;
630
673
  }
631
674
  return null;
632
675
  }
633
- function Qe() {
676
+ function ot() {
634
677
  let e = window.renderMath;
635
678
  return typeof e == "function" ? e : null;
636
679
  }
637
- async function $e(e) {
638
- let t = Ze(e);
680
+ async function st(e) {
681
+ let t = at(e);
639
682
  if (!t) return null;
640
- let n = Qe();
683
+ let n = ot();
641
684
  if (n || t.mathRenderingModuleUrlImported !== !0) return n;
642
- let r = Date.now() + Je;
685
+ let r = Date.now() + tt;
643
686
  for (; Date.now() < r;) {
644
- await new Promise((e) => setTimeout(e, qe));
645
- let e = Qe();
687
+ await new Promise((e) => setTimeout(e, et));
688
+ let e = ot();
646
689
  if (e) return e;
647
690
  }
648
691
  return null;
@@ -651,14 +694,14 @@ var $ = async (e) => {
651
694
  if (typeof window > "u") return;
652
695
  let t = typeof e == "string", n;
653
696
  t ? (n = document.createElement("div"), n.innerHTML = e) : n = e || document.body;
654
- let r = Q(), i = r || t ? null : await $e(n);
655
- return r ? await r.renderMath?.(n) : i && i !== $ ? await i(n) : await Xe()(n), t ? n.innerHTML : void 0;
656
- }, et = (e, t) => {
697
+ let r = Q(), i = r || t ? null : await st(n);
698
+ return r ? await r.renderMath?.(n) : i && i !== $ ? await i(n) : await it()(n), t ? n.innerHTML : void 0;
699
+ }, ct = (e, t) => {
657
700
  let n = Q()?.wrapMath?.(e, t);
658
701
  if (n != null) return n;
659
702
  let [r, i] = t === "dollar" || t === "double_dollar" ? ["$", "$"] : ["\\(", "\\)"];
660
- return `${r}${W(e)}${i}`;
661
- }, tt = (e) => {
703
+ return `${r}${q(e)}${i}`;
704
+ }, lt = (e) => {
662
705
  let t = e.trim();
663
706
  return t.startsWith("\\[") && t.endsWith("\\]") ? {
664
707
  unwrapped: t.slice(2, -2).trim(),
@@ -685,6 +728,6 @@ var $ = async (e) => {
685
728
  close: "$"
686
729
  }
687
730
  } : { unwrapped: t };
688
- }, nt = (e) => Q()?.mmlToLatex?.(e) ?? e;
731
+ }, ut = (e) => Q()?.mmlToLatex?.(e) ?? e;
689
732
  //#endregion
690
- export { z as MATHJAX_CONFLICT_EVENT, R as UNSUPPORTED_PAGE_DOCS_URL, X as createMathjaxRenderer, Ue as getMathjaxCssUrls, nt as mmlToLatex, $ as renderMath, tt as unWrapMath, et as wrapMath };
733
+ export { H as MATHJAX_CONFLICT_EVENT, V as UNSUPPORTED_PAGE_DOCS_URL, Ye as createMathjaxRenderer, Xe as getMathjaxCssUrls, ut as mmlToLatex, $ as renderMath, lt as unWrapMath, ct as wrapMath };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Theme colours for the MathJax explorer: the highlight on the explored expression, the outline on
3
+ * the current selection, and the speech, braille, magnifier and tooltip regions. MathJax paints
4
+ * them from its own palette, which follows the OS colour scheme.
5
+ *
6
+ * Each rule is MathJax 4.1.3's own selector under `:root`, one pseudo-class above it, so it wins
7
+ * over MathJax's `!important` declarations wherever either stylesheet loads. Deliberate trades:
8
+ *
9
+ * - The theme colours replace any highlight colours a student picks in the MathJax menu.
10
+ * - The regions are appended to `document.body`, so they resolve only a theme set on the document,
11
+ * and take the fallbacks under a theme scoped to an element.
12
+ * - The stylesheet is page-global, so a host's own MathJax 4 explorer takes it too.
13
+ */
14
+ export declare const EXPLORER_STYLESHEET_ID = "PIE-MJX-explorer-styles";
15
+ export declare const EXPLORER_CSS = "\n:root mjx-container [data-sre-highlight-1]:not([data-mjx-collapsed], rect) {\n color: var(--pie-text, black) !important;\n fill: var(--pie-text, black) !important;\n}\n:root mjx-container:not([data-mjx-clone-container]) [data-sre-highlight-1]:not([data-sre-enclosed], rect) {\n background-color: color-mix(in srgb, var(--pie-focus-outline, var(--pie-button-focus-outline, var(--pie-focus-checked-border, #1565C0))) 15%, transparent) !important;\n}\n:root mjx-container rect[data-sre-highlight-1]:not([data-sre-enclosed]) {\n fill: color-mix(in srgb, var(--pie-focus-outline, var(--pie-button-focus-outline, var(--pie-focus-checked-border, #1565C0))) 15%, transparent) !important;\n}\n:root mjx-container .mjx-selected {\n outline: 2px solid var(--pie-focus-outline, var(--pie-button-focus-outline, var(--pie-focus-checked-border, #1565C0))) !important;\n}\n:root mjx-container [data-sre-highlight-2] {\n color: var(--pie-text, black) !important;\n background-color: transparent !important;\n fill: var(--pie-text, black) !important;\n outline: 2px dashed var(--pie-focus-outline, var(--pie-button-focus-outline, var(--pie-focus-checked-border, #1565C0))) !important;\n}\n:root mjx-container rect[data-sre-highlight-2] {\n fill: transparent !important;\n stroke: var(--pie-focus-outline, var(--pie-button-focus-outline, var(--pie-focus-checked-border, #1565C0))) !important;\n stroke-width: 2px !important;\n vector-effect: non-scaling-stroke;\n}\n:root .MJX_LiveRegion, :root .MJX_HoverRegion, :root .MJX_ToolTip {\n color: var(--pie-text, black) !important;\n background-color: var(--pie-background, #ffffff) !important;\n border-color: var(--pie-border-dark, #66686A) !important;\n}\n:root .MJX_LiveRegion > div, :root .MJX_HoverRegion > div {\n color: var(--pie-text, black) !important;\n background-color: color-mix(in srgb, var(--pie-focus-outline, var(--pie-button-focus-outline, var(--pie-focus-checked-border, #1565C0))) 15%, transparent) !important;\n}\n";
16
+ /**
17
+ * Adds the explorer theme stylesheet to the document's `<head>` once. Every element bundles its
18
+ * own copy of this adapter, so the stylesheet id is the record that one copy has added it.
19
+ */
20
+ export declare function injectExplorerStyles(doc?: Document): void;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @pie-element/math-rendering-mathjax
3
3
  *
4
- * MathJax adapter for PIE math rendering (~2.7MB)
4
+ * MathJax adapter for PIE math rendering.
5
5
  * Full-featured LaTeX and MathML rendering with accessibility support.
6
6
  *
7
7
  * It also implements the legacy @pie-lib/math-rendering API (renderMath, wrapMath,
package/dist/index.js CHANGED
@@ -160,29 +160,29 @@ function ae(e, t, n) {
160
160
  scale: te.test(o) ? o : "0.6"
161
161
  };
162
162
  }
163
- function k(e) {
163
+ function oe(e) {
164
164
  let t = C(e, "mslinethickness") ?? "medium", n = _[t] ?? (y.test(t) ? t : "0.07em"), r = e.getAttribute("mathcolor")?.trim() ?? "";
165
165
  return `${n} solid ${ee.test(r) ? r : "currentColor"}`;
166
166
  }
167
- function oe(e, t, n) {
167
+ function se(e, t, n) {
168
168
  let r = Math.max(0, w(e, "length"));
169
169
  return {
170
170
  kind: "line",
171
171
  length: r,
172
172
  anchor: E(r, n.stackAlign),
173
173
  position: t,
174
- border: k(e)
174
+ border: oe(e)
175
175
  };
176
176
  }
177
- function A(e, t, n, r, i) {
177
+ function k(e, t, n, r, i) {
178
178
  e.forEach((e, a) => {
179
179
  let o = t + a * n + w(e, "position");
180
180
  switch (e.localName) {
181
181
  case "msgroup":
182
- A([...e.children], o, w(e, "shift"), r, i);
182
+ k([...e.children], o, w(e, "shift"), r, i);
183
183
  break;
184
184
  case "msline":
185
- i.push(oe(e, o, r));
185
+ i.push(se(e, o, r));
186
186
  break;
187
187
  case "mscarries":
188
188
  i.push(ae(e, o, r));
@@ -195,16 +195,16 @@ function A(e, t, n, r, i) {
195
195
  }
196
196
  });
197
197
  }
198
- function j(e) {
198
+ function A(e) {
199
199
  return -e.anchor - e.position;
200
200
  }
201
- function M(e) {
201
+ function j(e) {
202
202
  return e.kind === "digits" ? e.cells.length : e.kind === "carries" ? e.carries.length : e.length;
203
203
  }
204
- function N(e) {
205
- return j(e) + M(e) - 1;
204
+ function M(e) {
205
+ return A(e) + j(e) - 1;
206
206
  }
207
- function se(e, t, n, r) {
207
+ function ce(e, t, n, r) {
208
208
  let i = (e) => b(r.document, "mpadded", [t], {
209
209
  width: "0",
210
210
  ...e ? { lspace: e } : {}
@@ -230,7 +230,7 @@ function se(e, t, n, r) {
230
230
  default: return a("mover", [e, i("-0.5width")]);
231
231
  }
232
232
  }
233
- function ce(e, t, n) {
233
+ function le(e, t, n) {
234
234
  let r = b(n.document, "menclose", [e], {
235
235
  notation: t.join(" "),
236
236
  "data-padding": "0.1em",
@@ -241,38 +241,38 @@ function ce(e, t, n) {
241
241
  width: `-${2 * i}em`
242
242
  }) : r;
243
243
  }
244
- function le(e, t, n, r, i) {
245
- let a = e && t.crossout.length ? ce(e, t.crossout, i) : e;
244
+ function ue(e, t, n, r, i) {
245
+ let a = e && t.crossout.length ? le(e, t.crossout, i) : e;
246
246
  if (!t.content) return a;
247
247
  let o = b(i.document, "mstyle", [t.content], { scriptsizemultiplier: r });
248
- return se(a ?? S(i), o, n, i);
248
+ return ce(a ?? S(i), o, n, i);
249
249
  }
250
- function P(e, t) {
251
- return e.carries[t - j(e)] ?? null;
250
+ function N(e, t) {
251
+ return e.carries[t - A(e)] ?? null;
252
252
  }
253
- function ue(e, t, n, r) {
253
+ function de(e, t, n, r) {
254
254
  let i = e.content;
255
255
  n.forEach((e, a) => {
256
- let o = n.length - 1 - a, s = n[o], c = P(s, t), l = n.slice(0, o).some((e) => P(e, t));
256
+ let o = n.length - 1 - a, s = n[o], c = N(s, t), l = n.slice(0, o).some((e) => N(e, t));
257
257
  if (!c && !l) return;
258
258
  let u = c ?? {
259
259
  content: S(r),
260
260
  location: "n",
261
261
  crossout: []
262
262
  }, d = a === 0 ? u.location : "n";
263
- i = le(i, u, d, s.scale, r);
263
+ i = ue(i, u, d, s.scale, r);
264
264
  }), e.content = i;
265
265
  }
266
- function F(e, t) {
267
- let n = e.filter((e) => M(e) > 0), r = Math.min(0, ...n.map(j)), i = Math.max(r, ...n.map(N)) - r + 1, a = -r, o = [], s = /* @__PURE__ */ new Map(), c = () => Array.from({ length: i }, () => ({
266
+ function P(e, t) {
267
+ let n = e.filter((e) => j(e) > 0), r = Math.min(0, ...n.map(A)), i = Math.max(r, ...n.map(M)) - r + 1, a = -r, o = [], s = /* @__PURE__ */ new Map(), c = () => Array.from({ length: i }, () => ({
268
268
  content: null,
269
269
  borders: {}
270
- })), l = (e) => e.length === 0 ? Array.from({ length: i }, (e, t) => t) : Array.from({ length: e.length }, (t, n) => a + j(e) + n), u = [], d = [], f = (e) => {
270
+ })), l = (e) => e.length === 0 ? Array.from({ length: i }, (e, t) => t) : Array.from({ length: e.length }, (t, n) => a + A(e) + n), u = [], d = [], f = (e) => {
271
271
  let n = c();
272
272
  e.cells.forEach((t, r) => {
273
- n[a + j(e) + r].content = t;
273
+ n[a + A(e) + r].content = t;
274
274
  }), u.length && n.forEach((e, n) => {
275
- ue(e, n - a, u, t);
275
+ de(e, n - a, u, t);
276
276
  });
277
277
  for (let e of d) for (let t of l(e)) n[t].borders.top = e.border;
278
278
  u = [], d = [], s.set(e, o.length), o.push(n);
@@ -292,7 +292,7 @@ function F(e, t) {
292
292
  origin: a
293
293
  };
294
294
  }
295
- function I(e, { rows: t }, n) {
295
+ function F(e, { rows: t }, n) {
296
296
  let r = b(n.document, "mtable", t.map((e) => b(n.document, "mtr", e.map((e) => {
297
297
  let t = Object.entries(e.borders).map(([e, t]) => `border-${e}:${t}`).join(";");
298
298
  return b(n.document, "mtd", [e.content], {
@@ -304,21 +304,21 @@ function I(e, { rows: t }, n) {
304
304
  let i = C(e, "charspacing") ?? "medium", a = C(e, "charalign");
305
305
  return r.setAttribute("columnspacing", v[i] ?? (y.test(i) ? i : v.medium)), r.setAttribute("columnalign", a === "left" || a === "center" ? a : "right"), r.setAttribute("rowspacing", "0"), r.setAttribute("align", e.getAttribute("align") ?? "baseline"), r;
306
306
  }
307
- function L(e) {
307
+ function I(e) {
308
308
  return {
309
309
  document: e.ownerDocument,
310
310
  stackAlign: C(e, "stackalign") ?? "decimalpoint",
311
311
  decimalPoint: e.closest("[decimalpoint]")?.getAttribute("decimalpoint")?.trim().charAt(0) || "."
312
312
  };
313
313
  }
314
- function de(e) {
315
- let t = L(e), n = [];
316
- return A([...e.children], 0, 0, t, n), I(e, F(n, t), t);
314
+ function fe(e) {
315
+ let t = I(e), n = [];
316
+ return k([...e.children], 0, 0, t, n), F(e, P(n, t), t);
317
317
  }
318
- function R(e, t, n, r, i, a) {
318
+ function L(e, t, n, r, i, a) {
319
319
  for (let o = n; o <= r; o++) e[t][o].borders[i] = a;
320
320
  }
321
- function fe(e, t) {
321
+ function pe(e, t) {
322
322
  let n = x(t, ")");
323
323
  return n.setAttribute("minsize", "1.2em"), [b(t.document, "mrow", [e, b(t.document, "mspace", [], { width: "0.2em" })]), b(t.document, "mpadded", [n], {
324
324
  voffset: "0.1em",
@@ -327,9 +327,9 @@ function fe(e, t) {
327
327
  height: "-0.2em"
328
328
  })];
329
329
  }
330
- function pe(e) {
331
- let t = L(e), [n, r, ...i] = [...e.children], a = n && !T(n) ? n : null, o = r && !T(r) ? r : null, s = C(e, "longdivstyle") ?? "lefttop", c = k(e), l = [];
332
- A(i, 0, 0, t, l);
330
+ function me(e) {
331
+ let t = I(e), [n, r, ...i] = [...e.children], a = n && !T(n) ? n : null, o = r && !T(r) ? r : null, s = C(e, "longdivstyle") ?? "lefttop", c = oe(e), l = [];
332
+ k(i, 0, 0, t, l);
333
333
  let u = l.find((e) => e.kind === "digits");
334
334
  u || (u = {
335
335
  kind: "digits",
@@ -356,35 +356,35 @@ function pe(e) {
356
356
  case "righttop":
357
357
  case "stackedleftlinetop":
358
358
  case "lefttop":
359
- o && A([o], 0, 0, t, d), l.splice(l.indexOf(u), 0, ...d), s === "righttop" ? p(a) : s === "stackedleftlinetop" ? f(a) : f(...fe(a, t));
359
+ o && k([o], 0, 0, t, d), l.splice(l.indexOf(u), 0, ...d), s === "righttop" ? p(a) : s === "stackedleftlinetop" ? f(a) : f(...pe(a, t));
360
360
  break;
361
361
  }
362
- let m = F(l, t), h = m.rows, g = m.rowOf.get(u) ?? 0, _ = (e) => m.origin + j(u) + e, v = Math.max(_(u.cells.length - 1), ...d.map((e) => m.origin + N(e)));
362
+ let m = P(l, t), h = m.rows, g = m.rowOf.get(u) ?? 0, _ = (e) => m.origin + A(u) + e, v = Math.max(_(u.cells.length - 1), ...d.map((e) => m.origin + M(e)));
363
363
  switch (s) {
364
364
  case "left/\\right":
365
365
  case "left)(right":
366
366
  case ":right=right": break;
367
367
  case "righttop": {
368
368
  let e = h[g][_(u.cells.length - 1)];
369
- e.borders.left = c, e.borders.bottom = c, R(h, g, _(0), _(u.cells.length - 1), "top", c);
369
+ e.borders.left = c, e.borders.bottom = c, L(h, g, _(0), _(u.cells.length - 1), "top", c);
370
370
  break;
371
371
  }
372
372
  case "stackedleftlinetop": {
373
373
  let e = h[g][_(0)];
374
- e.borders.right = c, e.borders.bottom = c, R(h, g, _(1), v, "top", c);
374
+ e.borders.right = c, e.borders.bottom = c, L(h, g, _(1), v, "top", c);
375
375
  break;
376
376
  }
377
377
  case "stackedrightright":
378
378
  case "mediumstackedrightright":
379
379
  case "shortstackedrightright":
380
380
  case "stackedleftleft":
381
- me(h, g, s, a, o, c, t);
381
+ he(h, g, s, a, o, c, t);
382
382
  break;
383
- default: R(h, g, _(1), v, "top", c);
383
+ default: L(h, g, _(1), v, "top", c);
384
384
  }
385
- return I(e, m, t);
385
+ return F(e, m, t);
386
386
  }
387
- function me(e, t, n, r, i, a, o) {
387
+ function he(e, t, n, r, i, a, o) {
388
388
  let s = n === "stackedleftleft", c = s ? "right" : "left", l = (e) => e && b(o.document, "mpadded", [e], {
389
389
  lspace: "0.2em",
390
390
  width: "+0.4em"
@@ -404,57 +404,100 @@ function me(e, t, n, r, i, a, o) {
404
404
  }) : o === t + 1 ? (u.content = l(i), n !== "shortstackedrightright" && (u.borders[c] = a)) : o > t + 1 && (n === "stackedrightright" || s) && (u.borders[c] = a), s ? e.unshift(u) : e.push(u);
405
405
  });
406
406
  }
407
- function he(e) {
408
- for (let t of [...e.querySelectorAll("mstack, mlongdiv")]) !t.closest("math") || t.closest("mjx-container") || t.replaceWith(t.localName === "mstack" ? de(t) : pe(t));
407
+ function ge(e) {
408
+ for (let t of [...e.querySelectorAll("mstack, mlongdiv")]) !t.closest("math") || t.closest("mjx-container") || t.replaceWith(t.localName === "mstack" ? fe(t) : me(t));
409
+ }
410
+ //#endregion
411
+ //#region src/explorer-styles.ts
412
+ var _e = "PIE-MJX-explorer-styles", R = "var(--pie-text, black)", ve = "var(--pie-background, #ffffff)", ye = "var(--pie-border-dark, #66686A)", z = "var(--pie-focus-outline, var(--pie-button-focus-outline, var(--pie-focus-checked-border, #1565C0)))", B = `color-mix(in srgb, ${z} 15%, transparent)`, be = `
413
+ :root mjx-container [data-sre-highlight-1]:not([data-mjx-collapsed], rect) {
414
+ color: ${R} !important;
415
+ fill: ${R} !important;
416
+ }
417
+ :root mjx-container:not([data-mjx-clone-container]) [data-sre-highlight-1]:not([data-sre-enclosed], rect) {
418
+ background-color: ${B} !important;
419
+ }
420
+ :root mjx-container rect[data-sre-highlight-1]:not([data-sre-enclosed]) {
421
+ fill: ${B} !important;
422
+ }
423
+ :root mjx-container .mjx-selected {
424
+ outline: 2px solid ${z} !important;
425
+ }
426
+ :root mjx-container [data-sre-highlight-2] {
427
+ color: ${R} !important;
428
+ background-color: transparent !important;
429
+ fill: ${R} !important;
430
+ outline: 2px dashed ${z} !important;
431
+ }
432
+ :root mjx-container rect[data-sre-highlight-2] {
433
+ fill: transparent !important;
434
+ stroke: ${z} !important;
435
+ stroke-width: 2px !important;
436
+ vector-effect: non-scaling-stroke;
437
+ }
438
+ :root .MJX_LiveRegion, :root .MJX_HoverRegion, :root .MJX_ToolTip {
439
+ color: ${R} !important;
440
+ background-color: ${ve} !important;
441
+ border-color: ${ye} !important;
442
+ }
443
+ :root .MJX_LiveRegion > div, :root .MJX_HoverRegion > div {
444
+ color: ${R} !important;
445
+ background-color: ${B} !important;
446
+ }
447
+ `;
448
+ function xe(e = document) {
449
+ if (e.getElementById("PIE-MJX-explorer-styles")) return;
450
+ let t = e.createElement("style");
451
+ t.id = _e, t.textContent = be, e.head.appendChild(t);
409
452
  }
410
453
  //#endregion
411
454
  //#region src/adapter.ts
412
- var ge = "https://cdn.jsdelivr.net/npm/mathjax@4.1.3/tex-mml-chtml.js", _e = {
455
+ var Se = "https://cdn.jsdelivr.net/npm/mathjax@4.1.3/tex-mml-chtml.js", Ce = {
413
456
  parallelogram: "\\lower.2em{\\Huge\\unicode{x25B1}}",
414
457
  overarc: "\\overparen",
415
458
  napprox: "\\not\\approx",
416
459
  longdiv: "\\enclose{longdiv}",
417
460
  abs: ["\\left|#1\\right|", 1]
418
- }, ve = "[math-rendering] using $ is not advisable, please use $$..$$ or \\(...\\)", ye = /\\\(|\\\[|\$\$|\\\$|\\begin\{|\\(?:eq)?ref\{/, be = /\\\(|\\\[|\$|\\begin\{|\\(?:eq)?ref\{/, xe = /\\embed\{newLine\}\[\]/g, Se = [
461
+ }, we = "[math-rendering] using $ is not advisable, please use $$..$$ or \\(...\\)", Te = /\\\(|\\\[|\$\$|\\\$|\\begin\{|\\(?:eq)?ref\{/, Ee = /\\\(|\\\[|\$|\\begin\{|\\(?:eq)?ref\{/, De = /\\embed\{newLine\}\[\]/g, Oe = [
419
462
  ["$$", "$$"],
420
463
  ["$", "$"],
421
464
  ["\\[", "\\]"],
422
465
  ["\\(", "\\)"]
423
- ], z = Symbol.for("@pie-element/shared-math-rendering-mathjax/loading"), Ce = "MJX-CHTML-styles", we = "PIE-MJX-SVG-styles", B = "PIE-MathJax-Menu-Settings", Te = { "mjx-container[overflow=\"linebreak\"][display]": {
466
+ ], V = Symbol.for("@pie-element/shared-math-rendering-mathjax/loading"), ke = "MJX-CHTML-styles", Ae = "PIE-MJX-SVG-styles", H = "PIE-MathJax-Menu-Settings", je = { "mjx-container[overflow=\"linebreak\"][display]": {
424
467
  overflow: "auto clip",
425
468
  "min-width": "initial !important"
426
- } }, Ee = 200, De = 201;
427
- function V(e) {
469
+ } }, Me = 200, Ne = 201;
470
+ function U(e) {
428
471
  let t = [...e.matches("mjx-container") ? [e] : [], ...e.querySelectorAll("mjx-container")];
429
472
  for (let e of t) for (let t of [e, ...e.querySelectorAll("[data-latex],[data-latex-item]")]) t.removeAttribute("data-latex"), t.removeAttribute("data-latex-item");
430
473
  }
431
- function H(e) {
432
- for (let [t, n] of Se) if (e.startsWith(t) && e.endsWith(n)) return e.substring(t.length, e.length - n.length);
474
+ function W(e) {
475
+ for (let [t, n] of Oe) if (e.startsWith(t) && e.endsWith(n)) return e.substring(t.length, e.length - n.length);
433
476
  return e;
434
477
  }
435
- function Oe(e) {
436
- return H(e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e);
478
+ function Pe(e) {
479
+ return W(e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e);
437
480
  }
438
- var ke = "mathjax_ignore", U = "mathjax_process";
439
- function Ae(e, t) {
440
- let n = e.closest(`.${ke}, .${U}`);
441
- return n !== null && t.contains(n) && !n.classList.contains(U);
481
+ var Fe = "mathjax_ignore", G = "mathjax_process";
482
+ function Ie(e, t) {
483
+ let n = e.closest(`.${Fe}, .${G}`);
484
+ return n !== null && t.contains(n) && !n.classList.contains(G);
442
485
  }
443
- function je(e) {
486
+ function Le(e) {
444
487
  for (let t of e.querySelectorAll("[data-latex]")) {
445
- if (t.dataset.mathHandled || t.closest("mjx-container") || Ae(t, e)) continue;
488
+ if (t.dataset.mathHandled || t.closest("mjx-container") || Ie(t, e)) continue;
446
489
  let n = t.textContent;
447
- n && (t.textContent = `\\(${Oe(n)}\\)`.replace(xe, "\\newline "), t.dataset.mathHandled = "true");
490
+ n && (t.textContent = `\\(${Pe(n)}\\)`.replace(De, "\\newline "), t.dataset.mathHandled = "true");
448
491
  }
449
492
  }
450
- function Me(e) {
493
+ function Re(e) {
451
494
  for (let t of e.querySelectorAll("math")) t.closest("mjx-container") || t.setAttribute("displaystyle", "true");
452
495
  }
453
- function W(e, t) {
496
+ function ze(e, t) {
454
497
  for (let t of e.querySelectorAll("math")) if (!t.closest("mjx-assistive-mml")) return !0;
455
- return (t ? be : ye).test(e.textContent ?? "");
498
+ return (t ? Ee : Te).test(e.textContent ?? "");
456
499
  }
457
- function Ne(e) {
500
+ function Be(e) {
458
501
  return new Promise((t, n) => {
459
502
  let { useSingleDollar: r = !1, accessibility: i = !0, loadFonts: s = !0, srcUrl: c } = e, l = {
460
503
  loader: {
@@ -462,17 +505,17 @@ function Ne(e) {
462
505
  failed: (e) => n(e),
463
506
  "output/svg": { ready: (e) => {
464
507
  let t = a();
465
- return G(t) && K(t), e;
508
+ return K(t) && q(t), e;
466
509
  } }
467
510
  },
468
511
  startup: {
469
512
  typeset: !1,
470
513
  ready: () => {
471
- let e = a(), r = e?.startup, i = G(e);
472
- i && (K(e), Pe(e)), r?.defaultReady?.(), i && (Fe(r?.document), r?.document?.addStyles?.(Te)), Promise.resolve(r?.promise).then(() => t(), n);
514
+ let e = a(), r = e?.startup, i = K(e);
515
+ i && (q(e), Ve(e)), r?.defaultReady?.(), i && (He(r?.document), r?.document?.addStyles?.(je)), Promise.resolve(r?.promise).then(() => t(), n);
473
516
  }
474
517
  },
475
- tex: { macros: { ..._e } },
518
+ tex: { macros: { ...Ce } },
476
519
  output: { displayOverflow: "linebreak" },
477
520
  options: {
478
521
  enableMenu: i,
@@ -484,80 +527,80 @@ function Ne(e) {
484
527
  a11y: { inTabOrder: !1 }
485
528
  }
486
529
  };
487
- r && l.tex && (console.warn(ve), l.tex.inlineMath = [["$", "$"], ["\\(", "\\)"]], l.tex.processEscapes = !0), s || (l.chtml = { fontURL: "" }), o(l, c || ge).catch(n);
530
+ r && l.tex && (console.warn(we), l.tex.inlineMath = [["$", "$"], ["\\(", "\\)"]], l.tex.processEscapes = !0), s || (l.chtml = { fontURL: "" }), o(l, c || Se).catch(n);
488
531
  });
489
532
  }
490
- function G(e) {
533
+ function K(e) {
491
534
  return !!e?.version?.startsWith("4.");
492
535
  }
493
- function K(e) {
536
+ function q(e) {
494
537
  let t = e?._?.output, n = t?.chtml_ts?.CHTML;
495
538
  n && (n.STYLESHEETID = c);
496
539
  let r = t?.svg_ts?.SVG;
497
- r && (r.STYLESHEETID = we);
540
+ r && (r.STYLESHEETID = Ae);
498
541
  }
499
- function Pe(e) {
542
+ function Ve(e) {
500
543
  let t = e?._?.ui?.menu?.Menu?.Menu;
501
544
  if (t) {
502
- t.MENU_STORAGE = B;
545
+ t.MENU_STORAGE = H;
503
546
  try {
504
- let e = localStorage.getItem(B);
547
+ let e = localStorage.getItem(H);
505
548
  if (!e) return;
506
549
  let { assistiveMml: t, ...n } = JSON.parse(e);
507
550
  if (t === void 0) return;
508
- Object.keys(n).length ? localStorage.setItem(B, JSON.stringify(n)) : localStorage.removeItem(B);
551
+ Object.keys(n).length ? localStorage.setItem(H, JSON.stringify(n)) : localStorage.removeItem(H);
509
552
  } catch {}
510
553
  }
511
554
  }
512
- function Fe(e) {
555
+ function He(e) {
513
556
  if (!e) return;
514
557
  let t = /* @__PURE__ */ new WeakSet(), n = (e) => {
515
558
  let n = e.typesetRoot;
516
- !n || t.has(n) || (V(n), t.add(n));
559
+ !n || t.has(n) || (U(n), t.add(n));
517
560
  };
518
- e.addRenderAction?.("pie-strip-latex", De, (e) => {
561
+ e.addRenderAction?.("pie-strip-latex", Ne, (e) => {
519
562
  for (let t of e.math ?? []) n(t);
520
563
  return !1;
521
564
  }, (e) => {
522
565
  let t = e.typesetRoot;
523
- return t && V(t), !1;
566
+ return t && U(t), !1;
524
567
  });
525
568
  let r = e.outputJax?.chtmlStyles;
526
- r?.id === Ce && (r.id = c), Ie();
569
+ r?.id === ke && (r.id = c), Ue();
527
570
  }
528
- function q(e) {
571
+ function J(e) {
529
572
  return e instanceof HTMLStyleElement && l.includes(e.id);
530
573
  }
531
- function J(e) {
574
+ function Y(e) {
532
575
  r("foreign-output-stylesheet", `another MathJax added <style id="${e.id}"> to <head>`);
533
576
  }
534
- function Ie() {
535
- let e = document.head, t = [...e.children].find(q);
577
+ function Ue() {
578
+ let e = document.head, t = [...e.children].find(J);
536
579
  if (t) {
537
- J(t);
580
+ Y(t);
538
581
  return;
539
582
  }
540
583
  let n = new MutationObserver((e) => {
541
584
  for (let t of e) {
542
- let e = [...t.addedNodes].find(q);
585
+ let e = [...t.addedNodes].find(J);
543
586
  if (e) {
544
- J(e), n.disconnect();
587
+ Y(e), n.disconnect();
545
588
  return;
546
589
  }
547
590
  }
548
591
  });
549
592
  n.observe(e, { childList: !0 });
550
593
  }
551
- function Le(e) {
594
+ function We(e) {
552
595
  let t = e?.math;
553
596
  if (!t?.remove) return;
554
- let n = [...t].filter((e) => (e.state?.() ?? 0) >= Ee && e.typesetRoot?.isConnected === !1);
597
+ let n = [...t].filter((e) => (e.state?.() ?? 0) >= Me && e.typesetRoot?.isConnected === !1);
555
598
  if (n.length !== 0) {
556
599
  for (let e of [...n].reverse()) e.clear?.();
557
600
  t.remove(...n);
558
601
  }
559
602
  }
560
- function Re(e) {
603
+ function Ge(e) {
561
604
  return new Promise((t, n) => {
562
605
  let r = e.startup ?? {};
563
606
  e.startup = r;
@@ -568,81 +611,81 @@ function Re(e) {
568
611
  };
569
612
  });
570
613
  }
571
- function ze(e) {
614
+ function Ke(e) {
572
615
  let t = a();
573
- return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() : Re(t) : Ne(e);
616
+ return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() : Ge(t) : Be(e);
574
617
  }
575
- function Be(e) {
576
- return ze(e).then(() => {
618
+ function qe(e) {
619
+ return Ke(e).then(() => {
577
620
  typeof a()?.typesetPromise != "function" && console.warn("[mathjax-renderer] MathJax on this page has no typesetPromise; math stays untypeset.");
578
621
  });
579
622
  }
580
- function Ve(e) {
581
- let t = s, n = t[z];
582
- return n || (n = Be(e), t[z] = n), n;
623
+ function Je(e) {
624
+ let t = s, n = t[V];
625
+ return n || (n = qe(e), t[V] = n), n;
583
626
  }
584
- function Y(e = {}) {
627
+ function X(e = {}) {
585
628
  let t = e.useSingleDollar ?? !1;
586
629
  return async (n) => {
587
630
  if (typeof window > "u") return;
588
631
  let i = u();
589
- i && r("mathjax-3-global", `window.MathJax is MathJax ${i}`), je(n), m(n), Me(n), he(n);
590
- let o = Ve(e);
591
- if (!W(n, t)) {
632
+ i && r("mathjax-3-global", `window.MathJax is MathJax ${i}`), Le(n), m(n), Re(n), ge(n);
633
+ let o = Je(e);
634
+ if (!ze(n, t)) {
592
635
  o.catch(() => {});
593
636
  return;
594
637
  }
595
638
  await o;
596
639
  let s = a();
597
640
  if (await s?.startup?.promise, typeof s?.typesetPromise == "function") {
598
- Le(s.startup?.document);
641
+ xe(), We(s.startup?.document);
599
642
  try {
600
643
  await s.typesetPromise([n]);
601
644
  } catch (e) {
602
645
  throw s.typesetClear?.([n]), e;
603
646
  }
604
- V(n);
647
+ U(n);
605
648
  }
606
649
  };
607
650
  }
608
- function He() {
651
+ function Ye() {
609
652
  return [];
610
653
  }
611
654
  //#endregion
612
655
  //#region src/render-math.ts
613
- var Ue = "@pie-lib/math-rendering", We = "@pie-lib/math-rendering@2", Ge = "pie-print", Ke = 50, qe = 1e4, X = null;
614
- function Je() {
615
- return !!window[We]?.opts?.useSingleDollar;
656
+ var Xe = "@pie-lib/math-rendering", Ze = "@pie-lib/math-rendering@2", Qe = "pie-print", $e = 50, et = 1e4, Z = null;
657
+ function tt() {
658
+ return !!window[Ze]?.opts?.useSingleDollar;
616
659
  }
617
- function Ye() {
618
- return X ||= Y({ useSingleDollar: Je() }), X;
660
+ function nt() {
661
+ return Z ||= X({ useSingleDollar: tt() }), Z;
619
662
  }
620
- function Z() {
663
+ function Q() {
621
664
  if (typeof window > "u") return null;
622
- let e = window[Ue];
665
+ let e = window[Xe];
623
666
  return typeof e?.renderMath == "function" && e.renderMath !== $ ? e : null;
624
667
  }
625
- function Xe(e) {
668
+ function rt(e) {
626
669
  let t = e;
627
670
  for (; t;) {
628
- if (t instanceof Element && t.localName === Ge) return t;
671
+ if (t instanceof Element && t.localName === Qe) return t;
629
672
  t = t instanceof ShadowRoot ? t.host : t.parentNode;
630
673
  }
631
674
  return null;
632
675
  }
633
- function Q() {
676
+ function it() {
634
677
  let e = window.renderMath;
635
678
  return typeof e == "function" ? e : null;
636
679
  }
637
- async function Ze(e) {
638
- let t = Xe(e);
680
+ async function at(e) {
681
+ let t = rt(e);
639
682
  if (!t) return null;
640
- let n = Q();
683
+ let n = it();
641
684
  if (n || t.mathRenderingModuleUrlImported !== !0) return n;
642
- let r = Date.now() + qe;
685
+ let r = Date.now() + et;
643
686
  for (; Date.now() < r;) {
644
- await new Promise((e) => setTimeout(e, Ke));
645
- let e = Q();
687
+ await new Promise((e) => setTimeout(e, $e));
688
+ let e = it();
646
689
  if (e) return e;
647
690
  }
648
691
  return null;
@@ -651,14 +694,14 @@ var $ = async (e) => {
651
694
  if (typeof window > "u") return;
652
695
  let t = typeof e == "string", n;
653
696
  t ? (n = document.createElement("div"), n.innerHTML = e) : n = e || document.body;
654
- let r = Z(), i = r || t ? null : await Ze(n);
655
- return r ? await r.renderMath?.(n) : i && i !== $ ? await i(n) : await Ye()(n), t ? n.innerHTML : void 0;
656
- }, Qe = (e, t) => {
657
- let n = Z()?.wrapMath?.(e, t);
697
+ let r = Q(), i = r || t ? null : await at(n);
698
+ return r ? await r.renderMath?.(n) : i && i !== $ ? await i(n) : await nt()(n), t ? n.innerHTML : void 0;
699
+ }, ot = (e, t) => {
700
+ let n = Q()?.wrapMath?.(e, t);
658
701
  if (n != null) return n;
659
702
  let [r, i] = t === "dollar" || t === "double_dollar" ? ["$", "$"] : ["\\(", "\\)"];
660
- return `${r}${H(e)}${i}`;
661
- }, $e = (e) => {
703
+ return `${r}${W(e)}${i}`;
704
+ }, st = (e) => {
662
705
  let t = e.trim();
663
706
  return t.startsWith("\\[") && t.endsWith("\\]") ? {
664
707
  unwrapped: t.slice(2, -2).trim(),
@@ -685,6 +728,6 @@ var $ = async (e) => {
685
728
  close: "$"
686
729
  }
687
730
  } : { unwrapped: t };
688
- }, et = (e) => Z()?.mmlToLatex?.(e) ?? e;
731
+ }, ct = (e) => Q()?.mmlToLatex?.(e) ?? e;
689
732
  //#endregion
690
- export { t as MATHJAX_CONFLICT_EVENT, e as UNSUPPORTED_PAGE_DOCS_URL, Y as createMathjaxRenderer, He as getMathjaxCssUrls, et as mmlToLatex, $ as renderMath, $e as unWrapMath, Qe as wrapMath };
733
+ export { t as MATHJAX_CONFLICT_EVENT, e as UNSUPPORTED_PAGE_DOCS_URL, X as createMathjaxRenderer, Ye as getMathjaxCssUrls, ct as mmlToLatex, $ as renderMath, st as unWrapMath, ot as wrapMath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/shared-math-rendering-mathjax",
3
- "version": "0.1.2-next.20261003161149",
3
+ "version": "0.1.2-next.20261006070837",
4
4
  "description": "MathJax adapter for PIE math rendering",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",