@pie-element/shared-math-rendering-mathjax 0.1.3-next.20261006160832 → 0.1.3

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 CHANGED
@@ -1,107 +1,207 @@
1
+ //#region src/assets.ts
2
+ var e = "4.1.3", t = "https://github.com/pie-framework/pie-elements-ng/blob/develop/docs/MATH-RENDERING.md#assets", n = "@pie-lib/math-rendering@2", r = ["nemeth", "euro"], i = `mathjax@${e}/sre`, a = /^[^@]+@[^@]+$/;
3
+ function o(e) {
4
+ if (!e) return;
5
+ let t;
6
+ try {
7
+ t = new URL(e);
8
+ } catch {
9
+ return;
10
+ }
11
+ if (t.origin === "null") return;
12
+ let n = t.pathname.split("/");
13
+ for (let e = n.length - 1; e > 0; e--) {
14
+ let r = n[e];
15
+ if (r === "node_modules") return;
16
+ if (!a.test(r)) continue;
17
+ let i = n[e - 1]?.startsWith("@") ? e - 1 : e;
18
+ return t.origin + n.slice(0, i).join("/");
19
+ }
20
+ }
21
+ function s() {
22
+ let e = globalThis[n]?.opts;
23
+ return e && typeof e == "object" ? e : {};
24
+ }
25
+ function c(e) {
26
+ if (typeof e != "string" || !e) return;
27
+ let t = typeof document > "u" ? void 0 : document.baseURI;
28
+ try {
29
+ return new URL(e, t).href.replace(/\/+$/, "");
30
+ } catch {
31
+ return;
32
+ }
33
+ }
34
+ function l(e) {
35
+ if (!e || typeof e != "object") return;
36
+ let t = /* @__PURE__ */ new Map();
37
+ for (let [n, r] of Object.entries(e)) {
38
+ let e = c(r);
39
+ e && t.set(n, e);
40
+ }
41
+ return t.size ? t : void 0;
42
+ }
43
+ function u(e) {
44
+ if (Array.isArray(e)) return new Map(e.filter((e) => typeof e == "string").map((e) => [e, void 0]));
45
+ if (e && typeof e == "object") return new Map(Object.entries(e).map(([e, t]) => [e, typeof t == "string" ? t : void 0]));
46
+ }
47
+ function d(e, t) {
48
+ let n = s(), r = c(e.assetRoot ?? n.assetRoot) ?? o(t);
49
+ return {
50
+ root: r,
51
+ speechPath: c(e.speechPath ?? n.speechPath) ?? (r ? `${r}/${i}` : void 0),
52
+ speechLocales: u(e.speechLocales ?? n.speechLocales),
53
+ urls: l(e.assetUrls ?? n.assetUrls)
54
+ };
55
+ }
56
+ function f(e, t) {
57
+ if (!(!e || !t)) {
58
+ for (let n of [...e.keys()]) !t.has(n) && !r.includes(n) && e.delete(n);
59
+ for (let [n, r] of t) (r || !e.has(n)) && e.set(n, r ?? n);
60
+ }
61
+ }
62
+ function p(e) {
63
+ if (!(!e || e.has("en"))) return [...e.keys()].find((e) => !r.includes(e));
64
+ }
65
+ var m = "pie-mathjax-no-asset-root", h = {
66
+ untypeset: "no MathJax loads, so math stays untypeset",
67
+ "no-web-fonts": "math renders without web fonts",
68
+ "no-web-fonts-or-speech": "math renders without web fonts and speech"
69
+ }, g = Symbol.for("@pie-element/shared-math-rendering-mathjax/no-assets");
70
+ function _(e) {
71
+ let r = globalThis;
72
+ r[g] ??= [];
73
+ let i = r[g];
74
+ if (i.includes(e)) return;
75
+ i.push(e);
76
+ let a = `[math-rendering] No asset root for MathJax: ${h[e]}. Set window['${n}'].opts.assetRoot to an npm root. See ${t}`;
77
+ e === "untypeset" ? console.error(a) : console.warn(a), !(typeof window > "u") && window.dispatchEvent(new CustomEvent(m, { detail: {
78
+ effect: e,
79
+ message: a,
80
+ docsUrl: t
81
+ } }));
82
+ }
83
+ //#endregion
1
84
  //#region src/unsupported-page.ts
