@pie-element/shared-math-rendering-mathjax 0.1.1-next.6 → 0.1.1-next.8
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/adapter.d.ts +2 -0
- package/dist/index.js +82 -45
- package/dist/render-math.d.ts +7 -2
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/adapter.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -43,22 +43,29 @@ function v() {
|
|
|
43
43
|
return window.MathJax;
|
|
44
44
|
}
|
|
45
45
|
function y(e) {
|
|
46
|
-
let t
|
|
47
|
-
|
|
48
|
-
return t;
|
|
46
|
+
for (let [t, n] of d) if (e.startsWith(t) && e.endsWith(n)) return e.substring(t.length, e.length - n.length);
|
|
47
|
+
return e;
|
|
49
48
|
}
|
|
50
49
|
function b(e) {
|
|
50
|
+
return y(e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e);
|
|
51
|
+
}
|
|
52
|
+
var x = "mathjax_ignore", S = "mathjax_process";
|
|
53
|
+
function C(e, t) {
|
|
54
|
+
let n = e.closest(`.${x}, .${S}`);
|
|
55
|
+
return n !== null && t.contains(n) && !n.classList.contains(S);
|
|
56
|
+
}
|
|
57
|
+
function w(e) {
|
|
51
58
|
for (let t of e.querySelectorAll("[data-latex]")) {
|
|
52
|
-
if (t.dataset.mathHandled || t.closest("mjx-container")) continue;
|
|
53
|
-
let
|
|
54
|
-
|
|
59
|
+
if (t.dataset.mathHandled || t.closest("mjx-container") || C(t, e)) continue;
|
|
60
|
+
let n = t.textContent;
|
|
61
|
+
n && (t.textContent = `\\(${b(n)}\\)`.replace(u, "\\newline "), t.dataset.mathHandled = "true");
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
|
-
function
|
|
64
|
+
function T(e, t) {
|
|
58
65
|
for (let t of e.querySelectorAll("math")) if (!t.closest("mjx-assistive-mml")) return !0;
|
|
59
66
|
return (t ? l : c).test(e.textContent ?? "");
|
|
60
67
|
}
|
|
61
|
-
function
|
|
68
|
+
function E(e) {
|
|
62
69
|
return new Promise((t, n) => {
|
|
63
70
|
let { useSingleDollar: r = !1, accessibility: i = !0, loadFonts: c = !0, srcUrl: l } = e, u = {
|
|
64
71
|
loader: {
|
|
@@ -69,7 +76,7 @@ function S(e) {
|
|
|
69
76
|
typeset: !1,
|
|
70
77
|
ready: () => {
|
|
71
78
|
let e = v(), r = e?.startup, i = !!e?.version?.startsWith("4.");
|
|
72
|
-
i &&
|
|
79
|
+
i && D(e), r?.defaultReady?.(), i && O(r?.document), Promise.resolve(r?.promise).then(() => t(), n);
|
|
73
80
|
}
|
|
74
81
|
},
|
|
75
82
|
tex: { macros: { ...o } },
|
|
@@ -87,11 +94,11 @@ function S(e) {
|
|
|
87
94
|
d.src = l || a, d.async = !0, d.onerror = () => n(/* @__PURE__ */ Error("Failed to load MathJax")), document.head.appendChild(d);
|
|
88
95
|
});
|
|
89
96
|
}
|
|
90
|
-
function
|
|
97
|
+
function D(e) {
|
|
91
98
|
let t = e?._?.output?.chtml_ts?.CHTML;
|
|
92
99
|
t && (t.STYLESHEETID = p);
|
|
93
100
|
}
|
|
94
|
-
function
|
|
101
|
+
function O(e) {
|
|
95
102
|
if (!e) return;
|
|
96
103
|
let t = /* @__PURE__ */ new WeakSet(), n = (e) => {
|
|
97
104
|
let n = e.typesetRoot;
|
|
@@ -105,32 +112,32 @@ function w(e) {
|
|
|
105
112
|
return t && _(t), !1;
|
|
106
113
|
});
|
|
107
114
|
let r = e.outputJax?.chtmlStyles;
|
|
108
|
-
r?.id === m && (r.id = p),
|
|
115
|
+
r?.id === m && (r.id = p), j();
|
|
109
116
|
}
|
|
110
|
-
function
|
|
117
|
+
function k(e) {
|
|
111
118
|
return e instanceof HTMLStyleElement && h.includes(e.id);
|
|
112
119
|
}
|
|
113
|
-
function
|
|
120
|
+
function A(e) {
|
|
114
121
|
r("foreign-output-stylesheet", `another MathJax added <style id="${e.id}"> to <head>`);
|
|
115
122
|
}
|
|
116
|
-
function
|
|
117
|
-
let e = document.head, t = [...e.children].find(
|
|
123
|
+
function j() {
|
|
124
|
+
let e = document.head, t = [...e.children].find(k);
|
|
118
125
|
if (t) {
|
|
119
|
-
|
|
126
|
+
A(t);
|
|
120
127
|
return;
|
|
121
128
|
}
|
|
122
129
|
let n = new MutationObserver((e) => {
|
|
123
130
|
for (let t of e) {
|
|
124
|
-
let e = [...t.addedNodes].find(
|
|
131
|
+
let e = [...t.addedNodes].find(k);
|
|
125
132
|
if (e) {
|
|
126
|
-
|
|
133
|
+
A(e), n.disconnect();
|
|
127
134
|
return;
|
|
128
135
|
}
|
|
129
136
|
}
|
|
130
137
|
});
|
|
131
138
|
n.observe(e, { childList: !0 });
|
|
132
139
|
}
|
|
133
|
-
function
|
|
140
|
+
function M(e) {
|
|
134
141
|
return new Promise((t, n) => {
|
|
135
142
|
let r = e.startup ?? {};
|
|
136
143
|
e.startup = r;
|
|
@@ -141,27 +148,27 @@ function O(e) {
|
|
|
141
148
|
};
|
|
142
149
|
});
|
|
143
150
|
}
|
|
144
|
-
function
|
|
151
|
+
function N(e) {
|
|
145
152
|
let t = v();
|
|
146
|
-
return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() :
|
|
153
|
+
return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() : M(t) : E(e);
|
|
147
154
|
}
|
|
148
|
-
function
|
|
149
|
-
return
|
|
155
|
+
function P(e) {
|
|
156
|
+
return N(e).then(() => {
|
|
150
157
|
typeof v()?.typesetPromise != "function" && console.warn("[mathjax-renderer] MathJax on this page has no typesetPromise; math stays untypeset.");
|
|
151
158
|
});
|
|
152
159
|
}
|
|
153
|
-
function
|
|
160
|
+
function F(e) {
|
|
154
161
|
let t = globalThis, n = t[f];
|
|
155
|
-
return n || (n =
|
|
162
|
+
return n || (n = P(e), t[f] = n), n;
|
|
156
163
|
}
|
|
157
|
-
function
|
|
164
|
+
function I(e = {}) {
|
|
158
165
|
let t = e.useSingleDollar ?? !1;
|
|
159
166
|
return async (n) => {
|
|
160
167
|
if (typeof window > "u") return;
|
|
161
168
|
let a = i();
|
|
162
|
-
a && r("mathjax-3-global", `window.MathJax is MathJax ${a}`),
|
|
163
|
-
let o =
|
|
164
|
-
if (!
|
|
169
|
+
a && r("mathjax-3-global", `window.MathJax is MathJax ${a}`), w(n);
|
|
170
|
+
let o = F(e);
|
|
171
|
+
if (!T(n, t)) {
|
|
165
172
|
o.catch(() => {});
|
|
166
173
|
return;
|
|
167
174
|
}
|
|
@@ -170,30 +177,60 @@ function M(e = {}) {
|
|
|
170
177
|
await s?.startup?.promise, typeof s?.typesetPromise == "function" && (await s.typesetPromise([n]), _(n));
|
|
171
178
|
};
|
|
172
179
|
}
|
|
173
|
-
function
|
|
180
|
+
function L() {
|
|
174
181
|
return [];
|
|
175
182
|
}
|
|
176
183
|
//#endregion
|
|
177
184
|
//#region src/render-math.ts
|
|
178
|
-
var
|
|
179
|
-
function
|
|
180
|
-
return !!window[
|
|
185
|
+
var R = "@pie-lib/math-rendering", z = "@pie-lib/math-rendering@2", B = "pie-print", V = 50, H = 1e4, U = null;
|
|
186
|
+
function W() {
|
|
187
|
+
return !!window[z]?.opts?.useSingleDollar;
|
|
181
188
|
}
|
|
182
|
-
function
|
|
183
|
-
return
|
|
189
|
+
function G() {
|
|
190
|
+
return U ||= I({ useSingleDollar: W() }), U;
|
|
184
191
|
}
|
|
185
|
-
function
|
|
192
|
+
function K() {
|
|
186
193
|
if (typeof window > "u") return null;
|
|
187
|
-
let e = window[
|
|
188
|
-
return typeof e?.renderMath == "function" ? e : null;
|
|
194
|
+
let e = window[R];
|
|
195
|
+
return typeof e?.renderMath == "function" && e.renderMath !== X ? e : null;
|
|
196
|
+
}
|
|
197
|
+
function q(e) {
|
|
198
|
+
let t = e;
|
|
199
|
+
for (; t;) {
|
|
200
|
+
if (t instanceof Element && t.localName === B) return t;
|
|
201
|
+
t = t instanceof ShadowRoot ? t.host : t.parentNode;
|
|
202
|
+
}
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
function J() {
|
|
206
|
+
let e = window.renderMath;
|
|
207
|
+
return typeof e == "function" ? e : null;
|
|
208
|
+
}
|
|
209
|
+
async function Y(e) {
|
|
210
|
+
let t = q(e);
|
|
211
|
+
if (!t) return null;
|
|
212
|
+
let n = J();
|
|
213
|
+
if (n || t.mathRenderingModuleUrlImported !== !0) return n;
|
|
214
|
+
let r = Date.now() + H;
|
|
215
|
+
for (; Date.now() < r;) {
|
|
216
|
+
await new Promise((e) => setTimeout(e, V));
|
|
217
|
+
let e = J();
|
|
218
|
+
if (e) return e;
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
189
221
|
}
|
|
190
|
-
var
|
|
222
|
+
var X = async (e) => {
|
|
191
223
|
if (typeof window > "u") return;
|
|
192
224
|
let t = typeof e == "string", n;
|
|
193
225
|
t ? (n = document.createElement("div"), n.innerHTML = e) : n = e || document.body;
|
|
194
|
-
let r =
|
|
195
|
-
return r ? await r.renderMath?.(n) : await
|
|
196
|
-
},
|
|
226
|
+
let r = K(), i = r || t ? null : await Y(n);
|
|
227
|
+
return r ? await r.renderMath?.(n) : i && i !== X ? await i(n) : await G()(n), t ? n.innerHTML : void 0;
|
|
228
|
+
}, Z = (e, t) => {
|
|
229
|
+
let n = K()?.wrapMath?.(e, t);
|
|
230
|
+
if (n != null) return n;
|
|
231
|
+
let [r, i] = t === "dollar" || t === "double_dollar" ? ["$", "$"] : ["\\(", "\\)"];
|
|
232
|
+
return `${r}${y(e)}${i}`;
|
|
233
|
+
}, Q = (e) => {
|
|
197
234
|
let t = e.trim();
|
|
198
235
|
return t.startsWith("\\[") && t.endsWith("\\]") ? {
|
|
199
236
|
unwrapped: t.slice(2, -2).trim(),
|
|
@@ -220,6 +257,6 @@ var B = async (e) => {
|
|
|
220
257
|
close: "$"
|
|
221
258
|
}
|
|
222
259
|
} : { unwrapped: t };
|
|
223
|
-
},
|
|
260
|
+
}, $ = (e) => K()?.mmlToLatex?.(e) ?? e;
|
|
224
261
|
//#endregion
|
|
225
|
-
export { t as MATHJAX_CONFLICT_EVENT, e as UNSUPPORTED_PAGE_DOCS_URL,
|
|
262
|
+
export { t as MATHJAX_CONFLICT_EVENT, e as UNSUPPORTED_PAGE_DOCS_URL, I as createMathjaxRenderer, L as getMathjaxCssUrls, $ as mmlToLatex, X as renderMath, Q as unWrapMath, Z as wrapMath };
|
package/dist/render-math.d.ts
CHANGED
|
@@ -9,9 +9,14 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const renderMath: (el?: Element | string) => Promise<string | undefined>;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Wraps LaTeX in inline delimiters, through the page renderer's `wrapMath` when it has one. The
|
|
13
|
+
* fallback wraps as `@pie-lib/math-rendering` does, `$…$` for its `dollar` and `double_dollar`
|
|
14
|
+
* wrap types and `\(…\)` for any other, so a math node saves the same markup whichever renderer
|
|
15
|
+
* the authoring page installed. LaTeX that already has delimiters keeps one pair, where the legacy
|
|
16
|
+
* function adds a second: a math span saved without `data-raw` reaches the editor with its
|
|
17
|
+
* delimiters.
|
|
13
18
|
*/
|
|
14
|
-
export declare const wrapMath: (latex: string) => string;
|
|
19
|
+
export declare const wrapMath: (latex: string, wrapType?: string | null) => string;
|
|
15
20
|
/**
|
|
16
21
|
* Unwrap LaTeX delimiters - minimal implementation for editable-html-tip-tap
|
|
17
22
|
*/
|
package/dist/types.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface MathjaxOptions {
|
|
|
29
29
|
export type MathRenderer = (element: HTMLElement) => void | Promise<void>;
|
|
30
30
|
export interface MathRenderingAPI {
|
|
31
31
|
renderMath: MathRenderer;
|
|
32
|
-
wrapMath?: (latex: string) => string;
|
|
32
|
+
wrapMath?: (latex: string, wrapType?: string | null) => string;
|
|
33
33
|
unWrapMath?: (wrapped: string) => string;
|
|
34
34
|
mmlToLatex?: (mathml: string) => string;
|
|
35
35
|
}
|