@pie-element/shared-math-rendering-mathjax 0.1.2-next.20261002215153 → 0.1.2-next.20261002233132

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/index.d.ts CHANGED
@@ -4,8 +4,8 @@
4
4
  * MathJax adapter for PIE math rendering (~2.7MB)
5
5
  * Full-featured LaTeX and MathML rendering with accessibility support.
6
6
  *
7
- * This adapter wraps the upstream @pie-lib/math-rendering package,
8
- * which must be loaded separately (e.g., via a script tag or bundled).
7
+ * It also implements the legacy @pie-lib/math-rendering API (renderMath, wrapMath,
8
+ * unWrapMath, mmlToLatex) on MathJax 4; @pie-lib/math-rendering re-exports it.
9
9
  *
10
10
  * @example
11
11
  * ```typescript
package/dist/index.js CHANGED
@@ -34,49 +34,53 @@ var a = "https://cdn.jsdelivr.net/npm/mathjax@4.1.3/tex-mml-chtml.js", o = {
34
34
  ["$", "$"],
35
35
  ["\\[", "\\]"],
36
36
  ["\\(", "\\)"]
37
- ], f = Symbol.for("@pie-element/shared-math-rendering-mathjax/loading"), p = "PIE-MJX-CHTML-styles", m = "MJX-CHTML-styles", h = [m, "MJX-SVG-styles"], g = 200, _ = 201;
38
- function v(e) {
37
+ ], f = Symbol.for("@pie-element/shared-math-rendering-mathjax/loading"), p = "PIE-MJX-CHTML-styles", m = "MJX-CHTML-styles", h = "PIE-MJX-SVG-styles", g = "MJX-SVG-styles", _ = "PIE-MathJax-Menu-Settings", v = [m, g], y = 200, b = 201;
38
+ function x(e) {
39
39
  let t = [...e.matches("mjx-container") ? [e] : [], ...e.querySelectorAll("mjx-container")];
40
40
  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");
41
41
  }
42
- function y() {
42
+ function S() {
43
43
  return window.MathJax;
44
44
  }
45
- function b(e) {
45
+ function C(e) {
46
46
  for (let [t, n] of d) if (e.startsWith(t) && e.endsWith(n)) return e.substring(t.length, e.length - n.length);
47
47
  return e;
48
48
  }
49
- function x(e) {
50
- return b(e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e);
49
+ function w(e) {
50
+ return C(e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e);
51
51
  }
52
- var S = "mathjax_ignore", C = "mathjax_process";
53
- function w(e, t) {
54
- let n = e.closest(`.${S}, .${C}`);
55
- return n !== null && t.contains(n) && !n.classList.contains(C);
52
+ var T = "mathjax_ignore", E = "mathjax_process";
53
+ function D(e, t) {
54
+ let n = e.closest(`.${T}, .${E}`);
55
+ return n !== null && t.contains(n) && !n.classList.contains(E);
56
56
  }
57
- function T(e) {
57
+ function ee(e) {
58
58
  for (let t of e.querySelectorAll("[data-latex]")) {
59
- if (t.dataset.mathHandled || t.closest("mjx-container") || w(t, e)) continue;
59
+ if (t.dataset.mathHandled || t.closest("mjx-container") || D(t, e)) continue;
60
60
  let n = t.textContent;
61
- n && (t.textContent = `\\(${x(n)}\\)`.replace(u, "\\newline "), t.dataset.mathHandled = "true");
61
+ n && (t.textContent = `\\(${w(n)}\\)`.replace(u, "\\newline "), t.dataset.mathHandled = "true");
62
62
  }
63
63
  }
64
- function E(e, t) {
64
+ function te(e, t) {
65
65
  for (let t of e.querySelectorAll("math")) if (!t.closest("mjx-assistive-mml")) return !0;
66
66
  return (t ? l : c).test(e.textContent ?? "");
67
67
  }
68
- function D(e) {
68
+ function O(e) {
69
69
  return new Promise((t, n) => {
70
70
  let { useSingleDollar: r = !1, accessibility: i = !0, loadFonts: c = !0, srcUrl: l } = e, u = {
71
71
  loader: {
72
72
  load: i ? ["a11y/assistive-mml"] : [],
73
- failed: (e) => n(e)
73
+ failed: (e) => n(e),
74
+ "output/svg": { ready: (e) => {
75
+ let t = S();
76
+ return k(t) && A(t), e;
77
+ } }
74
78
  },
75
79
  startup: {
76
80
  typeset: !1,
77
81
  ready: () => {
78
- let e = y(), r = e?.startup, i = !!e?.version?.startsWith("4.");
79
- i && O(e), r?.defaultReady?.(), i && k(r?.document), Promise.resolve(r?.promise).then(() => t(), n);
82
+ let e = S(), r = e?.startup, i = k(e);
83
+ i && (A(e), j(e)), r?.defaultReady?.(), i && M(r?.document), Promise.resolve(r?.promise).then(() => t(), n);
80
84
  }
81
85
  },
82
86
  tex: { macros: { ...o } },
@@ -86,7 +90,8 @@ function D(e) {
86
90
  assistiveMml: i,
87
91
  enrich: !1,
88
92
  inTabOrder: !1
89
- } }
93
+ } },
94
+ a11y: { inTabOrder: !1 }
90
95
  }
91
96
  };
92
97
  r && u.tex && (console.warn(s), u.tex.inlineMath = [["$", "$"], ["\\(", "\\)"]], u.tex.processEscapes = !0), c || (u.chtml = { fontURL: "" }), window.MathJax = u;
@@ -94,160 +99,178 @@ function D(e) {
94
99
  d.src = l || a, d.async = !0, d.onerror = () => n(/* @__PURE__ */ Error("Failed to load MathJax")), document.head.appendChild(d);
95
100
  });
96
101
  }
97
- function O(e) {
98
- let t = e?._?.output?.chtml_ts?.CHTML;
99
- t && (t.STYLESHEETID = p);
100
- }
101
102
  function k(e) {
103
+ return !!e?.version?.startsWith("4.");
104
+ }
105
+ function A(e) {
106
+ let t = e?._?.output, n = t?.chtml_ts?.CHTML;
107
+ n && (n.STYLESHEETID = p);
108
+ let r = t?.svg_ts?.SVG;
109
+ r && (r.STYLESHEETID = h);
110
+ }
111
+ function j(e) {
112
+ let t = e?._?.ui?.menu?.Menu?.Menu;
113
+ if (t) {
114
+ t.MENU_STORAGE = _;
115
+ try {
116
+ let e = localStorage.getItem(_);
117
+ if (!e) return;
118
+ let { assistiveMml: t, ...n } = JSON.parse(e);
119
+ if (t === void 0) return;
120
+ Object.keys(n).length ? localStorage.setItem(_, JSON.stringify(n)) : localStorage.removeItem(_);
121
+ } catch {}
122
+ }
123
+ }
124
+ function M(e) {
102
125
  if (!e) return;
103
126
  let t = /* @__PURE__ */ new WeakSet(), n = (e) => {
104
127
  let n = e.typesetRoot;
105
- !n || t.has(n) || (v(n), t.add(n));
128
+ !n || t.has(n) || (x(n), t.add(n));
106
129
  };
107
- e.addRenderAction?.("pie-strip-latex", _, (e) => {
130
+ e.addRenderAction?.("pie-strip-latex", b, (e) => {
108
131
  for (let t of e.math ?? []) n(t);
109
132
  return !1;
110
133
  }, (e) => {
111
134
  let t = e.typesetRoot;
112
- return t && v(t), !1;
135
+ return t && x(t), !1;
113
136
  });
114
137
  let r = e.outputJax?.chtmlStyles;
115
- r?.id === m && (r.id = p), M();
138
+ r?.id === m && (r.id = p), F();
116
139
  }
117
- function A(e) {
118
- return e instanceof HTMLStyleElement && h.includes(e.id);
140
+ function N(e) {
141
+ return e instanceof HTMLStyleElement && v.includes(e.id);
119
142
  }
120
- function j(e) {
143
+ function P(e) {
121
144
  r("foreign-output-stylesheet", `another MathJax added <style id="${e.id}"> to <head>`);
122
145
  }
123
- function M() {
124
- let e = document.head, t = [...e.children].find(A);
146
+ function F() {
147
+ let e = document.head, t = [...e.children].find(N);
125
148
  if (t) {
126
- j(t);
149
+ P(t);
127
150
  return;
128
151
  }
129
152
  let n = new MutationObserver((e) => {
130
153
  for (let t of e) {
131
- let e = [...t.addedNodes].find(A);
154
+ let e = [...t.addedNodes].find(N);
132
155
  if (e) {
133
- j(e), n.disconnect();
156
+ P(e), n.disconnect();
134
157
  return;
135
158
  }
136
159
  }
137
160
  });
138
161
  n.observe(e, { childList: !0 });
139
162
  }
140
- function N(e) {
163
+ function I(e) {
141
164
  let t = e?.math;
142
165
  if (!t?.remove) return;
143
- let n = [...t].filter((e) => (e.state?.() ?? 0) >= g && e.typesetRoot?.isConnected === !1);
166
+ let n = [...t].filter((e) => (e.state?.() ?? 0) >= y && e.typesetRoot?.isConnected === !1);
144
167
  if (n.length !== 0) {
145
168
  for (let e of [...n].reverse()) e.clear?.();
146
169
  t.remove(...n);
147
170
  }
148
171
  }
149
- function P(e) {
172
+ function L(e) {
150
173
  return new Promise((t, n) => {
151
174
  let r = e.startup ?? {};
152
175
  e.startup = r;
153
176
  let i = r.ready;
154
177
  r.ready = () => {
155
- let e = y()?.startup;
178
+ let e = S()?.startup;
156
179
  i ? i.call(r) : e?.defaultReady?.(), Promise.resolve(e?.promise).then(() => t(), n);
157
180
  };
158
181
  });
159
182
  }
160
- function F(e) {
161
- let t = y();
162
- return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() : P(t) : D(e);
183
+ function R(e) {
184
+ let t = S();
185
+ return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() : L(t) : O(e);
163
186
  }
164
- function I(e) {
165
- return F(e).then(() => {
166
- typeof y()?.typesetPromise != "function" && console.warn("[mathjax-renderer] MathJax on this page has no typesetPromise; math stays untypeset.");
187
+ function z(e) {
188
+ return R(e).then(() => {
189
+ typeof S()?.typesetPromise != "function" && console.warn("[mathjax-renderer] MathJax on this page has no typesetPromise; math stays untypeset.");
167
190
  });
168
191
  }
169
- function L(e) {
192
+ function B(e) {
170
193
  let t = globalThis, n = t[f];
171
- return n || (n = I(e), t[f] = n), n;
194
+ return n || (n = z(e), t[f] = n), n;
172
195
  }
173
- function R(e = {}) {
196
+ function V(e = {}) {
174
197
  let t = e.useSingleDollar ?? !1;
175
198
  return async (n) => {
176
199
  if (typeof window > "u") return;
177
200
  let a = i();
178
- a && r("mathjax-3-global", `window.MathJax is MathJax ${a}`), T(n);
179
- let o = L(e);
180
- if (!E(n, t)) {
201
+ a && r("mathjax-3-global", `window.MathJax is MathJax ${a}`), ee(n);
202
+ let o = B(e);
203
+ if (!te(n, t)) {
181
204
  o.catch(() => {});
182
205
  return;
183
206
  }
184
207
  await o;
185
- let s = y();
208
+ let s = S();
186
209
  if (await s?.startup?.promise, typeof s?.typesetPromise == "function") {
187
- N(s.startup?.document);
210
+ I(s.startup?.document);
188
211
  try {
189
212
  await s.typesetPromise([n]);
190
213
  } catch (e) {
191
214
  throw s.typesetClear?.([n]), e;
192
215
  }
193
- v(n);
216
+ x(n);
194
217
  }
195
218
  };
196
219
  }
197
- function z() {
220
+ function H() {
198
221
  return [];
199
222
  }
200
223
  //#endregion
201
224
  //#region src/render-math.ts
202
- var B = "@pie-lib/math-rendering", V = "@pie-lib/math-rendering@2", H = "pie-print", U = 50, W = 1e4, G = null;
203
- function K() {
204
- return !!window[V]?.opts?.useSingleDollar;
225
+ var U = "@pie-lib/math-rendering", W = "@pie-lib/math-rendering@2", G = "pie-print", K = 50, q = 1e4, J = null;
226
+ function Y() {
227
+ return !!window[W]?.opts?.useSingleDollar;
205
228
  }
206
- function q() {
207
- return G ||= R({ useSingleDollar: K() }), G;
229
+ function X() {
230
+ return J ||= V({ useSingleDollar: Y() }), J;
208
231
  }
209
- function J() {
232
+ function Z() {
210
233
  if (typeof window > "u") return null;
211
- let e = window[B];
212
- return typeof e?.renderMath == "function" && e.renderMath !== Q ? e : null;
234
+ let e = window[U];
235
+ return typeof e?.renderMath == "function" && e.renderMath !== $ ? e : null;
213
236
  }
214
- function Y(e) {
237
+ function ne(e) {
215
238
  let t = e;
216
239
  for (; t;) {
217
- if (t instanceof Element && t.localName === H) return t;
240
+ if (t instanceof Element && t.localName === G) return t;
218
241
  t = t instanceof ShadowRoot ? t.host : t.parentNode;
219
242
  }
220
243
  return null;
221
244
  }
222
- function X() {
245
+ function Q() {
223
246
  let e = window.renderMath;
224
247
  return typeof e == "function" ? e : null;
225
248
  }
226
- async function Z(e) {
227
- let t = Y(e);
249
+ async function re(e) {
250
+ let t = ne(e);
228
251
  if (!t) return null;
229
- let n = X();
252
+ let n = Q();
230
253
  if (n || t.mathRenderingModuleUrlImported !== !0) return n;
231
- let r = Date.now() + W;
254
+ let r = Date.now() + q;
232
255
  for (; Date.now() < r;) {
233
- await new Promise((e) => setTimeout(e, U));
234
- let e = X();
256
+ await new Promise((e) => setTimeout(e, K));
257
+ let e = Q();
235
258
  if (e) return e;
236
259
  }
237
260
  return null;
238
261
  }
239
- var Q = async (e) => {
262
+ var $ = async (e) => {
240
263
  if (typeof window > "u") return;
241
264
  let t = typeof e == "string", n;
242
265
  t ? (n = document.createElement("div"), n.innerHTML = e) : n = e || document.body;
243
- let r = J(), i = r || t ? null : await Z(n);
244
- return r ? await r.renderMath?.(n) : i && i !== Q ? await i(n) : await q()(n), t ? n.innerHTML : void 0;
245
- }, $ = (e, t) => {
246
- let n = J()?.wrapMath?.(e, t);
266
+ let r = Z(), i = r || t ? null : await re(n);
267
+ return r ? await r.renderMath?.(n) : i && i !== $ ? await i(n) : await X()(n), t ? n.innerHTML : void 0;
268
+ }, ie = (e, t) => {
269
+ let n = Z()?.wrapMath?.(e, t);
247
270
  if (n != null) return n;
248
271
  let [r, i] = t === "dollar" || t === "double_dollar" ? ["$", "$"] : ["\\(", "\\)"];
249
- return `${r}${b(e)}${i}`;
250
- }, ee = (e) => {
272
+ return `${r}${C(e)}${i}`;
273
+ }, ae = (e) => {
251
274
  let t = e.trim();
252
275
  return t.startsWith("\\[") && t.endsWith("\\]") ? {
253
276
  unwrapped: t.slice(2, -2).trim(),
@@ -274,6 +297,6 @@ var Q = async (e) => {
274
297
  close: "$"
275
298
  }
276
299
  } : { unwrapped: t };
277
- }, te = (e) => J()?.mmlToLatex?.(e) ?? e;
300
+ }, oe = (e) => Z()?.mmlToLatex?.(e) ?? e;
278
301
  //#endregion
279
- export { t as MATHJAX_CONFLICT_EVENT, e as UNSUPPORTED_PAGE_DOCS_URL, R as createMathjaxRenderer, z as getMathjaxCssUrls, te as mmlToLatex, Q as renderMath, ee as unWrapMath, $ as wrapMath };
302
+ export { t as MATHJAX_CONFLICT_EVENT, e as UNSUPPORTED_PAGE_DOCS_URL, V as createMathjaxRenderer, H as getMathjaxCssUrls, oe as mmlToLatex, $ as renderMath, ae as unWrapMath, ie 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.20261002215153",
3
+ "version": "0.1.2-next.20261002233132",
4
4
  "description": "MathJax adapter for PIE math rendering",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",