2
- var e = "https://github.com/pie-framework/pie-players/blob/develop/docs/item-player/loading-strategies.md#one-mathjax-version-per-page", t = "pie-mathjax-version-conflict", n = Symbol.for("@pie-element/shared-math-rendering-mathjax/unsupported-page");
3
- function r(r, i) {
85
+ var v = "https://github.com/pie-framework/pie-players/blob/develop/docs/item-player/loading-strategies.md#one-mathjax-version-per-page", y = "pie-mathjax-version-conflict", b = Symbol.for("@pie-element/shared-math-rendering-mathjax/unsupported-page");
86
+ function x(e, t) {
4
87
  if (typeof window > "u") return;
5
- let a = globalThis;
6
- a[n] ??= {
88
+ let n = globalThis;
89
+ n[b] ??= {
7
90
  logged: !1,
8
91
  conditions: []
9
92
  };
10
- let o = a[n];
11
- if (o.conditions.includes(r)) return;
12
- o.conditions.push(r);
13
- let s = `[math-rendering] Unsupported page (${r}): ${i}. 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 ${e}`;
14
- o.logged || (o.logged = !0, console.error(s)), window.dispatchEvent(new CustomEvent(t, { detail: {
15
- condition: r,
16
- message: s,
17
- docsUrl: e
93
+ let r = n[b];
94
+ if (r.conditions.includes(e)) return;
95
+ r.conditions.push(e);
96
+ 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}`;
97
+ r.logged || (r.logged = !0, console.error(i)), window.dispatchEvent(new CustomEvent(y, { detail: {
98
+ condition: e,
99
+ message: i,
100
+ docsUrl: v
18
101
  } }));
19
102
  }
20
- function i() {
103
+ function ee() {
21
104
  let e = window.MathJax?.version;
22
105
  return typeof e == "string" && e.startsWith("3.") ? e : void 0;
23
106
  }
24
107
  //#endregion
25
108
  //#region src/engine/page.ts
26
- function a() {
109
+ function S() {
27
110
  return window.MathJax;
28
111
  }
29
- function o(e, t) {
30
- return new Promise((n, r) => {
112
+ function te(t, { root: n, speechPath: r }) {
113
+ n && (t.loader = {
114
+ ...t.loader,
115
+ paths: {
116
+ fonts: `${n}/@mathjax`,
117
+ "mathjax-newcm": `${n}/@mathjax/mathjax-newcm-font@${e}`,
118
+ "mathjax-mhchem-extension": `${n}/@mathjax/mathjax-mhchem-font-extension@${e}`
119
+ }
120
+ }), r && (t.options = {
121
+ ...t.options,
122
+ worker: {
123
+ path: r,
124
+ maps: `${r}/mathmaps`
125
+ }
126
+ });
127
+ }
128
+ function ne(e, t) {
129
+ let n = t.srcUrl || (t.root ? `${t.root}/mathjax@4.1.3/tex-mml-chtml.js` : void 0);
130
+ return n ? (te(e, t), new Promise((t, r) => {
31
131
  window.MathJax = e;
32
132
  let i = document.createElement("script");
33
- i.src = t, i.async = !0, i.onload = () => n(), i.onerror = () => r(/* @__PURE__ */ Error("Failed to load MathJax")), document.head.appendChild(i);
34
- });
133
+ i.src = n, i.async = !0, i.onload = () => t(!0), i.onerror = () => r(/* @__PURE__ */ Error("Failed to load MathJax")), document.head.appendChild(i);
134
+ })) : (_("untypeset"), Promise.resolve(!1));
35
135
  }
36
- var s = globalThis, c = "PIE-MJX-CHTML-styles", l = ["MJX-CHTML-styles", "MJX-SVG-styles"], u = i, d = "http://www.w3.org/1998/Math/MathML", f = /^([a-z_][\w.-]*):math$/, p = /^[a-z][a-z0-9-]*$/;
37
- function m(e) {
136
+ var re = globalThis, C = "PIE-MJX-CHTML-styles", ie = ["MJX-CHTML-styles", "MJX-SVG-styles"], ae = ee, w = "http://www.w3.org/1998/Math/MathML", oe = /^([a-z_][\w.-]*):math$/, se = /^[a-z][a-z0-9-]*$/;
137
+ function ce(e) {
38
138
  for (let t of e.querySelectorAll("*")) {
39
- let n = f.exec(t.tagName.toLowerCase())?.[1];
40
- !n || !e.contains(t) || t.closest("mjx-container") || t.replaceWith(h(t, `${n}:`));
139
+ let n = oe.exec(t.tagName.toLowerCase())?.[1];
140
+ !n || !e.contains(t) || t.closest("mjx-container") || t.replaceWith(T(t, `${n}:`));
41
141
  }
42
142
  }
43
- function h(e, t) {
143
+ function T(e, t) {
44
144
  let n = e.tagName.toLowerCase().slice(t.length);
45
- if (!p.test(n)) return e;
46
- let r = e.ownerDocument.createElementNS(d, n);
145
+ if (!se.test(n)) return e;
146
+ let r = e.ownerDocument.createElementNS(w, n);
47
147
  for (let t of e.attributes) r.setAttribute(t.name, t.value);
48
148
  for (let n of [...e.childNodes]) {
49
149
  let e = n instanceof Element && n.tagName.toLowerCase().startsWith(t);
50
- r.appendChild(e ? h(n, t) : n);
150
+ r.appendChild(e ? T(n, t) : n);
51
151
  }
52
152
  return r;
53
153
  }
54
154
  //#endregion
55
155
  //#region src/elementary-math.ts
56
- var g = /* @__PURE__ */ new Set([
156
+ var le = /* @__PURE__ */ new Set([
57
157
  "updiagonalstrike",
58
158
  "downdiagonalstrike",
59
159
  "verticalstrike",
60
160
  "horizontalstrike"
61
- ]), _ = {
161
+ ]), ue = {
62
162
  thin: "0.035em",
63
163
  medium: "0.07em",
64
164
  thick: "0.14em"
65
- }, v = {
165
+ }, de = {
66
166
  tight: "0em",
67
167
  medium: "0.1em",
68
168
  loose: "0.2em"
69
- }, y = /^(\d+(\.\d*)?|\.\d+)(em|ex|px|pt|pc|in|cm|mm)$/, ee = /^(#[0-9a-f]{3,8}|[a-z]+)$/i, te = /^(\d+(\.\d*)?|\.\d+)$/, ne = /* @__PURE__ */ new Set([
169
+ }, fe = /^(\d+(\.\d*)?|\.\d+)(em|ex|px|pt|pc|in|cm|mm)$/, pe = /^(#[0-9a-f]{3,8}|[a-z]+)$/i, me = /^(\d+(\.\d*)?|\.\d+)$/, he = /* @__PURE__ */ new Set([
70
170
  "mn",
71
171
  "mo",
72
172
  "mi",
73
173
  "mtext"
74
- ]), re = /* @__PURE__ */ new Set([
174
+ ]), ge = /* @__PURE__ */ new Set([
75
175
  "stackalign",
76
176
  "charalign",
77
177
  "charspacing",
78
178
  "longdivstyle"
79
179
  ]);
80
- function b(e, t, n = [], r = {}) {
81
- let i = e.createElementNS(d, t);
180
+ function E(e, t, n = [], r = {}) {
181
+ let i = e.createElementNS(w, t);
82
182
  for (let [e, t] of Object.entries(r)) i.setAttribute(e, t);
83
183
  for (let e of n) e && i.appendChild(e);
84
184
  return i;
85
185
  }
86
- function x(e, t) {
87
- let n = b(e.document, "mo");
186
+ function D(e, t) {
187
+ let n = E(e.document, "mo");
88
188
  return n.textContent = t, n;
89
189
  }
90
- function S(e) {
91
- let t = b(e.document, "mn");
92
- return t.textContent = "0", b(e.document, "mphantom", [t]);
190
+ function O(e) {
191
+ let t = E(e.document, "mn");
192
+ return t.textContent = "0", E(e.document, "mphantom", [t]);
93
193
  }
94
- function C(e, t) {
194
+ function k(e, t) {
95
195
  return e.getAttribute(t)?.trim().toLowerCase() || void 0;
96
196
  }
97
- function w(e, t) {
197
+ function A(e, t) {
98
198
  let n = Number.parseInt(e.getAttribute(t) ?? "", 10);
99
199
  return Number.isFinite(n) ? n : 0;
100
200
  }
101
- function T(e) {
201
+ function j(e) {
102
202
  return e.localName === "none" || e.localName === "mrow" && e.children.length === 0 && !e.textContent?.trim();
103
203
  }
104
- function E(e, t, n = e) {
204
+ function M(e, t, n = e) {
105
205
  switch (t) {
106
206
  case "left": return 0;
107
207
  case "center": return Math.floor(e / 2);
@@ -109,14 +209,14 @@ function E(e, t, n = e) {
109
209
  default: return n;
110
210
  }
111
211
  }
112
- function D(e, t, n) {
212
+ function N(e, t, n) {
113
213
  let r = [], i, a, o = (e, t) => {
114
214
  let s = (e) => t.reduceRight((e, t) => {
115
215
  let n = t.cloneNode(!1);
116
216
  return n.appendChild(e), n;
117
217
  }, e);
118
218
  if (e.localName === "mstyle") for (let n of [...e.children]) o(n, [...t, e]);
119
- else if (T(e)) r.push(null);
219
+ else if (j(e)) r.push(null);
120
220
  else if (e.localName === "mn" && e.children.length === 0) {
121
221
  let t = [...(e.textContent ?? "").trim()];
122
222
  for (let a of t) {
@@ -125,28 +225,28 @@ function D(e, t, n) {
125
225
  t.textContent = a, r.push(s(t));
126
226
  }
127
227
  t.length && (a ??= r.length);
128
- } else ne.has(e.localName) && e.textContent?.trim() === n.decimalPoint && (i ??= r.length), r.push(s(e));
228
+ } else he.has(e.localName) && e.textContent?.trim() === n.decimalPoint && (i ??= r.length), r.push(s(e));
129
229
  };
130
230
  for (let t of e) o(t, []);
131
231
  return {
132
232
  kind: "digits",
133
233
  cells: r,
134
- anchor: E(r.length, n.stackAlign, i ?? a),
234
+ anchor: M(r.length, n.stackAlign, i ?? a),
135
235
  position: t
136
236
  };
137
237
  }
138
- function O(e) {
139
- return (e ?? "").toLowerCase().split(/\s+/).filter((e) => g.has(e));
238
+ function _e(e) {
239
+ return (e ?? "").toLowerCase().split(/\s+/).filter((e) => le.has(e));
140
240
  }
141
- function ie(e, t) {
142
- let n = [...e.children].filter((e) => !T(e));
143
- return n.length <= 1 ? n[0] ?? null : b(t.document, "mrow", n);
241
+ function ve(e, t) {
242
+ let n = [...e.children].filter((e) => !j(e));
243
+ return n.length <= 1 ? n[0] ?? null : E(t.document, "mrow", n);
144
244
  }
145
- function ae(e, t, n) {
146
- let r = C(e, "location") ?? "n", i = O(e.getAttribute("crossout")), a = [...e.children].map((e) => T(e) ? null : e.localName === "mscarry" ? {
147
- content: ie(e, n),
148
- location: C(e, "location") ?? r,
149
- crossout: e.hasAttribute("crossout") ? O(e.getAttribute("crossout")) : i
245
+ function ye(e, t, n) {
246
+ let r = k(e, "location") ?? "n", i = _e(e.getAttribute("crossout")), a = [...e.children].map((e) => j(e) ? null : e.localName === "mscarry" ? {
247
+ content: ve(e, n),
248
+ location: k(e, "location") ?? r,
249
+ crossout: e.hasAttribute("crossout") ? _e(e.getAttribute("crossout")) : i
150
250
  } : {
151
251
  content: e,
152
252
  location: r,
@@ -155,60 +255,60 @@ function ae(e, t, n) {
155
255
  return {
156
256
  kind: "carries",
157
257
  carries: a,
158
- anchor: E(a.length, n.stackAlign),
258
+ anchor: M(a.length, n.stackAlign),
159
259
  position: t,
160
- scale: te.test(o) ? o : "0.6"
260
+ scale: me.test(o) ? o : "0.6"
161
261
  };
162
262
  }
163
- function oe(e) {
164
- let t = C(e, "mslinethickness") ?? "medium", n = _[t] ?? (y.test(t) ? t : "0.07em"), r = e.getAttribute("mathcolor")?.trim() ?? "";
165
- return `${n} solid ${ee.test(r) ? r : "currentColor"}`;
263
+ function be(e) {
264
+ let t = k(e, "mslinethickness") ?? "medium", n = ue[t] ?? (fe.test(t) ? t : "0.07em"), r = e.getAttribute("mathcolor")?.trim() ?? "";
265
+ return `${n} solid ${pe.test(r) ? r : "currentColor"}`;
166
266
  }
167
- function se(e, t, n) {
168
- let r = Math.max(0, w(e, "length"));
267
+ function xe(e, t, n) {
268
+ let r = Math.max(0, A(e, "length"));
169
269
  return {
170
270
  kind: "line",
171
271
  length: r,
172
- anchor: E(r, n.stackAlign),
272
+ anchor: M(r, n.stackAlign),
173
273
  position: t,
174
- border: oe(e)
274
+ border: be(e)
175
275
  };
176
276
  }
177
- function k(e, t, n, r, i) {
277
+ function P(e, t, n, r, i) {
178
278
  e.forEach((e, a) => {
179
- let o = t + a * n + w(e, "position");
279
+ let o = t + a * n + A(e, "position");
180
280
  switch (e.localName) {
181
281
  case "msgroup":
182
- k([...e.children], o, w(e, "shift"), r, i);
282
+ P([...e.children], o, A(e, "shift"), r, i);
183
283
  break;
184
284
  case "msline":
185
- i.push(se(e, o, r));
285
+ i.push(xe(e, o, r));
186
286
  break;
187
287
  case "mscarries":
188
- i.push(ae(e, o, r));
288
+ i.push(ye(e, o, r));
189
289
  break;
190
290
  case "msrow":
191
291
  case "mrow":
192
- i.push(D([...e.children], o, r));
292
+ i.push(N([...e.children], o, r));
193
293
  break;
194
- default: i.push(D([e], o, r));
294
+ default: i.push(N([e], o, r));
195
295
  }
196
296
  });
197
297
  }
198
- function A(e) {
298
+ function F(e) {
199
299
  return -e.anchor - e.position;
200
300
  }
201
- function j(e) {
301
+ function I(e) {
202
302
  return e.kind === "digits" ? e.cells.length : e.kind === "carries" ? e.carries.length : e.length;
203
303
  }
204
- function M(e) {
205
- return A(e) + j(e) - 1;
304
+ function L(e) {
305
+ return F(e) + I(e) - 1;
206
306
  }
207
- function ce(e, t, n, r) {
208
- let i = (e) => b(r.document, "mpadded", [t], {
307
+ function Se(e, t, n, r) {
308
+ let i = (e) => E(r.document, "mpadded", [t], {
209
309
  width: "0",
210
310
  ...e ? { lspace: e } : {}
211
- }), a = (e, t) => b(r.document, e, t);
311
+ }), a = (e, t) => E(r.document, e, t);
212
312
  switch (n) {
213
313
  case "s": return a("munder", [e, i("-0.5width")]);
214
314
  case "ne": return a("msup", [e, i()]);
@@ -230,49 +330,49 @@ function ce(e, t, n, r) {
230
330
  default: return a("mover", [e, i("-0.5width")]);
231
331
  }
232
332
  }
233
- function le(e, t, n) {
234
- let r = b(n.document, "menclose", [e], {
333
+ function Ce(e, t, n) {
334
+ let r = E(n.document, "menclose", [e], {
235
335
  notation: t.join(" "),
236
336
  "data-padding": "0.1em",
237
337
  "data-thickness": "0.067em"
238
338
  }), i = t.some((e) => e.endsWith("diagonalstrike")) ? .167 : t.includes("horizontalstrike") ? .1 : 0;
239
- return i ? b(n.document, "mpadded", [r], {
339
+ return i ? E(n.document, "mpadded", [r], {
240
340
  lspace: `-${i}em`,
241
341
  width: `-${2 * i}em`
242
342
  }) : r;
243
343
  }
244
- function ue(e, t, n, r, i) {
245
- let a = e && t.crossout.length ? le(e, t.crossout, i) : e;
344
+ function we(e, t, n, r, i) {
345
+ let a = e && t.crossout.length ? Ce(e, t.crossout, i) : e;
246
346
  if (!t.content) return a;
247
- let o = b(i.document, "mstyle", [t.content], { scriptsizemultiplier: r });
248
- return ce(a ?? S(i), o, n, i);
347
+ let o = E(i.document, "mstyle", [t.content], { scriptsizemultiplier: r });
348
+ return Se(a ?? O(i), o, n, i);
249
349
  }
250
- function N(e, t) {
251
- return e.carries[t - A(e)] ?? null;
350
+ function R(e, t) {
351
+ return e.carries[t - F(e)] ?? null;
252
352
  }
253
- function de(e, t, n, r) {
353
+ function Te(e, t, n, r) {
254
354
  let i = e.content;
255
355
  n.forEach((e, a) => {
256
- let o = n.length - 1 - a, s = n[o], c = N(s, t), l = n.slice(0, o).some((e) => N(e, t));
356
+ let o = n.length - 1 - a, s = n[o], c = R(s, t), l = n.slice(0, o).some((e) => R(e, t));
257
357
  if (!c && !l) return;
258
358
  let u = c ?? {
259
- content: S(r),
359
+ content: O(r),
260
360
  location: "n",
261
361
  crossout: []
262
362
  }, d = a === 0 ? u.location : "n";
263
- i = ue(i, u, d, s.scale, r);
363
+ i = we(i, u, d, s.scale, r);
264
364
  }), e.content = i;
265
365
  }
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 }, () => ({
366
+ function z(e, t) {
367
+ let n = e.filter((e) => I(e) > 0), r = Math.min(0, ...n.map(F)), i = Math.max(r, ...n.map(L)) - r + 1, a = -r, o = [], s = /* @__PURE__ */ new Map(), c = () => Array.from({ length: i }, () => ({
268
368
  content: null,
269
369
  borders: {}
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) => {
370
+ })), l = (e) => e.length === 0 ? Array.from({ length: i }, (e, t) => t) : Array.from({ length: e.length }, (t, n) => a + F(e) + n), u = [], d = [], f = (e) => {
271
371
  let n = c();
272
372
  e.cells.forEach((t, r) => {
273
- n[a + A(e) + r].content = t;
373
+ n[a + F(e) + r].content = t;
274
374
  }), u.length && n.forEach((e, n) => {
275
- de(e, n - a, u, t);
375
+ Te(e, n - a, u, t);
276
376
  });
277
377
  for (let e of d) for (let t of l(e)) n[t].borders.top = e.border;
278
378
  u = [], d = [], s.set(e, o.length), o.push(n);
@@ -292,44 +392,44 @@ function P(e, t) {
292
392
  origin: a
293
393
  };
294
394
  }
295
- function F(e, { rows: t }, n) {
296
- let r = b(n.document, "mtable", t.map((e) => b(n.document, "mtr", e.map((e) => {
395
+ function B(e, { rows: t }, n) {
396
+ let r = E(n.document, "mtable", t.map((e) => E(n.document, "mtr", e.map((e) => {
297
397
  let t = Object.entries(e.borders).map(([e, t]) => `border-${e}:${t}`).join(";");
298
- return b(n.document, "mtd", [e.content], {
398
+ return E(n.document, "mtd", [e.content], {
299
399
  ...t ? { style: t } : {},
300
400
  ...e.align ? { columnalign: e.align } : {}
301
401
  });
302
402
  }))));
303
- for (let { name: t, value: n } of [...e.attributes]) re.has(t) || r.setAttribute(t, n);
304
- let i = C(e, "charspacing") ?? "medium", a = C(e, "charalign");
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;
403
+ for (let { name: t, value: n } of [...e.attributes]) ge.has(t) || r.setAttribute(t, n);
404
+ let i = k(e, "charspacing") ?? "medium", a = k(e, "charalign");
405
+ return r.setAttribute("columnspacing", de[i] ?? (fe.test(i) ? i : de.medium)), r.setAttribute("columnalign", a === "left" || a === "center" ? a : "right"), r.setAttribute("rowspacing", "0"), r.setAttribute("align", e.getAttribute("align") ?? "baseline"), r;
306
406
  }
307
- function I(e) {
407
+ function V(e) {
308
408
  return {
309
409
  document: e.ownerDocument,
310
- stackAlign: C(e, "stackalign") ?? "decimalpoint",
410
+ stackAlign: k(e, "stackalign") ?? "decimalpoint",
311
411
  decimalPoint: e.closest("[decimalpoint]")?.getAttribute("decimalpoint")?.trim().charAt(0) || "."
312
412
  };
313
413
  }
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);
414
+ function Ee(e) {
415
+ let t = V(e), n = [];
416
+ return P([...e.children], 0, 0, t, n), B(e, z(n, t), t);
317
417
  }
318
- function L(e, t, n, r, i, a) {
418
+ function H(e, t, n, r, i, a) {
319
419
  for (let o = n; o <= r; o++) e[t][o].borders[i] = a;
320
420
  }
321
- function pe(e, t) {
322
- let n = x(t, ")");
323
- return n.setAttribute("minsize", "1.2em"), [b(t.document, "mrow", [e, b(t.document, "mspace", [], { width: "0.2em" })]), b(t.document, "mpadded", [n], {
421
+ function De(e, t) {
422
+ let n = D(t, ")");
423
+ return n.setAttribute("minsize", "1.2em"), [E(t.document, "mrow", [e, E(t.document, "mspace", [], { width: "0.2em" })]), E(t.document, "mpadded", [n], {
324
424
  voffset: "0.1em",
325
425
  lspace: "-0.15em",
326
426
  depth: "-0.2em",
327
427
  height: "-0.2em"
328
428
  })];
329
429
  }
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);
430
+ function Oe(e) {
431
+ let t = V(e), [n, r, ...i] = [...e.children], a = n && !j(n) ? n : null, o = r && !j(r) ? r : null, s = k(e, "longdivstyle") ?? "lefttop", c = be(e), l = [];
432
+ P(i, 0, 0, t, l);
333
433
  let u = l.find((e) => e.kind === "digits");
334
434
  u || (u = {
335
435
  kind: "digits",
@@ -341,51 +441,51 @@ function me(e) {
341
441
  u.cells.unshift(...e), u.anchor += e.length;
342
442
  }, p = (...e) => {
343
443
  let n = e.flatMap((e) => e ? e.localName === "mrow" ? [...e.children] : [e] : []);
344
- u.cells.push(...D(n, 0, t).cells);
444
+ u.cells.push(...N(n, 0, t).cells);
345
445
  };
346
446
  switch (s) {
347
447
  case "left/\\right":
348
- f(a, x(t, "/")), p(x(t, "\\"), o);
448
+ f(a, D(t, "/")), p(D(t, "\\"), o);
349
449
  break;
350
450
  case "left)(right":
351
- f(a, x(t, ")")), p(x(t, "("), o);
451
+ f(a, D(t, ")")), p(D(t, "("), o);
352
452
  break;
353
453
  case ":right=right":
354
- p(x(t, ":"), a, x(t, "="), o);
454
+ p(D(t, ":"), a, D(t, "="), o);
355
455
  break;
356
456
  case "righttop":
357
457
  case "stackedleftlinetop":
358
458
  case "lefttop":
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));
459
+ o && P([o], 0, 0, t, d), l.splice(l.indexOf(u), 0, ...d), s === "righttop" ? p(a) : s === "stackedleftlinetop" ? f(a) : f(...De(a, t));
360
460
  break;
361
461
  }
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)));
462
+ let m = z(l, t), h = m.rows, g = m.rowOf.get(u) ?? 0, _ = (e) => m.origin + F(u) + e, v = Math.max(_(u.cells.length - 1), ...d.map((e) => m.origin + L(e)));
363
463
  switch (s) {
364
464
  case "left/\\right":
365
465
  case "left)(right":
366
466
  case ":right=right": break;
367
467
  case "righttop": {
368
468
  let e = h[g][_(u.cells.length - 1)];
369
- e.borders.left = c, e.borders.bottom = c, L(h, g, _(0), _(u.cells.length - 1), "top", c);
469
+ e.borders.left = c, e.borders.bottom = c, H(h, g, _(0), _(u.cells.length - 1), "top", c);
370
470
  break;
371
471
  }
372
472
  case "stackedleftlinetop": {
373
473
  let e = h[g][_(0)];
374
- e.borders.right = c, e.borders.bottom = c, L(h, g, _(1), v, "top", c);
474
+ e.borders.right = c, e.borders.bottom = c, H(h, g, _(1), v, "top", c);
375
475
  break;
376
476
  }
377
477
  case "stackedrightright":
378
478
  case "mediumstackedrightright":
379
479
  case "shortstackedrightright":
380
480
  case "stackedleftleft":
381
- he(h, g, s, a, o, c, t);
481
+ ke(h, g, s, a, o, c, t);
382
482
  break;
383
- default: L(h, g, _(1), v, "top", c);
483
+ default: H(h, g, _(1), v, "top", c);
384
484
  }
385
- return F(e, m, t);
485
+ return B(e, m, t);
386
486
  }
387
- function he(e, t, n, r, i, a, o) {
388
- let s = n === "stackedleftleft", c = s ? "right" : "left", l = (e) => e && b(o.document, "mpadded", [e], {
487
+ function ke(e, t, n, r, i, a, o) {
488
+ let s = n === "stackedleftleft", c = s ? "right" : "left", l = (e) => e && E(o.document, "mpadded", [e], {
389
489
  lspace: "0.2em",
390
490
  width: "+0.4em"
391
491
  });
@@ -404,118 +504,140 @@ function he(e, t, n, r, i, a, o) {
404
504
  }) : 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
505
  });
406
506
  }
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));
507
+ function Ae(e) {
508
+ for (let t of [...e.querySelectorAll("mstack, mlongdiv")]) !t.closest("math") || t.closest("mjx-container") || t.replaceWith(t.localName === "mstack" ? Ee(t) : Oe(t));
409
509
  }
410
510
  //#endregion
411
511
  //#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 = `
512
+ var je = "PIE-MJX-explorer-styles", U = "var(--pie-text, black)", Me = "var(--pie-background, #ffffff)", Ne = "var(--pie-border-dark, #66686A)", W = "var(--pie-focus-outline, var(--pie-button-focus-outline, var(--pie-focus-checked-border, #1565C0)))", G = `color-mix(in srgb, ${W} 15%, transparent)`, Pe = `
413
513
  :root mjx-container [data-sre-highlight-1]:not([data-mjx-collapsed], rect) {
414
- color: ${R} !important;
415
- fill: ${R} !important;
514
+ color: ${U} !important;
515
+ fill: ${U} !important;
416
516
  }
417
517
  :root mjx-container:not([data-mjx-clone-container]) [data-sre-highlight-1]:not([data-sre-enclosed], rect) {
418
- background-color: ${B} !important;
518
+ background-color: ${G} !important;
419
519
  }
420
520
  :root mjx-container rect[data-sre-highlight-1]:not([data-sre-enclosed]) {
421
- fill: ${B} !important;
521
+ fill: ${G} !important;
422
522
  }
423
523
  :root mjx-container .mjx-selected {
424
- outline: 2px solid ${z} !important;
524
+ outline: 2px solid ${W} !important;
425
525
  }
426
526
  :root mjx-container [data-sre-highlight-2] {
427
- color: ${R} !important;
527
+ color: ${U} !important;
428
528
  background-color: transparent !important;
429
- fill: ${R} !important;
430
- outline: 2px dashed ${z} !important;
529
+ fill: ${U} !important;
530
+ outline: 2px dashed ${W} !important;
431
531
  }
432
532
  :root mjx-container rect[data-sre-highlight-2] {
433
533
  fill: transparent !important;
434
- stroke: ${z} !important;
534
+ stroke: ${W} !important;
435
535
  stroke-width: 2px !important;
436
536
  vector-effect: non-scaling-stroke;
437
537
  }
438
538
  :root .MJX_LiveRegion, :root .MJX_HoverRegion, :root .MJX_ToolTip {
439
- color: ${R} !important;
440
- background-color: ${ve} !important;
441
- border-color: ${ye} !important;
539
+ color: ${U} !important;
540
+ background-color: ${Me} !important;
541
+ border-color: ${Ne} !important;
442
542
  }
443
543
  :root .MJX_LiveRegion > div, :root .MJX_HoverRegion > div {
444
- color: ${R} !important;
445
- background-color: ${B} !important;
544
+ color: ${U} !important;
545
+ background-color: ${G} !important;
446
546
  }
447
547
  `;
448
- function xe(e = document) {
548
+ function Fe(e = document) {
449
549
  if (e.getElementById("PIE-MJX-explorer-styles")) return;
450
550
  let t = e.createElement("style");
451
- t.id = _e, t.textContent = be, e.head.appendChild(t);
551
+ t.id = je, t.textContent = Pe, e.head.appendChild(t);
552
+ }
553
+ //#endregion
554
+ //#region src/speech-worker.ts
555
+ var K = Symbol.for("@pie-element/shared-math-rendering-mathjax/speech-worker-failed");
556
+ function Ie() {
557
+ let e = globalThis;
558
+ e[K] || (e[K] = !0, console.warn(`[math-rendering] MathJax's speech worker did not start, so speech, braille and the explorer are off. A content security policy must allow blob: workers, and scripts and fetches from the asset root. See ${t}`));
559
+ }
560
+ function Le(e) {
561
+ let t = e.webworker;
562
+ if (!t || t.ready) return;
563
+ e.options ??= {};
564
+ let n = e.options;
565
+ n.enableSpeech = !1, n.enableBraille = !1, n.speechError = () => {}, t.Post = () => Promise.reject(/* @__PURE__ */ Error("The speech worker did not start")), t.Terminate(), Ie();
452
566
  }
567
+ function Re(e) {
568
+ let t = e?.adaptor, n = t?.createWorker;
569
+ !e || !t || !n || (t.createWorker = async (r, i) => {
570
+ let a = await n.call(t, r, i);
571
+ return a.addEventListener("error", () => Le(e), { once: !0 }), a;
572
+ });
573
+ }
574
+ `${i}`;
453
575
  //#endregion
454
576
  //#region src/adapter.ts
455
- var Se = "https://cdn.jsdelivr.net/npm/mathjax@4.1.3/tex-mml-chtml.js", Ce = {
577
+ var ze = {
456
578
  parallelogram: "\\lower.2em{\\Huge\\unicode{x25B1}}",
457
579
  overarc: "\\overparen",
458
580
  napprox: "\\not\\approx",
459
581
  longdiv: "\\enclose{longdiv}",
460
582
  abs: ["\\left|#1\\right|", 1]
461
- }, we = "[math-rendering] using $ is not advisable, please use $$..$$ or \\(...\\)", Te = /\\\(|\\\[|\$\$|\\\$|\\begin\{|\\(?:eq)?ref\{/, Ee = /\\\(|\\\[|\$|\\begin\{|\\(?:eq)?ref\{/, De = /\\embed\{newLine\}\[\]/g, Oe = [
583
+ }, Be = "[math-rendering] using $ is not advisable, please use $$..$$ or \\(...\\)", Ve = /\\\(|\\\[|\$\$|\\\$|\\begin\{|\\(?:eq)?ref\{/, He = /\\\(|\\\[|\$|\\begin\{|\\(?:eq)?ref\{/, Ue = /\\embed\{newLine\}\[\]/g, We = [
462
584
  ["$$", "$$"],
463
585
  ["$", "$"],
464
586
  ["\\[", "\\]"],
465
587
  ["\\(", "\\)"]
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]": {
588
+ ], q = Symbol.for("@pie-element/shared-math-rendering-mathjax/loading"), Ge = "MJX-CHTML-styles", Ke = "PIE-MJX-SVG-styles", J = "PIE-MathJax-Menu-Settings", qe = { "mjx-container[overflow=\"linebreak\"][display]": {
467
589
  overflow: "auto clip",
468
590
  "min-width": "initial !important"
469
- } }, Me = 200, Ne = 201;
470
- function U(e) {
591
+ } }, Je = 200, Ye = 201;
592
+ function Y(e) {
471
593
  let t = [...e.matches("mjx-container") ? [e] : [], ...e.querySelectorAll("mjx-container")];
472
594
  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");
473
595
  }
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);
596
+ function X(e) {
597
+ for (let [t, n] of We) if (e.startsWith(t) && e.endsWith(n)) return e.substring(t.length, e.length - n.length);
476
598
  return e;
477
599
  }
478
- function Pe(e) {
479
- return W(e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e);
600
+ function Xe(e) {
601
+ return X(e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e);
480
602
  }
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);
603
+ var Ze = "mathjax_ignore", Qe = "mathjax_process";
604
+ function $e(e, t) {
605
+ let n = e.closest(`.${Ze}, .${Qe}`);
606
+ return n !== null && t.contains(n) && !n.classList.contains(Qe);
485
607
  }
486
- function Le(e) {
608
+ function et(e) {
487
609
  for (let t of e.querySelectorAll("[data-latex]")) {
488
- if (t.dataset.mathHandled || t.closest("mjx-container") || Ie(t, e)) continue;
610
+ if (t.dataset.mathHandled || t.closest("mjx-container") || $e(t, e)) continue;
489
611
  let n = t.textContent;
490
- n && (t.textContent = `\\(${Pe(n)}\\)`.replace(De, "\\newline "), t.dataset.mathHandled = "true");
612
+ n && (t.textContent = `\\(${Xe(n)}\\)`.replace(Ue, "\\newline "), t.dataset.mathHandled = "true");
491
613
  }
492
614
  }
493
- function Re(e) {
615
+ function tt(e) {
494
616
  for (let t of e.querySelectorAll("math")) t.closest("mjx-container") || t.setAttribute("displaystyle", "true");
495
617
  }
496
- function ze(e, t) {
618
+ function nt(e, t) {
497
619
  for (let t of e.querySelectorAll("math")) if (!t.closest("mjx-assistive-mml")) return !0;
498
- return (t ? Ee : Te).test(e.textContent ?? "");
620
+ return (t ? He : Ve).test(e.textContent ?? "");
499
621
  }
500
- function Be(e) {
622
+ function rt(e) {
501
623
  return new Promise((t, n) => {
502
- let { useSingleDollar: r = !1, accessibility: i = !0, loadFonts: s = !0, srcUrl: c } = e, l = {
624
+ let { useSingleDollar: r = !1, accessibility: i = !0, loadFonts: a = !0, srcUrl: o } = e, s = d(e, import.meta.url), c = {
503
625
  loader: {
504
626
  load: i ? ["a11y/assistive-mml"] : [],
505
627
  failed: (e) => n(e),
506
628
  "output/svg": { ready: (e) => {
507
- let t = a();
508
- return K(t) && q(t), e;
629
+ let t = S();
630
+ return it(t) && at(t), e;
509
631
  } }
510
632
  },
511
633
  startup: {
512
634
  typeset: !1,
513
635
  ready: () => {
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);
636
+ let e = S(), r = e?.startup, i = it(e);
637
+ i && (at(e), ot(e, s.speechLocales), f(e?._?.a11y?.sre_ts?.locales, s.speechLocales)), r?.defaultReady?.(), i && (st(r?.document), r?.document?.addStyles?.(qe), Re(r?.document)), Promise.resolve(r?.promise).then(() => t(), n);
516
638
  }
517
639
  },
518
- tex: { macros: { ...Ce } },
640
+ tex: { macros: { ...ze } },
519
641
  output: { displayOverflow: "linebreak" },
520
642
  options: {
521
643
  enableMenu: i,
@@ -527,165 +649,173 @@ function Be(e) {
527
649
  a11y: { inTabOrder: !1 }
528
650
  }
529
651
  };
530
- r && l.tex && (console.warn(we), l.tex.inlineMath = [["$", "$"], ["\\(", "\\)"]], l.tex.processEscapes = !0), s || (l.chtml = { fontURL: "" }), o(l, c || Se).catch(n);
652
+ r && c.tex && (console.warn(Be), c.tex.inlineMath = [["$", "$"], ["\\(", "\\)"]], c.tex.processEscapes = !0), a || (c.chtml = { fontURL: "" });
653
+ let l = p(s.speechLocales);
654
+ l && c.options && (c.options.sre = { locale: l }), ne(c, {
655
+ ...s,
656
+ srcUrl: o
657
+ }).then((e) => {
658
+ e || t();
659
+ }, n);
531
660
  });
532
661
  }
533
- function K(e) {
662
+ function it(e) {
534
663
  return !!e?.version?.startsWith("4.");
535
664
  }
536
- function q(e) {
665
+ function at(e) {
537
666
  let t = e?._?.output, n = t?.chtml_ts?.CHTML;
538
- n && (n.STYLESHEETID = c);
667
+ n && (n.STYLESHEETID = C);
539
668
  let r = t?.svg_ts?.SVG;
540
- r && (r.STYLESHEETID = Ae);
669
+ r && (r.STYLESHEETID = Ke);
541
670
  }
542
- function Ve(e) {
543
- let t = e?._?.ui?.menu?.Menu?.Menu;
544
- if (t) {
545
- t.MENU_STORAGE = H;
671
+ function ot(e, t) {
672
+ let n = e?._?.ui?.menu?.Menu?.Menu;
673
+ if (n) {
674
+ n.MENU_STORAGE = J;
546
675
  try {
547
- let e = localStorage.getItem(H);
676
+ let e = localStorage.getItem(J);
548
677
  if (!e) return;
549
- let { assistiveMml: t, ...n } = JSON.parse(e);
550
- if (t === void 0) return;
551
- Object.keys(n).length ? localStorage.setItem(H, JSON.stringify(n)) : localStorage.removeItem(H);
678
+ let { assistiveMml: n, locale: r, ...i } = JSON.parse(e), a = r === void 0 || !t || t.has(r);
679
+ if (n === void 0 && a) return;
680
+ a && r !== void 0 && (i.locale = r), Object.keys(i).length ? localStorage.setItem(J, JSON.stringify(i)) : localStorage.removeItem(J);
552
681
  } catch {}
553
682
  }
554
683
  }
555
- function He(e) {
684
+ function st(e) {
556
685
  if (!e) return;
557
686
  let t = /* @__PURE__ */ new WeakSet(), n = (e) => {
558
687
  let n = e.typesetRoot;
559
- !n || t.has(n) || (U(n), t.add(n));
688
+ !n || t.has(n) || (Y(n), t.add(n));
560
689
  };
561
- e.addRenderAction?.("pie-strip-latex", Ne, (e) => {
690
+ e.addRenderAction?.("pie-strip-latex", Ye, (e) => {
562
691
  for (let t of e.math ?? []) n(t);
563
692
  return !1;
564
693
  }, (e) => {
565
694
  let t = e.typesetRoot;
566
- return t && U(t), !1;
695
+ return t && Y(t), !1;
567
696
  });
568
697
  let r = e.outputJax?.chtmlStyles;
569
- r?.id === ke && (r.id = c), Ue();
698
+ r?.id === Ge && (r.id = C), ut();
570
699
  }
571
- function J(e) {
572
- return e instanceof HTMLStyleElement && l.includes(e.id);
700
+ function ct(e) {
701
+ return e instanceof HTMLStyleElement && ie.includes(e.id);
573
702
  }
574
- function Y(e) {
575
- r("foreign-output-stylesheet", `another MathJax added <style id="${e.id}"> to <head>`);
703
+ function lt(e) {
704
+ x("foreign-output-stylesheet", `another MathJax added <style id="${e.id}"> to <head>`);
576
705
  }
577
- function Ue() {
578
- let e = document.head, t = [...e.children].find(J);
706
+ function ut() {
707
+ let e = document.head, t = [...e.children].find(ct);
579
708
  if (t) {
580
- Y(t);
709
+ lt(t);
581
710
  return;
582
711
  }
583
712
  let n = new MutationObserver((e) => {
584
713
  for (let t of e) {
585
- let e = [...t.addedNodes].find(J);
714
+ let e = [...t.addedNodes].find(ct);
586
715
  if (e) {
587
- Y(e), n.disconnect();
716
+ lt(e), n.disconnect();
588
717
  return;
589
718
  }
590
719
  }
591
720
  });
592
721
  n.observe(e, { childList: !0 });
593
722
  }
594
- function We(e) {
723
+ function dt(e) {
595
724
  let t = e?.math;
596
725
  if (!t?.remove) return;
597
- let n = [...t].filter((e) => (e.state?.() ?? 0) >= Me && e.typesetRoot?.isConnected === !1);
726
+ let n = [...t].filter((e) => (e.state?.() ?? 0) >= Je && e.typesetRoot?.isConnected === !1);
598
727
  if (n.length !== 0) {
599
728
  for (let e of [...n].reverse()) e.clear?.();
600
729
  t.remove(...n);
601
730
  }
602
731
  }
603
- function Ge(e) {
732
+ function ft(e) {
604
733
  return new Promise((t, n) => {
605
734
  let r = e.startup ?? {};
606
735
  e.startup = r;
607
736
  let i = r.ready;
608
737
  r.ready = () => {
609
- let e = a()?.startup;
738
+ let e = S()?.startup;
610
739
  i ? i.call(r) : e?.defaultReady?.(), Promise.resolve(e?.promise).then(() => t(), n);
611
740
  };
612
741
  });
613
742
  }
614
- function Ke(e) {
615
- let t = a();
616
- return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() : Ge(t) : Be(e);
743
+ function pt(e) {
744
+ let t = S();
745
+ return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() : ft(t) : rt(e);
617
746
  }
618
- function qe(e) {
619
- return Ke(e).then(() => {
620
- typeof a()?.typesetPromise != "function" && console.warn("[mathjax-renderer] MathJax on this page has no typesetPromise; math stays untypeset.");
747
+ function mt(e) {
748
+ return pt(e).then(() => {
749
+ let e = S();
750
+ e && typeof e.typesetPromise != "function" && console.warn("[mathjax-renderer] MathJax on this page has no typesetPromise; math stays untypeset.");
621
751
  });
622
752
  }
623
- function Je(e) {
624
- let t = s, n = t[V];
625
- return n || (n = qe(e), t[V] = n), n;
753
+ function ht(e) {
754
+ let t = re, n = t[q];
755
+ return n || (n = mt(e), t[q] = n), n;
626
756
  }
627
- function X(e = {}) {
757
+ function gt(e = {}) {
628
758
  let t = e.useSingleDollar ?? !1;
629
759
  return async (n) => {
630
760
  if (typeof window > "u") return;
631
- let i = u();
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)) {
635
- o.catch(() => {});
761
+ let r = ae();
762
+ r && x("mathjax-3-global", `window.MathJax is MathJax ${r}`), et(n), ce(n), tt(n), Ae(n);
763
+ let i = ht(e);
764
+ if (!nt(n, t)) {
765
+ i.catch(() => {});
636
766
  return;
637
767
  }
638
- await o;
639
- let s = a();
640
- if (await s?.startup?.promise, typeof s?.typesetPromise == "function") {
641
- xe(), We(s.startup?.document);
768
+ await i;
769
+ let a = S();
770
+ if (await a?.startup?.promise, typeof a?.typesetPromise == "function") {
771
+ Fe(), dt(a.startup?.document);
642
772
  try {
643
- await s.typesetPromise([n]);
773
+ await a.typesetPromise([n]);
644
774
  } catch (e) {
645
- throw s.typesetClear?.([n]), e;
775
+ throw a.typesetClear?.([n]), e;
646
776
  }
647
- U(n);
777
+ Y(n);
648
778
  }
649
779
  };
650
780
  }
651
- function Ye() {
781
+ function _t() {
652
782
  return [];
653
783
  }
654
784
  //#endregion
655
785
  //#region src/render-math.ts
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;
786
+ var vt = "@pie-lib/math-rendering", yt = "@pie-lib/math-rendering@2", bt = "pie-print", xt = 50, St = 1e4, Ct = null;
787
+ function wt() {
788
+ return !!window[yt]?.opts?.useSingleDollar;
659
789
  }
660
- function nt() {
661
- return Z ||= X({ useSingleDollar: tt() }), Z;
790
+ function Tt() {
791
+ return Ct ||= gt({ useSingleDollar: wt() }), Ct;
662
792
  }
663
- function Q() {
793
+ function Z() {
664
794
  if (typeof window > "u") return null;
665
- let e = window[Xe];
795
+ let e = window[vt];
666
796
  return typeof e?.renderMath == "function" && e.renderMath !== $ ? e : null;
667
797
  }
668
- function rt(e) {
798
+ function Et(e) {
669
799
  let t = e;
670
800
  for (; t;) {
671
- if (t instanceof Element && t.localName === Qe) return t;
801
+ if (t instanceof Element && t.localName === bt) return t;
672
802
  t = t instanceof ShadowRoot ? t.host : t.parentNode;
673
803
  }
674
804
  return null;
675
805
  }
676
- function it() {
806
+ function Q() {
677
807
  let e = window.renderMath;
678
808
  return typeof e == "function" ? e : null;
679
809
  }
680
- async function at(e) {
681
- let t = rt(e);
810
+ async function Dt(e) {
811
+ let t = Et(e);
682
812
  if (!t) return null;
683
- let n = it();
813
+ let n = Q();
684
814
  if (n || t.mathRenderingModuleUrlImported !== !0) return n;
685
- let r = Date.now() + et;
815
+ let r = Date.now() + St;
686
816
  for (; Date.now() < r;) {
687
- await new Promise((e) => setTimeout(e, $e));
688
- let e = it();
817
+ await new Promise((e) => setTimeout(e, xt));
818
+ let e = Q();
689
819
  if (e) return e;
690
820
  }
691
821
  return null;
@@ -694,14 +824,14 @@ var $ = async (e) => {
694
824
  if (typeof window > "u") return;
695
825
  let t = typeof e == "string", n;
696
826
  t ? (n = document.createElement("div"), n.innerHTML = e) : n = e || document.body;
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);
827
+ let r = Z(), i = r || t ? null : await Dt(n);
828
+ return r ? await r.renderMath?.(n) : i && i !== $ ? await i(n) : await Tt()(n), t ? n.innerHTML : void 0;
829
+ }, Ot = (e, t) => {
830
+ let n = Z()?.wrapMath?.(e, t);
701
831
  if (n != null) return n;
702
832
  let [r, i] = t === "dollar" || t === "double_dollar" ? ["$", "$"] : ["\\(", "\\)"];
703
- return `${r}${W(e)}${i}`;
704
- }, st = (e) => {
833
+ return `${r}${X(e)}${i}`;
834
+ }, kt = (e) => {
705
835
  let t = e.trim();
706
836
  return t.startsWith("\\[") && t.endsWith("\\]") ? {
707
837
  unwrapped: t.slice(2, -2).trim(),
@@ -728,6 +858,6 @@ var $ = async (e) => {
728
858
  close: "$"
729
859
  }
730
860
  } : { unwrapped: t };
731
- }, ct = (e) => Q()?.mmlToLatex?.(e) ?? e;
861
+ }, At = (e) => Z()?.mmlToLatex?.(e) ?? e;
732
862
  //#endregion
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 };
863
+ export { y as MATHJAX_CONFLICT_EVENT, m as NO_ASSET_ROOT_EVENT, v as UNSUPPORTED_PAGE_DOCS_URL, gt as createMathjaxRenderer, _t as getMathjaxCssUrls, At as mmlToLatex, $ as renderMath, kt as unWrapMath, Ot as wrapMath };