@pie-element/shared-math-rendering-mathjax 0.1.1 → 0.1.2-next.20261002215153
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.js +90 -73
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34,38 +34,38 @@ 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 = 201;
|
|
38
|
-
function
|
|
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) {
|
|
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
|
|
42
|
+
function y() {
|
|
43
43
|
return window.MathJax;
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function b(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
|
|
50
|
-
return
|
|
49
|
+
function x(e) {
|
|
50
|
+
return b(e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e);
|
|
51
51
|
}
|
|
52
|
-
var
|
|
53
|
-
function
|
|
54
|
-
let n = e.closest(`.${
|
|
55
|
-
return n !== null && t.contains(n) && !n.classList.contains(
|
|
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);
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function T(e) {
|
|
58
58
|
for (let t of e.querySelectorAll("[data-latex]")) {
|
|
59
|
-
if (t.dataset.mathHandled || t.closest("mjx-container") ||
|
|
59
|
+
if (t.dataset.mathHandled || t.closest("mjx-container") || w(t, e)) continue;
|
|
60
60
|
let n = t.textContent;
|
|
61
|
-
n && (t.textContent = `\\(${
|
|
61
|
+
n && (t.textContent = `\\(${x(n)}\\)`.replace(u, "\\newline "), t.dataset.mathHandled = "true");
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function E(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
|
|
68
|
+
function D(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: {
|
|
@@ -75,8 +75,8 @@ function E(e) {
|
|
|
75
75
|
startup: {
|
|
76
76
|
typeset: !1,
|
|
77
77
|
ready: () => {
|
|
78
|
-
let e =
|
|
79
|
-
i &&
|
|
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);
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
tex: { macros: { ...o } },
|
|
@@ -94,143 +94,160 @@ function E(e) {
|
|
|
94
94
|
d.src = l || a, d.async = !0, d.onerror = () => n(/* @__PURE__ */ Error("Failed to load MathJax")), document.head.appendChild(d);
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
-
function
|
|
97
|
+
function O(e) {
|
|
98
98
|
let t = e?._?.output?.chtml_ts?.CHTML;
|
|
99
99
|
t && (t.STYLESHEETID = p);
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function k(e) {
|
|
102
102
|
if (!e) return;
|
|
103
103
|
let t = /* @__PURE__ */ new WeakSet(), n = (e) => {
|
|
104
104
|
let n = e.typesetRoot;
|
|
105
|
-
!n || t.has(n) || (
|
|
105
|
+
!n || t.has(n) || (v(n), t.add(n));
|
|
106
106
|
};
|
|
107
|
-
e.addRenderAction?.("pie-strip-latex",
|
|
107
|
+
e.addRenderAction?.("pie-strip-latex", _, (e) => {
|
|
108
108
|
for (let t of e.math ?? []) n(t);
|
|
109
109
|
return !1;
|
|
110
110
|
}, (e) => {
|
|
111
111
|
let t = e.typesetRoot;
|
|
112
|
-
return t &&
|
|
112
|
+
return t && v(t), !1;
|
|
113
113
|
});
|
|
114
114
|
let r = e.outputJax?.chtmlStyles;
|
|
115
|
-
r?.id === m && (r.id = p),
|
|
115
|
+
r?.id === m && (r.id = p), M();
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function A(e) {
|
|
118
118
|
return e instanceof HTMLStyleElement && h.includes(e.id);
|
|
119
119
|
}
|
|
120
|
-
function
|
|
120
|
+
function j(e) {
|
|
121
121
|
r("foreign-output-stylesheet", `another MathJax added <style id="${e.id}"> to <head>`);
|
|
122
122
|
}
|
|
123
|
-
function
|
|
124
|
-
let e = document.head, t = [...e.children].find(
|
|
123
|
+
function M() {
|
|
124
|
+
let e = document.head, t = [...e.children].find(A);
|
|
125
125
|
if (t) {
|
|
126
|
-
|
|
126
|
+
j(t);
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
129
|
let n = new MutationObserver((e) => {
|
|
130
130
|
for (let t of e) {
|
|
131
|
-
let e = [...t.addedNodes].find(
|
|
131
|
+
let e = [...t.addedNodes].find(A);
|
|
132
132
|
if (e) {
|
|
133
|
-
|
|
133
|
+
j(e), n.disconnect();
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
});
|
|
138
138
|
n.observe(e, { childList: !0 });
|
|
139
139
|
}
|
|
140
|
-
function
|
|
140
|
+
function N(e) {
|
|
141
|
+
let t = e?.math;
|
|
142
|
+
if (!t?.remove) return;
|
|
143
|
+
let n = [...t].filter((e) => (e.state?.() ?? 0) >= g && e.typesetRoot?.isConnected === !1);
|
|
144
|
+
if (n.length !== 0) {
|
|
145
|
+
for (let e of [...n].reverse()) e.clear?.();
|
|
146
|
+
t.remove(...n);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function P(e) {
|
|
141
150
|
return new Promise((t, n) => {
|
|
142
151
|
let r = e.startup ?? {};
|
|
143
152
|
e.startup = r;
|
|
144
153
|
let i = r.ready;
|
|
145
154
|
r.ready = () => {
|
|
146
|
-
let e =
|
|
155
|
+
let e = y()?.startup;
|
|
147
156
|
i ? i.call(r) : e?.defaultReady?.(), Promise.resolve(e?.promise).then(() => t(), n);
|
|
148
157
|
};
|
|
149
158
|
});
|
|
150
159
|
}
|
|
151
|
-
function
|
|
152
|
-
let t =
|
|
153
|
-
return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() :
|
|
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);
|
|
154
163
|
}
|
|
155
|
-
function
|
|
156
|
-
return
|
|
157
|
-
typeof
|
|
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.");
|
|
158
167
|
});
|
|
159
168
|
}
|
|
160
|
-
function
|
|
169
|
+
function L(e) {
|
|
161
170
|
let t = globalThis, n = t[f];
|
|
162
|
-
return n || (n =
|
|
171
|
+
return n || (n = I(e), t[f] = n), n;
|
|
163
172
|
}
|
|
164
|
-
function
|
|
173
|
+
function R(e = {}) {
|
|
165
174
|
let t = e.useSingleDollar ?? !1;
|
|
166
175
|
return async (n) => {
|
|
167
176
|
if (typeof window > "u") return;
|
|
168
177
|
let a = i();
|
|
169
|
-
a && r("mathjax-3-global", `window.MathJax is MathJax ${a}`),
|
|
170
|
-
let o =
|
|
171
|
-
if (!
|
|
178
|
+
a && r("mathjax-3-global", `window.MathJax is MathJax ${a}`), T(n);
|
|
179
|
+
let o = L(e);
|
|
180
|
+
if (!E(n, t)) {
|
|
172
181
|
o.catch(() => {});
|
|
173
182
|
return;
|
|
174
183
|
}
|
|
175
184
|
await o;
|
|
176
|
-
let s =
|
|
177
|
-
await s?.startup?.promise, typeof s?.typesetPromise == "function"
|
|
185
|
+
let s = y();
|
|
186
|
+
if (await s?.startup?.promise, typeof s?.typesetPromise == "function") {
|
|
187
|
+
N(s.startup?.document);
|
|
188
|
+
try {
|
|
189
|
+
await s.typesetPromise([n]);
|
|
190
|
+
} catch (e) {
|
|
191
|
+
throw s.typesetClear?.([n]), e;
|
|
192
|
+
}
|
|
193
|
+
v(n);
|
|
194
|
+
}
|
|
178
195
|
};
|
|
179
196
|
}
|
|
180
|
-
function
|
|
197
|
+
function z() {
|
|
181
198
|
return [];
|
|
182
199
|
}
|
|
183
200
|
//#endregion
|
|
184
201
|
//#region src/render-math.ts
|
|
185
|
-
var
|
|
186
|
-
function
|
|
187
|
-
return !!window[
|
|
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;
|
|
188
205
|
}
|
|
189
|
-
function
|
|
190
|
-
return
|
|
206
|
+
function q() {
|
|
207
|
+
return G ||= R({ useSingleDollar: K() }), G;
|
|
191
208
|
}
|
|
192
|
-
function
|
|
209
|
+
function J() {
|
|
193
210
|
if (typeof window > "u") return null;
|
|
194
|
-
let e = window[
|
|
195
|
-
return typeof e?.renderMath == "function" && e.renderMath !==
|
|
211
|
+
let e = window[B];
|
|
212
|
+
return typeof e?.renderMath == "function" && e.renderMath !== Q ? e : null;
|
|
196
213
|
}
|
|
197
|
-
function
|
|
214
|
+
function Y(e) {
|
|
198
215
|
let t = e;
|
|
199
216
|
for (; t;) {
|
|
200
|
-
if (t instanceof Element && t.localName ===
|
|
217
|
+
if (t instanceof Element && t.localName === H) return t;
|
|
201
218
|
t = t instanceof ShadowRoot ? t.host : t.parentNode;
|
|
202
219
|
}
|
|
203
220
|
return null;
|
|
204
221
|
}
|
|
205
|
-
function
|
|
222
|
+
function X() {
|
|
206
223
|
let e = window.renderMath;
|
|
207
224
|
return typeof e == "function" ? e : null;
|
|
208
225
|
}
|
|
209
|
-
async function
|
|
210
|
-
let t =
|
|
226
|
+
async function Z(e) {
|
|
227
|
+
let t = Y(e);
|
|
211
228
|
if (!t) return null;
|
|
212
|
-
let n =
|
|
229
|
+
let n = X();
|
|
213
230
|
if (n || t.mathRenderingModuleUrlImported !== !0) return n;
|
|
214
|
-
let r = Date.now() +
|
|
231
|
+
let r = Date.now() + W;
|
|
215
232
|
for (; Date.now() < r;) {
|
|
216
|
-
await new Promise((e) => setTimeout(e,
|
|
217
|
-
let e =
|
|
233
|
+
await new Promise((e) => setTimeout(e, U));
|
|
234
|
+
let e = X();
|
|
218
235
|
if (e) return e;
|
|
219
236
|
}
|
|
220
237
|
return null;
|
|
221
238
|
}
|
|
222
|
-
var
|
|
239
|
+
var Q = async (e) => {
|
|
223
240
|
if (typeof window > "u") return;
|
|
224
241
|
let t = typeof e == "string", n;
|
|
225
242
|
t ? (n = document.createElement("div"), n.innerHTML = e) : n = e || document.body;
|
|
226
|
-
let r =
|
|
227
|
-
return r ? await r.renderMath?.(n) : i && i !==
|
|
228
|
-
},
|
|
229
|
-
let n =
|
|
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);
|
|
230
247
|
if (n != null) return n;
|
|
231
248
|
let [r, i] = t === "dollar" || t === "double_dollar" ? ["$", "$"] : ["\\(", "\\)"];
|
|
232
|
-
return `${r}${
|
|
233
|
-
},
|
|
249
|
+
return `${r}${b(e)}${i}`;
|
|
250
|
+
}, ee = (e) => {
|
|
234
251
|
let t = e.trim();
|
|
235
252
|
return t.startsWith("\\[") && t.endsWith("\\]") ? {
|
|
236
253
|
unwrapped: t.slice(2, -2).trim(),
|
|
@@ -257,6 +274,6 @@ var X = async (e) => {
|
|
|
257
274
|
close: "$"
|
|
258
275
|
}
|
|
259
276
|
} : { unwrapped: t };
|
|
260
|
-
},
|
|
277
|
+
}, te = (e) => J()?.mmlToLatex?.(e) ?? e;
|
|
261
278
|
//#endregion
|
|
262
|
-
export { t as MATHJAX_CONFLICT_EVENT, e as UNSUPPORTED_PAGE_DOCS_URL,
|
|
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 };
|